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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3a34f78ed6724b8d8beb17b8313c053defbca70d | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/combinators1.lean | 5cf58034b5aa0c76dfbf05d4aad171ae8cfe38ef | [
"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 | 492 | lean | open tactic
example (p q : Prop) : p → q → (p ∧ p) ∧ q :=
by do
intros, constructor, focus [trace "first goal" >> trace_state >> constructor >> skip, trace "--- Second goal: " >> trace_state >> assumption],
trace "--- After", trace_state,
solve [trace "should not work", assumption],
first [trace "should not work" >> failed, constructor >> skip, trace "should work" >> assumption]
example (p q : Prop) : p → q → p ∧ q :=
by do intros, constructor >> skip; assumption
|
7d1c3a3511b2dd99a003f4c926bcf889841c515e | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/continuous_function/t0_sierpinski.lean | 5c8bf236ec1460a511a532a314303265e42043a7 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 2,422 | lean | /-
Copyright (c) 2022 Ivan Sadofschi Costa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ivan Sadofschi Costa
-/
import topology.order
import topology.sets.opens
import topology.continuous_function.basic
/-!
# Any T0 space embeds in a product of copies of the Sierpinski space.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We consider `Prop` with the Sierpinski topology. If `X` is a topological space, there is a
continuous map `product_of_mem_opens` from `X` to `opens X → Prop` which is the product of the maps
`X → Prop` given by `x ↦ x ∈ u`.
The map `product_of_mem_opens` is always inducing. Whenever `X` is T0, `product_of_mem_opens` is
also injective and therefore an embedding.
-/
noncomputable theory
namespace topological_space
lemma eq_induced_by_maps_to_sierpinski (X : Type*) [t : topological_space X] :
t = ⨅ (u : opens X), sierpinski_space.induced (∈ u) :=
begin
apply le_antisymm,
{ rw [le_infi_iff],
exact λ u, continuous.le_induced (is_open_iff_continuous_mem.mp u.2) },
{ intros u h,
rw ← generate_from_Union_is_open,
apply is_open_generate_from_of_mem,
simp only [set.mem_Union, set.mem_set_of_eq, is_open_induced_iff],
exact ⟨⟨u, h⟩, {true}, is_open_singleton_true, by simp [set.preimage]⟩ },
end
variables (X : Type*) [topological_space X]
/--
The continuous map from `X` to the product of copies of the Sierpinski space, (one copy for each
open subset `u` of `X`). The `u` coordinate of `product_of_mem_opens x` is given by `x ∈ u`.
-/
def product_of_mem_opens : C(X, opens X → Prop) :=
{ to_fun := λ x u, x ∈ u,
continuous_to_fun := continuous_pi_iff.2 (λ u, continuous_Prop.2 u.is_open) }
lemma product_of_mem_opens_inducing : inducing (product_of_mem_opens X) :=
begin
convert inducing_infi_to_pi (λ (u : opens X) (x : X), x ∈ u),
apply eq_induced_by_maps_to_sierpinski,
end
lemma product_of_mem_opens_injective [t0_space X] : function.injective (product_of_mem_opens X) :=
begin
intros x1 x2 h,
apply inseparable.eq,
rw [←inducing.inseparable_iff (product_of_mem_opens_inducing X), h],
end
theorem product_of_mem_opens_embedding [t0_space X] : embedding (product_of_mem_opens X) :=
embedding.mk (product_of_mem_opens_inducing X) (product_of_mem_opens_injective X)
end topological_space
|
ecba9026d21b2846e27b0ea43882c84c0a18c5a7 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/analysis/complex/polynomial_auto.lean | e3290b139b96d85b09573e12c7cfac0a480ea529 | [] | 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 | 865 | lean | /-
Copyright (c) 2019 Chris Hughes All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.algebra.polynomial
import Mathlib.analysis.special_functions.pow
import Mathlib.PostPort
namespace Mathlib
/-!
# The fundamental theorem of algebra
This file proves that every nonconstant complex polynomial has a root.
-/
namespace complex
/- The following proof uses the method given at
<https://ncatlab.org/nlab/show/fundamental+theorem+of+algebra#classical_fta_via_advanced_calculus> -/
/-- The fundamental theorem of algebra. Every non constant complex polynomial
has a root -/
theorem exists_root {f : polynomial ℂ} (hf : 0 < polynomial.degree f) :
∃ (z : ℂ), polynomial.is_root f z :=
sorry
end Mathlib |
df0535564d1be08318aaf594d52485b1a34e41de | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/bornology/basic.lean | 6d518439fe5318e034cce6d4d431a2c831ed22a1 | [
"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 | 10,204 | lean | /-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import order.filter.cofinite
/-!
# Basic theory of bornology
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We develop the basic theory of bornologies. Instead of axiomatizing bounded sets and defining
bornologies in terms of those, we recognize that the cobounded sets form a filter and define a
bornology as a filter of cobounded sets which contains the cofinite filter. This allows us to make
use of the extensive library for filters, but we also provide the relevant connecting results for
bounded sets.
The specification of a bornology in terms of the cobounded filter is equivalent to the standard
one (e.g., see [Bourbaki, *Topological Vector Spaces*][bourbaki1987], **covering bornology**, now
often called simply **bornology**) in terms of bounded sets (see `bornology.of_bounded`,
`is_bounded.union`, `is_bounded.subset`), except that we do not allow the empty bornology (that is,
we require that *some* set must be bounded; equivalently, `∅` is bounded). In the literature the
cobounded filter is generally referred to as the *filter at infinity*.
## Main definitions
- `bornology α`: a class consisting of `cobounded : filter α` and a proof that this filter
contains the `cofinite` filter.
- `bornology.is_cobounded`: the predicate that a set is a member of the `cobounded α` filter. For
`s : set α`, one should prefer `bornology.is_cobounded s` over `s ∈ cobounded α`.
- `bornology.is_bounded`: the predicate that states a set is bounded (i.e., the complement of a
cobounded set). One should prefer `bornology.is_bounded s` over `sᶜ ∈ cobounded α`.
- `bounded_space α`: a class extending `bornology α` with the condition
`bornology.is_bounded (set.univ : set α)`
Although use of `cobounded α` is discouraged for indicating the (co)boundedness of individual sets,
it is intended for regular use as a filter on `α`.
-/
open set filter
variables {ι α β : Type*}
/-- A **bornology** on a type `α` is a filter of cobounded sets which contains the cofinite filter.
Such spaces are equivalently specified by their bounded sets, see `bornology.of_bounded`
and `bornology.ext_iff_is_bounded`-/
@[ext]
class bornology (α : Type*) :=
(cobounded [] : filter α)
(le_cofinite [] : cobounded ≤ cofinite)
/-- A constructor for bornologies by specifying the bounded sets,
and showing that they satisfy the appropriate conditions. -/
@[simps]
def bornology.of_bounded {α : Type*} (B : set (set α))
(empty_mem : ∅ ∈ B) (subset_mem : ∀ s₁ ∈ B, ∀ s₂ : set α, s₂ ⊆ s₁ → s₂ ∈ B)
(union_mem : ∀ s₁ s₂ ∈ B, s₁ ∪ s₂ ∈ B) (singleton_mem : ∀ x, {x} ∈ B) :
bornology α :=
{ cobounded :=
{ sets := {s : set α | sᶜ ∈ B},
univ_sets := by rwa ←compl_univ at empty_mem,
sets_of_superset := λ x y hx hy, subset_mem xᶜ hx yᶜ (compl_subset_compl.mpr hy),
inter_sets := λ x y hx hy, by simpa [compl_inter] using union_mem xᶜ hx yᶜ hy, },
le_cofinite :=
begin
rw le_cofinite_iff_compl_singleton_mem,
intros x,
change {x}ᶜᶜ ∈ B,
rw compl_compl,
exact singleton_mem x
end }
/-- A constructor for bornologies by specifying the bounded sets,
and showing that they satisfy the appropriate conditions. -/
@[simps]
def bornology.of_bounded' {α : Type*} (B : set (set α))
(empty_mem : ∅ ∈ B) (subset_mem : ∀ s₁ ∈ B, ∀ s₂ : set α, s₂ ⊆ s₁ → s₂ ∈ B)
(union_mem : ∀ s₁ s₂ ∈ B, s₁ ∪ s₂ ∈ B) (sUnion_univ : ⋃₀ B = univ) :
bornology α :=
bornology.of_bounded B empty_mem subset_mem union_mem $ λ x,
begin
rw sUnion_eq_univ_iff at sUnion_univ,
rcases sUnion_univ x with ⟨s, hs, hxs⟩,
exact subset_mem s hs {x} (singleton_subset_iff.mpr hxs)
end
namespace bornology
section
variables [bornology α] {s t : set α} {x : α}
/-- `is_cobounded` is the predicate that `s` is in the filter of cobounded sets in the ambient
bornology on `α` -/
def is_cobounded (s : set α) : Prop := s ∈ cobounded α
/-- `is_bounded` is the predicate that `s` is bounded relative to the ambient bornology on `α`. -/
def is_bounded (s : set α) : Prop := is_cobounded sᶜ
lemma is_cobounded_def {s : set α} : is_cobounded s ↔ s ∈ cobounded α := iff.rfl
lemma is_bounded_def {s : set α} : is_bounded s ↔ sᶜ ∈ cobounded α := iff.rfl
@[simp] lemma is_bounded_compl_iff : is_bounded sᶜ ↔ is_cobounded s :=
by rw [is_bounded_def, is_cobounded_def, compl_compl]
@[simp] lemma is_cobounded_compl_iff : is_cobounded sᶜ ↔ is_bounded s := iff.rfl
alias is_bounded_compl_iff ↔ is_bounded.of_compl is_cobounded.compl
alias is_cobounded_compl_iff ↔ is_cobounded.of_compl is_bounded.compl
@[simp] lemma is_bounded_empty : is_bounded (∅ : set α) :=
by { rw [is_bounded_def, compl_empty], exact univ_mem}
@[simp] lemma is_bounded_singleton : is_bounded ({x} : set α) :=
by {rw [is_bounded_def], exact le_cofinite _ (finite_singleton x).compl_mem_cofinite}
@[simp] lemma is_cobounded_univ : is_cobounded (univ : set α) := univ_mem
@[simp] lemma is_cobounded_inter : is_cobounded (s ∩ t) ↔ is_cobounded s ∧ is_cobounded t :=
inter_mem_iff
lemma is_cobounded.inter (hs : is_cobounded s) (ht : is_cobounded t) : is_cobounded (s ∩ t) :=
is_cobounded_inter.2 ⟨hs, ht⟩
@[simp] lemma is_bounded_union : is_bounded (s ∪ t) ↔ is_bounded s ∧ is_bounded t :=
by simp only [← is_cobounded_compl_iff, compl_union, is_cobounded_inter]
lemma is_bounded.union (hs : is_bounded s) (ht : is_bounded t) : is_bounded (s ∪ t) :=
is_bounded_union.2 ⟨hs, ht⟩
lemma is_cobounded.superset (hs : is_cobounded s) (ht : s ⊆ t) : is_cobounded t :=
mem_of_superset hs ht
lemma is_bounded.subset (ht : is_bounded t) (hs : s ⊆ t) : is_bounded s :=
ht.superset (compl_subset_compl.mpr hs)
@[simp]
lemma sUnion_bounded_univ : (⋃₀ {s : set α | is_bounded s}) = univ :=
sUnion_eq_univ_iff.2 $ λ a, ⟨{a}, is_bounded_singleton, mem_singleton a⟩
lemma comap_cobounded_le_iff [bornology β] {f : α → β} :
(cobounded β).comap f ≤ cobounded α ↔ ∀ ⦃s⦄, is_bounded s → is_bounded (f '' s) :=
begin
refine ⟨λ h s hs, _, λ h t ht,
⟨(f '' tᶜ)ᶜ, h $ is_cobounded.compl ht, compl_subset_comm.1 $ subset_preimage_image _ _⟩⟩,
obtain ⟨t, ht, hts⟩ := h hs.compl,
rw [subset_compl_comm, ←preimage_compl] at hts,
exact (is_cobounded.compl ht).subset ((image_subset f hts).trans $ image_preimage_subset _ _),
end
end
lemma ext_iff' {t t' : bornology α} :
t = t' ↔ ∀ s, (@cobounded α t).sets s ↔ (@cobounded α t').sets s :=
(ext_iff _ _).trans filter.ext_iff
lemma ext_iff_is_bounded {t t' : bornology α} :
t = t' ↔ ∀ s, @is_bounded α t s ↔ @is_bounded α t' s :=
⟨λ h s, h ▸ iff.rfl, λ h, by { ext, simpa only [is_bounded_def, compl_compl] using h sᶜ, }⟩
variables {s : set α}
lemma is_cobounded_of_bounded_iff (B : set (set α)) {empty_mem subset_mem union_mem sUnion_univ} :
@is_cobounded _ (of_bounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ sᶜ ∈ B := iff.rfl
lemma is_bounded_of_bounded_iff (B : set (set α)) {empty_mem subset_mem union_mem sUnion_univ} :
@is_bounded _ (of_bounded B empty_mem subset_mem union_mem sUnion_univ) s ↔ s ∈ B :=
by rw [is_bounded_def, ←filter.mem_sets, of_bounded_cobounded_sets, set.mem_set_of_eq, compl_compl]
variables [bornology α]
lemma is_cobounded_bInter {s : set ι} {f : ι → set α} (hs : s.finite) :
is_cobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, is_cobounded (f i) :=
bInter_mem hs
@[simp] lemma is_cobounded_bInter_finset (s : finset ι) {f : ι → set α} :
is_cobounded (⋂ i ∈ s, f i) ↔ ∀ i ∈ s, is_cobounded (f i) :=
bInter_finset_mem s
@[simp] lemma is_cobounded_Inter [finite ι] {f : ι → set α} :
is_cobounded (⋂ i, f i) ↔ ∀ i, is_cobounded (f i) :=
Inter_mem
lemma is_cobounded_sInter {S : set (set α)} (hs : S.finite) :
is_cobounded (⋂₀ S) ↔ ∀ s ∈ S, is_cobounded s :=
sInter_mem hs
lemma is_bounded_bUnion {s : set ι} {f : ι → set α} (hs : s.finite) :
is_bounded (⋃ i ∈ s, f i) ↔ ∀ i ∈ s, is_bounded (f i) :=
by simp only [← is_cobounded_compl_iff, compl_Union, is_cobounded_bInter hs]
lemma is_bounded_bUnion_finset (s : finset ι) {f : ι → set α} :
is_bounded (⋃ i ∈ s, f i) ↔ ∀ i ∈ s, is_bounded (f i) :=
is_bounded_bUnion s.finite_to_set
lemma is_bounded_sUnion {S : set (set α)} (hs : S.finite) :
is_bounded (⋃₀ S) ↔ (∀ s ∈ S, is_bounded s) :=
by rw [sUnion_eq_bUnion, is_bounded_bUnion hs]
@[simp] lemma is_bounded_Union [finite ι] {s : ι → set α} :
is_bounded (⋃ i, s i) ↔ ∀ i, is_bounded (s i) :=
by rw [← sUnion_range, is_bounded_sUnion (finite_range s), forall_range_iff]
end bornology
open bornology
lemma set.finite.is_bounded [bornology α] {s : set α} (hs : s.finite) : is_bounded s :=
bornology.le_cofinite α hs.compl_mem_cofinite
instance : bornology punit := ⟨⊥, bot_le⟩
/-- The cofinite filter as a bornology -/
@[reducible] def bornology.cofinite : bornology α :=
{ cobounded := cofinite,
le_cofinite := le_rfl }
/-- A space with a `bornology` is a **bounded space** if `set.univ : set α` is bounded. -/
class bounded_space (α : Type*) [bornology α] : Prop :=
(bounded_univ : bornology.is_bounded (univ : set α))
namespace bornology
variables [bornology α]
lemma is_bounded_univ : is_bounded (univ : set α) ↔ bounded_space α :=
⟨λ h, ⟨h⟩, λ h, h.1⟩
lemma cobounded_eq_bot_iff : cobounded α = ⊥ ↔ bounded_space α :=
by rw [← is_bounded_univ, is_bounded_def, compl_univ, empty_mem_iff_bot]
variables [bounded_space α]
lemma is_bounded.all (s : set α) : is_bounded s := bounded_space.bounded_univ.subset s.subset_univ
lemma is_cobounded.all (s : set α) : is_cobounded s := compl_compl s ▸ is_bounded.all sᶜ
variable (α)
@[simp] lemma cobounded_eq_bot : cobounded α = ⊥ := cobounded_eq_bot_iff.2 ‹_›
end bornology
|
ba2540cb7837e258870ec898e43760cd60df1e3e | 76ce87faa6bc3c2aa9af5962009e01e04f2a074a | /04_Implication/00_intro.lean | 0057f157f73e4d5d80afe34375c7333d935755ee | [] | no_license | Mnormansell/Discrete-Notes | db423dd9206bbe7080aecb84b4c2d275b758af97 | 61f13b98be590269fc4822be7b47924a6ddc1261 | refs/heads/master | 1,585,412,435,424 | 1,540,919,483,000 | 1,540,919,483,000 | 148,684,638 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,570 | lean | /-
Given any two propositions, P and Q, we can form
the proposition, P → Q. That is the syntax of an
implications.
If P and Q are propositions, we read P → Q as
P implies Q. A proof of a proposition, P → Q,
is a program that that converts any proof of P
into a proof of Q. The type of such a program
is P → Q.
-/
/- Elimination Rule for Implication -/
/-
From two premises, (1) that "if it's raining then
the streets are wet," and (2) "it's raining,"" we
can surely derive as a conclusion that the streets
are wet. Combining "raining → streets wet" with
"raining" reduces to "streets wet." This is modus
ponens.
Let's abbreviate the proposition "it's raining",
as R, and let's also abbreviate the proposition,
"the streets are wet as W". We will then abbreviate
the proposition "if it's raining then the streets
are wet" as R → W.
Such a proposition is in the form of what we call
an implication. It can be pronounced as "R implies
W", or simply "if R is true then W must be true."
Note that by this latter reading, in a case where
R is not true, the implication says nothing about
whether W must be true or not. We will thus judge
an implication to be true if either R is false (in
which case the implications does not constrain W
to be any value), or if whenever R is true, W is,
too. The one situation under which we will not be
able to judge R → W to be true is if it can be
the case that R is true and yet W is not, as that
would contradict the meaning of an implication.
With these abbreviations in hand, we can write
an informal inference rule to capture the idea
we started with. If we know that a proposition,
R → W, is true, and we know that the proposition,
R, is true, then we can deduce that W therefore
must also be true. We can write this inference
rule informally like this:
R → W, R
-------- (→ elim)
W
This is the arrow (→) elimination rule?
In the rest of this chapter, we will formalize
this notion of inference by first presenting the
elimination rule for implication. We will see
that this rule not only formalizes Aristotle's
modus ponens rule of reasoning (it is one of
his fundamental "syllogisms"), but is also
corresponds to funtion application!
EXERCISE: When you apply a function that takes
an argument of type R and returns a value of
type W to a value of type P, what do you get?
-/
/-
Now let's specofy that R and W are arbitrary
propositions in the type theory of Lean. And
recall that to judge R → W to be true or to
judge either R or W to be true means that we
have proofs of these propositions. We can now
give a precise rule in type theory capturing
Aristotle's modus ponens: what it means to be
a function, and how function application works.
{ R W : Prop }, pfRtoW : R → W, pfR : R
--------------------------------------- (→-elim)
pfW: W
Here it is formalized as a function.
-/
def
arrow_elim
{ R W: Prop } (pfRtopfW : R → W) (pfR : R) : W :=
pfRtopfW pfR
/-
This program expresses the inference rule. The
name of the rule (a program) is arrow_elim. The
function takes (1) two propositions, R and W;
(2) a proof of R → W (itself a program that
converts and proof of R into a proof of W;
(3) a proof of R. If promises that if it is
given any values of these types, it will
return a proof of(a value of type) W. Given
values for its arguments it derives a proof
of W by applying that given function to that
givenvalue. The result will be a proof of (a
value of type) W.
We thus now have another way to pronounce this
inference rule: "if you have a function that can
turn any proof of R into a proof of W, and if you
have a proof of R, then you obtain a proof of W,
and you do it in particular by applying the
function to that value."
-/
/- In yet other words, if you've got a function
and you've got an argument value, then you can
eliminate the function (the "arrow") by applying
the function to that value, yielding a value of
the return type.
-/
/-
A concrete example of a program that serves as
a proof of W → R is found in our program, from
the 03_Conjunction chapter that turns any proof
of P ∧ Q (W) into a proof Q ∧ P (R).
We wrote that code so that for any propositions,
P and Q, for any proof of P ∧ Q, it returns a
proof of Q ∧ P. It can always do this because
from any proof of P ∧ Q, it can obtain separate
proofs of P and Q that it can then re-assembled
into a proof of Q ∧ P. That function is a proof
of this type: ∀ P Q: Prop, P ∧ Q → Q ∧ P. That
says, for any propositions, P and Q, a function
of this type turns a proof of P ∧ Q into a proof
of Q ∧ P. It thus proves P ∧ Q → Q ∧ P.
-/
/-
We want to give an example of the use of the
arrow-elim rule. In this example we use a new
(for us) capability of Lean: you can define
variables to be give given types without proofs,
i.e., as axioms.
Here (read the code) we assume that P and Q
are arbitrary propositions. We do not say
what specific propositions they are. Next
we assume that we have a proof that P → Q,
which will be represented as a program
that takes proofs of Ps and returns proofs
of Qs. Third we assumpe that we have some
proof of P. And finally we check to see
that the result of applying impl to pfP is
of type Q.
-/
variables P Q : Prop
variable impl : P → Q
variable pfP : P
#check (impl pfP)
#check (arrow_elim impl pfP)
/-
In Lean, a proof of R → W is given as a
program: a "recipe" for making a proof of W
out of a proof of R. With such a program in
hand, if we apply it to a proof of R it will
derive a proof of W.
-/
/-
EXAMPLE: implications involving true and false
-/
/-
Another way to read P → Q is "if P (is true)
then Q (is true)."
We now ask which of the following implications
can be proved?
true → true -- if true (is true) then true (is true)
true → false -- if true (is true) then false (is true)
false → true -- if false (is true) then true (is true)
false → false -- if false (is true) then false (is true)
EXERCISE: What is your intuition?
Hint: Remember the unit on true and false. Think about
the false elimination rule. Recall how many proofs there
are of the proposition, false.
-/
/- true → true -/
/-
Let's see one of the simplest of all possible
examples to make these anstract ideas concrete.
Consider the proposition, true → true. We can
read this as "true implies true". But for our
purposes, a better way to say it is, "if you
assume you are given a proof of true, then you
can construct and return a proof of true."
We can also see this proposition as the type of
any program that turns a proof of true into a
proof of true. That's going to be easy! Here it
is: a simple function definition in Lean. We call
the program timpt (for "true implies true"). It
takes an argument, pf_true, of type true, i.e.,
a proof of true, as an argument, and it builds
and returns a proof of true by just returning
the proof it was given! This function is thus
just the identity function of type true → true.
-/
def timpt ( pf_true: true ) : true := pf_true
theorem timpt_theorem : true → true := timpt
#check timpt
/-
If this program is given a proof, pf, of true,
it can and does return a proof of true. Let's
quickly verify that by looking at the value we
get when we apply the function (implication) to
true.intro, which is the always-available proof
of true.
-/
#reduce (timpt true.intro)
/-
Indeed, this program is in effect a proof
of true → true because if it's given any
proof of true (there's only one), it then
returns a proof of true.
Now we can see explicitly that this program
is a proof of the proposition, true → true,
by formalizing the proposition, true → true,
and giving the program as a proof!
-/
theorem true_imp_true : true → true := timpt
/-
And the type of the program, which we are
now interpreting as a proof of true → true,
is thus true → true. The program is a value
of the proposition, and type, true → true.
-/
#check timpt
/- true → false -/
/-
EXERCISE: Can you prove true → false? If
so, state and prove the theorem. If not,
explain exactly why you think you can't
do it.
-/
/- false → true -/
/-
EXERCISE: Prove false → true. The key to
doing this is to remember that applying
false.elim (think of it as a function) to
a proof of false proves anything at all.
-/
def fimpt (f: false): true :=
true.intro
/- false → false -/
/-
EXERCISE: Is it true that false → false?
Prove it. Hint: We wrote a program that
turned out to be a proof of true → true.
If you can write such a program, call it
fimpf, then use it to prove the theorem,
false_imp_false: false → false.
-/
def fimpf (f: false) : false :=
false.elim f
def fimpf' (f:false) : 0 = 1 :=
false.elim f
theorem false_imp_false : false → false := fimpf
/-
We summarize our findings in the following
table for implication.
true → true : proof, true
true → false : <no proof>
false → true : proof, true
false → false : proof, true
What's deeply interesting here is that
we're not just given these judgments as
unexplained pronouncements. We've *proved*
three of these judgments. The fourth we
could not prove, and we made an argument
that it can't be proved, but we haven't
yet formally proved, nor do even have a
way to say yet, that the proposition is
false. The best we can say at this time
is that we don't have a proof.
-/
#check true_imp_true -- (proof of) implication
#check true.intro -- (proof of) premise
#check (true_imp_true true.intro) -- conclusion!
/- *** → INTRODUCTION RULE -/
/-
The → introduction rules say that if
assuming that there is proof of P allows
you to derive a proof of Q, then one can
derive a proof of P → Q, discharging the
assumption.
To represent this rule as an inference
rule, we need a notation to represent
the idea that from an assumption that
there is a proof of P one can derive a
proof of Q. The notation used in most
logic books represents this notion as a
vertical dotted line from a P above to
a Q below. If one has such a derivation
then one can conclude P → Q. The idea
is that the derivation is in essence a
program; the program is the proof; and
it is a proof of the proposition, which
is to say, of the type, P → Q.
P
|
|
Q
-----
P → Q
The proof of a proposition, P → Q, in
Lean, is thus a program that takes an
argument of type P and returns a result
of type Q.
|
6e14eb40a76262ea464ee8bb8c3769f22f146c7b | dd4e652c749fea9ac77e404005cb3470e5f75469 | /src/missing_mathlib/algebra/group_power.lean | 7f85cbb3613536084d3e3f9e8c78f93e6eae4f4f | [] | no_license | skbaek/cvx | e32822ad5943541539966a37dee162b0a5495f55 | c50c790c9116f9fac8dfe742903a62bdd7292c15 | refs/heads/master | 1,623,803,010,339 | 1,618,058,958,000 | 1,618,058,958,000 | 176,293,135 | 3 | 2 | null | null | null | null | UTF-8 | Lean | false | false | 479 | lean | import algebra.group_power
universes u v
variable {α : Type u}
/- monoid -/
section monoid
variables [monoid α] {β : Type u} [add_monoid β]
lemma pow_eq_mul_pow_sub {α : Type*} [monoid α] (p : α) {m n : ℕ} (h : m ≤ n) : p ^ m * p ^ (n - m) = p ^ n :=
by rw [←pow_add, nat.add_sub_cancel' h]
lemma pow_eq_pow_sub_mul {α : Type*} [monoid α] (p : α) {m n : ℕ} (h : m ≤ n) : p ^ (n - m) * p ^ m = p ^ n :=
by rw [←pow_add, nat.sub_add_cancel h]
end monoid |
ad1c3e8394b33b23712e865c8e016332f3c7054a | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/countable_dense_linear_order.lean | f5deec2b668fb1a3209bfc197886098b1609c5fc | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,929 | 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 order.ideal
import data.finset.lattice
/-!
# The back and forth method and countable dense linear orders
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Results
Suppose `α β` are linear orders, with `α` countable and `β` dense, nontrivial. Then there is an
order embedding `α ↪ β`. If in addition `α` is dense, nonempty, without endpoints and `β` is
countable, without endpoints, then we can upgrade this to an order isomorphism `α ≃ β`.
The idea for both results is to consider "partial isomorphisms", which identify a finite subset of
`α` with a finite subset of `β`, and prove that for any such partial isomorphism `f` and `a : α`, we
can extend `f` to include `a` in its domain.
## References
https://en.wikipedia.org/wiki/Back-and-forth_method
## Tags
back and forth, dense, countable, order
-/
noncomputable theory
open_locale classical
namespace order
/-- Suppose `α` is a nonempty dense linear order without endpoints, and
suppose `lo`, `hi`, are finite subssets with all of `lo` strictly
before `hi`. Then there is an element of `α` strictly between `lo`
and `hi`. -/
lemma exists_between_finsets {α : Type*} [linear_order α]
[densely_ordered α] [no_min_order α] [no_max_order α] [nonem : nonempty α]
(lo hi : finset α) (lo_lt_hi : ∀ (x ∈ lo) (y ∈ hi), x < y) :
∃ m : α, (∀ x ∈ lo, x < m) ∧ (∀ y ∈ hi, m < y) :=
if nlo : lo.nonempty then
if nhi : hi.nonempty then -- both sets are nonempty, use densely_ordered
exists.elim (exists_between (lo_lt_hi _ (finset.max'_mem _ nlo) _ (finset.min'_mem _ nhi)))
(λ m hm, ⟨m, λ x hx, lt_of_le_of_lt (finset.le_max' lo x hx) hm.1,
λ y hy, lt_of_lt_of_le hm.2 (finset.min'_le hi y hy)⟩)
else -- upper set is empty, use `no_max_order`
exists.elim (exists_gt (finset.max' lo nlo)) (λ m hm,
⟨m, λ x hx, lt_of_le_of_lt (finset.le_max' lo x hx) hm,
λ y hy, (nhi ⟨y, hy⟩).elim⟩)
else
if nhi : hi.nonempty then -- lower set is empty, use `no_min_order`
exists.elim (exists_lt (finset.min' hi nhi)) (λ m hm,
⟨m, λ x hx, (nlo ⟨x, hx⟩).elim,
λ y hy, lt_of_lt_of_le hm (finset.min'_le hi y hy)⟩)
else -- both sets are empty, use nonempty
nonem.elim (λ m,
⟨m, λ x hx, (nlo ⟨x, hx⟩).elim,
λ y hy, (nhi ⟨y, hy⟩).elim⟩)
variables (α β : Type*) [linear_order α] [linear_order β]
/-- The type of partial order isomorphisms between `α` and `β` defined on finite subsets.
A partial order isomorphism is encoded as a finite subset of `α × β`, consisting
of pairs which should be identified. -/
def partial_iso : Type* :=
{ f : finset (α × β) // ∀ (p q ∈ f),
cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q) }
namespace partial_iso
instance : inhabited (partial_iso α β) := ⟨⟨∅, λ p h q, h.elim⟩⟩
instance : preorder (partial_iso α β) := subtype.preorder _
variables {α β}
/-- For each `a`, we can find a `b` in the codomain, such that `a`'s relation to
the domain of `f` is `b`'s relation to the image of `f`.
Thus, if `a` is not already in `f`, then we can extend `f` by sending `a` to `b`.
-/
lemma exists_across [densely_ordered β] [no_min_order β] [no_max_order β] [nonempty β]
(f : partial_iso α β) (a : α) :
∃ b : β, ∀ (p ∈ f.val), cmp (prod.fst p) a = cmp (prod.snd p) b :=
begin
by_cases h : ∃ b, (a, b) ∈ f.val,
{ cases h with b hb, exact ⟨b, λ p hp, f.prop _ hp _ hb⟩, },
have : ∀ (x ∈ (f.val.filter (λ (p : α × β), p.fst < a)).image prod.snd)
(y ∈ (f.val.filter (λ (p : α × β), a < p.fst)).image prod.snd),
x < y,
{ intros x hx y hy,
rw finset.mem_image at hx hy,
rcases hx with ⟨p, hp1, rfl⟩,
rcases hy with ⟨q, hq1, rfl⟩,
rw finset.mem_filter at hp1 hq1,
rw ←lt_iff_lt_of_cmp_eq_cmp (f.prop _ hp1.1 _ hq1.1),
exact lt_trans hp1.right hq1.right, },
cases exists_between_finsets _ _ this with b hb,
use b,
rintros ⟨p1, p2⟩ hp,
have : p1 ≠ a := λ he, h ⟨p2, he ▸ hp⟩,
cases lt_or_gt_of_ne this with hl hr,
{ have : p1 < a ∧ p2 < b := ⟨hl, hb.1 _ (finset.mem_image.mpr ⟨(p1, p2),
finset.mem_filter.mpr ⟨hp, hl⟩, rfl⟩)⟩,
rw [←cmp_eq_lt_iff, ←cmp_eq_lt_iff] at this, cc, },
{ have : a < p1 ∧ b < p2 := ⟨hr, hb.2 _ (finset.mem_image.mpr ⟨(p1, p2),
finset.mem_filter.mpr ⟨hp, hr⟩, rfl⟩)⟩,
rw [←cmp_eq_gt_iff, ←cmp_eq_gt_iff] at this, cc, },
end
/-- A partial isomorphism between `α` and `β` is also a partial isomorphism between `β` and `α`. -/
protected def comm : partial_iso α β → partial_iso β α :=
subtype.map (finset.image (equiv.prod_comm _ _)) $ λ f hf p hp q hq,
eq.symm $ hf ((equiv.prod_comm α β).symm p)
(by { rw [←finset.mem_coe, finset.coe_image, equiv.image_eq_preimage] at hp, rwa ←finset.mem_coe })
((equiv.prod_comm α β).symm q)
(by { rw [←finset.mem_coe, finset.coe_image, equiv.image_eq_preimage] at hq, rwa ←finset.mem_coe })
variable (β)
/-- The set of partial isomorphisms defined at `a : α`, together with a proof that any
partial isomorphism can be extended to one defined at `a`. -/
def defined_at_left [densely_ordered β] [no_min_order β] [no_max_order β] [nonempty β]
(a : α) : cofinal (partial_iso α β) :=
{ carrier := λ f, ∃ b : β, (a, b) ∈ f.val,
mem_gt := λ f, begin
cases exists_across f a with b a_b,
refine ⟨⟨insert (a, b) f.val, λ p hp q hq, _⟩, ⟨b, finset.mem_insert_self _ _⟩,
finset.subset_insert _ _⟩,
rw finset.mem_insert at hp hq,
rcases hp with rfl | pf;
rcases hq with rfl | qf,
{ simp only [cmp_self_eq_eq] },
{ rw cmp_eq_cmp_symm, exact a_b _ qf },
{ exact a_b _ pf },
{ exact f.prop _ pf _ qf },
end }
variables (α) {β}
/-- The set of partial isomorphisms defined at `b : β`, together with a proof that any
partial isomorphism can be extended to include `b`. We prove this by symmetry. -/
def defined_at_right [densely_ordered α] [no_min_order α] [no_max_order α] [nonempty α]
(b : β) : cofinal (partial_iso α β) :=
{ carrier := λ f, ∃ a, (a, b) ∈ f.val,
mem_gt := λ f, begin
rcases (defined_at_left α b).mem_gt f.comm with ⟨f', ⟨a, ha⟩, hl⟩,
refine ⟨f'.comm, ⟨a, _⟩, _⟩,
{ change (a, b) ∈ f'.val.image _,
rwa [←finset.mem_coe, finset.coe_image, equiv.image_eq_preimage] },
{ change _ ⊆ f'.val.image _,
rw [←finset.coe_subset, finset.coe_image, ← equiv.subset_image],
change f.val.image _ ⊆ _ at hl,
rwa [←finset.coe_subset, finset.coe_image] at hl }
end }
variable {α}
/-- Given an ideal which intersects `defined_at_left β a`, pick `b : β` such that
some partial function in the ideal maps `a` to `b`. -/
def fun_of_ideal [densely_ordered β] [no_min_order β] [no_max_order β] [nonempty β]
(a : α) (I : ideal (partial_iso α β)) :
(∃ f, f ∈ defined_at_left β a ∧ f ∈ I) → { b // ∃ f ∈ I, (a, b) ∈ subtype.val f } :=
classical.indefinite_description _ ∘ (λ ⟨f, ⟨b, hb⟩, hf⟩, ⟨b, f, hf, hb⟩)
/-- Given an ideal which intersects `defined_at_right α b`, pick `a : α` such that
some partial function in the ideal maps `a` to `b`. -/
def inv_of_ideal [densely_ordered α] [no_min_order α] [no_max_order α] [nonempty α]
(b : β) (I : ideal (partial_iso α β)) :
(∃ f, f ∈ defined_at_right α b ∧ f ∈ I) → { a // ∃ f ∈ I, (a, b) ∈ subtype.val f } :=
classical.indefinite_description _ ∘ (λ ⟨f, ⟨a, ha⟩, hf⟩, ⟨a, f, hf, ha⟩)
end partial_iso
open partial_iso
variables (α β)
/-- Any countable linear order embeds in any nontrivial dense linear order. -/
theorem embedding_from_countable_to_dense [encodable α] [densely_ordered β] [nontrivial β] :
nonempty (α ↪o β) :=
begin
rcases exists_pair_lt β with ⟨x, y, hxy⟩,
cases exists_between hxy with a ha,
haveI : nonempty (set.Ioo x y) := ⟨⟨a, ha⟩⟩,
let our_ideal : ideal (partial_iso α _) :=
ideal_of_cofinals default (defined_at_left (set.Ioo x y)),
let F := λ a, fun_of_ideal a our_ideal (cofinal_meets_ideal_of_cofinals _ _ a),
refine ⟨rel_embedding.trans (order_embedding.of_strict_mono (λ a, (F a).val) (λ a₁ a₂, _))
(order_embedding.subtype _)⟩,
rcases (F a₁).prop with ⟨f, hf, ha₁⟩,
rcases (F a₂).prop with ⟨g, hg, ha₂⟩,
rcases our_ideal.directed _ hf _ hg with ⟨m, hm, fm, gm⟩,
exact (lt_iff_lt_of_cmp_eq_cmp $ m.prop (a₁, _) (fm ha₁) (a₂, _) (gm ha₂)).mp
end
/-- Any two countable dense, nonempty linear orders without endpoints are order isomorphic. -/
theorem iso_of_countable_dense
[encodable α] [densely_ordered α] [no_min_order α] [no_max_order α] [nonempty α]
[encodable β] [densely_ordered β] [no_min_order β] [no_max_order β] [nonempty β] :
nonempty (α ≃o β) :=
let to_cofinal : α ⊕ β → cofinal (partial_iso α β) :=
λ p, sum.rec_on p (defined_at_left β) (defined_at_right α) in
let our_ideal : ideal (partial_iso α β) := ideal_of_cofinals default to_cofinal in
let F := λ a, fun_of_ideal a our_ideal (cofinal_meets_ideal_of_cofinals _ to_cofinal (sum.inl a)) in
let G := λ b, inv_of_ideal b our_ideal (cofinal_meets_ideal_of_cofinals _ to_cofinal (sum.inr b)) in
⟨order_iso.of_cmp_eq_cmp (λ a, (F a).val) (λ b, (G b).val) $ λ a b,
begin
rcases (F a).prop with ⟨f, hf, ha⟩,
rcases (G b).prop with ⟨g, hg, hb⟩,
rcases our_ideal.directed _ hf _ hg with ⟨m, hm, fm, gm⟩,
exact m.prop (a, _) (fm ha) (_, b) (gm hb)
end⟩
end order
|
245bc46f2a5fb132d2fcb65d1159fcb82426dc71 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/algebra/category/Module/basic.lean | 1560683c195cb171c46f3758287936ca9de996c2 | [
"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,705 | lean | /-
Copyright (c) 2019 Robert A. Spencer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert A. Spencer
-/
import algebra.module
import algebra.punit_instances
import category_theory.concrete_category
import linear_algebra.basic
open category_theory
universe u
variables (R : Type u) [ring R]
/-- The category of R-modules and their morphisms. -/
structure Module :=
(carrier : Type u)
[is_add_comm_group : add_comm_group carrier]
[is_module : module R carrier]
attribute [instance] Module.is_add_comm_group Module.is_module
namespace Module
-- TODO revisit this after #1438 merges, to check coercions and instances are handled consistently
instance : has_coe_to_sort (Module R) :=
{ S := Type u, coe := Module.carrier }
instance : concrete_category (Module.{u} R) :=
{ to_category :=
{ hom := λ M N, M →ₗ[R] N,
id := λ M, 1,
comp := λ A B C f g, g.comp f },
forget := { obj := λ R, R, map := λ R S f, (f : R → S) },
forget_faithful := { } }
def of (X : Type u) [add_comm_group X] [module R X] : Module R := ⟨R, X⟩
-- TODO: Once #1445 has merged, replace this with `has_zero_object (Module R)`
instance : has_zero (Module R) := ⟨of R punit⟩
variables (M N U : Module R)
@[simp] lemma id_apply (m : M) : (𝟙 M : M → M) m = m := rfl
@[simp] lemma coe_comp (f : M ⟶ N) (g : N ⟶ U) :
((f ≫ g) : M → U) = g ∘ f := rfl
instance hom_is_module_hom {M₁ M₂ : Module R} (f : M₁ ⟶ M₂) :
is_linear_map R (f : M₁ → M₂) := linear_map.is_linear _
end Module
instance (M : Type u) [add_comm_group M] [module R M] : has_coe (submodule R M) (Module R) :=
⟨ λ N, Module.of R N ⟩
|
16f3c03ce0ef15f5250d61e708809e4aa73ac282 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/group_theory/order_of_element.lean | 59774cf908312958cc5c2f1b2f91a7f47c6174cd | [
"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 | 46,937 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Julian Kuelshammer
-/
import algebra.big_operators.order
import group_theory.coset
import data.nat.totient
import data.int.gcd
import data.set.finite
/-!
# Order of an element
This file defines the order of an element of a finite group. For a finite group `G` the order of
`g ∈ G` is the minimal `n ≥ 1` such that `g ^ n = 1`.
## Main definitions
* `order_of` defines the order of an element `a` of a group `G`, by convention its value is `0` if
`a` has infinite order.
* `is_cyclic` is a predicate on a group stating that the group is cyclic.
## Main statements
* `is_cyclic_of_prime_card` proves that a finite group of prime order is cyclic.
* `is_simple_group_of_prime_card`, `is_simple_group.is_cyclic`,
and `is_simple_group.prime_card` classify finite simple abelian groups.
## Implementation details
The parts about `is_cyclic` are currently only available for multiplicatively written groups.
## Tags
order of an element, cyclic group
## TODO
* Move the first declarations until the definition of order to other files.
* Yury's suggestion: Redefine `order_of x := minimal_period (* x) 1`, this should make `to_additive`
easier.
* Add the attribute `@[to_additive]` to the declarations about `is_cyclic`, so that they work for
additive groups.
-/
open function
open_locale big_operators
universe u
variables {α : Type u} {s : set α} {a a₁ a₂ b c: α}
section order_of
section monoid
variables {α} [monoid α]
variables {H : Type u} [add_monoid H] {x : H}
open_locale classical
/-- `add_order_of h` is the additive order of the element `x`, i.e. the `n ≥ 1`, s. t. `n •ℕ x = 0`
if it exists. Otherwise, i.e. if `x` is of infinite order, then `add_order_of x` is `0` by
convention.-/
noncomputable def add_order_of (x : H) : ℕ :=
if h : ∃ n, 0 < n ∧ n •ℕ x = 0 then nat.find h else 0
/-- `order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `a ^ n = 1` if it exists.
Otherwise, i.e. if `a` is of infinite order, then `order_of a` is `0` by convention.-/
noncomputable def order_of (a : α) : ℕ :=
if h : ∃ n, 0 < n ∧ a ^ n = 1 then nat.find h else 0
attribute [to_additive add_order_of] order_of
@[simp] lemma add_order_of_of_mul_eq_order_of (a : α) :
add_order_of (additive.of_mul a) = order_of a :=
by simp [add_order_of, order_of, ← of_mul_pow]
@[simp] lemma order_of_of_add_eq_add_order_of (x : H) :
order_of (multiplicative.of_add x) = add_order_of x :=
by simp [add_order_of, order_of, ← of_add_nsmul]
lemma add_order_of_pos' {x : H} (h : ∃ n, 0 < n ∧ n •ℕ x = 0) : 0 < add_order_of x :=
begin
rw add_order_of,
split_ifs,
exact (nat.find_spec h).1
end
@[to_additive add_order_of_pos']
lemma order_of_pos' {a : α} (h : ∃ n, 0 < n ∧ a ^ n = 1) : 0 < order_of a :=
begin
rw order_of,
split_ifs,
exact (nat.find_spec h).1
end
lemma pow_order_of_eq_one (a : α): a ^ order_of a = 1 :=
begin
rw order_of,
split_ifs with hfin,
{ exact (nat.find_spec hfin).2 },
{ exact pow_zero a }
end
lemma add_order_of_nsmul_eq_zero (x : H) : (add_order_of x) •ℕ x = 0 :=
begin
apply multiplicative.of_add.injective,
rw of_add_nsmul,
exact pow_order_of_eq_one _,
end
attribute [to_additive add_order_of_nsmul_eq_zero] pow_order_of_eq_one
lemma add_order_of_eq_zero {a : H} (h : ∀n, 0 < n → n •ℕ a ≠ 0) : add_order_of a = 0 :=
begin
rw add_order_of,
split_ifs with hx,
{ exfalso,
cases hx with n hn,
exact (h n) hn.1 hn.2 },
{ refl }
end
@[to_additive add_order_of_eq_zero]
lemma order_of_eq_zero {a : α} (h : ∀n, 0 < n → a ^ n ≠ 1) : order_of a = 0 :=
begin
rw order_of,
split_ifs with hx,
{ exfalso,
cases hx with n hn,
exact (h n) hn.1 hn.2 },
{ refl }
end
lemma add_order_of_le_of_nsmul_eq_zero' {m : ℕ} (h : m < add_order_of x) : ¬ (0 < m ∧ m •ℕ x = 0) :=
begin
rw add_order_of at h,
split_ifs at h with hfin,
{ exact nat.find_min hfin h },
{ exact absurd h m.zero_le.not_lt }
end
@[to_additive add_order_of_le_of_nsmul_eq_zero']
lemma order_of_le_of_pow_eq_one' {m : ℕ} (h : m < order_of a) : ¬ (0 < m ∧ a ^ m = 1) :=
begin
rw order_of at h,
split_ifs at h with hfin,
{ exact nat.find_min hfin h },
{ exact absurd h m.zero_le.not_lt }
end
lemma add_order_of_le_of_nsmul_eq_zero {n : ℕ} (hn : 0 < n) (h : n •ℕ x = 0) : add_order_of x ≤ n :=
le_of_not_lt (mt add_order_of_le_of_nsmul_eq_zero' (by simp [hn, h]))
@[to_additive add_order_of_le_of_nsmul_eq_zero]
lemma order_of_le_of_pow_eq_one {n : ℕ} (hn : 0 < n) (h : a ^ n = 1) : order_of a ≤ n :=
le_of_not_lt (mt order_of_le_of_pow_eq_one' (by simp [hn, h]))
@[simp] lemma order_of_one : order_of (1 : α) = 1 :=
begin
apply le_antisymm,
{ exact order_of_le_of_pow_eq_one (nat.one_pos) (pow_one 1) },
{ exact nat.succ_le_of_lt ( order_of_pos' ⟨1, ⟨nat.one_pos, pow_one 1⟩⟩) }
end
@[simp] lemma add_order_of_zero : add_order_of (0 : H) = 1 :=
by simp [← order_of_of_add_eq_add_order_of]
attribute [to_additive add_order_of_zero] order_of_one
@[simp] lemma order_of_eq_one_iff : order_of a = 1 ↔ a = 1 :=
⟨λ h, by conv_lhs { rw [← pow_one a, ← h, pow_order_of_eq_one] }, λ h, by simp [h]⟩
@[simp] lemma add_order_of_eq_one_iff : add_order_of x = 1 ↔ x = 0 :=
by simp [← order_of_of_add_eq_add_order_of]
attribute [to_additive add_order_of_eq_one_iff] order_of_eq_one_iff
lemma pow_eq_mod_order_of {n : ℕ} : a ^ n = a ^ (n % order_of a) :=
calc a ^ n = a ^ (n % order_of a + order_of a * (n / order_of a)) : by rw [nat.mod_add_div]
... = a ^ (n % order_of a) : by simp [pow_add, pow_mul, pow_order_of_eq_one]
lemma nsmul_eq_mod_add_order_of {n : ℕ} : n •ℕ x = (n % add_order_of x) •ℕ x :=
begin
apply multiplicative.of_add.injective,
rw [← order_of_of_add_eq_add_order_of, of_add_nsmul, of_add_nsmul, pow_eq_mod_order_of],
end
attribute [to_additive nsmul_eq_mod_add_order_of] pow_eq_mod_order_of
lemma order_of_dvd_of_pow_eq_one {n : ℕ} (h : a ^ n = 1) : order_of a ∣ n :=
begin
rcases n.zero_le.eq_or_lt with rfl|h₁,
{ simp },
{ apply nat.dvd_of_mod_eq_zero,
by_contradiction h₂,
have h₃ : ¬ (0 < n % order_of a ∧ a ^ (n % order_of a) = 1) := order_of_le_of_pow_eq_one'
( nat.mod_lt _ ( order_of_pos' ⟨n, h₁, h⟩)),
push_neg at h₃,
specialize h₃ (nat.pos_of_ne_zero h₂),
rw ← pow_eq_mod_order_of at h₃,
exact h₃ h },
end
lemma add_order_of_dvd_of_nsmul_eq_zero {n : ℕ} (h : n •ℕ x = 0) : add_order_of x ∣ n :=
begin
apply_fun multiplicative.of_add at h,
rw ← order_of_of_add_eq_add_order_of,
rw of_add_nsmul at h,
exact order_of_dvd_of_pow_eq_one h,
end
attribute [to_additive add_order_of_dvd_of_nsmul_eq_zero] order_of_dvd_of_pow_eq_one
lemma add_order_of_dvd_iff_nsmul_eq_zero {n : ℕ} : add_order_of x ∣ n ↔ n •ℕ x = 0 :=
⟨λ h, by rw [nsmul_eq_mod_add_order_of, nat.mod_eq_zero_of_dvd h, zero_nsmul],
add_order_of_dvd_of_nsmul_eq_zero⟩
@[to_additive add_order_of_dvd_iff_nsmul_eq_zero]
lemma order_of_dvd_iff_pow_eq_one {n : ℕ} : order_of a ∣ n ↔ a ^ n = 1 :=
⟨λ h, by rw [pow_eq_mod_order_of, nat.mod_eq_zero_of_dvd h, pow_zero], order_of_dvd_of_pow_eq_one⟩
lemma commute.order_of_mul_dvd_lcm (h : commute a b) :
order_of (a * b) ∣ nat.lcm (order_of a) (order_of b) :=
by rw [order_of_dvd_iff_pow_eq_one, h.mul_pow, order_of_dvd_iff_pow_eq_one.mp
(nat.dvd_lcm_left _ _), order_of_dvd_iff_pow_eq_one.mp (nat.dvd_lcm_right _ _), one_mul]
lemma add_order_of_eq_prime {p : ℕ} [hp : fact p.prime]
(hg : p •ℕ x = 0) (hg1 : x ≠ 0) : add_order_of x = p :=
(hp.out.2 _ (add_order_of_dvd_of_nsmul_eq_zero hg)).resolve_left (mt add_order_of_eq_one_iff.1 hg1)
@[to_additive add_order_of_eq_prime]
lemma order_of_eq_prime {p : ℕ} [hp : fact p.prime]
(hg : a^p = 1) (hg1 : a ≠ 1) : order_of a = p :=
(hp.out.2 _ (order_of_dvd_of_pow_eq_one hg)).resolve_left (mt order_of_eq_one_iff.1 hg1)
open nat
-- An example on how to determine the order of an element of a finite group.
example : order_of (-1 : units ℤ) = 2 :=
begin
haveI : fact (prime 2) := ⟨prime_two⟩,
exact order_of_eq_prime (by { rw pow_two, simp }) (dec_trivial)
end
lemma add_order_of_eq_add_order_of_iff {A : Type*} [add_monoid A] {y : A} :
add_order_of x = add_order_of y ↔ ∀ n : ℕ, n •ℕ x = 0 ↔ n •ℕ y = 0 :=
begin
simp_rw ← add_order_of_dvd_iff_nsmul_eq_zero,
exact ⟨λ h n, by rw h, λ h, nat.dvd_antisymm ((h _).mpr (dvd_refl _)) ((h _).mp (dvd_refl _))⟩,
end
@[to_additive add_order_of_eq_add_order_of_iff]
lemma order_of_eq_order_of_iff {β : Type*} [monoid β] {b : β} :
order_of a = order_of b ↔ ∀ n : ℕ, a ^ n = 1 ↔ b ^ n = 1 :=
begin
simp_rw ← order_of_dvd_iff_pow_eq_one,
exact ⟨λ h n, by rw h, λ h, nat.dvd_antisymm ((h _).mpr (dvd_refl _)) ((h _).mp (dvd_refl _))⟩,
end
lemma add_order_of_injective {A B : Type*} [add_monoid A] [add_monoid B] (f : A →+ B)
(hf : function.injective f) (x : A) : add_order_of (f x) = add_order_of x :=
by simp_rw [add_order_of_eq_add_order_of_iff, ←f.map_nsmul, ←f.map_zero, hf.eq_iff, iff_self,
forall_const]
@[to_additive add_order_of_injective]
lemma order_of_injective {G H : Type*} [monoid G] [monoid H] (f : G →* H)
(hf : function.injective f) (σ : G) : order_of (f σ) = order_of σ :=
by simp_rw [order_of_eq_order_of_iff, ←f.map_pow, ←f.map_one, hf.eq_iff, iff_self, forall_const]
@[simp, norm_cast, to_additive] lemma order_of_submonoid {G : Type*} [monoid G] {H : submonoid G}
(σ : H) : order_of (σ : G) = order_of σ :=
order_of_injective H.subtype subtype.coe_injective σ
@[simp, norm_cast, to_additive] lemma order_of_subgroup {G : Type*} [group G] {H : subgroup G}
(σ : H) : order_of (σ : G) = order_of σ :=
order_of_injective H.subtype subtype.coe_injective σ
lemma add_order_of_eq_prime_pow {p k : ℕ} (hprime : prime p)
(hnot : ¬ (p ^ k) •ℕ x = 0) (hfin : (p ^ (k + 1)) •ℕ x = 0) : add_order_of x = p ^ (k + 1) :=
begin
apply nat.eq_prime_pow_of_dvd_least_prime_pow hprime;
{ rwa add_order_of_dvd_iff_nsmul_eq_zero }
end
@[to_additive add_order_of_eq_prime_pow]
lemma order_of_eq_prime_pow {p k : ℕ} (hprime : prime p)
(hnot : ¬ a ^ p ^ k = 1) (hfin : a ^ p ^ (k + 1) = 1) : order_of a = p ^ (k + 1) :=
begin
apply nat.eq_prime_pow_of_dvd_least_prime_pow hprime;
{ rwa order_of_dvd_iff_pow_eq_one }
end
variables (a) {n : ℕ}
lemma order_of_pow' (h : n ≠ 0) :
order_of (a ^ n) = order_of a / gcd (order_of a) n :=
begin
apply dvd_antisymm,
{ apply order_of_dvd_of_pow_eq_one,
rw [← pow_mul, ← nat.mul_div_assoc _ (gcd_dvd_left _ _), mul_comm,
nat.mul_div_assoc _ (gcd_dvd_right _ _), pow_mul, pow_order_of_eq_one, one_pow] },
{ have gcd_pos : 0 < gcd (order_of a) n := gcd_pos_of_pos_right _ (nat.pos_of_ne_zero h),
apply coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd gcd_pos),
apply dvd_of_mul_dvd_mul_right gcd_pos,
rw [nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc, nat.div_mul_cancel (gcd_dvd_right _ _),
mul_comm],
apply order_of_dvd_of_pow_eq_one,
rw [pow_mul, pow_order_of_eq_one] }
end
variables (x)
lemma add_order_of_nsmul' (h : n ≠ 0) :
add_order_of (n •ℕ x) = add_order_of x / gcd (add_order_of x) n :=
by simpa [← order_of_of_add_eq_add_order_of, of_add_nsmul] using order_of_pow' _ h
attribute [to_additive add_order_of_nsmul'] order_of_pow'
variable (n)
lemma order_of_pow'' (h : ∃ n, 0 < n ∧ a ^ n = 1) :
order_of (a ^ n) = order_of a / gcd (order_of a) n :=
begin
apply dvd_antisymm,
{ apply order_of_dvd_of_pow_eq_one,
rw [← pow_mul, ← nat.mul_div_assoc _ (gcd_dvd_left _ _), mul_comm,
nat.mul_div_assoc _ (gcd_dvd_right _ _), pow_mul, pow_order_of_eq_one, one_pow] },
{ have gcd_pos : 0 < gcd (order_of a) n := gcd_pos_of_pos_left n (order_of_pos' h),
apply coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd gcd_pos),
apply dvd_of_mul_dvd_mul_right gcd_pos,
rw [nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc,
nat.div_mul_cancel (gcd_dvd_right _ _), mul_comm],
apply order_of_dvd_of_pow_eq_one,
rw [pow_mul, pow_order_of_eq_one] }
end
lemma add_order_of_nsmul'' (h : ∃n, 0 < n ∧ n •ℕ x = 0) :
add_order_of (n •ℕ x) = add_order_of x / gcd (add_order_of x) n :=
begin
repeat { rw ← order_of_of_add_eq_add_order_of },
rwa [of_add_nsmul, order_of_pow''],
end
attribute [to_additive add_order_of_nsmul''] order_of_pow''
end monoid
section cancel_monoid
variables {α} [left_cancel_monoid α] (a)
variables {H : Type u} [add_left_cancel_monoid H] (x : H)
lemma pow_injective_aux {n m : ℕ} (h : n ≤ m)
(hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m :=
by_contradiction $ assume ne : n ≠ m,
have h₁ : m - n > 0, from nat.pos_of_ne_zero (by simp [nat.sub_eq_iff_eq_add h, ne.symm]),
have h₂ : m = n + (m - n) := (nat.add_sub_of_le h).symm,
have h₃ : a ^ (m - n) = 1,
by { rw [h₂, pow_add] at eq, apply mul_left_cancel, convert eq.symm, exact mul_one (a ^ n) },
have le : order_of a ≤ m - n, from order_of_le_of_pow_eq_one h₁ h₃,
have lt : m - n < order_of a,
from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm,
lt_irrefl _ (lt_of_le_of_lt le lt)
-- TODO: This lemma was originally private, but this doesn't seem to work with `to_additive`,
-- therefore the private got removed.
lemma nsmul_injective_aux {n m : ℕ} (h : n ≤ m)
(hm : m < add_order_of x) (eq : n •ℕ x = m •ℕ x) : n = m :=
begin
apply_fun multiplicative.of_add at eq,
rw [of_add_nsmul, of_add_nsmul] at eq,
rw ← order_of_of_add_eq_add_order_of at hm,
exact pow_injective_aux (multiplicative.of_add x) h hm eq,
end
attribute [to_additive nsmul_injective_aux] pow_injective_aux
lemma nsmul_injective_of_lt_add_order_of {n m : ℕ}
(hn : n < add_order_of x) (hm : m < add_order_of x) (eq : n •ℕ x = m •ℕ x) : n = m :=
(le_total n m).elim
(assume h, nsmul_injective_aux x h hm eq)
(assume h, (nsmul_injective_aux x h hn eq.symm).symm)
@[to_additive nsmul_injective_of_lt_add_order_of]
lemma pow_injective_of_lt_order_of {n m : ℕ}
(hn : n < order_of a) (hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m :=
(le_total n m).elim
(assume h, pow_injective_aux a h hm eq)
(assume h, (pow_injective_aux a h hn eq.symm).symm)
end cancel_monoid
section group
variables {α} [group α] {a}
variables {H : Type u} [add_group H] {x : H}
lemma gpow_eq_mod_order_of {i : ℤ} : a ^ i = a ^ (i % order_of a) :=
calc a ^ i = a ^ (i % order_of a + order_of a * (i / order_of a)) :
by rw [int.mod_add_div]
... = a ^ (i % order_of a) :
by simp [gpow_add, gpow_mul, pow_order_of_eq_one]
lemma gsmul_eq_mod_add_order_of {i : ℤ} : i •ℤ x = (i % add_order_of x) •ℤ x :=
begin
apply multiplicative.of_add.injective,
simp [of_add_gsmul, gpow_eq_mod_order_of],
end
attribute [to_additive gsmul_eq_mod_add_order_of] gpow_eq_mod_order_of
end group
section finite_monoid
variables {α} [fintype α] [monoid α]
variables {H : Type u} [fintype H] [add_monoid H]
lemma sum_card_add_order_of_eq_card_nsmul_eq_zero [decidable_eq H] {n : ℕ} (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ x : H, add_order_of x = m)).card
= (finset.univ.filter (λ x : H, n •ℕ x = 0)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n),
(finset.univ.filter (λ x : H, add_order_of x = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume x,
suffices : add_order_of x ≤ n ∧ add_order_of x ∣ n ↔ n •ℕ x = 0,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in
by rw [hm, mul_comm, mul_nsmul, add_order_of_nsmul_eq_zero, nsmul_zero],
λ h, ⟨add_order_of_le_of_nsmul_eq_zero hn h, add_order_of_dvd_of_nsmul_eq_zero h⟩⟩
end))
@[to_additive sum_card_add_order_of_eq_card_nsmul_eq_zero]
lemma sum_card_order_of_eq_card_pow_eq_one [decidable_eq α] {n : ℕ} (hn : 0 < n) :
∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ a : α, order_of a = m)).card
= (finset.univ.filter (λ a : α, a ^ n = 1)).card :=
calc ∑ m in (finset.range n.succ).filter (∣ n), (finset.univ.filter (λ a : α, order_of a = m)).card
= _ : (finset.card_bUnion (by { intros, apply finset.disjoint_filter.2, cc })).symm
... = _ : congr_arg finset.card (finset.ext (begin
assume a,
suffices : order_of a ≤ n ∧ order_of a ∣ n ↔ a ^ n = 1,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, one_pow],
λ h, ⟨order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h⟩⟩
end))
end finite_monoid
section finite_cancel_monoid
/-- TODO: Of course everything also works for right_cancel_monoids. -/
variables {α} [fintype α] [left_cancel_monoid α]
variables {H : Type u} [fintype H] [add_left_cancel_monoid H]
/-- TODO: Use this to show that a finite left cancellative monoid is a group.-/
lemma exists_pow_eq_one (a : α) : ∃i, 0 < i ∧ a ^ i = 1 :=
begin
have h : ¬ injective (λi:ℕ, a^i) := not_injective_infinite_fintype _,
have h' : ∃(i j : ℕ), a ^ i = a ^ j ∧ i ≠ j,
{ rw injective at h,
simp only [not_forall, exists_prop] at h,
exact h },
rcases h' with ⟨i, j, a_eq, ne⟩,
wlog h'' : j ≤ i,
have h''' : a ^ (i - j) = 1,
{ rw [(nat.add_sub_of_le h'').symm, pow_add, ← mul_one (a ^ j), mul_assoc] at a_eq,
convert mul_left_cancel a_eq,
rw one_mul },
use (i - j),
split,
{ apply lt_of_le_of_ne (zero_le (i - j)),
by_contradiction,
rw not_not at h,
apply ne,
rw [(nat.add_sub_of_le h'').symm, ← h, add_zero] },
{ exact h''' },
end
lemma exists_nsmul_eq_zero (x : H) : ∃ i, 0 < i ∧ i •ℕ x = 0 :=
begin
rcases exists_pow_eq_one (multiplicative.of_add x) with ⟨i, hi1, hi2⟩,
refine ⟨i, hi1, multiplicative.of_add.injective _⟩,
rw [of_add_nsmul, hi2, of_add_zero],
end
attribute [to_additive exists_nsmul_eq_zero] exists_pow_eq_one
lemma add_order_of_le_card_univ {x : H} : add_order_of x ≤ fintype.card H :=
finset.le_card_of_inj_on_range (•ℕ x)
(assume n _, finset.mem_univ _)
(assume i hi j hj, nsmul_injective_of_lt_add_order_of x hi hj)
@[to_additive add_order_of_le_card_univ]
lemma order_of_le_card_univ {a : α} : order_of a ≤ fintype.card α :=
finset.le_card_of_inj_on_range ((^) a)
(assume n _, finset.mem_univ _)
(assume i hi j hj, pow_injective_of_lt_order_of a hi hj)
/-- This is the same as `order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative monoid.-/
lemma order_of_pos (a : α) : 0 < order_of a := order_of_pos' (exists_pow_eq_one a)
/-- This is the same as `add_order_of_pos' but with one fewer explicit assumption since this is
automatic in case of a finite cancellative additive monoid.-/
lemma add_order_of_pos (x : H) : 0 < add_order_of x :=
begin
rw ← order_of_of_add_eq_add_order_of,
exact order_of_pos _,
end
attribute [to_additive add_order_of_pos] order_of_pos
variables {n : ℕ}
open nat
lemma exists_pow_eq_self_of_coprime {α : Type*} [monoid α] {a : α} (h : coprime n (order_of a)) :
∃ m : ℕ, (a ^ n) ^ m = a :=
begin
by_cases h0 : order_of a = 0,
{ rw [h0, coprime_zero_right] at h,
exact ⟨1, by rw [h, pow_one, pow_one]⟩ },
by_cases h1 : order_of a = 1,
{ rw order_of_eq_one_iff at h1,
exact ⟨37, by rw [h1, one_pow, one_pow]⟩ },
obtain ⟨m, hm⟩ :=
exists_mul_mod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩),
exact ⟨m, by rw [←pow_mul, pow_eq_mod_order_of, hm, pow_one]⟩,
end
lemma exists_nsmul_eq_self_of_coprime {H : Type*} [add_monoid H] (x : H)
(h : coprime n (add_order_of x)) : ∃ m : ℕ, m •ℕ (n •ℕ x) = x :=
begin
have h' : coprime n (order_of (multiplicative.of_add x)),
{ simp_rw order_of_of_add_eq_add_order_of,
exact h },
cases exists_pow_eq_self_of_coprime h' with m hpow,
use m,
apply multiplicative.of_add.injective,
simpa [of_add_nsmul],
end
attribute [to_additive exists_nsmul_eq_self_of_coprime] exists_pow_eq_self_of_coprime
/-- This is the same as `order_of_pow'` and `order_of_pow''` but with one assumption less which is
automatic in the case of a finite cancellative monoid.-/
lemma order_of_pow (a : α) :
order_of (a ^ n) = order_of a / gcd (order_of a) n := order_of_pow'' _ _ (exists_pow_eq_one _)
/-- This is the same as `add_order_of_nsmul'` and `add_order_of_nsmul` but with one assumption less
which is automatic in the case of a finite cancellative additive monoid. -/
lemma add_order_of_nsmul (x : H) :
add_order_of (n •ℕ x) = add_order_of x / gcd (add_order_of x) n :=
begin
rw [← order_of_of_add_eq_add_order_of, of_add_nsmul],
exact order_of_pow _,
end
attribute [to_additive add_order_of_nsmul] order_of_pow
lemma mem_multiples_iff_mem_range_add_order_of [decidable_eq H] {x x' : H} :
x' ∈ add_submonoid.multiples x ↔
x' ∈ (finset.range (add_order_of x)).image ((•ℕ x) : ℕ → H) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (add_order_of_pos x)
(assume i, nsmul_eq_mod_add_order_of.symm)
@[to_additive mem_multiples_iff_mem_range_add_order_of]
lemma mem_powers_iff_mem_range_order_of [decidable_eq α] {a a' : α} :
a' ∈ submonoid.powers a ↔ a' ∈ (finset.range (order_of a)).image ((^) a : ℕ → α) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq' (order_of_pos a)
(assume i, pow_eq_mod_order_of.symm)
noncomputable instance decidable_multiples [decidable_eq H] {x : H} :
decidable_pred (add_submonoid.multiples x : set H) :=
begin
assume x',
apply decidable_of_iff' (x' ∈ (finset.range (add_order_of x)).image (•ℕ x)),
exact mem_multiples_iff_mem_range_add_order_of,
end
@[to_additive decidable_multiples]
noncomputable instance decidable_powers [decidable_eq α] :
decidable_pred (submonoid.powers a : set α) :=
begin
assume a',
apply decidable_of_iff'
(a' ∈ (finset.range (order_of a)).image ((^) a)),
exact mem_powers_iff_mem_range_order_of
end
lemma order_eq_card_powers [decidable_eq α] {a : α} :
order_of a = fintype.card (submonoid.powers a : set α) :=
begin
refine (finset.card_eq_of_bijective _ _ _ _).symm,
{ exact λn hn, ⟨a ^ n, ⟨n, rfl⟩⟩ },
{ rintros ⟨_, i, rfl⟩ _,
exact ⟨i % order_of a, mod_lt i (order_of_pos a), subtype.eq pow_eq_mod_order_of.symm⟩ },
{ intros, exact finset.mem_univ _ },
{ intros i j hi hj eq,
exact pow_injective_of_lt_order_of a hi hj ( by simpa using eq ) }
end
lemma add_order_of_eq_card_multiples [decidable_eq H] {x : H} :
add_order_of x = fintype.card (add_submonoid.multiples x : set H) :=
begin
rw [← order_of_of_add_eq_add_order_of, order_eq_card_powers],
apply fintype.card_congr,
rw ←of_add_image_multiples_eq_powers_of_add,
exact (equiv.set.image _ _ (equiv.injective _)).symm
end
attribute [to_additive add_order_of_eq_card_multiples] order_eq_card_powers
end finite_cancel_monoid
section finite_group
variables {α} [fintype α] [group α]
variables {H : Type u} [fintype H] [add_group H]
lemma exists_gpow_eq_one (a : α) : ∃ i ≠ 0, a ^ (i : ℤ) = 1 :=
begin
rcases exists_pow_eq_one a with ⟨w, hw1, hw2⟩,
use w,
split,
{ exact_mod_cast ne_of_gt hw1 },
{ exact_mod_cast hw2 }
end
lemma exists_gsmul_eq_zero (x : H) : ∃ i ≠ 0, i •ℤ x = 0 :=
begin
rcases exists_gpow_eq_one (multiplicative.of_add x) with ⟨i, hi1, hi2⟩,
refine ⟨i, hi1, multiplicative.of_add.injective _⟩,
{ rw [of_add_gsmul, hi2, of_add_zero] }
end
attribute [to_additive exists_gsmul_eq_zero] exists_gpow_eq_one
lemma mem_multiples_iff_mem_gmultiples {x y : H} :
y ∈ add_submonoid.multiples x ↔ y ∈ add_subgroup.gmultiples x :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩, λ ⟨i, hi⟩, ⟨(i % add_order_of x).nat_abs,
by { simp only at hi ⊢,
rwa [← gsmul_coe_nat,
int.nat_abs_of_nonneg (int.mod_nonneg _ (int.coe_nat_ne_zero_iff_pos.2
(add_order_of_pos x))), ← gsmul_eq_mod_add_order_of] } ⟩⟩
open subgroup
@[to_additive mem_multiples_iff_mem_gmultiples]
lemma mem_powers_iff_mem_gpowers {a x : α} : x ∈ submonoid.powers a ↔ x ∈ gpowers a :=
⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩,
λ ⟨i, hi⟩, ⟨(i % order_of a).nat_abs,
by rwa [← gpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (order_of_pos a))),
← gpow_eq_mod_order_of]⟩⟩
lemma multiples_eq_gmultiples (x : H) :
(add_submonoid.multiples x : set H) = add_subgroup.gmultiples x :=
set.ext $ λ y, mem_multiples_iff_mem_gmultiples
@[to_additive multiples_eq_gmultiples]
lemma powers_eq_gpowers (a : α) : (submonoid.powers a : set α) = gpowers a :=
set.ext $ λ x, mem_powers_iff_mem_gpowers
lemma mem_gmultiples_iff_mem_range_add_order_of [decidable_eq H] {x x' : H} :
x' ∈ add_subgroup.gmultiples x ↔ x' ∈ (finset.range (add_order_of x)).image (•ℕ x) :=
by rw [← mem_multiples_iff_mem_gmultiples, mem_multiples_iff_mem_range_add_order_of]
@[to_additive mem_gmultiples_iff_mem_range_add_order_of]
lemma mem_gpowers_iff_mem_range_order_of [decidable_eq α] {a a' : α} :
a' ∈ subgroup.gpowers a ↔ a' ∈ (finset.range (order_of a)).image ((^) a : ℕ → α) :=
by rw [← mem_powers_iff_mem_gpowers, mem_powers_iff_mem_range_order_of]
noncomputable instance decidable_gmultiples [decidable_eq H] {x : H}:
decidable_pred (add_subgroup.gmultiples x : set H) :=
begin
rw ← multiples_eq_gmultiples,
exact decidable_multiples,
end
@[to_additive decidable_gmultiples]
noncomputable instance decidable_gpowers [decidable_eq α] :
decidable_pred (subgroup.gpowers a : set α) :=
begin
rw ← powers_eq_gpowers,
exact decidable_powers,
end
lemma order_eq_card_gpowers [decidable_eq α] {a : α} :
order_of a = fintype.card (subgroup.gpowers a : set α) :=
begin
refine (finset.card_eq_of_bijective _ _ _ _).symm,
{ exact λn hn, ⟨a ^ (n : ℤ), ⟨n, rfl⟩⟩ },
{ exact assume ⟨_, i, rfl⟩ _,
have pos : (0 : ℤ) < order_of a := int.coe_nat_lt.mpr $ order_of_pos a,
have 0 ≤ i % (order_of a) := int.mod_nonneg _ $ ne_of_gt pos,
⟨int.to_nat (i % order_of a),
by rw [← int.coe_nat_lt, int.to_nat_of_nonneg this];
exact ⟨int.mod_lt_of_pos _ pos, subtype.eq gpow_eq_mod_order_of.symm⟩⟩ },
{ intros, exact finset.mem_univ _ },
{ exact assume i j hi hj eq, pow_injective_of_lt_order_of a hi hj $ by simpa using eq }
end
lemma add_order_eq_card_gmultiples [decidable_eq H] {x : H} :
add_order_of x = fintype.card (add_subgroup.gmultiples x : set H) :=
begin
rw [← order_of_of_add_eq_add_order_of, order_eq_card_gpowers],
apply fintype.card_congr,
rw ← of_add_image_gmultiples_eq_gpowers_of_add,
exact (equiv.set.image _ _ (equiv.injective _)).symm
end
attribute [to_additive add_order_eq_card_gmultiples] order_eq_card_gpowers
open quotient_group subgroup
/- TODO: use cardinal theory, introduce `card : set α → ℕ`, or setup decidability for cosets -/
lemma order_of_dvd_card_univ : order_of a ∣ fintype.card α :=
begin
classical,
have ft_prod : fintype (quotient (gpowers a) × (gpowers a)),
from fintype.of_equiv α group_equiv_quotient_times_subgroup,
have ft_s : fintype (gpowers a),
from @fintype.fintype_prod_right _ _ _ ft_prod _,
have ft_cosets : fintype (quotient (gpowers a)),
from @fintype.fintype_prod_left _ _ _ ft_prod ⟨⟨1, (gpowers a).one_mem⟩⟩,
have eq₁ : fintype.card α = @fintype.card _ ft_cosets * @fintype.card _ ft_s,
from calc fintype.card α = @fintype.card _ ft_prod :
@fintype.card_congr _ _ _ ft_prod group_equiv_quotient_times_subgroup
... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :
congr_arg (@fintype.card _) $ subsingleton.elim _ _
... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :
@fintype.card_prod _ _ ft_cosets ft_s,
have eq₂ : order_of a = @fintype.card _ ft_s,
from calc order_of a = _ : order_eq_card_gpowers
... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,
exact dvd.intro (@fintype.card (quotient (subgroup.gpowers a)) ft_cosets)
(by rw [eq₁, eq₂, mul_comm])
end
lemma add_order_of_dvd_card_univ {x : H} : add_order_of x ∣ fintype.card H :=
begin
rw ← order_of_of_add_eq_add_order_of,
exact order_of_dvd_card_univ,
end
attribute [to_additive add_order_of_dvd_card_univ] order_of_dvd_card_univ
@[simp] lemma pow_card_eq_one {a : α} : a ^ fintype.card α = 1 :=
let ⟨m, hm⟩ := @order_of_dvd_card_univ _ a _ _ in
by simp [hm, pow_mul, pow_order_of_eq_one]
@[simp] lemma card_nsmul_eq_zero {x : H} : fintype.card H •ℕ x = 0 :=
begin
apply multiplicative.of_add.injective,
rw [of_add_nsmul, of_add_zero],
exact pow_card_eq_one,
end
attribute [to_additive card_nsmul_eq_zero] pow_card_eq_one
variable (a)
lemma image_range_add_order_of [decidable_eq H] {x : H} :
finset.image (λ i, i •ℕ x) (finset.range (add_order_of x)) =
(add_subgroup.gmultiples x : set H).to_finset :=
by {ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gmultiples_iff_mem_range_add_order_of] }
/-- TODO: Generalise to `submonoid.powers`.-/
@[to_additive image_range_add_order_of]
lemma image_range_order_of [decidable_eq α] :
finset.image (λ i, a ^ i) (finset.range (order_of a)) = (gpowers a : set α).to_finset :=
by { ext x, rw [set.mem_to_finset, set_like.mem_coe, mem_gpowers_iff_mem_range_order_of] }
open nat
lemma gcd_nsmul_card_eq_zero_iff {x : H} {n : ℕ} :
n •ℕ x = 0 ↔ (gcd n (fintype.card H)) •ℕ x = 0 :=
⟨λ h, gcd_nsmul_eq_zero _ h $ card_nsmul_eq_zero,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card H) in
by rw [hm, mul_comm, mul_nsmul, h, nsmul_zero]⟩
/-- TODO: Generalise to `finite_cancel_monoid`. -/
@[to_additive gcd_nsmul_card_eq_zero_iff]
lemma pow_gcd_card_eq_one_iff {n : ℕ} :
a ^ n = 1 ↔ a ^ (gcd n (fintype.card α)) = 1 :=
⟨λ h, pow_gcd_eq_one _ h $ pow_card_eq_one,
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card α) in
by rw [hm, pow_mul, h, one_pow]⟩
end finite_group
end order_of
section cyclic
local attribute [instance] set_fintype
open subgroup
/-- A group is called *cyclic* if it is generated by a single element. -/
class is_cyclic (α : Type u) [group α] : Prop :=
(exists_generator [] : ∃ g : α, ∀ x, x ∈ gpowers g)
@[priority 100]
instance is_cyclic_of_subsingleton [group α] [subsingleton α] : is_cyclic α :=
⟨⟨1, λ x, by { rw subsingleton.elim x 1, exact mem_gpowers 1 }⟩⟩
/-- A cyclic group is always commutative. This is not an `instance` because often we have a better
proof of `comm_group`. -/
def is_cyclic.comm_group [hg : group α] [is_cyclic α] : comm_group α :=
{ mul_comm := λ x y, show x * y = y * x,
from let ⟨g, hg⟩ := is_cyclic.exists_generator α in
let ⟨n, hn⟩ := hg x in let ⟨m, hm⟩ := hg y in
hm ▸ hn ▸ gpow_mul_comm _ _ _,
..hg }
variables [group α]
lemma monoid_hom.map_cyclic {G : Type*} [group G] [h : is_cyclic G] (σ : G →* G) :
∃ m : ℤ, ∀ g : G, σ g = g ^ m :=
begin
obtain ⟨h, hG⟩ := is_cyclic.exists_generator G,
obtain ⟨m, hm⟩ := hG (σ h),
use m,
intro g,
obtain ⟨n, rfl⟩ := hG g,
rw [monoid_hom.map_gpow, ←hm, ←gpow_mul, ←gpow_mul'],
end
lemma is_cyclic_of_order_of_eq_card [fintype α] (x : α)
(hx : order_of x = fintype.card α) : is_cyclic α :=
begin
classical,
use x,
simp_rw ← set_like.mem_coe,
rw ← set.eq_univ_iff_forall,
apply set.eq_of_subset_of_card_le (set.subset_univ _),
rw [fintype.card_congr (equiv.set.univ α), ← hx, order_eq_card_gpowers],
end
/-- A finite group of prime order is cyclic. -/
lemma is_cyclic_of_prime_card {α : Type u} [group α] [fintype α] {p : ℕ} [hp : fact p.prime]
(h : fintype.card α = p) : is_cyclic α :=
⟨begin
obtain ⟨g, hg⟩ : ∃ g : α, g ≠ 1,
from fintype.exists_ne_of_one_lt_card (by { rw h, exact hp.1.one_lt }) 1,
classical, -- for fintype (subgroup.gpowers g)
have : fintype.card (subgroup.gpowers g) ∣ p,
{ rw ←h,
apply card_subgroup_dvd_card },
rw nat.dvd_prime hp.1 at this,
cases this,
{ rw fintype.card_eq_one_iff at this,
cases this with t ht,
suffices : g = 1,
{ contradiction },
have hgt := ht ⟨g, by { change g ∈ subgroup.gpowers g, exact subgroup.mem_gpowers g }⟩,
rw [←ht 1] at hgt,
change (⟨_, _⟩ : subgroup.gpowers g) = ⟨_, _⟩ at hgt,
simpa using hgt },
{ use g,
intro x,
rw [←h] at this,
rw subgroup.eq_top_of_card_eq _ this,
exact subgroup.mem_top _ }
end⟩
lemma order_of_eq_card_of_forall_mem_gpowers [fintype α]
{g : α} (hx : ∀ x, x ∈ gpowers g) : order_of g = fintype.card α :=
by { classical, rw [← fintype.card_congr (equiv.set.univ α), order_eq_card_gpowers],
simp [hx], apply fintype.card_of_finset', simp, intro x, exact hx x}
instance bot.is_cyclic {α : Type u} [group α] : is_cyclic (⊥ : subgroup α) :=
⟨⟨1, λ x, ⟨0, subtype.eq $ eq.symm (subgroup.mem_bot.1 x.2)⟩⟩⟩
instance subgroup.is_cyclic {α : Type u} [group α] [is_cyclic α] (H : subgroup α) : is_cyclic H :=
by haveI := classical.prop_decidable; exact
let ⟨g, hg⟩ := is_cyclic.exists_generator α in
if hx : ∃ (x : α), x ∈ H ∧ x ≠ (1 : α) then
let ⟨x, hx₁, hx₂⟩ := hx in
let ⟨k, hk⟩ := hg x in
have hex : ∃ n : ℕ, 0 < n ∧ g ^ n ∈ H,
from ⟨k.nat_abs, nat.pos_of_ne_zero
(λ h, hx₂ $ by rw [← hk, int.eq_zero_of_nat_abs_eq_zero h, gpow_zero]),
match k, hk with
| (k : ℕ), hk := by rw [int.nat_abs_of_nat, ← gpow_coe_nat, hk]; exact hx₁
| -[1+ k], hk := by rw [int.nat_abs_of_neg_succ_of_nat,
← subgroup.inv_mem_iff H]; simp * at *
end⟩,
⟨⟨⟨g ^ nat.find hex, (nat.find_spec hex).2⟩,
λ ⟨x, hx⟩, let ⟨k, hk⟩ := hg x in
have hk₁ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ gpowers (g ^ nat.find hex),
from ⟨k / nat.find hex, eq.symm $ gpow_mul _ _ _⟩,
have hk₂ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ H,
by rw gpow_mul; exact H.gpow_mem (nat.find_spec hex).2 _,
have hk₃ : g ^ (k % nat.find hex) ∈ H,
from (subgroup.mul_mem_cancel_right H hk₂).1 $
by rw [← gpow_add, int.mod_add_div, hk]; exact hx,
have hk₄ : k % nat.find hex = (k % nat.find hex).nat_abs,
by rw int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (nat.find_spec hex).1)),
have hk₅ : g ^ (k % nat.find hex ).nat_abs ∈ H,
by rwa [← gpow_coe_nat, ← hk₄],
have hk₆ : (k % (nat.find hex : ℤ)).nat_abs = 0,
from by_contradiction (λ h,
nat.find_min hex (int.coe_nat_lt.1 $ by rw [← hk₄];
exact int.mod_lt_of_pos _ (int.coe_nat_pos.2 (nat.find_spec hex).1))
⟨nat.pos_of_ne_zero h, hk₅⟩),
⟨k / (nat.find hex : ℤ), subtype.ext_iff_val.2 begin
suffices : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) = x,
{ simpa [gpow_mul] },
rw [int.mul_div_cancel' (int.dvd_of_mod_eq_zero (int.eq_zero_of_nat_abs_eq_zero hk₆)), hk]
end⟩⟩⟩
else
have H = (⊥ : subgroup α), from subgroup.ext $ λ x, ⟨λ h, by simp at *; tauto,
λ h, by rw [subgroup.mem_bot.1 h]; exact H.one_mem⟩,
by clear _let_match; substI this; apply_instance
open finset nat
section classical
open_locale classical
lemma is_cyclic.card_pow_eq_one_le [decidable_eq α] [fintype α] [is_cyclic α] {n : ℕ}
(hn0 : 0 < n) : (univ.filter (λ a : α, a ^ n = 1)).card ≤ n :=
let ⟨g, hg⟩ := is_cyclic.exists_generator α in
calc (univ.filter (λ a : α, a ^ n = 1)).card
≤ ((gpowers (g ^ (fintype.card α / (gcd n (fintype.card α))))) : set α).to_finset.card :
card_le_of_subset (λ x hx, let ⟨m, hm⟩ := show x ∈ submonoid.powers g,
from mem_powers_iff_mem_gpowers.2 $ hg x in
set.mem_to_finset.2 ⟨(m / (fintype.card α / (gcd n (fintype.card α))) : ℕ),
have hgmn : g ^ (m * gcd n (fintype.card α)) = 1,
by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2,
begin
rw [gpow_coe_nat, ← pow_mul, nat.mul_div_cancel_left', hm],
refine dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (fintype.card α) hn0) _,
conv {to_lhs,
rw [nat.div_mul_cancel (gcd_dvd_right _ _), ← order_of_eq_card_of_forall_mem_gpowers hg]},
exact order_of_dvd_of_pow_eq_one hgmn
end⟩)
... ≤ n :
let ⟨m, hm⟩ := gcd_dvd_right n (fintype.card α) in
have hm0 : 0 < m, from nat.pos_of_ne_zero
(λ hm0, (by rw [hm0, mul_zero, fintype.card_eq_zero_iff] at hm; exact hm 1)),
begin
rw [← fintype.card_of_finset' _ (λ _, set.mem_to_finset), ← order_eq_card_gpowers,
order_of_pow g, order_of_eq_card_of_forall_mem_gpowers hg],
rw [hm] {occs := occurrences.pos [2,3]},
rw [nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left,
hm, nat.mul_div_cancel _ hm0],
exact le_of_dvd hn0 (gcd_dvd_left _ _)
end
end classical
lemma is_cyclic.exists_monoid_generator [fintype α]
[is_cyclic α] : ∃ x : α, ∀ y : α, y ∈ submonoid.powers x :=
by { simp_rw [mem_powers_iff_mem_gpowers], exact is_cyclic.exists_generator α }
section
variables [decidable_eq α] [fintype α]
lemma is_cyclic.image_range_order_of (ha : ∀ x : α, x ∈ gpowers a) :
finset.image (λ i, a ^ i) (range (order_of a)) = univ :=
begin
simp_rw [←set_like.mem_coe] at ha,
simp only [image_range_order_of, set.eq_univ_iff_forall.mpr ha],
convert set.to_finset_univ
end
lemma is_cyclic.image_range_card (ha : ∀ x : α, x ∈ gpowers a) :
finset.image (λ i, a ^ i) (range (fintype.card α)) = univ :=
by rw [← order_of_eq_card_of_forall_mem_gpowers ha, is_cyclic.image_range_order_of ha]
end
section totient
variables [decidable_eq α] [fintype α]
(hn : ∀ n : ℕ, 0 < n → (univ.filter (λ a : α, a ^ n = 1)).card ≤ n)
include hn
lemma card_pow_eq_one_eq_order_of_aux (a : α) :
(finset.univ.filter (λ b : α, b ^ order_of a = 1)).card = order_of a :=
le_antisymm
(hn _ (order_of_pos a))
(calc order_of a = @fintype.card (gpowers a) (id _) : order_eq_card_gpowers
... ≤ @fintype.card (↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α)
(fintype.of_finset _ (λ _, iff.rfl)) :
@fintype.card_le_of_injective (gpowers a)
(↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α)
(id _) (id _) (λ b, ⟨b.1, mem_filter.2 ⟨mem_univ _,
let ⟨i, hi⟩ := b.2 in
by rw [← hi, ← gpow_coe_nat, ← gpow_mul, mul_comm, gpow_mul, gpow_coe_nat,
pow_order_of_eq_one, one_gpow]⟩⟩) (λ _ _ h, subtype.eq (subtype.mk.inj h))
... = (univ.filter (λ b : α, b ^ order_of a = 1)).card : fintype.card_of_finset _ _)
open_locale nat -- use φ for nat.totient
private lemma card_order_of_eq_totient_aux₁ :
∀ {d : ℕ}, d ∣ fintype.card α → 0 < (univ.filter (λ a : α, order_of a = d)).card →
(univ.filter (λ a : α, order_of a = d)).card = φ d
| 0 := λ hd hd0,
let ⟨a, ha⟩ := card_pos.1 hd0 in absurd (mem_filter.1 ha).2 $ ne_of_gt $ order_of_pos a
| (d+1) := λ hd hd0,
let ⟨a, ha⟩ := card_pos.1 hd0 in
have ha : order_of a = d.succ, from (mem_filter.1 ha).2,
have h : ∑ m in (range d.succ).filter (∣ d.succ),
(univ.filter (λ a : α, order_of a = m)).card =
∑ m in (range d.succ).filter (∣ d.succ), φ m, from
finset.sum_congr rfl
(λ m hm, have hmd : m < d.succ, from mem_range.1 (mem_filter.1 hm).1,
have hm : m ∣ d.succ, from (mem_filter.1 hm).2,
card_order_of_eq_totient_aux₁ (dvd.trans hm hd) (finset.card_pos.2
⟨a ^ (d.succ / m), mem_filter.2 ⟨mem_univ _,
by { rw [order_of_pow a, ha, gcd_eq_right (div_dvd_of_dvd hm),
nat.div_div_self hm (succ_pos _)]
}⟩⟩)),
have hinsert : insert d.succ ((range d.succ).filter (∣ d.succ))
= (range d.succ.succ).filter (∣ d.succ),
from (finset.ext $ λ x, ⟨λ h, (mem_insert.1 h).elim (λ h, by simp [h, range_succ])
(by clear _let_match; simp [range_succ]; tauto),
by clear _let_match; simp [range_succ] {contextual := tt}; tauto⟩),
have hinsert₁ : d.succ ∉ (range d.succ).filter (∣ d.succ),
by simp [mem_range, zero_le_one, le_succ],
(add_left_inj (∑ m in (range d.succ).filter (∣ d.succ),
(univ.filter (λ a : α, order_of a = m)).card)).1
(calc _ = ∑ m in insert d.succ (filter (∣ d.succ) (range d.succ)),
(univ.filter (λ a : α, order_of a = m)).card :
eq.symm (finset.sum_insert (by simp [mem_range, zero_le_one, le_succ]))
... = ∑ m in (range d.succ.succ).filter (∣ d.succ),
(univ.filter (λ a : α, order_of a = m)).card :
sum_congr hinsert (λ _ _, rfl)
... = (univ.filter (λ a : α, a ^ d.succ = 1)).card :
sum_card_order_of_eq_card_pow_eq_one (succ_pos d)
... = ∑ m in (range d.succ.succ).filter (∣ d.succ), φ m :
ha ▸ (card_pow_eq_one_eq_order_of_aux hn a).symm ▸ (sum_totient _).symm
... = _ : by rw [h, ← sum_insert hinsert₁];
exact finset.sum_congr hinsert.symm (λ _ _, rfl))
lemma card_order_of_eq_totient_aux₂ {d : ℕ} (hd : d ∣ fintype.card α) :
(univ.filter (λ a : α, order_of a = d)).card = φ d :=
by_contradiction $ λ h,
have h0 : (univ.filter (λ a : α , order_of a = d)).card = 0 :=
not_not.1 (mt pos_iff_ne_zero.2 (mt (card_order_of_eq_totient_aux₁ hn hd) h)),
let c := fintype.card α in
have hc0 : 0 < c, from fintype.card_pos_iff.2 ⟨1⟩,
lt_irrefl c $
calc c = (univ.filter (λ a : α, a ^ c = 1)).card :
congr_arg card $ by simp [finset.ext_iff, c]
... = ∑ m in (range c.succ).filter (∣ c),
(univ.filter (λ a : α, order_of a = m)).card :
(sum_card_order_of_eq_card_pow_eq_one hc0).symm
... = ∑ m in ((range c.succ).filter (∣ c)).erase d,
(univ.filter (λ a : α, order_of a = m)).card :
eq.symm (sum_subset (erase_subset _ _) (λ m hm₁ hm₂,
have m = d, by simp at *; cc,
by simp [*, finset.ext_iff] at *; exact h0))
... ≤ ∑ m in ((range c.succ).filter (∣ c)).erase d, φ m :
sum_le_sum (λ m hm,
have hmc : m ∣ c, by simp at hm; tauto,
(imp_iff_not_or.1 (card_order_of_eq_totient_aux₁ hn hmc)).elim
(λ h, by simp [nat.le_zero_iff.1 (le_of_not_gt h), nat.zero_le])
(λ h, by rw h))
... < φ d + ∑ m in ((range c.succ).filter (∣ c)).erase d, φ m :
lt_add_of_pos_left _ (totient_pos (nat.pos_of_ne_zero
(λ h, pos_iff_ne_zero.1 hc0 (eq_zero_of_zero_dvd $ h ▸ hd))))
... = ∑ m in insert d (((range c.succ).filter (∣ c)).erase d), φ m :
eq.symm (sum_insert (by simp))
... = ∑ m in (range c.succ).filter (∣ c), φ m : finset.sum_congr
(finset.insert_erase (mem_filter.2 ⟨mem_range.2 (lt_succ_of_le (le_of_dvd hc0 hd)), hd⟩))
(λ _ _, rfl)
... = c : sum_totient _
lemma is_cyclic_of_card_pow_eq_one_le : is_cyclic α :=
have (univ.filter (λ a : α, order_of a = fintype.card α)).nonempty,
from (card_pos.1 $
by rw [card_order_of_eq_totient_aux₂ hn (dvd_refl _)];
exact totient_pos (fintype.card_pos_iff.2 ⟨1⟩)),
let ⟨x, hx⟩ := this in
is_cyclic_of_order_of_eq_card x (finset.mem_filter.1 hx).2
end totient
lemma is_cyclic.card_order_of_eq_totient [is_cyclic α] [fintype α]
{d : ℕ} (hd : d ∣ fintype.card α) : (univ.filter (λ a : α, order_of a = d)).card = totient d :=
begin
classical,
apply card_order_of_eq_totient_aux₂ (λ n, is_cyclic.card_pow_eq_one_le) hd
end
/-- A finite group of prime order is simple. -/
lemma is_simple_group_of_prime_card {α : Type u} [group α] [fintype α] {p : ℕ} [hp : fact p.prime]
(h : fintype.card α = p) : is_simple_group α :=
⟨begin
have h' := nat.prime.one_lt (fact.out p.prime),
rw ← h at h',
haveI := fintype.one_lt_card_iff_nontrivial.1 h',
apply exists_pair_ne α,
end, λ H Hn, begin
classical,
have hcard := card_subgroup_dvd_card H,
rw [h, dvd_prime (fact.out p.prime)] at hcard,
refine hcard.imp (λ h1, _) (λ hp, _),
{ haveI := fintype.card_le_one_iff_subsingleton.1 (le_of_eq h1),
apply eq_bot_of_subsingleton },
{ exact eq_top_of_card_eq _ (hp.trans h.symm) }
end⟩
end cyclic
namespace is_simple_group
section comm_group
variables [comm_group α] [is_simple_group α]
@[priority 100]
instance : is_cyclic α :=
begin
cases subsingleton_or_nontrivial α with hi hi; haveI := hi,
{ apply is_cyclic_of_subsingleton },
{ obtain ⟨g, hg⟩ := exists_ne (1 : α),
refine ⟨⟨g, λ x, _⟩⟩,
cases is_simple_lattice.eq_bot_or_eq_top (subgroup.gpowers g) with hb ht,
{ exfalso,
apply hg,
rw [← subgroup.mem_bot, ← hb],
apply subgroup.mem_gpowers },
{ rw ht,
apply subgroup.mem_top } }
end
theorem prime_card [fintype α] : (fintype.card α).prime :=
begin
have h0 : 0 < fintype.card α := fintype.card_pos_iff.2 (by apply_instance),
obtain ⟨g, hg⟩ := is_cyclic.exists_generator α,
refine ⟨fintype.one_lt_card_iff_nontrivial.2 infer_instance, λ n hn, _⟩,
refine (is_simple_lattice.eq_bot_or_eq_top (subgroup.gpowers (g ^ n))).symm.imp _ _,
{ intro h,
have hgo := order_of_pow g,
rw [order_of_eq_card_of_forall_mem_gpowers hg, nat.gcd_eq_right_iff_dvd.1 hn,
order_of_eq_card_of_forall_mem_gpowers, eq_comm,
nat.div_eq_iff_eq_mul_left (nat.pos_of_dvd_of_pos hn h0) hn] at hgo,
{ exact (mul_left_cancel' (ne_of_gt h0) ((mul_one (fintype.card α)).trans hgo)).symm },
{ intro x,
rw h,
exact subgroup.mem_top _ } },
{ intro h,
apply le_antisymm (nat.le_of_dvd h0 hn),
rw ← order_of_eq_card_of_forall_mem_gpowers hg,
apply order_of_le_of_pow_eq_one (nat.pos_of_dvd_of_pos hn h0),
rw [← subgroup.mem_bot, ← h],
exact subgroup.mem_gpowers _ }
end
end comm_group
end is_simple_group
theorem comm_group.is_simple_iff_is_cyclic_and_prime_card [fintype α] [comm_group α] :
is_simple_group α ↔ is_cyclic α ∧ (fintype.card α).prime :=
begin
split,
{ introI h,
exact ⟨is_simple_group.is_cyclic, is_simple_group.prime_card⟩ },
{ rintro ⟨hc, hp⟩,
haveI : fact (fintype.card α).prime := ⟨hp⟩,
exact is_simple_group_of_prime_card rfl }
end
|
5c46cc4b5efeb17cde12176c9b7519dc6453111b | e6b8240a90527fd55d42d0ec6649253d5d0bd414 | /src/tactic/localized.lean | 5878b9e6865c78b9ec543215c27fe84dccdb9a2e | [
"Apache-2.0"
] | permissive | mattearnshaw/mathlib | ac90f9fb8168aa642223bea3ffd0286b0cfde44f | d8dc1445cf8a8c74f8df60b9f7a1f5cf10946666 | refs/heads/master | 1,606,308,351,137 | 1,576,594,130,000 | 1,576,594,130,000 | 228,666,195 | 0 | 0 | Apache-2.0 | 1,576,603,094,000 | 1,576,603,093,000 | null | UTF-8 | Lean | false | false | 3,431 | 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.core meta.rb_map
/-!
# Localized notation
This consists of two user-commands which allow you to declare notation and commands localized to a namespace.
* Declare notation which is localized to a namespace using:
```
localized "infix ` ⊹ `:60 := my_add" in my.add
```
* After this command it will be available in the same section/namespace/file, just as if you wrote `local infix ` ⊹ `:60 := my_add`
* You can open it in other places. The following command will declare the notation again as local notation in that section/namespace/files:
```
open_locale my.add
```
* More generally, the following will declare all localized notation in the specified namespaces.
```
open_locale namespace1 namespace2 ...
```
* You can also declare other localized commands, like local attributes
```
localized "attribute [simp] le_refl" in le
```
The code is inspired by code from Gabriel Ebner from the hott3 repository.
-/
open lean lean.parser interactive tactic native
reserve notation `localized`
@[user_attribute]
meta def localized_attr : user_attribute (rb_lmap name string) unit := {
name := "_localized",
descr := "(interal) attribute that flags localized commands",
cache_cfg := ⟨λ ns, (do dcls ← ns.mmap (λ n, mk_const n >>= eval_expr (name × string)),
return $ rb_lmap.of_list dcls), []⟩
}
/-- Get all commands in the given notation namespace and return them as a list of strings -/
meta def get_localized (ns : list name) : tactic (list string) :=
do m ← localized_attr.get_cache,
return (ns.bind $ λ nm, m.find nm)
/-- Execute all commands in the given notation namespace -/
@[user_command] meta def open_locale_cmd (meta_info : decl_meta_info)
(_ : parse $ tk "open_locale") : parser unit :=
do ns ← many ident,
cmds ← get_localized ns,
cmds.mmap' emit_code_here
def string_hash (s : string) : ℕ :=
s.fold 1 (λ h c, (33*h + c.val) % unsigned_sz)
/-- Add a new command to a notation namespace and execute it right now.
The new command is added as a declaration to the environment with name `_localized_decl.<number>`.
This declaration has attribute `_localized` and as value a name-string pair. -/
@[user_command] meta def localized_cmd (meta_info : decl_meta_info)
(_ : parse $ tk "localized") : parser unit :=
do cmd ← parser.pexpr, cmd ← i_to_expr cmd, cmd ← eval_expr string cmd,
let cmd := "local " ++ cmd,
emit_code_here cmd,
tk "in",
nm ← ident,
env ← get_env,
let dummy_decl_name := mk_num_name `_localized_decl
((string_hash (cmd ++ nm.to_string) + env.fingerprint) % unsigned_sz),
add_decl (declaration.defn dummy_decl_name [] `(name × string)
(reflect (⟨nm, cmd⟩ : name × string)) (reducibility_hints.regular 1 tt) ff),
localized_attr.set dummy_decl_name unit.star tt
/-- Print all commands in a given notation namespace -/
meta def print_localized_commands (ns : list name) : tactic unit :=
do cmds ← get_localized ns, cmds.mmap' trace
-- you can run `open_locale classical` to get the decidability of all propositions.
localized "attribute [instance, priority 9] classical.prop_decidable" in classical
localized "postfix `?`:9001 := optional" in parser
localized "postfix *:9001 := lean.parser.many" in parser
|
2f1eaede6a23f6fb474596b76dbdc35262c58e42 | 969dbdfed67fda40a6f5a2b4f8c4a3c7dc01e0fb | /src/tactic/explode_widget.lean | 563f6af40e538ceb2a98c2896a1ec8dbb9cd07c6 | [
"Apache-2.0"
] | permissive | SAAluthwela/mathlib | 62044349d72dd63983a8500214736aa7779634d3 | 83a4b8b990907291421de54a78988c024dc8a552 | refs/heads/master | 1,679,433,873,417 | 1,615,998,031,000 | 1,615,998,031,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,210 | lean | /-
Copyright (c) 2020 Minchao Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Minchao Wu
-/
import tactic.explode
import tactic.interactive_expr
/-!
# `#explode_widget` command
Render a widget that displays an `#explode` proof, providing more
interactivity such as jumping to definitions and exploding constants
occurring in the exploded proofs.
-/
open widget tactic tactic.explode
meta instance widget.string_to_html {α} : has_coe string (html α) :=
⟨λ s, s⟩
namespace tactic
namespace explode_widget
open widget_override.interactive_expression
open tagged_format
open widget.html widget.attr
/-- Redefine some of the style attributes for better formatting. -/
meta def get_block_attrs {γ}: sf → tactic (sf × list (attr γ))
| (sf.block i a) := do
let s : attr (γ) := style [
("display", "inline-block"),
("white-space", "pre-wrap"),
("vertical-align", "top")
],
(a,rest) ← get_block_attrs a,
pure (a, s :: rest)
| (sf.highlight c a) := do
(a, rest) ← get_block_attrs a,
pure (a, (cn c.to_string) :: rest)
| a := pure (a,[])
/-- Explode button for subsequent exploding. -/
meta def insert_explode {γ} : expr → tactic (list (html (action γ)))
| (expr.const n _) := (do
pure $ [h "button" [
cn "pointer ba br3 mr1",
on_click (λ _, action.effect $ widget.effect.insert_text ("#explode_widget " ++ n.to_string)),
attr.val "title" "explode"] ["💥"]]
) <|> pure []
| e := pure []
/--
Render a subexpression as a list of html elements.
-/
meta def view {γ} (tooltip_component : tc subexpr (action γ))
(click_address : option expr.address)
(select_address : option expr.address) :
subexpr → sf → tactic (list (html (action γ)))
| ⟨ce, current_address⟩ (sf.tag_expr ea e m) := do
let new_address := current_address ++ ea,
let select_attrs : list (attr (action γ)) :=
if some new_address = select_address then
[className "highlight"] else [],
click_attrs : list (attr (action γ)) ←
if some new_address = click_address then do
content ← tc.to_html tooltip_component (e, new_address),
efmt : string ← format.to_string <$> tactic.pp e,
gd_btn ← goto_def_button e,
epld_btn ← insert_explode e,
pure [tooltip $ h "div" [] [
h "div" [cn "fr"] (gd_btn ++ epld_btn ++ [
h "button" [cn "pointer ba br3 mr1", on_click
(λ _, action.effect $ widget.effect.copy_text efmt),
attr.val "title" "copy expression to clipboard"] ["📋"],
h "button" [cn "pointer ba br3", on_click
(λ _, action.on_close_tooltip),
attr.val "title" "close"] ["×"]
]),
content
]]
else pure [],
(m, block_attrs) ← get_block_attrs m,
let as := [className "expr-boundary", key (ea)] ++ select_attrs ++
click_attrs ++ block_attrs,
inner ← view (e,new_address) m,
pure [h "span" as inner]
| ca (sf.compose x y) := pure (++) <*> view ca x <*> view ca y
| ca (sf.of_string s) := pure
[h "span" [
on_mouse_enter (λ _, action.on_mouse_enter ca),
on_click (λ _, action.on_click ca),
key s
] [html.of_string s]]
| ca b@(sf.block _ _) := do
(a, attrs) ← get_block_attrs b,
inner ← view ca a,
pure [h "span" attrs inner]
| ca b@(sf.highlight _ _) := do
(a, attrs) ← get_block_attrs b,
inner ← view ca a,
pure [h "span" attrs inner]
/-- Make an interactive expression. -/
meta def mk {γ} (tooltip : tc subexpr γ) : tc expr γ :=
let tooltip_comp :=
component.with_should_update
(λ (x y : tactic_state × expr × expr.address), x.2.2 ≠ y.2.2)
$ component.map_action (action.on_tooltip_action) tooltip in
component.filter_map_action
(λ _ (a : γ ⊕ widget.effect), sum.cases_on a some (λ _, none))
$ component.with_effects (λ _ (a : γ ⊕ widget.effect),
match a with
| (sum.inl g) := []
| (sum.inr s) := [s]
end
)
$ tc.mk_simple
(action γ)
(option subexpr × option subexpr)
(λ e, pure $ (none, none))
(λ e ⟨ca, sa⟩ act, pure $
match act with
| (action.on_mouse_enter ⟨e, ea⟩) := ((ca, some (e, ea)), none)
| (action.on_mouse_leave_all) := ((ca, none), none)
| (action.on_click ⟨e, ea⟩) := if some (e,ea) = ca then
((none, sa), none) else
((some (e, ea), sa), none)
| (action.on_tooltip_action g) := ((none, sa), some $ sum.inl g)
| (action.on_close_tooltip) := ((none, sa), none)
| (action.effect e) := ((ca,sa), some $ sum.inr $ e)
end
)
(λ e ⟨ca, sa⟩, do
m ← sf.of_eformat <$> tactic.pp_tagged e,
let m := m.elim_part_apps,
let m := m.flatten,
let m := m.tag_expr [] e,
v ← view tooltip_comp (prod.snd <$> ca) (prod.snd <$> sa) ⟨e, []⟩ m,
pure $
[ h "span" [
className "expr",
key e.hash,
on_mouse_leave (λ _, action.on_mouse_leave_all) ] $ v
]
)
/-- Render the implicit arguments for an expression in fancy, little pills. -/
meta def implicit_arg_list (tooltip : tc subexpr empty) (e : expr) : tactic $ html empty := do
fn ← (mk tooltip) $ expr.get_app_fn e,
args ← list.mmap (mk tooltip) $ expr.get_app_args e,
pure $ h "div" []
( (h "span" [className "bg-blue br3 ma1 ph2 white"] [fn]) ::
list.map (λ a, h "span" [className "bg-gray br3 ma1 ph2 white"] [a]) args
)
/--
Component for the type tooltip.
-/
meta def type_tooltip : tc subexpr empty :=
tc.stateless (λ ⟨e,ea⟩, do
y ← tactic.infer_type e,
y_comp ← mk type_tooltip y,
implicit_args ← implicit_arg_list type_tooltip e,
pure [h "div" [style [("minWidth", "12rem")]] [
h "div" [cn "pl1"] [y_comp],
h "hr" [] [],
implicit_args
]
]
)
/--
Component that shows a type.
-/
meta def show_type_component : tc expr empty :=
tc.stateless (λ x, do
y ← infer_type x,
y_comp ← mk type_tooltip $ y,
pure y_comp
)
/--
Component that shows a constant.
-/
meta def show_constant_component : tc expr empty :=
tc.stateless (λ x, do
y_comp ← mk type_tooltip x,
pure y_comp
)
/--
Search for an entry that has the specified line number.
-/
meta def lookup_lines : entries → nat → entry
| ⟨_, []⟩ n := ⟨default _, 0, 0, status.sintro, thm.string "", []⟩
| ⟨rb, (hd::tl)⟩ n := if hd.line = n then hd else lookup_lines ⟨rb, tl⟩ n
/--
Render a row that shows a goal.
-/
meta def goal_row (e : expr) (show_expr := tt): tactic (list (html empty)) :=
do t ← explode_widget.show_type_component e,
return $ [h "td" [cn "ba bg-dark-green tc"] "Goal",
h "td" [cn "ba tc"]
(if show_expr then [html.of_name e.local_pp_name, " : ", t] else t)]
/--
Render a row that shows the ID of a goal.
-/
meta def id_row {γ} (l : nat): tactic (list (html γ)) :=
return $ [h "td" [cn "ba bg-dark-green tc"] "ID",
h "td" [cn "ba tc"] (to_string l)]
/--
Render a row that shows the rule or theorem being applied.
-/
meta def rule_row : thm → tactic (list (html empty))
| (thm.expr e) := do t ← explode_widget.show_constant_component e,
return $ [h "td" [cn "ba bg-dark-green tc"] "Rule",
h "td" [cn "ba tc"] t]
| t := return $ [h "td" [cn "ba bg-dark-green tc"] "Rule",
h "td" [cn "ba tc"] t.to_string]
/--
Render a row that contains the sub-proofs, i.e., the proofs of the
arguments.
-/
meta def proof_row {γ} (args : list (html γ)): list (html γ) :=
[h "td" [cn "ba bg-dark-green tc"] "Proofs", h "td" [cn "ba tc"]
[h "details" [] $
(h "summary"
[attr.style [("color", "orange")]]
"Details")::args]
]
/--
Combine the goal row, id row, rule row and proof row to make them a table.
-/
meta def assemble_table {γ} (gr ir rr) : list (html γ) → html γ
| [] :=
h "table" [cn "collapse"]
[h "tbody" []
[h "tr" [] gr, h "tr" [] ir, h "tr" [] rr]
]
| pr :=
h "table" [cn "collapse"]
[h "tbody" []
[h "tr" [] gr, h "tr" [] ir, h "tr" [] rr, h "tr" [] pr]
]
/--
Render a table for a given entry.
-/
meta def assemble (es : entries): entry → tactic (html empty)
| ⟨e, l, d, status.sintro, t, ref⟩ := do
gr ← goal_row e, ir ← id_row l, rr ← rule_row $ thm.string "Assumption",
return $ assemble_table gr ir rr []
| ⟨e, l, d, status.intro, t, ref⟩ := do
gr ← goal_row e, ir ← id_row l, rr ← rule_row $ thm.string "Assumption",
return $ assemble_table gr ir rr []
| ⟨e, l, d, st, t, ref⟩ := do
gr ← goal_row e ff, ir ← id_row l, rr ← rule_row t,
let el : list entry := list.map (lookup_lines es) ref,
ls ← monad.mapm assemble el,
let pr := proof_row $ ls.intersperse (h "br" [] []),
return $ assemble_table gr ir rr pr
/--
Render a widget from given entries.
-/
meta def explode_component (es : entries) : tactic (html empty) :=
let concl := lookup_lines es (es.l.length - 1) in assemble es concl
/--
Explode a theorem and return entries.
-/
meta def explode_entries (n : name) (hide_non_prop := tt) : tactic entries :=
do expr.const n _ ← resolve_name n | fail "cannot resolve name",
d ← get_decl n,
v ← match d with
| (declaration.defn _ _ _ v _ _) := return v
| (declaration.thm _ _ _ v) := return v.get
| _ := fail "not a definition"
end,
t ← pp d.type,
explode_expr v hide_non_prop
end explode_widget
open lean lean.parser interactive explode_widget
/--
User command of the explode widget.
-/
@[user_command]
meta def explode_widget_cmd (_ : parse $ tk "#explode_widget") : lean.parser unit :=
do ⟨li,co⟩ ← cur_pos,
n ← ident,
es ← explode_entries n,
comp ← parser.of_tactic (do html ← explode_component es,
c ← pure $ component.stateless (λ _, [html]),
pure $ component.ignore_props $ component.ignore_action $ c),
save_widget ⟨li, co - "#explode_widget".length - 1⟩ comp,
trace "successfully rendered widget",
skip
.
end tactic
|
83a17daaca34a4a71a2fd4342de41f24f60abdf2 | a4673261e60b025e2c8c825dfa4ab9108246c32e | /src/Init/System/FilePath.lean | d6214a5fce01a2e60300685eb67474ad86932540 | [
"Apache-2.0"
] | permissive | jcommelin/lean4 | c02dec0cc32c4bccab009285475f265f17d73228 | 2909313475588cc20ac0436e55548a4502050d0a | refs/heads/master | 1,674,129,550,893 | 1,606,415,348,000 | 1,606,415,348,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,764 | 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.System.Platform
import Init.Data.String.Basic
namespace System
namespace FilePath
open Platform
/-- The character that separates directories. In the case where more than one character is possible, `pathSeparator` is the 'ideal' one. -/
def pathSeparator : Char :=
if isWindows then '\\' else '/'
/-- The list of all possible separators. -/
def pathSeparators : List Char :=
if isWindows then ['\\', '/'] else ['/']
/-- The character that is used to separate the entries in the $PATH environment variable. -/
def searchPathSeparator : Char :=
if isWindows then ';' else ':'
/-- The list of all possible separators. -/
def searchPathSeparators : List Char :=
if isWindows then [';', ':'] else [':']
def splitSearchPath (s : String) : List String :=
s.split (fun c => searchPathSeparators.elem c)
/-- File extension character -/
def extSeparator : Char := '.'
/-- Case-insensitive file system -/
def isCaseInsensitive : Bool := isWindows || isOSX
def normalizePath (fname : String) : String :=
if pathSeparators.length == 1 && !isCaseInsensitive then fname
else fname.map fun c =>
if pathSeparators.any (fun c' => c == c') then pathSeparator
-- else if isCaseInsensitive then c.toLower
else c
def dirName (fname : String) : String :=
let fname := normalizePath fname
match fname.revPosOf pathSeparator with
| none => "."
| some pos => { str := fname, startPos := 0, stopPos := pos : Substring }.toString
end FilePath
def mkFilePath (parts : List String) : String :=
String.intercalate FilePath.pathSeparator.toString parts
end System
|
ebfc5af1fe06be570d1226ad360c13682edbe595 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/analysis/special_functions/trigonometric/basic.lean | cbed8ed5b303c007f6f8d2bc85122173b4a27b10 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 41,933 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import analysis.special_functions.exp
import data.set.intervals.infinite
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `analysis.special_functions.trigonometric.inverse` and
`analysis.special_functions.trigonometric.arctan` for the inverse trigonometric functions.
See also `analysis.special_functions.complex.arg` and
`analysis.special_functions.complex.log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`analysis.special_functions.trigonometric.complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `analysis.special_functions.trigonometric.chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable theory
open_locale classical topological_space filter
open set filter
namespace complex
@[continuity] lemma continuous_sin : continuous sin :=
by { change continuous (λ z, ((exp (-z * I) - exp (z * I)) * I) / 2), continuity, }
lemma continuous_on_sin {s : set ℂ} : continuous_on sin s := continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
by { change continuous (λ z, (exp (z * I) + exp (-z * I)) / 2), continuity, }
lemma continuous_on_cos {s : set ℂ} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
by { change continuous (λ z, (exp z - exp (-z)) / 2), continuity, }
@[continuity] lemma continuous_cosh : continuous cosh :=
by { change continuous (λ z, (exp z + exp (-z)) / 2), continuity, }
end complex
namespace real
variables {x y z : ℝ}
@[continuity] lemma continuous_sin : continuous sin :=
complex.continuous_re.comp (complex.continuous_sin.comp complex.continuous_of_real)
lemma continuous_on_sin {s} : continuous_on sin s :=
continuous_sin.continuous_on
@[continuity] lemma continuous_cos : continuous cos :=
complex.continuous_re.comp (complex.continuous_cos.comp complex.continuous_of_real)
lemma continuous_on_cos {s} : continuous_on cos s := continuous_cos.continuous_on
@[continuity] lemma continuous_sinh : continuous sinh :=
complex.continuous_re.comp (complex.continuous_sinh.comp complex.continuous_of_real)
@[continuity] lemma continuous_cosh : continuous cosh :=
complex.continuous_re.comp (complex.continuous_cosh.comp complex.continuous_of_real)
end real
namespace real
lemma exists_cos_eq_zero : 0 ∈ cos '' Icc (1:ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuous_on_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `data.real.pi.bounds`. -/
protected noncomputable def pi : ℝ := 2 * classical.some exists_cos_eq_zero
localized "notation `π` := real.pi" in real
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).2
lemma one_le_pi_div_two : (1 : ℝ) ≤ π / 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.1
lemma pi_div_two_le_two : π / 2 ≤ 2 :=
by rw [real.pi, mul_div_cancel_left _ (@two_ne_zero' ℝ _ _ _)];
exact (classical.some_spec exists_cos_eq_zero).1.2
lemma two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(by rw div_self (@two_ne_zero' ℝ _ _ _); exact one_le_pi_div_two)
lemma pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2, by norm_num)).1
(calc π / 2 ≤ 2 : pi_div_two_le_two
... = 4 / 2 : by norm_num)
lemma pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
lemma pi_ne_zero : π ≠ 0 :=
ne_of_gt pi_pos
lemma pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
lemma two_pi_pos : 0 < 2 * π :=
by linarith [pi_pos]
end real
namespace nnreal
open real
open_locale real nnreal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 := ⟨π, real.pi_pos.le⟩
@[simp] lemma coe_real_pi : (pi : ℝ) = π := rfl
lemma pi_pos : 0 < pi := by exact_mod_cast real.pi_pos
lemma pi_ne_zero : pi ≠ 0 := pi_pos.ne'
end nnreal
namespace real
open_locale real
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), two_mul, add_div,
sin_add, cos_pi_div_two]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← mul_div_cancel_left π (@two_ne_zero ℝ _ _), mul_div_assoc,
cos_two_mul, cos_pi_div_two];
simp [bit0, pow_add]
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
@[simp] lemma sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp] lemma sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp] lemma sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp] lemma sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp] lemma sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp] lemma sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp] lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp] lemma sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp] lemma sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp] lemma sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp] lemma sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp] lemma sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp] lemma sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
@[simp] lemma cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp] lemma cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp] lemma cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp] lemma cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp] lemma cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp] lemma cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp] lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp] lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp] lemma cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp] lemma cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp] lemma cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp] lemma cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp] lemma cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp] lemma cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
@[simp] lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
@[simp] lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have (2 : ℝ) + 2 = 4, from rfl,
have π - x ≤ 2, from sub_le_iff_le_add.2
(le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)),
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
lemma sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
lemma sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x :=
begin
rw ← closure_Ioo pi_pos at hx,
exact closure_lt_subset_le continuous_const continuous_sin
(closure_mono (λ y, sin_pos_of_mem_Ioo) hx)
end
lemma sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
lemma sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 $ sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
lemma sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 $ sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
have sin (π / 2) = 1 ∨ sin (π / 2) = -1 :=
by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2),
this.resolve_right
(λ h, (show ¬(0 : ℝ) < -1, by norm_num) $
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos))
lemma sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
lemma cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
lemma cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 :=
neg_pos.1 $ cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
lemma cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 $ cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
lemma sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = sqrt (1 - cos x ^ 2) :=
by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
lemma cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = sqrt (1 - sin x ^ 2) :=
by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) :
sin x = 0 ↔ x = 0 :=
⟨λ h, le_antisymm
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 < sin x : sin_pos_of_pos_of_lt_pi h0 hx₂
... = 0 : h))
(le_of_not_gt (λ h0, lt_irrefl (0 : ℝ) $
calc 0 = sin x : h.symm
... < 0 : sin_neg_of_neg_of_neg_pi_lt h0 hx₁)),
λ h, by simp [h]⟩
lemma sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨λ h, ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 $ le_of_not_gt $ λ h₃,
(sin_pos_of_pos_of_lt_pi h₃ (sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
λ ⟨n, hn⟩, hn ▸ sin_int_mul_pi _⟩
lemma sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x :=
by rw [← not_exists, not_iff_not, sin_eq_zero_iff]
lemma sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x,
sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
lemma cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨λ h, let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (or.inl h)) in
⟨n / 2, (int.mod_two_eq_zero_or_one n).elim
(λ hn0, by rwa [← mul_assoc, ← @int.cast_two ℝ, ← int.cast_mul, int.div_mul_cancel
((int.dvd_iff_mod_eq_zero _ _).2 hn0)])
(λ hn1, by rw [← int.mod_add_div n 2, hn1, int.cast_add, int.cast_one, add_mul,
one_mul, add_comm, mul_comm (2 : ℤ), int.cast_mul, mul_assoc, int.cast_two] at hn;
rw [← hn, cos_int_mul_two_pi_add_pi] at h;
exact absurd h (by norm_num))⟩,
λ ⟨n, hn⟩, hn ▸ cos_int_mul_two_pi _⟩
lemma cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨λ h,
begin
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩,
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂,
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁,
norm_cast at hx₁ hx₂,
obtain rfl : n = 0 := le_antisymm (by linarith) (by linarith),
simp
end,
λ h, by simp [h]⟩
lemma cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) :
cos y < cos x :=
begin
rw [← sub_lt_zero, cos_sub_cos],
have : 0 < sin ((y + x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
have : 0 < sin ((y - x) / 2),
{ refine sin_pos_of_pos_of_lt_pi _ _; linarith },
nlinarith,
end
lemma cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x :=
match (le_total x (π / 2) : x ≤ π / 2 ∨ π / 2 ≤ x), le_total y (π / 2) with
| or.inl hx, or.inl hy := cos_lt_cos_of_nonneg_of_le_pi_div_two hx₁ hy hxy
| or.inl hx, or.inr hy := (lt_or_eq_of_le hx).elim
(λ hx, calc cos y ≤ 0 : cos_nonpos_of_pi_div_two_le_of_le hy (by linarith [pi_pos])
... < cos x : cos_pos_of_mem_Ioo ⟨by linarith, hx⟩)
(λ hx, calc cos y < 0 : cos_neg_of_pi_div_two_lt_of_lt (by linarith) (by linarith [pi_pos])
... = cos x : by rw [hx, cos_pi_div_two])
| or.inr hx, or.inl hy := by linarith
| or.inr hx, or.inr hy := neg_lt_neg_iff.1 (by rw [← cos_pi_sub, ← cos_pi_sub];
apply cos_lt_cos_of_nonneg_of_le_pi_div_two; linarith)
end
lemma strict_anti_on_cos : strict_anti_on cos (Icc 0 π) :=
λ x hx y hy hxy, cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
lemma cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strict_anti_on_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
lemma sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y :=
by rw [← cos_sub_pi_div_two, ← cos_sub_pi_div_two, ← cos_neg (x - _), ← cos_neg (y - _)];
apply cos_lt_cos_of_nonneg_of_le_pi; linarith
lemma strict_mono_on_sin : strict_mono_on sin (Icc (-(π / 2)) (π / 2)) :=
λ x hx y hy hxy, sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
lemma sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x)
(hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y :=
(strict_mono_on_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
lemma inj_on_sin : inj_on sin (Icc (-(π / 2)) (π / 2)) :=
strict_mono_on_sin.inj_on
lemma inj_on_cos : inj_on cos (Icc 0 π) := strict_anti_on_cos.inj_on
lemma surj_on_sin : surj_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
by simpa only [sin_neg, sin_pi_div_two]
using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuous_on
lemma surj_on_cos : surj_on cos (Icc 0 π) (Icc (-1) 1) :=
by simpa only [cos_zero, cos_pi]
using intermediate_value_Icc' pi_pos.le continuous_cos.continuous_on
lemma sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩
lemma cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩
lemma maps_to_sin (s : set ℝ) : maps_to sin s (Icc (-1 : ℝ) 1) := λ x _, sin_mem_Icc x
lemma maps_to_cos (s : set ℝ) : maps_to cos s (Icc (-1 : ℝ) 1) := λ x _, cos_mem_Icc x
lemma bij_on_sin : bij_on sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨maps_to_sin _, inj_on_sin, surj_on_sin⟩
lemma bij_on_cos : bij_on cos (Icc 0 π) (Icc (-1) 1) :=
⟨maps_to_cos _, inj_on_cos, surj_on_cos⟩
@[simp] lemma range_cos : range cos = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 cos_mem_Icc) surj_on_cos.subset_range
@[simp] lemma range_sin : range sin = (Icc (-1) 1 : set ℝ) :=
subset.antisymm (range_subset_iff.2 sin_mem_Icc) surj_on_sin.subset_range
lemma range_cos_infinite : (range real.cos).infinite :=
by { rw real.range_cos, exact Icc.infinite (by norm_num) }
lemma range_sin_infinite : (range real.sin).infinite :=
by { rw real.range_sin, exact Icc.infinite (by norm_num) }
lemma sin_lt {x : ℝ} (h : 0 < x) : sin x < x :=
begin
cases le_or_gt x 1 with h' h',
{ have hx : |x| = x := abs_of_nonneg (le_of_lt h),
have : |x| ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.2, rw [sub_le_iff_le_add', hx] at this,
apply lt_of_le_of_lt this, rw [sub_add], apply lt_of_lt_of_le _ (le_of_eq (sub_zero x)),
apply sub_lt_sub_left, rw [sub_pos, div_eq_mul_inv (x ^ 3)], apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h },
exact lt_of_le_of_lt (sin_le_one x) h'
end
/- note 1: this inequality is not tight, the tighter inequality is sin x > x - x ^ 3 / 6.
note 2: this is also true for x > 1, but it's nontrivial for x just above 1. -/
lemma sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x :=
begin
have hx : |x| = x := abs_of_nonneg (le_of_lt h),
have : |x| ≤ 1, rwa [hx],
have := sin_bound this, rw [abs_le] at this,
have := this.1, rw [le_sub_iff_add_le, hx] at this,
refine lt_of_lt_of_le _ this,
rw [add_comm, sub_add, sub_neg_eq_add], apply sub_lt_sub_left,
apply add_lt_of_lt_sub_left,
rw (show x ^ 3 / 4 - x ^ 3 / 6 = x ^ 3 * 12⁻¹,
by simp [div_eq_mul_inv, ← mul_sub]; norm_num),
apply mul_lt_mul',
{ rw [pow_succ x 3], refine le_trans _ (le_of_eq (one_mul _)),
rw mul_le_mul_right, exact h', apply pow_pos h },
norm_num, norm_num, apply pow_pos h
end
section cos_div_sq
variable (x : ℝ)
/-- the series `sqrt_two_add_series x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2`
-/
@[simp, pp_nodot] noncomputable def sqrt_two_add_series (x : ℝ) : ℕ → ℝ
| 0 := x
| (n+1) := sqrt (2 + sqrt_two_add_series n)
lemma sqrt_two_add_series_zero : sqrt_two_add_series x 0 = x := by simp
lemma sqrt_two_add_series_one : sqrt_two_add_series 0 1 = sqrt 2 := by simp
lemma sqrt_two_add_series_two : sqrt_two_add_series 0 2 = sqrt (2 + sqrt 2) := by simp
lemma sqrt_two_add_series_zero_nonneg : ∀(n : ℕ), 0 ≤ sqrt_two_add_series 0 n
| 0 := le_refl 0
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_nonneg {x : ℝ} (h : 0 ≤ x) : ∀(n : ℕ), 0 ≤ sqrt_two_add_series x n
| 0 := h
| (n+1) := sqrt_nonneg _
lemma sqrt_two_add_series_lt_two : ∀(n : ℕ), sqrt_two_add_series 0 n < 2
| 0 := by norm_num
| (n+1) :=
begin
refine lt_of_lt_of_le _ (sqrt_sq zero_lt_two.le).le,
rw [sqrt_two_add_series, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'],
{ refine (sqrt_two_add_series_lt_two n).trans_le _, norm_num },
{ exact add_nonneg zero_le_two (sqrt_two_add_series_zero_nonneg n) }
end
lemma sqrt_two_add_series_succ (x : ℝ) :
∀(n : ℕ), sqrt_two_add_series x (n+1) = sqrt_two_add_series (sqrt (2 + x)) n
| 0 := rfl
| (n+1) := by rw [sqrt_two_add_series, sqrt_two_add_series_succ, sqrt_two_add_series]
lemma sqrt_two_add_series_monotone_left {x y : ℝ} (h : x ≤ y) :
∀(n : ℕ), sqrt_two_add_series x n ≤ sqrt_two_add_series y n
| 0 := h
| (n+1) :=
begin
rw [sqrt_two_add_series, sqrt_two_add_series],
exact sqrt_le_sqrt (add_le_add_left (sqrt_two_add_series_monotone_left _) _)
end
@[simp] lemma cos_pi_over_two_pow : ∀(n : ℕ), cos (π / 2 ^ (n+1)) = sqrt_two_add_series 0 n / 2
| 0 := by simp
| (n+1) :=
begin
have : (2 : ℝ) ≠ 0 := two_ne_zero,
symmetry, rw [div_eq_iff_mul_eq this], symmetry,
rw [sqrt_two_add_series, sqrt_eq_iff_sq_eq, mul_pow, cos_sq, ←mul_div_assoc,
nat.add_succ, pow_succ, mul_div_mul_left _ _ this, cos_pi_over_two_pow, add_mul],
congr, { norm_num },
rw [mul_comm, sq, mul_assoc, ←mul_div_assoc, mul_div_cancel_left, ←mul_div_assoc,
mul_div_cancel_left]; try { exact this },
apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg, norm_num,
apply le_of_lt, apply cos_pos_of_mem_Ioo ⟨_, _⟩,
{ transitivity (0 : ℝ), rw neg_lt_zero, apply pi_div_two_pos,
apply div_pos pi_pos, apply pow_pos, norm_num },
apply div_lt_div' (le_refl π) _ pi_pos _,
refine lt_of_le_of_lt (le_of_eq (pow_one _).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_lt_succ, apply nat.succ_pos, all_goals {norm_num}
end
lemma sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n+1)) ^ 2 = 1 - (sqrt_two_add_series 0 n / 2) ^ 2 :=
by rw [sin_sq, cos_pi_over_two_pow]
lemma sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) ^ 2 = 1 / 2 - sqrt_two_add_series 0 n / 4 :=
begin
rw [sin_sq_pi_over_two_pow, sqrt_two_add_series, div_pow, sq_sqrt, add_div, ←sub_sub],
congr, norm_num, norm_num, apply add_nonneg, norm_num, apply sqrt_two_add_series_zero_nonneg,
end
@[simp] lemma sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n+2)) = sqrt (2 - sqrt_two_add_series 0 n) / 2 :=
begin
symmetry, rw [div_eq_iff_mul_eq], symmetry,
rw [sqrt_eq_iff_sq_eq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul],
{ congr, norm_num, rw [mul_comm], convert mul_div_cancel' _ _, norm_num, norm_num },
{ rw [sub_nonneg], apply le_of_lt, apply sqrt_two_add_series_lt_two },
apply le_of_lt, apply mul_pos, apply sin_pos_of_pos_of_lt_pi,
{ apply div_pos pi_pos, apply pow_pos, norm_num },
refine lt_of_lt_of_le _ (le_of_eq (div_one _)), rw [div_lt_div_left],
refine lt_of_le_of_lt (le_of_eq (pow_zero 2).symm) _,
apply pow_lt_pow, norm_num, apply nat.succ_pos, apply pi_pos,
apply pow_pos, all_goals {norm_num}
end
@[simp] lemma cos_pi_div_four : cos (π / 4) = sqrt 2 / 2 :=
by { transitivity cos (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma sin_pi_div_four : sin (π / 4) = sqrt 2 / 2 :=
by { transitivity sin (π / 2 ^ 2), congr, norm_num, simp }
@[simp] lemma cos_pi_div_eight : cos (π / 8) = sqrt (2 + sqrt 2) / 2 :=
by { transitivity cos (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma sin_pi_div_eight : sin (π / 8) = sqrt (2 - sqrt 2) / 2 :=
by { transitivity sin (π / 2 ^ 3), congr, norm_num, simp }
@[simp] lemma cos_pi_div_sixteen : cos (π / 16) = sqrt (2 + sqrt (2 + sqrt 2)) / 2 :=
by { transitivity cos (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma sin_pi_div_sixteen : sin (π / 16) = sqrt (2 - sqrt (2 + sqrt 2)) / 2 :=
by { transitivity sin (π / 2 ^ 4), congr, norm_num, simp }
@[simp] lemma cos_pi_div_thirty_two : cos (π / 32) = sqrt (2 + sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity cos (π / 2 ^ 5), congr, norm_num, simp }
@[simp] lemma sin_pi_div_thirty_two : sin (π / 32) = sqrt (2 - sqrt (2 + sqrt (2 + sqrt 2))) / 2 :=
by { transitivity sin (π / 2 ^ 5), congr, norm_num, simp }
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp] lemma cos_pi_div_three : cos (π / 3) = 1 / 2 :=
begin
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0,
{ have : cos (3 * (π / 3)) = cos π := by { congr' 1, ring },
linarith [cos_pi, cos_three_mul (π / 3)] },
cases mul_eq_zero.mp h₁ with h h,
{ linarith [pow_eq_zero h] },
{ have : cos π < cos (π / 3),
{ refine cos_lt_cos_of_nonneg_of_le_pi _ rfl.ge _;
linarith [pi_pos] },
linarith [cos_pi] }
end
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 :=
begin
have h1 : cos (π / 6) ^ 2 = 1 / 2 + 1 / 2 / 2,
{ convert cos_sq (π / 6),
have h2 : 2 * (π / 6) = π / 3 := by cancel_denoms,
rw [h2, cos_pi_div_three] },
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring
end
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp] lemma cos_pi_div_six : cos (π / 6) = (sqrt 3) / 2 :=
begin
suffices : sqrt 3 = cos (π / 6) * 2,
{ field_simp [(by norm_num : 0 ≠ 2)], exact this.symm },
rw sqrt_eq_iff_sq_eq,
{ have h1 := (mul_right_inj' (by norm_num : (4:ℝ) ≠ 0)).mpr sq_cos_pi_div_six,
rw ← sub_eq_zero at h1 ⊢,
convert h1 using 1,
ring },
{ norm_num },
{ have : 0 < cos (π / 6) := by { apply cos_pos_of_mem_Ioo; split; linarith [pi_pos] },
linarith },
end
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp] lemma sin_pi_div_six : sin (π / 6) = 1 / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_three],
congr,
ring
end
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
lemma sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 :=
begin
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six],
congr,
ring
end
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp] lemma sin_pi_div_three : sin (π / 3) = (sqrt 3) / 2 :=
begin
rw [← cos_pi_div_two_sub, ← cos_pi_div_six],
congr,
ring
end
end cos_div_sq
/-- `real.sin` as an `order_iso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sin_order_iso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1:ℝ) 1 :=
(strict_mono_on_sin.order_iso _ _).trans $ order_iso.set_congr _ _ bij_on_sin.image_eq
@[simp] lemma coe_sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
(sin_order_iso x : ℝ) = sin x := rfl
lemma sin_order_iso_apply (x : Icc (-(π / 2)) (π / 2)) :
sin_order_iso x = ⟨sin x, sin_mem_Icc x⟩ := rfl
@[simp] lemma tan_pi_div_four : tan (π / 4) = 1 :=
begin
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four],
have h : (sqrt 2) / 2 > 0 := by cancel_denoms,
exact div_self (ne_of_gt h),
end
@[simp] lemma tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
lemma tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x :=
by rw tan_eq_sin_div_cos; exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
lemma tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| or.inl hx0, or.inl hxp := le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| or.inl hx0, or.inr hxp := by simp [hxp, tan_eq_sin_div_cos]
| or.inr hx0, _ := by simp [hx0.symm]
end
lemma tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
lemma tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
lemma tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ}
(hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) :
tan x < tan y :=
begin
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos],
exact div_lt_div
(sin_lt_sin_of_lt_of_le_pi_div_two (by linarith) (le_of_lt hy₂) hxy)
(cos_le_cos_of_nonneg_of_le_pi hx₁ (by linarith) (le_of_lt hxy))
(sin_nonneg_of_nonneg_of_le_pi (by linarith) (by linarith))
(cos_pos_of_mem_Ioo ⟨by linarith, hy₂⟩)
end
lemma tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x)
(hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y :=
match le_total x 0, le_total y 0 with
| or.inl hx0, or.inl hy0 := neg_lt_neg_iff.1 $ by rw [← tan_neg, ← tan_neg]; exact
tan_lt_tan_of_nonneg_of_lt_pi_div_two (neg_nonneg.2 hy0)
(neg_lt.2 hx₁) (neg_lt_neg hxy)
| or.inl hx0, or.inr hy0 := (lt_or_eq_of_le hy0).elim
(λ hy0, calc tan x ≤ 0 : tan_nonpos_of_nonpos_of_neg_pi_div_two_le hx0 (le_of_lt hx₁)
... < tan y : tan_pos_of_pos_of_lt_pi_div_two hy0 hy₂)
(λ hy0, by rw [← hy0, tan_zero]; exact
tan_neg_of_neg_of_pi_div_two_lt (hy0.symm ▸ hxy) hx₁)
| or.inr hx0, or.inl hy0 := by linarith
| or.inr hx0, or.inr hy0 := tan_lt_tan_of_nonneg_of_lt_pi_div_two hx0 hy₂ hxy
end
lemma strict_mono_on_tan : strict_mono_on tan (Ioo (-(π / 2)) (π / 2)) :=
λ x hx y hy, tan_lt_tan_of_lt_of_lt_pi_div_two hx.1 hy.2
lemma inj_on_tan : inj_on tan (Ioo (-(π / 2)) (π / 2)) :=
strict_mono_on_tan.inj_on
lemma tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
inj_on_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
lemma tan_periodic : function.periodic tan π :=
by simpa only [function.periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℝ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℝ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℝ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma tendsto_sin_pi_div_two : tendsto sin (𝓝[Iio (π/2)] (π/2)) (𝓝 1) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_pi_div_two : tendsto cos (𝓝[Iio (π/2)] (π/2)) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Iio (right_mem_Ioc.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_pi_div_two : tendsto tan (𝓝[Iio (π/2)] (π/2)) at_top :=
begin
convert tendsto_cos_pi_div_two.inv_tendsto_zero.at_top_mul zero_lt_one
tendsto_sin_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
lemma tendsto_sin_neg_pi_div_two : tendsto sin (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝 (-1)) :=
by { convert continuous_sin.continuous_within_at, simp }
lemma tendsto_cos_neg_pi_div_two : tendsto cos (𝓝[Ioi (-(π/2))] (-(π/2))) (𝓝[Ioi 0] 0) :=
begin
apply tendsto_nhds_within_of_tendsto_nhds_of_eventually_within,
{ convert continuous_cos.continuous_within_at, simp },
{ filter_upwards [Ioo_mem_nhds_within_Ioi (left_mem_Ico.mpr (norm_num.lt_neg_pos
_ _ pi_div_two_pos pi_div_two_pos))] λ x hx, cos_pos_of_mem_Ioo hx },
end
lemma tendsto_tan_neg_pi_div_two : tendsto tan (𝓝[Ioi (-(π/2))] (-(π/2))) at_bot :=
begin
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.at_top_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two,
simp only [pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end
end real
namespace complex
open_locale real
lemma sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 :=
by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self];
exact ⟨λ h, by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ eq.symm⟩
@[simp] lemma cos_pi_div_two : cos (π / 2) = 0 :=
calc cos (π / 2) = real.cos (π / 2) : by rw [of_real_cos]; simp
... = 0 : by simp
@[simp] lemma sin_pi_div_two : sin (π / 2) = 1 :=
calc sin (π / 2) = real.sin (π / 2) : by rw [of_real_sin]; simp
... = 1 : by simp
@[simp] lemma sin_pi : sin π = 0 :=
by rw [← of_real_sin, real.sin_pi]; simp
@[simp] lemma cos_pi : cos π = -1 :=
by rw [← of_real_cos, real.cos_pi]; simp
@[simp] lemma sin_two_pi : sin (2 * π) = 0 :=
by simp [two_mul, sin_add]
@[simp] lemma cos_two_pi : cos (2 * π) = 1 :=
by simp [two_mul, cos_add]
lemma sin_antiperiodic : function.antiperiodic sin π :=
by simp [sin_add]
lemma sin_periodic : function.periodic sin (2 * π) :=
sin_antiperiodic.periodic
lemma sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
sin_antiperiodic x
lemma sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
sin_periodic x
lemma sin_sub_pi (x : ℂ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
lemma sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
lemma sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
lemma sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
lemma sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
lemma sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
lemma sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
lemma sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
lemma sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
lemma sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
lemma sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
lemma sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
lemma cos_antiperiodic : function.antiperiodic cos π :=
by simp [cos_add]
lemma cos_periodic : function.periodic cos (2 * π) :=
cos_antiperiodic.periodic
lemma cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
cos_antiperiodic x
lemma cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
cos_periodic x
lemma cos_sub_pi (x : ℂ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
lemma cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
lemma cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
lemma cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
lemma cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
lemma cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
lemma cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
lemma cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
lemma cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
lemma cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
lemma cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
lemma cos_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
lemma cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
lemma cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
lemma cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 :=
by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
lemma sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x :=
by simp [sin_add]
lemma sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x :=
by simp [sub_eq_add_neg, sin_add]
lemma cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x :=
by simp [cos_add]
lemma cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x :=
by simp [sub_eq_add_neg, cos_add]
lemma cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x :=
by rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
lemma tan_periodic : function.periodic tan π :=
by simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
lemma tan_add_pi (x : ℂ) : tan (x + π) = tan x :=
tan_periodic x
lemma tan_sub_pi (x : ℂ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
lemma tan_pi_sub (x : ℂ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
lemma tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
lemma tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
lemma tan_add_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
lemma tan_add_int_mul_pi (x : ℂ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
lemma tan_sub_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
lemma tan_sub_int_mul_pi (x : ℂ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
lemma tan_nat_mul_pi_sub (x : ℂ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
lemma tan_int_mul_pi_sub (x : ℂ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
lemma exp_antiperiodic : function.antiperiodic exp (π * I) :=
by simp [exp_add, exp_mul_I]
lemma exp_periodic : function.periodic exp (2 * π * I) :=
(mul_assoc (2:ℂ) π I).symm ▸ exp_antiperiodic.periodic
lemma exp_mul_I_antiperiodic : function.antiperiodic (λ x, exp (x * I)) π :=
by simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero
lemma exp_mul_I_periodic : function.periodic (λ x, exp (x * I)) (2 * π) :=
exp_mul_I_antiperiodic.periodic
@[simp] lemma exp_pi_mul_I : exp (π * I) = -1 :=
exp_zero ▸ exp_antiperiodic.eq
@[simp] lemma exp_two_pi_mul_I : exp (2 * π * I) = 1 :=
exp_periodic.eq.trans exp_zero
@[simp] lemma exp_nat_mul_two_pi_mul_I (n : ℕ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.nat_mul_eq n).trans exp_zero
@[simp] lemma exp_int_mul_two_pi_mul_I (n : ℤ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.int_mul_eq n).trans exp_zero
@[simp] lemma exp_add_pi_mul_I (z : ℂ) : exp (z + π * I) = -exp z :=
exp_antiperiodic z
@[simp] lemma exp_sub_pi_mul_I (z : ℂ) : exp (z - π * I) = -exp z :=
exp_antiperiodic.sub_eq z
end complex
|
1fae6226f40f7d19e5c5414ae5ba6bf365878535 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/logic/small/list.lean | 22c0c647cb521e249040d54eccb84d5a09ea73bb | [
"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 | 946 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import logic.small.basic
import data.vector.basic
/-!
# Instances for `small (list α)` and `small (vector α)`.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
These must not be in `logic.small.basic` as this is very low in the import hierarchy,
and is used by category theory files which do not need everything imported by `data.vector.basic`.
-/
universes u v
instance small_vector {α : Type v} {n : ℕ} [small.{u} α] :
small.{u} (vector α n) :=
small_of_injective (equiv.vector_equiv_fin α n).injective
instance small_list {α : Type v} [small.{u} α] :
small.{u} (list α) :=
begin
let e : (Σ n, vector α n) ≃ list α := equiv.sigma_fiber_equiv list.length,
exact small_of_surjective e.surjective,
end
|
5c3ff48ca64b552fc8165bfd62635de990eebc4f | 94e33a31faa76775069b071adea97e86e218a8ee | /src/field_theory/finite/galois_field.lean | b0ef45bbc4bb8d8c804faa442daacacc84f1165e | [
"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 | 8,526 | lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Alex J. Best, Johan Commelin, Eric Rodriguez, Ruben Van de Velde
-/
import algebra.char_p.algebra
import field_theory.finite.basic
import field_theory.galois
/-!
# Galois fields
If `p` is a prime number, and `n` a natural number,
then `galois_field p n` is defined as the splitting field of `X^(p^n) - X` over `zmod p`.
It is a finite field with `p ^ n` elements.
## Main definition
* `galois_field p n` is a field with `p ^ n` elements
## Main Results
- `galois_field.alg_equiv_galois_field`: Any finite field is isomorphic to some Galois field
- `finite_field.alg_equiv_of_card_eq`: Uniqueness of finite fields : algebra isomorphism
- `finite_field.ring_equiv_of_card_eq`: Uniqueness of finite fields : ring isomorphism
-/
noncomputable theory
open polynomial
open_locale polynomial
lemma galois_poly_separable {K : Type*} [field K] (p q : ℕ) [char_p K p] (h : p ∣ q) :
separable (X ^ q - X : K[X]) :=
begin
use [1, (X ^ q - X - 1)],
rw [← char_p.cast_eq_zero_iff K[X] p] at h,
rw [derivative_sub, derivative_pow, derivative_X, h],
ring,
end
/-- A finite field with `p ^ n` elements.
Every field with the same cardinality is (non-canonically)
isomorphic to this field. -/
@[derive field]
def galois_field (p : ℕ) [fact p.prime] (n : ℕ) :=
splitting_field (X^(p^n) - X : (zmod p)[X])
instance : inhabited (@galois_field 2 (fact.mk nat.prime_two) 1) :=
⟨37⟩
namespace galois_field
variables (p : ℕ) [fact p.prime] (n : ℕ)
instance : algebra (zmod p) (galois_field p n) :=
splitting_field.algebra _
instance : is_splitting_field (zmod p) (galois_field p n) (X^(p^n) - X) :=
polynomial.is_splitting_field.splitting_field _
instance : char_p (galois_field p n) p :=
(algebra.char_p_iff (zmod p) (galois_field p n) p).mp (by apply_instance)
instance : fintype (galois_field p n) := by {dsimp only [galois_field],
exact finite_dimensional.fintype_of_fintype (zmod p) (galois_field p n) }
lemma finrank {n} (h : n ≠ 0) : finite_dimensional.finrank (zmod p) (galois_field p n) = n :=
begin
set g_poly := (X^(p^n) - X : (zmod p)[X]),
have hp : 1 < p := (fact.out (nat.prime p)).one_lt,
have aux : g_poly ≠ 0 := finite_field.X_pow_card_pow_sub_X_ne_zero _ h hp,
have key : fintype.card ((g_poly).root_set (galois_field p n)) = (g_poly).nat_degree :=
card_root_set_eq_nat_degree (galois_poly_separable p _ (dvd_pow (dvd_refl p) h))
(splitting_field.splits g_poly),
have nat_degree_eq : (g_poly).nat_degree = p ^ n :=
finite_field.X_pow_card_pow_sub_X_nat_degree_eq _ h hp,
rw nat_degree_eq at key,
suffices : (g_poly).root_set (galois_field p n) = set.univ,
{ simp_rw [this, ←fintype.of_equiv_card (equiv.set.univ _)] at key,
rw [@card_eq_pow_finrank (zmod p), zmod.card] at key,
exact nat.pow_right_injective ((nat.prime.one_lt' p).out) key },
rw set.eq_univ_iff_forall,
suffices : ∀ x (hx : x ∈ (⊤ : subalgebra (zmod p) (galois_field p n))),
x ∈ (X ^ p ^ n - X : (zmod p)[X]).root_set (galois_field p n),
{ simpa, },
rw ← splitting_field.adjoin_root_set,
simp_rw algebra.mem_adjoin_iff,
intros x hx,
-- We discharge the `p = 0` separately, to avoid typeclass issues on `zmod p`.
unfreezingI { cases p, cases hp, },
apply subring.closure_induction hx; clear_dependent x; simp_rw mem_root_set aux,
{ rintros x (⟨r, rfl⟩ | hx),
{ simp only [aeval_X_pow, aeval_X, alg_hom.map_sub],
rw [← map_pow, zmod.pow_card_pow, sub_self], },
{ dsimp only [galois_field] at hx,
rwa mem_root_set aux at hx, }, },
{ dsimp only [g_poly],
rw [← coeff_zero_eq_aeval_zero'],
simp only [coeff_X_pow, coeff_X_zero, sub_zero, ring_hom.map_eq_zero, ite_eq_right_iff,
one_ne_zero, coeff_sub],
intro hn,
exact nat.not_lt_zero 1 (pow_eq_zero hn.symm ▸ hp), },
{ simp, },
{ simp only [aeval_X_pow, aeval_X, alg_hom.map_sub, add_pow_char_pow, sub_eq_zero],
intros x y hx hy,
rw [hx, hy], },
{ intros x hx,
simp only [sub_eq_zero, aeval_X_pow, aeval_X, alg_hom.map_sub, sub_neg_eq_add] at *,
rw [neg_pow, hx, char_p.neg_one_pow_char_pow],
simp, },
{ simp only [aeval_X_pow, aeval_X, alg_hom.map_sub, mul_pow, sub_eq_zero],
intros x y hx hy,
rw [hx, hy], },
end
lemma card (h : n ≠ 0) : fintype.card (galois_field p n) = p ^ n :=
begin
let b := is_noetherian.finset_basis (zmod p) (galois_field p n),
rw [module.card_fintype b, ← finite_dimensional.finrank_eq_card_basis b, zmod.card, finrank p h],
end
theorem splits_zmod_X_pow_sub_X : splits (ring_hom.id (zmod p)) (X ^ p - X) :=
begin
have hp : 1 < p := (fact.out (nat.prime p)).one_lt,
have h1 : roots (X ^ p - X : (zmod p)[X]) = finset.univ.val,
{ convert finite_field.roots_X_pow_card_sub_X _,
exact (zmod.card p).symm },
have h2 := finite_field.X_pow_card_sub_X_nat_degree_eq (zmod p) hp,
-- We discharge the `p = 0` separately, to avoid typeclass issues on `zmod p`.
unfreezingI { cases p, cases hp, },
rw [splits_iff_card_roots, h1, ←finset.card_def, finset.card_univ, h2, zmod.card],
end
/-- A Galois field with exponent 1 is equivalent to `zmod` -/
def equiv_zmod_p : galois_field p 1 ≃ₐ[zmod p] (zmod p) :=
have h : (X ^ p ^ 1 : (zmod p)[X]) = X ^ (fintype.card (zmod p)),
by rw [pow_one, zmod.card p],
have inst : is_splitting_field (zmod p) (zmod p) (X ^ p ^ 1 - X),
by { rw h, apply_instance },
by exactI (is_splitting_field.alg_equiv (zmod p) (X ^ (p ^ 1) - X : (zmod p)[X])).symm
variables {K : Type*} [field K] [fintype K] [algebra (zmod p) K]
theorem splits_X_pow_card_sub_X : splits (algebra_map (zmod p) K) (X ^ fintype.card K - X) :=
(finite_field.has_sub.sub.polynomial.is_splitting_field K (zmod p)).splits
lemma is_splitting_field_of_card_eq (h : fintype.card K = p ^ n) :
is_splitting_field (zmod p) K (X ^ (p ^ n) - X) :=
h ▸ finite_field.has_sub.sub.polynomial.is_splitting_field K (zmod p)
@[priority 100]
instance {K K' : Type*} [field K] [field K'] [fintype K'] [algebra K K'] : is_galois K K' :=
begin
obtain ⟨p, hp⟩ := char_p.exists K,
haveI : char_p K p := hp,
haveI : char_p K' p := char_p_of_injective_algebra_map' K K' p,
exact is_galois.of_separable_splitting_field (galois_poly_separable p (fintype.card K')
(let ⟨n, hp, hn⟩ := finite_field.card K' p in hn.symm ▸ dvd_pow_self p n.ne_zero)),
end
/-- Any finite field is (possibly non canonically) isomorphic to some Galois field. -/
def alg_equiv_galois_field (h : fintype.card K = p ^ n) :
K ≃ₐ[zmod p] galois_field p n :=
by haveI := is_splitting_field_of_card_eq _ _ h; exact is_splitting_field.alg_equiv _ _
end galois_field
namespace finite_field
variables {K : Type*} [field K] [fintype K] {K' : Type*} [field K'] [fintype K']
/-- Uniqueness of finite fields:
Any two finite fields of the same cardinality are (possibly non canonically) isomorphic-/
def alg_equiv_of_card_eq (p : ℕ) [fact p.prime] [algebra (zmod p) K] [algebra (zmod p) K']
(hKK' : fintype.card K = fintype.card K') :
K ≃ₐ[zmod p] K' :=
begin
haveI : char_p K p,
{ rw ← algebra.char_p_iff (zmod p) K p, exact zmod.char_p p, },
haveI : char_p K' p,
{ rw ← algebra.char_p_iff (zmod p) K' p, exact zmod.char_p p, },
choose n a hK using finite_field.card K p,
choose n' a' hK' using finite_field.card K' p,
rw [hK,hK'] at hKK',
have hGalK := galois_field.alg_equiv_galois_field p n hK,
have hK'Gal := (galois_field.alg_equiv_galois_field p n' hK').symm,
rw (nat.pow_right_injective (fact.out (nat.prime p)).one_lt hKK') at *,
use alg_equiv.trans hGalK hK'Gal,
end
/-- Uniqueness of finite fields:
Any two finite fields of the same cardinality are (possibly non canonically) isomorphic-/
def ring_equiv_of_card_eq (hKK' : fintype.card K = fintype.card K') : K ≃+* K' :=
begin
choose p _char_p_K using char_p.exists K,
choose p' _char_p'_K' using char_p.exists K',
resetI,
choose n hp hK using finite_field.card K p,
choose n' hp' hK' using finite_field.card K' p',
have hpp' : p = p', -- := eq_prime_of_eq_prime_pow
{ by_contra hne,
have h2 := nat.coprime_pow_primes n n' hp hp' hne,
rw [(eq.congr hK hK').mp hKK', nat.coprime_self, pow_eq_one_iff (pnat.ne_zero n')] at h2,
exact nat.prime.ne_one hp' h2,
all_goals {apply_instance}, },
rw ← hpp' at *,
haveI := fact_iff.2 hp,
exact alg_equiv_of_card_eq p hKK',
end
end finite_field
|
bb811dd8a9a75336d7013b924ad2cf00780b6651 | e953c38599905267210b87fb5d82dcc3e52a4214 | /library/data/pnat.lean | 0276fa59411316dece4a07b50e85216cb6b717b4 | [
"Apache-2.0"
] | permissive | c-cube/lean | 563c1020bff98441c4f8ba60111fef6f6b46e31b | 0fb52a9a139f720be418dafac35104468e293b66 | refs/heads/master | 1,610,753,294,113 | 1,440,451,356,000 | 1,440,499,588,000 | 41,748,334 | 0 | 0 | null | 1,441,122,656,000 | 1,441,122,656,000 | null | UTF-8 | Lean | false | false | 10,338 | lean | /-
Copyright (c) 2015 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Robert Y. Lewis
Basic facts about the positive natural numbers.
Developed primarily for use in the construction of ℝ. For the most part, the only theorems here
are those needed for that construction.
-/
import data.rat.order data.nat
open nat rat subtype eq.ops
namespace pnat
definition pnat := { n : ℕ | n > 0 }
notation `ℕ+` := pnat
definition pos (n : ℕ) (H : n > 0) : ℕ+ := tag n H
definition nat_of_pnat (p : ℕ+) : ℕ := elt_of p
reserve postfix `~`:std.prec.max_plus
local postfix ~ := nat_of_pnat
theorem pnat_pos (p : ℕ+) : p~ > 0 := has_property p
definition add (p q : ℕ+) : ℕ+ :=
tag (p~ + q~) (nat.add_pos (pnat_pos p) (pnat_pos q))
infix `+` := add
definition mul (p q : ℕ+) : ℕ+ :=
tag (p~ * q~) (nat.mul_pos (pnat_pos p) (pnat_pos q))
infix `*` := mul
definition le (p q : ℕ+) := p~ ≤ q~
infix `≤` := le
notation p `≥` q := q ≤ p
definition lt (p q : ℕ+) := p~ < q~
infix `<` := lt
protected theorem pnat.eq {p q : ℕ+} : p~ = q~ → p = q :=
subtype.eq
definition pnat_le_decidable [instance] (p q : ℕ+) : decidable (p ≤ q) :=
nat.decidable_le p~ q~
definition pnat_lt_decidable [instance] {p q : ℕ+} : decidable (p < q) :=
nat.decidable_lt p~ q~
theorem le.trans {p q r : ℕ+} (H1 : p ≤ q) (H2 : q ≤ r) : p ≤ r := nat.le.trans H1 H2
definition max (p q : ℕ+) :=
tag (nat.max p~ q~) (nat.lt_of_lt_of_le (!pnat_pos) (!le_max_right))
theorem max_right (a b : ℕ+) : max a b ≥ b := !le_max_right
theorem max_left (a b : ℕ+) : max a b ≥ a := !le_max_left
theorem max_eq_right {a b : ℕ+} (H : a < b) : max a b = b :=
pnat.eq (nat.max_eq_right_of_lt H)
theorem max_eq_left {a b : ℕ+} (H : ¬ a < b) : max a b = a :=
pnat.eq (nat.max_eq_left (le_of_not_gt H))
theorem le_of_lt {a b : ℕ+} : a < b → a ≤ b := nat.le_of_lt
theorem not_lt_of_ge {a b : ℕ+} : a ≤ b → ¬ (b < a) := nat.not_lt_of_ge
theorem le_of_not_gt {a b : ℕ+} : ¬ a < b → b ≤ a := nat.le_of_not_gt
theorem eq_of_le_of_ge {a b : ℕ+} (H1 : a ≤ b) (H2 : b ≤ a) : a = b :=
pnat.eq (nat.eq_of_le_of_ge H1 H2)
theorem le.refl (a : ℕ+) : a ≤ a := !nat.le.refl
notation 2 := (tag 2 dec_trivial : ℕ+)
notation 3 := (tag 3 dec_trivial : ℕ+)
definition pone : ℕ+ := tag 1 dec_trivial
definition rat_of_pnat [reducible] (n : ℕ+) : ℚ := n~
theorem pnat.to_rat_of_nat (n : ℕ+) : rat_of_pnat n = of_nat n~ := rfl
-- these will come in rat
theorem rat_of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial
theorem rat_of_pnat_ge_one (n : ℕ+) : rat_of_pnat n ≥ 1 :=
(iff.mpr !of_nat_le_of_nat) (pnat_pos n)
theorem rat_of_pnat_is_pos (n : ℕ+) : rat_of_pnat n > 0 :=
(iff.mpr !of_nat_pos) (pnat_pos n)
theorem of_nat_le_of_nat_of_le {m n : ℕ} (H : m ≤ n) : of_nat m ≤ of_nat n :=
(iff.mpr !of_nat_le_of_nat) H
theorem of_nat_lt_of_nat_of_lt {m n : ℕ} (H : m < n) : of_nat m < of_nat n :=
(iff.mpr !of_nat_lt_of_nat) H
theorem rat_of_pnat_le_of_pnat_le {m n : ℕ+} (H : m ≤ n) : rat_of_pnat m ≤ rat_of_pnat n :=
of_nat_le_of_nat_of_le H
theorem rat_of_pnat_lt_of_pnat_lt {m n : ℕ+} (H : m < n) : rat_of_pnat m < rat_of_pnat n :=
of_nat_lt_of_nat_of_lt H
theorem pnat_le_of_rat_of_pnat_le {m n : ℕ+} (H : rat_of_pnat m ≤ rat_of_pnat n) : m ≤ n :=
(iff.mp !of_nat_le_of_nat) H
definition inv (n : ℕ+) : ℚ := (1 : ℚ) / rat_of_pnat n
postfix `⁻¹` := inv
theorem inv_pos (n : ℕ+) : n⁻¹ > 0 := div_pos_of_pos !rat_of_pnat_is_pos
theorem inv_le_one (n : ℕ+) : n⁻¹ ≤ (1 : ℚ) :=
begin
rewrite [↑inv, -one_div_one],
apply div_le_div_of_le,
apply rat.zero_lt_one,
apply rat_of_pnat_ge_one
end
theorem inv_lt_one_of_gt {n : ℕ+} (H : n~ > 1) : n⁻¹ < (1 : ℚ) :=
begin
rewrite [↑inv, -one_div_one],
apply div_lt_div_of_lt,
apply rat.zero_lt_one,
rewrite pnat.to_rat_of_nat,
apply (of_nat_lt_of_nat_of_lt H)
end
theorem pone_inv : pone⁻¹ = 1 := rfl
theorem add_invs_nonneg (m n : ℕ+) : 0 ≤ m⁻¹ + n⁻¹ :=
begin
apply rat.le_of_lt,
apply rat.add_pos,
repeat apply inv_pos
end
theorem one_mul (n : ℕ+) : pone * n = n :=
begin
apply pnat.eq,
rewrite [↑pone, ↑mul, ↑nat_of_pnat, one_mul]
end
theorem pone_le (n : ℕ+) : pone ≤ n :=
succ_le_of_lt (pnat_pos n)
theorem pnat_to_rat_mul (a b : ℕ+) : rat_of_pnat (a * b) = rat_of_pnat a * rat_of_pnat b := rfl
theorem mul_lt_mul_left (a b c : ℕ+) (H : a < b) : a * c < b * c :=
nat.mul_lt_mul_of_pos_right H !pnat_pos
theorem one_lt_two : pone < 2 := !nat.le.refl
theorem inv_two_mul_lt_inv (n : ℕ+) : (2 * n)⁻¹ < n⁻¹ :=
begin
rewrite ↑inv,
apply div_lt_div_of_lt,
apply rat_of_pnat_is_pos,
have H : n~ < (2 * n)~, begin
rewrite -one_mul at {1},
apply mul_lt_mul_left,
apply one_lt_two
end,
apply of_nat_lt_of_nat_of_lt,
apply H
end
theorem inv_two_mul_le_inv (n : ℕ+) : (2 * n)⁻¹ ≤ n⁻¹ := rat.le_of_lt !inv_two_mul_lt_inv
theorem inv_ge_of_le {p q : ℕ+} (H : p ≤ q) : q⁻¹ ≤ p⁻¹ :=
div_le_div_of_le !rat_of_pnat_is_pos (rat_of_pnat_le_of_pnat_le H)
theorem inv_gt_of_lt {p q : ℕ+} (H : p < q) : q⁻¹ < p⁻¹ :=
div_lt_div_of_lt !rat_of_pnat_is_pos (rat_of_pnat_lt_of_pnat_lt H)
theorem ge_of_inv_le {p q : ℕ+} (H : p⁻¹ ≤ q⁻¹) : q ≤ p :=
pnat_le_of_rat_of_pnat_le (le_of_div_le !rat_of_pnat_is_pos H)
theorem two_mul (p : ℕ+) : rat_of_pnat (2 * p) = (1 + 1) * rat_of_pnat p :=
by rewrite pnat_to_rat_mul
theorem add_halves (p : ℕ+) : (2 * p)⁻¹ + (2 * p)⁻¹ = p⁻¹ :=
begin
rewrite [↑inv, -(@add_halves (1 / (rat_of_pnat p))), *div_div_eq_div_mul'],
have H : rat_of_pnat (2 * p) = rat_of_pnat p * (1 + 1), by rewrite [rat.mul.comm, two_mul],
rewrite *H
end
theorem add_halves_double (m n : ℕ+) :
m⁻¹ + n⁻¹ = ((2 * m)⁻¹ + (2 * n)⁻¹) + ((2 * m)⁻¹ + (2 * n)⁻¹) :=
have hsimp [visible] : ∀ a b : ℚ, (a + a) + (b + b) = (a + b) + (a + b),
by intros; rewrite [rat.add.assoc, -(rat.add.assoc a b b), {_+b}rat.add.comm, -*rat.add.assoc],
by rewrite [-add_halves m, -add_halves n, hsimp]
theorem inv_mul_eq_mul_inv {p q : ℕ+} : (p * q)⁻¹ = p⁻¹ * q⁻¹ :=
by rewrite [↑inv, pnat_to_rat_mul, one_div_mul_one_div''']
theorem inv_mul_le_inv (p q : ℕ+) : (p * q)⁻¹ ≤ q⁻¹ :=
begin
rewrite [inv_mul_eq_mul_inv, -{q⁻¹}rat.one_mul at {2}],
apply rat.mul_le_mul,
apply inv_le_one,
apply rat.le.refl,
apply rat.le_of_lt,
apply inv_pos,
apply rat.le_of_lt rat.zero_lt_one
end
theorem pnat_mul_le_mul_left' (a b c : ℕ+) (H : a ≤ b) : c * a ≤ c * b :=
nat.mul_le_mul_of_nonneg_left H (nat.le_of_lt !pnat_pos)
theorem mul.assoc (a b c : ℕ+) : a * b * c = a * (b * c) :=
pnat.eq !nat.mul.assoc
theorem mul.comm (a b : ℕ+) : a * b = b * a :=
pnat.eq !nat.mul.comm
theorem add.assoc (a b c : ℕ+) : a + b + c = a + (b + c) :=
pnat.eq !nat.add.assoc
theorem mul_le_mul_left (p q : ℕ+) : q ≤ p * q :=
begin
rewrite [-one_mul at {1}, mul.comm, mul.comm p],
apply pnat_mul_le_mul_left',
apply pone_le
end
theorem mul_le_mul_right (p q : ℕ+) : p ≤ p * q :=
by rewrite mul.comm; apply mul_le_mul_left
theorem pnat.lt_of_not_le {p q : ℕ+} (H : ¬ p ≤ q) : q < p :=
nat.lt_of_not_ge H
theorem inv_cancel_left (p : ℕ+) : rat_of_pnat p * p⁻¹ = (1 : ℚ) :=
mul_one_div_cancel (ne.symm (rat.ne_of_lt !rat_of_pnat_is_pos))
theorem inv_cancel_right (p : ℕ+) : p⁻¹ * rat_of_pnat p = (1 : ℚ) :=
by rewrite rat.mul.comm; apply inv_cancel_left
theorem lt_add_left (p q : ℕ+) : p < p + q :=
begin
have H : p~ < p~ + q~, begin
rewrite -nat.add_zero at {1},
apply nat.add_lt_add_left,
apply pnat_pos
end,
apply H
end
theorem inv_add_lt_left (p q : ℕ+) : (p + q)⁻¹ < p⁻¹ :=
by apply inv_gt_of_lt; apply lt_add_left
theorem div_le_pnat (q : ℚ) (n : ℕ+) (H : q ≥ n⁻¹) : 1 / q ≤ rat_of_pnat n :=
begin
apply rat.div_le_of_le_mul,
apply rat.lt_of_lt_of_le,
apply inv_pos,
rotate 1,
apply H,
apply rat.le_mul_of_div_le,
apply rat_of_pnat_is_pos,
apply H
end
theorem pnat_cancel' (n m : ℕ+) : (n * n * m)⁻¹ * (rat_of_pnat n * rat_of_pnat n) = m⁻¹ :=
assert hsimp : ∀ a b c : ℚ, (a * a * (b * b * c)) = (a * b) * (a * b) * c, from
λa b c, by rewrite[-*rat.mul.assoc]; exact (!rat.mul.right_comm ▸ rfl),
by rewrite [rat.mul.comm, *inv_mul_eq_mul_inv, hsimp, *inv_cancel_left, *rat.one_mul]
definition pceil (a : ℚ) : ℕ+ := tag (ubound a) !ubound_pos
theorem pceil_helper {a : ℚ} {n : ℕ+} (H : pceil a ≤ n) (Ha : a > 0) : n⁻¹ ≤ 1 / a :=
rat.le.trans (inv_ge_of_le H) (div_le_div_of_le Ha (ubound_ge a))
theorem inv_pceil_div (a b : ℚ) (Ha : a > 0) (Hb : b > 0) : (pceil (a / b))⁻¹ ≤ b / a :=
div_div' ▸ div_le_div_of_le
(div_pos_of_pos (pos_div_of_pos_of_pos Hb Ha))
((div_div_eq_mul_div (ne_of_gt Hb) (ne_of_gt Ha))⁻¹ ▸
!rat.one_mul⁻¹ ▸ !ubound_ge)
theorem sep_by_inv {a b : ℚ} (H : a > b) : ∃ N : ℕ+, a > (b + N⁻¹ + N⁻¹) :=
begin
apply exists.elim (find_midpoint H),
intro c Hc,
existsi (pceil ((1 + 1 + 1) / c)),
apply rat.lt.trans,
rotate 1,
apply and.left Hc,
rewrite rat.add.assoc,
apply rat.add_lt_add_left,
rewrite -(@rat.add_halves c) at {3},
apply rat.add_lt_add,
repeat (apply rat.lt_of_le_of_lt;
apply inv_pceil_div;
apply dec_trivial;
apply and.right Hc;
apply div_lt_div_of_pos_of_lt_of_pos;
repeat (apply two_pos);
apply and.right Hc)
end
theorem nonneg_of_ge_neg_invs (a : ℚ) (H : ∀ n : ℕ+, -n⁻¹ ≤ a) : 0 ≤ a :=
rat.le_of_not_gt (suppose a < 0,
have H2 : 0 < -a, from neg_pos_of_neg this,
(rat.not_lt_of_ge !H) (iff.mp !lt_neg_iff_lt_neg (calc
(pceil (of_num 2 / -a))⁻¹ ≤ -a / of_num 2
: !inv_pceil_div dec_trivial H2
... < -a / 1
: div_lt_div_of_pos_of_lt_of_pos dec_trivial dec_trivial H2
... = -a : div_one)))
end pnat
|
31c42d7d9503e0b24d57aa767483a2e77f1ac96b | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /library/init/meta/ref.lean | d58a8b8aa86e821e8782b75777b0ca4145df9a18 | [
"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 | 713 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic
universes u v
namespace tactic
meta constant ref (α : Type u) : Type u
/- Create a new reference `r` with initial value `a`, execute `t r`, and then delete `r`. -/
meta constant using_new_ref {α : Type u} {β : Type v} (a : α) (t : ref α → tactic β) : tactic β
/- Read the value stored in the given reference. -/
meta constant read_ref {α : Type u} : ref α → tactic α
/- Update the value stored in the given reference. -/
meta constant write_ref {α : Type u} : ref α → α → tactic unit
end tactic
|
c46ac88c0f52085adf9d6cc8a6059e8505bdf077 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/linear_algebra/multilinear.lean | 83b3225dd9dc5c872c51a5996bcfe73867f19696 | [
"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 | 33,815 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import linear_algebra.basic
import tactic.omega
import data.fintype.card
/-!
# Multilinear maps
We define multilinear maps as maps from `Π(i : ι), M₁ i` to `M₂` which are linear in each
coordinate. Here, `M₁ i` and `M₂` are modules over a ring `R`, and `ι` is an arbitrary type
(although some statements will require it to be a fintype). This space, denoted by
`multilinear_map R M₁ M₂`, inherits a module structure by pointwise addition and multiplication.
## Main definitions
* `multilinear_map R M₁ M₂` is the space of multilinear maps from `Π(i : ι), M₁ i` to `M₂`.
* `f.map_smul` is the multiplicativity of the multilinear map `f` along each coordinate.
* `f.map_add` is the additivity of the multilinear map `f` along each coordinate.
* `f.map_smul_univ` expresses the multiplicativity of `f` over all coordinates at the same time,
writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`.
* `f.map_add_univ` expresses the additivity of `f` over all coordinates at the same time, writing
`f (m + m')` as the sum over all subsets `s` of `ι` of `f (s.piecewise m m')`.
* `f.map_sum` expresses `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` as the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all possible functions.
We also register isomorphisms corresponding to currying or uncurrying variables, transforming a
multilinear function `f` on `n+1` variables into a linear function taking values in multilinear
functions in `n` variables, and into a multilinear function in `n` variables taking values in linear
functions. These operations are called `f.curry_left` and `f.curry_right` respectively
(with inverses `f.uncurry_left` and `f.uncurry_right`). These operations induce linear equivalences
between spaces of multilinear functions in `n+1` variables and spaces of linear functions into
multilinear functions in `n` variables (resp. multilinear functions in `n` variables taking values
in linear functions), called respectively `multilinear_curry_left_equiv` and
`multilinear_curry_right_equiv`.
## Implementation notes
Expressing that a map is linear along the `i`-th coordinate when all other coordinates are fixed
can be done in two (equivalent) different ways:
* fixing a vector `m : Π(j : ι - i), M₁ j.val`, and then choosing separately the `i`-th coordinate
* fixing a vector `m : Πj, M₁ j`, and then modifying its `i`-th coordinate
The second way is more artificial as the value of `m` at `i` is not relevant, but it has the
advantage of avoiding subtype inclusion issues. This is the definition we use, based on
`function.update` that allows to change the value of `m` at `i`.
-/
open function fin set
open_locale big_operators
universes u v v' v₁ v₂ v₃ w u'
variables {R : Type u} {ι : Type u'} {n : ℕ}
{M : fin n.succ → Type v} {M₁ : ι → Type v₁} {M₂ : Type v₂} {M₃ : Type v₃} {M' : Type v'}
[decidable_eq ι]
/-- Multilinear maps over the ring `R`, from `Πi, M₁ i` to `M₂` where `M₁ i` and `M₂` are modules
over `R`. -/
structure multilinear_map (R : Type u) {ι : Type u'} (M₁ : ι → Type v) (M₂ : Type w)
[decidable_eq ι] [semiring R] [∀i, add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [∀i, semimodule R (M₁ i)]
[semimodule R M₂] :=
(to_fun : (Πi, M₁ i) → M₂)
(map_add' : ∀(m : Πi, M₁ i) (i : ι) (x y : M₁ i),
to_fun (update m i (x + y)) = to_fun (update m i x) + to_fun (update m i y))
(map_smul' : ∀(m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i),
to_fun (update m i (c • x)) = c • to_fun (update m i x))
namespace multilinear_map
section semiring
variables [semiring R]
[∀i, add_comm_monoid (M i)] [∀i, add_comm_monoid (M₁ i)] [add_comm_monoid M₂] [add_comm_monoid M₃]
[add_comm_monoid M']
[∀i, semimodule R (M i)] [∀i, semimodule R (M₁ i)] [semimodule R M₂] [semimodule R M₃] [semimodule R M']
(f f' : multilinear_map R M₁ M₂)
instance : has_coe_to_fun (multilinear_map R M₁ M₂) := ⟨_, to_fun⟩
@[ext] theorem ext {f f' : multilinear_map R M₁ M₂} (H : ∀ x, f x = f' x) : f = f' :=
by cases f; cases f'; congr'; exact funext H
@[simp] lemma map_add (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x + y)) = f (update m i x) + f (update m i y) :=
f.map_add' m i x y
@[simp] lemma map_smul (m : Πi, M₁ i) (i : ι) (c : R) (x : M₁ i) :
f (update m i (c • x)) = c • f (update m i x) :=
f.map_smul' m i c x
lemma map_coord_zero {m : Πi, M₁ i} (i : ι) (h : m i = 0) : f m = 0 :=
begin
have : (0 : R) • (0 : M₁ i) = 0, by simp,
rw [← update_eq_self i m, h, ← this, f.map_smul, zero_smul]
end
@[simp] lemma map_zero [nonempty ι] : f 0 = 0 :=
begin
obtain ⟨i, _⟩ : ∃i:ι, i ∈ set.univ := set.exists_mem_of_nonempty ι,
exact map_coord_zero f i rfl
end
instance : has_add (multilinear_map R M₁ M₂) :=
⟨λf f', ⟨λx, f x + f' x, λm i x y, by simp [add_left_comm, add_assoc], λm i c x, by simp [smul_add]⟩⟩
@[simp] lemma add_apply (m : Πi, M₁ i) : (f + f') m = f m + f' m := rfl
instance : has_zero (multilinear_map R M₁ M₂) :=
⟨⟨λ _, 0, λm i x y, by simp, λm i c x, by simp⟩⟩
instance : inhabited (multilinear_map R M₁ M₂) := ⟨0⟩
@[simp] lemma zero_apply (m : Πi, M₁ i) : (0 : multilinear_map R M₁ M₂) m = 0 := rfl
instance : add_comm_monoid (multilinear_map R M₁ M₂) :=
by refine {zero := 0, add := (+), ..};
intros; ext; simp [add_comm, add_left_comm]
@[simp] lemma sum_apply {α : Type*} (f : α → multilinear_map R M₁ M₂)
(m : Πi, M₁ i) : ∀ {s : finset α}, (∑ a in s, f a) m = ∑ a in s, f a m :=
begin
classical,
apply finset.induction,
{ rw finset.sum_empty, simp },
{ assume a s has H, rw finset.sum_insert has, simp [H, has] }
end
/-- If `f` is a multilinear map, then `f.to_linear_map m i` is the linear map obtained by fixing all
coordinates but `i` equal to those of `m`, and varying the `i`-th coordinate. -/
def to_linear_map (m : Πi, M₁ i) (i : ι) : M₁ i →ₗ[R] M₂ :=
{ to_fun := λx, f (update m i x),
map_add' := λx y, by simp,
map_smul' := λc x, by simp }
/-- The cartesian product of two multilinear maps, as a multilinear map. -/
def prod (f : multilinear_map R M₁ M₂) (g : multilinear_map R M₁ M₃) :
multilinear_map R M₁ (M₂ × M₃) :=
{ to_fun := λ m, (f m, g m),
map_add' := λ m i x y, by simp,
map_smul' := λ m i c x, by simp }
/-- Given a multilinear map `f` on `n` variables (parameterized by `fin n`) and a subset `s` of `k`
of these variables, one gets a new multilinear map on `fin k` by varying these variables, and fixing
the other ones equal to a given value `z`. It is denoted by `f.restr s hk z`, where `hk` is a
proof that the cardinality of `s` is `k`. The implicit identification between `fin k` and `s` that
we use is the canonical (increasing) bijection. -/
noncomputable def restr {k n : ℕ} (f : multilinear_map R (λ i : fin n, M') M₂) (s : finset (fin n))
(hk : s.card = k) (z : M') :
multilinear_map R (λ i : fin k, M') M₂ :=
{ to_fun := λ v, f (λ j, if h : j ∈ s then v ((s.mono_equiv_of_fin hk).symm ⟨j, h⟩) else z),
map_add' := λ v i x y,
by { erw [dite_comp_equiv_update, dite_comp_equiv_update, dite_comp_equiv_update], simp },
map_smul' := λ v i c x, by { erw [dite_comp_equiv_update, dite_comp_equiv_update], simp } }
variable {R}
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma cons_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (x y : M 0) :
f (cons (x+y) m) = f (cons x m) + f (cons y m) :=
by rw [← update_cons_zero x m (x+y), f.map_add, update_cons_zero, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma cons_smul (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.succ) (c : R) (x : M 0) :
f (cons (c • x) m) = c • f (cons x m) :=
by rw [← update_cons_zero x m (c • x), f.map_smul, update_cons_zero]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `snoc`, one can express directly the additivity of a
multilinear map along the first variable. -/
lemma snoc_add (f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x y : M (last n)) :
f (snoc m (x+y)) = f (snoc m x) + f (snoc m y) :=
by rw [← update_snoc_last x m (x+y), f.map_add, update_snoc_last, update_snoc_last]
/-- In the specific case of multilinear maps on spaces indexed by `fin (n+1)`, where one can build
an element of `Π(i : fin (n+1)), M i` using `cons`, one can express directly the multiplicativity
of a multilinear map along the first variable. -/
lemma snoc_smul (f : multilinear_map R M M₂)
(m : Π(i : fin n), M i.cast_succ) (c : R) (x : M (last n)) :
f (snoc m (c • x)) = c • f (snoc m x) :=
by rw [← update_snoc_last x m (c • x), f.map_smul, update_snoc_last]
/- If `R` and `M₂` are implicit in the next definition, Lean is never able to infer them, even
given `g` and `f`. Therefore, we make them explicit. -/
variables (R M₂)
/-- If `g` is multilinear and `f` is linear, then `g (f m₁, ..., f mₙ)` is again a multilinear
function, that we call `g.comp_linear_map f`. -/
def comp_linear_map (g : multilinear_map R (λ (i : ι), M₂) M₃) (f : M' →ₗ[R] M₂) :
multilinear_map R (λ (i : ι), M') M₃ :=
{ to_fun := λ m, g (f ∘ m),
map_add' := λ m i x y, by simp [comp_update],
map_smul' := λ m i c x, by simp [comp_update] }
variables {R M₂}
/-- If one adds to a vector `m'` another vector `m`, but only for coordinates in a finset `t`, then
the image under a multilinear map `f` is the sum of `f (s.piecewise m m')` along all subsets `s` of
`t`. This is mainly an auxiliary statement to prove the result when `t = univ`, given in
`map_add_univ`, although it can be useful in its own right as it does not require the index set `ι`
to be finite.-/
lemma map_piecewise_add (m m' : Πi, M₁ i) (t : finset ι) :
f (t.piecewise (m + m') m') = ∑ s in t.powerset, f (s.piecewise m m') :=
begin
revert m',
refine finset.induction_on t (by simp) _,
assume i t hit Hrec m',
have A : (insert i t).piecewise (m + m') m' = update (t.piecewise (m + m') m') i (m i + m' i) :=
t.piecewise_insert _ _ _,
have B : update (t.piecewise (m + m') m') i (m' i) = t.piecewise (m + m') m',
{ ext j,
by_cases h : j = i,
{ rw h, simp [hit] },
{ simp [h] } },
let m'' := update m' i (m i),
have C : update (t.piecewise (m + m') m') i (m i) = t.piecewise (m + m'') m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', hit] },
{ by_cases h' : j ∈ t; simp [h, hit, m'', h'] } },
rw [A, f.map_add, B, C, finset.sum_powerset_insert hit, Hrec, Hrec, add_comm],
congr' 1,
apply finset.sum_congr rfl (λs hs, _),
have : (insert i s).piecewise m m' = s.piecewise m m'',
{ ext j,
by_cases h : j = i,
{ rw h, simp [m'', finset.not_mem_of_mem_powerset_of_not_mem hs hit] },
{ by_cases h' : j ∈ s; simp [h, m'', h'] } },
rw this
end
/-- Additivity of a multilinear map along all coordinates at the same time,
writing `f (m + m')` as the sum of `f (s.piecewise m m')` over all sets `s`. -/
lemma map_add_univ [fintype ι] (m m' : Πi, M₁ i) :
f (m + m') = ∑ s : finset ι, f (s.piecewise m m') :=
by simpa using f.map_piecewise_add m m' finset.univ
section apply_sum
variables {α : ι → Type*} [fintype ι] (g : Π i, α i → M₁ i) (A : Π i, finset (α i))
open_locale classical
open fintype finset
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. Here, we give an auxiliary statement tailored for an inductive proof. Use instead
`map_sum_finset`. -/
lemma map_sum_finset_aux {n : ℕ} (h : ∑ i, (A i).card = n) :
f (λ i, ∑ j in A i, g i j) = ∑ r in pi_finset A, f (λ i, g i (r i)) :=
begin
induction n using nat.strong_induction_on with n IH generalizing A,
-- If one of the sets is empty, then all the sums are zero
by_cases Ai_empty : ∃ i, A i = ∅,
{ rcases Ai_empty with ⟨i, hi⟩,
have : ∑ j in A i, g i j = 0, by convert sum_empty,
rw f.map_coord_zero i this,
have : pi_finset A = ∅,
{ apply finset.eq_empty_of_forall_not_mem (λ r hr, _),
have : r i ∈ A i := mem_pi_finset.mp hr i,
rwa hi at this },
convert sum_empty.symm },
push_neg at Ai_empty,
-- Otherwise, if all sets are at most singletons, then they are exactly singletons and the result
-- is again straightforward
by_cases Ai_singleton : ∀ i, (A i).card ≤ 1,
{ have Ai_card : ∀ i, (A i).card = 1,
{ assume i,
have : finset.card (A i) ≠ 0, by simp [finset.card_eq_zero, Ai_empty i],
have : finset.card (A i) ≤ 1 := Ai_singleton i,
omega },
have : ∀ (r : Π i, α i), r ∈ pi_finset A → f (λ i, g i (r i)) = f (λ i, ∑ j in A i, g i j),
{ assume r hr,
unfold_coes,
congr,
ext i,
have : ∀ j ∈ A i, g i j = g i (r i),
{ assume j hj,
congr,
apply finset.card_le_one_iff.1 (Ai_singleton i) hj,
exact mem_pi_finset.mp hr i },
simp only [finset.sum_congr rfl this, finset.mem_univ, finset.sum_const, Ai_card i,
one_nsmul] },
simp only [sum_congr rfl this, Ai_card, card_pi_finset, prod_const_one, one_nsmul,
sum_const] },
-- Remains the interesting case where one of the `A i`, say `A i₀`, has cardinality at least 2.
-- We will split into two parts `B i₀` and `C i₀` of smaller cardinality, let `B i = C i = A i`
-- for `i ≠ i₀`, apply the inductive assumption to `B` and `C`, and add up the corresponding
-- parts to get the sum for `A`.
push_neg at Ai_singleton,
obtain ⟨i₀, hi₀⟩ : ∃ i, 1 < (A i).card := Ai_singleton,
obtain ⟨j₁, j₂, hj₁, hj₂, j₁_ne_j₂⟩ : ∃ j₁ j₂, (j₁ ∈ A i₀) ∧ (j₂ ∈ A i₀) ∧ j₁ ≠ j₂ :=
finset.one_lt_card_iff.1 hi₀,
let B := function.update A i₀ (A i₀ \ {j₂}),
let C := function.update A i₀ {j₂},
have B_subset_A : ∀ i, B i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [B, sdiff_subset, update_same]},
{ simp only [hi, B, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
have C_subset_A : ∀ i, C i ⊆ A i,
{ assume i,
by_cases hi : i = i₀,
{ rw hi, simp only [C, hj₂, finset.singleton_subset_iff, update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff, finset.subset.refl] } },
-- split the sum at `i₀` as the sum over `B i₀` plus the sum over `C i₀`, to use additivity.
have A_eq_BC : (λ i, ∑ j in A i, g i j) =
function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in B i₀, g i₀ j + ∑ j in C i₀, g i₀ j),
{ ext i,
by_cases hi : i = i₀,
{ rw [hi],
simp only [function.update_same],
have : A i₀ = B i₀ ∪ C i₀,
{ simp only [B, C, function.update_same, finset.sdiff_union_self_eq_union],
symmetry,
simp only [hj₂, finset.singleton_subset_iff, union_eq_left_iff_subset] },
rw this,
apply finset.sum_union,
apply finset.disjoint_right.2 (λ j hj, _),
have : j = j₂, by { dsimp [C] at hj, simpa using hj },
rw this,
dsimp [B],
simp only [mem_sdiff, eq_self_iff_true, not_true, not_false_iff, finset.mem_singleton,
update_same, and_false] },
{ simp [hi] } },
have Beq : function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in B i₀, g i₀ j) =
(λ i, ∑ j in B i, g i j),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, B, update_noteq, ne.def, not_false_iff] } },
have Ceq : function.update (λ i, ∑ j in A i, g i j) i₀ (∑ j in C i₀, g i₀ j) =
(λ i, ∑ j in C i, g i j),
{ ext i,
by_cases hi : i = i₀,
{ rw hi, simp only [update_same] },
{ simp only [hi, C, update_noteq, ne.def, not_false_iff] } },
-- Express the inductive assumption for `B`
have Brec : f (λ i, ∑ j in B i, g i j) = ∑ r in pi_finset B, f (λ i, g i (r i)),
{ have : ∑ i, finset.card (B i) < ∑ i, finset.card (A i),
{ refine finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (B_subset_A i))
⟨i₀, finset.mem_univ _, _⟩,
have : {j₂} ⊆ A i₀, by simp [hj₂],
simp only [B, finset.card_sdiff this, function.update_same, finset.card_singleton],
exact nat.pred_lt (ne_of_gt (lt_trans zero_lt_one hi₀)) },
rw h at this,
exact IH _ this B rfl },
-- Express the inductive assumption for `C`
have Crec : f (λ i, ∑ j in C i, g i j) = ∑ r in pi_finset C, f (λ i, g i (r i)),
{ have : ∑ i, finset.card (C i) < ∑ i, finset.card (A i) :=
finset.sum_lt_sum (λ i hi, finset.card_le_of_subset (C_subset_A i))
⟨i₀, finset.mem_univ _, by simp [C, hi₀]⟩,
rw h at this,
exact IH _ this C rfl },
have D : disjoint (pi_finset B) (pi_finset C),
{ have : disjoint (B i₀) (C i₀), by simp [B, C],
exact pi_finset_disjoint_of_disjoint B C this },
have pi_BC : pi_finset A = pi_finset B ∪ pi_finset C,
{ apply finset.subset.antisymm,
{ assume r hr,
by_cases hri₀ : r i₀ = j₂,
{ apply finset.mem_union_right,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ C i₀, by simp [C, hri₀],
convert this },
{ simp [C, hi, mem_pi_finset.1 hr i] } },
{ apply finset.mem_union_left,
apply mem_pi_finset.2 (λ i, _),
by_cases hi : i = i₀,
{ have : r i₀ ∈ B i₀,
by simp [B, hri₀, mem_pi_finset.1 hr i₀],
convert this },
{ simp [B, hi, mem_pi_finset.1 hr i] } } },
{ exact finset.union_subset (pi_finset_subset _ _ (λ i, B_subset_A i))
(pi_finset_subset _ _ (λ i, C_subset_A i)) } },
rw A_eq_BC,
simp only [multilinear_map.map_add, Beq, Ceq, Brec, Crec, pi_BC],
rw ← finset.sum_union D,
end
/-- If `f` is multilinear, then `f (Σ_{j₁ ∈ A₁} g₁ j₁, ..., Σ_{jₙ ∈ Aₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions with `r 1 ∈ A₁`, ...,
`r n ∈ Aₙ`. This follows from multilinearity by expanding successively with respect to each
coordinate. -/
lemma map_sum_finset :
f (λ i, ∑ j in A i, g i j) = ∑ r in pi_finset A, f (λ i, g i (r i)) :=
f.map_sum_finset_aux _ _ rfl
/-- If `f` is multilinear, then `f (Σ_{j₁} g₁ j₁, ..., Σ_{jₙ} gₙ jₙ)` is the sum of
`f (g₁ (r 1), ..., gₙ (r n))` where `r` ranges over all functions `r`. This follows from
multilinearity by expanding successively with respect to each coordinate. -/
lemma map_sum [∀ i, fintype (α i)] :
f (λ i, ∑ j, g i j) = ∑ r : Π i, α i, f (λ i, g i (r i)) :=
f.map_sum_finset g (λ i, finset.univ)
end apply_sum
end semiring
section comm_semiring
variables [comm_semiring R] [∀i, add_comm_monoid (M₁ i)] [∀i, add_comm_monoid (M i)] [add_comm_monoid M₂]
[∀i, semimodule R (M i)] [∀i, semimodule R (M₁ i)] [semimodule R M₂]
(f f' : multilinear_map R M₁ M₂)
/-- If one multiplies by `c i` the coordinates in a finset `s`, then the image under a multilinear
map is multiplied by `∏ i in s, c i`. This is mainly an auxiliary statement to prove the result when
`s = univ`, given in `map_smul_univ`, although it can be useful in its own right as it does not
require the index set `ι` to be finite. -/
lemma map_piecewise_smul (c : ι → R) (m : Πi, M₁ i) (s : finset ι) :
f (s.piecewise (λi, c i • m i) m) = (∏ i in s, c i) • f m :=
begin
refine s.induction_on (by simp) _,
assume j s j_not_mem_s Hrec,
have A : function.update (s.piecewise (λi, c i • m i) m) j (m j) =
s.piecewise (λi, c i • m i) m,
{ ext i,
by_cases h : i = j,
{ rw h, simp [j_not_mem_s] },
{ simp [h] } },
rw [s.piecewise_insert, f.map_smul, A, Hrec],
simp [j_not_mem_s, mul_smul]
end
/-- Multiplicativity of a multilinear map along all coordinates at the same time,
writing `f (λi, c i • m i)` as `(∏ i, c i) • f m`. -/
lemma map_smul_univ [fintype ι] (c : ι → R) (m : Πi, M₁ i) :
f (λi, c i • m i) = (∏ i, c i) • f m :=
by simpa using map_piecewise_smul f c m finset.univ
instance : has_scalar R (multilinear_map R M₁ M₂) := ⟨λ c f,
⟨λ m, c • f m, λm i x y, by simp [smul_add], λl i x d, by simp [smul_smul, mul_comm]⟩⟩
@[simp] lemma smul_apply (c : R) (m : Πi, M₁ i) : (c • f) m = c • f m := rfl
variables (R ι)
/-- The canonical multilinear map on `R^ι` when `ι` is finite, associating to `m` the product of
all the `m i` (multiplied by a fixed reference element `z` in the target module) -/
protected def mk_pi_ring [fintype ι] (z : M₂) : multilinear_map R (λ(i : ι), R) M₂ :=
{ to_fun := λm, (∏ i, m i) • z,
map_add' := λ m i x y, by simp [finset.prod_update_of_mem, add_mul, add_smul],
map_smul' := λ m i c x, by { rw [smul_eq_mul],
simp [finset.prod_update_of_mem, smul_smul, mul_assoc] } }
variables {R ι}
@[simp] lemma mk_pi_ring_apply [fintype ι] (z : M₂) (m : ι → R) :
(multilinear_map.mk_pi_ring R ι z : (ι → R) → M₂) m = (∏ i, m i) • z := rfl
lemma mk_pi_ring_apply_one_eq_self [fintype ι] (f : multilinear_map R (λ(i : ι), R) M₂) :
multilinear_map.mk_pi_ring R ι (f (λi, 1)) = f :=
begin
ext m,
have : m = (λi, m i • 1), by { ext j, simp },
conv_rhs { rw [this, f.map_smul_univ] },
refl
end
end comm_semiring
section ring
variables [ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂]
[∀i, semimodule R (M₁ i)] [semimodule R M₂]
(f : multilinear_map R M₁ M₂)
@[simp] lemma map_sub (m : Πi, M₁ i) (i : ι) (x y : M₁ i) :
f (update m i (x - y)) = f (update m i x) - f (update m i y) :=
by { simp only [map_add, add_left_inj, sub_eq_add_neg, (neg_one_smul R y).symm, map_smul], simp }
instance : has_neg (multilinear_map R M₁ M₂) :=
⟨λ f, ⟨λ m, - f m, λm i x y, by simp [add_comm], λm i c x, by simp⟩⟩
@[simp] lemma neg_apply (m : Πi, M₁ i) : (-f) m = - (f m) := rfl
instance : add_comm_group (multilinear_map R M₁ M₂) :=
by refine {zero := 0, add := (+), neg := has_neg.neg, ..};
intros; ext; simp [add_comm, add_left_comm]
end ring
section comm_ring
variables [comm_ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂]
[∀i, semimodule R (M₁ i)] [semimodule R M₂]
variables (R ι M₁ M₂)
/-- The space of multilinear maps is a module over `R`, for the pointwise addition and scalar
multiplication. -/
instance semimodule : semimodule R (multilinear_map R M₁ M₂) :=
semimodule.of_core $ by refine { smul := (•), ..};
intros; ext; simp [smul_add, add_smul, smul_smul]
-- This instance should not be needed!
instance semimodule_ring : semimodule R (multilinear_map R (λ (i : ι), R) M₂) :=
multilinear_map.semimodule _ _ (λ (i : ι), R) _
/-- When `ι` is finite, multilinear maps on `R^ι` with values in `M₂` are in bijection with `M₂`,
as such a multilinear map is completely determined by its value on the constant vector made of ones.
We register this bijection as a linear equivalence in `multilinear_map.pi_ring_equiv`. -/
protected def pi_ring_equiv [fintype ι] : M₂ ≃ₗ[R] (multilinear_map R (λ(i : ι), R) M₂) :=
{ to_fun := λ z, multilinear_map.mk_pi_ring R ι z,
inv_fun := λ f, f (λi, 1),
map_add' := λ z z', by { ext m, simp [smul_add] },
map_smul' := λ c z, by { ext m, simp [smul_smul, mul_comm] },
left_inv := λ z, by simp,
right_inv := λ f, f.mk_pi_ring_apply_one_eq_self }
end comm_ring
end multilinear_map
namespace linear_map
variables [ring R] [∀i, add_comm_group (M₁ i)] [add_comm_group M₂] [add_comm_group M₃]
[∀i, module R (M₁ i)] [module R M₂] [module R M₃]
/-- Composing a multilinear map with a linear map gives again a multilinear map. -/
def comp_multilinear_map (g : M₂ →ₗ[R] M₃) (f : multilinear_map R M₁ M₂) : multilinear_map R M₁ M₃ :=
{ to_fun := λ m, g (f m),
map_add' := λ m i x y, by simp,
map_smul' := λ m i c x, by simp }
end linear_map
section currying
/-!
### Currying
We associate to a multilinear map in `n+1` variables (i.e., based on `fin n.succ`) two
curried functions, named `f.curry_left` (which is a linear map on `E 0` taking values
in multilinear maps in `n` variables) and `f.curry_right` (wich is a multilinear map in `n`
variables taking values in linear maps on `E 0`). In both constructions, the variable that is
singled out is `0`, to take advantage of the operations `cons` and `tail` on `fin n`.
The inverse operations are called `uncurry_left` and `uncurry_right`.
We also register linear equiv versions of these correspondences, in
`multilinear_curry_left_equiv` and `multilinear_curry_right_equiv`.
-/
open multilinear_map
variables {R M M₂}
[comm_ring R] [∀i, add_comm_group (M i)] [add_comm_group M'] [add_comm_group M₂]
[∀i, module R (M i)] [module R M'] [module R M₂]
/-! #### Left currying -/
/-- Given a linear map `f` from `M 0` to multilinear maps on `n` variables,
construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (m 0) (tail m)`-/
def linear_map.uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (m 0) (tail m),
map_add' := λm i x y, begin
by_cases h : i = 0,
{ revert x y,
rw h,
assume x y,
rw [update_same, update_same, update_same, f.map_add, add_apply,
tail_update_zero, tail_update_zero, tail_update_zero] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x y,
rw ← succ_pred i h,
assume x y,
rw [tail_update_succ, map_add, tail_update_succ, tail_update_succ] }
end,
map_smul' := λm i c x, begin
by_cases h : i = 0,
{ revert x,
rw h,
assume x,
rw [update_same, update_same, tail_update_zero, tail_update_zero,
← smul_apply, f.map_smul] },
{ rw [update_noteq (ne.symm h), update_noteq (ne.symm h)],
revert x,
rw ← succ_pred i h,
assume x,
rw [tail_update_succ, tail_update_succ, map_smul] }
end }
@[simp] lemma linear_map.uncurry_left_apply
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) (m : Πi, M i) :
f.uncurry_left m = f (m 0) (tail m) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the first variable to obtain
a linear map into multilinear maps in `n` variables, given by `x ↦ (m ↦ f (cons x m))`. -/
def multilinear_map.curry_left
(f : multilinear_map R M M₂) :
M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂) :=
{ to_fun := λx,
{ to_fun := λm, f (cons x m),
map_add' := λm i y y', by simp,
map_smul' := λm i y c, by simp },
map_add' := λx y, by { ext m, exact cons_add f m x y },
map_smul' := λc x, by { ext m, exact cons_smul f m c x } }
@[simp] lemma multilinear_map.curry_left_apply
(f : multilinear_map R M M₂) (x : M 0) (m : Π(i : fin n), M i.succ) :
f.curry_left x m = f (cons x m) := rfl
@[simp] lemma linear_map.curry_uncurry_left
(f : M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) :
f.uncurry_left.curry_left = f :=
begin
ext m x,
simp only [tail_cons, linear_map.uncurry_left_apply, multilinear_map.curry_left_apply],
rw cons_zero
end
@[simp] lemma multilinear_map.uncurry_curry_left
(f : multilinear_map R M M₂) :
f.curry_left.uncurry_left = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from `M 0` to the space of multilinear maps on
`Π(i : fin n), M i.succ `, by separating the first variable. We register this isomorphism as a
linear isomorphism in `multilinear_curry_left_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_left` and `f.curry_left`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_left_equiv :
(M 0 →ₗ[R] (multilinear_map R (λ(i : fin n), M i.succ) M₂)) ≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := linear_map.uncurry_left,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, refl },
inv_fun := multilinear_map.curry_left,
left_inv := linear_map.curry_uncurry_left,
right_inv := multilinear_map.uncurry_curry_left }
variables {R M M₂}
/-! #### Right currying -/
/-- Given a multilinear map `f` in `n` variables to the space of linear maps from `M (last n)` to
`M₂`, construct the corresponding multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m ↦ f (init m) (m (last n))`-/
def multilinear_map.uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) (M (last n) →ₗ[R] M₂))) :
multilinear_map R M M₂ :=
{ to_fun := λm, f (init m) (m (last n)),
map_add' := λm i x y, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this, update_noteq this],
revert x y,
rw [(cast_succ_cast_lt i h).symm],
assume x y,
rw [init_update_cast_succ, map_add, init_update_cast_succ, init_update_cast_succ,
linear_map.add_apply] },
{ revert x y,
rw eq_last_of_not_lt h,
assume x y,
rw [init_update_last, init_update_last, init_update_last,
update_same, update_same, update_same, linear_map.map_add] }
end,
map_smul' := λm i c x, begin
by_cases h : i.val < n,
{ have : last n ≠ i := ne.symm (ne_of_lt h),
rw [update_noteq this, update_noteq this],
revert x,
rw [(cast_succ_cast_lt i h).symm],
assume x,
rw [init_update_cast_succ, init_update_cast_succ, map_smul, linear_map.smul_apply] },
{ revert x,
rw eq_last_of_not_lt h,
assume x,
rw [update_same, update_same, init_update_last, init_update_last,
linear_map.map_smul] }
end }
@[simp] lemma multilinear_map.uncurry_right_apply
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) (m : Πi, M i) :
f.uncurry_right m = f (init m) (m (last n)) := rfl
/-- Given a multilinear map `f` in `n+1` variables, split the last variable to obtain
a multilinear map in `n` variables taking values in linear maps from `M (last n)` to `M₂`, given by
`m ↦ (x ↦ f (snoc m x))`. -/
def multilinear_map.curry_right (f : multilinear_map R M M₂) :
multilinear_map R (λ(i : fin n), M (fin.cast_succ i)) ((M (last n)) →ₗ[R] M₂) :=
{ to_fun := λm,
{ to_fun := λx, f (snoc m x),
map_add' := λx y, by rw f.snoc_add,
map_smul' := λc x, by rw f.snoc_smul },
map_add' := λm i x y, begin
ext z,
change f (snoc (update m i (x + y)) z)
= f (snoc (update m i x) z) + f (snoc (update m i y) z),
rw [snoc_update, snoc_update, snoc_update, f.map_add]
end,
map_smul' := λm i c x, begin
ext z,
change f (snoc (update m i (c • x)) z) = c • f (snoc (update m i x) z),
rw [snoc_update, snoc_update, f.map_smul]
end }
@[simp] lemma multilinear_map.curry_right_apply
(f : multilinear_map R M M₂) (m : Π(i : fin n), M i.cast_succ) (x : M (last n)) :
f.curry_right m x = f (snoc m x) := rfl
@[simp] lemma multilinear_map.curry_uncurry_right
(f : (multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))) :
f.uncurry_right.curry_right = f :=
begin
ext m x,
simp only [snoc_last, multilinear_map.curry_right_apply, multilinear_map.uncurry_right_apply],
rw init_snoc
end
@[simp] lemma multilinear_map.uncurry_curry_right
(f : multilinear_map R M M₂) : f.curry_right.uncurry_right = f :=
by { ext m, simp }
variables (R M M₂)
/-- The space of multilinear maps on `Π(i : fin (n+1)), M i` is canonically isomorphic to
the space of linear maps from the space of multilinear maps on `Π(i : fin n), M i.cast_succ` to the
space of linear maps on `M (last n)`, by separating the last variable. We register this isomorphism
as a linear isomorphism in `multilinear_curry_right_equiv R M M₂`.
The direct and inverse maps are given by `f.uncurry_right` and `f.curry_right`. Use these
unless you need the full framework of linear equivs. -/
def multilinear_curry_right_equiv :
(multilinear_map R (λ(i : fin n), M i.cast_succ) ((M (last n)) →ₗ[R] M₂))
≃ₗ[R] (multilinear_map R M M₂) :=
{ to_fun := multilinear_map.uncurry_right,
map_add' := λf₁ f₂, by { ext m, refl },
map_smul' := λc f, by { ext m, rw [smul_apply], refl },
inv_fun := multilinear_map.curry_right,
left_inv := multilinear_map.curry_uncurry_right,
right_inv := multilinear_map.uncurry_curry_right }
end currying
|
c23b1a88e4c78575f1fab88dd7ffb2996a7945ad | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Compiler/LCNF/ConfigOptions.lean | c478c03e78036f2e9bfca92e8531e16d605a3e88 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 2,395 | lean | /-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Data.Options
namespace Lean.Compiler.LCNF
/--
User controlled configuration options for the code generator.
-/
structure ConfigOptions where
/--
Any function declaration or join point with size `≤ smallThresold` is inlined
even if there are multiple occurrences.
-/
smallThreshold : Nat := 1
/--
Maximum number of times a recursive definition tagged with `[inline]` can be recursively inlined before generating an
error during compilation.
-/
maxRecInline : Nat := 1
/--
Maximum number of times a recursive definition tagged with `[inline_if_reduce]` can be recursively inlined
before generating an error during compilation.
-/
maxRecInlineIfReduce : Nat := 16
/--
Perform type compatibility checking after each compiler pass.
-/
checkTypes : Bool := false
deriving Inhabited
register_builtin_option compiler.small : Nat := {
defValue := 1
group := "compiler"
descr := "(compiler) function declarations with size `≤ small` is inlined even if there are multiple occurrences."
}
register_builtin_option compiler.maxRecInline : Nat := {
defValue := 1
group := "compiler"
descr := "(compiler) maximum number of times a recursive definition tagged with `[inline]` can be recursively inlined before generating an error during compilation."
}
register_builtin_option compiler.maxRecInlineIfReduce : Nat := {
defValue := 16
group := "compiler"
descr := "(compiler) maximum number of times a recursive definition tagged with `[inline_if_reduce]` can be recursively inlined before generating an error during compilation."
}
register_builtin_option compiler.checkTypes : Bool := {
defValue := false
group := "compiler"
descr := "(compiler) perform type compatibility checking after each compiler pass. Note this is not a complete check, and it is used only for debugging purposes. It fails in code that makes heavy use of dependent types."
}
def toConfigOptions (opts : Options) : ConfigOptions := {
smallThreshold := compiler.small.get opts
maxRecInline := compiler.maxRecInline.get opts
maxRecInlineIfReduce := compiler.maxRecInlineIfReduce.get opts
checkTypes := compiler.checkTypes.get opts
}
end Lean.Compiler.LCNF
|
08aa64f226fce16c3a8829d80ede3d24b0b4a4b2 | 69d4931b605e11ca61881fc4f66db50a0a875e39 | /src/order/liminf_limsup.lean | f2475a1418838afa3469ed9d741ea0b53a168514 | [
"Apache-2.0"
] | permissive | abentkamp/mathlib | d9a75d291ec09f4637b0f30cc3880ffb07549ee5 | 5360e476391508e092b5a1e5210bd0ed22dc0755 | refs/heads/master | 1,682,382,954,948 | 1,622,106,077,000 | 1,622,106,077,000 | 149,285,665 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,266 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import order.filter.partial
import order.filter.at_top_bot
/-!
# liminfs and limsups of functions and filters
Defines the Liminf/Limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `f.Limsup` (`f.Liminf`) where `f` is a filter taking values in a conditionally complete
lattice. `f.Limsup` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`f.Liminf`). To work with the Limsup along a function `u` use `(f.map u).Limsup`.
Usually, one defines the Limsup as `Inf (Sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `Inf_n (Sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `Limsup (λx, 1/x)` on ℝ. Then
there is no guarantee that the quantity above really decreases (the value of the `Sup` beforehand is
not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not
use this `Inf Sup ...` definition in conditionally complete lattices, and one has to use a less
tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open filter set
open_locale filter
variables {α β ι : Type*}
namespace filter
section relation
/-- `f.is_bounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def is_bounded (r : α → α → Prop) (f : filter α) := ∃ b, ∀ᶠ x in f, r x b
/-- `f.is_bounded_under (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def is_bounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_bounded r
variables {r : α → α → Prop} {f g : filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
lemma is_bounded_iff : f.is_bounded r ↔ (∃s∈f.sets, ∃b, s ⊆ {x | r x b}) :=
iff.intro
(assume ⟨b, hb⟩, ⟨{a | r a b}, hb, b, subset.refl _⟩)
(assume ⟨s, hs, b, hb⟩, ⟨b, mem_sets_of_superset hs hb⟩)
/-- A bounded function `u` is in particular eventually bounded. -/
lemma is_bounded_under_of {f : filter β} {u : β → α} :
(∃b, ∀x, r (u x) b) → f.is_bounded_under r u
| ⟨b, hb⟩ := ⟨b, show ∀ᶠ x in f, r (u x) b, from eventually_of_forall hb⟩
lemma is_bounded_bot : is_bounded r ⊥ ↔ nonempty α :=
by simp [is_bounded, exists_true_iff_nonempty]
lemma is_bounded_top : is_bounded r ⊤ ↔ (∃t, ∀x, r x t) :=
by simp [is_bounded, eq_univ_iff_forall]
lemma is_bounded_principal (s : set α) : is_bounded r (𝓟 s) ↔ (∃t, ∀x∈s, r x t) :=
by simp [is_bounded, subset_def]
lemma is_bounded_sup [is_trans α r] (hr : ∀b₁ b₂, ∃b, r b₁ b ∧ r b₂ b) :
is_bounded r f → is_bounded r g → is_bounded r (f ⊔ g)
| ⟨b₁, h₁⟩ ⟨b₂, h₂⟩ := let ⟨b, rb₁b, rb₂b⟩ := hr b₁ b₂ in
⟨b, eventually_sup.mpr ⟨h₁.mono (λ x h, trans h rb₁b), h₂.mono (λ x h, trans h rb₂b)⟩⟩
lemma is_bounded.mono (h : f ≤ g) : is_bounded r g → is_bounded r f
| ⟨b, hb⟩ := ⟨b, h hb⟩
lemma is_bounded_under.mono {f g : filter β} {u : β → α} (h : f ≤ g) :
g.is_bounded_under r u → f.is_bounded_under r u :=
λ hg, hg.mono (map_mono h)
lemma is_bounded.is_bounded_under {q : β → β → Prop} {u : α → β}
(hf : ∀a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.is_bounded r → f.is_bounded_under q u
| ⟨b, h⟩ := ⟨u b, show ∀ᶠ x in f, q (u x) (u b), from h.mono (λ x, hf x b)⟩
lemma not_is_bounded_under_of_tendsto_at_top [nonempty α] [semilattice_sup α]
[preorder β] [no_top_order β] {f : α → β} (hf : tendsto f at_top at_top) :
¬ is_bounded_under (≤) at_top f :=
begin
rintro ⟨b, hb⟩,
rw eventually_map at hb,
obtain ⟨b', h⟩ := no_top b,
have hb' := (tendsto_at_top.mp hf) b',
have : {x : α | f x ≤ b} ∩ {x : α | b' ≤ f x} = ∅ :=
eq_empty_of_subset_empty (λ x hx, (not_le_of_lt h) (le_trans hx.2 hx.1)),
exact at_top.empty_nmem_sets (this ▸ filter.inter_mem_sets hb hb' : ∅ ∈ (at_top : filter α)),
end
lemma not_is_bounded_under_of_tendsto_at_bot [nonempty α] [semilattice_sup α]
[preorder β] [no_bot_order β] {f : α → β} (hf : tendsto f at_top at_bot) :
¬ is_bounded_under (≥) at_top f :=
begin
rintro ⟨b, hb⟩,
rw eventually_map at hb,
obtain ⟨b', h⟩ := no_bot b,
have hb' := (tendsto_at_bot.mp hf) b',
have : {x : α | b ≤ f x} ∩ {x : α | f x ≤ b'} = ∅ :=
eq_empty_of_subset_empty (λ x hx, (not_le_of_lt h) (le_trans hx.1 hx.2)),
exact at_top.empty_nmem_sets (this ▸ filter.inter_mem_sets hb hb' : ∅ ∈ (at_top : filter α)),
end
/-- `is_cobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.is_cobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def is_cobounded (r : α → α → Prop) (f : filter α) := ∃b, ∀a, (∀ᶠ x in f, r x a) → r b a
/-- `is_cobounded_under (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def is_cobounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_cobounded r
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter.-/
lemma is_cobounded.mk [is_trans α r] (a : α) (h : ∀s∈f, ∃x∈s, r a x) : f.is_cobounded r :=
⟨a, assume y s, let ⟨x, h₁, h₂⟩ := h _ s in trans h₂ h₁⟩
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
lemma is_bounded.is_cobounded_flip [is_trans α r] [ne_bot f] :
f.is_bounded r → f.is_cobounded (flip r)
| ⟨a, ha⟩ := ⟨a, assume b hb,
let ⟨x, rxa, rbx⟩ := (ha.and hb).exists in
show r b a, from trans rbx rxa⟩
lemma is_cobounded_bot : is_cobounded r ⊥ ↔ (∃b, ∀x, r b x) :=
by simp [is_cobounded]
lemma is_cobounded_top : is_cobounded r ⊤ ↔ nonempty α :=
by simp [is_cobounded, eq_univ_iff_forall, exists_true_iff_nonempty] {contextual := tt}
lemma is_cobounded_principal (s : set α) :
(𝓟 s).is_cobounded r ↔ (∃b, ∀a, (∀x∈s, r x a) → r b a) :=
by simp [is_cobounded, subset_def]
lemma is_cobounded.mono (h : f ≤ g) : f.is_cobounded r → g.is_cobounded r
| ⟨b, hb⟩ := ⟨b, assume a ha, hb a (h ha)⟩
end relation
lemma is_cobounded_le_of_bot [order_bot α] {f : filter α} : f.is_cobounded (≤) :=
⟨⊥, assume a h, bot_le⟩
lemma is_cobounded_ge_of_top [order_top α] {f : filter α} : f.is_cobounded (≥) :=
⟨⊤, assume a h, le_top⟩
lemma is_bounded_le_of_top [order_top α] {f : filter α} : f.is_bounded (≤) :=
⟨⊤, eventually_of_forall $ λ _, le_top⟩
lemma is_bounded_ge_of_bot [order_bot α] {f : filter α} : f.is_bounded (≥) :=
⟨⊥, eventually_of_forall $ λ _, bot_le⟩
lemma is_bounded_under_sup [semilattice_sup α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≤) u → f.is_bounded_under (≤) v → f.is_bounded_under (≤) (λa, u a ⊔ v a)
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩ ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ :=
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv,
by filter_upwards [hu, hv] assume x, sup_le_sup⟩
lemma is_bounded_under_inf [semilattice_inf α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≥) u → f.is_bounded_under (≥) v → f.is_bounded_under (≥) (λa, u a ⊓ v a)
| ⟨bu, (hu : ∀ᶠ x in f, u x ≥ bu)⟩ ⟨bv, (hv : ∀ᶠ x in f, v x ≥ bv)⟩ :=
⟨bu ⊓ bv, show ∀ᶠ x in f, u x ⊓ v x ≥ bu ⊓ bv,
by filter_upwards [hu, hv] assume x, inf_le_inf⟩
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `is_bounded_default` in the statements,
in the form `(hf : f.is_bounded (≥) . is_bounded_default)`. -/
meta def is_bounded_default : tactic unit :=
tactic.applyc ``is_cobounded_le_of_bot <|>
tactic.applyc ``is_cobounded_ge_of_top <|>
tactic.applyc ``is_bounded_le_of_top <|>
tactic.applyc ``is_bounded_ge_of_bot
section conditionally_complete_lattice
variables [conditionally_complete_lattice α]
/-- The `Limsup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def Limsup (f : filter α) : α := Inf { a | ∀ᶠ n in f, n ≤ a }
/-- The `Liminf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def Liminf (f : filter α) : α := Sup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (f : filter β) (u : β → α) : α := (f.map u).Limsup
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (f : filter β) (u : β → α) : α := (f.map u).Liminf
section
variables {f : filter β} {u : β → α}
theorem limsup_eq : f.limsup u = Inf { a | ∀ᶠ n in f, u n ≤ a } := rfl
theorem liminf_eq : f.liminf u = Sup { a | ∀ᶠ n in f, a ≤ u n } := rfl
end
theorem Limsup_le_of_le {f : filter α} {a}
(hf : f.is_cobounded (≤) . is_bounded_default) (h : ∀ᶠ n in f, n ≤ a) : f.Limsup ≤ a :=
cInf_le hf h
theorem le_Liminf_of_le {f : filter α} {a}
(hf : f.is_cobounded (≥) . is_bounded_default) (h : ∀ᶠ n in f, a ≤ n) : a ≤ f.Liminf :=
le_cSup hf h
theorem le_Limsup_of_le {f : filter α} {a}
(hf : f.is_bounded (≤) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) :
a ≤ f.Limsup :=
le_cInf hf h
theorem Liminf_le_of_le {f : filter α} {a}
(hf : f.is_bounded (≥) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) :
f.Liminf ≤ a :=
cSup_le hf h
theorem Liminf_le_Limsup {f : filter α} [ne_bot f]
(h₁ : f.is_bounded (≤) . is_bounded_default) (h₂ : f.is_bounded (≥) . is_bounded_default) :
f.Liminf ≤ f.Limsup :=
Liminf_le_of_le h₂ $ assume a₀ ha₀, le_Limsup_of_le h₁ $ assume a₁ ha₁,
show a₀ ≤ a₁, from let ⟨b, hb₀, hb₁⟩ := (ha₀.and ha₁).exists in le_trans hb₀ hb₁
lemma Liminf_le_Liminf {f g : filter α}
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : f.Liminf ≤ g.Liminf :=
cSup_le_cSup hg hf h
lemma Limsup_le_Limsup {f g : filter α}
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : f.Limsup ≤ g.Limsup :=
cInf_le_cInf hf hg h
lemma Limsup_le_Limsup_of_le {f g : filter α} (h : f ≤ g)
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default) :
f.Limsup ≤ g.Limsup :=
Limsup_le_Limsup hf hg (assume a ha, h ha)
lemma Liminf_le_Liminf_of_le {f g : filter α} (h : g ≤ f)
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default) :
f.Liminf ≤ g.Liminf :=
Liminf_le_Liminf hf hg (assume a ha, h ha)
lemma limsup_le_limsup {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.is_cobounded_under (≤) u . is_bounded_default)
(hv : f.is_bounded_under (≤) v . is_bounded_default) :
f.limsup u ≤ f.limsup v :=
Limsup_le_Limsup hu hv $ assume b, h.trans
lemma liminf_le_liminf {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hv : f.is_cobounded_under (≥) v . is_bounded_default) :
f.liminf u ≤ f.liminf v :=
@limsup_le_limsup (order_dual β) α _ _ _ _ h hv hu
theorem Limsup_principal {s : set α} (h : bdd_above s) (hs : s.nonempty) :
(𝓟 s).Limsup = Sup s :=
by simp [Limsup]; exact cInf_upper_bounds_eq_cSup h hs
theorem Liminf_principal {s : set α} (h : bdd_below s) (hs : s.nonempty) :
(𝓟 s).Liminf = Inf s :=
@Limsup_principal (order_dual α) _ s h hs
lemma limsup_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup f u = limsup f v :=
begin
rw limsup_eq,
congr' with b,
exact eventually_congr (h.mono $ λ x hx, by simp [hx])
end
lemma liminf_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf f u = liminf f v :=
@limsup_congr (order_dual β) _ _ _ _ _ h
lemma limsup_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} [ne_bot f]
(b : β) : limsup f (λ x, b) = b :=
by simpa only [limsup_eq, eventually_const] using cInf_Ici
lemma liminf_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} [ne_bot f]
(b : β) : liminf f (λ x, b) = b :=
@limsup_const (order_dual β) α _ f _ b
end conditionally_complete_lattice
section complete_lattice
variables [complete_lattice α]
@[simp] theorem Limsup_bot : (⊥ : filter α).Limsup = ⊥ :=
bot_unique $ Inf_le $ by simp
@[simp] theorem Liminf_bot : (⊥ : filter α).Liminf = ⊤ :=
top_unique $ le_Sup $ by simp
@[simp] theorem Limsup_top : (⊤ : filter α).Limsup = ⊤ :=
top_unique $ le_Inf $
by simp [eq_univ_iff_forall]; exact assume b hb, (top_unique $ hb _)
@[simp] theorem Liminf_top : (⊤ : filter α).Liminf = ⊥ :=
bot_unique $ Sup_le $
by simp [eq_univ_iff_forall]; exact assume b hb, (bot_unique $ hb _)
/-- Same as limsup_const applied to `⊥` but without the `ne_bot f` assumption -/
lemma limsup_const_bot {f : filter β} : limsup f (λ x : β, (⊥ : α)) = (⊥ : α) :=
begin
rw [limsup_eq, eq_bot_iff],
exact Inf_le (eventually_of_forall (λ x, le_refl _)),
end
/-- Same as limsup_const applied to `⊤` but without the `ne_bot f` assumption -/
lemma liminf_const_top {f : filter β} : liminf f (λ x : β, (⊤ : α)) = (⊤ : α) :=
@limsup_const_bot (order_dual α) β _ _
lemma liminf_le_limsup {f : filter β} [ne_bot f] {u : β → α} : liminf f u ≤ limsup f u :=
Liminf_le_Limsup is_bounded_le_of_top is_bounded_ge_of_bot
theorem has_basis.Limsup_eq_infi_Sup {ι} {p : ι → Prop} {s} {f : filter α} (h : f.has_basis p s) :
f.Limsup = ⨅ i (hi : p i), Sup (s i) :=
le_antisymm
(le_binfi $ λ i hi, Inf_le $ h.eventually_iff.2 ⟨i, hi, λ x, le_Sup⟩)
(le_Inf $ assume a ha, let ⟨i, hi, ha⟩ := h.eventually_iff.1 ha in
infi_le_of_le _ $ infi_le_of_le hi $ Sup_le ha)
theorem has_basis.Liminf_eq_supr_Inf {p : ι → Prop} {s : ι → set α} {f : filter α}
(h : f.has_basis p s) : f.Liminf = ⨆ i (hi : p i), Inf (s i) :=
@has_basis.Limsup_eq_infi_Sup (order_dual α) _ _ _ _ _ h
theorem Limsup_eq_infi_Sup {f : filter α} : f.Limsup = ⨅ s ∈ f, Sup s :=
f.basis_sets.Limsup_eq_infi_Sup
theorem Liminf_eq_supr_Inf {f : filter α} : f.Liminf = ⨆ s ∈ f, Inf s :=
@Limsup_eq_infi_Sup (order_dual α) _ _
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_infi_supr {f : filter β} {u : β → α} : f.limsup u = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).Limsup_eq_infi_Sup.trans $
by simp only [Sup_image, id]
lemma limsup_eq_infi_supr_of_nat {u : ℕ → α} : limsup at_top u = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(at_top_basis.map u).Limsup_eq_infi_Sup.trans $
by simp only [Sup_image, infi_const]; refl
lemma limsup_eq_infi_supr_of_nat' {u : ℕ → α} : limsup at_top u = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) :=
by simp only [limsup_eq_infi_supr_of_nat, supr_ge_eq_supr_nat_add]
theorem has_basis.limsup_eq_infi_supr {p : ι → Prop} {s : ι → set β} {f : filter β} {u : β → α}
(h : f.has_basis p s) : f.limsup u = ⨅ i (hi : p i), ⨆ a ∈ s i, u a :=
(h.map u).Limsup_eq_infi_Sup.trans $ by simp only [Sup_image, id]
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_supr_infi {f : filter β} {u : β → α} : f.liminf u = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
@limsup_eq_infi_supr (order_dual α) β _ _ _
lemma liminf_eq_supr_infi_of_nat {u : ℕ → α} : liminf at_top u = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_infi_supr_of_nat (order_dual α) _ u
lemma liminf_eq_supr_infi_of_nat' {u : ℕ → α} : liminf at_top u = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_infi_supr_of_nat' (order_dual α) _ _
theorem has_basis.liminf_eq_supr_infi {p : ι → Prop} {s : ι → set β} {f : filter β} {u : β → α}
(h : f.has_basis p s) : f.liminf u = ⨆ i (hi : p i), ⨅ a ∈ s i, u a :=
@has_basis.limsup_eq_infi_supr (order_dual α) _ _ _ _ _ _ _ h
@[simp] lemma liminf_nat_add (f : ℕ → α) (k : ℕ) :
at_top.liminf (λ i, f (i + k)) = at_top.liminf f :=
by { simp_rw liminf_eq_supr_infi_of_nat, exact supr_infi_ge_nat_add f k }
@[simp] lemma limsup_nat_add (f : ℕ → α) (k : ℕ) :
at_top.limsup (λ i, f (i + k)) = at_top.limsup f :=
@liminf_nat_add (order_dual α) _ f k
lemma liminf_le_of_frequently_le' {α β} [complete_lattice β]
{f : filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) :
f.liminf u ≤ x :=
begin
rw liminf_eq,
refine Sup_le (λ b hb, _),
have hbx : ∃ᶠ a in f, b ≤ x,
{ revert h,
rw [←not_imp_not, not_frequently, not_frequently],
exact λ h, hb.mp (h.mono (λ a hbx hba hax, hbx (hba.trans hax))), },
exact hbx.exists.some_spec,
end
lemma le_limsup_of_frequently_le' {α β} [complete_lattice β]
{f : filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) :
x ≤ f.limsup u :=
@liminf_le_of_frequently_le' _ (order_dual β) _ _ _ _ h
end complete_lattice
section conditionally_complete_linear_order
lemma eventually_lt_of_lt_liminf {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : b < liminf f u) (hu : f.is_bounded_under (≥) u . is_bounded_default) :
∀ᶠ a in f, b < u a :=
begin
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (hc : c ∈ {c : β | ∀ᶠ (n : α) in f, c ≤ u n}), b < c :=
exists_lt_of_lt_cSup hu h,
exact hc.mono (λ x hx, lt_of_lt_of_le hbc hx)
end
lemma eventually_lt_of_limsup_lt {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : limsup f u < b) (hu : f.is_bounded_under (≤) u . is_bounded_default) :
∀ᶠ a in f, u a < b :=
@eventually_lt_of_lt_liminf _ (order_dual β) _ _ _ _ h hu
lemma le_limsup_of_frequently_le {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x)
(hu : f.is_bounded_under (≤) u . is_bounded_default) :
b ≤ f.limsup u :=
begin
revert hu_le,
rw [←not_imp_not, not_frequently],
simp_rw ←lt_iff_not_ge,
exact λ h, eventually_lt_of_limsup_lt h hu,
end
lemma liminf_le_of_frequently_le {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b)
(hu : f.is_bounded_under (≥) u . is_bounded_default) :
f.liminf u ≤ b :=
@le_limsup_of_frequently_le _ (order_dual β) _ f u b hu_le hu
end conditionally_complete_linear_order
end filter
section order
open filter
lemma galois_connection.l_limsup_le {α β γ} [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {v : α → β}
{l : β → γ} {u : γ → β} (gc : galois_connection l u)
(hlv : f.is_bounded_under (≤) (λ x, l (v x)) . is_bounded_default)
(hv_co : f.is_cobounded_under (≤) v . is_bounded_default) :
l (f.limsup v) ≤ f.limsup (λ x, l (v x)) :=
begin
refine le_Limsup_of_le hlv (λ c hc, _),
rw filter.eventually_map at hc,
simp_rw (gc _ _) at hc ⊢,
exact Limsup_le_of_le hv_co hc,
end
lemma order_iso.limsup_apply {γ} [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {u : α → β} (g : β ≃o γ)
(hu : f.is_bounded_under (≤) u . is_bounded_default)
(hu_co : f.is_cobounded_under (≤) u . is_bounded_default)
(hgu : f.is_bounded_under (≤) (λ x, g (u x)) . is_bounded_default)
(hgu_co : f.is_cobounded_under (≤) (λ x, g (u x)) . is_bounded_default) :
g (f.limsup u) = f.limsup (λ x, g (u x)) :=
begin
refine le_antisymm (g.to_galois_connection.l_limsup_le hgu hu_co) _,
rw [←(g.symm.symm_apply_apply (f.limsup (λ (x : α), g (u x)))), g.symm_symm],
refine g.monotone _,
have hf : u = λ i, g.symm (g (u i)), from funext (λ i, (g.symm_apply_apply (u i)).symm),
nth_rewrite 0 hf,
refine g.symm.to_galois_connection.l_limsup_le _ hgu_co,
simp_rw g.symm_apply_apply,
exact hu,
end
lemma order_iso.liminf_apply {γ} [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {u : α → β} (g : β ≃o γ)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hu_co : f.is_cobounded_under (≥) u . is_bounded_default)
(hgu : f.is_bounded_under (≥) (λ x, g (u x)) . is_bounded_default)
(hgu_co : f.is_cobounded_under (≥) (λ x, g (u x)) . is_bounded_default) :
g (f.liminf u) = f.liminf (λ x, g (u x)) :=
@order_iso.limsup_apply α (order_dual β) (order_dual γ) _ _ f u g.dual hu hu_co hgu hgu_co
end order
|
acb3a10638c712cac90727337febad131f3db1c2 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/extend_from_subset.lean | 3e024360c584ddf17c9670b9595559e830608dc0 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,370 | lean | /-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Anatole Dedecker
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.separation
import Mathlib.PostPort
universes u_2 u_1
namespace Mathlib
/-!
# Extending a function from a subset
The main definition of this file is `extend_from A f` where `f : X → Y`
and `A : set X`. This defines a new function `g : X → Y` which maps any
`x₀ : X` to the limit of `f` as `x` tends to `x₀`, if such a limit exists.
This is analoguous to the way `dense_inducing.extend` "extends" a function
`f : X → Z` to a function `g : Y → Z` along a dense inducing `i : X → Y`.
The main theorem we prove about this definition is `continuous_on_extend_from`
which states that, for `extend_from A f` to be continuous on a set `B ⊆ closure A`,
it suffices that `f` converges within `A` at any point of `B`, provided that
`f` is a function to a regular space.
-/
/-- Extend a function from a set `A`. The resulting function `g` is such that
at any `x₀`, if `f` converges to some `y` as `x` tends to `x₀` within `A`,
then `g x₀` is defined to be one of these `y`. Else, `g x₀` could be anything. -/
def extend_from {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] (A : set X) (f : X → Y) : X → Y :=
fun (x : X) => lim (nhds_within x A) f
/-- If `f` converges to some `y` as `x` tends to `x₀` within `A`,
then `f` tends to `extend_from A f x` as `x` tends to `x₀`. -/
theorem tendsto_extend_from {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] {A : set X} {f : X → Y} {x : X} (h : ∃ (y : Y), filter.tendsto f (nhds_within x A) (nhds y)) : filter.tendsto f (nhds_within x A) (nhds (extend_from A f x)) :=
tendsto_nhds_lim h
theorem extend_from_eq {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] [t2_space Y] {A : set X} {f : X → Y} {x : X} {y : Y} (hx : x ∈ closure A) (hf : filter.tendsto f (nhds_within x A) (nhds y)) : extend_from A f x = y :=
tendsto_nhds_unique (tendsto_nhds_lim (Exists.intro y hf)) hf
theorem extend_from_extends {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] [t2_space Y] {f : X → Y} {A : set X} (hf : continuous_on f A) (x : X) (H : x ∈ A) : extend_from A f x = f x :=
extend_from_eq (subset_closure x_in) (hf x x_in)
/-- If `f` is a function to a regular space `Y` which has a limit within `A` at any
point of a set `B ⊆ closure A`, then `extend_from A f` is continuous on `B`. -/
theorem continuous_on_extend_from {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] [regular_space Y] {f : X → Y} {A : set X} {B : set X} (hB : B ⊆ closure A) (hf : ∀ (x : X), x ∈ B → ∃ (y : Y), filter.tendsto f (nhds_within x A) (nhds y)) : continuous_on (extend_from A f) B := sorry
/-- If a function `f` to a regular space `Y` has a limit within a
dense set `A` for any `x`, then `extend_from A f` is continuous. -/
theorem continuous_extend_from {X : Type u_1} {Y : Type u_2} [topological_space X] [topological_space Y] [regular_space Y] {f : X → Y} {A : set X} (hA : dense A) (hf : ∀ (x : X), ∃ (y : Y), filter.tendsto f (nhds_within x A) (nhds y)) : continuous (extend_from A f) := sorry
|
e0e9e75621f6af37a9e69c8c64fb96c3db23503e | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/representation_theory/group_cohomology_resolution.lean | 0c953185cae1c4e5df693bf8c8acd9a3efa34bec | [
"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,229 | lean | /-
Copyright (c) 2022 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import representation_theory.Rep
import representation_theory.basic
/-!
# The structure of the `k[G]`-module `k[Gⁿ]`
This file contains facts about an important `k[G]`-module structure on `k[Gⁿ]`, where `k` is a
commutative ring and `G` is a group. The module structure arises from the representation
`G →* End(k[Gⁿ])` induced by the diagonal action of `G` on `Gⁿ.`
In particular, we define an isomorphism of `k`-linear `G`-representations between `k[Gⁿ⁺¹]` and
`k[G] ⊗ₖ k[Gⁿ]` (on which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`).
This allows us to define a `k[G]`-basis on `k[Gⁿ⁺¹]`, by mapping the natural `k[G]`-basis of
`k[G] ⊗ₖ k[Gⁿ]` along the isomorphism.
## Main definitions
* `group_cohomology.resolution.to_tensor`
* `group_cohomology.resolution.of_tensor`
* `Rep.of_mul_action`
* `group_cohomology.resolution.equiv_tensor`
* `group_cohomology.resolution.of_mul_action_basis`
## TODO
* Use the freeness of `k[Gⁿ⁺¹]` to build a projective resolution of the (trivial) `k[G]`-module
`k`, and so develop group cohomology.
## Implementation notes
We express `k[G]`-module structures on a module `k`-module `V` using the `representation`
definition. We avoid using instances `module (G →₀ k) V` so that we do not run into possible
scalar action diamonds.
We also use the category theory library to bundle the type `k[Gⁿ]` - or more generally `k[H]` when
`H` has `G`-action - and the representation together, as a term of type `Rep k G`, and call it
`Rep.of_mul_action k G H.` This enables us to express the fact that certain maps are
`G`-equivariant by constructing morphisms in the category `Rep k G`, i.e., representations of `G`
over `k`.
-/
noncomputable theory
universes u
variables {k G : Type u} [comm_ring k] {n : ℕ}
open_locale tensor_product
local notation `Gⁿ` := fin n → G
local notation `Gⁿ⁺¹` := fin (n + 1) → G
namespace group_cohomology.resolution
open finsupp (hiding lift) fin (partial_prod) representation
variables (k G n) [group G]
/-- The `k`-linear map from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` sending `(g₀, ..., gₙ)`
to `g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. -/
def to_tensor_aux :
((fin (n + 1) → G) →₀ k) →ₗ[k] (G →₀ k) ⊗[k] ((fin n → G) →₀ k) :=
finsupp.lift ((G →₀ k) ⊗[k] ((fin n → G) →₀ k)) k (fin (n + 1) → G)
(λ x, single (x 0) 1 ⊗ₜ[k] single (λ i, (x i)⁻¹ * x i.succ) 1)
/-- The `k`-linear map from `k[G] ⊗ₖ k[Gⁿ]` to `k[Gⁿ⁺¹]` sending `g ⊗ (g₁, ..., gₙ)` to
`(g, gg₁, gg₁g₂, ..., gg₁...gₙ)`. -/
def of_tensor_aux :
(G →₀ k) ⊗[k] ((fin n → G) →₀ k) →ₗ[k] ((fin (n + 1) → G) →₀ k) :=
tensor_product.lift (finsupp.lift _ _ _ $ λ g, finsupp.lift _ _ _
(λ f, single (g • partial_prod f) (1 : k)))
variables {k G n}
lemma to_tensor_aux_single (f : Gⁿ⁺¹) (m : k) :
to_tensor_aux k G n (single f m) = single (f 0) m ⊗ₜ single (λ i, (f i)⁻¹ * f i.succ) 1 :=
begin
simp only [to_tensor_aux, lift_apply, sum_single_index, tensor_product.smul_tmul'],
{ simp },
end
lemma to_tensor_aux_of_mul_action (g : G) (x : Gⁿ⁺¹) :
to_tensor_aux k G n (of_mul_action k G Gⁿ⁺¹ g (single x 1)) =
tensor_product.map (of_mul_action k G G g) 1 (to_tensor_aux k G n (single x 1)) :=
by simp [of_mul_action_def, to_tensor_aux_single, mul_assoc, inv_mul_cancel_left]
lemma of_tensor_aux_single (g : G) (m : k) (x : Gⁿ →₀ k) :
of_tensor_aux k G n ((single g m) ⊗ₜ x) =
finsupp.lift (Gⁿ⁺¹ →₀ k) k Gⁿ (λ f, single (g • partial_prod f) m) x :=
by simp [of_tensor_aux, sum_single_index, smul_sum, mul_comm m]
lemma of_tensor_aux_comm_of_mul_action (g h : G) (x : Gⁿ) :
of_tensor_aux k G n (tensor_product.map (of_mul_action k G G g)
(1 : module.End k (Gⁿ →₀ k)) (single h (1 : k) ⊗ₜ single x (1 : k))) =
of_mul_action k G Gⁿ⁺¹ g (of_tensor_aux k G n (single h 1 ⊗ₜ single x 1)) :=
begin
simp [of_mul_action_def, of_tensor_aux_single, mul_smul],
end
lemma to_tensor_aux_left_inv (x : Gⁿ⁺¹ →₀ k) :
of_tensor_aux _ _ _ (to_tensor_aux _ _ _ x) = x :=
begin
refine linear_map.ext_iff.1 (@finsupp.lhom_ext _ _ _ k _ _ _ _ _
(linear_map.comp (of_tensor_aux _ _ _) (to_tensor_aux _ _ _)) linear_map.id (λ x y, _)) x,
dsimp,
rw [to_tensor_aux_single x y, of_tensor_aux_single, finsupp.lift_apply, finsupp.sum_single_index,
one_smul, fin.partial_prod_left_inv],
{ rw zero_smul }
end
lemma to_tensor_aux_right_inv (x : (G →₀ k) ⊗[k] (Gⁿ →₀ k)) :
to_tensor_aux _ _ _ (of_tensor_aux _ _ _ x) = x :=
begin
refine tensor_product.induction_on x (by simp) (λ y z, _) (λ z w hz hw, by simp [hz, hw]),
rw [←finsupp.sum_single y, finsupp.sum, tensor_product.sum_tmul],
simp only [finset.smul_sum, linear_map.map_sum],
refine finset.sum_congr rfl (λ f hf, _),
simp only [of_tensor_aux_single, finsupp.lift_apply, finsupp.smul_single',
linear_map.map_finsupp_sum, to_tensor_aux_single, fin.partial_prod_right_inv],
dsimp,
simp only [fin.partial_prod_zero, mul_one],
conv_rhs {rw [←finsupp.sum_single z, finsupp.sum, tensor_product.tmul_sum]},
exact finset.sum_congr rfl (λ g hg, show _ ⊗ₜ _ = _, by
rw [←finsupp.smul_single', tensor_product.smul_tmul, finsupp.smul_single_one])
end
variables (k G n)
/-- Given a `G`-action on `H`, this is `k[H]` bundled with the natural representation
`G →* End(k[H])` as a term of type `Rep k G`. -/
abbreviation _root_.Rep.of_mul_action (G : Type u) [monoid G] (H : Type u) [mul_action G H] :
Rep k G :=
Rep.of $ representation.of_mul_action k G H
/-- A hom of `k`-linear representations of `G` from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` (on which `G` acts
by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) sending `(g₀, ..., gₙ)` to
`g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. -/
def to_tensor : Rep.of_mul_action k G (fin (n + 1) → G) ⟶ Rep.of
((representation.of_mul_action k G G).tprod (1 : G →* module.End k ((fin n → G) →₀ k))) :=
{ hom := to_tensor_aux k G n,
comm' := λ g, by ext; exact to_tensor_aux_of_mul_action _ _ }
/-- A hom of `k`-linear representations of `G` from `k[G] ⊗ₖ k[Gⁿ]` (on which `G` acts
by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) to `k[Gⁿ⁺¹]` sending `g ⊗ (g₁, ..., gₙ)` to
`(g, gg₁, gg₁g₂, ..., gg₁...gₙ)`. -/
def of_tensor :
Rep.of ((representation.of_mul_action k G G).tprod (1 : G →* module.End k ((fin n → G) →₀ k)))
⟶ Rep.of_mul_action k G (fin (n + 1) → G) :=
{ hom := of_tensor_aux k G n,
comm' := λ g, by { ext, congr' 1, exact (of_tensor_aux_comm_of_mul_action _ _ _) }}
variables {k G n}
@[simp] lemma to_tensor_single (f : Gⁿ⁺¹) (m : k) :
(to_tensor k G n).hom (single f m) = single (f 0) m ⊗ₜ single (λ i, (f i)⁻¹ * f i.succ) 1 :=
to_tensor_aux_single _ _
@[simp] lemma of_tensor_single (g : G) (m : k) (x : Gⁿ →₀ k) :
(of_tensor k G n).hom ((single g m) ⊗ₜ x) =
finsupp.lift (Rep.of_mul_action k G Gⁿ⁺¹) k Gⁿ (λ f, single (g • partial_prod f) m) x :=
of_tensor_aux_single _ _ _
lemma of_tensor_single' (g : G →₀ k) (x : Gⁿ) (m : k) :
(of_tensor k G n).hom (g ⊗ₜ single x m) =
finsupp.lift _ k G (λ a, single (a • partial_prod x) m) g :=
by simp [of_tensor, of_tensor_aux]
variables (k G n)
/-- An isomorphism of `k`-linear representations of `G` from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` (on
which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) sending `(g₀, ..., gₙ)` to
`g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. -/
def equiv_tensor : (Rep.of_mul_action k G (fin (n + 1) → G)) ≅ Rep.of
((representation.of_mul_action k G G).tprod (1 : representation k G ((fin n → G) →₀ k))) :=
Action.mk_iso (linear_equiv.to_Module_iso
{ inv_fun := of_tensor_aux k G n,
left_inv := to_tensor_aux_left_inv,
right_inv := λ x, by convert to_tensor_aux_right_inv x,
..to_tensor_aux k G n }) (to_tensor k G n).comm
-- not quite sure which simp lemmas to make here
@[simp] lemma equiv_tensor_def :
(equiv_tensor k G n).hom = to_tensor k G n := rfl
@[simp] lemma equiv_tensor_inv_def :
(equiv_tensor k G n).inv = of_tensor k G n := rfl
/-- The `k[G]`-linear isomorphism `k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹]`, where the `k[G]`-module structure on
the lefthand side is `tensor_product.left_module`, whilst that of the righthand side comes from
`representation.as_module`. Allows us to use `basis.algebra_tensor_product` to get a `k[G]`-basis
of the righthand side. -/
def of_mul_action_basis_aux : (monoid_algebra k G ⊗[k] ((fin n → G) →₀ k)) ≃ₗ[monoid_algebra k G]
(of_mul_action k G (fin (n + 1) → G)).as_module :=
{ map_smul' := λ r x,
begin
rw [ring_hom.id_apply, linear_equiv.to_fun_eq_coe, ←linear_equiv.map_smul],
congr' 1,
refine x.induction_on _ (λ x y, _) (λ y z hy hz, _),
{ simp only [smul_zero] },
{ simp only [tensor_product.smul_tmul'],
show (r * x) ⊗ₜ y = _,
rw [←of_mul_action_self_smul_eq_mul, smul_tprod_one_as_module] },
{ rw [smul_add, hz, hy, smul_add], }
end, .. ((Rep.equivalence_Module_monoid_algebra.1).map_iso
(equiv_tensor k G n).symm).to_linear_equiv }
/-- A `k[G]`-basis of `k[Gⁿ⁺¹]`, coming from the `k[G]`-linear isomorphism
`k[G] ⊗ₖ k[Gⁿ] ≃ k[Gⁿ⁺¹].` -/
def of_mul_action_basis :
basis (fin n → G) (monoid_algebra k G) (of_mul_action k G (fin (n + 1) → G)).as_module :=
@basis.map _ (monoid_algebra k G) (monoid_algebra k G ⊗[k] ((fin n → G) →₀ k))
_ _ _ _ _ _ (@algebra.tensor_product.basis k _ (monoid_algebra k G) _ _ ((fin n → G) →₀ k) _ _
(fin n → G) (⟨linear_equiv.refl k _⟩)) (of_mul_action_basis_aux k G n)
lemma of_mul_action_free :
module.free (monoid_algebra k G) (of_mul_action k G (fin (n + 1) → G)).as_module :=
module.free.of_basis (of_mul_action_basis k G n)
end group_cohomology.resolution
|
614839e5dd3d64850a0932ff9b6fce5871cec69a | 8e31b9e0d8cec76b5aa1e60a240bbd557d01047c | /scratch/polyhedra.lean | 6793c32454ef00fba688b541bbf6ba709bf686ba | [] | no_license | ChrisHughes24/LP | 7bdd62cb648461c67246457f3ddcb9518226dd49 | e3ed64c2d1f642696104584e74ae7226d8e916de | refs/heads/master | 1,685,642,642,858 | 1,578,070,602,000 | 1,578,070,602,000 | 195,268,102 | 4 | 3 | null | 1,569,229,518,000 | 1,562,255,287,000 | Lean | UTF-8 | Lean | false | false | 2,094 | lean | import .misc data.matrix .simplex tactic.fin_cases linear_algebra.matrix
#eval (encodable.choose)
import linear_algebra.dimension data.finsupp
#print prod.map
universes u v w
variables {m n k : Type u} [fintype m] [fintype n] [fintype k]
variables {one : Type u} [unique one]
variables {R : Type*} [discrete_linear_ordered_field R]
variables (A : matrix m n R)
open matrix
variables (x c : cvec R n) (b : cvec R m)
local notation M `⬝`:70 N := M.mul N
local postfix `ᵀ` : 1500 := transpose
section
variables {ι : Type*} {ι' : Type*} {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {v : ι → β}
variables [ring α] [add_comm_group β] [add_comm_group γ] [add_comm_group δ]
variables [module α β] [module α γ] [module α δ]
variables (α) (v)
local attribute [instance] finsupp.add_comm_group finsupp.module
end
local attribute [instance] finsupp.add_comm_group finsupp.module
def polyhedron : set (cvec R n) := { x | b ≤ A ⬝ x }
def dual_polyhedron : set (cvec R m) := { u | Aᵀ ⬝ u = c ∧ 0 ≤ u }
lemma row_mul (B : matrix n k R) (i) :
(row' A one i ⬝ B) = row' (A ⬝ B) one i := rfl
lemma polyhedron_row_inE :
x ∈ polyhedron A b ↔ ∀ i, b i 0 ≤ (row' A i ⬝ x) 0 0 :=
⟨λ h i, h _ _, λ h i j, by fin_cases j; apply h⟩
def active_ineq : set (fin m) :=
{i | (A ⬝ x) i 0 = b i 0}
/-- called feasible_dir in Coq paper -/
def unbounded_dir := { d : cvec R n | 0 ≤ A ⬝ d }
def pointed : Prop := n ≤ A.rank
lemma not_pointed_iff : ¬ pointed A ↔ ∃ d, d ≠ 0 ∧
(d : cvec R n) ∈ unbounded_dir A ∧ (-d) ∈ unbounded_dir A :=
have ¬ pointed A ↔ ∃ y : cvec R n, y ∈ linear_map.ker A.to_lin' ∧ y ≠ 0,
begin
rw [pointed, ← rank_transpose, row_le_rank_iff (Aᵀ), row_free], sorry,
end,
begin
rw this,
simp only [unbounded_dir, linear_map.mem_ker, set.mem_set_of_eq,
mul_neg, neg_zero, neg_nonneg],
split,
{ rintros ⟨y, yker, y0⟩,
exact ⟨y, y0, le_of_eq yker.symm, le_of_eq yker⟩ },
{ rintros ⟨d, d0, ubd, ubnd⟩,
exact ⟨d, le_antisymm ubnd ubd, d0⟩ }
end
|
5bd71cc07491b5230430497bdebdc4e544b521dc | b9a81ebb9de684db509231c4469a7d2c88915808 | /src/super/demod.lean | 258ef8338fcabc51faa5a50a51e4571826eea309 | [] | no_license | leanprover/super | 3dd81ce8d9ac3cba20bce55e84833fadb2f5716e | 47b107b4cec8f3b41d72daba9cbda2f9d54025de | refs/heads/master | 1,678,482,996,979 | 1,676,526,367,000 | 1,676,526,367,000 | 92,215,900 | 12 | 6 | null | 1,513,327,539,000 | 1,495,570,640,000 | Lean | UTF-8 | Lean | false | false | 2,170 | lean | /-
Copyright (c) 2017 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .superposition
open tactic monad expr
namespace super
meta def is_demodulator (c : clause) : bool :=
match c.get_lits with
| [clause.literal.right eqn] := eqn.is_eq.is_some
| _ := ff
end
variable gt : expr → expr → bool
meta def demod' (cs1 : list derived_clause) : clause → list derived_clause → tactic (list derived_clause × clause) | c2 used_demods :=
(first $ do
i ← list.range c2.num_lits,
pos ← rwr_positions c2 i,
c1 ← cs1,
(ltr, congr_ax) ← [(tt, ``super.sup_ltr), (ff, ``super.sup_rtl)],
[do c2' ← try_sup gt c1.c c2 0 i pos ltr tt congr_ax,
demod' c2' (c1 :: used_demods)]
) <|> return (used_demods, c2)
meta def demod (cs1 : list derived_clause) (c2 : clause) : tactic (list derived_clause × clause) := do
c2qf ← c2.open_constn c2.num_quants,
(used_demods, c2qf') ← demod' gt cs1 c2qf.1 [],
if used_demods.empty then return ([], c2) else
return (used_demods, c2qf'.close_constn c2qf.2)
meta def demod_fwd_inf : inference :=
assume given, do
active ← get_active,
demods ← return (do ac ← active.values, guard $ is_demodulator ac.c, guard $ ac.id ≠ given.id, [ac]),
if demods.empty then skip else do
(used_demods, given') ← demod gt demods given.c,
if used_demods.empty then skip else do
remove_redundant given.id used_demods,
mk_derived given' given.sc.sched_now >>= add_inferred
meta def demod_back1 (given active : derived_clause) : prover unit := do
(used_demods, c') ← demod gt [given] active.c,
if used_demods.empty then skip else do
remove_redundant active.id used_demods,
mk_derived c' active.sc.sched_now >>= add_inferred
meta def demod_back_inf : inference :=
assume given, if ¬is_demodulator given.c then skip else
do active ← get_active, sequence' $ do
ac ← active.values,
guard $ ac.id ≠ given.id,
[demod_back1 gt given ac]
@[super.inf]
meta def demod_inf : inf_decl := {
prio := 10,
inf := assume given, do
gt ← get_term_order,
demod_fwd_inf gt given,
demod_back_inf gt given,
skip
}
end super
|
e56e51df072d8af1bc3e05fab21338dfd8b221d9 | b9a81ebb9de684db509231c4469a7d2c88915808 | /test/cdcl_examples.lean | d4f46b82740c6d565eb1fa68078155eac44659fa | [] | no_license | leanprover/super | 3dd81ce8d9ac3cba20bce55e84833fadb2f5716e | 47b107b4cec8f3b41d72daba9cbda2f9d54025de | refs/heads/master | 1,678,482,996,979 | 1,676,526,367,000 | 1,676,526,367,000 | 92,215,900 | 12 | 6 | null | 1,513,327,539,000 | 1,495,570,640,000 | Lean | UTF-8 | Lean | false | false | 698 | lean | import super.cdcl
example {a} : a → ¬a → false := by cdcl
example {a} : a ∨ ¬a := by cdcl
example {a b} : a → (a → b) → b := by cdcl
example {a b c} : (a → b) → (¬a → b) → (b → c) → b ∧ c := by cdcl
open tactic
private meta def lit_unification : tactic unit :=
do ls ← local_context, first $ do l ← ls, [do apply l, assumption]
example {p : ℕ → Prop} : p 2 ∨ p 4 → (p (2*2) → p (2+0)) → p (1+1) :=
by cdcl_t lit_unification
example {p : ℕ → Prop} :
list.foldl (λf v, f ∧ (v ∨ ¬v)) true (p <$> list.range 5) :=
begin (target >>= whnf >>= change), cdcl end
example {a b c : Prop} : (a → b) → (b → c) → (a → c) := by cdcl
|
621963a9dc80890cbe3317fbe58dfb4a53cac8fc | 0d7f5899c0475f9e105a439896d9377f80c0d7c3 | /src/forget.lean | 61cc6c16fab419bcff0076887ba5ca90b2c83ac1 | [] | no_license | adamtopaz/UnivAlg | 127038f320e68cdf3efcd0c084c9af02fdb8da3d | 2458d47a6e4fd0525e3a25b07cb7dd518ac173ef | refs/heads/master | 1,670,320,985,286 | 1,597,350,882,000 | 1,597,350,882,000 | 280,585,500 | 4 | 0 | null | 1,597,350,883,000 | 1,595,048,527,000 | Lean | UTF-8 | Lean | false | false | 758 | lean | import .ualg
import .lang
class compat {L1 : lang} {L2 : lang} (ι : L1 →# L2) (A : Type*) [has_app L2 A] extends has_app L1 A :=
(compat {n} {t : L1 n} {as : ftuple A n} : applyo t as = applyo (ι t) as)
namespace lang_hom
def forget_along {L1 : lang} {L2 : lang} (ι : L1 →# L2) (A : Type*) [has_app L2 A] : compat ι A :=
{ app := λ n t, applyo (ι t),
compat := by tauto }
end lang_hom
namespace ralg_hom
variables {L0 : lang} {L1 : lang}
def drop {A : Type*} [has_app L1 A] {B : Type*} [has_app L1 B] (f : A →$[L1] B) (ι : L0 →# L1)
[compat ι A] [compat ι B] : A →$[L0] B :=
{ to_fn := f,
applyo_map' :=
begin
intros n t as,
simp_rw compat.compat,
apply ralg_hom.applyo_map,
end }
#check drop
end ralg_hom |
457d1ad98394e2f629e56b05c17f9477cc64390d | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/computability/language.lean | 77e72dfdc92255527fe412b51ba525fc142f6e28 | [] | 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,323 | lean | /-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.finset.basic
import Mathlib.PostPort
universes u_1 u v
namespace Mathlib
/-!
# Languages
This file contains the definition and operations on formal languages over an alphabet. Note strings
are implemented as lists over the alphabet.
The operations in this file define a [Kleene algebra](https://en.wikipedia.org/wiki/Kleene_algebra)
over the languages.
-/
/-- A language is a set of strings over an alphabet. -/
def language (α : Type u_1) :=
set (List α)
namespace language
protected instance has_zero {α : Type u} : HasZero (language α) :=
{ zero := ∅ }
protected instance has_one {α : Type u} : HasOne (language α) :=
{ one := singleton [] }
protected instance inhabited {α : Type u} : Inhabited (language α) :=
{ default := 0 }
protected instance has_add {α : Type u} : Add (language α) :=
{ add := set.union }
protected instance has_mul {α : Type u} : Mul (language α) :=
{ mul := fun (l m : language α) => (fun (p : List α × List α) => prod.fst p ++ prod.snd p) '' set.prod l m }
theorem zero_def {α : Type u} : 0 = ∅ :=
rfl
theorem one_def {α : Type u} : 1 = singleton [] :=
rfl
theorem add_def {α : Type u} (l : language α) (m : language α) : l + m = l ∪ m :=
rfl
theorem mul_def {α : Type u} (l : language α) (m : language α) : l * m = (fun (p : List α × List α) => prod.fst p ++ prod.snd p) '' set.prod l m :=
rfl
/-- The star of a language `L` is the set of all strings which can be written by concatenating
strings from `L`. -/
def star {α : Type u} (l : language α) : language α :=
set_of fun (x : List α) => ∃ (S : List (List α)), x = list.join S ∧ ∀ (y : List α), y ∈ S → y ∈ l
theorem star_def {α : Type u} (l : language α) : star l = set_of fun (x : List α) => ∃ (S : List (List α)), x = list.join S ∧ ∀ (y : List α), y ∈ S → y ∈ l :=
rfl
@[simp] theorem mem_one {α : Type u} (x : List α) : x ∈ 1 ↔ x = [] :=
iff.refl (x ∈ 1)
@[simp] theorem mem_add {α : Type u} (l : language α) (m : language α) (x : List α) : x ∈ l + m ↔ x ∈ l ∨ x ∈ m := sorry
theorem mem_mul {α : Type u} (l : language α) (m : language α) (x : List α) : x ∈ l * m ↔ ∃ (a : List α), ∃ (b : List α), a ∈ l ∧ b ∈ m ∧ a ++ b = x := sorry
theorem mem_star {α : Type u} (l : language α) (x : List α) : x ∈ star l ↔ ∃ (S : List (List α)), x = list.join S ∧ ∀ (y : List α), y ∈ S → y ∈ l :=
iff.refl (x ∈ star l)
protected instance semiring {α : Type u} : semiring (language α) :=
semiring.mk Add.add sorry 0 sorry sorry sorry Mul.mul mul_assoc_lang 1 one_mul_lang mul_one_lang sorry sorry
left_distrib_lang right_distrib_lang
@[simp] theorem add_self {α : Type u} (l : language α) : l + l = l :=
sup_idem
theorem star_def_nonempty {α : Type u} (l : language α) : star l = set_of fun (x : List α) => ∃ (S : List (List α)), x = list.join S ∧ ∀ (y : List α), y ∈ S → y ∈ l ∧ y ≠ [] := sorry
theorem le_iff {α : Type u} (l : language α) (m : language α) : l ≤ m ↔ l + m = m :=
iff.symm sup_eq_right
theorem le_mul_congr {α : Type u} {l₁ : language α} {l₂ : language α} {m₁ : language α} {m₂ : language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ * l₂ ≤ m₁ * m₂ := sorry
theorem le_add_congr {α : Type u} {l₁ : language α} {l₂ : language α} {m₁ : language α} {m₂ : language α} : l₁ ≤ m₁ → l₂ ≤ m₂ → l₁ + l₂ ≤ m₁ + m₂ :=
sup_le_sup
theorem supr_mul {α : Type u} {ι : Sort v} (l : ι → language α) (m : language α) : (supr fun (i : ι) => l i) * m = supr fun (i : ι) => l i * m := sorry
theorem mul_supr {α : Type u} {ι : Sort v} (l : ι → language α) (m : language α) : (m * supr fun (i : ι) => l i) = supr fun (i : ι) => m * l i := sorry
theorem supr_add {α : Type u} {ι : Sort v} [Nonempty ι] (l : ι → language α) (m : language α) : (supr fun (i : ι) => l i) + m = supr fun (i : ι) => l i + m :=
supr_sup
theorem add_supr {α : Type u} {ι : Sort v} [Nonempty ι] (l : ι → language α) (m : language α) : (m + supr fun (i : ι) => l i) = supr fun (i : ι) => m + l i :=
sup_supr
theorem star_eq_supr_pow {α : Type u} (l : language α) : star l = supr fun (i : ℕ) => l ^ i := sorry
theorem mul_self_star_comm {α : Type u} (l : language α) : star l * l = l * star l := sorry
@[simp] theorem one_add_self_mul_star_eq_star {α : Type u} (l : language α) : 1 + l * star l = star l := sorry
@[simp] theorem one_add_star_mul_self_eq_star {α : Type u} (l : language α) : 1 + star l * l = star l :=
eq.mpr (id (Eq._oldrec (Eq.refl (1 + star l * l = star l)) (mul_self_star_comm l)))
(eq.mpr (id (Eq._oldrec (Eq.refl (1 + l * star l = star l)) (one_add_self_mul_star_eq_star l))) (Eq.refl (star l)))
theorem star_mul_le_right_of_mul_le_right {α : Type u} (l : language α) (m : language α) : l * m ≤ m → star l * m ≤ m := sorry
theorem star_mul_le_left_of_mul_le_left {α : Type u} (l : language α) (m : language α) : m * l ≤ m → m * star l ≤ m := sorry
|
c2244eaa0ca4b04f3ab38059754f3fb4b4e0734f | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/combinatorics/quiver/path.lean | bbfec5111694a0495d5901a9c5c3d1dcbc3b2d59 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 6,150 | lean | /-
Copyright (c) 2021 David Wärn,. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn, Scott Morrison
-/
import combinatorics.quiver.basic
import logic.lemmas
/-!
# Paths in quivers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/811
> Any changes to this file require a corresponding PR to mathlib4.
Given a quiver `V`, we define the type of paths from `a : V` to `b : V` as an inductive
family. We define composition of paths and the action of prefunctors on paths.
-/
open function
universes v v₁ v₂ u u₁ u₂
namespace quiver
/-- `G.path a b` is the type of paths from `a` to `b` through the arrows of `G`. -/
inductive path {V : Type u} [quiver.{v} V] (a : V) : V → Sort (max (u+1) v)
| nil : path a
| cons : Π {b c : V}, path b → (b ⟶ c) → path c
/-- An arrow viewed as a path of length one. -/
def hom.to_path {V} [quiver V] {a b : V} (e : a ⟶ b) : path a b :=
path.nil.cons e
namespace path
variables {V : Type u} [quiver V] {a b c : V}
/-- The length of a path is the number of arrows it uses. -/
def length {a : V} : Π {b : V}, path a b → ℕ
| _ path.nil := 0
| _ (path.cons p _) := p.length + 1
instance {a : V} : inhabited (path a a) := ⟨path.nil⟩
@[simp] lemma length_nil {a : V} :
(path.nil : path a a).length = 0 := rfl
@[simp] lemma length_cons (a b c : V) (p : path a b)
(e : b ⟶ c) : (p.cons e).length = p.length + 1 := rfl
lemma eq_of_length_zero (p : path a b) (hzero : p.length = 0) : a = b :=
by { cases p, { refl }, { cases nat.succ_ne_zero _ hzero } }
/-- Composition of paths. -/
def comp {a b : V} : Π {c}, path a b → path b c → path a c
| _ p (path.nil) := p
| _ p (path.cons q e) := (p.comp q).cons e
@[simp] lemma comp_cons {a b c d : V} (p : path a b) (q : path b c) (e : c ⟶ d) :
p.comp (q.cons e) = (p.comp q).cons e := rfl
@[simp] lemma comp_nil {a b : V} (p : path a b) : p.comp path.nil = p := rfl
@[simp] lemma nil_comp {a : V} : ∀ {b} (p : path a b), path.nil.comp p = p
| a path.nil := rfl
| b (path.cons p e) := by rw [comp_cons, nil_comp]
@[simp] lemma comp_assoc {a b c : V} : ∀ {d}
(p : path a b) (q : path b c) (r : path c d),
(p.comp q).comp r = p.comp (q.comp r)
| c p q path.nil := rfl
| d p q (path.cons r e) := by rw [comp_cons, comp_cons, comp_cons, comp_assoc]
@[simp] lemma length_comp (p : path a b) :
∀ {c} (q : path b c), (p.comp q).length = p.length + q.length
| c nil := rfl
| c (cons q h) := congr_arg nat.succ q.length_comp
lemma comp_inj {p₁ p₂ : path a b} {q₁ q₂ : path b c} (hq : q₁.length = q₂.length) :
p₁.comp q₁ = p₂.comp q₂ ↔ p₁ = p₂ ∧ q₁ = q₂ :=
begin
refine ⟨λ h, _, by { rintro ⟨rfl, rfl⟩, refl }⟩,
induction q₁ with d₁ e₁ q₁ f₁ ih generalizing q₂; obtain _ | ⟨q₂, f₂⟩ := q₂,
{ exact ⟨h, rfl⟩ },
{ cases hq },
{ cases hq },
simp only [comp_cons] at h,
obtain rfl := h.1,
obtain ⟨rfl, rfl⟩ := ih (nat.succ.inj hq) h.2.1.eq,
rw h.2.2.eq,
exact ⟨rfl, rfl⟩,
end
lemma comp_inj' {p₁ p₂ : path a b} {q₁ q₂ : path b c} (h : p₁.length = p₂.length) :
p₁.comp q₁ = p₂.comp q₂ ↔ p₁ = p₂ ∧ q₁ = q₂ :=
⟨λ h_eq, (comp_inj $ nat.add_left_cancel $
by simpa [h] using congr_arg length h_eq).1 h_eq, by { rintro ⟨rfl, rfl⟩, refl }⟩
lemma comp_injective_left (q : path b c) : injective (λ p : path a b, p.comp q) :=
λ p₁ p₂ h, ((comp_inj rfl).1 h).1
lemma comp_injective_right (p : path a b) : injective (p.comp : path b c → path a c) :=
λ q₁ q₂ h, ((comp_inj' rfl).1 h).2
@[simp] lemma comp_inj_left {p₁ p₂ : path a b} {q : path b c} : p₁.comp q = p₂.comp q ↔ p₁ = p₂ :=
q.comp_injective_left.eq_iff
@[simp] lemma comp_inj_right {p : path a b} {q₁ q₂ : path b c} : p.comp q₁ = p.comp q₂ ↔ q₁ = q₂ :=
p.comp_injective_right.eq_iff
/-- Turn a path into a list. The list contains `a` at its head, but not `b` a priori. -/
@[simp] def to_list : Π {b : V}, path a b → list V
| b nil := []
| b (@cons _ _ _ c _ p f) := c :: p.to_list
/-- `quiver.path.to_list` is a contravariant functor. The inversion comes from `quiver.path` and
`list` having different preferred directions for adding elements. -/
@[simp] lemma to_list_comp (p : path a b) :
∀ {c} (q : path b c), (p.comp q).to_list = q.to_list ++ p.to_list
| c nil := by simp
| c (@cons _ _ _ d _ q f) := by simp [to_list_comp]
lemma to_list_chain_nonempty :
∀ {b} (p : path a b), p.to_list.chain (λ x y, nonempty (y ⟶ x)) b
| b nil := list.chain.nil
| b (cons p f) := p.to_list_chain_nonempty.cons ⟨f⟩
variables [∀ a b : V, subsingleton (a ⟶ b)]
lemma to_list_injective (a : V) : ∀ b, injective (to_list : path a b → list V)
| b nil nil h := rfl
| b nil (@cons _ _ _ c _ p f) h := by cases h
| b (@cons _ _ _ c _ p f) nil h := by cases h
| b (@cons _ _ _ c _ p f) (@cons _ _ s t u C D) h := begin
simp only [to_list] at h,
obtain ⟨rfl, hAC⟩ := h,
simp [to_list_injective _ hAC],
end
@[simp] lemma to_list_inj {p q : path a b} : p.to_list = q.to_list ↔ p = q :=
(to_list_injective _ _).eq_iff
end path
end quiver
namespace prefunctor
open quiver
variables {V : Type u₁} [quiver.{v₁} V] {W : Type u₂} [quiver.{v₂} W] (F : V ⥤q W)
/-- The image of a path under a prefunctor. -/
def map_path {a : V} :
Π {b : V}, path a b → path (F.obj a) (F.obj b)
| _ path.nil := path.nil
| _ (path.cons p e) := path.cons (map_path p) (F.map e)
@[simp] lemma map_path_nil (a : V) : F.map_path (path.nil : path a a) = path.nil := rfl
@[simp] lemma map_path_cons {a b c : V} (p : path a b) (e : b ⟶ c) :
F.map_path (path.cons p e) = path.cons (F.map_path p) (F.map e) := rfl
@[simp] lemma map_path_comp {a b : V} (p : path a b) :
∀ {c : V} (q : path b c), F.map_path (p.comp q) = (F.map_path p).comp (F.map_path q)
| _ path.nil := rfl
| _ (path.cons p e) := begin dsimp, rw [map_path_comp], end
@[simp]
lemma map_path_to_path {a b : V} (f : a ⟶ b) : F.map_path f.to_path = (F.map f).to_path := rfl
end prefunctor
|
bbccf3a2f6fd758474042addda73672b6cb38856 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/data/complex/module.lean | da3c22e4813d3994c8c3769519557b86f56824d8 | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,551 | lean | /-
Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Sébastien Gouëzel
-/
import data.complex.basic
import algebra.algebra.ordered
import data.matrix.notation
import field_theory.tower
import linear_algebra.finite_dimensional
/-!
# Complex number as a vector space over `ℝ`
This file contains the following instances:
* Any `•`-structure (`has_scalar`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on
`ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ`
algebra.
* any complex vector space is a real vector space;
* any finite dimensional complex vector space is a finite dimensional real vector space;
* the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex
vector space.
It also defines three linear maps:
* `complex.re_lm`;
* `complex.im_lm`;
* `complex.of_real_lm`;
* `complex.conj_lm`.
They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and
the complex conjugate as `ℝ`-linear maps.
-/
noncomputable theory
namespace complex
variables {R : Type*} {S : Type*}
section
variables [has_scalar R ℝ]
/- The useless `0` multiplication in `smul` is to make sure that
`restrict_scalars.module ℝ ℂ ℂ = complex.module` definitionally. -/
instance : has_scalar R ℂ :=
{ smul := λ r x, ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ }
lemma smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(•)]
lemma smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(•)]
@[simp] lemma smul_coe {x : ℝ} {z : ℂ} : x • z = x * z :=
by ext; simp [smul_re, smul_im]
end
instance [has_scalar R ℝ] [has_scalar S ℝ] [smul_comm_class R S ℝ] : smul_comm_class R S ℂ :=
{ smul_comm := λ r s x, by ext; simp [smul_re, smul_im, smul_comm] }
instance [has_scalar R S] [has_scalar R ℝ] [has_scalar S ℝ] [is_scalar_tower R S ℝ] :
is_scalar_tower R S ℂ :=
{ smul_assoc := λ r s x, by ext; simp [smul_re, smul_im, smul_assoc] }
instance [monoid R] [mul_action R ℝ] : mul_action R ℂ :=
{ one_smul := λ x, by ext; simp [smul_re, smul_im, one_smul],
mul_smul := λ r s x, by ext; simp [smul_re, smul_im, mul_smul] }
instance [semiring R] [distrib_mul_action R ℝ] : distrib_mul_action R ℂ :=
{ smul_add := λ r x y, by ext; simp [smul_re, smul_im, smul_add],
smul_zero := λ r, by ext; simp [smul_re, smul_im, smul_zero] }
instance [semiring R] [module R ℝ] : module R ℂ :=
{ add_smul := λ r s x, by ext; simp [smul_re, smul_im, add_smul],
zero_smul := λ r, by ext; simp [smul_re, smul_im, zero_smul] }
instance [comm_semiring R] [algebra R ℝ] : algebra R ℂ :=
{ smul := (•),
smul_def' := λ r x, by ext; simp [smul_re, smul_im, algebra.smul_def],
commutes' := λ r ⟨xr, xi⟩, by ext; simp [smul_re, smul_im, algebra.commutes],
..complex.of_real.comp (algebra_map R ℝ) }
/-- Complex conjugation as an `ℝ`-algebra isomorphism -/
def conj_alg_equiv : ℂ ≃ₐ[ℝ] ℂ :=
{ inv_fun := complex.conj,
left_inv := complex.conj_conj,
right_inv := complex.conj_conj,
commutes' := complex.conj_of_real,
.. complex.conj }
section
open_locale complex_order
lemma complex_ordered_module : ordered_module ℝ ℂ :=
{ smul_lt_smul_of_pos := λ z w x h₁ h₂,
begin
obtain ⟨y, l, rfl⟩ := lt_def.mp h₁,
refine lt_def.mpr ⟨x * y, _, _⟩,
exact mul_pos h₂ l,
ext; simp [mul_add],
end,
lt_of_smul_lt_smul_of_pos := λ z w x h₁ h₂,
begin
obtain ⟨y, l, e⟩ := lt_def.mp h₁,
by_cases h : x = 0,
{ subst h, exfalso, apply lt_irrefl 0 h₂, },
{ refine lt_def.mpr ⟨y / x, div_pos l h₂, _⟩,
replace e := congr_arg (λ z, (x⁻¹ : ℂ) * z) e,
simp only [mul_add, ←mul_assoc, h, one_mul, of_real_eq_zero, smul_coe, ne.def,
not_false_iff, inv_mul_cancel] at e,
convert e,
simp only [div_eq_iff_mul_eq, h, of_real_eq_zero, of_real_div, ne.def, not_false_iff],
norm_cast,
simp [mul_comm _ y, mul_assoc, h],
},
end }
localized "attribute [instance] complex_ordered_module" in complex_order
end
@[simp] lemma coe_algebra_map : ⇑(algebra_map ℝ ℂ) = complex.of_real := rfl
open submodule finite_dimensional
lemma is_basis_one_I : is_basis ℝ ![1, I] :=
begin
refine ⟨linear_independent_fin2.2 ⟨by simp [I_ne_zero], λ a, mt (congr_arg re) $ by simp⟩,
eq_top_iff'.2 $ λ z, _⟩,
suffices : ∃ a b : ℝ, z = a • I + b • 1,
by simpa [mem_span_insert, mem_span_singleton, -set.singleton_one],
use [z.im, z.re],
simp [algebra.smul_def, add_comm]
end
instance : finite_dimensional ℝ ℂ := of_fintype_basis is_basis_one_I
@[simp] lemma finrank_real_complex : finite_dimensional.finrank ℝ ℂ = 2 :=
by rw [finrank_eq_card_basis is_basis_one_I, fintype.card_fin]
@[simp] lemma dim_real_complex : module.rank ℝ ℂ = 2 :=
by simp [← finrank_eq_dim, finrank_real_complex]
lemma {u} dim_real_complex' : cardinal.lift.{0 u} (module.rank ℝ ℂ) = 2 :=
by simp [← finrank_eq_dim, finrank_real_complex, bit0]
/-- `fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the
circle. -/
lemma finrank_real_complex_fact : fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩
end complex
/- Register as an instance (with low priority) the fact that a complex vector space is also a real
vector space. -/
@[priority 900]
instance module.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E] : module ℝ E :=
restrict_scalars.module ℝ ℂ E
instance module.real_complex_tower (E : Type*) [add_comm_group E] [module ℂ E] :
is_scalar_tower ℝ ℂ E :=
restrict_scalars.is_scalar_tower ℝ ℂ E
@[priority 100]
instance finite_dimensional.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E]
[finite_dimensional ℂ E] : finite_dimensional ℝ E :=
finite_dimensional.trans ℝ ℂ E
lemma dim_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :
module.rank ℝ E = 2 * module.rank ℂ E :=
cardinal.lift_inj.1 $
by { rw [← dim_mul_dim' ℝ ℂ E, complex.dim_real_complex], simp [bit0] }
lemma finrank_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :
finite_dimensional.finrank ℝ E = 2 * finite_dimensional.finrank ℂ E :=
by rw [← finite_dimensional.finrank_mul_finrank ℝ ℂ E, complex.finrank_real_complex]
namespace complex
/-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/
def re_lm : ℂ →ₗ[ℝ] ℝ :=
{ to_fun := λx, x.re,
map_add' := add_re,
map_smul' := by simp, }
@[simp] lemma re_lm_coe : ⇑re_lm = re := rfl
/-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/
def im_lm : ℂ →ₗ[ℝ] ℝ :=
{ to_fun := λx, x.im,
map_add' := add_im,
map_smul' := by simp, }
@[simp] lemma im_lm_coe : ⇑im_lm = im := rfl
/-- Linear map version of the canonical embedding of `ℝ` in `ℂ`. -/
def of_real_lm : ℝ →ₗ[ℝ] ℂ :=
{ to_fun := coe,
map_add' := of_real_add,
map_smul' := λc x, by simp [algebra.smul_def] }
@[simp] lemma of_real_lm_coe : ⇑of_real_lm = coe := rfl
/-- `ℝ`-linear map version of the complex conjugation function from `ℂ` to `ℂ`. -/
def conj_lm : ℂ →ₗ[ℝ] ℂ :=
{ map_smul' := by simp [restrict_scalars_smul_def],
..conj }
@[simp] lemma conj_lm_coe : ⇑conj_lm = conj := rfl
end complex
|
1ee9b5aed62fcd55dbe0118c4b0c9a0a8fcfa010 | 63abd62053d479eae5abf4951554e1064a4c45b4 | /src/order/galois_connection.lean | 9d950a5b4583640c4550287ccaf5a5f8db63b102 | [
"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 | 25,293 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Johannes Hölzl
-/
import order.complete_lattice
import order.rel_iso
/-!
# Galois connections, insertions and coinsertions
Galois connections are order theoretic adjoints, i.e. a pair of functions `u` and `l`,
such that `∀a b, l a ≤ b ↔ a ≤ u b`.
## Main definitions
* `galois_connection`: A Galois connection is a pair of functions `l` and `u` satisfying
`l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory,
but do not depend on the category theory library in mathlib.
* `galois_insertion`: A Galois insertion is a Galois connection where `l ∘ u = id`
* `galois_coinsertion`: A Galois coinsertion is a Galois connection where `u ∘ l = id`
## Implementation details
Galois insertions can be used to lift order structures from one type to another.
For example if `α` is a complete lattice, and `l : α → β`, and `u : β → α` form
a Galois insertion, then `β` is also a complete lattice. `l` is the lower adjoint and
`u` is the upper adjoint.
An example of this is the Galois insertion is in group thery. If `G` is a topological space,
then there is a Galois insertion between the set of subsets of `G`, `set G`, and the
set of subgroups of `G`, `subgroup G`. The left adjoint is `subgroup.closure`,
taking the `subgroup` generated by a `set`, The right adjoint is the coercion from `subgroup G` to
`set G`, taking the underlying set of an subgroup.
Naively lifting a lattice structure along this Galois insertion would mean that the definition
of `inf` on subgroups would be `subgroup.closure (↑S ∩ ↑T)`. This is an undesirable definition
because the intersection of subgroups is already a subgroup, so there is no need to take the
closure. For this reason a `choice` function is added as a field to the `galois_insertion`
structure. It has type `Π S : set G, ↑(closure S) ≤ S → subgroup G`. When `↑(closure S) ≤ S`, then
`S` is already a subgroup, so this function can be defined using `subgroup.mk` and not `closure`.
This means the infimum of subgroups will be defined to be the intersection of sets, paired
with a proof that intersection of subgroups is a subgroup, rather than the closure of the
intersection.
-/
open function set
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a a₁ a₂ : α} {b b₁ b₂ : β}
/-- A Galois connection is a pair of functions `l` and `u` satisfying
`l a ≤ b ↔ a ≤ u b`. They are special cases of adjoint functors in category theory,
but do not depend on the category theory library in mathlib. -/
def galois_connection [preorder α] [preorder β] (l : α → β) (u : β → α) := ∀a b, l a ≤ b ↔ a ≤ u b
/-- Makes a Galois connection from an order-preserving bijection. -/
theorem order_iso.to_galois_connection [preorder α] [preorder β] (oi : α ≃o β) :
galois_connection oi oi.symm :=
λ b g, by rw [oi.map_rel_iff, rel_iso.apply_symm_apply]
namespace galois_connection
section
variables [preorder α] [preorder β] {l : α → β} {u : β → α} (gc : galois_connection l u)
lemma monotone_intro (hu : monotone u) (hl : monotone l)
(hul : ∀ a, a ≤ u (l a)) (hlu : ∀ a, l (u a) ≤ a) : galois_connection l u :=
assume a b, ⟨assume h, le_trans (hul _) (hu h), assume h, le_trans (hl h) (hlu _)⟩
include gc
lemma l_le {a : α} {b : β} : a ≤ u b → l a ≤ b :=
(gc _ _).mpr
lemma le_u {a : α} {b : β} : l a ≤ b → a ≤ u b :=
(gc _ _).mp
lemma le_u_l (a) : a ≤ u (l a) :=
gc.le_u $ le_refl _
lemma l_u_le (a) : l (u a) ≤ a :=
gc.l_le $ le_refl _
lemma monotone_u : monotone u :=
assume a b H, gc.le_u (le_trans (gc.l_u_le a) H)
lemma monotone_l : monotone l :=
assume a b H, gc.l_le (le_trans H (gc.le_u_l b))
lemma upper_bounds_l_image_subset {s : set α} : upper_bounds (l '' s) ⊆ u ⁻¹' upper_bounds s :=
assume b hb c, assume : c ∈ s, gc.le_u (hb (mem_image_of_mem _ ‹c ∈ s›))
lemma lower_bounds_u_image_subset {s : set β} : lower_bounds (u '' s) ⊆ l ⁻¹' lower_bounds s :=
assume a ha c, assume : c ∈ s, gc.l_le (ha (mem_image_of_mem _ ‹c ∈ s›))
lemma is_lub_l_image {s : set α} {a : α} (h : is_lub s a) : is_lub (l '' s) (l a) :=
⟨gc.monotone_l.mem_upper_bounds_image $ and.elim_left ‹is_lub s a›,
assume b hb, gc.l_le $ and.elim_right ‹is_lub s a› $ gc.upper_bounds_l_image_subset hb⟩
lemma is_glb_u_image {s : set β} {b : β} (h : is_glb s b) : is_glb (u '' s) (u b) :=
⟨gc.monotone_u.mem_lower_bounds_image $ and.elim_left ‹is_glb s b›,
assume a ha, gc.le_u $ and.elim_right ‹is_glb s b› $ gc.lower_bounds_u_image_subset ha⟩
lemma is_glb_l {a : α} : is_glb { b | a ≤ u b } (l a) :=
⟨assume b, gc.l_le, assume b h, h $ gc.le_u_l _⟩
lemma is_lub_u {b : β} : is_lub { a | l a ≤ b } (u b) :=
⟨assume b, gc.le_u, assume b h, h $ gc.l_u_le _⟩
end
section partial_order
variables [partial_order α] [partial_order β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma u_l_u_eq_u : u ∘ l ∘ u = u :=
funext (assume x, le_antisymm (gc.monotone_u (gc.l_u_le _)) (gc.le_u_l _))
lemma l_u_l_eq_l : l ∘ u ∘ l = l :=
funext (assume x, le_antisymm (gc.l_u_le _) (gc.monotone_l (gc.le_u_l _)))
lemma l_unique {l' : α → β} {u' : β → α} (gc' : galois_connection l' u')
(hu : ∀ b, u b = u' b) {a : α} : l a = l' a :=
le_antisymm (gc.l_le $ (hu (l' a)).symm ▸ gc'.le_u_l _)
(gc'.l_le $ hu (l a) ▸ gc.le_u_l _)
lemma u_unique {l' : α → β} {u' : β → α} (gc' : galois_connection l' u')
(hl : ∀ a, l a = l' a) {b : β} : u b = u' b :=
le_antisymm (gc'.le_u $ hl (u b) ▸ gc.l_u_le _)
(gc.le_u $ (hl (u' b)).symm ▸ gc'.l_u_le _)
end partial_order
section order_top
variables [order_top α] [order_top β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma u_top : u ⊤ = ⊤ :=
(gc.is_glb_u_image is_glb_empty).unique $ by simp only [is_glb_empty, image_empty]
end order_top
section order_bot
variables [order_bot α] [order_bot β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma l_bot : l ⊥ = ⊥ :=
(gc.is_lub_l_image is_lub_empty).unique $ by simp only [is_lub_empty, image_empty]
end order_bot
section semilattice_sup
variables [semilattice_sup α] [semilattice_sup β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma l_sup : l (a₁ ⊔ a₂) = l a₁ ⊔ l a₂ :=
(gc.is_lub_l_image is_lub_pair).unique $ by simp only [image_pair, is_lub_pair]
end semilattice_sup
section semilattice_inf
variables [semilattice_inf α] [semilattice_inf β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma u_inf : u (b₁ ⊓ b₂) = u b₁ ⊓ u b₂ :=
(gc.is_glb_u_image is_glb_pair).unique $ by simp only [image_pair, is_glb_pair]
end semilattice_inf
section complete_lattice
variables [complete_lattice α] [complete_lattice β] {l : α → β} {u : β → α} (gc : galois_connection l u)
include gc
lemma l_supr {f : ι → α} : l (supr f) = (⨆i, l (f i)) :=
eq.symm $ is_lub.supr_eq $ show is_lub (range (l ∘ f)) (l (supr f)),
by rw [range_comp, ← Sup_range]; exact gc.is_lub_l_image (is_lub_Sup _)
lemma u_infi {f : ι → β} : u (infi f) = (⨅i, u (f i)) :=
eq.symm $ is_glb.infi_eq $ show is_glb (range (u ∘ f)) (u (infi f)),
by rw [range_comp, ← Inf_range]; exact gc.is_glb_u_image (is_glb_Inf _)
lemma l_Sup {s : set α} : l (Sup s) = (⨆a∈s, l a) :=
by simp only [Sup_eq_supr, gc.l_supr]
lemma u_Inf {s : set β} : u (Inf s) = (⨅a∈s, u a) :=
by simp only [Inf_eq_infi, gc.u_infi]
end complete_lattice
/- Constructing Galois connections -/
section constructions
protected lemma id [pα : preorder α] : @galois_connection α α pα pα id id :=
assume a b, iff.intro (λx, x) (λx, x)
protected lemma compose [preorder α] [preorder β] [preorder γ]
(l1 : α → β) (u1 : β → α) (l2 : β → γ) (u2 : γ → β)
(gc1 : galois_connection l1 u1) (gc2 : galois_connection l2 u2) :
galois_connection (l2 ∘ l1) (u1 ∘ u2) :=
by intros a b; rw [gc2, gc1]
protected lemma dual [pα : preorder α] [pβ : preorder β]
{l : α → β} {u : β → α} (gc : galois_connection l u) :
@galois_connection (order_dual β) (order_dual α) _ _ u l :=
assume a b, (gc _ _).symm
protected lemma dfun {ι : Type u} {α : ι → Type v} {β : ι → Type w}
[∀i, preorder (α i)] [∀i, preorder (β i)]
(l : Πi, α i → β i) (u : Πi, β i → α i) (gc : ∀i, galois_connection (l i) (u i)) :
@galois_connection (Π i, α i) (Π i, β i) _ _ (λa i, l i (a i)) (λb i, u i (b i)) :=
assume a b, forall_congr $ assume i, gc i (a i) (b i)
end constructions
end galois_connection
namespace nat
lemma galois_connection_mul_div {k : ℕ} (h : 0 < k) : galois_connection (λn, n * k) (λn, n / k) :=
assume x y, (le_div_iff_mul_le x y h).symm
end nat
/-- A Galois insertion is a Galois connection where `l ∘ u = id`. It also contains a constructive
choice function, to give better definitional equalities when lifting order structures. Dual
to `galois_coinsertion` -/
@[nolint has_inhabited_instance]
structure galois_insertion {α β : Type*} [preorder α] [preorder β] (l : α → β) (u : β → α) :=
(choice : Πx:α, u (l x) ≤ x → β)
(gc : galois_connection l u)
(le_l_u : ∀x, x ≤ l (u x))
(choice_eq : ∀a h, choice a h = l a)
/-- A constructor for a Galois insertion with the trivial `choice` function. -/
def galois_insertion.monotone_intro {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α}
(hu : monotone u) (hl : monotone l) (hul : ∀ a, a ≤ u (l a)) (hlu : ∀ b, l (u b) = b) :
galois_insertion l u :=
{ choice := λ x _, l x,
gc := galois_connection.monotone_intro hu hl hul (λ b, le_of_eq (hlu b)),
le_l_u := λ b, le_of_eq $ (hlu b).symm,
choice_eq := λ _ _, rfl }
/-- Makes a Galois insertion from an order-preserving bijection. -/
protected def rel_iso.to_galois_insertion [preorder α] [preorder β] (oi : α ≃o β) :
@galois_insertion α β _ _ (oi) (oi.symm) :=
{ choice := λ b h, oi b,
gc := oi.to_galois_connection,
le_l_u := λ g, le_of_eq (oi.right_inv g).symm,
choice_eq := λ b h, rfl }
/-- Make a `galois_insertion l u` from a `galois_connection l u` such that `∀ b, b ≤ l (u b)` -/
def galois_connection.to_galois_insertion {α β : Type*} [preorder α] [preorder β]
{l : α → β} {u : β → α} (gc : galois_connection l u) (h : ∀ b, b ≤ l (u b)) :
galois_insertion l u :=
{ choice := λ x _, l x,
gc := gc,
le_l_u := h,
choice_eq := λ _ _, rfl }
/-- Lift the bottom along a Galois connection -/
def galois_connection.lift_order_bot {α β : Type*} [order_bot α] [partial_order β]
{l : α → β} {u : β → α} (gc : galois_connection l u) :
order_bot β :=
{ bot := l ⊥,
bot_le := assume b, gc.l_le $ bot_le,
.. ‹partial_order β› }
namespace galois_insertion
variables {l : α → β} {u : β → α}
lemma l_u_eq [preorder α] [partial_order β] (gi : galois_insertion l u) (b : β) :
l (u b) = b :=
le_antisymm (gi.gc.l_u_le _) (gi.le_l_u _)
lemma l_surjective [preorder α] [partial_order β] (gi : galois_insertion l u) :
surjective l :=
assume b, ⟨u b, gi.l_u_eq b⟩
lemma u_injective [preorder α] [partial_order β] (gi : galois_insertion l u) :
injective u :=
assume a b h,
calc a = l (u a) : (gi.l_u_eq a).symm
... = l (u b) : congr_arg l h
... = b : gi.l_u_eq b
lemma l_sup_u [semilattice_sup α] [semilattice_sup β] (gi : galois_insertion l u) (a b : β) :
l (u a ⊔ u b) = a ⊔ b :=
calc l (u a ⊔ u b) = l (u a) ⊔ l (u b) : gi.gc.l_sup
... = a ⊔ b : by simp only [gi.l_u_eq]
lemma l_supr_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u)
{ι : Sort x} (f : ι → β) :
l (⨆ i, u (f i)) = ⨆ i, (f i) :=
calc l (⨆ (i : ι), u (f i)) = ⨆ (i : ι), l (u (f i)) : gi.gc.l_supr
... = ⨆ (i : ι), f i : congr_arg _ $ funext $ λ i, gi.l_u_eq (f i)
lemma l_supr_of_ul_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u)
{ι : Sort x} (f : ι → α) (hf : ∀ i, u (l (f i)) = f i) :
l (⨆ i, (f i)) = ⨆ i, l (f i) :=
calc l (⨆ (i : ι), (f i)) = l ⨆ (i : ι), (u (l (f i))) : by simp [hf]
... = ⨆ (i : ι), l (f i) : gi.l_supr_u _
lemma l_inf_u [semilattice_inf α] [semilattice_inf β] (gi : galois_insertion l u) (a b : β) :
l (u a ⊓ u b) = a ⊓ b :=
calc l (u a ⊓ u b) = l (u (a ⊓ b)) : congr_arg l gi.gc.u_inf.symm
... = a ⊓ b : by simp only [gi.l_u_eq]
lemma l_infi_u [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u)
{ι : Sort x} (f : ι → β) :
l (⨅ i, u (f i)) = ⨅ i, (f i) :=
calc l (⨅ (i : ι), u (f i)) = l (u (⨅ (i : ι), (f i))) : congr_arg l gi.gc.u_infi.symm
... = ⨅ (i : ι), f i : gi.l_u_eq _
lemma l_infi_of_ul_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_insertion l u)
{ι : Sort x} (f : ι → α) (hf : ∀ i, u (l (f i)) = f i) :
l (⨅ i, (f i)) = ⨅ i, l (f i) :=
calc l (⨅ i, (f i)) = l ⨅ (i : ι), (u (l (f i))) : by simp [hf]
... = ⨅ i, l (f i) : gi.l_infi_u _
lemma u_le_u_iff [preorder α] [preorder β] (gi : galois_insertion l u) {a b} :
u a ≤ u b ↔ a ≤ b :=
⟨λ h, le_trans (gi.le_l_u _) (gi.gc.l_le h),
λ h, gi.gc.monotone_u h⟩
lemma strict_mono_u [preorder α] [partial_order β] (gi : galois_insertion l u) : strict_mono u :=
strict_mono_of_le_iff_le $ λ _ _, gi.u_le_u_iff.symm
section lift
variables [partial_order β]
/-- Lift the suprema along a Galois insertion -/
def lift_semilattice_sup [semilattice_sup α] (gi : galois_insertion l u) : semilattice_sup β :=
{ sup := λa b, l (u a ⊔ u b),
le_sup_left := assume a b, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_sup_left,
le_sup_right := assume a b, le_trans (gi.le_l_u b) $ gi.gc.monotone_l $ le_sup_right,
sup_le := assume a b c hac hbc, gi.gc.l_le $ sup_le (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc),
.. ‹partial_order β› }
/-- Lift the infima along a Galois insertion -/
def lift_semilattice_inf [semilattice_inf α] (gi : galois_insertion l u) : semilattice_inf β :=
{ inf := λa b, gi.choice (u a ⊓ u b) $
(le_inf (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_left) (gi.gc.monotone_u $ gi.gc.l_le $ inf_le_right)),
inf_le_left := by simp only [gi.choice_eq]; exact assume a b, gi.gc.l_le inf_le_left,
inf_le_right := by simp only [gi.choice_eq]; exact assume a b, gi.gc.l_le inf_le_right,
le_inf := by simp only [gi.choice_eq]; exact assume a b c hac hbc,
le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_inf (gi.gc.monotone_u hac) (gi.gc.monotone_u hbc),
.. ‹partial_order β› }
/-- Lift the suprema and infima along a Galois insertion -/
def lift_lattice [lattice α] (gi : galois_insertion l u) : lattice β :=
{ .. gi.lift_semilattice_sup, .. gi.lift_semilattice_inf }
/-- Lift the top along a Galois insertion -/
def lift_order_top [order_top α] (gi : galois_insertion l u) : order_top β :=
{ top := gi.choice ⊤ $ le_top,
le_top := by simp only [gi.choice_eq]; exact assume b, le_trans (gi.le_l_u b) (gi.gc.monotone_l le_top),
.. ‹partial_order β› }
/-- Lift the top, bottom, suprema, and infima along a Galois insertion -/
def lift_bounded_lattice [bounded_lattice α] (gi : galois_insertion l u) : bounded_lattice β :=
{ .. gi.lift_lattice, .. gi.lift_order_top, .. gi.gc.lift_order_bot }
/-- Lift all suprema and infima along a Galois insertion -/
def lift_complete_lattice [complete_lattice α] (gi : galois_insertion l u) : complete_lattice β :=
{ Sup := λs, l (⨆ b∈s, u b),
Sup_le := assume s a hs, gi.gc.l_le $ supr_le $ assume b, supr_le $ assume hb, gi.gc.monotone_u $ hs _ hb,
le_Sup := assume s a ha, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_supr_of_le a $ le_supr_of_le ha $ le_refl _,
Inf := λs, gi.choice (⨅ b∈s, u b) $ le_infi $ assume b, le_infi $ assume hb,
gi.gc.monotone_u $ gi.gc.l_le $ infi_le_of_le b $ infi_le_of_le hb $ le_refl _,
Inf_le := by simp only [gi.choice_eq]; exact
assume s a ha, gi.gc.l_le $ infi_le_of_le a $ infi_le_of_le ha $ le_refl _,
le_Inf := by simp only [gi.choice_eq]; exact
assume s a hs, le_trans (gi.le_l_u a) $ gi.gc.monotone_l $ le_infi $ assume b,
show u a ≤ ⨅ (H : b ∈ s), u b, from le_infi $ assume hb, gi.gc.monotone_u $ hs _ hb,
.. gi.lift_bounded_lattice }
end lift
end galois_insertion
/-- A Galois coinsertion is a Galois connection where `u ∘ l = id`. It also contains a constructive
choice function, to give better definitional equalities when lifting order structures. Dual to
`galois_insertion` -/
@[nolint has_inhabited_instance]
structure galois_coinsertion {α β : Type*} [preorder α] [preorder β] (l : α → β) (u : β → α) :=
(choice : Πx:β, x ≤ l (u x) → α)
(gc : galois_connection l u)
(u_l_le : ∀x, u (l x) ≤ x)
(choice_eq : ∀a h, choice a h = u a)
/-- Make a `galois_insertion u l` in the `order_dual`, from a `galois_coinsertion l u` -/
def galois_coinsertion.dual {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} :
galois_coinsertion l u → @galois_insertion (order_dual β) (order_dual α) _ _ u l :=
λ x, ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `galois_coinsertion u l` in the `order_dual`, from a `galois_insertion l u` -/
def galois_insertion.dual {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} :
galois_insertion l u → @galois_coinsertion (order_dual β) (order_dual α) _ _ u l :=
λ x, ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `galois_coinsertion l u` from a `galois_insertion l u` in the `order_dual` -/
def galois_coinsertion.of_dual {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} :
@galois_insertion (order_dual β) (order_dual α) _ _ u l → galois_coinsertion l u :=
λ x, ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Make a `galois_insertion l u` from a `galois_coinsertion l u` in the `order_dual` -/
def galois_insertion.of_dual {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α} :
@galois_coinsertion (order_dual β) (order_dual α) _ _ u l → galois_insertion l u :=
λ x, ⟨x.1, x.2.dual, x.3, x.4⟩
/-- Makes a Galois coinsertion from an order-preserving bijection. -/
protected def rel_iso.to_galois_coinsertion [preorder α] [preorder β] (oi : α ≃o β) :
@galois_coinsertion α β _ _ (oi) (oi.symm) :=
{ choice := λ b h, oi.symm b,
gc := oi.to_galois_connection,
u_l_le := λ g, le_of_eq (oi.left_inv g),
choice_eq := λ b h, rfl }
/-- A constructor for a Galois coinsertion with the trivial `choice` function. -/
def galois_coinsertion.monotone_intro {α β : Type*} [preorder α] [preorder β] {l : α → β} {u : β → α}
(hu : monotone u) (hl : monotone l) (hlu : ∀ b, l (u b) ≤ b) (hul : ∀ a, u (l a) = a) :
galois_coinsertion l u :=
galois_coinsertion.of_dual (galois_insertion.monotone_intro hl.order_dual hu.order_dual hlu hul)
/-- Make a `galois_coinsertion l u` from a `galois_connection l u` such that `∀ b, b ≤ l (u b)` -/
def galois_connection.to_galois_coinsertion {α β : Type*} [preorder α] [preorder β]
{l : α → β} {u : β → α} (gc : galois_connection l u) (h : ∀ a, u (l a) ≤ a) :
galois_coinsertion l u :=
{ choice := λ x _, u x,
gc := gc,
u_l_le := h,
choice_eq := λ _ _, rfl }
/-- Lift the top along a Galois connection -/
def galois_connection.lift_order_top {α β : Type*} [partial_order α] [order_top β]
{l : α → β} {u : β → α} (gc : galois_connection l u) :
order_top α :=
{ top := u ⊤,
le_top := assume b, gc.le_u $ le_top,
.. ‹partial_order α› }
namespace galois_coinsertion
variables {l : α → β} {u : β → α}
lemma u_l_eq [partial_order α] [preorder β] (gi : galois_coinsertion l u) (a : α) :
u (l a) = a :=
gi.dual.l_u_eq a
lemma u_surjective [partial_order α] [preorder β] (gi : galois_coinsertion l u) :
surjective u :=
gi.dual.l_surjective
lemma l_injective [partial_order α] [preorder β] (gi : galois_coinsertion l u) :
injective l :=
gi.dual.u_injective
lemma u_inf_l [semilattice_inf α] [semilattice_inf β] (gi : galois_coinsertion l u) (a b : α) :
u (l a ⊓ l b) = a ⊓ b :=
gi.dual.l_sup_u a b
lemma u_infi_l [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u)
{ι : Sort x} (f : ι → α) :
u (⨅ i, l (f i)) = ⨅ i, (f i) :=
gi.dual.l_supr_u _
lemma u_infi_of_lu_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u)
{ι : Sort x} (f : ι → β) (hf : ∀ i, l (u (f i)) = f i) :
u (⨅ i, (f i)) = ⨅ i, u (f i) :=
gi.dual.l_supr_of_ul_eq_self _ hf
lemma u_sup_l [semilattice_sup α] [semilattice_sup β] (gi : galois_coinsertion l u) (a b : α) :
u (l a ⊔ l b) = a ⊔ b :=
gi.dual.l_inf_u _ _
lemma u_supr_l [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u)
{ι : Sort x} (f : ι → α) :
u (⨆ i, l (f i)) = ⨆ i, (f i) :=
gi.dual.l_infi_u _
lemma u_supr_of_lu_eq_self [complete_lattice α] [complete_lattice β] (gi : galois_coinsertion l u)
{ι : Sort x} (f : ι → β) (hf : ∀ i, l (u (f i)) = f i) :
u (⨆ i, (f i)) = ⨆ i, u (f i) :=
gi.dual.l_infi_of_ul_eq_self _ hf
lemma l_le_l_iff [preorder α] [preorder β] (gi : galois_coinsertion l u) {a b} :
l a ≤ l b ↔ a ≤ b :=
gi.dual.u_le_u_iff
lemma strict_mono_l [partial_order α] [preorder β] (gi : galois_coinsertion l u) : strict_mono l :=
λ a b h, gi.dual.strict_mono_u h
section lift
variables [partial_order α]
/-- Lift the infima along a Galois coinsertion -/
def lift_semilattice_inf [semilattice_inf β] (gi : galois_coinsertion l u) : semilattice_inf α :=
{ inf := λa b, u (l a ⊓ l b),
inf_le_left := assume a b, le_trans (gi.gc.monotone_u $ inf_le_left) (gi.u_l_le a),
inf_le_right := assume a b, le_trans (gi.gc.monotone_u $ inf_le_right) (gi.u_l_le b),
le_inf := assume a b c hac hbc, gi.gc.le_u $ le_inf (gi.gc.monotone_l hac) (gi.gc.monotone_l hbc),
.. ‹partial_order α› }
/-- Lift the suprema along a Galois coinsertion -/
def lift_semilattice_sup [semilattice_sup β] (gi : galois_coinsertion l u) : semilattice_sup α :=
{ sup := λa b, gi.choice (l a ⊔ l b) $
(sup_le (gi.gc.monotone_l $ gi.gc.le_u $ le_sup_left) (gi.gc.monotone_l $ gi.gc.le_u $ le_sup_right)),
le_sup_left := by simp only [gi.choice_eq]; exact assume a b, gi.gc.le_u le_sup_left,
le_sup_right := by simp only [gi.choice_eq]; exact assume a b, gi.gc.le_u le_sup_right,
sup_le := by simp only [gi.choice_eq]; exact assume a b c hac hbc,
le_trans (gi.gc.monotone_u $ sup_le (gi.gc.monotone_l hac) (gi.gc.monotone_l hbc)) (gi.u_l_le c),
.. ‹partial_order α› }
/-- Lift the suprema and infima along a Galois coinsertion -/
def lift_lattice [lattice β] (gi : galois_coinsertion l u) : lattice α :=
{ .. gi.lift_semilattice_sup, .. gi.lift_semilattice_inf }
/-- Lift the bot along a Galois coinsertion -/
def lift_order_bot [order_bot β] (gi : galois_coinsertion l u) : order_bot α :=
{ bot := gi.choice ⊥ $ bot_le,
bot_le := by simp only [gi.choice_eq]; exact assume b, le_trans (gi.gc.monotone_u bot_le) (gi.u_l_le b),
.. ‹partial_order α› }
/-- Lift the top, bottom, suprema, and infima along a Galois coinsertion -/
def lift_bounded_lattice [bounded_lattice β] (gi : galois_coinsertion l u) : bounded_lattice α :=
{ .. gi.lift_lattice, .. gi.lift_order_bot, .. gi.gc.lift_order_top }
/-- Lift all suprema and infima along a Galois coinsertion -/
def lift_complete_lattice [complete_lattice β] (gi : galois_coinsertion l u) : complete_lattice α :=
{ Inf := λs, u (⨅ a∈s, l a),
le_Inf := assume s a hs, gi.gc.le_u $ le_infi $ assume b, le_infi $ assume hb, gi.gc.monotone_l $ hs _ hb,
Inf_le := assume s a ha, le_trans (gi.gc.monotone_u $ infi_le_of_le a $
infi_le_of_le ha $ le_refl _) (gi.u_l_le a),
Sup := λs, gi.choice (⨆ a∈s, l a) $ supr_le $ assume b, supr_le $ assume hb,
gi.gc.monotone_l $ gi.gc.le_u $ le_supr_of_le b $ le_supr_of_le hb $ le_refl _,
le_Sup := by simp only [gi.choice_eq]; exact
assume s a ha, gi.gc.le_u $ le_supr_of_le a $ le_supr_of_le ha $ le_refl _,
Sup_le := by simp only [gi.choice_eq]; exact
assume s a hs, le_trans (gi.gc.monotone_u $ supr_le $ assume b,
show (⨆ (hb : b ∈ s), l b) ≤ l a, from supr_le $ assume hb, gi.gc.monotone_l $ hs b hb)
(gi.u_l_le a),
.. gi.lift_bounded_lattice }
end lift
end galois_coinsertion
/-- If `α` is a partial order with bottom element (e.g., `ℕ`, `ℝ≥0`), then
`λ o : with_bot α, o.get_or_else ⊥` and coercion form a Galois insertion. -/
def with_bot.gi_get_or_else_bot [order_bot α] :
galois_insertion (λ o : with_bot α, o.get_or_else ⊥) coe :=
{ gc := λ a b, with_bot.get_or_else_bot_le_iff,
le_l_u := λ a, le_rfl,
choice := λ o ho, _,
choice_eq := λ _ _, rfl }
|
09baf24eb8e439d53ab9948e7d7a51a683f90b43 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/order/liminf_limsup.lean | fe9695149baaab7cef336f62c8c17a10f6ee7345 | [
"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 | 16,581 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl
Defines the Liminf/Limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `f.Limsup` (`f.Liminf`) where `f` is a filter taking values in a conditionally complete
lattice. `f.Limsup` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`f.Liminf`). To work with the Limsup along a function `u` use `(f.map u).Limsup`.
Usually, one defines the Limsup as `Inf (Sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `Inf_n (Sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `Limsup (λx, 1/x)` on ℝ. Then
there is no guarantee that the quantity above really decreases (the value of the `Sup` beforehand is
not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not
use this `Inf Sup ...` definition in conditionally complete lattices, and one has to use the
following less tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
We use cLimsup in theorems in conditionally complete lattices, and Limsup for the corresponding
theorems in complete lattices (usually with less assumptions).
-/
import order.filter order.conditionally_complete_lattice order.bounds
open lattice filter set
variables {α : Type*} {β : Type*}
namespace filter
section relation
/-- `f.is_bounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def is_bounded (r : α → α → Prop) (f : filter α) := ∃b, {x | r x b} ∈ f.sets
def is_bounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_bounded r
variables {r : α → α → Prop} {f g : filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
lemma is_bounded_iff : f.is_bounded r ↔ (∃s∈f.sets, ∃b, s ⊆ {x | r x b}) :=
iff.intro
(assume ⟨b, hb⟩, ⟨{a | r a b}, hb, b, subset.refl _⟩)
(assume ⟨s, hs, b, hb⟩, ⟨b, mem_sets_of_superset hs hb⟩)
/-- A bounded function `u` is in particular eventually bounded. -/
lemma is_bounded_under_of {f : filter β} {u : β → α} :
(∃b, ∀x, r (u x) b) → f.is_bounded_under r u
| ⟨b, hb⟩ := ⟨b, show {x | r (u x) b} ∈ f.sets, from univ_mem_sets' hb⟩
lemma is_bounded_bot : is_bounded r ⊥ ↔ nonempty α :=
by simp [is_bounded, exists_true_iff_nonempty]
lemma is_bounded_top : is_bounded r ⊤ ↔ (∃t, ∀x, r x t) :=
by simp [is_bounded, eq_univ_iff_forall]
lemma is_bounded_principal (s : set α) : is_bounded r (principal s) ↔ (∃t, ∀x∈s, r x t) :=
by simp [is_bounded, subset_def]
lemma is_bounded_sup [is_trans α r] (hr : ∀b₁ b₂, ∃b, r b₁ b ∧ r b₂ b) :
is_bounded r f → is_bounded r g → is_bounded r (f ⊔ g)
| ⟨b₁, h₁⟩ ⟨b₂, h₂⟩ := let ⟨b, rb₁b, rb₂b⟩ := hr b₁ b₂ in
⟨b, mem_sup_sets.2 ⟨
mem_sets_of_superset h₁ $ assume x rxb₁, show r x b, from trans rxb₁ rb₁b,
mem_sets_of_superset h₂ $ assume x rxb₂, show r x b, from trans rxb₂ rb₂b⟩⟩
lemma is_bounded_of_le (h : f ≤ g) : is_bounded r g → is_bounded r f
| ⟨b, hb⟩ := ⟨b, h hb⟩
lemma is_bounded_under_of_is_bounded {q : β → β → Prop} {u : α → β}
(hf : ∀a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.is_bounded r → f.is_bounded_under q u
| ⟨b, h⟩ := ⟨u b, show {x : α | q (u x) (u b)} ∈ f.sets, from mem_sets_of_superset h $ assume a, hf _ _⟩
/-- `is_cobounded (≺) f` states that filter `f` is not tend to infinite w.r.t. `≺`. This is also
called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.is_cobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀a, {n | a ≤ n} ∈ f.sets`
would not work as well in this case.
-/
def is_cobounded (r : α → α → Prop) (f : filter α) := ∃b, ∀a, {x | r x a} ∈ f.sets → r b a
def is_cobounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_cobounded r
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter.-/
lemma is_cobounded.mk [is_trans α r] (a : α) (h : ∀s∈f.sets, ∃x∈s, r a x) : f.is_cobounded r :=
⟨a, assume y s, let ⟨x, h₁, h₂⟩ := h _ s in trans h₂ h₁⟩
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
lemma is_cobounded_of_is_bounded [is_trans α r] (hf : f ≠ ⊥) :
f.is_bounded r → f.is_cobounded (flip r)
| ⟨a, ha⟩ := ⟨a, assume b hb,
have {x : α | r x a ∧ r b x} ∈ f.sets, from inter_mem_sets ha hb,
let ⟨x, rxa, rbx⟩ := inhabited_of_mem_sets hf this in
show r b a, from trans rbx rxa⟩
lemma is_cobounded_bot : is_cobounded r ⊥ ↔ (∃b, ∀x, r b x) :=
by simp [is_cobounded]
lemma is_cobounded_top : is_cobounded r ⊤ ↔ nonempty α :=
by simp [is_cobounded, eq_univ_iff_forall, exists_true_iff_nonempty] {contextual := tt}
lemma is_cobounded_principal (s : set α) :
(principal s).is_cobounded r↔ (∃b, ∀a, (∀x∈s, r x a) → r b a) :=
by simp [is_cobounded, subset_def]
lemma is_cobounded_of_le (h : f ≤ g) : f.is_cobounded r → g.is_cobounded r
| ⟨b, hb⟩ := ⟨b, assume a ha, hb a (h ha)⟩
end relation
instance is_trans_le [preorder α] : is_trans α (≤) := ⟨assume a b c, le_trans⟩
instance is_trans_ge [preorder α] : is_trans α (≥) := ⟨assume a b c h₁ h₂, le_trans h₂ h₁⟩
lemma is_cobounded_le_of_bot [order_bot α] {f : filter α} : f.is_cobounded (≤) :=
⟨⊥, assume a h, bot_le⟩
lemma is_cobounded_ge_of_top [order_top α] {f : filter α} : f.is_cobounded (≥) :=
⟨⊤, assume a h, le_top⟩
lemma is_bounded_le_of_top [order_top α] {f : filter α} : f.is_bounded (≤) :=
⟨⊤, univ_mem_sets' $ assume a, le_top⟩
lemma is_bounded_ge_of_bot [order_bot α] {f : filter α} : f.is_bounded (≥) :=
⟨⊥, univ_mem_sets' $ assume a, bot_le⟩
lemma is_bounded_under_sup [semilattice_sup α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≤) u → f.is_bounded_under (≤) v → f.is_bounded_under (≤) (λa, u a ⊔ v a)
| ⟨bu, (hu : {x | u x ≤ bu} ∈ f.sets)⟩ ⟨bv, (hv : {x | v x ≤ bv} ∈ f.sets)⟩ :=
⟨bu ⊔ bv, show {x | u x ⊔ v x ≤ bu ⊔ bv} ∈ f.sets,
by filter_upwards [hu, hv] assume x, sup_le_sup⟩
lemma is_bounded_under_inf [semilattice_inf α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≥) u → f.is_bounded_under (≥) v → f.is_bounded_under (≥) (λa, u a ⊓ v a)
| ⟨bu, (hu : {x | u x ≥ bu} ∈ f.sets)⟩ ⟨bv, (hv : {x | v x ≥ bv} ∈ f.sets)⟩ :=
⟨bu ⊓ bv, show {x | u x ⊓ v x ≥ bu ⊓ bv} ∈ f.sets,
by filter_upwards [hu, hv] assume x, inf_le_inf⟩
meta def is_bounded_default : tactic unit :=
tactic.applyc ``is_cobounded_le_of_bot <|>
tactic.applyc ``is_cobounded_ge_of_top <|>
tactic.applyc ``is_bounded_le_of_top <|>
tactic.applyc ``is_bounded_ge_of_bot
section conditionally_complete_lattice
variables [conditionally_complete_lattice α]
def Limsup (f : filter α) : α := Inf {a | {n | n ≤ a} ∈ f.sets}
def Liminf (f : filter α) : α := Sup {a | {n | a ≤ n} ∈ f.sets}
def limsup (f : filter β) (u : β → α) : α := (f.map u).Limsup
def liminf (f : filter β) (u : β → α) : α := (f.map u).Liminf
section
variables {f : filter β} {u : β → α}
theorem limsup_eq : f.limsup u = Inf {a:α | {n | u n ≤ a} ∈ f.sets} := rfl
theorem liminf_eq : f.liminf u = Sup {a:α | {n | a ≤ u n} ∈ f.sets} := rfl
end
theorem Limsup_le_of_le {f : filter α} {a} :
f.is_cobounded (≤) → {n | n ≤ a} ∈ f.sets → f.Limsup ≤ a := cInf_le
theorem le_Liminf_of_le {f : filter α} {a} :
f.is_cobounded (≥) → {n | a ≤ n} ∈ f.sets → a ≤ f.Liminf := le_cSup
theorem le_Limsup_of_le {f : filter α} {a}
(hf : f.is_bounded (≤)) (h : ∀b, {n : α | n ≤ b} ∈ f.sets → a ≤ b) : a ≤ f.Limsup :=
le_cInf (ne_empty_iff_exists_mem.2 hf) h
theorem Liminf_le_of_le {f : filter α} {a}
(hf : f.is_bounded (≥)) (h : ∀b, {n : α | b ≤ n} ∈ f.sets → b ≤ a) : f.Liminf ≤ a :=
cSup_le (ne_empty_iff_exists_mem.2 hf) h
theorem Liminf_le_Limsup {f : filter α}
(hf : f ≠ ⊥) (h₁ : f.is_bounded (≤)) (h₂ : f.is_bounded (≥)) : f.Liminf ≤ f.Limsup :=
Liminf_le_of_le h₂ $ assume a₀ ha₀, le_Limsup_of_le h₁ $ assume a₁ ha₁, show a₀ ≤ a₁, from
have {b | a₀ ≤ b ∧ b ≤ a₁} ∈ f.sets, from inter_mem_sets ha₀ ha₁,
let ⟨b, hb₀, hb₁⟩ := inhabited_of_mem_sets hf this in
le_trans hb₀ hb₁
lemma Liminf_le_Liminf {f g : filter α}
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default)
(h : ∀a, {n : α | a ≤ n} ∈ f.sets → {n : α | a ≤ n} ∈ g.sets) : f.Liminf ≤ g.Liminf :=
let ⟨a, ha⟩ := hf in cSup_le_cSup hg (ne_empty_of_mem ha) h
lemma Limsup_le_Limsup {f g : filter α}
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default)
(h : ∀a, {n : α | n ≤ a} ∈ g.sets → {n : α | n ≤ a} ∈ f.sets) : f.Limsup ≤ g.Limsup :=
let ⟨a, ha⟩ := hg in cInf_le_cInf hf (ne_empty_of_mem ha) h
lemma Limsup_le_Limsup_of_le {f g : filter α} (h : f ≤ g)
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default) :
f.Limsup ≤ g.Limsup :=
Limsup_le_Limsup hf hg (assume a ha, h ha)
lemma Liminf_le_Liminf_of_le {f g : filter α} (h : g ≤ f)
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default) :
f.Liminf ≤ g.Liminf :=
Liminf_le_Liminf hf hg (assume a ha, h ha)
lemma limsup_le_limsup [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : {a | u a ≤ v a} ∈ f.sets)
(hu : f.is_cobounded_under (≤) u . is_bounded_default)
(hv : f.is_bounded_under (≤) v . is_bounded_default) :
f.limsup u ≤ f.limsup v :=
Limsup_le_Limsup hu hv $ assume b (hb : {a | v a ≤ b} ∈ f.sets), show {a | u a ≤ b} ∈ f.sets,
by filter_upwards [h, hb] assume a, le_trans
lemma liminf_le_liminf [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : {a | u a ≤ v a} ∈ f.sets)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hv : f.is_cobounded_under (≥) v . is_bounded_default) :
f.liminf u ≤ f.liminf v :=
Liminf_le_Liminf hu hv $ assume b (hb : {a | b ≤ u a} ∈ f.sets), show {a | b ≤ v a} ∈ f.sets,
by filter_upwards [hb, h] assume a, le_trans
theorem Limsup_principal {s : set α} (h : bdd_above s) (hs : s ≠ ∅) :
(principal s).Limsup = Sup s :=
by simp [Limsup]; exact cInf_lower_bounds_eq_cSup h hs
theorem Liminf_principal {s : set α} (h : bdd_below s) (hs : s ≠ ∅) :
(principal s).Liminf = Inf s :=
by simp [Liminf]; exact cSup_upper_bounds_eq_cInf h hs
end conditionally_complete_lattice
section complete_lattice
variables [complete_lattice α]
@[simp] theorem Limsup_bot : (⊥ : filter α).Limsup = ⊥ :=
bot_unique $ Inf_le $ by simp
@[simp] theorem Liminf_bot : (⊥ : filter α).Liminf = ⊤ :=
top_unique $ le_Sup $ by simp
@[simp] theorem Limsup_top : (⊤ : filter α).Limsup = ⊤ :=
top_unique $ le_Inf $
by simp [eq_univ_iff_forall]; exact assume b hb, (top_unique $ hb _)
@[simp] theorem Liminf_top : (⊤ : filter α).Liminf = ⊥ :=
bot_unique $ Sup_le $
by simp [eq_univ_iff_forall]; exact assume b hb, (bot_unique $ hb _)
lemma liminf_le_limsup {f : filter β} (hf : f ≠ ⊥) {u : β → α} : liminf f u ≤ limsup f u :=
Liminf_le_Limsup (map_ne_bot hf) is_bounded_le_of_top is_bounded_ge_of_bot
theorem Limsup_eq_infi_Sup {f : filter α} : f.Limsup = ⨅s∈f.sets, Sup s :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, Inf_le $ show {n : α | n ≤ Sup s} ∈ f.sets,
by filter_upwards [hs] assume a, le_Sup)
(le_Inf $ assume a (ha : {n : α | n ≤ a} ∈ f.sets),
infi_le_of_le _ $ infi_le_of_le ha $ Sup_le $ assume b, id)
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_infi_supr {f : filter β} {u : β → α} : f.limsup u = ⨅s∈f.sets, ⨆a∈s, u a :=
calc f.limsup u = ⨅s∈(f.map u).sets, Sup s : Limsup_eq_infi_Sup
... = ⨅s∈f.sets, ⨆a∈s, u a :
le_antisymm
(le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le (u '' s) $ infi_le_of_le (image_mem_map hs) $ le_of_eq Sup_image)
(le_infi $ assume s, le_infi $ assume (hs : u ⁻¹' s ∈ f.sets),
infi_le_of_le _ $ infi_le_of_le hs $ supr_le $ assume a, supr_le $ assume ha, le_Sup ha)
lemma limsup_eq_infi_supr_of_nat {u : ℕ → α} : limsup at_top u = ⨅n:ℕ, ⨆i≥n, u i :=
calc
limsup at_top u = ⨅s∈(@at_top ℕ _).sets, ⨆n∈s, u n : limsup_eq_infi_supr
... = ⨅n:ℕ, ⨆i≥n, u i :
le_antisymm
(le_infi $ assume n, infi_le_of_le {i | i ≥ n} $ infi_le_of_le
(begin
simp only [mem_at_top_sets, mem_set_of_eq, nonempty_of_inhabited],
use n, simp
end)
(supr_le_supr $ assume i, supr_le_supr_const (by simp)))
(le_infi $ assume s, le_infi $ assume hs,
let ⟨n, hn⟩ := mem_at_top_sets.1 hs in
infi_le_of_le n $ supr_le_supr $ assume i, supr_le_supr_const (hn i))
theorem Liminf_eq_supr_Inf {f : filter α} : f.Liminf = ⨆s∈f.sets, Inf s :=
le_antisymm
(Sup_le $ assume a (ha : {n : α | a ≤ n} ∈ f.sets),
le_supr_of_le _ $ le_supr_of_le ha $ le_Inf $ assume b, id)
(supr_le $ assume s, supr_le $ assume hs, le_Sup $ show {n : α | Inf s ≤ n} ∈ f.sets,
by filter_upwards [hs] assume a, Inf_le)
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_supr_infi {f : filter β} {u : β → α} : f.liminf u = ⨆s∈f.sets, ⨅a∈s, u a :=
calc f.liminf u = ⨆s∈(f.map u).sets, Inf s : Liminf_eq_supr_Inf
... = ⨆s∈f.sets, ⨅a∈s, u a :
le_antisymm
(supr_le $ assume s, supr_le $ assume (hs : u ⁻¹' s ∈ f.sets),
le_supr_of_le _ $ le_supr_of_le hs $ le_infi $ assume a, le_infi $ assume ha, Inf_le ha)
(supr_le $ assume s, supr_le $ assume hs,
le_supr_of_le (u '' s) $ le_supr_of_le (image_mem_map hs) $ ge_of_eq Inf_image)
lemma liminf_eq_supr_infi_of_nat {u : ℕ → α} : liminf at_top u = ⨆n:ℕ, ⨅i≥n, u i :=
calc
liminf at_top u = ⨆s∈(@at_top ℕ _).sets, ⨅n∈s, u n : liminf_eq_supr_infi
... = ⨆n:ℕ, ⨅i≥n, u i :
le_antisymm
(supr_le $ assume s, supr_le $ assume hs,
let ⟨n, hn⟩ := mem_at_top_sets.1 hs in
le_supr_of_le n $ infi_le_infi $ assume i, infi_le_infi_const (hn _) )
(supr_le $ assume n, le_supr_of_le {i | n ≤ i} $
le_supr_of_le
(begin
simp only [mem_at_top_sets, mem_set_of_eq, nonempty_of_inhabited],
use n, simp
end)
(infi_le_infi $ assume i, infi_le_infi_const (by simp)))
end complete_lattice
end filter
|
36530b7828ed1451f0d84695a7cc03dbbc281ab8 | 4bcaca5dc83d49803f72b7b5920b75b6e7d9de2d | /stage0/src/Lean/Elab/BuiltinNotation.lean | f9018b826d9b6d376752c1d32cd11f81392ce45a | [
"Apache-2.0"
] | permissive | subfish-zhou/leanprover-zh_CN.github.io | 30b9fba9bd790720bd95764e61ae796697d2f603 | 8b2985d4a3d458ceda9361ac454c28168d920d3f | refs/heads/master | 1,689,709,967,820 | 1,632,503,056,000 | 1,632,503,056,000 | 409,962,097 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,812 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Init.Data.ToString
import Lean.Compiler.BorrowedAnnotation
import Lean.Meta.KAbstract
import Lean.Meta.Transform
import Lean.Elab.Term
import Lean.Elab.SyntheticMVars
namespace Lean.Elab.Term
open Meta
@[builtinTermElab anonymousCtor] def elabAnonymousCtor : TermElab := fun stx expectedType? =>
match stx with
| `(⟨$args,*⟩) => do
tryPostponeIfNoneOrMVar expectedType?
match expectedType? with
| some expectedType =>
let expectedType ← whnf expectedType
matchConstInduct expectedType.getAppFn
(fun _ => throwError "invalid constructor ⟨...⟩, expected type must be an inductive type {indentExpr expectedType}")
(fun ival us => do
match ival.ctors with
| [ctor] =>
let cinfo ← getConstInfoCtor ctor
let numExplicitFields ← forallTelescopeReducing cinfo.type fun xs _ => do
let mut n := 0
for i in [cinfo.numParams:xs.size] do
if (← getFVarLocalDecl xs[i]).binderInfo.isExplicit then
n := n + 1
return n
let args := args.getElems
if args.size < numExplicitFields then
throwError "invalid constructor ⟨...⟩, insufficient number of arguments, constructs '{ctor}' has #{numExplicitFields} explicit fields, but only #{args.size} provided"
let newStx ←
if args.size == numExplicitFields then
`($(mkCIdentFrom stx ctor) $(args)*)
else if numExplicitFields == 0 then
throwError "invalid constructor ⟨...⟩, insufficient number of arguments, constructs '{ctor}' does not have explicit fields, but #{args.size} provided"
else
let extra := args[numExplicitFields-1:args.size]
let newLast ← `(⟨$[$extra],*⟩)
let newArgs := args[0:numExplicitFields-1].toArray.push newLast
`($(mkCIdentFrom stx ctor) $(newArgs)*)
withMacroExpansion stx newStx $ elabTerm newStx expectedType?
| _ => throwError "invalid constructor ⟨...⟩, expected type must be an inductive type with only one constructor {indentExpr expectedType}")
| none => throwError "invalid constructor ⟨...⟩, expected type must be known"
| _ => throwUnsupportedSyntax
@[builtinTermElab borrowed] def elabBorrowed : TermElab := fun stx expectedType? =>
match stx with
| `(@& $e) => return markBorrowed (← elabTerm e expectedType?)
| _ => throwUnsupportedSyntax
@[builtinMacro Lean.Parser.Term.show] def expandShow : Macro := fun stx =>
match stx with
| `(show $type from $val) => let thisId := mkIdentFrom stx `this; `(let_fun $thisId : $type := $val; $thisId)
| `(show $type by%$b $tac:tacticSeq) => `(show $type from by%$b $tac:tacticSeq)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.have] def expandHave : Macro := fun stx =>
let thisId := mkIdentFrom stx `this
match stx with
| `(have $x $bs* $[: $type]? := $val $[;]? $body) => `(let_fun $x $bs* $[: $type]? := $val; $body)
| `(have $[: $type]? := $val $[;]? $body) => `(have $thisId:ident $[: $type]? := $val; $body)
| `(have $x $bs* $[: $type]? $alts:matchAlts $[;]? $body) => `(let_fun $x $bs* $[: $type]? $alts:matchAlts; $body)
| `(have $[: $type]? $alts:matchAlts $[;]? $body) => `(have $thisId:ident $[: $type]? $alts:matchAlts; $body)
| `(have $pattern:term $[: $type]? := $val:term $[;]? $body) => `(let_fun $pattern:term $[: $type]? := $val:term ; $body)
| _ => Macro.throwUnsupported
@[builtinMacro Lean.Parser.Term.suffices] def expandSuffices : Macro
| `(suffices $[$x :]? $type from $val $[;]? $body) => `(have $[$x]? : $type := $body; $val)
| `(suffices $[$x :]? $type by%$b $tac:tacticSeq $[;]? $body) => `(have $[$x]? : $type := $body; by%$b $tac:tacticSeq)
| _ => Macro.throwUnsupported
open Lean.Parser in
private def elabParserMacroAux (prec : Syntax) (e : Syntax) : TermElabM Syntax := do
let (some declName) ← getDeclName?
| throwError "invalid `leading_parser` macro, it must be used in definitions"
match extractMacroScopes declName with
| { name := Name.str _ s _, scopes := scps, .. } =>
let kind := quote declName
let s := quote s
-- if the parser decl is hidden by hygiene, it doesn't make sense to provide an antiquotation kind
let antiquotKind ← if scps == [] then `(some $kind) else `(none)
``(withAntiquot (mkAntiquot $s $antiquotKind) (leadingNode $kind $prec $e))
| _ => throwError "invalid `leading_parser` macro, unexpected declaration name"
@[builtinTermElab «leading_parser»] def elabLeadingParserMacro : TermElab :=
adaptExpander fun stx => match stx with
| `(leading_parser $e) => elabParserMacroAux (quote Parser.maxPrec) e
| `(leading_parser : $prec $e) => elabParserMacroAux prec e
| _ => throwUnsupportedSyntax
private def elabTParserMacroAux (prec lhsPrec : Syntax) (e : Syntax) : TermElabM Syntax := do
let declName? ← getDeclName?
match declName? with
| some declName => let kind := quote declName; ``(Lean.Parser.trailingNode $kind $prec $lhsPrec $e)
| none => throwError "invalid `trailing_parser` macro, it must be used in definitions"
@[builtinTermElab «trailing_parser»] def elabTrailingParserMacro : TermElab :=
adaptExpander fun stx => match stx with
| `(trailing_parser$[:$prec?]?$[:$lhsPrec?]? $e) =>
elabTParserMacroAux (prec?.getD <| quote Parser.maxPrec) (lhsPrec?.getD <| quote 0) e
| _ => throwUnsupportedSyntax
@[builtinTermElab panic] def elabPanic : TermElab := fun stx expectedType? => do
let arg := stx[1]
let pos ← getRefPosition
let env ← getEnv
let stxNew ← match (← getDeclName?) with
| some declName => `(panicWithPosWithDecl $(quote (toString env.mainModule)) $(quote (toString declName)) $(quote pos.line) $(quote pos.column) $arg)
| none => `(panicWithPos $(quote (toString env.mainModule)) $(quote pos.line) $(quote pos.column) $arg)
withMacroExpansion stx stxNew $ elabTerm stxNew expectedType?
@[builtinMacro Lean.Parser.Term.unreachable] def expandUnreachable : Macro := fun stx =>
`(panic! "unreachable code has been reached")
@[builtinMacro Lean.Parser.Term.assert] def expandAssert : Macro := fun stx =>
-- TODO: support for disabling runtime assertions
let cond := stx[1]
let body := stx[3]
match cond.reprint with
| some code => `(if $cond then $body else panic! ("assertion violation: " ++ $(quote code)))
| none => `(if $cond then $body else panic! ("assertion violation"))
@[builtinMacro Lean.Parser.Term.dbgTrace] def expandDbgTrace : Macro := fun stx =>
let arg := stx[1]
let body := stx[3]
if arg.getKind == interpolatedStrKind then
`(dbgTrace (s! $arg) fun _ => $body)
else
`(dbgTrace (toString $arg) fun _ => $body)
@[builtinTermElab «sorry»] def elabSorry : TermElab := fun stx expectedType? => do
logWarning "declaration uses 'sorry'"
let stxNew ← `(sorryAx _ false)
withMacroExpansion stx stxNew <| elabTerm stxNew expectedType?
/-- Return syntax `Prod.mk elems[0] (Prod.mk elems[1] ... (Prod.mk elems[elems.size - 2] elems[elems.size - 1])))` -/
partial def mkPairs (elems : Array Syntax) : MacroM Syntax :=
let rec loop (i : Nat) (acc : Syntax) := do
if i > 0 then
let i := i - 1
let elem := elems[i]
let acc ← `(Prod.mk $elem $acc)
loop i acc
else
pure acc
loop (elems.size - 1) elems.back
private partial def hasCDot : Syntax → Bool
| Syntax.node k args =>
if k == ``Lean.Parser.Term.paren then false
else if k == ``Lean.Parser.Term.cdot then true
else args.any hasCDot
| _ => false
/--
Return `some` if succeeded expanding `·` notation occurring in
the given syntax. Otherwise, return `none`.
Examples:
- `· + 1` => `fun _a_1 => _a_1 + 1`
- `f · · b` => `fun _a_1 _a_2 => f _a_1 _a_2 b` -/
partial def expandCDot? (stx : Syntax) : MacroM (Option Syntax) := do
if hasCDot stx then
let (newStx, binders) ← (go stx).run #[];
`(fun $binders* => $newStx)
else
pure none
where
/--
Auxiliary function for expanding the `·` notation.
The extra state `Array Syntax` contains the new binder names.
If `stx` is a `·`, we create a fresh identifier, store in the
extra state, and return it. Otherwise, we just return `stx`. -/
go : Syntax → StateT (Array Syntax) MacroM Syntax
| stx@(Syntax.node k args) =>
if k == ``Lean.Parser.Term.paren then pure stx
else if k == ``Lean.Parser.Term.cdot then withFreshMacroScope do
let id ← `(a)
modify fun s => s.push id;
pure id
else do
let args ← args.mapM go
pure $ Syntax.node k args
| stx => pure stx
/--
Helper method for elaborating terms such as `(.+.)` where a constant name is expected.
This method is usually used to implement tactics that function names as arguments (e.g., `simp`).
-/
def elabCDotFunctionAlias? (stx : Syntax) : TermElabM (Option Expr) := do
let some stx ← liftMacroM <| expandCDotArg? stx | pure none
let stx ← liftMacroM <| expandMacros stx
match stx with
| `(fun $binders* => $f:ident $args*) =>
if binders == args then
try Term.resolveId? f catch _ => return none
else
return none
| `(fun $binders* => binop% $f:ident $a $b) =>
if binders == #[a, b] then
try Term.resolveId? f catch _ => return none
else
return none
| _ => return none
where
expandCDotArg? (stx : Syntax) : MacroM (Option Syntax) :=
match stx with
| `(($e)) => Term.expandCDot? e
| _ => Term.expandCDot? stx
/--
Try to expand `·` notation.
Recall that in Lean the `·` notation must be surrounded by parentheses.
We may change this is the future, but right now, here are valid examples
- `(· + 1)`
- `(f ⟨·, 1⟩ ·)`
- `(· + ·)`
- `(f · a b)` -/
@[builtinMacro Lean.Parser.Term.paren] def expandParen : Macro
| `(()) => `(Unit.unit)
| `(($e : $type)) => do
match (← expandCDot? e) with
| some e => `(($e : $type))
| none => Macro.throwUnsupported
| `(($e)) => return (← expandCDot? e).getD e
| `(($e, $es,*)) => do
let pairs ← mkPairs (#[e] ++ es)
(← expandCDot? pairs).getD pairs
| stx =>
if !stx[1][0].isMissing && stx[1][1].isMissing then
-- parsed `(` and `term`, assume it's a basic parenthesis to get any elaboration output at all
`(($(stx[1][0])))
else
throw <| Macro.Exception.error stx "unexpected parentheses notation"
@[builtinTermElab paren] def elabParen : TermElab := fun stx expectedType? => do
match stx with
| `(($e : $type)) =>
let type ← withSynthesize (mayPostpone := true) <| elabType type
let e ← elabTerm e type
ensureHasType type e
| _ => throwUnsupportedSyntax
@[builtinTermElab subst] def elabSubst : TermElab := fun stx expectedType? => do
let expectedType ← tryPostponeIfHasMVars expectedType? "invalid `▸` notation"
match stx with
| `($heq ▸ $h) => do
let mut heq ← elabTerm heq none
let heqType ← inferType heq
let heqType ← instantiateMVars heqType
match (← Meta.matchEq? heqType) with
| none => throwError "invalid `▸` notation, argument{indentExpr heq}\nhas type{indentExpr heqType}\nequality expected"
| some (α, lhs, rhs) =>
let mut lhs := lhs
let mut rhs := rhs
let mkMotive (typeWithLooseBVar : Expr) := do
withLocalDeclD (← mkFreshUserName `x) α fun x => do
mkLambdaFVars #[x] $ typeWithLooseBVar.instantiate1 x
let mut expectedAbst ← kabstract expectedType rhs
unless expectedAbst.hasLooseBVars do
expectedAbst ← kabstract expectedType lhs
unless expectedAbst.hasLooseBVars do
throwError "invalid `▸` notation, expected type{indentExpr expectedType}\ndoes contain equation left-hand-side nor right-hand-side{indentExpr heqType}"
heq ← mkEqSymm heq
(lhs, rhs) := (rhs, lhs)
let hExpectedType := expectedAbst.instantiate1 lhs
let h ← withRef h do
let h ← elabTerm h hExpectedType
try
ensureHasType hExpectedType h
catch ex =>
-- if `rhs` occurs in `hType`, we try to apply `heq` to `h` too
let hType ← inferType h
let hTypeAbst ← kabstract hType rhs
unless hTypeAbst.hasLooseBVars do
throw ex
let hTypeNew := hTypeAbst.instantiate1 lhs
unless (← isDefEq hExpectedType hTypeNew) do
throw ex
mkEqNDRec (← mkMotive hTypeAbst) h (← mkEqSymm heq)
mkEqNDRec (← mkMotive expectedAbst) h heq
| _ => throwUnsupportedSyntax
@[builtinTermElab stateRefT] def elabStateRefT : TermElab := fun stx _ => do
let σ ← elabType stx[1]
let mut mStx := stx[2]
if mStx.getKind == ``Lean.Parser.Term.macroDollarArg then
mStx := mStx[1]
let m ← elabTerm mStx (← mkArrow (mkSort levelOne) (mkSort levelOne))
let ω ← mkFreshExprMVar (mkSort levelOne)
let stWorld ← mkAppM ``STWorld #[ω, m]
discard <| mkInstMVar stWorld
mkAppM ``StateRefT' #[ω, σ, m]
@[builtinTermElab noindex] def elabNoindex : TermElab := fun stx expectedType? => do
let e ← elabTerm stx[1] expectedType?
return DiscrTree.mkNoindexAnnotation e
end Lean.Elab.Term
|
93aaabac4f1b6006dfb1ad7d897aa4df25a3fe1c | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/iterate_hom.lean | d7ee7dfe9d699f65439be0706595daabaab24372 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,471 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import algebra.group_power.basic
import logic.function.iterate
import group_theory.perm.basic
/-!
# Iterates of monoid and ring homomorphisms
Iterate of a monoid/ring homomorphism is a monoid/ring homomorphism but it has a wrong type, so Lean
can't apply lemmas like `monoid_hom.map_one` to `f^[n] 1`. Though it is possible to define
a monoid structure on the endomorphisms, quite often we do not want to convert from
`M →* M` to (not yet defined) `monoid.End M` and from `f^[n]` to `f^n` just to apply a simple lemma.
So, we restate standard `*_hom.map_*` lemmas under names `*_hom.iterate_map_*`.
We also prove formulas for iterates of add/mul left/right.
## Tags
homomorphism, iterate
-/
open function
variables {M : Type*} {N : Type*} {G : Type*} {H : Type*}
/-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = (⇑f^[n])`. -/
lemma hom_coe_pow {F : Type*} [monoid F] (c : F → M → M) (h1 : c 1 = id)
(hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f^[n])
| 0 := by { rw [pow_zero, h1], refl }
| (n + 1) := by rw [pow_succ, iterate_succ', hmul, hom_coe_pow]
namespace monoid_hom
section
variables [mul_one_class M] [mul_one_class N]
@[simp, to_additive]
theorem iterate_map_one (f : M →* M) (n : ℕ) : f^[n] 1 = 1 :=
iterate_fixed f.map_one n
@[simp, to_additive]
theorem iterate_map_mul (f : M →* M) (n : ℕ) (x y) :
f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=
semiconj₂.iterate f.map_mul n x y
end
variables [monoid M] [monoid N] [group G] [group H]
@[simp, to_additive]
theorem iterate_map_inv (f : G →* G) (n : ℕ) (x) :
f^[n] (x⁻¹) = (f^[n] x)⁻¹ :=
commute.iterate_left f.map_inv n x
theorem iterate_map_pow (f : M →* M) (a) (n m : ℕ) : f^[n] (a^m) = (f^[n] a)^m :=
commute.iterate_left (λ x, f.map_pow x m) n a
theorem iterate_map_zpow (f : G →* G) (a) (n : ℕ) (m : ℤ) : f^[n] (a^m) = (f^[n] a)^m :=
commute.iterate_left (λ x, f.map_zpow x m) n a
lemma coe_pow {M} [comm_monoid M] (f : monoid.End M) (n : ℕ) : ⇑(f^n) = (f^[n]) :=
hom_coe_pow _ rfl (λ f g, rfl) _ _
end monoid_hom
namespace add_monoid_hom
variables [add_monoid M] [add_monoid N] [add_group G] [add_group H]
@[simp]
theorem iterate_map_sub (f : G →+ G) (n : ℕ) (x y) :
f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=
semiconj₂.iterate f.map_sub n x y
theorem iterate_map_smul (f : M →+ M) (n m : ℕ) (x : M) :
f^[n] (m • x) = m • (f^[n] x) :=
f.to_multiplicative.iterate_map_pow x n m
theorem iterate_map_zsmul (f : G →+ G) (n : ℕ) (m : ℤ) (x : G) :
f^[n] (m • x) = m • (f^[n] x) :=
f.to_multiplicative.iterate_map_zpow x n m
end add_monoid_hom
namespace ring_hom
section semiring
variables {R : Type*} [semiring R] (f : R →+* R) (n : ℕ) (x y : R)
lemma coe_pow (n : ℕ) : ⇑(f^n) = (f^[n]) :=
hom_coe_pow _ rfl (λ f g, rfl) f n
theorem iterate_map_one : f^[n] 1 = 1 := f.to_monoid_hom.iterate_map_one n
theorem iterate_map_zero : f^[n] 0 = 0 := f.to_add_monoid_hom.iterate_map_zero n
theorem iterate_map_add : f^[n] (x + y) = (f^[n] x) + (f^[n] y) :=
f.to_add_monoid_hom.iterate_map_add n x y
theorem iterate_map_mul : f^[n] (x * y) = (f^[n] x) * (f^[n] y) :=
f.to_monoid_hom.iterate_map_mul n x y
theorem iterate_map_pow (a) (n m : ℕ) : f^[n] (a^m) = (f^[n] a)^m :=
f.to_monoid_hom.iterate_map_pow a n m
theorem iterate_map_smul (n m : ℕ) (x : R) :
f^[n] (m • x) = m • (f^[n] x) :=
f.to_add_monoid_hom.iterate_map_smul n m x
end semiring
variables {R : Type*} [ring R] (f : R →+* R) (n : ℕ) (x y : R)
theorem iterate_map_sub : f^[n] (x - y) = (f^[n] x) - (f^[n] y) :=
f.to_add_monoid_hom.iterate_map_sub n x y
theorem iterate_map_neg : f^[n] (-x) = -(f^[n] x) :=
f.to_add_monoid_hom.iterate_map_neg n x
theorem iterate_map_zsmul (n : ℕ) (m : ℤ) (x : R) :
f^[n] (m • x) = m • (f^[n] x) :=
f.to_add_monoid_hom.iterate_map_zsmul n m x
end ring_hom
lemma equiv.perm.coe_pow {α : Type*} (f : equiv.perm α) (n : ℕ) : ⇑(f ^ n) = (f^[n]) :=
hom_coe_pow _ rfl (λ _ _, rfl) _ _
--what should be the namespace for this section?
section monoid
variables [monoid G] (a : G) (n : ℕ)
@[simp, to_additive] lemma mul_left_iterate : ((*) a)^[n] = (*) (a^n) :=
nat.rec_on n (funext $ λ x, by simp) $ λ n ihn,
funext $ λ x, by simp [iterate_succ, ihn, pow_succ', mul_assoc]
@[simp, to_additive] lemma mul_right_iterate : (* a)^[n] = (* a ^ n) :=
begin
induction n with d hd,
{ simpa },
{ simp [← pow_succ, hd] }
end
@[to_additive]
lemma mul_right_iterate_apply_one : (* a)^[n] 1 = a ^ n :=
by simp [mul_right_iterate]
end monoid
section semigroup
variables [semigroup G] {a b c : G}
@[to_additive]
lemma semiconj_by.function_semiconj_mul_left (h : semiconj_by a b c) :
function.semiconj ((*)a) ((*)b) ((*)c) :=
λ j, by rw [← mul_assoc, h.eq, mul_assoc]
@[to_additive]
lemma commute.function_commute_mul_left (h : commute a b) :
function.commute ((*)a) ((*)b) :=
semiconj_by.function_semiconj_mul_left h
@[to_additive]
lemma semiconj_by.function_semiconj_mul_right_swap (h : semiconj_by a b c) :
function.semiconj (*a) (*c) (*b) :=
λ j, by simp_rw [mul_assoc, ← h.eq]
@[to_additive]
lemma commute.function_commute_mul_right (h : commute a b) :
function.commute (*a) (*b) :=
semiconj_by.function_semiconj_mul_right_swap h
end semigroup
|
dfda8106aa0ff8199d8a8849a2351ec0aec0aaa9 | 8930e38ac0fae2e5e55c28d0577a8e44e2639a6d | /analysis/topology/topological_space.lean | e2a0ae1d52dae27d21f17d8b1fb966af10af2d37 | [
"Apache-2.0"
] | permissive | SG4316/mathlib | 3d64035d02a97f8556ad9ff249a81a0a51a3321a | a7846022507b531a8ab53b8af8a91953fceafd3a | refs/heads/master | 1,584,869,960,527 | 1,530,718,645,000 | 1,530,724,110,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 56,082 | 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
Theory of topological spaces.
Parts of the formalization is based on the books:
N. Bourbaki: General Topology
I. M. James: Topologies and Uniformities
A major difference is that this formalization is heavily based on the filter library.
-/
import order.filter data.set.countable tactic
open set filter lattice classical
local attribute [instance] prop_decidable
universes u v w
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
section topological_space
variables {α : Type u} {β : Type v} {ι : Sort w} {a a₁ a₂ : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop}
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
variables [topological_space α]
lemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) :=
have (⋃₀ {s₁, s₂}) = (s₁ ∪ s₂), by simp [union_comm],
this ▸ is_open_sUnion $ show ∀(t : set α), t ∈ ({s₁, s₂} : set (set α)) → is_open t,
by finish
lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) :=
is_open_sUnion $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ 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
@[simp] lemma is_open_empty : is_open (∅ : set α) :=
have is_open (⋃₀ ∅ : set α), from is_open_sUnion (assume a, false.elim),
by simp at this; assumption
lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) :=
finite.induction_on hs (by simp) $ λ a s has hs ih h, begin
suffices : is_open (a ∩ ⋂₀ s), { simpa },
exact is_open_inter (h _ $ mem_insert _ _) (ih $ assume t ht, h _ $ mem_insert_of_mem _ ht)
end
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 simp)
(by simp [or_imp_distrib, _root_.is_open_inter, forall_and_distrib] {contextual := tt})
lemma is_open_const {p : Prop} : is_open {a : α | p} :=
by_cases
(assume : p, begin simp [*]; exact is_open_univ end)
(assume : ¬ p, begin simp [*]; 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 -/
def is_closed (s : set α) : Prop := is_open (-s)
@[simp] lemma is_closed_empty : is_closed (∅ : set α) := by simp [is_closed]
@[simp] lemma is_closed_univ : is_closed (univ : set α) := by simp [is_closed]
lemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) :=
by simp [is_closed]; exact is_open_inter
lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) :=
by simp [is_closed, compl_sInter]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht
lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) :=
is_closed_sInter $ assume t ⟨i, (heq : t = f i)⟩, heq.symm ▸ h i
@[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl
@[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_diff {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_closed, compl_inter]; exact is_open_union h₁ h₂
lemma is_closed_Union {s : set β} {f : β → set α} (hs : finite s) :
(∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) :=
finite.induction_on hs
(by simp)
(by simp [or_imp_distrib, is_closed_union, forall_and_distrib] {contextual := tt})
lemma is_closed_imp [topological_space α] {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 $ by finish,
by rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq
lemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} :=
is_open_compl_iff.mpr
/-- 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 [interior, and_comm, 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 interior_eq_of_open {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, interior_eq_of_open⟩
lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s :=
by simp [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset]
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 α) = ∅ :=
interior_eq_of_open is_open_empty
@[simp] lemma interior_univ : interior (univ : set α) = univ :=
interior_eq_of_open is_open_univ
@[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s :=
interior_eq_of_open is_open_interior
@[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) $ by simp [is_open_inter])
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 simp [subset_interior_iff_subset_of_open, this, is_open_diff hu₁ h₁],
have u - s ⊆ ∅,
by rw [h₂] at this; assumption,
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 [subset_def, mem_interior]
/-- 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 closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s :=
subset.antisymm (closure_minimal (subset.refl s) h) subset_closure
lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s :=
⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩
lemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) :
closure s ⊆ t ↔ s ⊆ t :=
⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩
lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t :=
closure_minimal (subset.trans h subset_closure) is_closed_closure
@[simp] lemma closure_empty : closure (∅ : set α) = ∅ :=
closure_eq_of_is_closed is_closed_empty
@[simp] lemma closure_univ : closure (univ : set α) = univ :=
closure_eq_of_is_closed is_closed_univ
@[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s :=
closure_eq_of_is_closed is_closed_closure
@[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) $ by simp [is_closed_union])
(union_subset (closure_mono $ subset_union_left _ _) (closure_mono $ subset_union_right _ _))
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
simp [interior, closure],
rw [compl_sUnion, compl_image_set_of],
simp [compl_subset_compl_iff_subset]
end
@[simp] lemma interior_compl_eq {s : set α} : interior (- s) = - closure s :=
by simp [closure_eq_compl_interior_compl]
@[simp] lemma closure_compl_eq {s : set α} : closure (- s) = - interior s :=
by simp [closure_eq_compl_interior_compl]
lemma closure_compl {s : set α} : closure (-s) = - interior s :=
subset.antisymm
(by simp [closure_subset_iff_subset_of_is_closed, compl_subset_compl_iff_subset, subset.refl])
begin
rw [←compl_subset_compl_iff_subset, compl_compl, subset_interior_iff_subset_of_open,
←compl_subset_compl_iff_subset, compl_compl],
exact subset_closure,
exact is_open_compl_iff.mpr is_closed_closure
end
lemma interior_compl {s : set α} : interior (-s) = - closure s :=
calc interior (- s) = - - interior (- s) : by simp
... = - closure (- (- s)) : by rw [closure_compl]
... = - closure s : by simp
theorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → o ∩ s ≠ ∅ :=
⟨λ h o oo ao os,
have s ⊆ -o, from λ x xs xo, @ne_empty_of_mem α (o∩s) x ⟨xo, xs⟩ os,
closure_minimal this (is_closed_compl_iff.2 oo) h ao,
λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc,
let ⟨x, hc, hs⟩ := exists_mem_of_ne_empty (H _ h₁ nc) in hc (h₂ hs)⟩
/-- 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, sdiff_eq]
/-- neighbourhood filter -/
def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s)
lemma tendsto_nhds {m : β → α} {f : filter β} (h : ∀s, a ∈ s → is_open s → m ⁻¹' s ∈ f.sets) :
tendsto m f (nhds a) :=
show map m f ≤ (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s),
from le_infi $ assume s, le_infi $ assume ⟨ha, hs⟩, le_principal_iff.mpr $ h s ha hs
lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (nhds a) :=
tendsto_nhds $ assume s ha hs, univ_mem_sets' $ assume _, ha
lemma nhds_sets {a : α} : (nhds a).sets = {s | ∃t⊆s, is_open t ∧ a ∈ t} :=
calc (nhds a).sets = (⋃s∈{s : set α| a ∈ s ∧ is_open s}, (principal s).sets) : infi_sets_eq'
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,
⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp⟩)
⟨univ, by simp⟩
... = {s | ∃t⊆s, is_open t ∧ a ∈ t} :
le_antisymm
(supr_le $ assume i, supr_le $ assume ⟨hi₁, hi₂⟩ t ht, ⟨i, ht, hi₂, hi₁⟩)
(assume t ⟨i, hi₁, hi₂, hi₃⟩, by simp; exact ⟨i, ⟨hi₃, hi₂⟩, hi₁⟩)
lemma map_nhds {a : α} {f : α → β} :
map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) :=
calc map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, map f (principal s)) :
map_binfi_eq
(assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩,
⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, by simp⟩)
⟨univ, by simp⟩
... = _ : by simp
lemma mem_nhds_sets_iff {a : α} {s : set α} :
s ∈ (nhds a).sets ↔ ∃t⊆s, is_open t ∧ a ∈ t :=
by simp [nhds_sets]
lemma mem_of_nhds {a : α} {s : set α} : s ∈ (nhds a).sets → a ∈ s :=
by simp [mem_nhds_sets_iff]; exact assume t ht _ hs, ht hs
lemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) :
s ∈ (nhds a).sets :=
by simp [nhds_sets]; exact ⟨s, subset.refl _, hs, ha⟩
lemma return_le_nhds : return ≤ (nhds : α → filter α) :=
assume a, le_infi $ assume s, le_infi $ assume ⟨h₁, _⟩, principal_mono.mpr $ by simp [h₁]
@[simp] lemma nhds_neq_bot {a : α} : nhds a ≠ ⊥ :=
assume : nhds a = ⊥,
have return a = (⊥ : filter α),
from lattice.bot_unique $ this ▸ return_le_nhds a,
pure_neq_bot this
lemma interior_eq_nhds {s : set α} : interior s = {a | nhds a ≤ principal s} :=
set.ext $ by simp [mem_interior, nhds_sets]
lemma mem_interior_iff_mem_nhds {s : set α} {a : α} :
a ∈ interior s ↔ s ∈ (nhds a).sets :=
by simp [interior_eq_nhds]
lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, nhds a ≤ principal s :=
calc is_open s ↔ interior s = s : by rw [interior_eq_iff_open]
... ↔ s ⊆ interior s : ⟨assume h, by simp [*, subset.refl], subset.antisymm interior_subset⟩
... ↔ (∀a∈s, nhds a ≤ principal s) : by rw [interior_eq_nhds]; refl
lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ (nhds a).sets :=
by simpa using @is_open_iff_nhds α _ _
lemma closure_eq_nhds {s : set α} : closure s = {a | nhds a ⊓ principal s ≠ ⊥} :=
calc closure s = - interior (- s) : closure_eq_compl_interior_compl
... = {a | ¬ nhds a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl
... = {a | nhds a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr
(inf_eq_bot_iff_le_compl
(show principal s ⊔ principal (-s) = ⊤, by simp [principal_univ])
(by simp)).symm
theorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ (nhds a).sets, t ∩ s ≠ ∅ :=
mem_closure_iff.trans
⟨λ H t ht, subset_ne_empty
(inter_subset_inter_right _ interior_subset)
(H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)),
λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩
lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s :=
calc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed]
... ↔ closure s ⊆ s : ⟨assume h, by simp [*, subset.refl], assume h, subset.antisymm h subset_closure⟩
... ↔ (∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl
lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) :=
assume a ⟨hs, ht⟩,
have s ∈ (nhds a).sets, from mem_nhds_sets h hs,
have nhds a ⊓ principal s = nhds a, from inf_of_le_left $ by simp [this],
have nhds a ⊓ principal (s ∩ t) ≠ ⊥,
from calc nhds a ⊓ principal (s ∩ t) = nhds a ⊓ (principal s ⊓ principal t) : by simp
... = nhds a ⊓ principal t : by rw [←inf_assoc, this]
... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption,
by rw [closure_eq_nhds]; assumption
lemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) :=
calc closure s \ closure t = (- closure t) ∩ closure s : by simp [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 [diff_eq, inter_comm]
... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure
lemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α}
(hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b.sets) : a ∈ s :=
have b.map f ≤ nhds a ⊓ principal s,
from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf hf (le_refl _)),
is_closed_iff_nhds.mp hs a $ neq_bot_of_le_neq_bot (map_ne_bot hb) this
lemma mem_closure_of_tendsto {f : β → α} {x : filter β} {a : α} {s : set α}
(hf : tendsto f x (nhds a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s :=
is_closed_iff_nhds.mp hs _ $ neq_bot_of_le_neq_bot (@map_ne_bot _ _ _ f h) $
le_inf (le_trans (map_mono $ inf_le_left) hf) $
le_trans (map_mono $ inf_le_right_of_le $ by simp; exact subset.refl _) (@map_vmap_le _ _ _ f)
/- 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∈(nhds x).sets, finite {i | f i ∩ t ≠ ∅ }
lemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f :=
assume x, ⟨univ, univ_mem_sets, finite_subset h $ by simp⟩
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₁, finite_subset ht₂ $ assume i hi,
neq_bot_of_le_neq_bot hi $ inter_subset_inter (hf i) $ subset.refl _⟩
lemma is_closed_Union_of_locally_finite {f : β → set α}
(h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) :=
is_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i),
have ∀i, a ∈ -f i,
from assume i hi, by simp at h; exact h i hi,
have ∀i, - f i ∈ (nhds a).sets,
by rw [nhds_sets]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩,
let ⟨t, h_sets, (h_fin : finite {i | f i ∩ t ≠ ∅ })⟩ := h₁ a in
calc nhds a ≤ principal (t ∩ (⋂ i∈{i | f i ∩ t ≠ ∅ }, - f i)) :
begin
rw [le_principal_iff],
apply @filter.inter_mem_sets _ (nhds a) _ _ h_sets,
apply @filter.Inter_mem_sets _ (nhds a) _ _ _ h_fin,
exact assume i h, this i
end
... ≤ principal (- ⋃i, f i) :
begin
simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq,
mem_Inter_eq, mem_set_of_eq, mem_Union_eq, and_imp, not_exists,
not_eq_empty_iff_exists, exists_imp_distrib, (≠)],
exact assume x xt ht i xfi, ht i x xfi xt xfi
end
end locally_finite
/- compact sets -/
section compact
/-- A set `s` is compact if every filter that contains `s` also meets every
neighborhood of some `a ∈ s`. -/
def compact (s : set α) := ∀f, f ≠ ⊥ → f ≤ principal s → ∃a∈s, f ⊓ nhds a ≠ ⊥
lemma compact_of_is_closed_subset {s t : set α}
(hs : compact s) (ht : is_closed t) (h : t ⊆ s) : compact t :=
assume f hnf hsf,
let ⟨a, hsa, (ha : f ⊓ nhds a ≠ ⊥)⟩ := hs f hnf (le_trans hsf $ by simp [h]) in
have ∀a, principal t ⊓ nhds a ≠ ⊥ → a ∈ t,
by intro a; rw [inf_comm]; rw [is_closed_iff_nhds] at ht; exact ht a,
have a ∈ t,
from this a $ neq_bot_of_le_neq_bot ha $ inf_le_inf hsf (le_refl _),
⟨a, this, ha⟩
lemma compact_adherence_nhdset {s t : set α} {f : filter α}
(hs : compact s) (hf₂ : f ≤ principal s) (ht₁ : is_open t) (ht₂ : ∀a∈s, nhds a ⊓ f ≠ ⊥ → a ∈ t) :
t ∈ f.sets :=
classical.by_cases mem_sets_of_neq_bot $
assume : f ⊓ principal (- t) ≠ ⊥,
let ⟨a, ha, (hfa : f ⊓ principal (-t) ⊓ nhds a ≠ ⊥)⟩ := hs _ this $ inf_le_left_of_le hf₂ in
have a ∈ t,
from ht₂ a ha $ neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_left,
have nhds a ⊓ principal (-t) ≠ ⊥,
from neq_bot_of_le_neq_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_right,
have ∀s∈(nhds a ⊓ principal (-t)).sets, s ≠ ∅,
from forall_sets_neq_empty_iff_neq_bot.mpr this,
have false,
from this _ ⟨t, mem_nhds_sets ht₁ ‹a ∈ t›, -t, subset.refl _, subset.refl _⟩ (by simp),
by contradiction
lemma compact_iff_ultrafilter_le_nhds {s : set α} :
compact s ↔ (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a) :=
⟨assume hs : compact s, assume f hf hfs,
let ⟨a, ha, h⟩ := hs _ hf.left hfs in
⟨a, ha, le_of_ultrafilter hf h⟩,
assume hs : (∀f, ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ nhds a),
assume f hf hfs,
let ⟨a, ha, (h : ultrafilter_of f ≤ nhds a)⟩ :=
hs (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs) in
have ultrafilter_of f ⊓ nhds a ≠ ⊥,
by simp [inf_of_le_left, h]; exact (ultrafilter_ultrafilter_of hf).left,
⟨a, ha, neq_bot_of_le_neq_bot this (inf_le_inf ultrafilter_of_le (le_refl _))⟩⟩
lemma compact_elim_finite_subcover {s : set α} {c : set (set α)}
(hs : compact s) (hc₁ : ∀t∈c, is_open t) (hc₂ : s ⊆ ⋃₀ c) : ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c' :=
classical.by_contradiction $ assume h,
have h : ∀{c'}, c' ⊆ c → finite c' → ¬ s ⊆ ⋃₀ c',
from assume c' h₁ h₂ h₃, h ⟨c', h₁, h₂, h₃⟩,
let
f : filter α := (⨅c':{c' : set (set α) // c' ⊆ c ∧ finite c'}, principal (s - ⋃₀ c')),
⟨a, ha⟩ := @exists_mem_of_ne_empty α s
(assume h', h (empty_subset _) finite_empty $ h'.symm ▸ empty_subset _)
in
have f ≠ ⊥, from infi_neq_bot_of_directed ⟨a⟩
(assume ⟨c₁, hc₁, hc'₁⟩ ⟨c₂, hc₂, hc'₂⟩, ⟨⟨c₁ ∪ c₂, union_subset hc₁ hc₂, finite_union hc'₁ hc'₂⟩,
principal_mono.mpr $ diff_right_antimono $ sUnion_mono $ subset_union_left _ _,
principal_mono.mpr $ diff_right_antimono $ sUnion_mono $ subset_union_right _ _⟩)
(assume ⟨c', hc'₁, hc'₂⟩, show principal (s \ _) ≠ ⊥, by simp [diff_neq_empty]; exact h hc'₁ hc'₂),
have f ≤ principal s, from infi_le_of_le ⟨∅, empty_subset _, finite_empty⟩ $
show principal (s \ ⋃₀∅) ≤ principal s, by simp; exact subset.refl s,
let
⟨a, ha, (h : f ⊓ nhds a ≠ ⊥)⟩ := hs f ‹f ≠ ⊥› this,
⟨t, ht₁, (ht₂ : a ∈ t)⟩ := hc₂ ha
in
have f ≤ principal (-t),
from infi_le_of_le ⟨{t}, by simp [ht₁], finite_insert _ finite_empty⟩ $
principal_mono.mpr $
show s - ⋃₀{t} ⊆ - t, begin simp; exact assume x ⟨_, hnt⟩, hnt end,
have is_closed (- t), from is_open_compl_iff.mp $ by simp; exact hc₁ t ht₁,
have a ∈ - t, from is_closed_iff_nhds.mp this _ $ neq_bot_of_le_neq_bot h $
le_inf inf_le_right (inf_le_left_of_le ‹f ≤ principal (- t)›),
this ‹a ∈ t›
lemma compact_elim_finite_subcover_image {s : set α} {b : set β} {c : β → set α}
(hs : compact s) (hc₁ : ∀i∈b, is_open (c i)) (hc₂ : s ⊆ ⋃i∈b, c i) :
∃b'⊆b, finite b' ∧ s ⊆ ⋃i∈b', c i :=
if h : b = ∅ then ⟨∅, by simp, by simp, h ▸ hc₂⟩ else
let ⟨i, hi⟩ := exists_mem_of_ne_empty h in
have hc'₁ : ∀i∈c '' b, is_open i, from assume i ⟨j, hj, h⟩, h ▸ hc₁ _ hj,
have hc'₂ : s ⊆ ⋃₀ (c '' b), by simpa,
let ⟨d, hd₁, hd₂, hd₃⟩ := compact_elim_finite_subcover hs hc'₁ hc'₂ in
have ∀x : d, ∃i, i ∈ b ∧ c i = x, from assume ⟨x, hx⟩, hd₁ hx,
let ⟨f', hf⟩ := axiom_of_choice this,
f := λx:set α, (if h : x ∈ d then f' ⟨x, h⟩ else i : β) in
have ∀(x : α) (i : set α), i ∈ d → x ∈ i → (∃ (i : β), i ∈ f '' d ∧ x ∈ c i),
from assume x i hid hxi, ⟨f i, mem_image_of_mem f hid,
by simpa [f, hid, (hf ⟨_, hid⟩).2] using hxi⟩,
⟨f '' d,
assume i ⟨j, hj, h⟩,
h ▸ by simpa [f, hj] using (hf ⟨_, hj⟩).1,
finite_image f hd₂,
subset.trans hd₃ $ by simpa [subset_def]⟩
lemma compact_of_finite_subcover {s : set α}
(h : ∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') : compact s :=
assume f hfn hfs, classical.by_contradiction $ assume : ¬ (∃x∈s, f ⊓ nhds x ≠ ⊥),
have hf : ∀x∈s, nhds x ⊓ f = ⊥,
by simpa [not_and, inf_comm],
have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,
from assume ⟨x, hxs, hx⟩,
have ∅ ∈ (nhds x ⊓ f).sets, by rw [empty_in_sets_eq_bot, hf x hxs],
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := by rw [mem_inf_sets] at this; exact this in
have ∅ ∈ (nhds x ⊓ principal t₂).sets,
from (nhds x ⊓ principal t₂).upwards_sets (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,
have nhds x ⊓ principal t₂ = ⊥,
by rwa [empty_in_sets_eq_bot] at this,
by simp [closure_eq_nhds] at hx; exact hx t₂ ht₂ this,
have ∀x∈s, ∃t∈f.sets, x ∉ closure t, by simpa [_root_.not_forall],
let c := (λt, - closure t) '' f.sets, ⟨c', hcc', hcf, hsc'⟩ := h c
(assume t ⟨s, hs, h⟩, h ▸ is_closed_closure) (by simpa [subset_def]) in
let ⟨b, hb⟩ := axiom_of_choice $
show ∀s:c', ∃t, t ∈ f.sets ∧ - closure t = s,
from assume ⟨x, hx⟩, hcc' hx in
have (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,
from Inter_mem_sets hcf $ assume t ht, by rw [dif_pos ht]; exact (hb ⟨t, ht⟩).left,
have s ∩ (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f.sets,
from inter_mem_sets (by simp at hfs; assumption) this,
have ∅ ∈ f.sets,
from f.upwards_sets this $ assume x ⟨hxs, hxi⟩,
let ⟨t, htc', hxt⟩ := (show ∃t ∈ c', x ∈ t, by simpa using hsc' hxs) in
have -closure (b ⟨t, htc'⟩) = t, from (hb _).right,
have x ∈ - t,
from this ▸ (calc x ∈ b ⟨t, htc'⟩ : by simp at hxi; have h := hxi t htc'; rwa [dif_pos htc'] at h
... ⊆ closure (b ⟨t, htc'⟩) : subset_closure
... ⊆ - - closure (b ⟨t, htc'⟩) : by simp; exact subset.refl _),
show false, from this hxt,
hfn $ by rwa [empty_in_sets_eq_bot] at this
lemma compact_iff_finite_subcover {s : set α} :
compact s ↔ (∀c, (∀t∈c, is_open t) → s ⊆ ⋃₀ c → ∃c'⊆c, finite c' ∧ s ⊆ ⋃₀ c') :=
⟨assume hc c, compact_elim_finite_subcover hc, compact_of_finite_subcover⟩
lemma compact_empty : compact (∅ : set α) :=
assume f hnf hsf, not.elim hnf $
by simpa [empty_in_sets_eq_bot] using hsf
lemma compact_singleton {a : α} : compact ({a} : set α) :=
compact_of_finite_subcover $ assume c hc₁ hc₂,
let ⟨i, hic, hai⟩ := (show ∃i ∈ c, a ∈ i, by simpa using hc₂) in
⟨{i}, by simp [hic], finite_singleton _, by simp [hai]⟩
lemma compact_bUnion_of_compact {s : set β} {f : β → set α} (hs : finite s) :
(∀i ∈ s, compact (f i)) → compact (⋃i ∈ s, f i) :=
assume hf, compact_of_finite_subcover $ assume c c_open c_cover,
have ∀i : subtype s, ∃c' ⊆ c, finite c' ∧ f i ⊆ ⋃₀ c', from
assume ⟨i, hi⟩, compact_elim_finite_subcover (hf i hi) c_open
(calc f i ⊆ ⋃i ∈ s, f i : subset_bUnion_of_mem hi
... ⊆ ⋃₀ c : c_cover),
let ⟨finite_subcovers, h⟩ := axiom_of_choice this in
let c' := ⋃i, finite_subcovers i in
have c' ⊆ c, from Union_subset (λi, (h i).fst),
have finite c', from @finite_Union _ _ hs.fintype _ (λi, (h i).snd.1),
have (⋃i ∈ s, f i) ⊆ ⋃₀ c', from bUnion_subset $ λi hi, calc
f i ⊆ ⋃₀ finite_subcovers ⟨i,hi⟩ : (h ⟨i,hi⟩).snd.2
... ⊆ ⋃₀ c' : sUnion_mono (subset_Union _ _),
⟨c', ‹c' ⊆ c›, ‹finite c'›, this⟩
lemma compact_of_finite {s : set α} (hs : finite s) : compact s :=
let s' : set α := ⋃i ∈ s, {i} in
have e : s' = s, from ext $ λi, by simp,
have compact s', from compact_bUnion_of_compact hs (λ_ _, compact_singleton),
e ▸ this
end compact
/- separation axioms -/
section separation
/-- A T₁ space, also known as a Fréchet space, is a topological space
where for every pair `x ≠ y`, there is an open set containing `x` and not `y`.
Equivalently, every singleton set is closed. -/
class t1_space (α : Type u) [topological_space α] :=
(t1 : ∀x, is_closed ({x} : set α))
lemma is_closed_singleton [t1_space α] {x : α} : is_closed ({x} : set α) :=
t1_space.t1 x
lemma compl_singleton_mem_nhds [t1_space α] {x y : α} (h : y ≠ x) : - {x} ∈ (nhds y).sets :=
mem_nhds_sets is_closed_singleton $ by simp; exact h
@[simp] lemma closure_singleton [topological_space α] [t1_space α] {a : α} :
closure ({a} : set α) = {a} :=
closure_eq_of_is_closed is_closed_singleton
/-- A T₂ space, also known as a Hausdorff space, is one in which for every
`x ≠ y` there exists disjoint open sets around `x` and `y`. This is
the most widely used of the separation axioms. -/
class t2_space (α : Type u) [topological_space α] :=
(t2 : ∀x y, x ≠ y → ∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅)
lemma t2_separation [t2_space α] {x y : α} (h : x ≠ y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
t2_space.t2 x y h
instance t2_space.t1_space [topological_space α] [t2_space α] : t1_space α :=
⟨assume x,
have ∀y, y ≠ x ↔ ∃ (i : set α), (x ∉ i ∧ is_open i) ∧ y ∈ i,
from assume y, ⟨assume h',
let ⟨u, v, hu, hv, hy, hx, h⟩ := t2_separation h' in
have x ∉ u,
from assume : x ∈ u,
have x ∈ u ∩ v, from ⟨this, hx⟩,
by rwa [h] at this,
⟨u, ⟨this, hu⟩, hy⟩,
assume ⟨s, ⟨hx, hs⟩, hy⟩ h, hx $ h ▸ hy⟩,
have (-{x} : set α) = (⋃s∈{s : set α | x ∉ s ∧ is_open s}, s),
by apply set.ext; simpa,
show is_open (- {x}),
by rw [this]; exact (is_open_Union $ assume s, is_open_Union $ assume ⟨_, hs⟩, hs)⟩
lemma eq_of_nhds_neq_bot [ht : t2_space α] {x y : α} (h : nhds x ⊓ nhds y ≠ ⊥) : x = y :=
classical.by_contradiction $ assume : x ≠ y,
let ⟨u, v, hu, hv, hx, hy, huv⟩ := t2_space.t2 x y this in
have u ∩ v ∈ (nhds x ⊓ nhds y).sets,
from inter_mem_inf_sets (mem_nhds_sets hu hx) (mem_nhds_sets hv hy),
h $ empty_in_sets_eq_bot.mp $ huv ▸ this
@[simp] lemma nhds_eq_nhds_iff {a b : α} [t2_space α] : nhds a = nhds b ↔ a = b :=
⟨assume h, eq_of_nhds_neq_bot $ by simp [h], assume h, h ▸ rfl⟩
@[simp] lemma nhds_le_nhds_iff {a b : α} [t2_space α] : nhds a ≤ nhds b ↔ a = b :=
⟨assume h, eq_of_nhds_neq_bot $ by simp [inf_of_le_left h], assume h, h ▸ le_refl _⟩
lemma tendsto_nhds_unique [t2_space α] {f : β → α} {l : filter β} {a b : α}
(hl : l ≠ ⊥) (ha : tendsto f l (nhds a)) (hb : tendsto f l (nhds b)) : a = b :=
eq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot (map_ne_bot hl) $ le_inf ha hb
end separation
section regularity
/-- A T₃ space, also known as a regular space (although this condition sometimes
omits T₂), is one in which for every closed `C` and `x ∉ C`, there exist
disjoint open sets containing `x` and `C` respectively. -/
class regular_space (α : Type u) [topological_space α] extends t2_space α :=
(regular : ∀{s:set α} {a}, is_closed s → a ∉ s → ∃t, is_open t ∧ s ⊆ t ∧ nhds a ⊓ principal t = ⊥)
lemma nhds_is_closed [regular_space α] {a : α} {s : set α} (h : s ∈ (nhds a).sets) :
∃t∈(nhds a).sets, t ⊆ s ∧ is_closed t :=
let ⟨s', h₁, h₂, h₃⟩ := mem_nhds_sets_iff.mp h in
have ∃t, is_open t ∧ -s' ⊆ t ∧ nhds a ⊓ principal t = ⊥,
from regular_space.regular (is_closed_compl_iff.mpr h₂) (not_not_intro h₃),
let ⟨t, ht₁, ht₂, ht₃⟩ := this in
⟨-t,
mem_sets_of_neq_bot $ by simp; exact ht₃,
subset.trans (compl_subset_comm.1 ht₂) h₁,
is_closed_compl_iff.mpr ht₁⟩
end regularity
/- generating sets -/
end topological_space
namespace topological_space
variables {α : Type u}
/-- The least topology containing a collection of basic sets. -/
inductive generate_open (g : set (set α)) : set α → Prop
| basic : ∀s∈g, generate_open s
| univ : generate_open univ
| inter : ∀s t, generate_open s → generate_open t → generate_open (s ∩ t)
| sUnion : ∀k, (∀s∈k, generate_open s) → generate_open (⋃₀ k)
/-- The smallest topological space containing the collection `g` of basic sets -/
def generate_from (g : set (set α)) : topological_space α :=
{ is_open := generate_open g,
is_open_univ := generate_open.univ g,
is_open_inter := generate_open.inter,
is_open_sUnion := generate_open.sUnion }
lemma nhds_generate_from {g : set (set α)} {a : α} :
@nhds α (generate_from g) a = (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) :=
le_antisymm
(infi_le_infi $ assume s, infi_le_infi_const $ assume ⟨as, sg⟩, ⟨as, generate_open.basic _ sg⟩)
(le_infi $ assume s, le_infi $ assume ⟨as, hs⟩,
have ∀s, generate_open g s → a ∈ s → (⨅s∈{s | a ∈ s ∧ s ∈ g}, principal s) ≤ principal s,
begin
intros s hs,
induction hs,
case generate_open.basic : s hs
{ exact assume as, infi_le_of_le s $ infi_le _ ⟨as, hs⟩ },
case generate_open.univ
{ rw [principal_univ],
exact assume _, le_top },
case generate_open.inter : s t hs' ht' hs ht
{ exact assume ⟨has, hat⟩, calc _ ≤ principal s ⊓ principal t : le_inf (hs has) (ht hat)
... = _ : by simp },
case generate_open.sUnion : k hk' hk
{ exact λ ⟨t, htk, hat⟩, calc _ ≤ principal t : hk t htk hat
... ≤ _ : begin simp; exact subset_sUnion_of_mem htk end }
end,
this s hs as)
end topological_space
section lattice
variables {α : Type u} {β : Type v}
instance : partial_order (topological_space α) :=
{ le := λt s, t.is_open ≤ s.is_open,
le_antisymm := assume t s h₁ h₂, topological_space_eq $ le_antisymm h₁ h₂,
le_refl := assume t, le_refl t.is_open,
le_trans := assume a b c h₁ h₂, @le_trans _ _ a.is_open b.is_open c.is_open h₁ h₂ }
instance : has_Inf (topological_space α) := ⟨λ tt,
{ is_open := λs, ∀t∈tt, topological_space.is_open t s,
is_open_univ := assume t h, t.is_open_univ,
is_open_inter := assume s₁ s₂ h₁ h₂ t ht, t.is_open_inter s₁ s₂ (h₁ t ht) (h₂ t ht),
is_open_sUnion := assume s h t ht, t.is_open_sUnion _ $ assume s' hss', h _ hss' _ ht }⟩
private lemma Inf_le {tt : set (topological_space α)} {t : topological_space α} (h : t ∈ tt) :
Inf tt ≤ t :=
assume s hs, hs t h
private lemma le_Inf {tt : set (topological_space α)} {t : topological_space α} (h : ∀t'∈tt, t ≤ t') :
t ≤ Inf tt :=
assume s hs t' ht', h t' ht' s hs
instance : has_inf (topological_space α) := ⟨λ t₁ t₂,
{ is_open := λs, t₁.is_open s ∧ t₂.is_open s,
is_open_univ := ⟨t₁.is_open_univ, t₂.is_open_univ⟩,
is_open_inter := assume s₁ s₂ ⟨h₁₁, h₁₂⟩ ⟨h₂₁, h₂₂⟩, ⟨t₁.is_open_inter s₁ s₂ h₁₁ h₂₁, t₂.is_open_inter s₁ s₂ h₁₂ h₂₂⟩,
is_open_sUnion := assume s h, ⟨t₁.is_open_sUnion _ $ assume t ht, (h t ht).left, t₂.is_open_sUnion _ $ assume t ht, (h t ht).right⟩ }⟩
instance : has_top (topological_space α) :=
⟨{is_open := λs, true,
is_open_univ := trivial,
is_open_inter := assume a b ha hb, trivial,
is_open_sUnion := assume s h, trivial }⟩
instance {α : Type u} : complete_lattice (topological_space α) :=
{ sup := λa b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := assume a b, le_Inf $ assume x, assume h : a ≤ x ∧ b ≤ x, h.left,
le_sup_right := assume a b, le_Inf $ assume x, assume h : a ≤ x ∧ b ≤ x, h.right,
sup_le := assume a b c h₁ h₂, Inf_le $ show c ∈ {x | a ≤ x ∧ b ≤ x}, from ⟨h₁, h₂⟩,
inf := (⊓),
le_inf := assume a b h h₁ h₂ s hs, ⟨h₁ s hs, h₂ s hs⟩,
inf_le_left := assume a b s ⟨h₁, h₂⟩, h₁,
inf_le_right := assume a b s ⟨h₁, h₂⟩, h₂,
top := ⊤,
le_top := assume a t ht, trivial,
bot := Inf univ,
bot_le := assume a, Inf_le $ mem_univ a,
Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t},
le_Sup := assume s f h, le_Inf $ assume t ht, ht _ h,
Sup_le := assume s f h, Inf_le $ assume t ht, h _ ht,
Inf := Inf,
le_Inf := assume s a, le_Inf,
Inf_le := assume s a, Inf_le,
..topological_space.partial_order }
lemma le_of_nhds_le_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x ≤ @nhds α t₁ x) :
t₁ ≤ t₂ :=
assume s, show @is_open α t₁ s → @is_open α t₂ s,
begin simp [is_open_iff_nhds]; exact assume hs a ha, h _ $ hs _ ha end
lemma eq_of_nhds_eq_nhds {t₁ t₂ : topological_space α} (h : ∀x, @nhds α t₂ x = @nhds α t₁ x) :
t₁ = t₂ :=
le_antisymm
(le_of_nhds_le_nhds $ assume x, le_of_eq $ h x)
(le_of_nhds_le_nhds $ assume x, le_of_eq $ (h x).symm)
end lattice
section galois_connection
variables {α : Type u} {β : Type v}
/-- Given `f : α → β` and a topology on `β`, the induced topology on `α` is the collection of
sets that are preimages of some open set in `β`. This is the coarsest topology that
makes `f` continuous. -/
def topological_space.induced {α : Type u} {β : Type v} (f : α → β) (t : topological_space β) :
topological_space α :=
{ is_open := λs, ∃s', t.is_open s' ∧ s = f ⁻¹' s',
is_open_univ := ⟨univ, by simp; exact t.is_open_univ⟩,
is_open_inter := assume s₁ s₂ ⟨s'₁, hs₁, eq₁⟩ ⟨s'₂, hs₂, eq₂⟩,
⟨s'₁ ∩ s'₂, by simp [eq₁, eq₂]; exact t.is_open_inter _ _ hs₁ hs₂⟩,
is_open_sUnion := assume s h,
begin
simp [classical.skolem] at h,
cases h with f hf,
apply exists.intro (⋃(x : set α) (h : x ∈ s), f x h),
simp [sUnion_eq_Union, (λx h, (hf x h).right.symm)],
exact (@is_open_Union β _ t _ $ assume i,
show is_open (⋃h, f i h), from @is_open_Union β _ t _ $ assume h, (hf i h).left)
end }
lemma is_closed_induced_iff [t : topological_space β] {s : set α} {f : α → β} :
@is_closed α (t.induced f) s ↔ (∃t, is_closed t ∧ s = f ⁻¹' t) :=
⟨assume ⟨t, ht, heq⟩, ⟨-t, by simp; assumption, by simp [preimage_compl, heq.symm]⟩,
assume ⟨t, ht, heq⟩, ⟨-t, ht, by simp [preimage_compl, heq.symm]⟩⟩
/-- Given `f : α → β` and a topology on `α`, the coinduced topology on `β` is defined
such that `s:set β` is open if the preimage of `s` is open. This is the finest topology that
makes `f` continuous. -/
def topological_space.coinduced {α : Type u} {β : Type v} (f : α → β) (t : topological_space α) :
topological_space β :=
{ is_open := λs, t.is_open (f ⁻¹' s),
is_open_univ := by simp; exact t.is_open_univ,
is_open_inter := assume s₁ s₂ h₁ h₂, by simp; exact t.is_open_inter _ _ h₁ h₂,
is_open_sUnion := assume s h, by rw [preimage_sUnion]; exact (@is_open_Union _ _ t _ $ assume i,
show is_open (⋃ (H : i ∈ s), f ⁻¹' i), from
@is_open_Union _ _ t _ $ assume hi, h i hi) }
variables {t t₁ t₂ : topological_space α} {t' : topological_space β} {f : α → β} {g : β → α}
lemma induced_le_iff_le_coinduced {f : α → β } {tα : topological_space α} {tβ : topological_space β} :
tβ.induced f ≤ tα ↔ tβ ≤ tα.coinduced f :=
iff.intro
(assume h s hs, show tα.is_open (f ⁻¹' s), from h _ ⟨s, hs, rfl⟩)
(assume h s ⟨t, ht, hst⟩, hst.symm ▸ h _ ht)
lemma gc_induced_coinduced (f : α → β) :
galois_connection (topological_space.induced f) (topological_space.coinduced f) :=
assume f g, induced_le_iff_le_coinduced
lemma induced_mono (h : t₁ ≤ t₂) : t₁.induced g ≤ t₂.induced g :=
(gc_induced_coinduced g).monotone_l h
lemma coinduced_mono (h : t₁ ≤ t₂) : t₁.coinduced f ≤ t₂.coinduced f :=
(gc_induced_coinduced f).monotone_u h
@[simp] lemma induced_bot : (⊥ : topological_space α).induced g = ⊥ :=
(gc_induced_coinduced g).l_bot
@[simp] lemma induced_sup : (t₁ ⊔ t₂).induced g = t₁.induced g ⊔ t₂.induced g :=
(gc_induced_coinduced g).l_sup
@[simp] lemma induced_supr {ι : Sort w} {t : ι → topological_space α} :
(⨆i, t i).induced g = (⨆i, (t i).induced g) :=
(gc_induced_coinduced g).l_supr
@[simp] lemma coinduced_top : (⊤ : topological_space α).coinduced f = ⊤ :=
(gc_induced_coinduced f).u_top
@[simp] lemma coinduced_inf : (t₁ ⊓ t₂).coinduced f = t₁.coinduced f ⊓ t₂.coinduced f :=
(gc_induced_coinduced f).u_inf
@[simp] lemma coinduced_infi {ι : Sort w} {t : ι → topological_space α} :
(⨅i, t i).coinduced f = (⨅i, (t i).coinduced f) :=
(gc_induced_coinduced f).u_infi
end galois_connection
/- constructions using the complete lattice structure -/
section constructions
open topological_space
variables {α : Type u} {β : Type v}
instance inhabited_topological_space {α : Type u} : inhabited (topological_space α) :=
⟨⊤⟩
lemma t2_space_top : @t2_space α ⊤ :=
{ t2 := assume x y hxy, ⟨{x}, {y}, trivial, trivial, mem_insert _ _, mem_insert _ _,
eq_empty_iff_forall_not_mem.2 $ by intros z hz; simp at hz; cc⟩ }
instance : topological_space empty := ⊤
instance : topological_space unit := ⊤
instance : topological_space bool := ⊤
instance : topological_space ℕ := ⊤
instance : topological_space ℤ := ⊤
instance sierpinski_space : topological_space Prop :=
generate_from {{true}}
instance {p : α → Prop} [t : topological_space α] : topological_space (subtype p) :=
induced subtype.val t
instance {r : α → α → Prop} [t : topological_space α] : topological_space (quot r) :=
coinduced (quot.mk r) t
instance {s : setoid α} [t : topological_space α] : topological_space (quotient s) :=
coinduced quotient.mk t
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α × β) :=
induced prod.fst t₁ ⊔ induced prod.snd t₂
instance [t₁ : topological_space α] [t₂ : topological_space β] : topological_space (α ⊕ β) :=
coinduced sum.inl t₁ ⊓ coinduced sum.inr t₂
instance {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (sigma β) :=
⨅a, coinduced (sigma.mk a) (t₂ a)
instance Pi.topological_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] : topological_space (Πa, β a) :=
⨆a, induced (λf, f a) (t₂ a)
lemma generate_from_le {t : topological_space α} { g : set (set α) } (h : ∀s∈g, is_open s) :
generate_from g ≤ t :=
assume s (hs : generate_open g s), generate_open.rec_on hs h
is_open_univ
(assume s t _ _ hs ht, is_open_inter hs ht)
(assume k _ hk, is_open_sUnion hk)
lemma supr_eq_generate_from {ι : Sort w} { g : ι → topological_space α } :
supr g = generate_from (⋃i, {s | (g i).is_open s}) :=
le_antisymm
(supr_le $ assume i s is_open_s,
generate_open.basic _ $ by simp; exact ⟨i, is_open_s⟩)
(generate_from_le $ assume s,
begin
simp,
exact assume i is_open_s,
have g i ≤ supr g, from le_supr _ _,
this s is_open_s
end)
lemma sup_eq_generate_from { g₁ g₂ : topological_space α } :
g₁ ⊔ g₂ = generate_from {s | g₁.is_open s ∨ g₂.is_open s} :=
le_antisymm
(sup_le (assume s, generate_open.basic _ ∘ or.inl) (assume s, generate_open.basic _ ∘ or.inr))
(generate_from_le $ assume s hs,
have h₁ : g₁ ≤ g₁ ⊔ g₂, from le_sup_left,
have h₂ : g₂ ≤ g₁ ⊔ g₂, from le_sup_right,
or.rec_on hs (h₁ s) (h₂ s))
lemma nhds_mono {t₁ t₂ : topological_space α} {a : α} (h : t₁ ≤ t₂) : @nhds α t₂ a ≤ @nhds α t₁ a :=
infi_le_infi $ assume s, infi_le_infi2 $ assume ⟨ha, hs⟩, ⟨⟨ha, h _ hs⟩, le_refl _⟩
lemma nhds_supr {ι : Sort w} {t : ι → topological_space α} {a : α} :
@nhds α (supr t) a = (⨅i, @nhds α (t i) a) :=
le_antisymm
(le_infi $ assume i, nhds_mono $ le_supr _ _)
begin
rw [supr_eq_generate_from, nhds_generate_from],
exact (le_infi $ assume s, le_infi $ assume ⟨hs, hi⟩,
begin
simp at hi, cases hi with i hi,
exact (infi_le_of_le i $ le_principal_iff.mpr $ @mem_nhds_sets α (t i) _ _ hi hs)
end)
end
lemma nhds_sup {t₁ t₂ : topological_space α} {a : α} :
@nhds α (t₁ ⊔ t₂) a = @nhds α t₁ a ⊓ @nhds α t₂ a :=
calc @nhds α (t₁ ⊔ t₂) a = @nhds α (⨆b:bool, cond b t₁ t₂) a : by rw [supr_bool_eq]
... = (⨅b, @nhds α (cond b t₁ t₂) a) : begin rw [nhds_supr] end
... = @nhds α t₁ a ⊓ @nhds α t₂ a : by rw [infi_bool_eq]
private lemma separated_by_f
[tα : topological_space α] [tβ : topological_space β] [t2_space β]
(f : α → β) (hf : induced f tβ ≤ tα) {x y : α} (h : f x ≠ f y) :
∃u v : set α, is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ u ∩ v = ∅ :=
let ⟨u, v, uo, vo, xu, yv, uv⟩ := t2_separation h in
⟨f ⁻¹' u, f ⁻¹' v, hf _ ⟨u, uo, rfl⟩, hf _ ⟨v, vo, rfl⟩, xu, yv,
by rw [←preimage_inter, uv, preimage_empty]⟩
instance {p : α → Prop} [t : topological_space α] [t2_space α] : t2_space (subtype p) :=
⟨assume x y h,
separated_by_f subtype.val (le_refl _) (mt subtype.eq h)⟩
instance [t₁ : topological_space α] [t2_space α] [t₂ : topological_space β] [t2_space β] :
t2_space (α × β) :=
⟨assume ⟨x₁,x₂⟩ ⟨y₁,y₂⟩ h,
or.elim (not_and_distrib.mp (mt prod.ext_iff.mpr h))
(λ h₁, separated_by_f prod.fst le_sup_left h₁)
(λ h₂, separated_by_f prod.snd le_sup_right h₂)⟩
instance Pi.t2_space {β : α → Type v} [t₂ : Πa, topological_space (β a)] [Πa, t2_space (β a)] :
t2_space (Πa, β a) :=
⟨assume x y h,
let ⟨i, hi⟩ := not_forall.mp (mt funext h) in
separated_by_f (λz, z i) (le_supr _ i) hi⟩
end constructions
namespace topological_space
/- countability axioms
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.
-/
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). -/
def is_topological_basis (s : set (set α)) : Prop :=
(∀t₁∈s, ∀t₂∈s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃∈s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂) ∧
(⋃₀ s) = univ ∧
t = generate_from s
lemma is_topological_basis_of_subbasis {s : set (set α)} (hs : t = generate_from s) :
is_topological_basis ((λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅}) :=
let b' := (λf, ⋂₀ f) '' {f:set (set α) | finite f ∧ f ⊆ s ∧ ⋂₀ f ≠ ∅} in
⟨assume s₁ ⟨t₁, ⟨hft₁, ht₁b, ht₁⟩, eq₁⟩ s₂ ⟨t₂, ⟨hft₂, ht₂b, ht₂⟩, eq₂⟩,
have ie : ⋂₀(t₁ ∪ t₂) = ⋂₀ t₁ ∩ ⋂₀ t₂, from Inf_union,
eq₁ ▸ eq₂ ▸ assume x h,
⟨_, ⟨t₁ ∪ t₂, ⟨finite_union hft₁ hft₂, union_subset ht₁b ht₂b,
by simpa [ie] using ne_empty_of_mem h⟩, ie⟩, h, subset.refl _⟩,
eq_univ_iff_forall.2 $ assume a, ⟨univ, ⟨∅, by simp; exact (@empty_ne_univ _ ⟨a⟩).symm⟩, mem_univ _⟩,
have generate_from s = generate_from b',
from le_antisymm
(generate_from_le $ assume s hs,
by_cases
(assume : s = ∅, by rw [this]; apply @is_open_empty _ _)
(assume : s ≠ ∅, generate_open.basic _ ⟨{s}, by simp [this, hs]⟩))
(generate_from_le $ assume u ⟨t, ⟨hft, htb, ne⟩, eq⟩,
eq ▸ @is_open_sInter _ (generate_from s) _ hft (assume s hs, generate_open.basic _ $ htb hs)),
this ▸ hs⟩
lemma is_topological_basis_of_open_of_nhds {s : set (set α)}
(h_open : ∀ u ∈ s, _root_.is_open u)
(h_nhds : ∀(a:α) (u : set α), a ∈ u → _root_.is_open u → ∃v ∈ s, a ∈ v ∧ v ⊆ u) :
is_topological_basis s :=
⟨assume t₁ ht₁ t₂ ht₂ x ⟨xt₁, xt₂⟩,
h_nhds x (t₁ ∩ t₂) ⟨xt₁, xt₂⟩
(is_open_inter _ _ _ (h_open _ ht₁) (h_open _ ht₂)),
eq_univ_iff_forall.2 $ assume a,
let ⟨u, h₁, h₂, _⟩ := h_nhds a univ trivial (is_open_univ _) in
⟨u, h₁, h₂⟩,
le_antisymm
(assume u hu,
(@is_open_iff_nhds α (generate_from _) _).mpr $ assume a hau,
let ⟨v, hvs, hav, hvu⟩ := h_nhds a u hau hu in
by rw nhds_generate_from; exact infi_le_of_le v (infi_le_of_le ⟨hav, hvs⟩ $ by simp [hvu]))
(generate_from_le h_open)⟩
lemma mem_nhds_of_is_topological_basis {a : α} {s : set α} {b : set (set α)}
(hb : is_topological_basis b) : s ∈ (nhds a).sets ↔ ∃t∈b, a ∈ t ∧ t ⊆ s :=
begin
rw [hb.2.2, nhds_generate_from, infi_sets_eq'],
{ simpa [and_comm, 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₁⟩, by simpa using hu₃⟩ },
{ suffices : a ∈ (⋃₀ b), { simpa [and_comm] },
{ rw [hb.2.1], trivial } }
end
lemma is_open_of_is_topological_basis {s : set α} {b : set (set α)}
(hb : is_topological_basis b) (hs : s ∈ b) : _root_.is_open s :=
is_open_iff_mem_nhds.2 $ λ a as,
(mem_nhds_of_is_topological_basis hb).2 ⟨s, hs, as, subset.refl _⟩
lemma mem_basis_subset_of_mem_open {b : set (set α)}
(hb : is_topological_basis b) {a:α} {u : set α} (au : a ∈ u)
(ou : _root_.is_open u) : ∃v ∈ b, a ∈ v ∧ v ⊆ u :=
(mem_nhds_of_is_topological_basis hb).1 $ mem_nhds_sets ou au
lemma sUnion_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) :
∃ S ⊆ B, u = ⋃₀ S :=
⟨{s ∈ B | s ⊆ u}, λ s h, h.1, set.ext $ λ a,
⟨λ ha, let ⟨b, hb, ab, bu⟩ := mem_basis_subset_of_mem_open hB ha ou in
⟨b, ⟨hb, bu⟩, ab⟩,
λ ⟨b, ⟨hb, bu⟩, ab⟩, bu ab⟩⟩
lemma Union_basis_of_is_open {B : set (set α)}
(hB : is_topological_basis B) {u : set α} (ou : _root_.is_open u) :
∃ (β : Type u) (f : β → set α), u = (⋃ i, f i) ∧ ∀ i, f i ∈ B :=
let ⟨S, sb, su⟩ := sUnion_basis_of_is_open hB ou in
⟨S, subtype.val, su.trans set.sUnion_eq_Union', λ ⟨b, h⟩, sb h⟩
variables (α)
/-- A separable space is one with a countable dense subset. -/
class separable_space : Prop :=
(exists_countable_closure_eq_univ : ∃s:set α, countable s ∧ closure s = univ)
/-- A first-countable space is one in which every point has a
countable neighborhood basis. -/
class first_countable_topology : Prop :=
(nhds_generated_countable : ∀a:α, ∃s:set (set α), countable s ∧ nhds a = (⨅t∈s, principal t))
/-- A second-countable space is one with a countable basis. -/
class second_countable_topology : Prop :=
(is_open_generated_countable : ∃b:set (set α), countable b ∧ t = topological_space.generate_from b)
instance second_countable_topology.to_first_countable_topology
[second_countable_topology α] : first_countable_topology α :=
let ⟨b, hb, eq⟩ := second_countable_topology.is_open_generated_countable α in
⟨assume a, ⟨{s | a ∈ s ∧ s ∈ b},
countable_subset (assume x ⟨_, hx⟩, hx) hb, by rw [eq, nhds_generate_from]⟩⟩
lemma is_open_generated_countable_inter [second_countable_topology α] :
∃b:set (set α), countable b ∧ ∅ ∉ b ∧ is_topological_basis b :=
let ⟨b, hb₁, hb₂⟩ := second_countable_topology.is_open_generated_countable α in
let b' := (λs, ⋂₀ s) '' {s:set (set α) | finite s ∧ s ⊆ b ∧ ⋂₀ s ≠ ∅} in
⟨b',
countable_image $ countable_subset (by simp {contextual:=tt}) (countable_set_of_finite_subset hb₁),
assume ⟨s, ⟨_, _, hn⟩, hp⟩, hn hp,
is_topological_basis_of_subbasis hb₂⟩
instance second_countable_topology.to_separable_space
[second_countable_topology α] : separable_space α :=
let ⟨b, hb₁, hb₂, hb₃, hb₄, eq⟩ := is_open_generated_countable_inter α in
have nhds_eq : ∀a, nhds a = (⨅ s : {s : set α // a ∈ s ∧ s ∈ b}, principal s.val),
by intro a; rw [eq, nhds_generate_from]; simp [infi_subtype],
have ∀s∈b, ∃a, a ∈ s, from assume s hs, exists_mem_of_ne_empty $ assume eq, hb₂ $ eq ▸ hs,
have ∃f:∀s∈b, α, ∀s h, f s h ∈ s, by simp only [skolem] at this; exact this,
let ⟨f, hf⟩ := this in
⟨⟨(⋃s∈b, ⋃h:s∈b, {f s h}),
countable_bUnion hb₁ (by simp [countable_Union_Prop]),
set.ext $ assume a,
have a ∈ (⋃₀ b), by rw [hb₄]; exact trivial,
let ⟨t, ht₁, ht₂⟩ := this in
have w : {s : set α // a ∈ s ∧ s ∈ b}, from ⟨t, ht₂, ht₁⟩,
suffices (⨅ (x : {s // a ∈ s ∧ s ∈ b}), principal (x.val ∩ ⋃s (h₁ h₂ : s ∈ b), {f s h₂})) ≠ ⊥,
by simpa [closure_eq_nhds, nhds_eq, infi_inf w],
infi_neq_bot_of_directed ⟨a⟩
(assume ⟨s₁, has₁, hs₁⟩ ⟨s₂, has₂, hs₂⟩,
have a ∈ s₁ ∩ s₂, from ⟨has₁, has₂⟩,
let ⟨s₃, hs₃, has₃, hs⟩ := hb₃ _ hs₁ _ hs₂ _ this in
⟨⟨s₃, has₃, hs₃⟩, begin
simp only [le_principal_iff, mem_principal_sets],
simp at hs, split; apply inter_subset_inter_right; simp [hs]
end⟩)
(assume ⟨s, has, hs⟩,
have s ∩ (⋃ (s : set α) (H h : s ∈ b), {f s h}) ≠ ∅,
from ne_empty_of_mem ⟨hf _ hs, mem_bUnion hs $ (mem_Union_eq _ _).mpr ⟨hs, by simp⟩⟩,
by simp [this]) ⟩⟩
end topological_space
section limit
variables {α : Type u} [inhabited α] [topological_space α]
open classical
/-- If `f` is a filter, then `lim f` is a limit of the filter, if it exists. -/
noncomputable def lim (f : filter α) : α := epsilon $ λa, f ≤ nhds a
lemma lim_spec {f : filter α} (h : ∃a, f ≤ nhds a) : f ≤ nhds (lim f) := epsilon_spec h
variables [t2_space α] {f : filter α}
lemma lim_eq {a : α} (hf : f ≠ ⊥) (h : f ≤ nhds a) : lim f = a :=
eq_of_nhds_neq_bot $ neq_bot_of_le_neq_bot hf $ le_inf (lim_spec ⟨_, h⟩) h
@[simp] lemma lim_nhds_eq {a : α} : lim (nhds a) = a :=
lim_eq nhds_neq_bot (le_refl _)
@[simp] lemma lim_nhds_eq_of_closure {a : α} {s : set α} (h : a ∈ closure s) :
lim (nhds a ⊓ principal s) = a :=
lim_eq begin rw [closure_eq_nhds] at h, exact h end inf_le_left
end limit
|
f968641aee3348c8b10a5ad8865f3b96b8834a43 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/complex/upper_half_plane.lean | 707bcba0f7bf9d34618d1e1ccf1aa3525a6f2c8e | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 5,009 | lean | /-
Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu
-/
import linear_algebra.special_linear_group
import analysis.complex.basic
import group_theory.group_action.defs
/-!
# The upper half plane and its automorphisms
This file defines `upper_half_plane` to be the upper half plane in `ℂ`.
We furthermore equip it with the structure of an `SL(2,ℝ)` action by
fractional linear transformations.
We define the notation `ℍ` for the upper half plane available in the locale
`upper_half_plane` so as not to conflict with the quaternions.
-/
noncomputable theory
open matrix matrix.special_linear_group
open_locale classical big_operators matrix_groups
local attribute [instance] fintype.card_fin_even
/-- The open upper half plane -/
abbreviation upper_half_plane :=
{point : ℂ // 0 < point.im}
localized "notation `ℍ` := upper_half_plane" in upper_half_plane
namespace upper_half_plane
/-- Imaginary part -/
def im (z : ℍ) := (z : ℂ).im
/-- Real part -/
def re (z : ℍ) := (z : ℂ).re
@[simp] lemma coe_im (z : ℍ) : (z : ℂ).im = z.im := rfl
@[simp] lemma coe_re (z : ℍ) : (z : ℂ).re = z.re := rfl
lemma im_pos (z : ℍ) : 0 < z.im := z.2
lemma im_ne_zero (z : ℍ) : z.im ≠ 0 := z.im_pos.ne'
lemma ne_zero (z : ℍ) : (z : ℂ) ≠ 0 :=
mt (congr_arg complex.im) z.im_ne_zero
lemma norm_sq_pos (z : ℍ) : 0 < complex.norm_sq (z : ℂ) :=
by { rw complex.norm_sq_pos, exact z.ne_zero }
lemma norm_sq_ne_zero (z : ℍ) : complex.norm_sq (z : ℂ) ≠ 0 := (norm_sq_pos z).ne'
/-- Numerator of the formula for a fractional linear transformation -/
@[simp] def num (g : SL(2, ℝ)) (z : ℍ) : ℂ := (g 0 0) * z + (g 0 1)
/-- Denominator of the formula for a fractional linear transformation -/
@[simp] def denom (g : SL(2, ℝ)) (z : ℍ) : ℂ := (g 1 0) * z + (g 1 1)
lemma linear_ne_zero (cd : fin 2 → ℝ) (z : ℍ) (h : cd ≠ 0) : (cd 0 : ℂ) * z + cd 1 ≠ 0 :=
begin
contrapose! h,
have : cd 0 = 0, -- we will need this twice
{ apply_fun complex.im at h,
simpa only [z.im_ne_zero, complex.add_im, add_zero, coe_im, zero_mul, or_false,
complex.of_real_im, complex.zero_im, complex.mul_im, mul_eq_zero] using h, },
simp only [this, zero_mul, complex.of_real_zero, zero_add, complex.of_real_eq_zero] at h,
ext i,
fin_cases i; assumption,
end
lemma denom_ne_zero (g : SL(2, ℝ)) (z : ℍ) : denom g z ≠ 0 :=
linear_ne_zero (g 1) z (g.row_ne_zero 1)
lemma norm_sq_denom_pos (g : SL(2, ℝ)) (z : ℍ) : 0 < complex.norm_sq (denom g z) :=
complex.norm_sq_pos.mpr (denom_ne_zero g z)
lemma norm_sq_denom_ne_zero (g : SL(2, ℝ)) (z : ℍ) : complex.norm_sq (denom g z) ≠ 0 :=
ne_of_gt (norm_sq_denom_pos g z)
/-- Fractional linear transformation -/
def smul_aux' (g : SL(2, ℝ)) (z : ℍ) : ℂ := num g z / denom g z
lemma smul_aux'_im (g : SL(2, ℝ)) (z : ℍ) :
(smul_aux' g z).im = z.im / (denom g z).norm_sq :=
begin
rw [smul_aux', complex.div_im],
set NsqBot := (denom g z).norm_sq,
have : NsqBot ≠ 0,
{ simp only [denom_ne_zero g z, monoid_with_zero_hom.map_eq_zero, ne.def, not_false_iff], },
field_simp [smul_aux'],
convert congr_arg (λ x, x * z.im * NsqBot ^ 2) g.det_coe using 1,
{ rw det_fin_two ↑g,
ring },
{ ring }
end
/-- Fractional linear transformation -/
def smul_aux (g : SL(2,ℝ)) (z : ℍ) : ℍ :=
⟨smul_aux' g z,
by { rw smul_aux'_im, exact div_pos z.im_pos (complex.norm_sq_pos.mpr (denom_ne_zero g z)) }⟩
lemma denom_cocycle (x y : SL(2,ℝ)) (z : ℍ) :
denom (x * y) z = denom x (smul_aux y z) * denom y z :=
begin
change _ = (_ * (_ / _) + _) * _,
field_simp [denom_ne_zero, -denom, -num],
simp [matrix.mul, dot_product, fin.sum_univ_succ],
ring
end
lemma mul_smul' (x y : SL(2, ℝ)) (z : ℍ) :
smul_aux (x * y) z = smul_aux x (smul_aux y z) :=
begin
ext1,
change _ / _ = (_ * (_ / _) + _) * _,
rw denom_cocycle,
field_simp [denom_ne_zero, -denom, -num],
simp [matrix.mul, dot_product, fin.sum_univ_succ],
ring
end
/-- The action of `SL(2, ℝ)` on the upper half-plane by fractional linear transformations. -/
instance : mul_action SL(2, ℝ) ℍ :=
{ smul := smul_aux,
one_smul := λ z, by { ext1, change _ / _ = _, simp },
mul_smul := mul_smul' }
@[simp] lemma coe_smul (g : SL(2, ℝ)) (z : ℍ) : ↑(g • z) = num g z / denom g z := rfl
@[simp] lemma re_smul (g : SL(2, ℝ)) (z : ℍ) : (g • z).re = (num g z / denom g z).re := rfl
lemma im_smul (g : SL(2, ℝ)) (z : ℍ) : (g • z).im = (num g z / denom g z).im := rfl
lemma im_smul_eq_div_norm_sq (g : SL(2, ℝ)) (z : ℍ) :
(g • z).im = z.im / (complex.norm_sq (denom g z)) :=
smul_aux'_im g z
@[simp] lemma neg_smul (g : SL(2,ℝ)) (z : ℍ) : -g • z = g • z :=
begin
ext1,
change _ / _ = _ / _,
field_simp [denom_ne_zero, -denom, -num],
simp,
ring,
end
end upper_half_plane
|
bf6b6dc39657fe127ab65aa3b1821eeb475677e6 | 40ad357bbd0d327dd1e3e7f7beb868bd4e5b0a9d | /src/temporal_logic/refinement/one_to_one.lean | 08a48d34c17946aee80b17a8ea3ec11963aa6ad1 | [] | no_license | unitb/temporal-logic | 9966424f015976d5997a9ffa30cbd77cc3a9cb1c | accec04d1b09ca841be065511c9e206b725b16e9 | refs/heads/master | 1,633,868,382,769 | 1,541,072,223,000 | 1,541,072,223,000 | 114,790,987 | 5 | 3 | null | null | null | null | UTF-8 | Lean | false | false | 14,667 | lean | import .simulation
import ..scheduling
import ..spec
universe variables u u₀ u₁ u₂
open predicate nat
local infix ` ≃ `:75 := v_eq
local prefix `♯ `:0 := cast (by simp)
namespace temporal
namespace one_to_one
section
open fairness
parameters {α : Type u} {β : Type u₀} {γ : Type u₁ }
parameters {evt : Type u₂}
parameters {m₀ : mch' evt (γ×α)} {m₁ : mch' evt (γ×β)}
local notation `p` := m₀.init
local notation `q` := m₁.init
local notation `aevt` := m₀.evt
local notation `cevt` := m₁.evt
local notation `cs₀` := m₀.cs
local notation `fs₀` := m₀.fs
local notation `cs₁` := m₁.cs
local notation `fs₁` := m₁.fs
local notation `A` := m₀.A
local notation `C` := m₁.A
parameters (J : pred' (γ×α×β))
parameters (Jₐ : pred' (γ×α))
def C' (e : evt) : act (evt×γ×β) :=
λ ⟨sch,s⟩ ⟨_,s'⟩, sch = e ∧ C e s s'
abbreviation ae (i : evt) : event (γ×α) := ⟨cs₀ i,fs₀ i,A i⟩
abbreviation ce (i : evt) : event (evt×γ×β) := ⟨cs₁ i!pair.snd,fs₁ i!pair.snd,C' i⟩
section specs
parameters m₀ m₁
def SPEC₀.saf' (v : tvar α) (o : tvar γ) (sch : tvar evt) : cpred :=
spec_saf_spec m₀ ⦃o,v⦄ sch
def SPEC₀ (v : tvar α) (o : tvar γ) : cpred :=
spec m₀ ⦃o,v⦄
def SPEC₁ (v : tvar β) (o : tvar γ) : cpred :=
spec m₁ ⦃o,v⦄
def SPEC₂ (v : tvar β) (o : tvar γ) (s : tvar evt) : cpred :=
spec_sch m₁ ⦃o,v⦄ s
end specs
parameters [inhabited α] [inhabited evt]
parameter init_Jₐ : ∀ w o, (o,w) ⊨ p → (o,w) ⊨ Jₐ
parameter evt_Jₐ : ∀ w o w' o' e,
(o,w) ⊨ Jₐ →
(o,w) ⊨ cs₀ e →
(o,w) ⊨ fs₀ e →
A e (o,w) (o',w') →
(o',w') ⊨ Jₐ
parameter SIM₀ : ∀ v o, (o,v) ⊨ q → ∃ w, (o,w) ⊨ p ∧ (o,w,v) ⊨ J
parameter SIM
: ∀ w v o v' o' e,
(o,w,v) ⊨ J →
(o,w) ⊨ Jₐ →
(o,v) ⊨ cs₁ e →
(o,v) ⊨ fs₁ e →
C e (o,v) (o',v') →
∃ w', (o,w) ⊨ cs₀ e ∧
(o,w) ⊨ fs₀ e ∧
A e (o,w) (o',w') ∧
(o',w',v') ⊨ J
parameters (v : tvar β) (o : tvar γ) (sch : tvar evt)
variable (Γ : cpred)
parameters β γ
variable Hpo : ∀ w e sch,
one_to_one_po' (SPEC₁ v o ⋀ SPEC₀.saf' w o sch ⋀ ◻(J ! ⦃o,w,v⦄))
(ce e) (ae e) ⦃sch,o,v⦄ ⦃o,w⦄
parameters {β γ}
section SPEC₂
variables H : Γ ⊢ SPEC₂ v o sch
open prod temporal.prod
def Next_a : act $ (γ × evt) × α :=
λ σ σ',
∃ e, σ.1.2 = e ∧
map_left fst σ ⊨ cs₀ e ∧
map_left fst σ ⊨ fs₀ e ∧
(A e on map_left fst) σ σ'
def Next_c : act $ (γ × evt) × β :=
λ σ σ',
∃ e, σ.1.2 = e ∧
map_left fst σ ⊨ cs₁ e ∧
map_left fst σ ⊨ fs₁ e ∧
(C e on map_left fst) σ σ'
section J
def J' : pred' ((γ × evt) × α × β) :=
J ! ⟨ prod.map_left fst ⟩
def JJₐ : pred' ((γ × evt) × α) :=
Jₐ ! ⟨ prod.map_left fst ⟩
def p' : pred' ((γ × evt) × α) :=
p ! ⟨ prod.map_left fst ⟩
def q' : pred' ((γ × evt) × β) :=
q ! ⟨ prod.map_left fst ⟩
end J
variable w : tvar α
open simulation function
noncomputable def Wtn := Wtn p' Next_a J' v ⦃o,sch⦄
variable valid_witness
: Γ ⊢ Wtn w
lemma abstract_sch (e : evt)
: Γ ⊢ sch ≃ e ⋀ cs₀ e ! ⦃o,w⦄ ⋀ fs₀ e ! ⦃o,w⦄ ⋀ ⟦ o,w | A e ⟧ ≡
sch ≃ e ⋀ ⟦ ⦃o,sch⦄,w | Next_a ⟧ :=
begin
lifted_pred,
split ; intro h ; split
; casesm* _ ∧ _ ; try { assumption }
; simp [Next_a,on_fun] at * ; cc,
end
section Simulation_POs
include SIM₀
lemma SIM₀' (v : β) (o : γ × evt)
(h : (o, v) ⊨ q')
: (∃ (w : α), (o, w) ⊨ p' ∧ (o, w, v) ⊨ J') :=
begin
simp [q',prod.map_left] at h,
specialize SIM₀ v o.1 h,
revert SIM₀, intros_mono,
simp [J',p',map], intros,
constructor_matching* [Exists _, _ ∧ _] ;
tauto,
end
omit SIM₀
include SIM
lemma SIM' (w : α) (v : β) (o : γ × evt) (v' : β) (o' : γ × evt)
(h₀ : (o, w, v) ⊨ J')
(h₃ : (o, w) ⊨ JJₐ)
(h₄ : Next_c (o, v) (o', v'))
: (∃ w', Next_a (o,w) (o',w') ∧ (o', w', v') ⊨ J') :=
begin
simp [J',map] at h₀,
simp [Next_c,on_fun] at h₄,
casesm* _ ∧ _,
simp [JJₐ] at h₃,
specialize SIM w v o.1 v' o'.1 o.2 h₀ _ _ _ _
; try { assumption },
cases SIM with w' SIM,
existsi [w'],
simp [Next_a, J',on_fun,map,h₀],
tauto,
end
include H
omit SIM
lemma H'
: Γ ⊢ simulation.SPEC₁ q' Next_c v ⦃o,sch⦄ :=
begin [temporal]
simp [SPEC₂,simulation.SPEC₁,q'] at H ⊢,
split, tauto,
casesm* _ ⋀ _,
select h : ◻p_exists _,
henceforth! at h ⊢,
cases h with e h,
explicit' [Next_c,sched] with h
{ casesm* _ ∧ _, subst e, tauto, }
end
omit H
section
include init_Jₐ
lemma init_Jₐ' (w : α) (o : γ × evt)
(h : (o, w) ⊨ p')
: (o, w) ⊨ JJₐ :=
by { cases o, simp [JJₐ,p'] at *, solve_by_elim }
end
section
include evt_Jₐ
lemma evt_Jₐ' (w : α) (o : γ × evt) (w' : α) (o' : γ × evt)
(h₀ : (o, w) ⊨ JJₐ)
(h₁ : Next_a (o, w) (o', w'))
: (o', w') ⊨ JJₐ :=
by { cases o, simp [JJₐ,p',Next_a,on_fun] at *, tauto }
end
include SIM₀ SIM init_Jₐ evt_Jₐ H
lemma witness_imp_SPEC₀_saf
(h : Γ ⊢ Wtn w)
: Γ ⊢ SPEC₀.saf' w o sch :=
begin [temporal]
have hJ := J_inv_in_w p' q'
temporal.one_to_one.Next_a
temporal.one_to_one.Next_c
temporal.one_to_one.J'
temporal.one_to_one.JJₐ
temporal.one_to_one.init_Jₐ'
temporal.one_to_one.evt_Jₐ'
temporal.one_to_one.SIM₀'
temporal.one_to_one.SIM'
v ⦃o,sch⦄ Γ
(temporal.one_to_one.H' _ H) _ h,
have hJ' := abs_J_inv_in_w p' q'--
temporal.one_to_one.Next_a
temporal.one_to_one.Next_c
temporal.one_to_one.J'
temporal.one_to_one.JJₐ
temporal.one_to_one.init_Jₐ'
temporal.one_to_one.evt_Jₐ'
temporal.one_to_one.SIM₀'
temporal.one_to_one.SIM'
v ⦃o,sch⦄ Γ
(temporal.one_to_one.H' _ H)
_ h ,
simp [SPEC₀.saf',SPEC₂,Wtn,simulation.Wtn] at h ⊢ H,
casesm* _ ⋀ _,
split,
{ clear SIM hJ,
select h : w ≃ _,
select h' : q ! _,
rw [← pair.snd_mk sch w,h],
explicit
{ simp [Wx₀] at ⊢ h', unfold_coes,
simp [Wx₀_f,p',J',map],
cases SIM₀ (σ ⊨ v) (σ ⊨ o) h',
apply_epsilon_spec, } },
{ clear SIM₀,
select h : ◻(_ ≃ _),
select h' : ◻(p_exists _),
henceforth! at h h' ⊢ hJ hJ',
explicit' [Wf,Wf_f,J',JJₐ]
with h h' hJ hJ'
{ simp [Next_a,on_fun] at h h',
casesm* [_ ∧ _,Exists _],
subst w', subst h'_w,
apply_epsilon_spec,
have : (∃ (w' : α), (o, w) ⊨ cs₀ sch ∧
(o, w) ⊨ fs₀ sch ∧ A sch (o, w) (o', w') ∧ (o', w', v') ⊨ J), solve_by_elim,
cases this, tauto, } },
end
omit H
parameters p q cs₁ fs₁
include Hpo p
lemma SPEC₂_imp_SPEC₁
: (SPEC₂ v o sch) ⟹ (SPEC₁ v o) :=
begin [temporal]
simp only [SPEC₁,SPEC₂,temporal.one_to_one.SPEC₁,temporal.one_to_one.SPEC₂],
monotonicity, apply ctx_p_and_p_imp_p_and',
{ monotonicity, simp, intros x h₀ h₁ _ _,
existsi x, tauto, },
{ intros h i h₀ h₁,
replace h := h _ h₀ h₁,
revert h, monotonicity, simp, }
end
lemma H_C_imp_A (e : evt)
: SPEC₂ v o sch ⋀ Wtn w ⋀ ◻(J ! ⦃o,w,v⦄) ⟹
◻(cs₁ e ! ⦃o,v⦄ ⋀ fs₁ e ! ⦃o,v⦄ ⋀ sch ≃ ↑e ⋀ ⟦ o,v | C e ⟧ ⟶
cs₀ e ! ⦃o,w⦄ ⋀ fs₀ e ! ⦃o,w⦄ ⋀ ⟦ o,w | A e ⟧) :=
begin [temporal]
intro H',
have H : temporal.one_to_one.SPEC₁ v o ⋀
temporal.one_to_one.Wtn w ⋀
◻(J ! ⦃o,w,v⦄),
{ revert H', persistent,
intro, casesm* _ ⋀ _, split* ; try { assumption },
apply temporal.one_to_one.SPEC₂_imp_SPEC₁ _ Γ _,
solve_by_elim, casesm* _ ⋀ _, solve_by_elim, },
clear Hpo,
let J' := temporal.one_to_one.J',
have init_Jₐ' := temporal.one_to_one.init_Jₐ', clear init_Jₐ,
have evt_Jₐ' := temporal.one_to_one.evt_Jₐ', clear evt_Jₐ,
have SIM₀' := temporal.one_to_one.SIM₀', clear SIM₀,
have SIM' := temporal.one_to_one.SIM', clear SIM,
have := C_imp_A_in_w p' _ (Next_a A) (Next_c C) J' _
init_Jₐ' evt_Jₐ'
SIM₀' SIM' v ⦃o,sch⦄ Γ _ w _,
{ henceforth! at this ⊢,
simp, intros h₀ h₁ h₂ h₃, clear_except this h₀ h₁ h₂ h₃,
suffices : sch ≃ ↑e ⋀ cs₀ e ! ⦃o,w⦄ ⋀ fs₀ e ! ⦃o,w⦄ ⋀ ⟦ o,w | A e ⟧,
{ tauto },
rw abstract_sch, split, assumption,
apply this _,
simp [Next_c],
suffices : ⟦ ⦃o,sch⦄,v | λ (σ σ' : (γ × evt) × β), (σ.fst).snd = e ∧ (C e on map_left fst) σ σ' ⟧,
{ explicit' with h₀ h₁ h₂ h₃ { cc, }, },
rw [← action_and_action,← init_eq_action,action_on'], split,
explicit
{ simp at ⊢ h₀, assumption },
simp [h₃], },
clear_except H',
simp [simulation.SPEC₁,SPEC₂,temporal.one_to_one.SPEC₂] at H' ⊢,
cases_matching* _ ⋀ _, split,
{ simp [q'], assumption, },
{ select H' : ◻(p_exists _), clear_except H',
henceforth at H' ⊢, cases H' with i H',
simp [Next_c],
suffices : ⟦ ⦃o,sch⦄,v | λ (σ σ' : (γ × evt) × β), (σ.fst).snd = i ∧ (C i on map_left fst) σ σ' ⟧,
{ explicit'* { cases this, subst i, tauto, } },
explicit'* { cc }, },
{ cases_matching* _ ⋀ _, assumption, },
end
lemma Hpo' (e : evt)
: one_to_one_po (SPEC₂ v o sch ⋀ Wtn w ⋀ ◻(J ! ⦃o,w,v⦄))
/- -/ (cs₁ e ! ⦃o,v⦄)
(fs₁ e ! ⦃o,v⦄)
(sch ≃ ↑e ⋀ ⟦ o,v | C e ⟧)
/- -/ (cs₀ e ! ⦃o,w⦄)
(fs₀ e ! ⦃o,w⦄)
⟦ o,w | A e ⟧ :=
begin
have
: temporal.one_to_one.SPEC₂ v o sch ⋀ temporal.one_to_one.Wtn w ⋀ ◻(J ! ⦃o,w,v⦄) ⟹
temporal.one_to_one.SPEC₁ v o ⋀ temporal.one_to_one.SPEC₀.saf' w o sch ⋀ ◻(J ! ⦃o,w,v⦄),
begin [temporal]
simp, intros h₀ h₁ h₂,
split*,
{ apply temporal.one_to_one.SPEC₂_imp_SPEC₁ Hpo _ h₀, },
{ apply temporal.one_to_one.witness_imp_SPEC₀_saf ; solve_by_elim, },
{ solve_by_elim }
end,
constructor,
iterate 3
{ cases (Hpo w e sch),
simp at *,
transitivity,
{ apply this },
{ assumption }, },
begin [temporal]
intros Hs,
have H_imp := temporal.one_to_one.H_C_imp_A Hpo w e _ Hs,
henceforth! at ⊢ H_imp,
simp at H_imp ⊢,
exact H_imp,
end
end
end Simulation_POs
include H SIM₀ SIM Hpo init_Jₐ evt_Jₐ
lemma sched_ref (i : evt) (w : tvar α)
(Hw : Γ ⊢ Wtn w)
(h : Γ ⊢ sched (cs₁ i ! ⦃o,v⦄) (fs₁ i ! ⦃o,v⦄) (sch ≃ ↑i ⋀ ⟦ o,v | C i ⟧))
: Γ ⊢ sched (cs₀ i ! ⦃o,w⦄) (fs₀ i ! ⦃o,w⦄)
⟦ o,w | A i ⟧ :=
begin [temporal]
have H' := one_to_one.H' C v o sch _ H,
have hJ : ◻(J' J ! ⦃⦃o,sch⦄,w,v⦄),
{ replace SIM₀ := SIM₀' _ SIM₀,
replace SIM := SIM' A C J _ SIM,
apply simulation.J_inv_in_w p' q' (Next_a A) _ (J' J) _ _ _ SIM₀ SIM _ ⦃o,sch⦄ _ H' w Hw,
apply temporal.one_to_one.init_Jₐ',
apply temporal.one_to_one.evt_Jₐ' },
simp [J'] at hJ,
have Hpo' := temporal.one_to_one.Hpo' Hpo w i,
apply replacement Hpo' Γ _,
tauto, solve_by_elim,
end
lemma one_to_one
: Γ ⊢ ∃∃ w, SPEC₀ w o :=
begin [temporal]
select_witness w : temporal.one_to_one.Wtn w
with Hw using J,
have this := H, revert this,
dsimp [SPEC₀,SPEC₁],
have H' := temporal.one_to_one.H' , -- o sch,
apply ctx_p_and_p_imp_p_and' _ _,
apply ctx_p_and_p_imp_p_and' _ _,
{ clear_except SIM₀ Hw H,
replace SIM₀ := temporal.one_to_one.SIM₀',
have := init_in_w p' q' (Next_a A) (J' J) SIM₀ v ⦃o,sch⦄ Γ _ Hw,
intro Hq,
simp [p',q'] at this,
solve_by_elim, },
{ clear_except SIM SIM₀ Hw H init_Jₐ evt_Jₐ,
have H' := H' C v o sch _ H,
replace SIM₀ := SIM₀' _ SIM₀,
replace SIM := SIM' A C J _ SIM,
have := temporal.simulation.C_imp_A_in_w p' q'
(Next_a A) (Next_c C) (J' J) _ _ _ SIM₀ SIM v ⦃o,sch⦄ _ H' w Hw,
{ monotonicity!,
simp [exists_action],
intros e h₀ h₁ h₂ h₃, replace this := this _,
explicit'* [Next_a]
{ intros, casesm* _ ∧ _,
constructor_matching* [Exists _,_ ∧ _] ; solve_by_elim, },
simp [Next_c],
suffices : ⟦ ⦃o,sch⦄,v | λ (σ σ' : (γ × evt) × β), map_left prod.fst σ ⊨ fs₁ e ∧ ((λ s s', s = e) on (prod.snd ∘ prod.fst)) σ σ' ∧ (C e on map_left prod.fst) σ σ' ⟧,
explicit' with h₀ h₁ this
{ intros, subst e, tauto, },
henceforth at this,
explicit'* [Next_c]
{ tauto } },
{ apply temporal.one_to_one.init_Jₐ' },
{ apply temporal.one_to_one.evt_Jₐ' }, },
{ intros h i,
replace h := h i,
apply temporal.one_to_one.sched_ref; solve_by_elim },
end
end SPEC₂
section refinement_SPEC₂
include Hpo SIM₀ SIM init_Jₐ evt_Jₐ
parameters m₁ m₀
lemma refinement_SPEC₂
: Γ ⊢ (∃∃ sch, SPEC₂ v o sch) ⟶ (∃∃ a, SPEC₀ a o) :=
begin [temporal]
simp, intros sch Hc,
apply one_to_one J Jₐ init_Jₐ evt_Jₐ SIM₀ SIM _ _ _ _ _ Hc,
apply Hpo,
end
end refinement_SPEC₂
lemma refinement_SPEC₁ [schedulable evt]
: SPEC₁ v o ⟹ (∃∃ sch, SPEC₂ v o sch) :=
assume Γ,
sch_intro _ _ _ _ _ _
include SIM₀ SIM init_Jₐ evt_Jₐ
lemma refinement [schedulable evt]
(h : ∀ c a e sch, one_to_one_po' (SPEC₁ c o ⋀ SPEC₀.saf' a o sch ⋀ ◻(J ! ⦃o,a,c⦄))
⟨cs₁ e!pair.snd,fs₁ e!pair.snd,C' e⟩
⟨cs₀ e,fs₀ e,A e⟩ ⦃sch,o,c⦄ ⦃o,a⦄)
: (∃∃ c, SPEC₁ c o) ⟹ (∃∃ a, SPEC₀ a o) :=
begin [temporal]
transitivity (∃∃ c sch, SPEC₂ q C cs₁ fs₁ c o sch),
{ apply p_exists_p_imp_p_exists ,
intro v,
apply refinement_SPEC₁, },
{ simp, intros c sch Hspec,
specialize h c, simp [one_to_one_po'] at h,
apply refinement_SPEC₂ A C cs₀ fs₀ cs₁ fs₁ J Jₐ init_Jₐ evt_Jₐ SIM₀ SIM c o _ _ _,
simp [one_to_one_po'],
exact h,
existsi sch, assumption },
end
end
end one_to_one
end temporal
|
3a47f42aa617d154c52446cbf91c021a2c6aad2e | 05f637fa14ac28031cb1ea92086a0f4eb23ff2b1 | /tests/lean/exists4.lean | a1dbeb15f74f377fe615230183633c7e72642c99 | [
"Apache-2.0"
] | permissive | codyroux/lean0.1 | 1ce92751d664aacff0529e139083304a7bbc8a71 | 0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef | refs/heads/master | 1,610,830,535,062 | 1,402,150,480,000 | 1,402,150,480,000 | 19,588,851 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 664 | lean | variable N : Type
variables a b c : N
variables P : N -> N -> N -> Bool
axiom H3 : P a b c
theorem T1 : exists x y z : N, P x y z := @exists_intro N (fun x : N, exists y z : N, P x y z) a
(@exists_intro N _ b
(@exists_intro N (fun z : N, P a b z) c H3))
theorem T2 : exists x y z : N, P x y z := exists_intro a (exists_intro b (exists_intro c H3))
theorem T3 : exists x y z : N, P x y z := exists_intro _ (exists_intro _ (exists_intro _ H3))
theorem T4 (H : P a a b) : exists x y z, P x y z := exists_intro _ (exists_intro _ (exists_intro _ H))
print environment 4 |
6d0b5bc9bb78fef5c8369d41eea8678ea2eb31d5 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/ring_theory/polynomial/basic.lean | b9aa05f7fcaee7543b675fec32b0fd09d7bf4f1c | [
"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 | 23,561 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Ring-theoretic supplement of data.polynomial.
Main result: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
-/
import algebra.char_p
import data.mv_polynomial
import data.polynomial.field_division
import ring_theory.principal_ideal_domain
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
universes u v w
namespace polynomial
instance {R : Type u} [semiring R] (p : ℕ) [h : char_p R p] : char_p (polynomial R) p :=
let ⟨h⟩ := h in ⟨λ n, by rw [← C.map_nat_cast, ← C_0, C_inj, h]⟩
variables (R : Type u) [comm_ring R]
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
⨅ k : ℕ, ⨅ h : ↑k > n, (lcoeff R k).ker
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/
def degree_lt (n : ℕ) : submodule R (polynomial R) :=
⨅ k : ℕ, ⨅ h : k ≥ n, (lcoeff R k).ker
variable {R}
theorem mem_degree_le {n : with_bot ℕ} {f : polynomial R} :
f ∈ degree_le R n ↔ degree f ≤ n :=
by simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl
@[mono] theorem degree_le_mono {m n : with_bot ℕ} (H : m ≤ n) :
degree_le R m ≤ degree_le R n :=
λ f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H)
theorem degree_le_eq_span_X_pow {n : ℕ} :
degree_le R n = submodule.span R ↑((finset.range (n+1)).image (λ n, X^n) : finset (polynomial R)) :=
begin
apply le_antisymm,
{ intros p hp, replace hp := mem_degree_le.1 hp,
rw [← finsupp.sum_single p, finsupp.sum],
refine submodule.sum_mem _ (λ k hk, _),
show monomial _ _ ∈ _,
have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk),
rw [single_eq_C_mul_X, C_mul'],
refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $
finset.mem_image.2 ⟨_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl⟩) },
rw [submodule.span_le, finset.coe_image, set.image_subset_iff],
intros k hk, apply mem_degree_le.2,
apply le_trans (degree_X_pow_le _) (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk)
end
theorem mem_degree_lt {n : ℕ} {f : polynomial R} :
f ∈ degree_lt R n ↔ degree f < n :=
by { simp_rw [degree_lt, submodule.mem_infi, linear_map.mem_ker, degree,
finset.sup_lt_iff (with_bot.bot_lt_coe n), finsupp.mem_support_iff, with_bot.some_eq_coe,
with_bot.coe_lt_coe, lt_iff_not_ge', ne, not_imp_not], refl }
@[mono] theorem degree_lt_mono {m n : ℕ} (H : m ≤ n) :
degree_lt R m ≤ degree_lt R n :=
λ f hf, mem_degree_lt.2 (lt_of_lt_of_le (mem_degree_lt.1 hf) $ with_bot.coe_le_coe.2 H)
theorem degree_lt_eq_span_X_pow {n : ℕ} :
degree_lt R n = submodule.span R ↑((finset.range n).image (λ n, X^n) : finset (polynomial R)) :=
begin
apply le_antisymm,
{ intros p hp, replace hp := mem_degree_lt.1 hp,
rw [← finsupp.sum_single p, finsupp.sum],
refine submodule.sum_mem _ (λ k hk, _),
show monomial _ _ ∈ _,
have := with_bot.coe_lt_coe.1 ((finset.sup_lt_iff $ with_bot.bot_lt_coe n).1 hp k hk),
rw [single_eq_C_mul_X, C_mul'],
refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $
finset.mem_image.2 ⟨_, finset.mem_range.2 this, rfl⟩) },
rw [submodule.span_le, finset.coe_image, set.image_subset_iff],
intros k hk, apply mem_degree_lt.2,
exact lt_of_le_of_lt (degree_X_pow_le _) (with_bot.coe_lt_coe.2 $ finset.mem_range.1 hk)
end
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : polynomial R) : polynomial (ring.closure (↑p.frange : set R)) :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem
else ring.subset_closure $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
@[simp] theorem coeff_restriction {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl
@[simp] theorem coeff_restriction' {p : polynomial R} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := rfl
@[simp] theorem map_restriction (p : polynomial R) : p.restriction.map (algebra_map _ _) = p :=
ext $ λ n, by rw [coeff_map, algebra.subring_algebra_map_apply, coeff_restriction]
@[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl
@[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
@[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl
@[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 :=
ext $ λ i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl
variables {S : Type v} [ring S] {f : R →+* S} {x : S}
theorem eval₂_restriction {p : polynomial R} :
eval₂ f x p = eval₂ (f.comp (is_subring.subtype _)) x p.restriction :=
by { dsimp only [eval₂_eq_sum], refl, }
section to_subring
variables (p : polynomial R) (T : set R) [is_subring T]
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T. -/
def to_subring (hp : ↑p.frange ⊆ T) : polynomial T :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem
else hp $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
variables (hp : ↑p.frange ⊆ T)
include hp
@[simp] theorem coeff_to_subring {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl
@[simp] theorem coeff_to_subring' {n : ℕ} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl
@[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl
@[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_to_subring : monic (to_subring p T hp) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
omit hp
@[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl
@[simp] theorem to_subring_one : to_subring (1 : polynomial R) T
(set.subset.trans (finset.coe_subset.2 finsupp.frange_single)
(finset.singleton_subset_set_iff.2 is_submonoid.one_mem)) = 1 :=
ext $ λ i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl
@[simp] theorem map_to_subring : (p.to_subring T hp).map (is_subring.subtype T) = p :=
ext $ λ n, coeff_map _ _
end to_subring
variables (T : set R) [is_subring T]
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefificents are in the ambient ring. -/
def of_subring (p : polynomial T) : polynomial R :=
⟨p.support, subtype.val ∘ p.to_fun,
λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff
⟨λ h, congr_arg subtype.val h, λ h, subtype.eq h⟩)⟩
@[simp] theorem frange_of_subring {p : polynomial T} :
↑(p.of_subring T).frange ⊆ T :=
λ y H, let ⟨hy, x, hx⟩ := finsupp.mem_frange.1 H in hx ▸ (p.to_fun x).2
end polynomial
variables {R : Type u} {σ : Type v} {M : Type w} [comm_ring R] [add_comm_group M] [module R M]
namespace ideal
open polynomial
/-- The push-forward of an ideal `I` of `R` to `polynomial R` via inclusion
is exactly the set of polynomials whose coefficients are in `I` -/
theorem mem_map_C_iff {I : ideal R} {f : polynomial R} :
f ∈ (ideal.map C I : ideal (polynomial R)) ↔ ∀ n : ℕ, f.coeff n ∈ I :=
begin
split,
{ intros hf,
apply submodule.span_induction hf,
{ intros f hf n,
cases (set.mem_image _ _ _).mp hf with x hx,
rw [← hx.right, coeff_C],
by_cases (n = 0),
{ simpa [h] using hx.left },
{ simp [h] } },
{ simp },
{ exact λ f g hf hg n, by simp [I.add_mem (hf n) (hg n)] },
{ refine λ f g hg n, _,
rw [smul_eq_mul, coeff_mul],
exact I.sum_mem (λ c hc, I.smul_mem (f.coeff c.fst) (hg c.snd)) } },
{ intros hf,
rw ← sum_monomial_eq f,
refine (map C I : ideal (polynomial R)).sum_mem (λ n hn, _),
simp [single_eq_C_mul_X],
rw mul_comm,
exact (map C I : ideal (polynomial R)).smul_mem _ (mem_map_of_mem (hf n)) }
end
lemma quotient_map_C_eq_zero {I : ideal R} :
∀ a ∈ I, ((quotient.mk (map C I : ideal (polynomial R))).comp C) a = 0 :=
begin
intros a ha,
rw [ring_hom.comp_apply, quotient.eq_zero_iff_mem],
exact mem_map_of_mem ha,
end
lemma eval₂_C_mk_eq_zero {I : ideal R} :
∀ f ∈ (map C I : ideal (polynomial R)), eval₂_ring_hom (C.comp (quotient.mk I)) X f = 0 :=
begin
intros a ha,
rw ← sum_monomial_eq a,
dsimp,
rw eval₂_sum (C.comp (quotient.mk I)) a monomial X,
refine finset.sum_eq_zero (λ n hn, _),
dsimp,
rw eval₂_monomial (C.comp (quotient.mk I)) X,
refine mul_eq_zero_of_left (polynomial.ext (λ m, _)) (X ^ n),
erw coeff_C,
by_cases h : m = 0,
{ simpa [h] using quotient.eq_zero_iff_mem.2 ((mem_map_C_iff.1 ha) n) },
{ simp [h] }
end
/-- If `I` is an ideal of `R`, then the ring polynomials over the quotient ring `I.quotient` is
isomorphic to the quotient of `polynomial R` by the ideal `map C I`,
where `map C I` contains exactly the polynomials whose coefficients all lie in `I` -/
def polynomial_quotient_equiv_quotient_polynomial {I : ideal R} :
polynomial (I.quotient) ≃+* (map C I : ideal (polynomial R)).quotient :=
{ to_fun := eval₂_ring_hom
(quotient.lift I ((quotient.mk (map C I : ideal (polynomial R))).comp C) quotient_map_C_eq_zero)
((quotient.mk (map C I : ideal (polynomial R)) X)),
inv_fun := quotient.lift (map C I : ideal (polynomial R))
(eval₂_ring_hom (C.comp (quotient.mk I)) X) eval₂_C_mk_eq_zero,
map_mul' := λ f g, by simp,
map_add' := λ f g, by simp,
left_inv := begin
intro f,
apply polynomial.induction_on' f,
{ simp_intros p q hp hq,
rw [hp, hq] },
{ rintros n ⟨x⟩,
simp [monomial_eq_smul_X, C_mul'] }
end,
right_inv := begin
rintro ⟨f⟩,
apply polynomial.induction_on' f,
{ simp_intros p q hp hq,
rw [hp, hq] },
{ intros n a,
simp [monomial_eq_smul_X, ← C_mul' a (X ^ n)] },
end,
}
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) :=
{ carrier := I.carrier,
zero_mem' := I.zero_mem,
add_mem' := λ _ _, I.add_mem,
smul_mem' := λ c x H, by rw [← C_mul']; exact submodule.smul_mem _ _ H }
variables {I : ideal (polynomial R)}
theorem mem_of_polynomial (x) : x ∈ I.of_polynomial ↔ x ∈ I := iff.rfl
variables (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
degree_le R n ⊓ I.of_polynomial
/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of
leading coefficients of polynomials in `I` with degree ≤ `n`. -/
def leading_coeff_nth (n : ℕ) : ideal R :=
(I.degree_le n).map $ lcoeff R n
theorem mem_leading_coeff_nth (n : ℕ) (x) :
x ∈ I.leading_coeff_nth n ↔ ∃ p ∈ I, degree p ≤ n ∧ leading_coeff p = x :=
begin
simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le],
split,
{ rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩,
cases lt_or_eq_of_le hpdeg with hpdeg hpdeg,
{ refine ⟨0, I.zero_mem, bot_le, _⟩,
rw [leading_coeff_zero, eq_comm],
exact coeff_eq_zero_of_degree_lt hpdeg },
{ refine ⟨p, hpI, le_of_eq hpdeg, _⟩,
rw [leading_coeff, nat_degree, hpdeg], refl } },
{ rintro ⟨p, hpI, hpdeg, rfl⟩,
have : nat_degree p + (n - nat_degree p) = n,
{ exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) },
refine ⟨p * X ^ (n - nat_degree p), ⟨_, I.mul_mem_right hpI⟩, _⟩,
{ apply le_trans (degree_mul_le _ _) _,
apply le_trans (add_le_add (degree_le_nat_degree) (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, this],
exact le_refl _ },
{ rw [leading_coeff, ← coeff_mul_X_pow p (n - nat_degree p), this] } }
end
theorem mem_leading_coeff_nth_zero (x) :
x ∈ I.leading_coeff_nth 0 ↔ C x ∈ I :=
(mem_leading_coeff_nth _ _ _).trans
⟨λ ⟨p, hpI, hpdeg, hpx⟩, by rwa [← hpx, leading_coeff,
nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg),
← eq_C_of_degree_le_zero hpdeg],
λ hx, ⟨C x, hx, degree_C_le, leading_coeff_C x⟩⟩
theorem leading_coeff_nth_mono {m n : ℕ} (H : m ≤ n) :
I.leading_coeff_nth m ≤ I.leading_coeff_nth n :=
begin
intros r hr,
simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr ⊢,
rcases hr with ⟨p, hpI, hpdeg, rfl⟩,
refine ⟨p * X ^ (n - m), I.mul_mem_right hpI, _, leading_coeff_mul_X_pow⟩,
refine le_trans (degree_mul_le _ _) _,
refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, nat.add_sub_cancel' H],
exact le_refl _
end
/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the
leading coefficients in `I`. -/
def leading_coeff : ideal R :=
⨆ n : ℕ, I.leading_coeff_nth n
theorem mem_leading_coeff (x) :
x ∈ I.leading_coeff ↔ ∃ p ∈ I, polynomial.leading_coeff p = x :=
begin
rw [leading_coeff, submodule.mem_supr_of_directed],
simp only [mem_leading_coeff_nth],
{ split, { rintro ⟨i, p, hpI, hpdeg, rfl⟩, exact ⟨p, hpI, rfl⟩ },
rintro ⟨p, hpI, rfl⟩, exact ⟨nat_degree p, p, hpI, degree_le_nat_degree, rfl⟩ },
intros i j, exact ⟨i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _),
I.leading_coeff_nth_mono (nat.le_add_left _ _)⟩
end
theorem is_fg_degree_le [is_noetherian_ring R] (n : ℕ) :
submodule.fg (I.degree_le n) :=
is_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _
⟨_, degree_le_eq_span_X_pow.symm⟩) _
end ideal
/-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/
protected theorem polynomial.is_noetherian_ring [is_noetherian_ring R] :
is_noetherian_ring (polynomial R) :=
⟨assume I : ideal (polynomial R),
let L := I.leading_coeff in
let M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance))
(set.range I.leading_coeff_nth) ⟨_, ⟨0, rfl⟩⟩ in
have hm : M ∈ set.range I.leading_coeff_nth := well_founded.min_mem _ _ _,
let ⟨N, HN⟩ := hm, ⟨s, hs⟩ := I.is_fg_degree_le N in
have hm2 : ∀ k, I.leading_coeff_nth k ≤ M := λ k, or.cases_on (le_or_lt k N)
(λ h, HN ▸ I.leading_coeff_nth_mono h)
(λ h x hx, classical.by_contradiction $ λ hxm,
have ¬M < I.leading_coeff_nth k, by refine well_founded.not_lt_min
(well_founded_submodule_gt _ _) _ _ _; exact ⟨k, rfl⟩,
this ⟨HN ▸ I.leading_coeff_nth_mono (le_of_lt h), λ H, hxm (H hx)⟩),
have hs2 : ∀ {x}, x ∈ I.degree_le N → x ∈ ideal.span (↑s : set (polynomial R)),
from hs ▸ λ x hx, submodule.span_induction hx (λ _ hx, ideal.subset_span hx) (ideal.zero_mem _)
(λ _ _, ideal.add_mem _) (λ c f hf, f.C_mul' c ▸ ideal.mul_mem_left _ hf),
⟨s, le_antisymm (ideal.span_le.2 $ λ x hx, have x ∈ I.degree_le N, from hs ▸ submodule.subset_span hx, this.2) $ begin
change I ≤ ideal.span ↑s,
intros p hp, generalize hn : p.nat_degree = k,
induction k using nat.strong_induction_on with k ih generalizing p,
cases le_or_lt k N,
{ subst k, refine hs2 ⟨polynomial.mem_degree_le.2
(le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp⟩ },
{ have hp0 : p ≠ 0,
{ rintro rfl, cases hn, exact nat.not_lt_zero _ h },
have : (0 : R) ≠ 1,
{ intro h, apply hp0, ext i, refine (mul_one _).symm.trans _,
rw [← h, mul_zero], refl },
haveI : nontrivial R := ⟨⟨0, 1, this⟩⟩,
have : p.leading_coeff ∈ I.leading_coeff_nth N,
{ rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2
⟨_, hp, hn ▸ polynomial.degree_le_nat_degree, rfl⟩) },
rw I.mem_leading_coeff_nth at this,
rcases this with ⟨q, hq, hdq, hlqp⟩,
have hq0 : q ≠ 0,
{ intro H, rw [← polynomial.leading_coeff_eq_zero] at H,
rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H },
have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree,
{ rw [polynomial.degree_mul', polynomial.degree_X_pow],
rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0],
rw [← with_bot.coe_add, nat.add_sub_cancel', hn],
{ refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) },
rw [polynomial.leading_coeff_X_pow, mul_one],
exact mt polynomial.leading_coeff_eq_zero.1 hq0 },
have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff,
{ rw [← hlqp, polynomial.leading_coeff_mul_X_pow] },
have := polynomial.degree_sub_lt h1 hp0 h2,
rw [polynomial.degree_eq_nat_degree hp0] at this,
rw ← sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)),
refine (ideal.span ↑s).add_mem _ ((ideal.span ↑s).mul_mem_right _),
{ by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0,
{ rw hpq, exact ideal.zero_mem _ },
refine ih _ _ (I.sub_mem hp (I.mul_mem_right hq)) rfl,
rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this },
exact hs2 ⟨polynomial.mem_degree_le.2 hdq, hq⟩ }
end⟩⟩
attribute [instance] polynomial.is_noetherian_ring
namespace polynomial
theorem exists_irreducible_of_degree_pos {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : 0 < f.degree) : ∃ g, irreducible g ∧ g ∣ f :=
is_noetherian_ring.exists_irreducible_factor
(λ huf, ne_of_gt hf $ degree_eq_zero_of_is_unit huf)
(λ hf0, not_lt_of_lt hf $ hf0.symm ▸ (@degree_zero R _).symm ▸ with_bot.bot_lt_coe _)
theorem exists_irreducible_of_nat_degree_pos {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : 0 < f.nat_degree) : ∃ g, irreducible g ∧ g ∣ f :=
exists_irreducible_of_degree_pos $ by { contrapose! hf, exact nat_degree_le_of_degree_le hf }
theorem exists_irreducible_of_nat_degree_ne_zero {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : f.nat_degree ≠ 0) : ∃ g, irreducible g ∧ g ∣ f :=
exists_irreducible_of_nat_degree_pos $ nat.pos_of_ne_zero hf
lemma linear_independent_powers_iff_eval₂
(f : M →ₗ[R] M) (v : M) :
linear_independent R (λ n : ℕ, (f ^ n) v)
↔ ∀ (p : polynomial R), polynomial.eval₂ (algebra_map _ _) f p v = 0 → p = 0 :=
begin
rw linear_independent_iff,
simp only [finsupp.total_apply, eval₂_endomorphism_algebra_map],
refl
end
end polynomial
namespace mv_polynomial
lemma is_noetherian_ring_fin_0 [is_noetherian_ring R] :
is_noetherian_ring (mv_polynomial (fin 0) R) :=
is_noetherian_ring_of_ring_equiv R
((mv_polynomial.pempty_ring_equiv R).symm.trans
(mv_polynomial.ring_equiv_of_equiv _ fin_zero_equiv'.symm))
theorem is_noetherian_ring_fin [is_noetherian_ring R] :
∀ {n : ℕ}, is_noetherian_ring (mv_polynomial (fin n) R)
| 0 := is_noetherian_ring_fin_0
| (n+1) :=
@is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _ _ _
(mv_polynomial.fin_succ_equiv _ n).symm
(@polynomial.is_noetherian_ring (mv_polynomial (fin n) R) _ (is_noetherian_ring_fin))
/-- The multivariate polynomial ring in finitely many variables over a noetherian ring
is itself a noetherian ring. -/
instance is_noetherian_ring [fintype σ] [is_noetherian_ring R] :
is_noetherian_ring (mv_polynomial σ R) :=
trunc.induction_on (fintype.equiv_fin σ) $ λ e,
@is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) _ _ _
(mv_polynomial.ring_equiv_of_equiv _ e.symm) is_noetherian_ring_fin
lemma is_integral_domain_fin_zero (R : Type u) [comm_ring R] (hR : is_integral_domain R) :
is_integral_domain (mv_polynomial (fin 0) R) :=
ring_equiv.is_integral_domain R hR
((ring_equiv_of_equiv R fin_zero_equiv').trans (mv_polynomial.pempty_ring_equiv R))
/-- Auxilliary lemma:
Multivariate polynomials over an integral domain
with variables indexed by `fin n` form an integral domain.
This fact is proven inductively,
and then used to prove the general case without any finiteness hypotheses.
See `mv_polynomial.integral_domain` for the general case. -/
lemma is_integral_domain_fin (R : Type u) [comm_ring R] (hR : is_integral_domain R) :
∀ (n : ℕ), is_integral_domain (mv_polynomial (fin n) R)
| 0 := is_integral_domain_fin_zero R hR
| (n+1) :=
ring_equiv.is_integral_domain
(polynomial (mv_polynomial (fin n) R))
(is_integral_domain_fin n).polynomial
(mv_polynomial.fin_succ_equiv _ n)
lemma is_integral_domain_fintype (R : Type u) (σ : Type v) [comm_ring R] [fintype σ]
(hR : is_integral_domain R) : is_integral_domain (mv_polynomial σ R) :=
trunc.induction_on (fintype.equiv_fin σ) $ λ e,
@ring_equiv.is_integral_domain _ (mv_polynomial (fin $ fintype.card σ) R) _ _
(mv_polynomial.is_integral_domain_fin _ hR _)
(ring_equiv_of_equiv R e)
/-- Auxilliary definition:
Multivariate polynomials in finitely many variables over an integral domain form an integral domain.
This fact is proven by transport of structure from the `mv_polynomial.integral_domain_fin`,
and then used to prove the general case without finiteness hypotheses.
See `mv_polynomial.integral_domain` for the general case. -/
def integral_domain_fintype (R : Type u) (σ : Type v) [integral_domain R] [fintype σ] :
integral_domain (mv_polynomial σ R) :=
@is_integral_domain.to_integral_domain _ _ $ mv_polynomial.is_integral_domain_fintype R σ $
integral_domain.to_is_integral_domain R
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {R : Type u} [integral_domain R] {σ : Type v}
(p q : mv_polynomial σ R) (h : p * q = 0) : p = 0 ∨ q = 0 :=
begin
obtain ⟨s, p, rfl⟩ := exists_finset_rename p,
obtain ⟨t, q, rfl⟩ := exists_finset_rename q,
have : rename (subtype.map id (finset.subset_union_left s t) : {x // x ∈ s} → {x // x ∈ s ∪ t}) p *
rename (subtype.map id (finset.subset_union_right s t) : {x // x ∈ t} → {x // x ∈ s ∪ t}) q = 0,
{ apply rename_injective _ subtype.val_injective, simpa using h },
letI := mv_polynomial.integral_domain_fintype R {x // x ∈ (s ∪ t)},
rw mul_eq_zero at this,
cases this; [left, right],
all_goals { simpa using congr_arg (rename subtype.val) this }
end
/-- The multivariate polynomial ring over an integral domain is an integral domain. -/
instance {R : Type u} {σ : Type v} [integral_domain R] :
integral_domain (mv_polynomial σ R) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := mv_polynomial.eq_zero_or_eq_zero_of_mul_eq_zero,
exists_pair_ne := ⟨0, 1, λ H,
begin
have : eval₂ (ring_hom.id _) (λ s, (0:R)) (0 : mv_polynomial σ R) =
eval₂ (ring_hom.id _) (λ s, (0:R)) (1 : mv_polynomial σ R),
{ congr, exact H },
simpa,
end⟩,
.. (by apply_instance : comm_ring (mv_polynomial σ R)) }
end mv_polynomial
|
a57a6d753a9c0eba4669ea7fa98aca7668ea9c8c | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/group_theory/abelianization.lean | 3723138221d97da631ea68edc41be3b4e36fed5e | [
"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,882 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Michael Howes
The functor Grp → Ab which is the left adjoint
of the forgetful functor Ab → Grp.
-/
import group_theory.quotient_group
universes u v
variables (α : Type u) [group α]
def commutator : set α :=
group.normal_closure {x | ∃ p q, p * q * p⁻¹ * q⁻¹ = x}
instance : normal_subgroup (commutator α) :=
group.normal_closure.is_normal
def abelianization : Type u :=
quotient_group.quotient $ commutator α
namespace abelianization
local attribute [instance] quotient_group.left_rel normal_subgroup.to_is_subgroup
instance : comm_group (abelianization α) :=
{ mul_comm := λ x y, quotient.induction_on₂ x y $ λ a b, quotient.sound
(group.subset_normal_closure ⟨b⁻¹,a⁻¹, by simp [mul_inv_rev, inv_inv, mul_assoc]⟩),
.. quotient_group.group _}
variable {α}
def of (x : α) : abelianization α :=
quotient.mk x
instance of.is_group_hom : is_group_hom (@of α _) :=
{ map_mul := λ _ _, rfl }
section lift
variables {β : Type v} [comm_group β] (f : α → β) [is_group_hom f]
lemma commutator_subset_ker : commutator α ⊆ is_group_hom.ker f :=
group.normal_closure_subset (λ x ⟨p,q,w⟩, (is_group_hom.mem_ker f).2
(by {rw ←w, simp [is_mul_hom.map_mul f, is_group_hom.map_inv f, mul_comm]}))
def lift : abelianization α → β :=
quotient_group.lift _ f (λ x h, (is_group_hom.mem_ker f).1 (commutator_subset_ker f h))
instance lift.is_group_hom : is_group_hom (lift f) :=
quotient_group.is_group_hom_quotient_lift _ _ _
@[simp] lemma lift.of (x : α) : lift f (of x) = f x :=
rfl
theorem lift.unique
(g : abelianization α → β) [is_group_hom g]
(hg : ∀ x, g (of x) = f x) {x} :
g x = lift f x :=
quotient_group.induction_on x hg
end lift
end abelianization
|
aeba15afe125edc1d2b4bd779698aaf5462c4438 | fb4c13c9b8a3d8624041a268d2d3348d53c1aecb | /library/standard/list.lean | 2ccd8a946e1193449012734433010cad3c5008d2 | [
"Apache-2.0"
] | permissive | avigad/libraries | 90f149eedb7f621b7af5bd469f0b4869f1bc35c5 | 1a21725f97d83ae7531eaeb38d175bad8c0f1d89 | refs/heads/master | 1,610,958,129,193 | 1,405,610,493,000 | 1,405,610,493,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,915 | lean | ----------------------------------------------------------------------------------------------------
--- Copyright (c) 2014 Parikshit Khanna. All rights reserved.
--- Released under Apache 2.0 license as described in the file LICENSE.
--- Author: Parikshit Khanna, Jeremy Avigad
----------------------------------------------------------------------------------------------------
-- Theory list
-- ===========
--
-- Basic properties of lists.
import macros
import tactic
import nat
using nat
unary_nat
namespace list
-- Axioms
-- ------
variable list : Type → Type
variable nil {T : Type} : list T
variable cons {T : Type} (x : T) (l : list T) : list T
variable list_rec {T : Type} {C : list T → Type} (c : C nil)
(g : forall x : T, forall l : list T, forall c : C l, C (cons x l)) :
forall l : list T, C l
axiom list_rec_nil {T : Type} {C : list T → Type} (c : C nil)
(g : forall x : T, forall l : list T, forall c : C l, C (cons x l)) :
list_rec c g nil = c
axiom list_rec_cons {T : Type} {C : list T → Type} (c : C nil)
(g : forall x : T, forall l : list T, forall c : C l, C (cons x l))
(x : T) (l : list T):
list_rec c g (cons x l) = g x l (list_rec c g l)
theorem list_induction_on {T : Type} {P : list T → Bool} (l : list T) (Hnil : P nil)
(Hind : forall x : T, forall l : list T, forall H : P l, P (cons x l)) : P l
:= list_rec Hnil Hind l
theorem list_cases_on {T : Type} {P : list T → Bool} (l : list T) (Hnil : P nil)
(Hcons : forall x : T, forall l : list T, P (cons x l)) : P l
:= list_induction_on l Hnil (take x l IH, Hcons x l)
-- Concat
-- ------
definition concat {T : Type} (s t : list T) : list T
:= list_rec t (fun x : T, fun l : list T, fun u : list T, cons x u) s
infix 50 @ : concat
-- infix 50 ## : cons
theorem nil_concat {T : Type} (t : list T) : nil @ t = t
:= list_rec_nil _ _
theorem cons_concat {T : Type} (x : T) (s t : list T) : concat (cons x s) t = cons x (concat s t)
:= list_rec_cons _ _ _ _
theorem concat_nil {T : Type} (t : list T) : concat t nil = t
:=
list_induction_on t
(nil_concat nil)
(take (x : T) (l : list T) (H : concat l nil = l),
show concat (cons x l) nil = cons x l, from
calc
concat (cons x l) nil = cons x (concat l nil) : cons_concat x l nil
... = cons x l : {H})
theorem concat_assoc {T : Type} (s t u : list T) : concat (concat s t) u = concat s (concat t u)
:=
list_induction_on s
(calc
concat (concat nil t) u = concat t u : { nil_concat _ }
... = concat nil (concat t u) : symm (nil_concat _))
(take x l,
assume H : concat (concat l t) u = concat l (concat t u),
calc
concat (concat (cons x l) t) u = concat (cons x (concat l t)) u : {cons_concat _ _ _}
... = cons x (concat (concat l t) u) : {cons_concat _ _ _ }
... = cons x (concat l (concat t u)) : { H }
... = concat (cons x l) (concat t u) : {symm (cons_concat _ _ _)})
-- Length
-- ------
definition length {T : Type} : list T → ℕ
:= list_rec 0 (fun x l m, succ m)
theorem length_nil {T : Type} : length (@nil T) = zero
:= list_rec_nil _ _
theorem length_cons {T : Type} (x : T) (t : list T) : length (cons x t) = succ (length t)
:= list_rec_cons _ _ _ _
theorem length_concat {T : Type} (s t : list T) : length (concat s t) = length s + length t
:=
list_induction_on s
(calc
length (concat nil t) = length t : {nil_concat _}
... = zero + length t : {symm (add_zero_left (length t))}
... = length (@nil T) +length t : {symm (length_nil)})
(take x s,
assume H : length (concat s t) = length s + length t,
calc
length (concat (cons x s) t ) = length (cons x (concat s t)) : {cons_concat _ _ _}
... = succ (length (concat s t)) : {length_cons _ _}
... = succ (length s + length t) : { H }
... = succ (length s) + length t : {symm (add_succ_left _ _)}
... = length (cons x s) + length t : {symm (length_cons _ _)})
add_rewrite length_nil length_cons
-- Reverse
-- -------
definition reverse {T : Type} : list T → list T := list_rec nil (fun x l r, concat r (cons x nil))
theorem reverse_nil {T : Type} : reverse (@nil T) = nil
:= list_rec_nil _ _
theorem reverse_cons {T : Type} (x : T) (l : list T) : reverse (cons x l) =
concat (reverse l) (cons x nil)
:= list_rec_cons _ _ _ _
theorem reverse_concat {T : Type} (s t : list T) :
reverse (concat s t) = concat (reverse t) (reverse s)
:=
list_induction_on s
(calc
reverse (concat nil t) = reverse t : { nil_concat _ }
... = concat (reverse t) nil : symm (concat_nil _)
... = concat (reverse t) (reverse nil) : {symm (reverse_nil)})
(take x l,
assume H : reverse (concat l t) = concat (reverse t) (reverse l),
calc
reverse (concat (cons x l) t) = reverse (cons x (concat l t)) : {cons_concat _ _ _}
... = concat (reverse (concat l t)) (cons x nil) : reverse_cons _ _
... = concat (concat (reverse t) (reverse l)) (cons x nil) : { H }
... = concat (reverse t) (concat (reverse l) (cons x nil)) : concat_assoc _ _ _
... = concat (reverse t) (reverse (cons x l)) : {symm (reverse_cons _ _)})
theorem reverse_reverse {T : Type} (t : list T) : reverse (reverse t) = t
:=
list_induction_on t
(calc
reverse (reverse (@nil T)) = reverse nil : {reverse_nil}
... = nil : reverse_nil)
(take x l,
assume H: reverse (reverse l) = l,
show reverse (reverse (cons x l)) = cons x l, from
calc
reverse (reverse (cons x l)) = reverse (concat (reverse l) (cons x nil))
: {reverse_cons x l}
... = concat (reverse (cons x nil)) (reverse (reverse l)) : {reverse_concat _ _}
... = concat (reverse (cons x nil)) l : {H}
... = concat (concat (reverse nil) (cons x nil)) l : {reverse_cons _ _}
... = concat (concat nil (cons x nil)) l : {reverse_nil}
... = concat (cons x nil) l : {nil_concat _}
... = cons x (concat nil l) : cons_concat _ _ _
... = cons x l : {nil_concat _})
-- keep?
theorem concat_cons {T : Type} (x : T) (s l : list T) :
concat s (cons x l) = reverse (concat (reverse l) (cons x (reverse s)))
:=
calc
concat s (cons x l) = concat s (cons x (concat nil l)) : {symm (nil_concat _)}
... = concat s (concat (cons x nil) l) : {symm (cons_concat _ _ _)}
... = concat (concat s (cons x nil)) l : {symm (concat_assoc _ _ _)}
... = concat (concat (reverse(reverse s)) (cons x nil)) l : {symm (reverse_reverse _)}
... = concat (reverse (cons x (reverse s))) l : {symm (reverse_cons _ _)}
... = concat (reverse (cons x (reverse s))) (reverse(reverse l)) : {symm (reverse_reverse _)}
... = reverse (concat (reverse l) (cons x (reverse s))) : {symm (reverse_concat _ _)}
-- Append
-- ------
definition append {T : Type} (a : T) : list T → list T
:= list_rec (cons a nil) (fun x l b, cons x b)
theorem append_cons {T : Type } (x : T) (a : T) (t : list T) :
append a (cons x t) = cons x (append a t)
:= list_rec_cons _ _ _ _
theorem append_eq_concat {T : Type} (a : T) (t : list T) : append a t = concat t (cons a nil)
:=
list_induction_on t
(calc
append a nil = cons a nil : list_rec_nil _ _
... = concat nil (cons a nil) : symm (nil_concat _))
(take x l,
assume P : append a l = concat l (cons a nil),
calc
append a (cons x l) = cons x (append a l) : {append_cons _ _ _}
... = cons x (concat l (cons a nil)) : { P }
... = concat (cons x l) (cons a nil) : {symm (cons_concat _ _ _)})
theorem append_eq_reverse {T : Type} (a : T) (t : list T) :
append a t = reverse (cons a (reverse t))
:=
list_induction_on t
(calc
append a nil = cons a nil : (list_rec_nil _ _)
... = concat nil (cons a nil) : {symm (nil_concat _)}
... = concat (reverse nil) (cons a nil) : {symm (reverse_nil)}
... = reverse (cons a nil) : {symm (reverse_cons _ _)}
... = reverse (cons a (reverse nil)) : {symm (reverse_nil)})
(take x l,
assume H : append a l = reverse (cons a (reverse l)),
calc
append a (cons x l) = concat (cons x l) (cons a nil) : append_eq_concat _ _
... = concat (reverse (reverse (cons x l))) (cons a nil) : {symm (reverse_reverse _)}
... = reverse (cons a (reverse (cons x l))) : {symm (reverse_cons _ _)})
-- Head and tail
-- -------------
definition head {T : Type} (x0 : T) : list T → T
:= list_rec x0 (fun x l h, x)
theorem head_nil {T : Type} (x0 : T) : head x0 (@nil T) = x0
:= list_rec_nil _ _
theorem head_cons {T : Type} (x : T) (x0 : T) (t : list T) : head x0 (cons x t) = x
:= list_rec_cons _ _ _ _
theorem head_concat {T : Type} (s t : list T) (x0 : T) :
s ≠ nil → (head x0 (concat s t) = head x0 s)
:=
list_cases_on s
(take H : nil ≠ nil, absurd_elim (head x0 (concat nil t) = head x0 nil) (refl nil) H)
(take x s,
take H : cons x s ≠ nil,
calc
head x0 (concat (cons x s) t) = head x0 (cons x (concat s t)) : {cons_concat _ _ _}
... = x : {head_cons _ _ _}
... = head x0 (cons x s) : {symm ( head_cons x x0 s)})
definition tail {T : Type} : list T → list T
:= list_rec nil (fun x l b, l)
theorem tail_nil {T : Type} : tail (@nil T) = nil
:= list_rec_nil _ _
theorem tail_cons {T : Type} (x : T) (l : list T) : tail (cons x l) = l
:= list_rec_cons _ _ _ _
theorem cons_head_tail {T : Type} (x0 : T) (l : list T) :
l ≠ nil → cons (head x0 l) (tail l) = l
:=
list_cases_on l
(assume H : nil ≠ nil,
absurd_elim _ (refl _) H)
(take x l,
assume H : cons x l ≠ nil,
calc
cons (head x0 (cons x l)) (tail (cons x l)) = cons x (tail (cons x l)) : {head_cons _ _ _}
... = cons x l : {tail_cons _ _})
-- List membership
-- ---------------
definition mem {T : Type} (f : T) : list T → Bool
:= list_rec false (fun x l b,(b ∨ (x = f)))
infix 50 ∈ : mem
theorem mem_nil {T : Type} (f : T) : mem f nil ↔ false
:= list_rec_nil _ _
theorem mem_cons {T : Type} (x : T) (f : T) (l : list T) : mem f (cons x l) ↔ (mem f l ∨ x = f)
:= list_rec_cons _ _ _ _
theorem mem_concat_imp_or {T : Type} (f : T) (s t : list T) : mem f (concat s t) → mem f s ∨ mem f t
:=
list_induction_on s
(assume H : mem f (concat nil t),
have H1 : mem f t, from subst H (nil_concat t),
show mem f nil ∨ mem f t, from or_intro_right _ H1)
(take x l,
assume IH : mem f (concat l t) → mem f l ∨ mem f t,
assume H : mem f (concat (cons x l) t),
have H1 : mem f (cons x (concat l t)), from subst H (cons_concat _ _ _),
have H2 : mem f (concat l t) ∨ x = f, from (mem_cons _ _ _) ◂ H1,
have H3 : (mem f l ∨ mem f t) ∨ x = f, from or_imp_or_left H2 IH,
have H4 : (mem f l ∨ x = f) ∨ mem f t, from or_right_comm _ _ _ ◂ H3,
show mem f (cons x l) ∨ mem f t, from subst H4 (symm (mem_cons _ _ _)))
theorem mem_or_imp_concat {T : Type} (f : T) (s t : list T) :
mem f s ∨ mem f t → mem f (concat s t)
:=
list_induction_on s
(assume H : mem f nil ∨ mem f t,
have H1 : false ∨ mem f t, from subst H (mem_nil f),
have H2 : mem f t, from subst H1 (or_false_right _),
show mem f (concat nil t), from subst H2 (symm (nil_concat _)))
(take x l,
assume IH : mem f l ∨ mem f t → mem f (concat l t),
assume H : (mem f (cons x l)) ∨ (mem f t),
have H1 : ((mem f l) ∨ (x = f)) ∨ (mem f t), from subst H (mem_cons _ _ _),
have H2 : (mem f t) ∨ ((mem f l) ∨ (x = f)), from subst H1 (or_comm _ _),
have H3 : ((mem f t) ∨ (mem f l)) ∨ (x = f), from subst H2 (symm (or_assoc _ _ _)),
have H4 : ((mem f l) ∨ (mem f t)) ∨ (x = f), from subst H3 (or_comm _ _),
have H5 : (mem f (concat l t)) ∨ (x = f), from (or_imp_or_left H4 IH),
have H6 : (mem f (cons x (concat l t))), from subst H5 (symm (mem_cons _ _ _)),
show (mem f (concat (cons x l) t)), from subst H6 (symm (cons_concat _ _ _)))
theorem mem_concat {T : Type} (f : T) (s t : list T) : mem f (concat s t) ↔ mem f s ∨ mem f t
:= iff_intro (mem_concat_imp_or _ _ _) (mem_or_imp_concat _ _ _)
theorem mem_split {T : Type} (f : T) (s : list T) :
mem f s → ∃ a b : list T, s = concat a (cons f b)
:=
list_induction_on s
(assume H : mem f nil,
have H1 : mem f nil ↔ false, from (mem_nil f),
show ∃ a b : list T, nil = concat a (cons f b), from absurd_elim _ H (eqf_elim H1))
(take x l,
assume P1 : mem f l → ∃ a b : list T, l = concat a (cons f b),
assume P2 : mem f (cons x l),
have P3 : mem f l ∨ x = f, from subst P2 (mem_cons _ _ _),
show ∃ a b : list T, cons x l = concat a (cons f b), from
or_elim P3
(assume Q1 : mem f l,
obtain (a : list T) (PQ : ∃ b, l = concat a (cons f b)), from P1 Q1,
obtain (b : list T) (RS : l = concat a (cons f b)), from PQ,
exists_intro (cons x a)
(exists_intro b
(calc
cons x l = cons x (concat a (cons f b)) : { RS }
... = concat (cons x a) (cons f b) : (symm (cons_concat _ _ _)))))
(assume Q2 : x = f,
exists_intro nil
(exists_intro l
(calc
cons x l = concat nil (cons x l) : (symm (nil_concat _))
... = concat nil (cons f l) : {Q2}))))
-- Position
-- --------
-- rename to find?
definition find {T : Type} (x : T) : list T → ℕ
:= list_rec 0 (fun y l b, if x = y then 0 else succ b)
theorem find_nil {T : Type} (f : T) : find f nil = 0
:=list_rec_nil _ _
theorem find_cons {T : Type} (x y : T) (l : list T) : find x (cons y l) =
if x = y then 0 else succ (find x l)
:= list_rec_cons _ _ _ _
theorem not_mem_find {T : Type} (l : list T) (x : T) : ¬ mem x l → find x l = length l
:=
@list_induction_on T (λl, ¬ mem x l → find x l = length l) l
-- list_induction_on l
(assume P1 : ¬ mem x nil,
show find x nil = length nil, from
calc
find x nil = 0 : find_nil _
... = length nil : by simp)
(take y l,
assume IH : ¬ (mem x l) → find x l = length l,
assume P1 : ¬ (mem x (cons y l)),
have P2 : ¬ (mem x l ∨ (y = x)), from subst P1 (mem_cons _ _ _),
have P3 : ¬ (mem x l) ∧ (y ≠ x),from subst P2 (not_or _ _),
have P4 : x ≠ y, from ne_symm (and_elim_right P3),
calc
find x (cons y l) = succ (find x l) :
trans (find_cons _ _ _) (not_imp_if_eq P4 _ _)
... = succ (length l) : {IH (and_elim_left P3)}
... = length (cons y l) : symm (length_cons _ _))
-- nth element
-- -----------
definition nth_element {T : Type} (x0 : T) (l : list T) (n : ℕ) : T
:= nat::rec (λl, head x0 l) (λm f l, f (tail l)) n l
theorem nth_element_zero {T : Type} (x0 : T) (l : list T) : nth_element x0 l 0 = head x0 l
:= hcongr1 (nat::rec_zero _ _) l
theorem nth_element_succ {T : Type} (x0 : T) (l : list T) (n : ℕ) :
nth_element x0 l (succ n) = nth_element x0 (tail l) n
:= hcongr1 (nat::rec_succ _ _ _) l
-- theorem ... (n : ℕ) : ∀l, ....
-- definition list_succ {T : Type} (x : T) (x0 : T) : list T → T
-- := list_rec x0 (fun y l b, if (find x l = succ zero) then y else b)
-- theorem cons_list_succ {T : Type} (f x : T) (x0 : T) (l : list T) :
-- list_succ f x0 (cons x l) = if (find f l = succ zero) then x else list_succ f x0 l
-- := list_rec_cons _ _ _ _
-- definition nth_element {T : Type} (n : ℕ) (x0 : T) : list T → T
-- := list_rec x0 (fun x l b, if (n > succ (length l)) then x0 else list_succ b x0 (cons x l))
-- theorem cons_nth_element {T : Type} (n : ℕ) (x0 x : T) (l : list T) :
-- nth_element n x0 (cons x l) =
-- if n > succ (length l) then x0 else list_succ (nth_element n x0 l) x0 (cons x l)
-- := list_rec_cons _ _ _ _
-- rank
-- ----
--rank of f = position of f in a sorted list (provided present)
-- definition rank (f : ℕ) : list ℕ → ℕ
-- := list_rec zero (fun x l b, if ((x ≥ f) ∨ (¬ (mem f (cons x l)))) then b else (succ b))
definition rank (x : ℕ) : list ℕ → ℕ
:= list_rec 0 (fun y l r,if y ≥ x then r else succ r)
theorem rank_nil (x : ℕ) : rank x nil = 0
:= list_rec_nil _ _
add_rewrite rank_nil
theorem rank_cons (x y : ℕ) (l : list ℕ) :
rank x (cons y l) = if y ≥ x then rank x l else succ (rank x l)
:= list_rec_cons _ _ _ _
-- Sorting a list of natural numbers
-- ---------------------------------
-- Assumes l to be sorted
definition insert (n : ℕ) : list ℕ → list ℕ
:= list_rec (cons n nil) (fun m l b, if n ≥ m then (cons m b) else cons n (cons m l))
theorem insert_nil (n : ℕ) : insert n nil = cons n nil
:= list_rec_nil _ _
add_rewrite insert_nil
theorem insert_cons (n m : ℕ) (l : list ℕ) : insert n (cons m l) =
(if n ≥ m then cons m (insert n l) else cons n (cons m l))
:=list_rec_cons _ _ _ _
definition asort : list ℕ → list ℕ
:= list_rec nil (fun x l b, insert x b)
--What about these 2 definitions.Ofcourse perm is valid only for elements having natural ordering..
definition sorted (a : list ℕ) := ∃ l, a = asort l
definition perm (a b : list ℕ) := asort a = asort b
--
-- TO PROOVE
-- theorem asort_asort : asort (asort l) = l
-- merging routine?
definition dsort (l : list ℕ) : list ℕ
:= reverse (asort l)
theorem asort_nil : asort nil = nil
:= list_rec_nil _ _
add_rewrite asort_nil
theorem asort_cons (n : ℕ) (l : list ℕ) : asort (cons n l) = insert n (asort l)
:= list_rec_cons _ _ _ _
theorem mem_head {T : Type} (f x0 : T) (l : list T) (A : f ≠ x0) : (head x0 l = f) → (mem f l)
:= list_induction_on l
(assume H : head x0 nil = f,
have H1 : x0 = f,from subst H (head_nil x0),
show mem f nil,from absurd_elim _ (symm H1) A)
(take x l,
assume H1 : (head x0 l = f) → (mem f l),
assume P1 : head x0 (cons x l) = f,
have P2 : x = f,from subst P1 (head_cons _ _ _),
have P3 : (mem f l) ∨ (x = f),from (or_intro_right _ P2),
show mem f (cons x l),from subst P3 (symm (mem_cons _ _ _)))
theorem mem_tail {T : Type} (f : T) (l : list T) : mem f (tail l) → mem f l
:= list_induction_on l
(assume H : mem f (tail nil),
show mem f nil ,from subst H (tail_nil))
(take x l,
assume P : mem f (tail l) → mem f l,
assume H : mem f (tail (cons x l)),
have H1 : mem f l, from subst H (tail_cons x l),
have H2 : (mem f l) ∨ (x = f),from (or_intro_left _ H1),
show mem f (cons x l),from subst H2 (symm (mem_cons x f l)))
theorem mem_insert1 (n m : ℕ) (l : list ℕ) : mem n (insert m l) → (mem n l) ∨ (m = n)
:=
list_induction_on l
(assume H1 : mem n (insert m nil),
have H2 : mem n (cons m nil),from subst H1 (insert_nil _),
show mem n nil ∨ (m = n), from subst H2 (mem_cons _ _ _))
(take x l,
assume H : mem n (insert m l) → (mem n l) ∨ (m = n),
assume P : mem n (insert m (cons x l)),
have P1 : mem n (if m ≥ x then cons x (insert m l) else cons m (cons x l)),
from subst P (insert_cons _ _ _),
by_cases
(assume Q : m ≥ x,
have Q1 : mem n (cons x (insert m l)), from subst P1 (imp_if_eq Q _ _),
have Q2 : mem n (insert m l) ∨ (x = n), from subst Q1 (mem_cons _ _ _),
have Q3 : ((mem n l) ∨ (m = n)) ∨ (x = n), from or_imp_or_left Q2 H,
have Q4 : ((((mem n l) ∨ (m = n)) ∨ (x = n)) = (((mem n l) ∨ (x = n)) ∨ (m = n))),
by simp,
show mem n (cons x l) ∨ (m = n), from subst (Q4 ◂ Q3) (symm (mem_cons _ _ _)))
(assume R : ¬ (m ≥ x),
have R1 : mem n (cons m (cons x l)), from subst P1 (not_imp_if_eq R _ _),
show mem n (cons x l) ∨ (m = n), from (mem_cons _ _ _) ◂ R1))
theorem mem_insert2 (n m : ℕ) (l : list ℕ) : (mem n l) ∨ (m = n) → mem n (insert m l)
:=
list_induction_on l
(assume H : mem n nil ∨ (m = n),
have H1 : mem n (cons m nil),from subst H (symm (mem_cons _ _ _)),
show mem n (insert m nil), from subst H1 (symm (insert_nil _)))
(take x l,
assume H : (mem n l) ∨ (m = n) → mem n (insert m l),
assume P : (mem n (cons x l)) ∨ (m = n),
have P1 : (mem n l ∨ (x = n)) ∨ (m = n),from subst P (mem_cons _ _ _),
have P2 : (mem n l ∨ (m = n)) ∨ (x = n),from subst P1 (or_right_comm _ _ _),
have P3 : mem n (insert m l) ∨ (x = n),from or_imp_or_left P2 H,
by_cases
(assume Q : m ≥ x,
have Q1 : mem n (cons x (insert m l)),from subst P3 (symm (mem_cons _ _ _)),
have Q2 : mem n (if m ≥ x then cons x (insert m l) else cons m (cons x l)),from subst Q1 (symm (imp_if_eq Q _ _)),
show mem n (insert m (cons x l)), from subst Q2 (symm (insert_cons _ _ _)))
(assume R : ¬ (m ≥ x),
have R1 : mem n (cons m (cons x l)),from subst P (symm (mem_cons m n (cons x l))),
have R2 : mem n (if m ≥ x then cons x (insert m l) else cons m (cons x l)) ,from subst R1 (symm (not_imp_if_eq R _ _)),
show mem n (insert m (cons x l)),from subst R2 (symm (insert_cons _ _ _))))
theorem mem_insert (n m : ℕ) (l : list ℕ) : mem n (insert m l) ↔ (mem n l) ∨ (m = n)
:= iff_intro (mem_insert1 _ _ _) (mem_insert2 _ _ _)
theorem mem_asort1 (s : ℕ) (l : list ℕ) : mem s (asort l) → mem s l
:= list_induction_on l
(assume H : mem s (asort nil),
show mem s nil ,from subst H (asort_nil))
(take x l,
assume P : mem s (asort l) → mem s l,
assume H : mem s (asort (cons x l)),
have H1 : mem s (insert x (asort l)),from subst H (asort_cons _ _),
have H2 : mem s (asort l) ∨ (x = s), from (mem_insert1 _ _ _) H1,
have H3 : mem s l ∨ (x = s),from or_imp_or_left H2 P,
show mem s (cons x l), from subst H3 (symm (mem_cons _ _ _)))
theorem mem_asort2 (s : ℕ) (l : list ℕ) : mem s l → mem s (asort l)
:= list_induction_on l
(assume H : mem s nil,
show mem s (asort nil) ,from subst H (symm (asort_nil)))
(take x l,
assume P : mem s l → mem s (asort l),
assume H : mem s (cons x l),
have H1 : mem s l ∨ (x = s) ,from subst H (mem_cons _ _ _),
have H2 : mem s (asort l) ∨ (x = s) ,from or_imp_or_left H1 P,
have H3 : mem s (insert x (asort l)) ,from (mem_insert2 _ _ _) H2,
show mem s (asort (cons x l)) ,from subst H3 (symm (asort_cons _ _)))
theorem mem_asort (s : ℕ) (l : list ℕ) : mem s (asort l) ↔ mem s l
:= iff_intro (mem_asort1 _ _) (mem_asort2 _ _)
theorem if_else_intro (a b c : Bool) (H1 : a → b) (H2 : ¬ a → c) : if a then b else c
:=
by_cases
(assume H : a, (by simp) (H1 H))
(assume H : ¬ a, (by simp) (H2 H))
-- This is a good target for shortening
-- With splitting on cases, and adding insert_cons and rank_cons, this should be
-- one line: list_induction_on l (by simp) (by simp)
theorem rank_insert (x y : ℕ) (l : list ℕ) : rank x (insert y l) =
(if y ≥ x then rank x l else succ (rank x l))
:=
by_cases
(assume H : y ≥ x,
list_induction_on l
((by simp) (rank_cons x y nil))
(take z l,
assume IH : rank x (insert y l) = (if y ≥ x then rank x l else succ (rank x l)),
by_cases
(assume H1 : y ≥ z,
by_cases
(assume H2 : z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l))
(assume H2 : ¬ z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)))
(assume H1 : ¬ y ≥ z,
by_cases
(assume H2 : z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)
(rank_cons x y (cons z l)))
(assume H2 : ¬ z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)
(rank_cons x y (cons z l))))))
(assume H : ¬ y ≥ x,
list_induction_on l
((by simp) (rank_cons x y nil))
(take z l,
assume IH : rank x (insert y l) = (if y ≥ x then rank x l else succ (rank x l)),
by_cases
(assume H1 : y ≥ z,
by_cases
(assume H2 : z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l))
(assume H2 : ¬ z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)))
(assume H1 : ¬ y ≥ z,
by_cases
(assume H2 : z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)
(rank_cons x y (cons z l)))
(assume H2 : ¬ z ≥ x,
(by simp) (insert_cons y z l) (rank_cons x z (insert y l)) (rank_cons x z l)
(rank_cons x y (cons z l))))))
-- theorem find_insert (x y : ℕ) (l : list ℕ) : find x (insert y (asort l)) = (if y ≥ x then find x (asort l) else succ (find x (asort l)))
-- :=
-- by_cases
-- (assume H : y ≥ x,
-- list_induction_on l
-- ((by simp) (asort_nil) (insert_nil y) (find_cons x y nil)
-- (find_nil x))
-- (take z l,
-- assume IH : find x (insert y (asort l)) = (if y ≥ x then find x l else succ (find x l)),
-- by_cases
-- (assume H1 : y ≥ z,
-- by_cases
-- (assume H2 : z ≥ x,
-- (by simp) (asort_cons z l) (insert_cons _ _ l) (find_cons _ _ l))
-- (assume H2 : ¬ z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l)))
-- (assume H1 : ¬ y ≥ z,
-- by_cases
-- (assume H2 : z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l))
-- (assume H2 : ¬ z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l))))
-- (assume H : ¬ y ≥ x,
-- list_induction_on l
-- ((by simp) (asort_nil) (insert_nil y) (find_cons x y nil)
-- (find_nil x))
-- (take z l,
-- assume IH : find x (insert y (asort l)) = (if y ≥ x then find x l else succ (find x l)),
-- by_cases
-- (assume H1 : y ≥ z,
-- by_cases
-- (assume H2 : z ≥ x,
-- (by simp) (asort_cons z l) (insert_cons _ _ l) (find_cons _ _ l))
-- (assume H2 : ¬ z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l)))
-- (assume H1 : ¬ y ≥ z,
-- by_cases
-- (assume H2 : z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l))
-- (assume H2 : ¬ z ≥ x,
-- (by simp) (insert_cons _ _ l) (find_cons _ _ l))))))
theorem asort_rank (x : ℕ) (l : list ℕ) : rank x l = rank x (asort l)
:=
list_induction_on l
(show rank x nil = rank x (asort nil), by simp)
(take y l,
assume IH : rank x l = rank x (asort l),
by_cases
(assume P : y ≥ x,
(by simp) (rank_cons x y l) (asort_cons y l) (rank_insert x y (asort l)))
(assume P : ¬ y ≥ x,
(by simp) (rank_cons x y l) (asort_cons y l) (rank_insert x y (asort l))))
---Needed?
-- axiom ge_gt_eq (x y : ℕ) : (x ≥ y) ↔ (x > y) ∨ (x = y)
theorem le_iff_lt_or_eq (x y : ℕ) : (x ≤ y) ↔ (x < y) ∨ (x = y)
:=
iff_intro (le_imp_lt_or_eq)
(take H, or_elim H lt_imp_le (assume H1 : x = y, subst (le_refl x) H1))
theorem ge_gt_eq (x y : ℕ) : (x ≥ y) ↔ (x > y) ∨ (x = y)
:=
iff_intro
(take H, or_elim (le_imp_lt_or_eq H) (take H1, or_intro_left _ H1) (take H1, or_intro_right _ (symm H1)))
(take H, or_elim H lt_imp_le (assume H1 : x = y, subst (le_refl x) H1))
-- definition ge_gt_eq (x y : ℕ) : (x ≥ y) ↔ (x > y) ∨ (x = y)
---fetch recent to elimante the following two axioms
axiom gt_def (n m : ℕ) : n > m ↔ m < n
axiom lt_imp_not_ge {n m : ℕ} (H : n < m) : ¬ n ≥ m
-- axiom sorry {P : Bool} : P
-- theorem insert_comm_aux (x y : ℕ) (H : x < y) (l : list ℕ) : insert x (insert y l) = insert y (insert x l)
-- definition map {T : Type} {S : Type} (P : T → S) (x0 : S) : list T → list S
-- := list_rec (cons x0 nil) (fun x l b, cons (P x) b)
-- definition foldr {T : Type} {S : Type} (f : T → T → T) (x0 : T) : list T → T
-- := list_rec x0 (fun x l b,f x b)
-- -- l = x [a b c d]
-- -- b = f(c f( b (f a d)))) f( a (f b (f c d))) f (f (f a b) c) d
-- -- r = f (c f(b f(a (f x d)))) f a f b f c d f ( f (f ( f x a) b) c) d
-- definition last {T : Type} (x0 : T) (l : list T) : T
-- := head x0 (reverse l)
|
25f380c3aab180f5474803b81b4471ead5721010 | ba4b63fe3410ccb8e043a57aa024ac63bf06961c | /src/norms.lean | 671ce309d9561dd019f813599683837cfa059d78 | [] | no_license | digama0/lean-scratchpad | f30cd665037c226b63ef9933c8fa83e8770f7909 | fe7d6261d60769328e091a37dff7d456c57366b7 | refs/heads/master | 1,583,695,343,314 | 1,522,993,425,000 | 1,522,993,425,000 | 128,350,243 | 0 | 0 | null | 1,522,993,456,000 | 1,522,993,456,000 | null | UTF-8 | Lean | false | false | 6,722 | lean | -- The following line is here only to get mathlib tactics, there must be a better way
import algebra.group_power
noncomputable theory
local attribute [instance] classical.prop_decidable
open list
variables {α β : Type} [group α] [group β] {a b g h : α}
local attribute [simp] mul_assoc
-- Group morphisms
-------------------
def is_mph (f : α → β) : Prop :=
∀ a b : α, f(a*b) = f(a)*f(b)
-- Despite the decorator, I can't use this lemma implicitly in simp (and having H implicit is not enough)
@[simp]
lemma mph_one { f : α → β } (H : is_mph f) : f 1 = 1 :=
eq.symm (mul_left_cancel (show (f 1)*1 = (f 1)*(f 1), by simpa using H 1 1))
lemma mph_inv { f : α → β } (H : is_mph f) : (f a)⁻¹ = f (a⁻¹) :=
begin
have H' := eq.symm (show f 1 = f a * f a⁻¹, by simpa using H a a⁻¹),
rw [mph_one H] at H',
exact (inv_eq_of_mul_eq_one H')
end
lemma mph_prod (f : α → β) (mph : is_mph f) (l : list α) :
f (prod l) = prod (map f l) :=
begin
induction l,
case nil :
{ simp[mph_one mph] },
case cons :
{ simp,
rw mph,
simp[l_ih] }
end
-- Group anti-morphisms
------------------------
def is_anti_mph (f : α → β) : Prop :=
∀ a b : α, f(a*b) = f(b)*f(a)
@[simp]
lemma anti_mph_one { f : α → β } (H : is_anti_mph f) : f 1 = 1 :=
eq.symm (mul_left_cancel (show (f 1)*1 = (f 1)*(f 1), by simpa using H 1 1))
lemma anti_mph_prod (f : α → β) (anti_mph : is_anti_mph f) (l : list α) :
f (prod l) = prod (map f (reverse l)) :=
begin
induction l,
case nil :
{ simp [anti_mph_one anti_mph] },
case cons :
{ simp,
rw anti_mph,
simp[l_ih] }
end
-- The inversion anti-morphism
------------------------------
lemma inv_is_anti_mph : is_anti_mph (λ x : α, x⁻¹) :=
by { unfold is_anti_mph, simp }
-- Following lemma could also be proved directly by "by induction l; simp *"
lemma inv_prod (l : list α) : (prod l)⁻¹ = prod (map (λ x, x⁻¹) (reverse l)) :=
by apply (anti_mph_prod (λ x, x⁻¹) inv_is_anti_mph)
-- Conjuguation in a group
--------------------------
def conj (a b : α) := a*b*a⁻¹
lemma conj_action : conj (g * h) a = conj g (conj h a) :=
by simp[conj]
lemma conj_by_one : conj 1 a = a :=
by simp[conj]
lemma conj_is_mph : is_mph (conj g) :=
by { unfold is_mph conj, simp }
lemma inv_conj : (conj b a)⁻¹ = conj b (a⁻¹) :=
mph_inv conj_is_mph
lemma conj_one : conj a 1 = 1 :=
mph_one conj_is_mph
-- Products
-----------
/- "is_product S n a" means a can be written as a product of n elements of S or S⁻¹ -/
def is_product (S : set α) (n : ℕ) (g : α) : Prop :=
∃ l : list α, g = prod l ∧ (∀ x ∈ l, x ∈ S ∨ x⁻¹ ∈ S) ∧ l.length = n
lemma is_product_mul {S : set α} {m n a b}
(h₁ : is_product S m a) (h₂ : is_product S n b) : is_product S (m + n) (a * b) :=
begin
rcases h₁ with ⟨l₁, prod₁, inS₁, len₁⟩,
rcases h₂ with ⟨l₂, prod₂, inS₂, len₂⟩,
existsi l₁ ++ l₂, -- denoted by l in comments
repeat {split},
{ -- prove a*b = prod l
simp [prod₁,prod₂] },
{ -- prove elements of l are in S or S⁻¹
simpa,
intros x x_in_l₁_or_l₂,
cases x_in_l₁_or_l₂,
{ apply inS₁ x, assumption },
{ apply inS₂ x, assumption },
},
{ -- prove length l is m + n
simp [len₁, len₂] }
end
lemma is_product_inv (S : set α) {n a} (h : is_product S n a) : is_product S n (a⁻¹) :=
begin
rcases h with ⟨l, product, inS, len⟩,
existsi map (λ x, x⁻¹) (reverse l),
repeat {split},
{ rw product,
apply inv_prod },
{ simpa,
intros,
have H := (inS x_1) a_1,
have H' : x_1 = x⁻¹ := eq_inv_of_eq_inv (eq.symm a_2),
simp[H'] at H,
exact or.symm H },
{ simpa }
end
lemma is_product_conj {S T : set α} (g) (H : ∀ a, a ∈ S → conj g a ∈ T)
{n a} (h : is_product S n a) : is_product T n (conj g a) :=
begin
rcases h with ⟨l, prod, inS, len⟩,
existsi (map (conj g) l),
repeat {split},
{ rw prod,
apply (mph_prod (conj g) conj_is_mph) },
{ clear prod a len n,
intros x x_in_conj_l,
rw mem_map at x_in_conj_l,
rcases x_in_conj_l with ⟨b, b_in_l, conj_b_x⟩,
specialize inS b b_in_l, clear b_in_l l,
cases inS,
{ have conj_in_T := H b inS,
rw conj_b_x at conj_in_T,
exact or.inl conj_in_T},
{ have conj_in_T := H b⁻¹ inS,
rw [←inv_conj, conj_b_x] at conj_in_T,
exact or.inr conj_in_T } },
{ simp[len] }
end
--- Generating sets
-------------------
def is_generating (S : set α) : Prop :=
∀ g : α, ∃ n : ℕ, is_product S n g
structure generating_set :=
(set : set α)
(gen : is_generating set)
-- Invariant norms on a group
-----------------------------
structure is_invariant_norm (ν : α → ℕ) : Prop :=
(nonneg : ∀ g : α, 0 ≤ ν g) -- this is silly but ultimately the target will be ℝ
(eq_zero : ∀ g : α, ν g = 0 → g = 1)
(mul : ∀ g h : α, ν (g*h) ≤ ν g + ν h)
(inv : ∀ g : α, ν g⁻¹ = ν g)
(conj : ∀ g h : α, ν (conj h g) = ν g)
def is_conj_invariant_set (S : set α) : Prop :=
∀ g s : α, s ∈ S → conj g s ∈ S
/- Given a generating set S and an alement a,
gen_norm S a is the minimal number of elements of S or S⁻¹
required to write a as a product.
The next two lemma prove the definition is what it should be -/
def gen_norm (S : generating_set) (a : α) := nat.find (S.gen a)
lemma is_product_norm (S : generating_set) (g : α) :
is_product S.set (gen_norm S g) g :=
nat.find_spec (S.gen g)
lemma norm_min (S : generating_set) {a : α} {n} :
is_product S.set n a → gen_norm S a ≤ n :=
by apply nat.find_min' (S.gen a)
lemma inv_norm_of_inv_set [str : group α] (S : @generating_set α str) :
is_conj_invariant_set S.set → is_invariant_norm (gen_norm S) :=
begin
intro inv_hyp,
constructor; intros,
{ apply nat.zero_le },
{ have H' := is_product_norm S g,
rw a at H',
rcases H' with ⟨l, prod, inS, len⟩,
rw [eq_nil_of_length_eq_zero len] at prod,
simp at prod,
assumption },
{ have g_prod := is_product_norm S g,
have h_prod := is_product_norm S h,
have estimate := is_product_mul g_prod h_prod,
exact norm_min S estimate },
{ apply le_antisymm,
{ apply norm_min,
exact is_product_inv S.set (is_product_norm S g) },
{ apply norm_min,
simpa using is_product_inv S.set (is_product_norm S g⁻¹) } },
{ apply le_antisymm ; apply norm_min,
{ exact is_product_conj h (inv_hyp h) (is_product_norm S g) },
{ have prod := is_product_conj h⁻¹ (inv_hyp h⁻¹) (is_product_norm S (conj h g)),
rw [←conj_action] at prod,
simp[conj_by_one] at prod,
exact prod } },
end |
bd829ba8c2fb8e2959f006dc37b6fe7aa2273c0e | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /test/ring.lean | 70d52ca506cea757eb6aa628b57bb43ca015ba8a | [
"Apache-2.0"
] | permissive | anrddh/mathlib | 6a374da53c7e3a35cb0298b0cd67824efef362b4 | a4266a01d2dcb10de19369307c986d038c7bb6a6 | refs/heads/master | 1,656,710,827,909 | 1,589,560,456,000 | 1,589,560,456,000 | 264,271,800 | 0 | 0 | Apache-2.0 | 1,589,568,062,000 | 1,589,568,061,000 | null | UTF-8 | Lean | false | false | 2,004 | lean | import tactic.ring data.real.basic
example (x y : ℕ) : x + y = y + x := by ring
example (x y : ℕ) : x + y + y = 2 * y + x := by ring
example (x y : ℕ) : x + id y = y + id x := by ring!
example {α} [comm_ring α] (x y : α) : x + y + y - x = 2 * y := by ring
example (x y : ℚ) : x / 2 + x / 2 = x := by ring
example (x y : ℚ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
example (x y : ℝ) : (x + y) ^ 3 = x ^ 3 + y ^ 3 + 3 * (x * y ^ 2 + x ^ 2 * y) := by ring
example {α} [comm_semiring α] (x : α) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 15000 {ring}
example (n : ℕ) : (n / 2) + (n / 2) = 2 * (n / 2) := by ring
example {α} [linear_ordered_field α] (a b c : α) :
a * (-c / b) * (-c / b) + -c + c = a * (c / b * (c / b)) := by ring
example {α} [linear_ordered_field α] (a b c : α) :
b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
example (x : ℚ) : x ^ (2 + 2) = x^4 := by ring
example {α} [comm_ring α] (x : α) : x ^ 2 = x * x := by ring
example {α} [linear_ordered_field α] (a b c : α) :
b ^ 2 - 4 * c * a = -(4 * c * a) + b ^ 2 := by ring
example {α} [linear_ordered_field α] (a b c : α) :
b ^ 2 - 4 * a * c = 4 * a * 0 + b * b - 4 * a * c := by ring
example {α} [comm_semiring α] (x y z : α) (n : ℕ) :
(x + y) * (z * (y * y) + (x * x ^ n + (1 + ↑n) * x ^ n * y)) =
x * (x * x ^ n) + ((2 + ↑n) * (x * x ^ n) * y + (x * z + (z * y + (1 + ↑n) * x ^ n)) * (y * y)) := by ring
example {α} [comm_ring α] (a b c d e : α) :
(-(a * b) + c + d) * e = (c + (d + -a * b)) * e := by ring
example (a n s: ℕ) : a * (n - s) = (n - s) * a := by ring
example (x y z : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) (hz : z ≠ 0) :
x / (y / z) + y ⁻¹ + 1 / (y * -x) = -1/ (x * y) + (x * z + 1) / y :=
begin
field_simp [hx, hy, hz],
ring
end
example (a b c d x y : ℚ) (hx : x ≠ 0) (hy : y ≠ 0) :
a + b / x - c / x^2 + d / x^3 = a + x⁻¹ * (y * b / y + (d / x - c) / x) :=
begin
field_simp [hx, hy],
ring
end
|
d335fa61d8d53186f36ccf2a2e8aa1a6b9cd6e46 | acc85b4be2c618b11fc7cb3005521ae6858a8d07 | /order/bounded_lattice.lean | 68f83050b83f270a8d780002a2a4a5bb0ab5aa1b | [
"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 | 3,075 | 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
Defines bounded lattice type class hierarchy.
Includes the Prop and fun instances.
-/
import order.lattice
set_option old_structure_cmd true
universes u v
variable {α : Type u}
namespace lattice
/- Bounded lattices -/
class bounded_lattice (α : Type u) extends lattice α, order_top α, order_bot α
instance semilattice_inf_top_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_inf_top α :=
{ bl with le_top := assume x, @le_top α _ x }
instance semilattice_inf_bot_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_inf_bot α :=
{ bl with bot_le := assume x, @bot_le α _ x }
instance semilattice_sup_top_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_sup_top α :=
{ bl with le_top := assume x, @le_top α _ x }
instance semilattice_sup_bot_of_bounded_lattice (α : Type u) [bl : bounded_lattice α] : semilattice_sup_bot α :=
{ bl with bot_le := assume x, @bot_le α _ x }
/- Prop instance -/
instance bounded_lattice_Prop : bounded_lattice Prop :=
{ lattice.bounded_lattice .
le := λa b, a → b,
le_refl := assume _, id,
le_trans := assume a b c f g, g ∘ f,
le_antisymm := assume a b Hab Hba, propext ⟨Hab, Hba⟩,
sup := or,
le_sup_left := @or.inl,
le_sup_right := @or.inr,
sup_le := assume a b c, or.rec,
inf := and,
inf_le_left := @and.left,
inf_le_right := @and.right,
le_inf := assume a b c Hab Hac Ha, and.intro (Hab Ha) (Hac Ha),
top := true,
le_top := assume a Ha, true.intro,
bot := false,
bot_le := @false.elim }
section logic
variable [preorder α]
theorem monotone_and {p q : α → Prop} (m_p : monotone p) (m_q : monotone q) :
monotone (λx, p x ∧ q x) :=
assume a b h, and.imp (m_p h) (m_q h)
-- Note: by finish [monotone] doesn't work
theorem monotone_or {p q : α → Prop} (m_p : monotone p) (m_q : monotone q) :
monotone (λx, p x ∨ q x) :=
assume a b h, or.imp (m_p h) (m_q h)
end logic
/- Function lattices -/
/- TODO:
* build up the lattice hierarchy for `fun`-functor piecewise. semilattic_*, bounded_lattice, lattice ...
* can this be generalized to the dependent function space?
-/
instance bounded_lattice_fun {α : Type u} {β : Type v} [bounded_lattice β] :
bounded_lattice (α → β) :=
{ partial_order_fun with
sup := λf g a, f a ⊔ g a,
le_sup_left := assume f g a, le_sup_left,
le_sup_right := assume f g a, le_sup_right,
sup_le := assume f g h Hfg Hfh a, sup_le (Hfg a) (Hfh a),
inf := λf g a, f a ⊓ g a,
inf_le_left := assume f g a, inf_le_left,
inf_le_right := assume f g a, inf_le_right,
le_inf := assume f g h Hfg Hfh a, le_inf (Hfg a) (Hfh a),
top := λa, ⊤,
le_top := assume f a, le_top,
bot := λa, ⊥,
bot_le := assume f a, bot_le }
end lattice
|
a157f1c6cb66215845d6b269e5987e997eafeacf | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/ring_theory/integral_domain.lean | 61095b3bf2f57b2fc6f6b99d0667d68f76d66c8a | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,455 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Chris Hughes
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.fintype.card
import Mathlib.data.polynomial.ring_division
import Mathlib.group_theory.order_of_element
import Mathlib.algebra.geom_sum
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
/-!
# Integral domains
Assorted theorems about integral domains.
## Main theorems
* `is_cyclic_of_subgroup_integral_domain` : A finite subgroup of the units of an integral domain
is cyclic.
* `field_of_integral_domain` : A finite integral domain is a field.
## Tags
integral domain, finite integral domain, finite field
-/
theorem card_nth_roots_subgroup_units {R : Type u_1} {G : Type u_2} [integral_domain R] [group G] [fintype G] (f : G →* R) (hf : function.injective ⇑f) {n : ℕ} (hn : 0 < n) (g₀ : G) : finset.card (has_sep.sep (fun (g : G) => g ^ n = g₀) finset.univ) ≤
coe_fn multiset.card (polynomial.nth_roots n (coe_fn f g₀)) := sorry
/-- A finite subgroup of the unit group of an integral domain is cyclic. -/
theorem is_cyclic_of_subgroup_integral_domain {R : Type u_1} {G : Type u_2} [integral_domain R] [group G] [fintype G] (f : G →* R) (hf : function.injective ⇑f) : is_cyclic G := sorry
/-- The unit group of a finite integral domain is cyclic. -/
protected instance units.is_cyclic {R : Type u_1} [integral_domain R] [fintype R] : is_cyclic (units R) :=
is_cyclic_of_subgroup_integral_domain (units.coe_hom R) units.ext
/-- Every finite integral domain is a field. -/
def field_of_integral_domain {R : Type u_1} [integral_domain R] [DecidableEq R] [fintype R] : field R :=
field.mk integral_domain.add sorry integral_domain.zero sorry sorry integral_domain.neg integral_domain.sub sorry sorry
integral_domain.mul sorry integral_domain.one sorry sorry sorry sorry sorry
(fun (a : R) => dite (a = 0) (fun (h : a = 0) => 0) fun (h : ¬a = 0) => fintype.bij_inv sorry 1) sorry sorry sorry
/-- A finite subgroup of the units of an integral domain is cyclic. -/
protected instance subgroup_units_cyclic {R : Type u_1} [integral_domain R] (S : set (units R)) [is_subgroup S] [fintype ↥S] : is_cyclic ↥S := sorry
theorem card_fiber_eq_of_mem_range {G : Type u_2} [group G] [fintype G] {H : Type u_1} [group H] [DecidableEq H] (f : G →* H) {x : H} {y : H} (hx : x ∈ set.range ⇑f) (hy : y ∈ set.range ⇑f) : finset.card (finset.filter (fun (g : G) => coe_fn f g = x) finset.univ) =
finset.card (finset.filter (fun (g : G) => coe_fn f g = y) finset.univ) := sorry
/-- In an integral domain, a sum indexed by a nontrivial homomorphism from a finite group is zero. -/
theorem sum_hom_units_eq_zero {R : Type u_1} {G : Type u_2} [integral_domain R] [group G] [fintype G] (f : G →* R) (hf : f ≠ 1) : (finset.sum finset.univ fun (g : G) => coe_fn f g) = 0 := sorry
/-- In an integral domain, a sum indexed by a homomorphism from a finite group is zero,
unless the homomorphism is trivial, in which case the sum is equal to the cardinality of the group. -/
theorem sum_hom_units {R : Type u_1} {G : Type u_2} [integral_domain R] [group G] [fintype G] (f : G →* R) [Decidable (f = 1)] : (finset.sum finset.univ fun (g : G) => coe_fn f g) = ite (f = 1) (↑(fintype.card G)) 0 := sorry
|
f2e74aa0f71a24eb2d549fecb0d8045ea91e52b1 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/tactic/lint/type_classes.lean | e9b3ca7ecae7cd081046a91c198732a298fb3bef | [
"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 | 24,433 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Robert Y. Lewis, Gabriel Ebner
-/
import data.bool.basic
import meta.rb_map
import tactic.lint.basic
/-!
# Linters about type classes
This file defines several linters checking the correct usage of type classes
and the appropriate definition of instances:
* `instance_priority` ensures that blanket instances have low priority.
* `has_inhabited_instances` checks that every type has an `inhabited` instance.
* `impossible_instance` checks that there are no instances which can never apply.
* `incorrect_type_class_argument` checks that only type classes are used in
instance-implicit arguments.
* `dangerous_instance` checks for instances that generate subproblems with metavariables.
* `fails_quickly` checks that type class resolution finishes quickly.
* `class_structure` checks that every `class` is a structure, i.e. `@[class] def` is forbidden.
* `has_coe_variable` checks that there is no instance of type `has_coe α t`.
* `inhabited_nonempty` checks whether `[inhabited α]` arguments could be generalized
to `[nonempty α]`.
* `decidable_classical` checks propositions for `[decidable_... p]` hypotheses that are not used
in the statement, and could thus be removed by using `classical` in the proof.
* `linter.has_coe_to_fun` checks whether necessary `has_coe_to_fun` instances are declared.
* `linter.check_reducibility` checks whether non-instances with a class as type are reducible.
-/
open tactic
/-- Pretty prints a list of arguments of a declaration. Assumes `l` is a list of argument positions
and binders (or any other element that can be pretty printed).
`l` can be obtained e.g. by applying `list.indexes_values` to a list obtained by
`get_pi_binders`. -/
meta def print_arguments {α} [has_to_tactic_format α] (l : list (ℕ × α)) : tactic string := do
fs ← l.mmap (λ ⟨n, b⟩, (λ s, to_fmt "argument " ++ to_fmt (n+1) ++ ": " ++ s) <$> pp b),
return $ fs.to_string_aux tt
/-- checks whether an instance that always applies has priority ≥ 1000. -/
private meta def instance_priority (d : declaration) : tactic (option string) := do
let nm := d.to_name,
b ← is_instance nm,
/- return `none` if `d` is not an instance -/
if ¬ b then return none else do
(is_persistent, prio) ← has_attribute `instance nm,
/- return `none` if `d` is has low priority -/
if prio < 1000 then return none else do
(_, tp) ← open_pis d.type,
tp ← whnf tp transparency.none,
let (fn, args) := tp.get_app_fn_args,
cls ← get_decl fn.const_name,
let (pi_args, _) := cls.type.pi_binders,
guard (args.length = pi_args.length),
/- List all the arguments of the class that block type-class inference from firing
(if they are metavariables). These are all the arguments except instance-arguments and
out-params. -/
let relevant_args := (args.zip pi_args).filter_map $ λ⟨e, ⟨_, info, tp⟩⟩,
if info = binder_info.inst_implicit ∨ tp.get_app_fn.is_constant_of `out_param
then none else some e,
let always_applies := relevant_args.all expr.is_local_constant ∧ relevant_args.nodup,
if always_applies then return $ some "set priority below 1000" else return none
/--
There are places where typeclass arguments are specified with implicit `{}` brackets instead of
the usual `[]` brackets. This is done when the instances can be inferred because they are implicit
arguments to the type of one of the other arguments. When they can be inferred from these other
arguments, it is faster to use this method than to use type class inference.
For example, when writing lemmas about `(f : α →+* β)`, it is faster to specify the fact that `α`
and `β` are `semiring`s as `{rα : semiring α} {rβ : semiring β}` rather than the usual
`[semiring α] [semiring β]`.
-/
library_note "implicit instance arguments"
/--
Certain instances always apply during type-class resolution. For example, the instance
`add_comm_group.to_add_group {α} [add_comm_group α] : add_group α` applies to all type-class
resolution problems of the form `add_group _`, and type-class inference will then do an
exhaustive search to find a commutative group. These instances take a long time to fail.
Other instances will only apply if the goal has a certain shape. For example
`int.add_group : add_group ℤ` or
`add_group.prod {α β} [add_group α] [add_group β] : add_group (α × β)`. Usually these instances
will fail quickly, and when they apply, they are almost always the desired instance.
For this reason, we want the instances of the second type (that only apply in specific cases) to
always have higher priority than the instances of the first type (that always apply).
See also #1561.
Therefore, if we create an instance that always applies, we set the priority of these instances to
100 (or something similar, which is below the default value of 1000).
-/
library_note "lower instance priority"
/-- A linter object for checking instance priorities of instances that always apply.
This is in the default linter set. -/
@[linter] meta def linter.instance_priority : linter :=
{ test := instance_priority,
no_errors_found := "All instance priorities are good.",
errors_found := "DANGEROUS INSTANCE PRIORITIES.
The following instances always apply, and therefore should have a priority < 1000.
If you don't know what priority to choose, use priority 100.
See note [lower instance priority] for instructions to change the priority.",
auto_decls := tt }
/-- Reports declarations of types that do not have an associated `inhabited` instance. -/
private meta def has_inhabited_instance (d : declaration) : tactic (option string) := do
tt ← pure d.is_trusted | pure none,
ff ← has_attribute' `reducible d.to_name | pure none,
ff ← has_attribute' `class d.to_name | pure none,
(_, ty) ← open_pis d.type,
ty ← whnf ty,
if ty = `(Prop) then pure none else do
`(Sort _) ← whnf ty | pure none,
insts ← attribute.get_instances `instance,
insts_tys ← insts.mmap $ λ i, expr.pi_codomain <$> declaration.type <$> get_decl i,
let inhabited_insts := insts_tys.filter (λ i,
i.app_fn.const_name = ``inhabited ∨ i.app_fn.const_name = `unique),
let inhabited_tys := inhabited_insts.map (λ i, i.app_arg.get_app_fn.const_name),
if d.to_name ∈ inhabited_tys then
pure none
else
pure "inhabited instance missing"
/-- A linter for missing `inhabited` instances. -/
@[linter]
meta def linter.has_inhabited_instance : linter :=
{ test := has_inhabited_instance,
auto_decls := ff,
no_errors_found := "No types have missing inhabited instances.",
errors_found := "TYPES ARE MISSING INHABITED INSTANCES:",
is_fast := ff }
attribute [nolint has_inhabited_instance] pempty
/-- Checks whether an instance can never be applied. -/
private meta def impossible_instance (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
(binders, _) ← get_pi_binders_nondep d.type,
let bad_arguments := binders.filter $ λ nb, nb.2.info ≠ binder_info.inst_implicit,
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "Impossible to infer " ++ s) <$> print_arguments bad_arguments
/-- A linter object for `impossible_instance`. -/
@[linter] meta def linter.impossible_instance : linter :=
{ test := impossible_instance,
auto_decls := tt,
no_errors_found := "All instances are applicable.",
errors_found := "IMPOSSIBLE INSTANCES FOUND.
These instances have an argument that cannot be found during type-class resolution, and " ++
"therefore can never succeed. Either mark the arguments with square brackets (if it is a " ++
"class), or don't make it an instance." }
/-- Checks whether an instance can never be applied. -/
private meta def incorrect_type_class_argument (d : declaration) : tactic (option string) := do
(binders, _) ← get_pi_binders d.type,
let instance_arguments := binders.indexes_values $
λ b : binder, b.info = binder_info.inst_implicit,
/- the head of the type should either unfold to a class, or be a local constant.
A local constant is allowed, because that could be a class when applied to the
proper arguments. -/
bad_arguments ← instance_arguments.mfilter (λ ⟨_, b⟩, do
(_, head) ← open_pis b.type,
if head.get_app_fn.is_local_constant then return ff else do
bnot <$> is_class head),
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "These are not classes. " ++ s) <$> print_arguments bad_arguments
/-- A linter object for `incorrect_type_class_argument`. -/
@[linter] meta def linter.incorrect_type_class_argument : linter :=
{ test := incorrect_type_class_argument,
auto_decls := tt,
no_errors_found := "All declarations have correct type-class arguments.",
errors_found := "INCORRECT TYPE-CLASS ARGUMENTS.
Some declarations have non-classes between [square brackets]:" }
/-- Checks whether an instance is dangerous: it creates a new type-class problem with metavariable
arguments. -/
private meta def dangerous_instance (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
(local_constants, target) ← open_pis d.type,
let instance_arguments := local_constants.indexes_values $
λ e : expr, e.local_binding_info = binder_info.inst_implicit,
let bad_arguments := local_constants.indexes_values $ λ x,
!target.has_local_constant x &&
(x.local_binding_info ≠ binder_info.inst_implicit) &&
instance_arguments.any (λ nb, nb.2.local_type.has_local_constant x),
let bad_arguments : list (ℕ × binder) := bad_arguments.map $ λ ⟨n, e⟩, ⟨n, e.to_binder⟩,
_ :: _ ← return bad_arguments | return none,
(λ s, some $ "The following arguments become metavariables. " ++ s) <$>
print_arguments bad_arguments
/-- A linter object for `dangerous_instance`. -/
@[linter] meta def linter.dangerous_instance : linter :=
{ test := dangerous_instance,
no_errors_found := "No dangerous instances.",
errors_found := "DANGEROUS INSTANCES FOUND.\nThese instances are recursive, and create a new " ++
"type-class problem which will have metavariables.
Possible solution: remove the instance attribute or make it a local instance instead.
Currently this linter does not check whether the metavariables only occur in arguments marked " ++
"with `out_param`, in which case this linter gives a false positive.",
auto_decls := tt }
/-- Auxilliary definition for `find_nondep` -/
meta def find_nondep_aux : list expr → expr_set → tactic expr_set
| [] r := return r
| (h::hs) r :=
do type ← infer_type h,
find_nondep_aux hs $ r.union type.list_local_consts'
/-- Finds all hypotheses that don't occur in the target or other hypotheses. -/
meta def find_nondep : tactic (list expr) := do
ctx ← local_context,
tgt ← target,
lconsts ← find_nondep_aux ctx tgt.list_local_consts',
return $ ctx.filter $ λ e, !lconsts.contains e
/--
Tests whether type-class inference search will end quickly on certain unsolvable
type-class problems. This is to detect loops or very slow searches, which are problematic
(recall that normal type-class search often creates unsolvable subproblems, which have to fail
quickly for type-class inference to perform well.
We create these type-class problems by taking an instance, and removing the last hypothesis that
doesn't appear in the goal (or a later hypothesis). Note: this argument is necessarily an
instance-implicit argument if it passes the `linter.incorrect_type_class_argument`.
This tactic succeeds if `mk_instance` succeeds quickly or fails quickly with the error
message that it cannot find an instance. It fails if the tactic takes too long, or if any other
error message is raised (usually a maximum depth in the search).
-/
meta def fails_quickly (max_steps : ℕ) (d : declaration) : tactic (option string) := retrieve $ do
tt ← is_instance d.to_name | return none,
let e := d.type,
g ← mk_meta_var e,
set_goals [g],
intros,
l@(_::_) ← find_nondep | return none, -- if all arguments occur in the goal, this instance is ok
clear l.ilast,
reset_instance_cache,
state ← read,
let state_msg := "\nState:\n" ++ to_string state,
tgt ← target >>= instantiate_mvars,
sum.inr msg ← retrieve_or_report_error $ tactic.try_for max_steps $ mk_instance tgt |
return none, /- it's ok if type-class inference can find an instance with fewer hypotheses.
This happens a lot for `has_sizeof` and `has_well_founded`, but can also happen if there is a
noncomputable instance with fewer assumptions. -/
return $ if "tactic.mk_instance failed to generate instance for".is_prefix_of msg then none else
some $ (++ state_msg) $
if msg = "try_for tactic failed, timeout" then "type-class inference timed out" else msg
/--
A linter object for `fails_quickly`.
We currently set the number of steps in the type-class search pretty high.
Some instances take quite some time to fail, and we seem to run against the caching issue in
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/odd.20repeated.20type.20class.20search
-/
@[linter] meta def linter.fails_quickly : linter :=
{ test := fails_quickly 20000,
auto_decls := tt,
no_errors_found := "No type-class searches timed out.",
errors_found := "TYPE CLASS SEARCHES TIMED OUT.
The following instances are part of a loop, or an excessively long search.
It is common that the loop occurs in a different class than the one flagged below,
but usually an instance that is part of the loop is also flagged.
To debug:
(1) run `scripts/mk_all.sh` and create a file with `import all` and
`set_option trace.class_instances true`
(2) Recreate the state shown in the error message. You can do this easily by copying the type of
the instance (the output of `#check @my_instance`), turning this into an example and removing the
last argument in square brackets. Prove the example using `by apply_instance`.
For example, if `additive.topological_add_group` raises an error, run
```
example {G : Type*} [topological_space G] [group G] : topological_add_group (additive G) :=
by apply_instance
```
(3) What error do you get?
(3a) If the error is \"tactic.mk_instance failed to generate instance\",
there might be nothing wrong. But it might take unreasonably long for the type-class inference to
fail. Check the trace to see if type-class inference takes any unnecessary long unexpected turns.
If not, feel free to increase the value in the definition of the linter `fails_quickly`.
(3b) If the error is \"maximum class-instance resolution depth has been reached\" there is almost
certainly a loop in the type-class inference. Find which instance causes the type-class inference to
go astray, and fix that instance.",
is_fast := ff }
/-- Checks that all uses of the `@[class]` attribute apply to structures or inductive types.
This is future-proofing for lean 4, which no longer supports `@[class] def`. -/
private meta def class_structure (n : name) : tactic (option string) := do
is_class ← has_attribute' `class n,
if is_class then do
env ← get_env,
pure $ if env.is_inductive n then none else
"is a non-structure or inductive type marked @[class]"
else pure none
/-- A linter object for `class_structure`. -/
@[linter] meta def linter.class_structure : linter :=
{ test := λ d, class_structure d.to_name,
auto_decls := tt,
no_errors_found := "All classes are structures.",
errors_found := "USE OF @[class] def IS DISALLOWED:" }
/--
Tests whether there is no instance of type `has_coe α t` where `α` is a variable,
or `has_coe t α` where `α` does not occur in `t`.
See note [use has_coe_t].
-/
private meta def has_coe_variable (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
`(has_coe %%a %%b) ← return d.type.pi_codomain | return none,
if a.is_var then
return $ some $ "illegal instance, first argument is variable"
else if b.is_var ∧ ¬ b.occurs a then
return $ some $ "illegal instance, second argument is variable not occurring in first argument"
else
return none
/-- A linter object for `has_coe_variable`. -/
@[linter] meta def linter.has_coe_variable : linter :=
{ test := has_coe_variable,
auto_decls := tt,
no_errors_found := "No invalid `has_coe` instances.",
errors_found := "INVALID `has_coe` INSTANCES.
Make the following declarations instances of the class `has_coe_t` instead of `has_coe`." }
/-- Checks whether a declaration is prop-valued and takes an `inhabited _` argument that is unused
elsewhere in the type. In this case, that argument can be replaced with `nonempty _`. -/
private meta def inhabited_nonempty (d : declaration) : tactic (option string) :=
do tt ← is_prop d.type | return none,
(binders, _) ← get_pi_binders_nondep d.type,
let inhd_binders := binders.filter $ λ pr, pr.2.type.is_app_of `inhabited,
if inhd_binders.length = 0 then return none
else (λ s, some $ "The following `inhabited` instances should be `nonempty`. " ++ s) <$>
print_arguments inhd_binders
/-- A linter object for `inhabited_nonempty`. -/
@[linter] meta def linter.inhabited_nonempty : linter :=
{ test := inhabited_nonempty,
auto_decls := ff,
no_errors_found := "No uses of `inhabited` arguments should be replaced with `nonempty`.",
errors_found := "USES OF `inhabited` SHOULD BE REPLACED WITH `nonempty`." }
/-- Checks whether a declaration is `Prop`-valued and takes a `decidable* _`
hypothesis that is unused elsewhere in the type.
In this case, that hypothesis can be replaced with `classical` in the proof.
Theorems in the `decidable` namespace are exempt from the check. -/
private meta def decidable_classical (d : declaration) : tactic (option string) :=
do tt ← is_prop d.type | return none,
ff ← pure $ (`decidable).is_prefix_of d.to_name | return none,
(binders, _) ← get_pi_binders_nondep d.type,
let deceq_binders := binders.filter $ λ pr, pr.2.type.is_app_of `decidable_eq
∨ pr.2.type.is_app_of `decidable_pred ∨ pr.2.type.is_app_of `decidable_rel
∨ pr.2.type.is_app_of `decidable,
if deceq_binders.length = 0 then return none
else (λ s, some $ "The following `decidable` hypotheses should be replaced with
`classical` in the proof. " ++ s) <$>
print_arguments deceq_binders
/-- A linter object for `decidable_classical`. -/
@[linter] meta def linter.decidable_classical : linter :=
{ test := decidable_classical,
auto_decls := ff,
no_errors_found := "No uses of `decidable` arguments should be replaced with `classical`.",
errors_found := "USES OF `decidable` SHOULD BE REPLACED WITH `classical` IN THE PROOF." }
/- The file `logic/basic.lean` emphasizes the differences between what holds under classical
and non-classical logic. It makes little sense to make all these lemmas classical, so we add them
to the list of lemmas which are not checked by the linter `decidable_classical`. -/
attribute [nolint decidable_classical] dec_em dec_em' not.decidable_imp_symm
/-- Checks whether a declaration is `Prop`-valued and takes a `fintype _`
hypothesis that is unused elsewhere in the type.
In this case, that hypothesis can be replaced with `casesI nonempty_fintype _` in the proof. -/
meta def linter.fintype_finite_fun (d : declaration) : tactic (option string) :=
do tt ← is_prop d.type | return none,
(binders, _) ← get_pi_binders_nondep d.type,
let fintype_binders := binders.filter $ λ pr, pr.2.type.is_app_of `fintype,
if fintype_binders.length = 0 then return none
else (λ s, some $ "The following `fintype` hypotheses should be replaced with
`casesI nonempty_fintype _` in the proof. " ++ s) <$>
print_arguments fintype_binders
/-- A linter object for `fintype` vs `finite`. -/
@[linter] meta def linter.fintype_finite : linter :=
{ test := linter.fintype_finite_fun,
auto_decls := ff,
no_errors_found :=
"No uses of `fintype` arguments should be replaced with `casesI nonempty_fintype _`.",
errors_found :=
"USES OF `fintype` SHOULD BE REPLACED WITH `casesI nonempty_fintype _` IN THE PROOF." }
private meta def has_coe_to_fun_linter (d : declaration) : tactic (option string) :=
retrieve $ do
tt ← return d.is_trusted | pure none,
mk_meta_var d.type >>= set_goals ∘ pure,
args ← unfreezing intros,
expr.sort _ ← target | pure none,
let ty : expr := (expr.const d.to_name d.univ_levels).mk_app args,
some coe_fn_inst ←
try_core $ to_expr ``(_root_.has_coe_to_fun %%ty _) >>= mk_instance | pure none,
set_bool_option `pp.all true,
some trans_inst@(expr.app (expr.app _ trans_inst_1) trans_inst_2) ←
try_core $ to_expr ``(@_root_.coe_fn_trans %%ty _ _ _ _) | pure none,
tt ← succeeds $ unify trans_inst coe_fn_inst transparency.reducible | pure none,
set_bool_option `pp.all true,
trans_inst_1 ← pp trans_inst_1,
trans_inst_2 ← pp trans_inst_2,
pure $ format.to_string $
"`has_coe_to_fun` instance is definitionally equal to a transitive instance composed of: " ++
trans_inst_1.group.indent 2 ++
format.line ++ "and" ++
trans_inst_2.group.indent 2
/-- Linter that checks whether `has_coe_to_fun` instances comply with Note [function coercion]. -/
@[linter] meta def linter.has_coe_to_fun : linter :=
{ test := has_coe_to_fun_linter,
auto_decls := tt,
no_errors_found := "has_coe_to_fun is used correctly",
errors_found := "INVALID/MISSING `has_coe_to_fun` instances.
You should add a `has_coe_to_fun` instance for the following types.
See Note [function coercion]." }
/--
Checks whether an instance contains a semireducible non-instance with a class as
type in its value. We add some restrictions to get not too many false positives:
* We only consider classes with an `add` or `mul` field, since those classes are most likely to
occur as a field to another class, and be an extension of another class.
* We only consider instances of type-valued classes and non-instances that are definitions.
* We currently ignore declarations `foo` that have a `foo._main` declaration. We could look inside,
or at the generated equation lemmas, but it's unlikely that there are many problematic instances
defined using the equation compiler.
-/
meta def check_reducible_non_instances (d : declaration) : tactic (option string) := do
tt ← is_instance d.to_name | return none,
ff ← is_prop d.type | return none,
env ← get_env,
-- We only check if the class of the instance contains an `add` or a `mul` field.
let cls := d.type.pi_codomain.get_app_fn.const_name,
some constrs ← return $ env.structure_fields cls | return none,
tt ← return $ constrs.mem `add || constrs.mem `mul | return none,
l ← d.value.list_constant.mfilter $ λ nm, do
{ d ← env.get nm,
ff ← is_instance nm | return ff,
tt ← is_class d.type | return ff,
tt ← return d.is_definition | return ff,
-- We only check if the class of the non-instance contains an `add` or a `mul` field.
let cls := d.type.pi_codomain.get_app_fn.const_name,
some constrs ← return $ env.structure_fields cls | return ff,
tt ← return $ constrs.mem `add || constrs.mem `mul | return ff,
ff ← has_attribute' `reducible nm | return ff,
return tt },
if l.empty then return none else
-- we currently ignore declarations that have a `foo._main` declaration.
if l.to_list = [d.to_name ++ `_main] then return none else
return $ some $ "This instance contains the declarations " ++ to_string l.to_list ++
", which are semireducible non-instances."
/-- A linter that checks whether an instance contains a semireducible non-instance. -/
@[linter]
meta def linter.check_reducibility : linter :=
{ test := check_reducible_non_instances,
auto_decls := ff,
no_errors_found :=
"All non-instances are reducible.",
errors_found := "THE FOLLOWING INSTANCES MIGHT NOT REDUCE.
These instances contain one or more declarations that are not instances and are also not marked
`@[reducible]`. This means that type-class inference cannot unfold these declarations, " ++
"which might mean that type-class inference cannot infer that two instances are definitionally " ++
"equal. This can cause unexpected errors when this class occurs " ++
"as an *argument* to a type-class problem. See note [reducible non-instances].",
is_fast := tt }
|
3515cc9c9539e8427482a166bd02977ca98aaa75 | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/subterminal.lean | e23b134fcb5018bbf00d85f182eb566838833309 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 4,802 | 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.binary_products
/-!
# Subterminal objects
Subterminal objects are the objects which can be thought of as subobjects of the terminal object.
In fact, the definition can be constructed to not require a terminal object, by defining `A` to be
subterminal iff for any `Z`, there is at most one morphism `Z ⟶ A`.
An alternate definition is that the diagonal morphism `A ⟶ A ⨯ A` is an isomorphism.
In this file we define subterminal objects and show the equivalence of these three definitions.
We also construct the subcategory of subterminal objects.
## TODO
* Define exponential ideals, and show this subcategory is an exponential ideal.
* Define subobject lattices in general, show that `subterminals C` is equivalent to the subobject
category of a terminal object.
* Use both the above to show that in a locally cartesian closed category, every subobject lattice
is cartesian closed (equivalently, a Heyting algebra).
-/
universes v₁ v₂ u₁ u₂
noncomputable theory
namespace category_theory
open limits category
variables {C : Type u₁} [category.{v₁} C] {A : C}
/-- An object `A` is subterminal iff for any `Z`, there is at most one morphism `Z ⟶ A`. -/
def is_subterminal (A : C) : Prop := ∀ ⦃Z : C⦄ (f g : Z ⟶ A), f = g
lemma is_subterminal.def : is_subterminal A ↔ ∀ ⦃Z : C⦄ (f g : Z ⟶ A), f = g := iff.rfl
/--
If `A` is subterminal, the unique morphism from it to a terminal object is a monomorphism.
The converse of `is_subterminal_of_mono_is_terminal_from`.
-/
lemma is_subterminal.mono_is_terminal_from (hA : is_subterminal A) {T : C} (hT : is_terminal T) :
mono (hT.from A) :=
{ right_cancellation := λ Z g h _, hA _ _ }
/--
If `A` is subterminal, the unique morphism from it to the terminal object is a monomorphism.
The converse of `is_subterminal_of_mono_terminal_from`.
-/
lemma is_subterminal.mono_terminal_from [has_terminal C] (hA : is_subterminal A) :
mono (terminal.from A) :=
hA.mono_is_terminal_from terminal_is_terminal
/--
If the unique morphism from `A` to a terminal object is a monomorphism, `A` is subterminal.
The converse of `is_subterminal.mono_is_terminal_from`.
-/
lemma is_subterminal_of_mono_is_terminal_from {T : C} (hT : is_terminal T) [mono (hT.from A)] :
is_subterminal A :=
λ Z f g, by { rw ← cancel_mono (hT.from A), apply hT.hom_ext }
/--
If the unique morphism from `A` to the terminal object is a monomorphism, `A` is subterminal.
The converse of `is_subterminal.mono_terminal_from`.
-/
lemma is_subterminal_of_mono_terminal_from [has_terminal C] [mono (terminal.from A)] :
is_subterminal A :=
λ Z f g, by { rw ← cancel_mono (terminal.from A), apply subsingleton.elim }
lemma is_subterminal_of_is_terminal {T : C} (hT : is_terminal T) : is_subterminal T :=
λ Z f g, hT.hom_ext _ _
lemma is_subterminal_of_terminal [has_terminal C] : is_subterminal (⊤_ C) :=
λ Z f g, subsingleton.elim _ _
/--
If `A` is subterminal, its diagonal morphism is an isomorphism.
The converse of `is_subterminal_of_is_iso_diag`.
-/
def is_subterminal.is_iso_diag (hA : is_subterminal A) [has_binary_product A A] :
is_iso (diag A) :=
{ inv := limits.prod.fst,
inv_hom_id' := by { rw is_subterminal.def at hA, tidy } }
/--
If the diagonal morphism of `A` is an isomorphism, then it is subterminal.
The converse of `is_subterminal.is_iso_diag`.
-/
lemma is_subterminal_of_is_iso_diag [has_binary_product A A] [is_iso (diag A)] :
is_subterminal A :=
λ Z f g,
begin
have : (limits.prod.fst : A ⨯ A ⟶ _) = limits.prod.snd,
{ simp [←cancel_epi (diag A)] },
rw [←prod.lift_fst f g, this, prod.lift_snd],
end
/-- If `A` is subterminal, it is isomorphic to `A ⨯ A`. -/
@[simps]
def is_subterminal.iso_diag (hA : is_subterminal A) [has_binary_product A A] :
A ⨯ A ≅ A :=
begin
letI := is_subterminal.is_iso_diag hA,
apply (as_iso (diag A)).symm,
end
variables (C)
/--
The (full sub)category of subterminal objects.
TODO: If `C` is the category of sheaves on a topological space `X`, this category is equivalent
to the lattice of open subsets of `X`. More generally, if `C` is a topos, this is the lattice of
"external truth values".
-/
@[derive category]
def subterminals (C : Type u₁) [category.{v₁} C] :=
{A : C // is_subterminal A}
instance [has_terminal C] : inhabited (subterminals C) :=
⟨⟨⊤_ C, is_subterminal_of_terminal⟩⟩
/-- The inclusion of the subterminal objects into the original category. -/
@[derive [full, faithful]]
def subterminal_inclusion : subterminals C ⥤ C := full_subcategory_inclusion _
end category_theory
|
77e24d67a651ca251c12d25a9da0b3bea4444fb4 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/num/lemmas.lean | f212e34464e381c6a3114ba0b5bc738faf5a7505 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 50,672 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.num.bitwise
import data.int.char_zero
import data.nat.gcd
import data.nat.psub
/-!
# Properties of the binary representation of integers
-/
local attribute [simp] add_assoc
namespace pos_num
variables {α : Type*}
@[simp, norm_cast] theorem cast_one [has_one α] [has_add α] :
((1 : pos_num) : α) = 1 := rfl
@[simp] theorem cast_one' [has_one α] [has_add α] : (pos_num.one : α) = 1 := rfl
@[simp, norm_cast] theorem cast_bit0 [has_one α] [has_add α] (n : pos_num) :
(n.bit0 : α) = _root_.bit0 n := rfl
@[simp, norm_cast] theorem cast_bit1 [has_one α] [has_add α] (n : pos_num) :
(n.bit1 : α) = _root_.bit1 n := rfl
@[simp, norm_cast] theorem cast_to_nat [add_monoid α] [has_one α] :
∀ n : pos_num, ((n : ℕ) : α) = n
| 1 := nat.cast_one
| (bit0 p) := (nat.cast_bit0 _).trans $ congr_arg _root_.bit0 p.cast_to_nat
| (bit1 p) := (nat.cast_bit1 _).trans $ congr_arg _root_.bit1 p.cast_to_nat
@[simp, norm_cast] theorem to_nat_to_int (n : pos_num) : ((n : ℕ) : ℤ) = n :=
by rw [← int.nat_cast_eq_coe_nat, cast_to_nat]
@[simp, norm_cast] theorem cast_to_int [add_group α] [has_one α] (n : pos_num) :
((n : ℤ) : α) = n :=
by rw [← to_nat_to_int, int.cast_coe_nat, cast_to_nat]
theorem succ_to_nat : ∀ n, (succ n : ℕ) = n + 1
| 1 := rfl
| (bit0 p) := rfl
| (bit1 p) := (congr_arg _root_.bit0 (succ_to_nat p)).trans $
show ↑p + 1 + ↑p + 1 = ↑p + ↑p + 1 + 1, by simp [add_left_comm]
theorem one_add (n : pos_num) : 1 + n = succ n := by cases n; refl
theorem add_one (n : pos_num) : n + 1 = succ n := by cases n; refl
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : pos_num) : ℕ) = m + n
| 1 b := by rw [one_add b, succ_to_nat, add_comm]; refl
| a 1 := by rw [add_one a, succ_to_nat]; refl
| (bit0 a) (bit0 b) := (congr_arg _root_.bit0 (add_to_nat a b)).trans $ add_add_add_comm _ _ _ _
| (bit0 a) (bit1 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $
show ((a + b) + (a + b) + 1 : ℕ) = (a + a) + (b + b + 1), by simp [add_left_comm]
| (bit1 a) (bit0 b) := (congr_arg _root_.bit1 (add_to_nat a b)).trans $
show ((a + b) + (a + b) + 1 : ℕ) = (a + a + 1) + (b + b), by simp [add_comm, add_left_comm]
| (bit1 a) (bit1 b) :=
show (succ (a + b) + succ (a + b) : ℕ) = (a + a + 1) + (b + b + 1),
by rw [succ_to_nat, add_to_nat]; simp [add_left_comm]
theorem add_succ : ∀ (m n : pos_num), m + succ n = succ (m + n)
| 1 b := by simp [one_add]
| (bit0 a) 1 := congr_arg bit0 (add_one a)
| (bit1 a) 1 := congr_arg bit1 (add_one a)
| (bit0 a) (bit0 b) := rfl
| (bit0 a) (bit1 b) := congr_arg bit0 (add_succ a b)
| (bit1 a) (bit0 b) := rfl
| (bit1 a) (bit1 b) := congr_arg bit1 (add_succ a b)
theorem bit0_of_bit0 : Π n, _root_.bit0 n = bit0 n
| 1 := rfl
| (bit0 p) := congr_arg bit0 (bit0_of_bit0 p)
| (bit1 p) := show bit0 (succ (_root_.bit0 p)) = _, by rw bit0_of_bit0; refl
theorem bit1_of_bit1 (n : pos_num) : _root_.bit1 n = bit1 n :=
show _root_.bit0 n + 1 = bit1 n, by rw [add_one, bit0_of_bit0]; refl
@[norm_cast]
theorem mul_to_nat (m) : ∀ n, ((m * n : pos_num) : ℕ) = m * n
| 1 := (mul_one _).symm
| (bit0 p) := show (↑(m * p) + ↑(m * p) : ℕ) = ↑m * (p + p), by rw [mul_to_nat, left_distrib]
| (bit1 p) := (add_to_nat (bit0 (m * p)) m).trans $
show (↑(m * p) + ↑(m * p) + ↑m : ℕ) = ↑m * (p + p) + m, by rw [mul_to_nat, left_distrib]
theorem to_nat_pos : ∀ n : pos_num, 0 < (n : ℕ)
| 1 := zero_lt_one
| (bit0 p) := let h := to_nat_pos p in add_pos h h
| (bit1 p) := nat.succ_pos _
theorem cmp_to_nat_lemma {m n : pos_num} : (m:ℕ) < n → (bit1 m : ℕ) < bit0 n :=
show (m:ℕ) < n → (m + m + 1 + 1 : ℕ) ≤ n + n,
by intro h; rw [nat.add_right_comm m m 1, add_assoc]; exact add_le_add h h
theorem cmp_swap (m) : ∀n, (cmp m n).swap = cmp n m :=
by induction m with m IH m IH; intro n;
cases n with n n; try {unfold cmp}; try {refl}; rw ←IH; cases cmp m n; refl
theorem cmp_to_nat : ∀ (m n), (ordering.cases_on (cmp m n) ((m:ℕ) < n) (m = n) ((n:ℕ) < m) : Prop)
| 1 1 := rfl
| (bit0 a) 1 := let h : (1:ℕ) ≤ a := to_nat_pos a in add_le_add h h
| (bit1 a) 1 := nat.succ_lt_succ $ to_nat_pos $ bit0 a
| 1 (bit0 b) := let h : (1:ℕ) ≤ b := to_nat_pos b in add_le_add h h
| 1 (bit1 b) := nat.succ_lt_succ $ to_nat_pos $ bit0 b
| (bit0 a) (bit0 b) := begin
have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro,
{ exact add_lt_add this this },
{ rw this },
{ exact add_lt_add this this }
end
| (bit0 a) (bit1 b) := begin dsimp [cmp],
have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro,
{ exact nat.le_succ_of_le (add_lt_add this this) },
{ rw this, apply nat.lt_succ_self },
{ exact cmp_to_nat_lemma this }
end
| (bit1 a) (bit0 b) := begin dsimp [cmp],
have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro,
{ exact cmp_to_nat_lemma this },
{ rw this, apply nat.lt_succ_self },
{ exact nat.le_succ_of_le (add_lt_add this this) },
end
| (bit1 a) (bit1 b) := begin
have := cmp_to_nat a b, revert this, cases cmp a b; dsimp; intro,
{ exact nat.succ_lt_succ (add_lt_add this this) },
{ rw this },
{ exact nat.succ_lt_succ (add_lt_add this this) }
end
@[norm_cast]
theorem lt_to_nat {m n : pos_num} : (m:ℕ) < n ↔ m < n :=
show (m:ℕ) < n ↔ cmp m n = ordering.lt, from
match cmp m n, cmp_to_nat m n with
| ordering.lt, h := by simp at h; simp [h]
| ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial
| ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial
end
@[norm_cast]
theorem le_to_nat {m n : pos_num} : (m:ℕ) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr lt_to_nat
end pos_num
namespace num
variables {α : Type*}
open pos_num
theorem add_zero (n : num) : n + 0 = n := by cases n; refl
theorem zero_add (n : num) : 0 + n = n := by cases n; refl
theorem add_one : ∀ n : num, n + 1 = succ n
| 0 := rfl
| (pos p) := by cases p; refl
theorem add_succ : ∀ (m n : num), m + succ n = succ (m + n)
| 0 n := by simp [zero_add]
| (pos p) 0 := show pos (p + 1) = succ (pos p + 0),
by rw [pos_num.add_one, add_zero]; refl
| (pos p) (pos q) := congr_arg pos (pos_num.add_succ _ _)
@[simp, norm_cast] theorem add_of_nat (m) : ∀ n, ((m + n : ℕ) : num) = m + n
| 0 := (add_zero _).symm
| (n+1) := show ((m + n : ℕ) + 1 : num) = m + (↑ n + 1),
by rw [add_one, add_one, add_succ, add_of_nat]
theorem bit0_of_bit0 : ∀ n : num, bit0 n = n.bit0
| 0 := rfl
| (pos p) := congr_arg pos p.bit0_of_bit0
theorem bit1_of_bit1 : ∀ n : num, bit1 n = n.bit1
| 0 := rfl
| (pos p) := congr_arg pos p.bit1_of_bit1
@[simp, norm_cast] theorem cast_zero [has_zero α] [has_one α] [has_add α] :
((0 : num) : α) = 0 := rfl
@[simp] theorem cast_zero' [has_zero α] [has_one α] [has_add α] :
(num.zero : α) = 0 := rfl
@[simp, norm_cast] theorem cast_one [has_zero α] [has_one α] [has_add α] :
((1 : num) : α) = 1 := rfl
@[simp] theorem cast_pos [has_zero α] [has_one α] [has_add α]
(n : pos_num) : (num.pos n : α) = n := rfl
theorem succ'_to_nat : ∀ n, (succ' n : ℕ) = n + 1
| 0 := (_root_.zero_add _).symm
| (pos p) := pos_num.succ_to_nat _
theorem succ_to_nat (n) : (succ n : ℕ) = n + 1 := succ'_to_nat n
@[simp, norm_cast] theorem cast_to_nat [add_monoid α] [has_one α] : ∀ n : num, ((n : ℕ) : α) = n
| 0 := nat.cast_zero
| (pos p) := p.cast_to_nat
@[simp, norm_cast] theorem to_nat_to_int (n : num) : ((n : ℕ) : ℤ) = n :=
by rw [← int.nat_cast_eq_coe_nat, cast_to_nat]
@[simp, norm_cast] theorem cast_to_int [add_group α] [has_one α] (n : num) : ((n : ℤ) : α) = n :=
by rw [← to_nat_to_int, int.cast_coe_nat, cast_to_nat]
@[norm_cast]
theorem to_of_nat : Π (n : ℕ), ((n : num) : ℕ) = n
| 0 := rfl
| (n+1) := by rw [nat.cast_add_one, add_one, succ_to_nat, to_of_nat]
@[simp, norm_cast]
theorem of_nat_cast [add_monoid α] [has_one α] (n : ℕ) : ((n : num) : α) = n :=
by rw [← cast_to_nat, to_of_nat]
@[norm_cast] theorem of_nat_inj {m n : ℕ} : (m : num) = n ↔ m = n :=
⟨λ h, function.left_inverse.injective to_of_nat h, congr_arg _⟩
@[norm_cast]
theorem add_to_nat : ∀ m n, ((m + n : num) : ℕ) = m + n
| 0 0 := rfl
| 0 (pos q) := (_root_.zero_add _).symm
| (pos p) 0 := rfl
| (pos p) (pos q) := pos_num.add_to_nat _ _
@[norm_cast]
theorem mul_to_nat : ∀ m n, ((m * n : num) : ℕ) = m * n
| 0 0 := rfl
| 0 (pos q) := (zero_mul _).symm
| (pos p) 0 := rfl
| (pos p) (pos q) := pos_num.mul_to_nat _ _
theorem cmp_to_nat : ∀ (m n), (ordering.cases_on (cmp m n) ((m:ℕ) < n) (m = n) ((n:ℕ) < m) : Prop)
| 0 0 := rfl
| 0 (pos b) := to_nat_pos _
| (pos a) 0 := to_nat_pos _
| (pos a) (pos b) :=
by { have := pos_num.cmp_to_nat a b; revert this; dsimp [cmp];
cases pos_num.cmp a b, exacts [id, congr_arg pos, id] }
@[norm_cast]
theorem lt_to_nat {m n : num} : (m:ℕ) < n ↔ m < n :=
show (m:ℕ) < n ↔ cmp m n = ordering.lt, from
match cmp m n, cmp_to_nat m n with
| ordering.lt, h := by simp at h; simp [h]
| ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial
| ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial
end
@[norm_cast]
theorem le_to_nat {m n : num} : (m:ℕ) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr lt_to_nat
end num
namespace pos_num
@[simp] theorem of_to_nat : Π (n : pos_num), ((n : ℕ) : num) = num.pos n
| 1 := rfl
| (bit0 p) :=
show ↑(p + p : ℕ) = num.pos p.bit0,
by rw [num.add_of_nat, of_to_nat];
exact congr_arg num.pos p.bit0_of_bit0
| (bit1 p) :=
show ((p + p : ℕ) : num) + 1 = num.pos p.bit1,
by rw [num.add_of_nat, of_to_nat];
exact congr_arg num.pos p.bit1_of_bit1
end pos_num
namespace num
@[simp, norm_cast] theorem of_to_nat : Π (n : num), ((n : ℕ) : num) = n
| 0 := rfl
| (pos p) := p.of_to_nat
@[norm_cast] theorem to_nat_inj {m n : num} : (m : ℕ) = n ↔ m = n :=
⟨λ h, function.left_inverse.injective of_to_nat h, congr_arg _⟩
/--
This tactic tries to turn an (in)equality about `num`s to one about `nat`s by rewriting.
```lean
example (n : num) (m : num) : n ≤ n + m :=
begin
num.transfer_rw,
exact nat.le_add_right _ _
end
```
-/
meta def transfer_rw : tactic unit :=
`[repeat {rw ← to_nat_inj <|> rw ← lt_to_nat <|> rw ← le_to_nat},
repeat {rw add_to_nat <|> rw mul_to_nat <|> rw cast_one <|> rw cast_zero}]
/--
This tactic tries to prove (in)equalities about `num`s by transfering them to the `nat` world and
then trying to call `simp`.
```lean
example (n : num) (m : num) : n ≤ n + m := by num.transfer
```
-/
meta def transfer : tactic unit := `[intros, transfer_rw, try {simp}]
instance : comm_semiring num :=
by refine_struct
{ add := (+),
zero := 0,
zero_add := zero_add,
add_zero := add_zero,
mul := (*),
one := 1,
nsmul := @nsmul_rec num ⟨0⟩ ⟨(+)⟩,
npow := @npow_rec num ⟨1⟩ ⟨(*)⟩ };
try { intros, refl }; try { transfer }; simp [mul_add, mul_left_comm, mul_comm, add_comm]
instance : ordered_cancel_add_comm_monoid num :=
{ add_left_cancel := by {intros a b c, transfer_rw, apply add_left_cancel},
lt := (<),
lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le},
le := (≤),
le_refl := by transfer,
le_trans := by {intros a b c, transfer_rw, apply le_trans},
le_antisymm := by {intros a b, transfer_rw, apply le_antisymm},
add_le_add_left := by {intros a b h c, revert h, transfer_rw,
exact λ h, add_le_add_left h c},
le_of_add_le_add_left := by {intros a b c, transfer_rw, apply le_of_add_le_add_left},
..num.comm_semiring }
instance : linear_ordered_semiring num :=
{ le_total := by {intros a b, transfer_rw, apply le_total},
zero_le_one := dec_trivial,
mul_lt_mul_of_pos_left := by {intros a b c, transfer_rw, apply mul_lt_mul_of_pos_left},
mul_lt_mul_of_pos_right := by {intros a b c, transfer_rw, apply mul_lt_mul_of_pos_right},
decidable_lt := num.decidable_lt,
decidable_le := num.decidable_le,
decidable_eq := num.decidable_eq,
exists_pair_ne := ⟨0, 1, dec_trivial⟩,
..num.comm_semiring, ..num.ordered_cancel_add_comm_monoid }
@[norm_cast]
theorem dvd_to_nat (m n : num) : (m : ℕ) ∣ n ↔ m ∣ n :=
⟨λ ⟨k, e⟩, ⟨k, by rw [← of_to_nat n, e]; simp⟩,
λ ⟨k, e⟩, ⟨k, by simp [e, mul_to_nat]⟩⟩
end num
namespace pos_num
variables {α : Type*}
open num
@[norm_cast] theorem to_nat_inj {m n : pos_num} : (m : ℕ) = n ↔ m = n :=
⟨λ h, num.pos.inj $ by rw [← pos_num.of_to_nat, ← pos_num.of_to_nat, h],
congr_arg _⟩
theorem pred'_to_nat : ∀ n, (pred' n : ℕ) = nat.pred n
| 1 := rfl
| (bit0 n) :=
have nat.succ ↑(pred' n) = ↑n,
by rw [pred'_to_nat n, nat.succ_pred_eq_of_pos (to_nat_pos n)],
match pred' n, this : ∀ k : num, nat.succ ↑k = ↑n →
↑(num.cases_on k 1 bit1 : pos_num) = nat.pred (_root_.bit0 n) with
| 0, (h : ((1:num):ℕ) = n) := by rw ← to_nat_inj.1 h; refl
| num.pos p, (h : nat.succ ↑p = n) :=
by rw ← h; exact (nat.succ_add p p).symm
end
| (bit1 n) := rfl
@[simp] theorem pred'_succ' (n) : pred' (succ' n) = n :=
num.to_nat_inj.1 $ by rw [pred'_to_nat, succ'_to_nat,
nat.add_one, nat.pred_succ]
@[simp] theorem succ'_pred' (n) : succ' (pred' n) = n :=
to_nat_inj.1 $ by rw [succ'_to_nat, pred'_to_nat,
nat.add_one, nat.succ_pred_eq_of_pos (to_nat_pos _)]
instance : has_dvd pos_num := ⟨λ m n, pos m ∣ pos n⟩
@[norm_cast] theorem dvd_to_nat {m n : pos_num} : (m:ℕ) ∣ n ↔ m ∣ n :=
num.dvd_to_nat (pos m) (pos n)
theorem size_to_nat : ∀ n, (size n : ℕ) = nat.size n
| 1 := nat.size_one.symm
| (bit0 n) := by rw [size, succ_to_nat, size_to_nat, cast_bit0,
nat.size_bit0 $ ne_of_gt $ to_nat_pos n]
| (bit1 n) := by rw [size, succ_to_nat, size_to_nat, cast_bit1,
nat.size_bit1]
theorem size_eq_nat_size : ∀ n, (size n : ℕ) = nat_size n
| 1 := rfl
| (bit0 n) := by rw [size, succ_to_nat, nat_size, size_eq_nat_size]
| (bit1 n) := by rw [size, succ_to_nat, nat_size, size_eq_nat_size]
theorem nat_size_to_nat (n) : nat_size n = nat.size n :=
by rw [← size_eq_nat_size, size_to_nat]
theorem nat_size_pos (n) : 0 < nat_size n :=
by cases n; apply nat.succ_pos
/--
This tactic tries to turn an (in)equality about `pos_num`s to one about `nat`s by rewriting.
```lean
example (n : pos_num) (m : pos_num) : n ≤ n + m :=
begin
pos_num.transfer_rw,
exact nat.le_add_right _ _
end
```
-/
meta def transfer_rw : tactic unit :=
`[repeat {rw ← to_nat_inj <|> rw ← lt_to_nat <|> rw ← le_to_nat},
repeat {rw add_to_nat <|> rw mul_to_nat <|> rw cast_one <|> rw cast_zero}]
/--
This tactic tries to prove (in)equalities about `pos_num`s by transferring them to the `nat` world
and then trying to call `simp`.
```lean
example (n : pos_num) (m : pos_num) : n ≤ n + m := by pos_num.transfer
```
-/
meta def transfer : tactic unit :=
`[intros, transfer_rw, try {simp [add_comm, add_left_comm, mul_comm, mul_left_comm]}]
instance : add_comm_semigroup pos_num :=
by refine {add := (+), ..}; transfer
instance : comm_monoid pos_num :=
by refine_struct {mul := (*), one := (1 : pos_num), npow := @npow_rec pos_num ⟨1⟩ ⟨(*)⟩};
try { intros, refl }; transfer
instance : distrib pos_num :=
by refine {add := (+), mul := (*), ..}; {transfer, simp [mul_add, mul_comm]}
instance : linear_order pos_num :=
{ lt := (<),
lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le},
le := (≤),
le_refl := by transfer,
le_trans := by {intros a b c, transfer_rw, apply le_trans},
le_antisymm := by {intros a b, transfer_rw, apply le_antisymm},
le_total := by {intros a b, transfer_rw, apply le_total},
decidable_lt := by apply_instance,
decidable_le := by apply_instance,
decidable_eq := by apply_instance }
@[simp] theorem cast_to_num (n : pos_num) : ↑n = num.pos n :=
by rw [← cast_to_nat, ← of_to_nat n]
@[simp, norm_cast]
theorem bit_to_nat (b n) : (bit b n : ℕ) = nat.bit b n :=
by cases b; refl
@[simp, norm_cast]
theorem cast_add [add_monoid α] [has_one α] (m n) : ((m + n : pos_num) : α) = m + n :=
by rw [← cast_to_nat, add_to_nat, nat.cast_add, cast_to_nat, cast_to_nat]
@[simp, norm_cast, priority 500]
theorem cast_succ [add_monoid α] [has_one α] (n : pos_num) : (succ n : α) = n + 1 :=
by rw [← add_one, cast_add, cast_one]
@[simp, norm_cast]
theorem cast_inj [add_monoid α] [has_one α] [char_zero α] {m n : pos_num} : (m:α) = n ↔ m = n :=
by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_inj, to_nat_inj]
@[simp]
theorem one_le_cast [linear_ordered_semiring α] (n : pos_num) : (1 : α) ≤ n :=
by rw [← cast_to_nat, ← nat.cast_one, nat.cast_le]; apply to_nat_pos
@[simp]
theorem cast_pos [linear_ordered_semiring α] (n : pos_num) : 0 < (n : α) :=
lt_of_lt_of_le zero_lt_one (one_le_cast n)
@[simp, norm_cast]
theorem cast_mul [semiring α] (m n) : ((m * n : pos_num) : α) = m * n :=
by rw [← cast_to_nat, mul_to_nat, nat.cast_mul, cast_to_nat, cast_to_nat]
@[simp]
theorem cmp_eq (m n) : cmp m n = ordering.eq ↔ m = n :=
begin
have := cmp_to_nat m n,
cases cmp m n; simp at this ⊢; try {exact this};
{ simp [show m ≠ n, from λ e, by rw e at this; exact lt_irrefl _ this] }
end
@[simp, norm_cast]
theorem cast_lt [linear_ordered_semiring α] {m n : pos_num} : (m:α) < n ↔ m < n :=
by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_lt, lt_to_nat]
@[simp, norm_cast]
theorem cast_le [linear_ordered_semiring α] {m n : pos_num} : (m:α) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr cast_lt
end pos_num
namespace num
variables {α : Type*}
open pos_num
theorem bit_to_nat (b n) : (bit b n : ℕ) = nat.bit b n :=
by cases b; cases n; refl
theorem cast_succ' [add_monoid α] [has_one α] (n) : (succ' n : α) = n + 1 :=
by rw [← pos_num.cast_to_nat, succ'_to_nat, nat.cast_add_one, cast_to_nat]
theorem cast_succ [add_monoid α] [has_one α] (n) : (succ n : α) = n + 1 := cast_succ' n
@[simp, norm_cast] theorem cast_add [semiring α] (m n) : ((m + n : num) : α) = m + n :=
by rw [← cast_to_nat, add_to_nat, nat.cast_add, cast_to_nat, cast_to_nat]
@[simp, norm_cast] theorem cast_bit0 [semiring α] (n : num) : (n.bit0 : α) = _root_.bit0 n :=
by rw [← bit0_of_bit0, _root_.bit0, cast_add]; refl
@[simp, norm_cast] theorem cast_bit1 [semiring α] (n : num) : (n.bit1 : α) = _root_.bit1 n :=
by rw [← bit1_of_bit1, _root_.bit1, bit0_of_bit0, cast_add, cast_bit0]; refl
@[simp, norm_cast] theorem cast_mul [semiring α] : ∀ m n, ((m * n : num) : α) = m * n
| 0 0 := (zero_mul _).symm
| 0 (pos q) := (zero_mul _).symm
| (pos p) 0 := (mul_zero _).symm
| (pos p) (pos q) := pos_num.cast_mul _ _
theorem size_to_nat : ∀ n, (size n : ℕ) = nat.size n
| 0 := nat.size_zero.symm
| (pos p) := p.size_to_nat
theorem size_eq_nat_size : ∀ n, (size n : ℕ) = nat_size n
| 0 := rfl
| (pos p) := p.size_eq_nat_size
theorem nat_size_to_nat (n) : nat_size n = nat.size n :=
by rw [← size_eq_nat_size, size_to_nat]
@[simp] theorem of_nat'_zero : num.of_nat' 0 = 0 :=
by simp [num.of_nat']
@[simp, priority 999] theorem of_nat'_eq : ∀ n, num.of_nat' n = n :=
nat.binary_rec (by simp) $ λ b n IH, begin
rw of_nat' at IH ⊢,
rw [nat.binary_rec_eq, IH],
{ cases b; simp [nat.bit, bit0_of_bit0, bit1_of_bit1] },
{ refl }
end
theorem zneg_to_znum (n : num) : -n.to_znum = n.to_znum_neg := by cases n; refl
theorem zneg_to_znum_neg (n : num) : -n.to_znum_neg = n.to_znum := by cases n; refl
theorem to_znum_inj {m n : num} : m.to_znum = n.to_znum ↔ m = n :=
⟨λ h, by cases m; cases n; cases h; refl, congr_arg _⟩
@[simp, norm_cast squash] theorem cast_to_znum [has_zero α] [has_one α] [has_add α] [has_neg α] :
∀ n : num, (n.to_znum : α) = n
| 0 := rfl
| (num.pos p) := rfl
@[simp] theorem cast_to_znum_neg [add_group α] [has_one α] :
∀ n : num, (n.to_znum_neg : α) = -n
| 0 := neg_zero.symm
| (num.pos p) := rfl
@[simp] theorem add_to_znum (m n : num) : num.to_znum (m + n) = m.to_znum + n.to_znum :=
by cases m; cases n; refl
end num
namespace pos_num
open num
theorem pred_to_nat {n : pos_num} (h : 1 < n) : (pred n : ℕ) = nat.pred n :=
begin
unfold pred,
have := pred'_to_nat n,
cases e : pred' n,
{ have : (1:ℕ) ≤ nat.pred n :=
nat.pred_le_pred ((@cast_lt ℕ _ _ _).2 h),
rw [← pred'_to_nat, e] at this,
exact absurd this dec_trivial },
{ rw [← pred'_to_nat, e], refl }
end
theorem sub'_one (a : pos_num) : sub' a 1 = (pred' a).to_znum :=
by cases a; refl
theorem one_sub' (a : pos_num) : sub' 1 a = (pred' a).to_znum_neg :=
by cases a; refl
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt := iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ ordering.gt :=
not_congr $ lt_iff_cmp.trans $
by rw ← cmp_swap; cases cmp m n; exact dec_trivial
end pos_num
namespace num
variables {α : Type*}
open pos_num
theorem pred_to_nat : ∀ (n : num), (pred n : ℕ) = nat.pred n
| 0 := rfl
| (pos p) := by rw [pred, pos_num.pred'_to_nat]; refl
theorem ppred_to_nat : ∀ (n : num), coe <$> ppred n = nat.ppred n
| 0 := rfl
| (pos p) := by rw [ppred, option.map_some, nat.ppred_eq_some.2];
rw [pos_num.pred'_to_nat, nat.succ_pred_eq_of_pos (pos_num.to_nat_pos _)]; refl
theorem cmp_swap (m n) : (cmp m n).swap = cmp n m :=
by cases m; cases n; try {unfold cmp}; try {refl}; apply pos_num.cmp_swap
theorem cmp_eq (m n) : cmp m n = ordering.eq ↔ m = n :=
begin
have := cmp_to_nat m n,
cases cmp m n; simp at this ⊢; try {exact this};
{ simp [show m ≠ n, from λ e, by rw e at this; exact lt_irrefl _ this] }
end
@[simp, norm_cast]
theorem cast_lt [linear_ordered_semiring α] {m n : num} : (m:α) < n ↔ m < n :=
by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_lt, lt_to_nat]
@[simp, norm_cast]
theorem cast_le [linear_ordered_semiring α] {m n : num} : (m:α) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr cast_lt
@[simp, norm_cast]
theorem cast_inj [linear_ordered_semiring α] {m n : num} : (m:α) = n ↔ m = n :=
by rw [← cast_to_nat m, ← cast_to_nat n, nat.cast_inj, to_nat_inj]
theorem lt_iff_cmp {m n} : m < n ↔ cmp m n = ordering.lt := iff.rfl
theorem le_iff_cmp {m n} : m ≤ n ↔ cmp m n ≠ ordering.gt :=
not_congr $ lt_iff_cmp.trans $
by rw ← cmp_swap; cases cmp m n; exact dec_trivial
theorem bitwise_to_nat {f : num → num → num} {g : bool → bool → bool}
(p : pos_num → pos_num → num)
(gff : g ff ff = ff)
(f00 : f 0 0 = 0)
(f0n : ∀ n, f 0 (pos n) = cond (g ff tt) (pos n) 0)
(fn0 : ∀ n, f (pos n) 0 = cond (g tt ff) (pos n) 0)
(fnn : ∀ m n, f (pos m) (pos n) = p m n)
(p11 : p 1 1 = cond (g tt tt) 1 0)
(p1b : ∀ b n, p 1 (pos_num.bit b n) = bit (g tt b) (cond (g ff tt) (pos n) 0))
(pb1 : ∀ a m, p (pos_num.bit a m) 1 = bit (g a tt) (cond (g tt ff) (pos m) 0))
(pbb : ∀ a b m n, p (pos_num.bit a m) (pos_num.bit b n) = bit (g a b) (p m n))
: ∀ m n : num, (f m n : ℕ) = nat.bitwise g m n :=
begin
intros, cases m with m; cases n with n;
try { change zero with 0 };
try { change ((0:num):ℕ) with 0 },
{ rw [f00, nat.bitwise_zero]; refl },
{ unfold nat.bitwise, rw [f0n, nat.binary_rec_zero],
cases g ff tt; refl },
{ unfold nat.bitwise,
generalize h : (pos m : ℕ) = m', revert h,
apply nat.bit_cases_on m' _, intros b m' h,
rw [fn0, nat.binary_rec_eq, nat.binary_rec_zero, ←h],
cases g tt ff; refl,
apply nat.bitwise_bit_aux gff },
{ rw fnn,
have : ∀b (n : pos_num), (cond b ↑n 0 : ℕ) = ↑(cond b (pos n) 0 : num) :=
by intros; cases b; refl,
induction m with m IH m IH generalizing n; cases n with n n,
any_goals { change one with 1 },
any_goals { change pos 1 with 1 },
any_goals { change pos_num.bit0 with pos_num.bit ff },
any_goals { change pos_num.bit1 with pos_num.bit tt },
any_goals { change ((1:num):ℕ) with nat.bit tt 0 },
all_goals
{ repeat
{ rw show ∀ b n, (pos (pos_num.bit b n) : ℕ) = nat.bit b ↑n,
by intros; cases b; refl },
rw nat.bitwise_bit },
any_goals { assumption },
any_goals { rw [nat.bitwise_zero, p11], cases g tt tt; refl },
any_goals { rw [nat.bitwise_zero_left, this, ← bit_to_nat, p1b] },
any_goals { rw [nat.bitwise_zero_right _ gff, this, ← bit_to_nat, pb1] },
all_goals { rw [← show ∀ n, ↑(p m n) = nat.bitwise g ↑m ↑n, from IH],
rw [← bit_to_nat, pbb] } }
end
@[simp, norm_cast] theorem lor_to_nat : ∀ m n, (lor m n : ℕ) = nat.lor m n :=
by apply bitwise_to_nat (λx y, pos (pos_num.lor x y)); intros; try {cases a}; try {cases b}; refl
@[simp, norm_cast] theorem land_to_nat : ∀ m n, (land m n : ℕ) = nat.land m n :=
by apply bitwise_to_nat pos_num.land; intros; try {cases a}; try {cases b}; refl
@[simp, norm_cast] theorem ldiff_to_nat : ∀ m n, (ldiff m n : ℕ) = nat.ldiff m n :=
by apply bitwise_to_nat pos_num.ldiff; intros; try {cases a}; try {cases b}; refl
@[simp, norm_cast] theorem lxor_to_nat : ∀ m n, (lxor m n : ℕ) = nat.lxor m n :=
by apply bitwise_to_nat pos_num.lxor; intros; try {cases a}; try {cases b}; refl
@[simp, norm_cast] theorem shiftl_to_nat (m n) : (shiftl m n : ℕ) = nat.shiftl m n :=
begin
cases m; dunfold shiftl, {symmetry, apply nat.zero_shiftl},
simp, induction n with n IH, {refl},
simp [pos_num.shiftl, nat.shiftl_succ], rw ←IH
end
@[simp, norm_cast] theorem shiftr_to_nat (m n) : (shiftr m n : ℕ) = nat.shiftr m n :=
begin
cases m with m; dunfold shiftr, {symmetry, apply nat.zero_shiftr},
induction n with n IH generalizing m, {cases m; refl},
cases m with m m; dunfold pos_num.shiftr,
{ rw [nat.shiftr_eq_div_pow], symmetry, apply nat.div_eq_of_lt,
exact @nat.pow_lt_pow_of_lt_right 2 dec_trivial 0 (n+1) (nat.succ_pos _) },
{ transitivity, apply IH,
change nat.shiftr m n = nat.shiftr (bit1 m) (n+1),
rw [add_comm n 1, nat.shiftr_add],
apply congr_arg (λx, nat.shiftr x n), unfold nat.shiftr,
change (bit1 ↑m : ℕ) with nat.bit tt m,
rw nat.div2_bit },
{ transitivity, apply IH,
change nat.shiftr m n = nat.shiftr (bit0 m) (n + 1),
rw [add_comm n 1, nat.shiftr_add],
apply congr_arg (λx, nat.shiftr x n), unfold nat.shiftr,
change (bit0 ↑m : ℕ) with nat.bit ff m,
rw nat.div2_bit }
end
@[simp] theorem test_bit_to_nat (m n) : test_bit m n = nat.test_bit m n :=
begin
cases m with m; unfold test_bit nat.test_bit,
{ change (zero : nat) with 0, rw nat.zero_shiftr, refl },
induction n with n IH generalizing m;
cases m; dunfold pos_num.test_bit, {refl},
{ exact (nat.bodd_bit _ _).symm },
{ exact (nat.bodd_bit _ _).symm },
{ change ff = nat.bodd (nat.shiftr 1 (n + 1)),
rw [add_comm, nat.shiftr_add], change nat.shiftr 1 1 with 0,
rw nat.zero_shiftr; refl },
{ change pos_num.test_bit m n = nat.bodd (nat.shiftr (nat.bit tt m) (n + 1)),
rw [add_comm, nat.shiftr_add], unfold nat.shiftr,
rw nat.div2_bit, apply IH },
{ change pos_num.test_bit m n = nat.bodd (nat.shiftr (nat.bit ff m) (n + 1)),
rw [add_comm, nat.shiftr_add], unfold nat.shiftr,
rw nat.div2_bit, apply IH },
end
end num
namespace znum
variables {α : Type*}
open pos_num
@[simp, norm_cast] theorem cast_zero [has_zero α] [has_one α] [has_add α] [has_neg α] :
((0 : znum) : α) = 0 := rfl
@[simp] theorem cast_zero' [has_zero α] [has_one α] [has_add α] [has_neg α] :
(znum.zero : α) = 0 := rfl
@[simp, norm_cast] theorem cast_one [has_zero α] [has_one α] [has_add α] [has_neg α] :
((1 : znum) : α) = 1 := rfl
@[simp] theorem cast_pos [has_zero α] [has_one α] [has_add α] [has_neg α]
(n : pos_num) : (pos n : α) = n := rfl
@[simp] theorem cast_neg [has_zero α] [has_one α] [has_add α] [has_neg α]
(n : pos_num) : (neg n : α) = -n := rfl
@[simp, norm_cast] theorem cast_zneg [add_group α] [has_one α] : ∀ n, ((-n : znum) : α) = -n
| 0 := neg_zero.symm
| (pos p) := rfl
| (neg p) := (neg_neg _).symm
theorem neg_zero : (-0 : znum) = 0 := rfl
theorem zneg_pos (n : pos_num) : -pos n = neg n := rfl
theorem zneg_neg (n : pos_num) : -neg n = pos n := rfl
theorem zneg_zneg (n : znum) : - -n = n := by cases n; refl
theorem zneg_bit1 (n : znum) : -n.bit1 = (-n).bitm1 := by cases n; refl
theorem zneg_bitm1 (n : znum) : -n.bitm1 = (-n).bit1 := by cases n; refl
theorem zneg_succ (n : znum) : -n.succ = (-n).pred :=
by cases n; try {refl}; rw [succ, num.zneg_to_znum_neg]; refl
theorem zneg_pred (n : znum) : -n.pred = (-n).succ :=
by rw [← zneg_zneg (succ (-n)), zneg_succ, zneg_zneg]
@[simp, norm_cast] theorem neg_of_int : ∀ n, ((-n : ℤ) : znum) = -n
| (n+1:ℕ) := rfl
| 0 := rfl
| -[1+n] := (zneg_zneg _).symm
@[simp] theorem abs_to_nat : ∀ n, (abs n : ℕ) = int.nat_abs n
| 0 := rfl
| (pos p) := congr_arg int.nat_abs p.to_nat_to_int
| (neg p) := show int.nat_abs ((p:ℕ):ℤ) = int.nat_abs (- p),
by rw [p.to_nat_to_int, int.nat_abs_neg]
@[simp] theorem abs_to_znum : ∀ n : num, abs n.to_znum = n
| 0 := rfl
| (num.pos p) := rfl
@[simp, norm_cast] theorem cast_to_int [add_group α] [has_one α] : ∀ n : znum, ((n : ℤ) : α) = n
| 0 := rfl
| (pos p) := by rw [cast_pos, cast_pos, pos_num.cast_to_int]
| (neg p) := by rw [cast_neg, cast_neg, int.cast_neg, pos_num.cast_to_int]
theorem bit0_of_bit0 : ∀ n : znum, _root_.bit0 n = n.bit0
| 0 := rfl
| (pos a) := congr_arg pos a.bit0_of_bit0
| (neg a) := congr_arg neg a.bit0_of_bit0
theorem bit1_of_bit1 : ∀ n : znum, _root_.bit1 n = n.bit1
| 0 := rfl
| (pos a) := congr_arg pos a.bit1_of_bit1
| (neg a) := show pos_num.sub' 1 (_root_.bit0 a) = _,
by rw [pos_num.one_sub', a.bit0_of_bit0]; refl
@[simp, norm_cast] theorem cast_bit0 [add_group α] [has_one α] :
∀ n : znum, (n.bit0 : α) = bit0 n
| 0 := (add_zero _).symm
| (pos p) := by rw [znum.bit0, cast_pos, cast_pos]; refl
| (neg p) := by rw [znum.bit0, cast_neg, cast_neg, pos_num.cast_bit0,
_root_.bit0, _root_.bit0, neg_add_rev]
@[simp, norm_cast] theorem cast_bit1 [add_group α] [has_one α] :
∀ n : znum, (n.bit1 : α) = bit1 n
| 0 := by simp [znum.bit1, _root_.bit1, _root_.bit0]
| (pos p) := by rw [znum.bit1, cast_pos, cast_pos]; refl
| (neg p) := begin
rw [znum.bit1, cast_neg, cast_neg],
cases e : pred' p with a;
have : p = _ := (succ'_pred' p).symm.trans
(congr_arg num.succ' e),
{ change p=1 at this, subst p,
simp [_root_.bit1, _root_.bit0] },
{ rw [num.succ'] at this, subst p,
have : (↑(-↑a:ℤ) : α) = -1 + ↑(-↑a + 1 : ℤ), {simp [add_comm]},
simpa [_root_.bit1, _root_.bit0, -add_comm] },
end
@[simp] theorem cast_bitm1 [add_group α] [has_one α]
(n : znum) : (n.bitm1 : α) = bit0 n - 1 :=
begin
conv { to_lhs, rw ← zneg_zneg n },
rw [← zneg_bit1, cast_zneg, cast_bit1],
have : ((-1 + n + n : ℤ) : α) = (n + n + -1 : ℤ), {simp [add_comm, add_left_comm]},
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg, -int.add_neg_one]
end
theorem add_zero (n : znum) : n + 0 = n := by cases n; refl
theorem zero_add (n : znum) : 0 + n = n := by cases n; refl
theorem add_one : ∀ n : znum, n + 1 = succ n
| 0 := rfl
| (pos p) := congr_arg pos p.add_one
| (neg p) := by cases p; refl
end znum
namespace pos_num
variables {α : Type*}
theorem cast_to_znum : ∀ n : pos_num, (n : znum) = znum.pos n
| 1 := rfl
| (bit0 p) := (znum.bit0_of_bit0 p).trans $ congr_arg _ (cast_to_znum p)
| (bit1 p) := (znum.bit1_of_bit1 p).trans $ congr_arg _ (cast_to_znum p)
local attribute [-simp] int.add_neg_one
theorem cast_sub' [add_group α] [has_one α] : ∀ m n : pos_num, (sub' m n : α) = m - n
| a 1 := by rw [sub'_one, num.cast_to_znum,
← num.cast_to_nat, pred'_to_nat, ← nat.sub_one];
simp [pos_num.cast_pos]
| 1 b := by rw [one_sub', num.cast_to_znum_neg, ← neg_sub, neg_inj,
← num.cast_to_nat, pred'_to_nat, ← nat.sub_one];
simp [pos_num.cast_pos]
| (bit0 a) (bit0 b) := begin
rw [sub', znum.cast_bit0, cast_sub'],
have : ((a + -b + (a + -b) : ℤ) : α) = a + a + (-b + -b), {simp [add_left_comm]},
simpa [_root_.bit0, sub_eq_add_neg]
end
| (bit0 a) (bit1 b) := begin
rw [sub', znum.cast_bitm1, cast_sub'],
have : ((-b + (a + (-b + -1)) : ℤ) : α) = (a + -1 + (-b + -b):ℤ),
{ simp [add_comm, add_left_comm] },
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg]
end
| (bit1 a) (bit0 b) := begin
rw [sub', znum.cast_bit1, cast_sub'],
have : ((-b + (a + (-b + 1)) : ℤ) : α) = (a + 1 + (-b + -b):ℤ),
{ simp [add_comm, add_left_comm] },
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg]
end
| (bit1 a) (bit1 b) := begin
rw [sub', znum.cast_bit0, cast_sub'],
have : ((-b + (a + -b) : ℤ) : α) = a + (-b + -b), {simp [add_left_comm]},
simpa [_root_.bit1, _root_.bit0, sub_eq_add_neg]
end
theorem to_nat_eq_succ_pred (n : pos_num) : (n:ℕ) = n.pred' + 1 :=
by rw [← num.succ'_to_nat, n.succ'_pred']
theorem to_int_eq_succ_pred (n : pos_num) : (n:ℤ) = (n.pred' : ℕ) + 1 :=
by rw [← n.to_nat_to_int, to_nat_eq_succ_pred]; refl
end pos_num
namespace num
variables {α : Type*}
@[simp] theorem cast_sub' [add_group α] [has_one α] : ∀ m n : num, (sub' m n : α) = m - n
| 0 0 := (sub_zero _).symm
| (pos a) 0 := (sub_zero _).symm
| 0 (pos b) := (zero_sub _).symm
| (pos a) (pos b) := pos_num.cast_sub' _ _
@[simp] theorem of_nat_to_znum : ∀ n : ℕ, to_znum n = n
| 0 := rfl
| (n+1) := by rw [nat.cast_add_one, nat.cast_add_one,
znum.add_one, add_one, ← of_nat_to_znum]; cases (n:num); refl
@[simp] theorem of_nat_to_znum_neg (n : ℕ) : to_znum_neg n = -n :=
by rw [← of_nat_to_znum, zneg_to_znum]
theorem mem_of_znum' : ∀ {m : num} {n : znum}, m ∈ of_znum' n ↔ n = to_znum m
| 0 0 := ⟨λ _, rfl, λ _, rfl⟩
| (pos m) 0 := ⟨λ h, by cases h, λ h, by cases h⟩
| m (znum.pos p) := option.some_inj.trans $
by cases m; split; intro h; try {cases h}; refl
| m (znum.neg p) := ⟨λ h, by cases h, λ h, by cases m; cases h⟩
theorem of_znum'_to_nat : ∀ (n : znum), coe <$> of_znum' n = int.to_nat' n
| 0 := rfl
| (znum.pos p) := show _ = int.to_nat' p, by rw [← pos_num.to_nat_to_int p]; refl
| (znum.neg p) := congr_arg (λ x, int.to_nat' (-x)) $
show ((p.pred' + 1 : ℕ) : ℤ) = p, by rw ← succ'_to_nat; simp
@[simp] theorem of_znum_to_nat : ∀ (n : znum), (of_znum n : ℕ) = int.to_nat n
| 0 := rfl
| (znum.pos p) := show _ = int.to_nat p, by rw [← pos_num.to_nat_to_int p]; refl
| (znum.neg p) := congr_arg (λ x, int.to_nat (-x)) $
show ((p.pred' + 1 : ℕ) : ℤ) = p, by rw ← succ'_to_nat; simp
@[simp] theorem cast_of_znum [add_group α] [has_one α] (n : znum) :
(of_znum n : α) = int.to_nat n :=
by rw [← cast_to_nat, of_znum_to_nat]
@[simp, norm_cast] theorem sub_to_nat (m n) : ((m - n : num) : ℕ) = m - n :=
show (of_znum _ : ℕ) = _, by rw [of_znum_to_nat, cast_sub',
← to_nat_to_int, ← to_nat_to_int, int.to_nat_sub]
end num
namespace znum
variables {α : Type*}
@[simp, norm_cast] theorem cast_add [add_group α] [has_one α] : ∀ m n, ((m + n : znum) : α) = m + n
| 0 a := by cases a; exact (_root_.zero_add _).symm
| b 0 := by cases b; exact (_root_.add_zero _).symm
| (pos a) (pos b) := pos_num.cast_add _ _
| (pos a) (neg b) := by simpa only [sub_eq_add_neg] using pos_num.cast_sub' _ _
| (neg a) (pos b) :=
have (↑b + -↑a : α) = -↑a + ↑b, by rw [← pos_num.cast_to_int a, ← pos_num.cast_to_int b,
← int.cast_neg, ← int.cast_add (-a)]; simp [add_comm],
(pos_num.cast_sub' _ _).trans $ (sub_eq_add_neg _ _).trans this
| (neg a) (neg b) := show -(↑(a + b) : α) = -a + -b, by rw [
pos_num.cast_add, neg_eq_iff_neg_eq, neg_add_rev, neg_neg, neg_neg,
← pos_num.cast_to_int a, ← pos_num.cast_to_int b, ← int.cast_add]; simp [add_comm]
@[simp] theorem cast_succ [add_group α] [has_one α] (n) : ((succ n : znum) : α) = n + 1 :=
by rw [← add_one, cast_add, cast_one]
@[simp, norm_cast] theorem mul_to_int : ∀ m n, ((m * n : znum) : ℤ) = m * n
| 0 a := by cases a; exact (_root_.zero_mul _).symm
| b 0 := by cases b; exact (_root_.mul_zero _).symm
| (pos a) (pos b) := pos_num.cast_mul a b
| (pos a) (neg b) := show -↑(a * b) = ↑a * -↑b, by rw [pos_num.cast_mul, neg_mul_eq_mul_neg]
| (neg a) (pos b) := show -↑(a * b) = -↑a * ↑b, by rw [pos_num.cast_mul, neg_mul_eq_neg_mul]
| (neg a) (neg b) := show ↑(a * b) = -↑a * -↑b, by rw [pos_num.cast_mul, neg_mul_neg]
theorem cast_mul [ring α] (m n) : ((m * n : znum) : α) = m * n :=
by rw [← cast_to_int, mul_to_int, int.cast_mul, cast_to_int, cast_to_int]
@[simp, norm_cast] theorem of_to_int : Π (n : znum), ((n : ℤ) : znum) = n
| 0 := rfl
| (pos a) := by rw [cast_pos, ← pos_num.cast_to_nat,
int.cast_coe_nat', ← num.of_nat_to_znum, pos_num.of_to_nat]; refl
| (neg a) := by rw [cast_neg, neg_of_int, ← pos_num.cast_to_nat,
int.cast_coe_nat', ← num.of_nat_to_znum_neg, pos_num.of_to_nat]; refl
@[norm_cast]
theorem to_of_int : Π (n : ℤ), ((n : znum) : ℤ) = n
| (n : ℕ) := by rw [int.cast_coe_nat,
← num.of_nat_to_znum, num.cast_to_znum, ← num.cast_to_nat,
int.nat_cast_eq_coe_nat, num.to_of_nat]
| -[1+ n] := by rw [int.cast_neg_succ_of_nat, cast_zneg,
add_one, cast_succ, int.neg_succ_of_nat_eq,
← num.of_nat_to_znum, num.cast_to_znum, ← num.cast_to_nat,
int.nat_cast_eq_coe_nat, num.to_of_nat]
theorem to_int_inj {m n : znum} : (m : ℤ) = n ↔ m = n :=
⟨λ h, function.left_inverse.injective of_to_int h, congr_arg _⟩
@[simp, norm_cast] theorem of_int_cast [add_group α] [has_one α] (n : ℤ) : ((n : znum) : α) = n :=
by rw [← cast_to_int, to_of_int]
@[simp, norm_cast] theorem of_nat_cast [add_group α] [has_one α] (n : ℕ) : ((n : znum) : α) = n :=
of_int_cast n
@[simp] theorem of_int'_eq : ∀ n, znum.of_int' n = n
| (n : ℕ) := to_int_inj.1 $ by simp [znum.of_int']
| -[1+ n] := to_int_inj.1 $ by simp [znum.of_int']
theorem cmp_to_int : ∀ (m n), (ordering.cases_on (cmp m n) ((m:ℤ) < n) (m = n) ((n:ℤ) < m) : Prop)
| 0 0 := rfl
| (pos a) (pos b) := begin
have := pos_num.cmp_to_nat a b; revert this; dsimp [cmp];
cases pos_num.cmp a b; dsimp;
[simp, exact congr_arg pos, simp [gt]]
end
| (neg a) (neg b) := begin
have := pos_num.cmp_to_nat b a; revert this; dsimp [cmp];
cases pos_num.cmp b a; dsimp;
[simp, simp {contextual := tt}, simp [gt]]
end
| (pos a) 0 := pos_num.cast_pos _
| (pos a) (neg b) := lt_trans (neg_lt_zero.2 $ pos_num.cast_pos _) (pos_num.cast_pos _)
| 0 (neg b) := neg_lt_zero.2 $ pos_num.cast_pos _
| (neg a) 0 := neg_lt_zero.2 $ pos_num.cast_pos _
| (neg a) (pos b) := lt_trans (neg_lt_zero.2 $ pos_num.cast_pos _) (pos_num.cast_pos _)
| 0 (pos b) := pos_num.cast_pos _
@[norm_cast]
theorem lt_to_int {m n : znum} : (m:ℤ) < n ↔ m < n :=
show (m:ℤ) < n ↔ cmp m n = ordering.lt, from
match cmp m n, cmp_to_int m n with
| ordering.lt, h := by simp at h; simp [h]
| ordering.eq, h := by simp at h; simp [h, lt_irrefl]; exact dec_trivial
| ordering.gt, h := by simp [not_lt_of_gt h]; exact dec_trivial
end
theorem le_to_int {m n : znum} : (m:ℤ) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr lt_to_int
@[simp, norm_cast]
theorem cast_lt [linear_ordered_ring α] {m n : znum} : (m:α) < n ↔ m < n :=
by rw [← cast_to_int m, ← cast_to_int n, int.cast_lt, lt_to_int]
@[simp, norm_cast]
theorem cast_le [linear_ordered_ring α] {m n : znum} : (m:α) ≤ n ↔ m ≤ n :=
by rw ← not_lt; exact not_congr cast_lt
@[simp, norm_cast]
theorem cast_inj [linear_ordered_ring α] {m n : znum} : (m:α) = n ↔ m = n :=
by rw [← cast_to_int m, ← cast_to_int n, int.cast_inj, to_int_inj]
/--
This tactic tries to turn an (in)equality about `znum`s to one about `int`s by rewriting.
```lean
example (n : znum) (m : znum) : n ≤ n + m * m :=
begin
znum.transfer_rw,
exact le_add_of_nonneg_right (mul_self_nonneg _)
end
```
-/
meta def transfer_rw : tactic unit :=
`[repeat {rw ← to_int_inj <|> rw ← lt_to_int <|> rw ← le_to_int},
repeat {rw cast_add <|> rw mul_to_int <|> rw cast_one <|> rw cast_zero}]
/--
This tactic tries to prove (in)equalities about `znum`s by transfering them to the `int` world and
then trying to call `simp`.
```lean
example (n : znum) (m : znum) : n ≤ n + m * m :=
begin
znum.transfer,
exact mul_self_nonneg _
end
```
-/
meta def transfer : tactic unit :=
`[intros, transfer_rw, try {simp [add_comm, add_left_comm, mul_comm, mul_left_comm]}]
instance : linear_order znum :=
{ lt := (<),
lt_iff_le_not_le := by {intros a b, transfer_rw, apply lt_iff_le_not_le},
le := (≤),
le_refl := by transfer,
le_trans := by {intros a b c, transfer_rw, apply le_trans},
le_antisymm := by {intros a b, transfer_rw, apply le_antisymm},
le_total := by {intros a b, transfer_rw, apply le_total},
decidable_eq := znum.decidable_eq,
decidable_le := znum.decidable_le,
decidable_lt := znum.decidable_lt }
instance : add_comm_group znum :=
{ add := (+),
add_assoc := by transfer,
zero := 0,
zero_add := zero_add,
add_zero := add_zero,
add_comm := by transfer,
neg := has_neg.neg,
add_left_neg := by transfer }
instance : linear_ordered_comm_ring znum :=
{ mul := (*),
mul_assoc := by transfer,
one := 1,
one_mul := by transfer,
mul_one := by transfer,
left_distrib := by {transfer, simp [mul_add]},
right_distrib := by {transfer, simp [mul_add, mul_comm]},
mul_comm := by transfer,
exists_pair_ne := ⟨0, 1, dec_trivial⟩,
add_le_add_left := by {intros a b h c, revert h, transfer_rw, exact λ h, add_le_add_left h c},
mul_pos := λ a b, show 0 < a → 0 < b → 0 < a * b, by {transfer_rw, apply mul_pos},
zero_le_one := dec_trivial,
..znum.linear_order, ..znum.add_comm_group }
@[simp, norm_cast] theorem dvd_to_int (m n : znum) : (m : ℤ) ∣ n ↔ m ∣ n :=
⟨λ ⟨k, e⟩, ⟨k, by rw [← of_to_int n, e]; simp⟩,
λ ⟨k, e⟩, ⟨k, by simp [e]⟩⟩
end znum
namespace pos_num
theorem divmod_to_nat_aux {n d : pos_num} {q r : num}
(h₁ : (r:ℕ) + d * _root_.bit0 q = n)
(h₂ : (r:ℕ) < 2 * d) :
((divmod_aux d q r).2 + d * (divmod_aux d q r).1 : ℕ) = ↑n ∧
((divmod_aux d q r).2 : ℕ) < d :=
begin
unfold divmod_aux,
have : ∀ {r₂}, num.of_znum' (num.sub' r (num.pos d)) = some r₂ ↔ (r : ℕ) = r₂ + d,
{ intro r₂,
apply num.mem_of_znum'.trans,
rw [← znum.to_int_inj, num.cast_to_znum,
num.cast_sub', sub_eq_iff_eq_add, ← int.coe_nat_inj'],
simp },
cases e : num.of_znum' (num.sub' r (num.pos d)) with r₂;
simp [divmod_aux],
{ refine ⟨h₁, lt_of_not_ge (λ h, _)⟩,
cases nat.le.dest h with r₂ e',
rw [← num.to_of_nat r₂, add_comm] at e',
cases e.symm.trans (this.2 e'.symm) },
{ have := this.1 e,
split,
{ rwa [_root_.bit1, add_comm _ 1, mul_add, mul_one,
← add_assoc, ← this] },
{ rwa [this, two_mul, add_lt_add_iff_right] at h₂ } }
end
theorem divmod_to_nat (d n : pos_num) :
(n / d : ℕ) = (divmod d n).1 ∧
(n % d : ℕ) = (divmod d n).2 :=
begin
rw nat.div_mod_unique (pos_num.cast_pos _),
induction n with n IH n IH,
{ exact divmod_to_nat_aux (by simp; refl)
(nat.mul_le_mul_left 2
(pos_num.cast_pos d : (0 : ℕ) < d)) },
{ unfold divmod,
cases divmod d n with q r, simp only [divmod] at IH ⊢,
apply divmod_to_nat_aux; simp,
{ rw [_root_.bit1, _root_.bit1, add_right_comm,
bit0_eq_two_mul ↑n, ← IH.1,
mul_add, ← bit0_eq_two_mul,
mul_left_comm, ← bit0_eq_two_mul] },
{ rw ← bit0_eq_two_mul,
exact nat.bit1_lt_bit0 IH.2 } },
{ unfold divmod,
cases divmod d n with q r, simp only [divmod] at IH ⊢,
apply divmod_to_nat_aux; simp,
{ rw [bit0_eq_two_mul ↑n, ← IH.1,
mul_add, ← bit0_eq_two_mul,
mul_left_comm, ← bit0_eq_two_mul] },
{ rw ← bit0_eq_two_mul,
exact nat.bit0_lt IH.2 } }
end
@[simp] theorem div'_to_nat (n d) : (div' n d : ℕ) = n / d :=
(divmod_to_nat _ _).1.symm
@[simp] theorem mod'_to_nat (n d) : (mod' n d : ℕ) = n % d :=
(divmod_to_nat _ _).2.symm
end pos_num
namespace num
@[simp] protected lemma div_zero (n : num) : n / 0 = 0 :=
show n.div 0 = 0, by { cases n, refl, simp [num.div] }
@[simp, norm_cast] theorem div_to_nat : ∀ n d, ((n / d : num) : ℕ) = n / d
| 0 0 := by simp
| 0 (pos d) := (nat.zero_div _).symm
| (pos n) 0 := (nat.div_zero _).symm
| (pos n) (pos d) := pos_num.div'_to_nat _ _
@[simp] protected lemma mod_zero (n : num) : n % 0 = n :=
show n.mod 0 = n, by { cases n, refl, simp [num.mod] }
@[simp, norm_cast] theorem mod_to_nat : ∀ n d, ((n % d : num) : ℕ) = n % d
| 0 0 := by simp
| 0 (pos d) := (nat.zero_mod _).symm
| (pos n) 0 := (nat.mod_zero _).symm
| (pos n) (pos d) := pos_num.mod'_to_nat _ _
theorem gcd_to_nat_aux : ∀ {n} {a b : num},
a ≤ b → (a * b).nat_size ≤ n → (gcd_aux n a b : ℕ) = nat.gcd a b
| 0 0 b ab h := (nat.gcd_zero_left _).symm
| 0 (pos a) 0 ab h := (not_lt_of_ge ab).elim rfl
| 0 (pos a) (pos b) ab h :=
(not_lt_of_le h).elim $ pos_num.nat_size_pos _
| (nat.succ n) 0 b ab h := (nat.gcd_zero_left _).symm
| (nat.succ n) (pos a) b ab h := begin
simp [gcd_aux],
rw [nat.gcd_rec, gcd_to_nat_aux, mod_to_nat], {refl},
{ rw [← le_to_nat, mod_to_nat],
exact le_of_lt (nat.mod_lt _ (pos_num.cast_pos _)) },
rw [nat_size_to_nat, mul_to_nat, nat.size_le] at h ⊢,
rw [mod_to_nat, mul_comm],
rw [pow_succ', ← nat.mod_add_div b (pos a)] at h,
refine lt_of_mul_lt_mul_right (lt_of_le_of_lt _ h) (nat.zero_le 2),
rw [mul_two, mul_add],
refine add_le_add_left (nat.mul_le_mul_left _
(le_trans (le_of_lt (nat.mod_lt _ (pos_num.cast_pos _))) _)) _,
suffices : 1 ≤ _, simpa using nat.mul_le_mul_left (pos a) this,
rw [nat.le_div_iff_mul_le _ _ a.cast_pos, one_mul],
exact le_to_nat.2 ab
end
@[simp] theorem gcd_to_nat : ∀ a b, (gcd a b : ℕ) = nat.gcd a b :=
have ∀ a b : num, (a * b).nat_size ≤ a.nat_size + b.nat_size,
begin
intros,
simp [nat_size_to_nat],
rw [nat.size_le, pow_add],
exact mul_lt_mul'' (nat.lt_size_self _)
(nat.lt_size_self _) (nat.zero_le _) (nat.zero_le _)
end,
begin
intros, unfold gcd, split_ifs,
{ exact gcd_to_nat_aux h (this _ _) },
{ rw nat.gcd_comm,
exact gcd_to_nat_aux (le_of_not_le h) (this _ _) }
end
theorem dvd_iff_mod_eq_zero {m n : num} : m ∣ n ↔ n % m = 0 :=
by rw [← dvd_to_nat, nat.dvd_iff_mod_eq_zero,
← to_nat_inj, mod_to_nat]; refl
instance decidable_dvd : decidable_rel ((∣) : num → num → Prop)
| a b := decidable_of_iff' _ dvd_iff_mod_eq_zero
end num
instance pos_num.decidable_dvd : decidable_rel ((∣) : pos_num → pos_num → Prop)
| a b := num.decidable_dvd _ _
namespace znum
@[simp] protected lemma div_zero (n : znum) : n / 0 = 0 :=
show n.div 0 = 0, by cases n; refl <|> simp [znum.div]
@[simp, norm_cast] theorem div_to_int : ∀ n d, ((n / d : znum) : ℤ) = n / d
| 0 0 := by simp [int.div_zero]
| 0 (pos d) := (int.zero_div _).symm
| 0 (neg d) := (int.zero_div _).symm
| (pos n) 0 := (int.div_zero _).symm
| (neg n) 0 := (int.div_zero _).symm
| (pos n) (pos d) := (num.cast_to_znum _).trans $
by rw ← num.to_nat_to_int; simp
| (pos n) (neg d) := (num.cast_to_znum_neg _).trans $
by rw ← num.to_nat_to_int; simp
| (neg n) (pos d) := show - _ = (-_/↑d), begin
rw [n.to_int_eq_succ_pred, d.to_int_eq_succ_pred,
← pos_num.to_nat_to_int, num.succ'_to_nat,
num.div_to_nat],
change -[1+ n.pred' / ↑d] = -[1+ n.pred' / (d.pred' + 1)],
rw d.to_nat_eq_succ_pred
end
| (neg n) (neg d) := show ↑(pos_num.pred' n / num.pos d).succ' = (-_ / -↑d), begin
rw [n.to_int_eq_succ_pred, d.to_int_eq_succ_pred,
← pos_num.to_nat_to_int, num.succ'_to_nat,
num.div_to_nat],
change (nat.succ (_/d) : ℤ) = nat.succ (n.pred'/(d.pred' + 1)),
rw d.to_nat_eq_succ_pred
end
@[simp, norm_cast] theorem mod_to_int : ∀ n d, ((n % d : znum) : ℤ) = n % d
| 0 d := (int.zero_mod _).symm
| (pos n) d := (num.cast_to_znum _).trans $
by rw [← num.to_nat_to_int, cast_pos, num.mod_to_nat,
← pos_num.to_nat_to_int, abs_to_nat]; refl
| (neg n) d := (num.cast_sub' _ _).trans $
by rw [← num.to_nat_to_int, cast_neg, ← num.to_nat_to_int,
num.succ_to_nat, num.mod_to_nat, abs_to_nat,
← int.sub_nat_nat_eq_coe, n.to_int_eq_succ_pred]; refl
@[simp] theorem gcd_to_nat (a b) : (gcd a b : ℕ) = int.gcd a b :=
(num.gcd_to_nat _ _).trans $ by simpa
theorem dvd_iff_mod_eq_zero {m n : znum} : m ∣ n ↔ n % m = 0 :=
by rw [← dvd_to_int, int.dvd_iff_mod_eq_zero,
← to_int_inj, mod_to_int]; refl
instance : decidable_rel ((∣) : znum → znum → Prop)
| a b := decidable_of_iff' _ dvd_iff_mod_eq_zero
end znum
namespace int
/-- Cast a `snum` to the corresponding integer. -/
def of_snum : snum → ℤ :=
snum.rec' (λ a, cond a (-1) 0) (λa p IH, cond a (bit1 IH) (bit0 IH))
instance snum_coe : has_coe snum ℤ := ⟨of_snum⟩
end int
instance : has_lt snum := ⟨λa b, (a : ℤ) < b⟩
instance : has_le snum := ⟨λa b, (a : ℤ) ≤ b⟩
|
3b3dca7cbf3fe3f8b2a92a9dadfc955d34375787 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/order/category/PartialOrder.lean | 604159d46c0b35a4a0715ac99daae8a4b67efefe | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 816 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import order.category.Preorder
/-! # Category of partially ordered types -/
open category_theory
/-- The category of partially ordered types. -/
def PartialOrder := bundled partial_order
namespace PartialOrder
instance : bundled_hom.parent_projection @partial_order.to_preorder := ⟨⟩
attribute [derive [has_coe_to_sort, large_category, concrete_category]] PartialOrder
/-- Construct a bundled PartialOrder from the underlying type and typeclass. -/
def of (α : Type*) [partial_order α] : PartialOrder := bundled.of α
instance : inhabited PartialOrder := ⟨of punit⟩
instance (α : PartialOrder) : partial_order α := α.str
end PartialOrder
|
7e014e7292c1e714f234578e4104667fc9b36a98 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/sums/associator.lean | 4905f7c7ebe7eadf689440821a9e4ae06c1703c6 | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 3,491 | 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 category_theory.sums.basic
/-!
# Associator for binary disjoint union of categories.
The associator functor `((C ⊕ D) ⊕ E) ⥤ (C ⊕ (D ⊕ E))` and its inverse form an equivalence.
-/
universes v u
open category_theory
open sum
namespace category_theory.sum
variables (C : Type u) [category.{v} C]
(D : Type u) [category.{v} D]
(E : Type u) [category.{v} E]
/--
The associator functor `(C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E)` for sums of categories.
-/
def associator : (C ⊕ D) ⊕ E ⥤ C ⊕ (D ⊕ E) :=
{ obj := λ X, match X with
| inl (inl X) := inl X
| inl (inr X) := inr (inl X)
| inr X := inr (inr X)
end,
map := λ X Y f, match X, Y, f with
| inl (inl X), inl (inl Y), f := f
| inl (inr X), inl (inr Y), f := f
| inr X, inr Y, f := f
end }
@[simp] lemma associator_obj_inl_inl (X) : (associator C D E).obj (inl (inl X)) = inl X := rfl
@[simp] lemma associator_obj_inl_inr (X) : (associator C D E).obj (inl (inr X)) = inr (inl X) := rfl
@[simp] lemma associator_obj_inr (X) : (associator C D E).obj (inr X) = inr (inr X) := rfl
@[simp] lemma associator_map_inl_inl {X Y : C} (f : inl (inl X) ⟶ inl (inl Y)) :
(associator C D E).map f = f := rfl
@[simp] lemma associator_map_inl_inr {X Y : D} (f : inl (inr X) ⟶ inl (inr Y)) :
(associator C D E).map f = f := rfl
@[simp] lemma associator_map_inr {X Y : E} (f : inr X ⟶ inr Y) :
(associator C D E).map f = f := rfl
/--
The inverse associator functor `C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E` for sums of categories.
-/
def inverse_associator : C ⊕ (D ⊕ E) ⥤ (C ⊕ D) ⊕ E :=
{ obj := λ X, match X with
| inl X := inl (inl X)
| inr (inl X) := inl (inr X)
| inr (inr X) := inr X
end,
map := λ X Y f, match X, Y, f with
| inl X, inl Y, f := f
| inr (inl X), inr (inl Y), f := f
| inr (inr X), inr (inr Y), f := f
end }
@[simp] lemma inverse_associator_obj_inl (X) :
(inverse_associator C D E).obj (inl X) = inl (inl X) := rfl
@[simp] lemma inverse_associator_obj_inr_inl (X) :
(inverse_associator C D E).obj (inr (inl X)) = inl (inr X) := rfl
@[simp] lemma inverse_associator_obj_inr_inr (X) :
(inverse_associator C D E).obj (inr (inr X)) = inr X := rfl
@[simp] lemma inverse_associator_map_inl {X Y : C} (f : inl X ⟶ inl Y) :
(inverse_associator C D E).map f = f := rfl
@[simp] lemma inverse_associator_map_inr_inl {X Y : D} (f : inr (inl X) ⟶ inr (inl Y)) :
(inverse_associator C D E).map f = f := rfl
@[simp] lemma inverse_associator_map_inr_inr {X Y : E} (f : inr (inr X) ⟶ inr (inr Y)) :
(inverse_associator C D E).map f = f := rfl
/--
The equivalence of categories expressing associativity of sums of categories.
-/
def associativity : (C ⊕ D) ⊕ E ≌ C ⊕ (D ⊕ E) :=
equivalence.mk (associator C D E) (inverse_associator C D E)
(nat_iso.of_components (λ X, eq_to_iso (by tidy)) (by tidy))
(nat_iso.of_components (λ X, eq_to_iso (by tidy)) (by tidy))
instance associator_is_equivalence : is_equivalence (associator C D E) :=
(by apply_instance : is_equivalence (associativity C D E).functor)
instance inverse_associator_is_equivalence : is_equivalence (inverse_associator C D E) :=
(by apply_instance : is_equivalence (associativity C D E).inverse)
-- TODO unitors?
-- TODO pentagon natural transformation? ...satisfying?
end category_theory.sum
|
49ebfe27a6b02a06834501617ac38c8dda51d515 | 7cef822f3b952965621309e88eadf618da0c8ae9 | /src/number_theory/pell.lean | 3441f5f9f243185f2e6c926cb96cfc848b3e138e | [
"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 | 37,061 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.nat.modeq data.zsqrtd.basic tactic.ring
namespace pell
open nat
section
parameters {a : ℕ} (a1 : a > 1)
include a1
private def d := a*a - 1
@[simp] theorem d_pos : 0 < d := nat.sub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a)
/-- The Pell sequences, defined together in mutual recursion. -/
-- TODO(lint): Fix double namespace issue
@[nolint] def pell : ℕ → ℕ × ℕ :=
λn, nat.rec_on n (1, 0) (λn xy, (xy.1*a + d*xy.2, xy.1 + xy.2*a))
/-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ := (pell n).1
/-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ := (pell n).2
@[simp] theorem pell_val (n : ℕ) : pell n = (xn n, yn n) :=
show pell n = ((pell n).1, (pell n).2), from match pell n with (a, b) := rfl end
@[simp] theorem xn_zero : xn 0 = 1 := rfl
@[simp] theorem yn_zero : yn 0 = 0 := rfl
@[simp] theorem xn_succ (n : ℕ) : xn (n+1) = xn n * a + d * yn n := rfl
@[simp] theorem yn_succ (n : ℕ) : yn (n+1) = xn n + yn n * a := rfl
@[simp] theorem xn_one : xn 1 = a := by simp
@[simp] theorem yn_one : yn 1 = 1 := by simp
def xz (n : ℕ) : ℤ := xn n
def yz (n : ℕ) : ℤ := yn n
def az : ℤ := a
theorem asq_pos : 0 < a*a :=
le_trans (le_of_lt a1) (by have := @nat.mul_le_mul_left 1 a a (le_of_lt a1); rwa mul_one at this)
theorem dz_val : ↑d = az*az - 1 :=
have 1 ≤ a*a, from asq_pos,
show ↑(a*a - 1) = _, by rw int.coe_nat_sub this; refl
@[simp] theorem xz_succ (n : ℕ) : xz (n+1) = xz n * az + ↑d * yz n := rfl
@[simp] theorem yz_succ (n : ℕ) : yz (n+1) = xz n + yz n * az := rfl
/-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pell_zd (n : ℕ) : ℤ√d := ⟨xn n, yn n⟩
@[simp] theorem pell_zd_re (n : ℕ) : (pell_zd n).re = xn n := rfl
@[simp] theorem pell_zd_im (n : ℕ) : (pell_zd n).im = yn n := rfl
/-- The property of being a solution to the Pell equation, expressed
as a property of elements of `ℤ√d`. -/
def is_pell : ℤ√d → Prop | ⟨x, y⟩ := x*x - d*y*y = 1
theorem is_pell_nat {x y : ℕ} : is_pell ⟨x, y⟩ ↔ x*x - d*y*y = 1 :=
⟨λh, int.coe_nat_inj (by rw int.coe_nat_sub (int.le_of_coe_nat_le_coe_nat $ int.le.intro_sub h); exact h),
λh, show ((x*x : ℕ) - (d*y*y:ℕ) : ℤ) = 1, by rw [← int.coe_nat_sub $ le_of_lt $ nat.lt_of_sub_eq_succ h, h]; refl⟩
theorem is_pell_norm : Π {b : ℤ√d}, is_pell b ↔ b * b.conj = 1
| ⟨x, y⟩ := by simp [zsqrtd.ext, is_pell, mul_comm]
theorem is_pell_mul {b c : ℤ√d} (hb : is_pell b) (hc : is_pell c) : is_pell (b * c) :=
is_pell_norm.2 (by simp [mul_comm, mul_left_comm,
zsqrtd.conj_mul, pell.is_pell_norm.1 hb, pell.is_pell_norm.1 hc])
theorem is_pell_conj : ∀ {b : ℤ√d}, is_pell b ↔ is_pell b.conj | ⟨x, y⟩ :=
by simp [is_pell, zsqrtd.conj]
@[simp] theorem pell_zd_succ (n : ℕ) : pell_zd (n+1) = pell_zd n * ⟨a, 1⟩ :=
by simp [zsqrtd.ext]
theorem is_pell_one : is_pell ⟨a, 1⟩ :=
show az*az-d*1*1=1, by simp [dz_val]
theorem is_pell_pell_zd : ∀ (n : ℕ), is_pell (pell_zd n)
| 0 := rfl
| (n+1) := let o := is_pell_one in by simp; exact pell.is_pell_mul (is_pell_pell_zd n) o
@[simp] theorem pell_eqz (n : ℕ) : xz n * xz n - d * yz n * yz n = 1 := is_pell_pell_zd n
@[simp] theorem pell_eq (n : ℕ) : xn n * xn n - d * yn n * yn n = 1 :=
let pn := pell_eqz n in
have h : (↑(xn n * xn n) : ℤ) - ↑(d * yn n * yn n) = 1,
by repeat {rw int.coe_nat_mul}; exact pn,
have hl : d * yn n * yn n ≤ xn n * xn n, from
int.le_of_coe_nat_le_coe_nat $ int.le.intro $ add_eq_of_eq_sub' $ eq.symm h,
int.coe_nat_inj (by rw int.coe_nat_sub hl; exact h)
instance dnsq : zsqrtd.nonsquare d := ⟨λn h,
have n*n + 1 = a*a, by rw ← h; exact nat.succ_pred_eq_of_pos (asq_pos a1),
have na : n < a, from nat.mul_self_lt_mul_self_iff.2 (by rw ← this; exact nat.lt_succ_self _),
have (n+1)*(n+1) ≤ n*n + 1, by rw this; exact nat.mul_self_le_mul_self na,
have n+n ≤ 0, from @nat.le_of_add_le_add_right (n*n + 1) _ _ (by simpa [mul_add, mul_comm, mul_left_comm]),
ne_of_gt d_pos $ by rw nat.eq_zero_of_le_zero (le_trans (nat.le_add_left _ _) this) at h; exact h⟩
theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n
| 0 := le_refl 1
| (n+1) := by simp [nat.pow_succ]; exact le_trans
(nat.mul_le_mul_right _ (xn_ge_a_pow n)) (nat.le_add_right _ _)
theorem n_lt_a_pow : ∀ (n : ℕ), n < a^n
| 0 := nat.le_refl 1
| (n+1) := begin have IH := n_lt_a_pow n,
have : a^n + a^n ≤ a^n * a,
{ rw ← mul_two, exact nat.mul_le_mul_left _ a1 },
simp [nat.pow_succ], refine lt_of_lt_of_le _ this,
exact add_lt_add_of_lt_of_le IH (lt_of_le_of_lt (nat.zero_le _) IH)
end
theorem n_lt_xn (n) : n < xn n :=
lt_of_lt_of_le (n_lt_a_pow n) (xn_ge_a_pow n)
theorem x_pos (n) : xn n > 0 :=
lt_of_le_of_lt (nat.zero_le n) (n_lt_xn n)
lemma eq_pell_lem : ∀n (b:ℤ√d), 1 ≤ b → is_pell b → pell_zd n ≥ b → ∃n, b = pell_zd n
| 0 b := λh1 hp hl, ⟨0, @zsqrtd.le_antisymm _ dnsq _ _ hl h1⟩
| (n+1) b := λh1 hp h,
have a1p : (0:ℤ√d) ≤ ⟨a, 1⟩, from trivial,
have am1p : (0:ℤ√d) ≤ ⟨a, -1⟩, from show (_:nat) ≤ _, by simp; exact nat.pred_le _,
have a1m : (⟨a, 1⟩ * ⟨a, -1⟩ : ℤ√d) = 1, from is_pell_norm.1 is_pell_one,
if ha : b ≥ ⟨↑a, 1⟩ then
let ⟨m, e⟩ := eq_pell_lem n (b * ⟨a, -1⟩)
(by rw ← a1m; exact mul_le_mul_of_nonneg_right ha am1p)
(is_pell_mul hp (is_pell_conj.1 is_pell_one))
(by have t := mul_le_mul_of_nonneg_right h am1p; rwa [pell_zd_succ, mul_assoc, a1m, mul_one] at t) in
⟨m+1, by rw [show b = b * ⟨a, -1⟩ * ⟨a, 1⟩, by rw [mul_assoc, eq.trans (mul_comm _ _) a1m]; simp, pell_zd_succ, e]⟩
else
suffices ¬1 < b, from ⟨0, show b = 1, from (or.resolve_left (lt_or_eq_of_le h1) this).symm⟩, λh1l,
by cases b with x y; exact
have bm : (_*⟨_,_⟩ :ℤ√(d a1)) = 1, from pell.is_pell_norm.1 hp,
have y0l : (0:ℤ√(d a1)) < ⟨x - x, y - -y⟩, from sub_lt_sub h1l $ λ(hn : (1:ℤ√(d a1)) ≤ ⟨x, -y⟩),
by have t := mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1); rw [bm, mul_one] at t; exact h1l t,
have yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩, from
show (⟨x, y⟩ - ⟨x, -y⟩ : ℤ√(d a1)) < ⟨a, 1⟩ - ⟨a, -1⟩, from
sub_lt_sub (by exact ha) $ λ(hn : (⟨x, -y⟩ : ℤ√(d a1)) ≤ ⟨a, -1⟩),
by have t := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hn (le_trans zero_le_one h1)) a1p;
rw [bm, one_mul, mul_assoc, eq.trans (mul_comm _ _) a1m, mul_one] at t; exact ha t,
by simp at y0l; simp at yl2; exact
match y, y0l, (yl2 : (⟨_, _⟩ : ℤ√_) < ⟨_, _⟩) with
| 0, y0l, yl2 := y0l (le_refl 0)
| (y+1 : ℕ), y0l, yl2 := yl2 (zsqrtd.le_of_le_le (le_refl 0)
(let t := int.coe_nat_le_coe_nat_of_le (nat.succ_pos y) in add_le_add t t))
| -[1+y], y0l, yl2 := y0l trivial
end
theorem eq_pell_zd (b : ℤ√d) (b1 : 1 ≤ b) (hp : is_pell b) : ∃n, b = pell_zd n :=
let ⟨n, h⟩ := @zsqrtd.le_arch d b in
eq_pell_lem n b b1 hp $ zsqrtd.le_trans h $ by rw zsqrtd.coe_nat_val; exact
zsqrtd.le_of_le_le
(int.coe_nat_le_coe_nat_of_le $ le_of_lt $ n_lt_xn _ _) (int.coe_zero_le _)
theorem eq_pell {x y : ℕ} (hp : x*x - d*y*y = 1) : ∃n, x = xn n ∧ y = yn n :=
have (1:ℤ√d) ≤ ⟨x, y⟩, from match x, hp with
| 0, (hp : 0 - _ = 1) := by rw nat.zero_sub at hp; contradiction
| (x+1), hp := zsqrtd.le_of_le_le (int.coe_nat_le_coe_nat_of_le $ nat.succ_pos x) (int.coe_zero_le _)
end,
let ⟨m, e⟩ := eq_pell_zd ⟨x, y⟩ this (is_pell_nat.2 hp) in
⟨m, match x, y, e with ._, ._, rfl := ⟨rfl, rfl⟩ end⟩
theorem pell_zd_add (m) : ∀ n, pell_zd (m + n) = pell_zd m * pell_zd n
| 0 := (mul_one _).symm
| (n+1) := by rw[← add_assoc, pell_zd_succ, pell_zd_succ, pell_zd_add n, ← mul_assoc]
theorem xn_add (m n) : xn (m + n) = xn m * xn n + d * yn m * yn n :=
by injection (pell_zd_add _ m n) with h _;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem yn_add (m n) : yn (m + n) = xn m * yn n + yn m * xn n :=
by injection (pell_zd_add _ m n) with _ h;
repeat {rw ← int.coe_nat_add at h <|> rw ← int.coe_nat_mul at h};
exact int.coe_nat_inj h
theorem pell_zd_sub {m n} (h : n ≤ m) : pell_zd (m - n) = pell_zd m * (pell_zd n).conj :=
let t := pell_zd_add n (m - n) in
by rw [nat.add_sub_of_le h] at t;
rw [t, mul_comm (pell_zd _ n) _, mul_assoc, (is_pell_norm _).1 (is_pell_pell_zd _ _), mul_one]
theorem xz_sub {m n} (h : n ≤ m) : xz (m - n) = xz m * xz n - d * yz m * yz n :=
by injection (pell_zd_sub _ h) with h _; repeat {rw ← neg_mul_eq_mul_neg at h}; exact h
theorem yz_sub {m n} (h : n ≤ m) : yz (m - n) = xz n * yz m - xz m * yz n :=
by injection (pell_zd_sub a1 h) with _ h; repeat {rw ← neg_mul_eq_mul_neg at h}; rw [add_comm, mul_comm] at h; exact h
theorem xy_coprime (n) : (xn n).coprime (yn n) :=
nat.coprime_of_dvd' $ λk kx ky,
let p := pell_eq n in by rw ← p; exact
nat.dvd_sub (le_of_lt $ nat.lt_of_sub_eq_succ p)
(dvd_mul_of_dvd_right kx _) (dvd_mul_of_dvd_right ky _)
theorem y_increasing {m} : Π {n}, m < n → yn m < yn n
| 0 h := absurd h $ nat.not_lt_zero _
| (n+1) h :=
have yn m ≤ yn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ y_increasing hl) (λe, by rw e),
by simp; refine lt_of_le_of_lt _ (nat.lt_add_of_pos_left $ x_pos a1 n);
rw ← mul_one (yn a1 m);
exact mul_le_mul this (le_of_lt a1) (nat.zero_le _) (nat.zero_le _)
theorem x_increasing {m} : Π {n}, m < n → xn m < xn n
| 0 h := absurd h $ nat.not_lt_zero _
| (n+1) h :=
have xn m ≤ xn n, from or.elim (lt_or_eq_of_le $ nat.le_of_succ_le_succ h)
(λhl, le_of_lt $ x_increasing hl) (λe, by rw e),
by simp; refine lt_of_lt_of_le (lt_of_le_of_lt this _) (nat.le_add_right _ _);
have t := nat.mul_lt_mul_of_pos_left a1 (x_pos a1 n); rwa mul_one at t
theorem yn_ge_n : Π n, n ≤ yn n
| 0 := nat.zero_le _
| (n+1) := show n < yn (n+1), from lt_of_le_of_lt (yn_ge_n n) (y_increasing $ nat.lt_succ_self n)
theorem y_mul_dvd (n) : ∀k, yn n ∣ yn (n * k)
| 0 := dvd_zero _
| (k+1) := by rw [nat.mul_succ, yn_add]; exact
dvd_add (dvd_mul_left _ _) (dvd_mul_of_dvd_left (y_mul_dvd k) _)
theorem y_dvd_iff (m n) : yn m ∣ yn n ↔ m ∣ n :=
⟨λh, nat.dvd_of_mod_eq_zero $ (nat.eq_zero_or_pos _).resolve_right $ λhp,
have co : nat.coprime (yn m) (xn (m * (n / m))), from nat.coprime.symm $
(xy_coprime _).coprime_dvd_right (y_mul_dvd m (n / m)),
have m0 : m > 0, from m.eq_zero_or_pos.resolve_left $
λe, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact
have 0 < yn a1 n, from y_increasing _ hp,
ne_of_lt (y_increasing a1 hp) (eq_zero_of_zero_dvd h).symm,
by rw [← nat.mod_add_div n m, yn_add] at h; exact
not_le_of_gt (y_increasing _ $ nat.mod_lt n m0)
(nat.le_of_dvd (y_increasing _ hp) $ co.dvd_of_dvd_mul_right $
(nat.dvd_add_iff_right $ dvd_mul_of_dvd_right (y_mul_dvd _ _ _) _).2 h),
λ⟨k, e⟩, by rw e; apply y_mul_dvd⟩
theorem xy_modeq_yn (n) :
∀k, xn (n * k) ≡ (xn n)^k [MOD (yn n)^2]
∧ yn (n * k) ≡ k * (xn n)^(k-1) * yn n [MOD (yn n)^3]
| 0 := by constructor; simp
| (k+1) :=
let ⟨hx, hy⟩ := xy_modeq_yn k in
have L : xn (n * k) * xn n + d * yn (n * k) * yn n ≡ xn n^k * xn n + 0 [MOD yn n^2], from
modeq.modeq_add (modeq.modeq_mul_right _ hx) $ modeq.modeq_zero_iff.2 $
by rw nat.pow_succ; exact
mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq.modeq_zero_iff.1 $
(hy.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).trans $ modeq.modeq_zero_iff.2 $
by simp [-mul_comm, -mul_assoc]) _) _,
have R : xn (n * k) * yn n + yn (n * k) * xn n ≡
xn n^k * yn n + k * xn n^k * yn n [MOD yn n^3], from
modeq.modeq_add (by rw nat.pow_succ; exact modeq.modeq_mul_right' _ hx) $
have k * xn n^(k - 1) * yn n * xn n = k * xn n^k * yn n,
by clear _let_match; cases k with k; simp [nat.pow_succ, mul_comm, mul_left_comm],
by rw ← this; exact modeq.modeq_mul_right _ hy,
by rw [nat.add_sub_cancel, nat.mul_succ, xn_add, yn_add, nat.pow_succ (xn _ n),
nat.succ_mul, add_comm (k * xn _ n^k) (xn _ n^k), right_distrib];
exact ⟨L, R⟩
theorem ysq_dvd_yy (n) : yn n * yn n ∣ yn (n * yn n) :=
modeq.modeq_zero_iff.1 $
((xy_modeq_yn n (yn n)).right.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).trans
(modeq.modeq_zero_iff.2 $ by simp [mul_dvd_mul_left, mul_assoc])
theorem dvd_of_ysq_dvd {n t} (h : yn n * yn n ∣ yn t) : yn n ∣ t :=
have nt : n ∣ t, from (y_dvd_iff n t).1 $ dvd_of_mul_left_dvd h,
n.eq_zero_or_pos.elim (λn0, by rw n0; rw n0 at nt; exact nt) $ λ(n0l : n > 0),
let ⟨k, ke⟩ := nt in
have yn n ∣ k * (xn n)^(k-1), from
nat.dvd_of_mul_dvd_mul_right (y_increasing n0l) $ modeq.modeq_zero_iff.1 $
by have xm := (xy_modeq_yn a1 n k).right; rw ← ke at xm; exact
(xm.modeq_of_dvd_of_modeq $ by simp [nat.pow_succ]).symm.trans
(modeq.modeq_zero_iff.2 h),
by rw ke; exact dvd_mul_of_dvd_right
(((xy_coprime _ _).pow_left _).symm.dvd_of_dvd_mul_right this) _
theorem pell_zd_succ_succ (n) : pell_zd (n + 2) + pell_zd n = (2 * a : ℕ) * pell_zd (n + 1) :=
have (1:ℤ√d) + ⟨a, 1⟩ * ⟨a, 1⟩ = ⟨a, 1⟩ * (2 * a),
by rw zsqrtd.coe_nat_val; change (⟨_,_⟩:ℤ√(d a1))=⟨_,_⟩;
rw dz_val; change az a1 with a; simp [mul_add, add_mul],
by simpa [mul_add, mul_comm, mul_left_comm] using congr_arg (* pell_zd a1 n) this
theorem xy_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) ∧
yn (n + 2) + yn n = (2 * a) * yn (n + 1) := begin
have := pell_zd_succ_succ a1 n, unfold pell_zd at this,
rw [← int.cast_coe_nat, zsqrtd.smul_val] at this,
injection this with h₁ h₂,
split; apply int.coe_nat_inj; [simpa using h₁, simpa using h₂]
end
theorem xn_succ_succ (n) : xn (n + 2) + xn n = (2 * a) * xn (n + 1) := (xy_succ_succ n).1
theorem yn_succ_succ (n) : yn (n + 2) + yn n = (2 * a) * yn (n + 1) := (xy_succ_succ n).2
theorem xz_succ_succ (n) : xz (n + 2) = (2 * a : ℕ) * xz (n + 1) - xz n :=
eq_sub_of_add_eq $ by delta xz; rw [← int.coe_nat_add, ← int.coe_nat_mul, xn_succ_succ]
theorem yz_succ_succ (n) : yz (n + 2) = (2 * a : ℕ) * yz (n + 1) - yz n :=
eq_sub_of_add_eq $ by delta yz; rw [← int.coe_nat_add, ← int.coe_nat_mul, yn_succ_succ]
theorem yn_modeq_a_sub_one : ∀ n, yn n ≡ n [MOD a-1]
| 0 := by simp
| 1 := by simp
| (n+2) := modeq.modeq_add_cancel_right (yn_modeq_a_sub_one n) $
have 2*(n+1) = n+2+n, by simp [two_mul],
by rw [yn_succ_succ, ← this];
refine modeq.modeq_mul (modeq.modeq_mul_left 2 (_ : a ≡ 1 [MOD a-1])) (yn_modeq_a_sub_one (n+1));
exact (modeq.modeq_of_dvd $ by rw [int.coe_nat_sub $ le_of_lt a1]; apply dvd_refl).symm
theorem yn_modeq_two : ∀ n, yn n ≡ n [MOD 2]
| 0 := by simp
| 1 := by simp
| (n+2) := modeq.modeq_add_cancel_right (yn_modeq_two n) $
have 2*(n+1) = n+2+n, by simp [two_mul],
by rw [yn_succ_succ, ← this];
refine modeq.modeq_mul _ (yn_modeq_two (n+1));
exact modeq.trans
(modeq.modeq_zero_iff.2 $ by simp)
(modeq.modeq_zero_iff.2 $ by simp).symm
lemma x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) :
(a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) := by ring
theorem x_sub_y_dvd_pow (y : ℕ) :
∀ n, (2*a*y - y*y - 1 : ℤ) ∣ yz n * (a - y) + ↑(y^n) - xz n
| 0 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| 1 := by simp [xz, yz, int.coe_nat_zero, int.coe_nat_one]
| (n+2) :=
have (2*a*y - y*y - 1 : ℤ) ∣ ↑(y^(n + 2)) - ↑(2 * a) * ↑(y^(n + 1)) + ↑(y^n), from
⟨-↑(y^n), by simp [nat.pow_succ, mul_add, int.coe_nat_mul,
show ((2:ℕ):ℤ) = 2, from rfl, mul_comm, mul_left_comm]⟩,
by rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem a1 ↑(y^(n+2)) ↑(y^(n+1)) ↑(y^n)]; exact
dvd_sub (dvd_add this $ dvd_mul_of_dvd_right (x_sub_y_dvd_pow (n+1)) _) (x_sub_y_dvd_pow n)
theorem xn_modeq_x2n_add_lem (n j) : xn n ∣ d * yn n * (yn n * xn j) + xn j :=
have h1 : d * yn n * (yn n * xn j) + xn j = (d * yn n * yn n + 1) * xn j,
by simp [add_mul, mul_assoc],
have h2 : d * yn n * yn n + 1 = xn n * xn n, by apply int.coe_nat_inj;
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul}; exact
add_eq_of_eq_sub' (eq.symm $ pell_eqz _ _),
by rw h2 at h1; rw [h1, mul_assoc]; exact dvd_mul_right _ _
theorem xn_modeq_x2n_add (n j) : xn (2 * n + j) + xn j ≡ 0 [MOD xn n] :=
by rw [two_mul, add_assoc, xn_add, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right (xn a1 n) (xn a1 (n + j))) $
by rw [yn_add, left_distrib, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_of_dvd_right (dvd_mul_right _ _) _) $
modeq.modeq_zero_iff.2 $ xn_modeq_x2n_add_lem _ _ _
lemma xn_modeq_x2n_sub_lem {n j} (h : j ≤ n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
have h1 : xz n ∣ ↑d * yz n * yz (n - j) + xz j, by rw [yz_sub _ h, mul_sub_left_distrib, sub_add_eq_add_sub]; exact
dvd_sub
(by delta xz; delta yz;
repeat {rw ← int.coe_nat_add <|> rw ← int.coe_nat_mul}; rw mul_comm (xn a1 j) (yn a1 n);
exact int.coe_nat_dvd.2 (xn_modeq_x2n_add_lem _ _ _))
(dvd_mul_of_dvd_right (dvd_mul_right _ _) _),
by rw [two_mul, nat.add_sub_assoc h, xn_add, add_assoc]; exact
show _ ≡ 0+0 [MOD xn a1 n], from modeq.modeq_add (modeq.modeq_zero_iff.2 $ dvd_mul_right _ _) $
modeq.modeq_zero_iff.2 $ int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1
theorem xn_modeq_x2n_sub {n j} (h : j ≤ 2 * n) : xn (2 * n - j) + xn j ≡ 0 [MOD xn n] :=
(le_total j n).elim xn_modeq_x2n_sub_lem
(λjn, have 2 * n - j + j ≤ n + j, by rw [nat.sub_add_cancel h, two_mul]; exact nat.add_le_add_left jn _,
let t := xn_modeq_x2n_sub_lem (nat.le_of_add_le_add_right this) in by rwa [nat.sub_sub_self h, add_comm] at t)
theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) ≡ xn j [MOD xn n] :=
modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n + j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_add _ _ _).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, add_assoc]; apply xn_modeq_x2n_add
theorem xn_modeq_x4n_sub {n j} (h : j ≤ 2 * n) : xn (4 * n - j) ≡ xn j [MOD xn n] :=
have h' : j ≤ 2*n, from le_trans h (by rw nat.succ_mul; apply nat.le_add_left),
modeq.modeq_add_cancel_right (modeq.refl $ xn (2 * n - j)) $
by refine @modeq.trans _ _ 0 _ _ (by rw add_comm; exact (xn_modeq_x2n_sub _ h).symm);
rw [show 4*n = 2*n + 2*n, from right_distrib 2 2 n, nat.add_sub_assoc h']; apply xn_modeq_x2n_add
theorem eq_of_xn_modeq_lem1 {i n} : Π {j}, i < j → j < n → xn i % xn n < xn j % xn n
| 0 ij _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij jn :=
suffices xn j % xn n < xn (j + 1) % xn n, from
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem1 h (le_of_lt jn)) this)
(λh, by rw h; exact this),
by rw [nat.mod_eq_of_lt (x_increasing _ (nat.lt_of_succ_lt jn)), nat.mod_eq_of_lt (x_increasing _ jn)];
exact x_increasing _ (nat.lt_succ_self _)
theorem eq_of_xn_modeq_lem2 {n} (h : 2 * xn n = xn (n + 1)) : a = 2 ∧ n = 0 :=
by rw [xn_succ, mul_comm] at h; exact
have n = 0, from n.eq_zero_or_pos.resolve_right $ λnp,
ne_of_lt (lt_of_le_of_lt (nat.mul_le_mul_left _ a1)
(nat.lt_add_of_pos_right $ mul_pos (d_pos a1) (y_increasing a1 np))) h,
by cases this; simp at h; exact ⟨h.symm, rfl⟩
theorem eq_of_xn_modeq_lem3 {i n} (npos : n > 0) :
Π {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → xn i % xn n < xn j % xn n
| 0 ij _ _ _ := absurd ij (nat.not_lt_zero _)
| (j+1) ij j2n jnn ntriv :=
have lem2 : ∀k > n, k ≤ 2*n → (↑(xn k % xn n) : ℤ) = xn n - xn (2 * n - k), from λk kn k2n,
let k2nl := lt_of_add_lt_add_right $ show 2*n-k+k < n+k, by
{rw nat.sub_add_cancel, rw two_mul; exact (add_lt_add_left kn n), exact k2n } in
have xle : xn (2 * n - k) ≤ xn n, from le_of_lt $ x_increasing k2nl,
suffices xn k % xn n = xn n - xn (2 * n - k), by rw [this, int.coe_nat_sub xle],
by {
rw ← nat.mod_eq_of_lt (nat.sub_lt (x_pos a1 n) (x_pos a1 (2 * n - k))),
apply modeq.modeq_add_cancel_right (modeq.refl (xn a1 (2 * n - k))),
rw [nat.sub_add_cancel xle],
have t := xn_modeq_x2n_sub_lem a1 (le_of_lt k2nl),
rw nat.sub_sub_self k2n at t,
exact t.trans (modeq.modeq_zero_iff.2 $ dvd_refl _).symm },
(lt_trichotomy j n).elim
(λ (jn : j < n), eq_of_xn_modeq_lem1 ij (lt_of_le_of_ne jn jnn)) $ λo, o.elim
(λ (jn : j = n), by {
cases jn,
apply int.lt_of_coe_nat_lt_coe_nat,
rw [lem2 (n+1) (nat.lt_succ_self _) j2n,
show 2 * n - (n + 1) = n - 1, by rw[two_mul, ← nat.sub_sub, nat.add_sub_cancel]],
refine lt_sub_left_of_add_lt (int.coe_nat_lt_coe_nat_of_lt _),
cases (lt_or_eq_of_le $ nat.le_of_succ_le_succ ij) with lin ein,
{ rw nat.mod_eq_of_lt (x_increasing _ lin),
have ll : xn a1 (n-1) + xn a1 (n-1) ≤ xn a1 n,
{ rw [← two_mul, mul_comm, show xn a1 n = xn a1 (n-1+1), by rw [nat.sub_add_cancel npos], xn_succ],
exact le_trans (nat.mul_le_mul_left _ a1) (nat.le_add_right _ _) },
have npm : (n-1).succ = n := nat.succ_pred_eq_of_pos npos,
have il : i ≤ n - 1 := by apply nat.le_of_succ_le_succ; rw npm; exact lin,
cases lt_or_eq_of_le il with ill ile,
{ exact lt_of_lt_of_le (nat.add_lt_add_left (x_increasing a1 ill) _) ll },
{ rw ile,
apply lt_of_le_of_ne ll,
rw ← two_mul,
exact λe, ntriv $
let ⟨a2, s1⟩ := @eq_of_xn_modeq_lem2 _ a1 (n-1) (by rw[nat.sub_add_cancel npos]; exact e) in
have n1 : n = 1, from le_antisymm (nat.le_of_sub_eq_zero s1) npos,
by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } },
{ rw [ein, nat.mod_self, add_zero],
exact x_increasing _ (nat.pred_lt $ ne_of_gt npos) } })
(λ (jn : j > n),
have lem1 : j ≠ n → xn j % xn n < xn (j + 1) % xn n → xn i % xn n < xn (j + 1) % xn n, from λjn s,
(lt_or_eq_of_le (nat.le_of_succ_le_succ ij)).elim
(λh, lt_trans (eq_of_xn_modeq_lem3 h (le_of_lt j2n) jn $ λ⟨a1, n1, i0, j2⟩,
by rw [n1, j2] at j2n; exact absurd j2n dec_trivial) s)
(λh, by rw h; exact s),
lem1 (ne_of_gt jn) $ int.lt_of_coe_nat_lt_coe_nat $ by {
rw [lem2 j jn (le_of_lt j2n), lem2 (j+1) (nat.le_succ_of_le jn) j2n],
refine sub_lt_sub_left (int.coe_nat_lt_coe_nat_of_lt $ x_increasing _ _) _,
rw [nat.sub_succ],
exact nat.pred_lt (ne_of_gt $ nat.sub_pos_of_lt j2n) })
theorem eq_of_xn_modeq_le {i j n} (npos : n > 0) (ij : i ≤ j) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n])
(ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j :=
(lt_or_eq_of_le ij).resolve_left $ λij',
if jn : j = n then by {
refine ne_of_gt _ h,
rw [jn, nat.mod_self],
have x0 : xn a1 0 % xn a1 n > 0 := by rw [nat.mod_eq_of_lt (x_increasing a1 npos)]; exact dec_trivial,
cases i with i, exact x0,
rw jn at ij',
exact lt_trans x0 (eq_of_xn_modeq_lem3 _ npos (nat.succ_pos _) (le_trans ij j2n) (ne_of_lt ij') $
λ⟨a1, n1, _, i2⟩, by rw [n1, i2] at ij'; exact absurd ij' dec_trivial)
} else ne_of_lt (eq_of_xn_modeq_lem3 npos ij' j2n jn ntriv) h
theorem eq_of_xn_modeq {i j n} (npos : n > 0) (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n) (h : xn i ≡ xn j [MOD xn n])
(ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j :=
(le_total i j).elim
(λij, eq_of_xn_modeq_le npos ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2)
(λij, (eq_of_xn_modeq_le npos ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩, (ntriv a2 n1).right i2 j0).symm)
theorem eq_of_xn_modeq' {i j n} (ipos : i > 0) (hin : i ≤ n) (j4n : j ≤ 4 * n) (h : xn j ≡ xn i [MOD xn n]) :
j = i ∨ j + i = 4 * n :=
have i2n : i ≤ 2*n, by apply le_trans hin; rw two_mul; apply nat.le_add_left,
have npos : n > 0, from lt_of_lt_of_le ipos hin,
(le_or_gt j (2 * n)).imp
(λj2n : j ≤ 2*n, eq_of_xn_modeq npos j2n i2n h $
λa2 n1, ⟨λj0 i2, by rw [n1, i2] at hin; exact absurd hin dec_trivial,
λj2 i0, ne_of_gt ipos i0⟩)
(λj2n : j > 2*n, suffices i = 4*n - j, by rw [this, nat.add_sub_of_le j4n],
have j42n : 4*n - j ≤ 2*n, from @nat.le_of_add_le_add_right j _ _ $
by rw [nat.sub_add_cancel j4n, show 4*n = 2*n + 2*n, from right_distrib 2 2 n];
exact nat.add_le_add_left (le_of_lt j2n) _,
eq_of_xn_modeq npos i2n j42n
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [nat.sub_sub_self j4n] at t)
(λa2 n1, ⟨λi0, absurd i0 (ne_of_gt ipos), λi2, by rw[n1, i2] at hin; exact absurd hin dec_trivial⟩))
theorem modeq_of_xn_modeq {i j n} (ipos : i > 0) (hin : i ≤ n) (h : xn j ≡ xn i [MOD xn n]) :
j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] :=
let j' := j % (4 * n) in
have n4 : 4 * n > 0, from mul_pos dec_trivial (lt_of_lt_of_le ipos hin),
have jl : j' < 4 * n, from nat.mod_lt _ n4,
have jj : j ≡ j' [MOD 4 * n], by delta modeq; rw nat.mod_eq_of_lt jl,
have ∀j q, xn (j + 4 * n * q) ≡ xn j [MOD xn n], begin
intros j q, induction q with q IH, { simp },
rw[nat.mul_succ, ← add_assoc, add_comm],
exact modeq.trans (xn_modeq_x4n_add _ _ _) IH
end,
or.imp
(λ(ji : j' = i), by rwa ← ji)
(λ(ji : j' + i = 4 * n), (modeq.modeq_add jj (modeq.refl _)).trans $
by rw ji; exact modeq.modeq_zero_iff.2 (dvd_refl _))
(eq_of_xn_modeq' ipos hin (le_of_lt jl) $
(modeq.symm (by rw ← nat.mod_add_div j (4*n); exact this j' _)).trans h)
end
theorem xy_modeq_of_modeq {a b c} (a1 : a > 1) (b1 : b > 1) (h : a ≡ b [MOD c]) :
∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c]
| 0 := by constructor; refl
| 1 := by simp; exact ⟨h, modeq.refl 1⟩
| (n+2) := ⟨
modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).left $
by rw [xn_succ_succ a1, xn_succ_succ b1]; exact
modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).left,
modeq.modeq_add_cancel_right (xy_modeq_of_modeq n).right $
by rw [yn_succ_succ a1, yn_succ_succ b1]; exact
modeq.modeq_mul (modeq.modeq_mul_left _ h) (xy_modeq_of_modeq (n+1)).right⟩
theorem matiyasevic {a k x y} : (∃ a1 : a > 1, xn a1 k = x ∧ yn a1 k = y) ↔
a > 1 ∧ k ≤ y ∧
(x = 1 ∧ y = 0 ∨
∃ (u v s t b : ℕ),
x * x - (a * a - 1) * y * y = 1 ∧
u * u - (a * a - 1) * v * v = 1 ∧
s * s - (b * b - 1) * t * t = 1 ∧
b > 1 ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧
v > 0 ∧ y * y ∣ v ∧
s ≡ x [MOD u] ∧
t ≡ k [MOD 4 * y]) :=
⟨λ⟨a1, hx, hy⟩, by rw [← hx, ← hy];
refine ⟨a1, (nat.eq_zero_or_pos k).elim
(λk0, by rw k0; exact ⟨le_refl _, or.inl ⟨rfl, rfl⟩⟩) (λkpos, _)⟩; exact
let x := xn a1 k, y := yn a1 k,
m := 2 * (k * y),
u := xn a1 m, v := yn a1 m in
have ky : k ≤ y, from yn_ge_n a1 k,
have yv : y * y ∣ v, from dvd_trans (ysq_dvd_yy a1 k) $
(y_dvd_iff _ _ _).2 $ dvd_mul_left _ _,
have uco : nat.coprime u (4 * y), from
have 2 ∣ v, from modeq.modeq_zero_iff.1 $ (yn_modeq_two _ _).trans $
modeq.modeq_zero_iff.2 (dvd_mul_right _ _),
have nat.coprime u 2, from
(xy_coprime a1 m).coprime_dvd_right this,
(this.mul_right this).mul_right $
(xy_coprime _ _).coprime_dvd_right (dvd_of_mul_left_dvd yv),
let ⟨b, ba, bm1⟩ := modeq.chinese_remainder uco a 1 in
have m1 : 1 < m, from
have 0 < k * y, from mul_pos kpos (y_increasing a1 kpos),
nat.mul_le_mul_left 2 this,
have vp : v > 0, from y_increasing a1 (lt_trans zero_lt_one m1),
have b1 : b > 1, from
have u > xn a1 1, from x_increasing a1 m1,
have u > a, by simp at this; exact this,
lt_of_lt_of_le a1 $ by delta modeq at ba;
rw nat.mod_eq_of_lt this at ba; rw ← ba; apply nat.mod_le,
let s := xn b1 k, t := yn b1 k in
have sx : s ≡ x [MOD u], from (xy_modeq_of_modeq b1 a1 ba k).left,
have tk : t ≡ k [MOD 4 * y], from
have 4 * y ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1);
exact modeq.dvd_of_modeq bm1.symm,
modeq.modeq_of_dvd_of_modeq this $ yn_modeq_a_sub_one _ _,
⟨ky, or.inr ⟨u, v, s, t, b,
pell_eq _ _, pell_eq _ _, pell_eq _ _, b1, bm1, ba, vp, yv, sx, tk⟩⟩,
λ⟨a1, ky, o⟩, ⟨a1, match o with
| or.inl ⟨x1, y0⟩ := by rw y0 at ky; rw [nat.eq_zero_of_le_zero ky, x1, y0]; exact ⟨rfl, rfl⟩
| or.inr ⟨u, v, s, t, b, xy, uv, st, b1, rem⟩ :=
match x, y, eq_pell a1 xy, u, v, eq_pell a1 uv, s, t, eq_pell b1 st, rem, ky with
| ._, ._, ⟨i, rfl, rfl⟩, ._, ._, ⟨n, rfl, rfl⟩, ._, ._, ⟨j, rfl, rfl⟩,
⟨(bm1 : b ≡ 1 [MOD 4 * yn a1 i]),
(ba : b ≡ a [MOD xn a1 n]),
(vp : yn a1 n > 0),
(yv : yn a1 i * yn a1 i ∣ yn a1 n),
(sx : xn b1 j ≡ xn a1 i [MOD xn a1 n]),
(tk : yn b1 j ≡ k [MOD 4 * yn a1 i])⟩,
(ky : k ≤ yn a1 i) :=
(nat.eq_zero_or_pos i).elim
(λi0, by simp [i0] at ky; rw [i0, ky]; exact ⟨rfl, rfl⟩) $ λipos,
suffices i = k, by rw this; exact ⟨rfl, rfl⟩,
by clear _x o rem xy uv st _match _match _fun_match; exact
have iln : i ≤ n, from le_of_not_gt $ λhin,
not_lt_of_ge (nat.le_of_dvd vp (dvd_of_mul_left_dvd yv)) (y_increasing a1 hin),
have yd : 4 * yn a1 i ∣ 4 * n, from mul_dvd_mul_left _ $ dvd_of_ysq_dvd a1 yv,
have jk : j ≡ k [MOD 4 * yn a1 i], from
have 4 * yn a1 i ∣ b - 1, from int.coe_nat_dvd.1 $
by rw int.coe_nat_sub (le_of_lt b1); exact modeq.dvd_of_modeq bm1.symm,
(modeq.modeq_of_dvd_of_modeq this (yn_modeq_a_sub_one b1 _)).symm.trans tk,
have ki : k + i < 4 * yn a1 i, from
lt_of_le_of_lt (add_le_add ky (yn_ge_n a1 i)) $
by rw ← two_mul; exact nat.mul_lt_mul_of_pos_right dec_trivial (y_increasing a1 ipos),
have ji : j ≡ i [MOD 4 * n], from
have xn a1 j ≡ xn a1 i [MOD xn a1 n], from (xy_modeq_of_modeq b1 a1 ba j).left.symm.trans sx,
(modeq_of_xn_modeq a1 ipos iln this).resolve_right $ λ (ji : j + i ≡ 0 [MOD 4 * n]),
not_le_of_gt ki $ nat.le_of_dvd (lt_of_lt_of_le ipos $ nat.le_add_left _ _) $
modeq.modeq_zero_iff.1 $ (modeq.modeq_add jk.symm (modeq.refl i)).trans $
modeq.modeq_of_dvd_of_modeq yd ji,
by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) :=
(modeq.modeq_of_dvd_of_modeq yd ji).symm.trans jk;
rwa [nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_left _ _) ki),
nat.mod_eq_of_lt (lt_of_le_of_lt (nat.le_add_right _ _) ki)] at this
end
end⟩⟩
lemma eq_pow_of_pell_lem {a y k} (a1 : 1 < a) (ypos : y > 0) : k > 0 → a > y^k →
(↑(y^k) : ℤ) < 2*a*y - y*y - 1 :=
have y < a → 2*a*y ≥ a + (y*y + 1), begin
intro ya, induction y with y IH, exact absurd ypos (lt_irrefl _),
cases nat.eq_zero_or_pos y with y0 ypos,
{ rw y0, simpa [two_mul], },
{ rw [nat.mul_succ, nat.mul_succ, nat.succ_mul y],
have : 2 * a ≥ y + nat.succ y,
{ change y + y < 2 * a, rw ← two_mul,
exact mul_lt_mul_of_pos_left (nat.lt_of_succ_lt ya) dec_trivial },
have := add_le_add (IH ypos (nat.lt_of_succ_lt ya)) this,
simpa }
end, λk0 yak,
lt_of_lt_of_le (int.coe_nat_lt_coe_nat_of_lt yak) $
by rw sub_sub; apply le_sub_right_of_add_le;
apply int.coe_nat_le_coe_nat_of_le;
have y1 := nat.pow_le_pow_of_le_right ypos k0; simp at y1;
exact this (lt_of_le_of_lt y1 yak)
theorem eq_pow_of_pell {m n k} : (n^k = m ↔
k = 0 ∧ m = 1 ∨ k > 0 ∧
(n = 0 ∧ m = 0 ∨ n > 0 ∧
∃ (w a t z : ℕ) (a1 : a > 1),
xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧
2 * a * n = t + (n * n + 1) ∧
m < t ∧ n ≤ w ∧ k ≤ w ∧
a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)) :=
⟨λe, by rw ← e;
refine (nat.eq_zero_or_pos k).elim
(λk0, by rw k0; exact or.inl ⟨rfl, rfl⟩)
(λkpos, or.inr ⟨kpos, _⟩);
refine (nat.eq_zero_or_pos n).elim
(λn0, by rw [n0, nat.zero_pow kpos]; exact or.inl ⟨rfl, rfl⟩)
(λnpos, or.inr ⟨npos, _⟩); exact
let w := _root_.max n k in
have nw : n ≤ w, from le_max_left _ _,
have kw : k ≤ w, from le_max_right _ _,
have wpos : w > 0, from lt_of_lt_of_le npos nw,
have w1 : w + 1 > 1, from nat.succ_lt_succ wpos,
let a := xn w1 w in
have a1 : a > 1, from x_increasing w1 wpos,
let x := xn a1 k, y := yn a1 k in
let ⟨z, ze⟩ := show w ∣ yn w1 w, from modeq.modeq_zero_iff.1 $
modeq.trans (yn_modeq_a_sub_one w1 w) (modeq.modeq_zero_iff.2 $ dvd_refl _) in
have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k ≤ n^w : nat.pow_le_pow_of_le_right npos kw
... < (w + 1)^w : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) wpos
... ≤ a : xn_ge_a_pow w1 w,
let ⟨t, te⟩ := int.eq_coe_of_zero_le $
le_trans (int.coe_zero_le _) $ le_of_lt nt in
have na : n ≤ a, from le_trans nw $ le_of_lt $ n_lt_xn w1 w,
have tm : x ≡ y * (a - n) + n^k [MOD t], begin
apply modeq.modeq_of_dvd,
rw [int.coe_nat_add, int.coe_nat_mul, int.coe_nat_sub na, ← te],
exact x_sub_y_dvd_pow a1 n k
end,
have ta : 2 * a * n = t + (n * n + 1), from int.coe_nat_inj $
by rw [int.coe_nat_add, ← te, sub_sub];
repeat {rw int.coe_nat_add <|> rw int.coe_nat_mul};
rw [int.coe_nat_one, sub_add_cancel]; refl,
have mt : n^k < t, from int.lt_of_coe_nat_lt_coe_nat $
by rw ← te; exact nt,
have zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1,
by rw ← ze; exact pell_eq w1 w,
⟨w, a, t, z, a1, tm, ta, mt, nw, kw, zp⟩,
λo, match o with
| or.inl ⟨k0, m1⟩ := by rw [k0, m1]; refl
| or.inr ⟨kpos, or.inl ⟨n0, m0⟩⟩ := by rw [n0, m0, nat.zero_pow kpos]
| or.inr ⟨kpos, or.inr ⟨npos, w, a, t, z,
(a1 : a > 1),
(tm : xn a1 k ≡ yn a1 k * (a - n) + m [MOD t]),
(ta : 2 * a * n = t + (n * n + 1)),
(mt : m < t),
(nw : n ≤ w),
(kw : k ≤ w),
(zp : a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)⟩⟩ :=
have wpos : w > 0, from lt_of_lt_of_le npos nw,
have w1 : w + 1 > 1, from nat.succ_lt_succ wpos,
let ⟨j, xj, yj⟩ := eq_pell w1 zp in
by clear _match o _let_match; exact
have jpos : j > 0, from (nat.eq_zero_or_pos j).resolve_left $ λj0,
have a1 : a = 1, by rw j0 at xj; exact xj,
have 2 * n = t + (n * n + 1), by rw a1 at ta; exact ta,
have n1 : n = 1, from
have n * n < n * 2, by rw [mul_comm n 2, this]; apply nat.le_add_left,
have n ≤ 1, from nat.le_of_lt_succ $ lt_of_mul_lt_mul_left this (nat.zero_le _),
le_antisymm this npos,
by rw n1 at this;
rw ← @nat.add_right_cancel 0 2 t this at mt;
exact nat.not_lt_zero _ mt,
have wj : w ≤ j, from nat.le_of_dvd jpos $ modeq.modeq_zero_iff.1 $
(yn_modeq_a_sub_one w1 j).symm.trans $
modeq.modeq_zero_iff.2 ⟨z, yj.symm⟩,
have nt : (↑(n^k) : ℤ) < 2 * a * n - n * n - 1, from
eq_pow_of_pell_lem a1 npos kpos $ calc
n^k ≤ n^j : nat.pow_le_pow_of_le_right npos (le_trans kw wj)
... < (w + 1)^j : nat.pow_lt_pow_of_lt_left (nat.lt_succ_of_le nw) jpos
... ≤ xn w1 j : xn_ge_a_pow w1 j
... = a : xj.symm,
have na : n ≤ a, by rw xj; exact
le_trans (le_trans nw wj) (le_of_lt $ n_lt_xn _ _),
have te : (t : ℤ) = 2 * ↑a * ↑n - ↑n * ↑n - 1, by
rw sub_sub; apply eq_sub_of_add_eq; apply (int.coe_nat_eq_coe_nat_iff _ _).2;
exact ta.symm,
have xn a1 k ≡ yn a1 k * (a - n) + n^k [MOD t],
by have := x_sub_y_dvd_pow a1 n k;
rw [← te, ← int.coe_nat_sub na] at this; exact modeq.modeq_of_dvd this,
have n^k % t = m % t, from
modeq.modeq_add_cancel_left (modeq.refl _) (this.symm.trans tm),
by rw ← te at nt;
rwa [nat.mod_eq_of_lt (int.lt_of_coe_nat_lt_coe_nat nt), nat.mod_eq_of_lt mt] at this
end⟩
end pell
|
cb874ef1c3bf567a7e17c2d121a1ff11efddd820 | 75c54c8946bb4203e0aaf196f918424a17b0de99 | /src/bfol.lean | 7c47cce331f4f78fef6fc3eb55b02544746ef114 | [
"Apache-2.0"
] | permissive | urkud/flypitch | 261e2a45f1038130178575406df8aea78255ba77 | 2250f5eda14b6ef9fc3e4e1f4a9ac4005634de5c | refs/heads/master | 1,653,266,469,246 | 1,577,819,679,000 | 1,577,819,679,000 | 259,862,235 | 1 | 0 | Apache-2.0 | 1,588,147,244,000 | 1,588,147,244,000 | null | UTF-8 | Lean | false | false | 59,389 | lean | /-
Copyright (c) 2019 The Flypitch Project. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Han, Floris van Doorn
-/
/- A development of boolean-valued first-order logic in Lean.
-/
import .fol order.complete_boolean_algebra
open nat set fol lattice
universe variables u v w
local notation h :: t := dvector.cons h t
local notation `[` l:(foldr `, ` (h t, dvector.cons h t) dvector.nil `]`:0) := l
local infix ⇒ := lattice.imp
local infix ` ⟷ `:40 := lattice.biimp
namespace fol
section bfol
/- bModel β Theory -/
/- an L-Structure is a type S with interpretations of the functions and relations on S -/
variables (L : Language.{u}) (β : Type v) [complete_boolean_algebra β]
structure bStructure :=
(carrier : Type u)
(fun_map : ∀{n}, L.functions n → dvector carrier n → carrier)
(rel_map : ∀{n}, L.relations n → dvector carrier n → β)
(eq : carrier → carrier → β)
(eq_refl : ∀ x, eq x x = ⊤)
(eq_symm : ∀ x y, eq x y = eq y x)
(eq_trans : ∀{x} y {z}, eq x y ⊓ eq y z ≤ eq x z)
(fun_congr : ∀{n} (f : L.functions n) (x y : dvector carrier n),
(x.map2 eq y).fInf ≤ eq (fun_map f x) (fun_map f y))
(rel_congr : ∀{n} (R : L.relations n) (x y : dvector carrier n),
(x.map2 eq y).fInf ⊓ rel_map R x ≤ rel_map R y)
variables {L β}
instance has_coe_bStructure : has_coe_to_sort (bStructure L β) :=
⟨Type u, bStructure.carrier⟩
attribute [simp] bStructure.eq_refl
variables {S : bStructure L β} {v v' : ℕ → S} {n l : ℕ}
@[simp] lemma eq_drefl : ∀{n} (x : dvector S n), (x.map2 S.eq x).fInf = ⊤
| _ ([]) := rfl
| _ (x::xs) := by simp [eq_drefl]
lemma eq_dsymm : ∀{n} (x y : dvector S n), (x.map2 S.eq y).fInf = (y.map2 S.eq x).fInf
| _ ([]) ([]) := rfl
| _ (x::xs) (y::ys) := by simp [S.eq_symm x y, eq_dsymm]
lemma eq_dtrans : ∀{n} {x : dvector S n} (y : dvector S n) {z : dvector S n},
(x.map2 S.eq y).fInf ⊓ (y.map2 S.eq z).fInf ≤ (x.map2 S.eq z).fInf
| _ ([]) ([]) ([]) := by simp
| _ (x::xs) (y::ys) (z::zs) :=
begin
simp, split,
exact le_trans (inf_le_inf inf_le_left inf_le_left) (S.eq_trans y),
exact le_trans (inf_le_inf inf_le_right inf_le_right) (eq_dtrans ys)
end
@[simp] def subst_realize_congr1 (v v' : ℕ → S) (x : S) (n : ℕ) :
(⨅ (n : ℕ), S.eq (v n) (v' n)) ≤ ⨅(k : ℕ), S.eq (v[x // n] k) (v'[x // n] k) :=
by { rw [le_infi_iff], intro k, apply decidable.lt_by_cases k n; intro h; simp [h]; apply infi_le }
@[simp] def subst_realize_congr2 (v : ℕ → S) (x y : S) :
S.eq x y ≤ ⨅(k : ℕ), S.eq (v[x // n] k) (v[y // n] k) :=
by { rw [le_infi_iff], intro k, apply decidable.lt_by_cases k n; intro h; simp [h] }
/- realization of terms -/
@[simp] def boolean_realize_term (v : ℕ → S) :
∀{l} (t : preterm L l) (xs : dvector S l), S.carrier
| _ &k xs := v k
| _ (func f) xs := S.fun_map f xs
| _ (app t₁ t₂) xs := boolean_realize_term t₁ $ boolean_realize_term t₂ ([])::xs
lemma boolean_realize_term_congr' {v v' : ℕ → S} (h : ∀n, v n = v' n) :
∀{l} (t : preterm L l) (xs : dvector S l), boolean_realize_term v t xs = boolean_realize_term v' t xs
| _ &k xs := h k
| _ (func f) xs := by refl
| _ (app t₁ t₂) xs := by dsimp; rw [boolean_realize_term_congr' t₁, boolean_realize_term_congr' t₂]
lemma boolean_realize_term_subst (v : ℕ → S) : ∀{l} (n : ℕ) (t : preterm L l)
(s : term L) (xs : dvector S l), boolean_realize_term (v[boolean_realize_term v (s ↑ n) ([]) // n]) t xs = boolean_realize_term v (t[s // n]) xs
| _ n &k s [] :=
by apply decidable.lt_by_cases k n; intro h;[simp [h], {subst h; simp}, simp [h]]
| _ n (func f) s xs := by refl
| _ n (app t₁ t₂) s xs := by dsimp; simp*
lemma boolean_realize_term_subst_lift (v : ℕ → S) (x : S) (m : ℕ) : ∀{l} (t : preterm L l)
(xs : dvector S l), boolean_realize_term (v [x // m]) (t ↑' 1 # m) xs = boolean_realize_term v t xs
| _ &k [] :=
begin
by_cases h : m ≤ k,
{ have : m < k + 1, from lt_succ_of_le h, simp* },
{ have : k < m, from lt_of_not_ge h, simp* }
end
| _ (func f) xs := by refl
| _ (app t₁ t₂) xs := by simp*
lemma boolean_realize_term_congr_gen (v v' : ℕ → S) :
∀{l} (t : preterm L l) (xs xs' : dvector S l),
(⨅(n : ℕ), S.eq (v n) (v' n)) ⊓ (xs.map2 S.eq xs').fInf ≤
S.eq (boolean_realize_term v t xs) (boolean_realize_term v' t xs')
| _ &k xs xs' := le_trans inf_le_left (infi_le _ k)
| _ (func f) xs xs' := by { dsimp, apply le_trans inf_le_right, apply S.fun_congr }
| _ (app t₁ t₂) xs xs' :=
begin
refine le_trans _ (boolean_realize_term_congr_gen t₁ _ _),
simp only [dvector.map2, dvector.fInf_cons],
rw [le_inf_iff], split, apply inf_le_left,
apply inf_le_inf,
{ refine le_trans _ (boolean_realize_term_congr_gen t₂ _ _), simp [-le_infi_iff] },
reflexivity
end
lemma boolean_realize_term_congr (v v' : ℕ → S) {l} (t : preterm L l) (xs : dvector S l) :
(⨅(n : ℕ), S.eq (v n) (v' n)) ≤
S.eq (boolean_realize_term v t xs) (boolean_realize_term v' t xs) :=
begin
refine le_trans _ (boolean_realize_term_congr_gen v v' t _ _),
simp only [lattice.le_inf_iff, dvector.map2, le_refl, and_true, eq_drefl, le_top],
end
lemma boolean_realize_term_subst_congr (v : ℕ → S) {n} (s s' : term L) :
∀{l} (t : preterm L l) (xs : dvector S l),
S.eq (boolean_realize_term v (s ↑ n) ([])) (boolean_realize_term v (s' ↑ n) ([])) ≤
S.eq (boolean_realize_term v (t[s//n]) xs) (boolean_realize_term v (t[s'//n]) xs) :=
begin
intros,
rw [← boolean_realize_term_subst, ← boolean_realize_term_subst],
refine le_trans _ (boolean_realize_term_congr _ _ _ _),
apply subst_realize_congr2
end
/- realization of formulas -/
@[simp] def boolean_realize_formula : ∀{l}, (ℕ → S) → preformula L l → dvector S l → β
| _ v falsum xs := ⊥
| _ v (t₁ ≃ t₂) xs := S.eq (boolean_realize_term v t₁ xs) (boolean_realize_term v t₂ xs)
| _ v (rel R) xs := S.rel_map R xs
| _ v (apprel f t) xs := boolean_realize_formula v f $ boolean_realize_term v t ([])::xs
| _ v (f₁ ⟹ f₂) xs := boolean_realize_formula v f₁ xs ⇒ boolean_realize_formula v f₂ xs
| _ v (∀' f) xs := ⨅(x : S), boolean_realize_formula (v [x // 0]) f xs
lemma boolean_realize_formula_congr' : ∀{l} {v v' : ℕ → S} (h : ∀n, v n = v' n)
(f : preformula L l) (xs : dvector S l), boolean_realize_formula v f xs = boolean_realize_formula v' f xs
| _ v v' h falsum xs := by refl
| _ v v' h (t₁ ≃ t₂) xs := by simp [boolean_realize_term_congr' h]
| _ v v' h (rel R) xs := by refl
| _ v v' h (apprel f t) xs := by simp [boolean_realize_term_congr' h]; rw [boolean_realize_formula_congr' h]
| _ v v' h (f₁ ⟹ f₂) xs := by dsimp; rw [boolean_realize_formula_congr' h, boolean_realize_formula_congr' h]
| _ v v' h (∀' f) xs :=
by apply congr_arg infi; apply funext; intro x; apply boolean_realize_formula_congr'; intro n; apply subst_realize_congr h
lemma boolean_realize_formula_subst : ∀{l} (v : ℕ → S) (n : ℕ) (f : preformula L l)
(s : term L) (xs : dvector S l), boolean_realize_formula (v[boolean_realize_term v (s ↑ n) ([]) // n]) f xs = boolean_realize_formula v (f[s // n]) xs
| _ v n falsum s xs := by refl
| _ v n (t₁ ≃ t₂) s xs := by simp [boolean_realize_term_subst]
| _ v n (rel R) s xs := by refl
| _ v n (apprel f t) s xs := by simp [boolean_realize_term_subst]; rw boolean_realize_formula_subst
| _ v n (f₁ ⟹ f₂) s xs := by dsimp; congr' 1; rw boolean_realize_formula_subst
| _ v n (∀' f) s xs :=
begin
apply congr_arg infi; apply funext; intro x,
rw [←boolean_realize_formula_subst], apply boolean_realize_formula_congr',
intro k, rw [subst_realize2_0, ←boolean_realize_term_subst_lift v x 0, lift_term_def, lift_term2]
end
lemma boolean_realize_formula_subst0 {l} (v : ℕ → S) (f : preformula L l) (s : term L) (xs : dvector S l) :
boolean_realize_formula (v[boolean_realize_term v s ([]) // 0]) f xs = boolean_realize_formula v (f[s // 0]) xs :=
by have h := boolean_realize_formula_subst v 0 f s; simp at h; exact h xs
lemma boolean_realize_formula_subst_lift : ∀{l} (v : ℕ → S) (x : S) (m : ℕ)
(f : preformula L l) (xs : dvector S l), boolean_realize_formula (v [x // m]) (f ↑' 1 # m) xs = boolean_realize_formula v f xs
| _ v x m falsum xs := by refl
| _ v x m (t₁ ≃ t₂) xs := by simp [boolean_realize_term_subst_lift]
| _ v x m (rel R) xs := by refl
| _ v x m (apprel f t) xs :=
by simp [boolean_realize_term_subst_lift]; rw boolean_realize_formula_subst_lift
| _ v x m (f₁ ⟹ f₂) xs := by dsimp; congr' 1; apply boolean_realize_formula_subst_lift
| _ v x m (∀' f) xs :=
begin
apply congr_arg infi; apply funext, intro x',
rw [boolean_realize_formula_congr' (subst_realize2_0 _ _ _ _),
boolean_realize_formula_subst_lift]
end
lemma boolean_realize_formula_congr_gen : ∀(v v' : ℕ → S) {l} (f : preformula L l)
(xs xs' : dvector S l),
(⨅(n : ℕ), S.eq (v n) (v' n)) ⊓ (xs.map2 S.eq xs').fInf ⊓ boolean_realize_formula v f xs ≤
boolean_realize_formula v' f xs'
| v v' _ falsum xs xs' := inf_le_right
| v v' _ (t₁ ≃ t₂) xs xs' :=
begin
refine le_trans _ (S.eq_trans (boolean_realize_term v t₂ xs)),
rw le_inf_iff, split,
{ refine le_trans _ (S.eq_trans (boolean_realize_term v t₁ xs)),
apply inf_le_inf,
{ rw [S.eq_symm], apply boolean_realize_term_congr_gen },
refl },
apply le_trans inf_le_left, apply boolean_realize_term_congr_gen
end
| v v' _ (rel R) xs xs' := le_trans (inf_le_inf inf_le_right (le_refl _)) (S.rel_congr R xs xs')
| v v' _ (apprel f t) xs xs' :=
begin
simp, refine le_trans _ (boolean_realize_formula_congr_gen v v' f
(boolean_realize_term v t dvector.nil :: xs) _),
rw [le_inf_iff], split,
{ apply le_trans inf_le_left, rw [le_inf_iff], split, apply inf_le_left,
rw [dvector.map2, dvector.fInf_cons],
apply inf_le_inf, apply boolean_realize_term_congr, reflexivity },
{ apply inf_le_right }
end
| v v' _ (f₁ ⟹ f₂) xs xs' :=
begin
dsimp, simp only [lattice.imp, inf_sup_left], apply sup_le_sup,
{ apply le_neg_of_inf_eq_bot,
convert sub_eq_bot_of_le (boolean_realize_formula_congr_gen v' v f₁ xs' xs) using 1,
rw [inf_comm, @inf_comm _ _ (-_), @inf_assoc _ _ (has_inf.inf _ _),
@inf_assoc _ _ (has_inf.inf _ _)],
congr' 1, congr' 1, congr' 1, apply funext, intro n, apply S.eq_symm,
apply eq_dsymm, apply inf_comm },
{ apply boolean_realize_formula_congr_gen }
end
| v v' _ (∀' f) xs xs' :=
begin
dsimp only [boolean_realize_formula], rw le_infi_iff, intro x,
refine le_trans _ (boolean_realize_formula_congr_gen (v[x//0]) _ _ xs _),
apply inf_le_inf, apply inf_le_inf, apply subst_realize_congr1, refl, apply infi_le
end
lemma boolean_realize_formula_congr (v v' : ℕ → S) {l} (f : preformula L l) (xs : dvector S l) :
(⨅(n : ℕ), S.eq (v n) (v' n)) ⊓ boolean_realize_formula v f xs ≤
boolean_realize_formula v' f xs :=
begin
refine le_trans _ (boolean_realize_formula_congr_gen v v' f xs xs),
simp [lattice.le_inf_iff, dvector.map2, le_refl, and_true, eq_drefl, le_top],
end
lemma boolean_realize_formula_subst_congr (v : ℕ → S) (s s' : term L) :
∀{n l} (f : preformula L l) (xs : dvector S l),
S.eq (boolean_realize_term v (s ↑ n) ([])) (boolean_realize_term v (s' ↑ n) ([])) ⊓
boolean_realize_formula v (f[s//n]) xs ≤ boolean_realize_formula v (f[s'//n]) xs :=
begin
intros,
rw [← boolean_realize_formula_subst, ← boolean_realize_formula_subst],
refine le_trans _
(boolean_realize_formula_congr (v[boolean_realize_term v (s ↑ n) ([]) // n]) _ _ _),
simp, intro k,
apply decidable.lt_by_cases k n; intro h; simp [h]
end
lemma boolean_realize_formula_subst_congr0 (v : ℕ → S) (s s' : term L) {l} (f : preformula L l)
(xs : dvector S l) :
S.eq (boolean_realize_term v s ([])) (boolean_realize_term v s' ([])) ⊓
boolean_realize_formula v (f[s//0]) xs ≤ boolean_realize_formula v (f[s'//0]) xs :=
begin
convert boolean_realize_formula_subst_congr v s s' f xs; simp
end
@[simp] lemma boolean_realize_formula_not (v : ℕ → S) (f : formula L) :
boolean_realize_formula v (∼f) ([]) = -boolean_realize_formula v f ([]) :=
by simp [not]
/- the following definitions of provability and satisfiability are not exactly how you normally define them, since we define it for formulae instead of sentences. If all the formulae happen to be sentences, then these definitions are equivalent to the normal definitions (the realization of closed terms and sentences are independent of the realizer v).
-/
-- def all_prf (T T' : set (formula L)) := ∀{{f}}, f ∈ T' → T ⊢ f
-- infix ` ⊢ `:51 := fol.all_prf -- input: |- or \vdash
def boolean_realize_formula_glb (S : bStructure L β) (f : formula L) : β :=
⨅(v : ℕ → S), boolean_realize_formula v f ([])
notation `⟦`:max f `⟧[` S `]ᵤ`:0 := boolean_realize_formula_glb S f
-- def all_bsatisfied_in (S : bStructure L β) (T : set (formula L)) := ∀{{f}}, f ∈ T → S ⊨ᵇ f
-- infix ` ⊨ᵇ `:51 := fol.all_satisfied_in -- input using \|= or \vDash, but not using \bModels
variable (β)
def bstatisfied (T : set (formula L)) (f : formula L) : Prop :=
∀(S : bStructure L β) (v : ℕ → S),
(⨅(f' ∈ T), boolean_realize_formula v (f' : formula L) ([])) ≤ boolean_realize_formula v f ([])
variable {β}
notation T ` ⊨ᵤ[`:51 β`] `:0 f := fol.bstatisfied β T f -- input using \|= or \vDash, but not using \bModels
-- def all_bstatisfied (T T' : set (formula L)) := ∀{{f}}, f ∈ T' → T ⊨ᵇ f
-- infix ` ⊨ᵇ `:51 := fol.all_bstatisfied -- input using \|= or \vDash, but not using \bModels
-- def bstatisfied_in_trans {T : set (formula L)} {f : formula L} (H' : S ⊨ᵇ T)
-- (H : T ⊨ᵇ f) : S ⊨ᵇ f :=
-- λv, H S v $ λf' hf', H' hf' v
-- def all_bstatisfied_in_trans {T T' : set (formula L)} (H' : S ⊨ᵇ T) (H : T ⊨ᵇ T') :
-- S ⊨ᵇ T' :=
-- λf hf, bstatisfied_in_trans H' $ H hf
def bstatisfied_of_mem {T : set (formula L)} {f : formula L} (hf : f ∈ T) : T ⊨ᵤ[β] f :=
λS v, le_trans (infi_le _ f) (infi_le _ hf)
-- def all_bstatisfied_of_subset {T T' : set (formula L)} (h : T' ⊆ T) : T ⊨ᵇ T' :=
-- λf hf, bstatisfied_of_mem $ h hf
-- def bstatisfied_trans {T₁ T₂ : set (formula L)} {f : formula L} (H' : T₁ ⊨ᵇ T₂) (H : T₂ ⊨ᵇ f) : T₁ ⊨ᵇ f :=
-- λS v h, H S v $ λf' hf', H' hf' S v h
-- def all_bstatisfied_trans {T₁ T₂ T₃ : set (formula L)} (H' : T₁ ⊨ᵇ T₂) (H : T₂ ⊨ᵇ T₃) : T₁ ⊨ᵇ T₃ :=
-- λf hf, bstatisfied_trans H' $ H hf
def bstatisfied_weakening {T T' : set (formula L)} (H : T ⊆ T') {f : formula L} (HT : T ⊨ᵤ[β] f) :
T' ⊨ᵤ[β] f :=
begin
intros S v, refine le_trans _ (HT S v),
apply infi_le_infi, intro f,
apply infi_le_infi2, intro hf,
refine ⟨H hf, _⟩, refl
end
/- soundness for a set of formulae with boolean models -/
lemma boolean_formula_soundness {Γ : set (formula L)} {A : formula L} (H : Γ ⊢ A) : Γ ⊨ᵤ[β] A :=
begin
induction H; intros S v,
{ exact bstatisfied_of_mem H_h S v },
{ simp [deduction_simp], refine le_trans _ (H_ih S v), rw [inf_comm, infi_insert] },
{ refine le_trans _ (imp_inf_le _ _), swap,
refine le_trans _ (inf_le_inf (H_ih_h₁ S v) (H_ih_h₂ S v)), rw [inf_idem] },
{ apply le_of_sub_eq_bot, apply bot_unique, refine le_trans _ (H_ih S v),
rw [infi_insert, boolean_realize_formula_not] },
{ simp, intro x, refine le_trans _ (H_ih S _), apply le_infi, intro f,
apply le_infi, rintro ⟨f, hf, rfl⟩, rw [boolean_realize_formula_subst_lift],
exact le_trans (infi_le _ f) (infi_le _ hf) },
{ rw [←boolean_realize_formula_subst0], apply le_trans (H_ih S v), apply infi_le },
{ dsimp, rw [S.eq_refl], apply le_top },
{ refine le_trans _ (boolean_realize_formula_subst_congr0 v H_s H_t H_f ([])),
exact le_inf (H_ih_h₁ S v) (H_ih_h₂ S v) }
end
@[simp] def boolean_realize_bounded_term {n} (v : dvector S n) :
∀{l} (t : bounded_preterm L n l) (xs : dvector S l), S.carrier
| _ &k xs := v.nth k.1 k.2
| _ (bd_func f) xs := S.fun_map f xs
| _ (bd_app t₁ t₂) xs := boolean_realize_bounded_term t₁ $ boolean_realize_bounded_term t₂ ([])::xs
@[reducible] def boolean_realize_closed_term (S : bStructure L β) (t : closed_term L) : S :=
boolean_realize_bounded_term ([]) t ([])
lemma boolean_realize_bounded_term_eq {n} {v₁ : dvector S n} {v₂ : ℕ → S}
(hv : ∀k (hk : k < n), v₂ k = v₁.nth k hk) : ∀{l} (t : bounded_preterm L n l)
(xs : dvector S l), boolean_realize_term v₂ t.fst xs = boolean_realize_bounded_term v₁ t xs
| _ &k xs := hv k.1 k.2
| _ (bd_func f) xs := by refl
| _ (bd_app t₁ t₂) xs := by dsimp; simp [boolean_realize_bounded_term_eq]
lemma boolean_realize_bounded_term_irrel' {n n'} {v₁ : dvector S n} {v₂ : dvector S n'}
(h : ∀m (hn : m < n) (hn' : m < n'), v₁.nth m hn = v₂.nth m hn')
{l} (t : bounded_preterm L n l) (t' : bounded_preterm L n' l)
(ht : t.fst = t'.fst) (xs : dvector S l) :
boolean_realize_bounded_term v₁ t xs = boolean_realize_bounded_term v₂ t' xs :=
begin
induction t; cases t'; injection ht with ht₁ ht₂,
{ simp, cases t'_1; dsimp at ht₁, subst ht₁, exact h t.val t.2 t'_1_is_lt },
{ subst ht₁, refl },
{ simp [t_ih_t t'_t ht₁, t_ih_s t'_s ht₂] }
end
lemma boolean_realize_bounded_term_irrel {n} {v₁ : dvector S n}
(t : bounded_term L n) (t' : closed_term L) (ht : t.fst = t'.fst) (xs : dvector S 0) :
boolean_realize_bounded_term v₁ t xs = boolean_realize_closed_term S t' :=
by cases xs; exact boolean_realize_bounded_term_irrel'
(by intros m hm hm'; exfalso; exact not_lt_zero m hm') t t' ht ([])
@[simp] lemma boolean_realize_bounded_term_cast_eq_irrel {n m l} {h : n = m} {v : dvector S m} {t : bounded_preterm L n l} (xs : dvector S l) :
boolean_realize_bounded_term v (t.cast_eq h) xs = boolean_realize_bounded_term (v.cast h.symm) t xs := by {subst h, induction t, refl, refl, simp*}
@[simp] lemma boolean_realize_bounded_term_dvector_cast_irrel {n m l} {h : n = m} {v : dvector S n} {t : bounded_preterm L n l} {xs : dvector S l} :
boolean_realize_bounded_term (v.cast h) (t.cast (le_of_eq h)) xs = boolean_realize_bounded_term v t xs := by {subst h, simp, refl}
@[simp] lemma boolean_realize_bounded_term_bd_app
{n l} (t : bounded_preterm L n (l+1)) (s : bounded_term L n) (xs : dvector S n)
(xs' : dvector S l) :
boolean_realize_bounded_term xs (bd_app t s) xs' =
boolean_realize_bounded_term xs t (boolean_realize_bounded_term xs s ([])::xs') :=
by refl
@[simp] lemma boolean_realize_closed_term_bd_apps
{l} (t : closed_preterm L l) (ts : dvector (closed_term L) l) :
boolean_realize_closed_term S (bd_apps t ts) =
boolean_realize_bounded_term ([]) t (ts.map (λt', boolean_realize_bounded_term ([]) t' ([]))) :=
begin
induction ts generalizing t, refl, apply ts_ih (bd_app t ts_x)
end
lemma boolean_realize_bounded_term_bd_apps
{n l} (xs : dvector S n) (t : bounded_preterm L n l) (ts : dvector (bounded_term L n) l) :
boolean_realize_bounded_term xs (bd_apps t ts) ([]) =
boolean_realize_bounded_term xs t (ts.map (λt, boolean_realize_bounded_term xs t ([]))) :=
begin
induction ts generalizing t, refl, apply ts_ih (bd_app t ts_x)
end
@[simp] lemma boolean_realize_cast_bounded_term {n m} {h : n ≤ m} {t : bounded_term L n} {v : dvector S m} :
boolean_realize_bounded_term v (t.cast h) dvector.nil = boolean_realize_bounded_term (v.trunc n h) t dvector.nil :=
begin
revert t, apply bounded_term.rec,
{intro k, simp only [dvector.trunc_nth, fol.bounded_preterm.cast, fol.boolean_realize_bounded_term, dvector.nth, dvector.trunc], refl},
{simp[boolean_realize_bounded_term_bd_apps], intros, congr' 1, apply dvector.map_congr_pmem,
exact ih_ts}
end
/- When realizing a closed term, we can replace the realizing dvector with [] -/
@[simp] lemma boolean_realize_closed_term_v_irrel {n} {v : dvector S n} {t : bounded_term L 0} : boolean_realize_bounded_term v (t.cast (nat.zero_le n)) ([]) = boolean_realize_closed_term S t :=
by simp[boolean_realize_cast_bounded_term]
lemma boolean_realize_bounded_term_subst_lift' {n} (v : dvector S n) (x : S) :
∀{l} (t : bounded_preterm L n l) (xs : dvector S l),
boolean_realize_bounded_term (x::v) (t ↑' 1 # 0) xs = boolean_realize_bounded_term v t xs
| _ &k [] :=
begin
have : 0 < k.val + 1, from lt_succ_of_le (nat.zero_le _), simp*, refl
end
| _ (bd_func f) xs := by refl
| _ (bd_app t₁ t₂) xs := by { dsimp, simp* }
@[simp] lemma boolean_realize_bounded_term_subst_lift {n} (v : dvector S n) (x : S)
{l} (t : bounded_preterm L n l) (xs : dvector S l) :
boolean_realize_bounded_term (x::v) (t ↑ 1) xs = boolean_realize_bounded_term v t xs :=
boolean_realize_bounded_term_subst_lift' v x t xs
/- this is the same as boolean_realize_bounded_term, we should probably have a common generalization of this definition -/
-- @[simp] def substitute_bounded_term {n n'} (v : dvector (bounded_term n') n) :
-- ∀{l} (t : bounded_term L n l, bounded_preterm L n' l
-- | _ _ &k := v.nth k hk
-- | _ _ (bd_func f) := bd_func f
-- | _ _ (bd_app t₁ t₂) := bd_app (substitute_bounded_term ht₁) $ substitute_bounded_term ht₂
-- def substitute_bounded_term {n n' l} (t : bounded_preterm L n l)
-- (v : dvector (bounded_term n') n) : bounded_preterm L n' l :=
-- substitute_bounded_term v t.snd
@[simp] def boolean_realize_bounded_formula :
∀{n l} (v : dvector S n) (f : bounded_preformula L n l) (xs : dvector S l), β
| _ _ v bd_falsum xs := ⊥
| _ _ v (t₁ ≃ t₂) xs := S.eq (boolean_realize_bounded_term v t₁ xs) (boolean_realize_bounded_term v t₂ xs)
| _ _ v (bd_rel R) xs := S.rel_map R xs
| _ _ v (bd_apprel f t) xs := boolean_realize_bounded_formula v f $ boolean_realize_bounded_term v t ([])::xs
| _ _ v (f₁ ⟹ f₂) xs := boolean_realize_bounded_formula v f₁ xs ⇒ boolean_realize_bounded_formula v f₂ xs
| _ _ v (∀' f) xs := ⨅(x : S), boolean_realize_bounded_formula (x::v) f xs
notation S`[`:95 f ` ;; `:95 v ` ;; `:90 xs `]`:0 := @fol.boolean_realize_bounded_formula _ S _ _ v f xs
notation S`[`:95 f ` ;; `:95 v `]`:0 := @fol.boolean_realize_bounded_formula _ S _ 0 v f (dvector.nil)
@[reducible] def boolean_realize_sentence (S : bStructure L β) (f : sentence L) : β :=
boolean_realize_bounded_formula ([] : dvector S 0) f ([])
notation `⟦`:max f `⟧[` S `]`:0 := boolean_realize_sentence S f
lemma boolean_realize_bounded_formula_eq : ∀{n} {v₁ : dvector S n} {v₂ : ℕ → S}
(hv : ∀k (hk : k < n), v₂ k = v₁.nth k hk) {l} (t : bounded_preformula L n l)
(xs : dvector S l), boolean_realize_formula v₂ t.fst xs = boolean_realize_bounded_formula v₁ t xs
| _ _ _ hv _ bd_falsum xs := by refl
| _ _ _ hv _ (t₁ ≃ t₂) xs := by dsimp; congr' 1; apply boolean_realize_bounded_term_eq hv
| _ _ _ hv _ (bd_rel R) xs := by refl
| _ _ _ hv _ (bd_apprel f t) xs :=
by dsimp; simp [boolean_realize_bounded_term_eq hv, boolean_realize_bounded_formula_eq hv]
| _ _ _ hv _ (f₁ ⟹ f₂) xs :=
by dsimp; simp [boolean_realize_bounded_formula_eq hv]
| _ _ _ hv _ (∀' f) xs :=
begin
apply congr_arg infi; apply funext, intro x, apply boolean_realize_bounded_formula_eq,
intros k hk, cases k, refl, apply hv
end
lemma boolean_realize_bounded_formula_eq' {L : Language} {S : bStructure L β} {n}
{v₁ : dvector S n} (x : S) {l} (t : bounded_preformula L n l)
(xs : dvector S l) :
boolean_realize_bounded_formula v₁ t xs = boolean_realize_formula (λ k, if h : k < n then v₁.nth k h else x) t.fst xs :=
by { symmetry, apply boolean_realize_bounded_formula_eq, intros, rw [dif_pos] }
lemma boolean_realize_bounded_term_eq' {L : Language} {S : bStructure L β} {n}
{v₁ : dvector S n} (x : S) {l} (t : bounded_preterm L n l)
(xs : dvector S l) :
boolean_realize_bounded_term v₁ t xs = boolean_realize_term (λ k, if h : k < n then v₁.nth k h else x) t.fst xs :=
by { symmetry, apply boolean_realize_bounded_term_eq, intros, rw [dif_pos] }
lemma boolean_realize_bounded_formula_congr {n l} (H_nonempty : nonempty S) (v₁ v₂ : dvector S n) (f : bounded_preformula L n l) (xs : dvector S l) : ((⨅(m : fin n), S.eq (v₁.nth m (m.is_lt)) (v₂.nth m m.is_lt)) ⊓ boolean_realize_bounded_formula v₁ f xs : β) ≤ (boolean_realize_bounded_formula v₂ f xs) :=
begin
tactic.unfreeze_local_instances, cases H_nonempty with x,
rw [boolean_realize_bounded_formula_eq' x], rw[boolean_realize_bounded_formula_eq' x],
let v := (λ (k : ℕ), dite (k < n) (dvector.nth v₁ k) (λ (h : ¬k < n), x)),
let v' := (λ (k : ℕ), dite (k < n) (λ (h : k < n), dvector.nth v₂ k h) (λ (h : ¬k < n), x)),
have := boolean_realize_formula_congr v v' (f.fst) xs, convert this using 2,
{ refine le_antisymm _ _,
{ tidy_context, bv_intro N,
by_cases H_lt : N < n,
{ simp only [v,v',dif_pos H_lt], exact a ⟨N, ‹_›⟩ },
{ simp [v,v', dif_neg H_lt] } },
{ tidy_context, bv_intro m, rcases m with ⟨m,Hm⟩,
replace a := a m, dsimp [v,v'] at a, simpa only [dif_pos Hm] using a }}
end
-- lemma boolean_realize_bounded_formula_eq_of_fst : ∀{n} {v₁ w₁ : dvector S n}
-- {v₂ w₂ : ℕ → S} (hv₁ : ∀ k (hk : k < n), v₁.nth k hk = v₂ k)
-- (hw₁ : ∀ k (hk : k < n), w₁.nth k hk = w₂ k) {l₁ l₂}
-- (t₁ : bounded_preformula L n l₁) (t₂ : bounded_preformula L n l₂) (xs₁ : dvector S l₁)
-- (xs₂ : dvector S l₂) (H : boolean_realize_formula v₂ t₁.fst xs₁ = boolean_realize_formula w₂ t₂.fst xs₂),
-- (boolean_realize_bounded_formula v₁ t₁ xs₁ = boolean_realize_bounded_formula w₁ t₂ xs₂) :=
-- by intros; simpa[(boolean_realize_bounded_formula_eq hv₁ t₁).symm, (boolean_realize_bounded_formula_eq hw₁ t₂).symm]
lemma boolean_realize_bounded_formula_irrel' {n n'} {v₁ : dvector S n} {v₂ : dvector S n'}
(h : ∀m (hn : m < n) (hn' : m < n'), v₁.nth m hn = v₂.nth m hn')
{l} (f : bounded_preformula L n l) (f' : bounded_preformula L n' l)
(hf : f.fst = f'.fst) (xs : dvector S l) :
boolean_realize_bounded_formula v₁ f xs = boolean_realize_bounded_formula v₂ f' xs :=
begin
induction f generalizing n'; cases f'; injection hf with hf₁ hf₂,
{ refl },
{ simp [boolean_realize_bounded_term_irrel' h f_t₁ f'_t₁ hf₁,
boolean_realize_bounded_term_irrel' h f_t₂ f'_t₂ hf₂] },
{ rw [hf₁], refl },
{ simp [boolean_realize_bounded_term_irrel' h f_t f'_t hf₂, f_ih _ h f'_f hf₁] },
{ dsimp, congr' 1, apply f_ih_f₁ _ h _ hf₁, apply f_ih_f₂ _ h _ hf₂ },
{ apply congr_arg infi; apply funext, intro x, apply f_ih _ _ _ hf₁, intros,
cases m, refl, apply h }
end
lemma boolean_realize_bounded_formula_irrel {n} {v₁ : dvector S n}
(f : bounded_formula L n) (f' : sentence L) (hf : f.fst = f'.fst) (xs : dvector S 0) :
boolean_realize_bounded_formula v₁ f xs = ⟦f'⟧[S] :=
by cases xs; exact boolean_realize_bounded_formula_irrel'
(by intros m hm hm'; exfalso; exact not_lt_zero m hm') f f' hf ([])
@[simp] lemma boolean_realize_bounded_formula_cast_eq_irrel {n m l} {h : n = m} {v : dvector S m} {f : bounded_preformula L n l} {xs : dvector S l} :
boolean_realize_bounded_formula v (f.cast_eq h) xs = boolean_realize_bounded_formula (v.cast h.symm) f xs :=
by subst h; induction f; unfold bounded_preformula.cast_eq; finish
-- infix ` ⊨ᵇ `:51 := fol.boolean_realize_sentence -- input using \|= or \vDash, but not using \bModels
-- set_option pp.notation false
@[simp] lemma boolean_realize_sentence_false : ⟦(⊥ : sentence L)⟧[S] = (⊥ : β) :=
by refl
@[simp] lemma boolean_realize_sentence_imp {f₁ f₂ : sentence L} :
⟦f₁ ⟹ f₂⟧[S] = (⟦f₁⟧[S] ⇒ ⟦f₂⟧[S]) :=
by refl
@[simp] lemma boolean_realize_sentence_not {f : sentence L} :
⟦∼f⟧[S] = - (⟦f⟧[S]) :=
by simp [boolean_realize_sentence, bd_not]
lemma boolean_realize_sentence_dne {f : sentence L} :
⟦∼∼f⟧[S] = ⟦f⟧[S] :=
by simp [boolean_realize_sentence, bd_not]
@[simp] lemma boolean_realize_sentence_all {f : bounded_formula L 1} :
⟦∀'f⟧[S] = ⨅x : S, boolean_realize_bounded_formula([x]) f([]) :=
by refl
@[simp] lemma boolean_realize_bounded_formula_not {n} {v : dvector S n}
{f : bounded_formula.{u} L n} :
boolean_realize_bounded_formula v (∼f) ([]) = -boolean_realize_bounded_formula v f ([]) :=
by { simp [bd_not] }
@[simp] lemma boolean_realize_bounded_formula_or {n} {v : dvector S n}
{f g : bounded_formula.{u} L n} :
boolean_realize_bounded_formula v (f ⊔ g) ([]) =
boolean_realize_bounded_formula v f ([]) ⊔ boolean_realize_bounded_formula v g ([]) :=
by { simp [bd_or, lattice.imp] }
@[simp] lemma boolean_realize_bounded_formula_and {n} {v : dvector S n}
{f g : bounded_formula.{u} L n} :
boolean_realize_bounded_formula v (f ⊓ g) ([]) =
boolean_realize_bounded_formula v f ([]) ⊓ boolean_realize_bounded_formula v g ([]) :=
by { simp [bd_and, lattice.imp] }
@[simp] lemma boolean_realize_bounded_formula_ex {n} {v : dvector S n}
{f : bounded_formula.{u} L (n+1)} :
boolean_realize_bounded_formula v (∃' f) ([]) =
⨆(x : S), boolean_realize_bounded_formula (x::v) f ([]) :=
by { simp [bd_ex, neg_infi] }
lemma boolean_realize_bounded_sentence_ex {f : bounded_formula.{u} L 1} :
boolean_realize_bounded_formula ([] : dvector S 0) (∃' f) ([]) =
⨆(x : S), boolean_realize_bounded_formula ([x]) f ([]) :=
boolean_realize_bounded_formula_ex
@[simp] lemma boolean_realize_bounded_formula_biimp {n} {v : dvector S n}
{f g : bounded_formula.{u} L n} :
boolean_realize_bounded_formula v (f ⇔ g) ([]) =
(boolean_realize_bounded_formula v f ([]) ⟷ boolean_realize_bounded_formula v g ([])) :=
by {unfold bd_biimp, tidy}
lemma boolean_realize_bounded_formula_bd_apps_rel
{n l} (xs : dvector S n) (f : bounded_preformula L n l) (ts : dvector (bounded_term L n) l) :
boolean_realize_bounded_formula xs (bd_apps_rel f ts) ([]) =
boolean_realize_bounded_formula xs f (ts.map (λt, boolean_realize_bounded_term xs t ([]))) :=
begin
induction ts generalizing f, refl, apply ts_ih (bd_apprel f ts_x)
end
@[simp] lemma boolean_realize_cast_bounded_formula {n m} {h : n ≤ m} {f : bounded_formula L n} {v : dvector S m} :
boolean_realize_bounded_formula v (f.cast h) dvector.nil = boolean_realize_bounded_formula (v.trunc n h) f dvector.nil :=
begin
by_cases n = m,
by subst h; simp,
have : n < m, by apply nat.lt_of_le_and_ne; repeat{assumption},
apply boolean_realize_bounded_formula_irrel',
{intros, simp},
{simp}
end
@[simp] lemma boolean_realize_cast1_bounded_formula {n} {f : bounded_formula L n}
{v : dvector S (n+1)} :
boolean_realize_bounded_formula v f.cast1 dvector.nil =
boolean_realize_bounded_formula (v.trunc n $ n.le_add_right 1) f dvector.nil :=
boolean_realize_cast_bounded_formula
lemma boolean_realize_sentence_bd_apps_rel'
{l} (f : presentence L l) (ts : dvector (closed_term L) l) :
⟦bd_apps_rel f ts⟧[S] =
boolean_realize_bounded_formula ([]) f (ts.map $ boolean_realize_closed_term S) :=
boolean_realize_bounded_formula_bd_apps_rel ([]) f ts
lemma boolean_realize_bd_apps_rel
{l} (R : L.relations l) (ts : dvector (closed_term L) l) :
⟦bd_apps_rel (bd_rel R) ts⟧[S] = S.rel_map R (ts.map $ boolean_realize_closed_term S) :=
by apply boolean_realize_bounded_formula_bd_apps_rel ([]) (bd_rel R) ts
lemma boolean_realize_sentence_equal (t₁ t₂ : closed_term L) :
⟦t₁ ≃ t₂⟧[S] = S.eq (boolean_realize_closed_term S t₁) (boolean_realize_closed_term S t₂) :=
by refl
lemma boolean_realize_sentence_eq (v : ℕ → S) (f : sentence L) :
boolean_realize_formula v f.fst ([]) = ⟦f⟧[S] :=
boolean_realize_bounded_formula_eq (λk hk, by exfalso; exact not_lt_zero k hk) f _
lemma bstatisfied_in_eq_boolean_realize_sentence [HS : nonempty S] (f : sentence L) :
⟦f.fst⟧[S]ᵤ = ⟦f⟧[S] :=
begin
haveI : nonempty (ℕ → S) := HS.map (λ x n, x),
simp [boolean_realize_formula_glb, boolean_realize_sentence_eq]
end
def forced_in (x : β) (S : bStructure L β) (f : sentence L) : Prop :=
x ≤ ⟦f⟧[S]
notation x ` ⊩[`:52 S `] `:0 f:52 := forced_in x S f
def all_forced_in (x : β) (S : bStructure L β) (T : Theory L) : Prop :=
x ≤ ⨅(f ∈ T), ⟦f⟧[S]
notation x ` ⊩[`:52 S `] `:0 T:52 := all_forced_in x S T
@[simp]lemma forced_in_not {f : sentence L} {b} : b ⊩[S] ∼∼f ↔ b ⊩[S] f :=
by {change _ ≤ _ ↔ _ ≤ _, simp}
-- lemma all_boolean_realize_sentence_axm {f : sentence L} {T : Theory L} :
-- ∀ (H : S ⊨ᵇ insert f T = ⊤), S ⊨ᵇ f = ⊤ ∧ S ⊨ᵇ T = ⊤ :=
-- sorry --λ H, ⟨by {apply H, exact or.inl rfl}, by {intros ψ hψ, apply H, exact or.inr hψ}⟩
-- @[simp] lemma all_boolean_realize_sentence_axm_rw {f : sentence L} {T : Theory L} : (S ⊨ᵇ insert f T) = ((S ⊨ᵇ f : β) ⊓ (S ⊨ᵇ T : β) : β) :=
-- begin
-- refine ⟨by apply all_boolean_realize_sentence_axm, _⟩, intro H,
-- rcases H with ⟨Hf, HT⟩, intros g Hg, rcases Hg with ⟨Hg1, Hg2⟩,
-- exact Hf, exact HT Hg
-- end
-- @[simp] lemma all_boolean_realize_sentence_singleton {f : sentence L} : S ⊨ᵇ {f} = S ⊨ᵇ f :=
-- ⟨by{intro H, apply H, exact or.inl rfl}, by {intros H g Hg, repeat{cases Hg}, assumption}⟩
variable (β)
def forced (T : Theory L) (f : sentence L) :=
∀{{S : bStructure L β}}, nonempty S → (⨅(f ∈ T), ⟦f⟧[S]) ⊩[S] f
variable {β}
notation T ` ⊨[`:51 β`] `:0 f := fol.forced β T f -- input using \|= or \vDash, but not using \bModels
def bsatisfied_of_forced {T : Theory L} {f : sentence L} (H : T ⊨[β] f) : T.fst ⊨ᵤ[β] f.fst :=
begin
intros S v, rw [boolean_realize_sentence_eq],
refine le_trans _ (H ⟨v 0⟩),
rw [le_infi_iff], intro f, rw [le_infi_iff], intro hf,
refine le_trans (infi_le _ f.fst) _,
refine le_trans (infi_le _ (mem_image_of_mem _ hf)) _,
apply le_of_eq, rw [boolean_realize_sentence_eq]
end
def forced_of_bsatisfied {T : Theory L} {f : sentence L} (H : T.fst ⊨ᵤ[β] f.fst) : T ⊨[β] f :=
begin
intros S hS, induction hS with s, dsimp [forced_in],
rw [←boolean_realize_sentence_eq (λ _, s)],
refine le_trans _ (H S (λ _, s)),
rw [le_infi_iff], intro f', rw [le_infi_iff], intro hf',
rcases hf' with ⟨f', ⟨hf', rfl⟩⟩, rw [boolean_realize_sentence_eq],
refine le_trans (infi_le _ f') (infi_le _ hf')
end
@[simp]lemma inf_axioms_top_of_models {S : bStructure L β} {T : Theory L} (H : ⊤ ⊩[S] T) :
(⨅(f ∈ T), ⟦f⟧[S]) = ⊤ :=
by {apply top_unique, from le_trans H (by refl)}
lemma forced_absurd {S : bStructure L β} {T : Theory L} {f : sentence L} {Γ : β} (H₁ : Γ ⊩[S] f) (H₂ : Γ ⊩[S] ∼f) : Γ ⊩[S] bd_falsum :=
begin
change Γ ≤ _, apply le_trans' H₁, apply le_trans,
apply inf_le_inf, from H₂, refl, simp
end
--infix ` ⊨ᵇ `:51 := fol.forced -- input using \|= or \vDash, but not using \bModels
-- def all_forced (T T' : Theory L) := ∀(f ∈ T'), T ⊨ᵇ f
-- infix ` ⊨ᵇ `:51 := fol.all_ssatisfied -- input using \|= or \vDash, but not using \bModels
-- def ssatisfied_snot {f : sentence L} (hS : ¬(S ⊨ᵇ f)) : S ⊨ᵇ ∼ f :=
-- by exact hS
variable (β)
def bModel (T : Theory L) : Type* := Σ' (S : bStructure.{u v} L β), ⊤ ⊩[S] T
variable {β}
-- @[reducible] def bModel_ssatisfied {T : Theory L} (M : bModel β T) (ψ : sentence L) := M.fst ⊨ᵇ ψ
-- infix ` ⊨ᵇ `:51 := fol.bModel_ssatisfied -- input using \|= or \vDash, but not using \bModels
-- @[simp] lemma false_of_bModel_absurd {T : Theory L} (M : bModel β T) {ψ : sentence L} (h : M ⊨ᵇ ψ) (h' : M ⊨ᵇ ∼ψ) : false :=
-- by {unfold bModel_ssatisfied at *, simp[*,-h'] at h', exact h'}
theorem boolean_soundness {T : Theory L} {A : sentence L} (H : T ⊢ A) : T ⊨[β] A :=
forced_of_bsatisfied $ boolean_formula_soundness H
lemma unprovable_of_model_neg {T : Theory L} {f : sentence L} (S : bStructure L β) (H_model : ⊤ ⊩[S] T) [H_nonempty : nonempty S]
{Γ : β} (H_nonzero : (⊥ : β) < Γ) (H : Γ ⊩[S] ∼f) : ¬ (T ⊢' f) :=
begin
intro Hp, refine absurd H_nonzero (not_lt_of_le (forced_absurd _ H : Γ ⊩[S] (bd_falsum))),
from T, have := boolean_soundness (sprovable_of_provable (classical.choice Hp)) H_nonempty,
rw inf_axioms_top_of_models at this, from le_trans le_top ‹_›, from ‹_›
end
lemma boolean_realize_subst_preterm {n l} (t : bounded_preterm L (n+1) l)
(xs : dvector S l) (s : closed_term L) (v : dvector S n) :
boolean_realize_bounded_term v (substmax_bounded_term t s) xs =
boolean_realize_bounded_term (v.concat (boolean_realize_closed_term S s)) t xs :=
begin
induction t,
{ by_cases h : t.1 < n,
{ rw [substmax_var_lt t s h], dsimp,
simp only [dvector.map_nth, dvector.concat_nth _ _ _ _ h, dvector.nth'], },
{ have h' := le_antisymm (le_of_lt_succ t.2) (le_of_not_gt h), simp [h', dvector.nth'],
rw [substmax_var_eq t s h'],
apply boolean_realize_bounded_term_irrel, simp }},
{ refl },
{ dsimp, rw [substmax_bounded_term_bd_app], dsimp, rw [t_ih_s ([]), t_ih_t] }
end
lemma boolean_realize_subst_term {n} (v : dvector S n) (s : closed_term L)
(t : bounded_term L (n+1)) :
boolean_realize_bounded_term v (substmax_bounded_term t s) ([]) =
boolean_realize_bounded_term (v.concat (boolean_realize_closed_term S s)) t ([]) :=
by apply boolean_realize_subst_preterm t ([]) s v
lemma boolean_realize_sentence_bd_alls {f : bounded_formula L n} {S : bStructure L β} :
boolean_realize_sentence S (bd_alls n f) =
⨅ xs : dvector S n, boolean_realize_bounded_formula xs f ([]) :=
begin
induction n,
{ simp [-alls'_alls], apply le_antisymm,
{ rw [le_infi_iff], intro xs, cases xs, refl },
{ exact infi_le _ ([]) }},
{ rw [bd_alls, n_ih], --have := @n_ih (∀' f),
apply le_antisymm,
{ rw [le_infi_iff], intro xs, cases xs with _ x xs,
refine le_trans (infi_le _ xs) _,
exact infi_le _ x },
{ rw [le_infi_iff], intro xs, rw [boolean_realize_bounded_formula, le_infi_iff], intro x,
exact infi_le _ (x::xs) }}
end
end bfol
section consis_lemma
variables {L : Language} {β : Type u}
lemma consis_of_exists_bmodel [nontrivial_complete_boolean_algebra β] {T : Theory L} {S : bStructure L β} [h_nonempty : nonempty S] (H : ⊤ ⊩[S] T) :
is_consistent T :=
begin
intro H_inconsis,
suffices forces_false : ⊤ ⊩[S] bd_falsum,
from absurd (nontrivial.bot_lt_top) (not_lt_of_le forces_false),
convert (boolean_soundness (classical.choice H_inconsis) (h_nonempty)),
finish
end
end consis_lemma
variables {β : Type*} [complete_boolean_algebra β]
@[simp] lemma subst0_bounded_formula_not {L : Language} {n} (f : bounded_formula L (n+1))
(s : bounded_term L n) : (∼f)[s/0] = ∼(f[s/0]) :=
by { ext, simp [bd_not] }
@[simp] lemma subst0_bounded_formula_and {L : Language} {n} (f g : bounded_formula L (n+1))
(s : bounded_term L n) : (f ⊓ g)[s/0] = (f[s/0] ⊓ g[s/0]) :=
by { ext, simp[bd_and, bd_not] }
-- --TODO(floris)
-- lemma realize_subst_bt {L : Language} {S : bStructure L β} : ∀{n n' l}
-- (t : bounded_preterm L (n+n'+1) l)
-- (s : bounded_term L n') (v : dvector S n) (v' : dvector S n') (v'' : dvector S l),
-- boolean_realize_bounded_term ((v.append v').cast (add_comm n' n))
-- (subst_bounded_term t s) v'' =
-- boolean_realize_bounded_term
-- (((v.concat $ boolean_realize_bounded_term v' s ([])).append v').cast $
-- (by simp only [add_comm, add_right_inj, add_left_comm])) t v'' :=
-- begin
-- intros, induction t,
-- { apply decidable.lt_by_cases t.1 n; intro h, simp [h, subst_bounded_term], repeat {sorry} },
-- { sorry },
-- { sorry },
-- end
-- lemma realize_subst_bf {L : Language} {S : bStructure L β} : ∀{n n' n'' l}
-- (f : bounded_preformula L n'' l)
-- (s : bounded_term L n') (v : dvector S n) (v' : dvector S n') (v'' : dvector S l)
-- (h : n+n'+1 = n''),
-- boolean_realize_bounded_formula ((v.append v').cast (add_comm n' n))
-- (subst_bounded_formula f s h) v'' =
-- boolean_realize_bounded_formula
-- (((v.concat $ boolean_realize_bounded_term v' s ([])).append v').cast $
-- eq.trans (by simp only [add_comm, add_right_inj, add_left_comm]) h) f v'' :=
-- begin
-- intros, induction f generalizing n n'; induction h,
-- { refl },
-- { simp [realize_subst_bt] },
-- { refl },
-- { simp [realize_subst_bt, f_ih] },
-- { simp [f_ih_f₁, f_ih_f₂], },
-- { simp, congr, ext, sorry /-have := f_ih ([]) s v,-/ },
-- end
-- lemma realize_subst0_bf {L : Language} {n} (f : bounded_formula L (n+1)) (t : bounded_term L n)
-- {S : bStructure L β} (v : dvector S n) :
-- boolean_realize_bounded_formula v (f[t/0]) ([]) =
-- boolean_realize_bounded_formula (boolean_realize_bounded_term v t ([])::v) f ([]) :=
-- by { convert realize_subst_bf f t ([]) v ([]) _ using 1, simp [subst0_bounded_formula], refl }
-- lemma realize_substmax_bf {L : Language} {n} (f : bounded_formula L (n+1)) (t : closed_term L)
-- {S : bStructure L β} (v : dvector S n) :
-- boolean_realize_bounded_formula v (substmax_bounded_formula f t) ([]) =
-- boolean_realize_bounded_formula (v.concat $ boolean_realize_closed_term S t) f ([]) :=
-- by { convert realize_subst_bf f t v ([]) ([]) _, rw [cast_append_nil], simp, }
lemma boolean_realize_bounded_formula_insert_lift {L : Language} {S : bStructure L β}
{n l} (v : dvector S n) (x : S) (m : ℕ) (hm : m ≤ n)
(f : bounded_preformula L n l) (xs : dvector S l) :
boolean_realize_bounded_formula (v.insert x m) (f ↑' 1 # m) xs =
boolean_realize_bounded_formula v f xs :=
begin
rw [boolean_realize_bounded_formula_eq' x, boolean_realize_bounded_formula_eq' x], simp,
convert boolean_realize_formula_subst_lift _ x _ _ _, ext k,
by_cases hk : k < n + 1,
{ simp [hk],
apply decidable.lt_by_cases m k; intro hm'; simp [hm'],
{ have hk2 : k - 1 < n, from (nat.sub_lt_right_iff_lt_add (nat.one_le_of_lt hm')).mpr hk,
simp [hk2] },
have hk2 : k < n, from lt_of_lt_of_le hm' hm,
simp [hk2, dvector.insert_nth_lt x v hk2 hk hm'] },
{ have h2 : ¬k - 1 < n, from mt nat.lt_add_of_sub_lt_right hk,
have h3 : m < k, from lt_of_le_of_lt hm (lt_of_not_ge $ mt nat.lt_succ_of_le hk),
simp [hk, h2, h3] }
end
@[simp] lemma boolean_realize_formula_insert_lift2 {L : Language} {S : bStructure L β}
{n} (v : dvector S n) (x y z : S) (f : bounded_formula L (n+2)) :
boolean_realize_bounded_formula (x :: y :: z :: v) (f ↑' 1 # 2) ([]) =
boolean_realize_bounded_formula (x :: y :: v) f ([]) :=
by { convert boolean_realize_bounded_formula_insert_lift _ z 2 (le_add_left (le_refl 2)) f ([]),
simp }
lemma boolean_realize_subst_formula0 {L : Language} {n} (S : bStructure L β) [nonempty S]
(f : bounded_formula L (n+1)) (t : bounded_term L n) (v : dvector S n) :
boolean_realize_bounded_formula v (f[t/0]) ([]) =
boolean_realize_bounded_formula (boolean_realize_bounded_term v t ([])::v) f ([]) :=
begin
have := _inst_2, cases this with y, rw [boolean_realize_bounded_formula_eq' y, boolean_realize_bounded_formula_eq' y, boolean_realize_bounded_term_eq' y], simp,
convert (boolean_realize_formula_subst0 _ _ _ _).symm, ext k,
simp [subst_realize, not_lt_zero],
by_cases hk : k < n + 1,
{ cases k with k,
{ simp },
{ have h2k : k < n, from lt_of_succ_lt_succ hk,
simp [hk, h2k] }},
{ have h2k : 0 < k, from lt_of_lt_of_le (zero_lt_succ n) (le_of_not_gt hk),
have h3k : ¬k - 1 < n, from mt nat.lt_add_of_sub_lt_right hk,
simp [hk, h2k, h3k] }
end
end fol
-- #exit
-- lemma boolean_realize_subst_formula (S : bStructure L β) {n} (f : bounded_formula L (n+1))
-- (t : closed_term L) (v : dvector S n) :
-- boolean_realize_bounded_formula v (substmax_bounded_formula f t) ([]) =
-- boolean_realize_bounded_formula (v.concat (boolean_realize_closed_term S t)) f ([]) :=
-- begin
-- revert n f v, refine bounded_formula.rec1 _ _ _ _ _; intros,
-- { simp },
-- {sorry},
-- { rw [substmax_bounded_formula_bd_apps_rel, boolean_realize_bounded_formula_bd_apps_rel,
-- boolean_realize_bounded_formula_bd_apps_rel],
-- simp [ts.map_congr (realize_subst_term _ _)], sorry },
-- {sorry
-- -- apply imp_congr, apply ih₁ v, apply ih₂ v
-- },
-- { simp, apply congr_arg infi; apply funext, intro x, apply ih (x::v) }
-- end
-- /-- Given a bModel M ⊨ᵇ T with M ⊨ᵇ ¬ ψ, ¬ T ⊨ᵇ ψ--/
-- @[simp] lemma not_satisfied_of_bModel_not {T : Theory L} {ψ : sentence L} (M : bModel β T) (hM : M ⊨ᵇ ∼ψ) (h_nonempty : nonempty M.fst): ¬ T ⊨ᵇ ψ :=
-- begin
-- intro H, suffices : M ⊨ᵇ ψ, exact false_of_bModel_absurd M this hM,
-- exact H h_nonempty M.snd
-- end
-- --infix ` ⊨ᵇ `:51 := fol.ssatisfied -- input using \|= or \vDash, but not using \bModels
-- /- consistent theories -/
-- def is_consistent (T : Theory L) := ¬(T ⊢' (⊥ : sentence L))
-- protected def is_consistent.intro {T : Theory L} (H : ¬ T ⊢' (⊥ : sentence L)) : is_consistent T :=
-- H
-- protected def is_consistent.elim {T : Theory L} (H : is_consistent T) : ¬ T ⊢' (⊥ : sentence L)
-- | H' := H H'
-- lemma consis_not_of_not_provable {L} {T : Theory L} {f : sentence L} :
-- ¬ T ⊢' f → is_consistent (T ∪ {∼f}) :=
-- begin
-- intros h₁ h₂, cases h₂ with h₂, simp only [*, set.union_singleton] at h₂,
-- apply h₁, exact ⟨sfalsumE h₂⟩
-- end
-- /- complete theories -/
-- def is_complete (T : Theory L) :=
-- is_consistent T ∧ ∀(f : sentence L), f ∈ T ∨ ∼ f ∈ T
-- def mem_of_sprf {T : Theory L} (H : is_complete T) {f : sentence L} (Hf : T ⊢ f) : f ∈ T :=
-- begin
-- cases H.2 f, exact h, exfalso, apply H.1, constructor, refine impE _ _ Hf, apply saxm h
-- end
-- def mem_of_sprovable {T : Theory L} (H : is_complete T) {f : sentence L} (Hf : T ⊢' f) : f ∈ T :=
-- by destruct Hf; exact mem_of_sprf H
-- def sprovable_of_sprovable_or {T : Theory L} (H : is_complete T) {f₁ f₂ : sentence L}
-- (H₂ : T ⊢' f₁ ⊔ f₂) : (T ⊢' f₁) ∨ T ⊢' f₂ :=
-- begin
-- cases H.2 f₁ with h h, { left, exact ⟨saxm h⟩ },
-- cases H.2 f₂ with h' h', { right, exact ⟨saxm h'⟩ },
-- exfalso, destruct H₂, intro H₂, apply H.1, constructor,
-- apply orE H₂; refine impE _ _ axm1; apply weakening1; apply axm;
-- [exact mem_image_of_mem _ h, exact mem_image_of_mem _ h']
-- end
-- def impI_of_is_complete {T : Theory L} (H : is_complete T) {f₁ f₂ : sentence L}
-- (H₂ : T ⊢' f₁ → T ⊢' f₂) : T ⊢' f₁ ⟹ f₂ :=
-- begin
-- apply impI', cases H.2 f₁,
-- { apply weakening1', apply H₂, exact ⟨saxm h⟩ },
-- apply falsumE', apply weakening1',
-- apply impE' _ (weakening1' ⟨by apply saxm h⟩) ⟨axm1⟩
-- end
-- def notI_of_is_complete {T : Theory L} (H : is_complete T) {f : sentence L}
-- (H₂ : ¬T ⊢' f) : T ⊢' ∼f :=
-- begin
-- apply @impI_of_is_complete _ T H f ⊥,
-- intro h, exfalso, exact H₂ h
-- end
-- def has_enough_constants (T : Theory L) :=
-- ∃(C : Π(f : bounded_formula L 1), L.constants),
-- ∀(f : bounded_formula L 1), T ⊢' ∃' f ⟹ f[bd_const (C f)/0]
-- lemma has_enough_constants.intro {L : Language} (T : Theory L)
-- (H : ∀(f : bounded_formula L 1), ∃ c : L.constants, T ⊢' ∃' f ⟹ f[bd_const c/0]) :
-- has_enough_constants T :=
-- classical.axiom_of_choice H
-- def find_counterexample_of_henkin {T : Theory L} (H₁ : is_complete T) (H₂ : has_enough_constants T)
-- (f : bounded_formula L 1) (H₃ : ¬ T ⊢' ∀' f) : ∃(t : closed_term L), T ⊢' ∼ f[t/0] :=
-- begin
-- induction H₂ with C HC,
-- refine ⟨bd_const (C (∼ f)), _⟩, dsimp [sprovable] at HC,
-- apply (HC _).map2 (impE _),
-- apply nonempty.map ex_not_of_not_all, apply notI_of_is_complete H₁ H₃
-- end
-- variables (T : Theory L) (H₁ : is_complete T) (H₂ : has_enough_constants T)
-- def term_rel (t₁ t₂ : closed_term L) : β := T ⊢' t₁ ≃ t₂
-- def term_setoid : setoid $ closed_term L :=
-- ⟨term_rel T, λt, ⟨ref _ _⟩, λt t' H, H.map symm, λt₁ t₂ t₃ H₁ H₂, H₁.map2 trans H₂⟩
-- local attribute [instance] term_setoid
-- def term_bModel' : Type u :=
-- quotient $ term_setoid T
-- -- set_option pp.all true
-- -- #print term_setoid
-- -- set_option trace.class_instances true
-- def term_bModel_fun' {l} (t : closed_preterm L l) (ts : dvector (closed_term L) l) : term_bModel' T :=
-- @quotient.mk _ (term_setoid T) $ bd_apps t ts
-- -- def equal_preterms_trans {T : set (formula L)} : ∀{l} {t₁ t₂ t₃ : preterm L l}
-- -- (h₁₂ : equal_preterms T t₁ t₂) (h₂₃ : equal_preterms T t₂ t₃), equal_preterms T t₁ t₃
-- variable {T}
-- def term_bModel_fun_eq {l} (t t' : closed_preterm L (l+1)) (x x' : closed_term L)
-- (Ht : equal_preterms T.fst t.fst t'.fst) (Hx : T ⊢ x ≃ x') (ts : dvector (closed_term L) l) :
-- term_bModel_fun' T (bd_app t x) ts = term_bModel_fun' T (bd_app t' x') ts :=
-- begin
-- induction ts generalizing x x',
-- { apply quotient.sound, refine ⟨trans (app_congr t.fst Hx) _⟩, apply Ht ([x'.fst]) },
-- { apply ts_ih, apply equal_preterms_app Ht Hx, apply ref }
-- end
-- variable (T)
-- def term_bModel_fun {l} (t : closed_preterm L l) (ts : dvector (term_bModel' T) l) : term_bModel' T :=
-- begin
-- refine ts.quotient_lift (term_bModel_fun' T t) _, clear ts,
-- intros ts ts' hts,
-- induction hts,
-- { refl },
-- { apply (hts_ih _).trans, induction hts_hx with h, apply term_bModel_fun_eq,
-- refl, exact h }
-- end
-- def term_bModel_rel' {l} (f : presentence L l) (ts : dvector (closed_term L) l) : β :=
-- T ⊢' bd_apps_rel f ts
-- variable {T}
-- def term_bModel_rel_iff {l} (f f' : presentence L (l+1)) (x x' : closed_term L)
-- (Ht : equiv_preformulae T.fst f.fst f'.fst) (Hx : T ⊢ x ≃ x') (ts : dvector (closed_term L) l) :
-- term_bModel_rel' T (bd_apprel f x) ts = term_bModel_rel' T (bd_apprel f' x') ts :=
-- begin
-- induction ts generalizing x x',
-- { apply iff.trans (apprel_congr' f.fst Hx),
-- apply iff_of_biimp, have := Ht ([x'.fst]), exact ⟨this⟩ },
-- { apply ts_ih, apply equiv_preformulae_apprel Ht Hx, apply ref }
-- end
-- variable (T)
-- def term_bModel_rel {l} (f : presentence L l) (ts : dvector (term_bModel' T) l) : β :=
-- begin
-- refine ts.quotient_lift (term_bModel_rel' T f) _, clear ts,
-- intros ts ts' hts,
-- induction hts,
-- { refl },
-- { apply (hts_ih _).trans, induction hts_hx with h, apply βext, apply term_bModel_rel_iff,
-- refl, exact h }
-- end
-- def term_bModel : bStructure L β :=
-- ⟨term_bModel' T,
-- λn, term_bModel_fun T ∘ bd_func,
-- λn, term_bModel_rel T ∘ bd_rel⟩
-- @[reducible] def term_mk : closed_term L → term_bModel β T :=
-- @quotient.mk _ $ term_setoid T
-- -- lemma realize_bounded_preterm_term_bModel {l n} (ts : dvector (closed_term L) l)
-- -- (t : bounded_preterm L l n) (ts' : dvector (closed_term L) n) :
-- -- boolean_realize_bounded_term (ts.map term_mk) t (ts'.map term_mk) =
-- -- (term_mk _) :=
-- -- begin
-- -- induction t with t ht,
-- -- sorry
-- -- end
-- variable {T}
-- lemma realize_closed_preterm_term_bModel {l} (ts : dvector (closed_term L) l) (t : closed_preterm L l) :
-- boolean_realize_bounded_term ([]) t (ts.map $ term_mk T) = (term_mk T (bd_apps t ts)) :=
-- begin
-- induction t,
-- { apply t.fin_zero_elim },
-- { apply dvector.quotient_beta },
-- { rw [boolean_realize_bounded_term_bd_app],
-- have := t_ih_s ([]), dsimp at this, rw this,
-- apply t_ih_t (t_s::ts) }
-- end
-- @[simp] lemma boolean_realize_closed_term_term_bModel (t : closed_term L) :
-- boolean_realize_closed_term (term_bModel β T) t = term_mk T t :=
-- by apply realize_closed_preterm_term_bModel ([]) t
-- /- below we try to do this directly using bounded_term.rec -/
-- -- begin
-- -- revert t, refine bounded_term.rec _ _; intros,
-- -- { apply k.fin_zero_elim },
-- -- --{ apply dvector.quotient_beta },
-- -- {
-- -- --exact dvector.quotient_beta _ _ ts,
-- -- rw [boolean_realize_bounded_term_bd_app],
-- -- have := t_ih_s ([]), dsimp at this, rw this,
-- -- apply t_ih_t (t_s::ts) }
-- -- end
-- lemma boolean_realize_subst_preterm {n l} (t : bounded_preterm L (n+1) l)
-- (xs : dvector S l) (s : closed_term L) (v : dvector S n) :
-- boolean_realize_bounded_term v (substmax_bounded_term t s) xs =
-- boolean_realize_bounded_term (v.concat (boolean_realize_closed_term S s)) t xs :=
-- begin
-- induction t,
-- { by_cases h : t.1 < n,
-- { rw [substmax_var_lt t s h], dsimp,
-- simp only [dvector.map_nth, dvector.concat_nth _ _ _ _ h, dvector.nth'], },
-- { have h' := le_antisymm (le_of_lt_succ t.2) (le_of_not_gt h), simp [h', dvector.nth'],
-- rw [substmax_var_eq t s h'],
-- apply boolean_realize_bounded_term_irrel, simp }},
-- { refl },
-- { dsimp, rw [substmax_bounded_term_bd_app], dsimp, rw [t_ih_s ([]), t_ih_t] }
-- end
-- lemma boolean_realize_subst_term {n} (v : dvector S n) (s : closed_term L)
-- (t : bounded_term L (n+1)) :
-- boolean_realize_bounded_term v (substmax_bounded_term t s) ([]) =
-- boolean_realize_bounded_term (v.concat (boolean_realize_closed_term S s)) t ([]) :=
-- by apply boolean_realize_subst_preterm t ([]) s v
-- lemma boolean_realize_subst_formula (S : bStructure L β) {n} (f : bounded_formula L (n+1))
-- (t : closed_term L) (v : dvector S n) :
-- boolean_realize_bounded_formula v (substmax_bounded_formula f t) ([]) =
-- boolean_realize_bounded_formula (v.concat (boolean_realize_closed_term S t)) f ([]) :=
-- begin
-- revert n f v, refine bounded_formula.rec1 _ _ _ _ _; intros,
-- { simp },
-- { apply eq.congr, exact realize_subst_term v t t₁, exact realize_subst_term v t t₂ },
-- { rw [substmax_bounded_formula_bd_apps_rel, boolean_realize_bounded_formula_bd_apps_rel,
-- boolean_realize_bounded_formula_bd_apps_rel],
-- simp [ts.map_congr (realize_subst_term _ _)] },
-- { apply imp_congr, apply ih₁ v, apply ih₂ v },
-- { simp, apply congr_arg infi; apply funext, intro x, apply ih (x::v) }
-- end
-- lemma boolean_realize_subst_formula0 (S : bStructure L β) (f : bounded_formula L 1) (t : closed_term L) :
-- S ⊨ᵇ f[t/0] = boolean_realize_bounded_formula ([boolean_realize_closed_term S t]) f ([]) :=
-- iff.trans (by rw [substmax_eq_subst0_formula]) (by apply boolean_realize_subst_formula S f t ([]))
-- lemma term_bModel_subst0 (f : bounded_formula L 1) (t : closed_term L) :
-- term_bModel β T ⊨ᵇ f[t/0] = boolean_realize_bounded_formula ([term_mk T t]) f ([]) :=
-- (boolean_realize_subst_formula0 (term_bModel β T) f t).trans (by simp)
-- include H₂
-- instance nonempty_term_bModel : nonempty $ term_bModel β T :=
-- begin
-- induction H₂ with C, exact ⟨term_mk T (bd_const (C (&0 ≃ &0)))⟩
-- end
-- include H₁
-- def term_bModel_ssatisfied_iff {n} : ∀{l} (f : presentence L l)
-- (ts : dvector (closed_term L) l) (h : count_quantifiers f.fst < n),
-- T ⊢' bd_apps_rel f ts = term_bModel β T ⊨ᵇ bd_apps_rel f ts :=
-- begin
-- refine nat.strong_induction_on n _, clear n,
-- intros n n_ih l f ts hn,
-- have : {f' : preformula L l // f.fst = f' } := ⟨f.fst, rfl⟩,
-- cases this with f' hf, induction f'; cases f; injection hf with hf₁ hf₂,
-- { simp, exact H₁.1.elim },
-- { simp, refine iff.trans _ (boolean_realize_sentence_equal f_t₁ f_t₂).symm, simp [term_mk], refl },
-- { refine iff.trans _ (boolean_realize_bd_apps_rel _ _).symm,
-- dsimp [term_bModel, term_bModel_rel],
-- rw [ts.map_congr boolean_realize_closed_term_term_bModel, dvector.quotient_beta], refl },
-- { apply f'_ih f_f (f_t::ts) _ hf₁, simp at hn ⊢, exact hn },
-- { have ih₁ := f'_ih_f₁ f_f₁ ([]) (lt_of_le_of_lt (nat.le_add_right _ _) hn) hf₁,
-- have ih₂ := f'_ih_f₂ f_f₂ ([]) (lt_of_le_of_lt (nat.le_add_left _ _) hn) hf₂, cases ts,
-- split; intro h,
-- { intro h₁, apply ih₂.mp, apply h.map2 (impE _), refine ih₁.mpr h₁ },
-- { simp at h, simp at ih₁, rw [←ih₁] at h, simp at ih₂, rw [←ih₂] at h,
-- exact impI_of_is_complete H₁ h }},
-- { cases ts, split; intro h,
-- { simp at h ⊢,
-- apply quotient.ind, intro t,
-- apply (term_bModel_subst0 f_f t).mp,
-- cases n with n, { exfalso, exact not_lt_zero _ hn },
-- refine (n_ih n (lt.base n) (f_f[t/0]) ([]) _).mp (h.map _),
-- simp, exact lt_of_succ_lt_succ hn,
-- rw [bd_apps_rel_zero, subst0_bounded_formula_fst],
-- exact allE₂ _ _ },
-- { apply classical.by_contradiction, intro H,
-- cases find_counterexample_of_henkin H₁ H₂ f_f H with t ht,
-- apply H₁.left, apply impE' _ ht,
-- cases n with n, { exfalso, exact not_lt_zero _ hn },
-- refine (n_ih n (lt.base n) (f_f[t/0]) ([]) _).mpr _,
-- { simp, exact lt_of_succ_lt_succ hn },
-- exact (term_bModel_subst0 f_f t).mpr (h (term_mk T t)) }},
-- end
-- def term_bModel_ssatisfied : term_bModel β T ⊨ᵇ T :=
-- begin
-- intros f hf, apply (term_bModel_ssatisfied_iff H₁ H₂ f ([]) (lt.base _)).mp, exact ⟨saxm hf⟩
-- end
-- -- completeness for complete theories with enough constants
-- lemma completeness' {f : sentence L} (H : T ⊨ᵇ f) : T ⊢' f :=
-- begin
-- apply (term_bModel_ssatisfied_iff H₁ H₂ f ([]) (lt.base _)).mpr,
-- apply H, exact fol.nonempty_term_bModel H₂,
-- apply term_bModel_ssatisfied H₁ H₂,
-- end
-- omit H₁ H₂
-- def Th (S : bStructure L β) : Theory L := { f : sentence L | S ⊨ᵇ f }
-- lemma boolean_realize_sentence_Th (S : bStructure L β) : S ⊨ᵇ Th S :=
-- λf hf, hf
-- lemma is_complete_Th (S : bStructure L β) (HS : nonempty S) : is_complete (Th S) :=
-- ⟨λH, by cases H; apply soundness H HS (boolean_realize_sentence_Th S), λ(f : sentence L), classical.em (S ⊨ᵇ f)⟩
-- def eliminates_quantifiers : Theory L → β :=
-- λ T, ∀ f ∈ T, ∃ f' , bounded_preformula.quantifier_free f' ∧ (T ⊢' f ⇔ f')
-- def L_empty : Language :=
-- ⟨λ _, empty, λ _, empty⟩
-- def T_empty (L : Language) : Theory L := ∅
-- @[reducible] def T_equality : Theory L_empty := T_empty L_empty
-- @[simp] lemma in_theory_iff_satisfied {L : Language} {f : sentence L} : f ∈ Th S = S ⊨ᵇ f :=
-- by refl
-- @[simp] lemma alls_all_commute {L : Language} (f : formula L) {k : ℕ} : (alls k ∀' f) = (∀' alls k f) := by {induction k, refl, dunfold alls, rw[k_ih]}
-- @[simp] lemma alls_succ_k {L : Language} (f : formula L) {k : ℕ} : alls (k + 1) f = ∀' alls k f := by constructor
|
6aff45c84989b76370c2d6279699e9cebc362503 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/logic/relation.lean | 538212cfc874f744110b91c535e9acecbb45728e | [
"Apache-2.0"
] | permissive | fpvandoorn/mathlib | b21ab4068db079cbb8590b58fda9cc4bc1f35df4 | b3433a51ea8bc07c4159c1073838fc0ee9b8f227 | refs/heads/master | 1,624,791,089,608 | 1,556,715,231,000 | 1,556,715,231,000 | 165,722,980 | 5 | 0 | Apache-2.0 | 1,552,657,455,000 | 1,547,494,646,000 | Lean | UTF-8 | Lean | false | false | 13,115 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
Transitive reflexive as well as reflexive closure of relations.
-/
import tactic.interactive tactic.mk_iff_of_inductive_prop logic.relator
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
namespace relation
section comp
variables {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop}
def comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃b, r a b ∧ p b c
local infixr ` ∘r ` : 80 := relation.comp
lemma comp_eq : r ∘r (=) = r :=
funext $ assume a, funext $ assume b, propext $ iff.intro
(assume ⟨c, h, eq⟩, eq ▸ h)
(assume h, ⟨b, h, rfl⟩)
lemma eq_comp : (=) ∘r r = r :=
funext $ assume a, funext $ assume b, propext $ iff.intro
(assume ⟨c, eq, h⟩, eq.symm ▸ h)
(assume h, ⟨a, rfl, h⟩)
lemma iff_comp {r : Prop → α → Prop} : (↔) ∘r r = r :=
have (↔) = (=), by funext a b; exact iff_eq_eq,
by rw [this, eq_comp]
lemma comp_iff {r : α → Prop → Prop} : r ∘r (↔) = r :=
have (↔) = (=), by funext a b; exact iff_eq_eq,
by rw [this, comp_eq]
lemma comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q :=
begin
funext a d, apply propext,
split,
exact assume ⟨c, ⟨b, hab, hbc⟩, hcd⟩, ⟨b, hab, c, hbc, hcd⟩,
exact assume ⟨b, hab, c, hbc, hcd⟩, ⟨c, ⟨b, hab, hbc⟩, hcd⟩
end
lemma flip_comp : flip (r ∘r p) = (flip p) ∘r (flip r) :=
begin
funext c a, apply propext,
split,
exact assume ⟨b, hab, hbc⟩, ⟨b, hbc, hab⟩,
exact assume ⟨b, hbc, hab⟩, ⟨b, hab, hbc⟩
end
end comp
protected def map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop :=
λc d, ∃a b, r a b ∧ f a = c ∧ g b = d
variables {r : α → α → Prop} {a b c d : α}
/-- `refl_trans_gen r`: reflexive transitive closure of `r` -/
inductive refl_trans_gen (r : α → α → Prop) (a : α) : α → Prop
| refl {} : refl_trans_gen a
| tail {b c} : refl_trans_gen b → r b c → refl_trans_gen c
attribute [refl] refl_trans_gen.refl
run_cmd tactic.mk_iff_of_inductive_prop `relation.refl_trans_gen `relation.refl_trans_gen.cases_tail_iff
/-- `refl_gen r`: reflexive closure of `r` -/
inductive refl_gen (r : α → α → Prop) (a : α) : α → Prop
| refl {} : refl_gen a
| single {b} : r a b → refl_gen b
run_cmd tactic.mk_iff_of_inductive_prop `relation.refl_gen `relation.refl_gen_iff
/-- `trans_gen r`: transitive closure of `r` -/
inductive trans_gen (r : α → α → Prop) (a : α) : α → Prop
| single {b} : r a b → trans_gen b
| tail {b c} : trans_gen b → r b c → trans_gen c
run_cmd tactic.mk_iff_of_inductive_prop `relation.trans_gen `relation.trans_gen_iff
attribute [refl] refl_gen.refl
lemma refl_gen.to_refl_trans_gen : ∀{a b}, refl_gen r a b → refl_trans_gen r a b
| a _ refl_gen.refl := by refl
| a b (refl_gen.single h) := refl_trans_gen.tail refl_trans_gen.refl h
namespace refl_trans_gen
@[trans] lemma trans (hab : refl_trans_gen r a b) (hbc : refl_trans_gen r b c) : refl_trans_gen r a c :=
begin
induction hbc,
case refl_trans_gen.refl { assumption },
case refl_trans_gen.tail : c d hbc hcd hac { exact hac.tail hcd }
end
lemma single (hab : r a b) : refl_trans_gen r a b :=
refl.tail hab
lemma head (hab : r a b) (hbc : refl_trans_gen r b c) : refl_trans_gen r a c :=
begin
induction hbc,
case refl_trans_gen.refl { exact refl.tail hab },
case refl_trans_gen.tail : c d hbc hcd hac { exact hac.tail hcd }
end
lemma cases_tail : refl_trans_gen r a b → b = a ∨ (∃c, refl_trans_gen r a c ∧ r c b) :=
(cases_tail_iff r a b).1
lemma head_induction_on
{P : ∀(a:α), refl_trans_gen r a b → Prop}
{a : α} (h : refl_trans_gen r a b)
(refl : P b refl)
(head : ∀{a c} (h' : r a c) (h : refl_trans_gen r c b), P c h → P a (h.head h')) :
P a h :=
begin
induction h generalizing P,
case refl_trans_gen.refl { exact refl },
case refl_trans_gen.tail : b c hab hbc ih {
apply ih,
show P b _, from head hbc _ refl,
show ∀a a', r a a' → refl_trans_gen r a' b → P a' _ → P a _, from assume a a' hab hbc, head hab _
}
end
lemma trans_induction_on
{P : ∀{a b : α}, refl_trans_gen r a b → Prop}
{a b : α} (h : refl_trans_gen r a b)
(ih₁ : ∀a, @P a a refl)
(ih₂ : ∀{a b} (h : r a b), P (single h))
(ih₃ : ∀{a b c} (h₁ : refl_trans_gen r a b) (h₂ : refl_trans_gen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) :
P h :=
begin
induction h,
case refl_trans_gen.refl { exact ih₁ a },
case refl_trans_gen.tail : b c hab hbc ih { exact ih₃ hab (single hbc) ih (ih₂ hbc) }
end
lemma cases_head (h : refl_trans_gen r a b) : a = b ∨ (∃c, r a c ∧ refl_trans_gen r c b) :=
begin
induction h using relation.refl_trans_gen.head_induction_on,
{ left, refl },
{ right, existsi _, split; assumption }
end
lemma cases_head_iff : refl_trans_gen r a b ↔ a = b ∨ (∃c, r a c ∧ refl_trans_gen r c b) :=
begin
split,
{ exact cases_head },
{ assume h,
rcases h with rfl | ⟨c, hac, hcb⟩,
{ refl },
{ exact head hac hcb } }
end
lemma total_of_right_unique (U : relator.right_unique r)
(ab : refl_trans_gen r a b) (ac : refl_trans_gen r a c) :
refl_trans_gen r b c ∨ refl_trans_gen r c b :=
begin
induction ab with b d ab bd IH,
{ exact or.inl ac },
{ rcases IH with IH | IH,
{ rcases cases_head IH with rfl | ⟨e, be, ec⟩,
{ exact or.inr (single bd) },
{ cases U bd be, exact or.inl ec } },
{ exact or.inr (IH.tail bd) } }
end
end refl_trans_gen
namespace trans_gen
lemma to_refl {a b} (h : trans_gen r a b) : refl_trans_gen r a b :=
begin
induction h with b h b c _ bc ab,
exact refl_trans_gen.single h,
exact refl_trans_gen.tail ab bc
end
@[trans] lemma trans_left (hab : trans_gen r a b) (hbc : refl_trans_gen r b c) : trans_gen r a c :=
begin
induction hbc,
case refl_trans_gen.refl : c hab { assumption },
case refl_trans_gen.tail : c d hbc hcd hac { exact hac.tail hcd }
end
@[trans] lemma trans (hab : trans_gen r a b) (hbc : trans_gen r b c) : trans_gen r a c :=
trans_left hab hbc.to_refl
lemma head' (hab : r a b) (hbc : refl_trans_gen r b c) : trans_gen r a c :=
trans_left (single hab) hbc
lemma tail' (hab : refl_trans_gen r a b) (hbc : r b c) : trans_gen r a c :=
begin
induction hab generalizing c,
case refl_trans_gen.refl : c hac { exact single hac },
case refl_trans_gen.tail : d b hab hdb IH { exact tail (IH hdb) hbc }
end
@[trans] lemma trans_right (hab : refl_trans_gen r a b) (hbc : trans_gen r b c) : trans_gen r a c :=
begin
induction hbc,
case trans_gen.single : c hbc { exact tail' hab hbc },
case trans_gen.tail : c d hbc hcd hac { exact hac.tail hcd }
end
lemma head (hab : r a b) (hbc : trans_gen r b c) : trans_gen r a c :=
head' hab hbc.to_refl
lemma tail'_iff : trans_gen r a c ↔ ∃ b, refl_trans_gen r a b ∧ r b c :=
begin
refine ⟨λ h, _, λ ⟨b, hab, hbc⟩, tail' hab hbc⟩,
cases h with _ hac b _ hab hbc,
{ exact ⟨_, by refl, hac⟩ },
{ exact ⟨_, hab.to_refl, hbc⟩ }
end
lemma head'_iff : trans_gen r a c ↔ ∃ b, r a b ∧ refl_trans_gen r b c :=
begin
refine ⟨λ h, _, λ ⟨b, hab, hbc⟩, head' hab hbc⟩,
induction h,
case trans_gen.single : c hac { exact ⟨_, hac, by refl⟩ },
case trans_gen.tail : b c hab hbc IH {
rcases IH with ⟨d, had, hdb⟩, exact ⟨_, had, hdb.tail hbc⟩ }
end
end trans_gen
section refl_trans_gen
open refl_trans_gen
lemma refl_trans_gen_iff_eq (h : ∀b, ¬ r a b) : refl_trans_gen r a b ↔ b = a :=
by rw [cases_head_iff]; simp [h, eq_comm]
lemma refl_trans_gen_iff_eq_or_trans_gen :
refl_trans_gen r a b ↔ b = a ∨ trans_gen r a b :=
begin
refine ⟨λ h, _, λ h, _⟩,
{ cases h with c _ hac hcb,
{ exact or.inl rfl },
{ exact or.inr (trans_gen.tail' hac hcb) } },
{ rcases h with rfl | h, {refl}, {exact h.to_refl} }
end
lemma refl_trans_gen_lift {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀a b, r a b → p (f a) (f b)) (hab : refl_trans_gen r a b) : refl_trans_gen p (f a) (f b) :=
hab.trans_induction_on (assume a, refl) (assume a b, refl_trans_gen.single ∘ h _ _) (assume a b c _ _, trans)
lemma refl_trans_gen_mono {p : α → α → Prop} :
(∀a b, r a b → p a b) → refl_trans_gen r a b → refl_trans_gen p a b :=
refl_trans_gen_lift id
lemma refl_trans_gen_eq_self (refl : reflexive r) (trans : transitive r) :
refl_trans_gen r = r :=
funext $ λ a, funext $ λ b, propext $
⟨λ h, begin
induction h with b c h₁ h₂ IH, {apply refl},
exact trans IH h₂,
end, single⟩
lemma reflexive_refl_trans_gen : reflexive (refl_trans_gen r) :=
assume a, refl
lemma transitive_refl_trans_gen : transitive (refl_trans_gen r) :=
assume a b c, trans
lemma refl_trans_gen_idem :
refl_trans_gen (refl_trans_gen r) = refl_trans_gen r :=
refl_trans_gen_eq_self reflexive_refl_trans_gen transitive_refl_trans_gen
lemma refl_trans_gen_lift' {p : β → β → Prop} {a b : α} (f : α → β)
(h : ∀a b, r a b → refl_trans_gen p (f a) (f b)) (hab : refl_trans_gen r a b) : refl_trans_gen p (f a) (f b) :=
by simpa [refl_trans_gen_idem] using refl_trans_gen_lift f h hab
lemma refl_trans_gen_closed {p : α → α → Prop} :
(∀ a b, r a b → refl_trans_gen p a b) → refl_trans_gen r a b → refl_trans_gen p a b :=
refl_trans_gen_lift' id
end refl_trans_gen
def join (r : α → α → Prop) : α → α → Prop := λa b, ∃c, r a c ∧ r b c
section join
open refl_trans_gen refl_gen
lemma church_rosser
(h : ∀a b c, r a b → r a c → ∃d, refl_gen r b d ∧ refl_trans_gen r c d)
(hab : refl_trans_gen r a b) (hac : refl_trans_gen r a c) : join (refl_trans_gen r) b c :=
begin
induction hab,
case refl_trans_gen.refl { exact ⟨c, hac, refl⟩ },
case refl_trans_gen.tail : d e had hde ih {
clear hac had a,
rcases ih with ⟨b, hdb, hcb⟩,
have : ∃a, refl_trans_gen r e a ∧ refl_gen r b a,
{ clear hcb, induction hdb,
case refl_trans_gen.refl { exact ⟨e, refl, refl_gen.single hde⟩ },
case refl_trans_gen.tail : f b hdf hfb ih {
rcases ih with ⟨a, hea, hfa⟩,
cases hfa with _ hfa,
{ exact ⟨b, hea.tail hfb, refl_gen.refl⟩ },
{ rcases h _ _ _ hfb hfa with ⟨c, hbc, hac⟩,
exact ⟨c, hea.trans hac, hbc⟩ } } },
rcases this with ⟨a, hea, hba⟩, cases hba with _ hba,
{ exact ⟨b, hea, hcb⟩ },
{ exact ⟨a, hea, hcb.tail hba⟩ } }
end
lemma join_of_single (h : reflexive r) (hab : r a b) : join r a b :=
⟨b, hab, h b⟩
lemma symmetric_join : symmetric (join r) :=
assume a b ⟨c, hac, hcb⟩, ⟨c, hcb, hac⟩
lemma reflexive_join (h : reflexive r) : reflexive (join r) :=
assume a, ⟨a, h a, h a⟩
lemma transitive_join (ht : transitive r) (h : ∀a b c, r a b → r a c → join r b c) :
transitive (join r) :=
assume a b c ⟨x, hax, hbx⟩ ⟨y, hby, hcy⟩,
let ⟨z, hxz, hyz⟩ := h b x y hbx hby in
⟨z, ht hax hxz, ht hcy hyz⟩
lemma equivalence_join (hr : reflexive r) (ht : transitive r) (h : ∀a b c, r a b → r a c → join r b c) :
equivalence (join r) :=
⟨reflexive_join hr, symmetric_join, transitive_join ht h⟩
lemma equivalence_join_refl_trans_gen
(h : ∀a b c, r a b → r a c → ∃d, refl_gen r b d ∧ refl_trans_gen r c d) :
equivalence (join (refl_trans_gen r)) :=
equivalence_join reflexive_refl_trans_gen transitive_refl_trans_gen (assume a b c, church_rosser h)
lemma join_of_equivalence {r' : α → α → Prop} (hr : equivalence r)
(h : ∀a b, r' a b → r a b) : join r' a b → r a b
| ⟨c, hac, hbc⟩ := hr.2.2 (h _ _ hac) (hr.2.1 $ h _ _ hbc)
lemma refl_trans_gen_of_transitive_reflexive {r' : α → α → Prop} (hr : reflexive r) (ht : transitive r)
(h : ∀a b, r' a b → r a b) (h' : refl_trans_gen r' a b) : r a b :=
begin
induction h' with b c hab hbc ih,
{ exact hr _ },
{ exact ht ih (h _ _ hbc) }
end
lemma refl_trans_gen_of_equivalence {r' : α → α → Prop} (hr : equivalence r) :
(∀a b, r' a b → r a b) → refl_trans_gen r' a b → r a b :=
refl_trans_gen_of_transitive_reflexive hr.1 hr.2.2
end join
section eqv_gen
lemma eqv_gen_iff_of_equivalence (h : equivalence r) : eqv_gen r a b ↔ r a b :=
iff.intro
begin
assume h,
induction h,
case eqv_gen.rel { assumption },
case eqv_gen.refl { exact h.1 _ },
case eqv_gen.symm { apply h.2.1, assumption },
case eqv_gen.trans : a b c _ _ hab hbc { exact h.2.2 hab hbc }
end
(eqv_gen.rel a b)
lemma eqv_gen_mono {r p : α → α → Prop}
(hrp : ∀a b, r a b → p a b) (h : eqv_gen r a b) : eqv_gen p a b :=
begin
induction h,
case eqv_gen.rel : a b h { exact eqv_gen.rel _ _ (hrp _ _ h) },
case eqv_gen.refl : { exact eqv_gen.refl _ },
case eqv_gen.symm : a b h ih { exact eqv_gen.symm _ _ ih },
case eqv_gen.trans : a b c ih1 ih2 hab hbc { exact eqv_gen.trans _ _ _ hab hbc }
end
end eqv_gen
end relation
|
07f5fbe5003aebf5fcacd6bc55c514c094ed7dbc | 95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990 | /src/group_theory/free_abelian_group.lean | f0d2e9a97c03c8917204184dc50abd86f124e4b8 | [
"Apache-2.0"
] | permissive | uniformity1/mathlib | 829341bad9dfa6d6be9adaacb8086a8a492e85a4 | dd0e9bd8f2e5ec267f68e72336f6973311909105 | refs/heads/master | 1,588,592,015,670 | 1,554,219,842,000 | 1,554,219,842,000 | 179,110,702 | 0 | 0 | Apache-2.0 | 1,554,220,076,000 | 1,554,220,076,000 | null | UTF-8 | Lean | false | false | 8,358 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Free abelian groups as abelianization of free groups.
-/
import algebra.pi_instances
import group_theory.free_group
import group_theory.abelianization
universes u v
variables (α : Type u)
def free_abelian_group : Type u :=
additive $ abelianization $ free_group α
instance : add_comm_group (free_abelian_group α) :=
@additive.add_comm_group _ $ abelianization.comm_group _
variable {α}
namespace free_abelian_group
def of (x : α) : free_abelian_group α :=
abelianization.of $ free_group.of x
def lift {β : Type v} [add_comm_group β] (f : α → β) (x : free_abelian_group α) : β :=
@abelianization.lift _ _ (multiplicative β) _ (@free_group.to_group _ (multiplicative β) _ f) _ x
namespace lift
variables {β : Type v} [add_comm_group β] (f : α → β)
open free_abelian_group
instance is_add_group_hom : is_add_group_hom (lift f) :=
⟨λ x y, @is_group_hom.mul _ (multiplicative β) _ _ _ (abelianization.lift.is_group_hom _) x y⟩
@[simp] protected lemma add (x y : free_abelian_group α) :
lift f (x + y) = lift f x + lift f y :=
is_add_group_hom.add _ _ _
@[simp] protected lemma neg (x : free_abelian_group α) : lift f (-x) = -lift f x :=
is_add_group_hom.neg _ _
@[simp] protected lemma sub (x y : free_abelian_group α) :
lift f (x - y) = lift f x - lift f y :=
by simp
@[simp] protected lemma zero : lift f 0 = 0 :=
is_add_group_hom.zero _
@[simp] protected lemma of (x : α) : lift f (of x) = f x :=
by unfold of; unfold lift; simp
protected theorem unique (g : free_abelian_group α → β) [is_add_group_hom g]
(hg : ∀ x, g (of x) = f x) {x} :
g x = lift f x :=
@abelianization.lift.unique (free_group α) _ (multiplicative β) _ _ _ g
⟨λ x y, @is_add_group_hom.add (additive $ abelianization (free_group α)) _ _ _ _ _ x y⟩ (λ x,
@free_group.to_group.unique α (multiplicative β) _ _ (g ∘ abelianization.of)
⟨λ m n, is_add_group_hom.add g (abelianization.of m) (abelianization.of n)⟩ hg _) _
protected theorem ext (g h : free_abelian_group α → β)
[is_add_group_hom g] [is_add_group_hom h]
(H : ∀ x, g (of x) = h (of x)) {x} :
g x = h x :=
(lift.unique (g ∘ of) g (λ _, rfl)).trans $
eq.symm $ lift.unique _ _ $ λ x, eq.symm $ H x
lemma map_hom {α β γ} [add_comm_group β] [add_comm_group γ]
(a : free_abelian_group α) (f : α → β) (g : β → γ) [is_add_group_hom g] :
g (a.lift f) = a.lift (g ∘ f) :=
show (g ∘ lift f) a = a.lift (g ∘ f),
begin
apply @lift.unique,
assume a,
simp only [(∘), lift.of]
end
def universal : (α → β) ≃ { f : free_abelian_group α → β // is_add_group_hom f } :=
{ to_fun := λ f, ⟨_, lift.is_add_group_hom f⟩,
inv_fun := λ f, f.1 ∘ of,
left_inv := λ f, funext $ λ x, lift.of f x,
right_inv := λ f, subtype.eq $ funext $ λ x, eq.symm $ by letI := f.2; from
lift.unique _ _ (λ _, rfl) }
end lift
local attribute [instance] quotient_group.left_rel normal_subgroup.to_is_subgroup
@[elab_as_eliminator]
protected theorem induction_on
{C : free_abelian_group α → Prop}
(z : free_abelian_group α)
(C0 : C 0)
(C1 : ∀ x, C $ of x)
(Cn : ∀ x, C (of x) → C (-of x))
(Cp : ∀ x y, C x → C y → C (x + y)) : C z :=
quotient.induction_on z $ λ x, quot.induction_on x $ λ L,
list.rec_on L C0 $ λ ⟨x, b⟩ tl ih,
bool.rec_on b (Cp _ _ (Cn _ (C1 x)) ih) (Cp _ _ (C1 x) ih)
instance is_add_group_hom_lift' {α} (β) [add_comm_group β] (a : free_abelian_group α) :
is_add_group_hom (λf, (a.lift f : β)) :=
begin
refine ⟨assume f g, free_abelian_group.induction_on a _ _ _ _⟩,
{ simp [is_add_group_hom.zero (free_abelian_group.lift f)] },
{ simp [lift.of], assume x, refl },
{ simp [is_add_group_hom.neg (free_abelian_group.lift f)],
assume x h, show - (f x + g x) = -f x + - g x, exact neg_add _ _ },
{ simp [is_add_group_hom.add (free_abelian_group.lift f)],
assume x y hx hy,
rw [hx, hy],
ac_refl }
end
variables {β : Type u}
instance : monad free_abelian_group.{u} :=
{ pure := λ α, of,
bind := λ α β x f, lift f x }
@[elab_as_eliminator]
protected theorem induction_on'
{C : free_abelian_group α → Prop}
(z : free_abelian_group α)
(C0 : C 0)
(C1 : ∀ x, C $ pure x)
(Cn : ∀ x, C (pure x) → C (-pure x))
(Cp : ∀ x y, C x → C y → C (x + y)) : C z :=
free_abelian_group.induction_on z C0 C1 Cn Cp
@[simp] lemma map_pure (f : α → β) (x : α) : f <$> (pure x : free_abelian_group α) = pure (f x) :=
lift.of _ _
@[simp] lemma map_zero (f : α → β) : f <$> (0 : free_abelian_group α) = 0 :=
lift.zero (of ∘ f)
@[simp] lemma map_add (f : α → β) (x y : free_abelian_group α) : f <$> (x + y) = f <$> x + f <$> y :=
lift.add _ _ _
@[simp] lemma map_neg (f : α → β) (x : free_abelian_group α) : f <$> (-x) = -(f <$> x) :=
lift.neg _ _
@[simp] lemma map_sub (f : α → β) (x y : free_abelian_group α) : f <$> (x - y) = f <$> x - f <$> y :=
lift.sub _ _ _
@[simp] lemma pure_bind (f : α → free_abelian_group β) (x) : pure x >>= f = f x :=
lift.of _ _
@[simp] lemma zero_bind (f : α → free_abelian_group β) : 0 >>= f = 0 :=
lift.zero f
@[simp] lemma add_bind (f : α → free_abelian_group β) (x y : free_abelian_group α) : x + y >>= f = (x >>= f) + (y >>= f) :=
lift.add _ _ _
@[simp] lemma neg_bind (f : α → free_abelian_group β) (x : free_abelian_group α) : -x >>= f = -(x >>= f) :=
lift.neg _ _
@[simp] lemma sub_bind (f : α → free_abelian_group β) (x y : free_abelian_group α) : x - y >>= f = (x >>= f) - (y >>= f) :=
lift.sub _ _ _
@[simp] lemma pure_seq (f : α → β) (x : free_abelian_group α) : pure f <*> x = f <$> x :=
pure_bind _ _
@[simp] lemma zero_seq (x : free_abelian_group α) : (0 : free_abelian_group (α → β)) <*> x = 0 :=
zero_bind _
@[simp] lemma add_seq (f g : free_abelian_group (α → β)) (x : free_abelian_group α) : f + g <*> x = (f <*> x) + (g <*> x) :=
add_bind _ _ _
@[simp] lemma neg_seq (f : free_abelian_group (α → β)) (x : free_abelian_group α) : -f <*> x = -(f <*> x) :=
neg_bind _ _
@[simp] lemma sub_seq (f g : free_abelian_group (α → β)) (x : free_abelian_group α) : f - g <*> x = (f <*> x) - (g <*> x) :=
sub_bind _ _ _
instance is_add_group_hom_seq (f : free_abelian_group (α → β)) : is_add_group_hom ((<*>) f) :=
⟨λ x y, show lift (<$> (x+y)) _ = _, by simp only [map_add]; exact
@@is_add_group_hom.add _ _ _ (@@free_abelian_group.is_add_group_hom_lift' (free_abelian_group β) _ _) _ _⟩
@[simp] lemma seq_zero (f : free_abelian_group (α → β)) : f <*> 0 = 0 :=
is_add_group_hom.zero _
@[simp] lemma seq_add (f : free_abelian_group (α → β)) (x y : free_abelian_group α) : f <*> (x + y) = (f <*> x) + (f <*> y) :=
is_add_group_hom.add _ _ _
@[simp] lemma seq_neg (f : free_abelian_group (α → β)) (x : free_abelian_group α) : f <*> (-x) = -(f <*> x) :=
is_add_group_hom.neg _ _
@[simp] lemma seq_sub (f : free_abelian_group (α → β)) (x y : free_abelian_group α) : f <*> (x - y) = (f <*> x) - (f <*> y) :=
is_add_group_hom.sub _ _ _
instance : is_lawful_monad free_abelian_group.{u} :=
{ id_map := λ α x, free_abelian_group.induction_on' x (map_zero id) (λ x, map_pure id x)
(λ x ih, by rw [map_neg, ih]) (λ x y ihx ihy, by rw [map_add, ihx, ihy]),
pure_bind := λ α β x f, pure_bind f x,
bind_assoc := λ α β γ x f g, free_abelian_group.induction_on' x
(by iterate 3 { rw zero_bind }) (λ x, by iterate 2 { rw pure_bind })
(λ x ih, by iterate 3 { rw neg_bind }; rw ih)
(λ x y ihx ihy, by iterate 3 { rw add_bind }; rw [ihx, ihy]) }
instance : is_comm_applicative free_abelian_group.{u} :=
{ commutative_prod := λ α β x y, free_abelian_group.induction_on' x
(by rw [map_zero, zero_seq, seq_zero])
(λ p, by rw [map_pure, pure_seq]; exact free_abelian_group.induction_on' y
(by rw [map_zero, map_zero, zero_seq])
(λ q, by rw [map_pure, map_pure, pure_seq, map_pure])
(λ q ih, by rw [map_neg, map_neg, neg_seq, ih])
(λ y₁ y₂ ih1 ih2, by rw [map_add, map_add, add_seq, ih1, ih2]))
(λ p ih, by rw [map_neg, neg_seq, seq_neg, ih])
(λ x₁ x₂ ih1 ih2, by rw [map_add, add_seq, seq_add, ih1, ih2]) }
end free_abelian_group
|
345fec71acdc54ec5e1e94e47607bb7caf5cda37 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/topology/algebra/infinite_sum.lean | 61f617ed4c481a01e41ee7c0b6c215724076646c | [
"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 | 38,065 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import algebra.big_operators.intervals
import topology.instances.real
import data.indicator_function
import data.equiv.encodable.lattice
import order.filter.at_top_bot
/-!
# Infinite sum over a topological monoid
This sum is known as unconditionally convergent, as it sums to the same value under all possible
permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute
convergence.
Note: There are summable sequences which are not unconditionally convergent! The other way holds
generally, see `has_sum.tendsto_sum_nat`.
## References
* Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups)
-/
noncomputable theory
open finset filter function classical
open_locale topological_space classical big_operators
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section has_sum
variables [add_comm_monoid α] [topological_space α]
/-- Infinite sum on a topological monoid
The `at_top` filter on `finset α` is the limit of all finite sets towards the entire type. So we sum
up bigger and bigger sets. This sum operation is still invariant under reordering, and a absolute
sum operator.
This is based on Mario Carneiro's infinite sum in Metamath.
For the definition or many statements, α does not need to be a topological monoid. We only add
this assumption later, for the lemmas where it is relevant.
-/
def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, ∑ b in s, f b) at_top (𝓝 a)
/-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/
def summable (f : β → α) : Prop := ∃a, has_sum f a
/-- `∑' i, f i` is the sum of `f` it exists, or 0 otherwise -/
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 summable.has_sum (ha : summable f) : has_sum f (∑'b, f b) :=
by simp [ha, tsum]; exact some_spec ha
lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩
/-- Constant zero function has sum `0` -/
lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 :=
by simp [has_sum, tendsto_const_nhds]
lemma summable_zero : summable (λb, 0 : β → α) := has_sum_zero.summable
lemma tsum_eq_zero_of_not_summable (h : ¬ summable f) : (∑'b, f b) = 0 :=
by simp [tsum, h]
lemma has_sum.has_sum_of_sum_eq {g : γ → α}
(h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b)
(hf : has_sum g a) :
has_sum f a :=
le_trans (map_at_top_finset_sum_le_of_sum_eq h_eq) hf
lemma has_sum_iff_has_sum {g : γ → α}
(h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b)
(h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ ∑ b in v', f b = ∑ x in u', g x) :
has_sum f a ↔ has_sum g a :=
⟨has_sum.has_sum_of_sum_eq h₂, has_sum.has_sum_of_sum_eq h₁⟩
lemma function.injective.has_sum_iff {g : γ → β} (hg : injective g)
(hf : ∀ x ∉ set.range g, f x = 0) :
has_sum (f ∘ g) a ↔ has_sum f a :=
by simp only [has_sum, tendsto, hg.map_at_top_finset_sum_eq hf]
lemma function.injective.summable_iff {g : γ → β} (hg : injective g)
(hf : ∀ x ∉ set.range g, f x = 0) :
summable (f ∘ g) ↔ summable f :=
exists_congr $ λ _, hg.has_sum_iff hf
lemma has_sum_subtype_iff_of_support_subset {s : set β} (hf : support f ⊆ s) :
has_sum (f ∘ coe : s → α) a ↔ has_sum f a :=
subtype.coe_injective.has_sum_iff $ by simpa using support_subset_iff'.1 hf
lemma has_sum_subtype_iff_indicator {s : set β} :
has_sum (f ∘ coe : s → α) a ↔ has_sum (s.indicator f) a :=
by rw [← set.indicator_range_comp, subtype.range_coe,
has_sum_subtype_iff_of_support_subset set.support_indicator]
@[simp] lemma has_sum_subtype_support : has_sum (f ∘ coe : support f → α) a ↔ has_sum f a :=
has_sum_subtype_iff_of_support_subset $ set.subset.refl _
lemma has_sum_fintype [fintype β] (f : β → α) : has_sum f (∑ b, f b) :=
order_top.tendsto_at_top _
protected lemma finset.has_sum (s : finset β) (f : β → α) :
has_sum (f ∘ coe : (↑s : set β) → α) (∑ b in s, f b) :=
by { rw ← sum_attach, exact has_sum_fintype _ }
protected lemma finset.summable (s : finset β) (f : β → α) :
summable (f ∘ coe : (↑s : set β) → α) :=
(s.has_sum f).summable
protected lemma set.finite.summable {s : set β} (hs : s.finite) (f : β → α) :
summable (f ∘ coe : s → α) :=
by convert hs.to_finset.summable f; simp only [hs.coe_to_finset]
/-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `∑ b in s, f b`. -/
lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (∑ b in s, f b) :=
(has_sum_subtype_iff_of_support_subset $ support_subset_iff'.2 hf).1 $ s.has_sum f
lemma summable_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f :=
(has_sum_sum_of_ne_finset_zero hf).summable
lemma has_sum_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
has_sum f (f b) :=
suffices has_sum f (∑ b' in {b}, f b'),
by simpa using this,
has_sum_sum_of_ne_finset_zero $ by simpa [hf]
lemma has_sum_ite_eq (b : β) (a : α) : has_sum (λb', if b' = b then a else 0) a :=
begin
convert has_sum_single b _,
{ exact (if_pos rfl).symm },
assume b' hb',
exact if_neg hb'
end
lemma equiv.has_sum_iff (e : γ ≃ β) :
has_sum (f ∘ e) a ↔ has_sum f a :=
e.injective.has_sum_iff $ by simp
lemma equiv.summable_iff (e : γ ≃ β) :
summable (f ∘ e) ↔ summable f :=
exists_congr $ λ a, e.has_sum_iff
lemma summable.prod_symm {f : β × γ → α} (hf : summable f) : summable (λ p : γ × β, f p.swap) :=
(equiv.prod_comm γ β).summable_iff.2 hf
lemma equiv.has_sum_iff_of_support {g : γ → α} (e : support f ≃ support g)
(he : ∀ x : support f, g (e x) = f x) :
has_sum f a ↔ has_sum g a :=
have (g ∘ coe) ∘ e = f ∘ coe, from funext he,
by rw [← has_sum_subtype_support, ← this, e.has_sum_iff, has_sum_subtype_support]
lemma has_sum_iff_has_sum_of_ne_zero_bij {g : γ → α} (i : support g → β)
(hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y)
(hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) :
has_sum f a ↔ has_sum g a :=
iff.symm $ equiv.has_sum_iff_of_support
(equiv.of_bijective (λ x, ⟨i x, λ hx, x.coe_prop $ hfg x ▸ hx⟩)
⟨λ x y h, subtype.ext $ hi $ subtype.ext_iff.1 h,
λ y, (hf y.coe_prop).imp $ λ x hx, subtype.ext hx⟩)
hfg
lemma equiv.summable_iff_of_support {g : γ → α} (e : support f ≃ support g)
(he : ∀ x : support f, g (e x) = f x) :
summable f ↔ summable g :=
exists_congr $ λ _, e.has_sum_iff_of_support he
protected lemma has_sum.map [add_comm_monoid γ] [topological_space γ] (hf : has_sum f a)
(g : α →+ γ) (h₃ : continuous g) :
has_sum (g ∘ f) (g a) :=
have g ∘ (λs:finset β, ∑ b in s, f b) = (λs:finset β, ∑ b in s, g (f b)),
from funext $ g.map_sum _,
show tendsto (λs:finset β, ∑ b in s, g (f b)) at_top (𝓝 (g a)),
from this ▸ (h₃.tendsto a).comp hf
/-- If `f : ℕ → α` has sum `a`, then the partial sums `∑_{i=0}^{n-1} f i` converge to `a`. -/
lemma has_sum.tendsto_sum_nat {f : ℕ → α} (h : has_sum f a) :
tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
h.comp tendsto_finset_range
lemma has_sum.unique {a₁ a₂ : α} [t2_space α] : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ :=
tendsto_nhds_unique
lemma summable.has_sum_iff_tendsto_nat [t2_space α] {f : ℕ → α} {a : α} (hf : summable f) :
has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
begin
refine ⟨λ h, h.tendsto_sum_nat, λ h, _⟩,
rw tendsto_nhds_unique h hf.has_sum.tendsto_sum_nat,
exact hf.has_sum
end
lemma equiv.summable_iff_of_has_sum_iff {α' : Type*} [add_comm_monoid α']
[topological_space α'] (e : α' ≃ α) {f : β → α} {g : γ → α'}
(he : ∀ {a}, has_sum f (e a) ↔ has_sum g a) :
summable f ↔ summable g :=
⟨λ ⟨a, ha⟩, ⟨e.symm a, he.1 $ by rwa [e.apply_symm_apply]⟩, λ ⟨a, ha⟩, ⟨e a, he.2 ha⟩⟩
variable [has_continuous_add α]
lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) :=
by simp only [has_sum, sum_add_distrib]; exact hf.add hg
lemma summable.add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) :=
(hf.has_sum.add hg.has_sum).summable
lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} :
(∀i∈s, has_sum (f i) (a i)) → has_sum (λb, ∑ i in s, f i b) (∑ i in s, a i) :=
finset.induction_on s (by simp [has_sum_zero]) (by simp [has_sum.add] {contextual := tt})
lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
summable (λb, ∑ i in s, f i b) :=
(has_sum_sum $ assume i hi, (hf i hi).has_sum).summable
lemma has_sum.add_compl {s : set β} (ha : has_sum (f ∘ coe : s → α) a)
(hb : has_sum (f ∘ coe : sᶜ → α) b) :
has_sum f (a + b) :=
by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb)
lemma summable.add_compl {s : set β} (hs : summable (f ∘ coe : s → α))
(hsc : summable (f ∘ coe : sᶜ → α)) :
summable f :=
(hs.has_sum.add_compl hsc.has_sum).summable
lemma has_sum.compl_add {s : set β} (ha : has_sum (f ∘ coe : sᶜ → α) a)
(hb : has_sum (f ∘ coe : s → α) b) :
has_sum f (a + b) :=
by simpa using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb)
lemma summable.compl_add {s : set β} (hs : summable (f ∘ coe : sᶜ → α))
(hsc : summable (f ∘ coe : s → α)) :
summable f :=
(hs.has_sum.compl_add hsc.has_sum).summable
lemma has_sum.sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
(ha : has_sum f a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) : has_sum g a :=
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, ∑ b in bs, ∑ c in p b, f ⟨b, c⟩) ⁻¹' s).nonempty,
from assume cs,
let cs' := λb, (if h : b ∈ bs then cs b h else ∅) ∪ snds b in
have sum_eq : ∑ b in bs, ∑ c in cs' b, f ⟨b, c⟩ = ∑ x in bs.sigma cs', f x,
from sum_sigma.symm,
have ∑ x in bs.sigma cs', f x ∈ s,
from hu _ $ finset.subset.trans u_subset $ sigma_mono hbs $
assume b, @finset.subset_union_right (γ b) _ _ _,
exists.intro cs' $
by simp [sum_eq, this]; { intros b hb, simp [cs', hb, finset.subset_union_left] },
have tendsto (λp:(Πb:β, finset (γ b)), ∑ b in bs, ∑ c in p b, f ⟨b, c⟩)
(⨅b (h : b ∈ bs), at_top.comap (λp, p b)) (𝓝 (∑ b in bs, g b)),
from tendsto_finset_sum bs $
assume c hc, tendsto_infi' c $ tendsto_infi' hc $ by apply tendsto.comp (hf c) tendsto_comap,
have ∑ b in bs, g b ∈ s,
from @mem_of_closed_of_tendsto' _ _ _ _ _ _ _ this hsc $ forall_sets_nonempty_iff_ne_bot.mp $
begin
simp only [mem_inf_sets, exists_imp_distrib, forall_and_distrib, and_imp,
filter.mem_infi_sets_finset, mem_comap_sets, mem_at_top_sets, and_comm,
mem_principal_sets, set.preimage_subset_iff, exists_prop, skolem],
intros 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)),
exact (h _).mono (set.subset.trans (set.inter_subset_inter (le_trans this hs₂) hs₃) hs₁)
end,
hss' this
/-- If a series `f` on `β × γ` has sum `a` and for each `b` the restriction of `f` to `{b} × γ`
has sum `g b`, then the series `g` has sum `a`. -/
lemma has_sum.prod_fiberwise [regular_space α] {f : β × γ → α} {g : β → α} {a : α}
(ha : has_sum f a) (hf : ∀b, has_sum (λc, f (b, c)) (g b)) :
has_sum g a :=
has_sum.sigma ((equiv.sigma_equiv_prod β γ).has_sum_iff.2 ha) hf
lemma summable.sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (hf : ∀b, summable (λc, f ⟨b, c⟩)) :
summable (λb, ∑'c, f ⟨b, c⟩) :=
(ha.has_sum.sigma (assume b, (hf b).has_sum)).summable
lemma has_sum.sigma_of_has_sum [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α}
{a : α} (ha : has_sum g a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (hf' : summable f) :
has_sum f a :=
by simpa [(hf'.has_sum.sigma hf).unique ha] using hf'.has_sum
end has_sum
section tsum
variables [add_comm_monoid α] [topological_space α] [t2_space α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.tsum_eq (ha : has_sum f a) : (∑'b, f b) = a :=
(summable.has_sum ⟨a, ha⟩).unique ha
lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ (∑'b, f b) = a :=
iff.intro has_sum.tsum_eq (assume eq, eq ▸ h.has_sum)
@[simp] lemma tsum_zero : (∑'b:β, 0:α) = 0 := has_sum_zero.tsum_eq
lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) :
(∑'b, f b) = ∑ b in s, f b :=
(has_sum_sum_of_ne_finset_zero hf).tsum_eq
lemma tsum_fintype [fintype β] (f : β → α) : (∑'b, f b) = ∑ b, f b :=
(has_sum_fintype f).tsum_eq
@[simp] lemma finset.tsum_subtype (s : finset β) (f : β → α) :
(∑'x : {x // x ∈ s}, f x) = ∑ x in s, f x :=
(s.has_sum f).tsum_eq
lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
(∑'b, f b) = f b :=
(has_sum_single b hf).tsum_eq
@[simp] lemma tsum_ite_eq (b : β) (a : α) : (∑'b', if b' = b then a else 0) = a :=
(has_sum_ite_eq b a).tsum_eq
lemma equiv.tsum_eq_tsum_of_has_sum_iff_has_sum {α' : Type*} [add_comm_monoid α']
[topological_space α'] (e : α' ≃ α) (h0 : e 0 = 0) {f : β → α} {g : γ → α'}
(h : ∀ {a}, has_sum f (e a) ↔ has_sum g a) :
(∑' b, f b) = e (∑' c, g c) :=
by_cases
(assume : summable g, (h.mpr this.has_sum).tsum_eq)
(assume hg : ¬ summable g,
have hf : ¬ summable f, from mt (e.summable_iff_of_has_sum_iff @h).1 hg,
by simp [tsum, hf, hg, h0])
lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α}
(h : ∀{a}, has_sum f a ↔ has_sum g a) :
(∑'b, f b) = (∑'c, g c) :=
(equiv.refl α).tsum_eq_tsum_of_has_sum_iff_has_sum rfl @h
lemma equiv.tsum_eq (j : γ ≃ β) (f : β → α) : (∑'c, f (j c)) = (∑'b, f b) :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ a, j.has_sum_iff
lemma equiv.tsum_eq_tsum_of_support {f : β → α} {g : γ → α} (e : support f ≃ support g)
(he : ∀ x, g (e x) = f x) :
(∑' x, f x) = ∑' y, g y :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, e.has_sum_iff_of_support he
lemma tsum_eq_tsum_of_ne_zero_bij {g : γ → α} (i : support g → β)
(hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y)
(hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) :
(∑' x, f x) = ∑' y, g y :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_iff_has_sum_of_ne_zero_bij i hi hf hfg
lemma tsum_subtype (s : set β) (f : β → α) :
(∑' x : s, f x) = ∑' x, s.indicator f x :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_subtype_iff_indicator
section has_continuous_add
variable [has_continuous_add α]
lemma tsum_add (hf : summable f) (hg : summable g) : (∑'b, f b + g b) = (∑'b, f b) + (∑'b, g b) :=
(hf.has_sum.add hg.has_sum).tsum_eq
lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
(∑'b, ∑ i in s, f i b) = ∑ i in s, ∑'b, f i b :=
(has_sum_sum $ assume i hi, (hf i hi).has_sum).tsum_eq
lemma tsum_sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) :=
(h₂.has_sum.sigma (assume b, (h₁ b).has_sum)).tsum_eq.symm
lemma tsum_prod' [regular_space α] {f : β × γ → α} (h : summable f)
(h₁ : ∀b, summable (λc, f (b, c))) :
(∑'p, f p) = (∑'b c, f (b, c)) :=
(h.has_sum.prod_fiberwise (assume b, (h₁ b).has_sum)).tsum_eq.symm
lemma tsum_comm' [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f))
(h₁ : ∀b, summable (f b)) (h₂ : ∀ c, summable (λ b, f b c)) :
(∑' c b, f b c) = (∑' b c, f b c) :=
begin
erw [← tsum_prod' h h₁, ← tsum_prod' h.prod_symm h₂, ← (equiv.prod_comm β γ).tsum_eq],
refl,
assumption
end
end has_continuous_add
section encodable
open encodable
variable [encodable γ]
/-- You can compute a sum over an encodably type by summing over the natural numbers and
taking a supremum. This is useful for outer measures. -/
theorem tsum_supr_decode2 [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(s : γ → β) : (∑' i : ℕ, m (⨆ b ∈ decode2 γ i, s b)) = (∑' b : γ, m (s b)) :=
begin
have H : ∀ n, m (⨆ b ∈ decode2 γ n, s b) ≠ 0 → (decode2 γ n).is_some,
{ intros n h,
cases decode2 γ n with b,
{ refine (h $ by simp [m0]).elim },
{ exact rfl } },
symmetry, refine tsum_eq_tsum_of_ne_zero_bij (λ a, option.get (H a.1 a.2)) _ _ _,
{ rintros ⟨m, hm⟩ ⟨n, hn⟩ e,
have := mem_decode2.1 (option.get_mem (H n hn)),
rwa [← e, mem_decode2.1 (option.get_mem (H m hm))] at this },
{ intros b h,
refine ⟨⟨encode b, _⟩, _⟩,
{ simp only [mem_support, encodek2] at h ⊢, convert h, simp [set.ext_iff, encodek2] },
{ exact option.get_of_mem _ (encodek2 _) } },
{ rintros ⟨n, h⟩, dsimp only [subtype.coe_mk],
transitivity, swap,
rw [show decode2 γ n = _, from option.get_mem (H n h)],
congr, simp [ext_iff, -option.some_get] }
end
/-- `tsum_supr_decode2` specialized to the complete lattice of sets. -/
theorem tsum_Union_decode2 (m : set β → α) (m0 : m ∅ = 0)
(s : γ → set β) : (∑' i, m (⋃ b ∈ decode2 γ i, s b)) = (∑' b, m (s b)) :=
tsum_supr_decode2 m m0 s
/-! Some properties about measure-like functions.
These could also be functions defined on complete sublattices of sets, with the property
that they are countably sub-additive.
`R` will probably be instantiated with `(≤)` in all applications.
-/
/-- If a function is countably sub-additive then it is sub-additive on encodable types -/
theorem rel_supr_tsum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i)))
(s : γ → β) : R (m (⨆ b : γ, s b)) (∑' b : γ, m (s b)) :=
by { rw [← supr_decode2, ← tsum_supr_decode2 _ m0 s], exact m_supr _ }
/-- If a function is countably sub-additive then it is sub-additive on finite sets -/
theorem rel_supr_sum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i)))
(s : δ → β) (t : finset δ) :
R (m (⨆ d ∈ t, s d)) (∑ d in t, m (s d)) :=
by { cases t.nonempty_encodable, rw [supr_subtype'], convert rel_supr_tsum m m0 R m_supr _,
rw [← finset.tsum_subtype], assumption }
/-- If a function is countably sub-additive then it is binary sub-additive -/
theorem rel_sup_add [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i)))
(s₁ s₂ : β) : R (m (s₁ ⊔ s₂)) (m s₁ + m s₂) :=
begin
convert rel_supr_tsum m m0 R m_supr (λ b, cond b s₁ s₂),
{ simp only [supr_bool_eq, cond] },
{ rw tsum_fintype, simp only [finset.sum_insert, not_false_iff, fintype.univ_bool,
finset.mem_singleton, cond, finset.sum_singleton] }
end
end encodable
end tsum
section topological_group
variables [add_comm_group α] [topological_space α] [topological_add_group α]
variables {f g : β → α} {a a₁ a₂ : α}
-- `by simpa using` speeds up elaboration. Why?
lemma has_sum.neg (h : has_sum f a) : has_sum (λb, - f b) (- a) :=
by simpa only using h.map (-add_monoid_hom.id α) continuous_neg
lemma summable.neg (hf : summable f) : summable (λb, - f b) :=
hf.has_sum.neg.summable
lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) :=
by { simp [sub_eq_add_neg], exact hf.add hg.neg }
lemma summable.sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) :=
(hf.has_sum.sub hg.has_sum).summable
lemma has_sum.has_sum_compl_iff {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) :
has_sum (f ∘ coe : sᶜ → α) a₂ ↔ has_sum f (a₁ + a₂) :=
begin
refine ⟨λ h, hf.add_compl h, λ h, _⟩,
rw [has_sum_subtype_iff_indicator] at hf ⊢,
rw [set.indicator_compl],
simpa only [add_sub_cancel'] using h.sub hf
end
lemma has_sum.has_sum_iff_compl {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) :
has_sum f a₂ ↔ has_sum (f ∘ coe : sᶜ → α) (a₂ - a₁) :=
iff.symm $ hf.has_sum_compl_iff.trans $ by rw [add_sub_cancel'_right]
lemma summable.summable_compl_iff {s : set β} (hf : summable (f ∘ coe : s → α)) :
summable (f ∘ coe : sᶜ → α) ↔ summable f :=
⟨λ ⟨a, ha⟩, (hf.has_sum.has_sum_compl_iff.1 ha).summable,
λ ⟨a, ha⟩, (hf.has_sum.has_sum_iff_compl.1 ha).summable⟩
protected lemma finset.has_sum_compl_iff (s : finset β) :
has_sum (λ x : {x // x ∉ s}, f x) a ↔ has_sum f (a + ∑ i in s, f i) :=
(s.has_sum f).has_sum_compl_iff.trans $ by rw [add_comm]
protected lemma finset.has_sum_iff_compl (s : finset β) :
has_sum f a ↔ has_sum (λ x : {x // x ∉ s}, f x) (a - ∑ i in s, f i) :=
(s.has_sum f).has_sum_iff_compl
protected lemma finset.summable_compl_iff (s : finset β) :
summable (λ x : {x // x ∉ s}, f x) ↔ summable f :=
(s.summable f).summable_compl_iff
lemma set.finite.summable_compl_iff {s : set β} (hs : s.finite) :
summable (f ∘ coe : sᶜ → α) ↔ summable f :=
(hs.summable f).summable_compl_iff
section tsum
variables [t2_space α]
lemma tsum_neg (hf : summable f) : (∑'b, - f b) = - (∑'b, f b) :=
hf.has_sum.neg.tsum_eq
lemma tsum_sub (hf : summable f) (hg : summable g) : (∑'b, f b - g b) = (∑'b, f b) - (∑'b, g b) :=
(hf.has_sum.sub hg.has_sum).tsum_eq
lemma tsum_add_tsum_compl {s : set β} (hs : summable (f ∘ coe : s → α))
(hsc : summable (f ∘ coe : sᶜ → α)) :
(∑' x : s, f x) + (∑' x : sᶜ, f x) = ∑' x, f x :=
(hs.has_sum.add_compl hsc.has_sum).tsum_eq.symm
lemma sum_add_tsum_compl {s : finset β} (hf : summable f) :
(∑ x in s, f x) + (∑' x : (↑s : set β)ᶜ, f x) = ∑' x, f x :=
((s.has_sum f).add_compl (s.summable_compl_iff.2 hf).has_sum).tsum_eq.symm
end tsum
/-!
### Sums on subtypes
If `s` is a finset of `α`, we show that the summability of `f` in the whole space and on the subtype
`univ - s` are equivalent, and relate their sums. For a function defined on `ℕ`, we deduce the
formula `(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i)`, in `sum_add_tsum_nat_add`.
-/
section subtype
variables {s : finset β}
lemma has_sum_nat_add_iff {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) :=
begin
refine iff.trans _ ((range k).has_sum_compl_iff),
rw [← (not_mem_range_equiv k).symm.has_sum_iff],
refl
end
lemma summable_nat_add_iff {f : ℕ → α} (k : ℕ) : summable (λ n, f (n + k)) ↔ summable f :=
iff.symm $ (equiv.add_right (∑ i in range k, f i)).summable_iff_of_has_sum_iff $
λ a, (has_sum_nat_add_iff k).symm
lemma has_sum_nat_add_iff' {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) (a - ∑ i in range k, f i) ↔ has_sum f a :=
by simp [has_sum_nat_add_iff]
lemma sum_add_tsum_nat_add [t2_space α] {f : ℕ → α} (k : ℕ) (h : summable f) :
(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i) :=
by simpa [add_comm] using
((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum).unique h.has_sum
lemma tsum_eq_zero_add [t2_space α] {f : ℕ → α} (hf : summable f) :
(∑'b, f b) = f 0 + (∑'b, f (b + 1)) :=
by simpa only [range_one, sum_singleton] using (sum_add_tsum_nat_add 1 hf).symm
end subtype
end topological_group
section topological_semiring
variables [semiring α] [topological_space α] [topological_semiring α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.mul_left (a₂) (h : has_sum f a₁) : has_sum (λb, a₂ * f b) (a₂ * a₁) :=
by simpa only using h.map (add_monoid_hom.mul_left a₂) (continuous_const.mul continuous_id)
lemma has_sum.mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) :=
by simpa only using hf.map (add_monoid_hom.mul_right a₂) (continuous_id.mul continuous_const)
lemma summable.mul_left (a) (hf : summable f) : summable (λb, a * f b) :=
(hf.has_sum.mul_left _).summable
lemma summable.mul_right (a) (hf : summable f) : summable (λb, f b * a) :=
(hf.has_sum.mul_right _).summable
section tsum
variables [t2_space α]
lemma tsum_mul_left (a) (hf : summable f) : (∑'b, a * f b) = a * (∑'b, f b) :=
(hf.has_sum.mul_left _).tsum_eq
lemma tsum_mul_right (a) (hf : summable f) : (∑'b, f b * a) = (∑'b, f b) * a :=
(hf.has_sum.mul_right _).tsum_eq
end tsum
end topological_semiring
section division_ring
variables [division_ring α] [topological_space α] [topological_semiring α]
{f g : β → α} {a a₁ a₂ : α}
lemma has_sum_mul_left_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, a₂ * f b) (a₂ * a₁) :=
⟨has_sum.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a₂⁻¹⟩
lemma has_sum_mul_right_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, f b * a₂) (a₁ * a₂) :=
⟨has_sum.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a₂⁻¹⟩
lemma summable_mul_left_iff (h : a ≠ 0) : summable f ↔ summable (λb, a * f b) :=
⟨λ H, H.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a⁻¹⟩
lemma summable_mul_right_iff (h : a ≠ 0) : summable f ↔ summable (λb, f b * a) :=
⟨λ H, H.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a⁻¹⟩
end division_ring
section order_topology
variables [ordered_add_comm_monoid α] [topological_space α] [order_closed_topology α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto' hf hg $ assume s, sum_le_sum $ assume b _, h b
lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁,
begin
refine (has_sum_iff_has_sum_of_ne_zero_bij (i ∘ coe) _ _ _).2 hf,
{ exact assume c₁ c₂ eq, hi eq },
{ intros c hc,
rw [mem_support] at hc,
cases eq : partial_inv i c with b; rw eq at hc,
{ contradiction },
{ rw [partial_inv_of_injective hi] at eq,
exact ⟨⟨b, hc⟩, eq⟩ } },
{ assume c, simp [partial_inv_left hi, option.cases_on'] }
end,
begin
refine has_sum_le (assume c, _) this hg,
by_cases c ∈ set.range i,
{ rcases h with ⟨b, rfl⟩,
rw [partial_inv_left hi, option.cases_on'],
exact h _ },
{ have : partial_inv i c = none := dif_neg h,
rw [this, option.cases_on'],
exact hs _ h }
end
lemma tsum_le_tsum_of_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≤ tsum g :=
has_sum_le_inj i hi hs h hf.has_sum hg.has_sum
lemma sum_le_has_sum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : has_sum f a) :
∑ b in s, f b ≤ a :=
ge_of_tendsto hf (eventually_at_top.2 ⟨s, λ t hst,
sum_le_sum_of_subset_of_nonneg hst $ λ b hbt hbs, hs b hbs⟩)
lemma sum_le_tsum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : summable f) :
∑ b in s, f b ≤ tsum f :=
sum_le_has_sum s hs hf.has_sum
lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : (∑'b, f b) ≤ (∑'b, g b) :=
has_sum_le h hf.has_sum hg.has_sum
lemma tsum_nonneg (h : ∀ b, 0 ≤ g b) : 0 ≤ (∑'b, g b) :=
begin
by_cases hg : summable g,
{ simpa using tsum_le_tsum h summable_zero hg },
{ simp [tsum_eq_zero_of_not_summable hg] }
end
lemma tsum_nonpos (h : ∀ b, f b ≤ 0) : (∑'b, f b) ≤ 0 :=
begin
by_cases hf : summable f,
{ simpa using tsum_le_tsum h hf summable_zero},
{ simp [tsum_eq_zero_of_not_summable hf] }
end
end order_topology
section uniform_group
variables [add_comm_group α] [uniform_space α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma summable_iff_cauchy_seq_finset [complete_space α] :
summable f ↔ cauchy_seq (λ (s : finset β), ∑ b in s, f b) :=
cauchy_map_iff_exists_tendsto.symm
variable [uniform_add_group α]
lemma cauchy_seq_finset_iff_vanishing :
cauchy_seq (λ (s : finset β), ∑ b in s, f b)
↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) :=
begin
simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot,
prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)],
rw [tendsto_at_top' (_ : finset β × finset β → α)],
split,
{ assume h e he,
rcases h e he with ⟨⟨s₁, s₂⟩, h⟩,
use [s₁ ∪ s₂],
assume t ht,
specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_left_of_le le_sup_right⟩,
simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h },
{ assume h e he,
rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩,
rcases h d hd with ⟨s, h⟩,
use [(s, s)],
rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩,
have : ∑ b in t₂, f b - ∑ b in t₁, f b = ∑ b in t₂ \ s, f b - ∑ b in t₁ \ s, f b,
{ simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm,
add_sub_add_right_eq_sub] },
simp only [this],
exact hde _ _ (h _ finset.sdiff_disjoint) (h _ finset.sdiff_disjoint) }
end
variable [complete_space α]
lemma summable_iff_vanishing :
summable f ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) :=
by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing]
/- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/
lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) :
summable g :=
summable_iff_vanishing.2 $
assume e he,
let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in
⟨s, assume t ht,
have eq : ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t, g b :=
calc ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t.filter (λb, g b = f b), g b :
finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm)
... = ∑ b in t, g b :
begin
refine finset.sum_subset (finset.filter_subset _) _,
assume b hbt hb,
simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb,
exact (h b).resolve_right hb
end,
eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _) ht⟩
protected lemma summable.indicator (hf : summable f) (s : set β) :
summable (s.indicator f) :=
hf.summable_of_eq_zero_or_self $ λ b,
if hb : b ∈ s then or.inr (set.indicator_of_mem hb _)
else or.inl (set.indicator_of_not_mem hb _)
lemma summable.comp_injective {i : γ → β} (hf : summable f) (hi : injective i) :
summable (f ∘ i) :=
begin
simpa only [set.indicator_range_comp]
using (hi.summable_iff _).2 (hf.indicator (set.range i)),
exact λ x hx, set.indicator_of_not_mem hx _
end
lemma summable.subtype (hf : summable f) (s : set β) : summable (f ∘ coe : s → α) :=
hf.comp_injective subtype.coe_injective
lemma summable.sigma_factor {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (b : β) : summable (λc, f ⟨b, c⟩) :=
ha.comp_injective sigma_mk_injective
lemma summable.sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : summable (λb, ∑'c, f ⟨b, c⟩) :=
ha.sigma' (λ b, ha.sigma_factor b)
lemma summable.prod_factor {f : β × γ → α} (h : summable f) (b : β) :
summable (λ c, f (b, c)) :=
h.comp_injective $ λ c₁ c₂ h, (prod.ext_iff.1 h).2
lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : (∑'p, f p) = (∑'b c, f ⟨b, c⟩) :=
tsum_sigma' (λ b, ha.sigma_factor b) ha
lemma tsum_prod [regular_space α] {f : β × γ → α} (h : summable f) :
(∑'p, f p) = (∑'b c, f ⟨b, c⟩) :=
tsum_prod' h h.prod_factor
lemma tsum_comm [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f)) :
(∑' c b, f b c) = (∑' b c, f b c) :=
tsum_comm' h h.prod_factor h.prod_symm.prod_factor
end uniform_group
section cauchy_seq
open finset.Ico filter
/-- If the extended distance between consequent points of a sequence is estimated
by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_edist_le_of_summable [emetric_space α] {f : ℕ → α} (d : ℕ → nnreal)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _),
-- Actually we need partial sums of `d` to be a Cauchy sequence
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat,
-- Now we take the same `N` as in one of the definitions of a Cauchy sequence
refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _),
have hsum := hN n hn,
-- We simplify the known inequality
rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum,
norm_cast at hsum,
replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum,
rw edist_comm,
-- Then use `hf` to simplify the goal to the same form
apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)),
assumption_mod_cast
end
/-- If the distance between consequent points of a sequence is estimated by a summable series,
then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_dist_le_of_summable [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine metric.cauchy_seq_iff'.2 (λε εpos, _),
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in cauchy_seq_of_tendsto_nhds _ H.tendsto_sum_nat,
refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _),
have hsum := hN n hn,
rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum,
calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _
... ≤ ∑ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k)
... ≤ abs (∑ x in Ico N n, d x) : le_abs_self _
... < ε : hsum
end
lemma cauchy_seq_of_summable_dist [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ (λ _, le_refl _) h
lemma dist_le_tsum_of_dist_le_of_tendsto [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a))
(n : ℕ) :
dist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.dist ha)
(eventually_at_top.2 ⟨n, λ m hnm, _⟩),
refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _,
rw [sum_Ico_eq_sum_range],
refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _,
exact hd.comp_injective (add_right_injective n)
end
lemma dist_le_tsum_of_dist_le_of_tendsto₀ [metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ tsum d :=
by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0
lemma dist_le_tsum_dist_of_tendsto [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) (n) :
dist (f n) a ≤ ∑' m, dist (f (n+m)) (f (n+m).succ) :=
show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from
dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_refl _) h ha n
lemma dist_le_tsum_dist_of_tendsto₀ [metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) :=
by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0
end cauchy_seq
|
52f3e89c03c27e23ec16e368cec518eafc8c2043 | 1a61aba1b67cddccce19532a9596efe44be4285f | /hott/types/fiber.hlean | 3ae3efdcdf1f729a15767024c30e610fcea6d31c | [
"Apache-2.0"
] | permissive | eigengrau/lean | 07986a0f2548688c13ba36231f6cdbee82abf4c6 | f8a773be1112015e2d232661ce616d23f12874d0 | refs/heads/master | 1,610,939,198,566 | 1,441,352,386,000 | 1,441,352,494,000 | 41,903,576 | 0 | 0 | null | 1,441,352,210,000 | 1,441,352,210,000 | null | UTF-8 | Lean | false | false | 1,210 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Ported from Coq HoTT
Theorems about fibers
-/
import .sigma .eq
structure fiber {A B : Type} (f : A → B) (b : B) :=
(point : A)
(point_eq : f point = b)
open equiv sigma sigma.ops eq
namespace fiber
variables {A B : Type} {f : A → B} {b : B}
definition sigma_char (f : A → B) (b : B) : fiber f b ≃ (Σ(a : A), f a = b) :=
begin
fapply equiv.MK,
{intro x, exact ⟨point x, point_eq x⟩},
{intro x, exact (fiber.mk x.1 x.2)},
{intro x, cases x, apply idp},
{intro x, cases x, apply idp},
end
definition fiber_eq_equiv (x y : fiber f b)
: (x = y) ≃ (Σ(p : point x = point y), point_eq x = ap f p ⬝ point_eq y) :=
begin
apply equiv.trans,
apply eq_equiv_fn_eq_of_equiv, apply sigma_char,
apply equiv.trans,
apply sigma_eq_equiv,
apply sigma_equiv_sigma_id,
intro p,
apply pathover_eq_equiv_Fl,
end
definition fiber_eq {x y : fiber f b} (p : point x = point y)
(q : point_eq x = ap f p ⬝ point_eq y) : x = y :=
to_inv !fiber_eq_equiv ⟨p, q⟩
end fiber
|
ade48ff8981d4a870fae6599f3058c859d19b400 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Attributes.lean | e6d47d15bf268783577e29ef43c140ec65a5a7a2 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | EdAyers/lean4 | 57ac632d6b0789cb91fab2170e8c9e40441221bd | 37ba0df5841bde51dbc2329da81ac23d4f6a4de4 | refs/heads/master | 1,676,463,245,298 | 1,660,619,433,000 | 1,660,619,433,000 | 183,433,437 | 1 | 0 | Apache-2.0 | 1,657,612,672,000 | 1,556,196,574,000 | Lean | UTF-8 | Lean | false | false | 20,664 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Syntax
import Lean.CoreM
import Lean.ResolveName
namespace Lean
inductive AttributeApplicationTime where
| afterTypeChecking | afterCompilation | beforeElaboration
deriving Inhabited, BEq
abbrev AttrM := CoreM
instance : MonadLift ImportM AttrM where
monadLift x := do liftM (m := IO) (x { env := (← getEnv), opts := (← getOptions) })
structure AttributeImplCore where
/-- This is used as the target for go-to-definition queries for simple attributes -/
ref : Name := by exact decl_name%
name : Name
descr : String
applicationTime := AttributeApplicationTime.afterTypeChecking
deriving Inhabited
/-- You can tag attributes with the 'local' or 'scoped' kind.
For example: `attribute [local myattr, scoped yourattr, theirattr]`.
This is used to indicate how an attribute should be scoped.
- local means that the attribute should only be applied in the current scope and forgotten once the current section, namespace, or file is closed.
- scoped means that the attribute should only be applied while the namespace is open.
- global means that the attribute should always be applied.
Note that the attribute handler (`AttributeImpl.add`) is responsible for interpreting the kind and
making sure that these kinds are respected.
-/
inductive AttributeKind
| global | «local» | «scoped»
deriving BEq, Inhabited
instance : ToString AttributeKind where
toString
| .global => "global"
| .local => "local"
| .scoped => "scoped"
structure AttributeImpl extends AttributeImplCore where
/-- This is run when the attribute is applied to a declaration `decl`. `stx` is the syntax of the attribute including arguments. -/
add (decl : Name) (stx : Syntax) (kind : AttributeKind) : AttrM Unit
erase (decl : Name) : AttrM Unit := throwError "attribute cannot be erased"
deriving Inhabited
open Std (PersistentHashMap)
builtin_initialize attributeMapRef : IO.Ref (PersistentHashMap Name AttributeImpl) ← IO.mkRef {}
/-- Low level attribute registration function. -/
def registerBuiltinAttribute (attr : AttributeImpl) : IO Unit := do
let m ← attributeMapRef.get
if m.contains attr.name then throw (IO.userError ("invalid builtin attribute declaration, '" ++ toString attr.name ++ "' has already been used"))
unless (← initializing) do
throw (IO.userError "failed to register attribute, attributes can only be registered during initialization")
attributeMapRef.modify fun m => m.insert attr.name attr
/-!
Helper methods for decoding the parameters of builtin attributes that are defined before `Lean.Parser`.
We have the following ones:
```
@[builtinAttrParser] def simple := leading_parser ident >> optional ident >> optional priorityParser
/- We can't use `simple` for `class`, `instance`, `export` and `macro` because they are keywords. -/
@[builtinAttrParser] def «class» := leading_parser "class"
@[builtinAttrParser] def «instance» := leading_parser "instance" >> optional priorityParser
@[builtinAttrParser] def «macro» := leading_parser "macro " >> ident
```
Note that we need the parsers for `class`, `instance`, and `macros` because they are keywords.
-/
def Attribute.Builtin.ensureNoArgs (stx : Syntax) : AttrM Unit := do
if stx.getKind == `Lean.Parser.Attr.simple && stx[1].isNone && stx[2].isNone then
return ()
else if stx.getKind == `Lean.Parser.Attr.«class» then
return ()
else match stx with
| Syntax.missing => return () -- In the elaborator, we use `Syntax.missing` when creating attribute views for simple attributes such as `class and `inline
| _ => throwErrorAt stx "unexpected attribute argument"
def Attribute.Builtin.getIdent? (stx : Syntax) : AttrM (Option Syntax) := do
if stx.getKind == `Lean.Parser.Attr.simple then
if !stx[1].isNone && stx[1][0].isIdent then
return some stx[1][0]
else
return none
/- We handle `macro` here because it is handled by the generic `KeyedDeclsAttribute -/
else if stx.getKind == `Lean.Parser.Attr.«macro» || stx.getKind == `Lean.Parser.Attr.«export» then
return some stx[1]
else
throwErrorAt stx "unexpected attribute argument"
def Attribute.Builtin.getIdent (stx : Syntax) : AttrM Syntax := do
match (← getIdent? stx) with
| some id => return id
| none => throwErrorAt stx "unexpected attribute argument, identifier expected"
def Attribute.Builtin.getId? (stx : Syntax) : AttrM (Option Name) := do
let ident? ← getIdent? stx
return Syntax.getId <$> ident?
def Attribute.Builtin.getId (stx : Syntax) : AttrM Name := do
return (← getIdent stx).getId
def getAttrParamOptPrio (optPrioStx : Syntax) : AttrM Nat :=
if optPrioStx.isNone then
return eval_prio default
else match optPrioStx[0].isNatLit? with
| some prio => return prio
| none => throwErrorAt optPrioStx "priority expected"
def Attribute.Builtin.getPrio (stx : Syntax) : AttrM Nat := do
if stx.getKind == `Lean.Parser.Attr.simple then
getAttrParamOptPrio stx[1]
else
throwErrorAt stx "unexpected attribute argument, optional priority expected"
/--
Tag attributes are simple and efficient. They are useful for marking declarations in the modules where
they were defined.
The startup cost for this kind of attribute is very small since `addImportedFn` is a constant function.
They provide the predicate `tagAttr.hasTag env decl` which returns true iff declaration `decl`
is tagged in the environment `env`. -/
structure TagAttribute where
attr : AttributeImpl
ext : PersistentEnvExtension Name Name NameSet
deriving Inhabited
def registerTagAttribute (name : Name) (descr : String)
(validate : Name → AttrM Unit := fun _ => pure ()) (ref : Name := by exact decl_name%) : IO TagAttribute := do
let ext : PersistentEnvExtension Name Name NameSet ← registerPersistentEnvExtension {
name := name
mkInitial := pure {}
addImportedFn := fun _ _ => pure {}
addEntryFn := fun (s : NameSet) n => s.insert n
exportEntriesFn := fun es =>
let r : Array Name := es.fold (fun a e => a.push e) #[]
r.qsort Name.quickLt
statsFn := fun s => "tag attribute" ++ Format.line ++ "number of local entries: " ++ format s.size
}
let attrImpl : AttributeImpl := {
ref := ref
name := name
descr := descr
add := fun decl stx kind => do
Attribute.Builtin.ensureNoArgs stx
unless kind == AttributeKind.global do throwError "invalid attribute '{name}', must be global"
let env ← getEnv
unless (env.getModuleIdxFor? decl).isNone do
throwError "invalid attribute '{name}', declaration is in an imported module"
validate decl
let env ← getEnv
setEnv <| ext.addEntry env decl
}
registerBuiltinAttribute attrImpl
return { attr := attrImpl, ext := ext }
namespace TagAttribute
def hasTag (attr : TagAttribute) (env : Environment) (decl : Name) : Bool :=
match env.getModuleIdxFor? decl with
| some modIdx => (attr.ext.getModuleEntries env modIdx).binSearchContains decl Name.quickLt
| none => (attr.ext.getState env).contains decl
end TagAttribute
/--
A `TagAttribute` variant where we can attach parameters to attributes.
It is slightly more expensive and consumes a little bit more memory than `TagAttribute`.
They provide the function `pAttr.getParam env decl` which returns `some p` iff declaration `decl`
contains the attribute `pAttr` with parameter `p`. -/
structure ParametricAttribute (α : Type) where
attr : AttributeImpl
ext : PersistentEnvExtension (Name × α) (Name × α) (NameMap α)
deriving Inhabited
structure ParametricAttributeImpl (α : Type) extends AttributeImplCore where
/-- This is used as the target for go-to-definition queries for simple attributes -/
getParam : Name → Syntax → AttrM α
afterSet : Name → α → AttrM Unit := fun _ _ _ => pure ()
afterImport : Array (Array (Name × α)) → ImportM Unit := fun _ => pure ()
def registerParametricAttribute {α : Type} [Inhabited α] (impl : ParametricAttributeImpl α) : IO (ParametricAttribute α) := do
let ext : PersistentEnvExtension (Name × α) (Name × α) (NameMap α) ← registerPersistentEnvExtension {
name := impl.name
mkInitial := pure {}
addImportedFn := fun s => impl.afterImport s *> pure {}
addEntryFn := fun (s : NameMap α) (p : Name × α) => s.insert p.1 p.2
exportEntriesFn := fun m =>
let r : Array (Name × α) := m.fold (fun a n p => a.push (n, p)) #[]
r.qsort (fun a b => Name.quickLt a.1 b.1)
statsFn := fun s => "parametric attribute" ++ Format.line ++ "number of local entries: " ++ format s.size
}
let attrImpl : AttributeImpl := {
ref := impl.ref
name := impl.name
descr := impl.descr
add := fun decl stx kind => do
unless kind == AttributeKind.global do throwError "invalid attribute '{impl.name}', must be global"
let env ← getEnv
unless (env.getModuleIdxFor? decl).isNone do
throwError "invalid attribute '{impl.name}', declaration is in an imported module"
let val ← impl.getParam decl stx
let env' := ext.addEntry env (decl, val)
setEnv env'
try impl.afterSet decl val catch _ => setEnv env
}
registerBuiltinAttribute attrImpl
pure { attr := attrImpl, ext := ext }
namespace ParametricAttribute
def getParam? {α : Type} [Inhabited α] (attr : ParametricAttribute α) (env : Environment) (decl : Name) : Option α :=
match env.getModuleIdxFor? decl with
| some modIdx =>
match (attr.ext.getModuleEntries env modIdx).binSearch (decl, default) (fun a b => Name.quickLt a.1 b.1) with
| some (_, val) => some val
| none => none
| none => (attr.ext.getState env).find? decl
def setParam {α : Type} (attr : ParametricAttribute α) (env : Environment) (decl : Name) (param : α) : Except String Environment :=
if (env.getModuleIdxFor? decl).isSome then
Except.error ("invalid '" ++ toString attr.attr.name ++ "'.setParam, declaration is in an imported module")
else if ((attr.ext.getState env).find? decl).isSome then
Except.error ("invalid '" ++ toString attr.attr.name ++ "'.setParam, attribute has already been set")
else
Except.ok (attr.ext.addEntry env (decl, param))
end ParametricAttribute
/--
Given a list `[a₁, ..., a_n]` of elements of type `α`, `EnumAttributes` provides an attribute `Attr_i` for
associating a value `a_i` with an declaration. `α` is usually an enumeration type.
Note that whenever we register an `EnumAttributes`, we create `n` attributes, but only one environment extension. -/
structure EnumAttributes (α : Type) where
attrs : List AttributeImpl
ext : PersistentEnvExtension (Name × α) (Name × α) (NameMap α)
deriving Inhabited
def registerEnumAttributes {α : Type} [Inhabited α] (extName : Name) (attrDescrs : List (Name × String × α))
(validate : Name → α → AttrM Unit := fun _ _ => pure ())
(applicationTime := AttributeApplicationTime.afterTypeChecking)
(ref : Name := by exact decl_name%) : IO (EnumAttributes α) := do
let ext : PersistentEnvExtension (Name × α) (Name × α) (NameMap α) ← registerPersistentEnvExtension {
name := extName
mkInitial := pure {}
addImportedFn := fun _ _ => pure {}
addEntryFn := fun (s : NameMap α) (p : Name × α) => s.insert p.1 p.2
exportEntriesFn := fun m =>
let r : Array (Name × α) := m.fold (fun a n p => a.push (n, p)) #[]
r.qsort (fun a b => Name.quickLt a.1 b.1)
statsFn := fun s => "enumeration attribute extension" ++ Format.line ++ "number of local entries: " ++ format s.size
}
let attrs := attrDescrs.map fun (name, descr, val) => {
ref := ref
name := name
descr := descr
add := fun decl stx kind => do
Attribute.Builtin.ensureNoArgs stx
unless kind == AttributeKind.global do throwError "invalid attribute '{name}', must be global"
let env ← getEnv
unless (env.getModuleIdxFor? decl).isNone do
throwError "invalid attribute '{name}', declaration is in an imported module"
validate decl val
setEnv <| ext.addEntry env (decl, val)
applicationTime := applicationTime
: AttributeImpl
}
attrs.forM registerBuiltinAttribute
pure { ext := ext, attrs := attrs }
namespace EnumAttributes
def getValue {α : Type} [Inhabited α] (attr : EnumAttributes α) (env : Environment) (decl : Name) : Option α :=
match env.getModuleIdxFor? decl with
| some modIdx =>
match (attr.ext.getModuleEntries env modIdx).binSearch (decl, default) (fun a b => Name.quickLt a.1 b.1) with
| some (_, val) => some val
| none => none
| none => (attr.ext.getState env).find? decl
def setValue {α : Type} (attrs : EnumAttributes α) (env : Environment) (decl : Name) (val : α) : Except String Environment :=
if (env.getModuleIdxFor? decl).isSome then
Except.error ("invalid '" ++ toString attrs.ext.name ++ "'.setValue, declaration is in an imported module")
else if ((attrs.ext.getState env).find? decl).isSome then
Except.error ("invalid '" ++ toString attrs.ext.name ++ "'.setValue, attribute has already been set")
else
Except.ok (attrs.ext.addEntry env (decl, val))
end EnumAttributes
/-!
Attribute extension and builders. We use builders to implement attribute factories for parser categories.
-/
abbrev AttributeImplBuilder := Name → List DataValue → Except String AttributeImpl
abbrev AttributeImplBuilderTable := Std.HashMap Name AttributeImplBuilder
builtin_initialize attributeImplBuilderTableRef : IO.Ref AttributeImplBuilderTable ← IO.mkRef {}
def registerAttributeImplBuilder (builderId : Name) (builder : AttributeImplBuilder) : IO Unit := do
let table ← attributeImplBuilderTableRef.get
if table.contains builderId then throw (IO.userError ("attribute implementation builder '" ++ toString builderId ++ "' has already been declared"))
attributeImplBuilderTableRef.modify fun table => table.insert builderId builder
def mkAttributeImplOfBuilder (builderId ref : Name) (args : List DataValue) : IO AttributeImpl := do
let table ← attributeImplBuilderTableRef.get
match table.find? builderId with
| none => throw (IO.userError ("unknown attribute implementation builder '" ++ toString builderId ++ "'"))
| some builder => IO.ofExcept <| builder ref args
inductive AttributeExtensionOLeanEntry where
| decl (declName : Name) -- `declName` has type `AttributeImpl`
| builder (builderId ref : Name) (args : List DataValue)
structure AttributeExtensionState where
newEntries : List AttributeExtensionOLeanEntry := []
map : PersistentHashMap Name AttributeImpl
deriving Inhabited
abbrev AttributeExtension := PersistentEnvExtension AttributeExtensionOLeanEntry (AttributeExtensionOLeanEntry × AttributeImpl) AttributeExtensionState
private def AttributeExtension.mkInitial : IO AttributeExtensionState := do
let map ← attributeMapRef.get
pure { map := map }
unsafe def mkAttributeImplOfConstantUnsafe (env : Environment) (opts : Options) (declName : Name) : Except String AttributeImpl :=
match env.find? declName with
| none => throw ("unknow constant '" ++ toString declName ++ "'")
| some info =>
match info.type with
| Expr.const `Lean.AttributeImpl _ => env.evalConst AttributeImpl opts declName
| _ => throw ("unexpected attribute implementation type at '" ++ toString declName ++ "' (`AttributeImpl` expected")
@[implementedBy mkAttributeImplOfConstantUnsafe]
opaque mkAttributeImplOfConstant (env : Environment) (opts : Options) (declName : Name) : Except String AttributeImpl
def mkAttributeImplOfEntry (env : Environment) (opts : Options) (e : AttributeExtensionOLeanEntry) : IO AttributeImpl :=
match e with
| .decl declName => IO.ofExcept <| mkAttributeImplOfConstant env opts declName
| .builder builderId ref args => mkAttributeImplOfBuilder builderId ref args
private def AttributeExtension.addImported (es : Array (Array AttributeExtensionOLeanEntry)) : ImportM AttributeExtensionState := do
let ctx ← read
let map ← attributeMapRef.get
let map ← es.foldlM
(fun map entries =>
entries.foldlM
(fun (map : PersistentHashMap Name AttributeImpl) entry => do
let attrImpl ← mkAttributeImplOfEntry ctx.env ctx.opts entry
return map.insert attrImpl.name attrImpl)
map)
map
pure { map := map }
private def addAttrEntry (s : AttributeExtensionState) (e : AttributeExtensionOLeanEntry × AttributeImpl) : AttributeExtensionState :=
{ s with map := s.map.insert e.2.name e.2, newEntries := e.1 :: s.newEntries }
builtin_initialize attributeExtension : AttributeExtension ←
registerPersistentEnvExtension {
name := `attrExt
mkInitial := AttributeExtension.mkInitial
addImportedFn := AttributeExtension.addImported
addEntryFn := addAttrEntry
exportEntriesFn := fun s => s.newEntries.reverse.toArray
statsFn := fun s => format "number of local entries: " ++ format s.newEntries.length
}
/-- Return true iff `n` is the name of a registered attribute. -/
@[export lean_is_attribute]
def isBuiltinAttribute (n : Name) : IO Bool := do
let m ← attributeMapRef.get; pure (m.contains n)
/-- Return the name of all registered attributes. -/
def getBuiltinAttributeNames : IO (List Name) :=
return (← attributeMapRef.get).foldl (init := []) fun r n _ => n::r
def getBuiltinAttributeImpl (attrName : Name) : IO AttributeImpl := do
let m ← attributeMapRef.get
match m.find? attrName with
| some attr => pure attr
| none => throw (IO.userError ("unknown attribute '" ++ toString attrName ++ "'"))
@[export lean_attribute_application_time]
def getBuiltinAttributeApplicationTime (n : Name) : IO AttributeApplicationTime := do
let attr ← getBuiltinAttributeImpl n
pure attr.applicationTime
def isAttribute (env : Environment) (attrName : Name) : Bool :=
(attributeExtension.getState env).map.contains attrName
def getAttributeNames (env : Environment) : List Name :=
let m := (attributeExtension.getState env).map
m.foldl (fun r n _ => n::r) []
def getAttributeImpl (env : Environment) (attrName : Name) : Except String AttributeImpl :=
let m := (attributeExtension.getState env).map
match m.find? attrName with
| some attr => pure attr
| none => throw ("unknown attribute '" ++ toString attrName ++ "'")
def registerAttributeOfDecl (env : Environment) (opts : Options) (attrDeclName : Name) : Except String Environment := do
let attrImpl ← mkAttributeImplOfConstant env opts attrDeclName
if isAttribute env attrImpl.name then
throw ("invalid builtin attribute declaration, '" ++ toString attrImpl.name ++ "' has already been used")
else
return attributeExtension.addEntry env (.decl attrDeclName, attrImpl)
def registerAttributeOfBuilder (env : Environment) (builderId ref : Name) (args : List DataValue) : IO Environment := do
let attrImpl ← mkAttributeImplOfBuilder builderId ref args
if isAttribute env attrImpl.name then
throw (IO.userError ("invalid builtin attribute declaration, '" ++ toString attrImpl.name ++ "' has already been used"))
else
return attributeExtension.addEntry env (.builder builderId ref args, attrImpl)
def Attribute.add (declName : Name) (attrName : Name) (stx : Syntax) (kind := AttributeKind.global) : AttrM Unit := do
let attr ← ofExcept <| getAttributeImpl (← getEnv) attrName
attr.add declName stx kind
def Attribute.erase (declName : Name) (attrName : Name) : AttrM Unit := do
let attr ← ofExcept <| getAttributeImpl (← getEnv) attrName
attr.erase declName
/-- `updateEnvAttributes` implementation -/
@[export lean_update_env_attributes]
def updateEnvAttributesImpl (env : Environment) : IO Environment := do
let map ← attributeMapRef.get
let s := attributeExtension.getState env
let s := map.foldl (init := s) fun s attrName attrImpl =>
if s.map.contains attrName then
s
else
{ s with map := s.map.insert attrName attrImpl }
return attributeExtension.setState env s
/-- `getNumBuiltinAttributes` implementation -/
@[export lean_get_num_attributes] def getNumBuiltiAttributesImpl : IO Nat :=
return (← attributeMapRef.get).size
end Lean
|
e292dc03179a0e846fc4f6ace13187a87a4bab80 | 36c7a18fd72e5b57229bd8ba36493daf536a19ce | /library/theories/group_theory/perm.lean | b415bd686fffa8a944b765ea9a6df68f9b1b2d7d | [
"Apache-2.0"
] | permissive | YHVHvx/lean | 732bf0fb7a298cd7fe0f15d82f8e248c11db49e9 | 038369533e0136dd395dc252084d3c1853accbf2 | refs/heads/master | 1,610,701,080,210 | 1,449,128,595,000 | 1,449,128,595,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,145 | lean | /-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Haitao Zhang
-/
import algebra.group data data.fintype.function
open nat list algebra function
namespace group
open fintype
section perm
variable {A : Type}
variable [finA : fintype A]
include finA
variable [deceqA : decidable_eq A]
include deceqA
variable {f : A → A}
lemma perm_surj : injective f → surjective f :=
surj_of_inj_eq_card (eq.refl (card A))
variable (perm : injective f)
definition perm_inv : A → A :=
right_inv (perm_surj perm)
lemma perm_inv_right : f ∘ (perm_inv perm) = id :=
right_inv_of_surj (perm_surj perm)
lemma perm_inv_left : (perm_inv perm) ∘ f = id :=
have H : left_inverse f (perm_inv perm), from congr_fun (perm_inv_right perm),
funext (take x, right_inverse_of_injective_of_left_inverse perm H x)
lemma perm_inv_inj : injective (perm_inv perm) :=
injective_of_has_left_inverse (exists.intro f (congr_fun (perm_inv_right perm)))
end perm
structure perm (A : Type) [h : fintype A] : Type :=
(f : A → A) (inj : injective f)
local attribute perm.f [coercion]
section perm
variable {A : Type}
variable [finA : fintype A]
include finA
lemma eq_of_feq : ∀ {p₁ p₂ : perm A}, (perm.f p₁) = p₂ → p₁ = p₂
| (perm.mk f₁ P₁) (perm.mk f₂ P₂) := assume (feq : f₁ = f₂), by congruence; assumption
lemma feq_of_eq : ∀ {p₁ p₂ : perm A}, p₁ = p₂ → (perm.f p₁) = p₂
| (perm.mk f₁ P₁) (perm.mk f₂ P₂) := assume Peq,
have feq : f₁ = f₂, from perm.no_confusion Peq (λ Pe Pqe, Pe), feq
lemma eq_iff_feq {p₁ p₂ : perm A} : (perm.f p₁) = p₂ ↔ p₁ = p₂ :=
iff.intro eq_of_feq feq_of_eq
lemma perm.f_mk {f : A → A} {Pinj : injective f} : perm.f (perm.mk f Pinj) = f := rfl
definition move_by [reducible] (a : A) (f : perm A) : A := f a
variable [deceqA : decidable_eq A]
include deceqA
lemma perm.has_decidable_eq [instance] : decidable_eq (perm A) :=
take f g,
perm.destruct f (λ ff finj, perm.destruct g (λ gf ginj,
decidable.rec_on (decidable_eq_fun ff gf)
(λ Peq, decidable.inl (by substvars))
(λ Pne, decidable.inr begin intro P, injection P, contradiction end)))
lemma dinj_perm_mk : dinj (@injective A A) perm.mk :=
take a₁ a₂ Pa₁ Pa₂ Pmkeq, perm.no_confusion Pmkeq (λ Pe Pqe, Pe)
definition all_perms : list (perm A) :=
dmap injective perm.mk (all_injs A)
lemma nodup_all_perms : nodup (@all_perms A _ _) :=
dmap_nodup_of_dinj dinj_perm_mk nodup_all_injs
lemma all_perms_complete : ∀ p : perm A, p ∈ all_perms :=
take p, perm.destruct p (take f Pinj,
assert Pin : f ∈ all_injs A, from all_injs_complete Pinj,
mem_dmap Pinj Pin)
definition perm_is_fintype [instance] : fintype (perm A) :=
fintype.mk all_perms nodup_all_perms all_perms_complete
definition perm.mul (f g : perm A) :=
perm.mk (f∘g) (injective_compose (perm.inj f) (perm.inj g))
definition perm.one [reducible] : perm A := perm.mk id injective_id
definition perm.inv (f : perm A) := let inj := perm.inj f in
perm.mk (perm_inv inj) (perm_inv_inj inj)
local infix `^` := perm.mul
lemma perm.assoc (f g h : perm A) : f ^ g ^ h = f ^ (g ^ h) := rfl
lemma perm.one_mul (p : perm A) : perm.one ^ p = p :=
perm.cases_on p (λ f inj, rfl)
lemma perm.mul_one (p : perm A) : p ^ perm.one = p :=
perm.cases_on p (λ f inj, rfl)
lemma perm.left_inv (p : perm A) : (perm.inv p) ^ p = perm.one :=
begin rewrite [↑perm.one], generalize @injective_id A,
rewrite [-perm_inv_left (perm.inj p)], intros, exact rfl
end
lemma perm.right_inv (p : perm A) : p ^ (perm.inv p) = perm.one :=
begin rewrite [↑perm.one], generalize @injective_id A,
rewrite [-perm_inv_right (perm.inj p)], intros, exact rfl
end
definition perm_group [instance] : group (perm A) :=
group.mk perm.mul perm.assoc perm.one perm.one_mul perm.mul_one perm.inv perm.left_inv
lemma perm_one : (1 : perm A) = perm.one := rfl
end perm
end group
|
470d66ab36c53ff9261bdf7b1305b7c686448c75 | 69b400b14d8b9f598d16e57d334c8a68910f3584 | /prep/alg-geom/src/ex.lean | 94bf488457d2c1cb917a133c3be7fbdee7de38b6 | [] | no_license | TwoFX/partiii | e8cf563d9f7074a45eb35928bf7eb7dfd38ea29e | b949b1f7599ef35a1c1856ba6e9d1fddb245bcd9 | refs/heads/master | 1,683,178,340,068 | 1,622,049,944,000 | 1,622,049,944,000 | 304,524,313 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,379 | lean | import data.mv_polynomial.comm_ring
import ring_theory.ideal.basic
open mv_polynomial
variables {k : Type*} [field k] {n : ℕ}
def is_affine_variety (V : set (fin n → k)) : Prop :=
∃ F : set (mv_polynomial (fin n) k), F.finite ∧
∀ x, x ∈ V ↔ ∀ (f : mv_polynomial (fin n) k), f ∈ F → eval x f = 0
def I (V : set (fin n → k)) : set (mv_polynomial (fin n) k) :=
{ f | ∀ x ∈ V, eval x f = 0 }
def V (I : set (mv_polynomial (fin n) k)) : set (fin n → k) :=
{ x | ∀ f ∈ I, eval x f = 0 }
lemma I_empty : I (∅ : set (fin n → k)) = set.univ :=
begin
rw set.eq_univ_iff_forall,
intros f x,
simp only [set.mem_empty_eq, forall_prop_of_false, not_false_iff]
end
theorem ex_1 (I₁ I₂ : set (mv_polynomial (fin n) k)) (h : I₁ ⊆ I₂) : V I₂ ⊆ V I₁ :=
λ x hx f hf, hx _ (h hf)
theorem ex_2 (V₁ V₂ : set (fin n → k)) (h : V₁ ⊆ V₂) : I V₂ ⊆ I V₁ :=
λ x hx f hf, hx _ (h hf)
theorem ex_3 (V₁ : set (fin n → k)) : is_affine_variety V₁ → V (I V₁) = V₁ :=
begin
rintro ⟨F, ⟨-, hF⟩⟩,
have hF' : F ⊆ I V₁ := λ f hf x hx, (hF x).1 hx _ hf,
apply set.subset.antisymm,
{ exact λ x hx, (hF x).2 (λ f hf, hx _ (hF' hf)) },
{ exact λ x hx f hf, hf _ hx }
end
def rad (I : set (mv_polynomial (fin n) k)) : set (mv_polynomial (fin n) k) :=
{ f | ∃ m : ℕ, f ^ m ∈ I }
lemma rad_eq (I : ideal (mv_polynomial (fin n) k)) :
rad I.carrier = { f | ∃ m : ℕ, 0 < m ∧ f ^ m ∈ I } :=
begin
apply set.subset.antisymm,
{ rintros f ⟨m, hm⟩,
by_cases h : 0 < m,
{ exact ⟨m, ⟨h, hm⟩⟩ },
simp only [le_zero_iff_eq, not_lt] at h,
subst h,
change f ^ 0 ∈ I at hm,
simp only [pow_zero, ←ideal.eq_top_iff_one] at hm,
subst hm,
exact ⟨1, ⟨dec_trivial, submodule.mem_top⟩⟩ },
{ rintros f ⟨m, ⟨-, hm⟩⟩,
exact ⟨m, hm⟩ }
end
theorem lem {f : mv_polynomial (fin n) k} {m : ℕ} {x : fin n → k}
(hfx : eval x (f^m) = 0) : eval x f = 0 :=
begin
induction m with m hm,
{ rw [pow_zero, ring_hom.map_one] at hfx,
exact false.elim (one_ne_zero hfx) },
{ rw [pow_succ, ring_hom.map_mul] at hfx,
cases eq_zero_or_eq_zero_of_mul_eq_zero hfx,
{ exact h },
{ exact hm h } }
end
theorem ex_4 (I₁ : set (mv_polynomial (fin n) k)) : rad I₁ ⊆ I (V I₁) :=
λ f ⟨m, hfm⟩ x hx, lem (hx _ hfm) |
8acc439313c2addec97ea32952be99985a0b0a7d | 4727251e0cd73359b15b664c3170e5d754078599 | /src/group_theory/subsemigroup/centralizer.lean | 765fa4adf65f8013f823a6f7ca96e2a3fe69b030 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 4,848 | lean | /-
Copyright (c) 2021 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning, Jireh Loreaux
-/
import group_theory.subsemigroup.center
/-!
# Centralizers of magmas and semigroups
## Main definitions
* `set.centralizer`: the centralizer of a subset of a magma
* `subsemigroup.centralizer`: the centralizer of a subset of a semigroup
* `set.add_centralizer`: the centralizer of a subset of an additive magma
* `add_subsemigroup.centralizer`: the centralizer of a subset of an additive semigroup
We provide `monoid.centralizer`, `add_monoid.centralizer`, `subgroup.centralizer`, and
`add_subgroup.centralizer` in other files.
-/
variables {M : Type*} {S T : set M}
namespace set
variables (S)
/-- The centralizer of a subset of a magma. -/
@[to_additive add_centralizer /-" The centralizer of a subset of an additive magma. "-/]
def centralizer [has_mul M] : set M := {c | ∀ m ∈ S, m * c = c * m}
variables {S}
@[to_additive mem_add_centralizer]
lemma mem_centralizer_iff [has_mul M] {c : M} : c ∈ centralizer S ↔ ∀ m ∈ S, m * c = c * m :=
iff.rfl
@[to_additive decidable_mem_add_centralizer]
instance decidable_mem_centralizer [has_mul M] [decidable_eq M] [fintype M]
[decidable_pred (∈ S)] : decidable_pred (∈ centralizer S) :=
λ _, decidable_of_iff' _ (mem_centralizer_iff)
variables (S)
@[simp, to_additive zero_mem_add_centralizer]
lemma one_mem_centralizer [mul_one_class M] : (1 : M) ∈ centralizer S :=
by simp [mem_centralizer_iff]
@[simp]
lemma zero_mem_centralizer [mul_zero_class M] : (0 : M) ∈ centralizer S :=
by simp [mem_centralizer_iff]
variables {S} {a b : M}
@[simp, to_additive add_mem_add_centralizer]
lemma mul_mem_centralizer [semigroup M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a * b ∈ centralizer S :=
λ g hg, by rw [mul_assoc, ←hb g hg, ← mul_assoc, ha g hg, mul_assoc]
@[simp, to_additive neg_mem_add_centralizer]
lemma inv_mem_centralizer [group M] (ha : a ∈ centralizer S) : a⁻¹ ∈ centralizer S :=
λ g hg, by rw [mul_inv_eq_iff_eq_mul, mul_assoc, eq_inv_mul_iff_mul_eq, ha g hg]
@[simp]
lemma add_mem_centralizer [distrib M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a + b ∈ centralizer S :=
λ c hc, by rw [add_mul, mul_add, ha c hc, hb c hc]
@[simp]
lemma neg_mem_centralizer [has_mul M] [has_distrib_neg M] (ha : a ∈ centralizer S) :
-a ∈ centralizer S :=
λ c hc, by rw [mul_neg, ha c hc, neg_mul]
@[simp]
lemma inv_mem_centralizer₀ [group_with_zero M] (ha : a ∈ centralizer S) : a⁻¹ ∈ centralizer S :=
(eq_or_ne a 0).elim (λ h, by { rw [h, inv_zero], exact zero_mem_centralizer S })
(λ ha0 c hc, by rw [mul_inv_eq_iff_eq_mul₀ ha0, mul_assoc, eq_inv_mul_iff_mul_eq₀ ha0, ha c hc])
@[simp, to_additive sub_mem_add_centralizer]
lemma div_mem_centralizer [group M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a / b ∈ centralizer S :=
begin
rw [div_eq_mul_inv],
exact mul_mem_centralizer ha (inv_mem_centralizer hb),
end
@[simp]
lemma div_mem_centralizer₀ [group_with_zero M] (ha : a ∈ centralizer S) (hb : b ∈ centralizer S) :
a / b ∈ centralizer S :=
begin
rw div_eq_mul_inv,
exact mul_mem_centralizer ha (inv_mem_centralizer₀ hb),
end
@[to_additive add_centralizer_subset]
lemma centralizer_subset [has_mul M] (h : S ⊆ T) : centralizer T ⊆ centralizer S :=
λ t ht s hs, ht s (h hs)
variables (M)
@[simp, to_additive add_centralizer_univ]
lemma centralizer_univ [has_mul M] : centralizer univ = center M :=
subset.antisymm (λ a ha b, ha b (set.mem_univ b)) (λ a ha b hb, ha b)
variables {M} (S)
@[simp, to_additive add_centralizer_eq_univ]
lemma centralizer_eq_univ [comm_semigroup M] : centralizer S = univ :=
subset.antisymm (subset_univ _) $ λ x hx y hy, mul_comm y x
end set
namespace subsemigroup
section
variables {M} [semigroup M] (S)
/-- The centralizer of a subset of a semigroup `M`. -/
@[to_additive "The centralizer of a subset of an additive semigroup."]
def centralizer : subsemigroup M :=
{ carrier := S.centralizer,
mul_mem' := λ a b, set.mul_mem_centralizer }
@[simp, norm_cast, to_additive] lemma coe_centralizer : ↑(centralizer S) = S.centralizer := rfl
variables {S}
@[to_additive] lemma mem_centralizer_iff {z : M} : z ∈ centralizer S ↔ ∀ g ∈ S, g * z = z * g :=
iff.rfl
@[to_additive] instance decidable_mem_centralizer [decidable_eq M] [fintype M]
[decidable_pred (∈ S)] : decidable_pred (∈ centralizer S) :=
λ _, decidable_of_iff' _ mem_centralizer_iff
@[to_additive]
lemma centralizer_le (h : S ⊆ T) : centralizer T ≤ centralizer S :=
set.centralizer_subset h
variables (M)
@[simp, to_additive]
lemma centralizer_univ : centralizer set.univ = center M :=
set_like.ext' (set.centralizer_univ M)
end
end subsemigroup
|
b7d497321a4a6cb0b0f7971f0a82420815aa66e4 | d1bbf1801b3dcb214451d48214589f511061da63 | /src/field_theory/fixed.lean | 0e25720eee1aa2045d7abd6b0c24ef5eff2745d3 | [
"Apache-2.0"
] | permissive | cheraghchi/mathlib | 5c366f8c4f8e66973b60c37881889da8390cab86 | f29d1c3038422168fbbdb2526abf7c0ff13e86db | refs/heads/master | 1,676,577,831,283 | 1,610,894,638,000 | 1,610,894,638,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,472 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.polynomial.group_ring_action
import deprecated.subfield
import field_theory.normal
import field_theory.separable
import field_theory.tower
import linear_algebra.matrix
import ring_theory.polynomial
/-!
# Fixed field under a group action.
This is the basis of the Fundamental Theorem of Galois Theory.
Given a (finite) group `G` that acts on a field `F`, we define `fixed_points G F`,
the subfield consisting of elements of `F` fixed_points by every element of `G`.
This subfield is then normal and separable, and in addition (TODO) if `G` acts faithfully on `F`
then `findim (fixed_points G F) F = fintype.card G`.
## Main Definitions
- `fixed_points G F`, the subfield consisting of elements of `F` fixed_points by every element of `G`, where
`G` is a group that acts on `F`.
-/
noncomputable theory
open_locale classical big_operators
open mul_action finset finite_dimensional
universes u v w
variables (G : Type u) [group G] (F : Type v) [field F] [mul_semiring_action G F] (g : G)
instance fixed_by.is_subfield : is_subfield (fixed_by G F g) :=
{ zero_mem := smul_zero g,
add_mem := λ x y hx hy, (smul_add g x y).trans $ congr_arg2 _ hx hy,
neg_mem := λ x hx, (smul_neg g x).trans $ congr_arg _ hx,
one_mem := smul_one g,
mul_mem := λ x y hx hy, (smul_mul' g x y).trans $ congr_arg2 _ hx hy,
inv_mem := λ x hx, (smul_inv F g x).trans $ congr_arg _ hx }
namespace fixed_points
instance : is_subfield (fixed_points G F) :=
by convert @is_subfield.Inter F _ G (fixed_by G F) _; rw fixed_eq_Inter_fixed_by
instance : is_invariant_subring G (fixed_points G F) :=
{ smul_mem := λ g x hx g', by rw [hx, hx] }
@[simp] theorem smul (g : G) (x : fixed_points G F) : g • x = x :=
subtype.eq $ x.2 g
-- Why is this so slow?
@[simp] theorem smul_polynomial (g : G) (p : polynomial (fixed_points G F)) : g • p = p :=
polynomial.induction_on p
(λ x, by rw [polynomial.smul_C, smul])
(λ p q ihp ihq, by rw [smul_add, ihp, ihq])
(λ n x ih, by rw [smul_mul', polynomial.smul_C, smul, smul_pow, polynomial.smul_X])
instance : algebra (fixed_points G F) F :=
algebra.of_is_subring _
theorem coe_algebra_map :
algebra_map (fixed_points G F) F = is_subring.subtype (fixed_points G F) :=
rfl
lemma linear_independent_smul_of_linear_independent {s : finset F} :
linear_independent (fixed_points G F) (λ i : (↑s : set F), (i : F)) →
linear_independent F (λ i : (↑s : set F), mul_action.to_fun G F i) :=
begin
refine finset.induction_on s (λ _, linear_independent_empty_type $ λ ⟨x⟩, x.2) (λ a s has ih hs, _),
rw coe_insert at hs ⊢,
rw linear_independent_insert (mt mem_coe.1 has) at hs,
rw linear_independent_insert' (mt mem_coe.1 has), refine ⟨ih hs.1, λ ha, _⟩,
rw finsupp.mem_span_iff_total at ha, rcases ha with ⟨l, hl, hla⟩,
rw [finsupp.total_apply_of_mem_supported F hl] at hla,
suffices : ∀ i ∈ s, l i ∈ fixed_points G F,
{ replace hla := (sum_apply _ _ (λ i, l i • to_fun G F i)).symm.trans (congr_fun hla 1),
simp_rw [pi.smul_apply, to_fun_apply, one_smul] at hla,
refine hs.2 (hla ▸ submodule.sum_mem _ (λ c hcs, _)),
change (⟨l c, this c hcs⟩ : fixed_points G F) • c ∈ _,
exact submodule.smul_mem _ _ (submodule.subset_span $ mem_coe.2 hcs) },
intros i his g,
refine eq_of_sub_eq_zero (linear_independent_iff'.1 (ih hs.1) s.attach (λ i, g • l i - l i) _
⟨i, his⟩ (mem_attach _ _) : _),
refine (@sum_attach _ _ s _ (λ i, (g • l i - l i) • (to_fun G F) i)).trans _, ext g', dsimp only,
conv_lhs { rw sum_apply, congr, skip, funext, rw [pi.smul_apply, sub_smul, smul_eq_mul] },
rw [sum_sub_distrib, pi.zero_apply, sub_eq_zero],
conv_lhs { congr, skip, funext,
rw [to_fun_apply, ← mul_inv_cancel_left g g', mul_smul, ← smul_mul', ← to_fun_apply _ x] },
show ∑ x in s, g • (λ y, l y • to_fun G F y) x (g⁻¹ * g') =
∑ x in s, (λ y, l y • to_fun G F y) x g',
rw [← smul_sum, ← sum_apply _ _ (λ y, l y • to_fun G F y),
← sum_apply _ _ (λ y, l y • to_fun G F y)], dsimp only,
rw [hla, to_fun_apply, to_fun_apply, smul_smul, mul_inv_cancel_left]
end
variables [fintype G] (x : F)
/-- `minpoly G F x` is the minimal polynomial of `(x : F)` over `fixed_points G F`. -/
def minpoly : polynomial (fixed_points G F) :=
(prod_X_sub_smul G F x).to_subring _ $ λ c hc g,
let ⟨hc0, n, hn⟩ := finsupp.mem_frange.1 hc in hn ▸ prod_X_sub_smul.coeff G F x g n
namespace minpoly
theorem monic : (minpoly G F x).monic :=
subtype.eq $ prod_X_sub_smul.monic G F x
theorem eval₂ :
polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x (minpoly G F x) = 0 :=
begin
rw [← prod_X_sub_smul.eval G F x, polynomial.eval₂_eq_eval_map],
simp [minpoly],
end
theorem ne_one :
minpoly G F x ≠ (1 : polynomial (fixed_points G F)) :=
λ H, have _ := eval₂ G F x,
(one_ne_zero : (1 : F) ≠ 0) $ by rwa [H, polynomial.eval₂_one] at this
theorem of_eval₂ (f : polynomial (fixed_points G F))
(hf : polynomial.eval₂ (is_subring.subtype $ fixed_points G F) x f = 0) :
minpoly G F x ∣ f :=
begin
rw [← polynomial.map_dvd_map' (is_subring.subtype $ fixed_points G F),
minpoly, polynomial.map_to_subring, prod_X_sub_smul],
refine fintype.prod_dvd_of_coprime
(polynomial.pairwise_coprime_X_sub $ mul_action.injective_of_quotient_stabilizer G x)
(λ y, quotient_group.induction_on y $ λ g, _),
rw [polynomial.dvd_iff_is_root, polynomial.is_root.def, mul_action.of_quotient_stabilizer_mk,
polynomial.eval_smul', ← is_invariant_subring.coe_subtype_hom' G (fixed_points G F),
← mul_semiring_action_hom.coe_polynomial, ← mul_semiring_action_hom.map_smul,
smul_polynomial, mul_semiring_action_hom.coe_polynomial,
is_invariant_subring.coe_subtype_hom', polynomial.eval_map, hf, smul_zero]
end
/- Why is this so slow? -/
theorem irreducible_aux (f g : polynomial (fixed_points G F))
(hf : f.monic) (hg : g.monic) (hfg : f * g = minpoly G F x) :
f = 1 ∨ g = 1 :=
begin
have hf2 : f ∣ minpoly G F x,
{ rw ← hfg, exact dvd_mul_right _ _ },
have hg2 : g ∣ minpoly G F x,
{ rw ← hfg, exact dvd_mul_left _ _ },
have := eval₂ G F x,
rw [← hfg, polynomial.eval₂_mul, mul_eq_zero] at this,
cases this,
{ right,
have hf3 : f = minpoly G F x,
{ exact polynomial.eq_of_monic_of_associated hf (monic G F x)
(associated_of_dvd_dvd hf2 $ @of_eval₂ G _ F _ _ _ x f this) },
rwa [← mul_one (minpoly G F x), hf3,
mul_right_inj' (monic G F x).ne_zero] at hfg },
{ left,
have hg3 : g = minpoly G F x,
{ exact polynomial.eq_of_monic_of_associated hg (monic G F x)
(associated_of_dvd_dvd hg2 $ @of_eval₂ G _ F _ _ _ x g this) },
rwa [← one_mul (minpoly G F x), hg3,
mul_left_inj' (monic G F x).ne_zero] at hfg }
end
theorem irreducible : irreducible (minpoly G F x) :=
(polynomial.irreducible_of_monic (monic G F x) (ne_one G F x)).2 (irreducible_aux G F x)
end minpoly
theorem is_integral : is_integral (fixed_points G F) x :=
⟨minpoly G F x, minpoly.monic G F x, minpoly.eval₂ G F x⟩
theorem minpoly_eq_minpoly :
minpoly G F x = _root_.minpoly (is_integral G F x) :=
minpoly.unique' _ (minpoly.irreducible G F x)
(minpoly.eval₂ G F x) (minpoly.monic G F x)
instance normal : normal (fixed_points G F) F :=
λ x, ⟨is_integral G F x, (polynomial.splits_id_iff_splits _).1 $
by { rw [← minpoly_eq_minpoly, minpoly,
coe_algebra_map, polynomial.map_to_subring, prod_X_sub_smul],
exact polynomial.splits_prod _ (λ _ _, polynomial.splits_X_sub_C _) }⟩
instance separable : is_separable (fixed_points G F) F :=
λ x, ⟨is_integral G F x,
by { rw [← minpoly_eq_minpoly,
← polynomial.separable_map (is_subring.subtype (fixed_points G F)),
minpoly, polynomial.map_to_subring],
exact polynomial.separable_prod_X_sub_C_iff.2 (injective_of_quotient_stabilizer G x) }⟩
lemma dim_le_card : vector_space.dim (fixed_points G F) F ≤ fintype.card G :=
begin
refine dim_le (λ s hs, cardinal.nat_cast_le.1 _),
rw [← @dim_fun' F G, ← cardinal.lift_nat_cast.{v (max u v)},
cardinal.finset_card, ← cardinal.lift_id (vector_space.dim F (G → F))],
exact linear_independent_le_dim'.{_ _ _ (max u v)}
(linear_independent_smul_of_linear_independent G F hs)
end
instance : finite_dimensional (fixed_points G F) F :=
finite_dimensional.finite_dimensional_iff_dim_lt_omega.2 $
lt_of_le_of_lt (dim_le_card G F) (cardinal.nat_lt_omega _)
lemma findim_le_card : findim (fixed_points G F) F ≤ fintype.card G :=
by exact_mod_cast trans_rel_right (≤) (findim_eq_dim _ _) (dim_le_card G F)
end fixed_points
lemma linear_independent_to_linear_map (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [integral_domain A] [algebra R A] [integral_domain B] [algebra R B] :
linear_independent B (alg_hom.to_linear_map : (A →ₐ[R] B) → (A →ₗ[R] B)) :=
have linear_independent B (linear_map.lto_fun R A B ∘ alg_hom.to_linear_map),
from ((linear_independent_monoid_hom A B).comp
(coe : (A →ₐ[R] B) → (A →* B))
(λ f g hfg, alg_hom.ext $ monoid_hom.ext_iff.1 hfg) : _),
this.of_comp _
lemma cardinal_mk_alg_hom (K : Type u) (V : Type v) (W : Type w)
[field K] [field V] [algebra K V] [finite_dimensional K V]
[field W] [algebra K W] [finite_dimensional K W] :
cardinal.mk (V →ₐ[K] W) ≤ findim W (V →ₗ[K] W) :=
cardinal_mk_le_findim_of_linear_independent $ linear_independent_to_linear_map K V W
noncomputable instance alg_hom.fintype (K : Type u) (V : Type v) (W : Type w)
[field K] [field V] [algebra K V] [finite_dimensional K V]
[field W] [algebra K W] [finite_dimensional K W] :
fintype (V →ₐ[K] W) :=
classical.choice $ cardinal.lt_omega_iff_fintype.1 $
lt_of_le_of_lt (cardinal_mk_alg_hom K V W) (cardinal.nat_lt_omega _)
noncomputable instance alg_equiv.fintype (K : Type u) (V : Type v)
[field K] [field V] [algebra K V] [finite_dimensional K V] :
fintype (V ≃ₐ[K] V) :=
fintype.of_equiv (V →ₐ[K] V) (alg_equiv_equiv_alg_hom K V).symm
lemma findim_alg_hom (K : Type u) (V : Type v)
[field K] [field V] [algebra K V] [finite_dimensional K V] :
fintype.card (V →ₐ[K] V) ≤ findim V (V →ₗ[K] V) :=
fintype_card_le_findim_of_linear_independent $ linear_independent_to_linear_map K V V
namespace fixed_points
/-- Embedding produced from a faithful action. -/
@[simps apply {fully_applied := ff}]
def to_alg_hom (G : Type u) (F : Type v) [group G] [field F]
[faithful_mul_semiring_action G F] : G ↪ (F →ₐ[fixed_points G F] F) :=
{ to_fun := λ g, { commutes' := λ x, x.2 g,
.. mul_semiring_action.to_semiring_hom G F g },
inj' := λ g₁ g₂ hg, injective_to_semiring_hom G F $ ring_hom.ext $ λ x, alg_hom.ext_iff.1 hg x, }
lemma to_alg_hom_apply_apply {G : Type u} {F : Type v} [group G] [field F]
[faithful_mul_semiring_action G F] (g : G) (x : F) :
to_alg_hom G F g x = g • x :=
rfl
theorem findim_eq_card (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [faithful_mul_semiring_action G F] :
findim (fixed_points G F) F = fintype.card G :=
le_antisymm (fixed_points.findim_le_card G F) $
calc fintype.card G
≤ fintype.card (F →ₐ[fixed_points G F] F) : fintype.card_le_of_injective _ (to_alg_hom G F).2
... ≤ findim F (F →ₗ[fixed_points G F] F) : findim_alg_hom (fixed_points G F) F
... = findim (fixed_points G F) F : findim_linear_map' _ _ _
theorem to_alg_hom_bijective (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [faithful_mul_semiring_action G F] :
function.bijective (to_alg_hom G F) :=
begin
rw fintype.bijective_iff_injective_and_card,
split,
{ exact (to_alg_hom G F).injective },
{ apply le_antisymm,
{ exact fintype.card_le_of_injective _ (to_alg_hom G F).injective },
{ rw ← findim_eq_card G F,
exact has_le.le.trans_eq (findim_alg_hom _ F) (findim_linear_map' _ _ _) } },
end
/-- Bijection between G and algebra homomorphisms that fix the fixed points -/
def to_alg_hom_equiv (G : Type u) (F : Type v) [group G] [field F]
[fintype G] [faithful_mul_semiring_action G F] : G ≃ (F →ₐ[fixed_points G F] F) :=
function.embedding.equiv_of_surjective (to_alg_hom G F) (to_alg_hom_bijective G F).2
end fixed_points
|
002106d0d9d0cc9492d99167d65dda61bb729d71 | 4a092885406df4e441e9bb9065d9405dacb94cd8 | /src/for_mathlib/topological_rings.lean | dd8db84e5bdef7083a2077fa8628e663b1f653c4 | [
"Apache-2.0"
] | permissive | semorrison/lean-perfectoid-spaces | 78c1572cedbfae9c3e460d8aaf91de38616904d8 | bb4311dff45791170bcb1b6a983e2591bee88a19 | refs/heads/master | 1,588,841,765,494 | 1,554,805,620,000 | 1,554,805,620,000 | 180,353,546 | 0 | 1 | null | 1,554,809,880,000 | 1,554,809,880,000 | null | UTF-8 | Lean | false | false | 1,571 | lean | import topology.algebra.ring
import ring_theory.subring
import ring_theory.ideal_operations
import for_mathlib.subgroup
universe u
variables {A : Type u} [comm_ring A] [topological_space A] [topological_ring A]
open topological_ring
instance subring_has_zero (R : Type u) [comm_ring R] (S : set R) [HS : is_subring S] : has_zero S :=
⟨⟨0, is_add_submonoid.zero_mem S⟩⟩
instance topological_subring (A₀ : set A) [is_subring A₀] : topological_ring A₀ :=
{ continuous_neg := continuous_subtype_mk _ $ continuous_subtype_val.comp $ continuous_neg A,
continuous_add := continuous_subtype_mk _ $ continuous_add
(continuous_fst.comp continuous_subtype_val)
(continuous_snd.comp continuous_subtype_val),
continuous_mul := continuous_subtype_mk _ $ continuous_mul
(continuous_fst.comp continuous_subtype_val)
(continuous_snd.comp continuous_subtype_val) }
lemma half_nhds {s : set A} (hs : s ∈ (nhds (0 : A))) :
∃ V ∈ (nhds (0 : A)), ∀ v w ∈ V, v * w ∈ s :=
begin
have : ((λa:A×A, a.1 * a.2) ⁻¹' s) ∈ (nhds ((0, 0) : A × A)) :=
tendsto_mul' (by simpa using hs),
rw nhds_prod_eq at this,
rcases filter.mem_prod_iff.1 this with ⟨V₁, H₁, V₂, H₂, H⟩,
exact ⟨V₁ ∩ V₂, filter.inter_mem_sets H₁ H₂, assume v w ⟨hv, _⟩ ⟨_, hw⟩, @H (v, w) ⟨hv, hw⟩⟩
end
lemma continuous_mul_left (a : A) : continuous (λ x, a * x) :=
continuous_mul continuous_const continuous_id
lemma continuous_mul_right (a : A) : continuous (λ x, x * a) :=
continuous_mul continuous_id continuous_const
|
c5f8115074a02828a6d5bab49e8e4b2e4fd0c1ca | 94e33a31faa76775069b071adea97e86e218a8ee | /src/topology/category/CompHaus/default.lean | cecaffef175605bf44a51f6accf9e28af329e350 | [
"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 | 9,619 | lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Bhavik Mehta
-/
import category_theory.adjunction.reflective
import topology.category.Top
import topology.stone_cech
import category_theory.monad.limits
import topology.urysohns_lemma
/-!
# The category of Compact Hausdorff Spaces
We construct the category of compact Hausdorff spaces.
The type of compact Hausdorff spaces is denoted `CompHaus`, and it is endowed with a category
instance making it a full subcategory of `Top`.
The fully faithful functor `CompHaus ⥤ Top` is denoted `CompHaus_to_Top`.
**Note:** The file `topology/category/Compactum.lean` provides the equivalence between `Compactum`,
which is defined as the category of algebras for the ultrafilter monad, and `CompHaus`.
`Compactum_to_CompHaus` is the functor from `Compactum` to `CompHaus` which is proven to be an
equivalence of categories in `Compactum_to_CompHaus.is_equivalence`.
See `topology/category/Compactum.lean` for a more detailed discussion where these definitions are
introduced.
-/
universes v u
open category_theory
/-- The type of Compact Hausdorff topological spaces. -/
structure CompHaus :=
(to_Top : Top)
[is_compact : compact_space to_Top]
[is_hausdorff : t2_space to_Top]
namespace CompHaus
instance : inhabited CompHaus := ⟨{to_Top := { α := pempty }}⟩
instance : has_coe_to_sort CompHaus Type* := ⟨λ X, X.to_Top⟩
instance {X : CompHaus} : compact_space X := X.is_compact
instance {X : CompHaus} : t2_space X := X.is_hausdorff
instance category : category CompHaus := induced_category.category to_Top
instance concrete_category : concrete_category CompHaus :=
induced_category.concrete_category _
@[simp]
lemma coe_to_Top {X : CompHaus} : (X.to_Top : Type*) = X :=
rfl
variables (X : Type*) [topological_space X] [compact_space X] [t2_space X]
/-- A constructor for objects of the category `CompHaus`,
taking a type, and bundling the compact Hausdorff topology
found by typeclass inference. -/
def of : CompHaus :=
{ to_Top := Top.of X,
is_compact := ‹_›,
is_hausdorff := ‹_› }
@[simp] lemma coe_of : (CompHaus.of X : Type _) = X := rfl
/-- Any continuous function on compact Hausdorff spaces is a closed map. -/
lemma is_closed_map {X Y : CompHaus.{u}} (f : X ⟶ Y) : is_closed_map f :=
λ C hC, (hC.is_compact.image f.continuous).is_closed
/-- Any continuous bijection of compact Hausdorff spaces is an isomorphism. -/
lemma is_iso_of_bijective {X Y : CompHaus.{u}} (f : X ⟶ Y) (bij : function.bijective f) :
is_iso f :=
begin
let E := equiv.of_bijective _ bij,
have hE : continuous E.symm,
{ rw continuous_iff_is_closed,
intros S hS,
rw ← E.image_eq_preimage,
exact is_closed_map f S hS },
refine ⟨⟨⟨E.symm, hE⟩, _, _⟩⟩,
{ ext x,
apply E.symm_apply_apply },
{ ext x,
apply E.apply_symm_apply }
end
/-- Any continuous bijection of compact Hausdorff spaces induces an isomorphism. -/
noncomputable
def iso_of_bijective {X Y : CompHaus.{u}} (f : X ⟶ Y) (bij : function.bijective f) : X ≅ Y :=
by letI := is_iso_of_bijective _ bij; exact as_iso f
end CompHaus
/-- The fully faithful embedding of `CompHaus` in `Top`. -/
@[simps {rhs_md := semireducible}, derive [full, faithful]]
def CompHaus_to_Top : CompHaus.{u} ⥤ Top.{u} := induced_functor _
instance CompHaus.forget_reflects_isomorphisms : reflects_isomorphisms (forget CompHaus.{u}) :=
⟨by introsI A B f hf; exact CompHaus.is_iso_of_bijective _ ((is_iso_iff_bijective f).mp hf)⟩
/--
(Implementation) The object part of the compactification functor from topological spaces to
compact Hausdorff spaces.
-/
@[simps]
def StoneCech_obj (X : Top) : CompHaus := CompHaus.of (stone_cech X)
/--
(Implementation) The bijection of homsets to establish the reflective adjunction of compact
Hausdorff spaces in topological spaces.
-/
noncomputable def stone_cech_equivalence (X : Top.{u}) (Y : CompHaus.{u}) :
(StoneCech_obj X ⟶ Y) ≃ (X ⟶ CompHaus_to_Top.obj Y) :=
{ to_fun := λ f,
{ to_fun := f ∘ stone_cech_unit,
continuous_to_fun := f.2.comp (@continuous_stone_cech_unit X _) },
inv_fun := λ f,
{ to_fun := stone_cech_extend f.2,
continuous_to_fun := continuous_stone_cech_extend f.2 },
left_inv :=
begin
rintro ⟨f : stone_cech X ⟶ Y, hf : continuous f⟩,
ext (x : stone_cech X),
refine congr_fun _ x,
apply continuous.ext_on dense_range_stone_cech_unit (continuous_stone_cech_extend _) hf,
rintro _ ⟨y, rfl⟩,
apply congr_fun (stone_cech_extend_extends (hf.comp _)) y,
end,
right_inv :=
begin
rintro ⟨f : (X : Type*) ⟶ Y, hf : continuous f⟩,
ext,
exact congr_fun (stone_cech_extend_extends hf) _,
end }
/--
The Stone-Cech compactification functor from topological spaces to compact Hausdorff spaces,
left adjoint to the inclusion functor.
-/
noncomputable def Top_to_CompHaus : Top.{u} ⥤ CompHaus.{u} :=
adjunction.left_adjoint_of_equiv stone_cech_equivalence.{u} (λ _ _ _ _ _, rfl)
lemma Top_to_CompHaus_obj (X : Top) : ↥(Top_to_CompHaus.obj X) = stone_cech X :=
rfl
/--
The category of compact Hausdorff spaces is reflective in the category of topological spaces.
-/
noncomputable instance CompHaus_to_Top.reflective : reflective CompHaus_to_Top :=
{ to_is_right_adjoint := ⟨Top_to_CompHaus, adjunction.adjunction_of_equiv_left _ _⟩ }
noncomputable instance CompHaus_to_Top.creates_limits : creates_limits CompHaus_to_Top :=
monadic_creates_limits _
instance CompHaus.has_limits : limits.has_limits CompHaus :=
has_limits_of_has_limits_creates_limits CompHaus_to_Top
instance CompHaus.has_colimits : limits.has_colimits CompHaus :=
has_colimits_of_reflective CompHaus_to_Top
namespace CompHaus
/-- An explicit limit cone for a functor `F : J ⥤ CompHaus`, defined in terms of
`Top.limit_cone`. -/
def limit_cone {J : Type v} [small_category J] (F : J ⥤ CompHaus.{max v u}) :
limits.cone F :=
{ X :=
{ to_Top := (Top.limit_cone (F ⋙ CompHaus_to_Top)).X,
is_compact := begin
show compact_space ↥{u : Π j, (F.obj j) | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j},
rw ← is_compact_iff_compact_space,
apply is_closed.is_compact,
have : {u : Π j, F.obj j | ∀ {i j : J} (f : i ⟶ j), F.map f (u i) = u j} =
⋂ (i j : J) (f : i ⟶ j), {u | F.map f (u i) = u j},
{ ext1, simp only [set.mem_Inter, set.mem_set_of_eq], },
rw this,
apply is_closed_Inter, intros i,
apply is_closed_Inter, intros j,
apply is_closed_Inter, intros f,
apply is_closed_eq,
{ exact (continuous_map.continuous (F.map f)).comp (continuous_apply i), },
{ exact continuous_apply j, }
end,
is_hausdorff :=
show t2_space ↥{u : Π j, (F.obj j) | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j},
from infer_instance },
π :=
{ app := λ j, (Top.limit_cone (F ⋙ CompHaus_to_Top)).π.app j,
naturality' := by { intros _ _ _, ext ⟨x, hx⟩,
simp only [comp_apply, functor.const.obj_map, id_apply], exact (hx f).symm, } } }
/-- The limit cone `CompHaus.limit_cone F` is indeed a limit cone. -/
def limit_cone_is_limit {J : Type v} [small_category J] (F : J ⥤ CompHaus.{max v u}) :
limits.is_limit (limit_cone F) :=
{ lift := λ S,
(Top.limit_cone_is_limit (F ⋙ CompHaus_to_Top)).lift (CompHaus_to_Top.map_cone S),
uniq' := λ S m h, (Top.limit_cone_is_limit _).uniq (CompHaus_to_Top.map_cone S) _ h }
lemma epi_iff_surjective {X Y : CompHaus.{u}} (f : X ⟶ Y) : epi f ↔ function.surjective f :=
begin
split,
{ contrapose!,
rintros ⟨y, hy⟩ hf,
let C := set.range f,
have hC : is_closed C := (is_compact_range f.continuous).is_closed,
let D := {y},
have hD : is_closed D := is_closed_singleton,
have hCD : disjoint C D,
{ rw set.disjoint_singleton_right, rintro ⟨y', hy'⟩, exact hy y' hy' },
haveI : normal_space ↥(Y.to_Top) := normal_of_compact_t2,
obtain ⟨φ, hφ0, hφ1, hφ01⟩ := exists_continuous_zero_one_of_closed hC hD hCD,
haveI : compact_space (ulift.{u} $ set.Icc (0:ℝ) 1) := homeomorph.ulift.symm.compact_space,
haveI : t2_space (ulift.{u} $ set.Icc (0:ℝ) 1) := homeomorph.ulift.symm.t2_space,
let Z := of (ulift.{u} $ set.Icc (0:ℝ) 1),
let g : Y ⟶ Z := ⟨λ y', ⟨⟨φ y', hφ01 y'⟩⟩,
continuous_ulift_up.comp (continuous_subtype_mk (λ y', hφ01 y') φ.continuous)⟩,
let h : Y ⟶ Z := ⟨λ _, ⟨⟨0, set.left_mem_Icc.mpr zero_le_one⟩⟩, continuous_const⟩,
have H : h = g,
{ rw ← cancel_epi f,
ext x, dsimp,
simp only [comp_apply, continuous_map.coe_mk, subtype.coe_mk, hφ0 (set.mem_range_self x),
pi.zero_apply], },
apply_fun (λ e, (e y).down) at H,
dsimp at H,
simp only [subtype.mk_eq_mk, hφ1 (set.mem_singleton y), pi.one_apply] at H,
exact zero_ne_one H, },
{ rw ← category_theory.epi_iff_surjective,
apply (forget CompHaus).epi_of_epi_map }
end
lemma mono_iff_injective {X Y : CompHaus.{u}} (f : X ⟶ Y) : mono f ↔ function.injective f :=
begin
split,
{ introsI hf x₁ x₂ h,
let g₁ : of punit ⟶ X := ⟨λ _, x₁, continuous_of_discrete_topology⟩,
let g₂ : of punit ⟶ X := ⟨λ _, x₂, continuous_of_discrete_topology⟩,
have : g₁ ≫ f = g₂ ≫ f, by { ext, exact h },
rw cancel_mono at this,
apply_fun (λ e, e punit.star) at this,
exact this },
{ rw ← category_theory.mono_iff_injective,
apply (forget CompHaus).mono_of_mono_map }
end
end CompHaus
|
0d3f027e616c0fa45f86b3547f27975f65ff2fc7 | 0a6b214fd60b822ae708d58655b7d2f36091d8f8 | /src/homotopy.lean | b6e347b311067c9da8f3cfca6878a20c6a4b21a3 | [
"MIT"
] | permissive | Naomij1/lean-homotopie | de0bf067bc77254deac02aab0184511ce7aaafe7 | 21bd6be53449c61088234ceab7ec63c18628521a | refs/heads/master | 1,613,216,666,817 | 1,591,786,776,000 | 1,591,786,776,000 | 244,693,557 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,180 | lean | --- TODO :
-- - retirer des simps et optimiser
-- - retirer les derniers sorry (nommer les hypothèses dans ite)
import topology.basic
import topology.algebra.continuous_functions
import topology.continuous_on
import topology.algebra.ordered
import topology.constructions
import topology.algebra.ordered
import data.set.function
import topology.constructions
import tactic.split_ifs
import tactics
import misc
open set topological_space
open classical
set_option pp.beta true
/- Typeclass définissant un type pointé -/
class pointed (α : Type) :=
(point : α)
/- Prends un type pointé et lui renvoit son point base-/
def point (α : Type) [s : pointed α] : α :=
@pointed.point α s
-- On considère par la suite un espace topologique X pointé
variable X:Type
variable [topological_space X]
variable [pointed X]
-- Dans la suite du fichier, on pointe ℝ en 0
instance : pointed ℝ := pointed.mk 0
--Définitions par soustype d'un chemin et d'une boucle
/-- Chemin sur un type X -/
def path := {f: I → X // continuous f}
/-- Boucle sur un type X -/
def loop := {f: I → X // continuous f ∧ f(0)=f(1) ∧ f(0) = point X }
/-- Homotopie de lacets -/
def loop_homotopy (f : loop X) (g : loop X) : Prop :=
∃ (H : I × I -> X), (∀ t, H(0,t) = f.val(t) ∧ H(1,t)=g.val(t)) ∧ (continuous H)
/-- Compostition de lacets -/
noncomputable def loop_comp : (loop X ) -> (loop X) -> (loop X) :=
λ f g, ⟨λ t, ite (t.val≤0.5) (f.val(⟨2*t.val, sorry⟩) )
(g.val (⟨ 2*t.val-1, sorry⟩)),
begin
split,
-- on doit montrer que la compositions de lacets est un lacet
-- on commence par la continuité
apply continuous_if,
rotate, -- on relègue la preuve de la frontière à la fin
apply continuous.comp,
exact f.property.1,
apply continuous_subtype_mk,
apply continuous.mul,
exact continuous_const,
apply continuous_subtype_val,
apply continuous.comp,
exact g.property.1,
apply continuous_subtype_mk,
apply continuous.add,
apply continuous.mul,
exact continuous_const,
apply continuous_subtype_val,
exact continuous_const,
-- le lacet vaut bien x₀ aux extrémités
split_ifs,
simp at h_1,
exfalso,
sorry,
split,
simp,
rw f.property.2.2,
conv {to_lhs, -- conv permet de travailler dans le membre de gauche
rw <- g.property.2.2,
rw g.property.2.1,},
congr,
apply subtype.eq', -- on "relève" l'égalité dans le type ambiant
simp,
ring, -- découle des propriétés dans un anneau
simp,
rw f.property.2.2,
exfalso,
simp at h,
linarith,
exfalso,
simp at h,
linarith,
intros a ha,
have a_def : a.val=1/2, -- il faut montrer que la frontière = {1/2}
rw frontieronI' at ha,
exact ha,
rw a_def,
rw invtwo,
simp,
rw g.property.2.2,
rw <- f.property.2.1,
rw f.property.2.2,
end⟩
/- Lacet inverse -/
def loop_inv : loop X -> loop X := λ f, ⟨λ x:I, f.val(⟨1-x.val, oneminus x⟩ ),
begin
split,
apply continuous.comp,
exact f.property.left,
apply continuous_subtype_mk,
apply continuous.sub,
apply continuous_const,
apply continuous_subtype_val,,
split,
simp,
symmetry,
exact f.property.2.1,
simp,
rw <- f.property.2.1,
exact f.property.2.2,
end
⟩
/-- L'homotopie est reflexive -/
theorem loop_homotopy_refl : reflexive (loop_homotopy X) :=
begin
intro f,
-- on utilise l'homotopie H(t,s) = f(s)
let H : I × I -> X := λ x, f.val (x.2),
use H,
split,
-- l'homotopie vaut f aux extremités
intros,
split,
simp *,
-- l'homotopie est continue
apply continuous.comp, -- on déplit la composition
exact f.property.left, -- f est continue
exact continuous_snd, -- la projection sur le deuxième élément est continue
end
/-- L'homotopie est symmétrique -/
theorem loop_homotopy_symm : symmetric (loop_homotopy X) :=
begin
intros f g,
intro h1,
cases h1 with H hH,
-- on utilise l'homotopie H_2(t,s) = H(1-t,s)
let H2 : I × I -> X := λ x, H(⟨1-x.1.val, oneminus x.1⟩, x.2),
use H2,
split,
-- l'homotopie vaut g et f aux extremités
intros,
split,
simp *, -- on déplit la définition de H_2
simp [ coe_of_0],
rw (hH.1 t).2, -- on réécrit g en H(1,t)
simp *, -- on déplit la définition de H_2
simp [one_minus_one_coe],
rw (hH.1 t).1, -- on réécrit f en H(0,t)
-- l'homotopie est continue
apply continuous.comp, -- on déplit la composition
exact hH.2, -- H est continue par hypothèse
apply continuous.prod_mk, -- on déplit le produit
apply continuous_subtype_mk, -- on déplit le passage au sous-type
apply continuous.sub, -- on déplit la soustraction
apply continuous_const, -- une fonction constante est continue
apply continuous.comp, -- on déplit la composition
exact continuous_subtype_val, -- le "relèvement" de sous-type est continu
exact continuous_fst, -- la projection sur le premier élément est continue
exact continuous_snd, -- la projection sur le deuxième élément est continue
end
/-- L'homotopie est transitive -/
theorem loop_homotopy_trans : transitive (loop_homotopy X) :=
begin
intros f g h,
intros h1 h2,
cases h1 with h1func h1hyp,
cases h2 with h2func h2hyp,
-- on utilise l'homotopie H₃(t,s) = H₁(2t,s) si t ≤ 0.5
-- H₂(2t-1,s) sinon
let H : I × I -> X := λ x, ite (x.1.val≤0.5) (h1func( ⟨ 2*x.1.val, sorry ⟩, x.2))
(h2func(⟨2*x.1.val-1, sorry⟩, x.2 )),
use H,
split,
-- l'homotopie vaut f et h aux extremités
intros,
split,
simp *,
split_ifs, -- on déplit la définition d'une condition
rw <- (h1hyp.1 t).1, -- soit 0≤1/2
congr,
simp [coe_of_0], -- auquel cas les deux arguments sont égaux
simp at h_1, -- soit 2<0
exfalso,
exact not_2_lt_0 h_1, -- auquel cas on obtient une absurdité
simp *,
split_ifs, -- on déplit la définition d'une condition
simp at h_1, -- soit 1<1/2
exfalso,
exact not_1_lt_half h_1, -- auquel cas on obtient une absurdité
rw <- (h2hyp.1 t).2, -- soit 1>0
congr,
rw <- oneisone,
simp,
ring,
-- continuité
simp *,
apply continuous_if,
rotate,
-- partie 1
apply continuous.comp,
exact h1hyp.2,
apply continuous.prod_mk,
apply continuous_subtype_mk,
apply continuous.mul,
exact continuous_const,
apply continuous.comp,
exact continuous_subtype_val, -- le "relèvement" de sous-type est continu
exact continuous_fst,
exact continuous_snd,
-- partie 2
apply continuous.comp,
exact h2hyp.2,
apply continuous.prod_mk,
apply continuous_subtype_mk,
apply continuous.sub,
apply continuous.mul,
exact continuous_const,
apply continuous.comp,
exact continuous_subtype_val, -- le "relèvement" de sous-type est continu
exact continuous_fst,
exact continuous_const,
exact continuous_snd,
--frontière
intros a ha,
have a_def : a.fst.val=1/2, -- il faut montrer que la frontière = {1/2, -}
rw frontieronI at ha,
exact ha,
rw a_def,
rw invtwo,
simp,
rw (h1hyp.1 a.snd).2,
rw (h2hyp.1 a.snd).1,
end
/-- L'homotopie est une relation d'équivalence -/
theorem loop_homotopy_equiv : equivalence (loop_homotopy X) :=
⟨ loop_homotopy_refl X, loop_homotopy_symm X, loop_homotopy_trans X⟩
/-- Sétoïde (X, homotopies de X) -/
definition homotopy.setoid : setoid (loop X) := { r := loop_homotopy X, iseqv := loop_homotopy_equiv X}
/-- Ensemble des classes d'homotopie -/
definition homotopy_classes := quotient (homotopy.setoid X)
/-- Réduction à classe d'équivalence près -/
definition reduce_homotopy: (loop X) → homotopy_classes X := quot.mk (loop_homotopy X)
-- notation à améliorer (inférer le type automatiquement)
notation `[` f `|` X `]` := reduce_homotopy X f
|
1e62d5ab5e761c58bd0a6fac6c4fdefab0a34712 | a46270e2f76a375564f3b3e9c1bf7b635edc1f2c | /7.10.3.lean | ffe47e0fad16585b86dd891cd812c86231c4f94b | [
"CC0-1.0"
] | permissive | wudcscheme/lean-exercise | 88ea2506714eac343de2a294d1132ee8ee6d3a20 | 5b23b9be3d361fff5e981d5be3a0a1175504b9f6 | refs/heads/master | 1,678,958,930,293 | 1,583,197,205,000 | 1,583,197,205,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,338 | lean | inductive t: Type
| const : ℕ -> t
| var : ℕ -> t
| plus : t -> t -> t
| times : t -> t -> t
def bn := ℕ × ℕ.
def env := list bn.
def val := option ℕ
def lookup: env -> nat -> val
| [] _ := none
| ((y,v)::ys) x := if x = y then some v else lookup ys x
def bin: (ℕ -> ℕ -> ℕ) -> val -> val -> val
| _ none _ := none
| _ _ none := none
| op (some x) (some y) := some (op x y)
def add := bin nat.add
def mul := bin nat.mul
infix `<+>`:50 := add
infix `<*>`:70 := mul
def eval : env -> t -> val
| _ (t.const v) := some v
| e (t.var x) := lookup e x
| e (t.plus u v) := (eval e u) <+> (eval e v)
| e (t.times u v) := (eval e u) <*> (eval e v).
def tplus (u: t) (v: t): t := t.plus u v
def ttimes (u: t) (v: t): t := t.times u v
infix `[+]`:50 := tplus
infix `[*]`:70 := ttimes
def x₁ := t.var 1
def x₂ := t.var 2
def x₃ := t.var 3
def x₄ := t.var 4
#reduce eval [] (t.const 1)
#reduce eval [] (t.var 1)
#reduce eval [(1, 100)] (t.var 1)
#reduce eval [(1, 1), (2, 12)] ((x₁[*]x₁[*]x₁) [+] (x₂[*]x₂[*]x₂))
#reduce eval [(1, 9), (2, 10)] ((x₁[*]x₁[*]x₁) [+] (x₂[*]x₂[*]x₂))
#reduce eval [(3, 0), (2, 9), (1, 10)] ((x₁[*]x₁[*]x₁) [+] (x₂[*]x₂[*]x₂))
#reduce eval [(3, 0), (1, 10)] ((x₁[*]x₁[*]x₁) [+] (x₂[*]x₂[*]x₂))
|
1e17f194cfeca4ab3dff1621abaa462f1e85c91c | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/convex/integral.lean | 1fc608b88fed07e32eb4fdd3d0a45334aa936bd3 | [
"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 | 7,759 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import analysis.convex.function
import measure_theory.integral.set_integral
/-!
# Jensen's inequality for integrals
In this file we prove four theorems:
* `convex.smul_integral_mem`: if `μ` is a non-zero finite measure on `α`, `s` is a convex closed set
in `E`, and `f` is an integrable function sending `μ`-a.e. points to `s`, then the average value
of `f` belongs to `s`: `(μ univ).to_real⁻¹ • ∫ x, f x ∂μ ∈ s`. See also `convex.center_mass_mem`
for a finite sum version of this lemma.
* `convex.integral_mem`: if `μ` is a probability measure on `α`, `s` is a convex closed set in `E`,
and `f` is an integrable function sending `μ`-a.e. points to `s`, then the expected value of `f`
belongs to `s`: `∫ x, f x ∂μ ∈ s`. See also `convex.sum_mem` for a finite sum version of this
lemma.
* `convex_on.map_smul_integral_le`: Convex Jensen's inequality: If a function `g : E → ℝ` is convex
and continuous on a convex closed set `s`, `μ` is a finite non-zero measure on `α`, and
`f : α → E` is a function sending `μ`-a.e. points to `s`, then the value of `g` at the average
value of `f` is less than or equal to the average value of `g ∘ f` provided that both `f` and
`g ∘ f` are integrable. See also `convex_on.map_sum_le` for a finite sum version of this lemma.
* `convex_on.map_integral_le`: Convex Jensen's inequality: If a function `g : E → ℝ` is convex and
continuous on a convex closed set `s`, `μ` is a probability measure on `α`, and `f : α → E` is a
function sending `μ`-a.e. points to `s`, then the value of `g` at the expected value of `f` is
less than or equal to the expected value of `g ∘ f` provided that both `f` and `g ∘ f` are
integrable. See also `convex_on.map_sum_le` for a finite sum version of this lemma.
## Tags
convex, integral, center mass, Jensen's inequality
-/
open measure_theory set filter
open_locale topological_space big_operators
variables {α E : Type*} [measurable_space α] {μ : measure α}
[normed_group E] [normed_space ℝ E] [complete_space E]
[topological_space.second_countable_topology E] [measurable_space E] [borel_space E]
private lemma convex.smul_integral_mem_of_measurable
[is_finite_measure μ] {s : set E} (hs : convex ℝ s) (hsc : is_closed s)
(hμ : μ ≠ 0) {f : α → E} (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : integrable f μ) (hfm : measurable f) :
(μ univ).to_real⁻¹ • ∫ x, f x ∂μ ∈ s :=
begin
unfreezingI { rcases eq_empty_or_nonempty s with rfl|⟨y₀, h₀⟩ },
{ refine (hμ _).elim, simpa using hfs },
rw ← hsc.closure_eq at hfs,
have hc : integrable (λ _, y₀) μ := integrable_const _,
set F : ℕ → simple_func α E := simple_func.approx_on f hfm s y₀ h₀,
have : tendsto (λ n, (F n).integral μ) at_top (𝓝 $ ∫ x, f x ∂μ),
{ simp only [simple_func.integral_eq_integral _
(simple_func.integrable_approx_on hfm hfi h₀ hc _)],
exact tendsto_integral_of_L1 _ hfi
(eventually_of_forall $ simple_func.integrable_approx_on hfm hfi h₀ hc)
(simple_func.tendsto_approx_on_L1_nnnorm hfm h₀ hfs (hfi.sub hc).2) },
refine hsc.mem_of_tendsto (tendsto_const_nhds.smul this) (eventually_of_forall $ λ n, _),
have : ∑ y in (F n).range, (μ ((F n) ⁻¹' {y})).to_real = (μ univ).to_real,
by rw [← (F n).sum_range_measure_preimage_singleton, @ennreal.to_real_sum _ _
(λ y, μ ((F n) ⁻¹' {y})) (λ _ _, (measure_ne_top _ _))],
rw [← this, simple_func.integral],
refine hs.center_mass_mem (λ _ _, ennreal.to_real_nonneg) _ _,
{ rw this,
exact ennreal.to_real_pos (mt measure.measure_univ_eq_zero.mp hμ) (measure_ne_top _ _) },
{ simp only [simple_func.mem_range],
rintros _ ⟨x, rfl⟩,
exact simple_func.approx_on_mem hfm h₀ n x }
end
/-- If `μ` is a non-zero finite measure on `α`, `s` is a convex closed set in `E`, and `f` is an
integrable function sending `μ`-a.e. points to `s`, then the average value of `f` belongs to `s`:
`(μ univ).to_real⁻¹ • ∫ x, f x ∂μ ∈ s`. See also `convex.center_mass_mem` for a finite sum version
of this lemma. -/
lemma convex.smul_integral_mem
[is_finite_measure μ] {s : set E} (hs : convex ℝ s) (hsc : is_closed s)
(hμ : μ ≠ 0) {f : α → E} (hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : integrable f μ) :
(μ univ).to_real⁻¹ • ∫ x, f x ∂μ ∈ s :=
begin
have : ∀ᵐ (x : α) ∂μ, hfi.ae_measurable.mk f x ∈ s,
{ filter_upwards [hfs, hfi.ae_measurable.ae_eq_mk] with _ _ h,
rwa ← h, },
convert convex.smul_integral_mem_of_measurable hs hsc hμ this
(hfi.congr hfi.ae_measurable.ae_eq_mk) (hfi.ae_measurable.measurable_mk) using 2,
apply integral_congr_ae,
exact hfi.ae_measurable.ae_eq_mk
end
/-- If `μ` is a probability measure on `α`, `s` is a convex closed set in `E`, and `f` is an
integrable function sending `μ`-a.e. points to `s`, then the expected value of `f` belongs to `s`:
`∫ x, f x ∂μ ∈ s`. See also `convex.sum_mem` for a finite sum version of this lemma. -/
lemma convex.integral_mem [is_probability_measure μ] {s : set E} (hs : convex ℝ s)
(hsc : is_closed s) {f : α → E} (hf : ∀ᵐ x ∂μ, f x ∈ s) (hfi : integrable f μ) :
∫ x, f x ∂μ ∈ s :=
by simpa [measure_univ] using hs.smul_integral_mem hsc (is_probability_measure.ne_zero μ) hf hfi
/-- Jensen's inequality: if a function `g : E → ℝ` is convex and continuous on a convex closed set
`s`, `μ` is a finite non-zero measure on `α`, and `f : α → E` is a function sending `μ`-a.e. points
to `s`, then the value of `g` at the average value of `f` is less than or equal to the average value
of `g ∘ f` provided that both `f` and `g ∘ f` are integrable. See also `convex.map_center_mass_le`
for a finite sum version of this lemma. -/
lemma convex_on.map_smul_integral_le [is_finite_measure μ] {s : set E} {g : E → ℝ}
(hg : convex_on ℝ s g) (hgc : continuous_on g s) (hsc : is_closed s) (hμ : μ ≠ 0) {f : α → E}
(hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : integrable f μ) (hgi : integrable (g ∘ f) μ) :
g ((μ univ).to_real⁻¹ • ∫ x, f x ∂μ) ≤ (μ univ).to_real⁻¹ • ∫ x, g (f x) ∂μ :=
begin
set t := {p : E × ℝ | p.1 ∈ s ∧ g p.1 ≤ p.2},
have ht_conv : convex ℝ t := hg.convex_epigraph,
have ht_closed : is_closed t :=
(hsc.preimage continuous_fst).is_closed_le (hgc.comp continuous_on_fst (subset.refl _))
continuous_on_snd,
have ht_mem : ∀ᵐ x ∂μ, (f x, g (f x)) ∈ t := hfs.mono (λ x hx, ⟨hx, le_rfl⟩),
simpa [integral_pair hfi hgi]
using (ht_conv.smul_integral_mem ht_closed hμ ht_mem (hfi.prod_mk hgi)).2
end
/-- Convex **Jensen's inequality**: if a function `g : E → ℝ` is convex and continuous on a convex
closed set `s`, `μ` is a probability measure on `α`, and `f : α → E` is a function sending `μ`-a.e.
points to `s`, then the value of `g` at the expected value of `f` is less than or equal to the
expected value of `g ∘ f` provided that both `f` and `g ∘ f` are integrable. See also
`convex_on.map_center_mass_le` for a finite sum version of this lemma. -/
lemma convex_on.map_integral_le [is_probability_measure μ] {s : set E} {g : E → ℝ}
(hg : convex_on ℝ s g) (hgc : continuous_on g s) (hsc : is_closed s) {f : α → E}
(hfs : ∀ᵐ x ∂μ, f x ∈ s) (hfi : integrable f μ) (hgi : integrable (g ∘ f) μ) :
g (∫ x, f x ∂μ) ≤ ∫ x, g (f x) ∂μ :=
by simpa [measure_univ]
using hg.map_smul_integral_le hgc hsc (is_probability_measure.ne_zero μ) hfs hfi hgi
|
984e029ab360afdd0be82ade18903dbf91ab7096 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/simpRwBug.lean | bf2d440d40c1efcf25306d644d5ec570cc2933ef | [
"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 | 181 | lean | open Nat
theorem add_assoc (m n k : Nat) : m + n + k = m + (n + k) :=
Nat.recOn (motive := fun k => m + n + k = m + (n + k)) k rfl (fun k ih => by simp [Nat.add_succ, ih]; done)
|
d1e4b193c2e66e5ccf49e2ce9ac4c54b74702bde | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/cacheIssue.lean | 7bf19986520009c18a8975eae983c57050192f45 | [
"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 | 341 | lean | structure Foo (A B : Type) := f : Unit -> A
def foo (P : Type) : Foo ((p : P) -> Nat) ({p : P} -> Nat) := ⟨λ _ _ => 0⟩
def bar (P : Type) : Foo ((p : P) -> Nat) ({p : P} -> Int) := ⟨λ _ _ => 0⟩
#check foo Bool
#check (foo Bool).f -- (foo Bool).f : Unit → Bool → Nat
#check (bar Bool).f -- (bar Bool).f : Unit → Bool → Nat
|
b83dfdfd45323a99f464e27a61da898db6274612 | 351a46035517d2a1985619b8cabdf263754d343a | /src/ch16.lean | 310ffcaceca94a1b687f51f4b68f2ca314d00a07 | [] | no_license | kaychaks/logic_proof | accc212517b613caca92c10db77e6aaf6b7ccfbc | 90f3bf0acbabf558ba2f82dee968255d8bfe2de1 | refs/heads/master | 1,587,001,734,509 | 1,548,235,051,000 | 1,548,235,051,000 | 165,186,786 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,504 | lean | open function int algebra
def f (x : ℤ) : ℤ := x + 3
def g (x : ℤ) : ℤ := -x
def h (x : ℤ) : ℤ := 2 * x + 3
example : injective f :=
assume x1 x2,
assume h1 : x1 + 3 = x2 + 3, -- Lean knows this is the same as f x1 = f x2
show x1 = x2, from eq_of_add_eq_add_right h1
example : surjective f :=
assume y,
have h1 : f (y - 3) = y, from calc
f (y - 3) = (y - 3) + 3 : rfl
... = y : by rw sub_add_cancel,
show ∃ x, f x = y, from exists.intro (y - 3) h1
example (x y : ℤ) (h : 2 * x = 2 * y) : x = y :=
have h1 : 2 ≠ (0 : ℤ), from dec_trivial, -- this tells Lean to figure it out itself
show x = y, from eq_of_mul_eq_mul_left h1 h
example (x : ℤ) : -(-x) = x := neg_neg x
example (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :
∀ x, u (v x) = x :=
h
example (A B : Type) (u : A → B) (v : B → A) (h : left_inverse u v) :
right_inverse v u :=
h
-- fill in the sorry's in the following proofs
example : injective h :=
assume x₁ x₂,
assume : 2 * x₁ + 3 = 2 * x₂ + 3,
have 2 * x₁ = 2 * x₂ , from eq_of_add_eq_add_right this,
have 2 ≠ (0 : ℤ), from dec_trivial,
show x₁ = x₂ , from eq_of_mul_eq_mul_left this ‹ 2 * x₁ = 2 * x₂ ›
example : surjective g :=
assume y,
have h₁ : g (-y) = y, from calc
g (-y) = -(-y): rfl
... = y: by rw neg_neg,
show ∃ x, g x = y, from exists.intro (-y) h₁
example (A B : Type) (u : A → B) (v1 : B → A) (v2 : B → A)
(h1 : left_inverse v1 u) (h2 : right_inverse v2 u) : v1 = v2 :=
funext
(assume x,
calc
v1 x = v1 (u (v2 x)) : by rw (h2 x)
... = v2 x : by rw (h1 (v2 x)))
---
import data.set
open function set
variables {X Y : Type}
variable f : X → Y
variables A B : set X
example : f '' (A ∪ B) = f '' A ∪ f '' B :=
eq_of_subset_of_subset
(assume y,
assume h1 : y ∈ f '' (A ∪ B),
exists.elim h1 $
assume x h,
have h2 : x ∈ A ∪ B, from h.left,
have h3 : f x = y, from h.right,
or.elim h2
(assume h4 : x ∈ A,
have h5 : y ∈ f '' A, from ⟨x, h4, h3⟩,
show y ∈ f '' A ∪ f '' B, from or.inl h5)
(assume h4 : x ∈ B,
have h5 : y ∈ f '' B, from ⟨x, h4, h3⟩,
show y ∈ f '' A ∪ f '' B, from or.inr h5))
(assume y,
assume h2 : y ∈ f '' A ∪ f '' B,
or.elim h2
(assume h3 : y ∈ f '' A,
exists.elim h3 $
assume x h,
have h4 : x ∈ A, from h.left,
have h5 : f x = y, from h.right,
have h6 : x ∈ A ∪ B, from or.inl h4,
show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩)
(assume h3 : y ∈ f '' B,
exists.elim h3 $
assume x h,
have h4 : x ∈ B, from h.left,
have h5 : f x = y, from h.right,
have h6 : x ∈ A ∪ B, from or.inr h4,
show y ∈ f '' (A ∪ B), from ⟨x, h6, h5⟩))
-- remember, x ∈ A ∩ B is the same as x ∈ A ∧ x ∈ B
example (x : X) (h1 : x ∈ A) (h2 : x ∈ B) : x ∈ A ∩ B :=
and.intro h1 h2
example (x : X) (h1 : x ∈ A ∩ B) : x ∈ A :=
and.left h1
-- Fill in the proof below.
-- (It should take about 8 lines.)
example : f '' (A ∩ B) ⊆ f '' A ∩ f '' B :=
assume y,
assume h1 : y ∈ f '' (A ∩ B),
show y ∈ f '' A ∩ f '' B, from
exists.elim h1 $
assume x h,
have y ∈ f '' A, from ⟨ x, h.left.left, h.right ⟩,
have y ∈ f '' B, from ⟨ x, h.left.right, h.right ⟩,
⟨ ‹ y ∈ f '' A › , ‹ y ∈ f '' B › ⟩
|
0ac9deed7c563ea4c3f98e570c9a299dbf94c2dc | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /library/standard.lean | 68fdba1c64873544811951a721cf97207b045727 | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 289 | lean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Leonardo de Moura, Jeremy Avigad
-- standard
-- ========
-- The constructive core of Lean's library.
import type logic data tools.tactic
|
4a5e08d77ed43063bdf559a21a12559ad0271481 | cc060cf567f81c404a13ee79bf21f2e720fa6db0 | /lean/quantifiers.lean | 6379172062ad85b17bfe2603051f22abc717f402 | [
"Apache-2.0"
] | permissive | semorrison/proof | cf0a8c6957153bdb206fd5d5a762a75958a82bca | 5ee398aa239a379a431190edbb6022b1a0aa2c70 | refs/heads/master | 1,610,414,502,842 | 1,518,696,851,000 | 1,518,696,851,000 | 78,375,937 | 2 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 1,838 | lean | variables (A : Type) (p q : A → Prop)
example : (∀ x, p x ∧ q x) ↔ (∀ x, p x) ∧ (∀ x, q x) :=
iff.intro
(assume H : ∀ x, p x ∧ q x,
and.intro
(take y : A, and.left (H y))
(take y : A, and.right (H y)))
(assume H : (∀ x, p x) ∧ (∀ x, q x),
take y : A,
and.intro (and.left H y) (and.right H y))
example : (∀ x, p x → q x) → (∀ x, p x) → (∀ x, q x) :=
assume Hpq : ∀ x, p x → q x,
assume Hp : ∀ x, p x,
take y : A,
Hpq y (Hp y)
example : (∀ x, p x) ∨ (∀ x, q x) → ∀ x, p x ∨ q x :=
assume Hpq,
take y : A,
or.elim Hpq
(λ H : (∀ x, p x), or.inl (H y))
(λ H : (∀ x, q x), or.inr (H y))
variables (a b c : Type) (f : a → b) (g : b → c)
variable r : Prop
example : A → ((∀ x : A, r) ↔ r) :=
assume H : A,
iff.intro
(assume Hr : (∀ x : A, r), Hr H)
(assume Hr : r, take y, Hr)
open classical
example : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=
iff.intro
(assume H : ∀ x, p x ∨ r,
by_cases or.inr
(assume Hnr : ¬r,
or.inl
(take y : A,
or.elim (H y) id (λ Hr, absurd Hr Hnr))))
(assume H : (∀ x, p x) ∨ r,
take y : A,
or.elim H
(λ Hp, or.inl (Hp y))
or.inr)
example : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=
iff.intro
(assume H : (∀ x, r → p x),
assume Hr : r,
take y : A, H y Hr)
(assume H : r → ∀ x, p x,
take y : A,
assume Hr : r, H Hr y)
variables (men : Type) (barber : men) (shaves : men → men → Prop)
example (H : ∀ x : men, shaves barber x ↔ ¬shaves x x) : false :=
have Hns : ¬shaves barber barber, from
not.intro
(assume Hs : shaves barber barber,
iff.mp (H barber) Hs Hs),
have Hs : shaves barber barber, from
iff.mpr (H barber) Hns,
Hns Hs
|
fa7eb503a792fbd39236d651eaf562f4b99f6e9e | 968e2f50b755d3048175f176376eff7139e9df70 | /examples/pred_logic/unnamed_187.lean | 3efee1619bbb17786df625e06bf58b9fc329f6ed | [] | no_license | gihanmarasingha/mth1001_sphinx | 190a003269ba5e54717b448302a27ca26e31d491 | 05126586cbf5786e521be1ea2ef5b4ba3c44e74a | refs/heads/master | 1,672,913,933,677 | 1,604,516,583,000 | 1,604,516,583,000 | 309,245,750 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 76 | lean | def even (x : ℤ) : Prop := ∃ m : ℤ, x = 2 *m
#check even
#check even 5 |
39485a9a9e97022ee95d178704e4ab09844507de | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /library/init/core.lean | 0e937d6e1d22c5a737a57e7812fa54cd0847a022 | [
"Apache-2.0"
] | permissive | bjoeris/lean | 0ed95125d762b17bfcb54dad1f9721f953f92eeb | 4e496b78d5e73545fa4f9a807155113d8e6b0561 | refs/heads/master | 1,611,251,218,281 | 1,495,337,658,000 | 1,495,337,658,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,917 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
notation, basic datatypes and type classes
-/
prelude
notation `Prop` := Sort 0
notation f ` $ `:1 a:0 := f a
/- Logical operations and relations -/
reserve prefix `¬`:40
reserve prefix `~`:40
reserve infixr ` ∧ `:35
reserve infixr ` /\ `:35
reserve infixr ` \/ `:30
reserve infixr ` ∨ `:30
reserve infix ` <-> `:20
reserve infix ` ↔ `:20
reserve infix ` = `:50
reserve infix ` == `:50
reserve infix ` ≠ `:50
reserve infix ` ≈ `:50
reserve infix ` ~ `:50
reserve infix ` ≡ `:50
reserve infixl ` ⬝ `:75
reserve infixr ` ▸ `:75
reserve infixr ` ▹ `:75
/- types and type constructors -/
reserve infixr ` ⊕ `:30
reserve infixr ` × `:35
/- arithmetic operations -/
reserve infixl ` + `:65
reserve infixl ` - `:65
reserve infixl ` * `:70
reserve infixl ` / `:70
reserve infixl ` % `:70
reserve prefix `-`:100
reserve infix ` ^ `:80
reserve infixr ` ∘ `:90 -- input with \comp
reserve infix ` <= `:50
reserve infix ` ≤ `:50
reserve infix ` < `:50
reserve infix ` >= `:50
reserve infix ` ≥ `:50
reserve infix ` > `:50
/- boolean operations -/
reserve infixl ` && `:70
reserve infixl ` || `:65
/- set operations -/
reserve infix ` ∈ `:50
reserve infix ` ∉ `:50
reserve infixl ` ∩ `:70
reserve infixl ` ∪ `:65
reserve infix ` ⊆ `:50
reserve infix ` ⊇ `:50
reserve infix ` ⊂ `:50
reserve infix ` ⊃ `:50
reserve infix ` \ `:70
/- other symbols -/
reserve infix ` ∣ `:50
reserve infixl ` ++ `:65
reserve infixr ` :: `:67
reserve infixl `; `:1
universes u v w
/-- Gadget for optional parameter support. -/
@[reducible] def opt_param (α : Sort u) (default : α) : Sort u :=
α
/-- Gadget for marking output parameters in type classes. -/
@[reducible] def inout_param (α : Sort u) : Sort u := α
notation `inout`:1024 a:0 := inout_param a
inductive punit : Sort u
| star : punit
inductive unit : Type
| star : unit
/--
Gadget for defining thunks, thunk parameters have special treatment.
Example: given
def f (s : string) (t : thunk nat) : nat
an application
f "hello" 10
is converted into
f "hello" (λ _, 10)
-/
@[reducible] def thunk (α : Type u) : Type u :=
unit → α
inductive true : Prop
| intro : true
inductive false : Prop
inductive empty : Type
def not (a : Prop) := a → false
prefix `¬` := not
inductive eq {α : Sort u} (a : α) : α → Prop
| refl : eq a
init_quotient
inductive heq {α : Sort u} (a : α) : Π {β : Sort u}, β → Prop
| refl : heq a
structure prod (α : Type u) (β : Type v) :=
(fst : α) (snd : β)
/- Similar to prod, but α and β can be propositions.
We use this type internally to automatically generate the brec_on recursor. -/
structure pprod (α : Sort u) (β : Sort v) :=
(fst : α) (snd : β)
inductive and (a b : Prop) : Prop
| intro : a → b → and
def and.elim_left {a b : Prop} (h : and a b) : a :=
and.rec (λ ha hb, ha) h
def and.left := @and.elim_left
def and.elim_right {a b : Prop} (h : and a b) : b :=
and.rec (λ ha hb, hb) h
def and.right := @and.elim_right
/- eq basic support -/
infix = := eq
attribute [refl] eq.refl
@[pattern] def rfl {α : Sort u} {a : α} : a = a := eq.refl a
@[elab_as_eliminator, subst]
lemma eq.subst {α : Sort u} {P : α → Prop} {a b : α} (h₁ : a = b) (h₂ : P a) : P b :=
eq.rec h₂ h₁
notation h1 ▸ h2 := eq.subst h1 h2
@[trans] lemma eq.trans {α : Sort u} {a b c : α} (h₁ : a = b) (h₂ : b = c) : a = c :=
h₂ ▸ h₁
@[symm] lemma eq.symm {α : Sort u} {a b : α} (h : a = b) : b = a :=
h ▸ rfl
infix == := heq
lemma eq_of_heq {α : Sort u} {a a' : α} (h : a == a') : a = a' :=
have ∀ (α' : Sort u) (a' : α') (h₁ : @heq α a α' a') (h₂ : α = α'), (eq.rec_on h₂ a : α') = a', from
λ (α' : Sort u) (a' : α') (h₁ : @heq α a α' a'), heq.rec_on h₁ (λ h₂ : α = α, rfl),
show (eq.rec_on (eq.refl α) a : α) = a', from
this α a' h (eq.refl α)
/- The following four lemmas could not be automatically generated when the
structures were declared, so we prove them manually here. -/
lemma prod.mk.inj {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → and (x₁ = x₂) (y₁ = y₂) :=
λ h, prod.no_confusion h (λ h₁ h₂, ⟨h₁, h₂⟩)
lemma prod.mk.inj_arrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → Π ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P :=
λ h₁ _ h₂, prod.no_confusion h₁ h₂
lemma pprod.mk.inj {α : Sort u} {β : Sort v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: pprod.mk x₁ y₁ = pprod.mk x₂ y₂ → and (x₁ = x₂) (y₁ = y₂) :=
λ h, pprod.no_confusion h (λ h₁ h₂, ⟨h₁, h₂⟩)
lemma pprod.mk.inj_arrow {α : Type u} {β : Type v} {x₁ : α} {y₁ : β} {x₂ : α} {y₂ : β}
: (x₁, y₁) = (x₂, y₂) → Π ⦃P : Sort w⦄, (x₁ = x₂ → y₁ = y₂ → P) → P :=
λ h₁ _ h₂, prod.no_confusion h₁ h₂
inductive sum (α : Type u) (β : Type v)
| inl {} : α → sum
| inr {} : β → sum
inductive psum (α : Sort u) (β : Sort v)
| inl {} : α → psum
| inr {} : β → psum
inductive or (a b : Prop) : Prop
| inl {} : a → or
| inr {} : b → or
def or.intro_left {a : Prop} (b : Prop) (ha : a) : or a b :=
or.inl ha
def or.intro_right (a : Prop) {b : Prop} (hb : b) : or a b :=
or.inr hb
structure sigma {α : Type u} (β : α → Type v) :=
mk :: (fst : α) (snd : β fst)
structure psigma {α : Sort u} (β : α → Sort v) :=
mk :: (fst : α) (snd : β fst)
inductive pos_num : Type
| one : pos_num
| bit1 : pos_num → pos_num
| bit0 : pos_num → pos_num
namespace pos_num
def succ : pos_num → pos_num
| one := bit0 one
| (bit1 n) := bit0 (succ n)
| (bit0 n) := bit1 n
end pos_num
inductive num : Type
| zero : num
| pos : pos_num → num
namespace num
open pos_num
def succ : num → num
| zero := pos one
| (pos p) := pos (pos_num.succ p)
end num
inductive bool : Type
| ff : bool
| tt : bool
/- Remark: subtype must take a Sort instead of Type because of the axiom strong_indefinite_description. -/
structure subtype {α : Sort u} (p : α → Prop) :=
(val : α) (property : p val)
attribute [pp_using_anonymous_constructor] sigma psigma subtype pprod
class inductive decidable (p : Prop)
| is_false : ¬p → decidable
| is_true : p → decidable
@[reducible]
def decidable_pred {α : Sort u} (r : α → Prop) :=
Π (a : α), decidable (r a)
@[reducible]
def decidable_rel {α : Sort u} (r : α → α → Prop) :=
Π (a b : α), decidable (r a b)
@[reducible]
def decidable_eq (α : Sort u) :=
decidable_rel (@eq α)
inductive option (α : Type u)
| none {} : option
| some : α → option
export option (none some)
export bool (ff tt)
inductive list (T : Type u)
| nil {} : list
| cons : T → list → list
notation h :: t := list.cons h t
notation `[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) := l
inductive nat
| zero : nat
| succ : nat → nat
structure unification_constraint :=
{α : Type u} (lhs : α) (rhs : α)
infix ` ≟ `:50 := unification_constraint.mk
infix ` =?= `:50 := unification_constraint.mk
structure unification_hint :=
(pattern : unification_constraint)
(constraints : list unification_constraint)
/- Declare builtin and reserved notation -/
class has_zero (α : Type u) := (zero : α)
class has_one (α : Type u) := (one : α)
class has_add (α : Type u) := (add : α → α → α)
class has_mul (α : Type u) := (mul : α → α → α)
class has_inv (α : Type u) := (inv : α → α)
class has_neg (α : Type u) := (neg : α → α)
class has_sub (α : Type u) := (sub : α → α → α)
class has_div (α : Type u) := (div : α → α → α)
class has_dvd (α : Type u) := (dvd : α → α → Prop)
class has_mod (α : Type u) := (mod : α → α → α)
class has_le (α : Type u) := (le : α → α → Prop)
class has_lt (α : Type u) := (lt : α → α → Prop)
class has_append (α : Type u) := (append : α → α → α)
class has_andthen (α : Type u) := (andthen : α → α → α)
class has_union (α : Type u) := (union : α → α → α)
class has_inter (α : Type u) := (inter : α → α → α)
class has_sdiff (α : Type u) := (sdiff : α → α → α)
class has_subset (α : Type u) := (subset : α → α → Prop)
class has_ssubset (α : Type u) := (ssubset : α → α → Prop)
/- Type classes has_emptyc and has_insert are
used to implement polymorphic notation for collections.
Example: {a, b, c}. -/
class has_emptyc (α : Type u) := (emptyc : α)
class has_insert (α : inout Type u) (γ : Type v) := (insert : α → γ → γ)
/- Type class used to implement the notation { a ∈ c | p a } -/
class has_sep (α : inout Type u) (γ : Type v) :=
(sep : (α → Prop) → γ → γ)
/- Type class for set-like membership -/
class has_mem (α : inout Type u) (γ : Type v) := (mem : α → γ → Prop)
infix ∈ := has_mem.mem
notation a ∉ s := ¬ has_mem.mem a s
infix + := has_add.add
infix * := has_mul.mul
infix - := has_sub.sub
infix / := has_div.div
infix ∣ := has_dvd.dvd
infix % := has_mod.mod
prefix - := has_neg.neg
infix <= := has_le.le
infix ≤ := has_le.le
infix < := has_lt.lt
infix ++ := has_append.append
infix ; := has_andthen.andthen
notation `∅` := has_emptyc.emptyc _
infix ∪ := has_union.union
infix ∩ := has_inter.inter
infix ⊆ := has_subset.subset
infix ⊂ := has_ssubset.ssubset
infix \ := has_sdiff.sdiff
export has_append (append)
@[reducible] def ge {α : Type u} [has_le α] (a b : α) : Prop := has_le.le b a
@[reducible] def gt {α : Type u} [has_lt α] (a b : α) : Prop := has_lt.lt b a
infix >= := ge
infix ≥ := ge
infix > := gt
@[reducible] def superset {α : Type u} [has_subset α] (a b : α) : Prop := has_subset.subset b a
@[reducible] def ssuperset {α : Type u} [has_ssubset α] (a b : α) : Prop := has_ssubset.ssubset b a
infix ⊇ := superset
infix ⊃ := ssuperset
def bit0 {α : Type u} [s : has_add α] (a : α) : α := a + a
def bit1 {α : Type u} [s₁ : has_one α] [s₂ : has_add α] (a : α) : α := (bit0 a) + 1
attribute [pattern] has_zero.zero has_one.one bit0 bit1 has_add.add has_neg.neg
def insert {α : Type u} {γ : Type v} [has_insert α γ] : α → γ → γ :=
has_insert.insert
/- The empty collection -/
def singleton {α : Type u} {γ : Type v} [has_emptyc γ] [has_insert α γ] (a : α) : γ :=
has_insert.insert a ∅
/- num, pos_num instances -/
instance : has_zero num :=
⟨num.zero⟩
instance : has_one num :=
⟨num.pos pos_num.one⟩
instance : has_one pos_num :=
⟨pos_num.one⟩
namespace pos_num
def is_one : pos_num → bool
| one := tt
| _ := ff
def pred : pos_num → pos_num
| one := one
| (bit1 n) := bit0 n
| (bit0 one) := one
| (bit0 n) := bit1 (pred n)
def size : pos_num → pos_num
| one := one
| (bit0 n) := succ (size n)
| (bit1 n) := succ (size n)
def add : pos_num → pos_num → pos_num
| one b := succ b
| a one := succ a
| (bit0 a) (bit0 b) := bit0 (add a b)
| (bit1 a) (bit1 b) := bit0 (succ (add a b))
| (bit0 a) (bit1 b) := bit1 (add a b)
| (bit1 a) (bit0 b) := bit1 (add a b)
end pos_num
instance : has_add pos_num :=
⟨pos_num.add⟩
namespace num
open pos_num
def add : num → num → num
| zero a := a
| b zero := b
| (pos a) (pos b) := pos (pos_num.add a b)
end num
instance : has_add num :=
⟨num.add⟩
def std.priority.default : num := 1000
def std.priority.max : num := 4294967295
/- nat basic instances -/
namespace nat
protected def prio := num.add std.priority.default 100
protected def add : nat → nat → nat
| a zero := a
| a (succ b) := succ (add a b)
/- We mark the following definitions as pattern to make sure they can be used in recursive equations,
and reduced by the equation compiler. -/
attribute [pattern] nat.add nat.add._main
def of_pos_num : pos_num → nat
| pos_num.one := succ zero
| (pos_num.bit0 a) := let r := of_pos_num a in nat.add r r
| (pos_num.bit1 a) := let r := of_pos_num a in succ (nat.add r r)
def of_num : num → nat
| num.zero := zero
| (num.pos p) := of_pos_num p
end nat
instance : has_zero nat := ⟨nat.zero⟩
instance : has_one nat := ⟨nat.succ (nat.zero)⟩
instance : has_add nat := ⟨nat.add⟩
/-
Global declarations of right binding strength
If a module reassigns these, it will be incompatible with other modules that adhere to these
conventions.
When hovering over a symbol, use "C-c C-k" to see how to input it.
-/
def std.prec.max : num := 1024 -- the strength of application, identifiers, (, [, etc.
def std.prec.arrow : num := 25
/-
The next def is "max + 10". It can be used e.g. for postfix operations that should
be stronger than application.
-/
def std.prec.max_plus :=
num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ (num.succ
(num.succ std.prec.max)))))))))
reserve postfix `⁻¹`:std.prec.max_plus -- input with \sy or \-1 or \inv
postfix ⁻¹ := has_inv.inv
notation α × β := prod α β
-- notation for n-ary tuples
/- sizeof -/
class has_sizeof (α : Sort u) :=
(sizeof : α → nat)
def sizeof {α : Sort u} [s : has_sizeof α] : α → nat :=
has_sizeof.sizeof
/-
Declare sizeof instances and lemmas for types declared before has_sizeof.
From now on, the inductive compiler will automatically generate sizeof instances and lemmas.
-/
/- Every type `α` has a default has_sizeof instance that just returns 0 for every element of `α` -/
protected def default.sizeof (α : Sort u) : α → nat
| a := 0
instance default_has_sizeof (α : Sort u) : has_sizeof α :=
⟨default.sizeof α⟩
protected def nat.sizeof : nat → nat
| n := n
instance : has_sizeof nat :=
⟨nat.sizeof⟩
protected def prod.sizeof {α : Type u} {β : Type v} [has_sizeof α] [has_sizeof β] : (prod α β) → nat
| ⟨a, b⟩ := 1 + sizeof a + sizeof b
instance (α : Type u) (β : Type v) [has_sizeof α] [has_sizeof β] : has_sizeof (prod α β) :=
⟨prod.sizeof⟩
protected def sum.sizeof {α : Type u} {β : Type v} [has_sizeof α] [has_sizeof β] : (sum α β) → nat
| (sum.inl a) := 1 + sizeof a
| (sum.inr b) := 1 + sizeof b
instance (α : Type u) (β : Type v) [has_sizeof α] [has_sizeof β] : has_sizeof (sum α β) :=
⟨sum.sizeof⟩
protected def sigma.sizeof {α : Type u} {β : α → Type v} [has_sizeof α] [∀ a, has_sizeof (β a)] : sigma β → nat
| ⟨a, b⟩ := 1 + sizeof a + sizeof b
instance (α : Type u) (β : α → Type v) [has_sizeof α] [∀ a, has_sizeof (β a)] : has_sizeof (sigma β) :=
⟨sigma.sizeof⟩
protected def unit.sizeof : unit → nat
| u := 1
instance : has_sizeof unit := ⟨unit.sizeof⟩
protected def punit.sizeof : punit → nat
| u := 1
instance : has_sizeof punit := ⟨punit.sizeof⟩
protected def bool.sizeof : bool → nat
| b := 1
instance : has_sizeof bool := ⟨bool.sizeof⟩
protected def pos_num.sizeof : pos_num → nat
| p := nat.of_pos_num p
instance : has_sizeof pos_num :=
⟨pos_num.sizeof⟩
protected def num.sizeof : num → nat
| n := nat.of_num n
instance : has_sizeof num :=
⟨num.sizeof⟩
protected def option.sizeof {α : Type u} [has_sizeof α] : option α → nat
| none := 1
| (some a) := 1 + sizeof a
instance (α : Type u) [has_sizeof α] : has_sizeof (option α) :=
⟨option.sizeof⟩
protected def list.sizeof {α : Type u} [has_sizeof α] : list α → nat
| list.nil := 1
| (list.cons a l) := 1 + sizeof a + list.sizeof l
instance (α : Type u) [has_sizeof α] : has_sizeof (list α) :=
⟨list.sizeof⟩
protected def subtype.sizeof {α : Type u} [has_sizeof α] {p : α → Prop} : subtype p → nat
| ⟨a, _⟩ := sizeof a
instance {α : Type u} [has_sizeof α] (p : α → Prop) : has_sizeof (subtype p) :=
⟨subtype.sizeof⟩
lemma nat_add_zero (n : nat) : n + 0 = n := rfl
/- Combinator calculus -/
namespace combinator
universes u₁ u₂ u₃
def I {α : Type u₁} (a : α) := a
def K {α : Type u₁} {β : Type u₂} (a : α) (b : β) := a
def S {α : Type u₁} {β : Type u₂} {γ : Type u₃} (x : α → β → γ) (y : α → β) (z : α) := x z (y z)
end combinator
/- Basic unification hints -/
@[unify] def add_succ_defeq_succ_add_hint (x y z : nat) : unification_hint :=
{ pattern := x + nat.succ y ≟ nat.succ z,
constraints := [z ≟ x + y] }
|
03bd17876dab5bc4d8842e05ca4afdb32f4fd08a | 5ee26964f602030578ef0159d46145dd2e357ba5 | /src/for_mathlib/uniform_space/separation.lean | ec6c0b7c61ccdd42ba472c3cc294f2684f597e8f | [
"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 | 10,295 | lean | import topology.uniform_space.separation
import for_mathlib.function
import for_mathlib.quotient
import for_mathlib.topology
import for_mathlib.uniform_space.basic
noncomputable theory
local attribute [instance, priority 0] classical.prop_decidable
open filter
universes u v w
section
variables {α : Type u} {β : Type v} {γ : Type w}
variables [uniform_space α] [uniform_space β] [uniform_space γ]
local attribute [instance] uniform_space.separation_setoid
def uniform_space.separated_map (f : α → β) : Prop := ∀ x y, x ≈ y → f x ≈ f y
def uniform_space.separated_map₂ (f : α → β → γ) : Prop := uniform_space.separated_map (function.uncurry f)
--∀ x x' y y', x ≈ x' → y ≈ y' → f x y ≈ f x' y'
end
local attribute [instance] uniform_space.separation_setoid
section
open uniform_space
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type*}
variables [uniform_space α] [uniform_space β] [uniform_space γ] [uniform_space δ]
lemma uniform_space.separated_map.comp {f : α → β} {g : β → γ} (hf : separated_map f) (hg : separated_map g) :
separated_map (g ∘ f) := assume x y h, hg _ _ (hf x y h)
lemma uniform_space.separated_map.comp₂ {f : α → β → γ} {g : γ → δ} (hf : separated_map₂ f) (hg : separated_map g) :
separated_map₂ (g ∘₂ f) :=
begin
unfold separated_map₂,
rw function.uncurry_comp₂,
exact hf.comp hg
end
lemma uniform_space.separated_map.eqv_of_separated {f : α → β} {x y : α} (hf : uniform_space.separated_map f)
(h : x ≈ y) : f x ≈ f y := hf x y h
lemma uniform_space.separated_map.eq_of_separated [separated β] {f : α → β} {x y : α} (hf : uniform_space.separated_map f)
(h : x ≈ y) : f x = f y := separated_def.1 ‹_› _ _ (hf x y h)
lemma uniform_continuous.separated_map {f : α → β} (H : uniform_continuous f) :
uniform_space.separated_map f := assume x y h s Hs, h _ (H Hs)
lemma uniform_continuous.eqv_of_separated {f : α → β} (H : uniform_continuous f) {x y : α} (h : x ≈ y) :
f x ≈ f y
:= H.separated_map _ _ h
lemma uniform_continuous.eq_of_separated [separated β] {f : α → β} (H : uniform_continuous f) {x y : α} (h : x ≈ y) :
f x = f y
:= H.separated_map.eq_of_separated h
lemma separated.eq_iff [separated α] {x y : α} (h : x ≈ y) : x = y :=
separated_def.1 (by apply_instance) x y h
end
open uniform_space
/-- separation space -/
@[reducible]
def sep_quot (α : Type*) [uniform_space α] := quotient (separation_setoid α)
namespace sep_quot
variables {α : Type u} {β : Type v} {γ : Type w}
variables [uniform_space α] [uniform_space β] [uniform_space γ]
def mk {α : Type u} [uniform_space α] : α → sep_quot α := quotient.mk
lemma uniform_embedding [separated α] : uniform_embedding (sep_quot.mk : α → sep_quot α) :=
⟨λ x y h, separated.eq_iff (quotient.exact h), comap_quotient_eq_uniformity⟩
lemma uniform_continuous_mk :
uniform_continuous (quotient.mk : α → sep_quot α) :=
le_refl _
def lift [separated β] (f : α → β) : sep_quot α → β :=
if h : separated_map f then
quotient.lift f (λ x x' hxx', h.eq_of_separated hxx')
else
λ x, f $ habitant_of_quotient_habitant x
lemma continuous_lift [separated β] {f : α → β} (h : continuous f) : continuous (lift f) :=
begin
by_cases hf : separated_map f,
{ rw [lift, dif_pos hf], apply continuous_quotient_lift _ h, },
{ rw [lift, dif_neg hf], exact continuous_of_const (λ a b, rfl)}
end
lemma uniform_continuous_lift [separated β] {f : α → β} (hf : uniform_continuous f) : uniform_continuous (lift f) :=
by simp [lift, hf.separated_map] ; exact hf
section sep_quot_lift
variables [separated β] {f : α → β} (h : separated_map f)
include h
lemma lift_mk (x : α) : lift f ⟦x⟧ = f x := by simp[lift, h]
lemma unique_lift {g : sep_quot α → β} (hg : uniform_continuous g) (g_mk : ∀ x, g ⟦x⟧ = f x) : g = lift f :=
begin
ext a,
cases quotient.exists_rep a with x hx,
rwa [←hx, lift_mk h x, g_mk x]
end
end sep_quot_lift
def map (f : α → β) : sep_quot α → sep_quot β := lift (quotient.mk ∘ f)
lemma continuous_map {f : α → β} (h : continuous f) : continuous (map f) :=
continuous_lift $ h.comp continuous_quotient_mk
lemma uniform_continuous_map {f : α → β} (hf : uniform_continuous f): uniform_continuous (map f) :=
uniform_continuous_lift (hf.comp uniform_continuous_mk)
lemma map_mk {f : α → β} (h : separated_map f) (a : α) : map f ⟦a⟧ = ⟦f a⟧ :=
by rw [map, lift_mk (h.comp uniform_continuous_mk.separated_map)]
lemma map_unique {f : α → β} (hf : separated_map f)
{g : sep_quot α → sep_quot β}
(comm : quotient.mk ∘ f = g ∘ quotient.mk) : map f = g :=
by ext ⟨a⟩;
calc map f ⟦a⟧ = ⟦f a⟧ : map_mk hf a
... = g ⟦a⟧ : congr_fun comm a
@[simp] lemma map_id : map (@id α) = id :=
map_unique uniform_continuous_id.separated_map rfl
lemma map_comp {f : α → β} {g : β → γ} (hf : separated_map f) (hg : separated_map g) :
map g ∘ map f = map (g ∘ f) :=
(map_unique (hf.comp hg) $ by simp only [(∘), map_mk, hf, hg]).symm
protected def prod : sep_quot α → sep_quot β → sep_quot (α × β) :=
quotient.lift₂ (λ a b, ⟦(a, b)⟧) $ assume _ _ _ _ h h', quotient.eq.2 (separation_prod.2 ⟨h, h'⟩)
lemma uniform_continuous_prod : uniform_continuous₂ (@sep_quot.prod α β _ _) :=
begin
unfold uniform_continuous₂,
unfold uniform_continuous,
rw [uniformity_prod_eq_prod, uniformity_quotient, uniformity_quotient, filter.prod_map_map_eq,
filter.tendsto_map'_iff, filter.tendsto_map'_iff, uniformity_quotient, uniformity_prod_eq_prod],
exact tendsto_map
end
@[simp]
lemma prod_mk_mk (a : α) (b : β) : sep_quot.prod ⟦a⟧ ⟦b⟧ = ⟦(a, b)⟧ := rfl
def lift₂ [separated γ] (f : α → β → γ) : sep_quot α → sep_quot β → γ :=
(lift $ function.uncurry f) ∘₂ sep_quot.prod
lemma uniform_continuous_lift₂ [separated γ] {f : α → β → γ} (hf : uniform_continuous₂ f) :
uniform_continuous₂ (sep_quot.lift₂ f) :=
uniform_continuous_prod.comp $ uniform_continuous_lift hf
@[simp]
lemma lift₂_mk_mk [separated γ] {f : α → β → γ} (h : separated_map₂ f) (a : α) (b : β) :
lift₂ f ⟦a⟧ ⟦b⟧ = f a b := lift_mk h _
def map₂ (f : α → β → γ) : sep_quot α → sep_quot β → sep_quot γ :=
lift₂ (quotient.mk ∘₂ f)
lemma uniform_continuous_map₂ {f : α → β → γ} (hf : uniform_continuous₂ f) :
uniform_continuous₂ (sep_quot.map₂ f) :=
uniform_continuous_lift₂ $ hf.comp uniform_continuous_mk
@[simp]
lemma map₂_mk_mk {f : α → β → γ} (h : separated_map₂ f) (a : α) (b : β) :
map₂ f ⟦a⟧ ⟦b⟧ = ⟦f a b⟧ :=
lift₂_mk_mk (uniform_continuous_mk.separated_map.comp₂ h) _ _
lemma map₂_unique {f : α → β → γ} (hf : separated_map₂ f)
{g : sep_quot α → sep_quot β → sep_quot γ}
(comm : ∀ a b, ⟦f a b⟧ = g ⟦a⟧ ⟦b⟧) : map₂ f = g :=
by ext ⟨a⟩ ⟨b⟩ ;
calc map₂ f ⟦a⟧ ⟦b⟧ = ⟦f a b⟧ : map₂_mk_mk hf a b
... = g ⟦a⟧ ⟦b⟧ : comm a b
variables {δ : Type*} {δ' : Type*} {δ'' : Type*} {ε : Type*}
[uniform_space δ] [uniform_space δ'] [uniform_space δ''] [uniform_space ε]
lemma continuous_map₂ {f : α → β → γ} (h : continuous₂ f) : continuous₂ (map₂ f) :=
begin
unfold continuous₂ map₂ lift₂,
rw function.uncurry_comp₂,
apply continuous.comp uniform_continuous_prod.continuous,
apply continuous_lift,
rw function.uncurry_comp₂,
apply continuous.comp h continuous_quotient_mk
end
-- Now begins a long series of lemmas for which we use an ad hoc killing tactic.
meta def sep_quot_tac : tactic unit :=
`[repeat { rintros ⟨x⟩ },
repeat { rw quot_mk_quotient_mk },
repeat { rw map_mk },
repeat { rw map₂_mk_mk },
repeat { rw map_mk },
repeat { rw H },
repeat { assumption } ]
lemma map₂_const_left_eq_map {f : α → β → γ} (hf : separated_map₂ f)
{g : β → γ} (hg : separated_map g) (a : α)
(H : ∀ b, f a b = g b) : ∀ b, map₂ f ⟦a⟧ b = map g b :=
by sep_quot_tac
lemma map₂_const_right_eq_map {f : α → β → γ} (hf : separated_map₂ f)
{g : α → γ} (hg : separated_map g) (b : β)
(H : ∀ a, f a b = g a) : ∀ a, map₂ f a ⟦b⟧ = map g a :=
by sep_quot_tac
lemma map₂_map_left_self_const {f : α → β → γ} (hf : separated_map₂ f)
{g : β → α} (hg : separated_map g) (c : γ)
(H : ∀ b, f (g b) b = c) : ∀ b, map₂ f (map g b) b = ⟦c⟧ :=
by sep_quot_tac
lemma map₂_map_right_self_const {f : α → β → γ} (hf : separated_map₂ f)
{g : α → β} (hg : separated_map g) (c : γ)
(H : ∀ a, f a (g a) = c) : ∀ a, map₂ f a (map g a) = ⟦c⟧ :=
by sep_quot_tac
lemma map₂_comm {f : α → α → β} (hf : separated_map₂ f)
(H : ∀ a b, f a b = f b a) : ∀ a b, map₂ f a b = map₂ f b a :=
by sep_quot_tac
lemma map₂_assoc {f : α → β → δ} (hf : separated_map₂ f)
{f' : β → γ → δ'} (hf' : separated_map₂ f')
{g : δ → γ → ε} (hg : separated_map₂ g)
{g' : α → δ' → ε} (hg' : separated_map₂ g')
(H : ∀ a b c, g (f a b) c = g' a (f' b c)) :
∀ a b c, map₂ g (map₂ f a b) c = map₂ g' a (map₂ f' b c) :=
by sep_quot_tac
lemma map₂_left_distrib {f : α → β → δ} (hf : separated_map₂ f)
{f' : α → γ → δ'} (hf' : separated_map₂ f')
{g : δ → δ' → ε} (hg : separated_map₂ g)
{f'' : β → γ → δ''} (hg : separated_map₂ f'')
{g' : α → δ'' → ε} (hg : separated_map₂ g')
(H : ∀ a b c, g' a (f'' b c) = g (f a b) (f' a c)) :
∀ a b c, map₂ g' a (map₂ f'' b c) = map₂ g (map₂ f a b) (map₂ f' a c) :=
by sep_quot_tac
lemma map₂_right_distrib {f : α → γ → δ} (hf : separated_map₂ f)
{f' : β → γ → δ'} (hf' : separated_map₂ f')
{g : δ → δ' → ε} (hg : separated_map₂ g)
{f'' : α → β → δ''} (hg : separated_map₂ f'')
{g' : δ'' → γ → ε} (hg : separated_map₂ g')
(H : ∀ a b c, g' (f'' a b) c = g (f a c) (f' b c)) :
∀ a b c, map₂ g' (map₂ f'' a b) c = map₂ g (map₂ f a c) (map₂ f' b c) :=
by sep_quot_tac
end sep_quot
|
81e50fd8df6145d6ecfce221adcef832f99dd5fd | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/data/fin.lean | c44bf5e453a61aa2e81de57b790e16d74b87d8a1 | [
"Apache-2.0"
] | permissive | gebner/mathlib | eab0150cc4f79ec45d2016a8c21750244a2e7ff0 | cc6a6edc397c55118df62831e23bfbd6e6c6b4ab | refs/heads/master | 1,625,574,853,976 | 1,586,712,827,000 | 1,586,712,827,000 | 99,101,412 | 1 | 0 | Apache-2.0 | 1,586,716,389,000 | 1,501,667,958,000 | Lean | UTF-8 | Lean | false | false | 27,124 | lean | /-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import data.nat.basic
/-!
# The finite type with `n` elements
`fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
### Induction principles
* `fin_zero.elim` : Elimination principle for the empty set `fin 0`, generalizes `fin.elim0`.
* `fin.succ_rec` : Define `C n i` by induction on `i : fin n` interpreted
as `(0 : fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines
`0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element
of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple.
* `fin.succ_rec_on` : same as `fin.succ_rec` but `i : fin n` is the first argument;
### Casts
* `cast_lt i h` : embed `i` into a `fin` where `h` proves it belongs into;
* `cast_le h` : embed `fin n` into `fin m`, `h : n ≤ m`;
* `cast eq` : embed `fin n` into `fin m`, `eq : n = m`;
* `cast_add m` : embed `fin n` into `fin (n+m)`;
* `cast_succ` : embed `fin n` into `fin (n+1)`;
* `succ_above p` : embed `fin n` into `fin (n + 1)` with a hole around `p`;
* `pred_above p i h` : embed `i : fin (n+1)` into `fin n` by ignoring `p`;
* `sub_nat i h` : subtract `m` from `i ≥ m`, generalizes `fin.pred`;
* `add_nat i h` : add `m` on `i` on the right, generalizes `fin.succ`;
* `nat_add i h` adds `n` on `i` on the left;
* `clamp n m` : `min n m` as an element of `fin (m + 1)`;
### Operation on tuples
We interpret maps `Π i : fin n, α i` as tuples `(α 0, …, α (n-1))`.
If `α i` is a constant map, then tuples are isomorphic (but not definitionally equal)
to `vector`s.
We define the following operations:
* `tail` : the tail of an `n+1` tuple, i.e., its last `n` entries;
* `cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple;
* `init` : the beginning of an `n+1` tuple, i.e., its first `n` entries;
* `snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes
from `cons` (i.e., adding an element to the left of a tuple) read in reverse order.
* `find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied.
### Misc definitions
* `fin.last n` : The greatest value of `fin (n+1)`.
-/
universe u
open fin nat function
/-- Elimination principle for the empty set `fin 0`, dependent version. -/
def fin_zero_elim {α : fin 0 → Sort u} (x : fin 0) : α x := x.elim0
namespace fin
variables {n m : ℕ} {a b : fin n}
@[simp] protected lemma eta (a : fin n) (h : a.1 < n) : (⟨a.1, h⟩ : fin n) = a :=
by cases a; refl
attribute [ext] eq_of_veq
protected lemma ext_iff (a b : fin n) : a = b ↔ a.val = b.val :=
iff.intro (congr_arg _) fin.eq_of_veq
lemma injective_val {n : ℕ} : injective (val : fin n → ℕ) := λ _ _, fin.eq_of_veq
lemma eq_iff_veq (a b : fin n) : a = b ↔ a.1 = b.1 :=
⟨veq_of_eq, eq_of_veq⟩
@[simp] protected lemma mk.inj_iff {n a b : ℕ} {ha : a < n} {hb : b < n} :
fin.mk a ha = fin.mk b hb ↔ a = b :=
⟨fin.mk.inj, λ h, by subst h⟩
instance fin_to_nat (n : ℕ) : has_coe (fin n) nat := ⟨fin.val⟩
lemma mk_val {m n : ℕ} (h : m < n) : (⟨m, h⟩ : fin n).val = m := rfl
@[simp] lemma coe_mk {m n : ℕ} (h : m < n) : ((⟨m, h⟩ : fin n) : ℕ) = m := rfl
lemma coe_eq_val (a : fin n) : (a : ℕ) = a.val := rfl
attribute [simp] val_zero
@[simp] lemma val_one {n : ℕ} : (1 : fin (n+2)).val = 1 := rfl
@[simp] lemma val_two {n : ℕ} : (2 : fin (n+3)).val = 2 := rfl
@[simp] lemma coe_zero {n : ℕ} : ((0 : fin (n+1)) : ℕ) = 0 := rfl
@[simp] lemma coe_one {n : ℕ} : ((1 : fin (n+2)) : ℕ) = 1 := rfl
@[simp] lemma coe_two {n : ℕ} : ((2 : fin (n+3)) : ℕ) = 2 := rfl
/-- Assume `k = l`. If two functions defined on `fin k` and `fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected lemma heq {α : Type*} {k l : ℕ} (h : k = l) {f : fin k → α} {g : fin l → α}
(H : ∀ (i : fin k), f i = g ⟨i.val, lt_of_lt_of_le i.2 (le_of_eq h)⟩) : f == g :=
by { induction h, rw heq_iff_eq, ext i, convert H i, exact (fin.ext_iff _ _).mpr rfl }
instance {n : ℕ} : decidable_linear_order (fin n) :=
decidable_linear_order.lift fin.val (@fin.eq_of_veq _) (by apply_instance)
lemma exists_iff {p : fin n → Prop} : (∃ i, p i) ↔ ∃ i h, p ⟨i, h⟩ :=
⟨λ h, exists.elim h (λ ⟨i, hi⟩ hpi, ⟨i, hi, hpi⟩),
λ h, exists.elim h (λ i hi, ⟨⟨i, hi.fst⟩, hi.snd⟩)⟩
lemma forall_iff {p : fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ :=
⟨λ h i hi, h ⟨i, hi⟩, λ h ⟨i, hi⟩, h i hi⟩
lemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1
lemma lt_iff_val_lt_val : a < b ↔ a.val < b.val := iff.rfl
lemma le_iff_val_le_val : a ≤ b ↔ a.val ≤ b.val := iff.rfl
@[simp] lemma succ_val (j : fin n) : j.succ.val = j.val.succ :=
by cases j; simp [fin.succ]
protected theorem succ.inj (p : fin.succ a = fin.succ b) : a = b :=
by cases a; cases b; exact eq_of_veq (nat.succ.inj (veq_of_eq p))
@[simp] lemma succ_inj {a b : fin n} : a.succ = b.succ ↔ a = b :=
⟨λh, succ.inj h, λh, by rw h⟩
lemma injective_succ (n : ℕ) : injective (@fin.succ n) :=
λa b, succ.inj
lemma succ_ne_zero {n} : ∀ k : fin n, fin.succ k ≠ 0
| ⟨k, hk⟩ heq := nat.succ_ne_zero k $ (fin.ext_iff _ _).1 heq
@[simp] lemma pred_val (j : fin (n+1)) (h : j ≠ 0) : (j.pred h).val = j.val.pred :=
by cases j; simp [fin.pred]
@[simp] lemma succ_pred : ∀(i : fin (n+1)) (h : i ≠ 0), (i.pred h).succ = i
| ⟨0, h⟩ hi := by contradiction
| ⟨n + 1, h⟩ hi := rfl
@[simp] lemma pred_succ (i : fin n) {h : i.succ ≠ 0} : i.succ.pred h = i :=
by cases i; refl
@[simp] lemma pred_inj :
∀ {a b : fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b
| ⟨0, _⟩ b ha hb := by contradiction
| ⟨i+1, _⟩ ⟨0, _⟩ ha hb := by contradiction
| ⟨i+1, hi⟩ ⟨j+1, hj⟩ ha hb := by simp [fin.eq_iff_veq]
/-- The greatest value of `fin (n+1)` -/
def last (n : ℕ) : fin (n+1) := ⟨_, n.lt_succ_self⟩
/-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into. -/
def cast_lt (i : fin m) (h : i.1 < n) : fin n := ⟨i.1, h⟩
/-- `cast_le h i` embeds `i` into a larger `fin` type. -/
def cast_le (h : n ≤ m) (a : fin n) : fin m := cast_lt a (lt_of_lt_of_le a.2 h)
/-- `cast eq i` embeds `i` into a equal `fin` type. -/
def cast (eq : n = m) : fin n → fin m := cast_le $ le_of_eq eq
/-- `cast_add m i` embeds `i : fin n` in `fin (n+m)`. -/
def cast_add (m) : fin n → fin (n + m) := cast_le $ le_add_right n m
/-- `cast_succ i` embeds `i : fin n` in `fin (n+1)`. -/
def cast_succ : fin n → fin (n + 1) := cast_add 1
/-- `succ_above p i` embeds `fin n` into `fin (n + 1)` with a hole around `p`. -/
def succ_above (p : fin (n+1)) (i : fin n) : fin (n+1) :=
if i.1 < p.1 then i.cast_succ else i.succ
/-- `pred_above p i h` embeds `i : fin (n+1)` into `fin n` by ignoring `p`. -/
def pred_above (p : fin (n+1)) (i : fin (n+1)) (hi : i ≠ p) : fin n :=
if h : i < p
then i.cast_lt (lt_of_lt_of_le h $ nat.le_of_lt_succ p.2)
else i.pred $
have p < i, from lt_of_le_of_ne (le_of_not_gt h) hi.symm,
ne_of_gt (lt_of_le_of_lt (zero_le p) this)
/-- `sub_nat i h` subtracts `m` from `i`, generalizes `fin.pred`. -/
def sub_nat (m) (i : fin (n + m)) (h : m ≤ i.val) : fin n :=
⟨i.val - m, by simp [nat.sub_lt_right_iff_lt_add h, i.is_lt]⟩
/-- `add_nat i h` adds `m` on `i`, generalizes `fin.succ`. -/
def add_nat (m) (i : fin n) : fin (n + m) :=
⟨i.1 + m, add_lt_add_right i.2 _⟩
/-- `nat_add i h` adds `n` on `i` -/
def nat_add (n) {m} (i : fin m) : fin (n + m) :=
⟨n + i.1, add_lt_add_left i.2 _⟩
theorem le_last (i : fin (n+1)) : i ≤ last n :=
le_of_lt_succ i.is_lt
@[simp] lemma cast_val (k : fin n) (h : n = m) : (fin.cast h k).val = k.val := rfl
@[simp] lemma cast_succ_val (k : fin n) : k.cast_succ.val = k.val := rfl
@[simp] lemma cast_lt_val (k : fin m) (h : k.1 < n) : (k.cast_lt h).val = k.val := rfl
@[simp] lemma cast_le_val (k : fin m) (h : m ≤ n) : (k.cast_le h).val = k.val := rfl
@[simp] lemma cast_add_val (k : fin m) : (k.cast_add n).val = k.val := rfl
@[simp] lemma last_val (n : ℕ) : (last n).val = n := rfl
@[simp] lemma succ_last (n : ℕ) : (last n).succ = last (n.succ) := rfl
@[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : i.val < n) : cast_succ (cast_lt i h) = i :=
fin.eq_of_veq rfl
@[simp] lemma cast_lt_cast_succ {n : ℕ} (a : fin n) (h : a.1 < n) : cast_lt (cast_succ a) h = a :=
by cases a; refl
@[simp] lemma sub_nat_val (i : fin (n + m)) (h : m ≤ i.val) : (i.sub_nat m h).val = i.val - m :=
rfl
@[simp] lemma add_nat_val (i : fin (n + m)) (h : m ≤ i.val) : (i.add_nat m).val = i.val + m :=
rfl
@[simp] lemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ ↔ a = b :=
by simp [eq_iff_veq]
lemma cast_succ_ne_last (a : fin n) : cast_succ a ≠ last n :=
by simp [eq_iff_veq, ne_of_lt a.2]
lemma eq_last_of_not_lt {i : fin (n+1)} (h : ¬ i.val < n) : i = last n :=
le_antisymm (le_last i) (not_lt.1 h)
lemma cast_succ_fin_succ (n : ℕ) (j : fin n) :
cast_succ (fin.succ j) = fin.succ (cast_succ j) :=
by simp [fin.ext_iff]
/-- `min n m` as an element of `fin (m + 1)` -/
def clamp (n m : ℕ) : fin (m + 1) := fin.of_nat $ min n m
@[simp] lemma clamp_val (n m : ℕ) : (clamp n m).val = min n m :=
nat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _
lemma injective_cast_le {n₁ n₂ : ℕ} (h : n₁ ≤ n₂) : injective (fin.cast_le h)
| ⟨i₁, h₁⟩ ⟨i₂, h₂⟩ eq := fin.eq_of_veq $ show i₁ = i₂, from fin.veq_of_eq eq
lemma injective_cast_succ (n : ℕ) : injective (@fin.cast_succ n) :=
injective_cast_le (le_add_right n 1)
theorem succ_above_ne (p : fin (n+1)) (i : fin n) : p.succ_above i ≠ p :=
begin
assume eq,
unfold fin.succ_above at eq,
split_ifs at eq with h;
simpa [lt_irrefl, nat.lt_succ_self, eq.symm] using h
end
@[simp] lemma succ_above_descend : ∀(p i : fin (n+1)) (h : i ≠ p), p.succ_above (p.pred_above i h) = i
| ⟨p, hp⟩ ⟨0, hi⟩ h := fin.eq_of_veq $ by simp [succ_above, pred_above]; split_ifs; simp * at *
| ⟨p, hp⟩ ⟨i+1, hi⟩ h := fin.eq_of_veq
begin
have : i + 1 ≠ p, by rwa [(≠), fin.ext_iff] at h,
unfold succ_above pred_above,
split_ifs with h1 h2;
simp only [fin.cast_succ_cast_lt, add_right_inj, pred_val, ne.def, cast_succ_val,
nat.pred_succ, fin.succ_pred, add_right_inj] at *,
exact (this (le_antisymm h2 (le_of_not_gt h1))).elim
end
@[simp] lemma pred_above_succ_above (p : fin (n+1)) (i : fin n) (h : p.succ_above i ≠ p) :
p.pred_above (p.succ_above i) h = i :=
begin
unfold fin.succ_above,
apply eq_of_veq,
split_ifs with h₀,
{ simp [pred_above, h₀, lt_iff_val_lt_val], },
{ unfold pred_above,
split_ifs with h₁,
{ exfalso,
rw [lt_iff_val_lt_val, succ_val] at h₁,
exact h₀ (lt_trans (nat.lt_succ_self _) h₁) },
{ rw [pred_succ] } }
end
section rec
/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`.
This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,
and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element
of `n`-tuple. -/
@[elab_as_eliminator] def succ_rec
{C : Π n, fin n → Sort*}
(H0 : Π n, C (succ n) 0)
(Hs : Π n i, C n i → C (succ n) i.succ) : Π {n : ℕ} (i : fin n), C n i
| 0 i := i.elim0
| (succ n) ⟨0, _⟩ := H0 _
| (succ n) ⟨succ i, h⟩ := Hs _ _ (succ_rec ⟨i, lt_of_succ_lt_succ h⟩)
/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`.
This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,
and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element
of `n`-tuple.
A version of `fin.succ_rec` taking `i : fin n` as the first argument. -/
@[elab_as_eliminator] def succ_rec_on {n : ℕ} (i : fin n)
{C : Π n, fin n → Sort*}
(H0 : Π n, C (succ n) 0)
(Hs : Π n i, C n i → C (succ n) i.succ) : C n i :=
i.succ_rec H0 Hs
@[simp] theorem succ_rec_on_zero {C : ∀ n, fin n → Sort*} {H0 Hs} (n) :
@fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n :=
rfl
@[simp] theorem succ_rec_on_succ {C : ∀ n, fin n → Sort*} {H0 Hs} {n} (i : fin n) :
@fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) :=
by cases i; refl
/-- Define `f : Π i : fin n.succ, C i` by separately handling the cases `i = 0` and
`i = j.succ`, `j : fin n`. -/
@[elab_as_eliminator] def cases
{C : fin (succ n) → Sort*} (H0 : C 0) (Hs : Π i : fin n, C (i.succ)) :
Π (i : fin (succ n)), C i
| ⟨0, h⟩ := H0
| ⟨succ i, h⟩ := Hs ⟨i, lt_of_succ_lt_succ h⟩
@[simp] theorem cases_zero {n} {C : fin (succ n) → Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 :=
rfl
@[simp] theorem cases_succ {n} {C : fin (succ n) → Sort*} {H0 Hs} (i : fin n) :
@fin.cases n C H0 Hs i.succ = Hs i :=
by cases i; refl
lemma forall_fin_succ {P : fin (n+1) → Prop} :
(∀ i, P i) ↔ P 0 ∧ (∀ i:fin n, P i.succ) :=
⟨λ H, ⟨H 0, λ i, H _⟩, λ ⟨H0, H1⟩ i, fin.cases H0 H1 i⟩
lemma exists_fin_succ {P : fin (n+1) → Prop} :
(∃ i, P i) ↔ P 0 ∨ (∃i:fin n, P i.succ) :=
⟨λ ⟨i, h⟩, fin.cases or.inl (λ i hi, or.inr ⟨i, hi⟩) i h,
λ h, or.elim h (λ h, ⟨0, h⟩) $ λ⟨i, hi⟩, ⟨i.succ, hi⟩⟩
end rec
section tuple
/-!
### Tuples
We can think of the type `Π(i : fin n), α i` as `n`-tuples of elements of possibly varying type
`α i`. A particular case is `fin n → α` of elements with all the same type. Here are some relevant
operations, first about adding or removing elements at the beginning of a tuple.
-/
/-- There is exactly one tuple of size zero. -/
instance tuple0_unique (α : fin 0 → Type u) : unique (Π i : fin 0, α i) :=
{ default := fin_zero_elim, uniq := λ x, funext fin_zero_elim }
variables {α : fin (n+1) → Type u} (x : α 0) (q : Πi, α i) (p : Π(i : fin n), α (i.succ))
(i : fin n) (y : α i.succ) (z : α 0)
/-- The tail of an `n+1` tuple, i.e., its last `n` entries -/
def tail (q : Πi, α i) : (Π(i : fin n), α (i.succ)) := λ i, q i.succ
/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple -/
def cons (x : α 0) (p : Π(i : fin n), α (i.succ)) : Πi, α i :=
λ j, fin.cases x p j
@[simp] lemma tail_cons : tail (cons x p) = p :=
by simp [tail, cons]
@[simp] lemma cons_succ : cons x p i.succ = p i :=
by simp [cons]
@[simp] lemma cons_zero : cons x p 0 = x :=
by simp [cons]
/-- Updating a tuple and adding an element at the beginning commute. -/
@[simp] lemma cons_update : cons x (update p i y) = update (cons x p) i.succ y :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp [ne.symm (succ_ne_zero i)] },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ],
by_cases h' : j' = i,
{ rw h', simp },
{ have : j'.succ ≠ i.succ, by rwa [ne.def, succ_inj],
rw [update_noteq h', update_noteq this, cons_succ] } }
end
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/
lemma update_cons_zero : update (cons x p) 0 z = cons z p :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp },
{ simp only [h, update_noteq, ne.def, not_false_iff],
let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ, cons_succ] }
end
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp] lemma cons_self_tail : cons (q 0) (tail q) = q :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, tail, cons_succ] }
end
/-- Updating the first element of a tuple does not change the tail. -/
@[simp] lemma tail_update_zero : tail (update q 0 z) = tail q :=
by { ext j, simp [tail, fin.succ_ne_zero] }
/-- Updating a nonzero element and taking the tail commute. -/
@[simp] lemma tail_update_succ :
tail (update q i.succ y) = update (tail q) i y :=
begin
ext j,
by_cases h : j = i,
{ rw h, simp [tail] },
{ simp [tail, (fin.injective_succ n).ne h, h] }
end
lemma comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : fin n → α) :
g ∘ (cons y q) = cons (g y) (g ∘ q) :=
begin
ext j,
by_cases h : j = 0,
{ rw h, refl },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ, comp_app, cons_succ] }
end
lemma comp_tail {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :
g ∘ (tail q) = tail (g ∘ q) :=
by { ext j, simp [tail] }
end tuple
section tuple_right
/-! In the previous section, we have discussed inserting or removing elements on the left of a tuple.
In this section, we do the same on the right. A difference is that `fin (n+1)` is constructed
inductively from `fin n` starting from the left, not from the right. This implies that Lean needs
more help to realize that elements belong to the right types, i.e., we need to insert casts at
several places. -/
variables {α : fin (n+1) → Type u} (x : α (last n)) (q : Πi, α i) (p : Π(i : fin n), α i.cast_succ)
(i : fin n) (y : α i.cast_succ) (z : α (last n))
/-- The beginning of an `n+1` tuple, i.e., its first `n` entries -/
def init (q : Πi, α i) (i : fin n) : α i.cast_succ :=
q i.cast_succ
/-- Adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from
`cons` (i.e., adding an element to the left of a tuple) read in reverse order. -/
def snoc (p : Π(i : fin n), α i.cast_succ) (x : α (last n)) (i : fin (n+1)) : α i :=
if h : i.val < n
then _root_.cast (by rw fin.cast_succ_cast_lt i h) (p (cast_lt i h))
else _root_.cast (by rw eq_last_of_not_lt h) x
@[simp] lemma init_snoc : init (snoc p x) = p :=
begin
ext i,
have h' := fin.cast_lt_cast_succ i i.is_lt,
simp [init, snoc, i.is_lt, h'],
convert cast_eq rfl (p i)
end
@[simp] lemma snoc_cast_succ : snoc p x i.cast_succ = p i :=
begin
have : i.cast_succ.val < n := i.is_lt,
have h' := fin.cast_lt_cast_succ i i.is_lt,
simp [snoc, this, h'],
convert cast_eq rfl (p i)
end
@[simp] lemma snoc_last : snoc p x (last n) = x :=
by { simp [snoc], refl }
/-- Updating a tuple and adding an element at the end commute. -/
@[simp] lemma snoc_update : snoc (update p i y) x = update (snoc p x) i.cast_succ y :=
begin
ext j,
by_cases h : j.val < n,
{ simp only [snoc, h, dif_pos],
by_cases h' : j = cast_succ i,
{ have C1 : α i.cast_succ = α j, by rw h',
have E1 : update (snoc p x) i.cast_succ y j = _root_.cast C1 y,
{ have : update (snoc p x) j (_root_.cast C1 y) j = _root_.cast C1 y, by simp,
convert this,
{ exact h'.symm },
{ exact heq_of_eq_mp (congr_arg α (eq.symm h')) rfl } },
have C2 : α i.cast_succ = α (cast_succ (cast_lt j h)),
by rw [cast_succ_cast_lt, h'],
have E2 : update p i y (cast_lt j h) = _root_.cast C2 y,
{ have : update p (cast_lt j h) (_root_.cast C2 y) (cast_lt j h) = _root_.cast C2 y,
by simp,
convert this,
{ simp [h, h'] },
{ exact heq_of_eq_mp C2 rfl } },
rw [E1, E2],
exact eq_rec_compose _ _ _ },
{ have : ¬(cast_lt j h = i),
by { assume E, apply h', rw [← E, cast_succ_cast_lt] },
simp [h', this, snoc, h] } },
{ rw eq_last_of_not_lt h,
simp [ne.symm (cast_succ_ne_last i)] }
end
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it directly. -/
lemma update_snoc_last : update (snoc p x) (last n) z = snoc p z :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, update_noteq, this, snoc] },
{ rw eq_last_of_not_lt h,
simp }
end
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp] lemma snoc_init_self : snoc (init q) (q (last n)) = q :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, update_noteq, this, snoc, init, cast_succ_cast_lt],
have A : cast_succ (cast_lt j h) = j := cast_succ_cast_lt _ _,
rw ← cast_eq rfl (q j),
congr' 1; rw A },
{ rw eq_last_of_not_lt h,
simp }
end
/-- Updating the last element of a tuple does not change the beginning. -/
@[simp] lemma init_update_last : init (update q (last n) z) = init q :=
by { ext j, simp [init, cast_succ_ne_last] }
/-- Updating an element and taking the beginning commute. -/
@[simp] lemma init_update_cast_succ :
init (update q i.cast_succ y) = update (init q) i y :=
begin
ext j,
by_cases h : j = i,
{ rw h, simp [init] },
{ simp [init, h] }
end
/-- `tail` and `init` commute. We state this lemma in a non-dependent setting, as otherwise it
would involve a cast to convince Lean that the two types are equal, making it harder to use. -/
lemma tail_init_eq_init_tail {β : Type*} (q : fin (n+2) → β) :
tail (init q) = init (tail q) :=
by { ext i, simp [tail, init, cast_succ_fin_succ] }
/-- `cons` and `snoc` commute. We state this lemma in a non-dependent setting, as otherwise it
would involve a cast to convince Lean that the two types are equal, making it harder to use. -/
lemma cons_snoc_eq_snoc_cons {β : Type*} (a : β) (q : fin n → β) (b : β) :
@cons n.succ (λ i, β) a (snoc q b) = snoc (cons a q) b :=
begin
ext i,
by_cases h : i = 0,
{ rw h, refl },
set j := pred i h with ji,
have : i = j.succ, by rw [ji, succ_pred],
rw [this, cons_succ],
by_cases h' : j.val < n,
{ set k := cast_lt j h' with jk,
have : j = k.cast_succ, by rw [jk, cast_succ_cast_lt],
rw [this, ← cast_succ_fin_succ],
simp },
rw [eq_last_of_not_lt h', succ_last],
simp
end
lemma comp_snoc {α : Type*} {β : Type*} (g : α → β) (q : fin n → α) (y : α) :
g ∘ (snoc q y) = snoc (g ∘ q) (g y) :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, this, snoc, cast_succ_cast_lt],
refl },
{ rw eq_last_of_not_lt h,
simp }
end
lemma comp_init {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :
g ∘ (init q) = init (g ∘ q) :=
by { ext j, simp [init] }
end tuple_right
section find
/-- `find p` returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied. -/
def find : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p], option (fin n)
| 0 p _ := none
| (n+1) p _ := by resetI; exact option.cases_on
(@find n (λ i, p (i.cast_lt (nat.lt_succ_of_lt i.2))) _)
(if h : p (fin.last n) then some (fin.last n) else none)
(λ i, some (i.cast_lt (nat.lt_succ_of_lt i.2)))
/-- If `find p = some i`, then `p i` holds -/
lemma find_spec : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p] {i : fin n}
(hi : i ∈ by exactI fin.find p), p i
| 0 p I i hi := option.no_confusion hi
| (n+1) p I i hi := begin
dsimp [find] at hi,
resetI,
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ rw h at hi,
dsimp at hi,
split_ifs at hi with hl hl,
{ exact option.some_inj.1 hi ▸ hl },
{ exact option.no_confusion hi } },
{ rw h at hi,
rw [← option.some_inj.1 hi],
exact find_spec _ h }
end
/-- `find p` does not return `none` if and only if `p i` holds at some index `i`. -/
lemma is_some_find_iff : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p],
by exactI (find p).is_some ↔ ∃ i, p i
| 0 p _ := iff_of_false (λ h, bool.no_confusion h) (λ ⟨i, _⟩, fin.elim0 i)
| (n+1) p _ := ⟨λ h, begin
resetI,
rw [option.is_some_iff_exists] at h,
cases h with i hi,
exact ⟨i, find_spec _ hi⟩
end, λ ⟨⟨i, hin⟩, hi⟩,
begin
resetI,
dsimp [find],
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ split_ifs with hl hl,
{ exact option.is_some_some },
{ have := (@is_some_find_iff n (λ x, p (x.cast_lt (nat.lt_succ_of_lt x.2))) _).2
⟨⟨i, lt_of_le_of_ne (nat.le_of_lt_succ hin)
(λ h, by clear_aux_decl; subst h; exact hl hi)⟩, hi⟩,
rw h at this,
exact this } },
{ simp }
end⟩
/-- `find p` returns `none` if and only if `p i` never holds. -/
lemma find_eq_none_iff {n : ℕ} {p : fin n → Prop} [decidable_pred p] :
find p = none ↔ ∀ i, ¬ p i :=
by rw [← not_exists, ← is_some_find_iff]; cases (find p); simp
/-- If `find p` returns `some i`, then `p j` does not hold for `j < i`, i.e., `i` is minimal among
the indices where `p` holds. -/
lemma find_min : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p] {i : fin n}
(hi : i ∈ by exactI fin.find p) {j : fin n} (hj : j < i), ¬ p j
| 0 p _ i hi j hj hpj := option.no_confusion hi
| (n+1) p _ i hi ⟨j, hjn⟩ hj hpj := begin
resetI,
dsimp [find] at hi,
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with k,
{ rw [h] at hi,
split_ifs at hi with hl hl,
{ have := option.some_inj.1 hi,
subst this,
rw [find_eq_none_iff] at h,
exact h ⟨j, hj⟩ hpj },
{ exact option.no_confusion hi } },
{ rw h at hi,
dsimp at hi,
have := option.some_inj.1 hi,
subst this,
exact find_min h (show (⟨j, lt_trans hj k.2⟩ : fin n) < k, from hj) hpj }
end
lemma find_min' {p : fin n → Prop} [decidable_pred p] {i : fin n}
(h : i ∈ fin.find p) {j : fin n} (hj : p j) : i ≤ j :=
le_of_not_gt (λ hij, find_min h hij hj)
lemma nat_find_mem_find {p : fin n → Prop} [decidable_pred p]
(h : ∃ i, ∃ hin : i < n, p ⟨i, hin⟩) :
(⟨nat.find h, (nat.find_spec h).fst⟩ : fin n) ∈ find p :=
let ⟨i, hin, hi⟩ := h in
begin
cases hf : find p with f,
{ rw [find_eq_none_iff] at hf,
exact (hf ⟨i, hin⟩ hi).elim },
{ refine option.some_inj.2 (le_antisymm _ _),
{ exact find_min' hf (nat.find_spec h).snd },
{ exact nat.find_min' _ ⟨f.2, by convert find_spec p hf;
exact fin.eta _ _⟩ } }
end
lemma mem_find_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :
i ∈ fin.find p ↔ p i ∧ ∀ j, p j → i ≤ j :=
⟨λ hi, ⟨find_spec _ hi, λ _, find_min' hi⟩,
begin
rintros ⟨hpi, hj⟩,
cases hfp : fin.find p,
{ rw [find_eq_none_iff] at hfp,
exact (hfp _ hpi).elim },
{ exact option.some_inj.2 (le_antisymm (find_min' hfp hpi) (hj _ (find_spec _ hfp))) }
end⟩
lemma find_eq_some_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :
fin.find p = some i ↔ p i ∧ ∀ j, p j → i ≤ j :=
mem_find_iff
lemma mem_find_of_unique {p : fin n → Prop} [decidable_pred p]
(h : ∀ i j, p i → p j → i = j) {i : fin n} (hi : p i) : i ∈ fin.find p :=
mem_find_iff.2 ⟨hi, λ j hj, le_of_eq $ h i j hi hj⟩
end find
end fin
|
9abc4604ffbb23bbd474f56ff47d8882ec715909 | 4a092885406df4e441e9bb9065d9405dacb94cd8 | /src/for_mathlib/lc_algebra.lean | 98fe46feddbc17a79b2cd9b655300a8c2634d8e6 | [
"Apache-2.0"
] | permissive | semorrison/lean-perfectoid-spaces | 78c1572cedbfae9c3e460d8aaf91de38616904d8 | bb4311dff45791170bcb1b6a983e2591bee88a19 | refs/heads/master | 1,588,841,765,494 | 1,554,805,620,000 | 1,554,805,620,000 | 180,353,546 | 0 | 1 | null | 1,554,809,880,000 | 1,554,809,880,000 | null | UTF-8 | Lean | false | false | 4,686 | lean | import ring_theory.algebra
import linear_algebra.linear_combination
local attribute [instance, priority 0] classical.prop_decidable
noncomputable theory
namespace lc
open finsupp
variables {R : Type*} {A : Type*} [comm_ring R] [ring A] [algebra R A]
variables (f g h : lc R A)
def one : lc R A := single 1 1
instance : has_one (lc R A) := ⟨one⟩
lemma one_def : (1 : lc R A) = single 1 1 := rfl
def mul := f.sum $ λ r a, g.sum $ λ s b, single (r * s) (a * b)
instance : has_mul (lc R A) := ⟨mul⟩
lemma mul_def :
f * g = (f.sum $ λ r a, g.sum $ λ s b, single (r * s) (a * b)) := rfl
@[simp] lemma one_mul : 1 * f = f :=
by simp [one_def, mul_def, sum_single_index]
@[simp] lemma mul_one : f * 1 = f :=
by simp [one_def, mul_def, sum_single_index]
lemma mul_assoc : (f * g) * h = f * (g * h) :=
begin
repeat {rw mul_def},
rw sum_sum_index,
{ congr' 1,
funext a r,
repeat {rw sum_sum_index},
{ congr' 1,
funext b s,
rw sum_sum_index,
{ simp only [sum_single_index, zero_mul, sum_zero, single_zero, mul_zero],
congr' 1,
funext,
repeat {rw mul_assoc} },
all_goals { simp [left_distrib] } },
swap 4,
{ intros,
erw ← sum_add,
simp [right_distrib] },
all_goals { simp [left_distrib] } },
{ simp },
{ intros,
erw ← sum_add,
simp [right_distrib] }
end
instance : monoid (lc R A) :=
{ mul := mul,
mul_assoc := mul_assoc,
one_mul := one_mul,
mul_one := mul_one,
..lc.has_one }
lemma left_distrib : f * (g + h) = f * g + f * h :=
by simp only [mul_def, sum_add_index, left_distrib, sum_add, sum_zero, mul_zero,
single_add, single_zero, eq_self_iff_true, add_right_inj, forall_3_true_iff, forall_true_iff]
lemma right_distrib : (f + g) * h = f * h + g * h :=
by simp only [mul_def, sum_add_index, right_distrib, sum_add, sum_zero, zero_mul,
single_add, single_zero, eq_self_iff_true, add_right_inj, forall_3_true_iff, forall_true_iff]
instance : ring (lc R A) :=
{ left_distrib := left_distrib,
right_distrib := right_distrib,
..lc.monoid,
..lc.add_comm_group }
instance single.is_ring_hom : is_ring_hom (single 1 : R → lc R A) :=
{ map_one := rfl,
map_mul := λ _ _, by simp [mul_def, sum_single_index],
map_add := λ _ _, single_add }
instance single_swap.is_monoid_hom :
is_monoid_hom ((λ r, single (algebra_map A r) 1) : R → lc R A) :=
{ map_one := by simpa,
map_mul := λ _ _, by simp [mul_def, sum_single_index] }
instance : algebra R (lc R A) :=
{ to_fun := single 1,
hom := by apply_instance,
commutes' := by simp [mul_def, sum_single_index, mul_comm],
smul_def' := λ r f, finsupp.induction f (by simp) $ λ a b f ha hb IH,
by simp [mul_def, sum_single_index, smul_add, IH, left_distrib] }
instance total.is_ring_hom : is_ring_hom (lc.total R A) :=
{ map_one := by rw [one_def, total_single, one_smul],
map_mul := λ f g,
begin
repeat {erw total_apply},
rw mul_def,
rw sum_mul,
simp only [mul_sum],
rw sum_sum_index,
{ apply finset.sum_congr rfl,
intros a ha,
change finsupp.sum _ _ = sum _ _,
rw sum_sum_index,
{ apply finset.sum_congr rfl,
intros b hb,
change finsupp.sum _ _ = _,
rw sum_single_index,
{ change _ = _ • _ * _ • _,
rw [algebra.smul_mul_assoc, algebra.mul_smul_comm, smul_smul] },
{ apply zero_smul } },
{ apply zero_smul },
{ intros, apply add_smul } },
{ apply zero_smul },
{ intros, apply add_smul }
end,
map_add := (lc.total R A).map_add }
def atotal : lc R A →ₐ[R] A :=
{ hom := by apply_instance,
commutes' := λ r, by convert total_single _ _; simp [algebra.smul_def],
..lc.total R A }
section
open finset
lemma support_mul (f g : lc R A) :
(f * g).support ⊆ (image (λ x : A × A, x.fst * x.snd) $ f.support.product g.support) :=
begin
rw mul_def,
refine subset.trans support_sum _,
intros a' ha,
erw mem_bind at ha,
rcases ha with ⟨a, ha₁, ha₂⟩,
have hb := finsupp.support_sum ha₂,
erw mem_bind at hb,
rcases hb with ⟨b, hb₁, hb₂⟩,
have H := finsupp.support_single_subset hb₂,
erw set.mem_singleton_iff at H,
subst H,
rw mem_image,
use (a, b),
split,
{ rw mem_product,
split; assumption },
{ simp * }
end
end
end lc
namespace lc
open finsupp finset
variables {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A]
variables (f g : lc R A)
lemma mul_comm : f * g = g * f :=
begin
simp only [mul_def, finsupp.sum],
rw sum_comm,
iterate 2 {congr' 1, funext},
congr' 1; rw mul_comm,
end
instance : comm_ring (lc R A) :=
{ mul_comm := mul_comm,
..lc.ring }
end lc
|
f2a67637af89d73b2c2aa586534db279378a9ab0 | b32d3853770e6eaf06817a1b8c52064baaed0ef1 | /src/super/default.lean | 7248199b0eff2827190071287b805ddb0d7b0b5e | [] | no_license | gebner/super2 | 4d58b7477b6f7d945d5d866502982466db33ab0b | 9bc5256c31750021ab97d6b59b7387773e54b384 | refs/heads/master | 1,635,021,682,021 | 1,634,886,326,000 | 1,634,886,326,000 | 225,600,688 | 4 | 2 | null | 1,598,209,306,000 | 1,575,371,550,000 | Lean | UTF-8 | Lean | false | false | 20 | lean | import super.prover
|
3d6a5e21a4f660f7829fbc940a06989dccea73b5 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/topology/algebra/uniform_ring.lean | f86840b83de2e79a5d367fc32fd93c59bf108c87 | [
"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 | 7,422 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
Theory of topological rings with uniform structure.
-/
import topology.algebra.group_completion
import topology.algebra.ring
open classical set filter topological_space add_comm_group
open_locale classical
noncomputable theory
namespace uniform_space.completion
open dense_inducing uniform_space function
variables (α : Type*) [ring α] [uniform_space α]
instance : has_one (completion α) := ⟨(1:α)⟩
instance : has_mul (completion α) :=
⟨curry $ (dense_inducing_coe.prod dense_inducing_coe).extend (coe ∘ uncurry (*))⟩
@[norm_cast] lemma coe_one : ((1 : α) : completion α) = 1 := rfl
variables {α} [topological_ring α]
@[norm_cast]
lemma coe_mul (a b : α) : ((a * b : α) : completion α) = a * b :=
((dense_inducing_coe.prod dense_inducing_coe).extend_eq
((continuous_coe α).comp continuous_mul) (a, b)).symm
variables [uniform_add_group α]
lemma continuous_mul : continuous (λ p : completion α × completion α, p.1 * p.2) :=
begin
haveI : is_Z_bilin ((coe ∘ uncurry (*)) : α × α → completion α) :=
{ add_left := begin
introv,
change coe ((a + a')*b) = coe (a*b) + coe (a'*b),
rw_mod_cast add_mul
end,
add_right := begin
introv,
change coe (a*(b + b')) = coe (a*b) + coe (a*b'),
rw_mod_cast mul_add
end },
have : continuous ((coe ∘ uncurry (*)) : α × α → completion α),
from (continuous_coe α).comp continuous_mul,
convert dense_inducing_coe.extend_Z_bilin dense_inducing_coe this,
simp only [(*), curry, prod.mk.eta]
end
lemma continuous.mul {β : Type*} [topological_space β] {f g : β → completion α}
(hf : continuous f) (hg : continuous g) : continuous (λb, f b * g b) :=
continuous_mul.comp (continuous.prod_mk hf hg)
instance : ring (completion α) :=
{ one_mul := assume a, completion.induction_on a
(is_closed_eq (continuous.mul continuous_const continuous_id) continuous_id)
(assume a, by rw [← coe_one, ← coe_mul, one_mul]),
mul_one := assume a, completion.induction_on a
(is_closed_eq (continuous.mul continuous_id continuous_const) continuous_id)
(assume a, by rw [← coe_one, ← coe_mul, mul_one]),
mul_assoc := assume a b c, completion.induction_on₃ a b c
(is_closed_eq
(continuous.mul (continuous.mul continuous_fst (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd))
(continuous.mul continuous_fst
(continuous.mul (continuous_fst.comp continuous_snd) (continuous_snd.comp continuous_snd))))
(assume a b c, by rw [← coe_mul, ← coe_mul, ← coe_mul, ← coe_mul, mul_assoc]),
left_distrib := assume a b c, completion.induction_on₃ a b c
(is_closed_eq
(continuous.mul continuous_fst (continuous.add
(continuous_fst.comp continuous_snd)
(continuous_snd.comp continuous_snd)))
(continuous.add
(continuous.mul continuous_fst (continuous_fst.comp continuous_snd))
(continuous.mul continuous_fst (continuous_snd.comp continuous_snd))))
(assume a b c, by rw [← coe_add, ← coe_mul, ← coe_mul, ← coe_mul, ←coe_add, mul_add]),
right_distrib := assume a b c, completion.induction_on₃ a b c
(is_closed_eq
(continuous.mul (continuous.add continuous_fst
(continuous_fst.comp continuous_snd)) (continuous_snd.comp continuous_snd))
(continuous.add
(continuous.mul continuous_fst (continuous_snd.comp continuous_snd))
(continuous.mul (continuous_fst.comp continuous_snd) (continuous_snd.comp continuous_snd))))
(assume a b c, by rw [← coe_add, ← coe_mul, ← coe_mul, ← coe_mul, ←coe_add, add_mul]),
..completion.add_comm_group, ..completion.has_mul α, ..completion.has_one α }
/-- The map from a uniform ring to its completion, as a ring homomorphism. -/
def coe_ring_hom : α →+* completion α :=
⟨coe, coe_one α, assume a b, coe_mul a b, coe_zero, assume a b, coe_add a b⟩
universes u
variables {β : Type u} [uniform_space β] [ring β] [uniform_add_group β] [topological_ring β]
(f : α →+* β) (hf : continuous f)
/-- The completion extension as a ring morphism. -/
def extension_hom [complete_space β] [separated_space β] :
completion α →+* β :=
have hf : uniform_continuous f, from uniform_continuous_of_continuous hf,
{ to_fun := completion.extension f,
map_zero' := by rw [← coe_zero, extension_coe hf, f.map_zero],
map_add' := assume a b, completion.induction_on₂ a b
(is_closed_eq
(continuous_extension.comp continuous_add)
((continuous_extension.comp continuous_fst).add
(continuous_extension.comp continuous_snd)))
(assume a b,
by rw [← coe_add, extension_coe hf, extension_coe hf, extension_coe hf,
f.map_add]),
map_one' := by rw [← coe_one, extension_coe hf, f.map_one],
map_mul' := assume a b, completion.induction_on₂ a b
(is_closed_eq
(continuous_extension.comp continuous_mul)
((continuous_extension.comp continuous_fst).mul (continuous_extension.comp continuous_snd)))
(assume a b,
by rw [← coe_mul, extension_coe hf, extension_coe hf, extension_coe hf, f.map_mul]) }
instance top_ring_compl : topological_ring (completion α) :=
{ continuous_add := continuous_add,
continuous_mul := continuous_mul,
continuous_neg := continuous_neg }
/-- The completion map as a ring morphism. -/
def map_ring_hom : completion α →+* completion β :=
extension_hom (coe_ring_hom.comp f) ((continuous_coe β).comp hf)
variables (R : Type*) [comm_ring R] [uniform_space R] [uniform_add_group R] [topological_ring R]
instance : comm_ring (completion R) :=
{ mul_comm := assume a b, completion.induction_on₂ a b
(is_closed_eq (continuous_fst.mul continuous_snd)
(continuous_snd.mul continuous_fst))
(assume a b, by rw [← coe_mul, ← coe_mul, mul_comm]),
..completion.ring }
end uniform_space.completion
namespace uniform_space
variables {α : Type*}
lemma ring_sep_rel (α) [comm_ring α] [uniform_space α] [uniform_add_group α] [topological_ring α] :
separation_setoid α = submodule.quotient_rel (ideal.closure ⊥) :=
setoid.ext $ assume x y, group_separation_rel x y
lemma ring_sep_quot (α) [r : comm_ring α] [uniform_space α] [uniform_add_group α] [topological_ring α] :
quotient (separation_setoid α) = (⊥ : ideal α).closure.quotient :=
by rw [@ring_sep_rel α r]; refl
def sep_quot_equiv_ring_quot (α)
[r : comm_ring α] [uniform_space α] [uniform_add_group α] [topological_ring α] :
quotient (separation_setoid α) ≃ (⊥ : ideal α).closure.quotient :=
quotient.congr_right $ assume x y, group_separation_rel x y
/- TODO: use a form of transport a.k.a. lift definition a.k.a. transfer -/
instance [comm_ring α] [uniform_space α] [uniform_add_group α] [topological_ring α] :
comm_ring (quotient (separation_setoid α)) :=
by rw ring_sep_quot α; apply_instance
instance [comm_ring α] [uniform_space α] [uniform_add_group α] [topological_ring α] :
topological_ring (quotient (separation_setoid α)) :=
begin
convert topological_ring_quotient (⊥ : ideal α).closure; try {apply ring_sep_rel},
simp [uniform_space.comm_ring]
end
end uniform_space
|
1d021af8a85e87c0e34b7aa494711eb7f112b6f1 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/ring_theory/power_basis.lean | a03c727eba93a2c74b2f64fa8b773d6988b3bfa6 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 18,257 | lean | /-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import field_theory.minpoly
/-!
# Power basis
This file defines a structure `power_basis R S`, giving a basis of the
`R`-algebra `S` as a finite list of powers `1, x, ..., x^n`.
For example, if `x` is algebraic over a ring/field, adjoining `x`
gives a `power_basis` structure generated by `x`.
## Definitions
* `power_basis R A`: a structure containing an `x` and an `n` such that
`1, x, ..., x^n` is a basis for the `R`-algebra `A` (viewed as an `R`-module).
* `finrank (hf : f ≠ 0) : finite_dimensional.finrank K (adjoin_root f) = f.nat_degree`,
the dimension of `adjoin_root f` equals the degree of `f`
* `power_basis.lift (pb : power_basis R S)`: if `y : S'` satisfies the same
equations as `pb.gen`, this is the map `S →ₐ[R] S'` sending `pb.gen` to `y`
* `power_basis.equiv`: if two power bases satisfy the same equations, they are
equivalent as algebras
## Implementation notes
Throughout this file, `R`, `S`, ... are `comm_ring`s, `A`, `B`, ... are
`integral_domain`s and `K`, `L`, ... are `field`s.
`S` is an `R`-algebra, `B` is an `A`-algebra, `L` is a `K`-algebra.
## Tags
power basis, powerbasis
-/
open polynomial
variables {R S T : Type*} [comm_ring R] [comm_ring S] [comm_ring T]
variables [algebra R S] [algebra S T] [algebra R T] [is_scalar_tower R S T]
variables {A B : Type*} [integral_domain A] [integral_domain B] [algebra A B]
variables {K L : Type*} [field K] [field L] [algebra K L]
/-- `pb : power_basis R S` states that `1, pb.gen, ..., pb.gen ^ (pb.dim - 1)`
is a basis for the `R`-algebra `S` (viewed as `R`-module).
This is a structure, not a class, since the same algebra can have many power bases.
For the common case where `S` is defined by adjoining an integral element to `R`,
the canonical power basis is given by `{algebra,intermediate_field}.adjoin.power_basis`.
-/
@[nolint has_inhabited_instance]
structure power_basis (R S : Type*) [comm_ring R] [ring S] [algebra R S] :=
(gen : S)
(dim : ℕ)
(basis : basis (fin dim) R S)
(basis_eq_pow : ∀ i, basis i = gen ^ (i : ℕ))
namespace power_basis
@[simp] lemma coe_basis (pb : power_basis R S) :
⇑pb.basis = λ (i : fin pb.dim), pb.gen ^ (i : ℕ) :=
funext pb.basis_eq_pow
/-- Cannot be an instance because `power_basis` cannot be a class. -/
lemma finite_dimensional [algebra K S] (pb : power_basis K S) : finite_dimensional K S :=
finite_dimensional.of_fintype_basis pb.basis
lemma finrank [algebra K S] (pb : power_basis K S) : finite_dimensional.finrank K S = pb.dim :=
by rw [finite_dimensional.finrank_eq_card_basis pb.basis, fintype.card_fin]
lemma mem_span_pow' {x y : S} {d : ℕ} :
y ∈ submodule.span R (set.range (λ (i : fin d), x ^ (i : ℕ))) ↔
∃ f : polynomial R, f.degree < d ∧ y = aeval x f :=
begin
have : set.range (λ (i : fin d), x ^ (i : ℕ)) = (λ (i : ℕ), x ^ i) '' ↑(finset.range d),
{ ext n,
simp_rw [set.mem_range, set.mem_image, finset.mem_coe, finset.mem_range],
exact ⟨λ ⟨⟨i, hi⟩, hy⟩, ⟨i, hi, hy⟩, λ ⟨i, hi, hy⟩, ⟨⟨i, hi⟩, hy⟩⟩ },
simp only [this, finsupp.mem_span_image_iff_total, degree_lt_iff_coeff_zero,
exists_iff_exists_finsupp, coeff, aeval, eval₂_ring_hom', eval₂_eq_sum, polynomial.sum, support,
finsupp.mem_supported', finsupp.total, finsupp.sum, algebra.smul_def, eval₂_zero, exists_prop,
linear_map.id_coe, eval₂_one, id.def, not_lt, finsupp.coe_lsum, linear_map.coe_smul_right,
finset.mem_range, alg_hom.coe_mk, finset.mem_coe],
simp_rw [@eq_comm _ y],
exact iff.rfl
end
lemma mem_span_pow {x y : S} {d : ℕ} (hd : d ≠ 0) :
y ∈ submodule.span R (set.range (λ (i : fin d), x ^ (i : ℕ))) ↔
∃ f : polynomial R, f.nat_degree < d ∧ y = aeval x f :=
begin
rw mem_span_pow',
split;
{ rintros ⟨f, h, hy⟩,
refine ⟨f, _, hy⟩,
by_cases hf : f = 0,
{ simp only [hf, nat_degree_zero, degree_zero] at h ⊢,
exact lt_of_le_of_ne (nat.zero_le d) hd.symm <|> exact with_bot.bot_lt_coe d },
simpa only [degree_eq_nat_degree hf, with_bot.coe_lt_coe] using h },
end
lemma dim_ne_zero [h : nontrivial S] (pb : power_basis R S) : pb.dim ≠ 0 :=
λ h, not_nonempty_iff.mpr (h.symm ▸ fin.is_empty : is_empty (fin pb.dim)) pb.basis.index_nonempty
lemma dim_pos [nontrivial S] (pb : power_basis R S) : 0 < pb.dim :=
nat.pos_of_ne_zero pb.dim_ne_zero
lemma exists_eq_aeval [nontrivial S] (pb : power_basis R S) (y : S) :
∃ f : polynomial R, f.nat_degree < pb.dim ∧ y = aeval pb.gen f :=
(mem_span_pow pb.dim_ne_zero).mp (by simpa using pb.basis.mem_span y)
lemma exists_eq_aeval' (pb : power_basis R S) (y : S) :
∃ f : polynomial R, y = aeval pb.gen f :=
begin
nontriviality S,
obtain ⟨f, _, hf⟩ := exists_eq_aeval pb y,
exact ⟨f, hf⟩
end
lemma alg_hom_ext {S' : Type*} [semiring S'] [algebra R S']
(pb : power_basis R S) ⦃f g : S →ₐ[R] S'⦄ (h : f pb.gen = g pb.gen) :
f = g :=
begin
ext x,
obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x,
rw [← polynomial.aeval_alg_hom_apply, ← polynomial.aeval_alg_hom_apply, h]
end
section minpoly
open_locale big_operators
variable [algebra A S]
/-- `pb.minpoly_gen` is a minimal polynomial for `pb.gen`.
If `A` is not a field, it might not necessarily be *the* minimal polynomial,
however `nat_degree_minpoly` shows its degree is indeed minimal.
-/
noncomputable def minpoly_gen (pb : power_basis A S) : polynomial A :=
X ^ pb.dim -
∑ (i : fin pb.dim), C (pb.basis.repr (pb.gen ^ pb.dim) i) * X ^ (i : ℕ)
@[simp]
lemma degree_minpoly_gen (pb : power_basis A S) :
degree (minpoly_gen pb) = pb.dim :=
begin
unfold minpoly_gen,
rw degree_sub_eq_left_of_degree_lt; rw degree_X_pow,
apply degree_sum_fin_lt
end
@[simp]
lemma nat_degree_minpoly_gen (pb : power_basis A S) :
nat_degree (minpoly_gen pb) = pb.dim :=
nat_degree_eq_of_degree_eq_some pb.degree_minpoly_gen
lemma minpoly_gen_monic (pb : power_basis A S) : monic (minpoly_gen pb) :=
begin
apply monic_sub_of_left (monic_pow (monic_X) _),
rw degree_X_pow,
exact degree_sum_fin_lt _
end
@[simp]
lemma aeval_minpoly_gen (pb : power_basis A S) : aeval pb.gen (minpoly_gen pb) = 0 :=
begin
simp_rw [minpoly_gen, alg_hom.map_sub, alg_hom.map_sum, alg_hom.map_mul, alg_hom.map_pow,
aeval_C, ← algebra.smul_def, aeval_X],
refine sub_eq_zero.mpr ((pb.basis.total_repr (pb.gen ^ pb.dim)).symm.trans _),
rw [finsupp.total_apply, finsupp.sum_fintype];
simp only [pb.coe_basis, zero_smul, eq_self_iff_true, implies_true_iff]
end
lemma is_integral_gen (pb : power_basis A S) : is_integral A pb.gen :=
⟨minpoly_gen pb, minpoly_gen_monic pb, aeval_minpoly_gen pb⟩
lemma dim_le_nat_degree_of_root (h : power_basis A S) {p : polynomial A}
(ne_zero : p ≠ 0) (root : aeval h.gen p = 0) :
h.dim ≤ p.nat_degree :=
begin
refine le_of_not_lt (λ hlt, ne_zero _),
let p_coeff : fin (h.dim) → A := λ i, p.coeff i,
suffices : ∀ i, p_coeff i = 0,
{ ext i,
by_cases hi : i < h.dim,
{ exact this ⟨i, hi⟩ },
exact coeff_eq_zero_of_nat_degree_lt (lt_of_lt_of_le hlt (le_of_not_gt hi)) },
intro i,
refine linear_independent_iff'.mp h.basis.linear_independent _ _ _ i (finset.mem_univ _),
rw aeval_eq_sum_range' hlt at root,
rw finset.sum_fin_eq_sum_range,
convert root,
ext i,
split_ifs with hi,
{ simp_rw [coe_basis, p_coeff, fin.coe_mk] },
{ rw [coeff_eq_zero_of_nat_degree_lt (lt_of_lt_of_le hlt (le_of_not_gt hi)),
zero_smul] }
end
lemma dim_le_degree_of_root (h : power_basis A S) {p : polynomial A}
(ne_zero : p ≠ 0) (root : aeval h.gen p = 0) :
↑h.dim ≤ p.degree :=
by { rw [degree_eq_nat_degree ne_zero, with_bot.coe_le_coe],
exact h.dim_le_nat_degree_of_root ne_zero root }
@[simp]
lemma nat_degree_minpoly (pb : power_basis A S) :
(minpoly A pb.gen).nat_degree = pb.dim :=
begin
refine le_antisymm _
(dim_le_nat_degree_of_root pb (minpoly.ne_zero pb.is_integral_gen) (minpoly.aeval _ _)),
rw ← nat_degree_minpoly_gen,
apply nat_degree_le_of_degree_le,
rw ← degree_eq_nat_degree (minpoly_gen_monic pb).ne_zero,
exact minpoly.min _ _ (minpoly_gen_monic pb) (aeval_minpoly_gen pb)
end
@[simp]
lemma minpoly_gen_eq [algebra K S] (pb : power_basis K S) :
pb.minpoly_gen = minpoly K pb.gen :=
minpoly.unique K pb.gen pb.minpoly_gen_monic pb.aeval_minpoly_gen (λ p p_monic p_root,
pb.degree_minpoly_gen.symm ▸ pb.dim_le_degree_of_root p_monic.ne_zero p_root)
end minpoly
section equiv
variables [algebra A S] {S' : Type*} [comm_ring S'] [algebra A S']
lemma nat_degree_lt_nat_degree {p q : polynomial R} (hp : p ≠ 0) (hpq : p.degree < q.degree) :
p.nat_degree < q.nat_degree :=
begin
by_cases hq : q = 0, { rw [hq, degree_zero] at hpq, have := not_lt_bot hpq, contradiction },
rwa [degree_eq_nat_degree hp, degree_eq_nat_degree hq, with_bot.coe_lt_coe] at hpq
end
lemma constr_pow_aeval (pb : power_basis A S) {y : S'}
(hy : aeval y (minpoly A pb.gen) = 0) (f : polynomial A) :
pb.basis.constr A (λ i, y ^ (i : ℕ)) (aeval pb.gen f) = aeval y f :=
begin
rw [← aeval_mod_by_monic_eq_self_of_root (minpoly.monic pb.is_integral_gen) (minpoly.aeval _ _),
← @aeval_mod_by_monic_eq_self_of_root _ _ _ _ _ f _ (minpoly.monic pb.is_integral_gen) y hy],
by_cases hf : f %ₘ minpoly A pb.gen = 0,
{ simp only [hf, alg_hom.map_zero, linear_map.map_zero] },
have : (f %ₘ minpoly A pb.gen).nat_degree < pb.dim,
{ rw ← pb.nat_degree_minpoly,
apply nat_degree_lt_nat_degree hf,
exact degree_mod_by_monic_lt _ (minpoly.monic pb.is_integral_gen)
(minpoly.ne_zero pb.is_integral_gen) },
rw [aeval_eq_sum_range' this, aeval_eq_sum_range' this, linear_map.map_sum],
refine finset.sum_congr rfl (λ i (hi : i ∈ finset.range pb.dim), _),
rw finset.mem_range at hi,
rw linear_map.map_smul,
congr,
rw [← fin.coe_mk hi, ← pb.basis_eq_pow ⟨i, hi⟩, basis.constr_basis]
end
lemma constr_pow_gen (pb : power_basis A S) {y : S'}
(hy : aeval y (minpoly A pb.gen) = 0) :
pb.basis.constr A (λ i, y ^ (i : ℕ)) pb.gen = y :=
by { convert pb.constr_pow_aeval hy X; rw aeval_X }
lemma constr_pow_algebra_map (pb : power_basis A S) {y : S'}
(hy : aeval y (minpoly A pb.gen) = 0) (x : A) :
pb.basis.constr A (λ i, y ^ (i : ℕ)) (algebra_map A S x) = algebra_map A S' x :=
by { convert pb.constr_pow_aeval hy (C x); rw aeval_C }
lemma constr_pow_mul (pb : power_basis A S) {y : S'}
(hy : aeval y (minpoly A pb.gen) = 0) (x x' : S) :
pb.basis.constr A (λ i, y ^ (i : ℕ)) (x * x') =
pb.basis.constr A (λ i, y ^ (i : ℕ)) x * pb.basis.constr A (λ i, y ^ (i : ℕ)) x' :=
begin
obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x,
obtain ⟨g, rfl⟩ := pb.exists_eq_aeval' x',
simp only [← aeval_mul, pb.constr_pow_aeval hy]
end
/-- `pb.lift y hy` is the algebra map sending `pb.gen` to `y`,
where `hy` states the higher powers of `y` are the same as the higher powers of `pb.gen`.
See `power_basis.lift_equiv` for a bundled equiv sending `⟨y, hy⟩` to the algebra map.
-/
noncomputable def lift (pb : power_basis A S) (y : S')
(hy : aeval y (minpoly A pb.gen) = 0) :
S →ₐ[A] S' :=
{ map_one' := by { convert pb.constr_pow_algebra_map hy 1 using 2; rw ring_hom.map_one },
map_zero' := by { convert pb.constr_pow_algebra_map hy 0 using 2; rw ring_hom.map_zero },
map_mul' := pb.constr_pow_mul hy,
commutes' := pb.constr_pow_algebra_map hy,
.. pb.basis.constr A (λ i, y ^ (i : ℕ)) }
@[simp] lemma lift_gen (pb : power_basis A S) (y : S')
(hy : aeval y (minpoly A pb.gen) = 0) :
pb.lift y hy pb.gen = y :=
pb.constr_pow_gen hy
@[simp] lemma lift_aeval (pb : power_basis A S) (y : S')
(hy : aeval y (minpoly A pb.gen) = 0) (f : polynomial A) :
pb.lift y hy (aeval pb.gen f) = aeval y f :=
pb.constr_pow_aeval hy f
/-- `pb.lift_equiv` states that roots of the minimal polynomial of `pb.gen` correspond to
maps sending `pb.gen` to that root.
This is the bundled equiv version of `power_basis.lift`.
If the codomain of the `alg_hom`s is an integral domain, then the roots form a multiset,
see `lift_equiv'` for the corresponding statement.
-/
@[simps]
noncomputable def lift_equiv (pb : power_basis A S) :
(S →ₐ[A] S') ≃ {y : S' // aeval y (minpoly A pb.gen) = 0} :=
{ to_fun := λ f, ⟨f pb.gen, by rw [aeval_alg_hom_apply, minpoly.aeval, f.map_zero]⟩,
inv_fun := λ y, pb.lift y y.2,
left_inv := λ f, pb.alg_hom_ext $ lift_gen _ _ _,
right_inv := λ y, subtype.ext $ lift_gen _ _ y.prop }
/-- `pb.lift_equiv'` states that elements of the root set of the minimal
polynomial of `pb.gen` correspond to maps sending `pb.gen` to that root. -/
@[simps {fully_applied := ff}]
noncomputable def lift_equiv' (pb : power_basis A S) :
(S →ₐ[A] B) ≃ {y : B // y ∈ ((minpoly A pb.gen).map (algebra_map A B)).roots} :=
pb.lift_equiv.trans ((equiv.refl _).subtype_equiv (λ x,
begin
rw [mem_roots, is_root.def, equiv.refl_apply, ← eval₂_eq_eval_map, ← aeval_def],
exact map_monic_ne_zero (minpoly.monic pb.is_integral_gen)
end))
/-- There are finitely many algebra homomorphisms `S →ₐ[A] B` if `S` is of the form `A[x]`
and `B` is an integral domain. -/
noncomputable def alg_hom.fintype (pb : power_basis A S) :
fintype (S →ₐ[A] B) :=
by letI := classical.dec_eq B; exact
fintype.of_equiv _ pb.lift_equiv'.symm
/-- `pb.equiv pb' h` is an equivalence of algebras with the same power basis. -/
noncomputable def equiv
(pb : power_basis A S) (pb' : power_basis A S')
(h : minpoly A pb.gen = minpoly A pb'.gen) :
S ≃ₐ[A] S' :=
alg_equiv.of_alg_hom
(pb.lift pb'.gen (h.symm ▸ minpoly.aeval A pb'.gen))
(pb'.lift pb.gen (h ▸ minpoly.aeval A pb.gen))
(by { ext x, obtain ⟨f, hf, rfl⟩ := pb'.exists_eq_aeval' x, simp })
(by { ext x, obtain ⟨f, hf, rfl⟩ := pb.exists_eq_aeval' x, simp })
@[simp]
lemma equiv_aeval
(pb : power_basis A S) (pb' : power_basis A S')
(h : minpoly A pb.gen = minpoly A pb'.gen)
(f : polynomial A) :
pb.equiv pb' h (aeval pb.gen f) = aeval pb'.gen f :=
pb.lift_aeval _ (h.symm ▸ minpoly.aeval A _) _
@[simp]
lemma equiv_gen
(pb : power_basis A S) (pb' : power_basis A S')
(h : minpoly A pb.gen = minpoly A pb'.gen) :
pb.equiv pb' h pb.gen = pb'.gen :=
pb.lift_gen _ (h.symm ▸ minpoly.aeval A _)
local attribute [irreducible] power_basis.lift
@[simp]
lemma equiv_symm
(pb : power_basis A S) (pb' : power_basis A S')
(h : minpoly A pb.gen = minpoly A pb'.gen) :
(pb.equiv pb' h).symm = pb'.equiv pb h.symm :=
rfl
end equiv
end power_basis
open power_basis
/-- Useful lemma to show `x` generates a power basis:
the powers of `x` less than the degree of `x`'s minimal polynomial are linearly independent. -/
lemma is_integral.linear_independent_pow [algebra K S] {x : S} (hx : is_integral K x) :
linear_independent K (λ (i : fin (minpoly K x).nat_degree), x ^ (i : ℕ)) :=
begin
rw linear_independent_iff,
intros p hp,
set f : polynomial K := p.sum (λ i, monomial i) with hf0,
have f_def : ∀ (i : fin _), f.coeff i = p i,
{ intro i,
simp only [f, finsupp.sum, coeff_monomial, finset_sum_coeff],
rw [finset.sum_eq_single, if_pos rfl],
{ intros b _ hb,
rw if_neg (mt (λ h, _) hb),
exact fin.coe_injective h },
{ intro hi,
split_ifs; { exact finsupp.not_mem_support_iff.mp hi } } },
have f_def' : ∀ i, f.coeff i = if hi : i < _ then p ⟨i, hi⟩ else 0,
{ intro i,
split_ifs with hi,
{ exact f_def ⟨i, hi⟩ },
simp only [f, finsupp.sum, coeff_monomial, finset_sum_coeff],
apply finset.sum_eq_zero,
rintro ⟨j, hj⟩ -,
apply if_neg (mt _ hi),
rintro rfl,
exact hj },
suffices : f = 0,
{ ext i, rw [← f_def, this, coeff_zero, finsupp.zero_apply] },
contrapose hp with hf,
intro h,
have : (minpoly K x).degree ≤ f.degree,
{ apply minpoly.degree_le_of_ne_zero K x hf,
convert h,
simp_rw [finsupp.total_apply, aeval_def, hf0, finsupp.sum, eval₂_finset_sum],
apply finset.sum_congr rfl,
rintro i -,
simp only [algebra.smul_def, eval₂_monomial] },
have : ¬ (minpoly K x).degree ≤ f.degree,
{ apply not_le_of_lt,
rw [degree_eq_nat_degree (minpoly.ne_zero hx), degree_lt_iff_coeff_zero],
intros i hi,
rw [f_def' i, dif_neg],
exact hi.not_lt },
contradiction
end
lemma is_integral.mem_span_pow [nontrivial R] {x y : S} (hx : is_integral R x)
(hy : ∃ f : polynomial R, y = aeval x f) :
y ∈ submodule.span R (set.range (λ (i : fin (minpoly R x).nat_degree),
x ^ (i : ℕ))) :=
begin
obtain ⟨f, rfl⟩ := hy,
apply mem_span_pow'.mpr _,
have := minpoly.monic hx,
refine ⟨f.mod_by_monic (minpoly R x),
lt_of_lt_of_le (degree_mod_by_monic_lt _ this (ne_zero_of_monic this)) degree_le_nat_degree,
_⟩,
conv_lhs { rw ← mod_by_monic_add_div f this },
simp only [add_zero, zero_mul, minpoly.aeval, aeval_add, alg_hom.map_mul]
end
namespace power_basis
section map
variables {S' : Type*} [comm_ring S'] [algebra R S']
/-- `power_basis.map pb (e : S ≃ₐ[R] S')` is the power basis for `S'` generated by `e pb.gen`. -/
@[simps]
noncomputable def map (pb : power_basis R S) (e : S ≃ₐ[R] S') : power_basis R S' :=
{ dim := pb.dim,
basis := pb.basis.map e.to_linear_equiv,
gen := e pb.gen,
basis_eq_pow :=
λ i, by rw [basis.map_apply, pb.basis_eq_pow, e.to_linear_equiv_apply, e.map_pow] }
variables [algebra A S] [algebra A S']
@[simp]
lemma minpoly_gen_map (pb : power_basis A S) (e : S ≃ₐ[A] S') :
(pb.map e).minpoly_gen = pb.minpoly_gen :=
by { dsimp only [minpoly_gen, map_dim], -- Turn `fin (pb.map e).dim` into `fin pb.dim`
simp only [linear_equiv.trans_apply, map_basis, basis.map_repr,
map_gen, alg_equiv.to_linear_equiv_apply, e.to_linear_equiv_symm, alg_equiv.map_pow,
alg_equiv.symm_apply_apply, sub_right_inj] }
@[simp]
lemma equiv_map (pb : power_basis A S) (e : S ≃ₐ[A] S')
(h : minpoly A pb.gen = minpoly A (pb.map e).gen) :
pb.equiv (pb.map e) h = e :=
by { ext x, obtain ⟨f, rfl⟩ := pb.exists_eq_aeval' x, simp [aeval_alg_equiv] }
end map
end power_basis
|
c4e4ab08d59d2724b36fc476355a755997f441e4 | 19cc34575500ee2e3d4586c15544632aa07a8e66 | /src/algebra/pointwise.lean | 37bc8594eb116b3b62442579f3220acd398a8d9d | [
"Apache-2.0"
] | permissive | LibertasSpZ/mathlib | b9fcd46625eb940611adb5e719a4b554138dade6 | 33f7870a49d7cc06d2f3036e22543e6ec5046e68 | refs/heads/master | 1,672,066,539,347 | 1,602,429,158,000 | 1,602,429,158,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 15,389 | 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.finite
/-!
# Pointwise addition, multiplication, and scalar multiplication of sets.
This file defines pointwise algebraic operations on sets.
* For a type `α` with multiplication, multiplication is defined on `set α` by taking
`s * t` to be the set of all `x * y` where `x ∈ s` and `y ∈ t`. Similarly for addition.
* For `α` a semigroup, `set α` is a semigroup.
* If `α` is a (commutative) monoid, we define an alias `set_semiring α` for `set α`, which then
becomes a (commutative) semiring with union as addition and pointwise multiplication as
multiplication.
* For a type `β` with scalar multiplication by another type `α`, this
file defines a scalar multiplication of `set β` by `set α` and a separate scalar
multiplication of `set β` by `α`.
* We also define pointwise multiplication on `finset`.
Appropriate definitions and results are also transported to the additive theory via `to_additive`.
## Implementation notes
* The following expressions are considered in simp-normal form in a group:
`(λ h, h * g) ⁻¹' s`, `(λ h, g * h) ⁻¹' s`, `(λ h, h * g⁻¹) ⁻¹' s`, `(λ h, g⁻¹ * h) ⁻¹' s`,
`s * t`, `s⁻¹`, `(1 : set _)` (and similarly for additive variants).
Expressions equal to one of these will be simplified.
## Tags
set multiplication, set addition, pointwise addition, pointwise multiplication
-/
namespace set
open function
variables {α : Type*} {β : Type*} {s s₁ s₂ t t₁ t₂ u : set α} {a b : α} {x y : β}
/-! ### Properties about 1 -/
@[to_additive]
instance [has_one α] : has_one (set α) := ⟨{1}⟩
@[simp, to_additive]
lemma singleton_one [has_one α] : ({1} : set α) = 1 := rfl
@[simp, to_additive]
lemma mem_one [has_one α] : a ∈ (1 : set α) ↔ a = 1 := iff.rfl
@[to_additive]
lemma one_mem_one [has_one α] : (1 : α) ∈ (1 : set α) := eq.refl _
@[simp, to_additive]
theorem one_subset [has_one α] : 1 ⊆ s ↔ (1 : α) ∈ s := singleton_subset_iff
@[to_additive]
theorem one_nonempty [has_one α] : (1 : set α).nonempty := ⟨1, rfl⟩
@[simp, to_additive]
theorem image_one [has_one α] {f : α → β} : f '' 1 = {f 1} := image_singleton
/-! ### Properties about multiplication -/
@[to_additive]
instance [has_mul α] : has_mul (set α) := ⟨image2 has_mul.mul⟩
@[simp, to_additive]
lemma image2_mul [has_mul α] : image2 has_mul.mul s t = s * t := rfl
@[to_additive]
lemma mem_mul [has_mul α] : a ∈ s * t ↔ ∃ x y, x ∈ s ∧ y ∈ t ∧ x * y = a := iff.rfl
@[to_additive]
lemma mul_mem_mul [has_mul α] (ha : a ∈ s) (hb : b ∈ t) : a * b ∈ s * t := mem_image2_of_mem ha hb
@[to_additive add_image_prod]
lemma image_mul_prod [has_mul α] : (λ x : α × α, x.fst * x.snd) '' s.prod t = s * t := image_prod _
@[simp, to_additive]
lemma image_mul_left [group α] : (λ b, a * b) '' t = (λ b, a⁻¹ * b) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[simp, to_additive]
lemma image_mul_right [group α] : (λ a, a * b) '' t = (λ a, a * b⁻¹) ⁻¹' t :=
by { rw image_eq_preimage_of_inverse; intro c; simp }
@[to_additive]
lemma image_mul_left' [group α] : (λ b, a⁻¹ * b) '' t = (λ b, a * b) ⁻¹' t := by simp
@[to_additive]
lemma image_mul_right' [group α] : (λ a, a * b⁻¹) '' t = (λ a, a * b) ⁻¹' t := by simp
@[simp, to_additive]
lemma preimage_mul_left_one [group α] : (λ b, a * b) ⁻¹' 1 = {a⁻¹} :=
by rw [← image_mul_left', image_one, mul_one]
@[simp, to_additive]
lemma preimage_mul_right_one [group α] : (λ a, a * b) ⁻¹' 1 = {b⁻¹} :=
by rw [← image_mul_right', image_one, one_mul]
@[to_additive]
lemma preimage_mul_left_one' [group α] : (λ b, a⁻¹ * b) ⁻¹' 1 = {a} := by simp
@[to_additive]
lemma preimage_mul_right_one' [group α] : (λ a, a * b⁻¹) ⁻¹' 1 = {b} := by simp
@[simp, to_additive]
lemma mul_singleton [has_mul α] : s * {b} = (λ a, a * b) '' s := image2_singleton_right
@[simp, to_additive]
lemma singleton_mul [has_mul α] : {a} * t = (λ b, a * b) '' t := image2_singleton_left
@[simp, to_additive]
lemma singleton_mul_singleton [has_mul α] : ({a} : set α) * {b} = {a * b} := image2_singleton
@[to_additive set.add_semigroup]
instance [semigroup α] : semigroup (set α) :=
{ mul_assoc :=
by { intros, simp only [← image2_mul, image2_image2_left, image2_image2_right, mul_assoc] },
..set.has_mul }
@[to_additive set.add_monoid]
instance [monoid α] : monoid (set α) :=
{ mul_one := λ s, by { simp only [← singleton_one, mul_singleton, mul_one, image_id'] },
one_mul := λ s, by { simp only [← singleton_one, singleton_mul, one_mul, image_id'] },
..set.semigroup,
..set.has_one }
@[to_additive]
protected lemma mul_comm [comm_semigroup α] : s * t = t * s :=
by simp only [← image2_mul, image2_swap _ s, mul_comm]
@[to_additive set.add_comm_monoid]
instance [comm_monoid α] : comm_monoid (set α) :=
{ mul_comm := λ _ _, set.mul_comm, ..set.monoid }
@[to_additive]
lemma singleton.is_mul_hom [has_mul α] : is_mul_hom (singleton : α → set α) :=
{ map_mul := λ a b, singleton_mul_singleton.symm }
@[simp, to_additive]
lemma empty_mul [has_mul α] : ∅ * s = ∅ := image2_empty_left
@[simp, to_additive]
lemma mul_empty [has_mul α] : s * ∅ = ∅ := image2_empty_right
@[to_additive]
lemma mul_subset_mul [has_mul α] (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ * s₂ ⊆ t₁ * t₂ :=
image2_subset h₁ h₂
@[to_additive]
lemma union_mul [has_mul α] : (s ∪ t) * u = (s * u) ∪ (t * u) := image2_union_left
@[to_additive]
lemma mul_union [has_mul α] : s * (t ∪ u) = (s * t) ∪ (s * u) := image2_union_right
@[to_additive]
lemma Union_mul_left_image [has_mul α] : (⋃ a ∈ s, (λ x, a * x) '' t) = s * t :=
Union_image_left _
@[to_additive]
lemma Union_mul_right_image [has_mul α] : (⋃ a ∈ t, (λ x, x * a) '' s) = s * t :=
Union_image_right _
@[simp, to_additive]
lemma univ_mul_univ [monoid α] : (univ : set α) * univ = univ :=
begin
have : ∀x, ∃a b : α, a * b = x := λx, ⟨x, ⟨1, mul_one x⟩⟩,
simpa only [mem_mul, eq_univ_iff_forall, mem_univ, true_and]
end
/-- `singleton` is a monoid hom. -/
@[to_additive singleton_add_hom "singleton is an add monoid hom"]
def singleton_hom [monoid α] : α →* set α :=
{ to_fun := singleton, map_one' := rfl, map_mul' := λ a b, singleton_mul_singleton.symm }
@[to_additive]
lemma nonempty.mul [has_mul α] : s.nonempty → t.nonempty → (s * t).nonempty := nonempty.image2
@[to_additive]
lemma finite.mul [has_mul α] (hs : finite s) (ht : finite t) : finite (s * t) :=
hs.image2 _ ht
/-- multiplication preserves finiteness -/
@[to_additive "addition preserves finiteness"]
def fintype_mul [has_mul α] [decidable_eq α] (s t : set α) [hs : fintype s] [ht : fintype t] :
fintype (s * t : set α) :=
set.fintype_image2 _ s t
/-! ### Properties about inversion -/
@[to_additive set.has_neg'] -- todo: remove prime once name becomes available
instance [has_inv α] : has_inv (set α) :=
⟨preimage has_inv.inv⟩
@[simp, to_additive]
lemma mem_inv [has_inv α] : a ∈ s⁻¹ ↔ a⁻¹ ∈ s := iff.rfl
@[to_additive]
lemma inv_mem_inv [group α] : a⁻¹ ∈ s⁻¹ ↔ a ∈ s :=
by simp only [mem_inv, inv_inv]
@[simp, to_additive]
lemma inv_preimage [has_inv α] : has_inv.inv ⁻¹' s = s⁻¹ := rfl
@[simp, to_additive]
lemma image_inv [group α] : has_inv.inv '' s = s⁻¹ :=
by { simp only [← inv_preimage], rw [image_eq_preimage_of_inverse]; intro; simp only [inv_inv] }
@[simp, to_additive]
lemma inter_inv [has_inv α] : (s ∩ t)⁻¹ = s⁻¹ ∩ t⁻¹ := preimage_inter
@[simp, to_additive]
lemma union_inv [has_inv α] : (s ∪ t)⁻¹ = s⁻¹ ∪ t⁻¹ := preimage_union
@[simp, to_additive]
lemma compl_inv [has_inv α] : (sᶜ)⁻¹ = (s⁻¹)ᶜ := preimage_compl
@[simp, to_additive]
protected lemma inv_inv [group α] : s⁻¹⁻¹ = s :=
by { simp only [← inv_preimage, preimage_preimage, inv_inv, preimage_id'] }
@[simp, to_additive]
protected lemma univ_inv [group α] : (univ : set α)⁻¹ = univ := preimage_univ
@[simp, to_additive]
lemma inv_subset_inv [group α] {s t : set α} : s⁻¹ ⊆ t⁻¹ ↔ s ⊆ t :=
(equiv.inv α).surjective.preimage_subset_preimage_iff
@[to_additive] lemma inv_subset [group α] {s t : set α} : s⁻¹ ⊆ t ↔ s ⊆ t⁻¹ :=
by { rw [← inv_subset_inv, set.inv_inv] }
/-! ### Properties about scalar multiplication -/
/-- Scaling a set: multiplying every element by a scalar. -/
instance has_scalar_set [has_scalar α β] : has_scalar α (set β) :=
⟨λ a, image (has_scalar.smul a)⟩
@[simp]
lemma image_smul [has_scalar α β] {t : set β} : (λ x, a • x) '' t = a • t := rfl
lemma mem_smul_set [has_scalar α β] {t : set β} : x ∈ a • t ↔ ∃ y, y ∈ t ∧ a • y = x := iff.rfl
lemma smul_mem_smul_set [has_scalar α β] {t : set β} (hy : y ∈ t) : a • y ∈ a • t :=
⟨y, hy, rfl⟩
lemma smul_set_union [has_scalar α β] {s t : set β} : a • (s ∪ t) = a • s ∪ a • t :=
by simp only [← image_smul, image_union]
@[simp]
lemma smul_set_empty [has_scalar α β] (a : α) : a • (∅ : set β) = ∅ :=
by rw [← image_smul, image_empty]
lemma smul_set_mono [has_scalar α β] {s t : set β} (h : s ⊆ t) : a • s ⊆ a • t :=
by { simp only [← image_smul, image_subset, h] }
/-- Pointwise scalar multiplication by a set of scalars. -/
instance [has_scalar α β] : has_scalar (set α) (set β) := ⟨image2 has_scalar.smul⟩
@[simp]
lemma image2_smul [has_scalar α β] {t : set β} : image2 has_scalar.smul s t = s • t := rfl
lemma mem_smul [has_scalar α β] {t : set β} : x ∈ s • t ↔ ∃ a y, a ∈ s ∧ y ∈ t ∧ a • y = x :=
iff.rfl
lemma image_smul_prod [has_scalar α β] {t : set β} :
(λ x : α × β, x.fst • x.snd) '' s.prod t = s • t :=
image_prod _
theorem range_smul_range [has_scalar α β] {ι κ : Type*} (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⟩⟩
lemma singleton_smul [has_scalar α β] {t : set β} : ({a} : set α) • t = a • t :=
image2_singleton_left
section monoid
/-! ### `set α` as a `(∪,*)`-semiring -/
/-- An alias for `set α`, which has a semiring structure given by `∪` as "addition" and pointwise
multiplication `*` as "multiplication". -/
@[derive inhabited] def set_semiring (α : Type*) : Type* := set α
/-- The identitiy function `set α → set_semiring α`. -/
protected def up (s : set α) : set_semiring α := s
/-- The identitiy function `set_semiring α → set α`. -/
protected def set_semiring.down (s : set_semiring α) : set α := s
@[simp] protected lemma down_up {s : set α} : s.up.down = s := rfl
@[simp] protected lemma up_down {s : set_semiring α} : s.down.up = s := rfl
instance set_semiring.semiring [monoid α] : semiring (set_semiring α) :=
{ add := λ s t, (s ∪ t : set α),
zero := (∅ : set α),
add_assoc := union_assoc,
zero_add := empty_union,
add_zero := union_empty,
add_comm := union_comm,
zero_mul := λ s, empty_mul,
mul_zero := λ s, mul_empty,
left_distrib := λ _ _ _, mul_union,
right_distrib := λ _ _ _, union_mul,
..set.monoid }
instance set_semiring.comm_semiring [comm_monoid α] : comm_semiring (set_semiring α) :=
{ ..set.comm_monoid, ..set_semiring.semiring }
/-- A multiplicative action of a monoid on a type β gives also a
multiplicative action on the subsets of β. -/
instance 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, image_eta, one_smul, image_id'] },
..set.has_scalar_set }
section is_mul_hom
open is_mul_hom
variables [has_mul α] [has_mul β] (m : α → β) [is_mul_hom m]
@[to_additive]
lemma image_mul : m '' (s * t) = m '' s * m '' t :=
by { simp only [← image2_mul, image_image2, image2_image_left, image2_image_right, map_mul m] }
@[to_additive]
lemma preimage_mul_preimage_subset {s t : set β} : m ⁻¹' s * m ⁻¹' t ⊆ m ⁻¹' (s * t) :=
by { rintros _ ⟨_, _, _, _, rfl⟩, exact ⟨_, _, ‹_›, ‹_›, (map_mul _ _ _).symm ⟩ }
end is_mul_hom
/-- The image of a set under function is a ring homomorphism
with respect to the pointwise operations on sets. -/
def image_hom [monoid α] [monoid β] (f : α →* β) : set_semiring α →+* set_semiring β :=
{ to_fun := image f,
map_zero' := image_empty _,
map_one' := by simp only [← singleton_one, image_singleton, is_monoid_hom.map_one f],
map_add' := image_union _,
map_mul' := λ _ _, image_mul _ }
end monoid
end set
section
open set
variables {α : Type*} {β : Type*}
/-- A nonempty set in a semimodule is scaled by zero to the singleton
containing 0 in the semimodule. -/
lemma zero_smul_set [semiring α] [add_comm_monoid β] [semimodule α β] {s : set β} (h : s.nonempty) :
(0 : α) • s = (0 : set β) :=
by simp only [← image_smul, image_eta, zero_smul, h.image_const, singleton_zero]
lemma mem_inv_smul_set_iff [field α] [mul_action α β] {a : α} (ha : a ≠ 0) (A : set β) (x : β) :
x ∈ a⁻¹ • A ↔ a • x ∈ A :=
by simp only [← image_smul, mem_image, inv_smul_eq_iff ha, exists_eq_right]
lemma mem_smul_set_iff_inv_smul_mem [field α] [mul_action α β] {a : α} (ha : a ≠ 0) (A : set β)
(x : β) : x ∈ a • A ↔ a⁻¹ • x ∈ A :=
by rw [← mem_inv_smul_set_iff $ inv_ne_zero ha, inv_inv']
end
namespace finset
variables {α : Type*} [decidable_eq α]
/-- The pointwise product of two finite sets `s` and `t`:
`st = s ⬝ t = s * t = { x * y | x ∈ s, y ∈ t }`. -/
@[to_additive "The pointwise sum of two finite sets `s` and `t`:
`s + t = { x + y | x ∈ s, y ∈ t }`."]
instance [has_mul α] : has_mul (finset α) :=
⟨λ s t, (s.product t).image (λ p : α × α, p.1 * p.2)⟩
@[to_additive]
lemma mul_def [has_mul α] {s t : finset α} :
s * t = (s.product t).image (λ p : α × α, p.1 * p.2) := rfl
@[to_additive]
lemma mem_mul [has_mul α] {s t : finset α} {x : α} :
x ∈ s * t ↔ ∃ y z, y ∈ s ∧ z ∈ t ∧ y * z = x :=
by { simp only [finset.mul_def, and.assoc, mem_image, exists_prop, prod.exists, mem_product] }
@[simp, norm_cast, to_additive]
lemma coe_mul [has_mul α] {s t : finset α} : (↑(s * t) : set α) = ↑s * ↑t :=
by { ext, simp only [mem_mul, set.mem_mul, mem_coe] }
@[to_additive]
lemma mul_mem_mul [has_mul α] {s t : finset α} {x y : α} (hx : x ∈ s) (hy : y ∈ t) :
x * y ∈ s * t :=
by { simp only [finset.mem_mul], exact ⟨x, y, hx, hy, rfl⟩ }
lemma add_card_le [has_add α] {s t : finset α} : (s + t).card ≤ s.card * t.card :=
by { convert finset.card_image_le, rw [finset.card_product, mul_comm] }
@[to_additive]
lemma mul_card_le [has_mul α] {s t : finset α} : (s * t).card ≤ s.card * t.card :=
by { convert finset.card_image_le, rw [finset.card_product, mul_comm] }
end finset
|
9d4d327708e388b5da6f1e274c3d21e1eb0d559d | abd85493667895c57a7507870867b28124b3998f | /src/measure_theory/borel_space.lean | e596c31105fc21ce48479372dd7238ab91dd7d3f | [
"Apache-2.0"
] | permissive | pechersky/mathlib | d56eef16bddb0bfc8bc552b05b7270aff5944393 | f1df14c2214ee114c9738e733efd5de174deb95d | refs/heads/master | 1,666,714,392,571 | 1,591,747,567,000 | 1,591,747,567,000 | 270,557,274 | 0 | 0 | Apache-2.0 | 1,591,597,975,000 | 1,591,597,974,000 | null | UTF-8 | Lean | false | false | 29,406 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import measure_theory.measurable_space
import topology.instances.ennreal
import analysis.normed_space.basic
/-!
# Borel (measurable) space
## Main definitions
* `borel α` : the least `σ`-algebra that contains all open sets;
* `class borel_space` : a space with `topological_space` and `measurable_space` structures
such that `‹measurable_space α› = borel α`;
* `class opens_measurable_space` : a space with `topological_space` and `measurable_space`
structures such that all open sets are measurable; equivalently, `borel α ≤ ‹measurable_space α›`.
* `borel_space` instances on `empty`, `unit`, `bool`, `nat`, `int`, `rat`;
* `measurable` and `borel_space` instances on `ℝ`, `ℝ≥0`, `ennreal`.
## Main statements
* `is_open.is_measurable`, `is_closed.is_measurable`: open and closed sets are measurable;
* `continuous.measurable` : a continuous function is measurable;
* `continuous.measurable2` : if `f : α → β` and `g : α → γ` are measurable and `op : β × γ → δ`
is continuous, then `λ x, op (f x, g y)` is measurable;
* `measurable.add` etc : dot notation for arithmetic operations on `measurable` predicates,
and similarly for `dist` and `edist`;
* `measurable.ennreal*` : special cases for arithmetic operations on `ennreal`s.
-/
noncomputable theory
open classical set
open_locale classical
universes u v w x y
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} {ι : Sort y} {s t u : set α}
open measurable_space topological_space
/-- `measurable_space` structure generated by `topological_space`. -/
def borel (α : Type u) [topological_space α] : measurable_space α :=
generate_from {s : set α | is_open s}
lemma borel_eq_top_of_discrete [topological_space α] [discrete_topology α] :
borel α = ⊤ :=
top_le_iff.1 $ λ s hs, generate_measurable.basic s (is_open_discrete s)
lemma borel_eq_top_of_encodable [topological_space α] [t1_space α] [encodable α] :
borel α = ⊤ :=
begin
refine (top_le_iff.1 $ λ s hs, bUnion_of_singleton s ▸ _),
apply is_measurable.bUnion s.countable_encodable,
intros x hx,
apply is_measurable.of_compl,
apply generate_measurable.basic,
exact is_closed_singleton
end
lemma borel_eq_generate_from_of_subbasis {s : set (set α)}
[t : topological_space α] [second_countable_topology α] (hs : t = generate_from s) :
borel α = generate_from s :=
le_antisymm
(generate_from_le $ assume u (hu : t.is_open u),
begin
rw [hs] at hu,
induction hu,
case generate_open.basic : u hu
{ exact generate_measurable.basic u hu },
case generate_open.univ
{ exact @is_measurable.univ α (generate_from s) },
case generate_open.inter : s₁ s₂ _ _ hs₁ hs₂
{ exact @is_measurable.inter α (generate_from s) _ _ hs₁ hs₂ },
case generate_open.sUnion : f hf ih {
rcases is_open_sUnion_countable f (by rwa hs) with ⟨v, hv, vf, vu⟩,
rw ← vu,
exact @is_measurable.sUnion α (generate_from s) _ hv
(λ x xv, ih _ (vf xv)) }
end)
(generate_from_le $ assume u hu, generate_measurable.basic _ $
show t.is_open u, by rw [hs]; exact generate_open.basic _ hu)
lemma borel_eq_generate_Iio (α)
[topological_space α] [second_countable_topology α]
[linear_order α] [order_topology α] :
borel α = generate_from (range Iio) :=
begin
refine le_antisymm _ (generate_from_le _),
{ rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals α _ _ _),
have H : ∀ a:α, is_measurable (measurable_space.generate_from (range Iio)) (Iio a) :=
λ a, generate_measurable.basic _ ⟨_, rfl⟩,
refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩; [skip, apply H],
by_cases h : ∃ a', ∀ b, a < b ↔ a' ≤ b,
{ rcases h with ⟨a', ha'⟩,
rw (_ : Ioi a = -Iio a'), {exact (H _).compl _},
simp [set.ext_iff, ha'] },
{ rcases is_open_Union_countable
(λ a' : {a' : α // a < a'}, {b | a'.1 < b})
(λ a', is_open_lt' _) with ⟨v, ⟨hv⟩, vu⟩,
simp [set.ext_iff] at vu,
have : Ioi a = ⋃ x : v, -Iio x.1.1,
{ simp [set.ext_iff],
refine λ x, ⟨λ ax, _, λ ⟨a', ⟨h, av⟩, ax⟩, lt_of_lt_of_le h ax⟩,
rcases (vu x).2 _ with ⟨a', h₁, h₂⟩,
{ exact ⟨a', h₁, le_of_lt h₂⟩ },
refine not_imp_comm.1 (λ h, _) h,
exact ⟨x, λ b, ⟨λ ab, le_of_not_lt (λ h', h ⟨b, ab, h'⟩),
lt_of_lt_of_le ax⟩⟩ },
rw this, resetI,
apply is_measurable.Union,
exact λ _, (H _).compl _ } },
{ simp, rintro _ a rfl,
exact generate_measurable.basic _ is_open_Iio }
end
lemma borel_eq_generate_Ioi (α)
[topological_space α] [second_countable_topology α]
[linear_order α] [order_topology α] :
borel α = generate_from (range Ioi) :=
begin
refine le_antisymm _ (generate_from_le _),
{ rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals α _ _ _),
have H : ∀ a:α, is_measurable (measurable_space.generate_from (range (λ a, {x | a < x})))
{x | a < x} := λ a, generate_measurable.basic _ ⟨_, rfl⟩,
refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩, {apply H},
by_cases h : ∃ a', ∀ b, b < a ↔ b ≤ a',
{ rcases h with ⟨a', ha'⟩,
rw (_ : Iio a = -Ioi a'), {exact (H _).compl _},
simp [set.ext_iff, ha'] },
{ rcases is_open_Union_countable
(λ a' : {a' : α // a' < a}, {b | b < a'.1})
(λ a', is_open_gt' _) with ⟨v, ⟨hv⟩, vu⟩,
simp [set.ext_iff] at vu,
have : Iio a = ⋃ x : v, -Ioi x.1.1,
{ simp [set.ext_iff],
refine λ x, ⟨λ ax, _, λ ⟨a', ⟨h, av⟩, ax⟩, lt_of_le_of_lt ax h⟩,
rcases (vu x).2 _ with ⟨a', h₁, h₂⟩,
{ exact ⟨a', h₁, le_of_lt h₂⟩ },
refine not_imp_comm.1 (λ h, _) h,
exact ⟨x, λ b, ⟨λ ab, le_of_not_lt (λ h', h ⟨b, ab, h'⟩),
λ h, lt_of_le_of_lt h ax⟩⟩ },
rw this, resetI,
apply is_measurable.Union,
exact λ _, (H _).compl _ } },
{ simp, rintro _ a rfl,
exact generate_measurable.basic _ (is_open_lt' _) }
end
lemma borel_comap {f : α → β} {t : topological_space β} :
@borel α (t.induced f) = (@borel β t).comap f :=
comap_generate_from.symm
lemma continuous.borel_measurable [topological_space α] [topological_space β]
{f : α → β} (hf : continuous f) :
@measurable α β (borel α) (borel β) f :=
generate_from_le $ λ s hs, generate_measurable.basic (f ⁻¹' s) (hf s hs)
/-- A space with `measurable_space` and `topological_space` structures such that
all open sets are measurable. -/
class opens_measurable_space (α : Type*) [topological_space α] [h : measurable_space α] : Prop :=
(borel_le : borel α ≤ h)
/-- A space with `measurable_space` and `topological_space` structures such that
the `σ`-algebra of measurable sets is exactly the `σ`-algebra generated by open sets. -/
class borel_space (α : Type*) [topological_space α] [measurable_space α] : Prop :=
(measurable_eq : ‹measurable_space α› = borel α)
/-- In a `borel_space` all open sets are measurable. -/
@[priority 100]
instance borel_space.opens_measurable {α : Type*} [topological_space α] [measurable_space α]
[borel_space α] : opens_measurable_space α :=
⟨ge_of_eq $ borel_space.measurable_eq⟩
instance subtype.borel_space {α : Type*} [topological_space α] [measurable_space α]
[hα : borel_space α] (s : set α) :
borel_space s :=
⟨by { rw [hα.1, subtype.measurable_space, ← borel_comap], refl }⟩
instance subtype.opens_measurable_space {α : Type*} [topological_space α] [measurable_space α]
[h : opens_measurable_space α] (s : set α) :
opens_measurable_space s :=
⟨by { rw [borel_comap], exact comap_mono h.1 }⟩
section
variables [topological_space α] [measurable_space α] [opens_measurable_space α]
[topological_space β] [measurable_space β] [opens_measurable_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[measurable_space δ]
lemma is_open.is_measurable (h : is_open s) : is_measurable s :=
opens_measurable_space.borel_le _ $ generate_measurable.basic _ h
lemma is_measurable_interior : is_measurable (interior s) := is_open_interior.is_measurable
lemma is_closed.is_measurable (h : is_closed s) : is_measurable s :=
is_measurable.compl_iff.1 $ h.is_measurable
lemma is_measurable_singleton [t1_space α] {x : α} : is_measurable ({x} : set α) :=
is_closed_singleton.is_measurable
lemma is_measurable_eq [t1_space α] {a : α} : is_measurable {x | x = a} :=
is_measurable_singleton
lemma is_measurable_closure : is_measurable (closure s) :=
is_closed_closure.is_measurable
section order_closed_topology
variables [preorder α] [order_closed_topology α] {a b : α}
lemma is_measurable_Ici : is_measurable (Ici a) := is_closed_Ici.is_measurable
lemma is_measurable_Iic : is_measurable (Iic a) := is_closed_Iic.is_measurable
lemma is_measurable_Icc : is_measurable (Icc a b) := is_closed_Icc.is_measurable
end order_closed_topology
section order_closed_topology
variables [linear_order α] [order_closed_topology α] {a b : α}
lemma is_measurable_Iio : is_measurable (Iio a) := is_open_Iio.is_measurable
lemma is_measurable_Ioi : is_measurable (Ioi a) := is_open_Ioi.is_measurable
lemma is_measurable_Ioo : is_measurable (Ioo a b) := is_open_Ioo.is_measurable
lemma is_measurable_Ioc : is_measurable (Ioc a b) := is_measurable_Ioi.inter is_measurable_Iic
lemma is_measurable_Ico : is_measurable (Ico a b) := is_measurable_Ici.inter is_measurable_Iio
end order_closed_topology
lemma is_measurable_interval [decidable_linear_order α] [order_closed_topology α] {a b : α} :
is_measurable (interval a b) :=
is_measurable_Icc
instance prod.opens_measurable_space [second_countable_topology α] [second_countable_topology β] :
opens_measurable_space (α × β) :=
begin
refine ⟨_⟩,
rcases is_open_generated_countable_inter α with ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩,
rcases is_open_generated_countable_inter β with ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩,
have : prod.topological_space = generate_from {g | ∃u∈a, ∃v∈b, g = set.prod u v},
{ rw [ha₅, hb₅], exact prod_generate_from_generate_from_eq ha₄ hb₄ },
rw [borel_eq_generate_from_of_subbasis this],
apply generate_from_le,
rintros _ ⟨u, hu, v, hv, rfl⟩,
have hu : is_open u, by { rw [ha₅], exact generate_open.basic _ hu },
have hv : is_open v, by { rw [hb₅], exact generate_open.basic _ hv },
exact hu.is_measurable.prod hv.is_measurable
end
/-- A continuous function from an `opens_measurable_space` to a `borel_space`
is measurable. -/
lemma continuous.measurable {f : α → γ} (hf : continuous f) :
measurable f :=
hf.borel_measurable.mono opens_measurable_space.borel_le
(le_of_eq $ borel_space.measurable_eq)
/-- A homeomorphism between two Borel spaces is a measurable equivalence.-/
def homeomorph.to_measurable_equiv {α : Type*} {β : Type*} [topological_space α]
[measurable_space α] [borel_space α] [topological_space β] [measurable_space β]
[borel_space β] (h : α ≃ₜ β) :
measurable_equiv α β :=
{ measurable_to_fun := h.continuous_to_fun.measurable,
measurable_inv_fun := h.continuous_inv_fun.measurable,
.. h }
lemma measurable_of_continuous_on_compl_singleton [t1_space α] {f : α → γ} (a : α)
(hf : continuous_on f {x | x ≠ a}) :
measurable f :=
measurable_of_measurable_on_compl_singleton a is_measurable_singleton
(continuous_on_iff_continuous_restrict.1 hf).measurable
lemma continuous.measurable2 [second_countable_topology α] [second_countable_topology β]
{f : δ → α} {g : δ → β} {c : α → β → γ}
(h : continuous (λp:α×β, c p.1 p.2)) (hf : measurable f) (hg : measurable g) :
measurable (λa, c (f a) (g a)) :=
h.measurable.comp (hf.prod_mk hg)
lemma measurable.smul [semiring α] [second_countable_topology α]
[add_comm_monoid γ] [second_countable_topology γ]
[semimodule α γ] [topological_semimodule α γ]
{f : δ → α} {g : δ → γ} (hf : measurable f) (hg : measurable g) :
measurable (λ c, f c • g c) :=
continuous_smul.measurable2 hf hg
lemma measurable.const_smul {α : Type*} [topological_space α] [semiring α]
[add_comm_monoid γ] [semimodule α γ] [topological_semimodule α γ]
{f : δ → γ} (hf : measurable f) (c : α) :
measurable (λ x, c • f x) :=
(continuous_const.smul continuous_id).measurable.comp hf
lemma measurable_const_smul_iff {α : Type*} [topological_space α]
[division_ring α] [add_comm_monoid γ]
[semimodule α γ] [topological_semimodule α γ]
{f : δ → γ} {c : α} (hc : c ≠ 0) :
measurable (λ x, c • f x) ↔ measurable f :=
⟨λ h, by simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.const_smul c⁻¹,
λ h, h.const_smul c⟩
lemma is_measurable_le' [partial_order α] [order_closed_topology α] [second_countable_topology α] :
is_measurable {p : α × α | p.1 ≤ p.2} :=
order_closed_topology.is_closed_le'.is_measurable
lemma is_measurable_le [partial_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
is_measurable {a | f a ≤ g a} :=
(hf.prod_mk hg).preimage is_measurable_le'
lemma measurable.max [decidable_linear_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λa, max (f a) (g a)) :=
measurable.if (is_measurable_le hf hg) hg hf
lemma measurable.min [decidable_linear_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λa, min (f a) (g a)) :=
measurable.if (is_measurable_le hf hg) hf hg
end
section borel_space
variables [topological_space α] [measurable_space α] [borel_space α]
[topological_space β] [measurable_space β] [borel_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[measurable_space δ]
lemma prod_le_borel_prod : prod.measurable_space ≤ borel (α × β) :=
begin
rw [‹borel_space α›.measurable_eq, ‹borel_space β›.measurable_eq],
refine sup_le _ _,
{ exact comap_le_iff_le_map.mpr continuous_fst.borel_measurable },
{ exact comap_le_iff_le_map.mpr continuous_snd.borel_measurable }
end
instance prod.borel_space [second_countable_topology α] [second_countable_topology β] :
borel_space (α × β) :=
⟨le_antisymm prod_le_borel_prod opens_measurable_space.borel_le⟩
@[to_additive]
lemma measurable_mul [monoid α] [topological_monoid α] [second_countable_topology α] :
measurable (λ p : α × α, p.1 * p.2) :=
continuous_mul.measurable
@[to_additive]
lemma measurable.mul [monoid α] [topological_monoid α] [second_countable_topology α]
{f : δ → α} {g : δ → α} : measurable f → measurable g → measurable (λa, f a * g a) :=
continuous_mul.measurable2
@[to_additive]
lemma finset.measurable_prod {ι : Type*} [comm_monoid α] [topological_monoid α]
[second_countable_topology α] {f : ι → δ → α} (s : finset ι) (hf : ∀i, measurable (f i)) :
measurable (λa, s.prod (λi, f i a)) :=
finset.induction_on s
(by simp only [finset.prod_empty, measurable_const])
(assume i s his ih, by simpa [his] using (hf i).mul ih)
@[to_additive]
lemma measurable_inv [group α] [topological_group α] : measurable (has_inv.inv : α → α) :=
continuous_inv.measurable
@[to_additive]
lemma measurable.inv [group α] [topological_group α] {f : δ → α} (hf : measurable f) :
measurable (λa, (f a)⁻¹) :=
measurable_inv.comp hf
lemma measurable_inv' {α : Type*} [normed_field α] [measurable_space α] [borel_space α] :
measurable (has_inv.inv : α → α) :=
measurable_of_continuous_on_compl_singleton 0 normed_field.continuous_on_inv
lemma measurable.inv' {α : Type*} [normed_field α] [measurable_space α] [borel_space α]
{f : δ → α} (hf : measurable f) :
measurable (λa, (f a)⁻¹) :=
measurable_inv'.comp hf
@[to_additive]
lemma measurable.of_inv [group α] [topological_group α] {f : δ → α}
(hf : measurable (λ a, (f a)⁻¹)) : measurable f :=
by simpa only [inv_inv] using hf.inv
@[to_additive]
lemma measurable_inv_iff [group α] [topological_group α] {f : δ → α} :
measurable (λ a, (f a)⁻¹) ↔ measurable f :=
⟨measurable.of_inv, measurable.inv⟩
lemma measurable.sub [add_group α] [topological_add_group α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λ x, f x - g x) :=
hf.add hg.neg
lemma measurable.is_lub [linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_lub {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_lub (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_Ioi α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp only [set.preimage, mem_Ioi, lt_is_lub_iff (hg _), exists_range_iff, set_of_exists],
exact is_measurable.Union (λ i, hf i _ (is_open_lt' _).is_measurable)
end
lemma measurable.is_glb [linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_glb {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_glb (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_Iio α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp only [set.preimage, mem_Iio, is_glb_lt_iff (hg _), exists_range_iff, set_of_exists],
exact is_measurable.Union (λ i, hf i _ (is_open_gt' _).is_measurable)
end
lemma measurable_supr [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨆ i, f i b) :=
measurable.is_lub hf $ λ b, is_lub_supr
lemma measurable_infi [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨅ i, f i b) :=
measurable.is_glb hf $ λ b, is_glb_infi
lemma measurable.supr_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨆ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact supr_pos h end)
(assume h : ¬p, begin convert measurable_const, funext, exact supr_neg h end)
lemma measurable.infi_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨅ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact infi_pos h end )
(assume h : ¬p, begin convert measurable_const, funext, exact infi_neg h end)
lemma measurable_bsupr [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] (p : ι → Prop) {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨆ i (hi : p i), f i b) :=
measurable_supr $ λ i, (hf i).supr_Prop (p i)
lemma measurable_binfi [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] (p : ι → Prop) {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨅ i (hi : p i), f i b) :=
measurable_infi $ λ i, (hf i).infi_Prop (p i)
/-- Convert a `homeomorph` to a `measurable_equiv`. -/
def homemorph.to_measurable_equiv (h : α ≃ₜ β) :
measurable_equiv α β :=
{ to_equiv := h.to_equiv,
measurable_to_fun := h.continuous_to_fun.measurable,
measurable_inv_fun := h.continuous_inv_fun.measurable }
end borel_space
instance empty.borel_space : borel_space empty := ⟨borel_eq_top_of_discrete.symm⟩
instance unit.borel_space : borel_space unit := ⟨borel_eq_top_of_discrete.symm⟩
instance bool.borel_space : borel_space bool := ⟨borel_eq_top_of_discrete.symm⟩
instance nat.borel_space : borel_space ℕ := ⟨borel_eq_top_of_discrete.symm⟩
instance int.borel_space : borel_space ℤ := ⟨borel_eq_top_of_discrete.symm⟩
instance rat.borel_space : borel_space ℚ := ⟨borel_eq_top_of_encodable.symm⟩
instance real.measurable_space : measurable_space ℝ := borel ℝ
instance real.borel_space : borel_space ℝ := ⟨rfl⟩
instance nnreal.measurable_space : measurable_space nnreal := borel nnreal
instance nnreal.borel_space : borel_space nnreal := ⟨rfl⟩
instance ennreal.measurable_space : measurable_space ennreal := borel ennreal
instance ennreal.borel_space : borel_space ennreal := ⟨rfl⟩
section metric_space
variables [metric_space α] [measurable_space α] [opens_measurable_space α] {x : α} {ε : ℝ}
lemma is_measurable_ball : is_measurable (metric.ball x ε) :=
metric.is_open_ball.is_measurable
lemma is_measurable_closed_ball : is_measurable (metric.closed_ball x ε) :=
metric.is_closed_ball.is_measurable
lemma measurable_dist [second_countable_topology α] :
measurable (λp:α×α, dist p.1 p.2) :=
continuous_dist.measurable
lemma measurable.dist [second_countable_topology α] [measurable_space β] {f g : β → α}
(hf : measurable f) (hg : measurable g) : measurable (λ b, dist (f b) (g b)) :=
continuous_dist.measurable2 hf hg
lemma measurable_nndist [second_countable_topology α] : measurable (λp:α×α, nndist p.1 p.2) :=
continuous_nndist.measurable
lemma measurable.nndist [second_countable_topology α] [measurable_space β] {f g : β → α} :
measurable f → measurable g → measurable (λ b, nndist (f b) (g b)) :=
continuous_nndist.measurable2
end metric_space
section emetric_space
variables [emetric_space α] [measurable_space α] [opens_measurable_space α] {x : α} {ε : ennreal}
lemma is_measurable_eball : is_measurable (emetric.ball x ε) :=
emetric.is_open_ball.is_measurable
lemma measurable_edist [second_countable_topology α] :
measurable (λp:α×α, edist p.1 p.2) :=
continuous_edist.measurable
lemma measurable.edist [second_countable_topology α] [measurable_space β] {f g : β → α} :
measurable f → measurable g → measurable (λ b, edist (f b) (g b)) :=
continuous_edist.measurable2
end emetric_space
namespace real
open measurable_space
lemma borel_eq_generate_from_Ioo_rat :
borel ℝ = generate_from (⋃(a b : ℚ) (h : a < b), {Ioo a b}) :=
borel_eq_generate_from_of_subbasis is_topological_basis_Ioo_rat.2.2
lemma borel_eq_generate_from_Iio_rat :
borel ℝ = generate_from (⋃a:ℚ, {Iio a}) :=
begin
let g, swap,
apply le_antisymm (_ : _ ≤ g) (measurable_space.generate_from_le (λ t, _)),
{ rw borel_eq_generate_from_Ioo_rat,
refine generate_from_le (λ t, _),
simp only [mem_Union], rintro ⟨a, b, h, H⟩,
rw [mem_singleton_iff.1 H],
rw (set.ext (λ x, _) : Ioo (a:ℝ) b = (⋃c>a, - Iio c) ∩ Iio b),
{ have hg : ∀q:ℚ, g.is_measurable (Iio q) :=
λ q, generate_measurable.basic _ (by simp; exact ⟨_, rfl⟩),
refine @is_measurable.inter _ g _ _ _ (hg _),
refine @is_measurable.bUnion _ _ g _ _ (countable_encodable _) (λ c h, _),
exact @is_measurable.compl _ _ g (hg _) },
{ simp [Ioo, Iio],
refine and_congr _ iff.rfl,
exact ⟨λ h,
let ⟨c, ac, cx⟩ := exists_rat_btwn h in
⟨c, rat.cast_lt.1 ac, le_of_lt cx⟩,
λ ⟨c, ac, cx⟩, lt_of_lt_of_le (rat.cast_lt.2 ac) cx⟩ } },
{ simp, rintro r rfl,
exact is_open_Iio.is_measurable }
end
end real
lemma measurable.sub_nnreal [measurable_space α] {f g : α → nnreal} :
measurable f → measurable g → measurable (λ a, f a - g a) :=
nnreal.continuous_sub.measurable2
lemma measurable.nnreal_of_real [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, nnreal.of_real (f x)) :=
nnreal.continuous_of_real.measurable.comp hf
lemma measurable.nnreal_coe [measurable_space α] {f : α → nnreal} (hf : measurable f) :
measurable (λ x, (f x : ℝ)) :=
nnreal.continuous_coe.measurable.comp hf
lemma measurable.ennreal_coe [measurable_space α] {f : α → nnreal} (hf : measurable f) :
measurable (λ x, (f x : ennreal)) :=
(ennreal.continuous_coe.2 continuous_id).measurable.comp hf
lemma measurable.ennreal_of_real [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, ennreal.of_real (f x)) :=
ennreal.continuous_of_real.measurable.comp hf
/-- The set of finite `ennreal` numbers is `measurable_equiv` to `nnreal`. -/
def measurable_equiv.ennreal_equiv_nnreal : measurable_equiv {r : ennreal | r ≠ ⊤} nnreal :=
ennreal.ne_top_homeomorph_nnreal.to_measurable_equiv
namespace ennreal
open filter
lemma measurable_coe : measurable (coe : nnreal → ennreal) :=
measurable_id.ennreal_coe
lemma measurable_of_measurable_nnreal [measurable_space α] {f : ennreal → α}
(h : measurable (λp:nnreal, f p)) : measurable f :=
measurable_of_measurable_on_compl_singleton ⊤ is_measurable_singleton
(measurable_equiv.ennreal_equiv_nnreal.symm.measurable_coe_iff.1 h)
/-- `ennreal` is `measurable_equiv` to `nnreal ⊕ unit`. -/
def ennreal_equiv_sum :
measurable_equiv ennreal (nnreal ⊕ unit) :=
{ measurable_to_fun := measurable_of_measurable_nnreal measurable_inl,
measurable_inv_fun := measurable_sum measurable_coe (@measurable_const ennreal unit _ _ ⊤),
.. equiv.option_equiv_sum_punit nnreal }
lemma measurable_of_measurable_nnreal_nnreal [measurable_space α] [measurable_space β]
(f : ennreal → ennreal → β) {g : α → ennreal} {h : α → ennreal}
(h₁ : measurable (λp:nnreal × nnreal, f p.1 p.2))
(h₂ : measurable (λr:nnreal, f ⊤ r))
(h₃ : measurable (λr:nnreal, f r ⊤))
(hg : measurable g) (hh : measurable h) : measurable (λa, f (g a) (h a)) :=
let e : measurable_equiv (ennreal × ennreal)
(((nnreal × nnreal) ⊕ (nnreal × unit)) ⊕ ((unit × nnreal) ⊕ (unit × unit))) :=
(measurable_equiv.prod_congr ennreal_equiv_sum ennreal_equiv_sum).trans
(measurable_equiv.sum_prod_sum _ _ _ _) in
have measurable (λp:ennreal×ennreal, f p.1 p.2),
begin
refine e.symm.measurable_coe_iff.1 (measurable_sum (measurable_sum _ _) (measurable_sum _ _)),
{ show measurable (λp:nnreal × nnreal, f p.1 p.2),
exact h₁ },
{ show measurable (λp:nnreal × unit, f p.1 ⊤),
exact h₃.comp (measurable.fst measurable_id) },
{ show measurable ((λp:nnreal, f ⊤ p) ∘ (λp:unit × nnreal, p.2)),
exact h₂.comp (measurable.snd measurable_id) },
{ show measurable (λp:unit × unit, f ⊤ ⊤),
exact measurable_const }
end,
this.comp (measurable.prod_mk hg hh)
lemma measurable_of_real : measurable ennreal.of_real :=
ennreal.continuous_of_real.measurable
end ennreal
lemma measurable.ennreal_mul {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a * g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (*) _ _ _,
{ simp only [ennreal.coe_mul.symm],
exact ennreal.measurable_coe.comp measurable_mul },
{ simp [ennreal.top_mul],
exact measurable.if
(is_closed_eq continuous_id continuous_const).is_measurable
measurable_const
measurable_const },
{ simp [ennreal.mul_top],
exact measurable.if
(is_closed_eq continuous_id continuous_const).is_measurable
measurable_const
measurable_const }
end
lemma measurable.ennreal_add {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a + g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (+) _ _ _,
{ simp only [ennreal.coe_add.symm],
exact ennreal.measurable_coe.comp measurable_add },
{ simp [measurable_const] },
{ simp [measurable_const] }
end
lemma measurable.ennreal_sub {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a - g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (has_sub.sub) _ _ _,
{ simp only [ennreal.coe_sub.symm],
exact ennreal.measurable_coe.comp nnreal.continuous_sub.measurable },
{ simp [measurable_const] },
{ simp [measurable_const] }
end
section normed_group
variables [measurable_space α] [normed_group α] [opens_measurable_space α] [measurable_space β]
lemma measurable_norm : measurable (norm : α → ℝ) :=
continuous_norm.measurable
lemma measurable.norm {f : β → α} (hf : measurable f) : measurable (λa, norm (f a)) :=
measurable_norm.comp hf
lemma measurable_nnnorm : measurable (nnnorm : α → nnreal) :=
continuous_nnnorm.measurable
lemma measurable.nnnorm {f : β → α} (hf : measurable f) : measurable (λa, nnnorm (f a)) :=
measurable_nnnorm.comp hf
lemma measurable.ennnorm {f : β → α} (hf : measurable f) :
measurable (λa, (nnnorm (f a) : ennreal)) :=
hf.nnnorm.ennreal_coe
end normed_group
|
bfca895c13fb42af62313926ae0c6deb16a240c0 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/lake/Lake/Util/OrdHashSet.lean | 468ef1609375f05f15852268bbe8243d00cf5475 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,619 | lean | /-
Copyright (c) 2022 Mac Malone. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mac Malone
-/
import Lean.Data.HashSet
open Lean
namespace Lake
/-- A `HashSet` that preserves insertion order. -/
structure OrdHashSet (α) [Hashable α] [BEq α] where
toHashSet : HashSet α
toArray : Array α
namespace OrdHashSet
variable [Hashable α] [BEq α]
def empty : OrdHashSet α :=
⟨.empty, .empty⟩
def mkEmpty (size : Nat) : OrdHashSet α :=
⟨.empty, .mkEmpty size⟩
def insert (self : OrdHashSet α) (a : α) : OrdHashSet α :=
if self.toHashSet.contains a then
self
else
⟨self.toHashSet.insert a, self.toArray.push a⟩
def appendArray (self : OrdHashSet α) (arr : Array α) :=
arr.foldl (·.insert ·) self
instance : HAppend (OrdHashSet α) (Array α) (OrdHashSet α) := ⟨OrdHashSet.appendArray⟩
protected def append (self other : OrdHashSet α) :=
self.appendArray other.toArray
instance : Append (OrdHashSet α) := ⟨OrdHashSet.append⟩
def ofArray (arr : Array α) : OrdHashSet α :=
mkEmpty arr.size |>.appendArray arr
@[inline] def foldl (f : β → α → β) (init : β) (self : OrdHashSet α) : β :=
self.toArray.foldl f init
@[inline] def foldlM [Monad m] (f : β → α → m β) (init : β) (self : OrdHashSet α) : m β :=
self.toArray.foldlM f init
@[inline] def foldr (f : α → β → β) (init : β) (self : OrdHashSet α) : β :=
self.toArray.foldr f init
@[inline] def foldrM [Monad m] (f : α → β → m β) (init : β) (self : OrdHashSet α) : m β :=
self.toArray.foldrM f init
|
bf56118bee8a724648cb6604042289bf2321f121 | 761d983a78bc025071bac14a3facced881cf5e53 | /affine/add_group_action.lean | e7de2f8cd4444550c237cc68cfae78173e805f9f | [] | no_license | rohanrajnair/affine_lib | bcf22ff892cf74ccb36a95bc9b7fff8e0adb2d0d | 83076864245ac547b9d615bc6a23804b1b4a8f70 | refs/heads/master | 1,673,320,928,343 | 1,603,036,653,000 | 1,603,036,653,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 700 | lean | /-
Provides definitions so that we can have additive group actions.
-/
import algebra.group.basic
universes u v
variables {α : Type u} {β : Type v}
/-- Typeclass for types with transformation functions.
For our purposes, those transformations are translations by a vector. -/
class has_trans (α : Type u) (γ : Type v) := (sadd : α → γ → γ)
infixr ` ⊹ `:73 := has_trans.sadd -- notation for group addition
/-- Typeclass for additive actions by additive groups. -/
class add_action (α : Type u) (β : Type v) [add_group α] extends has_trans α β :=
(zero_sadd : ∀ b : β, (0 : α) ⊹ b = b)
(add_sadd : ∀ (x y : α) (b : β), (x + y) ⊹ b = x ⊹ y ⊹ b)
|
a25d20c9b63d780eeba8fdd3a74ede09cb84ac0e | 4727251e0cd73359b15b664c3170e5d754078599 | /src/analysis/inner_product_space/projection.lean | 8373fda22837d80c2adff261169684177f56410b | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 58,160 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Frédéric Dupuis, Heather Macbeth
-/
import analysis.convex.basic
import analysis.inner_product_space.basic
import analysis.normed_space.is_R_or_C
/-!
# The orthogonal projection
Given a nonempty complete subspace `K` of an inner product space `E`, this file constructs
`orthogonal_projection K : E →L[𝕜] K`, the orthogonal projection of `E` onto `K`. This map
satisfies: for any point `u` in `E`, the point `v = orthogonal_projection K u` in `K` minimizes the
distance `∥u - v∥` to `u`.
Also a linear isometry equivalence `reflection K : E ≃ₗᵢ[𝕜] E` is constructed, by choosing, for
each `u : E`, the point `reflection K u` to satisfy
`u + (reflection K u) = 2 • orthogonal_projection K u`.
Basic API for `orthogonal_projection` and `reflection` is developed.
Next, the orthogonal projection is used to prove a series of more subtle lemmas about the
the orthogonal complement of complete subspaces of `E` (the orthogonal complement itself was
defined in `analysis.inner_product_space.basic`); the lemma
`submodule.sup_orthogonal_of_is_complete`, stating that for a complete subspace `K` of `E` we have
`K ⊔ Kᗮ = ⊤`, is a typical example.
The last section covers orthonormal bases, etc. The lemma
`maximal_orthonormal_iff_orthogonal_complement_eq_bot` states that an orthonormal set in an inner
product space is maximal, if and only the orthogonal complement of its span is trivial.
Various consequences are stated for finite-dimensional `E`, including that a maximal orthonormal
set is a basis (`maximal_orthonormal_iff_basis_of_finite_dimensional`); these consequences require
the theory on the orthogonal complement developed earlier in this file. For consequences in
infinite dimension (Hilbert bases, etc.), see the file `analysis.inner_product_space.l2_space`.
## References
The orthogonal projection construction is adapted from
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable theory
open is_R_or_C real filter
open_locale big_operators topological_space
variables {𝕜 E F : Type*} [is_R_or_C 𝕜]
variables [inner_product_space 𝕜 E] [inner_product_space ℝ F]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E _ x y
local notation `absR` := has_abs.abs
/-! ### Orthogonal projection in inner product spaces -/
/--
Existence of minimizers
Let `u` be a point in a real inner product space, and let `K` be a nonempty complete convex subset.
Then there exists a (unique) `v` in `K` that minimizes the distance `∥u - v∥` to `u`.
-/
-- FIXME this monolithic proof causes a deterministic timeout with `-T50000`
-- It should be broken in a sequence of more manageable pieces,
-- perhaps with individual statements for the three steps below.
theorem exists_norm_eq_infi_of_complete_convex {K : set F} (ne : K.nonempty) (h₁ : is_complete K)
(h₂ : convex ℝ K) : ∀ u : F, ∃ v ∈ K, ∥u - v∥ = ⨅ w : K, ∥u - w∥ := assume u,
begin
let δ := ⨅ w : K, ∥u - w∥,
letI : nonempty K := ne.to_subtype,
have zero_le_δ : 0 ≤ δ := le_cinfi (λ _, norm_nonneg _),
have δ_le : ∀ w : K, δ ≤ ∥u - w∥,
from cinfi_le ⟨0, set.forall_range_iff.2 $ λ _, norm_nonneg _⟩,
have δ_le' : ∀ w ∈ K, δ ≤ ∥u - w∥ := assume w hw, δ_le ⟨w, hw⟩,
-- Step 1: since `δ` is the infimum, can find a sequence `w : ℕ → K` in `K`
-- such that `∥u - w n∥ < δ + 1 / (n + 1)` (which implies `∥u - w n∥ --> δ`);
-- maybe this should be a separate lemma
have exists_seq : ∃ w : ℕ → K, ∀ n, ∥u - w n∥ < δ + 1 / (n + 1),
{ have hδ : ∀n:ℕ, δ < δ + 1 / (n + 1), from
λ n, lt_add_of_le_of_pos le_rfl nat.one_div_pos_of_nat,
have h := λ n, exists_lt_of_cinfi_lt (hδ n),
let w : ℕ → K := λ n, classical.some (h n),
exact ⟨w, λ n, classical.some_spec (h n)⟩ },
rcases exists_seq with ⟨w, hw⟩,
have norm_tendsto : tendsto (λ n, ∥u - w n∥) at_top (nhds δ),
{ have h : tendsto (λ n:ℕ, δ) at_top (nhds δ) := tendsto_const_nhds,
have h' : tendsto (λ n:ℕ, δ + 1 / (n + 1)) at_top (nhds δ),
{ convert h.add tendsto_one_div_add_at_top_nhds_0_nat, simp only [add_zero] },
exact tendsto_of_tendsto_of_tendsto_of_le_of_le h h'
(λ x, δ_le _) (λ x, le_of_lt (hw _)) },
-- Step 2: Prove that the sequence `w : ℕ → K` is a Cauchy sequence
have seq_is_cauchy : cauchy_seq (λ n, ((w n):F)),
{ rw cauchy_seq_iff_le_tendsto_0, -- splits into three goals
let b := λ n:ℕ, (8 * δ * (1/(n+1)) + 4 * (1/(n+1)) * (1/(n+1))),
use (λn, sqrt (b n)),
split,
-- first goal : `∀ (n : ℕ), 0 ≤ sqrt (b n)`
assume n, exact sqrt_nonneg _,
split,
-- second goal : `∀ (n m N : ℕ), N ≤ n → N ≤ m → dist ↑(w n) ↑(w m) ≤ sqrt (b N)`
assume p q N hp hq,
let wp := ((w p):F), let wq := ((w q):F),
let a := u - wq, let b := u - wp,
let half := 1 / (2:ℝ), let div := 1 / ((N:ℝ) + 1),
have : 4 * ∥u - half • (wq + wp)∥ * ∥u - half • (wq + wp)∥ + ∥wp - wq∥ * ∥wp - wq∥ =
2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) :=
calc
4 * ∥u - half•(wq + wp)∥ * ∥u - half•(wq + wp)∥ + ∥wp - wq∥ * ∥wp - wq∥
= (2*∥u - half•(wq + wp)∥) * (2 * ∥u - half•(wq + wp)∥) + ∥wp-wq∥*∥wp-wq∥ : by ring
... = (absR ((2:ℝ)) * ∥u - half•(wq + wp)∥) * (absR ((2:ℝ)) * ∥u - half•(wq+wp)∥) +
∥wp-wq∥*∥wp-wq∥ :
by { rw _root_.abs_of_nonneg, exact zero_le_two }
... = ∥(2:ℝ) • (u - half • (wq + wp))∥ * ∥(2:ℝ) • (u - half • (wq + wp))∥ +
∥wp-wq∥ * ∥wp-wq∥ :
by simp [norm_smul]
... = ∥a + b∥ * ∥a + b∥ + ∥a - b∥ * ∥a - b∥ :
begin
rw [smul_sub, smul_smul, mul_one_div_cancel (_root_.two_ne_zero : (2 : ℝ) ≠ 0),
← one_add_one_eq_two, add_smul],
simp only [one_smul],
have eq₁ : wp - wq = a - b, from (sub_sub_sub_cancel_left _ _ _).symm,
have eq₂ : u + u - (wq + wp) = a + b, show u + u - (wq + wp) = (u - wq) + (u - wp), abel,
rw [eq₁, eq₂],
end
... = 2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) : parallelogram_law_with_norm _ _,
have eq : δ ≤ ∥u - half • (wq + wp)∥,
{ rw smul_add,
apply δ_le', apply h₂,
repeat {exact subtype.mem _},
repeat {exact le_of_lt one_half_pos},
exact add_halves 1 },
have eq₁ : 4 * δ * δ ≤ 4 * ∥u - half • (wq + wp)∥ * ∥u - half • (wq + wp)∥,
{ mono, mono, norm_num, apply mul_nonneg, norm_num, exact norm_nonneg _ },
have eq₂ : ∥a∥ * ∥a∥ ≤ (δ + div) * (δ + div) :=
mul_self_le_mul_self (norm_nonneg _)
(le_trans (le_of_lt $ hw q) (add_le_add_left (nat.one_div_le_one_div hq) _)),
have eq₂' : ∥b∥ * ∥b∥ ≤ (δ + div) * (δ + div) :=
mul_self_le_mul_self (norm_nonneg _)
(le_trans (le_of_lt $ hw p) (add_le_add_left (nat.one_div_le_one_div hp) _)),
rw dist_eq_norm,
apply nonneg_le_nonneg_of_sq_le_sq, { exact sqrt_nonneg _ },
rw mul_self_sqrt,
calc
∥wp - wq∥ * ∥wp - wq∥ = 2 * (∥a∥*∥a∥ + ∥b∥*∥b∥) -
4 * ∥u - half • (wq+wp)∥ * ∥u - half • (wq+wp)∥ : by { rw ← this, simp }
... ≤ 2 * (∥a∥ * ∥a∥ + ∥b∥ * ∥b∥) - 4 * δ * δ : sub_le_sub_left eq₁ _
... ≤ 2 * ((δ + div) * (δ + div) + (δ + div) * (δ + div)) - 4 * δ * δ :
sub_le_sub_right (mul_le_mul_of_nonneg_left (add_le_add eq₂ eq₂') (by norm_num)) _
... = 8 * δ * div + 4 * div * div : by ring,
exact add_nonneg
(mul_nonneg (mul_nonneg (by norm_num) zero_le_δ) (le_of_lt nat.one_div_pos_of_nat))
(mul_nonneg (mul_nonneg (by norm_num) nat.one_div_pos_of_nat.le) nat.one_div_pos_of_nat.le),
-- third goal : `tendsto (λ (n : ℕ), sqrt (b n)) at_top (𝓝 0)`
apply tendsto.comp,
{ convert continuous_sqrt.continuous_at, exact sqrt_zero.symm },
have eq₁ : tendsto (λ (n : ℕ), 8 * δ * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert (@tendsto_const_nhds _ _ _ (8 * δ) _).mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
have : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert (@tendsto_const_nhds _ _ _ (4:ℝ) _).mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
have eq₂ : tendsto (λ (n : ℕ), (4:ℝ) * (1 / (n + 1)) * (1 / (n + 1))) at_top (nhds (0:ℝ)),
{ convert this.mul tendsto_one_div_add_at_top_nhds_0_nat,
simp only [mul_zero] },
convert eq₁.add eq₂, simp only [add_zero] },
-- Step 3: By completeness of `K`, let `w : ℕ → K` converge to some `v : K`.
-- Prove that it satisfies all requirements.
rcases cauchy_seq_tendsto_of_is_complete h₁ (λ n, _) seq_is_cauchy with ⟨v, hv, w_tendsto⟩,
use v, use hv,
have h_cont : continuous (λ v, ∥u - v∥) :=
continuous.comp continuous_norm (continuous.sub continuous_const continuous_id),
have : tendsto (λ n, ∥u - w n∥) at_top (nhds ∥u - v∥),
convert (tendsto.comp h_cont.continuous_at w_tendsto),
exact tendsto_nhds_unique this norm_tendsto,
exact subtype.mem _
end
/-- Characterization of minimizers for the projection on a convex set in a real inner product
space. -/
theorem norm_eq_infi_iff_real_inner_le_zero {K : set F} (h : convex ℝ K) {u : F} {v : F}
(hv : v ∈ K) : ∥u - v∥ = (⨅ w : K, ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0 :=
iff.intro
begin
assume eq w hw,
let δ := ⨅ w : K, ∥u - w∥, let p := ⟪u - v, w - v⟫_ℝ, let q := ∥w - v∥^2,
letI : nonempty K := ⟨⟨v, hv⟩⟩,
have zero_le_δ : 0 ≤ δ,
apply le_cinfi, intro, exact norm_nonneg _,
have δ_le : ∀ w : K, δ ≤ ∥u - w∥,
assume w, apply cinfi_le, use (0:ℝ), rintros _ ⟨_, rfl⟩, exact norm_nonneg _,
have δ_le' : ∀ w ∈ K, δ ≤ ∥u - w∥ := assume w hw, δ_le ⟨w, hw⟩,
have : ∀θ:ℝ, 0 < θ → θ ≤ 1 → 2 * p ≤ θ * q,
assume θ hθ₁ hθ₂,
have : ∥u - v∥^2 ≤ ∥u - v∥^2 - 2 * θ * ⟪u - v, w - v⟫_ℝ + θ*θ*∥w - v∥^2 :=
calc
∥u - v∥^2 ≤ ∥u - (θ•w + (1-θ)•v)∥^2 :
begin
simp only [sq], apply mul_self_le_mul_self (norm_nonneg _),
rw [eq], apply δ_le',
apply h hw hv,
exacts [le_of_lt hθ₁, sub_nonneg.2 hθ₂, add_sub_cancel'_right _ _],
end
... = ∥(u - v) - θ • (w - v)∥^2 :
begin
have : u - (θ•w + (1-θ)•v) = (u - v) - θ • (w - v),
{ rw [smul_sub, sub_smul, one_smul],
simp only [sub_eq_add_neg, add_comm, add_left_comm, add_assoc, neg_add_rev] },
rw this
end
... = ∥u - v∥^2 - 2 * θ * inner (u - v) (w - v) + θ*θ*∥w - v∥^2 :
begin
rw [norm_sub_sq, inner_smul_right, norm_smul],
simp only [sq],
show ∥u-v∥*∥u-v∥-2*(θ*inner(u-v)(w-v))+absR (θ)*∥w-v∥*(absR (θ)*∥w-v∥)=
∥u-v∥*∥u-v∥-2*θ*inner(u-v)(w-v)+θ*θ*(∥w-v∥*∥w-v∥),
rw abs_of_pos hθ₁, ring
end,
have eq₁ : ∥u-v∥^2-2*θ*inner(u-v)(w-v)+θ*θ*∥w-v∥^2=∥u-v∥^2+(θ*θ*∥w-v∥^2-2*θ*inner(u-v)(w-v)),
by abel,
rw [eq₁, le_add_iff_nonneg_right] at this,
have eq₂ : θ*θ*∥w-v∥^2-2*θ*inner(u-v)(w-v)=θ*(θ*∥w-v∥^2-2*inner(u-v)(w-v)), ring,
rw eq₂ at this,
have := le_of_sub_nonneg (nonneg_of_mul_nonneg_left this hθ₁),
exact this,
by_cases hq : q = 0,
{ rw hq at this,
have : p ≤ 0,
have := this (1:ℝ) (by norm_num) (by norm_num),
linarith,
exact this },
{ have q_pos : 0 < q,
apply lt_of_le_of_ne, exact sq_nonneg _, intro h, exact hq h.symm,
by_contradiction hp, rw not_le at hp,
let θ := min (1:ℝ) (p / q),
have eq₁ : θ*q ≤ p := calc
θ*q ≤ (p/q) * q : mul_le_mul_of_nonneg_right (min_le_right _ _) (sq_nonneg _)
... = p : div_mul_cancel _ hq,
have : 2 * p ≤ p := calc
2 * p ≤ θ*q : by { refine this θ (lt_min (by norm_num) (div_pos hp q_pos)) (by norm_num) }
... ≤ p : eq₁,
linarith }
end
begin
assume h,
letI : nonempty K := ⟨⟨v, hv⟩⟩,
apply le_antisymm,
{ apply le_cinfi, assume w,
apply nonneg_le_nonneg_of_sq_le_sq (norm_nonneg _),
have := h w w.2,
calc
∥u - v∥ * ∥u - v∥ ≤ ∥u - v∥ * ∥u - v∥ - 2 * inner (u - v) ((w:F) - v) : by linarith
... ≤ ∥u - v∥^2 - 2 * inner (u - v) ((w:F) - v) + ∥(w:F) - v∥^2 :
by { rw sq, refine le_add_of_nonneg_right _, exact sq_nonneg _ }
... = ∥(u - v) - (w - v)∥^2 : norm_sub_sq.symm
... = ∥u - w∥ * ∥u - w∥ :
by { have : (u - v) - (w - v) = u - w, abel, rw [this, sq] } },
{ show (⨅ (w : K), ∥u - w∥) ≤ (λw:K, ∥u - w∥) ⟨v, hv⟩,
apply cinfi_le, use 0, rintros y ⟨z, rfl⟩, exact norm_nonneg _ }
end
variables (K : submodule 𝕜 E)
/--
Existence of projections on complete subspaces.
Let `u` be a point in an inner product space, and let `K` be a nonempty complete subspace.
Then there exists a (unique) `v` in `K` that minimizes the distance `∥u - v∥` to `u`.
This point `v` is usually called the orthogonal projection of `u` onto `K`.
-/
theorem exists_norm_eq_infi_of_complete_subspace
(h : is_complete (↑K : set E)) : ∀ u : E, ∃ v ∈ K, ∥u - v∥ = ⨅ w : (K : set E), ∥u - w∥ :=
begin
letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,
letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E,
let K' : submodule ℝ E := submodule.restrict_scalars ℝ K,
exact exists_norm_eq_infi_of_complete_convex ⟨0, K'.zero_mem⟩ h K'.convex
end
/--
Characterization of minimizers in the projection on a subspace, in the real case.
Let `u` be a point in a real inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `∥u - v∥` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`).
This is superceded by `norm_eq_infi_iff_inner_eq_zero` that gives the same conclusion over
any `is_R_or_C` field.
-/
theorem norm_eq_infi_iff_real_inner_eq_zero (K : submodule ℝ F) {u : F} {v : F}
(hv : v ∈ K) : ∥u - v∥ = (⨅ w : (↑K : set F), ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w⟫_ℝ = 0 :=
iff.intro
begin
assume h,
have h : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0,
{ rwa [norm_eq_infi_iff_real_inner_le_zero] at h, exacts [K.convex, hv] },
assume w hw,
have le : ⟪u - v, w⟫_ℝ ≤ 0,
let w' := w + v,
have : w' ∈ K := submodule.add_mem _ hw hv,
have h₁ := h w' this,
have h₂ : w' - v = w, simp only [add_neg_cancel_right, sub_eq_add_neg],
rw h₂ at h₁, exact h₁,
have ge : ⟪u - v, w⟫_ℝ ≥ 0,
let w'' := -w + v,
have : w'' ∈ K := submodule.add_mem _ (submodule.neg_mem _ hw) hv,
have h₁ := h w'' this,
have h₂ : w'' - v = -w, simp only [neg_inj, add_neg_cancel_right, sub_eq_add_neg],
rw [h₂, inner_neg_right] at h₁,
linarith,
exact le_antisymm le ge
end
begin
assume h,
have : ∀ w ∈ K, ⟪u - v, w - v⟫_ℝ ≤ 0,
assume w hw,
let w' := w - v,
have : w' ∈ K := submodule.sub_mem _ hw hv,
have h₁ := h w' this,
exact le_of_eq h₁,
rwa norm_eq_infi_iff_real_inner_le_zero,
exacts [submodule.convex _, hv]
end
/--
Characterization of minimizers in the projection on a subspace.
Let `u` be a point in an inner product space, and let `K` be a nonempty subspace.
Then point `v` minimizes the distance `∥u - v∥` over points in `K` if and only if
for all `w ∈ K`, `⟪u - v, w⟫ = 0` (i.e., `u - v` is orthogonal to the subspace `K`)
-/
theorem norm_eq_infi_iff_inner_eq_zero {u : E} {v : E}
(hv : v ∈ K) : ∥u - v∥ = (⨅ w : (↑K : set E), ∥u - w∥) ↔ ∀ w ∈ K, ⟪u - v, w⟫ = 0 :=
begin
letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,
letI : module ℝ E := restrict_scalars.module ℝ 𝕜 E,
let K' : submodule ℝ E := K.restrict_scalars ℝ,
split,
{ assume H,
have A : ∀ w ∈ K, re ⟪u - v, w⟫ = 0 := (norm_eq_infi_iff_real_inner_eq_zero K' hv).1 H,
assume w hw,
apply ext,
{ simp [A w hw] },
{ symmetry, calc
im (0 : 𝕜) = 0 : im.map_zero
... = re ⟪u - v, (-I) • w⟫ : (A _ (K.smul_mem (-I) hw)).symm
... = re ((-I) * ⟪u - v, w⟫) : by rw inner_smul_right
... = im ⟪u - v, w⟫ : by simp } },
{ assume H,
have : ∀ w ∈ K', ⟪u - v, w⟫_ℝ = 0,
{ assume w hw,
rw [real_inner_eq_re_inner, H w hw],
exact zero_re' },
exact (norm_eq_infi_iff_real_inner_eq_zero K' hv).2 this }
end
section orthogonal_projection
variables [complete_space K]
/-- The orthogonal projection onto a complete subspace, as an
unbundled function. This definition is only intended for use in
setting up the bundled version `orthogonal_projection` and should not
be used once that is defined. -/
def orthogonal_projection_fn (v : E) :=
(exists_norm_eq_infi_of_complete_subspace K (complete_space_coe_iff_is_complete.mp ‹_›) v).some
variables {K}
/-- The unbundled orthogonal projection is in the given subspace.
This lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
lemma orthogonal_projection_fn_mem (v : E) : orthogonal_projection_fn K v ∈ K :=
(exists_norm_eq_infi_of_complete_subspace K
(complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some
/-- The characterization of the unbundled orthogonal projection. This
lemma is only intended for use in setting up the bundled version
and should not be used once that is defined. -/
lemma orthogonal_projection_fn_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonal_projection_fn K v, w⟫ = 0 :=
begin
rw ←norm_eq_infi_iff_inner_eq_zero K (orthogonal_projection_fn_mem v),
exact (exists_norm_eq_infi_of_complete_subspace K
(complete_space_coe_iff_is_complete.mp ‹_›) v).some_spec.some_spec
end
/-- The unbundled orthogonal projection is the unique point in `K`
with the orthogonality property. This lemma is only intended for use
in setting up the bundled version and should not be used once that is
defined. -/
lemma eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero
{u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) :
orthogonal_projection_fn K u = v :=
begin
rw [←sub_eq_zero, ←inner_self_eq_zero],
have hvs : orthogonal_projection_fn K u - v ∈ K :=
submodule.sub_mem K (orthogonal_projection_fn_mem u) hvm,
have huo : ⟪u - orthogonal_projection_fn K u, orthogonal_projection_fn K u - v⟫ = 0 :=
orthogonal_projection_fn_inner_eq_zero u _ hvs,
have huv : ⟪u - v, orthogonal_projection_fn K u - v⟫ = 0 := hvo _ hvs,
have houv : ⟪(u - v) - (u - orthogonal_projection_fn K u), orthogonal_projection_fn K u - v⟫ = 0,
{ rw [inner_sub_left, huo, huv, sub_zero] },
rwa sub_sub_sub_cancel_left at houv
end
variables (K)
lemma orthogonal_projection_fn_norm_sq (v : E) :
∥v∥ * ∥v∥ = ∥v - (orthogonal_projection_fn K v)∥ * ∥v - (orthogonal_projection_fn K v)∥
+ ∥orthogonal_projection_fn K v∥ * ∥orthogonal_projection_fn K v∥ :=
begin
set p := orthogonal_projection_fn K v,
have h' : ⟪v - p, p⟫ = 0,
{ exact orthogonal_projection_fn_inner_eq_zero _ _ (orthogonal_projection_fn_mem v) },
convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (v - p) p h' using 2;
simp,
end
/-- The orthogonal projection onto a complete subspace. -/
def orthogonal_projection : E →L[𝕜] K :=
linear_map.mk_continuous
{ to_fun := λ v, ⟨orthogonal_projection_fn K v, orthogonal_projection_fn_mem v⟩,
map_add' := λ x y, begin
have hm : orthogonal_projection_fn K x + orthogonal_projection_fn K y ∈ K :=
submodule.add_mem K (orthogonal_projection_fn_mem x) (orthogonal_projection_fn_mem y),
have ho :
∀ w ∈ K, ⟪x + y - (orthogonal_projection_fn K x + orthogonal_projection_fn K y), w⟫ = 0,
{ intros w hw,
rw [add_sub_add_comm, inner_add_left, orthogonal_projection_fn_inner_eq_zero _ w hw,
orthogonal_projection_fn_inner_eq_zero _ w hw, add_zero] },
ext,
simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]
end,
map_smul' := λ c x, begin
have hm : c • orthogonal_projection_fn K x ∈ K :=
submodule.smul_mem K _ (orthogonal_projection_fn_mem x),
have ho : ∀ w ∈ K, ⟪c • x - c • orthogonal_projection_fn K x, w⟫ = 0,
{ intros w hw,
rw [←smul_sub, inner_smul_left, orthogonal_projection_fn_inner_eq_zero _ w hw, mul_zero] },
ext,
simp [eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hm ho]
end }
1
(λ x, begin
simp only [one_mul, linear_map.coe_mk],
refine le_of_pow_le_pow 2 (norm_nonneg _) (by norm_num) _,
change ∥orthogonal_projection_fn K x∥ ^ 2 ≤ ∥x∥ ^ 2,
nlinarith [orthogonal_projection_fn_norm_sq K x]
end)
variables {K}
@[simp]
lemma orthogonal_projection_fn_eq (v : E) :
orthogonal_projection_fn K v = (orthogonal_projection K v : E) :=
rfl
/-- The characterization of the orthogonal projection. -/
@[simp]
lemma orthogonal_projection_inner_eq_zero (v : E) :
∀ w ∈ K, ⟪v - orthogonal_projection K v, w⟫ = 0 :=
orthogonal_projection_fn_inner_eq_zero v
/-- The difference of `v` from its orthogonal projection onto `K` is in `Kᗮ`. -/
@[simp] lemma sub_orthogonal_projection_mem_orthogonal (v : E) :
v - orthogonal_projection K v ∈ Kᗮ :=
begin
intros w hw,
rw inner_eq_zero_sym,
exact orthogonal_projection_inner_eq_zero _ _ hw
end
/-- The orthogonal projection is the unique point in `K` with the
orthogonality property. -/
lemma eq_orthogonal_projection_of_mem_of_inner_eq_zero
{u v : E} (hvm : v ∈ K) (hvo : ∀ w ∈ K, ⟪u - v, w⟫ = 0) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hvm hvo
/-- The orthogonal projections onto equal subspaces are coerced back to the same point in `E`. -/
lemma eq_orthogonal_projection_of_eq_submodule
{K' : submodule 𝕜 E} [complete_space K'] (h : K = K') (u : E) :
(orthogonal_projection K u : E) = (orthogonal_projection K' u : E) :=
begin
change orthogonal_projection_fn K u = orthogonal_projection_fn K' u,
congr,
exact h
end
/-- The orthogonal projection sends elements of `K` to themselves. -/
@[simp] lemma orthogonal_projection_mem_subspace_eq_self (v : K) : orthogonal_projection K v = v :=
by { ext, apply eq_orthogonal_projection_of_mem_of_inner_eq_zero; simp }
/-- A point equals its orthogonal projection if and only if it lies in the subspace. -/
lemma orthogonal_projection_eq_self_iff {v : E} :
(orthogonal_projection K v : E) = v ↔ v ∈ K :=
begin
refine ⟨λ h, _, λ h, eq_orthogonal_projection_of_mem_of_inner_eq_zero h _⟩,
{ rw ← h,
simp },
{ simp }
end
lemma linear_isometry.map_orthogonal_projection {E E' : Type*} [inner_product_space 𝕜 E]
[inner_product_space 𝕜 E'] (f : E →ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [complete_space p]
(x : E) :
f (orthogonal_projection p x) = orthogonal_projection (p.map f.to_linear_map) (f x) :=
begin
refine (eq_orthogonal_projection_of_mem_of_inner_eq_zero (submodule.apply_coe_mem_map _ _) $
λ y hy, _).symm,
rcases hy with ⟨x', hx', rfl : f x' = y⟩,
rw [f.coe_to_linear_map, ← f.map_sub, f.inner_map_map,
orthogonal_projection_inner_eq_zero x x' hx']
end
/-- Orthogonal projection onto the `submodule.map` of a subspace. -/
lemma orthogonal_projection_map_apply {E E' : Type*} [inner_product_space 𝕜 E]
[inner_product_space 𝕜 E'] (f : E ≃ₗᵢ[𝕜] E') (p : submodule 𝕜 E) [complete_space p]
(x : E') :
(orthogonal_projection (p.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x : E')
= f (orthogonal_projection p (f.symm x)) :=
by simpa only [f.coe_to_linear_isometry, f.apply_symm_apply]
using (f.to_linear_isometry.map_orthogonal_projection p (f.symm x)).symm
/-- The orthogonal projection onto the trivial submodule is the zero map. -/
@[simp] lemma orthogonal_projection_bot : orthogonal_projection (⊥ : submodule 𝕜 E) = 0 :=
by ext
variables (K)
/-- The orthogonal projection has norm `≤ 1`. -/
lemma orthogonal_projection_norm_le : ∥orthogonal_projection K∥ ≤ 1 :=
linear_map.mk_continuous_norm_le _ (by norm_num) _
variables (𝕜)
lemma smul_orthogonal_projection_singleton {v : E} (w : E) :
(∥v∥ ^ 2 : 𝕜) • (orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v :=
begin
suffices : ↑(orthogonal_projection (𝕜 ∙ v) ((∥v∥ ^ 2 : 𝕜) • w)) = ⟪v, w⟫ • v,
{ simpa using this },
apply eq_orthogonal_projection_of_mem_of_inner_eq_zero,
{ rw submodule.mem_span_singleton,
use ⟪v, w⟫ },
{ intros x hx,
obtain ⟨c, rfl⟩ := submodule.mem_span_singleton.mp hx,
have hv : ↑∥v∥ ^ 2 = ⟪v, v⟫ := by { norm_cast, simp [norm_sq_eq_inner] },
simp [inner_sub_left, inner_smul_left, inner_smul_right, ring_equiv.map_div, mul_comm, hv,
inner_product_space.conj_sym, hv] }
end
/-- Formula for orthogonal projection onto a single vector. -/
lemma orthogonal_projection_singleton {v : E} (w : E) :
(orthogonal_projection (𝕜 ∙ v) w : E) = (⟪v, w⟫ / ∥v∥ ^ 2) • v :=
begin
by_cases hv : v = 0,
{ rw [hv, eq_orthogonal_projection_of_eq_submodule (submodule.span_zero_singleton 𝕜)],
{ simp },
{ apply_instance } },
have hv' : ∥v∥ ≠ 0 := ne_of_gt (norm_pos_iff.mpr hv),
have key : ((∥v∥ ^ 2 : 𝕜)⁻¹ * ∥v∥ ^ 2) • ↑(orthogonal_projection (𝕜 ∙ v) w)
= ((∥v∥ ^ 2 : 𝕜)⁻¹ * ⟪v, w⟫) • v,
{ simp [mul_smul, smul_orthogonal_projection_singleton 𝕜 w] },
convert key;
field_simp [hv']
end
/-- Formula for orthogonal projection onto a single unit vector. -/
lemma orthogonal_projection_unit_singleton {v : E} (hv : ∥v∥ = 1) (w : E) :
(orthogonal_projection (𝕜 ∙ v) w : E) = ⟪v, w⟫ • v :=
by { rw ← smul_orthogonal_projection_singleton 𝕜 w, simp [hv] }
end orthogonal_projection
section reflection
variables {𝕜} (K) [complete_space K]
/-- Auxiliary definition for `reflection`: the reflection as a linear equivalence. -/
def reflection_linear_equiv : E ≃ₗ[𝕜] E :=
linear_equiv.of_involutive
(bit0 (K.subtype.comp (orthogonal_projection K).to_linear_map) - linear_map.id)
(λ x, by simp [bit0])
/-- Reflection in a complete subspace of an inner product space. The word "reflection" is
sometimes understood to mean specifically reflection in a codimension-one subspace, and sometimes
more generally to cover operations such as reflection in a point. The definition here, of
reflection in a subspace, is a more general sense of the word that includes both those common
cases. -/
def reflection : E ≃ₗᵢ[𝕜] E :=
{ norm_map' := begin
intros x,
let w : K := orthogonal_projection K x,
let v := x - w,
have : ⟪v, w⟫ = 0 := orthogonal_projection_inner_eq_zero x w w.2,
convert norm_sub_eq_norm_add this using 2,
{ rw [linear_equiv.coe_mk, reflection_linear_equiv,
linear_equiv.to_fun_eq_coe, linear_equiv.coe_of_involutive,
linear_map.sub_apply, linear_map.id_apply, bit0, linear_map.add_apply,
linear_map.comp_apply, submodule.subtype_apply,
continuous_linear_map.to_linear_map_eq_coe, continuous_linear_map.coe_coe],
dsimp [w, v],
abel, },
{ simp only [add_sub_cancel'_right, eq_self_iff_true], }
end,
..reflection_linear_equiv K }
variables {K}
/-- The result of reflecting. -/
lemma reflection_apply (p : E) : reflection K p = bit0 ↑(orthogonal_projection K p) - p := rfl
/-- Reflection is its own inverse. -/
@[simp] lemma reflection_symm : (reflection K).symm = reflection K := rfl
/-- Reflection is its own inverse. -/
@[simp] lemma reflection_inv : (reflection K)⁻¹ = reflection K := rfl
variables (K)
/-- Reflecting twice in the same subspace. -/
@[simp] lemma reflection_reflection (p : E) : reflection K (reflection K p) = p :=
(reflection K).left_inv p
/-- Reflection is involutive. -/
lemma reflection_involutive : function.involutive (reflection K) := reflection_reflection K
/-- Reflection is involutive. -/
@[simp] lemma reflection_trans_reflection :
(reflection K).trans (reflection K) = linear_isometry_equiv.refl 𝕜 E :=
linear_isometry_equiv.ext $ reflection_involutive K
/-- Reflection is involutive. -/
@[simp] lemma reflection_mul_reflection : reflection K * reflection K = 1 :=
reflection_trans_reflection _
variables {K}
/-- A point is its own reflection if and only if it is in the subspace. -/
lemma reflection_eq_self_iff (x : E) : reflection K x = x ↔ x ∈ K :=
begin
rw [←orthogonal_projection_eq_self_iff, reflection_apply, sub_eq_iff_eq_add', ← two_smul 𝕜,
← two_smul' 𝕜],
refine (smul_right_injective E _).eq_iff,
exact two_ne_zero
end
lemma reflection_mem_subspace_eq_self {x : E} (hx : x ∈ K) : reflection K x = x :=
(reflection_eq_self_iff x).mpr hx
/-- Reflection in the `submodule.map` of a subspace. -/
lemma reflection_map_apply {E E' : Type*} [inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [complete_space K] (x : E') :
reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) x = f (reflection K (f.symm x)) :=
by simp [bit0, reflection_apply, orthogonal_projection_map_apply f K x]
/-- Reflection in the `submodule.map` of a subspace. -/
lemma reflection_map {E E' : Type*} [inner_product_space 𝕜 E] [inner_product_space 𝕜 E']
(f : E ≃ₗᵢ[𝕜] E') (K : submodule 𝕜 E) [complete_space K] :
reflection (K.map (f.to_linear_equiv : E →ₗ[𝕜] E')) = f.symm.trans ((reflection K).trans f) :=
linear_isometry_equiv.ext $ reflection_map_apply f K
/-- Reflection through the trivial subspace {0} is just negation. -/
@[simp] lemma reflection_bot : reflection (⊥ : submodule 𝕜 E) = linear_isometry_equiv.neg 𝕜 :=
by ext; simp [reflection_apply]
end reflection
section orthogonal
/-- If `K₁` is complete and contained in `K₂`, `K₁` and `K₁ᗮ ⊓ K₂` span `K₂`. -/
lemma submodule.sup_orthogonal_inf_of_complete_space {K₁ K₂ : submodule 𝕜 E} (h : K₁ ≤ K₂)
[complete_space K₁] : K₁ ⊔ (K₁ᗮ ⊓ K₂) = K₂ :=
begin
ext x,
rw submodule.mem_sup,
let v : K₁ := orthogonal_projection K₁ x,
have hvm : x - v ∈ K₁ᗮ := sub_orthogonal_projection_mem_orthogonal x,
split,
{ rintro ⟨y, hy, z, hz, rfl⟩,
exact K₂.add_mem (h hy) hz.2 },
{ exact λ hx, ⟨v, v.prop, x - v, ⟨hvm, K₂.sub_mem hx (h v.prop)⟩, add_sub_cancel'_right _ _⟩ }
end
variables {K}
/-- If `K` is complete, `K` and `Kᗮ` span the whole space. -/
lemma submodule.sup_orthogonal_of_complete_space [complete_space K] : K ⊔ Kᗮ = ⊤ :=
begin
convert submodule.sup_orthogonal_inf_of_complete_space (le_top : K ≤ ⊤),
simp
end
variables (K)
/-- If `K` is complete, any `v` in `E` can be expressed as a sum of elements of `K` and `Kᗮ`. -/
lemma submodule.exists_sum_mem_mem_orthogonal [complete_space K] (v : E) :
∃ (y ∈ K) (z ∈ Kᗮ), v = y + z :=
begin
have h_mem : v ∈ K ⊔ Kᗮ := by simp [submodule.sup_orthogonal_of_complete_space],
obtain ⟨y, hy, z, hz, hyz⟩ := submodule.mem_sup.mp h_mem,
exact ⟨y, hy, z, hz, hyz.symm⟩
end
/-- If `K` is complete, then the orthogonal complement of its orthogonal complement is itself. -/
@[simp] lemma submodule.orthogonal_orthogonal [complete_space K] : Kᗮᗮ = K :=
begin
ext v,
split,
{ obtain ⟨y, hy, z, hz, rfl⟩ := K.exists_sum_mem_mem_orthogonal v,
intros hv,
have hz' : z = 0,
{ have hyz : ⟪z, y⟫ = 0 := by simp [hz y hy, inner_eq_zero_sym],
simpa [inner_add_right, hyz] using hv z hz },
simp [hy, hz'] },
{ intros hv w hw,
rw inner_eq_zero_sym,
exact hw v hv }
end
lemma submodule.orthogonal_orthogonal_eq_closure [complete_space E] :
Kᗮᗮ = K.topological_closure :=
begin
refine le_antisymm _ _,
{ convert submodule.orthogonal_orthogonal_monotone K.submodule_topological_closure,
haveI : complete_space K.topological_closure :=
K.is_closed_topological_closure.complete_space_coe,
rw K.topological_closure.orthogonal_orthogonal },
{ exact K.topological_closure_minimal K.le_orthogonal_orthogonal Kᗮ.is_closed_orthogonal }
end
variables {K}
/-- If `K` is complete, `K` and `Kᗮ` are complements of each other. -/
lemma submodule.is_compl_orthogonal_of_complete_space [complete_space K] : is_compl K Kᗮ :=
⟨K.orthogonal_disjoint, le_of_eq submodule.sup_orthogonal_of_complete_space.symm⟩
@[simp] lemma submodule.orthogonal_eq_bot_iff [complete_space (K : set E)] :
Kᗮ = ⊥ ↔ K = ⊤ :=
begin
refine ⟨_, λ h, by rw [h, submodule.top_orthogonal_eq_bot] ⟩,
intro h,
have : K ⊔ Kᗮ = ⊤ := submodule.sup_orthogonal_of_complete_space,
rwa [h, sup_comm, bot_sup_eq] at this,
end
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
lemma eq_orthogonal_projection_of_mem_orthogonal
[complete_space K] {u v : E} (hv : v ∈ K) (hvo : u - v ∈ Kᗮ) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_fn_of_mem_of_inner_eq_zero hv (λ w, inner_eq_zero_sym.mp ∘ (hvo w))
/-- A point in `K` with the orthogonality property (here characterized in terms of `Kᗮ`) must be the
orthogonal projection. -/
lemma eq_orthogonal_projection_of_mem_orthogonal'
[complete_space K] {u v z : E} (hv : v ∈ K) (hz : z ∈ Kᗮ) (hu : u = v + z) :
(orthogonal_projection K u : E) = v :=
eq_orthogonal_projection_of_mem_orthogonal hv (by simpa [hu])
/-- The orthogonal projection onto `K` of an element of `Kᗮ` is zero. -/
lemma orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero
[complete_space K] {v : E} (hv : v ∈ Kᗮ) :
orthogonal_projection K v = 0 :=
by { ext, convert eq_orthogonal_projection_of_mem_orthogonal _ _; simp [hv] }
/-- The reflection in `K` of an element of `Kᗮ` is its negation. -/
lemma reflection_mem_subspace_orthogonal_complement_eq_neg
[complete_space K] {v : E} (hv : v ∈ Kᗮ) :
reflection K v = - v :=
by simp [reflection_apply, orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero hv]
/-- The orthogonal projection onto `Kᗮ` of an element of `K` is zero. -/
lemma orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero
[complete_space E] {v : E} (hv : v ∈ K) :
orthogonal_projection Kᗮ v = 0 :=
orthogonal_projection_mem_subspace_orthogonal_complement_eq_zero (K.le_orthogonal_orthogonal hv)
/-- The reflection in `Kᗮ` of an element of `K` is its negation. -/
lemma reflection_mem_subspace_orthogonal_precomplement_eq_neg
[complete_space E] {v : E} (hv : v ∈ K) :
reflection Kᗮ v = -v :=
reflection_mem_subspace_orthogonal_complement_eq_neg (K.le_orthogonal_orthogonal hv)
/-- The orthogonal projection onto `(𝕜 ∙ v)ᗮ` of `v` is zero. -/
lemma orthogonal_projection_orthogonal_complement_singleton_eq_zero [complete_space E] (v : E) :
orthogonal_projection (𝕜 ∙ v)ᗮ v = 0 :=
orthogonal_projection_mem_subspace_orthogonal_precomplement_eq_zero
(submodule.mem_span_singleton_self v)
/-- The reflection in `(𝕜 ∙ v)ᗮ` of `v` is `-v`. -/
lemma reflection_orthogonal_complement_singleton_eq_neg [complete_space E] (v : E) :
reflection (𝕜 ∙ v)ᗮ v = -v :=
reflection_mem_subspace_orthogonal_precomplement_eq_neg (submodule.mem_span_singleton_self v)
lemma reflection_sub [complete_space F] {v w : F} (h : ∥v∥ = ∥w∥) :
reflection (ℝ ∙ (v - w))ᗮ v = w :=
begin
set R : F ≃ₗᵢ[ℝ] F := reflection (ℝ ∙ (v - w))ᗮ,
suffices : R v + R v = w + w,
{ apply smul_right_injective F (by norm_num : (2:ℝ) ≠ 0),
simpa [two_smul] using this },
have h₁ : R (v - w) = -(v - w) := reflection_orthogonal_complement_singleton_eq_neg (v - w),
have h₂ : R (v + w) = v + w,
{ apply reflection_mem_subspace_eq_self,
apply mem_orthogonal_singleton_of_inner_left,
rw real_inner_add_sub_eq_zero_iff,
exact h },
convert congr_arg2 (+) h₂ h₁ using 1,
{ simp },
{ abel }
end
variables (K)
/-- In a complete space `E`, a vector splits as the sum of its orthogonal projections onto a
complete submodule `K` and onto the orthogonal complement of `K`.-/
lemma eq_sum_orthogonal_projection_self_orthogonal_complement
[complete_space E] [complete_space K] (w : E) :
w = (orthogonal_projection K w : E) + (orthogonal_projection Kᗮ w : E) :=
begin
obtain ⟨y, hy, z, hz, hwyz⟩ := K.exists_sum_mem_mem_orthogonal w,
convert hwyz,
{ exact eq_orthogonal_projection_of_mem_orthogonal' hy hz hwyz },
{ rw add_comm at hwyz,
refine eq_orthogonal_projection_of_mem_orthogonal' hz _ hwyz,
simp [hy] }
end
/-- The Pythagorean theorem, for an orthogonal projection.-/
lemma norm_sq_eq_add_norm_sq_projection
(x : E) (S : submodule 𝕜 E) [complete_space E] [complete_space S] :
∥x∥^2 = ∥orthogonal_projection S x∥^2 + ∥orthogonal_projection Sᗮ x∥^2 :=
begin
let p1 := orthogonal_projection S,
let p2 := orthogonal_projection Sᗮ,
have x_decomp : x = p1 x + p2 x :=
eq_sum_orthogonal_projection_self_orthogonal_complement S x,
have x_orth : ⟪ p1 x, p2 x ⟫ = 0 :=
submodule.inner_right_of_mem_orthogonal (set_like.coe_mem (p1 x)) (set_like.coe_mem (p2 x)),
nth_rewrite 0 [x_decomp],
simp only [sq, norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero ((p1 x) : E) (p2 x) x_orth,
add_left_inj, mul_eq_mul_left_iff, norm_eq_zero, true_or, eq_self_iff_true,
submodule.coe_norm, submodule.coe_eq_zero]
end
/-- In a complete space `E`, the projection maps onto a complete subspace `K` and its orthogonal
complement sum to the identity. -/
lemma id_eq_sum_orthogonal_projection_self_orthogonal_complement
[complete_space E] [complete_space K] :
continuous_linear_map.id 𝕜 E
= K.subtypeL.comp (orthogonal_projection K)
+ Kᗮ.subtypeL.comp (orthogonal_projection Kᗮ) :=
by { ext w, exact eq_sum_orthogonal_projection_self_orthogonal_complement K w }
/-- The orthogonal projection is self-adjoint. -/
lemma inner_orthogonal_projection_left_eq_right [complete_space E]
[complete_space K] (u v : E) :
⟪↑(orthogonal_projection K u), v⟫ = ⟪u, orthogonal_projection K v⟫ :=
begin
nth_rewrite 0 eq_sum_orthogonal_projection_self_orthogonal_complement K v,
nth_rewrite 1 eq_sum_orthogonal_projection_self_orthogonal_complement K u,
rw [inner_add_left, inner_add_right,
submodule.inner_right_of_mem_orthogonal (submodule.coe_mem (orthogonal_projection K u))
(submodule.coe_mem (orthogonal_projection Kᗮ v)),
submodule.inner_left_of_mem_orthogonal (submodule.coe_mem (orthogonal_projection K v))
(submodule.coe_mem (orthogonal_projection Kᗮ u))],
end
open finite_dimensional
/-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁`
containined in it, the dimensions of `K₁` and the intersection of its
orthogonal subspace with `K₂` add to that of `K₂`. -/
lemma submodule.finrank_add_inf_finrank_orthogonal {K₁ K₂ : submodule 𝕜 E}
[finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) :
finrank 𝕜 K₁ + finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = finrank 𝕜 K₂ :=
begin
haveI := submodule.finite_dimensional_of_le h,
haveI := proper_is_R_or_C 𝕜 K₁,
have hd := submodule.dim_sup_add_dim_inf_eq K₁ (K₁ᗮ ⊓ K₂),
rw [←inf_assoc, (submodule.orthogonal_disjoint K₁).eq_bot, bot_inf_eq, finrank_bot,
submodule.sup_orthogonal_inf_of_complete_space h] at hd,
rw add_zero at hd,
exact hd.symm
end
/-- Given a finite-dimensional subspace `K₂`, and a subspace `K₁`
containined in it, the dimensions of `K₁` and the intersection of its
orthogonal subspace with `K₂` add to that of `K₂`. -/
lemma submodule.finrank_add_inf_finrank_orthogonal' {K₁ K₂ : submodule 𝕜 E}
[finite_dimensional 𝕜 K₂] (h : K₁ ≤ K₂) {n : ℕ} (h_dim : finrank 𝕜 K₁ + n = finrank 𝕜 K₂) :
finrank 𝕜 (K₁ᗮ ⊓ K₂ : submodule 𝕜 E) = n :=
by { rw ← add_right_inj (finrank 𝕜 K₁),
simp [submodule.finrank_add_inf_finrank_orthogonal h, h_dim] }
/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to
that of `E`. -/
lemma submodule.finrank_add_finrank_orthogonal [finite_dimensional 𝕜 E] (K : submodule 𝕜 E) :
finrank 𝕜 K + finrank 𝕜 Kᗮ = finrank 𝕜 E :=
begin
convert submodule.finrank_add_inf_finrank_orthogonal (le_top : K ≤ ⊤) using 1,
{ rw inf_top_eq },
{ simp }
end
/-- Given a finite-dimensional space `E` and subspace `K`, the dimensions of `K` and `Kᗮ` add to
that of `E`. -/
lemma submodule.finrank_add_finrank_orthogonal' [finite_dimensional 𝕜 E] {K : submodule 𝕜 E} {n : ℕ}
(h_dim : finrank 𝕜 K + n = finrank 𝕜 E) :
finrank 𝕜 Kᗮ = n :=
by { rw ← add_right_inj (finrank 𝕜 K), simp [submodule.finrank_add_finrank_orthogonal, h_dim] }
local attribute [instance] fact_finite_dimensional_of_finrank_eq_succ
/-- In a finite-dimensional inner product space, the dimension of the orthogonal complement of the
span of a nonzero vector is one less than the dimension of the space. -/
lemma finrank_orthogonal_span_singleton {n : ℕ} [_i : fact (finrank 𝕜 E = n + 1)]
{v : E} (hv : v ≠ 0) :
finrank 𝕜 (𝕜 ∙ v)ᗮ = n :=
submodule.finrank_add_finrank_orthogonal' $ by simp [finrank_span_singleton hv, _i.elim, add_comm]
/-- An element `φ` of the orthogonal group of `F` can be factored as a product of reflections, and
specifically at most as many reflections as the dimension of the complement of the fixed subspace
of `φ`. -/
lemma linear_isometry_equiv.reflections_generate_dim_aux [finite_dimensional ℝ F] {n : ℕ}
(φ : F ≃ₗᵢ[ℝ] F)
(hn : finrank ℝ (continuous_linear_map.id ℝ F - φ.to_continuous_linear_equiv).kerᗮ ≤ n) :
∃ l : list F, l.length ≤ n ∧ φ = (l.map (λ v, reflection (ℝ ∙ v)ᗮ)).prod :=
begin
-- We prove this by strong induction on `n`, the dimension of the orthogonal complement of the
-- fixed subspace of the endomorphism `φ`
induction n with n IH generalizing φ,
{ -- Base case: `n = 0`, the fixed subspace is the whole space, so `φ = id`
refine ⟨[], rfl.le, show φ = 1, from _⟩,
have : (continuous_linear_map.id ℝ F - φ.to_continuous_linear_equiv).ker = ⊤,
{ rwa [nat.le_zero_iff, finrank_eq_zero, submodule.orthogonal_eq_bot_iff] at hn },
symmetry,
ext x,
have := linear_map.congr_fun (linear_map.ker_eq_top.mp this) x,
rwa [continuous_linear_map.coe_sub, linear_map.zero_apply, linear_map.sub_apply, sub_eq_zero]
at this },
{ -- Inductive step. Let `W` be the fixed subspace of `φ`. We suppose its complement to have
-- dimension at most n + 1.
let W := (continuous_linear_map.id ℝ F - φ.to_continuous_linear_equiv).ker,
have hW : ∀ w ∈ W, φ w = w := λ w hw, (sub_eq_zero.mp hw).symm,
by_cases hn' : finrank ℝ Wᗮ ≤ n,
{ obtain ⟨V, hV₁, hV₂⟩ := IH φ hn',
exact ⟨V, hV₁.trans n.le_succ, hV₂⟩ },
-- Take a nonzero element `v` of the orthogonal complement of `W`.
haveI : nontrivial Wᗮ := nontrivial_of_finrank_pos (by linarith [zero_le n] : 0 < finrank ℝ Wᗮ),
obtain ⟨v, hv⟩ := exists_ne (0 : Wᗮ),
have hφv : φ v ∈ Wᗮ,
{ intros w hw,
rw [← hW w hw, linear_isometry_equiv.inner_map_map],
exact v.prop w hw },
have hv' : (v:F) ∉ W,
{ intros h,
exact hv ((submodule.mem_left_iff_eq_zero_of_disjoint W.orthogonal_disjoint).mp h) },
-- Let `ρ` be the reflection in `v - φ v`; this is designed to swap `v` and `φ v`
let x : F := v - φ v,
let ρ := reflection (ℝ ∙ x)ᗮ,
-- Notation: Let `V` be the fixed subspace of `φ.trans ρ`
let V := (continuous_linear_map.id ℝ F - (φ.trans ρ).to_continuous_linear_equiv).ker,
have hV : ∀ w, ρ (φ w) = w → w ∈ V,
{ intros w hw,
change w - ρ (φ w) = 0,
rw [sub_eq_zero, hw] },
-- Everything fixed by `φ` is fixed by `φ.trans ρ`
have H₂V : W ≤ V,
{ intros w hw,
apply hV,
rw hW w hw,
refine reflection_mem_subspace_eq_self _,
apply mem_orthogonal_singleton_of_inner_left,
exact submodule.sub_mem _ v.prop hφv _ hw },
-- `v` is also fixed by `φ.trans ρ`
have H₁V : (v : F) ∈ V,
{ apply hV,
have : ρ v = φ v := reflection_sub (φ.norm_map v).symm,
rw ←this,
exact reflection_reflection _ _, },
-- By dimension-counting, the complement of the fixed subspace of `φ.trans ρ` has dimension at
-- most `n`
have : finrank ℝ Vᗮ ≤ n,
{ change finrank ℝ Wᗮ ≤ n + 1 at hn,
have : finrank ℝ W + 1 ≤ finrank ℝ V :=
submodule.finrank_lt_finrank_of_lt (set_like.lt_iff_le_and_exists.2 ⟨H₂V, v, H₁V, hv'⟩),
have : finrank ℝ V + finrank ℝ Vᗮ = finrank ℝ F := V.finrank_add_finrank_orthogonal,
have : finrank ℝ W + finrank ℝ Wᗮ = finrank ℝ F := W.finrank_add_finrank_orthogonal,
linarith },
-- So apply the inductive hypothesis to `φ.trans ρ`
obtain ⟨l, hl, hφl⟩ := IH (ρ * φ) this,
-- Prepend `ρ` to the factorization into reflections obtained for `φ.trans ρ`; this gives a
-- factorization into reflections for `φ`.
refine ⟨x :: l, nat.succ_le_succ hl, _⟩,
rw [list.map_cons, list.prod_cons],
have := congr_arg ((*) ρ) hφl,
rwa [←mul_assoc, reflection_mul_reflection, one_mul] at this, }
end
/-- The orthogonal group of `F` is generated by reflections; specifically each element `φ` of the
orthogonal group is a product of at most as many reflections as the dimension of `F`.
Special case of the **Cartan–Dieudonné theorem**. -/
lemma linear_isometry_equiv.reflections_generate_dim [finite_dimensional ℝ F] (φ : F ≃ₗᵢ[ℝ] F) :
∃ l : list F, l.length ≤ finrank ℝ F ∧ φ = (l.map (λ v, reflection (ℝ ∙ v)ᗮ)).prod :=
let ⟨l, hl₁, hl₂⟩ := φ.reflections_generate_dim_aux le_rfl in
⟨l, hl₁.trans (submodule.finrank_le _), hl₂⟩
/-- The orthogonal group of `F` is generated by reflections. -/
lemma linear_isometry_equiv.reflections_generate [finite_dimensional ℝ F] :
subgroup.closure (set.range (λ v : F, reflection (ℝ ∙ v)ᗮ)) = ⊤ :=
begin
rw subgroup.eq_top_iff',
intros φ,
rcases φ.reflections_generate_dim with ⟨l, _, rfl⟩,
apply (subgroup.closure _).list_prod_mem,
intros x hx,
rcases list.mem_map.mp hx with ⟨a, _, hax⟩,
exact subgroup.subset_closure ⟨a, hax⟩,
end
end orthogonal
section orthogonal_family
variables {ι : Type*}
/-- An orthogonal family of subspaces of `E` satisfies `direct_sum.submodule_is_internal` (that is,
they provide an internal direct sum decomposition of `E`) if and only if their span has trivial
orthogonal complement. -/
lemma orthogonal_family.submodule_is_internal_iff_of_is_complete [decidable_eq ι]
{V : ι → submodule 𝕜 E} (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ))
(hc : is_complete (↑(supr V) : set E)) :
direct_sum.submodule_is_internal V ↔ (supr V)ᗮ = ⊥ :=
begin
haveI : complete_space ↥(supr V) := hc.complete_space_coe,
simp only [direct_sum.submodule_is_internal_iff_independent_and_supr_eq_top, hV.independent,
true_and, submodule.orthogonal_eq_bot_iff]
end
/-- An orthogonal family of subspaces of `E` satisfies `direct_sum.submodule_is_internal` (that is,
they provide an internal direct sum decomposition of `E`) if and only if their span has trivial
orthogonal complement. -/
lemma orthogonal_family.submodule_is_internal_iff [decidable_eq ι] [finite_dimensional 𝕜 E]
{V : ι → submodule 𝕜 E} (hV : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) :
direct_sum.submodule_is_internal V ↔ (supr V)ᗮ = ⊥ :=
begin
haveI h := finite_dimensional.proper_is_R_or_C 𝕜 ↥(supr V),
exact hV.submodule_is_internal_iff_of_is_complete
(complete_space_coe_iff_is_complete.mp infer_instance)
end
end orthogonal_family
section orthonormal_basis
/-! ### Existence of orthonormal basis, etc. -/
variables {𝕜 E} {v : set E}
open finite_dimensional submodule set
/-- An orthonormal set in an `inner_product_space` is maximal, if and only if the orthogonal
complement of its span is empty. -/
lemma maximal_orthonormal_iff_orthogonal_complement_eq_bot (hv : orthonormal 𝕜 (coe : v → E)) :
(∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ (span 𝕜 v)ᗮ = ⊥ :=
begin
rw submodule.eq_bot_iff,
split,
{ contrapose!,
-- ** direction 1: nonempty orthogonal complement implies nonmaximal
rintros ⟨x, hx', hx⟩,
-- take a nonzero vector and normalize it
let e := (∥x∥⁻¹ : 𝕜) • x,
have he : ∥e∥ = 1 := by simp [e, norm_smul_inv_norm hx],
have he' : e ∈ (span 𝕜 v)ᗮ := smul_mem' _ _ hx',
have he'' : e ∉ v,
{ intros hev,
have : e = 0,
{ have : e ∈ (span 𝕜 v) ⊓ (span 𝕜 v)ᗮ := ⟨subset_span hev, he'⟩,
simpa [(span 𝕜 v).inf_orthogonal_eq_bot] using this },
have : e ≠ 0 := hv.ne_zero ⟨e, hev⟩,
contradiction },
-- put this together with `v` to provide a candidate orthonormal basis for the whole space
refine ⟨v.insert e, v.subset_insert e, ⟨_, _⟩, (v.ne_insert_of_not_mem he'').symm⟩,
{ -- show that the elements of `v.insert e` have unit length
rintros ⟨a, ha'⟩,
cases eq_or_mem_of_mem_insert ha' with ha ha,
{ simp [ha, he] },
{ exact hv.1 ⟨a, ha⟩ } },
{ -- show that the elements of `v.insert e` are orthogonal
have h_end : ∀ a ∈ v, ⟪a, e⟫ = 0,
{ intros a ha,
exact he' a (submodule.subset_span ha) },
rintros ⟨a, ha'⟩,
cases eq_or_mem_of_mem_insert ha' with ha ha,
{ rintros ⟨b, hb'⟩ hab',
have hb : b ∈ v,
{ refine mem_of_mem_insert_of_ne hb' _,
intros hbe',
apply hab',
simp [ha, hbe'] },
rw inner_eq_zero_sym,
simpa [ha] using h_end b hb },
rintros ⟨b, hb'⟩ hab',
cases eq_or_mem_of_mem_insert hb' with hb hb,
{ simpa [hb] using h_end a ha },
have : (⟨a, ha⟩ : v) ≠ ⟨b, hb⟩,
{ intros hab'',
apply hab',
simpa using hab'' },
exact hv.2 this } },
{ -- ** direction 2: empty orthogonal complement implies maximal
simp only [subset.antisymm_iff],
rintros h u (huv : v ⊆ u) hu,
refine ⟨_, huv⟩,
intros x hxu,
refine ((mt (h x)) (hu.ne_zero ⟨x, hxu⟩)).imp_symm _,
intros hxv y hy,
have hxv' : (⟨x, hxu⟩ : u) ∉ (coe ⁻¹' v : set u) := by simp [huv, hxv],
obtain ⟨l, hl, rfl⟩ :
∃ l ∈ finsupp.supported 𝕜 𝕜 (coe ⁻¹' v : set u), (finsupp.total ↥u E 𝕜 coe) l = y,
{ rw ← finsupp.mem_span_image_iff_total,
simp [huv, inter_eq_self_of_subset_left, hy] },
exact hu.inner_finsupp_eq_zero hxv' hl }
end
section finite_dimensional
variables [finite_dimensional 𝕜 E]
/-- An orthonormal set in a finite-dimensional `inner_product_space` is maximal, if and only if it
is a basis. -/
lemma maximal_orthonormal_iff_basis_of_finite_dimensional
(hv : orthonormal 𝕜 (coe : v → E)) :
(∀ u ⊇ v, orthonormal 𝕜 (coe : u → E) → u = v) ↔ ∃ b : basis v 𝕜 E, ⇑b = coe :=
begin
haveI := proper_is_R_or_C 𝕜 (span 𝕜 v),
rw maximal_orthonormal_iff_orthogonal_complement_eq_bot hv,
have hv_compl : is_complete (span 𝕜 v : set E) := (span 𝕜 v).complete_of_finite_dimensional,
rw submodule.orthogonal_eq_bot_iff,
have hv_coe : range (coe : v → E) = v := by simp,
split,
{ refine λ h, ⟨basis.mk hv.linear_independent _, basis.coe_mk _ _⟩,
convert h },
{ rintros ⟨h, coe_h⟩,
rw [← h.span_eq, coe_h, hv_coe] }
end
/-- In a finite-dimensional `inner_product_space`, any orthonormal subset can be extended to an
orthonormal basis. -/
lemma exists_subset_is_orthonormal_basis
(hv : orthonormal 𝕜 (coe : v → E)) :
∃ (u ⊇ v) (b : basis u 𝕜 E), orthonormal 𝕜 b ∧ ⇑b = coe :=
begin
obtain ⟨u, hus, hu, hu_max⟩ := exists_maximal_orthonormal hv,
obtain ⟨b, hb⟩ := (maximal_orthonormal_iff_basis_of_finite_dimensional hu).mp hu_max,
exact ⟨u, hus, b, by rwa hb, hb⟩
end
variables (𝕜 E)
/-- Index for an arbitrary orthonormal basis on a finite-dimensional `inner_product_space`. -/
def orthonormal_basis_index : set E :=
classical.some (exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E))
/-- A finite-dimensional `inner_product_space` has an orthonormal basis. -/
def std_orthonormal_basis :
basis (orthonormal_basis_index 𝕜 E) 𝕜 E :=
(exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some
lemma std_orthonormal_basis_orthonormal :
orthonormal 𝕜 (std_orthonormal_basis 𝕜 E) :=
(exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some_spec.1
@[simp] lemma coe_std_orthonormal_basis :
⇑(std_orthonormal_basis 𝕜 E) = coe :=
(exists_subset_is_orthonormal_basis (orthonormal_empty 𝕜 E)).some_spec.some_spec.some_spec.2
instance : fintype (orthonormal_basis_index 𝕜 E) :=
@is_noetherian.fintype_basis_index _ _ _ _ _ _
(is_noetherian.iff_fg.2 infer_instance) (std_orthonormal_basis 𝕜 E)
variables {𝕜 E}
/-- An `n`-dimensional `inner_product_space` has an orthonormal basis indexed by `fin n`. -/
def fin_std_orthonormal_basis {n : ℕ} (hn : finrank 𝕜 E = n) :
basis (fin n) 𝕜 E :=
have h : fintype.card (orthonormal_basis_index 𝕜 E) = n,
by rw [← finrank_eq_card_basis (std_orthonormal_basis 𝕜 E), hn],
(std_orthonormal_basis 𝕜 E).reindex (fintype.equiv_fin_of_card_eq h)
lemma fin_std_orthonormal_basis_orthonormal {n : ℕ} (hn : finrank 𝕜 E = n) :
orthonormal 𝕜 (fin_std_orthonormal_basis hn) :=
suffices orthonormal 𝕜 (std_orthonormal_basis _ _ ∘ equiv.symm _),
by { simp only [fin_std_orthonormal_basis, basis.coe_reindex], assumption }, -- simpa doesn't work?
(std_orthonormal_basis_orthonormal 𝕜 E).comp _ (equiv.injective _)
section subordinate_orthonormal_basis
open direct_sum
variables {n : ℕ} (hn : finrank 𝕜 E = n) {ι : Type*} [fintype ι] [decidable_eq ι]
{V : ι → submodule 𝕜 E} (hV : submodule_is_internal V)
/-- Exhibit a bijection between `fin n` and the index set of a certain basis of an `n`-dimensional
inner product space `E`. This should not be accessed directly, but only via the subsequent API. -/
@[irreducible] def direct_sum.submodule_is_internal.sigma_orthonormal_basis_index_equiv :
(Σ i, orthonormal_basis_index 𝕜 (V i)) ≃ fin n :=
let b := hV.collected_basis (λ i, std_orthonormal_basis 𝕜 (V i)) in
fintype.equiv_fin_of_card_eq $ (finite_dimensional.finrank_eq_card_basis b).symm.trans hn
/-- An `n`-dimensional `inner_product_space` equipped with a decomposition as an internal direct
sum has an orthonormal basis indexed by `fin n` and subordinate to that direct sum. -/
@[irreducible] def direct_sum.submodule_is_internal.subordinate_orthonormal_basis :
basis (fin n) 𝕜 E :=
(hV.collected_basis (λ i, std_orthonormal_basis 𝕜 (V i))).reindex
(hV.sigma_orthonormal_basis_index_equiv hn)
/-- An `n`-dimensional `inner_product_space` equipped with a decomposition as an internal direct
sum has an orthonormal basis indexed by `fin n` and subordinate to that direct sum. This function
provides the mapping by which it is subordinate. -/
def direct_sum.submodule_is_internal.subordinate_orthonormal_basis_index (a : fin n) : ι :=
((hV.sigma_orthonormal_basis_index_equiv hn).symm a).1
/-- The basis constructed in `orthogonal_family.subordinate_orthonormal_basis` is orthonormal. -/
lemma direct_sum.submodule_is_internal.subordinate_orthonormal_basis_orthonormal
(hV' : @orthogonal_family 𝕜 _ _ _ _ (λ i, V i) _ (λ i, (V i).subtypeₗᵢ)) :
orthonormal 𝕜 (hV.subordinate_orthonormal_basis hn) :=
begin
simp only [direct_sum.submodule_is_internal.subordinate_orthonormal_basis, basis.coe_reindex],
have : orthonormal 𝕜 (hV.collected_basis (λ i, std_orthonormal_basis 𝕜 (V i))) :=
hV.collected_basis_orthonormal hV' (λ i, std_orthonormal_basis_orthonormal 𝕜 (V i)),
exact this.comp _ (equiv.injective _),
end
/-- The basis constructed in `orthogonal_family.subordinate_orthonormal_basis` is subordinate to
the `orthogonal_family` in question. -/
lemma direct_sum.submodule_is_internal.subordinate_orthonormal_basis_subordinate (a : fin n) :
hV.subordinate_orthonormal_basis hn a ∈ V (hV.subordinate_orthonormal_basis_index hn a) :=
by simpa only [direct_sum.submodule_is_internal.subordinate_orthonormal_basis, basis.coe_reindex]
using hV.collected_basis_mem (λ i, std_orthonormal_basis 𝕜 (V i))
((hV.sigma_orthonormal_basis_index_equiv hn).symm a)
attribute [irreducible] direct_sum.submodule_is_internal.subordinate_orthonormal_basis_index
end subordinate_orthonormal_basis
end finite_dimensional
end orthonormal_basis
|
1cb2727643eb6c4cd65ae8bf65c26c479aa96928 | 59a4b050600ed7b3d5826a8478db0a9bdc190252 | /src/category_theory/opposites_2.lean | 8336abc1f643a2d5bcebf7e76aaf38d610eac7c8 | [] | no_license | rwbarton/lean-category-theory | f720268d800b62a25d69842ca7b5d27822f00652 | 00df814d463406b7a13a56f5dcda67758ba1b419 | refs/heads/master | 1,585,366,296,767 | 1,536,151,349,000 | 1,536,151,349,000 | 147,652,096 | 0 | 0 | null | 1,536,226,960,000 | 1,536,226,960,000 | null | UTF-8 | Lean | false | false | 527 | lean | import category_theory.opposites
namespace category_theory
universes u₁ v₁
-- def OppositeOpposite (C : Category) : Equivalence (Opposite (Opposite C)) C := sorry
-- PROJECT opposites preserve products, functors, slices.
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C]
include 𝒞
@[simp] lemma opop : @category_theory.opposite (Cᵒᵖ) (@category_theory.opposite C 𝒞) = 𝒞 :=
begin
tactic.unfreeze_local_instances,
cases 𝒞,
unfold category_theory.opposite,
congr,
end
end category_theory |
86f3b81eab79d6796d9f09b41a433157f1c8e508 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/pfunctor/univariate/M_auto.lean | fefaaac49b6ec54a9331f1c52ea624a253fd5620 | [] | 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 | 17,363 | lean | /-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.pfunctor.univariate.basic
import Mathlib.PostPort
universes u l w u_1
namespace Mathlib
/-!
# M-types
M types are potentially infinite tree-like structures. They are defined
as the greatest fixpoint of a polynomial functor.
-/
namespace pfunctor
namespace approx
/-- `cofix_a F n` is an `n` level approximation of a M-type -/
inductive cofix_a (F : pfunctor) : ℕ → Type u where
| continue : cofix_a F 0
| intro : {n : ℕ} → (a : A F) → (B F a → cofix_a F n) → cofix_a F (Nat.succ n)
/-- default inhabitant of `cofix_a` -/
protected def cofix_a.default (F : pfunctor) [Inhabited (A F)] (n : ℕ) : cofix_a F n := sorry
protected instance cofix_a.inhabited (F : pfunctor) [Inhabited (A F)] {n : ℕ} :
Inhabited (cofix_a F n) :=
{ default := cofix_a.default F n }
theorem cofix_a_eq_zero (F : pfunctor) (x : cofix_a F 0) (y : cofix_a F 0) : x = y := sorry
/--
The label of the root of the tree for a non-trivial
approximation of the cofix of a pfunctor.
-/
def head' {F : pfunctor} {n : ℕ} : cofix_a F (Nat.succ n) → A F := sorry
/-- for a non-trivial approximation, return all the subtrees of the root -/
def children' {F : pfunctor} {n : ℕ} (x : cofix_a F (Nat.succ n)) : B F (head' x) → cofix_a F n :=
sorry
theorem approx_eta {F : pfunctor} {n : ℕ} (x : cofix_a F (n + 1)) :
x = cofix_a.intro (head' x) (children' x) :=
sorry
/-- Relation between two approximations of the cofix of a pfunctor that state they both contain the same
data until one of them is truncated -/
inductive agree {F : pfunctor} : {n : ℕ} → cofix_a F n → cofix_a F (n + 1) → Prop where
| continue : ∀ (x : cofix_a F 0) (y : cofix_a F 1), agree x y
| intro :
∀ {n : ℕ} {a : A F} (x : B F a → cofix_a F n) (x' : B F a → cofix_a F (n + 1)),
(∀ (i : B F a), agree (x i) (x' i)) → agree (cofix_a.intro a x) (cofix_a.intro a x')
/--
Given an infinite series of approximations `approx`,
`all_agree approx` states that they are all consistent with each other.
-/
def all_agree {F : pfunctor} (x : (n : ℕ) → cofix_a F n) := ∀ (n : ℕ), agree (x n) (x (Nat.succ n))
@[simp] theorem agree_trival {F : pfunctor} {x : cofix_a F 0} {y : cofix_a F 1} : agree x y :=
agree.continue x y
theorem agree_children {F : pfunctor} {n : ℕ} (x : cofix_a F (Nat.succ n))
(y : cofix_a F (Nat.succ n + 1)) {i : B F (head' x)} {j : B F (head' y)} (h₀ : i == j)
(h₁ : agree x y) : agree (children' x i) (children' y j) :=
sorry
/-- `truncate a` turns `a` into a more limited approximation -/
def truncate {F : pfunctor} {n : ℕ} : cofix_a F (n + 1) → cofix_a F n := sorry
theorem truncate_eq_of_agree {F : pfunctor} {n : ℕ} (x : cofix_a F n) (y : cofix_a F (Nat.succ n))
(h : agree x y) : truncate y = x :=
sorry
/-- `s_corec f i n` creates an approximation of height `n`
of the final coalgebra of `f` -/
def s_corec {F : pfunctor} {X : Type w} (f : X → obj F X) (i : X) (n : ℕ) : cofix_a F n := sorry
theorem P_corec {F : pfunctor} {X : Type w} (f : X → obj F X) (i : X) (n : ℕ) :
agree (s_corec f i n) (s_corec f i (Nat.succ n)) :=
sorry
/-- `path F` provides indices to access internal nodes in `corec F` -/
def path (F : pfunctor) := List (Idx F)
protected instance path.inhabited {F : pfunctor} : Inhabited (path F) := { default := [] }
protected instance cofix_a.subsingleton {F : pfunctor} : subsingleton (cofix_a F 0) :=
subsingleton.intro
fun (a b : cofix_a F 0) =>
cofix_a.cases_on a
(fun (a_1 : 0 = 0) (H_2 : a == cofix_a.continue) =>
Eq._oldrec
(cofix_a.cases_on b
(fun (a : 0 = 0) (H_2 : b == cofix_a.continue) =>
Eq._oldrec (Eq.refl cofix_a.continue) (Eq.symm (eq_of_heq H_2)))
(fun {b_n : ℕ} (b_a : A F) (b_ᾰ : B F b_a → cofix_a F b_n) (a : 0 = Nat.succ b_n) =>
nat.no_confusion a)
(Eq.refl 0) (HEq.refl b))
(Eq.symm (eq_of_heq H_2)))
(fun {a_n : ℕ} (a_a : A F) (a_ᾰ : B F a_a → cofix_a F a_n) (a_1 : 0 = Nat.succ a_n) =>
nat.no_confusion a_1)
(Eq.refl 0) (HEq.refl a)
theorem head_succ' {F : pfunctor} (n : ℕ) (m : ℕ) (x : (n : ℕ) → cofix_a F n)
(Hconsistent : all_agree x) : head' (x (Nat.succ n)) = head' (x (Nat.succ m)) :=
sorry
end approx
/-- Internal definition for `M`. It is needed to avoid name clashes
between `M.mk` and `M.cases_on` and the declarations generated for
the structure -/
structure M_intl (F : pfunctor) where
approx : (n : ℕ) → approx.cofix_a F n
consistent : approx.all_agree approx
/-- For polynomial functor `F`, `M F` is its final coalgebra -/
def M (F : pfunctor) := M_intl F
theorem M.default_consistent (F : pfunctor) [Inhabited (A F)] (n : ℕ) :
approx.agree Inhabited.default Inhabited.default :=
sorry
protected instance M.inhabited (F : pfunctor) [Inhabited (A F)] : Inhabited (M F) :=
{ default := M_intl.mk (fun (n : ℕ) => Inhabited.default) (M.default_consistent F) }
protected instance M_intl.inhabited (F : pfunctor) [Inhabited (A F)] : Inhabited (M_intl F) :=
(fun (this : Inhabited (M F)) => this) (M.inhabited F)
namespace M
theorem ext' (F : pfunctor) (x : M F) (y : M F)
(H : ∀ (i : ℕ), M_intl.approx x i = M_intl.approx y i) : x = y :=
sorry
/-- Corecursor for the M-type defined by `F`. -/
protected def corec {F : pfunctor} {X : Type u_1} (f : X → obj F X) (i : X) : M F :=
M_intl.mk (approx.s_corec f i) (approx.P_corec f i)
/-- given a tree generated by `F`, `head` gives us the first piece of data
it contains -/
def head {F : pfunctor} (x : M F) : A F := approx.head' (M_intl.approx x 1)
/-- return all the subtrees of the root of a tree `x : M F` -/
def children {F : pfunctor} (x : M F) (i : B F (head x)) : M F :=
M_intl.mk (fun (n : ℕ) => approx.children' (M_intl.approx x (Nat.succ n)) (cast sorry i)) sorry
/-- select a subtree using a `i : F.Idx` or return an arbitrary tree if
`i` designates no subtree of `x` -/
def ichildren {F : pfunctor} [Inhabited (M F)] [DecidableEq (A F)] (i : Idx F) (x : M F) : M F :=
dite (sigma.fst i = head x)
(fun (H' : sigma.fst i = head x) => children x (cast sorry (sigma.snd i)))
fun (H' : ¬sigma.fst i = head x) => Inhabited.default
theorem head_succ {F : pfunctor} (n : ℕ) (m : ℕ) (x : M F) :
approx.head' (M_intl.approx x (Nat.succ n)) = approx.head' (M_intl.approx x (Nat.succ m)) :=
approx.head_succ' n m (M_intl.approx x) (M_intl.consistent x)
theorem head_eq_head' {F : pfunctor} (x : M F) (n : ℕ) :
head x = approx.head' (M_intl.approx x (n + 1)) :=
sorry
theorem head'_eq_head {F : pfunctor} (x : M F) (n : ℕ) :
approx.head' (M_intl.approx x (n + 1)) = head x :=
sorry
theorem truncate_approx {F : pfunctor} (x : M F) (n : ℕ) :
approx.truncate (M_intl.approx x (n + 1)) = M_intl.approx x n :=
approx.truncate_eq_of_agree (M_intl.approx x n) (M_intl.approx x (n + 1)) (M_intl.consistent x n)
/-- unfold an M-type -/
def dest {F : pfunctor} : M F → obj F (M F) := sorry
namespace approx
/-- generates the approximations needed for `M.mk` -/
protected def s_mk {F : pfunctor} (x : obj F (M F)) (n : ℕ) : approx.cofix_a F n := sorry
protected theorem P_mk {F : pfunctor} (x : obj F (M F)) : approx.all_agree (approx.s_mk x) := sorry
end approx
/-- constructor for M-types -/
protected def mk {F : pfunctor} (x : obj F (M F)) : M F := M_intl.mk (approx.s_mk x) (approx.P_mk x)
/-- `agree' n` relates two trees of type `M F` that
are the same up to dept `n` -/
inductive agree' {F : pfunctor} : ℕ → M F → M F → Prop where
| trivial : ∀ (x y : M F), agree' 0 x y
| step :
∀ {n : ℕ} {a : A F} (x y : B F a → M F) {x' y' : M F},
x' = M.mk (sigma.mk a x) →
y' = M.mk (sigma.mk a y) → (∀ (i : B F a), agree' n (x i) (y i)) → agree' (Nat.succ n) x' y'
@[simp] theorem dest_mk {F : pfunctor} (x : obj F (M F)) : dest (M.mk x) = x := sorry
@[simp] theorem mk_dest {F : pfunctor} (x : M F) : M.mk (dest x) = x := sorry
theorem mk_inj {F : pfunctor} {x : obj F (M F)} {y : obj F (M F)} (h : M.mk x = M.mk y) : x = y :=
eq.mpr (id (Eq._oldrec (Eq.refl (x = y)) (Eq.symm (dest_mk x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (dest (M.mk x) = y)) h))
(eq.mpr (id (Eq._oldrec (Eq.refl (dest (M.mk y) = y)) (dest_mk y))) (Eq.refl y)))
/-- destructor for M-types -/
protected def cases {F : pfunctor} {r : M F → Sort w} (f : (x : obj F (M F)) → r (M.mk x))
(x : M F) : r x :=
(fun (this : r (M.mk (dest x))) => eq.mpr sorry this) (f (dest x))
/-- destructor for M-types -/
protected def cases_on {F : pfunctor} {r : M F → Sort w} (x : M F)
(f : (x : obj F (M F)) → r (M.mk x)) : r x :=
M.cases f x
/-- destructor for M-types, similar to `cases_on` but also
gives access directly to the root and subtrees on an M-type -/
protected def cases_on' {F : pfunctor} {r : M F → Sort w} (x : M F)
(f : (a : A F) → (f : B F a → M F) → r (M.mk (sigma.mk a f))) : r x :=
M.cases_on x fun (_x : obj F (M F)) => sorry
theorem approx_mk {F : pfunctor} (a : A F) (f : B F a → M F) (i : ℕ) :
M_intl.approx (M.mk (sigma.mk a f)) (Nat.succ i) =
approx.cofix_a.intro a fun (j : B F a) => M_intl.approx (f j) i :=
rfl
@[simp] theorem agree'_refl {F : pfunctor} {n : ℕ} (x : M F) : agree' n x x := sorry
theorem agree_iff_agree' {F : pfunctor} {n : ℕ} (x : M F) (y : M F) :
approx.agree (M_intl.approx x n) (M_intl.approx y (n + 1)) ↔ agree' n x y :=
sorry
@[simp] theorem cases_mk {F : pfunctor} {r : M F → Sort u_1} (x : obj F (M F))
(f : (x : obj F (M F)) → r (M.mk x)) : M.cases f (M.mk x) = f x :=
sorry
@[simp] theorem cases_on_mk {F : pfunctor} {r : M F → Sort u_1} (x : obj F (M F))
(f : (x : obj F (M F)) → r (M.mk x)) : M.cases_on (M.mk x) f = f x :=
cases_mk x f
@[simp] theorem cases_on_mk' {F : pfunctor} {r : M F → Sort u_1} {a : A F} (x : B F a → M F)
(f : (a : A F) → (f : B F a → M F) → r (M.mk (sigma.mk a f))) :
M.cases_on' (M.mk (sigma.mk a x)) f = f a x :=
cases_mk (sigma.mk a x) fun (_x : obj F (M F)) => cases_on'._match_1 f _x
/-- `is_path p x` tells us if `p` is a valid path through `x` -/
inductive is_path {F : pfunctor} : approx.path F → M F → Prop where
| nil : ∀ (x : M F), is_path [] x
| cons :
∀ (xs : approx.path F) {a : A F} (x : M F) (f : B F a → M F) (i : B F a),
x = M.mk (sigma.mk a f) → is_path xs (f i) → is_path (sigma.mk a i :: xs) x
theorem is_path_cons {F : pfunctor} {xs : approx.path F} {a : A F} {a' : A F} {f : B F a → M F}
{i : B F a'} (h : is_path (sigma.mk a' i :: xs) (M.mk (sigma.mk a f))) : a = a' :=
sorry
theorem is_path_cons' {F : pfunctor} {xs : approx.path F} {a : A F} {f : B F a → M F} {i : B F a}
(h : is_path (sigma.mk a i :: xs) (M.mk (sigma.mk a f))) : is_path xs (f i) :=
sorry
/-- follow a path through a value of `M F` and return the subtree
found at the end of the path if it is a valid path for that value and
return a default tree -/
def isubtree {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)] : approx.path F → M F → M F :=
sorry
/-- similar to `isubtree` but returns the data at the end of the path instead
of the whole subtree -/
def iselect {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)] (ps : approx.path F) : M F → A F :=
fun (x : M F) => head (isubtree ps x)
theorem iselect_eq_default {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)] (ps : approx.path F)
(x : M F) (h : ¬is_path ps x) : iselect ps x = head Inhabited.default :=
sorry
@[simp] theorem head_mk {F : pfunctor} (x : obj F (M F)) : head (M.mk x) = sigma.fst x := sorry
theorem children_mk {F : pfunctor} {a : A F} (x : B F a → M F)
(i : B F (head (M.mk (sigma.mk a x)))) :
children (M.mk (sigma.mk a x)) i =
x
(cast
(eq.mpr
(id
(Eq._oldrec (Eq.refl (B F (head (M.mk (sigma.mk a x))) = B F a))
(head_mk (sigma.mk a x))))
(Eq.refl (B F (sigma.fst (sigma.mk a x)))))
i) :=
sorry
@[simp] theorem ichildren_mk {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)] (x : obj F (M F))
(i : Idx F) : ichildren i (M.mk x) = obj.iget x i :=
sorry
@[simp] theorem isubtree_cons {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)]
(ps : approx.path F) {a : A F} (f : B F a → M F) {i : B F a} :
isubtree (sigma.mk a i :: ps) (M.mk (sigma.mk a f)) = isubtree ps (f i) :=
sorry
@[simp] theorem iselect_nil {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)] {a : A F}
(f : B F a → M F) : iselect [] (M.mk (sigma.mk a f)) = a :=
Eq.refl (iselect [] (M.mk (sigma.mk a f)))
@[simp] theorem iselect_cons {F : pfunctor} [DecidableEq (A F)] [Inhabited (M F)]
(ps : approx.path F) {a : A F} (f : B F a → M F) {i : B F a} :
iselect (sigma.mk a i :: ps) (M.mk (sigma.mk a f)) = iselect ps (f i) :=
sorry
theorem corec_def {F : pfunctor} {X : Type u} (f : X → obj F X) (x₀ : X) :
M.corec f x₀ = M.mk (M.corec f <$> f x₀) :=
sorry
theorem ext_aux {F : pfunctor} [Inhabited (M F)] [DecidableEq (A F)] {n : ℕ} (x : M F) (y : M F)
(z : M F) (hx : agree' n z x) (hy : agree' n z y)
(hrec : ∀ (ps : approx.path F), n = list.length ps → iselect ps x = iselect ps y) :
M_intl.approx x (n + 1) = M_intl.approx y (n + 1) :=
sorry
theorem ext {F : pfunctor} [Inhabited (M F)] (x : M F) (y : M F)
(H : ∀ (ps : approx.path F), iselect ps x = iselect ps y) : x = y :=
sorry
/-- Bisimulation is the standard proof technique for equality between
infinite tree-like structures -/
structure is_bisimulation {F : pfunctor} (R : M F → M F → Prop) where
head :
∀ {a a' : A F} {f : B F a → M F} {f' : B F a' → M F},
R (M.mk (sigma.mk a f)) (M.mk (sigma.mk a' f')) → a = a'
tail :
∀ {a : A F} {f f' : B F a → M F},
R (M.mk (sigma.mk a f)) (M.mk (sigma.mk a f')) → ∀ (i : B F a), R (f i) (f' i)
theorem nth_of_bisim {F : pfunctor} (R : M F → M F → Prop) [Inhabited (M F)]
(bisim : is_bisimulation R) (s₁ : M F) (s₂ : M F) (ps : approx.path F) :
R s₁ s₂ →
is_path ps s₁ ∨ is_path ps s₂ →
iselect ps s₁ = iselect ps s₂ ∧
∃ (a : A F),
∃ (f : B F a → M F),
∃ (f' : B F a → M F),
isubtree ps s₁ = M.mk (sigma.mk a f) ∧
isubtree ps s₂ = M.mk (sigma.mk a f') ∧ ∀ (i : B F a), R (f i) (f' i) :=
sorry
theorem eq_of_bisim {F : pfunctor} (R : M F → M F → Prop) [Nonempty (M F)]
(bisim : is_bisimulation R) (s₁ : M F) (s₂ : M F) : R s₁ s₂ → s₁ = s₂ :=
sorry
/-- corecursor for `M F` with swapped arguments -/
def corec_on {F : pfunctor} {X : Type u_1} (x₀ : X) (f : X → obj F X) : M F := M.corec f x₀
theorem dest_corec {P : pfunctor} {α : Type u} (g : α → obj P α) (x : α) :
dest (M.corec g x) = M.corec g <$> g x :=
sorry
theorem bisim {P : pfunctor} (R : M P → M P → Prop)
(h :
∀ (x y : M P),
R x y →
∃ (a : A P),
∃ (f : B P a → M P),
∃ (f' : B P a → M P),
dest x = sigma.mk a f ∧ dest y = sigma.mk a f' ∧ ∀ (i : B P a), R (f i) (f' i))
(x : M P) (y : M P) : R x y → x = y :=
sorry
theorem bisim' {P : pfunctor} {α : Type u_1} (Q : α → Prop) (u : α → M P) (v : α → M P)
(h :
∀ (x : α),
Q x →
∃ (a : A P),
∃ (f : B P a → M P),
∃ (f' : B P a → M P),
dest (u x) = sigma.mk a f ∧
dest (v x) = sigma.mk a f' ∧
∀ (i : B P a), ∃ (x' : α), Q x' ∧ f i = u x' ∧ f' i = v x')
(x : α) : Q x → u x = v x :=
sorry
-- for the record, show M_bisim follows from _bisim'
theorem bisim_equiv {P : pfunctor} (R : M P → M P → Prop)
(h :
∀ (x y : M P),
R x y →
∃ (a : A P),
∃ (f : B P a → M P),
∃ (f' : B P a → M P),
dest x = sigma.mk a f ∧ dest y = sigma.mk a f' ∧ ∀ (i : B P a), R (f i) (f' i))
(x : M P) (y : M P) : R x y → x = y :=
sorry
theorem corec_unique {P : pfunctor} {α : Type u} (g : α → obj P α) (f : α → M P)
(hyp : ∀ (x : α), dest (f x) = f <$> g x) : f = M.corec g :=
sorry
/-- corecursor where the state of the computation can be sent downstream
in the form of a recursive call -/
def corec₁ {P : pfunctor} {α : Type u} (F : (X : Type u) → (α → X) → α → obj P X) : α → M P :=
M.corec (F α id)
/-- corecursor where it is possible to return a fully formed value at any point
of the computation -/
def corec' {P : pfunctor} {α : Type u} (F : {X : Type u} → (α → X) → α → M P ⊕ obj P X) (x : α) :
M P :=
corec₁
(fun (X : Type u) (rec : M P ⊕ α → X) (a : M P ⊕ α) =>
let y : M P ⊕ obj P X := a >>= F (rec ∘ sum.inr);
sorry)
(sum.inr x)
end Mathlib |
0e43bc9a00371538730520116cac821ead99164e | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/tactic/omega/eq_elim.lean | c002bfaa78dfde922e4264c6cac2a3a8dd710571 | [
"Apache-2.0"
] | permissive | roro47/mathlib | 761fdc002aef92f77818f3fef06bf6ec6fc1a28e | 80aa7d52537571a2ca62a3fdf71c9533a09422cf | refs/heads/master | 1,599,656,410,625 | 1,573,649,488,000 | 1,573,649,488,000 | 221,452,951 | 0 | 0 | Apache-2.0 | 1,573,647,693,000 | 1,573,647,692,000 | null | UTF-8 | Lean | false | false | 14,477 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
Correctness lemmas for equality elimination.
See 5.5 of http://www.decision-procedures.org/ for details.
-/
import tactic.omega.clause
open list.func
namespace omega
def symdiv (i j : int) : int :=
if (2 * (i % j)) < j
then i / j
else (i / j) + 1
def symmod (i j : int) : int :=
if (2 * (i % j)) < j
then i % j
else (i % j) - j
lemma symmod_add_one_self {i : int} :
0 < i → symmod i (i+1) = -1 :=
begin
intro h1,
unfold symmod,
rw [int.mod_eq_of_lt (le_of_lt h1) (lt_add_one _), if_neg],
simp only [add_comm, add_neg_cancel_left,
neg_add_rev, sub_eq_add_neg],
have h2 : 2 * i = (1 + 1) * i := rfl,
simpa only [h2, add_mul, one_mul,
add_lt_add_iff_left, not_lt] using h1
end
lemma mul_symdiv_eq {i j : int} :
j * (symdiv i j) = i - (symmod i j) :=
begin
unfold symdiv, unfold symmod,
by_cases h1 : (2 * (i % j)) < j,
{ repeat {rw if_pos h1},
rw [int.mod_def, sub_sub_cancel] },
{ repeat {rw if_neg h1},
rw [int.mod_def, sub_sub, sub_sub_cancel,
mul_add, mul_one] }
end
lemma symmod_eq {i j : int} :
symmod i j = i - j * (symdiv i j) :=
by rw [mul_symdiv_eq, sub_sub_cancel]
/- (sgm v b as n) is the new value assigned to the nth variable
after a single step of equality elimination using valuation v,
term ⟨b, as⟩, and variable index n. If v satisfies the initial
constraint set, then (v ⟨n ↦ sgm v b as n⟩) satisfies the new
constraint set after equality elimination. -/
def sgm (v : nat → int) (b : int) (as : list int) (n : nat) :=
let a_n : int := get n as in
let m : int := a_n + 1 in
((symmod b m) + (coeffs.val v (as.map (λ x, symmod x m)))) / m
open_locale list.func
def rhs : nat → int → list int → term
| n b as :=
let m := get n as + 1 in
⟨(symmod b m), (as.map (λ x, symmod x m)) {n ↦ -m}⟩
lemma rhs_correct_aux {v : nat → int} {m : int} {as : list int} :
∀ {k}, ∃ d, (m * d +
coeffs.val_between v (as.map (λ (x : ℤ), symmod x m)) 0 k =
coeffs.val_between v as 0 k)
| 0 :=
begin
existsi (0 : int),
simp only [add_zero, mul_zero, coeffs.val_between]
end
| (k+1) :=
begin
simp only [zero_add, coeffs.val_between, list.map],
cases @rhs_correct_aux k with d h1, rw ← h1,
by_cases hk : k < as.length,
{ rw [get_map hk, symmod_eq, sub_mul],
existsi (d + (symdiv (get k as) m * v k)),
ring },
{ rw not_lt at hk,
repeat {rw get_eq_default_of_le},
existsi d,
rw add_assoc,
exact hk,
simp only [hk, list.length_map] }
end
open_locale omega
lemma rhs_correct {v : nat → int}
{b : int} {as : list int} (n : nat) :
0 < get n as →
0 = term.val v (b,as) →
v n = term.val (v ⟨n ↦ sgm v b as n⟩) (rhs n b as) :=
begin
intros h0 h1,
let a_n := get n as,
let m := a_n + 1,
have h3 : m ≠ 0,
{ apply ne_of_gt, apply lt_trans h0, simp [a_n, m] },
have h2 : m * (sgm v b as n) = (symmod b m) +
coeffs.val v (as.map (λ x, symmod x m)),
{ simp only [sgm, mul_comm m],
rw [int.div_mul_cancel],
have h4 : ∃ c, m * c + (symmod b (get n as + 1) +
coeffs.val v (as.map (λ (x : ℤ), symmod x m))) = term.val v (b,as),
{ have h5: ∃ d, m * d +
(coeffs.val v (as.map (λ x, symmod x m))) = coeffs.val v as,
{ simp only [coeffs.val, list.length_map], apply rhs_correct_aux },
cases h5 with d h5, rw symmod_eq,
existsi (symdiv b m + d),
unfold term.val, rw ← h5,
simp only [term.val, mul_add, add_mul, m, a_n],
ring },
cases h4 with c h4,
rw [dvd_add_iff_right (dvd_mul_right m c), h4, ← h1],
apply dvd_zero },
apply calc v n
= -(m * sgm v b as n) + (symmod b m) +
(coeffs.val_except n v (as.map (λ x, symmod x m))) :
begin
rw [h2, ← coeffs.val_except_add_eq n],
have hn : n < as.length,
{ by_contra hc, rw not_lt at hc,
rw (get_eq_default_of_le n hc) at h0,
cases h0 },
rw get_map hn,
simp only [a_n, m],
rw [add_comm, symmod_add_one_self h0],
ring
end
... = term.val (v⟨n↦sgm v b as n⟩) (rhs n b as) :
begin
unfold rhs, unfold term.val,
rw [← coeffs.val_except_add_eq n, get_set, update_eq],
have h2 : ∀ a b c : int, a + b + c = b + (c + a) := by {intros, ring},
rw (h2 (- _)),
apply fun_mono_2 rfl,
apply fun_mono_2,
{ rw coeffs.val_except_update_set },
{ simp only [m, a_n], ring }
end
end
def sym_sym (m b : int) : int :=
symdiv b m + symmod b m
def coeffs_reduce : nat → int → list int → term
| n b as :=
let a := get n as in
let m := a + 1 in
(sym_sym m b, (as.map (sym_sym m)) {n ↦ -a})
lemma coeffs_reduce_correct
{v : nat → int} {b : int} {as : list int} {n : nat} :
0 < get n as →
0 = term.val v (b,as) →
0 = term.val (v ⟨n ↦ sgm v b as n⟩) (coeffs_reduce n b as) :=
begin
intros h1 h2,
let a_n := get n as,
let m := a_n + 1,
have h3 : m ≠ 0,
{ apply ne_of_gt,
apply lt_trans h1,
simp only [m, lt_add_iff_pos_right] },
have h4 : 0 = (term.val (v⟨n↦sgm v b as n⟩) (coeffs_reduce n b as)) * m :=
calc 0
= term.val v (b,as) : h2
... = b + coeffs.val_except n v as
+ a_n * ((rhs n b as).val (v⟨n ↦ sgm v b as n⟩)) :
begin
unfold term.val,
rw [← coeffs.val_except_add_eq n, rhs_correct n h1 h2],
simp only [a_n, add_assoc],
end
... = -(m * a_n * sgm v b as n) + (b + a_n * (symmod b m)) +
(coeffs.val_except n v as +
a_n * coeffs.val_except n v (as.map (λ x, symmod x m))) :
begin
simp only [term.val, rhs, mul_add, m, a_n,
add_assoc, add_left_inj, add_comm, add_left_comm],
rw [← coeffs.val_except_add_eq n,
get_set, update_eq, mul_add],
apply fun_mono_2,
{ rw coeffs.val_except_eq_val_except
update_eq_of_ne (get_set_eq_of_ne _) },
simp only [m], ring,
end
... = -(m * a_n * sgm v b as n) + (b + a_n * (symmod b m))
+ coeffs.val_except n v (as.map (λ a_i, a_i + a_n * (symmod a_i m))) :
begin
apply fun_mono_2 rfl,
simp only [coeffs.val_except, mul_add],
repeat {rw ← coeffs.val_between_map_mul},
have h4 : ∀ {a b c d : int},
a + b + (c + d) = (a + c) + (b + d),
{ intros, ring }, rw h4,
have h5 : add as (list.map (has_mul.mul a_n)
(list.map (λ (x : ℤ), symmod x (get n as + 1)) as)) =
list.map (λ (a_i : ℤ), a_i + a_n * symmod a_i m) as,
{ rw [list.map_map, ←map_add_map],
apply fun_mono_2,
{ have h5 : (λ x : int, x) = id,
{ rw function.funext_iff, intro x, refl },
rw [h5, list.map_id] },
{ apply fun_mono_2 _ rfl,
rw function.funext_iff, intro x,
simp only [m] } },
simp only [list.length_map],
repeat { rw [← coeffs.val_between_add, h5] },
end
... = -(m * a_n * sgm v b as n) + (m * sym_sym m b)
+ coeffs.val_except n v (as.map (λ a_i, m * sym_sym m a_i)) :
begin
repeat {rw add_assoc}, apply fun_mono_2, refl,
rw ← add_assoc,
have h4 : ∀ (x : ℤ), x + a_n * symmod x m = m * sym_sym m x,
{ intro x, have h5 : a_n = m - 1,
{ simp only [m],
rw add_sub_cancel },
rw [h5, sub_mul, one_mul, add_sub,
add_comm, add_sub_assoc, ← mul_symdiv_eq],
simp only [sym_sym, mul_add, add_comm] },
apply fun_mono_2 (h4 _),
apply coeffs.val_except_eq_val_except; intros x h5, refl,
apply congr_arg,
apply fun_mono_2 _ rfl,
rw function.funext_iff,
apply h4
end
... = (-(a_n * sgm v b as n) + (sym_sym m b)
+ coeffs.val_except n v (as.map (sym_sym m))) * m :
begin
simp only [add_mul _ _ m],
apply fun_mono_2, ring,
simp only [coeffs.val_except, add_mul _ _ m],
apply fun_mono_2,
{ rw [mul_comm _ m, ← coeffs.val_between_map_mul, list.map_map] },
simp only [list.length_map, mul_comm _ m],
rw [← coeffs.val_between_map_mul, list.map_map]
end
... = (sym_sym m b + (coeffs.val_except n v (as.map (sym_sym m)) +
(-a_n * sgm v b as n))) * m : by ring
... = (term.val (v ⟨n ↦ sgm v b as n⟩) (coeffs_reduce n b as)) * m :
begin
simp only [coeffs_reduce, term.val, m, a_n],
rw [← coeffs.val_except_add_eq n,
coeffs.val_except_update_set, get_set, update_eq]
end,
rw [← int.mul_div_cancel (term.val _ _) h3, ← h4, int.zero_div]
end
-- Requires : t1.coeffs[m] = 1
def cancel (m : nat) (t1 t2 : term) : term :=
term.add (t1.mul (-(get m (t2.snd)))) t2
def subst (n : nat) (t1 t2 : term) : term :=
term.add (t1.mul (get n t2.snd)) (t2.fst, t2.snd {n ↦ 0})
lemma subst_correct {v : nat → int} {b : int}
{as : list int} {t : term} {n : nat} :
0 < get n as → 0 = term.val v (b,as) →
term.val v t = term.val (v ⟨n ↦ sgm v b as n⟩) (subst n (rhs n b as) t) :=
begin
intros h1 h2,
simp only [subst, term.val, term.val_add, term.val_mul],
rw ← rhs_correct _ h1 h2,
cases t with b' as',
simp only [term.val],
have h3 : coeffs.val (v ⟨n ↦ sgm v b as n⟩) (as' {n ↦ 0}) =
coeffs.val_except n v as',
{ rw [← coeffs.val_except_add_eq n, get_set,
zero_mul, add_zero, coeffs.val_except_update_set] },
rw [h3, ← coeffs.val_except_add_eq n], ring
end
/- The type of equality elimination rules. -/
@[derive has_reflect]
inductive ee : Type
| drop : ee
| nondiv : int → ee
| factor : int → ee
| neg : ee
| reduce : nat → ee
| cancel : nat → ee
namespace ee
def repr : ee → string
| drop := "↓"
| (nondiv i) := i.repr ++ "∤"
| (factor i) := "/" ++ i.repr
| neg := "-"
| (reduce n) := "≻" ++ n.repr
| (cancel n) := "+" ++ n.repr
instance has_repr : has_repr ee := ⟨repr⟩
meta instance has_to_format : has_to_format ee := ⟨λ x, x.repr⟩
end ee
def eq_elim : list ee → clause → clause
| [] ([], les) := ([],les)
| [] ((_::_), les) := ([],[])
| (_::_) ([], les) := ([],[])
| (ee.drop::es) ((eq::eqs), les) := eq_elim es (eqs, les)
| (ee.neg::es) ((eq::eqs), les) := eq_elim es ((eq.neg::eqs), les)
| (ee.nondiv i::es) ((b,as)::eqs, les) :=
if ¬(i ∣ b) ∧ (∀ x ∈ as, i ∣ x)
then ([],[⟨-1,[]⟩])
else ([],[])
| (ee.factor i::es) ((b,as)::eqs, les) :=
if (i ∣ b) ∧ (∀ x ∈ as, i ∣ x)
then eq_elim es ((term.div i (b,as)::eqs), les)
else ([],[])
| (ee.reduce n::es) ((b,as)::eqs, les) :=
if 0 < get n as
then let eq' := coeffs_reduce n b as in
let r := rhs n b as in
let eqs' := eqs.map (subst n r) in
let les' := les.map (subst n r) in
eq_elim es ((eq'::eqs'), les')
else ([],[])
| (ee.cancel m::es) ((eq::eqs), les) :=
eq_elim es ((eqs.map (cancel m eq)), (les.map (cancel m eq)))
open tactic
lemma sat_empty : clause.sat ([],[]) :=
⟨λ _,0, ⟨dec_trivial, dec_trivial⟩⟩
lemma sat_eq_elim :
∀ {es : list ee} {c : clause}, c.sat → (eq_elim es c).sat
| [] ([], les) h := h
| (e::_) ([], les) h :=
by {cases e; simp only [eq_elim]; apply sat_empty}
| [] ((_::_), les) h := sat_empty
| (ee.drop::es) ((eq::eqs), les) h1 :=
begin
apply (@sat_eq_elim es _ _),
rcases h1 with ⟨v,h1,h2⟩,
refine ⟨v, list.forall_mem_of_forall_mem_cons h1, h2⟩
end
| (ee.neg::es) ((eq::eqs), les) h1 :=
begin
simp only [eq_elim], apply sat_eq_elim,
cases h1 with v h1,
existsi v,
cases h1 with hl hr,
apply and.intro _ hr,
rw list.forall_mem_cons at *,
apply and.intro _ hl.right,
rw term.val_neg,
rw ← hl.left,
refl
end
| (ee.nondiv i::es) ((b,as)::eqs, les) h1 :=
begin
unfold eq_elim,
by_cases h2 : (¬i ∣ b ∧ ∀ (x : ℤ), x ∈ as → i ∣ x),
{ exfalso, cases h1 with v h1,
have h3 : 0 = b + coeffs.val v as := h1.left _ (or.inl rfl),
have h4 : i ∣ coeffs.val v as := coeffs.dvd_val h2.right,
have h5 : i ∣ b + coeffs.val v as := by { rw ← h3, apply dvd_zero },
rw ← dvd_add_iff_left h4 at h5, apply h2.left h5 },
rw if_neg h2, apply sat_empty
end
| (ee.factor i::es) ((b,as)::eqs, les) h1 :=
begin
simp only [eq_elim],
by_cases h2 : (i ∣ b) ∧ (∀ x ∈ as, i ∣ x),
{ rw if_pos h2, apply sat_eq_elim, cases h1 with v h1,
existsi v, cases h1 with h3 h4, apply and.intro _ h4,
rw list.forall_mem_cons at *, cases h3 with h5 h6,
apply and.intro _ h6,
rw [term.val_div h2.left h2.right, ← h5, int.zero_div] },
{ rw if_neg h2, apply sat_empty }
end
| (ee.reduce n::es) ((b,as)::eqs, les) h1 :=
begin
simp only [eq_elim],
by_cases h2 : 0 < get n as,
tactic.rotate 1,
{ rw if_neg h2, apply sat_empty },
rw if_pos h2,
apply sat_eq_elim,
cases h1 with v h1,
existsi v ⟨n ↦ sgm v b as n⟩,
cases h1 with h1 h3,
rw list.forall_mem_cons at h1,
cases h1 with h4 h5,
constructor,
{ rw list.forall_mem_cons,
constructor,
{ apply coeffs_reduce_correct h2 h4 },
{ intros x h6, rw list.mem_map at h6,
cases h6 with t h6, cases h6 with h6 h7,
rw [← h7, ← subst_correct h2 h4], apply h5 _ h6 } },
{ intros x h6, rw list.mem_map at h6,
cases h6 with t h6, cases h6 with h6 h7,
rw [← h7, ← subst_correct h2 h4], apply h3 _ h6 }
end
| (ee.cancel m::es) ((eq::eqs), les) h1 :=
begin
unfold eq_elim,
apply sat_eq_elim,
cases h1 with v h1,
existsi v,
cases h1 with h1 h2,
rw list.forall_mem_cons at h1, cases h1 with h1 h3,
constructor; intros t h4; rw list.mem_map at h4;
rcases h4 with ⟨s,h4,h5⟩; rw ← h5;
simp only [term.val_add, term.val_mul, cancel];
rw [← h1, mul_zero, zero_add],
{ apply h3 _ h4 },
{ apply h2 _ h4 }
end
lemma unsat_of_unsat_eq_elim (ee : list ee) (c : clause) :
(eq_elim ee c).unsat → c.unsat :=
by {intros h1 h2, apply h1, apply sat_eq_elim h2}
end omega
|
a67200de4571112afca391c2c040e46b0148d4a5 | 367134ba5a65885e863bdc4507601606690974c1 | /test/fresh_names.lean | 389d058ecf089e227bdcacedd494b1e0d2c951ae | [
"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 | 733 | lean | /-
Copyright (c) 2020 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jannis Limperg
-/
import tactic.fresh_names
open tactic
open native
example (n m o p : ℕ) : true :=
by do
[n, m, o, p] ← [`n, `m, `o, `p].mmap get_local,
[n_uname, m_uname, o_uname, p_uname] ← pure $
[n, m, o, p].map expr.local_uniq_name,
let renames := rb_map.of_list
[ (n_uname, [`p, `j]),
(m_uname, [`i, `k]),
(o_uname, [`i, `k]),
(p_uname, [`i]) ],
let reserved := name_set.of_list [`i_1],
rename_fresh renames reserved,
`[ guard_hyp p : ℕ ],
`[ guard_hyp i : ℕ ],
`[ guard_hyp k : ℕ ],
`[ guard_hyp i_2 : ℕ ],
exact `(trivial)
|
417f6ce7c0df4a9c356ffc1621c1790cbd3b363c | c5b07d17b3c9fb19e4b302465d237fd1d988c14f | /src/functors/family.lean | 8db6828c90732f750b47a5e086aa23b435e1d281 | [
"MIT"
] | permissive | skaslev/papers | acaec61602b28c33d6115e53913b2002136aa29b | f15b379f3c43bbd0a37ac7bb75f4278f7e901389 | refs/heads/master | 1,665,505,770,318 | 1,660,378,602,000 | 1,660,378,602,000 | 14,101,547 | 0 | 1 | MIT | 1,595,414,522,000 | 1,383,542,702,000 | Lean | UTF-8 | Lean | false | false | 3,365 | lean | import data.iso
-- Family of `X`s
-- `fam x` is a collection of `x` with length some cardinal number `y`
-- fam(x) = Σ y, xʸ
def fam (X : Type*) := Σ Y : Type*, Y → X
namespace fam
variable {X : Type*}
-- Families can be coerced both to type and a function.
-- For example we can write the polynomial functor as
--
-- def poly (c : fam Type*) (X : Type*) :=
-- Σ i : c, c i → X
--
-- instead of the more explicit version without coercions
--
-- def poly (c : fam Type*) (X : Type*) :=
-- Σ i : c.1, c.2 i → X
instance : has_coe_to_fun (fam X) :=
{ F := λ c, c.1 → X, coe := λ c, c.2 }
instance : has_coe_to_sort (fam X) :=
{ S := Type*, coe := λ c, c.1 }
def of {Y X} (f : Y → X) : fam X := ⟨Y, f⟩
def all_types : fam Type* := of id
def all_props : fam Prop := of id
-- "Car Salesman: *slaps `fam.of`* this bad boy can fit a whole `f : Type* → Type*` in it."
def of_iso {f : Type* → Type*} {A} : f A ≃ of f A :=
iso.id_iso
def fam_iso {c : fam Type*} {A} : c A ≃ of c A :=
iso.id_iso
def set_iso : fam Prop ≃ Σ X, set X :=
iso.id_iso
@[reducible, simp]
def mem (p : X) (c : fam X) := ∃ i : c, c i = p
instance : has_mem X (fam X) :=
⟨mem⟩
def empty : fam X := ⟨0, pempty.rec _⟩
def single {X} (x : X) : fam X := ⟨1, λ _, x⟩
instance : inhabited (fam X) :=
⟨empty⟩
def is_empty (c : fam X) := ∀ p : X, ¬p ∈ c
def is_complete (c : fam X) := ∀ p : X, p ∈ c
def empty_is_empty : is_empty (@empty X) :=
λ p ⟨i, _⟩, i.rec _
def add {A} (x : fam A) (y : fam A) : fam A :=
⟨x ⊕ y, λ i, sum.rec x y i⟩
def add_iso {A} (x y : fam A) : add x y ≃ x ⊕ y :=
iso.id_iso
def map {X Y} (f : X → Y) (x : fam X) : fam Y :=
⟨x.1, f ∘ x.2⟩
instance : functor fam :=
{ map := @map }
instance : is_lawful_functor fam :=
{ id_map := λ X c, by simp [functor.map, map],
comp_map := λ A B C g h c, by simp [functor.map, map] }
def pure {X} (x : X) : fam X :=
⟨unit, λ i, x⟩
def seq {A B : Type*} (f : fam (A → B)) (x : fam A) : fam B :=
⟨f.1 × x.1, λ i, (f i.1) (x i.2)⟩
def join {X} (c : fam (fam X)) : fam X :=
⟨Σ a, (c a).1, λ i, c i.1 i.2⟩
def bind {A B} (x : fam A) (f : A → fam B) : fam B :=
join $ f <$> x
instance : has_pure fam :=
⟨@pure⟩
instance : has_seq fam :=
⟨@seq⟩
instance : has_bind fam :=
⟨@bind⟩
instance : applicative fam :=
{ pure := @pure,
seq := @seq }
instance : monad fam :=
{ pure := @pure,
bind := @bind }
-- Surprisingly monad laws hold only up to isomorphism
-- https://youtu.be/RDuNIP4icKI?t=13192
-- local infixl >>= :55 := bind
-- def pure_bind {A B} (x : A) (f : A → fam B) : pure x >>= f = f x :=
-- begin
-- dsimp [pure, bind, functor.map, map, join],
-- sorry
-- end
-- def bind_assoc {A B C} (x : fam A) (f : A → fam B) (g : B → fam C) : x >>= f >>= g = x >>= λ x, f x >>= g :=
-- begin
-- dsimp [pure, bind, functor.map, map, join],
-- sorry
-- end
end fam
-- Direct and inverse image functors
namespace fam
def direct {X Y} (f : X → Y) : fam X → fam Y :=
λ xs, ⟨xs, f ∘ xs⟩
def inverse {X Y} (f : X → Y) : fam Y → fam X :=
λ ys, ⟨Σ' x j, f x = ys j, psigma.fst⟩
end fam
namespace set
def direct {X Y} (f : X → Y) : set X → set Y :=
λ xs y, ∃ x ∈ xs, f x = y
def inverse {X Y} (f : X → Y) : set Y → set X :=
λ ys, ys ∘ f
end set
|
02a1d57a40069804a0d5f879faffd55a89c900af | 94637389e03c919023691dcd05bd4411b1034aa5 | /src/assignments/assignment_8/assignment_8.lean | 24e4c6c1277ce341fe5f9bfe294b3b6e09e2173c | [] | no_license | kevinsullivan/complogic-s21 | 7c4eef2105abad899e46502270d9829d913e8afc | 99039501b770248c8ceb39890be5dfe129dc1082 | refs/heads/master | 1,682,985,669,944 | 1,621,126,241,000 | 1,621,126,241,000 | 335,706,272 | 0 | 38 | null | 1,618,325,669,000 | 1,612,374,118,000 | Lean | UTF-8 | Lean | false | false | 7,605 | lean | import ...inClassNotes.langs.bool_expr
import data.bool
/- 1. [20 points]
The proof that e1 && e2 is semantically equivalent to e2 && e1
in our little language of Boolean expressions *broke* when we
added state as an argument to the evaluation function (which we
needed when we added Boolean variables to our language). Your
job here is to repair/evolve the initial proof, just below, in
light of these changes in the software about which it proves
that property. Hint: Be sure to add a state argument everywhere
one is needed. Here's the original proof. Just fix it here.
-/
example : ∀ (e1 e2 : bool_expr),
bool_eval (e1 ∧ e2) = bool_eval (e2 ∧ e1)
:=
begin
assume e1 e2,
simp [bool_eval],
cases (bool_eval e1),
cases (bool_eval e2),
apply rfl,
apply rfl,
cases (bool_eval e2),
repeat {apply rfl},
end
/- 2. [20 points]
An identity in Boolean algebra is that P → Q is equivalent
to ¬P || Q. We want to know that our language and semantics
correctly implement Boolean algebra. One way to improve our
confidence is to prove that the algebra we've implemented
has the properties we expect and require of Boolean algebra.
Hint: The following proposition captures this expectation.
Prove it.
A note to you: When trying to prove this proposition, I
got stuck. That was due to a subtle bug in my definition
of our Boolean expressions language. I used ¬ for not but
|| and && for and and or, thus mixing notations generally
used for logic (¬) and computation (&& and ||). It turns
out that the precedence levels don't work when you do
this, as && binds more tighly than ¬, meaning that ¬ P
∧ Q is read as ¬ (P ∧ Q). Oops! Good thing I tried to
prove something about our language! I fixed the notation
and was then able to push my proof through. As you gain
experience using verification tools and methods, you'll
find that they really do find bugs in code!
-/
example : ∀ (e1 e2 : bool_expr) (st: bool_var → bool),
bool_eval (¬e1 ∨ e2) st = bool_eval (e1 => e2) st :=
begin
-- your answer
end
/- 3. [40 points]
As mentioned (but not explained) in class, we can formalize the
semantics of a language not as a function from expressions (and
state) to values, but as a *relation* between expressions (and
state) and values. To this end, we need rules for proving that
an expression has a given value (in a given state).
Here, then, is a partial specification of the semantics of our
Boolean expression language in the form of an inductive type
family. Take a glance, then continue with the explanation below
and refer back to this definition as needed.
-/
open bool_expr
/-
We start by defining a predicate, bool_sem, with three arguments:
a state, and expression, and a Boolean value. Applying bool_sem to
such arguments (let's call them st, e, and b), yields a proposition,
(bool_sem st e b). This proposition asserts that in state st, the
expression, e (in our language), has as its semantic meaning the
Boolean value, b.
-/
inductive bool_sem : (bool_var → bool) → bool_expr → bool → Prop
/-
Such a proposition might or might not be true, of course. We now
define the rules for reasoning about when one is true. We give a
semantic rule for each form of expression in our language.
The first rule, lit_sem, says that if we're given a Boolean value,
b, an expression in our language, e, and a state, st, then the
three-tuple, (st, [b], b), is "in" our semantic relation. Be sure
you see why: For our language to mean what we want it to mean, a
literal expression, [b], better mean b, no matter the state, st.
-/
| lit_sem (b : bool) (e : bool_expr) (st : bool_var → bool) : bool_sem st [b] b
/-
The next rule says that if we're given a variable v, an expression
e, and a state, st, then the meaning of a variable expression is (st
v). This proof constructor is axiomatic: We are stating that this is
what we want expressions in our language to mean.
-/
| var_sem (v : bool_var) (e : bool_expr) (st : bool_var → bool) : bool_sem st [v] (st v)
/-
Finally, if e1 and e2 are expressions, st is a state, b1 and b2 are
bools, and the meaning of e1 in st is b1, and the meaning of e2 in st
is b2, then the meaning of (e1 ∧ e2) in st is the Boolean, b1 && b2.
-/
| and_sem : ∀ (e1 e2 : bool_expr) (st : bool_var → bool) (b1 b2 : bool),
bool_sem st e1 b1 → bool_sem st e2 b2 → bool_sem st (e1 ∧ e2) (b1 && b2)
/- 3A:
Extend this declarative/logical specification of the semantics of
our language with rules specifying the meaning of expressions formed
by ∨, ¬, and =>, respectively, and include comments like the ones just
above under each new constructor to explain what it specifies. Just
add your additional constructors to the preceding code in this file.
-/
/- 3B. Challenging. Extra credit for undergraduates. Required for
graduate students. Here you are asked to prove that for any two
expressions, e1 and e2, any state, st, and any Boolean value, v,
that the meaning of the expression, (e1 ∧ e2), in the state st,
in our language, is always the same as that of (e2 ∧ e1) in st.
(The order of the sub-expressions is reversed.)
We give you the statement of the conjecture to be proved, along
with a few hints:
Hint #1: You might have to rewrite an expression (band b1 b2),
i.e., (b1 && b2), as (b2 && b1) to make the proof go through.
Lean's libraries provide a theorem called bool.band_comm that
enables this rewriting. To do the rewriting, use the rw tactic
like this: rw bool.band_comm.
Hint #2: Don't forget: the "cases" tactic not only gives you
one case for each constructor of a value in your context but
*also* destructures it, assigning names to each of the values
that must have gone into forming that object. If you get stuck
at a point where you've got a proof object in your context
that seems like it contains information that would be useful
to you, destructure it using cases.
Hint #3: You will have to *apply* the rule for reasoning about
conjunction expressions, bool_sem.and_sem, to the right argument
values to construct a required proof term (to satisfy a subgoal).
You will have to begive the expression and state arguments, but
Lean should be able to infer the Boolean value arguments.
Hint #4: You win when you reduce a goal to one for which you
already have a proof. Then you can use the exact, assumption,
or trivial tactic to use that proof.
Hint #5: Don't forget that to prove a bi-implication, P ↔ Q,
you will have to give proofs in both directions. Applying
iff.intro, or just using the split tactic, will give you
the two subgoals to prove. I always celebrate when I get
half-way through, having solved one goal, only to quickly
sober up when I realize I have another whole goal to prove.
Happy news: The reverse proof is symmetrical with the one
in the forward direction, so once you have the first half
done, you're close to being finished. It doesn't always
work this way, but here we're lucky. Also, we've given
you both the proposition to be proved and the first few
"moves."
-/
#check bool.band_comm
example : ∀ (e1 e2 : bool_expr) (st : bool_var → bool) (b : bool),
bool_sem st (e1 ∧ e2) b ↔ bool_sem st (e2 ∧ e1) b :=
begin
intros,
split,
-- forward direction
assume h,
-- reverse direction
end
/- 4. [20 points]
Give a declarative semantics for our language or arithmetic
expressions equivalent to that of our operational semantics. Graduate
students, extra credit for undergraduates: prove that, given our
semantics, the meaning of e1 + e2 is the same as that of e2 + e1,
in any state.
-/
-- HERE |
8e02c455166e4f1751781c878a226d7d7a0e54c9 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/qexpr1.lean | cd854924148585151de69c65dc653f39a8e1d9ef | [
"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 | 595 | lean | open tactic
#check
λ (A : Type) (a b c d : A) (H1 : a = b) (H2 : c = b) (H3 : d = c),
have Hac : a = c, by do {
h ← get_local `H2,
hs ← mk_app `eq.symm [h],
x ← to_expr ```(eq.trans H1 %%hs),
exact x },
show a = d, by do {
x ← to_expr ```(
have aux : a = c, from Hac,
have c = d, by do { symmetry, assumption },
show a = d, by do {
get_local `Hac >>= clear,
get_local `H1 >>= clear,
trace "NESTED CALL:",
trace_state,
transitivity,
get_local `aux >>= exact,
assumption }),
trace "-----------",
trace_state,
exact x }
|
03f512520df53674320e86ffcc0b970c06a26f00 | abd85493667895c57a7507870867b28124b3998f | /src/topology/uniform_space/cauchy.lean | 37b62a041889390d7ca6dafd160f0ac50b97bcec | [
"Apache-2.0"
] | permissive | pechersky/mathlib | d56eef16bddb0bfc8bc552b05b7270aff5944393 | f1df14c2214ee114c9738e733efd5de174deb95d | refs/heads/master | 1,666,714,392,571 | 1,591,747,567,000 | 1,591,747,567,000 | 270,557,274 | 0 | 0 | Apache-2.0 | 1,591,597,975,000 | 1,591,597,974,000 | null | UTF-8 | Lean | false | false | 25,209 | 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.uniform_space.basic
import topology.bases
import data.set.intervals
/-!
# Theory of Cauchy filters in uniform spaces. Complete uniform spaces. Totally bounded subsets.
-/
universes u v
open filter topological_space set classical
open_locale classical
variables {α : Type u} {β : Type v} [uniform_space α]
open_locale uniformity topological_space
/-- A filter `f` is Cauchy if for every entourage `r`, there exists an
`s ∈ f` such that `s × s ⊆ r`. This is a generalization of Cauchy
sequences, because if `a : ℕ → α` then the filter of sets containing
cofinitely many of the `a n` is Cauchy iff `a` is a Cauchy sequence. -/
def cauchy (f : filter α) := f ≠ ⊥ ∧ filter.prod f f ≤ (𝓤 α)
/-- A set `s` is called *complete*, if any Cauchy filter `f` such that `s ∈ f`
has a limit in `s` (formally, it satisfies `f ≤ 𝓝 x` for some `x ∈ s`). -/
def is_complete (s : set α) := ∀f, cauchy f → f ≤ principal s → ∃x∈s, f ≤ 𝓝 x
lemma filter.has_basis.cauchy_iff {p : β → Prop} {s : β → set (α × α)} (h : (𝓤 α).has_basis p s)
{f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ i, p i → ∃ t ∈ f, ∀ x y ∈ t, (x, y) ∈ s i)) :=
and_congr iff.rfl $ (f.basis_sets.prod_self.le_basis_iff h).trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_iff' {f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, ∀ x y ∈ t, (x, y) ∈ s)) :=
(𝓤 α).basis_sets.cauchy_iff
lemma cauchy_iff {f : filter α} :
cauchy f ↔ (f ≠ ⊥ ∧ (∀ s ∈ 𝓤 α, ∃t∈f, (set.prod t t) ⊆ s)) :=
(𝓤 α).basis_sets.cauchy_iff.trans $
by simp only [subset_def, prod.forall, mem_prod_eq, and_imp, id]
lemma cauchy_map_iff {l : filter β} {f : β → α} :
cauchy (l.map f) ↔ (l ≠ ⊥ ∧ tendsto (λp:β×β, (f p.1, f p.2)) (l.prod l) (𝓤 α)) :=
by rw [cauchy, (≠), map_eq_bot_iff, prod_map_map_eq]; refl
lemma cauchy_downwards {f g : filter α} (h_c : cauchy f) (hg : g ≠ ⊥) (h_le : g ≤ f) : cauchy g :=
⟨hg, le_trans (filter.prod_mono h_le h_le) h_c.right⟩
lemma cauchy_nhds {a : α} : cauchy (𝓝 a) :=
⟨nhds_ne_bot,
calc filter.prod (𝓝 a) (𝓝 a) =
(𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set(α×α),
set.prod {y : α | (y, a) ∈ s} {y : α | (a, y) ∈ t})) : nhds_nhds_eq_uniformity_uniformity_prod
... ≤ (𝓤 α).lift' (λs:set (α×α), comp_rel 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_of_le hs $
principal_mono.mpr $
assume ⟨x, y⟩ ⟨(hx : (x, a) ∈ s), (hy : (a, y) ∈ s)⟩, ⟨a, hx, hy⟩
... ≤ 𝓤 α : comp_le_uniformity⟩
lemma cauchy_pure {a : α} : cauchy (pure a) :=
cauchy_downwards cauchy_nhds pure_ne_bot (pure_le_nhds a)
/-- The common part of the proofs of `le_nhds_of_cauchy_adhp` and
`sequentially_complete.le_nhds_of_seq_tendsto_nhds`: if for any entourage `s`
one can choose a set `t ∈ f` of diameter `s` such that it contains a point `y`
with `(x, y) ∈ s`, then `f` converges to `x`. -/
lemma le_nhds_of_cauchy_adhp_aux {f : filter α} {x : α}
(adhs : ∀ s ∈ 𝓤 α, ∃ t ∈ f, (set.prod t t ⊆ s) ∧ ∃ y, (y ∈ t) ∧ (x, y) ∈ s) :
f ≤ 𝓝 x :=
begin
-- Consider a neighborhood `s` of `x`
assume s hs,
-- Take an entourage twice smaller than `s`
rcases comp_mem_uniformity_sets (mem_nhds_uniformity_iff_right.1 hs) with ⟨U, U_mem, hU⟩,
-- Take a set `t ∈ f`, `t × t ⊆ U`, and a point `y ∈ t` such that `(x, y) ∈ U`
rcases adhs U U_mem with ⟨t, t_mem, ht, y, hy, hxy⟩,
apply mem_sets_of_superset t_mem,
-- Given a point `z ∈ t`, we have `(x, y) ∈ U` and `(y, z) ∈ t × t ⊆ U`, hence `z ∈ s`
exact (λ z hz, hU (prod_mk_mem_comp_rel hxy (ht $ mk_mem_prod hy hz)) rfl)
end
/-- If `x` is an adherent (cluster) point for a Cauchy filter `f`, then it is a limit point
for `f`. -/
lemma le_nhds_of_cauchy_adhp {f : filter α} {x : α} (hf : cauchy f)
(adhs : f ⊓ 𝓝 x ≠ ⊥) : f ≤ 𝓝 x :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
-- Take `t ∈ f` such that `t × t ⊆ s`.
rcases (cauchy_iff.1 hf).2 s hs with ⟨t, t_mem, ht⟩,
use [t, t_mem, ht],
exact (forall_sets_nonempty_iff_ne_bot.2 adhs _
(inter_mem_inf_sets t_mem (mem_nhds_left x hs)))
end
lemma le_nhds_iff_adhp_of_cauchy {f : filter α} {x : α} (hf : cauchy f) :
f ≤ 𝓝 x ↔ f ⊓ 𝓝 x ≠ ⊥ :=
⟨assume h, left_eq_inf.2 h ▸ hf.left, le_nhds_of_cauchy_adhp hf⟩
lemma cauchy_map [uniform_space β] {f : filter α} {m : α → β}
(hm : uniform_continuous m) (hf : cauchy f) : cauchy (map m f) :=
⟨have f ≠ ⊥, from hf.left, by simp; assumption,
calc filter.prod (map m f) (map m f) =
map (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_map_map_eq
... ≤ map (λp:α×α, (m p.1, m p.2)) (𝓤 α) : map_mono hf.right
... ≤ 𝓤 β : hm⟩
lemma cauchy_comap [uniform_space β] {f : filter β} {m : α → β}
(hm : comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) ≤ 𝓤 α)
(hf : cauchy f) (hb : comap m f ≠ ⊥) : cauchy (comap m f) :=
⟨hb,
calc filter.prod (comap m f) (comap m f) =
comap (λp:α×α, (m p.1, m p.2)) (filter.prod f f) : filter.prod_comap_comap_eq
... ≤ comap (λp:α×α, (m p.1, m p.2)) (𝓤 β) : comap_mono hf.right
... ≤ 𝓤 α : hm⟩
/-- Cauchy sequences. Usually defined on ℕ, but often it is also useful to say that a function
defined on ℝ is Cauchy at +∞ to deduce convergence. Therefore, we define it in a type class that
is general enough to cover both ℕ and ℝ, which are the main motivating examples. -/
def cauchy_seq [semilattice_sup β] (u : β → α) := cauchy (at_top.map u)
lemma cauchy_seq_of_tendsto_nhds [semilattice_sup β] [nonempty β] (f : β → α) {x}
(hx : tendsto f at_top (𝓝 x)) :
cauchy_seq f :=
cauchy_downwards cauchy_nhds (map_ne_bot at_top_ne_bot) hx
lemma cauchy_seq_iff_tendsto [nonempty β] [semilattice_sup β] {u : β → α} :
cauchy_seq u ↔ tendsto (prod.map u u) at_top (𝓤 α) :=
cauchy_map_iff.trans $ (and_iff_right at_top_ne_bot).trans $
by simp only [prod_at_top_at_top_eq, prod.map_def]
/-- If a Cauchy sequence has a convergent subsequence, then it converges. -/
lemma tendsto_nhds_of_cauchy_seq_of_subseq
[semilattice_sup β] {u : β → α} (hu : cauchy_seq u)
{ι : Type*} {f : ι → β} {p : filter ι} (hp : p ≠ ⊥)
(hf : tendsto f p at_top) {a : α} (ha : tendsto (λ i, u (f i)) p (𝓝 a)) :
tendsto u at_top (𝓝 a) :=
begin
apply le_nhds_of_cauchy_adhp hu,
rw ← bot_lt_iff_ne_bot,
have : ⊥ < map (λ i, u (f i)) p ⊓ 𝓝 a,
by { rw [bot_lt_iff_ne_bot, inf_of_le_left ha], exact map_ne_bot hp },
exact lt_of_lt_of_le this (inf_le_inf_right _ (map_mono hf))
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma filter.has_basis.cauchy_seq_iff {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (h : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀m n≥N, (u m, u n) ∈ s i :=
begin
rw [cauchy_seq_iff_tendsto, ← prod_at_top_at_top_eq],
refine (at_top_basis.prod_self.tendsto_iff h).trans _,
simp only [exists_prop, true_and, maps_to, preimage, subset_def, prod.forall,
mem_prod_eq, mem_set_of_eq, mem_Ici, and_imp, prod.map]
end
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma filter.has_basis.cauchy_seq_iff' {γ} [nonempty β] [semilattice_sup β] {u : β → α}
{p : γ → Prop} {s : γ → set (α × α)} (H : (𝓤 α).has_basis p s) :
cauchy_seq u ↔ ∀ i, p i → ∃N, ∀n≥N, (u n, u N) ∈ s i :=
begin
refine H.cauchy_seq_iff.trans ⟨λ h i hi, _, λ h i hi, _⟩,
{ exact (h i hi).imp (λ N hN n hn, hN n N hn (le_refl N)) },
{ rcases comp_symm_of_uniformity (H.mem_of_mem hi) with ⟨t, ht, ht', hts⟩,
rcases H.mem_iff.1 ht with ⟨j, hj, hjt⟩,
refine (h j hj).imp (λ N hN m n hm hn, hts ⟨u N, hjt _, ht' $ hjt _⟩),
{ exact hN m hm },
{ exact hN n hn } }
end
lemma cauchy_seq_of_controlled [semilattice_sup β] [nonempty β]
(U : β → set (α × α)) (hU : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
{f : β → α} (hf : ∀ {N m n : β}, N ≤ m → N ≤ n → (f m, f n) ∈ U N) :
cauchy_seq f :=
cauchy_seq_iff_tendsto.2
begin
assume s hs,
rw [mem_map, mem_at_top_sets],
cases hU s hs with N hN,
refine ⟨(N, N), λ mn hmn, _⟩,
cases mn with m n,
exact hN (hf hmn.1 hmn.2)
end
/-- A complete space is defined here using uniformities. A uniform space
is complete if every Cauchy filter converges. -/
class complete_space (α : Type u) [uniform_space α] : Prop :=
(complete : ∀{f:filter α}, cauchy f → ∃x, f ≤ 𝓝 x)
lemma complete_univ {α : Type u} [uniform_space α] [complete_space α] :
is_complete (univ : set α) :=
begin
assume f hf _,
rcases complete_space.complete hf with ⟨x, hx⟩,
exact ⟨x, mem_univ x, hx⟩
end
lemma cauchy_prod [uniform_space β] {f : filter α} {g : filter β} :
cauchy f → cauchy g → cauchy (filter.prod f g)
| ⟨f_proper, hf⟩ ⟨g_proper, hg⟩ := ⟨filter.prod_ne_bot.2 ⟨f_proper, g_proper⟩,
let p_α := λp:(α×β)×(α×β), (p.1.1, p.2.1), p_β := λp:(α×β)×(α×β), (p.1.2, p.2.2) in
suffices (f.prod f).comap p_α ⊓ (g.prod g).comap p_β ≤ (𝓤 α).comap p_α ⊓ (𝓤 β).comap p_β,
by simpa [uniformity_prod, filter.prod, filter.comap_inf, filter.comap_comap_comp, (∘),
inf_assoc, inf_comm, inf_left_comm],
inf_le_inf (filter.comap_mono hf) (filter.comap_mono hg)⟩
instance complete_space.prod [uniform_space β] [complete_space α] [complete_space β] :
complete_space (α × β) :=
{ complete := λ f hf,
let ⟨x1, hx1⟩ := complete_space.complete $ cauchy_map uniform_continuous_fst hf in
let ⟨x2, hx2⟩ := complete_space.complete $ cauchy_map uniform_continuous_snd hf in
⟨(x1, x2), by rw [nhds_prod_eq, filter.prod_def];
from filter.le_lift (λ s hs, filter.le_lift' $ λ t ht,
have H1 : prod.fst ⁻¹' s ∈ f.sets := hx1 hs,
have H2 : prod.snd ⁻¹' t ∈ f.sets := hx2 ht,
filter.inter_mem_sets H1 H2)⟩ }
/--If `univ` is complete, the space is a complete space -/
lemma complete_space_of_is_complete_univ (h : is_complete (univ : set α)) : complete_space α :=
⟨λ f hf, let ⟨x, _, hx⟩ := h f hf ((@principal_univ α).symm ▸ le_top) in ⟨x, hx⟩⟩
lemma complete_space_iff_is_complete_univ :
complete_space α ↔ is_complete (univ : set α) :=
⟨@complete_univ α _, complete_space_of_is_complete_univ⟩
lemma cauchy_iff_exists_le_nhds [complete_space α] {l : filter α} (hl : l ≠ ⊥) :
cauchy l ↔ (∃x, l ≤ 𝓝 x) :=
⟨complete_space.complete, assume ⟨x, hx⟩, cauchy_downwards cauchy_nhds hl hx⟩
lemma cauchy_map_iff_exists_tendsto [complete_space α] {l : filter β} {f : β → α}
(hl : l ≠ ⊥) : cauchy (l.map f) ↔ (∃x, tendsto f l (𝓝 x)) :=
cauchy_iff_exists_le_nhds (map_ne_bot hl)
/-- A Cauchy sequence in a complete space converges -/
theorem cauchy_seq_tendsto_of_complete [semilattice_sup β] [complete_space α]
{u : β → α} (H : cauchy_seq u) : ∃x, tendsto u at_top (𝓝 x) :=
complete_space.complete H
/-- If `K` is a complete subset, then any cauchy sequence in `K` converges to a point in `K` -/
lemma cauchy_seq_tendsto_of_is_complete [semilattice_sup β] {K : set α} (h₁ : is_complete K)
{u : β → α} (h₂ : ∀ n, u n ∈ K) (h₃ : cauchy_seq u) : ∃ v ∈ K, tendsto u at_top (𝓝 v) :=
h₁ _ h₃ $ le_principal_iff.2 $ mem_map_sets_iff.2 ⟨univ, univ_mem_sets,
by { simp only [image_univ], rintros _ ⟨n, rfl⟩, exact h₂ n }⟩
theorem cauchy.le_nhds_Lim [complete_space α] [nonempty α] {f : filter α} (hf : cauchy f) :
f ≤ 𝓝 (Lim f) :=
Lim_spec (complete_space.complete hf)
theorem cauchy_seq.tendsto_lim [semilattice_sup β] [complete_space α] [nonempty α] {u : β → α}
(h : cauchy_seq u) :
tendsto u at_top (𝓝 $ lim at_top u) :=
h.le_nhds_Lim
lemma is_complete_of_is_closed [complete_space α] {s : set α}
(h : is_closed s) : is_complete s :=
λ f cf fs, let ⟨x, hx⟩ := complete_space.complete cf in
⟨x, is_closed_iff_nhds.mp h x (ne_bot_of_le_ne_bot cf.left (le_inf hx fs)), hx⟩
/-- A set `s` is totally bounded if for every entourage `d` there is a finite
set of points `t` such that every element of `s` is `d`-near to some element of `t`. -/
def totally_bounded (s : set α) : Prop :=
∀d ∈ 𝓤 α, ∃t : set α, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d})
theorem totally_bounded_iff_subset {s : set α} : totally_bounded s ↔
∀d ∈ 𝓤 α, ∃t ⊆ s, finite t ∧ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}) :=
⟨λ H d hd, begin
rcases comp_symm_of_uniformity hd with ⟨r, hr, rs, rd⟩,
rcases H r hr with ⟨k, fk, ks⟩,
let u := {y ∈ k | ∃ x, x ∈ s ∧ (x, y) ∈ r},
let f : u → α := λ x, classical.some x.2.2,
have : ∀ x : u, f x ∈ s ∧ (f x, x.1) ∈ r := λ x, classical.some_spec x.2.2,
refine ⟨range f, _, _, _⟩,
{ exact range_subset_iff.2 (λ x, (this x).1) },
{ have : finite u := finite_subset fk (λ x h, h.1),
exact ⟨@set.fintype_range _ _ _ _ this.fintype⟩ },
{ intros x xs,
have := ks xs, simp at this,
rcases this with ⟨y, hy, xy⟩,
let z : coe_sort u := ⟨y, hy, x, xs, xy⟩,
exact mem_bUnion_iff.2 ⟨_, ⟨z, rfl⟩, rd $ mem_comp_rel.2 ⟨_, xy, rs (this z).2⟩⟩ }
end,
λ H d hd, let ⟨t, _, ht⟩ := H d hd in ⟨t, ht⟩⟩
lemma totally_bounded_subset {s₁ s₂ : set α} (hs : s₁ ⊆ s₂)
(h : totally_bounded s₂) : totally_bounded s₁ :=
assume d hd, let ⟨t, ht₁, ht₂⟩ := h d hd in ⟨t, ht₁, subset.trans hs ht₂⟩
lemma totally_bounded_empty : totally_bounded (∅ : set α) :=
λ d hd, ⟨∅, finite_empty, empty_subset _⟩
lemma totally_bounded_closure {s : set α} (h : totally_bounded s) :
totally_bounded (closure s) :=
assume t ht,
let ⟨t', ht', hct', htt'⟩ := mem_uniformity_is_closed ht, ⟨c, hcf, hc⟩ := h t' ht' in
⟨c, hcf,
calc closure s ⊆ closure (⋃ (y : α) (H : y ∈ c), {x : α | (x, y) ∈ t'}) : closure_mono hc
... = _ : closure_eq_of_is_closed $ is_closed_bUnion hcf $ assume i hi,
continuous_iff_is_closed.mp (continuous_id.prod_mk continuous_const) _ hct'
... ⊆ _ : bUnion_subset $ assume i hi, subset.trans (assume x, @htt' (x, i))
(subset_bUnion_of_mem hi)⟩
lemma totally_bounded_image [uniform_space β] {f : α → β} {s : set α}
(hf : uniform_continuous f) (hs : totally_bounded s) : totally_bounded (f '' s) :=
assume t ht,
have {p:α×α | (f p.1, f p.2) ∈ t} ∈ 𝓤 α,
from hf ht,
let ⟨c, hfc, hct⟩ := hs _ this in
⟨f '' c, finite_image f hfc,
begin
simp [image_subset_iff],
simp [subset_def] at hct,
intros x hx, simp,
exact hct x hx
end⟩
lemma cauchy_of_totally_bounded_of_ultrafilter {s : set α} {f : filter α}
(hs : totally_bounded s) (hf : is_ultrafilter f) (h : f ≤ principal s) : cauchy f :=
⟨hf.left, assume t ht,
let ⟨t', ht'₁, ht'_symm, ht'_t⟩ := comp_symm_of_uniformity ht in
let ⟨i, hi, hs_union⟩ := hs t' ht'₁ in
have (⋃y∈i, {x | (x,y) ∈ t'}) ∈ f.sets,
from mem_sets_of_superset (le_principal_iff.mp h) hs_union,
have ∃y∈i, {x | (x,y) ∈ t'} ∈ f.sets,
from mem_of_finite_Union_ultrafilter hf hi this,
let ⟨y, hy, hif⟩ := this in
have set.prod {x | (x,y) ∈ t'} {x | (x,y) ∈ t'} ⊆ comp_rel t' t',
from assume ⟨x₁, x₂⟩ ⟨(h₁ : (x₁, y) ∈ t'), (h₂ : (x₂, y) ∈ t')⟩,
⟨y, h₁, ht'_symm h₂⟩,
(filter.prod f f).sets_of_superset (prod_mem_prod hif hif) (subset.trans this ht'_t)⟩
lemma totally_bounded_iff_filter {s : set α} :
totally_bounded s ↔ (∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c) :=
⟨assume : totally_bounded s, assume f hf hs,
⟨ultrafilter_of f, ultrafilter_of_le,
cauchy_of_totally_bounded_of_ultrafilter this
(ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hs)⟩,
assume h : ∀f, f ≠ ⊥ → f ≤ principal s → ∃c ≤ f, cauchy c, assume d hd,
classical.by_contradiction $ assume hs,
have hd_cover : ∀{t:set α}, finite t → ¬ s ⊆ (⋃y∈t, {x | (x,y) ∈ d}),
by simpa using hs,
let
f := ⨅t:{t : set α // finite t}, principal (s \ (⋃y∈t.val, {x | (x,y) ∈ d})),
⟨a, ha⟩ := (@ne_empty_iff_nonempty α s).1
(assume h, hd_cover finite_empty $ h.symm ▸ empty_subset _)
in
have f ≠ ⊥,
from infi_ne_bot_of_directed ⟨a⟩
(assume ⟨t₁, ht₁⟩ ⟨t₂, ht₂⟩, ⟨⟨t₁ ∪ t₂, finite_union ht₁ ht₂⟩,
principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $
assume t, Union_subset_Union_const or.inl,
principal_mono.mpr $ diff_subset_diff_right $ Union_subset_Union $
assume t, Union_subset_Union_const or.inr⟩)
(assume ⟨t, ht⟩, by simp [diff_eq_empty]; exact hd_cover ht),
have f ≤ principal s, from infi_le_of_le ⟨∅, finite_empty⟩ $ by simp; exact subset.refl s,
let
⟨c, (hc₁ : c ≤ f), (hc₂ : cauchy c)⟩ := h f ‹f ≠ ⊥› this,
⟨m, hm, (hmd : set.prod m m ⊆ d)⟩ := (@mem_prod_same_iff α c d).mp $ hc₂.right hd
in
have c ≤ principal s, from le_trans ‹c ≤ f› this,
have m ∩ s ∈ c.sets, from inter_mem_sets hm $ le_principal_iff.mp this,
let ⟨y, hym, hys⟩ := nonempty_of_mem_sets hc₂.left this in
let ys := (⋃y'∈({y}:set α), {x | (x, y') ∈ d}) in
have m ⊆ ys,
from assume y' hy',
show y' ∈ (⋃y'∈({y}:set α), {x | (x, y') ∈ d}),
by simp; exact @hmd (y', y) ⟨hy', hym⟩,
have c ≤ principal (s - ys),
from le_trans hc₁ $ infi_le_of_le ⟨{y}, finite_singleton _⟩ $ le_refl _,
have (s - ys) ∩ (m ∩ s) ∈ c.sets,
from inter_mem_sets (le_principal_iff.mp this) ‹m ∩ s ∈ c.sets›,
have ∅ ∈ c.sets,
from c.sets_of_superset this $ assume x ⟨⟨hxs, hxys⟩, hxm, _⟩, hxys $ ‹m ⊆ ys› hxm,
hc₂.left $ empty_in_sets_eq_bot.mp this⟩
lemma totally_bounded_iff_ultrafilter {s : set α} :
totally_bounded s ↔ (∀f, is_ultrafilter f → f ≤ principal s → cauchy f) :=
⟨assume hs f, cauchy_of_totally_bounded_of_ultrafilter hs,
assume h, totally_bounded_iff_filter.mpr $ assume f hf hfs,
have cauchy (ultrafilter_of f),
from h (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs),
⟨ultrafilter_of f, ultrafilter_of_le, this⟩⟩
lemma compact_iff_totally_bounded_complete {s : set α} :
compact s ↔ totally_bounded s ∧ is_complete s :=
⟨λ hs, ⟨totally_bounded_iff_ultrafilter.2 (λ f hf1 hf2,
let ⟨x, xs, fx⟩ := compact_iff_ultrafilter_le_nhds.1 hs f hf1 hf2 in
cauchy_downwards (cauchy_nhds) (hf1.1) fx),
λ f fc fs,
let ⟨a, as, fa⟩ := hs f fc.1 fs in
⟨a, as, le_nhds_of_cauchy_adhp fc fa⟩⟩,
λ ⟨ht, hc⟩, compact_iff_ultrafilter_le_nhds.2
(λf hf hfs, hc _ (totally_bounded_iff_ultrafilter.1 ht _ hf hfs) hfs)⟩
@[priority 100] -- see Note [lower instance priority]
instance complete_of_compact {α : Type u} [uniform_space α] [compact_space α] : complete_space α :=
⟨λf hf, by simpa [principal_univ] using (compact_iff_totally_bounded_complete.1 compact_univ).2 f hf⟩
lemma compact_of_totally_bounded_is_closed [complete_space α] {s : set α}
(ht : totally_bounded s) (hc : is_closed s) : compact s :=
(@compact_iff_totally_bounded_complete α _ s).2 ⟨ht, is_complete_of_is_closed hc⟩
/-!
### Sequentially complete space
In this section we prove that a uniform space is complete provided that it is sequentially complete
(i.e., any Cauchy sequence converges) and its uniformity filter admits a countable generating set.
In particular, this applies to (e)metric spaces, see the files `topology/metric_space/emetric_space`
and `topology/metric_space/basic`.
More precisely, we assume that there is a sequence of entourages `U_n` such that any other
entourage includes one of `U_n`. Then any Cauchy filter `f` generates a decreasing sequence of
sets `s_n ∈ f` such that `s_n × s_n ⊆ U_n`. Choose a sequence `x_n∈s_n`. It is easy to show
that this is a Cauchy sequence. If this sequence converges to some `a`, then `f ≤ 𝓝 a`. -/
namespace sequentially_complete
variables {f : filter α} (hf : cauchy f) {U : ℕ → set (α × α)}
(U_mem : ∀ n, U n ∈ 𝓤 α) (U_le : ∀ s ∈ 𝓤 α, ∃ n, U n ⊆ s)
open set finset
noncomputable theory
/-- An auxiliary sequence of sets approximating a Cauchy filter. -/
def set_seq_aux (n : ℕ) : {s : set α // ∃ (_ : s ∈ f), s.prod s ⊆ U n } :=
indefinite_description _ $ (cauchy_iff.1 hf).2 (U n) (U_mem n)
/-- Given a Cauchy filter `f` and a sequence `U` of entourages, `set_seq` provides
a sequence of monotonically decreasing sets `s n ∈ f` such that `(s n).prod (s n) ⊆ U`. -/
def set_seq (n : ℕ) : set α := ⋂ m ∈ Iic n, (set_seq_aux hf U_mem m).val
lemma set_seq_mem (n : ℕ) : set_seq hf U_mem n ∈ f :=
Inter_mem_sets (finite_le_nat n) (λ m _, (set_seq_aux hf U_mem m).2.fst)
lemma set_seq_mono ⦃m n : ℕ⦄ (h : m ≤ n) : set_seq hf U_mem n ⊆ set_seq hf U_mem m :=
bInter_subset_bInter_left (λ k hk, le_trans hk h)
lemma set_seq_sub_aux (n : ℕ) : set_seq hf U_mem n ⊆ set_seq_aux hf U_mem n :=
bInter_subset_of_mem right_mem_Iic
lemma set_seq_prod_subset {N m n} (hm : N ≤ m) (hn : N ≤ n) :
(set_seq hf U_mem m).prod (set_seq hf U_mem n) ⊆ U N :=
begin
assume p hp,
refine (set_seq_aux hf U_mem N).2.snd ⟨_, _⟩;
apply set_seq_sub_aux,
exact set_seq_mono hf U_mem hm hp.1,
exact set_seq_mono hf U_mem hn hp.2
end
/-- A sequence of points such that `seq n ∈ set_seq n`. Here `set_seq` is a monotonically
decreasing sequence of sets `set_seq n ∈ f` with diameters controlled by a given sequence
of entourages. -/
def seq (n : ℕ) : α := some $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n)
lemma seq_mem (n : ℕ) : seq hf U_mem n ∈ set_seq hf U_mem n :=
some_spec $ nonempty_of_mem_sets hf.1 (set_seq_mem hf U_mem n)
lemma seq_pair_mem ⦃N m n : ℕ⦄ (hm : N ≤ m) (hn : N ≤ n) :
(seq hf U_mem m, seq hf U_mem n) ∈ U N :=
set_seq_prod_subset hf U_mem hm hn ⟨seq_mem hf U_mem m, seq_mem hf U_mem n⟩
include U_le
theorem seq_is_cauchy_seq : cauchy_seq $ seq hf U_mem :=
cauchy_seq_of_controlled U U_le $ seq_pair_mem hf U_mem
/-- If the sequence `sequentially_complete.seq` converges to `a`, then `f ≤ 𝓝 a`. -/
theorem le_nhds_of_seq_tendsto_nhds ⦃a : α⦄ (ha : tendsto (seq hf U_mem) at_top (𝓝 a)) :
f ≤ 𝓝 a :=
le_nhds_of_cauchy_adhp_aux
begin
assume s hs,
rcases U_le s hs with ⟨m, hm⟩,
rcases (tendsto_at_top' _ _).1 ha _ (mem_nhds_left a (U_mem m)) with ⟨n, hn⟩,
refine ⟨set_seq hf U_mem (max m n), set_seq_mem hf U_mem _, _,
seq hf U_mem (max m n), seq_mem hf U_mem _, _⟩,
{ have := le_max_left m n,
exact set.subset.trans (set_seq_prod_subset hf U_mem this this) hm },
{ exact hm (hn _ $ le_max_right m n) }
end
end sequentially_complete
namespace uniform_space
open sequentially_complete
variables (H : is_countably_generated (𝓤 α))
include H
/-- A uniform space is complete provided that (a) its uniformity filter has a countable basis;
(b) any sequence satisfying a "controlled" version of the Cauchy condition converges. -/
theorem complete_of_convergent_controlled_sequences (U : ℕ → set (α × α)) (U_mem : ∀ n, U n ∈ 𝓤 α)
(HU : ∀ u : ℕ → α, (∀ N m n, N ≤ m → N ≤ n → (u m, u n) ∈ U N) → ∃ a, tendsto u at_top (𝓝 a)) :
complete_space α :=
begin
rcases H.exists_antimono_seq' with ⟨U', U'_mono, hU'⟩,
have Hmem : ∀ n, U n ∩ U' n ∈ 𝓤 α,
from λ n, inter_mem_sets (U_mem n) (hU'.2 ⟨n, subset.refl _⟩),
refine ⟨λ f hf, (HU (seq hf Hmem) (λ N m n hm hn, _)).imp $
le_nhds_of_seq_tendsto_nhds _ _ (λ s hs, _)⟩,
{ rcases (hU'.1 hs) with ⟨N, hN⟩,
exact ⟨N, subset.trans (inter_subset_right _ _) hN⟩ },
{ exact inter_subset_left _ _ (seq_pair_mem hf Hmem hm hn) }
end
/-- A sequentially complete uniform space with a countable basis of the uniformity filter is
complete. -/
theorem complete_of_cauchy_seq_tendsto
(H' : ∀ u : ℕ → α, cauchy_seq u → ∃a, tendsto u at_top (𝓝 a)) :
complete_space α :=
let ⟨U', U'_mono, hU'⟩ := H.exists_antimono_seq' in
complete_of_convergent_controlled_sequences H U' (λ n, hU'.2 ⟨n, subset.refl _⟩)
(λ u hu, H' u $ cauchy_seq_of_controlled U' (λ s hs, hU'.1 hs) hu)
protected lemma first_countable_topology : first_countable_topology α :=
⟨λ a, by { rw nhds_eq_comap_uniformity, exact H.comap (prod.mk a) }⟩
end uniform_space
|
80926c049e77d828a13d8b1fc9181cfa05a1edee | 32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7 | /src/Lean/Elab/Alias.lean | 48cc606d1829940ef65832a3d3b285f0802f345b | [
"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 | 1,248 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Environment
namespace Lean
/- We use aliases to implement the `export <id> (<id>+)` command. -/
abbrev AliasState := SMap Name (List Name)
abbrev AliasEntry := Name × Name
def addAliasEntry (s : AliasState) (e : AliasEntry) : AliasState :=
match s.find? e.1 with
| none => s.insert e.1 [e.2]
| some es => if es.elem e.2 then s else s.insert e.1 (e.2 :: es)
def mkAliasExtension : IO (SimplePersistentEnvExtension AliasEntry AliasState) :=
registerSimplePersistentEnvExtension {
name := `aliasesExt,
addEntryFn := addAliasEntry,
addImportedFn := fun es => (mkStateFromImportedEntries addAliasEntry {} es).switch
}
@[init mkAliasExtension]
constant aliasExtension : SimplePersistentEnvExtension AliasEntry AliasState := arbitrary _
/- Add alias `a` for `e` -/
@[export lean_add_alias]
def addAlias (env : Environment) (a : Name) (e : Name) : Environment :=
aliasExtension.addEntry env (a, e)
def getAliases (env : Environment) (a : Name) : List Name :=
match (aliasExtension.getState env).find? a with
| none => []
| some es => es
end Lean
|
91715fc712ac81fe74935539a131722153e1601c | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/limits/opposites_auto.lean | 0b3ff97a451f880d40e069d3cd154dc5762fe87a | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,383 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Floris van Doorn
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.limits.shapes.products
import Mathlib.category_theory.discrete_category
import Mathlib.PostPort
universes v u
namespace Mathlib
namespace category_theory.limits
/--
If `F.left_op : Jᵒᵖ ⥤ C` has a colimit, we can construct a limit for `F : J ⥤ Cᵒᵖ`.
-/
theorem has_limit_of_has_colimit_left_op {C : Type u} [category C] {J : Type v} [small_category J]
(F : J ⥤ (Cᵒᵖ)) [has_colimit (functor.left_op F)] : has_limit F :=
has_limit.mk
(limit_cone.mk (cone_of_cocone_left_op (colimit.cocone (functor.left_op F)))
(is_limit.mk
fun (s : cone F) =>
has_hom.hom.op (colimit.desc (functor.left_op F) (cocone_left_op_of_cone s))))
/--
If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`.
-/
theorem has_limits_of_shape_op_of_has_colimits_of_shape {C : Type u} [category C] {J : Type v}
[small_category J] [has_colimits_of_shape (Jᵒᵖ) C] : has_limits_of_shape J (Cᵒᵖ) :=
has_limits_of_shape.mk fun (F : J ⥤ (Cᵒᵖ)) => has_limit_of_has_colimit_left_op F
/--
If `C` has colimits, we can construct limits for `Cᵒᵖ`.
-/
theorem has_limits_op_of_has_colimits {C : Type u} [category C] [has_colimits C] :
has_limits (Cᵒᵖ) :=
has_limits.mk
fun (J : Type v) (𝒥 : small_category J) => has_limits_of_shape_op_of_has_colimits_of_shape
/--
If `F.left_op : Jᵒᵖ ⥤ C` has a limit, we can construct a colimit for `F : J ⥤ Cᵒᵖ`.
-/
theorem has_colimit_of_has_limit_left_op {C : Type u} [category C] {J : Type v} [small_category J]
(F : J ⥤ (Cᵒᵖ)) [has_limit (functor.left_op F)] : has_colimit F :=
has_colimit.mk
(colimit_cocone.mk (cocone_of_cone_left_op (limit.cone (functor.left_op F)))
(is_colimit.mk
fun (s : cocone F) =>
has_hom.hom.op (limit.lift (functor.left_op F) (cone_left_op_of_cocone s))))
/--
If `C` has colimits of shape `Jᵒᵖ`, we can construct limits in `Cᵒᵖ` of shape `J`.
-/
theorem has_colimits_of_shape_op_of_has_limits_of_shape {C : Type u} [category C] {J : Type v}
[small_category J] [has_limits_of_shape (Jᵒᵖ) C] : has_colimits_of_shape J (Cᵒᵖ) :=
has_colimits_of_shape.mk fun (F : J ⥤ (Cᵒᵖ)) => has_colimit_of_has_limit_left_op F
/--
If `C` has limits, we can construct colimits for `Cᵒᵖ`.
-/
theorem has_colimits_op_of_has_limits {C : Type u} [category C] [has_limits C] :
has_colimits (Cᵒᵖ) :=
has_colimits.mk
fun (J : Type v) (𝒥 : small_category J) => has_colimits_of_shape_op_of_has_limits_of_shape
/--
If `C` has products indexed by `X`, then `Cᵒᵖ` has coproducts indexed by `X`.
-/
theorem has_coproducts_opposite {C : Type u} [category C] (X : Type v) [has_products_of_shape X C] :
has_coproducts_of_shape X (Cᵒᵖ) :=
has_colimits_of_shape_op_of_has_limits_of_shape
/--
If `C` has coproducts indexed by `X`, then `Cᵒᵖ` has products indexed by `X`.
-/
theorem has_products_opposite {C : Type u} [category C] (X : Type v) [has_coproducts_of_shape X C] :
has_products_of_shape X (Cᵒᵖ) :=
has_limits_of_shape_op_of_has_colimits_of_shape
end Mathlib |
e6b637e0342cf29df9769d55530b6c4e2368958e | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/analysis/calculus/deriv.lean | 9ac25dee19493ca35a67d34cfa75c475f61266e3 | [
"Apache-2.0"
] | permissive | aestriplex/mathlib | 77513ff2b176d74a3bec114f33b519069788811d | e2fa8b2b1b732d7c25119229e3cdfba8370cb00f | refs/heads/master | 1,621,969,960,692 | 1,586,279,279,000 | 1,586,279,279,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54,735 | lean | /-
Copyright (c) 2019 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sébastien Gouëzel
-/
import analysis.calculus.fderiv data.polynomial
/-!
# One-dimensional derivatives
This file defines the derivative of a function `f : 𝕜 → F` where `𝕜` is a
normed field and `F` is a normed space over this field. The derivative of
such a function `f` at a point `x` is given by an element `f' : F`.
The theory is developed analogously to the [Fréchet
derivatives](./fderiv.lean). We first introduce predicates defined in terms
of the corresponding predicates for Fréchet derivatives:
- `has_deriv_at_filter f f' x L` states that the function `f` has the
derivative `f'` at the point `x` as `x` goes along the filter `L`.
- `has_deriv_within_at f f' s x` states that the function `f` has the
derivative `f'` at the point `x` within the subset `s`.
- `has_deriv_at f f' x` states that the function `f` has the derivative `f'`
at the point `x`.
For the last two notions we also define a functional version:
- `deriv_within f s x` is a derivative of `f` at `x` within `s`. If the
derivative does not exist, then `deriv_within f s x` equals zero.
- `deriv f x` is a derivative of `f` at `x`. If the derivative does not
exist, then `deriv f x` equals zero.
The theorems `fderiv_within_deriv_within` and `fderiv_deriv` show that the
one-dimensional derivatives coincide with the general Fréchet derivatives.
We also show the existence and compute the derivatives of:
- constants
- the identity function
- linear maps
- addition
- negation
- subtraction
- multiplication
- inverse `x → x⁻¹`
- multiplication of two functions in `𝕜 → 𝕜`
- multiplication of a function in `𝕜 → 𝕜` and of a function in `𝕜 → E`
- composition of a function in `𝕜 → F` with a function in `𝕜 → 𝕜`
- composition of a function in `F → E` with a function in `𝕜 → F`
- division
- polynomials
For most binary operations we also define `const_op` and `op_const` theorems for the cases when
the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier,
and they more frequently lead to the desired result.
## Implementation notes
Most of the theorems are direct restatements of the corresponding theorems
for Fréchet derivatives.
-/
universes u v w
noncomputable theory
open_locale classical topological_space
open filter asymptotics set
open continuous_linear_map (smul_right smul_right_one_eq_iff)
set_option class.instance_max_depth 100
variables {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
section
variables {F : Type v} [normed_group F] [normed_space 𝕜 F]
variables {E : Type w} [normed_group E] [normed_space 𝕜 E]
/--
`f` has the derivative `f'` at the point `x` as `x` goes along the filter `L`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges along the filter `L`.
-/
def has_deriv_at_filter (f : 𝕜 → F) (f' : F) (x : 𝕜) (L : filter 𝕜) :=
has_fderiv_at_filter f (smul_right 1 f' : 𝕜 →L[𝕜] F) x L
/--
`f` has the derivative `f'` at the point `x` within the subset `s`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def has_deriv_within_at (f : 𝕜 → F) (f' : F) (s : set 𝕜) (x : 𝕜) :=
has_deriv_at_filter f f' x (nhds_within x s)
/--
`f` has the derivative `f'` at the point `x`.
That is, `f x' = f x + (x' - x) • f' + o(x' - x)` where `x'` converges to `x`.
-/
def has_deriv_at (f : 𝕜 → F) (f' : F) (x : 𝕜) :=
has_deriv_at_filter f f' x (𝓝 x)
/--
Derivative of `f` at the point `x` within the set `s`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_within_at f f' s x`), then
`f x' = f x + (x' - x) • deriv_within f s x + o(x' - x)` where `x'` converges to `x` inside `s`.
-/
def deriv_within (f : 𝕜 → F) (s : set 𝕜) (x : 𝕜) :=
(fderiv_within 𝕜 f s x : 𝕜 →L[𝕜] F) 1
/--
Derivative of `f` at the point `x`, if it exists. Zero otherwise.
If the derivative exists (i.e., `∃ f', has_deriv_at f f' x`), then
`f x' = f x + (x' - x) • deriv f x + o(x' - x)` where `x'` converges to `x`.
-/
def deriv (f : 𝕜 → F) (x : 𝕜) :=
(fderiv 𝕜 f x : 𝕜 →L[𝕜] F) 1
variables {f f₀ f₁ g : 𝕜 → F}
variables {f' f₀' f₁' g' : F}
variables {x : 𝕜}
variables {s t : set 𝕜}
variables {L L₁ L₂ : filter 𝕜}
/-- Expressing `has_fderiv_at_filter f f' x L` in terms of `has_deriv_at_filter` -/
lemma has_fderiv_at_filter_iff_has_deriv_at_filter {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at_filter f f' x L ↔ has_deriv_at_filter f (f' 1) x L :=
by simp [has_deriv_at_filter]
/-- Expressing `has_fderiv_within_at f f' s x` in terms of `has_deriv_within_at` -/
lemma has_fderiv_within_at_iff_has_deriv_within_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_within_at f f' s x ↔ has_deriv_within_at f (f' 1) s x :=
by simp [has_deriv_within_at, has_deriv_at_filter, has_fderiv_within_at]
/-- Expressing `has_deriv_within_at f f' s x` in terms of `has_fderiv_within_at` -/
lemma has_deriv_within_at_iff_has_fderiv_within_at {f' : F} :
has_deriv_within_at f f' s x ↔
has_fderiv_within_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) s x :=
iff.rfl
/-- Expressing `has_fderiv_at f f' x` in terms of `has_deriv_at` -/
lemma has_fderiv_at_iff_has_deriv_at {f' : 𝕜 →L[𝕜] F} :
has_fderiv_at f f' x ↔ has_deriv_at f (f' 1) x :=
by simp [has_deriv_at, has_deriv_at_filter, has_fderiv_at]
/-- Expressing `has_deriv_at f f' x` in terms of `has_fderiv_at` -/
lemma has_deriv_at_iff_has_fderiv_at {f' : F} :
has_deriv_at f f' x ↔
has_fderiv_at f (smul_right 1 f' : 𝕜 →L[𝕜] F) x :=
iff.rfl
lemma deriv_within_zero_of_not_differentiable_within_at
(h : ¬ differentiable_within_at 𝕜 f s x) : deriv_within f s x = 0 :=
by { unfold deriv_within, rw fderiv_within_zero_of_not_differentiable_within_at, simp, assumption }
lemma deriv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : deriv f x = 0 :=
by { unfold deriv, rw fderiv_zero_of_not_differentiable_at, simp, assumption }
theorem unique_diff_within_at.eq_deriv (s : set 𝕜) (H : unique_diff_within_at 𝕜 s x)
(h : has_deriv_within_at f f' s x) (h₁ : has_deriv_within_at f f₁' s x) : f' = f₁' :=
smul_right_one_eq_iff.mp $ unique_diff_within_at.eq H h h₁
theorem has_deriv_at_filter_iff_tendsto :
has_deriv_at_filter f f' x L ↔
tendsto (λ x' : 𝕜, ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) L (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_within_at_iff_tendsto : has_deriv_within_at f f' s x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (nhds_within x s) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_deriv_at_iff_tendsto : has_deriv_at f f' x ↔
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - (x' - x) • f'∥) (𝓝 x) (𝓝 0) :=
has_fderiv_at_filter_iff_tendsto
/-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical
definition with a limit. In this version we have to take the limit along the subset `-{x}`,
because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/
lemma has_deriv_at_filter_iff_tendsto_slope {x : 𝕜} {L : filter 𝕜} :
has_deriv_at_filter f f' x L ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (L ⊓ principal (-{x})) (𝓝 f') :=
begin
conv_lhs { simp only [has_deriv_at_filter_iff_tendsto, (normed_field.norm_inv _).symm,
(norm_smul _ _).symm, tendsto_zero_iff_norm_tendsto_zero.symm] },
conv_rhs { rw [← nhds_translation f', tendsto_comap_iff] },
refine (tendsto_inf_principal_nhds_iff_of_forall_eq $ by simp).symm.trans (tendsto_congr' _),
rw mem_inf_principal,
refine univ_mem_sets' (λ z hz, _),
have : z ≠ x, by simpa [function.comp] using hz,
simp only [mem_set_of_eq],
rw [smul_sub, ← mul_smul, inv_mul_cancel (sub_ne_zero.2 this), one_smul]
end
lemma has_deriv_within_at_iff_tendsto_slope {x : 𝕜} {s : set 𝕜} :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (nhds_within x (s \ {x})) (𝓝 f') :=
begin
simp only [has_deriv_within_at, nhds_within, diff_eq, inf_assoc.symm, inf_principal.symm],
exact has_deriv_at_filter_iff_tendsto_slope
end
lemma has_deriv_within_at_iff_tendsto_slope' {x : 𝕜} {s : set 𝕜} (hs : x ∉ s) :
has_deriv_within_at f f' s x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (nhds_within x s) (𝓝 f') :=
begin
convert ← has_deriv_within_at_iff_tendsto_slope,
exact diff_singleton_eq_self hs
end
lemma has_deriv_at_iff_tendsto_slope {x : 𝕜} :
has_deriv_at f f' x ↔
tendsto (λ y, (y - x)⁻¹ • (f y - f x)) (nhds_within x (-{x})) (𝓝 f') :=
has_deriv_at_filter_iff_tendsto_slope
theorem has_deriv_at_iff_is_o_nhds_zero : has_deriv_at f f' x ↔
is_o (λh, f (x + h) - f x - h • f') (λh, h) (𝓝 0) :=
has_fderiv_at_iff_is_o_nhds_zero
theorem has_deriv_at_filter.mono (h : has_deriv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) :
has_deriv_at_filter f f' x L₁ :=
has_fderiv_at_filter.mono h hst
theorem has_deriv_within_at.mono (h : has_deriv_within_at f f' t x) (hst : s ⊆ t) :
has_deriv_within_at f f' s x :=
has_fderiv_within_at.mono h hst
theorem has_deriv_at.has_deriv_at_filter (h : has_deriv_at f f' x) (hL : L ≤ 𝓝 x) :
has_deriv_at_filter f f' x L :=
has_fderiv_at.has_fderiv_at_filter h hL
theorem has_deriv_at.has_deriv_within_at
(h : has_deriv_at f f' x) : has_deriv_within_at f f' s x :=
has_fderiv_at.has_fderiv_within_at h
lemma has_deriv_within_at.differentiable_within_at (h : has_deriv_within_at f f' s x) :
differentiable_within_at 𝕜 f s x :=
has_fderiv_within_at.differentiable_within_at h
lemma has_deriv_at.differentiable_at (h : has_deriv_at f f' x) : differentiable_at 𝕜 f x :=
has_fderiv_at.differentiable_at h
@[simp] lemma has_deriv_within_at_univ : has_deriv_within_at f f' univ x ↔ has_deriv_at f f' x :=
has_fderiv_within_at_univ
theorem has_deriv_at_unique
(h₀ : has_deriv_at f f₀' x) (h₁ : has_deriv_at f f₁' x) : f₀' = f₁' :=
smul_right_one_eq_iff.mp $ has_fderiv_at_unique h₀ h₁
lemma has_deriv_within_at_inter' (h : t ∈ nhds_within x s) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter' h
lemma has_deriv_within_at_inter (h : t ∈ 𝓝 x) :
has_deriv_within_at f f' (s ∩ t) x ↔ has_deriv_within_at f f' s x :=
has_fderiv_within_at_inter h
lemma has_deriv_within_at.union (hs : has_deriv_within_at f f' s x) (ht : has_deriv_within_at f f' t x) :
has_deriv_within_at f f' (s ∪ t) x :=
begin
simp only [has_deriv_within_at, nhds_within_union],
exact hs.join ht,
end
lemma has_deriv_within_at.nhds_within (h : has_deriv_within_at f f' s x)
(ht : s ∈ nhds_within x t) : has_deriv_within_at f f' t x :=
(has_deriv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
lemma has_deriv_within_at.has_deriv_at (h : has_deriv_within_at f f' s x) (hs : s ∈ 𝓝 x) :
has_deriv_at f f' x :=
has_fderiv_within_at.has_fderiv_at h hs
lemma differentiable_within_at.has_deriv_within_at (h : differentiable_within_at 𝕜 f s x) :
has_deriv_within_at f (deriv_within f s x) s x :=
show has_fderiv_within_at _ _ _ _, by { convert h.has_fderiv_within_at, simp [deriv_within] }
lemma differentiable_at.has_deriv_at (h : differentiable_at 𝕜 f x) : has_deriv_at f (deriv f x) x :=
show has_fderiv_at _ _ _, by { convert h.has_fderiv_at, simp [deriv] }
lemma has_deriv_at.deriv (h : has_deriv_at f f' x) : deriv f x = f' :=
has_deriv_at_unique h.differentiable_at.has_deriv_at h
lemma has_deriv_within_at.deriv_within
(h : has_deriv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within f s x = f' :=
hxs.eq_deriv _ h.differentiable_within_at.has_deriv_within_at h
lemma fderiv_within_deriv_within : (fderiv_within 𝕜 f s x : 𝕜 → F) 1 = deriv_within f s x :=
rfl
lemma deriv_within_fderiv_within :
smul_right 1 (deriv_within f s x) = fderiv_within 𝕜 f s x :=
by simp [deriv_within]
lemma fderiv_deriv : (fderiv 𝕜 f x : 𝕜 → F) 1 = deriv f x :=
rfl
lemma deriv_fderiv :
smul_right 1 (deriv f x) = fderiv 𝕜 f x :=
by simp [deriv]
lemma differentiable_at.deriv_within (h : differentiable_at 𝕜 f x)
(hxs : unique_diff_within_at 𝕜 s x) : deriv_within f s x = deriv f x :=
by { unfold deriv_within deriv, rw h.fderiv_within hxs }
lemma deriv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f t x) :
deriv_within f s x = deriv_within f t x :=
((differentiable_within_at.has_deriv_within_at h).mono st).deriv_within ht
@[simp] lemma deriv_within_univ : deriv_within f univ = deriv f :=
by { ext, unfold deriv_within deriv, rw fderiv_within_univ }
lemma deriv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) :
deriv_within f (s ∩ t) x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_inter ht hs }
section congr
/-! ### Congruence properties of derivatives -/
theorem has_deriv_at_filter_congr_of_mem_sets
(hx : f₀ x = f₁ x) (h₀ : ∀ᶠ x in L, f₀ x = f₁ x) (h₁ : f₀' = f₁') :
has_deriv_at_filter f₀ f₀' x L ↔ has_deriv_at_filter f₁ f₁' x L :=
has_fderiv_at_filter_congr_of_mem_sets hx h₀ (by simp [h₁])
lemma has_deriv_at_filter.congr_of_mem_sets (h : has_deriv_at_filter f f' x L)
(hL : ∀ᶠ x in L, f₁ x = f x) (hx : f₁ x = f x) : has_deriv_at_filter f₁ f' x L :=
by rwa has_deriv_at_filter_congr_of_mem_sets hx hL rfl
lemma has_deriv_within_at.congr_mono (h : has_deriv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x)
(hx : f₁ x = f x) (h₁ : t ⊆ s) : has_deriv_within_at f₁ f' t x :=
has_fderiv_within_at.congr_mono h ht hx h₁
lemma has_deriv_within_at.congr (h : has_deriv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x)
(hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
h.congr_mono hs hx (subset.refl _)
lemma has_deriv_within_at.congr_of_mem_nhds_within (h : has_deriv_within_at f f' s x)
(h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) : has_deriv_within_at f₁ f' s x :=
has_deriv_at_filter.congr_of_mem_sets h h₁ hx
lemma has_deriv_at.congr_of_mem_nhds (h : has_deriv_at f f' x)
(h₁ : ∀ᶠ y in 𝓝 x, f₁ y = f y) : has_deriv_at f₁ f' x :=
has_deriv_at_filter.congr_of_mem_sets h h₁ (mem_of_nhds h₁ : _)
lemma deriv_within_congr_of_mem_nhds_within (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_congr_of_mem_nhds_within hs hL hx }
lemma deriv_within_congr (hs : unique_diff_within_at 𝕜 s x)
(hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) :
deriv_within f₁ s x = deriv_within f s x :=
by { unfold deriv_within, rw fderiv_within_congr hs hL hx }
lemma deriv_congr_of_mem_nhds (hL : ∀ᶠ y in 𝓝 x, f₁ y = f y) : deriv f₁ x = deriv f x :=
by { unfold deriv, rwa fderiv_congr_of_mem_nhds }
end congr
section id
/-! ### Derivative of the identity -/
variables (s x L)
theorem has_deriv_at_filter_id : has_deriv_at_filter id 1 x L :=
(is_o_zero _ _).congr_left $ by simp
theorem has_deriv_within_at_id : has_deriv_within_at id 1 s x :=
has_deriv_at_filter_id _ _
theorem has_deriv_at_id : has_deriv_at id 1 x :=
has_deriv_at_filter_id _ _
lemma deriv_id : deriv id x = 1 :=
has_deriv_at.deriv (has_deriv_at_id x)
@[simp] lemma deriv_id' : deriv (@id 𝕜) = λ _, 1 :=
funext deriv_id
lemma deriv_within_id (hxs : unique_diff_within_at 𝕜 s x) : deriv_within id s x = 1 :=
by { unfold deriv_within, rw fderiv_within_id, simp, assumption }
end id
section const
/-! ### Derivative of constant functions -/
variables (c : F) (s x L)
theorem has_deriv_at_filter_const : has_deriv_at_filter (λ x, c) 0 x L :=
(is_o_zero _ _).congr_left $ λ _, by simp [continuous_linear_map.zero_apply, sub_self]
theorem has_deriv_within_at_const : has_deriv_within_at (λ x, c) 0 s x :=
has_deriv_at_filter_const _ _ _
theorem has_deriv_at_const : has_deriv_at (λ x, c) 0 x :=
has_deriv_at_filter_const _ _ _
lemma deriv_const : deriv (λ x, c) x = 0 :=
has_deriv_at.deriv (has_deriv_at_const x c)
@[simp] lemma deriv_const' : deriv (λ x:𝕜, c) = λ x, 0 :=
funext (λ x, deriv_const x c)
lemma deriv_within_const (hxs : unique_diff_within_at 𝕜 s x) : deriv_within (λ x, c) s x = 0 :=
by { rw (differentiable_at_const _).deriv_within hxs, apply deriv_const }
end const
section is_linear_map
/-! ### Derivative of linear maps -/
variables (s x L) [is_linear_map 𝕜 f]
lemma is_linear_map.has_deriv_at_filter : has_deriv_at_filter f (f 1) x L :=
(is_o_zero _ _).congr_left begin
intro y,
simp [sub_smul],
rw ← is_linear_map.smul f x,
rw ← is_linear_map.smul f y,
simp
end
lemma is_linear_map.has_deriv_within_at : has_deriv_within_at f (f 1) s x :=
is_linear_map.has_deriv_at_filter _ _
lemma is_linear_map.has_deriv_at : has_deriv_at f (f 1) x :=
is_linear_map.has_deriv_at_filter _ _
lemma is_linear_map.differentiable_at : differentiable_at 𝕜 f x :=
(is_linear_map.has_deriv_at _).differentiable_at
lemma is_linear_map.differentiable_within_at : differentiable_within_at 𝕜 f s x :=
(is_linear_map.differentiable_at _).differentiable_within_at
@[simp] lemma is_linear_map.deriv : deriv f x = f 1 :=
has_deriv_at.deriv (is_linear_map.has_deriv_at _)
lemma is_linear_map.deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within f s x = f 1 :=
begin
rw differentiable_at.deriv_within (is_linear_map.differentiable_at _) hxs,
apply is_linear_map.deriv,
assumption
end
lemma is_linear_map.differentiable : differentiable 𝕜 f :=
λ x, is_linear_map.differentiable_at _
lemma is_linear_map.differentiable_on : differentiable_on 𝕜 f s :=
is_linear_map.differentiable.differentiable_on
end is_linear_map
section add
/-! ### Derivative of the sum of two functions -/
theorem has_deriv_at_filter.add
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ y, f y + g y) (f' + g') x L :=
(hf.add hg).congr_left $ by simp [add_smul, smul_add]
theorem has_deriv_within_at.add
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ y, f y + g y) (f' + g') s x :=
hf.add hg
theorem has_deriv_at.add
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x + g x) (f' + g') x :=
hf.add hg
lemma deriv_within_add (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y + g y) s x = deriv_within f s x + deriv_within g s x :=
(hf.has_deriv_within_at.add hg.has_deriv_within_at).deriv_within hxs
lemma deriv_add
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λy, f y + g y) x = deriv f x + deriv g x :=
(hf.has_deriv_at.add hg.has_deriv_at).deriv
theorem has_deriv_at_filter.add_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ y, f y + c) f' x L :=
add_zero f' ▸ hf.add (has_deriv_at_filter_const x L c)
theorem has_deriv_within_at.add_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ y, f y + c) f' s x :=
hf.add_const c
theorem has_deriv_at.add_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x + c) f' x :=
hf.add_const c
lemma deriv_within_add_const (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
deriv_within (λy, f y + c) s x = deriv_within f s x :=
(hf.has_deriv_within_at.add_const c).deriv_within hxs
lemma deriv_add_const (hf : differentiable_at 𝕜 f x) (c : F) :
deriv (λy, f y + c) x = deriv f x :=
(hf.has_deriv_at.add_const c).deriv
theorem has_deriv_at_filter.const_add (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ y, c + f y) f' x L :=
zero_add f' ▸ (has_deriv_at_filter_const x L c).add hf
theorem has_deriv_within_at.const_add (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c + f y) f' s x :=
hf.const_add c
theorem has_deriv_at.const_add (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c + f x) f' x :=
hf.const_add c
lemma deriv_within_const_add (hxs : unique_diff_within_at 𝕜 s x)
(c : F) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, c + f y) s x = deriv_within f s x :=
(hf.has_deriv_within_at.const_add c).deriv_within hxs
lemma deriv_const_add (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λy, c + f y) x = deriv f x :=
(hf.has_deriv_at.const_add c).deriv
end add
section mul_vector
/-! ### Derivative of the multiplication of a scalar function and a vector function -/
variables {c : 𝕜 → 𝕜} {c' : 𝕜}
theorem has_deriv_within_at.smul
(hc : has_deriv_within_at c c' s x) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c y • f y) (c x • f' + c' • f x) s x :=
begin
show has_fderiv_within_at _ _ _ _,
convert has_fderiv_within_at.smul hc hf,
ext,
simp [smul_add, (mul_smul _ _ _).symm, mul_comm]
end
theorem has_deriv_at.smul
(hc : has_deriv_at c c' x) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c y • f y) (c x • f' + c' • f x) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul hf
end
lemma deriv_within_smul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c y • f y) s x = c x • deriv_within f s x + (deriv_within c s x) • f x :=
(hc.has_deriv_within_at.smul hf.has_deriv_within_at).deriv_within hxs
lemma deriv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c y • f y) x = c x • deriv f x + (deriv c x) • f x :=
(hc.has_deriv_at.smul hf.has_deriv_at).deriv
theorem has_deriv_within_at.smul_const
(hc : has_deriv_within_at c c' s x) (f : F) :
has_deriv_within_at (λ y, c y • f) (c' • f) s x :=
begin
have := hc.smul (has_deriv_within_at_const x s f),
rwa [smul_zero, zero_add] at this
end
theorem has_deriv_at.smul_const
(hc : has_deriv_at c c' x) (f : F) :
has_deriv_at (λ y, c y • f) (c' • f) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.smul_const f
end
lemma deriv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (f : F) :
deriv_within (λ y, c y • f) s x = (deriv_within c s x) • f :=
(hc.has_deriv_within_at.smul_const f).deriv_within hxs
lemma deriv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) :
deriv (λ y, c y • f) x = (deriv c x) • f :=
(hc.has_deriv_at.smul_const f).deriv
theorem has_deriv_within_at.const_smul
(c : 𝕜) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ y, c • f y) (c • f') s x :=
begin
convert (has_deriv_within_at_const x s c).smul hf,
rw [zero_smul, add_zero]
end
theorem has_deriv_at.const_smul (c : 𝕜) (hf : has_deriv_at f f' x) :
has_deriv_at (λ y, c • f y) (c • f') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hf.const_smul c
end
lemma deriv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λ y, c • f y) s x = c • deriv_within f s x :=
(hf.has_deriv_within_at.const_smul c).deriv_within hxs
lemma deriv_const_smul (c : 𝕜) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c • f y) x = c • deriv f x :=
(hf.has_deriv_at.const_smul c).deriv
end mul_vector
section neg
/-! ### Derivative of the negative of a function -/
theorem has_deriv_at_filter.neg (h : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, -f x) (-f') x L :=
h.neg.congr (by simp) (by simp)
theorem has_deriv_within_at.neg (h : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, -f x) (-f') s x :=
h.neg
theorem has_deriv_at.neg (h : has_deriv_at f f' x) : has_deriv_at (λ x, -f x) (-f') x :=
h.neg
lemma deriv_within_neg (hxs : unique_diff_within_at 𝕜 s x)
(h : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, -f y) s x = - deriv_within f s x :=
h.has_deriv_within_at.neg.deriv_within hxs
lemma deriv_neg : deriv (λy, -f y) x = - deriv f x :=
if h : differentiable_at 𝕜 f x then h.has_deriv_at.neg.deriv else
have ¬differentiable_at 𝕜 (λ y, -f y) x, from λ h', by simpa only [neg_neg] using h'.neg,
by simp only [deriv_zero_of_not_differentiable_at h,
deriv_zero_of_not_differentiable_at this, neg_zero]
@[simp] lemma deriv_neg' : deriv (λy, -f y) = (λ x, - deriv f x) :=
funext $ λ x, deriv_neg
end neg
section sub
/-! ### Derivative of the difference of two functions -/
theorem has_deriv_at_filter.sub
(hf : has_deriv_at_filter f f' x L) (hg : has_deriv_at_filter g g' x L) :
has_deriv_at_filter (λ x, f x - g x) (f' - g') x L :=
hf.add hg.neg
theorem has_deriv_within_at.sub
(hf : has_deriv_within_at f f' s x) (hg : has_deriv_within_at g g' s x) :
has_deriv_within_at (λ x, f x - g x) (f' - g') s x :=
hf.sub hg
theorem has_deriv_at.sub
(hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x) :
has_deriv_at (λ x, f x - g x) (f' - g') x :=
hf.sub hg
lemma deriv_within_sub (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) :
deriv_within (λy, f y - g y) s x = deriv_within f s x - deriv_within g s x :=
(hf.has_deriv_within_at.sub hg.has_deriv_within_at).deriv_within hxs
lemma deriv_sub
(hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) :
deriv (λ y, f y - g y) x = deriv f x - deriv g x :=
(hf.has_deriv_at.sub hg.has_deriv_at).deriv
theorem has_deriv_at_filter.is_O_sub (h : has_deriv_at_filter f f' x L) :
is_O (λ x', f x' - f x) (λ x', x' - x) L :=
has_fderiv_at_filter.is_O_sub h
theorem has_deriv_at_filter.sub_const
(hf : has_deriv_at_filter f f' x L) (c : F) :
has_deriv_at_filter (λ x, f x - c) f' x L :=
hf.add_const (-c)
theorem has_deriv_within_at.sub_const
(hf : has_deriv_within_at f f' s x) (c : F) :
has_deriv_within_at (λ x, f x - c) f' s x :=
hf.sub_const c
theorem has_deriv_at.sub_const
(hf : has_deriv_at f f' x) (c : F) :
has_deriv_at (λ x, f x - c) f' x :=
hf.sub_const c
lemma deriv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x)
(hf : differentiable_within_at 𝕜 f s x) (c : F) :
deriv_within (λy, f y - c) s x = deriv_within f s x :=
(hf.has_deriv_within_at.sub_const c).deriv_within hxs
lemma deriv_sub_const (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, f y - c) x = deriv f x :=
(hf.has_deriv_at.sub_const c).deriv
theorem has_deriv_at_filter.const_sub (c : F) (hf : has_deriv_at_filter f f' x L) :
has_deriv_at_filter (λ x, c - f x) (-f') x L :=
hf.neg.const_add c
theorem has_deriv_within_at.const_sub (c : F) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (λ x, c - f x) (-f') s x :=
hf.const_sub c
theorem has_deriv_at.const_sub (c : F) (hf : has_deriv_at f f' x) :
has_deriv_at (λ x, c - f x) (-f') x :=
hf.const_sub c
lemma deriv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x)
(c : F) (hf : differentiable_within_at 𝕜 f s x) :
deriv_within (λy, c - f y) s x = -deriv_within f s x :=
(hf.has_deriv_within_at.const_sub c).deriv_within hxs
lemma deriv_const_sub (c : F) (hf : differentiable_at 𝕜 f x) :
deriv (λ y, c - f y) x = -deriv f x :=
(hf.has_deriv_at.const_sub c).deriv
end sub
section continuous
/-! ### Continuity of a function admitting a derivative -/
theorem has_deriv_at_filter.tendsto_nhds
(hL : L ≤ 𝓝 x) (h : has_deriv_at_filter f f' x L) :
tendsto f L (𝓝 (f x)) :=
has_fderiv_at_filter.tendsto_nhds hL h
theorem has_deriv_within_at.continuous_within_at
(h : has_deriv_within_at f f' s x) : continuous_within_at f s x :=
has_deriv_at_filter.tendsto_nhds inf_le_left h
theorem has_deriv_at.continuous_at (h : has_deriv_at f f' x) : continuous_at f x :=
has_deriv_at_filter.tendsto_nhds (le_refl _) h
end continuous
section cartesian_product
/-! ### Derivative of the cartesian product of two functions -/
variables {G : Type w} [normed_group G] [normed_space 𝕜 G]
variables {f₂ : 𝕜 → G} {f₂' : G}
lemma has_deriv_at_filter.prod
(hf₁ : has_deriv_at_filter f₁ f₁' x L) (hf₂ : has_deriv_at_filter f₂ f₂' x L) :
has_deriv_at_filter (λ x, (f₁ x, f₂ x)) (f₁', f₂') x L :=
show has_fderiv_at_filter _ _ _ _,
by convert has_fderiv_at_filter.prod hf₁ hf₂
lemma has_deriv_within_at.prod
(hf₁ : has_deriv_within_at f₁ f₁' s x) (hf₂ : has_deriv_within_at f₂ f₂' s x) :
has_deriv_within_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') s x :=
hf₁.prod hf₂
lemma has_deriv_at.prod (hf₁ : has_deriv_at f₁ f₁' x) (hf₂ : has_deriv_at f₂ f₂' x) :
has_deriv_at (λ x, (f₁ x, f₂ x)) (f₁', f₂') x :=
hf₁.prod hf₂
end cartesian_product
section composition
/-! ### Derivative of the composition of a vector valued function and a scalar function -/
variables {h : 𝕜 → 𝕜} {h' : 𝕜}
/- For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to
get confused since there are too many possibilities for composition -/
variable (x)
theorem has_deriv_at_filter.comp
(hg : has_deriv_at_filter g g' (h x) (L.map h))
(hh : has_deriv_at_filter h h' x L) :
has_deriv_at_filter (g ∘ h) (h' • g') x L :=
have (smul_right 1 g' : 𝕜 →L[𝕜] _).comp
(smul_right 1 h' : 𝕜 →L[𝕜] _) =
smul_right 1 (h' • g'), by { ext, simp [mul_smul] },
begin
unfold has_deriv_at_filter,
rw ← this,
exact has_fderiv_at_filter.comp x hg hh,
end
theorem has_deriv_within_at.comp {t : set 𝕜}
(hg : has_deriv_within_at g g' t (h x))
(hh : has_deriv_within_at h h' s x) (hst : s ⊆ h ⁻¹' t) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
begin
apply has_deriv_at_filter.comp _ (has_deriv_at_filter.mono hg _) hh,
calc map h (nhds_within x s)
≤ nhds_within (h x) (h '' s) : hh.continuous_within_at.tendsto_nhds_within_image
... ≤ nhds_within (h x) t : nhds_within_mono _ (image_subset_iff.mpr hst)
end
/-- The chain rule. -/
theorem has_deriv_at.comp
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_at h h' x) :
has_deriv_at (g ∘ h) (h' • g') x :=
(hg.mono hh.continuous_at).comp x hh
theorem has_deriv_at.comp_has_deriv_within_at
(hg : has_deriv_at g g' (h x)) (hh : has_deriv_within_at h h' s x) :
has_deriv_within_at (g ∘ h) (h' • g') s x :=
begin
rw ← has_deriv_within_at_univ at hg,
exact has_deriv_within_at.comp x hg hh subset_preimage_univ
end
lemma deriv_within.comp
(hg : differentiable_within_at 𝕜 g t (h x)) (hh : differentiable_within_at 𝕜 h s x)
(hs : s ⊆ h ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (g ∘ h) s x = deriv_within h s x • deriv_within g t (h x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact has_deriv_within_at.comp x (hg.has_deriv_within_at) (hh.has_deriv_within_at) hs
end
lemma deriv.comp
(hg : differentiable_at 𝕜 g (h x)) (hh : differentiable_at 𝕜 h x) :
deriv (g ∘ h) x = deriv h x • deriv g (h x) :=
begin
apply has_deriv_at.deriv,
exact has_deriv_at.comp x hg.has_deriv_at hh.has_deriv_at
end
end composition
section composition_vector
/-! ### Derivative of the composition of a function between vector spaces and of a function defined on `𝕜` -/
variables {l : F → E} {l' : F →L[𝕜] E}
variable (x)
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative within a set
equal to the Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_within_at.comp_has_deriv_within_at {t : set F}
(hl : has_fderiv_within_at l l' t (f x)) (hf : has_deriv_within_at f f' s x) (hst : s ⊆ f ⁻¹' t) :
has_deriv_within_at (l ∘ f) (l' (f')) s x :=
begin
rw has_deriv_within_at_iff_has_fderiv_within_at,
convert has_fderiv_within_at.comp x hl hf hst,
ext,
simp
end
/-- The composition `l ∘ f` where `l : F → E` and `f : 𝕜 → F`, has a derivative equal to the
Fréchet derivative of `l` applied to the derivative of `f`. -/
theorem has_fderiv_at.comp_has_deriv_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_at f f' x) :
has_deriv_at (l ∘ f) (l' (f')) x :=
begin
rw has_deriv_at_iff_has_fderiv_at,
convert has_fderiv_at.comp x hl hf,
ext,
simp
end
theorem has_fderiv_at.comp_has_deriv_within_at
(hl : has_fderiv_at l l' (f x)) (hf : has_deriv_within_at f f' s x) :
has_deriv_within_at (l ∘ f) (l' (f')) s x :=
begin
rw ← has_fderiv_within_at_univ at hl,
exact has_fderiv_within_at.comp_has_deriv_within_at x hl hf subset_preimage_univ
end
lemma fderiv_within.comp_deriv_within {t : set F}
(hl : differentiable_within_at 𝕜 l t (f x)) (hf : differentiable_within_at 𝕜 f s x)
(hs : s ⊆ f ⁻¹' t) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (l ∘ f) s x = (fderiv_within 𝕜 l t (f x) : F → E) (deriv_within f s x) :=
begin
apply has_deriv_within_at.deriv_within _ hxs,
exact (hl.has_fderiv_within_at).comp_has_deriv_within_at x (hf.has_deriv_within_at) hs
end
lemma fderiv.comp_deriv
(hl : differentiable_at 𝕜 l (f x)) (hf : differentiable_at 𝕜 f x) :
deriv (l ∘ f) x = (fderiv 𝕜 l (f x) : F → E) (deriv f x) :=
begin
apply has_deriv_at.deriv _,
exact (hl.has_fderiv_at).comp_has_deriv_at x (hf.has_deriv_at)
end
end composition_vector
section mul
/-! ### Derivative of the multiplication of two scalar functions -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
theorem has_deriv_within_at.mul
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c y * d y) (c' * d x + c x * d') s x :=
begin
convert hc.smul hd using 1,
rw [smul_eq_mul, smul_eq_mul, add_comm]
end
theorem has_deriv_at.mul (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c y * d y) (c' * d x + c x * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul hd
end
lemma deriv_within_mul (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c y * d y) s x = deriv_within c s x * d x + c x * deriv_within d s x :=
(hc.has_deriv_within_at.mul hd.has_deriv_within_at).deriv_within hxs
lemma deriv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c y * d y) x = deriv c x * d x + c x * deriv d x :=
(hc.has_deriv_at.mul hd.has_deriv_at).deriv
theorem has_deriv_within_at.mul_const (hc : has_deriv_within_at c c' s x) (d : 𝕜) :
has_deriv_within_at (λ y, c y * d) (c' * d) s x :=
begin
convert hc.mul (has_deriv_within_at_const x s d),
rw [mul_zero, add_zero]
end
theorem has_deriv_at.mul_const (hc : has_deriv_at c c' x) (d : 𝕜) :
has_deriv_at (λ y, c y * d) (c' * d) x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hc.mul_const d
end
lemma deriv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x)
(hc : differentiable_within_at 𝕜 c s x) (d : 𝕜) :
deriv_within (λ y, c y * d) s x = deriv_within c s x * d :=
(hc.has_deriv_within_at.mul_const d).deriv_within hxs
lemma deriv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝕜) :
deriv (λ y, c y * d) x = deriv c x * d :=
(hc.has_deriv_at.mul_const d).deriv
theorem has_deriv_within_at.const_mul (c : 𝕜) (hd : has_deriv_within_at d d' s x) :
has_deriv_within_at (λ y, c * d y) (c * d') s x :=
begin
convert (has_deriv_within_at_const x s c).mul hd,
rw [zero_mul, zero_add]
end
theorem has_deriv_at.const_mul (c : 𝕜) (hd : has_deriv_at d d' x) :
has_deriv_at (λ y, c * d y) (c * d') x :=
begin
rw [← has_deriv_within_at_univ] at *,
exact hd.const_mul c
end
lemma deriv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x)
(c : 𝕜) (hd : differentiable_within_at 𝕜 d s x) :
deriv_within (λ y, c * d y) s x = c * deriv_within d s x :=
(hd.has_deriv_within_at.const_mul c).deriv_within hxs
lemma deriv_const_mul (c : 𝕜) (hd : differentiable_at 𝕜 d x) :
deriv (λ y, c * d y) x = c * deriv d x :=
(hd.has_deriv_at.const_mul c).deriv
end mul
section inverse
/-! ### Derivative of `x ↦ x⁻¹` -/
lemma has_deriv_at_inv_one :
has_deriv_at (λx, x⁻¹) (-1) (1 : 𝕜) :=
begin
rw has_deriv_at_iff_is_o_nhds_zero,
have : is_o (λ (h : 𝕜), h^2 * (1 + h)⁻¹) (λ (h : 𝕜), h * 1) (𝓝 0),
{ have : tendsto (λ (h : 𝕜), (1 + h)⁻¹) (𝓝 0) (𝓝 (1 + 0)⁻¹) :=
((tendsto_const_nhds).add tendsto_id).inv' (by norm_num),
exact is_o.mul_is_O (is_o_pow_id one_lt_two) (is_O_one_of_tendsto _ this) },
apply this.congr' _ _,
{ have : metric.ball (0 : 𝕜) 1 ∈ 𝓝 (0 : 𝕜),
from metric.ball_mem_nhds 0 zero_lt_one,
filter_upwards [this],
assume h hx,
have : 0 < ∥1 + h∥ := calc
0 < ∥(1:𝕜)∥ - ∥-h∥ : by rwa [norm_neg, sub_pos, ← dist_zero_right h, normed_field.norm_one]
... ≤ ∥1 - -h∥ : norm_sub_norm_le _ _
... = ∥1 + h∥ : by simp,
have : 1 + h ≠ 0 := norm_pos_iff.mp this,
simp,
rw ← eq_div_iff_mul_eq _ _ (inv_ne_zero this),
field_simp,
simp [right_distrib, sub_mul,
(show (1 + h)⁻¹ * (1 + h) = 1, by rw mul_comm; exact field.mul_inv_cancel this)],
ring },
{ exact univ_mem_sets' mul_one }
end
theorem has_deriv_at_inv (x_ne_zero : x ≠ 0) :
has_deriv_at (λy, y⁻¹) (-(x^2)⁻¹) x :=
begin
have A : has_deriv_at (λy, y⁻¹) (-1) (x⁻¹ * x : 𝕜),
by { simp only [inv_mul_cancel x_ne_zero, has_deriv_at_inv_one] },
have B : has_deriv_at (λy, x⁻¹ * y) (x⁻¹) x,
by simpa only [mul_one] using (has_deriv_at_id x).const_mul x⁻¹,
convert (A.comp x B : _).const_mul x⁻¹,
{ ext y,
rw [function.comp_apply, mul_inv', inv_inv', mul_comm, mul_assoc, mul_inv_cancel x_ne_zero,
mul_one] },
{ rw [pow_two, mul_inv', smul_eq_mul, mul_neg_one, neg_mul_eq_mul_neg] }
end
theorem has_deriv_within_at_inv (x_ne_zero : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x⁻¹) (-(x^2)⁻¹) s x :=
(has_deriv_at_inv x_ne_zero).has_deriv_within_at
lemma differentiable_at_inv (x_ne_zero : x ≠ 0) :
differentiable_at 𝕜 (λx, x⁻¹) x :=
(has_deriv_at_inv x_ne_zero).differentiable_at
lemma differentiable_within_at_inv (x_ne_zero : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x⁻¹) s x :=
(differentiable_at_inv x_ne_zero).differentiable_within_at
lemma differentiable_on_inv : differentiable_on 𝕜 (λx:𝕜, x⁻¹) {x | x ≠ 0} :=
λx hx, differentiable_within_at_inv hx
lemma deriv_inv (x_ne_zero : x ≠ 0) :
deriv (λx, x⁻¹) x = -(x^2)⁻¹ :=
(has_deriv_at_inv x_ne_zero).deriv
lemma deriv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x⁻¹) s x = -(x^2)⁻¹ :=
begin
rw differentiable_at.deriv_within (differentiable_at_inv x_ne_zero) hxs,
exact deriv_inv x_ne_zero
end
lemma has_fderiv_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_at (λx, x⁻¹) (smul_right 1 (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) x :=
has_deriv_at_inv x_ne_zero
lemma has_fderiv_within_at_inv (x_ne_zero : x ≠ 0) :
has_fderiv_within_at (λx, x⁻¹) (smul_right 1 (-(x^2)⁻¹) : 𝕜 →L[𝕜] 𝕜) s x :=
(has_fderiv_at_inv x_ne_zero).has_fderiv_within_at
lemma fderiv_inv (x_ne_zero : x ≠ 0) :
fderiv 𝕜 (λx, x⁻¹) x = smul_right 1 (-(x^2)⁻¹) :=
(has_fderiv_at_inv x_ne_zero).fderiv
lemma fderiv_within_inv (x_ne_zero : x ≠ 0) (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, x⁻¹) s x = smul_right 1 (-(x^2)⁻¹) :=
begin
rw differentiable_at.fderiv_within (differentiable_at_inv x_ne_zero) hxs,
exact fderiv_inv x_ne_zero
end
end inverse
section division
/-! ### Derivative of `x ↦ c x / d x` -/
variables {c d : 𝕜 → 𝕜} {c' d' : 𝕜}
lemma has_deriv_within_at.div
(hc : has_deriv_within_at c c' s x) (hd : has_deriv_within_at d d' s x) (hx : d x ≠ 0) :
has_deriv_within_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) s x :=
begin
have A : (d x)⁻¹ * (d x)⁻¹ * (c' * d x) = (d x)⁻¹ * c',
by rw [← mul_assoc, mul_comm, ← mul_assoc, ← mul_assoc, mul_inv_cancel hx, one_mul],
convert hc.mul ((has_deriv_at_inv hx).comp_has_deriv_within_at x hd),
simp [div_eq_inv_mul', pow_two, mul_inv', mul_add, A, sub_eq_add_neg],
ring
end
lemma has_deriv_at.div (hc : has_deriv_at c c' x) (hd : has_deriv_at d d' x) (hx : d x ≠ 0) :
has_deriv_at (λ y, c y / d y) ((c' * d x - c x * d') / (d x)^2) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hc.div hd hx
end
lemma differentiable_within_at.div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0) :
differentiable_within_at 𝕜 (λx, c x / d x) s x :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).differentiable_within_at
lemma differentiable_at.div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
differentiable_at 𝕜 (λx, c x / d x) x :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).differentiable_at
lemma differentiable_on.div
(hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) (hx : ∀ x ∈ s, d x ≠ 0) :
differentiable_on 𝕜 (λx, c x / d x) s :=
λx h, (hc x h).div (hd x h) (hx x h)
lemma differentiable.div
(hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) (hx : ∀ x, d x ≠ 0) :
differentiable 𝕜 (λx, c x / d x) :=
λx, (hc x).div (hd x) (hx x)
lemma deriv_within_div
(hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) (hx : d x ≠ 0)
(hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, c x / d x) s x
= ((deriv_within c s x) * d x - c x * (deriv_within d s x)) / (d x)^2 :=
((hc.has_deriv_within_at).div (hd.has_deriv_within_at) hx).deriv_within hxs
lemma deriv_div
(hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) (hx : d x ≠ 0) :
deriv (λx, c x / d x) x = ((deriv c x) * d x - c x * (deriv d x)) / (d x)^2 :=
((hc.has_deriv_at).div (hd.has_deriv_at) hx).deriv
end division
end
namespace polynomial
/-! ### Derivative of a polynomial -/
variables {x : 𝕜} {s : set 𝕜}
variable (p : polynomial 𝕜)
/-- The derivative (in the analysis sense) of a polynomial `p` is given by `p.derivative`. -/
protected lemma has_deriv_at (x : 𝕜) : has_deriv_at (λx, p.eval x) (p.derivative.eval x) x :=
begin
apply p.induction_on,
{ simp [has_deriv_at_const] },
{ assume p q hp hq,
convert hp.add hq;
simp },
{ assume n a h,
convert h.mul (has_deriv_at_id x),
{ ext y, simp [pow_add, mul_assoc] },
{ simp [pow_add], ring } }
end
protected theorem has_deriv_within_at (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, p.eval x) (p.derivative.eval x) s x :=
(p.has_deriv_at x).has_deriv_within_at
protected lemma differentiable_at : differentiable_at 𝕜 (λx, p.eval x) x :=
(p.has_deriv_at x).differentiable_at
protected lemma differentiable_within_at : differentiable_within_at 𝕜 (λx, p.eval x) s x :=
p.differentiable_at.differentiable_within_at
protected lemma differentiable : differentiable 𝕜 (λx, p.eval x) :=
λx, p.differentiable_at
protected lemma differentiable_on : differentiable_on 𝕜 (λx, p.eval x) s :=
p.differentiable.differentiable_on
@[simp] protected lemma deriv : deriv (λx, p.eval x) x = p.derivative.eval x :=
(p.has_deriv_at x).deriv
protected lemma deriv_within (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, p.eval x) s x = p.derivative.eval x :=
begin
rw differentiable_at.deriv_within p.differentiable_at hxs,
exact p.deriv
end
protected lemma continuous : continuous (λx, p.eval x) :=
p.differentiable.continuous
protected lemma continuous_on : continuous_on (λx, p.eval x) s :=
p.continuous.continuous_on
protected lemma continuous_at : continuous_at (λx, p.eval x) x :=
p.continuous.continuous_at
protected lemma continuous_within_at : continuous_within_at (λx, p.eval x) s x :=
p.continuous_at.continuous_within_at
protected lemma has_fderiv_at (x : 𝕜) :
has_fderiv_at (λx, p.eval x) (smul_right 1 (p.derivative.eval x) : 𝕜 →L[𝕜] 𝕜) x :=
by simpa [has_deriv_at_iff_has_fderiv_at] using p.has_deriv_at x
protected lemma has_fderiv_within_at (x : 𝕜) :
has_fderiv_within_at (λx, p.eval x) (smul_right 1 (p.derivative.eval x) : 𝕜 →L[𝕜] 𝕜) s x :=
(p.has_fderiv_at x).has_fderiv_within_at
@[simp] protected lemma fderiv : fderiv 𝕜 (λx, p.eval x) x = smul_right 1 (p.derivative.eval x) :=
(p.has_fderiv_at x).fderiv
protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) :
fderiv_within 𝕜 (λx, p.eval x) s x = smul_right 1 (p.derivative.eval x) :=
begin
rw differentiable_at.fderiv_within p.differentiable_at hxs,
exact p.fderiv
end
end polynomial
section pow
/-! ### Derivative of `x ↦ x^n` for `n : ℕ` -/
variables {x : 𝕜} {s : set 𝕜}
variable {n : ℕ }
lemma has_deriv_at_pow (n : ℕ) (x : 𝕜) : has_deriv_at (λx, x^n) ((n : 𝕜) * x^(n-1)) x :=
begin
convert (polynomial.C 1 * (polynomial.X)^n).has_deriv_at x,
{ simp },
{ rw [polynomial.derivative_monomial], simp }
end
theorem has_deriv_within_at_pow (n : ℕ) (x : 𝕜) (s : set 𝕜) :
has_deriv_within_at (λx, x^n) ((n : 𝕜) * x^(n-1)) s x :=
(has_deriv_at_pow n x).has_deriv_within_at
lemma differentiable_at_pow : differentiable_at 𝕜 (λx, x^n) x :=
(has_deriv_at_pow n x).differentiable_at
lemma differentiable_within_at_pow : differentiable_within_at 𝕜 (λx, x^n) s x :=
differentiable_at_pow.differentiable_within_at
lemma differentiable_pow : differentiable 𝕜 (λx:𝕜, x^n) :=
λx, differentiable_at_pow
lemma differentiable_on_pow : differentiable_on 𝕜 (λx, x^n) s :=
differentiable_pow.differentiable_on
lemma deriv_pow : deriv (λx, x^n) x = (n : 𝕜) * x^(n-1) :=
(has_deriv_at_pow n x).deriv
@[simp] lemma deriv_pow' : deriv (λx, x^n) = λ x, (n : 𝕜) * x^(n-1) :=
funext $ λ x, deriv_pow
lemma deriv_within_pow (hxs : unique_diff_within_at 𝕜 s x) :
deriv_within (λx, x^n) s x = (n : 𝕜) * x^(n-1) :=
(has_deriv_within_at_pow n x s).deriv_within hxs
lemma iter_deriv_pow' {k : ℕ} :
deriv^[k] (λx:𝕜, x^n) = λ x, ((finset.range k).prod (λ i, n - i):ℕ) * x^(n-k) :=
begin
induction k with k ihk,
{ simp only [one_mul, finset.prod_range_zero, nat.iterate_zero, nat.sub_zero, nat.cast_one] },
{ simp only [nat.iterate_succ', ihk, finset.prod_range_succ],
ext x,
rw [((has_deriv_at_pow (n - k) x).const_mul _).deriv, nat.cast_mul, mul_left_comm, mul_assoc,
nat.succ_eq_add_one, nat.sub_sub] }
end
lemma iter_deriv_pow {k : ℕ} :
deriv^[k] (λx:𝕜, x^n) x = ((finset.range k).prod (λ i, n - i):ℕ) * x^(n-k) :=
congr_fun iter_deriv_pow' x
end pow
section fpow
/-! ### Derivative of `x ↦ x^m` for `m : ℤ` -/
variables {x : 𝕜} {s : set 𝕜}
variable {m : ℤ}
lemma has_deriv_at_fpow (m : ℤ) (hx : x ≠ 0) :
has_deriv_at (λx, x^m) ((m : 𝕜) * x^(m-1)) x :=
begin
have : ∀ m : ℤ, 0 < m → has_deriv_at (λx, x^m) ((m:𝕜) * x^(m-1)) x,
{ assume m hm,
lift m to ℕ using (le_of_lt hm),
simp only [fpow_of_nat, int.cast_coe_nat],
convert has_deriv_at_pow _ _ using 2,
rw [← int.coe_nat_one, ← int.coe_nat_sub, fpow_coe_nat],
norm_cast at hm,
exact nat.succ_le_of_lt hm },
rcases lt_trichotomy m 0 with hm|hm|hm,
{ have := (has_deriv_at_inv _).comp _ (this (-m) (neg_pos.2 hm));
[skip, exact fpow_ne_zero_of_ne_zero hx _],
simp only [(∘), fpow_neg, one_div_eq_inv, inv_inv', smul_eq_mul] at this,
convert this using 1,
rw [pow_two, mul_inv', inv_inv', int.cast_neg, ← neg_mul_eq_neg_mul, neg_mul_neg,
← fpow_add hx, mul_assoc, ← fpow_add hx], congr, abel },
{ simp only [hm, fpow_zero, int.cast_zero, zero_mul, has_deriv_at_const] },
{ exact this m hm }
end
theorem has_deriv_within_at_fpow (m : ℤ) (hx : x ≠ 0) (s : set 𝕜) :
has_deriv_within_at (λx, x^m) ((m : 𝕜) * x^(m-1)) s x :=
(has_deriv_at_fpow m hx).has_deriv_within_at
lemma differentiable_at_fpow (hx : x ≠ 0) : differentiable_at 𝕜 (λx, x^m) x :=
(has_deriv_at_fpow m hx).differentiable_at
lemma differentiable_within_at_fpow (hx : x ≠ 0) :
differentiable_within_at 𝕜 (λx, x^m) s x :=
(differentiable_at_fpow hx).differentiable_within_at
lemma differentiable_on_fpow (hs : (0:𝕜) ∉ s) : differentiable_on 𝕜 (λx, x^m) s :=
λ x hxs, differentiable_within_at_fpow (λ hx, hs $ hx ▸ hxs)
-- TODO : this is true at `x=0` as well
lemma deriv_fpow (hx : x ≠ 0) : deriv (λx, x^m) x = (m : 𝕜) * x^(m-1) :=
(has_deriv_at_fpow m hx).deriv
lemma deriv_within_fpow (hxs : unique_diff_within_at 𝕜 s x) (hx : x ≠ 0) :
deriv_within (λx, x^m) s x = (m : 𝕜) * x^(m-1) :=
(has_deriv_within_at_fpow m hx s).deriv_within hxs
lemma iter_deriv_fpow {k : ℕ} (hx : x ≠ 0) :
deriv^[k] (λx:𝕜, x^m) x = ((finset.range k).prod (λ i, m - i):ℤ) * x^(m-k) :=
begin
induction k with k ihk generalizing x hx,
{ simp only [one_mul, finset.prod_range_zero, nat.iterate_zero, int.coe_nat_zero, sub_zero,
int.cast_one] },
{ rw [nat.iterate_succ', finset.prod_range_succ, int.cast_mul, mul_assoc, mul_left_comm, int.coe_nat_succ,
← sub_sub, ← ((has_deriv_at_fpow _ hx).const_mul _).deriv],
apply deriv_congr_of_mem_nhds,
apply eventually.mono _ @ihk,
exact mem_nhds_sets (is_open_neg $ is_closed_eq continuous_id continuous_const) hx }
end
end fpow
/-! ### Upper estimates on liminf and limsup -/
section real
variables {f : ℝ → ℝ} {f' : ℝ} {s : set ℝ} {x : ℝ} {r : ℝ}
lemma has_deriv_within_at.limsup_slope_le (hf : has_deriv_within_at f f' s x) (hr : f' < r) :
∀ᶠ z in nhds_within x (s \ {x}), (z - x)⁻¹ * (f z - f x) < r :=
has_deriv_within_at_iff_tendsto_slope.1 hf (mem_nhds_sets is_open_Iio hr)
lemma has_deriv_within_at.limsup_slope_le' (hf : has_deriv_within_at f f' s x)
(hs : x ∉ s) (hr : f' < r) :
∀ᶠ z in nhds_within x s, (z - x)⁻¹ * (f z - f x) < r :=
(has_deriv_within_at_iff_tendsto_slope' hs).1 hf (mem_nhds_sets is_open_Iio hr)
lemma has_deriv_within_at.liminf_right_slope_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : f' < r) :
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (f z - f x) < r :=
(hf.limsup_slope_le' (lt_irrefl x) hr).frequently (nhds_within_Ioi_self_ne_bot x)
end real
section real_space
open metric
variables {E : Type u} [normed_group E] [normed_space ℝ E] {f : ℝ → E} {f' : E} {s : set ℝ}
{x r : ℝ}
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`. -/
lemma has_deriv_within_at.limsup_norm_slope_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in nhds_within x s, ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
begin
have hr₀ : 0 < r, from lt_of_le_of_lt (norm_nonneg f') hr,
have A : ∀ᶠ z in nhds_within x (s \ {x}), ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from (has_deriv_within_at_iff_tendsto_slope.1 hf).norm (mem_nhds_sets is_open_Iio hr),
have B : ∀ᶠ z in nhds_within x {x}, ∥(z - x)⁻¹ • (f z - f x)∥ ∈ Iio r,
from mem_sets_of_superset self_mem_nhds_within
(singleton_subset_iff.2 $ by simp [hr₀]),
have C := mem_sup_sets.2 ⟨A, B⟩,
rw [← nhds_within_union, diff_union_self, nhds_within_union, mem_sup_sets] at C,
filter_upwards [C.1],
simp only [mem_set_of_eq, norm_smul, mem_Iio, normed_field.norm_inv],
exact λ _, id
end
/-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / ∥z - x∥` is less than `r` in some neighborhood of `x` within `s`.
In other words, the limit superior of this ratio as `z` tends to `x` along `s`
is less than or equal to `∥f'∥`.
This lemma is a weaker version of `has_deriv_within_at.limsup_norm_slope_le`
where `∥f z∥ - ∥f x∥` is replaced by `∥f z - f x∥`. -/
lemma has_deriv_within_at.limsup_slope_norm_le
(hf : has_deriv_within_at f f' s x) (hr : ∥f'∥ < r) :
∀ᶠ z in nhds_within x s, ∥z - x∥⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
apply (hf.limsup_norm_slope_le hr).mono,
assume z hz,
refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) _) hz,
exact inv_nonneg.2 (norm_nonneg _)
end
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`∥f z - f x∥ / ∥z - x∥` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`. See also `has_deriv_within_at.limsup_norm_slope_le`
for a stronger version using limit superior and any set `s`. -/
lemma has_deriv_within_at.liminf_right_norm_slope_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in nhds_within x (Ioi x), ∥z - x∥⁻¹ * ∥f z - f x∥ < r :=
(hf.limsup_norm_slope_le hr).frequently (nhds_within_Ioi_self_ne_bot x)
/-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ∥f'∥` the ratio
`(∥f z∥ - ∥f x∥) / (z - x)` is frequently less than `r` as `z → x+0`.
In other words, the limit inferior of this ratio as `z` tends to `x+0`
is less than or equal to `∥f'∥`.
See also
* `has_deriv_within_at.limsup_norm_slope_le` for a stronger version using
limit superior and any set `s`;
* `has_deriv_within_at.liminf_right_norm_slope_le` for a stronger version using
`∥f z - f x∥` instead of `∥f z∥ - ∥f x∥`. -/
lemma has_deriv_within_at.liminf_right_slope_norm_le
(hf : has_deriv_within_at f f' (Ioi x) x) (hr : ∥f'∥ < r) :
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (∥f z∥ - ∥f x∥) < r :=
begin
have := (hf.limsup_slope_norm_le hr).frequently (nhds_within_Ioi_self_ne_bot x),
refine this.mp (eventually.mono self_mem_nhds_within _),
assume z hxz hz,
rwa [real.norm_eq_abs, abs_of_pos (sub_pos_of_lt hxz)] at hz
end
end real_space
|
1c44175484d41182e9e95f2a72917cfd586d48ca | aa5a655c05e5359a70646b7154e7cac59f0b4132 | /stage0/src/Lean/Meta/Tactic/Revert.lean | ff2394a8773bafa5abfa2aeaf8dbaab882be81a2 | [
"Apache-2.0"
] | permissive | lambdaxymox/lean4 | ae943c960a42247e06eff25c35338268d07454cb | 278d47c77270664ef29715faab467feac8a0f446 | refs/heads/master | 1,677,891,867,340 | 1,612,500,005,000 | 1,612,500,005,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 937 | 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.Meta.Tactic.Util
namespace Lean.Meta
def revert (mvarId : MVarId) (fvars : Array FVarId) (preserveOrder : Bool := false) : MetaM (Array FVarId × MVarId) := do
if fvars.isEmpty then
pure (fvars, mvarId)
else withMVarContext mvarId do
let tag ← getMVarTag mvarId
checkNotAssigned mvarId `revert
-- Set metavariable kind to natural to make sure `elimMVarDeps` will assign it.
setMVarKind mvarId MetavarKind.natural
let (e, toRevert) ←
try
liftMkBindingM <| MetavarContext.revert (fvars.map mkFVar) mvarId preserveOrder
finally
setMVarKind mvarId MetavarKind.syntheticOpaque
let mvar := e.getAppFn
setMVarTag mvar.mvarId! tag
return (toRevert.map Expr.fvarId!, mvar.mvarId!)
end Lean.Meta
|
2e448f617413102886d9bedea243a0980d9cd508 | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/category_theory/groupoid.lean | 43273a2472f77f079a4fbba80831147628083323 | [
"Apache-2.0"
] | permissive | roro47/mathlib | 761fdc002aef92f77818f3fef06bf6ec6fc1a28e | 80aa7d52537571a2ca62a3fdf71c9533a09422cf | refs/heads/master | 1,599,656,410,625 | 1,573,649,488,000 | 1,573,649,488,000 | 221,452,951 | 0 | 0 | Apache-2.0 | 1,573,647,693,000 | 1,573,647,692,000 | null | UTF-8 | Lean | false | false | 1,434 | lean | /-
Copyright (c) 2018 Reid Barton All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import category_theory.category
import category_theory.isomorphism
import data.equiv.basic
namespace category_theory
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
/-- A `groupoid` is a category such that all morphisms are isomorphisms. -/
class groupoid (obj : Type u) extends category.{v} obj : Type (max u (v+1)) :=
(inv : Π {X Y : obj}, (X ⟶ Y) → (Y ⟶ X))
(inv_comp' : ∀ {X Y : obj} (f : X ⟶ Y), comp (inv f) f = id Y . obviously)
(comp_inv' : ∀ {X Y : obj} (f : X ⟶ Y), comp f (inv f) = id X . obviously)
restate_axiom groupoid.inv_comp'
restate_axiom groupoid.comp_inv'
attribute [simp] groupoid.inv_comp groupoid.comp_inv
abbreviation large_groupoid (C : Type (u+1)) : Type (u+1) := groupoid.{u} C
abbreviation small_groupoid (C : Type u) : Type (u+1) := groupoid.{u} C
section
variables {C : Type u} [𝒞 : groupoid.{v} C] {X Y : C}
include 𝒞
instance is_iso.of_groupoid (f : X ⟶ Y) : is_iso f := { inv := groupoid.inv f }
variables (X Y)
/-- In a groupoid, isomorphisms are equivalent to morphisms. -/
def groupoid.iso_equiv_hom : (X ≅ Y) ≃ (X ⟶ Y) :=
{ to_fun := iso.hom,
inv_fun := λ f, as_iso f,
left_inv := λ i, iso.ext rfl,
right_inv := λ f, rfl }
end
end category_theory
|
1076ad82f7f017a120770374918246db6ab8e6f9 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /doc/examples/widgets.lean | 886f7914b6373ce63e92cde933f9473f25fb83bf | [
"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 | 9,846 | lean | import Lean
open Lean Widget
/-!
# The user-widgets system
Proving and programming are inherently interactive tasks. Lots of mathematical objects and data
structures are visual in nature. *User widgets* let you associate custom interactive UIs with
sections of a Lean document. User widgets are rendered in the Lean infoview.

## Trying it out
To try it out, simply type in the following code and place your cursor over the `#widget` command.
-/
@[widget]
def helloWidget : UserWidgetDefinition where
name := "Hello"
javascript := "
import * as React from 'react';
export default function(props) {
const name = props.name || 'world'
return React.createElement('p', {}, name + '!')
}"
#widget helloWidget .null
/-!
If you want to dive into a full sample right away, check out
[`RubiksCube`](https://github.com/leanprover/lean4-samples/blob/main/RubiksCube/).
Below, we'll explain the system piece by piece.
⚠️ WARNING: All of the user widget APIs are **unstable** and subject to breaking changes.
## Widget sources and instances
A *widget source* is a valid JavaScript [ESModule](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
which exports a [React component](https://reactjs.org/docs/components-and-props.html). To access
React, the module must use `import * as React from 'react'`. Our first example of a widget source
is of course the value of `helloWidget.javascript`.
We can register a widget source with the `@[widget]` attribute, giving it a friendlier name
in the `name` field. This is bundled together in a `UserWidgetDefinition`.
A *widget instance* is then the identifier of a `UserWidgetDefinition` (so `` `helloWidget ``,
not `"Hello"`) associated with a range of positions in the Lean source code. Widget instances
are stored in the *infotree* in the same manner as other information about the source file
such as the type of every expression. In our example, the `#widget` command stores a widget instance
with the entire line as its range. We can think of a widget instance as an instruction for the
infoview: "when the user places their cursor here, please render the following widget".
Every widget instance also contains a `props : Json` value. This value is passed as an argument
to the React component. In our first invocation of `#widget`, we set it to `.null`. Try out what
happens when you type in:
-/
#widget helloWidget (Json.mkObj [("name", "<your name here>")])
/-!
💡 NOTE: The RPC system presented below does not depend on JavaScript. However the primary use case
is the web-based infoview in VSCode.
## Querying the Lean server
Besides enabling us to create cool client-side visualizations, user widgets come with the ability
to communicate with the Lean server. Thanks to this, they have the same metaprogramming capabilities
as custom elaborators or the tactic framework. To see this in action, let's implement a `#check`
command as a web input form. This example assumes some familiarity with React.
The first thing we'll need is to create an *RPC method*. Meaning "Remote Procedure Call", this
is basically a Lean function callable from widget code (possibly remotely over the internet).
Our method will take in the `name : Name` of a constant in the environment and return its type.
By convention, we represent the input data as a `structure`. Since it will be sent over from JavaScript,
we need `FromJson` and `ToJson`. We'll see below why the position field is needed.
-/
structure GetTypeParams where
/-- Name of a constant to get the type of. -/
name : Name
/-- Position of our widget instance in the Lean file. -/
pos : Lsp.Position
deriving FromJson, ToJson
/-!
After its arguments, we define the `getType` method. Every RPC method executes in the `RequestM`
monad and must return a `RequestTask α` where `α` is its "actual" return type. The `Task` is so
that requests can be handled concurrently. A first guess for `α` might be `Expr`. However,
expressions in general can be large objects which depend on an `Environment` and `LocalContext`.
Thus we cannot directly serialize an `Expr` and send it to the widget. Instead, there are two
options:
- One is to send a *reference* which points to an object residing on the server. From JavaScript's
point of view, references are entirely opaque, but they can be sent back to other RPC methods for
further processing.
- Two is to pretty-print the expression and send its textual representation called `CodeWithInfos`.
This representation contains extra data which the infoview uses for interactivity. We take this
strategy here.
RPC methods execute in the context of a file, but not any particular `Environment` so they don't
know about the available `def`initions and `theorem`s. Thus, we need to pass in a position at which
we want to use the local `Environment`. This is why we store it in `GetTypeParams`. The `withWaitFindSnapAtPos`
method launches a concurrent computation whose job is to find such an `Environment` and a bit
more information for us, in the form of a `snap : Snapshot`. With this in hand, we can call
`MetaM` procedures to find out the type of `name` and pretty-print it.
-/
open Server RequestM in
@[server_rpc_method]
def getType (params : GetTypeParams) : RequestM (RequestTask CodeWithInfos) :=
withWaitFindSnapAtPos params.pos fun snap => do
runTermElabM snap do
let name ← resolveGlobalConstNoOverloadCore params.name
let c ← try getConstInfo name
catch _ => throwThe RequestError ⟨.invalidParams, s!"no constant named '{name}'"⟩
Widget.ppExprTagged c.type
/-!
## Using infoview components
Now that we have all we need on the server side, let's write the widget source. By importing
`@leanprover/infoview`, widgets can render UI components used to implement the infoview itself.
For example, the `<InteractiveCode>` component displays expressions with `term : type` tooltips
as seen in the goal view. We will use it to implement our custom `#check` display.
⚠️ WARNING: Like the other widget APIs, the infoview JS API is **unstable** and subject to breaking changes.
The code below demonstrates useful parts of the API. To make RPC method calls, we use the `RpcContext`.
The `useAsync` helper packs the results of a call into an `AsyncState` structure which indicates
whether the call has resolved successfully, has returned an error, or is still in-flight. Based
on this we either display an `InteractiveCode` with the type, `mapRpcError` the error in order
to turn it into a readable message, or show a `Loading..` message, respectively.
-/
@[widget]
def checkWidget : UserWidgetDefinition where
name := "#check as a service"
javascript := "
import * as React from 'react';
const e = React.createElement;
import { RpcContext, InteractiveCode, useAsync, mapRpcError } from '@leanprover/infoview';
export default function(props) {
const rs = React.useContext(RpcContext)
const [name, setName] = React.useState('getType')
const st = useAsync(() =>
rs.call('getType', { name, pos: props.pos }), [name, rs, props.pos])
const type = st.state === 'resolved' ? st.value && e(InteractiveCode, {fmt: st.value})
: st.state === 'rejected' ? e('p', null, mapRpcError(st.error).message)
: e('p', null, 'Loading..')
const onChange = (event) => { setName(event.target.value) }
return e('div', null,
e('input', { value: name, onChange }), ' : ', type)
}
"
/-!
Finally we can try out the widget.
-/
#widget checkWidget .null
/-!

## Building widget sources
While typing JavaScript inline is fine for a simple example, for real developments we want to use
packages from NPM, a proper build system, and JSX. Thus, most actual widget sources are built with
Lake and NPM. They consist of multiple files and may import libraries which don't work as ESModules
by default. On the other hand a widget source must be a single, self-contained ESModule in the form
of a string. Readers familiar with web development may already have guessed that to obtain such a
string, we need a *bundler*. Two popular choices are [`rollup.js`](https://rollupjs.org/guide/en/)
and [`esbuild`](https://esbuild.github.io/). If we go with `rollup.js`, to make a widget work with
the infoview we need to:
- Set [`output.format`](https://rollupjs.org/guide/en/#outputformat) to `'es'`.
- [Externalize](https://rollupjs.org/guide/en/#external) `react`, `react-dom`, `@leanprover/infoview`.
These libraries are already loaded by the infoview so they should not be bundled.
In the RubiksCube sample, we provide a working `rollup.js` build configuration in
[rollup.config.js](https://github.com/leanprover/lean4-samples/blob/main/RubiksCube/widget/rollup.config.js).
## Inserting text
We can also instruct the editor to insert text, copy text to the clipboard, or
reveal a certain location in the document.
To do this, use the `React.useContext(EditorContext)` React context.
This will return an `EditorConnection` whose `api` field contains a number of methods to
interact with the text editor.
You can see the full API for this [here](https://github.com/leanprover/vscode-lean4/blob/master/lean4-infoview-api/src/infoviewApi.ts#L52)
-/
@[widget]
def insertTextWidget : UserWidgetDefinition where
name := "textInserter"
javascript := "
import * as React from 'react';
const e = React.createElement;
import { EditorContext } from '@leanprover/infoview';
export default function(props) {
const editorConnection = React.useContext(EditorContext)
function onClick() {
editorConnection.api.insertText('-- hello!!!', 'above')
}
return e('div', null, e('button', { value: name, onClick }, 'insert'))
}
"
/-! Finally, we can try this out: -/
#widget insertTextWidget .null
|
586f037153d51f928adec1278f4a7844ed93d0dc | 94e33a31faa76775069b071adea97e86e218a8ee | /src/measure_theory/integral/circle_integral_transform.lean | 7dbb237f5f6db12d69f8141e1dc3ff726aed5f45 | [
"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 | 7,915 | lean | /-
Copyright (c) 2022 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import analysis.complex.cauchy_integral
import analysis.analytic.basic
import analysis.calculus.parametric_interval_integral
import data.complex.basic
import measure_theory.integral.circle_integral
/-!
# Circle integral transform
In this file we define the circle integral transform of a function `f` with complex domain. This is
defined as $(2πi)^{-1}\frac{f(x)}{x-w}$ where `x` moves along a circle. We then prove some basic
facts about these functions.
These results are useful for proving that the uniform limit of a sequence of holomorphic functions
is holomorphic.
-/
open set measure_theory metric filter function
open_locale interval real
noncomputable theory
variables {E : Type} [normed_group E] [normed_space ℂ E] (R : ℝ) (z w : ℂ)
namespace complex
/-- Given a function `f : ℂ → E`, `circle_transform R z w f` is the functions mapping `θ` to
`(2 * ↑π * I)⁻¹ • deriv (circle_map z R) θ • ((circle_map z R θ) - w)⁻¹ • f (circle_map z R θ)`.
If `f` is differentiable and `w` is in the interior of the ball, then the integral from `0` to
`2 * π` of this gives the value `f(w)`. -/
def circle_transform (f : ℂ → E) (θ : ℝ) : E :=
(2 * ↑π * I)⁻¹ • deriv (circle_map z R) θ • ((circle_map z R θ) - w)⁻¹ • f (circle_map z R θ)
/-- The derivative of `circle_transform` w.r.t `w`.-/
def circle_transform_deriv (f : ℂ → E) (θ : ℝ) : E :=
(2 * ↑π * I)⁻¹ • deriv (circle_map z R) θ • ((circle_map z R θ - w) ^ 2)⁻¹ • f (circle_map z R θ)
lemma circle_transform_deriv_periodic (f : ℂ → E) :
periodic (circle_transform_deriv R z w f) (2 * π) :=
begin
have := periodic_circle_map,
simp_rw periodic at *,
intro x,
simp_rw [circle_transform_deriv, this],
congr' 2,
simp [this],
end
lemma circle_transform_deriv_eq (f : ℂ → E) :
circle_transform_deriv R z w f =
(λ θ, (circle_map z R θ - w)⁻¹ • (circle_transform R z w f θ)) :=
begin
ext,
simp_rw [circle_transform_deriv, circle_transform, ←mul_smul, ←mul_assoc],
ring_nf,
rw inv_pow,
congr,
ring,
end
lemma integral_circle_transform [complete_space E] (f : ℂ → E) :
∫ (θ : ℝ) in 0..2 * π, circle_transform R z w f θ =
(2 * ↑π * I)⁻¹ • ∮ z in C(z, R), (z - w)⁻¹ • f z :=
begin
simp_rw [circle_transform, circle_integral, deriv_circle_map, circle_map],
simp,
end
lemma continuous_circle_transform {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}
(hf : continuous_on f $ sphere z R) (hw : w ∈ ball z R) :
continuous (circle_transform R z w f) :=
begin
apply_rules [continuous.smul, continuous_const],
simp_rw deriv_circle_map,
apply_rules [continuous.mul, (continuous_circle_map 0 R), continuous_const],
{ apply continuous_circle_map_inv hw },
{ apply continuous_on.comp_continuous hf (continuous_circle_map z R),
exact (λ _, (circle_map_mem_sphere _ hR.le) _) },
end
lemma continuous_circle_transform_deriv {R : ℝ} (hR : 0 < R) {f : ℂ → E} {z w : ℂ}
(hf : continuous_on f (sphere z R)) (hw : w ∈ ball z R) :
continuous (circle_transform_deriv R z w f) :=
begin
rw circle_transform_deriv_eq,
exact (continuous_circle_map_inv hw).smul (continuous_circle_transform hR hf hw),
end
/--A useful bound for circle integrals (with complex codomain)-/
def circle_transform_bounding_function (R : ℝ) (z : ℂ) (w : ℂ × ℝ) : ℂ :=
circle_transform_deriv R z w.1 (λ x, 1) w.2
lemma continuous_on_prod_circle_transform_function {R r : ℝ} (hr : r < R) {z : ℂ} :
continuous_on (λ (w : ℂ × ℝ), ((circle_map z R w.snd - w.fst)⁻¹) ^ 2)
((closed_ball z r) ×ˢ (⊤ : set ℝ)) :=
begin
simp_rw ←one_div,
apply_rules [continuous_on.pow, continuous_on.div, continuous_on_const],
refine ((continuous_circle_map z R).continuous_on.comp continuous_on_snd (λ _, and.right)).sub
(continuous_on_id.comp continuous_on_fst (λ _, and.left)),
simp only [mem_prod, ne.def, and_imp, prod.forall],
intros a b ha hb,
have ha2 : a ∈ ball z R, by {simp at *, linarith,},
exact (sub_ne_zero.2 (circle_map_ne_mem_ball ha2 b)),
end
lemma continuous_on_abs_circle_transform_bounding_function {R r : ℝ} (hr : r < R) (z : ℂ) :
continuous_on (abs ∘ (λ t, circle_transform_bounding_function R z t))
((closed_ball z r) ×ˢ (⊤ : set ℝ) : set $ ℂ × ℝ) :=
begin
have : continuous_on (circle_transform_bounding_function R z) (closed_ball z r ×ˢ (⊤ : set ℝ)),
{ apply_rules [continuous_on.smul, continuous_on_const],
simp only [deriv_circle_map],
have c := (continuous_circle_map 0 R).continuous_on,
apply_rules [continuous_on.mul, c.comp continuous_on_snd (λ _, and.right), continuous_on_const],
simp_rw ←inv_pow,
apply continuous_on_prod_circle_transform_function hr, },
refine continuous_abs.continuous_on.comp this _,
show maps_to _ _ (⊤ : set ℂ),
simp [maps_to],
end
lemma abs_circle_transform_bounding_function_le {R r : ℝ} (hr : r < R) (hr' : 0 ≤ r) (z : ℂ) :
∃ (x : ((closed_ball z r) ×ˢ [0, 2 * π] : set $ ℂ × ℝ)),
∀ (y : ((closed_ball z r) ×ˢ [0, 2 * π] : set $ ℂ × ℝ)),
abs (circle_transform_bounding_function R z y) ≤ abs (circle_transform_bounding_function R z x) :=
begin
have cts := continuous_on_abs_circle_transform_bounding_function hr z,
have comp : is_compact (((closed_ball z r) ×ˢ [0, 2 * π]) : set (ℂ × ℝ)),
{ apply_rules [is_compact.prod, proper_space.is_compact_closed_ball z r, is_compact_interval], },
have none := (nonempty_closed_ball.2 hr').prod nonempty_interval,
simpa using is_compact.exists_forall_ge comp none (cts.mono (by { intro z, simp, tauto })),
end
/-- The derivative of a `circle_transform` is locally bounded. -/
lemma circle_transform_deriv_bound {R : ℝ} (hR : 0 < R) {z x : ℂ} {f : ℂ → ℂ}
(hx : x ∈ ball z R) (hf : continuous_on f (sphere z R)) :
∃ (B ε : ℝ), 0 < ε ∧ ball x ε ⊆ ball z R ∧
(∀ (t : ℝ) (y ∈ ball x ε), ∥circle_transform_deriv R z y f t∥ ≤ B) :=
begin
obtain ⟨r, hr, hrx⟩ := exists_lt_mem_ball_of_mem_ball hx,
obtain ⟨ε', hε', H⟩ := exists_ball_subset_ball hrx,
obtain ⟨⟨⟨a, b⟩, ⟨ha, hb⟩⟩, hab⟩ := abs_circle_transform_bounding_function_le hr
(pos_of_mem_ball hrx).le z,
let V : ℝ → (ℂ → ℂ) := λ θ w, circle_transform_deriv R z w (λ x, 1) θ,
have funccomp : continuous_on (λ r , abs (f r)) (sphere z R),
by { have cabs : continuous_on abs ⊤ := by apply continuous_abs.continuous_on,
apply cabs.comp (hf), rw maps_to, tauto,},
have sbou := is_compact.exists_forall_ge (is_compact_sphere z R)
(normed_space.sphere_nonempty.2 hR.le) funccomp,
obtain ⟨X, HX, HX2⟩ := sbou,
refine ⟨abs (V b a) * abs (f X), ε' , hε', subset.trans H (ball_subset_ball hr.le), _ ⟩,
intros y v hv,
obtain ⟨y1, hy1, hfun⟩ := periodic.exists_mem_Ico₀
(circle_transform_deriv_periodic R z v f) real.two_pi_pos y,
have hy2: y1 ∈ [0, 2*π], by {convert (Ico_subset_Icc_self hy1),
simp [interval_of_le real.two_pi_pos.le]},
have := mul_le_mul (hab ⟨⟨v, y1⟩, ⟨ball_subset_closed_ball (H hv), hy2⟩⟩)
(HX2 (circle_map z R y1) (circle_map_mem_sphere z hR.le y1)) (abs_nonneg _) (abs_nonneg _),
simp_rw hfun,
simp only [circle_transform_bounding_function, circle_transform_deriv, V, norm_eq_abs,
algebra.id.smul_eq_mul, deriv_circle_map, abs_mul, abs_circle_map_zero, abs_I, mul_one,
←mul_assoc, mul_inv_rev, inv_I, abs_neg, abs_inv, abs_of_real, one_mul, abs_two, abs_pow,
mem_ball, gt_iff_lt, subtype.coe_mk, set_coe.forall, mem_prod, mem_closed_ball, and_imp,
prod.forall, normed_space.sphere_nonempty, mem_sphere_iff_norm] at *,
exact this,
end
end complex
|
e437f453346d41c2fc2f19fab3c240c2d2d75aa7 | 274261f7150b4ed5f1962f172c9357591be8a2b5 | /src/lists.lean | c664a8c12fc7fe5acfab280ad5f5582f45f9ffb3 | [] | no_license | rspencer01/lean_representation_theory | 219ea1edf4b9897b2997226b54473e44e1538b50 | 2eef2b4b39d99d7ce71bec7bbc3dcc2f7586fcb5 | refs/heads/master | 1,588,133,157,029 | 1,571,689,957,000 | 1,571,689,957,000 | 175,835,785 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,831 | lean | import data.list
universes U₁ U₂
def nonempty_list (γ : Type U₁) := {l : list γ // l ≠ []}
namespace nonempty_list
variable {γ : Type U₁}
@[simp]
def last (l : nonempty_list γ) := list.last l.val l.property
@[simp]
def head : nonempty_list γ → γ
| ⟨[] , h ⟩ := absurd rfl h
| ⟨ x :: t , _ ⟩ := x
end nonempty_list
namespace list
variables {α : Type U₁} {β : Type U₂}
-- Much like head, but doesn't require α to be inhabited
@[simp] def head'': Π (L : list α), L ≠ [] → α
| [] h := absurd rfl h
| (x :: xs) h := x
variables {R : α → α → Prop} {x y : α} {L L₁ L₂ : list α}
@[simp]
lemma chain'_desc_left : chain' R (x :: L) → chain' R L := by cases L; simp[chain']
def chain'_apply_between (f : Π(a b : α), (R a b) → β) : Π (L : list α), list.chain' R L → list β
| [] h := []
| [x] h := []
| (x :: y :: xs) h := (f x y (rel_of_chain_cons h)) ::
(chain'_apply_between (y :: xs) (chain'_desc_left h) )
@[simp]
lemma chain'_of_two : chain' R [x, y] ↔ R x y := by dunfold chain'; exact chain_singleton
lemma chain'_of_first_two : chain' R (x :: y :: L) → R x y := by dunfold chain'; simp; exact λ a b, a
lemma chain'_append : Π (L₁ : list α) (h : L₁ ≠ []) (x : α), (R (L₁.last h) x) → (chain' R L₁) → chain' R (L₁ ++ [x])
| [] h _ _ _ := absurd rfl h
| [a] h x h₁ h₂ := (by simp; assumption)
| (a :: b :: l) h x h₁ h₂ := iff.elim_right (@chain'_split α R b [a] (l ++ [x]))
⟨ iff.elim_right chain'_of_two (chain'_of_first_two h₂),
chain'_append (b :: l) _ x h₁ (chain'_desc_left h₂) ⟩
lemma chain'_concat' : Π (L₁ L₂ : nonempty_list α), (R L₁.last L₂.head) → (chain' R L₁.val) → (chain' R L₂.val) → chain' R (L₁.val ++ L₂.val)
| ⟨ [] , h₁ ⟩ _ _ _ _ := absurd rfl h₁
| _ ⟨ [] , h₁ ⟩ _ _ _ := absurd rfl h₁
| ⟨ x₁ :: l₁ , h₁ ⟩ ⟨ x₂ :: l₂ , h₂ ⟩ h₃ s₁ s₂ :=
begin
intros;
apply iff.elim_right chain'_split;
simp;
apply and.intro,
have k : nonempty_list.head ⟨x₂ :: l₂, h₂⟩ = x₂ := rfl,
cases l₁,
simp,
have j : nonempty_list.last ⟨[x₁], h₁⟩ = x₁ := rfl,
have l : chain' R [x₁ , x₂] := iff.elim_right (@chain'_of_two α R x₁ x₂) h₃,
exact (iff.elim_left chain'_of_two) l,
simp,
apply @chain'_append α R (x₁ :: l₁_hd :: l₁_tl),
apply h₃,
assumption,
assumption
end
def apply_between (f : α → α → β) : list α → list β
| [] := []
| [x] := []
| (x :: y :: xs) := (f x y) :: apply_between (y :: xs)
@[simp]
lemma tail_of_append (x y : α) (l : list α) : tail (l ++ [y,x]) = tail (l ++ [y]) ++ [x] :=
by cases l; repeat {simp}
lemma rev_init_rev_tail : Π (l : list α), l.init.reverse = l.reverse.tail
| [] := rfl
| [x] := rfl
| (x :: y :: l) := (by simp[init, rev_init_rev_tail]; finish)
lemma rev_init_rev_tail_2 : Π (l : list α), l.reverse.init = l.tail.reverse :=
begin
intros,
set l2 := l.reverse with l2h,
calc l.reverse.init = l2.reverse.reverse.init : by rw [l2h,reverse_reverse]
... = l2.reverse.reverse.init.reverse.reverse : by simp
... = l2.reverse.reverse.reverse.tail.reverse : by rw rev_init_rev_tail
... = l.reverse.reverse.tail.reverse : by rw [l2h,reverse_reverse]
... = l.tail.reverse : by rw reverse_reverse
end
lemma rev_init_rev_tail' : Π (l : list α), l.init = l.reverse.tail.reverse := λ l,
calc l.init = l.init.reverse.reverse : by rw reverse_reverse
... = l.reverse.tail.reverse : by rw rev_init_rev_tail
@[simp] def rev_rel : (α → α → Prop) → (α → α → Prop) := λ S x y, S y x
lemma chain_rev : Π (L : list α) , chain' R L → chain' (rev_rel R) L.reverse
| [] h := by simp
| [x] h := by simp; exact chain.nil
| (x :: y :: l) h := begin
rw reverse_cons,
rw reverse_cons,
simp,
apply chain'_split.2,
rw (reverse_cons y l).symm,
have h2 : chain' R (y :: l) := (chain_cons.1 h).elim_right,
split,
exact chain_rev _ h2,
apply chain'_of_two.2,
exact (chain_cons.1 h).elim_left
end
lemma chain'_init' : Π (L₁ : list α), chain' R L₁.reverse → chain' R L₁.reverse.init :=
begin
intros,
rw rev_init_rev_tail',
apply chain_rev,
simp,
cases L₁,
simp,
simp,
have h : chain' (rev_rel R) (L₁_hd :: L₁_tl) := begin
intros,
rw (reverse_reverse (L₁_hd :: L₁_tl)).symm,
exact chain_rev (L₁_hd :: L₁_tl).reverse a,
end,
exact chain'_desc_left h
end
lemma chain'_init : Π (L₁ : list α), chain' R L₁ → chain' R L₁.init :=
begin
intros,
set L₂ := L₁.reverse with Lh,
rw (reverse_reverse (L₁)).symm,
rw Lh.symm,
apply chain'_init',
rw Lh,
rw reverse_reverse,
assumption
end
lemma chain'_trans_last : Π (L : list α) [reflexive R] [transitive R] [chain' R L] (h : L ≠ []), ∀ (x ∈ L), R x (L.last h)
| [] _ _ _ h := absurd rfl h
| [x] h _ _ _ := begin
intros,
simp,
rw list.eq_of_mem_singleton H,
apply h x
end
| (x :: y :: l) h₁ h₂ h₃ _ := begin
intros,
cases H,
have I : R x y := chain'_of_first_two h₃,
have J : R y (last (y :: l) (by simp)) := @chain'_trans_last (y :: l) h₁ h₂ (chain'_desc_left h₃) (by simp) y (by simp),
have K : R x (last (y :: l) (by simp)) := h₂ I J,
rw last_cons,
rw H,
exact K,
rw last_cons,
exact @chain'_trans_last (y :: l) h₁ h₂ (chain'_desc_left h₃) (by simp) x_1 H
end
def map₃ : Π (L : list α) (f : Π (a : α), a ∈ L → β), list β
| [] _ := []
| (x :: y) f := f x (mem_cons_self x y) :: map₃ y (λ z h, f z (mem_cons_of_mem _ h))
variables (p : α → Prop) [preorder α]
def map₄ : Π (L : list α) (f : Π (a : α), a ∈ L → p a), list {x : α // p x}
| [] _ := []
| (x :: y) f := ⟨x, f x (mem_cons_self x y)⟩ :: map₄ y (λ z h, f z (mem_cons_of_mem _ h))
theorem chain'_map₄ : Π (L : list α) (f : Π (a : α), a ∈ L → p a),
chain' (≤) L → chain' (≤) (map₄ p L (λ a h, (f a h)))
| [] _ c := (by dunfold map₄; exact (chain'_map (λ (a : {x // p x}), a.val)).mp c)
| [x] _ c := begin
intros,
exact (chain'_map (λ (a : {x // p x}), a.val)).mp c
end
| (x :: y :: l) f c := begin
intros,
apply chain.cons,
apply chain'_of_first_two c,
exact chain'_map₄ (y :: l) (λ z h, f z (mem_cons_of_mem _ h)) (chain'_desc_left c)
end
end list
|
ed033c3d9115b870b961fe086f4ee1bb1d89c390 | 3446e92e64a5de7ed1f2109cfb024f83cd904c34 | /src/game/world1/level4.lean | fa7f80a6bd277f22793616ffd8092ba74c067f7c | [] | no_license | kckennylau/natural_number_game | 019f4a5f419c9681e65234ecd124c564f9a0a246 | ad8c0adaa725975be8a9f978c8494a39311029be | refs/heads/master | 1,598,784,137,722 | 1,571,905,156,000 | 1,571,905,156,000 | 218,354,686 | 0 | 0 | null | 1,572,373,319,000 | 1,572,373,318,000 | null | UTF-8 | Lean | false | false | 4,228 | lean | import mynat.definition -- hide
namespace mynat -- hide
/-
# World 1 : Tutorial world
## level 4: Peano's axioms.
Way back on page 1 we imported a file called `mynat.definition`.
This gave us the type `mynat` of natural numbers. But it
also gave us some other things, which we'll take a look at now:
* a term `0 : mynat`, interpreted as the number zero.
* a function `succ : mynat → mynat`, with `succ n` interpreted as "the number after n".
* The theorem `zero_ne_succ : ∀ a : mynat, zero ≠ succ(a)`.
This is the axiom that zero isn't a successor. The name means "zero not equal to succ".
* The theorem `succ_inj : ∀ a b : mynat, succ(a) = succ(b) → a = b`.
This is the theorem that `succ` is injective, and the theorem name indicates this.
* The principle of mathematical induction.
These are the five axioms isolated by Peano, which uniquely characterise
the natural numbers. If you've not seen them before, I guess they might
look intimidating, so let's just go through them briefly. Firsty, notice
that they are all standard statements about the natural numbers $\{0,1,2,3,\ldots\}$.
The first axiom says that 0 is a natural number. The second says that there
is a `succ` function which eats a number and spits out the number after it,
so succ(0)=1, succ(1)=2 and so on. Then there are two theorems, both of
which are obvious. `zero_ne_succ` says that there's no number before 0,
and `succ_inj` says that if the
number after `a` equals the number after `b`, then `a = b`. It is this fact
which guarantees that there are infinitely many natural numbers!
Peano's last axiom is the principle of mathematical induction. This is a deeper
fact. It says that if we have infinitely many true/false statements $P(0)$, $P(1)$,
$P(2)$ and so on, and if $P(0)$ is true, and if for every natural number $d$
we know that $P(d)$ implies $P(succ(d))$, then $P(n)$ must be true for every
natural number $n$. One can think of it as saying that every natural number
can be built by starting at 0 and then applying `succ` a finite number of times.
Peano's insights were firstly that these axioms completely characterise
the natural numbers, and secondly that these axioms alone can be used to build
a whole bunch of other structure on the natural numbers, for example
addition, multiplication and so on.
This game is all about seeing how far these axioms of Peano will take us.
The import also gives us usual numerical notation
0,1,2,3,4,5 etc, with `1 = succ(0)`, `2=succ(1)` and so on. We will only
really be concerned with 0 and 1, and it's hence useful to know that
`one_eq_succ_zero` is a proof of the theorem that `1 = succ(0)`.
Let's practice our use of the `rw` tactic in the following example.
Our hypothesis `h` is a proof that `b = succ(a)` and we want to prove that
`succ(b)=succ(succ(a))`. In words, we're going to prove that if
`b` is the number after `a` then `succ(b)` is the number after `succ(a)`.
Now `h` gives us a formula for `b` and we just want to substitute in.
This is exactly what the `rw` tactic does*.
Before you delete the sorry and write
`rw h,`
and hit enter whilst not forgetting the comma, try and figure out
what the goal will become. The answer: it will become `succ(succ(a))=succ(succ(a))`,
and that goal is of the form `X = X` (if the goal goes onto a
second line, resize the top right window -- make it wider by dragging
its left hand edge). You can prove this new goal with
`refl,`
on the line after `rw h`,. Don't forget blah blah blah.
**Important note** : the tactics `rw` and `exact` both expect
a proof afterwards (e.g. `rw h1,`, `exact h2,`), But `refl,` is just `refl,`.
Note also that the system sometimes drops brackets when they're not
necessary, and `succ b` just means `succ(b)`.
You may be wondering why we keep writing `succ(b)` instead of `b+1`. This
is because we haven't defined addition yet! On the next level, the final level
of Tutorial World, we will introduce addition, and then
we'll be ready to enter Addition World.
-/
/- Lemma : no-side-bar
If `b = succ(a)`, then `succ(b) = succ(succ(a))`.
-/
lemma example4 (a b : mynat) (h : b = succ a) : succ b = succ (succ a) :=
begin [less_leaky]
rw h,
refl,
end
end mynat -- hide
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.