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
59a0f7d2df907501ff63b4c68766d5627b1f8a63
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/linear_algebra/affine_space/basic.lean
74aac679a3f5299b43ea078c4090e94b6f366ef5
[ "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
56,729
lean
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Joseph Myers. -/ import algebra.add_torsor import linear_algebra.tensor_product noncomputable theory open_locale big_operators open_locale classical /-! # Affine spaces This file defines affine spaces (over modules) and subspaces, affine maps, and the affine span of a set of points. For affine combinations of points, see `linear_algebra.affine_space.combination`. For affinely independent families of points, see `linear_algebra.affine_space.independent`. For some additional results relating to finite-dimensional subspaces of affine spaces, see `linear_algebra.affine_space.finite_dimensional`. ## Main definitions * `affine_space V P` is an abbreviation for `add_torsor V P` in the case of `module k V`. `P` is the type of points in the space and `V` the `k`-module of displacement vectors. Definitions and results not depending on the `module` structure appear in `algebra.add_torsor` instead of here; that includes the instance of an `add_group` as an `add_torsor` over itself, which thus gives a `module` as an `affine_space` over itself. Definitions of affine spaces vary as to whether a space with no points is permitted; here, we require a nonempty type of points (via the definition of torsors requiring a nonempty type). Affine spaces are defined over any module, with stronger type class requirements on `k` being used for individual lemmas where needed. * `affine_subspace k P` is the type of affine subspaces. Unlike affine spaces, affine subspaces are allowed to be empty, and lemmas that do not apply to empty affine subspaces have `nonempty` hypotheses. There is a `complete_lattice` structure on affine subspaces. * `affine_subspace.direction` gives the `submodule` spanned by the pairwise differences of points in an `affine_subspace`. There are various lemmas relating to the set of vectors in the `direction`, and relating the lattice structure on affine subspaces to that on their directions. * `affine_span` gives the affine subspace spanned by a set of points, with `vector_span` giving its direction. `affine_span` is defined in terms of `span_points`, which gives an explicit description of the points contained in the affine span; `span_points` itself should generally only be used when that description is required, with `affine_span` being the main definition for other purposes. Two other descriptions of the affine span are proved equivalent: it is the `Inf` of affine subspaces containing the points, and (if `[nontrivial k]`) it contains exactly those points that are affine combinations of points in the given set. * `affine_map` is the type of affine maps between two affine spaces with the same ring `k`. Various basic examples of affine maps are defined, including `const`, `id`, `line_map` and `homothety`. ## Implementation notes `out_param` is used to make `V` an implicit argument (deduced from `P`) in most cases; `include V` is needed in many cases for `V`, and type classes using it, to be added as implicit arguments to individual lemmas. As for modules, `k` is an explicit argument rather than implied by `P` or `V`. This file only provides purely algebraic definitions and results. Those depending on analysis or topology are defined elsewhere; see `analysis.normed_space.add_torsor` and `topology.algebra.affine`. TODO: Some key definitions are not yet present. * Coercions from an `affine_subspace` to the subtype of its points, and a corresponding `affine_space` instance on that subtype in the case of a nonempty subspace. * `affine_equiv` (see issue #2909). * Affine frames. An affine frame might perhaps be represented as an `affine_equiv` to a `finsupp` (in the general case) or function type (in the finite-dimensional case) that gives the coordinates, with appropriate proofs of existence when `k` is a field. * Although results on affine combinations implicitly provide barycentric frames and coordinates, there is no explicit representation of the map from a point to its coordinates. ## References * https://en.wikipedia.org/wiki/Affine_space * https://en.wikipedia.org/wiki/Principal_homogeneous_space -/ /- `affine_space` is an abbreviation for `add_torsor` in the case where the group is a vector space, or more generally a module. We omit the arguments `(k : Type*) [ring k] [module k V]` in the type synonym itself to simplify type class search. -/ notation `affine_space` := add_torsor section variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] variables [affine_space V P] include V /-- The submodule spanning the differences of a (possibly empty) set of points. -/ def vector_span (s : set P) : submodule k V := submodule.span k (vsub_set s) /-- The definition of `vector_span`, for rewriting. -/ lemma vector_span_def (s : set P) : vector_span k s = submodule.span k (vsub_set s) := rfl /-- `vector_span` is monotone. -/ lemma vector_span_mono {s₁ s₂ : set P} (h : s₁ ⊆ s₂) : vector_span k s₁ ≤ vector_span k s₂ := submodule.span_mono (vsub_set_mono h) variables (P) /-- The `vector_span` of the empty set is `⊥`. -/ @[simp] lemma vector_span_empty : vector_span k (∅ : set P) = (⊥ : submodule k V) := by rw [vector_span_def, vsub_set_empty, submodule.span_empty] variables {P} /-- The `vector_span` of a single point is `⊥`. -/ @[simp] lemma vector_span_singleton (p : P) : vector_span k ({p} : set P) = ⊥ := by simp [vector_span_def] /-- The `vsub_set` lies within the `vector_span`. -/ lemma vsub_set_subset_vector_span (s : set P) : vsub_set s ⊆ vector_span k s := submodule.subset_span /-- Each pairwise difference is in the `vector_span`. -/ lemma vsub_mem_vector_span {s : set P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : p1 -ᵥ p2 ∈ vector_span k s := vsub_set_subset_vector_span k s (vsub_mem_vsub_set hp1 hp2) /-- The points in the affine span of a (possibly empty) set of points. Use `affine_span` instead to get an `affine_subspace k P`. -/ def span_points (s : set P) : set P := {p | ∃ p1 ∈ s, ∃ v ∈ (vector_span k s), p = v +ᵥ p1} /-- A point in a set is in its affine span. -/ lemma mem_span_points (p : P) (s : set P) : p ∈ s → p ∈ span_points k s | hp := ⟨p, hp, 0, submodule.zero_mem _, (zero_vadd V p).symm⟩ /-- A set is contained in its `span_points`. -/ lemma subset_span_points (s : set P) : s ⊆ span_points k s := λ p, mem_span_points k p s /-- The `span_points` of a set is nonempty if and only if that set is. -/ @[simp] lemma span_points_nonempty (s : set P) : (span_points k s).nonempty ↔ s.nonempty := begin split, { contrapose, rw [set.not_nonempty_iff_eq_empty, set.not_nonempty_iff_eq_empty], intro h, simp [h, span_points] }, { exact λ h, h.mono (subset_span_points _ _) } end /-- Adding a point in the affine span and a vector in the spanning submodule produces a point in the affine span. -/ lemma vadd_mem_span_points_of_mem_span_points_of_mem_vector_span {s : set P} {p : P} {v : V} (hp : p ∈ span_points k s) (hv : v ∈ vector_span k s) : v +ᵥ p ∈ span_points k s := begin rcases hp with ⟨p2, ⟨hp2, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩, rw [hv2p, vadd_assoc], use [p2, hp2, v + v2, (vector_span k s).add_mem hv hv2, rfl] end /-- Subtracting two points in the affine span produces a vector in the spanning submodule. -/ lemma vsub_mem_vector_span_of_mem_span_points_of_mem_span_points {s : set P} {p1 p2 : P} (hp1 : p1 ∈ span_points k s) (hp2 : p2 ∈ span_points k s) : p1 -ᵥ p2 ∈ vector_span k s := begin rcases hp1 with ⟨p1a, ⟨hp1a, ⟨v1, ⟨hv1, hv1p⟩⟩⟩⟩, rcases hp2 with ⟨p2a, ⟨hp2a, ⟨v2, ⟨hv2, hv2p⟩⟩⟩⟩, rw [hv1p, hv2p, vsub_vadd_eq_vsub_sub (v1 +ᵥ p1a), vadd_vsub_assoc, add_comm, add_sub_assoc], have hv1v2 : v1 - v2 ∈ vector_span k s, { apply (vector_span k s).add_mem hv1, rw ←neg_one_smul k v2, exact (vector_span k s).smul_mem (-1 : k) hv2 }, refine (vector_span k s).add_mem _ hv1v2, exact vsub_mem_vector_span k hp1a hp2a end end /-- An `affine_subspace k P` is a subset of an `affine_space V P` that, if not empty, has an affine space structure induced by a corresponding subspace of the `module k V`. -/ structure affine_subspace (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V] [affine_space V P] := (carrier : set P) (smul_vsub_vadd_mem : ∀ (c : k) {p1 p2 p3 : P}, p1 ∈ carrier → p2 ∈ carrier → p3 ∈ carrier → c • (p1 -ᵥ p2 : V) +ᵥ p3 ∈ carrier) namespace affine_subspace variables (k : Type*) {V : Type*} (P : Type*) [ring k] [add_comm_group V] [module k V] [affine_space V P] include V instance : has_coe (affine_subspace k P) (set P) := ⟨carrier⟩ instance : has_mem P (affine_subspace k P) := ⟨λ p s, p ∈ (s : set P)⟩ /-- A point is in an affine subspace coerced to a set if and only if it is in that affine subspace. -/ @[simp] lemma mem_coe (p : P) (s : affine_subspace k P) : p ∈ (s : set P) ↔ p ∈ s := iff.rfl variables {k P} /-- The direction of an affine subspace is the submodule spanned by the pairwise differences of points. (Except in the case of an empty affine subspace, where the direction is the zero submodule, every vector in the direction is the difference of two points in the affine subspace.) -/ def direction (s : affine_subspace k P) : submodule k V := vector_span k (s : set P) /-- The direction equals the `vector_span`. -/ lemma direction_eq_vector_span (s : affine_subspace k P) : s.direction = vector_span k (s : set P) := rfl /-- Alternative definition of the direction when the affine subspace is nonempty. This is defined so that the order on submodules (as used in the definition of `submodule.span`) can be used in the proof of `coe_direction_eq_vsub_set`, and is not intended to be used beyond that proof. -/ def direction_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) : submodule k V := { carrier := vsub_set (s : set P), zero_mem' := begin cases h with p hp, exact (vsub_self p) ▸ vsub_mem_vsub_set hp hp end, add_mem' := begin intros a b ha hb, rcases ha with ⟨p1, p2, hp1, hp2, rfl⟩, rcases hb with ⟨p3, p4, hp3, hp4, rfl⟩, rw [←vadd_vsub_assoc], refine vsub_mem_vsub_set _ hp4, convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp3, rw one_smul end, smul_mem' := begin intros c v hv, rcases hv with ⟨p1, p2, hp1, hp2, rfl⟩, rw [←vadd_vsub (c • (p1 -ᵥ p2)) p2], refine vsub_mem_vsub_set _ hp2, exact s.smul_vsub_vadd_mem c hp1 hp2 hp2 end } /-- `direction_of_nonempty` gives the same submodule as `direction`. -/ lemma direction_of_nonempty_eq_direction {s : affine_subspace k P} (h : (s : set P).nonempty) : direction_of_nonempty h = s.direction := le_antisymm (vsub_set_subset_vector_span k s) (submodule.span_le.2 set.subset.rfl) /-- The set of vectors in the direction of a nonempty affine subspace is given by `vsub_set`. -/ lemma coe_direction_eq_vsub_set {s : affine_subspace k P} (h : (s : set P).nonempty) : (s.direction : set V) = vsub_set (s : set P) := direction_of_nonempty_eq_direction h ▸ rfl /-- A vector is in the direction of a nonempty affine subspace if and only if it is the subtraction of two vectors in the subspace. -/ lemma mem_direction_iff_eq_vsub {s : affine_subspace k P} (h : (s : set P).nonempty) (v : V) : v ∈ s.direction ↔ ∃ p1 ∈ s, ∃ p2 ∈ s, v = p1 -ᵥ p2 := begin rw [←submodule.mem_coe, coe_direction_eq_vsub_set h], exact ⟨λ ⟨p1, p2, hp1, hp2, hv⟩, ⟨p1, hp1, p2, hp2, hv.symm⟩, λ ⟨p1, hp1, p2, hp2, hv⟩, ⟨p1, p2, hp1, hp2, hv.symm⟩⟩ end /-- Adding a vector in the direction to a point in the subspace produces a point in the subspace. -/ lemma vadd_mem_of_mem_direction {s : affine_subspace k P} {v : V} (hv : v ∈ s.direction) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s := begin rw mem_direction_iff_eq_vsub ⟨p, hp⟩ at hv, rcases hv with ⟨p1, hp1, p2, hp2, hv⟩, rw hv, convert s.smul_vsub_vadd_mem 1 hp1 hp2 hp, rw one_smul end /-- Subtracting two points in the subspace produces a vector in the direction. -/ lemma vsub_mem_direction {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) (hp2 : p2 ∈ s) : (p1 -ᵥ p2) ∈ s.direction := vsub_mem_vector_span k hp1 hp2 /-- Adding a vector to a point in a subspace produces a point in the subspace if and only if the vector is in the direction. -/ lemma vadd_mem_iff_mem_direction {s : affine_subspace k P} (v : V) {p : P} (hp : p ∈ s) : v +ᵥ p ∈ s ↔ v ∈ s.direction := ⟨λ h, by simpa using vsub_mem_direction h hp, λ h, vadd_mem_of_mem_direction h hp⟩ /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the right. -/ lemma coe_direction_eq_vsub_set_right {s : affine_subspace k P} {p : P} (hp : p ∈ s) : (s.direction : set V) = (-ᵥ p) '' s := begin rw coe_direction_eq_vsub_set ⟨p, hp⟩, refine le_antisymm _ _, { rintros v ⟨p1, p2, hp1, hp2, rfl⟩, exact ⟨p1 -ᵥ p2 +ᵥ p, vadd_mem_of_mem_direction (vsub_mem_direction hp1 hp2) hp, (vadd_vsub _ _)⟩ }, { rintros v ⟨p2, hp2, rfl⟩, exact ⟨p2, p, hp2, hp, rfl⟩ } end /-- Given a point in an affine subspace, the set of vectors in its direction equals the set of vectors subtracting that point on the left. -/ lemma coe_direction_eq_vsub_set_left {s : affine_subspace k P} {p : P} (hp : p ∈ s) : (s.direction : set V) = (-ᵥ) p '' s := begin ext v, rw [submodule.mem_coe, ←submodule.neg_mem_iff, ←submodule.mem_coe, coe_direction_eq_vsub_set_right hp, set.mem_image_iff_bex, set.mem_image_iff_bex], conv_lhs { congr, funext, rw [←neg_vsub_eq_vsub_rev, neg_inj] } end /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the right. -/ lemma mem_direction_iff_eq_vsub_right {s : affine_subspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p2 -ᵥ p := begin rw [←submodule.mem_coe, coe_direction_eq_vsub_set_right hp], exact ⟨λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩, λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩⟩ end /-- Given a point in an affine subspace, a vector is in its direction if and only if it results from subtracting that point on the left. -/ lemma mem_direction_iff_eq_vsub_left {s : affine_subspace k P} {p : P} (hp : p ∈ s) (v : V) : v ∈ s.direction ↔ ∃ p2 ∈ s, v = p -ᵥ p2 := begin rw [←submodule.mem_coe, coe_direction_eq_vsub_set_left hp], exact ⟨λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩, λ ⟨p2, hp2, hv⟩, ⟨p2, hp2, hv.symm⟩⟩ end /-- Given a point in an affine subspace, a result of subtracting that point on the right is in the direction if and only if the other point is in the subspace. -/ lemma vsub_right_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p2 -ᵥ p ∈ s.direction ↔ p2 ∈ s := begin rw mem_direction_iff_eq_vsub_right hp, simp end /-- Given a point in an affine subspace, a result of subtracting that point on the left is in the direction if and only if the other point is in the subspace. -/ lemma vsub_left_mem_direction_iff_mem {s : affine_subspace k P} {p : P} (hp : p ∈ s) (p2 : P) : p -ᵥ p2 ∈ s.direction ↔ p2 ∈ s := begin rw mem_direction_iff_eq_vsub_left hp, simp end /-- Two affine subspaces are equal if they have the same points. -/ @[ext] lemma ext {s1 s2 : affine_subspace k P} (h : (s1 : set P) = s2) : s1 = s2 := begin cases s1, cases s2, congr, exact h end /-- Two affine subspaces with the same direction and nonempty intersection are equal. -/ lemma ext_of_direction_eq {s1 s2 : affine_subspace k P} (hd : s1.direction = s2.direction) (hn : ((s1 : set P) ∩ s2).nonempty) : s1 = s2 := begin ext p, have hq1 := set.mem_of_mem_inter_left hn.some_mem, have hq2 := set.mem_of_mem_inter_right hn.some_mem, split, { intro hp, rw ←vsub_vadd p hn.some, refine vadd_mem_of_mem_direction _ hq2, rw ←hd, exact vsub_mem_direction hp hq1 }, { intro hp, rw ←vsub_vadd p hn.some, refine vadd_mem_of_mem_direction _ hq1, rw hd, exact vsub_mem_direction hp hq2 } end /-- Two affine subspaces with nonempty intersection are equal if and only if their directions are equal. -/ lemma eq_iff_direction_eq_of_mem {s₁ s₂ : affine_subspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : s₁ = s₂ ↔ s₁.direction = s₂.direction := ⟨λ h, h ▸ rfl, λ h, ext_of_direction_eq h ⟨p, h₁, h₂⟩⟩ /-- Construct an affine subspace from a point and a direction. -/ def mk' (p : P) (direction : submodule k V) : affine_subspace k P := { carrier := {q | ∃ v ∈ direction, q = v +ᵥ p}, smul_vsub_vadd_mem := λ c p1 p2 p3 hp1 hp2 hp3, begin rcases hp1 with ⟨v1, hv1, hp1⟩, rcases hp2 with ⟨v2, hv2, hp2⟩, rcases hp3 with ⟨v3, hv3, hp3⟩, use [c • (v1 - v2) + v3, direction.add_mem (direction.smul_mem c (direction.sub_mem hv1 hv2)) hv3], simp [hp1, hp2, hp3, vadd_assoc] end } /-- An affine subspace constructed from a point and a direction contains that point. -/ lemma self_mem_mk' (p : P) (direction : submodule k V) : p ∈ mk' p direction := ⟨0, ⟨direction.zero_mem, (zero_vadd _ _).symm⟩⟩ /-- An affine subspace constructed from a point and a direction contains the result of adding a vector in that direction to that point. -/ lemma vadd_mem_mk' {v : V} (p : P) {direction : submodule k V} (hv : v ∈ direction) : v +ᵥ p ∈ mk' p direction := ⟨v, hv, rfl⟩ /-- An affine subspace constructed from a point and a direction is nonempty. -/ lemma mk'_nonempty (p : P) (direction : submodule k V) : (mk' p direction : set P).nonempty := ⟨p, self_mem_mk' p direction⟩ /-- The direction of an affine subspace constructed from a point and a direction. -/ @[simp] lemma direction_mk' (p : P) (direction : submodule k V) : (mk' p direction).direction = direction := begin ext v, rw mem_direction_iff_eq_vsub (mk'_nonempty _ _), split, { rintros ⟨p1, ⟨v1, hv1, hp1⟩, p2, ⟨v2, hv2, hp2⟩, hv⟩, rw [hv, hp1, hp2, vadd_vsub_vadd_cancel_right], exact direction.sub_mem hv1 hv2 }, { exact λ hv, ⟨v +ᵥ p, vadd_mem_mk' _ hv, p, self_mem_mk' _ _, (vadd_vsub _ _).symm⟩ } end /-- Constructing an affine subspace from a point in a subspace and that subspace's direction yields the original subspace. -/ @[simp] lemma mk'_eq {s : affine_subspace k P} {p : P} (hp : p ∈ s) : mk' p s.direction = s := ext_of_direction_eq (direction_mk' p s.direction) ⟨p, set.mem_inter (self_mem_mk' _ _) hp⟩ /-- If an affine subspace contains a set of points, it contains the `span_points` of that set. -/ lemma span_points_subset_coe_of_subset_coe {s : set P} {s1 : affine_subspace k P} (h : s ⊆ s1) : span_points k s ⊆ s1 := begin rintros p ⟨p1, hp1, v, hv, hp⟩, rw hp, have hp1s1 : p1 ∈ (s1 : set P) := set.mem_of_mem_of_subset hp1 h, refine vadd_mem_of_mem_direction _ hp1s1, have hs : vector_span k s ≤ s1.direction := vector_span_mono k h, rw submodule.le_def at hs, rw ←submodule.mem_coe, exact set.mem_of_mem_of_subset hv hs end end affine_subspace section affine_span variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] [affine_space V P] include V /-- The affine span of a set of points is the smallest affine subspace containing those points. (Actually defined here in terms of spans in modules.) -/ def affine_span (s : set P) : affine_subspace k P := { carrier := span_points k s, smul_vsub_vadd_mem := λ c p1 p2 p3 hp1 hp2 hp3, vadd_mem_span_points_of_mem_span_points_of_mem_vector_span k hp3 ((vector_span k s).smul_mem c (vsub_mem_vector_span_of_mem_span_points_of_mem_span_points k hp1 hp2)) } /-- The affine span, converted to a set, is `span_points`. -/ @[simp] lemma coe_affine_span (s : set P) : (affine_span k s : set P) = span_points k s := rfl /-- A set is contained in its affine span. -/ lemma subset_affine_span (s : set P) : s ⊆ affine_span k s := subset_span_points k s /-- The direction of the affine span is the `vector_span`. -/ lemma direction_affine_span (s : set P) : (affine_span k s).direction = vector_span k s := begin apply le_antisymm, { refine submodule.span_le.2 _, rintros v ⟨p1, p3, ⟨p2, hp2, v1, hv1, hp1⟩, ⟨p4, hp4, v2, hv2, hp3⟩, rfl⟩, rw [hp1, hp3, vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, submodule.mem_coe], exact (vector_span k s).sub_mem ((vector_span k s).add_mem hv1 (vsub_mem_vector_span k hp2 hp4)) hv2 }, { exact vector_span_mono k (subset_span_points k s) } end /-- A point in a set is in its affine span. -/ lemma mem_affine_span {p : P} {s : set P} (hp : p ∈ s) : p ∈ affine_span k s := mem_span_points k p s hp end affine_span namespace affine_subspace variables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] [S : affine_space V P] include S instance : complete_lattice (affine_subspace k P) := { sup := λ s1 s2, affine_span k (s1 ∪ s2), le_sup_left := λ s1 s2, set.subset.trans (set.subset_union_left s1 s2) (subset_span_points k _), le_sup_right := λ s1 s2, set.subset.trans (set.subset_union_right s1 s2) (subset_span_points k _), sup_le := λ s1 s2 s3 hs1 hs2, span_points_subset_coe_of_subset_coe (set.union_subset hs1 hs2), inf := λ s1 s2, mk (s1 ∩ s2) (λ c p1 p2 p3 hp1 hp2 hp3, ⟨s1.smul_vsub_vadd_mem c hp1.1 hp2.1 hp3.1, s2.smul_vsub_vadd_mem c hp1.2 hp2.2 hp3.2⟩), inf_le_left := λ _ _, set.inter_subset_left _ _, inf_le_right := λ _ _, set.inter_subset_right _ _, le_inf := λ _ _ _, set.subset_inter, top := { carrier := set.univ, smul_vsub_vadd_mem := λ _ _ _ _ _ _ _, set.mem_univ _ }, le_top := λ _ _ _, set.mem_univ _, bot := { carrier := ∅, smul_vsub_vadd_mem := λ _ _ _ _, false.elim }, bot_le := λ _ _, false.elim, Sup := λ s, affine_span k (⋃ s' ∈ s, (s' : set P)), Inf := λ s, mk (⋂ s' ∈ s, (s' : set P)) (λ c p1 p2 p3 hp1 hp2 hp3, set.mem_bInter_iff.2 $ λ s2 hs2, s2.smul_vsub_vadd_mem c (set.mem_bInter_iff.1 hp1 s2 hs2) (set.mem_bInter_iff.1 hp2 s2 hs2) (set.mem_bInter_iff.1 hp3 s2 hs2)), le_Sup := λ _ _ h, set.subset.trans (set.subset_bUnion_of_mem h) (subset_span_points k _), Sup_le := λ _ _ h, span_points_subset_coe_of_subset_coe (set.bUnion_subset h), Inf_le := λ _ _, set.bInter_subset_of_mem, le_Inf := λ _ _, set.subset_bInter, .. partial_order.lift (coe : affine_subspace k P → set P) (λ _ _, ext) } instance : inhabited (affine_subspace k P) := ⟨⊤⟩ /-- The `≤` order on subspaces is the same as that on the corresponding sets. -/ lemma le_def (s1 s2 : affine_subspace k P) : s1 ≤ s2 ↔ (s1 : set P) ⊆ s2 := iff.rfl /-- One subspace is less than or equal to another if and only if all its points are in the second subspace. -/ lemma le_def' (s1 s2 : affine_subspace k P) : s1 ≤ s2 ↔ ∀ p ∈ s1, p ∈ s2 := iff.rfl /-- The `<` order on subspaces is the same as that on the corresponding sets. -/ lemma lt_def (s1 s2 : affine_subspace k P) : s1 < s2 ↔ (s1 : set P) ⊂ s2 := iff.rfl /-- One subspace is not less than or equal to another if and only if it has a point not in the second subspace. -/ lemma not_le_iff_exists (s1 s2 : affine_subspace k P) : ¬ s1 ≤ s2 ↔ ∃ p ∈ s1, p ∉ s2 := set.not_subset /-- If a subspace is less than another, there is a point only in the second. -/ lemma exists_of_lt {s1 s2 : affine_subspace k P} (h : s1 < s2) : ∃ p ∈ s2, p ∉ s1 := set.exists_of_ssubset h /-- A subspace is less than another if and only if it is less than or equal to the second subspace and there is a point only in the second. -/ lemma lt_iff_le_and_exists (s1 s2 : affine_subspace k P) : s1 < s2 ↔ s1 ≤ s2 ∧ ∃ p ∈ s2, p ∉ s1 := by rw [lt_iff_le_not_le, not_le_iff_exists] /-- If an affine subspace is nonempty and contained in another with the same direction, they are equal. -/ lemma eq_of_direction_eq_of_nonempty_of_le {s₁ s₂ : affine_subspace k P} (hd : s₁.direction = s₂.direction) (hn : (s₁ : set P).nonempty) (hle : s₁ ≤ s₂) : s₁ = s₂ := let ⟨p, hp⟩ := hn in ext_of_direction_eq hd ⟨p, hp, hle hp⟩ variables (k V) /-- The affine span is the `Inf` of subspaces containing the given points. -/ lemma affine_span_eq_Inf (s : set P) : affine_span k s = Inf {s' | s ⊆ s'} := le_antisymm (span_points_subset_coe_of_subset_coe (set.subset_bInter (λ _ h, h))) (Inf_le (subset_span_points k _)) variables (P) /-- The Galois insertion formed by `affine_span` and coercion back to a set. -/ protected def gi : galois_insertion (affine_span k) (coe : affine_subspace k P → set P) := { choice := λ s _, affine_span k s, gc := λ s1 s2, ⟨λ h, set.subset.trans (subset_span_points k s1) h, span_points_subset_coe_of_subset_coe⟩, le_l_u := λ _, subset_span_points k _, choice_eq := λ _ _, rfl } /-- The span of the empty set is `⊥`. -/ @[simp] lemma span_empty : affine_span k (∅ : set P) = ⊥ := (affine_subspace.gi k V P).gc.l_bot /-- The span of `univ` is `⊤`. -/ @[simp] lemma span_univ : affine_span k (set.univ : set P) = ⊤ := eq_top_iff.2 $ subset_span_points k _ variables {P} /-- The affine span of a single point, coerced to a set, contains just that point. -/ @[simp] lemma coe_affine_span_singleton (p : P) : (affine_span k ({p} : set P) : set P) = {p} := begin ext x, rw [mem_coe, ←vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_singleton p)) _, direction_affine_span], simp end /-- A point is in the affine span of a single point if and only if they are equal. -/ @[simp] lemma mem_affine_span_singleton (p1 p2 : P) : p1 ∈ affine_span k ({p2} : set P) ↔ p1 = p2 := by simp [←mem_coe] /-- The span of a union of sets is the sup of their spans. -/ lemma span_union (s t : set P) : affine_span k (s ∪ t) = affine_span k s ⊔ affine_span k t := (affine_subspace.gi k V P).gc.l_sup /-- The span of a union of an indexed family of sets is the sup of their spans. -/ lemma span_Union {ι : Type*} (s : ι → set P) : affine_span k (⋃ i, s i) = ⨆ i, affine_span k (s i) := (affine_subspace.gi k V P).gc.l_supr variables (P) /-- `⊤`, coerced to a set, is the whole set of points. -/ @[simp] lemma top_coe : ((⊤ : affine_subspace k P) : set P) = set.univ := rfl variables {P} /-- All points are in `⊤`. -/ lemma mem_top (p : P) : p ∈ (⊤ : affine_subspace k P) := set.mem_univ p variables (P) /-- The direction of `⊤` is the whole module as a submodule. -/ @[simp] lemma direction_top : (⊤ : affine_subspace k P).direction = ⊤ := begin cases S.nonempty with p, ext v, refine ⟨imp_intro submodule.mem_top, λ hv, _⟩, have hpv : (v +ᵥ p -ᵥ p : V) ∈ (⊤ : affine_subspace k P).direction := vsub_mem_direction (mem_top k V _) (mem_top k V _), rwa vadd_vsub at hpv end /-- `⊥`, coerced to a set, is the empty set. -/ @[simp] lemma bot_coe : ((⊥ : affine_subspace k P) : set P) = ∅ := rfl variables {P} /-- No points are in `⊥`. -/ lemma not_mem_bot (p : P) : p ∉ (⊥ : affine_subspace k P) := set.not_mem_empty p variables (P) /-- The direction of `⊥` is the submodule `⊥`. -/ @[simp] lemma direction_bot : (⊥ : affine_subspace k P).direction = ⊥ := by rw [direction_eq_vector_span, bot_coe, vector_span_def, vsub_set_empty, submodule.span_empty] variables {k V P} /-- A nonempty affine subspace is `⊤` if and only if its direction is `⊤`. -/ @[simp] lemma direction_eq_top_iff_of_nonempty {s : affine_subspace k P} (h : (s : set P).nonempty) : s.direction = ⊤ ↔ s = ⊤ := begin split, { intro hd, rw ←direction_top k V P at hd, refine ext_of_direction_eq hd _, simp [h] }, { rintro rfl, simp } end /-- The inf of two affine subspaces, coerced to a set, is the intersection of the two sets of points. -/ @[simp] lemma inf_coe (s1 s2 : affine_subspace k P) : ((s1 ⊓ s2) : set P) = s1 ∩ s2 := rfl /-- A point is in the inf of two affine subspaces if and only if it is in both of them. -/ lemma mem_inf_iff (p : P) (s1 s2 : affine_subspace k P) : p ∈ s1 ⊓ s2 ↔ p ∈ s1 ∧ p ∈ s2 := iff.rfl /-- The direction of the inf of two affine subspaces is less than or equal to the inf of their directions. -/ lemma direction_inf (s1 s2 : affine_subspace k P) : (s1 ⊓ s2).direction ≤ s1.direction ⊓ s2.direction := begin repeat { rw [direction_eq_vector_span, vector_span_def] }, exact le_inf (Inf_le_Inf (λ p hp, set.subset.trans (vsub_set_mono (set.inter_subset_left _ _)) hp)) (Inf_le_Inf (λ p hp, set.subset.trans (vsub_set_mono (set.inter_subset_right _ _)) hp)) end /-- If two affine subspaces have a point in common, the direction of their inf equals the inf of their directions. -/ lemma direction_inf_of_mem {s₁ s₂ : affine_subspace k P} {p : P} (h₁ : p ∈ s₁) (h₂ : p ∈ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := begin ext v, rw [submodule.mem_inf, ←vadd_mem_iff_mem_direction v h₁, ←vadd_mem_iff_mem_direction v h₂, ←vadd_mem_iff_mem_direction v ((mem_inf_iff p s₁ s₂).2 ⟨h₁, h₂⟩), mem_inf_iff] end /-- If two affine subspaces have a point in their inf, the direction of their inf equals the inf of their directions. -/ lemma direction_inf_of_mem_inf {s₁ s₂ : affine_subspace k P} {p : P} (h : p ∈ s₁ ⊓ s₂) : (s₁ ⊓ s₂).direction = s₁.direction ⊓ s₂.direction := direction_inf_of_mem ((mem_inf_iff p s₁ s₂).1 h).1 ((mem_inf_iff p s₁ s₂).1 h).2 /-- If one affine subspace is less than or equal to another, the same applies to their directions. -/ lemma direction_le {s1 s2 : affine_subspace k P} (h : s1 ≤ s2) : s1.direction ≤ s2.direction := begin repeat { rw [direction_eq_vector_span, vector_span_def] }, exact vector_span_mono k h end /-- If one nonempty affine subspace is less than another, the same applies to their directions -/ lemma direction_lt_of_nonempty {s1 s2 : affine_subspace k P} (h : s1 < s2) (hn : (s1 : set P).nonempty) : s1.direction < s2.direction := begin cases hn with p hp, rw lt_iff_le_and_exists at h, rcases h with ⟨hle, p2, hp2, hp2s1⟩, rw submodule.lt_iff_le_and_exists, use [direction_le hle, p2 -ᵥ p, vsub_mem_direction hp2 (hle hp)], intro hm, rw vsub_right_mem_direction_iff_mem hp p2 at hm, exact hp2s1 hm end /-- The sup of the directions of two affine subspaces is less than or equal to the direction of their sup. -/ lemma sup_direction_le (s1 s2 : affine_subspace k P) : s1.direction ⊔ s2.direction ≤ (s1 ⊔ s2).direction := begin repeat { rw [direction_eq_vector_span, vector_span_def] }, exact sup_le (Inf_le_Inf (λ p hp, set.subset.trans (vsub_set_mono (le_sup_left : s1 ≤ s1 ⊔ s2)) hp)) (Inf_le_Inf (λ p hp, set.subset.trans (vsub_set_mono (le_sup_right : s2 ≤ s1 ⊔ s2)) hp)) end /-- The sup of the directions of two nonempty affine subspaces with empty intersection is less than the direction of their sup. -/ lemma sup_direction_lt_of_nonempty_of_inter_empty {s1 s2 : affine_subspace k P} (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (he : (s1 ∩ s2 : set P) = ∅) : s1.direction ⊔ s2.direction < (s1 ⊔ s2).direction := begin cases h1 with p1 hp1, cases h2 with p2 hp2, rw submodule.lt_iff_le_and_exists, use [sup_direction_le s1 s2, p2 -ᵥ p1, vsub_mem_direction ((le_sup_right : s2 ≤ s1 ⊔ s2) hp2) ((le_sup_left : s1 ≤ s1 ⊔ s2) hp1)], intro h, rw submodule.mem_sup at h, rcases h with ⟨v1, hv1, v2, hv2, hv1v2⟩, rw [←sub_eq_zero, sub_eq_add_neg, neg_vsub_eq_vsub_rev, add_comm v1, add_assoc, ←vadd_vsub_assoc, ←neg_neg v2, add_comm, ←sub_eq_add_neg, ←vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hv1v2, refine set.nonempty.ne_empty _ he, use [v1 +ᵥ p1, vadd_mem_of_mem_direction hv1 hp1], rw hv1v2, exact vadd_mem_of_mem_direction (submodule.neg_mem _ hv2) hp2 end /-- If the directions of two nonempty affine subspaces span the whole module, they have nonempty intersection. -/ lemma inter_nonempty_of_nonempty_of_sup_direction_eq_top {s1 s2 : affine_subspace k P} (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (hd : s1.direction ⊔ s2.direction = ⊤) : ((s1 : set P) ∩ s2).nonempty := begin by_contradiction h, rw set.not_nonempty_iff_eq_empty at h, have hlt := sup_direction_lt_of_nonempty_of_inter_empty h1 h2 h, rw hd at hlt, exact not_top_lt hlt end /-- If the directions of two nonempty affine subspaces are complements of each other, they intersect in exactly one point. -/ lemma inter_eq_singleton_of_nonempty_of_is_compl {s1 s2 : affine_subspace k P} (h1 : (s1 : set P).nonempty) (h2 : (s2 : set P).nonempty) (hd : is_compl s1.direction s2.direction) : ∃ p, (s1 : set P) ∩ s2 = {p} := begin cases inter_nonempty_of_nonempty_of_sup_direction_eq_top h1 h2 hd.sup_eq_top with p hp, use p, ext q, rw set.mem_singleton_iff, split, { rintros ⟨hq1, hq2⟩, have hqp : q -ᵥ p ∈ s1.direction ⊓ s2.direction := ⟨vsub_mem_direction hq1 hp.1, vsub_mem_direction hq2 hp.2⟩, rwa [hd.inf_eq_bot, submodule.mem_bot, vsub_eq_zero_iff_eq] at hqp }, { exact λ h, h.symm ▸ hp } end /-- Coercing a subspace to a set then taking the affine span produces the original subspace. -/ @[simp] lemma affine_span_coe (s : affine_subspace k P) : affine_span k (s : set P) = s := begin refine le_antisymm _ (subset_span_points _ _), rintros p ⟨p1, hp1, v, hv, rfl⟩, exact vadd_mem_of_mem_direction hv hp1 end end affine_subspace section affine_space' variables (k : Type*) {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] [affine_space V P] variables {ι : Type*} include V open affine_subspace /-- The `vector_span` is the span of the pairwise subtractions with a given point on the left. -/ lemma vector_span_eq_span_vsub_set_left {s : set P} {p : P} (hp : p ∈ s) : vector_span k s = submodule.span k ((-ᵥ) p '' s) := begin rw vector_span_def, refine le_antisymm _ (submodule.span_mono _), { rw submodule.span_le, rintros v ⟨p1, p2, hp1, hp2, hv⟩, rw ←vsub_sub_vsub_cancel_left p1 p2 p at hv, rw [←hv, submodule.mem_coe, submodule.mem_span], exact λ m hm, submodule.sub_mem _ (hm ⟨p2, hp2, rfl⟩) (hm ⟨p1, hp1, rfl⟩) }, { rintros v ⟨p2, hp2, hv⟩, exact ⟨p, p2, hp, hp2, hv⟩ } end /-- The `vector_span` is the span of the pairwise subtractions with a given point on the right. -/ lemma vector_span_eq_span_vsub_set_right {s : set P} {p : P} (hp : p ∈ s) : vector_span k s = submodule.span k ((-ᵥ p) '' s) := begin rw vector_span_def, refine le_antisymm _ (submodule.span_mono _), { rw submodule.span_le, rintros v ⟨p1, p2, hp1, hp2, hv⟩, rw ←vsub_sub_vsub_cancel_right p1 p2 p at hv, rw [←hv, submodule.mem_coe, submodule.mem_span], exact λ m hm, submodule.sub_mem _ (hm ⟨p1, hp1, rfl⟩) (hm ⟨p2, hp2, rfl⟩) }, { rintros v ⟨p2, hp2, hv⟩, exact ⟨p2, p, hp2, hp, hv⟩ } end /-- The `vector_span` is the span of the pairwise subtractions with a given point on the left, excluding the subtraction of that point from itself. -/ lemma vector_span_eq_span_vsub_set_left_ne {s : set P} {p : P} (hp : p ∈ s) : vector_span k s = submodule.span k ((-ᵥ) p '' (s \ {p})) := begin conv_lhs { rw [vector_span_eq_span_vsub_set_left k hp, ←set.insert_eq_of_mem hp, ←set.insert_diff_singleton, set.image_insert_eq] }, simp [submodule.span_insert_eq_span] end /-- The `vector_span` is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ lemma vector_span_eq_span_vsub_set_right_ne {s : set P} {p : P} (hp : p ∈ s) : vector_span k s = submodule.span k ((-ᵥ p) '' (s \ {p})) := begin conv_lhs { rw [vector_span_eq_span_vsub_set_right k hp, ←set.insert_eq_of_mem hp, ←set.insert_diff_singleton, set.image_insert_eq] }, simp [submodule.span_insert_eq_span] end /-- The `vector_span` of the image of a function is the span of the pairwise subtractions with a given point on the left, excluding the subtraction of that point from itself. -/ lemma vector_span_image_eq_span_vsub_set_left_ne (p : ι → P) {s : set ι} {i : ι} (hi : i ∈ s) : vector_span k (p '' s) = submodule.span k ((-ᵥ) (p i) '' (p '' (s \ {i}))) := begin conv_lhs { rw [vector_span_eq_span_vsub_set_left k (set.mem_image_of_mem p hi), ←set.insert_eq_of_mem hi, ←set.insert_diff_singleton, set.image_insert_eq, set.image_insert_eq] }, simp [submodule.span_insert_eq_span] end /-- The `vector_span` of the image of a function is the span of the pairwise subtractions with a given point on the right, excluding the subtraction of that point from itself. -/ lemma vector_span_image_eq_span_vsub_set_right_ne (p : ι → P) {s : set ι} {i : ι} (hi : i ∈ s) : vector_span k (p '' s) = submodule.span k ((-ᵥ (p i)) '' (p '' (s \ {i}))) := begin conv_lhs { rw [vector_span_eq_span_vsub_set_right k (set.mem_image_of_mem p hi), ←set.insert_eq_of_mem hi, ←set.insert_diff_singleton, set.image_insert_eq, set.image_insert_eq] }, simp [submodule.span_insert_eq_span] end /-- The `vector_span` of an indexed family is the span of the pairwise subtractions with a given point on the left. -/ lemma vector_span_range_eq_span_range_vsub_left (p : ι → P) (i0 : ι) : vector_span k (set.range p) = submodule.span k (set.range (λ (i : ι), p i0 -ᵥ p i)) := by rw [vector_span_eq_span_vsub_set_left k (set.mem_range_self i0), ←set.range_comp] /-- The `vector_span` of an indexed family is the span of the pairwise subtractions with a given point on the right. -/ lemma vector_span_range_eq_span_range_vsub_right (p : ι → P) (i0 : ι) : vector_span k (set.range p) = submodule.span k (set.range (λ (i : ι), p i -ᵥ p i0)) := by rw [vector_span_eq_span_vsub_set_right k (set.mem_range_self i0), ←set.range_comp] /-- The affine span of a set is nonempty if and only if that set is. -/ lemma affine_span_nonempty (s : set P) : (affine_span k s : set P).nonempty ↔ s.nonempty := span_points_nonempty k s variables {k} /-- Suppose a set of vectors spans `V`. Then a point `p`, together with those vectors added to `p`, spans `P`. -/ lemma affine_span_singleton_union_vadd_eq_top_of_span_eq_top {s : set V} (p : P) (h : submodule.span k (set.range (coe : s → V)) = ⊤) : affine_span k ({p} ∪ (λ v, v +ᵥ p) '' s) = ⊤ := begin convert ext_of_direction_eq _ ⟨p, mem_affine_span k (set.mem_union_left _ (set.mem_singleton _)), mem_top k V p⟩, rw [direction_affine_span, direction_top, vector_span_eq_span_vsub_set_right k ((set.mem_union_left _ (set.mem_singleton _)) : p ∈ _), eq_top_iff, ←h], apply submodule.span_mono, rintros v ⟨v', rfl⟩, use (v' : V) +ᵥ p, simp end variables (k) /-- `affine_span` is monotone. -/ lemma affine_span_mono {s₁ s₂ : set P} (h : s₁ ⊆ s₂) : affine_span k s₁ ≤ affine_span k s₂ := span_points_subset_coe_of_subset_coe (set.subset.trans h (subset_affine_span k _)) /-- Taking the affine span of a set, adding a point and taking the span again produces the same results as adding the point to the set and taking the span. -/ lemma affine_span_insert_affine_span (p : P) (ps : set P) : affine_span k (insert p (affine_span k ps : set P)) = affine_span k (insert p ps) := by rw [set.insert_eq, set.insert_eq, span_union, span_union, affine_span_coe] /-- If a point is in the affine span of a set, adding it to that set does not change the affine span. -/ lemma affine_span_insert_eq_affine_span {p : P} {ps : set P} (h : p ∈ affine_span k ps) : affine_span k (insert p ps) = affine_span k ps := begin rw ←mem_coe at h, rw [←affine_span_insert_affine_span, set.insert_eq_of_mem h, affine_span_coe] end end affine_space' namespace affine_subspace variables {k : Type*} {V : Type*} {P : Type*} [ring k] [add_comm_group V] [module k V] [affine_space V P] include V /-- The direction of the sup of two nonempty affine subspaces is the sup of the two directions and of any one difference between points in the two subspaces. -/ lemma direction_sup {s1 s2 : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s1) (hp2 : p2 ∈ s2) : (s1 ⊔ s2).direction = s1.direction ⊔ s2.direction ⊔ submodule.span k {p2 -ᵥ p1} := begin refine le_antisymm _ _, { change (affine_span k ((s1 : set P) ∪ s2)).direction ≤ _, rw ←mem_coe at hp1, rw [direction_affine_span, vector_span_eq_span_vsub_set_right k (set.mem_union_left _ hp1), submodule.span_le], rintros v ⟨p3, hp3, rfl⟩, cases hp3, { rw [sup_assoc, sup_comm, submodule.mem_coe, submodule.mem_sup], use [0, submodule.zero_mem _, p3 -ᵥ p1, vsub_mem_direction hp3 hp1], rw zero_add }, { rw [sup_assoc, submodule.mem_coe, submodule.mem_sup], use [0, submodule.zero_mem _, p3 -ᵥ p1], rw [and_comm, zero_add], use rfl, rw [←vsub_add_vsub_cancel p3 p2 p1, submodule.mem_sup], use [p3 -ᵥ p2, vsub_mem_direction hp3 hp2, p2 -ᵥ p1, submodule.mem_span_singleton_self _] } }, { refine sup_le (sup_direction_le _ _) _, rw [direction_eq_vector_span, vector_span_def], exact Inf_le_Inf (λ p hp, set.subset.trans (set.singleton_subset_iff.2 (vsub_mem_vsub_set (mem_span_points k p2 _ (set.mem_union_right _ hp2)) (mem_span_points k p1 _ (set.mem_union_left _ hp1)))) hp) } end /-- The direction of the span of the result of adding a point to a nonempty affine subspace is the sup of the direction of that subspace and of any one difference between that point and a point in the subspace. -/ lemma direction_affine_span_insert {s : affine_subspace k P} {p1 p2 : P} (hp1 : p1 ∈ s) : (affine_span k (insert p2 (s : set P))).direction = submodule.span k {p2 -ᵥ p1} ⊔ s.direction := begin rw [sup_comm, ←set.union_singleton, ←coe_affine_span_singleton k V p2], change (s ⊔ affine_span k {p2}).direction = _, rw [direction_sup hp1 (mem_affine_span k (set.mem_singleton _)), direction_affine_span], simp end /-- Given a point `p1` in an affine subspace `s`, and a point `p2`, a point `p` is in the span of `s` with `p2` added if and only if it is a multiple of `p2 -ᵥ p1` added to a point in `s`. -/ lemma mem_affine_span_insert_iff {s : affine_subspace k P} {p1 : P} (hp1 : p1 ∈ s) (p2 p : P) : p ∈ affine_span k (insert p2 (s : set P)) ↔ ∃ (r : k) (p0 : P) (hp0 : p0 ∈ s), p = r • (p2 -ᵥ p1 : V) +ᵥ p0 := begin rw ←mem_coe at hp1, rw [←vsub_right_mem_direction_iff_mem (mem_affine_span k (set.mem_insert_of_mem _ hp1)), direction_affine_span_insert hp1, submodule.mem_sup], split, { rintros ⟨v1, hv1, v2, hv2, hp⟩, rw submodule.mem_span_singleton at hv1, rcases hv1 with ⟨r, rfl⟩, use [r, v2 +ᵥ p1, vadd_mem_of_mem_direction hv2 hp1], symmetry' at hp, rw [←sub_eq_zero_iff_eq, ←vsub_vadd_eq_vsub_sub, vsub_eq_zero_iff_eq] at hp, rw [hp, vadd_assoc] }, { rintros ⟨r, p3, hp3, rfl⟩, use [r • (p2 -ᵥ p1), submodule.mem_span_singleton.2 ⟨r, rfl⟩, p3 -ᵥ p1, vsub_mem_direction hp3 hp1], rw [vadd_vsub_assoc, add_comm] } end end affine_subspace /-- An `affine_map k P1 P2` is a map from `P1` to `P2` that induces a corresponding linear map from `V1` to `V2`. -/ structure affine_map (k : Type*) {V1 : Type*} (P1 : Type*) {V2 : Type*} (P2 : Type*) [ring k] [add_comm_group V1] [module k V1] [affine_space V1 P1] [add_comm_group V2] [module k V2] [affine_space V2 P2] := (to_fun : P1 → P2) (linear : linear_map k V1 V2) (map_vadd' : ∀ (p : P1) (v : V1), to_fun (v +ᵥ p) = linear v +ᵥ to_fun p) namespace affine_map variables {k : Type*} {V1 : Type*} {P1 : Type*} {V2 : Type*} {P2 : Type*} {V3 : Type*} {P3 : Type*} {V4 : Type*} {P4 : Type*} [ring k] [add_comm_group V1] [module k V1] [affine_space V1 P1] [add_comm_group V2] [module k V2] [affine_space V2 P2] [add_comm_group V3] [module k V3] [affine_space V3 P3] [add_comm_group V4] [module k V4] [affine_space V4 P4] include V1 V2 instance: has_coe_to_fun (affine_map k P1 P2) := ⟨_, to_fun⟩ /-- Constructing an affine map and coercing back to a function produces the same map. -/ @[simp] lemma coe_mk (f : P1 → P2) (linear add) : ((mk f linear add : affine_map k P1 P2) : P1 → P2) = f := rfl /-- `to_fun` is the same as the result of coercing to a function. -/ @[simp] lemma to_fun_eq_coe (f : affine_map k P1 P2) : f.to_fun = ⇑f := rfl /-- An affine map on the result of adding a vector to a point produces the same result as the linear map applied to that vector, added to the affine map applied to that point. -/ @[simp] lemma map_vadd (f : affine_map k P1 P2) (p : P1) (v : V1) : f (v +ᵥ p) = f.linear v +ᵥ f p := f.map_vadd' p v /-- The linear map on the result of subtracting two points is the result of subtracting the result of the affine map on those two points. -/ @[simp] lemma linear_map_vsub (f : affine_map k P1 P2) (p1 p2 : P1) : f.linear (p1 -ᵥ p2) = f p1 -ᵥ f p2 := by conv_rhs { rw [←vsub_vadd p1 p2, map_vadd, vadd_vsub] } /-- Two affine maps are equal if they coerce to the same function. -/ @[ext] lemma ext {f g : affine_map k P1 P2} (h : ∀ p, f p = g p) : f = g := begin rcases f with ⟨f, f_linear, f_add⟩, rcases g with ⟨g, g_linear, g_add⟩, have : f = g := funext h, subst g, congr' with v, cases (add_torsor.nonempty : nonempty P1) with p, apply vadd_right_cancel (f p), erw [← f_add, ← g_add] end lemma ext_iff {f g : affine_map k P1 P2} : f = g ↔ ∀ p, f p = g p := ⟨λ h p, h ▸ rfl, ext⟩ variables (k P1) /-- Constant function as an `affine_map`. -/ def const (p : P2) : affine_map k P1 P2 := { to_fun := function.const P1 p, linear := 0, map_vadd' := λ p v, by simp } @[simp] lemma coe_const (p : P2) : ⇑(const k P1 p) = function.const P1 p := rfl @[simp] lemma const_linear (p : P2) : (const k P1 p).linear = 0 := rfl variables {k P1} instance nonempty : nonempty (affine_map k P1 P2) := (add_torsor.nonempty : nonempty P2).elim $ λ p, ⟨const k P1 p⟩ /-- Construct an affine map by verifying the relation between the map and its linear part at one base point. Namely, this function takes a map `f : P₁ → P₂`, a linear map `f' : V₁ →ₗ[k] V₂`, and a point `p` such that for any other point `p'` we have `f p' = f' (p' -ᵥ p) +ᵥ f p`. -/ def mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p : P1) (h : ∀ p' : P1, f p' = f' (p' -ᵥ p) +ᵥ f p) : affine_map k P1 P2 := { to_fun := f, linear := f', map_vadd' := λ p' v, by rw [h, h p', vadd_vsub_assoc, f'.map_add, vadd_assoc] } @[simp] lemma coe_mk' (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : ⇑(mk' f f' p h) = f := rfl @[simp] lemma mk'_linear (f : P1 → P2) (f' : V1 →ₗ[k] V2) (p h) : (mk' f f' p h).linear = f' := rfl /-- The set of affine maps to a vector space is an additive commutative group. -/ instance : add_comm_group (affine_map k P1 V2) := { zero := ⟨0, 0, λ p v, (zero_vadd _ _).symm⟩, add := λ f g, ⟨f + g, f.linear + g.linear, λ p v, by simp [add_add_add_comm]⟩, neg := λ f, ⟨-f, -f.linear, λ p v, by simp [add_comm]⟩, add_assoc := λ f₁ f₂ f₃, ext $ λ p, add_assoc _ _ _, zero_add := λ f, ext $ λ p, zero_add (f p), add_zero := λ f, ext $ λ p, add_zero (f p), add_comm := λ f g, ext $ λ p, add_comm (f p) (g p), add_left_neg := λ f, ext $ λ p, add_left_neg (f p) } @[simp, norm_cast] lemma coe_zero : ⇑(0 : affine_map k P1 V2) = 0 := rfl @[simp] lemma zero_linear : (0 : affine_map k P1 V2).linear = 0 := rfl @[simp, norm_cast] lemma coe_add (f g : affine_map k P1 V2) : ⇑(f + g) = f + g := rfl @[simp] lemma add_linear (f g : affine_map k P1 V2) : (f + g).linear = f.linear + g.linear := rfl /-- The space of affine maps from `P1` to `P2` is an affine space over the space of affine spaces from `P1` to the vector `V2` corresponding to `P2`. -/ instance : affine_space (affine_map k P1 V2) (affine_map k P1 P2) := { vadd := λ f g, ⟨λ p, f p +ᵥ g p, f.linear + g.linear, λ p v, by simp [vadd_assoc, add_right_comm]⟩, zero_vadd' := λ f, ext $ λ p, zero_vadd _ (f p), vadd_assoc' := λ f₁ f₂ f₃, ext $ λ p, vadd_assoc (f₁ p) (f₂ p) (f₃ p), vsub := λ f g, ⟨λ p, f p -ᵥ g p, f.linear - g.linear, λ p v, by simp [vsub_vadd_eq_vsub_sub, vadd_vsub_assoc, add_sub, sub_add_eq_add_sub]⟩, vsub_vadd' := λ f g, ext $ λ p, vsub_vadd (f p) (g p), vadd_vsub' := λ f g, ext $ λ p, vadd_vsub (f p) (g p) } @[simp] lemma vadd_apply (f : affine_map k P1 V2) (g : affine_map k P1 P2) (p : P1) : (f +ᵥ g) p = f p +ᵥ g p := rfl @[simp] lemma vsub_apply (f g : affine_map k P1 P2) (p : P1) : (f -ᵥ g : affine_map k P1 V2) p = f p -ᵥ g p := rfl variables (k P1) omit V2 /-- Identity map as an affine map. -/ def id : affine_map k P1 P1 := { to_fun := id, linear := linear_map.id, map_vadd' := λ p v, rfl } /-- The identity affine map acts as the identity. -/ @[simp] lemma coe_id : ⇑(id k P1) = _root_.id := rfl @[simp] lemma id_linear : (id k P1).linear = linear_map.id := rfl variable {P1} /-- The identity affine map acts as the identity. -/ lemma id_apply (p : P1) : id k P1 p = p := rfl variables {k P1} instance : inhabited (affine_map k P1 P1) := ⟨id k P1⟩ include V2 V3 /-- Composition of affine maps. -/ def comp (f : affine_map k P2 P3) (g : affine_map k P1 P2) : affine_map k P1 P3 := { to_fun := f ∘ g, linear := f.linear.comp g.linear, map_vadd' := begin intros p v, rw [function.comp_app, g.map_vadd, f.map_vadd], refl end } /-- Composition of affine maps acts as applying the two functions. -/ @[simp] lemma coe_comp (f : affine_map k P2 P3) (g : affine_map k P1 P2) : ⇑(f.comp g) = f ∘ g := rfl /-- Composition of affine maps acts as applying the two functions. -/ lemma comp_apply (f : affine_map k P2 P3) (g : affine_map k P1 P2) (p : P1) : f.comp g p = f (g p) := rfl omit V3 @[simp] lemma comp_id (f : affine_map k P1 P2) : f.comp (id k P1) = f := ext $ λ p, rfl @[simp] lemma id_comp (f : affine_map k P1 P2) : (id k P2).comp f = f := ext $ λ p, rfl include V3 V4 lemma comp_assoc (f₃₄ : affine_map k P3 P4) (f₂₃ : affine_map k P2 P3) (f₁₂ : affine_map k P1 P2) : (f₃₄.comp f₂₃).comp f₁₂ = f₃₄.comp (f₂₃.comp f₁₂) := rfl omit V2 V3 V4 instance : monoid (affine_map k P1 P1) := { one := id k P1, mul := comp, one_mul := id_comp, mul_one := comp_id, mul_assoc := comp_assoc } @[simp] lemma coe_mul (f g : affine_map k P1 P1) : ⇑(f * g) = f ∘ g := rfl @[simp] lemma coe_one : ⇑(1 : affine_map k P1 P1) = _root_.id := rfl /-- The affine map from `k` to `P1` sending `0` to `p` and `1` to `v +ᵥ p`. -/ def line_map (p : P1) (v : V1) : affine_map k k P1 := { to_fun := λ c, c • v +ᵥ p, linear := linear_map.id.smul_right v, map_vadd' := λ a b, by simp [add_smul, vadd_assoc] } lemma line_map_apply (p : P1) (v : V1) (c : k) : line_map p v c = c • v +ᵥ p := rfl @[simp] lemma line_map_linear (p : P1) (v : V1) : (line_map p v : affine_map k k P1).linear = linear_map.id.smul_right v := rfl @[simp] lemma line_map_zero (p : P1) : line_map p (0:V1) = const k k p := by { ext c, simp [line_map_apply] } @[simp] lemma line_map_apply_zero (p : P1) (v : V1) : line_map p v (0:k) = p := by simp [line_map_apply] include V2 @[simp] lemma affine_apply_line_map (f : affine_map k P1 P2) (p : P1) (v : V1) (c : k) : f (line_map p v c) = line_map (f p) (f.linear v) c := by simp [line_map_apply] @[simp] lemma affine_comp_line_map (f : affine_map k P1 P2) (p : P1) (v : V1) : f.comp (line_map p v) = line_map (f p) (f.linear v) := ext $ f.affine_apply_line_map p v omit V2 lemma line_map_vadd_neg (p : P1) (v : V1) : line_map (v +ᵥ p) (-v) = (line_map p v).comp (line_map (1:k) (-1:k)) := by { rw [affine_comp_line_map], simp [line_map_apply] } /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ lemma decomp (f : affine_map k V1 V2) : (f : V1 → V2) = f.linear + (λ z, f 0) := begin ext x, calc f x = f.linear x +ᵥ f 0 : by simp [← f.map_vadd] ... = (f.linear.to_fun + λ (z : V1), f 0) x : by simp end /-- Decomposition of an affine map in the special case when the point space and vector space are the same. -/ lemma decomp' (f : affine_map k V1 V2) : (f.linear : V1 → V2) = f - (λ z, f 0) := by rw decomp ; simp only [linear_map.map_zero, pi.add_apply, add_sub_cancel, zero_add] end affine_map namespace affine_map variables {k : Type*} {V1 : Type*} {P1 : Type*} {V2 : Type*} [comm_ring k] [add_comm_group V1] [module k V1] [affine_space V1 P1] [add_comm_group V2] [module k V2] include V1 /-- If `k` is a commutative ring, then the set of affine maps with codomain in a `k`-module is a `k`-module. -/ instance : module k (affine_map k P1 V2) := { smul := λ c f, ⟨c • f, c • f.linear, λ p v, by simp [smul_add]⟩, one_smul := λ f, ext $ λ p, one_smul _ _, mul_smul := λ c₁ c₂ f, ext $ λ p, mul_smul _ _ _, smul_add := λ c f g, ext $ λ p, smul_add _ _ _, smul_zero := λ c, ext $ λ p, smul_zero _, add_smul := λ c₁ c₂ f, ext $ λ p, add_smul _ _ _, zero_smul := λ f, ext $ λ p, zero_smul _ _ } @[simp] lemma coe_smul (c : k) (f : affine_map k P1 V2) : ⇑(c • f) = c • f := rfl /-- `homothety c r` is the homothety about `c` with scale factor `r`. -/ def homothety (c : P1) (r : k) : affine_map k P1 P1 := r • (id k P1 -ᵥ const k P1 c) +ᵥ const k P1 c lemma homothety_def (c : P1) (r : k) : homothety c r = r • (id k P1 -ᵥ const k P1 c) +ᵥ const k P1 c := rfl lemma homothety_apply (c : P1) (r : k) (p : P1) : homothety c r p = r • (p -ᵥ c : V1) +ᵥ c := rfl @[simp] lemma homothety_one (c : P1) : homothety c (1:k) = id k P1 := by { ext p, simp [homothety_apply] } lemma homothety_mul (c : P1) (r₁ r₂ : k) : homothety c (r₁ * r₂) = (homothety c r₁).comp (homothety c r₂) := by { ext p, simp [homothety_apply, mul_smul] } @[simp] lemma homothety_zero (c : P1) : homothety c (0:k) = const k P1 c := by { ext p, simp [homothety_apply] } @[simp] lemma homothety_add (c : P1) (r₁ r₂ : k) : homothety c (r₁ + r₂) = r₁ • (id k P1 -ᵥ const k P1 c) +ᵥ homothety c r₂ := by simp only [homothety_def, add_smul, vadd_assoc] /-- `homothety` as a multiplicative monoid homomorphism. -/ def homothety_hom (c : P1) : k →* affine_map k P1 P1 := ⟨homothety c, homothety_one c, homothety_mul c⟩ @[simp] lemma coe_homothety_hom (c : P1) : ⇑(homothety_hom c : k →* _) = homothety c := rfl /-- `homothety` as an affine map. -/ def homothety_affine (c : P1) : affine_map k k (affine_map k P1 P1) := ⟨homothety c, (linear_map.lsmul k _).flip (id k P1 -ᵥ const k P1 c), function.swap (homothety_add c)⟩ @[simp] lemma coe_homothety_affine (c : P1) : ⇑(homothety_affine c : affine_map k k _) = homothety c := rfl end affine_map namespace linear_map variables {k : Type*} {V₁ : Type*} {V₂ : Type*} [ring k] [add_comm_group V₁] [module k V₁] [add_comm_group V₂] [module k V₂] (f : V₁ →ₗ[k] V₂) /-- Reinterpret a linear map as an affine map. -/ def to_affine_map : affine_map k V₁ V₂ := { to_fun := f, linear := f, map_vadd' := λ p v, f.map_add v p } @[simp] lemma coe_to_affine_map : ⇑f.to_affine_map = f := rfl @[simp] lemma to_affine_map_linear : f.to_affine_map.linear = f := rfl end linear_map
82c015197fee3aa57dd6653e9d5076c7ee4bb600
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/set/intervals/disjoint.lean
d75bf2f58d4c1e1a4753e12c4b43afa7c78f6e7b
[]
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,210
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Yury Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.set.lattice import Mathlib.PostPort universes u namespace Mathlib /-! # Extra lemmas about intervals This file contains lemmas about intervals that cannot be included into `data.set.intervals.basic` because this would create an `import` cycle. Namely, lemmas in this file can use definitions from `data.set.lattice`, including `disjoint`. -/ namespace set @[simp] theorem Iic_disjoint_Ioi {α : Type u} [preorder α] {a : α} {b : α} (h : a ≤ b) : disjoint (Iic a) (Ioi b) := sorry @[simp] theorem Iic_disjoint_Ioc {α : Type u} [preorder α] {a : α} {b : α} {c : α} (h : a ≤ b) : disjoint (Iic a) (Ioc b c) := disjoint.mono (le_refl (Iic a)) (fun (_x : α) => and.left) (Iic_disjoint_Ioi h) @[simp] theorem Ioc_disjoint_Ioc_same {α : Type u} [preorder α] {a : α} {b : α} {c : α} : disjoint (Ioc a b) (Ioc b c) := disjoint.mono (fun (_x : α) => and.right) (le_refl (Ioc b c)) (Iic_disjoint_Ioc (le_refl b)) @[simp] theorem Ico_disjoint_Ico_same {α : Type u} [preorder α] {a : α} {b : α} {c : α} : disjoint (Ico a b) (Ico b c) := fun (x : α) (hx : x ∈ Ico a b ⊓ Ico b c) => not_le_of_lt (and.right (and.left hx)) (and.left (and.right hx)) @[simp] theorem Ico_disjoint_Ico {α : Type u} [linear_order α] {a₁ : α} {a₂ : α} {b₁ : α} {b₂ : α} : disjoint (Ico a₁ a₂) (Ico b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := sorry @[simp] theorem Ioc_disjoint_Ioc {α : Type u} [linear_order α] {a₁ : α} {a₂ : α} {b₁ : α} {b₂ : α} : disjoint (Ioc a₁ a₂) (Ioc b₁ b₂) ↔ min a₂ b₂ ≤ max a₁ b₁ := sorry /-- If two half-open intervals are disjoint and the endpoint of one lies in the other, then it must be equal to the endpoint of the other. -/ theorem eq_of_Ico_disjoint {α : Type u} [linear_order α] {x₁ : α} {x₂ : α} {y₁ : α} {y₂ : α} (h : disjoint (Ico x₁ x₂) (Ico y₁ y₂)) (hx : x₁ < x₂) (h2 : x₂ ∈ Ico y₁ y₂) : y₁ = x₂ := sorry
eac87da0a01e0398d21dea1d148db9436656ab56
f70b31f6396d12f83817534a1579ad4102d34497
/solution.lean
dfbb1b0b83f461b25eb14ae5040d4d62d7f4330f
[]
no_license
asi1024/topprover-lean-example
cf3eeb017ebfc5547c56d41f490b471d54783171
3507da918fe235599776f6367e2603c0375e00e0
refs/heads/master
1,609,053,679,942
1,580,697,001,000
1,580,697,001,000
237,811,882
0
0
null
null
null
null
UTF-8
Lean
false
false
209
lean
import .problem theorem solution : prob := begin intros p q, assume Hpq : p ∧ q, have Hp : p, from and.elim_left Hpq, have Hq : q, from and.elim_right Hpq, show q ∧ p, from and.intro Hq Hp, end
22a4606b34defc08e4a4ddfc912c380f480b6698
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/algebra/order/group/densely_ordered.lean
822613485febac3d9b23dc60d66ce57d68ca1766
[ "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
1,277
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.order.monoid.canonical.defs import algebra.order.group.defs import algebra.order.monoid.order_dual /-! # Lemmas about densely linearly ordered groups. -/ variables {α : Type*} section densely_ordered variables [group α] [linear_order α] variables [covariant_class α α (*) (≤)] variables [densely_ordered α] {a b c : α} @[to_additive] lemma le_of_forall_lt_one_mul_le (h : ∀ ε < 1, a * ε ≤ b) : a ≤ b := @le_of_forall_one_lt_le_mul αᵒᵈ _ _ _ _ _ _ _ _ h @[to_additive] lemma le_of_forall_one_lt_div_le (h : ∀ ε : α, 1 < ε → a / ε ≤ b) : a ≤ b := le_of_forall_lt_one_mul_le $ λ ε ε1, by simpa only [div_eq_mul_inv, inv_inv] using h ε⁻¹ (left.one_lt_inv_iff.2 ε1) @[to_additive] lemma le_iff_forall_one_lt_le_mul : a ≤ b ↔ ∀ ε, 1 < ε → a ≤ b * ε := ⟨λ h ε ε_pos, le_mul_of_le_of_one_le h ε_pos.le, le_of_forall_one_lt_le_mul⟩ @[to_additive] lemma le_iff_forall_lt_one_mul_le : a ≤ b ↔ ∀ ε < 1, a * ε ≤ b := @le_iff_forall_one_lt_le_mul αᵒᵈ _ _ _ _ _ _ end densely_ordered
bdd9b3078c7cd6be5bd9a1e2b2284c0ca2ea0c23
bb31430994044506fa42fd667e2d556327e18dfe
/src/algebraic_geometry/elliptic_curve/weierstrass.lean
15703ad46c5dac968d15e02b544e5e29cb4b9f12
[ "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
23,106
lean
/- Copyright (c) 2021 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, David Kurniadi Angdinata -/ import algebra.cubic_discriminant import ring_theory.class_group import tactic.linear_combination /-! # Weierstrass equations of elliptic curves We give a working definition of an elliptic curve as a nonsingular Weierstrass curve given by a Weierstrass equation, which is mathematically accurate in many cases but also good for computation. ## Mathematical background Let `S` be a scheme. The actual category of elliptic curves over `S` is a large category, whose objects are schemes `E` equipped with a map `E → S`, a section `S → E`, and some axioms (the map is smooth and proper and the fibres are geometrically-connected one-dimensional group varieties). In the special case where `S` is the spectrum of some commutative ring `R` whose Picard group is zero (this includes all fields, all PIDs, and many other commutative rings) it can be shown (using a lot of algebro-geometric machinery) that every elliptic curve `E` is a projective plane cubic isomorphic to a Weierstrass curve given by the equation $Y^2 + a_1XY + a_3Y = X^3 + a_2X^2 + a_4X + a_6$ for some $a_i$ in `R`, and such that a certain quantity called the discriminant of `E` is a unit in `R`. If `R` is a field, this quantity divides the discriminant of a cubic polynomial whose roots over a splitting field of `R` are precisely the $X$-coordinates of the non-zero 2-torsion points of `E`. ## Main definitions * `weierstrass_curve`: a Weierstrass curve over a commutative ring. * `weierstrass_curve.Δ`: the discriminant of a Weierstrass curve. * `weierstrass_curve.variable_change`: the Weierstrass curve induced by a change of variables. * `weierstrass_curve.base_change`: the Weierstrass curve base changed over an algebra. * `weierstrass_curve.two_torsion_polynomial`: the 2-torsion polynomial of a Weierstrass curve. * `weierstrass_curve.polynomial`: the polynomial associated to a Weierstrass curve. * `weierstrass_curve.equation`: the Weirstrass equation of a Weierstrass curve. * `weierstrass_curve.nonsingular`: the nonsingular condition at a point on a Weierstrass curve. * `weierstrass_curve.coordinate_ring`: the coordinate ring of a Weierstrass curve. * `weierstrass_curve.function_field`: the function field of a Weierstrass curve. * `elliptic_curve`: an elliptic curve over a commutative ring. * `elliptic_curve.j`: the j-invariant of an elliptic curve. ## Main statements * `weierstrass_curve.two_torsion_polynomial_disc`: the discriminant of a Weierstrass curve is a constant factor of the cubic discriminant of its 2-torsion polynomial. * `weierstrass_curve.nonsingular_of_Δ_ne_zero`: a Weierstrass curve is nonsingular at every point if its discriminant is non-zero. * `weierstrass_curve.coordinate_ring.is_domain`: the coordinate ring of a Weierstrass curve is an integral domain. * `elliptic_curve.nonsingular`: an elliptic curve is nonsingular at every point. * `elliptic_curve.variable_change_j`: the j-invariant of an elliptic curve is invariant under an admissible linear change of variables. ## Implementation notes The definition of elliptic curves in this file makes sense for all commutative rings `R`, but it only gives a type which can be beefed up to a category which is equivalent to the category of elliptic curves over the spectrum $\mathrm{Spec}(R)$ of `R` in the case that `R` has trivial Picard group $\mathrm{Pic}(R)$ or, slightly more generally, when its 12-torsion is trivial. The issue is that for a general ring `R`, there might be elliptic curves over $\mathrm{Spec}(R)$ in the sense of algebraic geometry which are not globally defined by a cubic equation valid over the entire base. ## References * [N Katz and B Mazur, *Arithmetic Moduli of Elliptic Curves*][katz_mazur] * [P Deligne, *Courbes Elliptiques: Formulaire (d'après J. Tate)*][deligne_formulaire] * [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, weierstrass equation, j invariant -/ private meta def map_simp : tactic unit := `[simp only [map_one, map_bit0, map_bit1, map_neg, map_add, map_sub, map_mul, map_pow]] private meta def eval_simp : tactic unit := `[simp only [eval_C, eval_X, eval_add, eval_sub, eval_mul, eval_pow]] universes u v variable {R : Type u} /-! ## Weierstrass curves -/ /-- A Weierstrass curve $Y^2 + a_1XY + a_3Y = X^3 + a_2X^2 + a_4X + a_6$ with parameters $a_i$. -/ @[ext] structure weierstrass_curve (R : Type u) := (a₁ a₂ a₃ a₄ a₆ : R) instance [inhabited R] : inhabited $ weierstrass_curve R := ⟨⟨default, default, default, default, default⟩⟩ namespace weierstrass_curve variables [comm_ring R] (W : weierstrass_curve R) section quantity /-! ### Standard quantities -/ /-- The `b₂` coefficient of a Weierstrass curve. -/ @[simp] def b₂ : R := W.a₁ ^ 2 + 4 * W.a₂ /-- The `b₄` coefficient of a Weierstrass curve. -/ @[simp] def b₄ : R := 2 * W.a₄ + W.a₁ * W.a₃ /-- The `b₆` coefficient of a Weierstrass curve. -/ @[simp] def b₆ : R := W.a₃ ^ 2 + 4 * W.a₆ /-- The `b₈` coefficient of a Weierstrass curve. -/ @[simp] def b₈ : R := W.a₁ ^ 2 * W.a₆ + 4 * W.a₂ * W.a₆ - W.a₁ * W.a₃ * W.a₄ + W.a₂ * W.a₃ ^ 2 - W.a₄ ^ 2 lemma b_relation : 4 * W.b₈ = W.b₂ * W.b₆ - W.b₄ ^ 2 := by { simp only [b₂, b₄, b₆, b₈], ring1 } /-- The `c₄` coefficient of a Weierstrass curve. -/ @[simp] def c₄ : R := W.b₂ ^ 2 - 24 * W.b₄ /-- The `c₆` coefficient of a Weierstrass curve. -/ @[simp] def c₆ : R := -W.b₂ ^ 3 + 36 * W.b₂ * W.b₄ - 216 * W.b₆ /-- The discriminant `Δ` of a Weierstrass curve. If `R` is a field, then this polynomial vanishes if and only if the cubic curve cut out by this equation is singular. Sometimes only defined up to sign in the literature; we choose the sign used by the LMFDB. For more discussion, see [the LMFDB page on discriminants](https://www.lmfdb.org/knowledge/show/ec.discriminant). -/ @[simp] def Δ : R := -W.b₂ ^ 2 * W.b₈ - 8 * W.b₄ ^ 3 - 27 * W.b₆ ^ 2 + 9 * W.b₂ * W.b₄ * W.b₆ lemma c_relation : 1728 * W.Δ = W.c₄ ^ 3 - W.c₆ ^ 2 := by { simp only [b₂, b₄, b₆, b₈, c₄, c₆, Δ], ring1 } end quantity section variable_change /-! ### Variable changes -/ variables (u : Rˣ) (r s t : R) /-- The Weierstrass curve over `R` induced by an admissible linear change of variables $(X, Y) \mapsto (u^2X + r, u^3Y + u^2sX + t)$ for some $u \in R^\times$ and some $r, s, t \in R$. -/ @[simps] def variable_change : weierstrass_curve R := { a₁ := ↑u⁻¹ * (W.a₁ + 2 * s), a₂ := ↑u⁻¹ ^ 2 * (W.a₂ - s * W.a₁ + 3 * r - s ^ 2), a₃ := ↑u⁻¹ ^ 3 * (W.a₃ + r * W.a₁ + 2 * t), a₄ := ↑u⁻¹ ^ 4 * (W.a₄ - s * W.a₃ + 2 * r * W.a₂ - (t + r * s) * W.a₁ + 3 * r ^ 2 - 2 * s * t), a₆ := ↑u⁻¹ ^ 6 * (W.a₆ + r * W.a₄ + r ^ 2 * W.a₂ + r ^ 3 - t * W.a₃ - t ^ 2 - r * t * W.a₁) } @[simp] lemma variable_change_b₂ : (W.variable_change u r s t).b₂ = ↑u⁻¹ ^ 2 * (W.b₂ + 12 * r) := by { simp only [b₂, variable_change_a₁, variable_change_a₂], ring1 } @[simp] lemma variable_change_b₄ : (W.variable_change u r s t).b₄ = ↑u⁻¹ ^ 4 * (W.b₄ + r * W.b₂ + 6 * r ^ 2) := by { simp only [b₂, b₄, variable_change_a₁, variable_change_a₃, variable_change_a₄], ring1 } @[simp] lemma variable_change_b₆ : (W.variable_change u r s t).b₆ = ↑u⁻¹ ^ 6 * (W.b₆ + 2 * r * W.b₄ + r ^ 2 * W.b₂ + 4 * r ^ 3) := by { simp only [b₂, b₄, b₆, variable_change_a₃, variable_change_a₆], ring1 } @[simp] lemma variable_change_b₈ : (W.variable_change u r s t).b₈ = ↑u⁻¹ ^ 8 * (W.b₈ + 3 * r * W.b₆ + 3 * r ^ 2 * W.b₄ + r ^ 3 * W.b₂ + 3 * r ^ 4) := by { simp only [b₂, b₄, b₆, b₈, variable_change_a₁, variable_change_a₂, variable_change_a₃, variable_change_a₄, variable_change_a₆], ring1 } @[simp] lemma variable_change_c₄ : (W.variable_change u r s t).c₄ = ↑u⁻¹ ^ 4 * W.c₄ := by { simp only [c₄, variable_change_b₂, variable_change_b₄], ring1 } @[simp] lemma variable_change_c₆ : (W.variable_change u r s t).c₆ = ↑u⁻¹ ^ 6 * W.c₆ := by { simp only [c₆, variable_change_b₂, variable_change_b₄, variable_change_b₆], ring1 } @[simp] lemma variable_change_Δ : (W.variable_change u r s t).Δ = ↑u⁻¹ ^ 12 * W.Δ := by { dsimp, ring1 } end variable_change section base_change /-! ### Base changes -/ variables (A : Type v) [comm_ring A] [algebra R A] /-- The Weierstrass curve over `R` base changed to `A`. -/ @[simps] def base_change : weierstrass_curve A := ⟨algebra_map R A W.a₁, algebra_map R A W.a₂, algebra_map R A W.a₃, algebra_map R A W.a₄, algebra_map R A W.a₆⟩ @[simp] lemma base_change_b₂ : (W.base_change A).b₂ = algebra_map R A W.b₂ := by { simp only [b₂, base_change_a₁, base_change_a₂], map_simp } @[simp] lemma base_change_b₄ : (W.base_change A).b₄ = algebra_map R A W.b₄ := by { simp only [b₄, base_change_a₁, base_change_a₃, base_change_a₄], map_simp } @[simp] lemma base_change_b₆ : (W.base_change A).b₆ = algebra_map R A W.b₆ := by { simp only [b₆, base_change_a₃, base_change_a₆], map_simp } @[simp] lemma base_change_b₈ : (W.base_change A).b₈ = algebra_map R A W.b₈ := by { simp only [b₈, base_change_a₁, base_change_a₂, base_change_a₃, base_change_a₄, base_change_a₆], map_simp } @[simp] lemma base_change_c₄ : (W.base_change A).c₄ = algebra_map R A W.c₄ := by { simp only [c₄, base_change_b₂, base_change_b₄], map_simp } @[simp] lemma base_change_c₆ : (W.base_change A).c₆ = algebra_map R A W.c₆ := by { simp only [c₆, base_change_b₂, base_change_b₄, base_change_b₆], map_simp } @[simp, nolint simp_nf] lemma base_change_Δ : (W.base_change A).Δ = algebra_map R A W.Δ := by { simp only [Δ, base_change_b₂, base_change_b₄, base_change_b₆, base_change_b₈], map_simp } end base_change section torsion_polynomial /-! ### 2-torsion polynomials -/ /-- A cubic polynomial whose discriminant is a multiple of the Weierstrass curve discriminant. If `W` is an elliptic curve over a field `R` of characteristic different from 2, then its roots over a splitting field of `R` are precisely the $X$-coordinates of the non-zero 2-torsion points of `W`. -/ def two_torsion_polynomial : cubic R := ⟨4, W.b₂, 2 * W.b₄, W.b₆⟩ lemma two_torsion_polynomial_disc : W.two_torsion_polynomial.disc = 16 * W.Δ := by { dsimp [two_torsion_polynomial, cubic.disc], ring1 } lemma two_torsion_polynomial_disc_is_unit [invertible (2 : R)] : is_unit W.two_torsion_polynomial.disc ↔ is_unit W.Δ := begin rw [two_torsion_polynomial_disc, is_unit.mul_iff, show (16 : R) = 2 ^ 4, by norm_num1], exact and_iff_right (is_unit_of_invertible $ 2 ^ 4) end lemma two_torsion_polynomial_disc_ne_zero [nontrivial R] [invertible (2 : R)] (hΔ : is_unit W.Δ) : W.two_torsion_polynomial.disc ≠ 0 := (W.two_torsion_polynomial_disc_is_unit.mpr hΔ).ne_zero end torsion_polynomial section polynomial /-! ### Weierstrass polynomials and equations -/ open polynomial open_locale polynomial /-- The polynomial $W(X, Y) := Y^2 + a_1XY + a_3Y - (X^3 + a_2X^2 + a_4X + a_6)$ associated to a Weierstrass curve `W` over `R`. For ease of polynomial manipulation, this is represented as a term of type `R[X][X]`, where the inner variable represents $X$ and the outer variable represents $Y$. -/ protected noncomputable def polynomial : R[X][X] := X ^ 2 + C (C W.a₁ * X + C W.a₃) * X - C (X ^ 3 + C W.a₂ * X ^ 2 + C W.a₄ * X + C W.a₆) lemma polynomial_eq : W.polynomial = cubic.to_poly ⟨0, 1, cubic.to_poly ⟨0, 0, W.a₁, W.a₃⟩, cubic.to_poly ⟨-1, -W.a₂, -W.a₄, -W.a₆⟩⟩ := by { simp only [weierstrass_curve.polynomial, cubic.to_poly, C_0, C_1, C_neg, C_add, C_mul], ring1 } lemma polynomial_ne_zero [nontrivial R] : W.polynomial ≠ 0 := by { rw [polynomial_eq], exact cubic.ne_zero_of_b_ne_zero one_ne_zero } lemma degree_polynomial [nontrivial R] : W.polynomial.degree = 2 := by { rw [polynomial_eq], exact cubic.degree_of_b_ne_zero' one_ne_zero } lemma nat_degree_polynomial [nontrivial R] : W.polynomial.nat_degree = 2 := by { rw [polynomial_eq], exact cubic.nat_degree_of_b_ne_zero' one_ne_zero } lemma monic_polynomial : W.polynomial.monic := by { nontriviality R, simpa only [polynomial_eq] using cubic.monic_of_b_eq_one' } lemma irreducible_polynomial [nontrivial R] [no_zero_divisors R] : irreducible W.polynomial := begin by_contra h, rcases (W.monic_polynomial.not_irreducible_iff_exists_add_mul_eq_coeff W.nat_degree_polynomial).mp h with ⟨f, g, h0, h1⟩, simp only [polynomial_eq, cubic.coeff_eq_c, cubic.coeff_eq_d] at h0 h1, apply_fun degree at h0 h1, rw [cubic.degree_of_a_ne_zero' $ neg_ne_zero.mpr $ one_ne_zero' R, degree_mul] at h0, apply (h1.symm.le.trans cubic.degree_of_b_eq_zero').not_lt, rcases nat.with_bot.add_eq_three_iff.mp h0.symm with h | h | h | h, any_goals { rw [degree_add_eq_left_of_degree_lt]; simp only [h]; dec_trivial }, any_goals { rw [degree_add_eq_right_of_degree_lt]; simp only [h]; dec_trivial } end @[simp] lemma eval_polynomial (x y : R) : eval x (eval (C y) W.polynomial) = y ^ 2 + W.a₁ * x * y + W.a₃ * y - (x ^ 3 + W.a₂ * x ^ 2 + W.a₄ * x + W.a₆) := by { simp only [weierstrass_curve.polynomial], eval_simp, rw [add_mul, ← add_assoc] } @[simp] lemma eval_polynomial_zero : eval 0 (eval 0 W.polynomial) = -W.a₆ := by simp only [← C_0, eval_polynomial, zero_add, zero_sub, mul_zero, zero_pow (nat.zero_lt_succ _)] /-- The proposition that an affine point $(x, y)$ lies in `W`. In other words, $W(x, y) = 0$. -/ def equation (x y : R) : Prop := eval x (eval (C y) W.polynomial) = 0 lemma equation_iff' (x y : R) : W.equation x y ↔ y ^ 2 + W.a₁ * x * y + W.a₃ * y - (x ^ 3 + W.a₂ * x ^ 2 + W.a₄ * x + W.a₆) = 0 := by rw [equation, eval_polynomial] @[simp] lemma equation_iff (x y : R) : W.equation x y ↔ y ^ 2 + W.a₁ * x * y + W.a₃ * y = x ^ 3 + W.a₂ * x ^ 2 + W.a₄ * x + W.a₆ := by rw [equation_iff', sub_eq_zero] @[simp] lemma equation_zero : W.equation 0 0 ↔ W.a₆ = 0 := by rw [equation, C_0, eval_polynomial_zero, neg_eq_zero] lemma equation_iff_variable_change (x y : R) : W.equation x y ↔ (W.variable_change 1 x 0 y).equation 0 0 := begin rw [equation_iff', ← neg_eq_zero, equation_zero, variable_change_a₆, inv_one, units.coe_one], congr' 2, ring1 end /-! ### Nonsingularity of Weierstrass curves -/ /-- The partial derivative $W_X(X, Y)$ of $W(X, Y)$ with respect to $X$. -/ noncomputable def polynomial_X : R[X][X] := C (C W.a₁) * X - C (C 3 * X ^ 2 + C (2 * W.a₂) * X + C W.a₄) @[simp] lemma eval_polynomial_X (x y : R) : eval x (eval (C y) W.polynomial_X) = W.a₁ * y - (3 * x ^ 2 + 2 * W.a₂ * x + W.a₄) := by { simp only [polynomial_X], eval_simp } @[simp] lemma eval_polynomial_X_zero : eval 0 (eval 0 W.polynomial_X) = -W.a₄ := by simp only [← C_0, eval_polynomial_X, zero_add, zero_sub, mul_zero, zero_pow zero_lt_two] /-- The partial derivative $W_Y(X, Y)$ of $W(X, Y)$ with respect to $Y$. -/ noncomputable def polynomial_Y : R[X][X] := C (C 2) * X + C (C W.a₁ * X + C W.a₃) @[simp] lemma eval_polynomial_Y (x y : R) : eval x (eval (C y) W.polynomial_Y) = 2 * y + W.a₁ * x + W.a₃ := by { simp only [polynomial_Y], eval_simp, rw [← add_assoc] } @[simp] lemma eval_polynomial_Y_zero : eval 0 (eval 0 W.polynomial_Y) = W.a₃ := by simp only [← C_0, eval_polynomial_Y, zero_add, mul_zero] /-- The proposition that an affine point $(x, y)$ on `W` is nonsingular. In other words, either $W_X(x, y) \ne 0$ or $W_Y(x, y) \ne 0$. -/ def nonsingular (x y : R) : Prop := eval x (eval (C y) W.polynomial_X) ≠ 0 ∨ eval x (eval (C y) W.polynomial_Y) ≠ 0 lemma nonsingular_iff' (x y : R) : W.nonsingular x y ↔ W.a₁ * y - (3 * x ^ 2 + 2 * W.a₂ * x + W.a₄) ≠ 0 ∨ 2 * y + W.a₁ * x + W.a₃ ≠ 0 := by rw [nonsingular, eval_polynomial_X, eval_polynomial_Y] @[simp] lemma nonsingular_iff (x y : R) : W.nonsingular x y ↔ W.a₁ * y ≠ 3 * x ^ 2 + 2 * W.a₂ * x + W.a₄ ∨ y ≠ -y - W.a₁ * x - W.a₃ := by { rw [nonsingular_iff', sub_ne_zero, ← @sub_ne_zero _ _ y], congr' 3; ring1 } @[simp] lemma nonsingular_zero : W.nonsingular 0 0 ↔ W.a₃ ≠ 0 ∨ W.a₄ ≠ 0 := by rw [nonsingular, C_0, eval_polynomial_X_zero, neg_ne_zero, eval_polynomial_Y_zero, or_comm] lemma nonsingular_iff_variable_change (x y : R) : W.nonsingular x y ↔ (W.variable_change 1 x 0 y).nonsingular 0 0 := begin rw [nonsingular_iff', ← neg_ne_zero, or_comm, nonsingular_zero, variable_change_a₃, variable_change_a₄, inv_one, units.coe_one], congr' 3, all_goals { ring1 } end lemma nonsingular_zero_of_Δ_ne_zero (h : W.equation 0 0) (hΔ : W.Δ ≠ 0) : W.nonsingular 0 0 := by { simp only [equation_zero, nonsingular_zero] at *, contrapose! hΔ, simp [h, hΔ] } /-- A Weierstrass curve is nonsingular at every point if its discriminant is non-zero. -/ lemma nonsingular_of_Δ_ne_zero {x y : R} (h : W.equation x y) (hΔ : W.Δ ≠ 0) : W.nonsingular x y := (W.nonsingular_iff_variable_change x y).mpr $ nonsingular_zero_of_Δ_ne_zero _ ((W.equation_iff_variable_change x y).mp h) $ by rwa [variable_change_Δ, inv_one, units.coe_one, one_pow, one_mul] /-! ### The coordinate ring -/ /-- The coordinate ring $R[W] := R[X, Y] / \langle W(X, Y) \rangle$ of `W`. Note that `derive comm_ring` generates a reducible instance of `comm_ring` for `coordinate_ring`. In certain circumstances this might be extremely slow, because all instances in its definition are unified exponentially many times. In this case, one solution is to manually add the local attribute `local attribute [irreducible] coordinate_ring.comm_ring` to block this type-level unification. TODO Lean 4: verify if the new def-eq cache (lean4#1102) fixed this issue. See Zulip thread: https://leanprover.zulipchat.com/#narrow/stream/116395-maths/topic/.E2.9C.94.20class_group.2Emk -/ @[derive [inhabited, comm_ring]] def coordinate_ring : Type u := adjoin_root W.polynomial instance [is_domain R] [normalized_gcd_monoid R] : is_domain W.coordinate_ring := (ideal.quotient.is_domain_iff_prime _).mpr $ by simpa only [ideal.span_singleton_prime W.polynomial_ne_zero, ← gcd_monoid.irreducible_iff_prime] using W.irreducible_polynomial instance coordinate_ring.is_domain_of_field {F : Type u} [field F] (W : weierstrass_curve F) : is_domain W.coordinate_ring := by { classical, apply_instance } /-- The function field $R(W) := \mathrm{Frac}(R[W])$ of `W`. -/ @[reducible] def function_field : Type u := fraction_ring W.coordinate_ring variables (x : R) (y : R[X]) /-- The class of the element $X - x$ in $R[W]$ for some $x \in R$. -/ @[simp] noncomputable def X_class : W.coordinate_ring := adjoin_root.mk W.polynomial $ C $ X - C x lemma X_class_ne_zero [nontrivial R] : W.X_class x ≠ 0 := adjoin_root.mk_ne_zero_of_nat_degree_lt W.monic_polynomial (C_ne_zero.2 $ X_sub_C_ne_zero x) $ by { rw [nat_degree_polynomial, nat_degree_C], norm_num1 } /-- The class of the element $Y - y(X)$ in $R[W]$ for some $y(X) \in R[X]$. -/ @[simp] noncomputable def Y_class : W.coordinate_ring := adjoin_root.mk W.polynomial $ X - C y lemma Y_class_ne_zero [nontrivial R] : W.Y_class y ≠ 0 := adjoin_root.mk_ne_zero_of_nat_degree_lt W.monic_polynomial (X_sub_C_ne_zero _) $ by { rw [nat_degree_polynomial, nat_degree_X_sub_C], norm_num1 } /-- The ideal $\langle X - x \rangle$ of $R[W]$ for some $x \in R$. -/ @[simp] noncomputable def X_ideal : ideal W.coordinate_ring := ideal.span {W.X_class x} /-- The ideal $\langle Y - y(X) \rangle$ of $R[W]$ for some $y(X) \in R[X]$. -/ @[simp] noncomputable def Y_ideal : ideal W.coordinate_ring := ideal.span {W.Y_class y} end polynomial end weierstrass_curve /-! ## Elliptic curves -/ /-- An elliptic curve over a commutative ring. Note that this definition is only mathematically accurate for certain rings whose Picard group has trivial 12-torsion, such as a field or a PID. -/ @[ext] structure elliptic_curve (R : Type u) [comm_ring R] extends weierstrass_curve R := (Δ' : Rˣ) (coe_Δ' : ↑Δ' = to_weierstrass_curve.Δ) instance : inhabited $ elliptic_curve ℚ := ⟨⟨⟨0, 0, 1, -1, 0⟩, ⟨37, 37⁻¹, by norm_num1, by norm_num1⟩, by { dsimp, ring1 }⟩⟩ namespace elliptic_curve variables [comm_ring R] (E : elliptic_curve R) /-- The j-invariant `j` of an elliptic curve, which is invariant under isomorphisms over `R`. -/ @[simp] def j : R := ↑E.Δ'⁻¹ * E.c₄ ^ 3 lemma two_torsion_polynomial_disc_ne_zero [nontrivial R] [invertible (2 : R)] : E.two_torsion_polynomial.disc ≠ 0 := E.two_torsion_polynomial_disc_ne_zero $ E.coe_Δ' ▸ E.Δ'.is_unit lemma nonsingular [nontrivial R] {x y : R} (h : E.equation x y) : E.nonsingular x y := E.nonsingular_of_Δ_ne_zero h $ E.coe_Δ' ▸ E.Δ'.ne_zero section variable_change /-! ### Variable changes -/ variables (u : Rˣ) (r s t : R) /-- The elliptic curve over `R` induced by an admissible linear change of variables $(X, Y) \mapsto (u^2X + r, u^3Y + u^2sX + t)$ for some $u \in R^\times$ and some $r, s, t \in R$. When `R` is a field, any two Weierstrass equations isomorphic to `E` are related by this. -/ @[simps] def variable_change : elliptic_curve R := ⟨E.variable_change u r s t, u⁻¹ ^ 12 * E.Δ', by rw [units.coe_mul, units.coe_pow, coe_Δ', E.variable_change_Δ]⟩ lemma coe_variable_change_Δ' : (↑(E.variable_change u r s t).Δ' : R) = ↑u⁻¹ ^ 12 * E.Δ' := by rw [variable_change_Δ', units.coe_mul, units.coe_pow] lemma coe_inv_variable_change_Δ' : (↑(E.variable_change u r s t).Δ'⁻¹ : R) = u ^ 12 * ↑E.Δ'⁻¹ := by rw [variable_change_Δ', mul_inv, inv_pow, inv_inv, units.coe_mul, units.coe_pow] @[simp] lemma variable_change_j : (E.variable_change u r s t).j = E.j := begin rw [j, coe_inv_variable_change_Δ'], have hu : (u * ↑u⁻¹ : R) ^ 12 = 1 := by rw [u.mul_inv, one_pow], linear_combination E.j * hu with { normalization_tactic := `[dsimp, ring1] } end end variable_change section base_change /-! ### Base changes -/ variables (A : Type v) [comm_ring A] [algebra R A] /-- The elliptic curve over `R` base changed to `A`. -/ @[simps] def base_change : elliptic_curve A := ⟨E.base_change A, units.map ↑(algebra_map R A) E.Δ', by rw [units.coe_map, ring_hom.coe_monoid_hom, coe_Δ', E.base_change_Δ]⟩ lemma coe_base_change_Δ' : ↑(E.base_change A).Δ' = algebra_map R A E.Δ' := rfl lemma coe_inv_base_change_Δ' : ↑(E.base_change A).Δ'⁻¹ = algebra_map R A ↑E.Δ'⁻¹ := rfl @[simp] lemma base_change_j : (E.base_change A).j = algebra_map R A E.j := by { simp only [j, coe_inv_base_change_Δ', base_change_to_weierstrass_curve, E.base_change_c₄], map_simp } end base_change end elliptic_curve
f4a51d70c0acf9ca362e19646d816359ebe7ecdb
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
/09_Type_Classes.org.1.lean
a959419185a264dd5efd52514acc4220431d3d93
[]
no_license
cjmazey/lean-tutorial
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
refs/heads/master
1,610,286,098,832
1,447,124,923,000
1,447,124,923,000
43,082,433
0
0
null
null
null
null
UTF-8
Lean
false
false
186
lean
import standard import data.nat open nat attribute nat [class] definition one [instance] : ℕ := 1 definition foo [x : ℕ] : nat := x check @foo eval foo example : foo = 1 := rfl
23f4980b59f321fa3593606cff3f186aab5eb974
94e33a31faa76775069b071adea97e86e218a8ee
/src/category_theory/limits/cone_category.lean
a511297fa5ecf24d2390b1d46031d3ac9366a989
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
4,284
lean
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import category_theory.limits.preserves.shapes.terminal /-! # Limits and the category of (co)cones This files contains results that stem from the limit API. For the definition and the category instance of `cone`, please refer to `category_theory/limits/cones.lean`. A cone is limiting iff it is terminal in the category of cones. As a corollary, an equivalence of categories of cones preserves limiting properties. We also provide the dual. -/ namespace category_theory.limits open category_theory universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variables {J : Type u₁} [category.{v₁} J] {K : Type u₂} [category.{v₂} K] variables {C : Type u₃} [category.{v₃} C] {D : Type u₄} [category.{v₄} D] /-- A cone is a limit cone iff it is terminal. -/ def cone.is_limit_equiv_is_terminal {F : J ⥤ C} (c : cone F) : is_limit c ≃ is_terminal c := is_limit.iso_unique_cone_morphism.to_equiv.trans { to_fun := λ h, by exactI is_terminal.of_unique _, inv_fun := λ h s, ⟨⟨is_terminal.from h s⟩, λ a, is_terminal.hom_ext h a _⟩, left_inv := by tidy, right_inv := by tidy } lemma is_limit.lift_cone_morphism_eq_is_terminal_from {F : J ⥤ C} {c : cone F} (hc : is_limit c) (s : cone F) : hc.lift_cone_morphism s = is_terminal.from (cone.is_limit_equiv_is_terminal _ hc) _ := rfl lemma is_terminal.from_eq_lift_cone_morphism {F : J ⥤ C} {c : cone F} (hc : is_terminal c) (s : cone F) : is_terminal.from hc s = ((cone.is_limit_equiv_is_terminal _).symm hc).lift_cone_morphism s := by convert (is_limit.lift_cone_morphism_eq_is_terminal_from _ s).symm /-- If `G : cone F ⥤ cone F'` preserves terminal objects, it preserves limit cones. -/ def is_limit.of_preserves_cone_terminal {F : J ⥤ C} {F' : K ⥤ D} (G : cone F ⥤ cone F') [preserves_limit (functor.empty.{0} _) G] {c : cone F} (hc : is_limit c) : is_limit (G.obj c) := (cone.is_limit_equiv_is_terminal _).symm $ (cone.is_limit_equiv_is_terminal _ hc).is_terminal_obj _ _ /-- If `G : cone F ⥤ cone F'` reflects terminal objects, it reflects limit cones. -/ def is_limit.of_reflects_cone_terminal {F : J ⥤ C} {F' : K ⥤ D} (G : cone F ⥤ cone F') [reflects_limit (functor.empty.{0} _) G] {c : cone F} (hc : is_limit (G.obj c)) : is_limit c := (cone.is_limit_equiv_is_terminal _).symm $ (cone.is_limit_equiv_is_terminal _ hc).is_terminal_of_obj _ _ /-- A cocone is a colimit cocone iff it is initial. -/ def cocone.is_colimit_equiv_is_initial {F : J ⥤ C} (c : cocone F) : is_colimit c ≃ is_initial c := is_colimit.iso_unique_cocone_morphism.to_equiv.trans { to_fun := λ h, by exactI is_initial.of_unique _, inv_fun := λ h s, ⟨⟨is_initial.to h s⟩, λ a, is_initial.hom_ext h a _⟩, left_inv := by tidy, right_inv := by tidy } lemma is_colimit.desc_cocone_morphism_eq_is_initial_to {F : J ⥤ C} {c : cocone F} (hc : is_colimit c) (s : cocone F) : hc.desc_cocone_morphism s = is_initial.to (cocone.is_colimit_equiv_is_initial _ hc) _ := rfl lemma is_initial.to_eq_desc_cocone_morphism {F : J ⥤ C} {c : cocone F} (hc : is_initial c) (s : cocone F) : is_initial.to hc s = ((cocone.is_colimit_equiv_is_initial _).symm hc).desc_cocone_morphism s := by convert (is_colimit.desc_cocone_morphism_eq_is_initial_to _ s).symm /-- If `G : cocone F ⥤ cocone F'` preserves initial objects, it preserves colimit cocones. -/ def is_colimit.of_preserves_cocone_initial {F : J ⥤ C} {F' : K ⥤ D} (G : cocone F ⥤ cocone F') [preserves_colimit (functor.empty.{0} _) G] {c : cocone F} (hc : is_colimit c) : is_colimit (G.obj c) := (cocone.is_colimit_equiv_is_initial _).symm $ (cocone.is_colimit_equiv_is_initial _ hc).is_initial_obj _ _ /-- If `G : cocone F ⥤ cocone F'` reflects initial objects, it reflects colimit cocones. -/ def is_colimit.of_reflects_cocone_initial {F : J ⥤ C} {F' : K ⥤ D} (G : cocone F ⥤ cocone F') [reflects_colimit (functor.empty.{0} _) G] {c : cocone F} (hc : is_colimit (G.obj c)) : is_colimit c := (cocone.is_colimit_equiv_is_initial _).symm $ (cocone.is_colimit_equiv_is_initial _ hc).is_initial_of_obj _ _ end category_theory.limits
1e68d57d9552372399a49ebeeaea2167b629fa20
df7bb3acd9623e489e95e85d0bc55590ab0bc393
/lean/love02_backward_proofs_demo.lean
700fb76e93c42dade6c29f07a332d50ab31cfbbe
[]
no_license
MaschavanderMarel/logical_verification_2020
a41c210b9237c56cb35f6cd399e3ac2fe42e775d
7d562ef174cc6578ca6013f74db336480470b708
refs/heads/master
1,692,144,223,196
1,634,661,675,000
1,634,661,675,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
7,939
lean
import .love01_definitions_and_statements_demo /- # LoVe Demo 2: Backward Proofs A __tactic__ operates on a proof goal and either proves it or creates new subgoals. Tactics are a __backward__ proof mechanism: They start from the goal and work towards the available hypotheses and lemmas. -/ set_option pp.beta true set_option pp.generalized_field_notation false namespace LoVe namespace backward_proofs /- ## Tactic Mode Syntax of tactical proofs: begin _tactic₁_, …, _tacticN_ end -/ lemma fst_of_two_props : ∀a b : Prop, a → b → a := begin intros a b, intros ha hb, apply ha end /- ## Basic Tactics `intro`(`s`) moves `∀`-quantified variables, or the assumptions of implications `→`, from the goal's conclusion (after `⊢`) into the goal's hypotheses (before `⊢`). `apply` matches the goal's conclusion with the conclusion of the specified lemma and adds the lemma's hypotheses as new goals. -/ lemma fst_of_two_props₂ (a b : Prop) (ha : a) (hb : b) : a := begin apply ha end /- Terminal tactic syntax: by _tactic_ abbreviates begin _tactic_ end -/ lemma fst_of_two_props₃ (a b : Prop) (ha : a) (hb : b) : a := by apply ha lemma prop_comp (a b c : Prop) (hab : a → b) (hbc : b → c) : a → c := begin intro ha, apply hbc, apply hab, apply ha end /- `exact` matches the goal's conclusion with the specified lemma, closing the goal. We can often use `apply` in such situations, but `exact` communicates our intentions better. -/ lemma fst_of_two_props₄ (a b : Prop) (ha : a) (hb : b) : a := by exact ha /- `assumption` finds a hypothesis from the local context that matches the goal's conclusion and applies it to prove the goal. -/ lemma fst_of_two_props₅ (a b : Prop) (ha : a) (hb : b) : a := by assumption /- `refl` proves `l = r`, where the two sides are syntactically equal up to computation. Computation means unfolding of definitions, β-reduction (application of λ to an argument), `let`, and more. -/ lemma α_example {α β : Type} (f : α → β) : (λx, f x) = (λy, f y) := begin refl end lemma α_example₂ {α β : Type} (f : α → β) : (λx, f x) = (λy, f y) := by refl lemma β_example {α β : Type} (f : α → β) (a : α) : (λx, f x) a = f a := by refl def double (n : ℕ) : ℕ := n + n lemma δ_example : double 5 = 5 + 5 := by refl lemma ζ_example : (let n : ℕ := 2 in n + n) = 4 := by refl lemma η_example {α β : Type} (f : α → β) : (λx, f x) = f := by refl lemma ι_example {α β : Type} (a : α) (b : β) : prod.fst (a, b) = a := by refl /- ## Reasoning about Logical Connectives and Quantifiers Introduction rules: -/ #check true.intro #check not.intro #check and.intro #check or.intro_left #check or.intro_right #check iff.intro #check exists.intro /- Elimination rules: -/ #check false.elim #check and.elim_left #check and.elim_right #check or.elim #check iff.elim_left #check iff.elim_right #check exists.elim /- Definition of `¬` and related lemmas: -/ #print not #check not_def #check classical.em #check classical.by_contradiction lemma and_swap (a b : Prop) : a ∧ b → b ∧ a := begin intro hab, apply and.intro, apply and.elim_right, exact hab, apply and.elim_left, exact hab end /- The `{ … }` combinator focuses on the first subgoal. The tactic inside must fully prove it. -/ lemma and_swap₂ : ∀a b : Prop, a ∧ b → b ∧ a := begin intros a b hab, apply and.intro, { exact and.elim_right hab }, { exact and.elim_left hab } end /- Notice above how we pass the hypothesis `hab` directly to the lemmas `and.elim_right` and `and.elim_left`, instead of waiting for the lemmas's assumptions to appear as new subgoals. This is a small forward step in an otherwise backward proof. -/ lemma or_swap (a b : Prop) : a ∨ b → b ∨ a := begin intros hab, apply or.elim hab, { intro ha, exact or.intro_right _ ha }, { intro hb, exact or.intro_left _ hb } end lemma modus_ponens (a b : Prop) : (a → b) → a → b := begin intros hab ha, apply hab, exact ha end lemma not_not_intro (a : Prop) : a → ¬¬ a := begin intro ha, apply not.intro, intro hna, apply hna, exact ha end lemma not_not_intro₂ (a : Prop) : a → ¬¬ a := begin intros ha hna, apply hna, exact ha end lemma nat_exists_double_iden : ∃n : ℕ, double n = n := begin apply exists.intro 0, refl end /- ## Reasoning about Equality -/ #check eq.refl #check eq.symm #check eq.trans #check eq.subst /- The above rules can be used directly: -/ lemma cong_fst_arg {α : Type} (a a' b : α) (f : α → α → α) (ha : a = a') : f a b = f a' b := begin apply eq.subst ha, apply eq.refl end lemma cong_two_args {α : Type} (a a' b b' : α) (f : α → α → α) (ha : a = a') (hb : b = b') : f a b = f a' b' := begin apply eq.subst ha, apply eq.subst hb, apply eq.refl end /- `rw` applies a single equation as a left-to-right rewrite rule, once. To apply an equation right-to-left, prefix its name with `←`. -/ lemma cong_two_args₂ {α : Type} (a a' b b' : α) (f : α → α → α) (ha : a = a') (hb : b = b') : f a b = f a' b' := begin rw ha, rw hb end lemma a_proof_of_negation₃ (a : Prop) : a → ¬¬ a := begin rw not_def, rw not_def, intro ha, intro hna, apply hna, exact ha end /- `simp` applies a standard set of rewrite rules (the __simp set__) exhaustively. The set can be extended using the `@[simp]` attribute. Lemmas can be temporarily added to the simp set with the syntax `simp [_lemma₁_, …, _lemmaN_]`. -/ lemma cong_two_args_etc {α : Type} (a a' b b' : α) (g : α → α → ℕ → α) (ha : a = a') (hb : b = b') : g a b (1 + 1) = g a' b' 2 := by simp [ha, hb] /- `cc` applies __congruence closure__ to derive new equalities. -/ lemma cong_two_args₃ {α : Type} (a a' b b' : α) (f : α → α → α) (ha : a = a') (hb : b = b') : f a b = f a' b' := by cc /- `cc` can also reason up to associativity and commutativity of `+`, `*`, and other binary operators. -/ lemma cong_assoc_comm (a a' b c : ℝ) (f : ℝ → ℝ) (ha : a = a') : f (a + b + c) = f (c + b + a') := by cc /- ## Proofs by Mathematical Induction `induction'` performs induction on the specified variable. It gives rise to one subgoal per constructor. -/ lemma add_zero (n : ℕ) : add 0 n = n := begin induction' n, { refl }, { simp [add, ih] } end /- We use `induction'`, a variant of Lean's built-in `induction` tactic. The two tactics are similar, but `induction'` is more user-friendly. -/ lemma add_succ (m n : ℕ) : add (nat.succ m) n = nat.succ (add m n) := begin induction' n, { refl }, { simp [add, ih] } end lemma add_comm (m n : ℕ) : add m n = add n m := begin induction' n, { simp [add, add_zero] }, { simp [add, add_succ, ih] } end lemma add_assoc (l m n : ℕ) : add (add l m) n = add l (add m n) := begin induction' n, { refl }, { simp [add, ih] } end /- `cc` is extensible. We can register `add` as a commutative and associative operator using the type class instance mechanism (explained in lecture 4). This is useful for the `cc` invocation below. -/ @[instance] def add.is_commutative : is_commutative ℕ add := { comm := add_comm } @[instance] def add.is_associative : is_associative ℕ add := { assoc := add_assoc } lemma mul_add (l m n : ℕ) : mul l (add m n) = add (mul l m) (mul l n) := begin induction' n, { refl }, { simp [add, mul, ih], cc } end /- ## Cleanup Tactics `rename` changes the name of a variable or hypothesis. `clear` removes unused variables or hypotheses. -/ lemma cleanup_example (a b c : Prop) (ha : a) (hb : b) (hab : a → b) (hbc : b → c) : c := begin clear ha hab a, apply hbc, clear hbc c, rename hb h, exact h end end backward_proofs end LoVe
c2e16a9e87a5eaa536471f8a9c24a29e6615a82e
ff5230333a701471f46c57e8c115a073ebaaa448
/library/init/category/alternative.lean
41fd4ca796d5b96c1f675f9c49da9ec1e5b71747
[ "Apache-2.0" ]
permissive
stanford-cs242/lean
f81721d2b5d00bc175f2e58c57b710d465e6c858
7bd861261f4a37326dcf8d7a17f1f1f330e4548c
refs/heads/master
1,600,957,431,849
1,576,465,093,000
1,576,465,093,000
225,779,423
0
3
Apache-2.0
1,575,433,936,000
1,575,433,935,000
null
UTF-8
Lean
false
false
1,351
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import init.logic init.category.applicative universes u v class has_orelse (f : Type u → Type v) : Type (max (u+1) v) := (orelse : Π {α : Type u}, f α → f α → f α) infixr ` <|> `:2 := has_orelse.orelse class alternative (f : Type u → Type v) extends applicative f, has_orelse f : Type (max (u+1) v) := (failure : Π {α : Type u}, f α) section variables {f : Type u → Type v} [alternative f] {α : Type u} @[inline] def failure : f α := alternative.failure f /-- If the condition `p` is decided to be false, then fail, otherwise, return unit. -/ @[inline] def guard {f : Type → Type v} [alternative f] (p : Prop) [decidable p] : f unit := if p then pure () else failure @[inline] def assert {f : Type → Type v} [alternative f] (p : Prop) [decidable p] : f (inhabited p) := if h : p then pure ⟨h⟩ else failure /- Later we define a coercion from bool to Prop, but this version will still be useful. Given (t : tactic bool), we can write t >>= guardb -/ @[inline] def guardb {f : Type → Type v} [alternative f] : bool → f unit | tt := pure () | ff := failure @[inline] def optional (x : f α) : f (option α) := some <$> x <|> pure none end
0e875c5bf4d594429981a65ea9faf85ffa13741f
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/set_theory/cardinal/ordinal.lean
4d3ef1aaef7c78fa0ee4734b4a9d264a4ecc48d7
[ "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
49,442
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Floris van Doorn -/ import data.finsupp.multiset import order.bounded import set_theory.ordinal.principal import tactic.linarith /-! # Cardinals and ordinals Relationships between cardinals and ordinals, properties of cardinals that are proved using ordinals. ## Main definitions * The function `cardinal.aleph'` gives the cardinals listed by their ordinal index, and is the inverse of `cardinal.aleph_idx`. `aleph' n = n`, `aleph' ω = ℵ₀`, `aleph' (ω + 1) = succ ℵ₀`, etc. It is an order isomorphism between ordinals and cardinals. * The function `cardinal.aleph` gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. * The function `cardinal.beth` enumerates the Beth cardinals. `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ beth o`, and for a limit ordinal `o`, `beth o` is the supremum of `beth a` for `a < o`. ## Main Statements * `cardinal.mul_eq_max` and `cardinal.add_eq_max` state that the product (resp. sum) of two infinite cardinals is just their maximum. Several variations around this fact are also given. * `cardinal.mk_list_eq_mk` : when `α` is infinite, `α` and `list α` have the same cardinality. * simp lemmas for inequalities between `bit0 a` and `bit1 b` are registered, making `simp` able to prove inequalities about numeral cardinals. ## Tags cardinal arithmetic (for infinite cardinals) -/ noncomputable theory open function cardinal set equiv order open_locale classical cardinal ordinal universes u v w namespace cardinal section using_ordinals open ordinal theorem ord_is_limit {c} (co : ℵ₀ ≤ c) : (ord c).is_limit := begin refine ⟨λ h, aleph_0_ne_zero _, λ a, lt_imp_lt_of_le_imp_le (λ h, _)⟩, { rw [←ordinal.le_zero, ord_le] at h, simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h }, { rw ord_le at h ⊢, rwa [←@add_one_of_aleph_0_le (card a), ←card_succ], rw [←ord_le, ←le_succ_of_is_limit, ord_le], { exact co.trans h }, { rw ord_aleph_0, exact omega_is_limit } } end /-! ### Aleph cardinals -/ /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `aleph_idx n = n`, `aleph_idx ω = ω`, `aleph_idx ℵ₁ = ω + 1` and so on.) In this definition, we register additionally that this function is an initial segment, i.e., it is order preserving and its range is an initial segment of the ordinals. For the basic function version, see `aleph_idx`. For an upgraded version stating that the range is everything, see `aleph_idx.rel_iso`. -/ def aleph_idx.initial_seg : @initial_seg cardinal ordinal (<) (<) := @rel_embedding.collapse cardinal ordinal (<) (<) _ cardinal.ord.order_embedding.lt_embedding /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `aleph_idx n = n`, `aleph_idx ω = ω`, `aleph_idx ℵ₁ = ω + 1` and so on.) For an upgraded version stating that the range is everything, see `aleph_idx.rel_iso`. -/ def aleph_idx : cardinal → ordinal := aleph_idx.initial_seg @[simp] theorem aleph_idx.initial_seg_coe : (aleph_idx.initial_seg : cardinal → ordinal) = aleph_idx := rfl @[simp] theorem aleph_idx_lt {a b} : aleph_idx a < aleph_idx b ↔ a < b := aleph_idx.initial_seg.to_rel_embedding.map_rel_iff @[simp] theorem aleph_idx_le {a b} : aleph_idx a ≤ aleph_idx b ↔ a ≤ b := by rw [← not_lt, ← not_lt, aleph_idx_lt] theorem aleph_idx.init {a b} : b < aleph_idx a → ∃ c, aleph_idx c = b := aleph_idx.initial_seg.init _ _ /-- The `aleph'` index function, which gives the ordinal index of a cardinal. (The `aleph'` part is because unlike `aleph` this counts also the finite stages. So `aleph_idx n = n`, `aleph_idx ℵ₀ = ω`, `aleph_idx ℵ₁ = ω + 1` and so on.) In this version, we register additionally that this function is an order isomorphism between cardinals and ordinals. For the basic function version, see `aleph_idx`. -/ def aleph_idx.rel_iso : @rel_iso cardinal.{u} ordinal.{u} (<) (<) := @rel_iso.of_surjective cardinal.{u} ordinal.{u} (<) (<) aleph_idx.initial_seg.{u} $ (initial_seg.eq_or_principal aleph_idx.initial_seg.{u}).resolve_right $ λ ⟨o, e⟩, begin have : ∀ c, aleph_idx c < o := λ c, (e _).2 ⟨_, rfl⟩, refine ordinal.induction_on o _ this, introsI α r _ h, let s := ⨆ a, inv_fun aleph_idx (ordinal.typein r a), apply (lt_succ s).not_le, have I : injective aleph_idx := aleph_idx.initial_seg.to_embedding.injective, simpa only [typein_enum, left_inverse_inv_fun I (succ s)] using le_csupr (cardinal.bdd_above_range.{u u} (λ a : α, inv_fun aleph_idx (ordinal.typein r a))) (ordinal.enum r _ (h (succ s))) end @[simp] theorem aleph_idx.rel_iso_coe : (aleph_idx.rel_iso : cardinal → ordinal) = aleph_idx := rfl @[simp] theorem type_cardinal : @type cardinal (<) _ = ordinal.univ.{u (u+1)} := by rw ordinal.univ_id; exact quotient.sound ⟨aleph_idx.rel_iso⟩ @[simp] theorem mk_cardinal : #cardinal = univ.{u (u+1)} := by simpa only [card_type, card_univ] using congr_arg card type_cardinal /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. In this version, we register additionally that this function is an order isomorphism between ordinals and cardinals. For the basic function version, see `aleph'`. -/ def aleph'.rel_iso := cardinal.aleph_idx.rel_iso.symm /-- The `aleph'` function gives the cardinals listed by their ordinal index, and is the inverse of `aleph_idx`. `aleph' n = n`, `aleph' ω = ω`, `aleph' (ω + 1) = succ ℵ₀`, etc. -/ def aleph' : ordinal → cardinal := aleph'.rel_iso @[simp] theorem aleph'.rel_iso_coe : (aleph'.rel_iso : ordinal → cardinal) = aleph' := rfl @[simp] theorem aleph'_lt {o₁ o₂ : ordinal} : aleph' o₁ < aleph' o₂ ↔ o₁ < o₂ := aleph'.rel_iso.map_rel_iff @[simp] theorem aleph'_le {o₁ o₂ : ordinal} : aleph' o₁ ≤ aleph' o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph'_lt @[simp] theorem aleph'_aleph_idx (c : cardinal) : aleph' c.aleph_idx = c := cardinal.aleph_idx.rel_iso.to_equiv.symm_apply_apply c @[simp] theorem aleph_idx_aleph' (o : ordinal) : (aleph' o).aleph_idx = o := cardinal.aleph_idx.rel_iso.to_equiv.apply_symm_apply o @[simp] theorem aleph'_zero : aleph' 0 = 0 := by { rw [← nonpos_iff_eq_zero, ← aleph'_aleph_idx 0, aleph'_le], apply ordinal.zero_le } @[simp] theorem aleph'_succ {o : ordinal} : aleph' (succ o) = succ (aleph' o) := begin apply (succ_le_of_lt $ aleph'_lt.2 $ lt_succ o).antisymm' (cardinal.aleph_idx_le.1 $ _), rw [aleph_idx_aleph', succ_le_iff, ← aleph'_lt, aleph'_aleph_idx], apply lt_succ end @[simp] theorem aleph'_nat : ∀ n : ℕ, aleph' n = n | 0 := aleph'_zero | (n+1) := show aleph' (succ n) = n.succ, by rw [aleph'_succ, aleph'_nat, nat_succ] theorem aleph'_le_of_limit {o : ordinal} (l : o.is_limit) {c} : aleph' o ≤ c ↔ ∀ o' < o, aleph' o' ≤ c := ⟨λ h o' h', (aleph'_le.2 $ h'.le).trans h, λ h, begin rw [←aleph'_aleph_idx c, aleph'_le, limit_le l], intros x h', rw [←aleph'_le, aleph'_aleph_idx], exact h _ h' end⟩ theorem aleph'_limit {o : ordinal} (ho : is_limit o) : aleph' o = ⨆ a : Iio o, aleph' a := begin refine le_antisymm _ (csupr_le' (λ i, aleph'_le.2 (le_of_lt i.2))), rw aleph'_le_of_limit ho, exact λ a ha, le_csupr (bdd_above_of_small _) (⟨a, ha⟩ : Iio o) end @[simp] theorem aleph'_omega : aleph' ω = ℵ₀ := eq_of_forall_ge_iff $ λ c, begin simp only [aleph'_le_of_limit omega_is_limit, lt_omega, exists_imp_distrib, aleph_0_le], exact forall_swap.trans (forall_congr $ λ n, by simp only [forall_eq, aleph'_nat]), end /-- `aleph'` and `aleph_idx` form an equivalence between `ordinal` and `cardinal` -/ @[simp] def aleph'_equiv : ordinal ≃ cardinal := ⟨aleph', aleph_idx, aleph_idx_aleph', aleph'_aleph_idx⟩ /-- The `aleph` function gives the infinite cardinals listed by their ordinal index. `aleph 0 = ℵ₀`, `aleph 1 = succ ℵ₀` is the first uncountable cardinal, and so on. -/ def aleph (o : ordinal) : cardinal := aleph' (ω + o) @[simp] theorem aleph_lt {o₁ o₂ : ordinal} : aleph o₁ < aleph o₂ ↔ o₁ < o₂ := aleph'_lt.trans (add_lt_add_iff_left _) @[simp] theorem aleph_le {o₁ o₂ : ordinal} : aleph o₁ ≤ aleph o₂ ↔ o₁ ≤ o₂ := le_iff_le_iff_lt_iff_lt.2 aleph_lt @[simp] theorem max_aleph_eq (o₁ o₂ : ordinal) : max (aleph o₁) (aleph o₂) = aleph (max o₁ o₂) := begin cases le_total (aleph o₁) (aleph o₂) with h h, { rw [max_eq_right h, max_eq_right (aleph_le.1 h)] }, { rw [max_eq_left h, max_eq_left (aleph_le.1 h)] } end @[simp] theorem aleph_succ {o : ordinal} : aleph (succ o) = succ (aleph o) := by rw [aleph, add_succ, aleph'_succ, aleph] @[simp] theorem aleph_zero : aleph 0 = ℵ₀ := by rw [aleph, add_zero, aleph'_omega] theorem aleph_limit {o : ordinal} (ho : is_limit o) : aleph o = ⨆ a : Iio o, aleph a := begin apply le_antisymm _ (csupr_le' _), { rw [aleph, aleph'_limit (ho.add _)], refine csupr_mono' (bdd_above_of_small _) _, rintro ⟨i, hi⟩, cases lt_or_le i ω, { rcases lt_omega.1 h with ⟨n, rfl⟩, use ⟨0, ho.pos⟩, simpa using (nat_lt_aleph_0 n).le }, { exact ⟨⟨_, (sub_lt_of_le h).2 hi⟩, aleph'_le.2 (le_add_sub _ _)⟩ } }, { exact λ i, aleph_le.2 (le_of_lt i.2) } end theorem aleph_0_le_aleph' {o : ordinal} : ℵ₀ ≤ aleph' o ↔ ω ≤ o := by rw [← aleph'_omega, aleph'_le] theorem aleph_0_le_aleph (o : ordinal) : ℵ₀ ≤ aleph o := by { rw [aleph, aleph_0_le_aleph'], apply ordinal.le_add_right } theorem aleph'_pos {o : ordinal} (ho : 0 < o) : 0 < aleph' o := by rwa [←aleph'_zero, aleph'_lt] theorem aleph_pos (o : ordinal) : 0 < aleph o := aleph_0_pos.trans_le (aleph_0_le_aleph o) @[simp] theorem aleph_to_nat (o : ordinal) : (aleph o).to_nat = 0 := to_nat_apply_of_aleph_0_le $ aleph_0_le_aleph o @[simp] theorem aleph_to_part_enat (o : ordinal) : (aleph o).to_part_enat = ⊤ := to_part_enat_apply_of_aleph_0_le $ aleph_0_le_aleph o instance nonempty_out_aleph (o : ordinal) : nonempty (aleph o).ord.out.α := begin rw [out_nonempty_iff_ne_zero, ←ord_zero], exact λ h, (ord_injective h).not_gt (aleph_pos o) end theorem ord_aleph_is_limit (o : ordinal) : is_limit (aleph o).ord := ord_is_limit $ aleph_0_le_aleph _ instance (o : ordinal) : no_max_order (aleph o).ord.out.α := out_no_max_of_succ_lt (ord_aleph_is_limit o).2 theorem exists_aleph {c : cardinal} : ℵ₀ ≤ c ↔ ∃ o, c = aleph o := ⟨λ h, ⟨aleph_idx c - ω, by { rw [aleph, ordinal.add_sub_cancel_of_le, aleph'_aleph_idx], rwa [← aleph_0_le_aleph', aleph'_aleph_idx] }⟩, λ ⟨o, e⟩, e.symm ▸ aleph_0_le_aleph _⟩ theorem aleph'_is_normal : is_normal (ord ∘ aleph') := ⟨λ o, ord_lt_ord.2 $ aleph'_lt.2 $ lt_succ o, λ o l a, by simp only [ord_le, aleph'_le_of_limit l]⟩ theorem aleph_is_normal : is_normal (ord ∘ aleph) := aleph'_is_normal.trans $ add_is_normal ω theorem succ_aleph_0 : succ ℵ₀ = aleph 1 := by rw [←aleph_zero, ←aleph_succ, ordinal.succ_zero] lemma aleph_0_lt_aleph_one : ℵ₀ < aleph 1 := by { rw ←succ_aleph_0, apply lt_succ } lemma countable_iff_lt_aleph_one {α : Type*} (s : set α) : s.countable ↔ #s < aleph 1 := by rw [←succ_aleph_0, lt_succ_iff, le_aleph_0_iff_set_countable] /-- Ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded : unbounded (<) {b : ordinal | b.card.ord = b} := unbounded_lt_iff.2 $ λ a, ⟨_, ⟨(by { dsimp, rw card_ord }), (lt_ord_succ_card a).le⟩⟩ theorem eq_aleph'_of_eq_card_ord {o : ordinal} (ho : o.card.ord = o) : ∃ a, (aleph' a).ord = o := ⟨cardinal.aleph_idx.rel_iso o.card, by simpa using ho⟩ /-- `ord ∘ aleph'` enumerates the ordinals that are cardinals. -/ theorem ord_aleph'_eq_enum_card : ord ∘ aleph' = enum_ord {b : ordinal | b.card.ord = b} := begin rw [←eq_enum_ord _ ord_card_unbounded, range_eq_iff], exact ⟨aleph'_is_normal.strict_mono, ⟨(λ a, (by { dsimp, rw card_ord })), λ b hb, eq_aleph'_of_eq_card_ord hb⟩⟩ end /-- Infinite ordinals that are cardinals are unbounded. -/ theorem ord_card_unbounded' : unbounded (<) {b : ordinal | b.card.ord = b ∧ ω ≤ b} := (unbounded_lt_inter_le ω).2 ord_card_unbounded theorem eq_aleph_of_eq_card_ord {o : ordinal} (ho : o.card.ord = o) (ho' : ω ≤ o) : ∃ a, (aleph a).ord = o := begin cases eq_aleph'_of_eq_card_ord ho with a ha, use a - ω, unfold aleph, rwa ordinal.add_sub_cancel_of_le, rwa [←aleph_0_le_aleph', ←ord_le_ord, ha, ord_aleph_0] end /-- `ord ∘ aleph` enumerates the infinite ordinals that are cardinals. -/ theorem ord_aleph_eq_enum_card : ord ∘ aleph = enum_ord {b : ordinal | b.card.ord = b ∧ ω ≤ b} := begin rw ←eq_enum_ord _ ord_card_unbounded', use aleph_is_normal.strict_mono, rw range_eq_iff, refine ⟨(λ a, ⟨_, _⟩), λ b hb, eq_aleph_of_eq_card_ord hb.1 hb.2⟩, { rw card_ord }, { rw [←ord_aleph_0, ord_le_ord], exact aleph_0_le_aleph _ } end /-! ### Beth cardinals -/ /-- Beth numbers are defined so that `beth 0 = ℵ₀`, `beth (succ o) = 2 ^ (beth o)`, and when `o` is a limit ordinal, `beth o` is the supremum of `beth o'` for `o' < o`. Assuming the generalized continuum hypothesis, which is undecidable in ZFC, `beth o = aleph o` for every `o`. -/ def beth (o : ordinal.{u}) : cardinal.{u} := limit_rec_on o aleph_0 (λ _ x, 2 ^ x) (λ a ha IH, ⨆ b : Iio a, IH b.1 b.2) @[simp] theorem beth_zero : beth 0 = aleph_0 := limit_rec_on_zero _ _ _ @[simp] theorem beth_succ (o : ordinal) : beth (succ o) = 2 ^ beth o := limit_rec_on_succ _ _ _ _ theorem beth_limit {o : ordinal} : is_limit o → beth o = ⨆ a : Iio o, beth a := limit_rec_on_limit _ _ _ _ theorem beth_strict_mono : strict_mono beth := begin intros a b, induction b using ordinal.induction with b IH generalizing a, intro h, rcases zero_or_succ_or_limit b with rfl | ⟨c, rfl⟩ | hb, { exact (ordinal.not_lt_zero a h).elim }, { rw lt_succ_iff at h, rw beth_succ, apply lt_of_le_of_lt _ (cantor _), rcases eq_or_lt_of_le h with rfl | h, { refl }, exact (IH c (lt_succ c) h).le }, { apply (cantor _).trans_le, rw [beth_limit hb, ←beth_succ], exact le_csupr (bdd_above_of_small _) (⟨_, hb.succ_lt h⟩ : Iio b) } end lemma beth_mono : monotone beth := beth_strict_mono.monotone @[simp] theorem beth_lt {o₁ o₂ : ordinal} : beth o₁ < beth o₂ ↔ o₁ < o₂ := beth_strict_mono.lt_iff_lt @[simp] theorem beth_le {o₁ o₂ : ordinal} : beth o₁ ≤ beth o₂ ↔ o₁ ≤ o₂ := beth_strict_mono.le_iff_le theorem aleph_le_beth (o : ordinal) : aleph o ≤ beth o := begin apply limit_rec_on o, { simp }, { intros o h, rw [aleph_succ, beth_succ, succ_le_iff], exact (cantor _).trans_le (power_le_power_left two_ne_zero h) }, { intros o ho IH, rw [aleph_limit ho, beth_limit ho], exact csupr_mono (bdd_above_of_small _) (λ x, IH x.1 x.2) } end theorem aleph_0_le_beth (o : ordinal) : ℵ₀ ≤ beth o := (aleph_0_le_aleph o).trans $ aleph_le_beth o theorem beth_pos (o : ordinal) : 0 < beth o := aleph_0_pos.trans_le $ aleph_0_le_beth o theorem beth_ne_zero (o : ordinal) : beth o ≠ 0 := (beth_pos o).ne' lemma beth_normal : is_normal.{u} (λ o, (beth o).ord) := (is_normal_iff_strict_mono_limit _).2 ⟨ord_strict_mono.comp beth_strict_mono, λ o ho a ha, by { rw [beth_limit ho, ord_le], exact csupr_le' (λ b, ord_le.1 (ha _ b.2)) }⟩ /-! ### Properties of `mul` -/ /-- If `α` is an infinite type, then `α × α` and `α` have the same cardinality. -/ theorem mul_eq_self {c : cardinal} (h : ℵ₀ ≤ c) : c * c = c := begin refine le_antisymm _ (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph_0.trans h) c), -- the only nontrivial part is `c * c ≤ c`. We prove it inductively. refine acc.rec_on (cardinal.lt_wf.apply c) (λ c _, quotient.induction_on c $ λ α IH ol, _) h, -- consider the minimal well-order `r` on `α` (a type with cardinality `c`). rcases ord_eq α with ⟨r, wo, e⟩, resetI, letI := linear_order_of_STO r, haveI : is_well_order α (<) := wo, -- Define an order `s` on `α × α` by writing `(a, b) < (c, d)` if `max a b < max c d`, or -- the max are equal and `a < c`, or the max are equal and `a = c` and `b < d`. let g : α × α → α := λ p, max p.1 p.2, let f : α × α ↪ ordinal × (α × α) := ⟨λ p:α×α, (typein (<) (g p), p), λ p q, congr_arg prod.snd⟩, let s := f ⁻¹'o (prod.lex (<) (prod.lex (<) (<))), -- this is a well order on `α × α`. haveI : is_well_order _ s := (rel_embedding.preimage _ _).is_well_order, /- it suffices to show that this well order is smaller than `r` if it were larger, then `r` would be a strict prefix of `s`. It would be contained in `β × β` for some `β` of cardinality `< c`. By the inductive assumption, this set has the same cardinality as `β` (or it is finite if `β` is finite), so it is `< c`, which is a contradiction. -/ suffices : type s ≤ type r, {exact card_le_card this}, refine le_of_forall_lt (λ o h, _), rcases typein_surj s h with ⟨p, rfl⟩, rw [← e, lt_ord], refine lt_of_le_of_lt (_ : _ ≤ card (succ (typein (<) (g p))) * card (succ (typein (<) (g p)))) _, { have : {q | s q p} ⊆ insert (g p) {x | x < g p} ×ˢ insert (g p) {x | x < g p}, { intros q h, simp only [s, embedding.coe_fn_mk, order.preimage, typein_lt_typein, prod.lex_def, typein_inj] at h, exact max_le_iff.1 (le_iff_lt_or_eq.2 $ h.imp_right and.left) }, suffices H : (insert (g p) {x | r x (g p)} : set α) ≃ ({x | r x (g p)} ⊕ punit), { exact ⟨(set.embedding_of_subset _ _ this).trans ((equiv.set.prod _ _).trans (H.prod_congr H)).to_embedding⟩ }, refine (equiv.set.insert _).trans ((equiv.refl _).sum_congr punit_equiv_punit), apply @irrefl _ r }, cases lt_or_le (card (succ (typein (<) (g p)))) ℵ₀ with qo qo, { exact (mul_lt_aleph_0 qo qo).trans_le ol }, { suffices, {exact (IH _ this qo).trans_lt this}, rw ← lt_ord, apply (ord_is_limit ol).2, rw [mk_def, e], apply typein_lt_type } end end using_ordinals /-- If `α` and `β` are infinite types, then the cardinality of `α × β` is the maximum of the cardinalities of `α` and `β`. -/ theorem mul_eq_max {a b : cardinal} (ha : ℵ₀ ≤ a) (hb : ℵ₀ ≤ b) : a * b = max a b := le_antisymm (mul_eq_self (ha.trans (le_max_left a b)) ▸ mul_le_mul' (le_max_left _ _) (le_max_right _ _)) $ max_le (by simpa only [mul_one] using mul_le_mul_left' (one_le_aleph_0.trans hb) a) (by simpa only [one_mul] using mul_le_mul_right' (one_le_aleph_0.trans ha) b) @[simp] theorem mul_mk_eq_max {α β : Type*} [infinite α] [infinite β] : #α * #β = max (#α) (#β) := mul_eq_max (aleph_0_le_mk α) (aleph_0_le_mk β) @[simp] theorem aleph_mul_aleph (o₁ o₂ : ordinal) : aleph o₁ * aleph o₂ = aleph (max o₁ o₂) := by rw [cardinal.mul_eq_max (aleph_0_le_aleph o₁) (aleph_0_le_aleph o₂), max_aleph_eq] @[simp] theorem aleph_0_mul_eq {a : cardinal} (ha : ℵ₀ ≤ a) : ℵ₀ * a = a := (mul_eq_max le_rfl ha).trans (max_eq_right ha) @[simp] theorem mul_aleph_0_eq {a : cardinal} (ha : ℵ₀ ≤ a) : a * ℵ₀ = a := (mul_eq_max ha le_rfl).trans (max_eq_left ha) @[simp] theorem aleph_0_mul_mk_eq {α : Type*} [infinite α] : ℵ₀ * #α = #α := aleph_0_mul_eq (aleph_0_le_mk α) @[simp] theorem mk_mul_aleph_0_eq {α : Type*} [infinite α] : #α * ℵ₀ = #α := mul_aleph_0_eq (aleph_0_le_mk α) @[simp] theorem aleph_0_mul_aleph (o : ordinal) : ℵ₀ * aleph o = aleph o := aleph_0_mul_eq (aleph_0_le_aleph o) @[simp] theorem aleph_mul_aleph_0 (o : ordinal) : aleph o * ℵ₀ = aleph o := mul_aleph_0_eq (aleph_0_le_aleph o) theorem mul_lt_of_lt {a b c : cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a * b < c := (mul_le_mul' (le_max_left a b) (le_max_right a b)).trans_lt $ (lt_or_le (max a b) ℵ₀).elim (λ h, (mul_lt_aleph_0 h h).trans_le hc) (λ h, by { rw mul_eq_self h, exact max_lt h1 h2 }) lemma mul_le_max_of_aleph_0_le_left {a b : cardinal} (h : ℵ₀ ≤ a) : a * b ≤ max a b := begin convert mul_le_mul' (le_max_left a b) (le_max_right a b), rw mul_eq_self, refine h.trans (le_max_left a b) end lemma mul_eq_max_of_aleph_0_le_left {a b : cardinal} (h : ℵ₀ ≤ a) (h' : b ≠ 0) : a * b = max a b := begin cases le_or_lt ℵ₀ b with hb hb, { exact mul_eq_max h hb }, refine (mul_le_max_of_aleph_0_le_left h).antisymm _, have : b ≤ a, from hb.le.trans h, rw [max_eq_left this], convert mul_le_mul_left' (one_le_iff_ne_zero.mpr h') _, rw [mul_one], end lemma mul_eq_max_of_aleph_0_le_right {a b : cardinal} (h' : a ≠ 0) (h : ℵ₀ ≤ b) : a * b = max a b := begin rw [mul_comm, max_comm], exact mul_eq_max_of_aleph_0_le_left h h' end lemma mul_eq_max' {a b : cardinal} (h : ℵ₀ ≤ a * b) : a * b = max a b := begin rcases aleph_0_le_mul_iff.mp h with ⟨ha, hb, ha' | hb'⟩, { exact mul_eq_max_of_aleph_0_le_left ha' hb }, { exact mul_eq_max_of_aleph_0_le_right ha hb' } end theorem mul_le_max (a b : cardinal) : a * b ≤ max (max a b) ℵ₀ := begin rcases eq_or_ne a 0 with rfl | ha0, { simp }, rcases eq_or_ne b 0 with rfl | hb0, { simp }, cases le_or_lt ℵ₀ a with ha ha, { rw [mul_eq_max_of_aleph_0_le_left ha hb0], exact le_max_left _ _ }, { cases le_or_lt ℵ₀ b with hb hb, { rw [mul_comm, mul_eq_max_of_aleph_0_le_left hb ha0, max_comm], exact le_max_left _ _ }, { exact le_max_of_le_right (mul_lt_aleph_0 ha hb).le } } end lemma mul_eq_left {a b : cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) (hb' : b ≠ 0) : a * b = a := by { rw [mul_eq_max_of_aleph_0_le_left ha hb', max_eq_left hb] } lemma mul_eq_right {a b : cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) (ha' : a ≠ 0) : a * b = b := by { rw [mul_comm, mul_eq_left hb ha ha'] } lemma le_mul_left {a b : cardinal} (h : b ≠ 0) : a ≤ b * a := by { convert mul_le_mul_right' (one_le_iff_ne_zero.mpr h) _, rw [one_mul] } lemma le_mul_right {a b : cardinal} (h : b ≠ 0) : a ≤ a * b := by { rw [mul_comm], exact le_mul_left h } lemma mul_eq_left_iff {a b : cardinal} : a * b = a ↔ ((max ℵ₀ b ≤ a ∧ b ≠ 0) ∨ b = 1 ∨ a = 0) := begin rw max_le_iff, refine ⟨λ h, _, _⟩, { cases le_or_lt ℵ₀ a with ha ha, { have : a ≠ 0, { rintro rfl, exact ha.not_lt aleph_0_pos }, left, use ha, { rw ←not_lt, exact λ hb, ne_of_gt (hb.trans_le (le_mul_left this)) h }, { rintro rfl, apply this, rw mul_zero at h, exact h.symm }}, right, by_cases h2a : a = 0, { exact or.inr h2a }, have hb : b ≠ 0, { rintro rfl, apply h2a, rw mul_zero at h, exact h.symm }, left, rw [←h, mul_lt_aleph_0_iff, lt_aleph_0, lt_aleph_0] at ha, rcases ha with rfl|rfl|⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩, contradiction, contradiction, rw ←ne at h2a, rw ←one_le_iff_ne_zero at h2a hb, norm_cast at h2a hb h ⊢, apply le_antisymm _ hb, rw ←not_lt, apply λ h2b, ne_of_gt _ h, conv_lhs { rw ←mul_one n }, rwa mul_lt_mul_left, apply nat.lt_of_succ_le h2a }, { rintro (⟨⟨ha, hab⟩, hb⟩|rfl|rfl), { rw [mul_eq_max_of_aleph_0_le_left ha hb, max_eq_left hab] }, all_goals { simp }} end /-! ### Properties of `add` -/ /-- If `α` is an infinite type, then `α ⊕ α` and `α` have the same cardinality. -/ theorem add_eq_self {c : cardinal} (h : ℵ₀ ≤ c) : c + c = c := le_antisymm (by simpa only [nat.cast_bit0, nat.cast_one, mul_eq_self h, two_mul] using mul_le_mul_right' ((nat_lt_aleph_0 2).le.trans h) c) (self_le_add_left c c) /-- If `α` is an infinite type, then the cardinality of `α ⊕ β` is the maximum of the cardinalities of `α` and `β`. -/ theorem add_eq_max {a b : cardinal} (ha : ℵ₀ ≤ a) : a + b = max a b := le_antisymm (add_eq_self (ha.trans (le_max_left a b)) ▸ add_le_add (le_max_left _ _) (le_max_right _ _)) $ max_le (self_le_add_right _ _) (self_le_add_left _ _) theorem add_eq_max' {a b : cardinal} (ha : ℵ₀ ≤ b) : a + b = max a b := by rw [add_comm, max_comm, add_eq_max ha] @[simp] theorem add_mk_eq_max {α β : Type*} [infinite α] : #α + #β = max (#α) (#β) := add_eq_max (aleph_0_le_mk α) @[simp] theorem add_mk_eq_max' {α β : Type*} [infinite β] : #α + #β = max (#α) (#β) := add_eq_max' (aleph_0_le_mk β) theorem add_le_max (a b : cardinal) : a + b ≤ max (max a b) ℵ₀ := begin cases le_or_lt ℵ₀ a with ha ha, { rw [add_eq_max ha], exact le_max_left _ _ }, { cases le_or_lt ℵ₀ b with hb hb, { rw [add_comm, add_eq_max hb, max_comm], exact le_max_left _ _ }, { exact le_max_of_le_right (add_lt_aleph_0 ha hb).le } } end theorem add_le_of_le {a b c : cardinal} (hc : ℵ₀ ≤ c) (h1 : a ≤ c) (h2 : b ≤ c) : a + b ≤ c := (add_le_add h1 h2).trans $ le_of_eq $ add_eq_self hc theorem add_lt_of_lt {a b c : cardinal} (hc : ℵ₀ ≤ c) (h1 : a < c) (h2 : b < c) : a + b < c := (add_le_add (le_max_left a b) (le_max_right a b)).trans_lt $ (lt_or_le (max a b) ℵ₀).elim (λ h, (add_lt_aleph_0 h h).trans_le hc) (λ h, by rw add_eq_self h; exact max_lt h1 h2) lemma eq_of_add_eq_of_aleph_0_le {a b c : cardinal} (h : a + b = c) (ha : a < c) (hc : ℵ₀ ≤ c) : b = c := begin apply le_antisymm, { rw [← h], apply self_le_add_left }, rw[← not_lt], intro hb, have : a + b < c := add_lt_of_lt hc ha hb, simpa [h, lt_irrefl] using this end lemma add_eq_left {a b : cardinal} (ha : ℵ₀ ≤ a) (hb : b ≤ a) : a + b = a := by { rw [add_eq_max ha, max_eq_left hb] } lemma add_eq_right {a b : cardinal} (hb : ℵ₀ ≤ b) (ha : a ≤ b) : a + b = b := by { rw [add_comm, add_eq_left hb ha] } lemma add_eq_left_iff {a b : cardinal} : a + b = a ↔ (max ℵ₀ b ≤ a ∨ b = 0) := begin rw max_le_iff, refine ⟨λ h, _, _⟩, { cases (le_or_lt ℵ₀ a) with ha ha, { left, use ha, rw ←not_lt, apply λ hb, ne_of_gt _ h, exact hb.trans_le (self_le_add_left b a) }, right, rw [←h, add_lt_aleph_0_iff, lt_aleph_0, lt_aleph_0] at ha, rcases ha with ⟨⟨n, rfl⟩, ⟨m, rfl⟩⟩, norm_cast at h ⊢, rw [←add_right_inj, h, add_zero] }, { rintro (⟨h1, h2⟩|h3), { rw [add_eq_max h1, max_eq_left h2] }, { rw [h3, add_zero] } } end lemma add_eq_right_iff {a b : cardinal} : a + b = b ↔ (max ℵ₀ a ≤ b ∨ a = 0) := by { rw [add_comm, add_eq_left_iff] } lemma add_nat_eq {a : cardinal} (n : ℕ) (ha : ℵ₀ ≤ a) : a + n = a := add_eq_left ha ((nat_lt_aleph_0 _).le.trans ha) lemma add_one_eq {a : cardinal} (ha : ℵ₀ ≤ a) : a + 1 = a := add_eq_left ha (one_le_aleph_0.trans ha) @[simp] lemma mk_add_one_eq {α : Type*} [infinite α] : #α + 1 = #α := add_one_eq (aleph_0_le_mk α) protected lemma eq_of_add_eq_add_left {a b c : cardinal} (h : a + b = a + c) (ha : a < ℵ₀) : b = c := begin cases le_or_lt ℵ₀ b with hb hb, { have : a < b := ha.trans_le hb, rw [add_eq_right hb this.le, eq_comm] at h, rw [eq_of_add_eq_of_aleph_0_le h this hb] }, { have hc : c < ℵ₀, { rw ←not_le, intro hc, apply lt_irrefl ℵ₀, apply (hc.trans (self_le_add_left _ a)).trans_lt, rw ←h, apply add_lt_aleph_0 ha hb }, rw lt_aleph_0 at *, rcases ha with ⟨n, rfl⟩, rcases hb with ⟨m, rfl⟩, rcases hc with ⟨k, rfl⟩, norm_cast at h ⊢, apply add_left_cancel h } end protected lemma eq_of_add_eq_add_right {a b c : cardinal} (h : a + b = c + b) (hb : b < ℵ₀) : a = c := by { rw [add_comm a b, add_comm c b] at h, exact cardinal.eq_of_add_eq_add_left h hb } @[simp] theorem aleph_add_aleph (o₁ o₂ : ordinal) : aleph o₁ + aleph o₂ = aleph (max o₁ o₂) := by rw [cardinal.add_eq_max (aleph_0_le_aleph o₁), max_aleph_eq] theorem principal_add_ord {c : cardinal} (hc : ℵ₀ ≤ c) : ordinal.principal (+) c.ord := λ a b ha hb, by { rw [lt_ord, ordinal.card_add] at *, exact add_lt_of_lt hc ha hb } theorem principal_add_aleph (o : ordinal) : ordinal.principal (+) (aleph o).ord := principal_add_ord $ aleph_0_le_aleph o lemma add_right_inj_of_lt_aleph_0 {α β γ : cardinal} (γ₀ : γ < aleph_0) : α + γ = β + γ ↔ α = β := ⟨λ h, cardinal.eq_of_add_eq_add_right h γ₀, λ h, congr_fun (congr_arg (+) h) γ⟩ @[simp] lemma add_nat_inj {α β : cardinal} (n : ℕ) : α + n = β + n ↔ α = β := add_right_inj_of_lt_aleph_0 (nat_lt_aleph_0 _) @[simp] lemma add_one_inj {α β : cardinal} : α + 1 = β + 1 ↔ α = β := add_right_inj_of_lt_aleph_0 one_lt_aleph_0 lemma add_le_add_iff_of_lt_aleph_0 {α β γ : cardinal} (γ₀ : γ < cardinal.aleph_0) : α + γ ≤ β + γ ↔ α ≤ β := begin refine ⟨λ h, _, λ h, add_le_add_right h γ⟩, contrapose h, rw [not_le, lt_iff_le_and_ne, ne] at h ⊢, exact ⟨add_le_add_right h.1 γ, mt (add_right_inj_of_lt_aleph_0 γ₀).1 h.2⟩, end @[simp] lemma add_nat_le_add_nat_iff_of_lt_aleph_0 {α β : cardinal} (n : ℕ) : α + n ≤ β + n ↔ α ≤ β := add_le_add_iff_of_lt_aleph_0 (nat_lt_aleph_0 n) @[simp] lemma add_one_le_add_one_iff_of_lt_aleph_0 {α β : cardinal} : α + 1 ≤ β + 1 ↔ α ≤ β := add_le_add_iff_of_lt_aleph_0 one_lt_aleph_0 /-! ### Properties about power -/ theorem pow_le {κ μ : cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : μ < ℵ₀) : κ ^ μ ≤ κ := let ⟨n, H3⟩ := lt_aleph_0.1 H2 in H3.symm ▸ (quotient.induction_on κ (λ α H1, nat.rec_on n (lt_of_lt_of_le (by { rw [nat.cast_zero, power_zero], exact one_lt_aleph_0 }) H1).le (λ n ih, trans_rel_left _ (by { rw [nat.cast_succ, power_add, power_one], exact mul_le_mul_right' ih _ }) (mul_eq_self H1))) H1) theorem pow_eq {κ μ : cardinal.{u}} (H1 : ℵ₀ ≤ κ) (H2 : 1 ≤ μ) (H3 : μ < ℵ₀) : κ ^ μ = κ := (pow_le H1 H3).antisymm $ self_le_power κ H2 lemma power_self_eq {c : cardinal} (h : ℵ₀ ≤ c) : c ^ c = 2 ^ c := begin apply ((power_le_power_right $ (cantor c).le).trans _).antisymm, { convert power_le_power_right ((nat_lt_aleph_0 2).le.trans h), apply nat.cast_two.symm }, { rw [←power_mul, mul_eq_self h] } end lemma prod_eq_two_power {ι : Type u} [infinite ι] {c : ι → cardinal.{v}} (h₁ : ∀ i, 2 ≤ c i) (h₂ : ∀ i, lift.{u} (c i) ≤ lift.{v} (#ι)) : prod c = 2 ^ lift.{v} (#ι) := begin rw [← lift_id' (prod c), lift_prod, ← lift_two_power], apply le_antisymm, { refine (prod_le_prod _ _ h₂).trans_eq _, rw [prod_const, lift_lift, ← lift_power, power_self_eq (aleph_0_le_mk ι), lift_umax.{u v}] }, { rw [← prod_const', lift_prod], refine prod_le_prod _ _ (λ i, _), rw [lift_two, ← lift_two.{u v}, lift_le], exact h₁ i } end lemma power_eq_two_power {c₁ c₂ : cardinal} (h₁ : ℵ₀ ≤ c₁) (h₂ : 2 ≤ c₂) (h₂' : c₂ ≤ c₁) : c₂ ^ c₁ = 2 ^ c₁ := le_antisymm (power_self_eq h₁ ▸ power_le_power_right h₂') (power_le_power_right h₂) lemma nat_power_eq {c : cardinal.{u}} (h : ℵ₀ ≤ c) {n : ℕ} (hn : 2 ≤ n) : (n : cardinal.{u}) ^ c = 2 ^ c := power_eq_two_power h (by assumption_mod_cast) ((nat_lt_aleph_0 n).le.trans h) lemma power_nat_le {c : cardinal.{u}} {n : ℕ} (h : ℵ₀ ≤ c) : c ^ n ≤ c := pow_le h (nat_lt_aleph_0 n) lemma power_nat_eq {c : cardinal.{u}} {n : ℕ} (h1 : ℵ₀ ≤ c) (h2 : 1 ≤ n) : c ^ n = c := pow_eq h1 (by exact_mod_cast h2) (nat_lt_aleph_0 n) lemma power_nat_le_max {c : cardinal.{u}} {n : ℕ} : c ^ (n : cardinal.{u}) ≤ max c ℵ₀ := begin cases le_or_lt ℵ₀ c with hc hc, { exact le_max_of_le_left (power_nat_le hc) }, { exact le_max_of_le_right ((power_lt_aleph_0 hc (nat_lt_aleph_0 _)).le) } end lemma powerlt_aleph_0 {c : cardinal} (h : ℵ₀ ≤ c) : c ^< ℵ₀ = c := begin apply le_antisymm, { rw powerlt_le, intro c', rw lt_aleph_0, rintro ⟨n, rfl⟩, apply power_nat_le h }, convert le_powerlt c one_lt_aleph_0, rw power_one end lemma powerlt_aleph_0_le (c : cardinal) : c ^< ℵ₀ ≤ max c ℵ₀ := begin cases le_or_lt ℵ₀ c, { rw powerlt_aleph_0 h, apply le_max_left }, rw powerlt_le, exact λ c' hc', (power_lt_aleph_0 h hc').le.trans (le_max_right _ _) end /-! ### Computing cardinality of various types -/ @[simp] theorem mk_list_eq_mk (α : Type u) [infinite α] : #(list α) = #α := have H1 : ℵ₀ ≤ #α := aleph_0_le_mk α, eq.symm $ le_antisymm ⟨⟨λ x, [x], λ x y H, (list.cons.inj H).1⟩⟩ $ calc #(list α) = sum (λ n : ℕ, #α ^ (n : cardinal.{u})) : mk_list_eq_sum_pow α ... ≤ sum (λ n : ℕ, #α) : sum_le_sum _ _ $ λ n, pow_le H1 $ nat_lt_aleph_0 n ... = #α : by simp [H1] theorem mk_list_eq_aleph_0 (α : Type u) [countable α] [nonempty α] : #(list α) = ℵ₀ := mk_le_aleph_0.antisymm (aleph_0_le_mk _) theorem mk_list_eq_max_mk_aleph_0 (α : Type u) [nonempty α] : #(list α) = max (#α) ℵ₀ := begin casesI finite_or_infinite α, { rw [mk_list_eq_aleph_0, eq_comm, max_eq_right], exact mk_le_aleph_0 }, { rw [mk_list_eq_mk, eq_comm, max_eq_left], exact aleph_0_le_mk α } end theorem mk_list_le_max (α : Type u) : #(list α) ≤ max ℵ₀ (#α) := begin casesI finite_or_infinite α, { exact mk_le_aleph_0.trans (le_max_left _ _) }, { rw mk_list_eq_mk, apply le_max_right } end @[simp] theorem mk_finset_of_infinite (α : Type u) [infinite α] : #(finset α) = #α := eq.symm $ le_antisymm (mk_le_of_injective (λ x y, finset.singleton_inj.1)) $ calc #(finset α) ≤ #(list α) : mk_le_of_surjective list.to_finset_surjective ... = #α : mk_list_eq_mk α @[simp] lemma mk_finsupp_lift_of_infinite (α : Type u) (β : Type v) [infinite α] [has_zero β] [nontrivial β] : #(α →₀ β) = max (lift.{v} (#α)) (lift.{u} (#β)) := begin apply le_antisymm, { calc #(α →₀ β) ≤ # (finset (α × β)) : mk_le_of_injective (finsupp.graph_injective α β) ... = #(α × β) : mk_finset_of_infinite _ ... = max (lift.{v} (#α)) (lift.{u} (#β)) : by rw [mk_prod, mul_eq_max_of_aleph_0_le_left]; simp }, { apply max_le; rw [←lift_id (# (α →₀ β)), ←lift_umax], { cases exists_ne (0 : β) with b hb, exact lift_mk_le.{u (max u v) v}.2 ⟨⟨_, finsupp.single_left_injective hb⟩⟩ }, { inhabit α, exact lift_mk_le.{v (max u v) u}.2 ⟨⟨_, finsupp.single_injective default⟩⟩ } } end lemma mk_finsupp_of_infinite (α β : Type u) [infinite α] [has_zero β] [nontrivial β] : #(α →₀ β) = max (#α) (#β) := by simp @[simp] lemma mk_finsupp_lift_of_infinite' (α : Type u) (β : Type v) [nonempty α] [has_zero β] [infinite β] : #(α →₀ β) = max (lift.{v} (#α)) (lift.{u} (#β)) := begin casesI fintype_or_infinite α, { rw mk_finsupp_lift_of_fintype, have : ℵ₀ ≤ (#β).lift := aleph_0_le_lift.2 (aleph_0_le_mk β), rw [max_eq_right (le_trans _ this), power_nat_eq this], exacts [fintype.card_pos, lift_le_aleph_0.2 (lt_aleph_0_of_finite _).le] }, { apply mk_finsupp_lift_of_infinite }, end lemma mk_finsupp_of_infinite' (α β : Type u) [nonempty α] [has_zero β] [infinite β] : #(α →₀ β) = max (#α) (#β) := by simp lemma mk_finsupp_nat (α : Type u) [nonempty α] : #(α →₀ ℕ) = max (#α) ℵ₀ := by simp @[simp] lemma mk_multiset_of_nonempty (α : Type u) [nonempty α] : #(multiset α) = max (#α) ℵ₀ := multiset.to_finsupp.to_equiv.cardinal_eq.trans (mk_finsupp_nat α) lemma mk_multiset_of_infinite (α : Type u) [infinite α] : #(multiset α) = #α := by simp @[simp] lemma mk_multiset_of_is_empty (α : Type u) [is_empty α] : #(multiset α) = 1 := multiset.to_finsupp.to_equiv.cardinal_eq.trans (by simp) lemma mk_multiset_of_countable (α : Type u) [countable α] [nonempty α] : #(multiset α) = ℵ₀ := multiset.to_finsupp.to_equiv.cardinal_eq.trans (by simp) lemma mk_bounded_set_le_of_infinite (α : Type u) [infinite α] (c : cardinal) : #{t : set α // #t ≤ c} ≤ #α ^ c := begin refine le_trans _ (by rw [←add_one_eq (aleph_0_le_mk α)]), induction c using cardinal.induction_on with β, fapply mk_le_of_surjective, { intro f, use sum.inl ⁻¹' range f, refine le_trans (mk_preimage_of_injective _ _ (λ x y, sum.inl.inj)) _, apply mk_range_le }, rintro ⟨s, ⟨g⟩⟩, use λ y, if h : ∃(x : s), g x = y then sum.inl (classical.some h).val else sum.inr ⟨⟩, apply subtype.eq, ext, split, { rintro ⟨y, h⟩, dsimp only at h, by_cases h' : ∃ (z : s), g z = y, { rw [dif_pos h'] at h, cases sum.inl.inj h, exact (classical.some h').2 }, { rw [dif_neg h'] at h, cases h }}, { intro h, have : ∃(z : s), g z = g ⟨x, h⟩, exact ⟨⟨x, h⟩, rfl⟩, use g ⟨x, h⟩, dsimp only, rw [dif_pos this], congr', suffices : classical.some this = ⟨x, h⟩, exact congr_arg subtype.val this, apply g.2, exact classical.some_spec this } end lemma mk_bounded_set_le (α : Type u) (c : cardinal) : #{t : set α // #t ≤ c} ≤ max (#α) ℵ₀ ^ c := begin transitivity #{t : set (ulift.{u} ℕ ⊕ α) // #t ≤ c}, { refine ⟨embedding.subtype_map _ _⟩, apply embedding.image, use sum.inr, apply sum.inr.inj, intros s hs, exact mk_image_le.trans hs }, apply (mk_bounded_set_le_of_infinite (ulift.{u} ℕ ⊕ α) c).trans, rw [max_comm, ←add_eq_max]; refl end lemma mk_bounded_subset_le {α : Type u} (s : set α) (c : cardinal.{u}) : #{t : set α // t ⊆ s ∧ #t ≤ c} ≤ max (#s) ℵ₀ ^ c := begin refine le_trans _ (mk_bounded_set_le s c), refine ⟨embedding.cod_restrict _ _ _⟩, use λ t, coe ⁻¹' t.1, { rintros ⟨t, ht1, ht2⟩ ⟨t', h1t', h2t'⟩ h, apply subtype.eq, dsimp only at h ⊢, refine (preimage_eq_preimage' _ _).1 h; rw [subtype.range_coe]; assumption }, rintro ⟨t, h1t, h2t⟩, exact (mk_preimage_of_injective _ _ subtype.val_injective).trans h2t end /-! ### Properties of `compl` -/ lemma mk_compl_of_infinite {α : Type*} [infinite α] (s : set α) (h2 : #s < #α) : #(sᶜ : set α) = #α := by { refine eq_of_add_eq_of_aleph_0_le _ h2 (aleph_0_le_mk α), exact mk_sum_compl s } lemma mk_compl_finset_of_infinite {α : Type*} [infinite α] (s : finset α) : #((↑s)ᶜ : set α) = #α := by { apply mk_compl_of_infinite, exact (finset_card_lt_aleph_0 s).trans_le (aleph_0_le_mk α) } lemma mk_compl_eq_mk_compl_infinite {α : Type*} [infinite α] {s t : set α} (hs : #s < #α) (ht : #t < #α) : #(sᶜ : set α) = #(tᶜ : set α) := by { rw [mk_compl_of_infinite s hs, mk_compl_of_infinite t ht] } lemma mk_compl_eq_mk_compl_finite_lift {α : Type u} {β : Type v} [finite α] {s : set α} {t : set β} (h1 : lift.{max v w} (#α) = lift.{max u w} (#β)) (h2 : lift.{max v w} (#s) = lift.{max u w} (#t)) : lift.{max v w} (#(sᶜ : set α)) = lift.{max u w} (#(tᶜ : set β)) := begin casesI nonempty_fintype α, rcases lift_mk_eq.1 h1 with ⟨e⟩, letI : fintype β := fintype.of_equiv α e, replace h1 : fintype.card α = fintype.card β := (fintype.of_equiv_card _).symm, classical, lift s to finset α using s.to_finite, lift t to finset β using t.to_finite, simp only [finset.coe_sort_coe, mk_coe_finset, lift_nat_cast, nat.cast_inj] at h2, simp only [← finset.coe_compl, finset.coe_sort_coe, mk_coe_finset, finset.card_compl, lift_nat_cast, nat.cast_inj, h1, h2] end lemma mk_compl_eq_mk_compl_finite {α β : Type u} [finite α] {s : set α} {t : set β} (h1 : #α = #β) (h : #s = #t) : #(sᶜ : set α) = #(tᶜ : set β) := by { rw ← lift_inj, apply mk_compl_eq_mk_compl_finite_lift; rwa [lift_inj] } lemma mk_compl_eq_mk_compl_finite_same {α : Type*} [finite α] {s t : set α} (h : #s = #t) : #(sᶜ : set α) = #(tᶜ : set α) := mk_compl_eq_mk_compl_finite rfl h /-! ### Extending an injection to an equiv -/ theorem extend_function {α β : Type*} {s : set α} (f : s ↪ β) (h : nonempty ((sᶜ : set α) ≃ ((range f)ᶜ : set β))) : ∃ (g : α ≃ β), ∀ x : s, g x = f x := begin intros, have := h, cases this with g, let h : α ≃ β := (set.sum_compl (s : set α)).symm.trans ((sum_congr (equiv.of_injective f f.2) g).trans (set.sum_compl (range f))), refine ⟨h, _⟩, rintro ⟨x, hx⟩, simp [set.sum_compl_symm_apply_of_mem, hx] end theorem extend_function_finite {α β : Type*} [finite α] {s : set α} (f : s ↪ β) (h : nonempty (α ≃ β)) : ∃ (g : α ≃ β), ∀ x : s, g x = f x := begin apply extend_function f, cases id h with g, rw [← lift_mk_eq] at h, rw [←lift_mk_eq, mk_compl_eq_mk_compl_finite_lift h], rw [mk_range_eq_lift], exact f.2 end theorem extend_function_of_lt {α β : Type*} {s : set α} (f : s ↪ β) (hs : #s < #α) (h : nonempty (α ≃ β)) : ∃ (g : α ≃ β), ∀ x : s, g x = f x := begin casesI fintype_or_infinite α, { exact extend_function_finite f h }, { apply extend_function f, cases id h with g, haveI := infinite.of_injective _ g.injective, rw [← lift_mk_eq'] at h ⊢, rwa [mk_compl_of_infinite s hs, mk_compl_of_infinite], rwa [← lift_lt, mk_range_eq_of_injective f.injective, ← h, lift_lt] }, end section bit /-! This section proves inequalities for `bit0` and `bit1`, enabling `simp` to solve inequalities for numeral cardinals. The complexity of the resulting algorithm is not good, as in some cases `simp` reduces an inequality to a disjunction of two situations, depending on whether a cardinal is finite or infinite. Since the evaluation of the branches is not lazy, this is bad. It is good enough for practical situations, though. For specific numbers, these inequalities could also be deduced from the corresponding inequalities of natural numbers using `norm_cast`: ``` example : (37 : cardinal) < 42 := by { norm_cast, norm_num } ``` -/ lemma bit0_ne_zero (a : cardinal) : ¬bit0 a = 0 ↔ ¬a = 0 := by simp [bit0] @[simp] lemma bit1_ne_zero (a : cardinal) : ¬bit1 a = 0 := by simp [bit1] @[simp] lemma zero_lt_bit0 (a : cardinal) : 0 < bit0 a ↔ 0 < a := by { rw ←not_iff_not, simp [bit0], } @[simp] lemma zero_lt_bit1 (a : cardinal) : 0 < bit1 a := zero_lt_one.trans_le (self_le_add_left _ _) @[simp] lemma one_le_bit0 (a : cardinal) : 1 ≤ bit0 a ↔ 0 < a := ⟨λ h, (zero_lt_bit0 a).mp (zero_lt_one.trans_le h), λ h, (one_le_iff_pos.mpr h).trans (self_le_add_left a a)⟩ @[simp] lemma one_le_bit1 (a : cardinal) : 1 ≤ bit1 a := self_le_add_left _ _ theorem bit0_eq_self {c : cardinal} (h : ℵ₀ ≤ c) : bit0 c = c := add_eq_self h @[simp] theorem bit0_lt_aleph_0 {c : cardinal} : bit0 c < ℵ₀ ↔ c < ℵ₀ := by simp [bit0, add_lt_aleph_0_iff] @[simp] theorem aleph_0_le_bit0 {c : cardinal} : ℵ₀ ≤ bit0 c ↔ ℵ₀ ≤ c := by { rw ←not_iff_not, simp } @[simp] theorem bit1_eq_self_iff {c : cardinal} : bit1 c = c ↔ ℵ₀ ≤ c := begin by_cases h : ℵ₀ ≤ c, { simp only [bit1, bit0_eq_self h, h, eq_self_iff_true, add_one_of_aleph_0_le] }, { refine iff_of_false (ne_of_gt _) h, rcases lt_aleph_0.1 (not_le.1 h) with ⟨n, rfl⟩, norm_cast, dsimp [bit1, bit0], linarith } end @[simp] theorem bit1_lt_aleph_0 {c : cardinal} : bit1 c < ℵ₀ ↔ c < ℵ₀ := by simp [bit1, bit0, add_lt_aleph_0_iff, one_lt_aleph_0] @[simp] theorem aleph_0_le_bit1 {c : cardinal} : ℵ₀ ≤ bit1 c ↔ ℵ₀ ≤ c := by { rw ←not_iff_not, simp } @[simp] lemma bit0_le_bit0 {a b : cardinal} : bit0 a ≤ bit0 b ↔ a ≤ b := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { rw [bit0_eq_self ha, bit0_eq_self hb] }, { rw bit0_eq_self ha, refine iff_of_false (λ h, _) (hb.trans_le ha).not_le, have A : bit0 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans_le h) }, { rw bit0_eq_self hb, exact iff_of_true ((bit0_lt_aleph_0.2 ha).le.trans hb) (ha.le.trans hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, exact bit0_le_bit0 } end @[simp] lemma bit0_le_bit1 {a b : cardinal} : bit0 a ≤ bit1 b ↔ a ≤ b := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { rw [bit0_eq_self ha, bit1_eq_self_iff.2 hb] }, { rw bit0_eq_self ha, refine iff_of_false (λ h, _) (hb.trans_le ha).not_le, have A : bit1 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans_le h) }, { rw bit1_eq_self_iff.2 hb, exact iff_of_true ((bit0_lt_aleph_0.2 ha).le.trans hb) (ha.le.trans hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, exact nat.bit0_le_bit1_iff } end @[simp] lemma bit1_le_bit1 {a b : cardinal} : bit1 a ≤ bit1 b ↔ a ≤ b := ⟨λ h, bit0_le_bit1.1 ((self_le_add_right (bit0 a) 1).trans h), λ h, (add_le_add_right (add_le_add_left h a) 1).trans (add_le_add_right (add_le_add_right h b) 1)⟩ @[simp] lemma bit1_le_bit0 {a b : cardinal} : bit1 a ≤ bit0 b ↔ (a < b ∨ (a ≤ b ∧ ℵ₀ ≤ a)) := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { simp only [bit1_eq_self_iff.mpr ha, bit0_eq_self hb, ha, and_true], refine ⟨λ h, or.inr h, λ h, _⟩, cases h, { exact le_of_lt h }, { exact h } }, { rw bit1_eq_self_iff.2 ha, refine iff_of_false (λ h, _) (λ h, _), { have A : bit0 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans_le h) }, { exact not_le_of_lt (hb.trans_le ha) (h.elim le_of_lt and.left) } }, { rw bit0_eq_self hb, exact iff_of_true ((bit1_lt_aleph_0.2 ha).le.trans hb) (or.inl $ ha.trans_le hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, simp [not_le.mpr ha] } end @[simp] lemma bit0_lt_bit0 {a b : cardinal} : bit0 a < bit0 b ↔ a < b := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { rw [bit0_eq_self ha, bit0_eq_self hb] }, { rw bit0_eq_self ha, refine iff_of_false (λ h, _) (hb.le.trans ha).not_lt, have A : bit0 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans h) }, { rw bit0_eq_self hb, exact iff_of_true ((bit0_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, exact bit0_lt_bit0 } end @[simp] lemma bit1_lt_bit0 {a b : cardinal} : bit1 a < bit0 b ↔ a < b := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { rw [bit1_eq_self_iff.2 ha, bit0_eq_self hb] }, { rw bit1_eq_self_iff.2 ha, refine iff_of_false (λ h, _) (hb.le.trans ha).not_lt, have A : bit0 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans h) }, { rw bit0_eq_self hb, exact iff_of_true ((bit1_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, exact nat.bit1_lt_bit0_iff } end @[simp] lemma bit1_lt_bit1 {a b : cardinal} : bit1 a < bit1 b ↔ a < b := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { rw [bit1_eq_self_iff.2 ha, bit1_eq_self_iff.2 hb] }, { rw bit1_eq_self_iff.2 ha, refine iff_of_false (λ h, _) (hb.le.trans ha).not_lt, have A : bit1 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans h) }, { rw bit1_eq_self_iff.2 hb, exact iff_of_true ((bit1_lt_aleph_0.2 ha).trans_le hb) (ha.trans_le hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, exact bit1_lt_bit1 } end @[simp] lemma bit0_lt_bit1 {a b : cardinal} : bit0 a < bit1 b ↔ (a < b ∨ (a ≤ b ∧ a < ℵ₀)) := begin cases le_or_lt ℵ₀ a with ha ha; cases le_or_lt ℵ₀ b with hb hb, { simp [bit0_eq_self ha, bit1_eq_self_iff.2 hb, not_lt.mpr ha] }, { rw bit0_eq_self ha, refine iff_of_false (λ h, _) (λ h, _), { have A : bit1 b < ℵ₀, by simpa using hb, exact lt_irrefl _ ((A.trans_le ha).trans h) }, { exact (hb.trans_le ha).not_le (h.elim le_of_lt and.left) } }, { rw [bit1_eq_self_iff.2 hb], exact iff_of_true ((bit0_lt_aleph_0.2 ha).trans_le hb) (or.inl $ ha.trans_le hb) }, { rcases lt_aleph_0.1 ha with ⟨m, rfl⟩, rcases lt_aleph_0.1 hb with ⟨n, rfl⟩, norm_cast, simp only [ha, and_true, nat.bit0_lt_bit1_iff, or_iff_right_of_imp le_of_lt] } end lemma one_lt_two : (1 : cardinal) < 2 := -- This strategy works generally to prove inequalities between numerals in `cardinality`. by { norm_cast, norm_num } @[simp] lemma one_lt_bit0 {a : cardinal} : 1 < bit0 a ↔ 0 < a := by simp [←bit1_zero] @[simp] lemma one_lt_bit1 (a : cardinal) : 1 < bit1 a ↔ 0 < a := by simp [←bit1_zero] end bit end cardinal
a7aba3d37271436013a6a097a90f413308535b42
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/analysis/normed/group/hom_completion.lean
e3333fe0cc972f175d0b9c64295f387421be6da9
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
11,267
lean
/- Copyright (c) 2021 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot -/ import analysis.normed.group.hom import analysis.normed.group.completion /-! # Completion of normed group homs > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Given two (semi) normed groups `G` and `H` and a normed group hom `f : normed_add_group_hom G H`, we build and study a normed group hom `f.completion : normed_add_group_hom (completion G) (completion H)` such that the diagram ``` f G -----------> H | | | | | | V V completion G -----------> completion H f.completion ``` commutes. The map itself comes from the general theory of completion of uniform spaces, but here we want a normed group hom, study its operator norm and kernel. The vertical maps in the above diagrams are also normed group homs constructed in this file. ## Main definitions and results: * `normed_add_group_hom.completion`: see the discussion above. * `normed_add_comm_group.to_compl : normed_add_group_hom G (completion G)`: the canonical map from `G` to its completion, as a normed group hom * `normed_add_group_hom.completion_to_compl`: the above diagram indeed commutes. * `normed_add_group_hom.norm_completion`: `‖f.completion‖ = ‖f‖` * `normed_add_group_hom.ker_le_ker_completion`: the kernel of `f.completion` contains the image of the kernel of `f`. * `normed_add_group_hom.ker_completion`: the kernel of `f.completion` is the closure of the image of the kernel of `f` under an assumption that `f` is quantitatively surjective onto its image. * `normed_add_group_hom.extension` : if `H` is complete, the extension of `f : normed_add_group_hom G H` to a `normed_add_group_hom (completion G) H`. -/ noncomputable theory open set normed_add_group_hom uniform_space section completion variables {G : Type*} [seminormed_add_comm_group G] variables {H : Type*} [seminormed_add_comm_group H] variables {K : Type*} [seminormed_add_comm_group K] /-- The normed group hom induced between completions. -/ def normed_add_group_hom.completion (f : normed_add_group_hom G H) : normed_add_group_hom (completion G) (completion H) := { bound' := begin use ‖f‖, intro y, apply completion.induction_on y, { exact is_closed_le (continuous_norm.comp $ f.to_add_monoid_hom.continuous_completion f.continuous) (continuous_const.mul continuous_norm) }, { intro x, change ‖f.to_add_monoid_hom.completion _ ↑x‖ ≤ ‖f‖ * ‖↑x‖, rw f.to_add_monoid_hom.completion_coe f.continuous, simp only [completion.norm_coe], exact f.le_op_norm x } end, ..f.to_add_monoid_hom.completion f.continuous } lemma normed_add_group_hom.completion_def (f : normed_add_group_hom G H) (x : completion G) : f.completion x = completion.map f x := rfl @[simp] lemma normed_add_group_hom.completion_coe_to_fun (f : normed_add_group_hom G H) : (f.completion : completion G → completion H) = completion.map f := by { ext x, exact normed_add_group_hom.completion_def f x } @[simp] lemma normed_add_group_hom.completion_coe (f : normed_add_group_hom G H) (g : G) : f.completion g = f g := completion.map_coe f.uniform_continuous _ /-- Completion of normed group homs as a normed group hom. -/ @[simps] def normed_add_group_hom_completion_hom : normed_add_group_hom G H →+ normed_add_group_hom (completion G) (completion H) := { to_fun := normed_add_group_hom.completion, map_zero' := begin apply to_add_monoid_hom_injective, exact add_monoid_hom.completion_zero end, map_add' := λ f g, begin apply to_add_monoid_hom_injective, exact f.to_add_monoid_hom.completion_add g.to_add_monoid_hom f.continuous g.continuous, end } @[simp] lemma normed_add_group_hom.completion_id : (normed_add_group_hom.id G).completion = normed_add_group_hom.id (completion G) := begin ext x, rw [normed_add_group_hom.completion_def, normed_add_group_hom.coe_id, completion.map_id], refl end lemma normed_add_group_hom.completion_comp (f : normed_add_group_hom G H) (g : normed_add_group_hom H K) : g.completion.comp f.completion = (g.comp f).completion := begin ext x, rw [normed_add_group_hom.coe_comp, normed_add_group_hom.completion_def, normed_add_group_hom.completion_coe_to_fun, normed_add_group_hom.completion_coe_to_fun, completion.map_comp (normed_add_group_hom.uniform_continuous _) (normed_add_group_hom.uniform_continuous _)], refl end lemma normed_add_group_hom.completion_neg (f : normed_add_group_hom G H) : (-f).completion = -f.completion := map_neg (normed_add_group_hom_completion_hom : normed_add_group_hom G H →+ _) f lemma normed_add_group_hom.completion_add (f g : normed_add_group_hom G H) : (f + g).completion = f.completion + g.completion := normed_add_group_hom_completion_hom.map_add f g lemma normed_add_group_hom.completion_sub (f g : normed_add_group_hom G H) : (f - g).completion = f.completion - g.completion := map_sub (normed_add_group_hom_completion_hom : normed_add_group_hom G H →+ _) f g @[simp] lemma normed_add_group_hom.zero_completion : (0 : normed_add_group_hom G H).completion = 0 := normed_add_group_hom_completion_hom.map_zero /-- The map from a normed group to its completion, as a normed group hom. -/ def normed_add_comm_group.to_compl : normed_add_group_hom G (completion G) := { to_fun := coe, map_add' := completion.to_compl.map_add, bound' := ⟨1, by simp [le_refl]⟩ } open normed_add_comm_group lemma normed_add_comm_group.norm_to_compl (x : G) : ‖to_compl x‖ = ‖x‖ := completion.norm_coe x lemma normed_add_comm_group.dense_range_to_compl : dense_range (to_compl : G → completion G) := completion.dense_inducing_coe.dense @[simp] lemma normed_add_group_hom.completion_to_compl (f : normed_add_group_hom G H) : f.completion.comp to_compl = to_compl.comp f := begin ext x, change f.completion x = _, simpa end @[simp] lemma normed_add_group_hom.norm_completion (f : normed_add_group_hom G H) : ‖f.completion‖ = ‖f‖ := begin apply f.completion.op_norm_eq_of_bounds (norm_nonneg _), { intro x, apply completion.induction_on x, { apply is_closed_le, continuity }, { intro g, simp [f.le_op_norm g] } }, { intros N N_nonneg hN, apply f.op_norm_le_bound N_nonneg, intro x, simpa using hN x }, end lemma normed_add_group_hom.ker_le_ker_completion (f : normed_add_group_hom G H) : (to_compl.comp $ incl f.ker).range ≤ f.completion.ker := begin intros a h, replace h : ∃ y : f.ker, to_compl (y : G) = a, by simpa using h, rcases h with ⟨⟨g, g_in : g ∈ f.ker⟩, rfl⟩, rw f.mem_ker at g_in, change f.completion (g : completion G) = 0, simp [normed_add_group_hom.mem_ker, f.completion_coe g, g_in, completion.coe_zero], end lemma normed_add_group_hom.ker_completion {f : normed_add_group_hom G H} {C : ℝ} (h : f.surjective_on_with f.range C) : (f.completion.ker : set $ completion G) = closure (to_compl.comp $ incl f.ker).range := begin rcases h.exists_pos with ⟨C', C'_pos, hC'⟩, apply le_antisymm, { intros hatg hatg_in, rw seminormed_add_comm_group.mem_closure_iff, intros ε ε_pos, have hCf : 0 ≤ C'*‖f‖ := (zero_le_mul_left C'_pos).mpr (norm_nonneg f), have ineq : 0 < 1 + C'*‖f‖, by linarith, set δ := ε/(1 + C'*‖f‖), have δ_pos : δ > 0, from div_pos ε_pos ineq, obtain ⟨_, ⟨g : G, rfl⟩, hg : ‖hatg - g‖ < δ⟩ := seminormed_add_comm_group.mem_closure_iff.mp (completion.dense_inducing_coe.dense hatg) δ δ_pos, obtain ⟨g' : G, hgg' : f g' = f g, hfg : ‖g'‖ ≤ C' * ‖f g‖⟩ := hC' (f g) (mem_range_self g), have mem_ker : g - g' ∈ f.ker, by rw [f.mem_ker, map_sub, sub_eq_zero.mpr hgg'.symm], have : ‖f g‖ ≤ ‖f‖*‖hatg - g‖, calc ‖f g‖ = ‖f.completion g‖ : by rw [f.completion_coe, completion.norm_coe] ... = ‖f.completion g - 0‖ : by rw [sub_zero _] ... = ‖f.completion g - (f.completion hatg)‖ : by rw [(f.completion.mem_ker _).mp hatg_in] ... = ‖f.completion (g - hatg)‖ : by rw [map_sub] ... ≤ ‖f.completion‖ * ‖(g :completion G) - hatg‖ : f.completion.le_op_norm _ ... = ‖f‖ * ‖hatg - g‖ : by rw [norm_sub_rev, f.norm_completion], have : ‖(g' : completion G)‖ ≤ C'*‖f‖*‖hatg - g‖, calc ‖(g' : completion G)‖ = ‖g'‖ : completion.norm_coe _ ... ≤ C' * ‖f g‖ : hfg ... ≤ C' * ‖f‖ * ‖hatg - g‖ : by { rw mul_assoc, exact (mul_le_mul_left C'_pos).mpr this }, refine ⟨g - g', _, _⟩, { norm_cast, rw normed_add_group_hom.comp_range, apply add_subgroup.mem_map_of_mem, simp only [incl_range, mem_ker] }, { calc ‖hatg - (g - g')‖ = ‖hatg - g + g'‖ : by abel ... ≤ ‖hatg - g‖ + ‖(g' : completion G)‖ : norm_add_le _ _ ... < δ + C'*‖f‖*‖hatg - g‖ : by linarith ... ≤ δ + C'*‖f‖*δ : add_le_add_left (mul_le_mul_of_nonneg_left hg.le hCf) δ ... = (1 + C'*‖f‖)*δ : by ring ... = ε : mul_div_cancel' _ ineq.ne.symm } }, { rw ← f.completion.is_closed_ker.closure_eq, exact closure_mono f.ker_le_ker_completion } end end completion section extension variables {G : Type*} [seminormed_add_comm_group G] variables {H : Type*} [seminormed_add_comm_group H] [separated_space H] [complete_space H] /-- If `H` is complete, the extension of `f : normed_add_group_hom G H` to a `normed_add_group_hom (completion G) H`. -/ def normed_add_group_hom.extension (f : normed_add_group_hom G H) : normed_add_group_hom (completion G) H := { bound' := begin refine ⟨‖f‖, λ v, completion.induction_on v (is_closed_le _ _) (λ a, _)⟩, { exact continuous.comp continuous_norm completion.continuous_extension }, { exact continuous.mul continuous_const continuous_norm }, { rw [completion.norm_coe, add_monoid_hom.to_fun_eq_coe, add_monoid_hom.extension_coe], exact le_op_norm f a } end, ..f.to_add_monoid_hom.extension f.continuous } lemma normed_add_group_hom.extension_def (f : normed_add_group_hom G H) (v : G) : f.extension v = completion.extension f v := rfl @[simp] lemma normed_add_group_hom.extension_coe (f : normed_add_group_hom G H) (v : G) : f.extension v = f v := add_monoid_hom.extension_coe _ f.continuous _ lemma normed_add_group_hom.extension_coe_to_fun (f : normed_add_group_hom G H) : (f.extension : (completion G) → H) = completion.extension f := rfl lemma normed_add_group_hom.extension_unique (f : normed_add_group_hom G H) {g : normed_add_group_hom (completion G) H} (hg : ∀ v, f v = g v) : f.extension = g := begin ext v, rw [normed_add_group_hom.extension_coe_to_fun, completion.extension_unique f.uniform_continuous g.uniform_continuous (λ a, hg a)] end end extension
78a9bc77ebfcf499de0322fc2c2bbcb70a224785
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/topology/algebra/continuous_functions.lean
b04ab56d99d4c617f2bd3c9d86b9f95a998fa7e5
[ "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
14,314
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Nicolò Cavalleri -/ import topology.algebra.module import topology.continuous_map /-! # Algebraic structures over continuous functions In this file we define instances of algebraic sturctures over continuous functions. Instances are present both in the case of the subtype of continuous functions and the type of continuous bundled functions. Both implementations have advantages and disadvantages, but many experienced people in Zulip have expressed a preference towards continuous bundled maps, so when there is no particular reason to use the subtype, continuous bundled functions should be used for the sake of uniformity. -/ local attribute [elab_simple] continuous.comp namespace continuous_functions variables {α : Type*} {β : Type*} [topological_space α] [topological_space β] variables {f g : {f : α → β | continuous f }} instance : has_coe_to_fun {f : α → β | continuous f } := ⟨_, subtype.val⟩ end continuous_functions namespace continuous_map @[to_additive] instance has_mul {α : Type*} {β : Type*} [topological_space α] [topological_space β] [has_mul β] [has_continuous_mul β] : has_mul C(α, β) := ⟨λ f g, ⟨f * g, continuous_mul.comp (f.continuous.prod_mk g.continuous)⟩⟩ @[to_additive] instance {α : Type*} {β : Type*} [topological_space α] [topological_space β] [has_one β] : has_one C(α, β) := ⟨const (1 : β)⟩ end continuous_map section group_structure /-! ### Group stucture In this section we show that continuous functions valued in a topological group inherit the structure of a group. -/ section subtype @[to_additive] instance continuous_submonoid (α : Type*) (β : Type*) [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : is_submonoid { f : α → β | continuous f } := { one_mem := @continuous_const _ _ _ _ 1, mul_mem := λ f g fc gc, continuous.comp has_continuous_mul.continuous_mul (continuous.prod_mk fc gc) }. @[to_additive] instance continuous_subgroup (α : Type*) (β : Type*) [topological_space α] [topological_space β] [group β] [topological_group β] : is_subgroup { f : α → β | continuous f } := { inv_mem := λ f fc, continuous.comp topological_group.continuous_inv fc, ..continuous_submonoid α β, }. @[to_additive] instance continuous_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : monoid { f : α → β | continuous f } := subtype.monoid @[to_additive] instance continuous_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [group β] [topological_group β] : group { f : α → β | continuous f } := subtype.group @[to_additive] instance continuous_comm_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_group β] [topological_group β] : comm_group { f : α → β | continuous f } := @subtype.comm_group _ _ _ (continuous_subgroup α β) -- infer_instance doesn't work?! end subtype section continuous_map @[to_additive] instance continuous_map_semigroup {α : Type*} {β : Type*} [topological_space α] [topological_space β] [semigroup β] [has_continuous_mul β] : semigroup C(α, β) := { mul_assoc := λ a b c, by ext; exact mul_assoc _ _ _, ..continuous_map.has_mul} @[to_additive] instance continuous_map_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [monoid β] [has_continuous_mul β] : monoid C(α, β) := { one_mul := λ a, by ext; exact one_mul _, mul_one := λ a, by ext; exact mul_one _, ..continuous_map_semigroup, ..continuous_map.has_one } @[to_additive] instance continuous_map_comm_monoid {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_monoid β] [has_continuous_mul β] : comm_monoid C(α, β) := { one_mul := λ a, by ext; exact one_mul _, mul_one := λ a, by ext; exact mul_one _, mul_comm := λ a b, by ext; exact mul_comm _ _, ..continuous_map_semigroup, ..continuous_map.has_one } @[to_additive] instance continuous_map_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [group β] [topological_group β] : group C(α, β) := { inv := λ f, ⟨λ x, (f x)⁻¹, continuous_inv.comp f.continuous⟩, mul_left_inv := λ a, by ext; exact mul_left_inv _, ..continuous_map_monoid } @[to_additive] instance continuous_map_comm_group {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_group β] [topological_group β] : comm_group C(α, β) := { ..continuous_map_group, ..continuous_map_comm_monoid } end continuous_map end group_structure section ring_structure /-! ### Ring stucture In this section we show that continuous functions valued in a topological ring `R` inherit the structure of a ring. -/ section subtype instance continuous_subring (α : Type*) (R : Type*) [topological_space α] [topological_space R] [ring R] [topological_ring R] : is_subring { f : α → R | continuous f } := { ..continuous_add_subgroup α R, ..continuous_submonoid α R }. instance continuous_ring {α : Type*} {R : Type*} [topological_space α] [topological_space R] [ring R] [topological_ring R] : ring { f : α → R | continuous f } := @subtype.ring _ _ _ (continuous_subring α R) -- infer_instance doesn't work?! instance continuous_comm_ring {α : Type*} {R : Type*} [topological_space α] [topological_space R] [comm_ring R] [topological_ring R] : comm_ring { f : α → R | continuous f } := @subtype.comm_ring _ _ _ (continuous_subring α R) -- infer_instance doesn't work?! end subtype section continuous_map instance continuous_map_semiring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [semiring β] [topological_semiring β] : semiring C(α, β) := { left_distrib := λ a b c, by ext; exact left_distrib _ _ _, right_distrib := λ a b c, by ext; exact right_distrib _ _ _, zero_mul := λ a, by ext; exact zero_mul _, mul_zero := λ a, by ext; exact mul_zero _, ..continuous_map_add_comm_monoid, ..continuous_map_monoid } instance continuous_map_ring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [ring β] [topological_ring β] : ring C(α, β) := { ..continuous_map_semiring, ..continuous_map_add_comm_group, } instance continuous_map_comm_ring {α : Type*} {β : Type*} [topological_space α] [topological_space β] [comm_ring β] [topological_ring β] : comm_ring C(α, β) := { ..continuous_map_semiring, ..continuous_map_add_comm_group, ..continuous_map_comm_monoid,} end continuous_map end ring_structure local attribute [ext] subtype.eq section semimodule_structure /-! ### Semiodule stucture In this section we show that continuous functions valued in a topological semimodule `M` over a topological semiring `R` inherit the structure of a semimodule. -/ section subtype instance coninuous_has_scalar {α : Type*} [topological_space α] (R : Type*) [semiring R] [topological_space R] (M : Type*) [topological_space M] [add_comm_group M] [semimodule R M] [topological_semimodule R M] : has_scalar R { f : α → M | continuous f } := ⟨λ r f, ⟨r • f, continuous_const.smul f.property⟩⟩ instance continuous_semimodule {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [topological_add_group M] [semimodule R M] [topological_semimodule R M] : semimodule R { f : α → M | continuous f } := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add c (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul c₁ c₂ (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul c₁ c₂ (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end subtype section continuous_map instance continuous_map_has_scalar {α : Type*} [topological_space α] (R : Type*) [semiring R] [topological_space R] (M : Type*) [topological_space M] [add_comm_monoid M] [semimodule R M] [topological_semimodule R M] : has_scalar R C(α, M) := ⟨λ r f, ⟨r • f, continuous_const.smul f.continuous⟩⟩ instance continuous_map_semimodule {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [topological_add_group M] [semimodule R M] [topological_semimodule R M] : semimodule R C(α, M) := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add c (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul c₁ c₂ (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul c₁ c₂ (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end continuous_map end semimodule_structure section algebra_structure /-! ### Algebra structure In this section we show that continuous functions valued in a topological algebra `A` over a ring `R` inherit the structure of an algebra. Note that the hypothesis that `A` is a topological algebra is obtained by requiring that `A` be both a `topological_semimodule` and a `topological_semiring` (by now we require `topological_ring`: see TODO below).-/ section subtype variables {α : Type*} [topological_space α] {R : Type*} [comm_semiring R] {A : Type*} [topological_space A] [ring A] [algebra R A] [topological_ring A] /-- Continuous constant functions as a `ring_hom`. -/ def continuous.C : R →+* { f : α → A | continuous f } := { to_fun := λ c : R, ⟨λ x: α, ((algebra_map R A) c), continuous_const⟩, map_one' := by ext x; exact (algebra_map R A).map_one, map_mul' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_mul _ _, map_zero' := by ext x; exact (algebra_map R A).map_zero, map_add' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_add _ _ } variables [topological_space R] [topological_semimodule R A] instance : algebra R { f : α → A | continuous f } := { to_ring_hom := continuous.C, commutes' := λ c f, by ext x; exact algebra.commutes' _ _, smul_def' := λ c f, by ext x; exact algebra.smul_def' _ _, ..continuous_semimodule, ..continuous_ring } /- TODO: We are assuming `A` to be a ring and not a semiring just because there is not yet an instance of semiring. In turn, we do not want to define yet an instance of semiring because there is no `is_subsemiring` but only `subsemiring`, and it will make sense to change this when the whole file will have no more `is_subobject`s but only `subobject`s. It does not make sense to change it yet in this direction as `subring` does not exist yet, so everything is being blocked by `subring`: afterwards everything will need to be updated to the new conventions of Mathlib. Then the instance of `topological_ring` can also be removed, as it is below for `continuous_map`. -/ end subtype section continuous_map variables {α : Type*} [topological_space α] {R : Type*} [comm_semiring R] {A : Type*} [topological_space A] [semiring A] [algebra R A] [topological_semiring A] /-- Continuous constant functions as a `ring_hom`. -/ def continuous_map.C : R →+* C(α, A) := { to_fun := λ c : R, ⟨λ x: α, ((algebra_map R A) c), continuous_const⟩, map_one' := by ext x; exact (algebra_map R A).map_one, map_mul' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_mul _ _, map_zero' := by ext x; exact (algebra_map R A).map_zero, map_add' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_add _ _ } variables [topological_space R] [topological_semimodule R A] instance : algebra R C(α, A) := { to_ring_hom := continuous_map.C, commutes' := λ c f, by ext x; exact algebra.commutes' _ _, smul_def' := λ c f, by ext x; exact algebra.smul_def' _ _, ..continuous_map_semiring } end continuous_map end algebra_structure section module_over_continuous_functions /-! ### Structure as module over scalar functions If `M` is a module over `R`, then we show that the space of continuous functions from `α` to `M` is naturally a module over the algebra of continuous functions from `α` to `M`. -/ section subtype instance continuous_has_scalar' {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [semimodule R M] [topological_semimodule R M] : has_scalar { f : α → R | continuous f } { f : α → M | continuous f } := ⟨λ f g, ⟨λ x, (f x) • (g x), (continuous.smul f.2 g.2)⟩⟩ instance continuous_module' {α : Type*} [topological_space α] (R : Type*) [ring R] [topological_space R] [topological_ring R] (M : Type*) [topological_space M] [add_comm_group M] [topological_add_group M] [module R M] [topological_module R M] : module { f : α → R | continuous f } { f : α → M | continuous f } := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add (c x) (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul (c₁ x) (c₂ x) (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul (c₁ x) (c₂ x) (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end subtype section continuous_map instance continuous_map_has_scalar' {α : Type*} [topological_space α] {R : Type*} [semiring R] [topological_space R] {M : Type*} [topological_space M] [add_comm_group M] [semimodule R M] [topological_semimodule R M] : has_scalar C(α, R) C(α, M) := ⟨λ f g, ⟨λ x, (f x) • (g x), (continuous.smul f.2 g.2)⟩⟩ instance continuous_map_module' {α : Type*} [topological_space α] (R : Type*) [ring R] [topological_space R] [topological_ring R] (M : Type*) [topological_space M] [add_comm_group M] [topological_add_group M] [module R M] [topological_module R M] : module C(α, R) C(α, M) := semimodule.of_core $ { smul := (•), smul_add := λ c f g, by ext x; exact smul_add (c x) (f x) (g x), add_smul := λ c₁ c₂ f, by ext x; exact add_smul (c₁ x) (c₂ x) (f x), mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul (c₁ x) (c₂ x) (f x), one_smul := λ f, by ext x; exact one_smul R (f x) } end continuous_map end module_over_continuous_functions
d411d9052daee0779121b67747a8fb81bb73c8b7
82e44445c70db0f03e30d7be725775f122d72f3e
/src/data/subtype.lean
16ec816fb9cdb5637385f1bb5ff02d4b88777927
[ "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
6,240
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 tactic.lint import tactic.ext import tactic.simps open function namespace subtype variables {α : Sort*} {β : Sort*} {γ : Sort*} {p : α → Prop} {q : α → Prop} /-- See Note [custom simps projection] -/ def simps.coe (x : subtype p) : α := x initialize_simps_projections subtype (val → coe) /-- A version of `x.property` or `x.2` where `p` is syntactically applied to the coercion of `x` instead of `x.1`. A similar result is `subtype.mem` in `data.set.basic`. -/ lemma prop (x : subtype p) : p x := x.2 @[simp] lemma val_eq_coe {x : subtype p} : x.1 = ↑x := rfl @[simp] protected theorem «forall» {q : {a // p a} → Prop} : (∀ x, q x) ↔ (∀ a b, q ⟨a, b⟩) := ⟨assume h a b, h ⟨a, b⟩, assume h ⟨a, b⟩, h a b⟩ /-- An alternative version of `subtype.forall`. This one is useful if Lean cannot figure out `q` when using `subtype.forall` from right to left. -/ protected theorem forall' {q : ∀x, p x → Prop} : (∀ x h, q x h) ↔ (∀ x : {a // p a}, q x x.2) := (@subtype.forall _ _ (λ x, q x.1 x.2)).symm @[simp] protected theorem «exists» {q : {a // p a} → Prop} : (∃ x, q x) ↔ (∃ a b, q ⟨a, b⟩) := ⟨assume ⟨⟨a, b⟩, h⟩, ⟨a, b, h⟩, assume ⟨a, b, h⟩, ⟨⟨a, b⟩, h⟩⟩ @[ext] protected lemma ext : ∀ {a1 a2 : {x // p x}}, (a1 : α) = (a2 : α) → a1 = a2 | ⟨x, h1⟩ ⟨.(x), h2⟩ rfl := rfl lemma ext_iff {a1 a2 : {x // p x}} : a1 = a2 ↔ (a1 : α) = (a2 : α) := ⟨congr_arg _, subtype.ext⟩ lemma heq_iff_coe_eq (h : ∀ x, p x ↔ q x) {a1 : {x // p x}} {a2 : {x // q x}} : a1 == a2 ↔ (a1 : α) = (a2 : α) := eq.rec (λ a2', heq_iff_eq.trans ext_iff) (funext $ λ x, propext (h x)) a2 lemma heq_iff_coe_heq {α β : Sort*} {p : α → Prop} {q : β → Prop} {a : {x // p x}} {b : {y // q y}} (h : α = β) (h' : p == q) : a == b ↔ (a : α) == (b : β) := by { subst h, subst h', rw [heq_iff_eq, heq_iff_eq, ext_iff] } lemma ext_val {a1 a2 : {x // p x}} : a1.1 = a2.1 → a1 = a2 := subtype.ext lemma ext_iff_val {a1 a2 : {x // p x}} : a1 = a2 ↔ a1.1 = a2.1 := ext_iff @[simp] theorem coe_eta (a : {a // p a}) (h : p a) : mk ↑a h = a := subtype.ext rfl @[simp] theorem coe_mk (a h) : (@mk α p a h : α) = a := rfl @[simp, nolint simp_nf] -- built-in reduction doesn't always work theorem mk_eq_mk {a h a' h'} : @mk α p a h = @mk α p a' h' ↔ a = a' := ext_iff theorem coe_eq_iff {a : {a // p a}} {b : α} : ↑a = b ↔ ∃ h, a = ⟨b, h⟩ := ⟨λ h, h ▸ ⟨a.2, (coe_eta _ _).symm⟩, λ ⟨hb, ha⟩, ha.symm ▸ rfl⟩ theorem coe_injective : injective (coe : subtype p → α) := λ a b, subtype.ext theorem val_injective : injective (@val _ p) := coe_injective /-- Restrict a (dependent) function to a subtype -/ def restrict {α} {β : α → Type*} (f : Πx, β x) (p : α → Prop) (x : subtype p) : β x.1 := f x lemma restrict_apply {α} {β : α → Type*} (f : Πx, β x) (p : α → Prop) (x : subtype p) : restrict f p x = f x.1 := by refl lemma restrict_def {α β} (f : α → β) (p : α → Prop) : restrict f p = f ∘ coe := by refl lemma restrict_injective {α β} {f : α → β} (p : α → Prop) (h : injective f) : injective (restrict f p) := h.comp coe_injective /-- Defining a map into a subtype, this can be seen as an "coinduction principle" of `subtype`-/ @[simps] def coind {α β} (f : α → β) {p : β → Prop} (h : ∀a, p (f a)) : α → subtype p := λ a, ⟨f a, h a⟩ theorem coind_injective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a)) (hf : injective f) : injective (coind f h) := λ x y hxy, hf $ by apply congr_arg subtype.val hxy theorem coind_surjective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a)) (hf : surjective f) : surjective (coind f h) := λ x, let ⟨a, ha⟩ := hf x in ⟨a, coe_injective ha⟩ theorem coind_bijective {α β} {f : α → β} {p : β → Prop} (h : ∀a, p (f a)) (hf : bijective f) : bijective (coind f h) := ⟨coind_injective h hf.1, coind_surjective h hf.2⟩ /-- Restriction of a function to a function on subtypes. -/ @[simps] def map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀a, p a → q (f a)) : subtype p → subtype q := λ x, ⟨f x, h x x.prop⟩ theorem map_comp {p : α → Prop} {q : β → Prop} {r : γ → Prop} {x : subtype p} (f : α → β) (h : ∀a, p a → q (f a)) (g : β → γ) (l : ∀a, q a → r (g a)) : map g l (map f h x) = map (g ∘ f) (assume a ha, l (f a) $ h a ha) x := rfl theorem map_id {p : α → Prop} {h : ∀a, p a → p (id a)} : map (@id α) h = id := funext $ assume ⟨v, h⟩, rfl lemma map_injective {p : α → Prop} {q : β → Prop} {f : α → β} (h : ∀a, p a → q (f a)) (hf : injective f) : injective (map f h) := coind_injective _ $ hf.comp coe_injective lemma map_involutive {p : α → Prop} {f : α → α} (h : ∀a, p a → p (f a)) (hf : involutive f) : involutive (map f h) := λ x, subtype.ext (hf x) instance [has_equiv α] (p : α → Prop) : has_equiv (subtype p) := ⟨λ s t, (s : α) ≈ (t : α)⟩ theorem equiv_iff [has_equiv α] {p : α → Prop} {s t : subtype p} : s ≈ t ↔ (s : α) ≈ (t : α) := iff.rfl variables [setoid α] protected theorem refl (s : subtype p) : s ≈ s := setoid.refl ↑s protected theorem symm {s t : subtype p} (h : s ≈ t) : t ≈ s := setoid.symm h protected theorem trans {s t u : subtype p} (h₁ : s ≈ t) (h₂ : t ≈ u) : s ≈ u := setoid.trans h₁ h₂ theorem equivalence (p : α → Prop) : equivalence (@has_equiv.equiv (subtype p) _) := mk_equivalence _ subtype.refl (@subtype.symm _ p _) (@subtype.trans _ p _) instance (p : α → Prop) : setoid (subtype p) := setoid.mk (≈) (equivalence p) end subtype namespace subtype /-! Some facts about sets, which require that `α` is a type. -/ variables {α : Type*} {β : Type*} {γ : Type*} {p : α → Prop} @[simp] lemma coe_prop {S : set α} (a : {a // a ∈ S}) : ↑a ∈ S := a.prop lemma val_prop {S : set α} (a : {a // a ∈ S}) : a.val ∈ S := a.property end subtype
1f94e57d2a84ee79fb07fff1e96ce04672db69b6
d1a52c3f208fa42c41df8278c3d280f075eb020c
/src/Lean/Elab/Notation.lean
d5079515a4768acf585c65e2763e71a9ab299b5d
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
4,894
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.Syntax import Lean.Elab.AuxDef namespace Lean.Elab.Command open Lean.Syntax open Lean.Parser.Term hiding macroArg open Lean.Parser.Command /- Wrap all occurrences of the given `ident` nodes in antiquotations -/ private partial def antiquote (vars : Array Syntax) : Syntax → Syntax | stx => match stx with | `($id:ident) => if (vars.findIdx? (fun var => var.getId == id.getId)).isSome then mkAntiquotNode id else stx | _ => match stx with | Syntax.node i k args => Syntax.node i k (args.map (antiquote vars)) | stx => stx /- Convert `notation` command lhs item into a `syntax` command item -/ def expandNotationItemIntoSyntaxItem (stx : Syntax) : MacroM Syntax := let k := stx.getKind if k == `Lean.Parser.Command.identPrec then pure $ mkNode `Lean.Parser.Syntax.cat #[mkIdentFrom stx `term, stx[1]] else if k == strLitKind then pure $ mkNode `Lean.Parser.Syntax.atom #[stx] else Macro.throwUnsupported /- Convert `notation` command lhs item into a pattern element -/ def expandNotationItemIntoPattern (stx : Syntax) : MacroM Syntax := let k := stx.getKind if k == `Lean.Parser.Command.identPrec then mkAntiquotNode stx[0] else if k == strLitKind then strLitToPattern stx else Macro.throwUnsupported /-- Try to derive a `SimpleDelab` from a notation. The notation must be of the form `notation ... => c var_1 ... var_n` where `c` is a declaration in the current scope and the `var_i` are a permutation of the LHS vars. -/ def mkSimpleDelab (attrKind : Syntax) (vars : Array Syntax) (pat qrhs : Syntax) : OptionT MacroM Syntax := do match qrhs with | `($c:ident $args*) => let [(c, [])] ← Macro.resolveGlobalName c.getId | failure guard <| args.all (Syntax.isIdent ∘ getAntiquotTerm) guard <| args.allDiff -- replace head constant with (unused) antiquotation so we're not dependent on the exact pretty printing of the head `(@[$attrKind:attrKind appUnexpander $(mkIdent c):ident] aux_def unexpand $(mkIdent c) : Lean.PrettyPrinter.Unexpander := fun | `($$(_):ident $args*) => `($pat) | _ => throw ()) | `($c:ident) => let [(c, [])] ← Macro.resolveGlobalName c.getId | failure `(@[$attrKind:attrKind appUnexpander $(mkIdent c):ident] aux_def unexpand $(mkIdent c) : Lean.PrettyPrinter.Unexpander := fun | `($$(_):ident) => `($pat) | _ => throw ()) | _ => failure private def isLocalAttrKind (attrKind : Syntax) : Bool := match attrKind with | `(Parser.Term.attrKind| local) => true | _ => false private def expandNotationAux (ref : Syntax) (currNamespace : Name) (attrKind : Syntax) (prec? : Option Syntax) (name? : Option Syntax) (prio? : Option Syntax) (items : Array Syntax) (rhs : Syntax) : MacroM Syntax := do let prio ← evalOptPrio prio? -- build parser let syntaxParts ← items.mapM expandNotationItemIntoSyntaxItem let cat := mkIdentFrom ref `term let name ← match name? with | some name => pure name.getId | none => mkNameFromParserSyntax `term (mkNullNode syntaxParts) -- build macro rules let vars := items.filter fun item => item.getKind == `Lean.Parser.Command.identPrec let vars := vars.map fun var => var[0] let qrhs := antiquote vars rhs let patArgs ← items.mapM expandNotationItemIntoPattern /- The command `syntax [<kind>] ...` adds the current namespace to the syntax node kind. So, we must include current namespace when we create a pattern for the following `macro_rules` commands. -/ let fullName := currNamespace ++ name let pat := mkNode fullName patArgs let stxDecl ← `($attrKind:attrKind syntax $[: $prec?]? (name := $(mkIdent name)) (priority := $(quote prio):numLit) $[$syntaxParts]* : $cat) let mut macroDecl ← `(macro_rules | `($pat) => ``($qrhs)) if isLocalAttrKind attrKind then -- Make sure the quotation pre-checker takes section variables into account for local notation. macroDecl ← `(section set_option quotPrecheck.allowSectionVars true $macroDecl end) match (← mkSimpleDelab attrKind vars pat qrhs |>.run) with | some delabDecl => mkNullNode #[stxDecl, macroDecl, delabDecl] | none => mkNullNode #[stxDecl, macroDecl] @[builtinMacro Lean.Parser.Command.notation] def expandNotation : Macro | stx@`($attrKind:attrKind notation $[: $prec? ]? $[(name := $name?)]? $[(priority := $prio?)]? $items* => $rhs) => do -- trigger scoped checks early and only once let _ ← toAttributeKind attrKind expandNotationAux stx (← Macro.getCurrNamespace) attrKind prec? name? prio? items rhs | _ => Macro.throwUnsupported end Lean.Elab.Command
d0e0ecb68f25e74c0ff0d6382e1bb3709ebb7539
fe25de614feb5587799621c41487aaee0d083b08
/stage0/src/Lean/Elab/BuiltinCommand.lean
27dd560bc256887bb2bff8aa2c0db7fc02f4586c
[ "Apache-2.0" ]
permissive
pollend/lean4
e8469c2f5fb8779b773618c3267883cf21fb9fac
c913886938c4b3b83238a3f99673c6c5a9cec270
refs/heads/master
1,687,973,251,481
1,628,039,739,000
1,628,039,739,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
13,463
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.Command import Lean.Elab.Open namespace Lean.Elab.Command private def addScope (isNewNamespace : Bool) (header : String) (newNamespace : Name) : CommandElabM Unit := do modify fun s => { s with env := s.env.registerNamespace newNamespace, scopes := { s.scopes.head! with header := header, currNamespace := newNamespace } :: s.scopes } pushScope if isNewNamespace then activateScoped newNamespace private def addScopes (isNewNamespace : Bool) : Name → CommandElabM Unit | Name.anonymous => pure () | Name.str p header _ => do addScopes isNewNamespace p let currNamespace ← getCurrNamespace addScope isNewNamespace header (if isNewNamespace then Name.mkStr currNamespace header else currNamespace) | _ => throwError "invalid scope" private def addNamespace (header : Name) : CommandElabM Unit := addScopes (isNewNamespace := true) header def withNamespace {α} (ns : Name) (elabFn : CommandElabM α) : CommandElabM α := do addNamespace ns let a ← elabFn modify fun s => { s with scopes := s.scopes.drop ns.getNumParts } pure a private def popScopes (numScopes : Nat) : CommandElabM Unit := for i in [0:numScopes] do popScope private def checkAnonymousScope : List Scope → Bool | { header := "", .. } :: _ => true | _ => false private def checkEndHeader : Name → List Scope → Bool | Name.anonymous, _ => true | Name.str p s _, { header := h, .. } :: scopes => h == s && checkEndHeader p scopes | _, _ => false @[builtinCommandElab «namespace»] def elabNamespace : CommandElab := fun stx => match stx with | `(namespace $n) => addNamespace n.getId | _ => throwUnsupportedSyntax @[builtinCommandElab «section»] def elabSection : CommandElab := fun stx => match stx with | `(section $header:ident) => addScopes (isNewNamespace := false) header.getId | `(section) => do let currNamespace ← getCurrNamespace; addScope (isNewNamespace := false) "" currNamespace | _ => throwUnsupportedSyntax @[builtinCommandElab «end»] def elabEnd : CommandElab := fun stx => do let header? := (stx.getArg 1).getOptionalIdent?; let endSize := match header? with | none => 1 | some n => n.getNumParts let scopes ← getScopes if endSize < scopes.length then modify fun s => { s with scopes := s.scopes.drop endSize } popScopes endSize else -- we keep "root" scope let n := (← get).scopes.length - 1 modify fun s => { s with scopes := s.scopes.drop n } popScopes n throwError "invalid 'end', insufficient scopes" match header? with | none => unless checkAnonymousScope scopes do throwError "invalid 'end', name is missing" | some header => unless checkEndHeader header scopes do addCompletionInfo <| CompletionInfo.endSection stx (scopes.map fun scope => scope.header) throwError "invalid 'end', name mismatch" private partial def elabChoiceAux (cmds : Array Syntax) (i : Nat) : CommandElabM Unit := if h : i < cmds.size then let cmd := cmds.get ⟨i, h⟩; catchInternalId unsupportedSyntaxExceptionId (elabCommand cmd) (fun ex => elabChoiceAux cmds (i+1)) else throwUnsupportedSyntax @[builtinCommandElab choice] def elbChoice : CommandElab := fun stx => elabChoiceAux stx.getArgs 0 @[builtinCommandElab «universe»] def elabUniverse : CommandElab := fun n => do n[1].forArgsM addUnivLevel @[builtinCommandElab «init_quot»] def elabInitQuot : CommandElab := fun stx => do match (← getEnv).addDecl Declaration.quotDecl with | Except.ok env => setEnv env | Except.error ex => throwError (ex.toMessageData (← getOptions)) @[builtinCommandElab «export»] def elabExport : CommandElab := fun stx => do -- `stx` is of the form (Command.export "export" <namespace> "(" (null <ids>*) ")") let id := stx[1].getId let ns ← resolveNamespace id let currNamespace ← getCurrNamespace if ns == currNamespace then throwError "invalid 'export', self export" let env ← getEnv let ids := stx[3].getArgs let aliases ← ids.foldlM (init := []) fun (aliases : List (Name × Name)) (idStx : Syntax) => do let id := idStx.getId let declName ← resolveOpenDeclId ns idStx pure <| (currNamespace ++ id, declName) :: aliases modify fun s => { s with env := aliases.foldl (init := s.env) fun env p => addAlias env p.1 p.2 } @[builtinCommandElab «open»] def elabOpen : CommandElab := fun n => do let openDecls ← elabOpenDecl n[1] modifyScope fun scope => { scope with openDecls := openDecls } private def typelessBinder? : Syntax → Option (Array Name × Bool) | `(bracketedBinder|($ids*)) => some <| (ids.map Syntax.getId, true) | `(bracketedBinder|{$ids*}) => some <| (ids.map Syntax.getId, false) | _ => none -- This function is used to implement the `variable` command that updates binder annotations. private def matchBinderNames (ids : Array Syntax) (binderNames : Array Name) : CommandElabM Bool := let ids := ids.map Syntax.getId /- TODO: allow users to update the annotation of some of the ids. The current application supports the common case ``` variable (α : Type) ... variable {α : Type} ``` -/ if ids == binderNames then return true else if binderNames.any ids.contains then /- We currently do not split binder blocks. -/ throwError "failed to update variable binder annotation" -- TODO: improve error message else return false /-- Auxiliary method for processing binder annotation update commands: `variable (α)` and `variable {α}`. The argument `binder` is the binder of the `variable` command. The method retuns `true` if the binder annotation was updated. Remark: we currently do not suppor updates of the form ``` variable (α β : Type) ... variable {α} -- trying to update part of the binder block defined above. ``` -/ private def replaceBinderAnnotation (binder : Syntax) : CommandElabM Bool := do if let some (binderNames, explicit) := typelessBinder? binder then let varDecls := (← getScope).varDecls let mut varDeclsNew := #[] let mut found := false for varDecl in varDecls do if let some (ids, ty?, annot?) := match varDecl with | `(bracketedBinder|($ids* $[: $ty?]? $(annot?)?)) => some (ids, ty?, annot?) | `(bracketedBinder|{$ids* $[: $ty?]?}) => some (ids, ty?, none) | `(bracketedBinder|[$id : $ty]) => some (#[id], some ty, none) | _ => none then if (← matchBinderNames ids binderNames) then if annot?.isSome then throwError "cannot update binder annotation of variables with default values/tactics" if explicit then varDeclsNew := varDeclsNew.push (← `(bracketedBinder| ($ids* $[: $ty?]?))) else varDeclsNew := varDeclsNew.push (← `(bracketedBinder| {$ids* $[: $ty?]?})) found := true else varDeclsNew := varDeclsNew.push varDecl else varDeclsNew := varDeclsNew.push varDecl if found then modifyScope fun scope => { scope with varDecls := varDeclsNew } return true else return false else return false @[builtinCommandElab «variable»] def elabVariable : CommandElab | `(variable $binders*) => do -- Try to elaborate `binders` for sanity checking runTermElabM none fun _ => Term.withAutoBoundImplicit <| Term.elabBinders binders fun _ => pure () for binder in binders do unless (← replaceBinderAnnotation binder) do let varUIds ← getBracketedBinderIds binder |>.mapM (withFreshMacroScope ∘ MonadQuotation.addMacroScope) modifyScope fun scope => { scope with varDecls := scope.varDecls.push binder, varUIds := scope.varUIds ++ varUIds } | _ => throwUnsupportedSyntax open Meta @[builtinCommandElab Lean.Parser.Command.check] def elabCheck : CommandElab | `(#check%$tk $term) => withoutModifyingEnv $ runTermElabM (some `_check) fun _ => do let e ← Term.elabTerm term none Term.synthesizeSyntheticMVarsNoPostponing let (e, _) ← Term.levelMVarToParam (← instantiateMVars e) let type ← inferType e unless e.isSyntheticSorry do logInfoAt tk m!"{e} : {type}" | _ => throwUnsupportedSyntax @[builtinCommandElab Lean.Parser.Command.reduce] def elabReduce : CommandElab | `(#reduce%$tk $term) => withoutModifyingEnv <| runTermElabM (some `_check) fun _ => do let e ← Term.elabTerm term none Term.synthesizeSyntheticMVarsNoPostponing let (e, _) ← Term.levelMVarToParam (← instantiateMVars e) -- TODO: add options or notation for setting the following parameters withTheReader Core.Context (fun ctx => { ctx with options := ctx.options.setBool `smartUnfolding false }) do let e ← withTransparency (mode := TransparencyMode.all) <| reduce e (skipProofs := false) (skipTypes := false) logInfoAt tk e | _ => throwUnsupportedSyntax def hasNoErrorMessages : CommandElabM Bool := do return !(← get).messages.hasErrors def failIfSucceeds (x : CommandElabM Unit) : CommandElabM Unit := do let resetMessages : CommandElabM MessageLog := do let s ← get let messages := s.messages; modify fun s => { s with messages := {} }; pure messages let restoreMessages (prevMessages : MessageLog) : CommandElabM Unit := do modify fun s => { s with messages := prevMessages ++ s.messages.errorsToWarnings } let prevMessages ← resetMessages let succeeded ← try x hasNoErrorMessages catch | ex@(Exception.error _ _) => do logException ex; pure false | Exception.internal id _ => do logError (← id.getName); pure false finally restoreMessages prevMessages if succeeded then throwError "unexpected success" @[builtinCommandElab «check_failure»] def elabCheckFailure : CommandElab | `(#check_failure $term) => do failIfSucceeds <| elabCheck (← `(#check $term)) | _ => throwUnsupportedSyntax unsafe def elabEvalUnsafe : CommandElab | `(#eval%$tk $term) => do let n := `_eval let ctx ← read let addAndCompile (value : Expr) : TermElabM Unit := do let type ← inferType value let decl := Declaration.defnDecl { name := n levelParams := [] type := type value := value hints := ReducibilityHints.opaque safety := DefinitionSafety.unsafe } Term.ensureNoUnassignedMVars decl addAndCompile decl let elabMetaEval : CommandElabM Unit := runTermElabM (some n) fun _ => do let e ← Term.elabTerm term none Term.synthesizeSyntheticMVarsNoPostponing let e ← withLocalDeclD `env (mkConst ``Lean.Environment) fun env => withLocalDeclD `opts (mkConst ``Lean.Options) fun opts => do let e ← mkAppM ``Lean.runMetaEval #[env, opts, e]; mkLambdaFVars #[env, opts] e let env ← getEnv let opts ← getOptions let act ← try addAndCompile e; evalConst (Environment → Options → IO (String × Except IO.Error Environment)) n finally setEnv env let (out, res) ← act env opts -- we execute `act` using the environment logInfoAt tk out match res with | Except.error e => throwError e.toString | Except.ok env => do setEnv env; pure () let elabEval : CommandElabM Unit := runTermElabM (some n) fun _ => do -- fall back to non-meta eval if MetaEval hasn't been defined yet -- modify e to `runEval e` let e ← Term.elabTerm term none let e := mkSimpleThunk e Term.synthesizeSyntheticMVarsNoPostponing let e ← mkAppM ``Lean.runEval #[e] let env ← getEnv let act ← try addAndCompile e; evalConst (IO (String × Except IO.Error Unit)) n finally setEnv env let (out, res) ← liftM (m := IO) act logInfoAt tk out match res with | Except.error e => throwError e.toString | Except.ok _ => pure () if (← getEnv).contains ``Lean.MetaEval then do elabMetaEval else elabEval | _ => throwUnsupportedSyntax @[builtinCommandElab «eval», implementedBy elabEvalUnsafe] constant elabEval : CommandElab @[builtinCommandElab «synth»] def elabSynth : CommandElab := fun stx => do let term := stx[1] withoutModifyingEnv <| runTermElabM `_synth_cmd fun _ => do let inst ← Term.elabTerm term none Term.synthesizeSyntheticMVarsNoPostponing let inst ← instantiateMVars inst let val ← synthInstance inst logInfo val pure () @[builtinCommandElab «set_option»] def elabSetOption : CommandElab := fun stx => do let options ← Elab.elabSetOption stx[1] stx[2] modify fun s => { s with maxRecDepth := maxRecDepth.get options } modifyScope fun scope => { scope with opts := options } @[builtinMacro Lean.Parser.Command.«in»] def expandInCmd : Macro := fun stx => do let cmd₁ := stx[0] let cmd₂ := stx[2] `(section $cmd₁:command $cmd₂:command end) end Lean.Elab.Command
830613d12539948d92149059a619ba6b9c2e0044
b7f22e51856f4989b970961f794f1c435f9b8f78
/src/tests/shell/file2.lean
e05aeb57f73a578ea841ec9cc570de7611549ffa
[ "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
152
lean
check nat check nat.add_zero check nat.zero_add check finset open nat example (a b : nat) : a = 0 → b = 0 → a = b := begin intros, substvars end
8a9b8454164342da0ea1a8a51ac07e0454dfdf52
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/let1.lean
cccbb7b45d4b0b0e8390b6abcef75913282fed63
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
1,152
lean
prelude -- Correct version #check let bool := Sort 0, and (p q : bool) := ∀ c : bool, (p → q → c) → c, infixl `∧`:25 := and, and_intro (p q : bool) (H1 : p) (H2 : q) : p ∧ q := λ (c : bool) (H : p → q → c), H H1 H2, and_elim_left (p q : bool) (H : p ∧ q) : p := H p (λ (H1 : p) (H2 : q), H1), and_elim_right (p q : bool) (H : p ∧ q) : q := H q (λ (H1 : p) (H2 : q), H2) in and_intro -- TODO(Leo): fix expected output as soon as elaborator starts #checking let-expression type again #check let bool := Sort 0, and (p q : bool) := ∀ c : bool, (p → q → c) → c, infixl `∧`:25 := and, and_intro (p q : bool) (H1 : p) (H2 : q) : q ∧ p := λ (c : bool) (H : p → q → c), H H1 H2, and_elim_left (p q : bool) (H : p ∧ q) : p := H p (λ (H1 : p) (H2 : q), H1), and_elim_right (p q : bool) (H : p ∧ q) : q := H q (λ (H1 : p) (H2 : q), H2) in and_intro
e41b697aaea7d2e32806fa7856ccdf8b74532972
6094e25ea0b7699e642463b48e51b2ead6ddc23f
/library/data/nat/gcd.lean
c3470b90957b402331afc567f4cfe34ffcf1900d
[ "Apache-2.0" ]
permissive
gbaz/lean
a7835c4e3006fbbb079e8f8ffe18aacc45adebfb
a501c308be3acaa50a2c0610ce2e0d71becf8032
refs/heads/master
1,611,198,791,433
1,451,339,111,000
1,451,339,111,000
48,713,797
0
0
null
1,451,338,939,000
1,451,338,939,000
null
UTF-8
Lean
false
false
15,569
lean
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Definitions and properties of gcd, lcm, and coprime. -/ import .div open eq.ops well_founded decidable prod namespace nat /- gcd -/ private definition pair_nat.lt : nat × nat → nat × nat → Prop := measure pr₂ private definition pair_nat.lt.wf : well_founded pair_nat.lt := intro_k (measure.wf pr₂) 20 -- we use intro_k to be able to execute gcd efficiently in the kernel local attribute pair_nat.lt.wf [instance] -- instance will not be saved in .olean local infixl ` ≺ `:50 := pair_nat.lt private definition gcd.lt.dec (x y₁ : nat) : (succ y₁, x % succ y₁) ≺ (x, succ y₁) := !mod_lt (succ_pos y₁) definition gcd.F : Π (p₁ : nat × nat), (Π p₂ : nat × nat, p₂ ≺ p₁ → nat) → nat | (x, 0) f := x | (x, succ y) f := f (succ y, x % succ y) !gcd.lt.dec definition gcd (x y : nat) := fix gcd.F (x, y) theorem gcd_zero_right (x : nat) : gcd x 0 = x := rfl theorem gcd_succ (x y : nat) : gcd x (succ y) = gcd (succ y) (x % succ y) := well_founded.fix_eq gcd.F (x, succ y) theorem gcd_one_right (n : ℕ) : gcd n 1 = 1 := calc gcd n 1 = gcd 1 (n % 1) : gcd_succ ... = gcd 1 0 : mod_one theorem gcd_def (x : ℕ) : Π (y : ℕ), gcd x y = if y = 0 then x else gcd y (x % y) | 0 := !gcd_zero_right | (succ y) := !gcd_succ ⬝ (if_neg !succ_ne_zero)⁻¹ theorem gcd_self : Π (n : ℕ), gcd n n = n | 0 := rfl | (succ n₁) := calc gcd (succ n₁) (succ n₁) = gcd (succ n₁) (succ n₁ % succ n₁) : gcd_succ ... = gcd (succ n₁) 0 : mod_self theorem gcd_zero_left : Π (n : ℕ), gcd 0 n = n | 0 := rfl | (succ n₁) := calc gcd 0 (succ n₁) = gcd (succ n₁) (0 % succ n₁) : gcd_succ ... = gcd (succ n₁) 0 : zero_mod theorem gcd_of_pos (m : ℕ) {n : ℕ} (H : n > 0) : gcd m n = gcd n (m % n) := gcd_def m n ⬝ if_neg (ne_zero_of_pos H) theorem gcd_rec (m n : ℕ) : gcd m n = gcd n (m % n) := by_cases_zero_pos n (calc m = gcd 0 m : gcd_zero_left ... = gcd 0 (m % 0) : mod_zero) (take n, assume H : 0 < n, gcd_of_pos m H) theorem gcd.induction {P : ℕ → ℕ → Prop} (m n : ℕ) (H0 : ∀m, P m 0) (H1 : ∀m n, 0 < n → P n (m % n) → P m n) : P m n := induction (m, n) (prod.rec (λm, nat.rec (λ IH, H0 m) (λ n₁ v (IH : ∀p₂, p₂ ≺ (m, succ n₁) → P (pr₁ p₂) (pr₂ p₂)), H1 m (succ n₁) !succ_pos (IH _ !gcd.lt.dec)))) theorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) := gcd.induction m n (take m, and.intro (!one_mul ▸ !dvd_mul_left) !dvd_zero) (take m n (npos : 0 < n), and.rec (assume (IH₁ : gcd n (m % n) ∣ n) (IH₂ : gcd n (m % n) ∣ (m % n)), have H : (gcd n (m % n) ∣ (m / n * n + m % n)), from dvd_add (dvd.trans IH₁ !dvd_mul_left) IH₂, have H1 : (gcd n (m % n) ∣ m), from !eq_div_mul_add_mod⁻¹ ▸ H, show (gcd m n ∣ m) ∧ (gcd m n ∣ n), from !gcd_rec⁻¹ ▸ (and.intro H1 IH₁))) theorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := and.left !gcd_dvd theorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := and.right !gcd_dvd theorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n := gcd.induction m n (take m, imp.intro) (take m n (npos : n > 0) (IH : k ∣ n → k ∣ m % n → k ∣ gcd n (m % n)) (H1 : k ∣ m) (H2 : k ∣ n), have H3 : k ∣ m / n * n + m % n, from !eq_div_mul_add_mod ▸ H1, have H4 : k ∣ m % n, from nat.dvd_of_dvd_add_left H3 (dvd.trans H2 !dvd_mul_left), !gcd_rec⁻¹ ▸ IH H2 H4) theorem gcd.comm (m n : ℕ) : gcd m n = gcd n m := dvd.antisymm (dvd_gcd !gcd_dvd_right !gcd_dvd_left) (dvd_gcd !gcd_dvd_right !gcd_dvd_left) theorem gcd.assoc (m n k : ℕ) : gcd (gcd m n) k = gcd m (gcd n k) := dvd.antisymm (dvd_gcd (dvd.trans !gcd_dvd_left !gcd_dvd_left) (dvd_gcd (dvd.trans !gcd_dvd_left !gcd_dvd_right) !gcd_dvd_right)) (dvd_gcd (dvd_gcd !gcd_dvd_left (dvd.trans !gcd_dvd_right !gcd_dvd_left)) (dvd.trans !gcd_dvd_right !gcd_dvd_right)) theorem gcd_one_left (m : ℕ) : gcd 1 m = 1 := !gcd.comm ⬝ !gcd_one_right theorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k := gcd.induction n k (take n, calc gcd (m * n) (m * 0) = gcd (m * n) 0 : mul_zero) (take n k, assume H : 0 < k, assume IH : gcd (m * k) (m * (n % k)) = m * gcd k (n % k), calc gcd (m * n) (m * k) = gcd (m * k) (m * n % (m * k)) : !gcd_rec ... = gcd (m * k) (m * (n % k)) : mul_mod_mul_left ... = m * gcd k (n % k) : IH ... = m * gcd n k : !gcd_rec) theorem gcd_mul_right (m n k : ℕ) : gcd (m * n) (k * n) = gcd m k * n := calc gcd (m * n) (k * n) = gcd (n * m) (k * n) : mul.comm ... = gcd (n * m) (n * k) : mul.comm ... = n * gcd m k : gcd_mul_left ... = gcd m k * n : mul.comm theorem gcd_pos_of_pos_left {m : ℕ} (n : ℕ) (mpos : m > 0) : gcd m n > 0 := pos_of_dvd_of_pos !gcd_dvd_left mpos theorem gcd_pos_of_pos_right (m : ℕ) {n : ℕ} (npos : n > 0) : gcd m n > 0 := pos_of_dvd_of_pos !gcd_dvd_right npos theorem eq_zero_of_gcd_eq_zero_left {m n : ℕ} (H : gcd m n = 0) : m = 0 := or.elim (eq_zero_or_pos m) (assume H1, H1) (assume H1 : m > 0, absurd H⁻¹ (ne_of_lt (!gcd_pos_of_pos_left H1))) theorem eq_zero_of_gcd_eq_zero_right {m n : ℕ} (H : gcd m n = 0) : n = 0 := eq_zero_of_gcd_eq_zero_left (!gcd.comm ▸ H) theorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) : gcd (m / k) (n / k) = gcd m n / k := or.elim (eq_zero_or_pos k) (assume H3 : k = 0, by subst k; rewrite *nat.div_zero) (assume H3 : k > 0, (nat.div_eq_of_eq_mul_left H3 (calc gcd m n = gcd m (n / k * k) : nat.div_mul_cancel H2 ... = gcd (m / k * k) (n / k * k) : nat.div_mul_cancel H1 ... = gcd (m / k) (n / k) * k : gcd_mul_right))⁻¹) theorem gcd_dvd_gcd_mul_left (m n k : ℕ) : gcd m n ∣ gcd (k * m) n := dvd_gcd (dvd.trans !gcd_dvd_left !dvd_mul_left) !gcd_dvd_right theorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n := !mul.comm ▸ !gcd_dvd_gcd_mul_left theorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) := dvd_gcd !gcd_dvd_left (dvd.trans !gcd_dvd_right !dvd_mul_left) theorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) := !mul.comm ▸ !gcd_dvd_gcd_mul_left_right /- lcm -/ definition lcm (m n : ℕ) : ℕ := m * n / (gcd m n) theorem lcm.comm (m n : ℕ) : lcm m n = lcm n m := calc lcm m n = m * n / gcd m n : rfl ... = n * m / gcd m n : mul.comm ... = n * m / gcd n m : gcd.comm ... = lcm n m : rfl theorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 := calc lcm 0 m = 0 * m / gcd 0 m : rfl ... = 0 / gcd 0 m : zero_mul ... = 0 : nat.zero_div theorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := !lcm.comm ▸ !lcm_zero_left theorem lcm_one_left (m : ℕ) : lcm 1 m = m := calc lcm 1 m = 1 * m / gcd 1 m : rfl ... = m / gcd 1 m : one_mul ... = m / 1 : gcd_one_left ... = m : nat.div_one theorem lcm_one_right (m : ℕ) : lcm m 1 = m := !lcm.comm ▸ !lcm_one_left theorem lcm_self (m : ℕ) : lcm m m = m := have H : m * m / m = m, from by_cases_zero_pos m !nat.div_zero (take m, assume H1 : m > 0, !nat.mul_div_cancel H1), calc lcm m m = m * m / gcd m m : rfl ... = m * m / m : gcd_self ... = m : H theorem dvd_lcm_left (m n : ℕ) : m ∣ lcm m n := have H : lcm m n = m * (n / gcd m n), from nat.mul_div_assoc _ !gcd_dvd_right, dvd.intro H⁻¹ theorem dvd_lcm_right (m n : ℕ) : n ∣ lcm m n := !lcm.comm ▸ !dvd_lcm_left theorem gcd_mul_lcm (m n : ℕ) : gcd m n * lcm m n = m * n := eq.symm (nat.eq_mul_of_div_eq_right (dvd.trans !gcd_dvd_left !dvd_mul_right) rfl) theorem lcm_dvd {m n k : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k := or.elim (eq_zero_or_pos k) (assume kzero : k = 0, !kzero⁻¹ ▸ !dvd_zero) (assume kpos : k > 0, have mpos : m > 0, from pos_of_dvd_of_pos H1 kpos, have npos : n > 0, from pos_of_dvd_of_pos H2 kpos, have gcd_pos : gcd m n > 0, from !gcd_pos_of_pos_left mpos, obtain p (km : k = m * p), from exists_eq_mul_right_of_dvd H1, obtain q (kn : k = n * q), from exists_eq_mul_right_of_dvd H2, have ppos : p > 0, from pos_of_mul_pos_left (km ▸ kpos), have qpos : q > 0, from pos_of_mul_pos_left (kn ▸ kpos), have H3 : p * q * (m * n * gcd p q) = p * q * (gcd m n * k), from calc p * q * (m * n * gcd p q) = m * p * (n * q * gcd p q) : by rewrite [*mul.assoc, *mul.left_comm q, mul.left_comm p] ... = k * (k * gcd p q) : by rewrite [-kn, -km] ... = k * gcd (k * p) (k * q) : by rewrite gcd_mul_left ... = k * gcd (n * q * p) (m * p * q) : by rewrite [-kn, -km] ... = k * (gcd n m * (p * q)) : by rewrite [*mul.assoc, mul.comm q, gcd_mul_right] ... = p * q * (gcd m n * k) : by rewrite [mul.comm, mul.comm (gcd n m), gcd.comm, *mul.assoc], have H4 : m * n * gcd p q = gcd m n * k, from !eq_of_mul_eq_mul_left (mul_pos ppos qpos) H3, have H5 : gcd m n * (lcm m n * gcd p q) = gcd m n * k, from !mul.assoc ▸ !gcd_mul_lcm⁻¹ ▸ H4, have H6 : lcm m n * gcd p q = k, from !eq_of_mul_eq_mul_left gcd_pos H5, dvd.intro H6) theorem lcm.assoc (m n k : ℕ) : lcm (lcm m n) k = lcm m (lcm n k) := dvd.antisymm (lcm_dvd (lcm_dvd !dvd_lcm_left (dvd.trans !dvd_lcm_left !dvd_lcm_right)) (dvd.trans !dvd_lcm_right !dvd_lcm_right)) (lcm_dvd (dvd.trans !dvd_lcm_left !dvd_lcm_left) (lcm_dvd (dvd.trans !dvd_lcm_right !dvd_lcm_left) !dvd_lcm_right)) /- coprime -/ definition coprime [reducible] (m n : ℕ) : Prop := gcd m n = 1 lemma gcd_eq_one_of_coprime {m n : ℕ} : coprime m n → gcd m n = 1 := λ h, h theorem coprime_swap {m n : ℕ} (H : coprime n m) : coprime m n := !gcd.comm ▸ H theorem dvd_of_coprime_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ m := have H3 : gcd (m * k) (m * n) = m, from calc gcd (m * k) (m * n) = m * gcd k n : gcd_mul_left ... = m * 1 : H1 ... = m : mul_one, have H4 : (k ∣ gcd (m * k) (m * n)), from dvd_gcd !dvd_mul_left H2, H3 ▸ H4 theorem dvd_of_coprime_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n := dvd_of_coprime_of_dvd_mul_right H1 (!mul.comm ▸ H2) theorem gcd_mul_left_cancel_of_coprime {k : ℕ} (m : ℕ) {n : ℕ} (H : coprime k n) : gcd (k * m) n = gcd m n := have H1 : coprime (gcd (k * m) n) k, from calc gcd (gcd (k * m) n) k = gcd (k * gcd 1 m) n : by rewrite [-gcd_mul_left, mul_one, gcd.comm, gcd.assoc] ... = 1 : by rewrite [gcd_one_left, mul_one, ↑coprime at H, H], dvd.antisymm (dvd_gcd (dvd_of_coprime_of_dvd_mul_left H1 !gcd_dvd_left) !gcd_dvd_right) (dvd_gcd (dvd.trans !gcd_dvd_left !dvd_mul_left) !gcd_dvd_right) theorem gcd_mul_right_cancel_of_coprime (m : ℕ) {k n : ℕ} (H : coprime k n) : gcd (m * k) n = gcd m n := !mul.comm ▸ !gcd_mul_left_cancel_of_coprime H theorem gcd_mul_left_cancel_of_coprime_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (k * n) = gcd m n := !gcd.comm ▸ !gcd.comm ▸ !gcd_mul_left_cancel_of_coprime H theorem gcd_mul_right_cancel_of_coprime_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (n * k) = gcd m n := !gcd.comm ▸ !gcd.comm ▸ !gcd_mul_right_cancel_of_coprime H theorem coprime_div_gcd_div_gcd {m n : ℕ} (H : gcd m n > 0) : coprime (m / gcd m n) (n / gcd m n) := calc gcd (m / gcd m n) (n / gcd m n) = gcd m n / gcd m n : gcd_div !gcd_dvd_left !gcd_dvd_right ... = 1 : nat.div_self H theorem not_coprime_of_dvd_of_dvd {m n d : ℕ} (dgt1 : d > 1) (Hm : d ∣ m) (Hn : d ∣ n) : ¬ coprime m n := assume co : coprime m n, assert d ∣ gcd m n, from dvd_gcd Hm Hn, have d ∣ 1, by rewrite [↑coprime at co, co at this]; apply this, have d ≤ 1, from le_of_dvd dec_trivial this, show false, from not_lt_of_ge `d ≤ 1` `d > 1` theorem exists_coprime {m n : ℕ} (H : gcd m n > 0) : exists m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n := have H1 : m = (m / gcd m n) * gcd m n, from (nat.div_mul_cancel !gcd_dvd_left)⁻¹, have H2 : n = (n / gcd m n) * gcd m n, from (nat.div_mul_cancel !gcd_dvd_right)⁻¹, exists.intro _ (exists.intro _ (and.intro (coprime_div_gcd_div_gcd H) (and.intro H1 H2))) theorem coprime_mul {m n k : ℕ} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k := calc gcd (m * n) k = gcd n k : !gcd_mul_left_cancel_of_coprime H1 ... = 1 : H2 theorem coprime_mul_right {k m n : ℕ} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) := coprime_swap (coprime_mul (coprime_swap H1) (coprime_swap H2)) theorem coprime_of_coprime_mul_left {k m n : ℕ} (H : coprime (k * m) n) : coprime m n := have H1 : (gcd m n ∣ gcd (k * m) n), from !gcd_dvd_gcd_mul_left, eq_one_of_dvd_one (H ▸ H1) theorem coprime_of_coprime_mul_right {k m n : ℕ} (H : coprime (m * k) n) : coprime m n := coprime_of_coprime_mul_left (!mul.comm ▸ H) theorem coprime_of_coprime_mul_left_right {k m n : ℕ} (H : coprime m (k * n)) : coprime m n := coprime_swap (coprime_of_coprime_mul_left (coprime_swap H)) theorem coprime_of_coprime_mul_right_right {k m n : ℕ} (H : coprime m (n * k)) : coprime m n := coprime_of_coprime_mul_left_right (!mul.comm ▸ H) theorem comprime_one_left : ∀ n, coprime 1 n := λ n, !gcd_one_left theorem comprime_one_right : ∀ n, coprime n 1 := λ n, !gcd_one_right theorem exists_eq_prod_and_dvd_and_dvd {m n k : nat} (H : k ∣ m * n) : ∃ m' n', k = m' * n' ∧ m' ∣ m ∧ n' ∣ n := or.elim (eq_zero_or_pos (gcd k m)) (assume H1 : gcd k m = 0, have H2 : k = 0, from eq_zero_of_gcd_eq_zero_left H1, have H3 : m = 0, from eq_zero_of_gcd_eq_zero_right H1, have H4 : k = 0 * n, from H2 ⬝ !zero_mul⁻¹, have H5 : 0 ∣ m, from H3⁻¹ ▸ !dvd.refl, have H6 : n ∣ n, from !dvd.refl, exists.intro _ (exists.intro _ (and.intro H4 (and.intro H5 H6)))) (assume H1 : gcd k m > 0, have H2 : gcd k m ∣ k, from !gcd_dvd_left, have H3 : k / gcd k m ∣ (m * n) / gcd k m, from nat.div_dvd_div H2 H, have H4 : (m * n) / gcd k m = (m / gcd k m) * n, from calc m * n / gcd k m = n * m / gcd k m : mul.comm ... = n * (m / gcd k m) : !nat.mul_div_assoc !gcd_dvd_right ... = m / gcd k m * n : mul.comm, have H5 : k / gcd k m ∣ (m / gcd k m) * n, from H4 ▸ H3, have H6 : coprime (k / gcd k m) (m / gcd k m), from coprime_div_gcd_div_gcd H1, have H7 : k / gcd k m ∣ n, from dvd_of_coprime_of_dvd_mul_left H6 H5, have H8 : k = gcd k m * (k / gcd k m), from (nat.mul_div_cancel' H2)⁻¹, exists.intro _ (exists.intro _ (and.intro H8 (and.intro !gcd_dvd_right H7)))) end nat
fa7278a35d6769382fb116fe154219bb72d9c1c1
fcf3ffa92a3847189ca669cb18b34ef6b2ec2859
/src/world8/level7.lean
8c362230d910eea3453e8af9735374cc665a874c
[ "Apache-2.0" ]
permissive
nomoid/lean-proofs
4a80a97888699dee42b092b7b959b22d9aa0c066
b9f03a24623d1a1d111d6c2bbf53c617e2596d6a
refs/heads/master
1,674,955,317,080
1,607,475,706,000
1,607,475,706,000
314,104,281
0
0
null
null
null
null
UTF-8
Lean
false
false
610
lean
import mynat.definition import mynat.add import world8.level4 import world8.level5 namespace mynat theorem add_right_cancel_iff (a t b : mynat) : a + t = b + t ↔ a = b := begin [nat_num_game] split, { exact add_right_cancel a t b, }, { induction t with n hd, { rw add_zero, rw add_zero, intro h, exact h, }, { intro h, have res := hd h, rw add_succ, rw add_succ, rw eq_iff_succ_eq_succ, exact res, }, }, end end mynat
c0fb069447bf3dd18beda2cb49b2d46cd6ecb620
3dc4623269159d02a444fe898d33e8c7e7e9461b
/.github/workflows/project_1_a_decrire/lean-scheme-submission/src/spectrum_of_a_ring/properties.lean
c72aba5bb789c28f27067b91967fcf7e3f22ada7
[]
no_license
Or7ando/lean
cc003e6c41048eae7c34aa6bada51c9e9add9e66
d41169cf4e416a0d42092fb6bdc14131cee9dd15
refs/heads/master
1,650,600,589,722
1,587,262,906,000
1,587,262,906,000
255,387,160
0
0
null
null
null
null
UTF-8
Lean
false
false
6,603
lean
/- Properties of Spec(R). https://stacks.math.columbia.edu/tag/00E0 -/ import algebra.module import ring_theory.localization import to_mathlib.ideals import to_mathlib.localization.localization_alt import spectrum_of_a_ring.spec open lattice noncomputable theory local attribute [instance] classical.prop_decidable universe u section properties variables {R : Type u} [comm_ring R] open Spec -- Lemma 1. -- The spectrum of a ring R is empty if and only if R is the zero ring. lemma Spec.empty_iff_zero_ring : (Spec R → false) ↔ subsingleton R := begin split, { intros H, constructor, intros a b, have Hzo : (0 : R) = 1, { by_contra Hzno, replace Hzno : (0 : R) ≠ 1 := λ H, (Hzno H), have HTnB : (⊥ : ideal R) ≠ ⊤ := zero_ne_one_bot_ne_top Hzno, rcases (ideal.exists_le_maximal ⊥ HTnB) with ⟨M, ⟨HM, HBM⟩⟩, have MP : ideal.is_prime _ := ideal.is_maximal.is_prime HM, apply H, exact ⟨M, MP⟩, }, calc a = a * 0 : by rw [Hzo, mul_one] ... = b * 0 : by simp ... = b : by rw [Hzo, mul_one], }, { intros Hsub X, cases Hsub, rcases X with ⟨X, ⟨HC, PX⟩⟩, apply HC, apply ideal.ext, intros x, split, { intros Hx, trivial, }, { intros Hx, rw (Hsub x 0), exact X.2, } } end -- Lemma 5. -- V(S) = V((S)). lemma Spec.V.set_eq_span (S : set R) : Spec.V S = Spec.V (ideal.span S) := set.ext $ λ ⟨I, PI⟩, ⟨λ HI x Hx, begin have HxI := (ideal.span_mono HI) Hx, rw ideal.span_eq at HxI, exact HxI, end, λ HI x Hx, HI (ideal.subset_span Hx)⟩ -- Lemma 8. -- V(I) = ∅ iff I = R. lemma Spec.V.empty_iff_ideal_top (I : ideal R) : V(I.1) = ∅ ↔ I = ⊤ := begin split, { intros HI, by_contradiction HC, suffices Hsuff : ∃ x, x ∈ Spec.V I.1, cases Hsuff with x Hx, rw set.eq_empty_iff_forall_not_mem at HI, exact HI x Hx, rcases (ideal.exists_le_maximal I HC) with ⟨M, ⟨HM, HBM⟩⟩, have MP : ideal.is_prime M := ideal.is_maximal.is_prime HM, use [⟨M, MP⟩], exact HBM, }, { intros HI, rw [HI, set.eq_empty_iff_forall_not_mem], rintros ⟨J, PJ⟩ HnJ, have HJ : J = ⊤ := le_antisymm (λ x Hx, trivial) HnJ, exact PJ.1 HJ, } end -- Lemma 15. -- If f,g ∈ R, then D(fg) = D(f) ∩ D(g). lemma Spec.V'.product_eq_union (f g : R) : V'(f * g) = V'(f) ∪ V'(g) := begin unfold Spec.V', apply set.ext, rintros ⟨x, Px⟩, split, { intros Hx, have Hfg : f * g ∈ x := Hx, have Hforgx := Px.2 Hfg, cases Hforgx, { left, apply Hforgx, }, { right, apply Hforgx, } }, { intros Hx, cases Hx, { have Hf : f ∈ x := Hx, apply ideal.mul_mem_right x Hf, }, { have Hg : g ∈ x := Hx, apply ideal.mul_mem_left x Hg, } } end lemma Spec.D'.product_eq_inter (f g : R) : D'(f * g) = D'(f) ∩ D'(g) := begin unfold Spec.D', rw Spec.V'.product_eq_union, rw set.compl_union, end -- Lemma 16. -- ⋃D(fi) is the complement of V({fi}). lemma Spec.D'.union (F : set R) : ⋃₀ (D' '' F) = -V(F) := begin apply set.ext, intros x, split, { intros Hx HC, rcases Hx with ⟨Df, HDf, Hx⟩, rcases HDf with ⟨f, Hf, HDf⟩, rw ←HDf at Hx, apply Hx, exact HC Hf, }, { intros Hx, have Hf := not_forall.1 Hx, rcases Hf with ⟨f, Hf⟩, rw not_imp at Hf, rcases Hf with ⟨HfF, Hfnx⟩, use [Spec.D' f, ⟨f, HfF, rfl⟩], } end -- D(g) ⊆ D(f) → f ∈ R[1/g]*. --set_option trace.class_instances true lemma inverts.of_Dfs_subset {f g : R} (H : D'(g) ⊆ D'(f)) : localization_alt.inverts (powers f) (localization.of : R → localization R (powers g)) := begin rintros ⟨fn, Hfn⟩, suffices Hsuff : ∃ si, (localization.of : R → localization R (powers g)) f * si = 1, rcases Hsuff with ⟨si, Hsi⟩, show ∃ si, localization.of fn * si = 1, rcases Hfn with ⟨n, Hfn⟩, rw ←Hfn, clear Hfn, induction n with n Hn, { simp, }, { rw pow_succ, rw (@is_ring_hom.map_mul _ _ _ _ localization.of localization.of.is_ring_hom), rcases Hn with ⟨sin, Hn⟩, existsi (si * sin), rw ←mul_assoc, rw mul_assoc _ _ si, rw mul_comm _ si, rw ←mul_assoc, rw Hsi, rw one_mul, exact Hn, }, unfold Spec.D' at H, rw set.compl_subset_compl at H, unfold Spec.V' at H, by_contra Hne, rw not_exists at Hne, have Hnu : ¬is_unit ((localization.of : R → localization R (powers g)) f), intros HC, simp [is_unit] at HC, rcases HC with ⟨u, HC⟩, apply (Hne u.inv), rw HC, exact u.3, letI Rgr : comm_ring (localization.away g) := by apply_instance, let F : ideal (localization.away g) := ideal.span {(localization.of f)}, rcases (ideal.exists_le_maximal F (λ HC, Hnu (ideal.span_singleton_eq_top.1 HC))) with ⟨S, ⟨HMS, HFS⟩⟩, have HfF : (localization.of f : localization.away g) ∈ F, suffices Hsuff : localization.of f ∈ {localization.of f}, refine ideal.subset_span Hsuff, exact set.mem_singleton _, have HfM : localization.of f ∈ S := HFS HfF, have PS := ideal.is_maximal.is_prime HMS, have PS' : ideal.is_prime (ideal.comap localization.of S) := @ideal.is_prime.comap _ _ _ _ localization.of _ _ PS, let S' : Spec R := ⟨ideal.comap localization.of S, PS'⟩, have HfS' : f ∈ S'.val, erw ideal.mem_comap, exact HfM, replace HfS' : S' ∈ {P : Spec R | f ∈ P.val} := HfS', have HgS' : g ∈ ideal.comap localization.of S := H HfS', rw ideal.mem_comap at HgS', rcases (localization.coe_is_unit R (powers g) ⟨g, ⟨1, pow_one g⟩⟩) with ⟨w, Hw⟩, rcases w with ⟨w, winv, Hwwinv, Hwinvw⟩, change localization.of g = w at Hw, have HC : localization.of g * winv ∈ S := ideal.mul_mem_right S HgS', erw [Hw, Hwwinv] at HC, exact ((ideal.ne_top_iff_one S).1 PS.1) HC, end -- D(g) ⊆ D(f) → ∃ a e, g^e = a * f. lemma pow_eq.of_Dfs_subset {f g : R} (H : D'(g) ⊆ D'(f)) : ∃ (a : R) (e : ℕ), g^e = a * f := begin have Hinv := inverts.of_Dfs_subset H, rcases (Hinv ⟨f, ⟨1, pow_one f⟩⟩) with ⟨w, Hw⟩, dsimp only [subtype.coe_mk] at Hw, rcases (quotient.exists_rep w) with ⟨⟨a, ⟨gn, ⟨n, Hn⟩⟩⟩, Hagn⟩, erw [←Hagn, quotient.eq] at Hw, rcases Hw with ⟨gm, ⟨⟨m, Hm⟩, Hw⟩⟩, simp [-sub_eq_add_neg] at Hw, rw [sub_mul, sub_eq_zero, mul_assoc, mul_comm f, ←Hn, ←Hm, ←pow_add] at Hw, existsi [a * g ^ m, n + m], exact Hw, end end properties
484157915a54986d7666c28691ca0437d1ce76b5
5ae26df177f810c5006841e9c73dc56e01b978d7
/src/topology/algebra/infinite_sum.lean
6500bf8eb1f83e04dc1c7b5603238ba8bab04439
[ "Apache-2.0" ]
permissive
ChrisHughes24/mathlib
98322577c460bc6b1fe5c21f42ce33ad1c3e5558
a2a867e827c2a6702beb9efc2b9282bd801d5f9a
refs/heads/master
1,583,848,251,477
1,565,164,247,000
1,565,164,247,000
129,409,993
0
1
Apache-2.0
1,565,164,817,000
1,523,628,059,000
Lean
UTF-8
Lean
false
false
25,695
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 Infinite sum over a topological monoid This sum is known as unconditionally convergent, as it sums to the same value under all possible permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute convergence. Note: There are summable sequences which are not unconditionally convergent! The other way holds generally, see `tendsto_sum_nat_of_has_sum`. Reference: * Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups) -/ import logic.function algebra.big_operators data.set.lattice data.finset topology.metric_space.basic topology.algebra.uniform_group topology.algebra.ring topology.algebra.ordered topology.instances.real noncomputable theory open lattice finset filter function classical local attribute [instance] prop_decidable def option.cases_on' {α β} : option α → β → (α → β) → β | none n s := n | (some a) n s := s a variables {α : Type*} {β : Type*} {γ : Type*} section has_sum variables [add_comm_monoid α] [topological_space α] [topological_add_monoid α] /-- Infinite sum on a topological monoid The `at_top` filter on `finset α` is the limit of all finite sets towards the entire type. So we sum up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute sum operator. This is based on Mario Carneiro's infinite sum in Metamath. -/ def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, s.sum f) at_top (nhds a) /-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/ def summable (f : β → α) : Prop := ∃a, has_sum f a /-- `tsum f` is the sum of `f` it exists, or 0 otherwise -/ def tsum (f : β → α) := if h : summable f then classical.some h else 0 notation `∑` binders `, ` r:(scoped f, tsum f) := r variables {f g : β → α} {a b : α} {s : finset β} lemma has_sum_tsum (ha : summable f) : has_sum f (∑b, f b) := by simp [ha, tsum]; exact some_spec ha lemma summable_spec (ha : has_sum f a) : summable f := ⟨a, ha⟩ lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 := by simp [has_sum, tendsto_const_nhds] lemma summable_zero : summable (λb, 0 : β → α) := summable_spec has_sum_zero lemma has_sum_add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) := by simp [has_sum, sum_add_distrib]; exact tendsto_add hf hg lemma summable_add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) := summable_spec $ has_sum_add (has_sum_tsum hf)(has_sum_tsum hg) lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} : (∀i∈s, has_sum (f i) (a i)) → has_sum (λb, s.sum $ λi, f i b) (s.sum a) := finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum_add] {contextual := tt}) lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : summable (λb, s.sum $ λi, f i b) := summable_spec $ has_sum_sum $ assume i hi, has_sum_tsum $ hf i hi lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (s.sum f) := tendsto_infi' s $ tendsto.congr' (assume t (ht : s ⊆ t), show s.sum f = t.sum f, from sum_subset ht $ assume x _, hf _) tendsto_const_nhds lemma summable_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f := summable_spec $ has_sum_sum_of_ne_finset_zero hf lemma has_sum_ite_eq (b : β) (a : α) : has_sum (λb', if b' = b then a else 0) a := suffices has_sum (λb', if b' = b then a else 0) (({b} : finset β).sum (λb', if b' = b then a else 0)), from by simpa, has_sum_sum_of_ne_finset_zero $ assume b' hb, have b' ≠ b, by simpa using hb, by rw [if_neg this] lemma has_sum_of_iso {j : γ → β} {i : β → γ} (hf : has_sum f a) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : has_sum (f ∘ j) a := have ∀x y, j x = j y → x = y, from assume x y h, have i (j x) = i (j y), by rw [h], by rwa [h₁, h₁] at this, have (λs:finset γ, s.sum (f ∘ j)) = (λs:finset β, s.sum f) ∘ (λs:finset γ, s.image j), from funext $ assume s, (sum_image $ assume x _ y _, this x y).symm, show tendsto (λs:finset γ, s.sum (f ∘ j)) at_top (nhds a), by rw [this]; apply hf.comp (tendsto_finset_image_at_top_at_top h₂) lemma has_sum_iff_has_sum_of_iso {j : γ → β} (i : β → γ) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : has_sum (f ∘ j) a ↔ has_sum f a := iff.intro (assume hfj, have has_sum ((f ∘ j) ∘ i) a, from has_sum_of_iso hfj h₂ h₁, by simp [(∘), h₂] at this; assumption) (assume hf, has_sum_of_iso hf h₁ h₂) lemma has_sum_hom (g : α → γ) [add_comm_monoid γ] [topological_space γ] [topological_add_monoid γ] [is_add_monoid_hom g] (h₃ : continuous g) (hf : has_sum f a) : has_sum (g ∘ f) (g a) := have (λs:finset β, s.sum (g ∘ f)) = g ∘ (λs:finset β, s.sum f), from funext $ assume s, sum_hom g, show tendsto (λs:finset β, s.sum (g ∘ f)) at_top (nhds (g a)), by rw [this]; exact tendsto.comp (continuous_iff_continuous_at.mp h₃ a) hf lemma tendsto_sum_nat_of_has_sum {f : ℕ → α} (h : has_sum f a) : tendsto (λn:ℕ, (range n).sum f) at_top (nhds a) := suffices map (λ (n : ℕ), sum (range n) f) at_top ≤ map (λ (s : finset ℕ), sum s f) at_top, from le_trans this h, assume s (hs : {t : finset ℕ | t.sum f ∈ s} ∈ at_top), let ⟨t, ht⟩ := mem_at_top_sets.mp hs, ⟨n, hn⟩ := @exists_nat_subset_range t in mem_at_top_sets.mpr ⟨n, assume n' hn', ht _ $ finset.subset.trans hn $ range_subset.mpr hn'⟩ lemma has_sum_sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α} (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (ha : has_sum f a) : has_sum g a := assume s' hs', let ⟨s, hs, hss', hsc⟩ := nhds_is_closed hs', ⟨u, hu⟩ := mem_at_top_sets.mp $ ha $ hs, fsts := u.image sigma.fst, snds := λb, u.bind (λp, (if h : p.1 = b then {cast (congr_arg γ h) p.2} else ∅ : finset (γ b))) in have u_subset : u ⊆ fsts.sigma snds, from subset_iff.mpr $ assume ⟨b, c⟩ hu, have hb : b ∈ fsts, from finset.mem_image.mpr ⟨_, hu, rfl⟩, have hc : c ∈ snds b, from mem_bind.mpr ⟨_, hu, by simp; refl⟩, by simp [mem_sigma, hb, hc] , mem_at_top_sets.mpr $ exists.intro fsts $ assume bs (hbs : fsts ⊆ bs), have h : ∀cs : Π b ∈ bs, finset (γ b), (⋂b (hb : b ∈ bs), (λp:Πb, finset (γ b), p b) ⁻¹' {cs' | cs b hb ⊆ cs' }) ∩ (λp, bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩))) ⁻¹' s ≠ ∅, from assume cs, let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in have sum_eq : bs.sum (λb, (cs' b).sum (λc, f ⟨b, c⟩)) = (bs.sigma cs').sum f, from sum_sigma.symm, have (bs.sigma cs').sum f ∈ s, from hu _ $ finset.subset.trans u_subset $ sigma_mono hbs $ assume b, @finset.subset_union_right (γ b) _ _ _, set.ne_empty_iff_exists_mem.mpr $ exists.intro cs' $ by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_right] }, have tendsto (λp:(Πb:β, finset (γ b)), bs.sum (λb, (p b).sum (λc, f ⟨b, c⟩))) (⨅b (h : b ∈ bs), at_top.comap (λp, p b)) (nhds (bs.sum g)), from tendsto_finset_sum bs $ assume c hc, tendsto_infi' c $ tendsto_infi' hc $ by apply tendsto.comp (hf c) tendsto_comap, have bs.sum g ∈ s, from mem_of_closed_of_tendsto' this hsc $ forall_sets_neq_empty_iff_neq_bot.mp $ by simp [mem_inf_sets, exists_imp_distrib, and_imp, forall_and_distrib, filter.mem_infi_sets_finset, mem_comap_sets, skolem, mem_at_top_sets, and_comm]; from assume s₁ s₂ s₃ hs₁ hs₃ p hs₂ p' hp cs hp', have (⋂b (h : b ∈ bs), (λp:(Πb, finset (γ b)), p b) ⁻¹' {cs' | cs b h ⊆ cs' }) ≤ (⨅b∈bs, p b), from infi_le_infi $ assume b, infi_le_infi $ assume hb, le_trans (set.preimage_mono $ hp' b hb) (hp b hb), neq_bot_of_le_neq_bot (h _) (le_trans (set.inter_subset_inter (le_trans this hs₂) hs₃) hs₁), hss' this lemma summable_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (hf : ∀b, summable (λc, f ⟨b, c⟩)) (ha : summable f) : summable (λb, ∑c, f ⟨b, c⟩) := summable_spec $ has_sum_sigma (assume b, has_sum_tsum $ hf b) (has_sum_tsum ha) end has_sum section has_sum_iff_has_sum_of_iso_ne_zero variables [add_comm_monoid α] [topological_space α] [topological_add_monoid α] variables {f : β → α} {g : γ → α} {a : α} lemma has_sum_of_has_sum (h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ u'.sum g = v'.sum f) (hf : has_sum g a) : has_sum f a := suffices at_top.map (λs:finset β, s.sum f) ≤ at_top.map (λs:finset γ, s.sum g), from le_trans this hf, by rw [map_at_top_eq, map_at_top_eq]; from (le_infi $ assume b, let ⟨v, hv⟩ := h_eq b in infi_le_of_le v $ by simp [set.image_subset_iff]; exact hv) lemma has_sum_iff_has_sum (h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ u'.sum g = v'.sum f) (h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ v'.sum f = u'.sum g) : has_sum f a ↔ has_sum g a := ⟨has_sum_of_has_sum h₂, has_sum_of_has_sum h₁⟩ variables (i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0) (j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0) (hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c) (hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b) (hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b) include hi hj hji hij hgj lemma has_sum_of_has_sum_ne_zero : has_sum g a → has_sum f a := have j_inj : ∀x y (hx : f x ≠ 0) (hy : f y ≠ 0), (j hx = j hy ↔ x = y), from assume x y hx hy, ⟨assume h, have i (hj hx) = i (hj hy), by simp [h], by rwa [hij, hij] at this; assumption, by simp {contextual := tt}⟩, let ii : finset γ → finset β := λu, u.bind $ λc, if h : g c = 0 then ∅ else {i h} in let jj : finset β → finset γ := λv, v.bind $ λb, if h : f b = 0 then ∅ else {j h} in has_sum_of_has_sum $ assume u, exists.intro (ii u) $ assume v hv, exists.intro (u ∪ jj v) $ and.intro (subset_union_left _ _) $ have ∀c:γ, c ∈ u ∪ jj v → c ∉ jj v → g c = 0, from assume c hc hnc, classical.by_contradiction $ assume h : g c ≠ 0, have c ∈ u, from (finset.mem_union.1 hc).resolve_right hnc, have i h ∈ v, from hv $ by simp [mem_bind]; existsi c; simp [h, this], have j (hi h) ∈ jj v, by simp [mem_bind]; existsi i h; simp [h, hi, this], by rw [hji h] at this; exact hnc this, calc (u ∪ jj v).sum g = (jj v).sum g : (sum_subset (subset_union_right _ _) this).symm ... = v.sum _ : sum_bind $ by intros x hx y hy hxy; by_cases f x = 0; by_cases f y = 0; simp [*] ... = v.sum f : sum_congr rfl $ by intros x hx; by_cases f x = 0; simp [*] lemma has_sum_iff_has_sum_of_ne_zero : has_sum f a ↔ has_sum g a := iff.intro (has_sum_of_has_sum_ne_zero j hj i hi hij hji $ assume b hb, by rw [←hgj (hi _), hji]) (has_sum_of_has_sum_ne_zero i hi j hj hji hij hgj) lemma summable_iff_summable_ne_zero : summable g ↔ summable f := exists_congr $ assume a, has_sum_iff_has_sum_of_ne_zero j hj i hi hij hji $ assume b hb, by rw [←hgj (hi _), hji] end has_sum_iff_has_sum_of_iso_ne_zero section has_sum_iff_has_sum_of_bij_ne_zero variables [add_comm_monoid α] [topological_space α] [topological_add_monoid α] variables {f : β → α} {g : γ → α} {a : α} (i : Π⦃c⦄, g c ≠ 0 → β) (h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂) (h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b) (h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c) include i h₁ h₂ h₃ lemma has_sum_iff_has_sum_of_ne_zero_bij : has_sum f a ↔ has_sum g a := have hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0, from assume c h, by simp [h₃, h], let j : Π⦃b⦄, f b ≠ 0 → γ := λb h, some $ h₂ h in have hj : ∀⦃b⦄ (h : f b ≠ 0), ∃(h : g (j h) ≠ 0), i h = b, from assume b h, some_spec $ h₂ h, have hj₁ : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0, from assume b h, let ⟨h₁, _⟩ := hj h in h₁, have hj₂ : ∀⦃b⦄ (h : f b ≠ 0), i (hj₁ h) = b, from assume b h, let ⟨h₁, h₂⟩ := hj h in h₂, has_sum_iff_has_sum_of_ne_zero i hi j hj₁ (assume c h, h₁ (hj₁ _) h $ hj₂ _) hj₂ (assume b h, by rw [←h₃ (hj₁ _), hj₂]) lemma summable_iff_summable_ne_zero_bij : summable f ↔ summable g := exists_congr $ assume a, has_sum_iff_has_sum_of_ne_zero_bij @i h₁ h₂ h₃ end has_sum_iff_has_sum_of_bij_ne_zero section tsum variables [add_comm_monoid α] [topological_space α] [topological_add_monoid α] [t2_space α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_unique : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ := tendsto_nhds_unique at_top_ne_bot lemma tsum_eq_has_sum (ha : has_sum f a) : (∑b, f b) = a := has_sum_unique (has_sum_tsum ⟨a, ha⟩) ha lemma has_sum_iff_of_summable (h : summable f) : has_sum f a ↔ (∑b, f b) = a := iff.intro tsum_eq_has_sum (assume eq, eq ▸ has_sum_tsum h) @[simp] lemma tsum_zero : (∑b:β, 0:α) = 0 := tsum_eq_has_sum has_sum_zero lemma tsum_add (hf : summable f) (hg : summable g) : (∑b, f b + g b) = (∑b, f b) + (∑b, g b) := tsum_eq_has_sum $ has_sum_add (has_sum_tsum hf) (has_sum_tsum hg) lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) : (∑b, s.sum (λi, f i b)) = s.sum (λi, ∑b, f i b) := tsum_eq_has_sum $ has_sum_sum $ assume i hi, has_sum_tsum $ hf i hi lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) : (∑b, f b) = s.sum f := tsum_eq_has_sum $ has_sum_sum_of_ne_finset_zero hf lemma tsum_fintype [fintype β] (f : β → α) : (∑b, f b) = finset.univ.sum f := tsum_eq_sum $ λ a h, h.elim (mem_univ _) lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) : (∑b, f b) = f b := calc (∑b, f b) = (finset.singleton b).sum f : tsum_eq_sum $ by simp [hf] {contextual := tt} ... = f b : by simp lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α} (h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : (∑p, f p) = (∑b c, f ⟨b, c⟩) := (tsum_eq_has_sum $ has_sum_sigma (assume b, has_sum_tsum $ h₁ b) $ has_sum_tsum h₂).symm @[simp] lemma tsum_ite_eq (b : β) (a : α) : (∑b', if b' = b then a else 0) = a := tsum_eq_has_sum (has_sum_ite_eq b a) lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α} (h : ∀{a}, has_sum f a ↔ has_sum g a) : (∑b, f b) = (∑c, g c) := by_cases (assume : ∃a, has_sum f a, let ⟨a, hfa⟩ := this in have hga : has_sum g a, from h.mp hfa, by rw [tsum_eq_has_sum hfa, tsum_eq_has_sum hga]) (assume hf : ¬ summable f, have hg : ¬ summable g, from assume ⟨a, hga⟩, hf ⟨a, h.mpr hga⟩, by simp [tsum, hf, hg]) lemma tsum_eq_tsum_of_ne_zero {f : β → α} {g : γ → α} (i : Π⦃c⦄, g c ≠ 0 → β) (hi : ∀⦃c⦄ (h : g c ≠ 0), f (i h) ≠ 0) (j : Π⦃b⦄, f b ≠ 0 → γ) (hj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) ≠ 0) (hji : ∀⦃c⦄ (h : g c ≠ 0), j (hi h) = c) (hij : ∀⦃b⦄ (h : f b ≠ 0), i (hj h) = b) (hgj : ∀⦃b⦄ (h : f b ≠ 0), g (j h) = f b) : (∑i, f i) = (∑j, g j) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero i hi j hj hji hij hgj lemma tsum_eq_tsum_of_ne_zero_bij {f : β → α} {g : γ → α} (i : Π⦃c⦄, g c ≠ 0 → β) (h₁ : ∀⦃c₁ c₂⦄ (h₁ : g c₁ ≠ 0) (h₂ : g c₂ ≠ 0), i h₁ = i h₂ → c₁ = c₂) (h₂ : ∀⦃b⦄, f b ≠ 0 → ∃c (h : g c ≠ 0), i h = b) (h₃ : ∀⦃c⦄ (h : g c ≠ 0), f (i h) = g c) : (∑i, f i) = (∑j, g j) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_ne_zero_bij i h₁ h₂ h₃ lemma tsum_eq_tsum_of_iso (j : γ → β) (i : β → γ) (h₁ : ∀x, i (j x) = x) (h₂ : ∀x, j (i x) = x) : (∑c, f (j c)) = (∑b, f b) := tsum_eq_tsum_of_has_sum_iff_has_sum $ assume a, has_sum_iff_has_sum_of_iso i h₁ h₂ lemma tsum_equiv (j : γ ≃ β) : (∑c, f (j c)) = (∑b, f b) := tsum_eq_tsum_of_iso j j.symm (by simp) (by simp) end tsum section topological_group variables [add_comm_group α] [topological_space α] [topological_add_group α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_neg : has_sum f a → has_sum (λb, - f b) (- a) := has_sum_hom has_neg.neg continuous_neg' lemma summable_neg (hf : summable f) : summable (λb, - f b) := summable_spec $ has_sum_neg $ has_sum_tsum $ hf lemma has_sum_sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) := by simp; exact has_sum_add hf (has_sum_neg hg) lemma summable_sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) := summable_spec $ has_sum_sub (has_sum_tsum hf) (has_sum_tsum hg) section tsum variables [t2_space α] lemma tsum_neg (hf : summable f) : (∑b, - f b) = - (∑b, f b) := tsum_eq_has_sum $ has_sum_neg $ has_sum_tsum $ hf lemma tsum_sub (hf : summable f) (hg : summable g) : (∑b, f b - g b) = (∑b, f b) - (∑b, g b) := tsum_eq_has_sum $ has_sum_sub (has_sum_tsum hf) (has_sum_tsum hg) lemma tsum_eq_zero_add {f : ℕ → α} (hf : summable f) : (∑b, f b) = f 0 + (∑b, f (b + 1)) := begin let f₁ : ℕ → α := λ n, nat.rec (f 0) (λ _ _, 0) n, let f₂ : ℕ → α := λ n, nat.rec 0 (λ k _, f (k+1)) n, have : f = λ n, f₁ n + f₂ n, { ext n, symmetry, cases n, apply add_zero, apply zero_add }, have hf₁ : summable f₁, { fapply summable_sum_of_ne_finset_zero, { exact finset.singleton 0 }, { rintros (_ | n) hn, { exfalso, apply hn, apply finset.mem_singleton_self }, { refl } } }, have hf₂ : summable f₂, { have : f₂ = λ n, f n - f₁ n, ext, rw [eq_sub_iff_add_eq', this], rw [this], apply summable_sub hf hf₁ }, conv_lhs { rw [this] }, rw [tsum_add hf₁ hf₂, tsum_eq_single 0], { congr' 1, fapply tsum_eq_tsum_of_ne_zero_bij (λ n _, n + 1), { intros _ _ _ _, exact nat.succ_inj }, { rintros (_ | n) h, { contradiction }, { exact ⟨n, h, rfl⟩ } }, { intros, refl }, { apply_instance } }, { rintros (_ | n) hn, { contradiction }, { refl } }, { apply_instance } end end tsum end topological_group section topological_semiring variables [semiring α] [topological_space α] [topological_semiring α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_mul_left (a₂) : has_sum f a₁ → has_sum (λb, a₂ * f b) (a₂ * a₁) := has_sum_hom _ (continuous_mul continuous_const continuous_id) lemma has_sum_mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) := @has_sum_hom _ _ _ _ _ _ f a₁ (λa, a * a₂) _ _ _ _ (continuous_mul continuous_id continuous_const) hf lemma summable_mul_left (a) (hf : summable f) : summable (λb, a * f b) := summable_spec $ has_sum_mul_left _ $ has_sum_tsum hf lemma summable_mul_right (a) (hf : summable f) : summable (λb, f b * a) := summable_spec $ has_sum_mul_right _ $ has_sum_tsum hf section tsum variables [t2_space α] lemma tsum_mul_left (a) (hf : summable f) : (∑b, a * f b) = a * (∑b, f b) := tsum_eq_has_sum $ has_sum_mul_left _ $ has_sum_tsum hf lemma tsum_mul_right (a) (hf : summable f) : (∑b, f b * a) = (∑b, f b) * a := tsum_eq_has_sum $ has_sum_mul_right _ $ has_sum_tsum hf end tsum end topological_semiring section order_topology variables [ordered_comm_monoid α] [topological_space α] [ordered_topology α] [topological_add_monoid α] variables {f g : β → α} {a a₁ a₂ : α} lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto at_top_ne_bot hf hg $ univ_mem_sets' $ assume s, sum_le_sum $ assume b _, h b lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c) (h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ := have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁, begin refine (has_sum_iff_has_sum_of_ne_zero_bij (λb _, i b) _ _ _).2 hf, { assume c₁ c₂ h₁ h₂ eq, exact hi eq }, { assume c hc, cases eq : partial_inv i c with b; rw eq at hc, { contradiction }, { rw [partial_inv_of_injective hi] at eq, exact ⟨b, hc, eq⟩ } }, { assume c hc, rw [partial_inv_left hi, option.cases_on'] } end, begin refine has_sum_le (assume c, _) this hg, by_cases c ∈ set.range i, { rcases h with ⟨b, rfl⟩, rw [partial_inv_left hi, option.cases_on'], exact h _ }, { have : partial_inv i c = none := dif_neg h, rw [this, option.cases_on'], exact hs _ h } end lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : (∑b, f b) ≤ (∑b, g b) := has_sum_le h (has_sum_tsum hf) (has_sum_tsum hg) end order_topology section uniform_group variables [add_comm_group α] [uniform_space α] [complete_space α] [uniform_add_group α] variables (f g : β → α) {a a₁ a₂ : α} lemma summable_iff_cauchy : summable f ↔ cauchy (map (λ (s : finset β), sum s f) at_top) := (cauchy_map_iff_exists_tendsto at_top_ne_bot).symm lemma summable_iff_vanishing : summable f ↔ ∀ e ∈ nhds (0:α), (∃s:finset β, ∀t, disjoint t s → t.sum f ∈ e) := begin simp only [summable_iff_cauchy, cauchy_map_iff, and_iff_right at_top_ne_bot, prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)], rw [tendsto_at_top' (_ : finset β × finset β → α)], split, { assume h e he, rcases h e he with ⟨⟨s₁, s₂⟩, h⟩, use [s₁ ∪ s₂], assume t ht, have : (s₁ ∪ s₂) ∩ t = ∅ := finset.disjoint_iff_inter_eq_empty.1 ht.symm, specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩, simpa only [finset.sum_union this, add_sub_cancel'] using h }, { assume h e he, rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩, rcases h d hd with ⟨s, h⟩, use [(s, s)], rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩, have : t₂.sum f - t₁.sum f = (t₂ \ s).sum f - (t₁ \ s).sum f, { simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm, add_sub_add_right_eq_sub] }, simp only [this], exact hde _ _ (h _ finset.sdiff_disjoint) (h _ finset.sdiff_disjoint) } end /- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/ lemma summable_of_summable_of_sub (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) : summable g := (summable_iff_vanishing g).2 $ assume e he, let ⟨s, hs⟩ := (summable_iff_vanishing f).1 hf e he in ⟨s, assume t ht, have eq : (t.filter (λb, g b = f b)).sum f = t.sum g := calc (t.filter (λb, g b = f b)).sum f = (t.filter (λb, g b = f b)).sum g : finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm) ... = t.sum g : begin refine finset.sum_subset (finset.filter_subset _) _, assume b hbt hb, simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb, exact (h b).resolve_right hb end, eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩ lemma summable_comp_of_summable_of_injective {i : γ → β} (hf : summable f) (hi : injective i) : summable (f ∘ i) := suffices summable (λb, if b ∈ set.range i then f b else 0), begin refine (summable_iff_summable_ne_zero_bij (λc _, i c) _ _ _).1 this, { assume c₁ c₂ hc₁ hc₂ eq, exact hi eq }, { assume b hb, split_ifs at hb, { rcases h with ⟨c, rfl⟩, exact ⟨c, hb, rfl⟩ }, { contradiction } }, { assume c hc, exact if_pos (set.mem_range_self _) } end, summable_of_summable_of_sub _ _ hf $ assume b, by by_cases b ∈ set.range i; simp [h] end uniform_group section cauchy_seq open finset.Ico filter lemma cauchy_seq_of_summable_dist [metric_space α] {f : ℕ → α} (h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f := begin let d := λn, dist (f n) (f (n+1)), refine metric.cauchy_seq_iff'.2 (λε εpos, _), rcases (summable_iff_vanishing _).1 h {x : ℝ | x < ε} (gt_mem_nhds εpos) with ⟨s, hs⟩, have : ∃N:ℕ, ∀x ∈ s, x < N, { by_cases h : s = ∅, { use 0, simp [h]}, { use s.max' h + 1, exact λx hx, lt_of_le_of_lt (s.le_max' h x hx) (nat.lt_succ_self _) }}, rcases this with ⟨N, hN⟩, refine ⟨N, λn hn, _⟩, have : ∀n, n ≥ N → dist (f N) (f n) ≤ (Ico N n).sum d, { apply nat.le_induction, { simp }, { assume n hn hrec, calc dist (f N) (f (n+1)) ≤ dist (f N) (f n) + d n : dist_triangle _ _ _ ... ≤ (Ico N n).sum d + d n : add_le_add hrec (le_refl _) ... = (Ico N (n+1)).sum d : by rw [succ_top hn, sum_insert, add_comm]; simp }}, calc dist (f n) (f N) ≤ (Ico N n).sum d : by rw dist_comm; apply this n hn ... < ε : hs _ (finset.disjoint_iff_ne.2 (λa ha b hb, ne_of_gt (lt_of_lt_of_le (hN _ hb) (mem.1 ha).1))) end end cauchy_seq
acf99da77d3ad51b8be9e42be8c6e76ce0507a03
1437b3495ef9020d5413178aa33c0a625f15f15f
/order/filter.lean
e310322885cde29e1afc5317206144298be07477
[ "Apache-2.0" ]
permissive
jean002/mathlib
c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30
dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd
refs/heads/master
1,587,027,806,375
1,547,306,358,000
1,547,306,358,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
94,463
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 Theory of filters on sets. -/ import order.galois_connection order.zorn import data.set.finite data.list import category.applicative open lattice set universes u v w x y local attribute [instance] classical.prop_decidable namespace lattice variables {α : Type u} {ι : Sort v} section variable [complete_lattice α] lemma Inf_eq_finite_sets {s : set α} : Inf s = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t) := le_antisymm (le_infi $ assume t, le_infi $ assume ⟨_, h⟩, Inf_le_Inf h) (le_Inf $ assume b h, infi_le_of_le {b} $ infi_le_of_le (by simp only [h, finite_singleton, and_self, mem_set_of_eq, singleton_subset_iff]) $ Inf_le $ by simp only [mem_singleton]) lemma infi_insert_finset {ι : Type v} {s : finset ι} {f : ι → α} {i : ι} : (⨅j∈insert i s, f j) = f i ⊓ (⨅j∈s, f j) := by simp [infi_or, infi_inf_eq] lemma infi_empty_finset {ι : Type v} {f : ι → α} : (⨅j∈(∅ : finset ι), f j) = ⊤ := by simp only [finset.not_mem_empty, infi_top, infi_false, eq_self_iff_true] end -- TODO: move lemma inf_left_comm [semilattice_inf α] (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := by rw [← inf_assoc, ← inf_assoc, @inf_comm α _ a] def complete_lattice.copy (c : complete_lattice α) (le : α → α → Prop) (eq_le : le = @complete_lattice.le α c) (top : α) (eq_top : top = @complete_lattice.top α c) (bot : α) (eq_bot : bot = @complete_lattice.bot α c) (sup : α → α → α) (eq_sup : sup = @complete_lattice.sup α c) (inf : α → α → α) (eq_inf : inf = @complete_lattice.inf α c) (Sup : set α → α) (eq_Sup : Sup = @complete_lattice.Sup α c) (Inf : set α → α) (eq_Inf : Inf = @complete_lattice.Inf α c) : complete_lattice α := begin refine { le := le, top := top, bot := bot, sup := sup, inf := inf, Sup := Sup, Inf := Inf, ..}; subst_vars, exact @complete_lattice.le_refl α c, exact @complete_lattice.le_trans α c, exact @complete_lattice.le_antisymm α c, exact @complete_lattice.le_sup_left α c, exact @complete_lattice.le_sup_right α c, exact @complete_lattice.sup_le α c, exact @complete_lattice.inf_le_left α c, exact @complete_lattice.inf_le_right α c, exact @complete_lattice.le_inf α c, exact @complete_lattice.le_top α c, exact @complete_lattice.bot_le α c, exact @complete_lattice.le_Sup α c, exact @complete_lattice.Sup_le α c, exact @complete_lattice.Inf_le α c, exact @complete_lattice.le_Inf α c end end lattice namespace set variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} {ι : Sort y} theorem monotone_inter [preorder β] {f g : β → set α} (hf : monotone f) (hg : monotone g) : monotone (λx, (f x) ∩ (g x)) := assume a b h x ⟨h₁, h₂⟩, ⟨hf h h₁, hg h h₂⟩ theorem monotone_set_of [preorder α] {p : α → β → Prop} (hp : ∀b, monotone (λa, p a b)) : monotone (λa, {b | p a b}) := assume a a' h b, hp b h end set open set lattice section order variables {α : Type u} (r : α → α → Prop) local infix `≼` : 50 := r lemma directed_on_Union {r} {ι : Sort v} {f : ι → set α} (hd : directed (⊆) f) (h : ∀x, directed_on r (f x)) : directed_on r (⋃x, f x) := by simp only [directed_on, exists_prop, mem_Union, exists_imp_distrib]; exact assume a₁ b₁ fb₁ a₂ b₂ fb₂, let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂, ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂) in ⟨x, ⟨z, xf⟩, xa₁, xa₂⟩ end order theorem directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α} (h : zorn.chain (f ⁻¹'o r) c) : directed r (λx:{a:α // a ∈ c}, f (x.val)) := assume ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases (assume : a = b, by simp only [this, exists_prop, and_self, subtype.exists]; exact ⟨b, hb, refl _⟩) (assume : a ≠ b, (h a ha b hb this).elim (λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩) (λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩)) structure filter (α : Type*) := (sets : set (set α)) (univ_sets : set.univ ∈ sets) (sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets) (inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets) namespace filter variables {α : Type u} {f g : filter α} {s t : set α} lemma filter_eq : ∀{f g : filter α}, f.sets = g.sets → f = g | ⟨a, _, _, _⟩ ⟨._, _, _, _⟩ rfl := rfl lemma filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ protected lemma ext_iff : f = g ↔ ∀ s, s ∈ f.sets ↔ s ∈ g.sets := by rw [filter_eq_iff, ext_iff] @[extensionality] protected lemma ext : (∀ s, s ∈ f.sets ↔ s ∈ g.sets) → f = g := filter.ext_iff.2 lemma univ_mem_sets : univ ∈ f.sets := f.univ_sets lemma mem_sets_of_superset : ∀{x y : set α}, x ∈ f.sets → x ⊆ y → y ∈ f.sets := f.sets_of_superset lemma inter_mem_sets : ∀{s t}, s ∈ f.sets → t ∈ f.sets → s ∩ t ∈ f.sets := f.inter_sets lemma univ_mem_sets' (h : ∀ a, a ∈ s): s ∈ f.sets := mem_sets_of_superset univ_mem_sets (assume x _, h x) lemma mp_sets (hs : s ∈ f.sets) (h : {x | x ∈ s → x ∈ t} ∈ f.sets) : t ∈ f.sets := mem_sets_of_superset (inter_mem_sets hs h) $ assume x ⟨h₁, h₂⟩, h₂ h₁ lemma Inter_mem_sets {β : Type v} {s : β → set α} {is : set β} (hf : finite is) : (∀i∈is, s i ∈ f.sets) → (⋂i∈is, s i) ∈ f.sets := finite.induction_on hf (assume hs, by simp only [univ_mem_sets, mem_empty_eq, Inter_neg, Inter_univ, not_false_iff]) (assume i is _ hf hi hs, have h₁ : s i ∈ f.sets, from hs i (by simp), have h₂ : (⋂x∈is, s x) ∈ f.sets, from hi $ assume a ha, hs _ $ by simp only [ha, mem_insert_iff, or_true], by simp [inter_mem_sets h₁ h₂]) lemma exists_sets_subset_iff : (∃t∈f.sets, t ⊆ s) ↔ s ∈ f.sets := ⟨assume ⟨t, ht, ts⟩, mem_sets_of_superset ht ts, assume hs, ⟨s, hs, subset.refl _⟩⟩ lemma monotone_mem_sets {f : filter α} : monotone (λs, s ∈ f.sets) := assume s t hst h, mem_sets_of_superset h hst end filter namespace tactic.interactive open tactic interactive /-- `filter [t1, ⋯, tn]` replaces a goal of the form `s ∈ f.sets` and terms `h1 : t1 ∈ f.sets, ⋯, tn ∈ f.sets` with `∀x, x ∈ t1 → ⋯ → x ∈ tn → x ∈ s`. `filter [t1, ⋯, tn] e` is a short form for `{ filter [t1, ⋯, tn], exact e }`. -/ meta def filter_upwards (s : parse types.pexpr_list) (e' : parse $ optional types.texpr) : tactic unit := do s.reverse.mmap (λ e, eapplyc `filter.mp_sets >> eapply e), eapplyc `filter.univ_mem_sets', match e' with | some e := interactive.exact e | none := skip end end tactic.interactive namespace filter variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} section principal /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : set α) : filter α := { sets := {t | s ⊆ t}, univ_sets := subset_univ s, sets_of_superset := assume x y hx hy, subset.trans hx hy, inter_sets := assume x y, subset_inter } instance : inhabited (filter α) := ⟨principal ∅⟩ @[simp] lemma mem_principal_sets {s t : set α} : s ∈ (principal t).sets ↔ t ⊆ s := iff.rfl lemma mem_principal_self (s : set α) : s ∈ (principal s).sets := subset.refl _ end principal section join /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : filter (filter α)) : filter α := { sets := {s | {t : filter α | s ∈ t.sets} ∈ f.sets}, univ_sets := by simp only [univ_mem_sets, mem_set_of_eq]; exact univ_mem_sets, sets_of_superset := assume x y hx xy, mem_sets_of_superset hx $ assume f h, mem_sets_of_superset h xy, inter_sets := assume x y hx hy, mem_sets_of_superset (inter_mem_sets hx hy) $ assume f ⟨h₁, h₂⟩, inter_mem_sets h₁ h₂ } @[simp] lemma mem_join_sets {s : set α} {f : filter (filter α)} : s ∈ (join f).sets ↔ {t | s ∈ filter.sets t} ∈ f.sets := iff.rfl end join section lattice instance : partial_order (filter α) := { le := λf g, g.sets ⊆ f.sets, le_antisymm := assume a b h₁ h₂, filter_eq $ subset.antisymm h₂ h₁, le_refl := assume a, subset.refl _, le_trans := assume a b c h₁ h₂, subset.trans h₂ h₁ } theorem le_def {f g : filter α} : f ≤ g ↔ ∀ x ∈ g.sets, x ∈ f.sets := iff.rfl /-- `generate_sets g s`: `s` is in the filter closure of `g`. -/ inductive generate_sets (g : set (set α)) : set α → Prop | basic {s : set α} : s ∈ g → generate_sets s | univ {} : generate_sets univ | superset {s t : set α} : generate_sets s → s ⊆ t → generate_sets t | inter {s t : set α} : generate_sets s → generate_sets t → generate_sets (s ∩ t) /-- `generate g` is the smallest filter containing the sets `g`. -/ def generate (g : set (set α)) : filter α := { sets := {s | generate_sets g s}, univ_sets := generate_sets.univ, sets_of_superset := assume x y, generate_sets.superset, inter_sets := assume s t, generate_sets.inter } lemma sets_iff_generate {s : set (set α)} {f : filter α} : f ≤ filter.generate s ↔ s ⊆ f.sets := iff.intro (assume h u hu, h $ generate_sets.basic $ hu) (assume h u hu, hu.rec_on h univ_mem_sets (assume x y _ hxy hx, mem_sets_of_superset hx hxy) (assume x y _ _ hx hy, inter_mem_sets hx hy)) protected def mk_of_closure (s : set (set α)) (hs : (generate s).sets = s) : filter α := { sets := s, univ_sets := hs ▸ univ_mem_sets, sets_of_superset := assume x y, hs ▸ mem_sets_of_superset, inter_sets := assume x y, hs ▸ inter_mem_sets } lemma mk_of_closure_sets {s : set (set α)} {hs : (generate s).sets = s} : filter.mk_of_closure s hs = generate s := filter.ext $ assume u, hs.symm ▸ iff.refl _ /- Galois insertion from sets of sets into a filters. -/ def gi_generate (α : Type*) : @galois_insertion (set (set α)) (order_dual (filter α)) _ _ filter.generate filter.sets := { gc := assume s f, sets_iff_generate, le_l_u := assume f u, generate_sets.basic, choice := λs hs, filter.mk_of_closure s (le_antisymm hs $ sets_iff_generate.1 $ le_refl _), choice_eq := assume s hs, mk_of_closure_sets } /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance : has_inf (filter α) := ⟨λf g : filter α, { sets := {s | ∃ (a ∈ f.sets) (b ∈ g.sets), a ∩ b ⊆ s }, univ_sets := ⟨_, univ_mem_sets, _, univ_mem_sets, inter_subset_left _ _⟩, sets_of_superset := assume x y ⟨a, ha, b, hb, h⟩ xy, ⟨a, ha, b, hb, subset.trans h xy⟩, inter_sets := assume x y ⟨a, ha, b, hb, hx⟩ ⟨c, hc, d, hd, hy⟩, ⟨_, inter_mem_sets ha hc, _, inter_mem_sets hb hd, calc a ∩ c ∩ (b ∩ d) = (a ∩ b) ∩ (c ∩ d) : by ac_refl ... ⊆ x ∩ y : inter_subset_inter hx hy⟩ }⟩ @[simp] lemma mem_inf_sets {f g : filter α} {s : set α} : s ∈ (f ⊓ g).sets ↔ ∃t₁∈f.sets, ∃t₂∈g.sets, t₁ ∩ t₂ ⊆ s := iff.rfl lemma mem_inf_sets_of_left {f g : filter α} {s : set α} (h : s ∈ f.sets) : s ∈ (f ⊓ g).sets := ⟨s, h, univ, univ_mem_sets, inter_subset_left _ _⟩ lemma mem_inf_sets_of_right {f g : filter α} {s : set α} (h : s ∈ g.sets) : s ∈ (f ⊓ g).sets := ⟨univ, univ_mem_sets, s, h, inter_subset_right _ _⟩ lemma inter_mem_inf_sets {α : Type u} {f g : filter α} {s t : set α} (hs : s ∈ f.sets) (ht : t ∈ g.sets) : s ∩ t ∈ (f ⊓ g).sets := inter_mem_sets (mem_inf_sets_of_left hs) (mem_inf_sets_of_right ht) instance : has_top (filter α) := ⟨{ sets := {s | ∀x, x ∈ s}, univ_sets := assume x, mem_univ x, sets_of_superset := assume x y hx hxy a, hxy (hx a), inter_sets := assume x y hx hy a, mem_inter (hx _) (hy _) }⟩ lemma mem_top_sets_iff_forall {s : set α} : s ∈ (⊤ : filter α).sets ↔ (∀x, x ∈ s) := iff.refl _ @[simp] lemma mem_top_sets {s : set α} : s ∈ (⊤ : filter α).sets ↔ s = univ := by rw [mem_top_sets_iff_forall, eq_univ_iff_forall] section complete_lattice /- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately, we want to have different definitional equalities for the lattice operations. So we define them upfront and change the lattice operations for the complete lattice instance. -/ private def original_complete_lattice : complete_lattice (filter α) := @order_dual.lattice.complete_lattice _ (gi_generate α).lift_complete_lattice local attribute [instance] original_complete_lattice instance : complete_lattice (filter α) := original_complete_lattice.copy /- le -/ filter.partial_order.le rfl /- top -/ (filter.lattice.has_top).1 (top_unique $ assume s hs, (eq_univ_of_forall hs).symm ▸ univ_mem_sets) /- bot -/ _ rfl /- sup -/ _ rfl /- inf -/ (filter.lattice.has_inf).1 begin ext f g : 2, exact le_antisymm (le_inf (assume s, mem_inf_sets_of_left) (assume s, mem_inf_sets_of_right)) (assume s ⟨a, ha, b, hb, hs⟩, mem_sets_of_superset (inter_mem_sets (@inf_le_left (filter α) _ _ _ _ ha) (@inf_le_right (filter α) _ _ _ _ hb)) hs) end /- Sup -/ (join ∘ principal) (by ext s x; exact (@mem_bInter_iff _ _ s filter.sets x).symm) /- Inf -/ _ rfl end complete_lattice lemma bot_sets_eq : (⊥ : filter α).sets = univ := rfl lemma sup_sets_eq {f g : filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (gi_generate α).gc.u_inf lemma Sup_sets_eq {s : set (filter α)} : (Sup s).sets = (⋂f∈s, (f:filter α).sets) := (gi_generate α).gc.u_Inf lemma supr_sets_eq {f : ι → filter α} : (supr f).sets = (⋂i, (f i).sets) := (gi_generate α).gc.u_infi lemma generate_empty : filter.generate ∅ = (⊤ : filter α) := (gi_generate α).gc.l_bot lemma generate_univ : filter.generate univ = (⊥ : filter α) := mk_of_closure_sets.symm lemma generate_union {s t : set (set α)} : filter.generate (s ∪ t) = filter.generate s ⊓ filter.generate t := (gi_generate α).gc.l_sup lemma generate_Union {s : ι → set (set α)} : filter.generate (⋃ i, s i) = (⨅ i, filter.generate (s i)) := (gi_generate α).gc.l_supr @[simp] lemma mem_bot_sets {s : set α} : s ∈ (⊥ : filter α).sets := trivial @[simp] lemma mem_sup_sets {f g : filter α} {s : set α} : s ∈ (f ⊔ g).sets ↔ s ∈ f.sets ∧ s ∈ g.sets := iff.rfl @[simp] lemma mem_Sup_sets {x : set α} {s : set (filter α)} : x ∈ (Sup s).sets ↔ (∀f∈s, x ∈ (f:filter α).sets) := iff.rfl @[simp] lemma mem_supr_sets {x : set α} {f : ι → filter α} : x ∈ (supr f).sets ↔ (∀i, x ∈ (f i).sets) := by simp only [supr_sets_eq, iff_self, mem_Inter] @[simp] lemma le_principal_iff {s : set α} {f : filter α} : f ≤ principal s ↔ s ∈ f.sets := show (∀{t}, s ⊆ t → t ∈ f.sets) ↔ s ∈ f.sets, from ⟨assume h, h (subset.refl s), assume hs t ht, mem_sets_of_superset hs ht⟩ lemma principal_mono {s t : set α} : principal s ≤ principal t ↔ s ⊆ t := by simp only [le_principal_iff, iff_self, mem_principal_sets] lemma monotone_principal : monotone (principal : set α → filter α) := by simp only [monotone, principal_mono]; exact assume a b h, h @[simp] lemma principal_eq_iff_eq {s t : set α} : principal s = principal t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal_sets]; refl @[simp] lemma join_principal_eq_Sup {s : set (filter α)} : join (principal s) = Sup s := rfl /- lattice equations -/ lemma empty_in_sets_eq_bot {f : filter α} : ∅ ∈ f.sets ↔ f = ⊥ := ⟨assume h, bot_unique $ assume s _, mem_sets_of_superset h (empty_subset s), assume : f = ⊥, this.symm ▸ mem_bot_sets⟩ lemma inhabited_of_mem_sets {f : filter α} {s : set α} (hf : f ≠ ⊥) (hs : s ∈ f.sets) : ∃x, x ∈ s := have ∅ ∉ f.sets, from assume h, hf $ empty_in_sets_eq_bot.mp h, have s ≠ ∅, from assume h, this (h ▸ hs), exists_mem_of_ne_empty this lemma filter_eq_bot_of_not_nonempty {f : filter α} (ne : ¬ nonempty α) : f = ⊥ := empty_in_sets_eq_bot.mp $ univ_mem_sets' $ assume x, false.elim (ne ⟨x⟩) lemma forall_sets_neq_empty_iff_neq_bot {f : filter α} : (∀ (s : set α), s ∈ f.sets → s ≠ ∅) ↔ f ≠ ⊥ := by simp only [(@empty_in_sets_eq_bot α f).symm, ne.def]; exact ⟨assume h hs, h _ hs rfl, assume h s hs eq, h $ eq ▸ hs⟩ lemma mem_sets_of_neq_bot {f : filter α} {s : set α} (h : f ⊓ principal (-s) = ⊥) : s ∈ f.sets := have ∅ ∈ (f ⊓ principal (- s)).sets, from h.symm ▸ mem_bot_sets, let ⟨s₁, hs₁, s₂, (hs₂ : -s ⊆ s₂), (hs : s₁ ∩ s₂ ⊆ ∅)⟩ := this in by filter_upwards [hs₁] assume a ha, classical.by_contradiction $ assume ha', hs ⟨ha, hs₂ ha'⟩ lemma infi_sets_eq {f : ι → filter α} (h : directed (≥) f) (ne : nonempty ι) : (infi f).sets = (⋃ i, (f i).sets) := let ⟨i⟩ := ne, u := { filter . sets := (⋃ i, (f i).sets), univ_sets := by simp only [mem_Union]; exact ⟨i, univ_mem_sets⟩, sets_of_superset := by simp only [mem_Union, exists_imp_distrib]; intros x y i hx hxy; exact ⟨i, mem_sets_of_superset hx hxy⟩, inter_sets := begin simp only [mem_Union, exists_imp_distrib], assume x y a hx b hy, rcases h a b with ⟨c, ha, hb⟩, exact ⟨c, inter_mem_sets (ha hx) (hb hy)⟩ end } in subset.antisymm (show u ≤ infi f, from le_infi $ assume i, le_supr (λi, (f i).sets) i) (Union_subset $ assume i, infi_le f i) lemma infi_sets_eq' {f : β → filter α} {s : set β} (h : directed_on (f ⁻¹'o (≥)) s) (ne : ∃i, i ∈ s) : (⨅ i∈s, f i).sets = (⋃ i ∈ s, (f i).sets) := let ⟨i, hi⟩ := ne in calc (⨅ i ∈ s, f i).sets = (⨅ t : {t // t ∈ s}, (f t.val)).sets : by rw [infi_subtype]; refl ... = (⨆ t : {t // t ∈ s}, (f t.val).sets) : infi_sets_eq (assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end) ⟨⟨i, hi⟩⟩ ... = (⨆ t ∈ {t | t ∈ s}, (f t).sets) : by rw [supr_subtype]; refl lemma Inf_sets_eq_finite {s : set (filter α)} : (Inf s).sets = (⋃ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t).sets) := calc (Inf s).sets = (⨅ t ∈ { t | finite t ∧ t ⊆ s}, Inf t).sets : by rw [lattice.Inf_eq_finite_sets] ... = (⨆ t ∈ {t | finite t ∧ t ⊆ s}, (Inf t).sets) : infi_sets_eq' (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∪ y, ⟨finite_union hx₁ hy₁, union_subset hx₂ hy₂⟩, Inf_le_Inf $ subset_union_left _ _, Inf_le_Inf $ subset_union_right _ _⟩) ⟨∅, by simp only [empty_subset, finite_empty, and_self, mem_set_of_eq]⟩ @[simp] lemma sup_join {f₁ f₂ : filter (filter α)} : (join f₁ ⊔ join f₂) = join (f₁ ⊔ f₂) := filter_eq $ set.ext $ assume x, by simp only [supr_sets_eq, join, mem_sup_sets, iff_self, mem_set_of_eq] @[simp] lemma supr_join {ι : Sort w} {f : ι → filter (filter α)} : (⨆x, join (f x)) = join (⨆x, f x) := filter_eq $ set.ext $ assume x, by simp only [supr_sets_eq, join, iff_self, mem_Inter, mem_set_of_eq] instance : bounded_distrib_lattice (filter α) := { le_sup_inf := begin assume x y z s, simp only [and_assoc, mem_inf_sets, mem_sup_sets, exists_prop, exists_imp_distrib, and_imp], intros hs t₁ ht₁ t₂ ht₂ hts, exact ⟨s ∪ t₁, x.sets_of_superset hs $ subset_union_left _ _, y.sets_of_superset ht₁ $ subset_union_right _ _, s ∪ t₂, x.sets_of_superset hs $ subset_union_left _ _, z.sets_of_superset ht₂ $ subset_union_right _ _, subset.trans (@le_sup_inf (set α) _ _ _ _) (union_subset (subset.refl _) hts)⟩ end, ..filter.lattice.complete_lattice } private lemma infi_finite_distrib {s : set (filter α)} {f : filter α} (h : finite s) : (⨅ a ∈ s, f ⊔ a) = f ⊔ (Inf s) := finite.induction_on h (by simp only [mem_empty_eq, infi_false, infi_top, Inf_empty, sup_top_eq]) (by intros a s hn hs hi; rw [infi_insert, hi, ← sup_inf_left, Inf_insert]) /- the complementary version with ⨆ g∈s, f ⊓ g does not hold! -/ lemma binfi_sup_eq { f : filter α } {s : set (filter α)} : (⨅ g∈s, f ⊔ g) = f ⊔ Inf s := le_antisymm begin intros t h, cases h with h₁ h₂, rw [Inf_sets_eq_finite] at h₂, simp only [and_assoc, exists_prop, mem_Union, mem_set_of_eq] at h₂, rcases h₂ with ⟨s', hs', hs's, ht'⟩, have ht : t ∈ (⨅ a ∈ s', f ⊔ a).sets, { rw [infi_finite_distrib], exact ⟨h₁, ht'⟩, exact hs' }, clear h₁ ht', revert ht t, change (⨅ a ∈ s, f ⊔ a) ≤ (⨅ a ∈ s', f ⊔ a), apply infi_le_infi2 _, exact assume i, ⟨i, infi_le_infi2 $ assume h, ⟨hs's h, le_refl _⟩⟩ end (le_infi $ assume g, le_infi $ assume h, sup_le_sup (le_refl f) $ Inf_le h) lemma infi_sup_eq { f : filter α } {g : ι → filter α} : (⨅ x, f ⊔ g x) = f ⊔ infi g := calc (⨅ x, f ⊔ g x) = (⨅ x (h : ∃i, g i = x), f ⊔ x) : by simp only [infi_exists]; rw infi_comm; simp only [infi_infi_eq_right, eq_self_iff_true] ... = f ⊔ Inf {x | ∃i, g i = x} : binfi_sup_eq ... = f ⊔ infi g : by rw Inf_eq_infi; dsimp; simp only [infi_exists]; rw infi_comm; simp only [infi_infi_eq_right, eq_self_iff_true] lemma mem_infi_sets_finset {s : finset α} {f : α → filter β} : ∀t, t ∈ (⨅a∈s, f a).sets ↔ (∃p:α → set β, (∀a∈s, p a ∈ (f a).sets) ∧ (⋂a∈s, p a) ⊆ t) := show ∀t, t ∈ (⨅a∈s, f a).sets ↔ (∃p:α → set β, (∀a∈s, p a ∈ (f a).sets) ∧ (⨅a∈s, p a) ≤ t), begin refine finset.induction_on s _ _, { simp only [finset.not_mem_empty, false_implies_iff, lattice.infi_empty_finset, top_le_iff, imp_true_iff, mem_top_sets, true_and, exists_const], intros; refl }, { intros a s has ih t, simp only [ih, finset.forall_mem_insert, lattice.infi_insert_finset, mem_inf_sets, exists_prop, iff_iff_implies_and_implies, exists_imp_distrib, and_imp, and_assoc] {contextual := tt}, split, { intros t₁ ht₁ t₂ p hp ht₂ ht, existsi function.update p a t₁, have : ∀a'∈s, function.update p a t₁ a' = p a', from assume a' ha', have a' ≠ a, from assume h, has $ h ▸ ha', function.update_noteq this, have eq : (⨅j ∈ s, function.update p a t₁ j) = (⨅j ∈ s, p j), begin congr, funext b, congr, funext h, apply this, assumption end, simp only [this, ht₁, hp, function.update_same, true_and, imp_true_iff, eq] {contextual := tt}, exact subset.trans (inter_subset_inter (subset.refl _) ht₂) ht }, from assume p hpa hp ht, ⟨p a, hpa, (⨅j∈s, p j), ⟨⟨p, hp, le_refl _⟩, ht⟩⟩ } end /- principal equations -/ @[simp] lemma inf_principal {s t : set α} : principal s ⊓ principal t = principal (s ∩ t) := le_antisymm (by simp; exact ⟨s, subset.refl s, t, subset.refl t, by simp⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] lemma sup_principal {s t : set α} : principal s ⊔ principal t = principal (s ∪ t) := filter_eq $ set.ext $ by simp only [union_subset_iff, union_subset_iff, mem_sup_sets, forall_const, iff_self, mem_principal_sets] @[simp] lemma supr_principal {ι : Sort w} {s : ι → set α} : (⨆x, principal (s x)) = principal (⋃i, s i) := filter_eq $ set.ext $ assume x, by simp only [supr_sets_eq, mem_principal_sets, mem_Inter]; exact (@supr_le_iff (set α) _ _ _ _).symm lemma principal_univ : principal (univ : set α) = ⊤ := top_unique $ by simp only [le_principal_iff, mem_top_sets, eq_self_iff_true] lemma principal_empty : principal (∅ : set α) = ⊥ := bot_unique $ assume s _, empty_subset _ @[simp] lemma principal_eq_bot_iff {s : set α} : principal s = ⊥ ↔ s = ∅ := ⟨assume h, principal_eq_iff_eq.mp $ by simp only [principal_empty, h, eq_self_iff_true], assume h, by simp only [h, principal_empty, eq_self_iff_true]⟩ lemma inf_principal_eq_bot {f : filter α} {s : set α} (hs : -s ∈ f.sets) : f ⊓ principal s = ⊥ := empty_in_sets_eq_bot.mp ⟨_, hs, s, mem_principal_self s, assume x ⟨h₁, h₂⟩, h₁ h₂⟩ end lattice section map /-- The forward map of a filter -/ def map (m : α → β) (f : filter α) : filter β := { sets := preimage m ⁻¹' f.sets, univ_sets := univ_mem_sets, sets_of_superset := assume s t hs st, mem_sets_of_superset hs $ preimage_mono st, inter_sets := assume s t hs ht, inter_mem_sets hs ht } @[simp] lemma map_principal {s : set α} {f : α → β} : map f (principal s) = principal (set.image f s) := filter_eq $ set.ext $ assume a, image_subset_iff.symm variables {f : filter α} {m : α → β} {m' : β → γ} {s : set α} {t : set β} @[simp] lemma mem_map : t ∈ (map m f).sets ↔ {x | m x ∈ t} ∈ f.sets := iff.rfl lemma image_mem_map (hs : s ∈ f.sets) : m '' s ∈ (map m f).sets := f.sets_of_superset hs $ subset_preimage_image m s lemma range_mem_map : range m ∈ (map m f).sets := by rw ←image_univ; exact image_mem_map univ_mem_sets lemma mem_map_sets_iff : t ∈ (map m f).sets ↔ (∃s∈f.sets, m '' s ⊆ t) := iff.intro (assume ht, ⟨set.preimage m t, ht, image_preimage_subset _ _⟩) (assume ⟨s, hs, ht⟩, mem_sets_of_superset (image_mem_map hs) ht) @[simp] lemma map_id : filter.map id f = f := filter_eq $ rfl @[simp] lemma map_compose : filter.map m' ∘ filter.map m = filter.map (m' ∘ m) := funext $ assume _, filter_eq $ rfl @[simp] lemma map_map : filter.map m' (filter.map m f) = filter.map (m' ∘ m) f := congr_fun (@@filter.map_compose m m') f end map section comap /-- The inverse map of a filter -/ def comap (m : α → β) (f : filter β) : filter α := { sets := { s | ∃t∈f.sets, m ⁻¹' t ⊆ s }, univ_sets := ⟨univ, univ_mem_sets, by simp only [subset_univ, preimage_univ]⟩, sets_of_superset := assume a b ⟨a', ha', ma'a⟩ ab, ⟨a', ha', subset.trans ma'a ab⟩, inter_sets := assume a b ⟨a', ha₁, ha₂⟩ ⟨b', hb₁, hb₂⟩, ⟨a' ∩ b', inter_mem_sets ha₁ hb₁, inter_subset_inter ha₂ hb₂⟩ } end comap /-- The cofinite filter is the filter of subsets whose complements are finite. -/ def cofinite : filter α := { sets := {s | finite (- s)}, univ_sets := by simp only [compl_univ, finite_empty, mem_set_of_eq], sets_of_superset := assume s t (hs : finite (-s)) (st: s ⊆ t), finite_subset hs $ @lattice.neg_le_neg (set α) _ _ _ st, inter_sets := assume s t (hs : finite (-s)) (ht : finite (-t)), by simp only [compl_inter, finite_union, ht, hs, mem_set_of_eq] } /-- The monadic bind operation on filter is defined the usual way in terms of `map` and `join`. Unfortunately, this `bind` does not result in the expected applicative. See `filter.seq` for the applicative instance. -/ def bind (f : filter α) (m : α → filter β) : filter β := join (map m f) /-- The applicative sequentiation operation. This is not induced by the bind operation. -/ def seq (f : filter (α → β)) (g : filter α) : filter β := ⟨{ s | ∃u∈f.sets, ∃t∈g.sets, (∀m∈u, ∀x∈t, (m : α → β) x ∈ s) }, ⟨univ, univ_mem_sets, univ, univ_mem_sets, by simp only [forall_prop_of_true, mem_univ, forall_true_iff]⟩, assume s₀ s₁ ⟨t₀, t₁, h₀, h₁, h⟩ hst, ⟨t₀, t₁, h₀, h₁, assume x hx y hy, hst $ h _ hx _ hy⟩, assume s₀ s₁ ⟨t₀, ht₀, t₁, ht₁, ht⟩ ⟨u₀, hu₀, u₁, hu₁, hu⟩, ⟨t₀ ∩ u₀, inter_mem_sets ht₀ hu₀, t₁ ∩ u₁, inter_mem_sets ht₁ hu₁, assume x ⟨hx₀, hx₁⟩ x ⟨hy₀, hy₁⟩, ⟨ht _ hx₀ _ hy₀, hu _ hx₁ _ hy₁⟩⟩⟩ instance : has_pure filter := ⟨λ(α : Type u) x, principal {x}⟩ instance : has_bind filter := ⟨@filter.bind⟩ instance : has_seq filter := ⟨@filter.seq⟩ instance : functor filter := { map := @filter.map } section -- this section needs to be before applicative, otherwise the wrong instance will be chosen protected def monad : monad filter := { map := @filter.map } local attribute [instance] filter.monad protected def is_lawful_monad : is_lawful_monad filter := { id_map := assume α f, filter_eq rfl, pure_bind := assume α β a f, by simp only [bind, Sup_image, image_singleton, join_principal_eq_Sup, lattice.Sup_singleton, map_principal, eq_self_iff_true], bind_assoc := assume α β γ f m₁ m₂, filter_eq rfl, bind_pure_comp_eq_map := assume α β f x, filter_eq $ by simp only [bind, join, map, preimage, principal, set.subset_univ, eq_self_iff_true, function.comp_app, mem_set_of_eq, singleton_subset_iff] } end instance : applicative filter := { map := @filter.map, seq := @filter.seq } instance : alternative filter := { failure := λα, ⊥, orelse := λα x y, x ⊔ y } @[simp] lemma pure_def (x : α) : pure x = principal {x} := rfl @[simp] lemma mem_pure {a : α} {s : set α} : a ∈ s → s ∈ (pure a : filter α).sets := by simp only [imp_self, pure_def, mem_principal_sets, singleton_subset_iff]; exact id @[simp] lemma mem_pure_iff {a : α} {s : set α} : s ∈ (pure a : filter α).sets ↔ a ∈ s := by rw [pure_def, mem_principal_sets, set.singleton_subset_iff] @[simp] lemma map_def {α β} (m : α → β) (f : filter α) : m <$> f = map m f := rfl @[simp] lemma bind_def {α β} (f : filter α) (m : α → filter β) : f >>= m = bind f m := rfl /- map and comap equations -/ section map variables {f f₁ f₂ : filter α} {g g₁ g₂ : filter β} {m : α → β} {m' : β → γ} {s : set α} {t : set β} @[simp] theorem mem_comap_sets : s ∈ (comap m g).sets ↔ ∃t∈g.sets, m ⁻¹' t ⊆ s := iff.rfl theorem preimage_mem_comap (ht : t ∈ g.sets) : m ⁻¹' t ∈ (comap m g).sets := ⟨t, ht, subset.refl _⟩ lemma comap_id : comap id f = f := le_antisymm (assume s, preimage_mem_comap) (assume s ⟨t, ht, hst⟩, mem_sets_of_superset ht hst) lemma comap_comap_comp {m : γ → β} {n : β → α} : comap m (comap n f) = comap (n ∘ m) f := le_antisymm (assume c ⟨b, hb, (h : preimage (n ∘ m) b ⊆ c)⟩, ⟨preimage n b, preimage_mem_comap hb, h⟩) (assume c ⟨b, ⟨a, ha, (h₁ : preimage n a ⊆ b)⟩, (h₂ : preimage m b ⊆ c)⟩, ⟨a, ha, show preimage m (preimage n a) ⊆ c, from subset.trans (preimage_mono h₁) h₂⟩) @[simp] theorem comap_principal {t : set β} : comap m (principal t) = principal (m ⁻¹' t) := filter_eq $ set.ext $ assume s, ⟨assume ⟨u, (hu : t ⊆ u), (b : preimage m u ⊆ s)⟩, subset.trans (preimage_mono hu) b, assume : preimage m t ⊆ s, ⟨t, subset.refl t, this⟩⟩ lemma map_le_iff_le_comap : map m f ≤ g ↔ f ≤ comap m g := ⟨assume h s ⟨t, ht, hts⟩, mem_sets_of_superset (h ht) hts, assume h s ht, h ⟨_, ht, subset.refl _⟩⟩ lemma gc_map_comap (m : α → β) : galois_connection (map m) (comap m) := assume f g, map_le_iff_le_comap lemma map_mono (h : f₁ ≤ f₂) : map m f₁ ≤ map m f₂ := (gc_map_comap m).monotone_l h lemma monotone_map : monotone (map m) | a b := map_mono lemma comap_mono (h : g₁ ≤ g₂) : comap m g₁ ≤ comap m g₂ := (gc_map_comap m).monotone_u h lemma monotone_comap : monotone (comap m) | a b := comap_mono @[simp] lemma map_bot : map m ⊥ = ⊥ := (gc_map_comap m).l_bot @[simp] lemma map_sup : map m (f₁ ⊔ f₂) = map m f₁ ⊔ map m f₂ := (gc_map_comap m).l_sup @[simp] lemma map_supr {f : ι → filter α} : map m (⨆i, f i) = (⨆i, map m (f i)) := (gc_map_comap m).l_supr @[simp] lemma comap_top : comap m ⊤ = ⊤ := (gc_map_comap m).u_top @[simp] lemma comap_inf : comap m (g₁ ⊓ g₂) = comap m g₁ ⊓ comap m g₂ := (gc_map_comap m).u_inf @[simp] lemma comap_infi {f : ι → filter β} : comap m (⨅i, f i) = (⨅i, comap m (f i)) := (gc_map_comap m).u_infi lemma map_comap_le : map m (comap m g) ≤ g := (gc_map_comap m).l_u_le _ lemma le_comap_map : f ≤ comap m (map m f) := (gc_map_comap m).le_u_l _ @[simp] lemma comap_bot : comap m ⊥ = ⊥ := bot_unique $ assume s _, ⟨∅, by simp only [mem_bot_sets], by simp only [empty_subset, preimage_empty]⟩ lemma comap_supr {ι} {f : ι → filter β} {m : α → β} : comap m (supr f) = (⨆i, comap m (f i)) := le_antisymm (assume s hs, have ∀i, ∃t, t ∈ (f i).sets ∧ m ⁻¹' t ⊆ s, by simpa only [mem_comap_sets, exists_prop, mem_supr_sets] using mem_supr_sets.1 hs, let ⟨t, ht⟩ := classical.axiom_of_choice this in ⟨⋃i, t i, mem_supr_sets.2 $ assume i, (f i).sets_of_superset (ht i).1 (subset_Union _ _), begin rw [preimage_Union, Union_subset_iff], assume i, exact (ht i).2 end⟩) (supr_le $ assume i, monotone_comap $ le_supr _ _) lemma comap_Sup {s : set (filter β)} {m : α → β} : comap m (Sup s) = (⨆f∈s, comap m f) := by simp only [Sup_eq_supr, comap_supr, eq_self_iff_true] lemma comap_sup : comap m (g₁ ⊔ g₂) = comap m g₁ ⊔ comap m g₂ := le_antisymm (assume s ⟨⟨t₁, ht₁, hs₁⟩, ⟨t₂, ht₂, hs₂⟩⟩, ⟨t₁ ∪ t₂, ⟨g₁.sets_of_superset ht₁ (subset_union_left _ _), g₂.sets_of_superset ht₂ (subset_union_right _ _)⟩, union_subset hs₁ hs₂⟩) (sup_le (comap_mono le_sup_left) (comap_mono le_sup_right)) lemma le_map_comap' {f : filter β} {m : α → β} {s : set β} (hs : s ∈ f.sets) (hm : ∀b∈s, ∃a, m a = b) : f ≤ map m (comap m f) := assume t' ⟨t, ht, (sub : m ⁻¹' t ⊆ m ⁻¹' t')⟩, by filter_upwards [ht, hs] assume x hxt hxs, let ⟨y, hy⟩ := hm x hxs in hy ▸ sub (show m y ∈ t, from hy.symm ▸ hxt) lemma le_map_comap {f : filter β} {m : α → β} (hm : ∀x, ∃y, m y = x) : f ≤ map m (comap m f) := le_map_comap' univ_mem_sets (assume b _, hm b) lemma comap_map {f : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) : comap m (map m f) = f := have ∀s, preimage m (image m s) = s, from assume s, preimage_image_eq s h, le_antisymm (assume s hs, ⟨ image m s, f.sets_of_superset hs $ by simp only [this, subset.refl], by simp only [this, subset.refl]⟩) le_comap_map lemma le_of_map_le_map_inj' {f g : filter α} {m : α → β} {s : set α} (hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y) (h : map m f ≤ map m g) : f ≤ g := assume t ht, by filter_upwards [hsf, h $ image_mem_map (inter_mem_sets hsg ht)] assume a has ⟨b, ⟨hbs, hb⟩, h⟩, have b = a, from hm _ hbs _ has h, this ▸ hb lemma le_of_map_le_map_inj_iff {f g : filter α} {m : α → β} {s : set α} (hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y) : map m f ≤ map m g ↔ f ≤ g := iff.intro (le_of_map_le_map_inj' hsf hsg hm) map_mono lemma eq_of_map_eq_map_inj' {f g : filter α} {m : α → β} {s : set α} (hsf : s ∈ f.sets) (hsg : s ∈ g.sets) (hm : ∀x∈s, ∀y∈s, m x = m y → x = y) (h : map m f = map m g) : f = g := le_antisymm (le_of_map_le_map_inj' hsf hsg hm $ le_of_eq h) (le_of_map_le_map_inj' hsg hsf hm $ le_of_eq h.symm) lemma map_inj {f g : filter α} {m : α → β} (hm : ∀ x y, m x = m y → x = y) (h : map m f = map m g) : f = g := have comap m (map m f) = comap m (map m g), by rw h, by rwa [comap_map hm, comap_map hm] at this lemma comap_neq_bot {f : filter β} {m : α → β} (hm : ∀t∈f.sets, ∃a, m a ∈ t) : comap m f ≠ ⊥ := forall_sets_neq_empty_iff_neq_bot.mp $ assume s ⟨t, ht, t_s⟩, let ⟨a, (ha : a ∈ preimage m t)⟩ := hm t ht in neq_bot_of_le_neq_bot (ne_empty_of_mem ha) t_s lemma comap_neq_bot_of_surj {f : filter β} {m : α → β} (hf : f ≠ ⊥) (hm : ∀b, ∃a, m a = b) : comap m f ≠ ⊥ := comap_neq_bot $ assume t ht, let ⟨b, (hx : b ∈ t)⟩ := inhabited_of_mem_sets hf ht, ⟨a, (ha : m a = b)⟩ := hm b in ⟨a, ha.symm ▸ hx⟩ @[simp] lemma map_eq_bot_iff : map m f = ⊥ ↔ f = ⊥ := ⟨by rw [←empty_in_sets_eq_bot, ←empty_in_sets_eq_bot]; exact id, assume h, by simp only [h, eq_self_iff_true, map_bot]⟩ lemma map_ne_bot (hf : f ≠ ⊥) : map m f ≠ ⊥ := assume h, hf $ by rwa [map_eq_bot_iff] at h lemma sInter_comap_sets (f : α → β) (F : filter β) : ⋂₀(comap f F).sets = ⋂ U ∈ F.sets, f ⁻¹' U := begin ext x, suffices : (∀ (A : set α) (B : set β), B ∈ F.sets → f ⁻¹' B ⊆ A → x ∈ A) ↔ ∀ (B : set β), B ∈ F.sets → f x ∈ B, by simp only [mem_sInter, mem_Inter, mem_comap_sets, this, and_imp, mem_comap_sets, exists_prop, mem_sInter, iff_self, mem_Inter, mem_preimage_eq, exists_imp_distrib], split, { intros h U U_in, simpa only [set.subset.refl, forall_prop_of_true, mem_preimage_eq] using h (f ⁻¹' U) U U_in }, { intros h V U U_in f_U_V, exact f_U_V (h U U_in) }, end end map lemma map_cong {m₁ m₂ : α → β} {f : filter α} (h : {x | m₁ x = m₂ x} ∈ f.sets) : map m₁ f = map m₂ f := have ∀(m₁ m₂ : α → β) (h : {x | m₁ x = m₂ x} ∈ f.sets), map m₁ f ≤ map m₂ f, begin intros m₁ m₂ h s hs, show {x | m₁ x ∈ s} ∈ f.sets, filter_upwards [h, hs], simp only [subset_def, mem_preimage_eq, mem_set_of_eq, forall_true_iff] {contextual := tt} end, le_antisymm (this m₁ m₂ h) (this m₂ m₁ $ mem_sets_of_superset h $ assume x, eq.symm) -- this is a generic rule for monotone functions: lemma map_infi_le {f : ι → filter α} {m : α → β} : map m (infi f) ≤ (⨅ i, map m (f i)) := le_infi $ assume i, map_mono $ infi_le _ _ lemma map_infi_eq {f : ι → filter α} {m : α → β} (hf : directed (≥) f) (hι : nonempty ι) : map m (infi f) = (⨅ i, map m (f i)) := le_antisymm map_infi_le (assume s (hs : preimage m s ∈ (infi f).sets), have ∃i, preimage m s ∈ (f i).sets, by simp only [infi_sets_eq hf hι, mem_Union] at hs; assumption, let ⟨i, hi⟩ := this in have (⨅ i, map m (f i)) ≤ principal s, from infi_le_of_le i $ by simp only [le_principal_iff, mem_map]; assumption, by simp only [filter.le_principal_iff] at this; assumption) lemma map_binfi_eq {ι : Type w} {f : ι → filter α} {m : α → β} {p : ι → Prop} (h : directed_on (f ⁻¹'o (≥)) {x | p x}) (ne : ∃i, p i) : map m (⨅i (h : p i), f i) = (⨅i (h: p i), map m (f i)) := let ⟨i, hi⟩ := ne in calc map m (⨅i (h : p i), f i) = map m (⨅i:subtype p, f i.val) : by simp only [infi_subtype, eq_self_iff_true] ... = (⨅i:subtype p, map m (f i.val)) : map_infi_eq (assume ⟨x, hx⟩ ⟨y, hy⟩, match h x hx y hy with ⟨z, h₁, h₂, h₃⟩ := ⟨⟨z, h₁⟩, h₂, h₃⟩ end) ⟨⟨i, hi⟩⟩ ... = (⨅i (h : p i), map m (f i)) : by simp only [infi_subtype, eq_self_iff_true] lemma map_inf' {f g : filter α} {m : α → β} {t : set α} (htf : t ∈ f.sets) (htg : t ∈ g.sets) (h : ∀x∈t, ∀y∈t, m x = m y → x = y) : map m (f ⊓ g) = map m f ⊓ map m g := begin refine le_antisymm (le_inf (map_mono inf_le_left) (map_mono inf_le_right)) (assume s hs, _), simp only [map, mem_inf_sets, exists_prop, mem_map, mem_preimage_eq, mem_inf_sets] at hs ⊢, rcases hs with ⟨t₁, h₁, t₂, h₂, hs⟩, refine ⟨m '' (t₁ ∩ t), _, m '' (t₂ ∩ t), _, _⟩, { filter_upwards [h₁, htf] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ }, { filter_upwards [h₂, htg] assume a h₁ h₂, mem_image_of_mem _ ⟨h₁, h₂⟩ }, { rw [image_inter_on], { refine image_subset_iff.2 _, exact λ x ⟨⟨h₁, _⟩, h₂, _⟩, hs ⟨h₁, h₂⟩ }, { exact λ x ⟨_, hx⟩ y ⟨_, hy⟩, h x hx y hy } } end lemma map_inf {f g : filter α} {m : α → β} (h : ∀ x y, m x = m y → x = y) : map m (f ⊓ g) = map m f ⊓ map m g := map_inf' univ_mem_sets univ_mem_sets (assume x _ y _, h x y) lemma map_eq_comap_of_inverse {f : filter α} {m : α → β} {n : β → α} (h₁ : m ∘ n = id) (h₂ : n ∘ m = id) : map m f = comap n f := le_antisymm (assume b ⟨a, ha, (h : preimage n a ⊆ b)⟩, f.sets_of_superset ha $ calc a = preimage (n ∘ m) a : by simp only [h₂, preimage_id, eq_self_iff_true] ... ⊆ preimage m b : preimage_mono h) (assume b (hb : preimage m b ∈ f.sets), ⟨preimage m b, hb, show preimage (m ∘ n) b ⊆ b, by simp only [h₁]; apply subset.refl⟩) lemma map_swap_eq_comap_swap {f : filter (α × β)} : prod.swap <$> f = comap prod.swap f := map_eq_comap_of_inverse prod.swap_swap_eq prod.swap_swap_eq lemma le_map {f : filter α} {m : α → β} {g : filter β} (h : ∀s∈f.sets, m '' s ∈ g.sets) : g ≤ f.map m := assume s hs, mem_sets_of_superset (h _ hs) $ image_preimage_subset _ _ section applicative @[simp] lemma mem_pure_sets {a : α} {s : set α} : s ∈ (pure a : filter α).sets ↔ a ∈ s := by simp only [iff_self, pure_def, mem_principal_sets, singleton_subset_iff] lemma singleton_mem_pure_sets {a : α} : {a} ∈ (pure a : filter α).sets := by simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff] @[simp] lemma pure_neq_bot {α : Type u} {a : α} : pure a ≠ (⊥ : filter α) := by simp only [pure, has_pure.pure, ne.def, not_false_iff, singleton_ne_empty, principal_eq_bot_iff] lemma mem_seq_sets_def {f : filter (α → β)} {g : filter α} {s : set β} : s ∈ (f.seq g).sets ↔ (∃u∈f.sets, ∃t∈g.sets, ∀x∈u, ∀y∈t, (x : α → β) y ∈ s) := iff.refl _ lemma mem_seq_sets_iff {f : filter (α → β)} {g : filter α} {s : set β} : s ∈ (f.seq g).sets ↔ (∃u∈f.sets, ∃t∈g.sets, set.seq u t ⊆ s) := by simp only [mem_seq_sets_def, seq_subset, exists_prop, iff_self] lemma mem_map_seq_iff {f : filter α} {g : filter β} {m : α → β → γ} {s : set γ} : s ∈ ((f.map m).seq g).sets ↔ (∃t u, t ∈ g.sets ∧ u ∈ f.sets ∧ ∀x∈u, ∀y∈t, m x y ∈ s) := iff.intro (assume ⟨t, ht, s, hs, hts⟩, ⟨s, m ⁻¹' t, hs, ht, assume a, hts _⟩) (assume ⟨t, s, ht, hs, hts⟩, ⟨m '' s, image_mem_map hs, t, ht, assume f ⟨a, has, eq⟩, eq ▸ hts _ has⟩) lemma seq_mem_seq_sets {f : filter (α → β)} {g : filter α} {s : set (α → β)} {t : set α} (hs : s ∈ f.sets) (ht : t ∈ g.sets): s.seq t ∈ (f.seq g).sets := ⟨s, hs, t, ht, assume f hf a ha, ⟨f, hf, a, ha, rfl⟩⟩ lemma le_seq {f : filter (α → β)} {g : filter α} {h : filter β} (hh : ∀t∈f.sets, ∀u∈g.sets, set.seq t u ∈ h.sets) : h ≤ seq f g := assume s ⟨t, ht, u, hu, hs⟩, mem_sets_of_superset (hh _ ht _ hu) $ assume b ⟨m, hm, a, ha, eq⟩, eq ▸ hs _ hm _ ha lemma seq_mono {f₁ f₂ : filter (α → β)} {g₁ g₂ : filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.seq g₁ ≤ f₂.seq g₂ := le_seq $ assume s hs t ht, seq_mem_seq_sets (hf hs) (hg ht) @[simp] lemma pure_seq_eq_map (g : α → β) (f : filter α) : seq (pure g) f = f.map g := begin refine le_antisymm (le_map $ assume s hs, _) (le_seq $ assume s hs t ht, _), { rw ← singleton_seq, apply seq_mem_seq_sets _ hs, simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff] }, { rw mem_pure_sets at hs, refine sets_of_superset (map g f) (image_mem_map ht) _, rintros b ⟨a, ha, rfl⟩, exact ⟨g, hs, a, ha, rfl⟩ } end @[simp] lemma map_pure (f : α → β) (a : α) : map f (pure a) = pure (f a) := le_antisymm (le_principal_iff.2 $ sets_of_superset (map f (pure a)) (image_mem_map singleton_mem_pure_sets) $ by simp only [image_singleton, mem_singleton, singleton_subset_iff]) (le_map $ assume s, begin simp only [mem_image, pure_def, mem_principal_sets, singleton_subset_iff], exact assume has, ⟨a, has, rfl⟩ end) @[simp] lemma seq_pure (f : filter (α → β)) (a : α) : seq f (pure a) = map (λg:α → β, g a) f := begin refine le_antisymm (le_map $ assume s hs, _) (le_seq $ assume s hs t ht, _), { rw ← seq_singleton, exact seq_mem_seq_sets hs (by simp only [mem_singleton, pure_def, mem_principal_sets, singleton_subset_iff]) }, { rw mem_pure_sets at ht, refine sets_of_superset (map (λg:α→β, g a) f) (image_mem_map hs) _, rintros b ⟨g, hg, rfl⟩, exact ⟨g, hg, a, ht, rfl⟩ } end @[simp] lemma seq_assoc (x : filter α) (g : filter (α → β)) (h : filter (β → γ)) : seq h (seq g x) = seq (seq (map (∘) h) g) x := begin refine le_antisymm (le_seq $ assume s hs t ht, _) (le_seq $ assume s hs t ht, _), { rcases mem_seq_sets_iff.1 hs with ⟨u, hu, v, hv, hs⟩, rcases mem_map_sets_iff.1 hu with ⟨w, hw, hu⟩, refine mem_sets_of_superset _ (set.seq_mono (subset.trans (set.seq_mono hu (subset.refl _)) hs) (subset.refl _)), rw ← set.seq_seq, exact seq_mem_seq_sets hw (seq_mem_seq_sets hv ht) }, { rcases mem_seq_sets_iff.1 ht with ⟨u, hu, v, hv, ht⟩, refine mem_sets_of_superset _ (set.seq_mono (subset.refl _) ht), rw set.seq_seq, exact seq_mem_seq_sets (seq_mem_seq_sets (image_mem_map hs) hu) hv } end lemma prod_map_seq_comm (f : filter α) (g : filter β) : (map prod.mk f).seq g = seq (map (λb a, (a, b)) g) f := begin refine le_antisymm (le_seq $ assume s hs t ht, _) (le_seq $ assume s hs t ht, _), { rcases mem_map_sets_iff.1 hs with ⟨u, hu, hs⟩, refine mem_sets_of_superset _ (set.seq_mono hs (subset.refl _)), rw ← set.prod_image_seq_comm, exact seq_mem_seq_sets (image_mem_map ht) hu }, { rcases mem_map_sets_iff.1 hs with ⟨u, hu, hs⟩, refine mem_sets_of_superset _ (set.seq_mono hs (subset.refl _)), rw set.prod_image_seq_comm, exact seq_mem_seq_sets (image_mem_map ht) hu } end instance : is_lawful_functor (filter : Type u → Type u) := { id_map := assume α f, map_id, comp_map := assume α β γ f g a, map_map.symm } instance : is_lawful_applicative (filter : Type u → Type u) := { pure_seq_eq_map := assume α β, pure_seq_eq_map, map_pure := assume α β, map_pure, seq_pure := assume α β, seq_pure, seq_assoc := assume α β γ, seq_assoc } instance : is_comm_applicative (filter : Type u → Type u) := ⟨assume α β f g, prod_map_seq_comm f g⟩ lemma {l} seq_eq_filter_seq {α β : Type l} (f : filter (α → β)) (g : filter α) : f <*> g = seq f g := rfl end applicative /- bind equations -/ section bind @[simp] lemma mem_bind_sets {s : set β} {f : filter α} {m : α → filter β} : s ∈ (bind f m).sets ↔ ∃t ∈ f.sets, ∀x ∈ t, s ∈ (m x).sets := calc s ∈ (bind f m).sets ↔ {a | s ∈ (m a).sets} ∈ f.sets : by simp only [bind, mem_map, iff_self, mem_join_sets, mem_set_of_eq] ... ↔ (∃t ∈ f.sets, t ⊆ {a | s ∈ (m a).sets}) : exists_sets_subset_iff.symm ... ↔ (∃t ∈ f.sets, ∀x ∈ t, s ∈ (m x).sets) : iff.refl _ lemma bind_mono {f : filter α} {g h : α → filter β} (h₁ : {a | g a ≤ h a} ∈ f.sets) : bind f g ≤ bind f h := assume x h₂, show (_ ∈ f.sets), by filter_upwards [h₁, h₂] assume s gh' h', gh' h' lemma bind_sup {f g : filter α} {h : α → filter β} : bind (f ⊔ g) h = bind f h ⊔ bind g h := by simp only [bind, sup_join, map_sup, eq_self_iff_true] lemma bind_mono2 {f g : filter α} {h : α → filter β} (h₁ : f ≤ g) : bind f h ≤ bind g h := assume s h', h₁ h' lemma principal_bind {s : set α} {f : α → filter β} : (bind (principal s) f) = (⨆x ∈ s, f x) := show join (map f (principal s)) = (⨆x ∈ s, f x), by simp only [Sup_image, join_principal_eq_Sup, map_principal, eq_self_iff_true] end bind lemma infi_neq_bot_of_directed {f : ι → filter α} (hn : nonempty α) (hd : directed (≥) f) (hb : ∀i, f i ≠ ⊥): (infi f) ≠ ⊥ := let ⟨x⟩ := hn in assume h, have he: ∅ ∈ (infi f).sets, from h.symm ▸ mem_bot_sets, classical.by_cases (assume : nonempty ι, have ∃i, ∅ ∈ (f i).sets, by rw [infi_sets_eq hd this] at he; simp only [mem_Union] at he; assumption, let ⟨i, hi⟩ := this in hb i $ bot_unique $ assume s _, (f i).sets_of_superset hi $ empty_subset _) (assume : ¬ nonempty ι, have univ ⊆ (∅ : set α), begin rw [←principal_mono, principal_univ, principal_empty, ←h], exact (le_infi $ assume i, false.elim $ this ⟨i⟩) end, this $ mem_univ x) lemma infi_neq_bot_iff_of_directed {f : ι → filter α} (hn : nonempty α) (hd : directed (≥) f) : (infi f) ≠ ⊥ ↔ (∀i, f i ≠ ⊥) := ⟨assume neq_bot i eq_bot, neq_bot $ bot_unique $ infi_le_of_le i $ eq_bot ▸ le_refl _, infi_neq_bot_of_directed hn hd⟩ lemma mem_infi_sets {f : ι → filter α} (i : ι) : ∀{s}, s ∈ (f i).sets → s ∈ (⨅i, f i).sets := show (⨅i, f i) ≤ f i, from infi_le _ _ @[elab_as_eliminator] lemma infi_sets_induct {f : ι → filter α} {s : set α} (hs : s ∈ (infi f).sets) {p : set α → Prop} (uni : p univ) (ins : ∀{i s₁ s₂}, s₁ ∈ (f i).sets → p s₂ → p (s₁ ∩ s₂)) (upw : ∀{s₁ s₂}, s₁ ⊆ s₂ → p s₁ → p s₂) : p s := begin have hs' : s ∈ (Inf {a : filter α | ∃ (i : ι), f i = a}).sets := hs, rw [Inf_sets_eq_finite] at hs', simp only [mem_Union] at hs', rcases hs' with ⟨is, ⟨fin_is, his⟩, hs⟩, revert his s, refine finite.induction_on fin_is _ (λ fi is fi_ne_is fin_is ih, _); intros his s hs' hs, { rw [Inf_empty, mem_top_sets] at hs, simpa only [hs] }, { rw [Inf_insert] at hs, rcases hs with ⟨s₁, hs₁, s₂, hs₂, hs⟩, rcases (his (mem_insert _ _)) with ⟨i, rfl⟩, have hs₂ : p s₂, from have his : is ⊆ {x | ∃i, f i = x}, from assume i hi, his $ mem_insert_of_mem _ hi, have infi f ≤ Inf is, from Inf_le_Inf his, ih his (this hs₂) hs₂, exact upw hs (ins hs₁ hs₂) } end /- tendsto -/ /-- `tendsto` is the generic "limit of a function" predicate. `tendsto f l₁ l₂` asserts that for every `l₂` neighborhood `a`, the `f`-preimage of `a` is an `l₁` neighborhood. -/ def tendsto (f : α → β) (l₁ : filter α) (l₂ : filter β) := l₁.map f ≤ l₂ lemma tendsto_def {f : α → β} {l₁ : filter α} {l₂ : filter β} : tendsto f l₁ l₂ ↔ ∀ s ∈ l₂.sets, f ⁻¹' s ∈ l₁.sets := iff.rfl lemma tendsto_iff_comap {f : α → β} {l₁ : filter α} {l₂ : filter β} : tendsto f l₁ l₂ ↔ l₁ ≤ l₂.comap f := map_le_iff_le_comap lemma tendsto_cong {f₁ f₂ : α → β} {l₁ : filter α} {l₂ : filter β} (h : tendsto f₁ l₁ l₂) (hl : {x | f₁ x = f₂ x} ∈ l₁.sets) : tendsto f₂ l₁ l₂ := by rwa [tendsto, ←map_cong hl] lemma tendsto_id' {x y : filter α} : x ≤ y → tendsto id x y := by simp only [tendsto, map_id, forall_true_iff] {contextual := tt} lemma tendsto_id {x : filter α} : tendsto id x x := tendsto_id' $ le_refl x lemma tendsto.comp {f : α → β} {g : β → γ} {x : filter α} {y : filter β} {z : filter γ} (hf : tendsto f x y) (hg : tendsto g y z) : tendsto (g ∘ f) x z := calc map (g ∘ f) x = map g (map f x) : by rw [map_map] ... ≤ map g y : map_mono hf ... ≤ z : hg lemma tendsto_le_left {f : α → β} {x y : filter α} {z : filter β} (h : y ≤ x) : tendsto f x z → tendsto f y z := le_trans (map_mono h) lemma tendsto_le_right {f : α → β} {x : filter α} {y z : filter β} (h₁ : y ≤ z) (h₂ : tendsto f x y) : tendsto f x z := le_trans h₂ h₁ lemma tendsto_map {f : α → β} {x : filter α} : tendsto f x (map f x) := le_refl (map f x) lemma tendsto_map' {f : β → γ} {g : α → β} {x : filter α} {y : filter γ} (h : tendsto (f ∘ g) x y) : tendsto f (map g x) y := by rwa [tendsto, map_map] lemma tendsto_map'_iff {f : β → γ} {g : α → β} {x : filter α} {y : filter γ} : tendsto f (map g x) y ↔ tendsto (f ∘ g) x y := by rw [tendsto, map_map]; refl lemma tendsto_comap {f : α → β} {x : filter β} : tendsto f (comap f x) x := map_comap_le lemma tendsto_comap_iff {f : α → β} {g : β → γ} {a : filter α} {c : filter γ} : tendsto f a (c.comap g) ↔ tendsto (g ∘ f) a c := ⟨assume h, h.comp tendsto_comap, assume h, map_le_iff_le_comap.mp $ by rwa [map_map]⟩ lemma tendsto_comap'' {m : α → β} {f : filter α} {g : filter β} (s : set α) {i : γ → α} (hs : s ∈ f.sets) (hi : ∀a∈s, ∃c, i c = a) (h : tendsto (m ∘ i) (comap i f) g) : tendsto m f g := have tendsto m (map i $ comap i $ f) g, by rwa [tendsto, ←map_compose] at h, le_trans (map_mono $ le_map_comap' hs hi) this lemma comap_eq_of_inverse {f : filter α} {g : filter β} {φ : α → β} (ψ : β → α) (eq : ψ ∘ φ = id) (hφ : tendsto φ f g) (hψ : tendsto ψ g f) : comap φ g = f := begin refine le_antisymm (le_trans (comap_mono $ map_le_iff_le_comap.1 hψ) _) (map_le_iff_le_comap.1 hφ), rw [comap_comap_comp, eq, comap_id], exact le_refl _ end lemma map_eq_of_inverse {f : filter α} {g : filter β} {φ : α → β} (ψ : β → α) (eq : φ ∘ ψ = id) (hφ : tendsto φ f g) (hψ : tendsto ψ g f) : map φ f = g := begin refine le_antisymm hφ (le_trans _ (map_mono hψ)), rw [map_map, eq, map_id], exact le_refl _ end lemma tendsto_inf {f : α → β} {x : filter α} {y₁ y₂ : filter β} : tendsto f x (y₁ ⊓ y₂) ↔ tendsto f x y₁ ∧ tendsto f x y₂ := by simp only [tendsto, lattice.le_inf_iff, iff_self] lemma tendsto_inf_left {f : α → β} {x₁ x₂ : filter α} {y : filter β} (h : tendsto f x₁ y) : tendsto f (x₁ ⊓ x₂) y := le_trans (map_mono inf_le_left) h lemma tendsto_inf_right {f : α → β} {x₁ x₂ : filter α} {y : filter β} (h : tendsto f x₂ y) : tendsto f (x₁ ⊓ x₂) y := le_trans (map_mono inf_le_right) h lemma tendsto_infi {f : α → β} {x : filter α} {y : ι → filter β} : tendsto f x (⨅i, y i) ↔ ∀i, tendsto f x (y i) := by simp only [tendsto, iff_self, lattice.le_infi_iff] lemma tendsto_infi' {f : α → β} {x : ι → filter α} {y : filter β} (i : ι) : tendsto f (x i) y → tendsto f (⨅i, x i) y := tendsto_le_left (infi_le _ _) lemma tendsto_principal {f : α → β} {a : filter α} {s : set β} : tendsto f a (principal s) ↔ {a | f a ∈ s} ∈ a.sets := by simp only [tendsto, le_principal_iff, mem_map, iff_self] lemma tendsto_principal_principal {f : α → β} {s : set α} {t : set β} : tendsto f (principal s) (principal t) ↔ ∀a∈s, f a ∈ t := by simp only [tendsto, image_subset_iff, le_principal_iff, map_principal, mem_principal_sets]; refl lemma tendsto_pure_pure (f : α → β) (a : α) : tendsto f (pure a) (pure (f a)) := show filter.map f (pure a) ≤ pure (f a), by rw [filter.map_pure]; exact le_refl _ lemma tendsto_const_pure {a : filter α} {b : β} : tendsto (λa, b) a (pure b) := by simp [tendsto]; exact univ_mem_sets section lift /-- A variant on `bind` using a function `g` taking a set instead of a member of `α`. -/ protected def lift (f : filter α) (g : set α → filter β) := ⨅s ∈ f.sets, g s variables {f f₁ f₂ : filter α} {g g₁ g₂ : set α → filter β} lemma lift_sets_eq (hg : monotone g) : (f.lift g).sets = (⋃t∈f.sets, (g t).sets) := infi_sets_eq' (assume s hs t ht, ⟨s ∩ t, inter_mem_sets hs ht, hg $ inter_subset_left s t, hg $ inter_subset_right s t⟩) ⟨univ, univ_mem_sets⟩ lemma mem_lift {s : set β} {t : set α} (ht : t ∈ f.sets) (hs : s ∈ (g t).sets) : s ∈ (f.lift g).sets := le_principal_iff.mp $ show f.lift g ≤ principal s, from infi_le_of_le t $ infi_le_of_le ht $ le_principal_iff.mpr hs lemma mem_lift_sets (hg : monotone g) {s : set β} : s ∈ (f.lift g).sets ↔ (∃t∈f.sets, s ∈ (g t).sets) := by rw [lift_sets_eq hg]; simp only [mem_Union] lemma lift_le {f : filter α} {g : set α → filter β} {h : filter β} {s : set α} (hs : s ∈ f.sets) (hg : g s ≤ h) : f.lift g ≤ h := infi_le_of_le s $ infi_le_of_le hs $ hg lemma le_lift {f : filter α} {g : set α → filter β} {h : filter β} (hh : ∀s∈f.sets, h ≤ g s) : h ≤ f.lift g := le_infi $ assume s, le_infi $ assume hs, hh s hs lemma lift_mono (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁.lift g₁ ≤ f₂.lift g₂ := infi_le_infi $ assume s, infi_le_infi2 $ assume hs, ⟨hf hs, hg s⟩ lemma lift_mono' (hg : ∀s∈f.sets, g₁ s ≤ g₂ s) : f.lift g₁ ≤ f.lift g₂ := infi_le_infi $ assume s, infi_le_infi $ assume hs, hg s hs lemma map_lift_eq {m : β → γ} (hg : monotone g) : map m (f.lift g) = f.lift (map m ∘ g) := have monotone (map m ∘ g), from monotone_comp hg monotone_map, filter_eq $ set.ext $ by simp only [mem_lift_sets, hg, @mem_lift_sets _ _ f _ this, exists_prop, forall_const, mem_map, iff_self, function.comp_app] lemma comap_lift_eq {m : γ → β} (hg : monotone g) : comap m (f.lift g) = f.lift (comap m ∘ g) := have monotone (comap m ∘ g), from monotone_comp hg monotone_comap, filter_eq $ set.ext begin simp only [hg, @mem_lift_sets _ _ f _ this, comap, mem_lift_sets, mem_set_of_eq, exists_prop, function.comp_apply], exact λ s, ⟨λ ⟨b, ⟨a, ha, hb⟩, hs⟩, ⟨a, ha, b, hb, hs⟩, λ ⟨a, ha, b, hb, hs⟩, ⟨b, ⟨a, ha, hb⟩, hs⟩⟩ end theorem comap_lift_eq2 {m : β → α} {g : set β → filter γ} (hg : monotone g) : (comap m f).lift g = f.lift (g ∘ preimage m) := le_antisymm (le_infi $ assume s, le_infi $ assume hs, infi_le_of_le (preimage m s) $ infi_le _ ⟨s, hs, subset.refl _⟩) (le_infi $ assume s, le_infi $ assume ⟨s', hs', (h_sub : preimage m s' ⊆ s)⟩, infi_le_of_le s' $ infi_le_of_le hs' $ hg h_sub) lemma map_lift_eq2 {g : set β → filter γ} {m : α → β} (hg : monotone g) : (map m f).lift g = f.lift (g ∘ image m) := le_antisymm (infi_le_infi2 $ assume s, ⟨image m s, infi_le_infi2 $ assume hs, ⟨ f.sets_of_superset hs $ assume a h, mem_image_of_mem _ h, le_refl _⟩⟩) (infi_le_infi2 $ assume t, ⟨preimage m t, infi_le_infi2 $ assume ht, ⟨ht, hg $ assume x, assume h : x ∈ m '' preimage m t, let ⟨y, hy, h_eq⟩ := h in show x ∈ t, from h_eq ▸ hy⟩⟩) lemma lift_comm {g : filter β} {h : set α → set β → filter γ} : f.lift (λs, g.lift (h s)) = g.lift (λt, f.lift (λs, h s t)) := le_antisymm (le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj, infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi) (le_infi $ assume i, le_infi $ assume hi, le_infi $ assume j, le_infi $ assume hj, infi_le_of_le j $ infi_le_of_le hj $ infi_le_of_le i $ infi_le _ hi) lemma lift_assoc {h : set β → filter γ} (hg : monotone g) : (f.lift g).lift h = f.lift (λs, (g s).lift h) := le_antisymm (le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht, infi_le_of_le t $ infi_le _ $ (mem_lift_sets hg).mpr ⟨_, hs, ht⟩) (le_infi $ assume t, le_infi $ assume ht, let ⟨s, hs, h'⟩ := (mem_lift_sets hg).mp ht in infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le t $ infi_le _ h') lemma lift_lift_same_le_lift {g : set α → set α → filter β} : f.lift (λs, f.lift (g s)) ≤ f.lift (λs, g s s) := le_infi $ assume s, le_infi $ assume hs, infi_le_of_le s $ infi_le_of_le hs $ infi_le_of_le s $ infi_le _ hs lemma lift_lift_same_eq_lift {g : set α → set α → filter β} (hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)): f.lift (λs, f.lift (g s)) = f.lift (λs, g s s) := le_antisymm lift_lift_same_le_lift (le_infi $ assume s, le_infi $ assume hs, le_infi $ assume t, le_infi $ assume ht, infi_le_of_le (s ∩ t) $ infi_le_of_le (inter_mem_sets hs ht) $ calc g (s ∩ t) (s ∩ t) ≤ g s (s ∩ t) : hg₂ (s ∩ t) (inter_subset_left _ _) ... ≤ g s t : hg₁ s (inter_subset_right _ _)) lemma lift_principal {s : set α} (hg : monotone g) : (principal s).lift g = g s := le_antisymm (infi_le_of_le s $ infi_le _ $ subset.refl _) (le_infi $ assume t, le_infi $ assume hi, hg hi) theorem monotone_lift [preorder γ] {f : γ → filter α} {g : γ → set α → filter β} (hf : monotone f) (hg : monotone g) : monotone (λc, (f c).lift (g c)) := assume a b h, lift_mono (hf h) (hg h) lemma lift_neq_bot_iff (hm : monotone g) : (f.lift g ≠ ⊥) ↔ (∀s∈f.sets, g s ≠ ⊥) := classical.by_cases (assume hn : nonempty β, calc f.lift g ≠ ⊥ ↔ (⨅s : { s // s ∈ f.sets}, g s.val) ≠ ⊥ : by simp only [filter.lift, infi_subtype, iff_self, ne.def] ... ↔ (∀s:{ s // s ∈ f.sets}, g s.val ≠ ⊥) : infi_neq_bot_iff_of_directed hn (assume ⟨a, ha⟩ ⟨b, hb⟩, ⟨⟨a ∩ b, inter_mem_sets ha hb⟩, hm $ inter_subset_left _ _, hm $ inter_subset_right _ _⟩) ... ↔ (∀s∈f.sets, g s ≠ ⊥) : ⟨assume h s hs, h ⟨s, hs⟩, assume h ⟨s, hs⟩, h s hs⟩) (assume hn : ¬ nonempty β, have h₁ : f.lift g = ⊥, from filter_eq_bot_of_not_nonempty hn, have h₂ : ∀s, g s = ⊥, from assume s, filter_eq_bot_of_not_nonempty hn, calc (f.lift g ≠ ⊥) ↔ false : by simp only [h₁, iff_self, eq_self_iff_true, not_true, ne.def] ... ↔ (∀s∈f.sets, false) : ⟨false.elim, assume h, h univ univ_mem_sets⟩ ... ↔ (∀s∈f.sets, g s ≠ ⊥) : by simp only [h₂, iff_self, eq_self_iff_true, not_true, ne.def]) @[simp] lemma lift_const {f : filter α} {g : filter β} : f.lift (λx, g) = g := le_antisymm (lift_le univ_mem_sets $ le_refl g) (le_lift $ assume s hs, le_refl g) @[simp] lemma lift_inf {f : filter α} {g h : set α → filter β} : f.lift (λx, g x ⊓ h x) = f.lift g ⊓ f.lift h := by simp only [filter.lift, infi_inf_eq, eq_self_iff_true] @[simp] lemma lift_principal2 {f : filter α} : f.lift principal = f := le_antisymm (assume s hs, mem_lift hs (mem_principal_self s)) (le_infi $ assume s, le_infi $ assume hs, by simp only [hs, le_principal_iff]) lemma lift_infi {f : ι → filter α} {g : set α → filter β} (hι : nonempty ι) (hg : ∀{s t}, g s ⊓ g t = g (s ∩ t)) : (infi f).lift g = (⨅i, (f i).lift g) := le_antisymm (le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _)) (assume s, have g_mono : monotone g, from assume s t h, le_of_inf_eq $ eq.trans hg $ congr_arg g $ inter_eq_self_of_subset_left h, have ∀t∈(infi f).sets, (⨅ (i : ι), filter.lift (f i) g) ≤ g t, from assume t ht, infi_sets_induct ht (let ⟨i⟩ := hι in infi_le_of_le i $ infi_le_of_le univ $ infi_le _ univ_mem_sets) (assume i s₁ s₂ hs₁ hs₂, @hg s₁ s₂ ▸ le_inf (infi_le_of_le i $ infi_le_of_le s₁ $ infi_le _ hs₁) hs₂) (assume s₁ s₂ hs₁ hs₂, le_trans hs₂ $ g_mono hs₁), begin rw [lift_sets_eq g_mono], simp only [mem_Union, exists_imp_distrib], exact assume t ht hs, this t ht hs end) end lift section lift' /-- Specialize `lift` to functions `set α → set β`. This can be viewed as a generalization of `comap`. -/ protected def lift' (f : filter α) (h : set α → set β) := f.lift (principal ∘ h) variables {f f₁ f₂ : filter α} {h h₁ h₂ : set α → set β} lemma mem_lift' {t : set α} (ht : t ∈ f.sets) : h t ∈ (f.lift' h).sets := le_principal_iff.mp $ show f.lift' h ≤ principal (h t), from infi_le_of_le t $ infi_le_of_le ht $ le_refl _ lemma mem_lift'_sets (hh : monotone h) {s : set β} : s ∈ (f.lift' h).sets ↔ (∃t∈f.sets, h t ⊆ s) := have monotone (principal ∘ h), from assume a b h, principal_mono.mpr $ hh h, by simp only [filter.lift', @mem_lift_sets α β f _ this, exists_prop, iff_self, mem_principal_sets, function.comp_app] lemma lift'_le {f : filter α} {g : set α → set β} {h : filter β} {s : set α} (hs : s ∈ f.sets) (hg : principal (g s) ≤ h) : f.lift' g ≤ h := lift_le hs hg lemma lift'_mono (hf : f₁ ≤ f₂) (hh : h₁ ≤ h₂) : f₁.lift' h₁ ≤ f₂.lift' h₂ := lift_mono hf $ assume s, principal_mono.mpr $ hh s lemma lift'_mono' (hh : ∀s∈f.sets, h₁ s ⊆ h₂ s) : f.lift' h₁ ≤ f.lift' h₂ := infi_le_infi $ assume s, infi_le_infi $ assume hs, principal_mono.mpr $ hh s hs lemma lift'_cong (hh : ∀s∈f.sets, h₁ s = h₂ s) : f.lift' h₁ = f.lift' h₂ := le_antisymm (lift'_mono' $ assume s hs, le_of_eq $ hh s hs) (lift'_mono' $ assume s hs, le_of_eq $ (hh s hs).symm) lemma map_lift'_eq {m : β → γ} (hh : monotone h) : map m (f.lift' h) = f.lift' (image m ∘ h) := calc map m (f.lift' h) = f.lift (map m ∘ principal ∘ h) : map_lift_eq $ monotone_comp hh monotone_principal ... = f.lift' (image m ∘ h) : by simp only [(∘), filter.lift', map_principal, eq_self_iff_true] lemma map_lift'_eq2 {g : set β → set γ} {m : α → β} (hg : monotone g) : (map m f).lift' g = f.lift' (g ∘ image m) := map_lift_eq2 $ monotone_comp hg monotone_principal theorem comap_lift'_eq {m : γ → β} (hh : monotone h) : comap m (f.lift' h) = f.lift' (preimage m ∘ h) := calc comap m (f.lift' h) = f.lift (comap m ∘ principal ∘ h) : comap_lift_eq $ monotone_comp hh monotone_principal ... = f.lift' (preimage m ∘ h) : by simp only [(∘), filter.lift', comap_principal, eq_self_iff_true] theorem comap_lift'_eq2 {m : β → α} {g : set β → set γ} (hg : monotone g) : (comap m f).lift' g = f.lift' (g ∘ preimage m) := comap_lift_eq2 $ monotone_comp hg monotone_principal lemma lift'_principal {s : set α} (hh : monotone h) : (principal s).lift' h = principal (h s) := lift_principal $ monotone_comp hh monotone_principal lemma principal_le_lift' {t : set β} (hh : ∀s∈f.sets, t ⊆ h s) : principal t ≤ f.lift' h := le_infi $ assume s, le_infi $ assume hs, principal_mono.mpr (hh s hs) theorem monotone_lift' [preorder γ] {f : γ → filter α} {g : γ → set α → set β} (hf : monotone f) (hg : monotone g) : monotone (λc, (f c).lift' (g c)) := assume a b h, lift'_mono (hf h) (hg h) lemma lift_lift'_assoc {g : set α → set β} {h : set β → filter γ} (hg : monotone g) (hh : monotone h) : (f.lift' g).lift h = f.lift (λs, h (g s)) := calc (f.lift' g).lift h = f.lift (λs, (principal (g s)).lift h) : lift_assoc (monotone_comp hg monotone_principal) ... = f.lift (λs, h (g s)) : by simp only [lift_principal, hh, eq_self_iff_true] lemma lift'_lift'_assoc {g : set α → set β} {h : set β → set γ} (hg : monotone g) (hh : monotone h) : (f.lift' g).lift' h = f.lift' (λs, h (g s)) := lift_lift'_assoc hg (monotone_comp hh monotone_principal) lemma lift'_lift_assoc {g : set α → filter β} {h : set β → set γ} (hg : monotone g) : (f.lift g).lift' h = f.lift (λs, (g s).lift' h) := lift_assoc hg lemma lift_lift'_same_le_lift' {g : set α → set α → set β} : f.lift (λs, f.lift' (g s)) ≤ f.lift' (λs, g s s) := lift_lift_same_le_lift lemma lift_lift'_same_eq_lift' {g : set α → set α → set β} (hg₁ : ∀s, monotone (λt, g s t)) (hg₂ : ∀t, monotone (λs, g s t)): f.lift (λs, f.lift' (g s)) = f.lift' (λs, g s s) := lift_lift_same_eq_lift (assume s, monotone_comp monotone_id $ monotone_comp (hg₁ s) monotone_principal) (assume t, monotone_comp (hg₂ t) monotone_principal) lemma lift'_inf_principal_eq {h : set α → set β} {s : set β} : f.lift' h ⊓ principal s = f.lift' (λt, h t ∩ s) := le_antisymm (le_infi $ assume t, le_infi $ assume ht, calc filter.lift' f h ⊓ principal s ≤ principal (h t) ⊓ principal s : inf_le_inf (infi_le_of_le t $ infi_le _ ht) (le_refl _) ... = _ : by simp only [principal_eq_iff_eq, inf_principal, eq_self_iff_true, function.comp_app]) (le_inf (le_infi $ assume t, le_infi $ assume ht, infi_le_of_le t $ infi_le_of_le ht $ by simp only [le_principal_iff, inter_subset_left, mem_principal_sets, function.comp_app]; exact inter_subset_right _ _) (infi_le_of_le univ $ infi_le_of_le univ_mem_sets $ by simp only [le_principal_iff, inter_subset_right, mem_principal_sets, function.comp_app]; exact inter_subset_left _ _)) lemma lift'_neq_bot_iff (hh : monotone h) : (f.lift' h ≠ ⊥) ↔ (∀s∈f.sets, h s ≠ ∅) := calc (f.lift' h ≠ ⊥) ↔ (∀s∈f.sets, principal (h s) ≠ ⊥) : lift_neq_bot_iff (monotone_comp hh monotone_principal) ... ↔ (∀s∈f.sets, h s ≠ ∅) : by simp only [principal_eq_bot_iff, iff_self, ne.def, principal_eq_bot_iff] @[simp] lemma lift'_id {f : filter α} : f.lift' id = f := lift_principal2 lemma le_lift' {f : filter α} {h : set α → set β} {g : filter β} (h_le : ∀s∈f.sets, h s ∈ g.sets) : g ≤ f.lift' h := le_infi $ assume s, le_infi $ assume hs, by simp only [h_le, le_principal_iff, function.comp_app]; exact h_le s hs lemma lift_infi' {f : ι → filter α} {g : set α → filter β} (hι : nonempty ι) (hf : directed (≥) f) (hg : monotone g) : (infi f).lift g = (⨅i, (f i).lift g) := le_antisymm (le_infi $ assume i, lift_mono (infi_le _ _) (le_refl _)) (assume s, begin rw [lift_sets_eq hg], simp only [mem_Union, exists_imp_distrib, infi_sets_eq hf hι], exact assume t i ht hs, mem_infi_sets i $ mem_lift ht hs end) lemma lift'_infi {f : ι → filter α} {g : set α → set β} (hι : nonempty ι) (hg : ∀{s t}, g s ∩ g t = g (s ∩ t)) : (infi f).lift' g = (⨅i, (f i).lift' g) := lift_infi hι $ by simp only [principal_eq_iff_eq, inf_principal, function.comp_app]; apply assume s t, hg theorem comap_eq_lift' {f : filter β} {m : α → β} : comap m f = f.lift' (preimage m) := filter_eq $ set.ext $ by simp only [mem_lift'_sets, monotone_preimage, comap, exists_prop, forall_const, iff_self, mem_set_of_eq] end lift' section prod variables {s : set α} {t : set β} {f : filter α} {g : filter β} /- The product filter cannot be defined using the monad structure on filters. For example: F := do {x <- seq, y <- top, return (x, y)} hence: s ∈ F <-> ∃n, [n..∞] × univ ⊆ s G := do {y <- top, x <- seq, return (x, y)} hence: s ∈ G <-> ∀i:ℕ, ∃n, [n..∞] × {i} ⊆ s Now ⋃i, [i..∞] × {i} is in G but not in F. As product filter we want to have F as result. -/ /-- Product of filters. This is the filter generated by cartesian products of elements of the component filters. -/ protected def prod (f : filter α) (g : filter β) : filter (α × β) := f.comap prod.fst ⊓ g.comap prod.snd lemma prod_mem_prod {s : set α} {t : set β} {f : filter α} {g : filter β} (hs : s ∈ f.sets) (ht : t ∈ g.sets) : set.prod s t ∈ (filter.prod f g).sets := inter_mem_inf_sets (preimage_mem_comap hs) (preimage_mem_comap ht) lemma mem_prod_iff {s : set (α×β)} {f : filter α} {g : filter β} : s ∈ (filter.prod f g).sets ↔ (∃t₁∈f.sets, ∃t₂∈g.sets, set.prod t₁ t₂ ⊆ s) := begin simp only [filter.prod], split, exact assume ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, h⟩, ⟨s₁, hs₁, s₂, hs₂, subset.trans (inter_subset_inter hts₁ hts₂) h⟩, exact assume ⟨t₁, ht₁, t₂, ht₂, h⟩, ⟨prod.fst ⁻¹' t₁, ⟨t₁, ht₁, subset.refl _⟩, prod.snd ⁻¹' t₂, ⟨t₂, ht₂, subset.refl _⟩, h⟩ end lemma tendsto_fst {f : filter α} {g : filter β} : tendsto prod.fst (filter.prod f g) f := tendsto_inf_left tendsto_comap lemma tendsto_snd {f : filter α} {g : filter β} : tendsto prod.snd (filter.prod f g) g := tendsto_inf_right tendsto_comap lemma tendsto.prod_mk {f : filter α} {g : filter β} {h : filter γ} {m₁ : α → β} {m₂ : α → γ} (h₁ : tendsto m₁ f g) (h₂ : tendsto m₂ f h) : tendsto (λx, (m₁ x, m₂ x)) f (filter.prod g h) := tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ lemma prod_infi_left {f : ι → filter α} {g : filter β} (i : ι) : filter.prod (⨅i, f i) g = (⨅i, filter.prod (f i) g) := by rw [filter.prod, comap_infi, infi_inf i]; simp only [filter.prod, eq_self_iff_true] lemma prod_infi_right {f : filter α} {g : ι → filter β} (i : ι) : filter.prod f (⨅i, g i) = (⨅i, filter.prod f (g i)) := by rw [filter.prod, comap_infi, inf_infi i]; simp only [filter.prod, eq_self_iff_true] lemma prod_mono {f₁ f₂ : filter α} {g₁ g₂ : filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : filter.prod f₁ g₁ ≤ filter.prod f₂ g₂ := inf_le_inf (comap_mono hf) (comap_mono hg) lemma prod_comap_comap_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : filter α₁} {f₂ : filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} : filter.prod (comap m₁ f₁) (comap m₂ f₂) = comap (λp:β₁×β₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) := by simp only [filter.prod, comap_comap_comp, eq_self_iff_true, comap_inf] lemma prod_comm' : filter.prod f g = comap (prod.swap) (filter.prod g f) := by simp only [filter.prod, comap_comap_comp, (∘), inf_comm, prod.fst_swap, eq_self_iff_true, prod.snd_swap, comap_inf] lemma prod_comm : filter.prod f g = map (λp:β×α, (p.2, p.1)) (filter.prod g f) := by rw [prod_comm', ← map_swap_eq_comap_swap]; refl lemma prod_map_map_eq {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : filter α₁} {f₂ : filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : filter.prod (map m₁ f₁) (map m₂ f₂) = map (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) (filter.prod f₁ f₂) := le_antisymm (assume s hs, let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs in filter.sets_of_superset _ (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) $ calc set.prod (m₁ '' s₁) (m₂ '' s₂) = (λp:α₁×α₂, (m₁ p.1, m₂ p.2)) '' set.prod s₁ s₂ : set.prod_image_image_eq ... ⊆ _ : by rwa [image_subset_iff]) ((tendsto_fst.comp (le_refl _)).prod_mk (tendsto_snd.comp (le_refl _))) lemma map_prod (m : α × β → γ) (f : filter α) (g : filter β) : map m (f.prod g) = (f.map (λa b, m (a, b))).seq g := begin simp [filter.ext_iff, mem_prod_iff, mem_map_seq_iff], assume s, split, exact assume ⟨t, ht, s, hs, h⟩, ⟨s, hs, t, ht, assume x hx y hy, @h ⟨x, y⟩ ⟨hx, hy⟩⟩, exact assume ⟨s, hs, t, ht, h⟩, ⟨t, ht, s, hs, assume ⟨x, y⟩ ⟨hx, hy⟩, h x hx y hy⟩ end lemma prod_eq {f : filter α} {g : filter β} : f.prod g = (f.map prod.mk).seq g := have h : _ := map_prod id f g, by rwa [map_id] at h lemma prod_inf_prod {f₁ f₂ : filter α} {g₁ g₂ : filter β} : filter.prod f₁ g₁ ⊓ filter.prod f₂ g₂ = filter.prod (f₁ ⊓ f₂) (g₁ ⊓ g₂) := by simp only [filter.prod, comap_inf, inf_comm, inf_assoc, lattice.inf_left_comm] @[simp] lemma prod_bot1 {f : filter α} : filter.prod f (⊥ : filter β) = ⊥ := by simp [filter.prod] @[simp] lemma prod_bot2 {g : filter β} : filter.prod (⊥ : filter α) g = ⊥ := by simp [filter.prod] @[simp] lemma prod_principal_principal {s : set α} {t : set β} : filter.prod (principal s) (principal t) = principal (set.prod s t) := by simp only [filter.prod, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; refl @[simp] lemma prod_pure_pure {a : α} {b : β} : filter.prod (pure a) (pure b) = pure (a, b) := by simp lemma prod_def {f : filter α} {g : filter β} : f.prod g = (f.lift $ λs, g.lift' $ set.prod s) := have ∀(s:set α) (t : set β), principal (set.prod s t) = (principal s).comap prod.fst ⊓ (principal t).comap prod.snd, by simp only [principal_eq_iff_eq, comap_principal, inf_principal]; intros; refl, begin simp only [filter.lift', function.comp, this, -comap_principal, lift_inf, lift_const, lift_inf], rw [← comap_lift_eq monotone_principal, ← comap_lift_eq monotone_principal], simp only [filter.prod, lift_principal2, eq_self_iff_true] end lemma prod_same_eq : filter.prod f f = f.lift' (λt, set.prod t t) := by rw [prod_def]; from lift_lift'_same_eq_lift' (assume s, set.monotone_prod monotone_const monotone_id) (assume t, set.monotone_prod monotone_id monotone_const) lemma mem_prod_same_iff {s : set (α×α)} : s ∈ (filter.prod f f).sets ↔ (∃t∈f.sets, set.prod t t ⊆ s) := by rw [prod_same_eq, mem_lift'_sets]; exact set.monotone_prod monotone_id monotone_id lemma prod_lift_lift {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → filter β₁} {g₂ : set α₂ → filter β₂} (hg₁ : monotone g₁) (hg₂ : monotone g₂) : filter.prod (f₁.lift g₁) (f₂.lift g₂) = f₁.lift (λs, f₂.lift (λt, filter.prod (g₁ s) (g₂ t))) := begin simp only [prod_def], rw [lift_assoc], apply congr_arg, funext x, rw [lift_comm], apply congr_arg, funext y, rw [lift'_lift_assoc], exact hg₂, exact hg₁ end lemma prod_lift'_lift' {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : filter α₁} {f₂ : filter α₂} {g₁ : set α₁ → set β₁} {g₂ : set α₂ → set β₂} (hg₁ : monotone g₁) (hg₂ : monotone g₂) : filter.prod (f₁.lift' g₁) (f₂.lift' g₂) = f₁.lift (λs, f₂.lift' (λt, set.prod (g₁ s) (g₂ t))) := begin rw [prod_def, lift_lift'_assoc], apply congr_arg, funext x, rw [lift'_lift'_assoc], exact hg₂, exact set.monotone_prod monotone_const monotone_id, exact hg₁, exact (monotone_lift' monotone_const $ monotone_lam $ assume x, set.monotone_prod monotone_id monotone_const) end lemma prod_neq_bot {f : filter α} {g : filter β} : filter.prod f g ≠ ⊥ ↔ (f ≠ ⊥ ∧ g ≠ ⊥) := calc filter.prod f g ≠ ⊥ ↔ (∀s∈f.sets, g.lift' (set.prod s) ≠ ⊥) : begin rw [prod_def, lift_neq_bot_iff], exact (monotone_lift' monotone_const $ monotone_lam $ assume s, set.monotone_prod monotone_id monotone_const) end ... ↔ (∀s∈f.sets, ∀t∈g.sets, s ≠ ∅ ∧ t ≠ ∅) : begin apply forall_congr, intro s, apply forall_congr, intro hs, rw [lift'_neq_bot_iff], apply forall_congr, intro t, apply forall_congr, intro ht, rw [set.prod_neq_empty_iff], exact set.monotone_prod monotone_const monotone_id end ... ↔ (∀s∈f.sets, s ≠ ∅) ∧ (∀t∈g.sets, t ≠ ∅) : ⟨assume h, ⟨assume s hs, (h s hs univ univ_mem_sets).left, assume t ht, (h univ univ_mem_sets t ht).right⟩, assume ⟨h₁, h₂⟩ s hs t ht, ⟨h₁ s hs, h₂ t ht⟩⟩ ... ↔ _ : by simp only [forall_sets_neq_empty_iff_neq_bot] lemma tendsto_prod_iff {f : α × β → γ} {x : filter α} {y : filter β} {z : filter γ} : filter.tendsto f (filter.prod x y) z ↔ ∀ W ∈ z.sets, ∃ U ∈ x.sets, ∃ V ∈ y.sets, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop, iff_self] lemma tendsto_prod_self_iff {f : α × α → β} {x : filter α} {y : filter β} : filter.tendsto f (filter.prod x x) y ↔ ∀ W ∈ y.sets, ∃ U ∈ x.sets, ∀ (x x' : α), x ∈ U → x' ∈ U → f (x, x') ∈ W := by simp only [tendsto_def, mem_prod_same_iff, prod_sub_preimage_iff, exists_prop, iff_self] end prod /- at_top and at_bot -/ /-- `at_top` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def at_top [preorder α] : filter α := ⨅ a, principal {b | a ≤ b} /-- `at_bot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def at_bot [preorder α] : filter α := ⨅ a, principal {b | b ≤ a} lemma mem_at_top [preorder α] (a : α) : {b : α | a ≤ b} ∈ (@at_top α _).sets := mem_infi_sets a $ subset.refl _ @[simp] lemma at_top_ne_bot [inhabited α] [semilattice_sup α] : (at_top : filter α) ≠ ⊥ := infi_neq_bot_of_directed (by apply_instance) (assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of, mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩) (assume a, by simp only [principal_eq_bot_iff, ne.def, principal_eq_bot_iff]; exact ne_empty_of_mem (le_refl a)) @[simp] lemma mem_at_top_sets [inhabited α] [semilattice_sup α] {s : set α} : s ∈ (at_top : filter α).sets ↔ ∃a:α, ∀b≥a, b ∈ s := iff.intro (assume h, infi_sets_induct h ⟨default α, by simp only [forall_const, mem_univ, forall_true_iff]⟩ (assume a s₁ s₂ ha ⟨b, hb⟩, ⟨a ⊔ b, assume c hc, ⟨ha $ le_trans le_sup_left hc, hb _ $ le_trans le_sup_right hc⟩⟩) (assume s₁ s₂ h ⟨a, ha⟩, ⟨a, assume b hb, h $ ha _ hb⟩)) (assume ⟨a, h⟩, mem_infi_sets a $ assume x, h x) lemma map_at_top_eq [inhabited α] [semilattice_sup α] {f : α → β} : at_top.map f = (⨅a, principal $ f '' {a' | a ≤ a'}) := calc map f (⨅a, principal {a' | a ≤ a'}) = (⨅a, map f $ principal {a' | a ≤ a'}) : map_infi_eq (assume a b, ⟨a ⊔ b, by simp only [ge, le_principal_iff, forall_const, set_of_subset_set_of, mem_principal_sets, and_self, sup_le_iff, forall_true_iff] {contextual := tt}⟩) ⟨default α⟩ ... = (⨅a, principal $ f '' {a' | a ≤ a'}) : by simp only [map_principal, eq_self_iff_true] lemma tendsto_at_top {α β} [preorder β] (m : α → β) (f : filter α) : tendsto m f at_top ↔ (∀b, {a | b ≤ m a} ∈ f.sets) := by simp only [at_top, tendsto_infi, tendsto_principal]; refl lemma tendsto_at_top_at_top {α β} [preorder α] [preorder β] [hα : nonempty α] (h : directed (@has_le.le α _) id) (f : α → β) : tendsto f at_top at_top ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a := have directed ge (λ (a : α), principal {b : α | a ≤ b}), from λ a b, let ⟨z, hz⟩ := h b a in ⟨z, λ s h x hzx, h (le_trans hz.2 hzx), λ s h x hzx, h (le_trans hz.1 hzx)⟩, by rw [tendsto_at_top, at_top, infi_sets_eq this hα]; simp lemma tendsto_finset_image_at_top_at_top {i : β → γ} {j : γ → β} (h : ∀x, j (i x) = x) : tendsto (λs:finset γ, s.image j) at_top at_top := tendsto_infi.2 $ assume s, tendsto_infi' (s.image i) $ tendsto_principal_principal.2 $ assume t (ht : s.image i ⊆ t), calc s = (s.image i).image j : by simp only [finset.image_image, (∘), h]; exact finset.image_id.symm ... ⊆ t.image j : finset.image_subset_image ht /- ultrafilter -/ section ultrafilter open zorn variables {f g : filter α} /-- An ultrafilter is a minimal (maximal in the set order) proper filter. -/ def is_ultrafilter (f : filter α) := f ≠ ⊥ ∧ ∀g, g ≠ ⊥ → g ≤ f → f ≤ g lemma ultrafilter_unique (hg : is_ultrafilter g) (hf : f ≠ ⊥) (h : f ≤ g) : f = g := le_antisymm h (hg.right _ hf h) lemma le_of_ultrafilter {g : filter α} (hf : is_ultrafilter f) (h : f ⊓ g ≠ ⊥) : f ≤ g := le_of_inf_eq $ ultrafilter_unique hf h inf_le_left /-- Equivalent characterization of ultrafilters: A filter f is an ultrafilter if and only if for each set s, -s belongs to f if and only if s does not belong to f. -/ lemma ultrafilter_iff_compl_mem_iff_not_mem : is_ultrafilter f ↔ (∀ s, -s ∈ f.sets ↔ s ∉ f.sets) := ⟨assume hf s, ⟨assume hns hs, hf.1 $ empty_in_sets_eq_bot.mp $ by convert f.inter_sets hs hns; rw [inter_compl_self], assume hs, have f ≤ principal (-s), from le_of_ultrafilter hf $ assume h, hs $ mem_sets_of_neq_bot $ by simp only [h, eq_self_iff_true, lattice.neg_neg], by simp only [le_principal_iff] at this; assumption⟩, assume hf, ⟨mt empty_in_sets_eq_bot.mpr ((hf ∅).mp (by convert f.univ_sets; rw [compl_empty])), assume g hg g_le s hs, classical.by_contradiction $ mt (hf s).mpr $ assume : - s ∈ f.sets, have s ∩ -s ∈ g.sets, from inter_mem_sets hs (g_le this), by simp only [empty_in_sets_eq_bot, hg, inter_compl_self] at this; contradiction⟩⟩ lemma mem_or_compl_mem_of_ultrafilter (hf : is_ultrafilter f) (s : set α) : s ∈ f.sets ∨ - s ∈ f.sets := classical.or_iff_not_imp_left.2 (ultrafilter_iff_compl_mem_iff_not_mem.mp hf s).mpr lemma mem_or_mem_of_ultrafilter {s t : set α} (hf : is_ultrafilter f) (h : s ∪ t ∈ f.sets) : s ∈ f.sets ∨ t ∈ f.sets := (mem_or_compl_mem_of_ultrafilter hf s).imp_right (assume : -s ∈ f.sets, by filter_upwards [this, h] assume x hnx hx, hx.resolve_left hnx) lemma mem_of_finite_sUnion_ultrafilter {s : set (set α)} (hf : is_ultrafilter f) (hs : finite s) : ⋃₀ s ∈ f.sets → ∃t∈s, t ∈ f.sets := finite.induction_on hs (by simp only [empty_in_sets_eq_bot, hf.left, mem_empty_eq, sUnion_empty, forall_prop_of_false, exists_false, not_false_iff, exists_prop_of_false]) $ λ t s' ht' hs' ih, by simp only [exists_prop, mem_insert_iff, set.sUnion_insert]; exact assume h, (mem_or_mem_of_ultrafilter hf h).elim (assume : t ∈ f.sets, ⟨t, or.inl rfl, this⟩) (assume h, let ⟨t, hts', ht⟩ := ih h in ⟨t, or.inr hts', ht⟩) lemma mem_of_finite_Union_ultrafilter {is : set β} {s : β → set α} (hf : is_ultrafilter f) (his : finite is) (h : (⋃i∈is, s i) ∈ f.sets) : ∃i∈is, s i ∈ f.sets := have his : finite (image s is), from finite_image s his, have h : (⋃₀ image s is) ∈ f.sets, from by simp only [sUnion_image, set.sUnion_image]; assumption, let ⟨t, ⟨i, hi, h_eq⟩, (ht : t ∈ f.sets)⟩ := mem_of_finite_sUnion_ultrafilter hf his h in ⟨i, hi, h_eq.symm ▸ ht⟩ lemma ultrafilter_map {f : filter α} {m : α → β} (h : is_ultrafilter f) : is_ultrafilter (map m f) := by rw ultrafilter_iff_compl_mem_iff_not_mem at ⊢ h; exact assume s, h (m ⁻¹' s) lemma ultrafilter_pure {a : α} : is_ultrafilter (pure a) := begin rw ultrafilter_iff_compl_mem_iff_not_mem, intro s, rw [mem_pure_sets, mem_pure_sets], exact iff.rfl end lemma ultrafilter_bind {f : filter α} (hf : is_ultrafilter f) {m : α → filter β} (hm : ∀ a, is_ultrafilter (m a)) : is_ultrafilter (f.bind m) := begin simp only [ultrafilter_iff_compl_mem_iff_not_mem] at ⊢ hf hm, intro s, dsimp [bind, join, map], simp only [hm], apply hf end /-- The ultrafilter lemma: Any proper filter is contained in an ultrafilter. -/ lemma exists_ultrafilter (h : f ≠ ⊥) : ∃u, u ≤ f ∧ is_ultrafilter u := let τ := {f' // f' ≠ ⊥ ∧ f' ≤ f}, r : τ → τ → Prop := λt₁ t₂, t₂.val ≤ t₁.val, ⟨a, ha⟩ := inhabited_of_mem_sets h univ_mem_sets, top : τ := ⟨f, h, le_refl f⟩, sup : Π(c:set τ), chain r c → τ := λc hc, ⟨⨅a:{a:τ // a ∈ insert top c}, a.val.val, infi_neq_bot_of_directed ⟨a⟩ (directed_of_chain $ chain_insert hc $ assume ⟨b, _, hb⟩ _ _, or.inl hb) (assume ⟨⟨a, ha, _⟩, _⟩, ha), infi_le_of_le ⟨top, mem_insert _ _⟩ (le_refl _)⟩ in have ∀c (hc: chain r c) a (ha : a ∈ c), r a (sup c hc), from assume c hc a ha, infi_le_of_le ⟨a, mem_insert_of_mem _ ha⟩ (le_refl _), have (∃ (u : τ), ∀ (a : τ), r u a → r a u), from zorn (assume c hc, ⟨sup c hc, this c hc⟩) (assume f₁ f₂ f₃ h₁ h₂, le_trans h₂ h₁), let ⟨uτ, hmin⟩ := this in ⟨uτ.val, uτ.property.right, uτ.property.left, assume g hg₁ hg₂, hmin ⟨g, hg₁, le_trans hg₂ uτ.property.right⟩ hg₂⟩ /-- Construct an ultrafilter extending a given filter. The ultrafilter lemma is the assertion that such a filter exists; we use the axiom of choice to pick one. -/ noncomputable def ultrafilter_of (f : filter α) : filter α := if h : f = ⊥ then ⊥ else classical.epsilon (λu, u ≤ f ∧ is_ultrafilter u) lemma ultrafilter_of_spec (h : f ≠ ⊥) : ultrafilter_of f ≤ f ∧ is_ultrafilter (ultrafilter_of f) := begin have h' := classical.epsilon_spec (exists_ultrafilter h), simp only [ultrafilter_of, dif_neg, h, dif_neg, not_false_iff], simp only at h', assumption end lemma ultrafilter_of_le : ultrafilter_of f ≤ f := if h : f = ⊥ then by simp only [ultrafilter_of, dif_pos, h, dif_pos, eq_self_iff_true, le_bot_iff]; exact le_refl _ else (ultrafilter_of_spec h).left lemma ultrafilter_ultrafilter_of (h : f ≠ ⊥) : is_ultrafilter (ultrafilter_of f) := (ultrafilter_of_spec h).right lemma ultrafilter_of_ultrafilter (h : is_ultrafilter f) : ultrafilter_of f = f := ultrafilter_unique h (ultrafilter_ultrafilter_of h.left).left ultrafilter_of_le /-- A filter equals the intersection of all the ultrafilters which contain it. -/ lemma sup_of_ultrafilters (f : filter α) : f = ⨆ (g) (u : is_ultrafilter g) (H : g ≤ f), g := begin refine le_antisymm _ (supr_le $ λ g, supr_le $ λ u, supr_le $ λ H, H), intros s hs, -- If s ∉ f.sets, we'll apply the ultrafilter lemma to the restriction of f to -s. by_contradiction hs', let j : (-s) → α := subtype.val, have j_inv_s : j ⁻¹' s = ∅, by erw [←preimage_inter_range, subtype_val_range, inter_compl_self, preimage_empty], let f' := comap j f, have : f' ≠ ⊥, { apply mt empty_in_sets_eq_bot.mpr, rintro ⟨t, htf, ht⟩, suffices : t ⊆ s, from absurd (f.sets_of_superset htf this) hs', rw [subset_empty_iff] at ht, have : j '' (j ⁻¹' t) = ∅, by rw [ht, image_empty], erw [image_preimage_eq_inter_range, subtype_val_range, ←subset_compl_iff_disjoint, set.compl_compl] at this, exact this }, rcases exists_ultrafilter this with ⟨g', g'f', u'⟩, simp only [supr_sets_eq, mem_Inter] at hs, have := hs (g'.map subtype.val) (ultrafilter_map u') (map_le_iff_le_comap.mpr g'f'), rw [←le_principal_iff, map_le_iff_le_comap, comap_principal, j_inv_s, principal_empty, le_bot_iff] at this, exact absurd this u'.1 end /-- The `tendsto` relation can be checked on ultrafilters. -/ lemma tendsto_iff_ultrafilter (f : α → β) (l₁ : filter α) (l₂ : filter β) : tendsto f l₁ l₂ ↔ ∀ g, is_ultrafilter g → g ≤ l₁ → g.map f ≤ l₂ := ⟨assume h g u gx, le_trans (map_mono gx) h, assume h, by rw [sup_of_ultrafilters l₁]; simpa only [tendsto, map_supr, supr_le_iff]⟩ /- The ultrafilter monad. The monad structure on ultrafilters is the restriction of the one on filters. -/ def ultrafilter (α : Type u) : Type u := {f : filter α // is_ultrafilter f} def ultrafilter.map (m : α → β) (u : ultrafilter α) : ultrafilter β := ⟨u.val.map m, ultrafilter_map u.property⟩ def ultrafilter.pure (x : α) : ultrafilter α := ⟨pure x, ultrafilter_pure⟩ def ultrafilter.bind (u : ultrafilter α) (m : α → ultrafilter β) : ultrafilter β := ⟨u.val.bind (λ a, (m a).val), ultrafilter_bind u.property (λ a, (m a).property)⟩ instance ultrafilter.has_pure : has_pure ultrafilter := ⟨@ultrafilter.pure⟩ instance ultrafilter.has_bind : has_bind ultrafilter := ⟨@ultrafilter.bind⟩ instance ultrafilter.functor : functor ultrafilter := { map := @ultrafilter.map } instance ultrafilter.monad : monad ultrafilter := { map := @ultrafilter.map } section local attribute [instance] filter.monad filter.is_lawful_monad instance ultrafilter.is_lawful_monad : is_lawful_monad ultrafilter := { id_map := assume α f, subtype.eq (id_map f.val), pure_bind := assume α β a f, subtype.eq (pure_bind a (subtype.val ∘ f)), bind_assoc := assume α β γ f m₁ m₂, subtype.eq (filter_eq rfl), bind_pure_comp_eq_map := assume α β f x, subtype.eq (bind_pure_comp_eq_map _ f x.val) } end lemma ultrafilter.eq_iff_val_le_val {u v : ultrafilter α} : u = v ↔ u.val ≤ v.val := ⟨assume h, by rw h; exact le_refl _, assume h, by rw subtype.ext; apply ultrafilter_unique v.property u.property.1 h⟩ lemma exists_ultrafilter_iff (f : filter α) : (∃ (u : ultrafilter α), u.val ≤ f) ↔ f ≠ ⊥ := ⟨assume ⟨u, uf⟩, lattice.neq_bot_of_le_neq_bot u.property.1 uf, assume h, let ⟨u, uf, hu⟩ := exists_ultrafilter h in ⟨⟨u, hu⟩, uf⟩⟩ end ultrafilter end filter namespace filter variables {α β γ : Type u} {f : β → filter α} {s : γ → set α} open list lemma mem_traverse_sets : ∀(fs : list β) (us : list γ), forall₂ (λb c, s c ∈ (f b).sets) fs us → traverse s us ∈ (traverse f fs).sets | [] [] forall₂.nil := mem_pure_sets.2 $ mem_singleton _ | (f::fs) (u::us) (forall₂.cons h hs) := seq_mem_seq_sets (image_mem_map h) (mem_traverse_sets fs us hs) lemma mem_traverse_sets_iff (fs : list β) (t : set (list α)) : t ∈ (traverse f fs).sets ↔ (∃us:list (set α), forall₂ (λb (s : set α), s ∈ (f b).sets) fs us ∧ sequence us ⊆ t) := begin split, { induction fs generalizing t, case nil { simp only [sequence, pure_def, imp_self, forall₂_nil_left_iff, pure_def, exists_eq_left, mem_principal_sets, set.pure_def, singleton_subset_iff, traverse_nil] }, case cons : b fs ih t { assume ht, rcases mem_seq_sets_iff.1 ht with ⟨u, hu, v, hv, ht⟩, rcases mem_map_sets_iff.1 hu with ⟨w, hw, hwu⟩, rcases ih v hv with ⟨us, hus, hu⟩, exact ⟨w :: us, forall₂.cons hw hus, subset.trans (set.seq_mono hwu hu) ht⟩ } }, { rintros ⟨us, hus, hs⟩, exact mem_sets_of_superset (mem_traverse_sets _ _ hus) hs } end lemma sequence_mono : ∀(as bs : list (filter α)), forall₂ (≤) as bs → sequence as ≤ sequence bs | [] [] forall₂.nil := le_refl _ | (a::as) (b::bs) (forall₂.cons h hs) := seq_mono (map_mono h) (sequence_mono as bs hs) end filter
95f0a6821fb094207a0197ecdf3d84608a1a298a
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/tactic/lift.lean
62ca2dd4242a176495a10e4466b814c94e23f3c2
[ "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
9,246
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import tactic.rcases /-! # lift tactic This file defines the lift tactic, allowing the user to lift elements from one type to another under a specified condition. ## Tags lift, tactic -/ universe variables u v w /-- A class specifying that you can lift elements from `α` to `β` assuming `cond` is true. Used by the tactic `lift`. -/ class can_lift (α : Type u) (β : Type v) : Type (max u v) := (coe : β → α) (cond : α → Prop) (prf : ∀(x : α), cond x → ∃(y : β), coe y = x) open tactic @[user_attribute] meta def can_lift_attr : user_attribute (list name) := { name := "_can_lift", descr := "internal attribute used by the lift tactic", cache_cfg := { mk_cache := λ _, do { ls ← attribute.get_instances `instance, ls.mfilter $ λ l, do { (_,t) ← mk_const l >>= infer_type >>= open_pis, return $ t.is_app_of `can_lift } }, dependencies := [`instance] } } instance : can_lift ℤ ℕ := ⟨coe, λ n, 0 ≤ n, λ n hn, ⟨n.nat_abs, int.nat_abs_of_nonneg hn⟩⟩ /-- Enable automatic handling of pi types in `can_lift`. -/ instance pi.can_lift (ι : Type u) (α : Π i : ι, Type v) (β : Π i : ι, Type w) [Π i : ι, can_lift (α i) (β i)] : can_lift (Π i : ι, α i) (Π i : ι, β i) := { coe := λ f i, can_lift.coe (f i), cond := λ f, ∀ i, can_lift.cond (β i) (f i), prf := λ f hf, ⟨λ i, classical.some (can_lift.prf (f i) (hf i)), funext $ λ i, classical.some_spec (can_lift.prf (f i) (hf i))⟩ } namespace tactic /- Construct the proof of `cond x` in the lift tactic. `e` is the expression being lifted and `h` is the specified proof of `can_lift.cond e`. `old_tp` and `new_tp` are the arguments to `can_lift` and `inst` is the `can_lift`-instance. `s` and `to_unfold` contain the information of the simp set used to simplify. If the proof was specified, we check whether it has the correct type. If it doesn't have the correct type, we display an error message (but first call dsimp on the expression in the message). If the proof was not specified, we create assert it as a local constant. (The name of this local constant doesn't matter, since `lift` will remove it from the context) -/ meta def get_lift_prf (h : option pexpr) (old_tp new_tp inst e : expr) (s : simp_lemmas) (to_unfold : list name) : tactic expr := if h_some : h.is_some then (do prf ← i_to_expr (option.get h_some), prf_ty ← infer_type prf, expected_prf_ty ← mk_app `can_lift.cond [old_tp, new_tp, inst, e], unify prf_ty expected_prf_ty <|> (do expected_prf_ty2 ← s.dsimplify to_unfold expected_prf_ty, pformat!"lift tactic failed. The type of\n {prf}\nis\n {prf_ty}\nbut it is expected to be\n {expected_prf_ty2}" >>= fail), return prf) else (do prf_nm ← get_unused_name, prf ← mk_app `can_lift.cond [old_tp, new_tp, inst, e] >>= assert prf_nm, dsimp_target s to_unfold {}, swap, return prf) /-- Lift the expression `p` to the type `t`, with proof obligation given by `h`. The list `n` is used for the two newly generated names, and to specify whether `h` should remain in the local context. See the doc string of `tactic.interactive.lift` for more information. -/ meta def lift (p : pexpr) (t : pexpr) (h : option pexpr) (n : list name) : tactic unit := do propositional_goal <|> fail "lift tactic failed. Tactic is only applicable when the target is a proposition.", e ← i_to_expr p, old_tp ← infer_type e, new_tp ← i_to_expr t, inst_type ← mk_app ``can_lift [old_tp, new_tp], inst ← mk_instance inst_type <|> pformat!"Failed to find a lift from {old_tp} to {new_tp}. Provide an instance of\n {inst_type}" >>= fail, /- make the simp set to get rid of `can_lift` projections -/ can_lift_instances ← can_lift_attr.get_cache >>= λ l, l.mmap resolve_name, (s, to_unfold) ← mk_simp_set tt [] $ can_lift_instances.map simp_arg_type.expr, prf_cond ← get_lift_prf h old_tp new_tp inst e s to_unfold, let prf_nm := if prf_cond.is_local_constant then some prf_cond.local_pp_name else none, /- We use mk_mapp to apply `can_lift.prf` to all but one argument, and then just use expr.app for the last argument. For some reason we get an error when applying mk_mapp it to all arguments. -/ prf_ex0 ← mk_mapp `can_lift.prf [old_tp, new_tp, inst, e], let prf_ex := prf_ex0 prf_cond, /- Find the name of the new variable -/ new_nm ← if n ≠ [] then return n.head else if e.is_local_constant then return e.local_pp_name else get_unused_name, /- Find the name of the proof of the equation -/ eq_nm ← if hn : 1 < n.length then return (n.nth_le 1 hn) else if e.is_local_constant then return `rfl else get_unused_name `h, /- We add the proof of the existential statement to the context and then apply `dsimp` to it, unfolding all `can_lift` instances. -/ temp_nm ← get_unused_name, temp_e ← note temp_nm none prf_ex, dsimp_hyp temp_e s to_unfold {}, /- We case on the existential. We use `rcases` because `eq_nm` could be `rfl`. -/ rcases none (pexpr.of_expr temp_e) $ rcases_patt.tuple ([new_nm, eq_nm].map rcases_patt.one), /- If the lifted variable is not a local constant, try to rewrite it away using the new equality-/ when (¬ e.is_local_constant) (get_local eq_nm >>= λ e, interactive.rw ⟨[⟨⟨0, 0⟩, tt, (pexpr.of_expr e)⟩], none⟩ interactive.loc.wildcard), /- If the proof `prf_cond` is a local constant, remove it from the context, unless `n` specifies to keep it. -/ if h_prf_nm : prf_nm.is_some ∧ n.nth 2 ≠ prf_nm then get_local (option.get h_prf_nm.1) >>= clear else skip open lean.parser interactive interactive.types local postfix `?`:9001 := optional meta def using_texpr := (tk "using" *> texpr)? reserve notation `to` meta def to_texpr := (tk "to" *> texpr) namespace interactive /-- Lift an expression to another type. Lift an expression to another type. * Usage: `'lift' expr 'to' expr ('using' expr)? ('with' id (id id?)?)?`. * If `n : ℤ` and `hn : n ≥ 0` then the tactic `lift n to ℕ using hn` creates a new constant of type `ℕ`, also named `n` and replaces all occurrences of the old variable `(n : ℤ)` with `↑n` (where `n` in the new variable). It will remove `n` and `hn` from the context. + So for example the tactic `lift n to ℕ using hn` transforms the goal `n : ℤ, hn : n ≥ 0, h : P n ⊢ n = 3` to `n : ℕ, h : P ↑n ⊢ ↑n = 3` (here `P` is some term of type `ℤ → Prop`). * The argument `using hn` is optional, the tactic `lift n to ℕ` does the same, but also creates a new subgoal that `n ≥ 0` (where `n` is the old variable). + So for example the tactic `lift n to ℕ` transforms the goal `n : ℤ, h : P n ⊢ n = 3` to two goals `n : ℕ, h : P ↑n ⊢ ↑n = 3` and `n : ℤ, h : P n ⊢ n ≥ 0`. * You can also use `lift n to ℕ using e` where `e` is any expression of type `n ≥ 0`. * Use `lift n to ℕ with k` to specify the name of the new variable. * Use `lift n to ℕ with k hk` to also specify the name of the equality `↑k = n`. In this case, `n` will remain in the context. You can use `rfl` for the name of `hk` to substitute `n` away (i.e. the default behavior). * You can also use `lift e to ℕ with k hk` where `e` is any expression of type `ℤ`. In this case, the `hk` will always stay in the context, but it will be used to rewrite `e` in all hypotheses and the target. + So for example the tactic `lift n + 3 to ℕ using hn with k hk` transforms the goal `n : ℤ, hn : n + 3 ≥ 0, h : P (n + 3) ⊢ n + 3 = 2 * n` to the goal `n : ℤ, k : ℕ, hk : ↑k = n + 3, h : P ↑k ⊢ ↑k = 2 * n`. * The tactic `lift n to ℕ using h` will remove `h` from the context. If you want to keep it, specify it again as the third argument to `with`, like this: `lift n to ℕ using h with n rfl h`. * More generally, this can lift an expression from `α` to `β` assuming that there is an instance of `can_lift α β`. In this case the proof obligation is specified by `can_lift.cond`. * Given an instance `can_lift β γ`, it can also lift `α → β` to `α → γ`; more generally, given `β : Π a : α, Type*`, `γ : Π a : α, Type*`, and `[Π a : α, can_lift (β a) (γ a)]`, it automatically generates an instance `can_lift (Π a, β a) (Π a, γ a)`. `lift` is in some sense dual to the `zify` tactic. `lift (z : ℤ) to ℕ` will change the type of an integer `z` (in the supertype) to `ℕ` (the subtype), given a proof that `z ≥ 0`; propositions concerning `z` will still be over `ℤ`. `zify` changes propositions about `ℕ` (the subtype) to propositions about `ℤ` (the supertype), without changing the type of any variable. -/ meta def lift (p : parse texpr) (t : parse to_texpr) (h : parse using_texpr) (n : parse with_ident_list) : tactic unit := tactic.lift p t h n add_tactic_doc { name := "lift", category := doc_category.tactic, decl_names := [`tactic.interactive.lift], tags := ["coercions"] } end interactive end tactic
0d8771449ffb2d48a7a80d8a1e1356f4e972e947
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/group_theory/congruence_auto.lean
6811d904b59bb590c5c56326f3e0f136435bfc3f
[]
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
37,004
lean
/- Copyright (c) 2019 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.setoid.basic import Mathlib.algebra.group.pi import Mathlib.algebra.group.prod import Mathlib.data.equiv.mul_add import Mathlib.group_theory.submonoid.operations import Mathlib.PostPort universes u_1 l u_3 u_2 namespace Mathlib /-! # Congruence relations This file defines congruence relations: equivalence relations that preserve a binary operation, which in this case is multiplication or addition. The principal definition is a `structure` extending a `setoid` (an equivalence relation), and the inductive definition of the smallest congruence relation containing a binary relation is also given (see `con_gen`). The file also proves basic properties of the quotient of a type by a congruence relation, and the complete lattice of congruence relations on a type. We then establish an order-preserving bijection between the set of congruence relations containing a congruence relation `c` and the set of congruence relations on the quotient by `c`. The second half of the file concerns congruence relations on monoids, in which case the quotient by the congruence relation is also a monoid. There are results about the universal property of quotients of monoids, and the isomorphism theorems for monoids. ## Implementation notes The inductive definition of a congruence relation could be a nested inductive type, defined using the equivalence closure of a binary relation `eqv_gen`, but the recursor generated does not work. A nested inductive definition could conceivably shorten proofs, because they would allow invocation of the corresponding lemmas about `eqv_gen`. The lemmas `refl`, `symm` and `trans` are not tagged with `@[refl]`, `@[symm]`, and `@[trans]` respectively as these tags do not work on a structure coerced to a binary relation. There is a coercion from elements of a type to the element's equivalence class under a congruence relation. A congruence relation on a monoid `M` can be thought of as a submonoid of `M × M` for which membership is an equivalence relation, but whilst this fact is established in the file, it is not used, since this perspective adds more layers of definitional unfolding. ## Tags congruence, congruence relation, quotient, quotient by congruence relation, monoid, quotient monoid, isomorphism theorems -/ /-- A congruence relation on a type with an addition is an equivalence relation which preserves addition. -/ structure add_con (M : Type u_1) [Add M] extends setoid M where add' : ∀ {w x y z : M}, r w x → r y z → r (w + y) (x + z) /-- A congruence relation on a type with a multiplication is an equivalence relation which preserves multiplication. -/ structure con (M : Type u_1) [Mul M] extends setoid M where mul' : ∀ {w x y z : M}, r w x → r y z → r (w * y) (x * z) /-- The equivalence relation underlying an additive congruence relation. -/ /-- The equivalence relation underlying a multiplicative congruence relation. -/ /-- The inductively defined smallest additive congruence relation containing a given binary relation. -/ inductive add_con_gen.rel {M : Type u_1} [Add M] (r : M → M → Prop) : M → M → Prop where | of : ∀ (x y : M), r x y → add_con_gen.rel r x y | refl : ∀ (x : M), add_con_gen.rel r x x | symm : ∀ (x y : M), add_con_gen.rel r x y → add_con_gen.rel r y x | trans : ∀ (x y z : M), add_con_gen.rel r x y → add_con_gen.rel r y z → add_con_gen.rel r x z | add : ∀ (w x y z : M), add_con_gen.rel r w x → add_con_gen.rel r y z → add_con_gen.rel r (w + y) (x + z) /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ inductive con_gen.rel {M : Type u_1} [Mul M] (r : M → M → Prop) : M → M → Prop where | of : ∀ (x y : M), r x y → con_gen.rel r x y | refl : ∀ (x : M), con_gen.rel r x x | symm : ∀ (x y : M), con_gen.rel r x y → con_gen.rel r y x | trans : ∀ (x y z : M), con_gen.rel r x y → con_gen.rel r y z → con_gen.rel r x z | mul : ∀ (w x y z : M), con_gen.rel r w x → con_gen.rel r y z → con_gen.rel r (w * y) (x * z) /-- The inductively defined smallest multiplicative congruence relation containing a given binary relation. -/ def con_gen {M : Type u_1} [Mul M] (r : M → M → Prop) : con M := con.mk sorry sorry sorry namespace con protected instance Mathlib.add_con.inhabited {M : Type u_1} [Add M] : Inhabited (add_con M) := { default := add_con_gen empty_relation } /-- A coercion from a congruence relation to its underlying binary relation. -/ protected instance Mathlib.add_con.has_coe_to_fun {M : Type u_1} [Add M] : has_coe_to_fun (add_con M) := has_coe_to_fun.mk (fun (c : add_con M) => M → M → Prop) fun (c : add_con M) (x y : M) => add_con.r c x y @[simp] theorem Mathlib.add_con.rel_eq_coe {M : Type u_1} [Add M] (c : add_con M) : add_con.r c = ⇑c := rfl /-- Congruence relations are reflexive. -/ protected theorem Mathlib.add_con.refl {M : Type u_1} [Add M] (c : add_con M) (x : M) : coe_fn c x x := and.left (add_con.iseqv c) x /-- Congruence relations are symmetric. -/ protected theorem Mathlib.add_con.symm {M : Type u_1} [Add M] (c : add_con M) {x : M} {y : M} : coe_fn c x y → coe_fn c y x := fun (h : coe_fn c _x✝ _x) => and.left (and.right (add_con.iseqv c)) _x✝ _x h /-- Congruence relations are transitive. -/ protected theorem Mathlib.add_con.trans {M : Type u_1} [Add M] (c : add_con M) {x : M} {y : M} {z : M} : coe_fn c x y → coe_fn c y z → coe_fn c x z := fun (h : coe_fn c _x✝¹ _x✝) => and.right (and.right (add_con.iseqv c)) _x✝¹ _x✝ _x h /-- Multiplicative congruence relations preserve multiplication. -/ protected theorem Mathlib.add_con.add {M : Type u_1} [Add M] (c : add_con M) {w : M} {x : M} {y : M} {z : M} : coe_fn c w x → coe_fn c y z → coe_fn c (w + y) (x + z) := fun (h1 : coe_fn c _x✝² _x✝¹) (h2 : coe_fn c _x✝ _x) => add_con.add' c h1 h2 /-- Given a type `M` with a multiplication, a congruence relation `c` on `M`, and elements of `M` `x, y`, `(x, y) ∈ M × M` iff `x` is related to `y` by `c`. -/ protected instance Mathlib.add_con.has_mem {M : Type u_1} [Add M] : has_mem (M × M) (add_con M) := has_mem.mk fun (x : M × M) (c : add_con M) => coe_fn c (prod.fst x) (prod.snd x) /-- The map sending a congruence relation to its underlying binary relation is injective. -/ theorem Mathlib.add_con.ext' {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} (H : add_con.r c = add_con.r d) : c = d := sorry /-- Extensionality rule for congruence relations. -/ theorem Mathlib.add_con.ext {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} (H : ∀ (x y : M), coe_fn c x y ↔ coe_fn d x y) : c = d := add_con.ext' (funext fun (x : M) => funext fun (x_1 : M) => propext (H x x_1)) /-- The map sending a congruence relation to its underlying equivalence relation is injective. -/ theorem to_setoid_inj {M : Type u_1} [Mul M] {c : con M} {d : con M} (H : to_setoid c = to_setoid d) : c = d := ext (iff.mp setoid.ext_iff H) /-- Iff version of extensionality rule for congruence relations. -/ theorem Mathlib.add_con.ext_iff {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} : (∀ (x y : M), coe_fn c x y ↔ coe_fn d x y) ↔ c = d := { mp := add_con.ext, mpr := fun (h : c = d) (_x _x_1 : M) => h ▸ iff.rfl } /-- Two congruence relations are equal iff their underlying binary relations are equal. -/ theorem ext'_iff {M : Type u_1} [Mul M] {c : con M} {d : con M} : r c = r d ↔ c = d := { mp := ext', mpr := fun (h : c = d) => h ▸ rfl } /-- The kernel of a multiplication-preserving function as a congruence relation. -/ def mul_ker {M : Type u_1} {P : Type u_3} [Mul M] [Mul P] (f : M → P) (h : ∀ (x y : M), f (x * y) = f x * f y) : con M := mk (fun (x y : M) => f x = f y) sorry sorry /-- Given types with multiplications `M, N`, the product of two congruence relations `c` on `M` and `d` on `N`: `(x₁, x₂), (y₁, y₂) ∈ M × N` are related by `c.prod d` iff `x₁` is related to `y₁` by `c` and `x₂` is related to `y₂` by `d`. -/ protected def Mathlib.add_con.prod {M : Type u_1} {N : Type u_2} [Add M] [Add N] (c : add_con M) (d : add_con N) : add_con (M × N) := add_con.mk setoid.r sorry sorry /-- The product of an indexed collection of congruence relations. -/ def Mathlib.add_con.pi {ι : Type u_1} {f : ι → Type u_2} [(i : ι) → Add (f i)] (C : (i : ι) → add_con (f i)) : add_con ((i : ι) → f i) := add_con.mk setoid.r sorry sorry @[simp] theorem Mathlib.add_con.coe_eq {M : Type u_1} [Add M] (c : add_con M) : setoid.r = ⇑c := rfl -- Quotients /-- Defining the quotient by a congruence relation of a type with a multiplication. -/ protected def Mathlib.add_con.quotient {M : Type u_1} [Add M] (c : add_con M) := quotient (add_con.to_setoid c) /-- Coercion from a type with a multiplication to its quotient by a congruence relation. See Note [use has_coe_t]. -/ protected instance quotient.has_coe_t {M : Type u_1} [Mul M] (c : con M) : has_coe_t M (con.quotient c) := has_coe_t.mk quotient.mk /-- The quotient of a type with decidable equality by a congruence relation also has decidable equality. -/ protected instance quotient.decidable_eq {M : Type u_1} [Mul M] (c : con M) [d : (a b : M) → Decidable (coe_fn c a b)] : DecidableEq (con.quotient c) := quotient.decidable_eq /-- The function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ protected def Mathlib.add_con.lift_on {M : Type u_1} [Add M] {β : Sort u_2} {c : add_con M} (q : add_con.quotient c) (f : M → β) (h : ∀ (a b : M), coe_fn c a b → f a = f b) : β := quotient.lift_on' q f h /-- The binary function on the quotient by a congruence relation `c` induced by a binary function that is constant on `c`'s equivalence classes. -/ protected def Mathlib.add_con.lift_on₂ {M : Type u_1} [Add M] {β : Sort u_2} {c : add_con M} (q : add_con.quotient c) (r : add_con.quotient c) (f : M → M → β) (h : ∀ (a₁ a₂ b₁ b₂ : M), coe_fn c a₁ b₁ → coe_fn c a₂ b₂ → f a₁ a₂ = f b₁ b₂) : β := quotient.lift_on₂' q r f h /-- The inductive principle used to prove propositions about the elements of a quotient by a congruence relation. -/ protected theorem Mathlib.add_con.induction_on {M : Type u_1} [Add M] {c : add_con M} {C : add_con.quotient c → Prop} (q : add_con.quotient c) (H : ∀ (x : M), C ↑x) : C q := quotient.induction_on' q H /-- A version of `con.induction_on` for predicates which take two arguments. -/ protected theorem Mathlib.add_con.induction_on₂ {M : Type u_1} {N : Type u_2} [Add M] [Add N] {c : add_con M} {d : add_con N} {C : add_con.quotient c → add_con.quotient d → Prop} (p : add_con.quotient c) (q : add_con.quotient d) (H : ∀ (x : M) (y : N), C ↑x ↑y) : C p q := quotient.induction_on₂' p q H /-- Two elements are related by a congruence relation `c` iff they are represented by the same element of the quotient by `c`. -/ @[simp] protected theorem Mathlib.add_con.eq {M : Type u_1} [Add M] (c : add_con M) {a : M} {b : M} : ↑a = ↑b ↔ coe_fn c a b := quotient.eq' /-- The multiplication induced on the quotient by a congruence relation on a type with a multiplication. -/ protected instance has_mul {M : Type u_1} [Mul M] (c : con M) : Mul (con.quotient c) := { mul := fun (x y : con.quotient c) => quotient.lift_on₂' x y (fun (w z : M) => ↑(w * z)) sorry } /-- The kernel of the quotient map induced by a congruence relation `c` equals `c`. -/ @[simp] theorem mul_ker_mk_eq {M : Type u_1} [Mul M] (c : con M) : (mul_ker coe fun (x y : M) => rfl) = c := ext fun (x y : M) => quotient.eq' /-- The coercion to the quotient of a congruence relation commutes with multiplication (by definition). -/ @[simp] theorem Mathlib.add_con.coe_add {M : Type u_1} [Add M] {c : add_con M} (x : M) (y : M) : ↑(x + y) = ↑x + ↑y := rfl /-- Definition of the function on the quotient by a congruence relation `c` induced by a function that is constant on `c`'s equivalence classes. -/ @[simp] protected theorem lift_on_beta {M : Type u_1} [Mul M] {β : Sort u_2} (c : con M) (f : M → β) (h : ∀ (a b : M), coe_fn c a b → f a = f b) (x : M) : con.lift_on (↑x) f h = f x := rfl /-- Makes an isomorphism of quotients by two congruence relations, given that the relations are equal. -/ protected def Mathlib.add_con.congr {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} (h : c = d) : add_con.quotient c ≃+ add_con.quotient d := add_equiv.mk (equiv.to_fun (quotient.congr (equiv.refl M) sorry)) (equiv.inv_fun (quotient.congr (equiv.refl M) sorry)) sorry sorry sorry -- The complete lattice of congruence relations on a type /-- For congruence relations `c, d` on a type `M` with a multiplication, `c ≤ d` iff `∀ x y ∈ M`, `x` is related to `y` by `d` if `x` is related to `y` by `c`. -/ protected instance Mathlib.add_con.has_le {M : Type u_1} [Add M] : HasLessEq (add_con M) := { LessEq := fun (c d : add_con M) => ∀ {x y : M}, coe_fn c x y → coe_fn d x y } /-- Definition of `≤` for congruence relations. -/ theorem Mathlib.add_con.le_def {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} : c ≤ d ↔ ∀ {x y : M}, coe_fn c x y → coe_fn d x y := iff.rfl /-- The infimum of a set of congruence relations on a given type with a multiplication. -/ protected instance Mathlib.add_con.has_Inf {M : Type u_1} [Add M] : has_Inf (add_con M) := has_Inf.mk fun (S : set (add_con M)) => add_con.mk (fun (x y : M) => ∀ (c : add_con M), c ∈ S → coe_fn c x y) sorry sorry /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying equivalence relation. -/ theorem Mathlib.add_con.Inf_to_setoid {M : Type u_1} [Add M] (S : set (add_con M)) : add_con.to_setoid (Inf S) = Inf (add_con.to_setoid '' S) := sorry /-- The infimum of a set of congruence relations is the same as the infimum of the set's image under the map to the underlying binary relation. -/ theorem Inf_def {M : Type u_1} [Mul M] (S : set (con M)) : r (Inf S) = Inf (r '' S) := sorry protected instance Mathlib.add_con.partial_order {M : Type u_1} [Add M] : partial_order (add_con M) := partial_order.mk LessEq (fun (c d : add_con M) => c ≤ d ∧ ¬d ≤ c) sorry sorry sorry /-- The complete lattice of congruence relations on a given type with a multiplication. -/ protected instance complete_lattice {M : Type u_1} [Mul M] : complete_lattice (con M) := complete_lattice.mk complete_lattice.sup complete_lattice.le complete_lattice.lt sorry sorry sorry sorry sorry sorry (fun (c d : con M) => mk setoid.r sorry sorry) sorry sorry sorry (mk setoid.r sorry sorry) sorry (mk setoid.r sorry sorry) sorry complete_lattice.Sup complete_lattice.Inf sorry sorry sorry sorry /-- The infimum of two congruence relations equals the infimum of the underlying binary operations. -/ theorem Mathlib.add_con.inf_def {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} : add_con.r (c ⊓ d) = add_con.r c ⊓ add_con.r d := rfl /-- Definition of the infimum of two congruence relations. -/ theorem Mathlib.add_con.inf_iff_and {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} {x : M} {y : M} : coe_fn (c ⊓ d) x y ↔ coe_fn c x y ∧ coe_fn d x y := iff.rfl /-- The inductively defined smallest congruence relation containing a binary relation `r` equals the infimum of the set of congruence relations containing `r`. -/ theorem Mathlib.add_con.add_con_gen_eq {M : Type u_1} [Add M] (r : M → M → Prop) : add_con_gen r = Inf (set_of fun (s : add_con M) => ∀ (x y : M), r x y → coe_fn s x y) := sorry /-- The smallest congruence relation containing a binary relation `r` is contained in any congruence relation containing `r`. -/ theorem con_gen_le {M : Type u_1} [Mul M] {r : M → M → Prop} {c : con M} (h : ∀ (x y : M), r x y → r c x y) : con_gen r ≤ c := eq.mpr (id (Eq._oldrec (Eq.refl (con_gen r ≤ c)) (con_gen_eq r))) (Inf_le h) /-- Given binary relations `r, s` with `r` contained in `s`, the smallest congruence relation containing `s` contains the smallest congruence relation containing `r`. -/ theorem Mathlib.add_con.add_con_gen_mono {M : Type u_1} [Add M] {r : M → M → Prop} {s : M → M → Prop} (h : ∀ (x y : M), r x y → s x y) : add_con_gen r ≤ add_con_gen s := add_con.add_con_gen_le fun (x y : M) (hr : r x y) => add_con_gen.rel.of x y (h x y hr) /-- Congruence relations equal the smallest congruence relation in which they are contained. -/ @[simp] theorem con_gen_of_con {M : Type u_1} [Mul M] (c : con M) : con_gen ⇑c = c := le_antisymm (eq.mpr (id (Eq._oldrec (Eq.refl (con_gen ⇑c ≤ c)) (con_gen_eq ⇑c))) (Inf_le fun (_x _x_1 : M) => id)) con_gen.rel.of /-- The map sending a binary relation to the smallest congruence relation in which it is contained is idempotent. -/ @[simp] theorem Mathlib.add_con.add_con_gen_idem {M : Type u_1} [Add M] (r : M → M → Prop) : add_con_gen ⇑(add_con_gen r) = add_con_gen r := add_con.add_con_gen_of_add_con (add_con_gen r) /-- The supremum of congruence relations `c, d` equals the smallest congruence relation containing the binary relation '`x` is related to `y` by `c` or `d`'. -/ theorem sup_eq_con_gen {M : Type u_1} [Mul M] (c : con M) (d : con M) : c ⊔ d = con_gen fun (x y : M) => coe_fn c x y ∨ coe_fn d x y := sorry /-- The supremum of two congruence relations equals the smallest congruence relation containing the supremum of the underlying binary operations. -/ theorem Mathlib.add_con.sup_def {M : Type u_1} [Add M] {c : add_con M} {d : add_con M} : c ⊔ d = add_con_gen (add_con.r c ⊔ add_con.r d) := eq.mpr (id (Eq._oldrec (Eq.refl (c ⊔ d = add_con_gen (add_con.r c ⊔ add_con.r d))) (add_con.sup_eq_add_con_gen c d))) (Eq.refl (add_con_gen fun (x y : M) => coe_fn c x y ∨ coe_fn d x y)) /-- The supremum of a set of congruence relations `S` equals the smallest congruence relation containing the binary relation 'there exists `c ∈ S` such that `x` is related to `y` by `c`'. -/ theorem Mathlib.add_con.Sup_eq_add_con_gen {M : Type u_1} [Add M] (S : set (add_con M)) : Sup S = add_con_gen fun (x y : M) => ∃ (c : add_con M), c ∈ S ∧ coe_fn c x y := sorry /-- The supremum of a set of congruence relations is the same as the smallest congruence relation containing the supremum of the set's image under the map to the underlying binary relation. -/ theorem Mathlib.add_con.Sup_def {M : Type u_1} [Add M] {S : set (add_con M)} : Sup S = add_con_gen (Sup (add_con.r '' S)) := sorry /-- There is a Galois insertion of congruence relations on a type with a multiplication `M` into binary relations on `M`. -/ protected def gi (M : Type u_1) [Mul M] : galois_insertion con_gen r := galois_insertion.mk (fun (r : M → M → Prop) (h : r (con_gen r) ≤ r) => con_gen r) sorry sorry sorry /-- Given a function `f`, the smallest congruence relation containing the binary relation on `f`'s image defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by a congruence relation `c`.' -/ def Mathlib.add_con.map_gen {M : Type u_1} {N : Type u_2} [Add M] [Add N] (c : add_con M) (f : M → N) : add_con N := add_con_gen fun (x y : N) => ∃ (a : M), ∃ (b : M), f a = x ∧ f b = y ∧ coe_fn c a b /-- Given a surjective multiplicative-preserving function `f` whose kernel is contained in a congruence relation `c`, the congruence relation on `f`'s codomain defined by '`x ≈ y` iff the elements of `f⁻¹(x)` are related to the elements of `f⁻¹(y)` by `c`.' -/ def Mathlib.add_con.map_of_surjective {M : Type u_1} {N : Type u_2} [Add M] [Add N] (c : add_con M) (f : M → N) (H : ∀ (x y : M), f (x + y) = f x + f y) (h : add_con.add_ker f H ≤ c) (hf : function.surjective f) : add_con N := add_con.mk setoid.r sorry sorry /-- A specialization of 'the smallest congruence relation containing a congruence relation `c` equals `c`'. -/ theorem Mathlib.add_con.map_of_surjective_eq_map_gen {M : Type u_1} {N : Type u_2} [Add M] [Add N] {c : add_con M} {f : M → N} (H : ∀ (x y : M), f (x + y) = f x + f y) (h : add_con.add_ker f H ≤ c) (hf : function.surjective f) : add_con.map_gen c f = add_con.map_of_surjective c f H h hf := sorry /-- Given types with multiplications `M, N` and a congruence relation `c` on `N`, a multiplication-preserving map `f : M → N` induces a congruence relation on `f`'s domain defined by '`x ≈ y` iff `f(x)` is related to `f(y)` by `c`.' -/ def Mathlib.add_con.comap {M : Type u_1} {N : Type u_2} [Add M] [Add N] (f : M → N) (H : ∀ (x y : M), f (x + y) = f x + f y) (c : add_con N) : add_con M := add_con.mk setoid.r sorry sorry /-- Given a congruence relation `c` on a type `M` with a multiplication, the order-preserving bijection between the set of congruence relations containing `c` and the congruence relations on the quotient of `M` by `c`. -/ def Mathlib.add_con.correspondence {M : Type u_1} [Add M] (c : add_con M) : (Subtype fun (d : add_con M) => c ≤ d) ≃o add_con (add_con.quotient c) := rel_iso.mk (equiv.mk (fun (d : Subtype fun (d : add_con M) => c ≤ d) => add_con.map_of_surjective (subtype.val d) coe sorry sorry sorry) (fun (d : add_con (add_con.quotient c)) => { val := add_con.comap coe sorry d, property := sorry }) sorry sorry) sorry -- Monoids /-- The quotient of a monoid by a congruence relation is a monoid. -/ protected instance monoid {M : Type u_1} [monoid M] (c : con M) : monoid (con.quotient c) := monoid.mk Mul.mul sorry ↑1 sorry sorry /-- The quotient of a `comm_monoid` by a congruence relation is a `comm_monoid`. -/ protected instance Mathlib.add_con.add_comm_monoid {α : Type u_1} [add_comm_monoid α] (c : add_con α) : add_comm_monoid (add_con.quotient c) := add_comm_monoid.mk add_monoid.add sorry add_monoid.zero sorry sorry sorry /-- The 1 of the quotient of a monoid by a congruence relation is the equivalence class of the monoid's 1. -/ @[simp] theorem coe_one {M : Type u_1} [monoid M] {c : con M} : ↑1 = 1 := rfl /-- The submonoid of `M × M` defined by a congruence relation on a monoid `M`. -/ protected def Mathlib.add_con.add_submonoid (M : Type u_1) [add_monoid M] (c : add_con M) : add_submonoid (M × M) := add_submonoid.mk (set_of fun (x : M × M) => coe_fn c (prod.fst x) (prod.snd x)) sorry sorry /-- The congruence relation on a monoid `M` from a submonoid of `M × M` for which membership is an equivalence relation. -/ def Mathlib.add_con.of_add_submonoid {M : Type u_1} [add_monoid M] (N : add_submonoid (M × M)) (H : equivalence fun (x y : M) => (x, y) ∈ N) : add_con M := add_con.mk (fun (x y : M) => (x, y) ∈ N) H sorry /-- Coercion from a congruence relation `c` on a monoid `M` to the submonoid of `M × M` whose elements are `(x, y)` such that `x` is related to `y` by `c`. -/ protected instance to_submonoid {M : Type u_1} [monoid M] : has_coe (con M) (submonoid (M × M)) := has_coe.mk fun (c : con M) => con.submonoid M c theorem Mathlib.add_con.mem_coe {M : Type u_1} [add_monoid M] {c : add_con M} {x : M} {y : M} : (x, y) ∈ ↑c ↔ (x, y) ∈ c := iff.rfl theorem to_submonoid_inj {M : Type u_1} [monoid M] (c : con M) (d : con M) (H : ↑c = ↑d) : c = d := sorry theorem Mathlib.add_con.le_iff {M : Type u_1} [add_monoid M] {c : add_con M} {d : add_con M} : c ≤ d ↔ ↑c ≤ ↑d := { mp := fun (h : c ≤ d) (x : M × M) (H : x ∈ ↑c) => h H, mpr := fun (h : ↑c ≤ ↑d) (x y : M) (hc : coe_fn c x y) => h ((fun (this : (x, y) ∈ c) => this) hc) } /-- The kernel of a monoid homomorphism as a congruence relation. -/ def Mathlib.add_con.ker {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (f : M →+ P) : add_con M := add_con.add_ker (⇑f) (add_monoid_hom.map_add' f) /-- The definition of the congruence relation defined by a monoid homomorphism's kernel. -/ theorem ker_rel {M : Type u_1} {P : Type u_3} [monoid M] [monoid P] (f : M →* P) {x : M} {y : M} : coe_fn (ker f) x y ↔ coe_fn f x = coe_fn f y := iff.rfl /-- There exists an element of the quotient of a monoid by a congruence relation (namely 1). -/ protected instance quotient.inhabited {M : Type u_1} [monoid M] {c : con M} : Inhabited (con.quotient c) := { default := ↑1 } /-- The natural homomorphism from a monoid to its quotient by a congruence relation. -/ def Mathlib.add_con.mk' {M : Type u_1} [add_monoid M] (c : add_con M) : M →+ add_con.quotient c := add_monoid_hom.mk coe sorry sorry /-- The kernel of the natural homomorphism from a monoid to its quotient by a congruence relation `c` equals `c`. -/ @[simp] theorem Mathlib.add_con.mk'_ker {M : Type u_1} [add_monoid M] (c : add_con M) : add_con.ker (add_con.mk' c) = c := add_con.ext fun (_x _x_1 : M) => add_con.eq c /-- The natural homomorphism from a monoid to its quotient by a congruence relation is surjective. -/ theorem Mathlib.add_con.mk'_surjective {M : Type u_1} [add_monoid M] {c : add_con M} : function.surjective ⇑(add_con.mk' c) := fun (x : add_con.quotient c) => quot.induction_on x fun (x : M) => Exists.intro x rfl @[simp] theorem Mathlib.add_con.comp_mk'_apply {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} (g : add_con.quotient c →+ P) {x : M} : coe_fn (add_monoid_hom.comp g (add_con.mk' c)) x = coe_fn g ↑x := rfl /-- The elements related to `x ∈ M`, `M` a monoid, by the kernel of a monoid homomorphism are those in the preimage of `f(x)` under `f`. -/ theorem Mathlib.add_con.ker_apply_eq_preimage {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {f : M →+ P} (x : M) : coe_fn (add_con.ker f) x = ⇑f ⁻¹' singleton (coe_fn f x) := sorry /-- Given a monoid homomorphism `f : N → M` and a congruence relation `c` on `M`, the congruence relation induced on `N` by `f` equals the kernel of `c`'s quotient homomorphism composed with `f`. -/ theorem Mathlib.add_con.comap_eq {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N] {c : add_con M} {f : N →+ M} : add_con.comap (⇑f) (add_monoid_hom.map_add f) c = add_con.ker (add_monoid_hom.comp (add_con.mk' c) f) := sorry /-- The homomorphism on the quotient of a monoid by a congruence relation `c` induced by a homomorphism constant on `c`'s equivalence classes. -/ def Mathlib.add_con.lift {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (c : add_con M) (f : M →+ P) (H : c ≤ add_con.ker f) : add_con.quotient c →+ P := add_monoid_hom.mk (fun (x : add_con.quotient c) => add_con.lift_on x ⇑f sorry) sorry sorry /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[simp] theorem Mathlib.add_con.lift_mk' {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (H : c ≤ add_con.ker f) (x : M) : coe_fn (add_con.lift c f H) (coe_fn (add_con.mk' c) x) = coe_fn f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[simp] theorem Mathlib.add_con.lift_coe {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (H : c ≤ add_con.ker f) (x : M) : coe_fn (add_con.lift c f H) ↑x = coe_fn f x := rfl /-- The diagram describing the universal property for quotients of monoids commutes. -/ @[simp] theorem Mathlib.add_con.lift_comp_mk' {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (H : c ≤ add_con.ker f) : add_monoid_hom.comp (add_con.lift c f H) (add_con.mk' c) = f := add_monoid_hom.ext fun (x : M) => Eq.refl (coe_fn (add_monoid_hom.comp (add_con.lift c f H) (add_con.mk' c)) x) /-- Given a homomorphism `f` from the quotient of a monoid by a congruence relation, `f` equals the homomorphism on the quotient induced by `f` composed with the natural map from the monoid to the quotient. -/ @[simp] theorem Mathlib.add_con.lift_apply_mk' {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} (f : add_con.quotient c →+ P) : (add_con.lift c (add_monoid_hom.comp f (add_con.mk' c)) fun (x y : M) (h : coe_fn c x y) => (fun (this : coe_fn f ↑x = coe_fn f ↑y) => this) (eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn f ↑x = coe_fn f ↑y)) (iff.mpr (add_con.eq c) h))) (Eq.refl (coe_fn f ↑y)))) = f := sorry /-- Homomorphisms on the quotient of a monoid by a congruence relation are equal if they are equal on elements that are coercions from the monoid. -/ theorem Mathlib.add_con.lift_funext {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} (f : add_con.quotient c →+ P) (g : add_con.quotient c →+ P) (h : ∀ (a : M), coe_fn f ↑a = coe_fn g ↑a) : f = g := sorry /-- The uniqueness part of the universal property for quotients of monoids. -/ theorem Mathlib.add_con.lift_unique {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (H : c ≤ add_con.ker f) (g : add_con.quotient c →+ P) (Hg : add_monoid_hom.comp g (add_con.mk' c) = f) : g = add_con.lift c f H := sorry /-- Given a congruence relation `c` on a monoid and a homomorphism `f` constant on `c`'s equivalence classes, `f` has the same image as the homomorphism that `f` induces on the quotient. -/ theorem Mathlib.add_con.lift_range {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (H : c ≤ add_con.ker f) : add_monoid_hom.mrange (add_con.lift c f H) = add_monoid_hom.mrange f := sorry /-- Surjective monoid homomorphisms constant on a congruence relation `c`'s equivalence classes induce a surjective homomorphism on `c`'s quotient. -/ theorem Mathlib.add_con.lift_surjective_of_surjective {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {c : add_con M} {f : M →+ P} (h : c ≤ add_con.ker f) (hf : function.surjective ⇑f) : function.surjective ⇑(add_con.lift c f h) := fun (y : P) => exists.elim (hf y) fun (w : M) (hw : coe_fn f w = y) => Exists.intro (↑w) (Eq.symm (add_con.lift_mk' h w) ▸ hw) /-- Given a monoid homomorphism `f` from `M` to `P`, the kernel of `f` is the unique congruence relation on `M` whose induced map from the quotient of `M` to `P` is injective. -/ theorem Mathlib.add_con.ker_eq_lift_of_injective {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (c : add_con M) (f : M →+ P) (H : c ≤ add_con.ker f) (h : function.injective ⇑(add_con.lift c f H)) : add_con.ker f = c := add_con.to_setoid_inj (setoid.ker_eq_lift_of_injective (⇑f) H h) /-- The homomorphism induced on the quotient of a monoid by the kernel of a monoid homomorphism. -/ def Mathlib.add_con.ker_lift {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (f : M →+ P) : add_con.quotient (add_con.ker f) →+ P := add_con.lift (add_con.ker f) f sorry /-- The diagram described by the universal property for quotients of monoids, when the congruence relation is the kernel of the homomorphism, commutes. -/ @[simp] theorem ker_lift_mk {M : Type u_1} {P : Type u_3} [monoid M] [monoid P] {f : M →* P} (x : M) : coe_fn (ker_lift f) ↑x = coe_fn f x := rfl /-- Given a monoid homomorphism `f`, the induced homomorphism on the quotient by `f`'s kernel has the same image as `f`. -/ @[simp] theorem Mathlib.add_con.ker_lift_range_eq {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] {f : M →+ P} : add_monoid_hom.mrange (add_con.ker_lift f) = add_monoid_hom.mrange f := add_con.lift_range fun (_x _x_1 : M) => id /-- A monoid homomorphism `f` induces an injective homomorphism on the quotient by `f`'s kernel. -/ theorem Mathlib.add_con.ker_lift_injective {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (f : M →+ P) : function.injective ⇑(add_con.ker_lift f) := fun (x y : add_con.quotient (add_con.ker f)) => quotient.induction_on₂' x y fun (_x _x_1 : M) => iff.mpr (add_con.eq (add_con.ker f)) /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, `d`'s quotient map induces a homomorphism from the quotient by `c` to the quotient by `d`. -/ def Mathlib.add_con.map {M : Type u_1} [add_monoid M] (c : add_con M) (d : add_con M) (h : c ≤ d) : add_con.quotient c →+ add_con.quotient d := add_con.lift c (add_con.mk' d) sorry /-- Given congruence relations `c, d` on a monoid such that `d` contains `c`, the definition of the homomorphism from the quotient by `c` to the quotient by `d` induced by `d`'s quotient map. -/ theorem Mathlib.add_con.map_apply {M : Type u_1} [add_monoid M] {c : add_con M} {d : add_con M} (h : c ≤ d) (x : add_con.quotient c) : coe_fn (add_con.map c d h) x = coe_fn (add_con.lift c (add_con.mk' d) fun (x y : M) (hc : coe_fn c x y) => iff.mpr (add_con.eq d) (h hc)) x := rfl /-- The first isomorphism theorem for monoids. -/ def Mathlib.add_con.quotient_ker_equiv_range {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (f : M →+ P) : add_con.quotient (add_con.ker f) ≃+ ↥(add_monoid_hom.mrange f) := add_equiv.mk (equiv.to_fun (equiv.of_bijective ⇑(add_monoid_hom.comp (add_equiv.to_add_monoid_hom (add_equiv.add_submonoid_congr add_con.ker_lift_range_eq)) (add_monoid_hom.mrange_restrict (add_con.ker_lift f))) sorry)) (equiv.inv_fun (equiv.of_bijective ⇑(add_monoid_hom.comp (add_equiv.to_add_monoid_hom (add_equiv.add_submonoid_congr add_con.ker_lift_range_eq)) (add_monoid_hom.mrange_restrict (add_con.ker_lift f))) sorry)) sorry sorry sorry /-- The first isomorphism theorem for monoids in the case of a surjective homomorphism. -/ def Mathlib.add_con.quotient_ker_equiv_of_surjective {M : Type u_1} {P : Type u_3} [add_monoid M] [add_monoid P] (f : M →+ P) (hf : function.surjective ⇑f) : add_con.quotient (add_con.ker f) ≃+ P := add_equiv.mk (equiv.to_fun (equiv.of_bijective ⇑(add_con.ker_lift f) sorry)) (equiv.inv_fun (equiv.of_bijective ⇑(add_con.ker_lift f) sorry)) sorry sorry sorry /-- The second isomorphism theorem for monoids. -/ def Mathlib.add_con.comap_quotient_equiv {M : Type u_1} {N : Type u_2} [add_monoid M] [add_monoid N] (c : add_con M) (f : N →+ M) : add_con.quotient (add_con.comap (⇑f) (add_monoid_hom.map_add f) c) ≃+ ↥(add_monoid_hom.mrange (add_monoid_hom.comp (add_con.mk' c) f)) := add_equiv.trans (add_con.congr add_con.comap_eq) (add_con.quotient_ker_equiv_range (add_monoid_hom.comp (add_con.mk' c) f)) /-- The third isomorphism theorem for monoids. -/ def quotient_quotient_equiv_quotient {M : Type u_1} [monoid M] (c : con M) (d : con M) (h : c ≤ d) : con.quotient (ker (map c d h)) ≃* con.quotient d := mul_equiv.mk (equiv.to_fun (setoid.quotient_quotient_equiv_quotient (to_setoid c) (to_setoid d) h)) (equiv.inv_fun (setoid.quotient_quotient_equiv_quotient (to_setoid c) (to_setoid d) h)) sorry sorry sorry /-- Multiplicative congruence relations preserve inversion. -/ protected theorem Mathlib.add_con.neg {M : Type u_1} [add_group M] (c : add_con M) {w : M} {x : M} : coe_fn c w x → coe_fn c (-w) (-x) := sorry /-- The inversion induced on the quotient by a congruence relation on a type with a inversion. -/ protected instance has_inv {M : Type u_1} [group M] (c : con M) : has_inv (con.quotient c) := has_inv.mk fun (x : con.quotient c) => quotient.lift_on' x (fun (w : M) => ↑(w⁻¹)) sorry /-- The quotient of a group by a congruence relation is a group. -/ protected instance Mathlib.add_con.add_group {M : Type u_1} [add_group M] (c : add_con M) : add_group (add_con.quotient c) := add_group.mk add_monoid.add sorry add_monoid.zero sorry sorry (fun (x : add_con.quotient c) => -x) (sub_neg_monoid.sub._default add_monoid.add sorry add_monoid.zero sorry sorry fun (x : add_con.quotient c) => -x) sorry end Mathlib
040d31fbad5934a6ec449683379f1576dcfde74c
64874bd1010548c7f5a6e3e8902efa63baaff785
/tests/lean/run/unzip_bug.lean
281074b680ea49a1c38110ea9547eacd79879851
[ "Apache-2.0" ]
permissive
tjiaqi/lean
4634d729795c164664d10d093f3545287c76628f
d0ce4cf62f4246b0600c07e074d86e51f2195e30
refs/heads/master
1,622,323,796,480
1,422,643,069,000
1,422,643,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
380
lean
import data.vector open nat vector prod variables {A B : Type} definition unzip : Π {n : nat}, vector (A × B) n → vector A n × vector B n, @unzip ⌞zero⌟ nil := (nil, nil), @unzip ⌞succ n⌟ ((a, b) :: v) := match unzip v with (va, vb) := (a :: va, b :: vb) end example : unzip ((1, 20) :: (2, 30) :: nil) = (1 :: 2 :: nil, 20 :: 30 :: nil) := rfl
cfd15b11bb4b11d76e44af072b301e7ac35181f9
5d166a16ae129621cb54ca9dde86c275d7d2b483
/tests/lean/run/sec_var.lean
a292628e0e3d902a7302f8d44d72cbd9e3790cb4
[ "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
541
lean
section parameter A : Type definition foo : ∀ ⦃ a b : A ⦄, a = b → a = b := take a b H, H variable a : A set_option pp.implicit true #check foo (eq.refl a) #check foo #check foo = (λ (a b : A) (H : a = b), H) end #check foo = (λ (A : Type) (a b : A) (H : a = b), H) section variable A : Type definition foo2 : ∀ ⦃ a b : A ⦄, a = b → a = b := take a b H, H variable a : A set_option pp.implicit true #check foo2 A (eq.refl a) #check foo2 #check foo2 A = (λ (a b : A) (H : a = b), H) end
601a04a4bbec5d2fc30b4cd4c438fee7bb884a99
55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5
/src/topology/tactic.lean
f89fcca94f2f3e473d0f09645891589aa6979fd6
[ "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
3,397
lean
/- Copyright (c) 2020 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import tactic.auto_cases import tactic.tidy import tactic.with_local_reducibility import topology.basic /-! # Tactics for topology Currently we have one domain-specific tactic for topology: `continuity`. -/ /-! ### `continuity` tactic Automatically solve goals of the form `continuous f`. Mark lemmas with `@[continuity]` to add them to the set of lemmas used by `continuity`. Note: `to_additive` doesn't know yet how to copy the attribute to the additive version. -/ /-- User attribute used to mark tactics used by `continuity`. -/ @[user_attribute] meta def continuity : user_attribute := { name := `continuity, descr := "lemmas usable to prove continuity" } -- Mark some continuity lemmas already defined in `topology.basic` attribute [continuity] continuous_id continuous_const namespace tactic /-- Tactic to apply `continuous.comp` when appropriate. Applying `continuous.comp` is not always a good idea, so we have some extra logic here to try to avoid bad cases. * If the function we're trying to prove continuous is actually constant, and that constant is a function application `f z`, then continuous.comp would produce new goals `continuous f`, `continuous (λ _, z)`, which is silly. We avoid this by failing if we could apply continuous_const. * continuous.comp will always succeed on `continuous (λ x, f x)` and produce new goals `continuous (λ x, x)`, `continuous f`. We detect this by failing if a new goal can be closed by applying continuous_id. -/ meta def apply_continuous.comp : tactic unit := `[fail_if_success { exact continuous_const }; refine continuous.comp _ _; fail_if_success { exact continuous_id }] /-- List of tactics used by `continuity` internally. -/ meta def continuity_tactics : list (tactic string) := [ `[apply_rules continuity] >> pure "apply_rules continuity", -- auto_cases, intros1 >>= λ ns, pure ("intros " ++ (" ".intercalate (ns.map (λ e, e.to_string)))), tactic.interactive.apply_assumption >> pure "apply_assumption", apply_continuous.comp >> pure "refine continuous.comp _ _" ] namespace interactive /-- Solve goals of the form `continuous f`. -/ meta def continuity (cfg : tidy.cfg := {}) : tactic unit := with_local_reducibility `continuous decl_reducibility.irreducible $ tactic.tidy { tactics := continuity_tactics, ..cfg } /-- Version of `continuity` for use with auto_param. -/ meta def continuity' : tactic unit := continuity /-- `continuity` solves goals of the form `continuous f` by applying lemmas tagged with the `continuity` user attribute. ``` example {X Y : Type*} [topological_space X] [topological_space Y] (f₁ f₂ : X → Y) (hf₁ : continuous f₁) (hf₂ : continuous f₂) (g : Y → ℝ) (hg : continuous g) : continuous (λ x, (max (g (f₁ x)) (g (f₂ x))) + 1) := by continuity ``` will discharge the goal, generating a proof term like `((continuous.comp hg hf₁).max (continuous.comp hg hf₂)).add continuous_const` -/ add_tactic_doc { name := "continuity / continuity'", category := doc_category.tactic, decl_names := [`tactic.interactive.continuity, `tactic.interactive.continuity'], tags := ["lemma application"] } end interactive end tactic
873694d4c977918edead26b798dfda35c833119a
d29d82a0af640c937e499f6be79fc552eae0aa13
/src/topology/basic.lean
af6986720651c2fd42b05f004308e7c4b29726c1
[ "Apache-2.0" ]
permissive
AbdulMajeedkhurasani/mathlib
835f8a5c5cf3075b250b3737172043ab4fa1edf6
79bc7323b164aebd000524ebafd198eb0e17f956
refs/heads/master
1,688,003,895,660
1,627,788,521,000
1,627,788,521,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
58,659
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import order.filter.ultrafilter import order.filter.partial import algebra.support /-! # Basic theory of topological spaces. The main definition is the type class `topological space α` which endows a type `α` with a topology. Then `set α` gets predicates `is_open`, `is_closed` and functions `interior`, `closure` and `frontier`. Each point `x` of `α` gets a neighborhood filter `𝓝 x`. A filter `F` on `α` has `x` as a cluster point if `cluster_pt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : ι → α` clusters at `x` along `F : filter ι` if `map_cluster_pt x F f : cluster_pt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `map_cluster_pt x at_top u`. This file also defines locally finite families of subsets of `α`. For topological spaces `α` and `β`, a function `f : α → β` and a point `a : α`, `continuous_at f a` means `f` is continuous at `a`, and global continuity is `continuous f`. There is also a version of continuity `pcontinuous` for partially defined functions. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhds_within x s` of neighborhoods of a point `x` within a set `s`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable theory open set filter classical open_locale classical filter universes u v w /-! ### Topological spaces -/ /-- A topology on `α`. -/ @[protect_proj] structure topological_space (α : Type u) := (is_open : set α → Prop) (is_open_univ : is_open univ) (is_open_inter : ∀s t, is_open s → is_open t → is_open (s ∩ t)) (is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s)) attribute [class] topological_space /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def topological_space.of_closed {α : Type u} (T : set (set α)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A ⊆ T, ⋂₀ A ∈ T) (union_mem : ∀ A B ∈ T, A ∪ B ∈ T) : topological_space α := { is_open := λ X, Xᶜ ∈ T, is_open_univ := by simp [empty_mem], is_open_inter := λ s t hs ht, by simpa [set.compl_inter] using union_mem sᶜ tᶜ hs ht, is_open_sUnion := λ s hs, by rw set.compl_sUnion; exact sInter_mem (set.compl '' s) (λ z ⟨y, hy, hz⟩, by simpa [hz.symm] using hs y hy) } section topological_space variables {α : Type u} {β : Type v} {ι : Sort w} {a : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop} @[ext] lemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g | ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl section variables [t : topological_space α] include t /-- `is_open s` means that `s` is open in the ambient topological space on `α` -/ def is_open (s : set α) : Prop := topological_space.is_open t s @[simp] lemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t lemma is_open.inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) := topological_space.is_open_inter t s₁ s₂ h₁ h₂ lemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) := topological_space.is_open_sUnion t s h end lemma topological_space_eq_iff {t t' : topological_space α} : t = t' ↔ ∀ s, @is_open α t s ↔ @is_open α t' s := ⟨λ h s, h ▸ iff.rfl, λ h, by { ext, exact h _ }⟩ lemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s := rfl variables [topological_space α] lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) := is_open_sUnion $ by rintro _ ⟨i, rfl⟩; exact h i lemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) : is_open (⋃i∈s, f i) := is_open_Union $ assume i, is_open_Union $ assume hi, h i hi lemma is_open.union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) := by rw union_eq_Union; exact is_open_Union (bool.forall_bool.2 ⟨h₂, h₁⟩) @[simp] lemma is_open_empty : is_open (∅ : set α) := by rw ← sUnion_empty; exact is_open_sUnion (assume a, false.elim) lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) := finite.induction_on hs (λ _, by rw sInter_empty; exact is_open_univ) $ λ a s has hs ih h, by rw sInter_insert; exact is_open.inter (h _ $ mem_insert _ _) (ih $ λ t, h t ∘ mem_insert_of_mem _) lemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) : (∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) := finite.induction_on hs (λ _, by rw bInter_empty; exact is_open_univ) (λ a s has hs ih h, by rw bInter_insert; exact is_open.inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi)))) lemma is_open_Inter [fintype β] {s : β → set α} (h : ∀ i, is_open (s i)) : is_open (⋂ i, s i) := suffices is_open (⋂ (i : β) (hi : i ∈ @univ β), s i), by simpa, is_open_bInter finite_univ (λ i _, h i) lemma is_open_Inter_prop {p : Prop} {s : p → set α} (h : ∀ h : p, is_open (s h)) : is_open (Inter s) := by by_cases p; simp * lemma is_open_const {p : Prop} : is_open {a : α | p} := by_cases (assume : p, begin simp only [this]; exact is_open_univ end) (assume : ¬ p, begin simp only [this]; exact is_open_empty end) lemma is_open.and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} := is_open.inter /-- A set is closed if its complement is open -/ class is_closed (s : set α) : Prop := (is_open_compl : is_open sᶜ) @[simp] lemma is_open_compl_iff {s : set α} : is_open sᶜ ↔ is_closed s := ⟨λ h, ⟨h⟩, λ h, h.is_open_compl⟩ @[simp] lemma is_closed_empty : is_closed (∅ : set α) := by { rw [← is_open_compl_iff, compl_empty], exact is_open_univ } @[simp] lemma is_closed_univ : is_closed (univ : set α) := by { rw [← is_open_compl_iff, compl_univ], exact is_open_empty } lemma is_closed.union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) := λ h₁ h₂, by { rw [← is_open_compl_iff] at *, rw compl_union, exact is_open.inter h₁ h₂ } lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) := by simpa only [← is_open_compl_iff, compl_sInter, sUnion_image] using is_open_bUnion lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) := is_closed_sInter $ assume t ⟨i, (heq : f i = t)⟩, heq ▸ h i lemma is_closed_bInter {s : set β} {f : β → set α} (h : ∀ i ∈ s, is_closed (f i)) : is_closed (⋂ i ∈ s, f i) := is_closed_Inter $ λ i, is_closed_Inter $ h i @[simp] lemma is_closed_compl_iff {s : set α} : is_closed sᶜ ↔ is_open s := by rw [←is_open_compl_iff, compl_compl] lemma is_open.is_closed_compl {s : set α} (hs : is_open s) : is_closed sᶜ := is_closed_compl_iff.2 hs lemma is_open.sdiff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \ t) := is_open.inter h₁ $ is_open_compl_iff.mpr h₂ lemma is_closed.inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) := by { rw [← is_open_compl_iff] at *, rw compl_inter, exact is_open.union h₁ h₂ } lemma is_closed.sdiff {s t : set α} (h₁ : is_closed s) (h₂ : is_open t) : is_closed (s \ t) := is_closed.inter h₁ (is_closed_compl_iff.mpr h₂) lemma is_closed_bUnion {s : set β} {f : β → set α} (hs : finite s) : (∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) := finite.induction_on hs (λ _, by rw bUnion_empty; exact is_closed_empty) (λ a s has hs ih h, by rw bUnion_insert; exact is_closed.union (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi)))) lemma is_closed_Union [fintype β] {s : β → set α} (h : ∀ i, is_closed (s i)) : is_closed (Union s) := suffices is_closed (⋃ (i : β) (hi : i ∈ @univ β), s i), by convert this; simp [set.ext_iff], is_closed_bUnion finite_univ (λ i _, h i) lemma is_closed_Union_prop {p : Prop} {s : p → set α} (h : ∀ h : p, is_closed (s h)) : is_closed (Union s) := by by_cases p; simp * lemma is_closed_imp {p q : α → Prop} (hp : is_open {x | p x}) (hq : is_closed {x | q x}) : is_closed {x | p x → q x} := have {x | p x → q x} = {x | p x}ᶜ ∪ {x | q x}, from set.ext $ λ x, imp_iff_not_or, by rw [this]; exact is_closed.union (is_closed_compl_iff.mpr hp) hq lemma is_closed.not : is_closed {a | p a} → is_open {a | ¬ p a} := is_open_compl_iff.mpr /-! ### Interior of a set -/ /-- The interior of a set `s` is the largest open subset of `s`. -/ def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s} lemma mem_interior {s : set α} {x : α} : x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t := by simp only [interior, mem_set_of_eq, exists_prop, and_assoc, and.left_comm] @[simp] lemma is_open_interior {s : set α} : is_open (interior s) := is_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁ lemma interior_subset {s : set α} : interior s ⊆ s := sUnion_subset $ assume t ⟨h₁, h₂⟩, h₂ lemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ lemma is_open.interior_eq {s : set α} (h : is_open s) : interior s = s := subset.antisymm interior_subset (interior_maximal (subset.refl s) h) lemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s := ⟨assume h, h ▸ is_open_interior, is_open.interior_eq⟩ lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s := by simp only [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset, true_and] lemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) : s ⊆ interior t ↔ s ⊆ t := ⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩ lemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (subset.trans interior_subset h) is_open_interior @[simp] lemma interior_empty : interior (∅ : set α) = ∅ := is_open_empty.interior_eq @[simp] lemma interior_univ : interior (univ : set α) = univ := is_open_univ.interior_eq @[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s := is_open_interior.interior_eq @[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t := subset.antisymm (subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t)) (interior_maximal (inter_subset_inter interior_subset interior_subset) $ is_open.inter is_open_interior is_open_interior) lemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have interior (s ∪ t) ⊆ s, from assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩, classical.by_contradiction $ assume hx₂ : x ∉ s, have u \ s ⊆ t, from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂, have u \ s ⊆ interior t, by rwa subset_interior_iff_subset_of_open (is_open.sdiff hu₁ h₁), have u \ s ⊆ ∅, by rwa h₂ at this, this ⟨hx₁, hx₂⟩, subset.antisymm (interior_maximal this is_open_interior) (interior_mono $ subset_union_left _ _) lemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t := by rw ← subset_interior_iff_open; simp only [subset_def, mem_interior] /-! ### Closure of a set -/ /-- The closure of `s` is the smallest closed set containing `s`. -/ def closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t} @[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) := is_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁ lemma subset_closure {s : set α} : s ⊆ closure s := subset_sInter $ assume t ⟨h₁, h₂⟩, h₂ lemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ lemma is_closed.closure_eq {s : set α} (h : is_closed s) : closure s = s := subset.antisymm (closure_minimal (subset.refl s) h) subset_closure lemma is_closed.closure_subset {s : set α} (hs : is_closed s) : closure s ⊆ s := closure_minimal (subset.refl _) hs lemma is_closed.closure_subset_iff {s t : set α} (h₁ : is_closed t) : closure s ⊆ t ↔ s ⊆ t := ⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩ @[mono] lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (subset.trans h subset_closure) is_closed_closure lemma monotone_closure (α : Type*) [topological_space α] : monotone (@closure α _) := λ _ _, closure_mono lemma diff_subset_closure_iff {s t : set α} : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] lemma closure_inter_subset_inter_closure (s t : set α) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure α).map_inf_le s t lemma is_closed_of_closure_subset {s : set α} (h : closure s ⊆ s) : is_closed s := by rw subset.antisymm subset_closure h; exact is_closed_closure lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s := ⟨assume h, h ▸ is_closed_closure, is_closed.closure_eq⟩ lemma closure_subset_iff_is_closed {s : set α} : closure s ⊆ s ↔ is_closed s := ⟨is_closed_of_closure_subset, is_closed.closure_subset⟩ @[simp] lemma closure_empty : closure (∅ : set α) = ∅ := is_closed_empty.closure_eq @[simp] lemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, λ h, h.symm ▸ closure_empty⟩ @[simp] lemma closure_nonempty_iff {s : set α} : (closure s).nonempty ↔ s.nonempty := by simp only [← ne_empty_iff_nonempty, ne.def, closure_empty_iff] alias closure_nonempty_iff ↔ set.nonempty.of_closure set.nonempty.closure @[simp] lemma closure_univ : closure (univ : set α) = univ := is_closed_univ.closure_eq @[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s := is_closed_closure.closure_eq @[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t := subset.antisymm (closure_minimal (union_subset_union subset_closure subset_closure) $ is_closed.union is_closed_closure is_closed_closure) ((monotone_closure α).le_map_sup s t) lemma interior_subset_closure {s : set α} : interior s ⊆ closure s := subset.trans interior_subset subset_closure lemma closure_eq_compl_interior_compl {s : set α} : closure s = (interior sᶜ)ᶜ := begin rw [interior, closure, compl_sUnion, compl_image_set_of], simp only [compl_subset_compl, is_open_compl_iff], end @[simp] lemma interior_compl {s : set α} : interior sᶜ = (closure s)ᶜ := by simp [closure_eq_compl_interior_compl] @[simp] lemma closure_compl {s : set α} : closure sᶜ = (interior s)ᶜ := by simp [closure_eq_compl_interior_compl] theorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → (o ∩ s).nonempty := ⟨λ h o oo ao, classical.by_contradiction $ λ os, have s ⊆ oᶜ, from λ x xs xo, os ⟨x, xo, xs⟩, closure_minimal this (is_closed_compl_iff.2 oo) h ao, λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc, let ⟨x, hc, hs⟩ := (H _ h₁.is_open_compl nc) in hc (h₂ hs)⟩ /-- A set is dense in a topological space if every point belongs to its closure. -/ def dense (s : set α) : Prop := ∀ x, x ∈ closure s lemma dense_iff_closure_eq {s : set α} : dense s ↔ closure s = univ := eq_univ_iff_forall.symm lemma dense.closure_eq {s : set α} (h : dense s) : closure s = univ := dense_iff_closure_eq.mp h /-- The closure of a set `s` is dense if and only if `s` is dense. -/ @[simp] lemma dense_closure {s : set α} : dense (closure s) ↔ dense s := by rw [dense, dense, closure_closure] alias dense_closure ↔ dense.of_closure dense.closure @[simp] lemma dense_univ : dense (univ : set α) := λ x, subset_closure trivial /-- A set is dense if and only if it has a nonempty intersection with each nonempty open set. -/ lemma dense_iff_inter_open {s : set α} : dense s ↔ ∀ U, is_open U → U.nonempty → (U ∩ s).nonempty := begin split ; intro h, { rintros U U_op ⟨x, x_in⟩, exact mem_closure_iff.1 (by simp only [h.closure_eq]) U U_op x_in }, { intro x, rw mem_closure_iff, intros U U_op x_in, exact h U U_op ⟨_, x_in⟩ }, end alias dense_iff_inter_open ↔ dense.inter_open_nonempty _ lemma dense.nonempty_iff {s : set α} (hs : dense s) : s.nonempty ↔ nonempty α := ⟨λ ⟨x, hx⟩, ⟨x⟩, λ ⟨x⟩, let ⟨y, hy⟩ := hs.inter_open_nonempty _ is_open_univ ⟨x, trivial⟩ in ⟨y, hy.2⟩⟩ lemma dense.nonempty [h : nonempty α] {s : set α} (hs : dense s) : s.nonempty := hs.nonempty_iff.2 h @[mono] lemma dense.mono {s₁ s₂ : set α} (h : s₁ ⊆ s₂) (hd : dense s₁) : dense s₂ := λ x, closure_mono h (hd x) /-! ### Frontier of a set -/ /-- The frontier of a set is the set of points between the closure and interior. -/ def frontier (s : set α) : set α := closure s \ interior s lemma frontier_eq_closure_inter_closure {s : set α} : frontier s = closure s ∩ closure sᶜ := by rw [closure_compl, frontier, diff_eq] lemma frontier_subset_closure {s : set α} : frontier s ⊆ closure s := diff_subset _ _ /-- The complement of a set has the same frontier as the original set. -/ @[simp] lemma frontier_compl (s : set α) : frontier sᶜ = frontier s := by simp only [frontier_eq_closure_inter_closure, compl_compl, inter_comm] @[simp] lemma frontier_univ : frontier (univ : set α) = ∅ := by simp [frontier] @[simp] lemma frontier_empty : frontier (∅ : set α) = ∅ := by simp [frontier] lemma frontier_inter_subset (s t : set α) : frontier (s ∩ t) ⊆ (frontier s ∩ closure t) ∪ (closure s ∩ frontier t) := begin simp only [frontier_eq_closure_inter_closure, compl_inter, closure_union], convert inter_subset_inter_left _ (closure_inter_subset_inter_closure s t), simp only [inter_distrib_left, inter_distrib_right, inter_assoc], congr' 2, apply inter_comm end lemma frontier_union_subset (s t : set α) : frontier (s ∪ t) ⊆ (frontier s ∩ closure tᶜ) ∪ (closure sᶜ ∩ frontier t) := by simpa only [frontier_compl, ← compl_union] using frontier_inter_subset sᶜ tᶜ lemma is_closed.frontier_eq {s : set α} (hs : is_closed s) : frontier s = s \ interior s := by rw [frontier, hs.closure_eq] lemma is_open.frontier_eq {s : set α} (hs : is_open s) : frontier s = closure s \ s := by rw [frontier, hs.interior_eq] lemma is_open.inter_frontier_eq {s : set α} (hs : is_open s) : s ∩ frontier s = ∅ := by rw [hs.frontier_eq, inter_diff_self] /-- The frontier of a set is closed. -/ lemma is_closed_frontier {s : set α} : is_closed (frontier s) := by rw frontier_eq_closure_inter_closure; exact is_closed.inter is_closed_closure is_closed_closure /-- The frontier of a closed set has no interior point. -/ lemma interior_frontier {s : set α} (h : is_closed s) : interior (frontier s) = ∅ := begin have A : frontier s = s \ interior s, from h.frontier_eq, have B : interior (frontier s) ⊆ interior s, by rw A; exact interior_mono (diff_subset _ _), have C : interior (frontier s) ⊆ frontier s := interior_subset, have : interior (frontier s) ⊆ (interior s) ∩ (s \ interior s) := subset_inter B (by simpa [A] using C), rwa [inter_diff_self, subset_empty_iff] at this, end lemma closure_eq_interior_union_frontier (s : set α) : closure s = interior s ∪ frontier s := (union_diff_cancel interior_subset_closure).symm lemma closure_eq_self_union_frontier (s : set α) : closure s = s ∪ frontier s := (union_diff_cancel' interior_subset subset_closure).symm lemma is_open.inter_frontier_eq_empty_of_disjoint {s t : set α} (ht : is_open t) (hd : disjoint s t) : t ∩ frontier s = ∅ := begin rw [inter_comm, ← subset_compl_iff_disjoint], exact subset.trans frontier_subset_closure (closure_minimal (λ _, disjoint_left.1 hd) (is_closed_compl_iff.2 ht)) end lemma frontier_eq_inter_compl_interior {s : set α} : frontier s = (interior s)ᶜ ∩ (interior (sᶜ))ᶜ := by { rw [←frontier_compl, ←closure_compl], refl } lemma compl_frontier_eq_union_interior {s : set α} : (frontier s)ᶜ = interior s ∪ interior sᶜ := begin rw frontier_eq_inter_compl_interior, simp only [compl_inter, compl_compl], end /-! ### Neighborhoods -/ /-- A set is called a neighborhood of `a` if it contains an open set around `a`. The set of all neighborhoods of `a` forms a filter, the neighborhood filter at `a`, is here defined as the infimum over the principal filters of all open sets containing `a`. -/ @[irreducible] def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 s) localized "notation `𝓝` := nhds" in topological_space /-- The "neighborhood within" filter. Elements of `𝓝[s] a` are sets containing the intersection of `s` and a neighborhood of `a`. -/ def nhds_within (a : α) (s : set α) : filter α := 𝓝 a ⊓ 𝓟 s localized "notation `𝓝[` s `] ` x:100 := nhds_within x s" in topological_space lemma nhds_def (a : α) : 𝓝 a = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 s) := by rw nhds /-- The open sets containing `a` are a basis for the neighborhood filter. See `nhds_basis_opens'` for a variant using open neighborhoods instead. -/ lemma nhds_basis_opens (a : α) : (𝓝 a).has_basis (λ s : set α, a ∈ s ∧ is_open s) (λ x, x) := begin rw nhds_def, exact has_basis_binfi_principal (λ s ⟨has, hs⟩ t ⟨hat, ht⟩, ⟨s ∩ t, ⟨⟨has, hat⟩, is_open.inter hs ht⟩, ⟨inter_subset_left _ _, inter_subset_right _ _⟩⟩) ⟨univ, ⟨mem_univ a, is_open_univ⟩⟩ end /-- A filter lies below the neighborhood filter at `a` iff it contains every open set around `a`. -/ lemma le_nhds_iff {f a} : f ≤ 𝓝 a ↔ ∀ s : set α, a ∈ s → is_open s → s ∈ f := by simp [nhds_def] /-- To show a filter is above the neighborhood filter at `a`, it suffices to show that it is above the principal filter of some open set `s` containing `a`. -/ lemma nhds_le_of_le {f a} {s : set α} (h : a ∈ s) (o : is_open s) (sf : 𝓟 s ≤ f) : 𝓝 a ≤ f := by rw nhds_def; exact infi_le_of_le s (infi_le_of_le ⟨h, o⟩ sf) lemma mem_nhds_iff {a : α} {s : set α} : s ∈ 𝓝 a ↔ ∃t⊆s, is_open t ∧ a ∈ t := (nhds_basis_opens a).mem_iff.trans ⟨λ ⟨t, ⟨hat, ht⟩, hts⟩, ⟨t, hts, ht, hat⟩, λ ⟨t, hts, ht, hat⟩, ⟨t, ⟨hat, ht⟩, hts⟩⟩ /-- A predicate is true in a neighborhood of `a` iff it is true for all the points in an open set containing `a`. -/ lemma eventually_nhds_iff {a : α} {p : α → Prop} : (∀ᶠ x in 𝓝 a, p x) ↔ ∃ (t : set α), (∀ x ∈ t, p x) ∧ is_open t ∧ a ∈ t := mem_nhds_iff.trans $ by simp only [subset_def, exists_prop, mem_set_of_eq] lemma map_nhds {a : α} {f : α → β} : map f (𝓝 a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, 𝓟 (image f s)) := ((nhds_basis_opens a).map f).eq_binfi lemma mem_of_mem_nhds {a : α} {s : set α} : s ∈ 𝓝 a → a ∈ s := λ H, let ⟨t, ht, _, hs⟩ := mem_nhds_iff.1 H in ht hs /-- If a predicate is true in a neighborhood of `a`, then it is true for `a`. -/ lemma filter.eventually.self_of_nhds {p : α → Prop} {a : α} (h : ∀ᶠ y in 𝓝 a, p y) : p a := mem_of_mem_nhds h lemma is_open.mem_nhds {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) : s ∈ 𝓝 a := mem_nhds_iff.2 ⟨s, subset.refl _, hs, ha⟩ lemma is_open.eventually_mem {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) : ∀ᶠ x in 𝓝 a, x ∈ s := is_open.mem_nhds hs ha /-- The open neighborhoods of `a` are a basis for the neighborhood filter. See `nhds_basis_opens` for a variant using open sets around `a` instead. -/ lemma nhds_basis_opens' (a : α) : (𝓝 a).has_basis (λ s : set α, s ∈ 𝓝 a ∧ is_open s) (λ x, x) := begin convert nhds_basis_opens a, ext s, split, { rintros ⟨s_in, s_op⟩, exact ⟨mem_of_mem_nhds s_in, s_op⟩ }, { rintros ⟨a_in, s_op⟩, exact ⟨is_open.mem_nhds s_op a_in, s_op⟩ }, end /-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of `s`: it contains an open set containing `s`. -/ lemma exists_open_set_nhds {s U : set α} (h : ∀ x ∈ s, U ∈ 𝓝 x) : ∃ V : set α, s ⊆ V ∧ is_open V ∧ V ⊆ U := begin have := λ x hx, (nhds_basis_opens x).mem_iff.1 (h x hx), choose! Z hZ hZ' using this, refine ⟨⋃ x ∈ s, Z x, _, _, bUnion_subset hZ'⟩, { intros x hx, simp only [mem_Union], exact ⟨x, hx, (hZ x hx).1⟩ }, { apply is_open_Union, intros x, by_cases hx : x ∈ s ; simp [hx], exact (hZ x hx).2 } end /-- If `U` is a neighborhood of each point of a set `s` then it is a neighborhood of s: it contains an open set containing `s`. -/ lemma exists_open_set_nhds' {s U : set α} (h : U ∈ ⨆ x ∈ s, 𝓝 x) : ∃ V : set α, s ⊆ V ∧ is_open V ∧ V ⊆ U := exists_open_set_nhds (by simpa using h) /-- If a predicate is true in a neighbourhood of `a`, then for `y` sufficiently close to `a` this predicate is true in a neighbourhood of `y`. -/ lemma filter.eventually.eventually_nhds {p : α → Prop} {a : α} (h : ∀ᶠ y in 𝓝 a, p y) : ∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝 y, p x := let ⟨t, htp, hto, ha⟩ := eventually_nhds_iff.1 h in eventually_nhds_iff.2 ⟨t, λ x hx, eventually_nhds_iff.2 ⟨t, htp, hto, hx⟩, hto, ha⟩ @[simp] lemma eventually_eventually_nhds {p : α → Prop} {a : α} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝 y, p x) ↔ ∀ᶠ x in 𝓝 a, p x := ⟨λ h, h.self_of_nhds, λ h, h.eventually_nhds⟩ @[simp] lemma nhds_bind_nhds : (𝓝 a).bind 𝓝 = 𝓝 a := filter.ext $ λ s, eventually_eventually_nhds @[simp] lemma eventually_eventually_eq_nhds {f g : α → β} {a : α} : (∀ᶠ y in 𝓝 a, f =ᶠ[𝓝 y] g) ↔ f =ᶠ[𝓝 a] g := eventually_eventually_nhds lemma filter.eventually_eq.eq_of_nhds {f g : α → β} {a : α} (h : f =ᶠ[𝓝 a] g) : f a = g a := h.self_of_nhds @[simp] lemma eventually_eventually_le_nhds [has_le β] {f g : α → β} {a : α} : (∀ᶠ y in 𝓝 a, f ≤ᶠ[𝓝 y] g) ↔ f ≤ᶠ[𝓝 a] g := eventually_eventually_nhds /-- If two functions are equal in a neighbourhood of `a`, then for `y` sufficiently close to `a` these functions are equal in a neighbourhood of `y`. -/ lemma filter.eventually_eq.eventually_eq_nhds {f g : α → β} {a : α} (h : f =ᶠ[𝓝 a] g) : ∀ᶠ y in 𝓝 a, f =ᶠ[𝓝 y] g := h.eventually_nhds /-- If `f x ≤ g x` in a neighbourhood of `a`, then for `y` sufficiently close to `a` we have `f x ≤ g x` in a neighbourhood of `y`. -/ lemma filter.eventually_le.eventually_le_nhds [has_le β] {f g : α → β} {a : α} (h : f ≤ᶠ[𝓝 a] g) : ∀ᶠ y in 𝓝 a, f ≤ᶠ[𝓝 y] g := h.eventually_nhds theorem all_mem_nhds (x : α) (P : set α → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) : (∀ s ∈ 𝓝 x, P s) ↔ (∀ s, is_open s → x ∈ s → P s) := ((nhds_basis_opens x).forall_iff hP).trans $ by simp only [and_comm (x ∈ _), and_imp] theorem all_mem_nhds_filter (x : α) (f : set α → set β) (hf : ∀ s t, s ⊆ t → f s ⊆ f t) (l : filter β) : (∀ s ∈ 𝓝 x, f s ∈ l) ↔ (∀ s, is_open s → x ∈ s → f s ∈ l) := all_mem_nhds _ _ (λ s t ssubt h, mem_sets_of_superset h (hf s t ssubt)) theorem rtendsto_nhds {r : rel β α} {l : filter β} {a : α} : rtendsto r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.core s ∈ l) := all_mem_nhds_filter _ _ (λ s t, id) _ theorem rtendsto'_nhds {r : rel β α} {l : filter β} {a : α} : rtendsto' r l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → r.preimage s ∈ l) := by { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono } theorem ptendsto_nhds {f : β →. α} {l : filter β} {a : α} : ptendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.core s ∈ l) := rtendsto_nhds theorem ptendsto'_nhds {f : β →. α} {l : filter β} {a : α} : ptendsto' f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f.preimage s ∈ l) := rtendsto'_nhds theorem tendsto_nhds {f : β → α} {l : filter β} {a : α} : tendsto f l (𝓝 a) ↔ (∀ s, is_open s → a ∈ s → f ⁻¹' s ∈ l) := all_mem_nhds_filter _ _ (λ s t h, preimage_mono h) _ lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (𝓝 a) := tendsto_nhds.mpr $ assume s hs ha, univ_mem_sets' $ assume _, ha lemma tendsto_at_top_of_eventually_const {ι : Type*} [semilattice_sup ι] [nonempty ι] {x : α} {u : ι → α} {i₀ : ι} (h : ∀ i ≥ i₀, u i = x) : tendsto u at_top (𝓝 x) := tendsto.congr' (eventually_eq.symm (eventually_at_top.mpr ⟨i₀, h⟩)) tendsto_const_nhds lemma tendsto_at_bot_of_eventually_const {ι : Type*} [semilattice_inf ι] [nonempty ι] {x : α} {u : ι → α} {i₀ : ι} (h : ∀ i ≤ i₀, u i = x) : tendsto u at_bot (𝓝 x) := tendsto.congr' (eventually_eq.symm (eventually_at_bot.mpr ⟨i₀, h⟩)) tendsto_const_nhds lemma pure_le_nhds : pure ≤ (𝓝 : α → filter α) := assume a s hs, mem_pure_sets.2 $ mem_of_mem_nhds hs lemma tendsto_pure_nhds {α : Type*} [topological_space β] (f : α → β) (a : α) : tendsto f (pure a) (𝓝 (f a)) := (tendsto_pure_pure f a).mono_right (pure_le_nhds _) lemma order_top.tendsto_at_top_nhds {α : Type*} [order_top α] [topological_space β] (f : α → β) : tendsto f at_top (𝓝 $ f ⊤) := (tendsto_at_top_pure f).mono_right (pure_le_nhds _) @[simp] instance nhds_ne_bot {a : α} : ne_bot (𝓝 a) := ne_bot_of_le (pure_le_nhds a) /-! ### Cluster points In this section we define [cluster points](https://en.wikipedia.org/wiki/Limit_point) (also known as limit points and accumulation points) of a filter and of a sequence. -/ /-- A point `x` is a cluster point of a filter `F` if 𝓝 x ⊓ F ≠ ⊥. Also known as an accumulation point or a limit point. -/ def cluster_pt (x : α) (F : filter α) : Prop := ne_bot (𝓝 x ⊓ F) lemma cluster_pt.ne_bot {x : α} {F : filter α} (h : cluster_pt x F) : ne_bot (𝓝 x ⊓ F) := h lemma filter.has_basis.cluster_pt_iff {ιa ιF} {pa : ιa → Prop} {sa : ιa → set α} {pF : ιF → Prop} {sF : ιF → set α} {F : filter α} (ha : (𝓝 a).has_basis pa sa) (hF : F.has_basis pF sF) : cluster_pt a F ↔ ∀ ⦃i⦄ (hi : pa i) ⦃j⦄ (hj : pF j), (sa i ∩ sF j).nonempty := ha.inf_basis_ne_bot_iff hF lemma cluster_pt_iff {x : α} {F : filter α} : cluster_pt x F ↔ ∀ ⦃U : set α⦄ (hU : U ∈ 𝓝 x) ⦃V⦄ (hV : V ∈ F), (U ∩ V).nonempty := inf_ne_bot_iff /-- `x` is a cluster point of a set `s` if every neighbourhood of `x` meets `s` on a nonempty set. -/ lemma cluster_pt_principal_iff {x : α} {s : set α} : cluster_pt x (𝓟 s) ↔ ∀ U ∈ 𝓝 x, (U ∩ s).nonempty := inf_principal_ne_bot_iff lemma cluster_pt_principal_iff_frequently {x : α} {s : set α} : cluster_pt x (𝓟 s) ↔ ∃ᶠ y in 𝓝 x, y ∈ s := by simp only [cluster_pt_principal_iff, frequently_iff, set.nonempty, exists_prop, mem_inter_iff] lemma cluster_pt.of_le_nhds {x : α} {f : filter α} (H : f ≤ 𝓝 x) [ne_bot f] : cluster_pt x f := by rwa [cluster_pt, inf_eq_right.mpr H] lemma cluster_pt.of_le_nhds' {x : α} {f : filter α} (H : f ≤ 𝓝 x) (hf : ne_bot f) : cluster_pt x f := cluster_pt.of_le_nhds H lemma cluster_pt.of_nhds_le {x : α} {f : filter α} (H : 𝓝 x ≤ f) : cluster_pt x f := by simp only [cluster_pt, inf_eq_left.mpr H, nhds_ne_bot] lemma cluster_pt.mono {x : α} {f g : filter α} (H : cluster_pt x f) (h : f ≤ g) : cluster_pt x g := ⟨ne_bot_of_le_ne_bot H.ne $ inf_le_inf_left _ h⟩ lemma cluster_pt.of_inf_left {x : α} {f g : filter α} (H : cluster_pt x $ f ⊓ g) : cluster_pt x f := H.mono inf_le_left lemma cluster_pt.of_inf_right {x : α} {f g : filter α} (H : cluster_pt x $ f ⊓ g) : cluster_pt x g := H.mono inf_le_right lemma ultrafilter.cluster_pt_iff {x : α} {f : ultrafilter α} : cluster_pt x f ↔ ↑f ≤ 𝓝 x := ⟨f.le_of_inf_ne_bot', λ h, cluster_pt.of_le_nhds h⟩ /-- A point `x` is a cluster point of a sequence `u` along a filter `F` if it is a cluster point of `map u F`. -/ def map_cluster_pt {ι :Type*} (x : α) (F : filter ι) (u : ι → α) : Prop := cluster_pt x (map u F) lemma map_cluster_pt_iff {ι :Type*} (x : α) (F : filter ι) (u : ι → α) : map_cluster_pt x F u ↔ ∀ s ∈ 𝓝 x, ∃ᶠ a in F, u a ∈ s := by { simp_rw [map_cluster_pt, cluster_pt, inf_ne_bot_iff_frequently_left, frequently_map], refl } lemma map_cluster_pt_of_comp {ι δ :Type*} {F : filter ι} {φ : δ → ι} {p : filter δ} {x : α} {u : ι → α} [ne_bot p] (h : tendsto φ p F) (H : tendsto (u ∘ φ) p (𝓝 x)) : map_cluster_pt x F u := begin have := calc map (u ∘ φ) p = map u (map φ p) : map_map ... ≤ map u F : map_mono h, have : map (u ∘ φ) p ≤ 𝓝 x ⊓ map u F, from le_inf H this, exact ne_bot_of_le this end /-! ### Interior, closure and frontier in terms of neighborhoods -/ lemma interior_eq_nhds' {s : set α} : interior s = {a | s ∈ 𝓝 a} := set.ext $ λ x, by simp only [mem_interior, mem_nhds_iff, mem_set_of_eq] lemma interior_eq_nhds {s : set α} : interior s = {a | 𝓝 a ≤ 𝓟 s} := interior_eq_nhds'.trans $ by simp only [le_principal_iff] lemma mem_interior_iff_mem_nhds {s : set α} {a : α} : a ∈ interior s ↔ s ∈ 𝓝 a := by rw [interior_eq_nhds', mem_set_of_eq] @[simp] lemma interior_mem_nhds {s : set α} {a : α} : interior s ∈ 𝓝 a ↔ s ∈ 𝓝 a := ⟨λ h, mem_sets_of_superset h interior_subset, λ h, is_open.mem_nhds is_open_interior (mem_interior_iff_mem_nhds.2 h)⟩ lemma interior_set_of_eq {p : α → Prop} : interior {x | p x} = {x | ∀ᶠ y in 𝓝 x, p y} := interior_eq_nhds' lemma is_open_set_of_eventually_nhds {p : α → Prop} : is_open {x | ∀ᶠ y in 𝓝 x, p y} := by simp only [← interior_set_of_eq, is_open_interior] lemma subset_interior_iff_nhds {s V : set α} : s ⊆ interior V ↔ ∀ x ∈ s, V ∈ 𝓝 x := show (∀ x, x ∈ s → x ∈ _) ↔ _, by simp_rw mem_interior_iff_mem_nhds lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, 𝓝 a ≤ 𝓟 s := calc is_open s ↔ s ⊆ interior s : subset_interior_iff_open.symm ... ↔ (∀a∈s, 𝓝 a ≤ 𝓟 s) : by rw [interior_eq_nhds]; refl lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ 𝓝 a := is_open_iff_nhds.trans $ forall_congr $ λ _, imp_congr_right $ λ _, le_principal_iff theorem is_open_iff_ultrafilter {s : set α} : is_open s ↔ (∀ (x ∈ s) (l : ultrafilter α), ↑l ≤ 𝓝 x → s ∈ l) := by simp_rw [is_open_iff_mem_nhds, ← mem_iff_ultrafilter] lemma mem_closure_iff_frequently {s : set α} {a : α} : a ∈ closure s ↔ ∃ᶠ x in 𝓝 a, x ∈ s := by rw [filter.frequently, filter.eventually, ← mem_interior_iff_mem_nhds, closure_eq_compl_interior_compl]; refl alias mem_closure_iff_frequently ↔ _ filter.frequently.mem_closure /-- The set of cluster points of a filter is closed. In particular, the set of limit points of a sequence is closed. -/ lemma is_closed_set_of_cluster_pt {f : filter α} : is_closed {x | cluster_pt x f} := begin simp only [cluster_pt, inf_ne_bot_iff_frequently_left, set_of_forall, imp_iff_not_or], refine is_closed_Inter (λ p, is_closed.union _ _); apply is_closed_compl_iff.2, exacts [is_open_set_of_eventually_nhds, is_open_const] end theorem mem_closure_iff_cluster_pt {s : set α} {a : α} : a ∈ closure s ↔ cluster_pt a (𝓟 s) := mem_closure_iff_frequently.trans cluster_pt_principal_iff_frequently.symm lemma mem_closure_iff_nhds_ne_bot {s : set α} : a ∈ closure s ↔ 𝓝 a ⊓ 𝓟 s ≠ ⊥ := mem_closure_iff_cluster_pt.trans ne_bot_iff lemma closure_eq_cluster_pts {s : set α} : closure s = {a | cluster_pt a (𝓟 s)} := set.ext $ λ x, mem_closure_iff_cluster_pt theorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ 𝓝 a, (t ∩ s).nonempty := mem_closure_iff_cluster_pt.trans cluster_pt_principal_iff theorem mem_closure_iff_nhds' {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ 𝓝 a, ∃ y : s, ↑y ∈ t := by simp only [mem_closure_iff_nhds, set.nonempty_inter_iff_exists_right] theorem mem_closure_iff_comap_ne_bot {A : set α} {x : α} : x ∈ closure A ↔ ne_bot (comap (coe : A → α) (𝓝 x)) := by simp_rw [mem_closure_iff_nhds, comap_ne_bot_iff, set.nonempty_inter_iff_exists_right] theorem mem_closure_iff_nhds_basis' {a : α} {p : β → Prop} {s : β → set α} (h : (𝓝 a).has_basis p s) {t : set α} : a ∈ closure t ↔ ∀ i, p i → (s i ∩ t).nonempty := mem_closure_iff_cluster_pt.trans $ (h.cluster_pt_iff (has_basis_principal _)).trans $ by simp only [exists_prop, forall_const] theorem mem_closure_iff_nhds_basis {a : α} {p : β → Prop} {s : β → set α} (h : (𝓝 a).has_basis p s) {t : set α} : a ∈ closure t ↔ ∀ i, p i → ∃ y ∈ t, y ∈ s i := (mem_closure_iff_nhds_basis' h).trans $ by simp only [set.nonempty, mem_inter_eq, exists_prop, and_comm] /-- `x` belongs to the closure of `s` if and only if some ultrafilter supported on `s` converges to `x`. -/ lemma mem_closure_iff_ultrafilter {s : set α} {x : α} : x ∈ closure s ↔ ∃ (u : ultrafilter α), s ∈ u ∧ ↑u ≤ 𝓝 x := by simp [closure_eq_cluster_pts, cluster_pt, ← exists_ultrafilter_iff, and.comm] lemma is_closed_iff_cluster_pt {s : set α} : is_closed s ↔ ∀a, cluster_pt a (𝓟 s) → a ∈ s := calc is_closed s ↔ closure s ⊆ s : closure_subset_iff_is_closed.symm ... ↔ (∀a, cluster_pt a (𝓟 s) → a ∈ s) : by simp only [subset_def, mem_closure_iff_cluster_pt] lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀ x, (∀ U ∈ 𝓝 x, (U ∩ s).nonempty) → x ∈ s := by simp_rw [is_closed_iff_cluster_pt, cluster_pt, inf_principal_ne_bot_iff] lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) := begin rintro a ⟨hs, ht⟩, have : s ∈ 𝓝 a := is_open.mem_nhds h hs, rw mem_closure_iff_nhds_ne_bot at ht ⊢, rwa [← inf_principal, ← inf_assoc, inf_eq_left.2 (le_principal_iff.2 this)], end lemma closure_inter_open' {s t : set α} (h : is_open t) : closure s ∩ t ⊆ closure (s ∩ t) := by simpa only [inter_comm] using closure_inter_open h lemma mem_closure_of_mem_closure_union {s₁ s₂ : set α} {x : α} (h : x ∈ closure (s₁ ∪ s₂)) (h₁ : s₁ᶜ ∈ 𝓝 x) : x ∈ closure s₂ := begin rw mem_closure_iff_nhds_ne_bot at *, rwa ← calc 𝓝 x ⊓ principal (s₁ ∪ s₂) = 𝓝 x ⊓ (principal s₁ ⊔ principal s₂) : by rw sup_principal ... = (𝓝 x ⊓ principal s₁) ⊔ (𝓝 x ⊓ principal s₂) : inf_sup_left ... = ⊥ ⊔ 𝓝 x ⊓ principal s₂ : by rw inf_principal_eq_bot.mpr h₁ ... = 𝓝 x ⊓ principal s₂ : bot_sup_eq end /-- The intersection of an open dense set with a dense set is a dense set. -/ lemma dense.inter_of_open_left {s t : set α} (hs : dense s) (ht : dense t) (hso : is_open s) : dense (s ∩ t) := λ x, (closure_minimal (closure_inter_open hso) is_closed_closure) $ by simp [hs.closure_eq, ht.closure_eq] /-- The intersection of a dense set with an open dense set is a dense set. -/ lemma dense.inter_of_open_right {s t : set α} (hs : dense s) (ht : dense t) (hto : is_open t) : dense (s ∩ t) := inter_comm t s ▸ ht.inter_of_open_left hs hto lemma dense.inter_nhds_nonempty {s t : set α} (hs : dense s) {x : α} (ht : t ∈ 𝓝 x) : (s ∩ t).nonempty := let ⟨U, hsub, ho, hx⟩ := mem_nhds_iff.1 ht in (hs.inter_open_nonempty U ho ⟨x, hx⟩).mono $ λ y hy, ⟨hy.2, hsub hy.1⟩ lemma closure_diff {s t : set α} : closure s \ closure t ⊆ closure (s \ t) := calc closure s \ closure t = (closure t)ᶜ ∩ closure s : by simp only [diff_eq, inter_comm] ... ⊆ closure ((closure t)ᶜ ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure ... = closure (s \ closure t) : by simp only [diff_eq, inter_comm] ... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure lemma filter.frequently.mem_of_closed {a : α} {s : set α} (h : ∃ᶠ x in 𝓝 a, x ∈ s) (hs : is_closed s) : a ∈ s := hs.closure_subset h.mem_closure lemma is_closed.mem_of_frequently_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α} (hs : is_closed s) (h : ∃ᶠ x in b, f x ∈ s) (hf : tendsto f b (𝓝 a)) : a ∈ s := (hf.frequently $ show ∃ᶠ x in b, (λ y, y ∈ s) (f x), from h).mem_of_closed hs lemma is_closed.mem_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α} [ne_bot b] (hs : is_closed s) (hf : tendsto f b (𝓝 a)) (h : ∀ᶠ x in b, f x ∈ s) : a ∈ s := hs.mem_of_frequently_of_tendsto h.frequently hf lemma mem_closure_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α} [ne_bot b] (hf : tendsto f b (𝓝 a)) (h : ∀ᶠ x in b, f x ∈ s) : a ∈ closure s := is_closed_closure.mem_of_tendsto hf $ h.mono (preimage_mono subset_closure) /-- Suppose that `f` sends the complement to `s` to a single point `a`, and `l` is some filter. Then `f` tends to `a` along `l` restricted to `s` if and only if it tends to `a` along `l`. -/ lemma tendsto_inf_principal_nhds_iff_of_forall_eq {f : β → α} {l : filter β} {s : set β} {a : α} (h : ∀ x ∉ s, f x = a) : tendsto f (l ⊓ 𝓟 s) (𝓝 a) ↔ tendsto f l (𝓝 a) := begin rw [tendsto_iff_comap, tendsto_iff_comap], replace h : 𝓟 sᶜ ≤ comap f (𝓝 a), { rintros U ⟨t, ht, htU⟩ x hx, have : f x ∈ t, from (h x hx).symm ▸ mem_of_mem_nhds ht, exact htU this }, refine ⟨λ h', _, le_trans inf_le_left⟩, have := sup_le h' h, rw [sup_inf_right, sup_principal, union_compl_self, principal_univ, inf_top_eq, sup_le_iff] at this, exact this.1 end /-! ### Limits of filters in topological spaces -/ section lim /-- If `f` is a filter, then `Lim f` is a limit of the filter, if it exists. -/ noncomputable def Lim [nonempty α] (f : filter α) : α := epsilon $ λa, f ≤ 𝓝 a /-- If `f` is a filter satisfying `ne_bot f`, then `Lim' f` is a limit of the filter, if it exists. -/ def Lim' (f : filter α) [ne_bot f] : α := @Lim _ _ (nonempty_of_ne_bot f) f /-- If `F` is an ultrafilter, then `filter.ultrafilter.Lim F` is a limit of the filter, if it exists. Note that dot notation `F.Lim` can be used for `F : ultrafilter α`. -/ def ultrafilter.Lim : ultrafilter α → α := λ F, Lim' F /-- If `f` is a filter in `β` and `g : β → α` is a function, then `lim f` is a limit of `g` at `f`, if it exists. -/ noncomputable def lim [nonempty α] (f : filter β) (g : β → α) : α := Lim (f.map g) /-- If a filter `f` is majorated by some `𝓝 a`, then it is majorated by `𝓝 (Lim f)`. We formulate this lemma with a `[nonempty α]` argument of `Lim` derived from `h` to make it useful for types without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ lemma le_nhds_Lim {f : filter α} (h : ∃a, f ≤ 𝓝 a) : f ≤ 𝓝 (@Lim _ _ (nonempty_of_exists h) f) := epsilon_spec h /-- If `g` tends to some `𝓝 a` along `f`, then it tends to `𝓝 (lim f g)`. We formulate this lemma with a `[nonempty α]` argument of `lim` derived from `h` to make it useful for types without a `[nonempty α]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ lemma tendsto_nhds_lim {f : filter β} {g : β → α} (h : ∃ a, tendsto g f (𝓝 a)) : tendsto g f (𝓝 $ @lim _ _ _ (nonempty_of_exists h) f g) := le_nhds_Lim h end lim /-! ### Locally finite families -/ /- locally finite family [General Topology (Bourbaki, 1995)] -/ section locally_finite /-- A family of sets in `set α` is locally finite if at every point `x:α`, there is a neighborhood of `x` which meets only finitely many sets in the family -/ def locally_finite (f : β → set α) := ∀x:α, ∃t ∈ 𝓝 x, finite {i | (f i ∩ t).nonempty } lemma locally_finite.point_finite {f : β → set α} (hf : locally_finite f) (x : α) : finite {b | x ∈ f b} := let ⟨t, hxt, ht⟩ := hf x in ht.subset $ λ b hb, ⟨x, hb, mem_of_mem_nhds hxt⟩ lemma locally_finite_of_fintype [fintype β] (f : β → set α) : locally_finite f := assume x, ⟨univ, univ_mem_sets, finite.of_fintype _⟩ lemma locally_finite.subset {f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ := assume a, let ⟨t, ht₁, ht₂⟩ := hf₂ a in ⟨t, ht₁, ht₂.subset $ assume i hi, hi.mono $ inter_subset_inter (hf i) $ subset.refl _⟩ lemma locally_finite.comp_injective {ι} {f : β → set α} {g : ι → β} (hf : locally_finite f) (hg : function.injective g) : locally_finite (f ∘ g) := λ x, let ⟨t, htx, htf⟩ := hf x in ⟨t, htx, htf.preimage (hg.inj_on _)⟩ lemma locally_finite.closure {f : β → set α} (hf : locally_finite f) : locally_finite (λ i, closure (f i)) := begin intro x, rcases hf x with ⟨s, hsx, hsf⟩, refine ⟨interior s, interior_mem_nhds.2 hsx, hsf.subset $ λ i hi, _⟩, exact (hi.mono (closure_inter_open' is_open_interior)).of_closure.mono (inter_subset_inter_right _ interior_subset) end lemma locally_finite.is_closed_Union {f : β → set α} (h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) := is_open_compl_iff.1 $ is_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i), have ∀i, a ∈ (f i)ᶜ, from assume i hi, h $ mem_Union.2 ⟨i, hi⟩, have ∀i, (f i)ᶜ ∈ (𝓝 a), by simp only [mem_nhds_iff]; exact assume i, ⟨(f i)ᶜ, subset.refl _, (h₂ i).is_open_compl, this i⟩, let ⟨t, h_sets, (h_fin : finite {i | (f i ∩ t).nonempty })⟩ := h₁ a in calc 𝓝 a ≤ 𝓟 (t ∩ (⋂ i∈{i | (f i ∩ t).nonempty }, (f i)ᶜ)) : by simp * ... ≤ 𝓟 (⋃i, f i)ᶜ : begin simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq, mem_Inter, mem_set_of_eq, mem_Union, and_imp, not_exists, exists_imp_distrib, ne_empty_iff_nonempty, set.nonempty], exact assume x xt ht i xfi, ht i x xfi xt xfi end lemma locally_finite.closure_Union {f : β → set α} (h : locally_finite f) : closure (⋃ i, f i) = ⋃ i, closure (f i) := subset.antisymm (closure_minimal (Union_subset_Union $ λ _, subset_closure) $ h.closure.is_closed_Union $ λ _, is_closed_closure) (Union_subset $ λ i, closure_mono $ subset_Union _ _) end locally_finite end topological_space /-! ### Continuity -/ section continuous variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variables [topological_space α] [topological_space β] [topological_space γ] open_locale topological_space /-- A function between topological spaces is continuous if the preimage of every open set is open. Registered as a structure to make sure it is not unfolded by Lean. -/ structure continuous (f : α → β) : Prop := (is_open_preimage : ∀s, is_open s → is_open (f ⁻¹' s)) lemma continuous_def {f : α → β} : continuous f ↔ (∀s, is_open s → is_open (f ⁻¹' s)) := ⟨λ hf s hs, hf.is_open_preimage s hs, λ h, ⟨h⟩⟩ lemma is_open.preimage {f : α → β} (hf : continuous f) {s : set β} (h : is_open s) : is_open (f ⁻¹' s) := hf.is_open_preimage s h /-- A function between topological spaces is continuous at a point `x₀` if `f x` tends to `f x₀` when `x` tends to `x₀`. -/ def continuous_at (f : α → β) (x : α) := tendsto f (𝓝 x) (𝓝 (f x)) lemma continuous_at.tendsto {f : α → β} {x : α} (h : continuous_at f x) : tendsto f (𝓝 x) (𝓝 (f x)) := h lemma continuous_at_congr {f g : α → β} {x : α} (h : f =ᶠ[𝓝 x] g) : continuous_at f x ↔ continuous_at g x := by simp only [continuous_at, tendsto_congr' h, h.eq_of_nhds] lemma continuous_at.congr {f g : α → β} {x : α} (hf : continuous_at f x) (h : f =ᶠ[𝓝 x] g) : continuous_at g x := (continuous_at_congr h).1 hf lemma continuous_at.preimage_mem_nhds {f : α → β} {x : α} {t : set β} (h : continuous_at f x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝 x := h ht lemma eventually_eq_zero_nhds {M₀} [has_zero M₀] {a : α} {f : α → M₀} : f =ᶠ[𝓝 a] 0 ↔ a ∉ closure (function.support f) := by rw [← mem_compl_eq, ← interior_compl, mem_interior_iff_mem_nhds, function.compl_support]; refl lemma cluster_pt.map {x : α} {la : filter α} {lb : filter β} (H : cluster_pt x la) {f : α → β} (hfc : continuous_at f x) (hf : tendsto f la lb) : cluster_pt (f x) lb := ⟨ne_bot_of_le_ne_bot ((map_ne_bot_iff f).2 H).ne $ hfc.tendsto.inf hf⟩ lemma preimage_interior_subset_interior_preimage {f : α → β} {s : set β} (hf : continuous f) : f⁻¹' (interior s) ⊆ interior (f⁻¹' s) := interior_maximal (preimage_mono interior_subset) (is_open_interior.preimage hf) lemma continuous_id : continuous (id : α → α) := continuous_def.2 $ assume s h, h lemma continuous.comp {g : β → γ} {f : α → β} (hg : continuous g) (hf : continuous f) : continuous (g ∘ f) := continuous_def.2 $ assume s h, (h.preimage hg).preimage hf lemma continuous.iterate {f : α → α} (h : continuous f) (n : ℕ) : continuous (f^[n]) := nat.rec_on n continuous_id (λ n ihn, ihn.comp h) lemma continuous_at.comp {g : β → γ} {f : α → β} {x : α} (hg : continuous_at g (f x)) (hf : continuous_at f x) : continuous_at (g ∘ f) x := hg.comp hf lemma continuous.tendsto {f : α → β} (hf : continuous f) (x) : tendsto f (𝓝 x) (𝓝 (f x)) := ((nhds_basis_opens x).tendsto_iff $ nhds_basis_opens $ f x).2 $ λ t ⟨hxt, ht⟩, ⟨f ⁻¹' t, ⟨hxt, ht.preimage hf⟩, subset.refl _⟩ /-- A version of `continuous.tendsto` that allows one to specify a simpler form of the limit. E.g., one can write `continuous_exp.tendsto' 0 1 exp_zero`. -/ lemma continuous.tendsto' {f : α → β} (hf : continuous f) (x : α) (y : β) (h : f x = y) : tendsto f (𝓝 x) (𝓝 y) := h ▸ hf.tendsto x lemma continuous.continuous_at {f : α → β} {x : α} (h : continuous f) : continuous_at f x := h.tendsto x lemma continuous_iff_continuous_at {f : α → β} : continuous f ↔ ∀ x, continuous_at f x := ⟨continuous.tendsto, assume hf : ∀x, tendsto f (𝓝 x) (𝓝 (f x)), continuous_def.2 $ assume s, assume hs : is_open s, have ∀a, f a ∈ s → s ∈ 𝓝 (f a), from λ a ha, is_open.mem_nhds hs ha, show is_open (f ⁻¹' s), from is_open_iff_nhds.2 $ λ a ha, le_principal_iff.2 $ hf _ (this a ha)⟩ lemma continuous_at_const {x : α} {b : β} : continuous_at (λ a:α, b) x := tendsto_const_nhds lemma continuous_const {b : β} : continuous (λa:α, b) := continuous_iff_continuous_at.mpr $ assume a, continuous_at_const lemma continuous_at_id {x : α} : continuous_at id x := continuous_id.continuous_at lemma continuous_at.iterate {f : α → α} {x : α} (hf : continuous_at f x) (hx : f x = x) (n : ℕ) : continuous_at (f^[n]) x := nat.rec_on n continuous_at_id $ λ n ihn, show continuous_at (f^[n] ∘ f) x, from continuous_at.comp (hx.symm ▸ ihn) hf lemma continuous_iff_is_closed {f : α → β} : continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) := ⟨assume hf s hs, by simpa using (continuous_def.1 hf sᶜ hs.is_open_compl).is_closed_compl, assume hf, continuous_def.2 $ assume s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩ lemma is_closed.preimage {f : α → β} (hf : continuous f) {s : set β} (h : is_closed s) : is_closed (f ⁻¹' s) := continuous_iff_is_closed.mp hf s h lemma mem_closure_image {f : α → β} {x : α} {s : set α} (hf : continuous_at f x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := begin rw [mem_closure_iff_nhds_ne_bot] at hx ⊢, rw ← bot_lt_iff_ne_bot, haveI : ne_bot _ := ⟨hx⟩, calc ⊥ < map f (𝓝 x ⊓ principal s) : bot_lt_iff_ne_bot.mpr ne_bot.ne' ... ≤ (map f $ 𝓝 x) ⊓ (map f $ principal s) : map_inf_le ... = (map f $ 𝓝 x) ⊓ (principal $ f '' s) : by rw map_principal ... ≤ 𝓝 (f x) ⊓ (principal $ f '' s) : inf_le_inf hf le_rfl end lemma continuous_at_iff_ultrafilter {f : α → β} {x} : continuous_at f x ↔ ∀ g : ultrafilter α, ↑g ≤ 𝓝 x → tendsto f g (𝓝 (f x)) := tendsto_iff_ultrafilter f (𝓝 x) (𝓝 (f x)) lemma continuous_iff_ultrafilter {f : α → β} : continuous f ↔ ∀ x (g : ultrafilter α), ↑g ≤ 𝓝 x → tendsto f g (𝓝 (f x)) := by simp only [continuous_iff_continuous_at, continuous_at_iff_ultrafilter] lemma continuous.closure_preimage_subset {f : α → β} (hf : continuous f) (t : set β) : closure (f ⁻¹' t) ⊆ f ⁻¹' (closure t) := begin rw ← (is_closed_closure.preimage hf).closure_eq, exact closure_mono (preimage_mono subset_closure), end lemma continuous.frontier_preimage_subset {f : α → β} (hf : continuous f) (t : set β) : frontier (f ⁻¹' t) ⊆ f ⁻¹' (frontier t) := diff_subset_diff (hf.closure_preimage_subset t) (preimage_interior_subset_interior_preimage hf) /-! ### Continuity and partial functions -/ /-- Continuity of a partial function -/ def pcontinuous (f : α →. β) := ∀ s, is_open s → is_open (f.preimage s) lemma open_dom_of_pcontinuous {f : α →. β} (h : pcontinuous f) : is_open f.dom := by rw [←pfun.preimage_univ]; exact h _ is_open_univ lemma pcontinuous_iff' {f : α →. β} : pcontinuous f ↔ ∀ {x y} (h : y ∈ f x), ptendsto' f (𝓝 x) (𝓝 y) := begin split, { intros h x y h', simp only [ptendsto'_def, mem_nhds_iff], rintros s ⟨t, tsubs, opent, yt⟩, exact ⟨f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩ }, intros hf s os, rw is_open_iff_nhds, rintros x ⟨y, ys, fxy⟩ t, rw [mem_principal_sets], assume h : f.preimage s ⊆ t, change t ∈ 𝓝 x, apply mem_sets_of_superset _ h, have h' : ∀ s ∈ 𝓝 y, f.preimage s ∈ 𝓝 x, { intros s hs, have : ptendsto' f (𝓝 x) (𝓝 y) := hf fxy, rw ptendsto'_def at this, exact this s hs }, show f.preimage s ∈ 𝓝 x, apply h', rw mem_nhds_iff, exact ⟨s, set.subset.refl _, os, ys⟩ end /-- If a continuous map `f` maps `s` to `t`, then it maps `closure s` to `closure t`. -/ lemma set.maps_to.closure {s : set α} {t : set β} {f : α → β} (h : maps_to f s t) (hc : continuous f) : maps_to f (closure s) (closure t) := begin simp only [maps_to, mem_closure_iff_cluster_pt], exact λ x hx, hx.map hc.continuous_at (tendsto_principal_principal.2 h) end lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) : f '' closure s ⊆ closure (f '' s) := ((maps_to_image f s).closure h).image_subset lemma closure_subset_preimage_closure_image {f : α → β} {s : set α} (h : continuous f) : closure s ⊆ f ⁻¹' (closure (f '' s)) := by { rw ← set.image_subset_iff, exact image_closure_subset_closure_image h } lemma map_mem_closure {s : set α} {t : set β} {f : α → β} {a : α} (hf : continuous f) (ha : a ∈ closure s) (ht : ∀a∈s, f a ∈ t) : f a ∈ closure t := set.maps_to.closure ht hf ha /-! ### Function with dense range -/ section dense_range variables {κ ι : Type*} (f : κ → β) (g : β → γ) /-- `f : ι → β` has dense range if its range (image) is a dense subset of β. -/ def dense_range := dense (range f) variables {f} /-- A surjective map has dense range. -/ lemma function.surjective.dense_range (hf : function.surjective f) : dense_range f := λ x, by simp [hf.range_eq] lemma dense_range_iff_closure_range : dense_range f ↔ closure (range f) = univ := dense_iff_closure_eq lemma dense_range.closure_range (h : dense_range f) : closure (range f) = univ := h.closure_eq lemma continuous.range_subset_closure_image_dense {f : α → β} (hf : continuous f) {s : set α} (hs : dense s) : range f ⊆ closure (f '' s) := by { rw [← image_univ, ← hs.closure_eq], exact image_closure_subset_closure_image hf } /-- The image of a dense set under a continuous map with dense range is a dense set. -/ lemma dense_range.dense_image {f : α → β} (hf' : dense_range f) (hf : continuous f) {s : set α} (hs : dense s) : dense (f '' s) := (hf'.mono $ hf.range_subset_closure_image_dense hs).of_closure /-- If a continuous map with dense range maps a dense set to a subset of `t`, then `t` is a dense set. -/ lemma dense_range.dense_of_maps_to {f : α → β} (hf' : dense_range f) (hf : continuous f) {s : set α} (hs : dense s) {t : set β} (ht : maps_to f s t) : dense t := (hf'.dense_image hf hs).mono ht.image_subset /-- Composition of a continuous map with dense range and a function with dense range has dense range. -/ lemma dense_range.comp {g : β → γ} {f : κ → β} (hg : dense_range g) (hf : dense_range f) (cg : continuous g) : dense_range (g ∘ f) := by { rw [dense_range, range_comp], exact hg.dense_image cg hf } lemma dense_range.nonempty_iff (hf : dense_range f) : nonempty κ ↔ nonempty β := range_nonempty_iff_nonempty.symm.trans hf.nonempty_iff lemma dense_range.nonempty [h : nonempty β] (hf : dense_range f) : nonempty κ := hf.nonempty_iff.mpr h /-- Given a function `f : α → β` with dense range and `b : β`, returns some `a : α`. -/ def dense_range.some (hf : dense_range f) (b : β) : κ := classical.choice $ hf.nonempty_iff.mpr ⟨b⟩ end dense_range end continuous
b3092aed2b86d6221979ab592f9a0efc12947522
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/alias.lean
d6c1d81eb2c9a0dfe6e235da6a49c659f5e21e28
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
338
lean
-- namespace N1 constant num : Type.{1} constant foo : num → num → num end N1 namespace N2 constant val : Type.{1} constant foo : val → val → val end N2 open N2 open N1 constants a b : N1.num #print raw foo a b open N2 #print raw foo a b open N1 #print raw foo a b open N1 #print raw foo a b open N2 #print raw foo a b
fcceb8f1a315601a1a17ce34485bdd291cb6b732
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/quotient_auto.lean
16117b2369388f88e74bb7a4dc2138d81187c904
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
5,920
lean
/- Copyright (c) 2020 David Wärn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Wärn -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.natural_isomorphism import Mathlib.PostPort universes v u l u_1 u_2 namespace Mathlib /-! # Quotient category Constructs the quotient of a category by an arbitrary family of relations on its hom-sets, by introducing a type synonym for the objects, and identifying homs as necessary. This is analogous to 'the quotient of a group by the normal closure of a subset', rather than 'the quotient of a group by a normal subgroup'. -/ namespace category_theory /-- A type synonom for `C`, thought of as the objects of the quotient category. -/ structure quotient {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) where as : C protected instance quotient.inhabited {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) [Inhabited C] : Inhabited (quotient r) := { default := quotient.mk Inhabited.default } namespace quotient /-- Generates the closure of a family of relations w.r.t. composition from left and right. -/ inductive comp_closure {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {s : C} {t : C} : (s ⟶ t) → (s ⟶ t) → Prop where | intro : ∀ {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t), r m₁ m₂ → comp_closure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g) theorem comp_left {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {a : C} {b : C} {c : C} (f : a ⟶ b) (g₁ : b ⟶ c) (g₂ : b ⟶ c) (h : comp_closure r g₁ g₂) : comp_closure r (f ≫ g₁) (f ≫ g₂) := sorry theorem comp_right {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {a : C} {b : C} {c : C} (g : b ⟶ c) (f₁ : a ⟶ b) (f₂ : a ⟶ b) (h : comp_closure r f₁ f₂) : comp_closure r (f₁ ≫ g) (f₂ ≫ g) := sorry /-- Hom-sets of the quotient category. -/ def hom {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) (s : quotient r) (t : quotient r) := Quot (comp_closure r) protected instance hom.inhabited {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) (a : quotient r) : Inhabited (hom r a a) := { default := Quot.mk (comp_closure r) 𝟙 } /-- Composition in the quotient category. -/ def comp {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {a : quotient r} {b : quotient r} {c : quotient r} : hom r a b → hom r b c → hom r a c := fun (hf : hom r a b) (hg : hom r b c) => quot.lift_on hf (fun (f : as a ⟶ as b) => quot.lift_on hg (fun (g : as b ⟶ as c) => Quot.mk (comp_closure r) (f ≫ g)) sorry) sorry @[simp] theorem comp_mk {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {a : quotient r} {b : quotient r} {c : quotient r} (f : as a ⟶ as b) (g : as b ⟶ as c) : comp r (Quot.mk (comp_closure r) f) (Quot.mk (comp_closure r) g) = Quot.mk (comp_closure r) (f ≫ g) := rfl protected instance category {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) : category (quotient r) := category.mk /-- The functor from a category to its quotient. -/ @[simp] theorem functor_map {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) (_x : C) : ∀ (_x_1 : C) (f : _x ⟶ _x_1), functor.map (functor r) f = Quot.mk (comp_closure r) f := fun (_x_1 : C) (f : _x ⟶ _x_1) => Eq.refl (functor.map (functor r) f) protected theorem induction {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {P : {a b : quotient r} → (a ⟶ b) → Prop} (h : ∀ {x y : C} (f : x ⟶ y), P (functor.map (functor r) f)) {a : quotient r} {b : quotient r} (f : a ⟶ b) : P f := sorry protected theorem sound {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {a : C} {b : C} {f₁ : a ⟶ b} {f₂ : a ⟶ b} (h : r f₁ f₂) : functor.map (functor r) f₁ = functor.map (functor r) f₂ := sorry /-- The induced functor on the quotient category. -/ def lift {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {D : Type u_1} [category D] (F : C ⥤ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → functor.map F f₁ = functor.map F f₂) : quotient r ⥤ D := functor.mk (fun (a : quotient r) => functor.obj F (as a)) fun (a b : quotient r) (hf : a ⟶ b) => quot.lift_on hf (fun (f : as a ⟶ as b) => functor.map F f) sorry /-- The original functor factors through the induced functor. -/ def lift.is_lift {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {D : Type u_1} [category D] (F : C ⥤ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → functor.map F f₁ = functor.map F f₂) : functor r ⋙ lift r F H ≅ F := nat_iso.of_components (fun (X : C) => iso.refl (functor.obj (functor r ⋙ lift r F H) X)) sorry @[simp] theorem lift.is_lift_hom {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {D : Type u_1} [category D] (F : C ⥤ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → functor.map F f₁ = functor.map F f₂) (X : C) : nat_trans.app (iso.hom (lift.is_lift r F H)) X = 𝟙 := rfl @[simp] theorem lift.is_lift_inv {C : Type u} [category C] (r : {a b : C} → (a ⟶ b) → (a ⟶ b) → Prop) {D : Type u_1} [category D] (F : C ⥤ D) (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → functor.map F f₁ = functor.map F f₂) (X : C) : nat_trans.app (iso.inv (lift.is_lift r F H)) X = 𝟙 := rfl end Mathlib
46062242c336ac947081b11d5fd81fae2ced6148
d7189ea2ef694124821b033e533f18905b5e87ef
/galois/list/nth.lean
338fd74c85e754876042358212e34298bb7bff19
[ "Apache-2.0" ]
permissive
digama0/lean-protocol-support
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
refs/heads/master
1,625,421,450,627
1,506,035,462,000
1,506,035,462,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,830
lean
/- Lemmas about nth -/ universe u namespace list theorem nth_is_none_bound {α:Type} {l : list α} {i:ℕ} (pr : l.nth i = none) : i ≥ l.length := begin revert i, induction l, case nil { intros i pr, apply nat.zero_le, }, case cons h r ind { intros i pr, cases i; simp at pr, contradiction, exact nat.succ_le_succ (ind pr), } end theorem nth_is_some_bound {α:Type} {l : list α} {i:ℕ} {e : α} (pr : l.nth i = some e) : i < l.length := begin revert i, induction l, case nil { intros i pr, simp at pr, contradiction, }, case cons h r ind { intros i pr, cases i, { apply nat.zero_lt_succ, }, { apply nat.succ_le_succ (ind pr), } } end theorem nth_mem {α:Type} {l : list α} {i:ℕ} {e : α} (pr : l.nth i = some e) : e ∈ l := begin revert i, induction l, case nil { intros i pr, simp at pr, contradiction, }, case cons h r ind { intros i pr, cases i; simp at pr, case nat.zero { simp [option.some.inj pr], }, case nat.succ i { exact or.inr (ind pr), } } end lemma nth_mem_len {A} {x : A} {xs : list A} (H : x ∈ xs) : ∃ n, xs.nth n = some x := begin induction xs, case nil { simp at H, contradiction, }, case cons h r ind { simp at H, cases H with here there, { apply exists.intro 0, simp [here], }, { apply exists.elim (ind there), intros n pr, constructor, change (nth (h :: r) (nat.succ n) = some x), exact pr, } }, end lemma nth_append_left {α:Type u} {x : α} (xs ys : list α) {i : ℕ} (pr : xs.nth i = some x) : (xs ++ ys).nth i = some x := begin revert i, induction xs, case nil { intros i pr, contradiction, }, case cons h r ind { intros i pr, cases i with i, { exact pr, }, { exact ind pr, }, } end end list
5191ef129416785a75ccdc193356fd20aa76f144
a338c3e75cecad4fb8d091bfe505f7399febfd2b
/src/data/real/basic.lean
803765945cc324317ef86c69b7868f912a9eaa6b
[ "Apache-2.0" ]
permissive
bacaimano/mathlib
88eb7911a9054874fba2a2b74ccd0627c90188af
f2edc5a3529d95699b43514d6feb7eb11608723f
refs/heads/master
1,686,410,075,833
1,625,497,070,000
1,625,497,070,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
24,449
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn -/ import order.conditionally_complete_lattice import data.real.cau_seq_completion import algebra.archimedean import algebra.star.basic /-! # Real numbers from Cauchy sequences This file defines `ℝ` as the type of equivalence classes of Cauchy sequences of rational numbers. This choice is motivated by how easy it is to prove that `ℝ` is a commutative ring, by simply lifting everything to `ℚ`. -/ /-- The type `ℝ` of real numbers constructed as equivalence classes of Cauchy sequences of rational numbers. -/ structure real := of_cauchy :: (cauchy : @cau_seq.completion.Cauchy ℚ _ _ _ abs _) notation `ℝ` := real attribute [pp_using_anonymous_constructor] real namespace real open cau_seq cau_seq.completion variables {x y : ℝ} lemma ext_cauchy_iff : ∀ {x y : real}, x = y ↔ x.cauchy = y.cauchy | ⟨a⟩ ⟨b⟩ := by split; cc lemma ext_cauchy {x y : real} : x.cauchy = y.cauchy → x = y := ext_cauchy_iff.2 /-- The real numbers are isomorphic to the quotient of Cauchy sequences on the rationals. -/ def equiv_Cauchy : ℝ ≃ cau_seq.completion.Cauchy := ⟨real.cauchy, real.of_cauchy, λ ⟨_⟩, rfl, λ _, rfl⟩ -- irreducible doesn't work for instances: https://github.com/leanprover-community/lean/issues/511 @[irreducible] private def zero : ℝ := ⟨0⟩ @[irreducible] private def one : ℝ := ⟨1⟩ @[irreducible] private def add : ℝ → ℝ → ℝ | ⟨a⟩ ⟨b⟩ := ⟨a + b⟩ @[irreducible] private def neg : ℝ → ℝ | ⟨a⟩ := ⟨-a⟩ @[irreducible] private def mul : ℝ → ℝ → ℝ | ⟨a⟩ ⟨b⟩ := ⟨a * b⟩ instance : has_zero ℝ := ⟨zero⟩ instance : has_one ℝ := ⟨one⟩ instance : has_add ℝ := ⟨add⟩ instance : has_neg ℝ := ⟨neg⟩ instance : has_mul ℝ := ⟨mul⟩ lemma zero_cauchy : (⟨0⟩ : ℝ) = 0 := show _ = zero, by rw zero lemma one_cauchy : (⟨1⟩ : ℝ) = 1 := show _ = one, by rw one lemma add_cauchy {a b} : (⟨a⟩ + ⟨b⟩ : ℝ) = ⟨a + b⟩ := show add _ _ = _, by rw add lemma neg_cauchy {a} : (-⟨a⟩ : ℝ) = ⟨-a⟩ := show neg _ = _, by rw neg lemma mul_cauchy {a b} : (⟨a⟩ * ⟨b⟩ : ℝ) = ⟨a * b⟩ := show mul _ _ = _, by rw mul instance : comm_ring ℝ := begin refine_struct { zero := 0, one := 1, mul := (*), add := (+), neg := @has_neg.neg ℝ _, sub := λ a b, a + (-b), npow := @npow_rec _ ⟨1⟩ ⟨(*)⟩, nsmul := @nsmul_rec _ ⟨0⟩ ⟨(+)⟩, gsmul := @gsmul_rec _ ⟨0⟩ ⟨(+)⟩ ⟨@has_neg.neg ℝ _⟩ }; repeat { rintro ⟨_⟩, }; try { refl }; simp [← zero_cauchy, ← one_cauchy, add_cauchy, neg_cauchy, mul_cauchy]; apply add_assoc <|> apply add_comm <|> apply mul_assoc <|> apply mul_comm <|> apply left_distrib <|> apply right_distrib <|> apply sub_eq_add_neg <|> skip end /- Extra instances to short-circuit type class resolution -/ instance : ring ℝ := by apply_instance instance : comm_semiring ℝ := by apply_instance instance : semiring ℝ := by apply_instance instance : add_comm_group ℝ := by apply_instance instance : add_group ℝ := by apply_instance instance : add_comm_monoid ℝ := by apply_instance instance : add_monoid ℝ := by apply_instance instance : add_left_cancel_semigroup ℝ := by apply_instance instance : add_right_cancel_semigroup ℝ := by apply_instance instance : add_comm_semigroup ℝ := by apply_instance instance : add_semigroup ℝ := by apply_instance instance : comm_monoid ℝ := by apply_instance instance : monoid ℝ := by apply_instance instance : comm_semigroup ℝ := by apply_instance instance : semigroup ℝ := by apply_instance instance : has_sub ℝ := by apply_instance instance : inhabited ℝ := ⟨0⟩ /-- The real numbers are a `*`-ring, with the trivial `*`-structure. -/ instance : star_ring ℝ := star_ring_of_comm /-- Coercion `ℚ` → `ℝ` as a `ring_hom`. Note that this is `cau_seq.completion.of_rat`, not `rat.cast`. -/ def of_rat : ℚ →+* ℝ := by refine_struct { to_fun := of_cauchy ∘ of_rat }; simp [of_rat_one, of_rat_zero, of_rat_mul, of_rat_add, one_cauchy, zero_cauchy, ← mul_cauchy, ← add_cauchy] lemma of_rat_apply (x : ℚ) : of_rat x = of_cauchy (cau_seq.completion.of_rat x) := rfl /-- Make a real number from a Cauchy sequence of rationals (by taking the equivalence class). -/ def mk (x : cau_seq ℚ abs) : ℝ := ⟨cau_seq.completion.mk x⟩ theorem mk_eq {f g : cau_seq ℚ abs} : mk f = mk g ↔ f ≈ g := ext_cauchy_iff.trans mk_eq @[irreducible] private def lt : ℝ → ℝ → Prop | ⟨x⟩ ⟨y⟩ := quotient.lift_on₂ x y (<) $ λ f₁ g₁ f₂ g₂ hf hg, propext $ ⟨λ h, lt_of_eq_of_lt (setoid.symm hf) (lt_of_lt_of_eq h hg), λ h, lt_of_eq_of_lt hf (lt_of_lt_of_eq h (setoid.symm hg))⟩ instance : has_lt ℝ := ⟨lt⟩ lemma lt_cauchy {f g} : (⟨⟦f⟧⟩ : ℝ) < ⟨⟦g⟧⟩ ↔ f < g := show lt _ _ ↔ _, by rw lt; refl @[simp] theorem mk_lt {f g : cau_seq ℚ abs} : mk f < mk g ↔ f < g := lt_cauchy lemma mk_zero : mk 0 = 0 := by rw ← zero_cauchy; refl lemma mk_one : mk 1 = 1 := by rw ← one_cauchy; refl lemma mk_add {f g : cau_seq ℚ abs} : mk (f + g) = mk f + mk g := by simp [mk, add_cauchy] lemma mk_mul {f g : cau_seq ℚ abs} : mk (f * g) = mk f * mk g := by simp [mk, mul_cauchy] lemma mk_neg {f : cau_seq ℚ abs} : mk (-f) = -mk f := by simp [mk, neg_cauchy] @[simp] theorem mk_pos {f : cau_seq ℚ abs} : 0 < mk f ↔ pos f := by rw [← mk_zero, mk_lt]; exact iff_of_eq (congr_arg pos (sub_zero f)) @[irreducible] private def le (x y : ℝ) : Prop := x < y ∨ x = y instance : has_le ℝ := ⟨le⟩ private lemma le_def {x y : ℝ} : x ≤ y ↔ x < y ∨ x = y := show le _ _ ↔ _, by rw le @[simp] theorem mk_le {f g : cau_seq ℚ abs} : mk f ≤ mk g ↔ f ≤ g := by simp [le_def, mk_eq]; refl @[elab_as_eliminator] protected lemma ind_mk {C : real → Prop} (x : real) (h : ∀ y, C (mk y)) : C x := begin cases x with x, induction x using quot.induction_on with x, exact h x end theorem add_lt_add_iff_left {a b : ℝ} (c : ℝ) : c + a < c + b ↔ a < b := begin induction a using real.ind_mk, induction b using real.ind_mk, induction c using real.ind_mk, simp only [mk_lt, ← mk_add], show pos _ ↔ pos _, rw add_sub_add_left_eq_sub end instance : partial_order ℝ := { le := (≤), lt := (<), lt_iff_le_not_le := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b, by simpa using lt_iff_le_not_le, le_refl := λ a, a.ind_mk (by intro a; rw mk_le), le_trans := λ a b c, real.ind_mk a $ λ a, real.ind_mk b $ λ b, real.ind_mk c $ λ c, by simpa using le_trans, lt_iff_le_not_le := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b, by simpa using lt_iff_le_not_le, le_antisymm := λ a b, real.ind_mk a $ λ a, real.ind_mk b $ λ b, by simpa [mk_eq] using @cau_seq.le_antisymm _ _ a b } instance : preorder ℝ := by apply_instance theorem of_rat_lt {x y : ℚ} : of_rat x < of_rat y ↔ x < y := begin rw [mk_lt] {md := tactic.transparency.semireducible}, exact const_lt end protected theorem zero_lt_one : (0 : ℝ) < 1 := by convert of_rat_lt.2 zero_lt_one; simp protected theorem mul_pos {a b : ℝ} : 0 < a → 0 < b → 0 < a * b := begin induction a using real.ind_mk with a, induction b using real.ind_mk with b, simpa only [mk_lt, mk_pos, ← mk_mul] using cau_seq.mul_pos end instance : ordered_ring ℝ := { add_le_add_left := begin simp only [le_iff_eq_or_lt], rintros a b ⟨rfl, h⟩, { simp }, { exact λ c, or.inr ((add_lt_add_iff_left c).2 ‹_›) } end, zero_le_one := le_of_lt real.zero_lt_one, mul_pos := @real.mul_pos, .. real.comm_ring, .. real.partial_order, .. real.semiring } instance : ordered_semiring ℝ := by apply_instance instance : ordered_add_comm_group ℝ := by apply_instance instance : ordered_cancel_add_comm_monoid ℝ := by apply_instance instance : ordered_add_comm_monoid ℝ := by apply_instance instance : nontrivial ℝ := ⟨⟨0, 1, ne_of_lt real.zero_lt_one⟩⟩ open_locale classical noncomputable instance : linear_order ℝ := { le_total := begin intros a b, induction a using real.ind_mk with a, induction b using real.ind_mk with b, simpa using le_total a b, end, decidable_le := by apply_instance, .. real.partial_order } noncomputable instance : linear_ordered_comm_ring ℝ := { .. real.nontrivial, .. real.ordered_ring, .. real.comm_ring, .. real.linear_order } /- Extra instances to short-circuit type class resolution -/ noncomputable instance : linear_ordered_ring ℝ := by apply_instance noncomputable instance : linear_ordered_semiring ℝ := by apply_instance instance : domain ℝ := { .. real.nontrivial, .. real.comm_ring, .. linear_ordered_ring.to_domain } /-- The real numbers are an ordered `*`-ring, with the trivial `*`-structure. -/ instance : star_ordered_ring ℝ := { star_mul_self_nonneg := λ r, mul_self_nonneg r, } @[irreducible] private noncomputable def inv' : ℝ → ℝ | ⟨a⟩ := ⟨a⁻¹⟩ noncomputable instance : has_inv ℝ := ⟨inv'⟩ lemma inv_cauchy {f} : (⟨f⟩ : ℝ)⁻¹ = ⟨f⁻¹⟩ := show inv' _ = _, by rw inv' noncomputable instance : linear_ordered_field ℝ := { inv := has_inv.inv, mul_inv_cancel := begin rintros ⟨a⟩ h, rw mul_comm, simp only [inv_cauchy, mul_cauchy, ← one_cauchy, ← zero_cauchy, ne.def] at *, exact cau_seq.completion.inv_mul_cancel h, end, inv_zero := by simp [← zero_cauchy, inv_cauchy], ..real.linear_ordered_comm_ring, ..real.domain } /- Extra instances to short-circuit type class resolution -/ noncomputable instance : linear_ordered_add_comm_group ℝ := by apply_instance noncomputable instance field : field ℝ := by apply_instance noncomputable instance : division_ring ℝ := by apply_instance noncomputable instance : integral_domain ℝ := by apply_instance noncomputable instance : distrib_lattice ℝ := by apply_instance noncomputable instance : lattice ℝ := by apply_instance noncomputable instance : semilattice_inf ℝ := by apply_instance noncomputable instance : semilattice_sup ℝ := by apply_instance noncomputable instance : has_inf ℝ := by apply_instance noncomputable instance : has_sup ℝ := by apply_instance noncomputable instance decidable_lt (a b : ℝ) : decidable (a < b) := by apply_instance noncomputable instance decidable_le (a b : ℝ) : decidable (a ≤ b) := by apply_instance noncomputable instance decidable_eq (a b : ℝ) : decidable (a = b) := by apply_instance open rat @[simp] theorem of_rat_eq_cast : ∀ x : ℚ, of_rat x = x := of_rat.eq_rat_cast theorem le_mk_of_forall_le {f : cau_seq ℚ abs} : (∃ i, ∀ j ≥ i, x ≤ f j) → x ≤ mk f := begin intro h, induction x using real.ind_mk with x, apply le_of_not_lt, rw mk_lt, rintro ⟨K, K0, hK⟩, obtain ⟨i, H⟩ := exists_forall_ge_and h (exists_forall_ge_and hK (f.cauchy₃ $ half_pos K0)), apply not_lt_of_le (H _ (le_refl _)).1, rw ← of_rat_eq_cast, rw [mk_lt] {md := tactic.transparency.semireducible}, refine ⟨_, half_pos K0, i, λ j ij, _⟩, have := add_le_add (H _ ij).2.1 (le_of_lt (abs_lt.1 $ (H _ (le_refl _)).2.2 _ ij).1), rwa [← sub_eq_add_neg, sub_self_div_two, sub_apply, sub_add_sub_cancel] at this end theorem mk_le_of_forall_le {f : cau_seq ℚ abs} {x : ℝ} (h : ∃ i, ∀ j ≥ i, (f j : ℝ) ≤ x) : mk f ≤ x := begin cases h with i H, rw [← neg_le_neg_iff, ← mk_neg], exact le_mk_of_forall_le ⟨i, λ j ij, by simp [H _ ij]⟩ end theorem mk_near_of_forall_near {f : cau_seq ℚ abs} {x : ℝ} {ε : ℝ} (H : ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) ≤ ε) : abs (mk f - x) ≤ ε := abs_sub_le_iff.2 ⟨sub_le_iff_le_add'.2 $ mk_le_of_forall_le $ H.imp $ λ i h j ij, sub_le_iff_le_add'.1 (abs_sub_le_iff.1 $ h j ij).1, sub_le.1 $ le_mk_of_forall_le $ H.imp $ λ i h j ij, sub_le.1 (abs_sub_le_iff.1 $ h j ij).2⟩ instance : archimedean ℝ := archimedean_iff_rat_le.2 $ λ x, real.ind_mk x $ λ f, let ⟨M, M0, H⟩ := f.bounded' 0 in ⟨M, mk_le_of_forall_le ⟨0, λ i _, rat.cast_le.2 $ le_of_lt (abs_lt.1 (H i)).2⟩⟩ noncomputable instance : floor_ring ℝ := archimedean.floor_ring _ theorem is_cau_seq_iff_lift {f : ℕ → ℚ} : is_cau_seq abs f ↔ is_cau_seq abs (λ i, (f i : ℝ)) := ⟨λ H ε ε0, let ⟨δ, δ0, δε⟩ := exists_pos_rat_lt ε0 in (H _ δ0).imp $ λ i hi j ij, lt_trans (by simpa using (@rat.cast_lt ℝ _ _ _).2 (hi _ ij)) δε, λ H ε ε0, (H _ (rat.cast_pos.2 ε0)).imp $ λ i hi j ij, (@rat.cast_lt ℝ _ _ _).1 $ by simpa using hi _ ij⟩ theorem of_near (f : ℕ → ℚ) (x : ℝ) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) < ε) : ∃ h', real.mk ⟨f, h'⟩ = x := ⟨is_cau_seq_iff_lift.2 (of_near _ (const abs x) h), sub_eq_zero.1 $ abs_eq_zero.1 $ eq_of_le_of_forall_le_of_dense (abs_nonneg _) $ λ ε ε0, mk_near_of_forall_near $ (h _ ε0).imp (λ i h j ij, le_of_lt (h j ij))⟩ theorem exists_floor (x : ℝ) : ∃ (ub : ℤ), (ub:ℝ) ≤ x ∧ ∀ (z : ℤ), (z:ℝ) ≤ x → z ≤ ub := int.exists_greatest_of_bdd (let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h', int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩) (let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩) theorem exists_sup (S : set ℝ) : (∃ x, x ∈ S) → (∃ x, ∀ y ∈ S, y ≤ x) → ∃ x, ∀ y, x ≤ y ↔ ∀ z ∈ S, z ≤ y | ⟨L, hL⟩ ⟨U, hU⟩ := begin choose f hf using begin refine λ d : ℕ, @int.exists_greatest_of_bdd (λ n, ∃ y ∈ S, (n:ℝ) ≤ y * d) _ _, { cases exists_int_gt U with k hk, refine ⟨k * d, λ z h, _⟩, rcases h with ⟨y, yS, hy⟩, refine int.cast_le.1 (le_trans hy _), simp, exact mul_le_mul_of_nonneg_right (le_trans (hU _ yS) (le_of_lt hk)) (nat.cast_nonneg _) }, { exact ⟨⌊L * d⌋, L, hL, floor_le _⟩ } end, have hf₁ : ∀ n > 0, ∃ y ∈ S, ((f n / n:ℚ):ℝ) ≤ y := λ n n0, let ⟨y, yS, hy⟩ := (hf n).1 in ⟨y, yS, by simpa using (div_le_iff ((nat.cast_pos.2 n0):((_:ℝ) < _))).2 hy⟩, have hf₂ : ∀ (n > 0) (y ∈ S), (y - (n:ℕ)⁻¹ : ℝ) < (f n / n:ℚ), { intros n n0 y yS, have := lt_of_lt_of_le (sub_one_lt_floor _) (int.cast_le.2 $ (hf n).2 _ ⟨y, yS, floor_le _⟩), simp [-sub_eq_add_neg], rwa [lt_div_iff ((nat.cast_pos.2 n0):((_:ℝ) < _)), sub_mul, _root_.inv_mul_cancel], exact ne_of_gt (nat.cast_pos.2 n0) }, suffices hg, let g : cau_seq ℚ abs := ⟨λ n, f n / n, hg⟩, refine ⟨mk g, λ y, ⟨λ h x xS, le_trans _ h, λ h, _⟩⟩, { refine le_of_forall_ge_of_dense (λ z xz, _), cases exists_nat_gt (x - z)⁻¹ with K hK, refine le_mk_of_forall_le ⟨K, λ n nK, _⟩, replace xz := sub_pos.2 xz, replace hK := le_trans (le_of_lt hK) (nat.cast_le.2 nK), have n0 : 0 < n := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 xz) hK), refine le_trans _ (le_of_lt $ hf₂ _ n0 _ xS), rwa [le_sub, inv_le ((nat.cast_pos.2 n0):((_:ℝ) < _)) xz] }, { exact mk_le_of_forall_le ⟨1, λ n n1, let ⟨x, xS, hx⟩ := hf₁ _ n1 in le_trans hx (h _ xS)⟩ }, intros ε ε0, suffices : ∀ j k ≥ nat_ceil ε⁻¹, (f j / j - f k / k : ℚ) < ε, { refine ⟨_, λ j ij, abs_lt.2 ⟨_, this _ _ ij (le_refl _)⟩⟩, rw [neg_lt, neg_sub], exact this _ _ (le_refl _) ij }, intros j k ij ik, replace ij := le_trans (le_nat_ceil _) (nat.cast_le.2 ij), replace ik := le_trans (le_nat_ceil _) (nat.cast_le.2 ik), have j0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 ε0) ij), have k0 := nat.cast_pos.1 (lt_of_lt_of_le (inv_pos.2 ε0) ik), rcases hf₁ _ j0 with ⟨y, yS, hy⟩, refine lt_of_lt_of_le ((@rat.cast_lt ℝ _ _ _).1 _) ((inv_le ε0 (nat.cast_pos.2 k0)).1 ik), simpa using sub_lt_iff_lt_add'.2 (lt_of_le_of_lt hy $ sub_lt_iff_lt_add.1 $ hf₂ _ k0 _ yS) end noncomputable instance : has_Sup ℝ := ⟨λ S, if h : (∃ x, x ∈ S) ∧ (∃ x, ∀ y ∈ S, y ≤ x) then classical.some (exists_sup S h.1 h.2) else 0⟩ lemma Sup_def (S : set ℝ) : Sup S = if h : (∃ x, x ∈ S) ∧ (∃ x, ∀ y ∈ S, y ≤ x) then classical.some (exists_sup S h.1 h.2) else 0 := rfl theorem Sup_le (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x) {y} : Sup S ≤ y ↔ ∀ z ∈ S, z ≤ y := by simp [Sup_def, h₁, h₂]; exact classical.some_spec (exists_sup S h₁ h₂) y theorem lt_Sup (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x) {y} : y < Sup S ↔ ∃ z ∈ S, y < z := by simpa [not_forall] using not_congr (@Sup_le S h₁ h₂ y) theorem le_Sup (S : set ℝ) (h₂ : ∃ x, ∀ y ∈ S, y ≤ x) {x} (xS : x ∈ S) : x ≤ Sup S := (Sup_le S ⟨_, xS⟩ h₂).1 (le_refl _) _ xS theorem Sup_le_ub (S : set ℝ) (h₁ : ∃ x, x ∈ S) {ub} (h₂ : ∀ y ∈ S, y ≤ ub) : Sup S ≤ ub := (Sup_le S h₁ ⟨_, h₂⟩).2 h₂ protected lemma is_lub_Sup {s : set ℝ} {a b : ℝ} (ha : a ∈ s) (hb : b ∈ upper_bounds s) : is_lub s (Sup s) := ⟨λ x xs, real.le_Sup s ⟨_, hb⟩ xs, λ u h, real.Sup_le_ub _ ⟨_, ha⟩ h⟩ noncomputable instance : has_Inf ℝ := ⟨λ S, -Sup {x | -x ∈ S}⟩ lemma Inf_def (S : set ℝ) : Inf S = -Sup {x | -x ∈ S} := rfl theorem le_Inf (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y) {y} : y ≤ Inf S ↔ ∀ z ∈ S, y ≤ z := begin refine le_neg.trans ((Sup_le _ _ _).trans _), { cases h₁ with x xS, exact ⟨-x, by simp [xS]⟩ }, { cases h₂ with ub h, exact ⟨-ub, λ y hy, le_neg.1 $ h _ hy⟩ }, split; intros H z hz, { exact neg_le_neg_iff.1 (H _ $ by simp [hz]) }, { exact le_neg.2 (H _ hz) } end section -- this proof times out without this local attribute [instance, priority 1000] classical.prop_decidable theorem Inf_lt (S : set ℝ) (h₁ : ∃ x, x ∈ S) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y) {y} : Inf S < y ↔ ∃ z ∈ S, z < y := by simpa [not_forall] using not_congr (@le_Inf S h₁ h₂ y) end theorem Inf_le (S : set ℝ) (h₂ : ∃ x, ∀ y ∈ S, x ≤ y) {x} (xS : x ∈ S) : Inf S ≤ x := (le_Inf S ⟨_, xS⟩ h₂).1 (le_refl _) _ xS theorem lb_le_Inf (S : set ℝ) (h₁ : ∃ x, x ∈ S) {lb} (h₂ : ∀ y ∈ S, lb ≤ y) : lb ≤ Inf S := (le_Inf S h₁ ⟨_, h₂⟩).2 h₂ noncomputable instance : conditionally_complete_linear_order ℝ := { Sup := has_Sup.Sup, Inf := has_Inf.Inf, le_cSup := assume (s : set ℝ) (a : ℝ) (_ : bdd_above s) (_ : a ∈ s), show a ≤ Sup s, from le_Sup s ‹bdd_above s› ‹a ∈ s›, cSup_le := assume (s : set ℝ) (a : ℝ) (_ : s.nonempty) (H : ∀b∈s, b ≤ a), show Sup s ≤ a, from Sup_le_ub s ‹s.nonempty› H, cInf_le := assume (s : set ℝ) (a : ℝ) (_ : bdd_below s) (_ : a ∈ s), show Inf s ≤ a, from Inf_le s ‹bdd_below s› ‹a ∈ s›, le_cInf := assume (s : set ℝ) (a : ℝ) (_ : s.nonempty) (H : ∀b∈s, a ≤ b), show a ≤ Inf s, from lb_le_Inf s ‹s.nonempty› H, ..real.linear_order, ..real.lattice} lemma lt_Inf_add_pos {s : set ℝ} (h : bdd_below s) (h' : s.nonempty) {ε : ℝ} (hε : 0 < ε) : ∃ a ∈ s, a < Inf s + ε := (Inf_lt _ h' h).1 $ lt_add_of_pos_right _ hε lemma add_pos_lt_Sup {s : set ℝ} (h : bdd_above s) (h' : s.nonempty) {ε : ℝ} (hε : ε < 0) : ∃ a ∈ s, Sup s + ε < a := (real.lt_Sup _ h' h).1 $ add_lt_iff_neg_left.mpr hε lemma Inf_le_iff {s : set ℝ} (h : bdd_below s) (h' : s.nonempty) {a : ℝ} : Inf s ≤ a ↔ ∀ ε, 0 < ε → ∃ x ∈ s, x < a + ε := begin rw le_iff_forall_pos_lt_add, split; intros H ε ε_pos, { exact exists_lt_of_cInf_lt h' (H ε ε_pos) }, { rcases H ε ε_pos with ⟨x, x_in, hx⟩, exact cInf_lt_of_lt h x_in hx } end lemma le_Sup_iff {s : set ℝ} (h : bdd_above s) (h' : s.nonempty) {a : ℝ} : a ≤ Sup s ↔ ∀ ε, ε < 0 → ∃ x ∈ s, a + ε < x := begin rw le_iff_forall_pos_lt_add, refine ⟨λ H ε ε_neg, _, λ H ε ε_pos, _⟩, { exact exists_lt_of_lt_cSup h' (lt_sub_iff_add_lt.mp (H _ (neg_pos.mpr ε_neg))) }, { rcases H _ (neg_lt_zero.mpr ε_pos) with ⟨x, x_in, hx⟩, exact sub_lt_iff_lt_add.mp (lt_cSup_of_lt h x_in hx) } end theorem Sup_empty : Sup (∅ : set ℝ) = 0 := dif_neg $ by simp theorem Sup_of_not_bdd_above {s : set ℝ} (hs : ¬ bdd_above s) : Sup s = 0 := dif_neg $ assume h, hs h.2 theorem Sup_univ : Sup (@set.univ ℝ) = 0 := real.Sup_of_not_bdd_above $ λ ⟨x, h⟩, not_le_of_lt (lt_add_one _) $ h (set.mem_univ _) theorem Inf_empty : Inf (∅ : set ℝ) = 0 := by simp [Inf_def, Sup_empty] theorem Inf_of_not_bdd_below {s : set ℝ} (hs : ¬ bdd_below s) : Inf s = 0 := have bdd_above {x | -x ∈ s} → bdd_below s, from assume ⟨b, hb⟩, ⟨-b, assume x hxs, neg_le.2 $ hb $ by simp [hxs]⟩, have ¬ bdd_above {x | -x ∈ s}, from mt this hs, neg_eq_zero.2 $ Sup_of_not_bdd_above $ this /-- As `0` is the default value for `real.Sup` of the empty set or sets which are not bounded above, it suffices to show that `S` is bounded below by `0` to show that `0 ≤ Inf S`. -/ lemma Sup_nonneg (S : set ℝ) (hS : ∀ x ∈ S, (0:ℝ) ≤ x) : 0 ≤ Sup S := begin rcases S.eq_empty_or_nonempty with rfl | ⟨y, hy⟩, { simp [Sup_empty] }, { apply dite _ (λ h, le_cSup_of_le h hy $ hS y hy) (λ h, (Sup_of_not_bdd_above h).ge) } end /-- As `0` is the default value for `real.Sup` of the empty set, it suffices to show that `S` is bounded above by `0` to show that `Sup S ≤ 0`. -/ lemma Sup_nonpos (S : set ℝ) (hS : ∀ x ∈ S, x ≤ (0:ℝ)) : Sup S ≤ 0 := begin rcases S.eq_empty_or_nonempty with rfl | hS₂, { simp [Sup_empty] }, { apply Sup_le_ub _ hS₂ hS, } end /-- As `0` is the default value for `real.Inf` of the empty set, it suffices to show that `S` is bounded below by `0` to show that `0 ≤ Inf S`. -/ lemma Inf_nonneg (S : set ℝ) (hS : ∀ x ∈ S, (0:ℝ) ≤ x) : 0 ≤ Inf S := begin rcases S.eq_empty_or_nonempty with rfl | hS₂, { simp [Inf_empty] }, { apply lb_le_Inf S hS₂ hS } end /-- As `0` is the default value for `real.Inf` of the empty set or sets which are not bounded below, it suffices to show that `S` is bounded above by `0` to show that `Inf S ≤ 0`. -/ lemma Inf_nonpos (S : set ℝ) (hS : ∀ x ∈ S, x ≤ (0:ℝ)) : Inf S ≤ 0 := begin rcases S.eq_empty_or_nonempty with rfl | ⟨y, hy⟩, { simp [Inf_empty] }, { apply dite _ (λ h, cInf_le_of_le h hy $ hS y hy) (λ h, (Inf_of_not_bdd_below h).le) } end theorem cau_seq_converges (f : cau_seq ℝ abs) : ∃ x, f ≈ const abs x := begin let S := {x : ℝ | const abs x < f}, have lb : ∃ x, x ∈ S := exists_lt f, have ub' : ∀ x, f < const abs x → ∀ y ∈ S, y ≤ x := λ x h y yS, le_of_lt $ const_lt.1 $ cau_seq.lt_trans yS h, have ub : ∃ x, ∀ y ∈ S, y ≤ x := (exists_gt f).imp ub', refine ⟨Sup S, ((lt_total _ _).resolve_left (λ h, _)).resolve_right (λ h, _)⟩, { rcases h with ⟨ε, ε0, i, ih⟩, refine not_lt_of_le (Sup_le_ub S lb (ub' _ _)) (sub_lt_self _ (half_pos ε0)), refine ⟨_, half_pos ε0, i, λ j ij, _⟩, rw [sub_apply, const_apply, sub_right_comm, le_sub_iff_add_le, add_halves], exact ih _ ij }, { rcases h with ⟨ε, ε0, i, ih⟩, refine not_lt_of_le (le_Sup S ub _) ((lt_add_iff_pos_left _).2 (half_pos ε0)), refine ⟨_, half_pos ε0, i, λ j ij, _⟩, rw [sub_apply, const_apply, add_comm, ← sub_sub, le_sub_iff_add_le, add_halves], exact ih _ ij } end noncomputable instance : cau_seq.is_complete ℝ abs := ⟨cau_seq_converges⟩ end real
5ad7ac9b2d40a64616816cb154f7d335de22ab30
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/inlineApp.lean
85f8377ca794b3b76760676e43d37d2596f92bb2
[ "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
396
lean
import Lean def f (x : Nat) := (x - 1) + x * 2 + x*x def h (x : Nat) := inline <| f (x + x) #eval Lean.Compiler.compile #[``h] open Lean Compiler LCNF in @[cpass] def simpInline : PassInstaller := Testing.assertDoesNotContainConstAfter ``inline "simp did not inline `inline`" |>.install `simp `simpInlinesInline set_option trace.Compiler.result true #eval Lean.Compiler.compile #[``h]
93fc33f07859af6b798155789bd57f85de43456e
dc253be9829b840f15d96d986e0c13520b085033
/choice.hlean
ea2e52b4b9a2e128329946e3cc829f94d6bf9361
[ "Apache-2.0" ]
permissive
cmu-phil/Spectral
4ce68e5c1ef2a812ffda5260e9f09f41b85ae0ea
3b078f5f1de251637decf04bd3fc8aa01930a6b3
refs/heads/master
1,685,119,195,535
1,684,169,772,000
1,684,169,772,000
46,450,197
42
13
null
1,505,516,767,000
1,447,883,921,000
Lean
UTF-8
Lean
false
false
3,505
hlean
import types.trunc types.sum types.lift types.unit open pi prod sum unit bool trunc is_trunc is_equiv eq equiv lift pointed namespace choice universe variables u v -- the following brilliant name is from Agda definition unchoose [unfold 4] (n : ℕ₋₂) {X : Type} (A : X → Type) : trunc n (Πx, A x) → Πx, trunc n (A x) := trunc.elim (λf x, tr (f x)) definition has_choice [class] (n : ℕ₋₂) (X : Type.{u}) : Type.{max u (v+1)} := Π(A : X → Type.{v}), is_equiv (unchoose n A) definition choice_equiv [constructor] {n : ℕ₋₂} {X : Type} [H : has_choice.{u v} n X] (A : X → Type) : trunc n (Πx, A x) ≃ (Πx, trunc n (A x)) := equiv.mk _ (H A) definition has_choice_of_succ (X : Type) (H : Πk, has_choice.{_ v} (k.+1) X) (n : ℕ₋₂) : has_choice.{_ v} n X := begin cases n with n, { intro A, exact is_equiv_of_is_contr _ _ _ }, { exact H n } end /- currently we prove it using univalence, which means we cannot apply it to lift. -/ definition has_choice_equiv_closed (n : ℕ₋₂) {A B : Type} (f : A ≃ B) (hA : has_choice.{u v} n B) : has_choice.{u v} n A := begin induction f using rec_on_ua_idp, exact hA end definition has_choice_empty [instance] (n : ℕ₋₂) : has_choice.{_ v} n empty := begin intro A, fapply adjointify, { intro f, apply tr, intro x, induction x }, { intro f, apply eq_of_homotopy, intro x, induction x }, { intro g, induction g with g, apply ap tr, apply eq_of_homotopy, intro x, induction x } end definition has_choice_unit [instance] : Πn, has_choice.{_ v} n unit := begin intro n A, fapply adjointify, { intro f, induction f ⋆ with a, apply tr, intro u, induction u, exact a }, { intro f, apply eq_of_homotopy, intro u, induction u, esimp, generalize f ⋆, intro a, induction a, reflexivity }, { intro g, induction g with g, apply ap tr, apply eq_of_homotopy, intro u, induction u, reflexivity } end definition has_choice_sum [instance] (n : ℕ₋₂) (A B : Type.{u}) [has_choice.{_ v} n A] [has_choice.{_ v} n B] : has_choice.{_ v} n (A ⊎ B) := begin intro P, fapply is_equiv_of_equiv_of_homotopy, { exact calc trunc n (Πx, P x) ≃ trunc n ((Πa, P (inl a)) × Πb, P (inr b)) : trunc_equiv_trunc n !equiv_sum_rec⁻¹ᵉ ... ≃ trunc n (Πa, P (inl a)) × trunc n (Πb, P (inr b)) : trunc_prod_equiv ... ≃ (Πa, trunc n (P (inl a))) × Πb, trunc n (P (inr b)) : by exact prod_equiv_prod (choice_equiv _) (choice_equiv _) ... ≃ Πx, trunc n (P x) : equiv_sum_rec }, { intro f, induction f, apply eq_of_homotopy, intro x, esimp, induction x with a b: reflexivity } end definition has_choice_bool [instance] (n : ℕ₋₂) : has_choice.{_ v} n bool := has_choice_equiv_closed n bool_equiv_unit_sum_unit _ definition has_choice_lift.{u'} [instance] (n : ℕ₋₂) (A : Type) [has_choice.{_ v} n A] : has_choice.{_ v} n (lift.{u u'} A) := sorry --has_choice_equiv_closed n !equiv_lift⁻¹ᵉ _ definition has_choice_punit [instance] (n : ℕ₋₂) : has_choice.{_ v} n punit := has_choice_unit n definition has_choice_pbool [instance] (n : ℕ₋₂) : has_choice.{_ v} n pbool := has_choice_bool n definition has_choice_plift [instance] (n : ℕ₋₂) (A : Type*) [has_choice.{_ v} n A] : has_choice.{_ v} n (plift A) := has_choice_lift n A definition has_choice_psum [instance] (n : ℕ₋₂) (A B : Type*) [has_choice.{_ v} n A] [has_choice.{_ v} n B] : has_choice.{_ v} n (psum A B) := has_choice_sum n A B end choice
2d2df0d643b52dc533eefef8f365e21dfef32357
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/group_theory/subgroup/basic.lean
e25deb946bc30c0d89ededf37c04152701b8d8b0
[ "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
128,254
lean
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import algebra.group.conj import algebra.module.basic import algebra.order.group.inj_surj import data.countable.basic import group_theory.submonoid.centralizer import group_theory.submonoid.membership import logic.encodable.basic import order.atoms import order.sup_indep /-! # Subgroups This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled form (unbundled subgroups are in `deprecated/subgroups.lean`). We prove subgroups of a group form a complete lattice, and results about images and preimages of subgroups under group homomorphisms. The bundled subgroups use bundled monoid homomorphisms. There are also theorems about the subgroups generated by an element or a subset of a group, defined both inductively and as the infimum of the set of subgroups containing a given element/subset. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `group`s - `A` is an `add_group` - `H K` are `subgroup`s of `G` or `add_subgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `subgroup G` : the type of subgroups of a group `G` * `add_subgroup A` : the type of subgroups of an additive group `A` * `complete_lattice (subgroup G)` : the subgroups of `G` form a complete lattice * `subgroup.closure k` : the minimal subgroup that includes the set `k` * `subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G` * `subgroup.gi` : `closure` forms a Galois insertion with the coercion to set * `subgroup.comap H f` : the preimage of a subgroup `H` along the group homomorphism `f` is also a subgroup * `subgroup.map f H` : the image of a subgroup `H` along the group homomorphism `f` is also a subgroup * `subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` * `monoid_hom.range f` : the range of the group homomorphism `f` is a subgroup * `monoid_hom.ker f` : the kernel of a group homomorphism `f` is the subgroup of elements `x : G` such that `f x = 1` * `monoid_hom.eq_locus f g` : given group homomorphisms `f`, `g`, the elements of `G` such that `f x = g x` form a subgroup of `G` * `is_simple_group G` : a class indicating that a group has exactly two normal subgroups ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ open_locale big_operators variables {G : Type*} [group G] variables {A : Type*} [add_group A] section subgroup_class /-- `inv_mem_class S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/ class inv_mem_class (S G : Type*) [has_inv G] [set_like S G] := (inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s) export inv_mem_class (inv_mem) /-- `neg_mem_class S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/ class neg_mem_class (S G : Type*) [has_neg G] [set_like S G] := (neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s) export neg_mem_class (neg_mem) /-- `subgroup_class S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/ class subgroup_class (S G : Type*) [div_inv_monoid G] [set_like S G] extends submonoid_class S G := (inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s) /-- `add_subgroup_class S G` states `S` is a type of subsets `s ⊆ G` that are additive subgroups of `G`. -/ class add_subgroup_class (S G : Type*) [sub_neg_monoid G] [set_like S G] extends add_submonoid_class S G := (neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s) attribute [to_additive] inv_mem_class subgroup_class variables (M S : Type*) [div_inv_monoid M] [set_like S M] [hSM : subgroup_class S M] include hSM @[to_additive, priority 100] -- See note [lower instance priority] instance subgroup_class.to_inv_mem_class : inv_mem_class S M := { .. hSM } variables {S M} {H K : S} /-- A subgroup is closed under division. -/ @[to_additive "An additive subgroup is closed under subtraction."] theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy) @[to_additive] lemma zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K | (n : ℕ) := by { rw [zpow_coe_nat], exact pow_mem hx n } | -[1+ n] := by { rw [zpow_neg_succ_of_nat], exact inv_mem (pow_mem hx n.succ) } omit hSM variables [set_like S G] [hSG : subgroup_class S G] include hSG @[simp, to_additive] theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := ⟨λ h, inv_inv x ▸ inv_mem h, inv_mem⟩ @[to_additive] lemma div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := by rw [← inv_mem_iff, div_eq_mul_inv, div_eq_mul_inv, mul_inv_rev, inv_inv] @[simp, to_additive] lemma exists_inv_mem_iff_exists_mem {P : G → Prop} : (∃ (x : G), x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by split; { rintros ⟨x, x_in, hx⟩, exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩ } @[to_additive] lemma mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := ⟨λ hba, by simpa using mul_mem hba (inv_mem h), λ hb, mul_mem hb h⟩ @[to_additive] lemma mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := ⟨λ hab, by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩ namespace subgroup_class omit hSG include hSM /-- A subgroup of a group inherits an inverse. -/ @[to_additive "An additive subgroup of a `add_group` inherits an inverse."] instance has_inv : has_inv H := ⟨λ a, ⟨a⁻¹, inv_mem a.2⟩⟩ /-- A subgroup of a group inherits a division -/ @[to_additive "An additive subgroup of an `add_group` inherits a subtraction."] instance has_div : has_div H := ⟨λ a b, ⟨a / b, div_mem a.2 b.2⟩⟩ omit hSM /-- An additive subgroup of an `add_group` inherits an integer scaling. -/ instance _root_.add_subgroup_class.has_zsmul {M S} [sub_neg_monoid M] [set_like S M] [add_subgroup_class S M] {H : S} : has_smul ℤ H := ⟨λ n a, ⟨n • a, zsmul_mem a.2 n⟩⟩ include hSM /-- A subgroup of a group inherits an integer power. -/ @[to_additive] instance has_zpow : has_pow H ℤ := ⟨λ a n, ⟨a ^ n, zpow_mem a.2 n⟩⟩ @[simp, norm_cast, to_additive] lemma coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : M) := rfl @[simp, norm_cast, to_additive] lemma coe_div (x y : H) : (↑(x / y) : M) = ↑x / ↑y := rfl omit hSM variables (H) include hSG /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An additive subgroup of an `add_group` inherits an `add_group` structure.", priority 75] -- Prefer subclasses of `group` over subclasses of `subgroup_class`. instance to_group : group H := subtype.coe_injective.group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) omit hSG /-- A subgroup of a `comm_group` is a `comm_group`. -/ @[to_additive "An additive subgroup of an `add_comm_group` is an `add_comm_group`.", priority 75] -- Prefer subclasses of `comm_group` over subclasses of `subgroup_class`. instance to_comm_group {G : Type*} [comm_group G] [set_like S G] [subgroup_class S G] : comm_group H := subtype.coe_injective.comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- A subgroup of an `ordered_comm_group` is an `ordered_comm_group`. -/ @[to_additive "An additive subgroup of an `add_ordered_comm_group` is an `add_ordered_comm_group`.", priority 75] -- Prefer subclasses of `group` over subclasses of `subgroup_class`. instance to_ordered_comm_group {G : Type*} [ordered_comm_group G] [set_like S G] [subgroup_class S G] : ordered_comm_group H := subtype.coe_injective.ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- A subgroup of a `linear_ordered_comm_group` is a `linear_ordered_comm_group`. -/ @[to_additive "An additive subgroup of a `linear_ordered_add_comm_group` is a `linear_ordered_add_comm_group`.", priority 75] -- Prefer subclasses of `group` over subclasses of `subgroup_class`. instance to_linear_ordered_comm_group {G : Type*} [linear_ordered_comm_group G] [set_like S G] [subgroup_class S G] : linear_ordered_comm_group H := subtype.coe_injective.linear_ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) include hSG /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an additive subgroup of `add_group` `G` to `G`."] def subtype : H →* G := ⟨coe, rfl, λ _ _, rfl⟩ @[simp, to_additive] theorem coe_subtype : (subtype H : H → G) = coe := rfl variables {H} @[simp, norm_cast, to_additive coe_smul] lemma coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = x ^ n := (subtype H : H →* G).map_pow _ _ @[simp, norm_cast, to_additive] lemma coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = x ^ n := (subtype H : H →* G).map_zpow _ _ /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from a additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : S} (h : H ≤ K) : H →* K := monoid_hom.mk' (λ x, ⟨x, h x.prop⟩) (λ ⟨a, ha⟩ ⟨b, hb⟩, rfl) @[simp, to_additive] lemma inclusion_self (x : H) : inclusion le_rfl x = x := by { cases x, refl } @[simp, to_additive] lemma inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ := rfl @[to_additive] lemma inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by { cases x, refl } @[simp] lemma inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) : inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by { cases x, refl } @[simp, to_additive] lemma coe_inclusion {H K : S} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by { cases a, simp only [inclusion, set_like.coe_mk, monoid_hom.mk'_apply] } @[simp, to_additive] lemma subtype_comp_inclusion {H K : S} (hH : H ≤ K) : (subtype K).comp (inclusion hH) = subtype H := by { ext, simp only [monoid_hom.comp_apply, coe_subtype, coe_inclusion] } end subgroup_class end subgroup_class set_option old_structure_cmd true /-- A subgroup of a group `G` is a subset containing 1, closed under multiplication and closed under multiplicative inverse. -/ structure subgroup (G : Type*) [group G] extends submonoid G := (inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier) /-- An additive subgroup of an additive group `G` is a subset containing 0, closed under addition and additive inverse. -/ structure add_subgroup (G : Type*) [add_group G] extends add_submonoid G:= (neg_mem' {x} : x ∈ carrier → -x ∈ carrier) attribute [to_additive] subgroup attribute [to_additive add_subgroup.to_add_submonoid] subgroup.to_submonoid /-- Reinterpret a `subgroup` as a `submonoid`. -/ add_decl_doc subgroup.to_submonoid /-- Reinterpret an `add_subgroup` as an `add_submonoid`. -/ add_decl_doc add_subgroup.to_add_submonoid namespace subgroup @[to_additive] instance : set_like (subgroup G) G := { coe := subgroup.carrier, coe_injective' := λ p q h, by cases p; cases q; congr' } @[to_additive] instance : subgroup_class (subgroup G) G := { mul_mem := subgroup.mul_mem', one_mem := subgroup.one_mem', inv_mem := subgroup.inv_mem' } @[simp, to_additive] lemma mem_carrier {s : subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s := iff.rfl @[simp, to_additive] lemma mem_mk {s : set G} {x : G} (h_one) (h_mul) (h_inv) : x ∈ mk s h_one h_mul h_inv ↔ x ∈ s := iff.rfl @[simp, to_additive] lemma coe_set_mk {s : set G} (h_one) (h_mul) (h_inv) : (mk s h_one h_mul h_inv : set G) = s := rfl @[simp, to_additive] lemma mk_le_mk {s t : set G} (h_one) (h_mul) (h_inv) (h_one') (h_mul') (h_inv') : mk s h_one h_mul h_inv ≤ mk t h_one' h_mul' h_inv' ↔ s ⊆ t := iff.rfl /-- See Note [custom simps projection] -/ @[to_additive "See Note [custom simps projection]"] def simps.coe (S : subgroup G) : set G := S initialize_simps_projections subgroup (carrier → coe) initialize_simps_projections add_subgroup (carrier → coe) @[simp, to_additive] lemma coe_to_submonoid (K : subgroup G) : (K.to_submonoid : set G) = K := rfl @[simp, to_additive] lemma mem_to_submonoid (K : subgroup G) (x : G) : x ∈ K.to_submonoid ↔ x ∈ K := iff.rfl @[to_additive] instance (K : subgroup G) [d : decidable_pred (∈ K)] [fintype G] : fintype K := show fintype {g : G // g ∈ K}, from infer_instance @[to_additive] instance (K : subgroup G) [finite G] : finite K := subtype.finite @[to_additive] theorem to_submonoid_injective : function.injective (to_submonoid : subgroup G → submonoid G) := λ p q h, set_like.ext'_iff.2 (show _, from set_like.ext'_iff.1 h) @[simp, to_additive] theorem to_submonoid_eq {p q : subgroup G} : p.to_submonoid = q.to_submonoid ↔ p = q := to_submonoid_injective.eq_iff @[to_additive, mono] lemma to_submonoid_strict_mono : strict_mono (to_submonoid : subgroup G → submonoid G) := λ _ _, id attribute [mono] add_subgroup.to_add_submonoid_strict_mono @[to_additive, mono] lemma to_submonoid_mono : monotone (to_submonoid : subgroup G → submonoid G) := to_submonoid_strict_mono.monotone attribute [mono] add_subgroup.to_add_submonoid_mono @[simp, to_additive] lemma to_submonoid_le {p q : subgroup G} : p.to_submonoid ≤ q.to_submonoid ↔ p ≤ q := iff.rfl end subgroup /-! ### Conversion to/from `additive`/`multiplicative` -/ section mul_add /-- Supgroups of a group `G` are isomorphic to additive subgroups of `additive G`. -/ @[simps] def subgroup.to_add_subgroup : subgroup G ≃o add_subgroup (additive G) := { to_fun := λ S, { neg_mem' := λ _, S.inv_mem', ..S.to_submonoid.to_add_submonoid }, inv_fun := λ S, { inv_mem' := λ _, S.neg_mem', ..S.to_add_submonoid.to_submonoid' }, left_inv := λ x, by cases x; refl, right_inv := λ x, by cases x; refl, map_rel_iff' := λ a b, iff.rfl, } /-- Additive subgroup of an additive group `additive G` are isomorphic to subgroup of `G`. -/ abbreviation add_subgroup.to_subgroup' : add_subgroup (additive G) ≃o subgroup G := subgroup.to_add_subgroup.symm /-- Additive supgroups of an additive group `A` are isomorphic to subgroups of `multiplicative A`. -/ @[simps] def add_subgroup.to_subgroup : add_subgroup A ≃o subgroup (multiplicative A) := { to_fun := λ S, { inv_mem' := λ _, S.neg_mem', ..S.to_add_submonoid.to_submonoid }, inv_fun := λ S, { neg_mem' := λ _, S.inv_mem', ..S.to_submonoid.to_add_submonoid' }, left_inv := λ x, by cases x; refl, right_inv := λ x, by cases x; refl, map_rel_iff' := λ a b, iff.rfl, } /-- Subgroups of an additive group `multiplicative A` are isomorphic to additive subgroups of `A`. -/ abbreviation subgroup.to_add_subgroup' : subgroup (multiplicative A) ≃o add_subgroup A := add_subgroup.to_subgroup.symm end mul_add namespace subgroup variables (H K : subgroup G) /-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities.-/ @[to_additive "Copy of an additive subgroup with a new `carrier` equal to the old one. Useful to fix definitional equalities"] protected def copy (K : subgroup G) (s : set G) (hs : s = K) : subgroup G := { carrier := s, one_mem' := hs.symm ▸ K.one_mem', mul_mem' := λ _ _, hs.symm ▸ K.mul_mem', inv_mem' := λ _, hs.symm ▸ K.inv_mem' } @[simp, to_additive] lemma coe_copy (K : subgroup G) (s : set G) (hs : s = ↑K) : (K.copy s hs : set G) = s := rfl @[to_additive] lemma copy_eq (K : subgroup G) (s : set G) (hs : s = ↑K) : K.copy s hs = K := set_like.coe_injective hs /-- Two subgroups are equal if they have the same elements. -/ @[ext, to_additive "Two `add_subgroup`s are equal if they have the same elements."] theorem ext {H K : subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K := set_like.ext h /-- A subgroup contains the group's 1. -/ @[to_additive "An `add_subgroup` contains the group's 0."] protected theorem one_mem : (1 : G) ∈ H := one_mem _ /-- A subgroup is closed under multiplication. -/ @[to_additive "An `add_subgroup` is closed under addition."] protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H := mul_mem /-- A subgroup is closed under inverse. -/ @[to_additive "An `add_subgroup` is closed under inverse."] protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H := inv_mem /-- A subgroup is closed under division. -/ @[to_additive "An `add_subgroup` is closed under subtraction."] protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := div_mem hx hy @[to_additive] protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H := inv_mem_iff @[to_additive] protected lemma div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff @[to_additive] protected lemma exists_inv_mem_iff_exists_mem (K : subgroup G) {P : G → Prop} : (∃ (x : G), x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x := exists_inv_mem_iff_exists_mem @[to_additive] protected lemma mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H := mul_mem_cancel_right h @[to_additive] protected lemma mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H := mul_mem_cancel_left h /-- Product of a list of elements in a subgroup is in the subgroup. -/ @[to_additive "Sum of a list of elements in an `add_subgroup` is in the `add_subgroup`."] protected lemma list_prod_mem {l : list G} : (∀ x ∈ l, x ∈ K) → l.prod ∈ K := list_prod_mem /-- Product of a multiset of elements in a subgroup of a `comm_group` is in the subgroup. -/ @[to_additive "Sum of a multiset of elements in an `add_subgroup` of an `add_comm_group` is in the `add_subgroup`."] protected lemma multiset_prod_mem {G} [comm_group G] (K : subgroup G) (g : multiset G) : (∀ a ∈ g, a ∈ K) → g.prod ∈ K := multiset_prod_mem g @[to_additive] lemma multiset_noncomm_prod_mem (K : subgroup G) (g : multiset G) (comm) : (∀ a ∈ g, a ∈ K) → g.noncomm_prod comm ∈ K := K.to_submonoid.multiset_noncomm_prod_mem g comm /-- Product of elements of a subgroup of a `comm_group` indexed by a `finset` is in the subgroup. -/ @[to_additive "Sum of elements in an `add_subgroup` of an `add_comm_group` indexed by a `finset` is in the `add_subgroup`."] protected lemma prod_mem {G : Type*} [comm_group G] (K : subgroup G) {ι : Type*} {t : finset ι} {f : ι → G} (h : ∀ c ∈ t, f c ∈ K) : ∏ c in t, f c ∈ K := prod_mem h @[to_additive] lemma noncomm_prod_mem (K : subgroup G) {ι : Type*} {t : finset ι} {f : ι → G} (comm) : (∀ c ∈ t, f c ∈ K) → t.noncomm_prod f comm ∈ K := K.to_submonoid.noncomm_prod_mem t f comm @[to_additive add_subgroup.nsmul_mem] protected lemma pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K := pow_mem hx @[to_additive] protected lemma zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K := zpow_mem hx /-- Construct a subgroup from a nonempty set that is closed under division. -/ @[to_additive "Construct a subgroup from a nonempty set that is closed under subtraction"] def of_div (s : set G) (hsn : s.nonempty) (hs : ∀ x y ∈ s, x * y⁻¹ ∈ s) : subgroup G := have one_mem : (1 : G) ∈ s, from let ⟨x, hx⟩ := hsn in by simpa using hs x hx x hx, have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s, from λ x hx, by simpa using hs 1 one_mem x hx, { carrier := s, one_mem' := one_mem, inv_mem' := inv_mem, mul_mem' := λ x y hx hy, by simpa using hs x hx y⁻¹ (inv_mem y hy) } /-- A subgroup of a group inherits a multiplication. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits an addition."] instance has_mul : has_mul H := H.to_submonoid.has_mul /-- A subgroup of a group inherits a 1. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits a zero."] instance has_one : has_one H := H.to_submonoid.has_one /-- A subgroup of a group inherits an inverse. -/ @[to_additive "A `add_subgroup` of a `add_group` inherits an inverse."] instance has_inv : has_inv H := ⟨λ a, ⟨a⁻¹, H.inv_mem a.2⟩⟩ /-- A subgroup of a group inherits a division -/ @[to_additive "An `add_subgroup` of an `add_group` inherits a subtraction."] instance has_div : has_div H := ⟨λ a b, ⟨a / b, H.div_mem a.2 b.2⟩⟩ /-- An `add_subgroup` of an `add_group` inherits a natural scaling. -/ instance _root_.add_subgroup.has_nsmul {G} [add_group G] {H : add_subgroup G} : has_smul ℕ H := ⟨λ n a, ⟨n • a, H.nsmul_mem a.2 n⟩⟩ /-- A subgroup of a group inherits a natural power -/ @[to_additive] instance has_npow : has_pow H ℕ := ⟨λ a n, ⟨a ^ n, H.pow_mem a.2 n⟩⟩ /-- An `add_subgroup` of an `add_group` inherits an integer scaling. -/ instance _root_.add_subgroup.has_zsmul {G} [add_group G] {H : add_subgroup G} : has_smul ℤ H := ⟨λ n a, ⟨n • a, H.zsmul_mem a.2 n⟩⟩ /-- A subgroup of a group inherits an integer power -/ @[to_additive] instance has_zpow : has_pow H ℤ := ⟨λ a n, ⟨a ^ n, H.zpow_mem a.2 n⟩⟩ @[simp, norm_cast, to_additive] lemma coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y := rfl @[simp, norm_cast, to_additive] lemma coe_one : ((1 : H) : G) = 1 := rfl @[simp, norm_cast, to_additive] lemma coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) := rfl @[simp, norm_cast, to_additive] lemma coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y := rfl @[simp, norm_cast, to_additive] lemma coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x := rfl @[simp, norm_cast, to_additive] lemma coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = x ^ n := rfl @[simp, norm_cast, to_additive] lemma coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = x ^ n := rfl @[simp, to_additive] lemma mk_eq_one_iff {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := show (⟨g, h⟩ : H) = (⟨1, H.one_mem⟩ : H) ↔ g = 1, by simp /-- A subgroup of a group inherits a group structure. -/ @[to_additive "An `add_subgroup` of an `add_group` inherits an `add_group` structure."] instance to_group {G : Type*} [group G] (H : subgroup G) : group H := subtype.coe_injective.group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- A subgroup of a `comm_group` is a `comm_group`. -/ @[to_additive "An `add_subgroup` of an `add_comm_group` is an `add_comm_group`."] instance to_comm_group {G : Type*} [comm_group G] (H : subgroup G) : comm_group H := subtype.coe_injective.comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- A subgroup of an `ordered_comm_group` is an `ordered_comm_group`. -/ @[to_additive "An `add_subgroup` of an `add_ordered_comm_group` is an `add_ordered_comm_group`."] instance to_ordered_comm_group {G : Type*} [ordered_comm_group G] (H : subgroup G) : ordered_comm_group H := subtype.coe_injective.ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- A subgroup of a `linear_ordered_comm_group` is a `linear_ordered_comm_group`. -/ @[to_additive "An `add_subgroup` of a `linear_ordered_add_comm_group` is a `linear_ordered_add_comm_group`."] instance to_linear_ordered_comm_group {G : Type*} [linear_ordered_comm_group G] (H : subgroup G) : linear_ordered_comm_group H := subtype.coe_injective.linear_ordered_comm_group _ rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) (λ _ _, rfl) /-- The natural group hom from a subgroup of group `G` to `G`. -/ @[to_additive "The natural group hom from an `add_subgroup` of `add_group` `G` to `G`."] def subtype : H →* G := ⟨coe, rfl, λ _ _, rfl⟩ @[simp, to_additive] theorem coe_subtype : ⇑H.subtype = coe := rfl @[to_additive] lemma subtype_injective : function.injective (subtype H) := subtype.coe_injective @[simp, norm_cast, to_additive] theorem coe_list_prod (l : list H) : (l.prod : G) = (l.map coe).prod := submonoid_class.coe_list_prod l @[simp, norm_cast, to_additive] theorem coe_multiset_prod {G} [comm_group G] (H : subgroup G) (m : multiset H) : (m.prod : G) = (m.map coe).prod := submonoid_class.coe_multiset_prod m @[simp, norm_cast, to_additive] theorem coe_finset_prod {ι G} [comm_group G] (H : subgroup G) (f : ι → H) (s : finset ι) : ↑(∏ i in s, f i) = (∏ i in s, f i : G) := submonoid_class.coe_finset_prod f s /-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/ @[to_additive "The inclusion homomorphism from a additive subgroup `H` contained in `K` to `K`."] def inclusion {H K : subgroup G} (h : H ≤ K) : H →* K := monoid_hom.mk' (λ x, ⟨x, h x.prop⟩) (λ ⟨a, ha⟩ ⟨b, hb⟩, rfl) @[simp, to_additive] lemma coe_inclusion {H K : subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by { cases a, simp only [inclusion, coe_mk, monoid_hom.mk'_apply] } @[to_additive] lemma inclusion_injective {H K : subgroup G} (h : H ≤ K) : function.injective $ inclusion h := set.inclusion_injective h @[simp, to_additive] lemma subtype_comp_inclusion {H K : subgroup G} (hH : H ≤ K) : K.subtype.comp (inclusion hH) = H.subtype := rfl /-- The subgroup `G` of the group `G`. -/ @[to_additive "The `add_subgroup G` of the `add_group G`."] instance : has_top (subgroup G) := ⟨{ inv_mem' := λ _ _, set.mem_univ _ , .. (⊤ : submonoid G) }⟩ /-- The top subgroup is isomorphic to the group. This is the group version of `submonoid.top_equiv`. -/ @[to_additive "The top additive subgroup is isomorphic to the additive group. This is the additive group version of `add_submonoid.top_equiv`.", simps] def top_equiv : (⊤ : subgroup G) ≃* G := submonoid.top_equiv /-- The trivial subgroup `{1}` of an group `G`. -/ @[to_additive "The trivial `add_subgroup` `{0}` of an `add_group` `G`."] instance : has_bot (subgroup G) := ⟨{ inv_mem' := λ _, by simp *, .. (⊥ : submonoid G) }⟩ @[to_additive] instance : inhabited (subgroup G) := ⟨⊥⟩ @[simp, to_additive] lemma mem_bot {x : G} : x ∈ (⊥ : subgroup G) ↔ x = 1 := iff.rfl @[simp, to_additive] lemma mem_top (x : G) : x ∈ (⊤ : subgroup G) := set.mem_univ x @[simp, to_additive] lemma coe_top : ((⊤ : subgroup G) : set G) = set.univ := rfl @[simp, to_additive] lemma coe_bot : ((⊥ : subgroup G) : set G) = {1} := rfl @[to_additive] instance : unique (⊥ : subgroup G) := ⟨⟨1⟩, λ g, subtype.ext g.2⟩ @[simp, to_additive] lemma top_to_submonoid : (⊤ : subgroup G).to_submonoid = ⊤ := rfl @[simp, to_additive] lemma bot_to_submonoid : (⊥ : subgroup G).to_submonoid = ⊥ := rfl @[to_additive] lemma eq_bot_iff_forall : H = ⊥ ↔ ∀ x ∈ H, x = (1 : G) := to_submonoid_injective.eq_iff.symm.trans $ submonoid.eq_bot_iff_forall _ @[to_additive] lemma eq_bot_of_subsingleton [subsingleton H] : H = ⊥ := begin rw subgroup.eq_bot_iff_forall, intros y hy, rw [← subgroup.coe_mk H y hy, subsingleton.elim (⟨y, hy⟩ : H) 1, subgroup.coe_one], end @[to_additive] lemma coe_eq_univ {H : subgroup G} : (H : set G) = set.univ ↔ H = ⊤ := (set_like.ext'_iff.trans (by refl)).symm @[to_additive] lemma coe_eq_singleton {H : subgroup G} : (∃ g : G, (H : set G) = {g}) ↔ H = ⊥ := ⟨λ ⟨g, hg⟩, by { haveI : subsingleton (H : set G) := by { rw hg, apply_instance }, exact H.eq_bot_of_subsingleton }, λ h, ⟨1, set_like.ext'_iff.mp h⟩⟩ @[to_additive] instance fintype_bot : fintype (⊥ : subgroup G) := ⟨{1}, by {rintro ⟨x, ⟨hx⟩⟩, exact finset.mem_singleton_self _}⟩ /- curly brackets `{}` are used here instead of instance brackets `[]` because the instance in a goal is often not the same as the one inferred by type class inference. -/ @[simp, to_additive] lemma card_bot {_ : fintype ↥(⊥ : subgroup G)} : fintype.card (⊥ : subgroup G) = 1 := fintype.card_eq_one_iff.2 ⟨⟨(1 : G), set.mem_singleton 1⟩, λ ⟨y, hy⟩, subtype.eq $ subgroup.mem_bot.1 hy⟩ @[to_additive] lemma eq_top_of_card_eq [fintype H] [fintype G] (h : fintype.card H = fintype.card G) : H = ⊤ := begin haveI : fintype (H : set G) := ‹fintype H›, rw [set_like.ext'_iff, coe_top, ← finset.coe_univ, ← (H : set G).coe_to_finset, finset.coe_inj, ← finset.card_eq_iff_eq_univ, ← h, set.to_finset_card], congr end @[to_additive] lemma eq_top_of_le_card [fintype H] [fintype G] (h : fintype.card G ≤ fintype.card H) : H = ⊤ := eq_top_of_card_eq H (le_antisymm (fintype.card_le_of_injective coe subtype.coe_injective) h) @[to_additive] lemma eq_bot_of_card_le [fintype H] (h : fintype.card H ≤ 1) : H = ⊥ := let _ := fintype.card_le_one_iff_subsingleton.mp h in by exactI eq_bot_of_subsingleton H @[to_additive] lemma eq_bot_of_card_eq [fintype H] (h : fintype.card H = 1) : H = ⊥ := H.eq_bot_of_card_le (le_of_eq h) @[to_additive] lemma nontrivial_iff_exists_ne_one (H : subgroup G) : nontrivial H ↔ ∃ x ∈ H, x ≠ (1:G) := subtype.nontrivial_iff_exists_ne (λ x, x ∈ H) (1 : H) /-- A subgroup is either the trivial subgroup or nontrivial. -/ @[to_additive "A subgroup is either the trivial subgroup or nontrivial."] lemma bot_or_nontrivial (H : subgroup G) : H = ⊥ ∨ nontrivial H := begin classical, by_cases h : ∀ x ∈ H, x = (1 : G), { left, exact H.eq_bot_iff_forall.mpr h }, { right, simp only [not_forall] at h, simpa only [nontrivial_iff_exists_ne_one] } end /-- A subgroup is either the trivial subgroup or contains a non-identity element. -/ @[to_additive "A subgroup is either the trivial subgroup or contains a nonzero element."] lemma bot_or_exists_ne_one (H : subgroup G) : H = ⊥ ∨ ∃ x ∈ H, x ≠ (1:G) := begin convert H.bot_or_nontrivial, rw nontrivial_iff_exists_ne_one end @[to_additive] lemma card_le_one_iff_eq_bot [fintype H] : fintype.card H ≤ 1 ↔ H = ⊥ := ⟨λ h, (eq_bot_iff_forall _).2 (λ x hx, by simpa [subtype.ext_iff] using fintype.card_le_one_iff.1 h ⟨x, hx⟩ 1), λ h, by simp [h]⟩ @[to_additive] lemma one_lt_card_iff_ne_bot [fintype H] : 1 < fintype.card H ↔ H ≠ ⊥ := lt_iff_not_le.trans H.card_le_one_iff_eq_bot.not /-- The inf of two subgroups is their intersection. -/ @[to_additive "The inf of two `add_subgroups`s is their intersection."] instance : has_inf (subgroup G) := ⟨λ H₁ H₂, { inv_mem' := λ _ ⟨hx, hx'⟩, ⟨H₁.inv_mem hx, H₂.inv_mem hx'⟩, .. H₁.to_submonoid ⊓ H₂.to_submonoid }⟩ @[simp, to_additive] lemma coe_inf (p p' : subgroup G) : ((p ⊓ p' : subgroup G) : set G) = p ∩ p' := rfl @[simp, to_additive] lemma mem_inf {p p' : subgroup G} {x : G} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl @[to_additive] instance : has_Inf (subgroup G) := ⟨λ s, { inv_mem' := λ x hx, set.mem_bInter $ λ i h, i.inv_mem (by apply set.mem_Inter₂.1 hx i h), .. (⨅ S ∈ s, subgroup.to_submonoid S).copy (⋂ S ∈ s, ↑S) (by simp) }⟩ @[simp, norm_cast, to_additive] lemma coe_Inf (H : set (subgroup G)) : ((Inf H : subgroup G) : set G) = ⋂ s ∈ H, ↑s := rfl @[simp, to_additive] lemma mem_Inf {S : set (subgroup G)} {x : G} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_Inter₂ @[to_additive] lemma mem_infi {ι : Sort*} {S : ι → subgroup G} {x : G} : (x ∈ ⨅ i, S i) ↔ ∀ i, x ∈ S i := by simp only [infi, mem_Inf, set.forall_range_iff] @[simp, norm_cast, to_additive] lemma coe_infi {ι : Sort*} {S : ι → subgroup G} : (↑(⨅ i, S i) : set G) = ⋂ i, S i := by simp only [infi, coe_Inf, set.bInter_range] /-- Subgroups of a group form a complete lattice. -/ @[to_additive "The `add_subgroup`s of an `add_group` form a complete lattice."] instance : complete_lattice (subgroup G) := { bot := (⊥), bot_le := λ S x hx, (mem_bot.1 hx).symm ▸ S.one_mem, top := (⊤), le_top := λ S x hx, mem_top x, inf := (⊓), le_inf := λ a b c ha hb x hx, ⟨ha hx, hb hx⟩, inf_le_left := λ a b x, and.left, inf_le_right := λ a b x, and.right, .. complete_lattice_of_Inf (subgroup G) $ λ s, is_glb.of_image (λ H K, show (H : set G) ≤ K ↔ H ≤ K, from set_like.coe_subset_coe) is_glb_binfi } @[to_additive] lemma mem_sup_left {S T : subgroup G} : ∀ {x : G}, x ∈ S → x ∈ S ⊔ T := show S ≤ S ⊔ T, from le_sup_left @[to_additive] lemma mem_sup_right {S T : subgroup G} : ∀ {x : G}, x ∈ T → x ∈ S ⊔ T := show T ≤ S ⊔ T, from le_sup_right @[to_additive] lemma mul_mem_sup {S T : subgroup G} {x y : G} (hx : x ∈ S) (hy : y ∈ T) : x * y ∈ S ⊔ T := (S ⊔ T).mul_mem (mem_sup_left hx) (mem_sup_right hy) @[to_additive] lemma mem_supr_of_mem {ι : Sort*} {S : ι → subgroup G} (i : ι) : ∀ {x : G}, x ∈ S i → x ∈ supr S := show S i ≤ supr S, from le_supr _ _ @[to_additive] lemma mem_Sup_of_mem {S : set (subgroup G)} {s : subgroup G} (hs : s ∈ S) : ∀ {x : G}, x ∈ s → x ∈ Sup S := show s ≤ Sup S, from le_Sup hs @[simp, to_additive] lemma subsingleton_iff : subsingleton (subgroup G) ↔ subsingleton G := ⟨ λ h, by exactI ⟨λ x y, have ∀ i : G, i = 1 := λ i, mem_bot.mp $ subsingleton.elim (⊤ : subgroup G) ⊥ ▸ mem_top i, (this x).trans (this y).symm⟩, λ h, by exactI ⟨λ x y, subgroup.ext $ λ i, subsingleton.elim 1 i ▸ by simp [subgroup.one_mem]⟩⟩ @[simp, to_additive] lemma nontrivial_iff : nontrivial (subgroup G) ↔ nontrivial G := not_iff_not.mp ( (not_nontrivial_iff_subsingleton.trans subsingleton_iff).trans not_nontrivial_iff_subsingleton.symm) @[to_additive] instance [subsingleton G] : unique (subgroup G) := ⟨⟨⊥⟩, λ a, @subsingleton.elim _ (subsingleton_iff.mpr ‹_›) a _⟩ @[to_additive] instance [nontrivial G] : nontrivial (subgroup G) := nontrivial_iff.mpr ‹_› @[to_additive] lemma eq_top_iff' : H = ⊤ ↔ ∀ x : G, x ∈ H := eq_top_iff.trans ⟨λ h m, h $ mem_top m, λ h m _, h m⟩ /-- The `subgroup` generated by a set. -/ @[to_additive "The `add_subgroup` generated by a set"] def closure (k : set G) : subgroup G := Inf {K | k ⊆ K} variable {k : set G} @[to_additive] lemma mem_closure {x : G} : x ∈ closure k ↔ ∀ K : subgroup G, k ⊆ K → x ∈ K := mem_Inf /-- The subgroup generated by a set includes the set. -/ @[simp, to_additive "The `add_subgroup` generated by a set includes the set."] lemma subset_closure : k ⊆ closure k := λ x hx, mem_closure.2 $ λ K hK, hK hx @[to_additive] lemma not_mem_of_not_mem_closure {P : G} (hP : P ∉ closure k) : P ∉ k := λ h, hP (subset_closure h) open set /-- A subgroup `K` includes `closure k` if and only if it includes `k`. -/ @[simp, to_additive "An additive subgroup `K` includes `closure k` if and only if it includes `k`"] lemma closure_le : closure k ≤ K ↔ k ⊆ K := ⟨subset.trans subset_closure, λ h, Inf_le h⟩ @[to_additive] lemma closure_eq_of_le (h₁ : k ⊆ K) (h₂ : K ≤ closure k) : closure k = K := le_antisymm ((closure_le $ K).2 h₁) h₂ /-- An induction principle for closure membership. If `p` holds for `1` and all elements of `k`, and is preserved under multiplication and inverse, then `p` holds for all elements of the closure of `k`. -/ @[elab_as_eliminator, to_additive "An induction principle for additive closure membership. If `p` holds for `0` and all elements of `k`, and is preserved under addition and inverses, then `p` holds for all elements of the additive closure of `k`."] lemma closure_induction {p : G → Prop} {x} (h : x ∈ closure k) (Hk : ∀ x ∈ k, p x) (H1 : p 1) (Hmul : ∀ x y, p x → p y → p (x * y)) (Hinv : ∀ x, p x → p x⁻¹) : p x := (@closure_le _ _ ⟨p, Hmul, H1, Hinv⟩ _).2 Hk h /-- A dependent version of `subgroup.closure_induction`. -/ @[elab_as_eliminator, to_additive "A dependent version of `add_subgroup.closure_induction`. "] lemma closure_induction' {p : Π x, x ∈ closure k → Prop} (Hs : ∀ x (h : x ∈ k), p x (subset_closure h)) (H1 : p 1 (one_mem _)) (Hmul : ∀ x hx y hy, p x hx → p y hy → p (x * y) (mul_mem hx hy)) (Hinv : ∀ x hx, p x hx → p x⁻¹ (inv_mem hx)) {x} (hx : x ∈ closure k) : p x hx := begin refine exists.elim _ (λ (hx : x ∈ closure k) (hc : p x hx), hc), exact closure_induction hx (λ x hx, ⟨_, Hs x hx⟩) ⟨_, H1⟩ (λ x y ⟨hx', hx⟩ ⟨hy', hy⟩, ⟨_, Hmul _ _ _ _ hx hy⟩) (λ x ⟨hx', hx⟩, ⟨_, Hinv _ _ hx⟩), end /-- An induction principle for closure membership for predicates with two arguments. -/ @[elab_as_eliminator, to_additive "An induction principle for additive closure membership, for predicates with two arguments."] lemma closure_induction₂ {p : G → G → Prop} {x} {y : G} (hx : x ∈ closure k) (hy : y ∈ closure k) (Hk : ∀ (x ∈ k) (y ∈ k), p x y) (H1_left : ∀ x, p 1 x) (H1_right : ∀ x, p x 1) (Hmul_left : ∀ x₁ x₂ y, p x₁ y → p x₂ y → p (x₁ * x₂) y) (Hmul_right : ∀ x y₁ y₂, p x y₁ → p x y₂ → p x (y₁ * y₂)) (Hinv_left : ∀ x y, p x y → p x⁻¹ y) (Hinv_right : ∀ x y, p x y → p x y⁻¹) : p x y := closure_induction hx (λ x xk, closure_induction hy (Hk x xk) (H1_right x) (Hmul_right x) (Hinv_right x)) (H1_left y) (λ z z', Hmul_left z z' y) (λ z, Hinv_left z y) @[simp, to_additive] lemma closure_closure_coe_preimage {k : set G} : closure ((coe : closure k → G) ⁻¹' k) = ⊤ := eq_top_iff.2 $ λ x, subtype.rec_on x $ λ x hx _, begin refine closure_induction' (λ g hg, _) _ (λ g₁ g₂ hg₁ hg₂, _) (λ g hg, _) hx, { exact subset_closure hg }, { exact one_mem _ }, { exact mul_mem }, { exact inv_mem } end /-- If all the elements of a set `s` commute, then `closure s` is a commutative group. -/ @[to_additive "If all the elements of a set `s` commute, then `closure s` is an additive commutative group."] def closure_comm_group_of_comm {k : set G} (hcomm : ∀ (x ∈ k) (y ∈ k), x * y = y * x) : comm_group (closure k) := { mul_comm := λ x y, begin ext, simp only [subgroup.coe_mul], refine closure_induction₂ x.prop y.prop hcomm (λ x, by simp only [mul_one, one_mul]) (λ x, by simp only [mul_one, one_mul]) (λ x y z h₁ h₂, by rw [mul_assoc, h₂, ←mul_assoc, h₁, mul_assoc]) (λ x y z h₁ h₂, by rw [←mul_assoc, h₁, mul_assoc, h₂, ←mul_assoc]) (λ x y h, by rw [inv_mul_eq_iff_eq_mul, ←mul_assoc, h, mul_assoc, mul_inv_self, mul_one]) (λ x y h, by rw [mul_inv_eq_iff_eq_mul, mul_assoc, h, ←mul_assoc, inv_mul_self, one_mul]) end, ..(closure k).to_group } variable (G) /-- `closure` forms a Galois insertion with the coercion to set. -/ @[to_additive "`closure` forms a Galois insertion with the coercion to set."] protected def gi : galois_insertion (@closure G _) coe := { choice := λ s _, closure s, gc := λ s t, @closure_le _ _ t s, le_l_u := λ s, subset_closure, choice_eq := λ s h, rfl } variable {G} /-- Subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`. -/ @[to_additive "Additive subgroup closure of a set is monotone in its argument: if `h ⊆ k`, then `closure h ≤ closure k`"] lemma closure_mono ⦃h k : set G⦄ (h' : h ⊆ k) : closure h ≤ closure k := (subgroup.gi G).gc.monotone_l h' /-- Closure of a subgroup `K` equals `K`. -/ @[simp, to_additive "Additive closure of an additive subgroup `K` equals `K`"] lemma closure_eq : closure (K : set G) = K := (subgroup.gi G).l_u_eq K @[simp, to_additive] lemma closure_empty : closure (∅ : set G) = ⊥ := (subgroup.gi G).gc.l_bot @[simp, to_additive] lemma closure_univ : closure (univ : set G) = ⊤ := @coe_top G _ ▸ closure_eq ⊤ @[to_additive] lemma closure_union (s t : set G) : closure (s ∪ t) = closure s ⊔ closure t := (subgroup.gi G).gc.l_sup @[to_additive] lemma closure_Union {ι} (s : ι → set G) : closure (⋃ i, s i) = ⨆ i, closure (s i) := (subgroup.gi G).gc.l_supr @[to_additive] lemma closure_eq_bot_iff (G : Type*) [group G] (S : set G) : closure S = ⊥ ↔ S ⊆ {1} := by { rw [← le_bot_iff], exact closure_le _} @[to_additive] lemma supr_eq_closure {ι : Sort*} (p : ι → subgroup G) : (⨆ i, p i) = closure (⋃ i, (p i : set G)) := by simp_rw [closure_Union, closure_eq] /-- The subgroup generated by an element of a group equals the set of integer number powers of the element. -/ @[to_additive /-"The `add_subgroup` generated by an element of an `add_group` equals the set of natural number multiples of the element."-/] lemma mem_closure_singleton {x y : G} : y ∈ closure ({x} : set G) ↔ ∃ n : ℤ, x ^ n = y := begin refine ⟨λ hy, closure_induction hy _ _ _ _, λ ⟨n, hn⟩, hn ▸ zpow_mem (subset_closure $ mem_singleton x) n⟩, { intros y hy, rw [eq_of_mem_singleton hy], exact ⟨1, zpow_one x⟩ }, { exact ⟨0, zpow_zero x⟩ }, { rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩, exact ⟨n + m, zpow_add x n m⟩ }, rintros _ ⟨n, rfl⟩, exact ⟨-n, zpow_neg x n⟩ end @[to_additive] lemma closure_singleton_one : closure ({1} : set G) = ⊥ := by simp [eq_bot_iff_forall, mem_closure_singleton] @[to_additive] lemma le_closure_to_submonoid (S : set G) : submonoid.closure S ≤ (closure S).to_submonoid := submonoid.closure_le.2 subset_closure @[to_additive] lemma closure_eq_top_of_mclosure_eq_top {S : set G} (h : submonoid.closure S = ⊤) : closure S = ⊤ := (eq_top_iff' _).2 $ λ x, le_closure_to_submonoid _ $ h.symm ▸ trivial @[to_additive] lemma mem_supr_of_directed {ι} [hι : nonempty ι] {K : ι → subgroup G} (hK : directed (≤) K) {x : G} : x ∈ (supr K : subgroup G) ↔ ∃ i, x ∈ K i := begin refine ⟨_, λ ⟨i, hi⟩, (set_like.le_def.1 $ le_supr K i) hi⟩, suffices : x ∈ closure (⋃ i, (K i : set G)) → ∃ i, x ∈ K i, by simpa only [closure_Union, closure_eq (K _)] using this, refine (λ hx, closure_induction hx (λ _, mem_Union.1) _ _ _), { exact hι.elim (λ i, ⟨i, (K i).one_mem⟩) }, { rintros x y ⟨i, hi⟩ ⟨j, hj⟩, rcases hK i j with ⟨k, hki, hkj⟩, exact ⟨k, mul_mem (hki hi) (hkj hj)⟩ }, rintros _ ⟨i, hi⟩, exact ⟨i, inv_mem hi⟩ end @[to_additive] lemma coe_supr_of_directed {ι} [nonempty ι] {S : ι → subgroup G} (hS : directed (≤) S) : ((⨆ i, S i : subgroup G) : set G) = ⋃ i, ↑(S i) := set.ext $ λ x, by simp [mem_supr_of_directed hS] @[to_additive] lemma mem_Sup_of_directed_on {K : set (subgroup G)} (Kne : K.nonempty) (hK : directed_on (≤) K) {x : G} : x ∈ Sup K ↔ ∃ s ∈ K, x ∈ s := begin haveI : nonempty K := Kne.to_subtype, simp only [Sup_eq_supr', mem_supr_of_directed hK.directed_coe, set_coe.exists, subtype.coe_mk] end variables {N : Type*} [group N] {P : Type*} [group P] /-- The preimage of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The preimage of an `add_subgroup` along an `add_monoid` homomorphism is an `add_subgroup`."] def comap {N : Type*} [group N] (f : G →* N) (H : subgroup N) : subgroup G := { carrier := (f ⁻¹' H), inv_mem' := λ a ha, show f a⁻¹ ∈ H, by rw f.map_inv; exact H.inv_mem ha, .. H.to_submonoid.comap f } @[simp, to_additive] lemma coe_comap (K : subgroup N) (f : G →* N) : (K.comap f : set G) = f ⁻¹' K := rfl @[simp, to_additive] lemma mem_comap {K : subgroup N} {f : G →* N} {x : G} : x ∈ K.comap f ↔ f x ∈ K := iff.rfl @[to_additive] lemma comap_mono {f : G →* N} {K K' : subgroup N} : K ≤ K' → comap f K ≤ comap f K' := preimage_mono @[to_additive] lemma comap_comap (K : subgroup P) (g : N →* P) (f : G →* N) : (K.comap g).comap f = K.comap (g.comp f) := rfl @[simp, to_additive] lemma comap_id (K : subgroup N) : K.comap (monoid_hom.id _) = K := by { ext, refl } /-- The image of a subgroup along a monoid homomorphism is a subgroup. -/ @[to_additive "The image of an `add_subgroup` along an `add_monoid` homomorphism is an `add_subgroup`."] def map (f : G →* N) (H : subgroup G) : subgroup N := { carrier := (f '' H), inv_mem' := by { rintros _ ⟨x, hx, rfl⟩, exact ⟨x⁻¹, H.inv_mem hx, f.map_inv x⟩ }, .. H.to_submonoid.map f } @[simp, to_additive] lemma coe_map (f : G →* N) (K : subgroup G) : (K.map f : set N) = f '' K := rfl @[simp, to_additive] lemma mem_map {f : G →* N} {K : subgroup G} {y : N} : y ∈ K.map f ↔ ∃ x ∈ K, f x = y := mem_image_iff_bex @[to_additive] lemma mem_map_of_mem (f : G →* N) {K : subgroup G} {x : G} (hx : x ∈ K) : f x ∈ K.map f := mem_image_of_mem f hx @[to_additive] lemma apply_coe_mem_map (f : G →* N) (K : subgroup G) (x : K) : f x ∈ K.map f := mem_map_of_mem f x.prop @[to_additive] lemma map_mono {f : G →* N} {K K' : subgroup G} : K ≤ K' → map f K ≤ map f K' := image_subset _ @[simp, to_additive] lemma map_id : K.map (monoid_hom.id G) = K := set_like.coe_injective $ image_id _ @[to_additive] lemma map_map (g : N →* P) (f : G →* N) : (K.map f).map g = K.map (g.comp f) := set_like.coe_injective $ image_image _ _ _ @[simp, to_additive] lemma map_one_eq_bot : K.map (1 : G →* N) = ⊥ := eq_bot_iff.mpr $ by { rintros x ⟨y, _ , rfl⟩, simp } @[to_additive] lemma mem_map_equiv {f : G ≃* N} {K : subgroup G} {x : N} : x ∈ K.map f.to_monoid_hom ↔ f.symm x ∈ K := @set.mem_image_equiv _ _ ↑K f.to_equiv x @[to_additive] lemma mem_map_iff_mem {f : G →* N} (hf : function.injective f) {K : subgroup G} {x : G} : f x ∈ K.map f ↔ x ∈ K := hf.mem_set_image @[to_additive] lemma map_equiv_eq_comap_symm (f : G ≃* N) (K : subgroup G) : K.map f.to_monoid_hom = K.comap f.symm.to_monoid_hom := set_like.coe_injective (f.to_equiv.image_eq_preimage K) @[to_additive] lemma comap_equiv_eq_map_symm (f : N ≃* G) (K : subgroup G) : K.comap f.to_monoid_hom = K.map f.symm.to_monoid_hom := (map_equiv_eq_comap_symm f.symm K).symm @[to_additive] lemma map_symm_eq_iff_map_eq {H : subgroup N} {e : G ≃* N} : H.map ↑e.symm = K ↔ K.map ↑e = H := begin split; rintro rfl, { rw [map_map, ← mul_equiv.coe_monoid_hom_trans, mul_equiv.symm_trans_self, mul_equiv.coe_monoid_hom_refl, map_id] }, { rw [map_map, ← mul_equiv.coe_monoid_hom_trans, mul_equiv.self_trans_symm, mul_equiv.coe_monoid_hom_refl, map_id] }, end @[to_additive] lemma map_le_iff_le_comap {f : G →* N} {K : subgroup G} {H : subgroup N} : K.map f ≤ H ↔ K ≤ H.comap f := image_subset_iff @[to_additive] lemma gc_map_comap (f : G →* N) : galois_connection (map f) (comap f) := λ _ _, map_le_iff_le_comap @[to_additive] lemma map_sup (H K : subgroup G) (f : G →* N) : (H ⊔ K).map f = H.map f ⊔ K.map f := (gc_map_comap f).l_sup @[to_additive] lemma map_supr {ι : Sort*} (f : G →* N) (s : ι → subgroup G) : (supr s).map f = ⨆ i, (s i).map f := (gc_map_comap f).l_supr @[to_additive] lemma comap_sup_comap_le (H K : subgroup N) (f : G →* N) : comap f H ⊔ comap f K ≤ comap f (H ⊔ K) := monotone.le_map_sup (λ _ _, comap_mono) H K @[to_additive] lemma supr_comap_le {ι : Sort*} (f : G →* N) (s : ι → subgroup N) : (⨆ i, (s i).comap f) ≤ (supr s).comap f := monotone.le_map_supr (λ _ _, comap_mono) @[to_additive] lemma comap_inf (H K : subgroup N) (f : G →* N) : (H ⊓ K).comap f = H.comap f ⊓ K.comap f := (gc_map_comap f).u_inf @[to_additive] lemma comap_infi {ι : Sort*} (f : G →* N) (s : ι → subgroup N) : (infi s).comap f = ⨅ i, (s i).comap f := (gc_map_comap f).u_infi @[to_additive] lemma map_inf_le (H K : subgroup G) (f : G →* N) : map f (H ⊓ K) ≤ map f H ⊓ map f K := le_inf (map_mono inf_le_left) (map_mono inf_le_right) @[to_additive] lemma map_inf_eq (H K : subgroup G) (f : G →* N) (hf : function.injective f) : map f (H ⊓ K) = map f H ⊓ map f K := begin rw ← set_like.coe_set_eq, simp [set.image_inter hf], end @[simp, to_additive] lemma map_bot (f : G →* N) : (⊥ : subgroup G).map f = ⊥ := (gc_map_comap f).l_bot @[simp, to_additive] lemma map_top_of_surjective (f : G →* N) (h : function.surjective f) : subgroup.map f ⊤ = ⊤ := by {rw eq_top_iff, intros x hx, obtain ⟨y, hy⟩ := (h x), exact ⟨y, trivial, hy⟩ } @[simp, to_additive] lemma comap_top (f : G →* N) : (⊤ : subgroup N).comap f = ⊤ := (gc_map_comap f).u_top /-- For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`. -/ @[to_additive "For any subgroups `H` and `K`, view `H ⊓ K` as a subgroup of `K`."] def subgroup_of (H K : subgroup G) : subgroup K := H.comap K.subtype /-- If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`. -/ @[to_additive "If `H ≤ K`, then `H` as a subgroup of `K` is isomorphic to `H`.", simps] def subgroup_of_equiv_of_le {G : Type*} [group G] {H K : subgroup G} (h : H ≤ K) : H.subgroup_of K ≃* H := { to_fun := λ g, ⟨g.1, g.2⟩, inv_fun := λ g, ⟨⟨g.1, h g.2⟩, g.2⟩, left_inv := λ g, subtype.ext (subtype.ext rfl), right_inv := λ g, subtype.ext rfl, map_mul' := λ g h, rfl } @[simp, to_additive] lemma comap_subtype (H K : subgroup G) : H.comap K.subtype = H.subgroup_of K := rfl @[simp, to_additive] lemma comap_inclusion_subgroup_of {K₁ K₂ : subgroup G} (h : K₁ ≤ K₂) (H : subgroup G) : (H.subgroup_of K₂).comap (inclusion h) = H.subgroup_of K₁ := rfl @[to_additive] lemma coe_subgroup_of (H K : subgroup G) : (H.subgroup_of K : set K) = K.subtype ⁻¹' H := rfl @[to_additive] lemma mem_subgroup_of {H K : subgroup G} {h : K} : h ∈ H.subgroup_of K ↔ (h : G) ∈ H := iff.rfl @[simp, to_additive] lemma subgroup_of_map_subtype (H K : subgroup G) : (H.subgroup_of K).map K.subtype = H ⊓ K := set_like.ext' $ subtype.image_preimage_coe _ _ @[simp, to_additive] lemma bot_subgroup_of : (⊥ : subgroup G).subgroup_of H = ⊥ := eq.symm (subgroup.ext (λ g, subtype.ext_iff)) @[simp, to_additive] lemma top_subgroup_of : (⊤ : subgroup G).subgroup_of H = ⊤ := rfl @[to_additive] lemma subgroup_of_bot_eq_bot : H.subgroup_of ⊥ = ⊥ := subsingleton.elim _ _ @[to_additive] lemma subgroup_of_bot_eq_top : H.subgroup_of ⊥ = ⊤ := subsingleton.elim _ _ @[simp, to_additive] lemma subgroup_of_self : H.subgroup_of H = ⊤ := top_unique (λ g hg, g.2) @[simp, to_additive] lemma subgroup_of_inj {H₁ H₂ K : subgroup G} : H₁.subgroup_of K = H₂.subgroup_of K ↔ H₁ ⊓ K = H₂ ⊓ K := by simpa only [set_like.ext_iff, mem_inf, mem_subgroup_of, and.congr_left_iff] using subtype.forall @[simp, to_additive] lemma inf_subgroup_of_right (H K : subgroup G) : (H ⊓ K).subgroup_of K = H.subgroup_of K := subgroup_of_inj.2 inf_right_idem @[simp, to_additive] lemma inf_subgroup_of_left (H K : subgroup G) : (K ⊓ H).subgroup_of K = H.subgroup_of K := by rw [inf_comm, inf_subgroup_of_right] @[simp, to_additive] lemma subgroup_of_eq_bot {H K : subgroup G} : H.subgroup_of K = ⊥ ↔ disjoint H K := by rw [disjoint_iff, ← bot_subgroup_of, subgroup_of_inj, bot_inf_eq] @[simp, to_additive] lemma subgroup_of_eq_top {H K : subgroup G} : H.subgroup_of K = ⊤ ↔ K ≤ H := by rw [← top_subgroup_of, subgroup_of_inj, top_inf_eq, inf_eq_right] /-- Given `subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `add_subgroup`s `H`, `K` of `add_group`s `A`, `B` respectively, `H × K` as an `add_subgroup` of `A × B`."] def prod (H : subgroup G) (K : subgroup N) : subgroup (G × N) := { inv_mem' := λ _ hx, ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩, .. submonoid.prod H.to_submonoid K.to_submonoid} @[to_additive coe_prod] lemma coe_prod (H : subgroup G) (K : subgroup N) : (H.prod K : set (G × N)) = H ×ˢ K := rfl @[to_additive mem_prod] lemma mem_prod {H : subgroup G} {K : subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := iff.rfl @[to_additive prod_mono] lemma prod_mono : ((≤) ⇒ (≤) ⇒ (≤)) (@prod G _ N _) (@prod G _ N _) := λ s s' hs t t' ht, set.prod_mono hs ht @[to_additive prod_mono_right] lemma prod_mono_right (K : subgroup G) : monotone (λ t : subgroup N, K.prod t) := prod_mono (le_refl K) @[to_additive prod_mono_left] lemma prod_mono_left (H : subgroup N) : monotone (λ K : subgroup G, K.prod H) := λ s₁ s₂ hs, prod_mono hs (le_refl H) @[to_additive prod_top] lemma prod_top (K : subgroup G) : K.prod (⊤ : subgroup N) = K.comap (monoid_hom.fst G N) := ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst] @[to_additive top_prod] lemma top_prod (H : subgroup N) : (⊤ : subgroup G).prod H = H.comap (monoid_hom.snd G N) := ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd] @[simp, to_additive top_prod_top] lemma top_prod_top : (⊤ : subgroup G).prod (⊤ : subgroup N) = ⊤ := (top_prod _).trans $ comap_top _ @[to_additive] lemma bot_prod_bot : (⊥ : subgroup G).prod (⊥ : subgroup N) = ⊥ := set_like.coe_injective $ by simp [coe_prod, prod.one_eq_mk] @[to_additive le_prod_iff] lemma le_prod_iff {H : subgroup G} {K : subgroup N} {J : subgroup (G × N)} : J ≤ H.prod K ↔ map (monoid_hom.fst G N) J ≤ H ∧ map (monoid_hom.snd G N) J ≤ K := by simpa only [← subgroup.to_submonoid_le] using submonoid.le_prod_iff @[to_additive prod_le_iff] lemma prod_le_iff {H : subgroup G} {K : subgroup N} {J : subgroup (G × N)} : H.prod K ≤ J ↔ map (monoid_hom.inl G N) H ≤ J ∧ map (monoid_hom.inr G N) K ≤ J := by simpa only [← subgroup.to_submonoid_le] using submonoid.prod_le_iff @[simp, to_additive prod_eq_bot_iff] lemma prod_eq_bot_iff {H : subgroup G} {K : subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← subgroup.to_submonoid_eq] using submonoid.prod_eq_bot_iff /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prod_equiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prod_equiv (H : subgroup G) (K : subgroup N) : H.prod K ≃* H × K := { map_mul' := λ x y, rfl, .. equiv.set.prod ↑H ↑K } section pi variables {η : Type*} {f : η → Type*} -- defined here and not in group_theory.submonoid.operations to have access to algebra.group.pi /-- A version of `set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive " A version of `set.pi` for `add_submonoid`s. Given an index set `I` and a family of submodules `s : Π i, add_submonoid f i`, `pi I s` is the `add_submonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ "] def _root_.submonoid.pi [∀ i, mul_one_class (f i)] (I : set η) (s : Π i, submonoid (f i)) : submonoid (Π i, f i) := { carrier := I.pi (λ i, (s i).carrier), one_mem' := λ i _ , (s i).one_mem, mul_mem' := λ p q hp hq i hI, (s i).mul_mem (hp i hI) (hq i hI) } variables [∀ i, group (f i)] /-- A version of `set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive " A version of `set.pi` for `add_subgroup`s. Given an index set `I` and a family of submodules `s : Π i, add_subgroup f i`, `pi I s` is the `add_subgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ "] def pi (I : set η) (H : Π i, subgroup (f i)) : subgroup (Π i, f i) := { submonoid.pi I (λ i, (H i).to_submonoid) with inv_mem' := λ p hp i hI, (H i).inv_mem (hp i hI) } @[to_additive] lemma coe_pi (I : set η) (H : Π i, subgroup (f i)) : (pi I H : set (Π i, f i)) = set.pi I (λ i, (H i : set (f i))) := rfl @[to_additive] lemma mem_pi (I : set η) {H : Π i, subgroup (f i)} {p : Π i, f i} : p ∈ pi I H ↔ (∀ i : η, i ∈ I → p i ∈ H i) := iff.rfl @[to_additive] lemma pi_top (I : set η) : pi I (λ i, (⊤ : subgroup (f i))) = ⊤ := ext $ λ x, by simp [mem_pi] @[to_additive] lemma pi_empty (H : Π i, subgroup (f i)): pi ∅ H = ⊤ := ext $ λ x, by simp [mem_pi] @[to_additive] lemma pi_bot : pi set.univ (λ i, (⊥ : subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr $ λ p hp, by { simp only [mem_pi, mem_bot] at *, ext j, exact hp j trivial, } @[to_additive] lemma le_pi_iff {I : set η} {H : Π i, subgroup (f i)} {J : subgroup (Π i, f i)} : J ≤ pi I H ↔ (∀ i : η , i ∈ I → map (pi.eval_monoid_hom f i) J ≤ H i) := begin split, { intros h i hi, rintros _ ⟨x, hx, rfl⟩, exact (h hx) _ hi, }, { intros h x hx i hi, refine h i hi ⟨_, hx, rfl⟩, } end @[simp, to_additive] lemma mul_single_mem_pi [decidable_eq η] {I : set η} {H : Π i, subgroup (f i)} (i : η) (x : f i) : pi.mul_single i x ∈ pi I H ↔ (i ∈ I → x ∈ H i) := begin split, { intros h hi, simpa using h i hi, }, { intros h j hj, by_cases heq : j = i, { subst heq, simpa using h hj, }, { simp [heq, one_mem], }, } end @[to_additive] lemma pi_mem_of_mul_single_mem_aux [decidable_eq η] (I : finset η) {H : subgroup (Π i, f i) } (x : Π i, f i) (h1 : ∀ i, i ∉ I → x i = 1) (h2 : ∀ i, i ∈ I → pi.mul_single i (x i) ∈ H ) : x ∈ H := begin induction I using finset.induction_on with i I hnmem ih generalizing x, { convert one_mem H, ext i, exact (h1 i (not_mem_empty i)) }, { have : x = function.update x i 1 * pi.mul_single i (x i), { ext j, by_cases heq : j = i, { subst heq, simp, }, { simp [heq], }, }, rw this, clear this, apply mul_mem, { apply ih; clear ih, { intros j hj, by_cases heq : j = i, { subst heq, simp, }, { simp [heq], apply h1 j, simpa [heq] using hj, } }, { intros j hj, have : j ≠ i, by { rintro rfl, contradiction }, simp [this], exact h2 _ (finset.mem_insert_of_mem hj), }, }, { apply h2, simp, } } end @[to_additive] lemma pi_mem_of_mul_single_mem [finite η] [decidable_eq η] {H : subgroup (Π i, f i)} (x : Π i, f i) (h : ∀ i, pi.mul_single i (x i) ∈ H) : x ∈ H := by { casesI nonempty_fintype η, exact pi_mem_of_mul_single_mem_aux finset.univ x (by simp) (λ i _, h i) } /-- For finite index types, the `subgroup.pi` is generated by the embeddings of the groups. -/ @[to_additive "For finite index types, the `subgroup.pi` is generated by the embeddings of the additive groups."] lemma pi_le_iff [decidable_eq η] [finite η] {H : Π i, subgroup (f i)} {J : subgroup (Π i, f i)} : pi univ H ≤ J ↔ ∀ i : η, map (monoid_hom.single f i) (H i) ≤ J := begin split, { rintros h i _ ⟨x, hx, rfl⟩, apply h, simpa using hx }, { exact λ h x hx, pi_mem_of_mul_single_mem x (λ i, h i (mem_map_of_mem _ (hx i trivial))), } end @[to_additive] lemma pi_eq_bot_iff (H : Π i, subgroup (f i)) : pi set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := begin classical, simp only [eq_bot_iff_forall], split, { intros h i x hx, have : monoid_hom.single f i x = 1 := h (monoid_hom.single f i x) ((mul_single_mem_pi i x).mpr (λ _, hx)), simpa using congr_fun this i, }, { exact λ h x hx, funext (λ i, h _ _ (hx i trivial)), }, end end pi /-- A subgroup is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/ structure normal : Prop := (conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H) attribute [class] normal end subgroup namespace add_subgroup /-- An add_subgroup is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : G` -/ structure normal (H : add_subgroup A) : Prop := (conj_mem [] : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H) attribute [to_additive add_subgroup.normal] subgroup.normal attribute [class] normal end add_subgroup namespace subgroup variables {H K : subgroup G} @[priority 100, to_additive] instance normal_of_comm {G : Type*} [comm_group G] (H : subgroup G) : H.normal := ⟨by simp [mul_comm, mul_left_comm]⟩ namespace normal variable (nH : H.normal) @[to_additive] lemma mem_comm {a b : G} (h : a * b ∈ H) : b * a ∈ H := have a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H, from nH.conj_mem (a * b) h a⁻¹, by simpa @[to_additive] lemma mem_comm_iff {a b : G} : a * b ∈ H ↔ b * a ∈ H := ⟨nH.mem_comm, nH.mem_comm⟩ end normal variables (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `characteristic.iff...` -/ structure characteristic : Prop := (fixed : ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom = H) attribute [class] characteristic @[priority 100] instance normal_of_characteristic [h : H.characteristic] : H.normal := ⟨λ a ha b, (set_like.ext_iff.mp (h.fixed (mul_aut.conj b)) a).mpr ha⟩ end subgroup namespace add_subgroup variables (H : add_subgroup A) /-- A add_subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `characteristic.iff...` -/ structure characteristic : Prop := (fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.to_add_monoid_hom = H) attribute [to_additive add_subgroup.characteristic] subgroup.characteristic attribute [class] characteristic @[priority 100] instance normal_of_characteristic [h : H.characteristic] : H.normal := ⟨λ a ha b, (set_like.ext_iff.mp (h.fixed (add_aut.conj b)) a).mpr ha⟩ end add_subgroup namespace subgroup variables {H K : subgroup G} @[to_additive] lemma characteristic_iff_comap_eq : H.characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom = H := ⟨characteristic.fixed, characteristic.mk⟩ @[to_additive] lemma characteristic_iff_comap_le : H.characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.to_monoid_hom ≤ H := characteristic_iff_comap_eq.trans ⟨λ h ϕ, le_of_eq (h ϕ), λ h ϕ, le_antisymm (h ϕ) (λ g hg, h ϕ.symm ((congr_arg (∈ H) (ϕ.symm_apply_apply g)).mpr hg))⟩ @[to_additive] lemma characteristic_iff_le_comap : H.characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.to_monoid_hom := characteristic_iff_comap_eq.trans ⟨λ h ϕ, ge_of_eq (h ϕ), λ h ϕ, le_antisymm (λ g hg, (congr_arg (∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ @[to_additive] lemma characteristic_iff_map_eq : H.characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.to_monoid_hom = H := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_comap_eq.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] lemma characteristic_iff_map_le : H.characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.to_monoid_hom ≤ H := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_comap_le.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] lemma characteristic_iff_le_map : H.characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.to_monoid_hom := begin simp_rw map_equiv_eq_comap_symm, exact characteristic_iff_le_comap.trans ⟨λ h ϕ, h ϕ.symm, λ h ϕ, h ϕ.symm⟩, end @[to_additive] instance bot_characteristic : characteristic (⊥ : subgroup G) := characteristic_iff_le_map.mpr (λ ϕ, bot_le) @[to_additive] instance top_characteristic : characteristic (⊤ : subgroup G) := characteristic_iff_map_le.mpr (λ ϕ, le_top) variable (G) /-- The center of a group `G` is the set of elements that commute with everything in `G` -/ @[to_additive "The center of an additive group `G` is the set of elements that commute with everything in `G`"] def center : subgroup G := { carrier := set.center G, inv_mem' := λ a, set.inv_mem_center, .. submonoid.center G } @[to_additive] lemma coe_center : ↑(center G) = set.center G := rfl @[simp, to_additive] lemma center_to_submonoid : (center G).to_submonoid = submonoid.center G := rfl variable {G} @[to_additive] lemma mem_center_iff {z : G} : z ∈ center G ↔ ∀ g, g * z = z * g := iff.rfl instance decidable_mem_center [decidable_eq G] [fintype G] : decidable_pred (∈ center G) := λ _, decidable_of_iff' _ mem_center_iff @[to_additive] instance center_characteristic : (center G).characteristic := begin refine characteristic_iff_comap_le.mpr (λ ϕ g hg h, _), rw [←ϕ.injective.eq_iff, ϕ.map_mul, ϕ.map_mul], exact hg (ϕ h), end lemma _root_.comm_group.center_eq_top {G : Type*} [comm_group G] : center G = ⊤ := by { rw [eq_top_iff'], intros x y, exact mul_comm y x } /-- A group is commutative if the center is the whole group -/ def _root_.group.comm_group_of_center_eq_top (h : center G = ⊤) : comm_group G := { mul_comm := by { rw eq_top_iff' at h, intros x y, exact h y x }, .. (_ : group G) } variables {G} (H) section normalizer /-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/ @[to_additive "The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal."] def normalizer : subgroup G := { carrier := {g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H}, one_mem' := by simp, mul_mem' := λ a b (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n, by { rw [hb, ha], simp [mul_assoc] }, inv_mem' := λ a (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n, by { rw [ha (a⁻¹ * n * a⁻¹⁻¹)], simp [mul_assoc] } } -- variant for sets. -- TODO should this replace `normalizer`? /-- The `set_normalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/ @[to_additive "The `set_normalizer` of `S` is the subgroup of `G` whose elements satisfy `g+S-g=S`."] def set_normalizer (S : set G) : subgroup G := { carrier := {g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S}, one_mem' := by simp, mul_mem' := λ a b (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n, by { rw [hb, ha], simp [mul_assoc] }, inv_mem' := λ a (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n, by { rw [ha (a⁻¹ * n * a⁻¹⁻¹)], simp [mul_assoc] } } lemma mem_normalizer_fintype {S : set G} [finite S] {x : G} (h : ∀ n, n ∈ S → x * n * x⁻¹ ∈ S) : x ∈ subgroup.set_normalizer S := by haveI := classical.prop_decidable; casesI nonempty_fintype S; haveI := set.fintype_image S (λ n, x * n * x⁻¹); exact λ n, ⟨h n, λ h₁, have heq : (λ n, x * n * x⁻¹) '' S = S := set.eq_of_subset_of_card_le (λ n ⟨y, hy⟩, hy.2 ▸ h y hy.1) (by rw set.card_image_of_injective S conj_injective), have x * n * x⁻¹ ∈ (λ n, x * n * x⁻¹) '' S := heq.symm ▸ h₁, let ⟨y, hy⟩ := this in conj_injective hy.2 ▸ hy.1⟩ variable {H} @[to_additive] lemma mem_normalizer_iff {g : G} : g ∈ H.normalizer ↔ ∀ h, h ∈ H ↔ g * h * g⁻¹ ∈ H := iff.rfl @[to_additive] lemma mem_normalizer_iff'' {g : G} : g ∈ H.normalizer ↔ ∀ h : G, h ∈ H ↔ g⁻¹ * h * g ∈ H := by rw [←inv_mem_iff, mem_normalizer_iff, inv_inv] @[to_additive] lemma mem_normalizer_iff' {g : G} : g ∈ H.normalizer ↔ ∀ n, n * g ∈ H ↔ g * n ∈ H := ⟨λ h n, by rw [h, mul_assoc, mul_inv_cancel_right], λ h n, by rw [mul_assoc, ←h, inv_mul_cancel_right]⟩ @[to_additive] lemma le_normalizer : H ≤ normalizer H := λ x xH n, by rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH] @[priority 100, to_additive] instance normal_in_normalizer : (H.subgroup_of H.normalizer).normal := ⟨λ x xH g, by simpa using (g.2 x).1 xH⟩ @[to_additive] lemma normalizer_eq_top : H.normalizer = ⊤ ↔ H.normal := eq_top_iff.trans ⟨λ h, ⟨λ a ha b, (h (mem_top b) a).mp ha⟩, λ h a ha b, ⟨λ hb, h.conj_mem b hb a, λ hb, by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ @[to_additive] lemma center_le_normalizer : center G ≤ H.normalizer := λ x hx y, by simp [← mem_center_iff.mp hx y, mul_assoc] open_locale classical @[to_additive] lemma le_normalizer_of_normal [hK : (H.subgroup_of K).normal] (HK : H ≤ K) : K ≤ H.normalizer := λ x hx y, ⟨λ yH, hK.conj_mem ⟨y, HK yH⟩ yH ⟨x, hx⟩, λ yH, by simpa [mem_subgroup_of, mul_assoc] using hK.conj_mem ⟨x * y * x⁻¹, HK yH⟩ yH ⟨x⁻¹, K.inv_mem hx⟩⟩ variables {N : Type*} [group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] lemma le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := λ x, begin simp only [mem_normalizer_iff, mem_comap], assume h n, simp [h (f n)] end /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] lemma le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := λ _, begin simp only [and_imp, exists_prop, mem_map, exists_imp_distrib, mem_normalizer_iff], rintros x hx rfl n, split, { rintros ⟨y, hy, rfl⟩, use [x * y * x⁻¹, (hx y).1 hy], simp }, { rintros ⟨y, hyH, hy⟩, use [x⁻¹ * y * x], rw [hx], simp [hy, hyH, mul_assoc] } end variable (G) /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.normalizer_condition := ∀ (H : subgroup G), H < ⊤ → H < normalizer H variable {G} /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ lemma _root_.normalizer_condition_iff_only_full_group_self_normalizing : normalizer_condition G ↔ ∀ (H : subgroup G), H.normalizer = H → H = ⊤ := begin apply forall_congr, intro H, simp only [lt_iff_le_and_ne, le_normalizer, true_and, le_top, ne.def], tauto!, end variable (H) /-- In a group that satisifes the normalizer condition, every maximal subgroup is normal -/ lemma normalizer_condition.normal_of_coatom (hnc : normalizer_condition G) (hmax : is_coatom H) : H.normal := normalizer_eq_top.mp (hmax.2 _ (hnc H (lt_top_iff_ne_top.mpr hmax.1))) end normalizer section centralizer /-- The `centralizer` of `H` is the subgroup of `g : G` commuting with every `h : H`. -/ @[to_additive "The `centralizer` of `H` is the additive subgroup of `g : G` commuting with every `h : H`."] def centralizer : subgroup G := { carrier := set.centralizer H, inv_mem' := λ g, set.inv_mem_centralizer, .. submonoid.centralizer ↑H } variables {H} @[to_additive] lemma mem_centralizer_iff {g : G} : g ∈ H.centralizer ↔ ∀ h ∈ H, h * g = g * h := iff.rfl @[to_additive] lemma mem_centralizer_iff_commutator_eq_one {g : G} : g ∈ H.centralizer ↔ ∀ h ∈ H, h * g * h⁻¹ * g⁻¹ = 1 := by simp only [mem_centralizer_iff, mul_inv_eq_iff_eq_mul, one_mul] @[to_additive] lemma centralizer_top : centralizer ⊤ = center G := set_like.ext' (set.centralizer_univ G) @[to_additive] lemma le_centralizer_iff : H ≤ K.centralizer ↔ K ≤ H.centralizer := ⟨λ h x hx y hy, (h hy x hx).symm, λ h x hx y hy, (h hy x hx).symm⟩ @[to_additive] lemma centralizer_le (h : H ≤ K) : centralizer K ≤ centralizer H := submonoid.centralizer_le h @[to_additive] instance subgroup.centralizer.characteristic [hH : H.characteristic] : H.centralizer.characteristic := begin refine subgroup.characteristic_iff_comap_le.mpr (λ ϕ g hg h hh, ϕ.injective _), rw [map_mul, map_mul], exact hg (ϕ h) (subgroup.characteristic_iff_le_comap.mp hH ϕ hh), end end centralizer /-- Commutivity of a subgroup -/ structure is_commutative : Prop := (is_comm : _root_.is_commutative H (*)) attribute [class] is_commutative /-- Commutivity of an additive subgroup -/ structure _root_.add_subgroup.is_commutative (H : add_subgroup A) : Prop := (is_comm : _root_.is_commutative H (+)) attribute [to_additive add_subgroup.is_commutative] subgroup.is_commutative attribute [class] add_subgroup.is_commutative /-- A commutative subgroup is commutative. -/ @[to_additive "A commutative subgroup is commutative."] instance is_commutative.comm_group [h : H.is_commutative] : comm_group H := { mul_comm := h.is_comm.comm, .. H.to_group } instance center.is_commutative : (center G).is_commutative := ⟨⟨λ a b, subtype.ext (b.2 a)⟩⟩ @[to_additive] instance map_is_commutative {G' : Type*} [group G'] (f : G →* G') [H.is_commutative] : (H.map f).is_commutative := ⟨⟨begin rintros ⟨-, a, ha, rfl⟩ ⟨-, b, hb, rfl⟩, rw [subtype.ext_iff, coe_mul, coe_mul, subtype.coe_mk, subtype.coe_mk, ←map_mul, ←map_mul], exact congr_arg f (subtype.ext_iff.mp (mul_comm ⟨a, ha⟩ ⟨b, hb⟩)), end⟩⟩ @[to_additive] lemma comap_injective_is_commutative {G' : Type*} [group G'] {f : G' →* G} (hf : function.injective f) [H.is_commutative] : (H.comap f).is_commutative := ⟨⟨λ a b, subtype.ext begin have := mul_comm (⟨f a, a.2⟩ : H) (⟨f b, b.2⟩ : H), rwa [subtype.ext_iff, coe_mul, coe_mul, coe_mk, coe_mk, ←map_mul, ←map_mul, hf.eq_iff] at this, end⟩⟩ @[to_additive] instance subgroup_of_is_commutative [H.is_commutative] : (H.subgroup_of K).is_commutative := H.comap_injective_is_commutative subtype.coe_injective @[to_additive] lemma le_centralizer_iff_is_commutative : K ≤ K.centralizer ↔ K.is_commutative := ⟨λ h, ⟨⟨λ x y, subtype.ext (h y.2 x x.2)⟩⟩, λ h x hx y hy, congr_arg coe (h.1.1 ⟨y, hy⟩ ⟨x, hx⟩)⟩ @[to_additive] lemma le_centralizer [h : H.is_commutative] : H ≤ H.centralizer := le_centralizer_iff_is_commutative.mpr h end subgroup namespace group variables {s : set G} /-- Given a set `s`, `conjugates_of_set s` is the set of all conjugates of the elements of `s`. -/ def conjugates_of_set (s : set G) : set G := ⋃ a ∈ s, conjugates_of a lemma mem_conjugates_of_set_iff {x : G} : x ∈ conjugates_of_set s ↔ ∃ a ∈ s, is_conj a x := set.mem_Union₂ theorem subset_conjugates_of_set : s ⊆ conjugates_of_set s := λ (x : G) (h : x ∈ s), mem_conjugates_of_set_iff.2 ⟨x, h, is_conj.refl _⟩ theorem conjugates_of_set_mono {s t : set G} (h : s ⊆ t) : conjugates_of_set s ⊆ conjugates_of_set t := set.bUnion_subset_bUnion_left h lemma conjugates_subset_normal {N : subgroup G} [tn : N.normal] {a : G} (h : a ∈ N) : conjugates_of a ⊆ N := by { rintros a hc, obtain ⟨c, rfl⟩ := is_conj_iff.1 hc, exact tn.conj_mem a h c } theorem conjugates_of_set_subset {s : set G} {N : subgroup G} [N.normal] (h : s ⊆ N) : conjugates_of_set s ⊆ N := set.Union₂_subset (λ x H, conjugates_subset_normal (h H)) /-- The set of conjugates of `s` is closed under conjugation. -/ lemma conj_mem_conjugates_of_set {x c : G} : x ∈ conjugates_of_set s → (c * x * c⁻¹ ∈ conjugates_of_set s) := λ H, begin rcases (mem_conjugates_of_set_iff.1 H) with ⟨a,h₁,h₂⟩, exact mem_conjugates_of_set_iff.2 ⟨a, h₁, h₂.trans (is_conj_iff.2 ⟨c,rfl⟩)⟩, end end group namespace subgroup open group variable {s : set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normal_closure (s : set G) : subgroup G := closure (conjugates_of_set s) theorem conjugates_of_set_subset_normal_closure : conjugates_of_set s ⊆ normal_closure s := subset_closure theorem subset_normal_closure : s ⊆ normal_closure s := set.subset.trans subset_conjugates_of_set conjugates_of_set_subset_normal_closure theorem le_normal_closure {H : subgroup G} : H ≤ normal_closure ↑H := λ _ h, subset_normal_closure h /-- The normal closure of `s` is a normal subgroup. -/ instance normal_closure_normal : (normal_closure s).normal := ⟨λ n h g, begin refine subgroup.closure_induction h (λ x hx, _) _ (λ x y ihx ihy, _) (λ x ihx, _), { exact (conjugates_of_set_subset_normal_closure (conj_mem_conjugates_of_set hx)) }, { simpa using (normal_closure s).one_mem }, { rw ← conj_mul, exact mul_mem ihx ihy }, { rw ← conj_inv, exact inv_mem ihx } end⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normal_closure_le_normal {N : subgroup G} [N.normal] (h : s ⊆ N) : normal_closure s ≤ N := begin assume a w, refine closure_induction w (λ x hx, _) _ (λ x y ihx ihy, _) (λ x ihx, _), { exact (conjugates_of_set_subset h hx) }, { exact one_mem _ }, { exact mul_mem ihx ihy }, { exact inv_mem ihx } end lemma normal_closure_subset_iff {N : subgroup G} [N.normal] : s ⊆ N ↔ normal_closure s ≤ N := ⟨normal_closure_le_normal, set.subset.trans (subset_normal_closure)⟩ theorem normal_closure_mono {s t : set G} (h : s ⊆ t) : normal_closure s ≤ normal_closure t := normal_closure_le_normal (set.subset.trans h subset_normal_closure) theorem normal_closure_eq_infi : normal_closure s = ⨅ (N : subgroup G) (_ : normal N) (hs : s ⊆ N), N := le_antisymm (le_infi (λ N, le_infi (λ hN, by exactI le_infi (normal_closure_le_normal)))) (infi_le_of_le (normal_closure s) (infi_le_of_le (by apply_instance) (infi_le_of_le subset_normal_closure le_rfl))) @[simp] theorem normal_closure_eq_self (H : subgroup G) [H.normal] : normal_closure ↑H = H := le_antisymm (normal_closure_le_normal rfl.subset) (le_normal_closure) @[simp] theorem normal_closure_idempotent : normal_closure ↑(normal_closure s) = normal_closure s := normal_closure_eq_self _ theorem closure_le_normal_closure {s : set G} : closure s ≤ normal_closure s := by simp only [subset_normal_closure, closure_le] @[simp] theorem normal_closure_closure_eq_normal_closure {s : set G} : normal_closure ↑(closure s) = normal_closure s := le_antisymm (normal_closure_le_normal closure_le_normal_closure) (normal_closure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `subgroup.normal_core_eq_supr`. -/ def normal_core (H : subgroup G) : subgroup G := { carrier := {a : G | ∀ b : G, b * a * b⁻¹ ∈ H}, one_mem' := λ a, by rw [mul_one, mul_inv_self]; exact H.one_mem, inv_mem' := λ a h b, (congr_arg (∈ H) conj_inv).mp (H.inv_mem (h b)), mul_mem' := λ a b ha hb c, (congr_arg (∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) } lemma normal_core_le (H : subgroup G) : H.normal_core ≤ H := λ a h, by { rw [←mul_one a, ←inv_one, ←one_mul a], exact h 1 } instance normal_core_normal (H : subgroup G) : H.normal_core.normal := ⟨λ a h b c, by rw [mul_assoc, mul_assoc, ←mul_inv_rev, ←mul_assoc, ←mul_assoc]; exact h (c * b)⟩ lemma normal_le_normal_core {H : subgroup G} {N : subgroup G} [hN : N.normal] : N ≤ H.normal_core ↔ N ≤ H := ⟨ge_trans H.normal_core_le, λ h_le n hn g, h_le (hN.conj_mem n hn g)⟩ lemma normal_core_mono {H K : subgroup G} (h : H ≤ K) : H.normal_core ≤ K.normal_core := normal_le_normal_core.mpr (H.normal_core_le.trans h) lemma normal_core_eq_supr (H : subgroup G) : H.normal_core = ⨆ (N : subgroup G) (_ : normal N) (hs : N ≤ H), N := le_antisymm (le_supr_of_le H.normal_core (le_supr_of_le H.normal_core_normal (le_supr_of_le H.normal_core_le le_rfl))) (supr_le (λ N, supr_le (λ hN, supr_le (by exactI normal_le_normal_core.mpr)))) @[simp] lemma normal_core_eq_self (H : subgroup G) [H.normal] : H.normal_core = H := le_antisymm H.normal_core_le (normal_le_normal_core.mpr le_rfl) @[simp] theorem normal_core_idempotent (H : subgroup G) : H.normal_core.normal_core = H.normal_core := H.normal_core.normal_core_eq_self end subgroup namespace monoid_hom variables {N : Type*} {P : Type*} [group N] [group P] (K : subgroup G) open subgroup /-- The range of a monoid homomorphism from a group is a subgroup. -/ @[to_additive "The range of an `add_monoid_hom` from an `add_group` is an `add_subgroup`."] def range (f : G →* N) : subgroup N := subgroup.copy ((⊤ : subgroup G).map f) (set.range f) (by simp [set.ext_iff]) @[to_additive] instance decidable_mem_range (f : G →* N) [fintype G] [decidable_eq N] : decidable_pred (∈ f.range) := λ x, fintype.decidable_exists_fintype @[simp, to_additive] lemma coe_range (f : G →* N) : (f.range : set N) = set.range f := rfl @[simp, to_additive] lemma mem_range {f : G →* N} {y : N} : y ∈ f.range ↔ ∃ x, f x = y := iff.rfl @[to_additive] lemma range_eq_map (f : G →* N) : f.range = (⊤ : subgroup G).map f := by ext; simp @[simp, to_additive] lemma restrict_range (f : G →* N) : (f.restrict K).range = K.map f := by simp_rw [set_like.ext_iff, mem_range, mem_map, restrict_apply, set_like.exists, subtype.coe_mk, iff_self, forall_const] /-- The canonical surjective group homomorphism `G →* f(G)` induced by a group homomorphism `G →* N`. -/ @[to_additive "The canonical surjective `add_group` homomorphism `G →+ f(G)` induced by a group homomorphism `G →+ N`."] def range_restrict (f : G →* N) : G →* f.range := cod_restrict f _ $ λ x, ⟨x, rfl⟩ @[simp, to_additive] lemma coe_range_restrict (f : G →* N) (g : G) : (f.range_restrict g : N) = f g := rfl @[to_additive] lemma coe_comp_range_restrict (f : G →* N) : (coe : f.range → N) ∘ (⇑(f.range_restrict) : G → f.range) = f := rfl @[to_additive] lemma subtype_comp_range_restrict (f : G →* N) : f.range.subtype.comp (f.range_restrict) = f := ext $ f.coe_range_restrict @[to_additive] lemma range_restrict_surjective (f : G →* N) : function.surjective f.range_restrict := λ ⟨_, g, rfl⟩, ⟨g, rfl⟩ @[to_additive] lemma map_range (g : N →* P) (f : G →* N) : f.range.map g = (g.comp f).range := by rw [range_eq_map, range_eq_map]; exact (⊤ : subgroup G).map_map g f @[to_additive] lemma range_top_iff_surjective {N} [group N] {f : G →* N} : f.range = (⊤ : subgroup N) ↔ function.surjective f := set_like.ext'_iff.trans $ iff.trans (by rw [coe_range, coe_top]) set.range_iff_surjective /-- The range of a surjective monoid homomorphism is the whole of the codomain. -/ @[to_additive "The range of a surjective `add_monoid` homomorphism is the whole of the codomain."] lemma range_top_of_surjective {N} [group N] (f : G →* N) (hf : function.surjective f) : f.range = (⊤ : subgroup N) := range_top_iff_surjective.2 hf @[simp, to_additive] lemma range_one : (1 : G →* N).range = ⊥ := set_like.ext $ λ x, by simpa using @comm _ (=) _ 1 x @[simp, to_additive] lemma _root_.subgroup.subtype_range (H : subgroup G) : H.subtype.range = H := by { rw [range_eq_map, ← set_like.coe_set_eq, coe_map, subgroup.coe_subtype], ext, simp } @[simp, to_additive] lemma _root_.subgroup.inclusion_range {H K : subgroup G} (h_le : H ≤ K) : (inclusion h_le).range = H.subgroup_of K := subgroup.ext (λ g, set.ext_iff.mp (set.range_inclusion h_le) g) @[to_additive] lemma subgroup_of_range_eq_of_le {G₁ G₂ : Type*} [group G₁] [group G₂] {K : subgroup G₂} (f : G₁ →* G₂) (h : f.range ≤ K) : f.range.subgroup_of K = (f.cod_restrict K (λ x, h ⟨x, rfl⟩)).range := begin ext k, refine exists_congr _, simp [subtype.ext_iff], end /-- Computable alternative to `monoid_hom.of_injective`. -/ @[to_additive /-"Computable alternative to `add_monoid_hom.of_injective`."-/] def of_left_inverse {f : G →* N} {g : N →* G} (h : function.left_inverse g f) : G ≃* f.range := { to_fun := f.range_restrict, inv_fun := g ∘ f.range.subtype, left_inv := h, right_inv := by { rintros ⟨x, y, rfl⟩, apply subtype.ext, rw [coe_range_restrict, function.comp_apply, subgroup.coe_subtype, subtype.coe_mk, h] }, .. f.range_restrict } @[simp, to_additive] lemma of_left_inverse_apply {f : G →* N} {g : N →* G} (h : function.left_inverse g f) (x : G) : ↑(of_left_inverse h x) = f x := rfl @[simp, to_additive] lemma of_left_inverse_symm_apply {f : G →* N} {g : N →* G} (h : function.left_inverse g f) (x : f.range) : (of_left_inverse h).symm x = g x := rfl /-- The range of an injective group homomorphism is isomorphic to its domain. -/ @[to_additive /-"The range of an injective additive group homomorphism is isomorphic to its domain."-/ ] noncomputable def of_injective {f : G →* N} (hf : function.injective f) : G ≃* f.range := (mul_equiv.of_bijective (f.cod_restrict f.range (λ x, ⟨x, rfl⟩)) ⟨λ x y h, hf (subtype.ext_iff.mp h), by { rintros ⟨x, y, rfl⟩, exact ⟨y, rfl⟩ }⟩) @[to_additive] lemma of_injective_apply {f : G →* N} (hf : function.injective f) {x : G} : ↑(of_injective hf x) = f x := rfl section ker variables {M : Type*} [mul_one_class M] /-- The multiplicative kernel of a monoid homomorphism is the subgroup of elements `x : G` such that `f x = 1` -/ @[to_additive "The additive kernel of an `add_monoid` homomorphism is the `add_subgroup` of elements such that `f x = 0`"] def ker (f : G →* M) : subgroup G := { inv_mem' := λ x (hx : f x = 1), calc f x⁻¹ = f x * f x⁻¹ : by rw [hx, one_mul] ... = 1 : by rw [← map_mul, mul_inv_self, map_one], ..f.mker } @[to_additive] lemma mem_ker (f : G →* M) {x : G} : x ∈ f.ker ↔ f x = 1 := iff.rfl @[to_additive] lemma coe_ker (f : G →* M) : (f.ker : set G) = (f : G → M) ⁻¹' {1} := rfl @[to_additive] lemma eq_iff (f : G →* M) {x y : G} : f x = f y ↔ y⁻¹ * x ∈ f.ker := begin split; intro h, { rw [mem_ker, map_mul, h, ← map_mul, inv_mul_self, map_one] }, { rw [← one_mul x, ← mul_inv_self y, mul_assoc, map_mul, f.mem_ker.1 h, mul_one] } end @[to_additive] instance decidable_mem_ker [decidable_eq M] (f : G →* M) : decidable_pred (∈ f.ker) := λ x, decidable_of_iff (f x = 1) f.mem_ker @[to_additive] lemma comap_ker (g : N →* P) (f : G →* N) : g.ker.comap f = (g.comp f).ker := rfl @[simp, to_additive] lemma comap_bot (f : G →* N) : (⊥ : subgroup N).comap f = f.ker := rfl @[simp, to_additive] lemma ker_restrict (f : G →* N) : (f.restrict K).ker = f.ker.subgroup_of K := rfl @[simp, to_additive] lemma ker_cod_restrict {S} [set_like S N] [submonoid_class S N] (f : G →* N) (s : S) (h : ∀ x, f x ∈ s) : (f.cod_restrict s h).ker = f.ker := set_like.ext $ λ x, subtype.ext_iff @[simp, to_additive] lemma ker_range_restrict (f : G →* N) : ker (range_restrict f) = ker f := ker_cod_restrict _ _ _ @[simp, to_additive] lemma ker_one : (1 : G →* M).ker = ⊤ := set_like.ext $ λ x, eq_self_iff_true _ @[to_additive] lemma ker_eq_bot_iff (f : G →* M) : f.ker = ⊥ ↔ function.injective f := ⟨λ h x y hxy, by rwa [eq_iff, h, mem_bot, inv_mul_eq_one, eq_comm] at hxy, λ h, bot_unique $ λ x hx, h (hx.trans f.map_one.symm)⟩ @[simp, to_additive] lemma _root_.subgroup.ker_subtype (H : subgroup G) : H.subtype.ker = ⊥ := H.subtype.ker_eq_bot_iff.mpr subtype.coe_injective @[simp, to_additive] lemma _root_.subgroup.ker_inclusion {H K : subgroup G} (h : H ≤ K) : (inclusion h).ker = ⊥ := (inclusion h).ker_eq_bot_iff.mpr (set.inclusion_injective h) @[to_additive] lemma prod_map_comap_prod {G' : Type*} {N' : Type*} [group G'] [group N'] (f : G →* N) (g : G' →* N') (S : subgroup N) (S' : subgroup N') : (S.prod S').comap (prod_map f g) = (S.comap f).prod (S'.comap g) := set_like.coe_injective $ set.preimage_prod_map_prod f g _ _ @[to_additive] lemma ker_prod_map {G' : Type*} {N' : Type*} [group G'] [group N'] (f : G →* N) (g : G' →* N') : (prod_map f g).ker = f.ker.prod g.ker := by rw [←comap_bot, ←comap_bot, ←comap_bot, ←prod_map_comap_prod, bot_prod_bot] @[priority 100, to_additive] instance normal_ker (f : G →* M) : f.ker.normal := ⟨λ x hx y, by rw [mem_ker, map_mul, map_mul, f.mem_ker.1 hx, mul_one, map_mul_eq_one f (mul_inv_self y)]⟩ end ker section eq_locus variables {M : Type*} [monoid M] /-- The subgroup of elements `x : G` such that `f x = g x` -/ @[to_additive "The additive subgroup of elements `x : G` such that `f x = g x`"] def eq_locus (f g : G →* M) : subgroup G := { inv_mem' := λ x, eq_on_inv f g, .. eq_mlocus f g} /-- If two monoid homomorphisms are equal on a set, then they are equal on its subgroup closure. -/ @[to_additive "If two monoid homomorphisms are equal on a set, then they are equal on its subgroup closure."] lemma eq_on_closure {f g : G →* M} {s : set G} (h : set.eq_on f g s) : set.eq_on f g (closure s) := show closure s ≤ f.eq_locus g, from (closure_le _).2 h @[to_additive] lemma eq_of_eq_on_top {f g : G →* M} (h : set.eq_on f g (⊤ : subgroup G)) : f = g := ext $ λ x, h trivial @[to_additive] lemma eq_of_eq_on_dense {s : set G} (hs : closure s = ⊤) {f g : G →* M} (h : s.eq_on f g) : f = g := eq_of_eq_on_top $ hs ▸ eq_on_closure h end eq_locus @[to_additive] lemma closure_preimage_le (f : G →* N) (s : set N) : closure (f ⁻¹' s) ≤ (closure s).comap f := (closure_le _).2 $ λ x hx, by rw [set_like.mem_coe, mem_comap]; exact subset_closure hx /-- The image under a monoid homomorphism of the subgroup generated by a set equals the subgroup generated by the image of the set. -/ @[to_additive "The image under an `add_monoid` hom of the `add_subgroup` generated by a set equals the `add_subgroup` generated by the image of the set."] lemma map_closure (f : G →* N) (s : set G) : (closure s).map f = closure (f '' s) := set.image_preimage.l_comm_of_u_comm (subgroup.gc_map_comap f) (subgroup.gi N).gc (subgroup.gi G).gc (λ t, rfl) -- this instance can't go just after the definition of `mrange` because `fintype` is -- not imported at that stage /-- The range of a finite monoid under a monoid homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` in the presence of `fintype N`. -/ @[to_additive "The range of a finite additive monoid under an additive monoid homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`."] instance fintype_mrange {M N : Type*} [monoid M] [monoid N] [fintype M] [decidable_eq N] (f : M →* N) : fintype (mrange f) := set.fintype_range f /-- The range of a finite group under a group homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`. -/ @[to_additive "The range of a finite additive group under an additive group homomorphism is finite. Note: this instance can form a diamond with `subtype.fintype` or `subgroup.fintype` in the presence of `fintype N`."] instance fintype_range [fintype G] [decidable_eq N] (f : G →* N) : fintype (range f) := set.fintype_range f end monoid_hom namespace subgroup variables {N : Type*} [group N] (H : subgroup G) @[to_additive] lemma normal.map {H : subgroup G} (h : H.normal) (f : G →* N) (hf : function.surjective f) : (H.map f).normal := begin rw [← normalizer_eq_top, ← top_le_iff, ← f.range_top_of_surjective hf, f.range_eq_map, ← normalizer_eq_top.2 h], exact le_normalizer_map _ end @[to_additive] lemma map_eq_bot_iff {f : G →* N} : H.map f = ⊥ ↔ H ≤ f.ker := (gc_map_comap f).l_eq_bot @[to_additive] lemma map_eq_bot_iff_of_injective {f : G →* N} (hf : function.injective f) : H.map f = ⊥ ↔ H = ⊥ := by rw [map_eq_bot_iff, f.ker_eq_bot_iff.mpr hf, le_bot_iff] end subgroup namespace subgroup open monoid_hom variables {N : Type*} [group N] (f : G →* N) @[to_additive] lemma map_le_range (H : subgroup G) : map f H ≤ f.range := (range_eq_map f).symm ▸ map_mono le_top @[to_additive] lemma map_subtype_le {H : subgroup G} (K : subgroup H) : K.map H.subtype ≤ H := (K.map_le_range H.subtype).trans (le_of_eq H.subtype_range) @[to_additive] lemma ker_le_comap (H : subgroup N) : f.ker ≤ comap f H := (comap_bot f) ▸ comap_mono bot_le @[to_additive] lemma map_comap_le (H : subgroup N) : map f (comap f H) ≤ H := (gc_map_comap f).l_u_le _ @[to_additive] lemma le_comap_map (H : subgroup G) : H ≤ comap f (map f H) := (gc_map_comap f).le_u_l _ @[to_additive] lemma map_comap_eq (H : subgroup N) : map f (comap f H) = f.range ⊓ H := set_like.ext' $ by rw [coe_map, coe_comap, set.image_preimage_eq_inter_range, coe_inf, coe_range, set.inter_comm] @[to_additive] lemma comap_map_eq (H : subgroup G) : comap f (map f H) = H ⊔ f.ker := begin refine le_antisymm _ (sup_le (le_comap_map _ _) (ker_le_comap _ _)), intros x hx, simp only [exists_prop, mem_map, mem_comap] at hx, rcases hx with ⟨y, hy, hy'⟩, rw ← mul_inv_cancel_left y x, exact mul_mem_sup hy (by simp [mem_ker, hy']), end @[to_additive] lemma map_comap_eq_self {f : G →* N} {H : subgroup N} (h : H ≤ f.range) : map f (comap f H) = H := by rwa [map_comap_eq, inf_eq_right] @[to_additive] lemma map_comap_eq_self_of_surjective {f : G →* N} (h : function.surjective f) (H : subgroup N) : map f (comap f H) = H := map_comap_eq_self ((range_top_of_surjective _ h).symm ▸ le_top) @[to_additive] lemma comap_le_comap_of_le_range {f : G →* N} {K L : subgroup N} (hf : K ≤ f.range) : K.comap f ≤ L.comap f ↔ K ≤ L := ⟨(map_comap_eq_self hf).ge.trans ∘ map_le_iff_le_comap.mpr, comap_mono⟩ @[to_additive] lemma comap_le_comap_of_surjective {f : G →* N} {K L : subgroup N} (hf : function.surjective f) : K.comap f ≤ L.comap f ↔ K ≤ L := comap_le_comap_of_le_range (le_top.trans (f.range_top_of_surjective hf).ge) @[to_additive] lemma comap_lt_comap_of_surjective {f : G →* N} {K L : subgroup N} (hf : function.surjective f) : K.comap f < L.comap f ↔ K < L := by simp_rw [lt_iff_le_not_le, comap_le_comap_of_surjective hf] @[to_additive] lemma comap_injective {f : G →* N} (h : function.surjective f) : function.injective (comap f) := λ K L, by simp only [le_antisymm_iff, comap_le_comap_of_surjective h, imp_self] @[to_additive] lemma comap_map_eq_self {f : G →* N} {H : subgroup G} (h : f.ker ≤ H) : comap f (map f H) = H := by rwa [comap_map_eq, sup_eq_left] @[to_additive] lemma comap_map_eq_self_of_injective {f : G →* N} (h : function.injective f) (H : subgroup G) : comap f (map f H) = H := comap_map_eq_self (((ker_eq_bot_iff _).mpr h).symm ▸ bot_le) @[to_additive] lemma map_le_map_iff_of_injective {f : G →* N} (hf : function.injective f) {H K : subgroup G} : H.map f ≤ K.map f ↔ H ≤ K := by rw [map_le_iff_le_comap, comap_map_eq_self_of_injective hf] @[simp, to_additive] lemma map_subtype_le_map_subtype {G' : subgroup G} {H K : subgroup G'} : H.map G'.subtype ≤ K.map G'.subtype ↔ H ≤ K := map_le_map_iff_of_injective subtype.coe_injective @[to_additive] lemma map_injective {f : G →* N} (h : function.injective f) : function.injective (map f) := function.left_inverse.injective $ comap_map_eq_self_of_injective h @[to_additive] lemma map_eq_comap_of_inverse {f : G →* N} {g : N →* G} (hl : function.left_inverse g f) (hr : function.right_inverse g f) (H : subgroup G) : map f H = comap g H := set_like.ext' $ by rw [coe_map, coe_comap, set.image_eq_preimage_of_inverse hl hr] /-- Given `f(A) = f(B)`, `ker f ≤ A`, and `ker f ≤ B`, deduce that `A = B`. -/ @[to_additive "Given `f(A) = f(B)`, `ker f ≤ A`, and `ker f ≤ B`, deduce that `A = B`."] lemma map_injective_of_ker_le {H K : subgroup G} (hH : f.ker ≤ H) (hK : f.ker ≤ K) (hf : map f H = map f K) : H = K := begin apply_fun comap f at hf, rwa [comap_map_eq, comap_map_eq, sup_of_le_left hH, sup_of_le_left hK] at hf, end @[to_additive] lemma closure_preimage_eq_top (s : set G) : closure ((closure s).subtype ⁻¹' s) = ⊤ := begin apply map_injective (closure s).subtype_injective, rwa [monoid_hom.map_closure, ←monoid_hom.range_eq_map, subtype_range, set.image_preimage_eq_of_subset], rw [coe_subtype, subtype.range_coe_subtype], exact subset_closure, end @[to_additive] lemma comap_sup_eq_of_le_range {H K : subgroup N} (hH : H ≤ f.range) (hK : K ≤ f.range) : comap f H ⊔ comap f K = comap f (H ⊔ K) := map_injective_of_ker_le f ((ker_le_comap f H).trans le_sup_left) (ker_le_comap f (H ⊔ K)) (by rw [map_comap_eq, map_sup, map_comap_eq, map_comap_eq, inf_eq_right.mpr hH, inf_eq_right.mpr hK, inf_eq_right.mpr (sup_le hH hK)]) @[to_additive] lemma comap_sup_eq (H K : subgroup N) (hf : function.surjective f) : comap f H ⊔ comap f K = comap f (H ⊔ K) := comap_sup_eq_of_le_range f (le_top.trans (ge_of_eq (f.range_top_of_surjective hf))) (le_top.trans (ge_of_eq (f.range_top_of_surjective hf))) @[to_additive] lemma sup_subgroup_of_eq {H K L : subgroup G} (hH : H ≤ L) (hK : K ≤ L) : H.subgroup_of L ⊔ K.subgroup_of L = (H ⊔ K).subgroup_of L := comap_sup_eq_of_le_range L.subtype (hH.trans L.subtype_range.ge) (hK.trans L.subtype_range.ge) @[to_additive] lemma codisjoint_subgroup_of_sup (H K : subgroup G) : codisjoint (H.subgroup_of (H ⊔ K)) (K.subgroup_of (H ⊔ K)) := by { rw [codisjoint_iff, sup_subgroup_of_eq, subgroup_of_self], exacts [le_sup_left, le_sup_right] } /-- A subgroup is isomorphic to its image under an injective function -/ @[to_additive "An additive subgroup is isomorphic to its image under an injective function"] noncomputable def equiv_map_of_injective (H : subgroup G) (f : G →* N) (hf : function.injective f) : H ≃* H.map f := { map_mul' := λ _ _, subtype.ext (f.map_mul _ _), ..equiv.set.image f H hf } @[simp, to_additive] lemma coe_equiv_map_of_injective_apply (H : subgroup G) (f : G →* N) (hf : function.injective f) (h : H) : (equiv_map_of_injective H f hf h : N) = f h := rfl /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] lemma comap_normalizer_eq_of_surjective (H : subgroup G) {f : N →* G} (hf : function.surjective f) : H.normalizer.comap f = (H.comap f).normalizer := le_antisymm (le_normalizer_comap f) begin assume x hx, simp only [mem_comap, mem_normalizer_iff] at *, assume n, rcases hf n with ⟨y, rfl⟩, simp [hx y] end @[to_additive] lemma comap_normalizer_eq_of_injective_of_le_range {N : Type*} [group N] (H : subgroup G) {f : N →* G} (hf : function.injective f) (h : H.normalizer ≤ f.range) : comap f H.normalizer = (comap f H).normalizer := begin apply (subgroup.map_injective hf), rw map_comap_eq_self h, apply le_antisymm, { refine (le_trans (le_of_eq _) (map_mono (le_normalizer_comap _))), rewrite map_comap_eq_self h, }, { refine (le_trans (le_normalizer_map f) (le_of_eq _)), rewrite map_comap_eq_self (le_trans le_normalizer h), } end @[to_additive] lemma subgroup_of_normalizer_eq {H N : subgroup G} (h : H.normalizer ≤ N) : H.normalizer.subgroup_of N = (H.subgroup_of N).normalizer := begin apply comap_normalizer_eq_of_injective_of_le_range, exact subtype.coe_injective, simpa, end /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] lemma map_equiv_normalizer_eq (H : subgroup G) (f : G ≃* N) : H.normalizer.map f.to_monoid_hom = (H.map f.to_monoid_hom).normalizer := begin ext x, simp only [mem_normalizer_iff, mem_map_equiv], rw [f.to_equiv.forall_congr], simp end /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] lemma map_normalizer_eq_of_bijective (H : subgroup G) {f : G →* N} (hf : function.bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (mul_equiv.of_bijective f hf) end subgroup namespace monoid_hom variables {G₁ G₂ G₃ : Type*} [group G₁] [group G₂] [group G₃] variables (f : G₁ →* G₂) (f_inv : G₂ → G₁) /-- Auxiliary definition used to define `lift_of_right_inverse` -/ @[to_additive "Auxiliary definition used to define `lift_of_right_inverse`"] def lift_of_right_inverse_aux (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) : G₂ →* G₃ := { to_fun := λ b, g (f_inv b), map_one' := hg (hf 1), map_mul' := begin intros x y, rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker], apply hg, rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul], simp only [hf _], end } @[simp, to_additive] lemma lift_of_right_inverse_aux_comp_apply (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (x : G₁) : (f.lift_of_right_inverse_aux f_inv hf g hg) (f x) = g x := begin dsimp [lift_of_right_inverse_aux], rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker], apply hg, rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one], simp only [hf _], end /-- `lift_of_right_inverse f hf g hg` is the unique group homomorphism `φ` * such that `φ.comp f = g` (`monoid_hom.lift_of_right_inverse_comp`), * where `f : G₁ →+* G₂` has a right_inverse `f_inv` (`hf`), * and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`. See `monoid_hom.eq_lift_of_right_inverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ G₂----> G₃ ∃!φ ``` -/ @[to_additive "`lift_of_right_inverse f f_inv hf g hg` is the unique additive group homomorphism `φ` * such that `φ.comp f = g` (`add_monoid_hom.lift_of_right_inverse_comp`), * where `f : G₁ →+ G₂` has a right_inverse `f_inv` (`hf`), * and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`. See `add_monoid_hom.eq_lift_of_right_inverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ G₂----> G₃ ∃!φ ```"] def lift_of_right_inverse (hf : function.right_inverse f_inv f) : {g : G₁ →* G₃ // f.ker ≤ g.ker} ≃ (G₂ →* G₃) := { to_fun := λ g, f.lift_of_right_inverse_aux f_inv hf g.1 g.2, inv_fun := λ φ, ⟨φ.comp f, λ x hx, (mem_ker _).mpr $ by simp [(mem_ker _).mp hx]⟩, left_inv := λ g, by { ext, simp only [comp_apply, lift_of_right_inverse_aux_comp_apply, subtype.coe_mk, subtype.val_eq_coe], }, right_inv := λ φ, by { ext b, simp [lift_of_right_inverse_aux, hf b], } } /-- A non-computable version of `monoid_hom.lift_of_right_inverse` for when no computable right inverse is available, that uses `function.surj_inv`. -/ @[simp, to_additive "A non-computable version of `add_monoid_hom.lift_of_right_inverse` for when no computable right inverse is available."] noncomputable abbreviation lift_of_surjective (hf : function.surjective f) : {g : G₁ →* G₃ // f.ker ≤ g.ker} ≃ (G₂ →* G₃) := f.lift_of_right_inverse (function.surj_inv hf) (function.right_inverse_surj_inv hf) @[simp, to_additive] lemma lift_of_right_inverse_comp_apply (hf : function.right_inverse f_inv f) (g : {g : G₁ →* G₃ // f.ker ≤ g.ker}) (x : G₁) : (f.lift_of_right_inverse f_inv hf g) (f x) = g x := f.lift_of_right_inverse_aux_comp_apply f_inv hf g.1 g.2 x @[simp, to_additive] lemma lift_of_right_inverse_comp (hf : function.right_inverse f_inv f) (g : {g : G₁ →* G₃ // f.ker ≤ g.ker}) : (f.lift_of_right_inverse f_inv hf g).comp f = g := monoid_hom.ext $ f.lift_of_right_inverse_comp_apply f_inv hf g @[to_additive] lemma eq_lift_of_right_inverse (hf : function.right_inverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) : h = (f.lift_of_right_inverse f_inv hf ⟨g, hg⟩) := begin simp_rw ←hh, exact ((f.lift_of_right_inverse f_inv hf).apply_symm_apply _).symm, end end monoid_hom variables {N : Type*} [group N] -- Here `H.normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] lemma subgroup.normal.comap {H : subgroup N} (hH : H.normal) (f : G →* N) : (H.comap f).normal := ⟨λ _, by simp [subgroup.mem_comap, hH.conj_mem] {contextual := tt}⟩ @[priority 100, to_additive] instance subgroup.normal_comap {H : subgroup N} [nH : H.normal] (f : G →* N) : (H.comap f).normal := nH.comap _ -- Here `H.normal` is an explicit argument so we can use dot notation with `subgroup_of`. @[to_additive] lemma subgroup.normal.subgroup_of {H : subgroup G} (hH : H.normal) (K : subgroup G) : (H.subgroup_of K).normal := hH.comap _ @[priority 100, to_additive] instance subgroup.normal_subgroup_of {H N : subgroup G} [N.normal] : (N.subgroup_of H).normal := subgroup.normal_comap _ namespace subgroup /-- The subgroup generated by an element. -/ def zpowers (g : G) : subgroup G := subgroup.copy (zpowers_hom G g).range (set.range ((^) g : ℤ → G)) rfl @[simp] lemma mem_zpowers (g : G) : g ∈ zpowers g := ⟨1, zpow_one _⟩ lemma zpowers_eq_closure (g : G) : zpowers g = closure {g} := by { ext, exact mem_closure_singleton.symm } @[simp] lemma range_zpowers_hom (g : G) : (zpowers_hom G g).range = zpowers g := rfl lemma zpowers_subset {a : G} {K : subgroup G} (h : a ∈ K) : zpowers a ≤ K := λ x hx, match x, hx with _, ⟨i, rfl⟩ := K.zpow_mem h i end lemma mem_zpowers_iff {g h : G} : h ∈ zpowers g ↔ ∃ (k : ℤ), g ^ k = h := iff.rfl @[simp] lemma zpow_mem_zpowers (g : G) (k : ℤ) : g^k ∈ zpowers g := mem_zpowers_iff.mpr ⟨k, rfl⟩ @[simp] lemma npow_mem_zpowers (g : G) (k : ℕ) : g^k ∈ zpowers g := (zpow_coe_nat g k) ▸ zpow_mem_zpowers g k @[simp] lemma forall_zpowers {x : G} {p : zpowers x → Prop} : (∀ g, p g) ↔ ∀ m : ℤ, p ⟨x ^ m, m, rfl⟩ := set.forall_subtype_range_iff @[simp] lemma exists_zpowers {x : G} {p : zpowers x → Prop} : (∃ g, p g) ↔ ∃ m : ℤ, p ⟨x ^ m, m, rfl⟩ := set.exists_subtype_range_iff lemma forall_mem_zpowers {x : G} {p : G → Prop} : (∀ g ∈ zpowers x, p g) ↔ ∀ m : ℤ, p (x ^ m) := set.forall_range_iff lemma exists_mem_zpowers {x : G} {p : G → Prop} : (∃ g ∈ zpowers x, p g) ↔ ∃ m : ℤ, p (x ^ m) := set.exists_range_iff instance (a : G) : countable (zpowers a) := ((zpowers_hom G a).range_restrict_surjective.comp multiplicative.of_add.surjective).countable end subgroup namespace add_subgroup /-- The subgroup generated by an element. -/ def zmultiples (a : A) : add_subgroup A := add_subgroup.copy (zmultiples_hom A a).range (set.range ((• a) : ℤ → A)) rfl @[simp] lemma range_zmultiples_hom (a : A) : (zmultiples_hom A a).range = zmultiples a := rfl attribute [to_additive add_subgroup.zmultiples] subgroup.zpowers attribute [to_additive add_subgroup.mem_zmultiples] subgroup.mem_zpowers attribute [to_additive add_subgroup.zmultiples_eq_closure] subgroup.zpowers_eq_closure attribute [to_additive add_subgroup.range_zmultiples_hom] subgroup.range_zpowers_hom attribute [to_additive add_subgroup.zmultiples_subset] subgroup.zpowers_subset attribute [to_additive add_subgroup.mem_zmultiples_iff] subgroup.mem_zpowers_iff attribute [to_additive add_subgroup.zsmul_mem_zmultiples] subgroup.zpow_mem_zpowers attribute [to_additive add_subgroup.nsmul_mem_zmultiples] subgroup.npow_mem_zpowers attribute [to_additive add_subgroup.forall_zmultiples] subgroup.forall_zpowers attribute [to_additive add_subgroup.forall_mem_zmultiples] subgroup.forall_mem_zpowers attribute [to_additive add_subgroup.exists_zmultiples] subgroup.exists_zpowers attribute [to_additive add_subgroup.exists_mem_zmultiples] subgroup.exists_mem_zpowers instance (a : A) : countable (zmultiples a) := (zmultiples_hom A a).range_restrict_surjective.countable section ring variables {R : Type*} [ring R] (r : R) (k : ℤ) @[simp] lemma int_cast_mul_mem_zmultiples : ↑(k : ℤ) * r ∈ zmultiples r := by simpa only [← zsmul_eq_mul] using zsmul_mem_zmultiples r k @[simp] lemma int_cast_mem_zmultiples_one : ↑(k : ℤ) ∈ zmultiples (1 : R) := mem_zmultiples_iff.mp ⟨k, by simp⟩ end ring end add_subgroup lemma int.mem_zmultiples_iff {a b : ℤ} : b ∈ add_subgroup.zmultiples a ↔ a ∣ b := exists_congr (λ k, by rw [mul_comm, eq_comm, ← smul_eq_mul]) lemma of_mul_image_zpowers_eq_zmultiples_of_mul { x : G } : additive.of_mul '' ((subgroup.zpowers x) : set G) = add_subgroup.zmultiples (additive.of_mul x) := begin ext y, split, { rintro ⟨z, ⟨m, hm⟩, hz2⟩, use m, simp only, rwa [← of_mul_zpow, hm] }, { rintros ⟨n, hn⟩, refine ⟨x ^ n, ⟨n, rfl⟩, _⟩, rwa of_mul_zpow } end lemma of_add_image_zmultiples_eq_zpowers_of_add {x : A} : multiplicative.of_add '' ((add_subgroup.zmultiples x) : set A) = subgroup.zpowers (multiplicative.of_add x) := begin symmetry, rw equiv.eq_image_iff_symm_image_eq, exact of_mul_image_zpowers_eq_zmultiples_of_mul, end namespace subgroup @[to_additive zmultiples_is_commutative] instance zpowers_is_commutative (g : G) : (zpowers g).is_commutative := ⟨⟨λ ⟨_, _, h₁⟩ ⟨_, _, h₂⟩, by rw [subtype.ext_iff, coe_mul, coe_mul, subtype.coe_mk, subtype.coe_mk, ←h₁, ←h₂, zpow_mul_comm]⟩⟩ @[simp, to_additive zmultiples_le] lemma zpowers_le {g : G} {H : subgroup G} : zpowers g ≤ H ↔ g ∈ H := by rw [zpowers_eq_closure, closure_le, set.singleton_subset_iff, set_like.mem_coe] @[simp, to_additive zmultiples_eq_bot] lemma zpowers_eq_bot {g : G} : zpowers g = ⊥ ↔ g = 1 := by rw [eq_bot_iff, zpowers_le, mem_bot] @[simp, to_additive zmultiples_zero_eq_bot] lemma zpowers_one_eq_bot : subgroup.zpowers (1 : G) = ⊥ := subgroup.zpowers_eq_bot.mpr rfl @[to_additive] lemma centralizer_closure (S : set G) : (closure S).centralizer = ⨅ g ∈ S, (zpowers g).centralizer := le_antisymm (le_infi $ λ g, le_infi $ λ hg, centralizer_le $ zpowers_le.2 $ subset_closure hg) $ le_centralizer_iff.1 $ (closure_le _).2 $ λ g, set_like.mem_coe.2 ∘ zpowers_le.1 ∘ le_centralizer_iff.1 ∘ infi_le_of_le g ∘ infi_le _ @[to_additive] lemma center_eq_infi (S : set G) (hS : closure S = ⊤) : center G = ⨅ g ∈ S, centralizer (zpowers g) := by rw [←centralizer_top, ←hS, centralizer_closure] @[to_additive] lemma center_eq_infi' (S : set G) (hS : closure S = ⊤) : center G = ⨅ g : S, centralizer (zpowers g) := by rw [center_eq_infi S hS, ←infi_subtype''] end subgroup namespace monoid_hom variables {G' : Type*} [group G'] /-- The `monoid_hom` from the preimage of a subgroup to itself. -/ @[to_additive "the `add_monoid_hom` from the preimage of an additive subgroup to itself.", simps] def subgroup_comap (f : G →* G') (H' : subgroup G') : H'.comap f →* H' := f.submonoid_comap H'.to_submonoid /-- The `monoid_hom` from a subgroup to its image. -/ @[to_additive "the `add_monoid_hom` from an additive subgroup to its image", simps] def subgroup_map (f : G →* G') (H : subgroup G) : H →* H.map f := f.submonoid_map H.to_submonoid @[to_additive] lemma subgroup_map_surjective (f : G →* G') (H : subgroup G) : function.surjective (f.subgroup_map H) := f.submonoid_map_surjective H.to_submonoid end monoid_hom namespace mul_equiv variables {H K : subgroup G} /-- Makes the identity isomorphism from a proof two subgroups of a multiplicative group are equal. -/ @[to_additive "Makes the identity additive isomorphism from a proof two subgroups of an additive group are equal."] def subgroup_congr (h : H = K) : H ≃* K := { map_mul' := λ _ _, rfl, ..equiv.set_congr $ congr_arg _ h } /-- A `mul_equiv` `φ` between two groups `G` and `G'` induces a `mul_equiv` between a subgroup `H ≤ G` and the subgroup `φ(H) ≤ G'`. -/ @[to_additive "An `add_equiv` `φ` between two additive groups `G` and `G'` induces an `add_equiv` between a subgroup `H ≤ G` and the subgroup `φ(H) ≤ G'`. "] def subgroup_map {G'} [group G'] (e : G ≃* G') (H : subgroup G) : H ≃* H.map e.to_monoid_hom := e.submonoid_map H.to_submonoid end mul_equiv -- TODO : ↥(⊤ : subgroup H) ≃* H ? namespace subgroup variables {C : Type*} [comm_group C] {s t : subgroup C} {x : C} @[to_additive] lemma mem_sup : x ∈ s ⊔ t ↔ ∃ (y ∈ s) (z ∈ t), y * z = x := ⟨λ h, begin rw [← closure_eq s, ← closure_eq t, ← closure_union] at h, apply closure_induction h, { rintro y (h | h), { exact ⟨y, h, 1, t.one_mem, by simp⟩ }, { exact ⟨1, s.one_mem, y, h, by simp⟩ } }, { exact ⟨1, s.one_mem, 1, ⟨t.one_mem, mul_one 1⟩⟩ }, { rintro _ _ ⟨y₁, hy₁, z₁, hz₁, rfl⟩ ⟨y₂, hy₂, z₂, hz₂, rfl⟩, exact ⟨_, mul_mem hy₁ hy₂, _, mul_mem hz₁ hz₂, by simp [mul_assoc]; cc⟩ }, { rintro _ ⟨y, hy, z, hz, rfl⟩, exact ⟨_, inv_mem hy, _, inv_mem hz, mul_comm z y ▸ (mul_inv_rev z y).symm⟩ } end, by rintro ⟨y, hy, z, hz, rfl⟩; exact mul_mem_sup hy hz⟩ @[to_additive] lemma mem_sup' : x ∈ s ⊔ t ↔ ∃ (y : s) (z : t), (y:C) * z = x := mem_sup.trans $ by simp only [set_like.exists, coe_mk] @[to_additive] lemma mem_closure_pair {x y z : C} : z ∈ closure ({x, y} : set C) ↔ ∃ m n : ℤ, x ^ m * y ^ n = z := begin rw [←set.singleton_union, subgroup.closure_union, mem_sup], simp_rw [exists_prop, mem_closure_singleton, exists_exists_eq_and], end @[to_additive] instance : is_modular_lattice (subgroup C) := ⟨λ x y z xz a ha, begin rw [mem_inf, mem_sup] at ha, rcases ha with ⟨⟨b, hb, c, hc, rfl⟩, haz⟩, rw mem_sup, exact ⟨b, hb, c, mem_inf.2 ⟨hc, (mul_mem_cancel_left (xz hb)).1 haz⟩, rfl⟩ end⟩ end subgroup section variables (G) (A) /-- A `group` is simple when it has exactly two normal `subgroup`s. -/ class is_simple_group extends nontrivial G : Prop := (eq_bot_or_eq_top_of_normal : ∀ H : subgroup G, H.normal → H = ⊥ ∨ H = ⊤) /-- An `add_group` is simple when it has exactly two normal `add_subgroup`s. -/ class is_simple_add_group extends nontrivial A : Prop := (eq_bot_or_eq_top_of_normal : ∀ H : add_subgroup A, H.normal → H = ⊥ ∨ H = ⊤) attribute [to_additive] is_simple_group variables {G} {A} @[to_additive] lemma subgroup.normal.eq_bot_or_eq_top [is_simple_group G] {H : subgroup G} (Hn : H.normal) : H = ⊥ ∨ H = ⊤ := is_simple_group.eq_bot_or_eq_top_of_normal H Hn namespace is_simple_group @[to_additive] instance {C : Type*} [comm_group C] [is_simple_group C] : is_simple_order (subgroup C) := ⟨λ H, H.normal_of_comm.eq_bot_or_eq_top⟩ open _root_.subgroup @[to_additive] lemma is_simple_group_of_surjective {H : Type*} [group H] [is_simple_group G] [nontrivial H] (f : G →* H) (hf : function.surjective f) : is_simple_group H := ⟨nontrivial.exists_pair_ne, λ H iH, begin refine ((iH.comap f).eq_bot_or_eq_top).imp (λ h, _) (λ h, _), { rw [←map_bot f, ←h, map_comap_eq_self_of_surjective hf] }, { rw [←comap_top f] at h, exact comap_injective hf h } end⟩ end is_simple_group end namespace subgroup section subgroup_normal @[to_additive] lemma normal_subgroup_of_iff {H K : subgroup G} (hHK : H ≤ K) : (H.subgroup_of K).normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H := ⟨λ hN h k hH hK, hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, λ hN, { conj_mem := λ h hm k, (hN h.1 k.1 hm k.2) }⟩ @[to_additive] instance prod_subgroup_of_prod_normal {H₁ K₁ : subgroup G} {H₂ K₂ : subgroup N} [h₁ : (H₁.subgroup_of K₁).normal] [h₂ : (H₂.subgroup_of K₂).normal] : ((H₁.prod H₂).subgroup_of (K₁.prod K₂)).normal := { conj_mem := λ n hgHK g, ⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩, h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩ } @[to_additive] instance prod_normal (H : subgroup G) (K : subgroup N) [hH : H.normal] [hK : K.normal] : (H.prod K).normal := { conj_mem := λ n hg g, ⟨hH.conj_mem n.fst (subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (subgroup.mem_prod.mp hg).2 g.snd⟩ } @[to_additive] lemma inf_subgroup_of_inf_normal_of_right (A B' B : subgroup G) (hB : B' ≤ B) [hN : (B'.subgroup_of B).normal] : ((A ⊓ B').subgroup_of (A ⊓ B)).normal := { conj_mem := λ n hn g, ⟨mul_mem (mul_mem (mem_inf.1 g.2).1 (mem_inf.1 n.2).1) (inv_mem (mem_inf.1 g.2).1), (normal_subgroup_of_iff hB).mp hN n g hn.2 (mem_inf.mp g.2).2⟩ } @[to_additive] lemma inf_subgroup_of_inf_normal_of_left {A' A : subgroup G} (B : subgroup G) (hA : A' ≤ A) [hN : (A'.subgroup_of A).normal] : ((A' ⊓ B).subgroup_of (A ⊓ B)).normal := { conj_mem := λ n hn g, ⟨(normal_subgroup_of_iff hA).mp hN n g hn.1 (mem_inf.mp g.2).1, mul_mem (mul_mem (mem_inf.1 g.2).2 (mem_inf.1 n.2).2) (inv_mem (mem_inf.1 g.2).2)⟩ } @[to_additive] instance normal_inf_normal (H K : subgroup G) [hH : H.normal] [hK : K.normal] : (H ⊓ K).normal := ⟨λ n hmem g, ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩ @[to_additive] lemma subgroup_of_sup (A A' B : subgroup G) (hA : A ≤ B) (hA' : A' ≤ B) : (A ⊔ A').subgroup_of B = A.subgroup_of B ⊔ A'.subgroup_of B := begin refine map_injective_of_ker_le B.subtype (ker_le_comap _ _) (le_trans (ker_le_comap B.subtype _) le_sup_left) _, { simp only [subgroup_of, map_comap_eq, map_sup, subtype_range], rw [inf_of_le_right (sup_le hA hA'), inf_of_le_right hA', inf_of_le_right hA] }, end @[to_additive] lemma subgroup_normal.mem_comm {H K : subgroup G} (hK : H ≤ K) [hN : (H.subgroup_of K).normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := begin have := (normal_subgroup_of_iff hK).mp hN (a * b) b h hb, rwa [mul_assoc, mul_assoc, mul_right_inv, mul_one] at this, end /-- Elements of disjoint, normal subgroups commute. -/ @[to_additive "Elements of disjoint, normal subgroups commute."] lemma commute_of_normal_of_disjoint (H₁ H₂ : subgroup G) (hH₁ : H₁.normal) (hH₂ : H₂.normal) (hdis : disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : commute x y := begin suffices : x * y * x⁻¹ * y⁻¹ = 1, { show x * y = y * x, by { rw [mul_assoc, mul_eq_one_iff_eq_inv] at this, simpa } }, apply hdis.le_bot, split, { suffices : x * (y * x⁻¹ * y⁻¹) ∈ H₁, by simpa [mul_assoc], exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _) }, { show x * y * x⁻¹ * y⁻¹ ∈ H₂, apply H₂.mul_mem _ (H₂.inv_mem hy), apply (hH₂.conj_mem _ hy), } end end subgroup_normal @[to_additive] lemma disjoint_def {H₁ H₂ : subgroup G} : disjoint H₁ H₂ ↔ ∀ {x : G}, x ∈ H₁ → x ∈ H₂ → x = 1 := disjoint_iff_inf_le.trans $ by simp only [disjoint, set_like.le_def, mem_inf, mem_bot, and_imp] @[to_additive] lemma disjoint_def' {H₁ H₂ : subgroup G} : disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x = y → x = 1 := disjoint_def.trans ⟨λ h x y hx hy hxy, h hx $ hxy.symm ▸ hy, λ h x hx hx', h hx hx' rfl⟩ @[to_additive] lemma disjoint_iff_mul_eq_one {H₁ H₂ : subgroup G} : disjoint H₁ H₂ ↔ ∀ {x y : G}, x ∈ H₁ → y ∈ H₂ → x * y = 1 → x = 1 ∧ y = 1 := disjoint_def'.trans ⟨λ h x y hx hy hxy, let hx1 : x = 1 := h hx (H₂.inv_mem hy) (eq_inv_iff_mul_eq_one.mpr hxy) in ⟨hx1, by simpa [hx1] using hxy⟩, λ h x y hx hy hxy, (h hx (H₂.inv_mem hy) (mul_inv_eq_one.mpr hxy)).1⟩ @[to_additive] lemma mul_injective_of_disjoint {H₁ H₂ : subgroup G} (h : disjoint H₁ H₂) : function.injective (λ g, g.1 * g.2 : H₁ × H₂ → G) := begin intros x y hxy, rw [←inv_mul_eq_iff_eq_mul, ←mul_assoc, ←mul_inv_eq_one, mul_assoc] at hxy, replace hxy := disjoint_iff_mul_eq_one.mp h (y.1⁻¹ * x.1).prop (x.2 * y.2⁻¹).prop hxy, rwa [coe_mul, coe_mul, coe_inv, coe_inv, inv_mul_eq_one, mul_inv_eq_one, ←subtype.ext_iff, ←subtype.ext_iff, eq_comm, ←prod.ext_iff] at hxy, end /-- `finset.noncomm_prod` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `subgroup.disjoint_iff_mul_eq_one`. -/ @[to_additive "`finset.noncomm_sum` is “injective” in `f` if `f` maps into independent subgroups. This generalizes (one direction of) `add_subgroup.disjoint_iff_add_eq_zero`. "] lemma eq_one_of_noncomm_prod_eq_one_of_independent {ι : Type*} (s : finset ι) (f : ι → G) (comm) (K : ι → subgroup G) (hind : complete_lattice.independent K) (hmem : ∀ (x ∈ s), f x ∈ K x) (heq1 : s.noncomm_prod f comm = 1) : ∀ (i ∈ s), f i = 1 := begin classical, revert heq1, induction s using finset.induction_on with i s hnmem ih, { simp, }, { have hcomm := comm.mono (finset.coe_subset.2 $ finset.subset_insert _ _), simp only [finset.forall_mem_insert] at hmem, have hmem_bsupr: s.noncomm_prod f hcomm ∈ ⨆ (i ∈ (s : set ι)), K i, { refine subgroup.noncomm_prod_mem _ _ _, intros x hx, have : K x ≤ ⨆ (i ∈ (s : set ι)), K i := le_supr₂ x hx, exact this (hmem.2 x hx), }, intro heq1, rw finset.noncomm_prod_insert_of_not_mem _ _ _ _ hnmem at heq1, have hnmem' : i ∉ (s : set ι), by simpa, obtain ⟨heq1i : f i = 1, heq1S : s.noncomm_prod f _ = 1⟩ := subgroup.disjoint_iff_mul_eq_one.mp (hind.disjoint_bsupr hnmem') hmem.1 hmem_bsupr heq1, intros i h, simp only [finset.mem_insert] at h, rcases h with ⟨rfl | _⟩, { exact heq1i }, { exact ih hcomm hmem.2 heq1S _ h } } end end subgroup namespace is_conj open subgroup lemma normal_closure_eq_top_of {N : subgroup G} [hn : N.normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : is_conj g g') (ht : normal_closure ({⟨g, hg⟩} : set N) = ⊤) : normal_closure ({⟨g', hg'⟩} : set N) = ⊤ := begin obtain ⟨c, rfl⟩ := is_conj_iff.1 hc, have h : ∀ x : N, (mul_aut.conj c) x ∈ N, { rintro ⟨x, hx⟩, exact hn.conj_mem _ hx c }, have hs : function.surjective (((mul_aut.conj c).to_monoid_hom.restrict N).cod_restrict _ h), { rintro ⟨x, hx⟩, refine ⟨⟨c⁻¹ * x * c, _⟩, _⟩, { have h := hn.conj_mem _ hx c⁻¹, rwa [inv_inv] at h }, simp only [monoid_hom.cod_restrict_apply, mul_equiv.coe_to_monoid_hom, mul_aut.conj_apply, coe_mk, monoid_hom.restrict_apply, subtype.mk_eq_mk, ← mul_assoc, mul_inv_self, one_mul], rw [mul_assoc, mul_inv_self, mul_one] }, have ht' := map_mono (eq_top_iff.1 ht), rw [← monoid_hom.range_eq_map, monoid_hom.range_top_of_surjective _ hs] at ht', refine eq_top_iff.2 (le_trans ht' (map_le_iff_le_comap.2 (normal_closure_le_normal _))), rw [set.singleton_subset_iff, set_like.mem_coe], simp only [monoid_hom.cod_restrict_apply, mul_equiv.coe_to_monoid_hom, mul_aut.conj_apply, coe_mk, monoid_hom.restrict_apply, mem_comap], exact subset_normal_closure (set.mem_singleton _), end end is_conj /-! ### Actions by `subgroup`s These are just copies of the definitions about `submonoid` starting from `submonoid.mul_action`. -/ section actions namespace subgroup variables {α β : Type*} /-- The action by a subgroup is the action by the underlying group. -/ @[to_additive /-"The additive action by an add_subgroup is the action by the underlying add_group. "-/] instance [mul_action G α] (S : subgroup G) : mul_action S α := S.to_submonoid.mul_action @[to_additive] lemma smul_def [mul_action G α] {S : subgroup G} (g : S) (m : α) : g • m = (g : G) • m := rfl @[to_additive] instance smul_comm_class_left [mul_action G β] [has_smul α β] [smul_comm_class G α β] (S : subgroup G) : smul_comm_class S α β := S.to_submonoid.smul_comm_class_left @[to_additive] instance smul_comm_class_right [has_smul α β] [mul_action G β] [smul_comm_class α G β] (S : subgroup G) : smul_comm_class α S β := S.to_submonoid.smul_comm_class_right /-- Note that this provides `is_scalar_tower S G G` which is needed by `smul_mul_assoc`. -/ instance [has_smul α β] [mul_action G α] [mul_action G β] [is_scalar_tower G α β] (S : subgroup G) : is_scalar_tower S α β := S.to_submonoid.is_scalar_tower instance [mul_action G α] [has_faithful_smul G α] (S : subgroup G) : has_faithful_smul S α := S.to_submonoid.has_faithful_smul /-- The action by a subgroup is the action by the underlying group. -/ instance [add_monoid α] [distrib_mul_action G α] (S : subgroup G) : distrib_mul_action S α := S.to_submonoid.distrib_mul_action /-- The action by a subgroup is the action by the underlying group. -/ instance [monoid α] [mul_distrib_mul_action G α] (S : subgroup G) : mul_distrib_mul_action S α := S.to_submonoid.mul_distrib_mul_action /-- The center of a group acts commutatively on that group. -/ instance center.smul_comm_class_left : smul_comm_class (center G) G G := submonoid.center.smul_comm_class_left /-- The center of a group acts commutatively on that group. -/ instance center.smul_comm_class_right : smul_comm_class G (center G) G := submonoid.center.smul_comm_class_right end subgroup end actions /-! ### Mul-opposite subgroups -/ section mul_opposite namespace subgroup /-- A subgroup `H` of `G` determines a subgroup `H.opposite` of the opposite group `Gᵐᵒᵖ`. -/ @[to_additive "An additive subgroup `H` of `G` determines an additive subgroup `H.opposite` of the opposite additive group `Gᵃᵒᵖ`."] def opposite : subgroup G ≃ subgroup Gᵐᵒᵖ := { to_fun := λ H, { carrier := mul_opposite.unop ⁻¹' (H : set G), one_mem' := H.one_mem, mul_mem' := λ a b ha hb, H.mul_mem hb ha, inv_mem' := λ a, H.inv_mem }, inv_fun := λ H, { carrier := mul_opposite.op ⁻¹' (H : set Gᵐᵒᵖ), one_mem' := H.one_mem, mul_mem' := λ a b ha hb, H.mul_mem hb ha, inv_mem' := λ a, H.inv_mem }, left_inv := λ H, set_like.coe_injective rfl, right_inv := λ H, set_like.coe_injective rfl } /-- Bijection between a subgroup `H` and its opposite. -/ @[to_additive "Bijection between an additive subgroup `H` and its opposite.", simps] def opposite_equiv (H : subgroup G) : H ≃ H.opposite := mul_opposite.op_equiv.subtype_equiv $ λ _, iff.rfl @[to_additive] instance (H : subgroup G) [encodable H] : encodable H.opposite := encodable.of_equiv H H.opposite_equiv.symm @[to_additive] instance (H : subgroup G) [countable H] : countable H.opposite := countable.of_equiv H H.opposite_equiv @[to_additive] lemma smul_opposite_mul {H : subgroup G} (x g : G) (h : H.opposite) : h • (g * x) = g * (h • x) := begin cases h, simp [(•), mul_assoc], end end subgroup end mul_opposite /-! ### Saturated subgroups -/ section saturated namespace subgroup /-- A subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `g^n ∈ H` we have `n = 0` or `g ∈ H`. -/ @[to_additive "An additive subgroup `H` of `G` is *saturated* if for all `n : ℕ` and `g : G` with `n•g ∈ H` we have `n = 0` or `g ∈ H`."] def saturated (H : subgroup G) : Prop := ∀ ⦃n g⦄, g ^ n ∈ H → n = 0 ∨ g ∈ H @[to_additive] lemma saturated_iff_npow {H : subgroup G} : saturated H ↔ (∀ (n : ℕ) (g : G), g ^ n ∈ H → n = 0 ∨ g ∈ H) := iff.rfl @[to_additive] lemma saturated_iff_zpow {H : subgroup G} : saturated H ↔ (∀ (n : ℤ) (g : G), g ^ n ∈ H → n = 0 ∨ g ∈ H) := begin split, { rintros hH ⟨n⟩ g hgn, { simp only [int.coe_nat_eq_zero, int.of_nat_eq_coe, zpow_coe_nat] at hgn ⊢, exact hH hgn }, { suffices : g ^ (n+1) ∈ H, { refine (hH this).imp _ id, simp only [is_empty.forall_iff, nat.succ_ne_zero], }, simpa only [inv_mem_iff, zpow_neg_succ_of_nat] using hgn, } }, { intros h n g hgn, specialize h n g, simp only [int.coe_nat_eq_zero, zpow_coe_nat] at h, apply h hgn } end end subgroup namespace add_subgroup lemma ker_saturated {A₁ A₂ : Type*} [add_comm_group A₁] [add_comm_group A₂] [no_zero_smul_divisors ℕ A₂] (f : A₁ →+ A₂) : (f.ker).saturated := begin intros n g hg, simpa only [f.mem_ker, nsmul_eq_smul, f.map_nsmul, smul_eq_zero] using hg end end add_subgroup end saturated
8e32c5309096b9ea2146cc61f700403b1ef569ec
b2e508d02500f1512e1618150413e6be69d9db10
/src/data/real/ennreal.lean
75fe6eb0f7d759634aeadc50fb86d66f13edd65c
[ "Apache-2.0" ]
permissive
callum-sutton/mathlib
c3788f90216e9cd43eeffcb9f8c9f959b3b01771
afd623825a3ac6bfbcc675a9b023edad3f069e89
refs/heads/master
1,591,371,888,053
1,560,990,690,000
1,560,990,690,000
192,476,045
0
0
Apache-2.0
1,568,941,843,000
1,560,837,965,000
Lean
UTF-8
Lean
false
false
27,013
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl Extended non-negative reals -/ import data.real.nnreal order.bounds tactic.norm_num noncomputable theory open classical set lattice local attribute [instance] prop_decidable variables {α : Type*} {β : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ennreal := with_top nnreal local notation `∞` := (⊤ : ennreal) namespace ennreal variables {a b c d : ennreal} {r p q : nnreal} instance : canonically_ordered_comm_semiring ennreal := by unfold ennreal; apply_instance instance : decidable_linear_order ennreal := by unfold ennreal; apply_instance instance : complete_linear_order ennreal := by unfold ennreal; apply_instance instance : inhabited ennreal := ⟨0⟩ instance : densely_ordered ennreal := with_top.densely_ordered instance : has_coe nnreal ennreal := ⟨ option.some ⟩ lemma none_eq_top : (none : ennreal) = (⊤ : ennreal) := rfl lemma some_eq_coe (a : nnreal) : (some a : ennreal) = (↑a : ennreal) := rfl /-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/ protected def to_nnreal : ennreal → nnreal | (some r) := r | none := 0 /-- `to_real x` returns `x` if it is real, `0` otherwise. -/ protected def to_real (a : ennreal) : real := coe (a.to_nnreal) /-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def of_real (r : real) : ennreal := coe (nnreal.of_real r) @[simp] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl @[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a | (some r) h := rfl | none h := (h rfl).elim @[simp] lemma of_real_to_real {a : ennreal} (h : a ≠ ∞) : ennreal.of_real (a.to_real) = a := by simp [ennreal.to_real, ennreal.of_real, h] @[simp] lemma to_real_of_real {r : real} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r := by simp [ennreal.to_real, ennreal.of_real, nnreal.coe_of_real _ h] lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(a.to_nnreal) ≤ a | (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _ | none := le_top @[simp] lemma coe_zero : ↑(0 : nnreal) = (0 : ennreal) := rfl @[simp] lemma coe_one : ↑(1 : nnreal) = (1 : ennreal) := rfl @[simp] lemma to_real_nonneg {a : ennreal} : 0 ≤ a.to_real := by simp [ennreal.to_real] @[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl @[simp] lemma top_to_real : ∞.to_real = 0 := rfl @[simp] lemma zero_to_nnreal : (0 : ennreal).to_nnreal = 0 := rfl @[simp] lemma zero_to_real : (0 : ennreal).to_real = 0 := rfl @[simp] lemma of_real_zero : ennreal.of_real (0 : ℝ) = 0 := by simp [ennreal.of_real]; refl @[simp] lemma of_real_one : ennreal.of_real (1 : ℝ) = (1 : ennreal) := by simp [ennreal.of_real] lemma forall_ennreal {p : ennreal → Prop} : (∀a, p a) ↔ (∀r:nnreal, p r) ∧ p ∞ := ⟨assume h, ⟨assume r, h _, h _⟩, assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩ lemma to_nnreal_eq_zero_iff (x : ennreal) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ⊤ := ⟨begin cases x, { simp [none_eq_top] }, { have A : some (0:nnreal) = (0:ennreal) := rfl, simp [ennreal.to_nnreal, A] {contextual := tt} } end, by intro h; cases h; simp [h]⟩ lemma to_real_eq_zero_iff (x : ennreal) : x.to_real = 0 ↔ x = 0 ∨ x = ⊤ := by simp [ennreal.to_real, to_nnreal_eq_zero_iff] @[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top @[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe @[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real] @[simp] lemma top_ne_of_real {r : ℝ} : ∞ ≠ ennreal.of_real r := by simp [ennreal.of_real] @[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe @[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe @[simp] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe @[simp] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe @[simp] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe @[simp] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe @[simp] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe @[simp] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe @[simp] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe @[simp] lemma coe_nonneg : 0 ≤ (↑r : ennreal) ↔ 0 ≤ r := coe_le_coe @[simp] lemma coe_pos : 0 < (↑r : ennreal) ↔ 0 < r := coe_lt_coe @[simp] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add @[simp] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul @[simp] lemma coe_bit0 : (↑(bit0 r) : ennreal) = bit0 r := coe_add @[simp] lemma coe_bit1 : (↑(bit1 r) : ennreal) = bit1 r := by simp [bit1] @[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top @[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add instance : is_semiring_hom (coe : nnreal → ennreal) := by refine_struct {..}; simp lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top _ _ lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top _ _ lemma to_nnreal_add {r₁ r₂ : ennreal} (h₁ : r₁ < ⊤) (h₂ : r₂ < ⊤) : (r₁ + r₂).to_nnreal = r₁.to_nnreal + r₂.to_nnreal := begin rw [← coe_eq_coe, coe_add, coe_to_nnreal, coe_to_nnreal, coe_to_nnreal]; apply @ne_top_of_lt ennreal _ _ ⊤, exact h₂, exact h₁, exact add_lt_top.2 ⟨h₁, h₂⟩ end /- rw has trouble with the generic lt_top_iff_ne_top and bot_lt_iff_ne_bot (contrary to erw). This is solved with the next lemmas -/ protected lemma lt_top_iff_ne_top : a < ∞ ↔ a ≠ ∞ := lt_top_iff_ne_top protected lemma bot_lt_iff_ne_bot : 0 < a ↔ a ≠ 0 := bot_lt_iff_ne_bot lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end @[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top lemma mul_eq_top {a b : ennreal} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) := with_top.mul_eq_top_iff lemma mul_lt_top {a b : ennreal} : a < ⊤ → b < ⊤ → a * b < ⊤ := by simp [ennreal.lt_top_iff_ne_top, (≠), mul_eq_top] {contextual := tt} @[simp] lemma coe_finset_sum {s : finset α} {f : α → nnreal} : ↑(s.sum f) = (s.sum (λa, f a) : ennreal) := (finset.sum_hom coe).symm @[simp] lemma coe_finset_prod {s : finset α} {f : α → nnreal} : ↑(s.prod f) = (s.prod (λa, f a) : ennreal) := (finset.prod_hom coe).symm @[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl section order @[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r @[simp] lemma not_top_le_coe : ¬ (⊤:ennreal) ≤ ↑r := with_top.not_top_le_coe r @[simp] lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe @[simp] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe @[simp] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe @[simp] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe @[simp] lemma one_lt_zero_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe @[simp] lemma coe_nat (n : nat) : ((n : nnreal) : ennreal) = n := with_top.coe_nat n @[simp] lemma nat_ne_top (n : nat) : (n : ennreal) ≠ ⊤ := with_top.nat_ne_top n @[simp] lemma top_ne_nat (n : nat) : (⊤ : ennreal) ≠ n := with_top.top_ne_nat n lemma le_coe_iff : a ≤ ↑r ↔ (∃p:nnreal, a = p ∧ p ≤ r) := with_top.le_coe_iff r a lemma coe_le_iff : ↑r ≤ a ↔ (∀p:nnreal, a = p → r ≤ p) := with_top.coe_le_iff r a lemma lt_iff_exists_coe : a < b ↔ (∃p:nnreal, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe a b -- TODO: move to canonically ordered semiring ... protected lemma zero_lt_one : 0 < (1 : ennreal) := zero_lt_coe_iff.mpr zero_lt_one @[simp] lemma not_lt_zero : ¬ a < 0 := by simp lemma add_lt_add_iff_left : a < ⊤ → (a + c < a + b ↔ c < b) := with_top.add_lt_add_iff_left lemma add_lt_add_iff_right : a < ⊤ → (c + a < b + a ↔ c < b) := with_top.add_lt_add_iff_right lemma lt_add_right (ha : a < ⊤) (hb : 0 < b) : a < a + b := by rwa [← add_lt_add_iff_left ha, add_zero] at hb lemma le_of_forall_epsilon_le : ∀{a b : ennreal}, (∀ε:nnreal, ε > 0 → b < ∞ → a ≤ b + ε) → a ≤ b | a none h := le_top | none (some a) h := have (⊤:ennreal) ≤ ↑a + ↑(1:nnreal), from h 1 zero_lt_one coe_lt_top, by rw [← coe_add] at this; exact (not_top_le_coe this).elim | (some a) (some b) h := by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff] at *; exact nnreal.le_of_forall_epsilon_le h lemma lt_iff_exists_rat_btwn : a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) := ⟨λ h, begin rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩, rcases dense h with ⟨c, pc, cb⟩, rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩, rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩, exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩ end, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ lemma lt_iff_exists_real_btwn : a < b ↔ (∃r:ℝ, 0 ≤ r ∧ a < ennreal.of_real r ∧ (ennreal.of_real r:ennreal) < b) := ⟨λ h, let ⟨q, q0, aq, qb⟩ := ennreal.lt_iff_exists_rat_btwn.1 h in ⟨q, rat.cast_nonneg.2 q0, aq, qb⟩, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ protected lemma exists_nat_gt {r : ennreal} (h : r ≠ ⊤) : ∃n:ℕ, r < n := begin rcases lt_iff_exists_coe.1 (lt_top_iff_ne_top.2 h) with ⟨r, rfl, hb⟩, rcases exists_nat_gt r with ⟨n, hn⟩, refine ⟨n, _⟩, rwa [← ennreal.coe_nat, ennreal.coe_lt_coe], end lemma add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := begin rcases dense ac with ⟨a', aa', a'c⟩, rcases lt_iff_exists_coe.1 aa' with ⟨aR, rfl, _⟩, rcases lt_iff_exists_coe.1 a'c with ⟨a'R, rfl, _⟩, rcases dense bd with ⟨b', bb', b'd⟩, rcases lt_iff_exists_coe.1 bb' with ⟨bR, rfl, _⟩, rcases lt_iff_exists_coe.1 b'd with ⟨b'R, rfl, _⟩, have I : ↑aR + ↑bR < ↑a'R + ↑b'R := begin rw [← coe_add, ← coe_add, coe_lt_coe], apply add_lt_add (coe_lt_coe.1 aa') (coe_lt_coe.1 bb') end, have J : ↑a'R + ↑b'R ≤ c + d := add_le_add' (le_of_lt a'c) (le_of_lt b'd), apply lt_of_lt_of_le I J end end order section complete_lattice lemma coe_Sup {s : set nnreal} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup lemma coe_Inf {s : set nnreal} : s ≠ ∅ → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf @[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s := assume x hx, le_top lemma coe_mem_upper_bounds {s : set nnreal} : ↑r ∈ upper_bounds ((coe : nnreal → ennreal) '' s) ↔ r ∈ upper_bounds s := by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt} lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} : (⨅n, f n) = (⨅n:nnreal, f n) ⊓ f ⊤ := le_antisymm (le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _)) (le_infi $ forall_ennreal.2 ⟨assume r, inf_le_left_of_le $ infi_le _ _, inf_le_right⟩) end complete_lattice section mul lemma mul_eq_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b = a * c ↔ b = c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm, nnreal.mul_eq_mul_left] {contextual := tt}, end lemma mul_le_mul_left : a ≠ 0 → a ≠ ⊤ → (a * b ≤ a * c ↔ b ≤ c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt}, assume h, exact mul_le_mul_left (zero_lt_iff_ne_zero.2 h) end lemma mul_eq_zero {a b : ennreal} : a * b = 0 ↔ a = 0 ∨ b = 0 := canonically_ordered_comm_semiring.mul_eq_zero_iff _ _ end mul section sub instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩ lemma coe_sub : ↑(p - r) = (↑p:ennreal) - r := le_antisymm (le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $ by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb) (Inf_le $ show (↑p : ennreal) ≤ ↑(p - r) + ↑r, by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add]) @[simp] lemma top_sub_coe : ∞ - ↑r = ∞ := top_unique $ le_Inf $ by simp [add_eq_top] @[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 := le_antisymm (Inf_le $ le_add_left h) (zero_le _) @[simp] lemma zero_sub : 0 - a = 0 := le_antisymm (Inf_le $ zero_le _) (zero_le _) @[simp] lemma sub_infty : a - ∞ = 0 := le_antisymm (Inf_le $ by simp) (zero_le _) lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d := Inf_le_Inf $ assume e (h : b ≤ e + d), calc a ≤ b : h₁ ... ≤ e + d : h ... ≤ e + c : add_le_add' (le_refl _) h₂ @[simp] lemma add_sub_self : ∀{a b : ennreal}, b < ∞ → (a + b) - b = a | a none := by simp [none_eq_top] | none (some b) := by simp [none_eq_top, some_eq_coe] | (some a) (some b) := by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel] @[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b := by rw [add_comm, add_sub_self h] lemma add_left_inj (h : a < ∞) : a + b = a + c ↔ b = c := ⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩ lemma add_right_inj (h : a < ∞) : b + a = c + a ↔ b = c := by rw [add_comm, add_comm c, add_left_inj h] @[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, b ≤ a → (a - b) + b = a := begin simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt}, rintros r p x rfl h, rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h] end @[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a := by rwa [add_comm, sub_add_cancel_of_le] lemma sub_add_self_eq_max : (a - b) + b = max a b := match le_total a b with | or.inl h := by simp [h, max_eq_right] | or.inr h := by simp [h, max_eq_left] end @[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b := iff.intro (assume h : a - b ≤ c, calc a ≤ (a - b) + b : by rw [sub_add_self_eq_max]; exact le_max_left _ _ ... ≤ c + b : add_le_add' h (le_refl _)) (assume h : a ≤ c + b, calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _) ... ≤ c : Inf_le (le_refl (c + b))) @[simp] lemma sub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b := by simpa [-ennreal.sub_le_iff_le_add] using @ennreal.sub_le_iff_le_add a b 0 @[simp] lemma zero_lt_sub_iff_lt : 0 < a - b ↔ b < a := by simpa [ennreal.bot_lt_iff_ne_bot, -sub_eq_zero_iff_le] using not_iff_not.2 (@sub_eq_zero_iff_le a b) lemma sub_le_self (a b : ennreal) : a - b ≤ a := ennreal.sub_le_iff_le_add.2 $ le_add_of_nonneg_right' $ zero_le _ @[simp] lemma sub_zero : a - 0 = a := eq.trans (add_zero (a - 0)).symm $ by simp lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b := by rw [← add_right_inj (lt_of_le_of_lt (sub_le_self _ _) h), sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2] lemma sub_left_inj {a b c : ennreal} (ha : a < ⊤) (hb : b ≤ a) (hc : c ≤ a) : a - b = a - c ↔ b = c := iff.intro begin assume h, have : a - (a - b) = a - (a - c), rw h, rw [sub_sub_cancel ha hb, sub_sub_cancel ha hc] at this, exact this end (λ h, by rw h) end sub section bit @[simp] lemma bit0_inj : bit0 a = bit0 b ↔ a = b := ⟨λh, begin rcases (lt_trichotomy a b) with h₁| h₂| h₃, { exact (absurd h (ne_of_lt (add_lt_add h₁ h₁))) }, { exact h₂ }, { exact (absurd h.symm (ne_of_lt (add_lt_add h₃ h₃))) } end, λh, congr_arg _ h⟩ @[simp] lemma bit0_eq_zero_iff : bit0 a = 0 ↔ a = 0 := by simpa only [bit0_zero] using @bit0_inj a 0 @[simp] lemma bit0_eq_top_iff : bit0 a = ∞ ↔ a = ∞ := by rw [bit0, add_eq_top, or_self] @[simp] lemma bit1_inj : bit1 a = bit1 b ↔ a = b := ⟨λh, begin unfold bit1 at h, rwa [add_right_inj, bit0_inj] at h, simp [lt_top_iff_ne_top] end, λh, congr_arg _ h⟩ @[simp] lemma bit1_ne_zero : bit1 a ≠ 0 := by unfold bit1; simp @[simp] lemma bit1_eq_one_iff : bit1 a = 1 ↔ a = 0 := by simpa only [bit1_zero] using @bit1_inj a 0 @[simp] lemma bit1_eq_top_iff : bit1 a = ∞ ↔ a = ∞ := by unfold bit1; rw add_eq_top; simp end bit section inv instance : has_inv ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩ instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩ lemma div_def : a / b = a * b⁻¹ := rfl @[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ := show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl @[simp] lemma inv_top : (∞ : ennreal)⁻¹ = 0 := bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul] @[simp] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ennreal) = (↑r)⁻¹ := le_antisymm (le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $ by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb) (Inf_le $ by simp; rw [← coe_mul, nnreal.mul_inv_cancel hr]; exact le_refl 1) @[simp] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ennreal) = p / r := show ↑(p * r⁻¹) = ↑p * (↑r)⁻¹, by rw [coe_mul, coe_inv hr] @[simp] lemma inv_inv : (a⁻¹)⁻¹ = a := by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] at * @[simp] lemma inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] at * lemma inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp @[simp] lemma inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := by rw [← inv_eq_top, inv_inv] lemma inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp lemma le_div_iff_mul_le : ∀{b}, b ≠ 0 → b ≠ ⊤ → (a ≤ c / b ↔ a * b ≤ c) | none h0 ht := (ht rfl).elim | (some r) h0 ht := begin have hr : r ≠ 0, from mt coe_eq_coe.2 h0, rw [← ennreal.mul_le_mul_left h0 ht], suffices : ↑r * a ≤ (↑r * ↑r⁻¹) * c ↔ a * ↑r ≤ c, { simpa [some_eq_coe, div_def, hr, mul_left_comm, mul_comm, mul_assoc] }, rw [← coe_mul, nnreal.mul_inv_cancel hr, coe_one, one_mul, mul_comm] end lemma div_le_iff_le_mul (hb0 : b ≠ 0) (hbt : b ≠ ⊤) : a / b ≤ c ↔ a ≤ c * b := suffices a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_def], (le_div_iff_mul_le (inv_ne_zero.2 hbt) (inv_ne_top.2 hb0)).symm lemma inv_le_iff_le_mul : (b = ⊤ → a ≠ 0) → (a = ⊤ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) := begin cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt}, by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, -coe_inv, (coe_inv _).symm, nnreal.inv_le] end @[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := begin cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] }, by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le], suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_def, h] }, exact le_div_iff_mul_le (mt coe_eq_coe.1 h) coe_ne_top end lemma mul_inv_cancel : ∀{r : ennreal}, r ≠ 0 → r ≠ ⊤ → r * r⁻¹ = 1 := begin refine forall_ennreal.2 ⟨λ r, _, _⟩; simp [-coe_inv, (coe_inv _).symm] {contextual := tt}, assume h, rw [← ennreal.coe_mul, nnreal.mul_inv_cancel h, coe_one] end lemma mul_le_if_le_inv {a b r : ennreal} (hr₀ : r ≠ 0) (hr₁ : r ≠ ⊤) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) := by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul] lemma le_of_forall_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y := forall_ennreal.2 $ and.intro (assume r, forall_ennreal.2 $ and.intro (assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha, begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end) (assume h, le_top)) (assume r hr, have ((1 / 2 : nnreal) : ennreal) * ⊤ ≤ r := hr _ (coe_lt_coe.2 ((@nnreal.coe_lt (1/2) 1).2 one_half_lt_one)), have ne : ((1 / 2 : nnreal) : ennreal) ≠ 0, begin rw [(≠), coe_eq_zero], refine zero_lt_iff_ne_zero.1 _, show 0 < (1 / 2 : ℝ), exact div_pos zero_lt_one two_pos end, by rwa [mul_top, if_neg ne] at this) lemma div_add_div_same {a b c : ennreal} : a / c + b / c = (a + b) / c := eq.symm $ right_distrib a b (c⁻¹) lemma div_self {a : ennreal} (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 := have A : 1 ≤ a / a := by simp [le_div_iff_mul_le h0 hI, le_refl], have B : a / a ≤ 1 := by simp [div_le_iff_le_mul h0 hI, le_refl], le_antisymm B A lemma add_halves (a : ennreal) : a / 2 + a / 2 = a := have ¬((2 : nnreal) : ennreal) = (0 : nnreal) := by rw [coe_eq_coe]; norm_num, have A : (2:ennreal) * 2⁻¹ = 1 := by rw [←div_def, div_self]; [assumption, apply coe_ne_top], calc a / 2 + a / 2 = (a + a) / 2 : by rw div_add_div_same ... = (a * 1 + a * 1) / 2 : by rw mul_one ... = (a * (1 + 1)) / 2 : by rw left_distrib ... = (a * 2) / 2 : by rw one_add_one_eq_two ... = (a * 2) * 2⁻¹ : by rw div_def ... = a * (2 * 2⁻¹) : by rw mul_assoc ... = a * 1 : by rw A ... = a : by rw mul_one @[simp] lemma div_zero_iff {a b : ennreal} : a / b = 0 ↔ a = 0 ∨ b = ⊤ := by simp [div_def, mul_eq_zero] @[simp] lemma div_pos_iff {a b : ennreal} : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ⊤ := by simp [zero_lt_iff_ne_zero, not_or_distrib] lemma half_pos {a : ennreal} (h : 0 < a) : 0 < a / 2 := by simp [ne_of_gt h] lemma half_lt_self {a : ennreal} (hz : a ≠ 0) (ht : a ≠ ⊤) : a / 2 < a := begin cases a, { cases ht none_eq_top }, { simp [some_eq_coe] at hz, simpa [-coe_lt_coe, coe_div two_ne_zero'] using coe_lt_coe.2 (nnreal.half_lt_self hz) } end lemma exists_inv_nat_lt {a : ennreal} (h : a ≠ 0) : ∃n:ℕ, (n:ennreal)⁻¹ < a := begin rcases dense (bot_lt_iff_ne_bot.2 h) with ⟨b, bz, ba⟩, have bz' : b ≠ 0 := bot_lt_iff_ne_bot.1 bz, have : b⁻¹ ≠ ⊤ := by simp [bz'], rcases ennreal.exists_nat_gt this with ⟨n, bn⟩, have I : ((n : ℕ) : ennreal)⁻¹ ≤ b := begin rw [ennreal.inv_le_iff_le_mul, mul_comm, ← ennreal.inv_le_iff_le_mul], exact le_of_lt bn, simp only [h, ennreal.nat_ne_top, forall_prop_of_false, ne.def, not_false_iff], exact λ_, ne_bot_of_gt bn, exact λ_, ne_bot_of_gt bn, exact λ_, bz' end, exact ⟨n, lt_of_le_of_lt I ba⟩ end end inv section real lemma to_real_add (ha : a ≠ ⊤) (hb : b ≠ ⊤) : (a+b).to_real = a.to_real + b.to_real := begin cases a, { simpa [none_eq_top] using ha }, cases b, { simpa [none_eq_top] using hb }, refl end lemma of_real_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ennreal.of_real (p + q) = ennreal.of_real p + ennreal.of_real q := by rw [ennreal.of_real, ennreal.of_real, ennreal.of_real, ← coe_add, coe_eq_coe, nnreal.of_real_add hp hq] @[simp] lemma to_real_le_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real ≤ b.to_real ↔ a ≤ b := begin cases a, { simpa [none_eq_top] using ha }, cases b, { simpa [none_eq_top] using hb }, simp only [ennreal.to_real, nnreal.coe_le.symm, with_top.some_le_some], refl end @[simp] lemma to_real_lt_to_real (ha : a ≠ ⊤) (hb : b ≠ ⊤) : a.to_real < b.to_real ↔ a < b := begin cases a, { simpa [none_eq_top] using ha }, cases b, { simpa [none_eq_top] using hb }, rw [with_top.some_lt_some], refl end lemma of_real_le_of_real {p q : ℝ} (h : p ≤ q) : ennreal.of_real p ≤ ennreal.of_real q := by simp [ennreal.of_real, nnreal.of_real_le_of_real h] @[simp] lemma of_real_le_of_real_iff {p q : ℝ} (h : 0 ≤ q) : ennreal.of_real p ≤ ennreal.of_real q ↔ p ≤ q := by rw [ennreal.of_real, ennreal.of_real, coe_le_coe, nnreal.of_real_le_of_real_iff h] @[simp] lemma of_real_lt_of_real_iff {p q : ℝ} (h : 0 < q) : ennreal.of_real p < ennreal.of_real q ↔ p < q := by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff h] @[simp] lemma of_real_pos {p : ℝ} : 0 < ennreal.of_real p ↔ 0 < p := by simp [ennreal.of_real] @[simp] lemma of_real_eq_zero {p : ℝ} : ennreal.of_real p = 0 ↔ p ≤ 0 := by simp [ennreal.of_real] end real section infi variables {ι : Sort*} {f g : ι → ennreal} lemma infi_add : infi f + a = ⨅i, f i + a := le_antisymm (le_infi $ assume i, add_le_add' (infi_le _ _) $ le_refl _) (ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _) lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) := le_antisymm (ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i) (supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a)) lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) := begin refine (eq_of_forall_ge_iff $ λ c, _), rw [ennreal.sub_le_iff_le_add, add_comm, infi_add], simp [ennreal.sub_le_iff_le_add] end lemma Inf_add {s : set ennreal} : Inf s + a = ⨅b∈s, b + a := by simp [Inf_eq_infi, infi_add] lemma add_infi {a : ennreal} : a + infi f = ⨅b, a + f b := by rw [add_comm, infi_add]; simp lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) := suffices (⨅a, f a + g a) ≤ infi f + infi g, from le_antisymm (le_infi $ assume a, add_le_add' (infi_le _ _) (infi_le _ _)) this, calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') : le_infi $ assume a, le_infi $ assume a', let ⟨k, h⟩ := h a a' in infi_le_of_le k h ... ≤ infi f + infi g : by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _ lemma infi_sum {f : ι → α → ennreal} {s : finset α} [nonempty ι] (h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) : (⨅i, s.sum (f i)) = s.sum (λa, ⨅i, f i a) := finset.induction_on s (by simp) $ assume a s ha ih, have ∀ (i j : ι), ∃ (k : ι), f k a + s.sum (f k) ≤ f i a + s.sum (f j), from assume i j, let ⟨k, hk⟩ := h (insert a s) i j in ⟨k, add_le_add' (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum' $ assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩, by simp [ha, ih.symm, infi_add_infi this] end infi section supr lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ⊤ := (lattice.supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb) end supr end ennreal
18aba4fb85b80343d7fcfa11e0f0429cd6909ba7
4efff1f47634ff19e2f786deadd394270a59ecd2
/src/category_theory/limits/shapes/constructions/binary_products.lean
bbeb04be08f1ea3ad69ebe8ae72ee1b192688439
[ "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
1,623
lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import category_theory.limits.shapes.terminal import category_theory.limits.shapes.pullbacks import category_theory.limits.shapes.binary_products universes v u /-! # Constructing binary product from pullbacks and terminal object. If a category has pullbacks and a terminal object, then it has binary products. TODO: provide the dual result. -/ open category_theory category_theory.category category_theory.limits /-- Any category with pullbacks and terminal object has binary products. -/ -- This is not an instance, as it is not always how one wants to construct binary products! def has_binary_products_of_terminal_and_pullbacks (C : Type u) [𝒞 : category.{v} C] [has_terminal C] [has_pullbacks C] : has_binary_products C := { has_limit := λ F, { cone := { X := pullback (terminal.from (F.obj walking_pair.left)) (terminal.from (F.obj walking_pair.right)), π := discrete.nat_trans (λ x, walking_pair.cases_on x pullback.fst pullback.snd)}, is_limit := { lift := λ c, pullback.lift ((c.π).app walking_pair.left) ((c.π).app walking_pair.right) (subsingleton.elim _ _), fac' := λ s c, walking_pair.cases_on c (limit.lift_π _ _) (limit.lift_π _ _), uniq' := λ s m J, begin rw [←J, ←J], ext; rw limit.lift_π; refl end } } }
d6654c28f8c9a12532ebc3ff5915baf2b3e2a6b2
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
/stage0/src/Lean/Util/Constructions.lean
d0a16d7e98911eb71d45342fc2be765cd8a60736
[ "Apache-2.0" ]
permissive
banksonian/lean4
3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc
78da6b3aa2840693eea354a41e89fc5b212a5011
refs/heads/master
1,673,703,624,165
1,605,123,551,000
1,605,123,551,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,046
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Environment import Lean.MonadEnv namespace Lean @[extern "lean_mk_cases_on"] constant mkCasesOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_rec_on"] constant mkRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_no_confusion"] constant mkNoConfusionImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_below"] constant mkBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_ibelow"] constant mkIBelowImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_brec_on"] constant mkBRecOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment @[extern "lean_mk_binduction_on"] constant mkBInductionOnImp (env : Environment) (declName : @& Name) : Except KernelException Environment variables {m} [Monad m] [MonadEnv m] [MonadExceptOf Exception m] [Ref m] [AddErrorMessageContext m] [MonadOptions m] @[inline] private def adaptFn (f : Environment → Name → Except KernelException Environment) (declName : Name) : m Unit := do match f (← getEnv) declName with | Except.ok env => modifyEnv fun _ => env | Except.error ex => throwKernelException ex def mkCasesOn (declName : Name) : m Unit := adaptFn mkCasesOnImp declName def mkRecOn (declName : Name) : m Unit := adaptFn mkRecOnImp declName def mkNoConfusion (declName : Name) : m Unit := adaptFn mkNoConfusionImp declName def mkBelow (declName : Name) : m Unit := adaptFn mkBelowImp declName def mkIBelow (declName : Name) : m Unit := adaptFn mkIBelowImp declName def mkBRecOn (declName : Name) : m Unit := adaptFn mkBRecOnImp declName def mkBInductionOn (declName : Name) : m Unit := adaptFn mkBInductionOnImp declName end Lean
e11e3585ac4400dfd15d3f91d3dedb6da2cc9504
bb31430994044506fa42fd667e2d556327e18dfe
/src/topology/continuous_function/bounded.lean
7cbba6795e4d73360918eb792e6723bb2964f048
[ "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
60,044
lean
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Mario Carneiro, Yury Kudryashov, Heather Macbeth -/ import analysis.normed.order.lattice import analysis.normed_space.operator_norm import analysis.normed_space.star.basic import data.real.sqrt import topology.continuous_function.algebra import topology.metric_space.equicontinuity /-! # Bounded continuous functions The type of bounded continuous functions taking values in a metric space, with the uniform distance. -/ noncomputable theory open_locale topological_space classical nnreal uniformity uniform_convergence open set filter metric function universes u v w variables {F : Type*} {α : Type u} {β : Type v} {γ : Type w} /-- `α →ᵇ β` is the type of bounded continuous functions `α → β` from a topological space to a metric space. When possible, instead of parametrizing results over `(f : α →ᵇ β)`, you should parametrize over `(F : Type*) [bounded_continuous_map_class F α β] (f : F)`. When you extend this structure, make sure to extend `bounded_continuous_map_class`. -/ structure bounded_continuous_function (α : Type u) (β : Type v) [topological_space α] [pseudo_metric_space β] extends continuous_map α β : Type (max u v) := (map_bounded' : ∃ C, ∀ x y, dist (to_fun x) (to_fun y) ≤ C) localized "infixr (name := bounded_continuous_function) ` →ᵇ `:25 := bounded_continuous_function" in bounded_continuous_function section set_option old_structure_cmd true /-- `bounded_continuous_map_class F α β` states that `F` is a type of bounded continuous maps. You should also extend this typeclass when you extend `bounded_continuous_function`. -/ class bounded_continuous_map_class (F α β : Type*) [topological_space α] [pseudo_metric_space β] extends continuous_map_class F α β := (map_bounded (f : F) : ∃ C, ∀ x y, dist (f x) (f y) ≤ C) end export bounded_continuous_map_class (map_bounded) namespace bounded_continuous_function section basics variables [topological_space α] [pseudo_metric_space β] [pseudo_metric_space γ] variables {f g : α →ᵇ β} {x : α} {C : ℝ} instance : bounded_continuous_map_class (α →ᵇ β) α β := { coe := λ f, f.to_fun, coe_injective' := λ f g h, by { obtain ⟨⟨_, _⟩, _⟩ := f, obtain ⟨⟨_, _⟩, _⟩ := g, congr' }, map_continuous := λ f, f.continuous_to_fun, map_bounded := λ f, f.map_bounded' } /-- Helper instance for when there's too many metavariables to apply `fun_like.has_coe_to_fun` directly. -/ instance : has_coe_to_fun (α →ᵇ β) (λ _, α → β) := fun_like.has_coe_to_fun instance [bounded_continuous_map_class F α β] : has_coe_t F (α →ᵇ β) := ⟨λ f, { to_fun := f, continuous_to_fun := map_continuous f, map_bounded' := map_bounded f }⟩ @[simp] lemma coe_to_continuous_fun (f : α →ᵇ β) : (f.to_continuous_map : α → β) = f := rfl /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def simps.apply (h : α →ᵇ β) : α → β := h initialize_simps_projections bounded_continuous_function (to_continuous_map_to_fun → apply) protected lemma bounded (f : α →ᵇ β) : ∃C, ∀ x y : α, dist (f x) (f y) ≤ C := f.map_bounded' protected lemma continuous (f : α →ᵇ β) : continuous f := f.to_continuous_map.continuous @[ext] lemma ext (h : ∀ x, f x = g x) : f = g := fun_like.ext _ _ h lemma bounded_range (f : α →ᵇ β) : bounded (range f) := bounded_range_iff.2 f.bounded lemma bounded_image (f : α →ᵇ β) (s : set α) : bounded (f '' s) := f.bounded_range.mono $ image_subset_range _ _ lemma eq_of_empty [is_empty α] (f g : α →ᵇ β) : f = g := ext $ is_empty.elim ‹_› /-- A continuous function with an explicit bound is a bounded continuous function. -/ def mk_of_bound (f : C(α, β)) (C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β := ⟨f, ⟨C, h⟩⟩ @[simp] lemma mk_of_bound_coe {f} {C} {h} : (mk_of_bound f C h : α → β) = (f : α → β) := rfl /-- A continuous function on a compact space is automatically a bounded continuous function. -/ def mk_of_compact [compact_space α] (f : C(α, β)) : α →ᵇ β := ⟨f, bounded_range_iff.1 (is_compact_range f.continuous).bounded⟩ @[simp] lemma mk_of_compact_apply [compact_space α] (f : C(α, β)) (a : α) : mk_of_compact f a = f a := rfl /-- If a function is bounded on a discrete space, it is automatically continuous, and therefore gives rise to an element of the type of bounded continuous functions -/ @[simps] def mk_of_discrete [discrete_topology α] (f : α → β) (C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β := ⟨⟨f, continuous_of_discrete_topology⟩, ⟨C, h⟩⟩ /-- The uniform distance between two bounded continuous functions -/ instance : has_dist (α →ᵇ β) := ⟨λf g, Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C}⟩ lemma dist_eq : dist f g = Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C} := rfl lemma dist_set_exists : ∃ C, 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C := begin rcases f.bounded_range.union g.bounded_range with ⟨C, hC⟩, refine ⟨max 0 C, le_max_left _ _, λ x, (hC _ _ _ _).trans (le_max_right _ _)⟩; [left, right]; apply mem_range_self end /-- The pointwise distance is controlled by the distance between functions, by definition. -/ lemma dist_coe_le_dist (x : α) : dist (f x) (g x) ≤ dist f g := le_cInf dist_set_exists $ λb hb, hb.2 x /- This lemma will be needed in the proof of the metric space instance, but it will become useless afterwards as it will be superseded by the general result that the distance is nonnegative in metric spaces. -/ private lemma dist_nonneg' : 0 ≤ dist f g := le_cInf dist_set_exists (λ C, and.left) /-- The distance between two functions is controlled by the supremum of the pointwise distances -/ lemma dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀x:α, dist (f x) (g x) ≤ C := ⟨λ h x, le_trans (dist_coe_le_dist x) h, λ H, cInf_le ⟨0, λ C, and.left⟩ ⟨C0, H⟩⟩ lemma dist_le_iff_of_nonempty [nonempty α] : dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C := ⟨λ h x, le_trans (dist_coe_le_dist x) h, λ w, (dist_le (le_trans dist_nonneg (w (nonempty.some ‹_›)))).mpr w⟩ lemma dist_lt_of_nonempty_compact [nonempty α] [compact_space α] (w : ∀x:α, dist (f x) (g x) < C) : dist f g < C := begin have c : continuous (λ x, dist (f x) (g x)), { continuity, }, obtain ⟨x, -, le⟩ := is_compact.exists_forall_ge is_compact_univ set.univ_nonempty (continuous.continuous_on c), exact lt_of_le_of_lt (dist_le_iff_of_nonempty.mpr (λ y, le y trivial)) (w x), end lemma dist_lt_iff_of_compact [compact_space α] (C0 : (0 : ℝ) < C) : dist f g < C ↔ ∀x:α, dist (f x) (g x) < C := begin fsplit, { intros w x, exact lt_of_le_of_lt (dist_coe_le_dist x) w, }, { by_cases h : nonempty α, { resetI, exact dist_lt_of_nonempty_compact, }, { rintro -, convert C0, apply le_antisymm _ dist_nonneg', rw [dist_eq], exact cInf_le ⟨0, λ C, and.left⟩ ⟨le_rfl, λ x, false.elim (h (nonempty.intro x))⟩, }, }, end lemma dist_lt_iff_of_nonempty_compact [nonempty α] [compact_space α] : dist f g < C ↔ ∀x:α, dist (f x) (g x) < C := ⟨λ w x, lt_of_le_of_lt (dist_coe_le_dist x) w, dist_lt_of_nonempty_compact⟩ /-- The type of bounded continuous functions, with the uniform distance, is a pseudometric space. -/ instance : pseudo_metric_space (α →ᵇ β) := { dist_self := λ f, le_antisymm ((dist_le le_rfl).2 $ λ x, by simp) dist_nonneg', dist_comm := λ f g, by simp [dist_eq, dist_comm], dist_triangle := λ f g h, (dist_le (add_nonneg dist_nonneg' dist_nonneg')).2 $ λ x, le_trans (dist_triangle _ _ _) (add_le_add (dist_coe_le_dist _) (dist_coe_le_dist _)) } /-- The type of bounded continuous functions, with the uniform distance, is a metric space. -/ instance {α β} [topological_space α] [metric_space β] : metric_space (α →ᵇ β) := { eq_of_dist_eq_zero := λ f g hfg, by ext x; exact eq_of_dist_eq_zero (le_antisymm (hfg ▸ dist_coe_le_dist _) dist_nonneg) } lemma nndist_eq : nndist f g = Inf {C | ∀ x : α, nndist (f x) (g x) ≤ C} := subtype.ext $ dist_eq.trans $ begin rw [nnreal.coe_Inf, nnreal.coe_image], simp_rw [mem_set_of_eq, ←nnreal.coe_le_coe, subtype.coe_mk, exists_prop, coe_nndist], end lemma nndist_set_exists : ∃ C, ∀ x : α, nndist (f x) (g x) ≤ C := subtype.exists.mpr $ dist_set_exists.imp $ λ a ⟨ha, h⟩, ⟨ha, h⟩ lemma nndist_coe_le_nndist (x : α) : nndist (f x) (g x) ≤ nndist f g := dist_coe_le_dist x /-- On an empty space, bounded continuous functions are at distance 0 -/ lemma dist_zero_of_empty [is_empty α] : dist f g = 0 := by rw [(ext is_empty_elim : f = g), dist_self] lemma dist_eq_supr : dist f g = ⨆ x : α, dist (f x) (g x) := begin casesI is_empty_or_nonempty α, { rw [supr_of_empty', real.Sup_empty, dist_zero_of_empty] }, refine (dist_le_iff_of_nonempty.mpr $ le_csupr _).antisymm (csupr_le dist_coe_le_dist), exact dist_set_exists.imp (λ C hC, forall_range_iff.2 hC.2) end lemma nndist_eq_supr : nndist f g = ⨆ x : α, nndist (f x) (g x) := subtype.ext $ dist_eq_supr.trans $ by simp_rw [nnreal.coe_supr, coe_nndist] lemma tendsto_iff_tendsto_uniformly {ι : Type*} {F : ι → (α →ᵇ β)} {f : α →ᵇ β} {l : filter ι} : tendsto F l (𝓝 f) ↔ tendsto_uniformly (λ i, F i) f l := iff.intro (λ h, tendsto_uniformly_iff.2 (λ ε ε0, (metric.tendsto_nhds.mp h ε ε0).mp (eventually_of_forall $ λ n hn x, lt_of_le_of_lt (dist_coe_le_dist x) (dist_comm (F n) f ▸ hn)))) (λ h, metric.tendsto_nhds.mpr $ λ ε ε_pos, (h _ (dist_mem_uniformity $ half_pos ε_pos)).mp (eventually_of_forall $ λ n hn, lt_of_le_of_lt ((dist_le (half_pos ε_pos).le).mpr $ λ x, dist_comm (f x) (F n x) ▸ le_of_lt (hn x)) (half_lt_self ε_pos))) /-- The topology on `α →ᵇ β` is exactly the topology induced by the natural map to `α →ᵤ β`. -/ lemma inducing_coe_fn : inducing (uniform_fun.of_fun ∘ coe_fn : (α →ᵇ β) → (α →ᵤ β)) := begin rw inducing_iff_nhds, refine λ f, eq_of_forall_le_iff (λ l, _), rw [← tendsto_iff_comap, ← tendsto_id', tendsto_iff_tendsto_uniformly, uniform_fun.tendsto_iff_tendsto_uniformly], refl end -- TODO: upgrade to a `uniform_embedding` lemma embedding_coe_fn : embedding (uniform_fun.of_fun ∘ coe_fn : (α →ᵇ β) → (α →ᵤ β)) := ⟨inducing_coe_fn, λ f g h, ext $ λ x, congr_fun h x⟩ variables (α) {β} /-- Constant as a continuous bounded function. -/ @[simps {fully_applied := ff}] def const (b : β) : α →ᵇ β := ⟨continuous_map.const α b, 0, by simp [le_rfl]⟩ variable {α} lemma const_apply' (a : α) (b : β) : (const α b : α → β) a = b := rfl /-- If the target space is inhabited, so is the space of bounded continuous functions -/ instance [inhabited β] : inhabited (α →ᵇ β) := ⟨const α default⟩ lemma lipschitz_evalx (x : α) : lipschitz_with 1 (λ f : α →ᵇ β, f x) := lipschitz_with.mk_one $ λ f g, dist_coe_le_dist x theorem uniform_continuous_coe : @uniform_continuous (α →ᵇ β) (α → β) _ _ coe_fn := uniform_continuous_pi.2 $ λ x, (lipschitz_evalx x).uniform_continuous lemma continuous_coe : continuous (λ (f : α →ᵇ β) x, f x) := uniform_continuous.continuous uniform_continuous_coe /-- When `x` is fixed, `(f : α →ᵇ β) ↦ f x` is continuous -/ @[continuity] theorem continuous_eval_const {x : α} : continuous (λ f : α →ᵇ β, f x) := (continuous_apply x).comp continuous_coe /-- The evaluation map is continuous, as a joint function of `u` and `x` -/ @[continuity] theorem continuous_eval : continuous (λ p : (α →ᵇ β) × α, p.1 p.2) := continuous_prod_of_continuous_lipschitz _ 1 (λ f, f.continuous) $ lipschitz_evalx /-- Bounded continuous functions taking values in a complete space form a complete space. -/ instance [complete_space β] : complete_space (α →ᵇ β) := complete_of_cauchy_seq_tendsto $ λ (f : ℕ → α →ᵇ β) (hf : cauchy_seq f), begin /- We have to show that `f n` converges to a bounded continuous function. For this, we prove pointwise convergence to define the limit, then check it is a continuous bounded function, and then check the norm convergence. -/ rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, have f_bdd := λx n m N hn hm, le_trans (dist_coe_le_dist x) (b_bound n m N hn hm), have fx_cau : ∀x, cauchy_seq (λn, f n x) := λx, cauchy_seq_iff_le_tendsto_0.2 ⟨b, b0, f_bdd x, b_lim⟩, choose F hF using λx, cauchy_seq_tendsto_of_complete (fx_cau x), /- F : α → β, hF : ∀ (x : α), tendsto (λ (n : ℕ), f n x) at_top (𝓝 (F x)) `F` is the desired limit function. Check that it is uniformly approximated by `f N` -/ have fF_bdd : ∀x N, dist (f N x) (F x) ≤ b N := λ x N, le_of_tendsto (tendsto_const_nhds.dist (hF x)) (filter.eventually_at_top.2 ⟨N, λn hn, f_bdd x N n N (le_refl N) hn⟩), refine ⟨⟨⟨F, _⟩, _⟩, _⟩, { /- Check that `F` is continuous, as a uniform limit of continuous functions -/ have : tendsto_uniformly (λn x, f n x) F at_top, { refine metric.tendsto_uniformly_iff.2 (λ ε ε0, _), refine ((tendsto_order.1 b_lim).2 ε ε0).mono (λ n hn x, _), rw dist_comm, exact lt_of_le_of_lt (fF_bdd x n) hn }, exact this.continuous (eventually_of_forall $ λ N, (f N).continuous) }, { /- Check that `F` is bounded -/ rcases (f 0).bounded with ⟨C, hC⟩, refine ⟨C + (b 0 + b 0), λ x y, _⟩, calc dist (F x) (F y) ≤ dist (f 0 x) (f 0 y) + (dist (f 0 x) (F x) + dist (f 0 y) (F y)) : dist_triangle4_left _ _ _ _ ... ≤ C + (b 0 + b 0) : by mono* }, { /- Check that `F` is close to `f N` in distance terms -/ refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero (λ _, dist_nonneg) _ b_lim), exact λ N, (dist_le (b0 _)).2 (λx, fF_bdd x N) } end /-- Composition of a bounded continuous function and a continuous function. -/ @[simps { fully_applied := ff }] def comp_continuous {δ : Type*} [topological_space δ] (f : α →ᵇ β) (g : C(δ, α)) : δ →ᵇ β := { to_continuous_map := f.1.comp g, map_bounded' := f.map_bounded'.imp (λ C hC x y, hC _ _) } lemma lipschitz_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) : lipschitz_with 1 (λ f : α →ᵇ β, f.comp_continuous g) := lipschitz_with.mk_one $ λ f₁ f₂, (dist_le dist_nonneg).2 $ λ x, dist_coe_le_dist (g x) lemma continuous_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) : continuous (λ f : α →ᵇ β, f.comp_continuous g) := (lipschitz_comp_continuous g).continuous /-- Restrict a bounded continuous function to a set. -/ @[simps apply { fully_applied := ff }] def restrict (f : α →ᵇ β) (s : set α) : s →ᵇ β := f.comp_continuous $ (continuous_map.id _).restrict s /-- Composition (in the target) of a bounded continuous function with a Lipschitz map again gives a bounded continuous function -/ def comp (G : β → γ) {C : ℝ≥0} (H : lipschitz_with C G) (f : α →ᵇ β) : α →ᵇ γ := ⟨⟨λx, G (f x), H.continuous.comp f.continuous⟩, let ⟨D, hD⟩ := f.bounded in ⟨max C 0 * D, λ x y, calc dist (G (f x)) (G (f y)) ≤ C * dist (f x) (f y) : H.dist_le_mul _ _ ... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left C 0) dist_nonneg ... ≤ max C 0 * D : mul_le_mul_of_nonneg_left (hD _ _) (le_max_right C 0)⟩⟩ /-- The composition operator (in the target) with a Lipschitz map is Lipschitz -/ lemma lipschitz_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) : lipschitz_with C (comp G H : (α →ᵇ β) → α →ᵇ γ) := lipschitz_with.of_dist_le_mul $ λ f g, (dist_le (mul_nonneg C.2 dist_nonneg)).2 $ λ x, calc dist (G (f x)) (G (g x)) ≤ C * dist (f x) (g x) : H.dist_le_mul _ _ ... ≤ C * dist f g : mul_le_mul_of_nonneg_left (dist_coe_le_dist _) C.2 /-- The composition operator (in the target) with a Lipschitz map is uniformly continuous -/ lemma uniform_continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) : uniform_continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) := (lipschitz_comp H).uniform_continuous /-- The composition operator (in the target) with a Lipschitz map is continuous -/ lemma continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) : continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) := (lipschitz_comp H).continuous /-- Restriction (in the target) of a bounded continuous function taking values in a subset -/ def cod_restrict (s : set β) (f : α →ᵇ β) (H : ∀x, f x ∈ s) : α →ᵇ s := ⟨⟨s.cod_restrict f H, f.continuous.subtype_mk _⟩, f.bounded⟩ section extend variables {δ : Type*} [topological_space δ] [discrete_topology δ] /-- A version of `function.extend` for bounded continuous maps. We assume that the domain has discrete topology, so we only need to verify boundedness. -/ def extend (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : δ →ᵇ β := { to_fun := extend f g h, continuous_to_fun := continuous_of_discrete_topology, map_bounded' := begin rw [← bounded_range_iff, range_extend f.injective, metric.bounded_union], exact ⟨g.bounded_range, h.bounded_image _⟩ end } @[simp] lemma extend_apply (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) (x : α) : extend f g h (f x) = g x := f.injective.extend_apply _ _ _ @[simp] lemma extend_comp (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : extend f g h ∘ f = g := extend_comp f.injective _ _ lemma extend_apply' {f : α ↪ δ} {x : δ} (hx : x ∉ range f) (g : α →ᵇ β) (h : δ →ᵇ β) : extend f g h x = h x := extend_apply' _ _ _ hx lemma extend_of_empty [is_empty α] (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : extend f g h = h := fun_like.coe_injective $ function.extend_of_empty f g h @[simp] lemma dist_extend_extend (f : α ↪ δ) (g₁ g₂ : α →ᵇ β) (h₁ h₂ : δ →ᵇ β) : dist (g₁.extend f h₁) (g₂.extend f h₂) = max (dist g₁ g₂) (dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ)) := begin refine le_antisymm ((dist_le $ le_max_iff.2 $ or.inl dist_nonneg).2 $ λ x, _) (max_le _ _), { rcases em (∃ y, f y = x) with (⟨x, rfl⟩|hx), { simp only [extend_apply], exact (dist_coe_le_dist x).trans (le_max_left _ _) }, { simp only [extend_apply' hx], lift x to ((range f)ᶜ : set δ) using hx, calc dist (h₁ x) (h₂ x) = dist (h₁.restrict (range f)ᶜ x) (h₂.restrict (range f)ᶜ x) : rfl ... ≤ dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ) : dist_coe_le_dist x ... ≤ _ : le_max_right _ _ } }, { refine (dist_le dist_nonneg).2 (λ x, _), rw [← extend_apply f g₁ h₁, ← extend_apply f g₂ h₂], exact dist_coe_le_dist _ }, { refine (dist_le dist_nonneg).2 (λ x, _), calc dist (h₁ x) (h₂ x) = dist (extend f g₁ h₁ x) (extend f g₂ h₂ x) : by rw [extend_apply' x.coe_prop, extend_apply' x.coe_prop] ... ≤ _ : dist_coe_le_dist _ } end lemma isometry_extend (f : α ↪ δ) (h : δ →ᵇ β) : isometry (λ g : α →ᵇ β, extend f g h) := isometry.of_dist_eq $ λ g₁ g₂, by simp [dist_nonneg] end extend end basics section arzela_ascoli variables [topological_space α] [compact_space α] [pseudo_metric_space β] variables {f g : α →ᵇ β} {x : α} {C : ℝ} /- Arzela-Ascoli theorem asserts that, on a compact space, a set of functions sharing a common modulus of continuity and taking values in a compact set forms a compact subset for the topology of uniform convergence. In this section, we prove this theorem and several useful variations around it. -/ /-- First version, with pointwise equicontinuity and range in a compact space -/ theorem arzela_ascoli₁ [compact_space β] (A : set (α →ᵇ β)) (closed : is_closed A) (H : equicontinuous (coe_fn : A → α → β)) : is_compact A := begin simp_rw [equicontinuous, metric.equicontinuous_at_iff_pair] at H, refine is_compact_of_totally_bounded_is_closed _ closed, refine totally_bounded_of_finite_discretization (λ ε ε0, _), rcases exists_between ε0 with ⟨ε₁, ε₁0, εε₁⟩, let ε₂ := ε₁/2/2, /- We have to find a finite discretization of `u`, i.e., finite information that is sufficient to reconstruct `u` up to ε. This information will be provided by the values of `u` on a sufficiently dense set tα, slightly translated to fit in a finite ε₂-dense set tβ in the image. Such sets exist by compactness of the source and range. Then, to check that these data determine the function up to ε, one uses the control on the modulus of continuity to extend the closeness on tα to closeness everywhere. -/ have ε₂0 : ε₂ > 0 := half_pos (half_pos ε₁0), have : ∀x:α, ∃U, x ∈ U ∧ is_open U ∧ ∀ (y z ∈ U) {f : α →ᵇ β}, f ∈ A → dist (f y) (f z) < ε₂ := λ x, let ⟨U, nhdsU, hU⟩ := H x _ ε₂0, ⟨V, VU, openV, xV⟩ := _root_.mem_nhds_iff.1 nhdsU in ⟨V, xV, openV, λy hy z hz f hf, hU y (VU hy) z (VU hz) ⟨f, hf⟩⟩, choose U hU using this, /- For all x, the set hU x is an open set containing x on which the elements of A fluctuate by at most ε₂. We extract finitely many of these sets that cover the whole space, by compactness -/ rcases is_compact_univ.elim_finite_subcover_image (λx _, (hU x).2.1) (λx hx, mem_bUnion (mem_univ _) (hU x).1) with ⟨tα, _, ⟨_⟩, htα⟩, /- tα : set α, htα : univ ⊆ ⋃x ∈ tα, U x -/ rcases @finite_cover_balls_of_compact β _ _ is_compact_univ _ ε₂0 with ⟨tβ, _, ⟨_⟩, htβ⟩, resetI, /- tβ : set β, htβ : univ ⊆ ⋃y ∈ tβ, ball y ε₂ -/ /- Associate to every point `y` in the space a nearby point `F y` in tβ -/ choose F hF using λy, show ∃z∈tβ, dist y z < ε₂, by simpa using htβ (mem_univ y), /- F : β → β, hF : ∀ (y : β), F y ∈ tβ ∧ dist y (F y) < ε₂ -/ /- Associate to every function a discrete approximation, mapping each point in `tα` to a point in `tβ` close to its true image by the function. -/ refine ⟨tα → tβ, by apply_instance, λ f a, ⟨F (f a), (hF (f a)).1⟩, _⟩, rintro ⟨f, hf⟩ ⟨g, hg⟩ f_eq_g, /- If two functions have the same approximation, then they are within distance ε -/ refine lt_of_le_of_lt ((dist_le $ le_of_lt ε₁0).2 (λ x, _)) εε₁, obtain ⟨x', x'tα, hx'⟩ : ∃x' ∈ tα, x ∈ U x' := mem_Union₂.1 (htα (mem_univ x)), calc dist (f x) (g x) ≤ dist (f x) (f x') + dist (g x) (g x') + dist (f x') (g x') : dist_triangle4_right _ _ _ _ ... ≤ ε₂ + ε₂ + ε₁/2 : le_of_lt (add_lt_add (add_lt_add _ _) _) ... = ε₁ : by rw [add_halves, add_halves], { exact (hU x').2.2 _ hx' _ ((hU x').1) hf }, { exact (hU x').2.2 _ hx' _ ((hU x').1) hg }, { have F_f_g : F (f x') = F (g x') := (congr_arg (λ f:tα → tβ, (f ⟨x', x'tα⟩ : β)) f_eq_g : _), calc dist (f x') (g x') ≤ dist (f x') (F (f x')) + dist (g x') (F (f x')) : dist_triangle_right _ _ _ ... = dist (f x') (F (f x')) + dist (g x') (F (g x')) : by rw F_f_g ... < ε₂ + ε₂ : add_lt_add (hF (f x')).2 (hF (g x')).2 ... = ε₁/2 : add_halves _ } end /-- Second version, with pointwise equicontinuity and range in a compact subset -/ theorem arzela_ascoli₂ (s : set β) (hs : is_compact s) (A : set (α →ᵇ β)) (closed : is_closed A) (in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s) (H : equicontinuous (coe_fn : A → α → β)) : is_compact A := /- This version is deduced from the previous one by restricting to the compact type in the target, using compactness there and then lifting everything to the original space. -/ begin have M : lipschitz_with 1 coe := lipschitz_with.subtype_coe s, let F : (α →ᵇ s) → α →ᵇ β := comp coe M, refine is_compact_of_is_closed_subset ((_ : is_compact (F ⁻¹' A)).image (continuous_comp M)) closed (λ f hf, _), { haveI : compact_space s := is_compact_iff_compact_space.1 hs, refine arzela_ascoli₁ _ (continuous_iff_is_closed.1 (continuous_comp M) _ closed) _, rw uniform_embedding_subtype_coe.to_uniform_inducing.equicontinuous_iff, exact H.comp (A.restrict_preimage F) }, { let g := cod_restrict s f (λx, in_s f x hf), rw [show f = F g, by ext; refl] at hf ⊢, exact ⟨g, hf, rfl⟩ } end /-- Third (main) version, with pointwise equicontinuity and range in a compact subset, but without closedness. The closure is then compact -/ theorem arzela_ascoli [t2_space β] (s : set β) (hs : is_compact s) (A : set (α →ᵇ β)) (in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s) (H : equicontinuous (coe_fn : A → α → β)) : is_compact (closure A) := /- This version is deduced from the previous one by checking that the closure of A, in addition to being closed, still satisfies the properties of compact range and equicontinuity -/ arzela_ascoli₂ s hs (closure A) is_closed_closure (λ f x hf, (mem_of_closed' hs.is_closed).2 $ λ ε ε0, let ⟨g, gA, dist_fg⟩ := metric.mem_closure_iff.1 hf ε ε0 in ⟨g x, in_s g x gA, lt_of_le_of_lt (dist_coe_le_dist _) dist_fg⟩) (H.closure' continuous_coe) end arzela_ascoli section has_one variables [topological_space α] [pseudo_metric_space β] [has_one β] @[to_additive] instance : has_one (α →ᵇ β) := ⟨const α 1⟩ @[simp, to_additive] lemma coe_one : ((1 : α →ᵇ β) : α → β) = 1 := rfl @[simp, to_additive] lemma mk_of_compact_one [compact_space α] : mk_of_compact (1 : C(α, β)) = 1 := rfl @[to_additive] lemma forall_coe_one_iff_one (f : α →ᵇ β) : (∀ x, f x = 1) ↔ f = 1 := (@fun_like.ext_iff _ _ _ _ f 1).symm @[simp, to_additive] lemma one_comp_continuous [topological_space γ] (f : C(γ, α)) : (1 : α →ᵇ β).comp_continuous f = 1 := rfl end has_one section has_lipschitz_add /- In this section, if `β` is an `add_monoid` whose addition operation is Lipschitz, then we show that the space of bounded continuous functions from `α` to `β` inherits a topological `add_monoid` structure, by using pointwise operations and checking that they are compatible with the uniform distance. Implementation note: The material in this section could have been written for `has_lipschitz_mul` and transported by `@[to_additive]`. We choose not to do this because this causes a few lemma names (for example, `coe_mul`) to conflict with later lemma names for normed rings; this is only a trivial inconvenience, but in any case there are no obvious applications of the multiplicative version. -/ variables [topological_space α] [pseudo_metric_space β] [add_monoid β] variables [has_lipschitz_add β] variables (f g : α →ᵇ β) {x : α} {C : ℝ} /-- The pointwise sum of two bounded continuous functions is again bounded continuous. -/ instance : has_add (α →ᵇ β) := { add := λ f g, bounded_continuous_function.mk_of_bound (f.to_continuous_map + g.to_continuous_map) (↑(has_lipschitz_add.C β) * max (classical.some f.bounded) (classical.some g.bounded)) begin intros x y, refine le_trans (lipschitz_with_lipschitz_const_add ⟨f x, g x⟩ ⟨f y, g y⟩) _, rw prod.dist_eq, refine mul_le_mul_of_nonneg_left _ (has_lipschitz_add.C β).coe_nonneg, apply max_le_max, exact classical.some_spec f.bounded x y, exact classical.some_spec g.bounded x y, end } @[simp] lemma coe_add : ⇑(f + g) = f + g := rfl lemma add_apply : (f + g) x = f x + g x := rfl @[simp] lemma mk_of_compact_add [compact_space α] (f g : C(α, β)) : mk_of_compact (f + g) = mk_of_compact f + mk_of_compact g := rfl lemma add_comp_continuous [topological_space γ] (h : C(γ, α)) : (g + f).comp_continuous h = g.comp_continuous h + f.comp_continuous h := rfl @[simp] lemma coe_nsmul_rec : ∀ n, ⇑(nsmul_rec n f) = n • f | 0 := by rw [nsmul_rec, zero_smul, coe_zero] | (n + 1) := by rw [nsmul_rec, succ_nsmul, coe_add, coe_nsmul_rec] instance has_nat_scalar : has_smul ℕ (α →ᵇ β) := { smul := λ n f, { to_continuous_map := n • f.to_continuous_map, map_bounded' := by simpa [coe_nsmul_rec] using (nsmul_rec n f).map_bounded' } } @[simp] lemma coe_nsmul (r : ℕ) (f : α →ᵇ β) : ⇑(r • f) = r • f := rfl @[simp] lemma nsmul_apply (r : ℕ) (f : α →ᵇ β) (v : α) : (r • f) v = r • f v := rfl instance : add_monoid (α →ᵇ β) := fun_like.coe_injective.add_monoid _ coe_zero coe_add (λ _ _, coe_nsmul _ _) instance : has_lipschitz_add (α →ᵇ β) := { lipschitz_add := ⟨has_lipschitz_add.C β, begin have C_nonneg := (has_lipschitz_add.C β).coe_nonneg, rw lipschitz_with_iff_dist_le_mul, rintros ⟨f₁, g₁⟩ ⟨f₂, g₂⟩, rw dist_le (mul_nonneg C_nonneg dist_nonneg), intros x, refine le_trans (lipschitz_with_lipschitz_const_add ⟨f₁ x, g₁ x⟩ ⟨f₂ x, g₂ x⟩) _, refine mul_le_mul_of_nonneg_left _ C_nonneg, apply max_le_max; exact dist_coe_le_dist x, end⟩ } /-- Coercion of a `normed_add_group_hom` is an `add_monoid_hom`. Similar to `add_monoid_hom.coe_fn`. -/ @[simps] def coe_fn_add_hom : (α →ᵇ β) →+ (α → β) := { to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add } variables (α β) /-- The additive map forgetting that a bounded continuous function is bounded. -/ @[simps] def to_continuous_map_add_hom : (α →ᵇ β) →+ C(α, β) := { to_fun := to_continuous_map, map_zero' := by { ext, simp, }, map_add' := by { intros, ext, simp, }, } end has_lipschitz_add section comm_has_lipschitz_add variables [topological_space α] [pseudo_metric_space β] [add_comm_monoid β] [has_lipschitz_add β] @[to_additive] instance : add_comm_monoid (α →ᵇ β) := { add_comm := assume f g, by ext; simp [add_comm], .. bounded_continuous_function.add_monoid } open_locale big_operators @[simp] lemma coe_sum {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) : ⇑(∑ i in s, f i) = (∑ i in s, (f i : α → β)) := (@coe_fn_add_hom α β _ _ _ _).map_sum f s lemma sum_apply {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) (a : α) : (∑ i in s, f i) a = (∑ i in s, f i a) := by simp end comm_has_lipschitz_add section normed_add_comm_group /- In this section, if β is a normed group, then we show that the space of bounded continuous functions from α to β inherits a normed group structure, by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables [topological_space α] [seminormed_add_comm_group β] variables (f g : α →ᵇ β) {x : α} {C : ℝ} instance : has_norm (α →ᵇ β) := ⟨λu, dist u 0⟩ lemma norm_def : ‖f‖ = dist f 0 := rfl /-- The norm of a bounded continuous function is the supremum of `‖f x‖`. We use `Inf` to ensure that the definition works if `α` has no elements. -/ lemma norm_eq (f : α →ᵇ β) : ‖f‖ = Inf {C : ℝ | 0 ≤ C ∧ ∀ (x : α), ‖f x‖ ≤ C} := by simp [norm_def, bounded_continuous_function.dist_eq] /-- When the domain is non-empty, we do not need the `0 ≤ C` condition in the formula for ‖f‖ as an `Inf`. -/ lemma norm_eq_of_nonempty [h : nonempty α] : ‖f‖ = Inf {C : ℝ | ∀ (x : α), ‖f x‖ ≤ C} := begin unfreezingI { obtain ⟨a⟩ := h, }, rw norm_eq, congr, ext, simp only [and_iff_right_iff_imp], exact λ h', le_trans (norm_nonneg (f a)) (h' a), end @[simp] lemma norm_eq_zero_of_empty [h : is_empty α] : ‖f‖ = 0 := dist_zero_of_empty lemma norm_coe_le_norm (x : α) : ‖f x‖ ≤ ‖f‖ := calc ‖f x‖ = dist (f x) ((0 : α →ᵇ β) x) : by simp [dist_zero_right] ... ≤ ‖f‖ : dist_coe_le_dist _ lemma dist_le_two_norm' {f : γ → β} {C : ℝ} (hC : ∀ x, ‖f x‖ ≤ C) (x y : γ) : dist (f x) (f y) ≤ 2 * C := calc dist (f x) (f y) ≤ ‖f x‖ + ‖f y‖ : dist_le_norm_add_norm _ _ ... ≤ C + C : add_le_add (hC x) (hC y) ... = 2 * C : (two_mul _).symm /-- Distance between the images of any two points is at most twice the norm of the function. -/ lemma dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ‖f‖ := dist_le_two_norm' f.norm_coe_le_norm x y variable {f} /-- The norm of a function is controlled by the supremum of the pointwise norms -/ lemma norm_le (C0 : (0 : ℝ) ≤ C) : ‖f‖ ≤ C ↔ ∀x:α, ‖f x‖ ≤ C := by simpa using @dist_le _ _ _ _ f 0 _ C0 lemma norm_le_of_nonempty [nonempty α] {f : α →ᵇ β} {M : ℝ} : ‖f‖ ≤ M ↔ ∀ x, ‖f x‖ ≤ M := begin simp_rw [norm_def, ←dist_zero_right], exact dist_le_iff_of_nonempty, end lemma norm_lt_iff_of_compact [compact_space α] {f : α →ᵇ β} {M : ℝ} (M0 : 0 < M) : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M := begin simp_rw [norm_def, ←dist_zero_right], exact dist_lt_iff_of_compact M0, end lemma norm_lt_iff_of_nonempty_compact [nonempty α] [compact_space α] {f : α →ᵇ β} {M : ℝ} : ‖f‖ < M ↔ ∀ x, ‖f x‖ < M := begin simp_rw [norm_def, ←dist_zero_right], exact dist_lt_iff_of_nonempty_compact, end variable (f) /-- Norm of `const α b` is less than or equal to `‖b‖`. If `α` is nonempty, then it is equal to `‖b‖`. -/ lemma norm_const_le (b : β) : ‖const α b‖ ≤ ‖b‖ := (norm_le (norm_nonneg b)).2 $ λ x, le_rfl @[simp] lemma norm_const_eq [h : nonempty α] (b : β) : ‖const α b‖ = ‖b‖ := le_antisymm (norm_const_le b) $ h.elim $ λ x, (const α b).norm_coe_le_norm x /-- Constructing a bounded continuous function from a uniformly bounded continuous function taking values in a normed group. -/ def of_normed_add_comm_group {α : Type u} {β : Type v} [topological_space α] [seminormed_add_comm_group β] (f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) : α →ᵇ β := ⟨⟨λn, f n, Hf⟩, ⟨_, dist_le_two_norm' H⟩⟩ @[simp] lemma coe_of_normed_add_comm_group {α : Type u} {β : Type v} [topological_space α] [seminormed_add_comm_group β] (f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) : (of_normed_add_comm_group f Hf C H : α → β) = f := rfl lemma norm_of_normed_add_comm_group_le {f : α → β} (hfc : continuous f) {C : ℝ} (hC : 0 ≤ C) (hfC : ∀ x, ‖f x‖ ≤ C) : ‖of_normed_add_comm_group f hfc C hfC‖ ≤ C := (norm_le hC).2 hfC /-- Constructing a bounded continuous function from a uniformly bounded function on a discrete space, taking values in a normed group -/ def of_normed_add_comm_group_discrete {α : Type u} {β : Type v} [topological_space α] [discrete_topology α] [seminormed_add_comm_group β] (f : α → β) (C : ℝ) (H : ∀x, norm (f x) ≤ C) : α →ᵇ β := of_normed_add_comm_group f continuous_of_discrete_topology C H @[simp] lemma coe_of_normed_add_comm_group_discrete {α : Type u} {β : Type v} [topological_space α] [discrete_topology α] [seminormed_add_comm_group β] (f : α → β) (C : ℝ) (H : ∀x, ‖f x‖ ≤ C) : (of_normed_add_comm_group_discrete f C H : α → β) = f := rfl /-- Taking the pointwise norm of a bounded continuous function with values in a `seminormed_add_comm_group` yields a bounded continuous function with values in ℝ. -/ def norm_comp : α →ᵇ ℝ := f.comp norm lipschitz_with_one_norm @[simp] lemma coe_norm_comp : (f.norm_comp : α → ℝ) = norm ∘ f := rfl @[simp] lemma norm_norm_comp : ‖f.norm_comp‖ = ‖f‖ := by simp only [norm_eq, coe_norm_comp, norm_norm] lemma bdd_above_range_norm_comp : bdd_above $ set.range $ norm ∘ f := (real.bounded_iff_bdd_below_bdd_above.mp $ @bounded_range _ _ _ _ f.norm_comp).2 lemma norm_eq_supr_norm : ‖f‖ = ⨆ x : α, ‖f x‖ := by simp_rw [norm_def, dist_eq_supr, coe_zero, pi.zero_apply, dist_zero_right] /-- If `‖(1 : β)‖ = 1`, then `‖(1 : α →ᵇ β)‖ = 1` if `α` is nonempty. -/ instance [nonempty α] [has_one β] [norm_one_class β] : norm_one_class (α →ᵇ β) := { norm_one := by simp only [norm_eq_supr_norm, coe_one, pi.one_apply, norm_one, csupr_const] } /-- The pointwise opposite of a bounded continuous function is again bounded continuous. -/ instance : has_neg (α →ᵇ β) := ⟨λf, of_normed_add_comm_group (-f) f.continuous.neg ‖f‖ $ λ x, trans_rel_right _ (norm_neg _) (f.norm_coe_le_norm x)⟩ /-- The pointwise difference of two bounded continuous functions is again bounded continuous. -/ instance : has_sub (α →ᵇ β) := ⟨λf g, of_normed_add_comm_group (f - g) (f.continuous.sub g.continuous) (‖f‖ + ‖g‖) $ λ x, by { simp only [sub_eq_add_neg], exact le_trans (norm_add_le _ _) (add_le_add (f.norm_coe_le_norm x) $ trans_rel_right _ (norm_neg _) (g.norm_coe_le_norm x)) }⟩ @[simp] lemma coe_neg : ⇑(-f) = -f := rfl lemma neg_apply : (-f) x = -f x := rfl @[simp] lemma coe_sub : ⇑(f - g) = f - g := rfl lemma sub_apply : (f - g) x = f x - g x := rfl @[simp] lemma mk_of_compact_neg [compact_space α] (f : C(α, β)) : mk_of_compact (-f) = -mk_of_compact f := rfl @[simp] lemma mk_of_compact_sub [compact_space α] (f g : C(α, β)) : mk_of_compact (f - g) = mk_of_compact f - mk_of_compact g := rfl @[simp] lemma coe_zsmul_rec : ∀ z, ⇑(zsmul_rec z f) = z • f | (int.of_nat n) := by rw [zsmul_rec, int.of_nat_eq_coe, coe_nsmul_rec, coe_nat_zsmul] | -[1+ n] := by rw [zsmul_rec, zsmul_neg_succ_of_nat, coe_neg, coe_nsmul_rec] instance has_int_scalar : has_smul ℤ (α →ᵇ β) := { smul := λ n f, { to_continuous_map := n • f.to_continuous_map, map_bounded' := by simpa using (zsmul_rec n f).map_bounded' } } @[simp] lemma coe_zsmul (r : ℤ) (f : α →ᵇ β) : ⇑(r • f) = r • f := rfl @[simp] lemma zsmul_apply (r : ℤ) (f : α →ᵇ β) (v : α) : (r • f) v = r • f v := rfl instance : add_comm_group (α →ᵇ β) := fun_like.coe_injective.add_comm_group _ coe_zero coe_add coe_neg coe_sub (λ _ _, coe_nsmul _ _) (λ _ _, coe_zsmul _ _) instance : seminormed_add_comm_group (α →ᵇ β) := { dist_eq := λ f g, by simp only [norm_eq, dist_eq, dist_eq_norm, sub_apply] } instance {α β} [topological_space α] [normed_add_comm_group β] : normed_add_comm_group (α →ᵇ β) := { ..bounded_continuous_function.seminormed_add_comm_group } lemma nnnorm_def : ‖f‖₊ = nndist f 0 := rfl lemma nnnorm_coe_le_nnnorm (x : α) : ‖f x‖₊ ≤ ‖f‖₊ := norm_coe_le_norm _ _ lemma nndist_le_two_nnnorm (x y : α) : nndist (f x) (f y) ≤ 2 * ‖f‖₊ := dist_le_two_norm _ _ _ /-- The nnnorm of a function is controlled by the supremum of the pointwise nnnorms -/ lemma nnnorm_le (C : ℝ≥0) : ‖f‖₊ ≤ C ↔ ∀x:α, ‖f x‖₊ ≤ C := norm_le C.prop lemma nnnorm_const_le (b : β) : ‖const α b‖₊ ≤ ‖b‖₊ := norm_const_le _ @[simp] lemma nnnorm_const_eq [h : nonempty α] (b : β) : ‖const α b‖₊ = ‖b‖₊ := subtype.ext $ norm_const_eq _ lemma nnnorm_eq_supr_nnnorm : ‖f‖₊ = ⨆ x : α, ‖f x‖₊ := subtype.ext $ (norm_eq_supr_norm f).trans $ by simp_rw [nnreal.coe_supr, coe_nnnorm] lemma abs_diff_coe_le_dist : ‖f x - g x‖ ≤ dist f g := by { rw dist_eq_norm, exact (f - g).norm_coe_le_norm x } lemma coe_le_coe_add_dist {f g : α →ᵇ ℝ} : f x ≤ g x + dist f g := sub_le_iff_le_add'.1 $ (abs_le.1 $ @dist_coe_le_dist _ _ _ _ f g x).2 lemma norm_comp_continuous_le [topological_space γ] (f : α →ᵇ β) (g : C(γ, α)) : ‖f.comp_continuous g‖ ≤ ‖f‖ := ((lipschitz_comp_continuous g).dist_le_mul f 0).trans $ by rw [nnreal.coe_one, one_mul, dist_zero_right] end normed_add_comm_group section has_bounded_smul /-! ### `has_bounded_smul` (in particular, topological module) structure In this section, if `β` is a metric space and a `𝕜`-module whose addition and scalar multiplication are compatible with the metric structure, then we show that the space of bounded continuous functions from `α` to `β` inherits a so-called `has_bounded_smul` structure (in particular, a `has_continuous_mul` structure, which is the mathlib formulation of being a topological module), by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables {𝕜 : Type*} [pseudo_metric_space 𝕜] [topological_space α] [pseudo_metric_space β] section has_smul variables [has_zero 𝕜] [has_zero β] [has_smul 𝕜 β] [has_bounded_smul 𝕜 β] instance : has_smul 𝕜 (α →ᵇ β) := { smul := λ c f, { to_continuous_map := c • f.to_continuous_map, map_bounded' := let ⟨b, hb⟩ := f.bounded in ⟨dist c 0 * b, λ x y, begin refine (dist_smul_pair c (f x) (f y)).trans _, refine mul_le_mul_of_nonneg_left _ dist_nonneg, exact hb x y end⟩ } } @[simp] lemma coe_smul (c : 𝕜) (f : α →ᵇ β) : ⇑(c • f) = λ x, c • (f x) := rfl lemma smul_apply (c : 𝕜) (f : α →ᵇ β) (x : α) : (c • f) x = c • f x := rfl instance [has_smul 𝕜ᵐᵒᵖ β] [is_central_scalar 𝕜 β] : is_central_scalar 𝕜 (α →ᵇ β) := { op_smul_eq_smul := λ _ _, ext $ λ _, op_smul_eq_smul _ _ } instance : has_bounded_smul 𝕜 (α →ᵇ β) := { dist_smul_pair' := λ c f₁ f₂, begin rw dist_le (mul_nonneg dist_nonneg dist_nonneg), intros x, refine (dist_smul_pair c (f₁ x) (f₂ x)).trans _, exact mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg end, dist_pair_smul' := λ c₁ c₂ f, begin rw dist_le (mul_nonneg dist_nonneg dist_nonneg), intros x, refine (dist_pair_smul c₁ c₂ (f x)).trans _, convert mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg, simp end } end has_smul section mul_action variables [monoid_with_zero 𝕜] [has_zero β] [mul_action 𝕜 β] [has_bounded_smul 𝕜 β] instance : mul_action 𝕜 (α →ᵇ β) := fun_like.coe_injective.mul_action _ coe_smul end mul_action section distrib_mul_action variables [monoid_with_zero 𝕜] [add_monoid β] [distrib_mul_action 𝕜 β] [has_bounded_smul 𝕜 β] variables [has_lipschitz_add β] instance : distrib_mul_action 𝕜 (α →ᵇ β) := function.injective.distrib_mul_action ⟨_, coe_zero, coe_add⟩ fun_like.coe_injective coe_smul end distrib_mul_action section module variables [semiring 𝕜] [add_comm_monoid β] [module 𝕜 β] [has_bounded_smul 𝕜 β] variables {f g : α →ᵇ β} {x : α} {C : ℝ} variables [has_lipschitz_add β] instance : module 𝕜 (α →ᵇ β) := function.injective.module _ ⟨_, coe_zero, coe_add⟩ fun_like.coe_injective coe_smul variables (𝕜) /-- The evaluation at a point, as a continuous linear map from `α →ᵇ β` to `β`. -/ def eval_clm (x : α) : (α →ᵇ β) →L[𝕜] β := { to_fun := λ f, f x, map_add' := λ f g, add_apply _ _, map_smul' := λ c f, smul_apply _ _ _ } @[simp] lemma eval_clm_apply (x : α) (f : α →ᵇ β) : eval_clm 𝕜 x f = f x := rfl variables (α β) /-- The linear map forgetting that a bounded continuous function is bounded. -/ @[simps] def to_continuous_map_linear_map : (α →ᵇ β) →ₗ[𝕜] C(α, β) := { to_fun := to_continuous_map, map_smul' := λ f g, rfl, map_add' := λ c f, rfl } end module end has_bounded_smul section normed_space /-! ### Normed space structure In this section, if `β` is a normed space, then we show that the space of bounded continuous functions from `α` to `β` inherits a normed space structure, by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables {𝕜 : Type*} variables [topological_space α] [seminormed_add_comm_group β] variables {f g : α →ᵇ β} {x : α} {C : ℝ} instance [normed_field 𝕜] [normed_space 𝕜 β] : normed_space 𝕜 (α →ᵇ β) := ⟨λ c f, begin refine norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _, exact (λ x, trans_rel_right _ (norm_smul _ _) (mul_le_mul_of_nonneg_left (f.norm_coe_le_norm _) (norm_nonneg _))) end⟩ variables [nontrivially_normed_field 𝕜] [normed_space 𝕜 β] variables [seminormed_add_comm_group γ] [normed_space 𝕜 γ] variables (α) -- TODO does this work in the `has_bounded_smul` setting, too? /-- Postcomposition of bounded continuous functions into a normed module by a continuous linear map is a continuous linear map. Upgraded version of `continuous_linear_map.comp_left_continuous`, similar to `linear_map.comp_left`. -/ protected def _root_.continuous_linear_map.comp_left_continuous_bounded (g : β →L[𝕜] γ) : (α →ᵇ β) →L[𝕜] (α →ᵇ γ) := linear_map.mk_continuous { to_fun := λ f, of_normed_add_comm_group (g ∘ f) (g.continuous.comp f.continuous) (‖g‖ * ‖f‖) (λ x, (g.le_op_norm_of_le (f.norm_coe_le_norm x))), map_add' := λ f g, by ext; simp, map_smul' := λ c f, by ext; simp } ‖g‖ (λ f, norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg g) (norm_nonneg f)) _) @[simp] lemma _root_.continuous_linear_map.comp_left_continuous_bounded_apply (g : β →L[𝕜] γ) (f : α →ᵇ β) (x : α) : (g.comp_left_continuous_bounded α f) x = g (f x) := rfl end normed_space section normed_ring /-! ### Normed ring structure In this section, if `R` is a normed ring, then we show that the space of bounded continuous functions from `α` to `R` inherits a normed ring structure, by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables [topological_space α] {R : Type*} section non_unital section semi_normed variables [non_unital_semi_normed_ring R] instance : has_mul (α →ᵇ R) := { mul := λ f g, of_normed_add_comm_group (f * g) (f.continuous.mul g.continuous) (‖f‖ * ‖g‖) $ λ x, le_trans (norm_mul_le (f x) (g x)) $ mul_le_mul (f.norm_coe_le_norm x) (g.norm_coe_le_norm x) (norm_nonneg _) (norm_nonneg _) } @[simp] lemma coe_mul (f g : α →ᵇ R) : ⇑(f * g) = f * g := rfl lemma mul_apply (f g : α →ᵇ R) (x : α) : (f * g) x = f x * g x := rfl instance : non_unital_ring (α →ᵇ R) := fun_like.coe_injective.non_unital_ring _ coe_zero coe_add coe_mul coe_neg coe_sub (λ _ _, coe_nsmul _ _) (λ _ _, coe_zsmul _ _) instance : non_unital_semi_normed_ring (α →ᵇ R) := { norm_mul := λ f g, norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _, .. bounded_continuous_function.seminormed_add_comm_group } end semi_normed instance [non_unital_normed_ring R] : non_unital_normed_ring (α →ᵇ R) := { .. bounded_continuous_function.non_unital_semi_normed_ring, .. bounded_continuous_function.normed_add_comm_group } end non_unital section semi_normed variables [semi_normed_ring R] @[simp] lemma coe_npow_rec (f : α →ᵇ R) : ∀ n, ⇑(npow_rec n f) = f ^ n | 0 := by rw [npow_rec, pow_zero, coe_one] | (n + 1) := by rw [npow_rec, pow_succ, coe_mul, coe_npow_rec] instance has_nat_pow : has_pow (α →ᵇ R) ℕ := { pow := λ f n, { to_continuous_map := f.to_continuous_map ^ n, map_bounded' := by simpa [coe_npow_rec] using (npow_rec n f).map_bounded' } } @[simp] lemma coe_pow (n : ℕ) (f : α →ᵇ R) : ⇑(f ^ n) = f ^ n := rfl @[simp] lemma pow_apply (n : ℕ) (f : α →ᵇ R) (v : α) : (f ^ n) v = f v ^ n := rfl instance : has_nat_cast (α →ᵇ R) := ⟨λ n, bounded_continuous_function.const _ n⟩ @[simp, norm_cast] lemma coe_nat_cast (n : ℕ) : ((n : α →ᵇ R) : α → R) = n := rfl instance : has_int_cast (α →ᵇ R) := ⟨λ n, bounded_continuous_function.const _ n⟩ @[simp, norm_cast] lemma coe_int_cast (n : ℤ) : ((n : α →ᵇ R) : α → R) = n := rfl instance : ring (α →ᵇ R) := fun_like.coe_injective.ring _ coe_zero coe_one coe_add coe_mul coe_neg coe_sub (λ _ _, coe_nsmul _ _) (λ _ _, coe_zsmul _ _) (λ _ _, coe_pow _ _) coe_nat_cast coe_int_cast instance : semi_normed_ring (α →ᵇ R) := { ..bounded_continuous_function.non_unital_semi_normed_ring } end semi_normed instance [normed_ring R] : normed_ring (α →ᵇ R) := { ..bounded_continuous_function.non_unital_normed_ring } end normed_ring section normed_comm_ring /-! ### Normed commutative ring structure In this section, if `R` is a normed commutative ring, then we show that the space of bounded continuous functions from `α` to `R` inherits a normed commutative ring structure, by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables [topological_space α] {R : Type*} instance [semi_normed_comm_ring R] : comm_ring (α →ᵇ R) := { mul_comm := λ f₁ f₂, ext $ λ x, mul_comm _ _, .. bounded_continuous_function.ring } instance [semi_normed_comm_ring R] : semi_normed_comm_ring (α →ᵇ R) := { ..bounded_continuous_function.comm_ring, ..bounded_continuous_function.seminormed_add_comm_group } instance [normed_comm_ring R] : normed_comm_ring (α →ᵇ R) := { .. bounded_continuous_function.comm_ring, .. bounded_continuous_function.normed_add_comm_group } end normed_comm_ring section normed_algebra /-! ### Normed algebra structure In this section, if `γ` is a normed algebra, then we show that the space of bounded continuous functions from `α` to `γ` inherits a normed algebra structure, by using pointwise operations and checking that they are compatible with the uniform distance. -/ variables {𝕜 : Type*} [normed_field 𝕜] variables [topological_space α] [seminormed_add_comm_group β] [normed_space 𝕜 β] variables [normed_ring γ] [normed_algebra 𝕜 γ] variables {f g : α →ᵇ γ} {x : α} {c : 𝕜} /-- `bounded_continuous_function.const` as a `ring_hom`. -/ def C : 𝕜 →+* (α →ᵇ γ) := { to_fun := λ (c : 𝕜), const α ((algebra_map 𝕜 γ) c), map_one' := ext $ λ x, (algebra_map 𝕜 γ).map_one, map_mul' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_mul _ _, map_zero' := ext $ λ x, (algebra_map 𝕜 γ).map_zero, map_add' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_add _ _ } instance : algebra 𝕜 (α →ᵇ γ) := { to_ring_hom := C, commutes' := λ c f, ext $ λ x, algebra.commutes' _ _, smul_def' := λ c f, ext $ λ x, algebra.smul_def' _ _, ..bounded_continuous_function.module, ..bounded_continuous_function.ring } @[simp] lemma algebra_map_apply (k : 𝕜) (a : α) : algebra_map 𝕜 (α →ᵇ γ) k a = k • 1 := by { rw algebra.algebra_map_eq_smul_one, refl, } instance : normed_algebra 𝕜 (α →ᵇ γ) := { ..bounded_continuous_function.normed_space } /-! ### Structure as normed module over scalar functions If `β` is a normed `𝕜`-space, then we show that the space of bounded continuous functions from `α` to `β` is naturally a module over the algebra of bounded continuous functions from `α` to `𝕜`. -/ instance has_smul' : has_smul (α →ᵇ 𝕜) (α →ᵇ β) := ⟨λ (f : α →ᵇ 𝕜) (g : α →ᵇ β), of_normed_add_comm_group (λ x, (f x) • (g x)) (f.continuous.smul g.continuous) (‖f‖ * ‖g‖) (λ x, calc ‖f x • g x‖ ≤ ‖f x‖ * ‖g x‖ : normed_space.norm_smul_le _ _ ... ≤ ‖f‖ * ‖g‖ : mul_le_mul (f.norm_coe_le_norm _) (g.norm_coe_le_norm _) (norm_nonneg _) (norm_nonneg _)) ⟩ instance module' : module (α →ᵇ 𝕜) (α →ᵇ β) := module.of_core $ { smul := (•), smul_add := λ c f₁ f₂, ext $ λ x, smul_add _ _ _, add_smul := λ c₁ c₂ f, ext $ λ x, add_smul _ _ _, mul_smul := λ c₁ c₂ f, ext $ λ x, mul_smul _ _ _, one_smul := λ f, ext $ λ x, one_smul 𝕜 (f x) } lemma norm_smul_le (f : α →ᵇ 𝕜) (g : α →ᵇ β) : ‖f • g‖ ≤ ‖f‖ * ‖g‖ := norm_of_normed_add_comm_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _ /- TODO: When `normed_module` has been added to `normed_space.basic`, the above facts show that the space of bounded continuous functions from `α` to `β` is naturally a normed module over the algebra of bounded continuous functions from `α` to `𝕜`. -/ end normed_algebra lemma nnreal.upper_bound {α : Type*} [topological_space α] (f : α →ᵇ ℝ≥0) (x : α) : f x ≤ nndist f 0 := begin have key : nndist (f x) ((0 : α →ᵇ ℝ≥0) x) ≤ nndist f 0, { exact @dist_coe_le_dist α ℝ≥0 _ _ f 0 x, }, simp only [coe_zero, pi.zero_apply] at key, rwa nnreal.nndist_zero_eq_val' (f x) at key, end /-! ### Star structures In this section, if `β` is a normed ⋆-group, then so is the space of bounded continuous functions from `α` to `β`, by using the star operation pointwise. If `𝕜` is normed field and a ⋆-ring over which `β` is a normed algebra and a star module, then the space of bounded continuous functions from `α` to `β` is a star module. If `β` is a ⋆-ring in addition to being a normed ⋆-group, then `α →ᵇ β` inherits a ⋆-ring structure. In summary, if `β` is a C⋆-algebra over `𝕜`, then so is `α →ᵇ β`; note that completeness is guaranteed when `β` is complete (see `bounded_continuous_function.complete`). -/ section normed_add_comm_group variables {𝕜 : Type*} [normed_field 𝕜] [star_ring 𝕜] [topological_space α] [seminormed_add_comm_group β] [star_add_monoid β] [normed_star_group β] variables [normed_space 𝕜 β] [star_module 𝕜 β] instance : star_add_monoid (α →ᵇ β) := { star := λ f, f.comp star star_normed_add_group_hom.lipschitz, star_involutive := λ f, ext $ λ x, star_star (f x), star_add := λ f g, ext $ λ x, star_add (f x) (g x) } /-- The right-hand side of this equality can be parsed `star ∘ ⇑f` because of the instance `pi.has_star`. Upon inspecting the goal, one sees `⊢ ⇑(star f) = star ⇑f`.-/ @[simp] lemma coe_star (f : α →ᵇ β) : ⇑(star f) = star f := rfl @[simp] lemma star_apply (f : α →ᵇ β) (x : α) : star f x = star (f x) := rfl instance : normed_star_group (α →ᵇ β) := { norm_star := λ f, by simp only [norm_eq, star_apply, norm_star] } instance : star_module 𝕜 (α →ᵇ β) := { star_smul := λ k f, ext $ λ x, star_smul k (f x) } end normed_add_comm_group section cstar_ring variables [topological_space α] variables [non_unital_normed_ring β] [star_ring β] instance [normed_star_group β] : star_ring (α →ᵇ β) := { star_mul := λ f g, ext $ λ x, star_mul (f x) (g x), ..bounded_continuous_function.star_add_monoid } variable [cstar_ring β] instance : cstar_ring (α →ᵇ β) := { norm_star_mul_self := begin intro f, refine le_antisymm _ _, { rw [←sq, norm_le (sq_nonneg _)], dsimp [star_apply], intro x, rw [cstar_ring.norm_star_mul_self, ←sq], refine sq_le_sq' _ _, { linarith [norm_nonneg (f x), norm_nonneg f] }, { exact norm_coe_le_norm f x }, }, { rw [←sq, ←real.le_sqrt (norm_nonneg _) (norm_nonneg _), norm_le (real.sqrt_nonneg _)], intro x, rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ←cstar_ring.norm_star_mul_self], exact norm_coe_le_norm (star f * f) x } end } end cstar_ring section normed_lattice_ordered_group variables [topological_space α] [normed_lattice_add_comm_group β] instance : partial_order (α →ᵇ β) := partial_order.lift (λ f, f.to_fun) (by tidy) /-- Continuous normed lattice group valued functions form a meet-semilattice -/ instance : semilattice_inf (α →ᵇ β) := { inf := λ f g, { to_fun := λ t, f t ⊓ g t, continuous_to_fun := f.continuous.inf g.continuous, map_bounded' := begin obtain ⟨C₁, hf⟩ := f.bounded, obtain ⟨C₂, hg⟩ := g.bounded, refine ⟨C₁ + C₂, λ x y, _⟩, simp_rw normed_add_comm_group.dist_eq at hf hg ⊢, exact (norm_inf_sub_inf_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)), end }, inf_le_left := λ f g, continuous_map.le_def.mpr (λ _, inf_le_left), inf_le_right := λ f g, continuous_map.le_def.mpr (λ _, inf_le_right), le_inf := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, le_inf (continuous_map.le_def.mp w₁ _) (continuous_map.le_def.mp w₂ _)), ..bounded_continuous_function.partial_order } instance : semilattice_sup (α →ᵇ β) := { sup := λ f g, { to_fun := λ t, f t ⊔ g t, continuous_to_fun := f.continuous.sup g.continuous, map_bounded' := begin obtain ⟨C₁, hf⟩ := f.bounded, obtain ⟨C₂, hg⟩ := g.bounded, refine ⟨C₁ + C₂, λ x y, _⟩, simp_rw normed_add_comm_group.dist_eq at hf hg ⊢, exact (norm_sup_sub_sup_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)), end }, le_sup_left := λ f g, continuous_map.le_def.mpr (λ _, le_sup_left), le_sup_right := λ f g, continuous_map.le_def.mpr (λ _, le_sup_right), sup_le := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, sup_le (continuous_map.le_def.mp w₁ _) (continuous_map.le_def.mp w₂ _)), ..bounded_continuous_function.partial_order } instance : lattice (α →ᵇ β) := { .. bounded_continuous_function.semilattice_sup, .. bounded_continuous_function.semilattice_inf } @[simp] lemma coe_fn_sup (f g : α →ᵇ β) : ⇑(f ⊔ g) = f ⊔ g := rfl @[simp] lemma coe_fn_abs (f : α →ᵇ β) : ⇑|f| = |f| := rfl instance : normed_lattice_add_comm_group (α →ᵇ β) := { add_le_add_left := begin intros f g h₁ h t, simp only [coe_to_continuous_fun, pi.add_apply, add_le_add_iff_left, coe_add, continuous_map.to_fun_eq_coe], exact h₁ _, end, solid := begin intros f g h, have i1: ∀ t, ‖f t‖ ≤ ‖g t‖ := λ t, solid (h t), rw norm_le (norm_nonneg _), exact λ t, (i1 t).trans (norm_coe_le_norm g t), end, ..bounded_continuous_function.lattice, ..bounded_continuous_function.seminormed_add_comm_group } end normed_lattice_ordered_group section nonnegative_part variables [topological_space α] /-- The nonnegative part of a bounded continuous `ℝ`-valued function as a bounded continuous `ℝ≥0`-valued function. -/ def nnreal_part (f : α →ᵇ ℝ) : α →ᵇ ℝ≥0 := bounded_continuous_function.comp _ (show lipschitz_with 1 real.to_nnreal, from lipschitz_with_pos) f @[simp] lemma nnreal_part_coe_fun_eq (f : α →ᵇ ℝ) : ⇑(f.nnreal_part) = real.to_nnreal ∘ ⇑f := rfl /-- The absolute value of a bounded continuous `ℝ`-valued function as a bounded continuous `ℝ≥0`-valued function. -/ def nnnorm (f : α →ᵇ ℝ) : α →ᵇ ℝ≥0 := bounded_continuous_function.comp _ (show lipschitz_with 1 (λ (x : ℝ), ‖x‖₊), from lipschitz_with_one_norm) f @[simp] lemma nnnorm_coe_fun_eq (f : α →ᵇ ℝ) : ⇑(f.nnnorm) = has_nnnorm.nnnorm ∘ ⇑f := rfl /-- Decompose a bounded continuous function to its positive and negative parts. -/ lemma self_eq_nnreal_part_sub_nnreal_part_neg (f : α →ᵇ ℝ) : ⇑f = coe ∘ f.nnreal_part - coe ∘ (-f).nnreal_part := by { funext x, dsimp, simp only [max_zero_sub_max_neg_zero_eq_self], } /-- Express the absolute value of a bounded continuous function in terms of its positive and negative parts. -/ lemma abs_self_eq_nnreal_part_add_nnreal_part_neg (f : α →ᵇ ℝ) : abs ∘ ⇑f = coe ∘ f.nnreal_part + coe ∘ (-f).nnreal_part := by { funext x, dsimp, simp only [max_zero_add_max_neg_zero_eq_abs_self], } end nonnegative_part end bounded_continuous_function
d08d071a198a83d1ee47b03b59631e7d2fe16550
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
/library/tools/super/cdcl_solver.lean
f7eac8e3da6f31faa9cf749e90ee0bb66fba0708
[ "Apache-2.0" ]
permissive
pacchiano/lean
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
fdadada3a970377a6df8afcd629a6f2eab6e84e8
refs/heads/master
1,611,357,380,399
1,489,870,101,000
1,489,870,101,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,076
lean
/- Copyright (c) 2016 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import .clause open tactic expr monad super namespace cdcl @[reducible] meta def prop_var := expr @[reducible] meta def proof_term := expr @[reducible] meta def proof_hyp := expr meta inductive trail_elem | dec : prop_var → bool → proof_hyp → trail_elem | propg : prop_var → bool → proof_term → proof_hyp → trail_elem | dbl_neg_propg : prop_var → bool → proof_term → proof_hyp → trail_elem namespace trail_elem meta def var : trail_elem → prop_var | (dec v _ _) := v | (propg v _ _ _) := v | (dbl_neg_propg v _ _ _) := v meta def phase : trail_elem → bool | (dec _ ph _) := ph | (propg _ ph _ _) := ph | (dbl_neg_propg _ ph _ _) := ph meta def hyp : trail_elem → proof_hyp | (dec _ _ h) := h | (propg _ _ _ h) := h | (dbl_neg_propg _ _ _ h) := h meta def is_decision : trail_elem → bool | (dec _ _ _) := tt | (propg _ _ _ _) := ff | (dbl_neg_propg _ _ _ _) := ff end trail_elem meta structure var_state := (phase : bool) (assigned : option proof_hyp) meta structure learned_clause := (c : clause) (actual_proof : proof_term) meta inductive prop_lit | neg : prop_var → prop_lit | pos : prop_var → prop_lit namespace prop_lit meta instance : has_ordering prop_lit := ⟨λl₁ l₂, match l₁, l₂ with | pos _, neg _ := ordering.gt | neg _, pos _ := ordering.lt | pos v₁, pos v₂ := has_ordering.cmp v₁ v₂ | neg v₁, neg v₂ := has_ordering.cmp v₁ v₂ end⟩ meta def of_cls_lit : clause.literal → prop_lit | (clause.literal.left v) := neg v | (clause.literal.right v) := pos v meta def of_var_and_phase (v : prop_var) : bool → prop_lit | tt := pos v | ff := neg v end prop_lit meta def watch_map := rb_map name (ℕ × ℕ × clause) meta structure state := (trail : list trail_elem) (vars : rb_map prop_var var_state) (unassigned : rb_map prop_var prop_var) (clauses : list clause) (learned : list learned_clause) (watches : rb_map prop_lit watch_map) (conflict : option proof_term) (unitp_queue : list prop_var) (local_false : expr) namespace state meta def initial (local_false : expr) : state := { trail := [], vars := rb_map.mk _ _, unassigned := rb_map.mk _ _, clauses := [], learned := [], watches := rb_map.mk _ _, conflict := none, unitp_queue := [], local_false := local_false } meta def watches_for (st : state) (pl : prop_lit) : watch_map := (st^.watches^.find pl)^.get_or_else (rb_map.mk _ _) end state meta def solver := state_t state tactic meta instance : monad solver := state_t.monad _ _ meta instance : has_monad_lift tactic solver := monad.monad_transformer_lift (state_t state) tactic meta instance (α : Type) : has_coe (tactic α) (solver α) := ⟨monad.monad_lift⟩ meta def fail {A B} [has_to_format B] (b : B) : solver A := @tactic.fail A B _ b meta def get_local_false : solver expr := do st ← state_t.read, return st^.local_false meta def mk_var_core (v : prop_var) (ph : bool) : solver unit := do state_t.modify $ λst, match st^.vars^.find v with | (some _) := st | none := { st with vars := st^.vars^.insert v ⟨ph, none⟩, unassigned := st^.unassigned^.insert v v } end meta def mk_var (v : prop_var) : solver unit := mk_var_core v ff meta def set_conflict (proof : proof_term) : solver unit := state_t.modify $ λst, { st with conflict := some proof } meta def has_conflict : solver bool := do st ← state_t.read, return st^.conflict^.is_some meta def push_trail (elem : trail_elem) : solver unit := do st ← state_t.read, match st^.vars^.find elem^.var with | none := fail $ "unknown variable: " ++ elem^.var^.to_string | some ⟨_, some _⟩ := fail $ "adding already assigned variable to trail: " ++ elem^.var^.to_string | some ⟨_, none⟩ := state_t.write { st with vars := st^.vars^.insert elem^.var ⟨elem^.phase, some elem^.hyp⟩, unassigned := st^.unassigned^.erase elem^.var, trail := elem :: st^.trail, unitp_queue := elem^.var :: st^.unitp_queue } end meta def pop_trail_core : solver (option trail_elem) := do st ← state_t.read, match st^.trail with | elem :: rest := do state_t.write { st with trail := rest, vars := st^.vars^.insert elem^.var ⟨elem^.phase, none⟩, unassigned := st^.unassigned^.insert elem^.var elem^.var, unitp_queue := [] }, return $ some elem | [] := return none end meta def is_decision_level_zero : solver bool := do st ← state_t.read, return $ st^.trail^.for_all $ λelem, ¬elem^.is_decision meta def revert_to_decision_level_zero : unit → solver unit | () := do is_dl0 ← is_decision_level_zero, if is_dl0 then return () else do pop_trail_core, revert_to_decision_level_zero () meta def formula_of_lit (local_false : expr) (v : prop_var) (ph : bool) := if ph then v else imp v local_false meta def lookup_var (v : prop_var) : solver (option var_state) := do st ← state_t.read, return $ st^.vars^.find v meta def add_propagation (v : prop_var) (ph : bool) (just : proof_term) (just_is_dn : bool) : solver unit := do v_st ← lookup_var v, local_false ← get_local_false, match v_st with | none := fail $ "propagating unknown variable: " ++ v^.to_string | some ⟨assg_ph, some proof⟩ := if ph = assg_ph then return () else if assg_ph ∧ ¬just_is_dn then set_conflict (app just proof) else set_conflict (app proof just) | some ⟨_, none⟩ := do hyp_name ← mk_fresh_name, hyp ← return $ local_const hyp_name hyp_name binder_info.default (formula_of_lit local_false v ph), if just_is_dn then do push_trail $ trail_elem.dbl_neg_propg v ph just hyp else do push_trail $ trail_elem.propg v ph just hyp end meta def add_decision (v : prop_var) (ph : bool) : solver unit := do hyp_name ← mk_fresh_name, local_false ← get_local_false, hyp ← return $ local_const hyp_name hyp_name binder_info.default (formula_of_lit local_false v ph), push_trail $ trail_elem.dec v ph hyp meta def lookup_lit (l : clause.literal) : solver (option (bool × proof_hyp)) := do var_st_opt ← lookup_var l^.formula, match var_st_opt with | none := return none | some ⟨ph, none⟩ := return none | some ⟨ph, some proof⟩ := return $ some (if l^.is_neg then bnot ph else ph, proof) end meta def lit_is_false (l : clause.literal) : solver bool := do s ← lookup_lit l, return $ match s with | some (ff, _) := tt | _ := ff end meta def lit_is_not_false (l : clause.literal) : solver bool := do isf ← lit_is_false l, return $ bnot isf meta def cls_is_false (c : clause) : solver bool := lift list.band $ mapm lit_is_false c^.get_lits private meta def unit_propg_cls' : clause → solver (option prop_var) | c := if c^.num_lits = 0 then return (some c^.proof) else let hd := c^.get_lit 0 in do lit_st ← lookup_lit hd, match lit_st with | some (ff, isf_prf) := unit_propg_cls' (c^.inst isf_prf) | _ := return none end meta def unit_propg_cls : clause → solver unit | c := do has_confl ← has_conflict, if has_confl then return () else if c^.num_lits = 0 then do set_conflict c^.proof else let hd := c^.get_lit 0 in do lit_st ← lookup_lit hd, match lit_st with | some (ff, isf_prf) := unit_propg_cls (c^.inst isf_prf) | some (tt, _) := return () | none := do fls_prf_opt ← unit_propg_cls' (c^.inst (expr.mk_var 0)), match fls_prf_opt with | some fls_prf := do fls_prf' ← return $ lam `H binder_info.default c^.type^.binding_domain fls_prf, if hd^.is_neg then add_propagation hd^.formula ff fls_prf' ff else add_propagation hd^.formula tt fls_prf' tt | none := return () end end private meta def modify_watches_for (pl : prop_lit) (f : watch_map → watch_map) : solver unit := state_t.modify $ λst, { st with watches := st^.watches^.insert pl $ f $ st^.watches_for pl } private meta def add_watch (n : name) (c : clause) (i j : ℕ) : solver unit := let l := c^.get_lit i, pl := prop_lit.of_cls_lit l in modify_watches_for pl $ λw, w^.insert n (i,j,c) private meta def remove_watch (n : name) (c : clause) (i : ℕ) : solver unit := let l := c^.get_lit i, pl := prop_lit.of_cls_lit l in modify_watches_for pl $ λw, w^.erase n private meta def set_watches (n : name) (c : clause) : solver unit := if c^.num_lits = 0 then set_conflict c^.proof else if c^.num_lits = 1 then unit_propg_cls c else do not_false_lits ← filter (λi, lit_is_not_false (c^.get_lit i)) (list.range c^.num_lits), match not_false_lits with | [] := do add_watch n c 0 1, add_watch n c 1 0, unit_propg_cls c | [i] := let j := if i = 0 then 1 else 0 in do add_watch n c i j, add_watch n c j i, unit_propg_cls c | (i::j::_) := do add_watch n c i j, add_watch n c j i end meta def update_watches (n : name) (c : clause) (i₁ i₂ : ℕ) : solver unit := do remove_watch n c i₁, remove_watch n c i₂, set_watches n c meta def mk_clause (c : clause) : solver unit := do c : clause ← c^.distinct, for c^.get_lits (λl, mk_var l^.formula), revert_to_decision_level_zero (), state_t.modify $ λst, { st with clauses := c :: st^.clauses }, c_name ← mk_fresh_name, set_watches c_name c meta def unit_propg_var (v : prop_var) : solver unit := do st ← state_t.read, if st^.conflict^.is_some then return () else match st^.vars^.find v with | some ⟨ph, none⟩ := fail $ "propagating unassigned variable: " ++ v^.to_string | none := fail $ "unknown variable: " ++ v^.to_string | some ⟨ph, some _⟩ := let watches := st^.watches_for $ prop_lit.of_var_and_phase v (bnot ph) in for' watches^.to_list $ λw, update_watches w.1 w.2.2.2 w.2.1 w.2.2.1 end meta def analyze_conflict' (local_false : expr) : proof_term → list trail_elem → clause | proof (trail_elem.dec v ph hyp :: es) := let abs_prf := abstract_local proof hyp^.local_uniq_name in if has_var abs_prf then clause.close_const (analyze_conflict' proof es) hyp else analyze_conflict' proof es | proof (trail_elem.propg v ph l_prf hyp :: es) := let abs_prf := abstract_local proof hyp^.local_uniq_name in if has_var abs_prf then analyze_conflict' (app (lam hyp^.local_pp_name binder_info.default (formula_of_lit local_false v ph) abs_prf) l_prf) es else analyze_conflict' proof es | proof (trail_elem.dbl_neg_propg v ph l_prf hyp :: es) := let abs_prf := abstract_local proof hyp^.local_uniq_name in if has_var abs_prf then analyze_conflict' (app l_prf (lambdas [hyp] proof)) es else analyze_conflict' proof es | proof [] := ⟨0, 0, proof, local_false, local_false⟩ meta def analyze_conflict (proof : proof_term) : solver clause := do st ← state_t.read, return $ analyze_conflict' st^.local_false proof st^.trail meta def add_learned (c : clause) : solver unit := do prf_abbrev_name ← mk_fresh_name, c' ← return { c with proof := local_const prf_abbrev_name prf_abbrev_name binder_info.default c^.type }, state_t.modify $ λst, { st with learned := ⟨c', c^.proof⟩ :: st^.learned }, c_name ← mk_fresh_name, set_watches c_name c' meta def backtrack_with : clause → solver unit | conflict_clause := do isf ← cls_is_false conflict_clause, if ¬isf then state_t.modify (λst, { st with conflict := none }) else do removed_elem ← pop_trail_core, if removed_elem^.is_some then backtrack_with conflict_clause else return () meta def replace_learned_clauses' : proof_term → list learned_clause → proof_term | proof [] := proof | proof (⟨c, actual_proof⟩ :: lcs) := let abs_prf := abstract_local proof c^.proof^.local_uniq_name in if has_var abs_prf then replace_learned_clauses' (elet c^.proof^.local_pp_name c^.type actual_proof abs_prf) lcs else replace_learned_clauses' proof lcs meta def replace_learned_clauses (proof : proof_term) : solver proof_term := do st ← state_t.read, return $ replace_learned_clauses' proof st^.learned meta inductive result | unsat : proof_term → result | sat : rb_map prop_var bool → result variable theory_solver : solver (option proof_term) meta def unit_propg : unit → solver unit | () := do st ← state_t.read, if st^.conflict^.is_some then return () else match st^.unitp_queue with | [] := return () | (v::vs) := do state_t.write { st with unitp_queue := vs }, unit_propg_var v, unit_propg () end private meta def run' : unit → solver result | () := do unit_propg (), st ← state_t.read, match st^.conflict with | some conflict := do conflict_clause ← analyze_conflict conflict, if conflict_clause^.num_lits = 0 then do proof ← replace_learned_clauses conflict_clause^.proof, return (result.unsat proof) else do backtrack_with conflict_clause, add_learned conflict_clause, run' () | none := match st^.unassigned^.min with | none := do theory_conflict ← theory_solver, match theory_conflict with | some conflict := do set_conflict conflict, run' () | none := return $ result.sat (st^.vars^.map (λvar_st, var_st^.phase)) end | some unassigned := match st^.vars^.find unassigned with | some ⟨ph, none⟩ := do add_decision unassigned ph, run' () | _ := fail $ "unassigned variable is assigned: " ++ unassigned^.to_string end end end meta def run : solver result := run' theory_solver () meta def solve (local_false : expr) (clauses : list clause) : tactic result := do res ← (do for clauses mk_clause, run theory_solver) (state.initial local_false), return res.1 meta def theory_solver_of_tactic (th_solver : tactic unit) : cdcl.solver (option cdcl.proof_term) := do s ← state_t.read, ↑do hyps ← return $ s^.trail^.map (λe, e^.hyp), subgoal ← mk_meta_var s^.local_false, goals ← get_goals, set_goals [subgoal], hvs ← for hyps (λhyp, assertv hyp^.local_pp_name hyp^.local_type hyp), solved ← (do th_solver, now, return tt) <|> return ff, set_goals goals, if solved then do proof ← instantiate_mvars subgoal, proof' ← whnf proof, -- gets rid of the unnecessary asserts return $ some proof' else return none end cdcl
75bdf495cffb7dab40cc049cfa3ec95c285ec5b7
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/convex/segment.lean
15a02d5fbdf9ddc33af6560b89b52dc0efc4deea
[ "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
18,934
lean
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, Yury Kudriashov, Yaël Dillies -/ import algebra.order.invertible import algebra.order.smul import linear_algebra.affine_space.midpoint import linear_algebra.ray import tactic.positivity /-! # Segments in vector spaces In a 𝕜-vector space, we define the following objects and properties. * `segment 𝕜 x y`: Closed segment joining `x` and `y`. * `open_segment 𝕜 x y`: Open segment joining `x` and `y`. ## Notations We provide the following notation: * `[x -[𝕜] y] = segment 𝕜 x y` in locale `convex` ## TODO Generalize all this file to affine spaces. Should we rename `segment` and `open_segment` to `convex.Icc` and `convex.Ioo`? Should we also define `clopen_segment`/`convex.Ico`/`convex.Ioc`? -/ variables {𝕜 E F : Type*} open set section ordered_semiring variables [ordered_semiring 𝕜] [add_comm_monoid E] section has_smul variables (𝕜) [has_smul 𝕜 E] {s : set E} {x y : E} /-- Segments in a vector space. -/ def segment (x y : E) : set E := {z : E | ∃ (a b : 𝕜) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1), a • x + b • y = z} /-- Open segment in a vector space. Note that `open_segment 𝕜 x x = {x}` instead of being `∅` when the base semiring has some element between `0` and `1`. -/ def open_segment (x y : E) : set E := {z : E | ∃ (a b : 𝕜) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1), a • x + b • y = z} localized "notation (name := segment) `[` x ` -[` 𝕜 `] ` y `]` := segment 𝕜 x y" in convex lemma segment_eq_image₂ (x y : E) : [x -[𝕜] y] = (λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 ≤ p.1 ∧ 0 ≤ p.2 ∧ p.1 + p.2 = 1} := by simp only [segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc] lemma open_segment_eq_image₂ (x y : E) : open_segment 𝕜 x y = (λ p : 𝕜 × 𝕜, p.1 • x + p.2 • y) '' {p | 0 < p.1 ∧ 0 < p.2 ∧ p.1 + p.2 = 1} := by simp only [open_segment, image, prod.exists, mem_set_of_eq, exists_prop, and_assoc] lemma segment_symm (x y : E) : [x -[𝕜] y] = [y -[𝕜] x] := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ lemma open_segment_symm (x y : E) : open_segment 𝕜 x y = open_segment 𝕜 y x := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩, λ ⟨a, b, ha, hb, hab, H⟩, ⟨b, a, hb, ha, (add_comm _ _).trans hab, (add_comm _ _).trans H⟩⟩ lemma open_segment_subset_segment (x y : E) : open_segment 𝕜 x y ⊆ [x -[𝕜] y] := λ z ⟨a, b, ha, hb, hab, hz⟩, ⟨a, b, ha.le, hb.le, hab, hz⟩ lemma segment_subset_iff : [x -[𝕜] y] ⊆ s ↔ ∀ a b : 𝕜, 0 ≤ a → 0 ≤ b → a + b = 1 → a • x + b • y ∈ s := ⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩, λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩ lemma open_segment_subset_iff : open_segment 𝕜 x y ⊆ s ↔ ∀ a b : 𝕜, 0 < a → 0 < b → a + b = 1 → a • x + b • y ∈ s := ⟨λ H a b ha hb hab, H ⟨a, b, ha, hb, hab, rfl⟩, λ H z ⟨a, b, ha, hb, hab, hz⟩, hz ▸ H a b ha hb hab⟩ end has_smul open_locale convex section mul_action_with_zero variables (𝕜) [mul_action_with_zero 𝕜 E] lemma left_mem_segment (x y : E) : x ∈ [x -[𝕜] y] := ⟨1, 0, zero_le_one, le_refl 0, add_zero 1, by rw [zero_smul, one_smul, add_zero]⟩ lemma right_mem_segment (x y : E) : y ∈ [x -[𝕜] y] := segment_symm 𝕜 y x ▸ left_mem_segment 𝕜 y x end mul_action_with_zero section module variables (𝕜) [module 𝕜 E] {s : set E} {x y z : E} @[simp] lemma segment_same (x : E) : [x -[𝕜] x] = {x} := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, by simpa only [(add_smul _ _ _).symm, mem_singleton_iff, hab, one_smul, eq_comm] using hz, λ h, mem_singleton_iff.1 h ▸ left_mem_segment 𝕜 z z⟩ lemma insert_endpoints_open_segment (x y : E) : insert x (insert y (open_segment 𝕜 x y)) = [x -[𝕜] y] := begin simp only [subset_antisymm_iff, insert_subset, left_mem_segment, right_mem_segment, open_segment_subset_segment, true_and], rintro z ⟨a, b, ha, hb, hab, rfl⟩, refine hb.eq_or_gt.imp _ (λ hb', ha.eq_or_gt.imp _ _), { rintro rfl, rw add_zero at hab, rw [hab, one_smul, zero_smul, add_zero] }, { rintro rfl, rw zero_add at hab, rw [hab, one_smul, zero_smul, zero_add] }, { exact λ ha', ⟨a, b, ha', hb', hab, rfl⟩ } end variables {𝕜} lemma mem_open_segment_of_ne_left_right (hx : x ≠ z) (hy : y ≠ z) (hz : z ∈ [x -[𝕜] y]) : z ∈ open_segment 𝕜 x y := begin rw [←insert_endpoints_open_segment] at hz, exact ((hz.resolve_left hx.symm).resolve_left hy.symm) end lemma open_segment_subset_iff_segment_subset (hx : x ∈ s) (hy : y ∈ s) : open_segment 𝕜 x y ⊆ s ↔ [x -[𝕜] y] ⊆ s := by simp only [←insert_endpoints_open_segment, insert_subset, *, true_and] end module end ordered_semiring open_locale convex section ordered_ring variables (𝕜) [ordered_ring 𝕜] [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F] section densely_ordered variables [nontrivial 𝕜] [densely_ordered 𝕜] @[simp] lemma open_segment_same (x : E) : open_segment 𝕜 x x = {x} := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, by simpa only [←add_smul, mem_singleton_iff, hab, one_smul, eq_comm] using hz, λ (h : z = x), begin obtain ⟨a, ha₀, ha₁⟩ := densely_ordered.dense (0 : 𝕜) 1 zero_lt_one, refine ⟨a, 1 - a, ha₀, sub_pos_of_lt ha₁, add_sub_cancel'_right _ _, _⟩, rw [←add_smul, add_sub_cancel'_right, one_smul, h], end⟩ end densely_ordered lemma segment_eq_image (x y : E) : [x -[𝕜] y] = (λ θ : 𝕜, (1 - θ) • x + θ • y) '' Icc (0 : 𝕜) 1 := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, ⟨b, ⟨hb, hab ▸ le_add_of_nonneg_left ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩, λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1-θ, θ, sub_nonneg.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ lemma open_segment_eq_image (x y : E) : open_segment 𝕜 x y = (λ (θ : 𝕜), (1 - θ) • x + θ • y) '' Ioo (0 : 𝕜) 1 := set.ext $ λ z, ⟨λ ⟨a, b, ha, hb, hab, hz⟩, ⟨b, ⟨hb, hab ▸ lt_add_of_pos_left _ ha⟩, hab ▸ hz ▸ by simp only [add_sub_cancel]⟩, λ ⟨θ, ⟨hθ₀, hθ₁⟩, hz⟩, ⟨1 - θ, θ, sub_pos.2 hθ₁, hθ₀, sub_add_cancel _ _, hz⟩⟩ lemma segment_eq_image' (x y : E) : [x -[𝕜] y] = (λ (θ : 𝕜), x + θ • (y - x)) '' Icc (0 : 𝕜) 1 := by { convert segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel } lemma open_segment_eq_image' (x y : E) : open_segment 𝕜 x y = (λ (θ : 𝕜), x + θ • (y - x)) '' Ioo (0 : 𝕜) 1 := by { convert open_segment_eq_image 𝕜 x y, ext θ, simp only [smul_sub, sub_smul, one_smul], abel } lemma segment_eq_image_line_map (x y : E) : [x -[𝕜] y] = affine_map.line_map x y '' Icc (0 : 𝕜) 1 := by { convert segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ } lemma open_segment_eq_image_line_map (x y : E) : open_segment 𝕜 x y = affine_map.line_map x y '' Ioo (0 : 𝕜) 1 := by { convert open_segment_eq_image 𝕜 x y, ext, exact affine_map.line_map_apply_module _ _ _ } lemma segment_image (f : E →ₗ[𝕜] F) (a b : E) : f '' [a -[𝕜] b] = [f a -[𝕜] f b] := set.ext (λ x, by simp_rw [segment_eq_image, mem_image, exists_exists_and_eq_and, map_add, map_smul]) @[simp] lemma open_segment_image (f : E →ₗ[𝕜] F) (a b : E) : f '' open_segment 𝕜 a b = open_segment 𝕜 (f a) (f b) := set.ext (λ x, by simp_rw [open_segment_eq_image, mem_image, exists_exists_and_eq_and, map_add, map_smul]) lemma mem_segment_translate (a : E) {x b c} : a + x ∈ [a + b -[𝕜] a + c] ↔ x ∈ [b -[𝕜] c] := begin rw [segment_eq_image', segment_eq_image'], refine exists_congr (λ θ, and_congr iff.rfl _), simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj], end @[simp] lemma mem_open_segment_translate (a : E) {x b c : E} : a + x ∈ open_segment 𝕜 (a + b) (a + c) ↔ x ∈ open_segment 𝕜 b c := begin rw [open_segment_eq_image', open_segment_eq_image'], refine exists_congr (λ θ, and_congr iff.rfl _), simp only [add_sub_add_left_eq_sub, add_assoc, add_right_inj], end lemma segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' [a + b -[𝕜] a + c] = [b -[𝕜] c] := set.ext $ λ x, mem_segment_translate 𝕜 a lemma open_segment_translate_preimage (a b c : E) : (λ x, a + x) ⁻¹' open_segment 𝕜 (a + b) (a + c) = open_segment 𝕜 b c := set.ext $ λ x, mem_open_segment_translate 𝕜 a lemma segment_translate_image (a b c : E) : (λ x, a + x) '' [b -[𝕜] c] = [a + b -[𝕜] a + c] := segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a lemma open_segment_translate_image (a b c : E) : (λ x, a + x) '' open_segment 𝕜 b c = open_segment 𝕜 (a + b) (a + c) := open_segment_translate_preimage 𝕜 a b c ▸ image_preimage_eq _ $ add_left_surjective a end ordered_ring lemma same_ray_of_mem_segment [ordered_comm_ring 𝕜] [add_comm_group E] [module 𝕜 E] {x y z : E} (h : x ∈ [y -[𝕜] z]) : same_ray 𝕜 (x - y) (z - x) := begin rw segment_eq_image' at h, rcases h with ⟨θ, ⟨hθ₀, hθ₁⟩, rfl⟩, simpa only [add_sub_cancel', ←sub_sub, sub_smul, one_smul] using (same_ray_nonneg_smul_left (z - y) hθ₀).nonneg_smul_right (sub_nonneg.2 hθ₁) end section linear_ordered_ring variables [linear_ordered_ring 𝕜] [add_comm_group E] [module 𝕜 E] {x y : E} lemma midpoint_mem_segment [invertible (2 : 𝕜)] (x y : E) : midpoint 𝕜 x y ∈ [x -[𝕜] y] := begin rw segment_eq_image_line_map, exact ⟨⅟2, ⟨inv_of_nonneg.mpr zero_le_two, inv_of_le_one one_le_two⟩, rfl⟩, end lemma mem_segment_sub_add [invertible (2 : 𝕜)] (x y : E) : x ∈ [x - y -[𝕜] x + y] := by { convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _, rw midpoint_sub_add } lemma mem_segment_add_sub [invertible (2 : 𝕜)] (x y : E) : x ∈ [x + y -[𝕜] x - y] := by { convert @midpoint_mem_segment 𝕜 _ _ _ _ _ _ _, rw midpoint_add_sub } @[simp] lemma left_mem_open_segment_iff [densely_ordered 𝕜] [no_zero_smul_divisors 𝕜 E] : x ∈ open_segment 𝕜 x y ↔ x = y := begin split, { rintro ⟨a, b, ha, hb, hab, hx⟩, refine smul_right_injective _ hb.ne' ((add_right_inj (a • x)).1 _), rw [hx, ←add_smul, hab, one_smul] }, { rintro rfl, rw open_segment_same, exact mem_singleton _ } end @[simp] lemma right_mem_open_segment_iff [densely_ordered 𝕜] [no_zero_smul_divisors 𝕜 E] : y ∈ open_segment 𝕜 x y ↔ x = y := by rw [open_segment_symm, left_mem_open_segment_iff, eq_comm] end linear_ordered_ring section linear_ordered_semifield variables [linear_ordered_semifield 𝕜] [add_comm_group E] [module 𝕜 E] {x y z : E} lemma mem_segment_iff_div : x ∈ [y -[𝕜] z] ↔ ∃ a b : 𝕜, 0 ≤ a ∧ 0 ≤ b ∧ 0 < a + b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := begin split, { rintro ⟨a, b, ha, hb, hab, rfl⟩, use [a, b, ha, hb], simp * }, { rintro ⟨a, b, ha, hb, hab, rfl⟩, refine ⟨a / (a + b), b / (a + b), div_nonneg ha hab.le, div_nonneg hb hab.le, _, rfl⟩, rw [←add_div, div_self hab.ne'] } end lemma mem_open_segment_iff_div : x ∈ open_segment 𝕜 y z ↔ ∃ a b : 𝕜, 0 < a ∧ 0 < b ∧ (a / (a + b)) • y + (b / (a + b)) • z = x := begin split, { rintro ⟨a, b, ha, hb, hab, rfl⟩, use [a, b, ha, hb], rw [hab, div_one, div_one] }, { rintro ⟨a, b, ha, hb, rfl⟩, have hab : 0 < a + b := by positivity, refine ⟨a / (a + b), b / (a + b), by positivity, by positivity, _, rfl⟩, rw [←add_div, div_self hab.ne'] } end end linear_ordered_semifield section linear_ordered_field variables [linear_ordered_field 𝕜] [add_comm_group E] [module 𝕜 E] {x y z : E} lemma mem_segment_iff_same_ray : x ∈ [y -[𝕜] z] ↔ same_ray 𝕜 (x - y) (z - x) := begin refine ⟨same_ray_of_mem_segment, λ h, _⟩, rcases h.exists_eq_smul_add with ⟨a, b, ha, hb, hab, hxy, hzx⟩, rw [add_comm, sub_add_sub_cancel] at hxy hzx, rw [←mem_segment_translate _ (-x), neg_add_self], refine ⟨b, a, hb, ha, add_comm a b ▸ hab, _⟩, rw [←sub_eq_neg_add, ←neg_sub, hxy, ←sub_eq_neg_add, hzx, smul_neg, smul_comm, neg_add_self] end end linear_ordered_field /-! #### Segments in an ordered space Relates `segment`, `open_segment` and `set.Icc`, `set.Ico`, `set.Ioc`, `set.Ioo` -/ section ordered_semiring variables [ordered_semiring 𝕜] section ordered_add_comm_monoid variables [ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E] {x y : E} lemma segment_subset_Icc (h : x ≤ y) : [x -[𝕜] y] ⊆ Icc x y := begin rintro z ⟨a, b, ha, hb, hab, rfl⟩, split, calc x = a • x + b • x :(convex.combo_self hab _).symm ... ≤ a • x + b • y : add_le_add_left (smul_le_smul_of_nonneg h hb) _, calc a • x + b • y ≤ a • y + b • y : add_le_add_right (smul_le_smul_of_nonneg h ha) _ ... = y : convex.combo_self hab _, end end ordered_add_comm_monoid section ordered_cancel_add_comm_monoid variables [ordered_cancel_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E] {x y : E} lemma open_segment_subset_Ioo (h : x < y) : open_segment 𝕜 x y ⊆ Ioo x y := begin rintro z ⟨a, b, ha, hb, hab, rfl⟩, split, calc x = a • x + b • x : (convex.combo_self hab _).symm ... < a • x + b • y : add_lt_add_left (smul_lt_smul_of_pos h hb) _, calc a • x + b • y < a • y + b • y : add_lt_add_right (smul_lt_smul_of_pos h ha) _ ... = y : convex.combo_self hab _, end end ordered_cancel_add_comm_monoid section linear_ordered_add_comm_monoid variables [linear_ordered_add_comm_monoid E] [module 𝕜 E] [ordered_smul 𝕜 E] {𝕜} {a b : 𝕜} lemma segment_subset_interval (x y : E) : [x -[𝕜] y] ⊆ interval x y := begin cases le_total x y, { rw interval_of_le h, exact segment_subset_Icc h }, { rw [interval_of_ge h, segment_symm], exact segment_subset_Icc h } end lemma convex.min_le_combo (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min x y ≤ a • x + b • y := (segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).1 lemma convex.combo_le_max (x y : E) (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : a • x + b • y ≤ max x y := (segment_subset_interval x y ⟨_, _, ha, hb, hab, rfl⟩).2 end linear_ordered_add_comm_monoid end ordered_semiring section linear_ordered_field variables [linear_ordered_field 𝕜] {x y z : 𝕜} lemma Icc_subset_segment : Icc x y ⊆ [x -[𝕜] y] := begin rintro z ⟨hxz, hyz⟩, obtain rfl | h := (hxz.trans hyz).eq_or_lt, { rw segment_same, exact hyz.antisymm hxz }, rw ←sub_nonneg at hxz hyz, rw ←sub_pos at h, refine ⟨(y - z) / (y - x), (z - x) / (y - x), div_nonneg hyz h.le, div_nonneg hxz h.le, _, _⟩, { rw [←add_div, sub_add_sub_cancel, div_self h.ne'] }, { rw [smul_eq_mul, smul_eq_mul, ←mul_div_right_comm, ←mul_div_right_comm, ←add_div, div_eq_iff h.ne', add_comm, sub_mul, sub_mul, mul_comm x, sub_add_sub_cancel, mul_sub] } end @[simp] lemma segment_eq_Icc (h : x ≤ y) : [x -[𝕜] y] = Icc x y := (segment_subset_Icc h).antisymm Icc_subset_segment lemma Ioo_subset_open_segment : Ioo x y ⊆ open_segment 𝕜 x y := λ z hz, mem_open_segment_of_ne_left_right hz.1.ne hz.2.ne' $ Icc_subset_segment $ Ioo_subset_Icc_self hz @[simp] lemma open_segment_eq_Ioo (h : x < y) : open_segment 𝕜 x y = Ioo x y := (open_segment_subset_Ioo h).antisymm Ioo_subset_open_segment lemma segment_eq_Icc' (x y : 𝕜) : [x -[𝕜] y] = Icc (min x y) (max x y) := begin cases le_total x y, { rw [segment_eq_Icc h, max_eq_right h, min_eq_left h] }, { rw [segment_symm, segment_eq_Icc h, max_eq_left h, min_eq_right h] } end lemma open_segment_eq_Ioo' (hxy : x ≠ y) : open_segment 𝕜 x y = Ioo (min x y) (max x y) := begin cases hxy.lt_or_lt, { rw [open_segment_eq_Ioo h, max_eq_right h.le, min_eq_left h.le] }, { rw [open_segment_symm, open_segment_eq_Ioo h, max_eq_left h.le, min_eq_right h.le] } end lemma segment_eq_interval (x y : 𝕜) : [x -[𝕜] y] = interval x y := segment_eq_Icc' _ _ /-- A point is in an `Icc` iff it can be expressed as a convex combination of the endpoints. -/ lemma convex.mem_Icc (h : x ≤ y) : z ∈ Icc x y ↔ ∃ a b, 0 ≤ a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := by { rw ←segment_eq_Icc h, simp_rw [←exists_prop], refl } /-- A point is in an `Ioo` iff it can be expressed as a strict convex combination of the endpoints. -/ lemma convex.mem_Ioo (h : x < y) : z ∈ Ioo x y ↔ ∃ a b, 0 < a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := by { rw ←open_segment_eq_Ioo h, simp_rw [←exists_prop], refl } /-- A point is in an `Ioc` iff it can be expressed as a semistrict convex combination of the endpoints. -/ lemma convex.mem_Ioc (h : x < y) : z ∈ Ioc x y ↔ ∃ a b, 0 ≤ a ∧ 0 < b ∧ a + b = 1 ∧ a * x + b * y = z := begin refine ⟨λ hz, _, _⟩, { obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ioc_subset_Icc_self hz), obtain rfl | hb' := hb.eq_or_lt, { rw add_zero at hab, rw [hab, one_mul, zero_mul, add_zero] at hz, exact (hz.1.ne rfl).elim }, { exact ⟨a, b, ha, hb', hab, rfl⟩ } }, { rintro ⟨a, b, ha, hb, hab, rfl⟩, obtain rfl | ha' := ha.eq_or_lt, { rw zero_add at hab, rwa [hab, one_mul, zero_mul, zero_add, right_mem_Ioc] }, { exact Ioo_subset_Ioc_self ((convex.mem_Ioo h).2 ⟨a, b, ha', hb, hab, rfl⟩) } } end /-- A point is in an `Ico` iff it can be expressed as a semistrict convex combination of the endpoints. -/ lemma convex.mem_Ico (h : x < y) : z ∈ Ico x y ↔ ∃ a b, 0 < a ∧ 0 ≤ b ∧ a + b = 1 ∧ a * x + b * y = z := begin refine ⟨λ hz, _, _⟩, { obtain ⟨a, b, ha, hb, hab, rfl⟩ := (convex.mem_Icc h.le).1 (Ico_subset_Icc_self hz), obtain rfl | ha' := ha.eq_or_lt, { rw zero_add at hab, rw [hab, one_mul, zero_mul, zero_add] at hz, exact (hz.2.ne rfl).elim }, { exact ⟨a, b, ha', hb, hab, rfl⟩ } }, { rintro ⟨a, b, ha, hb, hab, rfl⟩, obtain rfl | hb' := hb.eq_or_lt, { rw add_zero at hab, rwa [hab, one_mul, zero_mul, add_zero, left_mem_Ico] }, { exact Ioo_subset_Ico_self ((convex.mem_Ioo h).2 ⟨a, b, ha, hb', hab, rfl⟩) } } end end linear_ordered_field
f73a6a1c3b131570c7f5b98b991c7ba4cdc5cbfe
492a7e27d49633a89f7ce6e1e28f676b062fcbc9
/src/monoidal_categories_reboot/monoidal_functor_attributes.lean
f2c3da27e4c4c13fa39aad15874c3bf3f7107230
[ "Apache-2.0" ]
permissive
semorrison/monoidal-categories-reboot
9edba30277de48a234b63813cf85b171772ce36f
48b5f1d535daba4e591672042a298ac36be2e6dd
refs/heads/master
1,642,472,396,149
1,560,587,477,000
1,560,587,477,000
156,465,626
0
1
null
1,541,549,278,000
1,541,549,278,000
null
UTF-8
Lean
false
false
1,601
lean
import category_theory.monoidal.functor import category_theory.tactics.obviously open category_theory open category_theory.monoidal_category attribute [search] tensor_id tensor_comp associator_naturality left_unitor_naturality right_unitor_naturality pentagon triangle comp_tensor_id id_tensor_comp id_tensor_comp_tensor_id tensor_id_comp_id_tensor left_unitor_tensor left_unitor_tensor_inv right_unitor_tensor right_unitor_tensor_inv triangle_assoc_comp_left triangle_assoc_comp_right triangle_assoc_comp_right_inv triangle_assoc_comp_left_inv pentagon_inv associator_inv_naturality left_unitor_inv_naturality right_unitor_inv_naturality lax_monoidal_functor.μ_natural lax_monoidal_functor.left_unitality lax_monoidal_functor.right_unitality lax_monoidal_functor.associativity meta def rws : tactic string := `[rewrite_search {explain := tt}] >> pure "" @[obviously] meta def obviously'' := tactic.tidy {tactics := tactic.tidy.default_tactics ++ [rws]} notation `𝟙_` := tensor_unit notation `α_` := associator notation `λ_` := left_unitor notation `ρ_` := right_unitor universes v u variables {C : Sort u} [𝒞 : monoidal_category.{v} C] include 𝒞 @[search] lemma right_unitor_conjugation {X Y : C} (f : X ⟶ Y) : (ρ_ X).inv ≫ (f ⊗ (𝟙 (𝟙_ C))) ≫ (ρ_ Y).hom = f := by rw [right_unitor_naturality, ←category.assoc, iso.inv_hom_id, category.id_comp] @[search] lemma left_unitor_conjugation {X Y : C} (f : X ⟶ Y) : (λ_ X).inv ≫ ((𝟙 (𝟙_ C)) ⊗ f) ≫ (λ_ Y).hom = f := by rw [left_unitor_naturality, ←category.assoc, iso.inv_hom_id, category.id_comp]
4c8244c9b2fffec7baccf526ed2a74a2167c4dff
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/algebra/order/monoid/type_tags.lean
69ca44b7e7dc18d88e5f03732b88fd6c96eaba1f
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
4,770
lean
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl -/ import algebra.group.type_tags import algebra.order.monoid.cancel.defs import algebra.order.monoid.canonical.defs /-! # Ordered monoid structures on `multiplicative α` and `additive α`. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4.-/ universes u variables {α : Type u} instance : Π [has_le α], has_le (multiplicative α) := id instance : Π [has_le α], has_le (additive α) := id instance : Π [has_lt α], has_lt (multiplicative α) := id instance : Π [has_lt α], has_lt (additive α) := id instance : Π [preorder α], preorder (multiplicative α) := id instance : Π [preorder α], preorder (additive α) := id instance : Π [partial_order α], partial_order (multiplicative α) := id instance : Π [partial_order α], partial_order (additive α) := id instance : Π [linear_order α], linear_order (multiplicative α) := id instance : Π [linear_order α], linear_order (additive α) := id instance [has_le α] : Π [order_bot α], order_bot (multiplicative α) := id instance [has_le α] : Π [order_bot α], order_bot (additive α) := id instance [has_le α] : Π [order_top α], order_top (multiplicative α) := id instance [has_le α] : Π [order_top α], order_top (additive α) := id instance [has_le α] : Π [bounded_order α], bounded_order (multiplicative α) := id instance [has_le α] : Π [bounded_order α], bounded_order (additive α) := id instance [ordered_add_comm_monoid α] : ordered_comm_monoid (multiplicative α) := { mul_le_mul_left := @ordered_add_comm_monoid.add_le_add_left α _, ..multiplicative.partial_order, ..multiplicative.comm_monoid } instance [ordered_comm_monoid α] : ordered_add_comm_monoid (additive α) := { add_le_add_left := @ordered_comm_monoid.mul_le_mul_left α _, ..additive.partial_order, ..additive.add_comm_monoid } instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_comm_monoid (multiplicative α) := { le_of_mul_le_mul_left := @ordered_cancel_add_comm_monoid.le_of_add_le_add_left α _, ..multiplicative.ordered_comm_monoid } instance [ordered_cancel_comm_monoid α] : ordered_cancel_add_comm_monoid (additive α) := { le_of_add_le_add_left := @ordered_cancel_comm_monoid.le_of_mul_le_mul_left α _, ..additive.ordered_add_comm_monoid } instance [linear_ordered_add_comm_monoid α] : linear_ordered_comm_monoid (multiplicative α) := { ..multiplicative.linear_order, ..multiplicative.ordered_comm_monoid } instance [linear_ordered_comm_monoid α] : linear_ordered_add_comm_monoid (additive α) := { ..additive.linear_order, ..additive.ordered_add_comm_monoid } instance [has_add α] [has_le α] [has_exists_add_of_le α] : has_exists_mul_of_le (multiplicative α) := ⟨@exists_add_of_le α _ _ _⟩ instance [has_mul α] [has_le α] [has_exists_mul_of_le α] : has_exists_add_of_le (additive α) := ⟨@exists_mul_of_le α _ _ _⟩ instance [canonically_ordered_add_monoid α] : canonically_ordered_monoid (multiplicative α) := { le_self_mul := @le_self_add α _, ..multiplicative.ordered_comm_monoid, ..multiplicative.order_bot, ..multiplicative.has_exists_mul_of_le } instance [canonically_ordered_monoid α] : canonically_ordered_add_monoid (additive α) := { le_self_add := @le_self_mul α _, ..additive.ordered_add_comm_monoid, ..additive.order_bot, ..additive.has_exists_add_of_le } instance [canonically_linear_ordered_add_monoid α] : canonically_linear_ordered_monoid (multiplicative α) := { ..multiplicative.canonically_ordered_monoid, ..multiplicative.linear_order } instance [canonically_linear_ordered_monoid α] : canonically_linear_ordered_add_monoid (additive α) := { ..additive.canonically_ordered_add_monoid, ..additive.linear_order } namespace additive variables [preorder α] @[simp] lemma of_mul_le {a b : α} : of_mul a ≤ of_mul b ↔ a ≤ b := iff.rfl @[simp] lemma of_mul_lt {a b : α} : of_mul a < of_mul b ↔ a < b := iff.rfl @[simp] lemma to_mul_le {a b : additive α} : to_mul a ≤ to_mul b ↔ a ≤ b := iff.rfl @[simp] lemma to_mul_lt {a b : additive α} : to_mul a < to_mul b ↔ a < b := iff.rfl end additive namespace multiplicative variables [preorder α] @[simp] lemma of_add_le {a b : α} : of_add a ≤ of_add b ↔ a ≤ b := iff.rfl @[simp] lemma of_add_lt {a b : α} : of_add a < of_add b ↔ a < b := iff.rfl @[simp] lemma to_add_le {a b : multiplicative α} : to_add a ≤ to_add b ↔ a ≤ b := iff.rfl @[simp] lemma to_add_lt {a b : multiplicative α} : to_add a < to_add b ↔ a < b := iff.rfl end multiplicative
d292378858be8d84deb1721904012a6125c3a6b7
5d166a16ae129621cb54ca9dde86c275d7d2b483
/library/init/coe.lean
916496f843a59fa379a31a9cb663bcbbf7f4b2a0
[ "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
6,682
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 -/ /- The elaborator tries to insert coercions automatically. Only instances of has_coe type class are considered in the process. Lean also provides a "lifting" operator: ↑a. It uses all instances of has_lift type class. Every has_coe instance is also a has_lift instance. We recommend users only use has_coe for coercions that do not produce a lot of ambiguity. All coercions and lifts can be identified with the constant coe. We use the has_coe_to_fun type class for encoding coercions from a type to a function space. We use the has_coe_to_sort type class for encoding coercions from a type to a sort. -/ prelude import init.data.list.basic init.data.subtype.basic init.data.prod universes u v class has_lift (a : Sort u) (b : Sort v) := (lift : a → b) /- Auxiliary class that contains the transitive closure of has_lift. -/ class has_lift_t (a : Sort u) (b : Sort v) := (lift : a → b) class has_coe (a : Sort u) (b : Sort v) := (coe : a → b) /- Auxiliary class that contains the transitive closure of has_coe. -/ class has_coe_t (a : Sort u) (b : Sort v) := (coe : a → b) class has_coe_to_fun (a : Sort u) : Sort (max u (v+1)) := (F : a → Sort v) (coe : Π x, F x) class has_coe_to_sort (a : Sort u) : Type (max u (v+1)) := (S : Sort v) (coe : a → S) def lift {a : Sort u} {b : Sort v} [has_lift a b] : a → b := @has_lift.lift a b _ def lift_t {a : Sort u} {b : Sort v} [has_lift_t a b] : a → b := @has_lift_t.lift a b _ def coe_b {a : Sort u} {b : Sort v} [has_coe a b] : a → b := @has_coe.coe a b _ def coe_t {a : Sort u} {b : Sort v} [has_coe_t a b] : a → b := @has_coe_t.coe a b _ def coe_fn_b {a : Sort u} [has_coe_to_fun.{u v} a] : Π x : a, has_coe_to_fun.F.{u v} x := has_coe_to_fun.coe /- User level coercion operators -/ @[reducible] def coe {a : Sort u} {b : Sort v} [has_lift_t a b] : a → b := lift_t @[reducible] def coe_fn {a : Sort u} [has_coe_to_fun.{u v} a] : Π x : a, has_coe_to_fun.F.{u v} x := has_coe_to_fun.coe @[reducible] def coe_sort {a : Sort u} [has_coe_to_sort.{u v} a] : a → has_coe_to_sort.S.{u v} a := has_coe_to_sort.coe /- Notation -/ notation `↑`:max x:max := coe x notation `⇑`:max x:max := coe_fn x notation `↥`:max x:max := coe_sort x universes u₁ u₂ u₃ /- Transitive closure for has_lift, has_coe, has_coe_to_fun -/ instance lift_trans {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_lift a b] [has_lift_t b c] : has_lift_t a c := ⟨λ x, lift_t (lift x : b)⟩ instance lift_base {a : Sort u} {b : Sort v} [has_lift a b] : has_lift_t a b := ⟨lift⟩ instance coe_trans {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_coe a b] [has_coe_t b c] : has_coe_t a c := ⟨λ x, coe_t (coe_b x : b)⟩ instance coe_base {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t a b := ⟨coe_b⟩ /- We add this instance directly into has_coe_t to avoid non-termination. Suppose coe_option had type (has_coe a (option a)). Then, we can loop when searching a coercion from α to β (has_coe_t α β) 1- coe_trans at (has_coe_t α β) (has_coe α ?b₁) and (has_coe_t ?b₁ c) 2- coe_option at (has_coe α ?b₁) ?b₁ := option α 3- coe_trans at (has_coe_t (option α) β) (has_coe (option α) ?b₂) and (has_coe_t ?b₂ β) 4- coe_option at (has_coe (option α) ?b₂) ?b₂ := option (option α)) ... -/ instance coe_option {a : Type u} : has_coe_t a (option a) := ⟨λ x, some x⟩ /- Auxiliary transitive closure for has_coe which does not contain instances such as coe_option. They would produce non-termination when combined with coe_fn_trans and coe_sort_trans. -/ class has_coe_t_aux (a : Sort u) (b : Sort v) := (coe : a → b) instance coe_trans_aux {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_coe a b] [has_coe_t_aux b c] : has_coe_t_aux a c := ⟨λ x : a, @has_coe_t_aux.coe b c _ (coe_b x)⟩ instance coe_base_aux {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t_aux a b := ⟨coe_b⟩ instance coe_fn_trans {a : Sort u₁} {b : Sort u₂} [has_coe_t_aux a b] [has_coe_to_fun.{u₂ u₃} b] : has_coe_to_fun.{u₁ u₃} a := { F := λ x, @has_coe_to_fun.F.{u₂ u₃} b _ (@has_coe_t_aux.coe a b _ x), coe := λ x, coe_fn (@has_coe_t_aux.coe a b _ x) } instance coe_sort_trans {a : Sort u₁} {b : Sort u₂} [has_coe_t_aux a b] [has_coe_to_sort.{u₂ u₃} b] : has_coe_to_sort.{u₁ u₃} a := { S := has_coe_to_sort.S.{u₂ u₃} b, coe := λ x, coe_sort (@has_coe_t_aux.coe a b _ x) } /- Every coercion is also a lift -/ instance coe_to_lift {a : Sort u} {b : Sort v} [has_coe_t a b] : has_lift_t a b := ⟨coe_t⟩ /- basic coercions -/ instance coe_bool_to_Prop : has_coe bool Prop := ⟨λ y, y = tt⟩ instance coe_sort_bool : has_coe_to_sort bool := ⟨Prop, λ y, y = tt⟩ instance coe_decidable_eq (x : bool) : decidable (coe x) := show decidable (x = tt), from bool.decidable_eq x tt instance coe_subtype {a : Type u} {p : a → Prop} : has_coe {x // p x} a := ⟨subtype.val⟩ /- basic lifts -/ universes ua ua₁ ua₂ ub ub₁ ub₂ /- Remark: we can't use [has_lift_t a₂ a₁] since it will produce non-termination whenever a type class resolution problem does not have a solution. -/ instance lift_fn {a₁ : Sort ua₁} {a₂ : Sort ua₂} {b₁ : Sort ub₁} {b₂ : Sort ub₂} [has_lift a₂ a₁] [has_lift_t b₁ b₂] : has_lift (a₁ → b₁) (a₂ → b₂) := ⟨λ f x, ↑(f ↑x)⟩ instance lift_fn_range {a : Sort ua} {b₁ : Sort ub₁} {b₂ : Sort ub₂} [has_lift_t b₁ b₂] : has_lift (a → b₁) (a → b₂) := ⟨λ f x, ↑(f x)⟩ instance lift_fn_dom {a₁ : Sort ua₁} {a₂ : Sort ua₂} {b : Sort ub} [has_lift a₂ a₁] : has_lift (a₁ → b) (a₂ → b) := ⟨λ f x, f ↑x⟩ instance lift_pair {a₁ : Type ua₁} {a₂ : Type ub₂} {b₁ : Type ub₁} {b₂ : Type ub₂} [has_lift_t a₁ a₂] [has_lift_t b₁ b₂] : has_lift (a₁ × b₁) (a₂ × b₂) := ⟨λ p, prod.cases_on p (λ x y, (↑x, ↑y))⟩ instance lift_pair₁ {a₁ : Type ua₁} {a₂ : Type ua₂} {b : Type ub} [has_lift_t a₁ a₂] : has_lift (a₁ × b) (a₂ × b) := ⟨λ p, prod.cases_on p (λ x y, (↑x, y))⟩ instance lift_pair₂ {a : Type ua} {b₁ : Type ub₁} {b₂ : Type ub₂} [has_lift_t b₁ b₂] : has_lift (a × b₁) (a × b₂) := ⟨λ p, prod.cases_on p (λ x y, (x, ↑y))⟩ instance lift_list {a : Type u} {b : Type v} [has_lift_t a b] : has_lift (list a) (list b) := ⟨λ l, list.map (@coe a b _) l⟩
571fd13a4d3107c65d7ca5acda69629816db4d52
957a80ea22c5abb4f4670b250d55534d9db99108
/tests/lean/run/aexp.lean
b6e2dd571495dab5fa7c7b07a3596272b534bdcf
[ "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
1,708
lean
namespace imp open tactic @[reducible] def uname := string inductive aexp | val : nat → aexp | var : uname → aexp | plus : aexp → aexp → aexp | times : aexp → aexp → aexp instance : decidable_eq aexp := by mk_dec_eq_instance @[reducible] def value := nat def state := uname → value open aexp def aval : aexp → state → value | (val n) s := n | (var x) s := s x | (plus a₁ a₂) s := aval a₁ s + aval a₂ s | (times a₁ a₂) s := aval a₁ s * aval a₂ s example : aval (plus (val 3) (var "x")) (λ x, 0) = 3 := rfl def updt (s : state) (x : uname) (v : value) : state := λ y, if x = y then v else s y def asimp_const : aexp → aexp | (val n) := val n | (var x) := var x | (plus a₁ a₂) := match asimp_const a₁, asimp_const a₂ with | val n₁, val n₂ := val (n₁ + n₂) | b₁, b₂ := plus b₁ b₂ end | (times a₁ a₂) := match asimp_const a₁, asimp_const a₂ with | val n₁, val n₂ := val (n₁ * n₂) | b₁, b₂ := times b₁ b₂ end example : asimp_const (plus (plus (val 2) (val 3)) (var "x")) = plus (val 5) (var "x") := rfl attribute [ematch] asimp_const aval -- set_option trace.smt.ematch true meta def not_done : tactic unit := fail_if_success done lemma aval_asimp_const (a : aexp) (s : state) : aval (asimp_const a) s = aval a s := begin [smt] induction a, all_goals {destruct (asimp_const a_1), all_goals {destruct (asimp_const a), eblast}} end lemma ex2 (a : aexp) (s : state) : aval (asimp_const a) s = aval a s := begin [smt] induction a, all_goals {destruct (asimp_const a_1), all_goals {destruct (asimp_const a), eblast_using [asimp_const, aval]}} end end imp
85e281e88aef2336aa8a7bf1956cf6c50218f7c5
2fbe653e4bc441efde5e5d250566e65538709888
/src/topology/continuous_on.lean
f97cc2dd2485cc207f4f1fd99f189c597df1b456
[ "Apache-2.0" ]
permissive
aceg00/mathlib
5e15e79a8af87ff7eb8c17e2629c442ef24e746b
8786ea6d6d46d6969ac9a869eb818bf100802882
refs/heads/master
1,649,202,698,930
1,580,924,783,000
1,580,924,783,000
149,197,272
0
0
Apache-2.0
1,537,224,208,000
1,537,224,207,000
null
UTF-8
Lean
false
false
24,449
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import topology.constructions /-! # Neighborhoods and continuity relative to a subset This file defines relative versions `nhds_within` of `nhds` `continuous_on` of `continuous` `continuous_within_at` of `continuous_at` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. -/ open set filter open_locale topological_space variables {α : Type*} {β : Type*} {γ : Type*} variables [topological_space α] /-- The "neighborhood within" filter. Elements of `nhds_within a s` are sets containing the intersection of `s` and a neighborhood of `a`. -/ def nhds_within (a : α) (s : set α) : filter α := 𝓝 a ⊓ principal s theorem nhds_within_eq (a : α) (s : set α) : nhds_within a s = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (t ∩ s) := have set.univ ∈ {s : set α | a ∈ s ∧ is_open s}, from ⟨set.mem_univ _, is_open_univ⟩, begin rw [nhds_within, nhds, lattice.binfi_inf]; try { exact this }, simp only [inf_principal] end theorem nhds_within_univ (a : α) : nhds_within a set.univ = 𝓝 a := by rw [nhds_within, principal_univ, lattice.inf_top_eq] theorem mem_nhds_within {t : set α} {a : α} {s : set α} : t ∈ nhds_within a s ↔ ∃ u, is_open u ∧ a ∈ u ∧ u ∩ s ⊆ t := begin rw [nhds_within, mem_inf_principal, mem_nhds_sets_iff], split, { rintros ⟨u, hu, openu, au⟩, exact ⟨u, openu, au, λ x ⟨xu, xs⟩, hu xu xs⟩ }, rintros ⟨u, openu, au, hu⟩, exact ⟨u, λ x xu xs, hu ⟨xu, xs⟩, openu, au⟩ end lemma mem_nhds_within_iff_exists_mem_nhds_inter {t : set α} {a : α} {s : set α} : t ∈ nhds_within a s ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := begin rw [nhds_within, mem_inf_principal], split, { exact λH, ⟨_, H, λx hx, hx.1 hx.2⟩ }, { exact λ⟨u, Hu, h⟩, mem_sets_of_superset Hu (λx xu xs, h ⟨xu, xs⟩ ) } end lemma mem_nhds_within_of_mem_nhds {s t : set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ nhds_within a t := mem_inf_sets_of_left h theorem self_mem_nhds_within {a : α} {s : set α} : s ∈ nhds_within a s := mem_inf_sets_of_right (mem_principal_self s) theorem inter_mem_nhds_within (s : set α) {t : set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ nhds_within a s := inter_mem_sets (mem_inf_sets_of_right (mem_principal_self s)) (mem_inf_sets_of_left h) theorem nhds_within_mono (a : α) {s t : set α} (h : s ⊆ t) : nhds_within a s ≤ nhds_within a t := lattice.inf_le_inf (le_refl _) (principal_mono.mpr h) theorem nhds_within_restrict'' {a : α} (s : set α) {t : set α} (h : t ∈ nhds_within a s) : nhds_within a s = nhds_within a (s ∩ t) := le_antisymm (lattice.le_inf lattice.inf_le_left (le_principal_iff.mpr (inter_mem_sets self_mem_nhds_within h))) (lattice.inf_le_inf (le_refl _) (principal_mono.mpr (set.inter_subset_left _ _))) theorem nhds_within_restrict' {a : α} (s : set α) {t : set α} (h : t ∈ 𝓝 a) : nhds_within a s = nhds_within a (s ∩ t) := nhds_within_restrict'' s $ mem_inf_sets_of_left h theorem nhds_within_restrict {a : α} (s : set α) {t : set α} (h₀ : a ∈ t) (h₁ : is_open t) : nhds_within a s = nhds_within a (s ∩ t) := nhds_within_restrict' s (mem_nhds_sets h₁ h₀) theorem nhds_within_le_of_mem {a : α} {s t : set α} (h : s ∈ nhds_within a t) : nhds_within a t ≤ nhds_within a s := begin rcases mem_nhds_within.1 h with ⟨u, u_open, au, uts⟩, have : nhds_within a t = nhds_within a (t ∩ u) := nhds_within_restrict _ au u_open, rw [this, inter_comm], exact nhds_within_mono _ uts end theorem nhds_within_eq_nhds_within {a : α} {s t u : set α} (h₀ : a ∈ s) (h₁ : is_open s) (h₂ : t ∩ s = u ∩ s) : nhds_within a t = nhds_within a u := by rw [nhds_within_restrict t h₀ h₁, nhds_within_restrict u h₀ h₁, h₂] theorem nhds_within_eq_of_open {a : α} {s : set α} (h₀ : a ∈ s) (h₁ : is_open s) : nhds_within a s = 𝓝 a := by rw [←nhds_within_univ]; apply nhds_within_eq_nhds_within h₀ h₁; rw [set.univ_inter, set.inter_self] @[simp] theorem nhds_within_empty (a : α) : nhds_within a {} = ⊥ := by rw [nhds_within, principal_empty, lattice.inf_bot_eq] theorem nhds_within_union (a : α) (s t : set α) : nhds_within a (s ∪ t) = nhds_within a s ⊔ nhds_within a t := by unfold nhds_within; rw [←lattice.inf_sup_left, sup_principal] theorem nhds_within_inter (a : α) (s t : set α) : nhds_within a (s ∩ t) = nhds_within a s ⊓ nhds_within a t := by unfold nhds_within; rw [lattice.inf_left_comm, lattice.inf_assoc, inf_principal, ←lattice.inf_assoc, lattice.inf_idem] theorem nhds_within_inter' (a : α) (s t : set α) : nhds_within a (s ∩ t) = (nhds_within a s) ⊓ principal t := by { unfold nhds_within, rw [←inf_principal, lattice.inf_assoc] } lemma nhds_within_prod_eq {α : Type*} [topological_space α] {β : Type*} [topological_space β] (a : α) (b : β) (s : set α) (t : set β) : nhds_within (a, b) (s.prod t) = (nhds_within a s).prod (nhds_within b t) := by { unfold nhds_within, rw [nhds_prod_eq, ←filter.prod_inf_prod, filter.prod_principal_principal] } theorem tendsto_if_nhds_within {f g : α → β} {p : α → Prop} [decidable_pred p] {a : α} {s : set α} {l : filter β} (h₀ : tendsto f (nhds_within a (s ∩ p)) l) (h₁ : tendsto g (nhds_within a (s ∩ {x | ¬ p x})) l) : tendsto (λ x, if p x then f x else g x) (nhds_within a s) l := by apply tendsto_if; rw [←nhds_within_inter']; assumption lemma map_nhds_within (f : α → β) (a : α) (s : set α) : map f (nhds_within a s) = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (set.image f (t ∩ s)) := have h₀ : directed_on ((λ (i : set α), principal (i ∩ s)) ⁻¹'o ge) {x : set α | x ∈ {t : set α | a ∈ t ∧ is_open t}}, from assume x ⟨ax, openx⟩ y ⟨ay, openy⟩, ⟨x ∩ y, ⟨⟨ax, ay⟩, is_open_inter openx openy⟩, le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_left _ _)), le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_right _ _))⟩, have h₁ : ∃ (i : set α), i ∈ {t : set α | a ∈ t ∧ is_open t}, from ⟨set.univ, set.mem_univ _, is_open_univ⟩, by { rw [nhds_within_eq, map_binfi_eq h₀ h₁], simp only [map_principal] } theorem tendsto_nhds_within_mono_left {f : α → β} {a : α} {s t : set α} {l : filter β} (hst : s ⊆ t) (h : tendsto f (nhds_within a t) l) : tendsto f (nhds_within a s) l := tendsto_le_left (nhds_within_mono a hst) h theorem tendsto_nhds_within_mono_right {f : β → α} {l : filter β} {a : α} {s t : set α} (hst : s ⊆ t) (h : tendsto f l (nhds_within a s)) : tendsto f l (nhds_within a t) := tendsto_le_right (nhds_within_mono a hst) h theorem tendsto_nhds_within_of_tendsto_nhds {f : α → β} {a : α} {s : set α} {l : filter β} (h : tendsto f (𝓝 a) l) : tendsto f (nhds_within a s) l := by rw [←nhds_within_univ] at h; exact tendsto_nhds_within_mono_left (set.subset_univ _) h theorem principal_subtype {α : Type*} (s : set α) (t : set {x // x ∈ s}) : principal t = comap subtype.val (principal (subtype.val '' t)) := by rw comap_principal; rw set.preimage_image_eq; apply subtype.val_injective lemma mem_closure_iff_nhds_within_ne_bot {s : set α} {x : α} : x ∈ closure s ↔ nhds_within x s ≠ ⊥ := begin split, { assume hx, rw ← forall_sets_nonempty_iff_ne_bot, assume o ho, rw mem_nhds_within at ho, rcases ho with ⟨u, u_open, xu, hu⟩, rw mem_closure_iff at hx, exact (hx u u_open xu).mono hu }, { assume h, rw mem_closure_iff, rintros u u_open xu, have : u ∩ s ∈ nhds_within x s, { rw mem_nhds_within, exact ⟨u, u_open, xu, subset.refl _⟩ }, exact forall_sets_nonempty_iff_ne_bot.2 h (u ∩ s) this } end lemma nhds_within_ne_bot_of_mem {s : set α} {x : α} (hx : x ∈ s) : nhds_within x s ≠ ⊥ := mem_closure_iff_nhds_within_ne_bot.1 $ subset_closure hx lemma is_closed.mem_of_nhds_within_ne_bot {s : set α} (hs : is_closed s) {x : α} (hx : nhds_within x s ≠ ⊥) : x ∈ s := by simpa only [closure_eq_of_is_closed hs] using mem_closure_iff_nhds_within_ne_bot.2 hx /- nhds_within and subtypes -/ theorem mem_nhds_within_subtype (s : set α) (a : {x // x ∈ s}) (t u : set {x // x ∈ s}) : t ∈ nhds_within a u ↔ t ∈ comap (@subtype.val _ s) (nhds_within a.val (subtype.val '' u)) := by rw [nhds_within, nhds_subtype, principal_subtype, ←comap_inf, ←nhds_within] theorem nhds_within_subtype (s : set α) (a : {x // x ∈ s}) (t : set {x // x ∈ s}) : nhds_within a t = comap (@subtype.val _ s) (nhds_within a.val (subtype.val '' t)) := filter_eq $ by ext u; rw mem_nhds_within_subtype theorem nhds_within_eq_map_subtype_val {s : set α} {a : α} (h : a ∈ s) : nhds_within a s = map subtype.val (𝓝 ⟨a, h⟩) := have h₀ : s ∈ nhds_within a s, by { rw [mem_nhds_within], existsi set.univ, simp [set.diff_eq] }, have h₁ : ∀ y ∈ s, ∃ x, @subtype.val _ s x = y, from λ y h, ⟨⟨y, h⟩, rfl⟩, begin rw [←nhds_within_univ, nhds_within_subtype, subtype.val_image_univ], exact (map_comap_of_surjective' h₀ h₁).symm, end theorem tendsto_nhds_within_iff_subtype {s : set α} {a : α} (h : a ∈ s) (f : α → β) (l : filter β) : tendsto f (nhds_within a s) l ↔ tendsto (function.restrict f s) (𝓝 ⟨a, h⟩) l := by rw [tendsto, tendsto, function.restrict, nhds_within_eq_map_subtype_val h, ←(@filter.map_map _ _ _ _ subtype.val)] variables [topological_space β] [topological_space γ] /-- A function between topological spaces is continuous at a point `x₀` within a subset `s` if `f x` tends to `f x₀` when `x` tends to `x₀` while staying within `s`. -/ def continuous_within_at (f : α → β) (s : set α) (x : α) : Prop := tendsto f (nhds_within x s) (𝓝 (f x)) /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `tendsto.comp` as `continuous_within_at.comp` will have a different meaning. -/ lemma continuous_within_at.tendsto {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) : tendsto f (nhds_within x s) (𝓝 (f x)) := h /-- A function between topological spaces is continuous on a subset `s` when it's continuous at every point of `s` within `s`. -/ def continuous_on (f : α → β) (s : set α) : Prop := ∀ x ∈ s, continuous_within_at f s x theorem continuous_within_at_univ (f : α → β) (x : α) : continuous_within_at f set.univ x ↔ continuous_at f x := by rw [continuous_at, continuous_within_at, nhds_within_univ] theorem continuous_within_at_iff_continuous_at_restrict (f : α → β) {x : α} {s : set α} (h : x ∈ s) : continuous_within_at f s x ↔ continuous_at (function.restrict f s) ⟨x, h⟩ := tendsto_nhds_within_iff_subtype h f _ theorem continuous_within_at.tendsto_nhds_within_image {f : α → β} {x : α} {s : set α} (h : continuous_within_at f s x) : tendsto f (nhds_within x s) (nhds_within (f x) (f '' s)) := tendsto_inf.2 ⟨h, tendsto_principal.2 $ mem_inf_sets_of_right $ mem_principal_sets.2 $ λ x, mem_image_of_mem _⟩ theorem continuous_on_iff {f : α → β} {s : set α} : continuous_on f s ↔ ∀ x ∈ s, ∀ t : set β, is_open t → f x ∈ t → ∃ u, is_open u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [continuous_on, continuous_within_at, tendsto_nhds, mem_nhds_within] theorem continuous_on_iff_continuous_restrict {f : α → β} {s : set α} : continuous_on f s ↔ continuous (function.restrict f s) := begin rw [continuous_on, continuous_iff_continuous_at], split, { rintros h ⟨x, xs⟩, exact (continuous_within_at_iff_continuous_at_restrict f xs).mp (h x xs) }, intros h x xs, exact (continuous_within_at_iff_continuous_at_restrict f xs).mpr (h ⟨x, xs⟩) end theorem continuous_on_iff' {f : α → β} {s : set α} : continuous_on f s ↔ ∀ t : set β, is_open t → ∃ u, is_open u ∧ f ⁻¹' t ∩ s = u ∩ s := have ∀ t, is_open (function.restrict f s ⁻¹' t) ↔ ∃ (u : set α), is_open u ∧ f ⁻¹' t ∩ s = u ∩ s, begin intro t, rw [is_open_induced_iff, function.restrict_eq, set.preimage_comp], simp only [subtype.preimage_val_eq_preimage_val_iff], split; { rintros ⟨u, ou, useq⟩, exact ⟨u, ou, useq.symm⟩ } end, by rw [continuous_on_iff_continuous_restrict, continuous]; simp only [this] theorem continuous_on_iff_is_closed {f : α → β} {s : set α} : continuous_on f s ↔ ∀ t : set β, is_closed t → ∃ u, is_closed u ∧ f ⁻¹' t ∩ s = u ∩ s := have ∀ t, is_closed (function.restrict f s ⁻¹' t) ↔ ∃ (u : set α), is_closed u ∧ f ⁻¹' t ∩ s = u ∩ s, begin intro t, rw [is_closed_induced_iff, function.restrict_eq, set.preimage_comp], simp only [subtype.preimage_val_eq_preimage_val_iff] end, by rw [continuous_on_iff_continuous_restrict, continuous_iff_is_closed]; simp only [this] theorem nhds_within_le_comap {x : α} {s : set α} {f : α → β} (ctsf : continuous_within_at f s x) : nhds_within x s ≤ comap f (nhds_within (f x) (f '' s)) := map_le_iff_le_comap.1 ctsf.tendsto_nhds_within_image theorem continuous_within_at_iff_ptendsto_res (f : α → β) {x : α} {s : set α} : continuous_within_at f s x ↔ ptendsto (pfun.res f s) (𝓝 x) (𝓝 (f x)) := tendsto_iff_ptendsto _ _ _ _ lemma continuous_iff_continuous_on_univ {f : α → β} : continuous f ↔ continuous_on f univ := by simp [continuous_iff_continuous_at, continuous_on, continuous_at, continuous_within_at, nhds_within_univ] lemma continuous_within_at.mono {f : α → β} {s t : set α} {x : α} (h : continuous_within_at f t x) (hs : s ⊆ t) : continuous_within_at f s x := tendsto_le_left (nhds_within_mono x hs) h lemma continuous_within_at_inter' {f : α → β} {s t : set α} {x : α} (h : t ∈ nhds_within x s) : continuous_within_at f (s ∩ t) x ↔ continuous_within_at f s x := by simp [continuous_within_at, nhds_within_restrict'' s h] lemma continuous_within_at_inter {f : α → β} {s t : set α} {x : α} (h : t ∈ 𝓝 x) : continuous_within_at f (s ∩ t) x ↔ continuous_within_at f s x := by simp [continuous_within_at, nhds_within_restrict' s h] lemma continuous_within_at.union {f : α → β} {s t : set α} {x : α} (hs : continuous_within_at f s x) (ht : continuous_within_at f t x) : continuous_within_at f (s ∪ t) x := by simp only [continuous_within_at, nhds_within_union, tendsto, map_sup, lattice.sup_le_iff.2 ⟨hs, ht⟩] lemma continuous_within_at.mem_closure_image {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := mem_closure_of_tendsto (mem_closure_iff_nhds_within_ne_bot.1 hx) h $ mem_sets_of_superset self_mem_nhds_within (subset_preimage_image f s) lemma continuous_within_at.mem_closure {f : α → β} {s : set α} {x : α} {A : set β} (h : continuous_within_at f s x) (hx : x ∈ closure s) (hA : s ⊆ f⁻¹' A) : f x ∈ closure A := closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx) lemma continuous_within_at.image_closure {f : α → β} {s : set α} (hf : ∀ x ∈ closure s, continuous_within_at f s x) : f '' (closure s) ⊆ closure (f '' s) := begin rintros _ ⟨x, hx, rfl⟩, exact (hf x hx).mem_closure_image hx end theorem is_open_map.continuous_on_image_of_left_inv_on {f : α → β} {s : set α} (h : is_open_map (function.restrict f s)) {finv : β → α} (hleft : left_inv_on finv f s) : continuous_on finv (f '' s) := begin rintros _ ⟨x, xs, rfl⟩ t ht, rw [hleft x xs] at ht, replace h := h.nhds_le ⟨x, xs⟩, apply mem_nhds_within_of_mem_nhds, apply h, erw [map_compose.symm, function.comp, mem_map, ← nhds_within_eq_map_subtype_val], apply mem_sets_of_superset (inter_mem_nhds_within _ ht), assume y hy, rw [mem_set_of_eq, mem_preimage, hleft _ hy.1], exact hy.2 end theorem is_open_map.continuous_on_range_of_left_inverse {f : α → β} (hf : is_open_map f) {finv : β → α} (hleft : function.left_inverse finv f) : continuous_on finv (range f) := begin rw [← image_univ], exact (hf.restrict is_open_univ).continuous_on_image_of_left_inv_on (λ x _, hleft x) end lemma continuous_on.congr_mono {f g : α → β} {s s₁ : set α} (h : continuous_on f s) (h' : ∀x ∈ s₁, g x = f x) (h₁ : s₁ ⊆ s) : continuous_on g s₁ := begin assume x hx, unfold continuous_within_at, have A := (h x (h₁ hx)).mono h₁, unfold continuous_within_at at A, rw ← h' x hx at A, have : {x : α | g x = f x} ∈ nhds_within x s₁ := mem_inf_sets_of_right h', apply tendsto.congr' _ A, convert this, ext, finish end lemma continuous_on.congr {f g : α → β} {s : set α} (h : continuous_on f s) (h' : ∀x ∈ s, g x = f x) : continuous_on g s := h.congr_mono h' (subset.refl _) lemma continuous_at.continuous_within_at {f : α → β} {s : set α} {x : α} (h : continuous_at f x) : continuous_within_at f s x := continuous_within_at.mono ((continuous_within_at_univ f x).2 h) (subset_univ _) lemma continuous_within_at.continuous_at {f : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (hs : s ∈ 𝓝 x) : continuous_at f x := begin have : s = univ ∩ s, by rw univ_inter, rwa [this, continuous_within_at_inter hs, continuous_within_at_univ] at h end lemma continuous_within_at.comp {g : β → γ} {f : α → β} {s : set α} {t : set β} {x : α} (hg : continuous_within_at g t (f x)) (hf : continuous_within_at f s x) (h : s ⊆ f ⁻¹' t) : continuous_within_at (g ∘ f) s x := begin have : tendsto f (principal s) (principal t), by { rw tendsto_principal_principal, exact λx hx, h hx }, have : tendsto f (nhds_within x s) (principal t) := tendsto_le_left lattice.inf_le_right this, have : tendsto f (nhds_within x s) (nhds_within (f x) t) := tendsto_inf.2 ⟨hf, this⟩, exact tendsto.comp hg this end lemma continuous_on.comp {g : β → γ} {f : α → β} {s : set α} {t : set β} (hg : continuous_on g t) (hf : continuous_on f s) (h : s ⊆ f ⁻¹' t) : continuous_on (g ∘ f) s := λx hx, continuous_within_at.comp (hg _ (h hx)) (hf x hx) h lemma continuous_on.mono {f : α → β} {s t : set α} (hf : continuous_on f s) (h : t ⊆ s) : continuous_on f t := λx hx, tendsto_le_left (nhds_within_mono _ h) (hf x (h hx)) lemma continuous.continuous_on {f : α → β} {s : set α} (h : continuous f) : continuous_on f s := begin rw continuous_iff_continuous_on_univ at h, exact h.mono (subset_univ _) end lemma continuous.continuous_within_at {f : α → β} {s : set α} {x : α} (h : continuous f) : continuous_within_at f s x := tendsto_le_left lattice.inf_le_left (h.tendsto x) lemma continuous.comp_continuous_on {g : β → γ} {f : α → β} {s : set α} (hg : continuous g) (hf : continuous_on f s) : continuous_on (g ∘ f) s := hg.continuous_on.comp hf subset_preimage_univ lemma continuous_within_at.preimage_mem_nhds_within {f : α → β} {x : α} {s : set α} {t : set β} (h : continuous_within_at f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ nhds_within x s := h ht lemma continuous_within_at.preimage_mem_nhds_within' {f : α → β} {x : α} {s : set α} {t : set β} (h : continuous_within_at f s x) (ht : t ∈ nhds_within (f x) (f '' s)) : f ⁻¹' t ∈ nhds_within x s := begin rw mem_nhds_within at ht, rcases ht with ⟨u, u_open, fxu, hu⟩, have : f ⁻¹' u ∩ s ∈ nhds_within x s := filter.inter_mem_sets (h (mem_nhds_sets u_open fxu)) self_mem_nhds_within, apply mem_sets_of_superset this, calc f ⁻¹' u ∩ s ⊆ f ⁻¹' u ∩ f ⁻¹' (f '' s) : inter_subset_inter_right _ (subset_preimage_image f s) ... = f ⁻¹' (u ∩ f '' s) : rfl ... ⊆ f ⁻¹' t : preimage_mono hu end lemma continuous_within_at.congr_of_mem_nhds_within {f f₁ : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (h₁ : {y | f₁ y = f y} ∈ nhds_within x s) (hx : f₁ x = f x) : continuous_within_at f₁ s x := by rwa [continuous_within_at, filter.tendsto, hx, filter.map_cong h₁] lemma continuous_within_at.congr {f f₁ : α → β} {s : set α} {x : α} (h : continuous_within_at f s x) (h₁ : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) : continuous_within_at f₁ s x := h.congr_of_mem_nhds_within (mem_sets_of_superset self_mem_nhds_within h₁) hx lemma continuous_on_const {s : set α} {c : β} : continuous_on (λx, c) s := continuous_const.continuous_on lemma continuous_within_at_const {b : β} {s : set α} {x : α} : continuous_within_at (λ _:α, b) s x := continuous_const.continuous_within_at lemma continuous_on_id {s : set α} : continuous_on id s := continuous_id.continuous_on lemma continuous_within_at_id {s : set α} {x : α} : continuous_within_at id s x := continuous_id.continuous_within_at lemma continuous_on_open_iff {f : α → β} {s : set α} (hs : is_open s) : continuous_on f s ↔ (∀t, is_open t → is_open (s ∩ f⁻¹' t)) := begin rw continuous_on_iff', split, { assume h t ht, rcases h t ht with ⟨u, u_open, hu⟩, rw [inter_comm, hu], apply is_open_inter u_open hs }, { assume h t ht, refine ⟨s ∩ f ⁻¹' t, h t ht, _⟩, rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] } end lemma continuous_on.preimage_open_of_open {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_open s) (ht : is_open t) : is_open (s ∩ f⁻¹' t) := (continuous_on_open_iff hs).1 hf t ht lemma continuous_on.preimage_closed_of_closed {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_closed s) (ht : is_closed t) : is_closed (s ∩ f⁻¹' t) := begin rcases continuous_on_iff_is_closed.1 hf t ht with ⟨u, hu⟩, rw [inter_comm, hu.2], apply is_closed_inter hu.1 hs end lemma continuous_on.preimage_interior_subset_interior_preimage {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s) (hs : is_open s) : s ∩ f⁻¹' (interior t) ⊆ s ∩ interior (f⁻¹' t) := calc s ∩ f ⁻¹' (interior t) = interior (s ∩ f ⁻¹' (interior t)) : (interior_eq_of_open (hf.preimage_open_of_open hs is_open_interior)).symm ... ⊆ interior (s ∩ f ⁻¹' t) : interior_mono (inter_subset_inter (subset.refl _) (preimage_mono interior_subset)) ... = s ∩ interior (f ⁻¹' t) : by rw [interior_inter, interior_eq_of_open hs] lemma continuous_on_of_locally_continuous_on {f : α → β} {s : set α} (h : ∀x∈s, ∃t, is_open t ∧ x ∈ t ∧ continuous_on f (s ∩ t)) : continuous_on f s := begin assume x xs, rcases h x xs with ⟨t, open_t, xt, ct⟩, have := ct x ⟨xs, xt⟩, rwa [continuous_within_at, ← nhds_within_restrict _ xt open_t] at this end lemma continuous_on_open_of_generate_from {β : Type*} {s : set α} {T : set (set β)} {f : α → β} (hs : is_open s) (h : ∀t ∈ T, is_open (s ∩ f⁻¹' t)) : @continuous_on α β _ (topological_space.generate_from T) f s := begin rw continuous_on_open_iff, assume t ht, induction ht with u hu u v Tu Tv hu hv U hU hU', { exact h u hu }, { simp only [preimage_univ, inter_univ], exact hs }, { have : s ∩ f ⁻¹' (u ∩ v) = (s ∩ f ⁻¹' u) ∩ (s ∩ f ⁻¹' v), by { ext x, simp, split, finish, finish }, rw this, exact is_open_inter hu hv }, { rw [preimage_sUnion, inter_bUnion], exact is_open_bUnion hU' }, { exact hs } end lemma continuous_within_at.prod {f : α → β} {g : α → γ} {s : set α} {x : α} (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) : continuous_within_at (λx, (f x, g x)) s x := tendsto_prod_mk_nhds hf hg lemma continuous_on.prod {f : α → β} {g : α → γ} {s : set α} (hf : continuous_on f s) (hg : continuous_on g s) : continuous_on (λx, (f x, g x)) s := λx hx, continuous_within_at.prod (hf x hx) (hg x hx)
8c51f538b03b31b49d5cb5828cdc90414128b6b7
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/meta/simp_tactic.lean
29c948aaf75fa6d16924dd95375f502b4433b2a6
[]
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
8,720
lean
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.meta.tactic import Mathlib.Lean3Lib.init.meta.attribute import Mathlib.Lean3Lib.init.meta.constructor_tactic import Mathlib.Lean3Lib.init.meta.relation_tactics import Mathlib.Lean3Lib.init.meta.occurrences import Mathlib.Lean3Lib.init.data.option.basic universes l namespace Mathlib def simp.default_max_steps : ℕ := bit0 (bit0 (bit0 (bit0 (bit0 (bit0 (bit0 (bit1 (bit0 (bit1 (bit1 (bit0 (bit1 (bit0 (bit0 (bit1 (bit0 (bit0 (bit0 (bit1 (bit1 (bit0 (bit0 1)))))))))))))))))))))) /-- Prefix the given `attr_name` with `"simp_attr"`. -/ /-- Simp lemmas are used by the "simplifier" family of tactics. `simp_lemmas` is essentially a pair of tables `rb_map (expr_type × name) (priority_list simp_lemma)`. One of the tables is for congruences and one is for everything else. An individual simp lemma is: - A kind which can be `Refl`, `Simp` or `Congr`. - A pair of `expr`s `l ~> r`. The rb map is indexed by the name of `get_app_fn(l)`. - A proof that `l = r` or `l ↔ r`. - A list of the metavariables that must be filled before the proof can be applied. - A priority number -/ /-- Make a new table of simp lemmas -/ /-- Merge the simp_lemma tables. -/ /-- Remove the given lemmas from the table. Use the names of the lemmas. -/ /-- Makes the default simp_lemmas table which is composed of all lemmas tagged with `simp`. -/ /-- Add a simplification lemma by an expression `p`. Some conditions on `p` must hold for it to be added, see list below. If your lemma is not being added, you can see the reasons by setting `set_option trace.simp_lemmas true`. - `p` must have the type `Π (h₁ : _) ... (hₙ : _), LHS ~ RHS` for some reflexive, transitive relation (usually `=`). - Any of the hypotheses `hᵢ` should either be present in `LHS` or otherwise a `Prop` or a typeclass instance. - `LHS` should not occur within `RHS`. - `LHS` should not occur within a hypothesis `hᵢ`. -/ /-- Add a simplification lemma by it's declaration name. See `simp_lemmas.add` for more information.-/ /-- Adds a congruence simp lemma to simp_lemmas. A congruence simp lemma is a lemma that breaks the simplification down into separate problems. For example, to simplify `a ∧ b` to `c ∧ d`, we should try to simp `a` to `c` and `b` to `d`. For examples of congruence simp lemmas look for lemmas with the `@[congr]` attribute. ```lean lemma if_simp_congr ... (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := ... lemma imp_congr_right (h : a → (b ↔ c)) : (a → b) ↔ (a → c) := ... lemma and_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∧ b) ↔ (c ∧ d) := ... ``` -/ /-- Add expressions to a set of simp lemmas using `simp_lemmas.add`. This is the new version of `simp_lemmas.append`, which also allows you to set the `symm` flag. -/ /-- Add expressions to a set of simp lemmas using `simp_lemmas.add`. This is the backwards-compatibility version of `simp_lemmas.append_with_symm`, and sets all `symm` flags to `ff`. -/ /-- `simp_lemmas.rewrite s e prove R` apply a simplification lemma from 's' - 'e' is the expression to be "simplified" - 'prove' is used to discharge proof obligations. - 'r' is the equivalence relation being used (e.g., 'eq', 'iff') - 'md' is the transparency; how aggresively should the simplifier perform reductions. Result (new_e, pr) is the new expression 'new_e' and a proof (pr : e R new_e) -/ /-- `simp_lemmas.drewrite s e` tries to rewrite 'e' using only refl lemmas in 's' -/ namespace tactic /- Remark: `transform` should not change the target. -/ /-- Revert a local constant, change its type using `transform`. -/ /-- `get_eqn_lemmas_for deps d` returns the automatically generated equational lemmas for definition d. If deps is tt, then lemmas for automatically generated auxiliary declarations used to define d are also included. -/ structure dsimp_config where md : transparency max_steps : ℕ canonize_instances : Bool single_pass : Bool fail_if_unchanged : Bool eta : Bool zeta : Bool beta : Bool proj : Bool iota : Bool unfold_reducible : Bool memoize : Bool end tactic /-- (Definitional) Simplify the given expression using *only* reflexivity equality lemmas from the given set of lemmas. The resulting expression is definitionally equal to the input. The list `u` contains defintions to be delta-reduced, and projections to be reduced.-/ namespace tactic /- Remark: the configuration parameters `cfg.md` and `cfg.eta` are ignored by this tactic. -/ /- Remark: we use transparency.instances by default to make sure that we can unfold projections of type classes. Example: (@has_add.add nat nat.has_add a b) -/ /-- Tries to unfold `e` if it is a constant or a constant application. Remark: this is not a recursive procedure. -/ structure dunfold_config extends dsimp_config where /- Remark: in principle, dunfold can be implemented on top of dsimp. We don't do it for performance reasons. -/ structure delta_config where max_steps : ℕ visit_instances : Bool /-- Delta reduce the given constant names -/ structure unfold_proj_config extends dsimp_config where /-- If `e` is a projection application, try to unfold it, otherwise fail. -/ structure simp_config where max_steps : ℕ contextual : Bool lift_eq : Bool canonize_instances : Bool canonize_proofs : Bool use_axioms : Bool zeta : Bool beta : Bool eta : Bool proj : Bool iota : Bool iota_eqn : Bool constructor_eq : Bool single_pass : Bool fail_if_unchanged : Bool memoize : Bool trace_lemmas : Bool /-- `simplify s e cfg r prove` simplify `e` using `s` using bottom-up traversal. `discharger` is a tactic for dischaging new subgoals created by the simplifier. If it fails, the simplifier tries to discharge the subgoal by simplifying it to `true`. The parameter `to_unfold` specifies definitions that should be delta-reduced, and projection applications that should be unfolded. -/ /-- `ext_simplify_core a c s discharger pre post r e`: - `a : α` - initial user data - `c : simp_config` - simp configuration options - `s : simp_lemmas` - the set of simp_lemmas to use. Remark: the simplification lemmas are not applied automatically like in the simplify tactic. The caller must use them at pre/post. - `discharger : α → tactic α` - tactic for dischaging hypothesis in conditional rewriting rules. The argument 'α' is the current user data. - `pre a s r p e` is invoked before visiting the children of subterm 'e'. + arguments: - `a` is the current user data - `s` is the updated set of lemmas if 'contextual' is `tt`, - `r` is the simplification relation being used, - `p` is the "parent" expression (if there is one). - `e` is the current subexpression in question. + if it succeeds the result is `(new_a, new_e, new_pr, flag)` where - `new_a` is the new value for the user data - `new_e` is a new expression s.t. `r e new_e` - `new_pr` is a proof for `r e new_e`, If it is none, the proof is assumed to be by reflexivity - `flag` if tt `new_e` children should be visited, and `post` invoked. - `(post a s r p e)` is invoked after visiting the children of subterm `e`, The output is similar to `(pre a r s p e)`, but the 'flag' indicates whether the new expression should be revisited or not. - `r` is the simplification relation. Usually `=` or `↔`. - `e` is the input expression to be simplified. The method returns `(a,e,pr)` where - `a` is the final user data - `e` is the new expression - `pr` is the proof that the given expression equals the input expression. Note that `ext_simplify_core` will succeed even if `pre` and `post` fail, as failures are used to indicate that the method should move on to the next subterm. If it is desirable to propagate errors from `pre`, they can be propagated through the "user data". An easy way to do this is to call `tactic.capture (do ...)` in the parts of `pre`/`post` where errors matter, and then use `tactic.unwrap a` on the result. Additionally, `ext_simplify_core` does not propagate changes made to the tactic state by `pre` and `post. If it is desirable to propagate changes to the tactic state in addition to errors, use `tactic.resume` instead of `tactic.unwrap`. -/ structure simp_intros_config extends simp_config where use_hyps : Bool
718e09c22d6b03ed6ea4a3019339ec69af338427
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/data/finset/lattice.lean
454d0071096d4a09dab84e812ac8c9bf8faaa728
[ "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
24,116
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import data.finset.fold import data.multiset.lattice /-! # Lattice operations on multisets -/ variables {α β γ : Type*} namespace finset open multiset /-! ### sup -/ section sup variables [semilattice_sup_bot α] /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup (s : finset β) (f : β → α) : α := s.fold (⊔) ⊥ f variables {s s₁ s₂ : finset β} {f : β → α} lemma sup_def : s.sup f = (s.1.map f).sup := rfl @[simp] lemma sup_empty : (∅ : finset β).sup f = ⊥ := fold_empty @[simp] lemma sup_insert [decidable_eq β] {b : β} : (insert b s : finset β).sup f = f b ⊔ s.sup f := fold_insert_idem @[simp] lemma sup_singleton {b : β} : ({b} : finset β).sup f = f b := sup_singleton lemma sup_union [decidable_eq β] : (s₁ ∪ s₂).sup f = s₁.sup f ⊔ s₂.sup f := finset.induction_on s₁ (by rw [empty_union, sup_empty, bot_sup_eq]) $ λ a s has ih, by rw [insert_union, sup_insert, sup_insert, ih, sup_assoc] theorem sup_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.sup f = s₂.sup g := by subst hs; exact finset.fold_congr hfg @[simp] lemma sup_le_iff {a : α} : s.sup f ≤ a ↔ (∀b ∈ s, f b ≤ a) := begin apply iff.trans multiset.sup_le, simp only [multiset.mem_map, and_imp, exists_imp_distrib], exact ⟨λ k b hb, k _ _ hb rfl, λ k a' b hb h, h ▸ k _ hb⟩, end lemma sup_le {a : α} : (∀b ∈ s, f b ≤ a) → s.sup f ≤ a := sup_le_iff.2 lemma le_sup {b : β} (hb : b ∈ s) : f b ≤ s.sup f := sup_le_iff.1 (le_refl _) _ hb lemma sup_mono_fun {g : β → α} (h : ∀b∈s, f b ≤ g b) : s.sup f ≤ s.sup g := sup_le (λ b hb, le_trans (h b hb) (le_sup hb)) lemma sup_mono (h : s₁ ⊆ s₂) : s₁.sup f ≤ s₂.sup f := sup_le $ assume b hb, le_sup (h hb) @[simp] lemma sup_lt_iff [is_total α (≤)] {a : α} (ha : ⊥ < a) : s.sup f < a ↔ (∀b ∈ s, f b < a) := by letI := classical.dec_eq β; from ⟨ λh b hb, lt_of_le_of_lt (le_sup hb) h, finset.induction_on s (by simp [ha]) (by simp {contextual := tt}) ⟩ lemma comp_sup_eq_sup_comp [semilattice_sup_bot γ] {s : finset β} {f : β → α} (g : α → γ) (g_sup : ∀ x y, g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := by letI := classical.dec_eq β; from finset.induction_on s (by simp [bot]) (by simp [g_sup] {contextual := tt}) lemma comp_sup_eq_sup_comp_of_is_total [is_total α (≤)] {γ : Type} [semilattice_sup_bot γ] (g : α → γ) (mono_g : monotone g) (bot : g ⊥ = ⊥) : g (s.sup f) = s.sup (g ∘ f) := comp_sup_eq_sup_comp g mono_g.map_sup bot /-- Computating `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/ lemma sup_coe {P : α → Prop} {Pbot : P ⊥} {Psup : ∀{{x y}}, P x → P y → P (x ⊔ y)} (t : finset β) (f : β → {x : α // P x}) : (@sup _ _ (subtype.semilattice_sup_bot Pbot Psup) t f : α) = t.sup (λ x, f x) := by { classical, rw [comp_sup_eq_sup_comp coe]; intros; refl } theorem subset_range_sup_succ (s : finset ℕ) : s ⊆ range (s.sup id).succ := λ n hn, mem_range.2 $ nat.lt_succ_of_le $ le_sup hn theorem exists_nat_subset_range (s : finset ℕ) : ∃n : ℕ, s ⊆ range n := ⟨_, s.subset_range_sup_succ⟩ lemma mem_sup {α β} [decidable_eq β] {s : finset α} {f : α → multiset β} {x : β} : x ∈ s.sup f ↔ ∃ v ∈ s, x ∈ f v := begin classical, apply s.induction_on, { simp }, { intros a s has hxs, rw [finset.sup_insert, multiset.sup_eq_union, multiset.mem_union], split, { intro hxi, cases hxi with hf hf, { refine ⟨a, _, hf⟩, simp only [true_or, eq_self_iff_true, finset.mem_insert] }, { rcases hxs.mp hf with ⟨v, hv, hfv⟩, refine ⟨v, _, hfv⟩, simp only [hv, or_true, finset.mem_insert] } }, { rintros ⟨v, hv, hfv⟩, rw [finset.mem_insert] at hv, rcases hv with rfl | hv, { exact or.inl hfv }, { refine or.inr (hxs.mpr ⟨v, hv, hfv⟩) } } }, end lemma sup_subset {α β} [semilattice_sup_bot β] {s t : finset α} (hst : s ⊆ t) (f : α → β) : s.sup f ≤ t.sup f := by classical; calc t.sup f = (s ∪ t).sup f : by rw [finset.union_eq_right_iff_subset.mpr hst] ... = s.sup f ⊔ t.sup f : by rw finset.sup_union ... ≥ s.sup f : le_sup_left end sup lemma sup_eq_supr [complete_lattice β] (s : finset α) (f : α → β) : s.sup f = (⨆a∈s, f a) := le_antisymm (finset.sup_le $ assume a ha, le_supr_of_le a $ le_supr _ ha) (supr_le $ assume a, supr_le $ assume ha, le_sup ha) /-! ### inf -/ section inf variables [semilattice_inf_top α] /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf (s : finset β) (f : β → α) : α := s.fold (⊓) ⊤ f variables {s s₁ s₂ : finset β} {f : β → α} lemma inf_def : s.inf f = (s.1.map f).inf := rfl @[simp] lemma inf_empty : (∅ : finset β).inf f = ⊤ := fold_empty lemma le_inf_iff {a : α} : a ≤ s.inf f ↔ ∀b ∈ s, a ≤ f b := @sup_le_iff (order_dual α) _ _ _ _ _ @[simp] lemma inf_insert [decidable_eq β] {b : β} : (insert b s : finset β).inf f = f b ⊓ s.inf f := fold_insert_idem @[simp] lemma inf_singleton {b : β} : ({b} : finset β).inf f = f b := inf_singleton lemma inf_union [decidable_eq β] : (s₁ ∪ s₂).inf f = s₁.inf f ⊓ s₂.inf f := @sup_union (order_dual α) _ _ _ _ _ _ theorem inf_congr {f g : β → α} (hs : s₁ = s₂) (hfg : ∀a∈s₂, f a = g a) : s₁.inf f = s₂.inf g := by subst hs; exact finset.fold_congr hfg lemma inf_le {b : β} (hb : b ∈ s) : s.inf f ≤ f b := le_inf_iff.1 (le_refl _) _ hb lemma le_inf {a : α} : (∀b ∈ s, a ≤ f b) → a ≤ s.inf f := le_inf_iff.2 lemma inf_mono_fun {g : β → α} (h : ∀b∈s, f b ≤ g b) : s.inf f ≤ s.inf g := le_inf (λ b hb, le_trans (inf_le hb) (h b hb)) lemma inf_mono (h : s₁ ⊆ s₂) : s₂.inf f ≤ s₁.inf f := le_inf $ assume b hb, inf_le (h hb) lemma lt_inf_iff [h : is_total α (≤)] {a : α} (ha : a < ⊤) : a < s.inf f ↔ (∀b ∈ s, a < f b) := @sup_lt_iff (order_dual α) _ _ _ _ (@is_total.swap α _ h) _ ha lemma comp_inf_eq_inf_comp [semilattice_inf_top γ] {s : finset β} {f : β → α} (g : α → γ) (g_inf : ∀ x y, g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := @comp_sup_eq_sup_comp (order_dual α) _ (order_dual γ) _ _ _ _ _ g_inf top lemma comp_inf_eq_inf_comp_of_is_total [h : is_total α (≤)] {γ : Type} [semilattice_inf_top γ] (g : α → γ) (mono_g : monotone g) (top : g ⊤ = ⊤) : g (s.inf f) = s.inf (g ∘ f) := comp_inf_eq_inf_comp g mono_g.map_inf top /-- Computating `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/ lemma inf_coe {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀{{x y}}, P x → P y → P (x ⊓ y)} (t : finset β) (f : β → {x : α // P x}) : (@inf _ _ (subtype.semilattice_inf_top Ptop Pinf) t f : α) = t.inf (λ x, f x) := by { classical, rw [comp_inf_eq_inf_comp coe]; intros; refl } end inf lemma inf_eq_infi [complete_lattice β] (s : finset α) (f : α → β) : s.inf f = (⨅a∈s, f a) := @sup_eq_supr _ (order_dual β) _ _ _ /-! ### max and min of finite sets -/ section max_min variables [decidable_linear_order α] /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max : finset α → option α := fold (option.lift_or_get max) none some theorem max_eq_sup_with_bot (s : finset α) : s.max = @sup (with_bot α) α _ s some := rfl @[simp] theorem max_empty : (∅ : finset α).max = none := rfl @[simp] theorem max_insert {a : α} {s : finset α} : (insert a s).max = option.lift_or_get max (some a) s.max := fold_insert_idem @[simp] theorem max_singleton {a : α} : finset.max {a} = some a := by { rw [← insert_emptyc_eq], exact max_insert } theorem max_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.max := (@le_sup (with_bot α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem max_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.max := let ⟨a, ha⟩ := h in max_of_mem ha theorem max_eq_none {s : finset α} : s.max = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := max_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ max_empty⟩ theorem mem_of_max {s : finset α} : ∀ {a : α}, a ∈ s.max → a ∈ s := finset.induction_on s (λ _ H, by cases H) (λ b s _ (ih : ∀ {a}, a ∈ s.max → a ∈ s) a (h : a ∈ (insert b s).max), begin by_cases p : b = a, { induction p, exact mem_insert_self b s }, { cases option.lift_or_get_choice max_choice (some b) s.max with q q; rw [max_insert, q] at h, { cases h, cases p rfl }, { exact mem_insert_of_mem (ih h) } } end) theorem le_max_of_mem {s : finset α} {a b : α} (h₁ : a ∈ s) (h₂ : b ∈ s.max) : a ≤ b := by rcases @le_sup (with_bot α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min : finset α → option α := fold (option.lift_or_get min) none some theorem min_eq_inf_with_top (s : finset α) : s.min = @inf (with_top α) α _ s some := rfl @[simp] theorem min_empty : (∅ : finset α).min = none := rfl @[simp] theorem min_insert {a : α} {s : finset α} : (insert a s).min = option.lift_or_get min (some a) s.min := fold_insert_idem @[simp] theorem min_singleton {a : α} : finset.min {a} = some a := by { rw ← insert_emptyc_eq, exact min_insert } theorem min_of_mem {s : finset α} {a : α} (h : a ∈ s) : ∃ b, b ∈ s.min := (@inf_le (with_top α) _ _ _ _ _ h _ rfl).imp $ λ b, Exists.fst theorem min_of_nonempty {s : finset α} (h : s.nonempty) : ∃ a, a ∈ s.min := let ⟨a, ha⟩ := h in min_of_mem ha theorem min_eq_none {s : finset α} : s.min = none ↔ s = ∅ := ⟨λ h, s.eq_empty_or_nonempty.elim id (λ H, let ⟨a, ha⟩ := min_of_nonempty H in by rw h at ha; cases ha), λ h, h.symm ▸ min_empty⟩ theorem mem_of_min {s : finset α} : ∀ {a : α}, a ∈ s.min → a ∈ s := finset.induction_on s (λ _ H, by cases H) $ λ b s _ (ih : ∀ {a}, a ∈ s.min → a ∈ s) a (h : a ∈ (insert b s).min), begin by_cases p : b = a, { induction p, exact mem_insert_self b s }, { cases option.lift_or_get_choice min_choice (some b) s.min with q q; rw [min_insert, q] at h, { cases h, cases p rfl }, { exact mem_insert_of_mem (ih h) } } end theorem min_le_of_mem {s : finset α} {a b : α} (h₁ : b ∈ s) (h₂ : a ∈ s.min) : a ≤ b := by rcases @inf_le (with_top α) _ _ _ _ _ h₁ _ rfl with ⟨b', hb, ab⟩; cases h₂.symm.trans hb; assumption /-- Given a nonempty finset `s` in a linear order `α `, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `option α`. -/ def min' (s : finset α) (H : s.nonempty) : α := @option.get _ s.min $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := min_of_mem hk in by simp at hb; simp [hb] /-- Given a nonempty finset `s` in a linear order `α `, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `option α`. -/ def max' (s : finset α) (H : s.nonempty) : α := @option.get _ s.max $ let ⟨k, hk⟩ := H in let ⟨b, hb⟩ := max_of_mem hk in by simp at hb; simp [hb] variables (s : finset α) (H : s.nonempty) theorem min'_mem : s.min' H ∈ s := mem_of_min $ by simp [min'] theorem min'_le (x) (H2 : x ∈ s) : s.min' ⟨x, H2⟩ ≤ x := min_le_of_mem H2 $ option.get_mem _ theorem le_min' (x) (H2 : ∀ y ∈ s, x ≤ y) : x ≤ s.min' H := H2 _ $ min'_mem _ _ /-- `{a}.min' _` is `a`. -/ @[simp] lemma min'_singleton (a : α) : ({a} : finset α).min' (singleton_nonempty _) = a := by simp [min'] theorem max'_mem : s.max' H ∈ s := mem_of_max $ by simp [max'] theorem le_max' (x) (H2 : x ∈ s) : x ≤ s.max' ⟨x, H2⟩ := le_max_of_mem H2 $ option.get_mem _ theorem max'_le (x) (H2 : ∀ y ∈ s, y ≤ x) : s.max' H ≤ x := H2 _ $ max'_mem _ _ /-- `{a}.max' _` is `a`. -/ @[simp] lemma max'_singleton (a : α) : ({a} : finset α).max' (singleton_nonempty _) = a := by simp [max'] theorem min'_lt_max' {i j} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : s.min' ⟨i, H1⟩ < s.max' ⟨i, H1⟩ := begin rcases lt_trichotomy i j with H4 | H4 | H4, { have H5 := min'_le s i H1, have H6 := le_max' s j H2, apply lt_of_le_of_lt H5, apply lt_of_lt_of_le H4 H6 }, { cc }, { have H5 := min'_le s j H2, have H6 := le_max' s i H1, apply lt_of_le_of_lt H5, apply lt_of_lt_of_le H4 H6 } end /-- If there's more than 1 element, the min' is less than the max'. An alternate version of `min'_lt_max'` which is sometimes more convenient. -/ lemma min'_lt_max'_of_card (h₂ : 1 < card s) : s.min' (finset.card_pos.mp $ lt_trans zero_lt_one h₂) < s.max' (finset.card_pos.mp $ lt_trans zero_lt_one h₂) := begin apply lt_of_not_ge, intro a, apply not_le_of_lt h₂ (le_of_eq _), rw card_eq_one, use (max' s (finset.card_pos.mp $ lt_trans zero_lt_one h₂)), rw eq_singleton_iff_unique_mem, refine ⟨max'_mem _ _, λ t Ht, le_antisymm (le_max' s t Ht) (le_trans a (min'_le s t Ht))⟩, end end max_min section exists_max_min variables [linear_order α] lemma exists_max_image (s : finset β) (f : β → α) (h : s.nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x' ≤ f x := begin letI := classical.DLO α, cases max_of_nonempty (h.image f) with y hy, rcases mem_image.mp (mem_of_max hy) with ⟨x, hx, rfl⟩, exact ⟨x, hx, λ x' hx', le_max_of_mem (mem_image_of_mem f hx') hy⟩, end lemma exists_min_image (s : finset β) (f : β → α) (h : s.nonempty) : ∃ x ∈ s, ∀ x' ∈ s, f x ≤ f x' := @exists_max_image (order_dual α) β _ s f h end exists_max_min end finset namespace multiset lemma count_sup [decidable_eq β] (s : finset α) (f : α → multiset β) (b : β) : count b (s.sup f) = s.sup (λa, count b (f a)) := begin letI := classical.dec_eq α, refine s.induction _ _, { exact count_zero _ }, { assume i s his ih, rw [finset.sup_insert, sup_eq_union, count_union, finset.sup_insert, ih], refl } end end multiset section lattice variables {ι : Type*} {ι' : Sort*} [complete_lattice α] /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `supr_eq_supr_finset'` for a version that works for `ι : Sort*`. -/ lemma supr_eq_supr_finset (s : ι → α) : (⨆i, s i) = (⨆t:finset ι, ⨆i∈t, s i) := begin classical, exact le_antisymm (supr_le $ assume b, le_supr_of_le {b} $ le_supr_of_le b $ le_supr_of_le (by simp) $ le_refl _) (supr_le $ assume t, supr_le $ assume b, supr_le $ assume hb, le_supr _ _) end /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `supr_eq_supr_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ lemma supr_eq_supr_finset' (s : ι' → α) : (⨆i, s i) = (⨆t:finset (plift ι'), ⨆i∈t, s (plift.down i)) := by rw [← supr_eq_supr_finset, ← equiv.plift.surjective.supr_comp]; refl /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `infi_eq_infi_finset'` for a version that works for `ι : Sort*`. -/ lemma infi_eq_infi_finset (s : ι → α) : (⨅i, s i) = (⨅t:finset ι, ⨅i∈t, s i) := @supr_eq_supr_finset (order_dual α) _ _ _ /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `infi_eq_infi_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ lemma infi_eq_infi_finset' (s : ι' → α) : (⨅i, s i) = (⨅t:finset (plift ι'), ⨅i∈t, s (plift.down i)) := @supr_eq_supr_finset' (order_dual α) _ _ _ end lattice namespace set variables {ι : Type*} {ι' : Sort*} /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version assumes `ι : Type*`. See also `Union_eq_Union_finset'` for a version that works for `ι : Sort*`. -/ lemma Union_eq_Union_finset (s : ι → set α) : (⋃i, s i) = (⋃t:finset ι, ⋃i∈t, s i) := supr_eq_supr_finset s /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version works for `ι : Sort*`. See also `Union_eq_Union_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ lemma Union_eq_Union_finset' (s : ι' → set α) : (⋃i, s i) = (⋃t:finset (plift ι'), ⋃i∈t, s (plift.down i)) := supr_eq_supr_finset' s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version assumes `ι : Type*`. See also `Inter_eq_Inter_finset'` for a version that works for `ι : Sort*`. -/ lemma Inter_eq_Inter_finset (s : ι → set α) : (⋂i, s i) = (⋂t:finset ι, ⋂i∈t, s i) := infi_eq_infi_finset s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version works for `ι : Sort*`. See also `Inter_eq_Inter_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ lemma Inter_eq_Inter_finset' (s : ι' → set α) : (⋂i, s i) = (⋂t:finset (plift ι'), ⋂i∈t, s (plift.down i)) := infi_eq_infi_finset' s end set namespace finset open function /-! ### Interaction with big lattice/set operations -/ section lattice lemma supr_coe [has_Sup β] (f : α → β) (s : finset α) : (⨆ x ∈ (↑s : set α), f x) = ⨆ x ∈ s, f x := rfl lemma infi_coe [has_Inf β] (f : α → β) (s : finset α) : (⨅ x ∈ (↑s : set α), f x) = ⨅ x ∈ s, f x := rfl variables [complete_lattice β] theorem supr_singleton (a : α) (s : α → β) : (⨆ x ∈ ({a} : finset α), s x) = s a := by simp theorem infi_singleton (a : α) (s : α → β) : (⨅ x ∈ ({a} : finset α), s x) = s a := by simp lemma supr_option_to_finset (o : option α) (f : α → β) : (⨆ x ∈ o.to_finset, f x) = ⨆ x ∈ o, f x := by { congr, ext, rw [option.mem_to_finset] } lemma infi_option_to_finset (o : option α) (f : α → β) : (⨅ x ∈ o.to_finset, f x) = ⨅ x ∈ o, f x := @supr_option_to_finset _ (order_dual β) _ _ _ variables [decidable_eq α] theorem supr_union {f : α → β} {s t : finset α} : (⨆ x ∈ s ∪ t, f x) = (⨆x∈s, f x) ⊔ (⨆x∈t, f x) := by simp [supr_or, supr_sup_eq] theorem infi_union {f : α → β} {s t : finset α} : (⨅ x ∈ s ∪ t, f x) = (⨅ x ∈ s, f x) ⊓ (⨅ x ∈ t, f x) := by simp [infi_or, infi_inf_eq] lemma supr_insert (a : α) (s : finset α) (t : α → β) : (⨆ x ∈ insert a s, t x) = t a ⊔ (⨆ x ∈ s, t x) := by { rw insert_eq, simp only [supr_union, finset.supr_singleton] } lemma infi_insert (a : α) (s : finset α) (t : α → β) : (⨅ x ∈ insert a s, t x) = t a ⊓ (⨅ x ∈ s, t x) := by { rw insert_eq, simp only [infi_union, finset.infi_singleton] } lemma supr_finset_image {f : γ → α} {g : α → β} {s : finset γ} : (⨆ x ∈ s.image f, g x) = (⨆ y ∈ s, g (f y)) := by rw [← supr_coe, coe_image, supr_image, supr_coe] lemma infi_finset_image {f : γ → α} {g : α → β} {s : finset γ} : (⨅ x ∈ s.image f, g x) = (⨅ y ∈ s, g (f y)) := by rw [← infi_coe, coe_image, infi_image, infi_coe] lemma supr_insert_update {x : α} {t : finset α} (f : α → β) {s : β} (hx : x ∉ t) : (⨆ (i ∈ insert x t), function.update f x s i) = (s ⊔ ⨆ (i ∈ t), f i) := begin simp only [finset.supr_insert, update_same], rcongr i hi, apply update_noteq, rintro rfl, exact hx hi end lemma infi_insert_update {x : α} {t : finset α} (f : α → β) {s : β} (hx : x ∉ t) : (⨅ (i ∈ insert x t), update f x s i) = (s ⊓ ⨅ (i ∈ t), f i) := @supr_insert_update α (order_dual β) _ _ _ _ f _ hx lemma supr_bind (s : finset γ) (t : γ → finset α) (f : α → β) : (⨆ y ∈ s.bind t, f y) = ⨆ (x ∈ s) (y ∈ t x), f y := calc (⨆ y ∈ s.bind t, f y) = ⨆ y (hy : ∃ x ∈ s, y ∈ t x), f y : congr_arg _ $ funext $ λ y, by rw [mem_bind] ... = _ : by simp only [supr_exists, @supr_comm _ α] lemma infi_bind (s : finset γ) (t : γ → finset α) (f : α → β) : (⨅ y ∈ s.bind t, f y) = ⨅ (x ∈ s) (y ∈ t x), f y := @supr_bind _ (order_dual β) _ _ _ _ _ _ end lattice @[simp] theorem bUnion_coe (s : finset α) (t : α → set β) : (⋃ x ∈ (↑s : set α), t x) = ⋃ x ∈ s, t x := rfl @[simp] theorem bInter_coe (s : finset α) (t : α → set β) : (⋂ x ∈ (↑s : set α), t x) = ⋂ x ∈ s, t x := rfl @[simp] theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : finset α), s x) = s a := supr_singleton a s @[simp] theorem bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : finset α), s x) = s a := infi_singleton a s @[simp] lemma bUnion_preimage_singleton (f : α → β) (s : finset β) : (⋃ y ∈ s, f ⁻¹' {y}) = f ⁻¹' ↑s := set.bUnion_preimage_singleton f ↑s @[simp] lemma bUnion_option_to_finset (o : option α) (f : α → set β) : (⋃ x ∈ o.to_finset, f x) = ⋃ x ∈ o, f x := supr_option_to_finset o f @[simp] lemma bInter_option_to_finset (o : option α) (f : α → set β) : (⋂ x ∈ o.to_finset, f x) = ⋂ x ∈ o, f x := infi_option_to_finset o f variables [decidable_eq α] lemma bUnion_union (s t : finset α) (u : α → set β) : (⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) := supr_union lemma bInter_inter (s t : finset α) (u : α → set β) : (⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) := infi_union @[simp] lemma bUnion_insert (a : α) (s : finset α) (t : α → set β) : (⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) := supr_insert a s t @[simp] lemma bInter_insert (a : α) (s : finset α) (t : α → set β) : (⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) := infi_insert a s t @[simp] lemma bUnion_finset_image {f : γ → α} {g : α → set β} {s : finset γ} : (⋃x ∈ s.image f, g x) = (⋃y ∈ s, g (f y)) := supr_finset_image @[simp] lemma bInter_finset_image {f : γ → α} {g : α → set β} {s : finset γ} : (⋂ x ∈ s.image f, g x) = (⋂ y ∈ s, g (f y)) := infi_finset_image lemma bUnion_insert_update {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : x ∉ t) : (⋃ (i ∈ insert x t), @update _ _ _ f x s i) = (s ∪ ⋃ (i ∈ t), f i) := supr_insert_update f hx lemma bInter_insert_update {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : x ∉ t) : (⋂ (i ∈ insert x t), @update _ _ _ f x s i) = (s ∩ ⋂ (i ∈ t), f i) := infi_insert_update f hx @[simp] lemma bUnion_bind (s : finset γ) (t : γ → finset α) (f : α → set β) : (⋃ y ∈ s.bind t, f y) = ⋃ (x ∈ s) (y ∈ t x), f y := supr_bind s t f @[simp] lemma bInter_bind (s : finset γ) (t : γ → finset α) (f : α → set β) : (⋂ y ∈ s.bind t, f y) = ⋂ (x ∈ s) (y ∈ t x), f y := infi_bind s t f end finset
752e291ac4c8ace344b0d8032c2c29225342033f
92b50235facfbc08dfe7f334827d47281471333b
/library/data/num.lean
98bb1165598c01ab2d063a54942ddbcc56f19b7d
[ "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
17,532
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import data.bool tools.helper_tactics open bool eq.ops decidable helper_tactics namespace pos_num theorem succ_not_is_one (a : pos_num) : is_one (succ a) = ff := pos_num.induction_on a rfl (take n iH, rfl) (take n iH, rfl) theorem succ_one : succ one = bit0 one theorem succ_bit1 (a : pos_num) : succ (bit1 a) = bit0 (succ a) theorem succ_bit0 (a : pos_num) : succ (bit0 a) = bit1 a theorem ne_of_bit0_ne_bit0 {a b : pos_num} (H₁ : bit0 a ≠ bit0 b) : a ≠ b := assume H : a = b, absurd rfl (H ▸ H₁) theorem ne_of_bit1_ne_bit1 {a b : pos_num} (H₁ : bit1 a ≠ bit1 b) : a ≠ b := assume H : a = b, absurd rfl (H ▸ H₁) theorem pred_succ : ∀ (a : pos_num), pred (succ a) = a | one := rfl | (bit0 a) := by rewrite succ_bit0 | (bit1 a) := calc pred (succ (bit1 a)) = cond (is_one (succ a)) one (bit1 (pred (succ a))) : rfl ... = cond ff one (bit1 (pred (succ a))) : succ_not_is_one ... = bit1 (pred (succ a)) : rfl ... = bit1 a : pred_succ a section variables (a b : pos_num) theorem one_add_one : one + one = bit0 one theorem one_add_bit0 : one + (bit0 a) = bit1 a theorem one_add_bit1 : one + (bit1 a) = succ (bit1 a) theorem bit0_add_one : (bit0 a) + one = bit1 a theorem bit1_add_one : (bit1 a) + one = succ (bit1 a) theorem bit0_add_bit0 : (bit0 a) + (bit0 b) = bit0 (a + b) theorem bit0_add_bit1 : (bit0 a) + (bit1 b) = bit1 (a + b) theorem bit1_add_bit0 : (bit1 a) + (bit0 b) = bit1 (a + b) theorem bit1_add_bit1 : (bit1 a) + (bit1 b) = succ (bit1 (a + b)) theorem one_mul : one * a = a end theorem mul_one : ∀ a, a * one = a | one := rfl | (bit1 n) := calc bit1 n * one = bit0 (n * one) + one : rfl ... = bit0 n + one : mul_one n ... = bit1 n : bit0_add_one | (bit0 n) := calc bit0 n * one = bit0 (n * one) : rfl ... = bit0 n : mul_one n theorem decidable_eq [instance] : ∀ (a b : pos_num), decidable (a = b) | one one := inl rfl | one (bit0 b) := inr (by contradiction) | one (bit1 b) := inr (by contradiction) | (bit0 a) one := inr (by contradiction) | (bit0 a) (bit0 b) := match decidable_eq a b with | inl H₁ := inl (by rewrite H₁) | inr H₁ := inr (by intro H; injection H; contradiction) end | (bit0 a) (bit1 b) := inr (by contradiction) | (bit1 a) one := inr (by contradiction) | (bit1 a) (bit0 b) := inr (by contradiction) | (bit1 a) (bit1 b) := match decidable_eq a b with | inl H₁ := inl (by rewrite H₁) | inr H₁ := inr (by intro H; injection H; contradiction) end local notation a < b := (lt a b = tt) local notation a `≮`:50 b:50 := (lt a b = ff) theorem lt_one_right_eq_ff : ∀ a : pos_num, a ≮ one | one := rfl | (bit0 a) := rfl | (bit1 a) := rfl theorem lt_one_succ_eq_tt : ∀ a : pos_num, one < succ a | one := rfl | (bit0 a) := rfl | (bit1 a) := rfl theorem lt_of_lt_bit0_bit0 {a b : pos_num} (H : bit0 a < bit0 b) : a < b := H theorem lt_of_lt_bit0_bit1 {a b : pos_num} (H : bit1 a < bit0 b) : a < b := H theorem lt_of_lt_bit1_bit1 {a b : pos_num} (H : bit1 a < bit1 b) : a < b := H theorem lt_of_lt_bit1_bit0 {a b : pos_num} (H : bit0 a < bit1 b) : a < succ b := H theorem lt_bit0_bit0_eq_lt (a b : pos_num) : lt (bit0 a) (bit0 b) = lt a b := rfl theorem lt_bit1_bit1_eq_lt (a b : pos_num) : lt (bit1 a) (bit1 b) = lt a b := rfl theorem lt_bit1_bit0_eq_lt (a b : pos_num) : lt (bit1 a) (bit0 b) = lt a b := rfl theorem lt_bit0_bit1_eq_lt_succ (a b : pos_num) : lt (bit0 a) (bit1 b) = lt a (succ b) := rfl theorem lt_irrefl : ∀ (a : pos_num), a ≮ a | one := rfl | (bit0 a) := begin rewrite lt_bit0_bit0_eq_lt, apply lt_irrefl end | (bit1 a) := begin rewrite lt_bit1_bit1_eq_lt, apply lt_irrefl end theorem ne_of_lt_eq_tt : ∀ {a b : pos_num}, a < b → a = b → false | one ⌞one⌟ H₁ (eq.refl one) := absurd H₁ ff_ne_tt | (bit0 a) ⌞(bit0 a)⌟ H₁ (eq.refl (bit0 a)) := begin rewrite lt_bit0_bit0_eq_lt at H₁, apply ne_of_lt_eq_tt H₁ (eq.refl a) end | (bit1 a) ⌞(bit1 a)⌟ H₁ (eq.refl (bit1 a)) := begin rewrite lt_bit1_bit1_eq_lt at H₁, apply ne_of_lt_eq_tt H₁ (eq.refl a) end theorem lt_base : ∀ a : pos_num, a < succ a | one := rfl | (bit0 a) := begin rewrite [succ_bit0, lt_bit0_bit1_eq_lt_succ], apply lt_base end | (bit1 a) := begin rewrite [succ_bit1, lt_bit1_bit0_eq_lt], apply lt_base end theorem lt_step : ∀ {a b : pos_num}, a < b → a < succ b | one one H := rfl | one (bit0 b) H := rfl | one (bit1 b) H := rfl | (bit0 a) one H := absurd H ff_ne_tt | (bit0 a) (bit0 b) H := begin rewrite [succ_bit0, lt_bit0_bit1_eq_lt_succ, lt_bit0_bit0_eq_lt at H], apply lt_step H end | (bit0 a) (bit1 b) H := begin rewrite [succ_bit1, lt_bit0_bit0_eq_lt, lt_bit0_bit1_eq_lt_succ at H], exact H end | (bit1 a) one H := absurd H ff_ne_tt | (bit1 a) (bit0 b) H := begin rewrite [succ_bit0, lt_bit1_bit1_eq_lt, lt_bit1_bit0_eq_lt at H], exact H end | (bit1 a) (bit1 b) H := begin rewrite [succ_bit1, lt_bit1_bit0_eq_lt, lt_bit1_bit1_eq_lt at H], apply lt_step H end theorem lt_of_lt_succ_succ : ∀ {a b : pos_num}, succ a < succ b → a < b | one one H := absurd H ff_ne_tt | one (bit0 b) H := rfl | one (bit1 b) H := rfl | (bit0 a) one H := begin rewrite [succ_bit0 at H, succ_one at H, lt_bit1_bit0_eq_lt at H], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H end | (bit0 a) (bit0 b) H := by exact H | (bit0 a) (bit1 b) H := by exact H | (bit1 a) one H := begin rewrite [succ_bit1 at H, succ_one at H, lt_bit0_bit0_eq_lt at H], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff (succ a)) H end | (bit1 a) (bit0 b) H := begin rewrite [succ_bit1 at H, succ_bit0 at H, lt_bit0_bit1_eq_lt_succ at H], rewrite lt_bit1_bit0_eq_lt, apply lt_of_lt_succ_succ H end | (bit1 a) (bit1 b) H := begin rewrite [lt_bit1_bit1_eq_lt, *succ_bit1 at H, lt_bit0_bit0_eq_lt at H], apply lt_of_lt_succ_succ H end theorem lt_succ_succ : ∀ {a b : pos_num}, a < b → succ a < succ b | one one H := absurd H ff_ne_tt | one (bit0 b) H := begin rewrite [succ_bit0, succ_one, lt_bit0_bit1_eq_lt_succ], apply lt_one_succ_eq_tt end | one (bit1 b) H := begin rewrite [succ_one, succ_bit1, lt_bit0_bit0_eq_lt], apply lt_one_succ_eq_tt end | (bit0 a) one H := absurd H ff_ne_tt | (bit0 a) (bit0 b) H := by exact H | (bit0 a) (bit1 b) H := by exact H | (bit1 a) one H := absurd H ff_ne_tt | (bit1 a) (bit0 b) H := begin rewrite [succ_bit1, succ_bit0, lt_bit0_bit1_eq_lt_succ, lt_bit1_bit0_eq_lt at H], apply lt_succ_succ H end | (bit1 a) (bit1 b) H := begin rewrite [lt_bit1_bit1_eq_lt at H, *succ_bit1, lt_bit0_bit0_eq_lt], apply lt_succ_succ H end theorem lt_of_lt_succ : ∀ {a b : pos_num}, succ a < b → a < b | one one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H | one (bit0 b) H := rfl | one (bit1 b) H := rfl | (bit0 a) one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H | (bit0 a) (bit0 b) H := by exact H | (bit0 a) (bit1 b) H := begin rewrite [succ_bit0 at H, lt_bit1_bit1_eq_lt at H, lt_bit0_bit1_eq_lt_succ], apply lt_step H end | (bit1 a) one H := absurd_of_eq_ff_of_eq_tt !lt_one_right_eq_ff H | (bit1 a) (bit0 b) H := begin rewrite [lt_bit1_bit0_eq_lt, succ_bit1 at H, lt_bit0_bit0_eq_lt at H], apply lt_of_lt_succ H end | (bit1 a) (bit1 b) H := begin rewrite [succ_bit1 at H, lt_bit0_bit1_eq_lt_succ at H, lt_bit1_bit1_eq_lt], apply lt_of_lt_succ_succ H end theorem lt_of_lt_succ_of_ne : ∀ {a b : pos_num}, a < succ b → a ≠ b → a < b | one one H₁ H₂ := absurd rfl H₂ | one (bit0 b) H₁ H₂ := rfl | one (bit1 b) H₁ H₂ := rfl | (bit0 a) one H₁ H₂ := begin rewrite [succ_one at H₁, lt_bit0_bit0_eq_lt at H₁], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁ end | (bit0 a) (bit0 b) H₁ H₂ := begin rewrite [lt_bit0_bit0_eq_lt, succ_bit0 at H₁, lt_bit0_bit1_eq_lt_succ at H₁], apply lt_of_lt_succ_of_ne H₁ (ne_of_bit0_ne_bit0 H₂) end | (bit0 a) (bit1 b) H₁ H₂ := begin rewrite [succ_bit1 at H₁, lt_bit0_bit0_eq_lt at H₁, lt_bit0_bit1_eq_lt_succ], exact H₁ end | (bit1 a) one H₁ H₂ := begin rewrite [succ_one at H₁, lt_bit1_bit0_eq_lt at H₁], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁ end | (bit1 a) (bit0 b) H₁ H₂ := begin rewrite [succ_bit0 at H₁, lt_bit1_bit1_eq_lt at H₁, lt_bit1_bit0_eq_lt], exact H₁ end | (bit1 a) (bit1 b) H₁ H₂ := begin rewrite [succ_bit1 at H₁, lt_bit1_bit0_eq_lt at H₁, lt_bit1_bit1_eq_lt], apply lt_of_lt_succ_of_ne H₁ (ne_of_bit1_ne_bit1 H₂) end theorem lt_trans : ∀ {a b c : pos_num}, a < b → b < c → a < c | one b (bit0 c) H₁ H₂ := rfl | one b (bit1 c) H₁ H₂ := rfl | a (bit0 b) one H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂ | a (bit1 b) one H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂ | (bit0 a) (bit0 b) (bit0 c) H₁ H₂ := begin rewrite lt_bit0_bit0_eq_lt at *, apply lt_trans H₁ H₂ end | (bit0 a) (bit0 b) (bit1 c) H₁ H₂ := begin rewrite [lt_bit0_bit1_eq_lt_succ at *, lt_bit0_bit0_eq_lt at H₁], apply lt_trans H₁ H₂ end | (bit0 a) (bit1 b) (bit0 c) H₁ H₂ := begin rewrite [lt_bit0_bit1_eq_lt_succ at H₁, lt_bit1_bit0_eq_lt at H₂, lt_bit0_bit0_eq_lt], apply @by_cases (a = b), begin intro H, rewrite -H at H₂, exact H₂ end, begin intro H, apply lt_trans (lt_of_lt_succ_of_ne H₁ H) H₂ end end | (bit0 a) (bit1 b) (bit1 c) H₁ H₂ := begin rewrite [lt_bit0_bit1_eq_lt_succ at *, lt_bit1_bit1_eq_lt at H₂], apply lt_trans H₁ (lt_succ_succ H₂) end | (bit1 a) (bit0 b) (bit0 c) H₁ H₂ := begin rewrite [lt_bit0_bit0_eq_lt at H₂, lt_bit1_bit0_eq_lt at *], apply lt_trans H₁ H₂ end | (bit1 a) (bit0 b) (bit1 c) H₁ H₂ := begin rewrite [lt_bit1_bit0_eq_lt at H₁, lt_bit0_bit1_eq_lt_succ at H₂, lt_bit1_bit1_eq_lt], apply @by_cases (b = c), begin intro H, rewrite H at H₁, exact H₁ end, begin intro H, apply lt_trans H₁ (lt_of_lt_succ_of_ne H₂ H) end end | (bit1 a) (bit1 b) (bit0 c) H₁ H₂ := begin rewrite [lt_bit1_bit1_eq_lt at H₁, lt_bit1_bit0_eq_lt at H₂, lt_bit1_bit0_eq_lt], apply lt_trans H₁ H₂ end | (bit1 a) (bit1 b) (bit1 c) H₁ H₂ := begin rewrite lt_bit1_bit1_eq_lt at *, apply lt_trans H₁ H₂ end theorem lt_antisymm : ∀ {a b : pos_num}, a < b → b ≮ a | one one H := rfl | one (bit0 b) H := rfl | one (bit1 b) H := rfl | (bit0 a) one H := absurd H ff_ne_tt | (bit0 a) (bit0 b) H := begin rewrite lt_bit0_bit0_eq_lt at *, apply lt_antisymm H end | (bit0 a) (bit1 b) H := begin rewrite lt_bit1_bit0_eq_lt, rewrite lt_bit0_bit1_eq_lt_succ at H, have H₁ : succ b ≮ a, from lt_antisymm H, apply eq_ff_of_ne_tt, intro H₂, apply @by_cases (succ b = a), show succ b = a → false, begin intro Hp, rewrite -Hp at H, apply absurd_of_eq_ff_of_eq_tt (lt_irrefl (succ b)) H end, show succ b ≠ a → false, begin intro Hn, have H₃ : succ b < succ a, from lt_succ_succ H₂, have H₄ : succ b < a, from lt_of_lt_succ_of_ne H₃ Hn, apply absurd_of_eq_ff_of_eq_tt H₁ H₄ end, end | (bit1 a) one H := absurd H ff_ne_tt | (bit1 a) (bit0 b) H := begin rewrite lt_bit0_bit1_eq_lt_succ, rewrite lt_bit1_bit0_eq_lt at H, have H₁ : lt b a = ff, from lt_antisymm H, apply eq_ff_of_ne_tt, intro H₂, apply @by_cases (b = a), show b = a → false, begin intro Hp, rewrite -Hp at H, apply absurd_of_eq_ff_of_eq_tt (lt_irrefl b) H end, show b ≠ a → false, begin intro Hn, have H₃ : b < a, from lt_of_lt_succ_of_ne H₂ Hn, apply absurd_of_eq_ff_of_eq_tt H₁ H₃ end, end | (bit1 a) (bit1 b) H := begin rewrite lt_bit1_bit1_eq_lt at *, apply lt_antisymm H end local notation a ≤ b := (le a b = tt) theorem le_refl : ∀ a : pos_num, a ≤ a := lt_base theorem le_eq_lt_succ {a b : pos_num} : le a b = lt a (succ b) := rfl theorem not_lt_of_le : ∀ {a b : pos_num}, a ≤ b → b < a → false | one one H₁ H₂ := absurd H₂ ff_ne_tt | one (bit0 b) H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂ | one (bit1 b) H₁ H₂ := absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₂ | (bit0 a) one H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_one at H₁, lt_bit0_bit0_eq_lt at H₁], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁ end | (bit0 a) (bit0 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_bit0 at H₁, lt_bit0_bit1_eq_lt_succ at H₁], rewrite [lt_bit0_bit0_eq_lt at H₂], apply not_lt_of_le H₁ H₂ end | (bit0 a) (bit1 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_bit1 at H₁, lt_bit0_bit0_eq_lt at H₁], rewrite [lt_bit1_bit0_eq_lt at H₂], apply not_lt_of_le H₁ H₂ end | (bit1 a) one H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_one at H₁, lt_bit1_bit0_eq_lt at H₁], apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff _) H₁ end | (bit1 a) (bit0 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_bit0 at H₁, lt_bit1_bit1_eq_lt at H₁], rewrite lt_bit0_bit1_eq_lt_succ at H₂, have H₃ : a < succ b, from lt_step H₁, apply @by_cases (b = a), begin intro Hba, rewrite -Hba at H₁, apply absurd_of_eq_ff_of_eq_tt (lt_irrefl b) H₁ end, begin intro Hnba, have H₄ : b < a, from lt_of_lt_succ_of_ne H₂ Hnba, apply not_lt_of_le H₃ H₄ end end | (bit1 a) (bit1 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at H₁, succ_bit1 at H₁, lt_bit1_bit0_eq_lt at H₁], rewrite [lt_bit1_bit1_eq_lt at H₂], apply not_lt_of_le H₁ H₂ end theorem le_antisymm : ∀ {a b : pos_num}, a ≤ b → b ≤ a → a = b | one one H₁ H₂ := rfl | one (bit0 b) H₁ H₂ := by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff b) H₂ | one (bit1 b) H₁ H₂ := by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff b) H₂ | (bit0 a) one H₁ H₂ := by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H₁ | (bit0 a) (bit0 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at *, succ_bit0 at *, lt_bit0_bit1_eq_lt_succ at *], have H : a = b, from le_antisymm H₁ H₂, rewrite H end | (bit0 a) (bit1 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at *, succ_bit1 at H₁, succ_bit0 at H₂], rewrite [lt_bit0_bit0_eq_lt at H₁, lt_bit1_bit1_eq_lt at H₂], apply false.rec _ (not_lt_of_le H₁ H₂) end | (bit1 a) one H₁ H₂ := by apply absurd_of_eq_ff_of_eq_tt (lt_one_right_eq_ff a) H₁ | (bit1 a) (bit0 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at *, succ_bit0 at H₁, succ_bit1 at H₂], rewrite [lt_bit1_bit1_eq_lt at H₁, lt_bit0_bit0_eq_lt at H₂], apply false.rec _ (not_lt_of_le H₂ H₁) end | (bit1 a) (bit1 b) H₁ H₂ := begin rewrite [le_eq_lt_succ at *, succ_bit1 at *, lt_bit1_bit0_eq_lt at *], have H : a = b, from le_antisymm H₁ H₂, rewrite H end theorem le_trans {a b c : pos_num} : a ≤ b → b ≤ c → a ≤ c := begin intro H₁ H₂, rewrite [le_eq_lt_succ at *], apply @by_cases (a = b), begin intro Hab, rewrite Hab, exact H₂ end, begin intro Hnab, have Haltb : a < b, from lt_of_lt_succ_of_ne H₁ Hnab, apply lt_trans Haltb H₂ end, end end pos_num
aaaf9cf4e579a43d5c356698e321487ab3bb95c2
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/data/quot.lean
9e3af2d9cb03b515ecb50e56f1f9150af15ffcfd
[]
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
9,440
lean
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura Quotient types. -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.data.sigma.basic import Mathlib.Lean3Lib.init.logic import Mathlib.Lean3Lib.init.propext import Mathlib.Lean3Lib.init.data.setoid universes u v u_a u_b u_c namespace Mathlib /- We import propext here, otherwise we would need a quot.lift for propositions. -/ -- iff can now be used to do substitutions in a calculation theorem iff_subst {a : Prop} {b : Prop} {p : Prop → Prop} (h₁ : a ↔ b) (h₂ : p a) : p b := propext h₁ ▸ h₂ namespace quot axiom sound {α : Sort u} {r : α → α → Prop} {a : α} {b : α} : r a b → Quot.mk r a = Quot.mk r bprotected theorem lift_beta {α : Sort u} {r : α → α → Prop} {β : Sort v} (f : α → β) (c : ∀ (a b : α), r a b → f a = f b) (a : α) : Quot.lift f c (Quot.mk r a) = f a := rfl protected theorem ind_beta {α : Sort u} {r : α → α → Prop} {β : Quot r → Prop} (p : ∀ (a : α), β (Quot.mk r a)) (a : α) : Quot.ind p (Quot.mk r a) = p a := rfl protected def lift_on {α : Sort u} {β : Sort v} {r : α → α → Prop} (q : Quot r) (f : α → β) (c : ∀ (a b : α), r a b → f a = f b) : β := Quot.lift f c q protected theorem induction_on {α : Sort u} {r : α → α → Prop} {β : Quot r → Prop} (q : Quot r) (h : ∀ (a : α), β (Quot.mk r a)) : β q := Quot.ind h q theorem exists_rep {α : Sort u} {r : α → α → Prop} (q : Quot r) : ∃ (a : α), Quot.mk r a = q := quot.induction_on q fun (a : α) => Exists.intro a rfl protected def indep {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (f : (a : α) → β (Quot.mk r a)) (a : α) : psigma β := psigma.mk (Quot.mk r a) (f a) protected theorem indep_coherent {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (f : (a : α) → β (Quot.mk r a)) (h : ∀ (a b : α) (p : r a b), Eq._oldrec (f a) (sound p) = f b) (a : α) (b : α) : r a b → quot.indep f a = quot.indep f b := fun (e : r a b) => psigma.eq (sound e) (h a b e) protected theorem lift_indep_pr1 {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (f : (a : α) → β (Quot.mk r a)) (h : ∀ (a b : α) (p : r a b), Eq._oldrec (f a) (sound p) = f b) (q : Quot r) : psigma.fst (Quot.lift (quot.indep f) (quot.indep_coherent f h) q) = q := Quot.ind (fun (a : α) => Eq.refl (psigma.fst (quot.indep f a))) q protected def rec {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (f : (a : α) → β (Quot.mk r a)) (h : ∀ (a b : α) (p : r a b), Eq._oldrec (f a) (sound p) = f b) (q : Quot r) : β q := eq.rec_on (quot.lift_indep_pr1 f h q) (psigma.snd (Quot.lift (quot.indep f) (quot.indep_coherent f h) q)) protected def rec_on {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (q : Quot r) (f : (a : α) → β (Quot.mk r a)) (h : ∀ (a b : α) (p : r a b), Eq._oldrec (f a) (sound p) = f b) : β q := quot.rec f h q protected def rec_on_subsingleton {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} [h : ∀ (a : α), subsingleton (β (Quot.mk r a))] (q : Quot r) (f : (a : α) → β (Quot.mk r a)) : β q := quot.rec f sorry q protected def hrec_on {α : Sort u} {r : α → α → Prop} {β : Quot r → Sort v} (q : Quot r) (f : (a : α) → β (Quot.mk r a)) (c : ∀ (a b : α), r a b → f a == f b) : β q := quot.rec_on q f sorry end quot def quotient {α : Sort u} (s : setoid α) := Quot setoid.r namespace quotient protected def mk {α : Sort u} [s : setoid α] (a : α) : quotient s := Quot.mk setoid.r a def sound {α : Sort u} [s : setoid α] {a : α} {b : α} : a ≈ b → quotient.mk a = quotient.mk b := quot.sound protected def lift {α : Sort u} {β : Sort v} [s : setoid α] (f : α → β) : (∀ (a b : α), a ≈ b → f a = f b) → quotient s → β := Quot.lift f protected theorem ind {α : Sort u} [s : setoid α] {β : quotient s → Prop} : (∀ (a : α), β (quotient.mk a)) → ∀ (q : quotient s), β q := Quot.ind protected def lift_on {α : Sort u} {β : Sort v} [s : setoid α] (q : quotient s) (f : α → β) (c : ∀ (a b : α), a ≈ b → f a = f b) : β := quot.lift_on q f c protected theorem induction_on {α : Sort u} [s : setoid α] {β : quotient s → Prop} (q : quotient s) (h : ∀ (a : α), β (quotient.mk a)) : β q := quot.induction_on q h theorem exists_rep {α : Sort u} [s : setoid α] (q : quotient s) : ∃ (a : α), quotient.mk a = q := quot.exists_rep q protected def rec {α : Sort u} [s : setoid α] {β : quotient s → Sort v} (f : (a : α) → β (quotient.mk a)) (h : ∀ (a b : α) (p : a ≈ b), Eq._oldrec (f a) (sound p) = f b) (q : quotient s) : β q := quot.rec f h q protected def rec_on {α : Sort u} [s : setoid α] {β : quotient s → Sort v} (q : quotient s) (f : (a : α) → β (quotient.mk a)) (h : ∀ (a b : α) (p : a ≈ b), Eq._oldrec (f a) (sound p) = f b) : β q := quot.rec_on q f h protected def rec_on_subsingleton {α : Sort u} [s : setoid α] {β : quotient s → Sort v} [h : ∀ (a : α), subsingleton (β (quotient.mk a))] (q : quotient s) (f : (a : α) → β (quotient.mk a)) : β q := quot.rec_on_subsingleton q f protected def hrec_on {α : Sort u} [s : setoid α] {β : quotient s → Sort v} (q : quotient s) (f : (a : α) → β (quotient.mk a)) (c : ∀ (a b : α), a ≈ b → f a == f b) : β q := quot.hrec_on q f c protected def lift₂ {α : Sort u_a} {β : Sort u_b} {φ : Sort u_c} [s₁ : setoid α] [s₂ : setoid β] (f : α → β → φ) (c : ∀ (a₁ : α) (a₂ : β) (b₁ : α) (b₂ : β), a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) (q₁ : quotient s₁) (q₂ : quotient s₂) : φ := quotient.lift (fun (a₁ : α) => quotient.lift (f a₁) sorry q₂) sorry q₁ protected def lift_on₂ {α : Sort u_a} {β : Sort u_b} {φ : Sort u_c} [s₁ : setoid α] [s₂ : setoid β] (q₁ : quotient s₁) (q₂ : quotient s₂) (f : α → β → φ) (c : ∀ (a₁ : α) (a₂ : β) (b₁ : α) (b₂ : β), a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) : φ := quotient.lift₂ f c q₁ q₂ protected theorem ind₂ {α : Sort u_a} {β : Sort u_b} [s₁ : setoid α] [s₂ : setoid β] {φ : quotient s₁ → quotient s₂ → Prop} (h : ∀ (a : α) (b : β), φ (quotient.mk a) (quotient.mk b)) (q₁ : quotient s₁) (q₂ : quotient s₂) : φ q₁ q₂ := quotient.ind (fun (a₁ : α) => quotient.ind (fun (a₂ : β) => h a₁ a₂) q₂) q₁ protected theorem induction_on₂ {α : Sort u_a} {β : Sort u_b} [s₁ : setoid α] [s₂ : setoid β] {φ : quotient s₁ → quotient s₂ → Prop} (q₁ : quotient s₁) (q₂ : quotient s₂) (h : ∀ (a : α) (b : β), φ (quotient.mk a) (quotient.mk b)) : φ q₁ q₂ := quotient.ind (fun (a₁ : α) => quotient.ind (fun (a₂ : β) => h a₁ a₂) q₂) q₁ protected theorem induction_on₃ {α : Sort u_a} {β : Sort u_b} {φ : Sort u_c} [s₁ : setoid α] [s₂ : setoid β] [s₃ : setoid φ] {δ : quotient s₁ → quotient s₂ → quotient s₃ → Prop} (q₁ : quotient s₁) (q₂ : quotient s₂) (q₃ : quotient s₃) (h : ∀ (a : α) (b : β) (c : φ), δ (quotient.mk a) (quotient.mk b) (quotient.mk c)) : δ q₁ q₂ q₃ := quotient.ind (fun (a₁ : α) => quotient.ind (fun (a₂ : β) => quotient.ind (fun (a₃ : φ) => h a₁ a₂ a₃) q₃) q₂) q₁ theorem exact {α : Sort u} [s : setoid α] {a : α} {b : α} : quotient.mk a = quotient.mk b → a ≈ b := fun (h : quotient.mk a = quotient.mk b) => eq_imp_rel h protected def rec_on_subsingleton₂ {α : Sort u_a} {β : Sort u_b} [s₁ : setoid α] [s₂ : setoid β] {φ : quotient s₁ → quotient s₂ → Sort u_c} [h : ∀ (a : α) (b : β), subsingleton (φ (quotient.mk a) (quotient.mk b))] (q₁ : quotient s₁) (q₂ : quotient s₂) (f : (a : α) → (b : β) → φ (quotient.mk a) (quotient.mk b)) : φ q₁ q₂ := quotient.rec_on_subsingleton q₁ fun (a : α) => quotient.rec_on_subsingleton q₂ fun (b : β) => f a b end quotient inductive eqv_gen {α : Type u} (r : α → α → Prop) : α → α → Prop where | rel : ∀ (x y : α), r x y → eqv_gen r x y | refl : ∀ (x : α), eqv_gen r x x | symm : ∀ (x y : α), eqv_gen r x y → eqv_gen r y x | trans : ∀ (x y z : α), eqv_gen r x y → eqv_gen r y z → eqv_gen r x z theorem eqv_gen.is_equivalence {α : Type u} (r : α → α → Prop) : equivalence (eqv_gen r) := mk_equivalence (eqv_gen r) eqv_gen.refl eqv_gen.symm eqv_gen.trans def eqv_gen.setoid {α : Type u} (r : α → α → Prop) : setoid α := setoid.mk (eqv_gen r) (eqv_gen.is_equivalence r) theorem quot.exact {α : Type u} (r : α → α → Prop) {a : α} {b : α} (H : Quot.mk r a = Quot.mk r b) : eqv_gen r a b := quotient.exact (congr_arg (Quot.lift quotient.mk fun (x y : α) (h : r x y) => quot.sound (eqv_gen.rel x y h)) H) theorem quot.eqv_gen_sound {α : Type u} {r : α → α → Prop} {a : α} {b : α} (H : eqv_gen r a b) : Quot.mk r a = Quot.mk r b := sorry protected instance quotient.decidable_eq {α : Sort u} {s : setoid α} [d : (a b : α) → Decidable (a ≈ b)] : DecidableEq (quotient s) := fun (q₁ q₂ : quotient s) => quotient.rec_on_subsingleton₂ q₁ q₂ fun (a₁ a₂ : α) => sorry
93da83f24f2a85ffb252754cb782a8246de4b2cf
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/complex/schwarz.lean
83e5125bb8ded91e2586db67b38048f8f81a3bf5
[ "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
10,050
lean
/- Copyright (c) 2022 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import analysis.complex.abs_max import analysis.complex.removable_singularity /-! # Schwarz lemma In this file we prove several versions of the Schwarz lemma. * `complex.norm_deriv_le_div_of_maps_to_ball`, `complex.abs_deriv_le_div_of_maps_to_ball`: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`; * `complex.dist_le_div_mul_dist_of_maps_to_ball`: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open disk with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`; * `complex.abs_deriv_le_one_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`; * `complex.dist_le_dist_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`; * `complex.abs_le_abs_of_maps_to_ball`: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, then for any point `z` of this disk we have `abs (f z) ≤ abs z`. ## Implementation notes We prove some versions of the Schwarz lemma for a map `f : ℂ → E` taking values in any normed space over complex numbers. ## TODO * Prove that these inequalities are strict unless `f` is an affine map. * Prove that any diffeomorphism of the unit disk to itself is a Möbius map. ## Tags Schwarz lemma -/ open metric set function filter topological_space open_locale topological_space namespace complex section space variables {E : Type*} [normed_add_comm_group E] [normed_space ℂ E] {R R₁ R₂ : ℝ} {f : ℂ → E} {c z z₀ : ℂ} /-- An auxiliary lemma for `complex.norm_dslope_le_div_of_maps_to_ball`. -/ lemma schwarz_aux {f : ℂ → ℂ} (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ∥dslope f c z∥ ≤ R₂ / R₁ := begin have hR₁ : 0 < R₁, from nonempty_ball.1 ⟨z, hz⟩, suffices : ∀ᶠ r in 𝓝[<] R₁, ∥dslope f c z∥ ≤ R₂ / r, { refine ge_of_tendsto _ this, exact (tendsto_const_nhds.div tendsto_id hR₁.ne').mono_left nhds_within_le_nhds }, rw mem_ball at hz, filter_upwards [Ioo_mem_nhds_within_Iio ⟨hz, le_rfl⟩] with r hr, have hr₀ : 0 < r, from dist_nonneg.trans_lt hr.1, replace hd : diff_cont_on_cl ℂ (dslope f c) (ball c r), { refine differentiable_on.diff_cont_on_cl _, rw closure_ball c hr₀.ne', exact ((differentiable_on_dslope $ ball_mem_nhds _ hR₁).mpr hd).mono (closed_ball_subset_ball hr.2) }, refine norm_le_of_forall_mem_frontier_norm_le bounded_ball hd _ _, { rw frontier_ball c hr₀.ne', intros z hz, have hz' : z ≠ c, from ne_of_mem_sphere hz hr₀.ne', rw [dslope_of_ne _ hz', slope_def_module, norm_smul, norm_inv, (mem_sphere_iff_norm _ _ _).1 hz, ← div_eq_inv_mul, div_le_div_right hr₀, ← dist_eq_norm], exact le_of_lt (h_maps (mem_ball.2 (by { rw mem_sphere.1 hz, exact hr.2 }))) }, { rw [closure_ball c hr₀.ne', mem_closed_ball], exact hr.1.le } end /-- Two cases of the **Schwarz Lemma** (derivative and distance), merged together. -/ lemma norm_dslope_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : ∥dslope f c z∥ ≤ R₂ / R₁ := begin have hR₁ : 0 < R₁, from nonempty_ball.1 ⟨z, hz⟩, have hR₂ : 0 < R₂, from nonempty_ball.1 ⟨f z, h_maps hz⟩, cases eq_or_ne (dslope f c z) 0 with hc hc, { rw [hc, norm_zero], exact div_nonneg hR₂.le hR₁.le }, rcases exists_dual_vector ℂ _ hc with ⟨g, hg, hgf⟩, have hg' : ∥g∥₊ = 1, from nnreal.eq hg, have hg₀ : ∥g∥₊ ≠ 0, by simpa only [hg'] using one_ne_zero, calc ∥dslope f c z∥ = ∥dslope (g ∘ f) c z∥ : begin rw [g.dslope_comp, hgf, is_R_or_C.norm_of_real, norm_norm], exact λ _, hd.differentiable_at (ball_mem_nhds _ hR₁) end ... ≤ R₂ / R₁ : begin refine schwarz_aux (g.differentiable.comp_differentiable_on hd) (maps_to.comp _ h_maps) hz, simpa only [hg', nnreal.coe_one, one_mul] using g.lipschitz.maps_to_ball hg₀ (f c) R₂ end end /-- Equality case in the **Schwarz Lemma**: in the setup of `norm_dslope_le_div_of_maps_to_ball`, if `∥dslope f c z₀∥ = R₂ / R₁` holds at a point in the ball then the map `f` is affine. -/ lemma affine_of_maps_to_ball_of_exists_norm_dslope_eq_div [complete_space E] [strict_convex_space ℝ E] (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : set.maps_to f (ball c R₁) (ball (f c) R₂)) (h_z₀ : z₀ ∈ ball c R₁) (h_eq : ∥dslope f c z₀∥ = R₂ / R₁) : set.eq_on f (λ z, f c + (z - c) • dslope f c z₀) (ball c R₁) := begin set g := dslope f c, rintro z hz, by_cases z = c, { simp [h] }, have h_R₁ : 0 < R₁ := nonempty_ball.mp ⟨_, h_z₀⟩, have g_le_div : ∀ z ∈ ball c R₁, ∥g z∥ ≤ R₂ / R₁, from λ z hz, norm_dslope_le_div_of_maps_to_ball hd h_maps hz, have g_max : is_max_on (norm ∘ g) (ball c R₁) z₀, from is_max_on_iff.mpr (λ z hz, by simpa [h_eq] using g_le_div z hz), have g_diff : differentiable_on ℂ g (ball c R₁), from (differentiable_on_dslope (is_open_ball.mem_nhds (mem_ball_self h_R₁))).mpr hd, have : g z = g z₀ := eq_on_of_is_preconnected_of_is_max_on_norm (convex_ball c R₁).is_preconnected is_open_ball g_diff h_z₀ g_max hz, simp [← this] end lemma affine_of_maps_to_ball_of_exists_norm_dslope_eq_div' [complete_space E] [strict_convex_space ℝ E] (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : set.maps_to f (ball c R₁) (ball (f c) R₂)) (h_z₀ : ∃ z₀ ∈ ball c R₁, ∥dslope f c z₀∥ = R₂ / R₁) : ∃ C : E, ∥C∥ = R₂ / R₁ ∧ set.eq_on f (λ z, f c + (z - c) • C) (ball c R₁) := let ⟨z₀, h_z₀, h_eq⟩ := h_z₀ in ⟨dslope f c z₀, h_eq, affine_of_maps_to_ball_of_exists_norm_dslope_eq_div hd h_maps h_z₀ h_eq⟩ /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and a positive radius `R₁` to an open ball with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ lemma norm_deriv_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : ∥deriv f c∥ ≤ R₂ / R₁ := by simpa only [dslope_same] using norm_dslope_le_div_of_maps_to_ball hd h_maps (mem_ball_self h₀) /-- The **Schwarz Lemma**: if `f : ℂ → E` sends an open disk with center `c` and radius `R₁` to an open ball with center `f c` and radius `R₂`, then for any `z` in the former disk we have `dist (f z) (f c) ≤ (R₂ / R₁) * dist z c`. -/ lemma dist_le_div_mul_dist_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (hz : z ∈ ball c R₁) : dist (f z) (f c) ≤ (R₂ / R₁) * dist z c := begin rcases eq_or_ne z c with rfl|hne, { simp only [dist_self, mul_zero] }, simpa only [dslope_of_ne _ hne, slope_def_module, norm_smul, norm_inv, ← div_eq_inv_mul, ← dist_eq_norm, div_le_iff (dist_pos.2 hne)] using norm_dslope_le_div_of_maps_to_ball hd h_maps hz end end space variables {f : ℂ → ℂ} {c z : ℂ} {R R₁ R₂ : ℝ} /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `c` and a positive radius `R₁` to an open disk with center `f c` and radius `R₂`, then the absolute value of the derivative of `f` at `c` is at most the ratio `R₂ / R₁`. -/ lemma abs_deriv_le_div_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R₁)) (h_maps : maps_to f (ball c R₁) (ball (f c) R₂)) (h₀ : 0 < R₁) : abs (deriv f c) ≤ R₂ / R₁ := norm_deriv_le_div_of_maps_to_ball hd h_maps h₀ /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk of positive radius to itself and the center of this disk to itself, then the absolute value of the derivative of `f` at the center of this disk is at most `1`. -/ lemma abs_deriv_le_one_of_maps_to_ball (hd : differentiable_on ℂ f (ball c R)) (h_maps : maps_to f (ball c R) (ball c R)) (hc : f c = c) (h₀ : 0 < R) : abs (deriv f c) ≤ 1 := (norm_deriv_le_div_of_maps_to_ball hd (by rwa hc) h₀).trans_eq (div_self h₀.ne') /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk to itself and the center `c` of this disk to itself, then for any point `z` of this disk we have `dist (f z) c ≤ dist z c`. -/ lemma dist_le_dist_of_maps_to_ball_self (hd : differentiable_on ℂ f (ball c R)) (h_maps : maps_to f (ball c R) (ball c R)) (hc : f c = c) (hz : z ∈ ball c R) : dist (f z) c ≤ dist z c := have hR : 0 < R, from nonempty_ball.1 ⟨z, hz⟩, by simpa only [hc, div_self hR.ne', one_mul] using dist_le_div_mul_dist_of_maps_to_ball hd (by rwa hc) hz /-- The **Schwarz Lemma**: if `f : ℂ → ℂ` sends an open disk with center `0` to itself, the for any point `z` of this disk we have `abs (f z) ≤ abs z`. -/ lemma abs_le_abs_of_maps_to_ball_self (hd : differentiable_on ℂ f (ball 0 R)) (h_maps : maps_to f (ball 0 R) (ball 0 R)) (h₀ : f 0 = 0) (hz : abs z < R) : abs (f z) ≤ abs z := begin replace hz : z ∈ ball (0 : ℂ) R, from mem_ball_zero_iff.2 hz, simpa only [dist_zero_right] using dist_le_dist_of_maps_to_ball_self hd h_maps h₀ hz end end complex
b17994dd5726c9f63f909a4b606a953f17873b0a
bb31430994044506fa42fd667e2d556327e18dfe
/src/data/finset/sort.lean
c293a1d344bf9afcea7fb8e23127cfbd9fedfa33
[ "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
9,503
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import order.rel_iso.set import data.fintype.lattice import data.multiset.sort import data.list.nodup_equiv_fin /-! # Construct a sorted list from a finset. -/ namespace finset open multiset nat variables {α β : Type*} /-! ### sort -/ section sort variables (r : α → α → Prop) [decidable_rel r] [is_trans α r] [is_antisymm α r] [is_total α r] /-- `sort s` constructs a sorted list from the unordered set `s`. (Uses merge sort algorithm.) -/ def sort (s : finset α) : list α := sort r s.1 @[simp] theorem sort_sorted (s : finset α) : list.sorted r (sort r s) := sort_sorted _ _ @[simp] theorem sort_eq (s : finset α) : ↑(sort r s) = s.1 := sort_eq _ _ @[simp] theorem sort_nodup (s : finset α) : (sort r s).nodup := (by rw sort_eq; exact s.2 : @multiset.nodup α (sort r s)) @[simp] theorem sort_to_finset [decidable_eq α] (s : finset α) : (sort r s).to_finset = s := list.to_finset_eq (sort_nodup r s) ▸ eq_of_veq (sort_eq r s) @[simp] theorem mem_sort {s : finset α} {a : α} : a ∈ sort r s ↔ a ∈ s := multiset.mem_sort _ @[simp] theorem length_sort {s : finset α} : (sort r s).length = s.card := multiset.length_sort _ @[simp] theorem sort_empty : sort r ∅ = [] := multiset.sort_zero r @[simp] theorem sort_singleton (a : α) : sort r {a} = [a] := multiset.sort_singleton r a lemma sort_perm_to_list (s : finset α) : sort r s ~ s.to_list := by { rw ←multiset.coe_eq_coe, simp only [coe_to_list, sort_eq] } end sort section sort_linear_order variables [linear_order α] theorem sort_sorted_lt (s : finset α) : list.sorted (<) (sort (≤) s) := (sort_sorted _ _).imp₂ (@lt_of_le_of_ne _ _) (sort_nodup _ _) lemma sorted_zero_eq_min'_aux (s : finset α) (h : 0 < (s.sort (≤)).length) (H : s.nonempty) : (s.sort (≤)).nth_le 0 h = s.min' H := begin let l := s.sort (≤), apply le_antisymm, { have : s.min' H ∈ l := (finset.mem_sort (≤)).mpr (s.min'_mem H), obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.min' H := list.mem_iff_nth_le.1 this, rw ← hi, exact (s.sort_sorted (≤)).rel_nth_le_of_le _ _ (nat.zero_le i) }, { have : l.nth_le 0 h ∈ s := (finset.mem_sort (≤)).1 (list.nth_le_mem l 0 h), exact s.min'_le _ this } end lemma sorted_zero_eq_min' {s : finset α} {h : 0 < (s.sort (≤)).length} : (s.sort (≤)).nth_le 0 h = s.min' (card_pos.1 $ by rwa length_sort at h) := sorted_zero_eq_min'_aux _ _ _ lemma min'_eq_sorted_zero {s : finset α} {h : s.nonempty} : s.min' h = (s.sort (≤)).nth_le 0 (by { rw length_sort, exact card_pos.2 h }) := (sorted_zero_eq_min'_aux _ _ _).symm lemma sorted_last_eq_max'_aux (s : finset α) (h : (s.sort (≤)).length - 1 < (s.sort (≤)).length) (H : s.nonempty) : (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) h = s.max' H := begin let l := s.sort (≤), apply le_antisymm, { have : l.nth_le ((s.sort (≤)).length - 1) h ∈ s := (finset.mem_sort (≤)).1 (list.nth_le_mem l _ h), exact s.le_max' _ this }, { have : s.max' H ∈ l := (finset.mem_sort (≤)).mpr (s.max'_mem H), obtain ⟨i, i_lt, hi⟩ : ∃ i (hi : i < l.length), l.nth_le i hi = s.max' H := list.mem_iff_nth_le.1 this, rw ← hi, have : i ≤ l.length - 1 := nat.le_pred_of_lt i_lt, exact (s.sort_sorted (≤)).rel_nth_le_of_le _ _ (nat.le_pred_of_lt i_lt) }, end lemma sorted_last_eq_max' {s : finset α} {h : (s.sort (≤)).length - 1 < (s.sort (≤)).length} : (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) h = s.max' (by { rw length_sort at h, exact card_pos.1 (lt_of_le_of_lt bot_le h) }) := sorted_last_eq_max'_aux _ _ _ lemma max'_eq_sorted_last {s : finset α} {h : s.nonempty} : s.max' h = (s.sort (≤)).nth_le ((s.sort (≤)).length - 1) (by simpa using nat.sub_lt (card_pos.mpr h) zero_lt_one) := (sorted_last_eq_max'_aux _ _ _).symm /-- Given a finset `s` of cardinality `k` in a linear order `α`, the map `order_iso_of_fin s h` is the increasing bijection between `fin k` and `s` as an `order_iso`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of an iso `fin s.card ≃o s` to avoid casting issues in further uses of this function. -/ def order_iso_of_fin (s : finset α) {k : ℕ} (h : s.card = k) : fin k ≃o s := order_iso.trans (fin.cast ((length_sort (≤)).trans h).symm) $ (s.sort_sorted_lt.nth_le_iso _).trans $ order_iso.set_congr _ _ $ set.ext $ λ x, mem_sort _ /-- Given a finset `s` of cardinality `k` in a linear order `α`, the map `order_emb_of_fin s h` is the increasing bijection between `fin k` and `s` as an order embedding into `α`. Here, `h` is a proof that the cardinality of `s` is `k`. We use this instead of an embedding `fin s.card ↪o α` to avoid casting issues in further uses of this function. -/ def order_emb_of_fin (s : finset α) {k : ℕ} (h : s.card = k) : fin k ↪o α := (order_iso_of_fin s h).to_order_embedding.trans (order_embedding.subtype _) @[simp] lemma coe_order_iso_of_fin_apply (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : ↑(order_iso_of_fin s h i) = order_emb_of_fin s h i := rfl lemma order_iso_of_fin_symm_apply (s : finset α) {k : ℕ} (h : s.card = k) (x : s) : ↑((s.order_iso_of_fin h).symm x) = (s.sort (≤)).index_of x := rfl lemma order_emb_of_fin_apply (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : s.order_emb_of_fin h i = (s.sort (≤)).nth_le i (by { rw [length_sort, h], exact i.2 }) := rfl @[simp] lemma order_emb_of_fin_mem (s : finset α) {k : ℕ} (h : s.card = k) (i : fin k) : s.order_emb_of_fin h i ∈ s := (s.order_iso_of_fin h i).2 @[simp] lemma range_order_emb_of_fin (s : finset α) {k : ℕ} (h : s.card = k) : set.range (s.order_emb_of_fin h) = s := by simp only [order_emb_of_fin, set.range_comp coe (s.order_iso_of_fin h), rel_embedding.coe_trans, set.image_univ, finset.order_emb_of_fin.equations._eqn_1, rel_iso.range_eq, order_embedding.subtype_apply, order_iso.coe_to_order_embedding, eq_self_iff_true, subtype.range_coe_subtype, finset.set_of_mem, finset.coe_inj] /-- The bijection `order_emb_of_fin s h` sends `0` to the minimum of `s`. -/ lemma order_emb_of_fin_zero {s : finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : order_emb_of_fin s h ⟨0, hz⟩ = s.min' (card_pos.mp (h.symm ▸ hz)) := by simp only [order_emb_of_fin_apply, fin.coe_mk, sorted_zero_eq_min'] /-- The bijection `order_emb_of_fin s h` sends `k-1` to the maximum of `s`. -/ lemma order_emb_of_fin_last {s : finset α} {k : ℕ} (h : s.card = k) (hz : 0 < k) : order_emb_of_fin s h ⟨k-1, buffer.lt_aux_2 hz⟩ = s.max' (card_pos.mp (h.symm ▸ hz)) := by simp [order_emb_of_fin_apply, max'_eq_sorted_last, h] /-- `order_emb_of_fin {a} h` sends any argument to `a`. -/ @[simp] lemma order_emb_of_fin_singleton (a : α) (i : fin 1) : order_emb_of_fin {a} (card_singleton a) i = a := by rw [subsingleton.elim i ⟨0, zero_lt_one⟩, order_emb_of_fin_zero _ zero_lt_one, min'_singleton] /-- Any increasing map `f` from `fin k` to a finset of cardinality `k` has to coincide with the increasing bijection `order_emb_of_fin s h`. -/ lemma order_emb_of_fin_unique {s : finset α} {k : ℕ} (h : s.card = k) {f : fin k → α} (hfs : ∀ x, f x ∈ s) (hmono : strict_mono f) : f = s.order_emb_of_fin h := begin apply fin.strict_mono_unique hmono (s.order_emb_of_fin h).strict_mono, rw [range_order_emb_of_fin, ← set.image_univ, ← coe_univ, ← coe_image, coe_inj], refine eq_of_subset_of_card_le (λ x hx, _) _, { rcases mem_image.1 hx with ⟨x, hx, rfl⟩, exact hfs x }, { rw [h, card_image_of_injective _ hmono.injective, card_univ, fintype.card_fin] } end /-- An order embedding `f` from `fin k` to a finset of cardinality `k` has to coincide with the increasing bijection `order_emb_of_fin s h`. -/ lemma order_emb_of_fin_unique' {s : finset α} {k : ℕ} (h : s.card = k) {f : fin k ↪o α} (hfs : ∀ x, f x ∈ s) : f = s.order_emb_of_fin h := rel_embedding.ext $ function.funext_iff.1 $ order_emb_of_fin_unique h hfs f.strict_mono /-- Two parametrizations `order_emb_of_fin` of the same set take the same value on `i` and `j` if and only if `i = j`. Since they can be defined on a priori not defeq types `fin k` and `fin l` (although necessarily `k = l`), the conclusion is rather written `(i : ℕ) = (j : ℕ)`. -/ @[simp] lemma order_emb_of_fin_eq_order_emb_of_fin_iff {k l : ℕ} {s : finset α} {i : fin k} {j : fin l} {h : s.card = k} {h' : s.card = l} : s.order_emb_of_fin h i = s.order_emb_of_fin h' j ↔ (i : ℕ) = (j : ℕ) := begin substs k l, exact (s.order_emb_of_fin rfl).eq_iff_eq.trans fin.ext_iff end /-- Given a finset `s` of size at least `k` in a linear order `α`, the map `order_emb_of_card_le` is an order embedding from `fin k` to `α` whose image is contained in `s`. Specifically, it maps `fin k` to an initial segment of `s`. -/ def order_emb_of_card_le (s : finset α) {k : ℕ} (h : k ≤ s.card) : fin k ↪o α := (fin.cast_le h).trans (s.order_emb_of_fin rfl) lemma order_emb_of_card_le_mem (s : finset α) {k : ℕ} (h : k ≤ s.card) (a) : order_emb_of_card_le s h a ∈ s := by simp only [order_emb_of_card_le, rel_embedding.coe_trans, finset.order_emb_of_fin_mem] end sort_linear_order meta instance [has_repr α] : has_repr (finset α) := ⟨λ s, repr s.1⟩ end finset
ce02e322adbe0ff66c1ecc4447b6b487610411ba
367134ba5a65885e863bdc4507601606690974c1
/test/equiv_rw.lean
4337508083e99fef34353ba1879a715843d05672
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
9,422
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 tactic.equiv_rw import control.equiv_functor.instances -- these make equiv_rw more powerful! -- Uncomment this line to observe the steps of constructing appropriate equivalences. -- set_option trace.equiv_rw_type true import tactic.equiv_rw -- This fails if we use `occurs` rather than `kdepends_on` in `equiv_rw_type`. instance : equiv_functor set := { map := λ α β e s, by { equiv_rw e.symm, assumption, } } -- Rewriting a hypothesis along an equivalence. example {α β : Type} (e : α ≃ β) (f : α → ℕ) (h : ∀ b : β, f (e.symm b) = 0) (i : α) : f i = 0 := begin equiv_rw e at i, apply h, end -- Check that dependent hypotheses are reverted and reintroduced. example {α β : Type} (e : α ≃ β) (Z : α → Type) (f : Π a, Z a → ℕ) (h : ∀ (b : β) (x : Z (e.symm b)), f (e.symm b) x = 0) (i : α) (x : Z i) : f i x = 0 := begin equiv_rw e at i, guard_hyp i : β, guard_target f (e.symm i) x = 0, guard_hyp x : Z ((e.symm) i), exact h i x, end -- Rewriting the goal along an equivalence. example {α β : Type} (e : α ≃ β) (b : β) : α := begin equiv_rw e, exact b, end -- Fail if the equivalence can't be used. example {α β γ : Type} (e : β ≃ γ) (a : α) : α := begin success_if_fail { equiv_rw e at a }, success_if_fail { equiv_rw e }, exact a, end -- Verify that `equiv_rw` will rewrite under `equiv_functor` instances. example {α β : Type} (u : unique α) (e : α ≃ β) : β := begin equiv_rw e at u, apply inhabited.default, end example {α β : Type} (p : equiv.perm α) (e : α ≃ β) : equiv.perm β := begin equiv_rw e at p, exact p, end -- We can rewrite the goal under functors. example {α β : Type} (e : α ≃ β) (b : β) : option α := begin equiv_rw e, exact some b, end -- We can rewrite hypotheses under functors. example {α β : Type} (e : α ≃ β) (b : option α) : option β := begin equiv_rw e at b, exact b, end -- We can rewrite hypotheses under compositions of functors. example {α β : Type} (e : α ≃ β) (b : list (list α)) : list β := begin equiv_rw e at b, exact b.join, end -- Check that we can rewrite in the target position of function types. example {α β γ : Type} (e : α ≃ β) (f : γ → β) : γ → α := begin equiv_rw e, exact f, end -- Check that we can rewrite in the source position of function types. example {α β γ : Type} (e : α ≃ β) (f : β → γ) : α → γ := begin equiv_rw e, exact f, end -- Rewriting under multiple functors. example {α β : Type} (e : α ≃ β) (b : β) : list (option α) := begin equiv_rw e, exact [none, some b], end -- Rewriting under multiple functors, including functions. example {α β γ : Type} (e : α ≃ β) (b : β) : γ → list (option α) := begin equiv_rw e, exact (λ g, [none, some b]), end -- Rewriting in multiple positions. example {α β : Type*} [has_add β] (e : α ≃ β) : α → α := begin have : (α → α) ≃ _, { apply equiv.arrow_congr, apply e, apply e, }, equiv_rw e, exact (@id β), end -- Rewriting in multiple positions. example {α β : Type} [has_add β] (e : α ≃ β) : β → α → α := begin equiv_rw e, exact (+), end -- Rewriting in multiple positions. example {α β : Type} [has_add β] (e : α ≃ β) : α → α → α := begin equiv_rw e, exact (+), end example {α β γ : Type} (e : α ≃ β) (s : β ⊕ γ) : α ⊕ γ := begin equiv_rw e, exact s, end example {α β γ : Type} (e : α ≃ β) (s : β ⊕ γ) : (α ⊕ γ) × (γ ⊕ α) := begin equiv_rw e, exact (s, s.swap), end example {α β γ : Type} (e : α ≃ β) (s : α ⊕ γ) : (β ⊕ γ) × (γ ⊕ β) := begin equiv_rw e at s, exact (s, s.swap), end example {α β γ : Type} (e : α ≃ β) (s : (α ⊕ γ) × β) : (β ⊕ γ) := begin success_if_fail { equiv_rw e at s {max_depth := 4} }, equiv_rw e at s, exact s.1, end -- Test generating the actual equivalence using `equiv_rw_type`. example {α β : Type} (e : α ≃ β) (b : β) : α × (ℕ ⊕ ℕ) := begin have e' : α × (ℕ ⊕ ℕ) ≃ _ := by equiv_rw_type e, apply e'.inv_fun, exact (b, sum.inl 0) end example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : { a // P a }) : β := begin equiv_rw e at h, exact h.val, end example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : ∀ a, P a) (b : β) : { a // P a } := begin equiv_rw e, use b, apply h, end example {α β : Type} (e : α ≃ β) (P : α → Prop) (h : ∀ a : α, P a) (b : β) : P (e.symm b) := begin equiv_rw e.symm at b, exact h b, end example {α β : Type} (e : α ≃ β) (P : α → Sort*) (h : Π a : α, P a) (b : β) : P (e.symm b) := begin -- this is a bit perverse, as `equiv_rw e.symm at b` is more natural, -- but this tests rewriting in the argument of a dependent function equiv_rw e at h, exact h _, end -- a poor example, rewriting in the base of a dependent pair example {α β : Type} (P : α → Type) (h : Σ a, P a) (e : α ≃ β) : β := begin equiv_rw e at h, exact h.1 end -- rewriting in the argument of a dependent function can't be done in one step example {α β γ : Type} (e : α ≃ β) (P : α → Type*) (h : Π a : α, (P a) × (option α)) (b : β) : option β := begin equiv_rw e at h, have t := h b, equiv_rw e at t, exact t.2, end -- Demonstrate using `equiv_rw` to build new instances of `equiv_functor` -- Observe that the next three declarations could easily be implemented by a tactic. -- This has been automated in the `transport` branch, -- so we won't attempt to write a deriver handler until we join with that. def semigroup.map {α β : Type} (e : α ≃ β) : semigroup α → semigroup β := begin intro S, refine_struct { .. }, -- transport data fields using `equiv_rw` { have mul := S.mul, equiv_rw e at mul, -- This `equiv_rw` performs the following steps: -- have e' := (equiv.arrow_congr' e (equiv.arrow_congr' e e)), -- have h := (e'.symm_apply_apply mul).symm, -- revert h, -- generalize : (e' mul) = mul', -- intro h, -- clear_dependent mul, -- rename mul' mul, exact mul, }, -- transport axioms by simplifying, and applying the original axiom { intros, dsimp, simp, apply S.mul_assoc, } end example {α β : Type} (e : α ≃ β) (S : semigroup α) : (semigroup.map e S).mul = (equiv.arrow_congr' e (equiv.arrow_congr' e e)) has_mul.mul := rfl example {α β : Type} (e : α ≃ β) (S : semigroup α) (x y : β) : begin haveI := semigroup.map e S, exact x * y = e (e.symm x * e.symm y) end := rfl attribute [ext] semigroup lemma semigroup.id_map (α : Type) : semigroup.map (equiv.refl α) = id := by { ext, refl, } lemma semigroup.map_map {α β γ : Type} (e : α ≃ β) (f : β ≃ γ) : semigroup.map (e.trans f) = (semigroup.map f) ∘ (semigroup.map e) := by { ext, dsimp [semigroup.map], simp, } -- TODO (after joining the `transport` branch) create a derive handler for this instance : equiv_functor semigroup := { map := λ α β e, semigroup.map e, map_refl' := semigroup.id_map, map_trans' := λ α β γ e f, semigroup.map_map e f, } -- Verify that we can now use `equiv_rw` under `semigroup`: example {α : Type} [I : semigroup α] {β : Type} (e : α ≃ β) : semigroup β := begin equiv_rw e at I, exact I, end -- Now we do `monoid`, to try out a structure with constants. -- The constructions and proofs here are written as uniformly as possible. -- This example is the blueprint for the `transport` tactic. mk_simp_attribute transport_simps "simps useful inside `transport`" attribute [transport_simps] eq_rec_constant eq_mpr_rfl equiv.to_fun_as_coe equiv.arrow_congr'_apply equiv.symm_apply_apply equiv.apply_eq_iff_eq_symm_apply def monoid.map {α β : Type} (e : α ≃ β) (S : monoid α) : monoid β := begin refine_struct { .. }, { have mul := S.mul, equiv_rw e at mul, exact mul, }, { try { unfold_projs }, simp only with transport_simps, have mul_assoc := S.mul_assoc, equiv_rw e at mul_assoc, solve_by_elim, }, { have one := S.one, equiv_rw e at one, exact one, }, { try { unfold_projs }, simp only with transport_simps, have one_mul := S.one_mul, equiv_rw e at one_mul, solve_by_elim, }, { try { unfold_projs }, simp only with transport_simps, have mul_one := S.mul_one, equiv_rw e at mul_one, solve_by_elim, }, end example {α β : Type} (e : α ≃ β) (S : monoid α) : (monoid.map e S).mul = (equiv.arrow_congr' e (equiv.arrow_congr' e e)) has_mul.mul := rfl example {α β : Type} (e : α ≃ β) (S : monoid α) (x y : β) : begin haveI := monoid.map e S, exact x * y = e (e.symm x * e.symm y) end := rfl example {α β : Type} (e : α ≃ β) (S : monoid α) : begin haveI := monoid.map e S, exact (1 : β) = e (1 : α) end := rfl example {α : Type} {β : Type} (m : α → α → α) (e : α ≃ β) : β → β → β := begin equiv_rw e at m, exact m, end -- This used to fail because metavariables were getting stuck! example {α : Type} {β : Type 2} (m : α → α → α) (e : α ≃ β) : β → β → β := begin equiv_rw e at m, exact m, end
5ed68b6db11668722d3ee878d119fc2107fddc53
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/finset/locally_finite.lean
beac80359c465f5ea00ee13cf4a39c72b3bf2e40
[ "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
25,508
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Yaël Dillies -/ import order.locally_finite /-! # Intervals as finsets This file provides basic results about all the `finset.Ixx`, which are defined in `order.locally_finite`. ## TODO This file was originally only about `finset.Ico a b` where `a b : ℕ`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `data.x.intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ open_locale big_operators variables {ι α : Type*} namespace finset section preorder variables [preorder α] section locally_finite_order variables [locally_finite_order α] {a a₁ a₂ b b₁ b₂ c x : α} @[simp] lemma nonempty_Icc : (Icc a b).nonempty ↔ a ≤ b := by rw [←coe_nonempty, coe_Icc, set.nonempty_Icc] @[simp] lemma nonempty_Ico : (Ico a b).nonempty ↔ a < b := by rw [←coe_nonempty, coe_Ico, set.nonempty_Ico] @[simp] lemma nonempty_Ioc : (Ioc a b).nonempty ↔ a < b := by rw [←coe_nonempty, coe_Ioc, set.nonempty_Ioc] @[simp] lemma nonempty_Ioo [densely_ordered α] : (Ioo a b).nonempty ↔ a < b := by rw [←coe_nonempty, coe_Ioo, set.nonempty_Ioo] @[simp] lemma Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [←coe_eq_empty, coe_Icc, set.Icc_eq_empty_iff] @[simp] lemma Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by rw [←coe_eq_empty, coe_Ico, set.Ico_eq_empty_iff] @[simp] lemma Ioc_eq_empty_iff : Ioc a b = ∅ ↔ ¬a < b := by rw [←coe_eq_empty, coe_Ioc, set.Ioc_eq_empty_iff] @[simp] lemma Ioo_eq_empty_iff [densely_ordered α] : Ioo a b = ∅ ↔ ¬a < b := by rw [←coe_eq_empty, coe_Ioo, set.Ioo_eq_empty_iff] alias Icc_eq_empty_iff ↔ _ Icc_eq_empty alias Ico_eq_empty_iff ↔ _ Ico_eq_empty alias Ioc_eq_empty_iff ↔ _ Ioc_eq_empty @[simp] lemma Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 $ λ x hx, h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] lemma Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le @[simp] lemma Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt @[simp] lemma Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt @[simp] lemma Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt @[simp] lemma left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, true_and, le_rfl] @[simp] lemma left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] @[simp] lemma right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp only [mem_Icc, and_true, le_rfl] @[simp] lemma right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] @[simp] lemma left_not_mem_Ioc : a ∉ Ioc a b := λ h, lt_irrefl _ (mem_Ioc.1 h).1 @[simp] lemma left_not_mem_Ioo : a ∉ Ioo a b := λ h, lt_irrefl _ (mem_Ioo.1 h).1 @[simp] lemma right_not_mem_Ico : b ∉ Ico a b := λ h, lt_irrefl _ (mem_Ico.1 h).2 @[simp] lemma right_not_mem_Ioo : b ∉ Ioo a b := λ h, lt_irrefl _ (mem_Ioo.1 h).2 lemma Icc_subset_Icc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := by simpa [←coe_subset] using set.Icc_subset_Icc ha hb lemma Ico_subset_Ico (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := by simpa [←coe_subset] using set.Ico_subset_Ico ha hb lemma Ioc_subset_Ioc (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := by simpa [←coe_subset] using set.Ioc_subset_Ioc ha hb lemma Ioo_subset_Ioo (ha : a₂ ≤ a₁) (hb : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := by simpa [←coe_subset] using set.Ioo_subset_Ioo ha hb lemma Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl lemma Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl lemma Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl lemma Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl lemma Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h lemma Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h lemma Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h lemma Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h lemma Ico_subset_Ioo_left (h : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := by { rw [←coe_subset, coe_Ico, coe_Ioo], exact set.Ico_subset_Ioo_left h } lemma Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := by { rw [←coe_subset, coe_Ioc, coe_Ioo], exact set.Ioc_subset_Ioo_right h } lemma Icc_subset_Ico_right (h : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := by { rw [←coe_subset, coe_Icc, coe_Ico], exact set.Icc_subset_Ico_right h } lemma Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := by { rw [←coe_subset, coe_Ioo, coe_Ico], exact set.Ioo_subset_Ico_self } lemma Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := by { rw [←coe_subset, coe_Ioo, coe_Ioc], exact set.Ioo_subset_Ioc_self } lemma Ico_subset_Icc_self : Ico a b ⊆ Icc a b := by { rw [←coe_subset, coe_Ico, coe_Icc], exact set.Ico_subset_Icc_self } lemma Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := by { rw [←coe_subset, coe_Ioc, coe_Icc], exact set.Ioc_subset_Icc_self } lemma Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self lemma Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [←coe_subset, coe_Icc, coe_Icc, set.Icc_subset_Icc_iff h₁] lemma Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := by rw [←coe_subset, coe_Icc, coe_Ioo, set.Icc_subset_Ioo_iff h₁] lemma Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := by rw [←coe_subset, coe_Icc, coe_Ico, set.Icc_subset_Ico_iff h₁] lemma Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := (Icc_subset_Ico_iff h₁.dual).trans and.comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` lemma Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by { rw [←coe_ssubset, coe_Icc, coe_Icc], exact set.Icc_ssubset_Icc_left hI ha hb } lemma Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := by { rw [←coe_ssubset, coe_Icc, coe_Icc], exact set.Icc_ssubset_Icc_right hI ha hb } variables (a) @[simp] lemma Ico_self : Ico a a = ∅ := Ico_eq_empty $ lt_irrefl _ @[simp] lemma Ioc_self : Ioc a a = ∅ := Ioc_eq_empty $ lt_irrefl _ @[simp] lemma Ioo_self : Ioo a a = ∅ := Ioo_eq_empty $ lt_irrefl _ variables {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.set.fintype_of_mem_bounds {s : set α} [decidable_pred (∈ s)] (ha : a ∈ lower_bounds s) (hb : b ∈ upper_bounds s) : fintype s := set.fintype_subset (set.Icc a b) $ λ x hx, ⟨ha hx, hb hx⟩ lemma _root_.bdd_below.finite_of_bdd_above {s : set α} (h₀ : bdd_below s) (h₁ : bdd_above s) : s.finite := let ⟨a, ha⟩ := h₀, ⟨b, hb⟩ := h₁ in by { classical, exact ⟨set.fintype_of_mem_bounds ha hb⟩ } section filter lemma Ico_filter_lt_of_le_left [decidable_pred (< c)] (hca : c ≤ a) : (Ico a b).filter (< c) = ∅ := filter_false_of_mem (λ x hx, (hca.trans (mem_Ico.1 hx).1).not_lt) lemma Ico_filter_lt_of_right_le [decidable_pred (< c)] (hbc : b ≤ c) : (Ico a b).filter (< c) = Ico a b := filter_true_of_mem (λ x hx, (mem_Ico.1 hx).2.trans_le hbc) lemma Ico_filter_lt_of_le_right [decidable_pred (< c)] (hcb : c ≤ b) : (Ico a b).filter (< c) = Ico a c := begin ext x, rw [mem_filter, mem_Ico, mem_Ico, and.right_comm], exact and_iff_left_of_imp (λ h, h.2.trans_le hcb), end lemma Ico_filter_le_of_le_left {a b c : α} [decidable_pred ((≤) c)] (hca : c ≤ a) : (Ico a b).filter ((≤) c) = Ico a b := filter_true_of_mem (λ x hx, hca.trans (mem_Ico.1 hx).1) lemma Ico_filter_le_of_right_le {a b : α} [decidable_pred ((≤) b)] : (Ico a b).filter ((≤) b) = ∅ := filter_false_of_mem (λ x hx, (mem_Ico.1 hx).2.not_le) lemma Ico_filter_le_of_left_le {a b c : α} [decidable_pred ((≤) c)] (hac : a ≤ c) : (Ico a b).filter ((≤) c) = Ico c b := begin ext x, rw [mem_filter, mem_Ico, mem_Ico, and_comm, and.left_comm], exact and_iff_right_of_imp (λ h, hac.trans h.1), end lemma Icc_filter_lt_of_lt_right {a b c : α} [decidable_pred (< c)] (h : b < c) : (Icc a b).filter (< c) = Icc a b := (finset.filter_eq_self _).2 (λ x hx, lt_of_le_of_lt (mem_Icc.1 hx).2 h) lemma Ioc_filter_lt_of_lt_right {a b c : α} [decidable_pred (< c)] (h : b < c) : (Ioc a b).filter (< c) = Ioc a b := (finset.filter_eq_self _).2 (λ x hx, lt_of_le_of_lt (mem_Ioc.1 hx).2 h) lemma Iic_filter_lt_of_lt_right {α} [preorder α] [locally_finite_order_bot α] {a c : α} [decidable_pred (< c)] (h : a < c) : (Iic a).filter (< c) = Iic a := (finset.filter_eq_self _).2 (λ x hx, lt_of_le_of_lt (mem_Iic.1 hx) h) variables (a b) [fintype α] lemma filter_lt_lt_eq_Ioo [decidable_pred (λ j, a < j ∧ j < b)] : univ.filter (λ j, a < j ∧ j < b) = Ioo a b := by { ext, simp } lemma filter_lt_le_eq_Ioc [decidable_pred (λ j, a < j ∧ j ≤ b)] : univ.filter (λ j, a < j ∧ j ≤ b) = Ioc a b := by { ext, simp } lemma filter_le_lt_eq_Ico [decidable_pred (λ j, a ≤ j ∧ j < b)] : univ.filter (λ j, a ≤ j ∧ j < b) = Ico a b := by { ext, simp } lemma filter_le_le_eq_Icc [decidable_pred (λ j, a ≤ j ∧ j ≤ b)] : univ.filter (λ j, a ≤ j ∧ j ≤ b) = Icc a b := by { ext, simp } end filter section locally_finite_order_top variables [locally_finite_order_top α] lemma Icc_subset_Ici_self : Icc a b ⊆ Ici a := by simpa [←coe_subset] using set.Icc_subset_Ici_self lemma Ico_subset_Ici_self : Ico a b ⊆ Ici a := by simpa [←coe_subset] using set.Ico_subset_Ici_self lemma Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := by simpa [←coe_subset] using set.Ioc_subset_Ioi_self lemma Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := by simpa [←coe_subset] using set.Ioo_subset_Ioi_self lemma Ioc_subset_Ici_self : Ioc a b ⊆ Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self lemma Ioo_subset_Ici_self : Ioo a b ⊆ Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end locally_finite_order_top section locally_finite_order_bot variables [locally_finite_order_bot α] lemma Icc_subset_Iic_self : Icc a b ⊆ Iic b := by simpa [←coe_subset] using set.Icc_subset_Iic_self lemma Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := by simpa [←coe_subset] using set.Ioc_subset_Iic_self lemma Ico_subset_Iio_self : Ico a b ⊆ Iio b := by simpa [←coe_subset] using set.Ico_subset_Iio_self lemma Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := by simpa [←coe_subset] using set.Ioo_subset_Iio_self lemma Ico_subset_Iic_self : Ico a b ⊆ Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self lemma Ioo_subset_Iic_self : Ioo a b ⊆ Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self end locally_finite_order_bot end locally_finite_order section locally_finite_order_top variables [locally_finite_order_top α] {a : α} lemma Ioi_subset_Ici_self : Ioi a ⊆ Ici a := by simpa [←coe_subset] using set.Ioi_subset_Ici_self lemma _root_.bdd_below.finite {s : set α} (hs : bdd_below s) : s.finite := let ⟨a, ha⟩ := hs in (Ici a).finite_to_set.subset $ λ x hx, mem_Ici.2 $ ha hx variables [fintype α] lemma filter_lt_eq_Ioi [decidable_pred ((<) a)] : univ.filter ((<) a) = Ioi a := by { ext, simp } lemma filter_le_eq_Ici [decidable_pred ((≤) a)] : univ.filter ((≤) a) = Ici a := by { ext, simp } end locally_finite_order_top section locally_finite_order_bot variables [locally_finite_order_bot α] {a : α} lemma Iio_subset_Iic_self : Iio a ⊆ Iic a := by simpa [←coe_subset] using set.Iio_subset_Iic_self lemma _root_.bdd_above.finite {s : set α} (hs : bdd_above s) : s.finite := hs.dual.finite variables [fintype α] lemma filter_gt_eq_Iio [decidable_pred (< a)] : univ.filter (< a) = Iio a := by { ext, simp } lemma filter_ge_eq_Iic [decidable_pred (≤ a)] : univ.filter (≤ a) = Iic a := by { ext, simp } end locally_finite_order_bot variables [locally_finite_order_top α] [locally_finite_order_bot α] lemma disjoint_Ioi_Iio (a : α) : disjoint (Ioi a) (Iio a) := disjoint_left.2 $ λ b hab hba, (mem_Ioi.1 hab).not_lt $ mem_Iio.1 hba end preorder section partial_order variables [partial_order α] [locally_finite_order α] {a b c : α} @[simp] lemma Icc_self (a : α) : Icc a a = {a} := by rw [←coe_eq_singleton, coe_Icc, set.Icc_self] @[simp] lemma Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [←coe_eq_singleton, coe_Icc, set.Icc_eq_singleton_iff] lemma Ico_disjoint_Ico_consecutive (a b c : α) : disjoint (Ico a b) (Ico b c) := disjoint_left.2 $ λ x hab hbc, (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 section decidable_eq variables [decidable_eq α] @[simp] lemma Icc_erase_left (a b : α) : (Icc a b).erase a = Ioc a b := by simp [←coe_inj] @[simp] lemma Icc_erase_right (a b : α) : (Icc a b).erase b = Ico a b := by simp [←coe_inj] @[simp] lemma Ico_erase_left (a b : α) : (Ico a b).erase a = Ioo a b := by simp [←coe_inj] @[simp] lemma Ioc_erase_right (a b : α) : (Ioc a b).erase b = Ioo a b := by simp [←coe_inj] @[simp] lemma Icc_diff_both (a b : α) : Icc a b \ {a, b} = Ioo a b := by simp [←coe_inj] @[simp] lemma Ico_insert_right (h : a ≤ b) : insert b (Ico a b) = Icc a b := by rw [←coe_inj, coe_insert, coe_Icc, coe_Ico, set.insert_eq, set.union_comm, set.Ico_union_right h] @[simp] lemma Ioc_insert_left (h : a ≤ b) : insert a (Ioc a b) = Icc a b := by rw [←coe_inj, coe_insert, coe_Ioc, coe_Icc, set.insert_eq, set.union_comm, set.Ioc_union_left h] @[simp] lemma Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [←coe_inj, coe_insert, coe_Ioo, coe_Ico, set.insert_eq, set.union_comm, set.Ioo_union_left h] @[simp] lemma Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [←coe_inj, coe_insert, coe_Ioo, coe_Ioc, set.insert_eq, set.union_comm, set.Ioo_union_right h] @[simp] lemma Icc_diff_Ico_self (h : a ≤ b) : Icc a b \ Ico a b = {b} := by simp [←coe_inj, h] @[simp] lemma Icc_diff_Ioc_self (h : a ≤ b) : Icc a b \ Ioc a b = {a} := by simp [←coe_inj, h] @[simp] lemma Icc_diff_Ioo_self (h : a ≤ b) : Icc a b \ Ioo a b = {a, b} := by simp [←coe_inj, h] @[simp] lemma Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [←coe_inj, h] @[simp] lemma Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [←coe_inj, h] @[simp] lemma Ico_inter_Ico_consecutive (a b c : α) : Ico a b ∩ Ico b c = ∅ := (Ico_disjoint_Ico_consecutive a b c).eq_bot end decidable_eq -- Those lemmas are purposefully the other way around lemma Icc_eq_cons_Ico (h : a ≤ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by { classical, rw [cons_eq_insert, Ico_insert_right h] } lemma Icc_eq_cons_Ioc (h : a ≤ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by { classical, rw [cons_eq_insert, Ioc_insert_left h] } lemma Ico_filter_le_left {a b : α} [decidable_pred (≤ a)] (hab : a < b) : (Ico a b).filter (λ x, x ≤ a) = {a} := begin ext x, rw [mem_filter, mem_Ico, mem_singleton, and.right_comm, ←le_antisymm_iff, eq_comm], exact and_iff_left_of_imp (λ h, h.le.trans_lt hab), end lemma card_Ico_eq_card_Icc_sub_one (a b : α) : (Ico a b).card = (Icc a b).card - 1 := begin classical, by_cases h : a ≤ b, { rw [←Ico_insert_right h, card_insert_of_not_mem right_not_mem_Ico], exact (nat.add_sub_cancel _ _).symm }, { rw [Ico_eq_empty (λ h', h h'.le), Icc_eq_empty h, card_empty, zero_tsub] } end lemma card_Ioc_eq_card_Icc_sub_one (a b : α) : (Ioc a b).card = (Icc a b).card - 1 := @card_Ico_eq_card_Icc_sub_one αᵒᵈ _ _ _ _ lemma card_Ioo_eq_card_Ico_sub_one (a b : α) : (Ioo a b).card = (Ico a b).card - 1 := begin classical, by_cases h : a ≤ b, { obtain rfl | h' := h.eq_or_lt, { rw [Ioo_self, Ico_self, card_empty] }, rw [←Ioo_insert_left h', card_insert_of_not_mem left_not_mem_Ioo], exact (nat.add_sub_cancel _ _).symm }, { rw [Ioo_eq_empty (λ h', h h'.le), Ico_eq_empty (λ h', h h'.le), card_empty, zero_tsub] } end lemma card_Ioo_eq_card_Ioc_sub_one (a b : α) : (Ioo a b).card = (Ioc a b).card - 1 := @card_Ioo_eq_card_Ico_sub_one αᵒᵈ _ _ _ _ lemma card_Ioo_eq_card_Icc_sub_two (a b : α) : (Ioo a b).card = (Icc a b).card - 2 := by { rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one], refl } end partial_order section bounded_partial_order variables [partial_order α] section order_top variables [locally_finite_order_top α] @[simp] lemma Ici_erase [decidable_eq α] (a : α) : (Ici a).erase a = Ioi a := by { ext, simp_rw [finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm], } @[simp] lemma Ioi_insert [decidable_eq α] (a : α) : insert a (Ioi a) = Ici a := by { ext, simp_rw [finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] } @[simp] lemma not_mem_Ioi_self {b : α} : b ∉ Ioi b := λ h, lt_irrefl _ (mem_Ioi.1 h) -- Purposefully written the other way around lemma Ici_eq_cons_Ioi (a : α) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by { classical, rw [cons_eq_insert, Ioi_insert] } lemma card_Ioi_eq_card_Ici_sub_one (a : α) : (Ioi a).card = (Ici a).card - 1 := by rw [Ici_eq_cons_Ioi, card_cons, add_tsub_cancel_right] end order_top section order_bot variables [locally_finite_order_bot α] @[simp] lemma Iic_erase [decidable_eq α] (b : α) : (Iic b).erase b = Iio b := by { ext, simp_rw [finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] } @[simp] lemma Iio_insert [decidable_eq α] (b : α) : insert b (Iio b) = Iic b := by { ext, simp_rw [finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] } @[simp] lemma not_mem_Iio_self {b : α} : b ∉ Iio b := λ h, lt_irrefl _ (mem_Iio.1 h) -- Purposefully written the other way around lemma Iic_eq_cons_Iio (b : α) : Iic b = (Iio b).cons b not_mem_Iio_self := by { classical, rw [cons_eq_insert, Iio_insert] } lemma card_Iio_eq_card_Iic_sub_one (a : α) : (Iio a).card = (Iic a).card - 1 := by rw [Iic_eq_cons_Iio, card_cons, add_tsub_cancel_right] end order_bot end bounded_partial_order section linear_order variables [linear_order α] section locally_finite_order variables [locally_finite_order α] {a b : α} lemma Ico_subset_Ico_iff {a₁ b₁ a₂ b₂ : α} (h : a₁ < b₁) : Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := by rw [←coe_subset, coe_Ico, coe_Ico, set.Ico_subset_Ico_iff h] lemma Ico_union_Ico_eq_Ico {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : Ico a b ∪ Ico b c = Ico a c := by rw [←coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, set.Ico_union_Ico_eq_Ico hab hbc] @[simp] lemma Ioc_union_Ioc_eq_Ioc {a b c : α} (h₁ : a ≤ b) (h₂ : b ≤ c) : Ioc a b ∪ Ioc b c = Ioc a c := by rw [←coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, set.Ioc_union_Ioc_eq_Ioc h₁ h₂] lemma Ico_subset_Ico_union_Ico {a b c : α} : Ico a c ⊆ Ico a b ∪ Ico b c := by { rw [←coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico], exact set.Ico_subset_Ico_union_Ico } lemma Ico_union_Ico' {a b c d : α} (hcb : c ≤ b) (had : a ≤ d) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [←coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, set.Ico_union_Ico' hcb had] lemma Ico_union_Ico {a b c d : α} (h₁ : min a b ≤ max c d) (h₂ : min c d ≤ max a b) : Ico a b ∪ Ico c d = Ico (min a c) (max b d) := by rw [←coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, set.Ico_union_Ico h₁ h₂] lemma Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by rw [←coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, ←inf_eq_min, ←sup_eq_max, set.Ico_inter_Ico] @[simp] lemma Ico_filter_lt (a b c : α) : (Ico a b).filter (λ x, x < c) = Ico a (min b c) := begin cases le_total b c, { rw [Ico_filter_lt_of_right_le h, min_eq_left h] }, { rw [Ico_filter_lt_of_le_right h, min_eq_right h] } end @[simp] lemma Ico_filter_le (a b c : α) : (Ico a b).filter (λ x, c ≤ x) = Ico (max a c) b := begin cases le_total a c, { rw [Ico_filter_le_of_left_le h, max_eq_right h] }, { rw [Ico_filter_le_of_le_left h, max_eq_left h] } end @[simp] lemma Ioo_filter_lt (a b c : α) : (Ioo a b).filter (< c) = Ioo a (min b c) := by { ext, simp [and_assoc] } @[simp] lemma Iio_filter_lt {α} [linear_order α] [locally_finite_order_bot α] (a b : α) : (Iio a).filter (< b) = Iio (min a b) := by { ext, simp [and_assoc] } @[simp] lemma Ico_diff_Ico_left (a b c : α) : (Ico a b) \ (Ico a c) = Ico (max a c) b := begin cases le_total a c, { ext x, rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, max_eq_right h, and.right_comm, not_and, not_lt], exact and_congr_left' ⟨λ hx, hx.2 hx.1, λ hx, ⟨h.trans hx, λ _, hx⟩⟩ }, { rw [Ico_eq_empty_of_le h, sdiff_empty, max_eq_left h] } end @[simp] lemma Ico_diff_Ico_right (a b c : α) : (Ico a b) \ (Ico c b) = Ico a (min b c) := begin cases le_total b c, { rw [Ico_eq_empty_of_le h, sdiff_empty, min_eq_left h] }, { ext x, rw [mem_sdiff, mem_Ico, mem_Ico, mem_Ico, min_eq_right h, and_assoc, not_and', not_le], exact and_congr_right' ⟨λ hx, hx.2 hx.1, λ hx, ⟨hx.trans_le h, λ _, hx⟩⟩ } end end locally_finite_order variables [fintype α] [locally_finite_order_top α] [locally_finite_order_bot α] lemma Ioi_disj_union_Iio (a : α) : (Ioi a).disj_union (Iio a) (disjoint_Ioi_Iio a) = ({a} : finset α)ᶜ := by { ext, simp [eq_comm] } end linear_order section ordered_cancel_add_comm_monoid variables [ordered_cancel_add_comm_monoid α] [has_exists_add_of_le α] [decidable_eq α] [locally_finite_order α] lemma image_add_left_Icc (a b c : α) : (Icc a b).image ((+) c) = Icc (c + a) (c + b) := begin ext x, rw [mem_image, mem_Icc], split, { rintro ⟨y, hy, rfl⟩, rw mem_Icc at hy, exact ⟨add_le_add_left hy.1 c, add_le_add_left hy.2 c⟩ }, { intro hx, obtain ⟨y, hy⟩ := exists_add_of_le hx.1, rw add_assoc at hy, rw hy at hx, exact ⟨a + y, mem_Icc.2 ⟨le_of_add_le_add_left hx.1, le_of_add_le_add_left hx.2⟩, hy.symm⟩ } end lemma image_add_left_Ico (a b c : α) : (Ico a b).image ((+) c) = Ico (c + a) (c + b) := begin ext x, rw [mem_image, mem_Ico], split, { rintro ⟨y, hy, rfl⟩, rw mem_Ico at hy, exact ⟨add_le_add_left hy.1 c, add_lt_add_left hy.2 c⟩ }, { intro hx, obtain ⟨y, hy⟩ := exists_add_of_le hx.1, rw add_assoc at hy, rw hy at hx, exact ⟨a + y, mem_Ico.2 ⟨le_of_add_le_add_left hx.1, lt_of_add_lt_add_left hx.2⟩, hy.symm⟩ } end lemma image_add_left_Ioc (a b c : α) : (Ioc a b).image ((+) c) = Ioc (c + a) (c + b) := begin ext x, rw [mem_image, mem_Ioc], refine ⟨_, λ hx, _⟩, { rintro ⟨y, hy, rfl⟩, rw mem_Ioc at hy, exact ⟨add_lt_add_left hy.1 c, add_le_add_left hy.2 c⟩ }, { obtain ⟨y, hy⟩ := exists_add_of_le hx.1.le, rw add_assoc at hy, rw hy at hx, exact ⟨a + y, mem_Ioc.2 ⟨lt_of_add_lt_add_left hx.1, le_of_add_le_add_left hx.2⟩, hy.symm⟩ } end lemma image_add_left_Ioo (a b c : α) : (Ioo a b).image ((+) c) = Ioo (c + a) (c + b) := begin ext x, rw [mem_image, mem_Ioo], refine ⟨_, λ hx, _⟩, { rintro ⟨y, hy, rfl⟩, rw mem_Ioo at hy, exact ⟨add_lt_add_left hy.1 c, add_lt_add_left hy.2 c⟩ }, { obtain ⟨y, hy⟩ := exists_add_of_le hx.1.le, rw add_assoc at hy, rw hy at hx, exact ⟨a + y, mem_Ioo.2 ⟨lt_of_add_lt_add_left hx.1, lt_of_add_lt_add_left hx.2⟩, hy.symm⟩ } end lemma image_add_right_Icc (a b c : α) : (Icc a b).image (+ c) = Icc (a + c) (b + c) := by { simp_rw add_comm _ c, exact image_add_left_Icc a b c } lemma image_add_right_Ico (a b c : α) : (Ico a b).image (+ c) = Ico (a + c) (b + c) := by { simp_rw add_comm _ c, exact image_add_left_Ico a b c } lemma image_add_right_Ioc (a b c : α) : (Ioc a b).image (+ c) = Ioc (a + c) (b + c) := by { simp_rw add_comm _ c, exact image_add_left_Ioc a b c } lemma image_add_right_Ioo (a b c : α) : (Ioo a b).image (+ c) = Ioo (a + c) (b + c) := by { simp_rw add_comm _ c, exact image_add_left_Ioo a b c } end ordered_cancel_add_comm_monoid @[to_additive] lemma prod_prod_Ioi_mul_eq_prod_prod_off_diag [fintype ι] [linear_order ι] [locally_finite_order_top ι] [locally_finite_order_bot ι] [comm_monoid α] (f : ι → ι → α) : ∏ i, ∏ j in Ioi i, f j i * f i j = ∏ i, ∏ j in {i}ᶜ, f j i := begin simp_rw [←Ioi_disj_union_Iio, prod_disj_union, prod_mul_distrib], congr' 1, rw [prod_sigma', prod_sigma'], refine prod_bij' (λ i hi, ⟨i.2, i.1⟩) _ _ (λ i hi, ⟨i.2, i.1⟩) _ _ _; simp, end end finset
e4474d49184490f12b06d808a70a708d47267c3a
f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58
/group_theory/coset.lean
9354cca14be3be454b8f1e812d8b828803ac9087
[ "Apache-2.0" ]
permissive
semorrison/mathlib
1be6f11086e0d24180fec4b9696d3ec58b439d10
20b4143976dad48e664c4847b75a85237dca0a89
refs/heads/master
1,583,799,212,170
1,535,634,130,000
1,535,730,505,000
129,076,205
0
0
Apache-2.0
1,551,697,998,000
1,523,442,265,000
Lean
UTF-8
Lean
false
false
6,035
lean
/- Copyright (c) 2018 Mitchell Rowett. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Rowett, Scott Morrison -/ import group_theory.subgroup data.equiv.basic data.quot open set function variable {α : Type*} def left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s def right_coset [has_mul α] (s : set α) (a : α) : set α := (λ x, x * a) '' s local infix ` *l `:70 := left_coset local infix ` *r `:70 := right_coset section coset_mul variable [has_mul α] lemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s := mem_image_of_mem (λ b : α, a * b) hxS lemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a := mem_image_of_mem (λ b : α, b * a) hxS def left_coset_equiv (s : set α) (a b : α) := a *l s = b *l s lemma left_coset_equiv_rel (s : set α) : equivalence (left_coset_equiv s) := mk_equivalence (left_coset_equiv s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans) end coset_mul section coset_semigroup variable [semigroup α] @[simp] lemma left_coset_assoc (s : set α) (a b : α) : a *l (b *l s) = (a * b) *l s := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] @[simp] lemma right_coset_assoc (s : set α) (a b : α) : s *r a *r b = s *r (a * b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] lemma left_coset_right_coset (s : set α) (a b : α) : a *l s *r b = a *l (s *r b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] end coset_semigroup section coset_monoid variables [monoid α] (s : set α) @[simp] lemma one_left_coset : 1 *l s = s := set.ext $ by simp [left_coset] @[simp] lemma right_coset_one : s *r 1 = s := set.ext $ by simp [right_coset] end coset_monoid section coset_submonoid open is_submonoid variables [monoid α] (s : set α) [is_submonoid s] lemma mem_own_left_coset (a : α) : a ∈ a *l s := suffices a * 1 ∈ a *l s, by simpa, mem_left_coset a (one_mem s) lemma mem_own_right_coset (a : α) : a ∈ s *r a := suffices 1 * a ∈ s *r a, by simpa, mem_right_coset a (one_mem s) lemma mem_left_coset_left_coset {a : α} (ha : a *l s = s) : a ∈ s := by rw [←ha]; exact mem_own_left_coset s a lemma mem_right_coset_right_coset {a : α} (ha : s *r a = s) : a ∈ s := by rw [←ha]; exact mem_own_right_coset s a end coset_submonoid section coset_group variables [group α] {s : set α} {x : α} lemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨a⁻¹ * x, h, by simp⟩) lemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨x * a⁻¹, h, by simp⟩) end coset_group section coset_subgroup open is_submonoid open is_subgroup variables [group α] (s : set α) [is_subgroup s] lemma left_coset_mem_left_coset {a : α} (ha : a ∈ s) : a *l s = s := set.ext $ by simp [mem_left_coset_iff, mul_mem_cancel_right s (inv_mem ha)] lemma right_coset_mem_right_coset {a : α} (ha : a ∈ s) : s *r a = s := set.ext $ assume b, by simp [mem_right_coset_iff, mul_mem_cancel_left s (inv_mem ha)] theorem normal_of_eq_cosets [normal_subgroup s] (g : α) : g *l s = s *r g := set.ext $ assume a, by simp [mem_left_coset_iff, mem_right_coset_iff]; rw [mem_norm_comm_iff] theorem eq_cosets_of_normal (h : ∀ g, g *l s = s *r g) : normal_subgroup s := ⟨assume a ha g, show g * a * g⁻¹ ∈ s, by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩ theorem normal_iff_eq_cosets : normal_subgroup s ↔ ∀ g, g *l s = s *r g := ⟨@normal_of_eq_cosets _ _ s _, eq_cosets_of_normal s⟩ end coset_subgroup namespace quotient_group def left_rel [group α] (s : set α) [is_subgroup s] : setoid α := ⟨λ x y, x⁻¹ * y ∈ s, assume x, by simp [is_submonoid.one_mem], assume x y hxy, have (x⁻¹ * y)⁻¹ ∈ s, from is_subgroup.inv_mem hxy, by simpa using this, assume x y z hxy hyz, have x⁻¹ * y * (y⁻¹ * z) ∈ s, from is_submonoid.mul_mem hxy hyz, by simpa [mul_assoc] using this⟩ /-- `quotient s` is the quotient type representing the left cosets of `s`. If `s` is a normal subgroup, `quotient s` is a group -/ def quotient [group α] (s : set α) [is_subgroup s] : Type* := quotient (left_rel s) variables [group α] {s : set α} [is_subgroup s] def mk (a : α) : quotient s := quotient.mk' a instance : has_coe α (quotient s) := ⟨mk⟩ instance [group α] (s : set α) [is_subgroup s] : inhabited (quotient s) := ⟨((1 : α) : quotient s)⟩ protected lemma eq {a b : α} : (a : quotient s) = b ↔ a⁻¹ * b ∈ s := quotient.eq' lemma eq_class_eq_left_coset [group α] (s : set α) [is_subgroup s] (g : α) : {x : α | (x : quotient s) = g} = left_coset g s := set.ext $ λ z, by rw [mem_left_coset_iff, set.mem_set_of_eq, eq_comm, quotient_group.eq] end quotient_group namespace is_subgroup open quotient_group variables [group α] {s : set α} def left_coset_equiv_subgroup (g : α) : left_coset g s ≃ s := ⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩, λ x, ⟨g * x.1, x.1, x.2, rfl⟩, λ ⟨x, hx⟩, subtype.eq $ by simp, λ ⟨g, hg⟩, subtype.eq $ by simp⟩ noncomputable def group_equiv_quotient_times_subgroup (hs : is_subgroup s) : α ≃ (quotient s × s) := calc α ≃ Σ L : quotient s, {x : α // (x : quotient s)= L} : equiv.equiv_fib quotient_group.mk ... ≃ Σ L : quotient s, left_coset (quotient.out' L) s : equiv.sigma_congr_right (λ L, begin rw ← eq_class_eq_left_coset, show {x // quotient.mk' x = L} ≃ {x : α // quotient.mk' x = quotient.mk' _}, simp [-quotient.eq'] end) ... ≃ Σ L : quotient s, s : equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _) ... ≃ (quotient s × s) : equiv.sigma_equiv_prod _ _ end is_subgroup
5913b66fc0631e92142fb9b9e48775a23efc30cd
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/run/pred_using_structure_cmd.lean
870fb0d3767e04ed2b7731cb17981746a708e7ec
[ "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
341
lean
variable {A : Type} structure has_refl (R : A → A → Prop) : Prop := (refl : ∀ a, R a a) structure is_equiv (R : A → A → Prop) extends has_refl R : Prop := (symm : ∀ a b, R a b → R b a) (trans : ∀ a b c, R a b → R b c → R a c) check @is_equiv.refl check @is_equiv.symm check @is_equiv.trans check @is_equiv.to_has_refl
5b54c5fb2f2185693561eae910d7793822bc1d3f
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/sums/default_auto.lean
34759d033cc0c226bfc0883fabbd4df8ed331a0a
[]
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
162
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.sums.associator import Mathlib.PostPort namespace Mathlib end Mathlib
e20feb96b2e787417603cec943bb3fb4733c69f1
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/topology/bases.lean
53d3ad93ab534e69f910493efe87b252b8f77fcf
[ "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
42,100
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import topology.constructions import topology.continuous_on /-! # Bases of topologies. Countability axioms. A topological basis on a topological space `t` is a collection of sets, such that all open sets can be generated as unions of these sets, without the need to take finite intersections of them. This file introduces a framework for dealing with these collections, and also what more we can say under certain countability conditions on bases, which are referred to as first- and second-countable. We also briefly cover the theory of separable spaces, which are those with a countable, dense subset. If a space is second-countable, and also has a countably generated uniformity filter (for example, if `t` is a metric space), it will automatically be separable (and indeed, these conditions are equivalent in this case). ## Main definitions * `is_topological_basis s`: The topological space `t` has basis `s`. * `separable_space α`: The topological space `t` has a countable, dense subset. * `is_separable s`: The set `s` is contained in the closure of a countable set. * `first_countable_topology α`: A topology in which `𝓝 x` is countably generated for every `x`. * `second_countable_topology α`: A topology which has a topological basis which is countable. ## Main results * `first_countable_topology.tendsto_subseq`: In a first-countable space, cluster points are limits of subsequences. * `second_countable_topology.is_open_Union_countable`: In a second-countable space, the union of arbitrarily-many open sets is equal to a sub-union of only countably many of these sets. * `second_countable_topology.countable_cover_nhds`: Consider `f : α → set α` with the property that `f x ∈ 𝓝 x` for all `x`. Then there is some countable set `s` whose image covers the space. ## Implementation Notes For our applications we are interested that there exists a countable basis, but we do not need the concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins. ### TODO: More fine grained instances for `first_countable_topology`, `separable_space`, `t2_space`, and more (see the comment below `subtype.second_countable_topology`.) -/ open set filter function open_locale topological_space filter noncomputable theory namespace topological_space universe u variables {α : Type u} [t : topological_space α] include t /-- A topological basis is one that satisfies the necessary conditions so that it suffices to take unions of the basis sets to get a topology (without taking finite intersections as well). -/ structure is_topological_basis (s : set (set α)) : Prop := (exists_subset_inter : ∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) (sUnion_eq : (⋃₀ s) = univ) (eq_generate_from : t = generate_from s) lemma is_topological_basis.insert_empty {s : set (set α)} (h : is_topological_basis s) : is_topological_basis (insert ∅ s) := begin refine ⟨_, by rw [sUnion_insert, empty_union, h.sUnion_eq], _⟩, { rintro t₁ (rfl|h₁) t₂ (rfl|h₂) x ⟨hx₁, hx₂⟩, {cases hx₁}, {cases hx₁}, {cases hx₂}, obtain ⟨t₃, h₃, hs⟩ := h.exists_subset_inter _ h₁ _ h₂ x ⟨hx₁, hx₂⟩, exact ⟨t₃, or.inr h₃, hs⟩ }, { rw h.eq_generate_from, refine le_antisymm (le_generate_from $ λ t, _) (generate_from_mono $ subset_insert ∅ s), rintro (rfl|ht), { convert is_open_empty }, { exact generate_open.basic t ht } }, end lemma is_topological_basis.diff_empty {s : set (set α)} (h : is_topological_basis s) : is_topological_basis (s \ {∅}) := begin refine ⟨_, by rw [sUnion_diff_singleton_empty, h.sUnion_eq], _⟩, { rintro t₁ ⟨h₁, -⟩ t₂ ⟨h₂, -⟩ x hx, obtain ⟨t₃, h₃, hs⟩ := h.exists_subset_inter _ h₁ _ h₂ x hx, exact ⟨t₃, ⟨h₃, ne_empty_iff_nonempty.2 ⟨x, hs.1⟩⟩, hs⟩ }, { rw h.eq_generate_from, refine le_antisymm (generate_from_mono $ diff_subset s _) (le_generate_from $ λ t ht, _), obtain rfl|he := eq_or_ne t ∅, { convert is_open_empty }, exact generate_open.basic t ⟨ht, he⟩ }, end /-- If a family of sets `s` generates the topology, then intersections of finite subcollections of `s` form a topological basis. -/ lemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) : is_topological_basis ((λ f, ⋂₀ f) '' {f : set (set α) | f.finite ∧ f ⊆ s}) := begin refine ⟨_, _, hs.trans (le_antisymm (le_generate_from _) $ generate_from_mono $ λ t ht, _)⟩, { rintro _ ⟨t₁, ⟨hft₁, ht₁b⟩, rfl⟩ _ ⟨t₂, ⟨hft₂, ht₂b⟩, rfl⟩ x h, exact ⟨_, ⟨_, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b⟩, sInter_union t₁ t₂⟩, h, subset.rfl⟩ }, { rw [sUnion_image, Union₂_eq_univ_iff], exact λ x, ⟨∅, ⟨finite_empty, empty_subset _⟩, sInter_empty.substr $ mem_univ x⟩ }, { rintro _ ⟨t, ⟨hft, htb⟩, rfl⟩, apply is_open_sInter, exacts [hft, λ s hs, generate_open.basic _ $ htb hs] }, { rw ← sInter_singleton t, exact ⟨{t}, ⟨finite_singleton t, singleton_subset_iff.2 ht⟩, rfl⟩ }, end /-- If a family of open sets `s` is such that every open neighbourhood contains some member of `s`, then `s` is a topological basis. -/ lemma is_topological_basis_of_open_of_nhds {s : set (set α)} (h_open : ∀ u ∈ s, is_open u) (h_nhds : ∀(a:α) (u : set α), a ∈ u → is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) : is_topological_basis s := begin refine ⟨λ t₁ ht₁ t₂ ht₂ x hx, h_nhds _ _ hx (is_open.inter (h_open _ ht₁) (h_open _ ht₂)), _, _⟩, { refine sUnion_eq_univ_iff.2 (λ a, _), rcases h_nhds a univ trivial is_open_univ with ⟨u, h₁, h₂, -⟩, exact ⟨u, h₁, h₂⟩ }, { refine (le_generate_from h_open).antisymm (λ u hu, _), refine (@is_open_iff_nhds α (generate_from s) u).mpr (λ a ha, _), rcases h_nhds a u ha hu with ⟨v, hvs, hav, hvu⟩, rw nhds_generate_from, exact infi₂_le_of_le v ⟨hav, hvs⟩ (le_principal_iff.2 hvu) } end /-- A set `s` is in the neighbourhood of `a` iff there is some basis set `t`, which contains `a` and is itself contained in `s`. -/ lemma is_topological_basis.mem_nhds_iff {a : α} {s : set α} {b : set (set α)} (hb : is_topological_basis b) : s ∈ 𝓝 a ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s := begin change s ∈ (𝓝 a).sets ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s, rw [hb.eq_generate_from, nhds_generate_from, binfi_sets_eq], { simp [and_assoc, and.left_comm] }, { exact assume s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩, have a ∈ s ∩ t, from ⟨hs₁, ht₁⟩, let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ this in ⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (subset.trans hu₃ (inter_subset_left _ _)), le_principal_iff.2 (subset.trans hu₃ (inter_subset_right _ _))⟩ }, { rcases eq_univ_iff_forall.1 hb.sUnion_eq a with ⟨i, h1, h2⟩, exact ⟨i, h2, h1⟩ } end lemma is_topological_basis.is_open_iff {s : set α} {b : set (set α)} (hb : is_topological_basis b) : is_open s ↔ ∀ a ∈ s, ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by simp [is_open_iff_mem_nhds, hb.mem_nhds_iff] lemma is_topological_basis.nhds_has_basis {b : set (set α)} (hb : is_topological_basis b) {a : α} : (𝓝 a).has_basis (λ t : set α, t ∈ b ∧ a ∈ t) (λ t, t) := ⟨λ s, hb.mem_nhds_iff.trans $ by simp only [exists_prop, and_assoc]⟩ protected lemma is_topological_basis.is_open {s : set α} {b : set (set α)} (hb : is_topological_basis b) (hs : s ∈ b) : is_open s := by { rw hb.eq_generate_from, exact generate_open.basic s hs } protected lemma is_topological_basis.mem_nhds {a : α} {s : set α} {b : set (set α)} (hb : is_topological_basis b) (hs : s ∈ b) (ha : a ∈ s) : s ∈ 𝓝 a := (hb.is_open hs).mem_nhds ha lemma is_topological_basis.exists_subset_of_mem_open {b : set (set α)} (hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u) (ou : is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u := hb.mem_nhds_iff.1 $ is_open.mem_nhds ou au /-- Any open set is the union of the basis sets contained in it. -/ lemma is_topological_basis.open_eq_sUnion' {B : set (set α)} (hB : is_topological_basis B) {u : set α} (ou : is_open u) : u = ⋃₀ {s ∈ B | s ⊆ u} := ext $ λ a, ⟨λ ha, let ⟨b, hb, ab, bu⟩ := hB.exists_subset_of_mem_open ha ou in ⟨b, ⟨hb, bu⟩, ab⟩, λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩ lemma is_topological_basis.open_eq_sUnion {B : set (set α)} (hB : is_topological_basis B) {u : set α} (ou : is_open u) : ∃ S ⊆ B, u = ⋃₀ S := ⟨{s ∈ B | s ⊆ u}, λ s h, h.1, hB.open_eq_sUnion' ou⟩ lemma is_topological_basis.open_iff_eq_sUnion {B : set (set α)} (hB : is_topological_basis B) {u : set α} : is_open u ↔ ∃ S ⊆ B, u = ⋃₀ S := ⟨hB.open_eq_sUnion, λ ⟨S, hSB, hu⟩, hu.symm ▸ is_open_sUnion (λ s hs, hB.is_open (hSB hs))⟩ lemma is_topological_basis.open_eq_Union {B : set (set α)} (hB : is_topological_basis B) {u : set α} (ou : is_open u) : ∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B := ⟨↥{s ∈ B | s ⊆ u}, coe, by { rw ← sUnion_eq_Union, apply hB.open_eq_sUnion' ou }, λ s, and.left s.2⟩ /-- A point `a` is in the closure of `s` iff all basis sets containing `a` intersect `s`. -/ lemma is_topological_basis.mem_closure_iff {b : set (set α)} (hb : is_topological_basis b) {s : set α} {a : α} : a ∈ closure s ↔ ∀ o ∈ b, a ∈ o → (o ∩ s).nonempty := (mem_closure_iff_nhds_basis' hb.nhds_has_basis).trans $ by simp only [and_imp] /-- A set is dense iff it has non-trivial intersection with all basis sets. -/ lemma is_topological_basis.dense_iff {b : set (set α)} (hb : is_topological_basis b) {s : set α} : dense s ↔ ∀ o ∈ b, set.nonempty o → (o ∩ s).nonempty := begin simp only [dense, hb.mem_closure_iff], exact ⟨λ h o hb ⟨a, ha⟩, h a o hb ha, λ h a o hb ha, h o hb ⟨a, ha⟩⟩ end lemma is_topological_basis.is_open_map_iff {β} [topological_space β] {B : set (set α)} (hB : is_topological_basis B) {f : α → β} : is_open_map f ↔ ∀ s ∈ B, is_open (f '' s) := begin refine ⟨λ H o ho, H _ (hB.is_open ho), λ hf o ho, _⟩, rw [hB.open_eq_sUnion' ho, sUnion_eq_Union, image_Union], exact is_open_Union (λ s, hf s s.2.1) end lemma is_topological_basis.exists_nonempty_subset {B : set (set α)} (hb : is_topological_basis B) {u : set α} (hu : u.nonempty) (ou : is_open u) : ∃ v ∈ B, set.nonempty v ∧ v ⊆ u := begin cases hu with x hx, rw [hb.open_eq_sUnion' ou, mem_sUnion] at hx, rcases hx with ⟨v, hv, hxv⟩, exact ⟨v, hv.1, ⟨x, hxv⟩, hv.2⟩ end lemma is_topological_basis_opens : is_topological_basis { U : set α | is_open U } := is_topological_basis_of_open_of_nhds (by tauto) (by tauto) protected lemma is_topological_basis.prod {β} [topological_space β] {B₁ : set (set α)} {B₂ : set (set β)} (h₁ : is_topological_basis B₁) (h₂ : is_topological_basis B₂) : is_topological_basis (image2 (×ˢ) B₁ B₂) := begin refine is_topological_basis_of_open_of_nhds _ _, { rintro _ ⟨u₁, u₂, hu₁, hu₂, rfl⟩, exact (h₁.is_open hu₁).prod (h₂.is_open hu₂) }, { rintro ⟨a, b⟩ u hu uo, rcases (h₁.nhds_has_basis.prod_nhds h₂.nhds_has_basis).mem_iff.1 (is_open.mem_nhds uo hu) with ⟨⟨s, t⟩, ⟨⟨hs, ha⟩, ht, hb⟩, hu⟩, exact ⟨s ×ˢ t, mem_image2_of_mem hs ht, ⟨ha, hb⟩, hu⟩ } end protected lemma is_topological_basis.inducing {β} [topological_space β] {f : α → β} {T : set (set β)} (hf : inducing f) (h : is_topological_basis T) : is_topological_basis (image (preimage f) T) := begin refine is_topological_basis_of_open_of_nhds _ _, { rintros _ ⟨V, hV, rfl⟩, rwa hf.is_open_iff, refine ⟨V, h.is_open hV, rfl⟩ }, { intros a U ha hU, rw hf.is_open_iff at hU, obtain ⟨V, hV, rfl⟩ := hU, obtain ⟨S, hS, rfl⟩ := h.open_eq_sUnion hV, obtain ⟨W, hW, ha⟩ := ha, refine ⟨f ⁻¹' W, ⟨_, hS hW, rfl⟩, ha, set.preimage_mono $ set.subset_sUnion_of_mem hW⟩ } end lemma is_topological_basis_of_cover {ι} {U : ι → set α} (Uo : ∀ i, is_open (U i)) (Uc : (⋃ i, U i) = univ) {b : Π i, set (set (U i))} (hb : ∀ i, is_topological_basis (b i)) : is_topological_basis (⋃ i : ι, image (coe : U i → α) '' (b i)) := begin refine is_topological_basis_of_open_of_nhds (λ u hu, _) _, { simp only [mem_Union, mem_image] at hu, rcases hu with ⟨i, s, sb, rfl⟩, exact (Uo i).is_open_map_subtype_coe _ ((hb i).is_open sb) }, { intros a u ha uo, rcases Union_eq_univ_iff.1 Uc a with ⟨i, hi⟩, lift a to ↥(U i) using hi, rcases (hb i).exists_subset_of_mem_open (by exact ha) (uo.preimage continuous_subtype_coe) with ⟨v, hvb, hav, hvu⟩, exact ⟨coe '' v, mem_Union.2 ⟨i, mem_image_of_mem _ hvb⟩, mem_image_of_mem _ hav, image_subset_iff.2 hvu⟩ } end protected lemma is_topological_basis.continuous {β : Type*} [topological_space β] {B : set (set β)} (hB : is_topological_basis B) (f : α → β) (hf : ∀ s ∈ B, is_open (f ⁻¹' s)) : continuous f := begin rw hB.eq_generate_from, exact continuous_generated_from hf end variables (α) /-- A separable space is one with a countable dense subset, available through `topological_space.exists_countable_dense`. If `α` is also known to be nonempty, then `topological_space.dense_seq` provides a sequence `ℕ → α` with dense range, see `topological_space.dense_range_dense_seq`. If `α` is a uniform space with countably generated uniformity filter (e.g., an `emetric_space`), then this condition is equivalent to `topological_space.second_countable_topology α`. In this case the latter should be used as a typeclass argument in theorems because Lean can automatically deduce `separable_space` from `second_countable_topology` but it can't deduce `second_countable_topology` and `emetric_space`. -/ class separable_space : Prop := (exists_countable_dense : ∃s:set α, s.countable ∧ dense s) lemma exists_countable_dense [separable_space α] : ∃ s : set α, s.countable ∧ dense s := separable_space.exists_countable_dense /-- A nonempty separable space admits a sequence with dense range. Instead of running `cases` on the conclusion of this lemma, you might want to use `topological_space.dense_seq` and `topological_space.dense_range_dense_seq`. If `α` might be empty, then `exists_countable_dense` is the main way to use separability of `α`. -/ lemma exists_dense_seq [separable_space α] [nonempty α] : ∃ u : ℕ → α, dense_range u := begin obtain ⟨s : set α, hs, s_dense⟩ := exists_countable_dense α, cases set.countable_iff_exists_subset_range.mp hs with u hu, exact ⟨u, s_dense.mono hu⟩, end /-- A dense sequence in a non-empty separable topological space. If `α` might be empty, then `exists_countable_dense` is the main way to use separability of `α`. -/ def dense_seq [separable_space α] [nonempty α] : ℕ → α := classical.some (exists_dense_seq α) /-- The sequence `dense_seq α` has dense range. -/ @[simp] lemma dense_range_dense_seq [separable_space α] [nonempty α] : dense_range (dense_seq α) := classical.some_spec (exists_dense_seq α) variable {α} @[priority 100] instance countable.to_separable_space [countable α] : separable_space α := { exists_countable_dense := ⟨set.univ, set.countable_univ, dense_univ⟩ } lemma separable_space_of_dense_range {ι : Type*} [countable ι] (u : ι → α) (hu : dense_range u) : separable_space α := ⟨⟨range u, countable_range u, hu⟩⟩ /-- In a separable space, a family of nonempty disjoint open sets is countable. -/ lemma _root_.set.pairwise_disjoint.countable_of_is_open [separable_space α] {ι : Type*} {s : ι → set α} {a : set ι} (h : a.pairwise_disjoint s) (ha : ∀ i ∈ a, is_open (s i)) (h'a : ∀ i ∈ a, (s i).nonempty) : a.countable := begin rcases exists_countable_dense α with ⟨u, ⟨u_encodable⟩, u_dense⟩, have : ∀ i : a, ∃ y, y ∈ s i ∩ u := λ i, dense_iff_inter_open.1 u_dense (s i) (ha i i.2) (h'a i i.2), choose f hfs hfu using this, lift f to a → u using hfu, have f_inj : injective f, { refine injective_iff_pairwise_ne.mpr ((h.subtype _ _).mono $ λ i j hij hfij, hij.le_bot ⟨hfs i, _⟩), simp only [congr_arg coe hfij, hfs j] }, exact ⟨@encodable.of_inj _ _ u_encodable f f_inj⟩ end /-- In a separable space, a family of disjoint sets with nonempty interiors is countable. -/ lemma _root_.set.pairwise_disjoint.countable_of_nonempty_interior [separable_space α] {ι : Type*} {s : ι → set α} {a : set ι} (h : a.pairwise_disjoint s) (ha : ∀ i ∈ a, (interior (s i)).nonempty) : a.countable := (h.mono $ λ i, interior_subset).countable_of_is_open (λ i hi, is_open_interior) ha /-- A set `s` in a topological space is separable if it is contained in the closure of a countable set `c`. Beware that this definition does not require that `c` is contained in `s` (to express the latter, use `separable_space s` or `is_separable (univ : set s))`. In metric spaces, the two definitions are equivalent, see `topological_space.is_separable.separable_space`. -/ def is_separable (s : set α) := ∃ c : set α, c.countable ∧ s ⊆ closure c lemma is_separable.mono {s u : set α} (hs : is_separable s) (hu : u ⊆ s) : is_separable u := begin rcases hs with ⟨c, c_count, hs⟩, exact ⟨c, c_count, hu.trans hs⟩ end lemma is_separable.union {s u : set α} (hs : is_separable s) (hu : is_separable u) : is_separable (s ∪ u) := begin rcases hs with ⟨cs, cs_count, hcs⟩, rcases hu with ⟨cu, cu_count, hcu⟩, refine ⟨cs ∪ cu, cs_count.union cu_count, _⟩, exact union_subset (hcs.trans (closure_mono (subset_union_left _ _))) (hcu.trans (closure_mono (subset_union_right _ _))) end lemma is_separable.closure {s : set α} (hs : is_separable s) : is_separable (closure s) := begin rcases hs with ⟨c, c_count, hs⟩, exact ⟨c, c_count, by simpa using closure_mono hs⟩, end lemma is_separable_Union {ι : Type*} [countable ι] {s : ι → set α} (hs : ∀ i, is_separable (s i)) : is_separable (⋃ i, s i) := begin choose c hc h'c using hs, refine ⟨⋃ i, c i, countable_Union hc, Union_subset_iff.2 (λ i, _)⟩, exact (h'c i).trans (closure_mono (subset_Union _ i)) end lemma _root_.set.countable.is_separable {s : set α} (hs : s.countable) : is_separable s := ⟨s, hs, subset_closure⟩ lemma _root_.set.finite.is_separable {s : set α} (hs : s.finite) : is_separable s := hs.countable.is_separable lemma is_separable_univ_iff : is_separable (univ : set α) ↔ separable_space α := begin split, { rintros ⟨c, c_count, hc⟩, refine ⟨⟨c, c_count, by rwa [dense_iff_closure_eq, ← univ_subset_iff]⟩⟩ }, { introsI h, rcases exists_countable_dense α with ⟨c, c_count, hc⟩, exact ⟨c, c_count, by rwa [univ_subset_iff, ← dense_iff_closure_eq]⟩ } end lemma is_separable_of_separable_space [h : separable_space α] (s : set α) : is_separable s := is_separable.mono (is_separable_univ_iff.2 h) (subset_univ _) lemma is_separable.image {β : Type*} [topological_space β] {s : set α} (hs : is_separable s) {f : α → β} (hf : continuous f) : is_separable (f '' s) := begin rcases hs with ⟨c, c_count, hc⟩, refine ⟨f '' c, c_count.image _, _⟩, rw image_subset_iff, exact hc.trans (closure_subset_preimage_closure_image hf) end lemma is_separable_of_separable_space_subtype (s : set α) [separable_space s] : is_separable s := begin have : is_separable ((coe : s → α) '' (univ : set s)) := (is_separable_of_separable_space _).image continuous_subtype_coe, simpa only [image_univ, subtype.range_coe_subtype], end end topological_space open topological_space lemma is_topological_basis_pi {ι : Type*} {X : ι → Type*} [∀ i, topological_space (X i)] {T : Π i, set (set (X i))} (cond : ∀ i, is_topological_basis (T i)) : is_topological_basis {S : set (Π i, X i) | ∃ (U : Π i, set (X i)) (F : finset ι), (∀ i, i ∈ F → (U i) ∈ T i) ∧ S = (F : set ι).pi U } := begin refine is_topological_basis_of_open_of_nhds _ _, { rintro _ ⟨U, F, h1, rfl⟩, apply is_open_set_pi F.finite_to_set, intros i hi, exact (cond i).is_open (h1 i hi) }, { intros a U ha hU, obtain ⟨I, t, hta, htU⟩ : ∃ (I : finset ι) (t : Π (i : ι), set (X i)), (∀ i, t i ∈ 𝓝 (a i)) ∧ set.pi ↑I t ⊆ U, { rw [← filter.mem_pi', ← nhds_pi], exact hU.mem_nhds ha }, have : ∀ i, ∃ V ∈ T i, a i ∈ V ∧ V ⊆ t i := λ i, (cond i).mem_nhds_iff.1 (hta i), choose V hVT haV hVt, exact ⟨_, ⟨V, I, λ i hi, hVT i, rfl⟩, λ i hi, haV i, (pi_mono $ λ i hi, hVt i).trans htU⟩ }, end lemma is_topological_basis_infi {β : Type*} {ι : Type*} {X : ι → Type*} [t : ∀ i, topological_space (X i)] {T : Π i, set (set (X i))} (cond : ∀ i, is_topological_basis (T i)) (f : Π i, β → X i) : @is_topological_basis β (⨅ i, induced (f i) (t i)) { S | ∃ (U : Π i, set (X i)) (F : finset ι), (∀ i, i ∈ F → U i ∈ T i) ∧ S = ⋂ i (hi : i ∈ F), (f i) ⁻¹' (U i) } := begin convert (is_topological_basis_pi cond).inducing (inducing_infi_to_pi _), ext V, split, { rintros ⟨U, F, h1, h2⟩, have : (F : set ι).pi U = (⋂ (i : ι) (hi : i ∈ F), (λ (z : Π j, X j), z i) ⁻¹' (U i)), by { ext, simp }, refine ⟨(F : set ι).pi U, ⟨U, F, h1, rfl⟩, _⟩, rw [this, h2, set.preimage_Inter], congr' 1, ext1, rw set.preimage_Inter, refl }, { rintros ⟨U, ⟨U, F, h1, rfl⟩, h⟩, refine ⟨U, F, h1, _⟩, have : (F : set ι).pi U = (⋂ (i : ι) (hi : i ∈ F), (λ (z : Π j, X j), z i) ⁻¹' (U i)), by { ext, simp }, rw [← h, this, set.preimage_Inter], congr' 1, ext1, rw set.preimage_Inter, refl } end lemma is_topological_basis_singletons (α : Type*) [topological_space α] [discrete_topology α] : is_topological_basis {s | ∃ (x : α), (s : set α) = {x}} := is_topological_basis_of_open_of_nhds (λ u hu, is_open_discrete _) $ λ x u hx u_open, ⟨{x}, ⟨x, rfl⟩, mem_singleton x, singleton_subset_iff.2 hx⟩ /-- If `α` is a separable space and `f : α → β` is a continuous map with dense range, then `β` is a separable space as well. E.g., the completion of a separable uniform space is separable. -/ protected lemma dense_range.separable_space {α β : Type*} [topological_space α] [separable_space α] [topological_space β] {f : α → β} (h : dense_range f) (h' : continuous f) : separable_space β := let ⟨s, s_cnt, s_dense⟩ := exists_countable_dense α in ⟨⟨f '' s, countable.image s_cnt f, h.dense_image h' s_dense⟩⟩ lemma dense.exists_countable_dense_subset {α : Type*} [topological_space α] {s : set α} [separable_space s] (hs : dense s) : ∃ t ⊆ s, t.countable ∧ dense t := let ⟨t, htc, htd⟩ := exists_countable_dense s in ⟨coe '' t, image_subset_iff.2 $ λ x _, mem_preimage.2 $ subtype.coe_prop _, htc.image coe, hs.dense_range_coe.dense_image continuous_subtype_val htd⟩ /-- Let `s` be a dense set in a topological space `α` with partial order structure. If `s` is a separable space (e.g., if `α` has a second countable topology), then there exists a countable dense subset `t ⊆ s` such that `t` contains bottom/top element of `α` when they exist and belong to `s`. For a dense subset containing neither bot nor top elements, see `dense.exists_countable_dense_subset_no_bot_top`. -/ lemma dense.exists_countable_dense_subset_bot_top {α : Type*} [topological_space α] [partial_order α] {s : set α} [separable_space s] (hs : dense s) : ∃ t ⊆ s, t.countable ∧ dense t ∧ (∀ x, is_bot x → x ∈ s → x ∈ t) ∧ (∀ x, is_top x → x ∈ s → x ∈ t) := begin rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, htd⟩, refine ⟨(t ∪ ({x | is_bot x} ∪ {x | is_top x})) ∩ s, _, _, _, _, _⟩, exacts [inter_subset_right _ _, (htc.union ((countable_is_bot α).union (countable_is_top α))).mono (inter_subset_left _ _), htd.mono (subset_inter (subset_union_left _ _) hts), λ x hx hxs, ⟨or.inr $ or.inl hx, hxs⟩, λ x hx hxs, ⟨or.inr $ or.inr hx, hxs⟩] end instance separable_space_univ {α : Type*} [topological_space α] [separable_space α] : separable_space (univ : set α) := (equiv.set.univ α).symm.surjective.dense_range.separable_space (continuous_id.subtype_mk _) /-- If `α` is a separable topological space with a partial order, then there exists a countable dense set `s : set α` that contains those of both bottom and top elements of `α` that actually exist. For a dense set containing neither bot nor top elements, see `exists_countable_dense_no_bot_top`. -/ lemma exists_countable_dense_bot_top (α : Type*) [topological_space α] [separable_space α] [partial_order α] : ∃ s : set α, s.countable ∧ dense s ∧ (∀ x, is_bot x → x ∈ s) ∧ (∀ x, is_top x → x ∈ s) := by simpa using dense_univ.exists_countable_dense_subset_bot_top namespace topological_space universe u variables (α : Type u) [t : topological_space α] include t /-- A first-countable space is one in which every point has a countable neighborhood basis. -/ class first_countable_topology : Prop := (nhds_generated_countable : ∀a:α, (𝓝 a).is_countably_generated) attribute [instance] first_countable_topology.nhds_generated_countable namespace first_countable_topology variable {α} /-- In a first-countable space, a cluster point `x` of a sequence is the limit of some subsequence. -/ lemma tendsto_subseq [first_countable_topology α] {u : ℕ → α} {x : α} (hx : map_cluster_pt x at_top u) : ∃ (ψ : ℕ → ℕ), (strict_mono ψ) ∧ (tendsto (u ∘ ψ) at_top (𝓝 x)) := subseq_tendsto_of_ne_bot hx end first_countable_topology variables {α} instance {β} [topological_space β] [first_countable_topology α] [first_countable_topology β] : first_countable_topology (α × β) := ⟨λ ⟨x, y⟩, by { rw nhds_prod_eq, apply_instance }⟩ section pi omit t instance {ι : Type*} {π : ι → Type*} [countable ι] [Π i, topological_space (π i)] [∀ i, first_countable_topology (π i)] : first_countable_topology (Π i, π i) := ⟨λ f, by { rw nhds_pi, apply_instance }⟩ end pi instance is_countably_generated_nhds_within (x : α) [is_countably_generated (𝓝 x)] (s : set α) : is_countably_generated (𝓝[s] x) := inf.is_countably_generated _ _ variable (α) /-- A second-countable space is one with a countable basis. -/ class second_countable_topology : Prop := (is_open_generated_countable [] : ∃ b : set (set α), b.countable ∧ t = topological_space.generate_from b) variable {α} protected lemma is_topological_basis.second_countable_topology {b : set (set α)} (hb : is_topological_basis b) (hc : b.countable) : second_countable_topology α := ⟨⟨b, hc, hb.eq_generate_from⟩⟩ variable (α) lemma exists_countable_basis [second_countable_topology α] : ∃ b : set (set α), b.countable ∧ ∅ ∉ b ∧ is_topological_basis b := begin obtain ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α, refine ⟨_, _, not_mem_diff_of_mem _, (is_topological_basis_of_subbasis hb₂).diff_empty⟩, exacts [((countable_set_of_finite_subset hb₁).image _).mono (diff_subset _ _), rfl], end /-- A countable topological basis of `α`. -/ def countable_basis [second_countable_topology α] : set (set α) := (exists_countable_basis α).some lemma countable_countable_basis [second_countable_topology α] : (countable_basis α).countable := (exists_countable_basis α).some_spec.1 instance encodable_countable_basis [second_countable_topology α] : encodable (countable_basis α) := (countable_countable_basis α).to_encodable lemma empty_nmem_countable_basis [second_countable_topology α] : ∅ ∉ countable_basis α := (exists_countable_basis α).some_spec.2.1 lemma is_basis_countable_basis [second_countable_topology α] : is_topological_basis (countable_basis α) := (exists_countable_basis α).some_spec.2.2 lemma eq_generate_from_countable_basis [second_countable_topology α] : ‹topological_space α› = generate_from (countable_basis α) := (is_basis_countable_basis α).eq_generate_from variable {α} lemma is_open_of_mem_countable_basis [second_countable_topology α] {s : set α} (hs : s ∈ countable_basis α) : is_open s := (is_basis_countable_basis α).is_open hs lemma nonempty_of_mem_countable_basis [second_countable_topology α] {s : set α} (hs : s ∈ countable_basis α) : s.nonempty := ne_empty_iff_nonempty.1 $ ne_of_mem_of_not_mem hs $ empty_nmem_countable_basis α variable (α) @[priority 100] -- see Note [lower instance priority] instance second_countable_topology.to_first_countable_topology [second_countable_topology α] : first_countable_topology α := ⟨λ x, has_countable_basis.is_countably_generated $ ⟨(is_basis_countable_basis α).nhds_has_basis, (countable_countable_basis α).mono $ inter_subset_left _ _⟩⟩ /-- If `β` is a second-countable space, then its induced topology via `f` on `α` is also second-countable. -/ lemma second_countable_topology_induced (β) [t : topological_space β] [second_countable_topology β] (f : α → β) : @second_countable_topology α (t.induced f) := begin rcases second_countable_topology.is_open_generated_countable β with ⟨b, hb, eq⟩, refine { is_open_generated_countable := ⟨preimage f '' b, hb.image _, _⟩ }, rw [eq, induced_generate_from_eq] end instance subtype.second_countable_topology (s : set α) [second_countable_topology α] : second_countable_topology s := second_countable_topology_induced s α coe /- TODO: more fine grained instances for first_countable_topology, separable_space, t2_space, ... -/ instance {β : Type*} [topological_space β] [second_countable_topology α] [second_countable_topology β] : second_countable_topology (α × β) := ((is_basis_countable_basis α).prod (is_basis_countable_basis β)).second_countable_topology $ (countable_countable_basis α).image2 (countable_countable_basis β) _ instance {ι : Type*} {π : ι → Type*} [countable ι] [t : ∀a, topological_space (π a)] [∀a, second_countable_topology (π a)] : second_countable_topology (∀a, π a) := begin have : t = (λa, generate_from (countable_basis (π a))), from funext (assume a, (is_basis_countable_basis (π a)).eq_generate_from), rw [this, pi_generate_from_eq], constructor, refine ⟨_, _, rfl⟩, have : set.countable {T : set (Π i, π i) | ∃ (I : finset ι) (s : Π i : I, set (π i)), (∀ i, s i ∈ countable_basis (π i)) ∧ T = {f | ∀ i : I, f i ∈ s i}}, { simp only [set_of_exists, ← exists_prop], refine countable_Union (λ I, countable.bUnion _ (λ _ _, countable_singleton _)), change set.countable {s : Π i : I, set (π i) | ∀ i, s i ∈ countable_basis (π i)}, exact countable_pi (λ i, countable_countable_basis _) }, convert this using 1, ext1 T, split, { rintro ⟨s, I, hs, rfl⟩, refine ⟨I, λ i, s i, λ i, hs i i.2, _⟩, simp only [set.pi, set_coe.forall'], refl }, { rintro ⟨I, s, hs, rfl⟩, rcases @subtype.surjective_restrict ι (λ i, set (π i)) _ (λ i, i ∈ I) s with ⟨s, rfl⟩, exact ⟨s, I, λ i hi, hs ⟨i, hi⟩, set.ext $ λ f, subtype.forall⟩ } end @[priority 100] -- see Note [lower instance priority] instance second_countable_topology.to_separable_space [second_countable_topology α] : separable_space α := begin choose p hp using λ s : countable_basis α, nonempty_of_mem_countable_basis s.2, exact ⟨⟨range p, countable_range _, (is_basis_countable_basis α).dense_iff.2 $ λ o ho _, ⟨p ⟨o, ho⟩, hp _, mem_range_self _⟩⟩⟩ end variables {α} /-- A countable open cover induces a second-countable topology if all open covers are themselves second countable. -/ lemma second_countable_topology_of_countable_cover {ι} [encodable ι] {U : ι → set α} [∀ i, second_countable_topology (U i)] (Uo : ∀ i, is_open (U i)) (hc : (⋃ i, U i) = univ) : second_countable_topology α := begin have : is_topological_basis (⋃ i, image (coe : U i → α) '' (countable_basis (U i))), from is_topological_basis_of_cover Uo hc (λ i, is_basis_countable_basis (U i)), exact this.second_countable_topology (countable_Union $ λ i, (countable_countable_basis _).image _) end /-- In a second-countable space, an open set, given as a union of open sets, is equal to the union of countably many of those sets. -/ lemma is_open_Union_countable [second_countable_topology α] {ι} (s : ι → set α) (H : ∀ i, is_open (s i)) : ∃ T : set ι, T.countable ∧ (⋃ i ∈ T, s i) = ⋃ i, s i := begin let B := {b ∈ countable_basis α | ∃ i, b ⊆ s i}, choose f hf using λ b : B, b.2.2, haveI : encodable B := ((countable_countable_basis α).mono (sep_subset _ _)).to_encodable, refine ⟨_, countable_range f, (Union₂_subset_Union _ _).antisymm (sUnion_subset _)⟩, rintro _ ⟨i, rfl⟩ x xs, rcases (is_basis_countable_basis α).exists_subset_of_mem_open xs (H _) with ⟨b, hb, xb, bs⟩, exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ (by exact xb)⟩ end lemma is_open_sUnion_countable [second_countable_topology α] (S : set (set α)) (H : ∀ s ∈ S, is_open s) : ∃ T : set (set α), T.countable ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S := let ⟨T, cT, hT⟩ := is_open_Union_countable (λ s:S, s.1) (λ s, H s.1 s.2) in ⟨subtype.val '' T, cT.image _, image_subset_iff.2 $ λ ⟨x, xs⟩ xt, xs, by rwa [sUnion_image, sUnion_eq_Union]⟩ /-- In a topological space with second countable topology, if `f` is a function that sends each point `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`, `x ∈ s`, cover the whole space. -/ lemma countable_cover_nhds [second_countable_topology α] {f : α → set α} (hf : ∀ x, f x ∈ 𝓝 x) : ∃ s : set α, s.countable ∧ (⋃ x ∈ s, f x) = univ := begin rcases is_open_Union_countable (λ x, interior (f x)) (λ x, is_open_interior) with ⟨s, hsc, hsU⟩, suffices : (⋃ x ∈ s, interior (f x)) = univ, from ⟨s, hsc, flip eq_univ_of_subset this $ Union₂_mono $ λ _ _, interior_subset⟩, simp only [hsU, eq_univ_iff_forall, mem_Union], exact λ x, ⟨x, mem_interior_iff_mem_nhds.2 (hf x)⟩ end lemma countable_cover_nhds_within [second_countable_topology α] {f : α → set α} {s : set α} (hf : ∀ x ∈ s, f x ∈ 𝓝[s] x) : ∃ t ⊆ s, t.countable ∧ s ⊆ (⋃ x ∈ t, f x) := begin have : ∀ x : s, coe ⁻¹' (f x) ∈ 𝓝 x, from λ x, preimage_coe_mem_nhds_subtype.2 (hf x x.2), rcases countable_cover_nhds this with ⟨t, htc, htU⟩, refine ⟨coe '' t, subtype.coe_image_subset _ _, htc.image _, λ x hx, _⟩, simp only [bUnion_image, eq_univ_iff_forall, ← preimage_Union, mem_preimage] at htU ⊢, exact htU ⟨x, hx⟩ end section sigma variables {ι : Type*} {E : ι → Type*} [∀ i, topological_space (E i)] omit t /-- In a disjoint union space `Σ i, E i`, one can form a topological basis by taking the union of topological bases on each of the parts of the space. -/ lemma is_topological_basis.sigma {s : Π (i : ι), set (set (E i))} (hs : ∀ i, is_topological_basis (s i)) : is_topological_basis (⋃ (i : ι), (λ u, ((sigma.mk i) '' u : set (Σ i, E i))) '' (s i)) := begin apply is_topological_basis_of_open_of_nhds, { assume u hu, obtain ⟨i, t, ts, rfl⟩ : ∃ (i : ι) (t : set (E i)), t ∈ s i ∧ sigma.mk i '' t = u, by simpa only [mem_Union, mem_image] using hu, exact is_open_map_sigma_mk _ ((hs i).is_open ts) }, { rintros ⟨i, x⟩ u hxu u_open, have hx : x ∈ sigma.mk i ⁻¹' u := hxu, obtain ⟨v, vs, xv, hv⟩ : ∃ (v : set (E i)) (H : v ∈ s i), x ∈ v ∧ v ⊆ sigma.mk i ⁻¹' u := (hs i).exists_subset_of_mem_open hx (is_open_sigma_iff.1 u_open i), exact ⟨(sigma.mk i) '' v, mem_Union.2 ⟨i, mem_image_of_mem _ vs⟩, mem_image_of_mem _ xv, image_subset_iff.2 hv⟩ } end /-- A countable disjoint union of second countable spaces is second countable. -/ instance [countable ι] [∀ i, second_countable_topology (E i)] : second_countable_topology (Σ i, E i) := begin let b := (⋃ (i : ι), (λ u, ((sigma.mk i) '' u : set (Σ i, E i))) '' (countable_basis (E i))), have A : is_topological_basis b := is_topological_basis.sigma (λ i, is_basis_countable_basis _), have B : b.countable := countable_Union (λ i, countable.image (countable_countable_basis _) _), exact A.second_countable_topology B, end end sigma section sum omit t variables {β : Type*} [topological_space α] [topological_space β] /-- In a sum space `α ⊕ β`, one can form a topological basis by taking the union of topological bases on each of the two components. -/ lemma is_topological_basis.sum {s : set (set α)} (hs : is_topological_basis s) {t : set (set β)} (ht : is_topological_basis t) : is_topological_basis (((λ u, sum.inl '' u) '' s) ∪ ((λ u, sum.inr '' u) '' t)) := begin apply is_topological_basis_of_open_of_nhds, { assume u hu, cases hu, { rcases hu with ⟨w, hw, rfl⟩, exact open_embedding_inl.is_open_map w (hs.is_open hw) }, { rcases hu with ⟨w, hw, rfl⟩, exact open_embedding_inr.is_open_map w (ht.is_open hw) } }, { rintros x u hxu u_open, cases x, { have h'x : x ∈ sum.inl ⁻¹' u := hxu, obtain ⟨v, vs, xv, vu⟩ : ∃ (v : set α) (H : v ∈ s), x ∈ v ∧ v ⊆ sum.inl ⁻¹' u := hs.exists_subset_of_mem_open h'x (is_open_sum_iff.1 u_open).1, exact ⟨sum.inl '' v, mem_union_left _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv, image_subset_iff.2 vu⟩ }, { have h'x : x ∈ sum.inr ⁻¹' u := hxu, obtain ⟨v, vs, xv, vu⟩ : ∃ (v : set β) (H : v ∈ t), x ∈ v ∧ v ⊆ sum.inr ⁻¹' u := ht.exists_subset_of_mem_open h'x (is_open_sum_iff.1 u_open).2, exact ⟨sum.inr '' v, mem_union_right _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv, image_subset_iff.2 vu⟩ } } end /-- A sum type of two second countable spaces is second countable. -/ instance [second_countable_topology α] [second_countable_topology β] : second_countable_topology (α ⊕ β) := begin let b := (λ u, sum.inl '' u) '' (countable_basis α) ∪ (λ u, sum.inr '' u) '' (countable_basis β), have A : is_topological_basis b := (is_basis_countable_basis α).sum (is_basis_countable_basis β), have B : b.countable := (countable.image (countable_countable_basis _) _).union (countable.image (countable_countable_basis _) _), exact A.second_countable_topology B, end end sum section quotient variables {X : Type*} [topological_space X] {Y : Type*} [topological_space Y] {π : X → Y} omit t /-- The image of a topological basis under an open quotient map is a topological basis. -/ lemma is_topological_basis.quotient_map {V : set (set X)} (hV : is_topological_basis V) (h' : quotient_map π) (h : is_open_map π) : is_topological_basis (set.image π '' V) := begin apply is_topological_basis_of_open_of_nhds, { rintros - ⟨U, U_in_V, rfl⟩, apply h U (hV.is_open U_in_V), }, { intros y U y_in_U U_open, obtain ⟨x, rfl⟩ := h'.surjective y, let W := π ⁻¹' U, have x_in_W : x ∈ W := y_in_U, have W_open : is_open W := U_open.preimage h'.continuous, obtain ⟨Z, Z_in_V, x_in_Z, Z_in_W⟩ := hV.exists_subset_of_mem_open x_in_W W_open, have πZ_in_U : π '' Z ⊆ U := (set.image_subset _ Z_in_W).trans (image_preimage_subset π U), exact ⟨π '' Z, ⟨Z, Z_in_V, rfl⟩, ⟨x, x_in_Z, rfl⟩, πZ_in_U⟩, }, end /-- A second countable space is mapped by an open quotient map to a second countable space. -/ lemma quotient_map.second_countable_topology [second_countable_topology X] (h' : quotient_map π) (h : is_open_map π) : second_countable_topology Y := { is_open_generated_countable := begin obtain ⟨V, V_countable, V_no_empty, V_generates⟩ := exists_countable_basis X, exact ⟨set.image π '' V, V_countable.image (set.image π), (V_generates.quotient_map h' h).eq_generate_from⟩, end } variables {S : setoid X} /-- The image of a topological basis "downstairs" in an open quotient is a topological basis. -/ lemma is_topological_basis.quotient {V : set (set X)} (hV : is_topological_basis V) (h : is_open_map (quotient.mk : X → quotient S)) : is_topological_basis (set.image (quotient.mk : X → quotient S) '' V) := hV.quotient_map quotient_map_quotient_mk h /-- An open quotient of a second countable space is second countable. -/ lemma quotient.second_countable_topology [second_countable_topology X] (h : is_open_map (quotient.mk : X → quotient S)) : second_countable_topology (quotient S) := quotient_map_quotient_mk.second_countable_topology h end quotient end topological_space open topological_space variables {α β : Type*} [topological_space α] [topological_space β] {f : α → β} protected lemma inducing.second_countable_topology [second_countable_topology β] (hf : inducing f) : second_countable_topology α := by { rw hf.1, exact second_countable_topology_induced α β f } protected lemma embedding.second_countable_topology [second_countable_topology β] (hf : embedding f) : second_countable_topology α := hf.1.second_countable_topology
1f3c3fd8305b0c097f50be8fe9d0f5d88e8ada19
9dc8cecdf3c4634764a18254e94d43da07142918
/src/data/finite/basic.lean
060e39a1a81f055c49773a7d31320cf8a856603b
[ "Apache-2.0" ]
permissive
jcommelin/mathlib
d8456447c36c176e14d96d9e76f39841f69d2d9b
ee8279351a2e434c2852345c51b728d22af5a156
refs/heads/master
1,664,782,136,488
1,663,638,983,000
1,663,638,983,000
132,563,656
0
0
Apache-2.0
1,663,599,929,000
1,525,760,539,000
Lean
UTF-8
Lean
false
false
4,934
lean
/- Copyright (c) 2022 Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kyle Miller -/ import data.fintype.basic /-! # Finite types In this file we prove some theorems about `finite` and provide some instances. This typeclass is a `Prop`-valued counterpart of the typeclass `fintype`. See more details in the file where `finite` is defined. ## Main definitions * `fintype.finite`, `finite.of_fintype` creates a `finite` instance from a `fintype` instance. The former lemma takes `fintype α` as an explicit argument while the latter takes it as an instance argument. * `fintype.of_finite` noncomputably creates a `fintype` instance from a `finite` instance. ## Implementation notes There is an apparent duplication of many `fintype` instances in this module, however they follow a pattern: if a `fintype` instance depends on `decidable` instances or other `fintype` instances, then we need to "lower" the instance to be a `finite` instance by removing the `decidable` instances and switching the `fintype` instances to `finite` instances. These are precisely the ones that cannot be inferred using `finite.of_fintype`. (However, when using `open_locale classical` or the `classical` tactic the instances relying only on `decidable` instances will give `finite` instances.) In the future we might consider writing automation to create these "lowered" instances. ## Tags finiteness, finite types -/ noncomputable theory open_locale classical variables {α β γ : Type*} namespace finite @[priority 100] -- see Note [lower instance priority] instance of_subsingleton {α : Sort*} [subsingleton α] : finite α := of_injective (function.const α ()) $ function.injective_of_subsingleton _ @[nolint instance_priority] -- Higher priority for `Prop`s instance prop (p : Prop) : finite p := finite.of_subsingleton instance [finite α] [finite β] : finite (α × β) := by { haveI := fintype.of_finite α, haveI := fintype.of_finite β, apply_instance } instance {α β : Sort*} [finite α] [finite β] : finite (pprod α β) := of_equiv _ equiv.pprod_equiv_prod_plift.symm lemma prod_left (β) [finite (α × β)] [nonempty β] : finite α := of_surjective (prod.fst : α × β → α) prod.fst_surjective lemma prod_right (α) [finite (α × β)] [nonempty α] : finite β := of_surjective (prod.snd : α × β → β) prod.snd_surjective instance [finite α] [finite β] : finite (α ⊕ β) := by { haveI := fintype.of_finite α, haveI := fintype.of_finite β, apply_instance } lemma sum_left (β) [finite (α ⊕ β)] : finite α := of_injective (sum.inl : α → α ⊕ β) sum.inl_injective lemma sum_right (α) [finite (α ⊕ β)] : finite β := of_injective (sum.inr : β → α ⊕ β) sum.inr_injective instance {β : α → Type*} [finite α] [Π a, finite (β a)] : finite (Σ a, β a) := by { letI := fintype.of_finite α, letI := λ a, fintype.of_finite (β a), apply_instance } instance {ι : Sort*} {π : ι → Sort*} [finite ι] [Π i, finite (π i)] : finite (Σ' i, π i) := of_equiv _ (equiv.psigma_equiv_sigma_plift π).symm instance [finite α] : finite (set α) := by { casesI nonempty_fintype α, apply_instance } end finite /-- This instance also provides `[finite s]` for `s : set α`. -/ instance subtype.finite {α : Sort*} [finite α] {p : α → Prop} : finite {x // p x} := finite.of_injective coe subtype.coe_injective instance pi.finite {α : Sort*} {β : α → Sort*} [finite α] [∀ a, finite (β a)] : finite (Π a, β a) := begin haveI := fintype.of_finite (plift α), haveI := λ a, fintype.of_finite (plift (β a)), exact finite.of_equiv (Π (a : plift α), plift (β (equiv.plift a))) (equiv.Pi_congr equiv.plift (λ _, equiv.plift)), end instance vector.finite {α : Type*} [finite α] {n : ℕ} : finite (vector α n) := by { haveI := fintype.of_finite α, apply_instance } instance quot.finite {α : Sort*} [finite α] (r : α → α → Prop) : finite (quot r) := finite.of_surjective _ (surjective_quot_mk r) instance quotient.finite {α : Sort*} [finite α] (s : setoid α) : finite (quotient s) := quot.finite _ instance function.embedding.finite {α β : Sort*} [finite β] : finite (α ↪ β) := begin casesI is_empty_or_nonempty (α ↪ β) with _ h, { apply_instance, }, { refine h.elim (λ f, _), haveI : finite α := finite.of_injective _ f.injective, exact finite.of_injective _ fun_like.coe_injective }, end instance equiv.finite_right {α β : Sort*} [finite β] : finite (α ≃ β) := finite.of_injective equiv.to_embedding $ λ e₁ e₂ h, equiv.ext $ by convert fun_like.congr_fun h instance equiv.finite_left {α β : Sort*} [finite α] : finite (α ≃ β) := finite.of_equiv _ ⟨equiv.symm, equiv.symm, equiv.symm_symm, equiv.symm_symm⟩ instance [finite α] {n : ℕ} : finite (sym α n) := by { haveI := fintype.of_finite α, apply_instance }
8598a0e5f05e129dbfcf8569de448ce8bc2d0dfb
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/data/bundle.lean
0a00d9a6977d6be8e42e95de5edd5ed9e793edcb
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
2,954
lean
/- Copyright © 2021 Nicolò Cavalleri. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Nicolò Cavalleri -/ import tactic.basic import algebra.module.basic /-! # Bundle Basic data structure to implement fiber bundles, vector bundles (maybe fibrations?), etc. This file should contain all possible results that do not involve any topology. We provide a type synonym of `Σ x, E x` as `bundle.total_space E`, to be able to endow it with a topology which is not the disjoint union topology `sigma.topological_space`. In general, the constructions of fiber bundles we will make will be of this form. ## References - https://en.wikipedia.org/wiki/Bundle_(mathematics) -/ namespace bundle variables {B : Type*} (E : B → Type*) /-- `total_space E` is the total space of the bundle `Σ x, E x`. This type synonym is used to avoid conflicts with general sigma types. -/ def total_space := Σ x, E x instance [inhabited B] [inhabited (E default)] : inhabited (total_space E) := ⟨⟨default, default⟩⟩ /-- `bundle.proj E` is the canonical projection `total_space E → B` on the base space. -/ @[simp] def proj : total_space E → B := sigma.fst /-- Constructor for the total space of a `topological_fiber_bundle_core`. -/ @[simp, reducible] def total_space_mk (E : B → Type*) (b : B) (a : E b) : bundle.total_space E := ⟨b, a⟩ instance {x : B} : has_coe_t (E x) (total_space E) := ⟨sigma.mk x⟩ @[simp] lemma coe_fst (x : B) (v : E x) : (v : total_space E).fst = x := rfl lemma to_total_space_coe {x : B} (v : E x) : (v : total_space E) = ⟨x, v⟩ := rfl /-- `bundle.trivial B F` is the trivial bundle over `B` of fiber `F`. -/ def trivial (B : Type*) (F : Type*) : B → Type* := function.const B F instance {F : Type*} [inhabited F] {b : B} : inhabited (bundle.trivial B F b) := ⟨(default : F)⟩ /-- The trivial bundle, unlike other bundles, has a canonical projection on the fiber. -/ def trivial.proj_snd (B : Type*) (F : Type*) : (total_space (bundle.trivial B F)) → F := sigma.snd section fiber_structures variable [∀ x, add_comm_monoid (E x)] @[simp] lemma coe_snd_map_apply (x : B) (v w : E x) : (↑(v + w) : total_space E).snd = (v : total_space E).snd + (w : total_space E).snd := rfl variables (R : Type*) [semiring R] [∀ x, module R (E x)] @[simp] lemma coe_snd_map_smul (x : B) (r : R) (v : E x) : (↑(r • v) : total_space E).snd = r • (v : total_space E).snd := rfl end fiber_structures section trivial_instances local attribute [reducible] bundle.trivial variables {F : Type*} {R : Type*} [semiring R] (b : B) instance [add_comm_monoid F] : add_comm_monoid (bundle.trivial B F b) := ‹add_comm_monoid F› instance [add_comm_group F] : add_comm_group (bundle.trivial B F b) := ‹add_comm_group F› instance [add_comm_monoid F] [module R F] : module R (bundle.trivial B F b) := ‹module R F› end trivial_instances end bundle
f7d22fab88f82f24af767dee2e7e07919a06d2eb
df7bb3acd9623e489e95e85d0bc55590ab0bc393
/lean/love01_definitions_and_statements_demo.lean
c2655377bec0875f8f66e1189f43a2a60b5b711b
[]
no_license
MaschavanderMarel/logical_verification_2020
a41c210b9237c56cb35f6cd399e3ac2fe42e775d
7d562ef174cc6578ca6013f74db336480470b708
refs/heads/master
1,692,144,223,196
1,634,661,675,000
1,634,661,675,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
10,797
lean
import .lovelib /- # LoVe Preface ## Proof Assistants Proof assistants (also called interactive theorem provers) * check and help develop formal proofs; * can be used to prove big theorems, not only logic puzzles; * can be tedious to use; * are highly addictive (think video games). A selection of proof assistants, classified by logical foundations: * set theory: Isabelle/ZF, Metamath, Mizar; * simple type theory: HOL4, HOL Light, Isabelle/HOL; * **dependent type theory**: Agda, Coq, **Lean**, Matita, PVS. ## Success Stories Mathematics: * the four-color theorem (in Coq); * the odd-order theorem (in Coq); * the Kepler conjecture (in HOL Light and Isabelle/HOL). Computer science: * hardware * operating systems * programming language theory * compilers * security ## Lean Lean is a proof assistant developed primarily by Leonardo de Moura (Microsoft Research) since 2012. Its mathematical library, `mathlib`, is developed under the leadership of Jeremy Avigad (Carnegie Mellon University). We use community version 3.20.0. We use its basic libraries, `mathlib`, and `LoVelib`. Lean is a research project. Strengths: * highly expressive logic based on a dependent type theory called the **calculus of inductive constructions**; * extended with classical axioms and quotient types; * metaprogramming framework; * modern user interface; * documentation; * open source; * endless source of puns (Lean Forward, Lean Together, Boolean, …). ## This Course ### Web Site https://lean-forward.github.io/logical-verification/2020/index.html ### Installation Instructions https://github.com/blanchette/logical_verification_2020/blob/master/README.md#logical-verification-2020---installation-instructions ### Repository (Demos, Exercises, Homework) https://github.com/blanchette/logical_verification_2020 The file you are currently looking at is a demo. There are * 13 demo files; * 13 exercise sheets; * 11 homework sheets (10 points each); * 1 project (20 points). You may submit at most 10 homework, or at most 8 homework and the project. Homework, including the project, must be done individually. The homework builds on the exercises, which build on the demos. ### The Hitchhiker's Guide to Logical Verification https://github.com/blanchette/logical_verification_2020/blob/master/hitchhikers_guide.pdf https://github.com/blanchette/logical_verification_2020/blob/master/hitchhikers_guide_tablet.pdf The lecture notes consist of a preface and 13 chapters. They cover the same material as the corresponding lectures but with more details. Sometimes there will not be enough time to cover everything in class, so reading the lecture notes will be necessary. ### Final Exam The course aims at teaching concepts, not syntax. Therefore, the final exam is on paper. ## Our Goal We want you to * master fundamental theory and techniques in interactive theorem proving; * familiarize yourselves with some application areas; * develop some practical skills you can apply on a larger project (as a hobby, for an MSc or PhD, or in industry); * feel ready to move to another proof assistant and apply what you have learned; * understand the domain well enough to start reading scientific papers. This course is neither a pure logical foundations course nor a Lean tutorial. Lean is our vehicle, not an end in itself. # LoVe Demo 1: Definitions and Statements We introduce the basics of Lean and proof assistants, without trying to carry out actual proofs yet. We focus on specifying objects and statements of their intended properties. -/ set_option pp.beta true set_option pp.generalized_field_notation false namespace LoVe /- ## A View of Lean In a first approximation: Lean = functional programming + logic In today's lecture, we cover inductive types, recursive functions, and lemma statements. If you are not familiar with typed functional programming (e.g., Haskell, ML, OCaml, Scala), we recommend that you study a tutorial, such as the first chapters of the online tutorial __Learn You a Haskell for Great Good!__: http://learnyouahaskell.com/chapters Make sure to at least reach the section titled "Lambdas". ## Types and Terms Similar to simply typed λ-calculus or typed functional programming languages (ML, OCaml, Haskell). Types `σ`, `τ`, `υ`: * type variables `α`; * basic types `T`; * complex types `T σ1 … σN`. Some type constructors `T` are written infix, e.g., `→` (function type). The function arrow is right-associative: `σ₁ → σ₂ → σ₃ → τ` = `σ₁ → (σ₂ → (σ₃ → τ))`. Polymorphic types are also possible. In Lean, the type variables must be bound using `∀`, e.g., `∀α, α → α`. Terms `t`, `u`: * constants `c`; * variables `x`; * applications `t u`; * λ-expressions `λx, t`. __Currying__: functions can be * fully applied (e.g., `f x y z` if `f` is ternary); * partially applied (e.g., `f x y`, `f x`); * left unapplied (e.g., `f`). Application is left-associative: `f x y z` = `((f x) y) z`. -/ #check ℕ #check ℤ #check empty #check unit #check bool #check ℕ → ℤ #check ℤ → ℕ #check bool → ℕ → ℤ #check (bool → ℕ) → ℤ #check ℕ → (bool → ℕ) → ℤ #check λx : ℕ, x #check λf : ℕ → ℕ, λg : ℕ → ℕ, λh : ℕ → ℕ, λx : ℕ, h (g (f x)) #check λ(f g h : ℕ → ℕ) (x : ℕ), h (g (f x)) constants a b : ℤ constant f : ℤ → ℤ constant g : ℤ → ℤ → ℤ #check λx : ℤ, g (f (g a x)) (g x b) #check λx, g (f (g a x)) (g x b) #check λx, x constant trool : Type constants trool.true trool.false trool.maybe : trool /- ### Type Checking and Type Inference Type checking and type inference are decidable problems, but this property is quickly lost if features such as overloading or subtyping are added. Type judgment: `C ⊢ t : σ`, meaning `t` has type `σ` in local context `C`. Typing rules: —————————— Cst if c is declared with type σ C ⊢ c : σ —————————— Var if x : σ occurs in C C ⊢ x : σ C ⊢ t : σ → τ C ⊢ u : σ ——————————————————————————— App C ⊢ t u : τ C, x : σ ⊢ t : τ ———————————————————————— Lam C ⊢ (λx : σ, t) : σ → τ ### Type Inhabitation Given a type `σ`, the __type inhabitation__ problem consists of finding a term of that type. Recursive procedure: 1. If `σ` is of the form `τ → υ`, a candidate inhabitant is an anonymous function of the form `λx, _`. 2. Alternatively, you can use any constant or variable `x : τ₁ → ⋯ → τN → σ` to build the term `x _ … _`. -/ constants α β γ : Type def some_fun_of_type : (α → β → γ) → ((β → α) → β) → α → γ := λf g a, f a (g (λb, a)) /- ## Type Definitions An __inductive type__ (also called __inductive datatype__, __algebraic datatype__, or just __datatype__) is a type that consists all the values that can be built using a finite number of applications of its __constructors__, and only those. ### Natural Numbers -/ namespace my_nat /- Definition of type `nat` (= `ℕ`) of natural numbers, using Peano-style unary notation: -/ inductive nat : Type | zero : nat | succ : nat → nat #check nat #check nat.zero #check nat.succ end my_nat #print nat #print ℕ /- ### Arithmetic Expressions -/ inductive aexp : Type | num : ℤ → aexp | var : string → aexp | add : aexp → aexp → aexp | sub : aexp → aexp → aexp | mul : aexp → aexp → aexp | div : aexp → aexp → aexp /- ### Lists -/ namespace my_list inductive list (α : Type) : Type | nil : list | cons : α → list → list #check list.nil #check list.cons end my_list #print list /- ## Function Definitions The syntax for defining a function operating on an inductive type is very compact: We define a single function and use __pattern matching__ to extract the arguments to the constructors. -/ def add : ℕ → ℕ → ℕ | m nat.zero := m | m (nat.succ n) := nat.succ (add m n) #eval add 2 7 #reduce add 2 7 def mul : ℕ → ℕ → ℕ | _ nat.zero := nat.zero | m (nat.succ n) := add m (mul m n) #eval mul 2 7 #print mul #print mul._main def power : ℕ → ℕ → ℕ | _ nat.zero := 1 | m (nat.succ n) := m * power m n #eval power 2 5 def power₂ (m : ℕ) : ℕ → ℕ | nat.zero := 1 | (nat.succ n) := m * power₂ n #eval power₂ 2 5 def iter (α : Type) (z : α) (f : α → α) : ℕ → α | nat.zero := z | (nat.succ n) := f (iter n) #check iter def power₃ (m n : ℕ) : ℕ := iter ℕ 1 (λl, m * l) n #eval power₃ 2 5 def append (α : Type) : list α → list α → list α | list.nil ys := ys | (list.cons x xs) ys := list.cons x (append xs ys) #check append #eval append _ [3, 1] [4, 1, 5] /- Aliases: `[]` := `nil` `x :: xs` := `cons x xs` `[x₁, …, xN]` := `x₁ :: … :: xN :: []` -/ def append₂ {α : Type} : list α → list α → list α | list.nil ys := ys | (list.cons x xs) ys := list.cons x (append₂ xs ys) #check append₂ #eval append₂ [3, 1] [4, 1, 5] #check @append₂ #eval @append₂ _ [3, 1] [4, 1, 5] def append₃ {α : Type} : list α → list α → list α | [] ys := ys | (x :: xs) ys := x :: append₃ xs ys def reverse {α : Type} : list α → list α | [] := [] | (x :: xs) := reverse xs ++ [x] def eval (env : string → ℤ) : aexp → ℤ | (aexp.num i) := i | (aexp.var x) := env x | (aexp.add e₁ e₂) := eval e₁ + eval e₂ | (aexp.sub e₁ e₂) := eval e₁ - eval e₂ | (aexp.mul e₁ e₂) := eval e₁ * eval e₂ | (aexp.div e₁ e₂) := eval e₁ / eval e₂ /- Lean only accepts the function definitions for which it can prove termination. In particular, it accepts __structurally recursive__ functions, which peel off exactly one constructor at a time. ## Lemma Statements Notice the similarity with `def` commands. -/ namespace sorry_lemmas lemma add_comm (m n : ℕ) : add m n = add n m := sorry lemma add_assoc (l m n : ℕ) : add (add l m) n = add l (add m n) := sorry lemma mul_comm (m n : ℕ) : mul m n = mul n m := sorry lemma mul_assoc (l m n : ℕ) : mul (mul l m) n = mul l (mul m n) := sorry lemma mul_add (l m n : ℕ) : mul l (add m n) = add (mul l m) (mul l n) := sorry lemma reverse_reverse {α : Type} (xs : list α) : reverse (reverse xs) = xs := sorry /- Axioms are like lemmas but without proofs (`:= …`). Constant declarations are like definitions but without bodies (`:= …`). -/ constants a b : ℤ axiom a_less_b : a < b end sorry_lemmas end LoVe
cb9b927050d0337183ac5c7a6882f0a0c2b3d560
e031d1fbf8353b338e3189e0d9aec3adb5bb0512
/src/data/classes.lean
2b5ad1391364139998f67cdaca1a2ee68ea7095e
[ "Apache-2.0" ]
permissive
UniversalAlgebra/lean-ualib
e64431a70007a835b1dd933d66be04ffca118601
ab9cbddbb5bdf1eeac4b0d5994bd6cad2a3665d4
refs/heads/master
1,584,931,281,084
1,558,364,533,000
1,558,364,533,000
140,986,567
6
0
Apache-2.0
1,532,718,578,000
1,531,613,794,000
Lean
UTF-8
Lean
false
false
3,123
lean
-- we start with some examples of classical algebraic structures namespace examples universes u variables {α : Type u} class magma (α : Type u) extends has_mul α -- avoid the name groupoid here because that means something -- different in category theory; we could have called these "binars" -- by convention, we use an additive model if the operation is commutative class commutative_magma (α : Type u) extends has_add α := (add_comm : ∀ a b : α, a + b = b + a) class semigroup (α : Type u) extends magma α := (mul_assoc : ∀ a b c : α, a * b * c = a * (b * c)) class commutative_semigroup (α : Type u) extends commutative_magma α := (add_assoc : ∀ a b c : α, a + b + c = a + (b + c)) class monoid (α : Type u) extends semigroup α, has_one α := (one_mul : ∀ a : α, 1 * a = a) (mul_one : ∀ a : α, a * 1 = a) class commutative_monoid (α : Type u) extends commutative_semigroup α, has_zero α := (zero_add : ∀ a : α, 0 + a = a) (add_zero : ∀ a : α, a + 0 = a) class group (α : Type u) extends monoid α, has_inv α class commutative_group (α : Type u) extends commutative_monoid α, has_inv α -- Use monoid here because we assume rings have a multiplicative identity class ring (α : Type u) extends commutative_group α, monoid α := (distr_add_mul_left : ∀ a b c : α, a * (b + c) = a * b + a * c) (distr_add_mul_right : ∀ a b c : α, (b + c) * a = b * a + c * a) -- Use semigroup here to model rings without a multiplicative identity; i.e. "rngs" class rng (α : Type u) extends commutative_group α, semigroup α := (distr_add_mul_left : ∀ a b c : α, a * (b + c) = a * b + a * c) (distr_add_mul_right : ∀ a b c : α, (b + c) * a = b * a + c * a) -- model meet or join with plus class semilattice (α : Type u) extends commutative_semigroup α := (add_idempotent : ∀ x :α, x + x = x) -- we model ∨ (or "join" or "sup") as + of semilattice; -- we model ∧ (or "meet" or "inf") as a * of a semigroup and make it commutative. class lattice (α : Type u) extends semilattice α, semigroup α := (mul_idempotent : ∀ x : α, x * x = x) (add_absorb_left: ∀ x y: α, x * (x + y) = x) (add_absorb_right: ∀ x y: α, (x + y) * x = x) (mul_absorb_left: ∀ x y: α, x + (x * y) = x) (mul_absorb_right: ∀ x y: α, (x * y) + x = x) class bounded_lattice (a : Type u) extends lattice α, has_one α, has_zero α := (one_mul : ∀ x : α, one * x = x) (mul_one : ∀ x : α, x * one = x) (add_one : ∀ x : α, one + x = one) (one_add : ∀ x : α, x + one = one) (zero_mul : ∀ x : α, zero * x = zero) (mul_zero : ∀ x : α, x * zero = zero) (zero_add : ∀ x : α, zero + x = x) (add_zero : ∀ x : α, x + zero = x) class distributative_lattice (α : Type u) extends lattice α := (add_dis : ∀ x y z : α, x + (y * z) = (x + y) * (x + z)) (dis_add : ∀ x y z : α, (y * z) + x = (y + x) * (z + x)) (mul_dis : ∀ x y z : α, x * (y + z) = (x * y) + (x * z)) (dis_mul : ∀ x y z : α, (y + z) * x = (y * x) + (z * x)) end examples
39d53f657b98de115cadbae11045ca6e76056645
fe25de614feb5587799621c41487aaee0d083b08
/tests/lean/PPRoundtrip.lean
e1e31b6c8fdc7896b8ef272689a6bf536b3aeb35
[ "Apache-2.0" ]
permissive
pollend/lean4
e8469c2f5fb8779b773618c3267883cf21fb9fac
c913886938c4b3b83238a3f99673c6c5a9cec270
refs/heads/master
1,687,973,251,481
1,628,039,739,000
1,628,039,739,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
3,271
lean
import Lean open Lean open Lean.Elab open Lean.Elab.Term open Lean.Elab.Command open Std.Format open Std open Lean.PrettyPrinter open Lean.PrettyPrinter.Delaborator open Lean.Meta def checkM (stx : TermElabM Syntax) (optionsPerPos : OptionsPerPos := {}) : TermElabM Unit := do let opts ← getOptions let stx ← stx let e ← elabTermAndSynthesize stx none <* throwErrorIfErrors let stx' ← delab Name.anonymous [] e optionsPerPos let f' ← PrettyPrinter.ppTerm stx' let s := f'.pretty' opts IO.println s let env ← getEnv match Parser.runParserCategory env `term s "<input>" with | Except.error e => throwErrorAt stx e | Except.ok stx'' => do let e' ← elabTermAndSynthesize stx'' none <* throwErrorIfErrors unless (← isDefEq e e') do throwErrorAt stx (m!"failed to round-trip" ++ line ++ format e ++ line ++ format e') -- set_option trace.PrettyPrinter.parenthesize true set_option format.width 20 -- #eval checkM `(?m) -- fails round-trip #eval checkM `(Sort) #eval checkM `(Type) #eval checkM `(Type 0) #eval checkM `(Type 1) -- TODO: we need support for parsing `?u` to roundtrip the terms containing universe metavariables. Just pretty printing them as `_` is bad for error and trace messages -- #eval checkM `(Type _) -- #eval checkM `(Type (_ + 2)) #eval checkM `(Nat) #eval checkM `(List Nat) #eval checkM `(id Nat) #eval checkM `(id (id (id Nat))) section set_option pp.explicit true #eval checkM `(List Nat) #eval checkM `(id Nat) end section set_option pp.universes true #eval checkM `(List Nat) #eval checkM `(id Nat) #eval checkM `(Sum Nat Nat) end #eval checkM `(id (id Nat)) (Std.RBMap.empty.insert 5 $ KVMap.empty.insert `pp.explicit true) -- specify the expected type of `a` in a way that is not erased by the delaborator def typeAs.{u} (α : Type u) (a : α) := () set_option pp.analyze.knowsType false in #eval checkM `(fun (a : Nat) => a) #eval checkM `(fun (a : Nat) => a) #eval checkM `(fun (a b : Nat) => a) #eval checkM `(fun (a : Nat) (b : Bool) => a) #eval checkM `(fun {a b : Nat} => a) -- implicit lambdas work as long as the expected type is preserved #eval checkM `(typeAs ({α : Type} → (a : α) → α) fun a => a) section set_option pp.explicit true #eval checkM `(fun {α : Type} [ToString α] (a : α) => toString a) end #eval checkM `((α : Type) → α) #eval checkM `((α β : Type) → α) -- group #eval checkM `((α β : Type) → Type) -- don't group #eval checkM `((α : Type) → (a : α) → α) #eval checkM `({α : Type} → α) #eval checkM `({α : Type} → [ToString α] → α) #eval checkM `(∀ x : Nat, x = x) #eval checkM `(∀ {x : Nat} [ToString Nat], x = x) set_option pp.binderTypes false in #eval checkM `(∀ x : Nat, x = x) -- TODO: hide `ofNat` #eval checkM `(0) #eval checkM `(1) #eval checkM `(42) #eval checkM `("hi") set_option pp.structureInstanceTypes true in #eval checkM `({ type := Nat, val := 0 : PointedType }) #eval checkM `((1,2,3)) #eval checkM `((1,2).fst) #eval checkM `(1 < 2 || true) #eval checkM `(id (fun a => a) 0) #eval checkM `(typeAs Nat (do let x ← pure 1 discard <| pure 2 let y := 3 return x + y)) #eval checkM `(typeAs (Id Nat) (pure 1 >>= pure)) #eval checkM `((0 ≤ 1) = False) #eval checkM `((0 = 1) = False)
625092040efca3fc6275e1a9aee29b8f8010d355
57c233acf9386e610d99ed20ef139c5f97504ba3
/src/order/zorn.lean
1d8ce9d6224d7052c3eb8d189173d043851207f0
[ "Apache-2.0" ]
permissive
robertylewis/mathlib
3d16e3e6daf5ddde182473e03a1b601d2810952c
1d13f5b932f5e40a8308e3840f96fc882fae01f0
refs/heads/master
1,651,379,945,369
1,644,276,960,000
1,644,276,960,000
98,875,504
0
0
Apache-2.0
1,644,253,514,000
1,501,495,700,000
Lean
UTF-8
Lean
false
false
17,850
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 data.set.pairwise /-! # Chains and Zorn's lemmas This file defines chains for an arbitrary relation and proves several formulations of Zorn's Lemma, along with Hausdorff's Maximality Principle. ## Main declarations * `chain c`: A chain `c` is a set of comparable elements. * `max_chain_spec`: Hausdorff's Maximality Principle. * `exists_maximal_of_chains_bounded`: Zorn's Lemma. Many variants are offered. ## Variants The primary statement of Zorn's lemma is `exists_maximal_of_chains_bounded`. Then it is specialized to particular relations: * `(≤)` with `zorn_partial_order` * `(⊆)` with `zorn_subset` * `(⊇)` with `zorn_superset` Lemma names carry modifiers: * `₀`: Quantifies over a set, as opposed to over a type. * `_nonempty`: Doesn't ask to prove that the empty chain is bounded and lets you give an element that will be smaller than the maximal element found (the maximal element is no smaller than any other element, but it can also be incomparable to some). ## How-to This file comes across as confusing to those who haven't yet used it, so here is a detailed walkthrough: 1. Know what relation on which type/set you're looking for. See Variants above. You can discharge some conditions to Zorn's lemma directly using a `_nonempty` variant. 2. Write down the definition of your type/set, put a `suffices : ∃ m, ∀ a, m ≺ a → a ≺ m, { ... },` (or whatever you actually need) followed by a `apply some_version_of_zorn`. 3. Fill in the details. This is where you start talking about chains. A typical proof using Zorn could look like this ```lean lemma zorny_lemma : zorny_statement := begin let s : set α := {x | whatever x}, suffices : ∃ x ∈ s, ∀ y ∈ s, y ⊆ x → y = x, -- or with another operator { exact proof_post_zorn }, apply zorn.zorn_subset, -- or another variant rintro c hcs hc, obtain rfl | hcnemp := c.eq_empty_or_nonempty, -- you might need to disjunct on c empty or not { exact ⟨edge_case_construction, proof_that_edge_case_construction_respects_whatever, proof_that_edge_case_construction_contains_all_stuff_in_c⟩ }, exact ⟨construction, proof_that_construction_respects_whatever, proof_that_construction_contains_all_stuff_in_c⟩, end ``` ## Notes Originally ported from Isabelle/HOL. The [original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D. Fleuriot, Tobias Nipkow, Christian Sternagel. -/ noncomputable theory universes u open set classical open_locale classical namespace zorn section chain parameters {α : Type u} (r : α → α → Prop) local infix ` ≺ `:50 := r /-- A chain is a subset `c` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/ def chain (c : set α) := c.pairwise (λ x y, x ≺ y ∨ y ≺ x) parameters {r} lemma chain.total_of_refl [is_refl α r] {c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) : x ≺ y ∨ y ≺ x := if e : x = y then or.inl (e ▸ refl _) else H hx hy e lemma chain.mono {c c'} : c' ⊆ c → chain c → chain c' := set.pairwise.mono lemma chain_of_trichotomous [is_trichotomous α r] (s : set α) : chain s := begin intros a _ b _ hab, obtain h | h | h := @trichotomous _ r _ a b, { exact or.inl h }, { exact (hab h).elim }, { exact or.inr h } end lemma chain_univ_iff : chain (univ : set α) ↔ is_trichotomous α r := begin refine ⟨λ h, ⟨λ a b , _⟩, λ h, @chain_of_trichotomous _ _ h univ⟩, rw [or.left_comm, or_iff_not_imp_left], exact h trivial trivial, end lemma chain.directed_on [is_refl α r] {c} (H : chain c) : directed_on (≺) c := λ x hx y hy, match H.total_of_refl hx hy with | or.inl h := ⟨y, hy, h, refl _⟩ | or.inr h := ⟨x, hx, refl _, h⟩ end lemma chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀ b ∈ c, b ≠ a → a ≺ b ∨ b ≺ a) : chain (insert a c) := forall_insert_of_forall (λ x hx, forall_insert_of_forall (hc hx) (λ hneq, (ha x hx hneq).symm)) (forall_insert_of_forall (λ x hx hneq, ha x hx $ λ h', hneq h'.symm) (λ h, (h rfl).rec _)) /-- `super_chain c₁ c₂` means that `c₂` is a chain that strictly includes `c₁`. -/ def super_chain (c₁ c₂ : set α) : Prop := chain c₂ ∧ c₁ ⊂ c₂ /-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/ def is_max_chain (c : set α) := chain c ∧ ¬ (∃ c', super_chain c c') /-- Given a set `c`, if there exists a chain `c'` strictly including `c`, then `succ_chain c` is one of these chains. Otherwise it is `c`. -/ def succ_chain (c : set α) : set α := if h : ∃ c', chain c ∧ super_chain c c' then some h else c lemma succ_spec {c : set α} (h : ∃ c', chain c ∧ super_chain c c') : super_chain c (succ_chain c) := let ⟨c', hc'⟩ := h in have chain c ∧ super_chain c (some h), from @some_spec _ (λ c', chain c ∧ super_chain c c') _, by simp [succ_chain, dif_pos, h, this.right] lemma chain_succ {c : set α} (hc : chain c) : chain (succ_chain c) := if h : ∃ c', chain c ∧ super_chain c c' then (succ_spec h).left else by simp [succ_chain, dif_neg, h]; exact hc lemma super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) : super_chain c (succ_chain c) := begin simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂, cases hc₂.neg_resolve_left hc₁ with c' hc', exact succ_spec ⟨c', hc₁, hc'⟩ end lemma succ_increasing {c : set α} : c ⊆ succ_chain c := if h : ∃ c', chain c ∧ super_chain c c' then have super_chain c (succ_chain c), from succ_spec h, this.right.left else by simp [succ_chain, dif_neg, h, subset.refl] /-- Set of sets reachable from `∅` using `succ_chain` and `⋃₀`. -/ inductive chain_closure : set (set α) | succ : ∀ {s}, chain_closure s → chain_closure (succ_chain s) | union : ∀ {s}, (∀ a ∈ s, chain_closure a) → chain_closure (⋃₀ s) lemma chain_closure_empty : ∅ ∈ chain_closure := have chain_closure (⋃₀ ∅), from chain_closure.union $ λ a h, h.rec _, by simp at this; assumption lemma chain_closure_closure : ⋃₀ chain_closure ∈ chain_closure := chain_closure.union $ λ s hs, hs variables {c c₁ c₂ c₃ : set α} private lemma chain_closure_succ_total_aux (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) (h : ∀ {c₃}, c₃ ∈ chain_closure → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) : c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ := begin induction hc₁, case succ : c₃ hc₃ ih { cases ih with ih ih, { have h := h hc₃ ih, cases h with h h, { exact or.inr (h ▸ subset.refl _) }, { exact or.inl h } }, { exact or.inr (subset.trans ih succ_increasing) } }, case union : s hs ih { refine (or_iff_not_imp_right.2 $ λ hn, sUnion_subset $ λ a ha, _), apply (ih a ha).resolve_right, apply mt (λ h, _) hn, exact subset.trans h (subset_sUnion_of_mem ha) } end private lemma chain_closure_succ_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) (h : c₁ ⊆ c₂) : c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ := begin induction hc₂ generalizing c₁ hc₁ h, case succ : c₂ hc₂ ih { have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ := (chain_closure_succ_total_aux hc₁ hc₂ $ λ c₁, ih), cases h₁ with h₁ h₁, { have h₂ := ih hc₁ h₁, cases h₂ with h₂ h₂, { exact (or.inr $ h₂ ▸ subset.refl _) }, { exact (or.inr $ subset.trans h₂ succ_increasing) } }, { exact (or.inl $ subset.antisymm h₁ h) } }, case union : s hs ih { apply or.imp_left (λ h', subset.antisymm h' h), apply classical.by_contradiction, simp [not_or_distrib, sUnion_subset_iff, not_forall], intros c₃ hc₃ h₁ h₂, have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (λ c₄, ih _ hc₃), cases h with h h, { have h' := ih c₃ hc₃ hc₁ h, cases h' with h' h', { exact (h₁ $ h' ▸ subset.refl _) }, { exact (h₂ $ subset.trans h' $ subset_sUnion_of_mem hc₃) } }, { exact (h₁ $ subset.trans succ_increasing h) } } end lemma chain_closure_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) : c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ := or.imp_right succ_increasing.trans $ chain_closure_succ_total_aux hc₁ hc₂ $ λ c₃ hc₃, chain_closure_succ_total hc₃ hc₂ lemma chain_closure_succ_fixpoint (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) (h_eq : succ_chain c₂ = c₂) : c₁ ⊆ c₂ := begin induction hc₁, case succ : c₁ hc₁ h { exact or.elim (chain_closure_succ_total hc₁ hc₂ h) (λ h, h ▸ h_eq.symm ▸ subset.refl c₂) id }, case union : s hs ih { exact (sUnion_subset $ λ c₁ hc₁, ih c₁ hc₁) } end lemma chain_closure_succ_fixpoint_iff (hc : c ∈ chain_closure) : succ_chain c = c ↔ c = ⋃₀ chain_closure := ⟨λ h, (subset_sUnion_of_mem hc).antisymm (chain_closure_succ_fixpoint chain_closure_closure hc h), λ h, subset.antisymm (calc succ_chain c ⊆ ⋃₀{c : set α | c ∈ chain_closure} : subset_sUnion_of_mem $ chain_closure.succ hc ... = c : h.symm) succ_increasing⟩ lemma chain_chain_closure (hc : c ∈ chain_closure) : chain c := begin induction hc, case succ : c hc h { exact chain_succ h }, case union : s hs h { have h : ∀ c ∈ s, zorn.chain c := h, exact λ c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq, have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂), or.elim this (λ ht, h t₂ ht₂ (ht hc₁) hc₂ hneq) (λ ht, h t₁ ht₁ hc₁ (ht hc₂) hneq) } end lemma chain_empty : chain ∅ := chain_chain_closure chain_closure_empty lemma _root_.set.subsingleton.chain (hc : set.subsingleton c) : chain c := λ _ hx _ hy hne, (hne (hc hx hy)).elim /-- An explicit maximal chain. `max_chain` is taken to be the union of all sets in `chain_closure`. -/ def max_chain := ⋃₀ chain_closure /-- Hausdorff's maximality principle There exists a maximal totally ordered subset of `α`. Note that we do not require `α` to be partially ordered by `r`. -/ theorem max_chain_spec : is_max_chain max_chain := classical.by_contradiction $ λ h, begin obtain ⟨h₁, H⟩ := super_of_not_max (chain_chain_closure chain_closure_closure) h, obtain ⟨h₂, h₃⟩ := ssubset_iff_subset_ne.1 H, exact h₃ ((chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl).symm, end /-- Zorn's lemma If every chain has an upper bound, then there exists a maximal element. -/ theorem exists_maximal_of_chains_bounded (h : ∀ c, chain c → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := have ∃ ub, ∀ a ∈ max_chain, a ≺ ub, from h _ $ max_chain_spec.left, let ⟨ub, (hub : ∀ a ∈ max_chain, a ≺ ub)⟩ := this in ⟨ub, λ a ha, have chain (insert a max_chain), from chain_insert max_chain_spec.left $ λ b hb _, or.inr $ trans (hub b hb) ha, have a ∈ max_chain, from classical.by_contradiction $ λ h : a ∉ max_chain, max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩, hub a this⟩ /-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then there is a maximal element. -/ theorem exists_maximal_of_nonempty_chains_bounded [nonempty α] (h : ∀ c, chain c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub) (trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) : ∃ m, ∀ a, m ≺ a → a ≺ m := exists_maximal_of_chains_bounded (λ c hc, (eq_empty_or_nonempty c).elim (λ h, ⟨classical.arbitrary α, λ x hx, (h ▸ hx : x ∈ (∅ : set α)).elim⟩) (h c hc)) (λ a b c, trans) end chain --This lemma isn't under section `chain` because `parameters` messes up with it. Feel free to fix it /-- This can be used to turn `zorn.chain (≥)` into `zorn.chain (≤)` and vice-versa. -/ lemma chain.symm {α : Type u} {s : set α} {q : α → α → Prop} (h : chain q s) : chain (flip q) s := h.mono' (λ _ _, or.symm) theorem zorn_partial_order {α : Type u} [partial_order α] (h : ∀ c : set α, chain (≤) c → ∃ ub, ∀ a ∈ c, a ≤ ub) : ∃ m : α, ∀ a, m ≤ a → a = m := let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (λ a b c, le_trans) in ⟨m, λ a ha, le_antisymm (hm a ha) ha⟩ theorem zorn_nonempty_partial_order {α : Type u} [partial_order α] [nonempty α] (h : ∀ (c : set α), chain (≤) c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≤ ub) : ∃ (m : α), ∀ a, m ≤ a → a = m := let ⟨m, hm⟩ := @exists_maximal_of_nonempty_chains_bounded α (≤) _ h (λ a b c, le_trans) in ⟨m, λ a ha, le_antisymm (hm a ha) ha⟩ theorem zorn_partial_order₀ {α : Type u} [partial_order α] (s : set α) (ih : ∀ c ⊆ s, chain (≤) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) : ∃ m ∈ s, ∀ z ∈ s, m ≤ z → z = m := let ⟨⟨m, hms⟩, h⟩ := @zorn_partial_order {m // m ∈ s} _ (λ c hc, let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (λ _ ⟨⟨x, hx⟩, _, h⟩, h ▸ hx) (by { rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq; refine hc hpc hqc (λ t, hpq (subtype.ext_iff.1 t)) }) in ⟨⟨ub, hubs⟩, λ ⟨y, hy⟩ hc, hub _ ⟨_, hc, rfl⟩⟩) in ⟨m, hms, λ z hzs hmz, congr_arg subtype.val (h ⟨z, hzs⟩ hmz)⟩ theorem zorn_nonempty_partial_order₀ {α : Type u} [partial_order α] (s : set α) (ih : ∀ c ⊆ s, chain (≤) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α) (hxs : x ∈ s) : ∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m := let ⟨⟨m, hms, hxm⟩, h⟩ := @zorn_partial_order {m // m ∈ s ∧ x ≤ m} _ (λ c hc, c.eq_empty_or_nonempty.elim (λ hce, hce.symm ▸ ⟨⟨x, hxs, le_rfl⟩, λ _, false.elim⟩) (λ ⟨m, hmc⟩, let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (image_subset_iff.2 $ λ z hzc, z.2.1) (by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq; exact hc hpc hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in ⟨⟨ub, hubs, le_trans m.2.2 $ hub m.1 $ mem_image_of_mem _ hmc⟩, λ a hac, hub a.1 ⟨a, hac, rfl⟩⟩)) in ⟨m, hms, hxm, λ z hzs hmz, congr_arg subtype.val $ h ⟨z, hzs, le_trans hxm hmz⟩ hmz⟩ theorem zorn_subset {α : Type u} (S : set (set α)) (h : ∀ c ⊆ S, chain (⊆) c → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) : ∃ m ∈ S, ∀ a ∈ S, m ⊆ a → a = m := zorn_partial_order₀ S h theorem zorn_subset_nonempty {α : Type u} (S : set (set α)) (H : ∀ c ⊆ S, chain (⊆) c → c.nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) : ∃ m ∈ S, x ⊆ m ∧ ∀ a ∈ S, m ⊆ a → a = m := zorn_nonempty_partial_order₀ _ (λ c cS hc y yc, H _ cS hc ⟨y, yc⟩) _ hx theorem zorn_superset {α : Type u} (S : set (set α)) (h : ∀ c ⊆ S, chain (⊆) c → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) : ∃ m ∈ S, ∀ a ∈ S, a ⊆ m → a = m := @zorn_partial_order₀ (order_dual (set α)) _ S $ λ c cS hc, h c cS hc.symm theorem zorn_superset_nonempty {α : Type u} (S : set (set α)) (H : ∀ c ⊆ S, chain (⊆) c → c.nonempty → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) (x) (hx : x ∈ S) : ∃ m ∈ S, m ⊆ x ∧ ∀ a ∈ S, a ⊆ m → a = m := @zorn_nonempty_partial_order₀ (order_dual (set α)) _ S (λ c cS hc y yc, H _ cS hc.symm ⟨y, yc⟩) _ hx /-- Every chain is contained in a maximal chain. This generalizes Hausdorff's maximality principle. -/ theorem chain.max_chain_of_chain {α r} {c : set α} (hc : zorn.chain r c) : ∃ M, @zorn.is_max_chain _ r M ∧ c ⊆ M := begin obtain ⟨M, ⟨_, hM₀⟩, hM₁, hM₂⟩ := zorn.zorn_subset_nonempty {s | c ⊆ s ∧ zorn.chain r s} _ c ⟨subset.rfl, hc⟩, { refine ⟨M, ⟨hM₀, _⟩, hM₁⟩, rintro ⟨d, hd, hMd, hdM⟩, exact hdM (hM₂ _ ⟨hM₁.trans hMd, hd⟩ hMd).le }, rintros cs hcs₀ hcs₁ ⟨s, hs⟩, refine ⟨⋃₀ cs, ⟨λ _ ha, set.mem_sUnion_of_mem ((hcs₀ hs).left ha) hs, _⟩, λ _, set.subset_sUnion_of_mem⟩, rintros y ⟨sy, hsy, hysy⟩ z ⟨sz, hsz, hzsz⟩ hyz, obtain rfl | hsseq := eq_or_ne sy sz, { exact (hcs₀ hsy).right hysy hzsz hyz }, cases hcs₁ hsy hsz hsseq with h h, { exact (hcs₀ hsz).right (h hysy) hzsz hyz }, { exact (hcs₀ hsy).right hysy (h hzsz) hyz } end lemma chain.total {α : Type u} [preorder α] {c : set α} (H : chain (≤) c) : ∀ {x y}, x ∈ c → y ∈ c → x ≤ y ∨ y ≤ x := λ x y, H.total_of_refl lemma chain.image {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) (f : α → β) (h : ∀ x y, r x y → s (f x) (f y)) {c : set α} (hrc : chain r c) : chain s (f '' c) := λ x ⟨a, ha₁, ha₂⟩ y ⟨b, hb₁, hb₂⟩, ha₂ ▸ hb₂ ▸ λ hxy, (hrc ha₁ hb₁ $ ne_of_apply_ne f hxy).elim (or.inl ∘ h _ _) (or.inr ∘ h _ _) end zorn lemma directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α} (h : zorn.chain (f ⁻¹'o r) c) : directed r (λ x : {a : α // a ∈ c}, f x) := λ ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases (λ hab : a = b, by simp only [hab, exists_prop, and_self, subtype.exists]; exact ⟨b, hb, refl _⟩) (λ hab, (h ha hb hab).elim (λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩) (λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩))
91380ac9e502fbf5f1413d3841cd2c087d4b9212
0c1546a496eccfb56620165cad015f88d56190c5
/library/init/meta/fun_info.lean
e92dfdb0288a68096ea0605ef7d761b87a1f13bf
[ "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
3,715
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.meta.format init.function structure param_info := (is_implicit : bool) (is_inst_implicit : bool) (is_prop : bool) (has_fwd_deps : bool) (back_deps : list nat) -- previous parameters it depends on open format list decidable private meta def ppfield {α : Type} [has_to_format α] (fname : string) (v : α) : format := group $ to_fmt fname ++ space ++ to_fmt ":=" ++ space ++ nest (length fname + 4) (to_fmt v) private meta def concat_fields (f₁ f₂ : format) : format := if is_nil f₁ then f₂ else if is_nil f₂ then f₁ else f₁ ++ to_fmt "," ++ line ++ f₂ local infix `+++`:65 := concat_fields meta def param_info.to_format : param_info → format | (param_info.mk i ii p d ds) := group ∘ cbrace $ when i "implicit" +++ when ii "inst_implicit" +++ when p "prop" +++ when d "has_fwd_deps" +++ when (to_bool (length ds > 0)) (to_fmt "back_deps := " ++ to_fmt ds) meta instance : has_to_format param_info := has_to_format.mk param_info.to_format structure fun_info := (params : list param_info) (result_deps : list nat) -- parameters the result type depends on meta def fun_info_to_format : fun_info → format | (fun_info.mk ps ds) := group ∘ dcbrace $ ppfield "params" ps +++ ppfield "result_deps" ds meta instance : has_to_format fun_info := has_to_format.mk fun_info_to_format /- specialized is true if the result of fun_info has been specifialized using this argument. For example, consider the function f : Pi (α : Type), α -> α Now, suppse we request get_specialize fun_info for the application f unit a fun_info_manager returns two param_info objects: 1) specialized = true 2) is_subsingleton = true Note that, in general, the second argument of f is not a subsingleton, but it is in this particular case/specialization. \remark This bit is only set if it is a dependent parameter. Moreover, we only set is_specialized IF another parameter becomes a subsingleton -/ structure subsingleton_info := (specialized : bool) (is_subsingleton : bool) meta def subsingleton_info_to_format : subsingleton_info → format | (subsingleton_info.mk s ss) := group ∘ cbrace $ when s "specialized" +++ when ss "subsingleton" meta instance : has_to_format subsingleton_info := has_to_format.mk subsingleton_info_to_format namespace tactic /-- If nargs is not none, then return information assuming the function has only nargs arguments. -/ meta constant get_fun_info (f : expr) (nargs : option nat := none) (md := semireducible) : tactic fun_info meta constant get_subsingleton_info (f : expr) (nargs : option nat := none) (md := semireducible) : tactic (list subsingleton_info) /- (get_spec_subsingleton_info t) return subsingleton parameter information for the function application t of the form (f a_1 ... a_n). This tactic is more precise than (get_subsingleton_info f) and (get_subsingleton_info_n f n) Example: given (f : Pi (α : Type), α -> α), \c get_spec_subsingleton_info for f unit b returns a fun_info with two param_info 1) specialized = tt 2) is_subsingleton = tt The second argument is marked as subsingleton only because the resulting information is taking into account the first argument. -/ meta constant get_spec_subsingleton_info (t : expr) (md := semireducible) : tactic (list subsingleton_info) meta constant get_spec_prefix_size (t : expr) (nargs : nat) (md := semireducible) : tactic nat end tactic
4f31e29813c1a1e20ea9aca0f74a9ed75f6f6900
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/1851.lean
467833032bfd6b07deefe4512f1b599c8c5ded44
[ "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
270
lean
class Approx {α : Type} (a : α) (X : Type) : Type where val : X variable {α β X Y : Type} {f' : α → β} {x' : α} [f : Approx f' (X → Y)] [x : Approx x' X] -- fails #check f.val x.val -- works #check let f'' := f.val let x'' := x.val f'' x''
2c2097ed7781bdc534157287c44369f35a835e2c
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/monoidal/Bimod.lean
48b955f7b99b42d8a4403db69e19d8ac3290c907
[ "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
42,804
lean
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Oleksandr Manzyuk -/ import category_theory.bicategory.basic import category_theory.monoidal.Mon_ import category_theory.limits.preserves.shapes.equalizers /-! # The category of bimodule objects over a pair of monoid objects. > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. -/ universes v₁ v₂ u₁ u₂ open category_theory open category_theory.monoidal_category variables {C : Type u₁} [category.{v₁} C] [monoidal_category.{v₁} C] section open category_theory.limits variables [has_coequalizers C] section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] lemma id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W) (wh : (𝟙 Z ⊗ f) ≫ h = (𝟙 Z ⊗ g) ≫ h) : (𝟙 Z ⊗ coequalizer.π f g) ≫ (preserves_coequalizer.iso (tensor_left Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensor_left Z) f g h wh lemma id_tensor_π_preserves_coequalizer_inv_colim_map_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (𝟙 Z ⊗ f) ≫ q = p ≫ f') (wg : (𝟙 Z ⊗ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (𝟙 Z ⊗ coequalizer.π f g) ≫ (preserves_coequalizer.iso (tensor_left Z) f g).inv ≫ colim_map (parallel_pair_hom (𝟙 Z ⊗ f) (𝟙 Z ⊗ g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colim_map_desc (tensor_left Z) f g f' g' p q wf wg h wh end section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] lemma π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W) (wh : (f ⊗ 𝟙 Z) ≫ h = (g ⊗ 𝟙 Z) ≫ h) : (coequalizer.π f g ⊗ 𝟙 Z) ≫ (preserves_coequalizer.iso (tensor_right Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensor_right Z) f g h wh lemma π_tensor_id_preserves_coequalizer_inv_colim_map_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ⊗ 𝟙 Z) ≫ q = p ≫ f') (wg : (g ⊗ 𝟙 Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (coequalizer.π f g ⊗ 𝟙 Z) ≫ (preserves_coequalizer.iso (tensor_right Z) f g).inv ≫ colim_map (parallel_pair_hom (f ⊗ 𝟙 Z) (g ⊗ 𝟙 Z) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colim_map_desc (tensor_right Z) f g f' g' p q wf wg h wh end end /-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/ structure Bimod (A B : Mon_ C) := (X : C) (act_left : A.X ⊗ X ⟶ X) (one_act_left' : (A.one ⊗ 𝟙 X) ≫ act_left = (λ_ X).hom . obviously) (left_assoc' : (A.mul ⊗ 𝟙 X) ≫ act_left = (α_ A.X A.X X).hom ≫ (𝟙 A.X ⊗ act_left) ≫ act_left . obviously) (act_right : X ⊗ B.X ⟶ X) (act_right_one' : (𝟙 X ⊗ B.one) ≫ act_right = (ρ_ X).hom . obviously) (right_assoc' : (𝟙 X ⊗ B.mul) ≫ act_right = (α_ X B.X B.X).inv ≫ (act_right ⊗ 𝟙 B.X) ≫ act_right . obviously) (middle_assoc' : (act_left ⊗ 𝟙 B.X) ≫ act_right = (α_ A.X X B.X).hom ≫ (𝟙 A.X ⊗ act_right) ≫ act_left . obviously) restate_axiom Bimod.one_act_left' restate_axiom Bimod.act_right_one' restate_axiom Bimod.left_assoc' restate_axiom Bimod.right_assoc' restate_axiom Bimod.middle_assoc' attribute [simp, reassoc] Bimod.one_act_left Bimod.act_right_one Bimod.left_assoc Bimod.right_assoc Bimod.middle_assoc namespace Bimod variables {A B : Mon_ C} (M : Bimod A B) /-- A morphism of bimodule objects. -/ @[ext] structure hom (M N : Bimod A B) := (hom : M.X ⟶ N.X) (left_act_hom' : M.act_left ≫ hom = (𝟙 A.X ⊗ hom) ≫ N.act_left . obviously) (right_act_hom' : M.act_right ≫ hom = (hom ⊗ 𝟙 B.X) ≫ N.act_right . obviously) restate_axiom hom.left_act_hom' restate_axiom hom.right_act_hom' attribute [simp, reassoc] hom.left_act_hom hom.right_act_hom /-- The identity morphism on a bimodule object. -/ @[simps] def id' (M : Bimod A B) : hom M M := { hom := 𝟙 M.X, } instance hom_inhabited (M : Bimod A B) : inhabited (hom M M) := ⟨id' M⟩ /-- Composition of bimodule object morphisms. -/ @[simps] def comp {M N O : Bimod A B} (f : hom M N) (g : hom N O) : hom M O := { hom := f.hom ≫ g.hom, } instance : category (Bimod A B) := { hom := λ M N, hom M N, id := id', comp := λ M N O f g, comp f g, } @[simp] lemma id_hom' (M : Bimod A B) : (𝟙 M : hom M M).hom = 𝟙 M.X := rfl @[simp] lemma comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : hom M K).hom = f.hom ≫ g.hom := rfl /-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects and checking compatibility with left and right actions only in the forward direction. -/ @[simps] def iso_of_iso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X) (f_left_act_hom : P.act_left ≫ f.hom = (𝟙 X.X ⊗ f.hom) ≫ Q.act_left) (f_right_act_hom : P.act_right ≫ f.hom = (f.hom ⊗ 𝟙 Y.X) ≫ Q.act_right) : P ≅ Q := { hom := ⟨f.hom⟩, inv := { hom := f.inv, left_act_hom' := begin rw [←(cancel_mono f.hom), category.assoc, category.assoc, iso.inv_hom_id, category.comp_id, f_left_act_hom, ←category.assoc, ←id_tensor_comp, iso.inv_hom_id, monoidal_category.tensor_id, category.id_comp], end, right_act_hom' := begin rw [←(cancel_mono f.hom), category.assoc, category.assoc, iso.inv_hom_id, category.comp_id, f_right_act_hom, ←category.assoc, ←comp_tensor_id, iso.inv_hom_id, monoidal_category.tensor_id, category.id_comp], end }, hom_inv_id' := begin ext, dsimp, rw iso.hom_inv_id, end, inv_hom_id' := begin ext, dsimp, rw iso.inv_hom_id, end } variables (A) /-- A monoid object as a bimodule over itself. -/ @[simps] def regular : Bimod A A := { X := A.X, act_left := A.mul, act_right := A.mul, } instance : inhabited (Bimod A A) := ⟨regular A⟩ /-- The forgetful functor from bimodule objects to the ambient category. -/ def forget : Bimod A B ⥤ C := { obj := λ A, A.X, map := λ A B f, f.hom, } open category_theory.limits variables [has_coequalizers C] namespace tensor_Bimod variables {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T) /-- The underlying object of the tensor product of two bimodules. -/ noncomputable def X : C := coequalizer (P.act_right ⊗ 𝟙 Q.X) ((α_ _ _ _).hom ≫ (𝟙 P.X ⊗ Q.act_left)) section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] /-- Left action for the tensor product of two bimodules. -/ noncomputable def act_left : R.X ⊗ X P Q ⟶ X P Q := (preserves_coequalizer.iso (tensor_left R.X) _ _).inv ≫ colim_map (parallel_pair_hom _ _ _ _ ((𝟙 _ ⊗ (α_ _ _ _).hom) ≫ (α_ _ _ _).inv ≫ (P.act_left ⊗ 𝟙 S.X ⊗ 𝟙 Q.X) ≫ (α_ _ _ _).inv) ((α_ _ _ _).inv ≫ (P.act_left ⊗ 𝟙 Q.X)) begin dsimp, slice_lhs 1 2 { rw associator_inv_naturality }, slice_rhs 3 4 { rw associator_inv_naturality }, slice_rhs 4 5 { rw [←tensor_comp, middle_assoc, tensor_comp, comp_tensor_id] }, coherence, end begin dsimp, slice_lhs 1 1 { rw id_tensor_comp }, slice_lhs 2 3 { rw associator_inv_naturality }, slice_lhs 3 4 { rw [tensor_id, id_tensor_comp_tensor_id] }, slice_rhs 4 6 { rw iso.inv_hom_id_assoc }, slice_rhs 3 4 { rw [tensor_id, tensor_id_comp_id_tensor] }, end) lemma id_tensor_π_act_left : (𝟙 R.X ⊗ coequalizer.π _ _) ≫ act_left P Q = (α_ _ _ _).inv ≫ (P.act_left ⊗ 𝟙 Q.X) ≫ coequalizer.π _ _ := begin erw map_π_preserves_coequalizer_inv_colim_map (tensor_left _), simp only [category.assoc], end lemma one_act_left' : (R.one ⊗ 𝟙 _) ≫ act_left P Q = (λ_ _).hom := begin refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp [X], slice_lhs 1 2 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, slice_lhs 2 3 { rw id_tensor_π_act_left }, slice_lhs 1 2 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_lhs 2 3 { rw [←comp_tensor_id, one_act_left] }, slice_rhs 1 2 { rw left_unitor_naturality }, coherence, end lemma left_assoc' : (R.mul ⊗ 𝟙 _) ≫ act_left P Q = (α_ R.X R.X _).hom ≫ (𝟙 R.X ⊗ act_left P Q) ≫ act_left P Q := begin refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp [X], slice_lhs 1 2 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, slice_lhs 2 3 { rw id_tensor_π_act_left }, slice_lhs 1 2 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_lhs 2 3 { rw [←comp_tensor_id, left_assoc, comp_tensor_id, comp_tensor_id] }, slice_rhs 1 2 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_rhs 2 3 { rw [←id_tensor_comp, id_tensor_π_act_left, id_tensor_comp, id_tensor_comp] }, slice_rhs 4 5 { rw id_tensor_π_act_left }, slice_rhs 3 4 { rw associator_inv_naturality }, coherence, end end section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] /-- Right action for the tensor product of two bimodules. -/ noncomputable def act_right : X P Q ⊗ T.X ⟶ X P Q := (preserves_coequalizer.iso (tensor_right T.X) _ _).inv ≫ colim_map (parallel_pair_hom _ _ _ _ ((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (𝟙 P.X ⊗ 𝟙 S.X ⊗ Q.act_right) ≫ (α_ _ _ _).inv) ((α_ _ _ _).hom ≫ (𝟙 P.X ⊗ Q.act_right)) begin dsimp, slice_lhs 1 2 { rw associator_naturality }, slice_lhs 2 3 { rw [tensor_id, tensor_id_comp_id_tensor] }, slice_rhs 3 4 { rw associator_inv_naturality }, slice_rhs 2 4 { rw iso.hom_inv_id_assoc }, slice_rhs 2 3 { rw [tensor_id, id_tensor_comp_tensor_id] }, end begin dsimp, slice_lhs 1 1 { rw comp_tensor_id }, slice_lhs 2 3 { rw associator_naturality }, slice_lhs 3 4 { rw [←id_tensor_comp, middle_assoc, id_tensor_comp] }, slice_rhs 4 6 { rw iso.inv_hom_id_assoc }, slice_rhs 3 4 { rw ←id_tensor_comp }, coherence, end) lemma π_tensor_id_act_right : (coequalizer.π _ _ ⊗ 𝟙 T.X) ≫ act_right P Q = (α_ _ _ _).hom ≫ (𝟙 P.X ⊗ Q.act_right) ≫ coequalizer.π _ _ := begin erw map_π_preserves_coequalizer_inv_colim_map (tensor_right _), simp only [category.assoc], end lemma act_right_one' : (𝟙 _ ⊗ T.one) ≫ act_right P Q = (ρ_ _).hom := begin refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp [X], slice_lhs 1 2 { rw [tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_lhs 2 3 { rw π_tensor_id_act_right }, slice_lhs 1 2 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_lhs 2 3 { rw [←id_tensor_comp, act_right_one] }, slice_rhs 1 2 { rw right_unitor_naturality }, coherence, end lemma right_assoc' : (𝟙 _ ⊗ T.mul) ≫ act_right P Q = (α_ _ T.X T.X).inv ≫ (act_right P Q ⊗ 𝟙 T.X) ≫ act_right P Q := begin refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp [X], slice_lhs 1 2 { rw [tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_lhs 2 3 { rw π_tensor_id_act_right }, slice_lhs 1 2 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_lhs 2 3 { rw [←id_tensor_comp, right_assoc, id_tensor_comp, id_tensor_comp] }, slice_rhs 1 2 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_rhs 2 3 { rw [←comp_tensor_id, π_tensor_id_act_right, comp_tensor_id, comp_tensor_id] }, slice_rhs 4 5 { rw π_tensor_id_act_right }, slice_rhs 3 4 { rw associator_naturality }, coherence, end end section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] lemma middle_assoc' : (act_left P Q ⊗ 𝟙 T.X) ≫ act_right P Q = (α_ R.X _ T.X).hom ≫ (𝟙 R.X ⊗ act_right P Q) ≫ act_left P Q := begin refine (cancel_epi ((tensor_left _ ⋙ tensor_right _).map (coequalizer.π _ _))).1 _, dsimp [X], slice_lhs 1 2 { rw [←comp_tensor_id, id_tensor_π_act_left, comp_tensor_id, comp_tensor_id] }, slice_lhs 3 4 { rw π_tensor_id_act_right }, slice_lhs 2 3 { rw associator_naturality }, slice_lhs 3 4 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor] }, slice_rhs 1 2 { rw associator_naturality }, slice_rhs 2 3 { rw [←id_tensor_comp, π_tensor_id_act_right, id_tensor_comp, id_tensor_comp] }, slice_rhs 4 5 { rw id_tensor_π_act_left }, slice_rhs 3 4 { rw associator_inv_naturality }, slice_rhs 4 5 { rw [monoidal_category.tensor_id, id_tensor_comp_tensor_id] }, coherence, end end end tensor_Bimod section variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] /-- Tensor product of two bimodule objects as a bimodule object. -/ @[simps] noncomputable def tensor_Bimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z := { X := tensor_Bimod.X M N, act_left := tensor_Bimod.act_left M N, act_right := tensor_Bimod.act_right M N, one_act_left' := tensor_Bimod.one_act_left' M N, act_right_one' := tensor_Bimod.act_right_one' M N, left_assoc' := tensor_Bimod.left_assoc' M N, right_assoc' := tensor_Bimod.right_assoc' M N, middle_assoc' := tensor_Bimod.middle_assoc' M N, } /-- Tensor product of two morphisms of bimodule objects. -/ @[simps] noncomputable def tensor_hom {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} {N₁ N₂ : Bimod Y Z} (f : M₁ ⟶ M₂) (g : N₁ ⟶ N₂) : M₁.tensor_Bimod N₁ ⟶ M₂.tensor_Bimod N₂ := { hom := colim_map (parallel_pair_hom _ _ _ _ ((f.hom ⊗ 𝟙 Y.X) ⊗ g.hom) (f.hom ⊗ g.hom) (by rw [←tensor_comp, ←tensor_comp, hom.right_act_hom, category.id_comp, category.comp_id]) begin slice_lhs 2 3 { rw [←tensor_comp, hom.left_act_hom, category.id_comp] }, slice_rhs 1 2 { rw associator_naturality }, slice_rhs 2 3 { rw [←tensor_comp, category.comp_id] }, end), left_act_hom' := begin refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 2 { rw tensor_Bimod.id_tensor_π_act_left }, slice_lhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 2 3 { rw [←tensor_comp, hom.left_act_hom, category.id_comp] }, slice_rhs 1 2 { rw [←id_tensor_comp, ι_colim_map, parallel_pair_hom_app_one, id_tensor_comp] }, slice_rhs 2 3 { rw tensor_Bimod.id_tensor_π_act_left }, slice_rhs 1 2 { rw associator_inv_naturality }, slice_rhs 2 3 { rw [←tensor_comp, category.comp_id] }, end, right_act_hom' := begin refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 2 { rw tensor_Bimod.π_tensor_id_act_right }, slice_lhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 2 3 { rw [←tensor_comp, category.id_comp, hom.right_act_hom] }, slice_rhs 1 2 { rw [←comp_tensor_id, ι_colim_map, parallel_pair_hom_app_one, comp_tensor_id] }, slice_rhs 2 3 { rw tensor_Bimod.π_tensor_id_act_right }, slice_rhs 1 2 { rw associator_naturality }, slice_rhs 2 3 { rw [←tensor_comp, category.comp_id] }, end } lemma tensor_id {X Y Z : Mon_ C} {M : Bimod X Y} {N : Bimod Y Z} : tensor_hom (𝟙 M) (𝟙 N) = 𝟙 (M.tensor_Bimod N) := begin ext, simp only [id_hom', tensor_id, tensor_hom_hom, ι_colim_map, parallel_pair_hom_app_one], dsimp, dunfold tensor_Bimod.X, simp only [category.id_comp, category.comp_id], end lemma tensor_comp {X Y Z : Mon_ C} {M₁ M₂ M₃ : Bimod X Y} {N₁ N₂ N₃ : Bimod Y Z} (f₁ : M₁ ⟶ M₂) (f₂ : M₂ ⟶ M₃) (g₁ : N₁ ⟶ N₂) (g₂ : N₂ ⟶ N₃) : tensor_hom (f₁ ≫ f₂) (g₁ ≫ g₂) = tensor_hom f₁ g₁ ≫ tensor_hom f₂ g₂ := begin ext, simp only [comp_hom', tensor_comp, tensor_hom_hom, ι_colim_map, parallel_pair_hom_app_one, category.assoc, ι_colim_map_assoc] end end namespace associator_Bimod variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] variables {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U) /-- An auxiliary morphism for the definition of the underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def hom_aux : (P.tensor_Bimod Q).X ⊗ L.X ⟶ (P.tensor_Bimod (Q.tensor_Bimod L)).X := (preserves_coequalizer.iso (tensor_right L.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).hom ≫ (𝟙 P.X ⊗ (coequalizer.π _ _)) ≫ (coequalizer.π _ _)) begin dsimp, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw associator_naturality }, slice_lhs 2 3 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_lhs 3 4 { rw coequalizer.condition }, slice_lhs 2 3 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_lhs 3 4 { rw [←id_tensor_comp, tensor_Bimod.id_tensor_π_act_left, id_tensor_comp] }, slice_rhs 1 1 { rw comp_tensor_id }, slice_rhs 2 3 { rw associator_naturality }, slice_rhs 3 4 { rw ←id_tensor_comp }, coherence, end /-- The underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def hom : ((P.tensor_Bimod Q).tensor_Bimod L).X ⟶ (P.tensor_Bimod (Q.tensor_Bimod L)).X := coequalizer.desc (hom_aux P Q L) begin dsimp [hom_aux], refine (cancel_epi ((tensor_right _ ⋙ tensor_right _).map (coequalizer.π _ _))).1 _, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw [←comp_tensor_id, tensor_Bimod.π_tensor_id_act_right, comp_tensor_id, comp_tensor_id] }, slice_lhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 2 3 { rw associator_naturality }, slice_lhs 3 4 { rw [←id_tensor_comp, coequalizer.condition, id_tensor_comp, id_tensor_comp] }, slice_rhs 1 2 { rw associator_naturality }, slice_rhs 2 3 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_rhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 2 3 { rw [←monoidal_category.tensor_id, associator_naturality] }, coherence, end lemma hom_left_act_hom' : ((P.tensor_Bimod Q).tensor_Bimod L).act_left ≫ hom P Q L = (𝟙 R.X ⊗ hom P Q L) ≫ (P.tensor_Bimod (Q.tensor_Bimod L)).act_left := begin dsimp, dsimp [hom, hom_aux], refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, rw tensor_left_map, slice_lhs 1 2 { rw tensor_Bimod.id_tensor_π_act_left }, slice_lhs 3 4 { rw coequalizer.π_desc }, slice_rhs 1 2 { rw [←id_tensor_comp, coequalizer.π_desc, id_tensor_comp] }, refine (cancel_epi ((tensor_right _ ⋙ tensor_left _).map (coequalizer.π _ _))).1 _, dsimp, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw associator_inv_naturality }, slice_lhs 2 3 { rw [←comp_tensor_id, tensor_Bimod.id_tensor_π_act_left, comp_tensor_id, comp_tensor_id] }, slice_lhs 4 6 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 3 4 { rw associator_naturality }, slice_lhs 4 5 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor] }, slice_rhs 1 3 { rw [←id_tensor_comp, ←id_tensor_comp, π_tensor_id_preserves_coequalizer_inv_desc, id_tensor_comp, id_tensor_comp] }, slice_rhs 3 4 { erw tensor_Bimod.id_tensor_π_act_left P (Q.tensor_Bimod L) }, slice_rhs 2 3 { erw associator_inv_naturality }, slice_rhs 3 4 { erw [monoidal_category.tensor_id, id_tensor_comp_tensor_id] }, coherence, end lemma hom_right_act_hom' : ((P.tensor_Bimod Q).tensor_Bimod L).act_right ≫ hom P Q L = (hom P Q L ⊗ 𝟙 U.X) ≫ (P.tensor_Bimod (Q.tensor_Bimod L)).act_right := begin dsimp, dsimp [hom, hom_aux], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, rw tensor_right_map, slice_lhs 1 2 { rw tensor_Bimod.π_tensor_id_act_right }, slice_lhs 3 4 { rw coequalizer.π_desc }, slice_rhs 1 2 { rw [←comp_tensor_id, coequalizer.π_desc, comp_tensor_id] }, refine (cancel_epi ((tensor_right _ ⋙ tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw associator_naturality }, slice_lhs 2 3 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_lhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 2 3 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_rhs 1 3 { rw [←comp_tensor_id, ←comp_tensor_id, π_tensor_id_preserves_coequalizer_inv_desc, comp_tensor_id, comp_tensor_id] }, slice_rhs 3 4 { erw tensor_Bimod.π_tensor_id_act_right P (Q.tensor_Bimod L) }, slice_rhs 2 3 { erw associator_naturality }, dsimp, slice_rhs 3 4 { rw [←id_tensor_comp, tensor_Bimod.π_tensor_id_act_right, id_tensor_comp, id_tensor_comp] }, coherence, end /-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def inv_aux : P.X ⊗ (Q.tensor_Bimod L).X ⟶ ((P.tensor_Bimod Q).tensor_Bimod L).X := (preserves_coequalizer.iso (tensor_left P.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).inv ≫ ((coequalizer.π _ _) ⊗ 𝟙 L.X) ≫ (coequalizer.π _ _)) begin dsimp, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw associator_inv_naturality }, rw [←(iso.inv_hom_id_assoc (α_ _ _ _) (𝟙 P.X ⊗ Q.act_right)), comp_tensor_id], slice_lhs 3 4 { rw [←comp_tensor_id, category.assoc, ←tensor_Bimod.π_tensor_id_act_right, comp_tensor_id] }, slice_lhs 4 5 { rw coequalizer.condition }, slice_lhs 3 4 { rw associator_naturality }, slice_lhs 4 5 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor] }, slice_rhs 1 2 { rw id_tensor_comp }, slice_rhs 2 3 { rw associator_inv_naturality }, slice_rhs 3 4 { rw [monoidal_category.tensor_id, id_tensor_comp_tensor_id] }, coherence, end /-- The underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def inv : (P.tensor_Bimod (Q.tensor_Bimod L)).X ⟶ ((P.tensor_Bimod Q).tensor_Bimod L).X := coequalizer.desc (inv_aux P Q L) begin dsimp [inv_aux], refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp [tensor_Bimod.X], slice_lhs 1 2 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, slice_lhs 2 4 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_lhs 1 2 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_lhs 2 3 { rw [←comp_tensor_id, coequalizer.condition, comp_tensor_id, comp_tensor_id] }, slice_rhs 1 2 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_rhs 2 3 { rw [←id_tensor_comp, tensor_Bimod.id_tensor_π_act_left, id_tensor_comp, id_tensor_comp] }, slice_rhs 4 6 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_rhs 3 4 { rw associator_inv_naturality }, coherence, end lemma hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := begin dsimp [hom, hom_aux, inv, inv_aux], ext, slice_lhs 1 2 { rw coequalizer.π_desc }, refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, rw tensor_right_map, slice_lhs 1 3 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 3 4 { rw coequalizer.π_desc }, slice_lhs 2 4 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_lhs 1 3 { rw iso.hom_inv_id_assoc }, dunfold tensor_Bimod.X, slice_rhs 2 3 { rw category.comp_id }, refl, end lemma inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := begin dsimp [hom, hom_aux, inv, inv_aux], ext, slice_lhs 1 2 { rw coequalizer.π_desc }, refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, rw tensor_left_map, slice_lhs 1 3 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_lhs 3 4 { rw coequalizer.π_desc }, slice_lhs 2 4 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 1 3 { rw iso.inv_hom_id_assoc }, dunfold tensor_Bimod.X, slice_rhs 2 3 { rw category.comp_id }, refl, end end associator_Bimod namespace left_unitor_Bimod variables {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the left unitor isomorphism. -/ noncomputable def hom : tensor_Bimod.X (regular R) P ⟶ P.X := coequalizer.desc P.act_left (by { dsimp, rw [category.assoc, left_assoc] }) /-- The underlying morphism of the inverse component of the left unitor isomorphism. -/ noncomputable def inv : P.X ⟶ tensor_Bimod.X (regular R) P := (λ_ P.X).inv ≫ (R.one ⊗ 𝟙 _) ≫ coequalizer.π _ _ lemma hom_inv_id : hom P ≫ inv P = 𝟙 _ := begin dunfold hom inv tensor_Bimod.X, ext, dsimp, slice_lhs 1 2 { rw coequalizer.π_desc }, slice_lhs 1 2 { rw left_unitor_inv_naturality }, slice_lhs 2 3 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, slice_lhs 3 3 { rw ←(iso.inv_hom_id_assoc (α_ R.X R.X P.X) (𝟙 R.X ⊗ P.act_left)) }, slice_lhs 4 6 { rw [←category.assoc, ←coequalizer.condition] }, slice_lhs 2 3 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_lhs 3 4 { rw [←comp_tensor_id, Mon_.one_mul] }, slice_rhs 1 2 { rw category.comp_id }, coherence, end lemma inv_hom_id : inv P ≫ hom P = 𝟙 _ := begin dsimp [hom, inv], slice_lhs 3 4 { rw coequalizer.π_desc }, rw [one_act_left, iso.inv_hom_id], end variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] lemma hom_left_act_hom' : ((regular R).tensor_Bimod P).act_left ≫ hom P = (𝟙 R.X ⊗ hom P) ≫ P.act_left := begin dsimp, dsimp [hom, tensor_Bimod.act_left, regular], refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 4 { rw id_tensor_π_preserves_coequalizer_inv_colim_map_desc }, slice_lhs 2 3 { rw left_assoc }, slice_rhs 1 2 { rw [←id_tensor_comp, coequalizer.π_desc] }, rw iso.inv_hom_id_assoc, end lemma hom_right_act_hom' : ((regular R).tensor_Bimod P).act_right ≫ hom P = (hom P ⊗ 𝟙 S.X) ≫ P.act_right := begin dsimp, dsimp [hom, tensor_Bimod.act_right, regular], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 4 { rw π_tensor_id_preserves_coequalizer_inv_colim_map_desc }, slice_rhs 1 2 { rw [←comp_tensor_id, coequalizer.π_desc] }, slice_rhs 1 2 { rw middle_assoc }, simp only [category.assoc], end end left_unitor_Bimod namespace right_unitor_Bimod variables {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the right unitor isomorphism. -/ noncomputable def hom : tensor_Bimod.X P (regular S) ⟶ P.X := coequalizer.desc P.act_right (by { dsimp, rw [category.assoc, right_assoc, iso.hom_inv_id_assoc] }) /-- The underlying morphism of the inverse component of the right unitor isomorphism. -/ noncomputable def inv : P.X ⟶ tensor_Bimod.X P (regular S) := (ρ_ P.X).inv ≫ (𝟙 _ ⊗ S.one) ≫ coequalizer.π _ _ lemma hom_inv_id : hom P ≫ inv P = 𝟙 _ := begin dunfold hom inv tensor_Bimod.X, ext, dsimp, slice_lhs 1 2 { rw coequalizer.π_desc }, slice_lhs 1 2 { rw right_unitor_inv_naturality }, slice_lhs 2 3 { rw [tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_lhs 3 4 { rw coequalizer.condition }, slice_lhs 2 3 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_lhs 3 4 { rw [←id_tensor_comp, Mon_.mul_one] }, slice_rhs 1 2 { rw category.comp_id }, coherence, end lemma inv_hom_id : inv P ≫ hom P = 𝟙 _ := begin dsimp [hom, inv], slice_lhs 3 4 { rw coequalizer.π_desc }, rw [act_right_one, iso.inv_hom_id], end variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] lemma hom_left_act_hom' : (P.tensor_Bimod (regular S)).act_left ≫ hom P = (𝟙 R.X ⊗ hom P) ≫ P.act_left := begin dsimp, dsimp [hom, tensor_Bimod.act_left, regular], refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 4 { rw id_tensor_π_preserves_coequalizer_inv_colim_map_desc }, slice_lhs 2 3 { rw middle_assoc }, slice_rhs 1 2 { rw [←id_tensor_comp, coequalizer.π_desc] }, rw iso.inv_hom_id_assoc, end lemma hom_right_act_hom' : (P.tensor_Bimod (regular S)).act_right ≫ hom P = (hom P ⊗ 𝟙 S.X) ≫ P.act_right := begin dsimp, dsimp [hom, tensor_Bimod.act_right, regular], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 4 { rw π_tensor_id_preserves_coequalizer_inv_colim_map_desc }, slice_lhs 2 3 { rw right_assoc }, slice_rhs 1 2 { rw [←comp_tensor_id, coequalizer.π_desc] }, rw iso.hom_inv_id_assoc, end end right_unitor_Bimod variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_left X)] variables [∀ X : C, preserves_colimits_of_size.{0 0} (tensor_right X)] /-- The associator as a bimodule isomorphism. -/ noncomputable def associator_Bimod {W X Y Z : Mon_ C} (L : Bimod W X) (M : Bimod X Y) (N : Bimod Y Z) : (L.tensor_Bimod M).tensor_Bimod N ≅ L.tensor_Bimod (M.tensor_Bimod N) := iso_of_iso { hom := associator_Bimod.hom L M N, inv := associator_Bimod.inv L M N, hom_inv_id' := associator_Bimod.hom_inv_id L M N, inv_hom_id' := associator_Bimod.inv_hom_id L M N } (associator_Bimod.hom_left_act_hom' L M N) (associator_Bimod.hom_right_act_hom' L M N) /-- The left unitor as a bimodule isomorphism. -/ noncomputable def left_unitor_Bimod {X Y : Mon_ C} (M : Bimod X Y) : (regular X).tensor_Bimod M ≅ M := iso_of_iso { hom := left_unitor_Bimod.hom M, inv := left_unitor_Bimod.inv M, hom_inv_id' := left_unitor_Bimod.hom_inv_id M, inv_hom_id' := left_unitor_Bimod.inv_hom_id M } (left_unitor_Bimod.hom_left_act_hom' M) (left_unitor_Bimod.hom_right_act_hom' M) /-- The right unitor as a bimodule isomorphism. -/ noncomputable def right_unitor_Bimod {X Y : Mon_ C} (M : Bimod X Y) : M.tensor_Bimod (regular Y) ≅ M := iso_of_iso { hom := right_unitor_Bimod.hom M, inv := right_unitor_Bimod.inv M, hom_inv_id' := right_unitor_Bimod.hom_inv_id M, inv_hom_id' := right_unitor_Bimod.inv_hom_id M } (right_unitor_Bimod.hom_left_act_hom' M) (right_unitor_Bimod.hom_right_act_hom' M) lemma whisker_left_comp_Bimod {X Y Z : Mon_ C} (M : Bimod X Y) {N P Q : Bimod Y Z} (f : N ⟶ P) (g : P ⟶ Q) : tensor_hom (𝟙 M) (f ≫ g) = tensor_hom (𝟙 M) f ≫ tensor_hom (𝟙 M) g := by rw [←tensor_comp, category.comp_id] lemma id_whisker_left_Bimod {X Y : Mon_ C} {M N : Bimod X Y} (f : M ⟶ N) : tensor_hom (𝟙 (regular X)) f = (left_unitor_Bimod M).hom ≫ f ≫ (left_unitor_Bimod N).inv := begin dsimp [tensor_hom, regular, left_unitor_Bimod], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [left_unitor_Bimod.hom], slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [left_unitor_Bimod.inv], slice_rhs 1 2 { rw hom.left_act_hom }, slice_rhs 2 3 { rw left_unitor_inv_naturality }, slice_rhs 3 4 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, slice_rhs 4 4 { rw ←(iso.inv_hom_id_assoc (α_ X.X X.X N.X) (𝟙 X.X ⊗ N.act_left)) }, slice_rhs 5 7 { rw [←category.assoc, ←coequalizer.condition] }, slice_rhs 3 4 { rw [←monoidal_category.tensor_id, associator_inv_naturality] }, slice_rhs 4 5 { rw [←comp_tensor_id, Mon_.one_mul] }, have : (λ_ (X.X ⊗ N.X)).inv ≫ (α_ (𝟙_ C) X.X N.X).inv ≫ ((λ_ X.X).hom ⊗ 𝟙 N.X) = 𝟙 _ := by pure_coherence, slice_rhs 2 4 { rw this }, slice_rhs 1 2 { rw category.comp_id }, end lemma comp_whisker_left_Bimod {W X Y Z : Mon_ C} (M : Bimod W X) (N : Bimod X Y) {P P' : Bimod Y Z} (f : P ⟶ P') : tensor_hom (𝟙 (M.tensor_Bimod N)) f = (associator_Bimod M N P).hom ≫ tensor_hom (𝟙 M) (tensor_hom (𝟙 N) f) ≫ (associator_Bimod M N P').inv := begin dsimp [tensor_hom, tensor_Bimod, associator_Bimod], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [tensor_Bimod.X, associator_Bimod.hom], slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [associator_Bimod.hom_aux, associator_Bimod.inv], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, rw tensor_right_map, slice_rhs 1 3 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 2 3 { rw [←id_tensor_comp, ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 3 4 { rw coequalizer.π_desc }, dsimp [associator_Bimod.inv_aux], slice_rhs 2 2 { rw id_tensor_comp }, slice_rhs 3 5 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_rhs 2 3 { rw associator_inv_naturality }, slice_rhs 1 3 { rw [iso.hom_inv_id_assoc, monoidal_category.tensor_id] }, slice_lhs 1 2 { rw [tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, dunfold tensor_Bimod.X, simp only [category.assoc], end lemma comp_whisker_right_Bimod {X Y Z : Mon_ C} {M N P : Bimod X Y} (f : M ⟶ N) (g : N ⟶ P) (Q : Bimod Y Z) : tensor_hom (f ≫ g) (𝟙 Q) = tensor_hom f (𝟙 Q) ≫ tensor_hom g (𝟙 Q) := by rw [←tensor_comp, category.comp_id] lemma whisker_right_id_Bimod {X Y : Mon_ C} {M N : Bimod X Y} (f : M ⟶ N) : tensor_hom f (𝟙 (regular Y)) = (right_unitor_Bimod M).hom ≫ f ≫ (right_unitor_Bimod N).inv := begin dsimp [tensor_hom, regular, right_unitor_Bimod], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [right_unitor_Bimod.hom], slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [right_unitor_Bimod.inv], slice_rhs 1 2 { rw hom.right_act_hom }, slice_rhs 2 3 { rw right_unitor_inv_naturality }, slice_rhs 3 4 { rw [tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_rhs 4 5 { rw coequalizer.condition }, slice_rhs 3 4 { rw [←monoidal_category.tensor_id, associator_naturality] }, slice_rhs 4 5 { rw [←id_tensor_comp, Mon_.mul_one] }, have : (ρ_ (N.X ⊗ Y.X)).inv ≫ (α_ N.X Y.X (𝟙_ C)).hom ≫ (𝟙 N.X ⊗ (ρ_ Y.X).hom) = 𝟙 _ := by pure_coherence, slice_rhs 2 4 { rw this }, slice_rhs 1 2 { rw category.comp_id }, end lemma whisker_right_comp_Bimod {W X Y Z : Mon_ C} {M M' : Bimod W X} (f : M ⟶ M') (N : Bimod X Y) (P : Bimod Y Z) : tensor_hom f (𝟙 (N.tensor_Bimod P)) = (associator_Bimod M N P).inv ≫ tensor_hom (tensor_hom f (𝟙 N)) (𝟙 P) ≫ (associator_Bimod M' N P).hom := begin dsimp [tensor_hom, tensor_Bimod, associator_Bimod], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [tensor_Bimod.X, associator_Bimod.inv], slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [associator_Bimod.inv_aux, associator_Bimod.hom], refine (cancel_epi ((tensor_left _).map (coequalizer.π _ _))).1 _, rw tensor_left_map, slice_rhs 1 3 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_rhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 2 3 { rw [←comp_tensor_id, ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 3 4 { rw coequalizer.π_desc }, dsimp [associator_Bimod.hom_aux], slice_rhs 2 2 { rw comp_tensor_id }, slice_rhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 2 3 { rw associator_naturality }, slice_rhs 1 3 { rw [iso.inv_hom_id_assoc, monoidal_category.tensor_id] }, slice_lhs 1 2 { rw [id_tensor_comp_tensor_id, ←tensor_id_comp_id_tensor] }, dunfold tensor_Bimod.X, simp only [category.assoc], end lemma whisker_assoc_Bimod {W X Y Z : Mon_ C} (M : Bimod W X) {N N' : Bimod X Y} (f : N ⟶ N') (P : Bimod Y Z) : tensor_hom (tensor_hom (𝟙 M) f) (𝟙 P) = (associator_Bimod M N P).hom ≫ tensor_hom (𝟙 M) (tensor_hom f (𝟙 P)) ≫ (associator_Bimod M N' P).inv := begin dsimp [tensor_hom, tensor_Bimod, associator_Bimod], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [associator_Bimod.hom], slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [associator_Bimod.hom_aux], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, rw tensor_right_map, slice_lhs 1 2 { rw [←comp_tensor_id, ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 1 3 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 2 3 { rw [←id_tensor_comp, ι_colim_map, parallel_pair_hom_app_one] }, dsimp [associator_Bimod.inv], slice_rhs 3 4 { rw coequalizer.π_desc }, dsimp [associator_Bimod.inv_aux], slice_rhs 2 2 { rw id_tensor_comp }, slice_rhs 3 5 { rw id_tensor_π_preserves_coequalizer_inv_desc }, slice_rhs 2 3 { rw associator_inv_naturality }, slice_rhs 1 3 { rw iso.hom_inv_id_assoc }, slice_lhs 1 1 { rw comp_tensor_id }, end lemma whisker_exchange_Bimod {X Y Z : Mon_ C} {M N : Bimod X Y} {P Q : Bimod Y Z} (f : M ⟶ N) (g : P ⟶ Q) : tensor_hom (𝟙 M) g ≫ tensor_hom f (𝟙 Q) = tensor_hom f (𝟙 P) ≫ tensor_hom (𝟙 N) g := begin dsimp [tensor_hom], ext, dsimp, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 2 3 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 1 2 { rw id_tensor_comp_tensor_id }, slice_rhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 2 3 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_rhs 1 2 { rw tensor_id_comp_id_tensor }, end lemma pentagon_Bimod {V W X Y Z : Mon_ C} (M : Bimod V W) (N : Bimod W X) (P : Bimod X Y) (Q : Bimod Y Z) : tensor_hom (associator_Bimod M N P).hom (𝟙 Q) ≫ (associator_Bimod M (N.tensor_Bimod P) Q).hom ≫ tensor_hom (𝟙 M) (associator_Bimod N P Q).hom = (associator_Bimod (M.tensor_Bimod N) P Q).hom ≫ (associator_Bimod M N (P.tensor_Bimod Q)).hom := begin dsimp [tensor_hom, associator_Bimod], ext, dsimp, dunfold associator_Bimod.hom, slice_lhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 2 3 { rw coequalizer.π_desc }, slice_rhs 1 2 { rw coequalizer.π_desc }, dsimp [associator_Bimod.hom_aux], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 2 { rw [←comp_tensor_id, coequalizer.π_desc] }, slice_rhs 1 3 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 3 4 { rw coequalizer.π_desc }, refine (cancel_epi ((tensor_right _ ⋙ tensor_right _).map (coequalizer.π _ _))).1 _, dsimp, slice_lhs 1 2 { rw [←comp_tensor_id, π_tensor_id_preserves_coequalizer_inv_desc, comp_tensor_id, comp_tensor_id ]}, slice_lhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, dunfold tensor_Bimod.X, slice_lhs 2 3 { rw associator_naturality }, slice_lhs 5 6 { rw [ι_colim_map, parallel_pair_hom_app_one] }, slice_lhs 4 5 { rw [←id_tensor_comp, coequalizer.π_desc] }, slice_lhs 3 4 { rw [←id_tensor_comp, π_tensor_id_preserves_coequalizer_inv_desc, id_tensor_comp, id_tensor_comp] }, slice_rhs 1 2 { rw associator_naturality }, slice_rhs 2 3 { rw [monoidal_category.tensor_id, tensor_id_comp_id_tensor, ←id_tensor_comp_tensor_id] }, slice_rhs 3 5 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_rhs 2 3 { rw [←monoidal_category.tensor_id, associator_naturality] }, coherence, end lemma triangle_Bimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : (associator_Bimod M (regular Y) N).hom ≫ tensor_hom (𝟙 M) (left_unitor_Bimod N).hom = tensor_hom (right_unitor_Bimod M).hom (𝟙 N) := begin dsimp [tensor_hom, associator_Bimod, left_unitor_Bimod, right_unitor_Bimod], ext, dsimp, dsimp [associator_Bimod.hom], slice_lhs 1 2 { rw coequalizer.π_desc }, dsimp [associator_Bimod.hom_aux], slice_rhs 1 2 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [right_unitor_Bimod.hom], refine (cancel_epi ((tensor_right _).map (coequalizer.π _ _))).1 _, dsimp [regular], slice_lhs 1 3 { rw π_tensor_id_preserves_coequalizer_inv_desc }, slice_lhs 3 4 { rw [ι_colim_map, parallel_pair_hom_app_one] }, dsimp [left_unitor_Bimod.hom], slice_lhs 2 3 { rw [←id_tensor_comp, coequalizer.π_desc] }, slice_rhs 1 2 { rw [←comp_tensor_id, coequalizer.π_desc] }, slice_rhs 1 2 { rw coequalizer.condition }, simp only [category.assoc], end /-- The bicategory of algebras (monoids) and bimodules, all internal to some monoidal category. -/ noncomputable def Mon_bicategory : bicategory (Mon_ C) := { hom := λ X Y, Bimod X Y, id := λ X, regular X, comp := λ _ _ _ M N, tensor_Bimod M N, whisker_left := λ _ _ _ L _ _ f, tensor_hom (𝟙 L) f, whisker_right := λ _ _ _ _ _ f N, tensor_hom f (𝟙 N), associator := λ _ _ _ _ L M N, associator_Bimod L M N, left_unitor := λ _ _ M, left_unitor_Bimod M, right_unitor := λ _ _ M, right_unitor_Bimod M, whisker_left_id' := λ _ _ _ _ _, tensor_id, whisker_left_comp' := λ _ _ _ M _ _ _ f g, whisker_left_comp_Bimod M f g, id_whisker_left' := λ _ _ _ _ f, id_whisker_left_Bimod f, comp_whisker_left' := λ _ _ _ _ M N _ _ f, comp_whisker_left_Bimod M N f, id_whisker_right' := λ _ _ _ _ _, tensor_id, comp_whisker_right' := λ _ _ _ _ _ _ f g Q, comp_whisker_right_Bimod f g Q, whisker_right_id' := λ _ _ _ _ f, whisker_right_id_Bimod f, whisker_right_comp' := λ _ _ _ _ _ _ f N P, whisker_right_comp_Bimod f N P, whisker_assoc' := λ _ _ _ _ M _ _ f P, whisker_assoc_Bimod M f P, whisker_exchange' := λ _ _ _ _ _ _ _ f g, whisker_exchange_Bimod f g, pentagon' := λ _ _ _ _ _ M N P Q, pentagon_Bimod M N P Q, triangle' := λ _ _ _ M N, triangle_Bimod M N } end Bimod
f11e9a10f7b57fa3e56021d7877bd6bccb8ab1aa
7cef822f3b952965621309e88eadf618da0c8ae9
/src/algebra/group/units_hom.lean
44881d7eb409c5aaa8a601e2065258ea63f8f0d1
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
1,599
lean
/- Copyright (c) 2018 Johan Commelin All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Chris Hughes, Kevin Buzzard Lift monoid homomorphisms to group homomorphisms of their units subgroups. -/ import algebra.group.units algebra.group.hom universes u v w namespace units variables {α : Type u} {β : Type v} {γ : Type w} [monoid α] [monoid β] [monoid γ] def map (f : α →* β) : units α →* units β := monoid_hom.mk' (λ u, ⟨f u.val, f u.inv, by rw [← f.map_mul, u.val_inv, f.map_one], by rw [← f.map_mul, u.inv_val, f.map_one]⟩) (λ x y, ext (f.map_mul x y)) /-- The group homomorphism on units induced by a multiplicative morphism. -/ @[reducible] def map' (f : α → β) [is_monoid_hom f] : units α →* units β := map (monoid_hom.of f) @[simp] lemma coe_map (f : α →* β) (x : units α) : ↑(map f x) = f x := rfl @[simp] lemma coe_map' (f : α → β) [is_monoid_hom f] (x : units α) : ↑((map' f : units α → units β) x) = f x := rfl @[simp] lemma map_comp (f : α →* β) (g : β →* γ) : map (g.comp f) = (map g).comp (map f) := rfl variables (α) @[simp] lemma map_id : map (monoid_hom.id α) = monoid_hom.id (units α) := by ext; refl /-- Coercion `units α → α` as a monoid homomorphism. -/ def coe_hom : units α →* α := ⟨coe, coe_one, coe_mul⟩ @[simp] lemma coe_hom_apply (x : units α) : coe_hom α x = ↑x := rfl instance coe_is_monoid_hom : is_monoid_hom (coe : units α → α) := (coe_hom α).is_monoid_hom end units
671bfe6488b931a52f310014e53c349bffb7c083
80cc5bf14c8ea85ff340d1d747a127dcadeb966f
/src/data/polynomial/derivative.lean
adc93eb68e89ff443bd759aeee27b7e3bd4fc110
[ "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
10,172
lean
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import data.polynomial.eval /-! # Theory of univariate polynomials -/ noncomputable theory local attribute [instance, priority 100] classical.prop_decidable open finsupp finset open_locale big_operators namespace polynomial universes u v w y z variables {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {A : Type z} {a b : R} {n : ℕ} section derivative section semiring variables [semiring R] /-- `derivative p` is the formal derivative of the polynomial `p` -/ def derivative (p : polynomial R) : polynomial R := p.sum (λn a, C (a * n) * X^(n - 1)) lemma coeff_derivative (p : polynomial R) (n : ℕ) : coeff (derivative p) n = coeff p (n + 1) * (n + 1) := begin rw [derivative], simp only [coeff_X_pow, coeff_sum, coeff_C_mul], rw [finsupp.sum, finset.sum_eq_single (n + 1)], simp only [nat.add_succ_sub_one, add_zero, mul_one, if_true, eq_self_iff_true], norm_cast, swap, { rw [if_pos (nat.add_sub_cancel _ _).symm, mul_one, nat.cast_add, nat.cast_one, mem_support_iff], intro h, push_neg at h, simp [h], }, { assume b, cases b, { intros, rw [nat.cast_zero, mul_zero, zero_mul], }, { intros _ H, rw [nat.succ_sub_one b, if_neg (mt (congr_arg nat.succ) H.symm), mul_zero] } } end @[simp] lemma derivative_zero : derivative (0 : polynomial R) = 0 := finsupp.sum_zero_index lemma derivative_monomial (a : R) (n : ℕ) : derivative (C a * X ^ n) = C (a * n) * X^(n - 1) := begin rw [← single_eq_C_mul_X, ← single_eq_C_mul_X, derivative, monomial, sum_single_index, single_eq_C_mul_X], simp only [zero_mul, C_0], end @[simp] lemma derivative_C {a : R} : derivative (C a) = 0 := suffices derivative (C a * X^0) = C (a * 0:R) * X ^ 0, by simpa only [mul_one, zero_mul, C_0, mul_zero, pow_zero], derivative_monomial a 0 @[simp] lemma derivative_X : derivative (X : polynomial R) = 1 := by simpa only [mul_one, one_mul, C_1, pow_one, nat.cast_one, pow_zero] using derivative_monomial (1:R) 1 @[simp] lemma derivative_one : derivative (1 : polynomial R) = 0 := derivative_C @[simp] lemma derivative_add {f g : polynomial R} : derivative (f + g) = derivative f + derivative g := by refine finsupp.sum_add_index _ _; intros; simp only [add_mul, zero_mul, C_0, C_add, C_mul] /-- The formal derivative of polynomials, as additive homomorphism. -/ def derivative_hom (R : Type*) [semiring R] : polynomial R →+ polynomial R := { to_fun := derivative, map_zero' := derivative_zero, map_add' := λ p q, derivative_add } @[simp] lemma derivative_neg {R : Type*} [ring R] (f : polynomial R) : derivative (-f) = -derivative f := (derivative_hom R).map_neg f @[simp] lemma derivative_sub {R : Type*} [ring R] (f g : polynomial R) : derivative (f - g) = derivative f - derivative g := (derivative_hom R).map_sub f g instance : is_add_monoid_hom (derivative : polynomial R → polynomial R) := (derivative_hom R).is_add_monoid_hom @[simp] lemma derivative_sum {s : finset ι} {f : ι → polynomial R} : derivative (∑ b in s, f b) = ∑ b in s, derivative (f b) := (derivative_hom R).map_sum f s @[simp] lemma derivative_smul (r : R) (p : polynomial R) : derivative (r • p) = r • derivative p := by { ext, simp only [coeff_derivative, mul_assoc, coeff_smul], } end semiring section comm_semiring variables [comm_semiring R] @[simp] lemma derivative_mul {f g : polynomial R} : derivative (f * g) = derivative f * g + f * derivative g := calc derivative (f * g) = f.sum (λn a, g.sum (λm b, C ((a * b) * (n + m : ℕ)) * X^((n + m) - 1))) : begin transitivity, exact derivative_sum, transitivity, { apply finset.sum_congr rfl, assume x hx, exact derivative_sum }, apply finset.sum_congr rfl, assume n hn, apply finset.sum_congr rfl, assume m hm, transitivity, { apply congr_arg, exact single_eq_C_mul_X }, exact derivative_monomial _ _ end ... = f.sum (λn a, g.sum (λm b, (C (a * n) * X^(n - 1)) * (C b * X^m) + (C a * X^n) * (C (b * m) * X^(m - 1)))) : sum_congr rfl $ assume n hn, sum_congr rfl $ assume m hm, by simp only [nat.cast_add, mul_add, add_mul, C_add, C_mul]; cases n; simp only [nat.succ_sub_succ, pow_zero]; cases m; simp only [nat.cast_zero, C_0, nat.succ_sub_succ, zero_mul, mul_zero, nat.sub_zero, pow_zero, pow_add, one_mul, pow_succ, mul_comm, mul_left_comm] ... = derivative f * g + f * derivative g : begin conv { to_rhs, congr, { rw [← sum_C_mul_X_eq g] }, { rw [← sum_C_mul_X_eq f] } }, unfold derivative finsupp.sum, simp only [sum_add_distrib, finset.mul_sum, finset.sum_mul] end theorem derivative_pow_succ (p : polynomial R) (n : ℕ) : (p ^ (n + 1)).derivative = (n + 1) * (p ^ n) * p.derivative := nat.rec_on n (by rw [pow_one, nat.cast_zero, zero_add, one_mul, pow_zero, one_mul]) $ λ n ih, by rw [pow_succ', derivative_mul, ih, mul_right_comm, ← add_mul, add_mul (n.succ : polynomial R), one_mul, pow_succ', mul_assoc, n.cast_succ] theorem derivative_pow (p : polynomial R) (n : ℕ) : (p ^ n).derivative = n * (p ^ (n - 1)) * p.derivative := nat.cases_on n (by rw [pow_zero, derivative_one, nat.cast_zero, zero_mul, zero_mul]) $ λ n, by rw [p.derivative_pow_succ n, n.succ_sub_one, n.cast_succ] theorem derivative_map [comm_semiring S] (p : polynomial R) (f : R →+* S) : (p.map f).derivative = p.derivative.map f := polynomial.induction_on p (λ r, by rw [map_C, derivative_C, derivative_C, map_zero]) (λ p q ihp ihq, by rw [map_add, derivative_add, ihp, ihq, derivative_add, map_add]) (λ n r ih, by rw [map_mul, map_C, map_pow, map_X, derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one, derivative_mul, derivative_pow_succ, derivative_C, zero_mul, zero_add, derivative_X, mul_one, map_mul, map_C, map_mul, map_pow, map_add, map_nat_cast, map_one, map_X]) /-- Chain rule for formal derivative of polynomials. -/ theorem derivative_eval₂_C (p q : polynomial R) : (p.eval₂ C q).derivative = p.derivative.eval₂ C q * q.derivative := polynomial.induction_on p (λ r, by rw [eval₂_C, derivative_C, eval₂_zero, zero_mul]) (λ p₁ p₂ ih₁ ih₂, by rw [eval₂_add, derivative_add, ih₁, ih₂, derivative_add, eval₂_add, add_mul]) (λ n r ih, by rw [pow_succ', ← mul_assoc, eval₂_mul, eval₂_X, derivative_mul, ih, @derivative_mul _ _ _ X, derivative_X, mul_one, eval₂_add, @eval₂_mul _ _ _ _ X, eval₂_X, add_mul, mul_right_comm]) theorem of_mem_support_derivative {p : polynomial R} {n : ℕ} (h : n ∈ p.derivative.support) : n + 1 ∈ p.support := finsupp.mem_support_iff.2 $ λ (h1 : p.coeff (n+1) = 0), finsupp.mem_support_iff.1 h $ show p.derivative.coeff n = 0, by rw [coeff_derivative, h1, zero_mul] theorem degree_derivative_lt {p : polynomial R} (hp : p ≠ 0) : p.derivative.degree < p.degree := (finset.sup_lt_iff $ bot_lt_iff_ne_bot.2 $ mt degree_eq_bot.1 hp).2 $ λ n hp, lt_of_lt_of_le (with_bot.some_lt_some.2 n.lt_succ_self) $ finset.le_sup $ of_mem_support_derivative hp theorem nat_degree_derivative_lt {p : polynomial R} (hp : p.derivative ≠ 0) : p.derivative.nat_degree < p.nat_degree := have hp1 : p ≠ 0, from λ h, hp $ by rw [h, derivative_zero], with_bot.some_lt_some.1 $ by { rw [nat_degree, option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp, nat_degree, option.get_or_else_of_ne_none $ mt degree_eq_bot.1 hp1], exact degree_derivative_lt hp1 } theorem degree_derivative_le {p : polynomial R} : p.derivative.degree ≤ p.degree := if H : p = 0 then le_of_eq $ by rw [H, derivative_zero] else le_of_lt $ degree_derivative_lt H /-- The formal derivative of polynomials, as linear homomorphism. -/ def derivative_lhom (R : Type*) [comm_ring R] : polynomial R →ₗ[R] polynomial R := { to_fun := derivative, map_add' := λ p q, derivative_add, map_smul' := λ r p, derivative_smul r p } end comm_semiring section domain variables [integral_domain R] lemma mem_support_derivative [char_zero R] (p : polynomial R) (n : ℕ) : n ∈ (derivative p).support ↔ n + 1 ∈ p.support := suffices (¬(coeff p (n + 1) = 0 ∨ ((n + 1:ℕ) : R) = 0)) ↔ coeff p (n + 1) ≠ 0, by simpa only [mem_support_iff_coeff_ne_zero, coeff_derivative, ne.def, mul_eq_zero], by { rw [nat.cast_eq_zero], simp only [nat.succ_ne_zero, or_false] } @[simp] lemma degree_derivative_eq [char_zero R] (p : polynomial R) (hp : 0 < nat_degree p) : degree (derivative p) = (nat_degree p - 1 : ℕ) := le_antisymm (le_trans (degree_sum_le _ _) $ sup_le $ assume n hn, have n ≤ nat_degree p, begin rw [← with_bot.coe_le_coe, ← degree_eq_nat_degree], { refine le_degree_of_ne_zero _, simpa only [mem_support_iff] using hn }, { assume h, simpa only [h, support_zero] using hn } end, le_trans (degree_monomial_le _ _) $ with_bot.coe_le_coe.2 $ nat.sub_le_sub_right this _) begin refine le_sup _, rw [mem_support_derivative, nat.sub_add_cancel, mem_support_iff], { show ¬ leading_coeff p = 0, rw [leading_coeff_eq_zero], assume h, rw [h, nat_degree_zero] at hp, exact lt_irrefl 0 (lt_of_le_of_lt (zero_le _) hp), }, exact hp end theorem nat_degree_eq_zero_of_derivative_eq_zero [char_zero R] {f : polynomial R} (h : f.derivative = 0) : f.nat_degree = 0 := begin by_cases hf : f = 0, { exact (congr_arg polynomial.nat_degree hf).trans rfl }, { rw nat_degree_eq_zero_iff_degree_le_zero, by_contra absurd, have f_nat_degree_pos : 0 < f.nat_degree, { rwa [not_le, ←nat_degree_pos_iff_degree_pos] at absurd }, let m := f.nat_degree - 1, have hm : m + 1 = f.nat_degree := nat.sub_add_cancel f_nat_degree_pos, have h2 := coeff_derivative f m, rw polynomial.ext_iff at h, rw [h m, coeff_zero, zero_eq_mul] at h2, cases h2, { rw [hm, ←leading_coeff, leading_coeff_eq_zero] at h2, exact hf h2, }, { norm_cast at h2 } } end end domain end derivative end polynomial
745f109d04a6f9699f1490798809252615c5acd7
acc85b4be2c618b11fc7cb3005521ae6858a8d07
/data/bool.lean
824927448ebc7d695040141b9e0a91ff1df115d1
[ "Apache-2.0" ]
permissive
linpingchuan/mathlib
d49990b236574df2a45d9919ba43c923f693d341
5ad8020f67eb13896a41cc7691d072c9331b1f76
refs/heads/master
1,626,019,377,808
1,508,048,784,000
1,508,048,784,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,806
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura, Jeremy Avigad -/ namespace bool set_option pp.universes true @[simp] theorem coe_sort_tt : coe_sort.{1 1} tt = true := eq_true_intro rfl @[simp] theorem coe_sort_ff : coe_sort.{1 1} ff = false := eq_false_intro ff_ne_tt attribute [simp] to_bool_iff @[simp] theorem to_bool_true {h} : @to_bool true h = tt := show _ = to_bool true, by congr @[simp] theorem to_bool_false {h} : @to_bool false h = ff := show _ = to_bool false, by congr @[simp] theorem to_bool_bool (b : bool) : to_bool b = b := by cases b; simp theorem dichotomy (b : bool) : b = ff ∨ b = tt := by cases b; simp @[simp] theorem cond_ff {A : Type} (t e : A) : cond ff t e = e := rfl @[simp] theorem cond_tt {A : Type} (t e : A) : cond tt t e = t := rfl theorem eq_tt_of_ne_ff {a : bool} : a ≠ ff → a = tt := by cases a; simp theorem eq_ff_of_ne_tt {a : bool} : a ≠ tt → a = ff := by cases a; simp theorem absurd_of_eq_ff_of_eq_tt {B : Prop} {a : bool} (H₁ : a = ff) (H₂ : a = tt) : B := by subst a; contradiction @[simp] theorem bor_comm (a b : bool) : a || b = b || a := by cases a; cases b; simp @[simp] theorem bor_assoc (a b c : bool) : (a || b) || c = a || (b || c) := by cases a; cases b; simp @[simp] theorem bor_left_comm (a b c : bool) : a || (b || c) = b || (a || c) := by cases a; cases b; simp theorem bor_inl {a b : bool} (H : a) : a || b := by simp [H] theorem bor_inr {a b : bool} (H : b) : a || b := by simp [H] @[simp] theorem band_comm (a b : bool) : a && b = b && a := by cases a; simp @[simp] theorem band_assoc (a b c : bool) : (a && b) && c = a && (b && c) := by cases a; simp @[simp] theorem band_left_comm (a b c : bool) : a && (b && c) = b && (a && c) := by cases a; simp theorem band_elim_left {a b : bool} (H : a && b = tt) : a = tt := begin cases a, simp at H, simp [H] end theorem band_intro {a b : bool} (H₁ : a = tt) (H₂ : b = tt) : a && b = tt := begin cases a, simp [H₁, H₂], simp [H₂] end theorem band_elim_right {a b : bool} (H : a && b = tt) : b = tt := begin cases a, contradiction, simp at H, exact H end @[simp] theorem bnot_false : bnot ff = tt := rfl @[simp] theorem bnot_true : bnot tt = ff := rfl theorem eq_tt_of_bnot_eq_ff {a : bool} : bnot a = ff → a = tt := by cases a; simp theorem eq_ff_of_bnot_eq_tt {a : bool} : bnot a = tt → a = ff := by cases a; simp @[simp] theorem bxor_comm (a b : bool) : bxor a b = bxor b a := by cases a; simp @[simp] theorem bxor_assoc (a b c : bool) : bxor (bxor a b) c = bxor a (bxor b c) := by cases a; cases b; simp @[simp] theorem bxor_left_comm (a b c : bool) : bxor a (bxor b c) = bxor b (bxor a c) := by cases a; cases b; simp end bool
7dad3a5bb0a489974b53fdf9d301be1f10e69abf
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/congr_tac.lean
23b3a5a74efe9c6356e93b80f6fcdfc76599c809
[ "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
716
lean
import data.list example (f : nat → nat → nat) (a b c : nat) : b = c → f a b = f a c := begin intro bc, congruence, assumption end example (f g : nat → nat → nat) (a b c : nat) : f = g → b = c → f a b = g a c := begin intro fg bc, congruence, exact fg, exact bc end example (f g : nat → nat → nat) (a b c : nat) : f = g → b = c → f a b = g a c := by intros; congruence; repeat assumption open list example (a b : nat) : a = b → [a] ++ [b] = [b] ++ [a] := begin intro ab, congruence, {congruence, exact ab}, {congruence, exact (eq.symm ab)} end example (a b : nat) : a = b → [a] ++ [b] = [b] ++ [a] := by intros; repeat (congruence | assumption | symmetry)
cb7b6f91dd3847bcac9a4961bad98821b31a2f02
32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7
/tests/lean/abst.lean
5a4de4ad119bb083b2a851fb1efe0e2d3af1d4e3
[ "Apache-2.0" ]
permissive
walterhu1015/lean4
b2c71b688975177402758924eaa513475ed6ce72
2214d81e84646a905d0b20b032c89caf89c737ad
refs/heads/master
1,671,342,096,906
1,599,695,985,000
1,599,695,985,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
509
lean
import Lean.Expr open Lean def tst : IO Unit := do let f := mkConst `f; let x := mkFVar `x; let y := mkFVar `y; let t := mkApp (mkApp (mkApp f x) y) (mkApp f x); IO.println t; let p := t.abstract [x, y].toArray; IO.println p; IO.println $ p.instantiateRev #[x, y]; let a := mkConst `a; let b := mkApp f (mkConst `b); IO.println $ p.instantiateRev #[a, b]; IO.println $ p.instantiate #[a]; let p := t.abstractRange 1 #[x, y]; IO.println p; let p := t.abstractRange 3 #[x, y]; IO.println p; pure () #eval tst
7068ba23c34a1a326425465e3705e23bdaceb87e
6e41ee3ac9b96e8980a16295cc21f131e731884f
/library/algebra/category/morphism.lean
f90cc4be030abae6d21d13bc96d649a01aaa3866
[ "Apache-2.0" ]
permissive
EgbertRijke/lean
3426cfa0e5b3d35d12fc3fd7318b35574cb67dc3
4f2e0c6d7fc9274d953cfa1c37ab2f3e799ab183
refs/heads/master
1,610,834,871,476
1,422,159,801,000
1,422,159,801,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,990
lean
/- Copyright (c) 2014 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Module: algebra.category.morphism Author: Floris van Doorn -/ import .basic algebra.relation algebra.binary open eq eq.ops category namespace morphism variables {ob : Type} [C : category ob] include C variables {a b c : ob} {g : b ⟶ c} {f : a ⟶ b} {h : b ⟶ a} inductive is_section [class] (f : a ⟶ b) : Type := mk : ∀{g}, g ∘ f = id → is_section f inductive is_retraction [class] (f : a ⟶ b) : Type := mk : ∀{g}, f ∘ g = id → is_retraction f inductive is_iso [class] (f : a ⟶ b) : Type := mk : ∀{g}, g ∘ f = id → f ∘ g = id → is_iso f persistent attribute is_iso [multiple-instances] definition retraction_of (f : a ⟶ b) [H : is_section f] : hom b a := is_section.rec (λg h, g) H definition section_of (f : a ⟶ b) [H : is_retraction f] : hom b a := is_retraction.rec (λg h, g) H definition inverse (f : a ⟶ b) [H : is_iso f] : hom b a := is_iso.rec (λg h1 h2, g) H postfix `⁻¹` := inverse theorem inverse_compose (f : a ⟶ b) [H : is_iso f] : f⁻¹ ∘ f = id := is_iso.rec (λg h1 h2, h1) H theorem compose_inverse (f : a ⟶ b) [H : is_iso f] : f ∘ f⁻¹ = id := is_iso.rec (λg h1 h2, h2) H theorem retraction_compose (f : a ⟶ b) [H : is_section f] : retraction_of f ∘ f = id := is_section.rec (λg h, h) H theorem compose_section (f : a ⟶ b) [H : is_retraction f] : f ∘ section_of f = id := is_retraction.rec (λg h, h) H theorem iso_imp_retraction [instance] (f : a ⟶ b) [H : is_iso f] : is_section f := is_section.mk !inverse_compose theorem iso_imp_section [instance] (f : a ⟶ b) [H : is_iso f] : is_retraction f := is_retraction.mk !compose_inverse theorem id_is_iso [instance] : is_iso (ID a) := is_iso.mk !id_compose !id_compose theorem inverse_is_iso [instance] (f : a ⟶ b) [H : is_iso f] : is_iso (f⁻¹) := is_iso.mk !compose_inverse !inverse_compose theorem left_inverse_eq_right_inverse {f : a ⟶ b} {g g' : hom b a} (Hl : g ∘ f = id) (Hr : f ∘ g' = id) : g = g' := calc g = g ∘ id : symm !id_right ... = g ∘ f ∘ g' : {symm Hr} ... = (g ∘ f) ∘ g' : !assoc ... = id ∘ g' : {Hl} ... = g' : !id_left theorem retraction_eq_intro [H : is_section f] (H2 : f ∘ h = id) : retraction_of f = h := left_inverse_eq_right_inverse !retraction_compose H2 theorem section_eq_intro [H : is_retraction f] (H2 : h ∘ f = id) : section_of f = h := symm (left_inverse_eq_right_inverse H2 !compose_section) theorem inverse_eq_intro_right [H : is_iso f] (H2 : f ∘ h = id) : f⁻¹ = h := left_inverse_eq_right_inverse !inverse_compose H2 theorem inverse_eq_intro_left [H : is_iso f] (H2 : h ∘ f = id) : f⁻¹ = h := symm (left_inverse_eq_right_inverse H2 !compose_inverse) theorem section_eq_retraction (f : a ⟶ b) [Hl : is_section f] [Hr : is_retraction f] : retraction_of f = section_of f := retraction_eq_intro !compose_section theorem section_retraction_imp_iso (f : a ⟶ b) [Hl : is_section f] [Hr : is_retraction f] : is_iso f := is_iso.mk (subst (section_eq_retraction f) (retraction_compose f)) (compose_section f) theorem inverse_unique (H H' : is_iso f) : @inverse _ _ _ _ f H = @inverse _ _ _ _ f H' := inverse_eq_intro_left !inverse_compose theorem inverse_involutive (f : a ⟶ b) [H : is_iso f] : (f⁻¹)⁻¹ = f := inverse_eq_intro_right !inverse_compose theorem retraction_of_id : retraction_of (ID a) = id := retraction_eq_intro !id_compose theorem section_of_id : section_of (ID a) = id := section_eq_intro !id_compose theorem iso_of_id : ID a⁻¹ = id := inverse_eq_intro_left !id_compose theorem composition_is_section [instance] [Hf : is_section f] [Hg : is_section g] : is_section (g ∘ f) := is_section.mk (calc (retraction_of f ∘ retraction_of g) ∘ g ∘ f = retraction_of f ∘ retraction_of g ∘ g ∘ f : symm (assoc _ _ (g ∘ f)) ... = retraction_of f ∘ (retraction_of g ∘ g) ∘ f : {assoc _ g f} ... = retraction_of f ∘ id ∘ f : {retraction_compose g} ... = retraction_of f ∘ f : {id_left f} ... = id : !retraction_compose) theorem composition_is_retraction [instance] (Hf : is_retraction f) (Hg : is_retraction g) : is_retraction (g ∘ f) := is_retraction.mk (calc (g ∘ f) ∘ section_of f ∘ section_of g = g ∘ f ∘ section_of f ∘ section_of g : symm !assoc ... = g ∘ (f ∘ section_of f) ∘ section_of g : {assoc f _ _} ... = g ∘ id ∘ section_of g : {compose_section f} ... = g ∘ section_of g : {id_left (section_of g)} ... = id : !compose_section) theorem composition_is_inverse [instance] (Hf : is_iso f) (Hg : is_iso g) : is_iso (g ∘ f) := !section_retraction_imp_iso structure isomorphic (a b : ob) := (iso : a ⟶ b) [is_iso : is_iso iso] infix `≅`:50 := morphism.isomorphic namespace isomorphic open relation persistent attribute is_iso [instance] theorem refl (a : ob) : a ≅ a := mk id theorem symm ⦃a b : ob⦄ (H : a ≅ b) : b ≅ a := mk (inverse (iso H)) theorem trans ⦃a b c : ob⦄ (H1 : a ≅ b) (H2 : b ≅ c) : a ≅ c := mk (iso H2 ∘ iso H1) theorem is_equivalence_eq [instance] (T : Type) : is_equivalence isomorphic := is_equivalence.mk refl symm trans end isomorphic inductive is_mono [class] (f : a ⟶ b) : Prop := mk : (∀c (g h : hom c a), f ∘ g = f ∘ h → g = h) → is_mono f inductive is_epi [class] (f : a ⟶ b) : Prop := mk : (∀c (g h : hom b c), g ∘ f = h ∘ f → g = h) → is_epi f theorem mono_elim [H : is_mono f] {g h : c ⟶ a} (H2 : f ∘ g = f ∘ h) : g = h := is_mono.rec (λH3, H3 c g h H2) H theorem epi_elim [H : is_epi f] {g h : b ⟶ c} (H2 : g ∘ f = h ∘ f) : g = h := is_epi.rec (λH3, H3 c g h H2) H theorem section_is_mono [instance] (f : a ⟶ b) [H : is_section f] : is_mono f := is_mono.mk (λ c g h H, calc g = id ∘ g : symm !id_left ... = (retraction_of f ∘ f) ∘ g : {symm (retraction_compose f)} ... = retraction_of f ∘ f ∘ g : symm !assoc ... = retraction_of f ∘ f ∘ h : {H} ... = (retraction_of f ∘ f) ∘ h : !assoc ... = id ∘ h : {retraction_compose f} ... = h : !id_left) theorem retraction_is_epi [instance] (f : a ⟶ b) [H : is_retraction f] : is_epi f := is_epi.mk (λ c g h H, calc g = g ∘ id : symm !id_right ... = g ∘ f ∘ section_of f : {symm (compose_section f)} ... = (g ∘ f) ∘ section_of f : !assoc ... = (h ∘ f) ∘ section_of f : {H} ... = h ∘ f ∘ section_of f : symm !assoc ... = h ∘ id : {compose_section f} ... = h : !id_right) --these theorems are now proven automatically using type classes --should they be instances? theorem id_is_mono : is_mono (ID a) theorem id_is_epi : is_epi (ID a) theorem composition_is_mono [instance] [Hf : is_mono f] [Hg : is_mono g] : is_mono (g ∘ f) := is_mono.mk (λ d h₁ h₂ H, have H2 : g ∘ (f ∘ h₁) = g ∘ (f ∘ h₂), from symm (assoc g f h₁) ▸ symm (assoc g f h₂) ▸ H, mono_elim (mono_elim H2)) theorem composition_is_epi [instance] [Hf : is_epi f] [Hg : is_epi g] : is_epi (g ∘ f) := is_epi.mk (λ d h₁ h₂ H, have H2 : (h₁ ∘ g) ∘ f = (h₂ ∘ g) ∘ f, from assoc h₁ g f ▸ assoc h₂ g f ▸ H, epi_elim (epi_elim H2)) end morphism namespace morphism --rewrite lemmas for inverses, modified from --https://github.com/JasonGross/HoTT-categories/blob/master/theories/Categories/Category/Morphisms.v namespace iso section variables {ob : Type} [C : category ob] include C variables {a b c d : ob} (f : b ⟶ a) (r : c ⟶ d) (q : b ⟶ c) (p : a ⟶ b) (g : d ⟶ c) variable [Hq : is_iso q] include Hq theorem compose_pV : q ∘ q⁻¹ = id := !compose_inverse theorem compose_Vp : q⁻¹ ∘ q = id := !inverse_compose theorem compose_V_pp : q⁻¹ ∘ (q ∘ p) = p := calc q⁻¹ ∘ (q ∘ p) = (q⁻¹ ∘ q) ∘ p : assoc (q⁻¹) q p ... = id ∘ p : {inverse_compose q} ... = p : id_left p theorem compose_p_Vp : q ∘ (q⁻¹ ∘ g) = g := calc q ∘ (q⁻¹ ∘ g) = (q ∘ q⁻¹) ∘ g : assoc q (q⁻¹) g ... = id ∘ g : {compose_inverse q} ... = g : id_left g theorem compose_pp_V : (r ∘ q) ∘ q⁻¹ = r := calc (r ∘ q) ∘ q⁻¹ = r ∘ q ∘ q⁻¹ : assoc r q (q⁻¹)⁻¹ ... = r ∘ id : {compose_inverse q} ... = r : id_right r theorem compose_pV_p : (f ∘ q⁻¹) ∘ q = f := calc (f ∘ q⁻¹) ∘ q = f ∘ q⁻¹ ∘ q : assoc f (q⁻¹) q⁻¹ ... = f ∘ id : {inverse_compose q} ... = f : id_right f theorem inv_pp [H' : is_iso p] : (q ∘ p)⁻¹ = p⁻¹ ∘ q⁻¹ := have H1 : (p⁻¹ ∘ q⁻¹) ∘ q ∘ p = p⁻¹ ∘ (q⁻¹ ∘ (q ∘ p)), from assoc (p⁻¹) (q⁻¹) (q ∘ p)⁻¹, have H2 : (p⁻¹) ∘ (q⁻¹ ∘ (q ∘ p)) = p⁻¹ ∘ p, from congr_arg _ (compose_V_pp q p), have H3 : p⁻¹ ∘ p = id, from inverse_compose p, inverse_eq_intro_left (H1 ⬝ H2 ⬝ H3) --the proof using calc is hard for the unifier (needs ~90k steps) -- inverse_eq_intro_left -- (calc -- (p⁻¹ ∘ (q⁻¹)) ∘ q ∘ p = p⁻¹ ∘ (q⁻¹ ∘ (q ∘ p)) : assoc (p⁻¹) (q⁻¹) (q ∘ p)⁻¹ -- ... = (p⁻¹) ∘ p : congr_arg (λx, p⁻¹ ∘ x) (compose_V_pp q p) -- ... = id : inverse_compose p) theorem inv_Vp [H' : is_iso g] : (q⁻¹ ∘ g)⁻¹ = g⁻¹ ∘ q := inverse_involutive q ▸ inv_pp (q⁻¹) g theorem inv_pV [H' : is_iso f] : (q ∘ f⁻¹)⁻¹ = f ∘ q⁻¹ := inverse_involutive f ▸ inv_pp q (f⁻¹) theorem inv_VV [H' : is_iso r] : (q⁻¹ ∘ r⁻¹)⁻¹ = r ∘ q := inverse_involutive r ▸ inv_Vp q (r⁻¹) end section variables {ob : Type} {C : category ob} include C variables {d c b a : ob} {i : b ⟶ c} {f : b ⟶ a} {r : c ⟶ d} {q : b ⟶ c} {p : a ⟶ b} {g : d ⟶ c} {h : c ⟶ b} {x : b ⟶ d} {z : a ⟶ c} {y : d ⟶ b} {w : c ⟶ a} variable [Hq : is_iso q] include Hq theorem moveR_Mp (H : y = q⁻¹ ∘ g) : q ∘ y = g := H⁻¹ ▸ compose_p_Vp q g theorem moveR_pM (H : w = f ∘ q⁻¹) : w ∘ q = f := H⁻¹ ▸ compose_pV_p f q theorem moveR_Vp (H : z = q ∘ p) : q⁻¹ ∘ z = p := H⁻¹ ▸ compose_V_pp q p theorem moveR_pV (H : x = r ∘ q) : x ∘ q⁻¹ = r := H⁻¹ ▸ compose_pp_V r q theorem moveL_Mp (H : q⁻¹ ∘ g = y) : g = q ∘ y := moveR_Mp (H⁻¹)⁻¹ theorem moveL_pM (H : f ∘ q⁻¹ = w) : f = w ∘ q := moveR_pM (H⁻¹)⁻¹ theorem moveL_Vp (H : q ∘ p = z) : p = q⁻¹ ∘ z := moveR_Vp (H⁻¹)⁻¹ theorem moveL_pV (H : r ∘ q = x) : r = x ∘ q⁻¹ := moveR_pV (H⁻¹)⁻¹ theorem moveL_1V (H : h ∘ q = id) : h = q⁻¹ := inverse_eq_intro_left H⁻¹ theorem moveL_V1 (H : q ∘ h = id) : h = q⁻¹ := inverse_eq_intro_right H⁻¹ theorem moveL_1M (H : i ∘ q⁻¹ = id) : i = q := moveL_1V H ⬝ inverse_involutive q theorem moveL_M1 (H : q⁻¹ ∘ i = id) : i = q := moveL_V1 H ⬝ inverse_involutive q theorem moveR_1M (H : id = i ∘ q⁻¹) : q = i := moveL_1M (H⁻¹)⁻¹ theorem moveR_M1 (H : id = q⁻¹ ∘ i) : q = i := moveL_M1 (H⁻¹)⁻¹ theorem moveR_1V (H : id = h ∘ q) : q⁻¹ = h := moveL_1V (H⁻¹)⁻¹ theorem moveR_V1 (H : id = q ∘ h) : q⁻¹ = h := moveL_V1 (H⁻¹)⁻¹ end end iso end morphism
4b425925d0f65e492af7500041c2c09aadf096a4
d9d511f37a523cd7659d6f573f990e2a0af93c6f
/src/algebra/category/CommRing/basic.lean
8248b00f727f5ba930f4a449191b1bf0c3d2c3ad
[ "Apache-2.0" ]
permissive
hikari0108/mathlib
b7ea2b7350497ab1a0b87a09d093ecc025a50dfa
a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901
refs/heads/master
1,690,483,608,260
1,631,541,580,000
1,631,541,580,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,101
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Johannes Hölzl, Yury Kudryashov -/ import algebra.category.Group.basic import data.equiv.ring /-! # Category instances for semiring, ring, comm_semiring, and comm_ring. We introduce the bundled categories: * `SemiRing` * `Ring` * `CommSemiRing` * `CommRing` along with the relevant forgetful functors between them. -/ universes u v open category_theory /-- The category of semirings. -/ def SemiRing : Type (u+1) := bundled semiring namespace SemiRing /-- `ring_hom` doesn't actually assume associativity. This alias is needed to make the category theory machinery work. We use the same trick in `category_theory.Mon.assoc_monoid_hom`. -/ abbreviation assoc_ring_hom (M N : Type*) [semiring M] [semiring N] := ring_hom M N instance bundled_hom : bundled_hom assoc_ring_hom := ⟨λ M N [semiring M] [semiring N], by exactI @ring_hom.to_fun M N _ _, λ M [semiring M], by exactI @ring_hom.id M _, λ M N P [semiring M] [semiring N] [semiring P], by exactI @ring_hom.comp M N P _ _ _, λ M N [semiring M] [semiring N], by exactI @ring_hom.coe_inj M N _ _⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] SemiRing /-- Construct a bundled SemiRing from the underlying type and typeclass. -/ def of (R : Type u) [semiring R] : SemiRing := bundled.of R instance : inhabited SemiRing := ⟨of punit⟩ instance (R : SemiRing) : semiring R := R.str @[simp] lemma coe_of (R : Type u) [semiring R] : (SemiRing.of R : Type u) = R := rfl instance has_forget_to_Mon : has_forget₂ SemiRing Mon := bundled_hom.mk_has_forget₂ (λ R hR, @monoid_with_zero.to_monoid R (@semiring.to_monoid_with_zero R hR)) (λ R₁ R₂, ring_hom.to_monoid_hom) (λ _ _ _, rfl) instance has_forget_to_AddCommMon : has_forget₂ SemiRing AddCommMon := -- can't use bundled_hom.mk_has_forget₂, since AddCommMon is an induced category { forget₂ := { obj := λ R, AddCommMon.of R, map := λ R₁ R₂ f, ring_hom.to_add_monoid_hom f } } end SemiRing /-- The category of rings. -/ def Ring : Type (u+1) := bundled ring namespace Ring instance : bundled_hom.parent_projection @ring.to_semiring := ⟨⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] Ring /-- Construct a bundled Ring from the underlying type and typeclass. -/ def of (R : Type u) [ring R] : Ring := bundled.of R instance : inhabited Ring := ⟨of punit⟩ instance (R : Ring) : ring R := R.str @[simp] lemma coe_of (R : Type u) [ring R] : (Ring.of R : Type u) = R := rfl instance has_forget_to_SemiRing : has_forget₂ Ring SemiRing := bundled_hom.forget₂ _ _ instance has_forget_to_AddCommGroup : has_forget₂ Ring AddCommGroup := -- can't use bundled_hom.mk_has_forget₂, since AddCommGroup is an induced category { forget₂ := { obj := λ R, AddCommGroup.of R, map := λ R₁ R₂ f, ring_hom.to_add_monoid_hom f } } end Ring /-- The category of commutative semirings. -/ def CommSemiRing : Type (u+1) := bundled comm_semiring namespace CommSemiRing instance : bundled_hom.parent_projection @comm_semiring.to_semiring := ⟨⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] CommSemiRing /-- Construct a bundled CommSemiRing from the underlying type and typeclass. -/ def of (R : Type u) [comm_semiring R] : CommSemiRing := bundled.of R instance : inhabited CommSemiRing := ⟨of punit⟩ instance (R : CommSemiRing) : comm_semiring R := R.str @[simp] lemma coe_of (R : Type u) [comm_semiring R] : (CommSemiRing.of R : Type u) = R := rfl instance has_forget_to_SemiRing : has_forget₂ CommSemiRing SemiRing := bundled_hom.forget₂ _ _ /-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/ instance has_forget_to_CommMon : has_forget₂ CommSemiRing CommMon := has_forget₂.mk' (λ R : CommSemiRing, CommMon.of R) (λ R, rfl) (λ R₁ R₂ f, f.to_monoid_hom) (by tidy) end CommSemiRing /-- The category of commutative rings. -/ def CommRing : Type (u+1) := bundled comm_ring namespace CommRing instance : bundled_hom.parent_projection @comm_ring.to_ring := ⟨⟩ attribute [derive [has_coe_to_sort, large_category, concrete_category]] CommRing /-- Construct a bundled CommRing from the underlying type and typeclass. -/ def of (R : Type u) [comm_ring R] : CommRing := bundled.of R instance : inhabited CommRing := ⟨of punit⟩ instance (R : CommRing) : comm_ring R := R.str @[simp] lemma coe_of (R : Type u) [comm_ring R] : (CommRing.of R : Type u) = R := rfl instance has_forget_to_Ring : has_forget₂ CommRing Ring := bundled_hom.forget₂ _ _ /-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/ instance has_forget_to_CommSemiRing : has_forget₂ CommRing CommSemiRing := has_forget₂.mk' (λ R : CommRing, CommSemiRing.of R) (λ R, rfl) (λ R₁ R₂ f, f) (by tidy) instance : full (forget₂ CommRing CommSemiRing) := { preimage := λ X Y f, f, } end CommRing -- This example verifies an improvement possible in Lean 3.8. -- Before that, to have `add_ring_hom.map_zero` usable by `simp` here, -- we had to mark all the concrete category `has_coe_to_sort` instances reducible. -- Now, it just works. example {R S : CommRing} (i : R ⟶ S) (r : R) (h : r = 0) : i r = 0 := by simp [h] namespace ring_equiv variables {X Y : Type u} /-- Build an isomorphism in the category `Ring` from a `ring_equiv` between `ring`s. -/ @[simps] def to_Ring_iso [ring X] [ring Y] (e : X ≃+* Y) : Ring.of X ≅ Ring.of Y := { hom := e.to_ring_hom, inv := e.symm.to_ring_hom } /-- Build an isomorphism in the category `CommRing` from a `ring_equiv` between `comm_ring`s. -/ @[simps] def to_CommRing_iso [comm_ring X] [comm_ring Y] (e : X ≃+* Y) : CommRing.of X ≅ CommRing.of Y := { hom := e.to_ring_hom, inv := e.symm.to_ring_hom } end ring_equiv namespace category_theory.iso /-- Build a `ring_equiv` from an isomorphism in the category `Ring`. -/ def Ring_iso_to_ring_equiv {X Y : Ring} (i : X ≅ Y) : X ≃+* Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := by tidy, right_inv := by tidy, map_add' := by tidy, map_mul' := by tidy }. /-- Build a `ring_equiv` from an isomorphism in the category `CommRing`. -/ def CommRing_iso_to_ring_equiv {X Y : CommRing} (i : X ≅ Y) : X ≃+* Y := { to_fun := i.hom, inv_fun := i.inv, left_inv := by tidy, right_inv := by tidy, map_add' := by tidy, map_mul' := by tidy }. end category_theory.iso /-- Ring equivalences between `ring`s are the same as (isomorphic to) isomorphisms in `Ring`. -/ def ring_equiv_iso_Ring_iso {X Y : Type u} [ring X] [ring Y] : (X ≃+* Y) ≅ (Ring.of X ≅ Ring.of Y) := { hom := λ e, e.to_Ring_iso, inv := λ i, i.Ring_iso_to_ring_equiv, } /-- Ring equivalences between `comm_ring`s are the same as (isomorphic to) isomorphisms in `CommRing`. -/ def ring_equiv_iso_CommRing_iso {X Y : Type u} [comm_ring X] [comm_ring Y] : (X ≃+* Y) ≅ (CommRing.of X ≅ CommRing.of Y) := { hom := λ e, e.to_CommRing_iso, inv := λ i, i.CommRing_iso_to_ring_equiv, } instance Ring.forget_reflects_isos : reflects_isomorphisms (forget Ring.{u}) := { reflects := λ X Y f _, begin resetI, let i := as_iso ((forget Ring).map f), let e : X ≃+* Y := { ..f, ..i.to_equiv }, exact ⟨(is_iso.of_iso e.to_Ring_iso).1⟩, end } instance CommRing.forget_reflects_isos : reflects_isomorphisms (forget CommRing.{u}) := { reflects := λ X Y f _, begin resetI, let i := as_iso ((forget CommRing).map f), let e : X ≃+* Y := { ..f, ..i.to_equiv }, exact ⟨(is_iso.of_iso e.to_CommRing_iso).1⟩, end } -- It would be nice if we could have the following, -- but it requires making `reflects_isomorphisms_forget₂` an instance, -- which can cause typeclass loops: local attribute [priority 50,instance] reflects_isomorphisms_forget₂ example : reflects_isomorphisms (forget₂ Ring AddCommGroup) := by apply_instance
57eb9f9db795d92b1ff1d97d43f0ff203940623b
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/src/Leanpkg.lean
68d01dd728d6f172c9eca92d9522f9555ad6a46c
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
7,567
lean
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Sebastian Ullrich -/ import Leanpkg.Resolve import Leanpkg.Git namespace Leanpkg def readManifest : IO Manifest := do let m ← Manifest.fromFile leanpkgTomlFn if m.leanVersion ≠ leanVersionString then IO.eprintln $ "\nWARNING: Lean version mismatch: installed version is " ++ leanVersionString ++ ", but package requires " ++ m.leanVersion ++ "\n" return m def writeManifest (manifest : Lean.Syntax) (fn : String) : IO Unit := do IO.FS.writeFile fn manifest.reprint.get! def lockFileName := ".leanpkg-lock" partial def withLockFile (x : IO α) : IO α := do acquire try x finally IO.removeFile lockFileName where acquire (firstTime := true) := try -- TODO: lock file should ideally contain PID if !System.Platform.isWindows then discard <| IO.Prim.Handle.mk lockFileName "wx" else -- `x` mode doesn't seem to work on Windows even though it's listed at -- https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-160 -- ...? Let's use the slightly racy approach then. if ← IO.fileExists lockFileName then throw <| IO.Error.alreadyExists 0 "" discard <| IO.Prim.Handle.mk lockFileName "w" catch | IO.Error.alreadyExists _ _ => do if firstTime then IO.eprintln s!"Waiting for prior leanpkg invocation to finish... (remove '{lockFileName}' if stuck)" IO.sleep (ms := 300) acquire (firstTime := false) | e => throw e structure Configuration := leanPath : String leanSrcPath : String def configure : IO Configuration := do let d ← readManifest IO.eprintln $ "configuring " ++ d.name ++ " " ++ d.version let assg ← solveDeps d let paths ← constructPath assg for path in paths do unless path == "./." do -- build recursively -- TODO: share build of common dependencies execCmd { cmd := (← IO.appPath) cwd := path args := #["build"] } let sep := System.FilePath.searchPathSeparator.toString return { leanPath := sep.intercalate <| paths.map (· ++ "/build") leanSrcPath := sep.intercalate paths } def execMake (makeArgs leanArgs : List String) (leanPath : String) : IO Unit := withLockFile do let manifest ← readManifest let leanArgs := (match manifest.timeout with | some t => ["-T", toString t] | none => []) ++ leanArgs let mut spawnArgs := { cmd := "sh" cwd := manifest.effectivePath args := #["-c", s!"\"{← IO.appDir}/leanmake\" LEAN_OPTS=\"{" ".intercalate leanArgs}\" LEAN_PATH=\"{leanPath}\" {" ".intercalate makeArgs} >&2"] } execCmd spawnArgs def buildImports (imports : List String) (leanArgs : List String) : IO Unit := do unless (← IO.fileExists leanpkgTomlFn) do return let manifest ← readManifest let cfg ← configure let imports := imports.map (·.toName) -- TODO: shoddy check let localImports := imports.filter fun i => i.getRoot.toString.toLower == manifest.name.toLower if localImports != [] then let oleans := localImports.map fun i => s!"\"build{Lean.modPathToFilePath i}.olean\"" execMake oleans leanArgs cfg.leanPath IO.println cfg.leanPath IO.println cfg.leanSrcPath def build (makeArgs leanArgs : List String) : IO Unit := do execMake makeArgs leanArgs (← configure).leanPath def initGitignoreContents := "/build " def initPkg (n : String) (fromNew : Bool) : IO Unit := do IO.FS.writeFile leanpkgTomlFn s!"[package] name = \"{n}\" version = \"0.1\" lean_version = \"{leanVersionString}\" " IO.FS.writeFile s!"{n.capitalize}.lean" "def main : IO Unit := IO.println \"Hello, world!\" " let h ← IO.FS.Handle.mk ".gitignore" IO.FS.Mode.append (bin := false) h.putStr initGitignoreContents let gitEx ← IO.isDir ".git" unless gitEx do (do execCmd {cmd := "git", args := #["init", "-q"]} unless upstreamGitBranch = "master" do execCmd {cmd := "git", args := #["checkout", "-B", upstreamGitBranch]} ) <|> IO.eprintln "WARNING: failed to initialize git repository" def init (n : String) := initPkg n false def usage := "Lean package manager, version " ++ uiLeanVersionString ++ " Usage: leanpkg <command> init <name> create a Lean package in the current directory configure download and build dependencies build [<args>] configure and build *.olean files See `leanpkg help <command>` for more information on a specific command." def main : (cmd : String) → (leanpkgArgs leanArgs : List String) → IO Unit | "init", [Name], [] => init Name | "configure", [], [] => discard <| configure | "print-paths", leanpkgArgs, leanArgs => buildImports leanpkgArgs leanArgs | "build", makeArgs, leanArgs => build makeArgs leanArgs | "help", ["configure"], [] => IO.println "Download dependencies Usage: leanpkg configure This command sets up the `build/deps` directory. For each (transitive) git dependency, the specified commit is checked out into a sub-directory of `build/deps`. If there are dependencies on multiple versions of the same package, the version materialized is undefined. No copy is made of local dependencies." | "help", ["build"], [] => IO.println "download dependencies and build *.olean files Usage: leanpkg build [<leanmake-args>] [-- <lean-args>] This command invokes `leanpkg configure` followed by `leanmake <leanmake-args> LEAN_OPTS=<lean-args>`. If defined, the `package.timeout` configuration value is passed to Lean via its `-T` parameter. If no <lean-args> are given, only .olean files will be produced in `build/`. If `lib` or `bin` is passed instead, the extracted C code is compiled with `c++` and a static library in `build/lib` or an executable in `build/bin`, respectively, is created. `leanpkg build bin` requires a declaration of name `main` in the root namespace, which must return `IO Unit` or `IO UInt32` (the exit code) and may accept the program's command line arguments as a `List String` parameter. NOTE: building and linking dependent libraries currently has to be done manually, e.g. ``` $ (cd a; leanpkg build lib) $ (cd b; leanpkg build bin LINK_OPTS=../a/build/lib/libA.a) ```" | "help", ["init"], [] => IO.println "Create a new Lean package in the current directory Usage: leanpkg init <name> This command creates a new Lean package with the given name in the current directory." | "help", _, [] => IO.println usage | _, _, _ => throw <| IO.userError usage private def splitCmdlineArgsCore : List String → List String × List String | [] => ([], []) | (arg::args) => if arg == "--" then ([], args) else let (outerArgs, innerArgs) := splitCmdlineArgsCore args (arg::outerArgs, innerArgs) def splitCmdlineArgs : List String → IO (String × List String × List String) | [] => throw <| IO.userError usage | [cmd] => return (cmd, [], []) | (cmd::rest) => let (outerArgs, innerArgs) := splitCmdlineArgsCore rest return (cmd, outerArgs, innerArgs) end Leanpkg def main (args : List String) : IO Unit := do Lean.initSearchPath none -- HACK let (cmd, outerArgs, innerArgs) ← Leanpkg.splitCmdlineArgs args Leanpkg.main cmd outerArgs innerArgs
75ef83cfe8366fe7fe5ee6bbc70b4824bcc55f4e
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/tactic/omega/lin_comb.lean
28b499c99a2df93169f2415a553e5bc7d201eb0a
[ "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
1,857
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek Linear combination of constraints. -/ import tactic.omega.clause namespace omega @[simp] def lin_comb : list nat → list term → term | [] [] := ⟨0,[]⟩ | [] (_::_) := ⟨0,[]⟩ | (_::_) [] := ⟨0,[]⟩ | (n::ns) (t::ts) := term.add (t.mul ↑n) (lin_comb ns ts) lemma lin_comb_holds {v : nat → int} : ∀ {ts} ns, (∀ t ∈ ts, 0 ≤ term.val v t) → (0 ≤ (lin_comb ns ts).val v) | [] [] h := by simp only [add_zero, term.val, lin_comb, coeffs.val_nil] | [] (_::_) h := by simp only [add_zero, term.val, lin_comb, coeffs.val_nil] | (_::_) [] h := by simp only [add_zero, term.val, lin_comb, coeffs.val_nil] | (t::ts) (n::ns) h := begin have : 0 ≤ ↑n * term.val v t + term.val v (lin_comb ns ts), { apply add_nonneg, { apply mul_nonneg, apply int.coe_nat_nonneg, apply h _ (or.inl rfl) }, { apply lin_comb_holds, apply list.forall_mem_of_forall_mem_cons h } }, simpa only [lin_comb, term.val_mul, term.val_add], end def unsat_lin_comb (ns : list nat) (ts : list term) : Prop := (lin_comb ns ts).fst < 0 ∧ ∀ x ∈ (lin_comb ns ts).snd, x = (0 : int) lemma unsat_lin_comb_of (ns : list nat) (ts : list term) : (lin_comb ns ts).fst < 0 → (∀ x ∈ (lin_comb ns ts).snd, x = (0 : int)) → unsat_lin_comb ns ts := by {intros h1 h2, exact ⟨h1,h2⟩} lemma unsat_of_unsat_lin_comb (ns : list nat) (ts : list term) : (unsat_lin_comb ns ts) → clause.unsat ([], ts) := begin intros h1 h2, cases h2 with v h2, have h3 := lin_comb_holds ns h2.right, cases h1 with hl hr, cases (lin_comb ns ts) with b as, unfold term.val at h3, rw [coeffs.val_eq_zero hr, add_zero, ← not_lt] at h3, apply h3 hl end end omega
aecb307b74e6a6f8f177e5b625abccf3f8e9b7f4
5749d8999a76f3a8fddceca1f6941981e33aaa96
/src/topology/dense_embedding.lean
50cc7e034dfe7f6f800f97530540d4c94702a738
[ "Apache-2.0" ]
permissive
jdsalchow/mathlib
13ab43ef0d0515a17e550b16d09bd14b76125276
497e692b946d93906900bb33a51fd243e7649406
refs/heads/master
1,585,819,143,348
1,580,072,892,000
1,580,072,892,000
154,287,128
0
0
Apache-2.0
1,540,281,610,000
1,540,281,609,000
null
UTF-8
Lean
false
false
14,875
lean
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import topology.separation /-! # Dense embeddings This file defines three properties of functions: `dense_range f` means `f` has dense image; `dense_inducing i` means `i` is also `inducing`; `dense_embedding e` means `e` is also an `embedding`. The main theorem `continuous_extend` gives a criterion for a function `f : X → Z` to a regular (T₃) space Z to extend along a dense embedding `i : X → Y` to a continuous function `g : Y → Z`. Actually `i` only has to be `dense_inducing` (not necessarily injective). -/ noncomputable theory open set filter lattice open_locale classical topological_space variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section dense_range variables [topological_space β] [topological_space γ] (f : α → β) (g : β → γ) /-- `f : α → β` has dense range if its range (image) is a dense subset of β. -/ def dense_range := ∀ x, x ∈ closure (range f) variables {f} lemma dense_range_iff_closure_range : dense_range f ↔ closure (range f) = univ := eq_univ_iff_forall.symm lemma dense_range.closure_range (h : dense_range f) : closure (range f) = univ := eq_univ_iff_forall.mpr h lemma dense_range.comp (hg : dense_range g) (hf : dense_range f) (cg : continuous g) : dense_range (g ∘ f) := begin have : g '' (closure $ range f) ⊆ closure (g '' range f), from image_closure_subset_closure_image cg, have : closure (g '' closure (range f)) ⊆ closure (g '' range f), by simpa [closure_closure] using (closure_mono this), intro c, rw range_comp, apply this, rw [hf.closure_range, image_univ], exact hg c end /-- If `f : α → β` has dense range and `β` contains some element, then `α` must too. -/ def dense_range.inhabited (df : dense_range f) (b : β) : inhabited α := ⟨begin have := exists_mem_of_ne_empty (mem_closure_iff.1 (df b) _ is_open_univ trivial), simp only [mem_range, univ_inter] at this, exact classical.some (classical.some_spec this), end⟩ lemma dense_range.nonempty (hf : dense_range f) : nonempty α ↔ nonempty β := ⟨nonempty.map f, λ ⟨b⟩, @nonempty_of_inhabited _ (hf.inhabited b)⟩ lemma dense_range.prod {ι : Type*} {κ : Type*} {f : ι → β} {g : κ → γ} (hf : dense_range f) (hg : dense_range g) : dense_range (λ p : ι × κ, (f p.1, g p.2)) := have closure (range $ λ p : ι×κ, (f p.1, g p.2)) = set.prod (closure $ range f) (closure $ range g), by rw [←closure_prod_eq, prod_range_range_eq], assume ⟨b, d⟩, this.symm ▸ mem_prod.2 ⟨hf _, hg _⟩ end dense_range /-- `i : α → β` is "dense inducing" if it has dense range and the topology on `α` is the one induced by `i` from the topology on `β`. -/ structure dense_inducing [topological_space α] [topological_space β] (i : α → β) extends inducing i : Prop := (dense : dense_range i) namespace dense_inducing variables [topological_space α] [topological_space β] variables {i : α → β} (di : dense_inducing i) lemma nhds_eq_comap (di : dense_inducing i) : ∀ a : α, 𝓝 a = comap i (𝓝 $ i a) := di.to_inducing.nhds_eq_comap protected lemma continuous (di : dense_inducing i) : continuous i := di.to_inducing.continuous lemma closure_range : closure (range i) = univ := di.dense.closure_range lemma self_sub_closure_image_preimage_of_open {s : set β} (di : dense_inducing i) : is_open s → s ⊆ closure (i '' (i ⁻¹' s)) := begin intros s_op b b_in_s, rw [image_preimage_eq_inter_range, mem_closure_iff], intros U U_op b_in, rw ←inter_assoc, have ne_e : U ∩ s ≠ ∅ := ne_empty_of_mem ⟨b_in, b_in_s⟩, exact (dense_iff_inter_open.1 di.closure_range) _ (is_open_inter U_op s_op) ne_e end lemma closure_image_nhds_of_nhds {s : set α} {a : α} (di : dense_inducing i) : s ∈ 𝓝 a → closure (i '' s) ∈ 𝓝 (i a) := begin rw [di.nhds_eq_comap a, mem_comap_sets], intro h, rcases h with ⟨t, t_nhd, sub⟩, rw mem_nhds_sets_iff at t_nhd, rcases t_nhd with ⟨U, U_sub, ⟨U_op, e_a_in_U⟩⟩, have := calc i ⁻¹' U ⊆ i⁻¹' t : preimage_mono U_sub ... ⊆ s : sub, have := calc U ⊆ closure (i '' (i ⁻¹' U)) : self_sub_closure_image_preimage_of_open di U_op ... ⊆ closure (i '' s) : closure_mono (image_subset i this), have U_nhd : U ∈ 𝓝 (i a) := mem_nhds_sets U_op e_a_in_U, exact (𝓝 (i a)).sets_of_superset U_nhd this end /-- The product of two dense inducings is a dense inducing -/ protected lemma prod [topological_space γ] [topological_space δ] {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_inducing e₁) (de₂ : dense_inducing e₂) : dense_inducing (λ(p : α × γ), (e₁ p.1, e₂ p.2)) := { induced := (de₁.to_inducing.prod_mk de₂.to_inducing).induced, dense := de₁.dense.prod de₂.dense } variables [topological_space δ] {f : γ → α} {g : γ → δ} {h : δ → β} /-- γ -f→ α g↓ ↓e δ -h→ β -/ lemma tendsto_comap_nhds_nhds {d : δ} {a : α} (di : dense_inducing i) (H : tendsto h (𝓝 d) (𝓝 (i a))) (comm : h ∘ g = i ∘ f) : tendsto f (comap g (𝓝 d)) (𝓝 a) := begin have lim1 : map g (comap g (𝓝 d)) ≤ 𝓝 d := map_comap_le, replace lim1 : map h (map g (comap g (𝓝 d))) ≤ map h (𝓝 d) := map_mono lim1, rw [filter.map_map, comm, ← filter.map_map, map_le_iff_le_comap] at lim1, have lim2 : comap i (map h (𝓝 d)) ≤ comap i (𝓝 (i a)) := comap_mono H, rw ← di.nhds_eq_comap at lim2, exact le_trans lim1 lim2, end protected lemma nhds_inf_ne_bot (di : dense_inducing i) {b : β} : 𝓝 b ⊓ principal (range i) ≠ ⊥ := begin convert di.dense b, simp [closure_eq_nhds] end lemma comap_nhds_ne_bot (di : dense_inducing i) {b : β} : comap i (𝓝 b) ≠ ⊥ := forall_sets_ne_empty_iff_ne_bot.mp $ assume s ⟨t, ht, (hs : i ⁻¹' t ⊆ s)⟩, have t ∩ range i ∈ 𝓝 b ⊓ principal (range i), from inter_mem_inf_sets ht (subset.refl _), let ⟨_, ⟨hx₁, y, rfl⟩⟩ := inhabited_of_mem_sets di.nhds_inf_ne_bot this in subset_ne_empty hs $ ne_empty_of_mem hx₁ variables [topological_space γ] /-- If `i : α → β` is a dense inducing, then any function `f : α → γ` "extends" to a function `g = extend di f : β → γ`. If `γ` is Hausdorff and `f` has a continuous extension, then `g` is the unique such extension. In general, `g` might not be continuous or even extend `f`. -/ def extend (di : dense_inducing i) (f : α → γ) (b : β) : γ := @lim _ _ ⟨f (dense_range.inhabited di.dense b).default⟩ (map f (comap i (𝓝 b))) lemma extend_eq [t2_space γ] {b : β} {c : γ} {f : α → γ} (hf : map f (comap i (𝓝 b)) ≤ 𝓝 c) : di.extend f b = c := @lim_eq _ _ (id _) _ _ _ (by simp; exact comap_nhds_ne_bot di) hf lemma extend_e_eq [t2_space γ] {f : α → γ} (a : α) (hf : continuous_at f a) : di.extend f (i a) = f a := extend_eq _ $ di.nhds_eq_comap a ▸ hf lemma extend_eq_of_cont [t2_space γ] {f : α → γ} (hf : continuous f) (a : α) : di.extend f (i a) = f a := di.extend_e_eq a (continuous_iff_continuous_at.1 hf a) lemma tendsto_extend [regular_space γ] {b : β} {f : α → γ} (di : dense_inducing i) (hf : {b | ∃c, tendsto f (comap i $ 𝓝 b) (𝓝 c)} ∈ 𝓝 b) : tendsto (di.extend f) (𝓝 b) (𝓝 (di.extend f b)) := let φ := {b | tendsto f (comap i $ 𝓝 b) (𝓝 $ di.extend f b)} in have hφ : φ ∈ 𝓝 b, from (𝓝 b).sets_of_superset hf $ assume b ⟨c, hc⟩, show tendsto f (comap i (𝓝 b)) (𝓝 (di.extend f b)), from (di.extend_eq hc).symm ▸ hc, assume s hs, let ⟨s'', hs''₁, hs''₂, hs''₃⟩ := nhds_is_closed hs in let ⟨s', hs'₁, (hs'₂ : i ⁻¹' s' ⊆ f ⁻¹' s'')⟩ := mem_of_nhds hφ hs''₁ in let ⟨t, (ht₁ : t ⊆ φ ∩ s'), ht₂, ht₃⟩ := mem_nhds_sets_iff.mp $ inter_mem_sets hφ hs'₁ in have h₁ : closure (f '' (i ⁻¹' s')) ⊆ s'', by rw [closure_subset_iff_subset_of_is_closed hs''₃, image_subset_iff]; exact hs'₂, have h₂ : t ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' t)), from assume b' hb', have 𝓝 b' ≤ principal t, by simp; exact mem_nhds_sets ht₂ hb', have map f (comap i (𝓝 b')) ≤ 𝓝 (di.extend f b') ⊓ principal (f '' (i ⁻¹' t)), from calc _ ≤ map f (comap i (𝓝 b' ⊓ principal t)) : map_mono $ comap_mono $ le_inf (le_refl _) this ... ≤ map f (comap i (𝓝 b')) ⊓ map f (comap i (principal t)) : le_inf (map_mono $ comap_mono $ inf_le_left) (map_mono $ comap_mono $ inf_le_right) ... ≤ map f (comap i (𝓝 b')) ⊓ principal (f '' (i ⁻¹' t)) : by simp [le_refl] ... ≤ _ : inf_le_inf ((ht₁ hb').left) (le_refl _), show di.extend f b' ∈ closure (f '' (i ⁻¹' t)), begin rw [closure_eq_nhds], apply ne_bot_of_le_ne_bot _ this, simp, exact di.comap_nhds_ne_bot end, (𝓝 b).sets_of_superset (show t ∈ 𝓝 b, from mem_nhds_sets ht₂ ht₃) (calc t ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' t)) : h₂ ... ⊆ di.extend f ⁻¹' closure (f '' (i ⁻¹' s')) : preimage_mono $ closure_mono $ image_subset f $ preimage_mono $ subset.trans ht₁ $ inter_subset_right _ _ ... ⊆ di.extend f ⁻¹' s'' : preimage_mono h₁ ... ⊆ di.extend f ⁻¹' s : preimage_mono hs''₂) lemma continuous_extend [regular_space γ] {f : α → γ} (di : dense_inducing i) (hf : ∀b, ∃c, tendsto f (comap i (𝓝 b)) (𝓝 c)) : continuous (di.extend f) := continuous_iff_continuous_at.mpr $ assume b, di.tendsto_extend $ univ_mem_sets' hf lemma mk' (i : α → β) (c : continuous i) (dense : ∀x, x ∈ closure (range i)) (H : ∀ (a:α) s ∈ 𝓝 a, ∃t ∈ 𝓝 (i a), ∀ b, i b ∈ t → b ∈ s) : dense_inducing i := { induced := (induced_iff_nhds_eq i).2 $ λ a, le_antisymm (tendsto_iff_comap.1 $ c.tendsto _) (by simpa [le_def] using H a), dense := dense } end dense_inducing /-- A dense embedding is an embedding with dense image. -/ structure dense_embedding [topological_space α] [topological_space β] (e : α → β) extends dense_inducing e : Prop := (inj : function.injective e) theorem dense_embedding.mk' [topological_space α] [topological_space β] (e : α → β) (c : continuous e) (dense : ∀x, x ∈ closure (range e)) (inj : function.injective e) (H : ∀ (a:α) s ∈ 𝓝 a, ∃t ∈ 𝓝 (e a), ∀ b, e b ∈ t → b ∈ s) : dense_embedding e := { inj := inj, ..dense_inducing.mk' e c dense H} namespace dense_embedding variables [topological_space α] [topological_space β] [topological_space γ] [topological_space δ] variables {e : α → β} (de : dense_embedding e) lemma inj_iff {x y} : e x = e y ↔ x = y := de.inj.eq_iff lemma to_embedding : embedding e := { induced := de.induced, inj := de.inj } /-- The product of two dense embeddings is a dense embedding -/ protected lemma prod {e₁ : α → β} {e₂ : γ → δ} (de₁ : dense_embedding e₁) (de₂ : dense_embedding e₂) : dense_embedding (λ(p : α × γ), (e₁ p.1, e₂ p.2)) := { inj := assume ⟨x₁, x₂⟩ ⟨y₁, y₂⟩, by simp; exact assume h₁ h₂, ⟨de₁.inj h₁, de₂.inj h₂⟩, ..dense_inducing.prod de₁.to_dense_inducing de₂.to_dense_inducing } /-- The dense embedding of a subtype inside its closure. -/ def subtype_emb {α : Type*} (p : α → Prop) (e : α → β) (x : {x // p x}) : {x // x ∈ closure (e '' {x | p x})} := ⟨e x.1, subset_closure $ mem_image_of_mem e x.2⟩ protected lemma subtype (p : α → Prop) : dense_embedding (subtype_emb p e) := { dense_embedding . dense := assume ⟨x, hx⟩, closure_subtype.mpr $ have (λ (x : {x // p x}), e (x.val)) = e ∘ subtype.val, from rfl, begin rw ← image_univ, simp [(image_comp _ _ _).symm, (∘), subtype_emb, -image_univ], rw [this, image_comp, subtype.val_image], simp, assumption end, inj := assume ⟨x, hx⟩ ⟨y, hy⟩ h, subtype.eq $ de.inj $ @@congr_arg subtype.val h, induced := (induced_iff_nhds_eq _).2 (assume ⟨x, hx⟩, by simp [subtype_emb, nhds_subtype_eq_comap, de.to_inducing.nhds_eq_comap, comap_comap_comp, (∘)]) } end dense_embedding lemma is_closed_property [topological_space β] {e : α → β} {p : β → Prop} (he : dense_range e) (hp : is_closed {x | p x}) (h : ∀a, p (e a)) : ∀b, p b := have univ ⊆ {b | p b}, from calc univ = closure (range e) : he.closure_range.symm ... ⊆ closure {b | p b} : closure_mono $ range_subset_iff.mpr h ... = _ : closure_eq_of_is_closed hp, assume b, this trivial lemma is_closed_property2 [topological_space β] {e : α → β} {p : β → β → Prop} (he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) : ∀b₁ b₂, p b₁ b₂ := have ∀q:β×β, p q.1 q.2, from is_closed_property (he.prod he) hp $ λ _, h _ _, assume b₁ b₂, this ⟨b₁, b₂⟩ lemma is_closed_property3 [topological_space β] {e : α → β} {p : β → β → β → Prop} (he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) : ∀b₁ b₂ b₃, p b₁ b₂ b₃ := have ∀q:β×β×β, p q.1 q.2.1 q.2.2, from is_closed_property (he.prod $ he.prod he) hp $ λ _, h _ _ _, assume b₁ b₂ b₃, this ⟨b₁, b₂, b₃⟩ @[elab_as_eliminator] lemma dense_range.induction_on [topological_space β] {e : α → β} (he : dense_range e) {p : β → Prop} (b₀ : β) (hp : is_closed {b | p b}) (ih : ∀a:α, p $ e a) : p b₀ := is_closed_property he hp ih b₀ @[elab_as_eliminator] lemma dense_range.induction_on₂ [topological_space β] {e : α → β} {p : β → β → Prop} (he : dense_range e) (hp : is_closed {q:β×β | p q.1 q.2}) (h : ∀a₁ a₂, p (e a₁) (e a₂)) (b₁ b₂ : β) : p b₁ b₂ := is_closed_property2 he hp h _ _ @[elab_as_eliminator] lemma dense_range.induction_on₃ [topological_space β] {e : α → β} {p : β → β → β → Prop} (he : dense_range e) (hp : is_closed {q:β×β×β | p q.1 q.2.1 q.2.2}) (h : ∀a₁ a₂ a₃, p (e a₁) (e a₂) (e a₃)) (b₁ b₂ b₃ : β) : p b₁ b₂ b₃ := is_closed_property3 he hp h _ _ _ section variables [topological_space β] [topological_space γ] [t2_space γ] variables {f : α → β} /-- Two continuous functions to a t2-space that agree on the dense range of a function are equal. -/ lemma dense_range.equalizer (hfd : dense_range f) {g h : β → γ} (hg : continuous g) (hh : continuous h) (H : g ∘ f = h ∘ f) : g = h := funext $ λ y, hfd.induction_on y (is_closed_eq hg hh) $ congr_fun H end
255a6b968378be901948be0442ed43b7da35ac9d
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/ring_theory/witt_vector/verschiebung_auto.lean
89c618e684ef54f3561d6583f4007e48b7640dc5
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
5,534
lean
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.ring_theory.witt_vector.basic import Mathlib.ring_theory.witt_vector.is_poly import Mathlib.PostPort universes u_1 u_2 namespace Mathlib /-! ## The Verschiebung operator -/ namespace witt_vector -- unfortunately, without this attribute, some of the code breaks for reasons I don't understand /-- `verschiebung_fun x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient. `x.coeff i` then becomes `(verchiebung_fun x).coeff (i + 1)`. `verschiebung_fun` is the underlying function of the additive monoid hom `witt_vector.verschiebung`. -/ def verschiebung_fun {p : ℕ} {R : Type u_1} [comm_ring R] (x : witt_vector p R) : witt_vector p R := mk p fun (n : ℕ) => ite (n = 0) 0 (coeff x (n - 1)) theorem verschiebung_fun_coeff {p : ℕ} {R : Type u_1} [comm_ring R] (x : witt_vector p R) (n : ℕ) : coeff (verschiebung_fun x) n = ite (n = 0) 0 (coeff x (n - 1)) := sorry theorem verschiebung_fun_coeff_zero {p : ℕ} {R : Type u_1} [comm_ring R] (x : witt_vector p R) : coeff (verschiebung_fun x) 0 = 0 := eq.mpr (id (Eq._oldrec (Eq.refl (coeff (verschiebung_fun x) 0 = 0)) (verschiebung_fun_coeff x 0))) (eq.mpr (id (Eq._oldrec (Eq.refl (ite (0 = 0) 0 (coeff x (0 - 1)) = 0)) (if_pos rfl))) (Eq.refl 0)) @[simp] theorem verschiebung_fun_coeff_succ {p : ℕ} {R : Type u_1} [comm_ring R] (x : witt_vector p R) (n : ℕ) : coeff (verschiebung_fun x) (Nat.succ n) = coeff x n := rfl theorem ghost_component_zero_verschiebung_fun {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) : coe_fn (ghost_component 0) (verschiebung_fun x) = 0 := sorry theorem ghost_component_verschiebung_fun {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) (n : ℕ) : coe_fn (ghost_component (n + 1)) (verschiebung_fun x) = ↑p * coe_fn (ghost_component n) x := sorry /-- The 0th Verschiebung polynomial is 0. For `n > 0`, the `n`th Verschiebung polynomial is the variable `X (n-1)`. -/ def verschiebung_poly (n : ℕ) : mv_polynomial ℕ ℤ := ite (n = 0) 0 (mv_polynomial.X (n - 1)) @[simp] theorem verschiebung_poly_zero : verschiebung_poly 0 = 0 := rfl theorem aeval_verschiebung_poly' {p : ℕ} {R : Type u_1} [comm_ring R] (x : witt_vector p R) (n : ℕ) : coe_fn (mv_polynomial.aeval (coeff x)) (verschiebung_poly n) = coeff (verschiebung_fun x) n := sorry /-- `witt_vector.verschiebung` has polynomial structure given by `witt_vector.verschiebung_poly`. -/ theorem verschiebung_fun_is_poly (p : ℕ) : is_poly p fun (R : Type u_1) (_Rcr : comm_ring R) => verschiebung_fun := sorry /-- `verschiebung x` shifts the coefficients of `x` up by one, by inserting 0 as the 0th coefficient. `x.coeff i` then becomes `(verchiebung x).coeff (i + 1)`. This is a additive monoid hom with underlying function `verschiebung_fun`. -/ def verschiebung {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] : witt_vector p R →+ witt_vector p R := add_monoid_hom.mk verschiebung_fun sorry sorry /-- `witt_vector.verschiebung` is a polynomial function. -/ theorem verschiebung_is_poly {p : ℕ} [hp : fact (nat.prime p)] : is_poly p fun (R : Type u_1) (_Rcr : comm_ring R) => ⇑verschiebung := verschiebung_fun_is_poly p /-- verschiebung is a natural transformation -/ @[simp] theorem map_verschiebung {p : ℕ} {R : Type u_1} {S : Type u_2} [hp : fact (nat.prime p)] [comm_ring R] [comm_ring S] (f : R →+* S) (x : witt_vector p R) : coe_fn (map f) (coe_fn verschiebung x) = coe_fn verschiebung (coe_fn (map f) x) := sorry theorem ghost_component_zero_verschiebung {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) : coe_fn (ghost_component 0) (coe_fn verschiebung x) = 0 := ghost_component_zero_verschiebung_fun x theorem ghost_component_verschiebung {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) (n : ℕ) : coe_fn (ghost_component (n + 1)) (coe_fn verschiebung x) = ↑p * coe_fn (ghost_component n) x := ghost_component_verschiebung_fun x n @[simp] theorem verschiebung_coeff_zero {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) : coeff (coe_fn verschiebung x) 0 = 0 := rfl -- simp_nf complains if this is simp theorem verschiebung_coeff_add_one {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) (n : ℕ) : coeff (coe_fn verschiebung x) (n + 1) = coeff x n := rfl @[simp] theorem verschiebung_coeff_succ {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) (n : ℕ) : coeff (coe_fn verschiebung x) (Nat.succ n) = coeff x n := rfl theorem aeval_verschiebung_poly {p : ℕ} {R : Type u_1} [hp : fact (nat.prime p)] [comm_ring R] (x : witt_vector p R) (n : ℕ) : coe_fn (mv_polynomial.aeval (coeff x)) (verschiebung_poly n) = coeff (coe_fn verschiebung x) n := aeval_verschiebung_poly' x n @[simp] theorem bind₁_verschiebung_poly_witt_polynomial {p : ℕ} [hp : fact (nat.prime p)] (n : ℕ) : coe_fn (mv_polynomial.bind₁ verschiebung_poly) (witt_polynomial p ℤ n) = ite (n = 0) 0 (↑p * witt_polynomial p ℤ (n - 1)) := sorry end Mathlib
f2467605c8085c06aaf352e5f75b0f93db4b7edc
1abd1ed12aa68b375cdef28959f39531c6e95b84
/src/algebra/continued_fractions/computation/terminates_iff_rat.lean
c3305ec8d05a571e2d114f019c8853649c651f60
[ "Apache-2.0" ]
permissive
jumpy4/mathlib
d3829e75173012833e9f15ac16e481e17596de0f
af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13
refs/heads/master
1,693,508,842,818
1,636,203,271,000
1,636,203,271,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
14,243
lean
/- Copyright (c) 2020 Kevin Kappelmann. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Kappelmann -/ import algebra.continued_fractions.computation.approximations import algebra.continued_fractions.computation.correctness_terminating import data.rat /-! # Termination of Continued Fraction Computations (`gcf.of`) ## Summary We show that the continued fraction for a value `v`, as defined in `algebra.continued_fractions.computation.basic`, terminates if and only if `v` corresponds to a rational number, that is `↑v = q` for some `q : ℚ`. ## Main Theorems - `generalized_continued_fraction.coe_of_rat` shows that `generalized_continued_fraction.of v = generalized_continued_fraction.of q` for `v : α` given that `↑v = q` and `q : ℚ`. - `generalized_continued_fraction.terminates_iff_rat` shows that `generalized_continued_fraction.of v` terminates if and only if `↑v = q` for some `q : ℚ`. ## Tags rational, continued fraction, termination -/ namespace generalized_continued_fraction open generalized_continued_fraction (of) variables {K : Type*} [linear_ordered_field K] [floor_ring K] /- We will have to constantly coerce along our structures in the following proofs using their provided map functions. -/ local attribute [simp] pair.map int_fract_pair.mapFr section rat_of_terminates /-! ### Terminating Continued Fractions Are Rational We want to show that the computation of a continued fraction `generalized_continued_fraction.of v` terminates if and only if `v ∈ ℚ`. In this section, we show the implication from left to right. We first show that every finite convergent corresponds to a rational number `q` and then use the finite correctness proof (`of_correctness_of_terminates`) of `generalized_continued_fraction.of` to show that `v = ↑q`. -/ variables (v : K) (n : ℕ) lemma exists_gcf_pair_rat_eq_of_nth_conts_aux : ∃ (conts : pair ℚ), (of v).continuants_aux n = (conts.map coe : pair K) := nat.strong_induction_on n begin clear n, let g := of v, assume n IH, rcases n with _|_|n, -- n = 0 { suffices : ∃ (gp : pair ℚ), pair.mk (1 : K) 0 = gp.map coe, by simpa [continuants_aux], use (pair.mk 1 0), simp }, -- n = 1 { suffices : ∃ (conts : pair ℚ), pair.mk g.h 1 = conts.map coe, by simpa [continuants_aux], use (pair.mk ⌊v⌋ 1), simp }, -- 2 ≤ n { cases (IH (n + 1) $ lt_add_one (n + 1)) with pred_conts pred_conts_eq, -- invoke the IH cases s_ppred_nth_eq : (g.s.nth n) with gp_n, -- option.none { use pred_conts, have : g.continuants_aux (n + 2) = g.continuants_aux (n + 1), from continuants_aux_stable_of_terminated (n + 1).le_succ s_ppred_nth_eq, simp only [this, pred_conts_eq] }, -- option.some { -- invoke the IH a second time cases (IH n $ lt_of_le_of_lt (n.le_succ) $ lt_add_one $ n + 1) with ppred_conts ppred_conts_eq, obtain ⟨a_eq_one, z, b_eq_z⟩ : gp_n.a = 1 ∧ ∃ (z : ℤ), gp_n.b = (z : K), from of_part_num_eq_one_and_exists_int_part_denom_eq s_ppred_nth_eq, -- finally, unfold the recurrence to obtain the required rational value. simp only [a_eq_one, b_eq_z, (continuants_aux_recurrence s_ppred_nth_eq ppred_conts_eq pred_conts_eq)], use (next_continuants 1 (z : ℚ) ppred_conts pred_conts), cases ppred_conts, cases pred_conts, simp [next_continuants, next_numerator, next_denominator] } } end lemma exists_gcf_pair_rat_eq_nth_conts : ∃ (conts : pair ℚ), (of v).continuants n = (conts.map coe : pair K) := by { rw [nth_cont_eq_succ_nth_cont_aux], exact (exists_gcf_pair_rat_eq_of_nth_conts_aux v $ n + 1) } lemma exists_rat_eq_nth_numerator : ∃ (q : ℚ), (of v).numerators n = (q : K) := begin rcases (exists_gcf_pair_rat_eq_nth_conts v n) with ⟨⟨a, _⟩, nth_cont_eq⟩, use a, simp [num_eq_conts_a, nth_cont_eq], end lemma exists_rat_eq_nth_denominator : ∃ (q : ℚ), (of v).denominators n = (q : K) := begin rcases (exists_gcf_pair_rat_eq_nth_conts v n) with ⟨⟨_, b⟩, nth_cont_eq⟩, use b, simp [denom_eq_conts_b, nth_cont_eq] end /-- Every finite convergent corresponds to a rational number. -/ lemma exists_rat_eq_nth_convergent : ∃ (q : ℚ), (of v).convergents n = (q : K) := begin rcases (exists_rat_eq_nth_numerator v n) with ⟨Aₙ, nth_num_eq⟩, rcases (exists_rat_eq_nth_denominator v n) with ⟨Bₙ, nth_denom_eq⟩, use (Aₙ / Bₙ), simp [nth_num_eq, nth_denom_eq, convergent_eq_num_div_denom] end variable {v} /-- Every terminating continued fraction corresponds to a rational number. -/ theorem exists_rat_eq_of_terminates (terminates : (of v).terminates) : ∃ (q : ℚ), v = ↑q := begin obtain ⟨n, v_eq_conv⟩ : ∃ n, v = (of v).convergents n, from of_correctness_of_terminates terminates, obtain ⟨q, conv_eq_q⟩ : ∃ (q : ℚ), (of v).convergents n = (↑q : K), from exists_rat_eq_nth_convergent v n, have : v = (↑q : K), from eq.trans v_eq_conv conv_eq_q, use [q, this] end end rat_of_terminates section rat_translation /-! ### Technical Translation Lemmas Before we can show that the continued fraction of a rational number terminates, we have to prove some technical translation lemmas. More precisely, in this section, we show that, given a rational number `q : ℚ` and value `v : K` with `v = ↑q`, the continued fraction of `q` and `v` coincide. In particular, we show that ```lean (↑(generalized_continued_fraction.of q : generalized_continued_fraction ℚ) : generalized_continued_fraction K) = generalized_continued_fraction.of v` ``` in `generalized_continued_fraction.coe_of_rat`. To do this, we proceed bottom-up, showing the correspondence between the basic functions involved in the computation first and then lift the results step-by-step. -/ /- The lifting works for arbitrary linear ordered fields with a floor function. -/ variables {v : K} {q : ℚ} (v_eq_q : v = (↑q : K)) (n : ℕ) include v_eq_q /-! First, we show the correspondence for the very basic functions in `generalized_continued_fraction.int_fract_pair`. -/ namespace int_fract_pair lemma coe_of_rat_eq : ((int_fract_pair.of q).mapFr coe : int_fract_pair K) = int_fract_pair.of v := by simp [int_fract_pair.of, v_eq_q, int.fract] lemma coe_stream_nth_rat_eq : ((int_fract_pair.stream q n).map (mapFr coe) : option $ int_fract_pair K) = int_fract_pair.stream v n := begin induction n with n IH, case nat.zero : { simp [int_fract_pair.stream, (coe_of_rat_eq v_eq_q)] }, case nat.succ : { rw v_eq_q at IH, cases stream_q_nth_eq : (int_fract_pair.stream q n) with ifp_n, case option.none : { simp [int_fract_pair.stream, IH.symm, v_eq_q, stream_q_nth_eq] }, case option.some : { cases ifp_n with b fr, cases decidable.em (fr = 0) with fr_zero fr_ne_zero, { simp [int_fract_pair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_zero] }, { replace IH : some (int_fract_pair.mk b ↑fr) = int_fract_pair.stream ↑q n, by rwa [stream_q_nth_eq] at IH, have : (fr : K)⁻¹ = ((fr⁻¹ : ℚ) : K), by norm_cast, have coe_of_fr := (coe_of_rat_eq this), simp [int_fract_pair.stream, IH.symm, v_eq_q, stream_q_nth_eq, fr_ne_zero], unfold_coes, simpa [coe_of_fr] } } } end lemma coe_stream_rat_eq : ((int_fract_pair.stream q).map (option.map (mapFr coe)) : stream $ option $ int_fract_pair K) = int_fract_pair.stream v := by { funext n, exact (int_fract_pair.coe_stream_nth_rat_eq v_eq_q n) } end int_fract_pair /-! Now we lift the coercion results to the continued fraction computation. -/ lemma coe_of_h_rat_eq : (↑((of q).h : ℚ) : K) = (of v).h := begin unfold of int_fract_pair.seq1, rw ←(int_fract_pair.coe_of_rat_eq v_eq_q), simp end lemma coe_of_s_nth_rat_eq : (((of q).s.nth n).map (pair.map coe) : option $ pair K) = (of v).s.nth n := begin simp only [of, int_fract_pair.seq1, seq.map_nth, seq.nth_tail], simp only [seq.nth], rw [←(int_fract_pair.coe_stream_rat_eq v_eq_q)], rcases succ_nth_stream_eq : (int_fract_pair.stream q (n + 1)) with _ | ⟨_, _⟩; simp [stream.map, stream.nth, succ_nth_stream_eq] end lemma coe_of_s_rat_eq : (((of q).s).map (pair.map coe) : seq $ pair K) = (of v).s := by { ext n, rw ←(coe_of_s_nth_rat_eq v_eq_q), refl } /-- Given `(v : K), (q : ℚ), and v = q`, we have that `gcf.of q = gcf.of v` -/ lemma coe_of_rat_eq : (⟨(of q).h, (of q).s.map (pair.map coe)⟩ : generalized_continued_fraction K) = of v := begin cases gcf_v_eq : (of v) with h s, subst v, obtain rfl : ↑⌊↑q⌋ = h, by { injection gcf_v_eq }, simp [coe_of_h_rat_eq rfl, coe_of_s_rat_eq rfl, gcf_v_eq] end lemma of_terminates_iff_of_rat_terminates {v : K} {q : ℚ} (v_eq_q : v = (q : K)) : (of v).terminates ↔ (of q).terminates := begin split; intro h; cases h with n h; use n; simp only [seq.terminated_at, (coe_of_s_nth_rat_eq v_eq_q n).symm] at h ⊢; cases ((of q).s.nth n); trivial end end rat_translation section terminates_of_rat /-! ### Continued Fractions of Rationals Terminate Finally, we show that the continued fraction of a rational number terminates. The crucial insight is that, given any `q : ℚ` with `0 < q < 1`, the numerator of `int.fract q` is smaller than the numerator of `q`. As the continued fraction computation recursively operates on the fractional part of a value `v` and `0 ≤ int.fract v < 1`, we infer that the numerator of the fractional part in the computation decreases by at least one in each step. As `0 ≤ int.fract v`, this process must stop after finite number of steps, and the computation hence terminates. -/ namespace int_fract_pair variables {q : ℚ} {n : ℕ} /-- Shows that for any `q : ℚ` with `0 < q < 1`, the numerator of the fractional part of `int_fract_pair.of q⁻¹` is smaller than the numerator of `q`. -/ lemma of_inv_fr_num_lt_num_of_pos (q_pos : 0 < q) : (int_fract_pair.of q⁻¹).fr.num < q.num := rat.fract_inv_num_lt_num_of_pos q_pos /-- Shows that the sequence of numerators of the fractional parts of the stream is strictly antitone. -/ lemma stream_succ_nth_fr_num_lt_nth_fr_num_rat {ifp_n ifp_succ_n : int_fract_pair ℚ} (stream_nth_eq : int_fract_pair.stream q n = some ifp_n) (stream_succ_nth_eq : int_fract_pair.stream q (n + 1) = some ifp_succ_n) : ifp_succ_n.fr.num < ifp_n.fr.num := begin obtain ⟨ifp_n', stream_nth_eq', ifp_n_fract_ne_zero, int_fract_pair.of_eq_ifp_succ_n⟩ : ∃ ifp_n', int_fract_pair.stream q n = some ifp_n' ∧ ifp_n'.fr ≠ 0 ∧ int_fract_pair.of ifp_n'.fr⁻¹ = ifp_succ_n, from succ_nth_stream_eq_some_iff.elim_left stream_succ_nth_eq, have : ifp_n = ifp_n', by injection (eq.trans stream_nth_eq.symm stream_nth_eq'), cases this, rw [←int_fract_pair.of_eq_ifp_succ_n], cases (nth_stream_fr_nonneg_lt_one stream_nth_eq) with zero_le_ifp_n_fract ifp_n_fract_lt_one, have : 0 < ifp_n.fr, from (lt_of_le_of_ne zero_le_ifp_n_fract $ ifp_n_fract_ne_zero.symm), exact (of_inv_fr_num_lt_num_of_pos this) end lemma stream_nth_fr_num_le_fr_num_sub_n_rat : ∀ {ifp_n : int_fract_pair ℚ}, int_fract_pair.stream q n = some ifp_n → ifp_n.fr.num ≤ (int_fract_pair.of q).fr.num - n := begin induction n with n IH, case nat.zero { assume ifp_zero stream_zero_eq, have : int_fract_pair.of q = ifp_zero, by injection stream_zero_eq, simp [le_refl, this.symm] }, case nat.succ { assume ifp_succ_n stream_succ_nth_eq, suffices : ifp_succ_n.fr.num + 1 ≤ (int_fract_pair.of q).fr.num - n, by { rw [int.coe_nat_succ, sub_add_eq_sub_sub], solve_by_elim [le_sub_right_of_add_le] }, rcases (succ_nth_stream_eq_some_iff.elim_left stream_succ_nth_eq) with ⟨ifp_n, stream_nth_eq, -⟩, have : ifp_succ_n.fr.num < ifp_n.fr.num, from stream_succ_nth_fr_num_lt_nth_fr_num_rat stream_nth_eq stream_succ_nth_eq, have : ifp_succ_n.fr.num + 1 ≤ ifp_n.fr.num, from int.add_one_le_of_lt this, exact (le_trans this (IH stream_nth_eq)) } end lemma exists_nth_stream_eq_none_of_rat (q : ℚ) : ∃ (n : ℕ), int_fract_pair.stream q n = none := begin let fract_q_num := (int.fract q).num, let n := fract_q_num.nat_abs + 1, cases stream_nth_eq : (int_fract_pair.stream q n) with ifp, { use n, exact stream_nth_eq }, { -- arrive at a contradiction since the numerator decreased num + 1 times but every fractional -- value is nonnegative. have ifp_fr_num_le_q_fr_num_sub_n : ifp.fr.num ≤ fract_q_num - n, from stream_nth_fr_num_le_fr_num_sub_n_rat stream_nth_eq, have : fract_q_num - n = -1, by { have : 0 ≤ fract_q_num, from rat.num_nonneg_iff_zero_le.elim_right (int.fract_nonneg q), simp [(int.nat_abs_of_nonneg this), sub_add_eq_sub_sub_swap, sub_right_comm] }, have : ifp.fr.num ≤ -1, by rwa this at ifp_fr_num_le_q_fr_num_sub_n, have : 0 ≤ ifp.fr, from (nth_stream_fr_nonneg_lt_one stream_nth_eq).left, have : 0 ≤ ifp.fr.num, from rat.num_nonneg_iff_zero_le.elim_right this, linarith } end end int_fract_pair /-- The continued fraction of a rational number terminates. -/ theorem terminates_of_rat (q : ℚ) : (of q).terminates := exists.elim (int_fract_pair.exists_nth_stream_eq_none_of_rat q) ( assume n stream_nth_eq_none, exists.intro n ( have int_fract_pair.stream q (n + 1) = none, from int_fract_pair.stream_is_seq q stream_nth_eq_none, (of_terminated_at_n_iff_succ_nth_int_fract_pair_stream_eq_none.elim_right this) ) ) end terminates_of_rat /-- The continued fraction `generalized_continued_fraction.of v` terminates if and only if `v ∈ ℚ`. -/ theorem terminates_iff_rat (v : K) : (of v).terminates ↔ ∃ (q : ℚ), v = (q : K) := iff.intro ( assume terminates_v : (of v).terminates, show ∃ (q : ℚ), v = (q : K), from exists_rat_eq_of_terminates terminates_v ) ( assume exists_q_eq_v : ∃ (q : ℚ), v = (↑q : K), exists.elim exists_q_eq_v ( assume q, assume v_eq_q : v = ↑q, have (of q).terminates, from terminates_of_rat q, (of_terminates_iff_of_rat_terminates v_eq_q).elim_right this ) ) end generalized_continued_fraction
6438bbca422c4f3bb5d32b85fe47f8a4082f6457
ce6917c5bacabee346655160b74a307b4a5ab620
/src/ch3/ex0504.lean
16bbdaadbfca53501c3856cf8abc992e483bef68
[]
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
132
lean
open classical variable p : Prop example (h : ¬¬p) : p := by_contradiction (assume h1 : ¬p, show false, from h h1)
7c25a06f4d5c754ba5c44740c120ddaf96a917ac
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/tests/lean/var2.lean
8dff452c12e43d0b7ac847f4a9be041037ad2724
[ "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
176
lean
-- section universe l variable A : Type.{l} variable a : A parameter B : Type.{l} parameter b : B definition foo := fun (H : A = B), cast H a = b end check foo
287868b6fc49378620a4c7636542f74f4e5cf234
63abd62053d479eae5abf4951554e1064a4c45b4
/test/library_search/nat.lean
a8f8b1f6604bc4ddf71737d818a1656fe09c958d
[ "Apache-2.0" ]
permissive
Lix0120/mathlib
0020745240315ed0e517cbf32e738d8f9811dd80
e14c37827456fc6707f31b4d1d16f1f3a3205e91
refs/heads/master
1,673,102,855,024
1,604,151,044,000
1,604,151,044,000
308,930,245
0
0
Apache-2.0
1,604,164,710,000
1,604,163,547,000
null
UTF-8
Lean
false
false
2,471
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import tactic.suggest import data.nat.basic namespace test.library_search /- Turn off trace messages so they don't pollute the test build: -/ set_option trace.silence_library_search true /- For debugging purposes, we can display the list of lemmas: -/ -- set_option trace.suggest true def lt_one (n : ℕ) := n < 1 lemma zero_lt_one (n : ℕ) (h : n = 0) : lt_one n := by subst h; dsimp [lt_one]; simp -- Verify that calls to solve_by_elim to discharge subgoals use `rfl` example : lt_one 0 := by library_search example {n m : ℕ} (h : m < n) : m ≤ n - 1 := by library_search -- says: `exact nat.le_pred_of_lt h` example (a b : ℕ) : 0 < a → 0 < b → 0 < a + b := by library_search -- says: `exact add_pos` section synonym -- Synonym `>` for `<` in the goal example (a b : ℕ) : 0 < a → 0 < b → a + b > 0 := by library_search -- says: `exact add_pos` -- Synonym `>` for `<` in another part of the goal example (a b : ℕ) : a > 0 → 0 < b → 0 < a + b := by library_search -- says: `exact add_pos` end synonym example {a b c : ℕ} (ha : a > 0) (w : b ∣ c) : a * b ∣ a * c := by library_search -- exact mul_dvd_mul_left a w -- We have control of how `library_search` uses `solve_by_elim`. -- In particular, we can add extra lemmas to the `solve_by_elim` step -- (i.e. for `library_search` to use to attempt to discharge subgoals -- after successfully applying a lemma from the library.) example {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) := begin library_search [add_lt_add], -- Says: `exact max_eq_left_of_lt (add_lt_add h₁ h₂)` end -- We can also use attributes: meta def ex_attr : user_attribute := { name := `ex, descr := "A lemma that should be applied by `library_search` when discharging subgoals." } run_cmd attribute.register ``ex_attr attribute [ex] add_lt_add example {a b c d: nat} (h₁ : a < c) (h₂ : b < d) : max (c + d) (a + b) = (c + d) := begin library_search with ex, -- Says: `exact max_eq_left_of_lt (add_lt_add h₁ h₂)` end example (a b : ℕ) (h : 0 < b) : (a * b) / b = a := by library_search -- Says: `exact nat.mul_div_left a h` example (a b : ℕ) (h : b ≠ 0) : (a * b) / b = a := begin success_if_fail { library_search }, library_search [nat.pos_iff_ne_zero.mpr], end end test.library_search
059f72e079deb729527f3e9199b7ccd276770f08
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/group_theory/coset.lean
33171bacdfb1bbb284c2c0dc67c6ee0278a24a14
[ "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
11,454
lean
/- Copyright (c) 2018 Mitchell Rowett. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mitchell Rowett, Scott Morrison -/ import group_theory.subgroup data.equiv.basic data.quot open set function variable {α : Type*} @[to_additive left_add_coset] def left_coset [has_mul α] (a : α) (s : set α) : set α := (λ x, a * x) '' s attribute [to_additive left_add_coset.equations._eqn_1] left_coset.equations._eqn_1 @[to_additive right_add_coset] def right_coset [has_mul α] (s : set α) (a : α) : set α := (λ x, x * a) '' s attribute [to_additive right_add_coset.equations._eqn_1] right_coset.equations._eqn_1 local infix ` *l `:70 := left_coset local infix ` +l `:70 := left_add_coset local infix ` *r `:70 := right_coset local infix ` +r `:70 := right_add_coset section coset_mul variable [has_mul α] @[to_additive mem_left_add_coset] lemma mem_left_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : a * x ∈ a *l s := mem_image_of_mem (λ b : α, a * b) hxS @[to_additive mem_right_add_coset] lemma mem_right_coset {s : set α} {x : α} (a : α) (hxS : x ∈ s) : x * a ∈ s *r a := mem_image_of_mem (λ b : α, b * a) hxS @[to_additive left_add_coset_equiv] def left_coset_equiv (s : set α) (a b : α) := a *l s = b *l s @[to_additive left_add_coset_equiv_rel] lemma left_coset_equiv_rel (s : set α) : equivalence (left_coset_equiv s) := mk_equivalence (left_coset_equiv s) (λ a, rfl) (λ a b, eq.symm) (λ a b c, eq.trans) end coset_mul section coset_semigroup variable [semigroup α] @[simp] lemma left_coset_assoc (s : set α) (a b : α) : a *l (b *l s) = (a * b) *l s := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] attribute [to_additive left_add_coset_assoc] left_coset_assoc @[simp] lemma right_coset_assoc (s : set α) (a b : α) : s *r a *r b = s *r (a * b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] attribute [to_additive right_add_coset_assoc] right_coset_assoc @[to_additive left_add_coset_right_add_coset] lemma left_coset_right_coset (s : set α) (a b : α) : a *l s *r b = a *l (s *r b) := by simp [left_coset, right_coset, (image_comp _ _ _).symm, function.comp, mul_assoc] end coset_semigroup section coset_monoid variables [monoid α] (s : set α) @[simp] lemma one_left_coset : 1 *l s = s := set.ext $ by simp [left_coset] attribute [to_additive zero_left_add_coset] one_left_coset @[simp] lemma right_coset_one : s *r 1 = s := set.ext $ by simp [right_coset] attribute [to_additive right_add_coset_zero] right_coset_one end coset_monoid section coset_submonoid open is_submonoid variables [monoid α] (s : set α) [is_submonoid s] @[to_additive mem_own_left_add_coset] lemma mem_own_left_coset (a : α) : a ∈ a *l s := suffices a * 1 ∈ a *l s, by simpa, mem_left_coset a (one_mem s) @[to_additive mem_own_right_add_coset] lemma mem_own_right_coset (a : α) : a ∈ s *r a := suffices 1 * a ∈ s *r a, by simpa, mem_right_coset a (one_mem s) @[to_additive mem_left_add_coset_left_add_coset] lemma mem_left_coset_left_coset {a : α} (ha : a *l s = s) : a ∈ s := by rw [←ha]; exact mem_own_left_coset s a @[to_additive mem_right_add_coset_right_add_coset] lemma mem_right_coset_right_coset {a : α} (ha : s *r a = s) : a ∈ s := by rw [←ha]; exact mem_own_right_coset s a end coset_submonoid section coset_group variables [group α] {s : set α} {x : α} @[to_additive mem_left_add_coset_iff] lemma mem_left_coset_iff (a : α) : x ∈ a *l s ↔ a⁻¹ * x ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨a⁻¹ * x, h, by simp⟩) @[to_additive mem_right_add_coset_iff] lemma mem_right_coset_iff (a : α) : x ∈ s *r a ↔ x * a⁻¹ ∈ s := iff.intro (assume ⟨b, hb, eq⟩, by simp [eq.symm, hb]) (assume h, ⟨x * a⁻¹, h, by simp⟩) end coset_group section coset_subgroup open is_submonoid open is_subgroup variables [group α] (s : set α) [is_subgroup s] @[to_additive left_add_coset_mem_left_add_coset] lemma left_coset_mem_left_coset {a : α} (ha : a ∈ s) : a *l s = s := set.ext $ by simp [mem_left_coset_iff, mul_mem_cancel_right s (inv_mem ha)] @[to_additive right_add_coset_mem_right_add_coset] lemma right_coset_mem_right_coset {a : α} (ha : a ∈ s) : s *r a = s := set.ext $ assume b, by simp [mem_right_coset_iff, mul_mem_cancel_left s (inv_mem ha)] @[to_additive normal_of_eq_add_cosets] theorem normal_of_eq_cosets [normal_subgroup s] (g : α) : g *l s = s *r g := set.ext $ assume a, by simp [mem_left_coset_iff, mem_right_coset_iff]; rw [mem_norm_comm_iff] @[to_additive eq_add_cosets_of_normal] theorem eq_cosets_of_normal (h : ∀ g, g *l s = s *r g) : normal_subgroup s := ⟨assume a ha g, show g * a * g⁻¹ ∈ s, by rw [← mem_right_coset_iff, ← h]; exact mem_left_coset g ha⟩ @[to_additive normal_iff_eq_add_cosets] theorem normal_iff_eq_cosets : normal_subgroup s ↔ ∀ g, g *l s = s *r g := ⟨@normal_of_eq_cosets _ _ s _, eq_cosets_of_normal s⟩ end coset_subgroup namespace quotient_group def left_rel [group α] (s : set α) [is_subgroup s] : setoid α := ⟨λ x y, x⁻¹ * y ∈ s, assume x, by simp [is_submonoid.one_mem], assume x y hxy, have (x⁻¹ * y)⁻¹ ∈ s, from is_subgroup.inv_mem hxy, by simpa using this, assume x y z hxy hyz, have x⁻¹ * y * (y⁻¹ * z) ∈ s, from is_submonoid.mul_mem hxy hyz, by simpa [mul_assoc] using this⟩ attribute [to_additive quotient_add_group.left_rel._proof_1] left_rel._proof_1 attribute [to_additive quotient_add_group.left_rel] left_rel attribute [to_additive quotient_add_group.left_rel.equations._eqn_1] left_rel.equations._eqn_1 /-- `quotient s` is the quotient type representing the left cosets of `s`. If `s` is a normal subgroup, `quotient s` is a group -/ def quotient [group α] (s : set α) [is_subgroup s] : Type* := quotient (left_rel s) attribute [to_additive quotient_add_group.quotient] quotient attribute [to_additive quotient_add_group.quotient.equations._eqn_1] quotient.equations._eqn_1 variables [group α] {s : set α} [is_subgroup s] @[to_additive quotient_add_group.mk] def mk (a : α) : quotient s := quotient.mk' a attribute [to_additive quotient_add_group.mk.equations._eqn_1] mk.equations._eqn_1 @[elab_as_eliminator, to_additive quotient_add_group.induction_on] lemma induction_on {C : quotient s → Prop} (x : quotient s) (H : ∀ z, C (quotient_group.mk z)) : C x := quotient.induction_on' x H attribute [elab_as_eliminator] quotient_add_group.induction_on @[to_additive quotient_add_group.has_coe] instance : has_coe α (quotient s) := ⟨mk⟩ attribute [to_additive quotient_add_group.has_coe.equations._eqn_1] has_coe.equations._eqn_1 @[elab_as_eliminator, to_additive quotient_add_group.induction_on'] lemma induction_on' {C : quotient s → Prop} (x : quotient s) (H : ∀ z : α, C z) : C x := quotient.induction_on' x H attribute [elab_as_eliminator] quotient_add_group.induction_on' @[to_additive quotient_add_group.inhabited] instance [group α] (s : set α) [is_subgroup s] : inhabited (quotient s) := ⟨((1 : α) : quotient s)⟩ attribute [to_additive quotient_add_group.inhabited.equations._eqn_1] inhabited.equations._eqn_1 @[to_additive quotient_add_group.eq] protected lemma eq {a b : α} : (a : quotient s) = b ↔ a⁻¹ * b ∈ s := quotient.eq' @[to_additive quotient_add_group.eq_class_eq_left_coset] lemma eq_class_eq_left_coset [group α] (s : set α) [is_subgroup s] (g : α) : {x : α | (x : quotient s) = g} = left_coset g s := set.ext $ λ z, by rw [mem_left_coset_iff, set.mem_set_of_eq, eq_comm, quotient_group.eq] end quotient_group namespace is_subgroup open quotient_group variables [group α] {s : set α} def left_coset_equiv_subgroup (g : α) : left_coset g s ≃ s := ⟨λ x, ⟨g⁻¹ * x.1, (mem_left_coset_iff _).1 x.2⟩, λ x, ⟨g * x.1, x.1, x.2, rfl⟩, λ ⟨x, hx⟩, subtype.eq $ by simp, λ ⟨g, hg⟩, subtype.eq $ by simp⟩ attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._match_2] left_coset_equiv_subgroup._match_2 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._match_1] left_coset_equiv_subgroup._match_1 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._proof_4] left_coset_equiv_subgroup._proof_4 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._proof_3] left_coset_equiv_subgroup._proof_3 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._proof_2] left_coset_equiv_subgroup._proof_2 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._proof_1] left_coset_equiv_subgroup._proof_1 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup] left_coset_equiv_subgroup attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup.equations._eqn_1] left_coset_equiv_subgroup.equations._eqn_1 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._match_1.equations._eqn_1] left_coset_equiv_subgroup._match_1.equations._eqn_1 attribute [to_additive is_add_subgroup.left_add_coset_equiv_subgroup._match_2.equations._eqn_1] left_coset_equiv_subgroup._match_2.equations._eqn_1 noncomputable def group_equiv_quotient_times_subgroup (hs : is_subgroup s) : α ≃ (quotient s × s) := calc α ≃ Σ L : quotient s, {x : α // (x : quotient s)= L} : equiv.equiv_fib quotient_group.mk ... ≃ Σ L : quotient s, left_coset (quotient.out' L) s : equiv.sigma_congr_right (λ L, begin rw ← eq_class_eq_left_coset, show {x // quotient.mk' x = L} ≃ {x : α // quotient.mk' x = quotient.mk' _}, simp [-quotient.eq'] end) ... ≃ Σ L : quotient s, s : equiv.sigma_congr_right (λ L, left_coset_equiv_subgroup _) ... ≃ (quotient s × s) : equiv.sigma_equiv_prod _ _ attribute [to_additive is_add_subgroup.add_group_equiv_quotient_times_subgroup._proof_2] group_equiv_quotient_times_subgroup._proof_2 attribute [to_additive is_add_subgroup.add_group_equiv_quotient_times_subgroup._proof_1] group_equiv_quotient_times_subgroup._proof_1 attribute [to_additive is_add_subgroup.add_group_equiv_quotient_times_subgroup] group_equiv_quotient_times_subgroup attribute [to_additive is_add_subgroup.add_group_equiv_quotient_times_subgroup.equations._eqn_1] group_equiv_quotient_times_subgroup.equations._eqn_1 end is_subgroup namespace quotient_group variables [group α] noncomputable def preimage_mk_equiv_subgroup_times_set (s : set α) [is_subgroup s] (t : set (quotient s)) : quotient_group.mk ⁻¹' t ≃ (s × t) := have h : ∀ {x : quotient s} {a : α}, x ∈ t → a ∈ s → (quotient.mk' (quotient.out' x * a) : quotient s) = quotient.mk' (quotient.out' x) := λ x a hx ha, quotient.sound' (show (quotient.out' x * a)⁻¹ * quotient.out' x ∈ s, from (is_subgroup.inv_mem_iff _).1 $ by rwa [mul_inv_rev, inv_inv, ← mul_assoc, inv_mul_self, one_mul]), { to_fun := λ ⟨a, ha⟩, ⟨⟨(quotient.out' (quotient.mk' a))⁻¹ * a, @quotient.exact' _ (left_rel s) _ _ $ (quotient.out_eq' _)⟩, ⟨quotient.mk' a, ha⟩⟩, inv_fun := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, ⟨quotient.out' x * a, show quotient.mk' _ ∈ t, by simp [h hx ha, hx]⟩, left_inv := λ ⟨a, ha⟩, subtype.eq $ show _ * _ = a, by simp, right_inv := λ ⟨⟨a, ha⟩, ⟨x, hx⟩⟩, show (_, _) = _, by simp [h hx ha] } end quotient_group
c4e515990801f4662a6048805506643341d51cdf
a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7
/src/linear_algebra/bilinear_form.lean
bdeb5de8a72b779c4c6f8e89e94c24606f990eb2
[ "Apache-2.0" ]
permissive
kmill/mathlib
ea5a007b67ae4e9e18dd50d31d8aa60f650425ee
1a419a9fea7b959317eddd556e1bb9639f4dcc05
refs/heads/master
1,668,578,197,719
1,593,629,163,000
1,593,629,163,000
276,482,939
0
0
null
1,593,637,960,000
1,593,637,959,000
null
UTF-8
Lean
false
false
28,124
lean
/- Copyright (c) 2018 Andreas Swerdlow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Andreas Swerdlow -/ import linear_algebra.matrix import linear_algebra.tensor_product import linear_algebra.nonsingular_inverse /-! # Bilinear form This file defines a bilinear form over a module. Basic ideas such as orthogonality are also introduced, as well as reflexivive, symmetric and alternating bilinear forms. Adjoints of linear maps with respect to a bilinear form are also introduced. A bilinear form on an R-module M, is a function from M x M to R, that is linear in both arguments ## Notations Given any term B of type bilin_form, due to a coercion, can use the notation B x y to refer to the function field, ie. B x y = B.bilin x y. ## References * <https://en.wikipedia.org/wiki/Bilinear_form> ## Tags Bilinear form, -/ open_locale big_operators universes u v w /-- A bilinear form over a module -/ structure bilin_form (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] := (bilin : M → M → R) (bilin_add_left : ∀ (x y z : M), bilin (x + y) z = bilin x z + bilin y z) (bilin_smul_left : ∀ (a : R) (x y : M), bilin (a • x) y = a * (bilin x y)) (bilin_add_right : ∀ (x y z : M), bilin x (y + z) = bilin x y + bilin x z) (bilin_smul_right : ∀ (a : R) (x y : M), bilin x (a • y) = a * (bilin x y)) /-- A map with two arguments that is linear in both is a bilinear form -/ def linear_map.to_bilin {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M] (f : M →ₗ[R] M →ₗ[R] R) : bilin_form R M := { bilin := λ x y, f x y, bilin_add_left := λ x y z, (linear_map.map_add f x y).symm ▸ linear_map.add_apply (f x) (f y) z, bilin_smul_left := λ a x y, by {rw linear_map.map_smul, rw linear_map.smul_apply, rw smul_eq_mul}, bilin_add_right := λ x y z, linear_map.map_add (f x) y z, bilin_smul_right := λ a x y, linear_map.map_smul (f x) a y } namespace bilin_form variables {R : Type u} {M : Type v} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M} instance : has_coe_to_fun (bilin_form R M) := ⟨_, λ B, B.bilin⟩ @[simp] lemma coe_fn_mk (f : M → M → R) (h₁ h₂ h₃ h₄) : (bilin_form.mk f h₁ h₂ h₃ h₄ : M → M → R) = f := rfl lemma coe_fn_congr : Π {x x' y y' : M}, x = x' → y = y' → B x y = B x' y' | _ _ _ _ rfl rfl := rfl lemma add_left (x y z : M) : B (x + y) z = B x z + B y z := bilin_add_left B x y z lemma smul_left (a : R) (x y : M) : B (a • x) y = a * (B x y) := bilin_smul_left B a x y lemma add_right (x y z : M) : B x (y + z) = B x y + B x z := bilin_add_right B x y z lemma smul_right (a : R) (x y : M) : B x (a • y) = a * (B x y) := bilin_smul_right B a x y lemma zero_left (x : M) : B 0 x = 0 := by {rw [←@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul]} lemma zero_right (x : M) : B x 0 = 0 := by rw [←@zero_smul _ _ _ _ _ (0 : M), smul_right, ring.zero_mul] lemma neg_left (x y : M) : B (-x) y = -(B x y) := by rw [←@neg_one_smul R _ _, smul_left, neg_one_mul] lemma neg_right (x y : M) : B x (-y) = -(B x y) := by rw [←@neg_one_smul R _ _, smul_right, neg_one_mul] lemma sub_left (x y z : M) : B (x - y) z = B x z - B y z := by rw [sub_eq_add_neg, add_left, neg_left]; refl lemma sub_right (x y z : M) : B x (y - z) = B x y - B x z := by rw [sub_eq_add_neg, add_right, neg_right]; refl variable {D : bilin_form R M} @[ext] lemma ext (H : ∀ (x y : M), B x y = D x y) : B = D := by {cases B, cases D, congr, funext, exact H _ _} instance : add_comm_group (bilin_form R M) := { add := λ B D, { bilin := λ x y, B x y + D x y, bilin_add_left := λ x y z, by {rw add_left, rw add_left, ac_refl}, bilin_smul_left := λ a x y, by {rw [smul_left, smul_left, mul_add]}, bilin_add_right := λ x y z, by {rw add_right, rw add_right, ac_refl}, bilin_smul_right := λ a x y, by {rw [smul_right, smul_right, mul_add]} }, add_assoc := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin coe_fn has_coe_to_fun.coe bilin, rw add_assoc}, zero := { bilin := λ x y, 0, bilin_add_left := λ x y z, (add_zero 0).symm, bilin_smul_left := λ a x y, (mul_zero a).symm, bilin_add_right := λ x y z, (zero_add 0).symm, bilin_smul_right := λ a x y, (mul_zero a).symm }, zero_add := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_add}, add_zero := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_zero}, neg := λ B, { bilin := λ x y, - (B.1 x y), bilin_add_left := λ x y z, by rw [bilin_add_left, neg_add], bilin_smul_left := λ a x y, by rw [bilin_smul_left, mul_neg_eq_neg_mul_symm], bilin_add_right := λ x y z, by rw [bilin_add_right, neg_add], bilin_smul_right := λ a x y, by rw [bilin_smul_right, mul_neg_eq_neg_mul_symm] }, add_left_neg := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw neg_add_self}, add_comm := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_comm} } lemma add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl lemma neg_apply (x y : M) : (-B) x y = -(B x y) := rfl instance : inhabited (bilin_form R M) := ⟨0⟩ section variables {R₂ : Type*} [comm_ring R₂] [module R₂ M] (F : bilin_form R₂ M) (f : M → M) instance to_module : module R₂ (bilin_form R₂ M) := { smul := λ c B, { bilin := λ x y, c * B x y, bilin_add_left := λ x y z, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, left_distrib]}, bilin_smul_left := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_smul_left, ←mul_assoc, mul_comm c, mul_assoc]}, bilin_add_right := λ x y z, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_right, left_distrib]}, bilin_smul_right := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_smul_right, ←mul_assoc, mul_comm c, mul_assoc]} }, smul_add := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw left_distrib}, add_smul := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw right_distrib}, mul_smul := λ a c D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_assoc}, one_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_mul}, zero_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_mul}, smul_zero := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_zero} } lemma smul_apply (a : R₂) (x y : M) : (a • F) x y = a • (F x y) := rfl /-- `B.to_linear_map` applies B on the left argument, then the right. -/ def to_linear_map : M →ₗ[R₂] M →ₗ[R₂] R₂ := linear_map.mk₂ R₂ F.1 (bilin_add_left F) (bilin_smul_left F) (bilin_add_right F) (bilin_smul_right F) /-- Bilinear forms are equivalent to maps with two arguments that is linear in both. -/ def bilin_linear_map_equiv : (bilin_form R₂ M) ≃ₗ[R₂] (M →ₗ[R₂] M →ₗ[R₂] R₂) := { to_fun := to_linear_map, map_add' := λ B D, rfl, map_smul' := λ a B, rfl, inv_fun := linear_map.to_bilin, left_inv := λ B, by {ext, refl}, right_inv := λ B, by {ext, refl} } @[norm_cast] lemma coe_fn_to_linear_map (x : M) : ⇑(F.to_linear_map x) = F x := rfl lemma map_sum_left {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (w : M) : B (∑ i in t, g i) w = ∑ i in t, B (g i) w := show B.to_linear_map (∑ i in t, g i) w = ∑ i in t, B.to_linear_map (g i) w, by rw [B.to_linear_map.map_sum, linear_map.coe_fn_sum, finset.sum_apply] lemma map_sum_right {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (v : M) : B v (∑ i in t, g i) = ∑ i in t, B v (g i) := (B.to_linear_map v).map_sum end section comp variables {N : Type w} [add_comm_group N] [module R N] /-- Apply a linear map on the left and right argument of a bilinear form. -/ def comp (B : bilin_form R N) (l r : M →ₗ[R] N) : bilin_form R M := { bilin := λ x y, B (l x) (r y), bilin_add_left := λ x y z, by simp [add_left], bilin_smul_left := λ x y z, by simp [smul_left], bilin_add_right := λ x y z, by simp [add_right], bilin_smul_right := λ x y z, by simp [smul_right] } /-- Apply a linear map to the left argument of a bilinear form. -/ def comp_left (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M := B.comp f linear_map.id /-- Apply a linear map to the right argument of a bilinear form. -/ def comp_right (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M := B.comp linear_map.id f @[simp] lemma comp_left_comp_right (B : bilin_form R M) (l r : M →ₗ[R] M) : (B.comp_left l).comp_right r = B.comp l r := rfl @[simp] lemma comp_right_comp_left (B : bilin_form R M) (l r : M →ₗ[R] M) : (B.comp_right r).comp_left l = B.comp l r := rfl @[simp] lemma comp_apply (B : bilin_form R N) (l r : M →ₗ[R] N) (v w) : B.comp l r v w = B (l v) (r w) := rfl @[simp] lemma comp_left_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) : B.comp_left f v w = B (f v) w := rfl @[simp] lemma comp_right_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) : B.comp_right f v w = B v (f w) := rfl lemma comp_injective (B₁ B₂ : bilin_form R N) (l r : M →ₗ[R] N) (hₗ : function.surjective l) (hᵣ : function.surjective r) : B₁.comp l r = B₂.comp l r ↔ B₁ = B₂ := begin split; intros h, { -- B₁.comp l r = B₂.comp l r → B₁ = B₂ ext, cases hₗ x with x' hx, subst hx, cases hᵣ y with y' hy, subst hy, rw [←comp_apply, ←comp_apply, h], }, { -- B₁ = B₂ → B₁.comp l r = B₂.comp l r subst h, }, end end comp section lin_mul_lin variables {R₂ : Type*} [comm_ring R₂] [module R₂ M] {N : Type w} [add_comm_group N] [module R₂ N] /-- `lin_mul_lin f g` is the bilinear form mapping `x` and `y` to `f x * g y` -/ def lin_mul_lin (f g : M →ₗ[R₂] R₂) : bilin_form R₂ M := { bilin := λ x y, f x * g y, bilin_add_left := λ x y z, by simp [add_mul], bilin_smul_left := λ x y z, by simp [mul_assoc], bilin_add_right := λ x y z, by simp [mul_add], bilin_smul_right := λ x y z, by simp [mul_left_comm] } variables {f g : M →ₗ[R₂] R₂} @[simp] lemma lin_mul_lin_apply (x y) : lin_mul_lin f g x y = f x * g y := rfl @[simp] lemma lin_mul_lin_comp (l r : N →ₗ[R₂] M) : (lin_mul_lin f g).comp l r = lin_mul_lin (f.comp l) (g.comp r) := rfl @[simp] lemma lin_mul_lin_comp_left (l : M →ₗ[R₂] M) : (lin_mul_lin f g).comp_left l = lin_mul_lin (f.comp l) g := rfl @[simp] lemma lin_mul_lin_comp_right (r : M →ₗ[R₂] M) : (lin_mul_lin f g).comp_right r = lin_mul_lin f (g.comp r) := rfl end lin_mul_lin /-- The proposition that two elements of a bilinear form space are orthogonal -/ def is_ortho (B : bilin_form R M) (x y : M) : Prop := B x y = 0 lemma ortho_zero (x : M) : is_ortho B (0 : M) x := zero_left x section variables {R₃ : Type*} [domain R₃] [module R₃ M] {G : bilin_form R₃ M} theorem ortho_smul_left {x y : M} {a : R₃} (ha : a ≠ 0) : (is_ortho G x y) ↔ (is_ortho G (a • x) y) := begin dunfold is_ortho, split; intro H, { rw [smul_left, H, ring.mul_zero] }, { rw [smul_left, mul_eq_zero] at H, cases H, { trivial }, { exact H }} end theorem ortho_smul_right {x y : M} {a : R₃} (ha : a ≠ 0) : (is_ortho G x y) ↔ (is_ortho G x (a • y)) := begin dunfold is_ortho, split; intro H, { rw [smul_right, H, ring.mul_zero] }, { rw [smul_right, mul_eq_zero] at H, cases H, { trivial }, { exact H }} end end end bilin_form section matrix variables {R : Type u} [comm_ring R] variables {n o : Type w} [fintype n] [fintype o] open bilin_form finset matrix open_locale matrix /-- The linear map from `matrix n n R` to bilinear forms on `n → R`. -/ def matrix.to_bilin_formₗ : matrix n n R →ₗ[R] bilin_form R (n → R) := { to_fun := λ M, { bilin := λ v w, (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩, bilin_add_left := λ x y z, by simp [matrix.add_mul], bilin_smul_left := λ a x y, by simp, bilin_add_right := λ x y z, by simp [matrix.mul_add], bilin_smul_right := λ a x y, by simp }, map_add' := λ f g, by { ext, simp [add_apply, matrix.mul_add, matrix.add_mul] }, map_smul' := λ f g, by { ext, simp [smul_apply] } } /-- The map from `matrix n n R` to bilinear forms on `n → R`. -/ def matrix.to_bilin_form : matrix n n R → bilin_form R (n → R) := matrix.to_bilin_formₗ.to_fun lemma matrix.to_bilin_form_apply (M : matrix n n R) (v w : n → R) : (M.to_bilin_form : (n → R) → (n → R) → R) v w = (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩ := rfl variables [decidable_eq n] [decidable_eq o] /-- The linear map from bilinear forms on `n → R` to `matrix n n R`. -/ def bilin_form.to_matrixₗ : bilin_form R (n → R) →ₗ[R] matrix n n R := { to_fun := λ B i j, B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0), map_add' := λ f g, rfl, map_smul' := λ f g, rfl } /-- The map from bilinear forms on `n → R` to `matrix n n R`. -/ def bilin_form.to_matrix : bilin_form R (n → R) → matrix n n R := bilin_form.to_matrixₗ.to_fun lemma bilin_form.to_matrix_apply (B : bilin_form R (n → R)) (i j : n) : B.to_matrix i j = B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0) := rfl lemma bilin_form.to_matrix_smul (B : bilin_form R (n → R)) (x : R) : (x • B).to_matrix = x • B.to_matrix := by { ext, refl } open bilin_form lemma bilin_form.to_matrix_comp (B : bilin_form R (n → R)) (l r : (o → R) →ₗ[R] (n → R)) : (B.comp l r).to_matrix = l.to_matrixᵀ ⬝ B.to_matrix ⬝ r.to_matrix := begin ext i j, simp only [to_matrix_apply, comp_apply, mul_val, sum_mul], have sum_smul_eq : Π (f : (o → R) →ₗ[R] (n → R)) (i : o), f (λ n, ite (n = i) 1 0) = ∑ k, f.to_matrix k i • λ n, ite (n = k) (1 : R) 0, { intros f i, ext j, change f (λ n, ite (n = i) 1 0) j = (∑ k, λ n, f.to_matrix k i * ite (n = k) (1 : R) 0) j, simp [linear_map.to_matrix, linear_map.to_matrixₗ, eq_comm] }, simp_rw [sum_smul_eq, map_sum_right, map_sum_left, smul_right, mul_comm, smul_left], refl end lemma bilin_form.to_matrix_comp_left (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) : (B.comp_left f).to_matrix = f.to_matrixᵀ ⬝ B.to_matrix := by simp [comp_left, bilin_form.to_matrix_comp] lemma bilin_form.to_matrix_comp_right (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) : (B.comp_right f).to_matrix = B.to_matrix ⬝ f.to_matrix := by simp [comp_right, bilin_form.to_matrix_comp] lemma bilin_form.mul_to_matrix_mul (B : bilin_form R (n → R)) (M : matrix o n R) (N : matrix n o R) : M ⬝ B.to_matrix ⬝ N = (B.comp (Mᵀ.to_lin) (N.to_lin)).to_matrix := by { ext, simp [B.to_matrix_comp (Mᵀ.to_lin) (N.to_lin), to_lin_to_matrix] } lemma bilin_form.mul_to_matrix (B : bilin_form R (n → R)) (M : matrix n n R) : M ⬝ B.to_matrix = (B.comp_left (Mᵀ.to_lin)).to_matrix := by { ext, simp [B.to_matrix_comp_left (Mᵀ.to_lin), to_lin_to_matrix] } lemma bilin_form.to_matrix_mul (B : bilin_form R (n → R)) (M : matrix n n R) : B.to_matrix ⬝ M = (B.comp_right (M.to_lin)).to_matrix := by { ext, simp [B.to_matrix_comp_right (M.to_lin), to_lin_to_matrix] } @[simp] lemma to_matrix_to_bilin_form (B : bilin_form R (n → R)) : B.to_matrix.to_bilin_form = B := begin ext, rw [matrix.to_bilin_form_apply, B.mul_to_matrix_mul, bilin_form.to_matrix_apply, comp_apply], { apply coe_fn_congr; ext; simp [mul_vec], }, { apply_instance, }, end @[simp] lemma to_bilin_form_to_matrix (M : matrix n n R) : M.to_bilin_form.to_matrix = M := by { ext, simp [bilin_form.to_matrix_apply, matrix.to_bilin_form_apply, mul_val], } /-- Bilinear forms are linearly equivalent to matrices. -/ def bilin_form_equiv_matrix : bilin_form R (n → R) ≃ₗ[R] matrix n n R := { inv_fun := matrix.to_bilin_form, left_inv := to_matrix_to_bilin_form, right_inv := to_bilin_form_to_matrix, ..bilin_form.to_matrixₗ } lemma matrix.to_bilin_form_comp {n o : Type w} [fintype n] [fintype o] (M : matrix n n R) (P Q : matrix n o R) : M.to_bilin_form.comp P.to_lin Q.to_lin = (Pᵀ ⬝ M ⬝ Q).to_bilin_form := by { classical, rw [←to_matrix_to_bilin_form (Pᵀ ⬝ M ⬝ Q).to_bilin_form, ←to_matrix_to_bilin_form (M.to_bilin_form.comp P.to_lin Q.to_lin), bilin_form.to_matrix_comp, to_bilin_form_to_matrix, to_bilin_form_to_matrix, to_lin_to_matrix, to_lin_to_matrix], } end matrix namespace refl_bilin_form open refl_bilin_form bilin_form variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M} /-- The proposition that a bilinear form is reflexive -/ def is_refl (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = 0 → B y x = 0 variable (H : is_refl B) lemma eq_zero : ∀ {x y : M}, B x y = 0 → B y x = 0 := λ x y, H x y lemma ortho_sym {x y : M} : is_ortho B x y ↔ is_ortho B y x := ⟨eq_zero H, eq_zero H⟩ end refl_bilin_form namespace sym_bilin_form open sym_bilin_form bilin_form variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M} /-- The proposition that a bilinear form is symmetric -/ def is_sym (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = B y x variable (H : is_sym B) lemma sym (x y : M) : B x y = B y x := H x y lemma is_refl : refl_bilin_form.is_refl B := λ x y H1, H x y ▸ H1 lemma ortho_sym {x y : M} : is_ortho B x y ↔ is_ortho B y x := refl_bilin_form.ortho_sym (is_refl H) end sym_bilin_form namespace alt_bilin_form open alt_bilin_form bilin_form variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M} /-- The proposition that a bilinear form is alternating -/ def is_alt (B : bilin_form R M) : Prop := ∀ (x : M), B x x = 0 variable (H : is_alt B) include H lemma self_eq_zero (x : M) : B x x = 0 := H x lemma neg (x y : M) : - B x y = B y x := begin have H1 : B (x + y) (x + y) = 0, { exact self_eq_zero H (x + y) }, rw [add_left, add_right, add_right, self_eq_zero H, self_eq_zero H, ring.zero_add, ring.add_zero, add_eq_zero_iff_neg_eq] at H1, exact H1, end end alt_bilin_form namespace bilin_form section linear_adjoints variables {R : Type u} [comm_ring R] variables {M : Type v} [add_comm_group M] [module R M] variables {M₂ : Type w} [add_comm_group M₂] [module R M₂] variables (B B' : bilin_form R M) (B₂ : bilin_form R M₂) variables (f f' : M →ₗ[R] M₂) (g g' : M₂ →ₗ[R] M) /-- Given a pair of modules equipped with bilinear forms, this is the condition for a pair of maps between them to be mutually adjoint. -/ def is_adjoint_pair := ∀ ⦃x y⦄, B₂ (f x) y = B x (g y) variables {B B' B₂ f f' g g'} lemma is_adjoint_pair.eq (h : is_adjoint_pair B B₂ f g) : ∀ {x y}, B₂ (f x) y = B x (g y) := h lemma is_adjoint_pair_iff_comp_left_eq_comp_right (f g : module.End R M) : is_adjoint_pair B B' f g ↔ B'.comp_left f = B.comp_right g := begin split; intros h, { ext x y, rw [comp_left_apply, comp_right_apply], apply h, }, { intros x y, rw [←comp_left_apply, ←comp_right_apply], rw h, }, end lemma is_adjoint_pair_zero : is_adjoint_pair B B₂ 0 0 := λ x y, by simp only [bilin_form.zero_left, bilin_form.zero_right, linear_map.zero_apply] lemma is_adjoint_pair_id : is_adjoint_pair B B 1 1 := λ x y, rfl lemma is_adjoint_pair.add (h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B B₂ f' g') : is_adjoint_pair B B₂ (f + f') (g + g') := λ x y, by rw [linear_map.add_apply, linear_map.add_apply, add_left, add_right, h, h'] lemma is_adjoint_pair.sub (h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B B₂ f' g') : is_adjoint_pair B B₂ (f - f') (g - g') := λ x y, by rw [linear_map.sub_apply, linear_map.sub_apply, sub_left, sub_right, h, h'] lemma is_adjoint_pair.smul (c : R) (h : is_adjoint_pair B B₂ f g) : is_adjoint_pair B B₂ (c • f) (c • g) := λ x y, by rw [linear_map.smul_apply, linear_map.smul_apply, smul_left, smul_right, h] lemma is_adjoint_pair.comp {M₃ : Type v} [add_comm_group M₃] [module R M₃] {B₃ : bilin_form R M₃} {f' : M₂ →ₗ[R] M₃} {g' : M₃ →ₗ[R] M₂} (h : is_adjoint_pair B B₂ f g) (h' : is_adjoint_pair B₂ B₃ f' g') : is_adjoint_pair B B₃ (f'.comp f) (g.comp g') := λ x y, by rw [linear_map.comp_apply, linear_map.comp_apply, h', h] lemma is_adjoint_pair.mul {f g f' g' : module.End R M} (h : is_adjoint_pair B B f g) (h' : is_adjoint_pair B B f' g') : is_adjoint_pair B B (f * f') (g' * g) := λ x y, by rw [linear_map.mul_app, linear_map.mul_app, h, h'] variables (B B' B₂) /-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear forms on the underlying module. In the case that these two forms are identical, this is the usual concept of self adjointness. In the case that one of the forms is the negation of the other, this is the usual concept of skew adjointness. -/ def is_pair_self_adjoint (f : module.End R M) := is_adjoint_pair B B' f f /-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/ def is_pair_self_adjoint_submodule : submodule R (module.End R M) := { carrier := { f | is_pair_self_adjoint B B' f }, zero_mem' := is_adjoint_pair_zero, add_mem' := λ f g hf hg, hf.add hg, smul_mem' := λ c f h, h.smul c, } @[simp] lemma mem_is_pair_self_adjoint_submodule (f : module.End R M) : f ∈ is_pair_self_adjoint_submodule B B' ↔ is_pair_self_adjoint B B' f := by refl lemma is_pair_self_adjoint_equiv (e : M₂ ≃ₗ[R] M) (f : module.End R M) : is_pair_self_adjoint B B' f ↔ is_pair_self_adjoint (B.comp ↑e ↑e) (B'.comp ↑e ↑e) (e.symm.conj f) := begin have hₗ : (B'.comp ↑e ↑e).comp_left (e.symm.conj f) = (B'.comp_left f).comp ↑e ↑e := by { ext, simp [linear_equiv.symm_conj_apply], }, have hᵣ : (B.comp ↑e ↑e).comp_right (e.symm.conj f) = (B.comp_right f).comp ↑e ↑e := by { ext, simp [linear_equiv.conj_apply], }, have he : function.surjective (⇑(↑e : M₂ →ₗ[R] M) : M₂ → M) := e.surjective, show bilin_form.is_adjoint_pair _ _ _ _ ↔ bilin_form.is_adjoint_pair _ _ _ _, rw [is_adjoint_pair_iff_comp_left_eq_comp_right, is_adjoint_pair_iff_comp_left_eq_comp_right, hᵣ, hₗ, comp_injective _ _ ↑e ↑e he he], end /-- An endomorphism of a module is self-adjoint with respect to a bilinear form if it serves as an adjoint for itself. -/ def is_self_adjoint (f : module.End R M) := is_adjoint_pair B B f f /-- An endomorphism of a module is skew-adjoint with respect to a bilinear form if its negation serves as an adjoint. -/ def is_skew_adjoint (f : module.End R M) := is_adjoint_pair B B f (-f) lemma is_skew_adjoint_iff_neg_self_adjoint (f : module.End R M) : B.is_skew_adjoint f ↔ is_adjoint_pair (-B) B f f := show (∀ x y, B (f x) y = B x ((-f) y)) ↔ ∀ x y, B (f x) y = (-B) x (f y), by simp only [linear_map.neg_apply, bilin_form.neg_apply, bilin_form.neg_right] /-- The set of self-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact it is a Jordan subalgebra.) -/ def self_adjoint_submodule := is_pair_self_adjoint_submodule B B @[simp] lemma mem_self_adjoint_submodule (f : module.End R M) : f ∈ B.self_adjoint_submodule ↔ B.is_self_adjoint f := iff.rfl /-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact it is a Lie subalgebra.) -/ def skew_adjoint_submodule := is_pair_self_adjoint_submodule (-B) B @[simp] lemma mem_skew_adjoint_submodule (f : module.End R M) : f ∈ B.skew_adjoint_submodule ↔ B.is_skew_adjoint f := by { rw is_skew_adjoint_iff_neg_self_adjoint, exact iff.rfl, } end linear_adjoints end bilin_form section matrix_adjoints open_locale matrix variables {R : Type u} [comm_ring R] variables {n : Type w} [fintype n] variables (J J₂ A B : matrix n n R) /-- The condition for the square matrices `A`, `B` to be an adjoint pair with respect to the square matrices `J`, `J₂`. -/ def matrix.is_adjoint_pair := Aᵀ ⬝ J₂ = J ⬝ B /-- The condition for a square matrix `A` to be self-adjoint with respect to the square matrix `J`. -/ def matrix.is_self_adjoint := matrix.is_adjoint_pair J J A A /-- The condition for a square matrix `A` to be skew-adjoint with respect to the square matrix `J`. -/ def matrix.is_skew_adjoint := matrix.is_adjoint_pair J J A (-A) @[simp] lemma matrix_is_adjoint_pair_bilin_form : bilin_form.is_adjoint_pair J.to_bilin_form J₂.to_bilin_form A.to_lin B.to_lin ↔ matrix.is_adjoint_pair J J₂ A B:= begin classical, rw bilin_form.is_adjoint_pair_iff_comp_left_eq_comp_right, have h : ∀ (B B' : bilin_form R (n → R)), B = B' ↔ B.to_matrix = B'.to_matrix := λ B B', by { split; intros h, { rw h, }, { rw [←to_matrix_to_bilin_form B, h, to_matrix_to_bilin_form B'], }, }, rw [h, J₂.to_bilin_form.to_matrix_comp_left A.to_lin, J.to_bilin_form.to_matrix_comp_right B.to_lin, to_lin_to_matrix, to_lin_to_matrix, to_bilin_form_to_matrix, to_bilin_form_to_matrix], refl, end lemma matrix.is_adjoint_pair_equiv [decidable_eq n] (P : matrix n n R) (h : is_unit P) : (Pᵀ ⬝ J ⬝ P).is_adjoint_pair (Pᵀ ⬝ J ⬝ P) A B ↔ J.is_adjoint_pair J (P ⬝ A ⬝ P⁻¹) (P ⬝ B ⬝ P⁻¹) := have h' : is_unit P.det := P.is_unit_iff_is_unit_det.mp h, begin let u := P.nonsing_inv_unit h', let v := Pᵀ.nonsing_inv_unit (P.is_unit_det_transpose h'), let x := Aᵀ * Pᵀ * J, let y := J * P * B, suffices : x * ↑u = ↑v * y ↔ ↑v⁻¹ * x = y * ↑u⁻¹, { dunfold matrix.is_adjoint_pair, repeat { rw matrix.transpose_mul, }, simp only [←matrix.mul_eq_mul, ←mul_assoc, P.transpose_nonsing_inv h'], conv_lhs { to_rhs, rw [mul_assoc, mul_assoc], congr, skip, rw ←mul_assoc, }, conv_rhs { rw [mul_assoc, mul_assoc], conv { to_lhs, congr, skip, rw ←mul_assoc }, }, exact this, }, rw units.eq_mul_inv_iff_mul_eq, conv_rhs { rw mul_assoc, }, rw v.inv_mul_eq_iff_eq_mul, end variables [decidable_eq n] /-- The submodule of pair-self-adjoint matrices with respect to bilinear forms corresponding to given matrices `J`, `J₂`. -/ def pair_self_adjoint_matrices_submodule : submodule R (matrix n n R) := (bilin_form.is_pair_self_adjoint_submodule J.to_bilin_form J₂.to_bilin_form).map (@linear_equiv_matrix' n n _ _ R _ _) @[simp] lemma mem_pair_self_adjoint_matrices_submodule : A ∈ (pair_self_adjoint_matrices_submodule J J₂) ↔ matrix.is_adjoint_pair J J₂ A A := begin simp only [pair_self_adjoint_matrices_submodule,linear_equiv.coe_coe, linear_equiv_matrix'_apply, submodule.mem_map, bilin_form.mem_is_pair_self_adjoint_submodule], split, { rintros ⟨f, hf, hA⟩, have hf' : f = A.to_lin := by rw [←hA, to_matrix_to_lin], rw hf' at hf, rw ←matrix_is_adjoint_pair_bilin_form, exact hf, }, { intros h, refine ⟨A.to_lin, _, to_lin_to_matrix⟩, exact (matrix_is_adjoint_pair_bilin_form _ _ _ _).mpr h, }, end /-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def self_adjoint_matrices_submodule : submodule R (matrix n n R) := pair_self_adjoint_matrices_submodule J J @[simp] lemma mem_self_adjoint_matrices_submodule : A ∈ self_adjoint_matrices_submodule J ↔ J.is_self_adjoint A := by { erw mem_pair_self_adjoint_matrices_submodule, refl, } /-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to the matrix `J`. -/ def skew_adjoint_matrices_submodule : submodule R (matrix n n R) := pair_self_adjoint_matrices_submodule (-J) J @[simp] lemma mem_skew_adjoint_matrices_submodule : A ∈ skew_adjoint_matrices_submodule J ↔ J.is_skew_adjoint A := begin erw mem_pair_self_adjoint_matrices_submodule, simp [matrix.is_skew_adjoint, matrix.is_adjoint_pair], end end matrix_adjoints
50333de789dec6f94330fb31d2b16495c91ee139
302c785c90d40ad3d6be43d33bc6a558354cc2cf
/src/algebra/group/hom.lean
770dafb922f9b853787a72ae047c4e4921355dbc
[ "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
37,540
lean
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kevin Buzzard, Scott Morrison, Johan Commelin, Chris Hughes, Johannes Hölzl, Yury Kudryashov -/ import algebra.group.commute import algebra.group_with_zero.defs /-! # monoid and group homomorphisms This file defines the bundled structures for monoid and group homomorphisms. Namely, we define `monoid_hom` (resp., `add_monoid_hom`) to be bundled homomorphisms between multiplicative (resp., additive) monoids or groups. We also define coercion to a function, and usual operations: composition, identity homomorphism, pointwise multiplication and pointwise inversion. This file also defines the lesser-used (and notation-less) homomorphism types which are used as building blocks for other homomorphisms: * `zero_hom` * `one_hom` * `add_hom` * `mul_hom` * `monoid_with_zero_hom` ## Notations * `→*` for bundled monoid homs (also use for group homs) * `→+` for bundled add_monoid homs (also use for add_group homs) ## implementation notes There's a coercion from bundled homs to fun, and the canonical notation is to use the bundled hom as a function via this coercion. There is no `group_hom` -- the idea is that `monoid_hom` is used. The constructor for `monoid_hom` needs a proof of `map_one` as well as `map_mul`; a separate constructor `monoid_hom.mk'` will construct group homs (i.e. monoid homs between groups) given only a proof that multiplication is preserved, Implicit `{}` brackets are often used instead of type class `[]` brackets. This is done when the instances can be inferred because they are implicit arguments to the type `monoid_hom`. When they can be inferred from the type it is faster to use this method than to use type class inference. Historically this file also included definitions of unbundled homomorphism classes; they were deprecated and moved to `deprecated/group`. ## Tags monoid_hom, add_monoid_hom -/ variables {M : Type*} {N : Type*} {P : Type*} -- monoids {G : Type*} {H : Type*} -- groups -- for easy multiple inheritance set_option old_structure_cmd true /-- Homomorphism that preserves zero -/ structure zero_hom (M : Type*) (N : Type*) [has_zero M] [has_zero N] := (to_fun : M → N) (map_zero' : to_fun 0 = 0) /-- Homomorphism that preserves addition -/ structure add_hom (M : Type*) (N : Type*) [has_add M] [has_add N] := (to_fun : M → N) (map_add' : ∀ x y, to_fun (x + y) = to_fun x + to_fun y) /-- Bundled add_monoid homomorphisms; use this for bundled add_group homomorphisms too. -/ @[ancestor zero_hom add_hom] structure add_monoid_hom (M : Type*) (N : Type*) [add_zero_class M] [add_zero_class N] extends zero_hom M N, add_hom M N attribute [nolint doc_blame] add_monoid_hom.to_add_hom attribute [nolint doc_blame] add_monoid_hom.to_zero_hom infixr ` →+ `:25 := add_monoid_hom /-- Homomorphism that preserves one -/ @[to_additive] structure one_hom (M : Type*) (N : Type*) [has_one M] [has_one N] := (to_fun : M → N) (map_one' : to_fun 1 = 1) /-- Homomorphism that preserves multiplication -/ @[to_additive] structure mul_hom (M : Type*) (N : Type*) [has_mul M] [has_mul N] := (to_fun : M → N) (map_mul' : ∀ x y, to_fun (x * y) = to_fun x * to_fun y) /-- Bundled monoid homomorphisms; use this for bundled group homomorphisms too. -/ @[ancestor one_hom mul_hom, to_additive] structure monoid_hom (M : Type*) (N : Type*) [mul_one_class M] [mul_one_class N] extends one_hom M N, mul_hom M N /-- Bundled monoid with zero homomorphisms; use this for bundled group with zero homomorphisms too. -/ @[ancestor zero_hom monoid_hom] structure monoid_with_zero_hom (M : Type*) (N : Type*) [monoid_with_zero M] [monoid_with_zero N] extends zero_hom M N, monoid_hom M N attribute [nolint doc_blame] monoid_hom.to_mul_hom attribute [nolint doc_blame] monoid_hom.to_one_hom attribute [nolint doc_blame] monoid_with_zero_hom.to_monoid_hom attribute [nolint doc_blame] monoid_with_zero_hom.to_zero_hom infixr ` →* `:25 := monoid_hom -- completely uninteresting lemmas about coercion to function, that all homs need section coes /-! Bundled morphisms can be down-cast to weaker bundlings -/ @[to_additive] instance monoid_hom.has_coe_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} : has_coe (M →* N) (one_hom M N) := ⟨monoid_hom.to_one_hom⟩ @[to_additive] instance monoid_hom.has_coe_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} : has_coe (M →* N) (mul_hom M N) := ⟨monoid_hom.to_mul_hom⟩ instance monoid_with_zero_hom.has_coe_to_monoid_hom {mM : monoid_with_zero M} {mN : monoid_with_zero N} : has_coe (monoid_with_zero_hom M N) (M →* N) := ⟨monoid_with_zero_hom.to_monoid_hom⟩ instance monoid_with_zero_hom.has_coe_to_zero_hom {mM : monoid_with_zero M} {mN : monoid_with_zero N} : has_coe (monoid_with_zero_hom M N) (zero_hom M N) := ⟨monoid_with_zero_hom.to_zero_hom⟩ /-! The simp-normal form of morphism coercion is `f.to_..._hom`. This choice is primarily because this is the way things were before the above coercions were introduced. Bundled morphisms defined elsewhere in Mathlib may choose `↑f` as their simp-normal form instead. -/ @[simp, to_additive] lemma monoid_hom.coe_eq_to_one_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) : (f : one_hom M N) = f.to_one_hom := rfl @[simp, to_additive] lemma monoid_hom.coe_eq_to_mul_hom {mM : mul_one_class M} {mN : mul_one_class N} (f : M →* N) : (f : mul_hom M N) = f.to_mul_hom := rfl @[simp] lemma monoid_with_zero_hom.coe_eq_to_monoid_hom {mM : monoid_with_zero M} {mN : monoid_with_zero N} (f : monoid_with_zero_hom M N) : (f : M →* N) = f.to_monoid_hom := rfl @[simp] lemma monoid_with_zero_hom.coe_eq_to_zero_hom {mM : monoid_with_zero M} {mN : monoid_with_zero N} (f : monoid_with_zero_hom M N) : (f : zero_hom M N) = f.to_zero_hom := rfl @[to_additive] instance {mM : has_one M} {mN : has_one N} : has_coe_to_fun (one_hom M N) := ⟨_, one_hom.to_fun⟩ @[to_additive] instance {mM : has_mul M} {mN : has_mul N} : has_coe_to_fun (mul_hom M N) := ⟨_, mul_hom.to_fun⟩ @[to_additive] instance {mM : mul_one_class M} {mN : mul_one_class N} : has_coe_to_fun (M →* N) := ⟨_, monoid_hom.to_fun⟩ instance {mM : monoid_with_zero M} {mN : monoid_with_zero N} : has_coe_to_fun (monoid_with_zero_hom M N) := ⟨_, monoid_with_zero_hom.to_fun⟩ -- these must come after the coe_to_fun definitions initialize_simps_projections zero_hom (to_fun → apply) initialize_simps_projections add_hom (to_fun → apply) initialize_simps_projections add_monoid_hom (to_fun → apply) initialize_simps_projections one_hom (to_fun → apply) initialize_simps_projections mul_hom (to_fun → apply) initialize_simps_projections monoid_hom (to_fun → apply) initialize_simps_projections monoid_with_zero_hom (to_fun → apply) @[simp, to_additive] lemma one_hom.to_fun_eq_coe [has_one M] [has_one N] (f : one_hom M N) : f.to_fun = f := rfl @[simp, to_additive] lemma mul_hom.to_fun_eq_coe [has_mul M] [has_mul N] (f : mul_hom M N) : f.to_fun = f := rfl @[simp, to_additive] lemma monoid_hom.to_fun_eq_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : f.to_fun = f := rfl @[simp] lemma monoid_with_zero_hom.to_fun_eq_coe [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : f.to_fun = f := rfl @[simp, to_additive] lemma one_hom.coe_mk [has_one M] [has_one N] (f : M → N) (h1) : ⇑(one_hom.mk f h1) = f := rfl @[simp, to_additive] lemma mul_hom.coe_mk [has_mul M] [has_mul N] (f : M → N) (hmul) : ⇑(mul_hom.mk f hmul) = f := rfl @[simp, to_additive] lemma monoid_hom.coe_mk [mul_one_class M] [mul_one_class N] (f : M → N) (h1 hmul) : ⇑(monoid_hom.mk f h1 hmul) = f := rfl @[simp] lemma monoid_with_zero_hom.coe_mk [monoid_with_zero M] [monoid_with_zero N] (f : M → N) (h0 h1 hmul) : ⇑(monoid_with_zero_hom.mk f h0 h1 hmul) = f := rfl @[simp, to_additive] lemma monoid_hom.to_one_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : (f.to_one_hom : M → N) = f := rfl @[simp, to_additive] lemma monoid_hom.to_mul_hom_coe [mul_one_class M] [mul_one_class N] (f : M →* N) : (f.to_mul_hom : M → N) = f := rfl @[simp] lemma monoid_with_zero_hom.to_zero_hom_coe [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : (f.to_zero_hom : M → N) = f := rfl @[simp] lemma monoid_with_zero_hom.to_monoid_hom_coe [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : (f.to_monoid_hom : M → N) = f := rfl @[to_additive] theorem one_hom.congr_fun [has_one M] [has_one N] {f g : one_hom M N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : one_hom M N, h x) h @[to_additive] theorem mul_hom.congr_fun [has_mul M] [has_mul N] {f g : mul_hom M N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : mul_hom M N, h x) h @[to_additive] theorem monoid_hom.congr_fun [mul_one_class M] [mul_one_class N] {f g : M →* N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : M →* N, h x) h theorem monoid_with_zero_hom.congr_fun [monoid_with_zero M] [monoid_with_zero N] {f g : monoid_with_zero_hom M N} (h : f = g) (x : M) : f x = g x := congr_arg (λ h : monoid_with_zero_hom M N, h x) h @[to_additive] theorem one_hom.congr_arg [has_one M] [has_one N] (f : one_hom M N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] theorem mul_hom.congr_arg [has_mul M] [has_mul N] (f : mul_hom M N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] theorem monoid_hom.congr_arg [mul_one_class M] [mul_one_class N] (f : M →* N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h theorem monoid_with_zero_hom.congr_arg [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) {x y : M} (h : x = y) : f x = f y := congr_arg (λ x : M, f x) h @[to_additive] lemma one_hom.coe_inj [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[to_additive] lemma mul_hom.coe_inj [has_mul M] [has_mul N] ⦃f g : mul_hom M N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[to_additive] lemma monoid_hom.coe_inj [mul_one_class M] [mul_one_class N] ⦃f g : M →* N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl lemma monoid_with_zero_hom.coe_inj [monoid_with_zero M] [monoid_with_zero N] ⦃f g : monoid_with_zero_hom M N⦄ (h : (f : M → N) = g) : f = g := by cases f; cases g; cases h; refl @[ext, to_additive] lemma one_hom.ext [has_one M] [has_one N] ⦃f g : one_hom M N⦄ (h : ∀ x, f x = g x) : f = g := one_hom.coe_inj (funext h) @[ext, to_additive] lemma mul_hom.ext [has_mul M] [has_mul N] ⦃f g : mul_hom M N⦄ (h : ∀ x, f x = g x) : f = g := mul_hom.coe_inj (funext h) @[ext, to_additive] lemma monoid_hom.ext [mul_one_class M] [mul_one_class N] ⦃f g : M →* N⦄ (h : ∀ x, f x = g x) : f = g := monoid_hom.coe_inj (funext h) @[ext] lemma monoid_with_zero_hom.ext [monoid_with_zero M] [monoid_with_zero N] ⦃f g : monoid_with_zero_hom M N⦄ (h : ∀ x, f x = g x) : f = g := monoid_with_zero_hom.coe_inj (funext h) attribute [ext] zero_hom.ext add_hom.ext add_monoid_hom.ext @[to_additive] lemma one_hom.ext_iff [has_one M] [has_one N] {f g : one_hom M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, one_hom.ext h⟩ @[to_additive] lemma mul_hom.ext_iff [has_mul M] [has_mul N] {f g : mul_hom M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, mul_hom.ext h⟩ @[to_additive] lemma monoid_hom.ext_iff [mul_one_class M] [mul_one_class N] {f g : M →* N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, monoid_hom.ext h⟩ lemma monoid_with_zero_hom.ext_iff [monoid_with_zero M] [monoid_with_zero N] {f g : monoid_with_zero_hom M N} : f = g ↔ ∀ x, f x = g x := ⟨λ h x, h ▸ rfl, λ h, monoid_with_zero_hom.ext h⟩ @[simp, to_additive] lemma one_hom.mk_coe [has_one M] [has_one N] (f : one_hom M N) (h1) : one_hom.mk f h1 = f := one_hom.ext $ λ _, rfl @[simp, to_additive] lemma mul_hom.mk_coe [has_mul M] [has_mul N] (f : mul_hom M N) (hmul) : mul_hom.mk f hmul = f := mul_hom.ext $ λ _, rfl @[simp, to_additive] lemma monoid_hom.mk_coe [mul_one_class M] [mul_one_class N] (f : M →* N) (h1 hmul) : monoid_hom.mk f h1 hmul = f := monoid_hom.ext $ λ _, rfl @[simp] lemma monoid_with_zero_hom.mk_coe [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) (h0 h1 hmul) : monoid_with_zero_hom.mk f h0 h1 hmul = f := monoid_with_zero_hom.ext $ λ _, rfl end coes @[simp, to_additive] lemma one_hom.map_one [has_one M] [has_one N] (f : one_hom M N) : f 1 = 1 := f.map_one' /-- If `f` is a monoid homomorphism then `f 1 = 1`. -/ @[simp, to_additive] lemma monoid_hom.map_one [mul_one_class M] [mul_one_class N] (f : M →* N) : f 1 = 1 := f.map_one' @[simp] lemma monoid_with_zero_hom.map_one [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : f 1 = 1 := f.map_one' /-- If `f` is an additive monoid homomorphism then `f 0 = 0`. -/ add_decl_doc add_monoid_hom.map_zero @[simp] lemma monoid_with_zero_hom.map_zero [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : f 0 = 0 := f.map_zero' @[simp, to_additive] lemma mul_hom.map_mul [has_mul M] [has_mul N] (f : mul_hom M N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b /-- If `f` is a monoid homomorphism then `f (a * b) = f a * f b`. -/ @[simp, to_additive] lemma monoid_hom.map_mul [mul_one_class M] [mul_one_class N] (f : M →* N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b @[simp] lemma monoid_with_zero_hom.map_mul [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) (a b : M) : f (a * b) = f a * f b := f.map_mul' a b /-- If `f` is an additive monoid homomorphism then `f (a + b) = f a + f b`. -/ add_decl_doc add_monoid_hom.map_add namespace monoid_hom variables {mM : mul_one_class M} {mN : mul_one_class N} {mP : mul_one_class P} variables [group G] [comm_group H] include mM mN @[to_additive] lemma map_mul_eq_one (f : M →* N) {a b : M} (h : a * b = 1) : f a * f b = 1 := by rw [← f.map_mul, h, f.map_one] /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too. For elements invertible on both sides see `is_unit.map`. -/ @[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a right inverse, then `f x` has a right inverse too."] lemma map_exists_right_inv (f : M →* N) {x : M} (hx : ∃ y, x * y = 1) : ∃ y, f x * y = 1 := let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩ /-- Given a monoid homomorphism `f : M →* N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `is_unit.map`. -/ @[to_additive "Given an add_monoid homomorphism `f : M →+ N` and an element `x : M`, if `x` has a left inverse, then `f x` has a left inverse too. For elements invertible on both sides see `is_add_unit.map`."] lemma map_exists_left_inv (f : M →* N) {x : M} (hx : ∃ y, y * x = 1) : ∃ y, y * f x = 1 := let ⟨y, hy⟩ := hx in ⟨f y, f.map_mul_eq_one hy⟩ end monoid_hom /-- The identity map from a type with 1 to itself. -/ @[to_additive] def one_hom.id (M : Type*) [has_one M] : one_hom M M := { to_fun := id, map_one' := rfl, } /-- The identity map from a type with multiplication to itself. -/ @[to_additive] def mul_hom.id (M : Type*) [has_mul M] : mul_hom M M := { to_fun := id, map_mul' := λ _ _, rfl, } /-- The identity map from a monoid to itself. -/ @[to_additive] def monoid_hom.id (M : Type*) [mul_one_class M] : M →* M := { to_fun := id, map_one' := rfl, map_mul' := λ _ _, rfl, } /-- The identity map from a monoid_with_zero to itself. -/ def monoid_with_zero_hom.id (M : Type*) [monoid_with_zero M] : monoid_with_zero_hom M M := { to_fun := id, map_zero' := rfl, map_one' := rfl, map_mul' := λ _ _, rfl, } /-- The identity map from an type with zero to itself. -/ add_decl_doc zero_hom.id /-- The identity map from an type with addition to itself. -/ add_decl_doc add_hom.id /-- The identity map from an additive monoid to itself. -/ add_decl_doc add_monoid_hom.id @[simp, to_additive] lemma one_hom.id_apply {M : Type*} [has_one M] (x : M) : one_hom.id M x = x := rfl @[simp, to_additive] lemma mul_hom.id_apply {M : Type*} [has_mul M] (x : M) : mul_hom.id M x = x := rfl @[simp, to_additive] lemma monoid_hom.id_apply {M : Type*} [mul_one_class M] (x : M) : monoid_hom.id M x = x := rfl @[simp] lemma monoid_with_zero_hom.id_apply {M : Type*} [monoid_with_zero M] (x : M) : monoid_with_zero_hom.id M x = x := rfl /-- Composition of `one_hom`s as a `one_hom`. -/ @[to_additive] def one_hom.comp [has_one M] [has_one N] [has_one P] (hnp : one_hom N P) (hmn : one_hom M N) : one_hom M P := { to_fun := hnp ∘ hmn, map_one' := by simp, } /-- Composition of `mul_hom`s as a `mul_hom`. -/ @[to_additive] def mul_hom.comp [has_mul M] [has_mul N] [has_mul P] (hnp : mul_hom N P) (hmn : mul_hom M N) : mul_hom M P := { to_fun := hnp ∘ hmn, map_mul' := by simp, } /-- Composition of monoid morphisms as a monoid morphism. -/ @[to_additive] def monoid_hom.comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (hnp : N →* P) (hmn : M →* N) : M →* P := { to_fun := hnp ∘ hmn, map_one' := by simp, map_mul' := by simp, } /-- Composition of `monoid_with_zero_hom`s as a `monoid_with_zero_hom`. -/ def monoid_with_zero_hom.comp [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] (hnp : monoid_with_zero_hom N P) (hmn : monoid_with_zero_hom M N) : monoid_with_zero_hom M P := { to_fun := hnp ∘ hmn, map_zero' := by simp, map_one' := by simp, map_mul' := by simp, } /-- Composition of `zero_hom`s as a `zero_hom`. -/ add_decl_doc zero_hom.comp /-- Composition of `add_hom`s as a `add_hom`. -/ add_decl_doc add_hom.comp /-- Composition of additive monoid morphisms as an additive monoid morphism. -/ add_decl_doc add_monoid_hom.comp @[simp, to_additive] lemma one_hom.coe_comp [has_one M] [has_one N] [has_one P] (g : one_hom N P) (f : one_hom M N) : ⇑(g.comp f) = g ∘ f := rfl @[simp, to_additive] lemma mul_hom.coe_comp [has_mul M] [has_mul N] [has_mul P] (g : mul_hom N P) (f : mul_hom M N) : ⇑(g.comp f) = g ∘ f := rfl @[simp, to_additive] lemma monoid_hom.coe_comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (g : N →* P) (f : M →* N) : ⇑(g.comp f) = g ∘ f := rfl @[simp] lemma monoid_with_zero_hom.coe_comp [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] (g : monoid_with_zero_hom N P) (f : monoid_with_zero_hom M N) : ⇑(g.comp f) = g ∘ f := rfl @[to_additive] lemma one_hom.comp_apply [has_one M] [has_one N] [has_one P] (g : one_hom N P) (f : one_hom M N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] lemma mul_hom.comp_apply [has_mul M] [has_mul N] [has_mul P] (g : mul_hom N P) (f : mul_hom M N) (x : M) : g.comp f x = g (f x) := rfl @[to_additive] lemma monoid_hom.comp_apply [mul_one_class M] [mul_one_class N] [mul_one_class P] (g : N →* P) (f : M →* N) (x : M) : g.comp f x = g (f x) := rfl lemma monoid_with_zero_hom.comp_apply [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] (g : monoid_with_zero_hom N P) (f : monoid_with_zero_hom M N) (x : M) : g.comp f x = g (f x) := rfl /-- Composition of monoid homomorphisms is associative. -/ @[to_additive] lemma one_hom.comp_assoc {Q : Type*} [has_one M] [has_one N] [has_one P] [has_one Q] (f : one_hom M N) (g : one_hom N P) (h : one_hom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma mul_hom.comp_assoc {Q : Type*} [has_mul M] [has_mul N] [has_mul P] [has_mul Q] (f : mul_hom M N) (g : mul_hom N P) (h : mul_hom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma monoid_hom.comp_assoc {Q : Type*} [mul_one_class M] [mul_one_class N] [mul_one_class P] [mul_one_class Q] (f : M →* N) (g : N →* P) (h : P →* Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl lemma monoid_with_zero_hom.comp_assoc {Q : Type*} [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] [monoid_with_zero Q] (f : monoid_with_zero_hom M N) (g : monoid_with_zero_hom N P) (h : monoid_with_zero_hom P Q) : (h.comp g).comp f = h.comp (g.comp f) := rfl @[to_additive] lemma one_hom.cancel_right [has_one M] [has_one N] [has_one P] {g₁ g₂ : one_hom N P} {f : one_hom M N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, one_hom.ext $ (forall_iff_forall_surj hf).1 (one_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma mul_hom.cancel_right [has_mul M] [has_mul N] [has_mul P] {g₁ g₂ : mul_hom N P} {f : mul_hom M N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, mul_hom.ext $ (forall_iff_forall_surj hf).1 (mul_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma monoid_hom.cancel_right [mul_one_class M] [mul_one_class N] [mul_one_class P] {g₁ g₂ : N →* P} {f : M →* N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, monoid_hom.ext $ (forall_iff_forall_surj hf).1 (monoid_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ lemma monoid_with_zero_hom.cancel_right [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] {g₁ g₂ : monoid_with_zero_hom N P} {f : monoid_with_zero_hom M N} (hf : function.surjective f) : g₁.comp f = g₂.comp f ↔ g₁ = g₂ := ⟨λ h, monoid_with_zero_hom.ext $ (forall_iff_forall_surj hf).1 (monoid_with_zero_hom.ext_iff.1 h), λ h, h ▸ rfl⟩ @[to_additive] lemma one_hom.cancel_left [has_one M] [has_one N] [has_one P] {g : one_hom N P} {f₁ f₂ : one_hom M N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, one_hom.ext $ λ x, hg $ by rw [← one_hom.comp_apply, h, one_hom.comp_apply], λ h, h ▸ rfl⟩ @[to_additive] lemma mul_hom.cancel_left [has_one M] [has_one N] [has_one P] {g : one_hom N P} {f₁ f₂ : one_hom M N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, one_hom.ext $ λ x, hg $ by rw [← one_hom.comp_apply, h, one_hom.comp_apply], λ h, h ▸ rfl⟩ @[to_additive] lemma monoid_hom.cancel_left [mul_one_class M] [mul_one_class N] [mul_one_class P] {g : N →* P} {f₁ f₂ : M →* N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, monoid_hom.ext $ λ x, hg $ by rw [← monoid_hom.comp_apply, h, monoid_hom.comp_apply], λ h, h ▸ rfl⟩ lemma monoid_with_zero_hom.cancel_left [monoid_with_zero M] [monoid_with_zero N] [monoid_with_zero P] {g : monoid_with_zero_hom N P} {f₁ f₂ : monoid_with_zero_hom M N} (hg : function.injective g) : g.comp f₁ = g.comp f₂ ↔ f₁ = f₂ := ⟨λ h, monoid_with_zero_hom.ext $ λ x, hg $ by rw [ ← monoid_with_zero_hom.comp_apply, h, monoid_with_zero_hom.comp_apply], λ h, h ▸ rfl⟩ @[simp, to_additive] lemma one_hom.comp_id [has_one M] [has_one N] (f : one_hom M N) : f.comp (one_hom.id M) = f := one_hom.ext $ λ x, rfl @[simp, to_additive] lemma mul_hom.comp_id [has_mul M] [has_mul N] (f : mul_hom M N) : f.comp (mul_hom.id M) = f := mul_hom.ext $ λ x, rfl @[simp, to_additive] lemma monoid_hom.comp_id [mul_one_class M] [mul_one_class N] (f : M →* N) : f.comp (monoid_hom.id M) = f := monoid_hom.ext $ λ x, rfl @[simp] lemma monoid_with_zero_hom.comp_id [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : f.comp (monoid_with_zero_hom.id M) = f := monoid_with_zero_hom.ext $ λ x, rfl @[simp, to_additive] lemma one_hom.id_comp [has_one M] [has_one N] (f : one_hom M N) : (one_hom.id N).comp f = f := one_hom.ext $ λ x, rfl @[simp, to_additive] lemma mul_hom.id_comp [has_mul M] [has_mul N] (f : mul_hom M N) : (mul_hom.id N).comp f = f := mul_hom.ext $ λ x, rfl @[simp, to_additive] lemma monoid_hom.id_comp [mul_one_class M] [mul_one_class N] (f : M →* N) : (monoid_hom.id N).comp f = f := monoid_hom.ext $ λ x, rfl @[simp] lemma monoid_with_zero_hom.id_comp [monoid_with_zero M] [monoid_with_zero N] (f : monoid_with_zero_hom M N) : (monoid_with_zero_hom.id N).comp f = f := monoid_with_zero_hom.ext $ λ x, rfl section End namespace monoid variables (M) [mul_one_class M] /-- The monoid of endomorphisms. -/ protected def End := M →* M namespace End instance : 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 : inhabited (monoid.End M) := ⟨1⟩ instance : has_coe_to_fun (monoid.End M) := ⟨_, monoid_hom.to_fun⟩ end End @[simp] lemma coe_one : ((1 : monoid.End M) : M → M) = id := rfl @[simp] lemma coe_mul (f g) : ((f * g : monoid.End M) : M → M) = f ∘ g := rfl end monoid namespace add_monoid variables (A : Type*) [add_zero_class A] /-- The monoid of endomorphisms. -/ protected def End := A →+ A namespace End instance : 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 : inhabited (add_monoid.End A) := ⟨1⟩ instance : has_coe_to_fun (add_monoid.End A) := ⟨_, add_monoid_hom.to_fun⟩ end End @[simp] lemma coe_one : ((1 : add_monoid.End A) : A → A) = id := rfl @[simp] lemma coe_mul (f g) : ((f * g : add_monoid.End A) : A → A) = f ∘ g := rfl end add_monoid end End /-- `1` is the homomorphism sending all elements to `1`. -/ @[to_additive] instance [has_one M] [has_one N] : has_one (one_hom M N) := ⟨⟨λ _, 1, rfl⟩⟩ /-- `1` is the multiplicative homomorphism sending all elements to `1`. -/ @[to_additive] instance [has_mul M] [mul_one_class N] : has_one (mul_hom M N) := ⟨⟨λ _, 1, λ _ _, (one_mul 1).symm⟩⟩ /-- `1` is the monoid homomorphism sending all elements to `1`. -/ @[to_additive] instance [mul_one_class M] [mul_one_class N] : has_one (M →* N) := ⟨⟨λ _, 1, rfl, λ _ _, (one_mul 1).symm⟩⟩ /-- `0` is the homomorphism sending all elements to `0`. -/ add_decl_doc zero_hom.has_zero /-- `0` is the additive homomorphism sending all elements to `0`. -/ add_decl_doc add_hom.has_zero /-- `0` is the additive monoid homomorphism sending all elements to `0`. -/ add_decl_doc add_monoid_hom.has_zero @[simp, to_additive] lemma one_hom.one_apply [has_one M] [has_one N] (x : M) : (1 : one_hom M N) x = 1 := rfl @[simp, to_additive] lemma monoid_hom.one_apply [mul_one_class M] [mul_one_class N] (x : M) : (1 : M →* N) x = 1 := rfl @[simp, to_additive] lemma one_hom.one_comp [has_one M] [has_one N] [has_one P] (f : one_hom M N) : (1 : one_hom N P).comp f = 1 := rfl @[simp, to_additive] lemma one_hom.comp_one [has_one M] [has_one N] [has_one P] (f : one_hom N P) : f.comp (1 : one_hom M N) = 1 := by { ext, simp only [one_hom.map_one, one_hom.coe_comp, function.comp_app, one_hom.one_apply] } @[to_additive] instance [has_one M] [has_one N] : inhabited (one_hom M N) := ⟨1⟩ @[to_additive] instance [has_mul M] [mul_one_class N] : inhabited (mul_hom M N) := ⟨1⟩ @[to_additive] instance [mul_one_class M] [mul_one_class N] : inhabited (M →* N) := ⟨1⟩ -- unlike the other homs, `monoid_with_zero_hom` does not have a `1` or `0` instance [monoid_with_zero M] : inhabited (monoid_with_zero_hom M M) := ⟨monoid_with_zero_hom.id M⟩ namespace monoid_hom variables [mM : mul_one_class M] [mN : mul_one_class N] [mP : mul_one_class P] variables [group G] [comm_group H] /-- Given two monoid morphisms `f`, `g` to a commutative monoid, `f * g` is the monoid morphism sending `x` to `f x * g x`. -/ @[to_additive] instance {M N} {mM : mul_one_class M} [comm_monoid N] : has_mul (M →* N) := ⟨λ f g, { to_fun := λ m, f m * g m, map_one' := show f 1 * g 1 = 1, by simp, map_mul' := begin intros, show f (x * y) * g (x * y) = f x * g x * (f y * g y), rw [f.map_mul, g.map_mul, ←mul_assoc, ←mul_assoc, mul_right_comm (f x)], end }⟩ /-- Given two additive monoid morphisms `f`, `g` to an additive commutative monoid, `f + g` is the additive monoid morphism sending `x` to `f x + g x`. -/ add_decl_doc add_monoid_hom.has_add @[simp, to_additive] lemma mul_apply {M N} {mM : mul_one_class M} {mN : comm_monoid N} (f g : M →* N) (x : M) : (f * g) x = f x * g x := rfl @[simp, to_additive] lemma one_comp [mul_one_class M] [mul_one_class N] [mul_one_class P] (f : M →* N) : (1 : N →* P).comp f = 1 := rfl @[simp, to_additive] lemma comp_one [mul_one_class M] [mul_one_class N] [mul_one_class P] (f : N →* P) : f.comp (1 : M →* N) = 1 := by { ext, simp only [map_one, coe_comp, function.comp_app, one_apply] } @[to_additive] lemma mul_comp [mul_one_class M] [comm_monoid N] [comm_monoid P] (g₁ g₂ : N →* P) (f : M →* N) : (g₁ * g₂).comp f = g₁.comp f * g₂.comp f := rfl @[to_additive] lemma comp_mul [mul_one_class M] [comm_monoid N] [comm_monoid P] (g : N →* P) (f₁ f₂ : M →* N) : g.comp (f₁ * f₂) = g.comp f₁ * g.comp f₂ := by { ext, simp only [mul_apply, function.comp_app, map_mul, coe_comp] } /-- (M →* N) is a comm_monoid if N is commutative. -/ @[to_additive] instance {M N} [mul_one_class M] [comm_monoid N] : comm_monoid (M →* N) := { mul := (*), mul_assoc := by intros; ext; apply mul_assoc, one := 1, one_mul := by intros; ext; apply one_mul, mul_one := by intros; ext; apply mul_one, mul_comm := by intros; ext; apply mul_comm } /-- `flip` arguments of `f : M →* N →* P` -/ @[to_additive "`flip` arguments of `f : M →+ N →+ P`"] def flip {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} (f : M →* N →* P) : N →* M →* P := { to_fun := λ y, ⟨λ x, f x y, by rw [f.map_one, one_apply], λ x₁ x₂, by rw [f.map_mul, mul_apply]⟩, map_one' := ext $ λ x, (f x).map_one, map_mul' := λ y₁ y₂, ext $ λ x, (f x).map_mul y₁ y₂ } @[simp, to_additive] lemma flip_apply {mM : mul_one_class M} {mN : mul_one_class N} {mP : comm_monoid P} (f : M →* N →* P) (x : M) (y : N) : f.flip y x = f x y := rfl /-- Evaluation of a `monoid_hom` at a point as a monoid homomorphism. See also `monoid_hom.apply` for the evaluation of any function at a point. -/ @[to_additive "Evaluation of an `add_monoid_hom` at a point as an additive monoid homomorphism. See also `add_monoid_hom.apply` for the evaluation of any function at a point."] def eval [mul_one_class M] [comm_monoid N] : M →* (M →* N) →* N := (monoid_hom.id (M →* N)).flip @[simp, to_additive] lemma eval_apply [mul_one_class M] [comm_monoid N] (x : M) (f : M →* N) : eval x f = f x := rfl /-- Composition of monoid morphisms (`monoid_hom.comp`) as a monoid morphism. -/ @[to_additive "Composition of additive monoid morphisms (`add_monoid_hom.comp`) as an additive monoid morphism.", simps] def comp_hom [mul_one_class M] [comm_monoid N] [comm_monoid P] : (N →* P) →* (M →* N) →* (M →* P) := { to_fun := λ g, { to_fun := g.comp, map_one' := comp_one g, map_mul' := comp_mul g }, map_one' := by { ext1 f, exact one_comp f }, map_mul' := λ g₁ g₂, by { ext1 f, exact mul_comp g₁ g₂ f } } /-- If two homomorphism from a group to a monoid are equal at `x`, then they are equal at `x⁻¹`. -/ @[to_additive "If two homomorphism from an additive group to an additive monoid are equal at `x`, then they are equal at `-x`." ] lemma eq_on_inv {G} [group G] [monoid M] {f g : G →* M} {x : G} (h : f x = g x) : f x⁻¹ = g x⁻¹ := left_inv_eq_right_inv (f.map_mul_eq_one $ inv_mul_self x) $ h.symm ▸ g.map_mul_eq_one $ mul_inv_self x /-- Group homomorphisms preserve inverse. -/ @[simp, to_additive] theorem map_inv {G H} [group G] [group H] (f : G →* H) (g : G) : f g⁻¹ = (f g)⁻¹ := eq_inv_of_mul_eq_one $ f.map_mul_eq_one $ inv_mul_self g /-- Group homomorphisms preserve division. -/ @[simp, to_additive] theorem map_mul_inv {G H} [group G] [group H] (f : G →* H) (g h : G) : f (g * h⁻¹) = (f g) * (f h)⁻¹ := by rw [f.map_mul, f.map_inv] /-- A homomorphism from a group to a monoid is injective iff its kernel is trivial. -/ @[to_additive] lemma injective_iff {G H} [group G] [mul_one_class H] (f : G →* H) : function.injective f ↔ (∀ a, f a = 1 → a = 1) := ⟨λ h x hfx, h $ hfx.trans f.map_one.symm, λ h x y hxy, mul_inv_eq_one.1 $ h _ $ by rw [f.map_mul, hxy, ← f.map_mul, mul_inv_self, f.map_one]⟩ include mM /-- Makes a group homomorphism from a proof that the map preserves multiplication. -/ @[to_additive "Makes an additive group homomorphism from a proof that the map preserves addition."] def mk' (f : M → G) (map_mul : ∀ a b : M, f (a * b) = f a * f b) : M →* G := { to_fun := f, map_mul' := map_mul, map_one' := mul_left_eq_self.1 $ by rw [←map_mul, mul_one] } @[simp, to_additive] lemma coe_mk' {f : M → G} (map_mul : ∀ a b : M, f (a * b) = f a * f b) : ⇑(mk' f map_mul) = f := rfl omit mM /-- Makes a group homomorphism from a proof that the map preserves right division `λ x y, x * y⁻¹`. -/ @[to_additive "Makes an additive group homomorphism from a proof that the map preserves the operation `λ a b, a + -b`. See also `add_monoid_hom.of_map_sub` for a version using `λ a b, a - b`."] def of_map_mul_inv {H : Type*} [group H] (f : G → H) (map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : G →* H := mk' f $ λ x y, calc f (x * y) = f x * (f $ 1 * 1⁻¹ * y⁻¹)⁻¹ : by simp only [one_mul, one_inv, ← map_div, inv_inv] ... = f x * f y : by { simp only [map_div], simp only [mul_right_inv, one_mul, inv_inv] } @[simp, to_additive] lemma coe_of_map_mul_inv {H : Type*} [group H] (f : G → H) (map_div : ∀ a b : G, f (a * b⁻¹) = f a * (f b)⁻¹) : ⇑(of_map_mul_inv f map_div) = f := rfl /-- If `f` is a monoid homomorphism to a commutative group, then `f⁻¹` is the homomorphism sending `x` to `(f x)⁻¹`. -/ @[to_additive] instance {M G} [mul_one_class M] [comm_group G] : has_inv (M →* G) := ⟨λ f, mk' (λ g, (f g)⁻¹) $ λ a b, by rw [←mul_inv, f.map_mul]⟩ /-- If `f` is an additive monoid homomorphism to an additive commutative group, then `-f` is the homomorphism sending `x` to `-(f x)`. -/ add_decl_doc add_monoid_hom.has_neg @[simp, to_additive] lemma inv_apply {M G} {mM : mul_one_class M} {gG : comm_group G} (f : M →* G) (x : M) : f⁻¹ x = (f x)⁻¹ := rfl @[simp, to_additive] lemma inv_comp {M N A} {mM : mul_one_class M} {gN : mul_one_class N} {gA : comm_group A} (φ : N →* A) (ψ : M →* N) : φ⁻¹.comp ψ = (φ.comp ψ)⁻¹ := by { ext, simp only [function.comp_app, inv_apply, coe_comp] } @[simp, to_additive] lemma comp_inv {M A B} {mM : mul_one_class M} {mA : comm_group A} {mB : comm_group B} (φ : A →* B) (ψ : M →* A) : φ.comp ψ⁻¹ = (φ.comp ψ)⁻¹ := by { ext, simp only [function.comp_app, inv_apply, map_inv, coe_comp] } /-- If `f` and `g` are monoid homomorphisms to a commutative group, then `f / g` is the homomorphism sending `x` to `(f x) / (g x)`. -/ @[to_additive] instance {M G} [mul_one_class M] [comm_group G] : has_div (M →* G) := ⟨λ f g, mk' (λ x, f x / g x) $ λ a b, by simp [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm]⟩ /-- If `f` and `g` are monoid homomorphisms to an additive commutative group, then `f - g` is the homomorphism sending `x` to `(f x) - (g x)`. -/ add_decl_doc add_monoid_hom.has_sub @[simp, to_additive] lemma div_apply {M G} {mM : mul_one_class M} {gG : comm_group G} (f g : M →* G) (x : M) : (f / g) x = f x / g x := rfl /-- If `G` is a commutative group, then `M →* G` a commutative group too. -/ @[to_additive] instance {M G} [mul_one_class M] [comm_group G] : comm_group (M →* G) := { inv := has_inv.inv, div := has_div.div, div_eq_mul_inv := by { intros, ext, apply div_eq_mul_inv }, mul_left_inv := by intros; ext; apply mul_left_inv, ..monoid_hom.comm_monoid } /-- If `G` is an additive commutative group, then `M →+ G` an additive commutative group too. -/ add_decl_doc add_monoid_hom.add_comm_group end monoid_hom namespace add_monoid_hom variables {A B : Type*} [add_zero_class A] [add_comm_group B] [add_group G] [add_group H] /-- Additive group homomorphisms preserve subtraction. -/ @[simp] theorem map_sub (f : G →+ H) (g h : G) : f (g - h) = (f g) - (f h) := by rw [sub_eq_add_neg, sub_eq_add_neg, f.map_add_neg g h] /-- Define a morphism of additive groups given a map which respects difference. -/ def of_map_sub (f : G → H) (hf : ∀ x y, f (x - y) = f x - f y) : G →+ H := of_map_add_neg f (by simpa only [sub_eq_add_neg] using hf) @[simp] lemma coe_of_map_sub (f : G → H) (hf : ∀ x y, f (x - y) = f x - f y) : ⇑(of_map_sub f hf) = f := rfl end add_monoid_hom section commute variables [mul_one_class M] [mul_one_class N] {a x y : M} @[simp, to_additive] protected lemma semiconj_by.map (h : semiconj_by a x y) (f : M →* N) : semiconj_by (f a) (f x) (f y) := by simpa only [semiconj_by, f.map_mul] using congr_arg f h @[simp, to_additive] protected lemma commute.map (h : commute x y) (f : M →* N) : commute (f x) (f y) := h.map f end commute
fe2cdb6dd4834b408b5cd1294fa38f06b29ed7ad
e61a235b8468b03aee0120bf26ec615c045005d2
/src/Init/Lean/Elab/Command.lean
f817013cd6e137c1c5dc0144cdeee9c6964b9013
[ "Apache-2.0" ]
permissive
SCKelemen/lean4
140dc63a80539f7c61c8e43e1c174d8500ec3230
e10507e6615ddbef73d67b0b6c7f1e4cecdd82bc
refs/heads/master
1,660,973,595,917
1,590,278,033,000
1,590,278,033,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
25,729
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Elab.Alias import Init.Lean.Elab.Log import Init.Lean.Elab.ResolveName import Init.Lean.Elab.Term import Init.Lean.Elab.Binders import Init.Lean.Elab.SyntheticMVars namespace Lean namespace Elab namespace Command structure Scope := (kind : String) (header : String) (opts : Options := {}) (currNamespace : Name := Name.anonymous) (openDecls : List OpenDecl := []) (levelNames : List Name := []) (varDecls : Array Syntax := #[]) instance Scope.inhabited : Inhabited Scope := ⟨{ kind := "", header := "" }⟩ structure State := (env : Environment) (messages : MessageLog := {}) (scopes : List Scope := [{ kind := "root", header := "" }]) (nextMacroScope : Nat := firstFrontendMacroScope + 1) (maxRecDepth : Nat) instance State.inhabited : Inhabited State := ⟨{ env := arbitrary _, maxRecDepth := 0 }⟩ def mkState (env : Environment) (messages : MessageLog := {}) (opts : Options := {}) : State := { env := env, messages := messages, scopes := [{ kind := "root", header := "", opts := opts }], maxRecDepth := getMaxRecDepth opts } structure Context := (fileName : String) (fileMap : FileMap) (stateRef : IO.Ref State) (currRecDepth : Nat := 0) (cmdPos : String.Pos := 0) (macroStack : MacroStack := []) (currMacroScope : MacroScope := firstFrontendMacroScope) instance Exception.inhabited : Inhabited Exception := ⟨Exception.error $ arbitrary _⟩ abbrev CommandElabCoreM (ε) := ReaderT Context (EIO ε) abbrev CommandElabM := CommandElabCoreM Exception abbrev CommandElab := Syntax → CommandElabM Unit def mkMessageAux (ctx : Context) (ref : Syntax) (msgData : MessageData) (severity : MessageSeverity) : Message := mkMessageCore ctx.fileName ctx.fileMap msgData severity (ref.getPos.getD ctx.cmdPos) private def ioErrorToMessage (ctx : Context) (ref : Syntax) (err : IO.Error) : Message := let ref := getBetterRef ref ctx.macroStack; mkMessageAux ctx ref (addMacroStack (toString err) ctx.macroStack) MessageSeverity.error @[inline] def liftIOCore {α} (ctx : Context) (ref : Syntax) (x : IO α) : EIO Exception α := EIO.adaptExcept (fun ex => Exception.error $ ioErrorToMessage ctx ref ex) x @[inline] def liftIO {α} (ref : Syntax) (x : IO α) : CommandElabM α := fun ctx => liftIOCore ctx ref x private def getState : CommandElabM State := fun ctx => liftIOCore ctx Syntax.missing $ ctx.stateRef.get private def setState (s : State) : CommandElabM Unit := fun ctx => liftIOCore ctx Syntax.missing $ ctx.stateRef.set s @[inline] private def modifyGetState {α} (f : State → α × State) : CommandElabM α := do s ← getState; let (a, s) := f s; setState s; pure a instance CommandElabCoreM.monadState : MonadState State CommandElabM := { get := getState, set := setState, modifyGet := @modifyGetState } def getEnv : CommandElabM Environment := do s ← get; pure s.env def getScope : CommandElabM Scope := do s ← get; pure s.scopes.head! def getOptions : CommandElabM Options := do scope ← getScope; pure scope.opts def addContext (msg : MessageData) : CommandElabM MessageData := do env ← getEnv; opts ← getOptions; pure (MessageData.withContext { env := env, mctx := {}, lctx := {}, opts := opts } msg) instance CommandElabM.monadLog : MonadLog CommandElabM := { getCmdPos := do ctx ← read; pure ctx.cmdPos, getFileMap := do ctx ← read; pure ctx.fileMap, getFileName := do ctx ← read; pure ctx.fileName, addContext := addContext, logMessage := fun msg => modify $ fun s => { s with messages := s.messages.add msg } } /-- Throws an error with the given `msgData` and extracting position information from `ref`. If `ref` does not contain position information, then use `cmdPos` -/ def throwError {α} (ref : Syntax) (msgData : MessageData) : CommandElabM α := do ctx ← read; let ref := getBetterRef ref ctx.macroStack; let msgData := addMacroStack msgData ctx.macroStack; msg ← mkMessage msgData MessageSeverity.error ref; throw (Exception.error msg) def logTrace (cls : Name) (ref : Syntax) (msg : MessageData) : CommandElabM Unit := do msg ← addContext $ MessageData.tagged cls msg; logInfo ref msg @[inline] def trace (cls : Name) (ref : Syntax) (msg : Unit → MessageData) : CommandElabM Unit := do opts ← getOptions; when (checkTraceOption opts cls) $ logTrace cls ref (msg ()) def throwUnsupportedSyntax {α} : CommandElabM α := throw Elab.Exception.unsupportedSyntax protected def getCurrMacroScope : CommandElabM Nat := do ctx ← read; pure ctx.currMacroScope protected def getMainModule : CommandElabM Name := do env ← getEnv; pure env.mainModule @[inline] protected def withFreshMacroScope {α} (x : CommandElabM α) : CommandElabM α := do fresh ← modifyGet (fun st => (st.nextMacroScope, { st with nextMacroScope := st.nextMacroScope + 1 })); adaptReader (fun (ctx : Context) => { ctx with currMacroScope := fresh }) x instance CommandElabM.MonadQuotation : MonadQuotation CommandElabM := { getCurrMacroScope := Command.getCurrMacroScope, getMainModule := Command.getMainModule, withFreshMacroScope := @Command.withFreshMacroScope } unsafe def mkCommandElabAttribute : IO (KeyedDeclsAttribute CommandElab) := mkElabAttribute CommandElab `Lean.Elab.Command.commandElabAttribute `builtinCommandElab `commandElab `Lean.Parser.Command `Lean.Elab.Command.CommandElab "command" @[init mkCommandElabAttribute] constant commandElabAttribute : KeyedDeclsAttribute CommandElab := arbitrary _ @[inline] def withIncRecDepth {α} (ref : Syntax) (x : CommandElabM α) : CommandElabM α := do ctx ← read; s ← get; when (ctx.currRecDepth == s.maxRecDepth) $ throwError ref maxRecDepthErrorMessage; adaptReader (fun (ctx : Context) => { ctx with currRecDepth := ctx.currRecDepth + 1 }) x private def elabCommandUsing (s : State) (stx : Syntax) : List CommandElab → CommandElabM Unit | [] => do let refFmt := stx.prettyPrint; throwError stx ("unexpected syntax" ++ MessageData.nest 2 (Format.line ++ refFmt)) | (elabFn::elabFns) => catch (elabFn stx) (fun ex => match ex with | Exception.error _ => throw ex | Exception.unsupportedSyntax => do set s; elabCommandUsing elabFns) /- Elaborate `x` with `stx` on the macro stack -/ @[inline] def withMacroExpansion {α} (beforeStx afterStx : Syntax) (x : CommandElabM α) : CommandElabM α := adaptReader (fun (ctx : Context) => { ctx with macroStack := { before := beforeStx, after := afterStx } :: ctx.macroStack }) x instance : MonadMacroAdapter CommandElabM := { getEnv := getEnv, getCurrMacroScope := getCurrMacroScope, getNextMacroScope := do s ← get; pure s.nextMacroScope, setNextMacroScope := fun next => modify $ fun s => { s with nextMacroScope := next }, throwError := @throwError, throwUnsupportedSyntax := @throwUnsupportedSyntax} partial def elabCommand : Syntax → CommandElabM Unit | stx => withIncRecDepth stx $ withFreshMacroScope $ match stx with | Syntax.node k args => if k == nullKind then -- list of commands => elaborate in order -- The parser will only ever return a single command at a time, but syntax quotations can return multiple ones args.forM elabCommand else do trace `Elab.step stx $ fun _ => stx; s ← get; stxNew? ← catch (do newStx ← adaptMacro (getMacros s.env) stx; pure (some newStx)) (fun ex => match ex with | Exception.unsupportedSyntax => pure none | _ => throw ex); match stxNew? with | some stxNew => withMacroExpansion stx stxNew $ elabCommand stxNew | _ => do let table := (commandElabAttribute.ext.getState s.env).table; let k := stx.getKind; match table.find? k with | some elabFns => elabCommandUsing s stx elabFns | none => throwError stx ("elaboration function for '" ++ toString k ++ "' has not been implemented") | _ => throwError stx "unexpected command" /-- Adapt a syntax transformation to a regular, command-producing elaborator. -/ def adaptExpander (exp : Syntax → CommandElabM Syntax) : CommandElab := fun stx => do stx' ← exp stx; withMacroExpansion stx stx' $ elabCommand stx' private def mkTermContext (ctx : Context) (s : State) (declName? : Option Name) : Term.Context := let scope := s.scopes.head!; { config := { opts := scope.opts, foApprox := true, ctxApprox := true, quasiPatternApprox := true, isDefEqStuckEx := true }, fileName := ctx.fileName, fileMap := ctx.fileMap, currRecDepth := ctx.currRecDepth, maxRecDepth := s.maxRecDepth, cmdPos := ctx.cmdPos, declName? := declName?, macroStack := ctx.macroStack, currMacroScope := ctx.currMacroScope, currNamespace := scope.currNamespace, levelNames := scope.levelNames, openDecls := scope.openDecls } private def mkTermState (s : State) : Term.State := { env := s.env, messages := s.messages, nextMacroScope := s.nextMacroScope } private def updateState (s : State) (newS : Term.State) : State := { s with env := newS.env, messages := newS.messages, nextMacroScope := newS.nextMacroScope } private def getVarDecls (s : State) : Array Syntax := s.scopes.head!.varDecls private def toCommandResult {α} (ctx : Context) (s : State) (result : EStateM.Result Term.Exception Term.State α) : EStateM.Result Exception State α := match result with | EStateM.Result.ok a newS => EStateM.Result.ok a (updateState s newS) | EStateM.Result.error (Term.Exception.ex ex) newS => EStateM.Result.error ex (updateState s newS) | EStateM.Result.error Term.Exception.postpone newS => unreachable! instance CommandElabM.inhabited {α} : Inhabited (CommandElabM α) := ⟨throw $ arbitrary _⟩ @[inline] def liftTermElabM {α} (declName? : Option Name) (x : TermElabM α) : CommandElabM α := do ctx ← read; s ← get; match (x $ mkTermContext ctx s declName?).run (mkTermState s) with | EStateM.Result.ok a newS => do modify $ fun s => { s with env := newS.env, messages := newS.messages }; pure a | EStateM.Result.error (Term.Exception.ex ex) newS => do modify $ fun s => { s with env := newS.env, messages := newS.messages }; throw ex | EStateM.Result.error Term.Exception.postpone newS => unreachable! @[inline] def runTermElabM {α} (declName? : Option Name) (elab : Array Expr → TermElabM α) : CommandElabM α := do s ← get; liftTermElabM declName? (Term.elabBinders (getVarDecls s) elab) @[inline] def withLogging (x : CommandElabM Unit) : CommandElabM Unit := catch x (fun ex => match ex with | Exception.error ex => do logMessage ex; pure () | Exception.unsupportedSyntax => unreachable!) @[inline] def catchExceptions (x : CommandElabM Unit) : CommandElabCoreM Empty Unit := fun ctx => EIO.catchExceptions (withLogging x ctx) (fun _ => pure ()) def dbgTrace {α} [HasToString α] (a : α) : CommandElabM Unit := _root_.dbgTrace (toString a) $ fun _ => pure () def setEnv (newEnv : Environment) : CommandElabM Unit := modify $ fun s => { s with env := newEnv } def getCurrNamespace : CommandElabM Name := do scope ← getScope; pure scope.currNamespace private def addScope (kind : String) (header : String) (newNamespace : Name) : CommandElabM Unit := modify $ fun s => { s with env := s.env.registerNamespace newNamespace, scopes := { s.scopes.head! with kind := kind, header := header, currNamespace := newNamespace } :: s.scopes } private def addScopes (ref : Syntax) (kind : String) (updateNamespace : Bool) : Name → CommandElabM Unit | Name.anonymous => pure () | Name.str p header _ => do addScopes p; currNamespace ← getCurrNamespace; addScope kind header (if updateNamespace then currNamespace ++ header else currNamespace) | _ => throwError ref "invalid scope" private def addNamespace (ref : Syntax) (header : Name) : CommandElabM Unit := addScopes ref "namespace" true header @[builtinCommandElab «namespace»] def elabNamespace : CommandElab := fun stx => match_syntax stx with | `(namespace $n) => addNamespace stx n.getId | _ => throw Exception.unsupportedSyntax @[builtinCommandElab «section»] def elabSection : CommandElab := fun stx => match_syntax stx with | `(section $header:ident) => addScopes stx "section" false header.getId | `(section) => do currNamespace ← getCurrNamespace; addScope "section" "" currNamespace | _ => throw Exception.unsupportedSyntax def getScopes : CommandElabM (List Scope) := do s ← get; pure s.scopes private def checkAnonymousScope : List Scope → Bool | { header := "", .. } :: _ => true | _ => false private def checkEndHeader : Name → List Scope → Bool | Name.anonymous, _ => true | Name.str p s _, { header := h, .. } :: scopes => h == s && checkEndHeader p scopes | _, _ => false @[builtinCommandElab «end»] def elabEnd : CommandElab := fun stx => do let header? := (stx.getArg 1).getOptionalIdent?; let endSize := match header? with | none => 1 | some n => n.getNumParts; scopes ← getScopes; if endSize < scopes.length then modify $ fun s => { s with scopes := s.scopes.drop endSize } else do { -- we keep "root" scope modify $ fun s => { s with scopes := s.scopes.drop (s.scopes.length - 1) }; throwError stx "invalid 'end', insufficient scopes" }; match header? with | none => unless (checkAnonymousScope scopes) $ throwError stx "invalid 'end', name is missing" | some header => unless (checkEndHeader header scopes) $ throwError stx "invalid 'end', name mismatch" @[inline] def withNamespace {α} (ref : Syntax) (ns : Name) (elab : CommandElabM α) : CommandElabM α := do addNamespace ref ns; a ← elab; modify $ fun s => { s with scopes := s.scopes.drop ns.getNumParts }; pure a @[specialize] def modifyScope (f : Scope → Scope) : CommandElabM Unit := modify $ fun s => { s with scopes := match s.scopes with | h::t => f h :: t | [] => unreachable! } def getLevelNames : CommandElabM (List Name) := do scope ← getScope; pure scope.levelNames def throwAlreadyDeclaredUniverseLevel {α} (ref : Syntax) (u : Name) : CommandElabM α := throwError ref ("a universe level named '" ++ toString u ++ "' has already been declared") def addUnivLevel (idStx : Syntax) : CommandElabM Unit := do let id := idStx.getId; levelNames ← getLevelNames; if levelNames.elem id then throwAlreadyDeclaredUniverseLevel idStx id else modifyScope $ fun scope => { scope with levelNames := id :: scope.levelNames } partial def elabChoiceAux (cmds : Array Syntax) : Nat → CommandElabM Unit | i => if h : i < cmds.size then let cmd := cmds.get ⟨i, h⟩; catch (elabCommand cmd) (fun ex => match ex with | Exception.unsupportedSyntax => elabChoiceAux (i+1) | _ => throw ex) else throwUnsupportedSyntax @[builtinCommandElab choice] def elbChoice : CommandElab := fun stx => elabChoiceAux stx.getArgs 0 @[builtinCommandElab «universe»] def elabUniverse : CommandElab := fun n => do addUnivLevel (n.getArg 1) @[builtinCommandElab «universes»] def elabUniverses : CommandElab := fun n => do let idsStx := n.getArg 1; idsStx.forArgsM addUnivLevel @[builtinCommandElab «init_quot»] def elabInitQuot : CommandElab := fun stx => do env ← getEnv; match env.addDecl Declaration.quotDecl with | Except.ok env => setEnv env | Except.error ex => do opts ← getOptions; throwError stx (ex.toMessageData opts) def getOpenDecls : CommandElabM (List OpenDecl) := do scope ← getScope; pure scope.openDecls def logUnknownDecl (stx : Syntax) (declName : Name) : CommandElabM Unit := logError stx ("unknown declaration '" ++ toString declName ++ "'") def resolveNamespace (id : Name) : CommandElabM Name := do env ← getEnv; currNamespace ← getCurrNamespace; openDecls ← getOpenDecls; match Elab.resolveNamespace env currNamespace openDecls id with | some ns => pure ns | none => throw Exception.unsupportedSyntax @[builtinCommandElab «export»] def elabExport : CommandElab := fun stx => do -- `stx` is of the form (Command.export "export" <namespace> "(" (null <ids>*) ")") let id := stx.getIdAt 1; ns ← resolveNamespace id; currNamespace ← getCurrNamespace; when (ns == currNamespace) $ throwError stx "invalid 'export', self export"; env ← getEnv; let ids := (stx.getArg 3).getArgs; aliases ← ids.foldlM (fun (aliases : List (Name × Name)) (idStx : Syntax) => do { let id := idStx.getId; let declName := ns ++ id; if env.contains declName then pure $ (currNamespace ++ id, declName) :: aliases else do logUnknownDecl idStx declName; pure aliases }) []; modify $ fun s => { s with env := aliases.foldl (fun env p => addAlias env p.1 p.2) s.env } def addOpenDecl (d : OpenDecl) : CommandElabM Unit := modifyScope $ fun scope => { scope with openDecls := d :: scope.openDecls } def elabOpenSimple (n : SyntaxNode) : CommandElabM Unit := -- `open` id+ let nss := n.getArg 0; nss.forArgsM $ fun ns => do ns ← resolveNamespace ns.getId; addOpenDecl (OpenDecl.simple ns []) -- `open` id `(` id+ `)` def elabOpenOnly (n : SyntaxNode) : CommandElabM Unit := do let ns := n.getIdAt 0; ns ← resolveNamespace ns; let ids := n.getArg 2; ids.forArgsM $ fun idStx => do let id := idStx.getId; let declName := ns ++ id; env ← getEnv; if env.contains declName then addOpenDecl (OpenDecl.explicit id declName) else logUnknownDecl idStx declName -- `open` id `hiding` id+ def elabOpenHiding (n : SyntaxNode) : CommandElabM Unit := do let ns := n.getIdAt 0; ns ← resolveNamespace ns; let idsStx := n.getArg 2; env ← getEnv; ids : List Name ← idsStx.foldArgsM (fun idStx ids => do let id := idStx.getId; let declName := ns ++ id; if env.contains declName then pure (id::ids) else do logUnknownDecl idStx declName; pure ids) []; addOpenDecl (OpenDecl.simple ns ids) -- `open` id `renaming` sepBy (id `->` id) `,` def elabOpenRenaming (n : SyntaxNode) : CommandElabM Unit := do let ns := n.getIdAt 0; ns ← resolveNamespace ns; let rs := (n.getArg 2); rs.forSepArgsM $ fun stx => do let fromId := stx.getIdAt 0; let toId := stx.getIdAt 2; let declName := ns ++ fromId; env ← getEnv; if env.contains declName then addOpenDecl (OpenDecl.explicit toId declName) else logUnknownDecl stx declName @[builtinCommandElab «open»] def elabOpen : CommandElab := fun n => do let body := (n.getArg 1).asNode; let k := body.getKind; if k == `Lean.Parser.Command.openSimple then elabOpenSimple body else if k == `Lean.Parser.Command.openOnly then elabOpenOnly body else if k == `Lean.Parser.Command.openHiding then elabOpenHiding body else elabOpenRenaming body @[builtinCommandElab «variable»] def elabVariable : CommandElab := fun n => do -- `variable` bracketedBinder let binder := n.getArg 1; -- Try to elaborate `binder` for sanity checking runTermElabM none $ fun _ => Term.elabBinder binder $ fun _ => pure (); modifyScope $ fun scope => { scope with varDecls := scope.varDecls.push binder } @[builtinCommandElab «variables»] def elabVariables : CommandElab := fun n => do -- `variables` bracketedBinder+ let binders := (n.getArg 1).getArgs; -- Try to elaborate `binders` for sanity checking runTermElabM none $ fun _ => Term.elabBinders binders $ fun _ => pure (); modifyScope $ fun scope => { scope with varDecls := scope.varDecls ++ binders } @[inline] def withoutModifyingEnv {α} (x : CommandElabM α) : CommandElabM α := do env ← getEnv; finally x (setEnv env) @[builtinCommandElab «check»] def elabCheck : CommandElab := fun stx => do let term := stx.getArg 1; withoutModifyingEnv $ runTermElabM (some `_check) $ fun _ => do e ← Term.elabTerm term none; Term.synthesizeSyntheticMVars false; type ← Term.inferType stx e; logInfo stx (e ++ " : " ++ type); pure () def hasNoErrorMessages : CommandElabM Bool := do s ← get; pure $ !s.messages.hasErrors def failIfSucceeds (ref : Syntax) (x : CommandElabM Unit) : CommandElabM Unit := do let resetMessages : CommandElabM MessageLog := do { s ← get; let messages := s.messages; modify $ fun s => { s with messages := {} }; pure messages }; let restoreMessages (prevMessages : MessageLog) : CommandElabM Unit := do { modify $ fun s => { s with messages := prevMessages ++ s.messages.errorsToWarnings } }; prevMessages ← resetMessages; succeeded ← finally (catch (do x; hasNoErrorMessages) (fun ex => match ex with | Exception.error msg => do modify (fun s => { s with messages := s.messages.add msg }); pure false | Exception.unsupportedSyntax => do logError ref "unsupported syntax"; pure false)) (restoreMessages prevMessages); when succeeded $ throwError ref "unexpected success" @[builtinCommandElab «check_failure»] def elabCheckFailure : CommandElab := fun stx => failIfSucceeds stx $ elabCheck stx @[builtinCommandElab «synth»] def elabSynth : CommandElab := fun stx => do let ref := stx; let term := stx.getArg 1; withoutModifyingEnv $ runTermElabM `_synth_cmd $ fun _ => do inst ← Term.elabTerm term none; Term.synthesizeSyntheticMVars false; inst ← Term.instantiateMVars ref inst; val ← Term.liftMetaM ref $ Meta.synthInstance inst; logInfo stx val; pure () def setOption (ref : Syntax) (optionName : Name) (val : DataValue) : CommandElabM Unit := do decl ← liftIO ref $ getOptionDecl optionName; unless (decl.defValue.sameCtor val) $ throwError ref "type mismatch at set_option"; modifyScope $ fun scope => { scope with opts := scope.opts.insert optionName val }; match optionName, val with | `maxRecDepth, DataValue.ofNat max => modify $ fun s => { s with maxRecDepth := max } | _, _ => pure () @[builtinCommandElab «set_option»] def elabSetOption : CommandElab := fun stx => do let ref := stx; let optionName := stx.getIdAt 1; let val := stx.getArg 2; match val.isStrLit? with | some str => setOption ref optionName (DataValue.ofString str) | none => match val.isNatLit? with | some num => setOption ref optionName (DataValue.ofNat num) | none => match val with | Syntax.atom _ "true" => setOption ref optionName (DataValue.ofBool true) | Syntax.atom _ "false" => setOption ref optionName (DataValue.ofBool false) | _ => logError val ("unexpected set_option value " ++ toString val) /- `declId` is of the form ``` parser! ident >> optional (".{" >> sepBy1 ident ", " >> "}") ``` but we also accept a single identifier to users to make macro writing more convenient . -/ def expandDeclId (declId : Syntax) : Name × Syntax := if declId.isIdent then (declId.getId, mkNullNode) else let id := declId.getIdAt 0; let optUnivDeclStx := declId.getArg 1; (id, optUnivDeclStx) @[inline] def withDeclId (declId : Syntax) (f : Name → CommandElabM Unit) : CommandElabM Unit := do -- ident >> optional (".{" >> sepBy1 ident ", " >> "}") let (id, optUnivDeclStx) := expandDeclId declId; savedLevelNames ← getLevelNames; levelNames ← if optUnivDeclStx.isNone then pure savedLevelNames else do { let extraLevels := (optUnivDeclStx.getArg 1).getArgs.getEvenElems; extraLevels.foldlM (fun levelNames idStx => let id := idStx.getId; if levelNames.elem id then throwAlreadyDeclaredUniverseLevel idStx id else pure (id :: levelNames)) savedLevelNames }; let ref := declId; -- extract (optional) namespace part of id, after decoding macro scopes that would interfere with the check let scpView := extractMacroScopes id; match scpView.name with | Name.str pre s _ => /- Add back macro scopes. We assume a declaration like `def a.b[1,2] ...` with macro scopes `[1,2]` is always meant to mean `namespace a def b[1,2] ...`. -/ let id := { scpView with name := mkNameSimple s }.review; withNamespace ref pre $ do modifyScope $ fun scope => { scope with levelNames := levelNames }; finally (f id) (modifyScope $ fun scope => { scope with levelNames := savedLevelNames }) | _ => throwError ref "invalid declaration name" /-- Sort the given list of `usedParams` using the following order: - If it is an explicit level `explicitParams`, then use user given order. - Otherwise, use lexicographical. Remark: `explicitParams` are in reverse declaration order. That is, the head is the last declared parameter. -/ def sortDeclLevelParams (explicitParams : List Name) (usedParams : Array Name) : List Name := let result := explicitParams.foldl (fun result levelName => if usedParams.elem levelName then levelName :: result else result) []; let remaining := usedParams.filter (fun levelParam => !explicitParams.elem levelParam); let remaining := remaining.qsort Name.lt; result ++ remaining.toList def addDecl (ref : Syntax) (decl : Declaration) : CommandElabM Unit := liftTermElabM none $ Term.addDecl ref decl def compileDecl (ref : Syntax) (decl : Declaration) : CommandElabM Unit := liftTermElabM none $ Term.compileDecl ref decl end Command end Elab end Lean
4a9500f3d3960e09fa6768a7f453d4a0b3009b36
7cef822f3b952965621309e88eadf618da0c8ae9
/src/ring_theory/localization.lean
545e5559f68852e05a283a9457894fefe46addff
[ "Apache-2.0" ]
permissive
rmitta/mathlib
8d90aee30b4db2b013e01f62c33f297d7e64a43d
883d974b608845bad30ae19e27e33c285200bf84
refs/heads/master
1,585,776,832,544
1,576,874,096,000
1,576,874,096,000
153,663,165
0
2
Apache-2.0
1,544,806,490,000
1,539,884,365,000
Lean
UTF-8
Lean
false
false
24,535
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin -/ import tactic.ring data.quot data.equiv.algebra ring_theory.ideal_operations group_theory.submonoid universes u v namespace localization variables (α : Type u) [comm_ring α] (S : set α) [is_submonoid S] def r (x y : α × S) : Prop := ∃ t ∈ S, ((x.2 : α) * y.1 - y.2 * x.1) * t = 0 local infix ≈ := r α S section variables {α S} theorem r_of_eq {a₀ a₁ : α × S} (h : (a₀.2 : α) * a₁.1 = a₁.2 * a₀.1) : a₀ ≈ a₁ := ⟨1, is_submonoid.one_mem S, by rw [h, sub_self, mul_one]⟩ end theorem refl (x : α × S) : x ≈ x := r_of_eq rfl theorem symm (x y : α × S) : x ≈ y → y ≈ x := λ ⟨t, hts, ht⟩, ⟨t, hts, by rw [← neg_sub, ← neg_mul_eq_neg_mul, ht, neg_zero]⟩ 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 simp only [subtype.coe_mk] at ht ht'; rw [ht, ht']; simp⟩ instance : setoid (α × S) := ⟨r α S, refl α S, symm α S, trans α S⟩ end localization /-- The localization of a ring at a submonoid: the elements of the submonoid become invertible in the localization.-/ def localization (α : Type u) [comm_ring α] (S : set α) [is_submonoid S] := quotient $ localization.setoid α S namespace localization variables (α : Type u) [comm_ring α] (S : set α) [is_submonoid S] instance : has_add (localization α S) := ⟨quotient.lift₂ (λ x y : α × S, (⟦⟨x.2 * y.1 + y.2 * x.1, x.2 * y.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩, quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅, calc (s₁ * s₂ * (s₃ * r₄ + s₄ * r₃) - s₃ * s₄ * (s₁ * r₂ + s₂ * r₁)) * (t₆ * t₅) = s₁ * s₃ * ((s₂ * r₄ - s₄ * r₂) * t₆) * t₅ + s₂ * s₄ * ((s₁ * r₃ - s₃ * r₁) * t₅) * t₆ : by ring ... = 0 : by simp only [subtype.coe_mk] at ht₅ ht₆; rw [ht₆, ht₅]; simp⟩⟩ instance : has_neg (localization α S) := ⟨quotient.lift (λ x : α × S, (⟦⟨-x.1, x.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩, quotient.sound ⟨t, hts, calc (s₁ * -r₂ - s₂ * -r₁) * t = -((s₁ * r₂ - s₂ * r₁) * t) : by ring ... = 0 : by simp only [subtype.coe_mk] at ht; rw ht; simp⟩⟩ instance : has_mul (localization α S) := ⟨quotient.lift₂ (λ x y : α × S, (⟦⟨x.1 * y.1, x.2 * y.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩, quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅, calc ((s₁ * s₂) * (r₃ * r₄) - (s₃ * s₄) * (r₁ * r₂)) * (t₆ * t₅) = t₆ * ((s₁ * r₃ - s₃ * r₁) * t₅) * r₂ * s₄ + t₅ * ((s₂ * r₄ - s₄ * r₂) * t₆) * r₃ * s₁ : by simp [mul_left_comm, mul_add, mul_comm] ... = 0 : by simp only [subtype.coe_mk] at ht₅ ht₆; rw [ht₅, ht₆]; simp⟩⟩ variables {α S} def mk (r : α) (s : S) : localization α S := ⟦(r, s)⟧ /-- The natural map from the ring to the localization.-/ def of (r : α) : localization α S := mk r 1 instance : comm_ring (localization α S) := by refine { add := has_add.add, add_assoc := λ m n k, quotient.induction_on₃ m n k _, zero := of 0, zero_add := quotient.ind _, add_zero := quotient.ind _, neg := has_neg.neg, add_left_neg := quotient.ind _, add_comm := quotient.ind₂ _, mul := has_mul.mul, mul_assoc := λ m n k, quotient.induction_on₃ m n k _, one := of 1, one_mul := quotient.ind _, mul_one := quotient.ind _, left_distrib := λ m n k, quotient.induction_on₃ m n k _, right_distrib := λ m n k, quotient.induction_on₃ m n k _, mul_comm := quotient.ind₂ _ }; { intros, try {rcases a with ⟨r₁, s₁, hs₁⟩}, try {rcases b with ⟨r₂, s₂, hs₂⟩}, try {rcases c with ⟨r₃, s₃, hs₃⟩}, refine (quotient.sound $ r_of_eq _), simp [mul_left_comm, mul_add, mul_comm] } instance of.is_ring_hom : is_ring_hom (of : α → localization α S) := { map_add := λ x y, quotient.sound $ by simp, map_mul := λ x y, quotient.sound $ by simp, map_one := rfl } variables {S} instance : has_coe_t α (localization α S) := ⟨of⟩ -- note [use has_coe_t] instance coe.is_ring_hom : is_ring_hom (coe : α → localization α S) := localization.of.is_ring_hom /-- The natural map from the submonoid to the unit group of the localization.-/ def to_units (s : S) : units (localization α S) := { val := s, inv := mk 1 s, val_inv := quotient.sound $ r_of_eq $ mul_assoc _ _ _, inv_val := quotient.sound $ r_of_eq $ show s.val * 1 * 1 = 1 * (1 * s.val), by simp } @[simp] lemma to_units_coe (s : S) : ((to_units s) : localization α S) = s := rfl section variables (α S) (x y : α) (n : ℕ) @[simp] lemma of_zero : (of 0 : localization α S) = 0 := rfl @[simp] lemma of_one : (of 1 : localization α S) = 1 := rfl @[simp] lemma of_add : (of (x + y) : localization α S) = of x + of y := by apply is_ring_hom.map_add @[simp] lemma of_sub : (of (x - y) : localization α S) = of x - of y := by apply is_ring_hom.map_sub @[simp] lemma of_mul : (of (x * y) : localization α S) = of x * of y := by apply is_ring_hom.map_mul @[simp] lemma of_neg : (of (-x) : localization α S) = -of x := by apply is_ring_hom.map_neg @[simp] lemma of_pow : (of (x ^ n) : localization α S) = (of x) ^ n := by apply is_semiring_hom.map_pow @[simp] lemma of_is_unit (s : S) : is_unit (of s : localization α S) := is_unit_unit $ to_units s @[simp] lemma of_is_unit' (s ∈ S) : is_unit (of s : localization α S) := is_unit_unit $ to_units ⟨s, ‹s ∈ S›⟩ @[simp] lemma coe_zero : ((0 : α) : localization α S) = 0 := rfl @[simp] lemma coe_one : ((1 : α) : localization α S) = 1 := rfl @[simp] lemma coe_add : (↑(x + y) : localization α S) = x + y := of_add _ _ _ _ @[simp] lemma coe_sub : (↑(x - y) : localization α S) = x - y := of_sub _ _ _ _ @[simp] lemma coe_mul : (↑(x * y) : localization α S) = x * y := of_mul _ _ _ _ @[simp] lemma coe_neg : (↑(-x) : localization α S) = -x := of_neg _ _ _ @[simp] lemma coe_pow : (↑(x ^ n) : localization α S) = x ^ n := of_pow _ _ _ _ @[simp] lemma coe_is_unit (s : S) : is_unit (s : localization α S) := of_is_unit _ _ _ @[simp] lemma coe_is_unit' (s ∈ S) : is_unit (s : localization α S) := of_is_unit' _ _ _ ‹s ∈ S› end @[simp] lemma mk_self {x : α} {hx : x ∈ S} : (mk x ⟨x, hx⟩ : localization α S) = 1 := quotient.sound ⟨1, is_submonoid.one_mem S, by simp only [subtype.coe_mk, is_submonoid.coe_one, mul_one, one_mul, sub_self]⟩ @[simp] lemma mk_self' {s : S} : (mk s s : localization α S) = 1 := by cases s; exact mk_self @[simp] lemma mk_self'' {s : S} : (mk s.1 s : localization α S) = 1 := mk_self' @[simp] lemma coe_mul_mk (x y : α) (s : S) : ↑x * mk y s = mk (x * y) s := quotient.sound $ r_of_eq $ by rw one_mul lemma mk_eq_mul_mk_one (r : α) (s : S) : mk r s = r * mk 1 s := by rw [coe_mul_mk, mul_one] @[simp] lemma mk_mul_mk (x y : α) (s t : S) : mk x s * mk y t = mk (x * y) (s * t) := rfl @[simp] lemma mk_mul_cancel_left (r : α) (s : S) : mk (↑s * r) s = r := by rw [mk_eq_mul_mk_one, mul_comm ↑s, coe_mul, mul_assoc, ← mk_eq_mul_mk_one, mk_self', mul_one] @[simp] lemma mk_mul_cancel_right (r : α) (s : S) : mk (r * s) s = r := by rw [mul_comm, mk_mul_cancel_left] @[simp] lemma mk_eq (r : α) (s : S) : mk r s = r * ((to_units s)⁻¹ : units _) := quotient.sound $ by simp @[elab_as_eliminator] protected theorem induction_on {C : localization α S → Prop} (x : localization α S) (ih : ∀ r s, C (mk r s : localization α S)) : C x := by rcases x with ⟨r, s⟩; exact ih r s section variables {β : Type v} [comm_ring β] {T : set β} [is_submonoid T] (f : α → β) [is_ring_hom f] @[elab_with_expected_type] def lift' (g : S → units β) (hg : ∀ s, (g s : β) = f s) (x : localization α S) : β := quotient.lift_on x (λ p, f p.1 * ((g p.2)⁻¹ : units β)) $ λ ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨t, hts, ht⟩, show f r₁ * ↑(g s₁)⁻¹ = f r₂ * ↑(g s₂)⁻¹, from calc f r₁ * ↑(g s₁)⁻¹ = (f r₁ * g s₂ + ((g s₁ * f r₂ - g s₂ * f r₁) * g ⟨t, hts⟩) * ↑(g ⟨t, hts⟩)⁻¹) * ↑(g s₁)⁻¹ * ↑(g s₂)⁻¹ : by simp only [hg, subtype.coe_mk, (is_ring_hom.map_mul f).symm, (is_ring_hom.map_sub f).symm, ht, is_ring_hom.map_zero f, zero_mul, add_zero]; rw [is_ring_hom.map_mul f, ← hg, mul_right_comm, mul_assoc (f r₁), ← units.coe_mul, mul_inv_self]; rw [units.coe_one, mul_one] ... = f r₂ * ↑(g s₂)⁻¹ : by rw [mul_assoc, mul_assoc, ← units.coe_mul, mul_inv_self, units.coe_one, mul_one, mul_comm ↑(g s₂), add_sub_cancel'_right]; rw [mul_comm ↑(g s₁), ← mul_assoc, mul_assoc (f r₂), ← units.coe_mul, mul_inv_self, units.coe_one, mul_one] instance lift'.is_ring_hom (g : S → units β) (hg : ∀ s, (g s : β) = f s) : is_ring_hom (localization.lift' f g hg) := { map_one := have g 1 = 1, from units.ext (by rw hg; exact is_ring_hom.map_one f), show f 1 * ↑(g 1)⁻¹ = 1, by rw [this, one_inv, units.coe_one, mul_one, is_ring_hom.map_one f], map_mul := λ x y, localization.induction_on x $ λ r₁ s₁, localization.induction_on y $ λ r₂ s₂, have g (s₁ * s₂) = g s₁ * g s₂, from units.ext (by simp only [hg, units.coe_mul]; exact is_ring_hom.map_mul f), show _ * ↑(g (_ * _))⁻¹ = (_ * _) * (_ * _), by simp only [subtype.coe_mk, mul_one, one_mul, subtype.coe_eta, this, mul_inv_rev]; rw [is_ring_hom.map_mul f, units.coe_mul, ← mul_assoc, ← mul_assoc]; simp only [mul_right_comm], map_add := λ x y, localization.induction_on x $ λ r₁ s₁, localization.induction_on y $ λ r₂ s₂, have g (s₁ * s₂) = g s₁ * g s₂, from units.ext (by simp only [hg, units.coe_mul]; exact is_ring_hom.map_mul f), show _ * ↑(g (_ * _))⁻¹ = _ * _ + _ * _, by simp only [subtype.coe_mk, mul_one, one_mul, subtype.coe_eta, this, mul_inv_rev]; simp only [is_ring_hom.map_mul f, is_ring_hom.map_add f, add_mul, (hg _).symm]; simp only [mul_assoc, mul_comm, mul_left_comm, (units.coe_mul _ _).symm]; rw [mul_inv_cancel_left, mul_left_comm, ← mul_assoc, mul_inv_cancel_right, add_comm] } noncomputable def lift (h : ∀ s ∈ S, is_unit (f s)) : localization α S → β := localization.lift' f (λ s, classical.some $ h s.1 s.2) (λ s, by rw [← classical.some_spec (h s.1 s.2)]; refl) instance lift.is_ring_hom (h : ∀ s ∈ S, is_unit (f s)) : is_ring_hom (lift f h) := lift'.is_ring_hom _ _ _ @[simp] lemma lift'_mk (g : S → units β) (hg : ∀ s, (g s : β) = f s) (r : α) (s : S) : lift' f g hg (mk r s) = f r * ↑(g s)⁻¹ := rfl @[simp] lemma lift'_of (g : S → units β) (hg : ∀ s, (g s : β) = f s) (a : α) : lift' f g hg (of a) = f a := have g 1 = 1, from units.ext_iff.2 $ by simp [hg, is_ring_hom.map_one f], by simp [lift', quotient.lift_on_beta, of, mk, this] @[simp] lemma lift'_coe (g : S → units β) (hg : ∀ s, (g s : β) = f s) (a : α) : lift' f g hg a = f a := lift'_of _ _ _ _ @[simp] lemma lift_of (h : ∀ s ∈ S, is_unit (f s)) (a : α) : lift f h (of a) = f a := lift'_of _ _ _ _ @[simp] lemma lift_coe (h : ∀ s ∈ S, is_unit (f s)) (a : α) : lift f h a = f a := lift'_of _ _ _ _ @[simp] lemma lift'_comp_of (g : S → units β) (hg : ∀ s, (g s : β) = f s) : lift' f g hg ∘ of = f := funext $ λ a, lift'_of _ _ _ a @[simp] lemma lift_comp_of (h : ∀ s ∈ S, is_unit (f s)) : lift f h ∘ of = f := lift'_comp_of _ _ _ @[simp] lemma lift'_apply_coe (f : localization α S → β) [is_ring_hom f] (g : S → units β) (hg : ∀ s, (g s : β) = f s) : lift' (λ a : α, f a) g hg = f := have g = (λ s, (units.map' f : units (localization α S) → units β) (to_units s)), from funext $ λ x, units.ext $ (hg x).symm ▸ rfl, funext $ λ x, localization.induction_on x (λ r s, by subst this; rw [lift'_mk, ← (units.map' f).map_inv, units.coe_map']; simp [is_ring_hom.map_mul f]) @[simp] lemma lift_apply_coe (f : localization α S → β) [is_ring_hom f] : lift (λ a : α, f a) (λ s hs, is_unit.map' f (is_unit_unit (to_units ⟨s, hs⟩))) = f := by rw [lift, lift'_apply_coe] /-- Function extensionality for localisations: two functions are equal if they agree on elements that are coercions.-/ protected lemma funext (f g : localization α S → β) [is_ring_hom f] [is_ring_hom g] (h : ∀ a : α, f a = g a) : f = g := begin rw [← lift_apply_coe f, ← lift_apply_coe g], congr' 1, exact funext h end variables {α S T} def map (hf : ∀ s ∈ S, f s ∈ T) : localization α S → localization β T := lift' (of ∘ f) (to_units ∘ subtype.map f hf) (λ s, rfl) instance map.is_ring_hom (hf : ∀ s ∈ S, f s ∈ T) : is_ring_hom (map f hf) := lift'.is_ring_hom _ _ _ @[simp] lemma map_of (hf : ∀ s ∈ S, f s ∈ T) (a : α) : map f hf (of a) = of (f a) := lift'_of _ _ _ _ @[simp] lemma map_coe (hf : ∀ s ∈ S, f s ∈ T) (a : α) : map f hf a = (f a) := lift'_of _ _ _ _ @[simp] lemma map_comp_of (hf : ∀ s ∈ S, f s ∈ T) : map f hf ∘ of = of ∘ f := funext $ λ a, map_of _ _ _ @[simp] lemma map_id : map id (λ s (hs : s ∈ S), hs) = id := localization.funext _ _ $ map_coe _ _ lemma map_comp_map {γ : Type*} [comm_ring γ] (hf : ∀ s ∈ S, f s ∈ T) (U : set γ) [is_submonoid U] (g : β → γ) [is_ring_hom g] (hg : ∀ t ∈ T, g t ∈ U) : map g hg ∘ map f hf = map (λ x, g (f x)) (λ s hs, hg _ (hf _ hs)) := localization.funext _ _ $ by simp lemma map_map {γ : Type*} [comm_ring γ] (hf : ∀ s ∈ S, f s ∈ T) (U : set γ) [is_submonoid U] (g : β → γ) [is_ring_hom g] (hg : ∀ t ∈ T, g t ∈ U) (x) : map g hg (map f hf x) = map (λ x, g (f x)) (λ s hs, hg _ (hf _ hs)) x := congr_fun (map_comp_map _ _ _ _ _) x def equiv_of_equiv (h₁ : α ≃+* β) (h₂ : h₁ '' S = T) : localization α S ≃+* localization β T := { to_fun := map h₁ $ λ s hs, h₂ ▸ set.mem_image_of_mem _ hs, inv_fun := map h₁.symm $ λ t ht, by simp [h₁.image_eq_preimage, set.preimage, set.ext_iff, *] at *, left_inv := λ _, by simp only [map_map, h₁.symm_apply_apply]; erw map_id; refl, right_inv := λ _, by simp only [map_map, h₁.apply_symm_apply]; erw map_id; refl, map_mul' := λ _ _, is_ring_hom.map_mul _, map_add' := λ _ _, is_ring_hom.map_add _ } end section away variables {β : Type v} [comm_ring β] (f : α → β) [is_ring_hom f] @[reducible] def away (x : α) := localization α (powers x) @[simp] def away.inv_self (x : α) : away x := mk 1 ⟨x, 1, pow_one x⟩ @[elab_with_expected_type] noncomputable def away.lift {x : α} (hfx : is_unit (f x)) : away x → β := localization.lift' f (λ s, classical.some hfx ^ classical.some s.2) $ λ s, by rw [units.coe_pow, ← classical.some_spec hfx, ← is_semiring_hom.map_pow f, classical.some_spec s.2]; refl instance away.lift.is_ring_hom {x : α} (hfx : is_unit (f x)) : is_ring_hom (localization.away.lift f hfx) := lift'.is_ring_hom _ _ _ @[simp] lemma away.lift_of {x : α} (hfx : is_unit (f x)) (a : α) : away.lift f hfx (of a) = f a := lift'_of _ _ _ _ @[simp] lemma away.lift_coe {x : α} (hfx : is_unit (f x)) (a : α) : away.lift f hfx a = f a := lift'_of _ _ _ _ @[simp] lemma away.lift_comp_of {x : α} (hfx : is_unit (f x)) : away.lift f hfx ∘ of = f := lift'_comp_of _ _ _ noncomputable def away_to_away_right (x y : α) : away x → away (x * y) := localization.away.lift coe $ is_unit_of_mul_one x (y * away.inv_self (x * y)) $ by rw [away.inv_self, coe_mul_mk, coe_mul_mk, mul_one, mk_self] instance away_to_away_right.is_ring_hom (x y : α) : is_ring_hom (away_to_away_right x y) := away.lift.is_ring_hom _ _ end away section at_prime variables (P : ideal α) [hp : ideal.is_prime P] include hp instance prime.is_submonoid : is_submonoid (-P : set α) := { one_mem := P.ne_top_iff_one.1 hp.1, mul_mem := λ x y hnx hny hxy, or.cases_on (hp.2 hxy) hnx hny } @[reducible] def at_prime := localization α (-P) instance at_prime.local_ring : local_ring (at_prime P) := local_of_nonunits_ideal (λ hze, let ⟨t, hts, ht⟩ := quotient.exact hze in hts $ have htz : t = 0, by simpa using ht, suffices (0:α) ∈ P, by rwa htz, P.zero_mem) (begin rintro ⟨⟨r₁, s₁, hs₁⟩⟩ ⟨⟨r₂, s₂, hs₂⟩⟩ hx hy hu, rcases is_unit_iff_exists_inv.1 hu with ⟨⟨⟨r₃, s₃, hs₃⟩⟩, hz⟩, rcases quotient.exact hz with ⟨t, hts, ht⟩, simp at ht, have : ∀ {r s hs}, (⟦⟨r, s, hs⟩⟧ : at_prime P) ∈ nonunits (at_prime P) → r ∈ P, { haveI := classical.dec, exact λ r s hs, not_imp_comm.1 (λ nr, is_unit_iff_exists_inv.2 ⟨⟦⟨s, r, nr⟩⟧, quotient.sound $ r_of_eq $ by simp [mul_comm]⟩) }, have hr₃ := (hp.mem_or_mem_of_mul_eq_zero ht).resolve_right hts, have := (ideal.add_mem_iff_left _ _).1 hr₃, { exact not_or (mt hp.mem_or_mem (not_or hs₁ hs₂)) hs₃ (hp.mem_or_mem this) }, { exact P.neg_mem (P.mul_mem_right (P.add_mem (P.mul_mem_left (this hy)) (P.mul_mem_left (this hx)))) } end) end at_prime variable (α) def non_zero_divisors : set α := {x | ∀ z, z * x = 0 → z = 0} instance non_zero_divisors.is_submonoid : is_submonoid (non_zero_divisors α) := { one_mem := λ z hz, by rwa mul_one at hz, mul_mem := λ x₁ x₂ hx₁ hx₂ z hz, have z * x₁ * x₂ = 0, by rwa mul_assoc, hx₁ z $ hx₂ (z * x₁) this } @[simp] lemma non_zero_divisors_one_val : (1 : non_zero_divisors α).val = 1 := rfl /-- The field of fractions of an integral domain.-/ @[reducible] def fraction_ring := localization α (non_zero_divisors α) namespace fraction_ring open function variables {β : Type u} [integral_domain β] [decidable_eq β] lemma eq_zero_of_ne_zero_of_mul_eq_zero {x y : β} : x ≠ 0 → y * x = 0 → y = 0 := λ hnx hxy, or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx lemma mem_non_zero_divisors_iff_ne_zero {x : β} : x ∈ non_zero_divisors β ↔ x ≠ 0 := ⟨λ hm hz, zero_ne_one (hm 1 $ by rw [hz, one_mul]).symm, λ hnx z, eq_zero_of_ne_zero_of_mul_eq_zero hnx⟩ variable (β) def inv_aux (x : β × (non_zero_divisors β)) : fraction_ring β := if h : x.1 = 0 then 0 else ⟦⟨x.2, x.1, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ instance : has_inv (fraction_ring β) := ⟨quotient.lift (inv_aux β) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩, begin have hrs : s₁ * r₂ = 0 + s₂ * r₁, from sub_eq_iff_eq_add.1 (hts _ ht), by_cases hr₁ : r₁ = 0; by_cases hr₂ : r₂ = 0; simp [hr₁, hr₂] at hrs; simp only [inv_aux, hr₁, hr₂, dif_pos, dif_neg, not_false_iff, subtype.coe_mk, quotient.eq], { exfalso, exact mem_non_zero_divisors_iff_ne_zero.mp hs₁ hrs }, { exfalso, exact mem_non_zero_divisors_iff_ne_zero.mp hs₂ hrs }, { apply r_of_eq, simpa [mul_comm] using hrs.symm } end⟩ lemma mk_inv {r s} : (mk r s : fraction_ring β)⁻¹ = if h : r = 0 then 0 else ⟦⟨s, r, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ := rfl lemma mk_inv' : ∀ (x : β × (non_zero_divisors β)), (⟦x⟧⁻¹ : fraction_ring β) = if h : x.1 = 0 then 0 else ⟦⟨x.2.val, x.1, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ | ⟨r,s,hs⟩ := rfl instance : decidable_eq (fraction_ring β) := @quotient.decidable_eq (β × non_zero_divisors β) (localization.setoid β (non_zero_divisors β)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩, show decidable (∃ t ∈ non_zero_divisors β, (s₁ * r₂ - s₂ * r₁) * t = 0), from decidable_of_iff (s₁ * r₂ - s₂ * r₁ = 0) ⟨λ H, ⟨1, λ y, (mul_one y).symm ▸ id, H.symm ▸ zero_mul _⟩, λ ⟨t, ht1, ht2⟩, or.resolve_right (mul_eq_zero.1 ht2) $ λ ht, one_ne_zero (ht1 1 ((one_mul t).symm ▸ ht))⟩ instance : discrete_field (fraction_ring β) := by refine { inv := has_inv.inv, zero_ne_one := λ hzo, let ⟨t, hts, ht⟩ := quotient.exact hzo in zero_ne_one (by simpa using hts _ ht : 0 = 1), mul_inv_cancel := quotient.ind _, inv_mul_cancel := quotient.ind _, has_decidable_eq := fraction_ring.decidable_eq β, inv_zero := dif_pos rfl, .. localization.comm_ring }; { intros x hnx, rcases x with ⟨x, z, hz⟩, have : x ≠ 0, from assume hx, hnx (quotient.sound $ r_of_eq $ by simp [hx]), simp only [has_inv.inv, inv_aux, quotient.lift_beta, dif_neg this], exact (quotient.sound $ r_of_eq $ by simp [mul_comm]) } @[simp] lemma mk_eq_div {r s} : (mk r s : fraction_ring β) = (r / s : fraction_ring β) := show _ = _ * dite (s.1 = 0) _ _, by rw [dif_neg (mem_non_zero_divisors_iff_ne_zero.mp s.2)]; exact localization.mk_eq_mul_mk_one _ _ variables {β} @[simp] lemma mk_eq_div' (x : β × (non_zero_divisors β)) : (⟦x⟧ : fraction_ring β) = ((x.1) / ((x.2).val) : fraction_ring β) := by erw ← mk_eq_div; cases x; refl lemma eq_zero_of (x : β) (h : (of x : fraction_ring β) = 0) : x = 0 := begin rcases quotient.exact h with ⟨t, ht, ht'⟩, simpa [mem_non_zero_divisors_iff_ne_zero.mp ht] using ht' end lemma of.injective : function.injective (of : β → fraction_ring β) := (is_add_group_hom.injective_iff _).mpr eq_zero_of section map open function is_ring_hom variables {A : Type u} [integral_domain A] [decidable_eq A] variables {B : Type v} [integral_domain B] [decidable_eq B] variables (f : A → B) [is_ring_hom f] def map (hf : injective f) : fraction_ring A → fraction_ring B := localization.map f $ λ s h, by rw [mem_non_zero_divisors_iff_ne_zero, ← map_zero f, ne.def, hf.eq_iff]; exact mem_non_zero_divisors_iff_ne_zero.1 h @[simp] lemma map_of (hf : injective f) (a : A) : map f hf (of a) = of (f a) := localization.map_of _ _ _ @[simp] lemma map_coe (hf : injective f) (a : A) : map f hf a = f a := localization.map_coe _ _ _ @[simp] lemma map_comp_of (hf : injective f) : map f hf ∘ (of : A → fraction_ring A) = (of : B → fraction_ring B) ∘ f := localization.map_comp_of _ _ instance map.is_ring_hom (hf : injective f) : is_ring_hom (map f hf) := localization.map.is_ring_hom _ _ def equiv_of_equiv (h : A ≃+* B) : fraction_ring A ≃+* fraction_ring B := localization.equiv_of_equiv h begin ext b, rw [h.image_eq_preimage, set.preimage, set.mem_set_of_eq, mem_non_zero_divisors_iff_ne_zero, mem_non_zero_divisors_iff_ne_zero, ne.def], exact h.to_add_equiv.symm.map_ne_zero_iff b end end map end fraction_ring section ideals theorem map_comap (J : ideal (localization α S)) : ideal.map coe (ideal.comap (coe : α → localization α S) J) = J := le_antisymm (ideal.map_le_iff_le_comap.2 (le_refl _)) $ λ x, localization.induction_on x $ λ r s hJ, (submodule.mem_coe _).2 $ mul_one r ▸ coe_mul_mk r 1 s ▸ (ideal.mul_mem_right _ $ ideal.mem_map_of_mem $ have _ := @ideal.mul_mem_left (localization α S) _ _ s _ hJ, by rwa [coe_coe, coe_mul_mk, mk_mul_cancel_left] at this) def le_order_embedding : ((≤) : ideal (localization α S) → ideal (localization α S) → Prop) ≼o ((≤) : ideal α → ideal α → Prop) := { to_fun := λ J, ideal.comap coe J, inj := function.injective_of_left_inverse (map_comap α), ord := λ J₁ J₂, ⟨ideal.comap_mono, λ hJ, map_comap α J₁ ▸ map_comap α J₂ ▸ ideal.map_mono hJ⟩ } end ideals end localization
916bf54f9885adaac0263612b7546bcefaa7cd9b
94e33a31faa76775069b071adea97e86e218a8ee
/src/ring_theory/localization/localization_localization.lean
0bb2ef93f76c624213014fa392eda2955e02cb3b
[ "Apache-2.0" ]
permissive
urkud/mathlib
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
6379d39e6b5b279df9715f8011369a301b634e41
refs/heads/master
1,658,425,342,662
1,658,078,703,000
1,658,078,703,000
186,910,338
0
0
Apache-2.0
1,568,512,083,000
1,557,958,709,000
Lean
UTF-8
Lean
false
false
13,072
lean
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import ring_theory.localization.at_prime import ring_theory.localization.basic import ring_theory.localization.fraction_ring /-! # Localizations of localizations ## Implementation notes See `src/ring_theory/localization/basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variables {R : Type*} [comm_ring R] (M : submonoid R) {S : Type*} [comm_ring S] variables [algebra R S] {P : Type*} [comm_ring P] open function open_locale big_operators namespace is_localization section localization_localization variable (M) variables (N : submonoid S) (T : Type*) [comm_ring T] [algebra R T] section variables [algebra S T] [is_scalar_tower R S T] /-- Localizing wrt `M ⊆ R` and then wrt `N ⊆ S = M⁻¹R` is equal to the localization of `R` wrt this module. See `localization_localization_is_localization`. -/ -- This should only be defined when `S` is the localization `M⁻¹R`, hence the nolint. @[nolint unused_arguments] def localization_localization_submodule : submonoid R := (N ⊔ M.map (algebra_map R S)).comap (algebra_map R S) variables {M N} @[simp] lemma mem_localization_localization_submodule {x : R} : x ∈ localization_localization_submodule M N ↔ ∃ (y : N) (z : M), algebra_map R S x = y * algebra_map R S z := begin rw [localization_localization_submodule, submonoid.mem_comap, submonoid.mem_sup], split, { rintros ⟨y, hy, _, ⟨z, hz, rfl⟩, e⟩, exact ⟨⟨y, hy⟩, ⟨z, hz⟩ ,e.symm⟩ }, { rintros ⟨y, z, e⟩, exact ⟨y, y.prop, _, ⟨z, z.prop, rfl⟩, e.symm⟩ } end variables (M N) [is_localization M S] lemma localization_localization_map_units [is_localization N T] (y : localization_localization_submodule M N) : is_unit (algebra_map R T y) := begin obtain ⟨y', z, eq⟩ := mem_localization_localization_submodule.mp y.prop, rw [is_scalar_tower.algebra_map_apply R S T, eq, ring_hom.map_mul, is_unit.mul_iff], exact ⟨is_localization.map_units T y', (is_localization.map_units _ z).map (algebra_map S T)⟩, end lemma localization_localization_surj [is_localization N T] (x : T) : ∃ (y : R × localization_localization_submodule M N), x * (algebra_map R T y.2) = algebra_map R T y.1 := begin rcases is_localization.surj N x with ⟨⟨y, s⟩, eq₁⟩, -- x = y / s rcases is_localization.surj M y with ⟨⟨z, t⟩, eq₂⟩, -- y = z / t rcases is_localization.surj M (s : S) with ⟨⟨z', t'⟩, eq₃⟩, -- s = z' / t' dsimp only at eq₁ eq₂ eq₃, use z * t', use z' * t, -- x = y / s = (z * t') / (z' * t) { rw mem_localization_localization_submodule, refine ⟨s, t * t', _⟩, rw [ring_hom.map_mul, ← eq₃, mul_assoc, ← ring_hom.map_mul, mul_comm t, submonoid.coe_mul] }, { simp only [subtype.coe_mk, ring_hom.map_mul, is_scalar_tower.algebra_map_apply R S T, ← eq₃, ← eq₂, ← eq₁], ring }, end lemma localization_localization_eq_iff_exists [is_localization N T] (x y : R) : algebra_map R T x = algebra_map R T y ↔ ∃ (c : localization_localization_submodule M N), x * c = y * c := begin rw [is_scalar_tower.algebra_map_apply R S T, is_scalar_tower.algebra_map_apply R S T, is_localization.eq_iff_exists N T], split, { rintros ⟨z, eq₁⟩, rcases is_localization.surj M (z : S) with ⟨⟨z', s⟩, eq₂⟩, dsimp only at eq₂, obtain ⟨c, eq₃ : x * z' * ↑ c = y * z' * ↑ c⟩ := (is_localization.eq_iff_exists M S).mp _, swap, { rw [ring_hom.map_mul, ring_hom.map_mul, ← eq₂, ← mul_assoc, ← mul_assoc, ← eq₁] }, use z' * c, { rw mem_localization_localization_submodule, refine ⟨z, s * c, _⟩, rw [ring_hom.map_mul, ← eq₂, mul_assoc, ← ring_hom.map_mul, submonoid.coe_mul] }, { simpa only [mul_assoc] using eq₃ } }, { rintro ⟨⟨c, hc⟩, eq₁ : x * c = y * c⟩, rw mem_localization_localization_submodule at hc, rcases hc with ⟨z₁, z, eq₂⟩, use z₁, refine (is_localization.map_units S z).mul_left_inj.mp _, rw [mul_assoc, mul_assoc, ← eq₂, ← ring_hom.map_mul, ← ring_hom.map_mul, eq₁] } end /-- Given submodules `M ⊆ R` and `N ⊆ S = M⁻¹R`, with `f : R →+* S` the localization map, we have `N ⁻¹ S = T = (f⁻¹ (N • f(M))) ⁻¹ R`. I.e., the localization of a localization is a localization. -/ lemma localization_localization_is_localization [is_localization N T] : is_localization (localization_localization_submodule M N) T := { map_units := localization_localization_map_units M N T, surj := localization_localization_surj M N T, eq_iff_exists := localization_localization_eq_iff_exists M N T } include M /-- Given submodules `M ⊆ R` and `N ⊆ S = M⁻¹R`, with `f : R →+* S` the localization map, if `N` contains all the units of `S`, then `N ⁻¹ S = T = (f⁻¹ N) ⁻¹ R`. I.e., the localization of a localization is a localization. -/ lemma localization_localization_is_localization_of_has_all_units [is_localization N T] (H : ∀ (x : S), is_unit x → x ∈ N) : is_localization (N.comap (algebra_map R S)) T := begin convert localization_localization_is_localization M N T, symmetry, rw sup_eq_left, rintros _ ⟨x, hx, rfl⟩, exact H _ (is_localization.map_units _ ⟨x, hx⟩), end /-- Given a submodule `M ⊆ R` and a prime ideal `p` of `S = M⁻¹R`, with `f : R →+* S` the localization map, then `T = Sₚ` is the localization of `R` at `f⁻¹(p)`. -/ lemma is_localization_is_localization_at_prime_is_localization (p : ideal S) [Hp : p.is_prime] [is_localization.at_prime T p] : is_localization.at_prime T (p.comap (algebra_map R S)) := begin apply localization_localization_is_localization_of_has_all_units M p.prime_compl T, intros x hx hx', exact (Hp.1 : ¬ _) (p.eq_top_of_is_unit_mem hx' hx), end instance (p : ideal (localization M)) [p.is_prime] : algebra R (localization.at_prime p) := localization.algebra instance (p : ideal (localization M)) [p.is_prime] : is_scalar_tower R (localization M) (localization.at_prime p) := is_scalar_tower.of_algebra_map_eq' rfl instance localization_localization_at_prime_is_localization (p : ideal (localization M)) [p.is_prime] : is_localization.at_prime (localization.at_prime p) (p.comap (algebra_map R _)) := is_localization_is_localization_at_prime_is_localization M _ _ /-- Given a submodule `M ⊆ R` and a prime ideal `p` of `M⁻¹R`, with `f : R →+* S` the localization map, then `(M⁻¹R)ₚ` is isomorphic (as an `R`-algebra) to the localization of `R` at `f⁻¹(p)`. -/ noncomputable def localization_localization_at_prime_iso_localization (p : ideal (localization M)) [p.is_prime] : localization.at_prime (p.comap (algebra_map R (localization M))) ≃ₐ[R] localization.at_prime p := is_localization.alg_equiv (p.comap (algebra_map R (localization M))).prime_compl _ _ end variables (S) /-- Given submonoids `M ≤ N` of `R`, this is the canonical algebra structure of `M⁻¹S` acting on `N⁻¹S`. -/ noncomputable def localization_algebra_of_submonoid_le (M N : submonoid R) (h : M ≤ N) [is_localization M S] [is_localization N T] : algebra S T := (is_localization.lift (λ y, (map_units T ⟨↑y, h y.prop⟩ : _)) : S →+* T).to_algebra /-- If `M ≤ N` are submonoids of `R`, then the natural map `M⁻¹S →+* N⁻¹S` commutes with the localization maps -/ lemma localization_is_scalar_tower_of_submonoid_le (M N : submonoid R) (h : M ≤ N) [is_localization M S] [is_localization N T] : @@is_scalar_tower R S T _ (localization_algebra_of_submonoid_le S T M N h).to_has_smul _ := begin letI := localization_algebra_of_submonoid_le S T M N h, exact is_scalar_tower.of_algebra_map_eq' (is_localization.lift_comp _).symm end noncomputable instance (x : ideal R) [H : x.is_prime] [is_domain R] : algebra (localization.at_prime x) (localization (non_zero_divisors R)) := localization_algebra_of_submonoid_le _ _ x.prime_compl (non_zero_divisors R) (by { intros a ha, rw mem_non_zero_divisors_iff_ne_zero, exact λ h, ha (h.symm ▸ x.zero_mem) }) /-- If `M ≤ N` are submonoids of `R`, then `N⁻¹S` is also the localization of `M⁻¹S` at `N`. -/ lemma is_localization_of_submonoid_le (M N : submonoid R) (h : M ≤ N) [is_localization M S] [is_localization N T] [algebra S T] [is_scalar_tower R S T] : is_localization (N.map (algebra_map R S).to_monoid_hom) T := { map_units := begin rintro ⟨_, ⟨y, hy, rfl⟩⟩, convert is_localization.map_units T ⟨y, hy⟩, exact (is_scalar_tower.algebra_map_apply _ _ _ _).symm end, surj := λ y, begin obtain ⟨⟨x, s⟩, e⟩ := is_localization.surj N y, refine ⟨⟨algebra_map _ _ x, _, _, s.prop, rfl⟩, _⟩, simpa [← is_scalar_tower.algebra_map_apply] using e end, eq_iff_exists := λ x₁ x₂, begin obtain ⟨⟨y₁, s₁⟩, e₁⟩ := is_localization.surj M x₁, obtain ⟨⟨y₂, s₂⟩, e₂⟩ := is_localization.surj M x₂, refine iff.trans _ (set.exists_image_iff (algebra_map R S) N (λ c, x₁ * c = x₂ * c)).symm, dsimp only at e₁ e₂ ⊢, suffices : algebra_map R T (y₁ * s₂) = algebra_map R T (y₂ * s₁) ↔ ∃ (a : N), algebra_map R S (a * (y₁ * s₂)) = algebra_map R S (a * (y₂ * s₁)), { have h₁ := (is_localization.map_units T ⟨_, h s₁.prop⟩).mul_left_inj, have h₂ := (is_localization.map_units T ⟨_, h s₂.prop⟩).mul_left_inj, simp only [is_scalar_tower.algebra_map_apply R S T, subtype.coe_mk] at h₁ h₂, simp only [is_scalar_tower.algebra_map_apply R S T, map_mul, ← e₁, ← e₂, ← mul_assoc, mul_right_comm _ (algebra_map R S s₂), mul_right_comm _ (algebra_map S T (algebra_map R S s₂)), (is_localization.map_units S s₁).mul_left_inj, (is_localization.map_units S s₂).mul_left_inj] at this, rw [h₂, h₁] at this, simpa only [mul_comm] using this }, simp_rw [is_localization.eq_iff_exists N T, is_localization.eq_iff_exists M S], split, { rintro ⟨a, e⟩, exact ⟨a, 1, by { convert e using 1; simp; ring }⟩ }, { rintro ⟨a, b, e⟩, exact ⟨a * (⟨_, h b.prop⟩ : N), by { convert e using 1; simp; ring }⟩ } end } /-- If `M ≤ N` are submonoids of `R` such that `∀ x : N, ∃ m : R, m * x ∈ M`, then the localization at `N` is equal to the localizaton of `M`. -/ lemma is_localization_of_is_exists_mul_mem (M N : submonoid R) [is_localization M S] (h : M ≤ N) (h' : ∀ x : N, ∃ m : R, m * x ∈ M) : is_localization N S := { map_units := λ y, begin obtain ⟨m, hm⟩ := h' y, have := is_localization.map_units S ⟨_, hm⟩, erw map_mul at this, exact (is_unit.mul_iff.mp this).2 end, surj := λ z, by { obtain ⟨⟨y, s⟩, e⟩ := is_localization.surj M z, exact ⟨⟨y, _, h s.prop⟩, e⟩ }, eq_iff_exists := λ x₁ x₂, begin rw is_localization.eq_iff_exists M, refine ⟨λ ⟨x, hx⟩, ⟨⟨_, h x.prop⟩, hx⟩, _⟩, rintros ⟨x, h⟩, obtain ⟨m, hm⟩ := h' x, refine ⟨⟨_, hm⟩, _⟩, simp [mul_comm m, ← mul_assoc, h] end } end localization_localization end is_localization namespace is_fraction_ring open is_localization variable (M) lemma is_fraction_ring_of_is_localization (S T : Type*) [comm_ring S] [comm_ring T] [algebra R S] [algebra R T] [algebra S T] [is_scalar_tower R S T] [is_localization M S] [is_fraction_ring R T] (hM : M ≤ non_zero_divisors R) : is_fraction_ring S T := begin have := is_localization_of_submonoid_le S T M (non_zero_divisors R) _, refine @@is_localization_of_is_exists_mul_mem _ _ _ _ _ _ this _ _, { exact map_non_zero_divisors_le M S }, { rintro ⟨x, hx⟩, obtain ⟨⟨y, s⟩, e⟩ := is_localization.surj M x, use algebra_map R S s, rw [mul_comm, subtype.coe_mk, e], refine set.mem_image_of_mem (algebra_map R S) _, intros z hz, apply is_localization.injective S hM, rw map_zero, apply hx, rw [← (map_units S s).mul_left_inj, mul_assoc, e, ← map_mul, hz, map_zero, zero_mul] }, { exact hM } end lemma is_fraction_ring_of_is_domain_of_is_localization [is_domain R] (S T : Type*) [comm_ring S] [comm_ring T] [algebra R S] [algebra R T] [algebra S T] [is_scalar_tower R S T] [is_localization M S] [is_fraction_ring R T] : is_fraction_ring S T := begin haveI := is_fraction_ring.nontrivial R T, haveI := (algebra_map S T).domain_nontrivial, apply is_fraction_ring_of_is_localization M S T, intros x hx, rw mem_non_zero_divisors_iff_ne_zero, intro hx', apply @zero_ne_one S, rw [← (algebra_map R S).map_one, ← @mk'_one R _ M, @comm _ eq, mk'_eq_zero_iff], exact ⟨⟨_, hx⟩, (one_mul x).symm ▸ hx'⟩, end end is_fraction_ring
af4f79321aaa1deedd6bff4e4ba8597bd2cf72aa
08bd4ba4ca87dba1f09d2c96a26f5d65da81f4b4
/src/Lean/SubExpr.lean
e8c705e9ed5ed72a58d7a4de1d8633d48cba4425
[ "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", "Apache-2.0", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
gebner/lean4
d51c4922640a52a6f7426536ea669ef18a1d9af5
8cd9ce06843c9d42d6d6dc43d3e81e3b49dfc20f
refs/heads/master
1,685,732,780,391
1,672,962,627,000
1,673,459,398,000
373,307,283
0
0
Apache-2.0
1,691,316,730,000
1,622,669,271,000
Lean
UTF-8
Lean
false
false
6,982
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sebastian Ullrich, Daniel Selsam, Wojciech Nawrocki, E.W.Ayers -/ import Lean.Meta.Basic import Lean.Data.Json import Lean.Data.RBMap namespace Lean /-- A position of a subexpression in an expression. See docstring of `SubExpr` for more detail.-/ def SubExpr.Pos := Nat namespace SubExpr.Pos def maxChildren := 4 /-- The coordinate `3 = maxChildren - 1` is reserved to denote the type of the expression. -/ def typeCoord : Nat := maxChildren - 1 def asNat : Pos → Nat := id /-- The Pos representing the root subexpression. -/ def root : Pos := (1 : Nat) instance : Inhabited Pos := ⟨root⟩ def isRoot (p : Pos) : Bool := p.asNat < maxChildren /-- The coordinate deepest in the Pos. -/ def head (p : Pos) : Nat := if p.isRoot then panic! "already at top" else p.asNat % maxChildren def tail (p : Pos) : Pos := if p.isRoot then panic! "already at top" else (p.asNat - p.head) / maxChildren def push (p : Pos) (c : Nat) : Pos := if c >= maxChildren then panic! s!"invalid coordinate {c}" else p.asNat * maxChildren + c variable {α : Type} [Inhabited α] /-- Fold over the position starting at the root and heading to the leaf-/ partial def foldl (f : α → Nat → α) (a : α) (p : Pos) : α := if p.isRoot then a else f (foldl f a p.tail) p.head /-- Fold over the position starting at the leaf and heading to the root-/ partial def foldr (f : Nat → α → α) (p : Pos) (a : α) : α := if p.isRoot then a else foldr f p.tail (f p.head a) /-- monad-fold over the position starting at the root and heading to the leaf -/ partial def foldlM [Monad M] (f : α → Nat → M α) (a : α) (p : Pos) : M α := have : Inhabited (M α) := inferInstance if p.isRoot then pure a else do foldlM f a p.tail >>= (f · p.head) /-- monad-fold over the position starting at the leaf and finishing at the root. -/ partial def foldrM [Monad M] (f : Nat → α → M α) (p : Pos) (a : α) : M α := if p.isRoot then pure a else f p.head a >>= foldrM f p.tail def depth (p : Pos) := p.foldr (fun _ => Nat.succ) 0 /-- Returns true if `pred` is true for each coordinate in `p`.-/ def all (pred : Nat → Bool) (p : Pos) : Bool := OptionT.run (m := Id) (foldrM (fun n a => if pred n then pure a else failure) p ()) |>.isSome def append : Pos → Pos → Pos := foldl push /-- Creates a subexpression `Pos` from an array of 'coordinates'. Each coordinate is a number {0,1,2} expressing which child subexpression should be explored. The first coordinate in the array corresponds to the root of the expression tree. -/ def ofArray (ps : Array Nat) : Pos := ps.foldl push root /-- Decodes a subexpression `Pos` as a sequence of coordinates `cs : Array Nat`. See `Pos.fromArray` for details. `cs[0]` is the coordinate for the root expression. -/ def toArray (p : Pos) : Array Nat := foldl Array.push #[] p def pushBindingDomain (p : Pos) := p.push 0 def pushBindingBody (p : Pos) := p.push 1 def pushLetVarType (p : Pos) := p.push 0 def pushLetValue (p : Pos) := p.push 1 def pushLetBody (p : Pos) := p.push 2 def pushAppFn (p : Pos) := p.push 0 def pushAppArg (p : Pos) := p.push 1 def pushProj (p : Pos) := p.push 0 def pushNaryFn (numArgs : Nat) (p : Pos) : Pos := p.asNat * (maxChildren ^ numArgs) def pushNaryArg (numArgs argIdx : Nat) (p : Pos) : Pos := show Nat from p.asNat * (maxChildren ^ (numArgs - argIdx)) + 1 def pushNthBindingDomain : (binderIdx : Nat) → Pos → Pos | 0, p => p.pushBindingDomain | (n+1), p => pushNthBindingDomain n p.pushBindingBody def pushNthBindingBody : (numBinders : Nat) → Pos → Pos | 0, p => p | (n+1), p => pushNthBindingBody n p.pushBindingBody protected def toString (p : Pos) : String := p.toArray.toList |>.map toString |> String.intercalate "/" |> ("/" ++ ·) open Except in private def ofStringCoord : String → Except String Nat | "0" => ok 0 | "1" => ok 1 | "2" => ok 2 | "3" => ok 3 | c => error s!"Invalid coordinate {c}" open Except in protected def fromString? : String → Except String Pos | "/" => Except.ok Pos.root | s => match String.splitOn s "/" with | "" :: tail => Pos.ofArray <$> tail.toArray.mapM ofStringCoord | ss => error s!"malformed {ss}" protected def fromString! (s : String) : Pos := match Pos.fromString? s with | Except.ok a => a | Except.error e => panic! e instance : Ord Pos := show Ord Nat by infer_instance instance : DecidableEq Pos := show DecidableEq Nat by infer_instance instance : ToString Pos := ⟨Pos.toString⟩ instance : EmptyCollection Pos := ⟨root⟩ instance : Repr Pos where reprPrec p _ := f!"Pos.fromString! {repr p.toString}" -- Note: we can't send the bare Nat over the wire because Json will convert to float -- if the nat is too big and least significant bits will be lost. instance : ToJson Pos := ⟨toJson ∘ Pos.toString⟩ instance : FromJson Pos := ⟨fun j => fromJson? j >>= Pos.fromString?⟩ end SubExpr.Pos /-- An expression and the position of a subexpression within this expression. Subexpressions are encoded as the current subexpression `e` and a position `p : Pos` denoting `e`'s position with respect to the root expression. We use a simple encoding scheme for expression positions `Pos`: every `Expr` constructor has at most 3 direct expression children. Considering an expression's type to be one extra child as well, we can injectively map a path of `childIdxs` to a natural number by computing the value of the 4-ary representation `1 :: childIdxs`, since n-ary representations without leading zeros are unique. Note that `pos` is initialized to `1` (case `childIdxs == []`).-/ structure SubExpr where expr : Expr pos : SubExpr.Pos deriving Inhabited namespace SubExpr def mkRoot (e : Expr) : SubExpr := ⟨e, Pos.root⟩ /-- Returns true if the selected subexpression is the topmost one.-/ def isRoot (s : SubExpr) : Bool := s.pos.isRoot /-- Map from subexpr positions to values. -/ abbrev PosMap (α : Type u) := RBMap Pos α compare def bindingBody! : SubExpr → SubExpr | ⟨.forallE _ _ b _, p⟩ => ⟨b, p.pushBindingBody⟩ | ⟨.lam _ _ b _, p⟩ => ⟨b, p.pushBindingBody⟩ | _ => panic! "subexpr is not a binder" def bindingDomain! : SubExpr → SubExpr | ⟨.forallE _ t _ _, p⟩ => ⟨t, p.pushBindingDomain⟩ | ⟨.lam _ t _ _, p⟩ => ⟨t, p.pushBindingDomain⟩ | _ => panic! "subexpr is not a binder" end SubExpr open SubExpr in /-- Same as `Expr.traverseApp` but also includes a `SubExpr.Pos` argument for tracking subexpression position. -/ def Expr.traverseAppWithPos {M} [Monad M] (visit : Pos → Expr → M Expr) (p : Pos) (e : Expr) : M Expr := match e with | Expr.app f a => e.updateApp! <$> traverseAppWithPos visit p.pushAppFn f <*> visit p.pushAppArg a | e => visit p e end Lean
a1ae2325bf9033512bd9b483734008708871872b
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/data/set/pointwise/smul.lean
fadc4414c6e4f70219978011d61aaaab86456c23
[ "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
26,469
lean
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Floris van Doorn -/ import algebra.module.basic import data.set.pairwise import data.set.pointwise.basic /-! # Pointwise operations of sets This file defines pointwise algebraic operations on sets. ## Main declarations For sets `s` and `t` and scalar `a`: * `s • t`: Scalar multiplication, set of all `x • y` where `x ∈ s` and `y ∈ t`. * `s +ᵥ t`: Scalar addition, set of all `x +ᵥ y` where `x ∈ s` and `y ∈ t`. * `s -ᵥ t`: Scalar subtraction, set of all `x -ᵥ y` where `x ∈ s` and `y ∈ t`. * `a • s`: Scaling, set of all `a • x` where `x ∈ s`. * `a +ᵥ s`: Translation, set of all `a +ᵥ x` where `x ∈ s`. For `α` a semigroup/monoid, `set α` is a semigroup/monoid. Appropriate definitions and results are also transported to the additive theory via `to_additive`. ## Implementation notes * We put all instances in the locale `pointwise`, so that these instances are not available by default. Note that we do not mark them as reducible (as argued by note [reducible non-instances]) since we expect the locale to be open whenever the instances are actually used (and making the instances reducible changes the behavior of `simp`. -/ open function variables {F α β γ : Type*} namespace set open_locale pointwise /-! ### Translation/scaling of sets -/ section smul /-- The dilation of set `x • s` is defined as `{x • y | y ∈ s}` in locale `pointwise`. -/ @[to_additive "The translation of set `x +ᵥ s` is defined as `{x +ᵥ y | y ∈ s}` in locale `pointwise`."] protected def has_smul_set [has_smul α β] : has_smul α (set β) := ⟨λ a, image (has_smul.smul a)⟩ /-- The pointwise scalar multiplication of sets `s • t` is defined as `{x • y | x ∈ s, y ∈ t}` in locale `pointwise`. -/ @[to_additive "The pointwise scalar addition of sets `s +ᵥ t` is defined as `{x +ᵥ y | x ∈ s, y ∈ t}` in locale `pointwise`."] protected def has_smul [has_smul α β] : has_smul (set α) (set β) := ⟨image2 has_smul.smul⟩ localized "attribute [instance] set.has_smul_set set.has_smul" in pointwise localized "attribute [instance] set.has_vadd_set set.has_vadd" in pointwise section has_smul variables {ι : Sort*} {κ : ι → Sort*} [has_smul α β] {s s₁ s₂ : set α} {t t₁ t₂ u : set β} {a : α} {b : β} @[simp, to_additive] lemma image2_smul : image2 has_smul.smul s t = s • t := rfl @[to_additive add_image_prod] lemma image_smul_prod : (λ x : α × β, x.fst • x.snd) '' s ×ˢ t = s • t := image_prod _ @[to_additive] lemma mem_smul : b ∈ s • t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x • y = b := iff.rfl @[to_additive] lemma smul_mem_smul : a ∈ s → b ∈ t → a • b ∈ s • t := mem_image2_of_mem @[simp, to_additive] lemma empty_smul : (∅ : set α) • t = ∅ := image2_empty_left @[simp, to_additive] lemma smul_empty : s • (∅ : set β) = ∅ := image2_empty_right @[simp, to_additive] lemma smul_eq_empty : s • t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff @[simp, to_additive] lemma smul_nonempty : (s • t).nonempty ↔ s.nonempty ∧ t.nonempty := image2_nonempty_iff @[to_additive] lemma nonempty.smul : s.nonempty → t.nonempty → (s • t).nonempty := nonempty.image2 @[to_additive] lemma nonempty.of_smul_left : (s • t).nonempty → s.nonempty := nonempty.of_image2_left @[to_additive] lemma nonempty.of_smul_right : (s • t).nonempty → t.nonempty := nonempty.of_image2_right @[simp, to_additive] lemma smul_singleton : s • {b} = (• b) '' s := image2_singleton_right @[simp, to_additive] lemma singleton_smul : ({a} : set α) • t = a • t := image2_singleton_left @[simp, to_additive] lemma singleton_smul_singleton : ({a} : set α) • ({b} : set β) = {a • b} := image2_singleton @[to_additive, mono] lemma smul_subset_smul : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ • t₁ ⊆ s₂ • t₂ := image2_subset @[to_additive] lemma smul_subset_smul_left : t₁ ⊆ t₂ → s • t₁ ⊆ s • t₂ := image2_subset_left @[to_additive] lemma smul_subset_smul_right : s₁ ⊆ s₂ → s₁ • t ⊆ s₂ • t := image2_subset_right @[to_additive] lemma smul_subset_iff : s • t ⊆ u ↔ ∀ (a ∈ s) (b ∈ t), a • b ∈ u := image2_subset_iff attribute [mono] vadd_subset_vadd @[to_additive] lemma union_smul : (s₁ ∪ s₂) • t = s₁ • t ∪ s₂ • t := image2_union_left @[to_additive] lemma smul_union : s • (t₁ ∪ t₂) = s • t₁ ∪ s • t₂ := image2_union_right @[to_additive] lemma inter_smul_subset : (s₁ ∩ s₂) • t ⊆ s₁ • t ∩ s₂ • t := image2_inter_subset_left @[to_additive] lemma smul_inter_subset : s • (t₁ ∩ t₂) ⊆ s • t₁ ∩ s • t₂ := image2_inter_subset_right @[to_additive] lemma Union_smul_left_image : (⋃ a ∈ s, a • t) = s • t := Union_image_left _ @[to_additive] lemma Union_smul_right_image : (⋃ a ∈ t, (• a) '' s) = s • t := Union_image_right _ @[to_additive] lemma Union_smul (s : ι → set α) (t : set β) : (⋃ i, s i) • t = ⋃ i, s i • t := image2_Union_left _ _ _ @[to_additive] lemma smul_Union (s : set α) (t : ι → set β) : s • (⋃ i, t i) = ⋃ i, s • t i := image2_Union_right _ _ _ @[to_additive] lemma Union₂_smul (s : Π i, κ i → set α) (t : set β) : (⋃ i j, s i j) • t = ⋃ i j, s i j • t := image2_Union₂_left _ _ _ @[to_additive] lemma smul_Union₂ (s : set α) (t : Π i, κ i → set β) : s • (⋃ i j, t i j) = ⋃ i j, s • t i j := image2_Union₂_right _ _ _ @[to_additive] lemma Inter_smul_subset (s : ι → set α) (t : set β) : (⋂ i, s i) • t ⊆ ⋂ i, s i • t := image2_Inter_subset_left _ _ _ @[to_additive] lemma smul_Inter_subset (s : set α) (t : ι → set β) : s • (⋂ i, t i) ⊆ ⋂ i, s • t i := image2_Inter_subset_right _ _ _ @[to_additive] lemma Inter₂_smul_subset (s : Π i, κ i → set α) (t : set β) : (⋂ i j, s i j) • t ⊆ ⋂ i j, s i j • t := image2_Inter₂_subset_left _ _ _ @[to_additive] lemma smul_Inter₂_subset (s : set α) (t : Π i, κ i → set β) : s • (⋂ i j, t i j) ⊆ ⋂ i j, s • t i j := image2_Inter₂_subset_right _ _ _ @[simp, to_additive] lemma bUnion_smul_set (s : set α) (t : set β) : (⋃ a ∈ s, a • t) = s • t := Union_image_left _ end has_smul section has_smul_set variables {ι : Sort*} {κ : ι → Sort*} [has_smul α β] {s t t₁ t₂ : set β} {a : α} {b : β} {x y : β} @[simp, to_additive] lemma image_smul : (λ x, a • x) '' t = a • t := rfl @[to_additive] lemma mem_smul_set : x ∈ a • t ↔ ∃ y, y ∈ t ∧ a • y = x := iff.rfl @[to_additive] lemma smul_mem_smul_set : b ∈ s → a • b ∈ a • s := mem_image_of_mem _ @[simp, to_additive] lemma smul_set_empty : a • (∅ : set β) = ∅ := image_empty _ @[simp, to_additive] lemma smul_set_eq_empty : a • s = ∅ ↔ s = ∅ := image_eq_empty @[simp, to_additive] lemma smul_set_nonempty : (a • s).nonempty ↔ s.nonempty := nonempty_image_iff @[simp, to_additive] lemma smul_set_singleton : a • ({b} : set β) = {a • b} := image_singleton @[to_additive] lemma smul_set_mono : s ⊆ t → a • s ⊆ a • t := image_subset _ @[to_additive] lemma smul_set_subset_iff : a • s ⊆ t ↔ ∀ ⦃b⦄, b ∈ s → a • b ∈ t := image_subset_iff @[to_additive] lemma smul_set_union : a • (t₁ ∪ t₂) = a • t₁ ∪ a • t₂ := image_union _ _ _ @[to_additive] lemma smul_set_inter_subset : a • (t₁ ∩ t₂) ⊆ a • t₁ ∩ (a • t₂) := image_inter_subset _ _ _ @[to_additive] lemma smul_set_Union (a : α) (s : ι → set β) : a • (⋃ i, s i) = ⋃ i, a • s i := image_Union @[to_additive] lemma smul_set_Union₂ (a : α) (s : Π i, κ i → set β) : a • (⋃ i j, s i j) = ⋃ i j, a • s i j := image_Union₂ _ _ @[to_additive] lemma smul_set_Inter_subset (a : α) (t : ι → set β) : a • (⋂ i, t i) ⊆ ⋂ i, a • t i := image_Inter_subset _ _ @[to_additive] lemma smul_set_Inter₂_subset (a : α) (t : Π i, κ i → set β) : a • (⋂ i j, t i j) ⊆ ⋂ i j, a • t i j := image_Inter₂_subset _ _ @[to_additive] lemma nonempty.smul_set : s.nonempty → (a • s).nonempty := nonempty.image _ end has_smul_set variables {s s₁ s₂ : set α} {t t₁ t₂ : set β} {a : α} {b : β} @[simp, to_additive] lemma bUnion_op_smul_set [has_mul α] (s t : set α) : (⋃ a ∈ t, mul_opposite.op a • s) = s * t := Union_image_right _ @[to_additive] lemma smul_set_inter [group α] [mul_action α β] {s t : set β} : a • (s ∩ t) = a • s ∩ a • t := (image_inter $ mul_action.injective a).symm lemma smul_set_inter₀ [group_with_zero α] [mul_action α β] {s t : set β} (ha : a ≠ 0) : a • (s ∩ t) = a • s ∩ a • t := show units.mk0 a ha • _ = _, from smul_set_inter @[simp, to_additive] lemma smul_set_univ [group α] [mul_action α β] {a : α} : a • (univ : set β) = univ := eq_univ_of_forall $ λ b, ⟨a⁻¹ • b, trivial, smul_inv_smul _ _⟩ @[simp, to_additive] lemma smul_univ [group α] [mul_action α β] {s : set α} (hs : s.nonempty) : s • (univ : set β) = univ := let ⟨a, ha⟩ := hs in eq_univ_of_forall $ λ b, ⟨a, a⁻¹ • b, ha, trivial, smul_inv_smul _ _⟩ @[to_additive] theorem range_smul_range {ι κ : Type*} [has_smul α β] (b : ι → α) (c : κ → β) : range b • range c = range (λ p : ι × κ, b p.1 • c p.2) := ext $ λ x, ⟨λ hx, let ⟨p, q, ⟨i, hi⟩, ⟨j, hj⟩, hpq⟩ := set.mem_smul.1 hx in ⟨(i, j), hpq ▸ hi ▸ hj ▸ rfl⟩, λ ⟨⟨i, j⟩, h⟩, set.mem_smul.2 ⟨b i, c j, ⟨i, rfl⟩, ⟨j, rfl⟩, h⟩⟩ @[to_additive] lemma smul_set_range [has_smul α β] {ι : Sort*} {f : ι → β} : a • range f = range (λ i, a • f i) := (range_comp _ _).symm @[to_additive] instance smul_comm_class_set [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] : smul_comm_class α β (set γ) := ⟨λ _ _, commute.set_image $ smul_comm _ _⟩ @[to_additive] instance smul_comm_class_set' [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] : smul_comm_class α (set β) (set γ) := ⟨λ _ _ _, image_image2_distrib_right $ smul_comm _⟩ @[to_additive] instance smul_comm_class_set'' [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] : smul_comm_class (set α) β (set γ) := by haveI := smul_comm_class.symm α β γ; exact smul_comm_class.symm _ _ _ @[to_additive] instance smul_comm_class [has_smul α γ] [has_smul β γ] [smul_comm_class α β γ] : smul_comm_class (set α) (set β) (set γ) := ⟨λ _ _ _, image2_left_comm smul_comm⟩ @[to_additive] instance is_scalar_tower [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] : is_scalar_tower α β (set γ) := { smul_assoc := λ a b T, by simp only [←image_smul, image_image, smul_assoc] } @[to_additive] instance is_scalar_tower' [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] : is_scalar_tower α (set β) (set γ) := ⟨λ _ _ _, image2_image_left_comm $ smul_assoc _⟩ @[to_additive] instance is_scalar_tower'' [has_smul α β] [has_smul α γ] [has_smul β γ] [is_scalar_tower α β γ] : is_scalar_tower (set α) (set β) (set γ) := { smul_assoc := λ T T' T'', image2_assoc smul_assoc } instance is_central_scalar [has_smul α β] [has_smul αᵐᵒᵖ β] [is_central_scalar α β] : is_central_scalar α (set β) := ⟨λ a S, congr_arg (λ f, f '' S) $ by exact funext (λ _, op_smul_eq_smul _ _)⟩ /-- A multiplicative action of a monoid `α` on a type `β` gives a multiplicative action of `set α` on `set β`. -/ @[to_additive "An additive action of an additive monoid `α` on a type `β` gives an additive action of `set α` on `set β`"] protected def mul_action [monoid α] [mul_action α β] : mul_action (set α) (set β) := { mul_smul := λ _ _ _, image2_assoc mul_smul, one_smul := λ s, image2_singleton_left.trans $ by simp_rw [one_smul, image_id'] } /-- A multiplicative action of a monoid on a type `β` gives a multiplicative action on `set β`. -/ @[to_additive "An additive action of an additive monoid on a type `β` gives an additive action on `set β`."] protected def mul_action_set [monoid α] [mul_action α β] : mul_action α (set β) := { mul_smul := by { intros, simp only [← image_smul, image_image, ← mul_smul] }, one_smul := by { intros, simp only [← image_smul, one_smul, image_id'] } } localized "attribute [instance] set.mul_action_set set.add_action_set set.mul_action set.add_action" in pointwise /-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive multiplicative action on `set β`. -/ protected def distrib_mul_action_set [monoid α] [add_monoid β] [distrib_mul_action α β] : distrib_mul_action α (set β) := { smul_add := λ _ _ _, image_image2_distrib $ smul_add _, smul_zero := λ _, image_singleton.trans $ by rw [smul_zero, singleton_zero] } /-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `set β`. -/ protected def mul_distrib_mul_action_set [monoid α] [monoid β] [mul_distrib_mul_action α β] : mul_distrib_mul_action α (set β) := { smul_mul := λ _ _ _, image_image2_distrib $ smul_mul' _, smul_one := λ _, image_singleton.trans $ by rw [smul_one, singleton_one] } localized "attribute [instance] set.distrib_mul_action_set set.mul_distrib_mul_action_set" in pointwise instance [has_zero α] [has_zero β] [has_smul α β] [no_zero_smul_divisors α β] : no_zero_smul_divisors (set α) (set β) := ⟨λ s t h, begin by_contra' H, have hst : (s • t).nonempty := h.symm.subst zero_nonempty, simp_rw [←hst.of_smul_left.subset_zero_iff, ←hst.of_smul_right.subset_zero_iff, not_subset, mem_zero] at H, obtain ⟨⟨a, hs, ha⟩, b, ht, hb⟩ := H, exact (eq_zero_or_eq_zero_of_smul_eq_zero $ h.subset $ smul_mem_smul hs ht).elim ha hb, end⟩ instance no_zero_smul_divisors_set [has_zero α] [has_zero β] [has_smul α β] [no_zero_smul_divisors α β] : no_zero_smul_divisors α (set β) := ⟨λ a s h, begin by_contra' H, have hst : (a • s).nonempty := h.symm.subst zero_nonempty, simp_rw [←hst.of_image.subset_zero_iff, not_subset, mem_zero] at H, obtain ⟨ha, b, ht, hb⟩ := H, exact (eq_zero_or_eq_zero_of_smul_eq_zero $ h.subset $ smul_mem_smul_set ht).elim ha hb, end⟩ instance [has_zero α] [has_mul α] [no_zero_divisors α] : no_zero_divisors (set α) := ⟨λ s t h, eq_zero_or_eq_zero_of_smul_eq_zero h⟩ end smul section vsub variables {ι : Sort*} {κ : ι → Sort*} [has_vsub α β] {s s₁ s₂ t t₁ t₂ : set β} {u : set α} {a : α} {b c : β} include α instance has_vsub : has_vsub (set α) (set β) := ⟨image2 (-ᵥ)⟩ @[simp] lemma image2_vsub : (image2 has_vsub.vsub s t : set α) = s -ᵥ t := rfl lemma image_vsub_prod : (λ x : β × β, x.fst -ᵥ x.snd) '' s ×ˢ t = s -ᵥ t := image_prod _ lemma mem_vsub : a ∈ s -ᵥ t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x -ᵥ y = a := iff.rfl lemma vsub_mem_vsub (hb : b ∈ s) (hc : c ∈ t) : b -ᵥ c ∈ s -ᵥ t := mem_image2_of_mem hb hc @[simp] lemma empty_vsub (t : set β) : ∅ -ᵥ t = ∅ := image2_empty_left @[simp] lemma vsub_empty (s : set β) : s -ᵥ ∅ = ∅ := image2_empty_right @[simp] lemma vsub_eq_empty : s -ᵥ t = ∅ ↔ s = ∅ ∨ t = ∅ := image2_eq_empty_iff @[simp] lemma vsub_nonempty : (s -ᵥ t : set α).nonempty ↔ s.nonempty ∧ t.nonempty := image2_nonempty_iff lemma nonempty.vsub : s.nonempty → t.nonempty → (s -ᵥ t : set α).nonempty := nonempty.image2 lemma nonempty.of_vsub_left : (s -ᵥ t :set α).nonempty → s.nonempty := nonempty.of_image2_left lemma nonempty.of_vsub_right : (s -ᵥ t : set α).nonempty → t.nonempty := nonempty.of_image2_right @[simp] lemma vsub_singleton (s : set β) (b : β) : s -ᵥ {b} = (-ᵥ b) '' s := image2_singleton_right @[simp] lemma singleton_vsub (t : set β) (b : β) : {b} -ᵥ t = ((-ᵥ) b) '' t := image2_singleton_left @[simp] lemma singleton_vsub_singleton : ({b} : set β) -ᵥ {c} = {b -ᵥ c} := image2_singleton @[mono] lemma vsub_subset_vsub : s₁ ⊆ s₂ → t₁ ⊆ t₂ → s₁ -ᵥ t₁ ⊆ s₂ -ᵥ t₂ := image2_subset lemma vsub_subset_vsub_left : t₁ ⊆ t₂ → s -ᵥ t₁ ⊆ s -ᵥ t₂ := image2_subset_left lemma vsub_subset_vsub_right : s₁ ⊆ s₂ → s₁ -ᵥ t ⊆ s₂ -ᵥ t := image2_subset_right lemma vsub_subset_iff : s -ᵥ t ⊆ u ↔ ∀ (x ∈ s) (y ∈ t), x -ᵥ y ∈ u := image2_subset_iff lemma vsub_self_mono (h : s ⊆ t) : s -ᵥ s ⊆ t -ᵥ t := vsub_subset_vsub h h lemma union_vsub : (s₁ ∪ s₂) -ᵥ t = s₁ -ᵥ t ∪ (s₂ -ᵥ t) := image2_union_left lemma vsub_union : s -ᵥ (t₁ ∪ t₂) = s -ᵥ t₁ ∪ (s -ᵥ t₂) := image2_union_right lemma inter_vsub_subset : s₁ ∩ s₂ -ᵥ t ⊆ (s₁ -ᵥ t) ∩ (s₂ -ᵥ t) := image2_inter_subset_left lemma vsub_inter_subset : s -ᵥ t₁ ∩ t₂ ⊆ (s -ᵥ t₁) ∩ (s -ᵥ t₂) := image2_inter_subset_right lemma Union_vsub_left_image : (⋃ a ∈ s, ((-ᵥ) a) '' t) = s -ᵥ t := Union_image_left _ lemma Union_vsub_right_image : (⋃ a ∈ t, (-ᵥ a) '' s) = s -ᵥ t := Union_image_right _ lemma Union_vsub (s : ι → set β) (t : set β) : (⋃ i, s i) -ᵥ t = ⋃ i, s i -ᵥ t := image2_Union_left _ _ _ lemma vsub_Union (s : set β) (t : ι → set β) : s -ᵥ (⋃ i, t i) = ⋃ i, s -ᵥ t i := image2_Union_right _ _ _ lemma Union₂_vsub (s : Π i, κ i → set β) (t : set β) : (⋃ i j, s i j) -ᵥ t = ⋃ i j, s i j -ᵥ t := image2_Union₂_left _ _ _ lemma vsub_Union₂ (s : set β) (t : Π i, κ i → set β) : s -ᵥ (⋃ i j, t i j) = ⋃ i j, s -ᵥ t i j := image2_Union₂_right _ _ _ lemma Inter_vsub_subset (s : ι → set β) (t : set β) : (⋂ i, s i) -ᵥ t ⊆ ⋂ i, s i -ᵥ t := image2_Inter_subset_left _ _ _ lemma vsub_Inter_subset (s : set β) (t : ι → set β) : s -ᵥ (⋂ i, t i) ⊆ ⋂ i, s -ᵥ t i := image2_Inter_subset_right _ _ _ lemma Inter₂_vsub_subset (s : Π i, κ i → set β) (t : set β) : (⋂ i j, s i j) -ᵥ t ⊆ ⋂ i j, s i j -ᵥ t := image2_Inter₂_subset_left _ _ _ lemma vsub_Inter₂_subset (s : set β) (t : Π i, κ i → set β) : s -ᵥ (⋂ i j, t i j) ⊆ ⋂ i j, s -ᵥ t i j := image2_Inter₂_subset_right _ _ _ end vsub open_locale pointwise section smul_with_zero variables [has_zero α] [has_zero β] [smul_with_zero α β] {s : set α} {t : set β} /-! Note that we have neither `smul_with_zero α (set β)` nor `smul_with_zero (set α) (set β)` because `0 * ∅ ≠ 0`. -/ lemma smul_zero_subset (s : set α) : s • (0 : set β) ⊆ 0 := by simp [subset_def, mem_smul] lemma zero_smul_subset (t : set β) : (0 : set α) • t ⊆ 0 := by simp [subset_def, mem_smul] lemma nonempty.smul_zero (hs : s.nonempty) : s • (0 : set β) = 0 := s.smul_zero_subset.antisymm $ by simpa [mem_smul] using hs lemma nonempty.zero_smul (ht : t.nonempty) : (0 : set α) • t = 0 := t.zero_smul_subset.antisymm $ by simpa [mem_smul] using ht /-- A nonempty set is scaled by zero to the singleton set containing 0. -/ lemma zero_smul_set {s : set β} (h : s.nonempty) : (0 : α) • s = (0 : set β) := by simp only [← image_smul, image_eta, zero_smul, h.image_const, singleton_zero] lemma zero_smul_set_subset (s : set β) : (0 : α) • s ⊆ 0 := image_subset_iff.2 $ λ x _, zero_smul α x lemma subsingleton_zero_smul_set (s : set β) : ((0 : α) • s).subsingleton := subsingleton_singleton.anti $ zero_smul_set_subset s lemma zero_mem_smul_set {t : set β} {a : α} (h : (0 : β) ∈ t) : (0 : β) ∈ a • t := ⟨0, h, smul_zero _⟩ variables [no_zero_smul_divisors α β] {a : α} lemma zero_mem_smul_iff : (0 : β) ∈ s • t ↔ (0 : α) ∈ s ∧ t.nonempty ∨ (0 : β) ∈ t ∧ s.nonempty := begin split, { rintro ⟨a, b, ha, hb, h⟩, obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h, { exact or.inl ⟨ha, b, hb⟩ }, { exact or.inr ⟨hb, a, ha⟩ } }, { rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩), { exact ⟨0, b, hs, hb, zero_smul _ _⟩ }, { exact ⟨a, 0, ha, ht, smul_zero _⟩ } } end lemma zero_mem_smul_set_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t := begin refine ⟨_, zero_mem_smul_set⟩, rintro ⟨b, hb, h⟩, rwa (eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha at hb, end end smul_with_zero section left_cancel_semigroup variables [left_cancel_semigroup α] {s t : set α} @[to_additive] lemma pairwise_disjoint_smul_iff : s.pairwise_disjoint (• t) ↔ (s ×ˢ t).inj_on (λ p, p.1 * p.2) := pairwise_disjoint_image_right_iff $ λ _ _, mul_right_injective _ end left_cancel_semigroup section group variables [group α] [mul_action α β] {s t A B : set β} {a : α} {x : β} @[simp, to_additive] lemma smul_mem_smul_set_iff : a • x ∈ a • s ↔ x ∈ s := (mul_action.injective _).mem_set_image @[to_additive] lemma mem_smul_set_iff_inv_smul_mem : x ∈ a • A ↔ a⁻¹ • x ∈ A := show x ∈ mul_action.to_perm a '' A ↔ _, from mem_image_equiv @[to_additive] lemma mem_inv_smul_set_iff : x ∈ a⁻¹ • A ↔ a • x ∈ A := by simp only [← image_smul, mem_image, inv_smul_eq_iff, exists_eq_right] @[to_additive] lemma preimage_smul (a : α) (t : set β) : (λ x, a • x) ⁻¹' t = a⁻¹ • t := ((mul_action.to_perm a).symm.image_eq_preimage _).symm @[to_additive] lemma preimage_smul_inv (a : α) (t : set β) : (λ x, a⁻¹ • x) ⁻¹' t = a • t := preimage_smul (to_units a)⁻¹ t @[simp, to_additive] lemma set_smul_subset_set_smul_iff : a • A ⊆ a • B ↔ A ⊆ B := image_subset_image_iff $ mul_action.injective _ @[to_additive] lemma set_smul_subset_iff : a • A ⊆ B ↔ A ⊆ a⁻¹ • B := (image_subset_iff).trans $ iff_of_eq $ congr_arg _ $ preimage_equiv_eq_image_symm _ $ mul_action.to_perm _ @[to_additive] lemma subset_set_smul_iff : A ⊆ a • B ↔ a⁻¹ • A ⊆ B := iff.symm $ (image_subset_iff).trans $ iff.symm $ iff_of_eq $ congr_arg _ $ image_equiv_eq_preimage_symm _ $ mul_action.to_perm _ @[to_additive] lemma smul_inter_ne_empty_iff {s t : set α} {x : α} : x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ t ∧ b ∈ s) ∧ a * b⁻¹ = x := begin rw ne_empty_iff_nonempty, split, { rintros ⟨a, h, ha⟩, obtain ⟨b, hb, rfl⟩ := mem_smul_set.mp h, exact ⟨x • b, b, ⟨ha, hb⟩, by simp⟩, }, { rintros ⟨a, b, ⟨ha, hb⟩, rfl⟩, exact ⟨a, mem_inter (mem_smul_set.mpr ⟨b, hb, by simp⟩) ha⟩, }, end @[to_additive] lemma smul_inter_ne_empty_iff' {s t : set α} {x : α} : x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ t ∧ b ∈ s) ∧ a / b = x := by simp_rw [smul_inter_ne_empty_iff, div_eq_mul_inv] @[to_additive] lemma op_smul_inter_ne_empty_iff {s t : set α} {x : αᵐᵒᵖ} : x • s ∩ t ≠ ∅ ↔ ∃ a b, (a ∈ s ∧ b ∈ t) ∧ a⁻¹ * b = mul_opposite.unop x := begin rw ne_empty_iff_nonempty, split, { rintros ⟨a, h, ha⟩, obtain ⟨b, hb, rfl⟩ := mem_smul_set.mp h, exact ⟨b, x • b, ⟨hb, ha⟩, by simp⟩, }, { rintros ⟨a, b, ⟨ha, hb⟩, H⟩, have : mul_opposite.op (a⁻¹ * b) = x := congr_arg mul_opposite.op H, exact ⟨b, mem_inter (mem_smul_set.mpr ⟨a, ha, by simp [← this]⟩) hb⟩, }, end @[simp, to_additive] lemma Union_inv_smul : (⋃ (g : α), g⁻¹ • s) = (⋃ (g : α), g • s) := function.surjective.supr_congr _ inv_surjective $ λ g, rfl @[to_additive] lemma Union_smul_eq_set_of_exists {s : set β} : (⋃ (g : α), g • s) = {a | ∃ (g : α), g • a ∈ s} := by simp_rw [← Union_set_of, ← Union_inv_smul, ← preimage_smul, preimage] end group section group_with_zero variables [group_with_zero α] [mul_action α β] {s : set α} {a : α} @[simp] lemma smul_mem_smul_set_iff₀ (ha : a ≠ 0) (A : set β) (x : β) : a • x ∈ a • A ↔ x ∈ A := show units.mk0 a ha • _ ∈ _ ↔ _, from smul_mem_smul_set_iff lemma mem_smul_set_iff_inv_smul_mem₀ (ha : a ≠ 0) (A : set β) (x : β) : x ∈ a • A ↔ a⁻¹ • x ∈ A := show _ ∈ units.mk0 a ha • _ ↔ _, from mem_smul_set_iff_inv_smul_mem lemma mem_inv_smul_set_iff₀ (ha : a ≠ 0) (A : set β) (x : β) : x ∈ a⁻¹ • A ↔ a • x ∈ A := show _ ∈ (units.mk0 a ha)⁻¹ • _ ↔ _, from mem_inv_smul_set_iff lemma preimage_smul₀ (ha : a ≠ 0) (t : set β) : (λ x, a • x) ⁻¹' t = a⁻¹ • t := preimage_smul (units.mk0 a ha) t lemma preimage_smul_inv₀ (ha : a ≠ 0) (t : set β) : (λ x, a⁻¹ • x) ⁻¹' t = a • t := preimage_smul ((units.mk0 a ha)⁻¹) t @[simp] lemma set_smul_subset_set_smul_iff₀ (ha : a ≠ 0) {A B : set β} : a • A ⊆ a • B ↔ A ⊆ B := show units.mk0 a ha • _ ⊆ _ ↔ _, from set_smul_subset_set_smul_iff lemma set_smul_subset_iff₀ (ha : a ≠ 0) {A B : set β} : a • A ⊆ B ↔ A ⊆ a⁻¹ • B := show units.mk0 a ha • _ ⊆ _ ↔ _, from set_smul_subset_iff lemma subset_set_smul_iff₀ (ha : a ≠ 0) {A B : set β} : A ⊆ a • B ↔ a⁻¹ • A ⊆ B := show _ ⊆ units.mk0 a ha • _ ↔ _, from subset_set_smul_iff lemma smul_univ₀ (hs : ¬ s ⊆ 0) : s • (univ : set β) = univ := let ⟨a, ha, ha₀⟩ := not_subset.1 hs in eq_univ_of_forall $ λ b, ⟨a, a⁻¹ • b, ha, trivial, smul_inv_smul₀ ha₀ _⟩ lemma smul_set_univ₀ (ha : a ≠ 0) : a • (univ : set β) = univ := eq_univ_of_forall $ λ b, ⟨a⁻¹ • b, trivial, smul_inv_smul₀ ha _⟩ end group_with_zero section monoid variables [monoid α] [add_group β] [distrib_mul_action α β] (a : α) (s : set α) (t : set β) @[simp] lemma smul_set_neg : a • -t = -(a • t) := by simp_rw [←image_smul, ←image_neg, image_image, smul_neg] @[simp] protected lemma smul_neg : s • -t = -(s • t) := by { simp_rw ←image_neg, exact image_image2_right_comm smul_neg } end monoid section ring variables [ring α] [add_comm_group β] [module α β] (a : α) (s : set α) (t : set β) @[simp] lemma neg_smul_set : -a • t = -(a • t) := by simp_rw [←image_smul, ←image_neg, image_image, neg_smul] @[simp] protected lemma neg_smul : -s • t = -(s • t) := by { simp_rw ←image_neg, exact image2_image_left_comm neg_smul } end ring end set
fd7993e69478a9f16c9eb450ca35a9a81a25a078
5ee26964f602030578ef0159d46145dd2e357ba5
/src/valuation/basic.lean
7695d89594da5b247b72d9715dd660ec736716ff
[ "Apache-2.0" ]
permissive
fpvandoorn/lean-perfectoid-spaces
569b4006fdfe491ca8b58dd817bb56138ada761f
06cec51438b168837fc6e9268945735037fd1db6
refs/heads/master
1,590,154,571,918
1,557,685,392,000
1,557,685,392,000
186,363,547
0
0
Apache-2.0
1,557,730,933,000
1,557,730,933,000
null
UTF-8
Lean
false
false
29,288
lean
import algebra.group_power import ring_theory.ideal_operations import ring_theory.localization import ring_theory.subring import for_mathlib.rings import for_mathlib.linear_ordered_comm_group import for_mathlib.equiv /- valuations.basic The basic theory of valuations (non-archimedean norms) on a commutative ring, following Wedhorn's unpublished notes on adic spaces. The definition of a valuation is Definition 1.22 of Wedhorn. `valuation R Γ` is the type of valuations R → Γ ∪ {0}, with a coercion to the underlying function. If v is a valuation from R to Γ ∪ {0} then the induced group homomorphism units(R) → Γ is called `unit_map v`. The equivalence "relation" `is_equiv v₁ v₂ : Prop` is not strictly speaking a relation, because v₁ : valuation R Γ₁ and v₂ : valuation R Γ₂ might not have the same type. This corresponds in ZFC to the set-theoretic difficulty that the class of all valuations (as Γ varies) on a ring R is not a set. The "relation" is however reflexive, symmetric and transitive in the obvious sense. The trivial valuation associated to a prime ideal P is `trivial P : valuation R Γ`. The support of a valuation v : valuation R Γ is `supp v`. The induced valuation on R / J = `ideal.quotient J` if `h : J ⊆ supp v` is `on_quot v h`. If v is a valuation on an integral domain R and `hv : supp v = 0`, then `on_frac v hv` is the extension of v to fraction_ring R, the field of fractions of R. `valuation_field v`, `valuation_ring v`, `max_ideal v` and `residue_field v` are the valuation field, valuation ring, maximal ideal and residue field of v. See Definition 1.26 of Wedhorn. -/ local attribute [instance] classical.prop_decidable noncomputable theory -- Some counter-Kenny trick, no need to read def classical.decidable_linear_order {α : Type*} [linear_order α] : decidable_linear_order α := { decidable_le := by apply_instance, decidable_eq := by apply_instance, decidable_lt := by apply_instance, ..‹linear_order α› } local attribute [instance, priority 0] classical.decidable_linear_order open function with_zero ideal localization universes u u₀ u₁ u₂ u₃ -- v is used for valuations variables {Γ : Type u} [linear_ordered_comm_group Γ] variables {Γ₁ : Type u₁} [linear_ordered_comm_group Γ₁] variables {Γ₂ : Type u₂} [linear_ordered_comm_group Γ₂] variables {Γ₃ : Type u₃} [linear_ordered_comm_group Γ₃] variables {R : Type u₀} -- This will be a ring, assumed commutative in some sections -- Valuations on a ring with values in {0} ∪ Γ class valuation.is_valuation [ring R] (v : R → with_zero Γ) : Prop := (map_zero : v 0 = 0) (map_one : v 1 = 1) (map_mul : ∀ x y, v (x * y) = v x * v y) (map_add : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y) /-- Γ-valued valuations on R -/ def valuation (R : Type u₀) [ring R] (Γ : Type u) [linear_ordered_comm_group Γ] := { v : R → with_zero Γ // valuation.is_valuation v } namespace valuation section variables [ring R] -- A valuation is coerced to the underlying function R → {0} ∪ Γ instance (R : Type u₀) [ring R] (Γ : Type u) [linear_ordered_comm_group Γ] : has_coe_to_fun (valuation R Γ) := { F := λ _, R → with_zero Γ, coe := subtype.val} @[extensionality] lemma ext {Γ : Type u} [linear_ordered_comm_group Γ] (v₁ v₂ : valuation R Γ) : v₁ = v₂ ↔ ∀ r, v₁ r = v₂ r := subtype.ext.trans ⟨λ h r, congr h rfl, funext⟩ variables (v : valuation R Γ) {x y z : R} instance : is_valuation v := v.property @[simp] lemma map_zero : v 0 = 0 := v.property.map_zero @[simp] lemma map_one : v 1 = 1 := v.property.map_one @[simp] lemma map_mul : ∀ x y, v (x * y) = v x * v y := v.property.map_mul @[simp] lemma map_add : ∀ x y, v (x + y) ≤ v x ∨ v (x + y) ≤ v y := v.property.map_add lemma map_one_ne_zero : v 1 ≠ 0 := by rw map_one; simp lemma map_add_le_max (x y) : v (x + y) ≤ max (v x) (v y) := begin cases map_add v x y with h, apply le_max_left_of_le h, apply le_max_right_of_le h, end -- not an instance, because more than one v on a given R /-- a valuation gives a preorder on the underlying ring-/ def to_preorder : preorder R := preorder.lift v (by apply_instance) -- If x ∈ R is a unit then v x is non-zero theorem map_unit (h : x * y = 1) : (v x).is_some := begin have h1 := v.map_mul x y, rw [h, map_one v] at h1, cases (v x), { exfalso, exact option.no_confusion h1 }, { constructor } end -- As far as Patrick can see, this is the useful version of valuation.map_unit lemma unit_is_some (x : units R) : ∃ γ : Γ, v x = γ := begin have h1 := v.map_mul x.val x.inv, rw [x.val_inv, valuation.map_one] at h1, exact with_zero.eq_some_of_mul_eq_some_left h1.symm end lemma unit_is_not_none (x : units R) : v x ≠ 0 := begin cases unit_is_some v x with γ Hγ, rw Hγ, apply option.no_confusion, end lemma unit_is_some' {Γ : Type u} [_inst_1 : linear_ordered_comm_group Γ] {R : Type u₀} [comm_ring R] (v : valuation R Γ) {x : R} (h : ∃ y : R, x * y = 1) : ∃ γ : Γ, v x = γ := begin cases h with y hy, let x' : units R := units.mk x y hy (mul_comm x y ▸ hy), exact unit_is_some v x' end lemma map_inv (x : units R) : v x⁻¹.val = (v x)⁻¹ := begin have := congr_arg v x.val_inv, rw [v.map_one, map_mul] at this, exact with_zero.eq_inv_of_mul_eq_one_right this, end lemma map_unit' (x : units R) : (v x).is_some := map_unit v x.val_inv definition unit_map : units R → Γ := λ u, match v u with | some x := x | none := 1 end @[simp] theorem unit_map_eq (u : units R) : some (unit_map v u) = v u := begin unfold unit_map, have h1 := v.map_mul u.val u.inv, change _ = v u * _ at h1, rw [u.val_inv, v.map_one] at h1, cases h : (v u), rw h at h1, exfalso, exact option.no_confusion h1, refl, end lemma unit_map.ext (x z : units R) (H : v (z.val) = v (x.val)) : valuation.unit_map v z = valuation.unit_map v x := by rwa [←option.some_inj, valuation.unit_map_eq, valuation.unit_map_eq] @[simp] lemma coe_unit_map (x : units R) : ↑(v.unit_map x) = v x := by rw ← valuation.unit_map_eq ; refl instance is_group_hom.unit_map : is_group_hom (unit_map v) := ⟨λ a b, option.some.inj $ show _ = (some _ * some _ : with_zero Γ), by simp⟩ @[simp] theorem map_neg_one : v (-1) = 1 := begin change v (-1 : units R) = 1, rw ← unit_map_eq, congr' 1, apply linear_ordered_comm_group.eq_one_of_pow_eq_one (_ : _ ^ 2 = _), rw pow_two, apply option.some.inj, change (some _ * some _ : with_zero Γ) = _, rw [unit_map_eq, ← v.map_mul, units.coe_neg, units.coe_one, neg_one_mul, neg_neg, v.map_one], refl end @[simp] lemma map_neg (x : R) : v (-x) = v x := calc v (-x) = v (-1 * x) : by simp ... = v (-1) * v x : map_mul _ _ _ ... = v x : by simp lemma map_sub_swap (x y : R) : v (x - y) = v (y - x) := calc v (x - y) = v (-(y - x)) : by rw show x - y = -(y-x), by abel ... = _ : map_neg _ _ lemma map_sub_le_max (x y : R) : v (x - y) ≤ max (v x) (v y) := calc v (x-y) = v (x + -y) : by simp ... ≤ max (v x) (v $ -y) : map_add_le_max _ _ _ ... = max (v x) (v y) : by rw map_neg lemma map_add_of_distinct_val (h : v x ≠ v y) : v (x + y) = max (v x) (v y) := begin suffices : ¬v (x + y) < max (v x) (v y), from or_iff_not_imp_right.1 (le_iff_eq_or_lt.1 (map_add_le_max v x y)) this, intro h', wlog vyx : v y < v x using x y, { apply lt_or_gt_of_ne h.symm }, { rw max_eq_left_of_lt vyx at h', apply lt_irrefl (v x), calc v x = v ((x+y) - y) : by simp ... ≤ max (v $ x + y) (v y) : map_sub_le_max _ _ _ ... < v x : max_lt h' vyx }, { apply this h.symm, rwa [add_comm, max_comm] at h' } end lemma map_eq_of_sub_lt (h : v (y - x) < v x) : v y = v x := begin have := valuation.map_add_of_distinct_val v (ne_of_gt h).symm, rw max_eq_right (le_of_lt h) at this, simpa using this end @[simp] theorem eq_zero_iff_le_zero {r : R} : v r = 0 ↔ v r ≤ v 0 := v.map_zero.symm ▸ with_zero.le_zero_iff_eq_zero.symm section variables {v₁ : R → with_zero Γ₁} {v₂ : R → with_zero Γ₂} variables {ψ : Γ₁ → Γ₂} variables (H12 : ∀ r, with_zero.map ψ (v₁ r) = v₂ r) variables (Hle : ∀ g h : Γ₁, g ≤ h ↔ ψ g ≤ ψ h) -- This include statement means that we have an underlying assumption -- that ψ : Γ₁ → Γ₂ is order-preserving, and that v₁ and v₂ are functions with ψ ∘ v₁ = v₂. include H12 Hle theorem le_of_le (r s : R) : v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s := begin rw ←H12 r, rw ←H12 s, cases v₁ r; cases v₁ s, swap 3,{ simp [Hle, @with_zero.coe_ne_zero _ (ψ val)], }, all_goals { simp [Hle] }, end -- Restriction of a Γ₂-valued valuation to a subgroup Γ₁ is still a valuation theorem valuation_of_valuation [is_group_hom ψ] (Hiψ : function.injective ψ) (H : is_valuation v₂) : is_valuation v₁ := { map_zero := with_zero.injective_map Hiψ $ by erw [H12, H.map_zero, ← with_zero.map_zero], map_one := with_zero.injective_map Hiψ $ by erw [H12, H.map_one, with_zero.map_some, is_group_hom.map_one ψ]; refl, map_mul := λ r s, with_zero.injective_map Hiψ $ by rw [H12, H.map_mul, ←H12 r, ←H12 s]; exact (with_zero.map_mul _ _ _).symm, map_add := λ r s, begin apply (is_valuation.map_add v₂ r s).imp _ _; erw [with_zero.map_le Hle, ←H12, ←H12]; exact id end } end -- section /-- f : S → R induces map valuation R Γ → valuation S Γ -/ def comap {S : Type u₁} [ring S] (f : S → R) [is_ring_hom f] : valuation S Γ := { val := v ∘ f, property := by constructor; simp [is_ring_hom.map_zero f, is_ring_hom.map_one f, is_ring_hom.map_mul f, is_ring_hom.map_add f] } lemma comap_id : v.comap (id : R → R) = v := subtype.eq rfl lemma comap_comp {S₁ : Type u₁} [ring S₁] {S₂ : Type u₂} [ring S₂] (f : S₁ → S₂) [is_ring_hom f] (g : S₂ → R) [is_ring_hom g] : v.comap (g ∘ f) = (v.comap g).comap f := subtype.ext.mpr $ rfl def map {Γ₁ : Type u₁} [linear_ordered_comm_group Γ₁] (f : Γ → Γ₁) [is_group_hom f] (hf : monotone f) : valuation R Γ₁ := { val := with_zero.map f ∘ v, property := { map_zero := by simp [with_zero.map_zero], map_one := begin show with_zero.map f (_) = 1, erw [v.map_one, with_zero.map_some, is_group_hom.map_one f], refl end, map_mul := λ x y, begin delta function.comp, erw [v.map_mul, with_zero.map_mul f], refl end, map_add := λ x y, begin delta function.comp, apply (v.map_add x y).imp _ _; exact λ h, with_zero.map_monotone hf h, end } } -- Definition of equivalence relation on valuations def is_equiv (v₁ : valuation R Γ₁) (v₂ : valuation R Γ₂) : Prop := ∀ r s, v₁ r ≤ v₁ s ↔ v₂ r ≤ v₂ s end namespace is_equiv variables [ring R] variables {v : valuation R Γ} variables {v₁ : valuation R Γ₁} {v₂ : valuation R Γ₂} {v₃ : valuation R Γ₃} @[refl] lemma refl : v.is_equiv v := λ _ _, iff.refl _ @[symm] lemma symm (h : v₁.is_equiv v₂) : v₂.is_equiv v₁ := λ _ _, iff.symm (h _ _) @[trans] lemma trans (h₁₂ : v₁.is_equiv v₂) (h₂₃ : v₂.is_equiv v₃) : v₁.is_equiv v₃ := λ _ _, iff.trans (h₁₂ _ _) (h₂₃ _ _) lemma of_eq {v' : valuation R Γ} (h : v = v') : v.is_equiv v' := by subst h; refl lemma map {v' : valuation R Γ} (f : Γ → Γ₁) [is_group_hom f] (inf : injective f) (hf : monotone f) (h : v.is_equiv v') : (map v f hf).is_equiv (map v' f hf) := λ r s, begin show (with_zero.map f) (v r) ≤ (with_zero.map f) (v s) ↔ (with_zero.map f) (v' r) ≤ (with_zero.map f) (v' s), rw ←linear_order_le_iff_of_monotone_injective (with_zero.injective_map inf) (with_zero.map_monotone hf), rw ←linear_order_le_iff_of_monotone_injective (with_zero.injective_map inf) (with_zero.map_monotone hf), apply h, end lemma comap {S : Type u₃} [ring S] (f : S → R) [is_ring_hom f] (h : v₁.is_equiv v₂) : (v₁.comap f).is_equiv (v₂.comap f) := λ r s, h (f r) (f s) lemma val_eq (h : v₁.is_equiv v₂) {r s : R} : v₁ r = v₁ s ↔ v₂ r = v₂ s := ⟨λ H, le_antisymm ((h _ _).1 (le_of_eq H)) ((h _ _).1 (le_of_eq H.symm)), λ H, le_antisymm ((h.symm _ _).1 (le_of_eq H)) ((h.symm _ _).1 (le_of_eq H.symm)) ⟩ lemma ne_zero (h : v₁.is_equiv v₂) {r : R} : v₁ r ≠ 0 ↔ v₂ r ≠ 0 := begin have : v₁ r ≠ v₁ 0 ↔ v₂ r ≠ v₂ 0 := not_iff_not_of_iff h.val_eq, rwa [v₁.map_zero, v₂.map_zero] at this, end end is_equiv lemma is_equiv_of_map_of_strict_mono [ring R] {v : valuation R Γ} (f : Γ → Γ₁) [is_group_hom f] (H : strict_mono f) : is_equiv (v.map f (H.monotone)) v := λ x y, ⟨(with_zero.map_strict_mono H).le_iff_le.mp, λ h, with_zero.map_monotone H.monotone h⟩ section trivial variable [comm_ring R] variables (S : ideal R) [prime : ideal.is_prime S] include prime -- trivial Γ-valued valuation associated to a prime ideal S def trivial : valuation R Γ := { val := λ x, if x ∈ S then 0 else 1, property := { map_zero := if_pos S.zero_mem, map_one := if_neg (assume h, prime.1 (S.eq_top_iff_one.2 h)), map_mul := λ x y, begin split_ifs with hxy hx hy hy hx hy hy, { simp }, { simp }, { simp }, { exfalso, cases ideal.is_prime.mem_or_mem prime hxy with h' h', { exact hx h' }, { exact hy h' } }, { exfalso, exact hxy (S.mul_mem_right hx) }, { exfalso, exact hxy (S.mul_mem_right hx) }, { exfalso, exact hxy (S.mul_mem_left hy) }, { simp }, end, map_add := λ x y, begin split_ifs with hxy hx hy _ hx hy; try {simp}; try {left; exact le_refl _}; try {right}; try {exact le_refl _}, { have hxy' : x + y ∈ S := S.add_mem hx hy, exfalso, exact hxy hxy' } end } } @[simp] lemma trivial_val : (trivial S).val = (λ x, if x ∈ S then 0 else 1 : R → (with_zero Γ)) := rfl end trivial section supp variables [comm_ring R] variables (v : valuation R Γ) -- support of a valuation v : R → {0} ∪ Γ def supp : ideal R := { carrier := {x | v x = 0}, zero := map_zero v, add := λ x y hx hy, or.cases_on (map_add v x y) (λ hxy, le_antisymm (hx ▸ hxy) zero_le) (λ hxy, le_antisymm (hy ▸ hxy) zero_le), smul := λ c x hx, calc v (c * x) = v c * v x : map_mul v c x ... = v c * 0 : congr_arg _ hx ... = 0 : mul_zero _ } @[simp] lemma mem_supp_iff (x : R) : x ∈ supp v ↔ v x = 0 := iff.rfl @[simp] lemma mem_supp_iff' (x : R) : x ∈ (supp v : set R) ↔ v x = 0 := iff.rfl -- support is a prime ideal. instance : ideal.is_prime (supp v) := ⟨λ h, have h1 : (1:R) ∈ supp v, by rw h; trivial, have h2 : v 1 = 0 := h1, by rw [map_one v] at h2; exact option.no_confusion h2, λ x y hxy, begin dsimp [supp] at hxy ⊢, change v (x * y) = 0 at hxy, rw [map_mul v x y] at hxy, exact eq_zero_or_eq_zero_of_mul_eq_zero _ _ hxy end⟩ lemma v_nonzero_of_not_in_supp (a : R) (h : a ∉ supp v) : v a ≠ 0 := λ h2, h h2 -- group version of v def v_to_Γ (a : R) : Γ := option.rec_on (v a) 1 id variable {v} lemma v_to_Γ_is_v {a : R} (h : a ∉ supp v) : v a = ↑(v_to_Γ v a) := begin destruct (v a), { intro h2, exfalso, apply v_nonzero_of_not_in_supp v a h, exact h2 }, { intros g hg, unfold v_to_Γ, rw hg, refl, } end -- v(a)=v(a+s) if s in support. First an auxiliary lemma lemma val_add_supp_aux (a s : R) (h : v s = 0) : v (a + s) ≤ v a := begin cases map_add v a s with H H, exact H, change v s = 0 at h, rw h at H, exact le_trans H with_zero.zero_le end lemma val_add_supp (a s : R) (h : s ∈ supp v) : v (a + s) = v a := begin apply le_antisymm (val_add_supp_aux a s h), convert val_add_supp_aux (a + s) (-s) _, simp, rwa ←ideal.neg_mem_iff at h, end variable (v) -- Function corresponding to extension of a valuation on R to a valuation on R / J if J is in the support -/ definition on_quot_val {J : ideal R} (hJ : J ≤ supp v) : J.quotient → with_zero Γ := λ q, quotient.lift_on' q v $ λ a b h, begin have hsupp : a - b ∈ supp v := hJ h, convert val_add_supp b (a - b) hsupp, simp, end -- Proof that function is a valuation. variable {v} instance on_quot_val.is_valuation {J : ideal R} (hJ : J ≤ supp v) : is_valuation (on_quot_val v hJ) := { map_zero := v.map_zero, map_one := v.map_one, map_mul := λ xbar ybar, quotient.ind₂' v.map_mul xbar ybar, map_add := λ xbar ybar, quotient.ind₂' v.map_add xbar ybar } -- Now the valuation variable (v) /-- Extension of valuation v on R to valuation on R/J if J ⊆ supp v -/ definition on_quot {J : ideal R} (hJ : J ≤ supp v) : valuation J.quotient Γ := { val := v.on_quot_val hJ, property := on_quot_val.is_valuation hJ } @[simp] lemma on_quot_comap_eq {J : ideal R} (hJ : J ≤ supp v) : (v.on_quot hJ).comap (ideal.quotient.mk J) = v := subtype.ext.mpr $ funext $ λ r, @quotient.lift_on_beta _ _ (J.quotient_rel) v (λ a b h, have hsupp : a - b ∈ supp v := hJ h, by convert val_add_supp b (a - b) hsupp; simp) _ end supp section supp_comm variable [comm_ring R] variables (v : valuation R Γ) lemma comap_supp {S : Type u₁} [comm_ring S] (f : S → R) [is_ring_hom f] : supp (v.comap f) = ideal.comap f v.supp := ideal.ext $ λ x, begin rw [mem_supp_iff, ideal.mem_comap, mem_supp_iff], refl, end @[simp] lemma comap_on_quot_eq (J : ideal R) (v : valuation J.quotient Γ) : (v.comap (ideal.quotient.mk J)).on_quot (by rw [comap_supp, ← ideal.map_le_iff_le_comap]; simp) = v := subtype.ext.mpr $ funext $ begin rintro ⟨x⟩, dsimp [on_quot, on_quot_val, comap, function.comp], show quotient.lift_on _ _ _ = _, erw quotient.lift_on_beta, refl, end /-- quotient valuation on R/J has support supp(v)/J if J ⊆ supp v-/ lemma supp_quot_supp {J : ideal R} (hJ : J ≤ supp v) : supp (v.on_quot hJ) = (supp v).map (ideal.quotient.mk J) := begin apply le_antisymm, { rintro ⟨x⟩ hx, apply ideal.subset_span, exact ⟨x, hx, rfl⟩ }, { rw ideal.map_le_iff_le_comap, intros x hx, exact hx } end lemma quot_supp_zero : supp (v.on_quot (le_refl _)) = 0 := by rw supp_quot_supp; exact ideal.map_quotient_self _ lemma quot_preorder_comap {J : ideal R} (hJ : J ≤ supp v) : preorder.lift (ideal.quotient.mk J) (v.on_quot hJ).to_preorder = v.to_preorder := preorder.ext $ λ x y, iff.rfl end supp_comm section fraction_ring variables [integral_domain R] -- integral domain is abreviated ID in the following variables (v : valuation R Γ) -- function corresponding to extension of valuation on ID with support 0 -- to valuation on field of fractions definition on_frac_val (hv : supp v = 0) : fraction_ring R → with_zero Γ := quotient.lift (λ rs, v rs.1 / v rs.2.1 : R × non_zero_divisors R → with_zero Γ) begin rintro ⟨r, s, hs⟩ ⟨t, u, hu⟩ ⟨w, hw, h⟩, change v r / v s = v t / v u, change (s * t - (u * r)) * w = 0 at h, rw fraction_ring.mem_non_zero_divisors_iff_ne_zero at hs hu hw, have hvs : v s ≠ 0 := λ H, hs ((submodule.mem_bot R).mp (lattice.eq_bot_iff.1 hv H)), have hvu : v u ≠ 0 := λ H, hu ((submodule.mem_bot R).mp (lattice.eq_bot_iff.1 hv H)), have hvw : v w ≠ 0 := λ H, hw ((submodule.mem_bot R).mp (lattice.eq_bot_iff.1 hv H)), rw [with_zero.div_eq_div hvs hvu], rw [sub_mul, sub_eq_zero] at h, replace h := congr_arg v h, iterate 4 { rw map_mul at h }, cases v w with w hvw, { exact false.elim (hvw rfl), }, rw mul_comm, cases v s * v t; cases v u * v r, { refl }, { simpa using h }, { simpa using h }, congr' 1, replace h := option.some.inj h, symmetry, exact mul_right_cancel h end @[simp] lemma on_frac_val_mk (hv : supp v = 0) (rs : R × non_zero_divisors R) : v.on_frac_val hv (⟦rs⟧) = v rs.1 / v rs.2.1 := rfl @[simp] lemma on_frac_val_mk' (hv : supp v = 0) (rs : R × non_zero_divisors R) : v.on_frac_val hv (quotient.mk' rs) = v rs.1 / v rs.2.1 := rfl def on_frac_val.is_valuation (hv : supp v = 0) : is_valuation (v.on_frac_val hv) := { map_zero := show v.on_frac_val hv (quotient.mk' ⟨0,1⟩) = 0, by simp, map_one := show v.on_frac_val hv (quotient.mk' ⟨_,1⟩) = 1, by simp, map_mul := λ xbar ybar, quotient.ind₂' (λ x y, begin change v(x.1 * y.1) * (v((x.2 * y.2).val))⁻¹ = v(x.1) * (v(x.2.val))⁻¹ * (v(y.1) * (v(y.2.val))⁻¹), erw [v.map_mul, v.map_mul, with_zero.mul_inv_rev], simp [mul_assoc, mul_comm, mul_left_comm] end) xbar ybar, map_add := λ xbar ybar, quotient.ind₂' (λ x y, begin let x_plus_y : fraction_ring R := ⟦⟨x.2 * y.1 + y.2 * x.1, _, is_submonoid.mul_mem x.2.2 y.2.2⟩⟧, change on_frac_val v hv x_plus_y ≤ _ * _ ∨ on_frac_val v hv x_plus_y ≤ _ * _, dsimp, cases (is_valuation.map_add v (x.2 * y.1) (y.2 * x.1)) with h h; [right, left]; refine le_trans (linear_ordered_comm_monoid.mul_le_mul_right h _) _; erw [v.map_mul, v.map_mul, with_zero.mul_inv_rev]; refine le_trans (le_of_eq _) (le_trans (linear_ordered_comm_monoid.mul_le_mul_right (mul_inv_self $ v (_ : R × (non_zero_divisors R)).snd.val) _) $ le_of_eq $ one_mul _), { exact x }, { repeat {rw [mul_assoc]}, congr' 1, rw [← mul_assoc, mul_comm], }, { exact y }, { repeat {rw [mul_assoc]}, congr' 1, rw mul_left_comm, }, end) xbar ybar } /-- Extension of valuation on R with supp 0 to valuation on field of fractions -/ def on_frac (hv : supp v = 0) : valuation (fraction_ring R) Γ := { val := on_frac_val v hv, property := on_frac_val.is_valuation v hv } lemma on_frac_val' (hv : supp v = 0) (q : fraction_ring R) : v.on_frac hv q = v.on_frac_val hv q := rfl @[simp] lemma on_frac_comap_eq (hv : supp v = 0) : (v.on_frac hv).comap of = v := subtype.ext.mpr $ funext $ λ r, show v r / v 1 = v r, by simp lemma on_frac_comap_eq' (hv : supp v = 0) (r : R) : ((v.on_frac hv).comap of : valuation R Γ) r = v r := by rw on_frac_comap_eq @[simp] lemma comap_on_frac_eq (v : valuation (fraction_ring R) Γ) : (v.comap of).on_frac (by {rw [comap_supp, ideal.zero_eq_bot, (supp v).eq_bot_of_prime], apply ideal.comap_bot_of_inj, apply fraction_ring.of.injective }) = v := subtype.ext.mpr $ funext $ begin rintro ⟨x⟩, dsimp [on_frac, on_frac_val, comap, function.comp], erw quotient.lift_beta, change v (x.1) / v (x.2.val) = _, rw with_zero.div_eq_iff_mul_eq, { erw ← v.map_mul, apply congr_arg, change ⟦_⟧ = ⟦_⟧, apply quotient.sound, use 1, use is_submonoid.one_mem _, show (↑(x.snd) * 1 * x.fst + -(1 * (x.fst * (x.snd).val))) * 1 = 0, rw [mul_one, mul_one, one_mul, mul_comm], exact sub_self _}, intro h, rw [← mem_supp_iff, (supp v).eq_bot_of_prime, submodule.mem_bot] at h, replace h := fraction_ring.eq_zero_of _ h, refine fraction_ring.mem_non_zero_divisors_iff_ne_zero.mp _ h, exact x.2.2 end lemma frac_preorder_comap (hv : supp v = 0) : preorder.lift (localization.of) (v.on_frac hv).to_preorder = v.to_preorder := preorder.ext $ λ x y, begin show (v.on_frac hv) x ≤ (v.on_frac hv) y ↔ v x ≤ v y, rw [←on_frac_comap_eq' v hv, ←on_frac_comap_eq' v hv], exact iff.rfl end end fraction_ring section valuation_field variables [comm_ring R] variables (v : valuation R Γ) definition valuation_ID := (supp v).quotient instance valuation.integral_domain' : integral_domain (valuation_ID v) := by delta valuation_ID; apply_instance instance : preorder (valuation_ID v) := (v.on_quot (le_refl _)).to_preorder def valuation_ID_mk : R → valuation_ID v := ideal.quotient.mk (supp v) -- need that it's a ring hom, need that its kernel is whatever instance : is_ring_hom (v.valuation_ID_mk) := by unfold valuation_ID_mk; apply_instance lemma valuation_ID_mk_ker (r : R) : v.valuation_ID_mk r = 0 ↔ r ∈ supp v := ideal.quotient.eq_zero_iff_mem definition valuation_field := localization.fraction_ring (valuation_ID v) instance : discrete_field (valuation_field v) := by delta valuation_field; apply_instance def valuation_field_mk (r : R) : valuation_field v := localization.of (v.valuation_ID_mk r) instance to_valuation_field.is_ring_hom : is_ring_hom (valuation_field_mk v) := by delta valuation_field_mk; apply_instance lemma valuation_field_mk_ker (r : R) : v.valuation_field_mk r = 0 ↔ r ∈ supp v := ⟨λ h, (v.valuation_ID_mk_ker r).1 $ localization.fraction_ring.eq_zero_of _ h, λ h, show localization.of _ = 0, by rw (v.valuation_ID_mk_ker r).2 h; apply is_ring_hom.map_zero⟩ lemma valuation_field_mk_ne_zero (r : R) (hr : v r ≠ 0) : valuation_field_mk v r ≠ 0 := λ h, hr ((valuation_field_mk_ker v r).1 h) instance valuation.valfield_preorder : preorder (valuation_field v) := ((v.on_quot (le_refl _)).on_frac $ quot_supp_zero v).to_preorder def units_valfield_mk (r : R) (h : r ∉ supp v) : units (valuation_field v) := ⟨v.valuation_field_mk r, (v.valuation_field_mk r)⁻¹, mul_inv_cancel (λ h2, h $ ideal.quotient.eq_zero_iff_mem.1 $ localization.fraction_ring.eq_zero_of _ h2), inv_mul_cancel (λ h2, h $ ideal.quotient.eq_zero_iff_mem.1 $ localization.fraction_ring.eq_zero_of _ h2)⟩ instance valuation.units_valfield_preorder : preorder (units (valuation_field v)) := preorder.lift (λ u, u.val) (by apply_instance) -- on_frac_quot_comap_eq needs more class.instance_max_depth to compile if -- this instance is not explicitly given as a hint instance : is_submonoid (localization.non_zero_divisors (ideal.quotient (supp v))) := by apply_instance @[simp] lemma on_frac_quot_comap_eq : ((v.on_quot (le_refl _)).on_frac $ quot_supp_zero v).comap (localization.of ∘ (ideal.quotient.mk _)) = v := by rw [comap_comp, on_frac_comap_eq, on_quot_comap_eq] definition on_valuation_field : valuation (valuation_field v) Γ := on_frac (v.on_quot (set.subset.refl _)) begin rw [supp_quot_supp], rw zero_eq_bot, apply ideal.map_quotient_self, end definition valuation_ring := {x | v.on_valuation_field x ≤ 1} instance : is_subring (valuation_ring v) := { zero_mem := show v.on_valuation_field 0 ≤ 1, by simp, add_mem := λ x y hx hy, by cases (v.on_valuation_field.map_add x y) with h h; exact le_trans h (by assumption), neg_mem := by simp [valuation_ring], one_mem := by simp [valuation_ring, le_refl], mul_mem := λ x y (hx : _ ≤ _) (hy : _ ≤ _), show v.on_valuation_field _ ≤ 1, by convert le_trans (linear_ordered_comm_monoid.mul_le_mul_left hy _) _; simp [hx] } definition max_ideal : ideal (valuation_ring v) := { carrier := { r | v.on_valuation_field r < 1 }, zero := show v.on_valuation_field 0 < 1, by apply lt_of_le_of_ne; simp, add := λ x y (hx : _ < 1) (hy : _ < 1), show v.on_valuation_field _ < 1, by cases (v.on_valuation_field.map_add x y) with h h; exact lt_of_le_of_lt h (by assumption), smul := λ c x (hx : _ < 1), show v.on_valuation_field _ < 1, begin refine lt_of_le_of_lt _ _, swap, convert (linear_ordered_comm_monoid.mul_le_mul_right _ _), exact map_mul _ _ _, swap, convert c.property, simpa using hx end } set_option class.instance_max_depth 40 instance max_ideal_is_maximal : (max_ideal v).is_maximal := begin rw ideal.is_maximal_iff, split, { exact λ (H : _ < _), ne_of_lt H (map_one _) }, { rintros J ⟨x,hx⟩ hJ hxni hxinJ, have vx : v.on_valuation_field x = 1 := begin rw eq_iff_le_not_lt, split; assumption end, have xinv_mul_x : (x : valuation_field v)⁻¹ * x = 1 := begin apply inv_mul_cancel, intro hxeq0, simpa [hxeq0] using vx end, have hxinv : v.on_valuation_field x⁻¹ ≤ 1 := begin refine le_of_eq _, symmetry, simpa [xinv_mul_x, vx] using v.on_valuation_field.map_mul x⁻¹ x end, convert J.smul_mem ⟨x⁻¹, hxinv⟩ hxinJ, symmetry, apply subtype.val_injective, exact xinv_mul_x } end set_option class.instance_max_depth 32 definition residue_field := (max_ideal v).quotient instance residue_field.discrete_field : discrete_field (residue_field v) := ideal.quotient.field _ end valuation_field end valuation
fa510e1b00c02dd3d22e54655b706f47fbca7074
fbf512ee44de430e3d3c5869751ad95325c938d7
/reify.lean
893bfcba69259fb2beadf34db787c36b1ee9b2ef
[]
no_license
skbaek/clausify
4858c9005fb86a5e410bfcaa77524f82d955f655
d09b071bdcce7577c3fffacd0893b776285b1590
refs/heads/master
1,588,360,590,818
1,553,553,880,000
1,553,553,880,000
177,644,542
0
0
null
null
null
null
UTF-8
Lean
false
false
2,154
lean
import .form .abst variable {α : Type} open tactic expr meta def get_domain_core : expr → tactic expr | `(¬ %%p) := get_domain_core p | `(%%p ∨ %%q) := get_domain_core p <|> get_domain_core q | `(%%p ∧ %%q) := get_domain_core p <|> get_domain_core q | `(%%p ↔ %%q) := get_domain_core p <|> get_domain_core q | (pi _ _ p q) := mcond (is_prop p) (get_domain_core p <|> get_domain_core q) (return p) | `(@Exists %%t _) := return t | _ := failed meta def get_domain : tactic expr := target >>= get_domain_core meta def symb_arities (dx) : expr → ((list (bool × nat)) × expr) | x@(pi _ _ tx px) := if (is_pred_type dx tx || is_func_type dx tx) then let (as,y) := symb_arities px in ((is_pred_type dx tx, arity_of tx)::as, y) else ([],x) | x := ([],x) meta def to_term (k : nat) : expr → tactic term | (app x1 x2) := do t1 ← to_term x1, t2 ← to_term x2, return (t1 ^* t2) | (var m) := if m < k then return (term.var m) else return (term.fnc (m - k)) | _ := failed meta def to_form : nat → expr → tactic form | k `(true) := return ⊤* | k `(false) := return ⊥* | k `(¬ %%px) := do φ ← to_form k px, return (¬* φ) | k `(%%px ∨ %%qx) := do φ ← to_form k px, χ ← to_form k qx, return (φ ∨* χ) | k `(%%px ∧ %%qx) := do φ ← to_form k px, χ ← to_form k qx, return (φ ∧* χ) | k foo@(pi _ _ _ px) := do trace foo, φ ← to_form (k+1) px, return (∀* φ) | k `(Exists %%(expr.lam _ _ _ px)) := do φ ← to_form (k+1) px, return (∃* φ) | k `(Exists %%prx) := do φ ← to_form (k+1) (app (prx.lift_vars 0 1) (var 0)), return (∃* φ) | k px := match px.get_app_fn with | (var m) := do ts ← monad.mapm (to_term k) px.get_app_args, return ((m-k) ** ts) | foo := trace foo >> failed end meta def reify (dx ix : expr) : tactic unit := do gx ← target, (as,x) ← return (symb_arities dx gx), p ← to_form 0 x, px ← to_expr ``(@form.rvalid %%dx %%ix %%`(as) model.default %%`(p)), to_expr ``(imp_of_imp (%%px)) >>= apply, intro_fresh >>= apply, skip
d0ed39183654b8446de3a3a0428210cae8e5f7c8
618003631150032a5676f229d13a079ac875ff77
/src/tactic/omega/find_ees.lean
8c90d658ed6fc95041ab278de6bb5e733e8c5ed2
[ "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
5,559
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek A tactic for finding a sequence of equality elimination rules for a given set of constraints. -/ import tactic.omega.eq_elim variables {α β : Type} open tactic namespace omega /-- The state of equality elimination proof search. `eqs` is the list of equality constraints, and each `t ∈ eqs` represents the constraint `0 = t`. Similarly, `les` is the list of inequality constraints, and each `t ∈ eqs` represents the constraint `0 < t`. `ees` is the sequence of equality elimination steps that have been used so far to obtain the current set of constraints. The list `ees` grows over time until `eqs` becomes empty. -/ @[derive inhabited] structure ee_state := (eqs : list term) (les : list term) (ees : list ee) @[reducible] meta def eqelim := state_t ee_state tactic meta def abort {α : Type} : eqelim α := ⟨λ x, failed⟩ private meta def mk_eqelim_state (eqs les : list term) : tactic ee_state := return (ee_state.mk eqs les []) /-- Get the current list of equality constraints. -/ meta def get_eqs : eqelim (list term) := ee_state.eqs <$> get /-- Get the current list of inequality constraints. -/ meta def get_les : eqelim (list term) := ee_state.les <$> get /-- Get the current sequence of equality elimiation steps. -/ meta def get_ees : eqelim (list ee) := ee_state.ees <$> get /-- Update the list of equality constraints. -/ meta def set_eqs (eqs : list term) : eqelim unit := modify $ λ s, {eqs := eqs, ..s} /-- Update the list of inequality constraints. -/ meta def set_les (les : list term) : eqelim unit := modify $ λ s, {les := les, ..s} /-- Update the sequence of equality elimiation steps. -/ meta def set_ees (es : list ee) : eqelim unit := modify $ λ s, {ees := es, ..s} /-- Add a new step to the sequence of equality elimination steps. -/ meta def add_ee (e : ee) : eqelim unit := do es ← get_ees, set_ees (es ++ [e]) /-- Return the first equality constraint in the current list of equality constraints. The returned constraint is 'popped' and no longer available in the state. -/ meta def head_eq : eqelim term := do eqs ← get_eqs, match eqs with | [] := abort | (eq::eqs') := set_eqs eqs' >> pure eq end meta def run {α : Type} (eqs les : list term) (r : eqelim α) : tactic α := prod.fst <$> (mk_eqelim_state eqs les >>= r.run) /-- If `t1` succeeds and returns a value, 'commit' to that choice and run `t3` with the returned value as argument. Do not backtrack to try `t2` even if `t3` fails. If `t1` fails outright, run `t2`. -/ meta def ee_commit (t1 : eqelim α) (t2 : eqelim β) (t3 : α → eqelim β) : eqelim β := do x ← ((t1 >>= return ∘ some) <|> return none), match x with | none := t2 | (some a) := t3 a end local notation t1 `!>>=` t2 `;` t3 := ee_commit t1 t2 t3 private meta def of_tactic {α : Type} : tactic α → eqelim α := state_t.lift /-- GCD of all elements of the list. -/ def gcd : list int → nat | [] := 0 | (i::is) := nat.gcd i.nat_abs (gcd is) /-- GCD of all coefficients in a term. -/ meta def get_gcd (t : term) : eqelim int := pure ↑(gcd t.snd) /-- Divide a term by an integer if the integer divides the constant component of the term. It is assumed that the integer also divides all coefficients of the term. -/ meta def factor (i : int) (t : term) : eqelim term := if i ∣ t.fst then add_ee (ee.factor i) >> pure (t.div i) else abort /-- If list has a nonzero element, return the minimum element (by absolute value) with its index. Otherwise, return none. -/ meta def find_min_coeff_core : list int → eqelim (int × nat) | [] := abort | (i::is) := (do (j,n) ← find_min_coeff_core is, if i ≠ 0 ∧ i.nat_abs ≤ j.nat_abs then pure (i,0) else pure (j,n+1)) <|> (if i = (0 : int) then abort else pure (i,0)) /-- Find and return the smallest coefficient (by absolute value) in a term, along with the coefficient's variable index and the term itself. If the coefficient is negative, negate both the coefficient and the term before returning them. -/ meta def find_min_coeff (t : term) : eqelim (int × nat × term) := do (i,n) ← find_min_coeff_core t.snd, if 0 < i then pure (i,n,t) else add_ee (ee.neg) >> pure (-i,n,t.neg) /-- Find an appropriate equality elimination step for the current state and apply it. -/ meta def elim_eq : eqelim unit := do t ← head_eq, i ← get_gcd t, factor i t !>>= (set_eqs [] >> add_ee (ee.nondiv i)) ; λ s, find_min_coeff s !>>= add_ee ee.drop ; λ ⟨i, n, u⟩, if i = 1 then do eqs ← get_eqs, les ← get_les, set_eqs (eqs.map (cancel n u)), set_les (les.map (cancel n u)), add_ee (ee.cancel n) else let v : term := coeffs_reduce n u.fst u.snd in let r : term := rhs n u.fst u.snd in do eqs ← get_eqs, les ← get_les, set_eqs (v::eqs.map (subst n r)), set_les (les.map (subst n r)), add_ee (ee.reduce n), elim_eq /-- Find and return the sequence of steps for eliminating all equality constraints in the current state. -/ meta def elim_eqs : eqelim (list ee) := elim_eq !>>= get_ees ; λ _, elim_eqs /-- Given a linear constrain clause, return a list of steps for eliminating its equality constraints. -/ meta def find_ees : clause → tactic (list ee) | (eqs,les) := run eqs les elim_eqs end omega
90331dc4bb817219c375666e03363d937d6da7ee
500f65bb93c499cd35c3254d894d762208cae042
/src/set_theory/cardinal.lean
7fd66777987533e1aeed7b54e368428e097ea8c4
[ "Apache-2.0" ]
permissive
PatrickMassot/mathlib
c39dc0ff18bbde42f1c93a1642f6e429adad538c
45df75b3c9da159fe3192fa7f769dfbec0bd6bda
refs/heads/master
1,623,168,646,390
1,566,940,765,000
1,566,940,765,000
115,220,590
0
1
null
1,514,061,524,000
1,514,061,524,000
null
UTF-8
Lean
false
false
42,389
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl, Mario Carneiro -/ import data.set.countable data.quot logic.function set_theory.schroeder_bernstein /-! # Cardinal Numbers We define cardinal numbers as a quotient of types under the equivalence relation of equinumerity. We define the order on cardinal numbers, define omega, and do basic cardinal arithmetic: addition, multiplication, power, cardinal successor, minimum, supremum, infinitary sums and products ## Implementation notes * There is a type of cardinal numbers in every universe level: `cardinal.{u} : Type (u + 1)` is the quotient of types in `Type u`. There is a lift operation lifting cardinal numbers to a higher level. * Cardinal arithmetic specifically for infinite cardinals (like `κ * κ = κ`) is in the file `set_theory/ordinal.lean`, because concepts from that file are used in the proof. ## References * https://en.wikipedia.org/wiki/Cardinal_number ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, omega -/ open function lattice set local attribute [instance] classical.prop_decidable universes u v w x variables {α β : Type u} /-- The equivalence relation on types given by equivalence (bijective correspondence) of types. Quotienting by this equivalence relation gives the cardinal numbers. -/ instance cardinal.is_equivalent : setoid (Type u) := { r := λα β, nonempty (α ≃ β), iseqv := ⟨λα, ⟨equiv.refl α⟩, λα β ⟨e⟩, ⟨e.symm⟩, λα β γ ⟨e₁⟩ ⟨e₂⟩, ⟨e₁.trans e₂⟩⟩ } /-- `cardinal.{u}` is the type of cardinal numbers in `Type u`, defined as the quotient of `Type u` by existence of an equivalence (a bijection with explicit inverse). -/ def cardinal : Type (u + 1) := quotient cardinal.is_equivalent namespace cardinal /-- The cardinal number of a type -/ def mk : Type u → cardinal := quotient.mk @[simp] theorem mk_def (α : Type u) : @eq cardinal ⟦α⟧ (mk α) := rfl @[simp] theorem mk_out (c : cardinal) : mk (c.out) = c := quotient.out_eq _ /-- We define the order on cardinal numbers by `mk α ≤ mk β` if and only if there exists an embedding (injective function) from α to β. -/ instance : has_le cardinal.{u} := ⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, nonempty $ α ↪ β) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩, propext ⟨assume ⟨e⟩, ⟨e.congr e₁ e₂⟩, assume ⟨e⟩, ⟨e.congr e₁.symm e₂.symm⟩⟩⟩ theorem mk_le_of_injective {α β : Type u} {f : α → β} (hf : injective f) : mk α ≤ mk β := ⟨⟨f, hf⟩⟩ theorem mk_le_of_surjective {α β : Type u} {f : α → β} (hf : surjective f) : mk β ≤ mk α := ⟨embedding.of_surjective hf⟩ theorem le_mk_iff_exists_set {c : cardinal} {α : Type u} : c ≤ mk α ↔ ∃ p : set α, mk p = c := ⟨quotient.induction_on c $ λ β ⟨⟨f, hf⟩⟩, ⟨set.range f, eq.symm $ quot.sound ⟨equiv.set.range f hf⟩⟩, λ ⟨p, e⟩, e ▸ ⟨⟨subtype.val, λ a b, subtype.eq⟩⟩⟩ theorem out_embedding {c c' : cardinal} : c ≤ c' ↔ nonempty (c.out ↪ c'.out) := by { transitivity _, rw [←quotient.out_eq c, ←quotient.out_eq c'], refl } instance : linear_order cardinal.{u} := { le := (≤), le_refl := by rintros ⟨α⟩; exact ⟨embedding.refl _⟩, le_trans := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨e₁.trans e₂⟩, le_antisymm := by rintros ⟨α⟩ ⟨β⟩ ⟨e₁⟩ ⟨e₂⟩; exact quotient.sound (e₁.antisymm e₂), le_total := by rintros ⟨α⟩ ⟨β⟩; exact embedding.total } noncomputable instance : decidable_linear_order cardinal.{u} := classical.DLO _ noncomputable instance : distrib_lattice cardinal.{u} := by apply_instance instance : has_zero cardinal.{u} := ⟨⟦pempty⟧⟩ instance : inhabited cardinal.{u} := ⟨0⟩ theorem ne_zero_iff_nonempty {α : Type u} : mk α ≠ 0 ↔ nonempty α := not_iff_comm.1 ⟨λ h, quotient.sound ⟨(equiv.empty_of_not_nonempty h).trans equiv.empty_equiv_pempty⟩, λ e, let ⟨h⟩ := quotient.exact e in λ ⟨a⟩, (h a).elim⟩ instance : has_one cardinal.{u} := ⟨⟦punit⟧⟩ instance : zero_ne_one_class cardinal.{u} := { zero := 0, one := 1, zero_ne_one := ne.symm $ ne_zero_iff_nonempty.2 ⟨punit.star⟩ } theorem le_one_iff_subsingleton {α : Type u} : mk α ≤ 1 ↔ subsingleton α := ⟨λ ⟨f⟩, ⟨λ a b, f.inj (subsingleton.elim _ _)⟩, λ ⟨h⟩, ⟨⟨λ a, punit.star, λ a b _, h _ _⟩⟩⟩ instance : has_add cardinal.{u} := ⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α ⊕ β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩, quotient.sound ⟨equiv.sum_congr e₁ e₂⟩⟩ @[simp] theorem add_def (α β) : mk α + mk β = mk (α ⊕ β) := rfl instance : has_mul cardinal.{u} := ⟨λq₁ q₂, quotient.lift_on₂ q₁ q₂ (λα β, mk (α × β)) $ assume α β γ δ ⟨e₁⟩ ⟨e₂⟩, quotient.sound ⟨equiv.prod_congr e₁ e₂⟩⟩ @[simp] theorem mul_def (α β : Type u) : mk α * mk β = mk (α × β) := rfl private theorem add_comm (a b : cardinal.{u}) : a + b = b + a := quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.sum_comm α β⟩ private theorem mul_comm (a b : cardinal.{u}) : a * b = b * a := quotient.induction_on₂ a b $ assume α β, quotient.sound ⟨equiv.prod_comm α β⟩ private theorem zero_add (a : cardinal.{u}) : 0 + a = a := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_sum α⟩ private theorem zero_mul (a : cardinal.{u}) : 0 * a = 0 := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_prod α⟩ private theorem one_mul (a : cardinal.{u}) : 1 * a = a := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.punit_prod α⟩ private theorem left_distrib (a b c : cardinal.{u}) : a * (b + c) = a * b + a * c := quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.prod_sum_distrib α β γ⟩ instance : comm_semiring cardinal.{u} := { zero := 0, one := 1, add := (+), mul := (*), zero_add := zero_add, add_zero := assume a, by rw [add_comm a 0, zero_add a], add_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.sum_assoc α β γ⟩, add_comm := add_comm, zero_mul := zero_mul, mul_zero := assume a, by rw [mul_comm a 0, zero_mul a], one_mul := one_mul, mul_one := assume a, by rw [mul_comm a 1, one_mul a], mul_assoc := λa b c, quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.prod_assoc α β γ⟩, mul_comm := mul_comm, left_distrib := left_distrib, right_distrib := assume a b c, by rw [mul_comm (a + b) c, left_distrib c a b, mul_comm c a, mul_comm c b] } /-- The cardinal exponential. `mk α ^ mk β` is the cardinal of `β → α`. -/ protected def power (a b : cardinal.{u}) : cardinal.{u} := quotient.lift_on₂ a b (λα β, mk (β → α)) $ assume α₁ α₂ β₁ β₂ ⟨e₁⟩ ⟨e₂⟩, quotient.sound ⟨equiv.arrow_congr e₂ e₁⟩ instance : has_pow cardinal cardinal := ⟨cardinal.power⟩ local infixr ^ := @has_pow.pow cardinal cardinal cardinal.has_pow @[simp] theorem power_def (α β) : mk α ^ mk β = mk (β → α) := rfl @[simp] theorem power_zero {a : cardinal} : a ^ 0 = 1 := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.pempty_arrow_equiv_punit α⟩ @[simp] theorem power_one {a : cardinal} : a ^ 1 = a := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.punit_arrow_equiv α⟩ @[simp] theorem one_power {a : cardinal} : 1 ^ a = 1 := quotient.induction_on a $ assume α, quotient.sound ⟨equiv.arrow_punit_equiv_punit α⟩ @[simp] theorem prop_eq_two : mk (ulift Prop) = 2 := quot.sound ⟨equiv.ulift.trans $ equiv.Prop_equiv_bool.trans equiv.bool_equiv_punit_sum_punit⟩ @[simp] theorem zero_power {a : cardinal} : a ≠ 0 → 0 ^ a = 0 := quotient.induction_on a $ assume α heq, nonempty.rec_on (ne_zero_iff_nonempty.1 heq) $ assume a, quotient.sound ⟨equiv.equiv_pempty $ assume f, pempty.rec (λ _, false) (f a)⟩ theorem power_ne_zero {a : cardinal} (b) : a ≠ 0 → a ^ b ≠ 0 := quotient.induction_on₂ a b $ λ α β h, let ⟨a⟩ := ne_zero_iff_nonempty.1 h in ne_zero_iff_nonempty.2 ⟨λ _, a⟩ theorem mul_power {a b c : cardinal} : (a * b) ^ c = a ^ c * b ^ c := quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.arrow_prod_equiv_prod_arrow α β γ⟩ theorem power_add {a b c : cardinal} : a ^ (b + c) = a ^ b * a ^ c := quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.sum_arrow_equiv_prod_arrow β γ α⟩ theorem power_mul {a b c : cardinal} : (a ^ b) ^ c = a ^ (b * c) := by rw [_root_.mul_comm b c]; from (quotient.induction_on₃ a b c $ assume α β γ, quotient.sound ⟨equiv.arrow_arrow_equiv_prod_arrow γ β α⟩) @[simp] lemma pow_cast_right (κ : cardinal.{u}) : ∀ n : ℕ, (κ ^ (↑n : cardinal.{u})) = @has_pow.pow _ _ monoid.has_pow κ n | 0 := by simp | (_+1) := by rw [nat.cast_succ, power_add, power_one, _root_.mul_comm, pow_succ, pow_cast_right] section order_properties open sum theorem zero_le : ∀(a : cardinal), 0 ≤ a := by rintro ⟨α⟩; exact ⟨embedding.of_not_nonempty $ λ ⟨a⟩, a.elim⟩ theorem le_zero (a : cardinal) : a ≤ 0 ↔ a = 0 := by simp [le_antisymm_iff, zero_le] theorem pos_iff_ne_zero {o : cardinal} : 0 < o ↔ o ≠ 0 := by simp [lt_iff_le_and_ne, eq_comm, zero_le] theorem zero_lt_one : (0 : cardinal) < 1 := lt_of_le_of_ne (zero_le _) zero_ne_one lemma zero_power_le (c : cardinal.{u}) : (0 : cardinal.{u}) ^ c ≤ 1 := by { by_cases h : c = 0, rw [h, power_zero], rw [zero_power h], apply zero_le } theorem add_le_add : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a + c ≤ b + d := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨embedding.sum_congr e₁ e₂⟩ theorem add_le_add_left (a) {b c : cardinal} : b ≤ c → a + b ≤ a + c := add_le_add (le_refl _) theorem add_le_add_right {a b : cardinal} (c) (h : a ≤ b) : a + c ≤ b + c := add_le_add h (le_refl _) theorem le_add_right (a b : cardinal) : a ≤ a + b := by simpa using add_le_add_left a (zero_le b) theorem le_add_left (a b : cardinal) : a ≤ b + a := by simpa using add_le_add_right a (zero_le b) theorem mul_le_mul : ∀{a b c d : cardinal}, a ≤ b → c ≤ d → a * c ≤ b * d := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ ⟨δ⟩ ⟨e₁⟩ ⟨e₂⟩; exact ⟨embedding.prod_congr e₁ e₂⟩ theorem mul_le_mul_left (a) {b c : cardinal} : b ≤ c → a * b ≤ a * c := mul_le_mul (le_refl _) theorem mul_le_mul_right {a b : cardinal} (c) (h : a ≤ b) : a * c ≤ b * c := mul_le_mul h (le_refl _) theorem power_le_power_left : ∀{a b c : cardinal}, a ≠ 0 → b ≤ c → a ^ b ≤ a ^ c := by rintros ⟨α⟩ ⟨β⟩ ⟨γ⟩ hα ⟨e⟩; exact let ⟨a⟩ := ne_zero_iff_nonempty.1 hα in ⟨@embedding.arrow_congr_right _ _ _ ⟨a⟩ e⟩ theorem power_le_power_right {a b c : cardinal} : a ≤ b → a ^ c ≤ b ^ c := quotient.induction_on₃ a b c $ assume α β γ ⟨e⟩, ⟨embedding.arrow_congr_left e⟩ theorem le_iff_exists_add {a b : cardinal} : a ≤ b ↔ ∃ c, b = a + c := ⟨quotient.induction_on₂ a b $ λ α β ⟨⟨f, hf⟩⟩, have (α ⊕ ↥-range f) ≃ β, from (equiv.sum_congr (equiv.set.range f hf) (equiv.refl _)).trans $ (equiv.set.sum_compl (range f)), ⟨⟦(-range f : set β)⟧, quotient.sound ⟨this.symm⟩⟩, λ ⟨c, e⟩, add_zero a ▸ e.symm ▸ add_le_add_left _ (zero_le _)⟩ end order_properties instance : order_bot cardinal.{u} := { bot := 0, bot_le := zero_le, ..cardinal.linear_order } instance : canonically_ordered_monoid cardinal.{u} := { add_le_add_left := λ a b h c, add_le_add_left _ h, lt_of_add_lt_add_left := λ a b c, lt_imp_lt_of_le_imp_le (add_le_add_left _), le_iff_exists_add := @le_iff_exists_add, ..cardinal.lattice.order_bot, ..cardinal.comm_semiring, ..cardinal.linear_order } theorem cantor : ∀(a : cardinal.{u}), a < 2 ^ a := by rw ← prop_eq_two; rintros ⟨a⟩; exact ⟨ ⟨⟨λ a b, ⟨a = b⟩, λ a b h, cast (ulift.up.inj (@congr_fun _ _ _ _ h b)).symm rfl⟩⟩, λ ⟨⟨f, hf⟩⟩, cantor_injective (λ s, f (λ a, ⟨s a⟩)) $ λ s t h, by funext a; injection congr_fun (hf h) a⟩ instance : no_top_order cardinal.{u} := { no_top := λ a, ⟨_, cantor a⟩, ..cardinal.linear_order } /-- The minimum cardinal in a family of cardinals (the existence of which is provided by `injective_min`). -/ noncomputable def min {ι} (I : nonempty ι) (f : ι → cardinal) : cardinal := f $ classical.some $ @embedding.injective_min _ (λ i, (f i).out) I theorem min_eq {ι} (I) (f : ι → cardinal) : ∃ i, min I f = f i := ⟨_, rfl⟩ theorem min_le {ι I} (f : ι → cardinal) (i) : min I f ≤ f i := by rw [← mk_out (min I f), ← mk_out (f i)]; exact let ⟨g⟩ := classical.some_spec (@embedding.injective_min _ (λ i, (f i).out) I) in ⟨g i⟩ theorem le_min {ι I} {f : ι → cardinal} {a} : a ≤ min I f ↔ ∀ i, a ≤ f i := ⟨λ h i, le_trans h (min_le _ _), λ h, let ⟨i, e⟩ := min_eq I f in e.symm ▸ h i⟩ protected theorem wf : @well_founded cardinal.{u} (<) := ⟨λ a, classical.by_contradiction $ λ h, let ι := {c :cardinal // ¬ acc (<) c}, f : ι → cardinal := subtype.val, ⟨⟨c, hc⟩, hi⟩ := @min_eq ι ⟨⟨_, h⟩⟩ f in hc (acc.intro _ (λ j ⟨_, h'⟩, classical.by_contradiction $ λ hj, h' $ by have := min_le f ⟨j, hj⟩; rwa hi at this))⟩ instance has_wf : @has_well_founded cardinal.{u} := ⟨(<), cardinal.wf⟩ instance wo : @is_well_order cardinal.{u} (<) := ⟨cardinal.wf⟩ /-- The successor cardinal - the smallest cardinal greater than `c`. This is not the same as `c + 1` except in the case of finite `c`. -/ noncomputable def succ (c : cardinal) : cardinal := @min {c' // c < c'} ⟨⟨_, cantor _⟩⟩ subtype.val theorem lt_succ_self (c : cardinal) : c < succ c := by cases min_eq _ _ with s e; rw [succ, e]; exact s.2 theorem succ_le {a b : cardinal} : succ a ≤ b ↔ a < b := ⟨lt_of_lt_of_le (lt_succ_self _), λ h, by exact min_le _ (subtype.mk b h)⟩ theorem lt_succ {a b : cardinal} : a < succ b ↔ a ≤ b := by rw [← not_le, succ_le, not_lt] theorem add_one_le_succ (c : cardinal) : c + 1 ≤ succ c := begin refine quot.induction_on c (λ α, _) (lt_succ_self c), refine quot.induction_on (succ (quot.mk setoid.r α)) (λ β h, _), cases h.left with f, have : ¬ surjective f := λ hn, ne_of_lt h (quotient.sound ⟨equiv.of_bijective ⟨f.inj, hn⟩⟩), cases classical.not_forall.1 this with b nex, refine ⟨⟨sum.rec (by exact f) _, _⟩⟩, { exact λ _, b }, { intros a b h, rcases a with a|⟨⟨⟨⟩⟩⟩; rcases b with b|⟨⟨⟨⟩⟩⟩, { rw f.inj h }, { exact nex.elim ⟨_, h⟩ }, { exact nex.elim ⟨_, h.symm⟩ }, { refl } } end lemma succ_ne_zero (c : cardinal) : succ c ≠ 0 := by { rw [←pos_iff_ne_zero, lt_succ], apply zero_le } /-- The indexed sum of cardinals is the cardinality of the indexed disjoint union, i.e. sigma type. -/ def sum {ι} (f : ι → cardinal) : cardinal := mk Σ i, (f i).out theorem le_sum {ι} (f : ι → cardinal) (i) : f i ≤ sum f := by rw ← quotient.out_eq (f i); exact ⟨⟨λ a, ⟨i, a⟩, λ a b h, eq_of_heq $ by injection h⟩⟩ @[simp] theorem sum_mk {ι} (f : ι → Type*) : sum (λ i, mk (f i)) = mk (Σ i, f i) := quot.sound ⟨equiv.sigma_congr_right $ λ i, classical.choice $ quotient.exact $ quot.out_eq $ mk (f i)⟩ theorem sum_const (ι : Type u) (a : cardinal.{u}) : sum (λ _:ι, a) = mk ι * a := quotient.induction_on a $ λ α, by simp; exact quotient.sound ⟨equiv.sigma_equiv_prod _ _⟩ theorem sum_le_sum {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sum f ≤ sum g := ⟨embedding.sigma_congr_right $ λ i, classical.choice $ by have := H i; rwa [← quot.out_eq (f i), ← quot.out_eq (g i)] at this⟩ /-- The indexed supremum of cardinals is the smallest cardinal above everything in the family. -/ noncomputable def sup {ι} (f : ι → cardinal) : cardinal := @min {c // ∀ i, f i ≤ c} ⟨⟨sum f, le_sum f⟩⟩ (λ a, a.1) theorem le_sup {ι} (f : ι → cardinal) (i) : f i ≤ sup f := by dsimp [sup]; cases min_eq _ _ with c hc; rw hc; exact c.2 i theorem sup_le {ι} {f : ι → cardinal} {a} : sup f ≤ a ↔ ∀ i, f i ≤ a := ⟨λ h i, le_trans (le_sup _ _) h, λ h, by dsimp [sup]; change a with (⟨a, h⟩:subtype _).1; apply min_le⟩ theorem sup_le_sup {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : sup f ≤ sup g := sup_le.2 $ λ i, le_trans (H i) (le_sup _ _) theorem sup_le_sum {ι} (f : ι → cardinal) : sup f ≤ sum f := sup_le.2 $ le_sum _ theorem sum_le_sup {ι : Type u} (f : ι → cardinal.{u}) : sum f ≤ mk ι * sup.{u u} f := by rw ← sum_const; exact sum_le_sum _ _ (le_sup _) theorem sup_eq_zero {ι} {f : ι → cardinal} (h : ι → false) : sup f = 0 := by { rw [←le_zero, sup_le], intro x, exfalso, exact h x } /-- The indexed product of cardinals is the cardinality of the Pi type (dependent product). -/ def prod {ι : Type u} (f : ι → cardinal) : cardinal := mk (Π i, (f i).out) @[simp] theorem prod_mk {ι} (f : ι → Type*) : prod (λ i, mk (f i)) = mk (Π i, f i) := quot.sound ⟨equiv.Pi_congr_right $ λ i, classical.choice $ quotient.exact $ mk_out $ mk (f i)⟩ theorem prod_const (ι : Type u) (a : cardinal.{u}) : prod (λ _:ι, a) = a ^ mk ι := quotient.induction_on a $ by simp theorem prod_le_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i ≤ g i) : prod f ≤ prod g := ⟨embedding.Pi_congr_right $ λ i, classical.choice $ by have := H i; rwa [← mk_out (f i), ← mk_out (g i)] at this⟩ theorem prod_ne_zero {ι} (f : ι → cardinal) : prod f ≠ 0 ↔ ∀ i, f i ≠ 0 := begin conv in (f _) {rw ← mk_out (f i)}, simp [prod, ne_zero_iff_nonempty, -mk_out, -ne.def], exact ⟨λ ⟨F⟩ i, ⟨F i⟩, λ h, ⟨λ i, classical.choice (h i)⟩⟩, end theorem prod_eq_zero {ι} (f : ι → cardinal) : prod f = 0 ↔ ∃ i, f i = 0 := not_iff_not.1 $ by simpa using prod_ne_zero f /-- The universe lift operation on cardinals. You can specify the universes explicitly with `lift.{u v} : cardinal.{u} → cardinal.{max u v}` -/ def lift (c : cardinal.{u}) : cardinal.{max u v} := quotient.lift_on c (λ α, ⟦ulift α⟧) $ λ α β ⟨e⟩, quotient.sound ⟨equiv.ulift.trans $ e.trans equiv.ulift.symm⟩ theorem lift_mk (α) : lift.{u v} (mk α) = mk (ulift.{v u} α) := rfl theorem lift_umax : lift.{u (max u v)} = lift.{u v} := funext $ λ a, quot.induction_on a $ λ α, quotient.sound ⟨equiv.ulift.trans equiv.ulift.symm⟩ theorem lift_id' (a : cardinal) : lift a = a := quot.induction_on a $ λ α, quot.sound ⟨equiv.ulift⟩ @[simp] theorem lift_id : ∀ a, lift.{u u} a = a := lift_id'.{u u} @[simp] theorem lift_lift (a : cardinal) : lift.{(max u v) w} (lift.{u v} a) = lift.{u (max v w)} a := quot.induction_on a $ λ α, quotient.sound ⟨equiv.ulift.trans $ equiv.ulift.trans equiv.ulift.symm⟩ theorem lift_mk_le {α : Type u} {β : Type v} : lift.{u (max v w)} (mk α) ≤ lift.{v (max u w)} (mk β) ↔ nonempty (α ↪ β) := ⟨λ ⟨f⟩, ⟨embedding.congr equiv.ulift equiv.ulift f⟩, λ ⟨f⟩, ⟨embedding.congr equiv.ulift.symm equiv.ulift.symm f⟩⟩ theorem lift_mk_eq {α : Type u} {β : Type v} : lift.{u (max v w)} (mk α) = lift.{v (max u w)} (mk β) ↔ nonempty (α ≃ β) := quotient.eq.trans ⟨λ ⟨f⟩, ⟨equiv.ulift.symm.trans $ f.trans equiv.ulift⟩, λ ⟨f⟩, ⟨equiv.ulift.trans $ f.trans equiv.ulift.symm⟩⟩ @[simp] theorem lift_le {a b : cardinal} : lift a ≤ lift b ↔ a ≤ b := quotient.induction_on₂ a b $ λ α β, by rw ← lift_umax; exact lift_mk_le @[simp] theorem lift_inj {a b : cardinal} : lift a = lift b ↔ a = b := by simp [le_antisymm_iff] @[simp] theorem lift_lt {a b : cardinal} : lift a < lift b ↔ a < b := by simp [lt_iff_le_not_le, -not_le] @[simp] theorem lift_zero : lift 0 = 0 := quotient.sound ⟨equiv.ulift.trans equiv.pempty_equiv_pempty⟩ @[simp] theorem lift_one : lift 1 = 1 := quotient.sound ⟨equiv.ulift.trans equiv.punit_equiv_punit⟩ @[simp] theorem lift_add (a b) : lift (a + b) = lift a + lift b := quotient.induction_on₂ a b $ λ α β, quotient.sound ⟨equiv.ulift.trans (equiv.sum_congr equiv.ulift equiv.ulift).symm⟩ @[simp] theorem lift_mul (a b) : lift (a * b) = lift a * lift b := quotient.induction_on₂ a b $ λ α β, quotient.sound ⟨equiv.ulift.trans (equiv.prod_congr equiv.ulift equiv.ulift).symm⟩ @[simp] theorem lift_power (a b) : lift (a ^ b) = lift a ^ lift b := quotient.induction_on₂ a b $ λ α β, quotient.sound ⟨equiv.ulift.trans (equiv.arrow_congr equiv.ulift equiv.ulift).symm⟩ @[simp] theorem lift_two_power (a) : lift (2 ^ a) = 2 ^ lift a := by simp [bit0] @[simp] theorem lift_min {ι I} (f : ι → cardinal) : lift (min I f) = min I (lift ∘ f) := le_antisymm (le_min.2 $ λ a, lift_le.2 $ min_le _ a) $ let ⟨i, e⟩ := min_eq I (lift ∘ f) in by rw e; exact lift_le.2 (le_min.2 $ λ j, lift_le.1 $ by have := min_le (lift ∘ f) j; rwa e at this) theorem lift_down {a : cardinal.{u}} {b : cardinal.{max u v}} : b ≤ lift a → ∃ a', lift a' = b := quotient.induction_on₂ a b $ λ α β, by dsimp; rw [← lift_id (mk β), ← lift_umax, ← lift_umax.{u v}, lift_mk_le]; exact λ ⟨f⟩, ⟨mk (set.range f), eq.symm $ lift_mk_eq.2 ⟨embedding.equiv_of_surjective (embedding.cod_restrict _ f set.mem_range_self) $ λ ⟨a, ⟨b, e⟩⟩, ⟨b, subtype.eq e⟩⟩⟩ theorem le_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} : b ≤ lift a ↔ ∃ a', lift a' = b ∧ a' ≤ a := ⟨λ h, let ⟨a', e⟩ := lift_down h in ⟨a', e, lift_le.1 $ e.symm ▸ h⟩, λ ⟨a', e, h⟩, e ▸ lift_le.2 h⟩ theorem lt_lift_iff {a : cardinal.{u}} {b : cardinal.{max u v}} : b < lift a ↔ ∃ a', lift a' = b ∧ a' < a := ⟨λ h, let ⟨a', e⟩ := lift_down (le_of_lt h) in ⟨a', e, lift_lt.1 $ e.symm ▸ h⟩, λ ⟨a', e, h⟩, e ▸ lift_lt.2 h⟩ @[simp] theorem lift_succ (a) : lift (succ a) = succ (lift a) := le_antisymm (le_of_not_gt $ λ h, begin rcases lt_lift_iff.1 h with ⟨b, e, h⟩, rw [lt_succ, ← lift_le, e] at h, exact not_lt_of_le h (lt_succ_self _) end) (succ_le.2 $ lift_lt.2 $ lt_succ_self _) @[simp] theorem lift_max {a : cardinal.{u}} {b : cardinal.{v}} : lift.{u (max v w)} a = lift.{v (max u w)} b ↔ lift.{u v} a = lift.{v u} b := calc lift.{u (max v w)} a = lift.{v (max u w)} b ↔ lift.{(max u v) w} (lift.{u v} a) = lift.{(max u v) w} (lift.{v u} b) : by simp ... ↔ lift.{u v} a = lift.{v u} b : lift_inj theorem mk_prod {α : Type u} {β : Type v} : mk (α × β) = lift.{u v} (mk α) * lift.{v u} (mk β) := quotient.sound ⟨equiv.prod_congr (equiv.ulift).symm (equiv.ulift).symm⟩ theorem sum_const_eq_lift_mul (ι : Type u) (a : cardinal.{v}) : sum (λ _:ι, a) = lift.{u v} (mk ι) * lift.{v u} a := begin apply quotient.induction_on a, intro α, simp only [cardinal.mk_def, cardinal.sum_mk, cardinal.lift_id], convert mk_prod using 1, exact quotient.sound ⟨equiv.sigma_equiv_prod ι α⟩, end /-- `ω` is the smallest infinite cardinal, also known as ℵ₀. -/ def omega : cardinal.{u} := lift (mk ℕ) lemma mk_nat : mk nat = omega := (lift_id _).symm theorem omega_ne_zero : omega ≠ 0 := ne_zero_iff_nonempty.2 ⟨⟨0⟩⟩ theorem omega_pos : 0 < omega := pos_iff_ne_zero.2 omega_ne_zero @[simp] theorem lift_omega : lift omega = omega := lift_lift _ @[simp] theorem mk_fin : ∀ (n : ℕ), mk (fin n) = n | 0 := quotient.sound ⟨(equiv.pempty_of_not_nonempty $ λ ⟨h⟩, h.elim0)⟩ | (n+1) := by rw [nat.cast_succ, ← mk_fin]; exact quotient.sound (fintype.card_eq.1 $ by simp) @[simp] theorem lift_nat_cast (n : ℕ) : lift n = n := by induction n; simp * theorem lift_mk_fin (n : ℕ) : lift (mk (fin n)) = n := by simp theorem fintype_card (α : Type u) [fintype α] : mk α = fintype.card α := by rw [← lift_mk_fin.{u}, ← lift_id (mk α), lift_mk_eq.{u 0 u}]; exact fintype.card_eq.1 (by simp) theorem card_le_of_finset {α} (s : finset α) : (s.card : cardinal) ≤ cardinal.mk α := begin rw (_ : (s.card : cardinal) = cardinal.mk (↑s : set α)), { exact ⟨function.embedding.subtype _⟩ }, rw [cardinal.fintype_card, fintype.card_coe] end @[simp, elim_cast] theorem nat_cast_pow {m n : ℕ} : (↑(pow m n) : cardinal) = m ^ n := by induction n; simp [nat.pow_succ, -_root_.add_comm, power_add, *] @[simp, elim_cast] theorem nat_cast_le {m n : ℕ} : (m : cardinal) ≤ n ↔ m ≤ n := by rw [← lift_mk_fin, ← lift_mk_fin, lift_le]; exact ⟨λ ⟨⟨f, hf⟩⟩, begin have : _ = fintype.card _ := finset.card_image_of_injective finset.univ hf, simp at this, rw [← fintype.card_fin n, ← this], exact finset.card_le_of_subset (finset.subset_univ _) end, λ h, ⟨⟨λ i, ⟨i.1, lt_of_lt_of_le i.2 h⟩, λ a b h, have _, from fin.veq_of_eq h, fin.eq_of_veq this⟩⟩⟩ @[simp, elim_cast] theorem nat_cast_lt {m n : ℕ} : (m : cardinal) < n ↔ m < n := by simp [lt_iff_le_not_le, -not_le] @[simp, elim_cast] theorem nat_cast_inj {m n : ℕ} : (m : cardinal) = n ↔ m = n := by simp [le_antisymm_iff] @[simp, elim_cast] theorem nat_succ (n : ℕ) : succ n = n.succ := le_antisymm (succ_le.2 $ nat_cast_lt.2 $ nat.lt_succ_self _) (add_one_le_succ _) @[simp] theorem succ_zero : succ 0 = 1 := by simpa using nat_succ 0 theorem cantor' (a) {b : cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le, (by simpa using nat_succ 1 : succ 1 = 2)] at hb; exact lt_of_lt_of_le (cantor _) (power_le_power_right hb) theorem one_le_iff_pos {c : cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le] theorem one_le_iff_ne_zero {c : cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] theorem nat_lt_omega (n : ℕ) : (n : cardinal.{u}) < omega := succ_le.1 $ by rw [nat_succ, ← lift_mk_fin, omega, lift_mk_le.{0 0 u}]; exact ⟨⟨fin.val, λ a b, fin.eq_of_veq⟩⟩ theorem one_lt_omega : 1 < omega := by simpa using nat_lt_omega 1 theorem lt_omega {c : cardinal.{u}} : c < omega ↔ ∃ n : ℕ, c = n := ⟨λ h, begin rcases lt_lift_iff.1 h with ⟨c, rfl, h'⟩, rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩, suffices : finite S, { cases this, resetI, existsi fintype.card S, rw [← lift_nat_cast.{0 u}, lift_inj, fintype_card S] }, by_contra nf, have P : ∀ (n : ℕ) (IH : ∀ i<n, S), ∃ a : S, ¬ ∃ y h, IH y h = a := λ n IH, let g : {i | i < n} → S := λ ⟨i, h⟩, IH i h in classical.not_forall.1 (λ h, nf ⟨fintype.of_surjective g (λ a, subtype.exists.2 (h a))⟩), let F : ℕ → S := nat.lt_wf.fix (λ n IH, classical.some (P n IH)), refine not_le_of_lt h' ⟨⟨F, _⟩⟩, suffices : ∀ (n : ℕ) (m < n), F m ≠ F n, { refine λ m n, not_imp_not.1 (λ ne, _), rcases lt_trichotomy m n with h|h|h, { exact this n m h }, { contradiction }, { exact (this m n h).symm } }, intros n m h, have := classical.some_spec (P n (λ y _, F y)), rw [← show F n = classical.some (P n (λ y _, F y)), from nat.lt_wf.fix_eq (λ n IH, classical.some (P n IH)) n] at this, exact λ e, this ⟨m, h, e⟩, end, λ ⟨n, e⟩, e.symm ▸ nat_lt_omega _⟩ theorem omega_le {c : cardinal.{u}} : omega ≤ c ↔ ∀ n : ℕ, (n:cardinal) ≤ c := ⟨λ h n, le_trans (le_of_lt (nat_lt_omega _)) h, λ h, le_of_not_lt $ λ hn, begin rcases lt_omega.1 hn with ⟨n, rfl⟩, exact not_le_of_lt (nat.lt_succ_self _) (nat_cast_le.1 (h (n+1))) end⟩ theorem lt_omega_iff_fintype {α : Type u} : mk α < omega ↔ nonempty (fintype α) := lt_omega.trans ⟨λ ⟨n, e⟩, begin rw [← lift_mk_fin n] at e, cases quotient.exact e with f, exact ⟨fintype.of_equiv _ f.symm⟩ end, λ ⟨_⟩, by exactI ⟨_, fintype_card _⟩⟩ theorem lt_omega_iff_finite {α} {S : set α} : mk S < omega ↔ finite S := lt_omega_iff_fintype theorem add_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a + b < omega := match a, b, lt_omega.1 ha, lt_omega.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_add]; apply nat_lt_omega end theorem mul_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a * b < omega := match a, b, lt_omega.1 ha, lt_omega.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat.cast_mul]; apply nat_lt_omega end theorem power_lt_omega {a b : cardinal} (ha : a < omega) (hb : b < omega) : a ^ b < omega := match a, b, lt_omega.1 ha, lt_omega.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by rw [← nat_cast_pow]; apply nat_lt_omega end theorem infinite_iff {α : Type u} : infinite α ↔ omega ≤ mk α := by rw [←not_lt, lt_omega_iff_fintype, not_nonempty_fintype] lemma countable_iff (s : set α) : countable s ↔ mk s ≤ omega := begin rw [countable_iff_exists_injective], split, rintro ⟨f, hf⟩, exact ⟨embedding.trans ⟨f, hf⟩ equiv.ulift.symm.to_embedding⟩, rintro ⟨f'⟩, cases embedding.trans f' equiv.ulift.to_embedding with f hf, exact ⟨f, hf⟩ end lemma denumerable_iff {α : Type u} : nonempty (denumerable α) ↔ mk α = omega := ⟨λ⟨h⟩, quotient.sound $ by exactI ⟨ (denumerable.eqv α).trans equiv.ulift.symm ⟩, λ h, by { cases quotient.exact h with f, exact ⟨denumerable.mk' $ f.trans equiv.ulift⟩ }⟩ lemma mk_int : mk ℤ = omega := denumerable_iff.mp ⟨by apply_instance⟩ lemma mk_pnat : mk ℕ+ = omega := denumerable_iff.mp ⟨by apply_instance⟩ lemma two_le_iff : (2 : cardinal) ≤ mk α ↔ ∃x y : α, x ≠ y := begin split, { rintro ⟨f⟩, refine ⟨f $ sum.inl ⟨⟩, f $ sum.inr ⟨⟩, _⟩, intro h, cases f.2 h }, { rintro ⟨x, y, h⟩, by_contra h', rw [not_le, ←nat.cast_two, ←nat_succ, lt_succ, nat.cast_one, le_one_iff_subsingleton] at h', apply h, exactI subsingleton.elim _ _ } end lemma two_le_iff' (x : α) : (2 : cardinal) ≤ mk α ↔ ∃y : α, x ≠ y := begin rw [two_le_iff], split, { rintro ⟨y, z, h⟩, refine classical.by_cases (λ(h' : x = y), _) (λ h', ⟨y, h'⟩), rw [←h'] at h, exact ⟨z, h⟩ }, { rintro ⟨y, h⟩, exact ⟨x, y, h⟩ } end /-- König's theorem -/ theorem sum_lt_prod {ι} (f g : ι → cardinal) (H : ∀ i, f i < g i) : sum f < prod g := lt_of_not_ge $ λ ⟨F⟩, begin have : inhabited (Π (i : ι), (g i).out), { refine ⟨λ i, classical.choice $ ne_zero_iff_nonempty.1 _⟩, rw mk_out, exact ne_of_gt (lt_of_le_of_lt (zero_le _) (H i)) }, resetI, let G := inv_fun F, have sG : surjective G := inv_fun_surjective F.2, choose C hc using show ∀ i, ∃ b, ∀ a, G ⟨i, a⟩ i ≠ b, { assume i, simp only [- not_exists, not_exists.symm, classical.not_forall.symm], refine λ h, not_le_of_lt (H i) _, rw [← mk_out (f i), ← mk_out (g i)], exact ⟨embedding.of_surjective h⟩ }, exact (let ⟨⟨i, a⟩, h⟩ := sG C in hc i a (congr_fun h _)) end @[simp] theorem mk_empty : mk empty = 0 := fintype_card empty @[simp] theorem mk_pempty : mk pempty = 0 := fintype_card pempty @[simp] theorem mk_plift_of_false {p : Prop} (h : ¬ p) : mk (plift p) = 0 := quotient.sound ⟨equiv.plift.trans $ equiv.equiv_pempty h⟩ @[simp] theorem mk_unit : mk unit = 1 := (fintype_card unit).trans nat.cast_one @[simp] theorem mk_punit : mk punit = 1 := (fintype_card punit).trans nat.cast_one @[simp] theorem mk_singleton {α : Type u} (x : α) : mk ({x} : set α) = 1 := quotient.sound ⟨equiv.set.singleton x⟩ @[simp] theorem mk_plift_of_true {p : Prop} (h : p) : mk (plift p) = 1 := quotient.sound ⟨equiv.plift.trans $ equiv.prop_equiv_punit h⟩ @[simp] theorem mk_bool : mk bool = 2 := quotient.sound ⟨equiv.bool_equiv_punit_sum_punit⟩ @[simp] theorem mk_Prop : mk Prop = 2 := (quotient.sound ⟨equiv.Prop_equiv_bool⟩ : mk Prop = mk bool).trans mk_bool @[simp] theorem mk_option {α : Type u} : mk (option α) = mk α + 1 := quotient.sound ⟨equiv.option_equiv_sum_punit α⟩ theorem mk_list_eq_sum_pow (α : Type u) : mk (list α) = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) := calc mk (list α) = mk (Σ n, vector α n) : quotient.sound ⟨equiv.equiv_sigma_subtype list.length⟩ ... = mk (Σ n, fin n → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n, ⟨vector.nth, vector.of_fn, vector.of_fn_nth, λ f, funext $ vector.nth_of_fn f⟩⟩ ... = mk (Σ n : ℕ, ulift.{u} (fin n) → α) : quotient.sound ⟨equiv.sigma_congr_right $ λ n, equiv.arrow_congr equiv.ulift.symm (equiv.refl α)⟩ ... = sum (λ n : ℕ, (mk α)^(n:cardinal.{u})) : by simp only [(lift_mk_fin _).symm, lift_mk, power_def, sum_mk] theorem mk_quot_le {α : Type u} {r : α → α → Prop} : mk (quot r) ≤ mk α := mk_le_of_surjective quot.exists_rep theorem mk_quotient_le {α : Type u} {s : setoid α} : mk (quotient s) ≤ mk α := mk_quot_le theorem mk_subtype_le {α : Type u} {s : set α} : mk s ≤ mk α := mk_le_of_injective subtype.val_injective @[simp] theorem mk_emptyc (α : Type u) : mk (∅ : set α) = 0 := quotient.sound ⟨equiv.set.pempty α⟩ theorem mk_univ {α : Type u} : mk (@univ α) = mk α := quotient.sound ⟨equiv.set.univ α⟩ theorem mk_image_le {α β : Type u} {f : α → β} {s : set α} : mk (f '' s) ≤ mk s := mk_le_of_surjective surjective_onto_image theorem mk_range_le {α β : Type u} {f : α → β} : mk (range f) ≤ mk α := mk_le_of_surjective surjective_onto_range lemma mk_range_eq (f : α → β) (h : injective f) : mk (range f) = mk α := quotient.sound ⟨(equiv.set.range f h).symm⟩ lemma mk_range_eq_of_inj {α : Type u} {β : Type v} {f : α → β} (hf : injective f) : lift.{v u} (mk (range f)) = lift.{u v} (mk α) := begin have := (@lift_mk_eq.{v u max u v} (range f) α).2 ⟨(equiv.set.range f hf).symm⟩, simp only [lift_umax.{u v}, lift_umax.{v u}] at this, exact this end theorem mk_image_eq {α β : Type u} {f : α → β} {s : set α} (hf : injective f) : mk (f '' s) = mk s := quotient.sound ⟨(equiv.set.image f s hf).symm⟩ theorem mk_Union_le_sum_mk {α ι : Type u} {f : ι → set α} : mk (⋃ i, f i) ≤ sum (λ i, mk (f i)) := calc mk (⋃ i, f i) ≤ mk (Σ i, f i) : mk_le_of_surjective (set.surjective_sigma_to_Union f) ... = sum (λ i, mk (f i)) : (sum_mk _).symm theorem mk_Union_eq_sum_mk {α ι : Type u} {f : ι → set α} (h : ∀i j, i ≠ j → disjoint (f i) (f j)) : mk (⋃ i, f i) = sum (λ i, mk (f i)) := calc mk (⋃ i, f i) = mk (Σi, f i) : quot.sound ⟨set.Union_eq_sigma_of_disjoint h⟩ ... = sum (λi, mk (f i)) : (sum_mk _).symm lemma mk_Union_le {α ι : Type u} (f : ι → set α) : mk (⋃ i, f i) ≤ mk ι * cardinal.sup.{u u} (λ i, mk (f i)) := le_trans mk_Union_le_sum_mk (sum_le_sup _) lemma mk_sUnion_le {α : Type u} (A : set (set α)) : mk (⋃₀ A) ≤ mk A * cardinal.sup.{u u} (λ s : A, mk s) := by { rw [sUnion_eq_Union], apply mk_Union_le } lemma mk_bUnion_le {ι α : Type u} (A : ι → set α) (s : set ι) : mk (⋃(x ∈ s), A x) ≤ mk s * cardinal.sup.{u u} (λ x : s, mk (A x.1)) := by { rw [bUnion_eq_Union], apply mk_Union_le } @[simp] lemma finset_card {α : Type u} {s : finset α} : ↑(finset.card s) = mk (↑s : set α) := by rw [fintype_card, nat_cast_inj, fintype.card_coe] lemma finset_card_lt_omega (s : finset α) : mk (↑s : set α) < omega := by { rw [lt_omega_iff_fintype], exact ⟨finset.subtype.fintype s⟩ } theorem mk_union_add_mk_inter {α : Type u} {S T : set α} : mk (S ∪ T : set α) + mk (S ∩ T : set α) = mk S + mk T := quot.sound ⟨equiv.set.union_sum_inter S T⟩ theorem mk_union_of_disjoint {α : Type u} {S T : set α} (H : disjoint S T) : mk (S ∪ T : set α) = mk S + mk T := quot.sound ⟨equiv.set.union (disjoint_iff.1 H)⟩ lemma mk_le_mk_of_subset {α} {s t : set α} (h : s ⊆ t) : mk s ≤ mk t := ⟨ set.embedding_of_subset h ⟩ lemma mk_subtype_mono {p q : α → Prop} (h : ∀x, p x → q x) : mk {x // p x} ≤ mk {x // q x} := ⟨embedding_of_subset h⟩ lemma mk_set_le (s : set α) : mk s ≤ mk α := ⟨⟨subtype.val, subtype.val_injective⟩⟩ lemma mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : injective f) : lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) := lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image f s h).symm⟩ lemma mk_image_eq_of_inj_on_lift {α : Type u} {β : Type v} (f : α → β) (s : set α) (h : inj_on f s) : lift.{v u} (mk (f '' s)) = lift.{u v} (mk s) := lift_mk_eq.{v u 0}.mpr ⟨(equiv.set.image_of_inj_on f s h).symm⟩ lemma mk_image_eq_of_inj_on {α β : Type u} (f : α → β) (s : set α) (h : inj_on f s) : mk (f '' s) = mk s := quotient.sound ⟨(equiv.set.image_of_inj_on f s h).symm⟩ lemma mk_subtype_of_equiv {α β : Type u} (p : α → Prop) (e : α ≃ β) : mk {a : α // p a} = mk {b : β // p (e.symm b)} := quotient.sound ⟨equiv.subtype_equiv_of_subtype' e⟩ lemma mk_sep (s : set α) (t : α → Prop) : mk ({ x ∈ s | t x } : set α) = mk { x : s | t x.1 } := quotient.sound ⟨equiv.set.sep s t⟩ lemma mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : set β) (h : injective f) : lift.{u v} (mk (f ⁻¹' s)) ≤ lift.{v u} (mk s) := begin rw lift_mk_le.{u v 0}, use subtype.coind (λ x, f x.1) (λ x, x.2), apply subtype.coind_injective, exact injective_comp h subtype.val_injective end lemma mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : set β) (h : s ⊆ range f) : lift.{v u} (mk s) ≤ lift.{u v} (mk (f ⁻¹' s)) := begin rw lift_mk_le.{v u 0}, refine ⟨⟨_, _⟩⟩, { rintro ⟨y, hy⟩, rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩, exact ⟨x, hy⟩ }, rintro ⟨y, hy⟩ ⟨y', hy'⟩, dsimp, rcases classical.subtype_of_exists (h hy) with ⟨x, rfl⟩, rcases classical.subtype_of_exists (h hy') with ⟨x', rfl⟩, simp, intro hxx', rw hxx' end lemma mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : set β) (h : injective f) (h2 : s ⊆ range f) : lift.{u v} (mk (f ⁻¹' s)) = lift.{v u} (mk s) := le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2) lemma mk_preimage_of_injective (f : α → β) (s : set β) (h : injective f) : mk (f ⁻¹' s) ≤ mk s := by { convert mk_preimage_of_injective_lift.{u u} f s h using 1; rw [lift_id] } lemma mk_preimage_of_subset_range (f : α → β) (s : set β) (h : s ⊆ range f) : mk s ≤ mk (f ⁻¹' s) := by { convert mk_preimage_of_subset_range_lift.{u u} f s h using 1; rw [lift_id] } lemma mk_preimage_of_injective_of_subset_range (f : α → β) (s : set β) (h : injective f) (h2 : s ⊆ range f) : mk (f ⁻¹' s) = mk s := by { convert mk_preimage_of_injective_of_subset_range_lift.{u u} f s h h2 using 1; rw [lift_id] } lemma mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : set α} {t : set β} (h : t ⊆ f '' s) : lift.{v u} (mk t) ≤ lift.{u v} (mk ({ x ∈ s | f x ∈ t } : set α)) := by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range_lift _ _ h using 1, rw [mk_sep], refl } lemma mk_subset_ge_of_subset_image (f : α → β) {s : set α} {t : set β} (h : t ⊆ f '' s) : mk t ≤ mk ({ x ∈ s | f x ∈ t } : set α) := by { rw [image_eq_range] at h, convert mk_preimage_of_subset_range _ _ h using 1, rw [mk_sep], refl } theorem le_mk_iff_exists_subset {c : cardinal} {α : Type u} {s : set α} : c ≤ mk s ↔ ∃ p : set α, p ⊆ s ∧ mk p = c := begin rw [le_mk_iff_exists_set, ←subtype.exists_set_subtype], apply exists_congr, intro t, rw [mk_image_eq], apply subtype.val_injective end /-- The function α^{<β}, defined to be sup_{γ < β} α^γ. We index over {s : set β.out // mk s < β } instead of {γ // γ < β}, because the latter lives in a higher universe -/ noncomputable def powerlt (α β : cardinal.{u}) : cardinal.{u} := sup.{u u} (λ(s : {s : set β.out // mk s < β}), α ^ mk.{u} s) infix ` ^< `:80 := powerlt theorem powerlt_aux {c c' : cardinal} (h : c < c') : ∃(s : {s : set c'.out // mk s < c'}), mk s = c := begin cases out_embedding.mp (le_of_lt h) with f, have : mk ↥(range ⇑f) = c, { rwa [mk_range_eq, mk, quotient.out_eq c], exact f.2 }, exact ⟨⟨range f, by convert h⟩, this⟩ end lemma le_powerlt {c₁ c₂ c₃ : cardinal} (h : c₂ < c₃) : c₁ ^ c₂ ≤ c₁ ^< c₃ := by { rcases powerlt_aux h with ⟨s, rfl⟩, apply le_sup _ s } lemma powerlt_le {c₁ c₂ c₃ : cardinal} : c₁ ^< c₂ ≤ c₃ ↔ ∀(c₄ < c₂), c₁ ^ c₄ ≤ c₃ := begin rw [powerlt, sup_le], split, { intros h c₄ hc₄, rcases powerlt_aux hc₄ with ⟨s, rfl⟩, exact h s }, intros h s, exact h _ s.2 end lemma powerlt_le_powerlt_left {a b c : cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c := by { rw [powerlt, sup_le], rintro ⟨s, hs⟩, apply le_powerlt, exact lt_of_lt_of_le hs h } lemma powerlt_succ {c₁ c₂ : cardinal} (h : c₁ ≠ 0) : c₁ ^< c₂.succ = c₁ ^ c₂ := begin apply le_antisymm, { rw powerlt_le, intros c₃ h2, apply power_le_power_left h, rwa [←lt_succ] }, { apply le_powerlt, apply lt_succ_self } end lemma powerlt_max {c₁ c₂ c₃ : cardinal} : c₁ ^< max c₂ c₃ = max (c₁ ^< c₂) (c₁ ^< c₃) := by { cases le_total c₂ c₃; simp only [max_eq_left, max_eq_right, h, powerlt_le_powerlt_left] } lemma zero_powerlt {a : cardinal} (h : a ≠ 0) : 0 ^< a = 1 := begin apply le_antisymm, { rw [powerlt_le], intros c hc, apply zero_power_le }, convert le_powerlt (pos_iff_ne_zero.2 h), rw [power_zero] end lemma powerlt_zero {a : cardinal} : a ^< 0 = 0 := by { apply sup_eq_zero, rintro ⟨x, hx⟩, rw [←not_le] at hx, apply hx, apply zero_le } end cardinal
bc8abfa719e7cf8f313896f1c2887d07b160f698
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/blast19.lean
32ff2b8a6544962238ccbe9c1cca519e903a60f4
[ "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
568
lean
-- Backward chaining with hypotheses set_option blast.strategy "backward" constants {P Q R S T U : Prop} constants (Huq : U → Q) (Hur : U → R) (Hus : U → S) (Hut : U → T) attribute Huq [intro] attribute Hur [intro] attribute Hus [intro] attribute Hut [intro] definition lemma1 : (P → Q) → P → Q := by blast definition lemma2 : (P → Q) → (Q → R) → P → R := by blast definition lemma3 : (P → Q) → (Q → R) → (R → S) → P → S := by blast definition lemma4 : (P → Q) → (Q → R) → (R → S) → (S → T) → P → T := by blast
5ed40a2aa2223fed22148dc18850107bc25ae39f
e9dbaaae490bc072444e3021634bf73664003760
/src/Problems/2010/IMO_2010_P2.lean
ac6eb9df0c620083a3a7107b0c5eef27cd0ed7ac
[ "Apache-2.0" ]
permissive
liaofei1128/geometry
566d8bfe095ce0c0113d36df90635306c60e975b
3dd128e4eec8008764bb94e18b932f9ffd66e6b3
refs/heads/master
1,678,996,510,399
1,581,454,543,000
1,583,337,839,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
562
lean
import Geo.Geo.Core namespace Geo open Angle Triangle def IMO_2010_P2 : Prop := ∀ (A B C D E F : Point), let I := incenter ⟨A, B, C⟩; let Γ := Triangle.circumcircle ⟨A, B, C⟩; intersectAt₂ (Line.mk A I) Γ A D → on E (Arc.mk Γ B C A) → -- ryankrue: note the utility of the avoid construction here on F (Seg.mk B C) → uangle ⟨B, A, F⟩ = uangle ⟨C, A, E⟩ → uangle ⟨C, A, E⟩ < (uangle ⟨B, A, C⟩).divNat 2 → -- TODO: notation for divNat let G := (Seg.mk I F).midp; allIntersect₂ [Line.mk D G, Line.mk E I] [Γ] end Geo
51bdbf4e30380d7766c38e638819952550f1b387
367134ba5a65885e863bdc4507601606690974c1
/src/topology/sheaves/stalks.lean
4f7b431f3e1407c9156289a3b460295500687e9c
[ "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
6,786
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.category.Top.open_nhds import topology.sheaves.presheaf import category_theory.limits.limits import category_theory.limits.types noncomputable theory universes v u v' u' open category_theory open Top open category_theory.limits open topological_space open opposite variables {C : Type u} [category.{v} C] variables [has_colimits.{v} C] variables {X Y Z : Top.{v}} namespace Top.presheaf variables (C) /-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/ def stalk_functor (x : X) : X.presheaf C ⥤ C := ((whiskering_left _ _ C).obj (open_nhds.inclusion x).op) ⋙ colim variables {C} /-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor nbhds x ⥤ opens F.X ⥤ C -/ def stalk (ℱ : X.presheaf C) (x : X) : C := (stalk_functor C x).obj ℱ -- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ) @[simp] lemma stalk_functor_obj (ℱ : X.presheaf C) (x : X) : (stalk_functor C x).obj ℱ = ℱ.stalk x := rfl /-- The germ of a section of a presheaf over an open at a point of that open. -/ def germ (F : X.presheaf C) {U : opens X} (x : U) : F.obj (op U) ⟶ stalk F x := colimit.ι ((open_nhds.inclusion x.1).op ⋙ F) (op ⟨U, x.2⟩) /-- For a `Type` valued presheaf, every point in a stalk is a germ. -/ lemma germ_exist (F : X.presheaf (Type v)) (x : X) (t : stalk F x) : ∃ (U : opens X) (m : x ∈ U) (s : F.obj (op U)), F.germ ⟨x, m⟩ s = t := begin obtain ⟨U, s, e⟩ := types.jointly_surjective _ (colimit.is_colimit _) t, revert s e, rw [(show U = op (unop U), from rfl)], generalize : unop U = V, clear U, cases V with V m, intros s e, exact ⟨V, m, s, e⟩, end lemma germ_eq (F : X.presheaf (Type v)) {U V : opens X} (x : X) (mU : x ∈ U) (mV : x ∈ V) (s : F.obj (op U)) (t : F.obj (op V)) (h : germ F ⟨x, mU⟩ s = germ F ⟨x, mV⟩ t) : ∃ (W : opens X) (m : x ∈ W) (iU : W ⟶ U) (iV : W ⟶ V), F.map iU.op s = F.map iV.op t := begin erw types.filtered_colimit.colimit_eq_iff at h, rcases h with ⟨W, iU, iV, e⟩, exact ⟨(unop W).1, (unop W).2, iU.unop, iV.unop, e⟩, end @[simp] lemma germ_res (F : X.presheaf C) {U V : opens X} (i : U ⟶ V) (x : U) : F.map i.op ≫ germ F x = germ F (i x : V) := let i' : (⟨U, x.2⟩ : open_nhds x.1) ⟶ ⟨V, (i x : V).2⟩ := i in colimit.w ((open_nhds.inclusion x.1).op ⋙ F) i'.op @[simp] lemma germ_res_apply (F : X.presheaf (Type v)) {U V : opens X} (i : U ⟶ V) (x : U) (f : F.obj (op V)) : germ F x (F.map i.op f) = germ F (i x : V) f := let i' : (⟨U, x.2⟩ : open_nhds x.1) ⟶ ⟨V, (i x : V).2⟩ := i in congr_fun (colimit.w ((open_nhds.inclusion x.1).op ⋙ F) i'.op) f /-- A variant when the open sets are written in `(opens X)ᵒᵖ`. -/ @[simp] lemma germ_res_apply' (F : X.presheaf (Type v)) {U V : (opens X)ᵒᵖ} (i : V ⟶ U) (x : unop U) (f : F.obj V) : germ F x (F.map i f) = germ F (i.unop x : unop V) f := let i' : (⟨unop U, x.2⟩ : open_nhds x.1) ⟶ ⟨unop V, (i.unop x : unop V).2⟩ := i.unop in congr_fun (colimit.w ((open_nhds.inclusion x.1).op ⋙ F) i'.op) f section local attribute [instance] concrete_category.has_coe_to_sort concrete_category.has_coe_to_fun @[ext] lemma germ_ext {D : Type u} [category.{v} D] [concrete_category D] [has_colimits D] (F : X.presheaf D) {U V : opens X} {x : X} {hxU : x ∈ U} {hxV : x ∈ V} (W : opens X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V) {sU : F.obj (op U)} {sV : F.obj (op V)} (ih : F.map iWU.op sU = F.map iWV.op sV) : F.germ ⟨x, hxU⟩ sU = F.germ ⟨x, hxV⟩ sV := by erw [← F.germ_res iWU ⟨x, hxW⟩, ← F.germ_res iWV ⟨x, hxW⟩, coe_comp, coe_comp, ih] end lemma stalk_hom_ext (F : X.presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y} (ih : ∀ (U : opens X) (hxU : x ∈ U), F.germ ⟨x, hxU⟩ ≫ f₁ = F.germ ⟨x, hxU⟩ ≫ f₂) : f₁ = f₂ := colimit.hom_ext $ λ U, by { op_induction U, cases U with U hxU, exact ih U hxU } variables (C) def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := begin -- This is a hack; Lean doesn't like to elaborate the term written directly. transitivity, swap, exact colimit.pre _ (open_nhds.map f x).op, exact colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ), end -- Here are two other potential solutions, suggested by @fpvandoorn at -- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240> -- However, I can't get the subsequent two proofs to work with either one. -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- colim.map ((functor.associator _ _ _).inv ≫ -- whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op -- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x := -- (colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) : -- colim.obj ((open_nhds.inclusion (f x) ⋙ opens.map f).op ⋙ ℱ) ⟶ _) ≫ -- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op namespace stalk_pushforward local attribute [tidy] tactic.op_induction' @[simp] lemma id (ℱ : X.presheaf C) (x : X) : ℱ.stalk_pushforward C (𝟙 X) x = (stalk_functor C x).map ((pushforward.id ℱ).hom) := begin dsimp [stalk_pushforward, stalk_functor], ext1, tactic.op_induction', cases j, cases j_val, rw [colimit.ι_map_assoc, colimit.ι_map, colimit.ι_pre, whisker_left_app, whisker_right_app, pushforward.id_hom_app, eq_to_hom_map, eq_to_hom_refl], dsimp, -- FIXME A simp lemma which unfortunately doesn't fire: erw [category_theory.functor.map_id], end -- This proof is sadly not at all robust: -- having to use `erw` at all is a bad sign. @[simp] lemma comp (ℱ : X.presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : ℱ.stalk_pushforward C (f ≫ g) x = ((f _* ℱ).stalk_pushforward C g (f x)) ≫ (ℱ.stalk_pushforward C f x) := begin dsimp [stalk_pushforward, stalk_functor], ext U, op_induction U, cases U, cases U_val, simp only [colimit.ι_map_assoc, colimit.ι_pre_assoc, whisker_right_app, category.assoc], dsimp, -- FIXME: Some of these are simp lemmas, but don't fire successfully: erw [category_theory.functor.map_id, category.id_comp, category.id_comp, category.id_comp, colimit.ι_pre, colimit.ι_pre], refl, end end stalk_pushforward end Top.presheaf
a7ada9e0d2cc87f1b4fd475fc5f6edbee5376a09
c777c32c8e484e195053731103c5e52af26a25d1
/src/measure_theory/integral/bochner.lean
82ee783fd13b7318eb396d75bae800e70c8a3587
[ "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
84,629
lean
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov, Sébastien Gouëzel, Rémy Degenne -/ import measure_theory.integral.set_to_l1 /-! # Bochner integral The Bochner integral extends the definition of the Lebesgue integral to functions that map from a measure space into a Banach space (complete normed vector space). It is constructed here by extending the integral on simple functions. ## Main definitions The Bochner integral is defined through the extension process described in the file `set_to_L1`, which follows these steps: 1. Define the integral of the indicator of a set. This is `weighted_smul μ s x = (μ s).to_real * x`. `weighted_smul μ` is shown to be linear in the value `x` and `dominated_fin_meas_additive` (defined in the file `set_to_L1`) with respect to the set `s`. 2. Define the integral on simple functions of the type `simple_func α E` (notation : `α →ₛ E`) where `E` is a real normed space. (See `simple_func.integral` for details.) 3. Transfer this definition to define the integral on `L1.simple_func α E` (notation : `α →₁ₛ[μ] E`), see `L1.simple_func.integral`. Show that this integral is a continuous linear map from `α →₁ₛ[μ] E` to `E`. 4. Define the Bochner integral on L1 functions by extending the integral on integrable simple functions `α →₁ₛ[μ] E` using `continuous_linear_map.extend` and the fact that the embedding of `α →₁ₛ[μ] E` into `α →₁[μ] E` is dense. 5. Define the Bochner integral on functions as the Bochner integral of its equivalence class in L1 space, if it is in L1, and 0 otherwise. The result of that construction is `∫ a, f a ∂μ`, which is definitionally equal to `set_to_fun (dominated_fin_meas_additive_weighted_smul μ) f`. Some basic properties of the integral (like linearity) are particular cases of the properties of `set_to_fun` (which are described in the file `set_to_L1`). ## Main statements 1. Basic properties of the Bochner integral on functions of type `α → E`, where `α` is a measure space and `E` is a real normed space. * `integral_zero` : `∫ 0 ∂μ = 0` * `integral_add` : `∫ x, f x + g x ∂μ = ∫ x, f ∂μ + ∫ x, g x ∂μ` * `integral_neg` : `∫ x, - f x ∂μ = - ∫ x, f x ∂μ` * `integral_sub` : `∫ x, f x - g x ∂μ = ∫ x, f x ∂μ - ∫ x, g x ∂μ` * `integral_smul` : `∫ x, r • f x ∂μ = r • ∫ x, f x ∂μ` * `integral_congr_ae` : `f =ᵐ[μ] g → ∫ x, f x ∂μ = ∫ x, g x ∂μ` * `norm_integral_le_integral_norm` : `‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ` 2. Basic properties of the Bochner integral on functions of type `α → ℝ`, where `α` is a measure space. * `integral_nonneg_of_ae` : `0 ≤ᵐ[μ] f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos_of_ae` : `f ≤ᵐ[μ] 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono_ae` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` * `integral_nonneg` : `0 ≤ f → 0 ≤ ∫ x, f x ∂μ` * `integral_nonpos` : `f ≤ 0 → ∫ x, f x ∂μ ≤ 0` * `integral_mono` : `f ≤ᵐ[μ] g → ∫ x, f x ∂μ ≤ ∫ x, g x ∂μ` 3. Propositions connecting the Bochner integral with the integral on `ℝ≥0∞`-valued functions, which is called `lintegral` and has the notation `∫⁻`. * `integral_eq_lintegral_max_sub_lintegral_min` : `∫ x, f x ∂μ = ∫⁻ x, f⁺ x ∂μ - ∫⁻ x, f⁻ x ∂μ`, where `f⁺` is the positive part of `f` and `f⁻` is the negative part of `f`. * `integral_eq_lintegral_of_nonneg_ae` : `0 ≤ᵐ[μ] f → ∫ x, f x ∂μ = ∫⁻ x, f x ∂μ` 4. `tendsto_integral_of_dominated_convergence` : the Lebesgue dominated convergence theorem 5. (In the file `set_integral`) integration commutes with continuous linear maps. * `continuous_linear_map.integral_comp_comm` * `linear_isometry.integral_comp_comm` ## Notes Some tips on how to prove a proposition if the API for the Bochner integral is not enough so that you need to unfold the definition of the Bochner integral and go back to simple functions. One method is to use the theorem `integrable.induction` in the file `simple_func_dense_lp` (or one of the related results, like `Lp.induction` for functions in `Lp`), which allows you to prove something for an arbitrary integrable function. Another method is using the following steps. See `integral_eq_lintegral_max_sub_lintegral_min` for a complicated example, which proves that `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, with the first integral sign being the Bochner integral of a real-valued function `f : α → ℝ`, and second and third integral sign being the integral on `ℝ≥0∞`-valued functions (called `lintegral`). The proof of `integral_eq_lintegral_max_sub_lintegral_min` is scattered in sections with the name `pos_part`. Here are the usual steps of proving that a property `p`, say `∫ f = ∫⁻ f⁺ - ∫⁻ f⁻`, holds for all functions : 1. First go to the `L¹` space. For example, if you see `ennreal.to_real (∫⁻ a, ennreal.of_real $ ‖f a‖)`, that is the norm of `f` in `L¹` space. Rewrite using `L1.norm_of_fun_eq_lintegral_norm`. 2. Show that the set `{f ∈ L¹ | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻}` is closed in `L¹` using `is_closed_eq`. 3. Show that the property holds for all simple functions `s` in `L¹` space. Typically, you need to convert various notions to their `simple_func` counterpart, using lemmas like `L1.integral_coe_eq_integral`. 4. Since simple functions are dense in `L¹`, ``` univ = closure {s simple} = closure {s simple | ∫ s = ∫⁻ s⁺ - ∫⁻ s⁻} : the property holds for all simple functions ⊆ closure {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} = {f | ∫ f = ∫⁻ f⁺ - ∫⁻ f⁻} : closure of a closed set is itself ``` Use `is_closed_property` or `dense_range.induction_on` for this argument. ## Notations * `α →ₛ E` : simple functions (defined in `measure_theory/integration`) * `α →₁[μ] E` : functions in L1 space, i.e., equivalence classes of integrable functions (defined in `measure_theory/lp_space`) * `α →₁ₛ[μ] E` : simple functions in L1 space, i.e., equivalence classes of integrable simple functions (defined in `measure_theory/simple_func_dense`) * `∫ a, f a ∂μ` : integral of `f` with respect to a measure `μ` * `∫ a, f a` : integral of `f` with respect to `volume`, the default measure on the ambient type We also define notations for integral on a set, which are described in the file `measure_theory/set_integral`. Note : `ₛ` is typed using `\_s`. Sometimes it shows as a box if the font is missing. ## Tags Bochner integral, simple function, function space, Lebesgue dominated convergence theorem -/ noncomputable theory open_locale topology big_operators nnreal ennreal measure_theory open set filter topological_space ennreal emetric namespace measure_theory variables {α E F 𝕜 : Type*} section weighted_smul open continuous_linear_map variables [normed_add_comm_group F] [normed_space ℝ F] {m : measurable_space α} {μ : measure α} /-- Given a set `s`, return the continuous linear map `λ x, (μ s).to_real • x`. The extension of that set function through `set_to_L1` gives the Bochner integral of L1 functions. -/ def weighted_smul {m : measurable_space α} (μ : measure α) (s : set α) : F →L[ℝ] F := (μ s).to_real • (continuous_linear_map.id ℝ F) lemma weighted_smul_apply {m : measurable_space α} (μ : measure α) (s : set α) (x : F) : weighted_smul μ s x = (μ s).to_real • x := by simp [weighted_smul] @[simp] lemma weighted_smul_zero_measure {m : measurable_space α} : weighted_smul (0 : measure α) = (0 : set α → F →L[ℝ] F) := by { ext1, simp [weighted_smul], } @[simp] lemma weighted_smul_empty {m : measurable_space α} (μ : measure α) : weighted_smul μ ∅ = (0 : F →L[ℝ] F) := by { ext1 x, rw [weighted_smul_apply], simp, } lemma weighted_smul_add_measure {m : measurable_space α} (μ ν : measure α) {s : set α} (hμs : μ s ≠ ∞) (hνs : ν s ≠ ∞) : (weighted_smul (μ + ν) s : F →L[ℝ] F) = weighted_smul μ s + weighted_smul ν s := begin ext1 x, push_cast, simp_rw [pi.add_apply, weighted_smul_apply], push_cast, rw [pi.add_apply, ennreal.to_real_add hμs hνs, add_smul], end lemma weighted_smul_smul_measure {m : measurable_space α} (μ : measure α) (c : ℝ≥0∞) {s : set α} : (weighted_smul (c • μ) s : F →L[ℝ] F) = c.to_real • weighted_smul μ s := begin ext1 x, push_cast, simp_rw [pi.smul_apply, weighted_smul_apply], push_cast, simp_rw [pi.smul_apply, smul_eq_mul, to_real_mul, smul_smul], end lemma weighted_smul_congr (s t : set α) (hst : μ s = μ t) : (weighted_smul μ s : F →L[ℝ] F) = weighted_smul μ t := by { ext1 x, simp_rw weighted_smul_apply, congr' 2, } lemma weighted_smul_null {s : set α} (h_zero : μ s = 0) : (weighted_smul μ s : F →L[ℝ] F) = 0 := by { ext1 x, rw [weighted_smul_apply, h_zero], simp, } lemma weighted_smul_union' (s t : set α) (ht : measurable_set t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weighted_smul μ (s ∪ t) : F →L[ℝ] F) = weighted_smul μ s + weighted_smul μ t := begin ext1 x, simp_rw [add_apply, weighted_smul_apply, measure_union (set.disjoint_iff_inter_eq_empty.mpr h_inter) ht, ennreal.to_real_add hs_finite ht_finite, add_smul], end @[nolint unused_arguments] lemma weighted_smul_union (s t : set α) (hs : measurable_set s) (ht : measurable_set t) (hs_finite : μ s ≠ ∞) (ht_finite : μ t ≠ ∞) (h_inter : s ∩ t = ∅) : (weighted_smul μ (s ∪ t) : F →L[ℝ] F) = weighted_smul μ s + weighted_smul μ t := weighted_smul_union' s t ht hs_finite ht_finite h_inter lemma weighted_smul_smul [normed_field 𝕜] [normed_space 𝕜 F] [smul_comm_class ℝ 𝕜 F] (c : 𝕜) (s : set α) (x : F) : weighted_smul μ s (c • x) = c • weighted_smul μ s x := by { simp_rw [weighted_smul_apply, smul_comm], } lemma norm_weighted_smul_le (s : set α) : ‖(weighted_smul μ s : F →L[ℝ] F)‖ ≤ (μ s).to_real := calc ‖(weighted_smul μ s : F →L[ℝ] F)‖ = ‖(μ s).to_real‖ * ‖continuous_linear_map.id ℝ F‖ : norm_smul _ _ ... ≤ ‖(μ s).to_real‖ : (mul_le_mul_of_nonneg_left norm_id_le (norm_nonneg _)).trans (mul_one _).le ... = abs (μ s).to_real : real.norm_eq_abs _ ... = (μ s).to_real : abs_eq_self.mpr ennreal.to_real_nonneg lemma dominated_fin_meas_additive_weighted_smul {m : measurable_space α} (μ : measure α) : dominated_fin_meas_additive μ (weighted_smul μ : set α → F →L[ℝ] F) 1 := ⟨weighted_smul_union, λ s _ _, (norm_weighted_smul_le s).trans (one_mul _).symm.le⟩ lemma weighted_smul_nonneg (s : set α) (x : ℝ) (hx : 0 ≤ x) : 0 ≤ weighted_smul μ s x := begin simp only [weighted_smul, algebra.id.smul_eq_mul, coe_smul', id.def, coe_id', pi.smul_apply], exact mul_nonneg to_real_nonneg hx, end end weighted_smul local infixr ` →ₛ `:25 := simple_func namespace simple_func section pos_part variables [linear_order E] [has_zero E] [measurable_space α] /-- Positive part of a simple function. -/ def pos_part (f : α →ₛ E) : α →ₛ E := f.map (λ b, max b 0) /-- Negative part of a simple function. -/ def neg_part [has_neg E] (f : α →ₛ E) : α →ₛ E := pos_part (-f) lemma pos_part_map_norm (f : α →ₛ ℝ) : (pos_part f).map norm = pos_part f := by { ext, rw [map_apply, real.norm_eq_abs, abs_of_nonneg], exact le_max_right _ _ } lemma neg_part_map_norm (f : α →ₛ ℝ) : (neg_part f).map norm = neg_part f := by { rw neg_part, exact pos_part_map_norm _ } lemma pos_part_sub_neg_part (f : α →ₛ ℝ) : f.pos_part - f.neg_part = f := begin simp only [pos_part, neg_part], ext a, rw coe_sub, exact max_zero_sub_eq_self (f a) end end pos_part section integral /-! ### The Bochner integral of simple functions Define the Bochner integral of simple functions of the type `α →ₛ β` where `β` is a normed group, and prove basic property of this integral. -/ open finset variables [normed_add_comm_group E] [normed_add_comm_group F] [normed_space ℝ F] {p : ℝ≥0∞} {G F' : Type*} [normed_add_comm_group G] [normed_add_comm_group F'] [normed_space ℝ F'] {m : measurable_space α} {μ : measure α} /-- Bochner integral of simple functions whose codomain is a real `normed_space`. This is equal to `∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x` (see `integral_eq`). -/ def integral {m : measurable_space α} (μ : measure α) (f : α →ₛ F) : F := f.set_to_simple_func (weighted_smul μ) lemma integral_def {m : measurable_space α} (μ : measure α) (f : α →ₛ F) : f.integral μ = f.set_to_simple_func (weighted_smul μ) := rfl lemma integral_eq {m : measurable_space α} (μ : measure α) (f : α →ₛ F) : f.integral μ = ∑ x in f.range, (μ (f ⁻¹' {x})).to_real • x := by simp [integral, set_to_simple_func, weighted_smul_apply] lemma integral_eq_sum_filter [decidable_pred (λ x : F, x ≠ 0)] {m : measurable_space α} (f : α →ₛ F) (μ : measure α) : f.integral μ = ∑ x in f.range.filter (λ x, x ≠ 0), (μ (f ⁻¹' {x})).to_real • x := by { rw [integral_def, set_to_simple_func_eq_sum_filter], simp_rw weighted_smul_apply, congr } /-- The Bochner integral is equal to a sum over any set that includes `f.range` (except `0`). -/ lemma integral_eq_sum_of_subset [decidable_pred (λ x : F, x ≠ 0)] {f : α →ₛ F} {s : finset F} (hs : f.range.filter (λ x, x ≠ 0) ⊆ s) : f.integral μ = ∑ x in s, (μ (f ⁻¹' {x})).to_real • x := begin rw [simple_func.integral_eq_sum_filter, finset.sum_subset hs], rintro x - hx, rw [finset.mem_filter, not_and_distrib, ne.def, not_not] at hx, rcases hx with hx|rfl; [skip, simp], rw [simple_func.mem_range] at hx, rw [preimage_eq_empty]; simp [set.disjoint_singleton_left, hx] end @[simp] lemma integral_const {m : measurable_space α} (μ : measure α) (y : F) : (const α y).integral μ = (μ univ).to_real • y := by classical; calc (const α y).integral μ = ∑ z in {y}, (μ ((const α y) ⁻¹' {z})).to_real • z : integral_eq_sum_of_subset $ (filter_subset _ _).trans (range_const_subset _ _) ... = (μ univ).to_real • y : by simp @[simp] lemma integral_piecewise_zero {m : measurable_space α} (f : α →ₛ F) (μ : measure α) {s : set α} (hs : measurable_set s) : (piecewise s hs f 0).integral μ = f.integral (μ.restrict s) := begin classical, refine (integral_eq_sum_of_subset _).trans ((sum_congr rfl $ λ y hy, _).trans (integral_eq_sum_filter _ _).symm), { intros y hy, simp only [mem_filter, mem_range, coe_piecewise, coe_zero, piecewise_eq_indicator, mem_range_indicator] at *, rcases hy with ⟨⟨rfl, -⟩|⟨x, hxs, rfl⟩, h₀⟩, exacts [(h₀ rfl).elim, ⟨set.mem_range_self _, h₀⟩] }, { dsimp, rw [set.piecewise_eq_indicator, indicator_preimage_of_not_mem, measure.restrict_apply (f.measurable_set_preimage _)], exact λ h₀, (mem_filter.1 hy).2 (eq.symm h₀) } end /-- Calculate the integral of `g ∘ f : α →ₛ F`, where `f` is an integrable function from `α` to `E` and `g` is a function from `E` to `F`. We require `g 0 = 0` so that `g ∘ f` is integrable. -/ lemma map_integral (f : α →ₛ E) (g : E → F) (hf : integrable f μ) (hg : g 0 = 0) : (f.map g).integral μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • (g x) := map_set_to_simple_func _ weighted_smul_union hf hg /-- `simple_func.integral` and `simple_func.lintegral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion. See `integral_eq_lintegral` for a simpler version. -/ lemma integral_eq_lintegral' {f : α →ₛ E} {g : E → ℝ≥0∞} (hf : integrable f μ) (hg0 : g 0 = 0) (ht : ∀ b, g b ≠ ∞) : (f.map (ennreal.to_real ∘ g)).integral μ = ennreal.to_real (∫⁻ a, g (f a) ∂μ) := begin have hf' : f.fin_meas_supp μ := integrable_iff_fin_meas_supp.1 hf, simp only [← map_apply g f, lintegral_eq_lintegral], rw [map_integral f _ hf, map_lintegral, ennreal.to_real_sum], { refine finset.sum_congr rfl (λb hb, _), rw [smul_eq_mul, to_real_mul, mul_comm] }, { assume a ha, by_cases a0 : a = 0, { rw [a0, hg0, zero_mul], exact with_top.zero_ne_top }, { apply mul_ne_top (ht a) (hf'.meas_preimage_singleton_ne_zero a0).ne } }, { simp [hg0] } end variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E] lemma integral_congr {f g : α →ₛ E} (hf : integrable f μ) (h : f =ᵐ[μ] g) : f.integral μ = g.integral μ := set_to_simple_func_congr (weighted_smul μ) (λ s hs, weighted_smul_null) weighted_smul_union hf h /-- `simple_func.bintegral` and `simple_func.integral` agree when the integrand has type `α →ₛ ℝ≥0∞`. But since `ℝ≥0∞` is not a `normed_space`, we need some form of coercion. -/ lemma integral_eq_lintegral {f : α →ₛ ℝ} (hf : integrable f μ) (h_pos : 0 ≤ᵐ[μ] f) : f.integral μ = ennreal.to_real (∫⁻ a, ennreal.of_real (f a) ∂μ) := begin have : f =ᵐ[μ] f.map (ennreal.to_real ∘ ennreal.of_real) := h_pos.mono (λ a h, (ennreal.to_real_of_real h).symm), rw [← integral_eq_lintegral' hf], exacts [integral_congr hf this, ennreal.of_real_zero, λ b, ennreal.of_real_ne_top] end lemma integral_add {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) : integral μ (f + g) = integral μ f + integral μ g := set_to_simple_func_add _ weighted_smul_union hf hg lemma integral_neg {f : α →ₛ E} (hf : integrable f μ) : integral μ (-f) = - integral μ f := set_to_simple_func_neg _ weighted_smul_union hf lemma integral_sub {f g : α →ₛ E} (hf : integrable f μ) (hg : integrable g μ) : integral μ (f - g) = integral μ f - integral μ g := set_to_simple_func_sub _ weighted_smul_union hf hg lemma integral_smul (c : 𝕜) {f : α →ₛ E} (hf : integrable f μ) : integral μ (c • f) = c • integral μ f := set_to_simple_func_smul _ weighted_smul_union weighted_smul_smul c hf lemma norm_set_to_simple_func_le_integral_norm (T : set α → E →L[ℝ] F) {C : ℝ} (hT_norm : ∀ s, measurable_set s → μ s < ∞ → ‖T s‖ ≤ C * (μ s).to_real) {f : α →ₛ E} (hf : integrable f μ) : ‖f.set_to_simple_func T‖ ≤ C * (f.map norm).integral μ := calc ‖f.set_to_simple_func T‖ ≤ C * ∑ x in f.range, ennreal.to_real (μ (f ⁻¹' {x})) * ‖x‖ : norm_set_to_simple_func_le_sum_mul_norm_of_integrable T hT_norm f hf ... = C * (f.map norm).integral μ : by { rw map_integral f norm hf norm_zero, simp_rw smul_eq_mul, } lemma norm_integral_le_integral_norm (f : α →ₛ E) (hf : integrable f μ) : ‖f.integral μ‖ ≤ (f.map norm).integral μ := begin refine (norm_set_to_simple_func_le_integral_norm _ (λ s _ _, _) hf).trans (one_mul _).le, exact (norm_weighted_smul_le s).trans (one_mul _).symm.le, end lemma integral_add_measure {ν} (f : α →ₛ E) (hf : integrable f (μ + ν)) : f.integral (μ + ν) = f.integral μ + f.integral ν := begin simp_rw [integral_def], refine set_to_simple_func_add_left' (weighted_smul μ) (weighted_smul ν) (weighted_smul (μ + ν)) (λ s hs hμνs, _) hf, rw [lt_top_iff_ne_top, measure.coe_add, pi.add_apply, ennreal.add_ne_top] at hμνs, rw weighted_smul_add_measure _ _ hμνs.1 hμνs.2, end end integral end simple_func namespace L1 open ae_eq_fun Lp.simple_func Lp variables [normed_add_comm_group E] [normed_add_comm_group F] {m : measurable_space α} {μ : measure α} variables {α E μ} namespace simple_func lemma norm_eq_integral (f : α →₁ₛ[μ] E) : ‖f‖ = ((to_simple_func f).map norm).integral μ := begin rw [norm_eq_sum_mul f, (to_simple_func f).map_integral norm (simple_func.integrable f) norm_zero], simp_rw smul_eq_mul, end section pos_part /-- Positive part of a simple function in L1 space. -/ def pos_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := ⟨Lp.pos_part (f : α →₁[μ] ℝ), begin rcases f with ⟨f, s, hsf⟩, use s.pos_part, simp only [subtype.coe_mk, Lp.coe_pos_part, ← hsf, ae_eq_fun.pos_part_mk, simple_func.pos_part, simple_func.coe_map, mk_eq_mk], end ⟩ /-- Negative part of a simple function in L1 space. -/ def neg_part (f : α →₁ₛ[μ] ℝ) : α →₁ₛ[μ] ℝ := pos_part (-f) @[norm_cast] lemma coe_pos_part (f : α →₁ₛ[μ] ℝ) : (pos_part f : α →₁[μ] ℝ) = Lp.pos_part (f : α →₁[μ] ℝ) := rfl @[norm_cast] lemma coe_neg_part (f : α →₁ₛ[μ] ℝ) : (neg_part f : α →₁[μ] ℝ) = Lp.neg_part (f : α →₁[μ] ℝ) := rfl end pos_part section simple_func_integral /-! ### The Bochner integral of `L1` Define the Bochner integral on `α →₁ₛ[μ] E` by extension from the simple functions `α →₁ₛ[μ] E`, and prove basic properties of this integral. -/ variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space ℝ E] [smul_comm_class ℝ 𝕜 E] {F' : Type*} [normed_add_comm_group F'] [normed_space ℝ F'] local attribute [instance] simple_func.normed_space /-- The Bochner integral over simple functions in L1 space. -/ def integral (f : α →₁ₛ[μ] E) : E := ((to_simple_func f)).integral μ lemma integral_eq_integral (f : α →₁ₛ[μ] E) : integral f = ((to_simple_func f)).integral μ := rfl lemma integral_eq_lintegral {f : α →₁ₛ[μ] ℝ} (h_pos : 0 ≤ᵐ[μ] (to_simple_func f)) : integral f = ennreal.to_real (∫⁻ a, ennreal.of_real ((to_simple_func f) a) ∂μ) := by rw [integral, simple_func.integral_eq_lintegral (simple_func.integrable f) h_pos] lemma integral_eq_set_to_L1s (f : α →₁ₛ[μ] E) : integral f = set_to_L1s (weighted_smul μ) f := rfl lemma integral_congr {f g : α →₁ₛ[μ] E} (h : to_simple_func f =ᵐ[μ] to_simple_func g) : integral f = integral g := simple_func.integral_congr (simple_func.integrable f) h lemma integral_add (f g : α →₁ₛ[μ] E) : integral (f + g) = integral f + integral g := set_to_L1s_add _ (λ _ _, weighted_smul_null) weighted_smul_union _ _ lemma integral_smul (c : 𝕜) (f : α →₁ₛ[μ] E) : integral (c • f) = c • integral f := set_to_L1s_smul _ (λ _ _, weighted_smul_null) weighted_smul_union weighted_smul_smul c f lemma norm_integral_le_norm (f : α →₁ₛ[μ] E) : ‖integral f‖ ≤ ‖f‖ := begin rw [integral, norm_eq_integral], exact (to_simple_func f).norm_integral_le_integral_norm (simple_func.integrable f) end variables {E' : Type*} [normed_add_comm_group E'] [normed_space ℝ E'] [normed_space 𝕜 E'] variables (α E μ 𝕜) /-- The Bochner integral over simple functions in L1 space as a continuous linear map. -/ def integral_clm' : (α →₁ₛ[μ] E) →L[𝕜] E := linear_map.mk_continuous ⟨integral, integral_add, integral_smul⟩ 1 (λf, le_trans (norm_integral_le_norm _) $ by rw one_mul) /-- The Bochner integral over simple functions in L1 space as a continuous linear map over ℝ. -/ def integral_clm : (α →₁ₛ[μ] E) →L[ℝ] E := integral_clm' α E ℝ μ variables {α E μ 𝕜} local notation (name := simple_func.integral_clm) `Integral` := integral_clm α E μ open continuous_linear_map lemma norm_Integral_le_one : ‖Integral‖ ≤ 1 := linear_map.mk_continuous_norm_le _ (zero_le_one) _ section pos_part lemma pos_part_to_simple_func (f : α →₁ₛ[μ] ℝ) : to_simple_func (pos_part f) =ᵐ[μ] (to_simple_func f).pos_part := begin have eq : ∀ a, (to_simple_func f).pos_part a = max ((to_simple_func f) a) 0 := λa, rfl, have ae_eq : ∀ᵐ a ∂μ, to_simple_func (pos_part f) a = max ((to_simple_func f) a) 0, { filter_upwards [to_simple_func_eq_to_fun (pos_part f), Lp.coe_fn_pos_part (f : α →₁[μ] ℝ), to_simple_func_eq_to_fun f] with _ _ h₂ _, convert h₂, }, refine ae_eq.mono (assume a h, _), rw [h, eq], end lemma neg_part_to_simple_func (f : α →₁ₛ[μ] ℝ) : to_simple_func (neg_part f) =ᵐ[μ] (to_simple_func f).neg_part := begin rw [simple_func.neg_part, measure_theory.simple_func.neg_part], filter_upwards [pos_part_to_simple_func (-f), neg_to_simple_func f], assume a h₁ h₂, rw h₁, show max _ _ = max _ _, rw h₂, refl end lemma integral_eq_norm_pos_part_sub (f : α →₁ₛ[μ] ℝ) : integral f = ‖pos_part f‖ - ‖neg_part f‖ := begin -- Convert things in `L¹` to their `simple_func` counterpart have ae_eq₁ : (to_simple_func f).pos_part =ᵐ[μ] (to_simple_func (pos_part f)).map norm, { filter_upwards [pos_part_to_simple_func f] with _ h, rw [simple_func.map_apply, h], conv_lhs { rw [← simple_func.pos_part_map_norm, simple_func.map_apply] } }, -- Convert things in `L¹` to their `simple_func` counterpart have ae_eq₂ : (to_simple_func f).neg_part =ᵐ[μ] (to_simple_func (neg_part f)).map norm, { filter_upwards [neg_part_to_simple_func f] with _ h, rw [simple_func.map_apply, h], conv_lhs { rw [← simple_func.neg_part_map_norm, simple_func.map_apply], }, }, -- Convert things in `L¹` to their `simple_func` counterpart have ae_eq : ∀ᵐ a ∂μ, (to_simple_func f).pos_part a - (to_simple_func f).neg_part a = (to_simple_func (pos_part f)).map norm a - (to_simple_func (neg_part f)).map norm a, { filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂, rw [h₁, h₂], }, rw [integral, norm_eq_integral, norm_eq_integral, ← simple_func.integral_sub], { show (to_simple_func f).integral μ = ((to_simple_func (pos_part f)).map norm - (to_simple_func (neg_part f)).map norm).integral μ, apply measure_theory.simple_func.integral_congr (simple_func.integrable f), filter_upwards [ae_eq₁, ae_eq₂] with _ h₁ h₂, show _ = _ - _, rw [← h₁, ← h₂], have := (to_simple_func f).pos_part_sub_neg_part, conv_lhs {rw ← this}, refl, }, { exact (simple_func.integrable f).pos_part.congr ae_eq₁ }, { exact (simple_func.integrable f).neg_part.congr ae_eq₂ } end end pos_part end simple_func_integral end simple_func open simple_func local notation (name := simple_func.integral_clm) `Integral` := @integral_clm α E _ _ _ _ _ μ _ variables [normed_space ℝ E] [nontrivially_normed_field 𝕜] [normed_space 𝕜 E] [smul_comm_class ℝ 𝕜 E] [normed_space ℝ F] [complete_space E] section integration_in_L1 local attribute [instance] simple_func.normed_space open continuous_linear_map variables (𝕜) /-- The Bochner integral in L1 space as a continuous linear map. -/ def integral_clm' : (α →₁[μ] E) →L[𝕜] E := (integral_clm' α E 𝕜 μ).extend (coe_to_Lp α E 𝕜) (simple_func.dense_range one_ne_top) simple_func.uniform_inducing variables {𝕜} /-- The Bochner integral in L1 space as a continuous linear map over ℝ. -/ def integral_clm : (α →₁[μ] E) →L[ℝ] E := integral_clm' ℝ /-- The Bochner integral in L1 space -/ @[irreducible] def integral (f : α →₁[μ] E) : E := integral_clm f lemma integral_eq (f : α →₁[μ] E) : integral f = integral_clm f := by simp only [integral] lemma integral_eq_set_to_L1 (f : α →₁[μ] E) : integral f = set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f := by { simp only [integral], refl } @[norm_cast] lemma simple_func.integral_L1_eq_integral (f : α →₁ₛ[μ] E) : integral (f : α →₁[μ] E) = (simple_func.integral f) := begin simp only [integral], exact set_to_L1_eq_set_to_L1s_clm (dominated_fin_meas_additive_weighted_smul μ) f end variables (α E) @[simp] lemma integral_zero : integral (0 : α →₁[μ] E) = 0 := begin simp only [integral], exact map_zero integral_clm end variables {α E} lemma integral_add (f g : α →₁[μ] E) : integral (f + g) = integral f + integral g := begin simp only [integral], exact map_add integral_clm f g end lemma integral_neg (f : α →₁[μ] E) : integral (-f) = - integral f := begin simp only [integral], exact map_neg integral_clm f end lemma integral_sub (f g : α →₁[μ] E) : integral (f - g) = integral f - integral g := begin simp only [integral], exact map_sub integral_clm f g end lemma integral_smul (c : 𝕜) (f : α →₁[μ] E) : integral (c • f) = c • integral f := begin simp only [integral], show (integral_clm' 𝕜) (c • f) = c • (integral_clm' 𝕜) f, from map_smul (integral_clm' 𝕜) c f end local notation (name := integral_clm) `Integral` := @integral_clm α E _ _ μ _ _ local notation (name := simple_func.integral_clm') `sIntegral` := @simple_func.integral_clm α E _ _ μ _ lemma norm_Integral_le_one : ‖Integral‖ ≤ 1 := norm_set_to_L1_le (dominated_fin_meas_additive_weighted_smul μ) zero_le_one lemma norm_integral_le (f : α →₁[μ] E) : ‖integral f‖ ≤ ‖f‖ := calc ‖integral f‖ = ‖Integral f‖ : by simp only [integral] ... ≤ ‖Integral‖ * ‖f‖ : le_op_norm _ _ ... ≤ 1 * ‖f‖ : mul_le_mul_of_nonneg_right norm_Integral_le_one $ norm_nonneg _ ... = ‖f‖ : one_mul _ @[continuity] lemma continuous_integral : continuous (λ (f : α →₁[μ] E), integral f) := begin simp only [integral], exact L1.integral_clm.continuous end section pos_part lemma integral_eq_norm_pos_part_sub (f : α →₁[μ] ℝ) : integral f = ‖Lp.pos_part f‖ - ‖Lp.neg_part f‖ := begin -- Use `is_closed_property` and `is_closed_eq` refine @is_closed_property _ _ _ (coe : (α →₁ₛ[μ] ℝ) → (α →₁[μ] ℝ)) (λ f : α →₁[μ] ℝ, integral f = ‖Lp.pos_part f‖ - ‖Lp.neg_part f‖) (simple_func.dense_range one_ne_top) (is_closed_eq _ _) _ f, { simp only [integral], exact cont _ }, { refine continuous.sub (continuous_norm.comp Lp.continuous_pos_part) (continuous_norm.comp Lp.continuous_neg_part) }, -- Show that the property holds for all simple functions in the `L¹` space. { assume s, norm_cast, exact simple_func.integral_eq_norm_pos_part_sub _ } end end pos_part end integration_in_L1 end L1 /-! ## The Bochner integral on functions Define the Bochner integral on functions generally to be the `L1` Bochner integral, for integrable functions, and 0 otherwise; prove its basic properties. -/ variables [normed_add_comm_group E] [normed_space ℝ E] [complete_space E] [nontrivially_normed_field 𝕜] [normed_space 𝕜 E] [smul_comm_class ℝ 𝕜 E] [normed_add_comm_group F] [normed_space ℝ F] [complete_space F] section open_locale classical /-- The Bochner integral -/ @[irreducible] def integral {m : measurable_space α} (μ : measure α) (f : α → E) : E := if hf : integrable f μ then L1.integral (hf.to_L1 f) else 0 end /-! In the notation for integrals, an expression like `∫ x, g ‖x‖ ∂μ` will not be parsed correctly, and needs parentheses. We do not set the binding power of `r` to `0`, because then `∫ x, f x = 0` will be parsed incorrectly. -/ notation `∫` binders `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral μ r notation `∫` binders `, ` r:(scoped:60 f, integral volume f) := r notation `∫` binders ` in ` s `, ` r:(scoped:60 f, f) ` ∂` μ:70 := integral (measure.restrict μ s) r notation `∫` binders ` in ` s `, ` r:(scoped:60 f, integral (measure.restrict volume s) f) := r section properties open continuous_linear_map measure_theory.simple_func variables {f g : α → E} {m : measurable_space α} {μ : measure α} lemma integral_eq (f : α → E) (hf : integrable f μ) : ∫ a, f a ∂μ = L1.integral (hf.to_L1 f) := by { rw [integral], exact @dif_pos _ (id _) hf _ _ _ } lemma integral_eq_set_to_fun (f : α → E) : ∫ a, f a ∂μ = set_to_fun μ (weighted_smul μ) (dominated_fin_meas_additive_weighted_smul μ) f := by { simp only [integral, L1.integral], refl } lemma L1.integral_eq_integral (f : α →₁[μ] E) : L1.integral f = ∫ a, f a ∂μ := begin simp only [integral, L1.integral], exact (L1.set_to_fun_eq_set_to_L1 (dominated_fin_meas_additive_weighted_smul μ) f).symm end lemma integral_undef (h : ¬ integrable f μ) : ∫ a, f a ∂μ = 0 := by { rw [integral], exact @dif_neg _ (id _) h _ _ _ } lemma integral_non_ae_strongly_measurable (h : ¬ ae_strongly_measurable f μ) : ∫ a, f a ∂μ = 0 := integral_undef $ not_and_of_not_left _ h variables (α E) lemma integral_zero : ∫ a : α, (0:E) ∂μ = 0 := begin simp only [integral, L1.integral], exact set_to_fun_zero (dominated_fin_meas_additive_weighted_smul μ) end @[simp] lemma integral_zero' : integral μ (0 : α → E) = 0 := integral_zero α E variables {α E} lemma integrable_of_integral_eq_one {f : α → ℝ} (h : ∫ x, f x ∂μ = 1) : integrable f μ := by { contrapose h, rw integral_undef h, exact zero_ne_one } lemma integral_add (hf : integrable f μ) (hg : integrable g μ) : ∫ a, f a + g a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_add (dominated_fin_meas_additive_weighted_smul μ) hf hg end lemma integral_add' (hf : integrable f μ) (hg : integrable g μ) : ∫ a, (f + g) a ∂μ = ∫ a, f a ∂μ + ∫ a, g a ∂μ := integral_add hf hg lemma integral_finset_sum {ι} (s : finset ι) {f : ι → α → E} (hf : ∀ i ∈ s, integrable (f i) μ) : ∫ a, ∑ i in s, f i a ∂μ = ∑ i in s, ∫ a, f i a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_finset_sum (dominated_fin_meas_additive_weighted_smul _) s hf end lemma integral_neg (f : α → E) : ∫ a, -f a ∂μ = - ∫ a, f a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_neg (dominated_fin_meas_additive_weighted_smul μ) f end lemma integral_neg' (f : α → E) : ∫ a, (-f) a ∂μ = - ∫ a, f a ∂μ := integral_neg f lemma integral_sub (hf : integrable f μ) (hg : integrable g μ) : ∫ a, f a - g a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_sub (dominated_fin_meas_additive_weighted_smul μ) hf hg end lemma integral_sub' (hf : integrable f μ) (hg : integrable g μ) : ∫ a, (f - g) a ∂μ = ∫ a, f a ∂μ - ∫ a, g a ∂μ := integral_sub hf hg lemma integral_smul (c : 𝕜) (f : α → E) : ∫ a, c • (f a) ∂μ = c • ∫ a, f a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_smul (dominated_fin_meas_additive_weighted_smul μ) weighted_smul_smul c f end lemma integral_mul_left {L : Type*} [is_R_or_C L] (r : L) (f : α → L) : ∫ a, r * (f a) ∂μ = r * ∫ a, f a ∂μ := integral_smul r f lemma integral_mul_right {L : Type*} [is_R_or_C L] (r : L) (f : α → L) : ∫ a, (f a) * r ∂μ = ∫ a, f a ∂μ * r := by { simp only [mul_comm], exact integral_mul_left r f } lemma integral_div {L : Type*} [is_R_or_C L] (r : L) (f : α → L) : ∫ a, (f a) / r ∂μ = ∫ a, f a ∂μ / r := by simpa only [←div_eq_mul_inv] using integral_mul_right r⁻¹ f lemma integral_congr_ae (h : f =ᵐ[μ] g) : ∫ a, f a ∂μ = ∫ a, g a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_congr_ae (dominated_fin_meas_additive_weighted_smul μ) h end @[simp] lemma L1.integral_of_fun_eq_integral {f : α → E} (hf : integrable f μ) : ∫ a, (hf.to_L1 f) a ∂μ = ∫ a, f a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_to_L1 (dominated_fin_meas_additive_weighted_smul μ) hf end @[continuity] lemma continuous_integral : continuous (λ (f : α →₁[μ] E), ∫ a, f a ∂μ) := begin simp only [integral, L1.integral], exact continuous_set_to_fun (dominated_fin_meas_additive_weighted_smul μ) end lemma norm_integral_le_lintegral_norm (f : α → E) : ‖∫ a, f a ∂μ‖ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ) := begin by_cases hf : integrable f μ, { rw [integral_eq f hf, ← integrable.norm_to_L1_eq_lintegral_norm f hf], exact L1.norm_integral_le _ }, { rw [integral_undef hf, norm_zero], exact to_real_nonneg } end lemma ennnorm_integral_le_lintegral_ennnorm (f : α → E) : (‖∫ a, f a ∂μ‖₊ : ℝ≥0∞) ≤ ∫⁻ a, ‖f a‖₊ ∂μ := by { simp_rw [← of_real_norm_eq_coe_nnnorm], apply ennreal.of_real_le_of_le_to_real, exact norm_integral_le_lintegral_norm f } lemma integral_eq_zero_of_ae {f : α → E} (hf : f =ᵐ[μ] 0) : ∫ a, f a ∂μ = 0 := by simp [integral_congr_ae hf, integral_zero] /-- If `f` has finite integral, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ lemma has_finite_integral.tendsto_set_integral_nhds_zero {ι} {f : α → E} (hf : has_finite_integral f μ) {l : filter ι} {s : ι → set α} (hs : tendsto (μ ∘ s) l (𝓝 0)) : tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) := begin rw [tendsto_zero_iff_norm_tendsto_zero], simp_rw [← coe_nnnorm, ← nnreal.coe_zero, nnreal.tendsto_coe, ← ennreal.tendsto_coe, ennreal.coe_zero], exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds (tendsto_set_lintegral_zero (ne_of_lt hf) hs) (λ i, zero_le _) (λ i, ennnorm_integral_le_lintegral_ennnorm _) end /-- If `f` is integrable, then `∫ x in s, f x ∂μ` is absolutely continuous in `s`: it tends to zero as `μ s` tends to zero. -/ lemma integrable.tendsto_set_integral_nhds_zero {ι} {f : α → E} (hf : integrable f μ) {l : filter ι} {s : ι → set α} (hs : tendsto (μ ∘ s) l (𝓝 0)) : tendsto (λ i, ∫ x in s i, f x ∂μ) l (𝓝 0) := hf.2.tendsto_set_integral_nhds_zero hs /-- If `F i → f` in `L1`, then `∫ x, F i x ∂μ → ∫ x, f x ∂μ`. -/ lemma tendsto_integral_of_L1 {ι} (f : α → E) (hfi : integrable f μ) {F : ι → α → E} {l : filter ι} (hFi : ∀ᶠ i in l, integrable (F i) μ) (hF : tendsto (λ i, ∫⁻ x, ‖F i x - f x‖₊ ∂μ) l (𝓝 0)) : tendsto (λ i, ∫ x, F i x ∂μ) l (𝓝 $ ∫ x, f x ∂μ) := begin simp only [integral, L1.integral], exact tendsto_set_to_fun_of_L1 (dominated_fin_meas_additive_weighted_smul μ) f hfi hFi hF end /-- Lebesgue dominated convergence theorem provides sufficient conditions under which almost everywhere convergence of a sequence of functions implies the convergence of their integrals. We could weaken the condition `bound_integrable` to require `has_finite_integral bound μ` instead (i.e. not requiring that `bound` is measurable), but in all applications proving integrability is easier. -/ theorem tendsto_integral_of_dominated_convergence {F : ℕ → α → E} {f : α → E} (bound : α → ℝ) (F_measurable : ∀ n, ae_strongly_measurable (F n) μ) (bound_integrable : integrable bound μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) at_top (𝓝 (f a))) : tendsto (λn, ∫ a, F n a ∂μ) at_top (𝓝 $ ∫ a, f a ∂μ) := begin simp only [integral, L1.integral], exact tendsto_set_to_fun_of_dominated_convergence (dominated_fin_meas_additive_weighted_smul μ) bound F_measurable bound_integrable h_bound h_lim end /-- Lebesgue dominated convergence theorem for filters with a countable basis -/ lemma tendsto_integral_filter_of_dominated_convergence {ι} {l : filter ι} [l.is_countably_generated] {F : ι → α → E} {f : α → E} (bound : α → ℝ) (hF_meas : ∀ᶠ n in l, ae_strongly_measurable (F n) μ) (h_bound : ∀ᶠ n in l, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_lim : ∀ᵐ a ∂μ, tendsto (λ n, F n a) l (𝓝 (f a))) : tendsto (λn, ∫ a, F n a ∂μ) l (𝓝 $ ∫ a, f a ∂μ) := begin simp only [integral, L1.integral], exact tendsto_set_to_fun_filter_of_dominated_convergence (dominated_fin_meas_additive_weighted_smul μ) bound hF_meas h_bound bound_integrable h_lim end /-- Lebesgue dominated convergence theorem for series. -/ lemma has_sum_integral_of_dominated_convergence {ι} [countable ι] {F : ι → α → E} {f : α → E} (bound : ι → α → ℝ) (hF_meas : ∀ n, ae_strongly_measurable (F n) μ) (h_bound : ∀ n, ∀ᵐ a ∂μ, ‖F n a‖ ≤ bound n a) (bound_summable : ∀ᵐ a ∂μ, summable (λ n, bound n a)) (bound_integrable : integrable (λ a, ∑' n, bound n a) μ) (h_lim : ∀ᵐ a ∂μ, has_sum (λ n, F n a) (f a)) : has_sum (λn, ∫ a, F n a ∂μ) (∫ a, f a ∂μ) := begin have hb_nonneg : ∀ᵐ a ∂μ, ∀ n, 0 ≤ bound n a := eventually_countable_forall.2 (λ n, (h_bound n).mono $ λ a, (norm_nonneg _).trans), have hb_le_tsum : ∀ n, bound n ≤ᵐ[μ] (λ a, ∑' n, bound n a), { intro n, filter_upwards [hb_nonneg, bound_summable] with _ ha0 ha_sum using le_tsum ha_sum _ (λ i _, ha0 i) }, have hF_integrable : ∀ n, integrable (F n) μ, { refine λ n, bound_integrable.mono' (hF_meas n) _, exact eventually_le.trans (h_bound n) (hb_le_tsum n) }, simp only [has_sum, ← integral_finset_sum _ (λ n _, hF_integrable n)], refine tendsto_integral_filter_of_dominated_convergence (λ a, ∑' n, bound n a) _ _ bound_integrable h_lim, { exact eventually_of_forall (λ s, s.ae_strongly_measurable_sum $ λ n hn, hF_meas n) }, { refine eventually_of_forall (λ s, _), filter_upwards [eventually_countable_forall.2 h_bound, hb_nonneg, bound_summable] with a hFa ha0 has, calc ‖∑ n in s, F n a‖ ≤ ∑ n in s, bound n a : norm_sum_le_of_le _ (λ n hn, hFa n) ... ≤ ∑' n, bound n a : sum_le_tsum _ (λ n hn, ha0 n) has }, end variables {X : Type*} [topological_space X] [first_countable_topology X] lemma continuous_within_at_of_dominated {F : X → α → E} {x₀ : X} {bound : α → ℝ} {s : set X} (hF_meas : ∀ᶠ x in 𝓝[s] x₀, ae_strongly_measurable (F x) μ) (h_bound : ∀ᶠ x in 𝓝[s] x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_within_at (λ x, F x a) s x₀) : continuous_within_at (λ x, ∫ a, F x a ∂μ) s x₀ := begin simp only [integral, L1.integral], exact continuous_within_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas h_bound bound_integrable h_cont end lemma continuous_at_of_dominated {F : X → α → E} {x₀ : X} {bound : α → ℝ} (hF_meas : ∀ᶠ x in 𝓝 x₀, ae_strongly_measurable (F x) μ) (h_bound : ∀ᶠ x in 𝓝 x₀, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_at (λ x, F x a) x₀) : continuous_at (λ x, ∫ a, F x a ∂μ) x₀ := begin simp only [integral, L1.integral], exact continuous_at_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas h_bound bound_integrable h_cont end lemma continuous_on_of_dominated {F : X → α → E} {bound : α → ℝ} {s : set X} (hF_meas : ∀ x ∈ s, ae_strongly_measurable (F x) μ) (h_bound : ∀ x ∈ s, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous_on (λ x, F x a) s) : continuous_on (λ x, ∫ a, F x a ∂μ) s := begin simp only [integral, L1.integral], exact continuous_on_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas h_bound bound_integrable h_cont end lemma continuous_of_dominated {F : X → α → E} {bound : α → ℝ} (hF_meas : ∀ x, ae_strongly_measurable (F x) μ) (h_bound : ∀ x, ∀ᵐ a ∂μ, ‖F x a‖ ≤ bound a) (bound_integrable : integrable bound μ) (h_cont : ∀ᵐ a ∂μ, continuous (λ x, F x a)) : continuous (λ x, ∫ a, F x a ∂μ) := begin simp only [integral, L1.integral], exact continuous_set_to_fun_of_dominated (dominated_fin_meas_additive_weighted_smul μ) hF_meas h_bound bound_integrable h_cont end /-- The Bochner integral of a real-valued function `f : α → ℝ` is the difference between the integral of the positive part of `f` and the integral of the negative part of `f`. -/ lemma integral_eq_lintegral_pos_part_sub_lintegral_neg_part {f : α → ℝ} (hf : integrable f μ) : ∫ a, f a ∂μ = ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) - ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) := let f₁ := hf.to_L1 f in -- Go to the `L¹` space have eq₁ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) = ‖Lp.pos_part f₁‖ := begin rw L1.norm_def, congr' 1, apply lintegral_congr_ae, filter_upwards [Lp.coe_fn_pos_part f₁, hf.coe_fn_to_L1] with _ h₁ h₂, rw [h₁, h₂, ennreal.of_real], congr' 1, apply nnreal.eq, rw real.nnnorm_of_nonneg (le_max_right _ _), simp only [real.coe_to_nnreal', subtype.coe_mk], end, -- Go to the `L¹` space have eq₂ : ennreal.to_real (∫⁻ a, (ennreal.of_real $ - f a) ∂μ) = ‖Lp.neg_part f₁‖ := begin rw L1.norm_def, congr' 1, apply lintegral_congr_ae, filter_upwards [Lp.coe_fn_neg_part f₁, hf.coe_fn_to_L1] with _ h₁ h₂, rw [h₁, h₂, ennreal.of_real], congr' 1, apply nnreal.eq, simp only [real.coe_to_nnreal', coe_nnnorm, nnnorm_neg], rw [real.norm_of_nonpos (min_le_right _ _), ← max_neg_neg, neg_zero], end, begin rw [eq₁, eq₂, integral, dif_pos], exact L1.integral_eq_norm_pos_part_sub _ end lemma integral_eq_lintegral_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfm : ae_strongly_measurable f μ) : ∫ a, f a ∂μ = ennreal.to_real (∫⁻ a, (ennreal.of_real $ f a) ∂μ) := begin by_cases hfi : integrable f μ, { rw integral_eq_lintegral_pos_part_sub_lintegral_neg_part hfi, have h_min : ∫⁻ a, ennreal.of_real (-f a) ∂μ = 0, { rw lintegral_eq_zero_iff', { refine hf.mono _, simp only [pi.zero_apply], assume a h, simp only [h, neg_nonpos, of_real_eq_zero], }, { exact measurable_of_real.comp_ae_measurable hfm.ae_measurable.neg } }, rw [h_min, zero_to_real, _root_.sub_zero] }, { rw integral_undef hfi, simp_rw [integrable, hfm, has_finite_integral_iff_norm, lt_top_iff_ne_top, ne.def, true_and, not_not] at hfi, have : ∫⁻ (a : α), ennreal.of_real (f a) ∂μ = ∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ, { refine lintegral_congr_ae (hf.mono $ assume a h, _), rw [real.norm_eq_abs, abs_of_nonneg h] }, rw [this, hfi], refl } end lemma integral_norm_eq_lintegral_nnnorm {G} [normed_add_comm_group G] {f : α → G} (hf : ae_strongly_measurable f μ) : ∫ x, ‖f x‖ ∂μ = ennreal.to_real ∫⁻ x, ‖f x‖₊ ∂μ := begin rw integral_eq_lintegral_of_nonneg_ae _ hf.norm, { simp_rw [of_real_norm_eq_coe_nnnorm], }, { refine ae_of_all _ _, simp_rw [pi.zero_apply, norm_nonneg, imp_true_iff] }, end lemma of_real_integral_norm_eq_lintegral_nnnorm {G} [normed_add_comm_group G] {f : α → G} (hf : integrable f μ) : ennreal.of_real ∫ x, ‖f x‖ ∂μ = ∫⁻ x, ‖f x‖₊ ∂μ := by rw [integral_norm_eq_lintegral_nnnorm hf.ae_strongly_measurable, ennreal.of_real_to_real (lt_top_iff_ne_top.mp hf.2)] lemma integral_eq_integral_pos_part_sub_integral_neg_part {f : α → ℝ} (hf : integrable f μ) : ∫ a, f a ∂μ = (∫ a, real.to_nnreal (f a) ∂μ) - (∫ a, real.to_nnreal (-f a) ∂μ) := begin rw [← integral_sub hf.real_to_nnreal], { simp }, { exact hf.neg.real_to_nnreal } end lemma integral_nonneg_of_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a, f a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_nonneg (dominated_fin_meas_additive_weighted_smul μ) (λ s _ _, weighted_smul_nonneg s) hf end lemma lintegral_coe_eq_integral (f : α → ℝ≥0) (hfi : integrable (λ x, (f x : ℝ)) μ) : ∫⁻ a, f a ∂μ = ennreal.of_real ∫ a, f a ∂μ := begin simp_rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (λ x, (f x).coe_nonneg)) hfi.ae_strongly_measurable, ← ennreal.coe_nnreal_eq], rw [ennreal.of_real_to_real], rw [← lt_top_iff_ne_top], convert hfi.has_finite_integral, ext1 x, rw [nnreal.nnnorm_eq] end lemma of_real_integral_eq_lintegral_of_real {f : α → ℝ} (hfi : integrable f μ) (f_nn : 0 ≤ᵐ[μ] f) : ennreal.of_real (∫ x, f x ∂μ) = ∫⁻ x, ennreal.of_real (f x) ∂μ := begin simp_rw [integral_congr_ae (show f =ᵐ[μ] λ x, ‖f x‖, by { filter_upwards [f_nn] with x hx, rw [real.norm_eq_abs, abs_eq_self.mpr hx], }), of_real_integral_norm_eq_lintegral_nnnorm hfi, ←of_real_norm_eq_coe_nnnorm], apply lintegral_congr_ae, filter_upwards [f_nn] with x hx, exact congr_arg ennreal.of_real (by rw [real.norm_eq_abs, abs_eq_self.mpr hx]), end lemma integral_to_real {f : α → ℝ≥0∞} (hfm : ae_measurable f μ) (hf : ∀ᵐ x ∂μ, f x < ∞) : ∫ a, (f a).to_real ∂μ = (∫⁻ a, f a ∂μ).to_real := begin rw [integral_eq_lintegral_of_nonneg_ae _ hfm.ennreal_to_real.ae_strongly_measurable], { rw lintegral_congr_ae, refine hf.mp (eventually_of_forall _), intros x hx, rw [lt_top_iff_ne_top] at hx, simp [hx] }, { exact (eventually_of_forall $ λ x, ennreal.to_real_nonneg) } end lemma lintegral_coe_le_coe_iff_integral_le {f : α → ℝ≥0} (hfi : integrable (λ x, (f x : ℝ)) μ) {b : ℝ≥0} : ∫⁻ a, f a ∂μ ≤ b ↔ ∫ a, (f a : ℝ) ∂μ ≤ b := by rw [lintegral_coe_eq_integral f hfi, ennreal.of_real, ennreal.coe_le_coe, real.to_nnreal_le_iff_le_coe] lemma integral_coe_le_of_lintegral_coe_le {f : α → ℝ≥0} {b : ℝ≥0} (h : ∫⁻ a, f a ∂μ ≤ b) : ∫ a, (f a : ℝ) ∂μ ≤ b := begin by_cases hf : integrable (λ a, (f a : ℝ)) μ, { exact (lintegral_coe_le_coe_iff_integral_le hf).1 h }, { rw integral_undef hf, exact b.2 } end lemma integral_nonneg {f : α → ℝ} (hf : 0 ≤ f) : 0 ≤ ∫ a, f a ∂μ := integral_nonneg_of_ae $ eventually_of_forall hf lemma integral_nonpos_of_ae {f : α → ℝ} (hf : f ≤ᵐ[μ] 0) : ∫ a, f a ∂μ ≤ 0 := begin have hf : 0 ≤ᵐ[μ] (-f) := hf.mono (assume a h, by rwa [pi.neg_apply, pi.zero_apply, neg_nonneg]), have : 0 ≤ ∫ a, -f a ∂μ := integral_nonneg_of_ae hf, rwa [integral_neg, neg_nonneg] at this, end lemma integral_nonpos {f : α → ℝ} (hf : f ≤ 0) : ∫ a, f a ∂μ ≤ 0 := integral_nonpos_of_ae $ eventually_of_forall hf lemma integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) : ∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := by simp_rw [integral_eq_lintegral_of_nonneg_ae hf hfi.1, ennreal.to_real_eq_zero_iff, lintegral_eq_zero_iff' (ennreal.measurable_of_real.comp_ae_measurable hfi.1.ae_measurable), ← ennreal.not_lt_top, ← has_finite_integral_iff_of_real hf, hfi.2, not_true, or_false, ← hf.le_iff_eq, filter.eventually_eq, filter.eventually_le, (∘), pi.zero_apply, ennreal.of_real_eq_zero] lemma integral_eq_zero_iff_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) : ∫ x, f x ∂μ = 0 ↔ f =ᵐ[μ] 0 := integral_eq_zero_iff_of_nonneg_ae (eventually_of_forall hf) hfi lemma integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hfi : integrable f μ) : (0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) := by simp_rw [(integral_nonneg_of_ae hf).lt_iff_ne, pos_iff_ne_zero, ne.def, @eq_comm ℝ 0, integral_eq_zero_iff_of_nonneg_ae hf hfi, filter.eventually_eq, ae_iff, pi.zero_apply, function.support] lemma integral_pos_iff_support_of_nonneg {f : α → ℝ} (hf : 0 ≤ f) (hfi : integrable f μ) : (0 < ∫ x, f x ∂μ) ↔ 0 < μ (function.support f) := integral_pos_iff_support_of_nonneg_ae (eventually_of_forall hf) hfi section normed_add_comm_group variables {H : Type*} [normed_add_comm_group H] lemma L1.norm_eq_integral_norm (f : α →₁[μ] H) : ‖f‖ = ∫ a, ‖f a‖ ∂μ := begin simp only [snorm, snorm', ennreal.one_to_real, ennreal.rpow_one, Lp.norm_def, if_false, ennreal.one_ne_top, one_ne_zero, _root_.div_one], rw integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (by simp [norm_nonneg])) (Lp.ae_strongly_measurable f).norm, simp [of_real_norm_eq_coe_nnnorm] end lemma L1.norm_of_fun_eq_integral_norm {f : α → H} (hf : integrable f μ) : ‖hf.to_L1 f‖ = ∫ a, ‖f a‖ ∂μ := begin rw L1.norm_eq_integral_norm, refine integral_congr_ae _, apply hf.coe_fn_to_L1.mono, intros a ha, simp [ha] end lemma mem_ℒp.snorm_eq_integral_rpow_norm {f : α → H} {p : ℝ≥0∞} (hp1 : p ≠ 0) (hp2 : p ≠ ∞) (hf : mem_ℒp f p μ) : snorm f p μ = ennreal.of_real ((∫ a, ‖f a‖ ^ p.to_real ∂μ) ^ (p.to_real ⁻¹)) := begin have A : ∫⁻ (a : α), ennreal.of_real (‖f a‖ ^ p.to_real) ∂μ = ∫⁻ (a : α), ‖f a‖₊ ^ p.to_real ∂μ, { apply lintegral_congr (λ x, _), rw [← of_real_rpow_of_nonneg (norm_nonneg _) to_real_nonneg, of_real_norm_eq_coe_nnnorm] }, simp only [snorm_eq_lintegral_rpow_nnnorm hp1 hp2, one_div], rw integral_eq_lintegral_of_nonneg_ae, rotate, { exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _) }, { exact (hf.ae_strongly_measurable.norm.ae_measurable.pow_const _).ae_strongly_measurable }, rw [A, ← of_real_rpow_of_nonneg to_real_nonneg (inv_nonneg.2 to_real_nonneg), of_real_to_real], exact (lintegral_rpow_nnnorm_lt_top_of_snorm_lt_top hp1 hp2 hf.2).ne end end normed_add_comm_group lemma integral_mono_ae {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := begin simp only [integral, L1.integral], exact set_to_fun_mono (dominated_fin_meas_additive_weighted_smul μ) (λ s _ _, weighted_smul_nonneg s) hf hg h end @[mono] lemma integral_mono {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ) (h : f ≤ g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := integral_mono_ae hf hg $ eventually_of_forall h lemma integral_mono_of_nonneg {f g : α → ℝ} (hf : 0 ≤ᵐ[μ] f) (hgi : integrable g μ) (h : f ≤ᵐ[μ] g) : ∫ a, f a ∂μ ≤ ∫ a, g a ∂μ := begin by_cases hfm : ae_strongly_measurable f μ, { refine integral_mono_ae ⟨hfm, _⟩ hgi h, refine (hgi.has_finite_integral.mono $ h.mp $ hf.mono $ λ x hf hfg, _), simpa [abs_of_nonneg hf, abs_of_nonneg (le_trans hf hfg)] }, { rw [integral_non_ae_strongly_measurable hfm], exact integral_nonneg_of_ae (hf.trans h) } end lemma integral_mono_measure {f : α → ℝ} {ν} (hle : μ ≤ ν) (hf : 0 ≤ᵐ[ν] f) (hfi : integrable f ν) : ∫ a, f a ∂μ ≤ ∫ a, f a ∂ν := begin have hfi' : integrable f μ := hfi.mono_measure hle, have hf' : 0 ≤ᵐ[μ] f := hle.absolutely_continuous hf, rw [integral_eq_lintegral_of_nonneg_ae hf' hfi'.1, integral_eq_lintegral_of_nonneg_ae hf hfi.1, ennreal.to_real_le_to_real], exacts [lintegral_mono' hle le_rfl, ((has_finite_integral_iff_of_real hf').1 hfi'.2).ne, ((has_finite_integral_iff_of_real hf).1 hfi.2).ne] end lemma norm_integral_le_integral_norm (f : α → E) : ‖(∫ a, f a ∂μ)‖ ≤ ∫ a, ‖f a‖ ∂μ := have le_ae : ∀ᵐ a ∂μ, 0 ≤ ‖f a‖ := eventually_of_forall (λa, norm_nonneg _), classical.by_cases ( λh : ae_strongly_measurable f μ, calc ‖∫ a, f a ∂μ‖ ≤ ennreal.to_real (∫⁻ a, (ennreal.of_real ‖f a‖) ∂μ) : norm_integral_le_lintegral_norm _ ... = ∫ a, ‖f a‖ ∂μ : (integral_eq_lintegral_of_nonneg_ae le_ae $ h.norm).symm ) ( λh : ¬ae_strongly_measurable f μ, begin rw [integral_non_ae_strongly_measurable h, norm_zero], exact integral_nonneg_of_ae le_ae end ) lemma norm_integral_le_of_norm_le {f : α → E} {g : α → ℝ} (hg : integrable g μ) (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ g x) : ‖∫ x, f x ∂μ‖ ≤ ∫ x, g x ∂μ := calc ‖∫ x, f x ∂μ‖ ≤ ∫ x, ‖f x‖ ∂μ : norm_integral_le_integral_norm f ... ≤ ∫ x, g x ∂μ : integral_mono_of_nonneg (eventually_of_forall $ λ x, norm_nonneg _) hg h lemma simple_func.integral_eq_integral (f : α →ₛ E) (hfi : integrable f μ) : f.integral μ = ∫ x, f x ∂μ := begin rw [integral_eq f hfi, ← L1.simple_func.to_Lp_one_eq_to_L1, L1.simple_func.integral_L1_eq_integral, L1.simple_func.integral_eq_integral], exact simple_func.integral_congr hfi (Lp.simple_func.to_simple_func_to_Lp _ _).symm end lemma simple_func.integral_eq_sum (f : α →ₛ E) (hfi : integrable f μ) : ∫ x, f x ∂μ = ∑ x in f.range, (ennreal.to_real (μ (f ⁻¹' {x}))) • x := by { rw [← f.integral_eq_integral hfi, simple_func.integral, ← simple_func.integral_eq], refl, } @[simp] lemma integral_const (c : E) : ∫ x : α, c ∂μ = (μ univ).to_real • c := begin cases (@le_top _ _ _ (μ univ)).lt_or_eq with hμ hμ, { haveI : is_finite_measure μ := ⟨hμ⟩, simp only [integral, L1.integral], exact set_to_fun_const (dominated_fin_meas_additive_weighted_smul _) _, }, { by_cases hc : c = 0, { simp [hc, integral_zero] }, { have : ¬integrable (λ x : α, c) μ, { simp only [integrable_const_iff, not_or_distrib], exact ⟨hc, hμ.not_lt⟩ }, simp [integral_undef, *] } } end lemma norm_integral_le_of_norm_le_const [is_finite_measure μ] {f : α → E} {C : ℝ} (h : ∀ᵐ x ∂μ, ‖f x‖ ≤ C) : ‖∫ x, f x ∂μ‖ ≤ C * (μ univ).to_real := calc ‖∫ x, f x ∂μ‖ ≤ ∫ x, C ∂μ : norm_integral_le_of_norm_le (integrable_const C) h ... = C * (μ univ).to_real : by rw [integral_const, smul_eq_mul, mul_comm] lemma tendsto_integral_approx_on_of_measurable [measurable_space E] [borel_space E] {f : α → E} {s : set E} [separable_space s] (hfi : integrable f μ) (hfm : measurable f) (hs : ∀ᵐ x ∂μ, f x ∈ closure s) {y₀ : E} (h₀ : y₀ ∈ s) (h₀i : integrable (λ x, y₀) μ) : tendsto (λ n, (simple_func.approx_on f hfm s y₀ h₀ n).integral μ) at_top (𝓝 $ ∫ x, f x ∂μ) := begin have hfi' := simple_func.integrable_approx_on hfm hfi h₀ h₀i, simp only [simple_func.integral_eq_integral _ (hfi' _), integral, L1.integral], exact tendsto_set_to_fun_approx_on_of_measurable (dominated_fin_meas_additive_weighted_smul μ) hfi hfm hs h₀ h₀i, end lemma tendsto_integral_approx_on_of_measurable_of_range_subset [measurable_space E] [borel_space E] {f : α → E} (fmeas : measurable f) (hf : integrable f μ) (s : set E) [separable_space s] (hs : range f ∪ {0} ⊆ s) : tendsto (λ n, (simple_func.approx_on f fmeas s 0 (hs $ by simp) n).integral μ) at_top (𝓝 $ ∫ x, f x ∂μ) := begin apply tendsto_integral_approx_on_of_measurable hf fmeas _ _ (integrable_zero _ _ _), exact eventually_of_forall (λ x, subset_closure (hs (set.mem_union_left _ (mem_range_self _)))), end variable {ν : measure α} lemma integral_add_measure {f : α → E} (hμ : integrable f μ) (hν : integrable f ν) : ∫ x, f x ∂(μ + ν) = ∫ x, f x ∂μ + ∫ x, f x ∂ν := begin have hfi := hμ.add_measure hν, simp_rw [integral_eq_set_to_fun], have hμ_dfma : dominated_fin_meas_additive (μ + ν) (weighted_smul μ : set α → E →L[ℝ] E) 1, from dominated_fin_meas_additive.add_measure_right μ ν (dominated_fin_meas_additive_weighted_smul μ) zero_le_one, have hν_dfma : dominated_fin_meas_additive (μ + ν) (weighted_smul ν : set α → E →L[ℝ] E) 1, from dominated_fin_meas_additive.add_measure_left μ ν (dominated_fin_meas_additive_weighted_smul ν) zero_le_one, rw [← set_to_fun_congr_measure_of_add_right hμ_dfma (dominated_fin_meas_additive_weighted_smul μ) f hfi, ← set_to_fun_congr_measure_of_add_left hν_dfma (dominated_fin_meas_additive_weighted_smul ν) f hfi], refine set_to_fun_add_left' _ _ _ (λ s hs hμνs, _) f, rw [measure.coe_add, pi.add_apply, add_lt_top] at hμνs, rw [weighted_smul, weighted_smul, weighted_smul, ← add_smul, measure.coe_add, pi.add_apply, to_real_add hμνs.1.ne hμνs.2.ne], end @[simp] lemma integral_zero_measure {m : measurable_space α} (f : α → E) : ∫ x, f x ∂(0 : measure α) = 0 := begin simp only [integral, L1.integral], exact set_to_fun_measure_zero (dominated_fin_meas_additive_weighted_smul _) rfl end theorem integral_finset_sum_measure {ι} {m : measurable_space α} {f : α → E} {μ : ι → measure α} {s : finset ι} (hf : ∀ i ∈ s, integrable f (μ i)) : ∫ a, f a ∂(∑ i in s, μ i) = ∑ i in s, ∫ a, f a ∂μ i := begin classical, refine finset.induction_on' s _ _, -- `induction s using finset.induction_on'` fails { simp }, { intros i t hi ht hit iht, simp only [finset.sum_insert hit, ← iht], exact integral_add_measure (hf _ hi) (integrable_finset_sum_measure.2 $ λ j hj, hf j (ht hj)) } end lemma nndist_integral_add_measure_le_lintegral (h₁ : integrable f μ) (h₂ : integrable f ν) : (nndist (∫ x, f x ∂μ) (∫ x, f x ∂(μ + ν)) : ℝ≥0∞) ≤ ∫⁻ x, ‖f x‖₊ ∂ν := begin rw [integral_add_measure h₁ h₂, nndist_comm, nndist_eq_nnnorm, add_sub_cancel'], exact ennnorm_integral_le_lintegral_ennnorm _ end theorem has_sum_integral_measure {ι} {m : measurable_space α} {f : α → E} {μ : ι → measure α} (hf : integrable f (measure.sum μ)) : has_sum (λ i, ∫ a, f a ∂μ i) (∫ a, f a ∂measure.sum μ) := begin have hfi : ∀ i, integrable f (μ i) := λ i, hf.mono_measure (measure.le_sum _ _), simp only [has_sum, ← integral_finset_sum_measure (λ i _, hfi i)], refine metric.nhds_basis_ball.tendsto_right_iff.mpr (λ ε ε0, _), lift ε to ℝ≥0 using ε0.le, have hf_lt : ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ) < ∞ := hf.2, have hmem : ∀ᶠ y in 𝓝 ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ), ∫⁻ x, ‖f x‖₊ ∂(measure.sum μ) < y + ε, { refine tendsto_id.add tendsto_const_nhds (lt_mem_nhds $ ennreal.lt_add_right _ _), exacts [hf_lt.ne, ennreal.coe_ne_zero.2 (nnreal.coe_ne_zero.1 ε0.ne')] }, refine ((has_sum_lintegral_measure (λ x, ‖f x‖₊) μ).eventually hmem).mono (λ s hs, _), obtain ⟨ν, hν⟩ : ∃ ν, (∑ i in s, μ i) + ν = measure.sum μ, { refine ⟨measure.sum (λ i : ↥(sᶜ : set ι), μ i), _⟩, simpa only [← measure.sum_coe_finset] using measure.sum_add_sum_compl (s : set ι) μ }, rw [metric.mem_ball, ← coe_nndist, nnreal.coe_lt_coe, ← ennreal.coe_lt_coe, ← hν], rw [← hν, integrable_add_measure] at hf, refine (nndist_integral_add_measure_le_lintegral hf.1 hf.2).trans_lt _, rw [← hν, lintegral_add_measure, lintegral_finset_sum_measure] at hs, exact lt_of_add_lt_add_left hs end theorem integral_sum_measure {ι} {m : measurable_space α} {f : α → E} {μ : ι → measure α} (hf : integrable f (measure.sum μ)) : ∫ a, f a ∂measure.sum μ = ∑' i, ∫ a, f a ∂μ i := (has_sum_integral_measure hf).tsum_eq.symm lemma integral_tsum {ι} [countable ι] {f : ι → α → E} (hf : ∀ i, ae_strongly_measurable (f i) μ) (hf' : ∑' i, ∫⁻ (a : α), ‖f i a‖₊ ∂μ ≠ ∞) : ∫ (a : α), (∑' i, f i a) ∂μ = ∑' i, ∫ (a : α), f i a ∂μ := begin have hf'' : ∀ i, ae_measurable (λ x, (‖f i x‖₊ : ℝ≥0∞)) μ, from λ i, (hf i).ennnorm, have hhh : ∀ᵐ (a : α) ∂μ, summable (λ n, (‖f n a‖₊ : ℝ)), { rw ← lintegral_tsum hf'' at hf', refine (ae_lt_top' (ae_measurable.ennreal_tsum hf'') hf').mono _, intros x hx, rw ← ennreal.tsum_coe_ne_top_iff_summable_coe, exact hx.ne, }, convert (measure_theory.has_sum_integral_of_dominated_convergence (λ i a, ‖f i a‖₊) hf _ hhh ⟨_, _⟩ _).tsum_eq.symm, { intros n, filter_upwards with x, refl, }, { simp_rw [← coe_nnnorm, ← nnreal.coe_tsum], rw ae_strongly_measurable_iff_ae_measurable, apply ae_measurable.coe_nnreal_real, apply ae_measurable.nnreal_tsum, exact λ i, (hf i).nnnorm.ae_measurable, }, { dsimp [has_finite_integral], have : ∫⁻ a, ∑' n, ‖f n a‖₊ ∂μ < ⊤ := by rwa [lintegral_tsum hf'', lt_top_iff_ne_top], convert this using 1, apply lintegral_congr_ae, simp_rw [← coe_nnnorm, ← nnreal.coe_tsum, nnreal.nnnorm_eq], filter_upwards [hhh] with a ha, exact ennreal.coe_tsum (nnreal.summable_coe.mp ha), }, { filter_upwards [hhh] with x hx, exact (summable_of_summable_norm hx).has_sum, }, end @[simp] lemma integral_smul_measure (f : α → E) (c : ℝ≥0∞) : ∫ x, f x ∂(c • μ) = c.to_real • ∫ x, f x ∂μ := begin -- First we consider the “degenerate” case `c = ∞` rcases eq_or_ne c ∞ with rfl|hc, { rw [ennreal.top_to_real, zero_smul, integral_eq_set_to_fun, set_to_fun_top_smul_measure], }, -- Main case: `c ≠ ∞` simp_rw [integral_eq_set_to_fun, ← set_to_fun_smul_left], have hdfma : dominated_fin_meas_additive μ (weighted_smul (c • μ) : set α → E →L[ℝ] E) c.to_real, from mul_one c.to_real ▸ (dominated_fin_meas_additive_weighted_smul (c • μ)).of_smul_measure c hc, have hdfma_smul := (dominated_fin_meas_additive_weighted_smul (c • μ)), rw ← set_to_fun_congr_smul_measure c hc hdfma hdfma_smul f, exact set_to_fun_congr_left' _ _ (λ s hs hμs, weighted_smul_smul_measure μ c) f, end lemma integral_map_of_strongly_measurable {β} [measurable_space β] {φ : α → β} (hφ : measurable φ) {f : β → E} (hfm : strongly_measurable f) : ∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ := begin by_cases hfi : integrable f (measure.map φ μ), swap, { rw [integral_undef hfi, integral_undef], rwa [← integrable_map_measure hfm.ae_strongly_measurable hφ.ae_measurable] }, borelize E, haveI : separable_space (range f ∪ {0} : set E) := hfm.separable_space_range_union_singleton, refine tendsto_nhds_unique (tendsto_integral_approx_on_of_measurable_of_range_subset hfm.measurable hfi _ subset.rfl) _, convert tendsto_integral_approx_on_of_measurable_of_range_subset (hfm.measurable.comp hφ) ((integrable_map_measure hfm.ae_strongly_measurable hφ.ae_measurable).1 hfi) (range f ∪ {0}) (by simp [insert_subset_insert, set.range_comp_subset_range]) using 1, ext1 i, simp only [simple_func.approx_on_comp, simple_func.integral_eq, measure.map_apply, hφ, simple_func.measurable_set_preimage, ← preimage_comp, simple_func.coe_comp], refine (finset.sum_subset (simple_func.range_comp_subset_range _ hφ) (λ y _ hy, _)).symm, rw [simple_func.mem_range, ← set.preimage_singleton_eq_empty, simple_func.coe_comp] at hy, rw [hy], simp, end lemma integral_map {β} [measurable_space β] {φ : α → β} (hφ : ae_measurable φ μ) {f : β → E} (hfm : ae_strongly_measurable f (measure.map φ μ)) : ∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ := let g := hfm.mk f in calc ∫ y, f y ∂(measure.map φ μ) = ∫ y, g y ∂(measure.map φ μ) : integral_congr_ae hfm.ae_eq_mk ... = ∫ y, g y ∂(measure.map (hφ.mk φ) μ) : by { congr' 1, exact measure.map_congr hφ.ae_eq_mk } ... = ∫ x, g (hφ.mk φ x) ∂μ : integral_map_of_strongly_measurable hφ.measurable_mk hfm.strongly_measurable_mk ... = ∫ x, g (φ x) ∂μ : integral_congr_ae (hφ.ae_eq_mk.symm.fun_comp _) ... = ∫ x, f (φ x) ∂μ : integral_congr_ae $ ae_eq_comp hφ (hfm.ae_eq_mk).symm lemma _root_.measurable_embedding.integral_map {β} {_ : measurable_space β} {f : α → β} (hf : measurable_embedding f) (g : β → E) : ∫ y, g y ∂(measure.map f μ) = ∫ x, g (f x) ∂μ := begin by_cases hgm : ae_strongly_measurable g (measure.map f μ), { exact integral_map hf.measurable.ae_measurable hgm }, { rw [integral_non_ae_strongly_measurable hgm, integral_non_ae_strongly_measurable], rwa ← hf.ae_strongly_measurable_map_iff } end lemma _root_.closed_embedding.integral_map {β} [topological_space α] [borel_space α] [topological_space β] [measurable_space β] [borel_space β] {φ : α → β} (hφ : closed_embedding φ) (f : β → E) : ∫ y, f y ∂(measure.map φ μ) = ∫ x, f (φ x) ∂μ := hφ.measurable_embedding.integral_map _ lemma integral_map_equiv {β} [measurable_space β] (e : α ≃ᵐ β) (f : β → E) : ∫ y, f y ∂(measure.map e μ) = ∫ x, f (e x) ∂μ := e.measurable_embedding.integral_map f lemma measure_preserving.integral_comp {β} {_ : measurable_space β} {f : α → β} {ν} (h₁ : measure_preserving f μ ν) (h₂ : measurable_embedding f) (g : β → E) : ∫ x, g (f x) ∂μ = ∫ y, g y ∂ν := h₁.map_eq ▸ (h₂.integral_map g).symm lemma set_integral_eq_subtype {α} [measure_space α] {s : set α} (hs : measurable_set s) (f : α → E) : ∫ x in s, f x = ∫ x : s, f x := by { rw ← map_comap_subtype_coe hs, exact (measurable_embedding.subtype_coe hs).integral_map _ } @[simp] lemma integral_dirac' [measurable_space α] (f : α → E) (a : α) (hfm : strongly_measurable f) : ∫ x, f x ∂(measure.dirac a) = f a := begin borelize E, calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) : integral_congr_ae $ ae_eq_dirac' hfm.measurable ... = f a : by simp [measure.dirac_apply_of_mem] end @[simp] lemma integral_dirac [measurable_space α] [measurable_singleton_class α] (f : α → E) (a : α) : ∫ x, f x ∂(measure.dirac a) = f a := calc ∫ x, f x ∂(measure.dirac a) = ∫ x, f a ∂(measure.dirac a) : integral_congr_ae $ ae_eq_dirac f ... = f a : by simp [measure.dirac_apply_of_mem] lemma set_integral_dirac' {mα : measurable_space α} {f : α → E} (hf : strongly_measurable f) (a : α) {s : set α} (hs : measurable_set s) [decidable (a ∈ s)] : ∫ x in s, f x ∂(measure.dirac a) = if a ∈ s then f a else 0 := begin rw [restrict_dirac' hs], swap, { apply_instance, }, split_ifs, { exact integral_dirac' _ _ hf, }, { exact integral_zero_measure _, }, end lemma set_integral_dirac [measurable_space α] [measurable_singleton_class α] (f : α → E) (a : α) (s : set α) [decidable (a ∈ s)] : ∫ x in s, f x ∂(measure.dirac a) = if a ∈ s then f a else 0 := begin rw [restrict_dirac], split_ifs, { exact integral_dirac _ _, }, { exact integral_zero_measure _, }, end lemma mul_meas_ge_le_integral_of_nonneg [is_finite_measure μ] {f : α → ℝ} (hf_nonneg : 0 ≤ f) (hf_int : integrable f μ) (ε : ℝ) : ε * (μ {x | ε ≤ f x}).to_real ≤ ∫ x, f x ∂μ := begin cases lt_or_le ε 0 with hε hε, { exact (mul_nonpos_of_nonpos_of_nonneg hε.le ennreal.to_real_nonneg).trans (integral_nonneg hf_nonneg), }, rw [integral_eq_lintegral_of_nonneg_ae (eventually_of_forall (λ x, hf_nonneg x)) hf_int.ae_strongly_measurable, ← ennreal.to_real_of_real hε, ← ennreal.to_real_mul], have : {x : α | (ennreal.of_real ε).to_real ≤ f x} = {x : α | ennreal.of_real ε ≤ (λ x, ennreal.of_real (f x)) x}, { ext1 x, rw [set.mem_set_of_eq, set.mem_set_of_eq, ← ennreal.to_real_of_real (hf_nonneg x)], exact ennreal.to_real_le_to_real ennreal.of_real_ne_top ennreal.of_real_ne_top, }, rw this, have h_meas : ae_measurable (λ x, ennreal.of_real (f x)) μ, from measurable_id'.ennreal_of_real.comp_ae_measurable hf_int.ae_measurable, have h_mul_meas_le := @mul_meas_ge_le_lintegral₀ _ _ μ _ h_meas (ennreal.of_real ε), rw ennreal.to_real_le_to_real _ _, { exact h_mul_meas_le, }, { simp only [ne.def, with_top.mul_eq_top_iff, ennreal.of_real_eq_zero, not_le, ennreal.of_real_ne_top, false_and, or_false, not_and], exact λ _, measure_ne_top _ _, }, { have h_lt_top : ∫⁻ a, ‖f a‖₊ ∂μ < ∞ := hf_int.has_finite_integral, simp_rw [← of_real_norm_eq_coe_nnnorm, real.norm_eq_abs] at h_lt_top, convert h_lt_top.ne, ext1 x, rw abs_of_nonneg (hf_nonneg x), }, end /-- Hölder's inequality for the integral of a product of norms. The integral of the product of two norms of functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem integral_mul_norm_le_Lp_mul_Lq {E} [normed_add_comm_group E] {f g : α → E} {p q : ℝ} (hpq : p.is_conjugate_exponent q) (hf : mem_ℒp f (ennreal.of_real p) μ) (hg : mem_ℒp g (ennreal.of_real q) μ) : ∫ a, ‖f a‖ * ‖g a‖ ∂μ ≤ (∫ a, ‖f a‖ ^ p ∂μ) ^ (1/p) * (∫ a, ‖g a‖ ^ q ∂μ) ^ (1/q) := begin -- translate the Bochner integrals into Lebesgue integrals. rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae], rotate 1, { exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _), }, { exact (hg.1.norm.ae_measurable.pow ae_measurable_const).ae_strongly_measurable, }, { exact eventually_of_forall (λ x, real.rpow_nonneg_of_nonneg (norm_nonneg _) _),}, { exact (hf.1.norm.ae_measurable.pow ae_measurable_const).ae_strongly_measurable, }, { exact eventually_of_forall (λ x, mul_nonneg (norm_nonneg _) (norm_nonneg _)), }, { exact hf.1.norm.mul hg.1.norm, }, rw [ennreal.to_real_rpow, ennreal.to_real_rpow, ← ennreal.to_real_mul], -- replace norms by nnnorm have h_left : ∫⁻ a, ennreal.of_real (‖f a‖ * ‖g a‖) ∂μ = ∫⁻ a, ((λ x, (‖f x‖₊ : ℝ≥0∞)) * (λ x, ‖g x‖₊)) a ∂μ, { simp_rw [pi.mul_apply, ← of_real_norm_eq_coe_nnnorm, ennreal.of_real_mul (norm_nonneg _)], }, have h_right_f : ∫⁻ a, ennreal.of_real (‖f a‖ ^ p) ∂μ = ∫⁻ a, ‖f a‖₊ ^ p ∂μ, { refine lintegral_congr (λ x, _), rw [← of_real_norm_eq_coe_nnnorm, ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hpq.nonneg], }, have h_right_g : ∫⁻ a, ennreal.of_real (‖g a‖ ^ q) ∂μ = ∫⁻ a, ‖g a‖₊ ^ q ∂μ, { refine lintegral_congr (λ x, _), rw [← of_real_norm_eq_coe_nnnorm, ennreal.of_real_rpow_of_nonneg (norm_nonneg _) hpq.symm.nonneg], }, rw [h_left, h_right_f, h_right_g], -- we can now apply `ennreal.lintegral_mul_le_Lp_mul_Lq` (up to the `to_real` application) refine ennreal.to_real_mono _ _, { refine ennreal.mul_ne_top _ _, { convert hf.snorm_ne_top, rw snorm_eq_lintegral_rpow_nnnorm, { rw ennreal.to_real_of_real hpq.nonneg, }, { rw [ne.def, ennreal.of_real_eq_zero, not_le], exact hpq.pos, }, { exact ennreal.coe_ne_top, }, }, { convert hg.snorm_ne_top, rw snorm_eq_lintegral_rpow_nnnorm, { rw ennreal.to_real_of_real hpq.symm.nonneg, }, { rw [ne.def, ennreal.of_real_eq_zero, not_le], exact hpq.symm.pos, }, { exact ennreal.coe_ne_top, }, }, }, { exact ennreal.lintegral_mul_le_Lp_mul_Lq μ hpq hf.1.nnnorm.ae_measurable.coe_nnreal_ennreal hg.1.nnnorm.ae_measurable.coe_nnreal_ennreal, }, end /-- Hölder's inequality for functions `α → ℝ`. The integral of the product of two nonnegative functions is bounded by the product of their `ℒp` and `ℒq` seminorms when `p` and `q` are conjugate exponents. -/ theorem integral_mul_le_Lp_mul_Lq_of_nonneg {p q : ℝ} (hpq : p.is_conjugate_exponent q) {f g : α → ℝ} (hf_nonneg : 0 ≤ᵐ[μ] f) (hg_nonneg : 0 ≤ᵐ[μ] g) (hf : mem_ℒp f (ennreal.of_real p) μ) (hg : mem_ℒp g (ennreal.of_real q) μ) : ∫ a, f a * g a ∂μ ≤ (∫ a, (f a) ^ p ∂μ) ^ (1/p) * (∫ a, (g a) ^ q ∂μ) ^ (1/q) := begin have h_left : ∫ a, f a * g a ∂μ = ∫ a, ‖f a‖ * ‖g a‖ ∂μ, { refine integral_congr_ae _, filter_upwards [hf_nonneg, hg_nonneg] with x hxf hxg, rw [real.norm_of_nonneg hxf, real.norm_of_nonneg hxg], }, have h_right_f : ∫ a, (f a) ^ p ∂μ = ∫ a, ‖f a‖ ^ p ∂μ, { refine integral_congr_ae _, filter_upwards [hf_nonneg] with x hxf, rw real.norm_of_nonneg hxf, }, have h_right_g : ∫ a, (g a) ^ q ∂μ = ∫ a, ‖g a‖ ^ q ∂μ, { refine integral_congr_ae _, filter_upwards [hg_nonneg] with x hxg, rw real.norm_of_nonneg hxg, }, rw [h_left, h_right_f, h_right_g], exact integral_mul_norm_le_Lp_mul_Lq hpq hf hg, end end properties mk_simp_attribute integral_simps "Simp set for integral rules." attribute [integral_simps] integral_neg integral_smul L1.integral_add L1.integral_sub L1.integral_smul L1.integral_neg section integral_trim variables {H β γ : Type*} [normed_add_comm_group H] {m m0 : measurable_space β} {μ : measure β} /-- Simple function seen as simple function of a larger `measurable_space`. -/ def simple_func.to_larger_space (hm : m ≤ m0) (f : @simple_func β m γ) : simple_func β γ := ⟨@simple_func.to_fun β m γ f, λ x, hm _ (@simple_func.measurable_set_fiber β γ m f x), @simple_func.finite_range β γ m f⟩ lemma simple_func.coe_to_larger_space_eq (hm : m ≤ m0) (f : @simple_func β m γ) : ⇑(f.to_larger_space hm) = f := rfl lemma integral_simple_func_larger_space (hm : m ≤ m0) (f : @simple_func β m F) (hf_int : integrable f μ) : ∫ x, f x ∂μ = ∑ x in (@simple_func.range β F m f), (ennreal.to_real (μ (f ⁻¹' {x}))) • x := begin simp_rw ← f.coe_to_larger_space_eq hm, have hf_int : integrable (f.to_larger_space hm) μ, by rwa simple_func.coe_to_larger_space_eq, rw simple_func.integral_eq_sum _ hf_int, congr, end lemma integral_trim_simple_func (hm : m ≤ m0) (f : @simple_func β m F) (hf_int : integrable f μ) : ∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) := begin have hf : strongly_measurable[m] f, from @simple_func.strongly_measurable β F m _ f, have hf_int_m := hf_int.trim hm hf, rw [integral_simple_func_larger_space (le_refl m) f hf_int_m, integral_simple_func_larger_space hm f hf_int], congr' with x, congr, exact (trim_measurable_set_eq hm (@simple_func.measurable_set_fiber β F m f x)).symm, end lemma integral_trim (hm : m ≤ m0) {f : β → F} (hf : strongly_measurable[m] f) : ∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) := begin borelize F, by_cases hf_int : integrable f μ, swap, { have hf_int_m : ¬ integrable f (μ.trim hm), from λ hf_int_m, hf_int (integrable_of_integrable_trim hm hf_int_m), rw [integral_undef hf_int, integral_undef hf_int_m], }, haveI : separable_space (range f ∪ {0} : set F) := hf.separable_space_range_union_singleton, let f_seq := @simple_func.approx_on F β _ _ _ m _ hf.measurable (range f ∪ {0}) 0 (by simp) _, have hf_seq_meas : ∀ n, strongly_measurable[m] (f_seq n), from λ n, @simple_func.strongly_measurable β F m _ (f_seq n), have hf_seq_int : ∀ n, integrable (f_seq n) μ, from simple_func.integrable_approx_on_range (hf.mono hm).measurable hf_int, have hf_seq_int_m : ∀ n, integrable (f_seq n) (μ.trim hm), from λ n, (hf_seq_int n).trim hm (hf_seq_meas n) , have hf_seq_eq : ∀ n, ∫ x, f_seq n x ∂μ = ∫ x, f_seq n x ∂(μ.trim hm), from λ n, integral_trim_simple_func hm (f_seq n) (hf_seq_int n), have h_lim_1 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂μ)), { refine tendsto_integral_of_L1 f hf_int (eventually_of_forall hf_seq_int) _, exact simple_func.tendsto_approx_on_range_L1_nnnorm (hf.mono hm).measurable hf_int, }, have h_lim_2 : at_top.tendsto (λ n, ∫ x, f_seq n x ∂μ) (𝓝 (∫ x, f x ∂(μ.trim hm))), { simp_rw hf_seq_eq, refine @tendsto_integral_of_L1 β F _ _ _ m (μ.trim hm) _ f (hf_int.trim hm hf) _ _ (eventually_of_forall hf_seq_int_m) _, exact @simple_func.tendsto_approx_on_range_L1_nnnorm β F m _ _ _ f _ _ hf.measurable (hf_int.trim hm hf), }, exact tendsto_nhds_unique h_lim_1 h_lim_2, end lemma integral_trim_ae (hm : m ≤ m0) {f : β → F} (hf : ae_strongly_measurable f (μ.trim hm)) : ∫ x, f x ∂μ = ∫ x, f x ∂(μ.trim hm) := begin rw [integral_congr_ae (ae_eq_of_ae_eq_trim hf.ae_eq_mk), integral_congr_ae hf.ae_eq_mk], exact integral_trim hm hf.strongly_measurable_mk, end lemma ae_eq_trim_of_strongly_measurable [topological_space γ] [metrizable_space γ] (hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.trim hm] g := begin rwa [eventually_eq, ae_iff, trim_measurable_set_eq hm _], exact (hf.measurable_set_eq_fun hg).compl end lemma ae_eq_trim_iff [topological_space γ] [metrizable_space γ] (hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) : f =ᵐ[μ.trim hm] g ↔ f =ᵐ[μ] g := ⟨ae_eq_of_ae_eq_trim, ae_eq_trim_of_strongly_measurable hm hf hg⟩ lemma ae_le_trim_of_strongly_measurable [linear_order γ] [topological_space γ] [order_closed_topology γ] [pseudo_metrizable_space γ] (hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) (hfg : f ≤ᵐ[μ] g) : f ≤ᵐ[μ.trim hm] g := begin rwa [eventually_le, ae_iff, trim_measurable_set_eq hm _], exact (hf.measurable_set_le hg).compl, end lemma ae_le_trim_iff [linear_order γ] [topological_space γ] [order_closed_topology γ] [pseudo_metrizable_space γ] (hm : m ≤ m0) {f g : β → γ} (hf : strongly_measurable[m] f) (hg : strongly_measurable[m] g) : f ≤ᵐ[μ.trim hm] g ↔ f ≤ᵐ[μ] g := ⟨ae_le_of_ae_le_trim, ae_le_trim_of_strongly_measurable hm hf hg⟩ end integral_trim section snorm_bound variables {m0 : measurable_space α} {μ : measure α} lemma snorm_one_le_of_le {r : ℝ≥0} {f : α → ℝ} (hfint : integrable f μ) (hfint' : 0 ≤ ∫ x, f x ∂μ) (hf : ∀ᵐ ω ∂μ, f ω ≤ r) : snorm f 1 μ ≤ 2 * μ set.univ * r := begin by_cases hr : r = 0, { suffices : f =ᵐ[μ] 0, { rw [snorm_congr_ae this, snorm_zero, hr, ennreal.coe_zero, mul_zero], exact le_rfl }, rw [hr, nonneg.coe_zero] at hf, have hnegf : ∫ x, -f x ∂μ = 0, { rw [integral_neg, neg_eq_zero], exact le_antisymm (integral_nonpos_of_ae hf) hfint' }, have := (integral_eq_zero_iff_of_nonneg_ae _ hfint.neg).1 hnegf, { filter_upwards [this] with ω hω, rwa [pi.neg_apply, pi.zero_apply, neg_eq_zero] at hω }, { filter_upwards [hf] with ω hω, rwa [pi.zero_apply, pi.neg_apply, right.nonneg_neg_iff] } }, by_cases hμ : is_finite_measure μ, swap, { have : μ set.univ = ∞, { by_contra hμ', exact hμ (is_finite_measure.mk $ lt_top_iff_ne_top.2 hμ') }, rw [this, ennreal.mul_top, if_neg, ennreal.top_mul, if_neg], { exact le_top }, { simp [hr] }, { norm_num } }, haveI := hμ, rw [integral_eq_integral_pos_part_sub_integral_neg_part hfint, sub_nonneg] at hfint', have hposbdd : ∫ ω, max (f ω) 0 ∂μ ≤ (μ set.univ).to_real • r, { rw ← integral_const, refine integral_mono_ae hfint.real_to_nnreal (integrable_const r) _, filter_upwards [hf] with ω hω using real.to_nnreal_le_iff_le_coe.2 hω }, rw [mem_ℒp.snorm_eq_integral_rpow_norm one_ne_zero ennreal.one_ne_top (mem_ℒp_one_iff_integrable.2 hfint), ennreal.of_real_le_iff_le_to_real (ennreal.mul_ne_top (ennreal.mul_ne_top ennreal.two_ne_top $ @measure_ne_top _ _ _ hμ _) ennreal.coe_ne_top)], simp_rw [ennreal.one_to_real, _root_.inv_one, real.rpow_one, real.norm_eq_abs, ← max_zero_add_max_neg_zero_eq_abs_self, ← real.coe_to_nnreal'], rw integral_add hfint.real_to_nnreal, { simp only [real.coe_to_nnreal', ennreal.to_real_mul, ennreal.to_real_bit0, ennreal.one_to_real, ennreal.coe_to_real] at hfint' ⊢, refine (add_le_add_left hfint' _).trans _, rwa [← two_mul, mul_assoc, mul_le_mul_left (two_pos : (0 : ℝ) < 2)] }, { exact hfint.neg.sup (integrable_zero _ _ μ) } end lemma snorm_one_le_of_le' {r : ℝ} {f : α → ℝ} (hfint : integrable f μ) (hfint' : 0 ≤ ∫ x, f x ∂μ) (hf : ∀ᵐ ω ∂μ, f ω ≤ r) : snorm f 1 μ ≤ 2 * μ set.univ * ennreal.of_real r := begin refine snorm_one_le_of_le hfint hfint' _, simp only [real.coe_to_nnreal', le_max_iff], filter_upwards [hf] with ω hω using or.inl hω, end end snorm_bound end measure_theory
69693430e38f3e8c996be20c0eed1ad592c0cf23
9dc8cecdf3c4634764a18254e94d43da07142918
/src/analysis/complex/upper_half_plane/functions_bounded_at_infty.lean
d8732563824f19c21b76599728e4e040a724b908
[ "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,708
lean
/- Copyright (c) 2022 Chris Birkbeck. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Birkbeck, David Loeffler -/ import algebra.module.submodule.basic import analysis.complex.upper_half_plane.basic import order.filter.zero_and_bounded_at_filter /-! # Bounded at infinity For complex valued functions on the upper half plane, this file defines the filter `at_im_infty` required for defining when functions are bounded at infinity and zero at infinity. Both of which are relevant for defining modular forms. -/ open complex filter open_locale topological_space upper_half_plane noncomputable theory namespace upper_half_plane /-- Filter for approaching `i∞`. -/ def at_im_infty := filter.at_top.comap upper_half_plane.im lemma at_im_infty_basis : (at_im_infty).has_basis (λ _, true) (λ (i : ℝ), im ⁻¹' set.Ici i) := filter.has_basis.comap upper_half_plane.im filter.at_top_basis lemma at_im_infty_mem (S : set ℍ) : S ∈ at_im_infty ↔ (∃ A : ℝ, ∀ z : ℍ, A ≤ im z → z ∈ S) := begin simp only [at_im_infty, filter.mem_comap', filter.mem_at_top_sets, ge_iff_le, set.mem_set_of_eq, upper_half_plane.coe_im], refine ⟨λ ⟨a, h⟩, ⟨a, (λ z hz, h (im z) hz rfl)⟩, _⟩, rintro ⟨A, h⟩, refine ⟨A, λ b hb x hx, h x _⟩, rwa hx, end /-- A function ` f : ℍ → α` is bounded at infinity if it is bounded along `at_im_infty`. -/ def is_bounded_at_im_infty {α : Type*} [has_norm α] [has_one (ℍ → α)] (f : ℍ → α) : Prop := bounded_at_filter at_im_infty f /-- A function ` f : ℍ → α` is zero at infinity it is zero along `at_im_infty`. -/ def is_zero_at_im_infty {α : Type*} [has_zero α] [topological_space α] (f : ℍ → α) : Prop := zero_at_filter at_im_infty f lemma zero_form_is_bounded_at_im_infty {α : Type*} [normed_field α] : is_bounded_at_im_infty (0 : ℍ → α) := zero_is_bounded_at_filter at_im_infty /-- Module of functions that are zero at infinity. -/ def zero_at_im_infty_submodule (α : Type*) [normed_field α] : submodule α (ℍ → α) := zero_at_filter_submodule at_im_infty /-- ubalgebra of functions that are bounded at infinity. -/ def bounded_at_im_infty_subalgebra (α : Type*) [normed_field α] : subalgebra α (ℍ → α) := bounded_filter_subalgebra at_im_infty lemma prod_of_bounded_is_bounded {f g : ℍ → ℂ} (hf : is_bounded_at_im_infty f) (hg : is_bounded_at_im_infty g) : is_bounded_at_im_infty (f * g) := by simpa only [pi.one_apply, mul_one, norm_eq_abs, complex.abs_mul] using hf.mul hg @[simp] lemma bounded_mem (f : ℍ → ℂ) : is_bounded_at_im_infty f ↔ ∃ (M A : ℝ), ∀ z : ℍ, A ≤ im z → abs (f z) ≤ M := begin simp [is_bounded_at_im_infty, bounded_at_filter, asymptotics.is_O_iff, filter.eventually, at_im_infty_mem], end lemma zero_at_im_infty (f : ℍ → ℂ) : is_zero_at_im_infty f ↔ ∀ ε : ℝ, 0 < ε → ∃ A : ℝ, ∀ z : ℍ, A ≤ im z → abs (f z) ≤ ε := begin rw [is_zero_at_im_infty, zero_at_filter, tendsto_iff_forall_eventually_mem], split, { simp_rw [filter.eventually, at_im_infty_mem], intros h ε hε, simpa using (h (metric.closed_ball (0 : ℂ) ε) (metric.closed_ball_mem_nhds (0 : ℂ) hε))}, { simp_rw metric.mem_nhds_iff, intros h s hs, simp_rw [filter.eventually, at_im_infty_mem], obtain ⟨ε, h1, h2⟩ := hs, have h11 : 0 < (ε/2), by {linarith,}, obtain ⟨A, hA⟩ := (h (ε/2) h11), use A, intros z hz, have hzs : f z ∈ s, { apply h2, simp only [mem_ball_zero_iff, norm_eq_abs], apply lt_of_le_of_lt (hA z hz), linarith }, apply hzs,} end end upper_half_plane
ad1826893d5bb5b4ede55cdf7b0c654e823577aa
57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d
/tests/lean/run/synth1.lean
767a7b7912ba66d3206bd30fd74060198cf07a1b
[ "Apache-2.0" ]
permissive
collares/lean4
861a9269c4592bce49b71059e232ff0bfe4594cc
52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee
refs/heads/master
1,691,419,031,324
1,618,678,138,000
1,618,678,138,000
358,989,750
0
0
Apache-2.0
1,618,696,333,000
1,618,696,333,000
null
UTF-8
Lean
false
false
1,553
lean
import Lean.Meta open Lean open Lean.Meta class HasCoerce (a b : Type) := (coerce : a → b) def coerce {a b : Type} [HasCoerce a b] : a → b := @HasCoerce.coerce a b _ instance coerceTrans {a b c : Type} [HasCoerce b c] [HasCoerce a b] : HasCoerce a c := ⟨fun x => coerce (coerce x : b)⟩ instance coerceBoolToProp : HasCoerce Bool Prop := ⟨fun y => y = true⟩ instance coerceDecidableEq (x : Bool) : Decidable (coerce x) := inferInstanceAs (Decidable (x = true)) instance coerceNatToBool : HasCoerce Nat Bool := ⟨fun x => x == 0⟩ instance coerceNatToInt : HasCoerce Nat Int := ⟨fun x => Int.ofNat x⟩ def print {α} [ToString α] (a : α) : MetaM Unit := trace[Meta.synthInstance] (toString a) def tst1 : MetaM Unit := do let inst ← mkAppM `HasCoerce #[mkConst `Nat, mkSort levelZero] let r ← synthInstance inst print r set_option trace.Meta.synthInstance true in set_option trace.Meta.synthInstance.tryResolve false in #eval tst1 def tst2 : MetaM Unit := do let inst ← mkAppM `Bind #[mkConst `IO] -- globalInstances ← getGlobalInstances -- print (format globalInstances) -- result ← globalInstances.getUnify inst -- print result let r ← synthInstance inst print r pure () set_option trace.Meta.synthInstance true in set_option trace.Meta.synthInstance.tryResolve false in #eval tst2 def tst3 : MetaM Unit := do let inst ← mkAppM `BEq #[mkConst `Nat] let r ← synthInstance inst print r pure () set_option trace.Meta.synthInstance true in set_option trace.Meta.synthInstance.tryResolve false in #eval tst3