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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f4d5bf1b4d3482739ad658d446a78fb5ee8cc406 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/probability/moments.lean | bbbdc72197fdff2524d6c977c0b94c6e54ef0733 | [
"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 | 15,587 | lean | /-
Copyright (c) 2022 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import probability.variance
/-!
# Moments and moment generating function
## Main definitions
* `probability_theory.moment X p μ`: `p`th moment of a real random variable `X` with respect to
measure `μ`, `μ[X^p]`
* `probability_theory.central_moment X p μ`:`p`th central moment of `X` with respect to measure `μ`,
`μ[(X - μ[X])^p]`
* `probability_theory.mgf X μ t`: moment generating function of `X` with respect to measure `μ`,
`μ[exp(t*X)]`
* `probability_theory.cgf X μ t`: cumulant generating function, logarithm of the moment generating
function
## Main results
* `probability_theory.indep_fun.mgf_add`: if two real random variables `X` and `Y` are independent
and their mgf are defined at `t`, then `mgf (X + Y) μ t = mgf X μ t * mgf Y μ t`
* `probability_theory.indep_fun.cgf_add`: if two real random variables `X` and `Y` are independent
and their mgf are defined at `t`, then `cgf (X + Y) μ t = cgf X μ t + cgf Y μ t`
* `probability_theory.measure_ge_le_exp_cgf` and `probability_theory.measure_le_le_exp_cgf`:
Chernoff bound on the upper (resp. lower) tail of a random variable. For `t` nonnegative such that
the cgf exists, `ℙ(ε ≤ X) ≤ exp(- t*ε + cgf X ℙ t)`. See also
`probability_theory.measure_ge_le_exp_mul_mgf` and
`probability_theory.measure_le_le_exp_mul_mgf` for versions of these results using `mgf` instead
of `cgf`.
-/
open measure_theory filter finset real
noncomputable theory
open_locale big_operators measure_theory probability_theory ennreal nnreal
namespace probability_theory
variables {Ω ι : Type*} {m : measurable_space Ω} {X : Ω → ℝ} {p : ℕ} {μ : measure Ω}
include m
/-- Moment of a real random variable, `μ[X ^ p]`. -/
def moment (X : Ω → ℝ) (p : ℕ) (μ : measure Ω) : ℝ := μ[X ^ p]
/-- Central moment of a real random variable, `μ[(X - μ[X]) ^ p]`. -/
def central_moment (X : Ω → ℝ) (p : ℕ) (μ : measure Ω) : ℝ := μ[(X - (λ x, μ[X])) ^ p]
@[simp] lemma moment_zero (hp : p ≠ 0) : moment 0 p μ = 0 :=
by simp only [moment, hp, zero_pow', ne.def, not_false_iff, pi.zero_apply, integral_const,
algebra.id.smul_eq_mul, mul_zero]
@[simp] lemma central_moment_zero (hp : p ≠ 0) : central_moment 0 p μ = 0 :=
by simp only [central_moment, hp, pi.zero_apply, integral_const, algebra.id.smul_eq_mul,
mul_zero, zero_sub, pi.pow_apply, pi.neg_apply, neg_zero', zero_pow', ne.def, not_false_iff]
lemma central_moment_one' [is_finite_measure μ] (h_int : integrable X μ) :
central_moment X 1 μ = (1 - (μ set.univ).to_real) * μ[X] :=
begin
simp only [central_moment, pi.sub_apply, pow_one],
rw integral_sub h_int (integrable_const _),
simp only [sub_mul, integral_const, algebra.id.smul_eq_mul, one_mul],
end
@[simp] lemma central_moment_one [is_probability_measure μ] : central_moment X 1 μ = 0 :=
begin
by_cases h_int : integrable X μ,
{ rw central_moment_one' h_int,
simp only [measure_univ, ennreal.one_to_real, sub_self, zero_mul], },
{ simp only [central_moment, pi.sub_apply, pow_one],
have : ¬ integrable (λ x, X x - integral μ X) μ,
{ refine λ h_sub, h_int _,
have h_add : X = (λ x, X x - integral μ X) + (λ x, integral μ X),
{ ext1 x, simp, },
rw h_add,
exact h_sub.add (integrable_const _), },
rw integral_undef this, },
end
@[simp] lemma central_moment_two_eq_variance : central_moment X 2 μ = variance X μ := rfl
section moment_generating_function
variables {t : ℝ}
/-- Moment generating function of a real random variable `X`: `λ t, μ[exp(t*X)]`. -/
def mgf (X : Ω → ℝ) (μ : measure Ω) (t : ℝ) : ℝ := μ[λ ω, exp (t * X ω)]
/-- Cumulant generating function of a real random variable `X`: `λ t, log μ[exp(t*X)]`. -/
def cgf (X : Ω → ℝ) (μ : measure Ω) (t : ℝ) : ℝ := log (mgf X μ t)
@[simp] lemma mgf_zero_fun : mgf 0 μ t = (μ set.univ).to_real :=
by simp only [mgf, pi.zero_apply, mul_zero, exp_zero, integral_const, algebra.id.smul_eq_mul,
mul_one]
@[simp] lemma cgf_zero_fun : cgf 0 μ t = log (μ set.univ).to_real :=
by simp only [cgf, mgf_zero_fun]
@[simp] lemma mgf_zero_measure : mgf X (0 : measure Ω) t = 0 :=
by simp only [mgf, integral_zero_measure]
@[simp] lemma cgf_zero_measure : cgf X (0 : measure Ω) t = 0 :=
by simp only [cgf, log_zero, mgf_zero_measure]
@[simp] lemma mgf_const' (c : ℝ) : mgf (λ _, c) μ t = (μ set.univ).to_real * exp (t * c) :=
by simp only [mgf, integral_const, algebra.id.smul_eq_mul]
@[simp] lemma mgf_const (c : ℝ) [is_probability_measure μ] : mgf (λ _, c) μ t = exp (t * c) :=
by simp only [mgf_const', measure_univ, ennreal.one_to_real, one_mul]
@[simp] lemma cgf_const' [is_finite_measure μ] (hμ : μ ≠ 0) (c : ℝ) :
cgf (λ _, c) μ t = log (μ set.univ).to_real + t * c :=
begin
simp only [cgf, mgf_const'],
rw log_mul _ (exp_pos _).ne',
{ rw log_exp _, },
{ rw [ne.def, ennreal.to_real_eq_zero_iff, measure.measure_univ_eq_zero],
simp only [hμ, measure_ne_top μ set.univ, or_self, not_false_iff], },
end
@[simp] lemma cgf_const [is_probability_measure μ] (c : ℝ) : cgf (λ _, c) μ t = t * c :=
by simp only [cgf, mgf_const, log_exp]
@[simp] lemma mgf_zero' : mgf X μ 0 = (μ set.univ).to_real :=
by simp only [mgf, zero_mul, exp_zero, integral_const, algebra.id.smul_eq_mul, mul_one]
@[simp] lemma mgf_zero [is_probability_measure μ] : mgf X μ 0 = 1 :=
by simp only [mgf_zero', measure_univ, ennreal.one_to_real]
@[simp] lemma cgf_zero' : cgf X μ 0 = log (μ set.univ).to_real :=
by simp only [cgf, mgf_zero']
@[simp] lemma cgf_zero [is_probability_measure μ] : cgf X μ 0 = 0 :=
by simp only [cgf_zero', measure_univ, ennreal.one_to_real, log_one]
lemma mgf_undef (hX : ¬ integrable (λ ω, exp (t * X ω)) μ) : mgf X μ t = 0 :=
by simp only [mgf, integral_undef hX]
lemma cgf_undef (hX : ¬ integrable (λ ω, exp (t * X ω)) μ) : cgf X μ t = 0 :=
by simp only [cgf, mgf_undef hX, log_zero]
lemma mgf_nonneg : 0 ≤ mgf X μ t :=
begin
refine integral_nonneg _,
intro ω,
simp only [pi.zero_apply],
exact (exp_pos _).le,
end
lemma mgf_pos' (hμ : μ ≠ 0) (h_int_X : integrable (λ ω, exp (t * X ω)) μ) : 0 < mgf X μ t :=
begin
simp_rw mgf,
have : ∫ (x : Ω), exp (t * X x) ∂μ = ∫ (x : Ω) in set.univ, exp (t * X x) ∂μ,
{ simp only [measure.restrict_univ], },
rw [this, set_integral_pos_iff_support_of_nonneg_ae _ _],
{ have h_eq_univ : function.support (λ (x : Ω), exp (t * X x)) = set.univ,
{ ext1 x,
simp only [function.mem_support, set.mem_univ, iff_true],
exact (exp_pos _).ne', },
rw [h_eq_univ, set.inter_univ _],
refine ne.bot_lt _,
simp only [hμ, ennreal.bot_eq_zero, ne.def, measure.measure_univ_eq_zero, not_false_iff], },
{ refine eventually_of_forall (λ x, _),
rw pi.zero_apply,
exact (exp_pos _).le, },
{ rwa integrable_on_univ, },
end
lemma mgf_pos [is_probability_measure μ] (h_int_X : integrable (λ ω, exp (t * X ω)) μ) :
0 < mgf X μ t :=
mgf_pos' (is_probability_measure.ne_zero μ) h_int_X
lemma mgf_neg : mgf (-X) μ t = mgf X μ (-t) :=
by simp_rw [mgf, pi.neg_apply, mul_neg, neg_mul]
lemma cgf_neg : cgf (-X) μ t = cgf X μ (-t) := by simp_rw [cgf, mgf_neg]
/-- This is a trivial application of `indep_fun.comp` but it will come up frequently. -/
lemma indep_fun.exp_mul {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ) (s t : ℝ) :
indep_fun (λ ω, exp (s * X ω)) (λ ω, exp (t * Y ω)) μ :=
begin
have h_meas : ∀ t, measurable (λ x, exp (t * x)) := λ t, (measurable_id'.const_mul t).exp,
change indep_fun ((λ x, exp (s * x)) ∘ X) ((λ x, exp (t * x)) ∘ Y) μ,
exact indep_fun.comp h_indep (h_meas s) (h_meas t),
end
lemma indep_fun.mgf_add {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ)
(hX : ae_strongly_measurable (λ ω, exp (t * X ω)) μ)
(hY : ae_strongly_measurable (λ ω, exp (t * Y ω)) μ) :
mgf (X + Y) μ t = mgf X μ t * mgf Y μ t :=
begin
simp_rw [mgf, pi.add_apply, mul_add, exp_add],
exact (h_indep.exp_mul t t).integral_mul hX hY,
end
lemma indep_fun.mgf_add' {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ)
(hX : ae_strongly_measurable X μ) (hY : ae_strongly_measurable Y μ) :
mgf (X + Y) μ t = mgf X μ t * mgf Y μ t :=
begin
have A : continuous (λ (x : ℝ), exp (t * x)), by continuity,
have h'X : ae_strongly_measurable (λ ω, exp (t * X ω)) μ :=
A.ae_strongly_measurable.comp_ae_measurable hX.ae_measurable,
have h'Y : ae_strongly_measurable (λ ω, exp (t * Y ω)) μ :=
A.ae_strongly_measurable.comp_ae_measurable hY.ae_measurable,
exact h_indep.mgf_add h'X h'Y
end
lemma indep_fun.cgf_add {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ)
(h_int_X : integrable (λ ω, exp (t * X ω)) μ)
(h_int_Y : integrable (λ ω, exp (t * Y ω)) μ) :
cgf (X + Y) μ t = cgf X μ t + cgf Y μ t :=
begin
by_cases hμ : μ = 0,
{ simp [hμ], },
simp only [cgf, h_indep.mgf_add h_int_X.ae_strongly_measurable h_int_Y.ae_strongly_measurable],
exact log_mul (mgf_pos' hμ h_int_X).ne' (mgf_pos' hμ h_int_Y).ne',
end
lemma ae_strongly_measurable_exp_mul_add {X Y : Ω → ℝ}
(h_int_X : ae_strongly_measurable (λ ω, exp (t * X ω)) μ)
(h_int_Y : ae_strongly_measurable (λ ω, exp (t * Y ω)) μ) :
ae_strongly_measurable (λ ω, exp (t * (X + Y) ω)) μ :=
begin
simp_rw [pi.add_apply, mul_add, exp_add],
exact ae_strongly_measurable.mul h_int_X h_int_Y,
end
lemma ae_strongly_measurable_exp_mul_sum {X : ι → Ω → ℝ} {s : finset ι}
(h_int : ∀ i ∈ s, ae_strongly_measurable (λ ω, exp (t * X i ω)) μ) :
ae_strongly_measurable (λ ω, exp (t * (∑ i in s, X i) ω)) μ :=
begin
classical,
induction s using finset.induction_on with i s hi_notin_s h_rec h_int,
{ simp only [pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero],
exact ae_strongly_measurable_const, },
{ have : ∀ (i : ι), i ∈ s → ae_strongly_measurable (λ (ω : Ω), exp (t * X i ω)) μ,
from λ i hi, h_int i (mem_insert_of_mem hi),
specialize h_rec this,
rw sum_insert hi_notin_s,
apply ae_strongly_measurable_exp_mul_add (h_int i (mem_insert_self _ _)) h_rec }
end
lemma indep_fun.integrable_exp_mul_add {X Y : Ω → ℝ} (h_indep : indep_fun X Y μ)
(h_int_X : integrable (λ ω, exp (t * X ω)) μ)
(h_int_Y : integrable (λ ω, exp (t * Y ω)) μ) :
integrable (λ ω, exp (t * (X + Y) ω)) μ :=
begin
simp_rw [pi.add_apply, mul_add, exp_add],
exact (h_indep.exp_mul t t).integrable_mul h_int_X h_int_Y,
end
lemma Indep_fun.integrable_exp_mul_sum [is_probability_measure μ]
{X : ι → Ω → ℝ} (h_indep : Indep_fun (λ i, infer_instance) X μ) (h_meas : ∀ i, measurable (X i))
{s : finset ι} (h_int : ∀ i ∈ s, integrable (λ ω, exp (t * X i ω)) μ) :
integrable (λ ω, exp (t * (∑ i in s, X i) ω)) μ :=
begin
classical,
induction s using finset.induction_on with i s hi_notin_s h_rec h_int,
{ simp only [pi.zero_apply, sum_apply, sum_empty, mul_zero, exp_zero],
exact integrable_const _, },
{ have : ∀ (i : ι), i ∈ s → integrable (λ (ω : Ω), exp (t * X i ω)) μ,
from λ i hi, h_int i (mem_insert_of_mem hi),
specialize h_rec this,
rw sum_insert hi_notin_s,
refine indep_fun.integrable_exp_mul_add _ (h_int i (mem_insert_self _ _)) h_rec,
exact (h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm, },
end
lemma Indep_fun.mgf_sum [is_probability_measure μ]
{X : ι → Ω → ℝ} (h_indep : Indep_fun (λ i, infer_instance) X μ) (h_meas : ∀ i, measurable (X i))
(s : finset ι) :
mgf (∑ i in s, X i) μ t = ∏ i in s, mgf (X i) μ t :=
begin
classical,
induction s using finset.induction_on with i s hi_notin_s h_rec h_int,
{ simp only [sum_empty, mgf_zero_fun, measure_univ, ennreal.one_to_real, prod_empty], },
{ have h_int' : ∀ (i : ι), ae_strongly_measurable (λ (ω : Ω), exp (t * X i ω)) μ,
from λ i, ((h_meas i).const_mul t).exp.ae_strongly_measurable,
rw [sum_insert hi_notin_s, indep_fun.mgf_add
(h_indep.indep_fun_finset_sum_of_not_mem h_meas hi_notin_s).symm (h_int' i)
(ae_strongly_measurable_exp_mul_sum (λ i hi, h_int' i)),
h_rec, prod_insert hi_notin_s] }
end
lemma Indep_fun.cgf_sum [is_probability_measure μ]
{X : ι → Ω → ℝ} (h_indep : Indep_fun (λ i, infer_instance) X μ) (h_meas : ∀ i, measurable (X i))
{s : finset ι} (h_int : ∀ i ∈ s, integrable (λ ω, exp (t * X i ω)) μ) :
cgf (∑ i in s, X i) μ t = ∑ i in s, cgf (X i) μ t :=
begin
simp_rw cgf,
rw ← log_prod _ _ (λ j hj, _),
{ rw h_indep.mgf_sum h_meas },
{ exact (mgf_pos (h_int j hj)).ne', },
end
/-- **Chernoff bound** on the upper tail of a real random variable. -/
lemma measure_ge_le_exp_mul_mgf [is_finite_measure μ] (ε : ℝ) (ht : 0 ≤ t)
(h_int : integrable (λ ω, exp (t * X ω)) μ) :
(μ {ω | ε ≤ X ω}).to_real ≤ exp (- t * ε) * mgf X μ t :=
begin
cases ht.eq_or_lt with ht_zero_eq ht_pos,
{ rw ht_zero_eq.symm,
simp only [neg_zero', zero_mul, exp_zero, mgf_zero', one_mul],
rw ennreal.to_real_le_to_real (measure_ne_top μ _) (measure_ne_top μ _),
exact measure_mono (set.subset_univ _), },
calc (μ {ω | ε ≤ X ω}).to_real
= (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).to_real :
begin
congr' with ω,
simp only [exp_le_exp, eq_iff_iff],
exact ⟨λ h, mul_le_mul_of_nonneg_left h ht_pos.le, λ h, le_of_mul_le_mul_left h ht_pos⟩,
end
... ≤ (exp (t * ε))⁻¹ * μ[λ ω, exp (t * X ω)] :
begin
have : exp (t * ε) * (μ {ω | exp (t * ε) ≤ exp (t * X ω)}).to_real
≤ μ[λ ω, exp (t * X ω)],
from mul_meas_ge_le_integral_of_nonneg (λ x, (exp_pos _).le) h_int _,
rwa [mul_comm (exp (t * ε))⁻¹, ← div_eq_mul_inv, le_div_iff' (exp_pos _)],
end
... = exp (- t * ε) * mgf X μ t : by { rw [neg_mul, exp_neg], refl, },
end
/-- **Chernoff bound** on the lower tail of a real random variable. -/
lemma measure_le_le_exp_mul_mgf [is_finite_measure μ] (ε : ℝ) (ht : t ≤ 0)
(h_int : integrable (λ ω, exp (t * X ω)) μ) :
(μ {ω | X ω ≤ ε}).to_real ≤ exp (- t * ε) * mgf X μ t :=
begin
rw [← neg_neg t, ← mgf_neg, neg_neg, ← neg_mul_neg (-t)],
refine eq.trans_le _ (measure_ge_le_exp_mul_mgf (-ε) (neg_nonneg.mpr ht) _),
{ congr' with ω,
simp only [pi.neg_apply, neg_le_neg_iff], },
{ simp_rw [pi.neg_apply, neg_mul_neg],
exact h_int, },
end
/-- **Chernoff bound** on the upper tail of a real random variable. -/
lemma measure_ge_le_exp_cgf [is_finite_measure μ] (ε : ℝ) (ht : 0 ≤ t)
(h_int : integrable (λ ω, exp (t * X ω)) μ) :
(μ {ω | ε ≤ X ω}).to_real ≤ exp (- t * ε + cgf X μ t) :=
begin
refine (measure_ge_le_exp_mul_mgf ε ht h_int).trans _,
rw exp_add,
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le,
end
/-- **Chernoff bound** on the lower tail of a real random variable. -/
lemma measure_le_le_exp_cgf [is_finite_measure μ] (ε : ℝ) (ht : t ≤ 0)
(h_int : integrable (λ ω, exp (t * X ω)) μ) :
(μ {ω | X ω ≤ ε}).to_real ≤ exp (- t * ε + cgf X μ t) :=
begin
refine (measure_le_le_exp_mul_mgf ε ht h_int).trans _,
rw exp_add,
exact mul_le_mul le_rfl (le_exp_log _) mgf_nonneg (exp_pos _).le,
end
end moment_generating_function
end probability_theory
|
f6b4afb47d286167705c1abc46904cc047830b4c | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/topology/instances/ennreal.lean | 921ad489aaf3e62d523d4acbf189535e0993ca78 | [
"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 | 56,389 | 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 topology.instances.nnreal
import topology.algebra.ordered.liminf_limsup
import topology.metric_space.lipschitz
/-!
# Extended non-negative reals
-/
noncomputable theory
open classical set filter metric
open_locale classical topological_space ennreal nnreal big_operators filter
variables {α : Type*} {β : Type*} {γ : Type*}
namespace ennreal
variables {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
variables {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : set ℝ≥0∞}
section topological_space
open topological_space
/-- Topology on `ℝ≥0∞`.
Note: this is different from the `emetric_space` topology. The `emetric_space` topology has
`is_open {⊤}`, while this topology doesn't have singleton elements. -/
instance : topological_space ℝ≥0∞ := preorder.topology ℝ≥0∞
instance : order_topology ℝ≥0∞ := ⟨rfl⟩
instance : t2_space ℝ≥0∞ := by apply_instance -- short-circuit type class inference
instance : second_countable_topology ℝ≥0∞ :=
⟨⟨⋃q ≥ (0:ℚ), {{a : ℝ≥0∞ | a < real.to_nnreal q}, {a : ℝ≥0∞ | ↑(real.to_nnreal q) < a}},
(countable_encodable _).bUnion $ assume a ha, (countable_singleton _).insert _,
le_antisymm
(le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt})
(le_generate_from $ λ s h, begin
rcases h with ⟨a, hs | hs⟩;
[ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < real.to_nnreal q}, {b | ↑(real.to_nnreal q) < b},
from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]),
rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(real.to_nnreal q) < a}, {b | b < ↑(real.to_nnreal q)},
from set.ext (assume b,
by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])];
{ apply is_open_Union, intro q,
apply is_open_Union, intro hq,
exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) }
end)⟩⟩
lemma embedding_coe : embedding (coe : ℝ≥0 → ℝ≥0∞) :=
⟨⟨begin
refine le_antisymm _ _,
{ rw [@order_topology.topology_eq_generate_intervals ℝ≥0∞ _,
← coinduced_le_iff_le_induced],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
show is_open {b : ℝ≥0 | a < ↑b},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] },
show is_open {b : ℝ≥0 | ↑b < a},
{ cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } },
{ rw [@order_topology.topology_eq_generate_intervals ℝ≥0 _],
refine le_generate_from (assume s ha, _),
rcases ha with ⟨a, rfl | rfl⟩,
exact ⟨Ioi a, is_open_Ioi, by simp [Ioi]⟩,
exact ⟨Iio a, is_open_Iio, by simp [Iio]⟩ }
end⟩,
assume a b, coe_eq_coe.1⟩
lemma is_open_ne_top : is_open {a : ℝ≥0∞ | a ≠ ⊤} := is_open_ne
lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio}
lemma open_embedding_coe : open_embedding (coe : ℝ≥0 → ℝ≥0∞) :=
⟨embedding_coe, by { convert is_open_ne_top, ext (x|_); simp [none_eq_top, some_eq_coe] }⟩
lemma coe_range_mem_nhds : range (coe : ℝ≥0 → ℝ≥0∞) ∈ 𝓝 (r : ℝ≥0∞) :=
is_open.mem_nhds open_embedding_coe.open_range $ mem_range_self _
@[norm_cast] lemma tendsto_coe {f : filter α} {m : α → ℝ≥0} {a : ℝ≥0} :
tendsto (λa, (m a : ℝ≥0∞)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) :=
embedding_coe.tendsto_nhds_iff.symm
lemma continuous_coe : continuous (coe : ℝ≥0 → ℝ≥0∞) :=
embedding_coe.continuous
lemma continuous_coe_iff {α} [topological_space α] {f : α → ℝ≥0} :
continuous (λa, (f a : ℝ≥0∞)) ↔ continuous f :=
embedding_coe.continuous_iff.symm
lemma nhds_coe {r : ℝ≥0} : 𝓝 (r : ℝ≥0∞) = (𝓝 r).map coe :=
(open_embedding_coe.map_nhds_eq r).symm
lemma tendsto_nhds_coe_iff {α : Type*} {l : filter α} {x : ℝ≥0} {f : ℝ≥0∞ → α} :
tendsto f (𝓝 ↑x) l ↔ tendsto (f ∘ coe : ℝ≥0 → α) (𝓝 x) l :=
show _ ≤ _ ↔ _ ≤ _, by rw [nhds_coe, filter.map_map]
lemma continuous_at_coe_iff {α : Type*} [topological_space α] {x : ℝ≥0} {f : ℝ≥0∞ → α} :
continuous_at f (↑x) ↔ continuous_at (f ∘ coe : ℝ≥0 → α) x :=
tendsto_nhds_coe_iff
lemma nhds_coe_coe {r p : ℝ≥0} :
𝓝 ((r : ℝ≥0∞), (p : ℝ≥0∞)) = (𝓝 (r, p)).map (λp:ℝ≥0×ℝ≥0, (p.1, p.2)) :=
((open_embedding_coe.prod open_embedding_coe).map_nhds_eq (r, p)).symm
lemma continuous_of_real : continuous ennreal.of_real :=
(continuous_coe_iff.2 continuous_id).comp nnreal.continuous_of_real
lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (𝓝 a)) :
tendsto (λa, ennreal.of_real (m a)) f (𝓝 (ennreal.of_real a)) :=
tendsto.comp (continuous.tendsto continuous_of_real _) h
lemma tendsto_to_nnreal {a : ℝ≥0∞} (ha : a ≠ ⊤) :
tendsto ennreal.to_nnreal (𝓝 a) (𝓝 a.to_nnreal) :=
begin
lift a to ℝ≥0 using ha,
rw [nhds_coe, tendsto_map'_iff],
exact tendsto_id
end
lemma eventually_eq_of_to_real_eventually_eq {l : filter α} {f g : α → ℝ≥0∞}
(hfi : ∀ᶠ x in l, f x ≠ ∞) (hgi : ∀ᶠ x in l, g x ≠ ∞)
(hfg : (λ x, (f x).to_real) =ᶠ[l] (λ x, (g x).to_real)) :
f =ᶠ[l] g :=
begin
filter_upwards [hfi, hgi, hfg],
intros x hfx hgx hfgx,
rwa ← ennreal.to_real_eq_to_real hfx hgx,
end
lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a ≠ ∞} :=
λ a ha, continuous_at.continuous_within_at (tendsto_to_nnreal ha)
lemma tendsto_to_real {a : ℝ≥0∞} (ha : a ≠ ⊤) : tendsto ennreal.to_real (𝓝 a) (𝓝 a.to_real) :=
nnreal.tendsto_coe.2 $ tendsto_to_nnreal ha
/-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/
def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ ℝ≥0 :=
{ continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal,
continuous_inv_fun := continuous_subtype_mk _ continuous_coe,
.. ne_top_equiv_nnreal }
/-- The set of finite `ℝ≥0∞` numbers is homeomorphic to `ℝ≥0`. -/
def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ ℝ≥0 :=
by refine (homeomorph.set_congr $ set.ext $ λ x, _).trans ne_top_homeomorph_nnreal;
simp only [mem_set_of_eq, lt_top_iff_ne_top]
lemma nhds_top : 𝓝 ∞ = ⨅ a ≠ ∞, 𝓟 (Ioi a) :=
nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi]
lemma nhds_top' : 𝓝 ∞ = ⨅ r : ℝ≥0, 𝓟 (Ioi r) :=
nhds_top.trans $ infi_ne_top _
lemma nhds_top_basis : (𝓝 ∞).has_basis (λ a, a < ∞) (λ a, Ioi a) := nhds_top_basis
lemma tendsto_nhds_top_iff_nnreal {m : α → ℝ≥0∞} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ x : ℝ≥0, ∀ᶠ a in f, ↑x < m a :=
by simp only [nhds_top', tendsto_infi, tendsto_principal, mem_Ioi]
lemma tendsto_nhds_top_iff_nat {m : α → ℝ≥0∞} {f : filter α} :
tendsto m f (𝓝 ⊤) ↔ ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a :=
tendsto_nhds_top_iff_nnreal.trans ⟨λ h n, by simpa only [ennreal.coe_nat] using h n,
λ h x, let ⟨n, hn⟩ := exists_nat_gt x in
(h n).mono (λ y, lt_trans $ by rwa [← ennreal.coe_nat, coe_lt_coe])⟩
lemma tendsto_nhds_top {m : α → ℝ≥0∞} {f : filter α}
(h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : tendsto m f (𝓝 ⊤) :=
tendsto_nhds_top_iff_nat.2 h
lemma tendsto_nat_nhds_top : tendsto (λ n : ℕ, ↑n) at_top (𝓝 ∞) :=
tendsto_nhds_top $ λ n, mem_at_top_sets.2
⟨n+1, λ m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hm⟩
@[simp, norm_cast] lemma tendsto_coe_nhds_top {f : α → ℝ≥0} {l : filter α} :
tendsto (λ x, (f x : ℝ≥0∞)) l (𝓝 ∞) ↔ tendsto f l at_top :=
by rw [tendsto_nhds_top_iff_nnreal, at_top_basis_Ioi.tendsto_right_iff];
[simp, apply_instance, apply_instance]
lemma nhds_zero : 𝓝 (0 : ℝ≥0∞) = ⨅a ≠ 0, 𝓟 (Iio a) :=
nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio]
lemma nhds_zero_basis : (𝓝 (0 : ℝ≥0∞)).has_basis (λ a : ℝ≥0∞, 0 < a) (λ a, Iio a) := nhds_bot_basis
lemma nhds_zero_basis_Iic : (𝓝 (0 : ℝ≥0∞)).has_basis (λ a : ℝ≥0∞, 0 < a) Iic := nhds_bot_basis_Iic
@[instance] lemma nhds_within_Ioi_coe_ne_bot {r : ℝ≥0} : (𝓝[Ioi r] (r : ℝ≥0∞)).ne_bot :=
nhds_within_Ioi_self_ne_bot' ennreal.coe_lt_top
@[instance] lemma nhds_within_Ioi_zero_ne_bot : (𝓝[Ioi 0] (0 : ℝ≥0∞)).ne_bot :=
nhds_within_Ioi_coe_ne_bot
-- using Icc because
-- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0
-- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not
lemma Icc_mem_nhds (xt : x ≠ ⊤) (ε0 : ε ≠ 0) : Icc (x - ε) (x + ε) ∈ 𝓝 x :=
begin
rw _root_.mem_nhds_iff,
by_cases x0 : x = 0,
{ use Iio (x + ε),
have : Iio (x + ε) ⊆ Icc (x - ε) (x + ε), assume a, rw x0, simpa using le_of_lt,
use this, exact ⟨is_open_Iio, mem_Iio_self_add xt ε0⟩ },
{ use Ioo (x - ε) (x + ε), use Ioo_subset_Icc_self,
exact ⟨is_open_Ioo, mem_Ioo_self_sub_add xt x0 ε0 ε0 ⟩ }
end
lemma nhds_of_ne_top (xt : x ≠ ⊤) : 𝓝 x = ⨅ ε > 0, 𝓟 (Icc (x - ε) (x + ε)) :=
begin
refine le_antisymm _ _,
-- first direction
simp only [le_infi_iff, le_principal_iff], assume ε ε0, exact Icc_mem_nhds xt ε0.lt.ne',
-- second direction
rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _),
rcases hs with ⟨xs, ⟨a, (rfl : s = Ioi a)|(rfl : s = Iio a)⟩⟩,
{ rcases exists_between xs with ⟨b, ab, bx⟩,
have xb_pos : 0 < x - b := tsub_pos_iff_lt.2 bx,
have xxb : x - (x - b) = b := sub_sub_cancel xt bx.le,
refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _),
simp only [mem_principal, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xxb at h₁, calc a < b : ab ... ≤ y : h₁ },
{ rcases exists_between xs with ⟨b, xb, ba⟩,
have bx_pos : 0 < b - x := tsub_pos_iff_lt.2 xb,
have xbx : x + (b - x) = b := add_tsub_cancel_of_le xb.le,
refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _),
simp only [mem_principal, le_principal_iff],
assume y, rintros ⟨h₁, h₂⟩, rw xbx at h₂, calc y ≤ b : h₂ ... < a : ba },
end
/-- Characterization of neighborhoods for `ℝ≥0∞` numbers. See also `tendsto_order`
for a version with strict inequalities. -/
protected theorem tendsto_nhds {f : filter α} {u : α → ℝ≥0∞} {a : ℝ≥0∞} (ha : a ≠ ⊤) :
tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, (u x) ∈ Icc (a - ε) (a + ε) :=
by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc]
protected lemma tendsto_at_top [nonempty β] [semilattice_sup β] {f : β → ℝ≥0∞} {a : ℝ≥0∞}
(ha : a ≠ ⊤) : tendsto f at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, (f n) ∈ Icc (a - ε) (a + ε) :=
by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually]
instance : has_continuous_add ℝ≥0∞ :=
begin
refine ⟨continuous_iff_continuous_at.2 _⟩,
rintro ⟨(_|a), b⟩,
{ exact tendsto_nhds_top_mono' continuous_at_fst (λ p, le_add_right le_rfl) },
rcases b with (_|b),
{ exact tendsto_nhds_top_mono' continuous_at_snd (λ p, le_add_left le_rfl) },
simp only [continuous_at, some_eq_coe, nhds_coe_coe, ← coe_add, tendsto_map'_iff, (∘),
tendsto_coe, tendsto_add]
end
protected lemma tendsto_at_top_zero [hβ : nonempty β] [semilattice_sup β] {f : β → ℝ≥0∞} :
filter.at_top.tendsto f (𝓝 0) ↔ ∀ ε > 0, ∃ N, ∀ n ≥ N, f n ≤ ε :=
begin
rw ennreal.tendsto_at_top zero_ne_top,
{ simp_rw [set.mem_Icc, zero_add, zero_tsub, zero_le _, true_and], },
{ exact hβ, },
end
protected lemma tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) :=
have ht : ∀b:ℝ≥0∞, b ≠ 0 → tendsto (λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) (𝓝 ((⊤:ℝ≥0∞), b)) (𝓝 ⊤),
begin
refine assume b hb, tendsto_nhds_top_iff_nnreal.2 $ assume n, _,
rcases lt_iff_exists_nnreal_btwn.1 (pos_iff_ne_zero.2 hb) with ⟨ε, hε, hεb⟩,
replace hε : 0 < ε, from coe_pos.1 hε,
filter_upwards [prod_is_open.mem_nhds (lt_mem_nhds $ @coe_lt_top (n / ε)) (lt_mem_nhds hεb)],
rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩,
dsimp at h₁ h₂ ⊢,
rw [← div_mul_cancel n hε.ne', coe_mul],
exact mul_lt_mul h₁ h₂
end,
begin
cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] },
cases b, {
simp [none_eq_top] at ha,
simp [*, nhds_swap (a : ℝ≥0∞) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘),
mul_comm] },
simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)],
simp only [coe_mul.symm, tendsto_coe, tendsto_mul]
end
protected lemma tendsto.mul {f : filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) :
tendsto (λa, ma a * mb a) f (𝓝 (a * b)) :=
show tendsto ((λp:ℝ≥0∞×ℝ≥0∞, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (𝓝 (a * b)), from
tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb)
protected lemma tendsto.const_mul {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (𝓝 (a * b)) :=
by_cases
(assume : a = 0, by simp [this, tendsto_const_nhds])
(assume ha : a ≠ 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb)
protected lemma tendsto.mul_const {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : tendsto (λx, m x * b) f (𝓝 (a * b)) :=
by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha
lemma tendsto_finset_prod_of_ne_top {ι : Type*} {f : ι → α → ℝ≥0∞} {x : filter α} {a : ι → ℝ≥0∞}
(s : finset ι) (h : ∀ i ∈ s, tendsto (f i) x (𝓝 (a i))) (h' : ∀ i ∈ s, a i ≠ ∞):
tendsto (λ b, ∏ c in s, f c b) x (𝓝 (∏ c in s, a c)) :=
begin
induction s using finset.induction with a s has IH, { simp [tendsto_const_nhds] },
simp only [finset.prod_insert has],
apply tendsto.mul (h _ (finset.mem_insert_self _ _)),
{ right,
exact (prod_lt_top (λ i hi, h' _ (finset.mem_insert_of_mem hi))).ne },
{ exact IH (λ i hi, h _ (finset.mem_insert_of_mem hi))
(λ i hi, h' _ (finset.mem_insert_of_mem hi)) },
{ exact or.inr (h' _ (finset.mem_insert_self _ _)) }
end
protected lemma continuous_at_const_mul {a b : ℝ≥0∞} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at ((*) a) b :=
tendsto.const_mul tendsto_id h.symm
protected lemma continuous_at_mul_const {a b : ℝ≥0∞} (h : a ≠ ⊤ ∨ b ≠ 0) :
continuous_at (λ x, x * a) b :=
tendsto.mul_const tendsto_id h.symm
protected lemma continuous_const_mul {a : ℝ≥0∞} (ha : a ≠ ⊤) : continuous ((*) a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_const_mul (or.inl ha)
protected lemma continuous_mul_const {a : ℝ≥0∞} (ha : a ≠ ⊤) : continuous (λ x, x * a) :=
continuous_iff_continuous_at.2 $ λ x, ennreal.continuous_at_mul_const (or.inl ha)
@[continuity]
lemma continuous_pow (n : ℕ) : continuous (λ a : ℝ≥0∞, a ^ n) :=
begin
induction n with n IH,
{ simp [continuous_const] },
simp_rw [nat.succ_eq_add_one, pow_add, pow_one, continuous_iff_continuous_at],
assume x,
refine ennreal.tendsto.mul (IH.tendsto _) _ tendsto_id _;
by_cases H : x = 0,
{ simp only [H, zero_ne_top, ne.def, or_true, not_false_iff]},
{ exact or.inl (λ h, H (pow_eq_zero h)) },
{ simp only [H, pow_eq_top_iff, zero_ne_top, false_or, eq_self_iff_true,
not_true, ne.def, not_false_iff, false_and], },
{ simp only [H, true_or, ne.def, not_false_iff] }
end
protected lemma tendsto.pow {f : filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} {n : ℕ}
(hm : tendsto m f (𝓝 a)) :
tendsto (λ x, (m x) ^ n) f (𝓝 (a ^ n)) :=
((continuous_pow n).tendsto a).comp hm
lemma le_of_forall_lt_one_mul_le {x y : ℝ≥0∞} (h : ∀ a < 1, a * x ≤ y) : x ≤ y :=
begin
have : tendsto (* x) (𝓝[Iio 1] 1) (𝓝 (1 * x)) :=
(ennreal.continuous_at_mul_const (or.inr one_ne_zero)).mono_left inf_le_left,
rw one_mul at this,
haveI : (𝓝[Iio 1] (1 : ℝ≥0∞)).ne_bot := nhds_within_Iio_self_ne_bot' ennreal.zero_lt_one,
exact le_of_tendsto this (eventually_nhds_within_iff.2 $ eventually_of_forall h)
end
lemma infi_mul_left' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) (h0 : a = 0 → nonempty ι) :
(⨅ i, a * f i) = a * ⨅ i, f i :=
begin
by_cases H : a = ⊤ ∧ (⨅ i, f i) = 0,
{ rcases h H.1 H.2 with ⟨i, hi⟩,
rw [H.2, mul_zero, ← bot_eq_zero, infi_eq_bot],
exact λ b hb, ⟨i, by rwa [hi, mul_zero, ← bot_eq_zero]⟩ },
{ rw not_and_distrib at H,
casesI is_empty_or_nonempty ι,
{ rw [infi_of_empty, infi_of_empty, mul_top, if_neg],
exact mt h0 (not_nonempty_iff.2 ‹_›) },
{ exact (map_infi_of_continuous_at_of_monotone' (ennreal.continuous_at_const_mul H)
ennreal.mul_left_mono).symm } }
end
lemma infi_mul_left {ι} [nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, a * f i) = a * ⨅ i, f i :=
infi_mul_left' h (λ _, ‹nonempty ι›)
lemma infi_mul_right' {ι} {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) (h0 : a = 0 → nonempty ι) :
(⨅ i, f i * a) = (⨅ i, f i) * a :=
by simpa only [mul_comm a] using infi_mul_left' h h0
lemma infi_mul_right {ι} [nonempty ι] {f : ι → ℝ≥0∞} {a : ℝ≥0∞}
(h : a = ⊤ → (⨅ i, f i) = 0 → ∃ i, f i = 0) :
(⨅ i, f i * a) = (⨅ i, f i) * a :=
infi_mul_right' h (λ _, ‹nonempty ι›)
protected lemma continuous_inv : continuous (has_inv.inv : ℝ≥0∞ → ℝ≥0∞) :=
continuous_iff_continuous_at.2 $ λ a, tendsto_order.2
⟨begin
assume b hb,
simp only [@ennreal.lt_inv_iff_lt_inv b],
exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb),
end,
begin
assume b hb,
simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b],
exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb)
end⟩
@[simp] protected lemma tendsto_inv_iff {f : filter α} {m : α → ℝ≥0∞} {a : ℝ≥0∞} :
tendsto (λ x, (m x)⁻¹) f (𝓝 a⁻¹) ↔ tendsto m f (𝓝 a) :=
⟨λ h, by simpa only [function.comp, ennreal.inv_inv]
using (ennreal.continuous_inv.tendsto a⁻¹).comp h,
(ennreal.continuous_inv.tendsto a).comp⟩
protected lemma tendsto.div {f : filter α} {ma : α → ℝ≥0∞} {mb : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) :
tendsto (λa, ma a / mb a) f (𝓝 (a / b)) :=
by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] }
protected lemma tendsto.const_div {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λb, a / m b) f (𝓝 (a / b)) :=
by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] }
protected lemma tendsto.div_const {f : filter α} {m : α → ℝ≥0∞} {a b : ℝ≥0∞}
(hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : tendsto (λx, m x / b) f (𝓝 (a / b)) :=
by { apply tendsto.mul_const hm, simp [ha] }
protected lemma tendsto_inv_nat_nhds_zero : tendsto (λ n : ℕ, (n : ℝ≥0∞)⁻¹) at_top (𝓝 0) :=
ennreal.inv_top ▸ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top
lemma bsupr_add {ι} {s : set ι} (hs : s.nonempty) {f : ι → ℝ≥0∞} :
(⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a :=
begin
simp only [← Sup_image], symmetry,
rw [image_comp (+ a)],
refine is_lub.Sup_eq ((is_lub_Sup $ f '' s).is_lub_of_tendsto _ (hs.image _) _),
exacts [λ x _ y _ hxy, add_le_add hxy le_rfl,
tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds]
end
lemma Sup_add {s : set ℝ≥0∞} (hs : s.nonempty) : Sup s + a = ⨆b∈s, b + a :=
by rw [Sup_eq_supr, bsupr_add hs]
lemma supr_add {ι : Sort*} {s : ι → ℝ≥0∞} [h : nonempty ι] : supr s + a = ⨆b, s b + a :=
let ⟨x⟩ := h in
calc supr s + a = Sup (range s) + a : by rw Sup_range
... = (⨆b∈range s, b + a) : Sup_add ⟨s x, x, rfl⟩
... = _ : supr_range
lemma add_supr {ι : Sort*} {s : ι → ℝ≥0∞} [h : nonempty ι] : a + supr s = ⨆b, a + s b :=
by rw [add_comm, supr_add]; simp [add_comm]
lemma supr_add_supr {ι : Sort*} {f g : ι → ℝ≥0∞} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) :
supr f + supr g = (⨆ a, f a + g a) :=
begin
by_cases hι : nonempty ι,
{ letI := hι,
refine le_antisymm _ (supr_le $ λ a, add_le_add (le_supr _ _) (le_supr _ _)),
simpa [add_supr, supr_add] using
λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from
let ⟨k, hk⟩ := h i j in le_supr_of_le k hk },
{ have : ∀f:ι → ℝ≥0∞, (⨆i, f i) = 0 := λ f, supr_eq_zero.mpr (λ i, (hι ⟨i⟩).elim),
rw [this, this, this, zero_add] }
end
lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι]
{f g : ι → ℝ≥0∞} (hf : monotone f) (hg : monotone g) :
supr f + supr g = (⨆ a, f a + g a) :=
supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add (hf $ le_sup_left) (hg $ le_sup_right)⟩
lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ℝ≥0∞}
(hf : ∀a, monotone (f a)) :
∑ a in s, supr (f a) = (⨆ n, ∑ a in s, f a n) :=
begin
refine finset.induction_on s _ _,
{ simp, },
{ assume a s has ih,
simp only [finset.sum_insert has],
rw [ih, supr_add_supr_of_monotone (hf a)],
assume i j h,
exact (finset.sum_le_sum $ assume a ha, hf a h) }
end
lemma mul_Sup {s : set ℝ≥0∞} {a : ℝ≥0∞} : a * Sup s = ⨆i∈s, a * i :=
begin
by_cases hs : ∀x∈s, x = (0:ℝ≥0∞),
{ have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0),
have h₂ : (⨆i ∈ s, a * i) = 0 :=
(bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]),
rw [h₁, h₂, mul_zero] },
{ simp only [not_forall] at hs,
rcases hs with ⟨x, hx, hx0⟩,
have s₁ : Sup s ≠ 0 :=
pos_iff_ne_zero.1 (lt_of_lt_of_le (pos_iff_ne_zero.2 hx0) (le_Sup hx)),
have : Sup ((λb, a * b) '' s) = a * Sup s :=
is_lub.Sup_eq ((is_lub_Sup s).is_lub_of_tendsto
(assume x _ y _ h, mul_le_mul_left' h _)
⟨x, hx⟩
(ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl s₁))),
rw [this.symm, Sup_image] }
end
lemma mul_supr {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : a * supr f = ⨆i, a * f i :=
by rw [← Sup_range, mul_Sup, supr_range]
lemma supr_mul {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : supr f * a = ⨆i, f i * a :=
by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm]
lemma supr_div {ι : Sort*} {f : ι → ℝ≥0∞} {a : ℝ≥0∞} : supr f / a = ⨆i, f i / a :=
supr_mul
protected lemma tendsto_coe_sub : ∀{b:ℝ≥0∞}, tendsto (λb:ℝ≥0∞, ↑r - b) (𝓝 b) (𝓝 (↑r - b)) :=
begin
refine forall_ennreal.2 ⟨λ a, _, _⟩,
{ simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, ← with_top.coe_sub],
exact tendsto_const_nhds.sub tendsto_id },
simp,
exact (tendsto.congr' (mem_of_superset (lt_mem_nhds $ @coe_lt_top r) $
by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds
end
lemma sub_supr {ι : Sort*} [nonempty ι] {b : ι → ℝ≥0∞} (hr : a < ⊤) :
a - (⨆i, b i) = (⨅i, a - b i) :=
let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in
have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i),
from is_glb.Inf_eq $ is_lub_supr.is_glb_of_tendsto
(assume x _ y _, tsub_le_tsub (le_refl (r : ℝ≥0∞)))
(range_nonempty _)
(ennreal.tendsto_coe_sub.comp (tendsto_id' inf_le_left)),
by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_rfl
end topological_space
section tsum
variables {f g : α → ℝ≥0∞}
@[norm_cast] protected lemma has_sum_coe {f : α → ℝ≥0} {r : ℝ≥0} :
has_sum (λa, (f a : ℝ≥0∞)) ↑r ↔ has_sum f r :=
have (λs:finset α, ∑ a in s, ↑(f a)) = (coe : ℝ≥0 → ℝ≥0∞) ∘ (λs:finset α, ∑ a in s, f a),
from funext $ assume s, ennreal.coe_finset_sum.symm,
by unfold has_sum; rw [this, tendsto_coe]
protected lemma tsum_coe_eq {f : α → ℝ≥0} (h : has_sum f r) : ∑'a, (f a : ℝ≥0∞) = r :=
(ennreal.has_sum_coe.2 h).tsum_eq
protected lemma coe_tsum {f : α → ℝ≥0} : summable f → ↑(tsum f) = ∑'a, (f a : ℝ≥0∞)
| ⟨r, hr⟩ := by rw [hr.tsum_eq, ennreal.tsum_coe_eq hr]
protected lemma has_sum : has_sum f (⨆s:finset α, ∑ a in s, f a) :=
tendsto_at_top_supr $ λ s t, finset.sum_le_sum_of_subset
@[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩
lemma tsum_coe_ne_top_iff_summable {f : β → ℝ≥0} :
∑' b, (f b:ℝ≥0∞) ≠ ∞ ↔ summable f :=
begin
refine ⟨λ h, _, λ h, ennreal.coe_tsum h ▸ ennreal.coe_ne_top⟩,
lift (∑' b, (f b:ℝ≥0∞)) to ℝ≥0 using h with a ha,
refine ⟨a, ennreal.has_sum_coe.1 _⟩,
rw ha,
exact ennreal.summable.has_sum
end
protected lemma tsum_eq_supr_sum : ∑'a, f a = (⨆s:finset α, ∑ a in s, f a) :=
ennreal.has_sum.tsum_eq
protected lemma tsum_eq_supr_sum' {ι : Type*} (s : ι → finset α) (hs : ∀ t, ∃ i, t ⊆ s i) :
∑' a, f a = ⨆ i, ∑ a in s i, f a :=
begin
rw [ennreal.tsum_eq_supr_sum],
symmetry,
change (⨆i:ι, (λ t : finset α, ∑ a in t, f a) (s i)) = ⨆s:finset α, ∑ a in s, f a,
exact (finset.sum_mono_set f).supr_comp_eq hs
end
protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ℝ≥0∞) :
∑'p:Σa, β a, f p.1 p.2 = ∑'a b, f a b :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_sigma' {β : α → Type*} (f : (Σ a, β a) → ℝ≥0∞) :
∑'p:(Σa, β a), f p = ∑'a b, f ⟨a, b⟩ :=
tsum_sigma' (assume b, ennreal.summable) ennreal.summable
protected lemma tsum_prod {f : α → β → ℝ≥0∞} : ∑'p:α×β, f p.1 p.2 = ∑'a, ∑'b, f a b :=
tsum_prod' ennreal.summable $ λ _, ennreal.summable
protected lemma tsum_comm {f : α → β → ℝ≥0∞} : ∑'a, ∑'b, f a b = ∑'b, ∑'a, f a b :=
tsum_comm' ennreal.summable (λ _, ennreal.summable) (λ _, ennreal.summable)
protected lemma tsum_add : ∑'a, (f a + g a) = (∑'a, f a) + (∑'a, g a) :=
tsum_add ennreal.summable ennreal.summable
protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : ∑'a, f a ≤ ∑'a, g a :=
tsum_le_tsum h ennreal.summable ennreal.summable
protected lemma sum_le_tsum {f : α → ℝ≥0∞} (s : finset α) : ∑ x in s, f x ≤ ∑' x, f x :=
sum_le_tsum s (λ x hx, zero_le _) ennreal.summable
protected lemma tsum_eq_supr_nat' {f : ℕ → ℝ≥0∞} {N : ℕ → ℕ} (hN : tendsto N at_top at_top) :
∑'i:ℕ, f i = (⨆i:ℕ, ∑ a in finset.range (N i), f a) :=
ennreal.tsum_eq_supr_sum' _ $ λ t,
let ⟨n, hn⟩ := t.exists_nat_subset_range,
⟨k, _, hk⟩ := exists_le_of_tendsto_at_top hN 0 n in
⟨k, finset.subset.trans hn (finset.range_mono hk)⟩
protected lemma tsum_eq_supr_nat {f : ℕ → ℝ≥0∞} :
∑'i:ℕ, f i = (⨆i:ℕ, ∑ a in finset.range i, f a) :=
ennreal.tsum_eq_supr_sum' _ finset.exists_nat_subset_range
protected lemma tsum_eq_liminf_sum_nat {f : ℕ → ℝ≥0∞} :
∑' i, f i = filter.at_top.liminf (λ n, ∑ i in finset.range n, f i) :=
begin
rw [ennreal.tsum_eq_supr_nat, filter.liminf_eq_supr_infi_of_nat],
congr,
refine funext (λ n, le_antisymm _ _),
{ refine le_binfi (λ i hi, finset.sum_le_sum_of_subset_of_nonneg _ (λ _ _ _, zero_le _)),
simpa only [finset.range_subset, add_le_add_iff_right] using hi, },
{ refine le_trans (infi_le _ n) _,
simp [le_refl n, le_refl ((finset.range n).sum f)], },
end
protected lemma le_tsum (a : α) : f a ≤ ∑'a, f a :=
le_tsum' ennreal.summable a
@[simp] protected lemma tsum_eq_zero : ∑' i, f i = 0 ↔ ∀ i, f i = 0 :=
⟨λ h i, nonpos_iff_eq_zero.1 $ h ▸ ennreal.le_tsum i, λ h, by simp [h]⟩
protected lemma tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → ∑' a, f a = ∞
| ⟨a, ha⟩ := top_unique $ ha ▸ ennreal.le_tsum a
@[simp] protected lemma tsum_top [nonempty α] : ∑' a : α, ∞ = ∞ :=
let ⟨a⟩ := ‹nonempty α› in ennreal.tsum_eq_top_of_eq_top ⟨a, rfl⟩
lemma tsum_const_eq_top_of_ne_zero {α : Type*} [infinite α] {c : ℝ≥0∞} (hc : c ≠ 0) :
(∑' (a : α), c) = ∞ :=
begin
have A : tendsto (λ (n : ℕ), (n : ℝ≥0∞) * c) at_top (𝓝 (∞ * c)),
{ apply ennreal.tendsto.mul_const tendsto_nat_nhds_top,
simp only [true_or, top_ne_zero, ne.def, not_false_iff] },
have B : ∀ (n : ℕ), (n : ℝ≥0∞) * c ≤ (∑' (a : α), c),
{ assume n,
rcases infinite.exists_subset_card_eq α n with ⟨s, hs⟩,
simpa [hs] using @ennreal.sum_le_tsum α (λ i, c) s },
simpa [hc] using le_of_tendsto' A B,
end
protected lemma ne_top_of_tsum_ne_top (h : ∑' a, f a ≠ ∞) (a : α) : f a ≠ ∞ :=
λ ha, h $ ennreal.tsum_eq_top_of_eq_top ⟨a, ha⟩
protected lemma tsum_mul_left : ∑'i, a * f i = a * ∑'i, f i :=
if h : ∀i, f i = 0 then by simp [h] else
let ⟨i, (hi : f i ≠ 0)⟩ := not_forall.mp h in
have sum_ne_0 : ∑'i, f i ≠ 0, from ne_of_gt $
calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm
... ≤ ∑'i, f i : ennreal.le_tsum _,
have tendsto (λs:finset α, ∑ j in s, a * f j) at_top (𝓝 (a * ∑'i, f i)),
by rw [← show (*) a ∘ (λs:finset α, ∑ j in s, f j) = λs, ∑ j in s, a * f j,
from funext $ λ s, finset.mul_sum];
exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0),
has_sum.tsum_eq this
protected lemma tsum_mul_right : (∑'i, f i * a) = (∑'i, f i) * a :=
by simp [mul_comm, ennreal.tsum_mul_left]
@[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ℝ≥0∞} :
∑'b:α, (⨆ (h : a = b), f b) = f a :=
le_antisymm
(by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s,
calc (∑ b in s, ⨆ (h : a = b), f b) ≤ ∑ b in {a}, ⨆ (h : a = b), f b :
finset.sum_le_sum_of_ne_zero $ assume b _ hb,
suffices a = b, by simpa using this.symm,
classical.by_contradiction $ assume h,
by simpa [h] using hb
... = f a : by simp))
(calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl
... ≤ (∑'b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _)
lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0∞} (r : ℝ≥0∞) :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
refine ⟨has_sum.tendsto_sum_nat, assume h, _⟩,
rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat],
{ exact ennreal.summable.has_sum },
{ exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) }
end
lemma tendsto_nat_tsum (f : ℕ → ℝ≥0∞) :
tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 (∑' n, f n)) :=
by { rw ← has_sum_iff_tendsto_nat, exact ennreal.summable.has_sum }
lemma to_nnreal_apply_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) (x : α) :
(((ennreal.to_nnreal ∘ f) x : ℝ≥0) : ℝ≥0∞) = f x :=
coe_to_nnreal $ ennreal.ne_top_of_tsum_ne_top hf _
lemma summable_to_nnreal_of_tsum_ne_top {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' i, f i ≠ ∞) :
summable (ennreal.to_nnreal ∘ f) :=
by simpa only [←tsum_coe_ne_top_iff_summable, to_nnreal_apply_of_tsum_ne_top hf] using hf
lemma tendsto_cofinite_zero_of_tsum_ne_top {α} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) :
tendsto f cofinite (𝓝 0) :=
begin
have f_ne_top : ∀ n, f n ≠ ∞, from ennreal.ne_top_of_tsum_ne_top hf,
have h_f_coe : f = λ n, ((f n).to_nnreal : ennreal),
from funext (λ n, (coe_to_nnreal (f_ne_top n)).symm),
rw [h_f_coe, ←@coe_zero, tendsto_coe],
exact nnreal.tendsto_cofinite_zero_of_summable (summable_to_nnreal_of_tsum_ne_top hf),
end
lemma tendsto_at_top_zero_of_tsum_ne_top {f : ℕ → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) :
tendsto f at_top (𝓝 0) :=
by { rw ←nat.cofinite_eq_at_top, exact tendsto_cofinite_zero_of_tsum_ne_top hf }
/-- The sum over the complement of a finset tends to `0` when the finset grows to cover the whole
space. This does not need a summability assumption, as otherwise all sums are zero. -/
lemma tendsto_tsum_compl_at_top_zero {α : Type*} {f : α → ℝ≥0∞} (hf : ∑' x, f x ≠ ∞) :
tendsto (λ (s : finset α), ∑' b : {x // x ∉ s}, f b) at_top (𝓝 0) :=
begin
lift f to α → ℝ≥0 using ennreal.ne_top_of_tsum_ne_top hf,
convert ennreal.tendsto_coe.2 (nnreal.tendsto_tsum_compl_at_top_zero f),
ext1 s,
rw ennreal.coe_tsum,
exact nnreal.summable_comp_injective (tsum_coe_ne_top_iff_summable.1 hf) subtype.coe_injective
end
protected lemma tsum_apply {ι α : Type*} {f : ι → α → ℝ≥0∞} {x : α} :
(∑' i, f i) x = ∑' i, f i x :=
tsum_apply $ pi.summable.mpr $ λ _, ennreal.summable
lemma tsum_sub {f : ℕ → ℝ≥0∞} {g : ℕ → ℝ≥0∞} (h₁ : ∑' i, g i ≠ ∞) (h₂ : g ≤ f) :
∑' i, (f i - g i) = (∑' i, f i) - (∑' i, g i) :=
begin
have h₃: ∑' i, (f i - g i) = ∑' i, (f i - g i + g i) - ∑' i, g i,
{ rw [ennreal.tsum_add, add_sub_self h₁]},
have h₄:(λ i, (f i - g i) + (g i)) = f,
{ ext n, rw tsub_add_cancel_of_le (h₂ n)},
rw h₄ at h₃, apply h₃,
end
end tsum
lemma tendsto_to_real_iff {ι} {fi : filter ι} {f : ι → ℝ≥0∞} (hf : ∀ i, f i ≠ ∞) {x : ℝ≥0∞}
(hx : x ≠ ∞) :
fi.tendsto (λ n, (f n).to_real) (𝓝 x.to_real) ↔ fi.tendsto f (𝓝 x) :=
begin
refine ⟨λ h, _, λ h, tendsto.comp (ennreal.tendsto_to_real hx) h⟩,
have h_eq : f = (λ n, ennreal.of_real (f n).to_real),
by { ext1 n, rw ennreal.of_real_to_real (hf n), },
rw [h_eq, ← ennreal.of_real_to_real hx],
exact ennreal.tendsto_of_real h,
end
lemma tsum_coe_ne_top_iff_summable_coe {f : α → ℝ≥0} :
∑' a, (f a : ℝ≥0∞) ≠ ∞ ↔ summable (λ a, (f a : ℝ)) :=
begin
rw nnreal.summable_coe,
exact tsum_coe_ne_top_iff_summable,
end
lemma tsum_coe_eq_top_iff_not_summable_coe {f : α → ℝ≥0} :
∑' a, (f a : ℝ≥0∞) = ∞ ↔ ¬ summable (λ a, (f a : ℝ)) :=
begin
rw [← @not_not (∑' a, ↑(f a) = ⊤)],
exact not_congr tsum_coe_ne_top_iff_summable_coe
end
lemma summable_to_real {f : α → ℝ≥0∞} (hsum : ∑' x, f x ≠ ∞) :
summable (λ x, (f x).to_real) :=
begin
lift f to α → ℝ≥0 using ennreal.ne_top_of_tsum_ne_top hsum,
rwa ennreal.tsum_coe_ne_top_iff_summable_coe at hsum,
end
end ennreal
namespace nnreal
open_locale nnreal
lemma tsum_eq_to_nnreal_tsum {f : β → ℝ≥0} :
(∑' b, f b) = (∑' b, (f b : ℝ≥0∞)).to_nnreal :=
begin
by_cases h : summable f,
{ rw [← ennreal.coe_tsum h, ennreal.to_nnreal_coe] },
{ have A := tsum_eq_zero_of_not_summable h,
simp only [← ennreal.tsum_coe_ne_top_iff_summable, not_not] at h,
simp only [h, ennreal.top_to_nnreal, A] }
end
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma exists_le_has_sum_of_le {f g : β → ℝ≥0} {r : ℝ≥0}
(hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p :=
have ∑'b, (g b : ℝ≥0∞) ≤ r,
begin
refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr),
exact ennreal.coe_le_coe.2 (hgf _)
end,
let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in
⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ ennreal.summable.has_sum⟩
/-- Comparison test of convergence of `ℝ≥0`-valued series. -/
lemma summable_of_le {f g : β → ℝ≥0} (hgf : ∀b, g b ≤ f b) : summable f → summable g
| ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in hp.summable
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat {f : ℕ → ℝ≥0} {r : ℝ≥0} :
has_sum f r ↔ tendsto (λn:ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat],
simp only [ennreal.coe_finset_sum.symm],
exact ennreal.tendsto_coe
end
lemma not_summable_iff_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
split,
{ intros h,
refine ((tendsto_of_monotone _).resolve_right h).comp _,
exacts [finset.sum_mono_set _, tendsto_finset_range] },
{ rintros hnat ⟨r, hr⟩,
exact not_tendsto_nhds_of_tendsto_at_top hnat _ (has_sum_iff_tendsto_nat.1 hr) }
end
lemma summable_iff_not_tendsto_nat_at_top {f : ℕ → ℝ≥0} :
summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top]
lemma summable_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply summable_iff_not_tendsto_nat_at_top.2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ≥0} {c : ℝ≥0}
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : ∑' n, f n ≤ c :=
le_of_tendsto' (has_sum_iff_tendsto_nat.1 (summable_of_sum_range_le h).has_sum) h
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ≥0} (hf : summable f)
{i : β → α} (hi : function.injective i) : ∑' x, f (i x) ≤ ∑' x, f x :=
tsum_le_tsum_of_inj i hi (λ c hc, zero_le _) (λ b, le_refl _) (summable_comp_injective hf hi) hf
lemma summable_sigma {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ≥0} :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
begin
split,
{ simp only [← nnreal.summable_coe, nnreal.coe_tsum],
exact λ h, ⟨h.sigma_factor, h.sigma⟩ },
{ rintro ⟨h₁, h₂⟩,
simpa only [← ennreal.tsum_coe_ne_top_iff_summable, ennreal.tsum_sigma', ennreal.coe_tsum, h₁]
using h₂ }
end
lemma indicator_summable {f : α → ℝ≥0} (hf : summable f) (s : set α) :
summable (s.indicator f) :=
begin
refine nnreal.summable_of_le (λ a, le_trans (le_of_eq (s.indicator_apply f a)) _) hf,
split_ifs,
exact le_refl (f a),
exact zero_le_coe,
end
lemma tsum_indicator_ne_zero {f : α → ℝ≥0} (hf : summable f) {s : set α} (h : ∃ a ∈ s, f a ≠ 0) :
∑' x, (s.indicator f) x ≠ 0 :=
λ h', let ⟨a, ha, hap⟩ := h in
hap (trans (set.indicator_apply_eq_self.mpr (absurd ha)).symm
(((tsum_eq_zero_iff (indicator_summable hf s)).1 h') a))
open finset
/-- For `f : ℕ → ℝ≥0`, then `∑' k, f (k + i)` tends to zero. This does not require a summability
assumption on `f`, as otherwise all sums are zero. -/
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
rw ← tendsto_coe,
convert tendsto_sum_nat_add (λ i, (f i : ℝ)),
norm_cast,
end
lemma has_sum_lt {f g : α → ℝ≥0} {sf sg : ℝ≥0} {i : α} (h : ∀ (a : α), f a ≤ g a) (hi : f i < g i)
(hf : has_sum f sf) (hg : has_sum g sg) : sf < sg :=
begin
have A : ∀ (a : α), (f a : ℝ) ≤ g a := λ a, nnreal.coe_le_coe.2 (h a),
have : (sf : ℝ) < sg :=
has_sum_lt A (nnreal.coe_lt_coe.2 hi) (has_sum_coe.2 hf) (has_sum_coe.2 hg),
exact nnreal.coe_lt_coe.1 this
end
@[mono] lemma has_sum_strict_mono
{f g : α → ℝ≥0} {sf sg : ℝ≥0} (hf : has_sum f sf) (hg : has_sum g sg) (h : f < g) : sf < sg :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in has_sum_lt hle hi hf hg
lemma tsum_lt_tsum {f g : α → ℝ≥0} {i : α} (h : ∀ (a : α), f a ≤ g a) (hi : f i < g i)
(hg : summable g) : ∑' n, f n < ∑' n, g n :=
has_sum_lt h hi (summable_of_le h hg).has_sum hg.has_sum
@[mono] lemma tsum_strict_mono {f g : α → ℝ≥0} (hg : summable g) (h : f < g) :
∑' n, f n < ∑' n, g n :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in tsum_lt_tsum hle hi hg
lemma tsum_pos {g : α → ℝ≥0} (hg : summable g) (i : α) (hi : 0 < g i) :
0 < ∑' b, g b :=
by { rw ← tsum_zero, exact tsum_lt_tsum (λ a, zero_le _) hi hg }
end nnreal
namespace ennreal
lemma tsum_to_real_eq
{f : α → ℝ≥0∞} (hf : ∀ a, f a ≠ ∞) :
(∑' a, f a).to_real = ∑' a, (f a).to_real :=
begin
lift f to α → ℝ≥0 using hf,
have : (∑' (a : α), (f a : ℝ≥0∞)).to_real =
((∑' (a : α), (f a : ℝ≥0∞)).to_nnreal : ℝ≥0∞).to_real,
{ rw [ennreal.coe_to_real], refl },
rw [this, ← nnreal.tsum_eq_to_nnreal_tsum, ennreal.coe_to_real],
exact nnreal.coe_tsum
end
lemma tendsto_sum_nat_add (f : ℕ → ℝ≥0∞) (hf : ∑' i, f i ≠ ∞) :
tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
lift f to ℕ → ℝ≥0 using ennreal.ne_top_of_tsum_ne_top hf,
replace hf : summable f := tsum_coe_ne_top_iff_summable.1 hf,
simp only [← ennreal.coe_tsum, nnreal.summable_nat_add _ hf, ← ennreal.coe_zero],
exact_mod_cast nnreal.tendsto_sum_nat_add f
end
end ennreal
lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : summable f) (hn : ∀ a, 0 ≤ f a)
{i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f :=
begin
lift f to α → ℝ≥0 using hn,
rw nnreal.summable_coe at hf,
simpa only [(∘), ← nnreal.coe_tsum] using nnreal.tsum_comp_le_tsum_of_inj hf hi
end
/-- Comparison test of convergence of series of non-negative real numbers. -/
lemma summable_of_nonneg_of_le {f g : β → ℝ}
(hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g :=
begin
lift f to β → ℝ≥0 using λ b, (hg b).trans (hgf b),
lift g to β → ℝ≥0 using hg,
rw nnreal.summable_coe at hf ⊢,
exact nnreal.summable_of_le (λ b, nnreal.coe_le_coe.1 (hgf b)) hf
end
/-- A series of non-negative real numbers converges to `r` in the sense of `has_sum` if and only if
the sequence of partial sum converges to `r`. -/
lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) :
has_sum f r ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top (𝓝 r) :=
begin
lift f to ℕ → ℝ≥0 using hf,
simp only [has_sum, ← nnreal.coe_sum, nnreal.tendsto_coe'],
exact exists_congr (λ hr, nnreal.has_sum_iff_tendsto_nat)
end
lemma ennreal.of_real_tsum_of_nonneg {f : α → ℝ} (hf_nonneg : ∀ n, 0 ≤ f n) (hf : summable f) :
ennreal.of_real (∑' n, f n) = ∑' n, ennreal.of_real (f n) :=
by simp_rw [ennreal.of_real, ennreal.tsum_coe_eq (nnreal.has_sum_of_real_of_nonneg hf_nonneg hf)]
lemma not_summable_iff_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) :
¬ summable f ↔ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
begin
lift f to ℕ → ℝ≥0 using hf,
exact_mod_cast nnreal.not_summable_iff_tendsto_nat_at_top
end
lemma summable_iff_not_tendsto_nat_at_top_of_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) :
summable f ↔ ¬ tendsto (λ n : ℕ, ∑ i in finset.range n, f i) at_top at_top :=
by rw [← not_iff_not, not_not, not_summable_iff_tendsto_nat_at_top_of_nonneg hf]
lemma summable_sigma_of_nonneg {β : Π x : α, Type*} {f : (Σ x, β x) → ℝ} (hf : ∀ x, 0 ≤ f x) :
summable f ↔ (∀ x, summable (λ y, f ⟨x, y⟩)) ∧ summable (λ x, ∑' y, f ⟨x, y⟩) :=
by { lift f to (Σ x, β x) → ℝ≥0 using hf, exact_mod_cast nnreal.summable_sigma }
lemma summable_of_sum_le {ι : Type*} {f : ι → ℝ} {c : ℝ} (hf : 0 ≤ f)
(h : ∀ u : finset ι, ∑ x in u, f x ≤ c) :
summable f :=
⟨ ⨆ u : finset ι, ∑ x in u, f x,
tendsto_at_top_csupr (finset.sum_mono_set_of_nonneg hf) ⟨c, λ y ⟨u, hu⟩, hu ▸ h u⟩ ⟩
lemma summable_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : summable f :=
begin
apply (summable_iff_not_tendsto_nat_at_top_of_nonneg hf).2 (λ H, _),
rcases exists_lt_of_tendsto_at_top H 0 c with ⟨n, -, hn⟩,
exact lt_irrefl _ (hn.trans_le (h n)),
end
lemma tsum_le_of_sum_range_le {f : ℕ → ℝ} {c : ℝ} (hf : ∀ n, 0 ≤ f n)
(h : ∀ n, ∑ i in finset.range n, f i ≤ c) : ∑' n, f n ≤ c :=
le_of_tendsto' ((has_sum_iff_tendsto_nat_of_nonneg hf _).1
(summable_of_sum_range_le hf h).has_sum) h
/-- If a sequence `f` with non-negative terms is dominated by a sequence `g` with summable
series and at least one term of `f` is strictly smaller than the corresponding term in `g`,
then the series of `f` is strictly smaller than the series of `g`. -/
lemma tsum_lt_tsum_of_nonneg {i : ℕ} {f g : ℕ → ℝ}
(h0 : ∀ (b : ℕ), 0 ≤ f b) (h : ∀ (b : ℕ), f b ≤ g b) (hi : f i < g i) (hg : summable g) :
∑' n, f n < ∑' n, g n :=
tsum_lt_tsum h hi (summable_of_nonneg_of_le h0 h hg) hg
section
variables [emetric_space β]
open ennreal filter emetric
/-- In an emetric ball, the distance between points is everywhere finite -/
lemma edist_ne_top_of_mem_ball {a : β} {r : ℝ≥0∞} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ :=
lt_top_iff_ne_top.1 $
calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a
... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2
... ≤ ⊤ : le_top
/-- Each ball in an extended metric space gives us a metric space, as the edist
is everywhere finite. -/
def metric_space_emetric_ball (a : β) (r : ℝ≥0∞) : metric_space (ball a r) :=
emetric_space.to_metric_space edist_ne_top_of_mem_ball
local attribute [instance] metric_space_emetric_ball
lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ℝ≥0∞) (h : x ∈ ball a r) :
𝓝 x = map (coe : ball a r → β) (𝓝 ⟨x, h⟩) :=
(map_nhds_subtype_coe_eq _ $ is_open.mem_nhds emetric.is_open_ball h).symm
end
section
variable [pseudo_emetric_space α]
open emetric
lemma tendsto_iff_edist_tendsto_0 {l : filter β} {f : β → α} {y : α} :
tendsto f l (𝓝 y) ↔ tendsto (λ x, edist (f x) y) l (𝓝 0) :=
by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball,
@tendsto_order ℝ≥0∞ β _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and]
/-- Yet another metric characterization of Cauchy sequences on integers. This one is often the
most efficient. -/
lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty β] [semilattice_sup β] {s : β → α} :
cauchy_seq s ↔ (∃ (b: β → ℝ≥0∞), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N)
∧ (tendsto b at_top (𝓝 0))) :=
⟨begin
assume hs,
rw emetric.cauchy_seq_iff at hs,
/- `s` is Cauchy sequence. The sequence `b` will be constructed by taking
the supremum of the distances between `s n` and `s m` for `n m ≥ N`-/
let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}),
--Prove that it bounds the distances of points in the Cauchy sequence
have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
{ refine λm n N hm hn, le_Sup _,
use (prod.mk m n),
simp only [and_true, eq_self_iff_true, set.mem_set_of_eq],
exact ⟨hm, hn⟩ },
--Prove that it tends to `0`, by using the Cauchy property of `s`
have D : tendsto b at_top (𝓝 0),
{ refine tendsto_order.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩,
rcases exists_between εpos with ⟨δ, δpos, δlt⟩,
rcases hs δ δpos with ⟨N, hN⟩,
refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩,
have : b n ≤ δ := Sup_le begin
simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists],
intros d p q hp hq hd,
rw ← hd,
exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq))
end,
simpa using lt_of_le_of_lt this δlt },
-- Conclude
exact ⟨b, ⟨C, D⟩⟩
end,
begin
rintros ⟨b, ⟨b_bound, b_lim⟩⟩,
/-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N,
b_lim : tendsto b at_top (𝓝 0)-/
refine emetric.cauchy_seq_iff.2 (λε εpos, _),
have : ∀ᶠ n in at_top, b n < ε := (tendsto_order.1 b_lim ).2 _ εpos,
rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩,
exact ⟨N, λm n hm hn, calc
edist (s m) (s n) ≤ b N : b_bound m n N hm hn
... < ε : (hN _ (le_refl N)) ⟩
end⟩
lemma continuous_of_le_add_edist {f : α → ℝ≥0∞} (C : ℝ≥0∞)
(hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f :=
begin
rcases eq_or_ne C 0 with (rfl|C0),
{ simp only [zero_mul, add_zero] at h,
exact continuous_of_const (λ x y, le_antisymm (h _ _) (h _ _)) },
{ refine continuous_iff_continuous_at.2 (λ x, _),
by_cases hx : f x = ∞,
{ have : f =ᶠ[𝓝 x] (λ _, ∞),
{ filter_upwards [emetric.ball_mem_nhds x ennreal.coe_lt_top],
refine λ y (hy : edist y x < ⊤), _, rw edist_comm at hy,
simpa [hx, hC, hy.ne] using h x y },
exact this.continuous_at },
{ refine (ennreal.tendsto_nhds hx).2 (λ ε (ε0 : 0 < ε), _),
filter_upwards [emetric.closed_ball_mem_nhds x (ennreal.div_pos_iff.2 ⟨ε0.ne', hC⟩)],
have hεC : C * (ε / C) = ε := ennreal.mul_div_cancel' C0 hC,
refine λ y (hy : edist y x ≤ ε / C), ⟨tsub_le_iff_right.2 _, _⟩,
{ rw edist_comm at hy,
calc f x ≤ f y + C * edist x y : h x y
... ≤ f y + C * (ε / C) : add_le_add_left (mul_le_mul_left' hy C) (f y)
... = f y + ε : by rw hεC },
{ calc f y ≤ f x + C * edist y x : h y x
... ≤ f x + C * (ε / C) : add_le_add_left (mul_le_mul_left' hy C) (f x)
... = f x + ε : by rw hεC } } }
end
theorem continuous_edist : continuous (λp:α×α, edist p.1 p.2) :=
begin
apply continuous_of_le_add_edist 2 (by norm_num),
rintros ⟨x, y⟩ ⟨x', y'⟩,
calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _
... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc
... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) :
add_le_add_left (add_le_add (le_max_left _ _) (le_max_right _ _)) _
... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm]
end
@[continuity] theorem continuous.edist [topological_space β] {f g : β → α}
(hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) :=
continuous_edist.comp (hf.prod_mk hg : _)
theorem filter.tendsto.edist {f g : β → α} {x : filter β} {a b : α}
(hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) :
tendsto (λx, edist (f x) (g x)) x (𝓝 (edist a b)) :=
(continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg)
lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) :
cauchy_seq f :=
begin
lift d to (ℕ → nnreal) using (λ i, ennreal.ne_top_of_tsum_ne_top hd i),
rw ennreal.tsum_coe_ne_top_iff_summable at hd,
exact cauchy_seq_of_edist_le_of_summable d hf hd
end
lemma emetric.is_closed_ball {a : α} {r : ℝ≥0∞} : is_closed (closed_ball a r) :=
is_closed_le (continuous_id.edist continuous_const) continuous_const
@[simp] lemma emetric.diam_closure (s : set α) : diam (closure s) = diam s :=
begin
refine le_antisymm (diam_le $ λ x hx y hy, _) (diam_mono subset_closure),
have : edist x y ∈ closure (Iic (diam s)),
from map_mem_closure2 (@continuous_edist α _) hx hy (λ _ _, edist_le_diam_of_mem),
rwa closure_Iic at this
end
@[simp] lemma metric.diam_closure {α : Type*} [pseudo_metric_space α] (s : set α) :
metric.diam (closure s) = diam s :=
by simp only [metric.diam, emetric.diam_closure]
lemma is_closed_set_of_lipschitz_on_with {α β} [pseudo_emetric_space α] [pseudo_emetric_space β]
(K : ℝ≥0) (s : set α) :
is_closed {f : α → β | lipschitz_on_with K f s} :=
begin
simp only [lipschitz_on_with, set_of_forall],
refine is_closed_bInter (λ x hx, is_closed_bInter $ λ y hy, is_closed_le _ _),
exacts [continuous.edist (continuous_apply x) (continuous_apply y), continuous_const]
end
lemma is_closed_set_of_lipschitz_with {α β} [pseudo_emetric_space α] [pseudo_emetric_space β]
(K : ℝ≥0) :
is_closed {f : α → β | lipschitz_with K f} :=
by simp only [← lipschitz_on_univ, is_closed_set_of_lipschitz_on_with]
namespace real
/-- For a bounded set `s : set ℝ`, its `emetric.diam` is equal to `Sup s - Inf s` reinterpreted as
`ℝ≥0∞`. -/
lemma ediam_eq {s : set ℝ} (h : bounded s) :
emetric.diam s = ennreal.of_real (Sup s - Inf s) :=
begin
rcases eq_empty_or_nonempty s with rfl|hne, { simp },
refine le_antisymm (metric.ediam_le_of_forall_dist_le $ λ x hx y hy, _) _,
{ have := real.subset_Icc_Inf_Sup_of_bounded h,
exact real.dist_le_of_mem_Icc (this hx) (this hy) },
{ apply ennreal.of_real_le_of_le_to_real,
rw [← metric.diam, ← metric.diam_closure],
have h' := real.bounded_iff_bdd_below_bdd_above.1 h,
calc Sup s - Inf s ≤ dist (Sup s) (Inf s) : le_abs_self _
... ≤ diam (closure s) :
dist_le_diam_of_mem h.closure (cSup_mem_closure hne h'.2) (cInf_mem_closure hne h'.1) }
end
/-- For a bounded set `s : set ℝ`, its `metric.diam` is equal to `Sup s - Inf s`. -/
lemma diam_eq {s : set ℝ} (h : bounded s) : metric.diam s = Sup s - Inf s :=
begin
rw [metric.diam, real.ediam_eq h, ennreal.to_real_of_real],
rw real.bounded_iff_bdd_below_bdd_above at h,
exact sub_nonneg.2 (real.Inf_le_Sup s h.1 h.2)
end
@[simp] lemma ediam_Ioo (a b : ℝ) :
emetric.diam (Ioo a b) = ennreal.of_real (b - a) :=
begin
rcases le_or_lt b a with h|h,
{ simp [h] },
{ rw [real.ediam_eq (bounded_Ioo _ _), cSup_Ioo h, cInf_Ioo h] },
end
@[simp] lemma ediam_Icc (a b : ℝ) :
emetric.diam (Icc a b) = ennreal.of_real (b - a) :=
begin
rcases le_or_lt a b with h|h,
{ rw [real.ediam_eq (bounded_Icc _ _), cSup_Icc h, cInf_Icc h] },
{ simp [h, h.le] }
end
@[simp] lemma ediam_Ico (a b : ℝ) :
emetric.diam (Ico a b) = ennreal.of_real (b - a) :=
le_antisymm (ediam_Icc a b ▸ diam_mono Ico_subset_Icc_self)
(ediam_Ioo a b ▸ diam_mono Ioo_subset_Ico_self)
@[simp] lemma ediam_Ioc (a b : ℝ) :
emetric.diam (Ioc a b) = ennreal.of_real (b - a) :=
le_antisymm (ediam_Icc a b ▸ diam_mono Ioc_subset_Icc_self)
(ediam_Ioo a b ▸ diam_mono Ioo_subset_Ioc_self)
end real
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ℝ≥0∞`,
then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.edist ha)
(mem_at_top_sets.2 ⟨n, λ m hnm, _⟩),
refine le_trans (edist_le_Ico_sum_of_edist_le hnm (λ k _ _, hf k)) _,
rw [finset.sum_Ico_eq_sum_range],
exact sum_le_tsum _ (λ _ _, zero_le _) ennreal.summable
end
/-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ℝ≥0∞`,
then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/
lemma edist_le_tsum_of_edist_le_of_tendsto₀ {f : ℕ → α} (d : ℕ → ℝ≥0∞)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n)
{a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ ∑' m, d m :=
by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0
end --section
|
60306bf2519eceeb56fa1f6dd6434159a127c535 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/abstract_notation.lean | 07515d45c8be4f381f3a042cf1255f7e43222818 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 178 | lean | import data.nat
open nat
notation `$`:max := abstract by blast end
definition foo (a b : nat) : a + b = b + a ∧ a = 0 + a :=
and.intro $ $
check foo_1
check foo_2
print foo
|
511cfbbf2722258a8f843e68b788a415c7acba79 | 99b5e6372af1f404777312358869f95be7de84a3 | /src/hott/algebra/ring.lean | 71daaf83c345961d337dc87690f6bcc736efc717 | [
"Apache-2.0"
] | permissive | forked-from-1kasper/hott3 | 8fa064ab5e8c9d6752a783d74ab226ddc5b5232a | 2db24de7a361a7793b0eae4ca5c3fd4d4a0fc691 | refs/heads/master | 1,584,867,131,028 | 1,530,766,841,000 | 1,530,766,841,000 | 139,797,034 | 0 | 0 | Apache-2.0 | 1,530,766,961,000 | 1,530,766,961,000 | null | UTF-8 | Lean | false | false | 20,931 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
Structures with multiplicative and additive components, including semirings, rings, and fields.
The development is modeled after Isabelle's library.
-/
import .group
universes u v w
hott_theory
set_option old_structure_cmd true
namespace hott
open algebra
variable {A : Type _}
namespace algebra
/- auxiliary classes -/
@[hott, class] structure distrib (A : Type _) extends has_mul A, has_add A :=
(left_distrib : Πa b c, mul a (add b c) = add (mul a b) (mul a c))
(right_distrib : Πa b c, mul (add a b) c = add (mul a c) (mul b c))
@[hott] def left_distrib [s : distrib A] (a b c : A) : a * (b + c) = a * b + a * c :=
distrib.left_distrib _ _ _
@[hott] def right_distrib [s: distrib A] (a b c : A) : (a + b) * c = a * c + b * c :=
distrib.right_distrib _ _ _
@[hott, class] structure mul_zero_class (A : Type _) extends has_mul A, has_zero A :=
(zero_mul : Πa, mul zero a = zero)
(mul_zero : Πa, mul a zero = zero)
@[hott] def zero_mul [s : mul_zero_class A] (a : A) : 0 * a = 0 := mul_zero_class.zero_mul _
@[hott] def mul_zero [s : mul_zero_class A] (a : A) : a * 0 = 0 := mul_zero_class.mul_zero _
@[hott, class] structure zero_ne_one_class (A : Type _) extends has_zero A, has_one A :=
(zero_ne_one : zero ≠ one)
@[hott] theorem zero_ne_one [s: zero_ne_one_class A] : 0 ≠ (1:A) := @zero_ne_one_class.zero_ne_one A s
/- semiring -/
@[hott] structure semiring (A : Type _) extends comm_monoid A renaming
mul→add mul_assoc→add_assoc one→zero one_mul→zero_add mul_one→add_zero mul_comm→add_comm,
monoid A, distrib A, mul_zero_class A
/- we make it a class now (and not as part of the structure) to avoid
semiring.to_comm_monoid to be an instance -/
attribute [class] semiring
@[hott, reducible, instance] def add_comm_monoid_of_semiring (A : Type _)
[H : semiring A] : add_comm_monoid A :=
@semiring.to_comm_monoid A H
@[hott, reducible, instance] def monoid_of_semiring (A : Type _)
[H : semiring A] : monoid A :=
@semiring.to_monoid A H
@[hott, reducible, instance] def distrib_of_semiring (A : Type _)
[H : semiring A] : distrib A :=
@semiring.to_distrib A H
@[hott, reducible, instance] def mul_zero_class_of_semiring (A : Type _)
[H : semiring A] : mul_zero_class A :=
@semiring.to_mul_zero_class A H
section semiring
variables [s : semiring A] (a b c : A)
include s
@[hott] theorem As {a b c : A} : a + b + c = a + (b + c) :=
add.assoc _ _ _
@[hott] theorem one_add_one_eq_two : 1 + 1 = 2 :> A :=
by unfold bit0
@[hott] theorem ne_zero_of_mul_ne_zero_right {a b : A} (H : a * b ≠ 0) : a ≠ 0 :=
λthis,
have a * b = 0, by rwr [this, zero_mul],
H this
@[hott] theorem ne_zero_of_mul_ne_zero_left {a b : A} (H : a * b ≠ 0) : b ≠ 0 :=
λthis,
have a * b = 0, by rwr [this, mul_zero],
H this
@[hott] theorem distrib_three_right (a b c d : A) : (a + b + c) * d = a * d + b * d + c * d :=
by rwr [right_distrib, right_distrib]
@[hott] theorem mul_two : a * 2 = a + a :=
by rwr [←one_add_one_eq_two, left_distrib, mul_one]
@[hott] theorem two_mul : 2 * a = a + a :=
by rwr [←one_add_one_eq_two, right_distrib, one_mul]
end semiring
/- comm semiring -/
@[hott, class] structure comm_semiring (A : Type _) extends semiring A, comm_monoid A
-- TODO: we could also define a cancelative comm_semiring, i.e. satisfying
-- c ≠ 0 → c * a = c * b → a = b.
-- section comm_semiring
-- variables [s : comm_semiring A] (a b c : A)
-- include s
-- @[hott] protected def algebra.dvd (a b : A) : Type _ := Σc, b = a * c
-- @[hott, instance, priority 500] def comm_semiring_has_dvd : has_dvd A :=
-- has_dvd.mk algebra.dvd
-- @[hott] theorem dvd.intro {a b c : A} (H : a * c = b) : a ∣ b :=
-- sigma.mk _ H⁻¹
-- @[hott] theorem dvd_of_mul_right_eq {a b c : A} (H : a * c = b) : a ∣ b := dvd.intro H
-- @[hott] theorem dvd.intro_left {a b c : A} (H : c * a = b) : a ∣ b :=
-- by rwr mul.comm at H; exact dvd.intro H
-- @[hott] theorem dvd_of_mul_left_eq {a b c : A} (H : c * a = b) : a ∣ b := dvd.intro_left H
-- @[hott] theorem exists_eq_mul_right_of_dvd {a b : A} (H : a ∣ b) : Σc, b = a * c := H
-- @[hott] theorem dvd.elim {P : Type _} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = a * c → P) : P :=
-- sigma.rec_on H₁ H₂
-- @[hott] theorem exists_eq_mul_left_of_dvd {a b : A} (H : a ∣ b) : Σc, b = c * a :=
-- dvd.elim H (take c, assume H1 : b = a * c, sigma.mk c (H1 ⬝ mul.comm _ _))
-- @[hott] theorem dvd.elim_left {P : Type _} {a b : A} (H₁ : a ∣ b) (H₂ : Πc, b = c * a → P) : P :=
-- sigma.rec_on (exists_eq_mul_left_of_dvd H₁) (take c, assume H₃ : b = c * a, H₂ c H₃)
-- @[hott] theorem dvd.refl : a ∣ a := dvd.intro (mul_one _)
-- @[hott] theorem dvd.trans {a b c : A} (H₁ : a ∣ b) (H₂ : b ∣ c) : a ∣ c :=
-- dvd.elim H₁
-- (take d, assume H₃ : b = a * d,
-- dvd.elim H₂
-- (take e, assume H₄ : c = b * e,
-- dvd.intro
-- (show a * (d * e) = c, by rwr [←mul.assoc, -H₃, H₄])))
-- @[hott] theorem eq_zero_of_zero_dvd {a : A} (H : 0 ∣ a) : a = 0 :=
-- dvd.elim H (take c, assume H' : a = 0 * c, H' ⬝ (zero_mul _))
-- @[hott] theorem dvd_zero : a ∣ 0 := dvd.intro (mul_zero _)
-- @[hott] theorem one_dvd : 1 ∣ a := dvd.intro (one_mul _)
-- @[hott] theorem dvd_mul_right : a ∣ a * b := dvd.intro rfl
-- @[hott] theorem dvd_mul_left : a ∣ b * a :=
-- by rwr mul.comm; apply dvd_mul_right
-- @[hott] theorem dvd_mul_of_dvd_left {a b : A} (H : a ∣ b) (c : A) : a ∣ b * c :=
-- dvd.elim H
-- (take d,
-- suppose b = a * d,
-- dvd.intro
-- (show a * (d * c) = b * c, from by rwr [←mul.assoc]; substvars))
-- @[hott] theorem dvd_mul_of_dvd_right {a b : A} (H : a ∣ b) (c : A) : a ∣ c * b :=
-- by rwr mul.comm; exact dvd_mul_of_dvd_left H _
-- @[hott] theorem mul_dvd_mul {a b c d : A} (dvd_ab : a ∣ b) (dvd_cd : c ∣ d) : a * c ∣ b * d :=
-- dvd.elim dvd_ab
-- (take e, suppose b = a * e,
-- dvd.elim dvd_cd
-- (take f, suppose d = c * f,
-- dvd.intro
-- (show a * c * (e * f) = b * d,
-- by rwr [mul.assoc, {c*_}mul.left_comm, -mul.assoc]; substvars)))
-- @[hott] theorem dvd_of_mul_right_dvd {a b c : A} (H : a * b ∣ c) : a ∣ c :=
-- dvd.elim H (take d, assume Habdc : c = a * b * d, dvd.intro ((mul.assoc _ _ _)⁻¹ ⬝ (Habdc _ _ _ _)⁻¹))
-- @[hott] theorem dvd_of_mul_left_dvd {a b c : A} (H : a * b ∣ c) : b ∣ c :=
-- by apply dvd_of_mul_right_dvd; rwr mul.comm; exact H
-- @[hott] theorem dvd_add {a b c : A} (Hab : a ∣ b) (Hac : a ∣ c) : a ∣ b + c :=
-- dvd.elim Hab
-- (take d, suppose b = a * d,
-- dvd.elim Hac
-- (take e, suppose c = a * e,
-- dvd.intro (show a * (d + e) = b + c,
-- by rwr [left_distrib]; substvars)))
-- end comm_semiring
/- ring -/
@[hott] structure ring (A : Type _) extends ab_group A renaming mul→add mul_assoc→add_assoc
one→zero one_mul→zero_add mul_one→add_zero inv→neg mul_left_inv→add_left_inv mul_comm→add_comm,
monoid A, distrib A
/- we make it a class now (and not as part of the structure) to avoid
ring.to_ab_group to be an instance -/
attribute [class] ring
@[hott, reducible, instance] def add_ab_group_of_ring (A : Type _)
[H : ring A] : add_ab_group A :=
@ring.to_ab_group A H
@[hott, reducible, instance] def monoid_of_ring (A : Type _)
[H : ring A] : monoid A :=
@ring.to_monoid A H
@[hott, reducible, instance] def distrib_of_ring (A : Type _)
[H : ring A] : distrib A :=
@ring.to_distrib A H
@[hott] def ring.mul_zero [s : ring A] (a : A) : a * 0 = 0 :=
have a * 0 + 0 = a * 0 + a * 0, from calc
a * 0 + 0 = a * 0 : by rwr add_zero
... = a * (0 + 0) : by rwr add_zero
... = a * 0 + a * 0 : left_distrib a 0 0,
show a * 0 = 0, from (add.left_cancel this)⁻¹
@[hott] def ring.zero_mul [s : ring A] (a : A) : 0 * a = 0 :=
have 0 * a + 0 = 0 * a + 0 * a, from calc
0 * a + 0 = 0 * a : by rwr add_zero
... = (0 + 0) * a : by rwr add_zero
... = 0 * a + 0 * a : right_distrib 0 0 a,
show 0 * a = 0, from (add.left_cancel this)⁻¹
@[hott, reducible, instance] def ring.to_semiring [s : ring A] : semiring A :=
{ mul_zero := ring.mul_zero,
zero_mul := ring.zero_mul, ..s}
section
variables [s : ring A] (a b c d e : A)
include s
@[hott] def neg_mul_eq_neg_mul : -(a * b) = -a * b :=
neg_eq_of_add_eq_zero
begin
rwr [←right_distrib, add.right_inv, zero_mul]
end
@[hott] def neg_mul_eq_mul_neg : -(a * b) = a * -b :=
neg_eq_of_add_eq_zero
begin
rwr [←left_distrib, add.right_inv, mul_zero]
end
@[hott] def neg_mul_eq_neg_mul_symm : - a * b = - (a * b) := (neg_mul_eq_neg_mul _ _)⁻¹ᵖ
@[hott] def mul_neg_eq_neg_mul_symm : a * - b = - (a * b) := (neg_mul_eq_mul_neg _ _)⁻¹ᵖ
@[hott] theorem neg_mul_neg : -a * -b = a * b :=
calc
-a * -b = -(a * -b) : by rwr ←neg_mul_eq_neg_mul
... = - -(a * b) : by rwr ←neg_mul_eq_mul_neg
... = a * b : by rwr neg_neg
@[hott] theorem neg_mul_comm : -a * b = a * -b :=
(neg_mul_eq_neg_mul _ _)⁻¹ ⬝ (neg_mul_eq_mul_neg _ _)
@[hott] def neg_eq_neg_one_mul : -a = - 1 * a :=
calc
-a = -(1 * a) : by rwr one_mul
... = - 1 * a : by rwr neg_mul_eq_neg_mul
@[hott] def mul_sub_left_distrib : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : left_distrib _ _ _
... = a * b + - (a * c) : by rwr ←neg_mul_eq_mul_neg
... = a * b - a * c : rfl
@[hott] def mul_sub_right_distrib : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : right_distrib _ _ _
... = a * c + - (b * c) : by rwr neg_mul_eq_neg_mul
... = a * c - b * c : rfl
@[hott] theorem mul_add_eq_mul_add_iff_sub_mul_add_eq :
a * e + c = b * e + d ↔ (a - b) * e + c = d :=
calc
a * e + c = b * e + d ↔ a * e + c = d + b * e : by rwr add.comm (b*e)
... ↔ a * e + c - b * e = d : iff.symm (sub_eq_iff_eq_add _ _ _)
... ↔ a * e - b * e + c = d : by rwr sub_add_eq_add_sub
... ↔ (a - b) * e + c = d : by rwr mul_sub_right_distrib
@[hott] theorem mul_add_eq_mul_add_of_sub_mul_add_eq :
(a - b) * e + c = d → a * e + c = b * e + d :=
iff.mpr (mul_add_eq_mul_add_iff_sub_mul_add_eq _ _ _ _ _)
@[hott] theorem sub_mul_add_eq_of_mul_add_eq_mul_add :
a * e + c = b * e + d → (a - b) * e + c = d :=
iff.mp (mul_add_eq_mul_add_iff_sub_mul_add_eq _ _ _ _ _)
@[hott] theorem mul_neg_one_eq_neg : a * (- 1) = -a :=
have a + a * - 1 = 0, from calc
a + a * - 1 = a * 1 + a * - 1 : by rwr mul_one
... = a * (1 + - 1) : by rwr left_distrib
... = a * 0 : by rwr add.right_inv
... = 0 : by rwr mul_zero,
(neg_eq_of_add_eq_zero this)⁻¹
@[hott] theorem ne_zero_prod_ne_zero_of_mul_ne_zero {a b : A} (H : a * b ≠ 0) : a ≠ 0 × b ≠ 0 :=
have H1 : a ≠ 0, from
(λthis,
have a * b = 0, by rwr [this, zero_mul],
absurd this H),
have b ≠ 0, from
(λthis,
have a * b = 0, by rwr [this, mul_zero],
absurd this H),
prod.mk H1 this
end
@[hott, class] structure comm_ring (A : Type _) extends ring A, comm_semigroup A
@[hott, reducible, instance] def comm_ring.to_comm_semiring [s : comm_ring A] :
comm_semiring A :=
{ mul_zero := mul_zero,
zero_mul := zero_mul, ..s }
section
variables [s : comm_ring A] (a b c d e : A)
include s
@[hott] theorem mul_self_sub_mul_self_eq : a * a - b * b = (a + b) * (a - b) :=
begin
change a * a + - (b * b) = (a + b) * (a + - b),
rwr [left_distrib, right_distrib, right_distrib, add.assoc],
rwr [←add.assoc (b*a),
←neg_mul_eq_mul_neg, ←neg_mul_eq_mul_neg, mul.comm a b, add.right_inv, zero_add]
end
@[hott] theorem mul_self_sub_one_eq : a * a - 1 = (a + 1) * (a - 1) :=
by rwr [←mul_self_sub_mul_self_eq, mul_one]
-- @[hott] theorem dvd_neg_iff_dvd : (a ∣ -b) ↔ (a ∣ b) :=
-- iff.intro
-- (suppose a ∣ -b,
-- dvd.elim this
-- (take c, suppose -b = a * c,
-- dvd.intro
-- (show a * -c = b,
-- by rwr [←neg_mul_eq_mul_neg, -this, neg_neg])))
-- (suppose a ∣ b,
-- dvd.elim this
-- (take c, suppose b = a * c,
-- dvd.intro
-- (show a * -c = -b,
-- by rwr [←neg_mul_eq_mul_neg, -this])))
-- @[hott] theorem dvd_neg_of_dvd : (a ∣ b) → (a ∣ -b) :=
-- iff.mpr (dvd_neg_iff_dvd _ _)
-- @[hott] theorem dvd_of_dvd_neg : (a ∣ -b) → (a ∣ b) :=
-- iff.mp (dvd_neg_iff_dvd _ _)
-- @[hott] theorem neg_dvd_iff_dvd : (-a ∣ b) ↔ (a ∣ b) :=
-- iff.intro
-- (suppose -a ∣ b,
-- dvd.elim this
-- (take c, suppose b = -a * c,
-- dvd.intro
-- (show a * -c = b, by rwr [←neg_mul_comm, this])))
-- (suppose a ∣ b,
-- dvd.elim this
-- (take c, suppose b = a * c,
-- dvd.intro
-- (show -a * -c = b, by rwr [neg_mul_neg, this])))
-- @[hott] theorem neg_dvd_of_dvd : (a ∣ b) → (-a ∣ b) :=
-- iff.mpr (neg_dvd_iff_dvd _ _)
-- @[hott] theorem dvd_of_neg_dvd : (-a ∣ b) → (a ∣ b) :=
-- iff.mp (neg_dvd_iff_dvd _ _)
-- @[hott] theorem dvd_sub (H₁ : (a ∣ b)) (H₂ : (a ∣ c)) : (a ∣ b - c) :=
-- dvd_add H₁ (dvd_neg_of_dvd H₂)
end
/- integral domains -/
@[hott, class] structure no_zero_divisors (A : Type _) extends has_mul A, has_zero A :=
(eq_zero_sum_eq_zero_of_mul_eq_zero : Πa b, mul a b = zero → a = zero ⊎ b = zero)
@[hott] def eq_zero_sum_eq_zero_of_mul_eq_zero {A : Type _} [s : no_zero_divisors A] {a b : A}
(H : a * b = 0) : a = 0 ⊎ b = 0 :=
no_zero_divisors.eq_zero_sum_eq_zero_of_mul_eq_zero _ _ H
@[hott, class] structure integral_domain (A : Type _) extends comm_ring A, no_zero_divisors A,
zero_ne_one_class A
section
variables [s : integral_domain A] (a b c d e : A)
include s
@[hott] theorem mul_ne_zero {a b : A} (H1 : a ≠ 0) (H2 : b ≠ 0) : a * b ≠ 0 :=
λthis,
sum.elim (eq_zero_sum_eq_zero_of_mul_eq_zero this) (assume H3, H1 H3) (assume H4, H2 H4)
-- @[hott] theorem eq_of_mul_eq_mul_right {a b c : A} (Ha : a ≠ 0) (H : b * a = c * a) : b = c :=
-- have b * a - c * a = 0, from iff.mp (eq_iff_sub_eq_zero _ _) H,
-- have (b - c) * a = 0, by rwr [mul_sub_right_distrib, this],
-- have b - c = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,
-- iff.elim_right (eq_iff_sub_eq_zero _ _) this
-- @[hott] theorem eq_of_mul_eq_mul_left {a b c : A} (Ha : a ≠ 0) (H : a * b = a * c) : b = c :=
-- have a * b - a * c = 0, from iff.mp (eq_iff_sub_eq_zero _ _) H,
-- have a * (b - c) = 0, by rwr [mul_sub_left_distrib, this],
-- have b - c = 0, from sum_resolve_right (eq_zero_sum_eq_zero_of_mul_eq_zero this) Ha,
-- iff.elim_right (eq_iff_sub_eq_zero _ _) this
-- -- TODO: do we want the iff versions?
-- @[hott] theorem eq_zero_of_mul_eq_self_right {a b : A} (H₁ : b ≠ 1) (H₂ : a * b = a) : a = 0 :=
-- have b - 1 ≠ 0, by intro this; apply H₁; rwr zero_add; apply eq_add_of_sub_eq; exact this,
-- have a * b - a = 0, by rwr H₂; apply sub_self,
-- have a * (b - 1) = 0, by rwr [mul_sub_left_distrib, mul_one]; apply this,
-- show a = 0, from sum_resolve_left (eq_zero_sum_eq_zero_of_mul_eq_zero this) `b - 1 ≠ 0`
-- @[hott] theorem eq_zero_of_mul_eq_self_left {a b : A} (H₁ : b ≠ 1) (H₂ : b * a = a) : a = 0 :=
-- by apply eq_zero_of_mul_eq_self_right H₁; by rwr mul.comm; exact H₂
-- @[hott] theorem mul_self_eq_mul_self_iff (a b : A) : a * a = b * b ↔ a = b ⊎ a = -b :=
-- iff.intro
-- (suppose a * a = b * b,
-- have (a - b) * (a + b) = 0,
-- by rwr [mul.comm, -mul_self_sub_mul_self_eq, this, sub_self],
-- have a - b = 0 ⊎ a + b = 0, from eq_zero_sum_eq_zero_of_mul_eq_zero this,
-- sum.elim this
-- (suppose a - b = 0, sum.inl (eq_of_sub_eq_zero this))
-- (suppose a + b = 0, sum.inr (eq_neg_of_add_eq_zero this)))
-- (suppose a = b ⊎ a = -b, sum.elim this
-- (suppose a = b, by rwr this)
-- (suppose a = -b, by rwr [this, neg_mul_neg]))
-- @[hott] theorem mul_self_eq_one_iff (a : A) : a * a = 1 ↔ a = 1 ⊎ a = - 1 :=
-- have a * a = 1 * 1 ↔ a = 1 ⊎ a = - 1, from mul_self_eq_mul_self_iff a 1,
-- by rwr mul_one at this; exact this
-- -- TODO: c - b * c → c = 0 ⊎ b = 1 and variants
-- @[hott] theorem dvd_of_mul_dvd_mul_left {a b c : A} (Ha : a ≠ 0) (Hdvd : (a * b ∣ a * c)) : (b ∣ c) :=
-- dvd.elim Hdvd
-- (take d,
-- suppose a * c = a * b * d,
-- have b * d = c, by apply eq_of_mul_eq_mul_left Ha; rwr [mul.assoc, this],
-- dvd.intro this)
-- @[hott] theorem dvd_of_mul_dvd_mul_right {a b c : A} (Ha : a ≠ 0) (Hdvd : (b * a ∣ c * a)) : (b ∣ c) :=
-- dvd.elim Hdvd
-- (take d,
-- suppose c * a = b * a * d,
-- have b * d * a = c * a, from by rwr [mul.right_comm, -this],
-- have b * d = c, from eq_of_mul_eq_mul_right Ha this,
-- dvd.intro this)
end
namespace norm_num
-- @[hott] theorem mul_zero [s : mul_zero_class A] (a : A) : a * zero = zero :=
-- by rwr [↑zero, mul_zero]
-- @[hott] theorem zero_mul [s : mul_zero_class A] (a : A) : zero * a = zero :=
-- by rwr [↑zero, zero_mul]
-- @[hott] theorem mul_one [s : monoid A] (a : A) : a * one = a :=
-- by rwr [↑one, mul_one]
-- @[hott] theorem mul_bit0 [s : distrib A] (a b : A) : a * (bit0 b) = bit0 (a * b) :=
-- by rwr [↑bit0, left_distrib]
-- @[hott] theorem mul_bit0_helper [s : distrib A] (a b t : A) (H : a * b = t) : a * (bit0 b) = bit0 t :=
-- by rwr ←H; apply mul_bit0
-- @[hott] theorem mul_bit1 [s : semiring A] (a b : A) : a * (bit1 b) = bit0 (a * b) + a :=
-- by rwr [↑bit1, ↑bit0, +left_distrib, ↑one, mul_one]
-- @[hott] theorem mul_bit1_helper [s : semiring A] (a b s t : A) (Hs : a * b = s) (Ht : bit0 s + a = t) :
-- a * (bit1 b) = t :=
-- begin rwr [←Ht, -Hs, mul_bit1] end
-- @[hott] theorem subst_into_prod [s : has_mul A] (l r tl tr t : A) (prl : l = tl) (prr : r = tr)
-- (prt : tl * tr = t) :
-- l * r = t :=
-- by rwr [prl, prr, prt]
-- @[hott] theorem mk_cong (op : A → A) (a b : A) (H : a = b) : op a = op b :=
-- by congruence; exact H
-- @[hott] theorem mk_eq (a : A) : a = a := rfl
-- @[hott] theorem neg_add_neg_eq_of_add_add_eq_zero [s : add_ab_group A] (a b c : A) (H : c + a + b = 0) :
-- -a + -b = c :=
-- begin
-- apply add_neg_eq_of_eq_add,
-- apply neg_eq_of_add_eq_zero,
-- rwr [add.comm, add.assoc, add.comm b, -add.assoc, H]
-- end
-- @[hott] theorem neg_add_neg_helper [s : add_ab_group A] (a b c : A) (H : a + b = c) : -a + -b = -c :=
-- begin apply iff.mp (neg_eq_neg_iff_eq _ _), rwr [neg_add, *neg_neg, H] end
-- @[hott] theorem neg_add_pos_eq_of_eq_add [s : add_ab_group A] (a b c : A) (H : b = c + a) : -a + b = c :=
-- begin apply neg_add_eq_of_eq_add, rwr add.comm, exact H end
-- @[hott] theorem neg_add_pos_helper1 [s : add_ab_group A] (a b c : A) (H : b + c = a) : -a + b = -c :=
-- begin apply neg_add_eq_of_eq_add, apply eq_add_neg_of_add_eq H end
-- @[hott] theorem neg_add_pos_helper2 [s : add_ab_group A] (a b c : A) (H : a + c = b) : -a + b = c :=
-- begin apply neg_add_eq_of_eq_add, rwr H end
-- @[hott] theorem pos_add_neg_helper [s : add_ab_group A] (a b c : A) (H : b + a = c) : a + b = c :=
-- by rwr [add.comm, H]
-- @[hott] theorem sub_eq_add_neg_helper [s : add_ab_group A] (t₁ t₂ e w₁ w₂: A) (H₁ : t₁ = w₁)
-- (H₂ : t₂ = w₂) (H : w₁ + -w₂ = e) : t₁ - t₂ = e :=
-- by rwr [sub_eq_add_neg, H₁, H₂, H]
-- @[hott] theorem pos_add_pos_helper [s : add_ab_group A] (a b c h₁ h₂ : A) (H₁ : a = h₁) (H₂ : b = h₂)
-- (H : h₁ + h₂ = c) : a + b = c :=
-- by rwr [H₁, H₂, H]
-- @[hott] theorem subst_into_subtr [s : add_group A] (l r t : A) (prt : l + -r = t) : l - r = t :=
-- by rwr [sub_eq_add_neg, prt]
-- @[hott] theorem neg_neg_helper [s : add_group A] (a b : A) (H : a = -b) : -a = b :=
-- by rwr [H, neg_neg]
-- @[hott] theorem neg_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * (-b) = c :=
-- begin rwr [neg_mul_neg, H] end
-- @[hott] theorem neg_mul_pos_helper [s : ring A] (a b c : A) (H : a * b = c) : (-a) * b = -c :=
-- begin rwr [←neg_mul_eq_neg_mul, H] end
-- @[hott] theorem pos_mul_neg_helper [s : ring A] (a b c : A) (H : a * b = c) : a * (-b) = -c :=
-- begin rwr [←neg_mul_comm, -neg_mul_eq_neg_mul, H] end
end norm_num
end algebra
end hott
|
92aa3e2b6f1ad9b6433c98ca34f5e2c580fe9de2 | 46125763b4dbf50619e8846a1371029346f4c3db | /src/ring_theory/ideal_operations.lean | eb478cb10d9f867c8bb34b5cd7b29c289a9ac78f | [
"Apache-2.0"
] | permissive | thjread/mathlib | a9d97612cedc2c3101060737233df15abcdb9eb1 | 7cffe2520a5518bba19227a107078d83fa725ddc | refs/heads/master | 1,615,637,696,376 | 1,583,953,063,000 | 1,583,953,063,000 | 246,680,271 | 0 | 0 | Apache-2.0 | 1,583,960,875,000 | 1,583,960,875,000 | null | UTF-8 | Lean | false | false | 26,863 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
More operations on modules and ideals.
-/
import ring_theory.ideals data.nat.choose order.zorn
import linear_algebra.tensor_product
import data.equiv.algebra
import ring_theory.algebra_operations
universes u v w x
open lattice
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
instance has_scalar' : has_scalar (ideal R) (submodule R M) :=
⟨λ I N, ⨆ r : I, N.map (r.1 • linear_map.id)⟩
def annihilator (N : submodule R M) : ideal R :=
(linear_map.lsmul R N).ker
def colon (N P : submodule R M) : ideal R :=
annihilator (P.map N.mkq)
variables {I J : ideal R} {N N₁ N₂ P P₁ P₂ : submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0:M) :=
⟨λ hr n hn, congr_arg subtype.val (linear_map.ext_iff.1 (linear_map.mem_ker.1 hr) ⟨n, hn⟩),
λ h, linear_map.mem_ker.2 $ linear_map.ext $ λ n, subtype.eq $ h n.1 n.2⟩
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • linear_map.id) ⊥ :=
mem_annihilator.trans ⟨λ H n hn, (mem_bot R).2 $ H n hn, λ H n hn, (mem_bot R).1 $ H hn⟩
theorem annihilator_bot : (⊥ : submodule R M).annihilator = ⊤ :=
(ideal.eq_top_iff_one _).2 $ mem_annihilator'.2 bot_le
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ :=
⟨λ H, eq_bot_iff.2 $ λ (n:M) hn, (mem_bot R).2 $ one_smul R n ▸ mem_annihilator.1 ((ideal.eq_top_iff_one _).1 H) n hn,
λ H, H.symm ▸ annihilator_bot⟩
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator :=
λ r hrp, mem_annihilator.2 $ λ n hn, mem_annihilator.1 hrp n $ h hn
theorem annihilator_supr (ι : Type w) (f : ι → submodule R M) :
(annihilator ⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_infi $ λ i, annihilator_mono $ le_supr _ _)
(λ r H, mem_annihilator'.2 $ supr_le $ λ i,
have _ := (mem_infi _).1 H i, mem_annihilator'.1 this)
theorem mem_colon {r} : r ∈ N.colon P ↔ ∀ p ∈ P, r • p ∈ N :=
mem_annihilator.trans ⟨λ H p hp, (quotient.mk_eq_zero N).1 (H (quotient.mk p) (mem_map_of_mem hp)),
λ H m ⟨p, hp, hpm⟩, hpm ▸ (N.mkq).map_smul r p ▸ (quotient.mk_eq_zero N).2 $ H p hp⟩
theorem mem_colon' {r} : r ∈ N.colon P ↔ P ≤ comap (r • linear_map.id) N :=
mem_colon
theorem colon_mono (hn : N₁ ≤ N₂) (hp : P₁ ≤ P₂) : N₁.colon P₂ ≤ N₂.colon P₁ :=
λ r hrnp, mem_colon.2 $ λ p₁ hp₁, hn $ mem_colon.1 hrnp p₁ $ hp hp₁
theorem infi_colon_supr (ι₁ : Type w) (f : ι₁ → submodule R M)
(ι₂ : Type x) (g : ι₂ → submodule R M) :
(⨅ i, f i).colon (⨆ j, g j) = ⨅ i j, (f i).colon (g j) :=
le_antisymm (le_infi $ λ i, le_infi $ λ j, colon_mono (infi_le _ _) (le_supr _ _))
(λ r H, mem_colon'.2 $ supr_le $ λ j, map_le_iff_le_comap.1 $ le_infi $ λ i,
map_le_iff_le_comap.2 $ mem_colon'.1 $ have _ := ((mem_infi _).1 H i),
have _ := ((mem_infi _).1 this j), this)
theorem smul_mem_smul {r} {n} (hr : r ∈ I) (hn : n ∈ N) : r • n ∈ I • N :=
(le_supr _ ⟨r, hr⟩ : _ ≤ I • N) ⟨n, hn, rfl⟩
theorem smul_le {P : submodule R M} : I • N ≤ P ↔ ∀ (r ∈ I) (n ∈ N), r • n ∈ P :=
⟨λ H r hr n hn, H $ smul_mem_smul hr hn,
λ H, supr_le $ λ r, map_le_iff_le_comap.2 $ λ n hn, H r.1 r.2 n hn⟩
@[elab_as_eliminator]
theorem smul_induction_on {p : M → Prop} {x} (H : x ∈ I • N)
(Hb : ∀ (r ∈ I) (n ∈ N), p (r • n)) (H0 : p 0)
(H1 : ∀ x y, p x → p y → p (x + y))
(H2 : ∀ (c:R) n, p n → p (c • n)) : p x :=
(@smul_le _ _ _ _ _ _ _ ⟨p, H0, H1, H2⟩).2 Hb H
theorem mem_smul_span_singleton {I : ideal R} {m : M} {x : M} :
x ∈ I • span R ({m} : set M) ↔ ∃ y ∈ I, y • m = x :=
⟨λ hx, smul_induction_on hx
(λ r hri n hnm, let ⟨s, hs⟩ := mem_span_singleton.1 hnm in ⟨r * s, I.mul_mem_right hri, hs ▸ mul_smul r s m⟩)
⟨0, I.zero_mem, by rw [zero_smul]⟩
(λ m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩, ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩)
(λ c r ⟨y, hyi, hy⟩, ⟨c * y, I.mul_mem_left hyi, by rw [mul_smul, hy]⟩),
λ ⟨y, hyi, hy⟩, hy ▸ smul_mem_smul hyi (subset_span $ set.mem_singleton m)⟩
theorem smul_le_right : I • N ≤ N :=
smul_le.2 $ λ r hr n, N.smul_mem r
theorem smul_mono (hij : I ≤ J) (hnp : N ≤ P) : I • N ≤ J • P :=
smul_le.2 $ λ r hr n hn, smul_mem_smul (hij hr) (hnp hn)
theorem smul_mono_left (h : I ≤ J) : I • N ≤ J • N :=
smul_mono h (le_refl N)
theorem smul_mono_right (h : N ≤ P) : I • N ≤ I • P :=
smul_mono (le_refl I) h
variables (I J N P)
@[simp] theorem smul_bot : I • (⊥ : submodule R M) = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hri s hsb,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hsb).symm ▸ smul_zero r
@[simp] theorem bot_smul : (⊥ : ideal R) • N = ⊥ :=
eq_bot_iff.2 $ smul_le.2 $ λ r hrb s hsi,
(submodule.mem_bot R).2 $ ((submodule.mem_bot R).1 hrb).symm ▸ zero_smul _ s
@[simp] theorem top_smul : (⊤ : ideal R) • N = N :=
le_antisymm smul_le_right $ λ r hri, one_smul R r ▸ smul_mem_smul mem_top hri
theorem smul_sup : I • (N ⊔ P) = I • N ⊔ I • P :=
le_antisymm (smul_le.2 $ λ r hri m hmnp, let ⟨n, hn, p, hp, hnpm⟩ := mem_sup.1 hmnp in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hri hp, hnpm ▸ (smul_add _ _ _).symm⟩)
(sup_le (smul_mono_right le_sup_left)
(smul_mono_right le_sup_right))
theorem sup_smul : (I ⊔ J) • N = I • N ⊔ J • N :=
le_antisymm (smul_le.2 $ λ r hrij n hn, let ⟨ri, hri, rj, hrj, hrijr⟩ := mem_sup.1 hrij in
mem_sup.2 ⟨_, smul_mem_smul hri hn, _, smul_mem_smul hrj hn, hrijr ▸ (add_smul _ _ _).symm⟩)
(sup_le (smul_mono_left le_sup_left)
(smul_mono_left le_sup_right))
theorem smul_assoc : (I • J) • N = I • (J • N) :=
le_antisymm (smul_le.2 $ λ rs hrsij t htn,
smul_induction_on hrsij
(λ r hr s hs, (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ smul_mem_smul hr (smul_mem_smul hs htn))
((zero_smul R t).symm ▸ submodule.zero_mem _)
(λ x y, (add_smul x y t).symm ▸ submodule.add_mem _)
(λ r s h, (@smul_eq_mul R _ r s).symm ▸ smul_smul r s t ▸ submodule.smul_mem _ _ h))
(smul_le.2 $ λ r hr sn hsn, suffices J • N ≤ submodule.comap (r • linear_map.id) ((I • J) • N), from this hsn,
smul_le.2 $ λ s hs n hn, show r • (s • n) ∈ (I • J) • N, from mul_smul r s n ▸ smul_mem_smul (smul_mem_smul hr hs) hn)
variables (S : set R) (T : set M)
theorem span_smul_span : (ideal.span S) • (span R T) =
span R (⋃ (s ∈ S) (t ∈ T), {s • t}) :=
le_antisymm (smul_le.2 $ λ r hrS n hnT, span_induction hrS
(λ r hrS, span_induction hnT
(λ n hnT, subset_span $ set.mem_bUnion hrS $
set.mem_bUnion hnT $ set.mem_singleton _)
((smul_zero r : r • 0 = (0:M)).symm ▸ submodule.zero_mem _)
(λ x y, (smul_add r x y).symm ▸ submodule.add_mem _)
(λ c m, by rw [smul_smul, mul_comm, mul_smul]; exact submodule.smul_mem _ _))
((zero_smul R n).symm ▸ submodule.zero_mem _)
(λ r s, (add_smul r s n).symm ▸ submodule.add_mem _)
(λ c r, by rw [smul_eq_mul, mul_smul]; exact submodule.smul_mem _ _)) $
span_le.2 $ set.bUnion_subset $ λ r hrS, set.bUnion_subset $ λ n hnT, set.singleton_subset_iff.2 $
smul_mem_smul (subset_span hrS) (subset_span hnT)
end submodule
namespace ideal
section chinese_remainder
variables {R : Type u} [comm_ring R] {ι : Type v}
theorem exists_sub_one_mem_and_mem (s : finset ι) {f : ι → ideal R}
(hf : ∀ i ∈ s, ∀ j ∈ s, i ≠ j → f i ⊔ f j = ⊤) (i : ι) (his : i ∈ s) :
∃ r : R, r - 1 ∈ f i ∧ ∀ j ∈ s, j ≠ i → r ∈ f j :=
begin
have : ∀ j ∈ s, j ≠ i → ∃ r : R, ∃ H : r - 1 ∈ f i, r ∈ f j,
{ intros j hjs hji, specialize hf i his j hjs hji.symm,
rw [eq_top_iff_one, submodule.mem_sup] at hf,
rcases hf with ⟨r, hri, s, hsj, hrs⟩, refine ⟨1 - r, _, _⟩,
{ rw [sub_right_comm, sub_self, zero_sub], exact (f i).neg_mem hri },
{ rw [← hrs, add_sub_cancel'], exact hsj } },
classical,
have : ∃ g : ι → R, (∀ j, g j - 1 ∈ f i) ∧ ∀ j ∈ s, j ≠ i → g j ∈ f j,
{ choose g hg1 hg2,
refine ⟨λ j, if H : j ∈ s ∧ j ≠ i then g j H.1 H.2 else 1, λ j, _, λ j, _⟩,
{ split_ifs with h, { apply hg1 }, rw sub_self, exact (f i).zero_mem },
{ intros hjs hji, rw dif_pos, { apply hg2 }, exact ⟨hjs, hji⟩ } },
rcases this with ⟨g, hgi, hgj⟩, use (s.erase i).prod g, split,
{ rw [← quotient.eq, quotient.mk_one, ← finset.prod_hom _ (quotient.mk (f i))],
apply finset.prod_eq_one, intros, rw [← quotient.mk_one, quotient.eq], apply hgi },
intros j hjs hji, rw [← quotient.eq_zero_iff_mem, ← finset.prod_hom _ (quotient.mk (f j))],
refine finset.prod_eq_zero (finset.mem_erase_of_ne_of_mem hji hjs) _,
rw quotient.eq_zero_iff_mem, exact hgj j hjs hji
end
theorem exists_sub_mem [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) (g : ι → R) :
∃ r : R, ∀ i, r - g i ∈ f i :=
begin
have : ∃ φ : ι → R, (∀ i, φ i - 1 ∈ f i) ∧ (∀ i j, i ≠ j → φ i ∈ f j),
{ have := exists_sub_one_mem_and_mem (finset.univ : finset ι) (λ i _ j _ hij, hf i j hij),
choose φ hφ,
existsi λ i, φ i (finset.mem_univ i),
exact ⟨λ i, (hφ i _).1, λ i j hij, (hφ i _).2 j (finset.mem_univ j) hij.symm⟩ },
rcases this with ⟨φ, hφ1, hφ2⟩,
use finset.univ.sum (λ i, g i * φ i),
intros i,
rw [← quotient.eq, ← finset.univ.sum_hom (quotient.mk (f i))],
refine eq.trans (finset.sum_eq_single i _ _) _,
{ intros j _ hji, rw quotient.eq_zero_iff_mem, exact (f i).mul_mem_left (hφ2 j i hji) },
{ intros hi, exact (hi $ finset.mem_univ i).elim },
specialize hφ1 i, rw [← quotient.eq, quotient.mk_one] at hφ1,
rw [quotient.mk_mul, hφ1, mul_one]
end
def quotient_inf_to_pi_quotient (f : ι → ideal R) :
(⨅ i, f i).quotient → Π i, (f i).quotient :=
@@quotient.lift _ _ (⨅ i, f i) (λ r i, ideal.quotient.mk (f i) r)
(@pi.is_ring_hom_pi ι (λ i, (f i).quotient) _ R _ _ _)
(λ r hr, funext $ λ i, quotient.eq_zero_iff_mem.2 $ (submodule.mem_infi _).1 hr i)
theorem is_ring_hom_quotient_inf_to_pi_quotient (f : ι → ideal R) :
is_ring_hom (quotient_inf_to_pi_quotient f) :=
@@quotient.is_ring_hom _ _ _
(@pi.is_ring_hom_pi ι (λ i, (f i).quotient) _ R _ _ _) _
theorem bijective_quotient_inf_to_pi_quotient [fintype ι] {f : ι → ideal R}
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
function.bijective (quotient_inf_to_pi_quotient f) :=
⟨λ x y, quotient.induction_on₂' x y $ λ r s hrs, quotient.eq.2 $
(submodule.mem_infi _).2 $ λ i, quotient.eq.1 $
show quotient_inf_to_pi_quotient f (quotient.mk' r) i = _, by rw hrs; refl,
λ g, let ⟨r, hr⟩ := exists_sub_mem hf (λ i, quotient.out' (g i)) in
⟨quotient.mk _ r, funext $ λ i, quotient.out_eq' (g i) ▸ quotient.eq.2 (hr i)⟩⟩
/-- Chinese Remainder Theorem. Eisenbud Ex.2.6. Similar to Atiyah-Macdonald 1.10 and Stacks 00DT -/
noncomputable def quotient_inf_ring_equiv_pi_quotient [fintype ι] (f : ι → ideal R)
(hf : ∀ i j, i ≠ j → f i ⊔ f j = ⊤) :
(⨅ i, f i).quotient ≃+* Π i, (f i).quotient :=
by haveI : is_ring_hom (equiv.of_bijective (bijective_quotient_inf_to_pi_quotient hf)) :=
is_ring_hom_quotient_inf_to_pi_quotient f;
exact ring_equiv.of (equiv.of_bijective (bijective_quotient_inf_to_pi_quotient hf))
end chinese_remainder
section mul_and_radical
variables {R : Type u} [comm_ring R]
variables {I J K L: ideal R}
instance : has_mul (ideal R) := ⟨(•)⟩
theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J :=
submodule.smul_mem_smul hr hs
theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J :=
mul_comm r s ▸ mul_mem_mul hr hs
theorem mul_le : I * J ≤ K ↔ ∀ (r ∈ I) (s ∈ J), r * s ∈ K :=
submodule.smul_le
variables (I J K)
protected theorem mul_comm : I * J = J * I :=
le_antisymm (mul_le.2 $ λ r hrI s hsJ, mul_mem_mul_rev hsJ hrI)
(mul_le.2 $ λ r hrJ s hsI, mul_mem_mul_rev hsI hrJ)
protected theorem mul_assoc : (I * J) * K = I * (J * K) :=
submodule.smul_assoc I J K
theorem span_mul_span (S T : set R) : span S * span T =
span ⋃ (s ∈ S) (t ∈ T), {s * t} :=
submodule.span_smul_span S T
variables {I J K}
theorem mul_le_inf : I * J ≤ I ⊓ J :=
mul_le.2 $ λ r hri s hsj, ⟨I.mul_mem_right hri, J.mul_mem_left hsj⟩
theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J :=
le_antisymm mul_le_inf $ λ r ⟨hri, hrj⟩,
let ⟨s, hsi, t, htj, hst⟩ := submodule.mem_sup.1 ((eq_top_iff_one _).1 h) in
mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj)
variables (I)
theorem mul_bot : I * ⊥ = ⊥ :=
submodule.smul_bot I
theorem bot_mul : ⊥ * I = ⊥ :=
submodule.bot_smul I
theorem mul_top : I * ⊤ = I :=
ideal.mul_comm ⊤ I ▸ submodule.top_smul I
theorem top_mul : ⊤ * I = I :=
submodule.top_smul I
variables {I}
theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L :=
submodule.smul_mono hik hjl
theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K :=
submodule.smul_mono_left h
theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K :=
submodule.smul_mono_right h
variables (I J K)
theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K :=
submodule.smul_sup I J K
theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K :=
submodule.sup_smul I J K
variables {I J K}
lemma pow_le_pow {m n : ℕ} (h : m ≤ n) :
I^n ≤ I^m :=
begin
cases nat.exists_eq_add_of_le h with k hk,
rw [hk, pow_add],
exact le_trans (mul_le_inf) (lattice.inf_le_left)
end
/-- The radical of an ideal `I` consists of the elements `r` such that `r^n ∈ I` for some `n`. -/
def radical (I : ideal R) : ideal R :=
{ carrier := { r | ∃ n : ℕ, r ^ n ∈ I },
zero := ⟨1, (pow_one (0:R)).symm ▸ I.zero_mem⟩,
add := λ x y ⟨m, hxmi⟩ ⟨n, hyni⟩, ⟨m + n,
(add_pow x y (m + n)).symm ▸ I.sum_mem $
show ∀ c ∈ finset.range (nat.succ (m + n)), x ^ c * y ^ (m + n - c) * (nat.choose (m + n) c) ∈ I,
from λ c hc, or.cases_on (le_total c m)
(λ hcm, I.mul_mem_right $ I.mul_mem_left $ nat.add_comm n m ▸ (nat.add_sub_assoc hcm n).symm ▸
(pow_add y n (m-c)).symm ▸ I.mul_mem_right hyni)
(λ hmc, I.mul_mem_right $ I.mul_mem_right $ nat.add_sub_cancel' hmc ▸
(pow_add x m (c-m)).symm ▸ I.mul_mem_right hxmi)⟩,
smul := λ r s ⟨n, hsni⟩, ⟨n, show (r * s)^n ∈ I,
from (mul_pow r s n).symm ▸ I.mul_mem_left hsni⟩ }
theorem le_radical : I ≤ radical I :=
λ r hri, ⟨1, (pow_one r).symm ▸ hri⟩
variables (R)
theorem radical_top : (radical ⊤ : ideal R) = ⊤ :=
(eq_top_iff_one _).2 ⟨0, submodule.mem_top⟩
variables {R}
theorem radical_mono (H : I ≤ J) : radical I ≤ radical J :=
λ r ⟨n, hrni⟩, ⟨n, H hrni⟩
variables (I)
theorem radical_idem : radical (radical I) = radical I :=
le_antisymm (λ r ⟨n, k, hrnki⟩, ⟨n * k, (pow_mul r n k).symm ▸ hrnki⟩) le_radical
variables {I}
theorem radical_eq_top : radical I = ⊤ ↔ I = ⊤ :=
⟨λ h, (eq_top_iff_one _).2 $ let ⟨n, hn⟩ := (eq_top_iff_one _).1 h in
@one_pow R _ n ▸ hn, λ h, h.symm ▸ radical_top R⟩
theorem is_prime.radical (H : is_prime I) : radical I = I :=
le_antisymm (λ r ⟨n, hrni⟩, H.mem_of_pow_mem n hrni) le_radical
variables (I J)
theorem radical_sup : radical (I ⊔ J) = radical (radical I ⊔ radical J) :=
le_antisymm (radical_mono $ sup_le_sup le_radical le_radical) $
λ r ⟨n, hrnij⟩, let ⟨s, hs, t, ht, hst⟩ := submodule.mem_sup.1 hrnij in
@radical_idem _ _ (I ⊔ J) ▸ ⟨n, hst ▸ ideal.add_mem _
(radical_mono le_sup_left hs) (radical_mono le_sup_right ht)⟩
theorem radical_inf : radical (I ⊓ J) = radical I ⊓ radical J :=
le_antisymm (le_inf (radical_mono inf_le_left) (radical_mono inf_le_right))
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ I.mul_mem_right hrm,
(pow_add r m n).symm ▸ J.mul_mem_left hrn⟩)
theorem radical_mul : radical (I * J) = radical I ⊓ radical J :=
le_antisymm (radical_inf I J ▸ radical_mono $ @mul_le_inf _ _ I J)
(λ r ⟨⟨m, hrm⟩, ⟨n, hrn⟩⟩, ⟨m + n, (pow_add r m n).symm ▸ mul_mem_mul hrm hrn⟩)
variables {I J}
theorem is_prime.radical_le_iff (hj : is_prime J) :
radical I ≤ J ↔ I ≤ J :=
⟨le_trans le_radical, λ hij r ⟨n, hrni⟩, hj.mem_of_pow_mem n $ hij hrni⟩
theorem radical_eq_Inf (I : ideal R) :
radical I = Inf { J : ideal R | I ≤ J ∧ is_prime J } :=
le_antisymm (le_Inf $ λ J hJ, hJ.2.radical_le_iff.2 hJ.1) $
λ r hr, classical.by_contradiction $ λ hri,
let ⟨m, (hrm : r ∉ radical m), him, hm⟩ := zorn.zorn_partial_order₀ {K : ideal R | r ∉ radical K}
(λ c hc hcc y hyc, ⟨Sup c, λ ⟨n, hrnc⟩, let ⟨y, hyc, hrny⟩ :=
submodule.mem_Sup_of_directed hrnc y hyc hcc.directed_on in hc hyc ⟨n, hrny⟩,
λ z, le_Sup⟩) I hri in
have ∀ x ∉ m, r ∈ radical (m ⊔ span {x}) := λ x hxm, classical.by_contradiction $ λ hrmx, hxm $
hm (m ⊔ span {x}) hrmx le_sup_left ▸ (le_sup_right : _ ≤ m ⊔ span {x}) (subset_span $ set.mem_singleton _),
have is_prime m, from ⟨by rintro rfl; rw radical_top at hrm; exact hrm trivial,
λ x y hxym, classical.or_iff_not_imp_left.2 $ λ hxm, classical.by_contradiction $ λ hym,
let ⟨n, hrn⟩ := this _ hxm, ⟨p, hpm, q, hq, hpqrn⟩ := submodule.mem_sup.1 hrn, ⟨c, hcxq⟩ := mem_span_singleton'.1 hq in
let ⟨k, hrk⟩ := this _ hym, ⟨f, hfm, g, hg, hfgrk⟩ := submodule.mem_sup.1 hrk, ⟨d, hdyg⟩ := mem_span_singleton'.1 hg in
hrm ⟨n + k, by rw [pow_add, ← hpqrn, ← hcxq, ← hfgrk, ← hdyg, add_mul, mul_add (c*x), mul_assoc c x (d*y), mul_left_comm x, ← mul_assoc];
refine m.add_mem (m.mul_mem_right hpm) (m.add_mem (m.mul_mem_left hfm) (m.mul_mem_left hxym))⟩⟩,
hrm $ this.radical.symm ▸ (Inf_le ⟨him, this⟩ : Inf {J : ideal R | I ≤ J ∧ is_prime J} ≤ m) hr
instance : comm_semiring (ideal R) := submodule.comm_semiring
@[simp] lemma add_eq_sup : I + J = I ⊔ J := rfl
@[simp] lemma zero_eq_bot : (0 : ideal R) = ⊥ := rfl
@[simp] lemma one_eq_top : (1 : ideal R) = ⊤ :=
by erw [submodule.one_eq_map_top, submodule.map_id]
variables (I)
theorem radical_pow (n : ℕ) (H : n > 0) : radical (I^n) = radical I :=
nat.rec_on n (not.elim dec_trivial) (λ n ih H,
or.cases_on (lt_or_eq_of_le $ nat.le_of_lt_succ H)
(λ H, calc radical (I^(n+1))
= radical I ⊓ radical (I^n) : radical_mul _ _
... = radical I ⊓ radical I : by rw ih H
... = radical I : inf_idem)
(λ H, H ▸ (pow_one I).symm ▸ rfl)) H
end mul_and_radical
section map_and_comap
variables {R : Type u} {S : Type v} [comm_ring R] [comm_ring S]
variables (f : R → S) [is_ring_hom f]
variables {I J : ideal R} {K L : ideal S}
def map (I : ideal R) : ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap (I : ideal S) : ideal R :=
{ carrier := f ⁻¹' I,
zero := show f 0 ∈ I, by rw is_ring_hom.map_zero f; exact I.zero_mem,
add := λ x y hx hy, show f (x + y) ∈ I, by rw is_ring_hom.map_add f; exact I.add_mem hx hy,
smul := λ c x hx, show f (c * x) ∈ I, by rw is_ring_hom.map_mul f; exact I.mul_mem_left hx }
variables {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono $ set.image_subset _ h
theorem mem_map_of_mem {x} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem map_le_iff_le_comap :
map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans set.image_subset_iff
@[simp] theorem mem_comap {x} : x ∈ comap f K ↔ f x ∈ K := iff.rfl
theorem comap_mono (h : K ≤ L) : comap f K ≤ comap f L :=
set.preimage_mono h
variables (f)
theorem comap_ne_top (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 $ by rw [mem_comap, is_ring_hom.map_one f];
exact (ne_top_iff_one _).1 hK
instance is_prime.comap [hK : K.is_prime] : (comap f K).is_prime :=
⟨comap_ne_top _ hK.1, λ x y,
by simp only [mem_comap, is_ring_hom.map_mul f]; apply hK.2⟩
variables (I J K L)
theorem map_bot : map f ⊥ = ⊥ :=
le_antisymm (map_le_iff_le_comap.2 bot_le) bot_le
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 $ subset_span ⟨1, trivial, is_ring_hom.map_one f⟩
theorem comap_top : comap f ⊤ = ⊤ :=
(eq_top_iff_one _).2 trivial
theorem map_sup : map f (I ⊔ J) = map f I ⊔ map f J :=
le_antisymm (map_le_iff_le_comap.2 $ sup_le
(map_le_iff_le_comap.1 le_sup_left)
(map_le_iff_le_comap.1 le_sup_right))
(sup_le (map_mono le_sup_left) (map_mono le_sup_right))
theorem map_mul : map f (I * J) = map f I * map f J :=
le_antisymm (map_le_iff_le_comap.2 $ mul_le.2 $ λ r hri s hsj,
show f (r * s) ∈ _, by rw is_ring_hom.map_mul f;
exact mul_mem_mul (mem_map_of_mem hri) (mem_map_of_mem hsj))
(trans_rel_right _ (span_mul_span _ _) $ span_le.2 $
set.bUnion_subset $ λ i ⟨r, hri, hfri⟩,
set.bUnion_subset $ λ j ⟨s, hsj, hfsj⟩,
set.singleton_subset_iff.2 $ hfri ▸ hfsj ▸
by rw [← is_ring_hom.map_mul f];
exact mem_map_of_mem (mul_mem_mul hri hsj))
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L := rfl
theorem comap_radical : comap f (radical K) = radical (comap f K) :=
le_antisymm (λ r ⟨n, hfrnk⟩, ⟨n, show f (r ^ n) ∈ K,
from (is_semiring_hom.map_pow f r n).symm ▸ hfrnk⟩)
(λ r ⟨n, hfrnk⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ hfrnk⟩)
@[simp] lemma map_quotient_self :
map (quotient.mk I) I = ⊥ :=
lattice.eq_bot_iff.2 $ ideal.map_le_iff_le_comap.2 $ λ x hx,
(submodule.mem_bot I.quotient).2 $ ideal.quotient.eq_zero_iff_mem.2 hx
variables {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
map_le_iff_le_comap.2 $ (comap_inf f (map f I) (map f J)).symm ▸
inf_le_inf (map_le_iff_le_comap.1 $ le_refl _) (map_le_iff_le_comap.1 $ le_refl _)
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 $ λ r ⟨n, hrni⟩, ⟨n, is_semiring_hom.map_pow f r n ▸ mem_map_of_mem hrni⟩
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
map_le_iff_le_comap.1 $ (map_sup f (comap f K) (comap f L)).symm ▸
sup_le_sup (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 $ (map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 $ le_refl _) (map_le_iff_le_comap.2 $ le_refl _)
section surjective
variables (hf : function.surjective f)
include hf
theorem map_comap_of_surjective (I : ideal S) :
map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 (le_refl _))
(λ s hsi, let ⟨r, hfrs⟩ := hf s in
hfrs ▸ (mem_map_of_mem $ show f r ∈ I, from hfrs.symm ▸ hsi))
theorem mem_image_of_mem_map_of_surjective {I : ideal R} {y}
(H : y ∈ map f I) : y ∈ f '' I :=
submodule.span_induction H (λ _, id) ⟨0, I.zero_mem, is_ring_hom.map_zero f⟩
(λ y1 y2 ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩, ⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ is_ring_hom.map_add f⟩)
(λ c y ⟨x, hxi, hxy⟩, let ⟨d, hdc⟩ := hf c in ⟨d • x, I.smul_mem _ hxi, hdc ▸ hxy ▸ is_ring_hom.map_mul f⟩)
theorem comap_map_of_surjective (I : ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm (assume r h, let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h in
submodule.mem_sup.2 ⟨s, hsi, r - s, (submodule.mem_bot S).2 $ by rw [is_ring_hom.map_sub f, hfsr, sub_self],
add_sub_cancel'_right s r⟩)
(sup_le (map_le_iff_le_comap.1 (le_refl _)) (comap_mono bot_le))
/-- Correspondence theorem -/
def order_iso_of_surjective :
((≤) : ideal S → ideal S → Prop) ≃o
((≤) : { p : ideal R // comap f ⊥ ≤ p } → { p : ideal R // comap f ⊥ ≤ p } → Prop) :=
{ to_fun := λ J, ⟨comap f J, comap_mono bot_le⟩,
inv_fun := λ I, map f I.1,
left_inv := λ J, map_comap_of_surjective f hf J,
right_inv := λ I, subtype.eq $ show comap f (map f I.1) = I.1,
from (comap_map_of_surjective f hf I).symm ▸ le_antisymm
(sup_le (le_refl _) I.2) le_sup_left,
ord := λ I1 I2, ⟨comap_mono, λ H, map_comap_of_surjective f hf I1 ▸
map_comap_of_surjective f hf I2 ▸ map_mono H⟩ }
def le_order_embedding_of_surjective :
((≤) : ideal S → ideal S → Prop) ≼o ((≤) : ideal R → ideal R → Prop) :=
(order_iso_of_surjective f hf).to_order_embedding.trans (subtype.order_embedding _ _)
def lt_order_embedding_of_surjective :
((<) : ideal S → ideal S → Prop) ≼o ((<) : ideal R → ideal R → Prop) :=
(le_order_embedding_of_surjective f hf).lt_embedding_of_le_embedding
end surjective
end map_and_comap
end ideal
namespace is_ring_hom
variables {R : Type u} {S : Type v} (f : R → S) [comm_ring R]
section comm_ring
variables [comm_ring S] [is_ring_hom f]
def ker : ideal R := ideal.comap f ⊥
/-- An element is in the kernel if and only if it maps to zero.-/
lemma mem_ker {r} : r ∈ ker f ↔ f r = 0 :=
by rw [ker, ideal.mem_comap, submodule.mem_bot]
lemma ker_eq : ((ker f) : set R) = is_add_group_hom.ker f := rfl
lemma inj_iff_ker_eq_bot : function.injective f ↔ ker f = ⊥ :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.inj_iff_trivial_ker f
lemma ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 :=
by rw [←submodule.ext'_iff, ker_eq]; exact is_add_group_hom.trivial_ker_iff_eq_zero f
lemma injective_iff : function.injective f ↔ ∀ x, f x = 0 → x = 0 :=
is_add_group_hom.injective_iff f
end comm_ring
/-- If the target is not the zero ring, then one is not in the kernel.-/
lemma not_one_mem_ker [nonzero_comm_ring S] [is_ring_hom f] : (1:R) ∉ ker f :=
by { rw [mem_ker, is_ring_hom.map_one f], exact one_ne_zero }
/-- The kernel of a homomorphism to an integral domain is a prime ideal.-/
lemma ker_is_prime [integral_domain S] [is_ring_hom f] :
(ker f).is_prime :=
⟨by { rw [ne.def, ideal.eq_top_iff_one], exact not_one_mem_ker f },
λ x y, by simpa only [mem_ker, is_ring_hom.map_mul f] using eq_zero_or_eq_zero_of_mul_eq_zero⟩
end is_ring_hom
namespace submodule
variables {R : Type u} {M : Type v}
variables [comm_ring R] [add_comm_group M] [module R M]
-- It is even a semialgebra. But those aren't in mathlib yet.
instance : semimodule (ideal R) (submodule R M) :=
{ smul_add := smul_sup,
add_smul := sup_smul,
mul_smul := smul_assoc,
one_smul := by simp,
zero_smul := bot_smul,
smul_zero := smul_bot }
end submodule
|
cd2dab5681d5288420ceb31ebc82a23be03843fd | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/category/Top/open_nhds.lean | c75a34011a24a74108c5c46b87885b6f9086d1a3 | [] | 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 | 4,638 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.category.Top.opens
import Mathlib.category_theory.filtered
import Mathlib.PostPort
universes u
namespace Mathlib
namespace topological_space
def open_nhds {X : Top} (x : ↥X) :=
Subtype fun (U : opens ↥X) => x ∈ U
namespace open_nhds
protected instance partial_order {X : Top} (x : ↥X) : partial_order (open_nhds x) :=
partial_order.mk (fun (U V : open_nhds x) => subtype.val U ≤ subtype.val V)
(preorder.lt._default fun (U V : open_nhds x) => subtype.val U ≤ subtype.val V) sorry sorry sorry
protected instance lattice {X : Top} (x : ↥X) : lattice (open_nhds x) :=
lattice.mk (fun (U V : open_nhds x) => { val := subtype.val U ⊔ subtype.val V, property := sorry }) partial_order.le
partial_order.lt sorry sorry sorry sorry sorry sorry
(fun (U V : open_nhds x) => { val := subtype.val U ⊓ subtype.val V, property := sorry }) sorry sorry sorry
protected instance order_top {X : Top} (x : ↥X) : order_top (open_nhds x) :=
order_top.mk { val := ⊤, property := trivial } partial_order.le partial_order.lt sorry sorry sorry sorry
protected instance open_nhds_category {X : Top} (x : ↥X) : category_theory.category (open_nhds x) :=
eq.mpr sorry (category_theory.full_subcategory fun (U : opens ↥X) => x ∈ U)
protected instance opens_nhds_hom_has_coe_to_fun {X : Top} {x : ↥X} {U : open_nhds x} {V : open_nhds x} : has_coe_to_fun (U ⟶ V) :=
has_coe_to_fun.mk (fun (f : U ⟶ V) => ↥(subtype.val U) → ↥(subtype.val V))
fun (f : U ⟶ V) (x_1 : ↥(subtype.val U)) => { val := ↑x_1, property := sorry }
/--
The inclusion `U ⊓ V ⟶ U` as a morphism in the category of open sets.
-/
def inf_le_left {X : Top} {x : ↥X} (U : open_nhds x) (V : open_nhds x) : U ⊓ V ⟶ U :=
category_theory.hom_of_le sorry
/--
The inclusion `U ⊓ V ⟶ V` as a morphism in the category of open sets.
-/
def inf_le_right {X : Top} {x : ↥X} (U : open_nhds x) (V : open_nhds x) : U ⊓ V ⟶ V :=
category_theory.hom_of_le sorry
def inclusion {X : Top} (x : ↥X) : open_nhds x ⥤ opens ↥X :=
category_theory.full_subcategory_inclusion fun (U : opens ↥X) => x ∈ U
@[simp] theorem inclusion_obj {X : Top} (x : ↥X) (U : opens ↥X) (p : x ∈ U) : category_theory.functor.obj (inclusion x) { val := U, property := p } = U :=
rfl
protected instance open_nhds_is_filtered {X : Top} (x : ↥X) : category_theory.is_filtered (open_nhds xᵒᵖ) :=
category_theory.is_filtered.mk
def map {X : Top} {Y : Top} (f : X ⟶ Y) (x : ↥X) : open_nhds (coe_fn f x) ⥤ open_nhds x :=
category_theory.functor.mk
(fun (U : open_nhds (coe_fn f x)) =>
{ val := category_theory.functor.obj (opens.map f) (subtype.val U), property := sorry })
fun (U V : open_nhds (coe_fn f x)) (i : U ⟶ V) => category_theory.functor.map (opens.map f) i
@[simp] theorem map_obj {X : Top} {Y : Top} (f : X ⟶ Y) (x : ↥X) (U : opens ↥Y) (q : coe_fn f x ∈ U) : category_theory.functor.obj (map f x) { val := U, property := q } =
{ val := category_theory.functor.obj (opens.map f) U, property := q } :=
rfl
@[simp] theorem map_id_obj {X : Top} (x : ↥X) (U : open_nhds (coe_fn 𝟙 x)) : category_theory.functor.obj (map 𝟙 x) U = U := sorry
@[simp] theorem map_id_obj' {X : Top} (x : ↥X) (U : set ↥X) (p : is_open U) (q : coe_fn 𝟙 x ∈ { val := U, property := p }) : category_theory.functor.obj (map 𝟙 x) { val := { val := U, property := p }, property := q } =
{ val := { val := U, property := p }, property := q } :=
rfl
@[simp] theorem map_id_obj_unop {X : Top} (x : ↥X) (U : open_nhds xᵒᵖ) : category_theory.functor.obj (map 𝟙 x) (opposite.unop U) = opposite.unop U := sorry
@[simp] theorem op_map_id_obj {X : Top} (x : ↥X) (U : open_nhds xᵒᵖ) : category_theory.functor.obj (category_theory.functor.op (map 𝟙 x)) U = U := sorry
def inclusion_map_iso {X : Top} {Y : Top} (f : X ⟶ Y) (x : ↥X) : inclusion (coe_fn f x) ⋙ opens.map f ≅ map f x ⋙ inclusion x :=
category_theory.nat_iso.of_components (fun (U : open_nhds (coe_fn f x)) => category_theory.iso.mk 𝟙 𝟙) sorry
@[simp] theorem inclusion_map_iso_hom {X : Top} {Y : Top} (f : X ⟶ Y) (x : ↥X) : category_theory.iso.hom (inclusion_map_iso f x) = 𝟙 :=
rfl
@[simp] theorem inclusion_map_iso_inv {X : Top} {Y : Top} (f : X ⟶ Y) (x : ↥X) : category_theory.iso.inv (inclusion_map_iso f x) = 𝟙 :=
rfl
|
6407ac97bb62a007db760079e1d01e5f84b6bb48 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/algebra/category/groupoid.hlean | 837869c75c8476c48b0835e4c5f232106a1cafc9 | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 2,841 | hlean | /-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Floris van Doorn
Ported from Coq HoTT
-/
import .iso algebra.bundled
open eq is_trunc iso category algebra nat unit
namespace category
structure groupoid [class] (ob : Type) extends parent : precategory ob :=
mk' :: (all_iso : Π ⦃a b : ob⦄ (f : hom a b), @is_iso ob parent a b f)
abbreviation all_iso := @groupoid.all_iso
attribute groupoid.all_iso [instance] [priority 3000]
attribute groupoid.to_precategory [unfold 2]
definition groupoid.mk [reducible] [constructor] {ob : Type} (C : precategory ob)
(H : Π (a b : ob) (f : a ⟶ b), is_iso f) : groupoid ob :=
precategory.rec_on C groupoid.mk' H
definition groupoid_of_group.{l} [constructor] (A : Type.{l}) [G : group A] :
groupoid.{0 l} unit :=
begin
fapply groupoid.mk; fapply precategory.mk: intros,
{ exact A},
{ exact _},
{ exact a_2 * a_1},
{ exact 1},
{ apply mul.assoc},
{ apply mul_one},
{ apply one_mul},
{ esimp [precategory.mk],
fapply is_iso.mk,
{ exact f⁻¹},
{ apply mul.right_inv},
{ apply mul.left_inv}},
end
definition hom_group [constructor] {A : Type} [G : groupoid A] (a : A) : group (hom a a) :=
begin
fapply group.mk,
apply is_set_hom,
intro f g, apply (comp f g),
intros f g h, apply (assoc f g h)⁻¹,
apply (ID a),
intro f, apply id_left,
intro f, apply id_right,
intro f, exact (iso.inverse f),
intro f, exact (iso.left_inverse f),
end
definition group_of_is_contr_groupoid {ob : Type} [H : is_contr ob]
[G : groupoid ob] : group (hom (center ob) (center ob)) := !hom_group
definition group_of_groupoid_unit [G : groupoid unit] : group (hom ⋆ ⋆) := !hom_group
-- Bundled version of categories
-- we don't use Groupoid.carrier explicitly, but rather use Groupoid.carrier (to_Precategory C)
structure Groupoid : Type :=
(carrier : Type)
(struct : groupoid carrier)
attribute Groupoid.struct [instance] [coercion]
definition Groupoid.to_Precategory [coercion] [reducible] [unfold 1] (C : Groupoid)
: Precategory :=
Precategory.mk (Groupoid.carrier C) _
attribute Groupoid._trans_of_to_Precategory_1 [unfold 1]
definition groupoid.Mk [reducible] [constructor] := Groupoid.mk
definition groupoid.MK [reducible] [constructor] (C : Precategory)
(H : Π (a b : C) (f : a ⟶ b), is_iso f) : Groupoid :=
Groupoid.mk C (groupoid.mk C H)
definition Groupoid.eta [unfold 1] (C : Groupoid) : Groupoid.mk C C = C :=
Groupoid.rec (λob c, idp) C
definition Groupoid_of_Group [constructor] (G : Group) : Groupoid :=
Groupoid.mk unit (groupoid_of_group G)
end category
|
ff4b6562d323e8693b6b4c937857f73e3d5d8249 | 1a61aba1b67cddccce19532a9596efe44be4285f | /library/algebra/group_power.lean | e8c5f196989bfba5ea69bd2019779f273950567a | [
"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 | 8,041 | lean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
The power operation on monoids and groups. We separate this from group, because it depends on
nat, which in turn depends on other parts of algebra.
We have "pow a n" for natural number powers, and "gpow a i" for integer powers. The notation
a^n is used for the first, but users can locally redefine it to gpow when needed.
Note: power adopts the convention that 0^0=1.
-/
import data.nat.basic data.int.basic
namespace algebra
variables {A : Type}
/- monoid -/
section monoid
open nat
variable [s : monoid A]
include s
definition pow (a : A) : ℕ → A
| 0 := 1
| (n+1) := a * pow n
infix [priority algebra.prio] `^` := pow
theorem pow_zero (a : A) : a^0 = 1 := rfl
theorem pow_succ (a : A) (n : ℕ) : a^(succ n) = a * a^n := rfl
theorem pow_one (a : A) : a^1 = a := !mul_one
theorem pow_two (a : A) : a^2 = a * a :=
calc
a^2 = a * (a * 1) : rfl
... = a * a : mul_one
theorem pow_three (a : A) : a^3 = a * (a * a) :=
calc
a^3 = a * (a * (a * 1)) : rfl
... = a * (a * a) : mul_one
theorem pow_four (a : A) : a^4 = a * (a * (a * a)) :=
calc
a^4 = a * a^3 : rfl
... = a * (a * (a * a)) : pow_three
theorem pow_succ' (a : A) : ∀n, a^(succ n) = a^n * a
| 0 := by rewrite [pow_succ, *pow_zero, one_mul, mul_one]
| (succ n) := by rewrite [pow_succ, pow_succ' at {1}, pow_succ, mul.assoc]
theorem one_pow : ∀ n : ℕ, 1^n = (1:A)
| 0 := rfl
| (succ n) := by rewrite [pow_succ, one_mul, one_pow]
theorem pow_add (a : A) (m n : ℕ) : a^(m + n) = a^m * a^n :=
begin
induction n with n ih,
{rewrite [nat.add_zero, pow_zero, mul_one]},
rewrite [add_succ, *pow_succ', ih, mul.assoc]
end
theorem pow_mul (a : A) (m : ℕ) : ∀ n, a^(m * n) = (a^m)^n
| 0 := by rewrite [nat.mul_zero, pow_zero]
| (succ n) := by rewrite [nat.mul_succ, pow_add, pow_succ', pow_mul]
theorem pow_comm (a : A) (m n : ℕ) : a^m * a^n = a^n * a^m :=
by rewrite [-*pow_add, nat.add.comm]
end monoid
/- commutative monoid -/
section comm_monoid
open nat
variable [s : comm_monoid A]
include s
theorem mul_pow (a b : A) : ∀ n, (a * b)^n = a^n * b^n
| 0 := by rewrite [*pow_zero, mul_one]
| (succ n) := by rewrite [*pow_succ', mul_pow, *mul.assoc, mul.left_comm a]
end comm_monoid
section group
variable [s : group A]
include s
section nat
open nat
theorem inv_pow (a : A) : ∀n, (a⁻¹)^n = (a^n)⁻¹
| 0 := by rewrite [*pow_zero, one_inv]
| (succ n) := by rewrite [pow_succ, pow_succ', inv_pow, mul_inv]
theorem pow_sub (a : A) {m n : ℕ} (H : m ≥ n) : a^(m - n) = a^m * (a^n)⁻¹ :=
assert H1 : m - n + n = m, from nat.sub_add_cancel H,
have H2 : a^(m - n) * a^n = a^m, by rewrite [-pow_add, H1],
eq_mul_inv_of_mul_eq H2
theorem pow_inv_comm (a : A) : ∀m n, (a⁻¹)^m * a^n = a^n * (a⁻¹)^m
| 0 n := by rewrite [*pow_zero, one_mul, mul_one]
| m 0 := by rewrite [*pow_zero, one_mul, mul_one]
| (succ m) (succ n) := by rewrite [pow_succ' at {1}, pow_succ at {1}, pow_succ', pow_succ,
*mul.assoc, inv_mul_cancel_left, mul_inv_cancel_left, pow_inv_comm]
end nat
open int
definition gpow (a : A) : ℤ → A
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
private lemma gpow_add_aux (a : A) (m n : nat) :
gpow a ((of_nat m) + -[1+n]) = gpow a (of_nat m) * gpow a (-[1+n]) :=
or.elim (nat.lt_or_ge m (nat.succ n))
(assume H : (#nat m < nat.succ n),
assert H1 : (#nat nat.succ n - m > nat.zero), from nat.sub_pos_of_lt H,
calc
gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n)) : rfl
... = gpow a (-[1+ nat.pred (nat.sub (nat.succ n) m)]) : {sub_nat_nat_of_lt H}
... = (pow a (nat.succ (nat.pred (nat.sub (nat.succ n) m))))⁻¹ : rfl
... = (pow a (nat.succ n) * (pow a m)⁻¹)⁻¹ :
by rewrite [nat.succ_pred_of_pos H1, pow_sub a (nat.le_of_lt H)]
... = pow a m * (pow a (nat.succ n))⁻¹ :
by rewrite [mul_inv, inv_inv]
... = gpow a (of_nat m) * gpow a (-[1+n]) : rfl)
(assume H : (#nat m ≥ nat.succ n),
calc
gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n)) : rfl
... = gpow a (#nat m - nat.succ n) : {sub_nat_nat_of_ge H}
... = pow a m * (pow a (nat.succ n))⁻¹ : pow_sub a H
... = gpow a (of_nat m) * gpow a (-[1+n]) : rfl)
theorem gpow_add (a : A) : ∀i j : int, gpow a (i + j) = gpow a i * gpow a j
| (of_nat m) (of_nat n) := !pow_add
| (of_nat m) -[1+n] := !gpow_add_aux
| -[1+m] (of_nat n) := by rewrite [int.add.comm, gpow_add_aux, ↑gpow, -*inv_pow, pow_inv_comm]
| -[1+m] -[1+n] :=
calc
gpow a (-[1+m] + -[1+n]) = (a^(#nat nat.succ m + nat.succ n))⁻¹ : rfl
... = (a^(nat.succ m))⁻¹ * (a^(nat.succ n))⁻¹ : by rewrite [pow_add, pow_comm, mul_inv]
... = gpow a (-[1+m]) * gpow a (-[1+n]) : rfl
theorem gpow_comm (a : A) (i j : ℤ) : gpow a i * gpow a j = gpow a j * gpow a i :=
by rewrite [-*gpow_add, int.add.comm]
end group
section ordered_ring
open nat
variable [s : linear_ordered_ring A]
include s
theorem pow_pos {a : A} (H : a > 0) (n : ℕ) : pow a n > 0 :=
begin
induction n,
rewrite pow_zero,
apply zero_lt_one,
rewrite pow_succ',
apply mul_pos,
apply v_0, apply H
end
theorem pow_ge_one_of_ge_one {a : A} (H : a ≥ 1) (n : ℕ) : pow a n ≥ 1 :=
begin
induction n,
rewrite pow_zero,
apply le.refl,
rewrite [pow_succ', -{1}mul_one],
apply mul_le_mul v_0 H zero_le_one,
apply le_of_lt,
apply pow_pos,
apply gt_of_ge_of_gt H zero_lt_one
end
local notation 2 := (1 : A) + 1
theorem pow_two_add (n : ℕ) : pow 2 n + pow 2 n = pow 2 (succ n) :=
by rewrite [pow_succ', left_distrib, *mul_one]
end ordered_ring
/- additive monoid -/
section add_monoid
variable [s : add_monoid A]
include s
local attribute add_monoid.to_monoid [trans-instance]
open nat
definition nmul : ℕ → A → A := λ n a, pow a n
infix [priority algebra.prio] `⬝` := nmul
theorem zero_nmul (a : A) : (0:ℕ) ⬝ a = 0 := pow_zero a
theorem succ_nmul (n : ℕ) (a : A) : nmul (succ n) a = a + (nmul n a) := pow_succ a n
theorem succ_nmul' (n : ℕ) (a : A) : succ n ⬝ a = nmul n a + a := pow_succ' a n
theorem nmul_zero (n : ℕ) : n ⬝ 0 = (0:A) := one_pow n
theorem one_nmul (a : A) : 1 ⬝ a = a := pow_one a
theorem add_nmul (m n : ℕ) (a : A) : (m + n) ⬝ a = (m ⬝ a) + (n ⬝ a) := pow_add a m n
theorem mul_nmul (m n : ℕ) (a : A) : (m * n) ⬝ a = m ⬝ (n ⬝ a) := eq.subst (nat.mul.comm n m) (pow_mul a n m)
theorem nmul_comm (m n : ℕ) (a : A) : (m ⬝ a) + (n ⬝ a) = (n ⬝ a) + (m ⬝ a) := pow_comm a m n
end add_monoid
/- additive commutative monoid -/
section add_comm_monoid
open nat
variable [s : add_comm_monoid A]
include s
local attribute add_comm_monoid.to_comm_monoid [trans-instance]
theorem nmul_add (n : ℕ) (a b : A) : n ⬝ (a + b) = (n ⬝ a) + (n ⬝ b) := mul_pow a b n
end add_comm_monoid
section add_group
variable [s : add_group A]
include s
local attribute add_group.to_group [trans-instance]
section nat
open nat
theorem nmul_neg (n : ℕ) (a : A) : n ⬝ (-a) = -(n ⬝ a) := inv_pow a n
theorem sub_nmul {m n : ℕ} (a : A) (H : m ≥ n) : (m - n) ⬝ a = (m ⬝ a) + -(n ⬝ a) := pow_sub a H
theorem nmul_neg_comm (m n : ℕ) (a : A) : (m ⬝ (-a)) + (n ⬝ a) = (n ⬝ a) + (m ⬝ (-a)) := pow_inv_comm a m n
end nat
open int
definition imul : ℤ → A → A := λ i a, gpow a i
theorem add_imul (i j : ℤ) (a : A) : imul (i + j) a = imul i a + imul j a :=
gpow_add a i j
theorem imul_comm (i j : ℤ) (a : A) : imul i a + imul j a = imul j a + imul i a := gpow_comm a i j
end add_group
end algebra
|
40b69f22613cc039e5bfa36ea30f9c4bd95bd9c9 | 2a70b774d16dbdf5a533432ee0ebab6838df0948 | /_target/deps/mathlib/src/analysis/p_series.lean | e55321c6f9ed2d2999424e4841652e96f1a4e645 | [
"Apache-2.0"
] | permissive | hjvromen/lewis | 40b035973df7c77ebf927afab7878c76d05ff758 | 105b675f73630f028ad5d890897a51b3c1146fb0 | refs/heads/master | 1,677,944,636,343 | 1,676,555,301,000 | 1,676,555,301,000 | 327,553,599 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,263 | lean | /-
Copyright (c) 2020 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury G. Kudryashov
-/
import analysis.special_functions.pow
/-!
# Convergence of `p`-series
In this file we prove that the series `∑' k in ℕ, 1 / k ^ p` converges if and only if `p > 1`.
The proof is based on the
[Cauchy condensation test](https://en.wikipedia.org/wiki/Cauchy_condensation_test): `∑ k, f k`
converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. We prove this test in
`nnreal.summable_condensed_iff` and `summable_condensed_iff_of_nonneg`, then use it to prove
`summable_one_div_rpow`. After this transformation, a `p`-series turns into a geometric series.
## TODO
It should be easy to generalize arguments to Schlömilch's generalization of the Cauchy condensation
test once we need it.
## Tags
p-series, Cauchy condensation test
-/
open filter
open_locale big_operators ennreal nnreal topological_space
/-!
### Cauchy condensation test
In this section we prove the Cauchy condensation test: for `f : ℕ → ℝ≥0` or `f : ℕ → ℝ`,
`∑ k, f k` converges if and only if so does `∑ k, 2 ^ k f (2 ^ k)`. Instead of giving a monolithic
proof, we split it into a series of lemmas with explicit estimates of partial sums of each series in
terms of the partial sums of the other series.
-/
namespace finset
variables {M : Type*} [ordered_add_comm_monoid M] {f : ℕ → M}
lemma le_sum_condensed' (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k in Ico 1 (2 ^ n), f k) ≤ ∑ k in range n, (2 ^ k) •ℕ f (2 ^ k) :=
begin
induction n with n ihn, { simp },
suffices : (∑ k in Ico (2 ^ n) (2 ^ (n + 1)), f k) ≤ (2 ^ n) •ℕ f (2 ^ n),
{ rw [sum_range_succ, add_comm, ← sum_Ico_consecutive],
exact add_le_add ihn this,
exacts [n.one_le_two_pow, nat.pow_le_pow_of_le_right zero_lt_two n.le_succ] },
have : ∀ k ∈ Ico (2 ^ n) (2 ^ (n + 1)), f k ≤ f (2 ^ n) :=
λ k hk, hf (pow_pos zero_lt_two _) (Ico.mem.mp hk).1,
convert sum_le_sum this,
simp [pow_succ, two_mul]
end
lemma le_sum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k in range (2 ^ n), f k) ≤ f 0 + ∑ k in range n, (2 ^ k) •ℕ f (2 ^ k) :=
begin
convert add_le_add_left (le_sum_condensed' hf n) (f 0),
rw [← sum_range_add_sum_Ico _ n.one_le_two_pow, sum_range_succ, sum_range_zero, add_zero]
end
lemma sum_condensed_le' (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k in range n, (2 ^ k) •ℕ f (2 ^ (k + 1))) ≤ ∑ k in Ico 2 (2 ^ n + 1), f k :=
begin
induction n with n ihn, { simp },
suffices : (2 ^ n) •ℕ f (2 ^ (n + 1)) ≤ ∑ k in Ico (2 ^ n + 1) (2 ^ (n + 1) + 1), f k,
{ rw [sum_range_succ, add_comm, ← sum_Ico_consecutive],
exact add_le_add ihn this,
exacts [add_le_add_right n.one_le_two_pow _,
add_le_add_right (nat.pow_le_pow_of_le_right zero_lt_two n.le_succ) _] },
have : ∀ k ∈ Ico (2 ^ n + 1) (2 ^ (n + 1) + 1), f (2 ^ (n + 1)) ≤ f k :=
λ k hk, hf (n.one_le_two_pow.trans_lt $ (nat.lt_succ_of_le le_rfl).trans_le (Ico.mem.mp hk).1)
(nat.le_of_lt_succ $ (Ico.mem.mp hk).2),
convert sum_le_sum this,
simp [pow_succ, two_mul]
end
lemma sum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) (n : ℕ) :
(∑ k in range (n + 1), (2 ^ k) •ℕ f (2 ^ k)) ≤ f 1 + 2 •ℕ ∑ k in Ico 2 (2 ^ n + 1), f k :=
begin
convert add_le_add_left (nsmul_le_nsmul_of_le_right (sum_condensed_le' hf n) 2) (f 1),
simp [sum_range_succ', add_comm, pow_succ, mul_nsmul, sum_nsmul]
end
end finset
namespace ennreal
variable {f : ℕ → ennreal}
lemma le_tsum_condensed (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
(∑' k, f k) ≤ f 0 + ∑' k : ℕ, (2 ^ k) * f (2 ^ k) :=
begin
rw [ennreal.tsum_eq_supr_nat' (nat.tendsto_pow_at_top_at_top_of_one_lt _root_.one_lt_two)],
refine supr_le (λ n, (finset.le_sum_condensed hf n).trans (add_le_add_left _ _)),
simp only [nsmul_eq_mul, nat.cast_pow, nat.cast_two],
apply ennreal.sum_le_tsum
end
lemma tsum_condensed_le (hf : ∀ ⦃m n⦄, 1 < m → m ≤ n → f n ≤ f m) :
(∑' k : ℕ, (2 ^ k) * f (2 ^ k)) ≤ f 1 + 2 * ∑' k, f k :=
begin
rw [ennreal.tsum_eq_supr_nat' (tendsto_at_top_mono nat.le_succ tendsto_id), two_mul, ← two_nsmul],
refine supr_le (λ n, le_trans _ (add_le_add_left (nsmul_le_nsmul_of_le_right
(ennreal.sum_le_tsum $ finset.Ico 2 (2^n + 1)) _) _)),
simpa using finset.sum_condensed_le hf n
end
end ennreal
namespace nnreal
/-- Cauchy condensation test for a series of `nnreal` version. -/
lemma summable_condensed_iff {f : ℕ → ℝ≥0} (hf : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
summable (λ k : ℕ, (2 ^ k) * f (2 ^ k)) ↔ summable f :=
begin
simp only [← ennreal.tsum_coe_ne_top_iff_summable, ne.def, not_iff_not, ennreal.coe_mul,
ennreal.coe_pow, ennreal.coe_two],
split; intro h,
{ replace hf : ∀ m n, 1 < m → m ≤ n → (f n : ennreal) ≤ f m :=
λ m n hm hmn, ennreal.coe_le_coe.2 (hf (zero_lt_one.trans hm) hmn),
simpa [h, ennreal.add_eq_top] using (ennreal.tsum_condensed_le hf) },
{ replace hf : ∀ m n, 0 < m → m ≤ n → (f n : ennreal) ≤ f m :=
λ m n hm hmn, ennreal.coe_le_coe.2 (hf hm hmn),
simpa [h, ennreal.add_eq_top] using (ennreal.le_tsum_condensed hf) }
end
end nnreal
/-- Cauchy condensation test for series of nonnegative real numbers. -/
lemma summable_condensed_iff_of_nonneg {f : ℕ → ℝ} (h_nonneg : ∀ n, 0 ≤ f n)
(h_mono : ∀ ⦃m n⦄, 0 < m → m ≤ n → f n ≤ f m) :
summable (λ k : ℕ, (2 ^ k) * f (2 ^ k)) ↔ summable f :=
begin
set g : ℕ → ℝ≥0 := λ n, ⟨f n, h_nonneg n⟩,
have : f = λ n, g n := rfl,
simp only [this],
have : ∀ ⦃m n⦄, 0 < m → m ≤ n → g n ≤ g m := λ m n hm h, nnreal.coe_le_coe.2 (h_mono hm h),
exact_mod_cast nnreal.summable_condensed_iff this
end
open real
/-!
### Convergence of the `p`-series
In this section we prove that for a real number `p`, the series `∑' n : ℕ, 1 / (n ^ p)` converges if
and only if `1 < p`. There are many different proofs of this fact. The proof in this file uses the
Cauchy condensation test we formalized above. This test implies that `∑ n, 1 / (n ^ p)` converges if
and only if `∑ n, 2 ^ n / ((2 ^ n) ^ p)` converges, and the latter series is a geometric series with
common ratio `2 ^ {1 - p}`. -/
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp] lemma real.summable_nat_rpow_inv {p : ℝ} : summable (λ n, (n ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p :=
begin
cases le_or_lt 0 p with hp hp,
/- Cauchy condensation test applies only to monotonically decreasing sequences, so we consider the
cases `0 ≤ p` and `p < 0` separately. -/
{ rw ← summable_condensed_iff_of_nonneg,
{ simp_rw [nat.cast_pow, nat.cast_two, ← rpow_nat_cast, ← rpow_mul zero_lt_two.le, mul_comm _ p,
rpow_mul zero_lt_two.le, rpow_nat_cast, ← inv_pow', ← mul_pow,
summable_geometric_iff_norm_lt_1],
nth_rewrite 0 [← rpow_one 2],
rw [← division_def, ← rpow_sub zero_lt_two, norm_eq_abs,
abs_of_pos (rpow_pos_of_pos zero_lt_two _), rpow_lt_one_iff zero_lt_two.le],
norm_num },
{ intro n,
exact inv_nonneg.2 (rpow_nonneg_of_nonneg n.cast_nonneg _) },
{ intros m n hm hmn,
exact inv_le_inv_of_le (rpow_pos_of_pos (nat.cast_pos.2 hm) _)
(rpow_le_rpow m.cast_nonneg (nat.cast_le.2 hmn) hp) } },
/- If `p < 0`, then `1 / n ^ p` tends to infinity, thus the series diverges. -/
{ suffices : ¬summable (λ n, (n ^ p)⁻¹ : ℕ → ℝ),
{ have : ¬(1 < p) := λ hp₁, hp.not_le (zero_le_one.trans hp₁.le),
simpa [this, -one_div] },
{ intro h,
obtain ⟨k : ℕ, hk₁ : ((k ^ p)⁻¹ : ℝ) < 1, hk₀ : k ≠ 0⟩ :=
((h.tendsto_cofinite_zero.eventually (gt_mem_nhds zero_lt_one)).and
(eventually_cofinite_ne 0)).exists,
apply hk₀,
rw [← pos_iff_ne_zero, ← @nat.cast_pos ℝ] at hk₀,
simpa [inv_lt_one_iff_of_pos (rpow_pos_of_pos hk₀ _), one_lt_rpow_iff_of_pos hk₀, hp,
hp.not_lt, hk₀] using hk₁ } }
end
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
lemma real.summable_one_div_nat_rpow {p : ℝ} : summable (λ n, 1 / n ^ p : ℕ → ℝ) ↔ 1 < p :=
by simp
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, (n ^ p)⁻¹` converges
if and only if `1 < p`. -/
@[simp] lemma real.summable_nat_pow_inv {p : ℕ} : summable (λ n, (n ^ p)⁻¹ : ℕ → ℝ) ↔ 1 < p :=
by simp only [← rpow_nat_cast, real.summable_nat_rpow_inv, nat.one_lt_cast]
/-- Test for congergence of the `p`-series: the real-valued series `∑' n : ℕ, 1 / n ^ p` converges
if and only if `1 < p`. -/
lemma real.summable_one_div_nat_pow {p : ℕ} : summable (λ n, 1 / n ^ p : ℕ → ℝ) ↔ 1 < p :=
by simp
/-- Harmonic series is not unconditionally summable. -/
lemma real.not_summable_nat_cast_inv : ¬summable (λ n, n⁻¹ : ℕ → ℝ) :=
have ¬summable (λ n, (n^1)⁻¹ : ℕ → ℝ), from mt real.summable_nat_pow_inv.1 (lt_irrefl 1),
by simpa
/-- Harmonic series is not unconditionally summable. -/
lemma real.not_summable_one_div_nat_cast : ¬summable (λ n, 1 / n : ℕ → ℝ) :=
by simpa only [inv_eq_one_div] using real.not_summable_nat_cast_inv
/-- Harmonic series diverges. -/
lemma real.tendsto_sum_range_one_div_nat_succ_at_top :
tendsto (λ n, ∑ i in finset.range n, (1 / (i + 1) : ℝ)) at_top at_top :=
begin
rw ← not_summable_iff_tendsto_nat_at_top_of_nonneg,
{ exact_mod_cast mt (summable_nat_add_iff 1).1 real.not_summable_one_div_nat_cast },
{ exact λ i, div_nonneg zero_le_one i.cast_add_one_pos.le }
end
@[simp] lemma nnreal.summable_one_rpow_inv {p : ℝ} : summable (λ n, (n ^ p)⁻¹ : ℕ → ℝ≥0) ↔ 1 < p :=
by simp [← nnreal.summable_coe]
lemma nnreal.summable_one_div_rpow {p : ℝ} : summable (λ n, 1 / n ^ p : ℕ → ℝ≥0) ↔ 1 < p :=
by simp
|
3b3d4ac756b4ae1e882d4aa7ac1a38dc6cb3edd0 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/measure_theory/integral/circle_transform.lean | 4ba4ce3582103d532efef4f11ba604b2cc428fe3 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 7,969 | 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 data.complex.basic
import measure_theory.integral.circle_integral
/-!
# Circle integral transform
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
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_add_comm_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 ×ˢ univ) :=
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 ×ˢ univ) :=
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 * π],
∀ y : closed_ball z r ×ˢ [0, 2 * π],
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 * π]),
{ apply_rules [is_compact.prod, proper_space.is_compact_closed_ball z r, is_compact_uIcc], },
have none : (closed_ball z r ×ˢ [0, 2 * π]).nonempty :=
(nonempty_closed_ball.2 hr').prod nonempty_uIcc,
have := is_compact.exists_forall_ge comp none (cts.mono
(by { intro z, simp only [mem_prod, mem_closed_ball, mem_univ, and_true, and_imp], tauto })),
simpa only [set_coe.forall, subtype.coe_mk, set_coe.exists],
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 [uIcc_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))
(complex.abs.nonneg _) (complex.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, map_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
|
94140bb49d6e5ac8587b09d3ccc0002b37600f10 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/group_theory/transfer.lean | 1202268a0a7b74c4a53fda376b42def644191cba | [
"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,635 | lean | /-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import group_theory.complement
import group_theory.sylow
/-!
# The Transfer Homomorphism
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we construct the transfer homomorphism.
## Main definitions
- `diff ϕ S T` : The difference of two left transversals `S` and `T` under the homomorphism `ϕ`.
- `transfer ϕ` : The transfer homomorphism induced by `ϕ`.
- `transfer_center_pow`: The transfer homomorphism `G →* center G`.
## Main results
- `transfer_center_pow_apply`:
The transfer homomorphism `G →* center G` is given by `g ↦ g ^ (center G).index`.
- `ker_transfer_sylow_is_complement'`: Burnside's transfer (or normal `p`-complement) theorem:
If `hP : N(P) ≤ C(P)`, then `(transfer P hP).ker` is a normal `p`-complement.
-/
open_locale big_operators
variables {G : Type*} [group G] {H : subgroup G} {A : Type*} [comm_group A] (ϕ : H →* A)
namespace subgroup
namespace left_transversals
open finset mul_action
open_locale pointwise
variables (R S T : left_transversals (H : set G)) [finite_index H]
/-- The difference of two left transversals -/
@[to_additive "The difference of two left transversals"]
noncomputable def diff : A :=
let α := mem_left_transversals.to_equiv S.2, β := mem_left_transversals.to_equiv T.2 in
(@finset.univ (G ⧸ H) H.fintype_quotient_of_finite_index).prod $
λ q, ϕ ⟨(α q)⁻¹ * β q, quotient_group.left_rel_apply.mp $
quotient.exact' ((α.symm_apply_apply q).trans (β.symm_apply_apply q).symm)⟩
@[to_additive] lemma diff_mul_diff : diff ϕ R S * diff ϕ S T = diff ϕ R T :=
prod_mul_distrib.symm.trans (prod_congr rfl (λ q hq, (ϕ.map_mul _ _).symm.trans (congr_arg ϕ
(by simp_rw [subtype.ext_iff, coe_mul, coe_mk, mul_assoc, mul_inv_cancel_left]))))
@[to_additive] lemma diff_self : diff ϕ T T = 1 :=
mul_right_eq_self.mp (diff_mul_diff ϕ T T T)
@[to_additive] lemma diff_inv : (diff ϕ S T)⁻¹ = diff ϕ T S :=
inv_eq_of_mul_eq_one_right $ (diff_mul_diff ϕ S T S).trans $ diff_self ϕ S
@[to_additive] lemma smul_diff_smul (g : G) : diff ϕ (g • S) (g • T) = diff ϕ S T :=
let h := H.fintype_quotient_of_finite_index in by exactI
prod_bij' (λ q _, g⁻¹ • q) (λ _ _, mem_univ _) (λ _ _, congr_arg ϕ (by simp_rw [coe_mk,
smul_apply_eq_smul_apply_inv_smul, smul_eq_mul, mul_inv_rev, mul_assoc, inv_mul_cancel_left]))
(λ q _, g • q) (λ _ _, mem_univ _) (λ q _, smul_inv_smul g q) (λ q _, inv_smul_smul g q)
end left_transversals
end subgroup
namespace monoid_hom
open mul_action subgroup subgroup.left_transversals
/-- Given `ϕ : H →* A` from `H : subgroup G` to a commutative group `A`,
the transfer homomorphism is `transfer ϕ : G →* A`. -/
@[to_additive "Given `ϕ : H →+ A` from `H : add_subgroup G` to an additive commutative group `A`,
the transfer homomorphism is `transfer ϕ : G →+ A`."]
noncomputable def transfer [finite_index H] : G →* A :=
let T : left_transversals (H : set G) := inhabited.default in
{ to_fun := λ g, diff ϕ T (g • T),
map_one' := by rw [one_smul, diff_self],
map_mul' := λ g h, by rw [mul_smul, ←diff_mul_diff, smul_diff_smul] }
variables (T : left_transversals (H : set G))
@[to_additive] lemma transfer_def [finite_index H] (g : G) : transfer ϕ g = diff ϕ T (g • T) :=
by rw [transfer, ←diff_mul_diff, ←smul_diff_smul, mul_comm, diff_mul_diff]; refl
/-- Explicit computation of the transfer homomorphism. -/
lemma transfer_eq_prod_quotient_orbit_rel_zpowers_quot [finite_index H]
(g : G) [fintype (quotient (orbit_rel (zpowers g) (G ⧸ H)))] :
transfer ϕ g = ∏ (q : quotient (orbit_rel (zpowers g) (G ⧸ H))),
ϕ ⟨q.out'.out'⁻¹ * g ^ function.minimal_period ((•) g) q.out' * q.out'.out',
quotient_group.out'_conj_pow_minimal_period_mem H g q.out'⟩ :=
begin
classical,
letI := H.fintype_quotient_of_finite_index,
calc transfer ϕ g = ∏ (q : G ⧸ H), _ : transfer_def ϕ (transfer_transversal H g) g
... = _ : ((quotient_equiv_sigma_zmod H g).symm.prod_comp _).symm
... = _ : finset.prod_sigma _ _ _
... = _ : fintype.prod_congr _ _ (λ q, _),
simp only [quotient_equiv_sigma_zmod_symm_apply,
transfer_transversal_apply', transfer_transversal_apply''],
rw fintype.prod_eq_single (0 : zmod (function.minimal_period ((•) g) q.out')) (λ k hk, _),
{ simp only [if_pos, zmod.cast_zero, zpow_zero, one_mul, mul_assoc] },
{ simp only [if_neg hk, inv_mul_self],
exact map_one ϕ },
end
/-- Auxillary lemma in order to state `transfer_eq_pow`. -/
lemma transfer_eq_pow_aux (g : G)
(key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g₀⁻¹ * g ^ k * g₀ = g ^ k) :
g ^ H.index ∈ H :=
begin
by_cases hH : H.index = 0,
{ rw [hH, pow_zero],
exact H.one_mem },
letI := fintype_of_index_ne_zero hH,
classical,
replace key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g ^ k ∈ H :=
λ k g₀ hk, (_root_.congr_arg (∈ H) (key k g₀ hk)).mp hk,
replace key : ∀ q : G ⧸ H, g ^ function.minimal_period ((•) g) q ∈ H :=
λ q, key (function.minimal_period ((•) g) q) q.out'
(quotient_group.out'_conj_pow_minimal_period_mem H g q),
let f : quotient (orbit_rel (zpowers g) (G ⧸ H)) → zpowers g :=
λ q, (⟨g, mem_zpowers g⟩ : zpowers g) ^ function.minimal_period ((•) g) q.out',
have hf : ∀ q, f q ∈ H.subgroup_of (zpowers g) := λ q, key q.out',
replace key := subgroup.prod_mem (H.subgroup_of (zpowers g)) (λ q (hq : q ∈ finset.univ), hf q),
simpa only [minimal_period_eq_card, finset.prod_pow_eq_pow_sum, fintype.card_sigma,
fintype.card_congr (self_equiv_sigma_orbits (zpowers g) (G ⧸ H)), index_eq_card] using key,
end
lemma transfer_eq_pow [finite_index H] (g : G)
(key : ∀ (k : ℕ) (g₀ : G), g₀⁻¹ * g ^ k * g₀ ∈ H → g₀⁻¹ * g ^ k * g₀ = g ^ k) :
transfer ϕ g = ϕ ⟨g ^ H.index, transfer_eq_pow_aux g key⟩ :=
begin
classical,
letI := H.fintype_quotient_of_finite_index,
change ∀ k g₀ (hk : g₀⁻¹ * g ^ k * g₀ ∈ H), ↑(⟨g₀⁻¹ * g ^ k * g₀, hk⟩ : H) = g ^ k at key,
rw [transfer_eq_prod_quotient_orbit_rel_zpowers_quot, ←finset.prod_to_list, list.prod_map_hom],
refine congr_arg ϕ (subtype.coe_injective _),
rw [H.coe_mk, ←(zpowers g).coe_mk g (mem_zpowers g), ←(zpowers g).coe_pow, (zpowers g).coe_mk,
index_eq_card, fintype.card_congr (self_equiv_sigma_orbits (zpowers g) (G ⧸ H)),
fintype.card_sigma, ←finset.prod_pow_eq_pow_sum, ←finset.prod_to_list],
simp only [coe_list_prod, list.map_map, ←minimal_period_eq_card],
congr' 2,
funext,
apply key,
end
lemma transfer_center_eq_pow [finite_index (center G)] (g : G) :
transfer (monoid_hom.id (center G)) g = ⟨g ^ (center G).index, (center G).pow_index_mem g⟩ :=
transfer_eq_pow (id (center G)) g (λ k _ hk, by rw [←mul_right_inj, hk, mul_inv_cancel_right])
variables (G)
/-- The transfer homomorphism `G →* center G`. -/
noncomputable def transfer_center_pow [finite_index (center G)] : G →* center G :=
{ to_fun := λ g, ⟨g ^ (center G).index, (center G).pow_index_mem g⟩,
map_one' := subtype.ext (one_pow (center G).index),
map_mul' := λ a b, by simp_rw [←show ∀ g, (_ : center G) = _,
from transfer_center_eq_pow, map_mul] }
variables {G}
@[simp] lemma transfer_center_pow_apply [finite_index (center G)] (g : G) :
↑(transfer_center_pow G g) = g ^ (center G).index :=
rfl
section burnside_transfer
variables {p : ℕ} (P : sylow p G) (hP : (P : subgroup G).normalizer ≤ centralizer (P : set G))
include hP
/-- The homomorphism `G →* P` in Burnside's transfer theorem. -/
noncomputable def transfer_sylow [finite_index (P : subgroup G)] : G →* (P : subgroup G) :=
@transfer G _ P P (@subgroup.is_commutative.comm_group G _ P
⟨⟨λ a b, subtype.ext (hP (le_normalizer b.2) a a.2)⟩⟩) (monoid_hom.id P) _
variables [fact p.prime] [finite (sylow p G)]
/-- Auxillary lemma in order to state `transfer_sylow_eq_pow`. -/
lemma transfer_sylow_eq_pow_aux (g : G) (hg : g ∈ P) (k : ℕ) (g₀ : G) (h : g₀⁻¹ * g ^ k * g₀ ∈ P) :
g₀⁻¹ * g ^ k * g₀ = g ^ k :=
begin
haveI : (P : subgroup G).is_commutative := ⟨⟨λ a b, subtype.ext (hP (le_normalizer b.2) a a.2)⟩⟩,
replace hg := (P : subgroup G).pow_mem hg k,
obtain ⟨n, hn, h⟩ := P.conj_eq_normalizer_conj_of_mem (g ^ k) g₀ hg h,
exact h.trans (commute.inv_mul_cancel (hP hn (g ^ k) hg).symm),
end
variables [finite_index (P : subgroup G)]
lemma transfer_sylow_eq_pow (g : G) (hg : g ∈ P) : transfer_sylow P hP g =
⟨g ^ (P : subgroup G).index, transfer_eq_pow_aux g (transfer_sylow_eq_pow_aux P hP g hg)⟩ :=
by apply transfer_eq_pow
lemma transfer_sylow_restrict_eq_pow :
⇑((transfer_sylow P hP).restrict (P : subgroup G)) = (^ (P : subgroup G).index) :=
funext (λ g, transfer_sylow_eq_pow P hP g g.2)
/-- Burnside's normal p-complement theorem: If `N(P) ≤ C(P)`, then `P` has a normal complement. -/
lemma ker_transfer_sylow_is_complement' : is_complement' (transfer_sylow P hP).ker P :=
begin
have hf : function.bijective ((transfer_sylow P hP).restrict (P : subgroup G)) :=
(transfer_sylow_restrict_eq_pow P hP).symm ▸ (P.2.pow_equiv' (not_dvd_index_sylow P
(mt index_eq_zero_of_relindex_eq_zero index_ne_zero_of_finite))).bijective,
rw [function.bijective, ←range_top_iff_surjective, restrict_range] at hf,
have := range_top_iff_surjective.mp (top_le_iff.mp (hf.2.ge.trans (map_le_range _ P))),
rw [←(comap_injective this).eq_iff, comap_top, comap_map_eq, sup_comm, set_like.ext'_iff,
normal_mul, ←ker_eq_bot_iff, ←(map_injective (P : subgroup G).subtype_injective).eq_iff,
ker_restrict, subgroup_of_map_subtype, subgroup.map_bot, coe_top] at hf,
exact is_complement'_of_disjoint_and_mul_eq_univ (disjoint_iff.2 hf.1) hf.2,
end
lemma not_dvd_card_ker_transfer_sylow : ¬ p ∣ nat.card (transfer_sylow P hP).ker :=
(ker_transfer_sylow_is_complement' P hP).index_eq_card ▸ not_dvd_index_sylow P $
mt index_eq_zero_of_relindex_eq_zero index_ne_zero_of_finite
lemma ker_transfer_sylow_disjoint (Q : subgroup G) (hQ : is_p_group p Q) :
disjoint (transfer_sylow P hP).ker Q :=
disjoint_iff.mpr $ card_eq_one.mp $ (hQ.to_le inf_le_right).card_eq_or_dvd.resolve_right $
λ h, not_dvd_card_ker_transfer_sylow P hP $ h.trans $ nat_card_dvd_of_le _ _ inf_le_left
end burnside_transfer
end monoid_hom
|
2877196dfcd7936bc781f256d0d433b6804d0fde | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /stage0/src/Init/Core.lean | 55fb9ddbe6ec20649858a07d1592336a34162663 | [
"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 | 38,992 | 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
import Init.Prelude
import Init.SizeOf
universe u v w
def inline {α : Sort u} (a : α) : α := a
@[inline] def flip {α : Sort u} {β : Sort v} {φ : Sort w} (f : α → β → φ) : β → α → φ :=
fun b a => f a b
@[simp] theorem Function.const_apply {y : β} {x : α} : const α y x = y := rfl
@[simp] theorem Function.comp_apply {f : β → δ} {g : α → β} {x : α} : comp f g x = f (g x) := rfl
attribute [simp] namedPattern
/--
Thunks are "lazy" values that are evaluated when first accessed using `Thunk.get/map/bind`.
The value is then stored and not recomputed for all further accesses. -/
-- NOTE: the runtime has special support for the `Thunk` type to implement this behavior
structure Thunk (α : Type u) : Type u where
private fn : Unit → α
attribute [extern "lean_mk_thunk"] Thunk.mk
/-- Store a value in a thunk. Note that the value has already been computed, so there is no laziness. -/
@[extern "lean_thunk_pure"] protected def Thunk.pure (a : α) : Thunk α :=
⟨fun _ => a⟩
-- NOTE: we use `Thunk.get` instead of `Thunk.fn` as the accessor primitive as the latter has an additional `Unit` argument
@[extern "lean_thunk_get_own"] protected def Thunk.get (x : @& Thunk α) : α :=
x.fn ()
@[inline] protected def Thunk.map (f : α → β) (x : Thunk α) : Thunk β :=
⟨fun _ => f x.get⟩
@[inline] protected def Thunk.bind (x : Thunk α) (f : α → Thunk β) : Thunk β :=
⟨fun _ => (f x.get).get⟩
@[simp] theorem Thunk.sizeOf_eq [SizeOf α] (a : Thunk α) : sizeOf a = 1 + sizeOf a.get := by
cases a; rfl
abbrev Eq.ndrecOn.{u1, u2} {α : Sort u2} {a : α} {motive : α → Sort u1} {b : α} (h : a = b) (m : motive a) : motive b :=
Eq.ndrec m h
structure Iff (a b : Prop) : Prop where
intro :: (mp : a → b) (mpr : b → a)
infix:20 " <-> " => Iff
infix:20 " ↔ " => Iff
inductive Sum (α : Type u) (β : Type v) where
| inl (val : α) : Sum α β
| inr (val : β) : Sum α β
infixr:30 " ⊕ " => Sum
inductive PSum (α : Sort u) (β : Sort v) where
| inl (val : α) : PSum α β
| inr (val : β) : PSum α β
infixr:30 " ⊕' " => PSum
structure Sigma {α : Type u} (β : α → Type v) where
fst : α
snd : β fst
attribute [unbox] Sigma
structure PSigma {α : Sort u} (β : α → Sort v) where
fst : α
snd : β fst
inductive Exists {α : Sort u} (p : α → Prop) : Prop where
| intro (w : α) (h : p w) : Exists p
/-- Auxiliary type used to compile `for x in xs` notation. -/
inductive ForInStep (α : Type u) where
| done : α → ForInStep α
| yield : α → ForInStep α
deriving Inhabited
class ForIn (m : Type u₁ → Type u₂) (ρ : Type u) (α : outParam (Type v)) where
forIn {β} [Monad m] (x : ρ) (b : β) (f : α → β → m (ForInStep β)) : m β
export ForIn (forIn)
class ForIn' (m : Type u₁ → Type u₂) (ρ : Type u) (α : outParam (Type v)) (d : outParam $ Membership α ρ) where
forIn' {β} [Monad m] (x : ρ) (b : β) (f : (a : α) → a ∈ x → β → m (ForInStep β)) : m β
export ForIn' (forIn')
/-- Auxiliary type used to compile `do` notation. -/
inductive DoResultPRBC (α β σ : Type u) where
| pure : α → σ → DoResultPRBC α β σ
| return : β → σ → DoResultPRBC α β σ
| break : σ → DoResultPRBC α β σ
| continue : σ → DoResultPRBC α β σ
/-- Auxiliary type used to compile `do` notation. -/
inductive DoResultPR (α β σ : Type u) where
| pure : α → σ → DoResultPR α β σ
| return : β → σ → DoResultPR α β σ
/-- Auxiliary type used to compile `do` notation. -/
inductive DoResultBC (σ : Type u) where
| break : σ → DoResultBC σ
| continue : σ → DoResultBC σ
/-- Auxiliary type used to compile `do` notation. -/
inductive DoResultSBC (α σ : Type u) where
| pureReturn : α → σ → DoResultSBC α σ
| break : σ → DoResultSBC α σ
| continue : σ → DoResultSBC α σ
class HasEquiv (α : Sort u) where
Equiv : α → α → Sort v
infix:50 " ≈ " => HasEquiv.Equiv
class EmptyCollection (α : Type u) where
emptyCollection : α
notation "{" "}" => EmptyCollection.emptyCollection
notation "∅" => EmptyCollection.emptyCollection
/-- Remark: tasks have an efficient implementation in the runtime. -/
structure Task (α : Type u) : Type u where
pure :: (get : α)
deriving Inhabited
attribute [extern "lean_task_pure"] Task.pure
attribute [extern "lean_task_get_own"] Task.get
namespace Task
/-- Task priority. Tasks with higher priority will always be scheduled before ones with lower priority. -/
abbrev Priority := Nat
def Priority.default : Priority := 0
-- see `LEAN_MAX_PRIO`
def Priority.max : Priority := 8
/--
Any priority higher than `Task.Priority.max` will result in the task being scheduled immediately on a dedicated thread.
This is particularly useful for long-running and/or I/O-bound tasks since Lean will by default allocate no more
non-dedicated workers than the number of cores to reduce context switches. -/
def Priority.dedicated : Priority := 9
set_option linter.unusedVariables.funArgs false in
@[noinline, extern "lean_task_spawn"]
protected def spawn {α : Type u} (fn : Unit → α) (prio := Priority.default) : Task α :=
⟨fn ()⟩
set_option linter.unusedVariables.funArgs false in
@[noinline, extern "lean_task_map"]
protected def map {α : Type u} {β : Type v} (f : α → β) (x : Task α) (prio := Priority.default) : Task β :=
⟨f x.get⟩
set_option linter.unusedVariables.funArgs false in
@[noinline, extern "lean_task_bind"]
protected def bind {α : Type u} {β : Type v} (x : Task α) (f : α → Task β) (prio := Priority.default) : Task β :=
⟨(f x.get).get⟩
end Task
/-- Some type that is not a scalar value in our runtime. -/
structure NonScalar where
val : Nat
/-- Some type that is not a scalar value in our runtime and is universe polymorphic. -/
inductive PNonScalar : Type u where
| mk (v : Nat) : PNonScalar
@[simp] theorem Nat.add_zero (n : Nat) : n + 0 = n := rfl
theorem optParam_eq (α : Sort u) (default : α) : optParam α default = α := rfl
/-! # Boolean operators -/
@[extern c inline "#1 || #2"] def strictOr (b₁ b₂ : Bool) := b₁ || b₂
@[extern c inline "#1 && #2"] def strictAnd (b₁ b₂ : Bool) := b₁ && b₂
@[inline] def bne {α : Type u} [BEq α] (a b : α) : Bool :=
!(a == b)
infix:50 " != " => bne
class LawfulBEq (α : Type u) [BEq α] : Prop where
eq_of_beq : {a b : α} → (a == b) = true → a = b
protected rfl : {a : α} → (a == a) = true
export LawfulBEq (eq_of_beq)
instance : LawfulBEq Bool where
eq_of_beq {a b} h := by cases a <;> cases b <;> first | rfl | contradiction
rfl {a} := by cases a <;> decide
instance [DecidableEq α] : LawfulBEq α where
eq_of_beq := of_decide_eq_true
rfl := of_decide_eq_self_eq_true _
instance : LawfulBEq Char := inferInstance
instance : LawfulBEq String := inferInstance
/-! # Logical connectives and equality -/
def implies (a b : Prop) := a → b
theorem implies.trans {p q r : Prop} (h₁ : implies p q) (h₂ : implies q r) : implies p r :=
fun hp => h₂ (h₁ hp)
def trivial : True := ⟨⟩
theorem mt {a b : Prop} (h₁ : a → b) (h₂ : ¬b) : ¬a :=
fun ha => h₂ (h₁ ha)
theorem not_false : ¬False := id
theorem not_not_intro {p : Prop} (h : p) : ¬ ¬ p :=
fun hn : ¬ p => hn h
-- proof irrelevance is built in
theorem proofIrrel {a : Prop} (h₁ h₂ : a) : h₁ = h₂ := rfl
theorem id.def {α : Sort u} (a : α) : id a = a := rfl
@[macroInline] def Eq.mp {α β : Sort u} (h : α = β) (a : α) : β :=
h ▸ a
@[macroInline] def Eq.mpr {α β : Sort u} (h : α = β) (b : β) : α :=
h ▸ b
theorem Eq.substr {α : Sort u} {p : α → Prop} {a b : α} (h₁ : b = a) (h₂ : p a) : p b :=
h₁ ▸ h₂
theorem cast_eq {α : Sort u} (h : α = α) (a : α) : cast h a = a :=
rfl
@[reducible] def Ne {α : Sort u} (a b : α) :=
¬(a = b)
infix:50 " ≠ " => Ne
section Ne
variable {α : Sort u}
variable {a b : α} {p : Prop}
theorem Ne.intro (h : a = b → False) : a ≠ b := h
theorem Ne.elim (h : a ≠ b) : a = b → False := h
theorem Ne.irrefl (h : a ≠ a) : False := h rfl
theorem Ne.symm (h : a ≠ b) : b ≠ a :=
fun h₁ => h (h₁.symm)
theorem false_of_ne : a ≠ a → False := Ne.irrefl
theorem ne_false_of_self : p → p ≠ False :=
fun (hp : p) (h : p = False) => h ▸ hp
theorem ne_true_of_not : ¬p → p ≠ True :=
fun (hnp : ¬p) (h : p = True) =>
have : ¬True := h ▸ hnp
this trivial
theorem true_ne_false : ¬True = False :=
ne_false_of_self trivial
end Ne
theorem Bool.of_not_eq_true : {b : Bool} → ¬ (b = true) → b = false
| true, h => absurd rfl h
| false, _ => rfl
theorem Bool.of_not_eq_false : {b : Bool} → ¬ (b = false) → b = true
| true, _ => rfl
| false, h => absurd rfl h
theorem ne_of_beq_false [BEq α] [LawfulBEq α] {a b : α} (h : (a == b) = false) : a ≠ b := by
intro h'; subst h'; have : true = false := Eq.trans LawfulBEq.rfl.symm h; contradiction
theorem beq_false_of_ne [BEq α] [LawfulBEq α] {a b : α} (h : a ≠ b) : (a == b) = false :=
have : ¬ (a == b) = true := by
intro h'; rw [eq_of_beq h'] at h; contradiction
Bool.of_not_eq_true this
section
variable {α β φ : Sort u} {a a' : α} {b b' : β} {c : φ}
theorem HEq.ndrec.{u1, u2} {α : Sort u2} {a : α} {motive : {β : Sort u2} → β → Sort u1} (m : motive a) {β : Sort u2} {b : β} (h : HEq a b) : motive b :=
h.rec m
theorem HEq.ndrecOn.{u1, u2} {α : Sort u2} {a : α} {motive : {β : Sort u2} → β → Sort u1} {β : Sort u2} {b : β} (h : HEq a b) (m : motive a) : motive b :=
h.rec m
theorem HEq.elim {α : Sort u} {a : α} {p : α → Sort v} {b : α} (h₁ : HEq a b) (h₂ : p a) : p b :=
eq_of_heq h₁ ▸ h₂
theorem HEq.subst {p : (T : Sort u) → T → Prop} (h₁ : HEq a b) (h₂ : p α a) : p β b :=
HEq.ndrecOn h₁ h₂
theorem HEq.symm (h : HEq a b) : HEq b a :=
h.rec (HEq.refl a)
theorem heq_of_eq (h : a = a') : HEq a a' :=
Eq.subst h (HEq.refl a)
theorem HEq.trans (h₁ : HEq a b) (h₂ : HEq b c) : HEq a c :=
HEq.subst h₂ h₁
theorem heq_of_heq_of_eq (h₁ : HEq a b) (h₂ : b = b') : HEq a b' :=
HEq.trans h₁ (heq_of_eq h₂)
theorem heq_of_eq_of_heq (h₁ : a = a') (h₂ : HEq a' b) : HEq a b :=
HEq.trans (heq_of_eq h₁) h₂
def type_eq_of_heq (h : HEq a b) : α = β :=
h.rec (Eq.refl α)
end
theorem eqRec_heq {α : Sort u} {φ : α → Sort v} {a a' : α} : (h : a = a') → (p : φ a) → HEq (Eq.recOn (motive := fun x _ => φ x) h p) p
| rfl, p => HEq.refl p
theorem heq_of_eqRec_eq {α β : Sort u} {a : α} {b : β} (h₁ : α = β) (h₂ : Eq.rec (motive := fun α _ => α) a h₁ = b) : HEq a b := by
subst h₁
apply heq_of_eq
exact h₂
theorem cast_heq {α β : Sort u} : (h : α = β) → (a : α) → HEq (cast h a) a
| rfl, a => HEq.refl a
variable {a b c d : Prop}
theorem iff_iff_implies_and_implies (a b : Prop) : (a ↔ b) ↔ (a → b) ∧ (b → a) :=
Iff.intro (fun h => And.intro h.mp h.mpr) (fun h => Iff.intro h.left h.right)
theorem Iff.refl (a : Prop) : a ↔ a :=
Iff.intro (fun h => h) (fun h => h)
protected theorem Iff.rfl {a : Prop} : a ↔ a :=
Iff.refl a
theorem Iff.trans (h₁ : a ↔ b) (h₂ : b ↔ c) : a ↔ c :=
Iff.intro
(fun ha => Iff.mp h₂ (Iff.mp h₁ ha))
(fun hc => Iff.mpr h₁ (Iff.mpr h₂ hc))
theorem Iff.symm (h : a ↔ b) : b ↔ a :=
Iff.intro (Iff.mpr h) (Iff.mp h)
theorem Iff.comm : (a ↔ b) ↔ (b ↔ a) :=
Iff.intro Iff.symm Iff.symm
theorem And.comm : a ∧ b ↔ b ∧ a := by
constructor <;> intro ⟨h₁, h₂⟩ <;> exact ⟨h₂, h₁⟩
/-! # Exists -/
theorem Exists.elim {α : Sort u} {p : α → Prop} {b : Prop}
(h₁ : Exists (fun x => p x)) (h₂ : ∀ (a : α), p a → b) : b :=
match h₁ with
| intro a h => h₂ a h
/-! # Decidable -/
theorem decide_true_eq_true (h : Decidable True) : @decide True h = true :=
match h with
| isTrue _ => rfl
| isFalse h => False.elim <| h ⟨⟩
theorem decide_false_eq_false (h : Decidable False) : @decide False h = false :=
match h with
| isFalse _ => rfl
| isTrue h => False.elim h
/-- Similar to `decide`, but uses an explicit instance -/
@[inline] def toBoolUsing {p : Prop} (d : Decidable p) : Bool :=
decide p (h := d)
theorem toBoolUsing_eq_true {p : Prop} (d : Decidable p) (h : p) : toBoolUsing d = true :=
decide_eq_true (inst := d) h
theorem ofBoolUsing_eq_true {p : Prop} {d : Decidable p} (h : toBoolUsing d = true) : p :=
of_decide_eq_true (inst := d) h
theorem ofBoolUsing_eq_false {p : Prop} {d : Decidable p} (h : toBoolUsing d = false) : ¬ p :=
of_decide_eq_false (inst := d) h
instance : Decidable True :=
isTrue trivial
instance : Decidable False :=
isFalse not_false
namespace Decidable
variable {p q : Prop}
@[macroInline] def byCases {q : Sort u} [dec : Decidable p] (h1 : p → q) (h2 : ¬p → q) : q :=
match dec with
| isTrue h => h1 h
| isFalse h => h2 h
theorem em (p : Prop) [Decidable p] : p ∨ ¬p :=
byCases Or.inl Or.inr
set_option linter.unusedVariables.funArgs false in
theorem byContradiction [dec : Decidable p] (h : ¬p → False) : p :=
byCases id (fun np => False.elim (h np))
theorem of_not_not [Decidable p] : ¬ ¬ p → p :=
fun hnn => byContradiction (fun hn => absurd hn hnn)
theorem not_and_iff_or_not (p q : Prop) [d₁ : Decidable p] [d₂ : Decidable q] : ¬ (p ∧ q) ↔ ¬ p ∨ ¬ q :=
Iff.intro
(fun h => match d₁, d₂ with
| isTrue h₁, isTrue h₂ => absurd (And.intro h₁ h₂) h
| _, isFalse h₂ => Or.inr h₂
| isFalse h₁, _ => Or.inl h₁)
(fun (h) ⟨hp, hq⟩ => match h with
| Or.inl h => h hp
| Or.inr h => h hq)
end Decidable
section
variable {p q : Prop}
@[inline] def decidable_of_decidable_of_iff [Decidable p] (h : p ↔ q) : Decidable q :=
if hp : p then
isTrue (Iff.mp h hp)
else
isFalse fun hq => absurd (Iff.mpr h hq) hp
@[inline] def decidable_of_decidable_of_eq [hp : Decidable p] (h : p = q) : Decidable q :=
h ▸ hp
end
@[macroInline] instance {p q} [Decidable p] [Decidable q] : Decidable (p → q) :=
if hp : p then
if hq : q then isTrue (fun _ => hq)
else isFalse (fun h => absurd (h hp) hq)
else isTrue (fun h => absurd h hp)
instance {p q} [Decidable p] [Decidable q] : Decidable (p ↔ q) :=
if hp : p then
if hq : q then
isTrue ⟨fun _ => hq, fun _ => hp⟩
else
isFalse fun h => hq (h.1 hp)
else
if hq : q then
isFalse fun h => hp (h.2 hq)
else
isTrue ⟨fun h => absurd h hp, fun h => absurd h hq⟩
/-! # if-then-else expression theorems -/
theorem if_pos {c : Prop} {h : Decidable c} (hc : c) {α : Sort u} {t e : α} : (ite c t e) = t :=
match h with
| isTrue _ => rfl
| isFalse hnc => absurd hc hnc
theorem if_neg {c : Prop} {h : Decidable c} (hnc : ¬c) {α : Sort u} {t e : α} : (ite c t e) = e :=
match h with
| isTrue hc => absurd hc hnc
| isFalse _ => rfl
theorem dif_pos {c : Prop} {h : Decidable c} (hc : c) {α : Sort u} {t : c → α} {e : ¬ c → α} : (dite c t e) = t hc :=
match h with
| isTrue _ => rfl
| isFalse hnc => absurd hc hnc
theorem dif_neg {c : Prop} {h : Decidable c} (hnc : ¬c) {α : Sort u} {t : c → α} {e : ¬ c → α} : (dite c t e) = e hnc :=
match h with
| isTrue hc => absurd hc hnc
| isFalse _ => rfl
-- Remark: dite and ite are "defally equal" when we ignore the proofs.
theorem dif_eq_if (c : Prop) {h : Decidable c} {α : Sort u} (t : α) (e : α) : dite c (fun _ => t) (fun _ => e) = ite c t e :=
match h with
| isTrue _ => rfl
| isFalse _ => rfl
instance {c t e : Prop} [dC : Decidable c] [dT : Decidable t] [dE : Decidable e] : Decidable (if c then t else e) :=
match dC with
| isTrue _ => dT
| isFalse _ => dE
instance {c : Prop} {t : c → Prop} {e : ¬c → Prop} [dC : Decidable c] [dT : ∀ h, Decidable (t h)] [dE : ∀ h, Decidable (e h)] : Decidable (if h : c then t h else e h) :=
match dC with
| isTrue hc => dT hc
| isFalse hc => dE hc
/-- Auxiliary definitions for generating compact `noConfusion` for enumeration types -/
abbrev noConfusionTypeEnum {α : Sort u} {β : Sort v} [inst : DecidableEq β] (f : α → β) (P : Sort w) (x y : α) : Sort w :=
(inst (f x) (f y)).casesOn
(fun _ => P)
(fun _ => P → P)
abbrev noConfusionEnum {α : Sort u} {β : Sort v} [inst : DecidableEq β] (f : α → β) {P : Sort w} {x y : α} (h : x = y) : noConfusionTypeEnum f P x y :=
Decidable.casesOn
(motive := fun (inst : Decidable (f x = f y)) => Decidable.casesOn (motive := fun _ => Sort w) inst (fun _ => P) (fun _ => P → P))
(inst (f x) (f y))
(fun h' => False.elim (h' (congrArg f h)))
(fun _ => fun x => x)
/-! # Inhabited -/
instance : Inhabited Prop where
default := True
deriving instance Inhabited for NonScalar, PNonScalar, True, ForInStep
theorem nonempty_of_exists {α : Sort u} {p : α → Prop} : Exists (fun x => p x) → Nonempty α
| ⟨w, _⟩ => ⟨w⟩
/-! # Subsingleton -/
class Subsingleton (α : Sort u) : Prop where
intro :: allEq : (a b : α) → a = b
protected def Subsingleton.elim {α : Sort u} [h : Subsingleton α] : (a b : α) → a = b :=
h.allEq
protected def Subsingleton.helim {α β : Sort u} [h₁ : Subsingleton α] (h₂ : α = β) (a : α) (b : β) : HEq a b := by
subst h₂
apply heq_of_eq
apply Subsingleton.elim
instance (p : Prop) : Subsingleton p :=
⟨fun a b => proofIrrel a b⟩
instance (p : Prop) : Subsingleton (Decidable p) :=
Subsingleton.intro fun
| isTrue t₁ => fun
| isTrue _ => rfl
| isFalse f₂ => absurd t₁ f₂
| isFalse f₁ => fun
| isTrue t₂ => absurd t₂ f₁
| isFalse _ => rfl
theorem recSubsingleton
{p : Prop} [h : Decidable p]
{h₁ : p → Sort u}
{h₂ : ¬p → Sort u}
[h₃ : ∀ (h : p), Subsingleton (h₁ h)]
[h₄ : ∀ (h : ¬p), Subsingleton (h₂ h)]
: Subsingleton (h.casesOn h₂ h₁) :=
match h with
| isTrue h => h₃ h
| isFalse h => h₄ h
structure Equivalence {α : Sort u} (r : α → α → Prop) : Prop where
refl : ∀ x, r x x
symm : ∀ {x y}, r x y → r y x
trans : ∀ {x y z}, r x y → r y z → r x z
def emptyRelation {α : Sort u} (_ _ : α) : Prop :=
False
def Subrelation {α : Sort u} (q r : α → α → Prop) :=
∀ {x y}, q x y → r x y
def InvImage {α : Sort u} {β : Sort v} (r : β → β → Prop) (f : α → β) : α → α → Prop :=
fun a₁ a₂ => r (f a₁) (f a₂)
inductive TC {α : Sort u} (r : α → α → Prop) : α → α → Prop where
| base : ∀ a b, r a b → TC r a b
| trans : ∀ a b c, TC r a b → TC r b c → TC r a c
/-! # Subtype -/
namespace Subtype
def existsOfSubtype {α : Type u} {p : α → Prop} : { x // p x } → Exists (fun x => p x)
| ⟨a, h⟩ => ⟨a, h⟩
variable {α : Type u} {p : α → Prop}
protected theorem eq : ∀ {a1 a2 : {x // p x}}, val a1 = val a2 → a1 = a2
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
theorem eta (a : {x // p x}) (h : p (val a)) : mk (val a) h = a := by
cases a
exact rfl
instance {α : Type u} {p : α → Prop} {a : α} (h : p a) : Inhabited {x // p x} where
default := ⟨a, h⟩
instance {α : Type u} {p : α → Prop} [DecidableEq α] : DecidableEq {x : α // p x} :=
fun ⟨a, h₁⟩ ⟨b, h₂⟩ =>
if h : a = b then isTrue (by subst h; exact rfl)
else isFalse (fun h' => Subtype.noConfusion h' (fun h' => absurd h' h))
end Subtype
/-! # Sum -/
section
variable {α : Type u} {β : Type v}
instance Sum.inhabitedLeft [Inhabited α] : Inhabited (Sum α β) where
default := Sum.inl default
instance Sum.inhabitedRight [Inhabited β] : Inhabited (Sum α β) where
default := Sum.inr default
instance {α : Type u} {β : Type v} [DecidableEq α] [DecidableEq β] : DecidableEq (Sum α β) := fun a b =>
match a, b with
| Sum.inl a, Sum.inl b =>
if h : a = b then isTrue (h ▸ rfl)
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
| Sum.inr a, Sum.inr b =>
if h : a = b then isTrue (h ▸ rfl)
else isFalse fun h' => Sum.noConfusion h' fun h' => absurd h' h
| Sum.inr _, Sum.inl _ => isFalse fun h => Sum.noConfusion h
| Sum.inl _, Sum.inr _ => isFalse fun h => Sum.noConfusion h
end
/-! # Product -/
instance [Inhabited α] [Inhabited β] : Inhabited (α × β) where
default := (default, default)
instance [Inhabited α] [Inhabited β] : Inhabited (MProd α β) where
default := ⟨default, default⟩
instance [Inhabited α] [Inhabited β] : Inhabited (PProd α β) where
default := ⟨default, default⟩
instance [DecidableEq α] [DecidableEq β] : DecidableEq (α × β) :=
fun (a, b) (a', b') =>
match decEq a a' with
| isTrue e₁ =>
match decEq b b' with
| isTrue e₂ => isTrue (e₁ ▸ e₂ ▸ rfl)
| isFalse n₂ => isFalse fun h => Prod.noConfusion h fun _ e₂' => absurd e₂' n₂
| isFalse n₁ => isFalse fun h => Prod.noConfusion h fun e₁' _ => absurd e₁' n₁
instance [BEq α] [BEq β] : BEq (α × β) where
beq := fun (a₁, b₁) (a₂, b₂) => a₁ == a₂ && b₁ == b₂
instance [LT α] [LT β] : LT (α × β) where
lt s t := s.1 < t.1 ∨ (s.1 = t.1 ∧ s.2 < t.2)
instance prodHasDecidableLt
[LT α] [LT β] [DecidableEq α] [DecidableEq β]
[(a b : α) → Decidable (a < b)] [(a b : β) → Decidable (a < b)]
: (s t : α × β) → Decidable (s < t) :=
fun _ _ => inferInstanceAs (Decidable (_ ∨ _))
theorem Prod.lt_def [LT α] [LT β] (s t : α × β) : (s < t) = (s.1 < t.1 ∨ (s.1 = t.1 ∧ s.2 < t.2)) :=
rfl
theorem Prod.ext (p : α × β) : (p.1, p.2) = p := by
cases p; rfl
def Prod.map {α₁ : Type u₁} {α₂ : Type u₂} {β₁ : Type v₁} {β₂ : Type v₂}
(f : α₁ → α₂) (g : β₁ → β₂) : α₁ × β₁ → α₂ × β₂
| (a, b) => (f a, g b)
/-! # Dependent products -/
theorem ex_of_PSigma {α : Type u} {p : α → Prop} : (PSigma (fun x => p x)) → Exists (fun x => p x)
| ⟨x, hx⟩ => ⟨x, hx⟩
protected theorem PSigma.eta {α : Sort u} {β : α → Sort v} {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂}
(h₁ : a₁ = a₂) (h₂ : Eq.ndrec b₁ h₁ = b₂) : PSigma.mk a₁ b₁ = PSigma.mk a₂ b₂ := by
subst h₁
subst h₂
exact rfl
/-! # Universe polymorphic unit -/
theorem PUnit.subsingleton (a b : PUnit) : a = b := by
cases a; cases b; exact rfl
theorem PUnit.eq_punit (a : PUnit) : a = ⟨⟩ :=
PUnit.subsingleton a ⟨⟩
instance : Subsingleton PUnit :=
Subsingleton.intro PUnit.subsingleton
instance : Inhabited PUnit where
default := ⟨⟩
instance : DecidableEq PUnit :=
fun a b => isTrue (PUnit.subsingleton a b)
/-! # Setoid -/
class Setoid (α : Sort u) where
r : α → α → Prop
iseqv : Equivalence r
instance {α : Sort u} [Setoid α] : HasEquiv α :=
⟨Setoid.r⟩
namespace Setoid
variable {α : Sort u} [Setoid α]
theorem refl (a : α) : a ≈ a :=
iseqv.refl a
theorem symm {a b : α} (hab : a ≈ b) : b ≈ a :=
iseqv.symm hab
theorem trans {a b c : α} (hab : a ≈ b) (hbc : b ≈ c) : a ≈ c :=
iseqv.trans hab hbc
end Setoid
/-! # Propositional extensionality -/
axiom propext {a b : Prop} : (a ↔ b) → a = b
theorem Eq.propIntro {a b : Prop} (h₁ : a → b) (h₂ : b → a) : a = b :=
propext <| Iff.intro h₁ h₂
-- Eq for Prop is now decidable if the equivalent Iff is decidable
instance {p q : Prop} [d : Decidable (p ↔ q)] : Decidable (p = q) :=
match d with
| isTrue h => isTrue (propext h)
| isFalse h => isFalse fun heq => h (heq ▸ Iff.rfl)
gen_injective_theorems% Prod
gen_injective_theorems% PProd
gen_injective_theorems% MProd
gen_injective_theorems% Subtype
gen_injective_theorems% Fin
gen_injective_theorems% Array
gen_injective_theorems% Sum
gen_injective_theorems% PSum
gen_injective_theorems% Nat
gen_injective_theorems% Option
gen_injective_theorems% List
gen_injective_theorems% Except
gen_injective_theorems% EStateM.Result
gen_injective_theorems% Lean.Name
gen_injective_theorems% Lean.Syntax
@[simp] theorem beq_iff_eq [BEq α] [LawfulBEq α] (a b : α) : a == b ↔ a = b :=
⟨eq_of_beq, by intro h; subst h; exact LawfulBEq.rfl⟩
/-! # Quotients -/
/-- Iff can now be used to do substitutions in a calculation -/
theorem Iff.subst {a b : Prop} {p : Prop → Prop} (h₁ : a ↔ b) (h₂ : p a) : p b :=
Eq.subst (propext h₁) h₂
namespace Quot
axiom sound : ∀ {α : Sort u} {r : α → α → Prop} {a b : α}, r a b → Quot.mk r a = Quot.mk r b
protected theorem liftBeta {α : Sort u} {r : α → α → Prop} {β : Sort v}
(f : α → β)
(c : (a b : α) → r a b → f a = f b)
(a : α)
: lift f c (Quot.mk r a) = f a :=
rfl
protected theorem indBeta {α : Sort u} {r : α → α → Prop} {motive : Quot r → Prop}
(p : (a : α) → motive (Quot.mk r a))
(a : α)
: (ind p (Quot.mk r a) : motive (Quot.mk r a)) = p a :=
rfl
protected abbrev liftOn {α : Sort u} {β : Sort v} {r : α → α → Prop} (q : Quot r) (f : α → β) (c : (a b : α) → r a b → f a = f b) : β :=
lift f c q
@[elabAsElim]
protected theorem inductionOn {α : Sort u} {r : α → α → Prop} {motive : Quot r → Prop}
(q : Quot r)
(h : (a : α) → motive (Quot.mk r a))
: motive q :=
ind h q
theorem exists_rep {α : Sort u} {r : α → α → Prop} (q : Quot r) : Exists (fun a => (Quot.mk r a) = q) :=
q.inductionOn (fun a => ⟨a, rfl⟩)
section
variable {α : Sort u}
variable {r : α → α → Prop}
variable {motive : Quot r → Sort v}
@[reducible, macroInline]
protected def indep (f : (a : α) → motive (Quot.mk r a)) (a : α) : PSigma motive :=
⟨Quot.mk r a, f a⟩
protected theorem indepCoherent
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
: (a b : α) → r a b → Quot.indep f a = Quot.indep f b :=
fun a b e => PSigma.eta (sound e) (h a b e)
protected theorem liftIndepPr1
(f : (a : α) → motive (Quot.mk r a))
(h : ∀ (a b : α) (p : r a b), Eq.ndrec (f a) (sound p) = f b)
(q : Quot r)
: (lift (Quot.indep f) (Quot.indepCoherent f h) q).1 = q := by
induction q using Quot.ind
exact rfl
protected abbrev rec
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
(q : Quot r) : motive q :=
Eq.ndrecOn (Quot.liftIndepPr1 f h q) ((lift (Quot.indep f) (Quot.indepCoherent f h) q).2)
protected abbrev recOn
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
(h : (a b : α) → (p : r a b) → Eq.ndrec (f a) (sound p) = f b)
: motive q :=
q.rec f h
protected abbrev recOnSubsingleton
[h : (a : α) → Subsingleton (motive (Quot.mk r a))]
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
: motive q := by
induction q using Quot.rec
apply f
apply Subsingleton.elim
protected abbrev hrecOn
(q : Quot r)
(f : (a : α) → motive (Quot.mk r a))
(c : (a b : α) → (p : r a b) → HEq (f a) (f b))
: motive q :=
Quot.recOn q f fun a b p => eq_of_heq <|
have p₁ : HEq (Eq.ndrec (f a) (sound p)) (f a) := eqRec_heq (sound p) (f a)
HEq.trans p₁ (c a b p)
end
end Quot
set_option linter.unusedVariables.funArgs false in
def Quotient {α : Sort u} (s : Setoid α) :=
@Quot α Setoid.r
namespace Quotient
@[inline]
protected def mk {α : Sort u} (s : Setoid α) (a : α) : Quotient s :=
Quot.mk Setoid.r a
protected def mk' {α : Sort u} [s : Setoid α] (a : α) : Quotient s :=
Quotient.mk s a
def sound {α : Sort u} {s : Setoid α} {a b : α} : a ≈ b → Quotient.mk s a = Quotient.mk s b :=
Quot.sound
protected abbrev lift {α : Sort u} {β : Sort v} {s : Setoid α} (f : α → β) : ((a b : α) → a ≈ b → f a = f b) → Quotient s → β :=
Quot.lift f
protected theorem ind {α : Sort u} {s : Setoid α} {motive : Quotient s → Prop} : ((a : α) → motive (Quotient.mk s a)) → (q : Quot Setoid.r) → motive q :=
Quot.ind
protected abbrev liftOn {α : Sort u} {β : Sort v} {s : Setoid α} (q : Quotient s) (f : α → β) (c : (a b : α) → a ≈ b → f a = f b) : β :=
Quot.liftOn q f c
@[elabAsElim]
protected theorem inductionOn {α : Sort u} {s : Setoid α} {motive : Quotient s → Prop}
(q : Quotient s)
(h : (a : α) → motive (Quotient.mk s a))
: motive q :=
Quot.inductionOn q h
theorem exists_rep {α : Sort u} {s : Setoid α} (q : Quotient s) : Exists (fun (a : α) => Quotient.mk s a = q) :=
Quot.exists_rep q
section
variable {α : Sort u}
variable {s : Setoid α}
variable {motive : Quotient s → Sort v}
@[inline, elabAsElim]
protected def rec
(f : (a : α) → motive (Quotient.mk s a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
(q : Quotient s)
: motive q :=
Quot.rec f h q
@[elabAsElim]
protected abbrev recOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
(h : (a b : α) → (p : a ≈ b) → Eq.ndrec (f a) (Quotient.sound p) = f b)
: motive q :=
Quot.recOn q f h
@[elabAsElim]
protected abbrev recOnSubsingleton
[h : (a : α) → Subsingleton (motive (Quotient.mk s a))]
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
: motive q :=
Quot.recOnSubsingleton (h := h) q f
@[elabAsElim]
protected abbrev hrecOn
(q : Quotient s)
(f : (a : α) → motive (Quotient.mk s a))
(c : (a b : α) → (p : a ≈ b) → HEq (f a) (f b))
: motive q :=
Quot.hrecOn q f c
end
section
universe uA uB uC
variable {α : Sort uA} {β : Sort uB} {φ : Sort uC}
variable {s₁ : Setoid α} {s₂ : Setoid β}
protected abbrev lift₂
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
(q₁ : Quotient s₁) (q₂ : Quotient s₂)
: φ := by
apply Quotient.lift (fun (a₁ : α) => Quotient.lift (f a₁) (fun (a b : β) => c a₁ a a₁ b (Setoid.refl a₁)) q₂) _ q₁
intros
induction q₂ using Quotient.ind
apply c; assumption; apply Setoid.refl
protected abbrev liftOn₂
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(f : α → β → φ)
(c : (a₁ : α) → (b₁ : β) → (a₂ : α) → (b₂ : β) → a₁ ≈ a₂ → b₁ ≈ b₂ → f a₁ b₁ = f a₂ b₂)
: φ :=
Quotient.lift₂ f c q₁ q₂
@[elabAsElim]
protected theorem ind₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(h : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
@[elabAsElim]
protected theorem inductionOn₂
{motive : Quotient s₁ → Quotient s₂ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(h : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
: motive q₁ q₂ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
apply h
@[elabAsElim]
protected theorem inductionOn₃
{s₃ : Setoid φ}
{motive : Quotient s₁ → Quotient s₂ → Quotient s₃ → Prop}
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(q₃ : Quotient s₃)
(h : (a : α) → (b : β) → (c : φ) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b) (Quotient.mk s₃ c))
: motive q₁ q₂ q₃ := by
induction q₁ using Quotient.ind
induction q₂ using Quotient.ind
induction q₃ using Quotient.ind
apply h
end
section Exact
variable {α : Sort u}
private def rel {s : Setoid α} (q₁ q₂ : Quotient s) : Prop :=
Quotient.liftOn₂ q₁ q₂
(fun a₁ a₂ => a₁ ≈ a₂)
(fun _ _ _ _ a₁b₁ a₂b₂ =>
propext (Iff.intro
(fun a₁a₂ => Setoid.trans (Setoid.symm a₁b₁) (Setoid.trans a₁a₂ a₂b₂))
(fun b₁b₂ => Setoid.trans a₁b₁ (Setoid.trans b₁b₂ (Setoid.symm a₂b₂)))))
private theorem rel.refl {s : Setoid α} (q : Quotient s) : rel q q :=
q.inductionOn Setoid.refl
private theorem rel_of_eq {s : Setoid α} {q₁ q₂ : Quotient s} : q₁ = q₂ → rel q₁ q₂ :=
fun h => Eq.ndrecOn h (rel.refl q₁)
theorem exact {s : Setoid α} {a b : α} : Quotient.mk s a = Quotient.mk s b → a ≈ b :=
fun h => rel_of_eq h
end Exact
section
universe uA uB uC
variable {α : Sort uA} {β : Sort uB}
variable {s₁ : Setoid α} {s₂ : Setoid β}
@[elabAsElim]
protected abbrev recOnSubsingleton₂
{motive : Quotient s₁ → Quotient s₂ → Sort uC}
[s : (a : α) → (b : β) → Subsingleton (motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))]
(q₁ : Quotient s₁)
(q₂ : Quotient s₂)
(g : (a : α) → (b : β) → motive (Quotient.mk s₁ a) (Quotient.mk s₂ b))
: motive q₁ q₂ := by
induction q₁ using Quot.recOnSubsingleton
induction q₂ using Quot.recOnSubsingleton
apply g
intro a; apply s
induction q₂ using Quot.recOnSubsingleton
intro a; apply s
infer_instance
end
end Quotient
section
variable {α : Type u}
variable (r : α → α → Prop)
instance {α : Sort u} {s : Setoid α} [d : ∀ (a b : α), Decidable (a ≈ b)] : DecidableEq (Quotient s) :=
fun (q₁ q₂ : Quotient s) =>
Quotient.recOnSubsingleton₂ q₁ q₂
fun a₁ a₂ =>
match d a₁ a₂ with
| isTrue h₁ => isTrue (Quotient.sound h₁)
| isFalse h₂ => isFalse fun h => absurd (Quotient.exact h) h₂
/-! # Function extensionality -/
namespace Function
variable {α : Sort u} {β : α → Sort v}
protected def Equiv (f₁ f₂ : ∀ (x : α), β x) : Prop := ∀ x, f₁ x = f₂ x
protected theorem Equiv.refl (f : ∀ (x : α), β x) : Function.Equiv f f :=
fun _ => rfl
protected theorem Equiv.symm {f₁ f₂ : ∀ (x : α), β x} : Function.Equiv f₁ f₂ → Function.Equiv f₂ f₁ :=
fun h x => Eq.symm (h x)
protected theorem Equiv.trans {f₁ f₂ f₃ : ∀ (x : α), β x} : Function.Equiv f₁ f₂ → Function.Equiv f₂ f₃ → Function.Equiv f₁ f₃ :=
fun h₁ h₂ x => Eq.trans (h₁ x) (h₂ x)
protected theorem Equiv.isEquivalence (α : Sort u) (β : α → Sort v) : Equivalence (@Function.Equiv α β) := {
refl := Equiv.refl
symm := Equiv.symm
trans := Equiv.trans
}
end Function
section
open Quotient
variable {α : Sort u} {β : α → Sort v}
@[instance]
private def funSetoid (α : Sort u) (β : α → Sort v) : Setoid (∀ (x : α), β x) :=
Setoid.mk (@Function.Equiv α β) (Function.Equiv.isEquivalence α β)
private def extfunApp (f : Quotient <| funSetoid α β) (x : α) : β x :=
Quot.liftOn f
(fun (f : ∀ (x : α), β x) => f x)
(fun _ _ h => h x)
theorem funext {f₁ f₂ : ∀ (x : α), β x} (h : ∀ x, f₁ x = f₂ x) : f₁ = f₂ := by
show extfunApp (Quotient.mk' f₁) = extfunApp (Quotient.mk' f₂)
apply congrArg
apply Quotient.sound
exact h
end
instance {α : Sort u} {β : α → Sort v} [∀ a, Subsingleton (β a)] : Subsingleton (∀ a, β a) where
allEq f₁ f₂ :=
funext (fun a => Subsingleton.elim (f₁ a) (f₂ a))
/-! # Squash -/
def Squash (α : Type u) := Quot (fun (_ _ : α) => True)
def Squash.mk {α : Type u} (x : α) : Squash α := Quot.mk _ x
theorem Squash.ind {α : Type u} {motive : Squash α → Prop} (h : ∀ (a : α), motive (Squash.mk a)) : ∀ (q : Squash α), motive q :=
Quot.ind h
@[inline] def Squash.lift {α β} [Subsingleton β] (s : Squash α) (f : α → β) : β :=
Quot.lift f (fun _ _ _ => Subsingleton.elim _ _) s
instance : Subsingleton (Squash α) where
allEq a b := by
induction a using Squash.ind
induction b using Squash.ind
apply Quot.sound
trivial
/-! # Relations -/
class Antisymm {α : Sort u} (r : α → α → Prop) where
antisymm {a b : α} : r a b → r b a → a = b
namespace Lean
/-! # Kernel reduction hints -/
/--
When the kernel tries to reduce a term `Lean.reduceBool c`, it will invoke the Lean interpreter to evaluate `c`.
The kernel will not use the interpreter if `c` is not a constant.
This feature is useful for performing proofs by reflection.
Remark: the Lean frontend allows terms of the from `Lean.reduceBool t` where `t` is a term not containing
free variables. The frontend automatically declares a fresh auxiliary constant `c` and replaces the term with
`Lean.reduceBool c`. The main motivation is that the code for `t` will be pre-compiled.
Warning: by using this feature, the Lean compiler and interpreter become part of your trusted code base.
This is extra 30k lines of code. More importantly, you will probably not be able to check your developement using
external type checkers (e.g., Trepplein) that do not implement this feature.
Keep in mind that if you are using Lean as programming language, you are already trusting the Lean compiler and interpreter.
So, you are mainly losing the capability of type checking your developement using external checkers.
Recall that the compiler trusts the correctness of all `[implementedBy ...]` and `[extern ...]` annotations.
If an extern function is executed, then the trusted code base will also include the implementation of the associated
foreign function.
-/
opaque reduceBool (b : Bool) : Bool := b
/--
Similar to `Lean.reduceBool` for closed `Nat` terms.
Remark: we do not have plans for supporting a generic `reduceValue {α} (a : α) : α := a`.
The main issue is that it is non-trivial to convert an arbitrary runtime object back into a Lean expression.
We believe `Lean.reduceBool` enables most interesting applications (e.g., proof by reflection). -/
opaque reduceNat (n : Nat) : Nat := n
axiom ofReduceBool (a b : Bool) (h : reduceBool a = b) : a = b
axiom ofReduceNat (a b : Nat) (h : reduceNat a = b) : a = b
class IsAssociative {α : Sort u} (op : α → α → α) where
assoc : (a b c : α) → op (op a b) c = op a (op b c)
class IsCommutative {α : Sort u} (op : α → α → α) where
comm : (a b : α) → op a b = op b a
class IsIdempotent {α : Sort u} (op : α → α → α) where
idempotent : (x : α) → op x x = x
class IsNeutral {α : Sort u} (op : α → α → α) (neutral : α) where
left_neutral : (a : α) → op neutral a = a
right_neutral : (a : α) → op a neutral = a
end Lean
|
d85ab07a8101f41ce2b16880d04148db303c8ba8 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/fun.lean | 5f019237377d377644f4070b573e5b8b8b462eae | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 314 | lean | open function bool
constant f : num → bool
constant g : num → num
check f ∘ g ∘ g
check (id : num → num)
constant h : num → bool → num
check swap h
check swap h ff num.zero
check (swap h ff num.zero : num)
constant f1 : num → num → bool
constant f2 : bool → num
check (f1 on f2) ff tt
|
fe45a18eb3362118b7dd8f368e3d152ba524a014 | e030b0259b777fedcdf73dd966f3f1556d392178 | /library/tools/super/superposition.lean | 6782649cb2ee79579c7187ec4e34a8942acd6619 | [
"Apache-2.0"
] | permissive | fgdorais/lean | 17b46a095b70b21fa0790ce74876658dc5faca06 | c3b7c54d7cca7aaa25328f0a5660b6b75fe26055 | refs/heads/master | 1,611,523,590,686 | 1,484,412,902,000 | 1,484,412,902,000 | 38,489,734 | 0 | 0 | null | 1,435,923,380,000 | 1,435,923,379,000 | null | UTF-8 | Lean | false | false | 4,946 | lean | /-
Copyright (c) 2016 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import .clause .prover_state .utils
open tactic monad expr
namespace super
def position := list ℕ
meta def get_rwr_positions : expr → list position
| (app a b) := [[]] ++
do arg ← list.zip_with_index (get_app_args (app a b)),
pos ← get_rwr_positions arg.1,
[arg.2 :: pos]
| (var _) := []
| e := [[]]
meta def get_position : expr → position → expr
| (app a b) (p::ps) :=
match list.nth (get_app_args (app a b)) p with
| some arg := get_position arg ps
| none := (app a b)
end
| e _ := e
meta def replace_position (v : expr) : expr → position → expr
| (app a b) (p::ps) :=
let args := get_app_args (app a b) in
match args^.nth p with
| some arg := app_of_list a^.get_app_fn $ args^.update_nth p $ replace_position arg ps
| none := app a b
end
| e [] := v
| e _ := e
variable gt : expr → expr → bool
variables (c1 c2 : clause)
variables (ac1 ac2 : derived_clause)
variables (i1 i2 : nat)
variable pos : list ℕ
variable ltr : bool
variable lt_in_termorder : bool
variable congr_ax : name
lemma {u v w} sup_ltr (F : Type u) (A : Type v) (a1 a2) (f : A → Type w) : (f a1 → F) → f a2 → a1 = a2 → F :=
take hnfa1 hfa2 heq, hnfa1 (@eq.rec A a2 f hfa2 a1 heq^.symm)
lemma {u v w} sup_rtl (F : Type u) (A : Type v) (a1 a2) (f : A → Type w) : (f a1 → F) → f a2 → a2 = a1 → F :=
take hnfa1 hfa2 heq, hnfa1 (@eq.rec A a2 f hfa2 a1 heq)
meta def is_eq_dir (e : expr) (ltr : bool) : option (expr × expr) :=
match is_eq e with
| some (lhs, rhs) := if ltr then some (lhs, rhs) else some (rhs, lhs)
| none := none
end
meta def try_sup : tactic clause := do
guard $ (c1^.get_lit i1)^.is_pos,
qf1 ← c1^.open_metan c1^.num_quants,
qf2 ← c2^.open_metan c2^.num_quants,
(rwr_from, rwr_to) ← (is_eq_dir (qf1.1^.get_lit i1)^.formula ltr)^.to_monad,
atom ← return (qf2.1^.get_lit i2)^.formula,
eq_type ← infer_type rwr_from,
atom_at_pos ← return $ get_position atom pos,
atom_at_pos_type ← infer_type atom_at_pos,
unify eq_type atom_at_pos_type,
unify_core transparency.none rwr_from atom_at_pos,
rwr_from' ← instantiate_mvars atom_at_pos,
rwr_to' ← instantiate_mvars rwr_to,
if lt_in_termorder
then guard (gt rwr_from' rwr_to')
else guard (¬gt rwr_to' rwr_from'),
rwr_ctx_varn ← mk_fresh_name,
abs_rwr_ctx ← return $
lam rwr_ctx_varn binder_info.default eq_type
(if (qf2.1^.get_lit i2)^.is_neg
then replace_position (mk_var 0) atom pos
else imp (replace_position (mk_var 0) atom pos) c2^.local_false),
lf_univ ← infer_univ c1^.local_false,
univ ← infer_univ eq_type,
atom_univ ← infer_univ atom,
op1 ← qf1.1^.open_constn i1,
op2 ← qf2.1^.open_constn c2^.num_lits,
hi2 ← (op2.2^.nth i2)^.to_monad,
new_atom ← whnf_core transparency.none $ app abs_rwr_ctx rwr_to',
new_hi2 ← return $ local_const hi2^.local_uniq_name `H binder_info.default new_atom,
new_fin_prf ←
return $ app_of_list (const congr_ax [lf_univ, univ, atom_univ]) [c1^.local_false, eq_type, rwr_from, rwr_to,
abs_rwr_ctx, (op2.1^.close_const hi2)^.proof, new_hi2],
clause.meta_closure (qf1.2 ++ qf2.2) $ (op1.1^.inst new_fin_prf)^.close_constn (op1.2 ++ op2.2^.update_nth i2 new_hi2)
meta def rwr_positions (c : clause) (i : nat) : list (list ℕ) :=
get_rwr_positions (c^.get_lit i)^.formula
meta def try_add_sup : prover unit :=
(do c' ← try_sup gt ac1^.c ac2^.c i1 i2 pos ltr ff congr_ax,
inf_score 2 [ac1^.sc, ac2^.sc] >>= mk_derived c' >>= add_inferred)
<|> return ()
meta def superposition_back_inf : inference :=
take given, do active ← get_active, sequence' $ do
given_i ← given^.selected,
guard (given^.c^.get_lit given_i)^.is_pos,
option.to_monad $ is_eq (given^.c^.get_lit given_i)^.formula,
other ← rb_map.values active,
guard $ ¬given^.sc^.in_sos ∨ ¬other^.sc^.in_sos,
other_i ← other^.selected,
pos ← rwr_positions other^.c other_i,
-- FIXME(gabriel): ``sup_ltr fails to resolve at runtime
[do try_add_sup gt given other given_i other_i pos tt ``super.sup_ltr,
try_add_sup gt given other given_i other_i pos ff ``super.sup_rtl]
meta def superposition_fwd_inf : inference :=
take given, do active ← get_active, sequence' $ do
given_i ← given^.selected,
other ← rb_map.values active,
guard $ ¬given^.sc^.in_sos ∨ ¬other^.sc^.in_sos,
other_i ← other^.selected,
guard (other^.c^.get_lit other_i)^.is_pos,
option.to_monad $ is_eq (other^.c^.get_lit other_i)^.formula,
pos ← rwr_positions given^.c given_i,
[do try_add_sup gt other given other_i given_i pos tt ``super.sup_ltr,
try_add_sup gt other given other_i given_i pos ff ``super.sup_rtl]
@[super.inf]
meta def superposition_inf : inf_decl := inf_decl.mk 40 $
take given, do gt ← get_term_order,
superposition_fwd_inf gt given,
superposition_back_inf gt given
end super
|
2baebe23ed5d05014b872ad6911953c7da5ac646 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/order/field/inj_surj.lean | dcdde29d91008db6315911d552bba96c220a2d82 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 2,976 | lean | /-
Copyright (c) 2014 Robert Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn
-/
import algebra.order.field.defs
import algebra.field.basic
import algebra.order.ring.inj_surj
/-!
# Pulling back linearly ordered fields along injective maps.
-/
open function order_dual
variables {ι α β : Type*}
namespace function
/-- Pullback a `linear_ordered_semifield` under an injective map. -/
@[reducible] -- See note [reducible non-instances]
def injective.linear_ordered_semifield [linear_ordered_semifield α] [has_zero β] [has_one β]
[has_add β] [has_mul β] [has_pow β ℕ] [has_smul ℕ β] [has_nat_cast β] [has_inv β] [has_div β]
[has_pow β ℤ] [has_sup β] [has_inf β] (f : β → α) (hf : injective f) (zero : f 0 = 0)
(one : f 1 = 1) (add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x)
(npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n)
(nat_cast : ∀ n : ℕ, f n = n) (hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y))
(hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
linear_ordered_semifield β :=
{ ..hf.linear_ordered_semiring f zero one add mul nsmul npow nat_cast hsup hinf,
..hf.semifield f zero one add mul inv div nsmul npow zpow nat_cast }
/-- Pullback a `linear_ordered_field` under an injective map. -/
@[reducible] -- See note [reducible non-instances]
def injective.linear_ordered_field [linear_ordered_field α] [has_zero β] [has_one β] [has_add β]
[has_mul β] [has_neg β] [has_sub β] [has_pow β ℕ] [has_smul ℕ β] [has_smul ℤ β] [has_smul ℚ β]
[has_nat_cast β] [has_int_cast β] [has_rat_cast β] [has_inv β] [has_div β] [has_pow β ℤ]
[has_sup β] [has_inf β]
(f : β → α) (hf : injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y)
(inv : ∀ x, f (x⁻¹) = (f x)⁻¹) (div : ∀ x y, f (x / y) = f x / f y)
(nsmul : ∀ x (n : ℕ), f (n • x) = n • f x) (zsmul : ∀ x (n : ℤ), f (n • x) = n • f x)
(qsmul : ∀ x (n : ℚ), f (n • x) = n • f x)
(npow : ∀ x (n : ℕ), f (x ^ n) = f x ^ n) (zpow : ∀ x (n : ℤ), f (x ^ n) = f x ^ n)
(nat_cast : ∀ n : ℕ, f n = n) (int_cast : ∀ n : ℤ, f n = n) (rat_cast : ∀ n : ℚ, f n = n)
(hsup : ∀ x y, f (x ⊔ y) = max (f x) (f y)) (hinf : ∀ x y, f (x ⊓ y) = min (f x) (f y)) :
linear_ordered_field β :=
{ .. hf.linear_ordered_ring f zero one add mul neg sub nsmul zsmul npow nat_cast int_cast hsup hinf,
.. hf.field f zero one add mul neg sub inv div nsmul zsmul qsmul npow zpow nat_cast int_cast
rat_cast }
end function
|
ac2d961220c8e883cc7aa5490b183e834d6ccfd5 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/501.lean | c2e68857b3d5a7702d4b464b60b2af1608bd621b | [
"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 | 575 | lean | structure S where
x : Bool
y : Nat
def S.Z (s : S) : Type :=
if s.x then Nat else Int
def S.z : (s : S) → s.Z
| s@{ x := true, .. } => s.y
| s@{ x := false, .. } => Int.ofNat s.y
def S.a : (s : S) → s.Z
| s => s.z
def S.b : (s : S) → s.Z
| s@h:{ x := true, .. } => h ▸ s.z
| s => s.z
#check @S.b.match_1
theorem zeropow : ∀ {m : Nat}, m > 0 → 0 ^ m = 0
| 0, h => by cases h
| _+1, _ => rfl
theorem pow_nonneg : ∀ m : Nat, 0 ^ m ≥ 0
| 0 => by decide
| m@(_+1) => by
rw [zeropow]
· decide
· apply Nat.zero_lt_succ
|
afed8c903cc2ecf085d4a6bb500f5426981f84c3 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/vars_anywhere.lean | 6c80908a8343c79db1d7a71e62b723e3dab1aadb | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 110 | lean | variable {A : Type}
check @id
inductive list :=
| nil : list
| cons : A → list → list
check @list.cons
|
4091a8edf2237247776c59643c3f233262568d94 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/special_functions/sqrt.lean | 7cf611587351fef69f74942346f8307a404955ab | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 6,432 | lean | /-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import data.real.sqrt
import analysis.calculus.inverse
/-!
# Smoothness of `real.sqrt`
In this file we prove that `real.sqrt` is infinitely smooth at all points `x ≠ 0` and provide some
dot-notation lemmas.
## Tags
sqrt, differentiable
-/
open set
open_locale topological_space
namespace real
/-- Local homeomorph between `(0, +∞)` and `(0, +∞)` with `to_fun = λ x, x ^ 2` and
`inv_fun = sqrt`. -/
noncomputable def sq_local_homeomorph : local_homeomorph ℝ ℝ :=
{ to_fun := λ x, x ^ 2,
inv_fun := sqrt,
source := Ioi 0,
target := Ioi 0,
map_source' := λ x hx, mem_Ioi.2 (pow_pos hx _),
map_target' := λ x hx, mem_Ioi.2 (sqrt_pos.2 hx),
left_inv' := λ x hx, sqrt_sq (le_of_lt hx),
right_inv' := λ x hx, sq_sqrt (le_of_lt hx),
open_source := is_open_Ioi,
open_target := is_open_Ioi,
continuous_to_fun := (continuous_pow 2).continuous_on,
continuous_inv_fun := continuous_on_id.sqrt }
lemma deriv_sqrt_aux {x : ℝ} (hx : x ≠ 0) :
has_strict_deriv_at sqrt (1 / (2 * sqrt x)) x ∧ ∀ n, times_cont_diff_at ℝ n sqrt x :=
begin
cases hx.lt_or_lt with hx hx,
{ rw [sqrt_eq_zero_of_nonpos hx.le, mul_zero, div_zero],
have : sqrt =ᶠ[𝓝 x] (λ _, 0) := (gt_mem_nhds hx).mono (λ x hx, sqrt_eq_zero_of_nonpos hx.le),
exact ⟨(has_strict_deriv_at_const x (0 : ℝ)).congr_of_eventually_eq this.symm,
λ n, times_cont_diff_at_const.congr_of_eventually_eq this⟩ },
{ have : ↑2 * sqrt x ^ (2 - 1) ≠ 0, by simp [(sqrt_pos.2 hx).ne', @two_ne_zero ℝ],
split,
{ simpa using sq_local_homeomorph.has_strict_deriv_at_symm hx this
(has_strict_deriv_at_pow 2 _) },
{ exact λ n, sq_local_homeomorph.times_cont_diff_at_symm_deriv this hx
(has_deriv_at_pow 2 (sqrt x)) (times_cont_diff_at_id.pow 2) } }
end
lemma has_strict_deriv_at_sqrt {x : ℝ} (hx : x ≠ 0) :
has_strict_deriv_at sqrt (1 / (2 * sqrt x)) x :=
(deriv_sqrt_aux hx).1
lemma times_cont_diff_at_sqrt {x : ℝ} {n : with_top ℕ} (hx : x ≠ 0) :
times_cont_diff_at ℝ n sqrt x :=
(deriv_sqrt_aux hx).2 n
lemma has_deriv_at_sqrt {x : ℝ} (hx : x ≠ 0) : has_deriv_at sqrt (1 / (2 * sqrt x)) x :=
(has_strict_deriv_at_sqrt hx).has_deriv_at
end real
open real
section deriv
variables {f : ℝ → ℝ} {s : set ℝ} {f' x : ℝ}
lemma has_deriv_within_at.sqrt (hf : has_deriv_within_at f f' s x) (hx : f x ≠ 0) :
has_deriv_within_at (λ y, sqrt (f y)) (f' / (2 * sqrt (f x))) s x :=
by simpa only [(∘), div_eq_inv_mul, mul_one]
using (has_deriv_at_sqrt hx).comp_has_deriv_within_at x hf
lemma has_deriv_at.sqrt (hf : has_deriv_at f f' x) (hx : f x ≠ 0) :
has_deriv_at (λ y, sqrt (f y)) (f' / (2 * sqrt(f x))) x :=
by simpa only [(∘), div_eq_inv_mul, mul_one] using (has_deriv_at_sqrt hx).comp x hf
lemma has_strict_deriv_at.sqrt (hf : has_strict_deriv_at f f' x) (hx : f x ≠ 0) :
has_strict_deriv_at (λ t, sqrt (f t)) (f' / (2 * sqrt (f x))) x :=
by simpa only [(∘), div_eq_inv_mul, mul_one] using (has_strict_deriv_at_sqrt hx).comp x hf
lemma deriv_within_sqrt (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, sqrt (f x)) s x = (deriv_within f s x) / (2 * sqrt (f x)) :=
(hf.has_deriv_within_at.sqrt hx).deriv_within hxs
@[simp] lemma deriv_sqrt (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
deriv (λx, sqrt (f x)) x = (deriv f x) / (2 * sqrt (f x)) :=
(hf.has_deriv_at.sqrt hx).deriv
end deriv
section fderiv
variables {E : Type*} [normed_group E] [normed_space ℝ E] {f : E → ℝ} {n : with_top ℕ}
{s : set E} {x : E} {f' : E →L[ℝ] ℝ}
lemma has_fderiv_at.sqrt (hf : has_fderiv_at f f' x) (hx : f x ≠ 0) :
has_fderiv_at (λ y, sqrt (f y)) ((1 / (2 * sqrt (f x))) • f') x :=
(has_deriv_at_sqrt hx).comp_has_fderiv_at x hf
lemma has_strict_fderiv_at.sqrt (hf : has_strict_fderiv_at f f' x) (hx : f x ≠ 0) :
has_strict_fderiv_at (λ y, sqrt (f y)) ((1 / (2 * sqrt (f x))) • f') x :=
(has_strict_deriv_at_sqrt hx).comp_has_strict_fderiv_at x hf
lemma has_fderiv_within_at.sqrt (hf : has_fderiv_within_at f f' s x) (hx : f x ≠ 0) :
has_fderiv_within_at (λ y, sqrt (f y)) ((1 / (2 * sqrt (f x))) • f') s x :=
(has_deriv_at_sqrt hx).comp_has_fderiv_within_at x hf
lemma differentiable_within_at.sqrt (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) :
differentiable_within_at ℝ (λ y, sqrt (f y)) s x :=
(hf.has_fderiv_within_at.sqrt hx).differentiable_within_at
lemma differentiable_at.sqrt (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
differentiable_at ℝ (λ y, sqrt (f y)) x :=
(hf.has_fderiv_at.sqrt hx).differentiable_at
lemma differentiable_on.sqrt (hf : differentiable_on ℝ f s) (hs : ∀ x ∈ s, f x ≠ 0) :
differentiable_on ℝ (λ y, sqrt (f y)) s :=
λ x hx, (hf x hx).sqrt (hs x hx)
lemma differentiable.sqrt (hf : differentiable ℝ f) (hs : ∀ x, f x ≠ 0) :
differentiable ℝ (λ y, sqrt (f y)) :=
λ x, (hf x).sqrt (hs x)
lemma fderiv_within_sqrt (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0)
(hxs : unique_diff_within_at ℝ s x) :
fderiv_within ℝ (λx, sqrt (f x)) s x = (1 / (2 * sqrt (f x))) • fderiv_within ℝ f s x :=
(hf.has_fderiv_within_at.sqrt hx).fderiv_within hxs
@[simp] lemma fderiv_sqrt (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
fderiv ℝ (λx, sqrt (f x)) x = (1 / (2 * sqrt (f x))) • fderiv ℝ f x :=
(hf.has_fderiv_at.sqrt hx).fderiv
lemma times_cont_diff_at.sqrt (hf : times_cont_diff_at ℝ n f x) (hx : f x ≠ 0) :
times_cont_diff_at ℝ n (λ y, sqrt (f y)) x :=
(times_cont_diff_at_sqrt hx).comp x hf
lemma times_cont_diff_within_at.sqrt (hf : times_cont_diff_within_at ℝ n f s x) (hx : f x ≠ 0) :
times_cont_diff_within_at ℝ n (λ y, sqrt (f y)) s x :=
(times_cont_diff_at_sqrt hx).comp_times_cont_diff_within_at x hf
lemma times_cont_diff_on.sqrt (hf : times_cont_diff_on ℝ n f s) (hs : ∀ x ∈ s, f x ≠ 0) :
times_cont_diff_on ℝ n (λ y, sqrt (f y)) s :=
λ x hx, (hf x hx).sqrt (hs x hx)
lemma times_cont_diff.sqrt (hf : times_cont_diff ℝ n f) (h : ∀ x, f x ≠ 0) :
times_cont_diff ℝ n (λ y, sqrt (f y)) :=
times_cont_diff_iff_times_cont_diff_at.2 $ λ x, (hf.times_cont_diff_at.sqrt (h x))
end fderiv
|
883a8a13a6894cc46d8b0d1490f0733d43121eb0 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /08_Building_Theories_and_Proofs.org.32.lean | f02e43a4f5c42c7764c381d3239ccb5514290aea | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 77 | lean | import standard
import data.nat
section
open [notations] nat
/- ... -/
end
|
3009bcef37284791eeb32af58127b8f2ed679bb2 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/number_theory/pell.lean | afcb6b13660a4792da47c7ac8bf0bcb4cffc2dd8 | [
"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 | 37,771 | 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
import number_theory.zsqrtd.basic
/-!
# Pell's equation and Matiyasevic's theorem
This file solves Pell's equation, i.e. integer solutions to `x ^ 2 - d * y ^ 2 = 1` in the special
case that `d = a ^ 2 - 1`. This is then applied to prove Matiyasevic's theorem that the power
function is Diophantine, which is the last key ingredient in the solution to Hilbert's tenth
problem. For the definition of Diophantine function, see `dioph.lean`.
## Main definition
* `pell` is a function assigning to a natural number `n` the `n`-th solution to Pell's equation
constructed recursively from the initial solution `(0, 1)`.
## Main statements
* `eq_pell` shows that every solution to Pell's equation is recursively obtained using `pell`
* `matiyasevic` shows that a certain system of Diophantine equations has a solution if and only if
the first variable is the `x`-component in a solution to Pell's equation - the key step towards
Hilbert's tenth problem in Davis' version of Matiyasevic's theorem.
* `eq_pow_of_pell` shows that the power function is Diophantine.
## Implementation notes
The proof of Matiyasevic's theorem doesn't follow Matiyasevic's original account of using Fibonacci
numbers but instead Davis' variant of using solutions to Pell's equation.
## References
* [M. Carneiro, _A Lean formalization of Matiyasevič's theorem_][carneiro2018matiyasevic]
* [M. Davis, _Hilbert's tenth problem is unsolvable_][MR317916]
## Tags
Pell's equation, Matiyasevic's theorem, Hilbert's tenth problem
## TODO
* Provide solutions to Pell's equation for the case of arbitrary `d` (not just `d = a ^ 2 - 1` like
in the current version) and furthermore also for `x ^ 2 - d * y ^ 2 = -1`.
* Connect solutions to the continued fraction expansion of `√d`.
-/
namespace pell
open nat
section
parameters {a : ℕ} (a1 : 1 < a)
include a1
private def d := a*a - 1
@[simp] theorem d_pos : 0 < d :=
tsub_pos_of_lt (mul_lt_mul a1 (le_of_lt a1) dec_trivial dec_trivial : 1*1<a*a)
/-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
-- TODO(lint): Fix double namespace issue
@[nolint dup_namespace] 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
/-- The Pell `x` sequence, considered as an integer sequence.-/
def xz (n : ℕ) : ℤ := xn n
/-- The Pell `y` sequence, considered as an integer sequence.-/
def yz (n : ℕ) : ℤ := yn n
section
omit a1
/-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer.-/
def az : ℤ := a
end
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]; ring_nf
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]; ring
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 ring_nf at this ⊢; assumption),
ne_of_gt d_pos $ by rwa nat.eq_zero_of_le_zero ((nat.le_add_left _ _).trans this) at h⟩
theorem xn_ge_a_pow : ∀ (n : ℕ), a^n ≤ xn n
| 0 := le_refl 1
| (n+1) := by simp [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 [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) : 0 < xn n :=
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 → b ≤ pell_zd n → ∃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 : (⟨↑a, 1⟩ : ℤ√d) ≤ b 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 _)
/-- Every solution to **Pell's equation** is recursively obtained from the initial solution
`(1,0)` using the recursion `pell`. -/
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 zero_tsub 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 [add_tsub_cancel_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 kp 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)
(kx.mul_left _) (ky.mul_left _)
theorem strict_mono_y : strict_mono yn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (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 $ strict_mono_y 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 strict_mono_x : strict_mono xn
| m 0 h := absurd h $ nat.not_lt_zero _
| m (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 $ strict_mono_x 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) (strict_mono_y $ 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 _ _) ((y_mul_dvd k).mul_right _)
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 : 0 < m, from m.eq_zero_or_pos.resolve_left $
λe, by rw [e, nat.mod_zero] at hp; rw [e] at h; exact
ne_of_lt (strict_mono_y 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 (strict_mono_y _ $ nat.mod_lt n m0)
(nat.le_of_dvd (strict_mono_y _ hp) $ co.dvd_of_dvd_mul_right $
(nat.dvd_add_iff_right $ (y_mul_dvd _ _ _).mul_left _).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
(hx.mul_right _ ).add $ modeq_zero_iff_dvd.2 $
by rw pow_succ'; exact
mul_dvd_mul_right (dvd_mul_of_dvd_right (modeq_zero_iff_dvd.1 $
(hy.modeq_of_dvd $ by simp [pow_succ']).trans $ modeq_zero_iff_dvd.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.add (by { rw pow_succ', exact hx.mul_right' _ }) $
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 [pow_succ', mul_comm, mul_left_comm],
by { rw ← this, exact hy.mul_right _ },
by { rw [add_tsub_cancel_right, nat.mul_succ, xn_add, yn_add, 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_zero_iff_dvd.1 $
((xy_modeq_yn n (yn n)).right.modeq_of_dvd $ by simp [pow_succ]).trans
(modeq_zero_iff_dvd.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 rwa n0 at ⊢ nt) $ λ (n0l : 0 < n),
let ⟨k, ke⟩ := nt in
have yn n ∣ k * (xn n)^(k-1), from
nat.dvd_of_mul_dvd_mul_right (strict_mono_y n0l) $ modeq_zero_iff_dvd.1 $
by have xm := (xy_modeq_yn a1 n k).right; rw ← ke at xm; exact
(xm.modeq_of_dvd $ by simp [pow_succ]).symm.trans h.modeq_zero_nat,
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, dsimp [az], rw zsqrtd.ext, dsimp, split; ring },
by simpa [mul_add, mul_comm, mul_left_comm, add_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) := (yn_modeq_a_sub_one n).add_right_cancel $
begin
rw [yn_succ_succ, (by ring : n + 2 + n = 2 * (n + 1))],
exact ((modeq_sub a1.le).mul_left 2).mul (yn_modeq_a_sub_one (n+1)),
end
theorem yn_modeq_two : ∀ n, yn n ≡ n [MOD 2]
| 0 := by simp
| 1 := by simp
| (n+2) := (yn_modeq_two n).add_right_cancel $
begin
rw [yn_succ_succ, mul_assoc, (by ring : n + 2 + n = 2 * (n + 1))],
exact (dvd_mul_right 2 _).modeq_zero_nat.trans (dvd_mul_right 2 _).zero_modeq_nat,
end
section
omit a1
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
end
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 [pow_succ, mul_add, int.coe_nat_mul,
show ((2:ℕ):ℤ) = 2, from rfl, mul_comm, mul_left_comm], ring }⟩,
by { rw [xz_succ_succ, yz_succ_succ, x_sub_y_dvd_pow_lem ↑(y^(n+2)) ↑(y^(n+1)) ↑(y^n)],
exact
dvd_sub (dvd_add this $ (x_sub_y_dvd_pow (n+1)).mul_left _) (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] :=
begin
rw [two_mul, add_assoc, xn_add, add_assoc, ←zero_add 0],
refine (dvd_mul_right (xn a1 n) (xn a1 (n + j))).modeq_zero_nat.add _,
rw [yn_add, left_distrib, add_assoc, ←zero_add 0],
exact ((dvd_mul_right _ _).mul_left _).modeq_zero_nat.add
(xn_modeq_x2n_add_lem _ _ _).modeq_zero_nat,
end
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_right _ _).mul_left _),
begin
rw [two_mul, add_tsub_assoc_of_le h, xn_add, add_assoc, ←zero_add 0],
exact (dvd_mul_right _ _).modeq_zero_nat.add
(int.coe_nat_dvd.1 $ by simpa [xz, yz] using h1).modeq_zero_nat,
end
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 [tsub_add_cancel_of_le 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 [tsub_tsub_cancel_of_le h, add_comm] at t)
theorem xn_modeq_x4n_add (n j) : xn (4 * n + j) ≡ xn j [MOD xn n] :=
modeq.add_right_cancel' (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.add_right_cancel' (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, add_tsub_assoc_of_le 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 (strict_mono_x _ (nat.lt_of_succ_lt jn)),
nat.mod_eq_of_lt (strict_mono_x _ jn)];
exact strict_mono_x _ (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) (strict_mono_y a1 np))) h,
by cases this; simp at h; exact ⟨h.symm, rfl⟩
theorem eq_of_xn_modeq_lem3 {i n} (npos : 0 < n) :
Π {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 tsub_add_cancel_of_le, 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 $ strict_mono_x 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.add_right_cancel' (xn a1 (2 * n - k)),
rw [tsub_add_cancel_of_le xle],
have t := xn_modeq_x2n_sub_lem a1 k2nl.le,
rw tsub_tsub_cancel_of_le k2n at t,
exact t.trans dvd_rfl.zero_modeq_nat },
(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, tsub_add_eq_tsub_tsub, add_tsub_cancel_right]],
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 (strict_mono_x _ 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 [tsub_add_cancel_of_le (succ_le_of_lt 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, { 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 (strict_mono_x 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 rwa [tsub_add_cancel_of_le (succ_le_of_lt npos)]) in
have n1 : n = 1, from le_antisymm (tsub_eq_zero_iff_le.mp s1) npos,
by rw [ile, a2, n1]; exact ⟨rfl, rfl, rfl, rfl⟩ } },
{ rw [ein, nat.mod_self, add_zero],
exact strict_mono_x _ (nat.pred_lt npos.ne') } })
(λ (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 $ strict_mono_x _ _) _,
rw [nat.sub_succ],
exact nat.pred_lt (ne_of_gt $ tsub_pos_of_lt j2n) })
theorem eq_of_xn_modeq_le {i j n} (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 :=
if npos : n = 0 then by simp [*] at * else
(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 : 0 < xn a1 0 % xn a1 n :=
by rw [nat.mod_eq_of_lt (strict_mono_x a1 (nat.pos_of_ne_zero npos))]; exact dec_trivial,
cases i with i, exact x0,
rw jn at ij',
exact x0.trans (eq_of_xn_modeq_lem3 _ (nat.pos_of_ne_zero 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 (nat.pos_of_ne_zero npos) ij' j2n jn ntriv) h
theorem eq_of_xn_modeq {i j n} (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 ij j2n h $ λ⟨a2, n1, i0, j2⟩, (ntriv a2 n1).left i0 j2)
(λij, (eq_of_xn_modeq_le ij i2n h.symm $ λ⟨a2, n1, j0, i2⟩,
(ntriv a2 n1).right i2 j0).symm)
theorem eq_of_xn_modeq' {i j n} (ipos : 0 < i) (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,
(le_or_gt j (2 * n)).imp
(λj2n : j ≤ 2 * n, eq_of_xn_modeq 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 : 2 * n < j, suffices i = 4*n - j, by rw [this, add_tsub_cancel_of_le j4n],
have j42n : 4*n - j ≤ 2*n, from @nat.le_of_add_le_add_right j _ _ $
by rw [tsub_add_cancel_of_le 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 i2n j42n
(h.symm.trans $ let t := xn_modeq_x4n_sub j42n in by rwa [tsub_tsub_cancel_of_le 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 : 0 < i) (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 : 0 < 4 * n, from mul_pos dec_trivial (ipos.trans_le 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 (xn_modeq_x4n_add _ _ _).trans IH
end,
or.imp
(λ(ji : j' = i), by rwa ← ji)
(λ(ji : j' + i = 4 * n), (jj.add_right _).trans $
by { rw ji, exact dvd_rfl.modeq_zero_nat })
(eq_of_xn_modeq' ipos hin jl.le $
(h.symm.trans $ by { rw ← nat.mod_add_div j (4*n), exact this j' _ }).symm)
end
theorem xy_modeq_of_modeq {a b c} (a1 : 1 < a) (b1 : 1 < b) (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) := ⟨
(xy_modeq_of_modeq n).left.add_right_cancel $
by { rw [xn_succ_succ a1, xn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).left },
(xy_modeq_of_modeq n).right.add_right_cancel $
by { rw [yn_succ_succ a1, yn_succ_succ b1], exact
(h.mul_left _ ).mul (xy_modeq_of_modeq (n+1)).right }⟩
theorem matiyasevic {a k x y} : (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔
1 < a ∧ 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 ∧
1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧
0 < v ∧ 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_rfl, 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 (ysq_dvd_yy a1 k).trans $ (y_dvd_iff _ _ _).2 $ dvd_mul_left _ _,
have uco : nat.coprime u (4 * y), from
have 2 ∣ v, from modeq_zero_iff_dvd.1 $ (yn_modeq_two _ _).trans
(dvd_mul_right _ _).modeq_zero_nat,
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⟩ := chinese_remainder uco a 1 in
have m1 : 1 < m, from
have 0 < k * y, from mul_pos kpos (strict_mono_y a1 kpos),
nat.mul_le_mul_left 2 this,
have vp : 0 < v, from strict_mono_y a1 (lt_trans zero_lt_one m1),
have b1 : 1 < b, from
have xn a1 1 < u, from strict_mono_x a1 m1,
have a < u, 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 bm1.symm.dvd,
(yn_modeq_a_sub_one _ _).modeq_of_dvd this,
⟨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 : 0 < yn a1 n),
(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)) (strict_mono_y 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 bm1.symm.dvd,
((yn_modeq_a_sub_one b1 _).modeq_of_dvd this).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 (strict_mono_y 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_zero_iff_dvd.1 $ (jk.symm.add_right i).trans $
ji.modeq_of_dvd yd,
by have : i % (4 * yn a1 i) = k % (4 * yn a1 i) :=
(ji.modeq_of_dvd yd).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 : 0 < y) : 0 < k → y^k < a →
(↑(y^k) : ℤ) < 2*a*y - y*y - 1 :=
have y < a → a + (y*y + 1) ≤ 2*a*y, 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 : y + nat.succ y ≤ 2 * a,
{ 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,
convert this using 1,
ring }
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 ∨ 0 < k ∧
(n = 0 ∧ m = 0 ∨ 0 < n ∧
∃ (w a t z : ℕ) (a1 : 1 < a),
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, zero_pow kpos]; exact or.inl ⟨rfl, rfl⟩)
(λnpos, or.inr ⟨npos, _⟩); exact
let w := max n k in
have nw : n ≤ w, from le_max_left _ _,
have kw : k ≤ w, from le_max_right _ _,
have wpos : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 1, from nat.succ_lt_succ wpos,
let a := xn w1 w in
have a1 : 1 < a, from strict_mono_x w1 wpos,
let x := xn a1 k, y := yn a1 k in
let ⟨z, ze⟩ := show w ∣ yn w1 w, from modeq_zero_iff_dvd.1 $
(yn_modeq_a_sub_one w1 w).trans dvd_rfl.modeq_zero_nat 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 _) nt.le in
have na : n ≤ a, from nw.trans $ le_of_lt $ n_lt_xn w1 w,
have tm : x ≡ y * (a - n) + n^k [MOD t], begin
apply 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, zero_pow kpos]
| or.inr ⟨kpos, or.inr ⟨npos, w, a, t, z,
(a1 : 1 < a),
(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 : 0 < w, from lt_of_lt_of_le npos nw,
have w1 : 1 < w + 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 : 0 < j, 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_zero_iff_dvd.1 $
(yn_modeq_a_sub_one w1 j).symm.trans $
modeq_zero_iff_dvd.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_of_dvd this,
have n^k % t = m % t, from
(this.symm.trans tm).add_left_cancel' _,
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
|
befc93b9942065f3b46b1a555529d602c2918229 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/algebra/algebra/tower.lean | d2de541f23ddd1145e48d67434c7720f85e5461d | [] | 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 | 11,983 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.algebra.subalgebra
import Mathlib.PostPort
universes u v₁ w v u₁ u_1 u_2 u_3
namespace Mathlib
/-!
# Towers of algebras
In this file we prove basic facts about towers of algebra.
An algebra tower A/S/R is expressed by having instances of `algebra A S`,
`algebra R S`, `algebra R A` and `is_scalar_tower R S A`, the later asserting the
compatibility condition `(r • s) • a = r • (s • a)`.
An important definition is `to_alg_hom R S A`, the canonical `R`-algebra homomorphism `S →ₐ[R] A`.
-/
namespace algebra
/-- The `R`-algebra morphism `A → End (M)` corresponding to the representation of the algebra `A`
on the `R`-module `M`. -/
def lsmul (R : Type u) {A : Type w} (M : Type v₁) [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M] [semimodule R M] [semimodule A M] [is_scalar_tower R A M] : alg_hom R A (module.End R M) :=
alg_hom.mk
(linear_map.to_fun
((fun (this : linear_map R A (linear_map R M M)) => this)
(linear_map.mk₂ R has_scalar.smul sorry sorry sorry sorry)))
sorry sorry sorry sorry sorry
@[simp] theorem lsmul_coe (R : Type u) {A : Type w} (M : Type v₁) [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M] [semimodule R M] [semimodule A M] [is_scalar_tower R A M] (a : A) : ⇑(coe_fn (lsmul R M) a) = has_scalar.smul a :=
rfl
end algebra
namespace is_scalar_tower
theorem algebra_map_smul {R : Type u} (A : Type w) {M : Type v₁} [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M] [semimodule R M] [semimodule A M] [is_scalar_tower R A M] (r : R) (x : M) : coe_fn (algebra_map R A) r • x = r • x :=
eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn (algebra_map R A) r • x = r • x)) (algebra.algebra_map_eq_smul_one r)))
(eq.mpr (id (Eq._oldrec (Eq.refl ((r • 1) • x = r • x)) (smul_assoc r 1 x)))
(eq.mpr (id (Eq._oldrec (Eq.refl (r • 1 • x = r • x)) (one_smul A x))) (Eq.refl (r • x))))
theorem of_algebra_map_eq {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] (h : ∀ (x : R), coe_fn (algebra_map R A) x = coe_fn (algebra_map S A) (coe_fn (algebra_map R S) x)) : is_scalar_tower R S A := sorry
/-- See note [partially-applied ext lemmas]. -/
theorem of_algebra_map_eq' {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] (h : algebra_map R A = ring_hom.comp (algebra_map S A) (algebra_map R S)) : is_scalar_tower R S A :=
of_algebra_map_eq (iff.mp ring_hom.ext_iff h)
protected instance subalgebra (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] (S₀ : subalgebra R S) : is_scalar_tower (↥S₀) S A :=
of_algebra_map_eq fun (x : ↥S₀) => rfl
theorem algebra_map_eq (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : algebra_map R A = ring_hom.comp (algebra_map S A) (algebra_map R S) := sorry
theorem algebra_map_apply (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (x : R) : coe_fn (algebra_map R A) x = coe_fn (algebra_map S A) (coe_fn (algebra_map R S) x) := sorry
protected instance subalgebra' (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (S₀ : subalgebra R S) : is_scalar_tower R (↥S₀) A :=
of_algebra_map_eq fun (_x : R) => algebra_map_apply R S A _x
theorem algebra.ext {S : Type u} {A : Type v} [comm_semiring S] [semiring A] (h1 : algebra S A) (h2 : algebra S A) (h : ∀ {r : S} {x : A}, r • x = r • x) : h1 = h2 := sorry
theorem algebra_comap_eq (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : algebra.comap.algebra R S A = _inst_8 := sorry
/-- In a tower, the canonical map from the middle element to the top element is an
algebra homomorphism over the bottom element. -/
def to_alg_hom (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : alg_hom R S A :=
alg_hom.mk (ring_hom.to_fun (algebra_map S A)) sorry sorry sorry sorry sorry
theorem to_alg_hom_apply (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (y : S) : coe_fn (to_alg_hom R S A) y = coe_fn (algebra_map S A) y :=
rfl
@[simp] theorem coe_to_alg_hom (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : ↑(to_alg_hom R S A) = algebra_map S A :=
ring_hom.ext fun (_x : S) => rfl
@[simp] theorem coe_to_alg_hom' (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : ⇑(to_alg_hom R S A) = ⇑(algebra_map S A) :=
rfl
/-- R ⟶ S induces S-Alg ⥤ R-Alg -/
def restrict_base (R : Type u) {S : Type v} {A : Type w} {B : Type u₁} [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B] [is_scalar_tower R S A] [is_scalar_tower R S B] (f : alg_hom S A B) : alg_hom R A B :=
alg_hom.mk (ring_hom.to_fun ↑f) sorry sorry sorry sorry sorry
theorem restrict_base_apply (R : Type u) {S : Type v} {A : Type w} {B : Type u₁} [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B] [is_scalar_tower R S A] [is_scalar_tower R S B] (f : alg_hom S A B) (x : A) : coe_fn (restrict_base R f) x = coe_fn f x :=
rfl
@[simp] theorem coe_restrict_base (R : Type u) {S : Type v} {A : Type w} {B : Type u₁} [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B] [is_scalar_tower R S A] [is_scalar_tower R S B] (f : alg_hom S A B) : ↑(restrict_base R f) = ↑f :=
rfl
@[simp] theorem coe_restrict_base' (R : Type u) {S : Type v} {A : Type w} {B : Type u₁} [comm_semiring R] [comm_semiring S] [semiring A] [semiring B] [algebra R S] [algebra S A] [algebra S B] [algebra R A] [algebra R B] [is_scalar_tower R S A] [is_scalar_tower R S B] (f : alg_hom S A B) : ⇑(restrict_base R f) = ⇑f :=
rfl
protected instance right {S : Type v} {A : Type w} [comm_semiring S] [semiring A] [algebra S A] : is_scalar_tower S A A :=
mk
fun (x : S) (y z : A) =>
eq.mpr (id (Eq._oldrec (Eq.refl ((x • y) • z = x • y • z)) smul_eq_mul))
(eq.mpr (id (Eq._oldrec (Eq.refl (x • y * z = x • y • z)) smul_eq_mul))
(eq.mpr (id (Eq._oldrec (Eq.refl (x • y * z = x • (y * z))) (algebra.smul_mul_assoc x y z)))
(Eq.refl (x • (y * z)))))
protected instance comap {R : Type u_1} {S : Type u_2} {A : Type u_3} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] : is_scalar_tower R S (algebra.comap R S A) :=
of_algebra_map_eq fun (x : R) => rfl
-- conflicts with is_scalar_tower.subalgebra
protected instance subsemiring {S : Type v} {A : Type w} [comm_semiring S] [semiring A] [algebra S A] (U : subsemiring S) : is_scalar_tower (↥U) S A :=
of_algebra_map_eq fun (x : ↥U) => rfl
-- conflicts with is_scalar_tower.subalgebra
protected instance subring {S : Type u_1} {A : Type u_2} [comm_ring S] [ring A] [algebra S A] (U : set S) [is_subring U] : is_scalar_tower (↥U) S A :=
of_algebra_map_eq fun (x : ↥U) => rfl
protected instance of_ring_hom {R : Type u_1} {A : Type u_2} {B : Type u_3} [comm_semiring R] [comm_semiring A] [comm_semiring B] [algebra R A] [algebra R B] (f : alg_hom R A B) : is_scalar_tower R A B :=
let _inst : algebra A B := ring_hom.to_algebra ↑f;
of_algebra_map_eq fun (x : R) => Eq.symm (alg_hom.commutes f x)
protected instance rat (R : Type u) (S : Type v) [field R] [division_ring S] [algebra R S] [char_zero R] [char_zero S] : is_scalar_tower ℚ R S :=
of_algebra_map_eq fun (x : ℚ) => Eq.symm (ring_hom.map_rat_cast (algebra_map R S) x)
end is_scalar_tower
namespace subalgebra
/-- If A/S/R is a tower of algebras then the `res`triction of a S-subalgebra of A is
an R-subalgebra of A. -/
def res (R : Type u) {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (U : subalgebra S A) : subalgebra R A :=
mk (carrier U) (one_mem' U) (mul_mem' U) (zero_mem' U) (add_mem' U) sorry
@[simp] theorem res_top (R : Type u) {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] : res R ⊤ = ⊤ :=
iff.mpr algebra.eq_top_iff fun (_x : A) => (fun (this : _x ∈ ⊤) => this) algebra.mem_top
@[simp] theorem mem_res (R : Type u) {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] {U : subalgebra S A} {x : A} : x ∈ res R U ↔ x ∈ U :=
iff.rfl
theorem res_inj (R : Type u) {S : Type v} {A : Type w} [comm_semiring R] [comm_semiring S] [semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] {U : subalgebra S A} {V : subalgebra S A} (H : res R U = res R V) : U = V := sorry
/-- Produces a map from `subalgebra.under`. -/
def of_under {R : Type u_1} {A : Type u_2} {B : Type u_3} [comm_semiring R] [comm_semiring A] [semiring B] [algebra R A] [algebra R B] (S : subalgebra R A) (U : subalgebra (↥S) A) [algebra (↥S) B] [is_scalar_tower R (↥S) B] (f : alg_hom (↥S) (↥U) B) : alg_hom R (↥(under S U)) B :=
alg_hom.mk (alg_hom.to_fun f) sorry sorry sorry sorry sorry
end subalgebra
namespace is_scalar_tower
theorem range_under_adjoin (R : Type u) (S : Type v) (A : Type w) [comm_semiring R] [comm_semiring S] [comm_semiring A] [algebra R S] [algebra S A] [algebra R A] [is_scalar_tower R S A] (t : set A) : subalgebra.under (alg_hom.range (to_alg_hom R S A)) (algebra.adjoin (↥(alg_hom.range (to_alg_hom R S A))) t) =
subalgebra.res R (algebra.adjoin S t) := sorry
end is_scalar_tower
namespace submodule
theorem smul_mem_span_smul_of_mem {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [semiring S] [add_comm_monoid A] [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] {s : set S} {t : set A} {k : S} (hks : k ∈ span R s) {x : A} (hx : x ∈ t) : k • x ∈ span R (s • t) := sorry
theorem smul_mem_span_smul {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [semiring S] [add_comm_monoid A] [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] {s : set S} (hs : span R s = ⊤) {t : set A} {k : S} {x : A} (hx : x ∈ span R t) : k • x ∈ span R (s • t) := sorry
theorem smul_mem_span_smul' {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [semiring S] [add_comm_monoid A] [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] {s : set S} (hs : span R s = ⊤) {t : set A} {k : S} {x : A} (hx : x ∈ span R (s • t)) : k • x ∈ span R (s • t) := sorry
theorem span_smul {R : Type u} {S : Type v} {A : Type w} [comm_semiring R] [semiring S] [add_comm_monoid A] [algebra R S] [semimodule S A] [semimodule R A] [is_scalar_tower R S A] {s : set S} (hs : span R s = ⊤) (t : set A) : span R (s • t) = restrict_scalars R (span S t) := sorry
|
ef8067e64b6cab54f558e5031cec0bd14c85d77d | 78630e908e9624a892e24ebdd21260720d29cf55 | /src/logic_first_order/fol_12.lean | aacaa6361c4a9da25d5341b86b57f71387ebd888 | [
"CC0-1.0"
] | permissive | tomasz-lisowski/lean-logic-examples | 84e612466776be0a16c23a0439ff8ef6114ddbe1 | 2b2ccd467b49c3989bf6c92ec0358a8d6ee68c5d | refs/heads/master | 1,683,334,199,431 | 1,621,938,305,000 | 1,621,938,305,000 | 365,041,573 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 407 | lean | namespace fol_12
variable A : Type
variable P : A → Prop
variable R : A → A → Prop
theorem fol_12 : (∀ y, P y → (∀ x, R x y)) → (∃ y, P y) → (∃ z, ∀ x, R x z) :=
assume h1: ∀ y, P y → (∀ x, R x y),
assume h2: ∃ y, P y,
exists.elim h2
(assume t (h3: P t),
have h4: P t → (∀ x, R x t), from h1 t,
have h5: ∀ x, R x t, from h4 h3,
exists.intro t h5)
end fol_12 |
120aa649142e90570ab870ff82408ae723b42e79 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/CancellativeSemigroup.lean | 45c9d2d68e0926b50378d7a025f569f88ed8d27a | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,874 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section CancellativeSemigroup
structure CancellativeSemigroup (A : Type) : Type :=
(op : (A → (A → A)))
(associative_op : (∀ {x y z : A} , (op (op x y) z) = (op x (op y z))))
(leftCancellative : (∀ {x y z : A} , ((op z x) = (op z y) → x = y)))
(rightCancellative : (∀ {x y z : A} , ((op x z) = (op y z) → x = y)))
open CancellativeSemigroup
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(associative_opP : (∀ {xP yP zP : (Prod A A)} , (opP (opP xP yP) zP) = (opP xP (opP yP zP))))
(leftCancellativeP : (∀ {xP yP zP : (Prod A A)} , ((opP zP xP) = (opP zP yP) → xP = yP)))
(rightCancellativeP : (∀ {xP yP zP : (Prod A A)} , ((opP xP zP) = (opP yP zP) → xP = yP)))
structure Hom {A1 : Type} {A2 : Type} (Ca1 : (CancellativeSemigroup A1)) (Ca2 : (CancellativeSemigroup A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Ca1) x1 x2)) = ((op Ca2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Ca1 : (CancellativeSemigroup A1)) (Ca2 : (CancellativeSemigroup A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Ca1) x1 x2) ((op Ca2) y1 y2))))))
inductive CancellativeSemigroupTerm : Type
| opL : (CancellativeSemigroupTerm → (CancellativeSemigroupTerm → CancellativeSemigroupTerm))
open CancellativeSemigroupTerm
inductive ClCancellativeSemigroupTerm (A : Type) : Type
| sing : (A → ClCancellativeSemigroupTerm)
| opCl : (ClCancellativeSemigroupTerm → (ClCancellativeSemigroupTerm → ClCancellativeSemigroupTerm))
open ClCancellativeSemigroupTerm
inductive OpCancellativeSemigroupTerm (n : ℕ) : Type
| v : ((fin n) → OpCancellativeSemigroupTerm)
| opOL : (OpCancellativeSemigroupTerm → (OpCancellativeSemigroupTerm → OpCancellativeSemigroupTerm))
open OpCancellativeSemigroupTerm
inductive OpCancellativeSemigroupTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpCancellativeSemigroupTerm2)
| sing2 : (A → OpCancellativeSemigroupTerm2)
| opOL2 : (OpCancellativeSemigroupTerm2 → (OpCancellativeSemigroupTerm2 → OpCancellativeSemigroupTerm2))
open OpCancellativeSemigroupTerm2
def simplifyCl {A : Type} : ((ClCancellativeSemigroupTerm A) → (ClCancellativeSemigroupTerm A))
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpCancellativeSemigroupTerm n) → (OpCancellativeSemigroupTerm n))
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpCancellativeSemigroupTerm2 n A) → (OpCancellativeSemigroupTerm2 n A))
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((CancellativeSemigroup A) → (CancellativeSemigroupTerm → A))
| Ca (opL x1 x2) := ((op Ca) (evalB Ca x1) (evalB Ca x2))
def evalCl {A : Type} : ((CancellativeSemigroup A) → ((ClCancellativeSemigroupTerm A) → A))
| Ca (sing x1) := x1
| Ca (opCl x1 x2) := ((op Ca) (evalCl Ca x1) (evalCl Ca x2))
def evalOpB {A : Type} {n : ℕ} : ((CancellativeSemigroup A) → ((vector A n) → ((OpCancellativeSemigroupTerm n) → A)))
| Ca vars (v x1) := (nth vars x1)
| Ca vars (opOL x1 x2) := ((op Ca) (evalOpB Ca vars x1) (evalOpB Ca vars x2))
def evalOp {A : Type} {n : ℕ} : ((CancellativeSemigroup A) → ((vector A n) → ((OpCancellativeSemigroupTerm2 n A) → A)))
| Ca vars (v2 x1) := (nth vars x1)
| Ca vars (sing2 x1) := x1
| Ca vars (opOL2 x1 x2) := ((op Ca) (evalOp Ca vars x1) (evalOp Ca vars x2))
def inductionB {P : (CancellativeSemigroupTerm → Type)} : ((∀ (x1 x2 : CancellativeSemigroupTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → (∀ (x : CancellativeSemigroupTerm) , (P x)))
| popl (opL x1 x2) := (popl _ _ (inductionB popl x1) (inductionB popl x2))
def inductionCl {A : Type} {P : ((ClCancellativeSemigroupTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClCancellativeSemigroupTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → (∀ (x : (ClCancellativeSemigroupTerm A)) , (P x))))
| psing popcl (sing x1) := (psing x1)
| psing popcl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl x1) (inductionCl psing popcl x2))
def inductionOpB {n : ℕ} {P : ((OpCancellativeSemigroupTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpCancellativeSemigroupTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → (∀ (x : (OpCancellativeSemigroupTerm n)) , (P x))))
| pv popol (v x1) := (pv x1)
| pv popol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol x1) (inductionOpB pv popol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpCancellativeSemigroupTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpCancellativeSemigroupTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → (∀ (x : (OpCancellativeSemigroupTerm2 n A)) , (P x)))))
| pv2 psing2 popol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 x1) (inductionOp pv2 psing2 popol2 x2))
def stageB : (CancellativeSemigroupTerm → (Staged CancellativeSemigroupTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClCancellativeSemigroupTerm A) → (Staged (ClCancellativeSemigroupTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpCancellativeSemigroupTerm n) → (Staged (OpCancellativeSemigroupTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpCancellativeSemigroupTerm2 n A) → (Staged (OpCancellativeSemigroupTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
end CancellativeSemigroup |
a371cd9decff211202ad4720a6c5c2fcc98d5102 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /library/algebra/function.lean | 6bfdf402d9fb1504523608770596dc65e11379eb | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,405 | lean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
namespace function
variables {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
definition compose [reducible] (f : B → C) (g : A → B) : A → C :=
λx, f (g x)
definition id [reducible] (a : A) : A :=
a
definition on_fun (f : B → B → C) (g : A → B) : A → A → C :=
λx y, f (g x) (g y)
definition combine (f : A → B → C) (op : C → D → E) (g : A → B → D) : A → B → E :=
λx y, op (f x y) (g x y)
definition const {A : Type} (B : Type) (a : A) : B → A :=
λx, a
definition dcompose {A : Type} {B : A → Type} {C : Π {x : A}, B x → Type} (f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
λx, f (g x)
definition flip {A : Type} {B : Type} {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
λy x, f x y
definition app {A : Type} {B : A → Type} (f : Πx, B x) (x : A) : B x :=
f x
precedence `∘`:60
precedence `∘'`:60
precedence `on`:1
precedence `$`:1
infixr ∘ := compose
infixr ∘' := dcompose
infixl on := on_fun
infixr $ := app
notation f `-[` op `]-` g := combine f op g
-- Trick for using any binary function as infix operator
notation a `⟨` f `⟩` b := f a b
end function
|
89e9bb1a5dd7e0b20926910fd39ae1e05cded318 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/run/group2.lean | a609eeb8a22a6e418a4a38fe87c357af7d836ada | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,696 | lean | import logic
section
variable {A : Type}
variable f : A → A → A
variable one : A
variable inv : A → A
local infixl `*` := f
local postfix `^-1`:100 := inv
definition is_assoc := ∀ a b c, (a*b)*c = a*b*c
definition is_id := ∀ a, a*one = a
definition is_inv := ∀ a, a*a^-1 = one
end
inductive group_struct [class] (A : Type) : Type :=
mk : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
inductive group : Type :=
mk : Π (A : Type), group_struct A → group
definition carrier (g : group) : Type
:= group.rec (λ c s, c) g
attribute carrier [coercion]
definition group_to_struct [instance] (g : group) : group_struct (carrier g)
:= group.rec (λ (A : Type) (s : group_struct A), s) g
check group_struct
definition mul {A : Type} [s : group_struct A] (a b : A) : A
:= group_struct.rec (λ mul one inv h1 h2 h3, mul) s a b
infixl `*` := mul
section
variable G1 : group
variable G2 : group
variables a b c : G2
variables d e : G1
check a * b * b
check d * e
end
constant G : group.{1}
constants a b : G
definition val : G := a*b
check val
constant pos_real : Type.{1}
constant rmul : pos_real → pos_real → pos_real
constant rone : pos_real
constant rinv : pos_real → pos_real
axiom H1 : is_assoc rmul
axiom H2 : is_id rmul rone
axiom H3 : is_inv rmul rone rinv
definition real_group_struct [instance] : group_struct pos_real
:= group_struct.mk rmul rone rinv H1 H2 H3
constants x y : pos_real
check x * y
set_option pp.implicit true
print "---------------"
theorem T (a b : pos_real): (rmul a b) = a*b
:= eq.refl (rmul a b)
|
551cd6725e793a9f48e80d0b869c81394b57b862 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1808.lean | 7d949d36338ad8c519c933ea0cb85c81c4dcc58e | [
"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 | 307 | lean | class Preorder (α : Type u) extends LT α :=
(le : α → α → Prop)
(lt_iff_le_not_le : ∀ a b : α, lt a b ↔ (le a b ∧ ¬ le b a) := by intros; rfl)
theorem Preorder.toLE_injective (A B : Preorder α) (h : A.le = B.le) (h2 : A.toLT = B.toLT) : A = B := by
cases A; cases B; cases h
congr
|
c6dd93764114a06dd99188b57584bf1b37018830 | c31182a012eec69da0a1f6c05f42b0f0717d212d | /src/thm95/double_complex.lean | 29d57eb0234173b0f970782c73d7882ac926c08f | [] | no_license | Ja1941/lean-liquid | fbec3ffc7fc67df1b5ca95b7ee225685ab9ffbdc | 8e80ed0cbdf5145d6814e833a674eaf05a1495c1 | refs/heads/master | 1,689,437,983,362 | 1,628,362,719,000 | 1,628,362,719,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,939 | lean | import algebra.homology.functor
import for_mathlib.simplicial.complex
import polyhedral_lattice.Hom
import pseudo_normed_group.system_of_complexes
import system_of_complexes.rescale
import normed_spectral
import thm95.modify_complex
/-!
# The double complex that is the protagonist in the proof of Theorem 9.5
-/
noncomputable theory
open_locale nnreal big_operators
open category_theory opposite simplex_category
universe variables u v w
namespace thm95
variables (BD : breen_deligne.data) (κ : ℕ → ℝ≥0) [BD.suitable κ]
variables (r r' : ℝ≥0) [fact (0 < r)] [fact (0 < r')] [fact (r < r')] [fact (r' ≤ 1)]
variables (V : SemiNormedGroup.{u}) [normed_with_aut r V]
variables (Λ : PolyhedralLattice.{u}) (M : ProFiltPseuNormGrpWithTinv.{u} r')
variables (N : ℕ) [fact (0 < N)]
section
open PolyhedralLattice
def Cech_nerve : cosimplicial_object.augmented (ProFiltPseuNormGrpWithTinv.{u} r')ᵒᵖ :=
(cosimplicial_object.augmented.whiskering_obj _ _ (Hom.{u u} M).right_op).obj
(augmented_cosimplicial.{u} Λ N)
def Cech_augmentation_map : ((Cech_nerve r' Λ M N).right.obj (mk 0)).unop ⟶ (Hom M).obj (op Λ) :=
(Hom M).map (cosimplicial_augmentation_map Λ N).op
lemma Cech_nerve_hom_zero :
(Cech_nerve.{u} r' Λ M N).hom.app (mk.{u} 0) = (Cech_augmentation_map.{u} r' Λ M N).op :=
begin
dsimp only [Cech_nerve, Cech_augmentation_map, cosimplicial_object.augmented.whiskering_obj],
simp only [whisker_right_app, category.id_comp, functor.right_op_map, nat_trans.comp_app,
functor.const_comp_inv_app],
congr' 2,
dsimp only [augmented_cosimplicial, augmented_Cech_conerve],
rw cosimplicial_object.augment_hom_zero,
refl
end
def cosimplicial_system_of_complexes : cosimplicial_object.augmented system_of_complexes.{u} :=
(cosimplicial_object.augmented.whiskering_obj.{u} _ _ (BD.system κ r V r')).obj
(Cech_nerve r' Λ M N)
lemma cosimplicial_system_of_complexes_hom_zero :
(cosimplicial_system_of_complexes BD κ r r' V Λ M N).hom.app (mk 0) =
(BD.system κ r V r').map (Cech_augmentation_map.{u} r' Λ M N).op :=
begin
ext : 2, dsimp [cosimplicial_system_of_complexes],
rw [category.id_comp, Cech_nerve_hom_zero]
end
@[simps X d]
def double_complex_aux : cochain_complex system_of_complexes ℕ :=
(cosimplicial_system_of_complexes BD κ r r' V Λ M N).to_cocomplex
.
@[simps obj map]
def double_complex' : system_of_double_complexes :=
(double_complex_aux BD κ r r' V Λ M N).as_functor
end
section
open polyhedral_lattice
open PolyhedralLattice (of cosimplicial)
open_locale nat
-- we now have a `cochain_complex` of `system_of_complexes`
-- so we need to reorganize the data, to get a `system_of_double_complexes`
-- this is what `.as_functor` does, in the definition `double_complex` below
-- but before we do this, we need to rescale the norms in all the rows,
-- so that the vertical differentials become norm-nonincreasing
set_option pp.universes true
@[simps X d]
def double_complex_aux_rescaled : cochain_complex system_of_complexes ℕ :=
@homological_complex.modify _ _ _ _ _ _ _ _
(double_complex_aux BD κ r r' V Λ M N )
system_of_complexes.rescale_functor.{u}
system_of_complexes.rescale_nat_trans.{u u}
(system_of_complexes.rescale_functor.additive.{u u})
@[simps obj map]
def double_complex : system_of_double_complexes :=
(double_complex_aux_rescaled BD κ r r' V Λ M N).as_functor
lemma double_complex.row_zero :
(double_complex BD κ r r' V Λ M N).row 0 =
(BD.system κ r V r').obj (op $ Hom Λ M) := rfl
lemma double_complex.row_one :
(double_complex BD κ r r' V Λ M N).row 1 =
(BD.system κ r V r').obj (op $ Hom ((cosimplicial Λ N).obj (mk 0)) M) := rfl
lemma double_complex.row_map_zero_one :
(double_complex BD κ r r' V Λ M N).row_map 0 1 =
(BD.system κ r V r').map (Cech_augmentation_map r' Λ M N).op :=
begin
ext c i : 4,
dsimp only [system_of_double_complexes.row_map_app_f, system_of_double_complexes.d,
double_complex, homological_complex.as_functor_obj,
double_complex_aux_rescaled, homological_complex.modify,
system_of_complexes.rescale_nat_trans, nat_trans.id_app,
system_of_complexes.rescale_functor, functor.id_map, double_complex_aux, op_unop],
erw [category.comp_id, ← Cech_nerve_hom_zero],
simp only [dite_eq_ite, breen_deligne.data.system_map, if_true, eq_self_iff_true,
cosimplicial_object.augmented.to_cocomplex_d_2, eq_to_hom_refl, category.comp_id],
dsimp only [cosimplicial_object.augmented.to_cocomplex_d,
cosimplicial_system_of_complexes, cosimplicial_object.augmented.whiskering_obj],
simp only [breen_deligne.data.system_map, whisker_right_app, category.id_comp,
nat_trans.comp_app, functor.const_comp_inv_app],
refl
end
lemma double_complex.row (m : ℕ) :
(double_complex BD κ r r' V Λ M N).row (m+2) =
(system_of_complexes.rescale_functor (m+2)).obj
((BD.system κ r V r').obj (op $ Hom ((cosimplicial Λ N).obj (mk (m+1))) M)) := rfl
end
end thm95
namespace thm95
variables (BD : breen_deligne.data)
variables (r r' : ℝ≥0) [fact (0 < r)] [fact (0 < r')] [fact (r < r')] [fact (r' ≤ 1)]
variables (V : SemiNormedGroup.{u}) [normed_with_aut r V]
variables (κ : ℕ → ℝ≥0) [BD.very_suitable r r' κ]
variables (Λ : PolyhedralLattice.{u}) (M : ProFiltPseuNormGrpWithTinv.{u} r')
variables (N : ℕ) [fact (0 < N)]
variables {r r' V κ Λ M N}
lemma double_complex.row_admissible :
∀ m, ((double_complex BD κ r r' V Λ M N).row m).admissible
| 0 := BD.system_admissible
| 1 := BD.system_admissible
| (m+2) := system_of_complexes.rescale_admissible _ _ BD.system_admissible
lemma double_complex.d_one_norm_noninc (c : ℝ≥0) (q : ℕ) :
(@system_of_double_complexes.d (double_complex BD κ r r' V Λ M N) c 1 2 q).norm_noninc :=
begin
apply normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.2,
refine normed_group_hom.norm_comp_le_of_le' 2 _ 1 _ (SemiNormedGroup.norm_to_rescale_le _ _) _,
{ norm_num },
have : (2 : ℝ) = ∑ i : fin 2, 1,
{ simp only [finset.card_fin, mul_one, nat.cast_bit0, finset.sum_const, nsmul_eq_mul, nat.cast_one] },
dsimp [system_of_complexes.rescale_functor, double_complex_aux,
cosimplicial_object.augmented.to_cocomplex_d],
erw [category.comp_id, if_pos rfl],
dsimp [cosimplicial_object.coboundary],
simp only [← nat_trans.app_hom_apply, add_monoid_hom.map_sum, add_monoid_hom.map_gsmul,
← homological_complex.hom.f_add_monoid_hom_apply, this],
apply norm_sum_le_of_le,
rintro i -,
refine le_trans (norm_gsmul_le _ _) _,
rw [← int.norm_cast_real, int.cast_pow, normed_field.norm_pow, int.cast_neg, int.cast_one,
norm_neg, norm_one, one_pow, one_mul],
apply normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.1,
apply breen_deligne.data.complex.map_norm_noninc
end
.
lemma double_complex.d_two_norm_noninc (c : ℝ≥0) (p q : ℕ) :
(@system_of_double_complexes.d (double_complex BD κ r r' V Λ M N) c (p+2) (p+3) q).norm_noninc :=
begin
apply normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.2,
refine normed_group_hom.norm_comp_le_of_le' (p+3:ℕ) _ 1 _ (SemiNormedGroup.norm_scale_le _ _ _) _,
{ simp only [add_zero, nat.add_def, ← nat.cast_succ],
norm_cast,
rw [mul_comm, ← mul_div_assoc, eq_comm, ← nat.cast_mul, nat.factorial_succ], apply div_self,
norm_num [nat.factorial_ne_zero] },
apply SemiNormedGroup.norm_rescale_map_le,
have : (p+1+1+1 : ℝ) = ∑ i : fin (p+1+1+1), 1,
{ simp only [finset.card_fin, mul_one, finset.sum_const, nsmul_eq_mul, nat.cast_id,
nat.cast_bit1, nat.cast_add, nat.cast_one] },
dsimp [system_of_complexes.rescale_functor, double_complex_aux,
cosimplicial_object.augmented.to_cocomplex_d],
erw [category.comp_id, if_pos rfl],
dsimp [cosimplicial_object.coboundary],
simp only [← nat_trans.app_hom_apply, add_monoid_hom.map_sum, add_monoid_hom.map_gsmul,
← homological_complex.hom.f_add_monoid_hom_apply, this],
apply norm_sum_le_of_le,
rintro i -,
refine le_trans (norm_gsmul_le _ _) _,
rw [← int.norm_cast_real, int.cast_pow, normed_field.norm_pow, int.cast_neg, int.cast_one,
norm_neg, norm_one, one_pow, one_mul],
apply normed_group_hom.norm_noninc.norm_noninc_iff_norm_le_one.1,
apply breen_deligne.data.complex.map_norm_noninc
end
lemma double_complex.d_norm_noninc (c : ℝ≥0) (q : ℕ) :
∀ p, (@system_of_double_complexes.d (double_complex BD κ r r' V Λ M N) c p (p+1) q).norm_noninc
| 0 := breen_deligne.data.complex.map_norm_noninc _ _ _ _ _ _ _ _
| 1 := double_complex.d_one_norm_noninc _ _ _
| (p+2) := double_complex.d_two_norm_noninc _ _ _ _
-- see above: currently we can only prove this for the columns
lemma double_complex_admissible :
(double_complex BD κ r r' V Λ M N).admissible :=
system_of_double_complexes.admissible.mk' (double_complex.row_admissible _)
(by { rintro _ _ _ _ rfl, apply double_complex.d_norm_noninc })
end thm95
|
0905bf3b6b0d5c742e5d429e3c6c4c80ca582005 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/limits/shapes/terminal.lean | 3c8cd3fa89c1dcbd09e682a3391e2b185dacddfd | [
"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 | 27,209 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.pempty
import category_theory.limits.has_limits
import category_theory.epi_mono
import category_theory.category.preorder
/-!
# Initial and terminal objects in a category.
## References
* [Stacks: Initial and final objects](https://stacks.math.columbia.edu/tag/002B)
-/
noncomputable theory
universes w w' v v₁ v₂ u u₁ u₂
open category_theory
namespace category_theory.limits
variables {C : Type u₁} [category.{v₁} C]
local attribute [tidy] tactic.discrete_cases
/-- Construct a cone for the empty diagram given an object. -/
@[simps] def as_empty_cone (X : C) : cone (functor.empty.{0} C) := { X := X, π := by tidy }
/-- Construct a cocone for the empty diagram given an object. -/
@[simps] def as_empty_cocone (X : C) : cocone (functor.empty.{0} C) := { X := X, ι := by tidy }
/-- `X` is terminal if the cone it induces on the empty diagram is limiting. -/
abbreviation is_terminal (X : C) := is_limit (as_empty_cone X)
/-- `X` is initial if the cocone it induces on the empty diagram is colimiting. -/
abbreviation is_initial (X : C) := is_colimit (as_empty_cocone X)
/-- An object `Y` is terminal iff for every `X` there is a unique morphism `X ⟶ Y`. -/
def is_terminal_equiv_unique (F : discrete.{0} pempty.{1} ⥤ C) (Y : C) :
is_limit (⟨Y, by tidy⟩ : cone F) ≃ ∀ X : C, unique (X ⟶ Y) :=
{ to_fun := λ t X, { default := t.lift ⟨X, by tidy⟩,
uniq := λ f, t.uniq ⟨X, by tidy⟩ f (by tidy) },
inv_fun := λ u, { lift := λ s, (u s.X).default, uniq' := λ s _ _, (u s.X).2 _ },
left_inv := by tidy,
right_inv := by tidy }
/-- An object `Y` is terminal if for every `X` there is a unique morphism `X ⟶ Y`
(as an instance). -/
def is_terminal.of_unique (Y : C) [h : Π X : C, unique (X ⟶ Y)] : is_terminal Y :=
{ lift := λ s, (h s.X).default }
/-- If `α` is a preorder with top, then `⊤` is a terminal object. -/
def is_terminal_top {α : Type*} [preorder α] [order_top α] : is_terminal (⊤ : α) :=
is_terminal.of_unique _
/-- Transport a term of type `is_terminal` across an isomorphism. -/
def is_terminal.of_iso {Y Z : C} (hY : is_terminal Y) (i : Y ≅ Z) : is_terminal Z :=
is_limit.of_iso_limit hY
{ hom := { hom := i.hom },
inv := { hom := i.inv } }
/-- An object `X` is initial iff for every `Y` there is a unique morphism `X ⟶ Y`. -/
def is_initial_equiv_unique (F : discrete.{0} pempty.{1} ⥤ C) (X : C) :
is_colimit (⟨X, by tidy⟩ : cocone F) ≃ ∀ Y : C, unique (X ⟶ Y) :=
{ to_fun := λ t X, { default := t.desc ⟨X, by tidy⟩,
uniq := λ f, t.uniq ⟨X, by tidy⟩ f (by tidy) },
inv_fun := λ u, { desc := λ s, (u s.X).default, uniq' := λ s _ _, (u s.X).2 _ },
left_inv := by tidy,
right_inv := by tidy }
/-- An object `X` is initial if for every `Y` there is a unique morphism `X ⟶ Y`
(as an instance). -/
def is_initial.of_unique (X : C) [h : Π Y : C, unique (X ⟶ Y)] : is_initial X :=
{ desc := λ s, (h s.X).default }
/-- If `α` is a preorder with bot, then `⊥` is an initial object. -/
def is_initial_bot {α : Type*} [preorder α] [order_bot α] : is_initial (⊥ : α) :=
is_initial.of_unique _
/-- Transport a term of type `is_initial` across an isomorphism. -/
def is_initial.of_iso {X Y : C} (hX : is_initial X) (i : X ≅ Y) : is_initial Y :=
is_colimit.of_iso_colimit hX
{ hom := { hom := i.hom },
inv := { hom := i.inv } }
/-- Give the morphism to a terminal object from any other. -/
def is_terminal.from {X : C} (t : is_terminal X) (Y : C) : Y ⟶ X :=
t.lift (as_empty_cone Y)
/-- Any two morphisms to a terminal object are equal. -/
lemma is_terminal.hom_ext {X Y : C} (t : is_terminal X) (f g : Y ⟶ X) : f = g :=
t.hom_ext (by tidy)
@[simp] lemma is_terminal.comp_from {Z : C} (t : is_terminal Z) {X Y : C} (f : X ⟶ Y) :
f ≫ t.from Y = t.from X :=
t.hom_ext _ _
@[simp] lemma is_terminal.from_self {X : C} (t : is_terminal X) : t.from X = 𝟙 X :=
t.hom_ext _ _
/-- Give the morphism from an initial object to any other. -/
def is_initial.to {X : C} (t : is_initial X) (Y : C) : X ⟶ Y :=
t.desc (as_empty_cocone Y)
/-- Any two morphisms from an initial object are equal. -/
lemma is_initial.hom_ext {X Y : C} (t : is_initial X) (f g : X ⟶ Y) : f = g :=
t.hom_ext (by tidy)
@[simp] lemma is_initial.to_comp {X : C} (t : is_initial X) {Y Z : C} (f : Y ⟶ Z) :
t.to Y ≫ f = t.to Z :=
t.hom_ext _ _
@[simp] lemma is_initial.to_self {X : C} (t : is_initial X) : t.to X = 𝟙 X :=
t.hom_ext _ _
/-- Any morphism from a terminal object is split mono. -/
lemma is_terminal.is_split_mono_from {X Y : C} (t : is_terminal X) (f : X ⟶ Y) :
is_split_mono f := is_split_mono.mk' ⟨t.from _, t.hom_ext _ _⟩
/-- Any morphism to an initial object is split epi. -/
lemma is_initial.is_split_epi_to {X Y : C} (t : is_initial X) (f : Y ⟶ X) :
is_split_epi f := is_split_epi.mk' ⟨t.to _, t.hom_ext _ _⟩
/-- Any morphism from a terminal object is mono. -/
lemma is_terminal.mono_from {X Y : C} (t : is_terminal X) (f : X ⟶ Y) : mono f :=
by haveI := t.is_split_mono_from f; apply_instance
/-- Any morphism to an initial object is epi. -/
lemma is_initial.epi_to {X Y : C} (t : is_initial X) (f : Y ⟶ X) : epi f :=
by haveI := t.is_split_epi_to f; apply_instance
/-- If `T` and `T'` are terminal, they are isomorphic. -/
@[simps]
def is_terminal.unique_up_to_iso {T T' : C} (hT : is_terminal T) (hT' : is_terminal T') : T ≅ T' :=
{ hom := hT'.from _,
inv := hT.from _ }
/-- If `I` and `I'` are initial, they are isomorphic. -/
@[simps]
def is_initial.unique_up_to_iso {I I' : C} (hI : is_initial I) (hI' : is_initial I') : I ≅ I' :=
{ hom := hI.to _,
inv := hI'.to _ }
variable (C)
/--
A category has a terminal object if it has a limit over the empty diagram.
Use `has_terminal_of_unique` to construct instances.
-/
abbreviation has_terminal := has_limits_of_shape (discrete.{0} pempty) C
/--
A category has an initial object if it has a colimit over the empty diagram.
Use `has_initial_of_unique` to construct instances.
-/
abbreviation has_initial := has_colimits_of_shape (discrete.{0} pempty) C
section univ
variables (X : C) {F₁ : discrete.{w} pempty ⥤ C} {F₂ : discrete.{w'} pempty ⥤ C}
/-- Being terminal is independent of the empty diagram, its universe, and the cone over it,
as long as the cone points are isomorphic. -/
def is_limit_change_empty_cone {c₁ : cone F₁} (hl : is_limit c₁)
(c₂ : cone F₂) (hi : c₁.X ≅ c₂.X) : is_limit c₂ :=
{ lift := λ c, hl.lift ⟨c.X, by tidy⟩ ≫ hi.hom,
fac' := λ _ j, j.as.elim,
uniq' := λ c f _, by { erw ← hl.uniq ⟨c.X, by tidy⟩ (f ≫ hi.inv) (λ j, j.as.elim), simp } }
/-- Replacing an empty cone in `is_limit` by another with the same cone point
is an equivalence. -/
def is_limit_empty_cone_equiv (c₁ : cone F₁) (c₂ : cone F₂) (h : c₁.X ≅ c₂.X) :
is_limit c₁ ≃ is_limit c₂ :=
{ to_fun := λ hl, is_limit_change_empty_cone C hl c₂ h,
inv_fun := λ hl, is_limit_change_empty_cone C hl c₁ h.symm,
left_inv := by tidy,
right_inv := by tidy }
lemma has_terminal_change_diagram (h : has_limit F₁) : has_limit F₂ :=
⟨⟨⟨⟨limit F₁, by tidy⟩, is_limit_change_empty_cone C (limit.is_limit F₁) _ (eq_to_iso rfl)⟩⟩⟩
lemma has_terminal_change_universe [h : has_limits_of_shape (discrete.{w} pempty) C] :
has_limits_of_shape (discrete.{w'} pempty) C :=
{ has_limit := λ J, has_terminal_change_diagram C (let f := h.1 in f (functor.empty C)) }
/-- Being initial is independent of the empty diagram, its universe, and the cocone over it,
as long as the cocone points are isomorphic. -/
def is_colimit_change_empty_cocone {c₁ : cocone F₁} (hl : is_colimit c₁)
(c₂ : cocone F₂) (hi : c₁.X ≅ c₂.X) : is_colimit c₂ :=
{ desc := λ c, hi.inv ≫ hl.desc ⟨c.X, by tidy⟩,
fac' := λ _ j, j.as.elim,
uniq' := λ c f _, by { erw ← hl.uniq ⟨c.X, by tidy⟩ (hi.hom ≫ f) (λ j, j.as.elim), simp } }
/-- Replacing an empty cocone in `is_colimit` by another with the same cocone point
is an equivalence. -/
def is_colimit_empty_cocone_equiv (c₁ : cocone F₁) (c₂ : cocone F₂) (h : c₁.X ≅ c₂.X) :
is_colimit c₁ ≃ is_colimit c₂ :=
{ to_fun := λ hl, is_colimit_change_empty_cocone C hl c₂ h,
inv_fun := λ hl, is_colimit_change_empty_cocone C hl c₁ h.symm,
left_inv := by tidy,
right_inv := by tidy }
lemma has_initial_change_diagram (h : has_colimit F₁) : has_colimit F₂ :=
⟨⟨⟨⟨colimit F₁, by tidy⟩,
is_colimit_change_empty_cocone C (colimit.is_colimit F₁) _ (eq_to_iso rfl)⟩⟩⟩
lemma has_initial_change_universe [h : has_colimits_of_shape (discrete.{w} pempty) C] :
has_colimits_of_shape (discrete.{w'} pempty) C :=
{ has_colimit := λ J, has_initial_change_diagram C (let f := h.1 in f (functor.empty C)) }
end univ
/--
An arbitrary choice of terminal object, if one exists.
You can use the notation `⊤_ C`.
This object is characterized by having a unique morphism from any object.
-/
abbreviation terminal [has_terminal C] : C := limit (functor.empty.{0} C)
/--
An arbitrary choice of initial object, if one exists.
You can use the notation `⊥_ C`.
This object is characterized by having a unique morphism to any object.
-/
abbreviation initial [has_initial C] : C := colimit (functor.empty.{0} C)
notation `⊤_ ` C:20 := terminal C
notation `⊥_ ` C:20 := initial C
section
variables {C}
/-- We can more explicitly show that a category has a terminal object by specifying the object,
and showing there is a unique morphism to it from any other object. -/
lemma has_terminal_of_unique (X : C) [h : Π Y : C, unique (Y ⟶ X)] : has_terminal C :=
{ has_limit := λ F, has_limit.mk ⟨_, (is_terminal_equiv_unique F X).inv_fun h⟩ }
lemma is_terminal.has_terminal {X : C} (h : is_terminal X) : has_terminal C :=
{ has_limit := λ F, has_limit.mk ⟨⟨X, by tidy⟩, is_limit_change_empty_cone _ h _ (iso.refl _)⟩ }
/-- We can more explicitly show that a category has an initial object by specifying the object,
and showing there is a unique morphism from it to any other object. -/
lemma has_initial_of_unique (X : C) [h : Π Y : C, unique (X ⟶ Y)] : has_initial C :=
{ has_colimit := λ F, has_colimit.mk ⟨_, (is_initial_equiv_unique F X).inv_fun h⟩ }
lemma is_initial.has_initial {X : C} (h : is_initial X) : has_initial C :=
{ has_colimit := λ F, has_colimit.mk
⟨⟨X, by tidy⟩, is_colimit_change_empty_cocone _ h _ (iso.refl _)⟩ }
/-- The map from an object to the terminal object. -/
abbreviation terminal.from [has_terminal C] (P : C) : P ⟶ ⊤_ C :=
limit.lift (functor.empty C) (as_empty_cone P)
/-- The map to an object from the initial object. -/
abbreviation initial.to [has_initial C] (P : C) : ⊥_ C ⟶ P :=
colimit.desc (functor.empty C) (as_empty_cocone P)
/-- A terminal object is terminal. -/
def terminal_is_terminal [has_terminal C] : is_terminal (⊤_ C) :=
{ lift := λ s, terminal.from _ }
/-- An initial object is initial. -/
def initial_is_initial [has_initial C] : is_initial (⊥_ C) :=
{ desc := λ s, initial.to _ }
instance unique_to_terminal [has_terminal C] (P : C) : unique (P ⟶ ⊤_ C) :=
is_terminal_equiv_unique _ (⊤_ C) terminal_is_terminal P
instance unique_from_initial [has_initial C] (P : C) : unique (⊥_ C ⟶ P) :=
is_initial_equiv_unique _ (⊥_ C) initial_is_initial P
@[simp] lemma terminal.comp_from [has_terminal C] {P Q : C} (f : P ⟶ Q) :
f ≫ terminal.from Q = terminal.from P :=
by tidy
@[simp] lemma initial.to_comp [has_initial C] {P Q : C} (f : P ⟶ Q) :
initial.to P ≫ f = initial.to Q :=
by tidy
/-- The (unique) isomorphism between the chosen initial object and any other initial object. -/
@[simp] def initial_iso_is_initial [has_initial C] {P : C} (t : is_initial P) : ⊥_ C ≅ P :=
initial_is_initial.unique_up_to_iso t
/-- The (unique) isomorphism between the chosen terminal object and any other terminal object. -/
@[simp] def terminal_iso_is_terminal [has_terminal C] {P : C} (t : is_terminal P) : ⊤_ C ≅ P :=
terminal_is_terminal.unique_up_to_iso t
/-- Any morphism from a terminal object is split mono. -/
instance terminal.is_split_mono_from {Y : C} [has_terminal C] (f : ⊤_ C ⟶ Y) : is_split_mono f :=
is_terminal.is_split_mono_from terminal_is_terminal _
/-- Any morphism to an initial object is split epi. -/
instance initial.is_split_epi_to {Y : C} [has_initial C] (f : Y ⟶ ⊥_ C) : is_split_epi f :=
is_initial.is_split_epi_to initial_is_initial _
/-- An initial object is terminal in the opposite category. -/
def terminal_op_of_initial {X : C} (t : is_initial X) : is_terminal (opposite.op X) :=
{ lift := λ s, (t.to s.X.unop).op,
uniq' := λ s m w, quiver.hom.unop_inj (t.hom_ext _ _) }
/-- An initial object in the opposite category is terminal in the original category. -/
def terminal_unop_of_initial {X : Cᵒᵖ} (t : is_initial X) : is_terminal X.unop :=
{ lift := λ s, (t.to (opposite.op s.X)).unop,
uniq' := λ s m w, quiver.hom.op_inj (t.hom_ext _ _) }
/-- A terminal object is initial in the opposite category. -/
def initial_op_of_terminal {X : C} (t : is_terminal X) : is_initial (opposite.op X) :=
{ desc := λ s, (t.from s.X.unop).op,
uniq' := λ s m w, quiver.hom.unop_inj (t.hom_ext _ _) }
/-- A terminal object in the opposite category is initial in the original category. -/
def initial_unop_of_terminal {X : Cᵒᵖ} (t : is_terminal X) : is_initial X.unop :=
{ desc := λ s, (t.from (opposite.op s.X)).unop,
uniq' := λ s m w, quiver.hom.op_inj (t.hom_ext _ _) }
instance has_initial_op_of_has_terminal [has_terminal C] : has_initial Cᵒᵖ :=
(initial_op_of_terminal terminal_is_terminal).has_initial
instance has_terminal_op_of_has_initial [has_initial C] : has_terminal Cᵒᵖ :=
(terminal_op_of_initial initial_is_initial).has_terminal
lemma has_terminal_of_has_initial_op [has_initial Cᵒᵖ] : has_terminal C :=
(terminal_unop_of_initial initial_is_initial).has_terminal
lemma has_initial_of_has_terminal_op [has_terminal Cᵒᵖ] : has_initial C :=
(initial_unop_of_terminal terminal_is_terminal).has_initial
instance {J : Type*} [category J] {C : Type*} [category C] [has_terminal C] :
has_limit ((category_theory.functor.const J).obj (⊤_ C)) :=
has_limit.mk
{ cone :=
{ X := ⊤_ C,
π := { app := λ _, terminal.from _, }, },
is_limit :=
{ lift := λ s, terminal.from _, }, }
/-- The limit of the constant `⊤_ C` functor is `⊤_ C`. -/
@[simps hom]
def limit_const_terminal {J : Type*} [category J] {C : Type*} [category C] [has_terminal C] :
limit ((category_theory.functor.const J).obj (⊤_ C)) ≅ ⊤_ C :=
{ hom := terminal.from _,
inv := limit.lift ((category_theory.functor.const J).obj (⊤_ C))
{ X := ⊤_ C, π := { app := λ j, terminal.from _, }}, }
@[simp, reassoc] lemma limit_const_terminal_inv_π
{J : Type*} [category J] {C : Type*} [category C] [has_terminal C] {j : J} :
limit_const_terminal.inv ≫ limit.π ((category_theory.functor.const J).obj (⊤_ C)) j =
terminal.from _ :=
by ext ⟨⟨⟩⟩
instance {J : Type*} [category J] {C : Type*} [category C] [has_initial C] :
has_colimit ((category_theory.functor.const J).obj (⊥_ C)) :=
has_colimit.mk
{ cocone :=
{ X := ⊥_ C,
ι := { app := λ _, initial.to _, }, },
is_colimit :=
{ desc := λ s, initial.to _, }, }
/-- The colimit of the constant `⊥_ C` functor is `⊥_ C`. -/
@[simps inv]
def colimit_const_initial {J : Type*} [category J] {C : Type*} [category C] [has_initial C] :
colimit ((category_theory.functor.const J).obj (⊥_ C)) ≅ ⊥_ C :=
{ hom := colimit.desc ((category_theory.functor.const J).obj (⊥_ C))
{ X := ⊥_ C, ι := { app := λ j, initial.to _, }, },
inv := initial.to _, }
@[simp, reassoc] lemma ι_colimit_const_initial_hom
{J : Type*} [category J] {C : Type*} [category C] [has_initial C] {j : J} :
colimit.ι ((category_theory.functor.const J).obj (⊥_ C)) j ≫ colimit_const_initial.hom =
initial.to _ :=
by ext ⟨⟨⟩⟩
/-- A category is a `initial_mono_class` if the canonical morphism of an initial object is a
monomorphism. In practice, this is most useful when given an arbitrary morphism out of the chosen
initial object, see `initial.mono_from`.
Given a terminal object, this is equivalent to the assumption that the unique morphism from initial
to terminal is a monomorphism, which is the second of Freyd's axioms for an AT category.
TODO: This is a condition satisfied by categories with zero objects and morphisms.
-/
class initial_mono_class (C : Type u₁) [category.{v₁} C] : Prop :=
(is_initial_mono_from : ∀ {I} (X : C) (hI : is_initial I), mono (hI.to X))
lemma is_initial.mono_from [initial_mono_class C] {I} {X : C} (hI : is_initial I) (f : I ⟶ X) :
mono f :=
begin
rw hI.hom_ext f (hI.to X),
apply initial_mono_class.is_initial_mono_from,
end
@[priority 100]
instance initial.mono_from [has_initial C] [initial_mono_class C] (X : C) (f : ⊥_ C ⟶ X) :
mono f :=
initial_is_initial.mono_from f
/-- To show a category is a `initial_mono_class` it suffices to give an initial object such that
every morphism out of it is a monomorphism. -/
lemma initial_mono_class.of_is_initial {I : C} (hI : is_initial I) (h : ∀ X, mono (hI.to X)) :
initial_mono_class C :=
{ is_initial_mono_from := λ I' X hI',
begin
rw hI'.hom_ext (hI'.to X) ((hI'.unique_up_to_iso hI).hom ≫ hI.to X),
apply mono_comp,
end }
/-- To show a category is a `initial_mono_class` it suffices to show every morphism out of the
initial object is a monomorphism. -/
lemma initial_mono_class.of_initial [has_initial C] (h : ∀ X : C, mono (initial.to X)) :
initial_mono_class C :=
initial_mono_class.of_is_initial initial_is_initial h
/-- To show a category is a `initial_mono_class` it suffices to show the unique morphism from an
initial object to a terminal object is a monomorphism. -/
lemma initial_mono_class.of_is_terminal {I T : C} (hI : is_initial I) (hT : is_terminal T)
(f : mono (hI.to T)) :
initial_mono_class C :=
initial_mono_class.of_is_initial hI (λ X, mono_of_mono_fac (hI.hom_ext (_ ≫ hT.from X) (hI.to T)))
/-- To show a category is a `initial_mono_class` it suffices to show the unique morphism from the
initial object to a terminal object is a monomorphism. -/
lemma initial_mono_class.of_terminal [has_initial C] [has_terminal C]
(h : mono (initial.to (⊤_ C))) :
initial_mono_class C :=
initial_mono_class.of_is_terminal initial_is_initial terminal_is_terminal h
section comparison
variables {D : Type u₂} [category.{v₂} D] (G : C ⥤ D)
/--
The comparison morphism from the image of a terminal object to the terminal object in the target
category.
This is an isomorphism iff `G` preserves terminal objects, see
`category_theory.limits.preserves_terminal.of_iso_comparison`.
-/
def terminal_comparison [has_terminal C] [has_terminal D] :
G.obj (⊤_ C) ⟶ ⊤_ D :=
terminal.from _
/--
The comparison morphism from the initial object in the target category to the image of the initial
object.
-/
-- TODO: Show this is an isomorphism if and only if `G` preserves initial objects.
def initial_comparison [has_initial C] [has_initial D] :
⊥_ D ⟶ G.obj (⊥_ C) :=
initial.to _
end comparison
variables {J : Type u} [category.{v} J]
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cone for `J`.
In `limit_of_diagram_initial` we show it is a limit cone. -/
@[simps]
def cone_of_diagram_initial
{X : J} (tX : is_initial X) (F : J ⥤ C) : cone F :=
{ X := F.obj X,
π :=
{ app := λ j, F.map (tX.to j),
naturality' := λ j j' k,
begin
dsimp,
rw [← F.map_comp, category.id_comp, tX.hom_ext (tX.to j ≫ k) (tX.to j')],
end } }
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, show the cone
`cone_of_diagram_initial` is a limit. -/
def limit_of_diagram_initial
{X : J} (tX : is_initial X) (F : J ⥤ C) :
is_limit (cone_of_diagram_initial tX F) :=
{ lift := λ s, s.π.app X,
uniq' := λ s m w,
begin
rw [← w X, cone_of_diagram_initial_π_app, tX.hom_ext (tX.to X) (𝟙 _)],
dsimp, simp -- See note [dsimp, simp]
end}
-- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has an initial object then the image of it is isomorphic
to the limit of `F`. -/
@[reducible]
def limit_of_initial (F : J ⥤ C)
[has_initial J] [has_limit F] :
limit F ≅ F.obj (⊥_ J) :=
is_limit.cone_point_unique_up_to_iso
(limit.is_limit _)
(limit_of_diagram_initial initial_is_initial F)
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cone for `J`,
provided that the morphisms in the diagram are isomorphisms.
In `limit_of_diagram_terminal` we show it is a limit cone. -/
@[simps]
def cone_of_diagram_terminal {X : J} (hX : is_terminal X)
(F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : cone F :=
{ X := F.obj X,
π :=
{ app := λ i, inv (F.map (hX.from _)),
naturality' := begin
intros i j f,
dsimp,
simp only [is_iso.eq_inv_comp, is_iso.comp_inv_eq, category.id_comp,
← F.map_comp, hX.hom_ext (hX.from i) (f ≫ hX.from j)],
end } }
/-- From a functor `F : J ⥤ C`, given a terminal object of `J` and that the morphisms in the
diagram are isomorphisms, show the cone `cone_of_diagram_terminal` is a limit. -/
def limit_of_diagram_terminal {X : J} (hX : is_terminal X)
(F : J ⥤ C) [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
is_limit (cone_of_diagram_terminal hX F) :=
{ lift := λ S, S.π.app _ }
-- This is reducible to allow usage of lemmas about `cone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has a terminal object and all the morphisms in the diagram
are isomorphisms, then the image of the terminal object is isomorphic to the limit of `F`. -/
@[reducible]
def limit_of_terminal (F : J ⥤ C)
[has_terminal J] [has_limit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
limit F ≅ F.obj (⊤_ J) :=
is_limit.cone_point_unique_up_to_iso
(limit.is_limit _)
(limit_of_diagram_terminal terminal_is_terminal F)
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, construct a cocone for `J`.
In `colimit_of_diagram_terminal` we show it is a colimit cocone. -/
@[simps]
def cocone_of_diagram_terminal
{X : J} (tX : is_terminal X) (F : J ⥤ C) : cocone F :=
{ X := F.obj X,
ι :=
{ app := λ j, F.map (tX.from j),
naturality' := λ j j' k,
begin
dsimp,
rw [← F.map_comp, category.comp_id, tX.hom_ext (k ≫ tX.from j') (tX.from j)],
end } }
/-- From a functor `F : J ⥤ C`, given a terminal object of `J`, show the cocone
`cocone_of_diagram_terminal` is a colimit. -/
def colimit_of_diagram_terminal
{X : J} (tX : is_terminal X) (F : J ⥤ C) :
is_colimit (cocone_of_diagram_terminal tX F) :=
{ desc := λ s, s.ι.app X,
uniq' := λ s m w,
by { rw [← w X, cocone_of_diagram_terminal_ι_app, tX.hom_ext (tX.from X) (𝟙 _)], simp } }
-- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has a terminal object then the image of it is isomorphic
to the colimit of `F`. -/
@[reducible]
def colimit_of_terminal (F : J ⥤ C)
[has_terminal J] [has_colimit F] :
colimit F ≅ F.obj (⊤_ J) :=
is_colimit.cocone_point_unique_up_to_iso
(colimit.is_colimit _)
(colimit_of_diagram_terminal terminal_is_terminal F)
/-- From a functor `F : J ⥤ C`, given an initial object of `J`, construct a cocone for `J`,
provided that the morphisms in the diagram are isomorphisms.
In `colimit_of_diagram_initial` we show it is a colimit cocone. -/
@[simps]
def cocone_of_diagram_initial {X : J} (hX : is_initial X) (F : J ⥤ C)
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : cocone F :=
{ X := F.obj X,
ι :=
{ app := λ i, inv (F.map (hX.to _)),
naturality' := begin
intros i j f,
dsimp,
simp only [is_iso.eq_inv_comp, is_iso.comp_inv_eq, category.comp_id,
← F.map_comp, hX.hom_ext (hX.to i ≫ f) (hX.to j)],
end } }
/-- From a functor `F : J ⥤ C`, given an initial object of `J` and that the morphisms in the
diagram are isomorphisms, show the cone `cocone_of_diagram_initial` is a colimit. -/
def colimit_of_diagram_initial {X : J} (hX : is_initial X) (F : J ⥤ C)
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_colimit (cocone_of_diagram_initial hX F) :=
{ desc := λ S, S.ι.app _ }
-- This is reducible to allow usage of lemmas about `cocone_point_unique_up_to_iso`.
/-- For a functor `F : J ⥤ C`, if `J` has an initial object and all the morphisms in the diagram
are isomorphisms, then the image of the initial object is isomorphic to the colimit of `F`. -/
@[reducible]
def colimit_of_initial (F : J ⥤ C)
[has_initial J] [has_colimit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] :
colimit F ≅ F.obj (⊥_ J) :=
is_colimit.cocone_point_unique_up_to_iso
(colimit.is_colimit _)
(colimit_of_diagram_initial initial_is_initial _)
/--
If `j` is initial in the index category, then the map `limit.π F j` is an isomorphism.
-/
lemma is_iso_π_of_is_initial {j : J} (I : is_initial j) (F : J ⥤ C) [has_limit F] :
is_iso (limit.π F j) :=
⟨⟨limit.lift _ (cone_of_diagram_initial I F), ⟨by { ext, simp }, by simp⟩⟩⟩
instance is_iso_π_initial [has_initial J] (F : J ⥤ C) [has_limit F] :
is_iso (limit.π F (⊥_ J)) :=
is_iso_π_of_is_initial (initial_is_initial) F
lemma is_iso_π_of_is_terminal {j : J} (I : is_terminal j) (F : J ⥤ C)
[has_limit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (limit.π F j) :=
⟨⟨limit.lift _ (cone_of_diagram_terminal I F), by { ext, simp }, by simp ⟩⟩
instance is_iso_π_terminal [has_terminal J] (F : J ⥤ C) [has_limit F]
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (limit.π F (⊤_ J)) :=
is_iso_π_of_is_terminal terminal_is_terminal F
/--
If `j` is terminal in the index category, then the map `colimit.ι F j` is an isomorphism.
-/
lemma is_iso_ι_of_is_terminal {j : J} (I : is_terminal j) (F : J ⥤ C) [has_colimit F] :
is_iso (colimit.ι F j) :=
⟨⟨colimit.desc _ (cocone_of_diagram_terminal I F), ⟨by simp, by { ext, simp }⟩⟩⟩
instance is_iso_ι_terminal [has_terminal J] (F : J ⥤ C) [has_colimit F] :
is_iso (colimit.ι F (⊤_ J)) :=
is_iso_ι_of_is_terminal (terminal_is_terminal) F
lemma is_iso_ι_of_is_initial {j : J} (I : is_initial j) (F : J ⥤ C)
[has_colimit F] [∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (colimit.ι F j) :=
⟨⟨colimit.desc _ (cocone_of_diagram_initial I F), ⟨by tidy, by { ext, simp }⟩⟩⟩
instance is_iso_ι_initial [has_initial J] (F : J ⥤ C) [has_colimit F]
[∀ (i j : J) (f : i ⟶ j), is_iso (F.map f)] : is_iso (colimit.ι F (⊥_ J)) :=
is_iso_ι_of_is_initial initial_is_initial F
end
end category_theory.limits
|
064a3cc4fcc9684fdd580eccd0f40f0143db85eb | 7c4610454cf55b49f0c3cdaeb6b856eb3249cb2d | /src/relatively_prime.lean | c658c009b8e902f623e88650af58e973d78fc135 | [] | no_license | 101damnations/fg_over_pid | 097be43e11c3680a3fd4b6de2265de393cf4d4ef | a1a587c455a54a802f6ff61b07bb033701e451a7 | refs/heads/master | 1,669,708,904,636 | 1,597,259,770,000 | 1,597,259,770,000 | 287,097,363 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,169 | lean |
import ring_theory.principal_ideal_domain set_lemmas linear_algebra.basic torsion
open unique_factorization_domain multiset associates
variables {R : Type*} [integral_domain R] [is_principal_ideal_ring R] [decidable_eq R]
[decidable_eq (associates R)] (r : R)
open_locale classical
local infix ` ~ᵤ ` : 50 := associated
noncomputable theory
@[reducible] def mk' := map associates.mk (factors r)
/-- Given `r, w : R`, multiset of irreducible factors of `r` which are not associated to `w`.-/
def of_dvd' (w : R) : multiset R :=
(filter (λ x, ¬ x ~ᵤ w) $ factors r)
/-- Given `r = p₁ ^ k₁ * ... * pₙ ^ kₙ : R` with pᵢ prime, this is the finite set
`{(r / p₁ ^ k₁), ..., (r / pₙ ^ kₙ)}`. -/
def coprimes' := finset.image (multiset.prod ∘ of_dvd' r) (factors r).to_finset
variables (hr : r ≠ 0)
include hr
lemma prod_factors_eq : prod (mk' r) = associates.mk r :=
by rw [prod_mk, mk_eq_mk_iff_associated]; exact factors_prod hr
variables {w : associates R} {t : R}
/-- If t is an irred factor of r, it divides r. -/
lemma le_of_mem (t) (h : t ∈ factors r) : t ∣ r :=
begin
have := multiset.dvd_prod h,
rwa ←dvd_iff_dvd_of_rel_right (factors_prod hr),
end
/-- Given `r t : R`, if `i : ℕ` is the highest power to which `t` divides `r` and *`t` is irreducible*,
i.e. `r = p₁ ^ k₁ * ... * pₙ ^ kₙ * t ^ i` for some primes pᵢ and t prime, then there exist
`(q₁ ^ k₁ * ... * qₙ ^ kₙ) * (s₁ * ... * sᵢ) = r` where each `qⱼ` is associated to each `pⱼ` and each
`sⱼ` is associated to `t`. -/
lemma prod_of_dvd_eq' (t : R) :
(of_dvd' r t).prod * (filter (λ x, x ~ᵤ t) $ factors r).prod ~ᵤ r :=
begin
unfold of_dvd',
rw ←multiset.prod_add,
rw add_comm,
rw filter_add_not,
exact factors_prod hr,
end
/-- For any irreducible factor `t` of `r`, if `i : ℕ` is the highest power to which
`t` divides `r` then `r \ t ^ i` divides `r`. -/
lemma of_dvd'_dvd : (of_dvd' r t).prod ∣ r :=
begin
cases prod_of_dvd_eq' r hr t with u hu,
rw mul_assoc at hu,
use (filter (λ x, x ~ᵤ t) $ factors r).prod * u,
rw hu,
end
/-- If `q ∈ coprimes' r` (see coprimes' defn), `q` divides `r`. -/
lemma le_of_mem_coprimes' (q : R) (hq : q ∈ coprimes' r) :
q ∣ r :=
begin
unfold coprimes' at hq,
rw finset.mem_image at hq,
rcases hq with ⟨i, hm, hi⟩,
have : r ~ᵤ q * (filter (λ x, x ~ᵤ i) $ factors r).prod,
by {rw ←hi, symmetry, convert prod_of_dvd_eq' r hr i },
cases (associated.symm this) with u hu,
rw mul_assoc at hu,
use (filter (λ x, x ~ᵤ i) $ factors r).prod * u,
exact hu.symm,
end
/-- If `r ≠ 0` and `t` divides `r`, t ≠ 0.-/
lemma ne_zero_of_dvd (h : t ∣ r) : t ≠ 0 :=
λ ht0, hr $ zero_dvd_iff.1 $ ht0 ▸ h
/-- If `r ≠ 0`, for any irreducible factor `t` of `r`, if `i : ℕ` is the highest power to which
`t` divides `r` then `r \ t ^ i ≠ 0`. -/
lemma ne_zero_of_dvd' : (of_dvd' r t).prod ≠ 0 :=
ne_zero_of_dvd r hr (of_dvd'_dvd r hr)
/-- Given 2 primes `p q : R`, if one divides the other they are associated. -/
lemma prime_dvd_prime {p q : R} (hp : prime p) (hq : prime q) (hpq : p ∣ q) : p ~ᵤ q :=
begin
have hpq' := hpq,
cases hpq with u hu,
have : q ∣ p * u := ⟨1, by rw hu; rw mul_one⟩,
cases hq.2.2 _ _ this,
exact associated_of_dvd_dvd hpq' h,
cases h with t ht,
rw ht at hu,
have H : q * (1 - p * t) = 0, by {rw mul_sub, rw ←mul_assoc, rw mul_comm q p,
rw mul_assoc, rw ←hu, ring,},
rw mul_eq_zero at H, cases H with h1 h2,
exfalso,
exact hq.1 h1,
rw sub_eq_zero at h2,
exfalso,
exact hp.2.1 (is_unit_of_mul_eq_one p t h2.symm),
end
/-- For any irreducible factor `t` of `r`, if `i : ℕ` is the highest power to which
`t` divides `r` then `t` doesn't divide `r \ t ^ i`. -/
lemma not_le_of_dvd' (hm : t ∈ factors r) : ¬t ∣ (of_dvd' r t).prod :=
λ h,
begin
rcases exists_mem_factors_of_dvd (ne_zero_of_dvd' r hr) (irreducible_factors hr t hm)
h with ⟨q, hmq, hq⟩,
rcases exists_mem_multiset_dvd_of_prime (prime_factors (ne_zero_of_dvd' r hr) q hmq)
(le_of_mem (of_dvd' r t).prod (ne_zero_of_dvd' r hr) q hmq) with ⟨p, hmp, hqp⟩,
have hp : prime p := prime_factors hr p (filter_subset _ hmp),
have ht := associated.trans hq (prime_dvd_prime r hr (prime_factors (ne_zero_of_dvd' r hr) q hmq) hp hqp),
exact (mem_filter.1 hmp ).2 (associated.symm ht),
end
def wtf : is_monoid_hom (associates.mk) :=
{ map_mul := λ x y : R, associates.mk_mul_mk,
map_one := associates.one_eq_mk_one }
variables (hu : ¬is_unit r)
include hu
/-- If `r : R` isn't a unit, there exists an irreducible element dividing `r`. -/
lemma exists_mem_of_nonunit : ∃ p, p ∈ factors r :=
exists_mem_of_ne_zero
(λ h, absurd (by rw [←is_unit_mk, is_unit_iff_eq_one, ←prod_factors_eq r hr,
@multiset.prod_hom _ _ _ _ (factors r) (associates.mk) (wtf r hr), h, prod_zero,
associates.one_eq_mk_one]) hu)
/-- If `r : R` isn't a unit, the set `coprimes' r` (see the defn in this file) is nonempty. -/
lemma exists_mem_coprimes'_of_nonunit : ∃ q, q ∈ coprimes' r :=
let ⟨w, h⟩ := exists_mem_of_nonunit r hr hu in
finset.nonempty_iff_ne_empty.2 (λ hn, absurd (finset.image_eq_empty.1 hn)
(finset.ne_empty_of_mem (mem_to_finset.2 h)))
/-- Given nonunit nonzero `r : R` and `t : R`, if for all `q` in the set
"Given `r = p₁ ^ k₁ * ... * pₙ ^ kₙ : R` with pᵢ prime, the finite set
`{(r / p₁ ^ k₁), ..., (r / pₙ ^ kₙ)}`", t divides q, then t is a unit. -/
lemma relatively_prime' (H : ∀ q ∈ coprimes' r, t ∣ q) : is_unit t :=
begin
cases exists_mem_coprimes'_of_nonunit r hr hu,
apply (@not_not _ _).1, assume hnu,
have h' : t ≠ 0, by
{intro hnu,
exact absurd hnu (by {specialize H w h, have := le_of_mem_coprimes' r hr w h,
exfalso, apply hr,
rw ←zero_dvd_iff,
rw hnu at H,
exact dvd_trans H this,})},
cases exists_mem_of_nonunit t h' hnu with x hx,
have hxm : ∃ y ∈ factors r, x ~ᵤ y,
by {apply exists_mem_factors_of_dvd hr (irreducible_factors h' x hx),
apply dvd_trans (le_of_mem t h' x hx),
apply dvd_trans (H w h) (le_of_mem_coprimes' r hr w h),
},
rcases hxm with ⟨y, hmy, hy⟩,
cases associated.symm hy with u hu,
have H' : x ∣ (of_dvd' r y).prod, by
{apply dvd_trans (le_of_mem t h' x hx),
exact H (of_dvd' r y).prod (finset.mem_image.2 (⟨y, mem_to_finset.2 hmy, rfl⟩)), },
exact not_le_of_dvd' r hr hmy (dvd_trans (⟨u, hu.symm⟩) H'),
apply_instance
end
omit hr hu
/-- Given `s : multiset R` and `p : R`, the multiset of elements of `s` associated to `p` is
equal modulo association to a (number-of-elements-of-s-associated-to-p)-tuple of p's, modulo
association. -/
lemma associated_pow' {n : ℕ} {s : multiset R} (h : s.card = n) {p : R} :
map associates.mk (filter (λ x, x ~ᵤ p) s) =
map associates.mk (repeat p (filter (λ x, x ~ᵤ p) s).card) :=
begin
revert s,
induction n with n hn,
intros s h0,
rw card_eq_zero.1 h0, simp only [filter_zero, card_zero, map_zero, repeat_zero],
intros s hs,
cases card_pos_iff_exists_mem.1 (by rw hs; exact n.succ_pos) with a ha,
cases exists_cons_of_mem ha with t ht,
rw ht,
cases (classical.em (associated a p)),
rw @filter_cons_of_pos R (λ x, associated x p) _ _ t h,
rw map_cons, rw card_cons, rw repeat_succ, rw map_cons,
rw mk_eq_mk_iff_associated.2 h,
rw hn (by {rw ht at hs, rw card_cons at hs, exact nat.succ.inj hs}),
rw @filter_cons_of_neg R (λ x, associated x p) _ _ t h,
rw hn (by {rw ht at hs, rw card_cons at hs, exact nat.succ.inj hs}),
end
/-- Given multisets `s, t ⊆ R` if s equals t up to association, the product of the
elements of s is associated to the product of the elements of t. -/
lemma associated_prod {n : ℕ} {s t : multiset R} (hs : s.card = n)
(ht : t.card = n) (h : map associates.mk s = map associates.mk t) :
associates.mk s.prod = associates.mk t.prod :=
begin
revert s t,
induction n with n hn,
intros s t hs ht h,
rw card_eq_zero.1 hs,
rw card_eq_zero.1 ht,
intros s t hs ht h,
cases card_pos_iff_exists_mem.1 (by rw hs; exact n.succ_pos) with a ha,
cases exists_cons_of_mem ha with b hb,
cases card_pos_iff_exists_mem.1 (by rw ht; exact n.succ_pos) with c hc,
cases exists_cons_of_mem hc with d hd,
rw hb, rw hd,
rw prod_cons, rw prod_cons,
rw ←mk_mul_mk,
rw ←mk_mul_mk,
rw hb at h, rw hd at h,
rw map_cons at h, rw map_cons at h,
rw cons_eq_cons at h,
cases h with h h,
have hn' := hn (by {rw hb at hs, rw card_cons at hs, exact nat.succ.inj hs})
(by {rw hd at ht, rw card_cons at ht, exact nat.succ.inj ht}) h.2,
rw hn', rw h.1,
cases h with h1 h2,
cases h2 with cs hcs,
cases subset_map (show cs ≤ map associates.mk b, by rw hcs.1; exact le_cons_self _ _) with u hu,
rw hu at hcs,
rw ←map_cons at hcs, rw ←map_cons at hcs,
have hbu := hn (by {rw hb at hs, rw card_cons at hs, exact nat.succ.inj hs})
(show (c :: u).card = n, by {rw ←card_map associates.mk, rw ←hcs.1,
rw card_map,
rw hb at hs, rw card_cons at hs, exact nat.succ.inj hs}) hcs.1,
rw hbu, rw prod_cons,
have hdu := hn (by {rw hd at ht, rw card_cons at ht, exact nat.succ.inj ht})
(show (a :: u).card = n, by {rw ←card_map associates.mk, rw ←hcs.2,
rw card_map,
rw hd at ht, rw card_cons at ht, exact nat.succ.inj ht}) hcs.2,
rw hdu, rw prod_cons, rw ←associates.mk_mul_mk,
rw ←associates.mk_mul_mk,
rw ←mul_assoc, rw mul_comm (associates.mk a), rw mul_assoc,
end
/-- Let `r, p : R` with `p` prime. Then
`p ^ ((number of elements of a factorisation of irred factors of r associated to p) + 1)`
does not divide `r`. -/
lemma fin_pow_dvd {r p : R} (hr : r ≠ 0) (hp : prime p) :
¬((p ^ ((filter (λ x, associated x p) (factors r)).card + 1)) ∣ r) :=
begin
intro h,
cases h with z hz,
have ha := @associated_pow' _ _ _ _ _ _ (unique_factorization_domain.factors r) rfl p,
have ha' := associated_prod rfl (card_repeat _ _) ha,
cases mk_eq_mk_iff_associated.1 ha' with u hu,
rw prod_repeat at hu,
rw pow_succ at hz,
rw ←hu at hz,
have hnf := @filter_add_not _ (λ x, associated x p) _ (factors r),
have hf : (factors r).prod = ((filter (λ (x : R), x ~ᵤ p) (factors r)).prod *
(filter (λ (a : R), ¬(λ (x : R), x ~ᵤ p) a) (factors r)).prod) := by
{rw ←multiset.prod_add, rw hnf},
cases (factors_prod hr) with w hw,
conv at hz {to_lhs, rw ←hw, rw hf},
rw ←mul_assoc p at hz,
rw mul_comm p at hz,
rw ←sub_eq_zero at hz,
repeat {rw mul_assoc at hz},
rw ←mul_sub at hz,
have h0 := or.resolve_left (mul_eq_zero.1 hz) (by {intro hp0,
have huh := prod_eq_zero_iff'.1 hp0,
exact not_prime_zero ((prime_iff_of_associated (mem_filter.1 huh).2).2 hp),
}),
rw sub_eq_zero at h0,
have h0' := units.eq_mul_inv_iff_mul_eq.2 h0,
rcases exists_mem_multiset_dvd_of_prime hp (by {rw h0', exact ⟨(u : R) * z * (w⁻¹ : units R),
by rw mul_assoc⟩}) with ⟨s, hms, hs⟩,
have hms := mem_filter.1 hms,
have hps := prime_dvd_prime r hr hp (prime_factors hr s hms.1) hs,
exact hms.2 hps.symm,
end |
0d669bc67f649e051bb6f3091a2f3653e538ebcf | e00ea76a720126cf9f6d732ad6216b5b824d20a7 | /src/analysis/calculus/mean_value.lean | 11ae358f739caa66584f56215c37b05bda91b2ba | [
"Apache-2.0"
] | permissive | vaibhavkarve/mathlib | a574aaf68c0a431a47fa82ce0637f0f769826bfe | 17f8340912468f49bdc30acdb9a9fa02eeb0473a | refs/heads/master | 1,621,263,802,637 | 1,585,399,588,000 | 1,585,399,588,000 | 250,833,447 | 0 | 0 | Apache-2.0 | 1,585,410,341,000 | 1,585,410,341,000 | null | UTF-8 | Lean | false | false | 38,685 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.calculus.local_extr
import analysis.convex.topology
/-!
# The mean value inequality and equalities
In this file we prove the following facts:
* `convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentaible on a convex set `s`
and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with
constant `C`.
* `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or
`∥f x∥ ≤ B x` from upper estimates on `f'` or `∥f'∥`, respectively. These lemmas differ by
their assumptions:
* `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`;
* `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative
or its norm is less than `B' x`;
* `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `∥f x∥ = B x`;
* `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`;
* name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]`
and has a right derivative at every point of `[a, b)`, and (2) the lemma has
a counterpart assuming that `B` is differentiable everywhere on `ℝ`
* `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above
by a constant `C`, then `∥f x - f a∥ ≤ C * ∥x - a∥`; several versions deal with
right derivative and derivative within `[a, b]` (`has_deriv_within_at` or `deriv_within`).
* `convex.is_const_of_fderiv_within_eq_zero` : if a function has derivative `0` on a convex set `s`,
then it is a constant on `s`.
* `exists_ratio_has_deriv_at_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` :
Cauchy's Mean Value Theorem.
* `exists_has_deriv_at_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem.
* `convex.image_sub_lt_mul_sub_of_deriv_lt`, `convex.mul_sub_lt_image_sub_of_lt_deriv`,
`convex.image_sub_le_mul_sub_of_deriv_le`, `convex.mul_sub_le_image_sub_of_le_deriv`,
if `∀ x, C (</≤/>/≥) (f' x)`, then `C * (y - x) (</≤/>/≥) (f y - f x)` whenever `x < y`.
* `convex.mono_of_deriv_nonneg`, `convex.antimono_of_deriv_nonpos`,
`convex.strict_mono_of_deriv_pos`, `convex.strict_antimono_of_deriv_neg` :
if the derivative of a function is non-negative/non-positive/positive/negative, then
the function is monotone/monotonically decreasing/strictly monotone/strictly monotonically
decreasing.
* `convex_on_of_deriv_mono`, `convex_on_of_deriv2_nonneg` : if the derivative of a function
is increasing or its second derivative is nonnegative, then the original function is convex.
-/
set_option class.instance_max_depth 120
variables {E : Type*} [normed_group E] [normed_space ℝ E]
{F : Type*} [normed_group F] [normed_space ℝ F]
open metric set asymptotics continuous_linear_map filter
open_locale classical topological_space
/-! ### One-dimensional fencing inequalities -/
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf (z - x)⁻¹ * (f z - f x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r →
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (f z - f x) < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
begin
change Icc a b ⊆ {x | f x ≤ B x},
set s := {x | f x ≤ B x} ∩ Icc a b,
have A : continuous_on (λ x, (f x, B x)) (Icc a b), from hf.prod hB,
have : is_closed s,
{ simp only [s, inter_comm],
exact A.preimage_closed_of_closed is_closed_Icc (order_closed_topology.is_closed_le' _) },
apply this.Icc_subset_of_forall_exists_gt ha,
rintros x ⟨hxB, xab⟩ y hy,
change f x ≤ B x at hxB,
cases lt_or_eq_of_le hxB with hxB hxB,
{ -- If `f x < B x`, then all we need is continuity of both sides
apply nonempty_of_mem_sets (nhds_within_Ioi_self_ne_bot x),
refine inter_mem_sets _ (Ioc_mem_nhds_within_Ioi ⟨le_refl x, hy⟩),
have : ∀ᶠ x in nhds_within x (Icc a b), f x < B x,
from A x (Ico_subset_Icc_self xab)
(mem_nhds_sets (is_open_lt continuous_fst continuous_snd) hxB),
have : ∀ᶠ x in nhds_within x (Ioi x), f x < B x,
from nhds_within_le_of_mem (Icc_mem_nhds_within_Ioi xab) this,
refine mem_sets_of_superset this (set_of_subset_set_of.2 $ λ y, le_of_lt) },
{ rcases dense (bound x xab hxB) with ⟨r, hfr, hrB⟩,
specialize hf' x xab r hfr,
have HB : ∀ᶠ z in nhds_within x (Ioi x), r < (z - x)⁻¹ * (B z - B x),
from (has_deriv_within_at_iff_tendsto_slope' $ lt_irrefl x).1 (hB' x xab)
(mem_nhds_sets is_open_Ioi hrB),
obtain ⟨z, ⟨hfz, hzB⟩, hz⟩ :
∃ z, ((z - x)⁻¹ * (f z - f x) < r ∧ r < (z - x)⁻¹ * (B z - B x)) ∧ z ∈ Ioc x y,
from ((hf'.and_eventually HB).and_eventually
(Ioc_mem_nhds_within_Ioi ⟨le_refl _, hy⟩)).exists,
have := le_of_lt (lt_trans hfz hzB),
refine ⟨z, _, hz⟩,
rw [mul_le_mul_left (inv_pos.2 $ sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this,
exact this }
end
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf (z - x)⁻¹ * (f z - f x) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r →
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (f z - f x) < r)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, has_deriv_at B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha
(λ x hx, (hB x).continuous_at.continuous_within_at)
(λ x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)`
is bounded above by `B'`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
-- `bound` actually says `liminf (z - x)⁻¹ * (f z - f x) ≤ B' x`
(bound : ∀ x ∈ Ico a b, ∀ r, B' x < r →
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (f z - f x) < r) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
begin
have Hr : ∀ x ∈ Icc a b, ∀ r ∈ Ioi (0:ℝ), f x ≤ B x + r * (x - a),
{ intros x hx r hr,
apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound,
{ rwa [sub_self, mul_zero, add_zero] },
{ exact hB.add (continuous_on_const.mul
(continuous_id.continuous_on.sub continuous_on_const)) },
{ assume x hx,
exact (hB' x hx).add (((has_deriv_within_at_id x (Ioi x)).sub_const a).const_mul r) },
{ assume x hx _,
rw [mul_one],
exact (lt_add_iff_pos_right _).2 hr },
exact hx },
assume x hx,
have : continuous_within_at (λ r, B x + r * (x - a)) (Ioi 0) 0,
from continuous_within_at_const.add (continuous_within_at_id.mul continuous_within_at_const),
convert continuous_within_at_const.closure_le _ this (Hr x hx); simp [closure_Ioi]
end
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has right derivative `B'` at every point of `[a, b)`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' hf
(λ x hx r hr, (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x < B' x` whenever `f x = B x`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, has_deriv_at B (B' x) x)
(bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha
(λ x hx, (hB x).continuous_at.continuous_within_at)
(λ x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `f a ≤ B a`;
* `B` has derivative `B'` everywhere on `ℝ`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* we have `f' x ≤ B' x` on `[a, b)`.
Then `f x ≤ B x` everywhere on `[a, b]`. -/
lemma image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, f' x ≤ B' x) :
∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' $
assume x hx r hr, (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr)
/-! ### Vector-valued functions `f : ℝ → E` -/
section
variables {f : ℝ → E} {a b : ℝ}
/-- General fencing theorem for continuous functions with an estimate on the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `∥f a∥ ≤ B a`;
* `B` has right derivative at every point of `[a, b)`;
* for each `x ∈ [a, b)` the right-side limit inferior of `(∥f z∥ - ∥f x∥) / (z - x)`
is bounded above by a function `f'`;
* we have `f' x < B' x` whenever `∥f x∥ = B x`.
Then `∥f x∥ ≤ B x` everywhere on `[a, b]`. -/
lemma image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [normed_group E]
{f : ℝ → E} {f' : ℝ → ℝ} (hf : continuous_on f (Icc a b))
-- `hf'` actually says `liminf ∥z - x∥⁻¹ * (∥f z∥ - ∥f x∥) ≤ f' x`
(hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r →
∃ᶠ z in nhds_within x (Ioi x), (z - x)⁻¹ * (∥f z∥ - ∥f x∥) < r)
{B B' : ℝ → ℝ} (ha : ∥f a∥ ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, ∥f x∥ = B x → f' x < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → ∥f x∥ ≤ B x :=
image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuous_on hf) hf'
ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `∥f a∥ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* the norm of `f'` is strictly less than `B'` whenever `∥f x∥ = B x`.
Then `∥f x∥ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : ∥f a∥ ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, ∥f x∥ = B x → ∥f' x∥ < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → ∥f x∥ ≤ B x :=
image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf
(λ x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `∥f a∥ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* the norm of `f'` is strictly less than `B'` whenever `∥f x∥ = B x`.
Then `∥f x∥ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : ∥f a∥ ≤ B a) (hB : ∀ x, has_deriv_at B (B' x) x)
(bound : ∀ x ∈ Ico a b, ∥f x∥ = B x → ∥f' x∥ < B' x) :
∀ ⦃x⦄, x ∈ Icc a b → ∥f x∥ ≤ B x :=
image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha
(λ x hx, (hB x).continuous_at.continuous_within_at)
(λ x hx, (hB x).has_deriv_within_at) bound
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `∥f a∥ ≤ B a`;
* `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`;
* we have `∥f' x∥ ≤ B x` everywhere on `[a, b)`.
Then `∥f x∥ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : ∥f a∥ ≤ B a) (hB : continuous_on B (Icc a b))
(hB' : ∀ x ∈ Ico a b, has_deriv_within_at B (B' x) (Ioi x) x)
(bound : ∀ x ∈ Ico a b, ∥f' x∥ ≤ B' x) :
∀ ⦃x⦄, x ∈ Icc a b → ∥f x∥ ≤ B x :=
image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuous_on hf) ha hB hB' $
(λ x hx r hr, (hf' x hx).liminf_right_slope_norm_le (lt_of_le_of_lt (bound x hx) hr))
/-- General fencing theorem for continuous functions with an estimate on the norm of the derivative.
Let `f` and `B` be continuous functions on `[a, b]` such that
* `∥f a∥ ≤ B a`;
* `f` has right derivative `f'` at every point of `[a, b)`;
* `B` has derivative `B'` everywhere on `ℝ`;
* we have `∥f' x∥ ≤ B x` everywhere on `[a, b)`.
Then `∥f x∥ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions
to make this theorem work for piecewise differentiable functions.
-/
lemma image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
{B B' : ℝ → ℝ} (ha : ∥f a∥ ≤ B a) (hB : ∀ x, has_deriv_at B (B' x) x)
(bound : ∀ x ∈ Ico a b, ∥f' x∥ ≤ B' x) :
∀ ⦃x⦄, x ∈ Icc a b → ∥f x∥ ≤ B x :=
image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha
(λ x hx, (hB x).continuous_at.continuous_within_at)
(λ x hx, (hB x).has_deriv_within_at) bound
/-- A function on `[a, b]` with the norm of the right derivative bounded by `C`
satisfies `∥f x - f a∥ ≤ C * (x - a)`. -/
theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ}
(hf : continuous_on f (Icc a b))
(hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ioi x) x)
(bound : ∀x ∈ Ico a b, ∥f' x∥ ≤ C) :
∀ x ∈ Icc a b, ∥f x - f a∥ ≤ C * (x - a) :=
begin
let g := λ x, f x - f a,
have hg : continuous_on g (Icc a b), from hf.sub continuous_on_const,
have hg' : ∀ x ∈ Ico a b, has_deriv_within_at g (f' x) (Ioi x) x,
{ assume x hx,
simpa using (hf' x hx).sub (has_deriv_within_at_const _ _ _) },
let B := λ x, C * (x - a),
have hB : ∀ x, has_deriv_at B C x,
{ assume x,
simpa using (has_deriv_at_const x C).mul ((has_deriv_at_id x).sub (has_deriv_at_const x a)) },
convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound,
{ simp only [g, B] },
{ simp only [g, B], rw [sub_self, _root_.norm_zero, sub_self, mul_zero] }
end
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `∥f x - f a∥ ≤ C * (x - a)`, `has_deriv_within_at`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc a b, has_deriv_within_at f (f' x) (Icc a b) x)
(bound : ∀x ∈ Ico a b, ∥f' x∥ ≤ C) :
∀ x ∈ Icc a b, ∥f x - f a∥ ≤ C * (x - a) :=
begin
refine norm_image_sub_le_of_norm_deriv_right_le_segment
(λ x hx, (hf x hx).continuous_within_at) (λ x hx, _) bound,
apply (hf x $ Ico_subset_Icc_self hx).nhds_within,
exact Icc_mem_nhds_within_Ioi hx
end
/-- A function on `[a, b]` with the norm of the derivative within `[a, b]`
bounded by `C` satisfies `∥f x - f a∥ ≤ C * (x - a)`, `deriv_within`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : differentiable_on ℝ f (Icc a b))
(bound : ∀x ∈ Ico a b, ∥deriv_within f (Icc a b) x∥ ≤ C) :
∀ x ∈ Icc a b, ∥f x - f a∥ ≤ C * (x - a) :=
begin
refine norm_image_sub_le_of_norm_deriv_le_segment' _ bound,
exact λ x hx, (hf x hx).has_deriv_within_at
end
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `∥f 1 - f 0∥ ≤ C`, `has_deriv_within_at`
version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ}
(hf : ∀ x ∈ Icc (0:ℝ) 1, has_deriv_within_at f (f' x) (Icc (0:ℝ) 1) x)
(bound : ∀x ∈ Ico (0:ℝ) 1, ∥f' x∥ ≤ C) :
∥f 1 - f 0∥ ≤ C :=
by simpa only [sub_zero, mul_one]
using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one)
/-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]`
bounded by `C` satisfies `∥f 1 - f 0∥ ≤ C`, `deriv_within` version. -/
theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ}
(hf : differentiable_on ℝ f (Icc (0:ℝ) 1))
(bound : ∀x ∈ Ico (0:ℝ) 1, ∥deriv_within f (Icc (0:ℝ) 1) x∥ ≤ C) :
∥f 1 - f 0∥ ≤ C :=
by simpa only [sub_zero, mul_one]
using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one)
end
/-! ### Vector-valued functions `f : E → F` -/
/-- The mean value theorem on a convex set: if the derivative of a function is bounded by C, then
the function is C-Lipschitz -/
theorem convex.norm_image_sub_le_of_norm_deriv_le {f : E → F} {C : ℝ} {s : set E} {x y : E}
(hf : differentiable_on ℝ f s) (bound : ∀x∈s, ∥fderiv_within ℝ f s x∥ ≤ C)
(hs : convex s) (xs : x ∈ s) (ys : y ∈ s) : ∥f y - f x∥ ≤ C * ∥y - x∥ :=
begin
/- By composition with t ↦ x + t • (y-x), we reduce to a statement for functions defined
on [0,1], for which it is proved in `norm_image_sub_le_of_norm_deriv_le_segment`.
We just have to check the differentiability of the composition and bounds on its derivative,
which is straightforward but tedious for lack of automation. -/
have C0 : 0 ≤ C := le_trans (norm_nonneg _) (bound x xs),
set g : ℝ → E := λ t, x + t • (y - x),
have Dg : ∀ t, has_deriv_at g (y-x) t,
{ assume t,
simpa only [one_smul] using ((has_deriv_at_id t).smul_const (y - x)).const_add x },
have segm : Icc 0 1 ⊆ g ⁻¹' s,
{ rw [← image_subset_iff, ← segment_eq_image'],
apply hs.segment_subset xs ys },
have : f x = f (g 0), by { simp only [g], rw [zero_smul, add_zero] },
rw this,
have : f y = f (g 1), by { simp only [g], rw [one_smul, add_sub_cancel'_right] },
rw this,
have D2: ∀ t ∈ Icc (0:ℝ) 1, has_deriv_within_at (f ∘ g)
((fderiv_within ℝ f s (g t) : E → F) (y-x)) (Icc (0:ℝ) 1) t,
{ intros t ht,
exact (hf (g t) $ segm ht).has_fderiv_within_at.comp_has_deriv_within_at _
(Dg t).has_deriv_within_at segm },
apply norm_image_sub_le_of_norm_deriv_le_segment_01' D2,
assume t ht,
refine le_trans (le_op_norm _ _) (mul_le_mul_of_nonneg_right _ (norm_nonneg _)),
exact bound (g t) (segm $ Ico_subset_Icc_self ht)
end
/-- If a function has zero Fréchet derivative at every point of a convex set,
then it is a constant on this set. -/
theorem convex.is_const_of_fderiv_within_eq_zero {s : set E} (hs : convex s)
{f : E → F} (hf : differentiable_on ℝ f s) (hf' : ∀ x ∈ s, fderiv_within ℝ f s x = 0)
{x y : E} (hx : x ∈ s) (hy : y ∈ s) :
f x = f y :=
have bound : ∀ x ∈ s, ∥fderiv_within ℝ f s x∥ ≤ 0,
from λ x hx, by simp only [hf' x hx, _root_.norm_zero],
by simpa only [(dist_eq_norm _ _).symm, zero_mul, dist_le_zero, eq_comm]
using hs.norm_image_sub_le_of_norm_deriv_le hf bound hx hy
theorem is_const_of_fderiv_eq_zero {f : E → F} (hf : differentiable ℝ f)
(hf' : ∀ x, fderiv ℝ f x = 0) (x y : E) :
f x = f y :=
convex_univ.is_const_of_fderiv_within_eq_zero hf.differentiable_on
(λ x _, by rw fderiv_within_univ; exact hf' x) trivial trivial
/-! ### Functions `[a, b] → ℝ`. -/
section interval
-- Declare all variables here to make sure they come in a correct order
variables (f f' : ℝ → ℝ) {a b : ℝ} (hab : a < b) (hfc : continuous_on f (Icc a b))
(hff' : ∀ x ∈ Ioo a b, has_deriv_at f (f' x) x) (hfd : differentiable_on ℝ f (Ioo a b))
(g g' : ℝ → ℝ) (hgc : continuous_on g (Icc a b)) (hgg' : ∀ x ∈ Ioo a b, has_deriv_at g (g' x) x)
(hgd : differentiable_on ℝ g (Ioo a b))
include hab hfc hff' hgc hgg'
/-- Cauchy's Mean Value Theorem, `has_deriv_at` version. -/
lemma exists_ratio_has_deriv_at_eq_ratio_slope :
∃ c ∈ Ioo a b, (g b - g a) * f' c = (f b - f a) * g' c :=
begin
let h := λ x, (g b - g a) * f x - (f b - f a) * g x,
have hI : h a = h b,
{ simp only [h], ring },
let h' := λ x, (g b - g a) * f' x - (f b - f a) * g' x,
have hhh' : ∀ x ∈ Ioo a b, has_deriv_at h (h' x) x,
from λ x hx, ((hff' x hx).const_mul (g b - g a)).sub ((hgg' x hx).const_mul (f b - f a)),
have hhc : continuous_on h (Icc a b),
from (continuous_on_const.mul hfc).sub (continuous_on_const.mul hgc),
rcases exists_has_deriv_at_eq_zero h h' hab hhc hI hhh' with ⟨c, cmem, hc⟩,
exact ⟨c, cmem, sub_eq_zero.1 hc⟩
end
omit hgc hgg'
/-- Lagrange's Mean Value Theorem, `has_deriv_at` version -/
lemma exists_has_deriv_at_eq_slope : ∃ c ∈ Ioo a b, f' c = (f b - f a) / (b - a) :=
begin
rcases exists_ratio_has_deriv_at_eq_ratio_slope f f' hab hfc hff'
id 1 continuous_id.continuous_on (λ x hx, has_deriv_at_id x) with ⟨c, cmem, hc⟩,
use [c, cmem],
simp only [_root_.id, pi.one_apply, mul_one] at hc,
rw [← hc, mul_div_cancel_left],
exact ne_of_gt (sub_pos.2 hab)
end
omit hff'
/-- Cauchy's Mean Value Theorem, `deriv` version. -/
lemma exists_ratio_deriv_eq_ratio_slope :
∃ c ∈ Ioo a b, (g b - g a) * (deriv f c) = (f b - f a) * (deriv g c) :=
exists_ratio_has_deriv_at_eq_ratio_slope f (deriv f) hab hfc
(λ x hx, ((hfd x hx).differentiable_at $ mem_nhds_sets is_open_Ioo hx).has_deriv_at)
g (deriv g) hgc (λ x hx, ((hgd x hx).differentiable_at $ mem_nhds_sets is_open_Ioo hx).has_deriv_at)
/-- Lagrange's Mean Value Theorem, `deriv` version. -/
lemma exists_deriv_eq_slope : ∃ c ∈ Ioo a b, deriv f c = (f b - f a) / (b - a) :=
exists_has_deriv_at_eq_slope f (deriv f) hab hfc
(λ x hx, ((hfd x hx).differentiable_at $ mem_nhds_sets is_open_Ioo hx).has_deriv_at)
end interval
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C < f'`, then
`f` grows faster than `C * x` on `D`, i.e., `C * (y - x) < f y - f x` whenever `x, y ∈ D`,
`x < y`. -/
theorem convex.mul_sub_lt_image_sub_of_lt_deriv {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
{C} (hf'_gt : ∀ x ∈ interior D, C < deriv f x) :
∀ x y ∈ D, x < y → C * (y - x) < f y - f x :=
begin
assume x y hx hy hxy,
have hxyD : Icc x y ⊆ D, from convex_real_iff.1 hD hx hy,
have hxyD' : Ioo x y ⊆ interior D,
from subset_sUnion_of_mem ⟨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyD⟩,
obtain ⟨a, a_mem, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD'),
have : C < (f y - f x) / (y - x), by { rw [← ha], exact hf'_gt _ (hxyD' a_mem) },
exact (lt_div_iff (sub_pos.2 hxy)).1 this
end
/-- Let `f : ℝ → ℝ` be a differentiable function. If `C < f'`, then `f` grows faster than
`C * x`, i.e., `C * (y - x) < f y - f x` whenever `x < y`. -/
theorem mul_sub_lt_image_sub_of_lt_deriv {f : ℝ → ℝ} (hf : differentiable ℝ f)
{C} (hf'_gt : ∀ x, C < deriv f x) ⦃x y⦄ (hxy : x < y) :
C * (y - x) < f y - f x :=
convex_univ.mul_sub_lt_image_sub_of_lt_deriv hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf'_gt x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `C ≤ f'`, then
`f` grows at least as fast as `C * x` on `D`, i.e., `C * (y - x) ≤ f y - f x` whenever `x, y ∈ D`,
`x ≤ y`. -/
theorem convex.mul_sub_le_image_sub_of_le_deriv {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
{C} (hf'_ge : ∀ x ∈ interior D, C ≤ deriv f x) :
∀ x y ∈ D, x ≤ y → C * (y - x) ≤ f y - f x :=
begin
assume x y hx hy hxy,
cases eq_or_lt_of_le hxy with hxy' hxy', by rw [hxy', sub_self, sub_self, mul_zero],
have hxyD : Icc x y ⊆ D, from convex_real_iff.1 hD hx hy,
have hxyD' : Ioo x y ⊆ interior D,
from subset_sUnion_of_mem ⟨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyD⟩,
obtain ⟨a, a_mem, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy' (hf.mono hxyD) (hf'.mono hxyD'),
have : C ≤ (f y - f x) / (y - x), by { rw [← ha], exact hf'_ge _ (hxyD' a_mem) },
exact (le_div_iff (sub_pos.2 hxy')).1 this
end
/-- Let `f : ℝ → ℝ` be a differentiable function. If `C ≤ f'`, then `f` grows at least as fast
as `C * x`, i.e., `C * (y - x) ≤ f y - f x` whenever `x ≤ y`. -/
theorem mul_sub_le_image_sub_of_le_deriv {f : ℝ → ℝ} (hf : differentiable ℝ f)
{C} (hf'_ge : ∀ x, C ≤ deriv f x) ⦃x y⦄ (hxy : x ≤ y) :
C * (y - x) ≤ f y - f x :=
convex_univ.mul_sub_le_image_sub_of_le_deriv hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf'_ge x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' < C`, then
`f` grows slower than `C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x, y ∈ D`,
`x < y`. -/
theorem convex.image_sub_lt_mul_sub_of_deriv_lt {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
{C} (lt_hf' : ∀ x ∈ interior D, deriv f x < C) :
∀ x y ∈ D, x < y → f y - f x < C * (y - x) :=
begin
assume x y hx hy hxy,
have hf'_gt : ∀ x ∈ interior D, -C < deriv (λ y, -f y) x,
{ assume x hx,
rw [deriv_neg, neg_lt_neg_iff],
exact lt_hf' x hx },
simpa [-neg_lt_neg_iff]
using neg_lt_neg (hD.mul_sub_lt_image_sub_of_lt_deriv hf.neg hf'.neg hf'_gt x y hx hy hxy)
end
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f' < C`, then `f` grows slower than
`C * x` on `D`, i.e., `f y - f x < C * (y - x)` whenever `x < y`. -/
theorem image_sub_lt_mul_sub_of_deriv_lt {f : ℝ → ℝ} (hf : differentiable ℝ f)
{C} (lt_hf' : ∀ x, deriv f x < C) ⦃x y⦄ (hxy : x < y) :
f y - f x < C * (y - x) :=
convex_univ.image_sub_lt_mul_sub_of_deriv_lt hf.continuous.continuous_on hf.differentiable_on
(λ x _, lt_hf' x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f' ≤ C`, then
`f` grows at most as fast as `C * x` on `D`, i.e., `f y - f x ≤ C * (y - x)` whenever `x, y ∈ D`,
`x ≤ y`. -/
theorem convex.image_sub_le_mul_sub_of_deriv_le {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
{C} (le_hf' : ∀ x ∈ interior D, deriv f x ≤ C) :
∀ x y ∈ D, x ≤ y → f y - f x ≤ C * (y - x) :=
begin
assume x y hx hy hxy,
have hf'_ge : ∀ x ∈ interior D, -C ≤ deriv (λ y, -f y) x,
{ assume x hx,
rw [deriv_neg, neg_le_neg_iff],
exact le_hf' x hx },
simpa [-neg_le_neg_iff]
using neg_le_neg (hD.mul_sub_le_image_sub_of_le_deriv hf.neg hf'.neg hf'_ge x y hx hy hxy)
end
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f' ≤ C`, then `f` grows at most as fast
as `C * x`, i.e., `f y - f x ≤ C * (y - x)` whenever `x ≤ y`. -/
theorem image_sub_le_mul_sub_of_deriv_le {f : ℝ → ℝ} (hf : differentiable ℝ f)
{C} (le_hf' : ∀ x, deriv f x ≤ C) ⦃x y⦄ (hxy : x ≤ y) :
f y - f x ≤ C * (y - x) :=
convex_univ.image_sub_le_mul_sub_of_deriv_le hf.continuous.continuous_on hf.differentiable_on
(λ x _, le_hf' x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is positive, then
`f` is a strictly monotonically increasing function on `D`. -/
theorem convex.strict_mono_of_deriv_pos {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'_pos : ∀ x ∈ interior D, 0 < deriv f x) :
∀ x y ∈ D, x < y → f x < f y :=
by simpa only [zero_mul, sub_pos] using hD.mul_sub_lt_image_sub_of_lt_deriv hf hf' hf'_pos
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is positive, then
`f` is a strictly monotonically increasing function. -/
theorem strict_mono_of_deriv_pos {f : ℝ → ℝ} (hf : differentiable ℝ f)
(hf'_pos : ∀ x, 0 < deriv f x) :
strict_mono f :=
λ x y hxy, convex_univ.strict_mono_of_deriv_pos hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf'_pos x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonnegative, then
`f` is a monotonically increasing function on `D`. -/
theorem convex.mono_of_deriv_nonneg {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'_nonneg : ∀ x ∈ interior D, 0 ≤ deriv f x) :
∀ x y ∈ D, x ≤ y → f x ≤ f y :=
by simpa only [zero_mul, sub_nonneg] using hD.mul_sub_le_image_sub_of_le_deriv hf hf' hf'_nonneg
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonnegative, then
`f` is a monotonically increasing function. -/
theorem mono_of_deriv_nonneg {f : ℝ → ℝ} (hf : differentiable ℝ f) (hf' : ∀ x, 0 ≤ deriv f x) :
monotone f :=
λ x y hxy, convex_univ.mono_of_deriv_nonneg hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf' x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is negative, then
`f` is a strictly monotonically decreasing function on `D`. -/
theorem convex.strict_antimono_of_deriv_neg {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'_neg : ∀ x ∈ interior D, deriv f x < 0) :
∀ x y ∈ D, x < y → f y < f x :=
by simpa only [zero_mul, sub_lt_zero] using hD.image_sub_lt_mul_sub_of_deriv_lt hf hf' hf'_neg
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is negative, then
`f` is a strictly monotonically decreasing function. -/
theorem strict_antimono_of_deriv_neg {f : ℝ → ℝ} (hf : differentiable ℝ f)
(hf' : ∀ x, deriv f x < 0) :
∀ ⦃x y⦄, x < y → f y < f x :=
λ x y hxy, convex_univ.strict_antimono_of_deriv_neg hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf' x) x y trivial trivial hxy
/-- Let `f` be a function continuous on a convex (or, equivalently, connected) subset `D`
of the real line. If `f` is differentiable on the interior of `D` and `f'` is nonpositive, then
`f` is a monotonically decreasing function on `D`. -/
theorem convex.antimono_of_deriv_nonpos {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'_nonpos : ∀ x ∈ interior D, deriv f x ≤ 0) :
∀ x y ∈ D, x ≤ y → f y ≤ f x :=
by simpa only [zero_mul, sub_nonpos] using hD.image_sub_le_mul_sub_of_deriv_le hf hf' hf'_nonpos
/-- Let `f : ℝ → ℝ` be a differentiable function. If `f'` is nonpositive, then
`f` is a monotonically decreasing function. -/
theorem antimono_of_deriv_nonpos {f : ℝ → ℝ} (hf : differentiable ℝ f) (hf' : ∀ x, deriv f x ≤ 0) :
∀ ⦃x y⦄, x ≤ y → f y ≤ f x :=
λ x y hxy, convex_univ.antimono_of_deriv_nonpos hf.continuous.continuous_on hf.differentiable_on
(λ x _, hf' x) x y trivial trivial hxy
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `D`. -/
theorem convex_on_of_deriv_mono {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'_mono : ∀ x y ∈ interior D, x ≤ y → deriv f x ≤ deriv f y) :
convex_on D f :=
convex_on_real_of_slope_mono_adjacent hD
begin
intros x y z hx hz hxy hyz,
-- First we prove some trivial inclusions
have hxzD : Icc x z ⊆ D, from convex_real_iff.1 hD hx hz,
have hxyD : Icc x y ⊆ D, from subset.trans (Icc_subset_Icc_right $ le_of_lt hyz) hxzD,
have hxyD' : Ioo x y ⊆ interior D,
from subset_sUnion_of_mem ⟨is_open_Ioo, subset.trans Ioo_subset_Icc_self hxyD⟩,
have hyzD : Icc y z ⊆ D, from subset.trans (Icc_subset_Icc_left $ le_of_lt hxy) hxzD,
have hyzD' : Ioo y z ⊆ interior D,
from subset_sUnion_of_mem ⟨is_open_Ioo, subset.trans Ioo_subset_Icc_self hyzD⟩,
-- Then we apply MVT to both `[x, y]` and `[y, z]`
obtain ⟨a, ⟨hxa, hay⟩, ha⟩ : ∃ a ∈ Ioo x y, deriv f a = (f y - f x) / (y - x),
from exists_deriv_eq_slope f hxy (hf.mono hxyD) (hf'.mono hxyD'),
obtain ⟨b, ⟨hyb, hbz⟩, hb⟩ : ∃ b ∈ Ioo y z, deriv f b = (f z - f y) / (z - y),
from exists_deriv_eq_slope f hyz (hf.mono hyzD) (hf'.mono hyzD'),
rw [← ha, ← hb],
exact hf'_mono a b (hxyD' ⟨hxa, hay⟩) (hyzD' ⟨hyb, hbz⟩) (le_of_lt $ lt_trans hay hyb)
end
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is differentiable on its interior,
and `f'` is monotone on the interior, then `f` is convex on `ℝ`. -/
theorem convex_on_univ_of_deriv_mono {f : ℝ → ℝ} (hf : differentiable ℝ f)
(hf'_mono : monotone (deriv f)) : convex_on univ f :=
convex_on_of_deriv_mono convex_univ hf.continuous.continuous_on hf.differentiable_on
(λ x y _ _ h, hf'_mono h)
/-- If a function `f` is continuous on a convex set `D ⊆ ℝ`, is twice differentiable on its interior,
and `f''` is nonnegative on the interior, then `f` is convex on `D`. -/
theorem convex_on_of_deriv2_nonneg {D : set ℝ} (hD : convex D) {f : ℝ → ℝ}
(hf : continuous_on f D) (hf' : differentiable_on ℝ f (interior D))
(hf'' : differentiable_on ℝ (deriv f) (interior D))
(hf''_nonneg : ∀ x ∈ interior D, 0 ≤ (deriv^[2] f x)) :
convex_on D f :=
convex_on_of_deriv_mono hD hf hf' $
assume x y hx hy hxy,
hD.interior.mono_of_deriv_nonneg hf''.continuous_on (by rwa [interior_interior])
(by rwa [interior_interior]) _ _ hx hy hxy
/-- If a function `f` is twice differentiable on `ℝ`, and `f''` is nonnegative on `ℝ`,
then `f` is convex on `ℝ`. -/
theorem convex_on_univ_of_deriv2_nonneg {f : ℝ → ℝ} (hf' : differentiable ℝ f)
(hf'' : differentiable ℝ (deriv f)) (hf''_nonneg : ∀ x, 0 ≤ (deriv^[2] f x)) :
convex_on univ f :=
convex_on_of_deriv2_nonneg convex_univ hf'.continuous.continuous_on hf'.differentiable_on
hf''.differentiable_on (λ x _, hf''_nonneg x)
|
420037dd61f6c9b59ad98a6129cc4d4df2fa0678 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/combinatorics/set_family/compression/uv.lean | 4c1dd364e0b6de9640d9a3b1979d3f3a7a1d0bd8 | [
"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,873 | lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import data.finset.card
/-!
# UV-compressions
This file defines UV-compression. It is an operation on a set family that reduces its shadow.
UV-compressing `a : α` along `u v : α` means replacing `a` by `(a ⊔ u) \ v` if `a` and `u` are
disjoint and `v ≤ a`. In some sense, it's moving `a` from `v` to `u`.
UV-compressions are immensely useful to prove the Kruskal-Katona theorem. The idea is that
compressing a set family might decrease the size of its shadow, so iterated compressions hopefully
minimise the shadow.
## Main declarations
* `uv.compress`: `compress u v a` is `a` compressed along `u` and `v`.
* `uv.compression`: `compression u v s` is the compression of the set family `s` along `u` and `v`.
It is the compressions of the elements of `s` whose compression is not already in `s` along with
the element whose compression is already in `s`. This way of splitting into what moves and what
does not ensures the compression doesn't squash the set family, which is proved by
`uv.card_compress`.
## Notation
`𝓒` (typed with `\MCC`) is notation for `uv.compression` in locale `finset_family`.
## Notes
Even though our emphasis is on `finset α`, we define UV-compressions more generally in a generalized
boolean algebra, so that one can use it for `set α`.
## TODO
Prove that compressing reduces the size of shadow. This result and some more already exist on the
branch `combinatorics`.
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
## Tags
compression, UV-compression, shadow
-/
open finset
variable {α : Type*}
/-- UV-compression is injective on the elements it moves. See `uv.compress`. -/
lemma sup_sdiff_inj_on [generalized_boolean_algebra α] (u v : α) :
{x | disjoint u x ∧ v ≤ x}.inj_on (λ x, (x ⊔ u) \ v) :=
begin
rintro a ha b hb hab,
have h : (a ⊔ u) \ v \ u ⊔ v = (b ⊔ u) \ v \ u ⊔ v,
{ dsimp at hab,
rw hab },
rwa [sdiff_sdiff_comm, ha.1.symm.sup_sdiff_cancel_right, sdiff_sdiff_comm,
hb.1.symm.sup_sdiff_cancel_right, sdiff_sup_cancel ha.2, sdiff_sup_cancel hb.2] at h,
end
-- The namespace is here to distinguish from other compressions.
namespace uv
/-! ### UV-compression in generalized boolean algebras -/
section generalized_boolean_algebra
variables [generalized_boolean_algebra α] [decidable_rel (@disjoint α _ _)]
[decidable_rel ((≤) : α → α → Prop)] {s : finset α} {u v a b : α}
local attribute [instance] decidable_eq_of_decidable_le
/-- To UV-compress `a`, if it doesn't touch `U` and does contain `V`, we remove `V` and
put `U` in. We'll only really use this when `|U| = |V|` and `U ∩ V = ∅`. -/
def compress (u v a : α) : α := if disjoint u a ∧ v ≤ a then (a ⊔ u) \ v else a
/-- To UV-compress a set family, we compress each of its elements, except that we don't want to
reduce the cardinality, so we keep all elements whose compression is already present. -/
def compression (u v : α) (s : finset α) :=
s.filter (λ a, compress u v a ∈ s) ∪ (s.image $ compress u v).filter (λ a, a ∉ s)
localized "notation `𝓒 ` := uv.compression" in finset_family
/-- `is_compressed u v s` expresses that `s` is UV-compressed. -/
def is_compressed (u v : α) (s : finset α) := 𝓒 u v s = s
lemma compress_of_disjoint_of_le (hua : disjoint u a) (hva : v ≤ a) :
compress u v a = (a ⊔ u) \ v :=
if_pos ⟨hua, hva⟩
/-- `a` is in the UV-compressed family iff it's in the original and its compression is in the
original, or it's not in the original but it's the compression of something in the original. -/
lemma mem_compression :
a ∈ 𝓒 u v s ↔ a ∈ s ∧ compress u v a ∈ s ∨ a ∉ s ∧ ∃ b ∈ s, compress u v b = a :=
by simp_rw [compression, mem_union, mem_filter, mem_image, and_comm (a ∉ s)]
@[simp] lemma compress_self (u a : α) : compress u u a = a :=
begin
unfold compress,
split_ifs,
{ exact h.1.symm.sup_sdiff_cancel_right },
{ refl }
end
@[simp] lemma compression_self (u : α) (s : finset α) : 𝓒 u u s = s :=
begin
unfold compression,
convert union_empty s,
{ ext a,
rw [mem_filter, compress_self, and_self] },
{ refine eq_empty_of_forall_not_mem (λ a ha, _),
simp_rw [mem_filter, mem_image, compress_self] at ha,
obtain ⟨⟨b, hb, rfl⟩, hb'⟩ := ha,
exact hb' hb }
end
/-- Any family is compressed along two identical elements. -/
lemma is_compressed_self (u : α) (s : finset α) : is_compressed u u s := compression_self u s
lemma compress_disjoint (u v : α) :
disjoint (s.filter (λ a, compress u v a ∈ s)) ((s.image $ compress u v).filter (λ a, a ∉ s)) :=
disjoint_left.2 $ λ a ha₁ ha₂, (mem_filter.1 ha₂).2 (mem_filter.1 ha₁).1
/-- Compressing an element is idempotent. -/
@[simp] lemma compress_idem (u v a : α) : compress u v (compress u v a) = compress u v a :=
begin
unfold compress,
split_ifs with h h',
{ rw [le_sdiff_iff.1 h'.2, sdiff_bot, sdiff_bot, sup_assoc, sup_idem] },
{ refl },
{ refl }
end
lemma compress_mem_compression (ha : a ∈ s) : compress u v a ∈ 𝓒 u v s :=
begin
rw mem_compression,
by_cases compress u v a ∈ s,
{ rw compress_idem,
exact or.inl ⟨h, h⟩ },
{ exact or.inr ⟨h, a, ha, rfl⟩ }
end
-- This is a special case of `compress_mem_compression` once we have `compression_idem`.
lemma compress_mem_compression_of_mem_compression (ha : a ∈ 𝓒 u v s) : compress u v a ∈ 𝓒 u v s :=
begin
rw mem_compression at ⊢ ha,
simp only [compress_idem, exists_prop],
obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha,
{ exact or.inl ⟨ha, ha⟩ },
{ exact or.inr ⟨by rwa compress_idem, b, hb, (compress_idem _ _ _).symm⟩ }
end
/-- Compressing a family is idempotent. -/
@[simp] lemma compression_idem (u v : α) (s : finset α) : 𝓒 u v (𝓒 u v s) = 𝓒 u v s :=
begin
have h : filter (λ a, compress u v a ∉ 𝓒 u v s) (𝓒 u v s) = ∅ :=
filter_false_of_mem (λ a ha h, h $ compress_mem_compression_of_mem_compression ha),
rw [compression, image_filter, h, image_empty, ←h],
exact filter_union_filter_neg_eq _ (compression u v s),
end
/-- Compressing a family doesn't change its size. -/
lemma card_compression (u v : α) (s : finset α) : (𝓒 u v s).card = s.card :=
begin
rw [compression, card_disjoint_union (compress_disjoint _ _), image_filter, card_image_of_inj_on,
←card_disjoint_union, filter_union_filter_neg_eq],
{ rw disjoint_iff_inter_eq_empty,
exact filter_inter_filter_neg_eq _ _ },
intros a ha b hb hab,
dsimp at hab,
rw [mem_coe, mem_filter, function.comp_app] at ha hb,
rw compress at ha hab,
split_ifs at ha hab with has,
{ rw compress at hb hab,
split_ifs at hb hab with hbs,
{ exact sup_sdiff_inj_on u v has hbs hab },
{ exact (hb.2 hb.1).elim } },
{ exact (ha.2 ha.1).elim }
end
/-- If `a` is in the family compression and can be compressed, then its compression is in the
original family. -/
lemma sup_sdiff_mem_of_mem_compression (ha : a ∈ 𝓒 u v s) (hva : v ≤ a) (hua : disjoint u a) :
(a ⊔ u) \ v ∈ s :=
begin
rw [mem_compression, compress_of_disjoint_of_le hua hva] at ha,
obtain ⟨_, ha⟩ | ⟨_, b, hb, rfl⟩ := ha,
{ exact ha },
have hu : u = ⊥,
{ suffices : disjoint u (u \ v),
{ rwa [(hua.mono_right hva).sdiff_eq_left, disjoint_self] at this },
refine hua.mono_right _,
rw [←compress_idem, compress_of_disjoint_of_le hua hva],
exact sdiff_le_sdiff_right le_sup_right },
have hv : v = ⊥,
{ rw ←disjoint_self,
apply disjoint.mono_right hva,
rw [←compress_idem, compress_of_disjoint_of_le hua hva],
exact disjoint_sdiff_self_right },
rwa [hu, hv, compress_self, sup_bot_eq, sdiff_bot],
end
/-- If `a` is in the `u, v`-compression but `v ≤ a`, then `a` must have been in the original
family. -/
lemma mem_of_mem_compression (ha : a ∈ 𝓒 u v s) (hva : v ≤ a) (hvu : v = ⊥ → u = ⊥) : a ∈ s :=
begin
rw mem_compression at ha,
obtain ha | ⟨_, b, hb, h⟩ := ha,
{ exact ha.1 },
unfold compress at h,
split_ifs at h,
{ rw [←h, le_sdiff_iff] at hva,
rw [hvu hva, hva, sup_bot_eq, sdiff_bot] at h,
rwa ←h },
{ rwa ←h }
end
end generalized_boolean_algebra
/-! ### UV-compression on finsets -/
open_locale finset_family
variables [decidable_eq α] {𝒜 : finset (finset α)} {U V A : finset α}
/-- Compressing a finset doesn't change its size. -/
lemma card_compress (hUV : U.card = V.card) (A : finset α) : (compress U V A).card = A.card :=
begin
unfold compress,
split_ifs,
{ rw [card_sdiff (h.2.trans le_sup_left), sup_eq_union, card_disjoint_union h.1.symm, hUV,
add_tsub_cancel_right] },
{ refl }
end
end uv
|
e0eaa94220b9af2152a573be636b5e99ec44c684 | acc85b4be2c618b11fc7cb3005521ae6858a8d07 | /analysis/of_nat.lean | 1c91f839c02f09f36cf198d91b949e6cd2c8584a | [
"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,935 | 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
Morphism from `nat` into a semiring with 1.
TODO: move to `data.nat` and split into the different parts for `int`, `rat`, and `real`.
-/
import data.rat analysis.real
section of_nat
variables {α : Type*} [semiring α] {n : ℕ}
@[simp] def of_nat : ℕ → α
| 0 := 0
| (nat.succ n) := of_nat n + 1
@[simp] lemma of_nat_add : ∀{m}, of_nat (n + m) = (of_nat n + of_nat m : α)
| 0 := by simp
| (m + 1) := calc of_nat (n + (m + 1)) = of_nat (nat.succ (n + m)) :
by rw [nat.succ_eq_add_one]; simp
... = (of_nat n + of_nat (nat.succ m) : α) :
by simp [of_nat_add]
@[simp] lemma of_nat_one : of_nat 1 = (1 : α) :=
calc of_nat 1 = 0 + 1 : rfl
... = (1:α) : by simp
@[simp] lemma of_nat_mul : ∀{m}, of_nat (n * m) = (of_nat n * of_nat m : α)
| 0 := by simp
| (m + 1) := by simp [mul_add, of_nat_mul]
@[simp] lemma of_nat_bit0 : of_nat (bit0 n) = (bit0 (of_nat n) : α) := of_nat_add
@[simp] lemma of_nat_bit1 : of_nat (bit0 n) = (bit0 (of_nat n) : α) := of_nat_add
lemma of_nat_sub {α : Type*} [ring α] {n m : ℕ} (h : m ≤ n) :
of_nat (n - m) = (of_nat n - of_nat m : α) :=
calc of_nat (n - m) = (of_nat ((n - m) + m) - of_nat m : α) : by simp
... = (of_nat n - of_nat m : α) : by rw [nat.sub_add_cancel h]
end of_nat
lemma int_of_nat_eq_of_nat : ∀{n : ℕ}, int.of_nat n = of_nat n
| 0 := rfl
| (n + 1) := by simp [int.of_nat_add, int.of_nat_one, @int_of_nat_eq_of_nat n]
lemma rat_of_nat_eq_of_nat : ∀{n : ℕ}, (↑(of_nat n : ℤ) : ℚ) = of_nat n
| 0 := rfl
| (n + 1) :=
by rw [of_nat_add, rat.coe_int_add, of_nat_one, rat.coe_int_one, rat_of_nat_eq_of_nat]; simp
lemma rat_coe_eq_of_nat {n : ℕ} : (↑n : ℚ) = of_nat n :=
show ↑(int.of_nat n) = (of_nat n : ℚ), by rw [int_of_nat_eq_of_nat, rat_of_nat_eq_of_nat]
lemma real_of_rat_of_nat_eq_of_nat : ∀{n : ℕ}, of_rat (of_nat n) = of_nat n
| 0 := rfl
| (n+1) := by simp [of_rat_add.symm, of_rat_one.symm, real_of_rat_of_nat_eq_of_nat]
section of_nat_order
variables {α : Type*} [linear_ordered_semiring α]
lemma zero_le_of_nat : ∀{n}, 0 ≤ (of_nat n : α)
| 0 := le_refl 0
| (n + 1) := le_add_of_le_of_nonneg zero_le_of_nat (zero_le_one)
lemma of_nat_pos : ∀{n}, 0 < n → 0 < (of_nat n : α)
| 0 h := (lt_irrefl 0 h).elim
| (n + 1) h := by simp; exact lt_add_of_le_of_pos zero_le_of_nat zero_lt_one
lemma of_nat_le_of_nat {n m : ℕ} (h : n ≤ m) : of_nat n ≤ (of_nat m : α) :=
let ⟨k, hk⟩ := nat.le.dest h in
by simp [zero_le_of_nat, hk.symm]
lemma of_nat_le_of_nat_iff {n m : ℕ} : of_nat n ≤ (of_nat m : α) ↔ n ≤ m :=
suffices of_nat n ≤ (of_nat m : α) → n ≤ m,
from iff.intro this of_nat_le_of_nat,
begin
induction n generalizing m,
case nat.zero { simp [nat.zero_le] },
case nat.succ n ih {
cases m,
case nat.zero {
exact assume h,
have of_nat (n + 1) = (0:α), from le_antisymm h zero_le_of_nat,
have 1 ≤ (0:α),
from calc (1:α) ≤ of_nat n + 1 : le_add_of_nonneg_left zero_le_of_nat
... = (0:α) : this,
absurd this $ not_le_of_gt zero_lt_one },
case nat.succ m {
exact assume h,
have 1 + of_nat n ≤ (1 + of_nat m : α), by simp * at *,
have of_nat n ≤ (of_nat m : α), from le_of_add_le_add_left this,
show nat.succ n ≤ nat.succ m,
from nat.succ_le_succ $ ih this } }
end
end of_nat_order
lemma exists_lt_of_nat {r : ℝ} : ∃n, r < of_nat n :=
let ⟨q, hq⟩ := exists_lt_of_rat r in
⟨rat.nat_ceil q, calc r < of_rat q : hq
... ≤ of_rat (↑(int.of_nat $ rat.nat_ceil q)) : of_rat_le_of_rat.mpr $ rat.le_nat_ceil q
... = of_nat (rat.nat_ceil q) :
by simp [int_of_nat_eq_of_nat, rat_of_nat_eq_of_nat, real_of_rat_of_nat_eq_of_nat]⟩
|
e1d62411b2d67681ab27cd55686a8e8d70897cbf | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/linear_algebra/matrix/basis.lean | dd1d97858ab9c56aa20d2590bcb2746c20ea2d90 | [
"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 | 9,883 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
-/
import linear_algebra.matrix.nonsingular_inverse
import linear_algebra.matrix.reindex
import linear_algebra.matrix.to_lin
/-!
# Bases and matrices
This file defines the map `basis.to_matrix` that sends a family of vectors to
the matrix of their coordinates with respect to some basis.
## Main definitions
* `basis.to_matrix e v` is the matrix whose `i, j`th entry is `e.repr (v j) i`
* `basis.to_matrix_equiv` is `basis.to_matrix` bundled as a linear equiv
## Main results
* `linear_map.to_matrix_id_eq_basis_to_matrix`: `linear_map.to_matrix b c id`
is equal to `basis.to_matrix b c`
* `basis.to_matrix_mul_to_matrix`: multiplying `basis.to_matrix` with another
`basis.to_matrix` gives a `basis.to_matrix`
## Tags
matrix, basis
-/
noncomputable theory
open linear_map matrix set submodule
open_locale big_operators
open_locale matrix
section basis_to_matrix
variables {ι ι' κ κ' : Type*}
variables {R M : Type*} [comm_semiring R] [add_comm_monoid M] [module R M]
variables {R₂ M₂ : Type*} [comm_ring R₂] [add_comm_group M₂] [module R₂ M₂]
open function matrix
/-- From a basis `e : ι → M` and a family of vectors `v : ι' → M`, make the matrix whose columns
are the vectors `v i` written in the basis `e`. -/
def basis.to_matrix (e : basis ι R M) (v : ι' → M) : matrix ι ι' R :=
λ i j, e.repr (v j) i
variables (e : basis ι R M) (v : ι' → M) (i : ι) (j : ι')
namespace basis
lemma to_matrix_apply : e.to_matrix v i j = e.repr (v j) i :=
rfl
lemma to_matrix_transpose_apply : (e.to_matrix v)ᵀ j = e.repr (v j) :=
funext $ (λ _, rfl)
lemma to_matrix_eq_to_matrix_constr [fintype ι] [decidable_eq ι] (v : ι → M) :
e.to_matrix v = linear_map.to_matrix e e (e.constr ℕ v) :=
by { ext, rw [basis.to_matrix_apply, linear_map.to_matrix_apply, basis.constr_basis] }
-- TODO (maybe) Adjust the definition of `basis.to_matrix` to eliminate the transpose.
lemma coe_pi_basis_fun.to_matrix_eq_transpose [fintype ι] :
((pi.basis_fun R ι).to_matrix : matrix ι ι R → matrix ι ι R) = matrix.transpose :=
by { ext M i j, refl, }
@[simp] lemma to_matrix_self [decidable_eq ι] : e.to_matrix e = 1 :=
begin
rw basis.to_matrix,
ext i j,
simp [basis.equiv_fun, matrix.one_apply, finsupp.single, eq_comm]
end
lemma to_matrix_update [decidable_eq ι'] (x : M) :
e.to_matrix (function.update v j x) = matrix.update_column (e.to_matrix v) j (e.repr x) :=
begin
ext i' k,
rw [basis.to_matrix, matrix.update_column_apply, e.to_matrix_apply],
split_ifs,
{ rw [h, update_same j x v] },
{ rw update_noteq h },
end
/-- The basis constructed by `units_smul` has vectors given by a diagonal matrix. -/
@[simp] lemma to_matrix_units_smul [decidable_eq ι] (e : basis ι R₂ M₂) (w : ι → R₂ˣ) :
e.to_matrix (e.units_smul w) = diagonal (coe ∘ w) :=
begin
ext i j,
by_cases h : i = j,
{ simp [h, to_matrix_apply, units_smul_apply, units.smul_def] },
{ simp [h, to_matrix_apply, units_smul_apply, units.smul_def, ne.symm h] }
end
/-- The basis constructed by `is_unit_smul` has vectors given by a diagonal matrix. -/
@[simp] lemma to_matrix_is_unit_smul [decidable_eq ι] (e : basis ι R₂ M₂) {w : ι → R₂}
(hw : ∀ i, is_unit (w i)) :
e.to_matrix (e.is_unit_smul hw) = diagonal w :=
e.to_matrix_units_smul _
@[simp] lemma sum_to_matrix_smul_self [fintype ι] : ∑ (i : ι), e.to_matrix v i j • e i = v j :=
by simp_rw [e.to_matrix_apply, e.sum_repr]
lemma to_matrix_map_vec_mul {S : Type*} [ring S] [algebra R S] [fintype ι]
(b : basis ι R S) (v : ι' → S) :
((b.to_matrix v).map $ algebra_map R S).vec_mul b = v :=
begin
ext i,
simp_rw [vec_mul, dot_product, matrix.map_apply, ← algebra.commutes, ← algebra.smul_def,
sum_to_matrix_smul_self],
end
@[simp] lemma to_lin_to_matrix [fintype ι] [fintype ι'] [decidable_eq ι'] (v : basis ι' R M) :
matrix.to_lin v e (e.to_matrix v) = id :=
v.ext (λ i, by rw [to_lin_self, id_apply, e.sum_to_matrix_smul_self])
/-- From a basis `e : ι → M`, build a linear equivalence between families of vectors `v : ι → M`,
and matrices, making the matrix whose columns are the vectors `v i` written in the basis `e`. -/
def to_matrix_equiv [fintype ι] (e : basis ι R M) : (ι → M) ≃ₗ[R] matrix ι ι R :=
{ to_fun := e.to_matrix,
map_add' := λ v w, begin
ext i j,
change _ = _ + _,
rw [e.to_matrix_apply, pi.add_apply, linear_equiv.map_add],
refl
end,
map_smul' := begin
intros c v,
ext i j,
rw [e.to_matrix_apply, pi.smul_apply, linear_equiv.map_smul],
refl
end,
inv_fun := λ m j, ∑ i, (m i j) • e i,
left_inv := begin
intro v,
ext j,
exact e.sum_to_matrix_smul_self v j
end,
right_inv := begin
intros m,
ext k l,
simp only [e.to_matrix_apply, ← e.equiv_fun_apply, ← e.equiv_fun_symm_apply,
linear_equiv.apply_symm_apply],
end }
end basis
section mul_linear_map_to_matrix
variables {N : Type*} [add_comm_monoid N] [module R N]
variables (b : basis ι R M) (b' : basis ι' R M) (c : basis κ R N) (c' : basis κ' R N)
variables (f : M →ₗ[R] N)
open linear_map
section fintype
variables [fintype ι'] [fintype κ] [fintype κ']
@[simp] lemma basis_to_matrix_mul_linear_map_to_matrix [decidable_eq ι'] :
c.to_matrix c' ⬝ linear_map.to_matrix b' c' f = linear_map.to_matrix b' c f :=
(matrix.to_lin b' c).injective
(by haveI := classical.dec_eq κ';
rw [to_lin_to_matrix, to_lin_mul b' c' c, to_lin_to_matrix, c.to_lin_to_matrix, id_comp])
variable [fintype ι]
@[simp] lemma linear_map_to_matrix_mul_basis_to_matrix [decidable_eq ι] [decidable_eq ι'] :
linear_map.to_matrix b' c' f ⬝ b'.to_matrix b = linear_map.to_matrix b c' f :=
(matrix.to_lin b c').injective
(by rw [to_lin_to_matrix, to_lin_mul b b' c', to_lin_to_matrix, b'.to_lin_to_matrix, comp_id])
lemma basis_to_matrix_mul_linear_map_to_matrix_mul_basis_to_matrix
[decidable_eq ι] [decidable_eq ι'] :
c.to_matrix c' ⬝ linear_map.to_matrix b' c' f ⬝ b'.to_matrix b = linear_map.to_matrix b c f :=
by rw [basis_to_matrix_mul_linear_map_to_matrix, linear_map_to_matrix_mul_basis_to_matrix]
lemma basis_to_matrix_mul [decidable_eq κ]
(b₁ : basis ι R M) (b₂ : basis ι' R M) (b₃ : basis κ R N) (A : matrix ι' κ R) :
b₁.to_matrix b₂ ⬝ A = linear_map.to_matrix b₃ b₁ (to_lin b₃ b₂ A) :=
begin
have := basis_to_matrix_mul_linear_map_to_matrix b₃ b₁ b₂ (matrix.to_lin b₃ b₂ A),
rwa [linear_map.to_matrix_to_lin] at this
end
lemma mul_basis_to_matrix [decidable_eq ι] [decidable_eq ι']
(b₁ : basis ι R M) (b₂ : basis ι' R M) (b₃ : basis κ R N) (A : matrix κ ι R) :
A ⬝ b₁.to_matrix b₂ = linear_map.to_matrix b₂ b₃ (to_lin b₁ b₃ A) :=
begin
have := linear_map_to_matrix_mul_basis_to_matrix b₂ b₁ b₃ (matrix.to_lin b₁ b₃ A),
rwa [linear_map.to_matrix_to_lin] at this
end
lemma basis_to_matrix_basis_fun_mul (b : basis ι R (ι → R)) (A : matrix ι ι R) :
b.to_matrix (pi.basis_fun R ι) ⬝ A = of (λ i j, b.repr (Aᵀ j) i) :=
begin
classical,
simp only [basis_to_matrix_mul _ _ (pi.basis_fun R ι), matrix.to_lin_eq_to_lin'],
ext i j,
rw [linear_map.to_matrix_apply, matrix.to_lin'_apply, pi.basis_fun_apply,
matrix.mul_vec_std_basis_apply, matrix.of_apply]
end
/-- A generalization of `linear_map.to_matrix_id`. -/
@[simp] lemma linear_map.to_matrix_id_eq_basis_to_matrix [decidable_eq ι] :
linear_map.to_matrix b b' id = b'.to_matrix b :=
by { haveI := classical.dec_eq ι',
rw [←@basis_to_matrix_mul_linear_map_to_matrix _ _ ι, to_matrix_id, matrix.mul_one] }
/-- See also `basis.to_matrix_reindex` which gives the `simp` normal form of this result. -/
lemma basis.to_matrix_reindex' [decidable_eq ι] [decidable_eq ι']
(b : basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).to_matrix v = matrix.reindex_alg_equiv _ e (b.to_matrix (v ∘ e)) :=
by { ext, simp only [basis.to_matrix_apply, basis.reindex_repr, matrix.reindex_alg_equiv_apply,
matrix.reindex_apply, matrix.submatrix_apply, function.comp_app, e.apply_symm_apply] }
end fintype
/-- A generalization of `basis.to_matrix_self`, in the opposite direction. -/
@[simp] lemma basis.to_matrix_mul_to_matrix {ι'' : Type*} [fintype ι'] (b'' : ι'' → M) :
b.to_matrix b' ⬝ b'.to_matrix b'' = b.to_matrix b'' :=
begin
have := classical.dec_eq ι,
have := classical.dec_eq ι',
haveI := classical.dec_eq ι'',
ext i j,
simp only [matrix.mul_apply, basis.to_matrix_apply, basis.sum_repr_mul_repr],
end
/-- `b.to_matrix b'` and `b'.to_matrix b` are inverses. -/
lemma basis.to_matrix_mul_to_matrix_flip [decidable_eq ι] [fintype ι'] :
b.to_matrix b' ⬝ b'.to_matrix b = 1 :=
by rw [basis.to_matrix_mul_to_matrix, basis.to_matrix_self]
/-- A matrix whose columns form a basis `b'`, expressed w.r.t. a basis `b`, is invertible. -/
def basis.invertible_to_matrix [decidable_eq ι] [fintype ι] (b b' : basis ι R₂ M₂) :
invertible (b.to_matrix b') :=
matrix.invertible_of_left_inverse _ _ (basis.to_matrix_mul_to_matrix_flip _ _)
@[simp]
lemma basis.to_matrix_reindex
(b : basis ι R M) (v : ι' → M) (e : ι ≃ ι') :
(b.reindex e).to_matrix v = (b.to_matrix v).submatrix e.symm id :=
by { ext, simp only [basis.to_matrix_apply, basis.reindex_repr, matrix.submatrix_apply, id.def] }
@[simp]
lemma basis.to_matrix_map (b : basis ι R M) (f : M ≃ₗ[R] N) (v : ι → N) :
(b.map f).to_matrix v = b.to_matrix (f.symm ∘ v) :=
by { ext, simp only [basis.to_matrix_apply, basis.map, linear_equiv.trans_apply] }
end mul_linear_map_to_matrix
end basis_to_matrix
|
ebd63dd575f0f3a93d3080397cf581964dbd16a0 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/analysis/normed/group/hom_completion.lean | 2e3227117b81f5ccf27e0af185947e4f59335d9c | [
"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 | 11,156 | lean | /-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import analysis.normed.group.hom
import analysis.normed.group.completion
/-!
# Completion of normed group homs
Given two (semi) normed groups `G` and `H` and a normed group hom `f : normed_add_group_hom G H`,
we build and study a normed group hom
`f.completion : normed_add_group_hom (completion G) (completion H)` such that the diagram
```
f
G -----------> H
| |
| |
| |
V V
completion G -----------> completion H
f.completion
```
commutes. The map itself comes from the general theory of completion of uniform spaces, but here
we want a normed group hom, study its operator norm and kernel.
The vertical maps in the above diagrams are also normed group homs constructed in this file.
## Main definitions and results:
* `normed_add_group_hom.completion`: see the discussion above.
* `normed_add_comm_group.to_compl : normed_add_group_hom G (completion G)`: the canonical map from
`G` to its completion, as a normed group hom
* `normed_add_group_hom.completion_to_compl`: the above diagram indeed commutes.
* `normed_add_group_hom.norm_completion`: `∥f.completion∥ = ∥f∥`
* `normed_add_group_hom.ker_le_ker_completion`: the kernel of `f.completion` contains the image of
the kernel of `f`.
* `normed_add_group_hom.ker_completion`: the kernel of `f.completion` is the closure of the image of
the kernel of `f` under an assumption that `f` is quantitatively surjective onto its image.
* `normed_add_group_hom.extension` : if `H` is complete, the extension of
`f : normed_add_group_hom G H` to a `normed_add_group_hom (completion G) H`.
-/
noncomputable theory
open set normed_add_group_hom uniform_space
section completion
variables {G : Type*} [seminormed_add_comm_group G]
variables {H : Type*} [seminormed_add_comm_group H]
variables {K : Type*} [seminormed_add_comm_group K]
/-- The normed group hom induced between completions. -/
def normed_add_group_hom.completion (f : normed_add_group_hom G H) :
normed_add_group_hom (completion G) (completion H) :=
{ bound' := begin
use ∥f∥,
intro y,
apply completion.induction_on y,
{ exact is_closed_le
(continuous_norm.comp $ f.to_add_monoid_hom.continuous_completion f.continuous)
(continuous_const.mul continuous_norm) },
{ intro x,
change ∥f.to_add_monoid_hom.completion _ ↑x∥ ≤ ∥f∥ * ∥↑x∥,
rw f.to_add_monoid_hom.completion_coe f.continuous,
simp only [completion.norm_coe],
exact f.le_op_norm x }
end,
..f.to_add_monoid_hom.completion f.continuous }
lemma normed_add_group_hom.completion_def (f : normed_add_group_hom G H) (x : completion G) :
f.completion x = completion.map f x := rfl
@[simp]
lemma normed_add_group_hom.completion_coe_to_fun (f : normed_add_group_hom G H) :
(f.completion : completion G → completion H) = completion.map f :=
by { ext x, exact normed_add_group_hom.completion_def f x }
@[simp]
lemma normed_add_group_hom.completion_coe (f : normed_add_group_hom G H) (g : G) :
f.completion g = f g :=
completion.map_coe f.uniform_continuous _
/-- Completion of normed group homs as a normed group hom. -/
@[simps] def normed_add_group_hom_completion_hom :
normed_add_group_hom G H →+ normed_add_group_hom (completion G) (completion H) :=
{ to_fun := normed_add_group_hom.completion,
map_zero' := begin
apply to_add_monoid_hom_injective,
exact add_monoid_hom.completion_zero
end,
map_add' := λ f g, begin
apply to_add_monoid_hom_injective,
exact f.to_add_monoid_hom.completion_add g.to_add_monoid_hom f.continuous g.continuous,
end }
@[simp]
lemma normed_add_group_hom.completion_id :
(normed_add_group_hom.id G).completion = normed_add_group_hom.id (completion G) :=
begin
ext x,
rw [normed_add_group_hom.completion_def, normed_add_group_hom.coe_id, completion.map_id],
refl
end
lemma normed_add_group_hom.completion_comp (f : normed_add_group_hom G H)
(g : normed_add_group_hom H K) :
g.completion.comp f.completion = (g.comp f).completion :=
begin
ext x,
rw [normed_add_group_hom.coe_comp, normed_add_group_hom.completion_def,
normed_add_group_hom.completion_coe_to_fun, normed_add_group_hom.completion_coe_to_fun,
completion.map_comp (normed_add_group_hom.uniform_continuous _)
(normed_add_group_hom.uniform_continuous _)],
refl
end
lemma normed_add_group_hom.completion_neg (f : normed_add_group_hom G H) :
(-f).completion = -f.completion :=
map_neg (normed_add_group_hom_completion_hom : normed_add_group_hom G H →+ _) f
lemma normed_add_group_hom.completion_add (f g : normed_add_group_hom G H) :
(f + g).completion = f.completion + g.completion :=
normed_add_group_hom_completion_hom.map_add f g
lemma normed_add_group_hom.completion_sub (f g : normed_add_group_hom G H) :
(f - g).completion = f.completion - g.completion :=
map_sub (normed_add_group_hom_completion_hom : normed_add_group_hom G H →+ _) f g
@[simp]
lemma normed_add_group_hom.zero_completion : (0 : normed_add_group_hom G H).completion = 0 :=
normed_add_group_hom_completion_hom.map_zero
/-- The map from a normed group to its completion, as a normed group hom. -/
def normed_add_comm_group.to_compl : normed_add_group_hom G (completion G) :=
{ to_fun := coe,
map_add' := completion.to_compl.map_add,
bound' := ⟨1, by simp [le_refl]⟩ }
open normed_add_comm_group
lemma normed_add_comm_group.norm_to_compl (x : G) : ∥to_compl x∥ = ∥x∥ :=
completion.norm_coe x
lemma normed_add_comm_group.dense_range_to_compl : dense_range (to_compl : G → completion G) :=
completion.dense_inducing_coe.dense
@[simp]
lemma normed_add_group_hom.completion_to_compl (f : normed_add_group_hom G H) :
f.completion.comp to_compl = to_compl.comp f :=
begin
ext x,
change f.completion x = _,
simpa
end
@[simp] lemma normed_add_group_hom.norm_completion (f : normed_add_group_hom G H) :
∥f.completion∥ = ∥f∥ :=
begin
apply f.completion.op_norm_eq_of_bounds (norm_nonneg _),
{ intro x,
apply completion.induction_on x,
{ apply is_closed_le,
continuity },
{ intro g,
simp [f.le_op_norm g] } },
{ intros N N_nonneg hN,
apply f.op_norm_le_bound N_nonneg,
intro x,
simpa using hN x },
end
lemma normed_add_group_hom.ker_le_ker_completion (f : normed_add_group_hom G H) :
(to_compl.comp $ incl f.ker).range ≤ f.completion.ker :=
begin
intros a h,
replace h : ∃ y : f.ker, to_compl (y : G) = a, by simpa using h,
rcases h with ⟨⟨g, g_in : g ∈ f.ker⟩, rfl⟩,
rw f.mem_ker at g_in,
change f.completion (g : completion G) = 0,
simp [normed_add_group_hom.mem_ker, f.completion_coe g, g_in, completion.coe_zero],
end
lemma normed_add_group_hom.ker_completion {f : normed_add_group_hom G H} {C : ℝ}
(h : f.surjective_on_with f.range C) :
(f.completion.ker : set $ completion G) = closure (to_compl.comp $ incl f.ker).range :=
begin
rcases h.exists_pos with ⟨C', C'_pos, hC'⟩,
apply le_antisymm,
{ intros hatg hatg_in,
rw seminormed_add_comm_group.mem_closure_iff,
intros ε ε_pos,
have hCf : 0 ≤ C'*∥f∥ := (zero_le_mul_left C'_pos).mpr (norm_nonneg f),
have ineq : 0 < 1 + C'*∥f∥, by linarith,
set δ := ε/(1 + C'*∥f∥),
have δ_pos : δ > 0, from div_pos ε_pos ineq,
obtain ⟨_, ⟨g : G, rfl⟩, hg : ∥hatg - g∥ < δ⟩ := seminormed_add_comm_group.mem_closure_iff.mp
(completion.dense_inducing_coe.dense hatg) δ δ_pos,
obtain ⟨g' : G, hgg' : f g' = f g, hfg : ∥g'∥ ≤ C' * ∥f g∥⟩ :=
hC' (f g) (mem_range_self g),
have mem_ker : g - g' ∈ f.ker,
by rw [f.mem_ker, map_sub, sub_eq_zero.mpr hgg'.symm],
have : ∥f g∥ ≤ ∥f∥*∥hatg - g∥,
calc
∥f g∥ = ∥f.completion g∥ : by rw [f.completion_coe, completion.norm_coe]
... = ∥f.completion g - 0∥ : by rw [sub_zero _]
... = ∥f.completion g - (f.completion hatg)∥ : by rw [(f.completion.mem_ker _).mp hatg_in]
... = ∥f.completion (g - hatg)∥ : by rw [map_sub]
... ≤ ∥f.completion∥ * ∥(g :completion G) - hatg∥ : f.completion.le_op_norm _
... = ∥f∥ * ∥hatg - g∥ : by rw [norm_sub_rev, f.norm_completion],
have : ∥(g' : completion G)∥ ≤ C'*∥f∥*∥hatg - g∥,
calc
∥(g' : completion G)∥ = ∥g'∥ : completion.norm_coe _
... ≤ C' * ∥f g∥ : hfg
... ≤ C' * ∥f∥ * ∥hatg - g∥ : by { rw mul_assoc,
exact (mul_le_mul_left C'_pos).mpr this },
refine ⟨g - g', _, _⟩,
{ norm_cast,
rw normed_add_group_hom.comp_range,
apply add_subgroup.mem_map_of_mem,
simp only [incl_range, mem_ker] },
{ calc ∥hatg - (g - g')∥ = ∥hatg - g + g'∥ : by abel
... ≤ ∥hatg - g∥ + ∥(g' : completion G)∥ : norm_add_le _ _
... < δ + C'*∥f∥*∥hatg - g∥ : by linarith
... ≤ δ + C'*∥f∥*δ : add_le_add_left (mul_le_mul_of_nonneg_left hg.le hCf) δ
... = (1 + C'*∥f∥)*δ : by ring
... = ε : mul_div_cancel' _ ineq.ne.symm } },
{ rw ← f.completion.is_closed_ker.closure_eq,
exact closure_mono f.ker_le_ker_completion }
end
end completion
section extension
variables {G : Type*} [seminormed_add_comm_group G]
variables {H : Type*} [seminormed_add_comm_group H] [separated_space H] [complete_space H]
/-- If `H` is complete, the extension of `f : normed_add_group_hom G H` to a
`normed_add_group_hom (completion G) H`. -/
def normed_add_group_hom.extension (f : normed_add_group_hom G H) :
normed_add_group_hom (completion G) H :=
{ bound' := begin
refine ⟨∥f∥, λ v, completion.induction_on v (is_closed_le _ _) (λ a, _)⟩,
{ exact continuous.comp continuous_norm completion.continuous_extension },
{ exact continuous.mul continuous_const continuous_norm },
{ rw [completion.norm_coe, add_monoid_hom.to_fun_eq_coe, add_monoid_hom.extension_coe],
exact le_op_norm f a }
end,
..f.to_add_monoid_hom.extension f.continuous }
lemma normed_add_group_hom.extension_def (f : normed_add_group_hom G H) (v : G) :
f.extension v = completion.extension f v := rfl
@[simp] lemma normed_add_group_hom.extension_coe (f : normed_add_group_hom G H) (v : G) :
f.extension v = f v := add_monoid_hom.extension_coe _ f.continuous _
lemma normed_add_group_hom.extension_coe_to_fun (f : normed_add_group_hom G H) :
(f.extension : (completion G) → H) = completion.extension f := rfl
lemma normed_add_group_hom.extension_unique (f : normed_add_group_hom G H)
{g : normed_add_group_hom (completion G) H} (hg : ∀ v, f v = g v) : f.extension = g :=
begin
ext v,
rw [normed_add_group_hom.extension_coe_to_fun, completion.extension_unique f.uniform_continuous
g.uniform_continuous (λ a, hg a)]
end
end extension
|
ee33976fdd324d279cb9f3872a5a28efa83eaa7d | 3bdd27ffdff3ffa22d4bb010eba695afcc96bc4a | /src/combinatorics/simplicial_complex/convex_independence.lean | 745f0e4a0e9e266a1637c189c492c561c1821a35 | [] | no_license | mmasdeu/brouwerfixedpoint | 684d712c982c6a8b258b4e2c6b2eab923f2f1289 | 548270f79ecf12d7e20a256806ccb9fcf57b87e2 | refs/heads/main | 1,690,539,793,996 | 1,631,801,831,000 | 1,631,801,831,000 | 368,139,809 | 4 | 3 | null | 1,624,453,250,000 | 1,621,246,034,000 | Lean | UTF-8 | Lean | false | false | 4,260 | lean | /-
Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import analysis.convex.basic
import combinatorics.simplicial_complex.to_move.default
import data.finset.sort
import data.matrix.notation
import linear_algebra.affine_space.independent
open_locale affine big_operators classical
open finset
universes u₁ u₂
variables {E : Type u₁} [add_comm_group E] [module ℝ E]
variables {ι : Type u₂} {s t : set E}
def convex_independent (p : ι → E) : Prop :=
∀ (s : set ι) (x : ι), p x ∈ convex_hull (p '' s) → x ∈ s
lemma convex_independent.mono (hs : convex_independent (λ p, p : s → E)) (hts : t ⊆ s) :
convex_independent (λ p, p : t → E) :=
begin
rintro s x hs,
sorry
end
lemma convex_independent_set_iff (A : set E) :
convex_independent (λ p, p : A → E) ↔ ∀ s, s ⊆ A → A ∩ convex_hull s ⊆ s :=
begin
split,
{ rintro h s hs x ⟨hx₁, hx₂⟩,
have := h.mono hs,
/-suffices H : x ∈ convex_hull ((λ (p : A), ↑p) '' {x : A | ↑x ∈ s}),
{
have := h {x : A | ↑x ∈ s},
sorry
},-/
sorry
--simpa using h (s.attach.image (λ x, ⟨x.1, hs x.2⟩)) ⟨_, hx₁⟩ _,
--convert hx₂,
--ext y,
--simpa [←and_assoc] using @hs y
},
{ intros h s x hs,
simpa using h (s.image coe) (by simp) ⟨x.2, by simpa using hs⟩ }
end
lemma convex_independent_set_iff' (A : set E) :
convex_independent (λ p, p : A → E) ↔ ∀ x ∈ A, x ∉ convex_hull (A \ {x}) :=
begin
rw convex_independent_set_iff,
split,
{ rintro hA x hxA hx,
exact (hA _ (set.diff_subset _ _) ⟨hxA, hx⟩).2 (set.mem_singleton _) },
rintro hA s hs x ⟨hxA, hxs⟩,
by_contra h,
exact hA _ hxA (convex_hull_mono (set.subset_diff_singleton hs h) hxs),
end
-- TODO (Bhavik): move these two, and use them to prove the old versions
lemma nontrivial_sum_of_affine_independent' {p : ι → E} {X : finset ι}
(hX : affine_independent ℝ p) (w : ι → ℝ)
(hw₀ : ∑ i in X, w i = 0) (hw₁ : ∑ i in X, w i • p i = 0) :
∀ i ∈ X, w i = 0 :=
begin
specialize hX _ _ hw₀ _,
{ rw finset.weighted_vsub_eq_weighted_vsub_of_point_of_sum_eq_zero _ _ _ hw₀ (0 : E),
rw finset.weighted_vsub_of_point_apply,
simpa only [vsub_eq_sub, sub_zero, sum_finset_coe (λ i, w i • p i)] },
intros i hi,
apply hX _ hi
end
lemma unique_combination' {p : ι → E} (X : finset ι)
(hX : affine_independent ℝ p)
(w₁ w₂ : ι → ℝ) (hw₁ : ∑ i in X, w₁ i = 1) (hw₂ : ∑ i in X, w₂ i = 1)
(same : ∑ i in X, w₁ i • p i = ∑ i in X, w₂ i • p i) :
∀ i ∈ X, w₁ i = w₂ i :=
begin
let w := w₁ - w₂,
suffices : ∀ i ∈ X, w i = 0,
{ intros i hi,
apply eq_of_sub_eq_zero (this i hi) },
apply nontrivial_sum_of_affine_independent' hX,
{ change ∑ i in X, (w₁ i - w₂ i) = _,
rw [finset.sum_sub_distrib, hw₁, hw₂, sub_self] },
{ change ∑ i in X, (w₁ i - w₂ i) • p i = _,
simp_rw [sub_smul, finset.sum_sub_distrib, same, sub_self] }
end
lemma affine_independent.convex_independent {p : ι → E} (hp : affine_independent ℝ p) :
convex_independent p :=
begin
intros s x hx,
by_contra,
sorry
/-
rw [finset.convex_hull_eq] at hx,
rcases hx with ⟨w, hw₀, hw₁, x_eq⟩,
have : set.inj_on p s := λ x hx y hy h, injective_of_affine_independent hp h,
rw finset.center_mass_eq_of_sum_1 _ _ hw₁ at x_eq,
rw finset.sum_image ‹set.inj_on p s› at hw₁,
rw finset.sum_image ‹set.inj_on p s› at x_eq,
dsimp at hw₁ x_eq,
simp only [and_imp, finset.mem_image, forall_apply_eq_imp_iff₂, exists_imp_distrib] at hw₀,
let w₀ : ι → ℝ := λ i, if i ∈ s then w (p i) else 0,
let w₁ : ι → ℝ := λ i, if x = i then 1 else 0,
have thing : _ = _ := unique_combination' (insert x s) hp w₀ w₁ _ _ _ _ (mem_insert_self _ _),
{ change ite _ _ _ = ite _ _ _ at thing,
simpa [h] using thing },
{ rwa [sum_insert_of_eq_zero_if_not_mem, sum_extend_by_zero s],
simp [h] },
{ simp [sum_ite_eq] },
{ simpa [sum_insert_of_eq_zero_if_not_mem, h, ite_smul, sum_extend_by_zero s] }-/
end
|
ca5f005824ff40486694e656862dd3097ff53c0f | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/metric_space/cau_seq_filter_auto.lean | d889d23a8a47d60e58efaffcc8533257777a72bc | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 2,435 | lean | /-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Sébastien Gouëzel
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.analysis.normed_space.basic
import Mathlib.PostPort
universes v u
namespace Mathlib
/-!
# Completeness in terms of `cauchy` filters vs `is_cau_seq` sequences
In this file we apply `metric.complete_of_cauchy_seq_tendsto` to prove that a `normed_ring`
is complete in terms of `cauchy` filter if and only if it is complete in terms
of `cau_seq` Cauchy sequences.
-/
theorem cau_seq.tendsto_limit {β : Type v} [normed_ring β] [hn : is_absolute_value norm]
(f : cau_seq β norm) [cau_seq.is_complete β norm] :
filter.tendsto (⇑f) filter.at_top (nhds (cau_seq.lim f)) :=
sorry
/-
This section shows that if we have a uniform space generated by an absolute value, topological
completeness and Cauchy sequence completeness coincide. The problem is that there isn't
a good notion of "uniform space generated by an absolute value", so right now this is
specific to norm. Furthermore, norm only instantiates is_absolute_value on normed_field.
This needs to be fixed, since it prevents showing that ℤ_[hp] is complete
-/
protected instance normed_field.is_absolute_value {β : Type v} [normed_field β] :
is_absolute_value norm :=
is_absolute_value.mk norm_nonneg (fun (_x : β) => norm_eq_zero) norm_add_le normed_field.norm_mul
theorem cauchy_seq.is_cau_seq {β : Type v} [normed_field β] {f : ℕ → β} (hf : cauchy_seq f) :
is_cau_seq norm f :=
sorry
theorem cau_seq.cauchy_seq {β : Type v} [normed_field β] (f : cau_seq β norm) : cauchy_seq ⇑f :=
sorry
/-- In a normed field, `cau_seq` coincides with the usual notion of Cauchy sequences. -/
theorem cau_seq_iff_cauchy_seq {α : Type u} [normed_field α] {u : ℕ → α} :
is_cau_seq norm u ↔ cauchy_seq u :=
{ mp := fun (h : is_cau_seq norm u) => cau_seq.cauchy_seq { val := u, property := h },
mpr := fun (h : cauchy_seq u) => cauchy_seq.is_cau_seq h }
/-- A complete normed field is complete as a metric space, as Cauchy sequences converge by
assumption and this suffices to characterize completeness. -/
protected instance complete_space_of_cau_seq_complete {β : Type v} [normed_field β]
[cau_seq.is_complete β norm] : complete_space β :=
sorry
end Mathlib |
a4246a4f483ddc25907acde9d7034ec02f251d56 | d7189ea2ef694124821b033e533f18905b5e87ef | /galois/vector/init_last.lean | 519bc4df8a304c7bb35af6c58b3532209d6646d4 | [
"Apache-2.0"
] | permissive | digama0/lean-protocol-support | eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59 | cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda | refs/heads/master | 1,625,421,450,627 | 1,506,035,462,000 | 1,506,035,462,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,029 | lean | /- This defines init and last on vectors. -/
import ..list.init
import .simplify_eq
universe variables u
namespace vector
variable {α : Type u}
variable {n : ℕ}
local infix `++`:65 := vector.append
-- Generate proof list non-null from proof length is sucessor some number
private
lemma eq_succ_implies_non_nil {l : list α} {n : ℕ} (pr : l^.length = nat.succ n) : l ≠ list.nil :=
begin
cases l,
all_goals {contradiction}
end
-- Return all but the last element of a vector
def init : vector α n → vector α (n-1)
| ⟨l,p⟩ := ⟨list.init l, eq.trans (list.length_init l) (congr_arg (λx, x - 1) p)⟩
-- Return last element in a non-empty vector.
def last : vector α (nat.succ n) → α
| ⟨l,p⟩ := list.last l (eq_succ_implies_non_nil p)
theorem init_append_last_self {n : ℕ} (x : vector α (nat.succ n))
: init x ++ vector.cons (last x) vector.nil = x :=
begin
cases x with v p,
simp [init, last, cons, nil, append, list.init_append_last_self v (eq_succ_implies_non_nil p)],
end
end vector
|
e9ae5126b8213c711e9adb9555827d3214bc3af3 | 026eca3e4f104406f03192524c0ebed8b40e468b | /library/init/data/int/basic.lean | 40d2bb9b53b95762f364a34acc5a583d5d5a9d7a | [
"Apache-2.0"
] | permissive | jpablo/lean | 99bebe8f1c3e3df37e19fc4af27d4261efa40bc6 | bec8f0688552bc64f9c08fe0459f3fb20f93cb33 | refs/heads/master | 1,679,677,848,004 | 1,615,913,211,000 | 1,615,913,211,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,225 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The integers, with addition, multiplication, and subtraction.
-/
prelude
import init.data.nat.lemmas init.data.nat.gcd
open nat
/- the type, coercions, and notation -/
@[derive decidable_eq]
inductive int : Type
| of_nat : nat → int
| neg_succ_of_nat : nat → int
notation `ℤ` := int
instance : has_coe nat int := ⟨int.of_nat⟩
notation `-[1+ ` n `]` := int.neg_succ_of_nat n
protected def int.repr : int → string
| (int.of_nat n) := repr n
| (int.neg_succ_of_nat n) := "-" ++ repr (succ n)
instance : has_repr int :=
⟨int.repr⟩
instance : has_to_string int :=
⟨int.repr⟩
namespace int
protected lemma coe_nat_eq (n : ℕ) : ↑n = int.of_nat n := rfl
protected def zero : ℤ := of_nat 0
protected def one : ℤ := of_nat 1
instance : has_zero ℤ := ⟨int.zero⟩
instance : has_one ℤ := ⟨int.one⟩
lemma of_nat_zero : of_nat (0 : nat) = (0 : int) := rfl
lemma of_nat_one : of_nat (1 : nat) = (1 : int) := rfl
/- definitions of basic functions -/
def neg_of_nat : ℕ → ℤ
| 0 := 0
| (succ m) := -[1+ m]
def sub_nat_nat (m n : ℕ) : ℤ :=
match (n - m : nat) with
| 0 := of_nat (m - n) -- m ≥ n
| (succ k) := -[1+ k] -- m < n, and n - m = succ k
end
lemma sub_nat_nat_of_sub_eq_zero {m n : ℕ} (h : n - m = 0) :
sub_nat_nat m n = of_nat (m - n) :=
begin unfold sub_nat_nat, rw h, unfold sub_nat_nat._match_1 end
lemma sub_nat_nat_of_sub_eq_succ {m n k : ℕ} (h : n - m = succ k) :
sub_nat_nat m n = -[1+ k] :=
begin unfold sub_nat_nat, rw h, unfold sub_nat_nat._match_1 end
protected def neg : ℤ → ℤ
| (of_nat n) := neg_of_nat n
| -[1+ n] := succ n
protected def add : ℤ → ℤ → ℤ
| (of_nat m) (of_nat n) := of_nat (m + n)
| (of_nat m) -[1+ n] := sub_nat_nat m (succ n)
| -[1+ m] (of_nat n) := sub_nat_nat n (succ m)
| -[1+ m] -[1+ n] := -[1+ succ (m + n)]
protected def mul : ℤ → ℤ → ℤ
| (of_nat m) (of_nat n) := of_nat (m * n)
| (of_nat m) -[1+ n] := neg_of_nat (m * succ n)
| -[1+ m] (of_nat n) := neg_of_nat (succ m * n)
| -[1+ m] -[1+ n] := of_nat (succ m * succ n)
instance : has_neg ℤ := ⟨int.neg⟩
instance : has_add ℤ := ⟨int.add⟩
instance : has_mul ℤ := ⟨int.mul⟩
-- defeq to algebra.sub which gives subtraction for arbitrary `add_group`s
protected def sub : ℤ → ℤ → ℤ :=
λ m n, m + -n
instance : has_sub ℤ := ⟨int.sub⟩
protected lemma neg_zero : -(0:ℤ) = 0 := rfl
lemma of_nat_add (n m : ℕ) : of_nat (n + m) = of_nat n + of_nat m := rfl
lemma of_nat_mul (n m : ℕ) : of_nat (n * m) = of_nat n * of_nat m := rfl
lemma of_nat_succ (n : ℕ) : of_nat (succ n) = of_nat n + 1 := rfl
lemma neg_of_nat_zero : -(of_nat 0) = 0 := rfl
lemma neg_of_nat_of_succ (n : ℕ) : -(of_nat (succ n)) = -[1+ n] := rfl
lemma neg_neg_of_nat_succ (n : ℕ) : -(-[1+ n]) = of_nat (succ n) := rfl
lemma of_nat_eq_coe (n : ℕ) : of_nat n = ↑n := rfl
lemma neg_succ_of_nat_coe (n : ℕ) : -[1+ n] = -↑(n + 1) := rfl
protected lemma coe_nat_add (m n : ℕ) : (↑(m + n) : ℤ) = ↑m + ↑n := rfl
protected lemma coe_nat_mul (m n : ℕ) : (↑(m * n) : ℤ) = ↑m * ↑n := rfl
protected lemma coe_nat_zero : ↑(0 : ℕ) = (0 : ℤ) := rfl
protected lemma coe_nat_one : ↑(1 : ℕ) = (1 : ℤ) := rfl
protected lemma coe_nat_succ (n : ℕ) : (↑(succ n) : ℤ) = ↑n + 1 := rfl
protected lemma coe_nat_add_out (m n : ℕ) : ↑m + ↑n = (m + n : ℤ) := rfl
protected lemma coe_nat_mul_out (m n : ℕ) : ↑m * ↑n = (↑(m * n) : ℤ) := rfl
protected lemma coe_nat_add_one_out (n : ℕ) : ↑n + (1 : ℤ) = ↑(succ n) := rfl
/- these are only for internal use -/
lemma of_nat_add_of_nat (m n : nat) : of_nat m + of_nat n = of_nat (m + n) := rfl
lemma of_nat_add_neg_succ_of_nat (m n : nat) :
of_nat m + -[1+ n] = sub_nat_nat m (succ n) := rfl
lemma neg_succ_of_nat_add_of_nat (m n : nat) :
-[1+ m] + of_nat n = sub_nat_nat n (succ m) := rfl
lemma neg_succ_of_nat_add_neg_succ_of_nat (m n : nat) :
-[1+ m] + -[1+ n] = -[1+ succ (m + n)] := rfl
lemma of_nat_mul_of_nat (m n : nat) : of_nat m * of_nat n = of_nat (m * n) := rfl
lemma of_nat_mul_neg_succ_of_nat (m n : nat) :
of_nat m * -[1+ n] = neg_of_nat (m * succ n) := rfl
lemma neg_succ_of_nat_of_nat (m n : nat) :
-[1+ m] * of_nat n = neg_of_nat (succ m * n) := rfl
lemma mul_neg_succ_of_nat_neg_succ_of_nat (m n : nat) :
-[1+ m] * -[1+ n] = of_nat (succ m * succ n) := rfl
local attribute [simp] of_nat_add_of_nat of_nat_mul_of_nat neg_of_nat_zero neg_of_nat_of_succ
neg_neg_of_nat_succ of_nat_add_neg_succ_of_nat neg_succ_of_nat_add_of_nat
neg_succ_of_nat_add_neg_succ_of_nat of_nat_mul_neg_succ_of_nat neg_succ_of_nat_of_nat
mul_neg_succ_of_nat_neg_succ_of_nat
/- some basic functions and properties -/
protected lemma coe_nat_inj {m n : ℕ} (h : (↑m : ℤ) = ↑n) : m = n :=
int.of_nat.inj h
lemma of_nat_eq_of_nat_iff (m n : ℕ) : of_nat m = of_nat n ↔ m = n :=
iff.intro int.of_nat.inj (congr_arg _)
protected lemma coe_nat_eq_coe_nat_iff (m n : ℕ) : (↑m : ℤ) = ↑n ↔ m = n :=
of_nat_eq_of_nat_iff m n
lemma neg_succ_of_nat_inj_iff {m n : ℕ} : neg_succ_of_nat m = neg_succ_of_nat n ↔ m = n :=
⟨neg_succ_of_nat.inj, assume H, by simp [H]⟩
lemma neg_succ_of_nat_eq (n : ℕ) : -[1+ n] = -(n + 1) := rfl
/- neg -/
protected lemma neg_neg : ∀ a : ℤ, -(-a) = a
| (of_nat 0) := rfl
| (of_nat (n+1)) := rfl
| -[1+ n] := rfl
protected lemma neg_inj {a b : ℤ} (h : -a = -b) : a = b :=
by rw [← int.neg_neg a, ← int.neg_neg b, h]
protected lemma sub_eq_add_neg {a b : ℤ} : a - b = a + -b := rfl
/- basic properties of sub_nat_nat -/
lemma sub_nat_nat_elim (m n : ℕ) (P : ℕ → ℕ → ℤ → Prop)
(hp : ∀i n, P (n + i) n (of_nat i))
(hn : ∀i m, P m (m + i + 1) (-[1+ i])) :
P m n (sub_nat_nat m n) :=
begin
have H : ∀k, n - m = k → P m n (nat.cases_on k (of_nat (m - n)) (λa, -[1+ a])),
{ intro k, cases k,
{ intro e,
cases (nat.le.dest (nat.le_of_sub_eq_zero e)) with k h,
rw [h.symm, nat.add_sub_cancel_left],
apply hp },
{ intro heq,
have h : m ≤ n,
{ exact nat.le_of_lt (nat.lt_of_sub_eq_succ heq) },
rw [nat.sub_eq_iff_eq_add h] at heq,
rw [heq, nat.add_comm],
apply hn } },
delta sub_nat_nat,
exact H _ rfl
end
lemma sub_nat_nat_add_left {m n : ℕ} :
sub_nat_nat (m + n) m = of_nat n :=
begin
dunfold sub_nat_nat,
rw [nat.sub_eq_zero_of_le],
dunfold sub_nat_nat._match_1,
rw [nat.add_sub_cancel_left],
apply nat.le_add_right
end
lemma sub_nat_nat_add_right {m n : ℕ} :
sub_nat_nat m (m + n + 1) = neg_succ_of_nat n :=
calc sub_nat_nat._match_1 m (m + n + 1) (m + n + 1 - m) =
sub_nat_nat._match_1 m (m + n + 1) (m + (n + 1) - m) : by rw [nat.add_assoc]
... = sub_nat_nat._match_1 m (m + n + 1) (n + 1) : by rw [nat.add_sub_cancel_left]
... = neg_succ_of_nat n : rfl
lemma sub_nat_nat_add_add (m n k : ℕ) : sub_nat_nat (m + k) (n + k) = sub_nat_nat m n :=
sub_nat_nat_elim m n (λm n i, sub_nat_nat (m + k) (n + k) = i)
(assume i n, have n + i + k = (n + k) + i, by simp [nat.add_comm, nat.add_left_comm],
begin rw [this], exact sub_nat_nat_add_left end)
(assume i m, have m + i + 1 + k = (m + k) + i + 1, by simp [nat.add_comm, nat.add_left_comm],
begin rw [this], exact sub_nat_nat_add_right end)
lemma sub_nat_nat_of_le {m n : ℕ} (h : n ≤ m) : sub_nat_nat m n = of_nat (m - n) :=
sub_nat_nat_of_sub_eq_zero (sub_eq_zero_of_le h)
lemma sub_nat_nat_of_lt {m n : ℕ} (h : m < n) : sub_nat_nat m n = -[1+ pred (n - m)] :=
have n - m = succ (pred (n - m)), from eq.symm (succ_pred_eq_of_pos (nat.sub_pos_of_lt h)),
by rewrite sub_nat_nat_of_sub_eq_succ this
/- nat_abs -/
@[simp] def nat_abs : ℤ → ℕ
| (of_nat m) := m
| -[1+ m] := succ m
lemma nat_abs_of_nat (n : ℕ) : nat_abs ↑n = n := rfl
lemma eq_zero_of_nat_abs_eq_zero : Π {a : ℤ}, nat_abs a = 0 → a = 0
| (of_nat m) H := congr_arg of_nat H
| -[1+ m'] H := absurd H (succ_ne_zero _)
lemma nat_abs_pos_of_ne_zero {a : ℤ} (h : a ≠ 0) : 0 < nat_abs a :=
(eq_zero_or_pos _).resolve_left $ mt eq_zero_of_nat_abs_eq_zero h
lemma nat_abs_zero : nat_abs (0 : int) = (0 : nat) := rfl
lemma nat_abs_one : nat_abs (1 : int) = (1 : nat) := rfl
lemma nat_abs_mul_self : Π {a : ℤ}, ↑(nat_abs a * nat_abs a) = a * a
| (of_nat m) := rfl
| -[1+ m'] := rfl
@[simp] lemma nat_abs_neg (a : ℤ) : nat_abs (-a) = nat_abs a :=
by {cases a with n n, cases n; refl, refl}
lemma nat_abs_eq : Π (a : ℤ), a = nat_abs a ∨ a = -(nat_abs a)
| (of_nat m) := or.inl rfl
| -[1+ m'] := or.inr rfl
lemma eq_coe_or_neg (a : ℤ) : ∃n : ℕ, a = n ∨ a = -n := ⟨_, nat_abs_eq a⟩
/- sign -/
def sign : ℤ → ℤ
| (n+1:ℕ) := 1
| 0 := 0
| -[1+ n] := -1
@[simp] theorem sign_zero : sign 0 = 0 := rfl
@[simp] theorem sign_one : sign 1 = 1 := rfl
@[simp] theorem sign_neg_one : sign (-1) = -1 := rfl
/- Quotient and remainder -/
-- There are three main conventions for integer division,
-- referred here as the E, F, T rounding conventions.
-- All three pairs satisfy the identity x % y + (x / y) * y = x
-- unconditionally.
-- E-rounding: This pair satisfies 0 ≤ mod x y < nat_abs y for y ≠ 0
protected def div : ℤ → ℤ → ℤ
| (m : ℕ) (n : ℕ) := of_nat (m / n)
| (m : ℕ) -[1+ n] := -of_nat (m / succ n)
| -[1+ m] 0 := 0
| -[1+ m] (n+1:ℕ) := -[1+ m / succ n]
| -[1+ m] -[1+ n] := of_nat (succ (m / succ n))
protected def mod : ℤ → ℤ → ℤ
| (m : ℕ) n := (m % nat_abs n : ℕ)
| -[1+ m] n := sub_nat_nat (nat_abs n) (succ (m % nat_abs n))
-- F-rounding: This pair satisfies fdiv x y = floor (x / y)
def fdiv : ℤ → ℤ → ℤ
| 0 _ := 0
| (m : ℕ) (n : ℕ) := of_nat (m / n)
| (m+1:ℕ) -[1+ n] := -[1+ m / succ n]
| -[1+ m] 0 := 0
| -[1+ m] (n+1:ℕ) := -[1+ m / succ n]
| -[1+ m] -[1+ n] := of_nat (succ m / succ n)
def fmod : ℤ → ℤ → ℤ
| 0 _ := 0
| (m : ℕ) (n : ℕ) := of_nat (m % n)
| (m+1:ℕ) -[1+ n] := sub_nat_nat (m % succ n) n
| -[1+ m] (n : ℕ) := sub_nat_nat n (succ (m % n))
| -[1+ m] -[1+ n] := -of_nat (succ m % succ n)
-- T-rounding: This pair satisfies quot x y = round_to_zero (x / y)
def quot : ℤ → ℤ → ℤ
| (of_nat m) (of_nat n) := of_nat (m / n)
| (of_nat m) -[1+ n] := -of_nat (m / succ n)
| -[1+ m] (of_nat n) := -of_nat (succ m / n)
| -[1+ m] -[1+ n] := of_nat (succ m / succ n)
def rem : ℤ → ℤ → ℤ
| (of_nat m) (of_nat n) := of_nat (m % n)
| (of_nat m) -[1+ n] := of_nat (m % succ n)
| -[1+ m] (of_nat n) := -of_nat (succ m % n)
| -[1+ m] -[1+ n] := -of_nat (succ m % succ n)
instance : has_div ℤ := ⟨int.div⟩
instance : has_mod ℤ := ⟨int.mod⟩
/- gcd -/
def gcd (m n : ℤ) : ℕ := gcd (nat_abs m) (nat_abs n)
/-
int is a ring
-/
/- addition -/
protected lemma add_comm : ∀ a b : ℤ, a + b = b + a
| (of_nat n) (of_nat m) := by simp [nat.add_comm]
| (of_nat n) -[1+ m] := rfl
| -[1+ n] (of_nat m) := rfl
| -[1+ n] -[1+m] := by simp [nat.add_comm]
protected lemma add_zero : ∀ a : ℤ, a + 0 = a
| (of_nat n) := rfl
| -[1+ n] := rfl
protected lemma zero_add (a : ℤ) : 0 + a = a :=
int.add_comm a 0 ▸ int.add_zero a
lemma sub_nat_nat_sub {m n : ℕ} (h : n ≤ m) (k : ℕ) :
sub_nat_nat (m - n) k = sub_nat_nat m (k + n) :=
calc
sub_nat_nat (m - n) k = sub_nat_nat (m - n + n) (k + n) : by rewrite [sub_nat_nat_add_add]
... = sub_nat_nat m (k + n) : by rewrite [nat.sub_add_cancel h]
lemma sub_nat_nat_add (m n k : ℕ) : sub_nat_nat (m + n) k = of_nat m + sub_nat_nat n k :=
begin
have h := decidable.le_or_lt k n,
cases h with h' h',
{ rw [sub_nat_nat_of_le h'],
have h₂ : k ≤ m + n, exact (le_trans h' (le_add_left _ _)),
rw [sub_nat_nat_of_le h₂], simp,
rw nat.add_sub_assoc h' },
rw [sub_nat_nat_of_lt h'], simp, rw [succ_pred_eq_of_pos (nat.sub_pos_of_lt h')],
transitivity, rw [← nat.sub_add_cancel (le_of_lt h')],
apply sub_nat_nat_add_add
end
lemma sub_nat_nat_add_neg_succ_of_nat (m n k : ℕ) :
sub_nat_nat m n + -[1+ k] = sub_nat_nat m (n + succ k) :=
begin
have h := decidable.le_or_lt n m,
cases h with h' h',
{ rw [sub_nat_nat_of_le h'], simp, rw [sub_nat_nat_sub h', nat.add_comm] },
have h₂ : m < n + succ k, exact nat.lt_of_lt_of_le h' (le_add_right _ _),
have h₃ : m ≤ n + k, exact le_of_succ_le_succ h₂,
rw [sub_nat_nat_of_lt h', sub_nat_nat_of_lt h₂], simp [nat.add_comm],
rw [← add_succ, succ_pred_eq_of_pos (nat.sub_pos_of_lt h'), add_succ, succ_sub h₃, pred_succ],
rw [nat.add_comm n, nat.add_sub_assoc (le_of_lt h')]
end
lemma add_assoc_aux1 (m n : ℕ) :
∀ c : ℤ, of_nat m + of_nat n + c = of_nat m + (of_nat n + c)
| (of_nat k) := by simp [nat.add_assoc]
| -[1+ k] := by simp [sub_nat_nat_add]
lemma add_assoc_aux2 (m n k : ℕ) :
-[1+ m] + -[1+ n] + of_nat k = -[1+ m] + (-[1+ n] + of_nat k) :=
begin
simp [add_succ], rw [int.add_comm, sub_nat_nat_add_neg_succ_of_nat], simp [add_succ, succ_add, nat.add_comm]
end
protected lemma add_assoc : ∀ a b c : ℤ, a + b + c = a + (b + c)
| (of_nat m) (of_nat n) c := add_assoc_aux1 _ _ _
| (of_nat m) b (of_nat k) := by rw [int.add_comm, ← add_assoc_aux1, int.add_comm (of_nat k),
add_assoc_aux1, int.add_comm b]
| a (of_nat n) (of_nat k) := by rw [int.add_comm, int.add_comm a, ← add_assoc_aux1,
int.add_comm a, int.add_comm (of_nat k)]
| -[1+ m] -[1+ n] (of_nat k) := add_assoc_aux2 _ _ _
| -[1+ m] (of_nat n) -[1+ k] := by rw [int.add_comm, ← add_assoc_aux2, int.add_comm (of_nat n),
← add_assoc_aux2, int.add_comm -[1+ m] ]
| (of_nat m) -[1+ n] -[1+ k] := by rw [int.add_comm, int.add_comm (of_nat m),
int.add_comm (of_nat m), ← add_assoc_aux2,
int.add_comm -[1+ k] ]
| -[1+ m] -[1+ n] -[1+ k] := by simp [add_succ, nat.add_comm, nat.add_left_comm, neg_of_nat_of_succ]
/- negation -/
lemma sub_nat_self : ∀ n, sub_nat_nat n n = 0
| 0 := rfl
| (succ m) := begin rw [sub_nat_nat_of_sub_eq_zero, nat.sub_self, of_nat_zero], rw nat.sub_self end
local attribute [simp] sub_nat_self
protected lemma add_left_neg : ∀ a : ℤ, -a + a = 0
| (of_nat 0) := rfl
| (of_nat (succ m)) := by simp
| -[1+ m] := by simp
protected lemma add_right_neg (a : ℤ) : a + -a = 0 :=
by rw [int.add_comm, int.add_left_neg]
/- multiplication -/
protected lemma mul_comm : ∀ a b : ℤ, a * b = b * a
| (of_nat m) (of_nat n) := by simp [nat.mul_comm]
| (of_nat m) -[1+ n] := by simp [nat.mul_comm]
| -[1+ m] (of_nat n) := by simp [nat.mul_comm]
| -[1+ m] -[1+ n] := by simp [nat.mul_comm]
lemma of_nat_mul_neg_of_nat (m : ℕ) :
∀ n, of_nat m * neg_of_nat n = neg_of_nat (m * n)
| 0 := rfl
| (succ n) := begin unfold neg_of_nat, simp end
lemma neg_of_nat_mul_of_nat (m n : ℕ) :
neg_of_nat m * of_nat n = neg_of_nat (m * n) :=
begin rw int.mul_comm, simp [of_nat_mul_neg_of_nat, nat.mul_comm] end
lemma neg_succ_of_nat_mul_neg_of_nat (m : ℕ) :
∀ n, -[1+ m] * neg_of_nat n = of_nat (succ m * n)
| 0 := rfl
| (succ n) := begin unfold neg_of_nat, simp end
lemma neg_of_nat_mul_neg_succ_of_nat (m n : ℕ) :
neg_of_nat n * -[1+ m] = of_nat (n * succ m) :=
begin rw int.mul_comm, simp [neg_succ_of_nat_mul_neg_of_nat, nat.mul_comm] end
local attribute [simp] of_nat_mul_neg_of_nat neg_of_nat_mul_of_nat
neg_succ_of_nat_mul_neg_of_nat neg_of_nat_mul_neg_succ_of_nat
protected lemma mul_assoc : ∀ a b c : ℤ, a * b * c = a * (b * c)
| (of_nat m) (of_nat n) (of_nat k) := by simp [nat.mul_assoc]
| (of_nat m) (of_nat n) -[1+ k] := by simp [nat.mul_assoc]
| (of_nat m) -[1+ n] (of_nat k) := by simp [nat.mul_assoc]
| (of_nat m) -[1+ n] -[1+ k] := by simp [nat.mul_assoc]
| -[1+ m] (of_nat n) (of_nat k) := by simp [nat.mul_assoc]
| -[1+ m] (of_nat n) -[1+ k] := by simp [nat.mul_assoc]
| -[1+ m] -[1+ n] (of_nat k) := by simp [nat.mul_assoc]
| -[1+ m] -[1+ n] -[1+ k] := by simp [nat.mul_assoc]
protected lemma mul_zero : ∀ (a : ℤ), a * 0 = 0
| (of_nat m) := rfl
| -[1+ m] := rfl
protected lemma zero_mul (a : ℤ) : 0 * a = 0 :=
int.mul_comm a 0 ▸ int.mul_zero a
lemma neg_of_nat_eq_sub_nat_nat_zero : ∀ n, neg_of_nat n = sub_nat_nat 0 n
| 0 := rfl
| (succ n) := rfl
lemma of_nat_mul_sub_nat_nat (m n k : ℕ) :
of_nat m * sub_nat_nat n k = sub_nat_nat (m * n) (m * k) :=
begin
have h₀ : m > 0 ∨ 0 = m,
exact decidable.lt_or_eq_of_le (zero_le _),
cases h₀ with h₀ h₀,
{ have h := nat.lt_or_ge n k,
cases h with h h,
{ have h' : m * n < m * k,
exact nat.mul_lt_mul_of_pos_left h h₀,
rw [sub_nat_nat_of_lt h, sub_nat_nat_of_lt h'],
simp, rw [succ_pred_eq_of_pos (nat.sub_pos_of_lt h)],
rw [← neg_of_nat_of_succ, nat.mul_sub_left_distrib],
rw [← succ_pred_eq_of_pos (nat.sub_pos_of_lt h')], reflexivity },
have h' : m * k ≤ m * n,
exact mul_le_mul_left _ h,
rw [sub_nat_nat_of_le h, sub_nat_nat_of_le h'], simp,
rw [nat.mul_sub_left_distrib]
},
have h₂ : of_nat 0 = 0, exact rfl,
subst h₀, simp [h₂, int.zero_mul, nat.zero_mul]
end
lemma neg_of_nat_add (m n : ℕ) :
neg_of_nat m + neg_of_nat n = neg_of_nat (m + n) :=
begin
cases m,
{ cases n,
{ simp, reflexivity },
simp [nat.zero_add], reflexivity },
cases n,
{ simp, reflexivity },
simp [nat.succ_add], reflexivity
end
lemma neg_succ_of_nat_mul_sub_nat_nat (m n k : ℕ) :
-[1+ m] * sub_nat_nat n k = sub_nat_nat (succ m * k) (succ m * n) :=
begin
have h := nat.lt_or_ge n k,
cases h with h h,
{ have h' : succ m * n < succ m * k,
exact nat.mul_lt_mul_of_pos_left h (nat.succ_pos m),
rw [sub_nat_nat_of_lt h, sub_nat_nat_of_le (le_of_lt h')],
simp [succ_pred_eq_of_pos (nat.sub_pos_of_lt h), nat.mul_sub_left_distrib]},
have h' : n > k ∨ k = n,
exact decidable.lt_or_eq_of_le h,
cases h' with h' h',
{ have h₁ : succ m * n > succ m * k,
exact nat.mul_lt_mul_of_pos_left h' (nat.succ_pos m),
rw [sub_nat_nat_of_le h, sub_nat_nat_of_lt h₁], simp [nat.mul_sub_left_distrib, nat.mul_comm],
rw [nat.mul_comm k, nat.mul_comm n, ← succ_pred_eq_of_pos (nat.sub_pos_of_lt h₁),
← neg_of_nat_of_succ],
reflexivity },
subst h', simp, reflexivity
end
local attribute [simp] of_nat_mul_sub_nat_nat neg_of_nat_add neg_succ_of_nat_mul_sub_nat_nat
protected lemma distrib_left : ∀ a b c : ℤ, a * (b + c) = a * b + a * c
| (of_nat m) (of_nat n) (of_nat k) := by simp [nat.left_distrib]
| (of_nat m) (of_nat n) -[1+ k] := begin simp [neg_of_nat_eq_sub_nat_nat_zero],
rw ← sub_nat_nat_add, reflexivity end
| (of_nat m) -[1+ n] (of_nat k) := begin simp [neg_of_nat_eq_sub_nat_nat_zero],
rw [int.add_comm, ← sub_nat_nat_add], reflexivity end
| (of_nat m) -[1+ n] -[1+ k] := begin simp, rw [← nat.left_distrib, succ_add] end
| -[1+ m] (of_nat n) (of_nat k) := begin simp [nat.mul_comm], rw [← nat.right_distrib, nat.mul_comm] end
| -[1+ m] (of_nat n) -[1+ k] := begin simp [neg_of_nat_eq_sub_nat_nat_zero],
rw [int.add_comm, ← sub_nat_nat_add], reflexivity end
| -[1+ m] -[1+ n] (of_nat k) := begin simp [neg_of_nat_eq_sub_nat_nat_zero],
rw [← sub_nat_nat_add], reflexivity end
| -[1+ m] -[1+ n] -[1+ k] := begin simp, rw [← nat.left_distrib, succ_add] end
protected lemma distrib_right (a b c : ℤ) : (a + b) * c = a * c + b * c :=
begin rw [int.mul_comm, int.distrib_left], simp [int.mul_comm] end
protected lemma zero_ne_one : (0 : int) ≠ 1 :=
assume h : 0 = 1, succ_ne_zero _ (int.of_nat.inj h).symm
lemma of_nat_sub {n m : ℕ} (h : m ≤ n) : of_nat (n - m) = of_nat n - of_nat m :=
show of_nat (n - m) = of_nat n + neg_of_nat m, from match m, h with
| 0, h := rfl
| succ m, h := show of_nat (n - succ m) = sub_nat_nat n (succ m),
by delta sub_nat_nat; rw sub_eq_zero_of_le h; refl
end
protected lemma add_left_comm (a b c : ℤ) : a + (b + c) = b + (a + c) :=
by rw [← int.add_assoc, int.add_comm a, int.add_assoc]
protected lemma add_left_cancel {a b c : ℤ} (h : a + b = a + c) : b = c :=
have -a + (a + b) = -a + (a + c), by rw h,
by rwa [← int.add_assoc, ← int.add_assoc, int.add_left_neg, int.zero_add, int.zero_add] at this
protected lemma neg_add {a b : ℤ} : - (a + b) = -a + -b :=
calc - (a + b) = -(a + b) + (a + b) + -a + -b :
begin
rw [int.add_assoc, int.add_comm (-a), int.add_assoc, int.add_assoc, ← int.add_assoc b],
rw [int.add_right_neg, int.zero_add, int.add_right_neg, int.add_zero],
end
... = -a + -b : by { rw [int.add_left_neg, int.zero_add] }
lemma neg_succ_of_nat_coe' (n : ℕ) : -[1+ n] = -↑n - 1 :=
by rw [int.sub_eq_add_neg, ← int.neg_add]; refl
protected lemma coe_nat_sub {n m : ℕ} : n ≤ m → (↑(m - n) : ℤ) = ↑m - ↑n := of_nat_sub
local attribute [simp] int.sub_eq_add_neg
protected lemma sub_nat_nat_eq_coe {m n : ℕ} : sub_nat_nat m n = ↑m - ↑n :=
sub_nat_nat_elim m n (λm n i, i = ↑m - ↑n)
(λi n, by { simp [int.coe_nat_add, int.add_left_comm, int.add_assoc, int.add_right_neg], refl })
(λi n, by { rw [int.coe_nat_add, int.coe_nat_add, int.coe_nat_one, int.neg_succ_of_nat_eq,
int.sub_eq_add_neg, int.neg_add, int.neg_add, int.neg_add, ← int.add_assoc,
← int.add_assoc, int.add_right_neg, int.zero_add] })
def to_nat : ℤ → ℕ
| (n : ℕ) := n
| -[1+ n] := 0
theorem to_nat_sub (m n : ℕ) : to_nat (m - n) = m - n :=
by rw [← int.sub_nat_nat_eq_coe]; exact sub_nat_nat_elim m n
(λm n i, to_nat i = m - n)
(λi n, by rw [nat.add_sub_cancel_left]; refl)
(λi n, by rw [nat.add_assoc, nat.sub_eq_zero_of_le (nat.le_add_right _ _)]; refl)
-- Since mod x y is always nonnegative when y ≠ 0, we can make a nat version of it
def nat_mod (m n : ℤ) : ℕ := (m % n).to_nat
protected lemma one_mul : ∀ (a : ℤ), (1 : ℤ) * a = a
| (of_nat n) := show of_nat (1 * n) = of_nat n, by rw nat.one_mul
| -[1+ n] := show -[1+ (1 * n)] = -[1+ n], by rw nat.one_mul
protected lemma mul_one (a : ℤ) : a * 1 = a :=
by rw [int.mul_comm, int.one_mul]
protected lemma neg_eq_neg_one_mul : ∀ a : ℤ, -a = -1 * a
| (of_nat 0) := rfl
| (of_nat (n+1)) := show _ = -[1+ (1*n)+0], by { rw nat.one_mul, refl }
| -[1+ n] := show _ = of_nat _, by { rw nat.one_mul, refl }
theorem sign_mul_nat_abs : ∀ (a : ℤ), sign a * nat_abs a = a
| (n+1:ℕ) := int.one_mul _
| 0 := rfl
| -[1+ n] := (int.neg_eq_neg_one_mul _).symm
end int
|
d030d4ce5c579923c95b670e49a133bcaf3d7e9f | f083c4ed5d443659f3ed9b43b1ca5bb037ddeb58 | /analysis/nnreal.lean | a83308b31355d5b70c9ce72a4ab1d817d58993bf | [
"Apache-2.0"
] | permissive | semorrison/mathlib | 1be6f11086e0d24180fec4b9696d3ec58b439d10 | 20b4143976dad48e664c4847b75a85237dca0a89 | refs/heads/master | 1,583,799,212,170 | 1,535,634,130,000 | 1,535,730,505,000 | 129,076,205 | 0 | 0 | Apache-2.0 | 1,551,697,998,000 | 1,523,442,265,000 | Lean | UTF-8 | Lean | false | false | 3,915 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
Nonnegative real numbers.
-/
import data.real.nnreal analysis.real analysis.topology.infinite_sum
noncomputable theory
open set topological_space
namespace nnreal
local notation ` ℝ≥0 ` := nnreal
instance : metric_space ℝ≥0 := by unfold nnreal; apply_instance
instance : topological_space ℝ≥0 := infer_instance
instance : topological_semiring ℝ≥0 :=
{ continuous_mul :=
continuous_subtype_mk _
(continuous_mul (continuous.comp continuous_fst continuous_subtype_val)
(continuous.comp continuous_snd continuous_subtype_val)),
continuous_add :=
continuous_subtype_mk _
(continuous_add (continuous.comp continuous_fst continuous_subtype_val)
(continuous.comp continuous_snd continuous_subtype_val)) }
instance : orderable_topology ℝ≥0 :=
⟨ le_antisymm
begin
apply induced_le_iff_le_coinduced.2,
rw [orderable_topology.topology_eq_generate_intervals ℝ],
apply generate_from_le,
assume s hs,
rcases hs with ⟨a, rfl | rfl⟩,
{ show topological_space.generate_open _ {b : ℝ≥0 | a < b },
by_cases ha : 0 ≤ a,
{ exact topological_space.generate_open.basic _ ⟨⟨a, ha⟩, or.inl rfl⟩ },
{ have : a < 0, from lt_of_not_ge ha,
have : {b : ℝ≥0 | a < b } = set.univ,
from (set.eq_univ_iff_forall.2 $ assume b, lt_of_lt_of_le this b.2),
rw [this],
exact topological_space.generate_open.univ _ } },
{ show (topological_space.generate_from _).is_open {b : ℝ≥0 | a > b },
by_cases ha : 0 ≤ a,
{ exact topological_space.generate_open.basic _ ⟨⟨a, ha⟩, or.inr rfl⟩ },
{ have : {b : ℝ≥0 | a > b } = ∅,
from (set.eq_empty_iff_forall_not_mem.2 $ assume b hb, ha $
show 0 ≤ a, from le_trans b.2 (le_of_lt hb)),
rw [this],
apply @is_open_empty } },
end
(generate_from_le $ assume s hs,
match s, hs with
| _, ⟨⟨a, ha⟩, or.inl rfl⟩ := ⟨{b : ℝ | a < b}, is_open_lt' a, rfl⟩
| _, ⟨⟨a, ha⟩, or.inr rfl⟩ := ⟨{b : ℝ | b < a}, is_open_gt' a, set.ext $ assume b, iff.refl _⟩
end) ⟩
section coe
variable {α : Type*}
open filter
lemma continuous_of_real : continuous nnreal.of_real :=
continuous_subtype_mk _ $ continuous_max continuous_id continuous_const
lemma continuous_coe : continuous (coe : nnreal → ℝ) :=
continuous_subtype_val
lemma tendsto_coe {f : filter α} {m : α → nnreal} :
∀{x : nnreal}, tendsto (λa, (m a : ℝ)) f (nhds (x : ℝ)) ↔ tendsto m f (nhds x)
| ⟨r, hr⟩ := by rw [nhds_subtype_eq_vmap, tendsto_vmap_iff]; refl
lemma tendsto_of_real {f : filter α} {m : α → ℝ} {x : ℝ} (h : tendsto m f (nhds x)):
tendsto (λa, nnreal.of_real (m a)) f (nhds (nnreal.of_real x)) :=
h.comp (continuous_iff_tendsto.1 continuous_of_real _)
lemma tendsto_sub {f : filter α} {m n : α → nnreal} {r p : nnreal}
(hm : tendsto m f (nhds r)) (hn : tendsto n f (nhds p)) :
tendsto (λa, m a - n a) f (nhds (r - p)) :=
tendsto_of_real $ tendsto_sub (tendsto_coe.2 hm) (tendsto_coe.2 hn)
lemma is_sum_coe {f : α → nnreal} {r : nnreal} : is_sum (λa, (f a : ℝ)) (r : ℝ) ↔ is_sum f r :=
by simp [is_sum, sum_coe.symm, tendsto_coe]
lemma has_sum_coe {f : α → nnreal} : has_sum (λa, (f a : ℝ)) ↔ has_sum f :=
begin
simp [has_sum],
split,
exact assume ⟨a, ha⟩, ⟨⟨a, is_sum_le (λa, (f a).2) is_sum_zero ha⟩, is_sum_coe.1 ha⟩,
exact assume ⟨a, ha⟩, ⟨a.1, is_sum_coe.2 ha⟩
end
lemma tsum_coe {f : α → nnreal} (hf : has_sum f) : (∑a, (f a : ℝ)) = ↑(∑a, f a) :=
tsum_eq_is_sum $ is_sum_coe.2 $ is_sum_tsum $ hf
end coe
end nnreal |
800f93eefba20024ce9020a071927bafd3a7dcee | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/t6.lean | 12e3537794c9bfe1ef596f18ce3e80ec5e61aa85 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 342 | lean | prelude definition Prop : Type.{1} := Type.{0}
section
variable {A : Type} -- Mark A as implicit parameter
variable R : A → A → Prop
definition id (a : A) : A := a
definition refl : Prop := forall (a : A), R a a
definition symm : Prop := forall (a b : A), R a b -> R b a
end
check id.{2}
check refl.{1}
check symm.{1}
|
4b0ed56d629ef739f20d514e39447ec881f8cc19 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/sum/basic.lean | bec135e6da38c446745e2c9edf50eeff82689295 | [
"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 | 19,080 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury G. Kudryashov
-/
import logic.function.basic
import tactic.basic
/-!
# Disjoint union of types
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves basic results about the sum type `α ⊕ β`.
`α ⊕ β` is the type made of a copy of `α` and a copy of `β`. It is also called *disjoint union*.
## Main declarations
* `sum.get_left`: Retrieves the left content of `x : α ⊕ β` or returns `none` if it's coming from
the right.
* `sum.get_right`: Retrieves the right content of `x : α ⊕ β` or returns `none` if it's coming from
the left.
* `sum.is_left`: Returns whether `x : α ⊕ β` comes from the left component or not.
* `sum.is_right`: Returns whether `x : α ⊕ β` comes from the right component or not.
* `sum.map`: Maps `α ⊕ β` to `γ ⊕ δ` component-wise.
* `sum.elim`: Nondependent eliminator/induction principle for `α ⊕ β`.
* `sum.swap`: Maps `α ⊕ β` to `β ⊕ α` by swapping components.
* `sum.lex`: Lexicographic order on `α ⊕ β` induced by a relation on `α` and a relation on `β`.
## Notes
The definition of `sum` takes values in `Type*`. This effectively forbids `Prop`- valued sum types.
To this effect, we have `psum`, which takes value in `Sort*` and carries a more complicated
universe signature in consequence. The `Prop` version is `or`.
-/
universes u v w x
variables {α : Type u} {α' : Type w} {β : Type v} {β' : Type x} {γ δ : Type*}
namespace sum
attribute [derive decidable_eq] sum
@[simp] lemma «forall» {p : α ⊕ β → Prop} : (∀ x, p x) ↔ (∀ a, p (inl a)) ∧ ∀ b, p (inr b) :=
⟨λ h, ⟨λ a, h _, λ b, h _⟩, λ ⟨h₁, h₂⟩, sum.rec h₁ h₂⟩
@[simp] lemma «exists» {p : α ⊕ β → Prop} : (∃ x, p x) ↔ (∃ a, p (inl a)) ∨ ∃ b, p (inr b) :=
⟨λ h, match h with
| ⟨inl a, h⟩ := or.inl ⟨a, h⟩
| ⟨inr b, h⟩ := or.inr ⟨b, h⟩
end, λ h, match h with
| or.inl ⟨a, h⟩ := ⟨inl a, h⟩
| or.inr ⟨b, h⟩ := ⟨inr b, h⟩
end⟩
lemma inl_injective : function.injective (inl : α → α ⊕ β) := λ x y, inl.inj
lemma inr_injective : function.injective (inr : β → α ⊕ β) := λ x y, inr.inj
section get
/-- Check if a sum is `inl` and if so, retrieve its contents. -/
@[simp] def get_left : α ⊕ β → option α
| (inl a) := some a
| (inr _) := none
/-- Check if a sum is `inr` and if so, retrieve its contents. -/
@[simp] def get_right : α ⊕ β → option β
| (inr b) := some b
| (inl _) := none
/-- Check if a sum is `inl`. -/
@[simp] def is_left : α ⊕ β → bool
| (inl _) := tt
| (inr _) := ff
/-- Check if a sum is `inr`. -/
@[simp] def is_right : α ⊕ β → bool
| (inl _) := ff
| (inr _) := tt
variables {x y : α ⊕ β}
@[simp] lemma get_left_eq_none_iff : x.get_left = none ↔ x.is_right :=
by cases x; simp only [get_left, is_right, coe_sort_tt, coe_sort_ff, eq_self_iff_true]
@[simp] lemma get_right_eq_none_iff : x.get_right = none ↔ x.is_left :=
by cases x; simp only [get_right, is_left, coe_sort_tt, coe_sort_ff, eq_self_iff_true]
@[simp] lemma get_left_eq_some_iff {a} : x.get_left = some a ↔ x = inl a :=
by cases x; simp only [get_left]
@[simp] lemma get_right_eq_some_iff {b} : x.get_right = some b ↔ x = inr b :=
by cases x; simp only [get_right]
@[simp] lemma bnot_is_left (x : α ⊕ β) : bnot x.is_left = x.is_right := by cases x; refl
@[simp] lemma is_left_eq_ff : x.is_left = ff ↔ x.is_right := by cases x; simp
lemma not_is_left : ¬x.is_left ↔ x.is_right := by simp
@[simp] lemma bnot_is_right (x : α ⊕ β) : bnot x.is_right = x.is_left := by cases x; refl
@[simp] lemma is_right_eq_ff : x.is_right = ff ↔ x.is_left := by cases x; simp
lemma not_is_right : ¬x.is_right ↔ x.is_left := by simp
lemma is_left_iff : x.is_left ↔ ∃ y, x = sum.inl y := by cases x; simp
lemma is_right_iff : x.is_right ↔ ∃ y, x = sum.inr y := by cases x; simp
end get
theorem inl.inj_iff {a b} : (inl a : α ⊕ β) = inl b ↔ a = b :=
⟨inl.inj, congr_arg _⟩
theorem inr.inj_iff {a b} : (inr a : α ⊕ β) = inr b ↔ a = b :=
⟨inr.inj, congr_arg _⟩
theorem inl_ne_inr {a : α} {b : β} : inl a ≠ inr b.
theorem inr_ne_inl {a : α} {b : β} : inr b ≠ inl a.
/-- Define a function on `α ⊕ β` by giving separate definitions on `α` and `β`. -/
protected def elim {α β γ : Sort*} (f : α → γ) (g : β → γ) : α ⊕ β → γ := λ x, sum.rec_on x f g
@[simp] lemma elim_inl {α β γ : Sort*} (f : α → γ) (g : β → γ) (x : α) :
sum.elim f g (inl x) = f x := rfl
@[simp] lemma elim_inr {α β γ : Sort*} (f : α → γ) (g : β → γ) (x : β) :
sum.elim f g (inr x) = g x := rfl
@[simp] lemma elim_comp_inl {α β γ : Sort*} (f : α → γ) (g : β → γ) :
sum.elim f g ∘ inl = f := rfl
@[simp] lemma elim_comp_inr {α β γ : Sort*} (f : α → γ) (g : β → γ) :
sum.elim f g ∘ inr = g := rfl
@[simp] lemma elim_inl_inr {α β : Sort*} :
@sum.elim α β _ inl inr = id :=
funext $ λ x, sum.cases_on x (λ _, rfl) (λ _, rfl)
lemma comp_elim {α β γ δ : Sort*} (f : γ → δ) (g : α → γ) (h : β → γ):
f ∘ sum.elim g h = sum.elim (f ∘ g) (f ∘ h) :=
funext $ λ x, sum.cases_on x (λ _, rfl) (λ _, rfl)
@[simp] lemma elim_comp_inl_inr {α β γ : Sort*} (f : α ⊕ β → γ) :
sum.elim (f ∘ inl) (f ∘ inr) = f :=
funext $ λ x, sum.cases_on x (λ _, rfl) (λ _, rfl)
/-- Map `α ⊕ β` to `α' ⊕ β'` sending `α` to `α'` and `β` to `β'`. -/
protected def map (f : α → α') (g : β → β') : α ⊕ β → α' ⊕ β' :=
sum.elim (inl ∘ f) (inr ∘ g)
@[simp] lemma map_inl (f : α → α') (g : β → β') (x : α) : (inl x).map f g = inl (f x) := rfl
@[simp] lemma map_inr (f : α → α') (g : β → β') (x : β) : (inr x).map f g = inr (g x) := rfl
@[simp] lemma map_map {α'' β''} (f' : α' → α'') (g' : β' → β'') (f : α → α') (g : β → β') :
∀ x : α ⊕ β, (x.map f g).map f' g' = x.map (f' ∘ f) (g' ∘ g)
| (inl a) := rfl
| (inr b) := rfl
@[simp] lemma map_comp_map {α'' β''} (f' : α' → α'') (g' : β' → β'') (f : α → α') (g : β → β') :
(sum.map f' g') ∘ (sum.map f g) = sum.map (f' ∘ f) (g' ∘ g) :=
funext $ map_map f' g' f g
@[simp] lemma map_id_id (α β) : sum.map (@id α) (@id β) = id :=
funext $ λ x, sum.rec_on x (λ _, rfl) (λ _, rfl)
lemma elim_map {α β γ δ ε : Sort*} {f₁ : α → β} {f₂ : β → ε} {g₁ : γ → δ} {g₂ : δ → ε} {x} :
sum.elim f₂ g₂ (sum.map f₁ g₁ x) = sum.elim (f₂ ∘ f₁) (g₂ ∘ g₁) x :=
by cases x; refl
lemma elim_comp_map {α β γ δ ε : Sort*} {f₁ : α → β} {f₂ : β → ε} {g₁ : γ → δ} {g₂ : δ → ε} :
sum.elim f₂ g₂ ∘ sum.map f₁ g₁ = sum.elim (f₂ ∘ f₁) (g₂ ∘ g₁) :=
funext $ λ _, elim_map
@[simp] lemma is_left_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
is_left (x.map f g) = is_left x :=
by cases x; refl
@[simp] lemma is_right_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
is_right (x.map f g) = is_right x :=
by cases x; refl
@[simp] lemma get_left_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
(x.map f g).get_left = x.get_left.map f :=
by cases x; refl
@[simp] lemma get_right_map (f : α → β) (g : γ → δ) (x : α ⊕ γ) :
(x.map f g).get_right = x.get_right.map g :=
by cases x; refl
open function (update update_eq_iff update_comp_eq_of_injective update_comp_eq_of_forall_ne)
@[simp] lemma update_elim_inl [decidable_eq α] [decidable_eq (α ⊕ β)] {f : α → γ} {g : β → γ}
{i : α} {x : γ} :
update (sum.elim f g) (inl i) x = sum.elim (update f i x) g :=
update_eq_iff.2 ⟨by simp, by simp { contextual := tt }⟩
@[simp] lemma update_elim_inr [decidable_eq β] [decidable_eq (α ⊕ β)] {f : α → γ} {g : β → γ}
{i : β} {x : γ} :
update (sum.elim f g) (inr i) x = sum.elim f (update g i x) :=
update_eq_iff.2 ⟨by simp, by simp { contextual := tt }⟩
@[simp] lemma update_inl_comp_inl [decidable_eq α] [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : α}
{x : γ} :
update f (inl i) x ∘ inl = update (f ∘ inl) i x :=
update_comp_eq_of_injective _ inl_injective _ _
@[simp] lemma update_inl_apply_inl [decidable_eq α] [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ}
{i j : α} {x : γ} :
update f (inl i) x (inl j) = update (f ∘ inl) i x j :=
by rw ← update_inl_comp_inl
@[simp] lemma update_inl_comp_inr [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {x : γ} :
update f (inl i) x ∘ inr = f ∘ inr :=
update_comp_eq_of_forall_ne _ _ $ λ _, inr_ne_inl
@[simp] lemma update_inl_apply_inr [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {j : β} {x : γ} :
update f (inl i) x (inr j) = f (inr j) :=
function.update_noteq inr_ne_inl _ _
@[simp] lemma update_inr_comp_inl [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : β} {x : γ} :
update f (inr i) x ∘ inl = f ∘ inl :=
update_comp_eq_of_forall_ne _ _ $ λ _, inl_ne_inr
@[simp] lemma update_inr_apply_inl [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : α} {j : β} {x : γ} :
update f (inr j) x (inl i) = f (inl i) :=
function.update_noteq inl_ne_inr _ _
@[simp] lemma update_inr_comp_inr [decidable_eq β] [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ} {i : β}
{x : γ} :
update f (inr i) x ∘ inr = update (f ∘ inr) i x :=
update_comp_eq_of_injective _ inr_injective _ _
@[simp] lemma update_inr_apply_inr [decidable_eq β] [decidable_eq (α ⊕ β)] {f : α ⊕ β → γ}
{i j : β} {x : γ} :
update f (inr i) x (inr j) = update (f ∘ inr) i x j :=
by rw ← update_inr_comp_inr
/-- Swap the factors of a sum type -/
def swap : α ⊕ β → β ⊕ α := sum.elim inr inl
@[simp] lemma swap_inl (x : α) : swap (inl x : α ⊕ β) = inr x := rfl
@[simp] lemma swap_inr (x : β) : swap (inr x : α ⊕ β) = inl x := rfl
@[simp] lemma swap_swap (x : α ⊕ β) : swap (swap x) = x := by cases x; refl
@[simp] lemma swap_swap_eq : swap ∘ swap = @id (α ⊕ β) := funext $ swap_swap
@[simp] lemma swap_left_inverse : function.left_inverse (@swap α β) swap := swap_swap
@[simp] lemma swap_right_inverse : function.right_inverse (@swap α β) swap := swap_swap
@[simp] lemma is_left_swap (x : α ⊕ β) : x.swap.is_left = x.is_right := by cases x; refl
@[simp] lemma is_right_swap (x : α ⊕ β) : x.swap.is_right = x.is_left := by cases x; refl
@[simp] lemma get_left_swap (x : α ⊕ β) : x.swap.get_left = x.get_right := by cases x; refl
@[simp] lemma get_right_swap (x : α ⊕ β) : x.swap.get_right = x.get_left := by cases x; refl
section lift_rel
/-- Lifts pointwise two relations between `α` and `γ` and between `β` and `δ` to a relation between
`α ⊕ β` and `γ ⊕ δ`. -/
inductive lift_rel (r : α → γ → Prop) (s : β → δ → Prop) : α ⊕ β → γ ⊕ δ → Prop
| inl {a c} : r a c → lift_rel (inl a) (inl c)
| inr {b d} : s b d → lift_rel (inr b) (inr d)
attribute [protected] lift_rel.inl lift_rel.inr
variables {r r₁ r₂ : α → γ → Prop} {s s₁ s₂ : β → δ → Prop} {a : α} {b : β} {c : γ} {d : δ}
{x : α ⊕ β} {y : γ ⊕ δ}
@[simp] lemma lift_rel_inl_inl : lift_rel r s (inl a) (inl c) ↔ r a c :=
⟨λ h, by { cases h, assumption }, lift_rel.inl⟩
@[simp] lemma not_lift_rel_inl_inr : ¬ lift_rel r s (inl a) (inr d) .
@[simp] lemma not_lift_rel_inr_inl : ¬ lift_rel r s (inr b) (inl c) .
@[simp] lemma lift_rel_inr_inr : lift_rel r s (inr b) (inr d) ↔ s b d :=
⟨λ h, by { cases h, assumption }, lift_rel.inr⟩
instance [Π a c, decidable (r a c)] [Π b d, decidable (s b d)] :
Π (ab : α ⊕ β) (cd : γ ⊕ δ), decidable (lift_rel r s ab cd)
| (inl a) (inl c) := decidable_of_iff' _ lift_rel_inl_inl
| (inl a) (inr d) := decidable.is_false not_lift_rel_inl_inr
| (inr b) (inl c) := decidable.is_false not_lift_rel_inr_inl
| (inr b) (inr d) := decidable_of_iff' _ lift_rel_inr_inr
lemma lift_rel.mono (hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ a b, s₁ a b → s₂ a b)
(h : lift_rel r₁ s₁ x y) :
lift_rel r₂ s₂ x y :=
by { cases h, exacts [lift_rel.inl (hr _ _ ‹_›), lift_rel.inr (hs _ _ ‹_›)] }
lemma lift_rel.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) (h : lift_rel r₁ s x y) :
lift_rel r₂ s x y :=
h.mono hr $ λ _ _, id
lemma lift_rel.mono_right (hs : ∀ a b, s₁ a b → s₂ a b) (h : lift_rel r s₁ x y) :
lift_rel r s₂ x y :=
h.mono (λ _ _, id) hs
protected lemma lift_rel.swap (h : lift_rel r s x y) : lift_rel s r x.swap y.swap :=
by { cases h, exacts [lift_rel.inr ‹_›, lift_rel.inl ‹_›] }
@[simp] lemma lift_rel_swap_iff : lift_rel s r x.swap y.swap ↔ lift_rel r s x y :=
⟨λ h, by { rw [←swap_swap x, ←swap_swap y], exact h.swap }, lift_rel.swap⟩
end lift_rel
section lex
/-- Lexicographic order for sum. Sort all the `inl a` before the `inr b`, otherwise use the
respective order on `α` or `β`. -/
inductive lex (r : α → α → Prop) (s : β → β → Prop) : α ⊕ β → α ⊕ β → Prop
| inl {a₁ a₂} (h : r a₁ a₂) : lex (inl a₁) (inl a₂)
| inr {b₁ b₂} (h : s b₁ b₂) : lex (inr b₁) (inr b₂)
| sep (a b) : lex (inl a) (inr b)
attribute [protected] sum.lex.inl sum.lex.inr
attribute [simp] lex.sep
variables {r r₁ r₂ : α → α → Prop} {s s₁ s₂ : β → β → Prop} {a a₁ a₂ : α} {b b₁ b₂ : β}
{x y : α ⊕ β}
@[simp] lemma lex_inl_inl : lex r s (inl a₁) (inl a₂) ↔ r a₁ a₂ :=
⟨λ h, by { cases h, assumption }, lex.inl⟩
@[simp] lemma lex_inr_inr : lex r s (inr b₁) (inr b₂) ↔ s b₁ b₂ :=
⟨λ h, by { cases h, assumption }, lex.inr⟩
@[simp] lemma lex_inr_inl : ¬ lex r s (inr b) (inl a) .
instance [decidable_rel r] [decidable_rel s] : decidable_rel (lex r s)
| (inl a) (inl c) := decidable_of_iff' _ lex_inl_inl
| (inl a) (inr d) := decidable.is_true (lex.sep _ _)
| (inr b) (inl c) := decidable.is_false lex_inr_inl
| (inr b) (inr d) := decidable_of_iff' _ lex_inr_inr
protected lemma lift_rel.lex {a b : α ⊕ β} (h : lift_rel r s a b) : lex r s a b :=
by { cases h, exacts [lex.inl ‹_›, lex.inr ‹_›] }
lemma lift_rel_subrelation_lex : subrelation (lift_rel r s) (lex r s) := λ a b, lift_rel.lex
lemma lex.mono (hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ a b, s₁ a b → s₂ a b) (h : lex r₁ s₁ x y) :
lex r₂ s₂ x y :=
by { cases h, exacts [lex.inl (hr _ _ ‹_›), lex.inr (hs _ _ ‹_›), lex.sep _ _] }
lemma lex.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) (h : lex r₁ s x y) : lex r₂ s x y :=
h.mono hr $ λ _ _, id
lemma lex.mono_right (hs : ∀ a b, s₁ a b → s₂ a b) (h : lex r s₁ x y) : lex r s₂ x y :=
h.mono (λ _ _, id) hs
lemma lex_acc_inl {a} (aca : acc r a) : acc (lex r s) (inl a) :=
begin
induction aca with a H IH,
constructor, intros y h,
cases h with a' _ h',
exact IH _ h'
end
lemma lex_acc_inr (aca : ∀ a, acc (lex r s) (inl a)) {b} (acb : acc s b) : acc (lex r s) (inr b) :=
begin
induction acb with b H IH,
constructor, intros y h,
cases h with _ _ _ b' _ h' a,
{ exact IH _ h' },
{ exact aca _ }
end
lemma lex_wf (ha : well_founded r) (hb : well_founded s) : well_founded (lex r s) :=
have aca : ∀ a, acc (lex r s) (inl a), from λ a, lex_acc_inl (ha.apply a),
⟨λ x, sum.rec_on x aca (λ b, lex_acc_inr aca (hb.apply b))⟩
end lex
end sum
open sum
namespace function
lemma injective.sum_elim {f : α → γ} {g : β → γ}
(hf : injective f) (hg : injective g) (hfg : ∀ a b, f a ≠ g b) :
injective (sum.elim f g)
| (inl x) (inl y) h := congr_arg inl $ hf h
| (inl x) (inr y) h := (hfg x y h).elim
| (inr x) (inl y) h := (hfg y x h.symm).elim
| (inr x) (inr y) h := congr_arg inr $ hg h
lemma injective.sum_map {f : α → β} {g : α' → β'} (hf : injective f) (hg : injective g) :
injective (sum.map f g)
| (inl x) (inl y) h := congr_arg inl $ hf $ inl.inj h
| (inr x) (inr y) h := congr_arg inr $ hg $ inr.inj h
lemma surjective.sum_map {f : α → β} {g : α' → β'} (hf : surjective f) (hg : surjective g) :
surjective (sum.map f g)
| (inl y) := let ⟨x, hx⟩ := hf y in ⟨inl x, congr_arg inl hx⟩
| (inr y) := let ⟨x, hx⟩ := hg y in ⟨inr x, congr_arg inr hx⟩
lemma bijective.sum_map {f : α → β} {g : α' → β'} (hf : bijective f) (hg : bijective g) :
bijective (sum.map f g) :=
⟨hf.injective.sum_map hg.injective, hf.surjective.sum_map hg.surjective⟩
end function
namespace sum
open function
@[simp] lemma map_injective {f : α → γ} {g : β → δ} :
injective (sum.map f g) ↔ injective f ∧ injective g :=
⟨λ h, ⟨λ a₁ a₂ ha, inl_injective $ @h (inl a₁) (inl a₂) (congr_arg inl ha : _),
λ b₁ b₂ hb, inr_injective $ @h (inr b₁) (inr b₂) (congr_arg inr hb : _)⟩,
λ h, h.1.sum_map h.2⟩
@[simp] lemma map_surjective {f : α → γ} {g : β → δ} :
surjective (sum.map f g) ↔ surjective f ∧ surjective g :=
⟨λ h, ⟨λ c, begin
obtain ⟨a | b, h⟩ := h (inl c),
{ exact ⟨a, inl_injective h⟩ },
{ cases h },
end, λ d, begin
obtain ⟨a | b, h⟩ := h (inr d),
{ cases h },
{ exact ⟨b, inr_injective h⟩ },
end⟩, λ h, h.1.sum_map h.2⟩
@[simp] lemma map_bijective {f : α → γ} {g : β → δ} :
bijective (sum.map f g) ↔ bijective f ∧ bijective g :=
(map_injective.and map_surjective).trans $ and_and_and_comm _ _ _ _
lemma elim_const_const (c : γ) :
sum.elim (const _ c : α → γ) (const _ c : β → γ) = const _ c :=
by { ext x, cases x; refl }
@[simp]
lemma elim_lam_const_lam_const (c : γ) :
sum.elim (λ (_ : α), c) (λ (_ : β), c) = λ _, c :=
sum.elim_const_const c
lemma elim_update_left [decidable_eq α] [decidable_eq β]
(f : α → γ) (g : β → γ) (i : α) (c : γ) :
sum.elim (function.update f i c) g = function.update (sum.elim f g) (inl i) c :=
begin
ext x, cases x,
{ by_cases h : x = i,
{ subst h, simp },
{ simp [h] } },
{ simp }
end
lemma elim_update_right [decidable_eq α] [decidable_eq β]
(f : α → γ) (g : β → γ) (i : β) (c : γ) :
sum.elim f (function.update g i c) = function.update (sum.elim f g) (inr i) c :=
begin
ext x, cases x,
{ simp },
{ by_cases h : x = i,
{ subst h, simp },
{ simp [h] } }
end
end sum
/-!
### Ternary sum
Abbreviations for the maps from the summands to `α ⊕ β ⊕ γ`. This is useful for pattern-matching.
-/
namespace sum3
/-- The map from the first summand into a ternary sum. -/
@[pattern, simp, reducible] def in₀ (a) : α ⊕ β ⊕ γ := inl a
/-- The map from the second summand into a ternary sum. -/
@[pattern, simp, reducible] def in₁ (b) : α ⊕ β ⊕ γ := inr $ inl b
/-- The map from the third summand into a ternary sum. -/
@[pattern, simp, reducible] def in₂ (c) : α ⊕ β ⊕ γ := inr $ inr c
end sum3
|
42d3ac8bf5fa4cc92744f2df08ff5eeac9f2413b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/data/nat/default_auto.lean | dc59b8f4982a180967df5db0f2fd3f5e915d329c | [] | 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 | 395 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.nat.basic
import Mathlib.Lean3Lib.init.data.nat.div
import Mathlib.Lean3Lib.init.data.nat.lemmas
import Mathlib.Lean3Lib.init.data.nat.bitwise
namespace Mathlib
end Mathlib |
44de2e947e44f3ea9811d3908d9f0a06ced0df1e | 958488bc7f3c2044206e0358e56d7690b6ae696c | /lean/while/ReducePar.lean | 08c90d6a49c3ec6aa7884dfd0252e0300c4f79ba | [] | no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 1,692,263,717,723 | 1,691,757,179,000 | 1,691,757,179,000 | 40,361,602 | 3 | 0 | null | 1,679,896,438,000 | 1,438,953,859,000 | Coq | UTF-8 | Lean | false | false | 485 | lean | import Stmt
import Reduce
open list
open Stmt
inductive ReducePar : list Stmt → Env → list Stmt → Env → Prop
| Step : ∀ (e₁ e₂:Stmt) (s₁ s₂:Env) (es : list Stmt),
Reduce e₁ s₁ e₂ s₂ → ReducePar (e₁ :: es) s₁ (e₂ :: es) s₂
| Cons : ∀ (es₁ es₂:list Stmt) (s₁ s₂:Env) (e:Stmt),
ReducePar es₁ s₁ es₂ s₂ → ReducePar (e :: es₁) s₁ (e :: es₂) s₂
def p₀ : Stmt := "x" :== aNum 42
def p₁ : Stmt := "x" :== aNum 99
|
ed9b17117ccc6a7fd3d984041a3295ee9890333f | ad0c7d243dc1bd563419e2767ed42fb323d7beea | /data/real/irrational.lean | 526f44fd4ad43820f9f697e68eb582ff677443bd | [
"Apache-2.0"
] | permissive | sebzim4500/mathlib | e0b5a63b1655f910dee30badf09bd7e191d3cf30 | 6997cafbd3a7325af5cb318561768c316ceb7757 | refs/heads/master | 1,585,549,958,618 | 1,538,221,723,000 | 1,538,221,723,000 | 150,869,076 | 0 | 0 | Apache-2.0 | 1,538,229,323,000 | 1,538,229,323,000 | null | UTF-8 | Lean | false | false | 1,121 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
Irrationality of real numbers.
-/
import data.real.basic data.nat.prime
open real rat
def irrational (x : ℝ) := ¬ ∃ q : ℚ, x = q
theorem sqrt_two_irrational : irrational (sqrt 2)
| ⟨⟨n, d, h, c⟩, e⟩ := begin
simp [num_denom', mk_eq_div] at e,
have := mul_self_sqrt (le_of_lt two_pos),
have d0 : (0:ℝ) < d := nat.cast_pos.2 h,
rw [e, div_mul_div, div_eq_iff_mul_eq (ne_of_gt $ mul_pos d0 d0),
← int.cast_mul, ← int.nat_abs_mul_self] at this,
revert c this, generalize : n.nat_abs = a, intros,
have E : 2 * (d * d) = a * a := (@nat.cast_inj ℝ _ _ _ _ _).1 (by simpa),
have ae : 2 ∣ a,
{ refine (or_self _).1 (nat.prime_two.dvd_mul.1 _),
rw ← E, apply dvd_mul_right },
have de : 2 ∣ d,
{ have := mul_dvd_mul ae ae,
refine (or_self _).1 (nat.prime_two.dvd_mul.1 _),
rwa [← E, nat.mul_dvd_mul_iff_left (nat.succ_pos 1)] at this },
exact nat.not_coprime_of_dvd_of_dvd (nat.lt_succ_self _) ae de c
end
|
df01dfe74862259efc11555b81a9285df10d764c | 2eab05920d6eeb06665e1a6df77b3157354316ad | /src/order/zorn.lean | 50fab3552e4aed6cef0470e1696200af835ac168 | [
"Apache-2.0"
] | permissive | ayush1801/mathlib | 78949b9f789f488148142221606bf15c02b960d2 | ce164e28f262acbb3de6281b3b03660a9f744e3c | refs/heads/master | 1,692,886,907,941 | 1,635,270,866,000 | 1,635,270,866,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 16,761 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import data.set.lattice
/-!
# Chains and Zorn's lemmas
This file defines chains for an arbitrary relation and proves several formulations of Zorn's Lemma,
along with Hausdorff's Maximality Principle.
## Main declarations
* `chain c`: A chain `c` is a set of comparable elements.
* `max_chain_spec`: Hausdorff's Maximality Principle.
* `exists_maximal_of_chains_bounded`: Zorn's Lemma. Many variants are offered.
## Variants
The primary statement of Zorn's lemma is `exists_maximal_of_chains_bounded`. Then it is specialized
to particular relations:
* `(≤)` with `zorn_partial_order`
* `(⊆)` with `zorn_subset`
* `(⊇)` with `zorn_superset`
Lemma names carry modifiers:
* `₀`: Quantifies over a set, as opposed to over a type.
* `_nonempty`: Doesn't ask to prove that the empty chain is bounded and lets you give an element
that will be smaller than the maximal element found (the maximal element is no smaller than any
other element, but it can also be incomparable to some).
## How-to
This file comes across as confusing to those who haven't yet used it, so here is a detailed
walkthrough:
1. Know what relation on which type/set you're looking for. See Variants above. You can discharge
some conditions to Zorn's lemma directly using a `_nonempty` variant.
2. Write down the definition of your type/set, put a `suffices : ∃ m, ∀ a, m ≺ a → a ≺ m, { ... },`
(or whatever you actually need) followed by a `apply some_version_of_zorn`.
3. Fill in the details. This is where you start talking about chains.
A typical proof using Zorn could look like this
```lean
lemma zorny_lemma : zorny_statement :=
begin
let s : set α := {x | whatever x},
suffices : ∃ x ∈ s, ∀ y ∈ s, y ⊆ x → y = x, -- or with another operator
{ exact proof_post_zorn },
apply zorn.zorn_subset, -- or another variant
rintro c hcs hc,
obtain rfl | hcnemp := c.eq_empty_or_nonempty, -- you might need to disjunct on c empty or not
{ exact ⟨edge_case_construction,
proof_that_edge_case_construction_respects_whatever,
proof_that_edge_case_construction_contains_all_stuff_in_c⟩ },
exact ⟨construction,
proof_that_construction_respects_whatever,
proof_that_construction_contains_all_stuff_in_c⟩,
end
```
## Notes
Originally ported from Isabelle/HOL. The
[original file](https://isabelle.in.tum.de/dist/library/HOL/HOL/Zorn.html) was written by Jacques D.
Fleuriot, Tobias Nipkow, Christian Sternagel.
-/
noncomputable theory
universes u
open set classical
open_locale classical
namespace zorn
section chain
parameters {α : Type u} (r : α → α → Prop)
local infix ` ≺ `:50 := r
/-- A chain is a subset `c` satisfying `x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
def chain (c : set α) := pairwise_on c (λ x y, x ≺ y ∨ y ≺ x)
parameters {r}
lemma chain.total_of_refl [is_refl α r]
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
x ≺ y ∨ y ≺ x :=
if e : x = y then or.inl (e ▸ refl _) else H _ hx _ hy e
lemma chain.mono {c c'} :
c' ⊆ c → chain c → chain c' :=
pairwise_on.mono
lemma chain_of_trichotomous [is_trichotomous α r] (s : set α) :
chain s :=
begin
intros a _ b _ hab,
obtain h | h | h := @trichotomous _ r _ a b,
{ exact or.inl h },
{ exact (hab h).elim },
{ exact or.inr h }
end
lemma chain_univ_iff :
chain (univ : set α) ↔ is_trichotomous α r :=
begin
refine ⟨λ h, ⟨λ a b , _⟩, λ h, @chain_of_trichotomous _ _ h univ⟩,
rw [or.left_comm, or_iff_not_imp_left],
exact h a trivial b trivial,
end
lemma chain.directed_on [is_refl α r] {c} (H : chain c) :
directed_on (≺) c :=
λ x hx y hy,
match H.total_of_refl hx hy with
| or.inl h := ⟨y, hy, h, refl _⟩
| or.inr h := ⟨x, hx, refl _, h⟩
end
lemma chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀ b ∈ c, b ≠ a → a ≺ b ∨ b ≺ a) :
chain (insert a c) :=
forall_insert_of_forall
(λ x hx, forall_insert_of_forall (hc x hx) (λ hneq, (ha x hx hneq).symm))
(forall_insert_of_forall
(λ x hx hneq, ha x hx $ λ h', hneq h'.symm) (λ h, (h rfl).rec _))
/-- `super_chain c₁ c₂` means that `c₂` is a chain that strictly includes `c₁`. -/
def super_chain (c₁ c₂ : set α) : Prop := chain c₂ ∧ c₁ ⊂ c₂
/-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/
def is_max_chain (c : set α) := chain c ∧ ¬ (∃ c', super_chain c c')
/-- Given a set `c`, if there exists a chain `c'` strictly including `c`, then `succ_chain c`
is one of these chains. Otherwise it is `c`. -/
def succ_chain (c : set α) : set α :=
if h : ∃ c', chain c ∧ super_chain c c' then some h else c
lemma succ_spec {c : set α} (h : ∃ c', chain c ∧ super_chain c c') :
super_chain c (succ_chain c) :=
let ⟨c', hc'⟩ := h in
have chain c ∧ super_chain c (some h),
from @some_spec _ (λ c', chain c ∧ super_chain c c') _,
by simp [succ_chain, dif_pos, h, this.right]
lemma chain_succ {c : set α} (hc : chain c) :
chain (succ_chain c) :=
if h : ∃ c', chain c ∧ super_chain c c' then
(succ_spec h).left
else
by simp [succ_chain, dif_neg, h]; exact hc
lemma super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
super_chain c (succ_chain c) :=
begin
simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂,
cases hc₂.neg_resolve_left hc₁ with c' hc',
exact succ_spec ⟨c', hc₁, hc'⟩
end
lemma succ_increasing {c : set α} :
c ⊆ succ_chain c :=
if h : ∃ c', chain c ∧ super_chain c c' then
have super_chain c (succ_chain c), from succ_spec h,
this.right.left
else by simp [succ_chain, dif_neg, h, subset.refl]
/-- Set of sets reachable from `∅` using `succ_chain` and `⋃₀`. -/
inductive chain_closure : set (set α)
| succ : ∀ {s}, chain_closure s → chain_closure (succ_chain s)
| union : ∀ {s}, (∀ a ∈ s, chain_closure a) → chain_closure (⋃₀ s)
lemma chain_closure_empty :
∅ ∈ chain_closure :=
have chain_closure (⋃₀ ∅),
from chain_closure.union $ λ a h, h.rec _,
by simp at this; assumption
lemma chain_closure_closure :
⋃₀ chain_closure ∈ chain_closure :=
chain_closure.union $ λ s hs, hs
variables {c c₁ c₂ c₃ : set α}
private lemma chain_closure_succ_total_aux (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
(h : ∀ {c₃}, c₃ ∈ chain_closure → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ :=
begin
induction hc₁,
case succ : c₃ hc₃ ih {
cases ih with ih ih,
{ have h := h hc₃ ih,
cases h with h h,
{ exact or.inr (h ▸ subset.refl _) },
{ exact or.inl h } },
{ exact or.inr (subset.trans ih succ_increasing) } },
case union : s hs ih {
refine (or_iff_not_imp_right.2 $ λ hn, sUnion_subset $ λ a ha, _),
apply (ih a ha).resolve_right,
apply mt (λ h, _) hn,
exact subset.trans h (subset_sUnion_of_mem ha) }
end
private lemma chain_closure_succ_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
(h : c₁ ⊆ c₂) :
c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ :=
begin
induction hc₂ generalizing c₁ hc₁ h,
case succ : c₂ hc₂ ih {
have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ :=
(chain_closure_succ_total_aux hc₁ hc₂ $ λ c₁, ih),
cases h₁ with h₁ h₁,
{ have h₂ := ih hc₁ h₁,
cases h₂ with h₂ h₂,
{ exact (or.inr $ h₂ ▸ subset.refl _) },
{ exact (or.inr $ subset.trans h₂ succ_increasing) } },
{ exact (or.inl $ subset.antisymm h₁ h) } },
case union : s hs ih {
apply or.imp_left (λ h', subset.antisymm h' h),
apply classical.by_contradiction,
simp [not_or_distrib, sUnion_subset_iff, not_forall],
intros c₃ hc₃ h₁ h₂,
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (λ c₄, ih _ hc₃),
cases h with h h,
{ have h' := ih c₃ hc₃ hc₁ h,
cases h' with h' h',
{ exact (h₁ $ h' ▸ subset.refl _) },
{ exact (h₂ $ subset.trans h' $ subset_sUnion_of_mem hc₃) } },
{ exact (h₁ $ subset.trans succ_increasing h) } }
end
lemma chain_closure_total (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure) :
c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
or.imp_right succ_increasing.trans $ chain_closure_succ_total_aux hc₁ hc₂ $ λ c₃ hc₃,
chain_closure_succ_total hc₃ hc₂
lemma chain_closure_succ_fixpoint (hc₁ : c₁ ∈ chain_closure) (hc₂ : c₂ ∈ chain_closure)
(h_eq : succ_chain c₂ = c₂) :
c₁ ⊆ c₂ :=
begin
induction hc₁,
case succ : c₁ hc₁ h {
exact or.elim (chain_closure_succ_total hc₁ hc₂ h)
(λ h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
case union : s hs ih {
exact (sUnion_subset $ λ c₁ hc₁, ih c₁ hc₁) }
end
lemma chain_closure_succ_fixpoint_iff (hc : c ∈ chain_closure) :
succ_chain c = c ↔ c = ⋃₀ chain_closure :=
⟨λ h, (subset_sUnion_of_mem hc).antisymm
(chain_closure_succ_fixpoint chain_closure_closure hc h),
λ h,
subset.antisymm
(calc succ_chain c ⊆ ⋃₀{c : set α | c ∈ chain_closure} :
subset_sUnion_of_mem $ chain_closure.succ hc
... = c : h.symm)
succ_increasing⟩
lemma chain_chain_closure (hc : c ∈ chain_closure) :
chain c :=
begin
induction hc,
case succ : c hc h {
exact chain_succ h },
case union : s hs h {
have h : ∀ c ∈ s, zorn.chain c := h,
exact λ c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂),
or.elim this
(λ ht, h t₂ ht₂ c₁ (ht hc₁) c₂ hc₂ hneq)
(λ ht, h t₁ ht₁ c₁ hc₁ c₂ (ht hc₂) hneq) }
end
/-- An explicit maximal chain. `max_chain` is taken to be the union of all sets in `chain_closure`.
-/
def max_chain := ⋃₀ chain_closure
/-- Hausdorff's maximality principle
There exists a maximal totally ordered subset of `α`.
Note that we do not require `α` to be partially ordered by `r`. -/
theorem max_chain_spec :
is_max_chain max_chain :=
classical.by_contradiction $ λ h,
begin
obtain ⟨h₁, H⟩ := super_of_not_max (chain_chain_closure chain_closure_closure) h,
obtain ⟨h₂, h₃⟩ := ssubset_iff_subset_ne.1 H,
exact h₃ ((chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl).symm,
end
/-- Zorn's lemma
If every chain has an upper bound, then there exists a maximal element. -/
theorem exists_maximal_of_chains_bounded (h : ∀ c, chain c → ∃ ub, ∀ a ∈ c, a ≺ ub)
(trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) :
∃ m, ∀ a, m ≺ a → a ≺ m :=
have ∃ ub, ∀ a ∈ max_chain, a ≺ ub,
from h _ $ max_chain_spec.left,
let ⟨ub, (hub : ∀ a ∈ max_chain, a ≺ ub)⟩ := this in
⟨ub, λ a ha,
have chain (insert a max_chain),
from chain_insert max_chain_spec.left $ λ b hb _, or.inr $ trans (hub b hb) ha,
have a ∈ max_chain, from
classical.by_contradiction $ λ h : a ∉ max_chain,
max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩,
hub a this⟩
/-- A variant of Zorn's lemma. If every nonempty chain of a nonempty type has an upper bound, then
there is a maximal element.
-/
theorem exists_maximal_of_nonempty_chains_bounded [nonempty α]
(h : ∀ c, chain c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≺ ub)
(trans : ∀ {a b c}, a ≺ b → b ≺ c → a ≺ c) :
∃ m, ∀ a, m ≺ a → a ≺ m :=
exists_maximal_of_chains_bounded
(λ c hc,
(eq_empty_or_nonempty c).elim
(λ h, ⟨classical.arbitrary α, λ x hx, (h ▸ hx : x ∈ (∅ : set α)).elim⟩)
(h c hc))
(λ a b c, trans)
end chain
--This lemma isn't under section `chain` because `parameters` messes up with it. Feel free to fix it
/-- This can be used to turn `zorn.chain (≥)` into `zorn.chain (≤)` and vice-versa. -/
lemma chain.symm {α : Type u} {s : set α} {q : α → α → Prop} (h : chain q s) :
chain (flip q) s :=
h.mono' (λ _ _, or.symm)
theorem zorn_partial_order {α : Type u} [partial_order α]
(h : ∀ c : set α, chain (≤) c → ∃ ub, ∀ a ∈ c, a ≤ ub) :
∃ m : α, ∀ a, m ≤ a → a = m :=
let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (λ a b c, le_trans) in
⟨m, λ a ha, le_antisymm (hm a ha) ha⟩
theorem zorn_nonempty_partial_order {α : Type u} [partial_order α] [nonempty α]
(h : ∀ (c : set α), chain (≤) c → c.nonempty → ∃ ub, ∀ a ∈ c, a ≤ ub) :
∃ (m : α), ∀ a, m ≤ a → a = m :=
let ⟨m, hm⟩ := @exists_maximal_of_nonempty_chains_bounded α (≤) _ h (λ a b c, le_trans) in
⟨m, λ a ha, le_antisymm (hm a ha) ha⟩
theorem zorn_partial_order₀ {α : Type u} [partial_order α] (s : set α)
(ih : ∀ c ⊆ s, chain (≤) c → ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) :
∃ m ∈ s, ∀ z ∈ s, m ≤ z → z = m :=
let ⟨⟨m, hms⟩, h⟩ := @zorn_partial_order {m // m ∈ s} _
(λ c hc,
let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (λ _ ⟨⟨x, hx⟩, _, h⟩, h ▸ hx)
(by { rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq;
refine hc _ hpc _ hqc (λ t, hpq (subtype.ext_iff.1 t)) })
in ⟨⟨ub, hubs⟩, λ ⟨y, hy⟩ hc, hub _ ⟨_, hc, rfl⟩⟩)
in ⟨m, hms, λ z hzs hmz, congr_arg subtype.val (h ⟨z, hzs⟩ hmz)⟩
theorem zorn_nonempty_partial_order₀ {α : Type u} [partial_order α] (s : set α)
(ih : ∀ c ⊆ s, chain (≤) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub) (x : α) (hxs : x ∈ s) :
∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m :=
let ⟨⟨m, hms, hxm⟩, h⟩ := @zorn_partial_order {m // m ∈ s ∧ x ≤ m} _
(λ c hc, c.eq_empty_or_nonempty.elim
(λ hce, hce.symm ▸ ⟨⟨x, hxs, le_refl _⟩, λ _, false.elim⟩)
(λ ⟨m, hmc⟩,
let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (image_subset_iff.2 $ λ z hzc, z.2.1)
(by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq;
exact hc p hpc q hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in
⟨⟨ub, hubs, le_trans m.2.2 $ hub m.1 $ mem_image_of_mem _ hmc⟩,
λ a hac, hub a.1 ⟨a, hac, rfl⟩⟩)) in
⟨m, hms, hxm, λ z hzs hmz, congr_arg subtype.val $ h ⟨z, hzs, le_trans hxm hmz⟩ hmz⟩
theorem zorn_subset {α : Type u} (S : set (set α))
(h : ∀ c ⊆ S, chain (⊆) c → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) :
∃ m ∈ S, ∀ a ∈ S, m ⊆ a → a = m :=
zorn_partial_order₀ S h
theorem zorn_subset_nonempty {α : Type u} (S : set (set α))
(H : ∀ c ⊆ S, chain (⊆) c → c.nonempty → ∃ ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) :
∃ m ∈ S, x ⊆ m ∧ ∀ a ∈ S, m ⊆ a → a = m :=
zorn_nonempty_partial_order₀ _ (λ c cS hc y yc, H _ cS hc ⟨y, yc⟩) _ hx
theorem zorn_superset {α : Type u} (S : set (set α))
(h : ∀ c ⊆ S, chain (⊆) c → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) :
∃ m ∈ S, ∀ a ∈ S, a ⊆ m → a = m :=
@zorn_partial_order₀ (order_dual (set α)) _ S $ λ c cS hc, h c cS hc.symm
theorem zorn_superset_nonempty {α : Type u} (S : set (set α))
(H : ∀ c ⊆ S, chain (⊆) c → c.nonempty → ∃ lb ∈ S, ∀ s ∈ c, lb ⊆ s) (x) (hx : x ∈ S) :
∃ m ∈ S, m ⊆ x ∧ ∀ a ∈ S, a ⊆ m → a = m :=
@zorn_nonempty_partial_order₀ (order_dual (set α)) _ S (λ c cS hc y yc, H _ cS
hc.symm ⟨y, yc⟩) _ hx
lemma chain.total {α : Type u} [preorder α] {c : set α} (H : chain (≤) c) :
∀ {x y}, x ∈ c → y ∈ c → x ≤ y ∨ y ≤ x :=
λ x y, H.total_of_refl
lemma chain.image {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) (f : α → β)
(h : ∀ x y, r x y → s (f x) (f y)) {c : set α} (hrc : chain r c) :
chain s (f '' c) :=
λ x ⟨a, ha₁, ha₂⟩ y ⟨b, hb₁, hb₂⟩, ha₂ ▸ hb₂ ▸ λ hxy,
(hrc a ha₁ b hb₁ (mt (congr_arg f) $ hxy)).elim
(or.inl ∘ h _ _) (or.inr ∘ h _ _)
end zorn
lemma directed_of_chain {α β r} [is_refl β r] {f : α → β} {c : set α}
(h : zorn.chain (f ⁻¹'o r) c) :
directed r (λ x : {a : α // a ∈ c}, f x) :=
λ ⟨a, ha⟩ ⟨b, hb⟩, classical.by_cases
(λ hab : a = b, by simp only [hab, exists_prop, and_self, subtype.exists];
exact ⟨b, hb, refl _⟩)
(λ hab, (h a ha b hb hab).elim
(λ h : r (f a) (f b), ⟨⟨b, hb⟩, h, refl _⟩)
(λ h : r (f b) (f a), ⟨⟨a, ha⟩, refl _, h⟩))
|
6037803a168167298473bbac2fd1e66adc5486fc | 97f752b44fd85ec3f635078a2dd125ddae7a82b6 | /library/theories/group_theory/finsubg.lean | 51d1d74c3fafc6498b8f5e8b5cd9862da491c89f | [
"Apache-2.0"
] | permissive | tectronics/lean | ab977ba6be0fcd46047ddbb3c8e16e7c26710701 | f38af35e0616f89c6e9d7e3eb1d48e47ee666efe | refs/heads/master | 1,532,358,526,384 | 1,456,276,623,000 | 1,456,276,623,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,494 | lean | /-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Haitao Zhang
-/
-- develop the concept of finite subgroups based on finsets so that the properties
-- can be used directly without translating from the set based theory first
import data algebra.group .subgroup
open function finset
-- ⁻¹ in eq.ops conflicts with group ⁻¹
open eq.ops
namespace group_theory
open ops
section subg
-- we should be able to prove properties using finsets directly
variables {G : Type} [group G]
variable [decidable_eq G]
definition finset_mul_closed_on [reducible] (H : finset G) : Prop :=
∀ x y : G, x ∈ H → y ∈ H → x * y ∈ H
definition finset_has_inv (H : finset G) : Prop :=
∀ a : G, a ∈ H → a⁻¹ ∈ H
structure is_finsubg [class] (H : finset G) : Type :=
(has_one : 1 ∈ H)
(mul_closed : finset_mul_closed_on H)
(has_inv : finset_has_inv H)
definition univ_is_finsubg [instance] [finG : fintype G] : is_finsubg (@finset.univ G _) :=
is_finsubg.mk !mem_univ (λ x y Px Py, !mem_univ) (λ a Pa, !mem_univ)
definition one_is_finsubg [instance] : is_finsubg ('{(1:G)}) :=
is_finsubg.mk !mem_singleton
(λ x y Px Py, by rewrite [eq_of_mem_singleton Px, eq_of_mem_singleton Py, one_mul]; apply mem_singleton)
(λ x Px, by rewrite [eq_of_mem_singleton Px, one_inv]; apply mem_singleton)
lemma finsubg_has_one (H : finset G) [h : is_finsubg H] : 1 ∈ H :=
@is_finsubg.has_one G _ _ H h
lemma finsubg_mul_closed (H : finset G) [h : is_finsubg H] {x y : G} : x ∈ H → y ∈ H → x * y ∈ H :=
@is_finsubg.mul_closed G _ _ H h x y
lemma finsubg_has_inv (H : finset G) [h : is_finsubg H] {a : G} : a ∈ H → a⁻¹ ∈ H :=
@is_finsubg.has_inv G _ _ H h a
definition finsubg_to_subg [instance] {H : finset G} [h : is_finsubg H]
: is_subgroup (ts H) :=
is_subgroup.mk
(mem_eq_mem_to_set H 1 ▸ finsubg_has_one H)
(take x y, begin repeat rewrite -mem_eq_mem_to_set,
apply finsubg_mul_closed H end)
(take a, begin repeat rewrite -mem_eq_mem_to_set,
apply finsubg_has_inv H end)
open nat
lemma finsubg_eq_singleton_one_of_card_one {H : finset G} [h : is_finsubg H] :
card H = 1 → H = '{1} :=
assume Pcard, eq.symm (eq_of_card_eq_of_subset (by rewrite [Pcard])
(subset_of_forall take g,
by rewrite [mem_singleton_iff]; intro Pg; rewrite Pg; exact finsubg_has_one H))
end subg
section fin_lcoset
open set
variables {A : Type} [decidable_eq A] [group A]
definition fin_lcoset (H : finset A) (a : A) := finset.image (lmul_by a) H
definition fin_rcoset (H : finset A) (a : A) : finset A := image (rmul_by a) H
definition fin_lcosets (H G : finset A) := image (fin_lcoset H) G
definition fin_inv : finset A → finset A := image inv
variable {H : finset A}
lemma lmul_rmul {a b : A} : (lmul_by a) ∘ (rmul_by b) = (rmul_by b) ∘ (lmul_by a) :=
funext take c, calc a*(c*b) = (a*c)*b : mul.assoc
lemma fin_lrcoset_comm {a b : A} :
fin_lcoset (fin_rcoset H b) a = fin_rcoset (fin_lcoset H a) b :=
by esimp [fin_lcoset, fin_rcoset]; rewrite [-*image_comp, lmul_rmul]
lemma inv_mem_fin_inv {a : A} : a ∈ H → a⁻¹ ∈ fin_inv H :=
assume Pin, mem_image Pin rfl
lemma fin_lcoset_eq (a : A) : ts (fin_lcoset H a) = a ∘> (ts H) := calc
ts (fin_lcoset H a) = coset.l a (ts H) : to_set_image
... = a ∘> (ts H) : glcoset_eq_lcoset
lemma fin_lcoset_id : fin_lcoset H 1 = H :=
by rewrite [eq_eq_to_set_eq, fin_lcoset_eq, glcoset_id]
lemma fin_lcoset_compose (a b : A) : fin_lcoset (fin_lcoset H b) a = fin_lcoset H (a*b) :=
to_set.inj (by rewrite [*fin_lcoset_eq, glcoset_compose])
lemma fin_lcoset_inv (a : A) : fin_lcoset (fin_lcoset H a) a⁻¹ = H :=
to_set.inj (by rewrite [*fin_lcoset_eq, glcoset_inv])
lemma fin_lcoset_card (a : A) : card (fin_lcoset H a) = card H :=
card_image_eq_of_inj_on (lmul_inj_on a (ts H))
lemma fin_lcosets_card_eq {G : finset A} : ∀ gH, gH ∈ fin_lcosets H G → card gH = card H :=
take gH, assume Pcosets, obtain g Pg, from exists_of_mem_image Pcosets,
and.right Pg ▸ fin_lcoset_card g
variable [is_finsubgH : is_finsubg H]
include is_finsubgH
lemma fin_lcoset_same (x a : A) : x ∈ (fin_lcoset H a) = (fin_lcoset H x = fin_lcoset H a) :=
begin
rewrite mem_eq_mem_to_set,
rewrite [eq_eq_to_set_eq, *(fin_lcoset_eq x), fin_lcoset_eq a],
exact (subg_lcoset_same x a)
end
lemma fin_mem_lcoset (g : A) : g ∈ fin_lcoset H g :=
have P : g ∈ g ∘> ts H, from and.left (subg_in_coset_refl g),
assert P1 : g ∈ ts (fin_lcoset H g), from eq.symm (fin_lcoset_eq g) ▸ P,
eq.symm (mem_eq_mem_to_set _ g) ▸ P1
lemma fin_lcoset_subset {S : finset A} (Psub : S ⊆ H) : ∀ x, x ∈ H → fin_lcoset S x ⊆ H :=
assert Psubs : set.subset (ts S) (ts H), from subset_eq_to_set_subset S H ▸ Psub,
take x, assume Pxs : x ∈ ts H,
assert Pcoset : set.subset (x ∘> ts S) (ts H), from subg_lcoset_subset_subg Psubs x Pxs,
by rewrite [subset_eq_to_set_subset, fin_lcoset_eq x]; exact Pcoset
lemma finsubg_lcoset_id {a : A} : a ∈ H → fin_lcoset H a = H :=
by rewrite [eq_eq_to_set_eq, fin_lcoset_eq, mem_eq_mem_to_set]; apply subgroup_lcoset_id
lemma finsubg_inv_lcoset_eq_rcoset {a : A} :
fin_inv (fin_lcoset H a) = fin_rcoset H a⁻¹ :=
begin
esimp [fin_inv, fin_lcoset, fin_rcoset],
rewrite [-image_comp],
apply ext, intro b,
rewrite [*mem_image_iff, ↑compose, ↑lmul_by, ↑rmul_by],
apply iff.intro,
intro Pl, cases Pl with h Ph, cases Ph with Pin Peq,
existsi h⁻¹, apply and.intro,
exact finsubg_has_inv H Pin,
rewrite [-mul_inv, Peq],
intro Pr, cases Pr with h Ph, cases Ph with Pin Peq,
existsi h⁻¹, apply and.intro,
exact finsubg_has_inv H Pin,
rewrite [mul_inv, inv_inv, Peq],
end
lemma finsubg_conj_closed {g h : A} : g ∈ H → h ∈ H → g ∘c h ∈ H :=
assume Pgin Phin, finsubg_mul_closed H (finsubg_mul_closed H Pgin Phin) (finsubg_has_inv H Pgin)
variable {G : finset A}
variable [is_finsubgG : is_finsubg G]
include is_finsubgG
open finset.partition
definition fin_lcoset_partition_subg (Psub : H ⊆ G) :=
partition.mk G (fin_lcoset H) fin_lcoset_same
(restriction_imp_union (fin_lcoset H) fin_lcoset_same (fin_lcoset_subset Psub))
open nat
theorem lagrange_theorem (Psub : H ⊆ G) : card G = card (fin_lcosets H G) * card H := calc
card G = finset.Sum (fin_lcosets H G) card : class_equation (fin_lcoset_partition_subg Psub)
... = finset.Sum (fin_lcosets H G) (λ x, card H) : finset.Sum_ext (take g P, fin_lcosets_card_eq g P)
... = card (fin_lcosets H G) * card H : Sum_const_eq_card_mul
end fin_lcoset
section
open fintype list subtype
lemma dinj_tag {A : Type} (P : A → Prop) : dinj P tag :=
take a₁ a₂ Pa₁ Pa₂ Pteq, subtype.no_confusion Pteq (λ Pe Pqe, Pe)
open nat
lemma card_pos {A : Type} [ambientA : group A] [finA : fintype A] : 0 < card A :=
length_pos_of_mem (mem_univ 1)
end
section lcoset_fintype
open fintype list subtype
variables {A : Type} [group A] [fintype A] [decidable_eq A]
variables G H : finset A
definition is_fin_lcoset [reducible] (S : finset A) : Prop :=
∃ g, g ∈ G ∧ fin_lcoset H g = S
definition to_list : list A := list.filter (λ g, g ∈ G) (elems A)
definition list_lcosets : list (finset A) := erase_dup (map (fin_lcoset H) (to_list G))
definition lcoset_type [reducible] : Type := {S : finset A | is_fin_lcoset G H S}
definition all_lcosets : list (lcoset_type G H) :=
dmap (is_fin_lcoset G H) tag (list_lcosets G H)
variables {G H} [finsubgG : is_finsubg G]
include finsubgG
lemma self_is_lcoset : is_fin_lcoset G H H :=
exists.intro 1 (and.intro !finsubg_has_one fin_lcoset_id)
lemma lcoset_subset_of_subset (J : lcoset_type G H) : H ⊆ G → elt_of J ⊆ G :=
assume Psub, obtain j Pjin Pj, from has_property J,
by rewrite [-Pj]; apply fin_lcoset_subset Psub; exact Pjin
variables (G H)
definition lcoset_one : lcoset_type G H := tag H self_is_lcoset
variables {G H}
definition lcoset_lmul {g : A} (Pgin : g ∈ G) (S : lcoset_type G H)
: lcoset_type G H :=
tag (fin_lcoset (elt_of S) g)
(obtain f Pfin Pf, from has_property S,
exists.intro (g*f)
(by apply and.intro;
exact finsubg_mul_closed G Pgin Pfin;
rewrite [-Pf, -fin_lcoset_compose]))
definition lcoset_mul (S₁ S₂ : lcoset_type G H): finset A :=
Union (elt_of S₁) (fin_lcoset (elt_of S₂))
lemma mul_mem_lcoset_mul (J K : lcoset_type G H) {g h} :
g ∈ elt_of J → h ∈ elt_of K → g*h ∈ lcoset_mul J K :=
assume Pg, begin
rewrite [↑lcoset_mul, mem_Union_iff, ↑fin_lcoset],
intro Ph, existsi g, apply and.intro, exact Pg,
rewrite [mem_image_iff, ↑lmul_by],
existsi h, exact and.intro Ph rfl
end
lemma is_lcoset_of_mem_list_lcosets {S : finset A}
: S ∈ list_lcosets G H → is_fin_lcoset G H S :=
assume Pin, obtain g Pgin Pg, from exists_of_mem_map (mem_of_mem_erase_dup Pin),
exists.intro g (and.intro (of_mem_filter Pgin) Pg)
lemma mem_list_lcosets_of_is_lcoset {S : finset A}
: is_fin_lcoset G H S → S ∈ list_lcosets G H :=
assume Plcoset, obtain g Pgin Pg, from Plcoset,
Pg ▸ mem_erase_dup (mem_map _ (mem_filter_of_mem (complete g) Pgin))
lemma fin_lcosets_eq :
fin_lcosets H G = to_finset_of_nodup (list_lcosets G H) !nodup_erase_dup :=
ext (take S, iff.intro
(λ Pimg, mem_list_lcosets_of_is_lcoset (exists_of_mem_image Pimg))
(λ Pl, obtain g Pg, from is_lcoset_of_mem_list_lcosets Pl,
iff.elim_right !mem_image_iff (is_lcoset_of_mem_list_lcosets Pl)))
lemma length_all_lcosets : length (all_lcosets G H) = card (fin_lcosets H G) :=
eq.trans
(show length (all_lcosets G H) = length (list_lcosets G H), from
assert Pmap : map elt_of (all_lcosets G H) = list_lcosets G H, from
map_dmap_of_inv_of_pos (λ S P, rfl) (λ S, is_lcoset_of_mem_list_lcosets),
by rewrite[-Pmap, length_map])
(by rewrite fin_lcosets_eq)
lemma lcoset_lmul_compose {f g : A} (Pf : f ∈ G) (Pg : g ∈ G) (S : lcoset_type G H) :
lcoset_lmul Pf (lcoset_lmul Pg S) = lcoset_lmul (finsubg_mul_closed G Pf Pg) S :=
subtype.eq !fin_lcoset_compose
lemma lcoset_lmul_one (S : lcoset_type G H) : lcoset_lmul !finsubg_has_one S = S :=
subtype.eq fin_lcoset_id
lemma lcoset_lmul_inv {g : A} {Pg : g ∈ G} (S : lcoset_type G H) :
lcoset_lmul (finsubg_has_inv G Pg) (lcoset_lmul Pg S) = S :=
subtype.eq (to_set.inj begin
esimp [lcoset_lmul],
rewrite [fin_lcoset_compose, mul.left_inv, fin_lcoset_eq, glcoset_id]
end)
lemma lcoset_lmul_inj {g : A} {Pg : g ∈ G}:
@injective (lcoset_type G H) _ (lcoset_lmul Pg) :=
injective_of_has_left_inverse (exists.intro (lcoset_lmul (finsubg_has_inv G Pg)) lcoset_lmul_inv)
lemma card_elt_of_lcoset_type (S : lcoset_type G H) : card (elt_of S) = card H :=
obtain f Pfin Pf, from has_property S, Pf ▸ fin_lcoset_card f
definition lcoset_fintype [instance] : fintype (lcoset_type G H) :=
fintype.mk (all_lcosets G H)
(dmap_nodup_of_dinj (dinj_tag (is_fin_lcoset G H)) !nodup_erase_dup)
(take s, subtype.destruct s (take S, assume PS, mem_dmap PS (mem_list_lcosets_of_is_lcoset PS)))
lemma card_lcoset_type : card (lcoset_type G H) = card (fin_lcosets H G) :=
length_all_lcosets
open nat
variable [finsubgH : is_finsubg H]
include finsubgH
theorem lagrange_theorem' (Psub : H ⊆ G) : card G = card (lcoset_type G H) * card H :=
calc card G = card (fin_lcosets H G) * card H : lagrange_theorem Psub
... = card (lcoset_type G H) * card H : card_lcoset_type
lemma lcoset_disjoint {S₁ S₂ : lcoset_type G H} : S₁ ≠ S₂ → elt_of S₁ ∩ elt_of S₂ = ∅ :=
obtain f₁ Pfin₁ Pf₁, from has_property S₁,
obtain f₂ Pfin₂ Pf₂, from has_property S₂,
assume Pne, inter_eq_empty_of_disjoint (disjoint.intro
take g, begin
rewrite [-Pf₁, -Pf₂, *fin_lcoset_same],
intro Pgf₁, rewrite [Pgf₁, Pf₁, Pf₂],
intro Peq, exact absurd (subtype.eq Peq) Pne
end )
lemma card_Union_lcosets (lcs : finset (lcoset_type G H)) :
card (Union lcs elt_of) = card lcs * card H :=
calc card (Union lcs elt_of) = ∑ lc ∈ lcs, card (elt_of lc) : card_Union_of_disjoint lcs elt_of (λ (S₁ S₂ : lcoset_type G H) P₁ P₂ Pne, lcoset_disjoint Pne)
... = ∑ lc ∈ lcs, card H : Sum_ext (take lc P, card_elt_of_lcoset_type _)
... = card lcs * card H : Sum_const_eq_card_mul
lemma exists_of_lcoset_type (J : lcoset_type G H) :
∃ j, j ∈ elt_of J ∧ fin_lcoset H j = elt_of J :=
obtain j Pjin Pj, from has_property J,
exists.intro j (and.intro (Pj ▸ !fin_mem_lcoset) Pj)
lemma lcoset_not_empty (J : lcoset_type G H) : elt_of J ≠ ∅ :=
obtain j Pjin Pj, from has_property J,
assume Pempty, absurd (by rewrite [-Pempty, -Pj]; apply fin_mem_lcoset) (not_mem_empty j)
end lcoset_fintype
section normalizer
open subtype
variables {G : Type} [ambientG : group G] [finG : fintype G] [deceqG : decidable_eq G]
include ambientG deceqG finG
variable H : finset G
definition normalizer : finset G := {g ∈ univ | ∀ h, h ∈ H → g ∘c h ∈ H}
variable {H}
variable [finsubgH : is_finsubg H]
include finsubgH
lemma subset_normalizer : H ⊆ normalizer H :=
subset_of_forall take g, assume PginH, mem_sep_of_mem !mem_univ
(take h, assume PhinH, finsubg_conj_closed PginH PhinH)
lemma normalizer_has_one : 1 ∈ normalizer H :=
mem_of_subset_of_mem subset_normalizer (finsubg_has_one H)
lemma normalizer_mul_closed : finset_mul_closed_on (normalizer H) :=
take f g, assume Pfin Pgin,
mem_sep_of_mem !mem_univ take h, assume Phin, begin
rewrite [-conj_compose],
apply of_mem_sep Pfin,
apply of_mem_sep Pgin,
exact Phin
end
lemma conj_eq_of_mem_normalizer {g : G} : g ∈ normalizer H → image (conj_by g) H = H :=
assume Pgin,
eq_of_card_eq_of_subset (card_image_eq_of_inj_on (take h j, assume P1 P2, !conj_inj))
(subset_of_forall take h, assume Phin,
obtain j Pjin Pj, from exists_of_mem_image Phin,
begin substvars, apply of_mem_sep Pgin, exact Pjin end)
lemma normalizer_has_inv : finset_has_inv (normalizer H) :=
take g, assume Pgin,
mem_sep_of_mem !mem_univ take h, begin
rewrite [-(conj_eq_of_mem_normalizer Pgin) at {1}, mem_image_iff],
intro Pex, cases Pex with k Pk,
rewrite [-(and.right Pk), conj_compose, mul.left_inv, conj_id],
exact and.left Pk
end
definition normalizer_is_finsubg [instance] : is_finsubg (normalizer H) :=
is_finsubg.mk normalizer_has_one normalizer_mul_closed normalizer_has_inv
lemma lcoset_subset_normalizer (J : lcoset_type (normalizer H) H) :
elt_of J ⊆ normalizer H :=
lcoset_subset_of_subset J subset_normalizer
lemma lcoset_subset_normalizer_of_mem {g : G} :
g ∈ normalizer H → fin_lcoset H g ⊆ normalizer H :=
assume Pgin, fin_lcoset_subset subset_normalizer g Pgin
lemma lrcoset_same_of_mem_normalizer {g : G} :
g ∈ normalizer H → fin_lcoset H g = fin_rcoset H g :=
assume Pg, ext take h, iff.intro
(assume Pl, obtain j Pjin Pj, from exists_of_mem_image Pl,
mem_image (of_mem_sep Pg j Pjin)
(calc g*j*g⁻¹*g = g*j : inv_mul_cancel_right
... = h : Pj))
(assume Pr, obtain j Pjin Pj, from exists_of_mem_image Pr,
mem_image (of_mem_sep (finsubg_has_inv (normalizer H) Pg) j Pjin)
(calc g*(g⁻¹*j*g⁻¹⁻¹) = g*(g⁻¹*j*g) : inv_inv
... = g*(g⁻¹*(j*g)) : mul.assoc
... = j*g : mul_inv_cancel_left
... = h : Pj))
lemma lcoset_mul_eq_lcoset (J K : lcoset_type (normalizer H) H) {g : G} :
g ∈ elt_of J → (lcoset_mul J K) = fin_lcoset (elt_of K) g :=
assume Pgin,
obtain j Pjin Pj, from has_property J,
obtain k Pkin Pk, from has_property K,
Union_const (lcoset_not_empty J) begin
rewrite [-Pk], intro h Phin,
assert Phinn : h ∈ normalizer H,
apply mem_of_subset_of_mem (lcoset_subset_normalizer_of_mem Pjin),
rewrite Pj, assumption,
revert Phin Pgin,
rewrite [-Pj, *fin_lcoset_same],
intro Pheq Pgeq,
rewrite [*(lrcoset_same_of_mem_normalizer Pkin), *fin_lrcoset_comm, Pheq, Pgeq]
end
lemma lcoset_mul_is_lcoset (J K : lcoset_type (normalizer H) H) :
is_fin_lcoset (normalizer H) H (lcoset_mul J K) :=
obtain j Pjin Pj, from has_property J,
obtain k Pkin Pk, from has_property K,
exists.intro (j*k) (and.intro (finsubg_mul_closed _ Pjin Pkin)
begin rewrite [lcoset_mul_eq_lcoset J K (Pj ▸ fin_mem_lcoset j), -fin_lcoset_compose, Pk] end)
lemma lcoset_inv_is_lcoset (J : lcoset_type (normalizer H) H) :
is_fin_lcoset (normalizer H) H (fin_inv (elt_of J)) :=
obtain j Pjin Pj, from has_property J, exists.intro j⁻¹
begin
rewrite [-Pj, finsubg_inv_lcoset_eq_rcoset],
apply and.intro,
apply normalizer_has_inv, assumption,
apply lrcoset_same_of_mem_normalizer, apply normalizer_has_inv, assumption
end
definition fin_coset_mul (J K : lcoset_type (normalizer H) H) : lcoset_type (normalizer H) H :=
tag (lcoset_mul J K) (lcoset_mul_is_lcoset J K)
definition fin_coset_inv (J : lcoset_type (normalizer H) H) : lcoset_type (normalizer H) H :=
tag (fin_inv (elt_of J)) (lcoset_inv_is_lcoset J)
definition fin_coset_one : lcoset_type (normalizer H) H :=
tag H self_is_lcoset
local infix `^` := fin_coset_mul
lemma fin_coset_mul_eq_lcoset (J K : lcoset_type (normalizer H) H) {g : G} :
g ∈ (elt_of J) → elt_of (J ^ K) = fin_lcoset (elt_of K) g :=
assume Pgin, lcoset_mul_eq_lcoset J K Pgin
lemma fin_coset_mul_assoc (J K L : lcoset_type (normalizer H) H) :
J ^ K ^ L = J ^ (K ^ L) :=
obtain j Pjin Pj, from exists_of_lcoset_type J,
obtain k Pkin Pk, from exists_of_lcoset_type K,
assert Pjk : j*k ∈ elt_of (J ^ K), from mul_mem_lcoset_mul J K Pjin Pkin,
obtain l Plin Pl, from has_property L,
subtype.eq (begin
rewrite [fin_coset_mul_eq_lcoset (J ^ K) _ Pjk,
fin_coset_mul_eq_lcoset J _ Pjin,
fin_coset_mul_eq_lcoset K _ Pkin,
-Pl, *fin_lcoset_compose]
end)
lemma fin_coset_mul_one (J : lcoset_type (normalizer H) H) :
J ^ fin_coset_one = J :=
obtain j Pjin Pj, from exists_of_lcoset_type J,
subtype.eq begin
rewrite [↑fin_coset_one, fin_coset_mul_eq_lcoset _ _ Pjin, -Pj]
end
lemma fin_coset_one_mul (J : lcoset_type (normalizer H) H) :
fin_coset_one ^ J = J :=
subtype.eq begin
rewrite [↑fin_coset_one, fin_coset_mul_eq_lcoset _ _ (finsubg_has_one H), fin_lcoset_id]
end
lemma fin_coset_left_inv (J : lcoset_type (normalizer H) H) :
(fin_coset_inv J) ^ J = fin_coset_one :=
obtain j Pjin Pj, from exists_of_lcoset_type J,
assert Pjinv : j⁻¹ ∈ elt_of (fin_coset_inv J), from inv_mem_fin_inv Pjin,
subtype.eq begin
rewrite [↑fin_coset_one, fin_coset_mul_eq_lcoset _ _ Pjinv, -Pj, fin_lcoset_inv]
end
variable (H)
definition fin_coset_group [instance] : group (lcoset_type (normalizer H) H) :=
group.mk fin_coset_mul fin_coset_mul_assoc fin_coset_one fin_coset_one_mul fin_coset_mul_one fin_coset_inv fin_coset_left_inv
variables {H} (Hc : finset (lcoset_type (normalizer H) H))
definition fin_coset_Union : finset G := Union Hc elt_of
variables {Hc} [finsubgHc : is_finsubg Hc]
include finsubgHc
lemma mem_normalizer_of_mem_fcU {j : G} : j ∈ fin_coset_Union Hc → j ∈ normalizer H :=
assume Pjin, obtain J PJ PjJ, from iff.elim_left !mem_Union_iff Pjin,
mem_of_subset_of_mem !lcoset_subset_normalizer PjJ
lemma fcU_has_one : (1:G) ∈ fin_coset_Union Hc :=
iff.elim_right (mem_Union_iff Hc elt_of (1:G))
(exists.intro 1 (and.intro (finsubg_has_one Hc) (finsubg_has_one H)))
lemma fcU_has_inv : finset_has_inv (fin_coset_Union Hc) :=
take j, assume Pjin, obtain J PJ PjJ, from iff.elim_left !mem_Union_iff Pjin,
have PJinv : J⁻¹ ∈ Hc, from finsubg_has_inv Hc PJ,
have Pjinv : j⁻¹ ∈ elt_of J⁻¹, from inv_mem_fin_inv PjJ,
iff.elim_right !mem_Union_iff (exists.intro J⁻¹ (and.intro PJinv Pjinv))
lemma fcU_mul_closed : finset_mul_closed_on (fin_coset_Union Hc) :=
take j k, assume Pjin Pkin,
obtain J PJ PjJ, from iff.elim_left !mem_Union_iff Pjin,
obtain K PK PkK, from iff.elim_left !mem_Union_iff Pkin,
assert Pjk : j*k ∈ elt_of (J*K), from mul_mem_lcoset_mul J K PjJ PkK,
iff.elim_right !mem_Union_iff
(exists.intro (J*K) (and.intro (finsubg_mul_closed Hc PJ PK) Pjk))
definition fcU_is_finsubg [instance] : is_finsubg (fin_coset_Union Hc) :=
is_finsubg.mk fcU_has_one fcU_mul_closed fcU_has_inv
end normalizer
end group_theory
|
5dd8072343f1ddf465638acc15aa74c6996f005e | 83c8119e3298c0bfc53fc195c41a6afb63d01513 | /library/init/meta/simp_tactic.lean | a032b31a1dc7c90647d0d0fee79be5962817aebd | [
"Apache-2.0"
] | permissive | anfelor/lean | 584b91c4e87a6d95f7630c2a93fb082a87319ed0 | 31cfc2b6bf7d674f3d0f73848b842c9c9869c9f1 | refs/heads/master | 1,610,067,141,310 | 1,585,992,232,000 | 1,585,992,232,000 | 251,683,543 | 0 | 0 | Apache-2.0 | 1,585,676,570,000 | 1,585,676,569,000 | null | UTF-8 | Lean | false | false | 26,850 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic init.meta.attribute init.meta.constructor_tactic
import init.meta.relation_tactics init.meta.occurrences
import init.data.option.basic
open tactic
def simp.default_max_steps := 10000000
/-- Prefix the given `attr_name` with `"simp_attr"`. -/
meta constant mk_simp_attr_decl_name (attr_name : name) : name
/-- Simp lemmas are used by the "simplifier" family of tactics.
`simp_lemmas` is essentially a pair of tables `rb_map (expr_type × name) (priority_list simp_lemma)`.
One of the tables is for congruences and one is for everything else.
An individual simp lemma is:
- A kind which can be `Refl`, `Simp` or `Congr`.
- A pair of `expr`s `l ~> r`. The rb map is indexed by the name of `get_app_fn(l)`.
- A proof that `l = r` or `l ↔ r`.
- A list of the metavariables that must be filled before the proof can be applied.
- A priority number
-/
meta constant simp_lemmas : Type
/-- Make a new table of simp lemmas -/
meta constant simp_lemmas.mk : simp_lemmas
/-- Merge the simp_lemma tables. -/
meta constant simp_lemmas.join : simp_lemmas → simp_lemmas → simp_lemmas
/-- Remove the given lemmas from the table. Use the names of the lemmas. -/
meta constant simp_lemmas.erase : simp_lemmas → list name → simp_lemmas
/-- Makes the default simp_lemmas table which is composed of all lemmas tagged with `simp`. -/
meta constant simp_lemmas.mk_default : tactic simp_lemmas
/-- Add a simplification lemma by an expression `p`. Some conditions on `p` must hold for it to be added, see list below.
If your lemma is not being added, you can see the reasons by setting `set_option trace.simp_lemmas true`.
- `p` must have the type `Π (h₁ : _) ... (hₙ : _), LHS ~ RHS` for some reflexive, transitive relation (usually `=`).
- Any of the hypotheses `hᵢ` should either be present in `LHS` or otherwise a `Prop` or a typeclass instance.
- `LHS` should not occur within `RHS`.
- `LHS` should not occur within a hypothesis `hᵢ`.
-/
meta constant simp_lemmas.add (s : simp_lemmas) (e : expr) (symm : bool := false) : tactic simp_lemmas
/-- Add a simplification lemma by it's declaration name. See `simp_lemmas.add` for more information.-/
meta constant simp_lemmas.add_simp (s : simp_lemmas) (id : name) (symm : bool := false) : tactic simp_lemmas
/-- Adds a congruence simp lemma to simp_lemmas.
A congruence simp lemma is a lemma that breaks the simplification down into separate problems.
For example, to simplify `a ∧ b` to `c ∧ d`, we should try to simp `a` to `c` and `b` to `d`.
For examples of congruence simp lemmas look for lemmas with the `@[congr]` attribute.
```lean
lemma if_simp_congr ... (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := ...
lemma imp_congr_right (h : a → (b ↔ c)) : (a → b) ↔ (a → c) := ...
lemma and_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∧ b) ↔ (c ∧ d) := ...
```
-/
meta constant simp_lemmas.add_congr : simp_lemmas → name → tactic simp_lemmas
/-- Add expressions to a set of simp lemmas using `simp_lemmas.add`.
This is the new version of `simp_lemmas.append`,
which also allows you to set the `symm` flag.
-/
meta def simp_lemmas.append_with_symm (s : simp_lemmas) (hs : list (expr × bool)) :
tactic simp_lemmas :=
hs.mfoldl (λ s h, simp_lemmas.add s h.fst h.snd) s
/-- Add expressions to a set of simp lemmas using `simp_lemmas.add`.
This is the backwards-compatibility version of `simp_lemmas.append_with_symm`,
and sets all `symm` flags to `ff`.
-/
meta def simp_lemmas.append (s : simp_lemmas) (hs : list expr) : tactic simp_lemmas :=
hs.mfoldl (λ s h, simp_lemmas.add s h ff) s
/-- `simp_lemmas.rewrite s e prove R` apply a simplification lemma from 's'
- 'e' is the expression to be "simplified"
- 'prove' is used to discharge proof obligations.
- 'r' is the equivalence relation being used (e.g., 'eq', 'iff')
- 'md' is the transparency; how aggresively should the simplifier perform reductions.
Result (new_e, pr) is the new expression 'new_e' and a proof (pr : e R new_e) -/
meta constant simp_lemmas.rewrite (s : simp_lemmas) (e : expr)
(prove : tactic unit := failed) (r : name := `eq) (md := reducible)
: tactic (expr × expr)
meta constant simp_lemmas.rewrites (s : simp_lemmas) (e : expr)
(prove : tactic unit := failed) (r : name := `eq) (md := reducible)
: tactic $ list (expr × expr)
/-- `simp_lemmas.drewrite s e` tries to rewrite 'e' using only refl lemmas in 's' -/
meta constant simp_lemmas.drewrite (s : simp_lemmas) (e : expr) (md := reducible) : tactic expr
meta constant is_valid_simp_lemma_cnst : name → tactic bool
meta constant is_valid_simp_lemma : expr → tactic bool
meta constant simp_lemmas.pp : simp_lemmas → tactic format
meta instance : has_to_tactic_format simp_lemmas :=
⟨simp_lemmas.pp⟩
namespace tactic
/- Remark: `transform` should not change the target. -/
/-- Revert a local constant, change its type using `transform`. -/
meta def revert_and_transform (transform : expr → tactic expr) (h : expr) : tactic unit :=
do num_reverted : ℕ ← revert h,
t ← target,
match t with
| expr.pi n bi d b :=
do h_simp ← transform d,
unsafe_change $ expr.pi n bi h_simp b
| expr.elet n g e f :=
do h_simp ← transform g,
unsafe_change $ expr.elet n h_simp e f
| _ := fail "reverting hypothesis created neither a pi nor an elet expr (unreachable?)"
end,
intron num_reverted
/-- `get_eqn_lemmas_for deps d` returns the automatically generated equational lemmas for definition d.
If deps is tt, then lemmas for automatically generated auxiliary declarations used to define d are also included. -/
meta constant get_eqn_lemmas_for : bool → name → tactic (list name)
structure dsimp_config :=
(md := reducible) -- reduction mode: how aggressively constants are replaced with their definitions.
(max_steps : nat := simp.default_max_steps) -- The maximum number of steps allowed before failing.
(canonize_instances : bool := tt) -- See the documentation in `src/library/defeq_canonizer.h`
(single_pass : bool := ff) -- Visit each subterm no more than once.
(fail_if_unchanged := tt) -- Don't throw if dsimp didn't do anything.
(eta := tt) -- allow eta-equivalence: `(λ x, F $ x) ↝ F`
(zeta : bool := tt) -- do zeta-reductions: `let x : a := b in c ↝ c[x/b]`.
(beta : bool := tt) -- do beta-reductions: `(λ x, E) $ (y) ↝ E[x/y]`.
(proj : bool := tt) -- reduce projections: `⟨a,b⟩.1 ↝ a`.
(iota : bool := tt) -- reduce recursors for inductive datatypes: eg `nat.rec_on (succ n) Z R ↝ R n $ nat.rec_on n Z R`
(unfold_reducible := ff) -- if tt, definitions with `reducible` transparency will be unfolded (delta-reduced)
(memoize := tt) -- Perform caching of dsimps of subterms.
end tactic
/-- (Definitional) Simplify the given expression using *only* reflexivity equality lemmas from the given set of lemmas.
The resulting expression is definitionally equal to the input.
The list `u` contains defintions to be delta-reduced, and projections to be reduced.-/
meta constant simp_lemmas.dsimplify (s : simp_lemmas) (u : list name := []) (e : expr) (cfg : tactic.dsimp_config := {}) : tactic expr
namespace tactic
/- Remark: the configuration parameters `cfg.md` and `cfg.eta` are ignored by this tactic. -/
meta constant dsimplify_core
/- The user state type. -/
{α : Type}
/- Initial user data -/
(a : α)
/- (pre a e) is invoked before visiting the children of subterm 'e',
if it succeeds the result (new_a, new_e, flag) where
- 'new_a' is the new value for the user data
- 'new_e' is a new expression that must be definitionally equal to 'e',
- 'flag' if tt 'new_e' children should be visited, and 'post' invoked. -/
(pre : α → expr → tactic (α × expr × bool))
/- (post a e) is invoked after visiting the children of subterm 'e',
The output is similar to (pre a e), but the 'flag' indicates whether
the new expression should be revisited or not. -/
(post : α → expr → tactic (α × expr × bool))
(e : expr)
(cfg : dsimp_config := {})
: tactic (α × expr)
meta def dsimplify
(pre : expr → tactic (expr × bool))
(post : expr → tactic (expr × bool))
: expr → tactic expr :=
λ e, do (a, new_e) ← dsimplify_core ()
(λ u e, do r ← pre e, return (u, r))
(λ u e, do r ← post e, return (u, r)) e,
return new_e
meta def get_simp_lemmas_or_default : option simp_lemmas → tactic simp_lemmas
| none := simp_lemmas.mk_default
| (some s) := return s
meta def dsimp_target (s : option simp_lemmas := none) (u : list name := []) (cfg : dsimp_config := {}) : tactic unit :=
do
s ← get_simp_lemmas_or_default s,
t ← target >>= instantiate_mvars,
s.dsimplify u t cfg >>= unsafe_change
meta def dsimp_hyp (h : expr) (s : option simp_lemmas := none) (u : list name := []) (cfg : dsimp_config := {}) : tactic unit :=
do s ← get_simp_lemmas_or_default s, revert_and_transform (λ e, s.dsimplify u e cfg) h
/- Remark: we use transparency.instances by default to make sure that we
can unfold projections of type classes. Example:
(@has_add.add nat nat.has_add a b)
-/
/-- Tries to unfold `e` if it is a constant or a constant application.
Remark: this is not a recursive procedure. -/
meta constant dunfold_head (e : expr) (md := transparency.instances) : tactic expr
structure dunfold_config extends dsimp_config :=
(md := transparency.instances)
/- Remark: in principle, dunfold can be implemented on top of dsimp. We don't do it for
performance reasons. -/
meta constant dunfold (cs : list name) (e : expr) (cfg : dunfold_config := {}) : tactic expr
meta def dunfold_target (cs : list name) (cfg : dunfold_config := {}) : tactic unit :=
do t ← target, dunfold cs t cfg >>= unsafe_change
meta def dunfold_hyp (cs : list name) (h : expr) (cfg : dunfold_config := {}) : tactic unit :=
revert_and_transform (λ e, dunfold cs e cfg) h
structure delta_config :=
(max_steps := simp.default_max_steps)
(visit_instances := tt)
private meta def is_delta_target (e : expr) (cs : list name) : bool :=
cs.any (λ c,
if e.is_app_of c then tt /- Exact match -/
else let f := e.get_app_fn in
/- f is an auxiliary constant generated when compiling c -/
f.is_constant && f.const_name.is_internal && (f.const_name.get_prefix = c))
/-- Delta reduce the given constant names -/
meta def delta (cs : list name) (e : expr) (cfg : delta_config := {}) : tactic expr :=
let unfold (u : unit) (e : expr) : tactic (unit × expr × bool) := do
guard (is_delta_target e cs),
(expr.const f_name f_lvls) ← return e.get_app_fn,
env ← get_env,
decl ← env.get f_name,
new_f ← decl.instantiate_value_univ_params f_lvls,
new_e ← head_beta (expr.mk_app new_f e.get_app_args),
return (u, new_e, tt)
in do (c, new_e) ← dsimplify_core () (λ c e, failed) unfold e {max_steps := cfg.max_steps, canonize_instances := cfg.visit_instances},
return new_e
meta def delta_target (cs : list name) (cfg : delta_config := {}) : tactic unit :=
do t ← target, delta cs t cfg >>= unsafe_change
meta def delta_hyp (cs : list name) (h : expr) (cfg : delta_config := {}) :tactic unit :=
revert_and_transform (λ e, delta cs e cfg) h
structure unfold_proj_config extends dsimp_config :=
(md := transparency.instances)
/-- If `e` is a projection application, try to unfold it, otherwise fail. -/
meta constant unfold_proj (e : expr) (md := transparency.instances) : tactic expr
meta def unfold_projs (e : expr) (cfg : unfold_proj_config := {}) : tactic expr :=
let unfold (changed : bool) (e : expr) : tactic (bool × expr × bool) := do
new_e ← unfold_proj e cfg.md,
return (tt, new_e, tt)
in do (tt, new_e) ← dsimplify_core ff (λ c e, failed) unfold e cfg.to_dsimp_config | fail "no projections to unfold",
return new_e
meta def unfold_projs_target (cfg : unfold_proj_config := {}) : tactic unit :=
do t ← target, unfold_projs t cfg >>= unsafe_change
meta def unfold_projs_hyp (h : expr) (cfg : unfold_proj_config := {}) : tactic unit :=
revert_and_transform (λ e, unfold_projs e cfg) h
structure simp_config :=
(max_steps : nat := simp.default_max_steps)
(contextual : bool := ff)
(lift_eq : bool := tt)
(canonize_instances : bool := tt)
(canonize_proofs : bool := ff)
(use_axioms : bool := tt)
(zeta : bool := tt)
(beta : bool := tt)
(eta : bool := tt)
(proj : bool := tt) -- reduce projections
(iota : bool := tt)
(iota_eqn : bool := ff) -- reduce using all equation lemmas generated by equation/pattern-matching compiler
(constructor_eq : bool := tt)
(single_pass : bool := ff)
(fail_if_unchanged := tt)
(memoize := tt)
/--
`simplify s e cfg r prove` simplify `e` using `s` using bottom-up traversal.
`discharger` is a tactic for dischaging new subgoals created by the simplifier.
If it fails, the simplifier tries to discharge the subgoal by simplifying it to `true`.
The parameter `to_unfold` specifies definitions that should be delta-reduced,
and projection applications that should be unfolded.
-/
meta constant simplify (s : simp_lemmas) (to_unfold : list name := []) (e : expr) (cfg : simp_config := {}) (r : name := `eq)
(discharger : tactic unit := failed) : tactic (expr × expr)
meta def simp_target (s : simp_lemmas) (to_unfold : list name := []) (cfg : simp_config := {}) (discharger : tactic unit := failed) : tactic unit :=
do t ← target >>= instantiate_mvars,
(new_t, pr) ← simplify s to_unfold t cfg `eq discharger,
replace_target new_t pr
meta def simp_hyp (s : simp_lemmas) (to_unfold : list name := []) (h : expr) (cfg : simp_config := {}) (discharger : tactic unit := failed) : tactic expr :=
do when (expr.is_local_constant h = ff) (fail "tactic simp_at failed, the given expression is not a hypothesis"),
htype ← infer_type h,
(h_new_type, pr) ← simplify s to_unfold htype cfg `eq discharger,
replace_hyp h h_new_type pr
/--
`ext_simplify_core a c s discharger pre post r e`:
- `a : α` - initial user data
- `c : simp_config` - simp configuration options
- `s : simp_lemmas` - the set of simp_lemmas to use. Remark: the simplification lemmas are not applied automatically like in the simplify tactic. The caller must use them at pre/post.
- `discharger : α → tactic α` - tactic for dischaging hypothesis in conditional rewriting rules. The argument 'α' is the current user data.
- `pre a s r p e` is invoked before visiting the children of subterm 'e'.
+ arguments:
- `a` is the current user data
- `s` is the updated set of lemmas if 'contextual' is `tt`,
- `r` is the simplification relation being used,
- `p` is the "parent" expression (if there is one).
- `e` is the current subexpression in question.
+ if it succeeds the result is `(new_a, new_e, new_pr, flag)` where
- `new_a` is the new value for the user data
- `new_e` is a new expression s.t. `r e new_e`
- `new_pr` is a proof for `e r new_e`, If it is none, the proof is assumed to be by reflexivity
- `flag` if tt `new_e` children should be visited, and `post` invoked.
- `(post a s r p e)` is invoked after visiting the children of subterm `e`,
The output is similar to `(pre a r s p e)`, but the 'flag' indicates whether the new expression should be revisited or not.
- `r` is the simplification relation. Usually `=` or `↔`.
- `e` is the input expression to be simplified.
The method returns `(a,e,pr)` where
- `a` is the final user data
- `e` is the new expression
- `pr` is the proof that the given expression equals the input expression.
-/
meta constant ext_simplify_core
{α : Type}
(a : α)
(c : simp_config)
(s : simp_lemmas)
(discharger : α → tactic α)
(pre : α → simp_lemmas → name → option expr → expr → tactic (α × expr × option expr × bool))
(post : α → simp_lemmas → name → option expr → expr → tactic (α × expr × option expr × bool))
(r : name) :
expr → tactic (α × expr × expr)
private meta def is_equation : expr → bool
| (expr.pi n bi d b) := is_equation b
| e := match (expr.is_eq e) with (some a) := tt | none := ff end
meta def collect_ctx_simps : tactic (list expr) :=
local_context
section simp_intros
meta def intro1_aux : bool → list name → tactic expr
| ff _ := intro1
| tt (n::ns) := intro n
| _ _ := failed
structure simp_intros_config extends simp_config :=
(use_hyps := ff)
meta def simp_intros_aux (cfg : simp_config) (use_hyps : bool) (to_unfold : list name) : simp_lemmas → bool → list name → tactic simp_lemmas
| S tt [] := try (simp_target S to_unfold cfg) >> return S
| S use_ns ns := do
t ← target,
if t.is_napp_of `not 1 then
intro1_aux use_ns ns >> simp_intros_aux S use_ns ns.tail
else if t.is_arrow then
do {
d ← return t.binding_domain,
(new_d, h_d_eq_new_d) ← simplify S to_unfold d cfg,
h_d ← intro1_aux use_ns ns,
h_new_d ← mk_eq_mp h_d_eq_new_d h_d,
assertv_core h_d.local_pp_name new_d h_new_d,
clear h_d,
h_new ← intro1,
new_S ← if use_hyps then mcond (is_prop new_d) (S.add h_new ff) (return S)
else return S,
simp_intros_aux new_S use_ns ns.tail
}
<|>
-- failed to simplify... we just introduce and continue
(intro1_aux use_ns ns >> simp_intros_aux S use_ns ns.tail)
else if t.is_pi || t.is_let then
intro1_aux use_ns ns >> simp_intros_aux S use_ns ns.tail
else do
new_t ← whnf t reducible,
if new_t.is_pi then unsafe_change new_t >> simp_intros_aux S use_ns ns
else
try (simp_target S to_unfold cfg) >>
mcond (expr.is_pi <$> target)
(simp_intros_aux S use_ns ns)
(if use_ns ∧ ¬ns.empty then failed else return S)
meta def simp_intros (s : simp_lemmas) (to_unfold : list name := []) (ids : list name := []) (cfg : simp_intros_config := {}) : tactic unit :=
step $ simp_intros_aux cfg.to_simp_config cfg.use_hyps to_unfold s (bnot ids.empty) ids
end simp_intros
meta def mk_eq_simp_ext (simp_ext : expr → tactic (expr × expr)) : tactic unit :=
do (lhs, rhs) ← target >>= match_eq,
(new_rhs, heq) ← simp_ext lhs,
unify rhs new_rhs,
exact heq
/- Simp attribute support -/
meta def to_simp_lemmas : simp_lemmas → list name → tactic simp_lemmas
| S [] := return S
| S (n::ns) := do S' ← S.add_simp n ff, to_simp_lemmas S' ns
meta def mk_simp_attr (attr_name : name) (attr_deps : list name := []) : command :=
do let t := `(user_attribute simp_lemmas),
let v := `({name := attr_name,
descr := "simplifier attribute",
cache_cfg := {
mk_cache := λ ns, do {
s ← tactic.to_simp_lemmas simp_lemmas.mk ns,
s ← attr_deps.mfoldl
(λ s attr_name, do
ns ← attribute.get_instances attr_name,
to_simp_lemmas s ns)
s,
return s },
dependencies := `reducibility :: attr_deps}} : user_attribute simp_lemmas),
let n := mk_simp_attr_decl_name attr_name,
add_decl (declaration.defn n [] t v reducibility_hints.abbrev ff),
attribute.register n
/--
### Example usage:
```lean
-- make a new simp attribute called "my_reduction"
run_cmd mk_simp_attr `my_reduction
-- Add "my_reduction" attributes to these if-reductions
attribute [my_reduction] if_pos if_neg dif_pos dif_neg
-- will return the simp_lemmas with the `my_reduction` attribute.
#eval get_user_simp_lemmas `my_reduction
```
-/
meta def get_user_simp_lemmas (attr_name : name) : tactic simp_lemmas :=
if attr_name = `default then simp_lemmas.mk_default
else get_attribute_cache_dyn (mk_simp_attr_decl_name attr_name)
meta def join_user_simp_lemmas_core : simp_lemmas → list name → tactic simp_lemmas
| S [] := return S
| S (attr_name::R) := do S' ← get_user_simp_lemmas attr_name, join_user_simp_lemmas_core (S.join S') R
meta def join_user_simp_lemmas (no_dflt : bool) (attrs : list name) : tactic simp_lemmas :=
if no_dflt then
join_user_simp_lemmas_core simp_lemmas.mk attrs
else do
s ← simp_lemmas.mk_default,
join_user_simp_lemmas_core s attrs
/-- Normalize numerical expression, returns a pair (n, pr) where n is the resultant numeral,
and pr is a proof that the input argument is equal to n. -/
meta constant norm_num : expr → tactic (expr × expr)
meta def simplify_top_down {α} (a : α) (pre : α → expr → tactic (α × expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) :=
ext_simplify_core a cfg simp_lemmas.mk (λ _, failed)
(λ a _ _ _ e, do (new_a, new_e, pr) ← pre a e, guard (¬ new_e =ₐ e), return (new_a, new_e, some pr, tt))
(λ _ _ _ _ _, failed)
`eq e
meta def simp_top_down (pre : expr → tactic (expr × expr)) (cfg : simp_config := {}) : tactic unit :=
do t ← target,
(_, new_target, pr) ← simplify_top_down () (λ _ e, do (new_e, pr) ← pre e, return ((), new_e, pr)) t cfg,
replace_target new_target pr
meta def simplify_bottom_up {α} (a : α) (post : α → expr → tactic (α × expr × expr)) (e : expr) (cfg : simp_config := {}) : tactic (α × expr × expr) :=
ext_simplify_core a cfg simp_lemmas.mk (λ _, failed)
(λ _ _ _ _ _, failed)
(λ a _ _ _ e, do (new_a, new_e, pr) ← post a e, guard (¬ new_e =ₐ e), return (new_a, new_e, some pr, tt))
`eq e
meta def simp_bottom_up (post : expr → tactic (expr × expr)) (cfg : simp_config := {}) : tactic unit :=
do t ← target,
(_, new_target, pr) ← simplify_bottom_up () (λ _ e, do (new_e, pr) ← post e, return ((), new_e, pr)) t cfg,
replace_target new_target pr
private meta def remove_deps (s : name_set) (h : expr) : name_set :=
if s.empty then s
else h.fold s (λ e o s, if e.is_local_constant then s.erase e.local_uniq_name else s)
/- Return the list of hypothesis that are propositions and do not have
forward dependencies. -/
meta def non_dep_prop_hyps : tactic (list expr) :=
do
ctx ← local_context,
s ← ctx.mfoldl (λ s h, do
h_type ← infer_type h,
let s := remove_deps s h_type,
h_val ← head_zeta h,
let s := if h_val =ₐ h then s else remove_deps s h_val,
mcond (is_prop h_type)
(return $ s.insert h.local_uniq_name)
(return s)) mk_name_set,
t ← target,
let s := remove_deps s t,
return $ ctx.filter (λ h, s.contains h.local_uniq_name)
section simp_all
meta structure simp_all_entry :=
(h : expr) -- hypothesis
(new_type : expr) -- new type
(pr : option expr) -- proof that type of h is equal to new_type
(s : simp_lemmas) -- simplification lemmas for simplifying new_type
private meta def update_simp_lemmas (es : list simp_all_entry) (h : expr) : tactic (list simp_all_entry) :=
es.mmap $ λ e, do new_s ← e.s.add h ff, return {s := new_s, ..e}
/- Helper tactic for `init`.
Remark: the following tactic is quadratic on the length of list expr (the list of non dependent propositions).
We can make it more efficient as soon as we have an efficient simp_lemmas.erase. -/
private meta def init_aux : list expr → simp_lemmas → list simp_all_entry → tactic (simp_lemmas × list simp_all_entry)
| [] s r := return (s, r)
| (h::hs) s r := do
new_r ← update_simp_lemmas r h,
new_s ← s.add h ff,
h_type ← infer_type h,
init_aux hs new_s (⟨h, h_type, none, s⟩::new_r)
private meta def init (s : simp_lemmas) (hs : list expr) : tactic (simp_lemmas × list simp_all_entry) :=
init_aux hs s []
private meta def add_new_hyps (es : list simp_all_entry) : tactic unit :=
es.mmap' $ λ e,
match e.pr with
| none := return ()
| some pr :=
assert e.h.local_pp_name e.new_type >>
mk_eq_mp pr e.h >>= exact
end
private meta def clear_old_hyps (es : list simp_all_entry) : tactic unit :=
es.mmap' $ λ e, when (e.pr ≠ none) (try (clear e.h))
private meta def join_pr : option expr → expr → tactic expr
| none pr₂ := return pr₂
| (some pr₁) pr₂ := mk_eq_trans pr₁ pr₂
private meta def loop (cfg : simp_config) (discharger : tactic unit) (to_unfold : list name)
: list simp_all_entry → list simp_all_entry → simp_lemmas → bool → tactic unit
| [] r s m :=
if m then loop r [] s ff
else do
add_new_hyps r,
target_changed ← (simp_target s to_unfold cfg discharger >> return tt) <|> return ff,
guard (cfg.fail_if_unchanged = ff ∨ target_changed ∨ r.any (λ e, e.pr ≠ none)) <|> fail "simp_all tactic failed to simplify",
clear_old_hyps r
| (e::es) r s m := do
let ⟨h, h_type, h_pr, s'⟩ := e,
(new_h_type, new_pr) ← simplify s' to_unfold h_type {fail_if_unchanged := ff, ..cfg} `eq discharger,
if h_type =ₐ new_h_type then loop es (e::r) s m
else do
new_pr ← join_pr h_pr new_pr,
new_fact_pr ← mk_eq_mp new_pr h,
if new_h_type = `(false) then do
tgt ← target,
to_expr ``(@false.rec %%tgt %%new_fact_pr) >>= exact
else do
h0_type ← infer_type h,
let new_fact_pr := mk_id_proof new_h_type new_fact_pr,
new_es ← update_simp_lemmas es new_fact_pr,
new_r ← update_simp_lemmas r new_fact_pr,
let new_r := {new_type := new_h_type, pr := new_pr, ..e} :: new_r,
new_s ← s.add new_fact_pr ff,
loop new_es new_r new_s tt
meta def simp_all (s : simp_lemmas) (to_unfold : list name) (cfg : simp_config := {}) (discharger : tactic unit := failed) : tactic unit :=
do hs ← non_dep_prop_hyps,
(s, es) ← init s hs,
loop cfg discharger to_unfold es [] s ff
end simp_all
/- debugging support for algebraic normalizer -/
meta constant trace_algebra_info : expr → tactic unit
end tactic
export tactic (mk_simp_attr)
run_cmd mk_simp_attr `norm [`simp]
|
ce02fdce603f42a6281a383a2d848031c0cf771f | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/run/cc_ac4.lean | d90f380bf3502dd76a02b91b43b11e23fe5ab2f0 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 503 | lean | --import data.set.basic
open tactic
constant union_is_assoc {α} : is_associative (set α) (∪)
constant union_is_comm {α} : is_commutative (set α) (∪)
attribute [instance] union_is_assoc union_is_comm
section
universe variable u
variables {α : Type u}
example (a b c d₁ d₂ e₁ e₂ : set α) (f : set α → set α → set α) : b ∪ a = d₁ ∪ d₂ → b ∪ c = e₂ ∪ e₁ → f (a ∪ b ∪ c) (a ∪ b ∪ c) = f (c ∪ d₂ ∪ d₁) (e₂ ∪ a ∪ e₁) :=
by cc
end
|
d64c435eeaef3e5e3217c14d1f6f48d469df3082 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/set_theory/game/domineering.lean | bf6c59e05a9c550355ef9a0bb9891a7daeca6da5 | [
"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 | 7,964 | 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 set_theory.game.state
/-!
# Domineering as a combinatorial game.
We define the game of Domineering, played on a chessboard of arbitrary shape
(possibly even disconnected).
Left moves by placing a domino vertically, while Right moves by placing a domino horizontally.
This is only a fragment of a full development;
in order to successfully analyse positions we would need some more theorems.
Most importantly, we need a general statement that allows us to discard irrelevant moves.
Specifically to domineering, we need the fact that
disjoint parts of the chessboard give sums of games.
-/
namespace pgame
namespace domineering
open function
/-- The embedding `(x, y) ↦ (x, y+1)`. -/
def shift_up : ℤ × ℤ ↪ ℤ × ℤ :=
(embedding.refl ℤ).prod_map ⟨λ n, n + 1, add_left_injective 1⟩
/-- The embedding `(x, y) ↦ (x+1, y)`. -/
def shift_right : ℤ × ℤ ↪ ℤ × ℤ :=
embedding.prod_map ⟨λ n, n + 1, add_left_injective 1⟩ (embedding.refl ℤ)
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
@[derive inhabited]
def board := finset (ℤ × ℤ)
local attribute [reducible] board
/-- Left can play anywhere that a square and the square below it are open. -/
def left (b : board) : finset (ℤ × ℤ) := b ∩ b.map shift_up
/-- Right can play anywhere that a square and the square to the left are open. -/
def right (b : board) : finset (ℤ × ℤ) := b ∩ b.map shift_right
/-- After Left moves, two vertically adjacent squares are removed from the board. -/
def move_left (b : board) (m : ℤ × ℤ) : board :=
(b.erase m).erase (m.1, m.2 - 1)
/-- After Left moves, two horizontally adjacent squares are removed from the board. -/
def move_right (b : board) (m : ℤ × ℤ) : board :=
(b.erase m).erase (m.1 - 1, m.2)
lemma card_of_mem_left {b : board} {m : ℤ × ℤ} (h : m ∈ left b) : 2 ≤ finset.card b :=
begin
dsimp [left] at h,
have w₁ : m ∈ b,
{ rw finset.mem_inter at h,
exact h.1 },
have w₂ : (m.1, m.2 - 1) ∈ b.erase m,
{ simp only [finset.mem_erase],
fsplit,
{ exact λ w, pred_ne_self m.2 (congr_arg prod.snd w) },
{ rw finset.mem_inter at h,
have h₂ := h.2, clear h,
rw finset.mem_map at h₂,
rcases h₂ with ⟨m', ⟨h₂, rfl⟩⟩,
dsimp [shift_up],
simpa, }, },
have i₁ := finset.card_erase_lt_of_mem w₁,
have i₂ := nat.lt_of_le_of_lt (nat.zero_le _) (finset.card_erase_lt_of_mem w₂),
exact nat.lt_of_le_of_lt i₂ i₁,
end
lemma card_of_mem_right {b : board} {m : ℤ × ℤ} (h : m ∈ right b) : 2 ≤ finset.card b :=
begin
dsimp [right] at h,
have w₁ : m ∈ b,
{ rw finset.mem_inter at h,
exact h.1 },
have w₂ : (m.1 - 1, m.2) ∈ b.erase m,
{ simp only [finset.mem_erase],
fsplit,
{ exact λ w, pred_ne_self m.1 (congr_arg prod.fst w) },
{ rw finset.mem_inter at h,
have h₂ := h.2, clear h,
rw finset.mem_map at h₂,
rcases h₂ with ⟨m', ⟨h₂, rfl⟩⟩,
dsimp [shift_right],
simpa, }, },
have i₁ := finset.card_erase_lt_of_mem w₁,
have i₂ := nat.lt_of_le_of_lt (nat.zero_le _) (finset.card_erase_lt_of_mem w₂),
exact nat.lt_of_le_of_lt i₂ i₁,
end
lemma move_left_card {b : board} {m : ℤ × ℤ} (h : m ∈ left b) :
finset.card (move_left b m) + 2 = finset.card b :=
begin
dsimp [move_left],
rw finset.card_erase_of_mem,
{ rw finset.card_erase_of_mem,
{ exact nat.sub_add_cancel (card_of_mem_left h), },
{ exact finset.mem_of_mem_inter_left h, } },
{ apply finset.mem_erase_of_ne_of_mem,
{ exact λ w, pred_ne_self m.2 (congr_arg prod.snd w), },
{ have t := finset.mem_of_mem_inter_right h,
dsimp [shift_up] at t,
simp only [finset.mem_map, prod.exists] at t,
rcases t with ⟨x,y,w,h⟩,
rw ←h,
convert w,
simp, } }
end
lemma move_right_card {b : board} {m : ℤ × ℤ} (h : m ∈ right b) :
finset.card (move_right b m) + 2 = finset.card b :=
begin
dsimp [move_right],
rw finset.card_erase_of_mem,
{ rw finset.card_erase_of_mem,
{ exact nat.sub_add_cancel (card_of_mem_right h), },
{ exact finset.mem_of_mem_inter_left h, } },
{ apply finset.mem_erase_of_ne_of_mem,
{ exact λ w, pred_ne_self m.1 (congr_arg prod.fst w), },
{ have t := finset.mem_of_mem_inter_right h,
dsimp [shift_right] at t,
simp only [finset.mem_map, prod.exists] at t,
rcases t with ⟨x,y,w,h⟩,
rw ←h,
convert w,
simp, } }
end
lemma move_left_smaller {b : board} {m : ℤ × ℤ} (h : m ∈ left b) :
finset.card (move_left b m) / 2 < finset.card b / 2 :=
by simp [←move_left_card h, lt_add_one]
lemma move_right_smaller {b : board} {m : ℤ × ℤ} (h : m ∈ right b) :
finset.card (move_right b m) / 2 < finset.card b / 2 :=
by simp [←move_right_card h, lt_add_one]
/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
L := λ s, (left s).image (move_left s),
R := λ s, (right s).image (move_right s),
left_bound := λ s t m,
begin
simp only [finset.mem_image, prod.exists] at m,
rcases m with ⟨_, _, ⟨h, rfl⟩⟩,
exact move_left_smaller h
end,
right_bound := λ s t m,
begin
simp only [finset.mem_image, prod.exists] at m,
rcases m with ⟨_, _, ⟨h, rfl⟩⟩,
exact move_right_smaller h
end, }
end domineering
/-- Construct a pre-game from a Domineering board. -/
def domineering (b : domineering.board) : pgame := pgame.of b
/-- All games of Domineering are short, because each move removes two squares. -/
instance short_domineering (b : domineering.board) : short (domineering b) :=
by { dsimp [domineering], apply_instance }
/-- The Domineering board with two squares arranged vertically, in which Left has the only move. -/
def domineering.one := domineering ([(0,0), (0,1)].to_finset)
/-- The `L` shaped Domineering board, in which Left is exactly half a move ahead. -/
def domineering.L := domineering ([(0,2), (0,1), (0,0), (1,0)].to_finset)
instance short_one : short domineering.one := by { dsimp [domineering.one], apply_instance }
instance short_L : short domineering.L := by { dsimp [domineering.L], apply_instance }
-- The VM can play small games successfully:
-- #eval to_bool (domineering.one ≈ 1)
-- #eval to_bool (domineering.L + domineering.L ≈ 1)
-- The following no longer works since Lean 3.29, since definitions by well-founded
-- recursion no longer reduce definitionally.
-- We can check that `decidable` instances reduce as expected,
-- and so our implementation of domineering is computable.
-- run_cmd tactic.whnf `(by apply_instance : decidable (domineering.one ≤ 1)) >>= tactic.trace
-- dec_trivial can handle most of the dictionary of small games described in [conway2001]
-- example : domineering.one ≈ 1 := dec_trivial
-- example : domineering.L + domineering.L ≈ 1 := dec_trivial
-- example : domineering.L ≈ pgame.of_lists [0] [1] := dec_trivial
-- example : (domineering ([(0,0), (0,1), (0,2), (0,3)].to_finset) ≈ 2) := dec_trivial
-- example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) :=
-- dec_trivial.
-- The 3x3 grid is doable, but takes a minute...
-- example :
-- (domineering ([(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)].to_finset) ≈
-- pgame.of_lists [1] [-1]) := dec_trivial
-- The 5x5 grid is actually 0, but brute-forcing this is too challenging even for the VM.
-- #eval to_bool (domineering ([
-- (0,0), (0,1), (0,2), (0,3), (0,4),
-- (1,0), (1,1), (1,2), (1,3), (1,4),
-- (2,0), (2,1), (2,2), (2,3), (2,4),
-- (3,0), (3,1), (3,2), (3,3), (3,4),
-- (4,0), (4,1), (4,2), (4,3), (4,4)
-- ].to_finset) ≈ 0)
end pgame
|
233c8e35a1211bca6bd3d4f2940aad0ce2d1565b | 1e561612e7479c100cd9302e3fe08cbd2914aa25 | /mathlib4_experiments/Tactic/Exfalso.lean | bd1cdfdbae4c49469533fc2d03875f9563ccecee | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib4_experiments | 8de8ed7193f70748a7529e05d831203a7c64eedb | 87cb879b4d602c8ecfd9283b7c0b06015abdbab1 | refs/heads/master | 1,687,971,389,316 | 1,620,336,942,000 | 1,620,336,942,000 | 353,994,588 | 7 | 4 | Apache-2.0 | 1,622,410,748,000 | 1,617,361,732,000 | Lean | UTF-8 | Lean | false | false | 189 | lean | /-
## `exfalso`
-/
syntax "exfalso" : tactic
macro_rules
| `(tactic| exfalso) => `(tactic| apply False.elim)
/-
example : False -> p := by
intro h;
exfalso;
skip;
exact h;
-/ |
c8b45d10afb586020b73645badfd0e2a6f8c3449 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/combinatorics/colex.lean | 0441534ef83ca50b7d22db1b3674d8b4871e2ef5 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 15,018 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Alena Gusakov
-/
import data.fintype.basic
import algebra.geom_sum
/-!
# Colex
We define the colex ordering for finite sets, and give a couple of important
lemmas and properties relating to it.
The colex ordering likes to avoid large values - it can be thought of on
`finset ℕ` as the "binary" ordering. That is, order A based on
`∑_{i ∈ A} 2^i`.
It's defined here in a slightly more general way, requiring only `has_lt α` in
the definition of colex on `finset α`. In the context of the Kruskal-Katona
theorem, we are interested in particular on how colex behaves for sets of a
fixed size. If the size is 3, colex on ℕ starts
123, 124, 134, 234, 125, 135, 235, 145, 245, 345, ...
## Main statements
* `colex.hom_lt_iff`: strictly monotone functions preserve colex
* Colex order properties - linearity, decidability and so on.
* `forall_lt_of_colex_lt_of_forall_lt`: if A < B in colex, and everything
in B is < t, then everything in A is < t. This confirms the idea that
an enumeration under colex will exhaust all sets using elements < t before
allowing t to be included.
* `sum_two_pow_le_iff_lt`: colex for α = ℕ is the same as binary
(this also proves binary expansions are unique)
## See also
Related files are:
* `data.list.lex`: Lexicographic order on lists.
* `data.pi.lex`: Lexicographic order on `Πₗ i, α i`.
* `data.psigma.order`: Lexicographic order on `Σ' i, α i`.
* `data.sigma.order`: Lexicographic order on `Σ i, α i`.
* `data.prod.lex`: Lexicographic order on `α × β`.
## Tags
colex, colexicographic, binary
## References
* https://github.com/b-mehta/maths-notes/blob/master/iii/mich/combinatorics.pdf
-/
variable {α : Type*}
open finset
open_locale big_operators
/--
We define this type synonym to refer to the colexicographic ordering on finsets
rather than the natural subset ordering.
-/
@[derive inhabited]
def finset.colex (α) := finset α
/--
A convenience constructor to turn a `finset α` into a `finset.colex α`, useful in order to
use the colex ordering rather than the subset ordering.
-/
def finset.to_colex {α} (s : finset α) : finset.colex α := s
@[simp]
lemma colex.eq_iff (A B : finset α) :
A.to_colex = B.to_colex ↔ A = B := iff.rfl
/--
`A` is less than `B` in the colex ordering if the largest thing that's not in both sets is in B.
In other words, `max (A ∆ B) ∈ B` (if the maximum exists).
-/
instance [has_lt α] : has_lt (finset.colex α) :=
⟨λ (A B : finset α), ∃ (k : α), (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B⟩
/-- We can define (≤) in the obvious way. -/
instance [has_lt α] : has_le (finset.colex α) :=
⟨λ A B, A < B ∨ A = B⟩
lemma colex.lt_def [has_lt α] (A B : finset α) :
A.to_colex < B.to_colex ↔ ∃ k, (∀ {x}, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A ∧ k ∈ B :=
iff.rfl
lemma colex.le_def [has_lt α] (A B : finset α) :
A.to_colex ≤ B.to_colex ↔ A.to_colex < B.to_colex ∨ A = B :=
iff.rfl
/-- If everything in `A` is less than `k`, we can bound the sum of powers. -/
lemma nat.sum_two_pow_lt {k : ℕ} {A : finset ℕ} (h₁ : ∀ {x}, x ∈ A → x < k) :
A.sum (pow 2) < 2^k :=
begin
apply lt_of_le_of_lt (sum_le_sum_of_subset (λ t, mem_range.2 ∘ h₁)),
have z := geom_sum_mul_add 1 k,
rw [mul_one, one_add_one_eq_two] at z,
rw ← z,
apply nat.lt_succ_self,
end
namespace colex
/-- Strictly monotone functions preserve the colex ordering. -/
lemma hom_lt_iff {β : Type*} [linear_order α] [decidable_eq β] [preorder β]
{f : α → β} (h₁ : strict_mono f) (A B : finset α) :
(A.image f).to_colex < (B.image f).to_colex ↔ A.to_colex < B.to_colex :=
begin
simp only [colex.lt_def, not_exists, mem_image, exists_prop, not_and],
split,
{ rintro ⟨k, z, q, k', _, rfl⟩,
exact ⟨k', λ x hx, by simpa [h₁.injective.eq_iff] using z (h₁ hx), λ t, q _ t rfl, ‹k' ∈ B›⟩ },
rintro ⟨k, z, ka, _⟩,
refine ⟨f k, λ x hx, _, _, k, ‹k ∈ B›, rfl⟩,
{ split,
any_goals
{ rintro ⟨x', hx', rfl⟩,
refine ⟨x', _, rfl⟩,
rwa ← z _ <|> rwa z _,
rwa strict_mono.lt_iff_lt h₁ at hx } },
{ simp only [h₁.injective, function.injective.eq_iff],
exact λ x hx, ne_of_mem_of_not_mem hx ka }
end
/-- A special case of `colex.hom_lt_iff` which is sometimes useful. -/
@[simp] lemma hom_fin_lt_iff {n : ℕ} (A B : finset (fin n)) :
(A.image (λ i : fin n, (i : ℕ))).to_colex < (B.image (λ i : fin n, (i : ℕ))).to_colex
↔ A.to_colex < B.to_colex :=
colex.hom_lt_iff (λ x y k, k) _ _
instance [has_lt α] : is_irrefl (finset.colex α) (<) :=
⟨λ A h, exists.elim h (λ _ ⟨_,a,b⟩, a b)⟩
@[trans]
lemma lt_trans [linear_order α] {a b c : finset.colex α} : a < b → b < c → a < c :=
begin
rintros ⟨k₁, k₁z, notinA, inB⟩ ⟨k₂, k₂z, notinB, inC⟩,
cases lt_or_gt_of_ne (ne_of_mem_of_not_mem inB notinB),
{ refine ⟨k₂, λ x hx, _, by rwa k₁z h, inC⟩,
rw ← k₂z hx,
apply k₁z (trans h hx) },
{ refine ⟨k₁, λ x hx, _, notinA, by rwa ← k₂z h⟩,
rw k₁z hx,
apply k₂z (trans h hx) }
end
@[trans]
lemma le_trans [linear_order α] (a b c : finset.colex α) : a ≤ b → b ≤ c → a ≤ c :=
λ AB BC, AB.elim (λ k, BC.elim (λ t, or.inl (lt_trans k t)) (λ t, t ▸ AB)) (λ k, k.symm ▸ BC)
instance [linear_order α] : is_trans (finset.colex α) (<) := ⟨λ _ _ _, colex.lt_trans⟩
lemma lt_trichotomy [linear_order α] (A B : finset.colex α) :
A < B ∨ A = B ∨ B < A :=
begin
by_cases h₁ : (A = B),
{ tauto },
rcases (exists_max_image (A \ B ∪ B \ A) id _) with ⟨k, hk, z⟩,
{ simp only [mem_union, mem_sdiff] at hk,
cases hk,
{ right,
right,
refine ⟨k, λ t th, _, hk.2, hk.1⟩,
specialize z t,
by_contra h₂,
simp only [mem_union, mem_sdiff, id.def] at z,
rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm] at h₂,
apply not_le_of_lt th (z h₂) },
{ left,
refine ⟨k, λ t th, _, hk.2, hk.1⟩,
specialize z t,
by_contra h₃,
simp only [mem_union, mem_sdiff, id.def] at z,
rw [not_iff, iff_iff_and_or_not_and_not, not_not, and_comm, or_comm] at h₃,
apply not_le_of_lt th (z h₃) }, },
rw nonempty_iff_ne_empty,
intro a,
simp only [union_eq_empty_iff, sdiff_eq_empty_iff_subset] at a,
apply h₁ (subset.antisymm a.1 a.2)
end
instance [linear_order α] : is_trichotomous (finset.colex α) (<) := ⟨lt_trichotomy⟩
instance decidable_lt [linear_order α] : ∀ {A B : finset.colex α}, decidable (A < B) :=
show ∀ A B : finset α, decidable (A.to_colex < B.to_colex),
from λ A B, decidable_of_iff'
(∃ (k ∈ B), (∀ x ∈ A ∪ B, k < x → (x ∈ A ↔ x ∈ B)) ∧ k ∉ A)
begin
rw colex.lt_def,
apply exists_congr,
simp only [mem_union, exists_prop, or_imp_distrib, and_comm (_ ∈ B), and_assoc],
intro k,
refine and_congr_left' (forall_congr _),
tauto,
end
instance [linear_order α] : linear_order (finset.colex α) :=
{ le_refl := λ A, or.inr rfl,
le_trans := le_trans,
le_antisymm := λ A B AB BA, AB.elim (λ k, BA.elim (λ t, (asymm k t).elim) (λ t, t.symm)) id,
le_total := λ A B,
(lt_trichotomy A B).elim3 (or.inl ∘ or.inl) (or.inl ∘ or.inr) (or.inr ∘ or.inl),
decidable_le := λ A B, by apply_instance,
decidable_lt := λ A B, by apply_instance,
decidable_eq := λ A B, by apply_instance,
lt_iff_le_not_le := λ A B,
begin
split,
{ intro t,
refine ⟨or.inl t, _⟩,
rintro (i | rfl),
{ apply asymm_of _ t i },
{ apply irrefl _ t } },
rintro ⟨h₁ | rfl, h₂⟩,
{ apply h₁ },
apply h₂.elim (or.inr rfl),
end,
..finset.colex.has_lt,
..finset.colex.has_le }
/-- The instances set up let us infer that `colex.lt` is a strict total order. -/
example [linear_order α] : is_strict_total_order (finset.colex α) (<) := infer_instance
/-- Strictly monotone functions preserve the colex ordering. -/
lemma hom_le_iff {β : Type*} [linear_order α] [linear_order β]
{f : α → β} (h₁ : strict_mono f) (A B : finset α) :
(A.image f).to_colex ≤ (B.image f).to_colex ↔ A.to_colex ≤ B.to_colex :=
by rw [le_iff_le_iff_lt_iff_lt, hom_lt_iff h₁]
/-- A special case of `colex_hom` which is sometimes useful. -/
@[simp] lemma hom_fin_le_iff {n : ℕ} (A B : finset (fin n)) :
(A.image (λ i : fin n, (i : ℕ))).to_colex ≤ (B.image (λ i : fin n, (i : ℕ))).to_colex
↔ A.to_colex ≤ B.to_colex :=
colex.hom_le_iff (λ x y k, k) _ _
/--
If `A` is before `B` in colex, and everything in `B` is small, then everything in `A` is small.
-/
lemma forall_lt_of_colex_lt_of_forall_lt [linear_order α] {A B : finset α}
(t : α) (h₁ : A.to_colex < B.to_colex) (h₂ : ∀ x ∈ B, x < t) :
∀ x ∈ A, x < t :=
begin
rw colex.lt_def at h₁,
rcases h₁ with ⟨k, z, _, _⟩,
intros x hx,
apply lt_of_not_ge,
intro a,
refine not_lt_of_ge a (h₂ x _),
rwa ← z,
apply lt_of_lt_of_le (h₂ k ‹_›) a,
end
/-- `s.to_colex < {r}.to_colex` iff all elements of `s` are less than `r`. -/
lemma lt_singleton_iff_mem_lt [linear_order α] {r : α} {s : finset α} :
s.to_colex < ({r} : finset α).to_colex ↔ ∀ x ∈ s, x < r :=
begin
simp only [lt_def, mem_singleton, ←and_assoc, exists_eq_right],
split,
{ intros t x hx,
rw ←not_le,
intro h,
rcases lt_or_eq_of_le h with h₁ | rfl,
{ exact ne_of_irrefl h₁ ((t.1 h₁).1 hx).symm },
{ exact t.2 hx } },
{ exact λ h, ⟨λ z hz, ⟨λ i, (asymm hz (h _ i)).elim, λ i, (hz.ne' i).elim⟩, by simpa using h r⟩ }
end
/-- If {r} is less than or equal to s in the colexicographical sense,
then s contains an element greater than or equal to r. -/
lemma mem_le_of_singleton_le [linear_order α] {r : α} {s : finset α}:
({r} : finset α).to_colex ≤ s.to_colex ↔ ∃ x ∈ s, r ≤ x :=
by { rw ←not_lt, simp [lt_singleton_iff_mem_lt] }
/-- Colex is an extension of the base ordering on α. -/
lemma singleton_lt_iff_lt [linear_order α] {r s : α} :
({r} : finset α).to_colex < ({s} : finset α).to_colex ↔ r < s :=
by simp [lt_singleton_iff_mem_lt]
/-- Colex is an extension of the base ordering on α. -/
lemma singleton_le_iff_le [linear_order α] {r s : α} :
({r} : finset α).to_colex ≤ ({s} : finset α).to_colex ↔ r ≤ s :=
by rw [le_iff_le_iff_lt_iff_lt, singleton_lt_iff_lt]
/-- Colex doesn't care if you remove the other set -/
@[simp] lemma sdiff_lt_sdiff_iff_lt [has_lt α] [decidable_eq α] (A B : finset α) :
(A \ B).to_colex < (B \ A).to_colex ↔ A.to_colex < B.to_colex :=
begin
rw [colex.lt_def, colex.lt_def],
apply exists_congr,
intro k,
simp only [mem_sdiff, not_and, not_not],
split,
{ rintro ⟨z, kAB, kB, kA⟩,
refine ⟨_, kA, kB⟩,
{ intros x hx,
specialize z hx,
tauto } },
{ rintro ⟨z, kA, kB⟩,
refine ⟨_, λ _, kB, kB, kA⟩,
intros x hx,
rw z hx },
end
/-- Colex doesn't care if you remove the other set -/
@[simp] lemma sdiff_le_sdiff_iff_le [linear_order α] (A B : finset α) :
(A \ B).to_colex ≤ (B \ A).to_colex ↔ A.to_colex ≤ B.to_colex :=
by rw [le_iff_le_iff_lt_iff_lt, sdiff_lt_sdiff_iff_lt]
lemma empty_to_colex_lt [linear_order α] {A : finset α} (hA : A.nonempty) :
(∅ : finset α).to_colex < A.to_colex :=
begin
rw [colex.lt_def],
refine ⟨max' _ hA, _, by simp, max'_mem _ _⟩,
simp only [false_iff, not_mem_empty],
intros x hx t,
apply not_le_of_lt hx (le_max' _ _ t),
end
/-- If `A ⊂ B`, then `A` is less than `B` in the colex order. Note the converse does not hold, as
`⊆` is not a linear order. -/
lemma colex_lt_of_ssubset [linear_order α] {A B : finset α} (h : A ⊂ B) :
A.to_colex < B.to_colex :=
begin
rw [←sdiff_lt_sdiff_iff_lt, sdiff_eq_empty_iff_subset.2 h.1],
exact empty_to_colex_lt (by simpa [finset.nonempty] using exists_of_ssubset h),
end
@[simp] lemma empty_to_colex_le [linear_order α] {A : finset α} :
(∅ : finset α).to_colex ≤ A.to_colex :=
begin
rcases A.eq_empty_or_nonempty with rfl | hA,
{ simp },
{ apply (empty_to_colex_lt hA).le },
end
/-- If `A ⊆ B`, then `A ≤ B` in the colex order. Note the converse does not hold, as `⊆` is not a
linear order. -/
lemma colex_le_of_subset [linear_order α] {A B : finset α} (h : A ⊆ B) :
A.to_colex ≤ B.to_colex :=
begin
rw [←sdiff_le_sdiff_iff_le, sdiff_eq_empty_iff_subset.2 h],
apply empty_to_colex_le
end
/-- The function from finsets to finsets with the colex order is a relation homomorphism. -/
@[simps]
def to_colex_rel_hom [linear_order α] :
((⊆) : finset α → finset α → Prop) →r ((≤) : finset.colex α → finset.colex α → Prop) :=
{ to_fun := finset.to_colex,
map_rel' := λ A B, colex_le_of_subset }
instance [linear_order α] : order_bot (finset.colex α) :=
{ bot := (∅ : finset α).to_colex,
bot_le := λ x, empty_to_colex_le }
instance [linear_order α] [fintype α] : order_top (finset.colex α) :=
{ top := finset.univ.to_colex,
le_top := λ x, colex_le_of_subset (subset_univ _) }
instance [linear_order α] : lattice (finset.colex α) :=
{ ..(by apply_instance : semilattice_sup (finset.colex α)),
..(by apply_instance : semilattice_inf (finset.colex α)) }
instance [linear_order α] [fintype α] : bounded_order (finset.colex α) :=
{ ..(by apply_instance : order_top (finset.colex α)),
..(by apply_instance : order_bot (finset.colex α)) }
/-- For subsets of ℕ, we can show that colex is equivalent to binary. -/
lemma sum_two_pow_lt_iff_lt (A B : finset ℕ) :
∑ i in A, 2^i < ∑ i in B, 2^i ↔ A.to_colex < B.to_colex :=
begin
have z : ∀ (A B : finset ℕ), A.to_colex < B.to_colex → ∑ i in A, 2^i < ∑ i in B, 2^i,
{ intros A B,
rw [← sdiff_lt_sdiff_iff_lt, colex.lt_def],
rintro ⟨k, z, kA, kB⟩,
rw ← sdiff_union_inter A B,
conv_rhs { rw ← sdiff_union_inter B A },
rw [sum_union (disjoint_sdiff_inter _ _), sum_union (disjoint_sdiff_inter _ _),
inter_comm, add_lt_add_iff_right],
apply lt_of_lt_of_le (@nat.sum_two_pow_lt k (A \ B) _),
{ apply single_le_sum (λ _ _, nat.zero_le _) kB },
intros x hx,
apply lt_of_le_of_ne (le_of_not_lt (λ kx, _)),
{ apply (ne_of_mem_of_not_mem hx kA) },
have := (z kx).1 hx,
rw mem_sdiff at this hx,
exact hx.2 this.1 },
refine ⟨λ h, (lt_trichotomy A B).resolve_right (λ h₁, h₁.elim _ (not_lt_of_gt h ∘ z _ _)), z A B⟩,
rintro rfl,
apply irrefl _ h
end
/-- For subsets of ℕ, we can show that colex is equivalent to binary. -/
lemma sum_two_pow_le_iff_lt (A B : finset ℕ) :
∑ i in A, 2^i ≤ ∑ i in B, 2^i ↔ A.to_colex ≤ B.to_colex :=
by rw [le_iff_le_iff_lt_iff_lt, sum_two_pow_lt_iff_lt]
end colex
|
95b2a8ebbf555097cb0af5923f72681dc871fb17 | 5a6ff5f8d173cbfe51967eb4c96837e3a791fe3d | /mm0-lean/mm0/set/basic.lean | 936cd9183efa6246368ed826d026e5f3d141dcce | [
"CC0-1.0"
] | permissive | digama0/mm0 | 491ac09146708aa1bb775007bf3dbe339ffc0096 | 98496badaf6464e56ed7b4204e7d54b85667cb01 | refs/heads/master | 1,692,321,030,902 | 1,686,254,458,000 | 1,686,254,458,000 | 172,456,790 | 273 | 38 | CC0-1.0 | 1,689,939,563,000 | 1,551,080,059,000 | Rust | UTF-8 | Lean | false | false | 124,962 | lean | /-#
This file is not autogenerated, but it is meant as a prelude for the
autogenerated set.mm import. To use this file, you should run mm0-hs on set.mm
to generate the MM0 files out.mm0 and out.mmu, and then feed these back into
mm0-hs to generate files setN.lean in this directory.
* The `-a .basic` says that all axioms should be commented out and this
file should be referenced to find the definitions. (This will cause errors in
the resulting lean file because this file doesn't yet have every axiom and
definition in set.mm.)
* The `-c 2000` says to chunk up the output lean file
every 2000 statements; this helps keep lean performant and allows for
incremental builds. (You may want to adjust this value smaller, 2000 statements
means the files are around 30000 lines which is quite high by lean standards.)
The following commands were used to generate a set.mm export compatible with
this prologue and the epilogue in post.lean:
```
stack exec -- mm0-hs from-mm set.mm -f dirith,elnnne0 -o out.mm0 out.mmu
stack exec -- mm0-hs to-lean out.mm0 out.mmu -a .basic -c 2000 -o mm0-lean/mm0/set/set.lean
```
-/
import .zfc_extra
namespace mm0
def wff : Type := Prop
@[simp] def wff.proof : wff → Prop := id
@[simp] def wff.forget {p : Prop} (h : wff → p) : p := h true
prefix `⊦ `:26 := wff.proof
@[simp] def wi : wff → wff → wff := (→)
@[simp] def wn : wff → wff := not
theorem ax_1 {ph ps : wff} : ph → ps → ph := λ h _, h
theorem ax_2 {ph ps ch : wff} :
(ph → ps → ch) → (ph → ps) → ph → ch := λ h1 h2 h3, h1 h3 (h2 h3)
theorem ax_3 {ph ps : wff} : (¬ ph → ¬ ps) → ps → ph :=
λ h1 h2, classical.by_contradiction $ λ h3, h1 h3 h2
theorem ax_mp {ph ps : wff} : ph → (ph → ps) → ps := λ h1 h2, h2 h1
@[simp] def wb : wff → wff → wff := iff
theorem df_an {ph ps : wff} : ph ∧ ps ↔ ¬ (ph → ¬ ps) :=
⟨λ ⟨h1, h2⟩ h3, h3 h1 h2, λ h1, classical.by_contradiction $
λ h2, h1 $ λ h3 h4, h2 ⟨h3, h4⟩⟩
theorem df_bi.aux {ph ps : Prop} : (ph ↔ ps) ↔ ¬((ph → ps) → ¬(ps → ph)) :=
iff_def.trans df_an
theorem df_bi {ph ps : wff} :
¬(((ph ↔ ps) → ¬((ph → ps) → ¬(ps → ph))) →
¬(¬((ph → ps) → ¬(ps → ph)) → (ph ↔ ps))) :=
df_bi.aux.1 df_bi.aux
@[simp] def wo : wff → wff → wff := or
theorem df_or {ph ps : wff} : ph ∨ ps ↔ (¬ ph → ps) :=
classical.or_iff_not_imp_left
@[simp] def wa : wff → wff → wff := and
@[simp] def w3o (p q r : wff) : wff := p ∨ q ∨ r
@[simp] def w3a (p q r : wff) : wff := p ∧ q ∧ r
theorem df_3or {ph ps ch : Prop} : ph ∨ ps ∨ ch ↔ (ph ∨ ps) ∨ ch :=
or.assoc.symm
theorem df_3an {a b c : Prop} : a ∧ b ∧ c ↔ (a ∧ b) ∧ c :=
and.assoc.symm
def wnan (ph ps : wff) : wff := ¬ (ph ∧ ps)
theorem df_nan {ph ps : wff} : wb (wnan ph ps) (wn (wa ph ps)) :=
iff.rfl
@[simp] def wxo : wff → wff → wff := xor
theorem df_xor {ph ps : wff} : xor ph ps ↔ ¬ (ph ↔ ps) :=
⟨λ h1 h2, or.cases_on h1 (λ ⟨h3, h4⟩, h4 (h2.1 h3)) (λ ⟨h3, h4⟩, h4 (h2.2 h3)),
λ h1, classical.by_contradiction $ λ h2, h1
⟨λ h, classical.by_contradiction $ λ hn, h2 (or.inl ⟨h, hn⟩),
λ h, classical.by_contradiction $ λ hn, h2 (or.inr ⟨h, hn⟩)⟩⟩
@[simp] def wtru := true
@[simp] def wfal := false
theorem df_tru {ph : wff} : wb wtru (wb ph ph) :=
(iff_true_intro iff.rfl).symm
theorem df_fal : wb wfal (wn wtru) := not_true_iff.symm
def whad (ph ps ch : wff) : wff := wxo (wxo ph ps) ch
def wcad (ph ps ch : wff) : wff := wo (wa ph ps) (wa ch (wxo ph ps))
theorem df_had {ph ps ch : wff} : wb (whad ph ps ch) (wxo (wxo ph ps) ch) := iff.rfl
theorem df_cad {ph ps ch : wff} : wb (wcad ph ps ch) (wo (wa ph ps) (wa ch (wxo ph ps))) := iff.rfl
theorem ax_meredith {ph ps ch th ta : wff}
(h1 : (((ph → ps) → ¬ ch → ¬ th) → ch) → ta)
(h2 : ta → ph) (h3 : th) : ph :=
classical.by_contradiction $ λ hn, hn $ h2 $ h1 $ λ h,
classical.by_contradiction $ λ hc, h (not.elim hn) hc h3
@[reducible] def setvar : Type 1 := Set
def setvar.forget {p : Prop} (h : setvar → p) : p := h (∅ : Set)
@[simp] def wal (P : setvar → wff) : wff := ∀ x, P x
@[simp] def wex : (setvar → wff) → wff := Exists
theorem df_ex {ph : setvar → wff} : (∃ x, ph x) ↔ ¬ ∀ x, ¬ ph x :=
by classical; exact not_forall_not.symm
def wnf (ph : setvar → wff) : wff := ∀ x, ph x → ∀ y, ph y
theorem df_nf {ph : setvar → wff} : wnf ph ↔ ∀ x, ph x → ∀ y, ph y := iff.rfl
theorem ax_gen {ph : setvar → wff} (h : ∀ x, ph x) : ∀ x, ph x := h
theorem ax_4 {ph ps : setvar → wff} (h : ∀ x, ph x → ps x)
(h2 : ∀ x, ph x) (x) : ps x := h x (h2 x)
theorem ax_5 {ph : wff} (h : ph) (x : setvar) : ph := h
@[reducible] def «class» : Type 1 := Class
@[simp] def «class».forget {p : Prop} (h : «class» → p) : p := h ∅
@[simp] def cv : setvar → «class» := coe
@[simp] def wceq : «class» → «class» → wff := eq
local notation x ` ≡ ` y := eq (↑x : «class») ↑y
@[simp] theorem weq' {x y : setvar} : x ≡ y ↔ x = y := ⟨Class.of_Set.inj, congr_arg _⟩
@[simp] def wsb (ph : setvar → wff) : setvar → wff := ph
theorem df_sb {ph : setvar → wff} {y : setvar} (x : setvar) :
ph y ↔ (x ≡ y → ph x) ∧ ∃ x : setvar, x ≡ y ∧ ph x :=
⟨λ h, ⟨λ e, weq'.1 e.symm ▸ h, _, rfl, h⟩, λ ⟨_, x, e, h⟩, weq'.1 e ▸ h⟩
theorem df_sb_b {ph : setvar → wff} (x : setvar) :
ph x ↔ (x ≡ x → ph x) ∧ ∃ x : setvar, x ≡ x ∧ ph x :=
⟨λ h, ⟨λ _, h, _, rfl, h⟩, λ ⟨h, _⟩, h rfl⟩
theorem ax_6 {y : setvar} : ¬ ∀ x:setvar, ¬ x ≡ y :=
df_ex.1 ⟨_, rfl⟩
theorem ax_7 {x y z : setvar} : x ≡ y → x ≡ z → y ≡ z :=
λ h1 h2, h1.symm.trans h2
theorem ax_7_b {x : setvar} : x ≡ x → x ≡ x → x ≡ x := ax_7
theorem ax_7_b1 {x z : setvar} : x ≡ x → x ≡ z → x ≡ z := ax_7
theorem ax_7_b2 {x y : setvar} : x ≡ y → x ≡ x → y ≡ x := ax_7
theorem ax_7_b3 {x y : setvar} : x ≡ y → x ≡ y → y ≡ y := ax_7
@[simp] def wcel : «class» → «class» → wff := (∈)
local infix ` ∈' `:50 := (∈)
local notation x ` ∈ ` y := (x : «class») ∈ (y : «class»)
theorem ax_8 {x y z : setvar} (h : x ≡ y) (h' : x ∈ z) : y ∈ z := h ▸ h'
theorem ax_8_b {x y : setvar} : x ≡ y → x ∈ x → y ∈ x := ax_8
theorem ax_8_b1 {x y : setvar} : x ≡ y → x ∈ y → y ∈ y := ax_8
theorem ax_9 {x y z : setvar} (h : x ≡ y) (h' : z ∈ x) : z ∈ y := h ▸ h'
theorem ax_9_b {x y : setvar} : x ≡ y → x ∈ x → x ∈ y := ax_9
theorem ax_9_b1 {x y : setvar} : x ≡ y → y ∈ x → y ∈ y := ax_9
theorem ax_10 {ph : setvar → wff} (h : ¬ ∀ x, ph x) (x:setvar) : ¬ ∀ x, ph x := h
theorem ax_11 {ph : setvar → setvar → wff} (h : ∀ x y, ph x y) (y x) : ph x y := h x y
theorem ax_11_b {ph : setvar → wff} (h : ∀ x x : setvar, ph x) : ∀ x x : setvar, ph x := h
theorem ax_12 {ph : setvar → setvar → wff} (x y) (h : x ≡ y) (h2 : ∀ y, ph x y) (x') (h3 : x' ≡ y) : ph x' y :=
weq'.1 (h.trans h3.symm) ▸ h2 y
theorem ax_12_b {ph : setvar → wff} (x : setvar) (h : x ≡ x) (h2 : ∀ x, ph x) (x') (h3 : x' ≡ x') : ph x' := h2 x'
theorem ax_13 {y z : setvar} (x:setvar) (_ : ¬ x ≡ y) (h : y ≡ z) (x':setvar) : y ≡ z := h
theorem ax_13_b {z : setvar} (x:setvar) (h : ¬ x ≡ x) (_ : x ≡ z) (x':setvar) : x' ≡ z := h.elim rfl
theorem ax_c5 {ph : setvar → wff} (x : setvar) (h : ∀ x, ph x) : ph x := h x
theorem ax_c4 {ph ps : setvar → wff} (H : ∀ x, (∀ x, ph x) → ps x) (h : ∀ x, ph x) (x: setvar) : ps x := H x h
theorem ax_c7 {ph : setvar → wff} (x: setvar) (H : ¬ ∀ x':setvar, ¬ ∀ x, ph x) : ph x :=
let ⟨_, h⟩ := df_ex.2 H in h x
theorem ax_c10 {ph : setvar → wff} {y : setvar} (x : setvar)
(H : ∀ x:setvar, x ≡ y → ∀ x, ph x) : ph x := H _ rfl _
theorem ax_c10_b {ph : setvar → wff} (x : setvar)
(H : ∀ x:setvar, x ≡ x → ∀ x, ph x) : ph x := H x rfl _
theorem ax_c11 {ph : setvar → setvar → wff} (x y) (H : ∀ x : setvar, x ≡ y)
(h : ∀ x, ph x y) (y') : ph x y' := weq'.1 ((H y).trans (H y').symm) ▸ h _
theorem ax_c11_b {ph : setvar → wff} (_ : ∀ x : setvar, x ≡ x) (h : ∀ x, ph x) : ∀ x, ph x := h
theorem ax_c11n (x y : setvar) (H : ∀ x:setvar, x ≡ y) (y':setvar) : y' ≡ x :=
(H _).trans (H _).symm
theorem ax_c15 {ph : setvar → wff} {y : setvar} (x : setvar)
(_ : ¬ ∀ x:setvar, x ≡ y) (h : x ≡ y) (h2 : ph x) (x') (h3 : x' ≡ y) : ph x' :=
weq'.1 (h.trans h3.symm) ▸ h2
theorem ax_c9 {x y : setvar} (_ : ¬ ∀ z:setvar, z ≡ x) (_ : ¬ ∀ z:setvar, z ≡ y)
(h : x ≡ y) (z':setvar) : x ≡ y := h
theorem ax_c9_b (z:setvar) (_ : ¬ ∀ z:setvar, z ≡ z) (_ : ¬ ∀ z:setvar, z ≡ z)
(h : z ≡ z) (z':setvar) : z' ≡ z' := rfl
theorem ax_c9_b1 {x : setvar} (_ : ¬ ∀ z:setvar, z ≡ x) (_ : ¬ ∀ z:setvar, z ≡ x)
(h : x ≡ x) (z':setvar) : x ≡ x := rfl
theorem ax_c9_b2 {y : setvar} (z : setvar) (H : ¬ ∀ z:setvar, z ≡ z) (_ : ¬ ∀ z:setvar, z ≡ y)
(_ : z ≡ y) (z':setvar) : z' ≡ y := H.elim (λ _, rfl)
theorem ax_c9_b3 {x : setvar} (z : setvar) (_ : ¬ ∀ z:setvar, z ≡ x) (H : ¬ ∀ z:setvar, z ≡ z)
(_ : x ≡ z) (z':setvar) : x ≡ z' := H.elim (λ _, rfl)
theorem ax_c14 {x y : setvar} (_ : ¬ ∀ z:setvar, z ≡ x) (_ : ¬ ∀ z:setvar, z ≡ y)
(h : x ∈ y) (z':setvar) : x ∈ y := h
theorem ax_c16 {ph : setvar → wff} {y : setvar} (x : setvar)
(H : ∀ x:setvar, x ≡ y) (h : ph x) (x') : ph x' :=
weq'.1 ((H x).trans (H x').symm) ▸ h
@[simp] def weu : (setvar → wff) → wff := exists_unique
theorem df_eu {ph : setvar → wff} : (∃! x, ph x) ↔ (∃ y:setvar, ∀ x, ph x ↔ x ≡ y) :=
⟨λ ⟨x, hx, H⟩, ⟨x, λ y, ⟨λ h, weq'.2 (H _ h), λ e, weq'.1 e.symm ▸ hx⟩⟩,
λ ⟨x, hx⟩, ⟨x, (hx _).2 rfl, λ y hy, weq'.1 ((hx _).1 hy)⟩⟩
def wmo (ph : setvar → wff) : wff := ∀ x y, ph x → ph y → x = y
notation `∃*` binders `, ` r:(scoped P, wmo P) := r
theorem df_mo {ph : setvar → wff} : (∃* x, ph x) ↔ ((∃ x, ph x) → (∃! x, ph x)) :=
⟨λ H ⟨x, hx⟩, ⟨x, hx, λ y hy, H _ _ hy hx⟩,
λ H x y hx hy, let ⟨z, _, hz⟩ := H ⟨x, hx⟩ in
(hz _ hx).trans (hz _ hy).symm⟩
theorem ax_7d {ph : setvar → setvar → wff} (H : ∀ x y:setvar, ph x y) (y x) : ph x y := H x y
def ax_8d := @ax_7
theorem ax_9d1 : ¬ ∀ x:setvar, ¬ x ≡ x := df_ex.1 ⟨∅, rfl⟩
def ax_9d2 := @ax_6
def ax_10d := @ax_c11n
def ax_11d := @ax_12
@[simp] theorem wel' {x y : setvar} : x ∈ y ↔ x ∈' y :=
(Class.mem_hom_left _ _).trans (Class.mem_hom_right _ _)
theorem ax_ext {x y : setvar} : (∀ z:setvar, z ∈ x ↔ z ∈ y) → x ≡ y :=
by simpa using @Set.ext x y
@[simp] def cab (ph : setvar → wff) : «class» := {x | ph x}
local notation `{` binders ` | ` r:(scoped P, cab P) `}` := r
theorem df_clab {ph : setvar → wff} {x : setvar} : x ∈ {y | ph y} ↔ ph x :=
Class.mem_hom_left _ _
theorem df_clab_b {ph : setvar → wff} (y : setvar) : ↑y ∈ cab ph ↔ ph y := df_clab
theorem df_cleq {A B : setvar → setvar → «class»}
(_ : ∀ y z:setvar, (∀ x:setvar, x ∈ y ↔ x ∈ z) → y ≡ z) (y z : setvar) :
A y z = B y z ↔ ∀ x:setvar, x ∈ A y z ↔ x ∈ B y z :=
by simp; exact set.ext_iff (A y z) (B y z)
theorem df_clel {A B : «class»} : A ∈ B ↔ ∃ x:setvar, ↑x = A ∧ x ∈ B :=
by simp; refl
def wnfc (A : setvar → «class») : wff := ∀ x y, A x = A y
theorem df_nfc {A : setvar → «class»} : wnfc A ↔ ∀ y:setvar, wnf (λ x, y ∈ A x) :=
by simp; exact
⟨λ H y x hx x', by rw H x' x; exact hx,
λ H x x', set.ext $ λ y, ⟨λ h, H _ _ h _, λ h, H _ _ h _⟩⟩
@[simp] def wne : «class» → «class» → wff := (≠)
theorem df_ne {A B : «class»} : A ≠ B ↔ ¬ A = B := iff.rfl
@[simp] def wnel : «class» → «class» → wff := (∉)
theorem df_nel {A B : «class»} : A ∉ B ↔ ¬ A ∈ B := iff.rfl
@[simp] def wral (ph : setvar → wff) (A : setvar → «class») : wff := ∀ x:setvar, x ∈ A x → ph x
theorem df_ral {ph : setvar → wff} {A : setvar → «class»} :
wral ph A ↔ (∀ x:setvar, x ∈ A x → ph x) := iff.rfl
@[simp] def wrex (ph : setvar → wff) (A : setvar → «class») : wff := ∃ x:setvar, x ∈ A x ∧ ph x
theorem df_rex {ph : setvar → wff} {A : setvar → «class»} :
wrex ph A ↔ (∃ x:setvar, x ∈ A x ∧ ph x) := iff.rfl
@[simp] def wreu (ph : setvar → wff) (A : setvar → «class») : wff := ∃! x:setvar, x ∈ A x ∧ ph x
theorem df_reu {ph : setvar → wff} {A : setvar → «class»} :
wreu ph A ↔ ∃! x:setvar, x ∈ A x ∧ ph x := iff.rfl
@[simp] def wrmo (ph : setvar → wff) (A : setvar → «class») : wff := ∃* x:setvar, x ∈ A x ∧ ph x
theorem df_rmo {ph : setvar → wff} {A : setvar → «class»} :
wrmo ph A ↔ ∃* x:setvar, x ∈ A x ∧ ph x := iff.rfl
def crab (ph : setvar → wff) (A : setvar → «class») : «class» := {x | x ∈ A x ∧ ph x}
theorem df_rab {ph : setvar → wff} {A : setvar → «class»} :
crab ph A = {x | x ∈ A x ∧ ph x} := rfl
@[simp] def cvv : «class» := set.univ
notation `V` := cvv
theorem df_v : V = {x | x ≡ x} := set.ext $ λ x, (iff_true_intro rfl).symm
@[simp] def wcdeq (ph : wff) (x y : setvar) : wff := x ≡ y → ph
theorem df_cdeq {ph : wff} {x y : setvar} :
wcdeq ph x y ↔ (x ≡ y → ph) := iff.rfl
def wsbc (ph : setvar → wff) (A : «class») : wff := A ∈ {x | ph x}
theorem df_sbc {ph : setvar → wff} {A : setvar → «class»} (x) :
wsbc ph (A x) ↔ A x ∈ {x | ph x} := iff.rfl
def csb (A : «class») (B : setvar → «class») : «class» :=
{y | wsbc (λ x, y ∈ B x) A}
theorem df_csb {A B : setvar → «class»} (x) :
csb (A x) B = {y | wsbc (λ x, y ∈ B x) (A x)} := rfl
@[simp] def cdif : «class» → «class» → «class» := (\)
@[simp] def cun : «class» → «class» → «class» := (∪)
@[simp] def cin : «class» → «class» → «class» := (∩)
@[simp] def wss : «class» → «class» → wff := (⊆)
@[simp] def wpss : «class» → «class» → wff := (⊂)
theorem df_dif {A B : «class»} : A \ B = {x | x ∈ A ∧ ↑x ∉ B} := by simp; refl
theorem df_un {A B : «class»} : A ∪ B = {x | x ∈ A ∨ x ∈ B} := by simp; refl
theorem df_in {A B : «class»} : A ∩ B = {x | x ∈ A ∧ x ∈ B} := by simp; refl
theorem df_ss {A B : «class»} : A ⊆ B ↔ A ∩ B = A :=
⟨set.inter_eq_self_of_subset_left, λ h, h ▸ set.inter_subset_right _ _⟩
theorem df_pss {A B : «class»} : A ⊂ B ↔ A ⊆ B ∧ A ≠ B := iff.rfl
@[simp] def c0 : «class» := ∅
theorem df_nul : ∅ = V \ V := set.diff_self.symm
def cif (ph : wff) (A B : «class») : «class» := {x | x ∈ A ∧ ph ∨ x ∈ B ∧ ¬ ph}
theorem df_if {ph : wff} {A B : «class»} :
cif ph A B = {x | x ∈ A ∧ ph ∨ x ∈ B ∧ ¬ ph} := rfl
def cpw : «class» → «class» := Class.powerset
theorem df_pw {A : «class»} : cpw A = {x | ↑x ⊆ A} := rfl
def csn (A : «class») : «class» := {x | ↑x = A}
theorem df_sn {A : «class»} : csn A = {x | ↑x = A} := rfl
def cpr (A B : «class») : «class» := csn A ∪ csn B
theorem df_pr {A B : «class»} : cpr A B = csn A ∪ csn B := rfl
def ctp (A B C : «class») : «class» := csn A ∪ csn B ∪ csn C
theorem df_tp {A B C : «class»} : ctp A B C = cpr A B ∪ csn C := rfl
def cop (A B : «class») : «class» :=
{x | A ∈ V ∧ B ∈ V ∧ x ∈ cpr (csn A) (cpr A B)}
theorem df_op {A B : «class»} :
cop A B = {x | A ∈ V ∧ B ∈ V ∧ x ∈ cpr (csn A) (cpr A B)} := rfl
def cotp (A B C : «class») : «class» := cop (cop A B) C
theorem df_ot {A B C : «class»} : cotp A B C = cop (cop A B) C := rfl
def cuni (A : «class») : «class» := {x | ∃ y:setvar, x ∈ y ∧ y ∈ A}
theorem df_uni {A : «class»} : cuni A = {x | ∃ y:setvar, x ∈ y ∧ y ∈ A} := rfl
def cint (A : «class») : «class» := {x | ∀ y:setvar, y ∈ A → x ∈ y}
theorem df_int {A : «class»} : cint A = {x | ∀ y:setvar, y ∈ A → x ∈ y} := rfl
def ciun (A B : setvar → «class») : «class» := {y | ∃ x:setvar, x ∈ A x ∧ y ∈ B x}
theorem df_iun {A B : setvar → «class»} :
ciun A B = {y | ∃ x:setvar, x ∈ A x ∧ y ∈ B x} := rfl
def ciin (A B : setvar → «class») : «class» := {y | ∀ x:setvar, x ∈ A x → y ∈ B x}
theorem df_iin {A B : setvar → «class»} :
ciin A B = {y | ∀ x:setvar, x ∈ A x → y ∈ B x} := rfl
def wdisj (A B : setvar → «class») : wff := ∀ y:setvar, ∃* x, x ∈ A x ∧ y ∈ B x
theorem df_disj {A B : setvar → «class»} :
wdisj A B ↔ ∀ y:setvar, ∃* x, x ∈ A x ∧ y ∈ B x := iff.rfl
def wbr (A B R : «class») : wff := cop A B ∈ R
theorem df_br {A B R : «class»} : wbr A B R ↔ cop A B ∈ R := iff.rfl
def copab (ph : setvar → setvar → wff) : «class» :=
{z | ∃ x y:setvar, ↑z = cop x y ∧ ph x y}
theorem df_opab {ph : setvar → setvar → wff} :
copab ph = {z | ∃ x y:setvar, ↑z = cop x y ∧ ph x y} := rfl
-- TODO: fix this properly by bundling copab; for now we will just assume
-- this isn't used
axiom df_opab_b {ph : setvar → wff} :
copab (λ x x, ph x) = {z | ∃ x x':setvar, ↑z = cop x' x' ∧ ph x'}
def cmpt (A B : setvar → «class») : «class» := copab (λ x y, x ∈ A x ∧ ↑y = B x)
theorem df_mpt {A B : setvar → «class»} :
cmpt A B = copab (λ x y, x ∈ A x ∧ ↑y = B x) := rfl
def wtr (A : «class») : wff := wss (cuni A) A
theorem df_tr {A : «class»} : ⊦ wb (wtr A) (wss (cuni A) A) := iff.rfl
theorem ax_rep {ph : ∀ y z w : setvar, wff} {x : setvar}
(H : ∀ w:setvar, ∃ y:setvar, ∀ z, (∀ y, ph y z w) → z ≡ y) :
∃ y:setvar, ∀ z:setvar, z ∈ y ↔ ∃ w:setvar, w ∈ x ∧ (∀ y, ph y z w) :=
begin
simp at *,
choose f hf using classical.axiom_of_choice H, dsimp at f,
haveI := @classical.all_definable 1 f,
refine ⟨has_sep.sep (λ z, ∃ w, w ∈' x ∧ ∀ (y : setvar), ph y z w) (Set.image f x),
λ z, Set.mem_sep.trans (and_iff_right_of_imp _)⟩,
rintro ⟨w, wx, hw⟩,
exact Set.mem_image.2 ⟨w, wx, (hf _ _ hw).symm⟩
end
theorem ax_pow {x : setvar} :
∃ y:setvar, ∀ z:setvar, (∀ w:setvar, w ∈ z → w ∈ x) → z ∈ y :=
by simp; exact ⟨Set.powerset x, λ z, Set.mem_powerset.2⟩
def cep : «class» := copab (∈')
theorem df_eprel : cep = copab (∈) := by simp; refl
def cid : «class» := copab (=)
theorem df_id : cid = copab (λ x y, x ≡ y) := by simp; refl
def wpo (A R : «class») : wff :=
wral (λ x, wral (λ y, wral (λ z, wa (wn (wbr (cv x) (cv x) R)) (wi (wa (wbr (cv x) (cv y) R) (wbr (cv y) (cv z) R)) (wbr (cv x) (cv z) R))) (λ z, A)) (λ y, A)) (λ x, A)
theorem df_po {A R : «class»} : wpo A R ↔
wral (λ x, wral (λ y, wral (λ z, wa (wn (wbr (cv x) (cv x) R)) (wi (wa (wbr (cv x) (cv y) R) (wbr (cv y) (cv z) R)) (wbr (cv x) (cv z) R))) (λ z, A)) (λ y, A)) (λ x, A) := iff.rfl
def wor (A R : «class») : wff :=
wa (wpo A R) (wral (λ x, wral (λ y, w3o (wbr (cv x) (cv y) R) (wceq (cv x) (cv y)) (wbr (cv y) (cv x) R)) (λ y, A)) (λ x, A))
theorem df_so {A R : «class»} : wor A R ↔ (wa (wpo A R) (wral (λ x, wral (λ y, w3o (wbr (cv x) (cv y) R) (wceq (cv x) (cv y)) (wbr (cv y) (cv x) R)) (λ y, A)) (λ x, A))) := iff.rfl
def wfr (A R : «class») : wff := wal (λ x, wi (wa (wss (cv x) A) (wne (cv x) c0)) (wrex (λ y, wral (λ z, wn (wbr (cv z) (cv y) R)) (λ z, cv x)) (λ y, cv x)))
theorem df_fr {A R : «class»} : wfr A R ↔ (wal (λ x, wi (wa (wss (cv x) A) (wne (cv x) c0)) (wrex (λ y, wral (λ z, wn (wbr (cv z) (cv y) R)) (λ z, cv x)) (λ y, cv x)))) := iff.rfl
def wse (A R : «class») : wff := wral (λ x, wcel (crab (λ y, wbr (cv y) (cv x) R) (λ y, A)) V) (λ x, A)
theorem df_se {A R : «class»} : wse A R ↔ (wral (λ x, wcel (crab (λ y, wbr (cv y) (cv x) R) (λ y, A)) V) (λ x, A)) := iff.rfl
def wwe (A R : «class») : wff := wa (wfr A R) (wor A R)
theorem df_we {A R : «class»} : wwe A R ↔ (wa (wfr A R) (wor A R)) := iff.rfl
def word (A : «class») : wff := wa (wtr A) (wwe A cep)
theorem df_ord {A : «class»} : word A ↔ wa (wtr A) (wwe A cep) := iff.rfl
def con0 : «class» := cab (λ x, word (cv x))
theorem df_on : ⊦ wceq con0 (cab (λ x, word (cv x))) := eq.refl _
def wlim (A : «class») : wff := w3a (word A) (wne A c0) (wceq A (cuni A))
theorem df_lim {A : «class»} : wlim A ↔ w3a (word A) (wne A c0) (wceq A (cuni A)) := iff.rfl
def csuc (A : «class») : «class» := cun A (csn A)
theorem df_suc {A : «class»} : csuc A = cun A (csn A) := rfl
def cxp (A B : «class») : «class» := copab (λ x y, x ∈ A ∧ y ∈ B)
theorem df_xp {A B : «class»} : cxp A B = copab (λ x y, x ∈ A ∧ y ∈ B) := rfl
def ccnv (A : «class») : «class» := copab (λ x y, wbr y x A)
theorem df_cnv {A : «class»} : ccnv A = copab (λ x y, wbr y x A) := rfl
def cdm (A : «class») : «class» := {x | ∃ y:setvar, wbr (cv x) (cv y) A}
theorem df_dm {A : «class»} : cdm A = {x | ∃ y:setvar, wbr (cv x) (cv y) A} := rfl
def crn (A : «class») : «class» := cdm (ccnv A)
theorem df_rn {A : «class»} : crn A = cdm (ccnv A) := rfl
def cres (A B : «class») : «class» := cin A (cxp B V)
theorem df_res {A B : «class»} : cres A B = cin A (cxp B V) := rfl
def cima (A B : «class») : «class» := crn (cres A B)
theorem df_ima {A B : «class»} : cima A B = crn (cres A B) := rfl
def ccom (A B : «class») : «class» := copab (λ x y, wex (λ z, wa (wbr (cv x) (cv z) B) (wbr (cv z) (cv y) A)))
theorem df_co {A B : «class»} : ccom A B = copab (λ x y, wex (λ z, wa (wbr (cv x) (cv z) B) (wbr (cv z) (cv y) A))) := rfl
def wrel (A : «class») : wff := wss A (cxp V V)
theorem df_rel {A : «class»} : ⊦ wrel A ↔ wss A (cxp V V) := iff.rfl
def cio (ph : setvar → wff) : «class» := cuni (cab (λ y, wceq (cab (λ x, ph x)) (csn (cv y))))
theorem df_iota {ph : setvar → wff} : cio (λ x, ph x) = cuni (cab (λ y, wceq (cab (λ x, ph x)) (csn (cv y)))) := rfl
def wfun (A : «class») : wff := wa (wrel A) (wss (ccom A (ccnv A)) cid)
theorem df_fun {A : «class»} : wfun A ↔ wa (wrel A) (wss (ccom A (ccnv A)) cid) := iff.rfl
def wfn (A B : «class») : wff := wa (wfun A) (wceq (cdm A) B)
theorem df_fn {A B : «class»} : wfn A B ↔ wa (wfun A) (wceq (cdm A) B) := iff.rfl
def wf (A B F : «class») : wff := wa (wfn F A) (wss (crn F) B)
theorem df_f {A B F : «class»} : wf A B F ↔ wa (wfn F A) (wss (crn F) B) := iff.rfl
def wf1 (A B F : «class») : wff := wa (wf A B F) (wfun (ccnv F))
theorem df_f1 {A B F : «class»} : wf1 A B F ↔ wa (wf A B F) (wfun (ccnv F)) := iff.rfl
def wfo (A B F : «class») : wff := wa (wfn F A) (wceq (crn F) B)
theorem df_fo {A B F : «class»} : wfo A B F ↔ wa (wfn F A) (wceq (crn F) B) := iff.rfl
def wf1o (A B F : «class») : wff := wa (wf1 A B F) (wfo A B F)
theorem df_f1o {A B F : «class»} : wf1o A B F ↔ wa (wf1 A B F) (wfo A B F) := iff.rfl
def cfv (A F : «class») : «class» := cio (λ x, wbr A (cv x) F)
theorem df_fv {A F : «class»} : cfv A F = cio (λ x, wbr A (cv x) F) := rfl
def wiso (A B R S H : «class») : wff := wa (wf1o A B H) (wral (λ x, wral (λ y, wb (wbr (cv x) (cv y) R) (wbr (cfv (cv x) H) (cfv (cv y) H) S)) (λ y, A)) (λ x, A))
theorem df_isom {A B R S H : «class»} : wiso A B R S H ↔ wa (wf1o A B H) (wral (λ x, wral (λ y, wb (wbr (cv x) (cv y) R) (wbr (cfv (cv x) H) (cfv (cv y) H) S)) (λ y, A)) (λ x, A)) := iff.rfl
def crio (ph : setvar → wff) (A : setvar → «class») : «class» := cio (λ x, wa (wcel (cv x) (A x)) (ph x))
theorem df_riota {ph : setvar → wff} {A : setvar → «class»} : crio ph A = cio (λ x, wa (wcel (cv x) (A x)) (ph x)) := rfl
def co (A B F : «class») : «class» := cfv (cop A B) F
theorem df_ov {A B F : «class»} : co A B F = cfv (cop A B) F := rfl
def coprab (ph : ∀ x y z : setvar, wff) : «class» := cab (λ w, wex (λ x, wex (λ y, wex (λ z, wa (wceq (cv w) (cop (cop (cv x) (cv y)) (cv z))) (ph x y z)))))
theorem df_oprab {ph : ∀ x y z : setvar, wff} : coprab ph = cab (λ w, wex (λ x, wex (λ y, wex (λ z, wa (wceq (cv w) (cop (cop (cv x) (cv y)) (cv z))) (ph x y z))))) := rfl
def cmpt2 (A B C : setvar → setvar → «class») : «class» := coprab (λ x y z, wa (wa (wcel (cv x) (A x y)) (wcel (cv y) (B x y))) (wceq (cv z) (C x y)))
theorem df_mpt2 {A B C : setvar → setvar → «class»} : cmpt2 A B C = coprab (λ x y z, wa (wa (wcel (cv x) (A x y)) (wcel (cv y) (B x y))) (wceq (cv z) (C x y))) := rfl
def cof (R : «class») : «class» := cmpt2 (λ f1 g1, V) (λ f1 g1, V) (λ f1 g1, cmpt (λ x, cin (cdm (cv f1)) (cdm (cv g1))) (λ x, co (cfv (cv x) (cv f1)) (cfv (cv x) (cv g1)) R))
theorem df_of {R : «class»} : cof R = cmpt2 (λ f1 g1, V) (λ f1 g1, V) (λ f1 g1, cmpt (λ x, cin (cdm (cv f1)) (cdm (cv g1))) (λ x, co (cfv (cv x) (cv f1)) (cfv (cv x) (cv g1)) R)) := rfl
def cofr (R : «class») : «class» := copab (λ f1 g1, wral (λ x, wbr (cfv (cv x) (cv f1)) (cfv (cv x) (cv g1)) R) (λ x, cin (cdm (cv f1)) (cdm (cv g1))))
theorem df_ofr {R : «class»} : cofr R = copab (λ f1 g1, wral (λ x, wbr (cfv (cv x) (cv f1)) (cfv (cv x) (cv g1)) R) (λ x, cin (cdm (cv f1)) (cdm (cv g1)))) := rfl
def crpss : «class» := copab (λ x y, (x:«class») ⊂ y)
theorem df_rpss : crpss = copab (λ x y, wpss (cv x) (cv y)) := rfl
theorem ax_un {x : setvar} : ∃ y:setvar, ∀ z:setvar,
(∃ w:setvar, z ∈ w ∧ w ∈ x) → z ∈ y :=
by simp; exact ⟨Set.Union x, λ z w zw wx, Set.mem_Union.2 ⟨w, wx, zw⟩⟩
def com : «class» := crab (λ x, wal (λ y, wi (wlim (cv y)) (wcel (cv x) (cv y)))) (λ x, con0)
theorem df_om : com = crab (λ x, wal (λ y, wi (wlim (cv y)) (wcel (cv x) (cv y)))) (λ x, con0) := rfl
def c1st : «class» := cmpt (λ x, V) (λ x, cuni (cdm (csn (cv x))))
theorem df_1st : c1st = cmpt (λ x, V) (λ x, cuni (cdm (csn (cv x)))) := rfl
def c2nd : «class» := cmpt (λ x, V) (λ x, cuni (crn (csn (cv x))))
theorem df_2nd : c2nd = cmpt (λ x, V) (λ x, cuni (crn (csn (cv x)))) := rfl
def ctpos (F : «class») : «class» := ccom F (cmpt (λ x, cun (ccnv (cdm F)) (csn c0)) (λ x, cuni (ccnv (csn (cv x)))))
theorem df_tpos {F : «class»} : ctpos F = ccom F (cmpt (λ x, cun (ccnv (cdm F)) (csn c0)) (λ x, cuni (ccnv (csn (cv x))))) := rfl
def ccur (F : «class») : «class» := cmpt (λ x, cdm (cdm F)) (λ x, copab (λ y z, wbr (cop (cv x) (cv y)) (cv z) F))
theorem df_cur {F : «class»} : ccur F = cmpt (λ x, cdm (cdm F)) (λ x, copab (λ y z, wbr (cop (cv x) (cv y)) (cv z) F)) := rfl
def cunc (F : «class») : «class» := coprab (λ x y z, wbr (cv y) (cv z) (cfv (cv x) F))
theorem df_unc {F : «class»} : cunc F = coprab (λ x y z, wbr (cv y) (cv z) (cfv (cv x) F)) := rfl
def cund : «class» := cmpt (λ s, V) (λ s, cpw (cuni (cv s)))
theorem df_undef : cund = cmpt (λ s, V) (λ s, cpw (cuni (cv s))) := rfl
def wsmo (A : «class») : wff := w3a (wf (cdm A) con0 A) (word (cdm A)) (wral (λ x, wral (λ y, wi (wcel (cv x) (cv y)) (wcel (cfv (cv x) A) (cfv (cv y) A))) (λ y, cdm A)) (λ x, cdm A))
theorem df_smo {A : «class»} : wsmo A ↔ w3a (wf (cdm A) con0 A) (word (cdm A)) (wral (λ x, wral (λ y, wi (wcel (cv x) (cv y)) (wcel (cfv (cv x) A) (cfv (cv y) A))) (λ y, cdm A)) (λ x, cdm A)) := iff.rfl
def crecs (F : «class») : «class» := cuni (cab (λ f1, wrex (λ x, wa (wfn (cv f1) (cv x)) (wral (λ y, wceq (cfv (cv y) (cv f1)) (cfv (cres (cv f1) (cv y)) F)) (λ y, cv x))) (λ x, con0)))
theorem df_recs {F : «class»} : crecs F = cuni (cab (λ f1, wrex (λ x, wa (wfn (cv f1) (cv x)) (wral (λ y, wceq (cfv (cv y) (cv f1)) (cfv (cres (cv f1) (cv y)) F)) (λ y, cv x))) (λ x, con0))) := rfl
def crdg (F I : «class») : «class» := crecs (cmpt (λ g1, V) (λ g1, cif (wceq (cv g1) c0) I (cif (wlim (cdm (cv g1))) (cuni (crn (cv g1))) (cfv (cfv (cuni (cdm (cv g1))) (cv g1)) F))))
theorem df_rdg {F I : «class»} : crdg F I = crecs (cmpt (λ g1, V) (λ g1, cif (wceq (cv g1) c0) I (cif (wlim (cdm (cv g1))) (cuni (crn (cv g1))) (cfv (cfv (cuni (cdm (cv g1))) (cv g1)) F)))) := rfl
def cseqom (F I : «class») : «class» := cima (crdg (cmpt2 (λ i v, com) (λ i v, V) (λ i v, cop (csuc (cv i)) (co (cv i) (cv v) F))) (cop c0 (cfv I cid))) com
theorem df_seqom {F I : «class»} : cseqom F I = cima (crdg (cmpt2 (λ i v, com) (λ i v, V) (λ i v, cop (csuc (cv i)) (co (cv i) (cv v) F))) (cop c0 (cfv I cid))) com := rfl
def c1o : «class» := csuc c0
theorem df_1o : c1o = csuc c0 := rfl
def c2o : «class» := csuc c1o
theorem df_2o : c2o = csuc c1o := rfl
def c3o : «class» := csuc c2o
theorem df_3o : c3o = csuc c2o := rfl
def c4o : «class» := csuc c3o
theorem df_4o : c4o = csuc c3o := rfl
def coa : «class» := cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cfv (cv y) (crdg (cmpt (λ z, V) (λ z, csuc (cv z))) (cv x)))
theorem df_oadd : coa = cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cfv (cv y) (crdg (cmpt (λ z, V) (λ z, csuc (cv z))) (cv x))) := rfl
def comu : «class» := cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cfv (cv y) (crdg (cmpt (λ z, V) (λ z, co (cv z) (cv x) coa)) c0))
theorem df_omul : comu = cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cfv (cv y) (crdg (cmpt (λ z, V) (λ z, co (cv z) (cv x) coa)) c0)) := rfl
def coe : «class» := cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cif (wceq (cv x) c0) (cdif c1o (cv y)) (cfv (cv y) (crdg (cmpt (λ z, V) (λ z, co (cv z) (cv x) comu)) c1o)))
theorem df_oexp : coe = cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cif (wceq (cv x) c0) (cdif c1o (cv y)) (cfv (cv y) (crdg (cmpt (λ z, V) (λ z, co (cv z) (cv x) comu)) c1o))) := rfl
def wer (A R : «class») : wff := w3a (wrel R) (wceq (cdm R) A) (wss (cun (ccnv R) (ccom R R)) R)
theorem df_er {A R : «class»} : wer A R ↔ w3a (wrel R) (wceq (cdm R) A) (wss (cun (ccnv R) (ccom R R)) R) := iff.rfl
def cec (A R : «class») : «class» := cima R (csn A)
theorem df_ec {A R : «class»} : cec A R = cima R (csn A) := rfl
def cqs (A R : «class») : «class» := cab (λ y, wrex (λ x, wceq (cv y) (cec (cv x) R)) (λ x, A))
theorem df_qs {A R : «class»} : cqs A R = cab (λ y, wrex (λ x, wceq (cv y) (cec (cv x) R)) (λ x, A)) := rfl
def cmap : «class» := cmpt2 (λ x y, V) (λ x y, V) (λ x y, cab (λ f1, wf (cv y) (cv x) (cv f1)))
theorem df_map : cmap = cmpt2 (λ x y, V) (λ x y, V) (λ x y, cab (λ f1, wf (cv y) (cv x) (cv f1))) := rfl
def cpm : «class» := cmpt2 (λ x y, V) (λ x y, V) (λ x y, crab (λ f1, wfun (cv f1)) (λ f1, cpw (cxp (cv y) (cv x))))
theorem df_pm : cpm = cmpt2 (λ x y, V) (λ x y, V) (λ x y, crab (λ f1, wfun (cv f1)) (λ f1, cpw (cxp (cv y) (cv x)))) := rfl
def cixp (A B : setvar → «class») : «class» := cab (λ f1, wa (wfn (cv f1) (cab (λ x, wcel (cv x) (A x)))) (wral (λ x, wcel (cfv (cv x) (cv f1)) (B x)) (λ x, A x)))
theorem df_ixp {A B : setvar → «class»} : cixp A B = cab (λ f1, wa (wfn (cv f1) (cab (λ x, wcel (cv x) (A x)))) (wral (λ x, wcel (cfv (cv x) (cv f1)) (B x)) (λ x, A x))) := rfl
def cen : «class» := copab (λ x y, wex (λ f1, wf1o (cv x) (cv y) (cv f1)))
theorem df_en : cen = copab (λ x y, wex (λ f1, wf1o (cv x) (cv y) (cv f1))) := rfl
def cdom : «class» := copab (λ x y, wex (λ f1, wf1 (cv x) (cv y) (cv f1)))
theorem df_dom : cdom = copab (λ x y, wex (λ f1, wf1 (cv x) (cv y) (cv f1))) := rfl
def csdm : «class» := cdif cdom cen
theorem df_sdom : csdm = cdif cdom cen := rfl
def cfn : «class» := cab (λ x, wrex (λ y, wbr (cv x) (cv y) cen) (λ y, com))
theorem df_fin : cfn = cab (λ x, wrex (λ y, wbr (cv x) (cv y) cen) (λ y, com)) := rfl
def cfi : «class» := cmpt (λ x, V) (λ x, cab (λ z, wrex (λ y, wceq (cv z) (cint (cv y))) (λ y, cin (cpw (cv x)) cfn)))
theorem df_fi : cfi = cmpt (λ x, V) (λ x, cab (λ z, wrex (λ y, wceq (cv z) (cint (cv y))) (λ y, cin (cpw (cv x)) cfn))) := rfl
def csup (A B R : «class») : «class» := cuni (crab (λ x, wa (wral (λ y, wn (wbr (cv x) (cv y) R)) (λ y, A)) (wral (λ y, wi (wbr (cv y) (cv x) R) (wrex (λ z, wbr (cv y) (cv z) R) (λ z, A))) (λ y, B))) (λ x, B))
theorem df_sup {A B R : «class»} : csup A B R = cuni (crab (λ x, wa (wral (λ y, wn (wbr (cv x) (cv y) R)) (λ y, A)) (wral (λ y, wi (wbr (cv y) (cv x) R) (wrex (λ z, wbr (cv y) (cv z) R) (λ z, A))) (λ y, B))) (λ x, B)) := rfl
def coi (A R : «class») : «class» := cif (wa (wwe A R) (wse A R)) (cres (crecs (cmpt (λ h, V) (λ h, crio (λ v, wral (λ u, wn (wbr (cv u) (cv v) R)) (λ u, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))) (λ v, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))))) (crab (λ x, wrex (λ t, wral (λ z, wbr (cv z) (cv t) R) (λ z, cima (crecs (cmpt (λ h, V) (λ h, crio (λ v, wral (λ u, wn (wbr (cv u) (cv v) R)) (λ u, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))) (λ v, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))))) (cv x))) (λ t, A)) (λ x, con0))) c0
theorem df_oi {A R : «class»} : coi A R = cif (wa (wwe A R) (wse A R)) (cres (crecs (cmpt (λ h, V) (λ h, crio (λ v, wral (λ u, wn (wbr (cv u) (cv v) R)) (λ u, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))) (λ v, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))))) (crab (λ x, wrex (λ t, wral (λ z, wbr (cv z) (cv t) R) (λ z, cima (crecs (cmpt (λ h, V) (λ h, crio (λ v, wral (λ u, wn (wbr (cv u) (cv v) R)) (λ u, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))) (λ v, crab (λ w, wral (λ j, wbr (cv j) (cv w) R) (λ j, crn (cv h))) (λ w, A))))) (cv x))) (λ t, A)) (λ x, con0))) c0 := rfl
def char : «class» := cmpt (λ x, V) (λ x, crab (λ y, wbr (cv y) (cv x) cdom) (λ y, con0))
theorem df_har : char = cmpt (λ x, V) (λ x, crab (λ y, wbr (cv y) (cv x) cdom) (λ y, con0)) := rfl
def cwdom : «class» := copab (λ x y, wo (wceq (cv x) c0) (wex (λ z, wfo (cv y) (cv x) (cv z))))
theorem df_wdom : cwdom = copab (λ x y, wo (wceq (cv x) c0) (wex (λ z, wfo (cv y) (cv x) (cv z)))) := rfl
theorem ax_reg {x : setvar} (H : ∃ y:setvar, y ∈ x) : ∃ y:setvar, y ∈ x ∧ ∀ z:setvar, z ∈ y → z ∉ x :=
begin
simp at *,
cases H with y hy,
rcases Set.regularity x (λ h, (Set.eq_empty x).1 h _ hy) with ⟨w, xw, h⟩,
simp [Set.eq_empty] at h,
exact ⟨w, xw, λ z zy zx, h z zx zy⟩
end
def {u} ax_inf.aux (x : Set.{u}) : ℕ → Set.{u}
| 0 := x
| (n+1) := Set.insert (ax_inf.aux n) ∅
theorem ax_inf {x : setvar} : ∃ y:setvar, x ∈ y ∧
∀ z:setvar, z ∈ y → ∃ w:setvar, z ∈ w ∧ w ∈ y :=
⟨Set.range (ax_inf.aux x), begin
simp,
refine ⟨⟨0, rfl⟩, _⟩,
rintro _ n rfl,
exact ⟨_, Set.mem_insert.2 (or.inl rfl), n+1, rfl⟩
end⟩
theorem ax_inf2 : ∃ x:setvar,
(∃ y:setvar, y ∈ x ∧ ∀ z:setvar, ¬ z ∈ y) ∧
∀ y:setvar, y ∈ x → ∃ z:setvar, z ∈ x ∧ ∀ w:setvar, w ∈ z ↔ w ∈ y ∨ w ≡ y :=
by simp; exact
⟨Set.omega, ⟨∅, Set.omega_zero, Set.mem_empty⟩,
λ y hy, ⟨insert y y, Set.omega_succ hy, by simp [or_comm]⟩⟩
def ccnf : «class» := cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cmpt (λ f1, crab (λ g1, wcel (cima (ccnv (cv g1)) (cdif cvv c1o)) cfn) (λ g1, co (cv x) (cv y) cmap)) (λ f1, csb (coi (cima (ccnv (cv f1)) (cdif cvv c1o)) cep) (λ h, cfv (cdm (cv h)) (cseqom (cmpt2 (λ k z, cvv) (λ k z, cvv) (λ k z, co (co (co (cv x) (cfv (cv k) (cv h)) coe) (cfv (cfv (cv k) (cv h)) (cv f1)) comu) (cv z) coa)) c0))))
theorem df_cnf : ccnf = cmpt2 (λ x y, con0) (λ x y, con0) (λ x y, cmpt (λ f1, crab (λ g1, wcel (cima (ccnv (cv g1)) (cdif cvv c1o)) cfn) (λ g1, co (cv x) (cv y) cmap)) (λ f1, csb (coi (cima (ccnv (cv f1)) (cdif cvv c1o)) cep) (λ h, cfv (cdm (cv h)) (cseqom (cmpt2 (λ k z, cvv) (λ k z, cvv) (λ k z, co (co (co (cv x) (cfv (cv k) (cv h)) coe) (cfv (cfv (cv k) (cv h)) (cv f1)) comu) (cv z) coa)) c0)))) := rfl
def ctc : «class» := cmpt (λ x, V) (λ x, cint (cab (λ y, wa (wss (cv x) (cv y)) (wtr (cv y)))))
theorem df_tc : ctc = cmpt (λ x, V) (λ x, cint (cab (λ y, wa (wss (cv x) (cv y)) (wtr (cv y))))) := rfl
def cr1 : «class» := crdg (cmpt (λ x, V) (λ x, cpw (cv x))) c0
theorem df_r1 : cr1 = crdg (cmpt (λ x, V) (λ x, cpw (cv x))) c0 := rfl
def crnk : «class» := cmpt (λ x, V) (λ x, cint (crab (λ y, wcel (cv x) (cfv (csuc (cv y)) cr1)) (λ y, con0)))
theorem df_rank : crnk = cmpt (λ x, V) (λ x, cint (crab (λ y, wcel (cv x) (cfv (csuc (cv y)) cr1)) (λ y, con0))) := rfl
def ccrd : «class» := cmpt (λ x, V) (λ x, cint (crab (λ y, wbr (cv y) (cv x) cen) (λ y, con0)))
theorem df_card : ccrd = cmpt (λ x, V) (λ x, cint (crab (λ y, wbr (cv y) (cv x) cen) (λ y, con0))) := rfl
def cale : «class» := crdg char com
theorem df_aleph : cale = crdg char com := rfl
def ccf : «class» := cmpt (λ x, con0) (λ x, cint (cab (λ y, wex (λ z, wa (wceq (cv y) (cfv (cv z) ccrd)) (wa (wss (cv z) (cv x)) (wral (λ v, wrex (λ u, wss (cv v) (cv u)) (λ u, cv z)) (λ v, cv x)))))))
theorem df_cf : ccf = cmpt (λ x, con0) (λ x, cint (cab (λ y, wex (λ z, wa (wceq (cv y) (cfv (cv z) ccrd)) (wa (wss (cv z) (cv x)) (wral (λ v, wrex (λ u, wss (cv v) (cv u)) (λ u, cv z)) (λ v, cv x))))))) := rfl
def wacn (A : «class») : «class» := cab (λ x, wa (wcel A V) (wral (λ f1, wex (λ g1, wral (λ y, wcel (cfv (cv y) (cv g1)) (cfv (cv y) (cv f1))) (λ y, A))) (λ f1, co (cdif (cpw (cv x)) (csn c0)) A cmap)))
theorem df_acn {A : «class»} : wacn A = cab (λ x, wa (wcel A V) (wral (λ f1, wex (λ g1, wral (λ y, wcel (cfv (cv y) (cv g1)) (cfv (cv y) (cv f1))) (λ y, A))) (λ f1, co (cdif (cpw (cv x)) (csn c0)) A cmap))) := rfl
def wac : wff := wal (λ x, wex (λ f1, wa (wss (cv f1) (cv x)) (wfn (cv f1) (cdm (cv x)))))
theorem df_ac : wac ↔ wal (λ x, wex (λ f1, wa (wss (cv f1) (cv x)) (wfn (cv f1) (cdm (cv x))))) := iff.rfl
def ccda : «class» := cmpt2 (λ x y, V) (λ x y, V) (λ x y, cun (cxp (cv x) (csn c0)) (cxp (cv y) (csn c1o)))
theorem df_cda : ccda = cmpt2 (λ x y, V) (λ x y, V) (λ x y, cun (cxp (cv x) (csn c0)) (cxp (cv y) (csn c1o))) := rfl
def cnpi : «class» := cdif com (csn c0)
theorem df_ni : cnpi = cdif com (csn c0) := rfl
def cpli : «class» := cres coa (cxp cnpi cnpi)
theorem df_pli : cpli = cres coa (cxp cnpi cnpi) := rfl
def cmi : «class» := cres comu (cxp cnpi cnpi)
theorem df_mi : cmi = cres comu (cxp cnpi cnpi) := rfl
def clti : «class» := cin cep (cxp cnpi cnpi)
theorem df_lti : clti = cin cep (cxp cnpi cnpi) := rfl
def cplpq : «class» := cmpt2 (λ x y, cxp cnpi cnpi) (λ x y, cxp cnpi cnpi) (λ x y, cop (co (co (cfv (cv x) c1st) (cfv (cv y) c2nd) cmi) (co (cfv (cv y) c1st) (cfv (cv x) c2nd) cmi) cpli) (co (cfv (cv x) c2nd) (cfv (cv y) c2nd) cmi))
theorem df_plpq : cplpq = cmpt2 (λ x y, cxp cnpi cnpi) (λ x y, cxp cnpi cnpi) (λ x y, cop (co (co (cfv (cv x) c1st) (cfv (cv y) c2nd) cmi) (co (cfv (cv y) c1st) (cfv (cv x) c2nd) cmi) cpli) (co (cfv (cv x) c2nd) (cfv (cv y) c2nd) cmi)) := rfl
def cmpq : «class» := cmpt2 (λ x y, cxp cnpi cnpi) (λ x y, cxp cnpi cnpi) (λ x y, cop (co (cfv (cv x) c1st) (cfv (cv y) c1st) cmi) (co (cfv (cv x) c2nd) (cfv (cv y) c2nd) cmi))
theorem df_mpq : cmpq = cmpt2 (λ x y, cxp cnpi cnpi) (λ x y, cxp cnpi cnpi) (λ x y, cop (co (cfv (cv x) c1st) (cfv (cv y) c1st) cmi) (co (cfv (cv x) c2nd) (cfv (cv y) c2nd) cmi)) := rfl
def cltpq : «class» := copab (λ x y, wa (wa (wcel (cv x) (cxp cnpi cnpi)) (wcel (cv y) (cxp cnpi cnpi))) (wbr (co (cfv (cv x) c1st) (cfv (cv y) c2nd) cmi) (co (cfv (cv y) c1st) (cfv (cv x) c2nd) cmi) clti))
theorem df_ltpq : cltpq = copab (λ x y, wa (wa (wcel (cv x) (cxp cnpi cnpi)) (wcel (cv y) (cxp cnpi cnpi))) (wbr (co (cfv (cv x) c1st) (cfv (cv y) c2nd) cmi) (co (cfv (cv y) c1st) (cfv (cv x) c2nd) cmi) clti)) := rfl
def ceq : «class» := copab (λ x y, wa (wa (wcel (cv x) (cxp cnpi cnpi)) (wcel (cv y) (cxp cnpi cnpi))) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cop (cv z) (cv w))) (wceq (cv y) (cop (cv v) (cv u)))) (wceq (co (cv z) (cv u) cmi) (co (cv w) (cv v) cmi))))))))
theorem df_enq : ceq = copab (λ x y, wa (wa (wcel (cv x) (cxp cnpi cnpi)) (wcel (cv y) (cxp cnpi cnpi))) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cop (cv z) (cv w))) (wceq (cv y) (cop (cv v) (cv u)))) (wceq (co (cv z) (cv u) cmi) (co (cv w) (cv v) cmi)))))))) := rfl
def cnq : «class» := crab (λ x, wral (λ y, wi (wbr (cv x) (cv y) ceq) (wn (wbr (cfv (cv y) c2nd) (cfv (cv x) c2nd) clti))) (λ y, cxp cnpi cnpi)) (λ x, cxp cnpi cnpi)
theorem df_nq : cnq = crab (λ x, wral (λ y, wi (wbr (cv x) (cv y) ceq) (wn (wbr (cfv (cv y) c2nd) (cfv (cv x) c2nd) clti))) (λ y, cxp cnpi cnpi)) (λ x, cxp cnpi cnpi) := rfl
def c1q : «class» := cop c1o c1o
theorem df_1nq : c1q = cop c1o c1o := rfl
def cerq : «class» := cin ceq (cxp (cxp cnpi cnpi) cnq)
theorem df_erq : cerq = cin ceq (cxp (cxp cnpi cnpi) cnq) := rfl
def cplq : «class» := cres (ccom cerq cplpq) (cxp cnq cnq)
theorem df_plq : cplq = cres (ccom cerq cplpq) (cxp cnq cnq) := rfl
def cmq : «class» := cres (ccom cerq cmpq) (cxp cnq cnq)
theorem df_mq : cmq = cres (ccom cerq cmpq) (cxp cnq cnq) := rfl
def crq : «class» := cima (ccnv cmq) (csn c1q)
theorem df_rq : crq = cima (ccnv cmq) (csn c1q) := rfl
def cltq : «class» := cin cltpq (cxp cnq cnq)
theorem df_ltnq : cltq = cin cltpq (cxp cnq cnq) := rfl
def cnp : «class» := cab (λ x, wa (wa (wpss c0 (cv x)) (wpss (cv x) cnq)) (wral (λ y, wa (wal (λ z, wi (wbr (cv z) (cv y) cltq) (wcel (cv z) (cv x)))) (wrex (λ z, wbr (cv y) (cv z) cltq) (λ z, cv x))) (λ y, cv x)))
theorem df_np : cnp = cab (λ x, wa (wa (wpss c0 (cv x)) (wpss (cv x) cnq)) (wral (λ y, wa (wal (λ z, wi (wbr (cv z) (cv y) cltq) (wcel (cv z) (cv x)))) (wrex (λ z, wbr (cv y) (cv z) cltq) (λ z, cv x))) (λ y, cv x))) := rfl
def c1p : «class» := cab (λ x, wbr (cv x) c1q cltq)
theorem df_1p : c1p = cab (λ x, wbr (cv x) c1q cltq) := rfl
def cpp : «class» := cmpt2 (λ x y, cnp) (λ x y, cnp) (λ x y, cab (λ w, wrex (λ v, wrex (λ u, wceq (cv w) (co (cv v) (cv u) cplq)) (λ u, cv y)) (λ v, cv x)))
theorem df_plp : cpp = cmpt2 (λ x y, cnp) (λ x y, cnp) (λ x y, cab (λ w, wrex (λ v, wrex (λ u, wceq (cv w) (co (cv v) (cv u) cplq)) (λ u, cv y)) (λ v, cv x))) := rfl
def cmp : «class» := cmpt2 (λ x y, cnp) (λ x y, cnp) (λ x y, cab (λ w, wrex (λ v, wrex (λ u, wceq (cv w) (co (cv v) (cv u) cmq)) (λ u, cv y)) (λ v, cv x)))
theorem df_mp : cmp = cmpt2 (λ x y, cnp) (λ x y, cnp) (λ x y, cab (λ w, wrex (λ v, wrex (λ u, wceq (cv w) (co (cv v) (cv u) cmq)) (λ u, cv y)) (λ v, cv x))) := rfl
def cltp : «class» := copab (λ x y, wa (wa (wcel (cv x) cnp) (wcel (cv y) cnp)) (wpss (cv x) (cv y)))
theorem df_ltp : cltp = copab (λ x y, wa (wa (wcel (cv x) cnp) (wcel (cv y) cnp)) (wpss (cv x) (cv y))) := rfl
def cplpr : «class» := coprab (λ x y z, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (cv w) (cv u) cpp) (co (cv v) (cv f) cpp)))))))))
theorem df_plpr : cplpr = coprab (λ x y z, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (cv w) (cv u) cpp) (co (cv v) (cv f) cpp))))))))) := rfl
def cmpr : «class» := coprab (λ x y z, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (co (cv w) (cv u) cmp) (co (cv v) (cv f) cmp) cpp) (co (co (cv w) (cv f) cmp) (co (cv v) (cv u) cmp) cpp)))))))))
theorem df_mpr : cmpr = coprab (λ x y z, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (co (cv w) (cv u) cmp) (co (cv v) (cv f) cmp) cpp) (co (co (cv w) (cv f) cmp) (co (cv v) (cv u) cmp) cpp))))))))) := rfl
def cer : «class» := copab (λ x y, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cop (cv z) (cv w))) (wceq (cv y) (cop (cv v) (cv u)))) (wceq (co (cv z) (cv u) cpp) (co (cv w) (cv v) cpp))))))))
theorem df_enr : cer = copab (λ x y, wa (wa (wcel (cv x) (cxp cnp cnp)) (wcel (cv y) (cxp cnp cnp))) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cop (cv z) (cv w))) (wceq (cv y) (cop (cv v) (cv u)))) (wceq (co (cv z) (cv u) cpp) (co (cv w) (cv v) cpp)))))))) := rfl
def cnr : «class» := cqs (cxp cnp cnp) cer
theorem df_nr : cnr = cqs (cxp cnp cnp) cer := rfl
def c0r : «class» := cec (cop c1p c1p) cer
theorem df_0r : c0r = cec (cop c1p c1p) cer := rfl
def c1r : «class» := cec (cop (co c1p c1p cpp) c1p) cer
theorem df_1r : c1r = cec (cop (co c1p c1p cpp) c1p) cer := rfl
def cm1r : «class» := cec (cop c1p (co c1p c1p cpp)) cer
theorem df_m1r : cm1r = cec (cop c1p (co c1p c1p cpp)) cer := rfl
def cplr : «class» := coprab (λ x y z, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cec (cop (cv w) (cv v)) cer)) (wceq (cv y) (cec (cop (cv u) (cv f)) cer))) (wceq (cv z) (cec (co (cop (cv w) (cv v)) (cop (cv u) (cv f)) cplpr) cer))))))))
theorem df_plr : cplr = coprab (λ x y z, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cec (cop (cv w) (cv v)) cer)) (wceq (cv y) (cec (cop (cv u) (cv f)) cer))) (wceq (cv z) (cec (co (cop (cv w) (cv v)) (cop (cv u) (cv f)) cplpr) cer)))))))) := rfl
def cmr : «class» := coprab (λ x y z, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cec (cop (cv w) (cv v)) cer)) (wceq (cv y) (cec (cop (cv u) (cv f)) cer))) (wceq (cv z) (cec (co (cop (cv w) (cv v)) (cop (cv u) (cv f)) cmpr) cer))))))))
theorem df_mr : cmr = coprab (λ x y z, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cec (cop (cv w) (cv v)) cer)) (wceq (cv y) (cec (cop (cv u) (cv f)) cer))) (wceq (cv z) (cec (co (cop (cv w) (cv v)) (cop (cv u) (cv f)) cmpr) cer)))))))) := rfl
def cltr : «class» := copab (λ x y, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cec (cop (cv z) (cv w)) cer)) (wceq (cv y) (cec (cop (cv v) (cv u)) cer))) (wbr (co (cv z) (cv u) cpp) (co (cv w) (cv v) cpp) cltp)))))))
theorem df_ltr : cltr = copab (λ x y, wa (wa (wcel (cv x) cnr) (wcel (cv y) cnr)) (wex (λ z, wex (λ w, wex (λ v, wex (λ u, wa (wa (wceq (cv x) (cec (cop (cv z) (cv w)) cer)) (wceq (cv y) (cec (cop (cv v) (cv u)) cer))) (wbr (co (cv z) (cv u) cpp) (co (cv w) (cv v) cpp) cltp))))))) := rfl
def cc : «class» := cxp cnr cnr
theorem df_c : cc = cxp cnr cnr := rfl
def cr : «class» := cxp cnr (csn c0r)
theorem df_r : cr = cxp cnr (csn c0r) := rfl
def cc0 : «class» := cop c0r c0r
theorem df_0 : cc0 = cop c0r c0r := rfl
def c1 : «class» := cop c1r c0r
theorem df_1 : c1 = cop c1r c0r := rfl
def ci : «class» := cop c0r c1r
theorem df_i : ci = cop c0r c1r := rfl
def caddc : «class» := coprab (λ x y z, wa (wa (wcel (cv x) cc) (wcel (cv y) cc)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (cv w) (cv u) cplr) (co (cv v) (cv f) cplr)))))))))
theorem df_add : caddc = coprab (λ x y z, wa (wa (wcel (cv x) cc) (wcel (cv y) cc)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (cv w) (cv u) cplr) (co (cv v) (cv f) cplr))))))))) := rfl
def cltrr : «class» := copab (λ x y, wa (wa (wcel (cv x) cr) (wcel (cv y) cr)) (wex (λ z, wex (λ w, wa (wa (wceq (cv x) (cop (cv z) c0r)) (wceq (cv y) (cop (cv w) c0r))) (wbr (cv z) (cv w) cltr)))))
theorem df_lt : cltrr = copab (λ x y, wa (wa (wcel (cv x) cr) (wcel (cv y) cr)) (wex (λ z, wex (λ w, wa (wa (wceq (cv x) (cop (cv z) c0r)) (wceq (cv y) (cop (cv w) c0r))) (wbr (cv z) (cv w) cltr))))) := rfl
def cmul : «class» := coprab (λ x y z, wa (wa (wcel (cv x) cc) (wcel (cv y) cc)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (co (cv w) (cv u) cmr) (co cm1r (co (cv v) (cv f) cmr) cmr) cplr) (co (co (cv v) (cv u) cmr) (co (cv w) (cv f) cmr) cplr)))))))))
theorem df_mul : cmul = coprab (λ x y z, wa (wa (wcel (cv x) cc) (wcel (cv y) cc)) (wex (λ w, wex (λ v, wex (λ u, wex (λ f, wa (wa (wceq (cv x) (cop (cv w) (cv v))) (wceq (cv y) (cop (cv u) (cv f)))) (wceq (cv z) (cop (co (co (cv w) (cv u) cmr) (co cm1r (co (cv v) (cv f) cmr) cmr) cplr) (co (co (cv v) (cv u) cmr) (co (cv w) (cv f) cmr) cplr))))))))) := rfl
def cpnf : «class» := cpw (cuni cc)
theorem df_pnf : cpnf = cpw (cuni cc) := rfl
def cmnf : «class» := cpw cpnf
theorem df_mnf : cmnf = cpw cpnf := rfl
def cxr : «class» := cun cr (cpr cpnf cmnf)
theorem df_xr : cxr = cun cr (cpr cpnf cmnf) := rfl
def clt : «class» := cun (copab (λ x y, w3a (wcel (cv x) cr) (wcel (cv y) cr) (wbr (cv x) (cv y) cltrr))) (cun (cxp (cun cr (csn cmnf)) (csn cpnf)) (cxp (csn cmnf) cr))
theorem df_ltxr : clt = cun (copab (λ x y, w3a (wcel (cv x) cr) (wcel (cv y) cr) (wbr (cv x) (cv y) cltrr))) (cun (cxp (cun cr (csn cmnf)) (csn cpnf)) (cxp (csn cmnf) cr)) := rfl
def cle : «class» := cdif (cxp cxr cxr) (ccnv clt)
theorem df_le : cle = cdif (cxp cxr cxr) (ccnv clt) := rfl
def cmin : «class» := cmpt2 (λ x y, cc) (λ x y, cc) (λ x y, crio (λ z, wceq (co (cv y) (cv z) caddc) (cv x)) (λ z, cc))
theorem df_sub : cmin = cmpt2 (λ x y, cc) (λ x y, cc) (λ x y, crio (λ z, wceq (co (cv y) (cv z) caddc) (cv x)) (λ z, cc)) := rfl
def cneg (A : «class») : «class» := co cc0 A cmin
theorem df_neg {A : «class»} : cneg A = co cc0 A cmin := rfl
def cdiv : «class» := cmpt2 (λ x y, cc) (λ x y, cdif cc (csn cc0)) (λ x y, crio (λ z, wceq (co (cv y) (cv z) cmul) (cv x)) (λ z, cc))
theorem df_div : cdiv = cmpt2 (λ x y, cc) (λ x y, cdif cc (csn cc0)) (λ x y, crio (λ z, wceq (co (cv y) (cv z) cmul) (cv x)) (λ z, cc)) := rfl
def cn : «class» := cima (crdg (cmpt (λ x, cvv) (λ x, co (cv x) c1 caddc)) c1) com
theorem df_nn : cn = cima (crdg (cmpt (λ x, cvv) (λ x, co (cv x) c1 caddc)) c1) com := rfl
def c2 : «class» := co c1 c1 caddc
theorem df_2 : c2 = co c1 c1 caddc := rfl
def c3 : «class» := co c2 c1 caddc
theorem df_3 : c3 = co c2 c1 caddc := rfl
def c4 : «class» := co c3 c1 caddc
theorem df_4 : c4 = co c3 c1 caddc := rfl
def c5 : «class» := co c4 c1 caddc
theorem df_5 : c5 = co c4 c1 caddc := rfl
def c6 : «class» := co c5 c1 caddc
theorem df_6 : c6 = co c5 c1 caddc := rfl
def c7 : «class» := co c6 c1 caddc
theorem df_7 : c7 = co c6 c1 caddc := rfl
def c8 : «class» := co c7 c1 caddc
theorem df_8 : c8 = co c7 c1 caddc := rfl
def c9 : «class» := co c8 c1 caddc
theorem df_9 : c9 = co c8 c1 caddc := rfl
def c10 : «class» := co c9 c1 caddc
theorem df_10 : c10 = co c9 c1 caddc := rfl
def cn0 : «class» := cun cn (csn cc0)
theorem df_n0 : cn0 = cun cn (csn cc0) := rfl
def cz : «class» := crab (λ n, w3o (wceq (cv n) cc0) (wcel (cv n) cn) (wcel (cneg (cv n)) cn)) (λ n, cr)
theorem df_z : cz = crab (λ n, w3o (wceq (cv n) cc0) (wcel (cv n) cn) (wcel (cneg (cv n)) cn)) (λ n, cr) := rfl
def cdc (A B : «class») : «class» := co (co c10 A cmul) B caddc
theorem df_dec {A B : «class»} : cdc A B = co (co c10 A cmul) B caddc := rfl
def cuz : «class» := cmpt (λ j, cz) (λ j, crab (λ k, wbr (cv j) (cv k) cle) (λ k, cz))
theorem df_uz : cuz = cmpt (λ j, cz) (λ j, crab (λ k, wbr (cv j) (cv k) cle) (λ k, cz)) := rfl
def cq : «class» := cima cdiv (cxp cz cn)
theorem df_q : cq = cima cdiv (cxp cz cn) := rfl
def crp : «class» := crab (λ x, wbr cc0 (cv x) clt) (λ x, cr)
theorem df_rp : crp = crab (λ x, wbr cc0 (cv x) clt) (λ x, cr) := rfl
def cxne (A : «class») : «class» := cif (wceq A cpnf) cmnf (cif (wceq A cmnf) cpnf (cneg A))
theorem df_xneg {A : «class»} : cxne A = cif (wceq A cpnf) cmnf (cif (wceq A cmnf) cpnf (cneg A)) := rfl
def cxad : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wceq (cv x) cpnf) (cif (wceq (cv y) cmnf) cc0 cpnf) (cif (wceq (cv x) cmnf) (cif (wceq (cv y) cpnf) cc0 cmnf) (cif (wceq (cv y) cpnf) cpnf (cif (wceq (cv y) cmnf) cmnf (co (cv x) (cv y) caddc)))))
theorem df_xadd : cxad = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wceq (cv x) cpnf) (cif (wceq (cv y) cmnf) cc0 cpnf) (cif (wceq (cv x) cmnf) (cif (wceq (cv y) cpnf) cc0 cmnf) (cif (wceq (cv y) cpnf) cpnf (cif (wceq (cv y) cmnf) cmnf (co (cv x) (cv y) caddc))))) := rfl
def cxmu : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wo (wceq (cv x) cc0) (wceq (cv y) cc0)) cc0 (cif (wo (wo (wa (wbr cc0 (cv y) clt) (wceq (cv x) cpnf)) (wa (wbr (cv y) cc0 clt) (wceq (cv x) cmnf))) (wo (wa (wbr cc0 (cv x) clt) (wceq (cv y) cpnf)) (wa (wbr (cv x) cc0 clt) (wceq (cv y) cmnf)))) cpnf (cif (wo (wo (wa (wbr cc0 (cv y) clt) (wceq (cv x) cmnf)) (wa (wbr (cv y) cc0 clt) (wceq (cv x) cpnf))) (wo (wa (wbr cc0 (cv x) clt) (wceq (cv y) cmnf)) (wa (wbr (cv x) cc0 clt) (wceq (cv y) cpnf)))) cmnf (co (cv x) (cv y) cmul))))
theorem df_xmul : cxmu = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wo (wceq (cv x) cc0) (wceq (cv y) cc0)) cc0 (cif (wo (wo (wa (wbr cc0 (cv y) clt) (wceq (cv x) cpnf)) (wa (wbr (cv y) cc0 clt) (wceq (cv x) cmnf))) (wo (wa (wbr cc0 (cv x) clt) (wceq (cv y) cpnf)) (wa (wbr (cv x) cc0 clt) (wceq (cv y) cmnf)))) cpnf (cif (wo (wo (wa (wbr cc0 (cv y) clt) (wceq (cv x) cmnf)) (wa (wbr (cv y) cc0 clt) (wceq (cv x) cpnf))) (wo (wa (wbr cc0 (cv x) clt) (wceq (cv y) cmnf)) (wa (wbr (cv x) cc0 clt) (wceq (cv y) cpnf)))) cmnf (co (cv x) (cv y) cmul)))) := rfl
def cioo : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) clt) (wbr (cv z) (cv y) clt)) (λ z, cxr))
theorem df_ioo : cioo = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) clt) (wbr (cv z) (cv y) clt)) (λ z, cxr)) := rfl
def cioc : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) clt) (wbr (cv z) (cv y) cle)) (λ z, cxr))
theorem df_ioc : cioc = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) clt) (wbr (cv z) (cv y) cle)) (λ z, cxr)) := rfl
def cico : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) cle) (wbr (cv z) (cv y) clt)) (λ z, cxr))
theorem df_ico : cico = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) cle) (wbr (cv z) (cv y) clt)) (λ z, cxr)) := rfl
def cicc : «class» := cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) cle) (wbr (cv z) (cv y) cle)) (λ z, cxr))
theorem df_icc : cicc = cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, crab (λ z, wa (wbr (cv x) (cv z) cle) (wbr (cv z) (cv y) cle)) (λ z, cxr)) := rfl
def cfz : «class» := cmpt2 (λ m n, cz) (λ m n, cz) (λ m n, crab (λ k, wa (wbr (cv m) (cv k) cle) (wbr (cv k) (cv n) cle)) (λ k, cz))
theorem df_fz : cfz = cmpt2 (λ m n, cz) (λ m n, cz) (λ m n, crab (λ k, wa (wbr (cv m) (cv k) cle) (wbr (cv k) (cv n) cle)) (λ k, cz)) := rfl
def cfzo : «class» := cmpt2 (λ m n, cz) (λ m n, cz) (λ m n, co (cv m) (co (cv n) c1 cmin) cfz)
theorem df_fzo : cfzo = cmpt2 (λ m n, cz) (λ m n, cz) (λ m n, co (cv m) (co (cv n) c1 cmin) cfz) := rfl
def cfl : «class» := cmpt (λ x, cr) (λ x, crio (λ y, wa (wbr (cv y) (cv x) cle) (wbr (cv x) (co (cv y) c1 caddc) clt)) (λ y, cz))
theorem df_fl : cfl = cmpt (λ x, cr) (λ x, crio (λ y, wa (wbr (cv y) (cv x) cle) (wbr (cv x) (co (cv y) c1 caddc) clt)) (λ y, cz)) := rfl
def cmo : «class» := cmpt2 (λ x y, cr) (λ x y, crp) (λ x y, co (cv x) (co (cv y) (cfv (co (cv x) (cv y) cdiv) cfl) cmul) cmin)
theorem df_mod : cmo = cmpt2 (λ x y, cr) (λ x y, crp) (λ x y, co (cv x) (co (cv y) (cfv (co (cv x) (cv y) cdiv) cfl) cmul) cmin) := rfl
def cseq (c_pl F M : «class») : «class» := cima (crdg (cmpt2 (λ x y, cvv) (λ x y, cvv) (λ x y, cop (co (cv x) c1 caddc) (co (cv y) (cfv (co (cv x) c1 caddc) F) c_pl))) (cop M (cfv M F))) com
theorem df_seq {c_pl F M : «class»} : cseq c_pl F M = cima (crdg (cmpt2 (λ x y, cvv) (λ x y, cvv) (λ x y, cop (co (cv x) c1 caddc) (co (cv y) (cfv (co (cv x) c1 caddc) F) c_pl))) (cop M (cfv M F))) com := rfl
def cexp : «class» := cmpt2 (λ x y, cc) (λ x y, cz) (λ x y, cif (wceq (cv y) cc0) c1 (cif (wbr cc0 (cv y) clt) (cfv (cv y) (cseq cmul (cxp cn (csn (cv x))) c1)) (co c1 (cfv (cneg (cv y)) (cseq cmul (cxp cn (csn (cv x))) c1)) cdiv)))
theorem df_exp : cexp = cmpt2 (λ x y, cc) (λ x y, cz) (λ x y, cif (wceq (cv y) cc0) c1 (cif (wbr cc0 (cv y) clt) (cfv (cv y) (cseq cmul (cxp cn (csn (cv x))) c1)) (co c1 (cfv (cneg (cv y)) (cseq cmul (cxp cn (csn (cv x))) c1)) cdiv))) := rfl
def cfa : «class» := cun (csn (cop cc0 c1)) (cseq cmul cid c1)
theorem df_fac : cfa = cun (csn (cop cc0 c1)) (cseq cmul cid c1) := rfl
def cbc : «class» := cmpt2 (λ n k, cn0) (λ n k, cz) (λ n k, cif (wcel (cv k) (co cc0 (cv n) cfz)) (co (cfv (cv n) cfa) (co (cfv (co (cv n) (cv k) cmin) cfa) (cfv (cv k) cfa) cmul) cdiv) cc0)
theorem df_bc : cbc = cmpt2 (λ n k, cn0) (λ n k, cz) (λ n k, cif (wcel (cv k) (co cc0 (cv n) cfz)) (co (cfv (cv n) cfa) (co (cfv (co (cv n) (cv k) cmin) cfa) (cfv (cv k) cfa) cmul) cdiv) cc0) := rfl
def chash : «class» := cun (ccom (cres (crdg (cmpt (λ x, cvv) (λ x, co (cv x) c1 caddc)) cc0) com) ccrd) (cxp (cdif cvv cfn) (csn cpnf))
theorem df_hash : chash = cun (ccom (cres (crdg (cmpt (λ x, cvv) (λ x, co (cv x) c1 caddc)) cc0) com) ccrd) (cxp (cdif cvv cfn) (csn cpnf)) := rfl
def cword (S : «class») : «class» := (cab (λ w, wrex (λ l, wf (co cc0 (cv l) cfzo) S (cv w)) (λ l, cn0)))
theorem df_word {S : «class»} : cword S = cab (λ w, wrex (λ l, wf (co cc0 (cv l) cfzo) S (cv w)) (λ l, cn0)) := rfl
def cconcat : «class» := cmpt2 (λ s t, cvv) (λ s t, cvv) (λ s t, cmpt (λ x, co cc0 (co (cfv (cv s) chash) (cfv (cv t) chash) caddc) cfzo) (λ x, cif (wcel (cv x) (co cc0 (cfv (cv s) chash) cfzo)) (cfv (cv x) (cv s)) (cfv (co (cv x) (cfv (cv s) chash) cmin) (cv t))))
theorem df_concat : cconcat = cmpt2 (λ s t, cvv) (λ s t, cvv) (λ s t, cmpt (λ x, co cc0 (co (cfv (cv s) chash) (cfv (cv t) chash) caddc) cfzo) (λ x, cif (wcel (cv x) (co cc0 (cfv (cv s) chash) cfzo)) (cfv (cv x) (cv s)) (cfv (co (cv x) (cfv (cv s) chash) cmin) (cv t)))) := rfl
def cs1 (A : «class») : «class» := csn (cop cc0 (cfv A cid))
theorem df_s1 {A : «class»} : cs1 A = csn (cop cc0 (cfv A cid)) := rfl
def cshi : «class» := cmpt2 (λ f x, cvv) (λ f x, cc) (λ f x, copab (λ y z, wa (wcel (cv y) cc) (wbr (co (cv y) (cv x) cmin) (cv z) (cv f))))
theorem df_shft : cshi = cmpt2 (λ f x, cvv) (λ f x, cc) (λ f x, copab (λ y z, wa (wcel (cv y) cc) (wbr (co (cv y) (cv x) cmin) (cv z) (cv f)))) := rfl
def ccj : «class» := cmpt (λ x, cc) (λ x, crio (λ y, wa (wcel (co (cv x) (cv y) caddc) cr) (wcel (co ci (co (cv x) (cv y) cmin) cmul) cr)) (λ y, cc))
theorem df_cj : ccj = cmpt (λ x, cc) (λ x, crio (λ y, wa (wcel (co (cv x) (cv y) caddc) cr) (wcel (co ci (co (cv x) (cv y) cmin) cmul) cr)) (λ y, cc)) := rfl
def cre : «class» := cmpt (λ x, cc) (λ x, co (co (cv x) (cfv (cv x) ccj) caddc) c2 cdiv)
theorem df_re : cre = cmpt (λ x, cc) (λ x, co (co (cv x) (cfv (cv x) ccj) caddc) c2 cdiv) := rfl
def cim : «class» := cmpt (λ x, cc) (λ x, cfv (co (cv x) ci cdiv) cre)
theorem df_im : cim = cmpt (λ x, cc) (λ x, cfv (co (cv x) ci cdiv) cre) := rfl
def csqr : «class» := cmpt (λ x, cc) (λ x, crio (λ y, w3a (wceq (co (cv y) c2 cexp) (cv x)) (wbr cc0 (cfv (cv y) cre) cle) (wnel (co ci (cv y) cmul) crp)) (λ y, cc))
theorem df_sqr : csqr = cmpt (λ x, cc) (λ x, crio (λ y, w3a (wceq (co (cv y) c2 cexp) (cv x)) (wbr cc0 (cfv (cv y) cre) cle) (wnel (co ci (cv y) cmul) crp)) (λ y, cc)) := rfl
def cabs : «class» := cmpt (λ x, cc) (λ x, cfv (co (cv x) (cfv (cv x) ccj) cmul) csqr)
theorem df_abs : cabs = cmpt (λ x, cc) (λ x, cfv (co (cv x) (cfv (cv x) ccj) cmul) csqr) := rfl
def clsp : «class» := cmpt (λ x, cvv) (λ x, csup (crn (cmpt (λ k, cr) (λ k, csup (cin (cima (cv x) (co (cv k) cpnf cico)) cxr) cxr clt))) cxr (ccnv clt))
theorem df_limsup : clsp = cmpt (λ x, cvv) (λ x, csup (crn (cmpt (λ k, cr) (λ k, csup (cin (cima (cv x) (co (cv k) cpnf cico)) cxr) cxr clt))) cxr (ccnv clt)) := rfl
def cli : «class» := copab (λ f y, wa (wcel (cv y) cc) (wral (λ x, wrex (λ j, wral (λ k, wa (wcel (cfv (cv k) (cv f)) cc) (wbr (cfv (co (cfv (cv k) (cv f)) (cv y) cmin) cabs) (cv x) clt)) (λ k, cfv (cv j) cuz)) (λ j, cz)) (λ x, crp)))
theorem df_clim : cli = copab (λ f y, wa (wcel (cv y) cc) (wral (λ x, wrex (λ j, wral (λ k, wa (wcel (cfv (cv k) (cv f)) cc) (wbr (cfv (co (cfv (cv k) (cv f)) (cv y) cmin) cabs) (cv x) clt)) (λ k, cfv (cv j) cuz)) (λ j, cz)) (λ x, crp))) := rfl
def crli : «class» := copab (λ f x, wa (wa (wcel (cv f) (co cc cr cpm)) (wcel (cv x) cc)) (wral (λ y, wrex (λ z, wral (λ w, wi (wbr (cv z) (cv w) cle) (wbr (cfv (co (cfv (cv w) (cv f)) (cv x) cmin) cabs) (cv y) clt)) (λ w, cdm (cv f))) (λ z, cr)) (λ y, crp)))
theorem df_rlim : crli = copab (λ f x, wa (wa (wcel (cv f) (co cc cr cpm)) (wcel (cv x) cc)) (wral (λ y, wrex (λ z, wral (λ w, wi (wbr (cv z) (cv w) cle) (wbr (cfv (co (cfv (cv w) (cv f)) (cv x) cmin) cabs) (cv y) clt)) (λ w, cdm (cv f))) (λ z, cr)) (λ y, crp))) := rfl
def co1 : «class» := crab (λ f, wrex (λ x, wrex (λ m, wral (λ y, wbr (cfv (cfv (cv y) (cv f)) cabs) (cv m) cle) (λ y, cin (cdm (cv f)) (co (cv x) cpnf cico))) (λ m, cr)) (λ x, cr)) (λ f, co cc cr cpm)
theorem df_o1 : co1 = crab (λ f, wrex (λ x, wrex (λ m, wral (λ y, wbr (cfv (cfv (cv y) (cv f)) cabs) (cv m) cle) (λ y, cin (cdm (cv f)) (co (cv x) cpnf cico))) (λ m, cr)) (λ x, cr)) (λ f, co cc cr cpm) := rfl
def clo1 : «class» := crab (λ f, wrex (λ x, wrex (λ m, wral (λ y, wbr (cfv (cv y) (cv f)) (cv m) cle) (λ y, cin (cdm (cv f)) (co (cv x) cpnf cico))) (λ m, cr)) (λ x, cr)) (λ f, co cr cr cpm)
theorem df_lo1 : clo1 = crab (λ f, wrex (λ x, wrex (λ m, wral (λ y, wbr (cfv (cv y) (cv f)) (cv m) cle) (λ y, cin (cdm (cv f)) (co (cv x) cpnf cico))) (λ m, cr)) (λ x, cr)) (λ f, co cr cr cpm) := rfl
def csu (A : «class») (B : setvar → «class») : «class» := cio (λ x, wo (wrex (λ m, wa (wss A (cfv (cv m) cuz)) (wbr (cseq caddc (cmpt (λ n, cz) (λ n, cif (wcel (cv n) A) (csb (cv n) (λ k, B k)) cc0)) (cv m)) (cv x) cli)) (λ m, cz)) (wrex (λ m, wex (λ f, wa (wf1o (co c1 (cv m) cfz) A (cv f)) (wceq (cv x) (cfv (cv m) (cseq caddc (cmpt (λ n, cn) (λ n, csb (cfv (cv n) (cv f)) (λ k, B k))) c1))))) (λ m, cn)))
theorem df_sum {A B : setvar → «class»} (k : setvar) : csu (A k) (λ k, B k) = cio (λ x, wo (wrex (λ m, wa (wss (A k) (cfv (cv m) cuz)) (wbr (cseq caddc (cmpt (λ n, cz) (λ n, cif (wcel (cv n) (A k)) (csb (cv n) (λ k, B k)) cc0)) (cv m)) (cv x) cli)) (λ m, cz)) (wrex (λ m, wex (λ f, wa (wf1o (co c1 (cv m) cfz) (A k) (cv f)) (wceq (cv x) (cfv (cv m) (cseq caddc (cmpt (λ n, cn) (λ n, csb (cfv (cv n) (cv f)) (λ k, B k))) c1))))) (λ m, cn))) := rfl
def ce : «class» := cmpt (λ x, cc) (λ x, csu cn0 (λ k, co (co (cv x) (cv k) cexp) (cfv (cv k) cfa) cdiv))
theorem df_ef : ce = cmpt (λ x, cc) (λ x, csu cn0 (λ k, co (co (cv x) (cv k) cexp) (cfv (cv k) cfa) cdiv)) := rfl
def ceu : «class» := cfv c1 ce
theorem df_e : ceu = cfv c1 ce := rfl
def csin : «class» := cmpt (λ x, cc) (λ x, co (co (cfv (co ci (cv x) cmul) ce) (cfv (co (cneg ci) (cv x) cmul) ce) cmin) (co c2 ci cmul) cdiv)
theorem df_sin : csin = cmpt (λ x, cc) (λ x, co (co (cfv (co ci (cv x) cmul) ce) (cfv (co (cneg ci) (cv x) cmul) ce) cmin) (co c2 ci cmul) cdiv) := rfl
def ccos : «class» := cmpt (λ x, cc) (λ x, co (co (cfv (co ci (cv x) cmul) ce) (cfv (co (cneg ci) (cv x) cmul) ce) caddc) c2 cdiv)
theorem df_cos : ccos = cmpt (λ x, cc) (λ x, co (co (cfv (co ci (cv x) cmul) ce) (cfv (co (cneg ci) (cv x) cmul) ce) caddc) c2 cdiv) := rfl
def ctan : «class» := cmpt (λ x, cima (ccnv ccos) (cdif cc (csn cc0))) (λ x, co (cfv (cv x) csin) (cfv (cv x) ccos) cdiv)
theorem df_tan : ctan = cmpt (λ x, cima (ccnv ccos) (cdif cc (csn cc0))) (λ x, co (cfv (cv x) csin) (cfv (cv x) ccos) cdiv) := rfl
def cpi : «class» := csup (cin crp (cima (ccnv csin) (csn cc0))) cr (ccnv clt)
theorem df_pi : cpi = csup (cin crp (cima (ccnv csin) (csn cc0))) cr (ccnv clt) := rfl
def cdivides : «class» := copab (λ x y, wa (wa (wcel (cv x) cz) (wcel (cv y) cz)) (wrex (λ n, wceq (co (cv n) (cv x) cmul) (cv y)) (λ n, cz)))
theorem df_dvds : cdivides = copab (λ x y, wa (wa (wcel (cv x) cz) (wcel (cv y) cz)) (wrex (λ n, wceq (co (cv n) (cv x) cmul) (cv y)) (λ n, cz))) := rfl
def cgcd : «class» := cmpt2 (λ x y, cz) (λ x y, cz) (λ x y, cif (wa (wceq (cv x) cc0) (wceq (cv y) cc0)) cc0 (csup (crab (λ n, wa (wbr (cv n) (cv x) cdivides) (wbr (cv n) (cv y) cdivides)) (λ n, cz)) cr clt))
theorem df_gcd : cgcd = cmpt2 (λ x y, cz) (λ x y, cz) (λ x y, cif (wa (wceq (cv x) cc0) (wceq (cv y) cc0)) cc0 (csup (crab (λ n, wa (wbr (cv n) (cv x) cdivides) (wbr (cv n) (cv y) cdivides)) (λ n, cz)) cr clt)) := rfl
def cprime : «class» := crab (λ p, wbr (crab (λ n, wbr (cv n) (cv p) cdivides) (λ n, cn)) c2o cen) (λ p, cn)
theorem df_prm : cprime = crab (λ p, wbr (crab (λ n, wbr (cv n) (cv p) cdivides) (λ n, cn)) c2o cen) (λ p, cn) := rfl
def cnumer : «class» := cmpt (λ y, cq) (λ y, cfv (crio (λ x, wa (wceq (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cgcd) c1) (wceq (cv y) (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cdiv))) (λ x, cxp cz cn)) c1st)
theorem df_numer : cnumer = cmpt (λ y, cq) (λ y, cfv (crio (λ x, wa (wceq (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cgcd) c1) (wceq (cv y) (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cdiv))) (λ x, cxp cz cn)) c1st) := rfl
def cdenom : «class» := cmpt (λ y, cq) (λ y, cfv (crio (λ x, wa (wceq (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cgcd) c1) (wceq (cv y) (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cdiv))) (λ x, cxp cz cn)) c2nd)
theorem df_denom : cdenom = cmpt (λ y, cq) (λ y, cfv (crio (λ x, wa (wceq (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cgcd) c1) (wceq (cv y) (co (cfv (cv x) c1st) (cfv (cv x) c2nd) cdiv))) (λ x, cxp cz cn)) c2nd) := rfl
def cphi : «class» := cmpt (λ n, cn) (λ n, cfv (crab (λ x, wceq (co (cv x) (cv n) cgcd) c1) (λ x, co c1 (cv n) cfz)) chash)
theorem df_phi : cphi = cmpt (λ n, cn) (λ n, cfv (crab (λ x, wceq (co (cv x) (cv n) cgcd) c1) (λ x, co c1 (cv n) cfz)) chash) := rfl
def cpc : «class» := cmpt2 (λ p r, cprime) (λ p r, cq) (λ p r, cif (wceq (cv r) cc0) cpnf (cio (λ z, wrex (λ x, wrex (λ y, wa (wceq (cv r) (co (cv x) (cv y) cdiv)) (wceq (cv z) (co (csup (crab (λ n, wbr (co (cv p) (cv n) cexp) (cv x) cdivides) (λ n, cn0)) cr clt) (csup (crab (λ n, wbr (co (cv p) (cv n) cexp) (cv y) cdivides) (λ n, cn0)) cr clt) cmin))) (λ y, cn)) (λ x, cz))))
theorem df_pc : cpc = cmpt2 (λ p r, cprime) (λ p r, cq) (λ p r, cif (wceq (cv r) cc0) cpnf (cio (λ z, wrex (λ x, wrex (λ y, wa (wceq (cv r) (co (cv x) (cv y) cdiv)) (wceq (cv z) (co (csup (crab (λ n, wbr (co (cv p) (cv n) cexp) (cv x) cdivides) (λ n, cn0)) cr clt) (csup (crab (λ n, wbr (co (cv p) (cv n) cexp) (cv y) cdivides) (λ n, cn0)) cr clt) cmin))) (λ y, cn)) (λ x, cz)))) := rfl
def cstr : «class» := copab (λ f x, w3a (wcel (cv x) (cin cle (cxp cn cn))) (wfun (cdif (cv f) (csn c0))) (wss (cdm (cv f)) (cfv (cv x) cfz)))
theorem df_struct : cstr = copab (λ f x, w3a (wcel (cv x) (cin cle (cxp cn cn))) (wfun (cdif (cv f) (csn c0))) (wss (cdm (cv f)) (cfv (cv x) cfz))) := rfl
def cnx : «class» := cres cid cn
theorem df_ndx : cnx = cres cid cn := rfl
def csts : «class» := cmpt2 (λ s e, cvv) (λ s e, cvv) (λ s e, cun (cres (cv s) (cdif cvv (cdm (csn (cv e))))) (csn (cv e)))
theorem df_sets : csts = cmpt2 (λ s e, cvv) (λ s e, cvv) (λ s e, cun (cres (cv s) (cdif cvv (cdm (csn (cv e))))) (csn (cv e))) := rfl
def cslot (A : «class») : «class» := cmpt (λ x, cvv) (λ x, cfv A (cv x))
theorem df_slot {A : «class»} : cslot A = cmpt (λ x, cvv) (λ x, cfv A (cv x)) := rfl
def cbs : «class» := cslot c1
theorem df_base : cbs = cslot c1 := rfl
def cress : «class» := cmpt2 (λ w x, cvv) (λ w x, cvv) (λ w x, cif (wss (cfv (cv w) cbs) (cv x)) (cv w) (co (cv w) (cop (cfv cnx cbs) (cin (cv x) (cfv (cv w) cbs))) csts))
theorem df_ress : cress = cmpt2 (λ w x, cvv) (λ w x, cvv) (λ w x, cif (wss (cfv (cv w) cbs) (cv x)) (cv w) (co (cv w) (cop (cfv cnx cbs) (cin (cv x) (cfv (cv w) cbs))) csts)) := rfl
def cplusg : «class» := cslot c2
theorem df_plusg : cplusg = cslot c2 := rfl
def cmulr : «class» := cslot c3
theorem df_mulr : cmulr = cslot c3 := rfl
def cstv : «class» := cslot c4
theorem df_starv : cstv = cslot c4 := rfl
def csca : «class» := cslot c5
theorem df_sca : csca = cslot c5 := rfl
def cvsca : «class» := cslot c6
theorem df_vsca : cvsca = cslot c6 := rfl
def cts : «class» := cslot c9
theorem df_tset : cts = cslot c9 := rfl
def cple : «class» := cslot c10
theorem df_ple : cple = cslot c10 := rfl
def cds : «class» := cslot (cdc c1 c2)
theorem df_ds : cds = cslot (cdc c1 c2) := rfl
def cunif : «class» := cslot (cdc c1 c3)
theorem df_unif : cunif = cslot (cdc c1 c3) := rfl
def chom : «class» := cslot (cdc c1 c4)
theorem df_hom : chom = cslot (cdc c1 c4) := rfl
def cco : «class» := cslot (cdc c1 c5)
theorem df_cco : cco = cslot (cdc c1 c5) := rfl
def crest : «class» := cmpt2 (λ j x, cvv) (λ j x, cvv) (λ j x, crn (cmpt (λ y, cv j) (λ y, cin (cv y) (cv x))))
theorem df_rest : crest = cmpt2 (λ j x, cvv) (λ j x, cvv) (λ j x, crn (cmpt (λ y, cv j) (λ y, cin (cv y) (cv x)))) := rfl
def ctopn : «class» := cmpt (λ w, cvv) (λ w, co (cfv (cv w) cts) (cfv (cv w) cbs) crest)
theorem df_topn : ctopn = cmpt (λ w, cvv) (λ w, co (cfv (cv w) cts) (cfv (cv w) cbs) crest) := rfl
def ctg : «class» := cmpt (λ x, cvv) (λ x, cab (λ y, wss (cv y) (cuni (cin (cv x) (cpw (cv y))))))
theorem df_topgen : ctg = cmpt (λ x, cvv) (λ x, cab (λ y, wss (cv y) (cuni (cin (cv x) (cpw (cv y)))))) := rfl
def cpt : «class» := cmpt (λ f, cvv) (λ f, cfv (cab (λ x, wex (λ g, wa (w3a (wfn (cv g) (cdm (cv f))) (wral (λ y, wcel (cfv (cv y) (cv g)) (cfv (cv y) (cv f))) (λ y, cdm (cv f))) (wrex (λ z, wral (λ y, wceq (cfv (cv y) (cv g)) (cuni (cfv (cv y) (cv f)))) (λ y, cdif (cdm (cv f)) (cv z))) (λ z, cfn))) (wceq (cv x) (cixp (λ y, cdm (cv f)) (λ y, cfv (cv y) (cv g))))))) ctg)
theorem df_pt : cpt = cmpt (λ f, cvv) (λ f, cfv (cab (λ x, wex (λ g, wa (w3a (wfn (cv g) (cdm (cv f))) (wral (λ y, wcel (cfv (cv y) (cv g)) (cfv (cv y) (cv f))) (λ y, cdm (cv f))) (wrex (λ z, wral (λ y, wceq (cfv (cv y) (cv g)) (cuni (cfv (cv y) (cv f)))) (λ y, cdif (cdm (cv f)) (cv z))) (λ z, cfn))) (wceq (cv x) (cixp (λ y, cdm (cv f)) (λ y, cfv (cv y) (cv g))))))) ctg) := rfl
def cprds : «class» := cmpt2 (λ s r, cvv) (λ s r, cvv) (λ s r, csb (cixp (λ x, cdm (cv r)) (λ x, cfv (cfv (cv x) (cv r)) cbs)) (λ v, csb (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cixp (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) chom)))) (λ h, cun (cun (ctp (cop (cfv cnx cbs) (cv v)) (cop (cfv cnx cplusg) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cplusg))))) (cop (cfv cnx cmulr) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cmulr)))))) (cpr (cop (cfv cnx csca) (cv s)) (cop (cfv cnx cvsca) (cmpt2 (λ f g, cfv (cv s) cbs) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cv f) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cvsca))))))) (cun (ctp (cop (cfv cnx cts) (cfv (ccom ctopn (cv r)) cpt)) (cop (cfv cnx cple) (copab (λ f g, wa (wss (cpr (cv f) (cv g)) (cv v)) (wral (λ x, wbr (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cple)) (λ x, cdm (cv r)))))) (cop (cfv cnx cds) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, csup (cun (crn (cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cds)))) (csn cc0)) cxr clt)))) (cpr (cop (cfv cnx chom) (cv h)) (cop (cfv cnx cco) (cmpt2 (λ a c, cxp (cv v) (cv v)) (λ a c, cv v) (λ a c, cmpt2 (λ d e, co (cv c) (cfv (cv a) c2nd) (cv h)) (λ d e, cfv (cv a) (cv h)) (λ d e, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv d)) (cfv (cv x) (cv e)) (co (cop (cfv (cv x) (cfv (cv a) c1st)) (cfv (cv x) (cfv (cv a) c2nd))) (cfv (cv x) (cv c)) (cfv (cfv (cv x) (cv r)) cco))))))))))))
theorem df_prds : cprds = cmpt2 (λ s r, cvv) (λ s r, cvv) (λ s r, csb (cixp (λ x, cdm (cv r)) (λ x, cfv (cfv (cv x) (cv r)) cbs)) (λ v, csb (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cixp (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) chom)))) (λ h, cun (cun (ctp (cop (cfv cnx cbs) (cv v)) (cop (cfv cnx cplusg) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cplusg))))) (cop (cfv cnx cmulr) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cmulr)))))) (cpr (cop (cfv cnx csca) (cv s)) (cop (cfv cnx cvsca) (cmpt2 (λ f g, cfv (cv s) cbs) (λ f g, cv v) (λ f g, cmpt (λ x, cdm (cv r)) (λ x, co (cv f) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cvsca))))))) (cun (ctp (cop (cfv cnx cts) (cfv (ccom ctopn (cv r)) cpt)) (cop (cfv cnx cple) (copab (λ f g, wa (wss (cpr (cv f) (cv g)) (cv v)) (wral (λ x, wbr (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cple)) (λ x, cdm (cv r)))))) (cop (cfv cnx cds) (cmpt2 (λ f g, cv v) (λ f g, cv v) (λ f g, csup (cun (crn (cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv f)) (cfv (cv x) (cv g)) (cfv (cfv (cv x) (cv r)) cds)))) (csn cc0)) cxr clt)))) (cpr (cop (cfv cnx chom) (cv h)) (cop (cfv cnx cco) (cmpt2 (λ a c, cxp (cv v) (cv v)) (λ a c, cv v) (λ a c, cmpt2 (λ d e, co (cv c) (cfv (cv a) c2nd) (cv h)) (λ d e, cfv (cv a) (cv h)) (λ d e, cmpt (λ x, cdm (cv r)) (λ x, co (cfv (cv x) (cv d)) (cfv (cv x) (cv e)) (co (cop (cfv (cv x) (cfv (cv a) c1st)) (cfv (cv x) (cfv (cv a) c2nd))) (cfv (cv x) (cv c)) (cfv (cfv (cv x) (cv r)) cco)))))))))))) := rfl
def cordt : «class» := cmpt (λ r, cvv) (λ r, cfv (cfv (cun (csn (cdm (cv r))) (crn (cun (cmpt (λ x, cdm (cv r)) (λ x, crab (λ y, wn (wbr (cv y) (cv x) (cv r))) (λ y, cdm (cv r)))) (cmpt (λ x, cdm (cv r)) (λ x, crab (λ y, wn (wbr (cv x) (cv y) (cv r))) (λ y, cdm (cv r))))))) cfi) ctg)
theorem df_ordt : cordt = cmpt (λ r, cvv) (λ r, cfv (cfv (cun (csn (cdm (cv r))) (crn (cun (cmpt (λ x, cdm (cv r)) (λ x, crab (λ y, wn (wbr (cv y) (cv x) (cv r))) (λ y, cdm (cv r)))) (cmpt (λ x, cdm (cv r)) (λ x, crab (λ y, wn (wbr (cv x) (cv y) (cv r))) (λ y, cdm (cv r))))))) cfi) ctg) := rfl
def cxrs : «class» := cun (ctp (cop (cfv cnx cbs) cxr) (cop (cfv cnx cplusg) cxad) (cop (cfv cnx cmulr) cxmu)) (ctp (cop (cfv cnx cts) (cfv cle cordt)) (cop (cfv cnx cple) cle) (cop (cfv cnx cds) (cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wbr (cv x) (cv y) cle) (co (cv y) (cxne (cv x)) cxad) (co (cv x) (cxne (cv y)) cxad)))))
theorem df_xrs : cxrs = cun (ctp (cop (cfv cnx cbs) cxr) (cop (cfv cnx cplusg) cxad) (cop (cfv cnx cmulr) cxmu)) (ctp (cop (cfv cnx cts) (cfv cle cordt)) (cop (cfv cnx cple) cle) (cop (cfv cnx cds) (cmpt2 (λ x y, cxr) (λ x y, cxr) (λ x y, cif (wbr (cv x) (cv y) cle) (co (cv y) (cxne (cv x)) cxad) (co (cv x) (cxne (cv y)) cxad))))) := rfl
def c0g : «class» := cmpt (λ g, cvv) (λ g, cio (λ e, wa (wcel (cv e) (cfv (cv g) cbs)) (wral (λ x, wa (wceq (co (cv e) (cv x) (cfv (cv g) cplusg)) (cv x)) (wceq (co (cv x) (cv e) (cfv (cv g) cplusg)) (cv x))) (λ x, cfv (cv g) cbs))))
theorem df_0g : c0g = cmpt (λ g, cvv) (λ g, cio (λ e, wa (wcel (cv e) (cfv (cv g) cbs)) (wral (λ x, wa (wceq (co (cv e) (cv x) (cfv (cv g) cplusg)) (cv x)) (wceq (co (cv x) (cv e) (cfv (cv g) cplusg)) (cv x))) (λ x, cfv (cv g) cbs)))) := rfl
def cgsu : «class» := cmpt2 (λ w f, cvv) (λ w f, cvv) (λ w f, csb (crab (λ x, wral (λ y, wa (wceq (co (cv x) (cv y) (cfv (cv w) cplusg)) (cv y)) (wceq (co (cv y) (cv x) (cfv (cv w) cplusg)) (cv y))) (λ y, cfv (cv w) cbs)) (λ x, cfv (cv w) cbs)) (λ o, cif (wss (crn (cv f)) (cv o)) (cfv (cv w) c0g) (cif (wcel (cdm (cv f)) (crn cfz)) (cio (λ x, wex (λ m, wrex (λ n, wa (wceq (cdm (cv f)) (co (cv m) (cv n) cfz)) (wceq (cv x) (cfv (cv n) (cseq (cfv (cv w) cplusg) (cv f) (cv m))))) (λ n, cfv (cv m) cuz)))) (cio (λ x, wex (λ g, wsbc (λ y, wa (wf1o (co c1 (cfv (cv y) chash) cfz) (cv y) (cv g)) (wceq (cv x) (cfv (cfv (cv y) chash) (cseq (cfv (cv w) cplusg) (ccom (cv f) (cv g)) c1)))) (cima (ccnv (cv f)) (cdif cvv (cv o)))))))))
theorem df_gsum : cgsu = cmpt2 (λ w f, cvv) (λ w f, cvv) (λ w f, csb (crab (λ x, wral (λ y, wa (wceq (co (cv x) (cv y) (cfv (cv w) cplusg)) (cv y)) (wceq (co (cv y) (cv x) (cfv (cv w) cplusg)) (cv y))) (λ y, cfv (cv w) cbs)) (λ x, cfv (cv w) cbs)) (λ o, cif (wss (crn (cv f)) (cv o)) (cfv (cv w) c0g) (cif (wcel (cdm (cv f)) (crn cfz)) (cio (λ x, wex (λ m, wrex (λ n, wa (wceq (cdm (cv f)) (co (cv m) (cv n) cfz)) (wceq (cv x) (cfv (cv n) (cseq (cfv (cv w) cplusg) (cv f) (cv m))))) (λ n, cfv (cv m) cuz)))) (cio (λ x, wex (λ g, wsbc (λ y, wa (wf1o (co c1 (cfv (cv y) chash) cfz) (cv y) (cv g)) (wceq (cv x) (cfv (cfv (cv y) chash) (cseq (cfv (cv w) cplusg) (ccom (cv f) (cv g)) c1)))) (cima (ccnv (cv f)) (cdif cvv (cv o))))))))) := rfl
def cqtop : «class» := cmpt2 (λ j f, cvv) (λ j f, cvv) (λ j f, crab (λ s, wcel (cin (cima (ccnv (cv f)) (cv s)) (cuni (cv j))) (cv j)) (λ s, cpw (cima (cv f) (cuni (cv j)))))
theorem df_qtop : cqtop = cmpt2 (λ j f, cvv) (λ j f, cvv) (λ j f, crab (λ s, wcel (cin (cima (ccnv (cv f)) (cv s)) (cuni (cv j))) (cv j)) (λ s, cpw (cima (cv f) (cuni (cv j))))) := rfl
def cimas : «class» := cmpt2 (λ f r, cvv) (λ f r, cvv) (λ f r, csb (cfv (cv r) cbs) (λ v, cun (cun (ctp (cop (cfv cnx cbs) (crn (cv f))) (cop (cfv cnx cplusg) (ciun (λ p, cv v) (λ p, ciun (λ q, cv v) (λ q, csn (cop (cop (cfv (cv p) (cv f)) (cfv (cv q) (cv f))) (cfv (co (cv p) (cv q) (cfv (cv r) cplusg)) (cv f))))))) (cop (cfv cnx cmulr) (ciun (λ p, cv v) (λ p, ciun (λ q, cv v) (λ q, csn (cop (cop (cfv (cv p) (cv f)) (cfv (cv q) (cv f))) (cfv (co (cv p) (cv q) (cfv (cv r) cmulr)) (cv f)))))))) (cpr (cop (cfv cnx csca) (cfv (cv r) csca)) (cop (cfv cnx cvsca) (ciun (λ q, cv v) (λ q, cmpt2 (λ p x, cfv (cfv (cv r) csca) cbs) (λ p x, csn (cfv (cv q) (cv f))) (λ p x, cfv (co (cv p) (cv q) (cfv (cv r) cvsca)) (cv f))))))) (ctp (cop (cfv cnx cts) (co (cfv (cv r) ctopn) (cv f) cqtop)) (cop (cfv cnx cple) (ccom (ccom (cv f) (cfv (cv r) cple)) (ccnv (cv f)))) (cop (cfv cnx cds) (cmpt2 (λ x y, crn (cv f)) (λ x y, crn (cv f)) (λ x y, csup (ciun (λ n, cn) (λ n, crn (cmpt (λ g, crab (λ h, w3a (wceq (cfv (cfv (cfv c1 (cv h)) c1st) (cv f)) (cv x)) (wceq (cfv (cfv (cfv (cv n) (cv h)) c2nd) (cv f)) (cv y)) (wral (λ i, wceq (cfv (cfv (cfv (cv i) (cv h)) c2nd) (cv f)) (cfv (cfv (cfv (co (cv i) c1 caddc) (cv h)) c1st) (cv f))) (λ i, co c1 (co (cv n) c1 cmin) cfz))) (λ h, co (cxp (cv v) (cv v)) (co c1 (cv n) cfz) cmap)) (λ g, co cxrs (ccom (cfv (cv r) cds) (cv g)) cgsu)))) cxr (ccnv clt)))))))
theorem df_imas : cimas = cmpt2 (λ f r, cvv) (λ f r, cvv) (λ f r, csb (cfv (cv r) cbs) (λ v, cun (cun (ctp (cop (cfv cnx cbs) (crn (cv f))) (cop (cfv cnx cplusg) (ciun (λ p, cv v) (λ p, ciun (λ q, cv v) (λ q, csn (cop (cop (cfv (cv p) (cv f)) (cfv (cv q) (cv f))) (cfv (co (cv p) (cv q) (cfv (cv r) cplusg)) (cv f))))))) (cop (cfv cnx cmulr) (ciun (λ p, cv v) (λ p, ciun (λ q, cv v) (λ q, csn (cop (cop (cfv (cv p) (cv f)) (cfv (cv q) (cv f))) (cfv (co (cv p) (cv q) (cfv (cv r) cmulr)) (cv f)))))))) (cpr (cop (cfv cnx csca) (cfv (cv r) csca)) (cop (cfv cnx cvsca) (ciun (λ q, cv v) (λ q, cmpt2 (λ p x, cfv (cfv (cv r) csca) cbs) (λ p x, csn (cfv (cv q) (cv f))) (λ p x, cfv (co (cv p) (cv q) (cfv (cv r) cvsca)) (cv f))))))) (ctp (cop (cfv cnx cts) (co (cfv (cv r) ctopn) (cv f) cqtop)) (cop (cfv cnx cple) (ccom (ccom (cv f) (cfv (cv r) cple)) (ccnv (cv f)))) (cop (cfv cnx cds) (cmpt2 (λ x y, crn (cv f)) (λ x y, crn (cv f)) (λ x y, csup (ciun (λ n, cn) (λ n, crn (cmpt (λ g, crab (λ h, w3a (wceq (cfv (cfv (cfv c1 (cv h)) c1st) (cv f)) (cv x)) (wceq (cfv (cfv (cfv (cv n) (cv h)) c2nd) (cv f)) (cv y)) (wral (λ i, wceq (cfv (cfv (cfv (cv i) (cv h)) c2nd) (cv f)) (cfv (cfv (cfv (co (cv i) c1 caddc) (cv h)) c1st) (cv f))) (λ i, co c1 (co (cv n) c1 cmin) cfz))) (λ h, co (cxp (cv v) (cv v)) (co c1 (cv n) cfz) cmap)) (λ g, co cxrs (ccom (cfv (cv r) cds) (cv g)) cgsu)))) cxr (ccnv clt))))))) := rfl
def cqus : «class» := cmpt2 (λ r e, cvv) (λ r e, cvv) (λ r e, co (cmpt (λ x, cfv (cv r) cbs) (λ x, cec (cv x) (cv e))) (cv r) cimas)
theorem df_divs : cqus = cmpt2 (λ r e, cvv) (λ r e, cvv) (λ r e, co (cmpt (λ x, cfv (cv r) cbs) (λ x, cec (cv x) (cv e))) (cv r) cimas) := rfl
def cxps : «class» := cmpt2 (λ r s, cvv) (λ r s, cvv) (λ r s, co (ccnv (cmpt2 (λ x y, cfv (cv r) cbs) (λ x y, cfv (cv s) cbs) (λ x y, ccnv (co (csn (cv x)) (csn (cv y)) ccda)))) (co (cfv (cv r) csca) (ccnv (co (csn (cv r)) (csn (cv s)) ccda)) cprds) cimas)
theorem df_xps : cxps = cmpt2 (λ r s, cvv) (λ r s, cvv) (λ r s, co (ccnv (cmpt2 (λ x y, cfv (cv r) cbs) (λ x y, cfv (cv s) cbs) (λ x y, ccnv (co (csn (cv x)) (csn (cv y)) ccda)))) (co (cfv (cv r) csca) (ccnv (co (csn (cv r)) (csn (cv s)) ccda)) cprds) cimas) := rfl
def cmre : «class» := cmpt (λ x, cvv) (λ x, crab (λ c, wa (wcel (cv x) (cv c)) (wral (λ s, wi (wne (cv s) c0) (wcel (cint (cv s)) (cv c))) (λ s, cpw (cv c)))) (λ c, cpw (cpw (cv x))))
theorem df_mre : cmre = cmpt (λ x, cvv) (λ x, crab (λ c, wa (wcel (cv x) (cv c)) (wral (λ s, wi (wne (cv s) c0) (wcel (cint (cv s)) (cv c))) (λ s, cpw (cv c)))) (λ c, cpw (cpw (cv x)))) := rfl
def cmrc : «class» := cmpt (λ c, cuni (crn cmre)) (λ c, cmpt (λ x, cpw (cuni (cv c))) (λ x, cint (crab (λ s, wss (cv x) (cv s)) (λ s, cv c))))
theorem df_mrc : cmrc = cmpt (λ c, cuni (crn cmre)) (λ c, cmpt (λ x, cpw (cuni (cv c))) (λ x, cint (crab (λ s, wss (cv x) (cv s)) (λ s, cv c)))) := rfl
def cacs : «class» := cmpt (λ x, cvv) (λ x, crab (λ c, wex (λ f, wa (wf (cpw (cv x)) (cpw (cv x)) (cv f)) (wral (λ s, wb (wcel (cv s) (cv c)) (wss (cuni (cima (cv f) (cin (cpw (cv s)) cfn))) (cv s))) (λ s, cpw (cv x))))) (λ c, cfv (cv x) cmre))
theorem df_acs : cacs = cmpt (λ x, cvv) (λ x, crab (λ c, wex (λ f, wa (wf (cpw (cv x)) (cpw (cv x)) (cv f)) (wral (λ s, wb (wcel (cv s) (cv c)) (wss (cuni (cima (cv f) (cin (cpw (cv s)) cfn))) (cv s))) (λ s, cpw (cv x))))) (λ c, cfv (cv x) cmre)) := rfl
def cmnd : «class» := cab (λ g, wsbc (λ b, wsbc (λ p, wa (wral (λ x, wral (λ y, wral (λ z, wa (wcel (co (cv x) (cv y) (cv p)) (cv b)) (wceq (co (co (cv x) (cv y) (cv p)) (cv z) (cv p)) (co (cv x) (co (cv y) (cv z) (cv p)) (cv p)))) (λ z, cv b)) (λ y, cv b)) (λ x, cv b)) (wrex (λ e, wral (λ x, wa (wceq (co (cv e) (cv x) (cv p)) (cv x)) (wceq (co (cv x) (cv e) (cv p)) (cv x))) (λ x, cv b)) (λ e, cv b))) (cfv (cv g) cplusg)) (cfv (cv g) cbs))
theorem df_mnd : cmnd = cab (λ g, wsbc (λ b, wsbc (λ p, wa (wral (λ x, wral (λ y, wral (λ z, wa (wcel (co (cv x) (cv y) (cv p)) (cv b)) (wceq (co (co (cv x) (cv y) (cv p)) (cv z) (cv p)) (co (cv x) (co (cv y) (cv z) (cv p)) (cv p)))) (λ z, cv b)) (λ y, cv b)) (λ x, cv b)) (wrex (λ e, wral (λ x, wa (wceq (co (cv e) (cv x) (cv p)) (cv x)) (wceq (co (cv x) (cv e) (cv p)) (cv x))) (λ x, cv b)) (λ e, cv b))) (cfv (cv g) cplusg)) (cfv (cv g) cbs)) := rfl
def cgrp : «class» := crab (λ g, wral (λ a, wrex (λ m, wceq (co (cv m) (cv a) (cfv (cv g) cplusg)) (cfv (cv g) c0g)) (λ m, cfv (cv g) cbs)) (λ a, cfv (cv g) cbs)) (λ g, cmnd)
theorem df_grp : cgrp = crab (λ g, wral (λ a, wrex (λ m, wceq (co (cv m) (cv a) (cfv (cv g) cplusg)) (cfv (cv g) c0g)) (λ m, cfv (cv g) cbs)) (λ a, cfv (cv g) cbs)) (λ g, cmnd) := rfl
def cminusg : «class» := cmpt (λ g, cvv) (λ g, cmpt (λ x, cfv (cv g) cbs) (λ x, crio (λ w, wceq (co (cv w) (cv x) (cfv (cv g) cplusg)) (cfv (cv g) c0g)) (λ w, cfv (cv g) cbs)))
theorem df_minusg : cminusg = cmpt (λ g, cvv) (λ g, cmpt (λ x, cfv (cv g) cbs) (λ x, crio (λ w, wceq (co (cv w) (cv x) (cfv (cv g) cplusg)) (cfv (cv g) c0g)) (λ w, cfv (cv g) cbs))) := rfl
def csg : «class» := cmpt (λ g, cvv) (λ g, cmpt2 (λ x y, cfv (cv g) cbs) (λ x y, cfv (cv g) cbs) (λ x y, co (cv x) (cfv (cv y) (cfv (cv g) cminusg)) (cfv (cv g) cplusg)))
theorem df_sbg : csg = cmpt (λ g, cvv) (λ g, cmpt2 (λ x y, cfv (cv g) cbs) (λ x y, cfv (cv g) cbs) (λ x y, co (cv x) (cfv (cv y) (cfv (cv g) cminusg)) (cfv (cv g) cplusg))) := rfl
def cmg : «class» := cmpt (λ g, cvv) (λ g, cmpt2 (λ n x, cz) (λ n x, cfv (cv g) cbs) (λ n x, cif (wceq (cv n) cc0) (cfv (cv g) c0g) (csb (cseq (cfv (cv g) cplusg) (cxp cn (csn (cv x))) c1) (λ s, cif (wbr cc0 (cv n) clt) (cfv (cv n) (cv s)) (cfv (cfv (cneg (cv n)) (cv s)) (cfv (cv g) cminusg))))))
theorem df_mulg : cmg = cmpt (λ g, cvv) (λ g, cmpt2 (λ n x, cz) (λ n x, cfv (cv g) cbs) (λ n x, cif (wceq (cv n) cc0) (cfv (cv g) c0g) (csb (cseq (cfv (cv g) cplusg) (cxp cn (csn (cv x))) c1) (λ s, cif (wbr cc0 (cv n) clt) (cfv (cv n) (cv s)) (cfv (cfv (cneg (cv n)) (cv s)) (cfv (cv g) cminusg)))))) := rfl
def cmhm : «class» := cmpt2 (λ s t, cmnd) (λ s t, cmnd) (λ s t, crab (λ f, wa (wral (λ x, wral (λ y, wceq (cfv (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv t) cplusg))) (λ y, cfv (cv s) cbs)) (λ x, cfv (cv s) cbs)) (wceq (cfv (cfv (cv s) c0g) (cv f)) (cfv (cv t) c0g))) (λ f, co (cfv (cv t) cbs) (cfv (cv s) cbs) cmap))
theorem df_mhm : cmhm = cmpt2 (λ s t, cmnd) (λ s t, cmnd) (λ s t, crab (λ f, wa (wral (λ x, wral (λ y, wceq (cfv (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv t) cplusg))) (λ y, cfv (cv s) cbs)) (λ x, cfv (cv s) cbs)) (wceq (cfv (cfv (cv s) c0g) (cv f)) (cfv (cv t) c0g))) (λ f, co (cfv (cv t) cbs) (cfv (cv s) cbs) cmap)) := rfl
def csubmnd : «class» := cmpt (λ s, cmnd) (λ s, crab (λ t, wa (wcel (cfv (cv s) c0g) (cv t)) (wral (λ x, wral (λ y, wcel (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv t)) (λ y, cv t)) (λ x, cv t))) (λ t, cpw (cfv (cv s) cbs)))
theorem df_submnd : csubmnd = cmpt (λ s, cmnd) (λ s, crab (λ t, wa (wcel (cfv (cv s) c0g) (cv t)) (wral (λ x, wral (λ y, wcel (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv t)) (λ y, cv t)) (λ x, cv t))) (λ t, cpw (cfv (cv s) cbs))) := rfl
def csubg : «class» := cmpt (λ w, cgrp) (λ w, crab (λ s, wcel (co (cv w) (cv s) cress) cgrp) (λ s, cpw (cfv (cv w) cbs)))
theorem df_subg : csubg = cmpt (λ w, cgrp) (λ w, crab (λ s, wcel (co (cv w) (cv s) cress) cgrp) (λ s, cpw (cfv (cv w) cbs))) := rfl
def cnsg : «class» := cmpt (λ w, cgrp) (λ w, crab (λ s, wsbc (λ b, wsbc (λ p, wral (λ x, wral (λ y, wb (wcel (co (cv x) (cv y) (cv p)) (cv s)) (wcel (co (cv y) (cv x) (cv p)) (cv s))) (λ y, cv b)) (λ x, cv b)) (cfv (cv w) cplusg)) (cfv (cv w) cbs)) (λ s, cfv (cv w) csubg))
theorem df_nsg : cnsg = cmpt (λ w, cgrp) (λ w, crab (λ s, wsbc (λ b, wsbc (λ p, wral (λ x, wral (λ y, wb (wcel (co (cv x) (cv y) (cv p)) (cv s)) (wcel (co (cv y) (cv x) (cv p)) (cv s))) (λ y, cv b)) (λ x, cv b)) (cfv (cv w) cplusg)) (cfv (cv w) cbs)) (λ s, cfv (cv w) csubg)) := rfl
def cqg : «class» := cmpt2 (λ r i, cvv) (λ r i, cvv) (λ r i, copab (λ x y, wa (wss (cpr (cv x) (cv y)) (cfv (cv r) cbs)) (wcel (co (cfv (cv x) (cfv (cv r) cminusg)) (cv y) (cfv (cv r) cplusg)) (cv i))))
theorem df_eqg : cqg = cmpt2 (λ r i, cvv) (λ r i, cvv) (λ r i, copab (λ x y, wa (wss (cpr (cv x) (cv y)) (cfv (cv r) cbs)) (wcel (co (cfv (cv x) (cfv (cv r) cminusg)) (cv y) (cfv (cv r) cplusg)) (cv i)))) := rfl
def cghm : «class» := cmpt2 (λ s t, cgrp) (λ s t, cgrp) (λ s t, cab (λ g, wsbc (λ w, wa (wf (cv w) (cfv (cv t) cbs) (cv g)) (wral (λ x, wral (λ y, wceq (cfv (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv g)) (co (cfv (cv x) (cv g)) (cfv (cv y) (cv g)) (cfv (cv t) cplusg))) (λ y, cv w)) (λ x, cv w))) (cfv (cv s) cbs)))
theorem df_ghm : cghm = cmpt2 (λ s t, cgrp) (λ s t, cgrp) (λ s t, cab (λ g, wsbc (λ w, wa (wf (cv w) (cfv (cv t) cbs) (cv g)) (wral (λ x, wral (λ y, wceq (cfv (co (cv x) (cv y) (cfv (cv s) cplusg)) (cv g)) (co (cfv (cv x) (cv g)) (cfv (cv y) (cv g)) (cfv (cv t) cplusg))) (λ y, cv w)) (λ x, cv w))) (cfv (cv s) cbs))) := rfl
def cgim : «class» := cmpt2 (λ s t, cgrp) (λ s t, cgrp) (λ s t, crab (λ g, wf1o (cfv (cv s) cbs) (cfv (cv t) cbs) (cv g)) (λ g, co (cv s) (cv t) cghm))
theorem df_gim : cgim = cmpt2 (λ s t, cgrp) (λ s t, cgrp) (λ s t, crab (λ g, wf1o (cfv (cv s) cbs) (cfv (cv t) cbs) (cv g)) (λ g, co (cv s) (cv t) cghm)) := rfl
def cga : «class» := cmpt2 (λ g s, cgrp) (λ g s, cvv) (λ g s, csb (cfv (cv g) cbs) (λ b, crab (λ m, wral (λ x, wa (wceq (co (cfv (cv g) c0g) (cv x) (cv m)) (cv x)) (wral (λ y, wral (λ z, wceq (co (co (cv y) (cv z) (cfv (cv g) cplusg)) (cv x) (cv m)) (co (cv y) (co (cv z) (cv x) (cv m)) (cv m))) (λ z, cv b)) (λ y, cv b))) (λ x, cv s)) (λ m, co (cv s) (cxp (cv b) (cv s)) cmap)))
theorem df_ga : cga = cmpt2 (λ g s, cgrp) (λ g s, cvv) (λ g s, csb (cfv (cv g) cbs) (λ b, crab (λ m, wral (λ x, wa (wceq (co (cfv (cv g) c0g) (cv x) (cv m)) (cv x)) (wral (λ y, wral (λ z, wceq (co (co (cv y) (cv z) (cfv (cv g) cplusg)) (cv x) (cv m)) (co (cv y) (co (cv z) (cv x) (cv m)) (cv m))) (λ z, cv b)) (λ y, cv b))) (λ x, cv s)) (λ m, co (cv s) (cxp (cv b) (cv s)) cmap))) := rfl
def ccntz : «class» := cmpt (λ m, cvv) (λ m, cmpt (λ s, cpw (cfv (cv m) cbs)) (λ s, crab (λ x, wral (λ y, wceq (co (cv x) (cv y) (cfv (cv m) cplusg)) (co (cv y) (cv x) (cfv (cv m) cplusg))) (λ y, cv s)) (λ x, cfv (cv m) cbs)))
theorem df_cntz : ccntz = cmpt (λ m, cvv) (λ m, cmpt (λ s, cpw (cfv (cv m) cbs)) (λ s, crab (λ x, wral (λ y, wceq (co (cv x) (cv y) (cfv (cv m) cplusg)) (co (cv y) (cv x) (cfv (cv m) cplusg))) (λ y, cv s)) (λ x, cfv (cv m) cbs))) := rfl
def coppg : «class» := cmpt (λ w, cvv) (λ w, co (cv w) (cop (cfv cnx cplusg) (ctpos (cfv (cv w) cplusg))) csts)
theorem df_oppg : coppg = cmpt (λ w, cvv) (λ w, co (cv w) (cop (cfv cnx cplusg) (ctpos (cfv (cv w) cplusg))) csts) := rfl
def cod : «class» := cmpt (λ g, cvv) (λ g, cmpt (λ x, cfv (cv g) cbs) (λ x, csb (crab (λ n, wceq (co (cv n) (cv x) (cfv (cv g) cmg)) (cfv (cv g) c0g)) (λ n, cn)) (λ i, cif (wceq (cv i) c0) cc0 (csup (cv i) cr (ccnv clt)))))
theorem df_od : cod = cmpt (λ g, cvv) (λ g, cmpt (λ x, cfv (cv g) cbs) (λ x, csb (crab (λ n, wceq (co (cv n) (cv x) (cfv (cv g) cmg)) (cfv (cv g) c0g)) (λ n, cn)) (λ i, cif (wceq (cv i) c0) cc0 (csup (cv i) cr (ccnv clt))))) := rfl
def cgex : «class» := cmpt (λ g, cvv) (λ g, csb (crab (λ n, wral (λ x, wceq (co (cv n) (cv x) (cfv (cv g) cmg)) (cfv (cv g) c0g)) (λ x, cfv (cv g) cbs)) (λ n, cn)) (λ i, cif (wceq (cv i) c0) cc0 (csup (cv i) cr (ccnv clt))))
theorem df_gex : cgex = cmpt (λ g, cvv) (λ g, csb (crab (λ n, wral (λ x, wceq (co (cv n) (cv x) (cfv (cv g) cmg)) (cfv (cv g) c0g)) (λ x, cfv (cv g) cbs)) (λ n, cn)) (λ i, cif (wceq (cv i) c0) cc0 (csup (cv i) cr (ccnv clt)))) := rfl
def cpgp : «class» := copab (λ p g, wa (wa (wcel (cv p) cprime) (wcel (cv g) cgrp)) (wral (λ x, wrex (λ n, wceq (cfv (cv x) (cfv (cv g) cod)) (co (cv p) (cv n) cexp)) (λ n, cn0)) (λ x, cfv (cv g) cbs)))
theorem df_pgp : cpgp = copab (λ p g, wa (wa (wcel (cv p) cprime) (wcel (cv g) cgrp)) (wral (λ x, wrex (λ n, wceq (cfv (cv x) (cfv (cv g) cod)) (co (cv p) (cv n) cexp)) (λ n, cn0)) (λ x, cfv (cv g) cbs))) := rfl
def clsm : «class» := cmpt (λ w, cvv) (λ w, cmpt2 (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cpw (cfv (cv w) cbs)) (λ t u, crn (cmpt2 (λ x y, cv t) (λ x y, cv u) (λ x y, co (cv x) (cv y) (cfv (cv w) cplusg)))))
theorem df_lsm : clsm = cmpt (λ w, cvv) (λ w, cmpt2 (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cpw (cfv (cv w) cbs)) (λ t u, crn (cmpt2 (λ x y, cv t) (λ x y, cv u) (λ x y, co (cv x) (cv y) (cfv (cv w) cplusg))))) := rfl
def cpj1 : «class» := cmpt (λ w, cvv) (λ w, cmpt2 (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cmpt (λ z, co (cv t) (cv u) (cfv (cv w) clsm)) (λ z, crio (λ x, wrex (λ y, wceq (cv z) (co (cv x) (cv y) (cfv (cv w) cplusg))) (λ y, cv u)) (λ x, cv t))))
theorem df_pj1 : cpj1 = cmpt (λ w, cvv) (λ w, cmpt2 (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cpw (cfv (cv w) cbs)) (λ t u, cmpt (λ z, co (cv t) (cv u) (cfv (cv w) clsm)) (λ z, crio (λ x, wrex (λ y, wceq (cv z) (co (cv x) (cv y) (cfv (cv w) cplusg))) (λ y, cv u)) (λ x, cv t)))) := rfl
def ccmn : «class» := crab (λ g, wral (λ a, wral (λ b, wceq (co (cv a) (cv b) (cfv (cv g) cplusg)) (co (cv b) (cv a) (cfv (cv g) cplusg))) (λ b, cfv (cv g) cbs)) (λ a, cfv (cv g) cbs)) (λ g, cmnd)
theorem df_cmn : ccmn = crab (λ g, wral (λ a, wral (λ b, wceq (co (cv a) (cv b) (cfv (cv g) cplusg)) (co (cv b) (cv a) (cfv (cv g) cplusg))) (λ b, cfv (cv g) cbs)) (λ a, cfv (cv g) cbs)) (λ g, cmnd) := rfl
def cabel : «class» := cin cgrp ccmn
theorem df_abl : cabel = cin cgrp ccmn := rfl
def ccyg : «class» := crab (λ g, wrex (λ x, wceq (crn (cmpt (λ n, cz) (λ n, co (cv n) (cv x) (cfv (cv g) cmg)))) (cfv (cv g) cbs)) (λ x, cfv (cv g) cbs)) (λ g, cgrp)
theorem df_cyg : ccyg = crab (λ g, wrex (λ x, wceq (crn (cmpt (λ n, cz) (λ n, co (cv n) (cv x) (cfv (cv g) cmg)))) (cfv (cv g) cbs)) (λ x, cfv (cv g) cbs)) (λ g, cgrp) := rfl
def cdprd : «class» := cmpt2 (λ g s, cgrp) (λ g s, cab (λ h, wa (wf (cdm (cv h)) (cfv (cv g) csubg) (cv h)) (wral (λ x, wa (wral (λ y, wss (cfv (cv x) (cv h)) (cfv (cfv (cv y) (cv h)) (cfv (cv g) ccntz))) (λ y, cdif (cdm (cv h)) (csn (cv x)))) (wceq (cin (cfv (cv x) (cv h)) (cfv (cuni (cima (cv h) (cdif (cdm (cv h)) (csn (cv x))))) (cfv (cfv (cv g) csubg) cmrc))) (csn (cfv (cv g) c0g)))) (λ x, cdm (cv h))))) (λ g s, crn (cmpt (λ f, crab (λ h, wcel (cima (ccnv (cv h)) (cdif cvv (csn (cfv (cv g) c0g)))) cfn) (λ h, cixp (λ x, cdm (cv s)) (λ x, cfv (cv x) (cv s)))) (λ f, co (cv g) (cv f) cgsu)))
theorem df_dprd : cdprd = cmpt2 (λ g s, cgrp) (λ g s, cab (λ h, wa (wf (cdm (cv h)) (cfv (cv g) csubg) (cv h)) (wral (λ x, wa (wral (λ y, wss (cfv (cv x) (cv h)) (cfv (cfv (cv y) (cv h)) (cfv (cv g) ccntz))) (λ y, cdif (cdm (cv h)) (csn (cv x)))) (wceq (cin (cfv (cv x) (cv h)) (cfv (cuni (cima (cv h) (cdif (cdm (cv h)) (csn (cv x))))) (cfv (cfv (cv g) csubg) cmrc))) (csn (cfv (cv g) c0g)))) (λ x, cdm (cv h))))) (λ g s, crn (cmpt (λ f, crab (λ h, wcel (cima (ccnv (cv h)) (cdif cvv (csn (cfv (cv g) c0g)))) cfn) (λ h, cixp (λ x, cdm (cv s)) (λ x, cfv (cv x) (cv s)))) (λ f, co (cv g) (cv f) cgsu))) := rfl
def cdpj : «class» := cmpt2 (λ g s, cgrp) (λ g s, cima (cdm cdprd) (csn (cv g))) (λ g s, cmpt (λ i, cdm (cv s)) (λ i, co (cfv (cv i) (cv s)) (co (cv g) (cres (cv s) (cdif (cdm (cv s)) (csn (cv i)))) cdprd) (cfv (cv g) cpj1)))
theorem df_dpj : cdpj = cmpt2 (λ g s, cgrp) (λ g s, cima (cdm cdprd) (csn (cv g))) (λ g s, cmpt (λ i, cdm (cv s)) (λ i, co (cfv (cv i) (cv s)) (co (cv g) (cres (cv s) (cdif (cdm (cv s)) (csn (cv i)))) cdprd) (cfv (cv g) cpj1))) := rfl
def cmgp : «class» := cmpt (λ w, cvv) (λ w, co (cv w) (cop (cfv cnx cplusg) (cfv (cv w) cmulr)) csts)
theorem df_mgp : cmgp = cmpt (λ w, cvv) (λ w, co (cv w) (cop (cfv cnx cplusg) (cfv (cv w) cmulr)) csts) := rfl
def crg : «class» := crab (λ f, wa (wcel (cfv (cv f) cmgp) cmnd) (wsbc (λ r, wsbc (λ p, wsbc (λ t, wral (λ x, wral (λ y, wral (λ z, wa (wceq (co (cv x) (co (cv y) (cv z) (cv p)) (cv t)) (co (co (cv x) (cv y) (cv t)) (co (cv x) (cv z) (cv t)) (cv p))) (wceq (co (co (cv x) (cv y) (cv p)) (cv z) (cv t)) (co (co (cv x) (cv z) (cv t)) (co (cv y) (cv z) (cv t)) (cv p)))) (λ z, cv r)) (λ y, cv r)) (λ x, cv r)) (cfv (cv f) cmulr)) (cfv (cv f) cplusg)) (cfv (cv f) cbs))) (λ f, cgrp)
theorem df_rng : crg = crab (λ f, wa (wcel (cfv (cv f) cmgp) cmnd) (wsbc (λ r, wsbc (λ p, wsbc (λ t, wral (λ x, wral (λ y, wral (λ z, wa (wceq (co (cv x) (co (cv y) (cv z) (cv p)) (cv t)) (co (co (cv x) (cv y) (cv t)) (co (cv x) (cv z) (cv t)) (cv p))) (wceq (co (co (cv x) (cv y) (cv p)) (cv z) (cv t)) (co (co (cv x) (cv z) (cv t)) (co (cv y) (cv z) (cv t)) (cv p)))) (λ z, cv r)) (λ y, cv r)) (λ x, cv r)) (cfv (cv f) cmulr)) (cfv (cv f) cplusg)) (cfv (cv f) cbs))) (λ f, cgrp) := rfl
def ccrg : «class» := crab (λ f, wcel (cfv (cv f) cmgp) ccmn) (λ f, crg)
theorem df_cring : ccrg = crab (λ f, wcel (cfv (cv f) cmgp) ccmn) (λ f, crg) := rfl
def cur : «class» := ccom c0g cmgp
theorem df_ur : cur = ccom c0g cmgp := rfl
def coppr : «class» := cmpt (λ f, cvv) (λ f, co (cv f) (cop (cfv cnx cmulr) (ctpos (cfv (cv f) cmulr))) csts)
theorem df_oppr : coppr = cmpt (λ f, cvv) (λ f, co (cv f) (cop (cfv cnx cmulr) (ctpos (cfv (cv f) cmulr))) csts) := rfl
def cdsr : «class» := cmpt (λ w, cvv) (λ w, copab (λ x y, wa (wcel (cv x) (cfv (cv w) cbs)) (wrex (λ z, wceq (co (cv z) (cv x) (cfv (cv w) cmulr)) (cv y)) (λ z, cfv (cv w) cbs))))
theorem df_dvdsr : cdsr = cmpt (λ w, cvv) (λ w, copab (λ x y, wa (wcel (cv x) (cfv (cv w) cbs)) (wrex (λ z, wceq (co (cv z) (cv x) (cfv (cv w) cmulr)) (cv y)) (λ z, cfv (cv w) cbs)))) := rfl
def cui : «class» := cmpt (λ w, cvv) (λ w, cima (ccnv (cin (cfv (cv w) cdsr) (cfv (cfv (cv w) coppr) cdsr))) (csn (cfv (cv w) cur)))
theorem df_unit : cui = cmpt (λ w, cvv) (λ w, cima (ccnv (cin (cfv (cv w) cdsr) (cfv (cfv (cv w) coppr) cdsr))) (csn (cfv (cv w) cur))) := rfl
def cinvr : «class» := cmpt (λ r, cvv) (λ r, cfv (co (cfv (cv r) cmgp) (cfv (cv r) cui) cress) cminusg)
theorem df_invr : cinvr = cmpt (λ r, cvv) (λ r, cfv (co (cfv (cv r) cmgp) (cfv (cv r) cui) cress) cminusg) := rfl
def cdvr : «class» := cmpt (λ r, cvv) (λ r, cmpt2 (λ x y, cfv (cv r) cbs) (λ x y, cfv (cv r) cui) (λ x y, co (cv x) (cfv (cv y) (cfv (cv r) cinvr)) (cfv (cv r) cmulr)))
theorem df_dvr : cdvr = cmpt (λ r, cvv) (λ r, cmpt2 (λ x y, cfv (cv r) cbs) (λ x y, cfv (cv r) cui) (λ x y, co (cv x) (cfv (cv y) (cfv (cv r) cinvr)) (cfv (cv r) cmulr))) := rfl
def crh : «class» := cmpt2 (λ r s, crg) (λ r s, crg) (λ r s, csb (cfv (cv r) cbs) (λ v, csb (cfv (cv s) cbs) (λ w, crab (λ f, wa (wceq (cfv (cfv (cv r) cur) (cv f)) (cfv (cv s) cur)) (wral (λ x, wral (λ y, wa (wceq (cfv (co (cv x) (cv y) (cfv (cv r) cplusg)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv s) cplusg))) (wceq (cfv (co (cv x) (cv y) (cfv (cv r) cmulr)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv s) cmulr)))) (λ y, cv v)) (λ x, cv v))) (λ f, co (cv w) (cv v) cmap))))
theorem df_rnghom : crh = cmpt2 (λ r s, crg) (λ r s, crg) (λ r s, csb (cfv (cv r) cbs) (λ v, csb (cfv (cv s) cbs) (λ w, crab (λ f, wa (wceq (cfv (cfv (cv r) cur) (cv f)) (cfv (cv s) cur)) (wral (λ x, wral (λ y, wa (wceq (cfv (co (cv x) (cv y) (cfv (cv r) cplusg)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv s) cplusg))) (wceq (cfv (co (cv x) (cv y) (cfv (cv r) cmulr)) (cv f)) (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) (cfv (cv s) cmulr)))) (λ y, cv v)) (λ x, cv v))) (λ f, co (cv w) (cv v) cmap)))) := rfl
def cdr : «class» := crab (λ r, wceq (cfv (cv r) cui) (cdif (cfv (cv r) cbs) (csn (cfv (cv r) c0g)))) (λ r, crg)
theorem df_drng : cdr = crab (λ r, wceq (cfv (cv r) cui) (cdif (cfv (cv r) cbs) (csn (cfv (cv r) c0g)))) (λ r, crg) := rfl
def csubrg : «class» := cmpt (λ w, crg) (λ w, crab (λ s, wa (wcel (co (cv w) (cv s) cress) crg) (wcel (cfv (cv w) cur) (cv s))) (λ s, cpw (cfv (cv w) cbs)))
theorem df_subrg : csubrg = cmpt (λ w, crg) (λ w, crab (λ s, wa (wcel (co (cv w) (cv s) cress) crg) (wcel (cfv (cv w) cur) (cv s))) (λ s, cpw (cfv (cv w) cbs))) := rfl
def clmod : «class» := crab (λ g, wsbc (λ v, wsbc (λ a, wsbc (λ f, wsbc (λ s, wsbc (λ k, wsbc (λ p, wsbc (λ t, wa (wcel (cv f) crg) (wral (λ q, wral (λ r, wral (λ x, wral (λ w, wa (w3a (wcel (co (cv r) (cv w) (cv s)) (cv v)) (wceq (co (cv r) (co (cv w) (cv x) (cv a)) (cv s)) (co (co (cv r) (cv w) (cv s)) (co (cv r) (cv x) (cv s)) (cv a))) (wceq (co (co (cv q) (cv r) (cv p)) (cv w) (cv s)) (co (co (cv q) (cv w) (cv s)) (co (cv r) (cv w) (cv s)) (cv a)))) (wa (wceq (co (co (cv q) (cv r) (cv t)) (cv w) (cv s)) (co (cv q) (co (cv r) (cv w) (cv s)) (cv s))) (wceq (co (cfv (cv f) cur) (cv w) (cv s)) (cv w)))) (λ w, cv v)) (λ x, cv v)) (λ r, cv k)) (λ q, cv k))) (cfv (cv f) cmulr)) (cfv (cv f) cplusg)) (cfv (cv f) cbs)) (cfv (cv g) cvsca)) (cfv (cv g) csca)) (cfv (cv g) cplusg)) (cfv (cv g) cbs)) (λ g, cgrp)
theorem df_lmod : clmod = crab (λ g, wsbc (λ v, wsbc (λ a, wsbc (λ f, wsbc (λ s, wsbc (λ k, wsbc (λ p, wsbc (λ t, wa (wcel (cv f) crg) (wral (λ q, wral (λ r, wral (λ x, wral (λ w, wa (w3a (wcel (co (cv r) (cv w) (cv s)) (cv v)) (wceq (co (cv r) (co (cv w) (cv x) (cv a)) (cv s)) (co (co (cv r) (cv w) (cv s)) (co (cv r) (cv x) (cv s)) (cv a))) (wceq (co (co (cv q) (cv r) (cv p)) (cv w) (cv s)) (co (co (cv q) (cv w) (cv s)) (co (cv r) (cv w) (cv s)) (cv a)))) (wa (wceq (co (co (cv q) (cv r) (cv t)) (cv w) (cv s)) (co (cv q) (co (cv r) (cv w) (cv s)) (cv s))) (wceq (co (cfv (cv f) cur) (cv w) (cv s)) (cv w)))) (λ w, cv v)) (λ x, cv v)) (λ r, cv k)) (λ q, cv k))) (cfv (cv f) cmulr)) (cfv (cv f) cplusg)) (cfv (cv f) cbs)) (cfv (cv g) cvsca)) (cfv (cv g) csca)) (cfv (cv g) cplusg)) (cfv (cv g) cbs)) (λ g, cgrp) := rfl
def clss : «class» := cmpt (λ w, cvv) (λ w, crab (λ s, wral (λ x, wral (λ a, wral (λ b, wcel (co (co (cv x) (cv a) (cfv (cv w) cvsca)) (cv b) (cfv (cv w) cplusg)) (cv s)) (λ b, cv s)) (λ a, cv s)) (λ x, cfv (cfv (cv w) csca) cbs)) (λ s, cdif (cpw (cfv (cv w) cbs)) (csn c0)))
theorem df_lss : clss = cmpt (λ w, cvv) (λ w, crab (λ s, wral (λ x, wral (λ a, wral (λ b, wcel (co (co (cv x) (cv a) (cfv (cv w) cvsca)) (cv b) (cfv (cv w) cplusg)) (cv s)) (λ b, cv s)) (λ a, cv s)) (λ x, cfv (cfv (cv w) csca) cbs)) (λ s, cdif (cpw (cfv (cv w) cbs)) (csn c0))) := rfl
def clspn : «class» := cmpt (λ w, cvv) (λ w, cmpt (λ s, cpw (cfv (cv w) cbs)) (λ s, cint (crab (λ t, wss (cv s) (cv t)) (λ t, cfv (cv w) clss))))
theorem df_lsp : clspn = cmpt (λ w, cvv) (λ w, cmpt (λ s, cpw (cfv (cv w) cbs)) (λ s, cint (crab (λ t, wss (cv s) (cv t)) (λ t, cfv (cv w) clss)))) := rfl
def csra : «class» := cmpt (λ w, cvv) (λ w, cmpt (λ s, cpw (cfv (cv w) cbs)) (λ s, co (co (cv w) (cop (cfv cnx csca) (co (cv w) (cv s) cress)) csts) (cop (cfv cnx cvsca) (cfv (cv w) cmulr)) csts))
theorem df_sra : csra = cmpt (λ w, cvv) (λ w, cmpt (λ s, cpw (cfv (cv w) cbs)) (λ s, co (co (cv w) (cop (cfv cnx csca) (co (cv w) (cv s) cress)) csts) (cop (cfv cnx cvsca) (cfv (cv w) cmulr)) csts)) := rfl
def crglmod : «class» := cmpt (λ w, cvv) (λ w, cfv (cfv (cv w) cbs) (cfv (cv w) csra))
theorem df_rgmod : crglmod = cmpt (λ w, cvv) (λ w, cfv (cfv (cv w) cbs) (cfv (cv w) csra)) := rfl
def clidl : «class» := ccom clss crglmod
theorem df_lidl : clidl = ccom clss crglmod := rfl
def crsp : «class» := ccom clspn crglmod
theorem df_rsp : crsp = ccom clspn crglmod := rfl
def c2idl : «class» := cmpt (λ r, cvv) (λ r, cin (cfv (cv r) clidl) (cfv (cfv (cv r) coppr) clidl))
theorem df_2idl : c2idl = cmpt (λ r, cvv) (λ r, cin (cfv (cv r) clidl) (cfv (cfv (cv r) coppr) clidl)) := rfl
def cpsmet : «class» := cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wa (wceq (co (cv y) (cv y) (cv d)) cc0) (wral (λ z, wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) cxad) cle) (λ w, cv x)) (λ z, cv x))) (λ y, cv x)) (λ d, co cxr (cxp (cv x) (cv x)) cmap))
theorem df_psmet : cpsmet = cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wa (wceq (co (cv y) (cv y) (cv d)) cc0) (wral (λ z, wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) cxad) cle) (λ w, cv x)) (λ z, cv x))) (λ y, cv x)) (λ d, co cxr (cxp (cv x) (cv x)) cmap)) := rfl
def cxmt : «class» := cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wral (λ z, wa (wb (wceq (co (cv y) (cv z) (cv d)) cc0) (wceq (cv y) (cv z))) (wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) cxad) cle) (λ w, cv x))) (λ z, cv x)) (λ y, cv x)) (λ d, co cxr (cxp (cv x) (cv x)) cmap))
theorem df_xmet : cxmt = cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wral (λ z, wa (wb (wceq (co (cv y) (cv z) (cv d)) cc0) (wceq (cv y) (cv z))) (wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) cxad) cle) (λ w, cv x))) (λ z, cv x)) (λ y, cv x)) (λ d, co cxr (cxp (cv x) (cv x)) cmap)) := rfl
def cme : «class» := cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wral (λ z, wa (wb (wceq (co (cv y) (cv z) (cv d)) cc0) (wceq (cv y) (cv z))) (wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) caddc) cle) (λ w, cv x))) (λ z, cv x)) (λ y, cv x)) (λ d, co cr (cxp (cv x) (cv x)) cmap))
theorem df_met : cme = cmpt (λ x, cvv) (λ x, crab (λ d, wral (λ y, wral (λ z, wa (wb (wceq (co (cv y) (cv z) (cv d)) cc0) (wceq (cv y) (cv z))) (wral (λ w, wbr (co (cv y) (cv z) (cv d)) (co (co (cv w) (cv y) (cv d)) (co (cv w) (cv z) (cv d)) caddc) cle) (λ w, cv x))) (λ z, cv x)) (λ y, cv x)) (λ d, co cr (cxp (cv x) (cv x)) cmap)) := rfl
def cbl : «class» := cmpt (λ d, cvv) (λ d, cmpt2 (λ x z, cdm (cdm (cv d))) (λ x z, cxr) (λ x z, crab (λ y, wbr (co (cv x) (cv y) (cv d)) (cv z) clt) (λ y, cdm (cdm (cv d)))))
theorem df_bl : cbl = cmpt (λ d, cvv) (λ d, cmpt2 (λ x z, cdm (cdm (cv d))) (λ x z, cxr) (λ x z, crab (λ y, wbr (co (cv x) (cv y) (cv d)) (cv z) clt) (λ y, cdm (cdm (cv d))))) := rfl
def cfbas : «class» := cmpt (λ w, cvv) (λ w, crab (λ x, w3a (wne (cv x) c0) (wnel c0 (cv x)) (wral (λ y, wral (λ z, wne (cin (cv x) (cpw (cin (cv y) (cv z)))) c0) (λ z, cv x)) (λ y, cv x))) (λ x, cpw (cpw (cv w))))
theorem df_fbas : cfbas = cmpt (λ w, cvv) (λ w, crab (λ x, w3a (wne (cv x) c0) (wnel c0 (cv x)) (wral (λ y, wral (λ z, wne (cin (cv x) (cpw (cin (cv y) (cv z)))) c0) (λ z, cv x)) (λ y, cv x))) (λ x, cpw (cpw (cv w)))) := rfl
def cfg : «class» := cmpt2 (λ w x, cvv) (λ w x, cfv (cv w) cfbas) (λ w x, crab (λ y, wne (cin (cv x) (cpw (cv y))) c0) (λ y, cpw (cv w)))
theorem df_fg : cfg = cmpt2 (λ w x, cvv) (λ w x, cfv (cv w) cfbas) (λ w x, crab (λ y, wne (cin (cv x) (cpw (cv y))) c0) (λ y, cpw (cv w))) := rfl
def cmopn : «class» := cmpt (λ d, cuni (crn cxmt)) (λ d, cfv (crn (cfv (cv d) cbl)) ctg)
theorem df_mopn : cmopn = cmpt (λ d, cuni (crn cxmt)) (λ d, cfv (crn (cfv (cv d) cbl)) ctg) := rfl
def cmetu : «class» := cmpt (λ d, cuni (crn cpsmet)) (λ d, co (cxp (cdm (cdm (cv d))) (cdm (cdm (cv d)))) (crn (cmpt (λ a, crp) (λ a, cima (ccnv (cv d)) (co cc0 (cv a) cico)))) cfg)
theorem df_metu : cmetu = cmpt (λ d, cuni (crn cpsmet)) (λ d, co (cxp (cdm (cdm (cv d))) (cdm (cdm (cv d)))) (crn (cmpt (λ a, crp) (λ a, cima (ccnv (cv d)) (co cc0 (cv a) cico)))) cfg) := rfl
def ccnfld : «class» := cun (cun (ctp (cop (cfv cnx cbs) cc) (cop (cfv cnx cplusg) caddc) (cop (cfv cnx cmulr) cmul)) (csn (cop (cfv cnx cstv) ccj))) (cun (ctp (cop (cfv cnx cts) (cfv (ccom cabs cmin) cmopn)) (cop (cfv cnx cple) cle) (cop (cfv cnx cds) (ccom cabs cmin))) (csn (cop (cfv cnx cunif) (cfv (ccom cabs cmin) cmetu))))
theorem df_cnfld : ccnfld = cun (cun (ctp (cop (cfv cnx cbs) cc) (cop (cfv cnx cplusg) caddc) (cop (cfv cnx cmulr) cmul)) (csn (cop (cfv cnx cstv) ccj))) (cun (ctp (cop (cfv cnx cts) (cfv (ccom cabs cmin) cmopn)) (cop (cfv cnx cple) cle) (cop (cfv cnx cds) (ccom cabs cmin))) (csn (cop (cfv cnx cunif) (cfv (ccom cabs cmin) cmetu)))) := rfl
def czrh : «class» := cmpt (λ r, cvv) (λ r, cuni (co (co ccnfld cz cress) (cv r) crh))
theorem df_zrh : czrh = cmpt (λ r, cvv) (λ r, cuni (co (co ccnfld cz cress) (cv r) crh)) := rfl
def czn : «class» := cmpt (λ n, cn0) (λ n, csb (co ccnfld cz cress) (λ z, csb (co (cv z) (co (cv z) (cfv (csn (cv n)) (cfv (cv z) crsp)) cqg) cqus) (λ s, co (cv s) (cop (cfv cnx cple) (csb (cres (cfv (cv s) czrh) (cif (wceq (cv n) cc0) cz (co cc0 (cv n) cfzo))) (λ f, ccom (ccom (cv f) cle) (ccnv (cv f))))) csts)))
theorem df_zn : czn = cmpt (λ n, cn0) (λ n, csb (co ccnfld cz cress) (λ z, csb (co (cv z) (co (cv z) (cfv (csn (cv n)) (cfv (cv z) crsp)) cqg) cqus) (λ s, co (cv s) (cop (cfv cnx cple) (csb (cres (cfv (cv s) czrh) (cif (wceq (cv n) cc0) cz (co cc0 (cv n) cfzo))) (λ f, ccom (ccom (cv f) cle) (ccnv (cv f))))) csts))) := rfl
def ctop : «class» := cab (λ x, wa (wral (λ y, wcel (cuni (cv y)) (cv x)) (λ y, cpw (cv x))) (wral (λ y, wral (λ z, wcel (cin (cv y) (cv z)) (cv x)) (λ z, cv x)) (λ y, cv x)))
theorem df_top : ctop = cab (λ x, wa (wral (λ y, wcel (cuni (cv y)) (cv x)) (λ y, cpw (cv x))) (wral (λ y, wral (λ z, wcel (cin (cv y) (cv z)) (cv x)) (λ z, cv x)) (λ y, cv x))) := rfl
def ctopon : «class» := cmpt (λ b, cvv) (λ b, crab (λ j, wceq (cv b) (cuni (cv j))) (λ j, ctop))
theorem df_topon : ctopon = cmpt (λ b, cvv) (λ b, crab (λ j, wceq (cv b) (cuni (cv j))) (λ j, ctop)) := rfl
def ctps : «class» := cab (λ f, wcel (cfv (cv f) ctopn) (cfv (cfv (cv f) cbs) ctopon))
theorem df_topsp : ctps = cab (λ f, wcel (cfv (cv f) ctopn) (cfv (cfv (cv f) cbs) ctopon)) := rfl
def ctb : «class» := cab (λ x, wral (λ y, wral (λ z, wss (cin (cv y) (cv z)) (cuni (cin (cv x) (cpw (cin (cv y) (cv z)))))) (λ z, cv x)) (λ y, cv x))
theorem df_bases : ctb = cab (λ x, wral (λ y, wral (λ z, wss (cin (cv y) (cv z)) (cuni (cin (cv x) (cpw (cin (cv y) (cv z)))))) (λ z, cv x)) (λ y, cv x)) := rfl
def ccld : «class» := cmpt (λ j, ctop) (λ j, crab (λ x, wcel (cdif (cuni (cv j)) (cv x)) (cv j)) (λ x, cpw (cuni (cv j))))
theorem df_cld : ccld = cmpt (λ j, ctop) (λ j, crab (λ x, wcel (cdif (cuni (cv j)) (cv x)) (cv j)) (λ x, cpw (cuni (cv j)))) := rfl
def cnt : «class» := cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cuni (cin (cv j) (cpw (cv x)))))
theorem df_ntr : cnt = cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cuni (cin (cv j) (cpw (cv x))))) := rfl
def ccl : «class» := cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cint (crab (λ y, wss (cv x) (cv y)) (λ y, cfv (cv j) ccld))))
theorem df_cls : ccl = cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cint (crab (λ y, wss (cv x) (cv y)) (λ y, cfv (cv j) ccld)))) := rfl
def cnei : «class» := cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, crab (λ y, wrex (λ g, wa (wss (cv x) (cv g)) (wss (cv g) (cv y))) (λ g, cv j)) (λ y, cpw (cuni (cv j)))))
theorem df_nei : cnei = cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, crab (λ y, wrex (λ g, wa (wss (cv x) (cv g)) (wss (cv g) (cv y))) (λ g, cv j)) (λ y, cpw (cuni (cv j))))) := rfl
def clp : «class» := cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cab (λ y, wcel (cv y) (cfv (cdif (cv x) (csn (cv y))) (cfv (cv j) ccl)))))
theorem df_lp : clp = cmpt (λ j, ctop) (λ j, cmpt (λ x, cpw (cuni (cv j))) (λ x, cab (λ y, wcel (cv y) (cfv (cdif (cv x) (csn (cv y))) (cfv (cv j) ccl))))) := rfl
def cperf : «class» := crab (λ j, wceq (cfv (cuni (cv j)) (cfv (cv j) clp)) (cuni (cv j))) (λ j, ctop)
theorem df_perf : cperf = crab (λ j, wceq (cfv (cuni (cv j)) (cfv (cv j) clp)) (cuni (cv j))) (λ j, ctop) := rfl
def ccn : «class» := cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, crab (λ f, wral (λ y, wcel (cima (ccnv (cv f)) (cv y)) (cv j)) (λ y, cv k)) (λ f, co (cuni (cv k)) (cuni (cv j)) cmap))
theorem df_cn : ccn = cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, crab (λ f, wral (λ y, wcel (cima (ccnv (cv f)) (cv y)) (cv j)) (λ y, cv k)) (λ f, co (cuni (cv k)) (cuni (cv j)) cmap)) := rfl
def ccnp : «class» := cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, cmpt (λ x, cuni (cv j)) (λ x, crab (λ f, wral (λ y, wi (wcel (cfv (cv x) (cv f)) (cv y)) (wrex (λ g, wa (wcel (cv x) (cv g)) (wss (cima (cv f) (cv g)) (cv y))) (λ g, cv j))) (λ y, cv k)) (λ f, co (cuni (cv k)) (cuni (cv j)) cmap)))
theorem df_cnp : ccnp = cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, cmpt (λ x, cuni (cv j)) (λ x, crab (λ f, wral (λ y, wi (wcel (cfv (cv x) (cv f)) (cv y)) (wrex (λ g, wa (wcel (cv x) (cv g)) (wss (cima (cv f) (cv g)) (cv y))) (λ g, cv j))) (λ y, cv k)) (λ f, co (cuni (cv k)) (cuni (cv j)) cmap))) := rfl
def cha : «class» := crab (λ j, wral (λ x, wral (λ y, wi (wne (cv x) (cv y)) (wrex (λ n, wrex (λ m, w3a (wcel (cv x) (cv n)) (wcel (cv y) (cv m)) (wceq (cin (cv n) (cv m)) c0)) (λ m, cv j)) (λ n, cv j))) (λ y, cuni (cv j))) (λ x, cuni (cv j))) (λ j, ctop)
theorem df_haus : cha = crab (λ j, wral (λ x, wral (λ y, wi (wne (cv x) (cv y)) (wrex (λ n, wrex (λ m, w3a (wcel (cv x) (cv n)) (wcel (cv y) (cv m)) (wceq (cin (cv n) (cv m)) c0)) (λ m, cv j)) (λ n, cv j))) (λ y, cuni (cv j))) (λ x, cuni (cv j))) (λ j, ctop) := rfl
def ccmp : «class» := crab (λ x, wral (λ y, wi (wceq (cuni (cv x)) (cuni (cv y))) (wrex (λ z, wceq (cuni (cv x)) (cuni (cv z))) (λ z, cin (cpw (cv y)) cfn))) (λ y, cpw (cv x))) (λ x, ctop)
theorem df_cmp : ccmp = crab (λ x, wral (λ y, wi (wceq (cuni (cv x)) (cuni (cv y))) (wrex (λ z, wceq (cuni (cv x)) (cuni (cv z))) (λ z, cin (cpw (cv y)) cfn))) (λ y, cpw (cv x))) (λ x, ctop) := rfl
def ctx : «class» := cmpt2 (λ r s, cvv) (λ r s, cvv) (λ r s, cfv (crn (cmpt2 (λ x y, cv r) (λ x y, cv s) (λ x y, cxp (cv x) (cv y)))) ctg)
theorem df_tx : ctx = cmpt2 (λ r s, cvv) (λ r s, cvv) (λ r s, cfv (crn (cmpt2 (λ x y, cv r) (λ x y, cv s) (λ x y, cxp (cv x) (cv y)))) ctg) := rfl
def chmeo : «class» := cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, crab (λ f, wcel (ccnv (cv f)) (co (cv k) (cv j) ccn)) (λ f, co (cv j) (cv k) ccn))
theorem df_hmeo : chmeo = cmpt2 (λ j k, ctop) (λ j k, ctop) (λ j k, crab (λ f, wcel (ccnv (cv f)) (co (cv k) (cv j) ccn)) (λ f, co (cv j) (cv k) ccn)) := rfl
def cfil : «class» := cmpt (λ z, cvv) (λ z, crab (λ f, wral (λ x, wi (wne (cin (cv f) (cpw (cv x))) c0) (wcel (cv x) (cv f))) (λ x, cpw (cv z))) (λ f, cfv (cv z) cfbas))
theorem df_fil : cfil = cmpt (λ z, cvv) (λ z, crab (λ f, wral (λ x, wi (wne (cin (cv f) (cpw (cv x))) c0) (wcel (cv x) (cv f))) (λ x, cpw (cv z))) (λ f, cfv (cv z) cfbas)) := rfl
def cfm : «class» := cmpt2 (λ x f, cvv) (λ x f, cvv) (λ x f, cmpt (λ y, cfv (cdm (cv f)) cfbas) (λ y, co (cv x) (crn (cmpt (λ t, cv y) (λ t, cima (cv f) (cv t)))) cfg))
theorem df_fm : cfm = cmpt2 (λ x f, cvv) (λ x f, cvv) (λ x f, cmpt (λ y, cfv (cdm (cv f)) cfbas) (λ y, co (cv x) (crn (cmpt (λ t, cv y) (λ t, cima (cv f) (cv t)))) cfg)) := rfl
def cflim : «class» := cmpt2 (λ j f, ctop) (λ j f, cuni (crn cfil)) (λ j f, crab (λ x, wa (wss (cfv (csn (cv x)) (cfv (cv j) cnei)) (cv f)) (wss (cv f) (cpw (cuni (cv j))))) (λ x, cuni (cv j)))
theorem df_flim : cflim = cmpt2 (λ j f, ctop) (λ j f, cuni (crn cfil)) (λ j f, crab (λ x, wa (wss (cfv (csn (cv x)) (cfv (cv j) cnei)) (cv f)) (wss (cv f) (cpw (cuni (cv j))))) (λ x, cuni (cv j))) := rfl
def cflf : «class» := cmpt2 (λ x y, ctop) (λ x y, cuni (crn cfil)) (λ x y, cmpt (λ f, co (cuni (cv x)) (cuni (cv y)) cmap) (λ f, co (cv x) (cfv (cv y) (co (cuni (cv x)) (cv f) cfm)) cflim))
theorem df_flf : cflf = cmpt2 (λ x y, ctop) (λ x y, cuni (crn cfil)) (λ x y, cmpt (λ f, co (cuni (cv x)) (cuni (cv y)) cmap) (λ f, co (cv x) (cfv (cv y) (co (cuni (cv x)) (cv f) cfm)) cflim)) := rfl
def cxme : «class» := crab (λ f, wceq (cfv (cv f) ctopn) (cfv (cres (cfv (cv f) cds) (cxp (cfv (cv f) cbs) (cfv (cv f) cbs))) cmopn)) (λ f, ctps)
theorem df_xms : cxme = crab (λ f, wceq (cfv (cv f) ctopn) (cfv (cres (cfv (cv f) cds) (cxp (cfv (cv f) cbs) (cfv (cv f) cbs))) cmopn)) (λ f, ctps) := rfl
def cmt : «class» := crab (λ f, wcel (cres (cfv (cv f) cds) (cxp (cfv (cv f) cbs) (cfv (cv f) cbs))) (cfv (cfv (cv f) cbs) cme)) (λ f, cxme)
theorem df_ms : cmt = crab (λ f, wcel (cres (cfv (cv f) cds) (cxp (cfv (cv f) cbs) (cfv (cv f) cbs))) (cfv (cfv (cv f) cbs) cme)) (λ f, cxme) := rfl
def ctmt : «class» := cmpt (λ d, cuni (crn cxmt)) (λ d, co (cpr (cop (cfv cnx cbs) (cdm (cdm (cv d)))) (cop (cfv cnx cds) (cv d))) (cop (cfv cnx cts) (cfv (cv d) cmopn)) csts)
theorem df_tms : ctmt = cmpt (λ d, cuni (crn cxmt)) (λ d, co (cpr (cop (cfv cnx cbs) (cdm (cdm (cv d)))) (cop (cfv cnx cds) (cv d))) (cop (cfv cnx cts) (cfv (cv d) cmopn)) csts) := rfl
def ccncf : «class» := cmpt2 (λ a b, cpw cc) (λ a b, cpw cc) (λ a b, crab (λ f, wral (λ x, wral (λ e, wrex (λ d, wral (λ y, wi (wbr (cfv (co (cv x) (cv y) cmin) cabs) (cv d) clt) (wbr (cfv (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) cmin) cabs) (cv e) clt)) (λ y, cv a)) (λ d, crp)) (λ e, crp)) (λ x, cv a)) (λ f, co (cv b) (cv a) cmap))
theorem df_cncf : ccncf = cmpt2 (λ a b, cpw cc) (λ a b, cpw cc) (λ a b, crab (λ f, wral (λ x, wral (λ e, wrex (λ d, wral (λ y, wi (wbr (cfv (co (cv x) (cv y) cmin) cabs) (cv d) clt) (wbr (cfv (co (cfv (cv x) (cv f)) (cfv (cv y) (cv f)) cmin) cabs) (cv e) clt)) (λ y, cv a)) (λ d, crp)) (λ e, crp)) (λ x, cv a)) (λ f, co (cv b) (cv a) cmap)) := rfl
def c0p : «class» := cxp cc (csn cc0)
theorem df_0p : c0p = cxp cc (csn cc0) := rfl
def climc : «class» := cmpt2 (λ f x, co cc cc cpm) (λ f x, cc) (λ f x, cab (λ y, wsbc (λ j, wcel (cmpt (λ z, cun (cdm (cv f)) (csn (cv x))) (λ z, cif (wceq (cv z) (cv x)) (cv y) (cfv (cv z) (cv f)))) (cfv (cv x) (co (co (cv j) (cun (cdm (cv f)) (csn (cv x))) crest) (cv j) ccnp))) (cfv ccnfld ctopn)))
theorem df_limc : climc = cmpt2 (λ f x, co cc cc cpm) (λ f x, cc) (λ f x, cab (λ y, wsbc (λ j, wcel (cmpt (λ z, cun (cdm (cv f)) (csn (cv x))) (λ z, cif (wceq (cv z) (cv x)) (cv y) (cfv (cv z) (cv f)))) (cfv (cv x) (co (co (cv j) (cun (cdm (cv f)) (csn (cv x))) crest) (cv j) ccnp))) (cfv ccnfld ctopn))) := rfl
def cdv : «class» := cmpt2 (λ s f, cpw cc) (λ s f, co cc (cv s) cpm) (λ s f, ciun (λ x, cfv (cdm (cv f)) (cfv (co (cfv ccnfld ctopn) (cv s) crest) cnt)) (λ x, cxp (csn (cv x)) (co (cmpt (λ z, cdif (cdm (cv f)) (csn (cv x))) (λ z, co (co (cfv (cv z) (cv f)) (cfv (cv x) (cv f)) cmin) (co (cv z) (cv x) cmin) cdiv)) (cv x) climc)))
theorem df_dv : cdv = cmpt2 (λ s f, cpw cc) (λ s f, co cc (cv s) cpm) (λ s f, ciun (λ x, cfv (cdm (cv f)) (cfv (co (cfv ccnfld ctopn) (cv s) crest) cnt)) (λ x, cxp (csn (cv x)) (co (cmpt (λ z, cdif (cdm (cv f)) (csn (cv x))) (λ z, co (co (cfv (cv z) (cv f)) (cfv (cv x) (cv f)) cmin) (co (cv z) (cv x) cmin) cdiv)) (cv x) climc))) := rfl
def cply : «class» := cmpt (λ x, cpw cc) (λ x, cab (λ f, wrex (λ n, wrex (λ a, wceq (cv f) (cmpt (λ z, cc) (λ z, csu (co cc0 (cv n) cfz) (λ k, co (cfv (cv k) (cv a)) (co (cv z) (cv k) cexp) cmul)))) (λ a, co (cun (cv x) (csn cc0)) cn0 cmap)) (λ n, cn0)))
theorem df_ply : cply = cmpt (λ x, cpw cc) (λ x, cab (λ f, wrex (λ n, wrex (λ a, wceq (cv f) (cmpt (λ z, cc) (λ z, csu (co cc0 (cv n) cfz) (λ k, co (cfv (cv k) (cv a)) (co (cv z) (cv k) cexp) cmul)))) (λ a, co (cun (cv x) (csn cc0)) cn0 cmap)) (λ n, cn0))) := rfl
def cidp : «class» := cres cid cc
theorem df_idp : cidp = cres cid cc := rfl
def ccoe : «class» := cmpt (λ f, cfv cc cply) (λ f, crio (λ a, wrex (λ n, wa (wceq (cima (cv a) (cfv (co (cv n) c1 caddc) cuz)) (csn cc0)) (wceq (cv f) (cmpt (λ z, cc) (λ z, csu (co cc0 (cv n) cfz) (λ k, co (cfv (cv k) (cv a)) (co (cv z) (cv k) cexp) cmul))))) (λ n, cn0)) (λ a, co cc cn0 cmap))
theorem df_coe : ccoe = cmpt (λ f, cfv cc cply) (λ f, crio (λ a, wrex (λ n, wa (wceq (cima (cv a) (cfv (co (cv n) c1 caddc) cuz)) (csn cc0)) (wceq (cv f) (cmpt (λ z, cc) (λ z, csu (co cc0 (cv n) cfz) (λ k, co (cfv (cv k) (cv a)) (co (cv z) (cv k) cexp) cmul))))) (λ n, cn0)) (λ a, co cc cn0 cmap)) := rfl
def cdgr : «class» := cmpt (λ f, cfv cc cply) (λ f, csup (cima (ccnv (cfv (cv f) ccoe)) (cdif cc (csn cc0))) cn0 clt)
theorem df_dgr : cdgr = cmpt (λ f, cfv cc cply) (λ f, csup (cima (ccnv (cfv (cv f) ccoe)) (cdif cc (csn cc0))) cn0 clt) := rfl
def cquot : «class» := cmpt2 (λ f g, cfv cc cply) (λ f g, cdif (cfv cc cply) (csn c0p)) (λ f g, crio (λ q, wsbc (λ r, wo (wceq (cv r) c0p) (wbr (cfv (cv r) cdgr) (cfv (cv g) cdgr) clt)) (co (cv f) (co (cv g) (cv q) (cof cmul)) (cof cmin))) (λ q, cfv cc cply))
theorem df_quot : cquot = cmpt2 (λ f g, cfv cc cply) (λ f g, cdif (cfv cc cply) (csn c0p)) (λ f g, crio (λ q, wsbc (λ r, wo (wceq (cv r) c0p) (wbr (cfv (cv r) cdgr) (cfv (cv g) cdgr) clt)) (co (cv f) (co (cv g) (cv q) (cof cmul)) (cof cmin))) (λ q, cfv cc cply)) := rfl
def clog : «class» := ccnv (cres ce (cima (ccnv cim) (co (cneg cpi) cpi cioc)))
theorem df_log : clog = ccnv (cres ce (cima (ccnv cim) (co (cneg cpi) cpi cioc))) := rfl
def ccxp : «class» := cmpt2 (λ x y, cc) (λ x y, cc) (λ x y, cif (wceq (cv x) cc0) (cif (wceq (cv y) cc0) c1 cc0) (cfv (co (cv y) (cfv (cv x) clog) cmul) ce))
theorem df_cxp : ccxp = cmpt2 (λ x y, cc) (λ x y, cc) (λ x y, cif (wceq (cv x) cc0) (cif (wceq (cv y) cc0) c1 cc0) (cfv (co (cv y) (cfv (cv x) clog) cmul) ce)) := rfl
def cem : «class» := csu cn (λ k, co (co c1 (cv k) cdiv) (cfv (co c1 (co c1 (cv k) cdiv) caddc) clog) cmin)
theorem df_em : cem = csu cn (λ k, co (co c1 (cv k) cdiv) (cfv (co c1 (co c1 (cv k) cdiv) caddc) clog) cmin) := rfl
def ccht : «class» := cmpt (λ x, cr) (λ x, csu (cin (co cc0 (cv x) cicc) cprime) (λ p, cfv (cv p) clog))
theorem df_cht : ccht = cmpt (λ x, cr) (λ x, csu (cin (co cc0 (cv x) cicc) cprime) (λ p, cfv (cv p) clog)) := rfl
def cvma : «class» := cmpt (λ x, cn) (λ x, csb (crab (λ p, wbr (cv p) (cv x) cdivides) (λ p, cprime)) (λ s, cif (wceq (cfv (cv s) chash) c1) (cfv (cuni (cv s)) clog) cc0))
theorem df_vma : cvma = cmpt (λ x, cn) (λ x, csb (crab (λ p, wbr (cv p) (cv x) cdivides) (λ p, cprime)) (λ s, cif (wceq (cfv (cv s) chash) c1) (cfv (cuni (cv s)) clog) cc0)) := rfl
def cchp : «class» := cmpt (λ x, cr) (λ x, csu (co c1 (cfv (cv x) cfl) cfz) (λ n, cfv (cv n) cvma))
theorem df_chp : cchp = cmpt (λ x, cr) (λ x, csu (co c1 (cfv (cv x) cfl) cfz) (λ n, cfv (cv n) cvma)) := rfl
def cppi : «class» := cmpt (λ x, cr) (λ x, cfv (cin (co cc0 (cv x) cicc) cprime) chash)
theorem df_ppi : cppi = cmpt (λ x, cr) (λ x, cfv (cin (co cc0 (cv x) cicc) cprime) chash) := rfl
def cmu : «class» := cmpt (λ x, cn) (λ x, cif (wrex (λ p, wbr (co (cv p) c2 cexp) (cv x) cdivides) (λ p, cprime)) cc0 (co (cneg c1) (cfv (crab (λ p, wbr (cv p) (cv x) cdivides) (λ p, cprime)) chash) cexp))
theorem df_mu : cmu = cmpt (λ x, cn) (λ x, cif (wrex (λ p, wbr (co (cv p) c2 cexp) (cv x) cdivides) (λ p, cprime)) cc0 (co (cneg c1) (cfv (crab (λ p, wbr (cv p) (cv x) cdivides) (λ p, cprime)) chash) cexp)) := rfl
def cdchr : «class» := cmpt (λ n, cn) (λ n, csb (cfv (cv n) czn) (λ z, csb (crab (λ x, wss (cxp (cdif (cfv (cv z) cbs) (cfv (cv z) cui)) (csn cc0)) (cv x)) (λ x, co (cfv (cv z) cmgp) (cfv ccnfld cmgp) cmhm)) (λ b, cpr (cop (cfv cnx cbs) (cv b)) (cop (cfv cnx cplusg) (cres (cof cmul) (cxp (cv b) (cv b)))))))
theorem df_dchr : cdchr = cmpt (λ n, cn) (λ n, csb (cfv (cv n) czn) (λ z, csb (crab (λ x, wss (cxp (cdif (cfv (cv z) cbs) (cfv (cv z) cui)) (csn cc0)) (cv x)) (λ x, co (cfv (cv z) cmgp) (cfv ccnfld cmgp) cmhm)) (λ b, cpr (cop (cfv cnx cbs) (cv b)) (cop (cfv cnx cplusg) (cres (cof cmul) (cxp (cv b) (cv b))))))) := rfl
end mm0
|
622894bedb3a7f950ba2a91a9368ea6b20a19524 | af6139dd14451ab8f69cf181cf3a20f22bd699be | /library/init/meta/decl_cmds.lean | 7869970a52407dfcf4061024a59435791632e25f | [
"Apache-2.0"
] | permissive | gitter-badger/lean-1 | 1cca01252d3113faa45681b6a00e1b5e3a0f6203 | 5c7ade4ee4f1cdf5028eabc5db949479d6737c85 | refs/heads/master | 1,611,425,383,521 | 1,487,871,140,000 | 1,487,871,140,000 | 82,995,612 | 0 | 0 | null | 1,487,905,618,000 | 1,487,905,618,000 | null | UTF-8 | Lean | false | false | 2,066 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.meta.tactic init.meta.rb_map
open tactic
private meta def apply_replacement (replacements : name_map name) (e : expr) : expr :=
e^.replace (λ e d,
match e with
| expr.const n ls :=
match replacements^.find n with
| some new_n := some (expr.const new_n ls)
| none := none
end
| _ := none
end)
/- Given a set of constant renamings `replacements` and a declaration name `src_decl_name`, create a new
declaration called `new_decl_name` s.t. its type is the type of `src_decl_name` after applying the
given constant replacement.
Remark: the new type must be definitionally equal to the type of `src_decl_name`.
Example:
Assume the environment contains
def f : nat -> nat := ...
def g : nat -> nat := f
lemma f_lemma : forall a, f a > 0 := ...
Moreover, assume we have a mapping M containing `f -> `g
Then, the command
run_command copy_decl_updating_type M `f_lemma `g_lemma
creates the declaration
lemma g_lemma : forall a, g a > 0 := ... -/
meta def copy_decl_updating_type (replacements : name_map name) (src_decl_name : name) (new_decl_name : name) : command :=
do env ← get_env,
decl ← env^.get src_decl_name,
decl ← return $ decl^.update_name $ new_decl_name,
decl ← return $ decl^.update_type $ apply_replacement replacements decl^.type,
decl ← return $ decl^.update_value $ expr.const src_decl_name (decl^.univ_params^.for level.param),
add_decl decl
meta def copy_decl_using (replacements : name_map name) (src_decl_name : name) (new_decl_name : name) : command :=
do env ← get_env,
decl ← env^.get src_decl_name,
decl ← return $ decl^.update_name $ new_decl_name,
decl ← return $ decl^.update_type $ apply_replacement replacements decl^.type,
decl ← return $ decl^.map_value $ apply_replacement replacements,
add_decl decl
|
3464318e8c458de663c2fd230786d133128458f0 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/1956.lean | f62b235542272ec9f693e07ce57de00d4f3ff2bc | [
"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 | 38 | lean | example : 1000 * 1000 = 123456 :=
rfl
|
0f76c8009f350cc08ec574b6269dc5c2e61e90a7 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/order/closure.lean | 7feb1e920037778f87a4b079fa64ab1dd7de10cc | [
"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 | 17,255 | lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Yaël Dillies
-/
import data.set_like.basic
import order.preorder_hom
import order.galois_connection
import tactic.monotonicity
/-!
# Closure operators between preorders
We define (bundled) closure operators on a preorder as monotone (increasing), extensive
(inflationary) and idempotent functions.
We define closed elements for the operator as elements which are fixed by it.
Lower adjoints to a function between preorders `u : β → α` allow to generalise closure operators to
situations where the closure operator we are dealing with naturally decomposes as `u ∘ l` where `l`
is a worthy function to have on its own. Typical examples include
`l : set G → subgroup G := subgroup.closure`, `u : subgroup G → set G := coe`, where `G` is a group.
This shows there is a close connection between closure operators, lower adjoints and Galois
connections/insertions: every Galois connection induces a lower adjoint which itself induces a
closure operator by composition (see `galois_connection.lower_adjoint` and
`lower_adjoint.closure_operator`), and every closure operator on a partial order induces a Galois
insertion from the set of closed elements to the underlying type (see `closure_operator.gi`).
## Main definitions
* `closure_operator`: A closure operator is a monotone function `f : α → α` such that
`∀ x, x ≤ f x` and `∀ x, f (f x) = f x`.
* `lower_adjoint`: A lower adjoint to `u : β → α` is a function `l : α → β` such that `l` and `u`
form a Galois connection.
## Implementation details
Although `lower_adjoint` is technically a generalisation of `closure_operator` (by defining
`to_fun := id`), it is desirable to have both as otherwise `id`s would be carried all over the
place when using concrete closure operators such as `convex_hull`.
`lower_adjoint` really is a semibundled `structure` version of `galois_connection`.
## References
* https://en.wikipedia.org/wiki/Closure_operator#Closure_operators_on_partially_ordered_sets
-/
universe u
/-! ### Closure operator -/
variable (α : Type*)
/-- A closure operator on the preorder `α` is a monotone function which is extensive (every `x`
is less than its closure) and idempotent. -/
structure closure_operator [preorder α] extends α →ₘ α :=
(le_closure' : ∀ x, x ≤ to_fun x)
(idempotent' : ∀ x, to_fun (to_fun x) = to_fun x)
namespace closure_operator
instance [preorder α] : has_coe_to_fun (closure_operator α) :=
{ F := _, coe := λ c, c.to_fun }
/-- See Note [custom simps projection] -/
def simps.apply [preorder α] (f : closure_operator α) : α → α := f
initialize_simps_projections closure_operator (to_preorder_hom_to_fun → apply, -to_preorder_hom)
section partial_order
variable [partial_order α]
/-- The identity function as a closure operator. -/
@[simps]
def id : closure_operator α :=
{ to_preorder_hom := preorder_hom.id,
le_closure' := λ _, le_rfl,
idempotent' := λ _, rfl }
instance : inhabited (closure_operator α) := ⟨id α⟩
variables {α} (c : closure_operator α)
@[ext] lemma ext :
∀ (c₁ c₂ : closure_operator α), (c₁ : α → α) = (c₂ : α → α) → c₁ = c₂
| ⟨⟨c₁, _⟩, _, _⟩ ⟨⟨c₂, _⟩, _, _⟩ h := by { congr, exact h }
/-- Constructor for a closure operator using the weaker idempotency axiom: `f (f x) ≤ f x`. -/
@[simps]
def mk' (f : α → α) (hf₁ : monotone f) (hf₂ : ∀ x, x ≤ f x) (hf₃ : ∀ x, f (f x) ≤ f x) :
closure_operator α :=
{ to_fun := f,
monotone' := hf₁,
le_closure' := hf₂,
idempotent' := λ x, (hf₃ x).antisymm (hf₁ (hf₂ x)) }
/-- Convenience constructor for a closure operator using the weaker minimality axiom:
`x ≤ f y → f x ≤ f y`, which is sometimes easier to prove in practice. -/
@[simps]
def mk₂ (f : α → α) (hf : ∀ x, x ≤ f x) (hmin : ∀ ⦃x y⦄, x ≤ f y → f x ≤ f y) :
closure_operator α :=
{ to_fun := f,
monotone' := λ x y hxy, hmin (hxy.trans (hf y)),
le_closure' := hf,
idempotent' := λ x, (hmin le_rfl).antisymm (hf _) }
/-- Expanded out version of `mk₂`. `p` implies being closed. This constructor should be used when
you already know a sufficient condition for being closed and using `mem_mk₃_closed` will avoid you
the (slight) hassle of having to prove it both inside and outside the constructor. -/
@[simps]
def mk₃ (f : α → α) (p : α → Prop) (hf : ∀ x, x ≤ f x) (hfp : ∀ x, p (f x))
(hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y) :
closure_operator α :=
mk₂ f hf (λ x y hxy, hmin hxy (hfp y))
/-- This lemma shows that the image of `x` of a closure operator built from the `mk₃` constructor
respects `p`, the property that was fed into it. -/
lemma closure_mem_mk₃ {f : α → α} {p : α → Prop} {hf : ∀ x, x ≤ f x} {hfp : ∀ x, p (f x)}
{hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y} (x : α) :
p (mk₃ f p hf hfp hmin x) :=
hfp x
/-- Analogue of `closure_le_closed_iff_le` but with the `p` that was fed into the `mk₃` constructor.
-/
lemma closure_le_mk₃_iff {f : α → α} {p : α → Prop} {hf : ∀ x, x ≤ f x} {hfp : ∀ x, p (f x)}
{hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y} {x y : α} (hxy : x ≤ y) (hy : p y) :
mk₃ f p hf hfp hmin x ≤ y :=
hmin hxy hy
@[mono] lemma monotone : monotone c := c.monotone'
/-- Every element is less than its closure. This property is sometimes referred to as extensivity or
inflationarity. -/
lemma le_closure (x : α) : x ≤ c x := c.le_closure' x
@[simp] lemma idempotent (x : α) : c (c x) = c x := c.idempotent' x
lemma le_closure_iff (x y : α) : x ≤ c y ↔ c x ≤ c y :=
⟨λ h, c.idempotent y ▸ c.monotone h, λ h, (c.le_closure x).trans h⟩
/-- An element `x` is closed for the closure operator `c` if it is a fixed point for it. -/
def closed : set α := λ x, c x = x
lemma mem_closed_iff (x : α) : x ∈ c.closed ↔ c x = x := iff.rfl
lemma mem_closed_iff_closure_le (x : α) : x ∈ c.closed ↔ c x ≤ x :=
⟨le_of_eq, λ h, h.antisymm (c.le_closure x)⟩
lemma closure_eq_self_of_mem_closed {x : α} (h : x ∈ c.closed) : c x = x := h
@[simp] lemma closure_is_closed (x : α) : c x ∈ c.closed := c.idempotent x
/-- The set of closed elements for `c` is exactly its range. -/
lemma closed_eq_range_close : c.closed = set.range c :=
set.ext $ λ x, ⟨λ h, ⟨x, h⟩, by { rintro ⟨y, rfl⟩, apply c.idempotent }⟩
/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/
def to_closed (x : α) : c.closed := ⟨c x, c.closure_is_closed x⟩
@[simp] lemma closure_le_closed_iff_le (x : α) {y : α} (hy : c.closed y) : c x ≤ y ↔ x ≤ y :=
by rw [←c.closure_eq_self_of_mem_closed hy, ←le_closure_iff]
/-- A closure operator is equal to the closure operator obtained by feeding `c.closed` into the
`mk₃` constructor. -/
lemma eq_mk₃_closed (c : closure_operator α) :
c = mk₃ c c.closed c.le_closure c.closure_is_closed
(λ x y hxy hy, (c.closure_le_closed_iff_le x hy).2 hxy) :=
by { ext, refl }
/-- The property `p` fed into the `mk₃` constructor implies being closed. -/
lemma mem_mk₃_closed {f : α → α} {p : α → Prop} {hf : ∀ x, x ≤ f x} {hfp : ∀ x, p (f x)}
{hmin : ∀ ⦃x y⦄, x ≤ y → p y → f x ≤ y} {x : α} (hx : p x) :
x ∈ (mk₃ f p hf hfp hmin).closed :=
(hmin (le_refl _) hx).antisymm (hf _)
end partial_order
variable {α}
section order_top
variables [order_top α] (c : closure_operator α)
@[simp] lemma closure_top : c ⊤ = ⊤ :=
le_top.antisymm (c.le_closure _)
lemma top_mem_closed : ⊤ ∈ c.closed :=
c.closure_top
end order_top
lemma closure_inf_le [semilattice_inf α] (c : closure_operator α) (x y : α) :
c (x ⊓ y) ≤ c x ⊓ c y :=
c.monotone.map_inf_le _ _
section semilattice_sup
variables [semilattice_sup α] (c : closure_operator α)
lemma closure_sup_closure_le (x y : α) :
c x ⊔ c y ≤ c (x ⊔ y) :=
c.monotone.le_map_sup _ _
lemma closure_sup_closure_left (x y : α) :
c (c x ⊔ y) = c (x ⊔ y) :=
((c.le_closure_iff _ _).1 (sup_le (c.monotone le_sup_left) (le_sup_right.trans
(c.le_closure _)))).antisymm (c.monotone (sup_le_sup_right (c.le_closure _) _))
lemma closure_sup_closure_right (x y : α) :
c (x ⊔ c y) = c (x ⊔ y) :=
by rw [sup_comm, closure_sup_closure_left, sup_comm]
lemma closure_sup_closure (x y : α) :
c (c x ⊔ c y) = c (x ⊔ y) :=
by rw [closure_sup_closure_left, closure_sup_closure_right]
end semilattice_sup
section complete_lattice
variables [complete_lattice α] (c : closure_operator α)
lemma closure_supr_closure {ι : Type u} (x : ι → α) :
c (⨆ i, c (x i)) = c (⨆ i, x i) :=
le_antisymm ((c.le_closure_iff _ _).1 (supr_le (λ i, c.monotone
(le_supr x i)))) (c.monotone (supr_le_supr (λ i, c.le_closure _)))
lemma closure_bsupr_closure (p : α → Prop) :
c (⨆ x (H : p x), c x) = c (⨆ x (H : p x), x) :=
le_antisymm ((c.le_closure_iff _ _).1 (bsupr_le (λ x hx, c.monotone
(le_bsupr_of_le x hx (le_refl x))))) (c.monotone (bsupr_le_bsupr (λ x hx, c.le_closure x)))
end complete_lattice
end closure_operator
/-! ### Lower adjoint -/
variables {α} {β : Type*}
/-- A lower adjoint of `u` on the preorder `α` is a function `l` such that `l` and `u` form a Galois
connection. It allows us to define closure operators whose output does not match the input. In
practice, `u` is often `coe : β → α`. -/
structure lower_adjoint [preorder α] [preorder β] (u : β → α) :=
(to_fun : α → β)
(gc' : galois_connection to_fun u)
namespace lower_adjoint
variable (α)
/-- The identity function as a lower adjoint to itself. -/
@[simps]
protected def id [preorder α] : lower_adjoint (id : α → α) :=
{ to_fun := λ x, x,
gc' := galois_connection.id }
variable {α}
instance [preorder α] : inhabited (lower_adjoint (id : α → α)) := ⟨lower_adjoint.id α⟩
section preorder
variables [preorder α] [preorder β] {u : β → α} (l : lower_adjoint u)
instance : has_coe_to_fun (lower_adjoint u) :=
{ F := λ _, α → β, coe := to_fun }
/-- See Note [custom simps projection] -/
def simps.apply : α → β := l
lemma gc : galois_connection l u := l.gc'
@[ext] lemma ext :
∀ (l₁ l₂ : lower_adjoint u), (l₁ : α → β) = (l₂ : α → β) → l₁ = l₂
| ⟨l₁, _⟩ ⟨l₂, _⟩ h := by { congr, exact h }
@[mono] lemma monotone : monotone (u ∘ l) := l.gc.monotone_u.comp l.gc.monotone_l
/-- Every element is less than its closure. This property is sometimes referred to as extensivity or
inflationarity. -/
lemma le_closure (x : α) : x ≤ u (l x) := l.gc.le_u_l _
end preorder
section partial_order
variables [partial_order α] [preorder β] {u : β → α} (l : lower_adjoint u)
/-- Every lower adjoint induces a closure operator given by the composition. This is the partial
order version of the statement that every adjunction induces a monad. -/
@[simps]
def closure_operator :
closure_operator α :=
{ to_fun := λ x, u (l x),
monotone' := l.monotone,
le_closure' := l.le_closure,
idempotent' := λ x, show (u ∘ l ∘ u) (l x) = u (l x), by rw l.gc.u_l_u_eq_u }
lemma idempotent (x : α) : u (l (u (l x))) = u (l x) :=
l.closure_operator.idempotent _
lemma le_closure_iff (x y : α) : x ≤ u (l y) ↔ u (l x) ≤ u (l y) :=
l.closure_operator.le_closure_iff _ _
end partial_order
section preorder
variables [preorder α] [preorder β] {u : β → α} (l : lower_adjoint u)
/-- An element `x` is closed for `l : lower_adjoint u` if it is a fixed point: `u (l x) = x` -/
def closed : set α := λ x, u (l x) = x
lemma mem_closed_iff (x : α) : x ∈ l.closed ↔ u (l x) = x := iff.rfl
lemma closure_eq_self_of_mem_closed {x : α} (h : x ∈ l.closed) : u (l x) = x := h
end preorder
section partial_order
variables [partial_order α] [partial_order β] {u : β → α} (l : lower_adjoint u)
lemma mem_closed_iff_closure_le (x : α) : x ∈ l.closed ↔ u (l x) ≤ x :=
l.closure_operator.mem_closed_iff_closure_le _
@[simp] lemma closure_is_closed (x : α) : u (l x) ∈ l.closed := l.idempotent x
/-- The set of closed elements for `l` is the range of `u ∘ l`. -/
lemma closed_eq_range_close : l.closed = set.range (u ∘ l) :=
l.closure_operator.closed_eq_range_close
/-- Send an `x` to an element of the set of closed elements (by taking the closure). -/
def to_closed (x : α) : l.closed := ⟨u (l x), l.closure_is_closed x⟩
@[simp] lemma closure_le_closed_iff_le (x : α) {y : α} (hy : l.closed y) : u (l x) ≤ y ↔ x ≤ y :=
l.closure_operator.closure_le_closed_iff_le x hy
end partial_order
lemma closure_top [order_top α] [preorder β] {u : β → α} (l : lower_adjoint u) :
u (l ⊤) = ⊤ :=
l.closure_operator.closure_top
lemma closure_inf_le [semilattice_inf α] [preorder β] {u : β → α} (l : lower_adjoint u) (x y : α) :
u (l (x ⊓ y)) ≤ u (l x) ⊓ u (l y) :=
l.closure_operator.closure_inf_le x y
section semilattice_sup
variables [semilattice_sup α] [preorder β] {u : β → α} (l : lower_adjoint u)
lemma closure_sup_closure_le (x y : α) :
u (l x) ⊔ u (l y) ≤ u (l (x ⊔ y)) :=
l.closure_operator.closure_sup_closure_le x y
lemma closure_sup_closure_left (x y : α) :
u (l (u (l x) ⊔ y)) = u (l (x ⊔ y)) :=
l.closure_operator.closure_sup_closure_left x y
lemma closure_sup_closure_right (x y : α) :
u (l (x ⊔ u (l y))) = u (l (x ⊔ y)) :=
l.closure_operator.closure_sup_closure_right x y
lemma closure_sup_closure (x y : α) :
u (l (u (l x) ⊔ u (l y))) = u (l (x ⊔ y)) :=
l.closure_operator.closure_sup_closure x y
end semilattice_sup
section complete_lattice
variables [complete_lattice α] [preorder β] {u : β → α} (l : lower_adjoint u)
lemma closure_supr_closure {ι : Type u} (x : ι → α) :
u (l (⨆ i, u (l (x i)))) = u (l (⨆ i, x i)) :=
l.closure_operator.closure_supr_closure x
lemma closure_bsupr_closure (p : α → Prop) :
u (l (⨆ x (H : p x), u (l x))) = u (l (⨆ x (H : p x), x)) :=
l.closure_operator.closure_bsupr_closure p
end complete_lattice
/- Lemmas for `lower_adjoint (coe : α → set β)`, where `set_like α β` -/
section coe_to_set
variables [set_like α β] (l : lower_adjoint (coe : α → set β))
lemma subset_closure (s : set β) : s ⊆ l s :=
l.le_closure s
lemma le_iff_subset (s : set β) (S : α) : l s ≤ S ↔ s ⊆ S :=
l.gc s S
lemma mem_iff (s : set β) (x : β) : x ∈ l s ↔ ∀ S : α, s ⊆ S → x ∈ S :=
by { simp_rw [←set_like.mem_coe, ←set.singleton_subset_iff, ←l.le_iff_subset],
exact ⟨λ h S, h.trans, λ h, h _ le_rfl⟩ }
lemma eq_of_le {s : set β} {S : α} (h₁ : s ⊆ S) (h₂ : S ≤ l s) : l s = S :=
((l.le_iff_subset _ _).2 h₁).antisymm h₂
lemma closure_union_closure_subset (x y : α) :
(l x : set β) ∪ (l y) ⊆ l (x ∪ y) :=
l.closure_sup_closure_le x y
@[simp] lemma closure_union_closure_left (x y : α) :
(l ((l x) ∪ y) : set β) = l (x ∪ y) :=
l.closure_sup_closure_left x y
@[simp] lemma closure_union_closure_right (x y : α) :
l (x ∪ (l y)) = l (x ∪ y) :=
set_like.coe_injective (l.closure_sup_closure_right x y)
@[simp] lemma closure_union_closure (x y : α) :
l ((l x) ∪ (l y)) = l (x ∪ y) :=
set_like.coe_injective (l.closure_operator.closure_sup_closure x y)
@[simp] lemma closure_Union_closure {ι : Type u} (x : ι → α) :
l (⋃ i, l (x i)) = l (⋃ i, x i) :=
set_like.coe_injective (l.closure_supr_closure (coe ∘ x))
@[simp] lemma closure_bUnion_closure (p : set β → Prop) :
l (⋃ x (H : p x), l x) = l (⋃ x (H : p x), x) :=
set_like.coe_injective (l.closure_bsupr_closure p)
end coe_to_set
end lower_adjoint
/-! ### Translations between `galois_connection`, `lower_adjoint`, `closure_operator` -/
variable {α}
/-- Every Galois connection induces a lower adjoint. -/
@[simps]
def galois_connection.lower_adjoint [preorder α] [preorder β] {l : α → β} {u : β → α}
(gc : galois_connection l u) :
lower_adjoint u :=
{ to_fun := l,
gc' := gc }
/-- Every Galois connection induces a closure operator given by the composition. This is the partial
order version of the statement that every adjunction induces a monad. -/
@[simps]
def galois_connection.closure_operator [partial_order α] [preorder β] {l : α → β} {u : β → α}
(gc : galois_connection l u) :
closure_operator α :=
gc.lower_adjoint.closure_operator
/-- The set of closed elements has a Galois insertion to the underlying type. -/
def closure_operator.gi [partial_order α] (c : closure_operator α) :
galois_insertion c.to_closed coe :=
{ choice := λ x hx, ⟨x, hx.antisymm (c.le_closure x)⟩,
gc := λ x y, (c.closure_le_closed_iff_le _ y.2),
le_l_u := λ x, c.le_closure _,
choice_eq := λ x hx, le_antisymm (c.le_closure x) hx }
/-- The Galois insertion associated to a closure operator can be used to reconstruct the closure
operator.
Note that the inverse in the opposite direction does not hold in general. -/
@[simp]
lemma closure_operator_gi_self [partial_order α] (c : closure_operator α) :
c.gi.gc.closure_operator = c :=
by { ext x, refl }
|
8dc7e3198a120069cb16c588fd51cfa2aa26acc9 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/tactic/generalizes.lean | 691c7926346fe566248fa926203210df31b3eb07 | [
"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 | 8,901 | lean | /-
Copyright (c) 2020 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import tactic.core
/-!
# The `generalizes` tactic
This module defines the `tactic.generalizes'` tactic and its interactive version
`tactic.interactive.generalizes`. These work like `generalize`, but they can
generalize over multiple expressions at once. This is particularly handy when
there are dependencies between the expressions, in which case `generalize` will
usually fail but `generalizes` may succeed.
## Implementation notes
To generalize the target `T` over expressions `j₁ : J₁, ..., jₙ : Jₙ`, we first
create the new target type
T' = ∀ (k₁ : J₁) ... (kₙ : Jₙ) (k₁_eq : k₁ = j₁) ... (kₙ_eq : kₙ == jₙ), U
where `U` is `T` with any occurrences of the `jᵢ` replaced by the corresponding
`kᵢ`. Note that some of the `kᵢ_eq` may be heterogeneous; this happens when
there are dependencies between the `jᵢ`. The construction of `T'` is performed
by `generalizes.step1` and `generalizes.step2`.
Having constructed `T'`, we can `assert` it and use it to construct a proof of
the original target by instantiating the binders with
j₁ ... jₙ (eq.refl j₁) ... (heq.refl jₙ).
This leaves us with a generalized goal. This construction is performed by
`generalizes.step3`.
-/
universes u v w
namespace tactic
open expr
namespace generalizes
/--
Input:
- Target expression `e`.
- List of expressions `jᵢ` to be generalised, along with a name for the local
const that will replace them. The `jᵢ` must be in dependency order:
`[n, fin n]` is okay but `[fin n, n]` is not.
Output:
- List of new local constants `kᵢ`, one for each `jᵢ`.
- `e` with the `jᵢ` replaced by the `kᵢ`, i.e. `e[jᵢ := kᵢ]...[j₀ := k₀]`.
Note that the substitution also affects the types of the `kᵢ`: If `jᵢ : Jᵢ` then
`kᵢ : Jᵢ[jᵢ₋₁ := kᵢ₋₁]...[j₀ := k₀]`.
The transparency `md` and the boolean `unify` are passed to `kabstract` when we
abstract over occurrences of the `jᵢ` in `e`.
-/
meta def step1 (md : transparency) (unify : bool)
(e : expr) (to_generalize : list (name × expr)) : tactic (expr × list expr) := do
let go : name × expr → expr × list expr → tactic (expr × list expr) :=
λ ⟨n, j⟩ ⟨e, ks⟩, do {
J ← infer_type j,
k ← mk_local' n binder_info.default J,
e ← kreplace e j k md unify,
ks ← ks.mmap $ λ k', kreplace k' j k md unify,
pure (e, k :: ks) },
to_generalize.mfoldr go (e, [])
/--
Input: for each equation that should be generated: the equation name, the
argument `jᵢ` and the corresponding local constant `kᵢ` from step 1.
Output: for each element of the input list a new local constant of type
`jᵢ = kᵢ` or `jᵢ == kᵢ` and a proof of `jᵢ = jᵢ` or `jᵢ == jᵢ`.
The transparency `md` is used when determining whether the type of `jᵢ` is defeq
to the type of `kᵢ` (and thus whether to generate a homogeneous or heterogeneous
equation).
-/
meta def step2 (md : transparency)
(to_generalize : list (name × expr × expr))
: tactic (list (expr × expr)) :=
to_generalize.mmap $ λ ⟨n, j, k⟩, do
J ← infer_type j,
K ← infer_type k,
sort u ← infer_type K |
fail! "generalizes'/step2: expected the type of {K} to be a sort",
homogeneous ← succeeds $ is_def_eq J K md,
let ⟨eq_type, eq_proof⟩ :=
if homogeneous
then ((const `eq [u]) K k j , (const `eq.refl [u]) J j)
else ((const `heq [u]) K k J j, (const `heq.refl [u]) J j),
eq ← mk_local' n binder_info.default eq_type,
pure (eq, eq_proof)
/--
Input: The `jᵢ`; the local constants `kᵢ` from step 1; the equations and their
proofs from step 2.
This step is the first one that changes the goal (and also the last one
overall). It asserts the generalized goal, then derives the current goal from
it. This leaves us with the generalized goal.
-/
meta def step3 (e : expr) (js ks eqs eq_proofs : list expr)
: tactic unit :=
focus1 $ do
let new_target_type := (e.pis eqs).pis ks,
type_check new_target_type <|> fail!
("generalizes': unable to generalize the target because the generalized target type does not" ++
" type check:\n{new_target_type}"),
n ← mk_fresh_name,
new_target ← assert n new_target_type,
swap,
let target_proof := new_target.mk_app $ js ++ eq_proofs,
exact target_proof
end generalizes
open generalizes
/--
Generalizes the target over each of the expressions in `args`. Given
`args = [(a₁, h₁, arg₁), ...]`, this changes the target to
∀ (a₁ : T₁) ... (h₁ : a₁ = arg₁) ..., U
where `U` is the current target with every occurrence of `argᵢ` replaced by
`aᵢ`. A similar effect can be achieved by using `generalize` once for each of
the `args`, but if there are dependencies between the `args`, this may fail to
perform some generalizations.
The replacement is performed using keyed matching/unification with transparency
`md`. `unify` determines whether matching or unification is used. See
`kabstract`.
The `args` must be given in dependency order, so `[n, fin n]` is okay but
`[fin n, n]` will result in an error.
After generalizing the `args`, the target type may no longer type check.
`generalizes'` will then raise an error.
-/
meta def generalizes' (args : list (name × option name × expr))
(md := semireducible) (unify := tt) : tactic unit := do
tgt ← target,
let stage1_args := args.map $ λ ⟨n, _, j⟩, (n, j),
⟨e, ks⟩ ← step1 md unify tgt stage1_args,
let stage2_args : list (option (name × expr × expr)) :=
args.map₂ (λ ⟨_, eq_name, j⟩ k, eq_name.map $ λ eq_name, (eq_name, j, k)) ks,
let stage2_args := stage2_args.reduce_option,
eqs_and_proofs ← step2 md stage2_args,
let eqs := eqs_and_proofs.map prod.fst,
let eq_proofs := eqs_and_proofs.map prod.snd,
let js := args.map (prod.snd ∘ prod.snd),
step3 e js ks eqs eq_proofs
/--
Like `generalizes'`, but also introduces the generalized constants and their
associated equations into the context.
-/
meta def generalizes_intro (args : list (name × option name × expr))
(md := semireducible) (unify := tt) : tactic (list expr × list expr) := do
generalizes' args md unify,
ks ← intron' args.length,
eqs ← intron' $ args.countp $ λ x, x.snd.fst.is_some,
pure (ks, eqs)
namespace interactive
setup_tactic_parser
private meta def generalizes_arg_parser_eq : pexpr → lean.parser (pexpr × name)
| (app (app (macro _ [const `eq _ ]) e) (local_const x _ _ _)) := pure (e, x)
| (app (app (macro _ [const `heq _ ]) e) (local_const x _ _ _)) := pure (e, x)
| _ := failure
private meta def generalizes_arg_parser : lean.parser (name × option name × pexpr) :=
with_desc "(id :)? expr = id" $ do
lhs ← lean.parser.pexpr 0,
(tk ":" >> match lhs with
| local_const hyp_name _ _ _ := do
(arg, arg_name) ← lean.parser.pexpr 0 >>= generalizes_arg_parser_eq,
pure (arg_name, some hyp_name, arg)
| _ := failure
end) <|>
(do
(arg, arg_name) ← generalizes_arg_parser_eq lhs,
pure (arg_name, none, arg))
private meta def generalizes_args_parser
: lean.parser (list (name × option name × pexpr)) :=
with_desc "[(id :)? expr = id, ...]" $
tk "[" *> sep_by (tk ",") generalizes_arg_parser <* tk "]"
/--
Generalizes the target over multiple expressions. For example, given the goal
P : ∀ n, fin n → Prop
n : ℕ
f : fin n
⊢ P (nat.succ n) (fin.succ f)
you can use `generalizes [n'_eq : nat.succ n = n', f'_eq : fin.succ f == f']` to
get
P : ∀ n, fin n → Prop
n : ℕ
f : fin n
n' : ℕ
n'_eq : n' = nat.succ n
f' : fin n'
f'_eq : f' == fin.succ f
⊢ P n' f'
The expressions must be given in dependency order, so
`[f'_eq : fin.succ f == f', n'_eq : nat.succ n = n']` would fail since the type
of `fin.succ f` is `nat.succ n`.
You can choose to omit some or all of the generated equations. For the above
example, `generalizes [nat.succ n = n', fin.succ f == f']` gets you
P : ∀ n, fin n → Prop
n : ℕ
f : fin n
n' : ℕ
f' : fin n'
⊢ P n' f'
After generalization, the target type may no longer type check. `generalizes`
will then raise an error.
-/
meta def generalizes (args : parse generalizes_args_parser) : tactic unit :=
propagate_tags $ do
args ← args.mmap $ λ ⟨arg_name, hyp_name, arg⟩, do {
arg ← to_expr arg,
pure (arg_name, hyp_name, arg) },
generalizes_intro args,
pure ()
add_tactic_doc
{ name := "generalizes",
category := doc_category.tactic,
decl_names := [`tactic.interactive.generalizes],
tags := ["context management"],
inherit_description_from := `tactic.interactive.generalizes }
end interactive
end tactic
|
f6eac3d4015fc699b6d67365f258eb4f681ca3d8 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/homology/differential_object.lean | 03f8f3839d349fd516f07b61624e00007620fc18 | [
"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 | 5,077 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.homology.homological_complex
import category_theory.differential_object
/-!
# Homological complexes are differential graded objects.
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We verify that a `homological_complex` indexed by an `add_comm_group` is
essentially the same thing as a differential graded object.
This equivalence is probably not particularly useful in practice;
it's here to check that definitions match up as expected.
-/
open category_theory
open category_theory.limits
open_locale classical
noncomputable theory
namespace homological_complex
variables {β : Type*} [add_comm_group β] {b : β}
variables {V : Type*} [category V] [has_zero_morphisms V]
/-- Since `eq_to_hom` only preserves the fact that `X.X i = X.X j` but not `i = j`, this definition
is used to aid the simplifier. -/
abbreviation _root_.category_theory.differential_object.X_eq_to_hom
(X : differential_object (graded_object_with_shift b V))
{i j : β} (h : i = j) : X.X i ⟶ X.X j := eq_to_hom (congr_arg X.X h)
@[simp] lemma _root_.category_theory.differential_object.X_eq_to_hom_refl
(X : differential_object (graded_object_with_shift b V)) (i : β) :
X.X_eq_to_hom (refl i) = 𝟙 _ := rfl
@[simp, reassoc] lemma eq_to_hom_d (X : differential_object (graded_object_with_shift b V))
{x y : β} (h : x = y) :
X.X_eq_to_hom h ≫ X.d y = X.d x ≫ X.X_eq_to_hom (by { cases h, refl }) :=
by { cases h, dsimp, simp }
@[simp, reassoc] lemma d_eq_to_hom (X : homological_complex V (complex_shape.up' b))
{x y z : β} (h : y = z) :
X.d x y ≫ eq_to_hom (congr_arg X.X h) = X.d x z :=
by { cases h, simp }
@[simp, reassoc] lemma eq_to_hom_f' {X Y : differential_object (graded_object_with_shift b V)}
(f : X ⟶ Y) {x y : β} (h : x = y) :
X.X_eq_to_hom h ≫ f.f y = f.f x ≫ Y.X_eq_to_hom h :=
by { cases h, simp }
variables (b V)
local attribute [reducible] graded_object.has_shift
/--
The functor from differential graded objects to homological complexes.
-/
@[simps]
def dgo_to_homological_complex :
differential_object (graded_object_with_shift b V) ⥤
homological_complex V (complex_shape.up' b) :=
{ obj := λ X,
{ X := λ i, X.X i,
d := λ i j, if h : i + b = j then
X.d i ≫ X.X_eq_to_hom (show i + (1 : ℤ) • b = j, by simp [h]) else 0,
shape' := λ i j w, by { dsimp at w, convert dif_neg w },
d_comp_d' := λ i j k hij hjk, begin
dsimp at hij hjk, substs hij hjk,
have : X.d i ≫ X.d _ = _ := (congr_fun X.d_squared i : _),
reassoc! this,
simp [this],
end },
map := λ X Y f,
{ f := f.f,
comm' := λ i j h, begin
dsimp at h ⊢,
subst h,
have : f.f i ≫ Y.d i = X.d i ≫ f.f (i + 1 • b) := (congr_fun f.comm i).symm,
reassoc! this,
simp only [category.comp_id, eq_to_hom_refl, dif_pos rfl, this, category.assoc, eq_to_hom_f']
end, } }
/--
The functor from homological complexes to differential graded objects.
-/
@[simps]
def homological_complex_to_dgo :
homological_complex V (complex_shape.up' b) ⥤
differential_object (graded_object_with_shift b V) :=
{ obj := λ X,
{ X := λ i, X.X i,
d := λ i, X.d i (i + 1 • b),
d_squared' := by { ext i, dsimp, simp, } },
map := λ X Y f,
{ f := f.f,
comm' := by { ext i, dsimp, simp, }, } }
/--
The unit isomorphism for `dgo_equiv_homological_complex`.
-/
@[simps]
def dgo_equiv_homological_complex_unit_iso :
𝟭 (differential_object (graded_object_with_shift b V)) ≅
dgo_to_homological_complex b V ⋙ homological_complex_to_dgo b V :=
nat_iso.of_components (λ X,
{ hom := { f := λ i, 𝟙 (X.X i), },
inv := { f := λ i, 𝟙 (X.X i), }, }) (by tidy)
/--
The counit isomorphism for `dgo_equiv_homological_complex`.
-/
@[simps]
def dgo_equiv_homological_complex_counit_iso :
homological_complex_to_dgo b V ⋙ dgo_to_homological_complex b V ≅
𝟭 (homological_complex V (complex_shape.up' b)) :=
nat_iso.of_components (λ X,
{ hom :=
{ f := λ i, 𝟙 (X.X i),
comm' := λ i j h, begin
dsimp at h ⊢, subst h,
delta homological_complex_to_dgo,
simp,
end },
inv :=
{ f := λ i, 𝟙 (X.X i),
comm' := λ i j h, begin
dsimp at h ⊢, subst h,
delta homological_complex_to_dgo,
simp,
end }, }) (by tidy)
/--
The category of differential graded objects in `V` is equivalent
to the category of homological complexes in `V`.
-/
@[simps]
def dgo_equiv_homological_complex :
differential_object (graded_object_with_shift b V) ≌
homological_complex V (complex_shape.up' b) :=
{ functor := dgo_to_homological_complex b V,
inverse := homological_complex_to_dgo b V,
unit_iso := dgo_equiv_homological_complex_unit_iso b V,
counit_iso := dgo_equiv_homological_complex_counit_iso b V, }
end homological_complex
|
7493f92835bfc9221fac3807bb85fe4dbf452abd | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/topology/sheaves/sheaf_condition/sites.lean | 911d141b211caffaf36867bcac6326fe8ffc883e | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 20,078 | lean | /-
Copyright (c) 2021 Justus Springer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Justus Springer
-/
import category_theory.sites.sheaf
import category_theory.sites.spaces
import topology.sheaves.sheaf
/-!
# The sheaf condition in terms of sites.
The theory of sheaves on sites is developed independently from sheaves on spaces in
`category_theory/sites`. In this file, we connect the two theories: We show that for a topological
space `X`, a presheaf `F : (opens X)ᵒᵖ ⥤ C` is a sheaf on the site `opens X` if and only if it is
a sheaf on `X` in the usual sense.
Recall that a presheaf `F : (opens X)ᵒᵖ ⥤ C` is called a *sheaf* on the space `X`, if for every
family of opens `U : ι → opens X`, the object `F.obj (op (supr U))` is the limit of some fork
diagram. On the other hand, `F` is called a *sheaf* on the site `opens X`, if for every open set
`U : opens X` and every presieve `R : presieve U`, the object `F.obj (op U)` is the limit of a
very similar fork diagram. In this file, we will construct the two functions `covering_of_presieve`
and `presieve_of_covering`, which translate between the two concepts. We then prove a bunch of
naturality lemmas relating the two fork diagrams to each other.
## Main statements
* `is_sheaf_sites_iff_is_sheaf_spaces`. A presheaf `F : (opens X)ᵒᵖ ⥤ C` is a sheaf on the site
`opens X` if and only if it is a sheaf on the space `X`.
* `Sheaf_sites_eq_sheaf_spaces`. The type of sheaves on the site `opens X` is *equal* to the type
of sheaves on the space `X`.
-/
noncomputable theory
universes u v
namespace Top.presheaf
open category_theory topological_space Top category_theory.limits opposite
open Top.presheaf.sheaf_condition_equalizer_products
variables {C : Type u} [category.{v} C] [has_products C]
variables {X : Top.{v}} (F : presheaf C X)
/--
Given a presieve `R` on `U`, we obtain a covering family of open sets in `X`, by taking as index
type the type of dependent pairs `(V, f)`, where `f : V ⟶ U` is in `R`.
-/
def covering_of_presieve (U : opens X) (R : presieve U) : (Σ V, {f : V ⟶ U // R f}) → opens X :=
λ f, f.1
@[simp]
lemma covering_of_presieve_apply (U : opens X) (R : presieve U) (f : Σ V, {f : V ⟶ U // R f}) :
covering_of_presieve U R f = f.1 := rfl
namespace covering_of_presieve
variables (U : opens X) (R : presieve U)
/-!
In this section, we will relate two different fork diagrams to each other.
The first one is the defining fork diagram for the sheaf condition in terms of sites, applied to
the presieve `R`. It will henceforth be called the _sites diagram_. Its objects are called
`presheaf.first_obj` and `presheaf.second_obj` and its morphisms are `presheaf.first_map` and
`presheaf.second_obj`. The fork map into this diagram is called `presheaf.fork_map`.
The second one is the defining fork diagram for the sheaf condition in terms of spaces, applied to
the family of opens `covering_of_presieve U R`. It will henceforth be called the _spaces diagram_.
Its objects are called `pi_opens` and `pi_inters` and its morphisms are `left_res` and `right_res`.
The fork map into this diagram is called `res`.
-/
/--
If `R` is a presieve in the grothendieck topology on `opens X`, the covering family associated to
`R` really is _covering_, i.e. the union of all open sets equals `U`.
-/
lemma supr_eq_of_mem_grothendieck (hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
supr (covering_of_presieve U R) = U :=
begin
apply le_antisymm,
{ refine supr_le _,
intro f,
exact f.2.1.le, },
intros x hxU,
rw [subtype.val_eq_coe, opens.mem_coe, opens.mem_supr],
obtain ⟨V, iVU, ⟨W, iVW, iWU, hiWU, -⟩, hxV⟩ := hR x hxU,
exact ⟨⟨W, ⟨iWU, hiWU⟩⟩, iVW.le hxV⟩,
end
/--
The first object in the sites diagram is isomorphic to the first object in the spaces diagram.
Actually, they are even definitionally equal, but it is convenient to give this isomorphism a name.
-/
def first_obj_iso_pi_opens : presheaf.first_obj R F ≅ pi_opens F (covering_of_presieve U R) :=
eq_to_iso rfl
/--
The isomorphism `first_obj_iso_pi_opens` is compatible with canonical projections out of the
product.
-/
lemma first_obj_iso_pi_opens_π (f : Σ V, {f : V ⟶ U // R f}) :
(first_obj_iso_pi_opens F U R).hom ≫ pi.π _ f = pi.π _ f :=
category.id_comp _
/--
The second object in the sites diagram is isomorphic to the second object in the spaces diagram.
-/
def second_obj_iso_pi_inters :
presheaf.second_obj R F ≅ pi_inters F (covering_of_presieve U R) :=
has_limit.iso_of_nat_iso $ discrete.nat_iso $ λ i,
F.map_iso (eq_to_iso (complete_lattice.pullback_eq_inf _ _).symm).op
/--
The isomorphism `second_obj_iso_pi_inters` is compatible with canonical projections out of the
product. Here, we have to insert an `eq_to_hom` arrow to pass from
`F.obj (op (pullback f.2.1 g.2.1))` to `F.obj (op (f.1 ⊓ g.1))`.
-/
lemma second_obj_iso_pi_inters_π (f g : Σ V, {f : V ⟶ U // R f}) :
(second_obj_iso_pi_inters F U R).hom ≫ pi.π _ (f, g) =
pi.π _ (f, g) ≫ F.map (eq_to_hom (complete_lattice.pullback_eq_inf f.2.1 g.2.1).symm).op :=
begin
dunfold second_obj_iso_pi_inters,
rw has_limit.iso_of_nat_iso_hom_π,
refl,
end
/--
Composing the fork map of the sites diagram with the isomorphism `first_obj_iso_pi_opens` is the
same as the fork map of the spaces diagram (modulo an `eq_to_hom` arrow).
-/
lemma fork_map_comp_first_obj_iso_pi_opens_eq
(hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
presheaf.fork_map R F ≫ (first_obj_iso_pi_opens F U R).hom =
F.map (eq_to_hom (supr_eq_of_mem_grothendieck U R hR)).op ≫ res F (covering_of_presieve U R) :=
begin
ext f,
rw [category.assoc, category.assoc],
rw first_obj_iso_pi_opens_π,
dunfold presheaf.fork_map res,
rw [limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app, ← F.map_comp],
congr,
end
/--
First naturality condition. Under the isomorphisms `first_obj_iso_pi_opens` and
`second_obj_iso_pi_inters`, the map `presheaf.first_map` corresponds to `left_res`.
-/
lemma first_obj_iso_comp_left_res_eq :
presheaf.first_map R F ≫ (second_obj_iso_pi_inters F U R).hom =
(first_obj_iso_pi_opens F U R).hom ≫ left_res F (covering_of_presieve U R) :=
begin
ext ⟨f, g⟩,
rw [category.assoc, category.assoc, second_obj_iso_pi_inters_π],
dunfold left_res presheaf.first_map,
rw [limit.lift_π, fan.mk_π_app, limit.lift_π_assoc, fan.mk_π_app, ← category.assoc],
erw [first_obj_iso_pi_opens_π, category.assoc, ← F.map_comp],
refl,
end
/--
Second naturality condition. Under the isomorphisms `first_obj_iso_pi_opens` and
`second_obj_iso_pi_inters`, the map `presheaf.second_map` corresponds to `right_res`.
-/
lemma first_obj_iso_comp_right_res_eq :
presheaf.second_map R F ≫ (second_obj_iso_pi_inters F U R).hom =
(first_obj_iso_pi_opens F U R).hom ≫ right_res F (covering_of_presieve U R) :=
begin
ext ⟨f, g⟩,
dunfold right_res presheaf.second_map,
rw [category.assoc, category.assoc, second_obj_iso_pi_inters_π, limit.lift_π, fan.mk_π_app,
limit.lift_π_assoc, fan.mk_π_app, ← category.assoc, first_obj_iso_pi_opens_π, category.assoc,
← F.map_comp],
refl,
end
/-- The natural isomorphism between the sites diagram and the spaces diagram. -/
@[simps]
def diagram_nat_iso : parallel_pair (presheaf.first_map R F) (presheaf.second_map R F) ≅
diagram F (covering_of_presieve U R) :=
nat_iso.of_components
(λ i, walking_parallel_pair.cases_on i
(first_obj_iso_pi_opens F U R)
(second_obj_iso_pi_inters F U R)) $
begin
intros i j f,
cases i,
{ cases j,
{ cases f, simp },
{ cases f,
{ exact first_obj_iso_comp_left_res_eq F U R, },
{ exact first_obj_iso_comp_right_res_eq F U R, } } },
{ cases j,
{ cases f, },
{ cases f, simp } },
end
/--
Postcomposing the given fork of the _sites_ diagram with the natural isomorphism between the
diagrams gives us a fork of the _spaces_ diagram. We construct a morphism from this fork to the
given fork of the _spaces_ diagram. This is shown to be an isomorphism below.
-/
@[simps]
def postcompose_diagram_fork_hom (hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
(cones.postcompose (diagram_nat_iso F U R).hom).obj (fork.of_ι _ (presheaf.w R F)) ⟶
fork F (covering_of_presieve U R) :=
fork.mk_hom (F.map (eq_to_hom (supr_eq_of_mem_grothendieck U R hR)).op)
(fork_map_comp_first_obj_iso_pi_opens_eq F U R hR).symm
instance is_iso_postcompose_diagram_fork_hom_hom
(hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
is_iso (postcompose_diagram_fork_hom F U R hR).hom :=
begin rw postcompose_diagram_fork_hom_hom, apply eq_to_hom.is_iso, end
instance is_iso_postcompose_diagram_fork_hom
(hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
is_iso (postcompose_diagram_fork_hom F U R hR) :=
cones.cone_iso_of_hom_iso _
/-- See `postcompose_diagram_fork_hom`. -/
def postcompose_diagram_fork_iso (hR : sieve.generate R ∈ opens.grothendieck_topology X U) :
(cones.postcompose (diagram_nat_iso F U R).hom).obj (fork.of_ι _ (presheaf.w R F)) ≅
fork F (covering_of_presieve U R) :=
as_iso (postcompose_diagram_fork_hom F U R hR)
end covering_of_presieve
lemma is_sheaf_sites_of_is_sheaf_spaces (Fsh : F.is_sheaf) :
presheaf.is_sheaf (opens.grothendieck_topology X) F :=
begin
rw presheaf.is_sheaf_iff_is_sheaf',
intros U R hR,
refine ⟨_⟩,
apply (is_limit.of_cone_equiv (cones.postcompose_equivalence
(covering_of_presieve.diagram_nat_iso F U R))).to_fun,
apply (is_limit.equiv_iso_limit
(covering_of_presieve.postcompose_diagram_fork_iso F U R hR)).inv_fun,
exact (Fsh (covering_of_presieve U R)).some,
end
/--
Given a family of opens `U : ι → opens X`, we obtain a presieve on `supr U` by declaring that a
morphism `f : V ⟶ supr U` is a member of the presieve if and only if there exists an index `i : ι`
such that `V = U i`.
-/
def presieve_of_covering {ι : Type v} (U : ι → opens X) : presieve (supr U) :=
λ V f, ∃ i, V = U i
namespace presieve_of_covering
/-!
In this section, we will relate two different fork diagrams to each other.
The first one is the defining fork diagram for the sheaf condition in terms of spaces, applied to
the family of opens `U`. It will henceforth be called the _spaces diagram_. Its objects are called
`pi_opens` and `pi_inters` and its morphisms are `left_res` and `right_res`. The fork map into this
diagram is called `res`.
The second one is the defining fork diagram for the sheaf condition in terms of sites, applied to
the presieve `presieve_of_covering U`. It will henceforth be called the _sites diagram_. Its objects
are called `presheaf.first_obj` and `presheaf.second_obj` and its morphisms are `presheaf.first_map`
and `presheaf.second_obj`. The fork map into this diagram is called `presheaf.fork_map`.
-/
variables {ι : Type v} (U : ι → opens X)
/--
The sieve generated by `presieve_of_covering U` is a member of the grothendieck topology.
-/
lemma mem_grothendieck_topology :
sieve.generate (presieve_of_covering U) ∈ opens.grothendieck_topology X (supr U) :=
begin
intros x hx,
obtain ⟨i, hxi⟩ := opens.mem_supr.mp hx,
exact ⟨U i, opens.le_supr U i, ⟨U i, 𝟙 _, opens.le_supr U i, ⟨i, rfl⟩, category.id_comp _⟩, hxi⟩,
end
/--
An index `i : ι` can be turned into a dependent pair `(V, f)`, where `V` is an open set and
`f : V ⟶ supr U` is a member of `presieve_of_covering U f`.
-/
def hom_of_index (i : ι) : Σ V, {f : V ⟶ supr U // presieve_of_covering U f} :=
⟨U i, opens.le_supr U i, i, rfl⟩
/--
By using the axiom of choice, a dependent pair `(V, f)` where `f : V ⟶ supr U` is a member of
`presieve_of_covering U f` can be turned into an index `i : ι`, such that `V = U i`.
-/
def index_of_hom (f : Σ V, {f : V ⟶ supr U // presieve_of_covering U f}) : ι := f.2.2.some
lemma index_of_hom_spec (f : Σ V, {f : V ⟶ supr U // presieve_of_covering U f}) :
f.1 = U (index_of_hom U f) := f.2.2.some_spec
/--
The canonical morphism from the first object in the sites diagram to the first object in the
spaces diagram. Note that this is *not* an isomorphism, as the product `pi_opens F U` may contain
duplicate factors, i.e. `U : ι → opens X` may not be injective.
-/
def first_obj_to_pi_opens : presheaf.first_obj (presieve_of_covering U) F ⟶ pi_opens F U :=
pi.lift (λ i, pi.π _ (hom_of_index U i))
/--
The canonical morphism from the first object in the spaces diagram to the first object in the
sites diagram. Note that this is *not* an isomorphism, as the product `pi_opens F U` may contain
duplicate factors, i.e. `U : ι → opens X` may not be injective.
-/
def pi_opens_to_first_obj : pi_opens F U ⟶
presheaf.first_obj.{v v u} (presieve_of_covering U) F :=
pi.lift (λ f, pi.π _ (index_of_hom U f) ≫ F.map (eq_to_hom (index_of_hom_spec U f)).op)
/--
Even though `first_obj_to_pi_opens` and `pi_opens_to_first_obj` are not inverse to each other,
applying them both after a fork map `s.ι` does nothing. The intuition here is that a compatible
family `s : Π i : ι, F.obj (op (U i))` does not care about duplicate open sets:
If `U i = U j` the the compatible family coincides on the intersection `U i ⊓ U j = U i = U j`,
hence `s i = s j` (module an `eq_to_hom` arrow).
-/
lemma fork_ι_comp_pi_opens_to_first_obj_to_pi_opens_eq
(s : limits.fork (left_res F U) (right_res F U)) :
s.ι ≫ pi_opens_to_first_obj F U ≫ first_obj_to_pi_opens F U = s.ι :=
begin
ext j,
dunfold first_obj_to_pi_opens pi_opens_to_first_obj,
rw [category.assoc, category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app],
-- The issue here is that `index_of_hom U (hom_of_index U j)` need not be equal to `j`.
-- But `U j = U (index_of_hom U (hom_of_index U j))` and hence we obtain the following
-- `eq_to_hom` arrow:
have i_eq : U j ⟶ U j ⊓ U (index_of_hom U (hom_of_index U j)),
{ apply eq_to_hom, rw ← index_of_hom_spec U, exact inf_idem.symm, },
-- Since `s` is a fork, we know that `s.ι ≫ left_res F U = s.ι ≫ right_res F U`.
-- We compose both sides of this equality with the canonical projection at the index pair
-- `(j, index_of_hom U (hom_of_index U j)` and the restriction along `i_eq`.
have := congr_arg (λ f, f ≫
pi.π (λ p : ι × ι, F.obj (op (U p.1 ⊓ U p.2))) (j, index_of_hom U (hom_of_index U j)) ≫
F.map i_eq.op) s.condition,
dsimp at this,
rw [category.assoc, category.assoc] at this,
symmetry,
-- We claim that this is equality is our goal
convert this using 2,
{ dunfold left_res,
rw [limit.lift_π_assoc, fan.mk_π_app, category.assoc, ← F.map_comp],
erw F.map_id,
rw category.comp_id },
{ dunfold right_res,
rw [limit.lift_π_assoc, fan.mk_π_app, category.assoc, ← F.map_comp],
congr, }
end
/--
The canonical morphism from the second object of the spaces diagram to the second object of the
sites diagram.
-/
def pi_inters_to_second_obj : pi_inters F U ⟶
presheaf.second_obj.{v v u} (presieve_of_covering U) F :=
pi.lift (λ f, pi.π _ (index_of_hom U f.fst, index_of_hom U f.snd) ≫
F.map (eq_to_hom
(by rw [complete_lattice.pullback_eq_inf, ← index_of_hom_spec U, ← index_of_hom_spec U])).op)
lemma pi_opens_to_first_obj_comp_fist_map_eq :
pi_opens_to_first_obj F U ≫ presheaf.first_map (presieve_of_covering U) F =
left_res F U ≫ pi_inters_to_second_obj F U :=
begin
ext ⟨f, g⟩,
dunfold pi_opens_to_first_obj presheaf.first_map left_res pi_inters_to_second_obj,
rw [category.assoc, category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app,
← category.assoc, ← category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app,
category.assoc, category.assoc, ← F.map_comp, ← F.map_comp],
refl,
end
lemma pi_opens_to_first_obj_comp_second_map_eq :
pi_opens_to_first_obj F U ≫ presheaf.second_map (presieve_of_covering U) F =
right_res F U ≫ pi_inters_to_second_obj F U :=
begin
ext ⟨f, g⟩,
dunfold pi_opens_to_first_obj presheaf.second_map right_res pi_inters_to_second_obj,
rw [category.assoc, category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app,
← category.assoc, ← category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app,
category.assoc, category.assoc, ← F.map_comp, ← F.map_comp],
refl,
end
lemma fork_map_comp_first_map_to_pi_opens_eq :
presheaf.fork_map (presieve_of_covering U) F ≫ first_obj_to_pi_opens F U = res F U :=
begin
ext i,
dsimp [presheaf.fork_map, first_obj_to_pi_opens, res],
rw [category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app,
limit.lift_π, fan.mk_π_app],
refl,
end
lemma res_comp_pi_opens_to_first_obj_eq :
res F U ≫ pi_opens_to_first_obj F U = presheaf.fork_map (presieve_of_covering U) F :=
begin
ext f,
dunfold res pi_opens_to_first_obj presheaf.fork_map,
rw [category.assoc, limit.lift_π, fan.mk_π_app, limit.lift_π, fan.mk_π_app, ← category.assoc,
limit.lift_π, fan.mk_π_app, ← F.map_comp],
congr,
end
end presieve_of_covering
open presieve_of_covering
lemma is_sheaf_spaces_of_is_sheaf_sites
(Fsh : presheaf.is_sheaf (opens.grothendieck_topology X) F) :
F.is_sheaf :=
begin
intros ι U,
rw presheaf.is_sheaf_iff_is_sheaf' at Fsh,
-- We know that the sites diagram for `presieve_of_covering U` is a limit fork
obtain ⟨h_limit⟩ := Fsh (supr U) (presieve_of_covering U)
(presieve_of_covering.mem_grothendieck_topology U),
refine ⟨fork.is_limit.mk' _ _⟩,
-- Here, we are given an arbitrary fork of the spaces diagram and need to show that it factors
-- uniquely through our limit fork.
intro s,
-- Composing `s.ι` with `pi_opens_to_first_obj F U` gives a fork of the sites diagram, which
-- must factor through `presheaf.fork_map`.
obtain ⟨l, hl⟩ := fork.is_limit.lift' h_limit (s.ι ≫ pi_opens_to_first_obj F U) _,
swap,
{ rw [category.assoc, category.assoc, pi_opens_to_first_obj_comp_fist_map_eq,
pi_opens_to_first_obj_comp_second_map_eq, ← category.assoc, ← category.assoc, s.condition] },
-- We claim that `l` also gives a factorization of `s.ι`
refine ⟨l, _, _⟩,
{ rw [← fork_ι_comp_pi_opens_to_first_obj_to_pi_opens_eq F U s, ← category.assoc, ← hl,
category.assoc, fork.ι_of_ι, fork_map_comp_first_map_to_pi_opens_eq], refl },
{ intros m hm,
apply fork.is_limit.hom_ext h_limit,
rw [hl, fork.ι_of_ι],
simp_rw ← res_comp_pi_opens_to_first_obj_eq,
erw [← category.assoc, hm], },
end
lemma is_sheaf_sites_iff_is_sheaf_spaces :
presheaf.is_sheaf (opens.grothendieck_topology X) F ↔ F.is_sheaf :=
iff.intro (is_sheaf_spaces_of_is_sheaf_sites F) (is_sheaf_sites_of_is_sheaf_spaces F)
variables (C X)
/-- Turn a sheaf on the site `opens X` into a sheaf on the space `X`. -/
@[simps]
def Sheaf_sites_to_sheaf_spaces : Sheaf (opens.grothendieck_topology X) C ⥤ sheaf C X :=
{ obj := λ F, ⟨F.1, is_sheaf_spaces_of_is_sheaf_sites F.1 F.2⟩,
map := λ F G f, f }
/-- Turn a sheaf on the space `X` into a sheaf on the site `opens X`. -/
@[simps]
def Sheaf_spaces_to_sheaf_sites : sheaf C X ⥤ Sheaf (opens.grothendieck_topology X) C :=
{ obj := λ F, ⟨F.1, is_sheaf_sites_of_is_sheaf_spaces F.1 F.2⟩,
map := λ F G f, f }
/--
The equivalence of categories between sheaves on the site `opens X` and sheaves on the space `X`.
-/
@[simps]
def Sheaf_spaces_equivelence_sheaf_sites : Sheaf (opens.grothendieck_topology X) C ≌ sheaf C X :=
begin
refine equivalence.mk (Sheaf_sites_to_sheaf_spaces C X) (Sheaf_spaces_to_sheaf_sites C X) _ _,
all_goals {
refine nat_iso.of_components (λ F, eq_to_iso (subtype.ext rfl)) (λ F G f, _),
ext U, dsimp,
erw [nat_trans.comp_app, nat_trans.comp_app, eq_to_hom_refl G.1 rfl, eq_to_hom_refl F.1 rfl,
nat_trans.id_app G.1, category.comp_id, nat_trans.id_app F.1, category.id_comp], },
end
end Top.presheaf
|
9648253fb33b76d5dea72c6f78e0a02f166e6346 | 6b2a480f27775cba4f3ae191b1c1387a29de586e | /group_rep1/irreductible.lean | 307ec99fdaff75b9a946c295494cd4812a4f409a | [] | no_license | Or7ando/group_representation | a681de2e19d1930a1e1be573d6735a2f0b8356cb | 9b576984f17764ebf26c8caa2a542d248f1b50d2 | refs/heads/master | 1,662,413,107,324 | 1,590,302,389,000 | 1,590,302,389,000 | 258,130,829 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 4,411 | lean | import tactic
import .sub_module
import tactic.push_neg
import .morphism
import .homothetic
import .kernel
open Kernel range morphism homothetic
open stability
universe variables u v w w'
lemma Fact {R : Type v}[ring R]{M1 : Type w}[add_comm_group M1] [module R M1]
(p1 : submodule R M1) (hyp : p1 = ⊤ ∨ p1 = ⊥ )(z : M1)(hyp' : z ∈ p1)(hyp'' : z ≠ 0) : p1 = ⊤ := begin
rcases hyp, assumption, rw hyp at hyp', rw submodule.mem_bot at hyp', by contradiction,
end
namespace Irreductible
variables {G : Type u} [group G] {R : Type v}[ring R]
variables {M : Type w}[add_comm_group M] [module R M] ( ρ : group_representation G R M)
def Irreductible := ∀ {p : submodule R M}, (stable_submodule ρ p) → (p = ⊤ ∨ p = ⊥)
end Irreductible
namespace morphism.from_irreductible
open Irreductible linear_map
variables {G : Type u} [group G] {R : Type v}[ring R]
variables {M1 : Type w} [add_comm_group M1] [module R M1]
{M2 : Type w'} [add_comm_group M2] [module R M2]
{ ρ1 : group_representation G R M1}
{ρ2 : group_representation G R M2}
(f : ρ1 ⟶ ρ2)
--
-- Faire les choses plus proprement en definissant une strucure ⊤ ⊥ sur les representation
--
theorem pre_Schur_ker (hyp : Irreductible ρ1) :
(ker f.ℓ = ⊤ ∨ ker f.ℓ = ⊥ ) := hyp (ker_is_stable_submodule f)
theorem pre_Schur_range (hyp : Irreductible ρ2) :
(range f.ℓ = ⊤ ∨ range f.ℓ = ⊥ ) :=
hyp (range_is_stable_submodule f)
open linear_map
variables (hyp : Irreductible ρ2 )
#check f
#check pre_Schur_range f (by assumption)
/--
little modification of Serre `Representations linéaires des groupes finis`.
We have no assumption of field just a ring (`NOT` only commutative). `NOT` dimension.
-/
theorem Schur₁ (hyp1 : Irreductible ρ1)(hyp2 : Irreductible ρ2) : (∃ x : M1, (f.ℓ x ≠ 0)) →
(ker f.ℓ = ⊥ ) ∧ range f.ℓ = ⊤ :=
begin
intros hyp_not_nul,
rcases hyp_not_nul with ⟨x,hyp_not_nul⟩,
split, swap,
apply Fact, -- ici ?
apply pre_Schur_range, --- on ne comprend plus !
assumption,
rw linear_map.mem_range,
use x,
exact hyp_not_nul,
let schur := (hyp1 (ker_is_stable_submodule f)),unfold Ker at schur,
rcases schur, swap,assumption,
rw schur,
have R : x ∈ ker f.ℓ ,
rw schur, trivial,
rw linear_map.mem_ker at R,
trivial,
end
end morphism.from_irreductible
namespace Schur₂
open Irreductible morphism.from_irreductible
open_locale classical
variables {G : Type u} [group G] {R : Type v}[comm_ring R]{M : Type w}[add_comm_group M] [module R M]
variables {ρ : group_representation G R M}
theorem Schur₂(f : ρ ⟶ ρ) [re : Irreductible ρ] :
(∃ r : R, ∃ m0 : M, m0 ≠ 0 ∧ f.ℓ m0 + r • m0 = 0) → (∃ r : R, ∀ m : M, f.ℓ m + r • m = 0) :=
begin
--intro hyp,
rintros ⟨r,m0,⟨spec,spectral⟩⟩,
use r,
-- We proof g = f + r id =0. The idea is ker g is stable, so equal to {0} or M. But m0 ∈ Ker f and m0 ≠ 0 so Ker f = M
let g := f + r • 𝟙 ρ,
-- first step g.ℓ m0 = 0
have certif_m0_in_ker : g.ℓ m0 = 0,
erw [add_ext,
smul_ext, one_ext],
exact spectral,
let schur := (Schur₁ g) ( by assumption ) (by assumption), -- swap, exact re
by_contra, -- re doesnt work
push_neg at a,
rcases a with ⟨ζ,n ⟩,
have R : (f.ℓ) ζ + r • ζ = g.ℓ ζ,
erw [add_ext,smul_ext,one_ext],
exact rfl,
rw R at n,
let V := (schur ⟨ζ,n⟩).1,
have : m0 ∈ linear_map.ker g.ℓ,
rw linear_map.mem_ker,
exact certif_m0_in_ker,
rw V at this,
rw submodule.mem_bot at this,
by contradiction,
end
/-
example (P : Prop) (h : P ∨ ¬ P) : ¬ ¬ P → P := begin
intros hnn,
cases h,
assumption,
by contradiction,
end
example (P Q : Prop) : (P → Q) ↔ (¬ Q → ¬ P) := begin
split,
intro hpq,
intro hnQ,
intro hp,
end
example (X :Type) (P : X → Prop ) (hyp : (∃ x : X, ¬ (P x)) → false ) : ∀ x, P x := begin
intro,
contrapose! hyp,
use x,
end
example (X :Type) (P : X → Prop ) (hyp : (∃ x : X, ¬ (P x)) → false ) : ∀ x, P x := begin
by_contra,
rw not_forall at a,
exact hyp a,
end
-/ |
3188e0072d27bf4c69309d6550cddd3dd813b994 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /hott/algebra/category/colimits.hlean | b6a33f1d8a9b8cd2a4f90eeb387a84b9dc1d8ee0 | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,522 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Colimits in a category
-/
import .limits .constructions.opposite
open is_trunc functor nat_trans eq
-- we define colimits to be the dual of a limit
namespace category
variables {ob : Type} [C : precategory ob] {c c' : ob} (D I : Precategory)
include C
definition is_initial [reducible] (c : ob) := @is_terminal _ (opposite C) c
definition is_contr_of_is_initial [instance] (c d : ob) [H : is_initial d]
: is_contr (d ⟶ c) :=
H c
definition initial_morphism (c c' : ob) [H : is_initial c'] : c' ⟶ c :=
!center
definition hom_initial_eq [H : is_initial c'] (f f' : c' ⟶ c) : f = f' :=
!is_hprop.elim
definition eq_initial_morphism [H : is_initial c'] (f : c' ⟶ c) : f = initial_morphism c c' :=
!is_hprop.elim
definition initial_iso_initial {c c' : ob} (H : is_initial c) (K : is_initial c') : c ≅ c' :=
iso_of_opposite_iso (@terminal_iso_terminal _ (opposite C) _ _ H K)
theorem is_hprop_is_initial [instance] : is_hprop (is_initial c) := _
omit C
definition has_initial_object [reducible] : Type := has_terminal_object Dᵒᵖ
definition initial_object [unfold 2] [reducible] [H : has_initial_object D] : D :=
has_terminal_object.d Dᵒᵖ
definition has_initial_object.is_initial [H : has_initial_object D]
: is_initial (initial_object D) :=
@has_terminal_object.is_terminal (Opposite D) H
variable {D}
definition initial_object_iso_initial_object (H₁ H₂ : has_initial_object D)
: @initial_object D H₁ ≅ @initial_object D H₂ :=
initial_iso_initial (@has_initial_object.is_initial D H₁) (@has_initial_object.is_initial D H₂)
set_option pp.coercions true
theorem is_hprop_has_initial_object [instance] (D : Category)
: is_hprop (has_initial_object D) :=
is_hprop_has_terminal_object (Category_opposite D)
variable (D)
definition has_colimits_of_shape [reducible] := has_limits_of_shape Dᵒᵖ Iᵒᵖ
/-
The next definitions states that a category is cocomplete with respect to diagrams
in a certain universe. "is_cocomplete.{o₁ h₁ o₂ h₂}" means that D is cocomplete
with respect to diagrams of type Precategory.{o₂ h₂}
-/
definition is_cocomplete [reducible] (D : Precategory) := is_complete Dᵒᵖ
definition has_colimits_of_shape_of_is_cocomplete [instance] [H : is_cocomplete D]
(I : Precategory) : has_colimits_of_shape D I := H Iᵒᵖ
section
open pi
theorem is_hprop_has_colimits_of_shape [instance] (D : Category) (I : Precategory)
: is_hprop (has_colimits_of_shape D I) :=
is_hprop_has_limits_of_shape (Category_opposite D) _
theorem is_hprop_is_cocomplete [instance] (D : Category) : is_hprop (is_cocomplete D) :=
is_hprop_is_complete (Category_opposite D)
end
variables {D I} (F : I ⇒ D) [H : has_colimits_of_shape D I] {i j : I}
include H
definition cocone [reducible] := (cone Fᵒᵖ)ᵒᵖ
definition has_initial_object_cocone [H : has_colimits_of_shape D I]
(F : I ⇒ D) : has_initial_object (cocone F) :=
begin
unfold [has_colimits_of_shape,has_limits_of_shape] at H,
exact H Fᵒᵖ
end
local attribute has_initial_object_cocone [instance]
definition colimit_cocone : cocone F := limit_cone Fᵒᵖ
definition is_initial_colimit_cocone [instance] : is_initial (colimit_cocone F) :=
is_terminal_limit_cone Fᵒᵖ
definition colimit_object : D :=
limit_object Fᵒᵖ
definition colimit_nat_trans : constant_functor Iᵒᵖ (colimit_object F) ⟹ Fᵒᵖ :=
limit_nat_trans Fᵒᵖ
definition colimit_morphism (i : I) : F i ⟶ colimit_object F :=
limit_morphism Fᵒᵖ i
variable {H}
theorem colimit_commute {i j : I} (f : i ⟶ j)
: colimit_morphism F j ∘ to_fun_hom F f = colimit_morphism F i :=
by rexact limit_commute Fᵒᵖ f
variable [H]
definition colimit_cone_obj [constructor] {d : D} {η : Πi, F i ⟶ d}
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i) : cone_obj Fᵒᵖ :=
limit_cone_obj Fᵒᵖ proof p qed
variable {H}
definition colimit_hom {d : D} (η : Πi, F i ⟶ d)
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i) : colimit_object F ⟶ d :=
hom_limit Fᵒᵖ η proof p qed
theorem colimit_hom_commute {d : D} (η : Πi, F i ⟶ d)
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i) (i : I)
: colimit_hom F η p ∘ colimit_morphism F i = η i :=
by rexact hom_limit_commute Fᵒᵖ η proof p qed i
definition colimit_cone_hom [constructor] {d : D} {η : Πi, F i ⟶ d}
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i) {h : colimit_object F ⟶ d}
(q : Πi, h ∘ colimit_morphism F i = η i)
: cone_hom (colimit_cone_obj F p) (colimit_cocone F) :=
by rexact limit_cone_hom Fᵒᵖ proof p qed proof q qed
variable {F}
theorem eq_colimit_hom {d : D} {η : Πi, F i ⟶ d}
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i) {h : colimit_object F ⟶ d}
(q : Πi, h ∘ colimit_morphism F i = η i) : h = colimit_hom F η p :=
by rexact @eq_hom_limit _ _ Fᵒᵖ _ _ _ proof p qed _ proof q qed
theorem colimit_cocone_unique {d : D} {η : Πi, F i ⟶ d}
(p : Π⦃j i : I⦄ (f : i ⟶ j), η j ∘ to_fun_hom F f = η i)
{h₁ : colimit_object F ⟶ d} (q₁ : Πi, h₁ ∘ colimit_morphism F i = η i)
{h₂ : colimit_object F ⟶ d} (q₂ : Πi, h₂ ∘ colimit_morphism F i = η i) : h₁ = h₂ :=
@limit_cone_unique _ _ Fᵒᵖ _ _ _ proof p qed _ proof q₁ qed _ proof q₂ qed
omit H
variable (F)
definition colimit_object_iso_colimit_object [constructor] (H₁ H₂ : has_colimits_of_shape D I) :
@(colimit_object F) H₁ ≅ @(colimit_object F) H₂ :=
iso_of_opposite_iso (limit_object_iso_limit_object Fᵒᵖ H₁ H₂)
section bin_coproducts
open bool prod.ops
definition has_binary_coproducts [reducible] (D : Precategory) := has_colimits_of_shape D c2
variables [K : has_binary_coproducts D] (d d' : D)
include K
definition coproduct_object : D :=
colimit_object (c2_functor D d d')
infixr + := coproduct_object
definition inl : d ⟶ d + d' :=
colimit_morphism (c2_functor D d d') ff
definition inr : d' ⟶ d + d' :=
colimit_morphism (c2_functor D d d') tt
variables {d d'}
definition coproduct_hom {x : D} (f : d ⟶ x) (g : d' ⟶ x) : d + d' ⟶ x :=
colimit_hom (c2_functor D d d') (bool.rec f g)
(by intro b₁ b₂ f; induction b₁: induction b₂: esimp at *; try contradiction: apply id_right)
theorem coproduct_hom_inl {x : D} (f : d ⟶ x) (g : d' ⟶ x) : coproduct_hom f g ∘ !inl = f :=
colimit_hom_commute (c2_functor D d d') (bool.rec f g) _ ff
theorem coproduct_hom_inr {x : D} (f : d ⟶ x) (g : d' ⟶ x) : coproduct_hom f g ∘ !inr = g :=
colimit_hom_commute (c2_functor D d d') (bool.rec f g) _ tt
theorem eq_coproduct_hom {x : D} {f : d ⟶ x} {g : d' ⟶ x} {h : d + d' ⟶ x}
(p : h ∘ !inl = f) (q : h ∘ !inr = g) : h = coproduct_hom f g :=
eq_colimit_hom _ (bool.rec p q)
theorem coproduct_cocone_unique {x : D} {f : d ⟶ x} {g : d' ⟶ x}
{h₁ : d + d' ⟶ x} (p₁ : h₁ ∘ !inl = f) (q₁ : h₁ ∘ !inr = g)
{h₂ : d + d' ⟶ x} (p₂ : h₂ ∘ !inl = f) (q₂ : h₂ ∘ !inr = g) : h₁ = h₂ :=
eq_coproduct_hom p₁ q₁ ⬝ (eq_coproduct_hom p₂ q₂)⁻¹
variable (D)
definition coproduct_functor [constructor] : D ×c D ⇒ D :=
functor.mk
(λx, coproduct_object x.1 x.2)
(λx y f, coproduct_hom (!inl ∘ f.1) (!inr ∘ f.2))
abstract begin intro x, symmetry, apply eq_coproduct_hom: apply id_comp_eq_comp_id end end
abstract begin intro x y z g f, symmetry, apply eq_coproduct_hom,
rewrite [-assoc,coproduct_hom_inl,assoc,coproduct_hom_inl,-assoc],
rewrite [-assoc,coproduct_hom_inr,assoc,coproduct_hom_inr,-assoc] end end
omit K
variables {D} (d d')
definition coproduct_object_iso_coproduct_object [constructor] (H₁ H₂ : has_binary_coproducts D) :
@coproduct_object D H₁ d d' ≅ @coproduct_object D H₂ d d' :=
colimit_object_iso_colimit_object _ H₁ H₂
end bin_coproducts
/-
intentionally we define coproducts in terms of colimits,
but coequalizers in terms of equalizers, to see which characterization is more useful
-/
section coequalizers
open bool prod.ops sum equalizer_category_hom
definition has_coequalizers [reducible] (D : Precategory) := has_equalizers Dᵒᵖ
variables [K : has_coequalizers D]
include K
variables {d d' x : D} (f g : d ⟶ d')
definition coequalizer_object : D :=
!(@equalizer_object Dᵒᵖ) f g
definition coequalizer : d' ⟶ coequalizer_object f g :=
!(@equalizer Dᵒᵖ)
theorem coequalizes : coequalizer f g ∘ f = coequalizer f g ∘ g :=
by rexact !(@equalizes Dᵒᵖ)
variables {f g}
definition coequalizer_hom (h : d' ⟶ x) (p : h ∘ f = h ∘ g) : coequalizer_object f g ⟶ x :=
!(@hom_equalizer Dᵒᵖ) proof p qed
theorem coequalizer_hom_coequalizer (h : d' ⟶ x) (p : h ∘ f = h ∘ g)
: coequalizer_hom h p ∘ coequalizer f g = h :=
by rexact !(@equalizer_hom_equalizer Dᵒᵖ)
theorem eq_coequalizer_hom {h : d' ⟶ x} (p : h ∘ f = h ∘ g) {i : coequalizer_object f g ⟶ x}
(q : i ∘ coequalizer f g = h) : i = coequalizer_hom h p :=
by rexact !(@eq_hom_equalizer Dᵒᵖ) proof q qed
theorem coequalizer_cocone_unique {h : d' ⟶ x} (p : h ∘ f = h ∘ g)
{i₁ : coequalizer_object f g ⟶ x} (q₁ : i₁ ∘ coequalizer f g = h)
{i₂ : coequalizer_object f g ⟶ x} (q₂ : i₂ ∘ coequalizer f g = h) : i₁ = i₂ :=
!(@equalizer_cone_unique Dᵒᵖ) proof p qed proof q₁ qed proof q₂ qed
omit K
variables (f g)
definition coequalizer_object_iso_coequalizer_object [constructor] (H₁ H₂ : has_coequalizers D) :
@coequalizer_object D H₁ _ _ f g ≅ @coequalizer_object D H₂ _ _ f g :=
iso_of_opposite_iso !(@equalizer_object_iso_equalizer_object Dᵒᵖ)
end coequalizers
section pushouts
open bool prod.ops sum pullback_category_hom
definition has_pushouts [reducible] (D : Precategory) := has_pullbacks Dᵒᵖ
variables [K : has_pushouts D]
include K
variables {d₁ d₂ d₃ x : D} (f : d₁ ⟶ d₂) (g : d₁ ⟶ d₃)
definition pushout_object : D :=
!(@pullback_object Dᵒᵖ) f g
definition pushout : d₃ ⟶ pushout_object f g :=
!(@pullback Dᵒᵖ)
definition pushout_rev : d₂ ⟶ pushout_object f g :=
!(@pullback_rev Dᵒᵖ)
theorem pushout_commutes : pushout_rev f g ∘ f = pushout f g ∘ g :=
by rexact !(@pullback_commutes Dᵒᵖ)
variables {f g}
definition pushout_hom (h₁ : d₂ ⟶ x) (h₂ : d₃ ⟶ x) (p : h₁ ∘ f = h₂ ∘ g)
: pushout_object f g ⟶ x :=
!(@hom_pullback Dᵒᵖ) proof p qed
theorem pushout_hom_pushout (h₁ : d₂ ⟶ x) (h₂ : d₃ ⟶ x) (p : h₁ ∘ f = h₂ ∘ g)
: pushout_hom h₁ h₂ p ∘ pushout f g = h₂ :=
by rexact !(@pullback_hom_pullback Dᵒᵖ)
theorem pushout_hom_pushout_rev (h₁ : d₂ ⟶ x) (h₂ : d₃ ⟶ x) (p : h₁ ∘ f = h₂ ∘ g)
: pushout_hom h₁ h₂ p ∘ pushout_rev f g = h₁ :=
by rexact !(@pullback_rev_hom_pullback Dᵒᵖ)
theorem eq_pushout_hom {h₁ : d₂ ⟶ x} {h₂ : d₃ ⟶ x} (p : h₁ ∘ f = h₂ ∘ g)
{i : pushout_object f g ⟶ x} (q : i ∘ pushout f g = h₂) (r : i ∘ pushout_rev f g = h₁)
: i = pushout_hom h₁ h₂ p :=
by rexact !(@eq_hom_pullback Dᵒᵖ) proof q qed proof r qed
theorem pushout_cocone_unique {h₁ : d₂ ⟶ x} {h₂ : d₃ ⟶ x} (p : h₁ ∘ f = h₂ ∘ g)
{i₁ : pushout_object f g ⟶ x} (q₁ : i₁ ∘ pushout f g = h₂) (r₁ : i₁ ∘ pushout_rev f g = h₁)
{i₂ : pushout_object f g ⟶ x} (q₂ : i₂ ∘ pushout f g = h₂) (r₂ : i₂ ∘ pushout_rev f g = h₁)
: i₁ = i₂ :=
!(@pullback_cone_unique Dᵒᵖ) proof p qed proof q₁ qed proof r₁ qed proof q₂ qed proof r₂ qed
omit K
variables (f g)
definition pushout_object_iso_pushout_object [constructor] (H₁ H₂ : has_pushouts D) :
@pushout_object D H₁ _ _ _ f g ≅ @pushout_object D H₂ _ _ _ f g :=
iso_of_opposite_iso !(@pullback_object_iso_pullback_object (Opposite D))
end pushouts
end category
|
3c44e3e6dd42bd08100a579df01089d10e946a75 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/ring_theory/witt_vector/witt_polynomial.lean | e8127c9c519b8d868dd2c9469773f20d36790d24 | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 10,804 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import algebra.char_p.invertible
import data.fintype.card
import data.mv_polynomial.variables
import data.mv_polynomial.comm_ring
import data.mv_polynomial.expand
import data.zmod.basic
/-!
# Witt polynomials
To endow `witt_vector p R` with a ring structure,
we need to study the so-called Witt polynomials.
Fix a base value `p : ℕ`.
The `p`-adic Witt polynomials are an infinite family of polynomials
indexed by a natural number `n`, taking values in an arbitrary ring `R`.
The variables of these polynomials are represented by natural numbers.
The variable set of the `n`th Witt polynomial contains at most `n+1` elements `{0, ..., n}`,
with exactly these variables when `R` has characteristic `0`.
These polynomials are used to define the addition and multiplication operators
on the type of Witt vectors. (While this type itself is not complicated,
the ring operations are what make it interesting.)
When the base `p` is invertible in `R`, the `p`-adic Witt polynomials
form a basis for `mv_polynomial ℕ R`, equivalent to the standard basis.
## Main declarations
* `witt_polynomial p R n`: the `n`-th Witt polynomial, viewed as polynomial over the ring `R`
* `X_in_terms_of_W p R n`: if `p` is invertible, the polynomial `X n` is contained in the subalgebra
generated by the Witt polynomials. `X_in_terms_of_W p R n` is the explicit polynomial,
which upon being bound to the Witt polynomials yields `X n`.
* `bind₁_witt_polynomial_X_in_terms_of_W`: the proof of the claim that
`bind₁ (X_in_terms_of_W p R) (W_ R n) = X n`
* `bind₁_X_in_terms_of_W_witt_polynomial`: the converse of the above statement
## Notation
In this file we use the following notation
* `p` is a natural number, typically assumed to be prime.
* `R` and `S` are commutative rings
* `W n` (and `W_ R n` when the ring needs to be explicit) denotes the `n`th Witt polynomial
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
open mv_polynomial
open finset (hiding map)
open finsupp (single)
open_locale big_operators
local attribute [-simp] coe_eval₂_hom
variables (p : ℕ)
variables (R : Type*) [comm_ring R]
/-- `witt_polynomial p R n` is the `n`-th Witt polynomial
with respect to a prime `p` with coefficients in a commutative ring `R`.
It is defined as:
`∑_{i ≤ n} p^i X_i^{p^{n-i}} ∈ R[X_0, X_1, X_2, …]`. -/
noncomputable def witt_polynomial (n : ℕ) : mv_polynomial ℕ R :=
∑ i in range (n+1), monomial (single i (p ^ (n - i))) (p ^ i : R)
lemma witt_polynomial_eq_sum_C_mul_X_pow (n : ℕ) :
witt_polynomial p R n = ∑ i in range (n+1), C (p ^ i : R) * X i ^ (p ^ (n - i)) :=
begin
apply sum_congr rfl,
rintro i -,
rw [monomial_eq, finsupp.prod_single_index],
rw pow_zero,
end
/-! We set up notation locally to this file, to keep statements short and comprehensible.
This allows us to simply write `W n` or `W_ ℤ n`. -/
-- Notation with ring of coefficients explicit
localized "notation `W_` := witt_polynomial p" in witt
-- Notation with ring of coefficients implicit
localized "notation `W` := witt_polynomial p _" in witt
open_locale witt
open mv_polynomial
/- The first observation is that the Witt polynomial doesn't really depend on the coefficient ring.
If we map the coefficients through a ring homomorphism, we obtain the corresponding Witt polynomial
over the target ring. -/
section
variables {R} {S : Type*} [comm_ring S]
@[simp] lemma map_witt_polynomial (f : R →+* S) (n : ℕ) :
map f (W n) = W n :=
begin
rw [witt_polynomial, ring_hom.map_sum, witt_polynomial, sum_congr rfl],
intros i hi,
rw [map_monomial, ring_hom.map_pow, map_nat_cast],
end
variables (R)
@[simp] lemma constant_coeff_witt_polynomial [hp : fact p.prime] (n : ℕ) :
constant_coeff (witt_polynomial p R n) = 0 :=
begin
simp only [witt_polynomial, ring_hom.map_sum, constant_coeff_monomial],
rw [sum_eq_zero],
rintro i hi,
rw [if_neg],
rw [finsupp.single_eq_zero],
exact ne_of_gt (pow_pos hp.1.pos _)
end
@[simp] lemma witt_polynomial_zero : witt_polynomial p R 0 = X 0 :=
by simp only [witt_polynomial, X, sum_singleton, range_one, pow_zero]
@[simp] lemma witt_polynomial_one : witt_polynomial p R 1 = C ↑p * X 1 + (X 0) ^ p :=
by simp only [witt_polynomial_eq_sum_C_mul_X_pow, sum_range_succ_comm, range_one,
sum_singleton, one_mul, pow_one, C_1, pow_zero]
lemma aeval_witt_polynomial {A : Type*} [comm_ring A] [algebra R A] (f : ℕ → A) (n : ℕ) :
aeval f (W_ R n) = ∑ i in range (n+1), p^i * (f i) ^ (p ^ (n-i)) :=
by simp [witt_polynomial, alg_hom.map_sum, aeval_monomial, finsupp.prod_single_index]
/--
Over the ring `zmod (p^(n+1))`, we produce the `n+1`st Witt polynomial
by expanding the `n`th Witt polynomial by `p`.
-/
@[simp] lemma witt_polynomial_zmod_self (n : ℕ) :
W_ (zmod (p ^ (n + 1))) (n + 1) = expand p (W_ (zmod (p^(n + 1))) n) :=
begin
simp only [witt_polynomial_eq_sum_C_mul_X_pow],
rw [sum_range_succ, ← nat.cast_pow, char_p.cast_eq_zero (zmod (p^(n+1))) (p^(n+1)), C_0, zero_mul,
add_zero, alg_hom.map_sum, sum_congr rfl],
intros k hk,
rw [alg_hom.map_mul, alg_hom.map_pow, expand_X, alg_hom_C, ← pow_mul, ← pow_succ],
congr,
rw mem_range at hk,
rw [add_comm, add_tsub_assoc_of_le (nat.lt_succ_iff.mp hk), ← add_comm],
end
section p_prime
-- in fact, `0 < p` would be sufficient
variables [hp : fact p.prime]
include hp
lemma witt_polynomial_vars [char_zero R] (n : ℕ) :
(witt_polynomial p R n).vars = range (n + 1) :=
begin
have : ∀ i, (monomial (finsupp.single i (p ^ (n - i))) (p ^ i : R)).vars = {i},
{ intro i,
refine vars_monomial_single i (pow_ne_zero _ hp.1.ne_zero) _,
rw [← nat.cast_pow, nat.cast_ne_zero],
exact pow_ne_zero i hp.1.ne_zero },
rw [witt_polynomial, vars_sum_of_disjoint],
{ simp only [this, int.nat_cast_eq_coe_nat, bUnion_singleton_eq_self], },
{ simp only [this, int.nat_cast_eq_coe_nat],
intros a b h,
apply disjoint_singleton_left.mpr,
rwa mem_singleton, },
end
lemma witt_polynomial_vars_subset (n : ℕ) :
(witt_polynomial p R n).vars ⊆ range (n + 1) :=
begin
rw [← map_witt_polynomial p (int.cast_ring_hom R), ← witt_polynomial_vars p ℤ],
apply vars_map,
end
end p_prime
end
/-!
## Witt polynomials as a basis of the polynomial algebra
If `p` is invertible in `R`, then the Witt polynomials form a basis
of the polynomial algebra `mv_polynomial ℕ R`.
The polynomials `X_in_terms_of_W` give the coordinate transformation in the backwards direction.
-/
/-- The `X_in_terms_of_W p R n` is the polynomial on the basis of Witt polynomials
that corresponds to the ordinary `X n`. -/
noncomputable def X_in_terms_of_W [invertible (p : R)] :
ℕ → mv_polynomial ℕ R
| n := (X n - (∑ i : fin n,
have _ := i.2, (C (p^(i : ℕ) : R) * (X_in_terms_of_W i)^(p^(n-i))))) * C (⅟p ^ n : R)
lemma X_in_terms_of_W_eq [invertible (p : R)] {n : ℕ} :
X_in_terms_of_W p R n =
(X n - (∑ i in range n, C (p^i : R) * X_in_terms_of_W p R i ^ p ^ (n - i))) * C (⅟p ^ n : R) :=
by { rw [X_in_terms_of_W, ← fin.sum_univ_eq_sum_range] }
@[simp] lemma constant_coeff_X_in_terms_of_W [hp : fact p.prime] [invertible (p : R)] (n : ℕ) :
constant_coeff (X_in_terms_of_W p R n) = 0 :=
begin
apply nat.strong_induction_on n; clear n,
intros n IH,
rw [X_in_terms_of_W_eq, mul_comm, ring_hom.map_mul, ring_hom.map_sub, ring_hom.map_sum,
constant_coeff_C, sum_eq_zero],
{ simp only [constant_coeff_X, sub_zero, mul_zero] },
{ intros m H,
rw mem_range at H,
simp only [ring_hom.map_mul, ring_hom.map_pow, constant_coeff_C, IH m H],
rw [zero_pow, mul_zero],
apply pow_pos hp.1.pos, }
end
@[simp] lemma X_in_terms_of_W_zero [invertible (p : R)] :
X_in_terms_of_W p R 0 = X 0 :=
by rw [X_in_terms_of_W_eq, range_zero, sum_empty, pow_zero, C_1, mul_one, sub_zero]
section p_prime
variables [hp : fact p.prime]
include hp
lemma X_in_terms_of_W_vars_aux (n : ℕ) :
n ∈ (X_in_terms_of_W p ℚ n).vars ∧
(X_in_terms_of_W p ℚ n).vars ⊆ range (n + 1) :=
begin
apply nat.strong_induction_on n, clear n,
intros n ih,
rw [X_in_terms_of_W_eq, mul_comm, vars_C_mul, vars_sub_of_disjoint, vars_X, range_succ,
insert_eq],
swap 3, { apply nonzero_of_invertible },
work_on_goal 1
{ simp only [true_and, true_or, eq_self_iff_true,
mem_union, mem_singleton],
intro i,
rw [mem_union, mem_union],
apply or.imp id },
work_on_goal 2 { rw [vars_X, disjoint_singleton_left] },
all_goals
{ intro H,
replace H := vars_sum_subset _ _ H,
rw mem_bUnion at H,
rcases H with ⟨j, hj, H⟩,
rw vars_C_mul at H,
swap,
{ apply pow_ne_zero, exact_mod_cast hp.1.ne_zero },
rw mem_range at hj,
replace H := (ih j hj).2 (vars_pow _ _ H),
rw mem_range at H },
{ rw mem_range,
exact lt_of_lt_of_le H hj },
{ exact lt_irrefl n (lt_of_lt_of_le H hj) },
end
lemma X_in_terms_of_W_vars_subset (n : ℕ) :
(X_in_terms_of_W p ℚ n).vars ⊆ range (n + 1) :=
(X_in_terms_of_W_vars_aux p n).2
end p_prime
lemma X_in_terms_of_W_aux [invertible (p : R)] (n : ℕ) :
X_in_terms_of_W p R n * C (p^n : R) =
X n - ∑ i in range n, C (p^i : R) * (X_in_terms_of_W p R i)^p^(n-i) :=
by rw [X_in_terms_of_W_eq, mul_assoc, ← C_mul, ← mul_pow, inv_of_mul_self, one_pow, C_1, mul_one]
@[simp] lemma bind₁_X_in_terms_of_W_witt_polynomial [invertible (p : R)] (k : ℕ) :
bind₁ (X_in_terms_of_W p R) (W_ R k) = X k :=
begin
rw [witt_polynomial_eq_sum_C_mul_X_pow, alg_hom.map_sum],
simp only [alg_hom.map_pow, C_pow, alg_hom.map_mul, alg_hom_C],
rw [sum_range_succ_comm, tsub_self, pow_zero, pow_one, bind₁_X_right,
mul_comm, ← C_pow, X_in_terms_of_W_aux],
simp only [C_pow, bind₁_X_right, sub_add_cancel],
end
@[simp] lemma bind₁_witt_polynomial_X_in_terms_of_W [invertible (p : R)] (n : ℕ) :
bind₁ (W_ R) (X_in_terms_of_W p R n) = X n :=
begin
apply nat.strong_induction_on n,
clear n, intros n H,
rw [X_in_terms_of_W_eq, alg_hom.map_mul, alg_hom.map_sub, bind₁_X_right, alg_hom_C,
alg_hom.map_sum],
have : W_ R n - ∑ i in range n, C (p ^ i : R) * (X i) ^ p ^ (n - i) = C (p ^ n : R) * X n,
by simp only [witt_polynomial_eq_sum_C_mul_X_pow, tsub_self, sum_range_succ_comm,
pow_one, add_sub_cancel, pow_zero],
rw [sum_congr rfl, this],
{ -- this is really slow for some reason
rw [mul_right_comm, ← C_mul, ← mul_pow, mul_inv_of_self, one_pow, C_1, one_mul] },
{ intros i h,
rw mem_range at h,
simp only [alg_hom.map_mul, alg_hom.map_pow, alg_hom_C, H i h] },
end
|
3d8ca280533332a1c7661c3aa4c58639243104a2 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/field_theory/minpoly.lean | 815e312a7717da6a81673cae4140b6871153f040 | [
"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 | 18,026 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johan Commelin
-/
import data.polynomial.field_division
import ring_theory.integral_closure
import ring_theory.polynomial.gauss_lemma
/-!
# Minimal polynomials
This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,
under the assumption that x is integral over `A`.
After stating the defining property we specialize to the setting of field extensions
and derive some well-known properties, amongst which the fact that minimal polynomials
are irreducible, and uniquely determined by their defining property.
-/
open_locale classical
open polynomial set function
variables {A B : Type*}
section min_poly_def
variables (A) [comm_ring A] [ring B] [algebra A B]
/--
Suppose `x : B`, where `B` is an `A`-algebra.
The minimal polynomial `minpoly A x` of `x`
is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,
if such exists (`is_integral A x`) or zero otherwise.
For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then
the minimal polynomial of `f` is `minpoly 𝕜 f`.
-/
noncomputable def minpoly (x : B) : polynomial A :=
if hx : is_integral A x then well_founded.min degree_lt_wf _ hx else 0
end min_poly_def
namespace minpoly
section ring
variables [comm_ring A] [ring B] [algebra A B]
variables {x : B}
/-- A minimal polynomial is monic. -/
lemma monic (hx : is_integral A x) : monic (minpoly A x) :=
by { delta minpoly, rw dif_pos hx, exact (well_founded.min_mem degree_lt_wf _ hx).1 }
/-- A minimal polynomial is nonzero. -/
lemma ne_zero [nontrivial A] (hx : is_integral A x) : minpoly A x ≠ 0 :=
ne_zero_of_monic (monic hx)
lemma eq_zero (hx : ¬ is_integral A x) : minpoly A x = 0 :=
dif_neg hx
variables (A x)
/-- An element is a root of its minimal polynomial. -/
@[simp] lemma aeval : aeval x (minpoly A x) = 0 :=
begin
delta minpoly, split_ifs with hx,
{ exact (well_founded.min_mem degree_lt_wf _ hx).2 },
{ exact aeval_zero _ }
end
/-- A minimal polynomial is not `1`. -/
lemma ne_one [nontrivial B] : minpoly A x ≠ 1 :=
begin
intro h,
refine (one_ne_zero : (1 : B) ≠ 0) _,
simpa using congr_arg (polynomial.aeval x) h
end
lemma map_ne_one [nontrivial B] {R : Type*} [semiring R] [nontrivial R] (f : A →+* R) :
(minpoly A x).map f ≠ 1 :=
begin
by_cases hx : is_integral A x,
{ exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x) },
{ rw [eq_zero hx, polynomial.map_zero], exact zero_ne_one },
end
/-- A minimal polynomial is not a unit. -/
lemma not_is_unit [nontrivial B] : ¬ is_unit (minpoly A x) :=
begin
haveI : nontrivial A := (algebra_map A B).domain_nontrivial,
by_cases hx : is_integral A x,
{ exact mt (eq_one_of_is_unit_of_monic (monic hx)) (ne_one A x) },
{ rw [eq_zero hx], exact not_is_unit_zero }
end
lemma mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x ∈ (algebra_map A B).range :=
begin
have h : is_integral A x,
{ by_contra h,
rw [eq_zero h, degree_zero, ←with_bot.coe_one] at hx,
exact (ne_of_lt (show ⊥ < ↑1, from with_bot.bot_lt_coe 1) hx) },
have key := minpoly.aeval A x,
rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leading_coeff, C_1, one_mul, aeval_add,
aeval_C, aeval_X, ←eq_neg_iff_add_eq_zero, ←ring_hom.map_neg] at key,
exact ⟨-(minpoly A x).coeff 0, key.symm⟩,
end
/-- The defining property of the minimal polynomial of an element `x`:
it is the monic polynomial with smallest degree that has `x` as its root. -/
lemma min {p : polynomial A} (pmonic : p.monic) (hp : polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
begin
delta minpoly, split_ifs with hx,
{ exact le_of_not_lt (well_founded.not_lt_min degree_lt_wf _ hx ⟨pmonic, hp⟩) },
{ simp only [degree_zero, bot_le] }
end
@[nontriviality] lemma subsingleton [subsingleton B] : minpoly A x = 1 :=
begin
nontriviality A,
have := minpoly.min A x monic_one (subsingleton.elim _ _),
rw degree_one at this,
cases le_or_lt (minpoly A x).degree 0 with h h,
{ rwa (monic ⟨1, monic_one, by simp⟩ : (minpoly A x).monic).degree_le_zero_iff_eq_one at h },
{ exact (this.not_lt h).elim },
end
end ring
section comm_ring
variables [comm_ring A]
section ring
variables [ring B] [algebra A B] [nontrivial B]
variables {x : B}
/-- The degree of a minimal polynomial, as a natural number, is positive. -/
lemma nat_degree_pos (hx : is_integral A x) : 0 < nat_degree (minpoly A x) :=
begin
rw pos_iff_ne_zero,
intro ndeg_eq_zero,
have eq_one : minpoly A x = 1,
{ rw eq_C_of_nat_degree_eq_zero ndeg_eq_zero, convert C_1,
simpa only [ndeg_eq_zero.symm] using (monic hx).leading_coeff },
simpa only [eq_one, alg_hom.map_one, one_ne_zero] using aeval A x
end
/-- The degree of a minimal polynomial is positive. -/
lemma degree_pos (hx : is_integral A x) : 0 < degree (minpoly A x) :=
nat_degree_pos_iff_degree_pos.mp (nat_degree_pos hx)
/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,
then the minimal polynomial of `algebra_map A B a` is `X - C a`. -/
lemma eq_X_sub_C_of_algebra_map_inj [nontrivial A]
(a : A) (hf : function.injective (algebra_map A B)) :
minpoly A (algebra_map A B a) = X - C a :=
begin
have hdegle : (minpoly A (algebra_map A B a)).nat_degree ≤ 1,
{ apply with_bot.coe_le_coe.1,
rw [←degree_eq_nat_degree (ne_zero (@is_integral_algebra_map A B _ _ _ a)),
with_top.coe_one, ←degree_X_sub_C a],
refine min A (algebra_map A B a) (monic_X_sub_C a) _,
simp only [aeval_C, aeval_X, alg_hom.map_sub, sub_self] },
have hdeg : (minpoly A (algebra_map A B a)).degree = 1,
{ apply (degree_eq_iff_nat_degree_eq (ne_zero (@is_integral_algebra_map A B _ _ _ a))).2,
apply le_antisymm hdegle (nat_degree_pos (@is_integral_algebra_map A B _ _ _ a)) },
have hrw := eq_X_add_C_of_degree_eq_one hdeg,
simp only [monic (@is_integral_algebra_map A B _ _ _ a), one_mul,
monic.leading_coeff, ring_hom.map_one] at hrw,
have h0 : (minpoly A (algebra_map A B a)).coeff 0 = -a,
{ have hroot := aeval A (algebra_map A B a),
rw [hrw, add_comm] at hroot,
simp only [aeval_C, aeval_X, aeval_add] at hroot,
replace hroot := eq_neg_of_add_eq_zero hroot,
rw [←ring_hom.map_neg _ a] at hroot,
exact (hf hroot) },
rw hrw,
simp only [h0, ring_hom.map_neg, sub_eq_add_neg],
end
end ring
section is_domain
variables [is_domain A] [ring B] [algebra A B]
variables {x : B}
/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/
lemma aeval_ne_zero_of_dvd_not_unit_minpoly {a : polynomial A} (hx : is_integral A x)
(hamonic : a.monic) (hdvd : dvd_not_unit a (minpoly A x)) :
polynomial.aeval x a ≠ 0 :=
begin
intro ha,
refine not_lt_of_ge (minpoly.min A x hamonic ha) _,
obtain ⟨hzeroa, b, hb_nunit, prod⟩ := hdvd,
have hbmonic : b.monic,
{ rw monic.def,
have := monic hx,
rwa [monic.def, prod, leading_coeff_mul, monic.def.mp hamonic, one_mul] at this },
have hzerob : b ≠ 0 := hbmonic.ne_zero,
have degbzero : 0 < b.nat_degree,
{ apply nat.pos_of_ne_zero,
intro h,
have h₁ := eq_C_of_nat_degree_eq_zero h,
rw [←h, ←leading_coeff, monic.def.1 hbmonic, C_1] at h₁,
rw h₁ at hb_nunit,
have := is_unit_one,
contradiction },
rw [prod, degree_mul, degree_eq_nat_degree hzeroa, degree_eq_nat_degree hzerob],
exact_mod_cast lt_add_of_pos_right _ degbzero,
end
variables [is_domain B]
/-- A minimal polynomial is irreducible. -/
lemma irreducible (hx : is_integral A x) : irreducible (minpoly A x) :=
begin
cases irreducible_or_factor (minpoly A x) (not_is_unit A x) with hirr hred,
{ exact hirr },
exfalso,
obtain ⟨a, b, ha_nunit, hb_nunit, hab_eq⟩ := hred,
have coeff_prod : a.leading_coeff * b.leading_coeff = 1,
{ rw [←monic.def.1 (monic hx), ←hab_eq],
simp only [leading_coeff_mul] },
have hamonic : (a * C b.leading_coeff).monic,
{ rw monic.def,
simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },
have hbmonic : (b * C a.leading_coeff).monic,
{ rw [monic.def, mul_comm],
simp only [coeff_prod, leading_coeff_mul, leading_coeff_C] },
have prod : minpoly A x = (a * C b.leading_coeff) * (b * C a.leading_coeff),
{ symmetry,
calc a * C b.leading_coeff * (b * C a.leading_coeff)
= a * b * (C a.leading_coeff * C b.leading_coeff) : by ring
... = a * b * (C (a.leading_coeff * b.leading_coeff)) : by simp only [ring_hom.map_mul]
... = a * b : by rw [coeff_prod, C_1, mul_one]
... = minpoly A x : hab_eq },
have hzero := aeval A x,
rw [prod, aeval_mul, mul_eq_zero] at hzero,
cases hzero,
{ refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hamonic _ hzero,
exact ⟨hamonic.ne_zero, _, mt is_unit_of_mul_is_unit_left hb_nunit, prod⟩ },
{ refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hbmonic _ hzero,
rw mul_comm at prod,
exact ⟨hbmonic.ne_zero, _, mt is_unit_of_mul_is_unit_left ha_nunit, prod⟩ },
end
end is_domain
end comm_ring
section field
variables [field A]
section ring
variables [ring B] [algebra A B]
variables {x : B}
variables (A x)
/-- If an element `x` is a root of a nonzero polynomial `p`,
then the degree of `p` is at least the degree of the minimal polynomial of `x`. -/
lemma degree_le_of_ne_zero
{p : polynomial A} (pnz : p ≠ 0) (hp : polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
calc degree (minpoly A x) ≤ degree (p * C (leading_coeff p)⁻¹) :
min A x (monic_mul_leading_coeff_inv pnz) (by simp [hp])
... = degree p : degree_mul_leading_coeff_inv p pnz
/-- The minimal polynomial of an element `x` is uniquely characterized by its defining property:
if there is another monic polynomial of minimal degree that has `x` as a root,
then this polynomial is equal to the minimal polynomial of `x`. -/
lemma unique {p : polynomial A}
(pmonic : p.monic) (hp : polynomial.aeval x p = 0)
(pmin : ∀ q : polynomial A, q.monic → polynomial.aeval x q = 0 → degree p ≤ degree q) :
p = minpoly A x :=
begin
have hx : is_integral A x := ⟨p, pmonic, hp⟩,
symmetry, apply eq_of_sub_eq_zero,
by_contra hnz,
have := degree_le_of_ne_zero A x hnz (by simp [hp]),
contrapose! this,
apply degree_sub_lt _ (ne_zero hx),
{ rw [(monic hx).leading_coeff, pmonic.leading_coeff] },
{ exact le_antisymm (min A x pmonic hp)
(pmin (minpoly A x) (monic hx) (aeval A x)) }
end
/-- If an element `x` is a root of a polynomial `p`,
then the minimal polynomial of `x` divides `p`. -/
lemma dvd {p : polynomial A} (hp : polynomial.aeval x p = 0) : minpoly A x ∣ p :=
begin
by_cases hp0 : p = 0,
{ simp only [hp0, dvd_zero] },
have hx : is_integral A x,
{ rw ← is_algebraic_iff_is_integral, exact ⟨p, hp0, hp⟩ },
rw ← dvd_iff_mod_by_monic_eq_zero (monic hx),
by_contra hnz,
have := degree_le_of_ne_zero A x hnz _,
{ contrapose! this,
exact degree_mod_by_monic_lt _ (monic hx) },
{ rw ← mod_by_monic_add_div p (monic hx) at hp,
simpa using hp }
end
lemma dvd_map_of_is_scalar_tower (A K : Type*) {R : Type*} [comm_ring A] [field K] [comm_ring R]
[algebra A K] [algebra A R] [algebra K R] [is_scalar_tower A K R] (x : R) :
minpoly K x ∣ (minpoly A x).map (algebra_map A K) :=
by { refine minpoly.dvd K x _, rw [← is_scalar_tower.aeval_apply, minpoly.aeval] }
/-- If `y` is a conjugate of `x` over a field `K`, then it is a conjugate over a subring `R`. -/
lemma aeval_of_is_scalar_tower (R : Type*) {K T U : Type*} [comm_ring R] [field K] [comm_ring T]
[algebra R K] [algebra K T] [algebra R T] [is_scalar_tower R K T]
[comm_semiring U] [algebra K U] [algebra R U] [is_scalar_tower R K U]
(x : T) (y : U)
(hy : polynomial.aeval y (minpoly K x) = 0) : polynomial.aeval y (minpoly R x) = 0 :=
by { rw is_scalar_tower.aeval_apply R K,
exact eval₂_eq_zero_of_dvd_of_eval₂_eq_zero (algebra_map K U) y
(minpoly.dvd_map_of_is_scalar_tower R K x) hy }
variables {A x}
theorem eq_of_irreducible_of_monic
[nontrivial B] {p : polynomial A} (hp1 : _root_.irreducible p)
(hp2 : polynomial.aeval x p = 0) (hp3 : p.monic) : p = minpoly A x :=
let ⟨q, hq⟩ := dvd A x hp2 in
eq_of_monic_of_associated hp3 (monic ⟨p, ⟨hp3, hp2⟩⟩) $
mul_one (minpoly A x) ▸ hq.symm ▸ associated.mul_left _ $
associated_one_iff_is_unit.2 $ (hp1.is_unit_or_is_unit hq).resolve_left $ not_is_unit A x
lemma eq_of_irreducible [nontrivial B] {p : polynomial A}
(hp1 : _root_.irreducible p) (hp2 : polynomial.aeval x p = 0) :
p * C p.leading_coeff⁻¹ = minpoly A x :=
begin
have : p.leading_coeff ≠ 0 := leading_coeff_ne_zero.mpr hp1.ne_zero,
apply eq_of_irreducible_of_monic,
{ exact associated.irreducible ⟨⟨C p.leading_coeff⁻¹, C p.leading_coeff,
by rwa [←C_mul, inv_mul_cancel, C_1], by rwa [←C_mul, mul_inv_cancel, C_1]⟩, rfl⟩ hp1 },
{ rw [aeval_mul, hp2, zero_mul] },
{ rwa [polynomial.monic, leading_coeff_mul, leading_coeff_C, mul_inv_cancel] },
end
/-- If `y` is the image of `x` in an extension, their minimal polynomials coincide.
We take `h : y = algebra_map L T x` as an argument because `rw h` typically fails
since `is_integral R y` depends on y.
-/
lemma eq_of_algebra_map_eq {K S T : Type*} [field K] [comm_ring S] [comm_ring T]
[algebra K S] [algebra K T] [algebra S T]
[is_scalar_tower K S T] (hST : function.injective (algebra_map S T))
{x : S} {y : T} (hx : is_integral K x) (h : y = algebra_map S T x) :
minpoly K x = minpoly K y :=
minpoly.unique _ _ (minpoly.monic hx)
(by rw [h, ← is_scalar_tower.algebra_map_aeval, minpoly.aeval, ring_hom.map_zero])
(λ q q_monic root_q, minpoly.min _ _ q_monic
(is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero K S T hST
(h ▸ root_q : polynomial.aeval (algebra_map S T x) q = 0)))
section gcd_domain
/-- For GCD domains, the minimal polynomial over the ring is the same as the minimal polynomial
over the fraction field. -/
lemma gcd_domain_eq_field_fractions {A R : Type*} (K : Type*) [comm_ring A] [is_domain A]
[normalized_gcd_monoid A] [field K]
[comm_ring R] [is_domain R] [algebra A K] [is_fraction_ring A K]
[algebra K R] [algebra A R] [is_scalar_tower A K R] {x : R} (hx : is_integral A x) :
minpoly K x = (minpoly A x).map (algebra_map A K) :=
begin
symmetry,
refine eq_of_irreducible_of_monic _ _ _,
{ exact (polynomial.is_primitive.irreducible_iff_irreducible_map_fraction_map
(polynomial.monic.is_primitive (monic hx))).1 (irreducible hx) },
{ have htower := is_scalar_tower.aeval_apply A K R x (minpoly A x),
rwa [aeval, eq_comm] at htower },
{ exact monic_map _ (monic hx) }
end
/-- For GCD domains, the minimal polynomial divides any primitive polynomial that has the integral
element as root. -/
lemma gcd_domain_dvd {A R : Type*} (K : Type*)
[comm_ring A] [is_domain A] [normalized_gcd_monoid A] [field K]
[comm_ring R] [is_domain R] [algebra A K]
[is_fraction_ring A K] [algebra K R] [algebra A R] [is_scalar_tower A K R]
{x : R} (hx : is_integral A x)
{P : polynomial A} (hprim : is_primitive P) (hroot : polynomial.aeval x P = 0) :
minpoly A x ∣ P :=
begin
apply (is_primitive.dvd_iff_fraction_map_dvd_fraction_map K
(monic.is_primitive (monic hx)) hprim).2,
rw ← gcd_domain_eq_field_fractions K hx,
refine dvd _ _ _,
rwa ← is_scalar_tower.aeval_apply
end
end gcd_domain
variables (B) [nontrivial B]
/-- If `B/K` is a nontrivial algebra over a field, and `x` is an element of `K`,
then the minimal polynomial of `algebra_map K B x` is `X - C x`. -/
lemma eq_X_sub_C (a : A) : minpoly A (algebra_map A B a) = X - C a :=
eq_X_sub_C_of_algebra_map_inj a (algebra_map A B).injective
lemma eq_X_sub_C' (a : A) : minpoly A a = X - C a := eq_X_sub_C A a
variables (A)
/-- The minimal polynomial of `0` is `X`. -/
@[simp] lemma zero : minpoly A (0:B) = X :=
by simpa only [add_zero, C_0, sub_eq_add_neg, neg_zero, ring_hom.map_zero]
using eq_X_sub_C B (0:A)
/-- The minimal polynomial of `1` is `X - 1`. -/
@[simp] lemma one : minpoly A (1:B) = X - 1 :=
by simpa only [ring_hom.map_one, C_1, sub_eq_add_neg] using eq_X_sub_C B (1:A)
end ring
section is_domain
variables [ring B] [is_domain B] [algebra A B]
variables {x : B}
/-- A minimal polynomial is prime. -/
lemma prime (hx : is_integral A x) : prime (minpoly A x) :=
begin
refine ⟨ne_zero hx, not_is_unit A x, _⟩,
rintros p q ⟨d, h⟩,
have : polynomial.aeval x (p*q) = 0 := by simp [h, aeval A x],
replace : polynomial.aeval x p = 0 ∨ polynomial.aeval x q = 0 := by simpa,
exact or.imp (dvd A x) (dvd A x) this
end
/-- If `L/K` is a field extension and an element `y` of `K` is a root of the minimal polynomial
of an element `x ∈ L`, then `y` maps to `x` under the field embedding. -/
lemma root {x : B} (hx : is_integral A x) {y : A} (h : is_root (minpoly A x) y) :
algebra_map A B y = x :=
have key : minpoly A x = X - C y :=
eq_of_monic_of_associated (monic hx) (monic_X_sub_C y) (associated_of_dvd_dvd
((irreducible_X_sub_C y).dvd_symm (irreducible hx) (dvd_iff_is_root.2 h))
(dvd_iff_is_root.2 h)),
by { have := aeval A x, rwa [key, alg_hom.map_sub, aeval_X, aeval_C, sub_eq_zero, eq_comm] at this }
/-- The constant coefficient of the minimal polynomial of `x` is `0` if and only if `x = 0`. -/
@[simp] lemma coeff_zero_eq_zero (hx : is_integral A x) : coeff (minpoly A x) 0 = 0 ↔ x = 0 :=
begin
split,
{ intro h,
have zero_root := zero_is_root_of_coeff_zero_eq_zero h,
rw ← root hx zero_root,
exact ring_hom.map_zero _ },
{ rintro rfl, simp }
end
/-- The minimal polynomial of a nonzero element has nonzero constant coefficient. -/
lemma coeff_zero_ne_zero (hx : is_integral A x) (h : x ≠ 0) : coeff (minpoly A x) 0 ≠ 0 :=
by { contrapose! h, simpa only [hx, coeff_zero_eq_zero] using h }
end is_domain
end field
end minpoly
|
e891cbd13141bdcf1ce4a36b68eee93fc885ae9e | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/set_theory/schroeder_bernstein.lean | 8015ca5aee560b4cb24ff762ea8d41a1f7dec1ef | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,052 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
The Schröder-Bernstein theorem, and well ordering of cardinals.
-/
import order.fixed_points
import order.zorn
open set classical
open_locale classical
universes u v
namespace function
namespace embedding
section antisymm
variables {α : Type u} {β : Type v}
theorem schroeder_bernstein {f : α → β} {g : β → α}
(hf : function.injective f) (hg : function.injective g) : ∃h:α→β, bijective h :=
let s : set α := lfp $ λs, (g '' (f '' s)ᶜ)ᶜ in
have hs : s = (g '' (f '' s)ᶜ)ᶜ,
from lfp_eq $ assume s t h,
compl_subset_compl.mpr $ image_subset _ $
compl_subset_compl.mpr $ image_subset _ h,
have hns : sᶜ = g '' (f '' s)ᶜ,
from compl_injective $ by simp [hs.symm],
let g' := λa, @inv_fun β ⟨f a⟩ α g a in
have g'g : g' ∘ g = id,
from funext $ assume b, @left_inverse_inv_fun _ ⟨f (g b)⟩ _ _ hg b,
have hg'ns : g' '' sᶜ = (f '' s)ᶜ,
by rw [hns, ←image_comp, g'g, image_id],
let h := λa, if a ∈ s then f a else g' a in
have h '' univ = univ,
from calc h '' univ = h '' s ∪ h '' sᶜ : by rw [←image_union, union_compl_self]
... = f '' s ∪ g' '' sᶜ :
congr (congr_arg (∪)
(image_congr $ by simp [h, if_pos] {contextual := tt}))
(image_congr $ by simp [h, if_neg] {contextual := tt})
... = univ : by rw [hg'ns, union_compl_self],
have surjective h,
from assume b,
have b ∈ h '' univ, by rw [this]; trivial,
let ⟨a, _, eq⟩ := this in
⟨a, eq⟩,
have split : ∀x∈s, ∀y∉s, h x = h y → false,
from assume x hx y hy eq,
have y ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨y', hy', eq_y'⟩ := this in
have f x = y',
from calc f x = g' y : by simp [h, hx, hy, if_pos, if_neg] at eq; assumption
... = (g' ∘ g) y' : by simp [(∘), eq_y']
... = _ : by simp [g'g],
have y' ∈ f '' s, from this ▸ mem_image_of_mem _ hx,
hy' this,
have function.injective h,
from assume x y eq,
by_cases
(assume hx : x ∈ s, by_cases
(assume hy : y ∈ s, by simp [h, hx, hy, if_pos, if_neg] at eq; exact hf eq)
(assume hy : y ∉ s, (split x hx y hy eq).elim))
(assume hx : x ∉ s, by_cases
(assume hy : y ∈ s, (split y hy x hx eq.symm).elim)
(assume hy : y ∉ s,
have x ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨x', hx', eqx⟩ := this in
have y ∈ g '' (f '' s)ᶜ, by rwa [←hns],
let ⟨y', hy', eqy⟩ := this in
have g' x = g' y, by simp [h, hx, hy, if_pos, if_neg] at eq; assumption,
have (g' ∘ g) x' = (g' ∘ g) y', by simp [(∘), eqx, eqy, this],
have x' = y', by rwa [g'g] at this,
calc x = g x' : eqx.symm
... = g y' : by rw [this]
... = y : eqy)),
⟨h, ‹function.injective h›, ‹function.surjective h›⟩
theorem antisymm : (α ↪ β) → (β ↪ α) → nonempty (α ≃ β)
| ⟨e₁, h₁⟩ ⟨e₂, h₂⟩ :=
let ⟨f, hf⟩ := schroeder_bernstein h₁ h₂ in
⟨equiv.of_bijective f hf⟩
end antisymm
section wo
parameters {ι : Type u} {β : ι → Type v}
@[reducible] private def sets := {s : set (∀ i, β i) |
∀ (x ∈ s) (y ∈ s) i, (x : ∀ i, β i) i = y i → x = y}
theorem min_injective (I : nonempty ι) : ∃ i, nonempty (∀ j, β i ↪ β j) :=
let ⟨s, hs, ms⟩ := show ∃s∈sets, ∀a∈sets, s ⊆ a → a = s, from
zorn.zorn_subset sets (λ c hc hcc, ⟨⋃₀ c,
λ x ⟨p, hpc, hxp⟩ y ⟨q, hqc, hyq⟩ i hi, (hcc.total hpc hqc).elim
(λ h, hc hqc x (h hxp) y hyq i hi) (λ h, hc hpc x hxp y (h hyq) i hi),
λ _, subset_sUnion_of_mem⟩) in
let ⟨i, e⟩ := show ∃ i, ∀ y, ∃ x ∈ s, (x : ∀ i, β i) i = y, from
classical.by_contradiction $ λ h,
have h : ∀ i, ∃ y, ∀ x ∈ s, (x : ∀ i, β i) i ≠ y,
by simpa only [not_exists, not_forall] using h,
let ⟨f, hf⟩ := axiom_of_choice h in
have f ∈ s, from
have insert f s ∈ sets := λ x hx y hy, begin
cases hx; cases hy, {simp [hx, hy]},
{ subst x, exact λ i e, (hf i y hy e.symm).elim },
{ subst y, exact λ i e, (hf i x hx e).elim },
{ exact hs x hx y hy }
end, ms _ this (subset_insert f s) ▸ mem_insert _ _,
let ⟨i⟩ := I in hf i f this rfl in
let ⟨f, hf⟩ := axiom_of_choice e in
⟨i, ⟨λ j, ⟨λ a, f a j, λ a b e',
let ⟨sa, ea⟩ := hf a, ⟨sb, eb⟩ := hf b in
by rw [← ea, ← eb, hs _ sa _ sb _ e']⟩⟩⟩
end wo
theorem total {α : Type u} {β : Type v} : nonempty (α ↪ β) ∨ nonempty (β ↪ α) :=
match @min_injective bool (λ b, cond b (ulift α) (ulift.{(max u v) v} β)) ⟨tt⟩ with
| ⟨tt, ⟨h⟩⟩ := let ⟨f, hf⟩ := h ff in or.inl ⟨embedding.congr equiv.ulift equiv.ulift ⟨f, hf⟩⟩
| ⟨ff, ⟨h⟩⟩ := let ⟨f, hf⟩ := h tt in or.inr ⟨embedding.congr equiv.ulift equiv.ulift ⟨f, hf⟩⟩
end
end embedding
end function
|
d3b468374a4b6cc5163d8378078c82b160519255 | 22e97a5d648fc451e25a06c668dc03ac7ed7bc25 | /src/linear_algebra/bilinear_form.lean | dda43292d42a7e0045ca7466ac25ad62952c2eff | [
"Apache-2.0"
] | permissive | keeferrowan/mathlib | f2818da875dbc7780830d09bd4c526b0764a4e50 | aad2dfc40e8e6a7e258287a7c1580318e865817e | refs/heads/master | 1,661,736,426,952 | 1,590,438,032,000 | 1,590,438,032,000 | 266,892,663 | 0 | 0 | Apache-2.0 | 1,590,445,835,000 | 1,590,445,835,000 | null | UTF-8 | Lean | false | false | 15,959 | lean | /-
Copyright (c) 2018 Andreas Swerdlow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Andreas Swerdlow
-/
import linear_algebra.matrix
import linear_algebra.tensor_product
/-!
# Bilinear form
This file defines a bilinear form over a module. Basic ideas
such as orthogonality are also introduced, as well as reflexivive,
symmetric and alternating bilinear forms.
A bilinear form on an R-module V, is a function from V x V to R,
that is linear in both arguments
## Notations
Given any term B of type bilin_form, due to a coercion, can use
the notation B x y to refer to the function field, ie. B x y = B.bilin x y.
## References
* <https://en.wikipedia.org/wiki/Bilinear_form>
## Tags
Bilinear form,
-/
universes u v w
/-- A bilinear form over a module -/
structure bilin_form (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] :=
(bilin : M → M → R)
(bilin_add_left : ∀ (x y z : M), bilin (x + y) z = bilin x z + bilin y z)
(bilin_smul_left : ∀ (a : R) (x y : M), bilin (a • x) y = a * (bilin x y))
(bilin_add_right : ∀ (x y z : M), bilin x (y + z) = bilin x y + bilin x z)
(bilin_smul_right : ∀ (a : R) (x y : M), bilin x (a • y) = a * (bilin x y))
/-- A map with two arguments that is linear in both is a bilinear form -/
def linear_map.to_bilin {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
(f : M →ₗ[R] M →ₗ[R] R) : bilin_form R M :=
{ bilin := λ x y, f x y,
bilin_add_left := λ x y z, (linear_map.map_add f x y).symm ▸ linear_map.add_apply (f x) (f y) z,
bilin_smul_left := λ a x y, by {rw linear_map.map_smul, rw linear_map.smul_apply, rw smul_eq_mul},
bilin_add_right := λ x y z, linear_map.map_add (f x) y z,
bilin_smul_right := λ a x y, linear_map.map_smul (f x) a y }
namespace bilin_form
variables {R : Type u} {M : Type v} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
instance : has_coe_to_fun (bilin_form R M) :=
⟨_, λ B, B.bilin⟩
@[simp] lemma coe_fn_mk (f : M → M → R) (h₁ h₂ h₃ h₄) :
(bilin_form.mk f h₁ h₂ h₃ h₄ : M → M → R) = f :=
rfl
lemma coe_fn_congr : Π {x x' y y' : M}, x = x' → y = y' → B x y = B x' y'
| _ _ _ _ rfl rfl := rfl
lemma add_left (x y z : M) : B (x + y) z = B x z + B y z := bilin_add_left B x y z
lemma smul_left (a : R) (x y : M) : B (a • x) y = a * (B x y) := bilin_smul_left B a x y
lemma add_right (x y z : M) : B x (y + z) = B x y + B x z := bilin_add_right B x y z
lemma smul_right (a : R) (x y : M) : B x (a • y) = a * (B x y) := bilin_smul_right B a x y
lemma zero_left (x : M) :
B 0 x = 0 := by {rw [←@zero_smul R _ _ _ _ (0 : M), smul_left, zero_mul]}
lemma zero_right (x : M) :
B x 0 = 0 := by rw [←@zero_smul _ _ _ _ _ (0 : M), smul_right, ring.zero_mul]
lemma neg_left (x y : M) :
B (-x) y = -(B x y) := by rw [←@neg_one_smul R _ _, smul_left, neg_one_mul]
lemma neg_right (x y : M) :
B x (-y) = -(B x y) := by rw [←@neg_one_smul R _ _, smul_right, neg_one_mul]
lemma sub_left (x y z : M) :
B (x - y) z = B x z - B y z := by rw [sub_eq_add_neg, add_left, neg_left]; refl
lemma sub_right (x y z : M) :
B x (y - z) = B x y - B x z := by rw [sub_eq_add_neg, add_right, neg_right]; refl
variable {D : bilin_form R M}
@[ext] lemma ext (H : ∀ (x y : M), B x y = D x y) : B = D := by {cases B, cases D, congr, funext, exact H _ _}
instance : add_comm_group (bilin_form R M) :=
{ add := λ B D, { bilin := λ x y, B x y + D x y,
bilin_add_left := λ x y z, by {rw add_left, rw add_left, ac_refl},
bilin_smul_left := λ a x y, by {rw [smul_left, smul_left, mul_add]},
bilin_add_right := λ x y z, by {rw add_right, rw add_right, ac_refl},
bilin_smul_right := λ a x y, by {rw [smul_right, smul_right, mul_add]} },
add_assoc := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin coe_fn has_coe_to_fun.coe bilin, rw add_assoc},
zero := { bilin := λ x y, 0,
bilin_add_left := λ x y z, (add_zero 0).symm,
bilin_smul_left := λ a x y, (mul_zero a).symm,
bilin_add_right := λ x y z, (zero_add 0).symm,
bilin_smul_right := λ a x y, (mul_zero a).symm },
zero_add := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_add},
add_zero := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_zero},
neg := λ B, { bilin := λ x y, - (B.1 x y),
bilin_add_left := λ x y z, by rw [bilin_add_left, neg_add],
bilin_smul_left := λ a x y, by rw [bilin_smul_left, mul_neg_eq_neg_mul_symm],
bilin_add_right := λ x y z, by rw [bilin_add_right, neg_add],
bilin_smul_right := λ a x y, by rw [bilin_smul_right, mul_neg_eq_neg_mul_symm] },
add_left_neg := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw neg_add_self},
add_comm := by {intros, ext, unfold coe_fn has_coe_to_fun.coe bilin, rw add_comm} }
lemma add_apply (x y : M) : (B + D) x y = B x y + D x y := rfl
instance : inhabited (bilin_form R M) := ⟨0⟩
section
variables {R₂ : Type*} [comm_ring R₂] [module R₂ M] (F : bilin_form R₂ M) (f : M → M)
instance to_module : module R₂ (bilin_form R₂ M) :=
{ smul := λ c B, { bilin := λ x y, c * B x y,
bilin_add_left := λ x y z, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_left, left_distrib]},
bilin_smul_left := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_smul_left, ←mul_assoc, mul_comm c, mul_assoc]},
bilin_add_right := λ x y z, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_add_right, left_distrib]},
bilin_smul_right := λ a x y, by {unfold coe_fn has_coe_to_fun.coe bilin, rw [bilin_smul_right, ←mul_assoc, mul_comm c, mul_assoc]} },
smul_add := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw left_distrib},
add_smul := λ c B D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw right_distrib},
mul_smul := λ a c D, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_assoc},
one_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw one_mul},
zero_smul := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw zero_mul},
smul_zero := λ B, by {ext, unfold coe_fn has_coe_to_fun.coe bilin, rw mul_zero} }
lemma smul_apply (a : R₂) (x y : M) : (a • F) x y = a • (F x y) := rfl
/-- `B.to_linear_map` applies B on the left argument, then the right. -/
def to_linear_map : M →ₗ[R₂] M →ₗ[R₂] R₂ :=
linear_map.mk₂ R₂ F.1 (bilin_add_left F) (bilin_smul_left F) (bilin_add_right F) (bilin_smul_right F)
/-- Bilinear forms are equivalent to maps with two arguments that is linear in both. -/
def bilin_linear_map_equiv : (bilin_form R₂ M) ≃ₗ[R₂] (M →ₗ[R₂] M →ₗ[R₂] R₂) :=
{ to_fun := to_linear_map,
add := λ B D, rfl,
smul := λ a B, rfl,
inv_fun := linear_map.to_bilin,
left_inv := λ B, by {ext, refl},
right_inv := λ B, by {ext, refl} }
@[norm_cast]
lemma coe_fn_to_linear_map (x : M) : ⇑(F.to_linear_map x) = F x := rfl
lemma map_sum_left {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (w : M) :
B (t.sum g) w = t.sum (λ i, B (g i) w) :=
show B.to_linear_map (t.sum g) w = t.sum (λ i, B (g i) w),
by { rw [B.to_linear_map.map_sum, linear_map.coe_fn_sum, finset.sum_apply], norm_cast }
lemma map_sum_right {α} (B : bilin_form R₂ M) (t : finset α) (g : α → M) (v : M) :
B v (t.sum g) = t.sum (λ i, B v (g i)) :=
(B.to_linear_map v).map_sum
end
section comp
variables {N : Type w} [add_comm_group N] [module R N]
/-- Apply a linear map on the left and right argument of a bilinear form. -/
def comp (B : bilin_form R N) (l r : M →ₗ[R] N) : bilin_form R M :=
{ bilin := λ x y, B (l x) (r y),
bilin_add_left := λ x y z, by simp [add_left],
bilin_smul_left := λ x y z, by simp [smul_left],
bilin_add_right := λ x y z, by simp [add_right],
bilin_smul_right := λ x y z, by simp [smul_right] }
/-- Apply a linear map to the left argument of a bilinear form. -/
def comp_left (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp f linear_map.id
/-- Apply a linear map to the right argument of a bilinear form. -/
def comp_right (B : bilin_form R M) (f : M →ₗ[R] M) : bilin_form R M :=
B.comp linear_map.id f
@[simp] lemma comp_left_comp_right (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_left l).comp_right r = B.comp l r := rfl
@[simp] lemma comp_right_comp_left (B : bilin_form R M) (l r : M →ₗ[R] M) :
(B.comp_right r).comp_left l = B.comp l r := rfl
@[simp] lemma comp_apply (B : bilin_form R N) (l r : M →ₗ[R] N) (v w) :
B.comp l r v w = B (l v) (r w) := rfl
@[simp] lemma comp_left_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_left f v w = B (f v) w := rfl
@[simp] lemma comp_right_apply (B : bilin_form R M) (f : M →ₗ[R] M) (v w) :
B.comp_right f v w = B v (f w) := rfl
end comp
/-- The proposition that two elements of a bilinear form space are orthogonal -/
def is_ortho (B : bilin_form R M) (x y : M) : Prop :=
B x y = 0
lemma ortho_zero (x : M) :
is_ortho B (0 : M) x := zero_left x
section
variables {R₃ : Type*} [domain R₃] [module R₃ M] {G : bilin_form R₃ M}
theorem ortho_smul_left {x y : M} {a : R₃} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G (a • x) y) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_left, H, ring.mul_zero] },
{ rw [smul_left, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }}
end
theorem ortho_smul_right {x y : M} {a : R₃} (ha : a ≠ 0) :
(is_ortho G x y) ↔ (is_ortho G x (a • y)) :=
begin
dunfold is_ortho,
split; intro H,
{ rw [smul_right, H, ring.mul_zero] },
{ rw [smul_right, mul_eq_zero] at H,
cases H,
{ trivial },
{ exact H }}
end
end
end bilin_form
section matrix
variables {R : Type u} [comm_ring R]
variables {n o : Type w} [fintype n] [fintype o]
open bilin_form finset matrix
open_locale matrix
/-- The linear map from `matrix n n R` to bilinear forms on `n → R`. -/
def matrix.to_bilin_formₗ : matrix n n R →ₗ[R] bilin_form R (n → R) :=
{ to_fun := λ M,
{ bilin := λ v w, (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩,
bilin_add_left := λ x y z, by simp [matrix.add_mul],
bilin_smul_left := λ a x y, by simp,
bilin_add_right := λ x y z, by simp [matrix.mul_add],
bilin_smul_right := λ a x y, by simp },
add := λ f g, by { ext, simp [add_apply, matrix.mul_add, matrix.add_mul] },
smul := λ f g, by { ext, simp [smul_apply] } }
/-- The map from `matrix n n R` to bilinear forms on `n → R`. -/
def matrix.to_bilin_form : matrix n n R → bilin_form R (n → R) :=
matrix.to_bilin_formₗ.to_fun
lemma matrix.to_bilin_form_apply (M : matrix n n R) (v w : n → R) :
(M.to_bilin_form : (n → R) → (n → R) → R) v w = (row v ⬝ M ⬝ col w) ⟨⟩ ⟨⟩ := rfl
variables [decidable_eq n] [decidable_eq o]
/-- The linear map from bilinear forms on `n → R` to `matrix n n R`. -/
def bilin_form.to_matrixₗ : bilin_form R (n → R) →ₗ[R] matrix n n R :=
{ to_fun := λ B i j, B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0),
add := λ f g, rfl,
smul := λ f g, rfl }
/-- The map from bilinear forms on `n → R` to `matrix n n R`. -/
def bilin_form.to_matrix : bilin_form R (n → R) → matrix n n R :=
bilin_form.to_matrixₗ.to_fun
lemma bilin_form.to_matrix_apply (B : bilin_form R (n → R)) (i j : n) :
B.to_matrix i j = B (λ n, if n = i then 1 else 0) (λ n, if n = j then 1 else 0) := rfl
lemma bilin_form.to_matrix_smul (B : bilin_form R (n → R)) (x : R) :
(x • B).to_matrix = x • B.to_matrix :=
by { ext, refl }
open bilin_form
lemma bilin_form.to_matrix_comp (B : bilin_form R (n → R)) (l r : (o → R) →ₗ[R] (n → R)) :
(B.comp l r).to_matrix = l.to_matrixᵀ ⬝ B.to_matrix ⬝ r.to_matrix :=
begin
ext i j,
simp only [to_matrix_apply, comp_apply, mul_val, sum_mul],
have sum_smul_eq : Π (f : (o → R) →ₗ[R] (n → R)) (i : o),
f (λ n, ite (n = i) 1 0) = univ.sum (λ k, f.to_matrix k i • λ n, ite (n = k) (1 : R) 0),
{ intros f i,
ext j,
change f (λ n, ite (n = i) 1 0) j = univ.sum (λ k n, f.to_matrix k i * ite (n = k) (1 : R) 0) j,
simp [linear_map.to_matrix, linear_map.to_matrixₗ, eq_comm] },
simp_rw [sum_smul_eq, map_sum_right, map_sum_left, smul_right, mul_comm, smul_left],
refl
end
lemma bilin_form.to_matrix_comp_left (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) :
(B.comp_left f).to_matrix = f.to_matrixᵀ ⬝ B.to_matrix :=
by simp [comp_left, bilin_form.to_matrix_comp]
lemma bilin_form.to_matrix_comp_right (B : bilin_form R (n → R)) (f : (n → R) →ₗ[R] (n → R)) :
(B.comp_right f).to_matrix = B.to_matrix ⬝ f.to_matrix :=
by simp [comp_right, bilin_form.to_matrix_comp]
lemma bilin_form.mul_to_matrix_mul (B : bilin_form R (n → R)) (M : matrix o n R) (N : matrix n o R) :
M ⬝ B.to_matrix ⬝ N = (B.comp (Mᵀ.to_lin) (N.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp (Mᵀ.to_lin) (N.to_lin), to_lin_to_matrix] }
lemma bilin_form.mul_to_matrix (B : bilin_form R (n → R)) (M : matrix n n R) :
M ⬝ B.to_matrix = (B.comp_left (Mᵀ.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp_left (Mᵀ.to_lin), to_lin_to_matrix] }
lemma bilin_form.to_matrix_mul (B : bilin_form R (n → R)) (M : matrix n n R) :
B.to_matrix ⬝ M = (B.comp_right (M.to_lin)).to_matrix :=
by { ext, simp [B.to_matrix_comp_right (M.to_lin), to_lin_to_matrix] }
/-- Bilinear forms are linearly equivalent to matrices. -/
def bilin_form_equiv_matrix : bilin_form R (n → R) ≃ₗ[R] matrix n n R :=
{ inv_fun := matrix.to_bilin_form,
left_inv := λ B, show B.to_matrix.to_bilin_form = B,
begin
ext,
rw [matrix.to_bilin_form_apply, B.mul_to_matrix_mul, bilin_form.to_matrix_apply, comp_apply],
{ apply coe_fn_congr; ext; simp [mul_vec] },
apply_instance
end,
right_inv := λ M, by { ext, simp [bilin_form.to_matrixₗ, matrix.to_bilin_form_apply, mul_val] },
..bilin_form.to_matrixₗ }
end matrix
namespace refl_bilin_form
open refl_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is reflexive -/
def is_refl (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = 0 → B y x = 0
variable (H : is_refl B)
lemma eq_zero : ∀ {x y : M}, B x y = 0 → B y x = 0 := λ x y, H x y
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := ⟨eq_zero H, eq_zero H⟩
end refl_bilin_form
namespace sym_bilin_form
open sym_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is symmetric -/
def is_sym (B : bilin_form R M) : Prop := ∀ (x y : M), B x y = B y x
variable (H : is_sym B)
lemma sym (x y : M) : B x y = B y x := H x y
lemma is_refl : refl_bilin_form.is_refl B := λ x y H1, H x y ▸ H1
lemma ortho_sym {x y : M} :
is_ortho B x y ↔ is_ortho B y x := refl_bilin_form.ortho_sym (is_refl H)
end sym_bilin_form
namespace alt_bilin_form
open alt_bilin_form bilin_form
variables {R : Type*} {M : Type*} [ring R] [add_comm_group M] [module R M] {B : bilin_form R M}
/-- The proposition that a bilinear form is alternating -/
def is_alt (B : bilin_form R M) : Prop := ∀ (x : M), B x x = 0
variable (H : is_alt B)
include H
lemma self_eq_zero (x : M) : B x x = 0 := H x
lemma neg (x y : M) :
- B x y = B y x :=
begin
have H1 : B (x + y) (x + y) = 0,
{ exact self_eq_zero H (x + y) },
rw [add_left, add_right, add_right,
self_eq_zero H, self_eq_zero H, ring.zero_add,
ring.add_zero, add_eq_zero_iff_neg_eq] at H1,
exact H1,
end
end alt_bilin_form
|
7d6fe97543b7c7a90ad81efba8df665471e055a6 | 3dc4623269159d02a444fe898d33e8c7e7e9461b | /.github/workflows/project_1_a_decrire/foncteur/Idempotent_group/Idempotent_group.lean | a315299c6366533c9d4974a562ab804edf2cdaa4 | [] | no_license | Or7ando/lean | cc003e6c41048eae7c34aa6bada51c9e9add9e66 | d41169cf4e416a0d42092fb6bdc14131cee9dd15 | refs/heads/master | 1,650,600,589,722 | 1,587,262,906,000 | 1,587,262,906,000 | 255,387,160 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,896 | lean | import algebra.category.CommRing.basic
import algebra.ring
import tactic
import category_theory.functor_category -- this transitively imports
import algebra.category.CommRing.basic
import algebra.ring
import category_theory.types
universes v u
/--
## This is the groupe AGL_1(R) : x ↦ ax + b invertible i.e with a inveritible ! The goal is to make
## into a groupe for composition !
-/
structure AGL_1 ( R : Type v) [comm_ring R] :=
(a b : R)
(y : R)
(certif : a * y = 1)
namespace AGL_1
section
variables {R : Type v} [comm_ring R]
@[ext]
lemma ext : ∀ {g1 g2 : AGL_1 R}, g1.a = g2.a → g1.b = g2.b → g1 = g2 := λ g1 g2, --- it's ok ? just don't use Bracket ?
begin
intros h1 h2,
cases g1, --- difficult i have to analyse !
cases g2,
congr ; try { assumption },
change g1_a = g2_a at h1,
rw h1 at g1_certif,
apply_fun (*) g2_y at g1_certif,
rwa [← mul_assoc, mul_comm g2_y, g2_certif, one_mul, mul_one] at g1_certif,
end
def one : AGL_1(R) := {a := 1, b:=0, y := 1, certif := mul_one 1}
instance : has_one (AGL_1 R) := ⟨one⟩
lemma one_a : (1 : AGL_1(R)).a = 1 := rfl
lemma one_b : (1 : AGL_1(R)).b = 0 := rfl
def of (r : R) : AGL_1(R) := {a := 1, b := r, y := 1, certif := mul_one 1}
lemma one_eq_of_one : one = of (0 : R) := rfl
def mul_map' : AGL_1(R) → AGL_1 (R) → AGL_1(R) := λ g1 g2,
{ a := g1.a * g2.a,
b := g1.a * g2.b + g1.b,
y := g1.y * g2.y ,
certif := begin
have H : g1.a * g2.a * (g1.y * g2.y) = (g1.a * g1.y) * (g2.a * g2.y),
ring,
rw H,
rw [g1.certif,g2.certif],
exact one_mul 1,
end}
instance : inhabited (AGL_1 R) := ⟨1⟩
instance : has_mul (AGL_1 R) := ⟨AGL_1.mul_map'⟩
lemma a_comp (g1 g2 : AGL_1 R) : (g1 * g2).a = g1.a * g2.a := rfl
lemma b_comp (g1 g2 : AGL_1 R) : (g1 * g2).b = g1.a * g2.b + g1.b := rfl
meta def AGL_ring : tactic unit :=
`[simp only [one_a, one_b, a_comp, b_comp], ring]
run_cmd add_interactive [`AGL_ring]
def mul_inv : AGL_1 R → AGL_1 R := λ g, --- change here ?
{ a := g.y,
b:= - g.y * g.b,
y := g.a ,
certif := begin rw mul_comm, exact g.certif, end }
instance : has_inv (AGL_1 R) := ⟨AGL_1.mul_inv⟩
lemma a_comp_inv (g : AGL_1 R) : (g⁻¹).a =g.y := rfl
lemma b_comp_inv (g : AGL_1 R) : (g⁻¹).b = - g.y * g.b := rfl
def Rotation (R : Type v)[comm_ring R] (a : R) (y : R): ( a * y = 1 ) → AGL_1(R) :=
λ certif, {a := a, b := 0, y := y, certif := certif}
def mul_one' (g : AGL_1 R) : g * 1 = g := begin ext; AGL_ring, end
def one_mul' (g : AGL_1 R) : 1 * g = g := begin ext ;AGL_ring, end
def mul_assoc' (g1 g2 g3 : AGL_1 R) : (g1 * g2) * g3 = g1 * (g2 * g3) :=
begin
ext; AGL_ring,
end
instance [has_repr R] : has_repr (AGL_1 (R)) := ⟨λ x, repr (x.a) ++ " X + " ++ repr (x.b)⟩
lemma mul_right_inv' (g : AGL_1 R) : g * g⁻¹ = 1 :=begin
ext,
rw [a_comp,a_comp_inv], exact g.certif,
rw [b_comp,b_comp_inv,← mul_assoc,one_b,mul_comm,mul_neg_eq_neg_mul_symm,g.certif],
ring,
end
lemma mul_left_inv' (g : AGL_1 R) : g⁻¹ * g = 1 :=begin
ext,
rw [a_comp,a_comp_inv, mul_comm],
exact g.certif,
rw [b_comp,one_b,a_comp_inv,mul_comm,b_comp_inv],
ring,
end
#eval of (3 : ℤ) * of(4 : ℤ)
instance : group (AGL_1 R) :=
{ mul := mul_map',
one := 1,
one_mul := one_mul',
mul_one := mul_one',
inv := mul_inv,
mul_assoc := mul_assoc',
mul_left_inv := mul_left_inv',}
open CommRing
open is_ring_hom
variables (R' : Type v)[comm_ring R'] (f : R → R')[is_ring_hom f]
def hom_map (R' : Type v) [comm_ring R'](f : R → R')[is_ring_hom f] : AGL_1 R → AGL_1 R' := λ g,
{
a := f g.a,
b := f g.b,
y := f g.y,
certif := begin rw [← map_mul (f),g.certif], exact map_one f,
end
}
lemma a_comp_hom (g : AGL_1 R) : (hom_map (R') (f) (g)).a = f g.a := rfl
lemma b_comp_hom (g : AGL_1 R) : (hom_map (R') (f) (g)).b = f g.b := rfl
lemma y_comp_hom (g : AGL_1 R) : (hom_map (R') (f) (g)).y = f g.y := rfl
lemma hom_map_group_comp (R' : Type v) [comm_ring R'](f : R → R')[is_ring_hom f] (g1 g2 : AGL_1 R) :
hom_map (R')(f) (g1 * g2) = hom_map(R') (f) g1 * hom_map (R')(f) g2 := begin
ext,
rw [a_comp,a_comp_hom,a_comp_hom,a_comp_hom,a_comp],
exact map_mul f,
rw [b_comp,b_comp_hom,b_comp_hom,b_comp_hom,a_comp_hom,b_comp,← map_mul f,← map_add f],
end
lemma hom_map_one (R' : Type v)[comm_ring R'](f : R → R')[is_ring_hom f] (g1 g2 : AGL_1 R) : hom_map R' (f) (1) = 1 :=
begin
ext,
rw [a_comp_hom,one_a,one_a],
exact map_one f,
rw [b_comp_hom,one_b,one_b],
exact map_zero f,
#print AGL_1
def AGL__1 : CommRing ⥤ Type v :=
{ obj := λ R, AGL_1 R,
map :=λ R R' f, hom_map R' f,
}
end
end AGL_1 |
2e1d335fa2d8b08ca57679a3731a0d82f6701ef1 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/class3.lean | 1daa55a1ed1e60d7d365cdc0b89beeb0898774e7 | [
"Apache-2.0"
] | permissive | soonhokong/lean | cb8aa01055ffe2af0fb99a16b4cda8463b882cd1 | 38607e3eb57f57f77c0ac114ad169e9e4262e24f | refs/heads/master | 1,611,187,284,081 | 1,450,766,737,000 | 1,476,122,547,000 | 11,513,992 | 2 | 0 | null | 1,401,763,102,000 | 1,374,182,235,000 | C++ | UTF-8 | Lean | false | false | 238 | lean | import logic data.prod
open prod inhabited
section
variable {A : Type}
variable {B : Type}
variable Ha : inhabited A
variable Hb : inhabited B
include Ha Hb
theorem tst : inhabited (Prop × A × B)
end
reveal tst
print tst
|
9082ebfe38dbccb3297b2121acd4383ca0d871e6 | a8ca99e8fae20e1383a6a786312b9f44f7dfdb42 | /coq/step_01.lean | 4e90a85c6de0c8355ff3af927f65f4ebce600042 | [
"MIT"
] | permissive | nolmeunion/learn | b715a4e9560101275c9c418d191cc198c905d189 | 482f4b8a5de81375e5663ea0b065d25f2f7da4b6 | refs/heads/master | 1,671,751,332,943 | 1,601,261,285,000 | 1,601,261,285,000 | 287,418,011 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 199 | lean | -- BEGIN
theorem and_commutative (p q : Prop) : p ∧ q → q ∧ p :=
assume hpq : p ∧ q,
have hp : p, from and.left hpq,
have hq : q, from and.right hpq,
show q ∧ p, from and.intro hq hp
-- END |
7af71ef9ee5cdca55fc6e575bdfda022b6a44921 | 01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab | /categories/products/switch.lean | 962004171f5404a9d1c874b9e6b88761e063b6b9 | [] | no_license | PatrickMassot/lean-category-theory | 0f56a83464396a253c28a42dece16c93baf8ad74 | ef239978e91f2e1c3b8e88b6e9c64c155dc56c99 | refs/heads/master | 1,629,739,187,316 | 1,512,422,659,000 | 1,512,422,659,000 | 113,098,786 | 0 | 0 | null | 1,512,424,022,000 | 1,512,424,022,000 | null | UTF-8 | Lean | false | false | 893 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan, Scott Morrison
import ..products
import ..natural_isomorphism
open categories
open categories.functor
open categories.natural_transformation
namespace categories.products
definition SwitchProductCategory ( C D : Category ) : Functor (C × D) (D × C) :=
{
onObjects := λ X, (X.snd, X.fst),
onMorphisms := λ _ _ f, (f.snd, f.fst),
identities := ♮,
functoriality := ♮
}
definition SwitchSymmetry
( C D : Category )
: NaturalIsomorphism (FunctorComposition (SwitchProductCategory C D) (SwitchProductCategory D C)) (IdentityFunctor (C × D)) :=
by tidy {hints:=[9, 8, 9, 8, 6, 7, 6, 9, 10, 9, 10, 9, 8, 6, 7, 6, 9, 10, 9, 10, 6, 7, 6, 9, 10, 9, 10, 6, 7, 6, 9, 10, 9, 10]}
end categories.products
|
552fd58d5742e261b048e2868a307db6407ae2c5 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/list/infix.lean | 89bb5ba243d146177ee69dadc820b7dc3ab70f12 | [
"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 | 21,933 | 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.list.basic
/-!
# Prefixes, subfixes, infixes
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file proves properties about
* `list.prefix`: `l₁` is a prefix of `l₂` if `l₂` starts with `l₁`.
* `list.subfix`: `l₁` is a subfix of `l₂` if `l₂` ends with `l₁`.
* `list.infix`: `l₁` is an infix of `l₂` if `l₁` is a prefix of some subfix of `l₂`.
* `list.inits`: The list of prefixes of a list.
* `list.tails`: The list of prefixes of a list.
* `insert` on lists
All those (except `insert`) are defined in `data.list.defs`.
## Notation
`l₁ <+: l₂`: `l₁` is a prefix of `l₂`.
`l₁ <:+ l₂`: `l₁` is a subfix of `l₂`.
`l₁ <:+: l₂`: `l₁` is an infix of `l₂`.
-/
open nat
variables {α β : Type*}
namespace list
variables {l l₁ l₂ l₃ : list α} {a b : α} {m n : ℕ}
/-! ### prefix, suffix, infix -/
section fix
@[simp] lemma prefix_append (l₁ l₂ : list α) : l₁ <+: l₁ ++ l₂ := ⟨l₂, rfl⟩
@[simp] lemma suffix_append (l₁ l₂ : list α) : l₂ <:+ l₁ ++ l₂ := ⟨l₁, rfl⟩
lemma infix_append (l₁ l₂ l₃ : list α) : l₂ <:+: l₁ ++ l₂ ++ l₃ := ⟨l₁, l₃, rfl⟩
@[simp] lemma infix_append' (l₁ l₂ l₃ : list α) : l₂ <:+: l₁ ++ (l₂ ++ l₃) :=
by rw ← list.append_assoc; apply infix_append
lemma is_prefix.is_infix : l₁ <+: l₂ → l₁ <:+: l₂ := λ ⟨t, h⟩, ⟨[], t, h⟩
lemma is_suffix.is_infix : l₁ <:+ l₂ → l₁ <:+: l₂ := λ ⟨t, h⟩, ⟨t, [], by rw [h, append_nil]⟩
lemma nil_prefix (l : list α) : [] <+: l := ⟨l, rfl⟩
lemma nil_suffix (l : list α) : [] <:+ l := ⟨l, append_nil _⟩
lemma nil_infix (l : list α) : [] <:+: l := (nil_prefix _).is_infix
@[refl] lemma prefix_refl (l : list α) : l <+: l := ⟨[], append_nil _⟩
@[refl] lemma suffix_refl (l : list α) : l <:+ l := ⟨[], rfl⟩
@[refl] lemma infix_refl (l : list α) : l <:+: l := (prefix_refl l).is_infix
lemma prefix_rfl : l <+: l := prefix_refl _
lemma suffix_rfl : l <:+ l := suffix_refl _
lemma infix_rfl : l <:+: l := infix_refl _
@[simp] lemma suffix_cons (a : α) : ∀ l, l <:+ a :: l := suffix_append [a]
lemma prefix_concat (a : α) (l) : l <+: concat l a := by simp
lemma infix_cons : l₁ <:+: l₂ → l₁ <:+: a :: l₂ := λ ⟨L₁, L₂, h⟩, ⟨a :: L₁, L₂, h ▸ rfl⟩
lemma infix_concat : l₁ <:+: l₂ → l₁ <:+: concat l₂ a :=
λ ⟨L₁, L₂, h⟩, ⟨L₁, concat L₂ a, by simp_rw [←h, concat_eq_append, append_assoc]⟩
@[trans] lemma is_prefix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <+: l₂ → l₂ <+: l₃ → l₁ <+: l₃
| l ._ ._ ⟨r₁, rfl⟩ ⟨r₂, rfl⟩ := ⟨r₁ ++ r₂, (append_assoc _ _ _).symm⟩
@[trans] lemma is_suffix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+ l₂ → l₂ <:+ l₃ → l₁ <:+ l₃
| l ._ ._ ⟨l₁, rfl⟩ ⟨l₂, rfl⟩ := ⟨l₂ ++ l₁, append_assoc _ _ _⟩
@[trans] lemma is_infix.trans : ∀ {l₁ l₂ l₃ : list α}, l₁ <:+: l₂ → l₂ <:+: l₃ → l₁ <:+: l₃
| l ._ ._ ⟨l₁, r₁, rfl⟩ ⟨l₂, r₂, rfl⟩ := ⟨l₂ ++ l₁, r₁ ++ r₂, by simp only [append_assoc]⟩
protected lemma is_infix.sublist : l₁ <:+: l₂ → l₁ <+ l₂ :=
λ ⟨s, t, h⟩, by { rw [← h], exact (sublist_append_right _ _).trans (sublist_append_left _ _) }
protected lemma is_infix.subset (hl : l₁ <:+: l₂) : l₁ ⊆ l₂ :=
hl.sublist.subset
protected lemma is_prefix.sublist (h : l₁ <+: l₂) : l₁ <+ l₂ :=
h.is_infix.sublist
protected lemma is_prefix.subset (hl : l₁ <+: l₂) : l₁ ⊆ l₂ :=
hl.sublist.subset
protected lemma is_suffix.sublist (h : l₁ <:+ l₂) : l₁ <+ l₂ :=
h.is_infix.sublist
protected lemma is_suffix.subset (hl : l₁ <:+ l₂) : l₁ ⊆ l₂ :=
hl.sublist.subset
@[simp] lemma reverse_suffix : reverse l₁ <:+ reverse l₂ ↔ l₁ <+: l₂ :=
⟨λ ⟨r, e⟩, ⟨reverse r,
by rw [← reverse_reverse l₁, ← reverse_append, e, reverse_reverse]⟩,
λ ⟨r, e⟩, ⟨reverse r, by rw [← reverse_append, e]⟩⟩
@[simp] lemma reverse_prefix : reverse l₁ <+: reverse l₂ ↔ l₁ <:+ l₂ :=
by rw ← reverse_suffix; simp only [reverse_reverse]
@[simp] lemma reverse_infix : reverse l₁ <:+: reverse l₂ ↔ l₁ <:+: l₂ :=
⟨λ ⟨s, t, e⟩, ⟨reverse t, reverse s,
by rw [← reverse_reverse l₁, append_assoc,
← reverse_append, ← reverse_append, e, reverse_reverse]⟩,
λ ⟨s, t, e⟩, ⟨reverse t, reverse s,
by rw [append_assoc, ← reverse_append, ← reverse_append, e]⟩⟩
alias reverse_prefix ↔ _ is_suffix.reverse
alias reverse_suffix ↔ _ is_prefix.reverse
alias reverse_infix ↔ _ is_infix.reverse
lemma is_infix.length_le (h : l₁ <:+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le
lemma is_prefix.length_le (h : l₁ <+: l₂) : l₁.length ≤ l₂.length := h.sublist.length_le
lemma is_suffix.length_le (h : l₁ <:+ l₂) : l₁.length ≤ l₂.length := h.sublist.length_le
lemma eq_nil_of_infix_nil (h : l <:+: []) : l = [] := eq_nil_of_sublist_nil h.sublist
@[simp] lemma infix_nil_iff : l <:+: [] ↔ l = [] :=
⟨λ h, eq_nil_of_sublist_nil h.sublist, λ h, h ▸ infix_rfl⟩
alias infix_nil_iff ↔ eq_nil_of_infix_nil _
@[simp] lemma prefix_nil_iff : l <+: [] ↔ l = [] :=
⟨λ h, eq_nil_of_infix_nil h.is_infix, λ h, h ▸ prefix_rfl⟩
@[simp] lemma suffix_nil_iff : l <:+ [] ↔ l = [] :=
⟨λ h, eq_nil_of_infix_nil h.is_infix, λ h, h ▸ suffix_rfl⟩
alias prefix_nil_iff ↔ eq_nil_of_prefix_nil _
alias suffix_nil_iff ↔ eq_nil_of_suffix_nil _
lemma infix_iff_prefix_suffix (l₁ l₂ : list α) : l₁ <:+: l₂ ↔ ∃ t, l₁ <+: t ∧ t <:+ l₂ :=
⟨λ ⟨s, t, e⟩, ⟨l₁ ++ t, ⟨_, rfl⟩, by rw [← e, append_assoc]; exact ⟨_, rfl⟩⟩,
λ ⟨._, ⟨t, rfl⟩, s, e⟩, ⟨s, t, by rw append_assoc; exact e⟩⟩
lemma eq_of_infix_of_length_eq (h : l₁ <:+: l₂) : l₁.length = l₂.length → l₁ = l₂ :=
h.sublist.eq_of_length
lemma eq_of_prefix_of_length_eq (h : l₁ <+: l₂) : l₁.length = l₂.length → l₁ = l₂ :=
h.sublist.eq_of_length
lemma eq_of_suffix_of_length_eq (h : l₁ <:+ l₂) : l₁.length = l₂.length → l₁ = l₂ :=
h.sublist.eq_of_length
lemma prefix_of_prefix_length_le : ∀ {l₁ l₂ l₃ : list α},
l₁ <+: l₃ → l₂ <+: l₃ → length l₁ ≤ length l₂ → l₁ <+: l₂
| [] l₂ l₃ h₁ h₂ _ := nil_prefix _
| (a :: l₁) (b :: l₂) _ ⟨r₁, rfl⟩ ⟨r₂, e⟩ ll := begin
injection e with _ e', subst b,
rcases prefix_of_prefix_length_le ⟨_, rfl⟩ ⟨_, e'⟩
(le_of_succ_le_succ ll) with ⟨r₃, rfl⟩,
exact ⟨r₃, rfl⟩
end
lemma prefix_or_prefix_of_prefix (h₁ : l₁ <+: l₃) (h₂ : l₂ <+: l₃) : l₁ <+: l₂ ∨ l₂ <+: l₁ :=
(le_total (length l₁) (length l₂)).imp
(prefix_of_prefix_length_le h₁ h₂)
(prefix_of_prefix_length_le h₂ h₁)
lemma suffix_of_suffix_length_le (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) (ll : length l₁ ≤ length l₂) :
l₁ <:+ l₂ :=
reverse_prefix.1 $ prefix_of_prefix_length_le
(reverse_prefix.2 h₁) (reverse_prefix.2 h₂) (by simp [ll])
lemma suffix_or_suffix_of_suffix (h₁ : l₁ <:+ l₃) (h₂ : l₂ <:+ l₃) : l₁ <:+ l₂ ∨ l₂ <:+ l₁ :=
(prefix_or_prefix_of_prefix (reverse_prefix.2 h₁) (reverse_prefix.2 h₂)).imp
reverse_prefix.1 reverse_prefix.1
lemma suffix_cons_iff : l₁ <:+ a :: l₂ ↔ l₁ = a :: l₂ ∨ l₁ <:+ l₂ :=
begin
split,
{ rintro ⟨⟨hd, tl⟩, hl₃⟩,
{ exact or.inl hl₃ },
{ simp only [cons_append] at hl₃,
exact or.inr ⟨_, hl₃.2⟩ } },
{ rintro (rfl | hl₁),
{ exact (a :: l₂).suffix_refl },
{ exact hl₁.trans (l₂.suffix_cons _) } }
end
lemma infix_cons_iff : l₁ <:+: a :: l₂ ↔ l₁ <+: a :: l₂ ∨ l₁ <:+: l₂ :=
begin
split,
{ rintro ⟨⟨hd, tl⟩, t, hl₃⟩,
{ exact or.inl ⟨t, hl₃⟩ },
{ simp only [cons_append] at hl₃,
exact or.inr ⟨_, t, hl₃.2⟩ } },
{ rintro (h | hl₁),
{ exact h.is_infix },
{ exact infix_cons hl₁ } }
end
lemma infix_of_mem_join : ∀ {L : list (list α)}, l ∈ L → l <:+: join L
| (_ :: L) (or.inl rfl) := infix_append [] _ _
| (l' :: L) (or.inr h) := is_infix.trans (infix_of_mem_join h) $ (suffix_append _ _).is_infix
lemma prefix_append_right_inj (l) : l ++ l₁ <+: l ++ l₂ ↔ l₁ <+: l₂ :=
exists_congr $ λ r, by rw [append_assoc, append_right_inj]
lemma prefix_cons_inj (a) : a :: l₁ <+: a :: l₂ ↔ l₁ <+: l₂ := prefix_append_right_inj [a]
lemma take_prefix (n) (l : list α) : take n l <+: l := ⟨_, take_append_drop _ _⟩
lemma drop_suffix (n) (l : list α) : drop n l <:+ l := ⟨_, take_append_drop _ _⟩
lemma take_sublist (n) (l : list α) : take n l <+ l := (take_prefix n l).sublist
lemma drop_sublist (n) (l : list α) : drop n l <+ l := (drop_suffix n l).sublist
lemma take_subset (n) (l : list α) : take n l ⊆ l := (take_sublist n l).subset
lemma drop_subset (n) (l : list α) : drop n l ⊆ l := (drop_sublist n l).subset
lemma mem_of_mem_take (h : a ∈ l.take n) : a ∈ l := take_subset n l h
lemma mem_of_mem_drop (h : a ∈ l.drop n) : a ∈ l := drop_subset n l h
lemma slice_sublist (n m : ℕ) (l : list α) : l.slice n m <+ l :=
begin
rw list.slice_eq,
conv_rhs {rw ←list.take_append_drop n l},
rw [list.append_sublist_append_left, add_comm, list.drop_add],
exact list.drop_sublist _ _,
end
lemma slice_subset (n m : ℕ) (l : list α) : l.slice n m ⊆ l := (slice_sublist n m l).subset
lemma mem_of_mem_slice {n m : ℕ} {l : list α} {a : α} (h : a ∈ l.slice n m) : a ∈ l :=
slice_subset n m l h
lemma take_while_prefix (p : α → Prop) [decidable_pred p] : l.take_while p <+: l :=
⟨l.drop_while p, take_while_append_drop p l⟩
lemma drop_while_suffix (p : α → Prop) [decidable_pred p] : l.drop_while p <:+ l :=
⟨l.take_while p, take_while_append_drop p l⟩
lemma init_prefix : ∀ (l : list α), l.init <+: l
| [] := ⟨nil, by rw [init, list.append_nil]⟩
| (a :: l) := ⟨_, init_append_last (cons_ne_nil a l)⟩
lemma tail_suffix (l : list α) : tail l <:+ l := by rw ← drop_one; apply drop_suffix
lemma init_sublist (l : list α) : l.init <+ l := (init_prefix l).sublist
lemma tail_sublist (l : list α) : l.tail <+ l := (tail_suffix l).sublist
lemma init_subset (l : list α) : l.init ⊆ l := (init_sublist l).subset
lemma tail_subset (l : list α) : tail l ⊆ l := (tail_sublist l).subset
lemma mem_of_mem_init (h : a ∈ l.init) : a ∈ l := init_subset l h
lemma mem_of_mem_tail (h : a ∈ l.tail) : a ∈ l := tail_subset l h
lemma prefix_iff_eq_append : l₁ <+: l₂ ↔ l₁ ++ drop (length l₁) l₂ = l₂ :=
⟨by rintros ⟨r, rfl⟩; rw drop_left, λ e, ⟨_, e⟩⟩
lemma suffix_iff_eq_append : l₁ <:+ l₂ ↔ take (length l₂ - length l₁) l₂ ++ l₁ = l₂ :=
⟨by rintros ⟨r, rfl⟩; simp only [length_append, add_tsub_cancel_right, take_left], λ e, ⟨_, e⟩⟩
lemma prefix_iff_eq_take : l₁ <+: l₂ ↔ l₁ = take (length l₁) l₂ :=
⟨λ h, append_right_cancel $
(prefix_iff_eq_append.1 h).trans (take_append_drop _ _).symm,
λ e, e.symm ▸ take_prefix _ _⟩
lemma suffix_iff_eq_drop : l₁ <:+ l₂ ↔ l₁ = drop (length l₂ - length l₁) l₂ :=
⟨λ h, append_left_cancel $
(suffix_iff_eq_append.1 h).trans (take_append_drop _ _).symm,
λ e, e.symm ▸ drop_suffix _ _⟩
instance decidable_prefix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <+: l₂)
| [] l₂ := is_true ⟨l₂, rfl⟩
| (a :: l₁) [] := is_false $ λ ⟨t, te⟩, list.no_confusion te
| (a :: l₁) (b :: l₂) :=
if h : a = b then
decidable_of_decidable_of_iff (decidable_prefix l₁ l₂) (by rw [← h, prefix_cons_inj])
else
is_false $ λ ⟨t, te⟩, h $ by injection te
-- Alternatively, use mem_tails
instance decidable_suffix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+ l₂)
| [] l₂ := is_true ⟨l₂, append_nil _⟩
| (a :: l₁) [] := is_false $ mt (sublist.length_le ∘ is_suffix.sublist) dec_trivial
| l₁ (b :: l₂) := decidable_of_decidable_of_iff (@or.decidable _ _
_ (l₁.decidable_suffix l₂)) suffix_cons_iff.symm
instance decidable_infix [decidable_eq α] : ∀ (l₁ l₂ : list α), decidable (l₁ <:+: l₂)
| [] l₂ := is_true ⟨[], l₂, rfl⟩
| (a :: l₁) [] := is_false $ λ ⟨s, t, te⟩, by simp at te; exact te
| l₁ (b :: l₂) := decidable_of_decidable_of_iff (@or.decidable _ _
(l₁.decidable_prefix (b :: l₂)) (l₁.decidable_infix l₂)) infix_cons_iff.symm
lemma prefix_take_le_iff {L : list (list (option α))} (hm : m < L.length) :
L.take m <+: L.take n ↔ m ≤ n :=
begin
simp only [prefix_iff_eq_take, length_take],
induction m with m IH generalizing L n,
{ simp only [min_eq_left, eq_self_iff_true, nat.zero_le, take] },
cases L with l ls,
{ exact (not_lt_bot hm).elim },
cases n,
{ refine iff_of_false _ (zero_lt_succ _).not_le,
rw [take_zero, take_nil],
simp only [take],
exact not_false },
{ simp only [length] at hm,
specialize @IH ls n (nat.lt_of_succ_lt_succ hm),
simp only [le_of_lt (nat.lt_of_succ_lt_succ hm), min_eq_left] at IH,
simp only [le_of_lt hm, IH, true_and, min_eq_left, eq_self_iff_true, length, take],
exact ⟨nat.succ_le_succ, nat.le_of_succ_le_succ⟩ }
end
lemma cons_prefix_iff : a :: l₁ <+: b :: l₂ ↔ a = b ∧ l₁ <+: l₂ :=
begin
split,
{ rintro ⟨L, hL⟩,
simp only [cons_append] at hL,
exact ⟨hL.left, ⟨L, hL.right⟩⟩ },
{ rintro ⟨rfl, h⟩,
rwa [prefix_cons_inj] }
end
lemma is_prefix.map (h : l₁ <+: l₂) (f : α → β) : l₁.map f <+: l₂.map f :=
begin
induction l₁ with hd tl hl generalizing l₂,
{ simp only [nil_prefix, map_nil] },
{ cases l₂ with hd₂ tl₂,
{ simpa only using eq_nil_of_prefix_nil h },
{ rw cons_prefix_iff at h,
simp only [h, prefix_cons_inj, hl, map] } }
end
lemma is_prefix.filter_map (h : l₁ <+: l₂) (f : α → option β) :
l₁.filter_map f <+: l₂.filter_map f :=
begin
induction l₁ with hd₁ tl₁ hl generalizing l₂,
{ simp only [nil_prefix, filter_map_nil] },
{ cases l₂ with hd₂ tl₂,
{ simpa only using eq_nil_of_prefix_nil h },
{ rw cons_prefix_iff at h,
rw [←@singleton_append _ hd₁ _, ←@singleton_append _ hd₂ _, filter_map_append,
filter_map_append, h.left, prefix_append_right_inj],
exact hl h.right } }
end
lemma is_prefix.reduce_option {l₁ l₂ : list (option α)} (h : l₁ <+: l₂) :
l₁.reduce_option <+: l₂.reduce_option :=
h.filter_map id
lemma is_prefix.filter (p : α → Prop) [decidable_pred p] ⦃l₁ l₂ : list α⦄ (h : l₁ <+: l₂) :
l₁.filter p <+: l₂.filter p :=
begin
obtain ⟨xs, rfl⟩ := h,
rw filter_append,
exact prefix_append _ _
end
lemma is_suffix.filter (p : α → Prop) [decidable_pred p] ⦃l₁ l₂ : list α⦄ (h : l₁ <:+ l₂) :
l₁.filter p <:+ l₂.filter p :=
begin
obtain ⟨xs, rfl⟩ := h,
rw filter_append,
exact suffix_append _ _
end
lemma is_infix.filter (p : α → Prop) [decidable_pred p] ⦃l₁ l₂ : list α⦄ (h : l₁ <:+: l₂) :
l₁.filter p <:+: l₂.filter p :=
begin
obtain ⟨xs, ys, rfl⟩ := h,
rw [filter_append, filter_append],
exact infix_append _ _ _
end
instance : is_partial_order (list α) (<+:) :=
{ refl := prefix_refl,
trans := λ _ _ _, is_prefix.trans,
antisymm := λ _ _ h₁ h₂, eq_of_prefix_of_length_eq h₁ $ h₁.length_le.antisymm h₂.length_le }
instance : is_partial_order (list α) (<:+) :=
{ refl := suffix_refl,
trans := λ _ _ _, is_suffix.trans,
antisymm := λ _ _ h₁ h₂, eq_of_suffix_of_length_eq h₁ $ h₁.length_le.antisymm h₂.length_le }
instance : is_partial_order (list α) (<:+:) :=
{ refl := infix_refl,
trans := λ _ _ _, is_infix.trans,
antisymm := λ _ _ h₁ h₂, eq_of_infix_of_length_eq h₁ $ h₁.length_le.antisymm h₂.length_le }
end fix
section inits_tails
@[simp] lemma mem_inits : ∀ (s t : list α), s ∈ inits t ↔ s <+: t
| s [] := suffices s = nil ↔ s <+: nil, by simpa only [inits, mem_singleton],
⟨λ h, h.symm ▸ prefix_refl [], eq_nil_of_prefix_nil⟩
| s (a :: t) :=
suffices (s = nil ∨ ∃ l ∈ inits t, a :: l = s) ↔ s <+: a :: t, by simpa,
⟨λ o, match s, o with
| ._, or.inl rfl := ⟨_, rfl⟩
| s, or.inr ⟨r, hr, hs⟩ := let ⟨s, ht⟩ := (mem_inits _ _).1 hr in
by rw [← hs, ← ht]; exact ⟨s, rfl⟩
end, λ mi, match s, mi with
| [], ⟨._, rfl⟩ := or.inl rfl
| (b :: s), ⟨r, hr⟩ := list.no_confusion hr $ λ ba (st : s++r = t), or.inr $
by rw ba; exact ⟨_, (mem_inits _ _).2 ⟨_, st⟩, rfl⟩
end⟩
@[simp] lemma mem_tails : ∀ (s t : list α), s ∈ tails t ↔ s <:+ t
| s [] := by simp only [tails, mem_singleton];
exact ⟨λ h, by rw h; exact suffix_refl [], eq_nil_of_suffix_nil⟩
| s (a :: t) := by simp only [tails, mem_cons_iff, mem_tails s t];
exact show s = a :: t ∨ s <:+ t ↔ s <:+ a :: t, from
⟨λ o, match s, t, o with
| ._, t, or.inl rfl := suffix_rfl
| s, ._, or.inr ⟨l, rfl⟩ := ⟨a :: l, rfl⟩
end, λ e, match s, t, e with
| ._, t, ⟨[], rfl⟩ := or.inl rfl
| s, t, ⟨b :: l, he⟩ := list.no_confusion he (λ ab lt, or.inr ⟨l, lt⟩)
end⟩
lemma inits_cons (a : α) (l : list α) : inits (a :: l) = [] :: l.inits.map (λ t, a :: t) := by simp
lemma tails_cons (a : α) (l : list α) : tails (a :: l) = (a :: l) :: l.tails := by simp
@[simp]
lemma inits_append : ∀ (s t : list α), inits (s ++ t) = s.inits ++ t.inits.tail.map (λ l, s ++ l)
| [] [] := by simp
| [] (a :: t) := by simp
| (a :: s) t := by simp [inits_append s t]
@[simp]
lemma tails_append : ∀ (s t : list α), tails (s ++ t) = s.tails.map (λ l, l ++ t) ++ t.tails.tail
| [] [] := by simp
| [] (a :: t) := by simp
| (a :: s) t := by simp [tails_append s t]
-- the lemma names `inits_eq_tails` and `tails_eq_inits` are like `sublists_eq_sublists'`
lemma inits_eq_tails : ∀ (l : list α), l.inits = (reverse $ map reverse $ tails $ reverse l)
| [] := by simp
| (a :: l) := by simp [inits_eq_tails l, map_eq_map_iff]
lemma tails_eq_inits : ∀ (l : list α), l.tails = (reverse $ map reverse $ inits $ reverse l)
| [] := by simp
| (a :: l) := by simp [tails_eq_inits l, append_left_inj]
lemma inits_reverse (l : list α) : inits (reverse l) = reverse (map reverse l.tails) :=
by { rw tails_eq_inits l, simp [reverse_involutive.comp_self] }
lemma tails_reverse (l : list α) : tails (reverse l) = reverse (map reverse l.inits) :=
by { rw inits_eq_tails l, simp [reverse_involutive.comp_self] }
lemma map_reverse_inits (l : list α) : map reverse l.inits = (reverse $ tails $ reverse l) :=
by { rw inits_eq_tails l, simp [reverse_involutive.comp_self] }
lemma map_reverse_tails (l : list α) : map reverse l.tails = (reverse $ inits $ reverse l) :=
by { rw tails_eq_inits l, simp [reverse_involutive.comp_self] }
@[simp] lemma length_tails (l : list α) : length (tails l) = length l + 1 :=
begin
induction l with x l IH,
{ simp },
{ simpa using IH }
end
@[simp] lemma length_inits (l : list α) : length (inits l) = length l + 1 :=
by simp [inits_eq_tails]
@[simp] lemma nth_le_tails (l : list α) (n : ℕ) (hn : n < length (tails l)) :
nth_le (tails l) n hn = l.drop n :=
begin
induction l with x l IH generalizing n,
{ simp },
{ cases n,
{ simp },
{ simpa using IH n _ } }
end
@[simp] lemma nth_le_inits (l : list α) (n : ℕ) (hn : n < length (inits l)) :
nth_le (inits l) n hn = l.take n :=
begin
induction l with x l IH generalizing n,
{ simp },
{ cases n,
{ simp },
{ simpa using IH n _ } }
end
end inits_tails
/-! ### insert -/
section insert
variable [decidable_eq α]
@[simp] lemma insert_nil (a : α) : insert a nil = [a] := rfl
lemma insert.def (a : α) (l : list α) : insert a l = if a ∈ l then l else a :: l := rfl
@[simp, priority 980]
lemma insert_of_mem (h : a ∈ l) : insert a l = l := by simp only [insert.def, if_pos h]
@[simp, priority 970]
lemma insert_of_not_mem (h : a ∉ l) : insert a l = a :: l :=
by simp only [insert.def, if_neg h]; split; refl
@[simp] lemma mem_insert_iff : a ∈ insert b l ↔ a = b ∨ a ∈ l :=
begin
by_cases h' : b ∈ l,
{ simp only [insert_of_mem h'],
apply (or_iff_right_of_imp _).symm,
exact λ e, e.symm ▸ h' },
{ simp only [insert_of_not_mem h', mem_cons_iff] }
end
@[simp] lemma suffix_insert (a : α) (l : list α) : l <:+ insert a l :=
by by_cases a ∈ l; [simp only [insert_of_mem h], simp only [insert_of_not_mem h, suffix_cons]]
lemma infix_insert (a : α) (l : list α) : l <:+: insert a l := (suffix_insert a l).is_infix
lemma sublist_insert (a : α) (l : list α) : l <+ l.insert a := (suffix_insert a l).sublist
lemma subset_insert (a : α) (l : list α) : l ⊆ l.insert a := (sublist_insert a l).subset
@[simp] lemma mem_insert_self (a : α) (l : list α) : a ∈ l.insert a :=
mem_insert_iff.2 $ or.inl rfl
lemma mem_insert_of_mem (h : a ∈ l) : a ∈ insert b l := mem_insert_iff.2 (or.inr h)
lemma eq_or_mem_of_mem_insert (h : a ∈ insert b l) : a = b ∨ a ∈ l := mem_insert_iff.1 h
@[simp] lemma length_insert_of_mem (h : a ∈ l) : (insert a l).length = l.length :=
congr_arg _ $ insert_of_mem h
@[simp] lemma length_insert_of_not_mem (h : a ∉ l) : (insert a l).length = l.length + 1 :=
congr_arg _ $ insert_of_not_mem h
end insert
lemma mem_of_mem_suffix (hx : a ∈ l₁) (hl : l₁ <:+ l₂) : a ∈ l₂ :=
hl.subset hx
end list
|
e721423f0230be14bce6d50421d39484b9641203 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/filter/germ.lean | c12241e63ed32d698d48679c047760370897a2e7 | [] | 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 | 25,598 | 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, Abhimanyu Pallavi Sudhir
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.filter.basic
import Mathlib.algebra.module.pi
import Mathlib.PostPort
universes u_1 u_2 u_3 u_4 u_5 u_6 u_7
namespace Mathlib
/-!
# Germ of a function at a filter
The germ of a function `f : α → β` at a filter `l : filter α` is the equivalence class of `f`
with respect to the equivalence relation `eventually_eq l`: `f ≈ g` means `∀ᶠ x in l, f x = g x`.
## Main definitions
We define
* `germ l β` to be the space of germs of functions `α → β` at a filter `l : filter α`;
* coercion from `α → β` to `germ l β`: `(f : germ l β)` is the germ of `f : α → β`
at `l : filter α`; this coercion is declared as `has_coe_t`, so it does not require an explicit
up arrow `↑`;
* coercion from `β` to `germ l β`: `(↑c : germ l β)` is the germ of the constant function
`λ x:α, c` at a filter `l`; this coercion is declared as `has_lift_t`, so it requires an explicit
up arrow `↑`, see [TPiL][TPiL_coe] for details.
* `map (F : β → γ) (f : germ l β)` to be the composition of a function `F` and a germ `f`;
* `map₂ (F : β → γ → δ) (f : germ l β) (g : germ l γ)` to be the germ of `λ x, F (f x) (g x)`
at `l`;
* `f.tendsto lb`: we say that a germ `f : germ l β` tends to a filter `lb` if its representatives
tend to `lb` along `l`;
* `f.comp_tendsto g hg` and `f.comp_tendsto' g hg`: given `f : germ l β` and a function
`g : γ → α` (resp., a germ `g : germ lc α`), if `g` tends to `l` along `lc`, then the composition
`f ∘ g` is a well-defined germ at `lc`;
* `germ.lift_pred`, `germ.lift_rel`: lift a predicate or a relation to the space of germs:
`(f : germ l β).lift_pred p` means `∀ᶠ x in l, p (f x)`, and similarly for a relation.
[TPiL_coe]: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html#coercions-using-type-classes
We also define `map (F : β → γ) : germ l β → germ l γ` sending each germ `f` to `F ∘ f`.
For each of the following structures we prove that if `β` has this structure, then so does
`germ l β`:
* one-operation algebraic structures up to `comm_group`;
* `mul_zero_class`, `distrib`, `semiring`, `comm_semiring`, `ring`, `comm_ring`;
* `mul_action`, `distrib_mul_action`, `semimodule`;
* `preorder`, `partial_order`, and `lattice` structures up to `bounded_lattice`;
* `ordered_cancel_comm_monoid` and `ordered_cancel_add_comm_monoid`.
## Tags
filter, germ
-/
namespace filter
theorem const_eventually_eq' {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : filter.eventually (fun (x : α) => a = b) l ↔ a = b :=
eventually_const
theorem const_eventually_eq {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : (eventually_eq l (fun (_x : α) => a) fun (_x : α) => b) ↔ a = b :=
const_eventually_eq'
theorem eventually_eq.comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {f : α → β} {f' : α → β} (H : eventually_eq l f f') {g : γ → α} {lc : filter γ} (hg : tendsto g lc l) : eventually_eq lc (f ∘ g) (f' ∘ g) :=
tendsto.eventually hg H
/-- Setoid used to define the space of germs. -/
def germ_setoid {α : Type u_1} (l : filter α) (β : Type u_2) : setoid (α → β) :=
setoid.mk (eventually_eq l) sorry
/-- The space of germs of functions `α → β` at a filter `l`. -/
def germ {α : Type u_1} (l : filter α) (β : Type u_2) :=
quotient (germ_setoid l β)
namespace germ
protected instance has_coe_t {α : Type u_1} {β : Type u_2} {l : filter α} : has_coe_t (α → β) (germ l β) :=
has_coe_t.mk quotient.mk'
protected instance has_lift_t {α : Type u_1} {β : Type u_2} {l : filter α} : has_lift_t β (germ l β) :=
has_lift_t.mk fun (c : β) => ↑fun (x : α) => c
@[simp] theorem quot_mk_eq_coe {α : Type u_1} {β : Type u_2} (l : filter α) (f : α → β) : Quot.mk setoid.r f = ↑f :=
rfl
@[simp] theorem mk'_eq_coe {α : Type u_1} {β : Type u_2} (l : filter α) (f : α → β) : quotient.mk' f = ↑f :=
rfl
theorem induction_on {α : Type u_1} {β : Type u_2} {l : filter α} (f : germ l β) {p : germ l β → Prop} (h : ∀ (f : α → β), p ↑f) : p f :=
quotient.induction_on' f h
theorem induction_on₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) (g : germ l γ) {p : germ l β → germ l γ → Prop} (h : ∀ (f : α → β) (g : α → γ), p ↑f ↑g) : p f g :=
quotient.induction_on₂' f g h
theorem induction_on₃ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (f : germ l β) (g : germ l γ) (h : germ l δ) {p : germ l β → germ l γ → germ l δ → Prop} (H : ∀ (f : α → β) (g : α → γ) (h : α → δ), p ↑f ↑g ↑h) : p f g h :=
quotient.induction_on₃' f g h H
/-- Given a map `F : (α → β) → (γ → δ)` that sends functions eventually equal at `l` to functions
eventually equal at `lc`, returns a map from `germ l β` to `germ lc δ`. -/
def map' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} {lc : filter γ} (F : (α → β) → γ → δ) (hF : relator.lift_fun (eventually_eq l) (eventually_eq lc) F F) : germ l β → germ lc δ :=
quotient.map' F hF
/-- Given a germ `f : germ l β` and a function `F : (α → β) → γ` sending eventually equal functions
to the same value, returns the value `F` takes on functions having germ `f` at `l`. -/
def lift_on {α : Type u_1} {β : Type u_2} {l : filter α} {γ : Sort u_3} (f : germ l β) (F : (α → β) → γ) (hF : relator.lift_fun (eventually_eq l) Eq F F) : γ :=
quotient.lift_on' f F hF
@[simp] theorem map'_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} {lc : filter γ} (F : (α → β) → γ → δ) (hF : relator.lift_fun (eventually_eq l) (eventually_eq lc) F F) (f : α → β) : map' F hF ↑f = ↑(F f) :=
rfl
@[simp] theorem coe_eq {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} : ↑f = ↑g ↔ eventually_eq l f g :=
quotient.eq'
theorem Mathlib.filter.eventually_eq.germ_eq {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} : eventually_eq l f g → ↑f = ↑g :=
iff.mpr coe_eq
/-- Lift a function `β → γ` to a function `germ l β → germ l γ`. -/
def map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (op : β → γ) : germ l β → germ l γ :=
map' (function.comp op) sorry
@[simp] theorem map_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (op : β → γ) (f : α → β) : map op ↑f = ↑(op ∘ f) :=
rfl
@[simp] theorem map_id {α : Type u_1} {β : Type u_2} {l : filter α} : map id = id :=
funext fun (x : germ l β) => quot.induction_on x fun (f : α → β) => Eq.refl (map id (Quot.mk setoid.r f))
theorem map_map {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op₁ : γ → δ) (op₂ : β → γ) (f : germ l β) : map op₁ (map op₂ f) = map (op₁ ∘ op₂) f :=
induction_on f fun (f : α → β) => rfl
/-- Lift a binary function `β → γ → δ` to a function `germ l β → germ l γ → germ l δ`. -/
def map₂ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op : β → γ → δ) : germ l β → germ l γ → germ l δ :=
quotient.map₂' (fun (f : α → β) (g : α → γ) (x : α) => op (f x) (g x)) sorry
@[simp] theorem map₂_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} {l : filter α} (op : β → γ → δ) (f : α → β) (g : α → γ) : map₂ op ↑f ↑g = ↑fun (x : α) => op (f x) (g x) :=
rfl
/-- A germ at `l` of maps from `α` to `β` tends to `lb : filter β` if it is represented by a map
which tends to `lb` along `l`. -/
protected def tendsto {α : Type u_1} {β : Type u_2} {l : filter α} (f : germ l β) (lb : filter β) :=
lift_on f (fun (f : α → β) => tendsto f l lb) sorry
@[simp] theorem coe_tendsto {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {lb : filter β} : germ.tendsto (↑f) lb ↔ tendsto f l lb :=
iff.rfl
theorem Mathlib.filter.tendsto.germ_tendsto {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {lb : filter β} : tendsto f l lb → germ.tendsto (↑f) lb :=
iff.mpr coe_tendsto
/-- Given two germs `f : germ l β`, and `g : germ lc α`, where `l : filter α`, if `g` tends to `l`,
then the composition `f ∘ g` is well-defined as a germ at `lc`. -/
def comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} (g : germ lc α) (hg : germ.tendsto g l) : germ lc β :=
lift_on f (fun (f : α → β) => map f g) sorry
@[simp] theorem coe_comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : α → β) {lc : filter γ} {g : germ lc α} (hg : germ.tendsto g l) : comp_tendsto' (↑f) g hg = map f g :=
rfl
/-- Given a germ `f : germ l β` and a function `g : γ → α`, where `l : filter α`, if `g` tends
to `l` along `lc : filter γ`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/
def comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} (g : γ → α) (hg : tendsto g lc l) : germ lc β :=
comp_tendsto' f (↑g) (tendsto.germ_tendsto hg)
@[simp] theorem coe_comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : α → β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto (↑f) g hg = ↑(f ∘ g) :=
rfl
@[simp] theorem comp_tendsto'_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (f : germ l β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto' f (↑g) (tendsto.germ_tendsto hg) = comp_tendsto f g hg :=
rfl
@[simp] theorem const_inj {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {a : β} {b : β} : ↑a = ↑b ↔ a = b :=
iff.trans coe_eq const_eventually_eq
@[simp] theorem map_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} (l : filter α) (a : β) (f : β → γ) : map f ↑a = ↑(f a) :=
rfl
@[simp] theorem map₂_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} {δ : Type u_4} (l : filter α) (b : β) (c : γ) (f : β → γ → δ) : map₂ f ↑b ↑c = ↑(f b c) :=
rfl
@[simp] theorem const_comp_tendsto {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (b : β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : comp_tendsto (↑b) g hg = ↑b :=
rfl
@[simp] theorem const_comp_tendsto' {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (b : β) {lc : filter γ} {g : germ lc α} (hg : germ.tendsto g l) : comp_tendsto' (↑b) g hg = ↑b :=
induction_on g (fun (_x : γ → α) (_x_1 : germ.tendsto (↑_x) l) => rfl) hg
/-- Lift a predicate on `β` to `germ l β`. -/
def lift_pred {α : Type u_1} {β : Type u_2} {l : filter α} (p : β → Prop) (f : germ l β) :=
lift_on f (fun (f : α → β) => filter.eventually (fun (x : α) => p (f x)) l) sorry
@[simp] theorem lift_pred_coe {α : Type u_1} {β : Type u_2} {l : filter α} {p : β → Prop} {f : α → β} : lift_pred p ↑f ↔ filter.eventually (fun (x : α) => p (f x)) l :=
iff.rfl
theorem lift_pred_const {α : Type u_1} {β : Type u_2} {l : filter α} {p : β → Prop} {x : β} (hx : p x) : lift_pred p ↑x :=
eventually_of_forall fun (y : α) => hx
@[simp] theorem lift_pred_const_iff {α : Type u_1} {β : Type u_2} {l : filter α} [ne_bot l] {p : β → Prop} {x : β} : lift_pred p ↑x ↔ p x :=
eventually_const
/-- Lift a relation `r : β → γ → Prop` to `germ l β → germ l γ → Prop`. -/
def lift_rel {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} (r : β → γ → Prop) (f : germ l β) (g : germ l γ) :=
quotient.lift_on₂' f g (fun (f : α → β) (g : α → γ) => filter.eventually (fun (x : α) => r (f x) (g x)) l) sorry
@[simp] theorem lift_rel_coe {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {r : β → γ → Prop} {f : α → β} {g : α → γ} : lift_rel r ↑f ↑g ↔ filter.eventually (fun (x : α) => r (f x) (g x)) l :=
iff.rfl
theorem lift_rel_const {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} {r : β → γ → Prop} {x : β} {y : γ} (h : r x y) : lift_rel r ↑x ↑y :=
eventually_of_forall fun (_x : α) => h
@[simp] theorem lift_rel_const_iff {α : Type u_1} {β : Type u_2} {γ : Type u_3} {l : filter α} [ne_bot l] {r : β → γ → Prop} {x : β} {y : γ} : lift_rel r ↑x ↑y ↔ r x y :=
eventually_const
protected instance inhabited {α : Type u_1} {β : Type u_2} {l : filter α} [Inhabited β] : Inhabited (germ l β) :=
{ default := ↑Inhabited.default }
protected instance has_add {α : Type u_1} {l : filter α} {M : Type u_5} [Add M] : Add (germ l M) :=
{ add := map₂ Add.add }
@[simp] theorem coe_add {α : Type u_1} {l : filter α} {M : Type u_5} [Add M] (f : α → M) (g : α → M) : ↑(f + g) = ↑f + ↑g :=
rfl
protected instance has_one {α : Type u_1} {l : filter α} {M : Type u_5} [HasOne M] : HasOne (germ l M) :=
{ one := ↑1 }
@[simp] theorem coe_zero {α : Type u_1} {l : filter α} {M : Type u_5} [HasZero M] : ↑0 = 0 :=
rfl
protected instance add_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [add_semigroup M] : add_semigroup (germ l M) :=
add_semigroup.mk Add.add sorry
protected instance add_comm_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [add_comm_semigroup M] : add_comm_semigroup (germ l M) :=
add_comm_semigroup.mk Add.add sorry sorry
protected instance left_cancel_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [left_cancel_semigroup M] : left_cancel_semigroup (germ l M) :=
left_cancel_semigroup.mk Mul.mul sorry sorry
protected instance right_cancel_semigroup {α : Type u_1} {l : filter α} {M : Type u_5} [right_cancel_semigroup M] : right_cancel_semigroup (germ l M) :=
right_cancel_semigroup.mk Mul.mul sorry sorry
protected instance monoid {α : Type u_1} {l : filter α} {M : Type u_5} [monoid M] : monoid (germ l M) :=
monoid.mk Mul.mul sorry 1 sorry sorry
/-- coercion from functions to germs as a monoid homomorphism. -/
def coe_mul_hom {α : Type u_1} {M : Type u_5} [monoid M] (l : filter α) : (α → M) →* germ l M :=
monoid_hom.mk coe sorry sorry
/-- coercion from functions to germs as an additive monoid homomorphism. -/
@[simp] theorem coe_coe_mul_hom {α : Type u_1} {l : filter α} {M : Type u_5} [monoid M] : ⇑(coe_mul_hom l) = coe :=
rfl
protected instance add_comm_monoid {α : Type u_1} {l : filter α} {M : Type u_5} [add_comm_monoid M] : add_comm_monoid (germ l M) :=
add_comm_monoid.mk Add.add sorry 0 sorry sorry sorry
protected instance has_neg {α : Type u_1} {l : filter α} {G : Type u_6} [Neg G] : Neg (germ l G) :=
{ neg := map Neg.neg }
@[simp] theorem coe_neg {α : Type u_1} {l : filter α} {G : Type u_6} [Neg G] (f : α → G) : ↑(-f) = -↑f :=
rfl
protected instance has_div {α : Type u_1} {l : filter α} {M : Type u_5} [Div M] : Div (germ l M) :=
{ div := map₂ Div.div }
@[simp] theorem coe_div {α : Type u_1} {l : filter α} {M : Type u_5} [Div M] (f : α → M) (g : α → M) : ↑(f / g) = ↑f / ↑g :=
rfl
protected instance sub_neg_add_monoid {α : Type u_1} {l : filter α} {G : Type u_6} [sub_neg_monoid G] : sub_neg_monoid (germ l G) :=
sub_neg_monoid.mk add_monoid.add sorry add_monoid.zero sorry sorry Neg.neg Sub.sub
protected instance group {α : Type u_1} {l : filter α} {G : Type u_6} [group G] : group (germ l G) :=
group.mk Mul.mul sorry 1 sorry sorry div_inv_monoid.inv div_inv_monoid.div sorry
protected instance comm_group {α : Type u_1} {l : filter α} {G : Type u_6} [comm_group G] : comm_group (germ l G) :=
comm_group.mk Mul.mul sorry 1 sorry sorry has_inv.inv group.div sorry sorry
protected instance nontrivial {α : Type u_1} {l : filter α} {R : Type u_5} [nontrivial R] [ne_bot l] : nontrivial (germ l R) :=
sorry
protected instance mul_zero_class {α : Type u_1} {l : filter α} {R : Type u_5} [mul_zero_class R] : mul_zero_class (germ l R) :=
mul_zero_class.mk Mul.mul 0 sorry sorry
protected instance distrib {α : Type u_1} {l : filter α} {R : Type u_5} [distrib R] : distrib (germ l R) :=
distrib.mk Mul.mul Add.add sorry sorry
protected instance semiring {α : Type u_1} {l : filter α} {R : Type u_5} [semiring R] : semiring (germ l R) :=
semiring.mk add_comm_monoid.add sorry add_comm_monoid.zero sorry sorry sorry monoid.mul sorry monoid.one sorry sorry
sorry sorry sorry sorry
/-- Coercion `(α → R) → germ l R` as a `ring_hom`. -/
def coe_ring_hom {α : Type u_1} {R : Type u_5} [semiring R] (l : filter α) : (α → R) →+* germ l R :=
ring_hom.mk coe sorry sorry sorry sorry
@[simp] theorem coe_coe_ring_hom {α : Type u_1} {l : filter α} {R : Type u_5} [semiring R] : ⇑(coe_ring_hom l) = coe :=
rfl
protected instance ring {α : Type u_1} {l : filter α} {R : Type u_5} [ring R] : ring (germ l R) :=
ring.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub sorry sorry
monoid.mul sorry monoid.one sorry sorry sorry sorry
protected instance comm_semiring {α : Type u_1} {l : filter α} {R : Type u_5} [comm_semiring R] : comm_semiring (germ l R) :=
comm_semiring.mk semiring.add sorry semiring.zero sorry sorry sorry semiring.mul sorry semiring.one sorry sorry sorry
sorry sorry sorry sorry
protected instance comm_ring {α : Type u_1} {l : filter α} {R : Type u_5} [comm_ring R] : comm_ring (germ l R) :=
comm_ring.mk ring.add sorry ring.zero sorry sorry ring.neg ring.sub sorry sorry ring.mul sorry ring.one sorry sorry
sorry sorry sorry
protected instance has_scalar {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] : has_scalar M (germ l β) :=
has_scalar.mk fun (c : M) => map (has_scalar.smul c)
protected instance has_scalar' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] : has_scalar (germ l M) (germ l β) :=
has_scalar.mk (map₂ has_scalar.smul)
@[simp] theorem coe_smul {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] (c : M) (f : α → β) : ↑(c • f) = c • ↑f :=
rfl
@[simp] theorem coe_smul' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [has_scalar M β] (c : α → M) (f : α → β) : ↑(c • f) = ↑c • ↑f :=
rfl
protected instance mul_action {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [monoid M] [mul_action M β] : mul_action M (germ l β) :=
mul_action.mk sorry sorry
protected instance mul_action' {α : Type u_1} {β : Type u_2} {l : filter α} {M : Type u_5} [monoid M] [mul_action M β] : mul_action (germ l M) (germ l β) :=
mul_action.mk sorry sorry
protected instance distrib_mul_action {α : Type u_1} {l : filter α} {M : Type u_5} {N : Type u_6} [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action M (germ l N) :=
distrib_mul_action.mk sorry sorry
protected instance distrib_mul_action' {α : Type u_1} {l : filter α} {M : Type u_5} {N : Type u_6} [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action (germ l M) (germ l N) :=
distrib_mul_action.mk sorry sorry
protected instance semimodule {α : Type u_1} {l : filter α} {M : Type u_5} {R : Type u_7} [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule R (germ l M) :=
semimodule.mk sorry sorry
protected instance semimodule' {α : Type u_1} {l : filter α} {M : Type u_5} {R : Type u_7} [semiring R] [add_comm_monoid M] [semimodule R M] : semimodule (germ l R) (germ l M) :=
semimodule.mk sorry sorry
protected instance has_le {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] : HasLessEq (germ l β) :=
{ LessEq := lift_rel LessEq }
@[simp] theorem coe_le {α : Type u_1} {β : Type u_2} {l : filter α} {f : α → β} {g : α → β} [HasLessEq β] : ↑f ≤ ↑g ↔ eventually_le l f g :=
iff.rfl
theorem le_def {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] : LessEq = lift_rel LessEq :=
rfl
theorem const_le {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] {x : β} {y : β} (h : x ≤ y) : ↑x ≤ ↑y :=
lift_rel_const h
@[simp] theorem const_le_iff {α : Type u_1} {β : Type u_2} {l : filter α} [HasLessEq β] [ne_bot l] {x : β} {y : β} : ↑x ≤ ↑y ↔ x ≤ y :=
lift_rel_const_iff
protected instance preorder {α : Type u_1} {β : Type u_2} {l : filter α} [preorder β] : preorder (germ l β) :=
preorder.mk LessEq (fun (a b : germ l β) => a ≤ b ∧ ¬b ≤ a) sorry sorry
protected instance partial_order {α : Type u_1} {β : Type u_2} {l : filter α} [partial_order β] : partial_order (germ l β) :=
partial_order.mk LessEq preorder.lt sorry sorry sorry
protected instance has_bot {α : Type u_1} {β : Type u_2} {l : filter α} [has_bot β] : has_bot (germ l β) :=
has_bot.mk ↑⊥
@[simp] theorem const_bot {α : Type u_1} {β : Type u_2} {l : filter α} [has_bot β] : ↑⊥ = ⊥ :=
rfl
protected instance order_bot {α : Type u_1} {β : Type u_2} {l : filter α} [order_bot β] : order_bot (germ l β) :=
order_bot.mk ⊥ LessEq partial_order.lt sorry sorry sorry sorry
protected instance has_top {α : Type u_1} {β : Type u_2} {l : filter α} [has_top β] : has_top (germ l β) :=
has_top.mk ↑⊤
@[simp] theorem const_top {α : Type u_1} {β : Type u_2} {l : filter α} [has_top β] : ↑⊤ = ⊤ :=
rfl
protected instance order_top {α : Type u_1} {β : Type u_2} {l : filter α} [order_top β] : order_top (germ l β) :=
order_top.mk ⊤ LessEq partial_order.lt sorry sorry sorry sorry
protected instance has_sup {α : Type u_1} {β : Type u_2} {l : filter α} [has_sup β] : has_sup (germ l β) :=
has_sup.mk (map₂ has_sup.sup)
@[simp] theorem const_sup {α : Type u_1} {β : Type u_2} {l : filter α} [has_sup β] (a : β) (b : β) : ↑(a ⊔ b) = ↑a ⊔ ↑b :=
rfl
protected instance has_inf {α : Type u_1} {β : Type u_2} {l : filter α} [has_inf β] : has_inf (germ l β) :=
has_inf.mk (map₂ has_inf.inf)
@[simp] theorem const_inf {α : Type u_1} {β : Type u_2} {l : filter α} [has_inf β] (a : β) (b : β) : ↑(a ⊓ b) = ↑a ⊓ ↑b :=
rfl
protected instance semilattice_sup {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup β] : semilattice_sup (germ l β) :=
semilattice_sup.mk has_sup.sup partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry
protected instance semilattice_inf {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf β] : semilattice_inf (germ l β) :=
semilattice_inf.mk has_inf.inf partial_order.le partial_order.lt sorry sorry sorry sorry sorry sorry
protected instance semilattice_inf_bot {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf_bot β] : semilattice_inf_bot (germ l β) :=
semilattice_inf_bot.mk order_bot.bot semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry semilattice_inf.inf
sorry sorry sorry
protected instance semilattice_sup_bot {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup_bot β] : semilattice_sup_bot (germ l β) :=
semilattice_sup_bot.mk order_bot.bot semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry semilattice_sup.sup
sorry sorry sorry
protected instance semilattice_inf_top {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_inf_top β] : semilattice_inf_top (germ l β) :=
semilattice_inf_top.mk order_top.top semilattice_inf.le semilattice_inf.lt sorry sorry sorry sorry semilattice_inf.inf
sorry sorry sorry
protected instance semilattice_sup_top {α : Type u_1} {β : Type u_2} {l : filter α} [semilattice_sup_top β] : semilattice_sup_top (germ l β) :=
semilattice_sup_top.mk order_top.top semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry semilattice_sup.sup
sorry sorry sorry
protected instance lattice {α : Type u_1} {β : Type u_2} {l : filter α} [lattice β] : lattice (germ l β) :=
lattice.mk semilattice_sup.sup semilattice_sup.le semilattice_sup.lt sorry sorry sorry sorry sorry sorry
semilattice_inf.inf sorry sorry sorry
protected instance bounded_lattice {α : Type u_1} {β : Type u_2} {l : filter α} [bounded_lattice β] : bounded_lattice (germ l β) :=
bounded_lattice.mk lattice.sup lattice.le lattice.lt sorry sorry sorry sorry sorry sorry lattice.inf sorry sorry sorry
order_top.top sorry order_bot.bot sorry
protected instance ordered_cancel_add_comm_monoid {α : Type u_1} {β : Type u_2} {l : filter α} [ordered_cancel_add_comm_monoid β] : ordered_cancel_add_comm_monoid (germ l β) :=
ordered_cancel_add_comm_monoid.mk add_comm_monoid.add sorry sorry add_comm_monoid.zero sorry sorry sorry sorry
partial_order.le partial_order.lt sorry sorry sorry sorry sorry
protected instance ordered_add_comm_group {α : Type u_1} {β : Type u_2} {l : filter α} [ordered_add_comm_group β] : ordered_add_comm_group (germ l β) :=
ordered_add_comm_group.mk add_comm_group.add sorry add_comm_group.zero sorry sorry add_comm_group.neg add_comm_group.sub
sorry sorry partial_order.le partial_order.lt sorry sorry sorry sorry
|
780c932fa832949317e47697d64c7797307c2ef4 | f3849be5d845a1cb97680f0bbbe03b85518312f0 | /tests/lean/fail/run_command.lean | 17a3b3c35875096c65ffdf0ce66811958c3647c5 | [
"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 | 32 | lean | run_command tactic.fail "Error"
|
e4cd50c01cb11f8ed62b83b1475f1aa7b58071fa | f3a5af2927397cf346ec0e24312bfff077f00425 | /src/game/world3/level3.lean | 348823f21ab1cf750f480ac0b7100f43597271b2 | [
"Apache-2.0"
] | permissive | ImperialCollegeLondon/natural_number_game | 05c39e1586408cfb563d1a12e1085a90726ab655 | f29b6c2884299fc63fdfc81ae5d7daaa3219f9fd | refs/heads/master | 1,688,570,964,990 | 1,636,908,242,000 | 1,636,908,242,000 | 195,403,790 | 277 | 84 | Apache-2.0 | 1,694,547,955,000 | 1,562,328,792,000 | Lean | UTF-8 | Lean | false | false | 814 | lean | import game.world3.level2 -- hide
import mynat.mul -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 3: `one_mul`
These proofs from addition world might be useful here:
* `one_eq_succ_zero : 1 = succ(0)`
* `succ_eq_add_one a : succ(a) = a + 1`
We just proved `mul_one`, now let's prove `one_mul`.
Then we will have proved, in fancy terms,
that 1 is a "left and right identity"
for multiplication (just like we showed that
0 is a left and right identity for addition
with `add_zero` and `zero_add`).
-/
/- Lemma
For any natural number $m$, we have
$$ 1 \times m = m. $$
-/
lemma one_mul (m : mynat) : 1 * m = m :=
begin [nat_num_game]
induction m with d hd,
{
rw mul_zero,
refl,
},
{
rw mul_succ,
rw hd,
rw succ_eq_add_one,
refl,
}
end
end mynat -- hide
|
0f8bfb6b0d700195352fc5ba3a337f447877ffcd | 94e33a31faa76775069b071adea97e86e218a8ee | /src/geometry/manifold/charted_space.lean | 0379cfba3af20ec63f3081583991136845558c7e | [
"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 | 48,418 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import topology.local_homeomorph
/-!
# Charted spaces
A smooth manifold is a topological space `M` locally modelled on a euclidean space (or a euclidean
half-space for manifolds with boundaries, or an infinite dimensional vector space for more general
notions of manifolds), i.e., the manifold is covered by open subsets on which there are local
homeomorphisms (the charts) going to a model space `H`, and the changes of charts should be smooth
maps.
In this file, we introduce a general framework describing these notions, where the model space is an
arbitrary topological space. We avoid the word *manifold*, which should be reserved for the
situation where the model space is a (subset of a) vector space, and use the terminology
*charted space* instead.
If the changes of charts satisfy some additional property (for instance if they are smooth), then
`M` inherits additional structure (it makes sense to talk about smooth manifolds). There are
therefore two different ingredients in a charted space:
* the set of charts, which is data
* the fact that changes of charts belong to some group (in fact groupoid), which is additional Prop.
We separate these two parts in the definition: the charted space structure is just the set of
charts, and then the different smoothness requirements (smooth manifold, orientable manifold,
contact manifold, and so on) are additional properties of these charts. These properties are
formalized through the notion of structure groupoid, i.e., a set of local homeomorphisms stable
under composition and inverse, to which the change of coordinates should belong.
## Main definitions
* `structure_groupoid H` : a subset of local homeomorphisms of `H` stable under composition,
inverse and restriction (ex: local diffeos).
* `continuous_groupoid H` : the groupoid of all local homeomorphisms of `H`
* `charted_space H M` : charted space structure on `M` modelled on `H`, given by an atlas of
local homeomorphisms from `M` to `H` whose sources cover `M`. This is a type class.
* `has_groupoid M G` : when `G` is a structure groupoid on `H` and `M` is a charted space
modelled on `H`, require that all coordinate changes belong to `G`. This is a type class.
* `atlas H M` : when `M` is a charted space modelled on `H`, the atlas of this charted
space structure, i.e., the set of charts.
* `G.maximal_atlas M` : when `M` is a charted space modelled on `H` and admitting `G` as a
structure groupoid, one can consider all the local homeomorphisms from `M` to `H` such that
changing coordinate from any chart to them belongs to `G`. This is a larger atlas, called the
maximal atlas (for the groupoid `G`).
* `structomorph G M M'` : the type of diffeomorphisms between the charted spaces `M` and `M'` for
the groupoid `G`. We avoid the word diffeomorphism, keeping it for the smooth category.
As a basic example, we give the instance
`instance charted_space_model_space (H : Type*) [topological_space H] : charted_space H H`
saying that a topological space is a charted space over itself, with the identity as unique chart.
This charted space structure is compatible with any groupoid.
Additional useful definitions:
* `pregroupoid H` : a subset of local mas of `H` stable under composition and
restriction, but not inverse (ex: smooth maps)
* `groupoid_of_pregroupoid` : construct a groupoid from a pregroupoid, by requiring that a map and
its inverse both belong to the pregroupoid (ex: construct diffeos from smooth maps)
* `chart_at H x` is a preferred chart at `x : M` when `M` has a charted space structure modelled on
`H`.
* `G.compatible he he'` states that, for any two charts `e` and `e'` in the atlas, the composition
of `e.symm` and `e'` belongs to the groupoid `G` when `M` admits `G` as a structure groupoid.
* `G.compatible_of_mem_maximal_atlas he he'` states that, for any two charts `e` and `e'` in the
maximal atlas associated to the groupoid `G`, the composition of `e.symm` and `e'` belongs to the
`G` if `M` admits `G` as a structure groupoid.
* `charted_space_core.to_charted_space`: consider a space without a topology, but endowed with a set
of charts (which are local equivs) for which the change of coordinates are local homeos. Then
one can construct a topology on the space for which the charts become local homeos, defining
a genuine charted space structure.
## Implementation notes
The atlas in a charted space is *not* a maximal atlas in general: the notion of maximality depends
on the groupoid one considers, and changing groupoids changes the maximal atlas. With the current
formalization, it makes sense first to choose the atlas, and then to ask whether this precise atlas
defines a smooth manifold, an orientable manifold, and so on. A consequence is that structomorphisms
between `M` and `M'` do *not* induce a bijection between the atlases of `M` and `M'`: the
definition is only that, read in charts, the structomorphism locally belongs to the groupoid under
consideration. (This is equivalent to inducing a bijection between elements of the maximal atlas).
A consequence is that the invariance under structomorphisms of properties defined in terms of the
atlas is not obvious in general, and could require some work in theory (amounting to the fact
that these properties only depend on the maximal atlas, for instance). In practice, this does not
create any real difficulty.
We use the letter `H` for the model space thinking of the case of manifolds with boundary, where the
model space is a half space.
Manifolds are sometimes defined as topological spaces with an atlas of local diffeomorphisms, and
sometimes as spaces with an atlas from which a topology is deduced. We use the former approach:
otherwise, there would be an instance from manifolds to topological spaces, which means that any
instance search for topological spaces would try to find manifold structures involving a yet
unknown model space, leading to problems. However, we also introduce the latter approach,
through a structure `charted_space_core` making it possible to construct a topology out of a set of
local equivs with compatibility conditions (but we do not register it as an instance).
In the definition of a charted space, the model space is written as an explicit parameter as there
can be several model spaces for a given topological space. For instance, a complex manifold
(modelled over `ℂ^n`) will also be seen sometimes as a real manifold modelled over `ℝ^(2n)`.
## Notations
In the locale `manifold`, we denote the composition of local homeomorphisms with `≫ₕ`, and the
composition of local equivs with `≫`.
-/
noncomputable theory
open_locale classical topological_space
open filter
universes u
variables {H : Type u} {H' : Type*} {M : Type*} {M' : Type*} {M'' : Type*}
/- Notational shortcut for the composition of local homeomorphisms and local equivs, i.e.,
`local_homeomorph.trans` and `local_equiv.trans`.
Note that, as is usual for equivs, the composition is from left to right, hence the direction of
the arrow. -/
localized "infixr ` ≫ₕ `:100 := local_homeomorph.trans" in manifold
localized "infixr ` ≫ `:100 := local_equiv.trans" in manifold
/- `simp` looks for subsingleton instances at every call. This turns out to be very
inefficient, especially in `simp`-heavy parts of the library such as the manifold code.
Disable two such instances to speed up things.
NB: this is just a hack. TODO: fix `simp` properly. -/
localized "attribute [-instance] unique.subsingleton pi.subsingleton" in manifold
open set local_homeomorph
/-! ### Structure groupoids-/
section groupoid
/-! One could add to the definition of a structure groupoid the fact that the restriction of an
element of the groupoid to any open set still belongs to the groupoid.
(This is in Kobayashi-Nomizu.)
I am not sure I want this, for instance on `H × E` where `E` is a vector space, and the groupoid is
made of functions respecting the fibers and linear in the fibers (so that a charted space over this
groupoid is naturally a vector bundle) I prefer that the members of the groupoid are always
defined on sets of the form `s × E`. There is a typeclass `closed_under_restriction` for groupoids
which have the restriction property.
The only nontrivial requirement is locality: if a local homeomorphism belongs to the groupoid
around each point in its domain of definition, then it belongs to the groupoid. Without this
requirement, the composition of structomorphisms does not have to be a structomorphism. Note that
this implies that a local homeomorphism with empty source belongs to any structure groupoid, as
it trivially satisfies this condition.
There is also a technical point, related to the fact that a local homeomorphism is by definition a
global map which is a homeomorphism when restricted to its source subset (and its values outside
of the source are not relevant). Therefore, we also require that being a member of the groupoid only
depends on the values on the source.
We use primes in the structure names as we will reformulate them below (without primes) using a
`has_mem` instance, writing `e ∈ G` instead of `e ∈ G.members`.
-/
/-- A structure groupoid is a set of local homeomorphisms of a topological space stable under
composition and inverse. They appear in the definition of the smoothness class of a manifold. -/
structure structure_groupoid (H : Type u) [topological_space H] :=
(members : set (local_homeomorph H H))
(trans' : ∀e e' : local_homeomorph H H, e ∈ members → e' ∈ members → e ≫ₕ e' ∈ members)
(symm' : ∀e : local_homeomorph H H, e ∈ members → e.symm ∈ members)
(id_mem' : local_homeomorph.refl H ∈ members)
(locality' : ∀e : local_homeomorph H H, (∀x ∈ e.source, ∃s, is_open s ∧
x ∈ s ∧ e.restr s ∈ members) → e ∈ members)
(eq_on_source' : ∀ e e' : local_homeomorph H H, e ∈ members → e' ≈ e → e' ∈ members)
variable [topological_space H]
instance : has_mem (local_homeomorph H H) (structure_groupoid H) :=
⟨λ(e : local_homeomorph H H) (G : structure_groupoid H), e ∈ G.members⟩
lemma structure_groupoid.trans (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (he' : e' ∈ G) : e ≫ₕ e' ∈ G :=
G.trans' e e' he he'
lemma structure_groupoid.symm (G : structure_groupoid H) {e : local_homeomorph H H} (he : e ∈ G) :
e.symm ∈ G :=
G.symm' e he
lemma structure_groupoid.id_mem (G : structure_groupoid H) :
local_homeomorph.refl H ∈ G :=
G.id_mem'
lemma structure_groupoid.locality (G : structure_groupoid H) {e : local_homeomorph H H}
(h : ∀x ∈ e.source, ∃s, is_open s ∧ x ∈ s ∧ e.restr s ∈ G) :
e ∈ G :=
G.locality' e h
lemma structure_groupoid.eq_on_source (G : structure_groupoid H) {e e' : local_homeomorph H H}
(he : e ∈ G) (h : e' ≈ e) : e' ∈ G :=
G.eq_on_source' e e' he h
/-- Partial order on the set of groupoids, given by inclusion of the members of the groupoid -/
instance structure_groupoid.partial_order : partial_order (structure_groupoid H) :=
partial_order.lift structure_groupoid.members
(λa b h, by { cases a, cases b, dsimp at h, induction h, refl })
lemma structure_groupoid.le_iff {G₁ G₂ : structure_groupoid H} :
G₁ ≤ G₂ ↔ ∀ e, e ∈ G₁ → e ∈ G₂ :=
iff.rfl
/-- The trivial groupoid, containing only the identity (and maps with empty source, as this is
necessary from the definition) -/
def id_groupoid (H : Type u) [topological_space H] : structure_groupoid H :=
{ members := {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅},
trans' := λe e' he he', begin
cases he; simp at he he',
{ simpa only [he, refl_trans]},
{ have : (e ≫ₕ e').source ⊆ e.source := sep_subset _ _,
rw he at this,
have : (e ≫ₕ e') ∈ {e : local_homeomorph H H | e.source = ∅} := disjoint_iff.1 this,
exact (mem_union _ _ _).2 (or.inr this) },
end,
symm' := λe he, begin
cases (mem_union _ _ _).1 he with E E,
{ simp [mem_singleton_iff.mp E] },
{ right,
simpa only [e.to_local_equiv.image_source_eq_target.symm] with mfld_simps using E},
end,
id_mem' := mem_union_left _ rfl,
locality' := λe he, begin
cases e.source.eq_empty_or_nonempty with h h,
{ right, exact h },
{ left,
rcases h with ⟨x, hx⟩,
rcases he x hx with ⟨s, open_s, xs, hs⟩,
have x's : x ∈ (e.restr s).source,
{ rw [restr_source, open_s.interior_eq],
exact ⟨hx, xs⟩ },
cases hs,
{ replace hs : local_homeomorph.restr e s = local_homeomorph.refl H,
by simpa only using hs,
have : (e.restr s).source = univ, by { rw hs, simp },
change (e.to_local_equiv).source ∩ interior s = univ at this,
have : univ ⊆ interior s, by { rw ← this, exact inter_subset_right _ _ },
have : s = univ, by rwa [open_s.interior_eq, univ_subset_iff] at this,
simpa only [this, restr_univ] using hs },
{ exfalso,
rw mem_set_of_eq at hs,
rwa hs at x's } },
end,
eq_on_source' := λe e' he he'e, begin
cases he,
{ left,
have : e = e',
{ refine eq_of_eq_on_source_univ (setoid.symm he'e) _ _;
rw set.mem_singleton_iff.1 he ; refl },
rwa ← this },
{ right,
change (e.to_local_equiv).source = ∅ at he,
rwa [set.mem_set_of_eq, he'e.source_eq] }
end }
/-- Every structure groupoid contains the identity groupoid -/
instance : order_bot (structure_groupoid H) :=
{ bot := id_groupoid H,
bot_le := begin
assume u f hf,
change f ∈ {local_homeomorph.refl H} ∪ {e : local_homeomorph H H | e.source = ∅} at hf,
simp only [singleton_union, mem_set_of_eq, mem_insert_iff] at hf,
cases hf,
{ rw hf,
apply u.id_mem },
{ apply u.locality,
assume x hx,
rw [hf, mem_empty_eq] at hx,
exact hx.elim }
end }
instance (H : Type u) [topological_space H] : inhabited (structure_groupoid H) :=
⟨id_groupoid H⟩
/-- To construct a groupoid, one may consider classes of local homeos such that both the function
and its inverse have some property. If this property is stable under composition,
one gets a groupoid. `pregroupoid` bundles the properties needed for this construction, with the
groupoid of smooth functions with smooth inverses as an application. -/
structure pregroupoid (H : Type*) [topological_space H] :=
(property : (H → H) → (set H) → Prop)
(comp : ∀{f g u v}, property f u → property g v → is_open u → is_open v → is_open (u ∩ f ⁻¹' v)
→ property (g ∘ f) (u ∩ f ⁻¹' v))
(id_mem : property id univ)
(locality : ∀{f u}, is_open u → (∀x∈u, ∃v, is_open v ∧ x ∈ v ∧ property f (u ∩ v)) → property f u)
(congr : ∀{f g : H → H} {u}, is_open u → (∀x∈u, g x = f x) → property f u → property g u)
/-- Construct a groupoid of local homeos for which the map and its inverse have some property,
from a pregroupoid asserting that this property is stable under composition. -/
def pregroupoid.groupoid (PG : pregroupoid H) : structure_groupoid H :=
{ members := {e : local_homeomorph H H | PG.property e e.source ∧ PG.property e.symm e.target},
trans' := λe e' he he', begin
split,
{ apply PG.comp he.1 he'.1 e.open_source e'.open_source,
apply e.continuous_to_fun.preimage_open_of_open e.open_source e'.open_source },
{ apply PG.comp he'.2 he.2 e'.open_target e.open_target,
apply e'.continuous_inv_fun.preimage_open_of_open e'.open_target e.open_target }
end,
symm' := λe he, ⟨he.2, he.1⟩,
id_mem' := ⟨PG.id_mem, PG.id_mem⟩,
locality' := λe he, begin
split,
{ apply PG.locality e.open_source (λx xu, _),
rcases he x xu with ⟨s, s_open, xs, hs⟩,
refine ⟨s, s_open, xs, _⟩,
convert hs.1 using 1,
dsimp [local_homeomorph.restr], rw s_open.interior_eq },
{ apply PG.locality e.open_target (λx xu, _),
rcases he (e.symm x) (e.map_target xu) with ⟨s, s_open, xs, hs⟩,
refine ⟨e.target ∩ e.symm ⁻¹' s, _, ⟨xu, xs⟩, _⟩,
{ exact continuous_on.preimage_open_of_open e.continuous_inv_fun e.open_target s_open },
{ rw [← inter_assoc, inter_self],
convert hs.2 using 1,
dsimp [local_homeomorph.restr], rw s_open.interior_eq } },
end,
eq_on_source' := λe e' he ee', begin
split,
{ apply PG.congr e'.open_source ee'.2,
simp only [ee'.1, he.1] },
{ have A := ee'.symm',
apply PG.congr e'.symm.open_source A.2,
convert he.2,
rw A.1,
refl }
end }
lemma mem_groupoid_of_pregroupoid {PG : pregroupoid H} {e : local_homeomorph H H} :
e ∈ PG.groupoid ↔ PG.property e e.source ∧ PG.property e.symm e.target :=
iff.rfl
lemma groupoid_of_pregroupoid_le (PG₁ PG₂ : pregroupoid H)
(h : ∀f s, PG₁.property f s → PG₂.property f s) : PG₁.groupoid ≤ PG₂.groupoid :=
begin
refine structure_groupoid.le_iff.2 (λ e he, _),
rw mem_groupoid_of_pregroupoid at he ⊢,
exact ⟨h _ _ he.1, h _ _ he.2⟩
end
lemma mem_pregroupoid_of_eq_on_source (PG : pregroupoid H) {e e' : local_homeomorph H H}
(he' : e ≈ e') (he : PG.property e e.source) : PG.property e' e'.source :=
begin
rw ← he'.1,
exact PG.congr e.open_source he'.eq_on.symm he,
end
/-- The pregroupoid of all local maps on a topological space `H` -/
@[reducible] def continuous_pregroupoid (H : Type*) [topological_space H] : pregroupoid H :=
{ property := λf s, true,
comp := λf g u v hf hg hu hv huv, trivial,
id_mem := trivial,
locality := λf u u_open h, trivial,
congr := λf g u u_open hcongr hf, trivial }
instance (H : Type*) [topological_space H] : inhabited (pregroupoid H) :=
⟨continuous_pregroupoid H⟩
/-- The groupoid of all local homeomorphisms on a topological space `H` -/
def continuous_groupoid (H : Type*) [topological_space H] : structure_groupoid H :=
pregroupoid.groupoid (continuous_pregroupoid H)
/-- Every structure groupoid is contained in the groupoid of all local homeomorphisms -/
instance : order_top (structure_groupoid H) :=
{ top := continuous_groupoid H,
le_top := λ u f hf, by { split; exact dec_trivial } }
/-- A groupoid is closed under restriction if it contains all restrictions of its element local
homeomorphisms to open subsets of the source. -/
class closed_under_restriction (G : structure_groupoid H) : Prop :=
(closed_under_restriction : ∀ {e : local_homeomorph H H}, e ∈ G → ∀ (s : set H), is_open s →
e.restr s ∈ G)
lemma closed_under_restriction' {G : structure_groupoid H} [closed_under_restriction G]
{e : local_homeomorph H H} (he : e ∈ G) {s : set H} (hs : is_open s) :
e.restr s ∈ G :=
closed_under_restriction.closed_under_restriction he s hs
/-- The trivial restriction-closed groupoid, containing only local homeomorphisms equivalent to the
restriction of the identity to the various open subsets. -/
def id_restr_groupoid : structure_groupoid H :=
{ members := {e | ∃ {s : set H} (h : is_open s), e ≈ local_homeomorph.of_set s h},
trans' := begin
rintros e e' ⟨s, hs, hse⟩ ⟨s', hs', hse'⟩,
refine ⟨s ∩ s', is_open.inter hs hs', _⟩,
have := local_homeomorph.eq_on_source.trans' hse hse',
rwa local_homeomorph.of_set_trans_of_set at this,
end,
symm' := begin
rintros e ⟨s, hs, hse⟩,
refine ⟨s, hs, _⟩,
rw [← of_set_symm],
exact local_homeomorph.eq_on_source.symm' hse,
end,
id_mem' := ⟨univ, is_open_univ, by simp only with mfld_simps⟩,
locality' := begin
intros e h,
refine ⟨e.source, e.open_source, by simp only with mfld_simps, _⟩,
intros x hx,
rcases h x hx with ⟨s, hs, hxs, s', hs', hes'⟩,
have hes : x ∈ (e.restr s).source,
{ rw e.restr_source, refine ⟨hx, _⟩,
rw hs.interior_eq, exact hxs },
simpa only with mfld_simps using local_homeomorph.eq_on_source.eq_on hes' hes,
end,
eq_on_source' := begin
rintros e e' ⟨s, hs, hse⟩ hee',
exact ⟨s, hs, setoid.trans hee' hse⟩,
end }
lemma id_restr_groupoid_mem {s : set H} (hs : is_open s) :
of_set s hs ∈ @id_restr_groupoid H _ := ⟨s, hs, by refl⟩
/-- The trivial restriction-closed groupoid is indeed `closed_under_restriction`. -/
instance closed_under_restriction_id_restr_groupoid :
closed_under_restriction (@id_restr_groupoid H _) :=
⟨ begin
rintros e ⟨s', hs', he⟩ s hs,
use [s' ∩ s, is_open.inter hs' hs],
refine setoid.trans (local_homeomorph.eq_on_source.restr he s) _,
exact ⟨by simp only [hs.interior_eq] with mfld_simps, by simp only with mfld_simps⟩,
end ⟩
/-- A groupoid is closed under restriction if and only if it contains the trivial restriction-closed
groupoid. -/
lemma closed_under_restriction_iff_id_le (G : structure_groupoid H) :
closed_under_restriction G ↔ id_restr_groupoid ≤ G :=
begin
split,
{ introsI _i,
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
refine G.eq_on_source _ hes,
convert closed_under_restriction' G.id_mem hs,
change s = _ ∩ _,
rw hs.interior_eq,
simp only with mfld_simps },
{ intros h,
split,
intros e he s hs,
rw ← of_set_trans (e : local_homeomorph H H) hs,
refine G.trans _ he,
apply structure_groupoid.le_iff.mp h,
exact id_restr_groupoid_mem hs },
end
/-- The groupoid of all local homeomorphisms on a topological space `H` is closed under restriction.
-/
instance : closed_under_restriction (continuous_groupoid H) :=
(closed_under_restriction_iff_id_le _).mpr (by convert le_top)
end groupoid
/-! ### Charted spaces -/
/-- A charted space is a topological space endowed with an atlas, i.e., a set of local
homeomorphisms taking value in a model space `H`, called charts, such that the domains of the charts
cover the whole space. We express the covering property by chosing for each `x` a member
`chart_at H x` of the atlas containing `x` in its source: in the smooth case, this is convenient to
construct the tangent bundle in an efficient way.
The model space is written as an explicit parameter as there can be several model spaces for a
given topological space. For instance, a complex manifold (modelled over `ℂ^n`) will also be seen
sometimes as a real manifold over `ℝ^(2n)`.
-/
class charted_space (H : Type*) [topological_space H] (M : Type*) [topological_space M] :=
(atlas [] : set (local_homeomorph M H))
(chart_at [] : M → local_homeomorph M H)
(mem_chart_source [] : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas [] : ∀x, chart_at x ∈ atlas)
export charted_space
attribute [simp, mfld_simps] mem_chart_source chart_mem_atlas
section charted_space
/-- Any space is a charted_space modelled over itself, by just using the identity chart -/
instance charted_space_self (H : Type*) [topological_space H] : charted_space H H :=
{ atlas := {local_homeomorph.refl H},
chart_at := λx, local_homeomorph.refl H,
mem_chart_source := λx, mem_univ x,
chart_mem_atlas := λx, mem_singleton _ }
/-- In the trivial charted_space structure of a space modelled over itself through the identity, the
atlas members are just the identity -/
@[simp, mfld_simps] lemma charted_space_self_atlas
{H : Type*} [topological_space H] {e : local_homeomorph H H} :
e ∈ atlas H H ↔ e = local_homeomorph.refl H :=
by simp [atlas, charted_space.atlas]
/-- In the model space, chart_at is always the identity -/
lemma chart_at_self_eq {H : Type*} [topological_space H] {x : H} :
chart_at H x = local_homeomorph.refl H :=
by simpa using chart_mem_atlas H x
section
variables (H) [topological_space H] [topological_space M] [charted_space H M]
lemma mem_chart_target (x : M) : chart_at H x x ∈ (chart_at H x).target :=
(chart_at H x).map_source (mem_chart_source _ _)
lemma chart_source_mem_nhds (x : M) : (chart_at H x).source ∈ 𝓝 x :=
(chart_at H x).open_source.mem_nhds $ mem_chart_source H x
lemma chart_target_mem_nhds (x : M) : (chart_at H x).target ∈ 𝓝 (chart_at H x x) :=
(chart_at H x).open_target.mem_nhds $ mem_chart_target H x
open topological_space
lemma charted_space.second_countable_of_countable_cover [second_countable_topology H]
{s : set M} (hs : (⋃ x (hx : x ∈ s), (chart_at H x).source) = univ)
(hsc : s.countable) :
second_countable_topology M :=
begin
haveI : ∀ x : M, second_countable_topology (chart_at H x).source :=
λ x, (chart_at H x).second_countable_topology_source,
haveI := hsc.to_encodable,
rw bUnion_eq_Union at hs,
exact second_countable_topology_of_countable_cover (λ x : s, (chart_at H (x : M)).open_source) hs
end
lemma charted_space.second_countable_of_sigma_compact [second_countable_topology H]
[sigma_compact_space M] :
second_countable_topology M :=
begin
obtain ⟨s, hsc, hsU⟩ : ∃ s, set.countable s ∧ (⋃ x (hx : x ∈ s), (chart_at H x).source) = univ :=
countable_cover_nhds_of_sigma_compact (λ x : M, chart_source_mem_nhds H x),
exact charted_space.second_countable_of_countable_cover H hsU hsc
end
variable (M)
/-- If a topological space admits an atlas with locally compact charts, then the space itself
is locally compact. -/
lemma charted_space.locally_compact [locally_compact_space H] : locally_compact_space M :=
begin
have : ∀ (x : M), (𝓝 x).has_basis
(λ s, s ∈ 𝓝 (chart_at H x x) ∧ is_compact s ∧ s ⊆ (chart_at H x).target)
(λ s, (chart_at H x).symm '' s),
{ intro x,
rw [← (chart_at H x).symm_map_nhds_eq (mem_chart_source H x)],
exact ((compact_basis_nhds (chart_at H x x)).has_basis_self_subset
(chart_target_mem_nhds H x)).map _ },
refine locally_compact_space_of_has_basis this _,
rintro x s ⟨h₁, h₂, h₃⟩,
exact h₂.image_of_continuous_on ((chart_at H x).continuous_on_symm.mono h₃)
end
end
/-- For technical reasons we introduce two type tags:
* `model_prod H H'` is the same as `H × H'`;
* `model_pi H` is the same as `Π i, H i`, where `H : ι → Type*` and `ι` is a finite type.
In both cases the reason is the same, so we explain it only in the case of the product. A charted
space `M` with model `H` is a set of local charts from `M` to `H` covering the space. Every space is
registered as a charted space over itself, using the only chart `id`, in `manifold_model_space`. You
can also define a product of charted space `M` and `M'` (with model space `H × H'`) by taking the
products of the charts. Now, on `H × H'`, there are two charted space structures with model space
`H × H'` itself, the one coming from `manifold_model_space`, and the one coming from the product of
the two `manifold_model_space` on each component. They are equal, but not defeq (because the product
of `id` and `id` is not defeq to `id`), which is bad as we know. This expedient of renaming `H × H'`
solves this problem. -/
library_note "Manifold type tags"
/-- Same thing as `H × H'` We introduce it for technical reasons,
see note [Manifold type tags]. -/
def model_prod (H : Type*) (H' : Type*) := H × H'
/-- Same thing as `Π i, H i` We introduce it for technical reasons,
see note [Manifold type tags]. -/
def model_pi {ι : Type*} (H : ι → Type*) := Π i, H i
section
local attribute [reducible] model_prod
instance model_prod_inhabited [inhabited H] [inhabited H'] :
inhabited (model_prod H H') :=
prod.inhabited
instance (H : Type*) [topological_space H] (H' : Type*) [topological_space H'] :
topological_space (model_prod H H') :=
prod.topological_space
/- Next lemma shows up often when dealing with derivatives, register it as simp. -/
@[simp, mfld_simps] lemma model_prod_range_prod_id
{H : Type*} {H' : Type*} {α : Type*} (f : H → α) :
range (λ (p : model_prod H H'), (f p.1, p.2)) = range f ×ˢ (univ : set H') :=
by rw prod_range_univ_eq
end
section
variables {ι : Type*} {Hi : ι → Type*}
instance model_pi_inhabited [Π i, inhabited (Hi i)] :
inhabited (model_pi Hi) :=
pi.inhabited _
instance [Π i, topological_space (Hi i)] :
topological_space (model_pi Hi) :=
Pi.topological_space
end
/-- The product of two charted spaces is naturally a charted space, with the canonical
construction of the atlas of product maps. -/
instance prod_charted_space (H : Type*) [topological_space H]
(M : Type*) [topological_space M] [charted_space H M]
(H' : Type*) [topological_space H']
(M' : Type*) [topological_space M'] [charted_space H' M'] :
charted_space (model_prod H H') (M × M') :=
{ atlas := image2 local_homeomorph.prod (atlas H M) (atlas H' M'),
chart_at := λ x : M × M', (chart_at H x.1).prod (chart_at H' x.2),
mem_chart_source := λ x, ⟨mem_chart_source _ _, mem_chart_source _ _⟩,
chart_mem_atlas := λ x, mem_image2_of_mem (chart_mem_atlas _ _) (chart_mem_atlas _ _) }
section prod_charted_space
variables [topological_space H] [topological_space M] [charted_space H M]
[topological_space H'] [topological_space M'] [charted_space H' M'] {x : M×M'}
@[simp, mfld_simps] lemma prod_charted_space_chart_at :
(chart_at (model_prod H H') x) = (chart_at H x.fst).prod (chart_at H' x.snd) := rfl
end prod_charted_space
/-- The product of a finite family of charted spaces is naturally a charted space, with the
canonical construction of the atlas of finite product maps. -/
instance pi_charted_space {ι : Type*} [fintype ι] (H : ι → Type*) [Π i, topological_space (H i)]
(M : ι → Type*) [Π i, topological_space (M i)] [Π i, charted_space (H i) (M i)] :
charted_space (model_pi H) (Π i, M i) :=
{ atlas := local_homeomorph.pi '' (set.pi univ $ λ i, atlas (H i) (M i)),
chart_at := λ f, local_homeomorph.pi $ λ i, chart_at (H i) (f i),
mem_chart_source := λ f i hi, mem_chart_source (H i) (f i),
chart_mem_atlas := λ f, mem_image_of_mem _ $ λ i hi, chart_mem_atlas (H i) (f i) }
@[simp, mfld_simps] lemma pi_charted_space_chart_at {ι : Type*} [fintype ι] (H : ι → Type*)
[Π i, topological_space (H i)] (M : ι → Type*) [Π i, topological_space (M i)]
[Π i, charted_space (H i) (M i)] (f : Π i, M i) :
chart_at (model_pi H) f = local_homeomorph.pi (λ i, chart_at (H i) (f i)) := rfl
end charted_space
/-! ### Constructing a topology from an atlas -/
/-- Sometimes, one may want to construct a charted space structure on a space which does not yet
have a topological structure, where the topology would come from the charts. For this, one needs
charts that are only local equivs, and continuity properties for their composition.
This is formalised in `charted_space_core`. -/
@[nolint has_inhabited_instance]
structure charted_space_core (H : Type*) [topological_space H] (M : Type*) :=
(atlas : set (local_equiv M H))
(chart_at : M → local_equiv M H)
(mem_chart_source : ∀x, x ∈ (chart_at x).source)
(chart_mem_atlas : ∀x, chart_at x ∈ atlas)
(open_source : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas → is_open (e.symm.trans e').source)
(continuous_to_fun : ∀e e' : local_equiv M H, e ∈ atlas → e' ∈ atlas →
continuous_on (e.symm.trans e') (e.symm.trans e').source)
namespace charted_space_core
variables [topological_space H] (c : charted_space_core H M) {e : local_equiv M H}
/-- Topology generated by a set of charts on a Type. -/
protected def to_topological_space : topological_space M :=
topological_space.generate_from $ ⋃ (e : local_equiv M H) (he : e ∈ c.atlas)
(s : set H) (s_open : is_open s), {e ⁻¹' s ∩ e.source}
lemma open_source' (he : e ∈ c.atlas) : @is_open M c.to_topological_space e.source :=
begin
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
refine ⟨e, he, univ, is_open_univ, _⟩,
simp only [set.univ_inter, set.preimage_univ]
end
lemma open_target (he : e ∈ c.atlas) : is_open e.target :=
begin
have E : e.target ∩ e.symm ⁻¹' e.source = e.target :=
subset.antisymm (inter_subset_left _ _) (λx hx, ⟨hx,
local_equiv.target_subset_preimage_source _ hx⟩),
simpa [local_equiv.trans_source, E] using c.open_source e e he he
end
/-- An element of the atlas in a charted space without topology becomes a local homeomorphism
for the topology constructed from this atlas. The `local_homeomorph` version is given in this
definition. -/
protected def local_homeomorph (e : local_equiv M H) (he : e ∈ c.atlas) :
@local_homeomorph M H c.to_topological_space _ :=
{ open_source := by convert c.open_source' he,
open_target := by convert c.open_target he,
continuous_to_fun := begin
letI : topological_space M := c.to_topological_space,
rw continuous_on_open_iff (c.open_source' he),
assume s s_open,
rw inter_comm,
apply topological_space.generate_open.basic,
simp only [exists_prop, mem_Union, mem_singleton_iff],
exact ⟨e, he, ⟨s, s_open, rfl⟩⟩
end,
continuous_inv_fun := begin
letI : topological_space M := c.to_topological_space,
apply continuous_on_open_of_generate_from (c.open_target he),
assume t ht,
simp only [exists_prop, mem_Union, mem_singleton_iff] at ht,
rcases ht with ⟨e', e'_atlas, s, s_open, ts⟩,
rw ts,
let f := e.symm.trans e',
have : is_open (f ⁻¹' s ∩ f.source),
by simpa [inter_comm] using (continuous_on_open_iff (c.open_source e e' he e'_atlas)).1
(c.continuous_to_fun e e' he e'_atlas) s s_open,
have A : e' ∘ e.symm ⁻¹' s ∩ (e.target ∩ e.symm ⁻¹' e'.source) =
e.target ∩ (e' ∘ e.symm ⁻¹' s ∩ e.symm ⁻¹' e'.source),
by { rw [← inter_assoc, ← inter_assoc], congr' 1, exact inter_comm _ _ },
simpa [local_equiv.trans_source, preimage_inter, preimage_comp.symm, A] using this
end,
..e }
/-- Given a charted space without topology, endow it with a genuine charted space structure with
respect to the topology constructed from the atlas. -/
def to_charted_space : @charted_space H _ M c.to_topological_space :=
{ atlas := ⋃ (e : local_equiv M H) (he : e ∈ c.atlas), {c.local_homeomorph e he},
chart_at := λx, c.local_homeomorph (c.chart_at x) (c.chart_mem_atlas x),
mem_chart_source := λx, c.mem_chart_source x,
chart_mem_atlas := λx, begin
simp only [mem_Union, mem_singleton_iff],
exact ⟨c.chart_at x, c.chart_mem_atlas x, rfl⟩,
end }
end charted_space_core
/-! ### Charted space with a given structure groupoid -/
section has_groupoid
variables [topological_space H] [topological_space M] [charted_space H M]
/-- A charted space has an atlas in a groupoid `G` if the change of coordinates belong to the
groupoid -/
class has_groupoid {H : Type*} [topological_space H] (M : Type*) [topological_space M]
[charted_space H M] (G : structure_groupoid H) : Prop :=
(compatible [] : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M → e.symm ≫ₕ e' ∈ G)
/-- Reformulate in the `structure_groupoid` namespace the compatibility condition of charts in a
charted space admitting a structure groupoid, to make it more easily accessible with dot
notation. -/
lemma structure_groupoid.compatible {H : Type*} [topological_space H] (G : structure_groupoid H)
{M : Type*} [topological_space M] [charted_space H M] [has_groupoid M G]
{e e' : local_homeomorph M H} (he : e ∈ atlas H M) (he' : e' ∈ atlas H M) :
e.symm ≫ₕ e' ∈ G :=
has_groupoid.compatible G he he'
lemma has_groupoid_of_le {G₁ G₂ : structure_groupoid H} (h : has_groupoid M G₁) (hle : G₁ ≤ G₂) :
has_groupoid M G₂ :=
⟨ λ e e' he he', hle ((h.compatible : _) he he') ⟩
lemma has_groupoid_of_pregroupoid (PG : pregroupoid H)
(h : ∀{e e' : local_homeomorph M H}, e ∈ atlas H M → e' ∈ atlas H M
→ PG.property (e.symm ≫ₕ e') (e.symm ≫ₕ e').source) :
has_groupoid M (PG.groupoid) :=
⟨assume e e' he he', mem_groupoid_of_pregroupoid.mpr ⟨h he he', h he' he⟩⟩
/-- The trivial charted space structure on the model space is compatible with any groupoid -/
instance has_groupoid_model_space (H : Type*) [topological_space H] (G : structure_groupoid H) :
has_groupoid H G :=
{ compatible := λe e' he he', begin
replace he : e ∈ atlas H H := he,
replace he' : e' ∈ atlas H H := he',
rw charted_space_self_atlas at he he',
simp [he, he', structure_groupoid.id_mem]
end }
/-- Any charted space structure is compatible with the groupoid of all local homeomorphisms -/
instance has_groupoid_continuous_groupoid : has_groupoid M (continuous_groupoid H) :=
⟨begin
assume e e' he he',
rw [continuous_groupoid, mem_groupoid_of_pregroupoid],
simp only [and_self]
end⟩
section maximal_atlas
variables (M) (G : structure_groupoid H)
/-- Given a charted space admitting a structure groupoid, the maximal atlas associated to this
structure groupoid is the set of all local charts that are compatible with the atlas, i.e., such
that changing coordinates with an atlas member gives an element of the groupoid. -/
def structure_groupoid.maximal_atlas : set (local_homeomorph M H) :=
{e | ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G}
variable {M}
/-- The elements of the atlas belong to the maximal atlas for any structure groupoid -/
lemma structure_groupoid.mem_maximal_atlas_of_mem_atlas [has_groupoid M G]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ G.maximal_atlas M :=
λ e' he', ⟨G.compatible he he', G.compatible he' he⟩
lemma structure_groupoid.chart_mem_maximal_atlas [has_groupoid M G]
(x : M) : chart_at H x ∈ G.maximal_atlas M :=
G.mem_maximal_atlas_of_mem_atlas (chart_mem_atlas H x)
variable {G}
lemma mem_maximal_atlas_iff {e : local_homeomorph M H} :
e ∈ G.maximal_atlas M ↔ ∀ e' ∈ atlas H M, e.symm ≫ₕ e' ∈ G ∧ e'.symm ≫ₕ e ∈ G :=
iff.rfl
/-- Changing coordinates between two elements of the maximal atlas gives rise to an element
of the structure groupoid. -/
lemma structure_groupoid.compatible_of_mem_maximal_atlas {e e' : local_homeomorph M H}
(he : e ∈ G.maximal_atlas M) (he' : e' ∈ G.maximal_atlas M) : e.symm ≫ₕ e' ∈ G :=
begin
apply G.locality (λ x hx, _),
set f := chart_at H (e.symm x) with hf,
let s := e.target ∩ (e.symm ⁻¹' f.source),
have hs : is_open s,
{ apply e.symm.continuous_to_fun.preimage_open_of_open; apply open_source },
have xs : x ∈ s, by { dsimp at hx, simp [s, hx] },
refine ⟨s, hs, xs, _⟩,
have A : e.symm ≫ₕ f ∈ G := (mem_maximal_atlas_iff.1 he f (chart_mem_atlas _ _)).1,
have B : f.symm ≫ₕ e' ∈ G := (mem_maximal_atlas_iff.1 he' f (chart_mem_atlas _ _)).2,
have C : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ∈ G := G.trans A B,
have D : (e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') ≈ (e.symm ≫ₕ e').restr s := calc
(e.symm ≫ₕ f) ≫ₕ (f.symm ≫ₕ e') = e.symm ≫ₕ (f ≫ₕ f.symm) ≫ₕ e' : by simp [trans_assoc]
... ≈ e.symm ≫ₕ (of_set f.source f.open_source) ≫ₕ e' :
by simp [eq_on_source.trans', trans_self_symm]
... ≈ (e.symm ≫ₕ (of_set f.source f.open_source)) ≫ₕ e' : by simp [trans_assoc]
... ≈ (e.symm.restr s) ≫ₕ e' : by simp [s, trans_of_set']
... ≈ (e.symm ≫ₕ e').restr s : by simp [restr_trans],
exact G.eq_on_source C (setoid.symm D),
end
variable (G)
/-- In the model space, the identity is in any maximal atlas. -/
lemma structure_groupoid.id_mem_maximal_atlas : local_homeomorph.refl H ∈ G.maximal_atlas H :=
G.mem_maximal_atlas_of_mem_atlas (by simp)
end maximal_atlas
section singleton
variables {α : Type*} [topological_space α]
namespace local_homeomorph
variable (e : local_homeomorph α H)
/-- If a single local homeomorphism `e` from a space `α` into `H` has source covering the whole
space `α`, then that local homeomorphism induces an `H`-charted space structure on `α`.
(This condition is equivalent to `e` being an open embedding of `α` into `H`; see
`open_embedding.singleton_charted_space`.) -/
def singleton_charted_space (h : e.source = set.univ) : charted_space H α :=
{ atlas := {e},
chart_at := λ _, e,
mem_chart_source := λ _, by simp only [h] with mfld_simps,
chart_mem_atlas := λ _, by tauto }
@[simp, mfld_simps] lemma singleton_charted_space_chart_at_eq (h : e.source = set.univ) {x : α} :
@chart_at H _ α _ (e.singleton_charted_space h) x = e := rfl
lemma singleton_charted_space_chart_at_source
(h : e.source = set.univ) {x : α} :
(@chart_at H _ α _ (e.singleton_charted_space h) x).source = set.univ := h
lemma singleton_charted_space_mem_atlas_eq (h : e.source = set.univ)
(e' : local_homeomorph α H) (h' : e' ∈ (e.singleton_charted_space h).atlas) : e' = e := h'
/-- Given a local homeomorphism `e` from a space `α` into `H`, if its source covers the whole
space `α`, then the induced charted space structure on `α` is `has_groupoid G` for any structure
groupoid `G` which is closed under restrictions. -/
lemma singleton_has_groupoid (h : e.source = set.univ) (G : structure_groupoid H)
[closed_under_restriction G] : @has_groupoid _ _ _ _ (e.singleton_charted_space h) G :=
{ compatible := begin
intros e' e'' he' he'',
rw e.singleton_charted_space_mem_atlas_eq h e' he',
rw e.singleton_charted_space_mem_atlas_eq h e'' he'',
refine G.eq_on_source _ e.trans_symm_self,
have hle : id_restr_groupoid ≤ G := (closed_under_restriction_iff_id_le G).mp (by assumption),
exact structure_groupoid.le_iff.mp hle _ (id_restr_groupoid_mem _),
end }
end local_homeomorph
namespace open_embedding
variable [nonempty α]
/-- An open embedding of `α` into `H` induces an `H`-charted space structure on `α`.
See `local_homeomorph.singleton_charted_space` -/
def singleton_charted_space {f : α → H} (h : open_embedding f) :
charted_space H α := (h.to_local_homeomorph f).singleton_charted_space (by simp)
lemma singleton_charted_space_chart_at_eq {f : α → H} (h : open_embedding f) {x : α} :
⇑(@chart_at H _ α _ (h.singleton_charted_space) x) = f := rfl
lemma singleton_has_groupoid {f : α → H} (h : open_embedding f)
(G : structure_groupoid H) [closed_under_restriction G] :
@has_groupoid _ _ _ _ h.singleton_charted_space G :=
(h.to_local_homeomorph f).singleton_has_groupoid (by simp) G
end open_embedding
end singleton
namespace topological_space.opens
open topological_space
variables (G : structure_groupoid H) [has_groupoid M G]
variables (s : opens M)
/-- An open subset of a charted space is naturally a charted space. -/
instance : charted_space H s :=
{ atlas := ⋃ (x : s), {@local_homeomorph.subtype_restr _ _ _ _ (chart_at H x.1) s ⟨x⟩},
chart_at := λ x, @local_homeomorph.subtype_restr _ _ _ _ (chart_at H x.1) s ⟨x⟩,
mem_chart_source := λ x, by { simp only with mfld_simps, exact (mem_chart_source H x.1) },
chart_mem_atlas := λ x, by { simp only [mem_Union, mem_singleton_iff], use x } }
/-- If a groupoid `G` is `closed_under_restriction`, then an open subset of a space which is
`has_groupoid G` is naturally `has_groupoid G`. -/
instance [closed_under_restriction G] : has_groupoid s G :=
{ compatible := begin
rintros e e' ⟨_, ⟨x, hc⟩, he⟩ ⟨_, ⟨x', hc'⟩, he'⟩,
haveI : nonempty s := ⟨x⟩,
simp only [hc.symm, mem_singleton_iff, subtype.val_eq_coe] at he,
simp only [hc'.symm, mem_singleton_iff, subtype.val_eq_coe] at he',
rw [he, he'],
convert G.eq_on_source _
(subtype_restr_symm_trans_subtype_restr s (chart_at H x) (chart_at H x')),
apply closed_under_restriction',
{ exact G.compatible (chart_mem_atlas H x) (chart_mem_atlas H x') },
{ exact preimage_open_of_open_symm (chart_at H x) s.2 },
end }
end topological_space.opens
/-! ### Structomorphisms -/
/-- A `G`-diffeomorphism between two charted spaces is a homeomorphism which, when read in the
charts, belongs to `G`. We avoid the word diffeomorph as it is too related to the smooth category,
and use structomorph instead. -/
@[nolint has_inhabited_instance]
structure structomorph (G : structure_groupoid H) (M : Type*) (M' : Type*)
[topological_space M] [topological_space M'] [charted_space H M] [charted_space H M']
extends homeomorph M M' :=
(mem_groupoid : ∀c : local_homeomorph M H, ∀c' : local_homeomorph M' H,
c ∈ atlas H M → c' ∈ atlas H M' → c.symm ≫ₕ to_homeomorph.to_local_homeomorph ≫ₕ c' ∈ G)
variables [topological_space M'] [topological_space M'']
{G : structure_groupoid H} [charted_space H M'] [charted_space H M'']
/-- The identity is a diffeomorphism of any charted space, for any groupoid. -/
def structomorph.refl (M : Type*) [topological_space M] [charted_space H M]
[has_groupoid M G] : structomorph G M M :=
{ mem_groupoid := λc c' hc hc', begin
change (local_homeomorph.symm c) ≫ₕ (local_homeomorph.refl M) ≫ₕ c' ∈ G,
rw local_homeomorph.refl_trans,
exact has_groupoid.compatible G hc hc'
end,
..homeomorph.refl M }
/-- The inverse of a structomorphism is a structomorphism -/
def structomorph.symm (e : structomorph G M M') : structomorph G M' M :=
{ mem_groupoid := begin
assume c c' hc hc',
have : (c'.symm ≫ₕ e.to_homeomorph.to_local_homeomorph ≫ₕ c).symm ∈ G :=
G.symm (e.mem_groupoid c' c hc' hc),
rwa [trans_symm_eq_symm_trans_symm, trans_symm_eq_symm_trans_symm, symm_symm, trans_assoc]
at this,
end,
..e.to_homeomorph.symm}
/-- The composition of structomorphisms is a structomorphism -/
def structomorph.trans (e : structomorph G M M') (e' : structomorph G M' M'') :
structomorph G M M'' :=
{ mem_groupoid := begin
/- Let c and c' be two charts in M and M''. We want to show that e' ∘ e is smooth in these
charts, around any point x. For this, let y = e (c⁻¹ x), and consider a chart g around y.
Then g ∘ e ∘ c⁻¹ and c' ∘ e' ∘ g⁻¹ are both smooth as e and e' are structomorphisms, so
their composition is smooth, and it coincides with c' ∘ e' ∘ e ∘ c⁻¹ around x. -/
assume c c' hc hc',
refine G.locality (λx hx, _),
let f₁ := e.to_homeomorph.to_local_homeomorph,
let f₂ := e'.to_homeomorph.to_local_homeomorph,
let f := (e.to_homeomorph.trans e'.to_homeomorph).to_local_homeomorph,
have feq : f = f₁ ≫ₕ f₂ := homeomorph.trans_to_local_homeomorph _ _,
-- define the atlas g around y
let y := (c.symm ≫ₕ f₁) x,
let g := chart_at H y,
have hg₁ := chart_mem_atlas H y,
have hg₂ := mem_chart_source H y,
let s := (c.symm ≫ₕ f₁).source ∩ (c.symm ≫ₕ f₁) ⁻¹' g.source,
have open_s : is_open s,
by apply (c.symm ≫ₕ f₁).continuous_to_fun.preimage_open_of_open; apply open_source,
have : x ∈ s,
{ split,
{ simp only [trans_source, preimage_univ, inter_univ, homeomorph.to_local_homeomorph_source],
rw trans_source at hx,
exact hx.1 },
{ exact hg₂ } },
refine ⟨s, open_s, this, _⟩,
let F₁ := (c.symm ≫ₕ f₁ ≫ₕ g) ≫ₕ (g.symm ≫ₕ f₂ ≫ₕ c'),
have A : F₁ ∈ G := G.trans (e.mem_groupoid c g hc hg₁) (e'.mem_groupoid g c' hg₁ hc'),
let F₂ := (c.symm ≫ₕ f ≫ₕ c').restr s,
have : F₁ ≈ F₂ := calc
F₁ ≈ c.symm ≫ₕ f₁ ≫ₕ (g ≫ₕ g.symm) ≫ₕ f₂ ≫ₕ c' : by simp [F₁, trans_assoc]
... ≈ c.symm ≫ₕ f₁ ≫ₕ (of_set g.source g.open_source) ≫ₕ f₂ ≫ₕ c' :
by simp [eq_on_source.trans', trans_self_symm g]
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (of_set g.source g.open_source)) ≫ₕ (f₂ ≫ₕ c') :
by simp [trans_assoc]
... ≈ ((c.symm ≫ₕ f₁).restr s) ≫ₕ (f₂ ≫ₕ c') : by simp [s, trans_of_set']
... ≈ ((c.symm ≫ₕ f₁) ≫ₕ (f₂ ≫ₕ c')).restr s : by simp [restr_trans]
... ≈ (c.symm ≫ₕ (f₁ ≫ₕ f₂) ≫ₕ c').restr s : by simp [eq_on_source.restr, trans_assoc]
... ≈ F₂ : by simp [F₂, feq],
have : F₂ ∈ G := G.eq_on_source A (setoid.symm this),
exact this
end,
..homeomorph.trans e.to_homeomorph e'.to_homeomorph }
end has_groupoid
|
6f8e0f44edb7fe9ce2eb7194ed98fe6fc7ba834b | 8eeb99d0fdf8125f5d39a0ce8631653f588ee817 | /src/algebra/pointwise.lean | 9ba9673a888c02fdee137c8db5e0d496cc14251f | [
"Apache-2.0"
] | permissive | jesse-michael-han/mathlib | a15c58378846011b003669354cbab7062b893cfe | fa6312e4dc971985e6b7708d99a5bc3062485c89 | refs/heads/master | 1,625,200,760,912 | 1,602,081,753,000 | 1,602,081,753,000 | 181,787,230 | 0 | 0 | null | 1,555,460,682,000 | 1,555,460,682,000 | null | UTF-8 | Lean | false | false | 15,368 | 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
|
07578392b1bacc88d9a848b9092d5b62af9f4210 | dd0f5513e11c52db157d2fcc8456d9401a6cd9da | /11_Tactic-Style_Proofs.org.41.lean | 1d73858104b798fab0129e0bceec67e9a95f70e9 | [] | no_license | cjmazey/lean-tutorial | ba559a49f82aa6c5848b9bf17b7389bf7f4ba645 | 381f61c9fcac56d01d959ae0fa6e376f2c4e3b34 | refs/heads/master | 1,610,286,098,832 | 1,447,124,923,000 | 1,447,124,923,000 | 43,082,433 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 206 | lean | import standard
import data.nat
open nat
-- BEGIN
variables (a b : nat)
example (H₁ : a + 0 = 0) (H₂ : b + 0 = 0) : a + b = 0 :=
begin
rewrite add_zero at (H₁, H₂),
rewrite [H₁, H₂]
end
-- END
|
fec2f2722fd632de0d6520b9b3672fb1cec3b042 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/data/equiv/basic.lean | f2d228cb70a7bcbee3fbdb9a90a864c3dfa58cd7 | [
"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 | 70,741 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
In the standard library we cannot assume the univalence axiom.
We say two types are equivalent if they are isomorphic.
Two equivalent types have the same cardinality.
-/
import data.set.function
import algebra.group.basic
open function
universes u v w z
variables {α : Sort u} {β : Sort v} {γ : Sort w}
/-- `α ≃ β` is the type of functions from `α → β` with a two-sided inverse. -/
@[nolint inhabited]
structure equiv (α : Sort*) (β : Sort*) :=
(to_fun : α → β)
(inv_fun : β → α)
(left_inv : left_inverse inv_fun to_fun)
(right_inv : right_inverse inv_fun to_fun)
infix ` ≃ `:25 := equiv
/-- Convert an involutive function `f` to an equivalence with `to_fun = inv_fun = f`. -/
def function.involutive.to_equiv (f : α → α) (h : involutive f) : α ≃ α :=
⟨f, f, h.left_inverse, h.right_inverse⟩
namespace equiv
/-- `perm α` is the type of bijections from `α` to itself. -/
@[reducible] def perm (α : Sort*) := equiv α α
instance : has_coe_to_fun (α ≃ β) :=
⟨_, to_fun⟩
@[simp] theorem coe_fn_mk (f : α → β) (g l r) : (equiv.mk f g l r : α → β) = f :=
rfl
/-- The map `coe_fn : (r ≃ s) → (r → s)` is injective. We can't use `function.injective`
here but mimic its signature by using `⦃e₁ e₂⦄`. -/
theorem coe_fn_injective : ∀ ⦃e₁ e₂ : equiv α β⦄, (e₁ : α → β) = e₂ → e₁ = e₂
| ⟨f₁, g₁, l₁, r₁⟩ ⟨f₂, g₂, l₂, r₂⟩ h :=
have f₁ = f₂, from h,
have g₁ = g₂, from l₁.eq_right_inverse (this.symm ▸ r₂),
by simp *
@[ext] lemma ext {f g : equiv α β} (H : ∀ x, f x = g x) : f = g :=
coe_fn_injective (funext H)
@[ext] lemma perm.ext {σ τ : equiv.perm α} (H : ∀ x, σ x = τ x) : σ = τ :=
equiv.ext H
lemma ext_iff {f g : equiv α β} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, ext⟩
lemma perm.ext_iff {σ τ : equiv.perm α} : σ = τ ↔ ∀ x, σ x = τ x :=
ext_iff
/-- Any type is equivalent to itself. -/
@[refl] protected def refl (α : Sort*) : α ≃ α := ⟨id, id, λ x, rfl, λ x, rfl⟩
/-- Inverse of an equivalence `e : α ≃ β`. -/
@[symm] protected def symm (e : α ≃ β) : β ≃ α := ⟨e.inv_fun, e.to_fun, e.right_inv, e.left_inv⟩
/-- Composition of equivalences `e₁ : α ≃ β` and `e₂ : β ≃ γ`. -/
@[trans] protected def trans (e₁ : α ≃ β) (e₂ : β ≃ γ) : α ≃ γ :=
⟨e₂.to_fun ∘ e₁.to_fun, e₁.inv_fun ∘ e₂.inv_fun,
e₂.left_inv.comp e₁.left_inv, e₂.right_inv.comp e₁.right_inv⟩
@[simp]
lemma to_fun_as_coe (e : α ≃ β) : e.to_fun = e := rfl
@[simp]
lemma inv_fun_as_coe (e : α ≃ β) : e.inv_fun = e.symm := rfl
protected theorem injective (e : α ≃ β) : injective e :=
e.left_inv.injective
protected theorem surjective (e : α ≃ β) : surjective e :=
e.right_inv.surjective
protected theorem bijective (f : α ≃ β) : bijective f :=
⟨f.injective, f.surjective⟩
@[simp] lemma range_eq_univ {α : Type*} {β : Type*} (e : α ≃ β) : set.range e = set.univ :=
set.eq_univ_of_forall e.surjective
protected theorem subsingleton (e : α ≃ β) [subsingleton β] : subsingleton α :=
e.injective.comap_subsingleton
/-- Transfer `decidable_eq` across an equivalence. -/
protected def decidable_eq (e : α ≃ β) [decidable_eq β] : decidable_eq α :=
e.injective.decidable_eq
lemma nonempty_iff_nonempty (e : α ≃ β) : nonempty α ↔ nonempty β :=
nonempty.congr e e.symm
/-- If `α ≃ β` and `β` is inhabited, then so is `α`. -/
protected def inhabited [inhabited β] (e : α ≃ β) : inhabited α :=
⟨e.symm (default _)⟩
/-- If `α ≃ β` and `β` is a singleton type, then so is `α`. -/
protected def unique [unique β] (e : α ≃ β) : unique α :=
e.symm.surjective.unique
/-- Equivalence between equal types. -/
protected def cast {α β : Sort*} (h : α = β) : α ≃ β :=
⟨cast h, cast h.symm, λ x, by { cases h, refl }, λ x, by { cases h, refl }⟩
@[simp] theorem coe_fn_symm_mk (f : α → β) (g l r) : ((equiv.mk f g l r).symm : β → α) = g :=
rfl
@[simp] theorem coe_refl : ⇑(equiv.refl α) = id := rfl
theorem refl_apply (x : α) : equiv.refl α x = x := rfl
@[simp] theorem coe_trans (f : α ≃ β) (g : β ≃ γ) : ⇑(f.trans g) = g ∘ f := rfl
theorem trans_apply (f : α ≃ β) (g : β ≃ γ) (a : α) : (f.trans g) a = g (f a) := rfl
@[simp] theorem apply_symm_apply (e : α ≃ β) (x : β) : e (e.symm x) = x :=
e.right_inv x
@[simp] theorem symm_apply_apply (e : α ≃ β) (x : α) : e.symm (e x) = x :=
e.left_inv x
@[simp] theorem symm_comp_self (e : α ≃ β) : e.symm ∘ e = id := funext e.symm_apply_apply
@[simp] theorem self_comp_symm (e : α ≃ β) : e ∘ e.symm = id := funext e.apply_symm_apply
@[simp] lemma symm_trans_apply (f : α ≃ β) (g : β ≃ γ) (a : γ) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
@[simp] theorem apply_eq_iff_eq (f : α ≃ β) (x y : α) : f x = f y ↔ x = y :=
f.injective.eq_iff
theorem apply_eq_iff_eq_symm_apply {α β : Sort*} (f : α ≃ β) (x : α) (y : β) :
f x = y ↔ x = f.symm y :=
begin
conv_lhs { rw ←apply_symm_apply f y, },
rw apply_eq_iff_eq,
end
@[simp] theorem cast_apply {α β} (h : α = β) (x : α) : equiv.cast h x = cast h x := rfl
lemma symm_apply_eq {α β} (e : α ≃ β) {x y} : e.symm x = y ↔ x = e y :=
⟨λ H, by simp [H.symm], λ H, by simp [H]⟩
lemma eq_symm_apply {α β} (e : α ≃ β) {x y} : y = e.symm x ↔ e y = x :=
(eq_comm.trans e.symm_apply_eq).trans eq_comm
@[simp] theorem symm_symm (e : α ≃ β) : e.symm.symm = e := by { cases e, refl }
@[simp] theorem trans_refl (e : α ≃ β) : e.trans (equiv.refl β) = e := by { cases e, refl }
@[simp] theorem refl_symm : (equiv.refl α).symm = equiv.refl α := rfl
@[simp] theorem refl_trans (e : α ≃ β) : (equiv.refl α).trans e = e := by { cases e, refl }
@[simp] theorem symm_trans (e : α ≃ β) : e.symm.trans e = equiv.refl β := ext (by simp)
@[simp] theorem trans_symm (e : α ≃ β) : e.trans e.symm = equiv.refl α := ext (by simp)
lemma trans_assoc {δ} (ab : α ≃ β) (bc : β ≃ γ) (cd : γ ≃ δ) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) :=
equiv.ext $ assume a, rfl
theorem left_inverse_symm (f : equiv α β) : left_inverse f.symm f := f.left_inv
theorem right_inverse_symm (f : equiv α β) : function.right_inverse f.symm f := f.right_inv
/-- If `α` is equivalent to `β` and `γ` is equivalent to `δ`, then the type of equivalences `α ≃ γ`
is equivalent to the type of equivalences `β ≃ δ`. -/
def equiv_congr {δ} (ab : α ≃ β) (cd : γ ≃ δ) : (α ≃ γ) ≃ (β ≃ δ) :=
⟨ λac, (ab.symm.trans ac).trans cd, λbd, ab.trans $ bd.trans $ cd.symm,
assume ac, by { ext x, simp }, assume ac, by { ext x, simp } ⟩
/-- If `α` is equivalent to `β`, then `perm α` is equivalent to `perm β`. -/
def perm_congr {α : Type*} {β : Type*} (e : α ≃ β) : perm α ≃ perm β :=
equiv_congr e e
protected lemma image_eq_preimage {α β} (e : α ≃ β) (s : set α) : e '' s = e.symm ⁻¹' s :=
set.ext $ assume x, set.mem_image_iff_of_inverse e.left_inv e.right_inv
protected lemma subset_image {α β} (e : α ≃ β) (s : set α) (t : set β) :
t ⊆ e '' s ↔ e.symm '' t ⊆ s :=
by rw [set.image_subset_iff, e.image_eq_preimage]
lemma symm_image_image {α β} (f : equiv α β) (s : set α) : f.symm '' (f '' s) = s :=
by { rw [← set.image_comp], simp }
protected lemma image_compl {α β} (f : equiv α β) (s : set α) :
f '' sᶜ = (f '' s)ᶜ :=
set.image_compl_eq f.bijective
/- The group of permutations (self-equivalences) of a type `α` -/
namespace perm
instance perm_group {α : Type u} : group (perm α) :=
begin
refine { mul := λ f g, equiv.trans g f, one := equiv.refl α, inv:= equiv.symm, ..};
intros; apply equiv.ext; try { apply trans_apply },
apply symm_apply_apply
end
@[simp] theorem mul_apply {α : Type u} (f g : perm α) (x) : (f * g) x = f (g x) :=
equiv.trans_apply _ _ _
@[simp] theorem one_apply {α : Type u} (x) : (1 : perm α) x = x := rfl
@[simp] lemma inv_apply_self {α : Type u} (f : perm α) (x) :
f⁻¹ (f x) = x := equiv.symm_apply_apply _ _
@[simp] lemma apply_inv_self {α : Type u} (f : perm α) (x) :
f (f⁻¹ x) = x := equiv.apply_symm_apply _ _
lemma one_def {α : Type u} : (1 : perm α) = equiv.refl α := rfl
lemma mul_def {α : Type u} (f g : perm α) : f * g = g.trans f := rfl
lemma inv_def {α : Type u} (f : perm α) : f⁻¹ = f.symm := rfl
end perm
/-- If `α` is an empty type, then it is equivalent to the `empty` type. -/
def equiv_empty (h : α → false) : α ≃ empty :=
⟨λ x, (h x).elim, λ e, e.rec _, λ x, (h x).elim, λ e, e.rec _⟩
/-- `false` is equivalent to `empty`. -/
def false_equiv_empty : false ≃ empty :=
equiv_empty _root_.id
/-- If `α` is an empty type, then it is equivalent to the `pempty` type in any universe. -/
def {u' v'} equiv_pempty {α : Sort v'} (h : α → false) : α ≃ pempty.{u'} :=
⟨λ x, (h x).elim, λ e, e.rec _, λ x, (h x).elim, λ e, e.rec _⟩
/-- `false` is equivalent to `pempty`. -/
def false_equiv_pempty : false ≃ pempty :=
equiv_pempty _root_.id
/-- `empty` is equivalent to `pempty`. -/
def empty_equiv_pempty : empty ≃ pempty :=
equiv_pempty $ empty.rec _
/-- `pempty` types from any two universes are equivalent. -/
def pempty_equiv_pempty : pempty.{v} ≃ pempty.{w} :=
equiv_pempty pempty.elim
/-- If `α` is not `nonempty`, then it is equivalent to `empty`. -/
def empty_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : α ≃ empty :=
equiv_empty $ assume a, h ⟨a⟩
/-- If `α` is not `nonempty`, then it is equivalent to `pempty`. -/
def pempty_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : α ≃ pempty :=
equiv_pempty $ assume a, h ⟨a⟩
/-- The `Sort` of proofs of a true proposition is equivalent to `punit`. -/
def prop_equiv_punit {p : Prop} (h : p) : p ≃ punit :=
⟨λ x, (), λ x, h, λ _, rfl, λ ⟨⟩, rfl⟩
/-- `true` is equivalent to `punit`. -/
def true_equiv_punit : true ≃ punit := prop_equiv_punit trivial
/-- `ulift α` is equivalent to `α`. -/
protected def ulift {α : Type v} : ulift.{u} α ≃ α :=
⟨ulift.down, ulift.up, ulift.up_down, λ a, rfl⟩
@[simp] lemma coe_ulift {α : Type v} : ⇑(@equiv.ulift.{u} α) = ulift.down := rfl
@[simp] lemma coe_ulift_symm {α : Type v} : ⇑(@equiv.ulift.{u} α).symm = ulift.up := rfl
/-- `plift α` is equivalent to `α`. -/
protected def plift : plift α ≃ α :=
⟨plift.down, plift.up, plift.up_down, plift.down_up⟩
@[simp] lemma coe_plift : ⇑(@equiv.plift α) = plift.down := rfl
@[simp] lemma coe_plift_symm : ⇑(@equiv.plift α).symm = plift.up := rfl
/-- equivalence of propositions is the same as iff -/
def of_iff {P Q : Prop} (h : P ↔ Q) : P ≃ Q :=
{ to_fun := h.mp,
inv_fun := h.mpr,
left_inv := λ x, rfl,
right_inv := λ y, rfl }
/-- If `α₁` is equivalent to `α₂` and `β₁` is equivalent to `β₂`, then the type of maps `α₁ → β₁`
is equivalent to the type of maps `α₂ → β₂`. -/
@[congr] def arrow_congr {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(α₁ → β₁) ≃ (α₂ → β₂) :=
{ to_fun := λ f, e₂.to_fun ∘ f ∘ e₁.inv_fun,
inv_fun := λ f, e₂.inv_fun ∘ f ∘ e₁.to_fun,
left_inv := λ f, funext $ λ x, by simp,
right_inv := λ f, funext $ λ x, by simp }
@[simp] lemma arrow_congr_apply {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂)
(f : α₁ → β₁) (x : α₂) :
arrow_congr e₁ e₂ f x = (e₂ $ f $ e₁.symm x) :=
rfl
lemma arrow_congr_comp {α₁ β₁ γ₁ α₂ β₂ γ₂ : Sort*}
(ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) (ec : γ₁ ≃ γ₂) (f : α₁ → β₁) (g : β₁ → γ₁) :
arrow_congr ea ec (g ∘ f) = (arrow_congr eb ec g) ∘ (arrow_congr ea eb f) :=
by { ext, simp only [comp, arrow_congr_apply, eb.symm_apply_apply] }
@[simp] lemma arrow_congr_refl {α β : Sort*} :
arrow_congr (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl
@[simp] lemma arrow_congr_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Sort*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') :=
rfl
@[simp] lemma arrow_congr_symm {α₁ β₁ α₂ β₂ : Sort*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm :=
rfl
/--
A version of `equiv.arrow_congr` in `Type`, rather than `Sort`.
The `equiv_rw` tactic is not able to use the default `Sort` level `equiv.arrow_congr`,
because Lean's universe rules will not unify `?l_1` with `imax (1 ?m_1)`.
-/
@[congr]
def arrow_congr' {α₁ β₁ α₂ β₂ : Type*} (hα : α₁ ≃ α₂) (hβ : β₁ ≃ β₂) : (α₁ → β₁) ≃ (α₂ → β₂) :=
equiv.arrow_congr hα hβ
@[simp] lemma arrow_congr'_apply {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂)
(f : α₁ → β₁) (x : α₂) :
arrow_congr' e₁ e₂ f x = (e₂ $ f $ e₁.symm x) :=
rfl
@[simp] lemma arrow_congr'_refl {α β : Type*} :
arrow_congr' (equiv.refl α) (equiv.refl β) = equiv.refl (α → β) := rfl
@[simp] lemma arrow_congr'_trans {α₁ β₁ α₂ β₂ α₃ β₃ : Type*}
(e₁ : α₁ ≃ α₂) (e₁' : β₁ ≃ β₂) (e₂ : α₂ ≃ α₃) (e₂' : β₂ ≃ β₃) :
arrow_congr' (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr' e₁ e₁').trans (arrow_congr' e₂ e₂') :=
rfl
@[simp] lemma arrow_congr'_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(arrow_congr' e₁ e₂).symm = arrow_congr' e₁.symm e₂.symm :=
rfl
/-- Conjugate a map `f : α → α` by an equivalence `α ≃ β`. -/
def conj (e : α ≃ β) : (α → α) ≃ (β → β) := arrow_congr e e
@[simp] lemma conj_apply (e : α ≃ β) (f : α → α) (x : β) :
e.conj f x = (e $ f $ e.symm x) :=
rfl
@[simp] lemma conj_refl : conj (equiv.refl α) = equiv.refl (α → α) := rfl
@[simp] lemma conj_symm (e : α ≃ β) : e.conj.symm = e.symm.conj := rfl
@[simp] lemma conj_trans (e₁ : α ≃ β) (e₂ : β ≃ γ) :
(e₁.trans e₂).conj = e₁.conj.trans e₂.conj :=
rfl
-- This should not be a simp lemma as long as `(∘)` is reducible:
-- when `(∘)` is reducible, Lean can unify `f₁ ∘ f₂` with any `g` using
-- `f₁ := g` and `f₂ := λ x, x`. This causes nontermination.
lemma conj_comp (e : α ≃ β) (f₁ f₂ : α → α) :
e.conj (f₁ ∘ f₂) = (e.conj f₁) ∘ (e.conj f₂) :=
by apply arrow_congr_comp
/-- `punit` sorts in any two universes are equivalent. -/
def punit_equiv_punit : punit.{v} ≃ punit.{w} :=
⟨λ _, punit.star, λ _, punit.star, λ u, by { cases u, refl }, λ u, by { cases u, reflexivity }⟩
section
/-- The sort of maps to `punit.{v}` is equivalent to `punit.{w}`. -/
def arrow_punit_equiv_punit (α : Sort*) : (α → punit.{v}) ≃ punit.{w} :=
⟨λ f, punit.star, λ u f, punit.star,
λ f, by { funext x, cases f x, refl }, λ u, by { cases u, reflexivity }⟩
/-- The sort of maps from `punit` is equivalent to the codomain. -/
def punit_arrow_equiv (α : Sort*) : (punit.{u} → α) ≃ α :=
⟨λ f, f punit.star, λ a u, a, λ f, by { ext ⟨⟩, refl }, λ u, rfl⟩
/-- The sort of maps from `empty` is equivalent to `punit`. -/
def empty_arrow_equiv_punit (α : Sort*) : (empty → α) ≃ punit.{u} :=
⟨λ f, punit.star, λ u e, e.rec _, λ f, funext $ λ x, x.rec _, λ u, by { cases u, refl }⟩
/-- The sort of maps from `pempty` is equivalent to `punit`. -/
def pempty_arrow_equiv_punit (α : Sort*) : (pempty → α) ≃ punit.{u} :=
⟨λ f, punit.star, λ u e, e.rec _, λ f, funext $ λ x, x.rec _, λ u, by { cases u, refl }⟩
/-- The sort of maps from `false` is equivalent to `punit`. -/
def false_arrow_equiv_punit (α : Sort*) : (false → α) ≃ punit.{u} :=
calc (false → α) ≃ (empty → α) : arrow_congr false_equiv_empty (equiv.refl _)
... ≃ punit : empty_arrow_equiv_punit _
end
/-- Product of two equivalences. If `α₁ ≃ α₂` and `β₁ ≃ β₂`, then `α₁ × β₁ ≃ α₂ × β₂`. -/
@[congr] def prod_congr {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) : α₁ × β₁ ≃ α₂ × β₂ :=
⟨prod.map e₁ e₂, prod.map e₁.symm e₂.symm, λ ⟨a, b⟩, by simp, λ ⟨a, b⟩, by simp⟩
@[simp] theorem coe_prod_congr {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
⇑(prod_congr e₁ e₂) = prod.map e₁ e₂ :=
rfl
@[simp] theorem prod_congr_symm {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) :
(prod_congr e₁ e₂).symm = prod_congr e₁.symm e₂.symm :=
rfl
/-- Type product is commutative up to an equivalence: `α × β ≃ β × α`. -/
def prod_comm (α β : Type*) : α × β ≃ β × α :=
⟨prod.swap, prod.swap, λ⟨a, b⟩, rfl, λ⟨a, b⟩, rfl⟩
@[simp] lemma coe_prod_comm (α β) : ⇑(prod_comm α β)= prod.swap := rfl
@[simp] lemma prod_comm_symm (α β) : (prod_comm α β).symm = prod_comm β α := rfl
/-- Type product is associative up to an equivalence. -/
def prod_assoc (α β γ : Sort*) : (α × β) × γ ≃ α × (β × γ) :=
⟨λ p, ⟨p.1.1, ⟨p.1.2, p.2⟩⟩, λp, ⟨⟨p.1, p.2.1⟩, p.2.2⟩, λ ⟨⟨a, b⟩, c⟩, rfl, λ ⟨a, ⟨b, c⟩⟩, rfl⟩
@[simp] theorem prod_assoc_apply {α β γ : Sort*} (p : (α × β) × γ) :
prod_assoc α β γ p = ⟨p.1.1, ⟨p.1.2, p.2⟩⟩ := rfl
@[simp] theorem prod_assoc_sym_apply {α β γ : Sort*} (p : α × (β × γ)) :
(prod_assoc α β γ).symm p = ⟨⟨p.1, p.2.1⟩, p.2.2⟩ := rfl
section
/-- `punit` is a right identity for type product up to an equivalence. -/
def prod_punit (α : Type*) : α × punit.{u+1} ≃ α :=
⟨λ p, p.1, λ a, (a, punit.star), λ ⟨_, punit.star⟩, rfl, λ a, rfl⟩
@[simp] theorem prod_punit_apply {α : Sort*} (a : α × punit.{u+1}) : prod_punit α a = a.1 := rfl
/-- `punit` is a left identity for type product up to an equivalence. -/
def punit_prod (α : Type*) : punit.{u+1} × α ≃ α :=
calc punit × α ≃ α × punit : prod_comm _ _
... ≃ α : prod_punit _
@[simp] theorem punit_prod_apply {α : Type*} (a : punit.{u+1} × α) : punit_prod α a = a.2 := rfl
/-- `empty` type is a right absorbing element for type product up to an equivalence. -/
def prod_empty (α : Type*) : α × empty ≃ empty :=
equiv_empty (λ ⟨_, e⟩, e.rec _)
/-- `empty` type is a left absorbing element for type product up to an equivalence. -/
def empty_prod (α : Type*) : empty × α ≃ empty :=
equiv_empty (λ ⟨e, _⟩, e.rec _)
/-- `pempty` type is a right absorbing element for type product up to an equivalence. -/
def prod_pempty (α : Type*) : α × pempty ≃ pempty :=
equiv_pempty (λ ⟨_, e⟩, e.rec _)
/-- `pempty` type is a left absorbing element for type product up to an equivalence. -/
def pempty_prod (α : Type*) : pempty × α ≃ pempty :=
equiv_pempty (λ ⟨e, _⟩, e.rec _)
end
section
open sum
/-- `psum` is equivalent to `sum`. -/
def psum_equiv_sum (α β : Type*) : psum α β ≃ α ⊕ β :=
⟨λ s, psum.cases_on s inl inr,
λ s, sum.cases_on s psum.inl psum.inr,
λ s, by cases s; refl,
λ s, by cases s; refl⟩
/-- If `α ≃ α'` and `β ≃ β'`, then `α ⊕ β ≃ α' ⊕ β'`. -/
def sum_congr {α₁ β₁ α₂ β₂ : Type*} (ea : α₁ ≃ α₂) (eb : β₁ ≃ β₂) : α₁ ⊕ β₁ ≃ α₂ ⊕ β₂ :=
⟨sum.map ea eb, sum.map ea.symm eb.symm, λ x, by simp, λ x, by simp⟩
@[simp] theorem sum_congr_apply {α₁ β₁ α₂ β₂ : Type*} (e₁ : α₁ ≃ α₂) (e₂ : β₁ ≃ β₂) (a : α₁ ⊕ β₁) :
sum_congr e₁ e₂ a = a.map e₁ e₂ :=
rfl
@[simp] lemma sum_congr_symm {α β γ δ : Type u} (e : α ≃ β) (f : γ ≃ δ) :
(equiv.sum_congr e f).symm = (equiv.sum_congr (e.symm) (f.symm)) :=
rfl
/-- `bool` is equivalent the sum of two `punit`s. -/
def bool_equiv_punit_sum_punit : bool ≃ punit.{u+1} ⊕ punit.{v+1} :=
⟨λ b, cond b (inr punit.star) (inl punit.star),
λ s, sum.rec_on s (λ_, ff) (λ_, tt),
λ b, by cases b; refl,
λ s, by rcases s with ⟨⟨⟩⟩ | ⟨⟨⟩⟩; refl⟩
/-- `Prop` is noncomputably equivalent to `bool`. -/
noncomputable def Prop_equiv_bool : Prop ≃ bool :=
⟨λ p, @to_bool p (classical.prop_decidable _),
λ b, b, λ p, by simp, λ b, by simp⟩
/-- Sum of types is commutative up to an equivalence. -/
def sum_comm (α β : Sort*) : α ⊕ β ≃ β ⊕ α :=
⟨sum.swap, sum.swap, sum.swap_swap, sum.swap_swap⟩
@[simp] lemma sum_comm_apply (α β) (a) : sum_comm α β a = a.swap := rfl
@[simp] lemma sum_comm_symm (α β) : (sum_comm α β).symm = sum_comm β α := rfl
/-- Sum of types is associative up to an equivalence. -/
def sum_assoc (α β γ : Sort*) : (α ⊕ β) ⊕ γ ≃ α ⊕ (β ⊕ γ) :=
⟨sum.elim (sum.elim sum.inl (sum.inr ∘ sum.inl)) (sum.inr ∘ sum.inr),
sum.elim (sum.inl ∘ sum.inl) $ sum.elim (sum.inl ∘ sum.inr) sum.inr,
by rintros (⟨_ | _⟩ | _); refl,
by rintros (_ | ⟨_ | _⟩); refl⟩
@[simp] theorem sum_assoc_apply_in1 {α β γ} (a) : sum_assoc α β γ (inl (inl a)) = inl a := rfl
@[simp] theorem sum_assoc_apply_in2 {α β γ} (b) : sum_assoc α β γ (inl (inr b)) = inr (inl b) := rfl
@[simp] theorem sum_assoc_apply_in3 {α β γ} (c) : sum_assoc α β γ (inr c) = inr (inr c) := rfl
/-- Sum with `empty` is equivalent to the original type. -/
def sum_empty (α : Type*) : α ⊕ empty ≃ α :=
⟨sum.elim id (empty.rec _),
inl,
λ s, by { rcases s with _ | ⟨⟨⟩⟩, refl },
λ a, rfl⟩
@[simp] lemma sum_empty_apply_inl {α} (a) : sum_empty α (sum.inl a) = a := rfl
/-- The sum of `empty` with any `Sort*` is equivalent to the right summand. -/
def empty_sum (α : Sort*) : empty ⊕ α ≃ α :=
(sum_comm _ _).trans $ sum_empty _
@[simp] lemma empty_sum_apply_inr {α} (a) : empty_sum α (sum.inr a) = a := rfl
/-- Sum with `pempty` is equivalent to the original type. -/
def sum_pempty (α : Type*) : α ⊕ pempty ≃ α :=
⟨sum.elim id (pempty.rec _),
inl,
λ s, by { rcases s with _ | ⟨⟨⟩⟩, refl },
λ a, rfl⟩
@[simp] lemma sum_pempty_apply_inl {α} (a) : sum_pempty α (sum.inl a) = a := rfl
/-- The sum of `pempty` with any `Sort*` is equivalent to the right summand. -/
def pempty_sum (α : Sort*) : pempty ⊕ α ≃ α :=
(sum_comm _ _).trans $ sum_pempty _
@[simp] lemma pempty_sum_apply_inr {α} (a) : pempty_sum α (sum.inr a) = a := rfl
/-- `option α` is equivalent to `α ⊕ punit` -/
def option_equiv_sum_punit (α : Sort*) : option α ≃ α ⊕ punit.{u+1} :=
⟨λ o, match o with none := inr punit.star | some a := inl a end,
λ s, match s with inr _ := none | inl a := some a end,
λ o, by cases o; refl,
λ s, by rcases s with _ | ⟨⟨⟩⟩; refl⟩
@[simp] lemma option_equiv_sum_punit_none {α} : option_equiv_sum_punit α none = sum.inr () := rfl
@[simp] lemma option_equiv_sum_punit_some {α} (a) :
option_equiv_sum_punit α (some a) = sum.inl a := rfl
/-- The set of `x : option α` such that `is_some x` is equivalent to `α`. -/
def option_is_some_equiv (α : Type*) : {x : option α // x.is_some} ≃ α :=
{ to_fun := λ o, option.get o.2,
inv_fun := λ x, ⟨some x, dec_trivial⟩,
left_inv := λ o, subtype.eq $ option.some_get _,
right_inv := λ x, option.get_some _ _ }
/-- `α ⊕ β` is equivalent to a `sigma`-type over `bool`. -/
def sum_equiv_sigma_bool (α β : Sort*) : α ⊕ β ≃ (Σ b: bool, cond b α β) :=
⟨λ s, match s with inl a := ⟨tt, a⟩ | inr b := ⟨ff, b⟩ end,
λ s, match s with ⟨tt, a⟩ := inl a | ⟨ff, b⟩ := inr b end,
λ s, by cases s; refl,
λ s, by rcases s with ⟨_|_, _⟩; refl⟩
/-- `sigma_preimage_equiv f` for `f : α → β` is the natural equivalence between
the type of all fibres of `f` and the total space `α`. -/
def sigma_preimage_equiv {α β : Type*} (f : α → β) :
(Σ y : β, {x // f x = y}) ≃ α :=
⟨λ x, x.2.1, λ x, ⟨f x, x, rfl⟩, λ ⟨y, x, rfl⟩, rfl, λ x, rfl⟩
@[simp] lemma sigma_preimage_equiv_apply {α β : Type*} (f : α → β)
(x : Σ y : β, {x // f x = y}) :
(sigma_preimage_equiv f) x = x.2.1 := rfl
@[simp] lemma sigma_preimage_equiv_symm_apply_fst {α β : Type*} (f : α → β) (a : α) :
((sigma_preimage_equiv f).symm a).1 = f a := rfl
@[simp] lemma sigma_preimage_equiv_symm_apply_snd_fst {α β : Type*} (f : α → β) (a : α) :
((sigma_preimage_equiv f).symm a).2.1 = a := rfl
end
section sum_compl
/-- For any predicate `p` on `α`,
the sum of the two subtypes `{a // p a}` and its complement `{a // ¬ p a}`
is naturally equivalent to `α`. -/
def sum_compl {α : Type*} (p : α → Prop) [decidable_pred p] :
{a // p a} ⊕ {a // ¬ p a} ≃ α :=
{ to_fun := sum.elim coe coe,
inv_fun := λ a, if h : p a then sum.inl ⟨a, h⟩ else sum.inr ⟨a, h⟩,
left_inv := by { rintros (⟨x,hx⟩|⟨x,hx⟩); dsimp; [rw dif_pos, rw dif_neg], },
right_inv := λ a, by { dsimp, split_ifs; refl } }
@[simp] lemma sum_compl_apply_inl {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // p a}) :
sum_compl p (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {α : Type*} (p : α → Prop) [decidable_pred p]
(x : {a // ¬ p a}) :
sum_compl p (sum.inr x) = x := rfl
@[simp] lemma sum_compl_apply_symm_of_pos {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : p a) :
(sum_compl p).symm a = sum.inl ⟨a, h⟩ := dif_pos h
@[simp] lemma sum_compl_apply_symm_of_neg {α : Type*} (p : α → Prop) [decidable_pred p]
(a : α) (h : ¬ p a) :
(sum_compl p).symm a = sum.inr ⟨a, h⟩ := dif_neg h
end sum_compl
section subtype_preimage
variables (p : α → Prop) [decidable_pred p] (x₀ : {a // p a} → β)
/-- For a fixed function `x₀ : {a // p a} → β` defined on a subtype of `α`,
the subtype of functions `x : α → β` that agree with `x₀` on the subtype `{a // p a}`
is naturally equivalent to the type of functions `{a // ¬ p a} → β`. -/
def subtype_preimage :
{x : α → β // x ∘ coe = x₀} ≃ ({a // ¬ p a} → β) :=
{ to_fun := λ (x : {x : α → β // x ∘ coe = x₀}) a, (x : α → β) a,
inv_fun := λ x, ⟨λ a, if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩,
funext $ λ ⟨a, h⟩, dif_pos h⟩,
left_inv := λ ⟨x, hx⟩, subtype.val_injective $ funext $ λ a,
(by { dsimp, split_ifs; [ rw ← hx, skip ]; refl }),
right_inv := λ x, funext $ λ ⟨a, h⟩,
show dite (p a) _ _ = _, by { dsimp, rw [dif_neg h] } }
@[simp] lemma subtype_preimage_apply (x : {x : α → β // x ∘ coe = x₀}) :
subtype_preimage p x₀ x = λ a, (x : α → β) a := rfl
@[simp] lemma subtype_preimage_symm_apply_coe (x : {a // ¬ p a} → β) :
((subtype_preimage p x₀).symm x : α → β) =
λ a, if h : p a then x₀ ⟨a, h⟩ else x ⟨a, h⟩ := rfl
lemma subtype_preimage_symm_apply_coe_pos (x : {a // ¬ p a} → β) (a : α) (h : p a) :
((subtype_preimage p x₀).symm x : α → β) a = x₀ ⟨a, h⟩ :=
dif_pos h
lemma subtype_preimage_symm_apply_coe_neg (x : {a // ¬ p a} → β) (a : α) (h : ¬ p a) :
((subtype_preimage p x₀).symm x : α → β) a = x ⟨a, h⟩ :=
dif_neg h
end subtype_preimage
section fun_unique
variables (α β) [unique α]
/-- If `α` has a unique term, then the type of function `α → β` is equivalent to `β`. -/
def fun_unique : (α → β) ≃ β :=
{ to_fun := λ f, f (default α),
inv_fun := λ b a, b,
left_inv := λ f, funext $ λ a, congr_arg f $ subsingleton.elim _ _,
right_inv := λ b, rfl }
variables {α β}
@[simp] lemma fun_unique_apply (f : α → β) :
fun_unique α β f = f (default α) := rfl
@[simp] lemma fun_unique_symm_apply (b : β) (a : α) :
(fun_unique α β).symm b a = b := rfl
end fun_unique
section
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Π a, β₁ a` and
`Π a, β₂ a`. -/
def Pi_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Π a, β₁ a) ≃ (Π a, β₂ a) :=
⟨λ H a, F a (H a), λ H a, (F a).symm (H a),
λ H, funext $ by simp, λ H, funext $ by simp⟩
/-- Dependent `curry` equivalence: the type of dependent functions on `Σ i, β i` is equivalent
to the type of dependent functions of two arguments (i.e., functions to the space of functions). -/
def Pi_curry {α} {β : α → Sort*} (γ : Π a, β a → Sort*) :
(Π x : Σ i, β i, γ x.1 x.2) ≃ (Π a b, γ a b) :=
{ to_fun := λ f x y, f ⟨x,y⟩,
inv_fun := λ f x, f x.1 x.2,
left_inv := λ f, funext $ λ ⟨x,y⟩, rfl,
right_inv := λ f, funext $ λ x, funext $ λ y, rfl }
end
section
/-- A `psigma`-type is equivalent to the corresponding `sigma`-type. -/
def psigma_equiv_sigma {α} (β : α → Sort*) : (Σ' i, β i) ≃ Σ i, β i :=
⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
@[simp] lemma psigma_equiv_sigma_apply {α} (β : α → Sort*) (x) :
psigma_equiv_sigma β x = ⟨x.1, x.2⟩ :=
rfl
@[simp] lemma psigma_equiv_sigma_symm_apply {α} (β : α → Sort*) (x) :
(psigma_equiv_sigma β).symm x = ⟨x.1, x.2⟩ :=
rfl
/-- A family of equivalences `Π a, β₁ a ≃ β₂ a` generates an equivalence between `Σ a, β₁ a` and
`Σ a, β₂ a`. -/
def sigma_congr_right {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) : (Σ a, β₁ a) ≃ Σ a, β₂ a :=
⟨λ a, ⟨a.1, F a.1 a.2⟩, λ a, ⟨a.1, (F a.1).symm a.2⟩,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ symm_apply_apply (F a) b,
λ ⟨a, b⟩, congr_arg (sigma.mk a) $ apply_symm_apply (F a) b⟩
@[simp] lemma sigma_congr_right_apply {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) (x) :
sigma_congr_right F x = ⟨x.1, F x.1 x.2⟩ :=
rfl
@[simp] lemma sigma_congr_right_symm_apply {α} {β₁ β₂ : α → Sort*} (F : Π a, β₁ a ≃ β₂ a) (x) :
(sigma_congr_right F).symm x = ⟨x.1, (F x.1).symm x.2⟩ :=
rfl
/-- An equivalence `f : α₁ ≃ α₂` generates an equivalence between `Σ a, β (f a)` and `Σ a, β a`. -/
def sigma_congr_left {α₁ α₂} {β : α₂ → Sort*} (e : α₁ ≃ α₂) : (Σ a:α₁, β (e a)) ≃ (Σ a:α₂, β a) :=
⟨λ a, ⟨e a.1, a.2⟩, λ a, ⟨e.symm a.1, @@eq.rec β a.2 (e.right_inv a.1).symm⟩,
λ ⟨a, b⟩, match e.symm (e a), e.left_inv a : ∀ a' (h : a' = a),
@sigma.mk _ (β ∘ e) _ (@@eq.rec β b (congr_arg e h.symm)) = ⟨a, b⟩ with
| _, rfl := rfl end,
λ ⟨a, b⟩, match e (e.symm a), _ : ∀ a' (h : a' = a), sigma.mk a' (@@eq.rec β b h.symm) = ⟨a, b⟩ with
| _, rfl := rfl end⟩
@[simp] lemma sigma_congr_left_apply {α₁ α₂} {β : α₂ → Sort*} (e : α₁ ≃ α₂) (x : Σ a, β (e a)) :
sigma_congr_left e x = ⟨e x.1, x.2⟩ :=
rfl
/-- Transporting a sigma type through an equivalence of the base -/
def sigma_congr_left' {α₁ α₂} {β : α₁ → Sort*} (f : α₁ ≃ α₂) :
(Σ a:α₁, β a) ≃ (Σ a:α₂, β (f.symm a)) :=
(sigma_congr_left f.symm).symm
/-- Transporting a sigma type through an equivalence of the base and a family of equivalences
of matching fibers -/
def sigma_congr {α₁ α₂} {β₁ : α₁ → Sort*} {β₂ : α₂ → Sort*} (f : α₁ ≃ α₂)
(F : ∀ a, β₁ a ≃ β₂ (f a)) :
sigma β₁ ≃ sigma β₂ :=
(sigma_congr_right F).trans (sigma_congr_left f)
/-- `sigma` type with a constant fiber is equivalent to the product. -/
def sigma_equiv_prod (α β : Type*) : (Σ_:α, β) ≃ α × β :=
⟨λ a, ⟨a.1, a.2⟩, λ a, ⟨a.1, a.2⟩, λ ⟨a, b⟩, rfl, λ ⟨a, b⟩, rfl⟩
@[simp] lemma sigma_equiv_prod_apply {α β : Type*} (x : Σ _:α, β) :
sigma_equiv_prod α β x = ⟨x.1, x.2⟩ :=
rfl
@[simp] lemma sigma_equiv_prod_symm_apply {α β : Type*} (x : α × β) :
(sigma_equiv_prod α β).symm x = ⟨x.1, x.2⟩ :=
rfl
/-- If each fiber of a `sigma` type is equivalent to a fixed type, then the sigma type
is equivalent to the product. -/
def sigma_equiv_prod_of_equiv {α β} {β₁ : α → Sort*} (F : Π a, β₁ a ≃ β) : sigma β₁ ≃ α × β :=
(sigma_congr_right F).trans (sigma_equiv_prod α β)
end
section
/-- The type of functions to a product `α × β` is equivalent to the type of pairs of functions
`γ → α` and `γ → β`. -/
def arrow_prod_equiv_prod_arrow (α β γ : Type*) : (γ → α × β) ≃ (γ → α) × (γ → β) :=
⟨λ f, (λ c, (f c).1, λ c, (f c).2),
λ p c, (p.1 c, p.2 c),
λ f, funext $ λ c, prod.mk.eta,
λ p, by { cases p, refl }⟩
/-- Functions `α → β → γ` are equivalent to functions on `α × β`. -/
def arrow_arrow_equiv_prod_arrow (α β γ : Sort*) : (α → β → γ) ≃ (α × β → γ) :=
⟨uncurry, curry, curry_uncurry, uncurry_curry⟩
open sum
/-- The type of functions on a sum type `α ⊕ β` is equivalent to the type of pairs of functions
on `α` and on `β`. -/
def sum_arrow_equiv_prod_arrow (α β γ : Type*) : ((α ⊕ β) → γ) ≃ (α → γ) × (β → γ) :=
⟨λ f, (f ∘ inl, f ∘ inr),
λ p, sum.elim p.1 p.2,
λ f, by { ext ⟨⟩; refl },
λ p, by { cases p, refl }⟩
/-- Type product is right distributive with respect to type sum up to an equivalence. -/
def sum_prod_distrib (α β γ : Sort*) : (α ⊕ β) × γ ≃ (α × γ) ⊕ (β × γ) :=
⟨λ p, match p with (inl a, c) := inl (a, c) | (inr b, c) := inr (b, c) end,
λ s, match s with inl q := (inl q.1, q.2) | inr q := (inr q.1, q.2) end,
λ p, by rcases p with ⟨_ | _, _⟩; refl,
λ s, by rcases s with ⟨_, _⟩ | ⟨_, _⟩; refl⟩
@[simp] theorem sum_prod_distrib_apply_left {α β γ} (a : α) (c : γ) :
sum_prod_distrib α β γ (sum.inl a, c) = sum.inl (a, c) := rfl
@[simp] theorem sum_prod_distrib_apply_right {α β γ} (b : β) (c : γ) :
sum_prod_distrib α β γ (sum.inr b, c) = sum.inr (b, c) := rfl
/-- Type product is left distributive with respect to type sum up to an equivalence. -/
def prod_sum_distrib (α β γ : Sort*) : α × (β ⊕ γ) ≃ (α × β) ⊕ (α × γ) :=
calc α × (β ⊕ γ) ≃ (β ⊕ γ) × α : prod_comm _ _
... ≃ (β × α) ⊕ (γ × α) : sum_prod_distrib _ _ _
... ≃ (α × β) ⊕ (α × γ) : sum_congr (prod_comm _ _) (prod_comm _ _)
@[simp] theorem prod_sum_distrib_apply_left {α β γ} (a : α) (b : β) :
prod_sum_distrib α β γ (a, sum.inl b) = sum.inl (a, b) := rfl
@[simp] theorem prod_sum_distrib_apply_right {α β γ} (a : α) (c : γ) :
prod_sum_distrib α β γ (a, sum.inr c) = sum.inr (a, c) := rfl
/-- The product of an indexed sum of types (formally, a `sigma`-type `Σ i, α i`) by a type `β` is
equivalent to the sum of products `Σ i, (α i × β)`. -/
def sigma_prod_distrib {ι : Type*} (α : ι → Type*) (β : Type*) :
((Σ i, α i) × β) ≃ (Σ i, (α i × β)) :=
⟨λ p, ⟨p.1.1, (p.1.2, p.2)⟩,
λ p, (⟨p.1, p.2.1⟩, p.2.2),
λ p, by { rcases p with ⟨⟨_, _⟩, _⟩, refl },
λ p, by { rcases p with ⟨_, ⟨_, _⟩⟩, refl }⟩
/-- The product `bool × α` is equivalent to `α ⊕ α`. -/
def bool_prod_equiv_sum (α : Type u) : bool × α ≃ α ⊕ α :=
calc bool × α ≃ (unit ⊕ unit) × α : prod_congr bool_equiv_punit_sum_punit (equiv.refl _)
... ≃ (unit × α) ⊕ (unit × α) : sum_prod_distrib _ _ _
... ≃ α ⊕ α : sum_congr (punit_prod _) (punit_prod _)
end
section
open sum nat
/-- The set of natural numbers is equivalent to `ℕ ⊕ punit`. -/
def nat_equiv_nat_sum_punit : ℕ ≃ ℕ ⊕ punit.{u+1} :=
⟨λ n, match n with zero := inr punit.star | succ a := inl a end,
λ s, match s with inl n := succ n | inr punit.star := zero end,
λ n, begin cases n, repeat { refl } end,
λ s, begin cases s with a u, { refl }, {cases u, { refl }} end⟩
/-- `ℕ ⊕ punit` is equivalent to `ℕ`. -/
def nat_sum_punit_equiv_nat : ℕ ⊕ punit.{u+1} ≃ ℕ :=
nat_equiv_nat_sum_punit.symm
/-- The type of integer numbers is equivalent to `ℕ ⊕ ℕ`. -/
def int_equiv_nat_sum_nat : ℤ ≃ ℕ ⊕ ℕ :=
by refine ⟨_, _, _, _⟩; intro z; {cases z; [left, right]; assumption} <|> {cases z; refl}
end
/-- An equivalence between `α` and `β` generates an equivalence between `list α` and `list β`. -/
def list_equiv_of_equiv {α β : Type*} (e : α ≃ β) : list α ≃ list β :=
{ to_fun := list.map e,
inv_fun := list.map e.symm,
left_inv := λ l, by rw [list.map_map, e.symm_comp_self, list.map_id],
right_inv := λ l, by rw [list.map_map, e.self_comp_symm, list.map_id] }
/-- `fin n` is equivalent to `{m // m < n}`. -/
def fin_equiv_subtype (n : ℕ) : fin n ≃ {m // m < n} :=
⟨λ x, ⟨x.1, x.2⟩, λ x, ⟨x.1, x.2⟩, λ ⟨a, b⟩, rfl,λ ⟨a, b⟩, rfl⟩
/-- If `α` is equivalent to `β`, then `unique α` is equivalent to `β`. -/
def unique_congr (e : α ≃ β) : unique α ≃ unique β :=
{ to_fun := λ h, @equiv.unique _ _ h e.symm,
inv_fun := λ h, @equiv.unique _ _ h e,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
section
open subtype
/-- If `α` is equivalent to `β` and the predicates `p : α → Prop` and `q : β → Prop` are equivalent
at corresponding points, then `{a // p a}` is equivalent to `{b // q b}`. -/
def subtype_congr {p : α → Prop} {q : β → Prop}
(e : α ≃ β) (h : ∀ a, p a ↔ q (e a)) : {a : α // p a} ≃ {b : β // q b} :=
⟨λ x, ⟨e x.1, (h _).1 x.2⟩,
λ y, ⟨e.symm y.1, (h _).2 (by { simp, exact y.2 })⟩,
λ ⟨x, h⟩, subtype.ext_val $ by simp,
λ ⟨y, h⟩, subtype.ext_val $ by simp⟩
/-- If two predicates `p` and `q` are pointwise equivalent, then `{x // p x}` is equivalent to
`{x // q x}`. -/
def subtype_congr_right {p q : α → Prop} (e : ∀x, p x ↔ q x) : {x // p x} ≃ {x // q x} :=
subtype_congr (equiv.refl _) e
@[simp] lemma subtype_congr_right_mk {p q : α → Prop} (e : ∀x, p x ↔ q x)
{x : α} (h : p x) : subtype_congr_right e ⟨x, h⟩ = ⟨x, (e x).1 h⟩ := rfl
/-- If `α ≃ β`, then for any predicate `p : β → Prop` the subtype `{a // p (e a)}` is equivalent
to the subtype `{b // p b}`. -/
def subtype_equiv_of_subtype {p : β → Prop} (e : α ≃ β) :
{a : α // p (e a)} ≃ {b : β // p b} :=
subtype_congr e $ by simp
/-- If `α ≃ β`, then for any predicate `p : α → Prop` the subtype `{a // p a}` is equivalent
to the subtype `{b // p (e.symm b)}`. This version is used by `equiv_rw`. -/
def subtype_equiv_of_subtype' {p : α → Prop} (e : α ≃ β) :
{a : α // p a} ≃ {b : β // p (e.symm b)} :=
e.symm.subtype_equiv_of_subtype.symm
/-- If two predicates are equal, then the corresponding subtypes are equivalent. -/
def subtype_congr_prop {α : Type*} {p q : α → Prop} (h : p = q) : subtype p ≃ subtype q :=
subtype_congr (equiv.refl α) (assume a, h ▸ iff.rfl)
/-- The subtypes corresponding to equal sets are equivalent. -/
def set_congr {α : Type*} {s t : set α} (h : s = t) : s ≃ t :=
subtype_congr_prop h
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. This
version allows the “inner” predicate to depend on `h : p a`. -/
def subtype_subtype_equiv_subtype_exists {α : Type u} (p : α → Prop) (q : subtype p → Prop) :
subtype q ≃ {a : α // ∃h:p a, q ⟨a, h⟩ } :=
⟨λ⟨⟨a, ha⟩, ha'⟩, ⟨a, ha, ha'⟩,
λ⟨a, ha⟩, ⟨⟨a, ha.cases_on $ assume h _, h⟩, by { cases ha, exact ha_h }⟩,
assume ⟨⟨a, ha⟩, h⟩, rfl, assume ⟨a, h₁, h₂⟩, rfl⟩
/-- A subtype of a subtype is equivalent to the subtype of elements satisfying both predicates. -/
def subtype_subtype_equiv_subtype_inter {α : Type u} (p q : α → Prop) :
{x : subtype p // q x.1} ≃ subtype (λ x, p x ∧ q x) :=
(subtype_subtype_equiv_subtype_exists p _).trans $
subtype_congr_right $ λ x, exists_prop
/-- If the outer subtype has more restrictive predicate than the inner one,
then we can drop the latter. -/
def subtype_subtype_equiv_subtype {α : Type u} {p q : α → Prop} (h : ∀ {x}, q x → p x) :
{x : subtype p // q x.1} ≃ subtype q :=
(subtype_subtype_equiv_subtype_inter p _).trans $
subtype_congr_right $
assume x,
⟨and.right, λ h₁, ⟨h h₁, h₁⟩⟩
/-- If a proposition holds for all elements, then the subtype is
equivalent to the original type. -/
def subtype_univ_equiv {α : Type u} {p : α → Prop} (h : ∀ x, p x) :
subtype p ≃ α :=
⟨λ x, x, λ x, ⟨x, h x⟩, λ x, subtype.eq rfl, λ x, rfl⟩
/-- A subtype of a sigma-type is a sigma-type over a subtype. -/
def subtype_sigma_equiv {α : Type u} (p : α → Type v) (q : α → Prop) :
{ y : sigma p // q y.1 } ≃ Σ(x : subtype q), p x.1 :=
⟨λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ x, ⟨⟨x.1.1, x.2⟩, x.1.2⟩,
λ ⟨⟨x, h⟩, y⟩, rfl,
λ ⟨⟨x, y⟩, h⟩, rfl⟩
/-- A sigma type over a subtype is equivalent to the sigma set over the original type,
if the fiber is empty outside of the subset -/
def sigma_subtype_equiv_of_subset {α : Type u} (p : α → Type v) (q : α → Prop)
(h : ∀ x, p x → q x) :
(Σ x : subtype q, p x) ≃ Σ x : α, p x :=
(subtype_sigma_equiv p q).symm.trans $ subtype_univ_equiv $ λ x, h x.1 x.2
/-- If a predicate `p : β → Prop` is true on the range of a map `f : α → β`, then
`Σ y : {y // p y}, {x // f x = y}` is equivalent to `α`. -/
def sigma_subtype_preimage_equiv {α : Type u} {β : Type v} (f : α → β) (p : β → Prop)
(h : ∀ x, p (f x)) :
(Σ y : subtype p, {x : α // f x = y}) ≃ α :=
calc _ ≃ Σ y : β, {x : α // f x = y} : sigma_subtype_equiv_of_subset _ p (λ y ⟨x, h'⟩, h' ▸ h x)
... ≃ α : sigma_preimage_equiv f
/-- If for each `x` we have `p x ↔ q (f x)`, then `Σ y : {y // q y}, f ⁻¹' {y}` is equivalent
to `{x // p x}`. -/
def sigma_subtype_preimage_equiv_subtype {α : Type u} {β : Type v} (f : α → β)
{p : α → Prop} {q : β → Prop} (h : ∀ x, p x ↔ q (f x)) :
(Σ y : subtype q, {x : α // f x = y}) ≃ subtype p :=
calc (Σ y : subtype q, {x : α // f x = y}) ≃
Σ y : subtype q, {x : subtype p // subtype.mk (f x) ((h x).1 x.2) = y} :
begin
apply sigma_congr_right,
assume y,
symmetry,
refine (subtype_subtype_equiv_subtype_exists _ _).trans (subtype_congr_right _),
assume x,
exact ⟨λ ⟨hp, h'⟩, congr_arg subtype.val h', λ h', ⟨(h x).2 (h'.symm ▸ y.2), subtype.eq h'⟩⟩
end
... ≃ subtype p : sigma_preimage_equiv (λ x : subtype p, (⟨f x, (h x).1 x.property⟩ : subtype q))
/-- The `pi`-type `Π i, π i` is equivalent to the type of sections `f : ι → Σ i, π i` of the
`sigma` type such that for all `i` we have `(f i).fst = i`. -/
def pi_equiv_subtype_sigma (ι : Type*) (π : ι → Type*) :
(Πi, π i) ≃ {f : ι → Σi, π i | ∀i, (f i).1 = i } :=
⟨ λf, ⟨λi, ⟨i, f i⟩, assume i, rfl⟩, λf i, begin rw ← f.2 i, exact (f.1 i).2 end,
assume f, funext $ assume i, rfl,
assume ⟨f, hf⟩, subtype.eq $ funext $ assume i, sigma.eq (hf i).symm $
eq_of_heq $ rec_heq_of_heq _ $ rec_heq_of_heq _ $ heq.refl _⟩
/-- The set of functions `f : Π a, β a` such that for all `a` we have `p a (f a)` is equivalent
to the set of functions `Π a, {b : β a // p a b}`. -/
def subtype_pi_equiv_pi {α : Sort u} {β : α → Sort v} {p : Πa, β a → Prop} :
{f : Πa, β a // ∀a, p a (f a) } ≃ Πa, { b : β a // p a b } :=
⟨λf a, ⟨f.1 a, f.2 a⟩, λf, ⟨λa, (f a).1, λa, (f a).2⟩,
by { rintro ⟨f, h⟩, refl },
by { rintro f, funext a, exact subtype.ext_val rfl }⟩
/-- A subtype of a product defined by componentwise conditions
is equivalent to a product of subtypes. -/
def subtype_prod_equiv_prod {α : Type u} {β : Type v} {p : α → Prop} {q : β → Prop} :
{c : α × β // p c.1 ∧ q c.2} ≃ ({a // p a} × {b // q b}) :=
⟨λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ x, ⟨⟨x.1.1, x.2.1⟩, ⟨x.1.2, x.2.2⟩⟩,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl,
λ ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl⟩
end
section subtype_equiv_codomain
variables {X : Type*} {Y : Type*} [decidable_eq X] {x : X}
/-- The type of all functions `X → Y` with prescribed values for all `x' ≠ x`
is equivalent to the codomain `Y`. -/
def subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) : {g : X → Y // g ∘ coe = f} ≃ Y :=
(subtype_preimage _ f).trans $
@fun_unique {x' // ¬ x' ≠ x} _ $
show unique {x' // ¬ x' ≠ x}, from @equiv.unique _ _
(show unique {x' // x' = x}, from
{ default := ⟨x, rfl⟩, uniq := λ ⟨x', h⟩, subtype.val_injective h })
(subtype_congr_right $ λ a, not_not)
@[simp] lemma coe_subtype_equiv_codomain (f : {x' // x' ≠ x} → Y) :
(subtype_equiv_codomain f : {g : X → Y // g ∘ coe = f} → Y) = λ g, (g : X → Y) x := rfl
@[simp] lemma subtype_equiv_codomain_apply (f : {x' // x' ≠ x} → Y)
(g : {g : X → Y // g ∘ coe = f}) :
subtype_equiv_codomain f g = (g : X → Y) x := rfl
lemma coe_subtype_equiv_codomain_symm (f : {x' // x' ≠ x} → Y) :
((subtype_equiv_codomain f).symm : Y → {g : X → Y // g ∘ coe = f}) =
λ y, ⟨λ x', if h : x' ≠ x then f ⟨x', h⟩ else y,
by { funext x', dsimp, erw [dif_pos x'.2, subtype.coe_eta] }⟩ := rfl
@[simp] lemma subtype_equiv_codomain_symm_apply (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) :
((subtype_equiv_codomain f).symm y : X → Y) x' = if h : x' ≠ x then f ⟨x', h⟩ else y :=
rfl
@[simp] lemma subtype_equiv_codomain_symm_apply_eq (f : {x' // x' ≠ x} → Y) (y : Y) :
((subtype_equiv_codomain f).symm y : X → Y) x = y :=
dif_neg (not_not.mpr rfl)
lemma subtype_equiv_codomain_symm_apply_ne (f : {x' // x' ≠ x} → Y) (y : Y) (x' : X) (h : x' ≠ x) :
((subtype_equiv_codomain f).symm y : X → Y) x' = f ⟨x', h⟩ :=
dif_pos h
end subtype_equiv_codomain
namespace set
open set
/-- `univ α` is equivalent to `α`. -/
protected def univ (α) : @univ α ≃ α :=
⟨subtype.val, λ a, ⟨a, trivial⟩, λ ⟨a, _⟩, rfl, λ a, rfl⟩
@[simp] lemma univ_apply {α : Type u} (x : @univ α) :
equiv.set.univ α x = x := rfl
@[simp] lemma univ_symm_apply {α : Type u} (x : α) :
(equiv.set.univ α).symm x = ⟨x, trivial⟩ := rfl
/-- An empty set is equivalent to the `empty` type. -/
protected def empty (α) : (∅ : set α) ≃ empty :=
equiv_empty $ λ ⟨x, h⟩, not_mem_empty x h
/-- An empty set is equivalent to a `pempty` type. -/
protected def pempty (α) : (∅ : set α) ≃ pempty :=
equiv_pempty $ λ ⟨x, h⟩, not_mem_empty x h
/-- If sets `s` and `t` are separated by a decidable predicate, then `s ∪ t` is equivalent to
`s ⊕ t`. -/
protected def union' {α} {s t : set α}
(p : α → Prop) [decidable_pred p]
(hs : ∀ x ∈ s, p x)
(ht : ∀ x ∈ t, ¬ p x) : (s ∪ t : set α) ≃ s ⊕ t :=
{ to_fun := λ x, if hp : p x
then sum.inl ⟨_, x.2.resolve_right (λ xt, ht _ xt hp)⟩
else sum.inr ⟨_, x.2.resolve_left (λ xs, hp (hs _ xs))⟩,
inv_fun := λ o, match o with
| (sum.inl x) := ⟨x, or.inl x.2⟩
| (sum.inr x) := ⟨x, or.inr x.2⟩
end,
left_inv := λ ⟨x, h'⟩, by by_cases p x; simp [union'._match_1, h]; congr,
right_inv := λ o, begin
rcases o with ⟨x, h⟩ | ⟨x, h⟩;
dsimp [union'._match_1];
[simp [hs _ h], simp [ht _ h]]
end }
/-- If sets `s` and `t` are disjoint, then `s ∪ t` is equivalent to `s ⊕ t`. -/
protected def union {α} {s t : set α} [decidable_pred (λ x, x ∈ s)] (H : s ∩ t ⊆ ∅) :
(s ∪ t : set α) ≃ s ⊕ t :=
set.union' (λ x, x ∈ s) (λ _, id) (λ x xt xs, H ⟨xs, xt⟩)
lemma union_apply_left {α} {s t : set α} [decidable_pred (λ x, x ∈ s)] (H : s ∩ t ⊆ ∅)
{a : (s ∪ t : set α)} (ha : ↑a ∈ s) : equiv.set.union H a = sum.inl ⟨a, ha⟩ :=
dif_pos ha
lemma union_apply_right {α} {s t : set α} [decidable_pred (λ x, x ∈ s)] (H : s ∩ t ⊆ ∅)
{a : (s ∪ t : set α)} (ha : ↑a ∈ t) : equiv.set.union H a = sum.inr ⟨a, ha⟩ :=
dif_neg $ λ h, H ⟨h, ha⟩
-- TODO: Any reason to use the same universe?
/-- A singleton set is equivalent to a `punit` type. -/
protected def singleton {α} (a : α) : ({a} : set α) ≃ punit.{u} :=
⟨λ _, punit.star, λ _, ⟨a, mem_singleton _⟩,
λ ⟨x, h⟩, by { simp at h, subst x },
λ ⟨⟩, rfl⟩
/-- Equal sets are equivalent. -/
protected def of_eq {α : Type u} {s t : set α} (h : s = t) : s ≃ t :=
{ to_fun := λ x, ⟨x.1, h ▸ x.2⟩,
inv_fun := λ x, ⟨x.1, h.symm ▸ x.2⟩,
left_inv := λ _, subtype.eq rfl,
right_inv := λ _, subtype.eq rfl }
@[simp] lemma of_eq_apply {α : Type u} {s t : set α} (h : s = t) (a : s) :
equiv.set.of_eq h a = ⟨a, h ▸ a.2⟩ := rfl
@[simp] lemma of_eq_symm_apply {α : Type u} {s t : set α} (h : s = t) (a : t) :
(equiv.set.of_eq h).symm a = ⟨a, h.symm ▸ a.2⟩ := rfl
/-- If `a ∉ s`, then `insert a s` is equivalent to `s ⊕ punit`. -/
protected def insert {α} {s : set.{u} α} [decidable_pred s] {a : α} (H : a ∉ s) :
(insert a s : set α) ≃ s ⊕ punit.{u+1} :=
calc (insert a s : set α) ≃ ↥(s ∪ {a}) : equiv.set.of_eq (by simp)
... ≃ s ⊕ ({a} : set α) : equiv.set.union (by finish [set.subset_def])
... ≃ s ⊕ punit.{u+1} : sum_congr (equiv.refl _) (equiv.set.singleton _)
/-- If `s : set α` is a set with decidable membership, then `s ⊕ sᶜ` is equivalent to `α`. -/
protected def sum_compl {α} (s : set α) [decidable_pred s] : s ⊕ (sᶜ : set α) ≃ α :=
calc s ⊕ (sᶜ : set α) ≃ ↥(s ∪ sᶜ) : (equiv.set.union (by simp [set.ext_iff])).symm
... ≃ @univ α : equiv.set.of_eq (by simp)
... ≃ α : equiv.set.univ _
@[simp] lemma sum_compl_apply_inl {α : Type u} (s : set α) [decidable_pred s] (x : s) :
equiv.set.sum_compl s (sum.inl x) = x := rfl
@[simp] lemma sum_compl_apply_inr {α : Type u} (s : set α) [decidable_pred s] (x : sᶜ) :
equiv.set.sum_compl s (sum.inr x) = x := rfl
lemma sum_compl_symm_apply_of_mem {α : Type u} {s : set α} [decidable_pred s] {x : α}
(hx : x ∈ s) : (equiv.set.sum_compl s).symm x = sum.inl ⟨x, hx⟩ :=
have ↑(⟨x, or.inl hx⟩ : (s ∪ sᶜ : set α)) ∈ s, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_left _ this }
lemma sum_compl_symm_apply_of_not_mem {α : Type u} {s : set α} [decidable_pred s] {x : α}
(hx : x ∉ s) : (equiv.set.sum_compl s).symm x = sum.inr ⟨x, hx⟩ :=
have ↑(⟨x, or.inr hx⟩ : (s ∪ sᶜ : set α)) ∈ sᶜ, from hx,
by { rw [equiv.set.sum_compl], simpa using set.union_apply_right _ this }
/-- `sum_diff_subset s t` is the natural equivalence between
`s ⊕ (t \ s)` and `t`, where `s` and `t` are two sets. -/
protected def sum_diff_subset {α} {s t : set α} (h : s ⊆ t) [decidable_pred s] :
s ⊕ (t \ s : set α) ≃ t :=
calc s ⊕ (t \ s : set α) ≃ (s ∪ (t \ s) : set α) : (equiv.set.union (by simp [inter_diff_self])).symm
... ≃ t : equiv.set.of_eq (by { simp [union_diff_self, union_eq_self_of_subset_left h] })
@[simp] lemma sum_diff_subset_apply_inl
{α} {s t : set α} (h : s ⊆ t) [decidable_pred s] (x : s) :
equiv.set.sum_diff_subset h (sum.inl x) = inclusion h x := rfl
@[simp] lemma sum_diff_subset_apply_inr
{α} {s t : set α} (h : s ⊆ t) [decidable_pred s] (x : t \ s) :
equiv.set.sum_diff_subset h (sum.inr x) = inclusion (diff_subset t s) x := rfl
lemma sum_diff_subset_symm_apply_of_mem
{α} {s t : set α} (h : s ⊆ t) [decidable_pred s] {x : t} (hx : x.1 ∈ s) :
(equiv.set.sum_diff_subset h).symm x = sum.inl ⟨x, hx⟩ :=
begin
apply (equiv.set.sum_diff_subset h).injective,
simp only [apply_symm_apply, sum_diff_subset_apply_inl],
exact subtype.eq rfl,
end
lemma sum_diff_subset_symm_apply_of_not_mem
{α} {s t : set α} (h : s ⊆ t) [decidable_pred s] {x : t} (hx : x.1 ∉ s) :
(equiv.set.sum_diff_subset h).symm x = sum.inr ⟨x, ⟨x.2, hx⟩⟩ :=
begin
apply (equiv.set.sum_diff_subset h).injective,
simp only [apply_symm_apply, sum_diff_subset_apply_inr],
exact subtype.eq rfl,
end
/-- If `s` is a set with decidable membership, then the sum of `s ∪ t` and `s ∩ t` is equivalent
to `s ⊕ t`. -/
protected def union_sum_inter {α : Type u} (s t : set α) [decidable_pred s] :
(s ∪ t : set α) ⊕ (s ∩ t : set α) ≃ s ⊕ t :=
calc (s ∪ t : set α) ⊕ (s ∩ t : set α)
≃ (s ∪ t \ s : set α) ⊕ (s ∩ t : set α) : by rw [union_diff_self]
... ≃ (s ⊕ (t \ s : set α)) ⊕ (s ∩ t : set α) :
sum_congr (set.union $ subset_empty_iff.2 (inter_diff_self _ _)) (equiv.refl _)
... ≃ s ⊕ (t \ s : set α) ⊕ (s ∩ t : set α) : sum_assoc _ _ _
... ≃ s ⊕ (t \ s ∪ s ∩ t : set α) : sum_congr (equiv.refl _) begin
refine (set.union' (∉ s) _ _).symm,
exacts [λ x hx, hx.2, λ x hx, not_not_intro hx.1]
end
... ≃ s ⊕ t : by { rw (_ : t \ s ∪ s ∩ t = t), rw [union_comm, inter_comm, inter_union_diff] }
/-- The set product of two sets is equivalent to the type product of their coercions to types. -/
protected def prod {α β} (s : set α) (t : set β) :
s.prod t ≃ s × t :=
@subtype_prod_equiv_prod α β s t
/-- If a function `f` is injective on a set `s`, then `s` is equivalent to `f '' s`. -/
protected noncomputable def image_of_inj_on {α β} (f : α → β) (s : set α) (H : inj_on f s) :
s ≃ (f '' s) :=
⟨λ p, ⟨f p, mem_image_of_mem f p.2⟩,
λ p, ⟨classical.some p.2, (classical.some_spec p.2).1⟩,
λ ⟨x, h⟩, subtype.eq (H (classical.some_spec (mem_image_of_mem f h)).1 h
(classical.some_spec (mem_image_of_mem f h)).2),
λ ⟨y, h⟩, subtype.eq (classical.some_spec h).2⟩
/-- If `f` is an injective function, then `s` is equivalent to `f '' s`. -/
protected noncomputable def image {α β} (f : α → β) (s : set α) (H : injective f) : s ≃ (f '' s) :=
equiv.set.image_of_inj_on f s (λ x y hx hy hxy, H hxy)
@[simp] theorem image_apply {α β} (f : α → β) (s : set α) (H : injective f) (a h) :
set.image f s H ⟨a, h⟩ = ⟨f a, mem_image_of_mem _ h⟩ := rfl
lemma image_symm_preimage {α β} {f : α → β} (hf : injective f) (u s : set α) :
(λ x, (set.image f s hf).symm x : f '' s → α) ⁻¹' u = coe ⁻¹' (f '' u) :=
begin
ext ⟨b, a, has, rfl⟩,
have : ∀(h : ∃a', a' ∈ s ∧ a' = a), classical.some h = a := λ h, (classical.some_spec h).2,
simp [equiv.set.image, equiv.set.image_of_inj_on, hf, this],
end
/-- If `f : α → β` is an injective function, then `α` is equivalent to the range of `f`. -/
protected noncomputable def range {α β} (f : α → β) (H : injective f) :
α ≃ range f :=
{ to_fun := λ x, ⟨f x, mem_range_self _⟩,
inv_fun := λ x, classical.some x.2,
left_inv := λ x, H (classical.some_spec (show f x ∈ range f, from mem_range_self _)),
right_inv := λ x, subtype.eq $ classical.some_spec x.2 }
@[simp] theorem range_apply {α β} (f : α → β) (H : injective f) (a) :
set.range f H a = ⟨f a, set.mem_range_self _⟩ := rfl
theorem apply_range_symm {α β} (f : α → β) (H : injective f) (b : range f) :
f ((set.range f H).symm b) = b :=
begin
conv_rhs { rw ←((set.range f H).right_inv b), },
simp,
end
/-- If `α` is equivalent to `β`, then `set α` is equivalent to `set β`. -/
protected def congr {α β : Type*} (e : α ≃ β) : set α ≃ set β :=
⟨λ s, e '' s, λ t, e.symm '' t, symm_image_image e, symm_image_image e.symm⟩
/-- The set `{x ∈ s | t x}` is equivalent to the set of `x : s` such that `t x`. -/
protected def sep {α : Type u} (s : set α) (t : α → Prop) :
({ x ∈ s | t x } : set α) ≃ { x : s | t x } :=
(equiv.subtype_subtype_equiv_subtype_inter s t).symm
end set
/-- If `f` is a bijective function, then its domain is equivalent to its codomain. -/
noncomputable def of_bijective {α β} (f : α → β) (hf : bijective f) : α ≃ β :=
(equiv.set.range f hf.1).trans $ (set_congr hf.2.range_eq).trans $ equiv.set.univ β
@[simp] theorem coe_of_bijective {α β} {f : α → β} (hf : bijective f) :
(of_bijective f hf : α → β) = f := rfl
/-- If `f` is an injective function, then its domain is equivalent to its range. -/
noncomputable def of_injective {α β} (f : α → β) (hf : injective f) : α ≃ _root_.set.range f :=
of_bijective (λ x, ⟨f x, set.mem_range_self x⟩) ⟨λ x y hxy, hf $ by injections, λ ⟨_, x, rfl⟩, ⟨x, rfl⟩⟩
@[simp] lemma of_injective_apply {α β} (f : α → β) (hf : injective f) (x : α) :
of_injective f hf x = ⟨f x, set.mem_range_self x⟩ :=
rfl
def subtype_quotient_equiv_quotient_subtype (p₁ : α → Prop) [s₁ : setoid α]
[s₂ : setoid (subtype p₁)] (p₂ : quotient s₁ → Prop) (hp₂ : ∀ a, p₁ a ↔ p₂ ⟦a⟧)
(h : ∀ x y : subtype p₁, @setoid.r _ s₂ x y ↔ (x : α) ≈ y) :
{x // p₂ x} ≃ quotient s₂ :=
{ to_fun := λ a, quotient.hrec_on a.1 (λ a h, ⟦⟨a, (hp₂ _).2 h⟩⟧)
(λ a b hab, hfunext (by rw quotient.sound hab)
(λ h₁ h₂ _, heq_of_eq (quotient.sound ((h _ _).2 hab)))) a.2,
inv_fun := λ a, quotient.lift_on a (λ a, (⟨⟦a.1⟧, (hp₂ _).1 a.2⟩ : {x // p₂ x}))
(λ a b hab, subtype.ext_val (quotient.sound ((h _ _).1 hab))),
left_inv := λ ⟨a, ha⟩, quotient.induction_on a (λ a ha, rfl) ha,
right_inv := λ a, quotient.induction_on a (λ ⟨a, ha⟩, rfl) }
section swap
variable [decidable_eq α]
/-- A helper function for `equiv.swap`. -/
def swap_core (a b r : α) : α :=
if r = a then b
else if r = b then a
else r
theorem swap_core_self (r a : α) : swap_core a a r = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_swap_core (r a b : α) : swap_core a b (swap_core a b r) = r :=
by { unfold swap_core, split_ifs; cc }
theorem swap_core_comm (r a b : α) : swap_core a b r = swap_core b a r :=
by { unfold swap_core, split_ifs; cc }
/-- `swap a b` is the permutation that swaps `a` and `b` and
leaves other values as is. -/
def swap (a b : α) : perm α :=
⟨swap_core a b, swap_core a b, λr, swap_core_swap_core r a b, λr, swap_core_swap_core r a b⟩
theorem swap_self (a : α) : swap a a = equiv.refl _ :=
ext $ λ r, swap_core_self r a
theorem swap_comm (a b : α) : swap a b = swap b a :=
ext $ λ r, swap_core_comm r _ _
theorem swap_apply_def (a b x : α) : swap a b x = if x = a then b else if x = b then a else x :=
rfl
@[simp] theorem swap_apply_left (a b : α) : swap a b a = b :=
if_pos rfl
@[simp] theorem swap_apply_right (a b : α) : swap a b b = a :=
by { by_cases h : b = a; simp [swap_apply_def, h], }
theorem swap_apply_of_ne_of_ne {a b x : α} : x ≠ a → x ≠ b → swap a b x = x :=
by simp [swap_apply_def] {contextual := tt}
@[simp] theorem swap_swap (a b : α) : (swap a b).trans (swap a b) = equiv.refl _ :=
ext $ λ x, swap_core_swap_core _ _ _
theorem swap_comp_apply {a b x : α} (π : perm α) :
π.trans (swap a b) x = if π x = a then b else if π x = b then a else π x :=
by { cases π, refl }
@[simp] lemma swap_inv {α : Type*} [decidable_eq α] (x y : α) :
(swap x y)⁻¹ = swap x y := rfl
@[simp] lemma symm_trans_swap_trans [decidable_eq β] (a b : α)
(e : α ≃ β) : (e.symm.trans (swap a b)).trans e = swap (e a) (e b) :=
equiv.ext (λ x, begin
have : ∀ a, e.symm x = a ↔ x = e a :=
λ a, by { rw @eq_comm _ (e.symm x), split; intros; simp * at * },
simp [swap_apply_def, this],
split_ifs; simp
end)
@[simp] lemma swap_mul_self {α : Type*} [decidable_eq α] (i j : α) : swap i j * swap i j = 1 :=
equiv.swap_swap i j
@[simp] lemma swap_apply_self {α : Type*} [decidable_eq α] (i j a : α) :
swap i j (swap i j a) = a :=
by rw [← perm.mul_apply, swap_mul_self, perm.one_apply]
/-- Augment an equivalence with a prescribed mapping `f a = b` -/
def set_value (f : α ≃ β) (a : α) (b : β) : α ≃ β :=
(swap a (f.symm b)).trans f
@[simp] theorem set_value_eq (f : α ≃ β) (a : α) (b : β) : set_value f a b a = b :=
by { dsimp [set_value], simp [swap_apply_left] }
end swap
protected lemma forall_congr {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p x ↔ q (f x)) : (∀x, p x) ↔ (∀y, q y) :=
begin
split; intros h₂ x,
{ rw [←f.right_inv x], apply h.mp, apply h₂ },
apply h.mpr, apply h₂
end
protected lemma forall_congr' {p : α → Prop} {q : β → Prop} (f : α ≃ β)
(h : ∀{x}, p (f.symm x) ↔ q x) : (∀x, p x) ↔ (∀y, q y) :=
(equiv.forall_congr f.symm (λ x, h.symm)).symm
-- We next build some higher arity versions of `equiv.forall_congr`.
-- Although they appear to just be repeated applications of `equiv.forall_congr`,
-- unification of metavariables works better with these versions.
-- In particular, they are necessary in `equiv_rw`.
-- (Stopping at ternary functions seems reasonable: at least in 1-categorical mathematics,
-- it's rare to have axioms involving more than 3 elements at once.)
universes ua1 ua2 ub1 ub2 ug1 ug2
variables {α₁ : Sort ua1} {α₂ : Sort ua2}
{β₁ : Sort ub1} {β₂ : Sort ub2}
{γ₁ : Sort ug1} {γ₂ : Sort ug2}
protected lemma forall₂_congr {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂)
(eβ : β₁ ≃ β₂) (h : ∀{x y}, p x y ↔ q (eα x) (eβ y)) :
(∀x y, p x y) ↔ (∀x y, q x y) :=
begin
apply equiv.forall_congr,
intros,
apply equiv.forall_congr,
intros,
apply h,
end
protected lemma forall₂_congr' {p : α₁ → β₁ → Prop} {q : α₂ → β₂ → Prop} (eα : α₁ ≃ α₂)
(eβ : β₁ ≃ β₂) (h : ∀{x y}, p (eα.symm x) (eβ.symm y) ↔ q x y) :
(∀x y, p x y) ↔ (∀x y, q x y) :=
(equiv.forall₂_congr eα.symm eβ.symm (λ x y, h.symm)).symm
protected lemma forall₃_congr {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀{x y z}, p x y z ↔ q (eα x) (eβ y) (eγ z)) : (∀x y z, p x y z) ↔ (∀x y z, q x y z) :=
begin
apply equiv.forall₂_congr,
intros,
apply equiv.forall_congr,
intros,
apply h,
end
protected lemma forall₃_congr' {p : α₁ → β₁ → γ₁ → Prop} {q : α₂ → β₂ → γ₂ → Prop}
(eα : α₁ ≃ α₂) (eβ : β₁ ≃ β₂) (eγ : γ₁ ≃ γ₂)
(h : ∀{x y z}, p (eα.symm x) (eβ.symm y) (eγ.symm z) ↔ q x y z) :
(∀x y z, p x y z) ↔ (∀x y z, q x y z) :=
(equiv.forall₃_congr eα.symm eβ.symm eγ.symm (λ x y z, h.symm)).symm
protected lemma forall_congr_left' {p : α → Prop} (f : α ≃ β) :
(∀x, p x) ↔ (∀y, p (f.symm y)) :=
equiv.forall_congr f (λx, by simp)
protected lemma forall_congr_left {p : β → Prop} (f : α ≃ β) :
(∀x, p (f x)) ↔ (∀y, p y) :=
(equiv.forall_congr_left' f.symm).symm
section
variables (P : α → Sort w) (e : α ≃ β)
/--
Transport dependent functions through an equivalence of the base space.
-/
def Pi_congr_left' : (Π a, P a) ≃ (Π b, P (e.symm b)) :=
{ to_fun := λ f x, f (e.symm x),
inv_fun := λ f x, begin rw [← e.symm_apply_apply x], exact f (e x) end,
left_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { dsimp, rw e.symm_apply_apply })),
right_inv := λ f, funext $ λ x, eq_of_heq ((eq_rec_heq _ _).trans
(by { rw e.apply_symm_apply })) }
@[simp]
lemma Pi_congr_left'_apply (f : Π a, P a) (b : β) : ((Pi_congr_left' P e) f) b = f (e.symm b) :=
rfl
@[simp]
lemma Pi_congr_left'_symm_apply (g : Π b, P (e.symm b)) (a : α) :
((Pi_congr_left' P e).symm g) a = (by { convert g (e a), simp }) :=
rfl
end
section
variables (P : β → Sort w) (e : α ≃ β)
/--
Transporting dependent functions through an equivalence of the base,
expressed as a "simplification".
-/
def Pi_congr_left : (Π a, P (e a)) ≃ (Π b, P b) :=
(Pi_congr_left' P e.symm).symm
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π a : α, (W a ≃ Z (h₁ a)))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibers.
-/
def Pi_congr : (Π a, W a) ≃ (Π b, Z b) :=
(equiv.Pi_congr_right h₂).trans (equiv.Pi_congr_left _ h₁)
end
section
variables
{W : α → Sort w} {Z : β → Sort z} (h₁ : α ≃ β) (h₂ : Π b : β, (W (h₁.symm b) ≃ Z b))
/--
Transport dependent functions through
an equivalence of the base spaces and a family
of equivalences of the matching fibres.
-/
def Pi_congr' : (Π a, W a) ≃ (Π b, Z b) :=
(Pi_congr h₁.symm (λ b, (h₂ b).symm)).symm
end
end equiv
instance {α} [subsingleton α] : subsingleton (ulift α) := equiv.ulift.subsingleton
instance {α} [subsingleton α] : subsingleton (plift α) := equiv.plift.subsingleton
instance {α} [decidable_eq α] : decidable_eq (ulift α) := equiv.ulift.decidable_eq
instance {α} [decidable_eq α] : decidable_eq (plift α) := equiv.plift.decidable_eq
/-- If both `α` and `β` are singletons, then `α ≃ β`. -/
def equiv_of_unique_of_unique [unique α] [unique β] : α ≃ β :=
{ to_fun := λ _, default β,
inv_fun := λ _, default α,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- If `α` is a singleton, then it is equivalent to any `punit`. -/
def equiv_punit_of_unique [unique α] : α ≃ punit.{v} :=
equiv_of_unique_of_unique
/-- If `α` is a subsingleton, then it is equivalent to `α × α`. -/
def subsingleton_prod_self_equiv {α : Type*} [subsingleton α] : α × α ≃ α :=
{ to_fun := λ p, p.1,
inv_fun := λ a, (a, a),
left_inv := λ p, subsingleton.elim _ _,
right_inv := λ p, subsingleton.elim _ _, }
/-- To give an equivalence between two subsingleton types, it is sufficient to give any two
functions between them. -/
def equiv_of_subsingleton_of_subsingleton [subsingleton α] [subsingleton β]
(f : α → β) (g : β → α) : α ≃ β :=
{ to_fun := f,
inv_fun := g,
left_inv := λ _, subsingleton.elim _ _,
right_inv := λ _, subsingleton.elim _ _ }
/-- `unique (unique α)` is equivalent to `unique α`. -/
def unique_unique_equiv : unique (unique α) ≃ unique α :=
equiv_of_subsingleton_of_subsingleton (λ h, h.default)
(λ h, { default := h, uniq := λ _, subsingleton.elim _ _ })
namespace quot
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : α → α → Prop} {rb : β → β → Prop} (e : α ≃ β)
(eq : ∀a₁ a₂, ra a₁ a₂ ↔ rb (e a₁) (e a₂)) :
quot ra ≃ quot rb :=
{ to_fun := quot.map e (assume a₁ a₂, (eq a₁ a₂).1),
inv_fun := quot.map e.symm
(assume b₁ b₂ h,
(eq (e.symm b₁) (e.symm b₂)).2
((e.apply_symm_apply b₁).symm ▸ (e.apply_symm_apply b₂).symm ▸ h)),
left_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.symm_apply_apply] },
right_inv := by { rintros ⟨a⟩, dunfold quot.map, simp only [equiv.apply_symm_apply] } }
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : α → α → Prop} (eq : ∀a₁ a₂, r a₁ a₂ ↔ r' a₁ a₂) :
quot r ≃ quot r' :=
quot.congr (equiv.refl α) eq
/-- An equivalence `e : α ≃ β` generates an equivalence between the quotient space of `α`
by a relation `ra` and the quotient space of `β` by the image of this relation under `e`. -/
protected def congr_left {r : α → α → Prop} (e : α ≃ β) :
quot r ≃ quot (λ b b', r (e.symm b) (e.symm b')) :=
@quot.congr α β r (λ b b', r (e.symm b) (e.symm b')) e (λ a₁ a₂, by simp only [e.symm_apply_apply])
end quot
namespace quotient
/-- An equivalence `e : α ≃ β` generates an equivalence between quotient spaces,
if `ra a₁ a₂ ↔ rb (e a₁) (e a₂). -/
protected def congr {ra : setoid α} {rb : setoid β} (e : α ≃ β)
(eq : ∀a₁ a₂, @setoid.r α ra a₁ a₂ ↔ @setoid.r β rb (e a₁) (e a₂)) :
quotient ra ≃ quotient rb :=
quot.congr e eq
/-- Quotients are congruent on equivalences under equality of their relation.
An alternative is just to use rewriting with `eq`, but then computational proofs get stuck. -/
protected def congr_right {r r' : setoid α}
(eq : ∀a₁ a₂, @setoid.r α r a₁ a₂ ↔ @setoid.r α r' a₁ a₂) : quotient r ≃ quotient r' :=
quot.congr_right eq
end quotient
/-- If a function is a bijection between `univ` and a set `s` in the target type, it induces an
equivalence between the original type and the type `↑s`. -/
noncomputable def set.bij_on.equiv {α : Type*} {β : Type*} {s : set β} (f : α → β)
(h : set.bij_on f set.univ s) : α ≃ s :=
begin
have : function.bijective (λ (x : α), (⟨f x, begin exact h.maps_to (set.mem_univ x) end⟩ : s)),
{ split,
{ assume x y hxy,
apply h.inj_on (set.mem_univ x) (set.mem_univ y) (subtype.mk.inj hxy) },
{ assume x,
rcases h.surj_on x.2 with ⟨y, hy⟩,
exact ⟨y, subtype.eq hy.2⟩ } },
exact equiv.of_bijective _ this
end
/-- The composition of an updated function with an equiv on a subset can be expressed as an
updated function. -/
lemma dite_comp_equiv_update {α : Type*} {β : Type*} {γ : Type*} {s : set α} (e : β ≃ s)
(v : β → γ) (w : α → γ) (j : β) (x : γ) [decidable_eq β] [decidable_eq α]
[∀ j, decidable (j ∈ s)] :
(λ (i : α), if h : i ∈ s then (function.update v j x) (e.symm ⟨i, h⟩) else w i) =
function.update (λ (i : α), if h : i ∈ s then v (e.symm ⟨i, h⟩) else w i) (e j) x :=
begin
ext i,
by_cases h : i ∈ s,
{ simp only [h, dif_pos],
have A : e.symm ⟨i, h⟩ = j ↔ i = e j,
by { rw equiv.symm_apply_eq, exact subtype.ext_iff_val },
by_cases h' : i = e j,
{ rw [A.2 h', h'], simp },
{ have : ¬ e.symm ⟨i, h⟩ = j, by simpa [← A] using h',
simp [h, h', this] } },
{ have : i ≠ e j,
by { contrapose! h, have : (e j : α) ∈ s := (e j).2, rwa ← h at this },
simp [h, this] }
end
|
4cfa90fea4c9f907166dc42a121f7e07345876c5 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/tactic/replacer.lean | 4d8517311131776827f38b0f47406537b573c8a2 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,411 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.core
import Mathlib.PostPort
namespace Mathlib
/-!
# `def_replacer`
A mechanism for defining tactics for use in auto params, whose
meaning is defined incrementally through attributes.
-/
namespace tactic
/-- Define a new replaceable tactic. -/
/--
`def_replacer foo` sets up a stub definition `foo : tactic unit`, which can
effectively be defined and re-defined later, by tagging definitions with `@[foo]`.
- `@[foo] meta def foo_1 : tactic unit := ...` replaces the current definition of `foo`.
- `@[foo] meta def foo_2 (old : tactic unit) : tactic unit := ...` replaces the current
definition of `foo`, and provides access to the previous definition via `old`.
(The argument can also be an `option (tactic unit)`, which is provided as `none` if
this is the first definition tagged with `@[foo]` since `def_replacer` was invoked.)
`def_replacer foo : α → β → tactic γ` allows the specification of a replacer with
custom input and output types. In this case all subsequent redefinitions must have the
same type, or the type `α → β → tactic γ → tactic γ` or
`α → β → option (tactic γ) → tactic γ` analogously to the previous cases.
-/
|
6116a114439144d44d9d1af83067dc83eaf2d6e5 | 32025d5c2d6e33ad3b6dd8a3c91e1e838066a7f7 | /src/Lean/MetavarContext.lean | 8e6401f9c6bbaff54334a0cc8a3a4d9a879e0700 | [
"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 | 48,960 | 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.Util.MonadCache
import Lean.LocalContext
namespace Lean
/-
The metavariable context stores metavariable declarations and their
assignments. It is used in the elaborator, tactic framework, unifier
(aka `isDefEq`), and type class resolution (TC). First, we list all
the requirements imposed by these modules.
- We may invoke TC while executing `isDefEq`. We need this feature to
be able to solve unification problems such as:
```
f ?a (ringHasAdd ?s) ?x ?y =?= f Int intHasAdd n m
```
where `(?a : Type) (?s : Ring ?a) (?x ?y : ?a)`
During `isDefEq` (i.e., unification), it will need to solve the constrain
```
ringHasAdd ?s =?= intHasAdd
```
We say `ringHasAdd ?s` is stuck because it cannot be reduced until we
synthesize the term `?s : Ring ?a` using TC. This can be done since we
have assigned `?a := Int` when solving `?a =?= Int`.
- TC uses `isDefEq`, and `isDefEq` may create TC problems as shown
aaa. Thus, we may have nested TC problems.
- `isDefEq` extends the local context when going inside binders. Thus,
the local context for nested TC may be an extension of the local
context for outer TC.
- TC should not assign metavariables created by the elaborator, simp,
tactic framework, and outer TC problems. Reason: TC commits to the
first solution it finds. Consider the TC problem `HasCoe Nat ?x`,
where `?x` is a metavariable created by the caller. There are many
solutions to this problem (e.g., `?x := Int`, `?x := Real`, ...),
and it doesn’t make sense to commit to the first one since TC does
not know the the constraints the caller may impose on `?x` after the
TC problem is solved.
Remark: we claim it is not feasible to make the whole system backtrackable,
and allow the caller to backtrack back to TC and ask it for another solution
if the first one found did not work. We claim it would be too inefficient.
- TC metavariables should not leak outside of TC. Reason: we want to
get rid of them after we synthesize the instance.
- `simp` invokes `isDefEq` for matching the left-hand-side of
equations to terms in our goal. Thus, it may invoke TC indirectly.
- In Lean3, we didn’t have to create a fresh pattern for trying to
match the left-hand-side of equations when executing `simp`. We had a
mechanism called tmp metavariables. It avoided this overhead, but it
created many problems since `simp` may indirectly call TC which may
recursively call TC. Moreover, we want to allow TC to invoke
tactics. Thus, when `simp` invokes `isDefEq`, it may indirectly invoke
a tactic and `simp` itself. The Lean3 approach assumed that
metavariables were short-lived, this is not true in Lean4, and to some
extent was also not true in Lean3 since `simp`, in principle, could
trigger an arbitrary number of nested TC problems.
- Here are some possible call stack traces we could have in Lean3 (and Lean4).
```
Elaborator (-> TC -> isDefEq)+
Elaborator -> isDefEq (-> TC -> isDefEq)*
Elaborator -> simp -> isDefEq (-> TC -> isDefEq)*
```
In Lean4, TC may also invoke tactics.
- In Lean3 and Lean4, TC metavariables are not really short-lived. We
solve an arbitrary number of unification problems, and we may have
nested TC invocations.
- TC metavariables do not share the same local context even in the
same invocation. In the C++ and Lean implementations we use a trick to
ensure they do:
https://github.com/leanprover/lean/blob/92826917a252a6092cffaf5fc5f1acb1f8cef379/src/library/type_context.cpp#L3583-L3594
- Metavariables may be natural, synthetic or syntheticOpaque.
a) Natural metavariables may be assigned by unification (i.e., `isDefEq`).
b) Synthetic metavariables may still be assigned by unification,
but whenever possible `isDefEq` will avoid the assignment. For example,
if we have the unification constaint `?m =?= ?n`, where `?m` is synthetic,
but `?n` is not, `isDefEq` solves it by using the assignment `?n := ?m`.
We use synthetic metavariables for type class resolution.
Any module that creates synthetic metavariables, must also check
whether they have been assigned by `isDefEq`, and then still synthesize
them, and check whether the sythesized result is compatible with the one
assigned by `isDefEq`.
c) SyntheticOpaque metavariables are never assigned by `isDefEq`.
That is, the constraint `?n =?= Nat.succ Nat.zero` always fail
if `?n` is a syntheticOpaque metavariable. This kind of metavariable
is created by tactics such as `intro`. Reason: in the tactic framework,
subgoals as represented as metavariables, and a subgoal `?n` is considered
as solved whenever the metavariable is assigned.
This distinction was not precise in Lean3 and produced
counterintuitive behavior. For example, the following hack was added
in Lean3 to work around one of these issues:
https://github.com/leanprover/lean/blob/92826917a252a6092cffaf5fc5f1acb1f8cef379/src/library/type_context.cpp#L2751
- When creating lambda/forall expressions, we need to convert/abstract
free variables and convert them to bound variables. Now, suppose we a
trying to create a lambda/forall expression by abstracting free
variables `xs` and a term `t[?m]` which contains a metavariable `?m`,
and the local context of `?m` contains `xs`. The term
```
fun xs => t[?m]
```
will be ill-formed if we later assign a term `s` to `?m`, and
`s` contains free variables in `xs`. We address this issue by changing
the free variable abstraction procedure. We consider two cases: `?m`
is natural, `?m` is synthetic. Assume the type of `?m` is
`A[xs]`. Then, in both cases we create an auxiliary metavariable `?n` with
type `forall xs => A[xs]`, and local context := local context of `?m` - `xs`.
In both cases, we produce the term `fun xs => t[?n xs]`
1- If `?m` is natural or synthetic, then we assign `?m := ?n xs`, and we produce
the term `fun xs => t[?n xs]`
2- If `?m` is syntheticOpaque, then we mark `?n` as a syntheticOpaque variable.
However, `?n` is managed by the metavariable context itself.
We say we have a "delayed assignment" `?n xs := ?m`.
That is, after a term `s` is assigned to `?m`, and `s`
does not contain metavariables, we replace any occurrence
`?n ts` with `s[xs := ts]`.
Gruesome details:
- When we create the type `forall xs => A` for `?n`, we may
encounter the same issue if `A` contains metavariables. So, the
process above is recursive. We claim it terminates because we keep
creating new metavariables with smaller local contexts.
- Suppose, we have `t[?m]` and we want to create a let-expression by
abstracting a let-decl free variable `x`, and the local context of
`?m` contatins `x`. Similarly to the previous case
```
let x : T := v; t[?m]
```
will be ill-formed if we later assign a term `s` to `?m`, and
`s` contains free variable `x`. Again, assume the type of `?m` is `A[x]`.
1- If `?m` is natural or synthetic, then we create `?n : (let x : T := v; A[x])` with
and local context := local context of `?m` - `x`, we assign `?m := ?n`,
and produce the term `let x : T := v; t[?n]`. That is, we are just making
sure `?n` must never be assigned to a term containing `x`.
2- If `?m` is syntheticOpaque, we create a fresh syntheticOpaque `?n`
with type `?n : T -> (let x : T := v; A[x])` and local context := local context of `?m` - `x`,
create the delayed assignment `?n #[x] := ?m`, and produce the term `let x : T := v; t[?n x]`.
Now suppose we assign `s` to `?m`. We do not assign the term `fun (x : T) => s` to `?n`, since
`fun (x : T) => s` may not even be type correct. Instead, we just replace applications `?n r`
with `s[x/r]`. The term `r` may not necessarily be a bound variable. For example, a tactic
may have reduced `let x : T := v; t[?n x]` into `t[?n v]`.
We are essentially using the pair "delayed assignment + application" to implement a delayed
substitution.
- We use TC for implementing coercions. Both Joe Hendrix and Reid Barton
reported a nasty limitation. In Lean3, TC will not be used if there are
metavariables in the TC problem. For example, the elaborator will not try
to synthesize `HasCoe Nat ?x`. This is good, but this constraint is too
strict for problems such as `HasCoe (Vector Bool ?n) (BV ?n)`. The coercion
exists independently of `?n`. Thus, during TC, we want `isDefEq` to throw
an exception instead of return `false` whenever it tries to assign
a metavariable owned by its caller. The idea is to sign to the caller that
it cannot solve the TC problem at this point, and more information is needed.
That is, the caller must make progress an assign its metavariables before
trying to invoke TC again.
In Lean4, we are using a simpler design for the `MetavarContext`.
- No distinction betwen temporary and regular metavariables.
- Metavariables have a `depth` Nat field.
- MetavarContext also has a `depth` field.
- We bump the `MetavarContext` depth when we create a nested problem.
Example: Elaborator (depth = 0) -> Simplifier matcher (depth = 1) -> TC (level = 2) -> TC (level = 3) -> ...
- When `MetavarContext` is at depth N, `isDefEq` does not assign variables from `depth < N`.
- Metavariables from depth N+1 must be fully assigned before we return to level N.
- New design even allows us to invoke tactics from TC.
* Main concern
We don't have tmp metavariables anymore in Lean4. Thus, before trying to match
the left-hand-side of an equation in `simp`. We first must bump the level of the `MetavarContext`,
create fresh metavariables, then create a new pattern by replacing the free variable on the left-hand-side with
these metavariables. We are hoping to minimize this overhead by
- Using better indexing data structures in `simp`. They should reduce the number of time `simp` must invoke `isDefEq`.
- Implementing `isDefEqApprox` which ignores metavariables and returns only `false` or `undef`.
It is a quick filter that allows us to fail quickly and avoid the creation of new fresh metavariables,
and a new pattern.
- Adding built-in support for arithmetic, Logical connectives, etc. Thus, we avoid a bunch of lemmas in the simp set.
- Adding support for AC-rewriting. In Lean3, users use AC lemmas as
rewriting rules for "sorting" terms. This is inefficient, requires
a quadratic number of rewrite steps, and does not preserve the
structure of the goal.
The temporary metavariables were also used in the "app builder" module used in Lean3. The app builder uses
`isDefEq`. So, it could, in principle, invoke an arbitrary number of nested TC problems. However, in Lean3,
all app builder uses are controlled. That is, it is mainly used to synthesize implicit arguments using
very simple unification and/or non-nested TC. So, if the "app builder" becomes a bottleneck without tmp metavars,
we may solve the issue by implementing `isDefEqCheap` that never invokes TC and uses tmp metavars.
-/
structure LocalInstance :=
(className : Name)
(fvar : Expr)
abbrev LocalInstances := Array LocalInstance
def LocalInstance.beq (i₁ i₂ : LocalInstance) : Bool :=
i₁.fvar == i₂.fvar
instance LocalInstance.hasBeq : HasBeq LocalInstance := ⟨LocalInstance.beq⟩
/-- Remove local instance with the given `fvarId`. Do nothing if `localInsts` does not contain any free variable with id `fvarId`. -/
def LocalInstances.erase (localInsts : LocalInstances) (fvarId : FVarId) : LocalInstances :=
match localInsts.findIdx? (fun inst => inst.fvar.fvarId! == fvarId) with
| some idx => localInsts.eraseIdx idx
| _ => localInsts
inductive MetavarKind
| natural
| synthetic
| syntheticOpaque
def MetavarKind.isSyntheticOpaque : MetavarKind → Bool
| MetavarKind.syntheticOpaque => true
| _ => false
def MetavarKind.isNatural : MetavarKind → Bool
| MetavarKind.natural => true
| _ => false
structure MetavarDecl :=
(userName : Name := Name.anonymous)
(lctx : LocalContext)
(type : Expr)
(depth : Nat)
(localInstances : LocalInstances)
(kind : MetavarKind)
@[export lean_mk_metavar_decl]
def mkMetavarDeclEx (userName : Name) (lctx : LocalContext) (type : Expr) (depth : Nat) (localInstances : LocalInstances) (kind : MetavarKind) : MetavarDecl :=
{ userName := userName, lctx := lctx, type := type, depth := depth, localInstances := localInstances, kind := kind }
namespace MetavarDecl
instance : Inhabited MetavarDecl := ⟨{ lctx := arbitrary _, type := arbitrary _, depth := 0, localInstances := #[], kind := MetavarKind.natural }⟩
end MetavarDecl
/--
A delayed assignment for a metavariable `?m`. It represents an assignment of the form
`?m := (fun fvars => val)`. The local context `lctx` provides the declarations for `fvars`.
Note that `fvars` may not be defined in the local context for `?m`.
- TODO: after we delete the old frontend, we can remove the field `lctx`.
This field is only used in old C++ implementation. -/
structure DelayedMetavarAssignment :=
(lctx : LocalContext)
(fvars : Array Expr)
(val : Expr)
open Std (HashMap PersistentHashMap)
structure MetavarContext :=
(depth : Nat := 0)
(lDepth : PersistentHashMap MVarId Nat := {})
(decls : PersistentHashMap MVarId MetavarDecl := {})
(lAssignment : PersistentHashMap MVarId Level := {})
(eAssignment : PersistentHashMap MVarId Expr := {})
(dAssignment : PersistentHashMap MVarId DelayedMetavarAssignment := {})
namespace MetavarContext
instance : Inhabited MetavarContext := ⟨{}⟩
@[export lean_mk_metavar_ctx]
def mkMetavarContext : Unit → MetavarContext :=
fun _ => {}
/- Low level API for adding/declaring metavariable declarations.
It is used to implement actions in the monads `MetaM`, `ElabM` and `TacticM`.
It should not be used directly since the argument `(mvarId : MVarId)` is assumed to be "unique". -/
@[export lean_metavar_ctx_mk_decl]
def addExprMVarDecl (mctx : MetavarContext)
(mvarId : MVarId)
(userName : Name)
(lctx : LocalContext)
(localInstances : LocalInstances)
(type : Expr) (kind : MetavarKind := MetavarKind.natural) : MetavarContext :=
{ mctx with
decls := mctx.decls.insert mvarId {
userName := userName,
lctx := lctx,
localInstances := localInstances,
type := type,
depth := mctx.depth,
kind := kind } }
/- Low level API for adding/declaring universe level metavariable declarations.
It is used to implement actions in the monads `MetaM`, `ElabM` and `TacticM`.
It should not be used directly since the argument `(mvarId : MVarId)` is assumed to be "unique". -/
def addLevelMVarDecl (mctx : MetavarContext) (mvarId : MVarId) : MetavarContext :=
{ mctx with lDepth := mctx.lDepth.insert mvarId mctx.depth }
@[export lean_metavar_ctx_find_decl]
def findDecl? (mctx : MetavarContext) (mvarId : MVarId) : Option MetavarDecl :=
mctx.decls.find? mvarId
def getDecl (mctx : MetavarContext) (mvarId : MVarId) : MetavarDecl :=
match mctx.decls.find? mvarId with
| some decl => decl
| none => panic! "unknown metavariable"
def setMVarKind (mctx : MetavarContext) (mvarId : MVarId) (kind : MetavarKind) : MetavarContext :=
let decl := mctx.getDecl mvarId;
{ mctx with decls := mctx.decls.insert mvarId { decl with kind := kind } }
def setMVarUserName (mctx : MetavarContext) (mvarId : MVarId) (userName : Name) : MetavarContext :=
let decl := mctx.getDecl mvarId;
{ mctx with decls := mctx.decls.insert mvarId { decl with userName := userName } }
def findLevelDepth? (mctx : MetavarContext) (mvarId : MVarId) : Option Nat :=
mctx.lDepth.find? mvarId
def getLevelDepth (mctx : MetavarContext) (mvarId : MVarId) : Nat :=
match mctx.findLevelDepth? mvarId with
| some d => d
| none => panic! "unknown metavariable"
def isAnonymousMVar (mctx : MetavarContext) (mvarId : MVarId) : Bool :=
match mctx.findDecl? mvarId with
| none => false
| some mvarDecl => mvarDecl.userName.isAnonymous
def renameMVar (mctx : MetavarContext) (mvarId : MVarId) (newUserName : Name) : MetavarContext :=
match mctx.findDecl? mvarId with
| none => panic! "unknown metavariable"
| some mvarDecl => { mctx with decls := mctx.decls.insert mvarId { mvarDecl with userName := newUserName } }
@[export lean_metavar_ctx_assign_level]
def assignLevel (m : MetavarContext) (mvarId : MVarId) (val : Level) : MetavarContext :=
{ m with lAssignment := m.lAssignment.insert mvarId val }
@[export lean_metavar_ctx_assign_expr]
def assignExprCore (m : MetavarContext) (mvarId : MVarId) (val : Expr) : MetavarContext :=
{ m with eAssignment := m.eAssignment.insert mvarId val }
def assignExpr (m : MetavarContext) (mvarId : MVarId) (val : Expr) : MetavarContext :=
{ m with eAssignment := m.eAssignment.insert mvarId val }
@[export lean_metavar_ctx_assign_delayed]
def assignDelayed (m : MetavarContext) (mvarId : MVarId) (lctx : LocalContext) (fvars : Array Expr) (val : Expr) : MetavarContext :=
{ m with dAssignment := m.dAssignment.insert mvarId { lctx := lctx, fvars := fvars, val := val } }
@[export lean_metavar_ctx_get_level_assignment]
def getLevelAssignment? (m : MetavarContext) (mvarId : MVarId) : Option Level :=
m.lAssignment.find? mvarId
@[export lean_metavar_ctx_get_expr_assignment]
def getExprAssignment? (m : MetavarContext) (mvarId : MVarId) : Option Expr :=
m.eAssignment.find? mvarId
@[export lean_metavar_ctx_get_delayed_assignment]
def getDelayedAssignment? (m : MetavarContext) (mvarId : MVarId) : Option DelayedMetavarAssignment :=
m.dAssignment.find? mvarId
@[export lean_metavar_ctx_is_level_assigned]
def isLevelAssigned (m : MetavarContext) (mvarId : MVarId) : Bool :=
m.lAssignment.contains mvarId
@[export lean_metavar_ctx_is_expr_assigned]
def isExprAssigned (m : MetavarContext) (mvarId : MVarId) : Bool :=
m.eAssignment.contains mvarId
@[export lean_metavar_ctx_is_delayed_assigned]
def isDelayedAssigned (m : MetavarContext) (mvarId : MVarId) : Bool :=
m.dAssignment.contains mvarId
@[export lean_metavar_ctx_erase_delayed]
def eraseDelayed (m : MetavarContext) (mvarId : MVarId) : MetavarContext :=
{ m with dAssignment := m.dAssignment.erase mvarId }
/- Given a sequence of delayed assignments
```
mvarId₁ := mvarId₂ ...;
...
mvarIdₙ := mvarId_root ... -- where `mvarId_root` is not delayed assigned
```
in `mctx`, `getDelayedRoot mctx mvarId₁` return `mvarId_root`.
If `mvarId₁` is not delayed assigned then return `mvarId₁` -/
partial def getDelayedRoot (m : MetavarContext) : MVarId → MVarId
| mvarId => match getDelayedAssignment? m mvarId with
| some d => match d.val.getAppFn with
| Expr.mvar mvarId _ => getDelayedRoot mvarId
| _ => mvarId
| none => mvarId
def isLevelAssignable (mctx : MetavarContext) (mvarId : MVarId) : Bool :=
match mctx.lDepth.find? mvarId with
| some d => d == mctx.depth
| _ => panic! "unknown universe metavariable"
def isExprAssignable (mctx : MetavarContext) (mvarId : MVarId) : Bool :=
let decl := mctx.getDecl mvarId;
decl.depth == mctx.depth
def incDepth (mctx : MetavarContext) : MetavarContext :=
{ mctx with depth := mctx.depth + 1 }
/-- Return true iff the given level contains an assigned metavariable. -/
def hasAssignedLevelMVar (mctx : MetavarContext) : Level → Bool
| Level.succ lvl _ => lvl.hasMVar && hasAssignedLevelMVar lvl
| Level.max lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignedLevelMVar lvl₁) || (lvl₂.hasMVar && hasAssignedLevelMVar lvl₂)
| Level.imax lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignedLevelMVar lvl₁) || (lvl₂.hasMVar && hasAssignedLevelMVar lvl₂)
| Level.mvar mvarId _ => mctx.isLevelAssigned mvarId
| Level.zero _ => false
| Level.param _ _ => false
/-- Return `true` iff expression contains assigned (level/expr) metavariables or delayed assigned mvars -/
def hasAssignedMVar (mctx : MetavarContext) : Expr → Bool
| Expr.const _ lvls _ => lvls.any (hasAssignedLevelMVar mctx)
| Expr.sort lvl _ => hasAssignedLevelMVar mctx lvl
| Expr.app f a _ => (f.hasMVar && hasAssignedMVar f) || (a.hasMVar && hasAssignedMVar a)
| Expr.letE _ t v b _ => (t.hasMVar && hasAssignedMVar t) || (v.hasMVar && hasAssignedMVar v) || (b.hasMVar && hasAssignedMVar b)
| Expr.forallE _ d b _ => (d.hasMVar && hasAssignedMVar d) || (b.hasMVar && hasAssignedMVar b)
| Expr.lam _ d b _ => (d.hasMVar && hasAssignedMVar d) || (b.hasMVar && hasAssignedMVar b)
| Expr.fvar _ _ => false
| Expr.bvar _ _ => false
| Expr.lit _ _ => false
| Expr.mdata _ e _ => e.hasMVar && hasAssignedMVar e
| Expr.proj _ _ e _ => e.hasMVar && hasAssignedMVar e
| Expr.mvar mvarId _ => mctx.isExprAssigned mvarId || mctx.isDelayedAssigned mvarId
| Expr.localE _ _ _ _ => unreachable!
/-- Return true iff the given level contains a metavariable that can be assigned. -/
def hasAssignableLevelMVar (mctx : MetavarContext) : Level → Bool
| Level.succ lvl _ => lvl.hasMVar && hasAssignableLevelMVar lvl
| Level.max lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignableLevelMVar lvl₁) || (lvl₂.hasMVar && hasAssignableLevelMVar lvl₂)
| Level.imax lvl₁ lvl₂ _ => (lvl₁.hasMVar && hasAssignableLevelMVar lvl₁) || (lvl₂.hasMVar && hasAssignableLevelMVar lvl₂)
| Level.mvar mvarId _ => mctx.isLevelAssignable mvarId
| Level.zero _ => false
| Level.param _ _ => false
/-- Return `true` iff expression contains a metavariable that can be assigned. -/
def hasAssignableMVar (mctx : MetavarContext) : Expr → Bool
| Expr.const _ lvls _ => lvls.any (hasAssignableLevelMVar mctx)
| Expr.sort lvl _ => hasAssignableLevelMVar mctx lvl
| Expr.app f a _ => (f.hasMVar && hasAssignableMVar f) || (a.hasMVar && hasAssignableMVar a)
| Expr.letE _ t v b _ => (t.hasMVar && hasAssignableMVar t) || (v.hasMVar && hasAssignableMVar v) || (b.hasMVar && hasAssignableMVar b)
| Expr.forallE _ d b _ => (d.hasMVar && hasAssignableMVar d) || (b.hasMVar && hasAssignableMVar b)
| Expr.lam _ d b _ => (d.hasMVar && hasAssignableMVar d) || (b.hasMVar && hasAssignableMVar b)
| Expr.fvar _ _ => false
| Expr.bvar _ _ => false
| Expr.lit _ _ => false
| Expr.mdata _ e _ => e.hasMVar && hasAssignableMVar e
| Expr.proj _ _ e _ => e.hasMVar && hasAssignableMVar e
| Expr.mvar mvarId _ => mctx.isExprAssignable mvarId
| Expr.localE _ _ _ _ => unreachable!
partial def instantiateLevelMVars : Level → StateM MetavarContext Level
| lvl@(Level.succ lvl₁ _) => do lvl₁ ← instantiateLevelMVars lvl₁; pure (Level.updateSucc! lvl lvl₁)
| lvl@(Level.max lvl₁ lvl₂ _) => do lvl₁ ← instantiateLevelMVars lvl₁; lvl₂ ← instantiateLevelMVars lvl₂; pure (Level.updateMax! lvl lvl₁ lvl₂)
| lvl@(Level.imax lvl₁ lvl₂ _) => do lvl₁ ← instantiateLevelMVars lvl₁; lvl₂ ← instantiateLevelMVars lvl₂; pure (Level.updateIMax! lvl lvl₁ lvl₂)
| lvl@(Level.mvar mvarId _) => do
mctx ← get;
match getLevelAssignment? mctx mvarId with
| some newLvl =>
if !newLvl.hasMVar then pure newLvl
else do
newLvl' ← instantiateLevelMVars newLvl;
modify $ fun mctx => mctx.assignLevel mvarId newLvl';
pure newLvl'
| none => pure lvl
| lvl => pure lvl
namespace InstantiateExprMVars
private abbrev M := StateM (WithHashMapCache Expr Expr MetavarContext)
@[inline] def instantiateLevelMVars (lvl : Level) : M Level :=
WithHashMapCache.fromState $ MetavarContext.instantiateLevelMVars lvl
@[inline] private def visit (f : Expr → M Expr) (e : Expr) : M Expr :=
if !e.hasMVar then pure e else checkCache e f
@[inline] private def getMCtx : M MetavarContext := do
s ← get; pure s.state
@[inline] private def modifyCtx (f : MetavarContext → MetavarContext) : M Unit :=
modify $ fun s => { s with state := f s.state }
/-- instantiateExprMVars main function -/
partial def main : Expr → M Expr
| e@(Expr.proj _ _ s _) => do s ← visit main s; pure (e.updateProj! s)
| e@(Expr.forallE _ d b _) => do d ← visit main d; b ← visit main b; pure (e.updateForallE! d b)
| e@(Expr.lam _ d b _) => do d ← visit main d; b ← visit main b; pure (e.updateLambdaE! d b)
| e@(Expr.letE _ t v b _) => do t ← visit main t; v ← visit main v; b ← visit main b; pure (e.updateLet! t v b)
| e@(Expr.const _ lvls _) => do lvls ← lvls.mapM instantiateLevelMVars; pure (e.updateConst! lvls)
| e@(Expr.sort lvl _) => do lvl ← instantiateLevelMVars lvl; pure (e.updateSort! lvl)
| e@(Expr.mdata _ b _) => do b ← visit main b; pure (e.updateMData! b)
| e@(Expr.app _ _ _) => e.withApp $ fun f args => do
let instArgs (f : Expr) : M Expr := do {
args ← args.mapM (visit main);
pure (mkAppN f args)
};
let instApp : M Expr := do {
let wasMVar := f.isMVar;
f ← visit main f;
if wasMVar && f.isLambda then
/- Some of the arguments in args are irrelevant after we beta reduce. -/
visit main (f.betaRev args.reverse)
else
instArgs f
};
match f with
| Expr.mvar mvarId _ => do
mctx ← getMCtx;
match mctx.getDelayedAssignment? mvarId with
| none => instApp
| some { fvars := fvars, val := val, .. } =>
/-
Apply "delayed substitution" (i.e., delayed assignment + application).
That is, `f` is some metavariable `?m`, that is delayed assigned to `val`.
If after instantiating `val`, we obtain `newVal`, and `newVal` does not contain
metavariables, we replace the free variables `fvars` in `newVal` with the first
`fvars.size` elements of `args`. -/
if fvars.size > args.size then
/- We don't have sufficient arguments for instantiating the free variables `fvars`.
This can only happy if a tactic or elaboration function is not implemented correctly.
We decided to not use `panic!` here and report it as an error in the frontend
when we are checking for unassigned metavariables in an elaborated term. -/
instArgs f
else do
newVal ← visit main val;
if newVal.hasExprMVar then
instArgs f
else do
args ← args.mapM (visit main);
/-
Example: suppose we have
`?m t1 t2 t3`
That is, `f := ?m` and `args := #[t1, t2, t3]`
Morever, `?m` is delayed assigned
`?m #[x, y] := f x y`
where, `fvars := #[x, y]` and `newVal := f x y`.
After abstracting `newVal`, we have `f (Expr.bvar 0) (Expr.bvar 1)`.
After `instantiaterRevRange 0 2 args`, we have `f t1 t2`.
After `mkAppRange 2 3`, we have `f t1 t2 t3` -/
let newVal := newVal.abstract fvars;
let result := newVal.instantiateRevRange 0 fvars.size args;
let result := mkAppRange result fvars.size args.size args;
pure $ result
| _ => instApp
| e@(Expr.mvar mvarId _) => checkCache e $ fun e => do
mctx ← getMCtx;
match mctx.getExprAssignment? mvarId with
| some newE => do
newE' ← visit main newE;
modifyCtx $ fun mctx => mctx.assignExpr mvarId newE';
pure newE'
| none => pure e
| e => pure e
end InstantiateExprMVars
def instantiateMVars (mctx : MetavarContext) (e : Expr) : Expr × MetavarContext :=
if !e.hasMVar then (e, mctx)
else (WithHashMapCache.toState $ InstantiateExprMVars.main e).run mctx
def instantiateLCtxMVars (mctx : MetavarContext) (lctx : LocalContext) : LocalContext × MetavarContext :=
lctx.foldl
(fun (result : LocalContext × MetavarContext) ldecl =>
let (lctx, mctx) := result;
match ldecl with
| LocalDecl.cdecl _ fvarId userName type bi =>
let (type, mctx) := mctx.instantiateMVars type;
(lctx.mkLocalDecl fvarId userName type bi, mctx)
| LocalDecl.ldecl _ fvarId userName type value nonDep =>
let (type, mctx) := mctx.instantiateMVars type;
let (value, mctx) := mctx.instantiateMVars value;
(lctx.mkLetDecl fvarId userName type value nonDep, mctx))
({}, mctx)
def instantiateMVarDeclMVars (mctx : MetavarContext) (mvarId : MVarId) : MetavarContext :=
let mvarDecl := mctx.getDecl mvarId;
let (lctx, mctx) := mctx.instantiateLCtxMVars mvarDecl.lctx;
let (type, mctx) := mctx.instantiateMVars mvarDecl.type;
{ mctx with decls := mctx.decls.insert mvarId { mvarDecl with lctx := lctx, type := type } }
namespace DependsOn
private abbrev M := StateM ExprSet
private def visit? (e : Expr) : M Bool :=
if !e.hasMVar && !e.hasFVar then
pure false
else do
s ← get;
if s.contains e then
pure false
else do
modify $ fun s => s.insert e;
pure true
@[inline] private def visit (main : Expr → M Bool) (e : Expr) : M Bool :=
condM (visit? e) (main e) (pure false)
@[specialize] private partial def dep (mctx : MetavarContext) (p : FVarId → Bool) : Expr → M Bool
| e@(Expr.proj _ _ s _) => visit dep s
| e@(Expr.forallE _ d b _) => visit dep d <||> visit dep b
| e@(Expr.lam _ d b _) => visit dep d <||> visit dep b
| e@(Expr.letE _ t v b _) => visit dep t <||> visit dep v <||> visit dep b
| e@(Expr.mdata _ b _) => visit dep b
| e@(Expr.app f a _) => visit dep a <||> if f.isApp then dep f else visit dep f
| e@(Expr.mvar mvarId _) =>
match mctx.getExprAssignment? mvarId with
| some a => visit dep a
| none =>
let lctx := (mctx.getDecl mvarId).lctx;
pure $ lctx.any $ fun decl => p decl.fvarId
| e@(Expr.fvar fvarId _) => pure $ p fvarId
| e => pure false
@[inline] partial def main (mctx : MetavarContext) (p : FVarId → Bool) (e : Expr) : M Bool :=
if !e.hasFVar && !e.hasMVar then pure false else dep mctx p e
end DependsOn
/--
Return `true` iff `e` depends on a free variable `x` s.t. `p x` is `true`.
For each metavariable `?m` occurring in `x`
1- If `?m := t`, then we visit `t` looking for `x`
2- If `?m` is unassigned, then we consider the worst case and check whether `x` is in the local context of `?m`.
This case is a "may dependency". That is, we may assign a term `t` to `?m` s.t. `t` contains `x`. -/
@[inline] def findExprDependsOn (mctx : MetavarContext) (e : Expr) (p : FVarId → Bool) : Bool :=
(DependsOn.main mctx p e).run' {}
/--
Similar to `findExprDependsOn`, but checks the expressions in the given local declaration
depends on a free variable `x` s.t. `p x` is `true`. -/
@[inline] def findLocalDeclDependsOn (mctx : MetavarContext) (localDecl : LocalDecl) (p : FVarId → Bool) : Bool :=
match localDecl with
| LocalDecl.cdecl _ _ _ type _ => findExprDependsOn mctx type p
| LocalDecl.ldecl _ _ _ type value _ => (DependsOn.main mctx p type <||> DependsOn.main mctx p value).run' {}
def exprDependsOn (mctx : MetavarContext) (e : Expr) (fvarId : FVarId) : Bool :=
findExprDependsOn mctx e $ fun fvarId' => fvarId == fvarId'
def localDeclDependsOn (mctx : MetavarContext) (localDecl : LocalDecl) (fvarId : FVarId) : Bool :=
findLocalDeclDependsOn mctx localDecl $ fun fvarId' => fvarId == fvarId'
namespace MkBinding
inductive Exception
| revertFailure (mctx : MetavarContext) (lctx : LocalContext) (toRevert : Array Expr) (decl : LocalDecl)
def Exception.toString : Exception → String
| Exception.revertFailure _ lctx toRevert decl =>
"failed to revert "
++ toString (toRevert.map (fun x => "'" ++ toString (lctx.getFVar! x).userName ++ "'"))
++ ", '" ++ toString decl.userName ++ "' depends on them, and it is an auxiliary declaration created by the elaborator"
++ " (possible solution: use tactic 'clear' to remove '" ++ toString decl.userName ++ "' from local context)"
instance Exception.hasToString : HasToString Exception := ⟨Exception.toString⟩
/--
`MkBinding` and `elimMVarDepsAux` are mutually recursive, but `cache` is only used at `elimMVarDepsAux`.
We use a single state object for convenience.
We have a `NameGenerator` because we need to generate fresh auxiliary metavariables. -/
structure State :=
(mctx : MetavarContext)
(ngen : NameGenerator)
(cache : HashMap Expr Expr := {}) --
abbrev MCore := EStateM Exception State
abbrev M := ReaderT Bool (EStateM Exception State)
def preserveOrder : M Bool := read
instance : MonadHashMapCacheAdapter Expr Expr M :=
{ getCache := do s ← get; pure s.cache,
modifyCache := fun f => modify $ fun s => { s with cache := f s.cache } }
/-- Return the local declaration of the free variable `x` in `xs` with the smallest index -/
private def getLocalDeclWithSmallestIdx (lctx : LocalContext) (xs : Array Expr) : LocalDecl :=
let d : LocalDecl := lctx.getFVar! $ xs.get! 0;
xs.foldlFrom
(fun d x =>
let decl := lctx.getFVar! x;
if decl.index < d.index then decl else d)
d 1
/-- Given `toRevert` an array of free variables s.t. `lctx` contains their declarations,
return a new array of free variables that contains `toRevert` and all free variables
in `lctx` that may depend on `toRevert`.
Remark: the result is sorted by `LocalDecl` indices. -/
private def collectDeps (mctx : MetavarContext) (lctx : LocalContext) (toRevert : Array Expr) (preserveOrder : Bool) : Except Exception (Array Expr) :=
if toRevert.size == 0 then pure toRevert
else do
when preserveOrder $ do {
-- Make sure none of `toRevert` is an AuxDecl
-- Make sure toRevert[j] does not depend on toRevert[i] for j > i
toRevert.size.forM $ fun i => do
let fvar := toRevert.get! i;
let decl := lctx.getFVar! fvar;
when decl.binderInfo.isAuxDecl $
throw (Exception.revertFailure mctx lctx toRevert decl);
i.forM $ fun j =>
let prevFVar := toRevert.get! j;
let prevDecl := lctx.getFVar! prevFVar;
when (localDeclDependsOn mctx prevDecl fvar.fvarId!) $
throw (Exception.revertFailure mctx lctx toRevert prevDecl)
};
let newToRevert := if preserveOrder then toRevert else Array.mkEmpty toRevert.size;
let firstDeclToVisit := getLocalDeclWithSmallestIdx lctx toRevert;
let initSize := newToRevert.size;
lctx.foldlFromM
(fun (newToRevert : Array Expr) decl =>
if initSize.any $ fun i => decl.fvarId == (newToRevert.get! i).fvarId! then pure newToRevert
else if toRevert.any (fun x => decl.fvarId == x.fvarId!) then
pure (newToRevert.push decl.toExpr)
else if findLocalDeclDependsOn mctx decl (fun fvarId => newToRevert.any $ fun x => x.fvarId! == fvarId) then
if decl.binderInfo.isAuxDecl then
throw (Exception.revertFailure mctx lctx toRevert decl)
else
pure (newToRevert.push decl.toExpr)
else
pure newToRevert)
newToRevert
firstDeclToVisit
/-- Create a new `LocalContext` by removing the free variables in `toRevert` from `lctx`.
We use this function when we create auxiliary metavariables at `elimMVarDepsAux`. -/
private def reduceLocalContext (lctx : LocalContext) (toRevert : Array Expr) : LocalContext :=
toRevert.foldr
(fun x lctx => lctx.erase x.fvarId!)
lctx
@[inline] private def visit (f : Expr → M Expr) (e : Expr) : M Expr :=
if !e.hasMVar then pure e else checkCache e f
@[inline] private def getMCtx : M MetavarContext := do
s ← get; pure s.mctx
/-- Return free variables in `xs` that are in the local context `lctx` -/
private def getInScope (lctx : LocalContext) (xs : Array Expr) : Array Expr :=
xs.foldl
(fun scope x =>
if lctx.contains x.fvarId! then
scope.push x
else
scope)
#[]
/-- Execute `x` with an empty cache, and then restore the original cache. -/
@[inline] private def withFreshCache {α} (x : M α) : M α := do
cache ← modifyGet $ fun s => (s.cache, { s with cache := {} });
a ← x;
modify $ fun s => { s with cache := cache };
pure a
@[inline] private def abstractRangeAux (elimMVarDeps : Expr → M Expr) (xs : Array Expr) (i : Nat) (e : Expr) : M Expr := do
e ← elimMVarDeps e;
pure (e.abstractRange i xs)
private def mkAuxMVarType (elimMVarDeps : Expr → M Expr) (lctx : LocalContext) (xs : Array Expr) (kind : MetavarKind) (e : Expr) : M Expr := do
e ← abstractRangeAux elimMVarDeps xs xs.size e;
xs.size.foldRevM
(fun i e =>
let x := xs.get! i;
match lctx.getFVar! x with
| LocalDecl.cdecl _ _ n type bi => do
let type := type.headBeta;
type ← abstractRangeAux elimMVarDeps xs i type;
pure $ Lean.mkForall n bi type e
| LocalDecl.ldecl _ _ n type value nonDep => do
let type := type.headBeta;
type ← abstractRangeAux elimMVarDeps xs i type;
value ← abstractRangeAux elimMVarDeps xs i value;
let e := mkLet n type value e nonDep;
match kind with
| MetavarKind.syntheticOpaque =>
-- See "Gruesome details" section in the beginning of the file
let e := e.liftLooseBVars 0 1;
pure $ mkForall n BinderInfo.default type e
| _ => pure e)
e
/--
Create an application `mvar ys` where `ys` are the free variables.
See "Gruesome details" in the beginning of the file for understanding
how let-decl free variables are handled. -/
private def mkMVarApp (lctx : LocalContext) (mvar : Expr) (xs : Array Expr) (kind : MetavarKind) : Expr :=
xs.foldl
(fun e x =>
match kind with
| MetavarKind.syntheticOpaque => mkApp e x
| _ => if (lctx.getFVar! x).isLet then e else mkApp e x)
mvar
private def mkAuxMVar (lctx : LocalContext) (localInsts : LocalInstances) (type : Expr) (kind : MetavarKind) : M MVarId := do
s ← get;
let mvarId := s.ngen.curr;
modify $ fun s => { s with mctx := s.mctx.addExprMVarDecl mvarId Name.anonymous lctx localInsts type kind, ngen := s.ngen.next };
pure mvarId
/-- Return true iff some `e` in `es` depends on `fvarId` -/
private def anyDependsOn (mctx : MetavarContext) (es : Array Expr) (fvarId : FVarId) : Bool :=
es.any $ fun e => exprDependsOn mctx e fvarId
private partial def elimMVarDepsApp (elimMVarDepsAux : Expr → M Expr) (xs : Array Expr) : Expr → Array Expr → M Expr
| f, args =>
match f with
| Expr.mvar mvarId _ => do
let processDefault (newF : Expr) : M Expr := do {
if newF.isLambda then do
args ← args.mapM (visit elimMVarDepsAux);
elimMVarDepsAux $ newF.betaRev args.reverse
else if newF == f then do
args ← args.mapM (visit elimMVarDepsAux);
pure $ mkAppN newF args
else
elimMVarDepsApp newF args
};
mctx ← getMCtx;
match mctx.getExprAssignment? mvarId with
| some val => processDefault val
| _ =>
let mvarDecl := mctx.getDecl mvarId;
let mvarLCtx := mvarDecl.lctx;
let toRevert := getInScope mvarLCtx xs;
if toRevert.size == 0 then
processDefault f
else
let newMVarKind := if !mctx.isExprAssignable mvarId then MetavarKind.syntheticOpaque else mvarDecl.kind;
/- If `mvarId` is the lhs of a delayed assignment `?m #[x_1, ... x_n] := val`,
then `nestedFVars` is `#[x_1, ..., x_n]`.
In this case, we produce a new `syntheticOpaque` metavariable `?n` and a delayed assignment
```
?n #[y_1, ..., y_m, x_1, ... x_n] := ?m x_1 ... x_n
```
where `#[y_1, ..., y_m]` is `toRevert` after `collectDeps`.
Remark: `newMVarKind != MetavarKind.syntheticOpaque ==> nestedFVars == #[]`
-/
let continue (nestedFVars : Array Expr) : M Expr := do {
args ← args.mapM (visit elimMVarDepsAux);
preserve ← preserveOrder;
match collectDeps mctx mvarLCtx toRevert preserve with
| Except.error ex => throw ex
| Except.ok toRevert => do
let newMVarLCtx := reduceLocalContext mvarLCtx toRevert;
let newLocalInsts := mvarDecl.localInstances.filter $ fun inst => toRevert.all $ fun x => inst.fvar != x;
newMVarType ← mkAuxMVarType elimMVarDepsAux mvarLCtx toRevert newMVarKind mvarDecl.type;
newMVarId ← mkAuxMVar newMVarLCtx newLocalInsts newMVarType newMVarKind;
let newMVar := mkMVar newMVarId;
let result := mkMVarApp mvarLCtx newMVar toRevert newMVarKind;
match newMVarKind with
| MetavarKind.syntheticOpaque =>
modify $ fun s => { s with mctx := assignDelayed s.mctx newMVarId mvarLCtx (toRevert ++ nestedFVars) (mkAppN f nestedFVars) }
| _ =>
modify $ fun s => { s with mctx := assignExpr s.mctx mvarId result };
pure (mkAppN result args)
};
if !mvarDecl.kind.isSyntheticOpaque then
continue #[]
else match mctx.getDelayedAssignment? mvarId with
| none => continue #[]
| some { fvars := fvars, .. } => continue fvars
| _ => do
f ← visit elimMVarDepsAux f;
args ← args.mapM (visit elimMVarDepsAux);
pure (mkAppN f args)
private partial def elimMVarDepsAux (xs : Array Expr) : Expr → M Expr
| e@(Expr.proj _ _ s _) => do s ← visit elimMVarDepsAux s; pure (e.updateProj! s)
| e@(Expr.forallE _ d b _) => do d ← visit elimMVarDepsAux d; b ← visit elimMVarDepsAux b; pure (e.updateForallE! d b)
| e@(Expr.lam _ d b _) => do d ← visit elimMVarDepsAux d; b ← visit elimMVarDepsAux b; pure (e.updateLambdaE! d b)
| e@(Expr.letE _ t v b _) => do t ← visit elimMVarDepsAux t; v ← visit elimMVarDepsAux v; b ← visit elimMVarDepsAux b; pure (e.updateLet! t v b)
| e@(Expr.mdata _ b _) => do b ← visit elimMVarDepsAux b; pure (e.updateMData! b)
| e@(Expr.app _ _ _) => e.withApp $ fun f args => elimMVarDepsApp elimMVarDepsAux xs f args
| e@(Expr.mvar mvarId _) => elimMVarDepsApp elimMVarDepsAux xs e #[]
| e => pure e
partial def elimMVarDeps (xs : Array Expr) (e : Expr) : M Expr :=
if !e.hasMVar then
pure e
else
withFreshCache $ elimMVarDepsAux xs e
/--
Similar to `Expr.abstractRange`, but handles metavariables correctly.
It uses `elimMVarDeps` to ensure `e` and the type of the free variables `xs` do not
contain a metavariable `?m` s.t. local context of `?m` contains a free variable in `xs`.
`elimMVarDeps` is defined later in this file. -/
@[inline] private def abstractRange (xs : Array Expr) (i : Nat) (e : Expr) : M Expr := do
e ← elimMVarDeps xs e;
pure (e.abstractRange i xs)
/--
Similar to `LocalContext.mkBinding`, but handles metavariables correctly.
If `usedOnly == false` then `forall` and `lambda` are created only for used variables. -/
@[specialize] def mkBinding (isLambda : Bool) (lctx : LocalContext) (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) : M (Expr × Nat) := do
e ← abstractRange xs xs.size e;
xs.size.foldRevM
(fun i (p : Expr × Nat) =>
let (e, num) := p;
let x := xs.get! i;
match lctx.getFVar! x with
| LocalDecl.cdecl _ _ n type bi =>
if !usedOnly || e.hasLooseBVar 0 then do
let type := type.headBeta;
type ← abstractRange xs i type;
if isLambda then
pure (Lean.mkLambda n bi type e, num + 1)
else
pure (Lean.mkForall n bi type e, num + 1)
else
pure (e.lowerLooseBVars 1 1, num)
| LocalDecl.ldecl _ _ n type value nonDep => do
if e.hasLooseBVar 0 then do
type ← abstractRange xs i type;
value ← abstractRange xs i value;
pure (mkLet n type value e nonDep, num + 1)
else
pure (e.lowerLooseBVars 1 1, num))
(e, 0)
end MkBinding
abbrev MkBindingM := ReaderT LocalContext MkBinding.MCore
def elimMVarDeps (xs : Array Expr) (e : Expr) (preserveOrder : Bool) : MkBindingM Expr :=
fun _ => MkBinding.elimMVarDeps xs e preserveOrder
def mkBinding (isLambda : Bool) (xs : Array Expr) (e : Expr) (usedOnly : Bool := false) : MkBindingM (Expr × Nat) :=
fun lctx => MkBinding.mkBinding isLambda lctx xs e usedOnly false
@[inline] def mkLambda (xs : Array Expr) (e : Expr) : MkBindingM Expr := do
(e, _) ← mkBinding true xs e;
pure e
@[inline] def mkForall (xs : Array Expr) (e : Expr) : MkBindingM Expr := do
(e, _) ← mkBinding false xs e;
pure e
@[inline] def mkForallUsedOnly (xs : Array Expr) (e : Expr) : MkBindingM (Expr × Nat) := do
mkBinding false xs e true
/--
`isWellFormed mctx lctx e` return true if
- All locals in `e` are declared in `lctx`
- All metavariables `?m` in `e` have a local context which is a subprefix of `lctx` or are assigned, and the assignment is well-formed. -/
partial def isWellFormed (mctx : MetavarContext) (lctx : LocalContext) : Expr → Bool
| Expr.mdata _ e _ => isWellFormed e
| Expr.proj _ _ e _ => isWellFormed e
| e@(Expr.app f a _) => (e.hasExprMVar || e.hasFVar) && isWellFormed f && isWellFormed a
| e@(Expr.lam _ d b _) => (e.hasExprMVar || e.hasFVar) && isWellFormed d && isWellFormed b
| e@(Expr.forallE _ d b _) => (e.hasExprMVar || e.hasFVar) && isWellFormed d && isWellFormed b
| e@(Expr.letE _ t v b _) => (e.hasExprMVar || e.hasFVar) && isWellFormed t && isWellFormed v && isWellFormed b
| Expr.const _ _ _ => true
| Expr.bvar _ _ => true
| Expr.sort _ _ => true
| Expr.lit _ _ => true
| Expr.mvar mvarId _ =>
let mvarDecl := mctx.getDecl mvarId;
if mvarDecl.lctx.isSubPrefixOf lctx then true
else match mctx.getExprAssignment? mvarId with
| none => false
| some v => isWellFormed v
| Expr.fvar fvarId _ => lctx.contains fvarId
| Expr.localE _ _ _ _ => unreachable!
namespace LevelMVarToParam
structure Context :=
(paramNamePrefix : Name)
(alreadyUsedPred : Name → Bool)
structure State :=
(mctx : MetavarContext)
(paramNames : Array Name := #[])
(nextParamIdx : Nat)
abbrev M := ReaderT Context $ StateM State
partial def mkParamName : Unit → M Name
| _ => do
ctx ← read;
s ← get;
let newParamName := ctx.paramNamePrefix.appendIndexAfter s.nextParamIdx;
if ctx.alreadyUsedPred newParamName then do
modify $ fun s => { s with nextParamIdx := s.nextParamIdx + 1 };
mkParamName ()
else do
modify $ fun s => { s with nextParamIdx := s.nextParamIdx + 1, paramNames := s.paramNames.push newParamName };
pure newParamName
partial def visitLevel : Level → M Level
| u@(Level.succ v _) => do v ← visitLevel v; pure (u.updateSucc v rfl)
| u@(Level.max v₁ v₂ _) => do v₁ ← visitLevel v₁; v₂ ← visitLevel v₂; pure (u.updateMax v₁ v₂ rfl)
| u@(Level.imax v₁ v₂ _) => do v₁ ← visitLevel v₁; v₂ ← visitLevel v₂; pure (u.updateIMax v₁ v₂ rfl)
| u@(Level.zero _) => pure u
| u@(Level.param _ _) => pure u
| u@(Level.mvar mvarId _) => do
s ← get;
match s.mctx.getLevelAssignment? mvarId with
| some v => visitLevel v
| none => do
p ← mkParamName ();
let p := mkLevelParam p;
modify $ fun s => { s with mctx := s.mctx.assignLevel mvarId p };
pure p
@[inline] private def visit (f : Expr → M Expr) (e : Expr) : M Expr :=
if e.hasMVar then f e else pure e
partial def main : Expr → M Expr
| e@(Expr.proj _ _ s _) => do s ← visit main s; pure (e.updateProj! s)
| e@(Expr.forallE _ d b _) => do d ← visit main d; b ← visit main b; pure (e.updateForallE! d b)
| e@(Expr.lam _ d b _) => do d ← visit main d; b ← visit main b; pure (e.updateLambdaE! d b)
| e@(Expr.letE _ t v b _) => do t ← visit main t; v ← visit main v; b ← visit main b; pure (e.updateLet! t v b)
| e@(Expr.app f a _) => do f ← visit main f; a ← visit main a; pure (e.updateApp! f a)
| e@(Expr.mdata _ b _) => do b ← visit main b; pure (e.updateMData! b)
| e@(Expr.const _ us _) => do us ← us.mapM visitLevel; pure (e.updateConst! us)
| e@(Expr.sort u _) => do u ← visitLevel u; pure (e.updateSort! u)
| e@(Expr.mvar mvarId _) => do
s ← get;
match s.mctx.getExprAssignment? mvarId with
| some v => visit main v
| none => pure e
| e => pure e
end LevelMVarToParam
structure UnivMVarParamResult :=
(mctx : MetavarContext)
(newParamNames : Array Name)
(nextParamIdx : Nat)
(expr : Expr)
def levelMVarToParam (mctx : MetavarContext) (alreadyUsedPred : Name → Bool) (e : Expr) (paramNamePrefix : Name := `u) (nextParamIdx : Nat := 1)
: UnivMVarParamResult :=
let (e, s) := LevelMVarToParam.main e { paramNamePrefix := paramNamePrefix, alreadyUsedPred := alreadyUsedPred } { mctx := mctx, nextParamIdx := nextParamIdx };
{ mctx := s.mctx,
newParamNames := s.paramNames,
nextParamIdx := s.nextParamIdx,
expr := e }
end MetavarContext
class MonadMCtx (m : Type → Type) :=
(getMCtx : m MetavarContext)
export MonadMCtx (getMCtx)
instance monadMCtxTrans (m n) [MonadMCtx m] [MonadLift m n] : MonadMCtx n :=
{ getMCtx := liftM (getMCtx : m _) }
end Lean
|
887f065240b0af6e557fc403cc77f1dac9e13a20 | b561a44b48979a98df50ade0789a21c79ee31288 | /src/Lean/Parser/Command.lean | 8dbcc7c93f3b6267b54557299f9bea585847b812 | [
"Apache-2.0"
] | permissive | 3401ijk/lean4 | 97659c475ebd33a034fed515cb83a85f75ccfb06 | a5b1b8de4f4b038ff752b9e607b721f15a9a4351 | refs/heads/master | 1,693,933,007,651 | 1,636,424,845,000 | 1,636,424,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 11,301 | 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, Sebastian Ullrich
-/
import Lean.Parser.Term
import Lean.Parser.Do
namespace Lean
namespace Parser
/--
Syntax quotation for terms and (lists of) commands. We prefer terms, so ambiguous quotations like
`` `($x $y) `` will be parsed as an application, not two commands. Use `` `($x:command $y:command) `` instead.
Multiple command will be put in a `` `null `` node, but a single command will not (so that you can directly
match against a quotation in a command kind's elaborator). -/
-- TODO: use two separate quotation parsers with parser priorities instead
@[builtinTermParser] def Term.quot := leading_parser "`(" >> incQuotDepth (termParser <|> many1Unbox commandParser) >> ")"
@[builtinTermParser] def Term.precheckedQuot := leading_parser "`" >> Term.quot
namespace Command
/--
A mutual block may be broken in different cliques, we identify them using an `ident` (an element of the clique)
We provide two kinds of hints to the termination checker:
1- A wellfounded relation (`p` is `termParser`)
2- A tactic for proving the recursive applications are "decreasing" (`p` is `tacticSeq`)
-/
def terminationHintMany (p : Parser) := leading_parser atomic (lookahead (ident >> " => ")) >> many1Indent (group (ppLine >> ident >> " => " >> p >> optional ";"))
def terminationHint1 (p : Parser) := leading_parser p
def terminationHint (p : Parser) := terminationHintMany p <|> terminationHint1 p
def terminationBy := leading_parser "termination_by " >> terminationHint termParser
def decreasingBy := leading_parser "decreasing_by " >> terminationHint Tactic.tacticSeq
def terminationSuffix := optional terminationBy >> optional decreasingBy
@[builtinCommandParser]
def moduleDoc := leading_parser ppDedent $ "/-!" >> commentBody >> ppLine
def namedPrio := leading_parser (atomic ("(" >> nonReservedSymbol "priority") >> " := " >> priorityParser >> ")")
def optNamedPrio := optional namedPrio
def «private» := leading_parser "private "
def «protected» := leading_parser "protected "
def visibility := «private» <|> «protected»
def «noncomputable» := leading_parser "noncomputable "
def «unsafe» := leading_parser "unsafe "
def «partial» := leading_parser "partial "
def «nonrec» := leading_parser "nonrec "
def declModifiers (inline : Bool) := leading_parser optional docComment >> optional (Term.«attributes» >> if inline then skip else ppDedent ppLine) >> optional visibility >> optional «noncomputable» >> optional «unsafe» >> optional («partial» <|> «nonrec»)
def declId := leading_parser ident >> optional (".{" >> sepBy1 ident ", " >> "}")
def declSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.typeSpec
def optDeclSig := leading_parser many (ppSpace >> (Term.simpleBinderWithoutType <|> Term.bracketedBinder)) >> Term.optType
def declValSimple := leading_parser " :=\n" >> termParser >> optional Term.whereDecls
def declValEqns := leading_parser Term.matchAltsWhereDecls
def declVal := declValSimple <|> declValEqns <|> Term.whereDecls
def «abbrev» := leading_parser "abbrev " >> declId >> optDeclSig >> declVal
def optDefDeriving := optional (atomic ("deriving " >> notSymbol "instance") >> sepBy1 ident ", ")
def «def» := leading_parser "def " >> declId >> optDeclSig >> declVal >> optDefDeriving >> terminationSuffix
def «theorem» := leading_parser "theorem " >> declId >> declSig >> declVal >> terminationSuffix
def «constant» := leading_parser "constant " >> declId >> declSig >> optional declValSimple
def «instance» := leading_parser Term.attrKind >> "instance " >> optNamedPrio >> optional declId >> declSig >> declVal >> terminationSuffix
def «axiom» := leading_parser "axiom " >> declId >> declSig
def «example» := leading_parser "example " >> declSig >> declVal
def inferMod := leading_parser atomic (symbol "{" >> "}")
def ctor := leading_parser "\n| " >> declModifiers true >> ident >> optional inferMod >> optDeclSig
def derivingClasses := sepBy1 (group (ident >> optional (" with " >> Term.structInst))) ", "
def optDeriving := leading_parser optional (atomic ("deriving " >> notSymbol "instance") >> derivingClasses)
def «inductive» := leading_parser "inductive " >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving
def classInductive := leading_parser atomic (group (symbol "class " >> "inductive ")) >> declId >> optDeclSig >> optional (symbol ":=" <|> "where") >> many ctor >> optDeriving
def structExplicitBinder := leading_parser atomic (declModifiers true >> "(") >> many1 ident >> optional inferMod >> optDeclSig >> optional (Term.binderTactic <|> Term.binderDefault) >> ")"
def structImplicitBinder := leading_parser atomic (declModifiers true >> "{") >> many1 ident >> optional inferMod >> declSig >> "}"
def structInstBinder := leading_parser atomic (declModifiers true >> "[") >> many1 ident >> optional inferMod >> declSig >> "]"
def structSimpleBinder := leading_parser atomic (declModifiers true >> ident) >> optional inferMod >> optDeclSig >> optional (Term.binderTactic <|> Term.binderDefault)
def structFields := leading_parser manyIndent (ppLine >> checkColGe >>(structExplicitBinder <|> structImplicitBinder <|> structInstBinder <|> structSimpleBinder))
def structCtor := leading_parser atomic (declModifiers true >> ident >> optional inferMod >> " :: ")
def structureTk := leading_parser "structure "
def classTk := leading_parser "class "
def «extends» := leading_parser " extends " >> sepBy1 termParser ", "
def «structure» := leading_parser
(structureTk <|> classTk) >> declId >> many Term.bracketedBinder >> optional «extends» >> Term.optType
>> optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields)
>> optDeriving
@[builtinCommandParser] def declaration := leading_parser
declModifiers false >> («abbrev» <|> «def» <|> «theorem» <|> «constant» <|> «instance» <|> «axiom» <|> «example» <|> «inductive» <|> classInductive <|> «structure»)
@[builtinCommandParser] def «deriving» := leading_parser "deriving " >> "instance " >> derivingClasses >> " for " >> sepBy1 ident ", "
@[builtinCommandParser] def «section» := leading_parser "section " >> optional ident
@[builtinCommandParser] def «namespace» := leading_parser "namespace " >> ident
@[builtinCommandParser] def «end» := leading_parser "end " >> optional ident
@[builtinCommandParser] def «variable» := leading_parser "variable" >> many1 Term.bracketedBinder
@[builtinCommandParser] def «universe» := leading_parser "universe " >> many1 ident
@[builtinCommandParser] def check := leading_parser "#check " >> termParser
@[builtinCommandParser] def check_failure := leading_parser "#check_failure " >> termParser -- Like `#check`, but succeeds only if term does not type check
@[builtinCommandParser] def reduce := leading_parser "#reduce " >> termParser
@[builtinCommandParser] def eval := leading_parser "#eval " >> termParser
@[builtinCommandParser] def synth := leading_parser "#synth " >> termParser
@[builtinCommandParser] def exit := leading_parser "#exit"
@[builtinCommandParser] def print := leading_parser "#print " >> (ident <|> strLit)
@[builtinCommandParser] def printAxioms := leading_parser "#print " >> nonReservedSymbol "axioms " >> ident
@[builtinCommandParser] def «resolve_name» := leading_parser "#resolve_name " >> ident
@[builtinCommandParser] def «init_quot» := leading_parser "init_quot"
def optionValue := nonReservedSymbol "true" <|> nonReservedSymbol "false" <|> strLit <|> numLit
@[builtinCommandParser] def «set_option» := leading_parser "set_option " >> ident >> ppSpace >> optionValue
def eraseAttr := leading_parser "-" >> rawIdent
@[builtinCommandParser] def «attribute» := leading_parser "attribute " >> "[" >> sepBy1 (eraseAttr <|> Term.attrInstance) ", " >> "] " >> many1 ident
@[builtinCommandParser] def «export» := leading_parser "export " >> ident >> "(" >> many1 ident >> ")"
def openHiding := leading_parser atomic (ident >> "hiding") >> many1 (checkColGt >> ident)
def openRenamingItem := leading_parser ident >> unicodeSymbol "→" "->" >> checkColGt >> ident
def openRenaming := leading_parser atomic (ident >> "renaming") >> sepBy1 openRenamingItem ", "
def openOnly := leading_parser atomic (ident >> "(") >> many1 ident >> ")"
def openSimple := leading_parser many1 (checkColGt >> ident)
def openScoped := leading_parser "scoped " >> many1 (checkColGt >> ident)
def openDecl := openHiding <|> openRenaming <|> openOnly <|> openSimple <|> openScoped
@[builtinCommandParser] def «open» := leading_parser withPosition ("open " >> openDecl)
@[builtinCommandParser] def «mutual» := leading_parser "mutual " >> many1 (ppLine >> notSymbol "end" >> commandParser) >> ppDedent (ppLine >> "end") >> terminationSuffix
@[builtinCommandParser] def «initialize» := leading_parser optional visibility >> "initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq
@[builtinCommandParser] def «builtin_initialize» := leading_parser optional visibility >> "builtin_initialize " >> optional (atomic (ident >> Term.typeSpec >> Term.leftArrow)) >> Term.doSeq
@[builtinCommandParser] def «in» := trailing_parser withOpen (" in " >> commandParser)
/-
This is an auxiliary command for generation constructor injectivity theorems for inductive types defined at `Prelude.lean`.
It is meant for bootstrapping purposes only. -/
@[builtinCommandParser] def genInjectiveTheorems := leading_parser "gen_injective_theorems% " >> ident
@[runBuiltinParserAttributeHooks] abbrev declModifiersF := declModifiers false
@[runBuiltinParserAttributeHooks] abbrev declModifiersT := declModifiers true
builtin_initialize
register_parser_alias "declModifiers" declModifiersF
register_parser_alias "nestedDeclModifiers" declModifiersT
register_parser_alias declId
register_parser_alias declSig
register_parser_alias declVal
register_parser_alias optDeclSig
register_parser_alias openDecl
end Command
namespace Term
@[builtinTermParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> termParser)
@[builtinTermParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> termParser
end Term
namespace Tactic
@[builtinTacticParser] def «open» := leading_parser:leadPrec "open " >> Command.openDecl >> withOpenDecl (" in " >> tacticSeq)
@[builtinTacticParser] def «set_option» := leading_parser:leadPrec "set_option " >> ident >> ppSpace >> Command.optionValue >> " in " >> tacticSeq
end Tactic
end Parser
end Lean
|
d19747ff0f884278d2051a6f4fda3853792c3947 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/data/set/image.lean | fba4f00b8d959dd2a61ef078e2d6d51f2c10fcf5 | [
"Apache-2.0"
] | permissive | kbuzzard/mathlib | 2ff9e85dfe2a46f4b291927f983afec17e946eb8 | 58537299e922f9c77df76cb613910914a479c1f7 | refs/heads/master | 1,685,313,702,744 | 1,683,974,212,000 | 1,683,974,212,000 | 128,185,277 | 1 | 0 | null | 1,522,920,600,000 | 1,522,920,600,000 | null | UTF-8 | Lean | false | false | 50,201 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import data.set.basic
/-!
# Images and preimages of sets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main definitions
* `preimage f t : set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β.
* `range f : set β` : the image of `univ` under `f`.
Also works for `{p : Prop} (f : p → α)` (unlike `image`)
## Notation
* `f ⁻¹' t` for `set.preimage f t`
* `f '' s` for `set.image f s`
## Tags
set, sets, image, preimage, pre-image, range
-/
open function set
universes u v
variables {α β γ : Type*} {ι ι' : Sort*}
namespace set
/-! ### Inverse image -/
/-- The preimage of `s : set β` by `f : α → β`, written `f ⁻¹' s`,
is the set of `x : α` such that `f x ∈ s`. -/
def preimage {α : Type u} {β : Type v} (f : α → β) (s : set β) : set α := {x | f x ∈ s}
infix ` ⁻¹' `:80 := preimage
section preimage
variables {f : α → β} {g : β → γ}
@[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl
@[simp] theorem mem_preimage {s : set β} {a : α} : (a ∈ f ⁻¹' s) ↔ (f a ∈ s) := iff.rfl
lemma preimage_congr {f g : α → β} {s : set β} (h : ∀ (x : α), f x = g x) : f ⁻¹' s = g ⁻¹' s :=
by { congr' with x, apply_assumption }
theorem preimage_mono {s t : set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t :=
assume x hx, h hx
@[simp] theorem preimage_univ : f ⁻¹' univ = univ := rfl
theorem subset_preimage_univ {s : set α} : s ⊆ f ⁻¹' univ := subset_univ _
@[simp] theorem preimage_inter {s t : set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl
@[simp] theorem preimage_union {s t : set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl
@[simp] theorem preimage_compl {s : set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl
@[simp] theorem preimage_diff (f : α → β) (s t : set β) :
f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl
@[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : set β) :
f ⁻¹' (s.ite t₁ t₂) = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) :=
rfl
@[simp] theorem preimage_set_of_eq {p : α → Prop} {f : β → α} : f ⁻¹' {a | p a} = {a | p (f a)} :=
rfl
@[simp] lemma preimage_id_eq : preimage (id : α → α) = id := rfl
theorem preimage_id {s : set α} : id ⁻¹' s = s := rfl
@[simp] theorem preimage_id' {s : set α} : (λ x, x) ⁻¹' s = s := rfl
@[simp] theorem preimage_const_of_mem {b : β} {s : set β} (h : b ∈ s) :
(λ (x : α), b) ⁻¹' s = univ :=
eq_univ_of_forall $ λ x, h
@[simp] theorem preimage_const_of_not_mem {b : β} {s : set β} (h : b ∉ s) :
(λ (x : α), b) ⁻¹' s = ∅ :=
eq_empty_of_subset_empty $ λ x hx, h hx
theorem preimage_const (b : β) (s : set β) [decidable (b ∈ s)] :
(λ (x : α), b) ⁻¹' s = if b ∈ s then univ else ∅ :=
by { split_ifs with hb hb, exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] }
theorem preimage_comp {s : set γ} : (g ∘ f) ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl
lemma preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl
@[simp] lemma preimage_iterate_eq {f : α → α} {n : ℕ} :
set.preimage (f^[n]) = ((set.preimage f)^[n]) :=
begin
induction n with n ih, { simp, },
rw [iterate_succ, iterate_succ', set.preimage_comp_eq, ih],
end
lemma preimage_preimage {g : β → γ} {f : α → β} {s : set γ} :
f ⁻¹' (g ⁻¹' s) = (λ x, g (f x)) ⁻¹' s :=
preimage_comp.symm
theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : set (subtype p)} {t : set α} :
s = subtype.val ⁻¹' t ↔ (∀x (h : p x), (⟨x, h⟩ : subtype p) ∈ s ↔ x ∈ t) :=
⟨assume s_eq x h, by { rw [s_eq], simp },
assume h, ext $ λ ⟨x, hx⟩, by simp [h]⟩
lemma nonempty_of_nonempty_preimage {s : set β} {f : α → β} (hf : (f ⁻¹' s).nonempty) :
s.nonempty :=
let ⟨x, hx⟩ := hf in ⟨f x, hx⟩
lemma preimage_subtype_coe_eq_compl {α : Type*} {s u v : set α} (hsuv : s ⊆ u ∪ v)
(H : s ∩ (u ∩ v) = ∅) : (coe : s → α) ⁻¹' u = (coe ⁻¹' v)ᶜ :=
begin
ext ⟨x, x_in_s⟩,
split,
{ intros x_in_u x_in_v,
exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ },
{ intro hx,
exact or.elim (hsuv x_in_s) id (λ hx', hx.elim hx') }
end
end preimage
/-! ### Image of a set under a function -/
section image
variables {f : α → β} {s t : set α}
/-- The image of `s : set α` by `f : α → β`, written `f '' s`,
is the set of `y : β` such that `f x = y` for some `x ∈ s`. -/
def image (f : α → β) (s : set α) : set β := {y | ∃ x, x ∈ s ∧ f x = y}
infix ` '' `:80 := image
theorem mem_image_iff_bex {f : α → β} {s : set α} {y : β} :
y ∈ f '' s ↔ ∃ x (_ : x ∈ s), f x = y := bex_def.symm
@[simp] theorem mem_image (f : α → β) (s : set α) (y : β) :
y ∈ f '' s ↔ ∃ x, x ∈ s ∧ f x = y := iff.rfl
lemma image_eta (f : α → β) : f '' s = (λ x, f x) '' s := rfl
theorem mem_image_of_mem (f : α → β) {x : α} {a : set α} (h : x ∈ a) : f x ∈ f '' a :=
⟨_, h, rfl⟩
theorem _root_.function.injective.mem_set_image {f : α → β} (hf : injective f) {s : set α} {a : α} :
f a ∈ f '' s ↔ a ∈ s :=
⟨λ ⟨b, hb, eq⟩, (hf eq) ▸ hb, mem_image_of_mem f⟩
theorem ball_image_iff {f : α → β} {s : set α} {p : β → Prop} :
(∀ y ∈ f '' s, p y) ↔ (∀ x ∈ s, p (f x)) :=
by simp
theorem ball_image_of_ball {f : α → β} {s : set α} {p : β → Prop}
(h : ∀ x ∈ s, p (f x)) : ∀ y ∈ f '' s, p y :=
ball_image_iff.2 h
theorem bex_image_iff {f : α → β} {s : set α} {p : β → Prop} :
(∃ y ∈ f '' s, p y) ↔ (∃ x ∈ s, p (f x)) :=
by simp
theorem mem_image_elim {f : α → β} {s : set α} {C : β → Prop} (h : ∀ (x : α), x ∈ s → C (f x)) :
∀{y : β}, y ∈ f '' s → C y
| ._ ⟨a, a_in, rfl⟩ := h a a_in
theorem mem_image_elim_on {f : α → β} {s : set α} {C : β → Prop} {y : β} (h_y : y ∈ f '' s)
(h : ∀ (x : α), x ∈ s → C (f x)) : C y :=
mem_image_elim h h_y
@[congr] lemma image_congr {f g : α → β} {s : set α}
(h : ∀a∈s, f a = g a) : f '' s = g '' s :=
by safe [ext_iff, iff_def]
/-- A common special case of `image_congr` -/
lemma image_congr' {f g : α → β} {s : set α} (h : ∀ (x : α), f x = g x) : f '' s = g '' s :=
image_congr (λx _, h x)
theorem image_comp (f : β → γ) (g : α → β) (a : set α) : (f ∘ g) '' a = f '' (g '' a) :=
subset.antisymm
(ball_image_of_ball $ assume a ha, mem_image_of_mem _ $ mem_image_of_mem _ ha)
(ball_image_of_ball $ ball_image_of_ball $ assume a ha, mem_image_of_mem _ ha)
/-- A variant of `image_comp`, useful for rewriting -/
lemma image_image (g : β → γ) (f : α → β) (s : set α) : g '' (f '' s) = (λ x, g (f x)) '' s :=
(image_comp g f s).symm
lemma image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ}
(h_comm : ∀ a, f (g a) = g' (f' a)) :
(s.image g).image f = (s.image f').image g' :=
by simp_rw [image_image, h_comm]
lemma _root_.function.semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β}
(h : function.semiconj f ga gb) :
function.semiconj (image f) (image ga) (image gb) :=
λ s, image_comm h
lemma _root_.function.commute.set_image {f g : α → α} (h : function.commute f g) :
function.commute (image f) (image g) :=
h.set_image
/-- Image is monotone with respect to `⊆`. See `set.monotone_image` for the statement in
terms of `≤`. -/
theorem image_subset {a b : set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b :=
by { simp only [subset_def, mem_image], exact λ x, λ ⟨w, h1, h2⟩, ⟨w, h h1, h2⟩ }
/-- `set.image` is monotone. See `set.image_subset` for the statement in terms of `⊆`. -/
lemma monotone_image {f : α → β} : monotone (image f) :=
λ s t, image_subset _
theorem image_union (f : α → β) (s t : set α) :
f '' (s ∪ t) = f '' s ∪ f '' t :=
ext $ λ x, ⟨by rintro ⟨a, h|h, rfl⟩; [left, right]; exact ⟨_, h, rfl⟩,
by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩); refine ⟨_, _, rfl⟩; [left, right]; exact h⟩
@[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by { ext, simp }
lemma image_inter_subset (f : α → β) (s t : set α) :
f '' (s ∩ t) ⊆ f '' s ∩ f '' t :=
subset_inter (image_subset _ $ inter_subset_left _ _) (image_subset _ $ inter_subset_right _ _)
theorem image_inter_on {f : α → β} {s t : set α} (h : ∀x∈t, ∀y∈s, f x = f y → x = y) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
(image_inter_subset _ _ _).antisymm
(assume b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩,
have a₂ = a₁, from h _ ha₂ _ ha₁ (by simp *),
⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩)
theorem image_inter {f : α → β} {s t : set α} (H : injective f) :
f '' (s ∩ t) = f '' s ∩ f '' t :=
image_inter_on (assume x _ y _ h, H h)
theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : surjective f) : f '' univ = univ :=
eq_univ_of_forall $ by { simpa [image] }
@[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} :=
by { ext, simp [image, eq_comm] }
@[simp] theorem nonempty.image_const {s : set α} (hs : s.nonempty) (a : β) : (λ _, a) '' s = {a} :=
ext $ λ x, ⟨λ ⟨y, _, h⟩, h ▸ mem_singleton _,
λ h, (eq_of_mem_singleton h).symm ▸ hs.imp (λ y hy, ⟨hy, rfl⟩)⟩
@[simp] lemma image_eq_empty {α β} {f : α → β} {s : set α} : f '' s = ∅ ↔ s = ∅ :=
by { simp only [eq_empty_iff_forall_not_mem],
exact ⟨λ H a ha, H _ ⟨_, ha, rfl⟩, λ H b ⟨_, ha, _⟩, H _ ha⟩ }
lemma preimage_compl_eq_image_compl [boolean_algebra α] (S : set α) :
compl ⁻¹' S = compl '' S :=
set.ext (λ x, ⟨λ h, ⟨xᶜ,h, compl_compl x⟩,
λ h, exists.elim h (λ y hy, (compl_eq_comm.mp hy.2).symm.subst hy.1)⟩)
theorem mem_compl_image [boolean_algebra α] (t : α) (S : set α) :
t ∈ compl '' S ↔ tᶜ ∈ S :=
by simp [←preimage_compl_eq_image_compl]
/-- A variant of `image_id` -/
@[simp] lemma image_id' (s : set α) : (λx, x) '' s = s := by { ext, simp }
theorem image_id (s : set α) : id '' s = s := by simp
theorem compl_compl_image [boolean_algebra α] (S : set α) :
compl '' (compl '' S) = S :=
by rw [←image_comp, compl_comp_compl, image_id]
theorem image_insert_eq {f : α → β} {a : α} {s : set α} :
f '' (insert a s) = insert (f a) (f '' s) :=
by { ext, simp [and_or_distrib_left, exists_or_distrib, eq_comm, or_comm, and_comm] }
theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} :=
by simp only [image_insert_eq, image_singleton]
theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set α) : f '' s ⊆ g ⁻¹' s :=
λ b ⟨a, h, e⟩, e ▸ ((I a).symm ▸ h : g (f a) ∈ s)
theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α}
(I : left_inverse g f) (s : set β) : f ⁻¹' s ⊆ g '' s :=
λ b h, ⟨f b, h, I b⟩
theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
image f = preimage g :=
funext $ λ s, subset.antisymm
(image_subset_preimage_of_inverse h₁ s)
(preimage_subset_image_of_inverse h₂ s)
theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : set α}
(h₁ : left_inverse g f) (h₂ : right_inverse g f) :
b ∈ f '' s ↔ g b ∈ s :=
by rw image_eq_preimage_of_inverse h₁ h₂; refl
theorem image_compl_subset {f : α → β} {s : set α} (H : injective f) : f '' sᶜ ⊆ (f '' s)ᶜ :=
disjoint.subset_compl_left $ by simp [disjoint_iff_inf_le, ←image_inter H]
theorem subset_image_compl {f : α → β} {s : set α} (H : surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ :=
compl_subset_iff_union.2 $
by { rw ← image_union, simp [image_univ_of_surjective H] }
theorem image_compl_eq {f : α → β} {s : set α} (H : bijective f) : f '' sᶜ = (f '' s)ᶜ :=
subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2)
theorem subset_image_diff (f : α → β) (s t : set α) :
f '' s \ f '' t ⊆ f '' (s \ t) :=
begin
rw [diff_subset_iff, ← image_union, union_diff_self],
exact image_subset f (subset_union_right t s)
end
lemma subset_image_symm_diff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t :=
(union_subset_union (subset_image_diff _ _ _) $ subset_image_diff _ _ _).trans
(image_union _ _ _).superset
theorem image_diff {f : α → β} (hf : injective f) (s t : set α) :
f '' (s \ t) = f '' s \ f '' t :=
subset.antisymm
(subset.trans (image_inter_subset _ _ _) $ inter_subset_inter_right _ $ image_compl_subset hf)
(subset_image_diff f s t)
lemma image_symm_diff (hf : injective f) (s t : set α) : f '' (s ∆ t) = (f '' s) ∆ (f '' t) :=
by simp_rw [set.symm_diff_def, image_union, image_diff hf]
lemma nonempty.image (f : α → β) {s : set α} : s.nonempty → (f '' s).nonempty
| ⟨x, hx⟩ := ⟨f x, mem_image_of_mem f hx⟩
lemma nonempty.of_image {f : α → β} {s : set α} : (f '' s).nonempty → s.nonempty
| ⟨y, x, hx, _⟩ := ⟨x, hx⟩
@[simp] lemma nonempty_image_iff {f : α → β} {s : set α} :
(f '' s).nonempty ↔ s.nonempty :=
⟨nonempty.of_image, λ h, h.image f⟩
lemma nonempty.preimage {s : set β} (hs : s.nonempty) {f : α → β} (hf : surjective f) :
(f ⁻¹' s).nonempty :=
let ⟨y, hy⟩ := hs, ⟨x, hx⟩ := hf y in ⟨x, mem_preimage.2 $ hx.symm ▸ hy⟩
instance (f : α → β) (s : set α) [nonempty s] : nonempty (f '' s) :=
(set.nonempty.image f nonempty_of_nonempty_subtype).to_subtype
/-- image and preimage are a Galois connection -/
@[simp] theorem image_subset_iff {s : set α} {t : set β} {f : α → β} :
f '' s ⊆ t ↔ s ⊆ f ⁻¹' t :=
ball_image_iff
theorem image_preimage_subset (f : α → β) (s : set β) : f '' (f ⁻¹' s) ⊆ s :=
image_subset_iff.2 subset.rfl
theorem subset_preimage_image (f : α → β) (s : set α) :
s ⊆ f ⁻¹' (f '' s) :=
λ x, mem_image_of_mem f
theorem preimage_image_eq {f : α → β} (s : set α) (h : injective f) : f ⁻¹' (f '' s) = s :=
subset.antisymm
(λ x ⟨y, hy, e⟩, h e ▸ hy)
(subset_preimage_image f s)
theorem image_preimage_eq {f : α → β} (s : set β) (h : surjective f) : f '' (f ⁻¹' s) = s :=
subset.antisymm
(image_preimage_subset f s)
(λ x hx, let ⟨y, e⟩ := h x in ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩)
lemma preimage_eq_preimage {f : β → α} (hf : surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t :=
iff.intro
(assume eq, by rw [← image_preimage_eq s hf, ← image_preimage_eq t hf, eq])
(assume eq, eq ▸ rfl)
lemma image_inter_preimage (f : α → β) (s : set α) (t : set β) :
f '' (s ∩ f ⁻¹' t) = f '' s ∩ t :=
begin
apply subset.antisymm,
{ calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ (f '' (f⁻¹' t)) : image_inter_subset _ _ _
... ⊆ f '' s ∩ t : inter_subset_inter_right _ (image_preimage_subset f t) },
{ rintros _ ⟨⟨x, h', rfl⟩, h⟩,
exact ⟨x, ⟨h', h⟩, rfl⟩ }
end
lemma image_preimage_inter (f : α → β) (s : set α) (t : set β) :
f '' (f ⁻¹' t ∩ s) = t ∩ f '' s :=
by simp only [inter_comm, image_inter_preimage]
@[simp] lemma image_inter_nonempty_iff {f : α → β} {s : set α} {t : set β} :
(f '' s ∩ t).nonempty ↔ (s ∩ f ⁻¹' t).nonempty :=
by rw [←image_inter_preimage, nonempty_image_iff]
lemma image_diff_preimage {f : α → β} {s : set α} {t : set β} : f '' (s \ f ⁻¹' t) = f '' s \ t :=
by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage]
theorem compl_image : image (compl : set α → set α) = preimage compl :=
image_eq_preimage_of_inverse compl_compl compl_compl
theorem compl_image_set_of {p : set α → Prop} :
compl '' {s | p s} = {s | p sᶜ} :=
congr_fun compl_image p
theorem inter_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) :=
λ x h, ⟨mem_image_of_mem _ h.left, h.right⟩
theorem union_preimage_subset (s : set α) (t : set β) (f : α → β) :
s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) :=
λ x h, or.elim h (λ l, or.inl $ mem_image_of_mem _ l) (λ r, or.inr r)
theorem subset_image_union (f : α → β) (s : set α) (t : set β) :
f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t :=
image_subset_iff.2 (union_preimage_subset _ _ _)
lemma preimage_subset_iff {A : set α} {B : set β} {f : α → β} :
f⁻¹' B ⊆ A ↔ (∀ a : α, f a ∈ B → a ∈ A) := iff.rfl
lemma image_eq_image {f : α → β} (hf : injective f) : f '' s = f '' t ↔ s = t :=
iff.symm $ iff.intro (assume eq, eq ▸ rfl) $ assume eq,
by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq]
lemma image_subset_image_iff {f : α → β} (hf : injective f) : f '' s ⊆ f '' t ↔ s ⊆ t :=
begin
refine (iff.symm $ iff.intro (image_subset f) $ assume h, _),
rw [← preimage_image_eq s hf, ← preimage_image_eq t hf],
exact preimage_mono h
end
lemma prod_quotient_preimage_eq_image [s : setoid α] (g : quotient s → β) {h : α → β}
(Hh : h = g ∘ quotient.mk) (r : set (β × β)) :
{x : quotient s × quotient s | (g x.1, g x.2) ∈ r} =
(λ a : α × α, (⟦a.1⟧, ⟦a.2⟧)) '' ((λ a : α × α, (h a.1, h a.2)) ⁻¹' r) :=
Hh.symm ▸ set.ext (λ ⟨a₁, a₂⟩, ⟨quotient.induction_on₂ a₁ a₂
(λ a₁ a₂ h, ⟨(a₁, a₂), h, rfl⟩),
λ ⟨⟨b₁, b₂⟩, h₁, h₂⟩, show (g a₁, g a₂) ∈ r, from
have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := prod.ext_iff.1 h₂,
h₃.1 ▸ h₃.2 ▸ h₁⟩)
lemma exists_image_iff (f : α → β) (x : set α) (P : β → Prop) :
(∃ (a : f '' x), P a) ↔ ∃ (a : x), P (f a) :=
⟨λ ⟨a, h⟩, ⟨⟨_, a.prop.some_spec.1⟩, a.prop.some_spec.2.symm ▸ h⟩,
λ ⟨a, h⟩, ⟨⟨_, _, a.prop, rfl⟩, h⟩⟩
/-- Restriction of `f` to `s` factors through `s.image_factorization f : s → f '' s`. -/
def image_factorization (f : α → β) (s : set α) : s → f '' s :=
λ p, ⟨f p.1, mem_image_of_mem f p.2⟩
lemma image_factorization_eq {f : α → β} {s : set α} :
subtype.val ∘ image_factorization f s = f ∘ subtype.val :=
funext $ λ p, rfl
lemma surjective_onto_image {f : α → β} {s : set α} :
surjective (image_factorization f s) :=
λ ⟨_, ⟨a, ha, rfl⟩⟩, ⟨⟨a, ha⟩, rfl⟩
/-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect.
-/
lemma image_perm {s : set α} {σ : equiv.perm α} (hs : {a : α | σ a ≠ a} ⊆ s) : σ '' s = s :=
begin
ext i,
obtain hi | hi := eq_or_ne (σ i) i,
{ refine ⟨_, λ h, ⟨i, h, hi⟩⟩,
rintro ⟨j, hj, h⟩,
rwa σ.injective (hi.trans h.symm) },
{ refine iff_of_true ⟨σ.symm i, hs $ λ h, hi _, σ.apply_symm_apply _⟩ (hs hi),
convert congr_arg σ h; exact (σ.apply_symm_apply _).symm }
end
end image
/-! ### Lemmas about the powerset and image. -/
/-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/
theorem powerset_insert (s : set α) (a : α) :
𝒫 (insert a s) = 𝒫 s ∪ (insert a '' 𝒫 s) :=
begin
ext t,
simp_rw [mem_union, mem_image, mem_powerset_iff],
split,
{ intro h,
by_cases hs : a ∈ t,
{ right,
refine ⟨t \ {a}, _, _⟩,
{ rw [diff_singleton_subset_iff],
assumption },
{ rw [insert_diff_singleton, insert_eq_of_mem hs] }},
{ left,
exact (subset_insert_iff_of_not_mem hs).mp h}},
{ rintros (h | ⟨s', h₁, rfl⟩),
{ exact subset_trans h (subset_insert a s) },
{ exact insert_subset_insert h₁ }}
end
/-! ### Lemmas about range of a function. -/
section range
variables {f : ι → α} {s t : set α}
/-- Range of a function.
This function is more flexible than `f '' univ`, as the image requires that the domain is in Type
and not an arbitrary Sort. -/
def range (f : ι → α) : set α := {x | ∃y, f y = x}
@[simp] theorem mem_range {x : α} : x ∈ range f ↔ ∃ y, f y = x := iff.rfl
@[simp] theorem mem_range_self (i : ι) : f i ∈ range f := ⟨i, rfl⟩
theorem forall_range_iff {p : α → Prop} : (∀ a ∈ range f, p a) ↔ (∀ i, p (f i)) :=
by simp
theorem forall_subtype_range_iff {p : range f → Prop} :
(∀ a : range f, p a) ↔ ∀ i, p ⟨f i, mem_range_self _⟩ :=
⟨λ H i, H _, λ H ⟨y, i, hi⟩, by { subst hi, apply H }⟩
theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ (∃ i, p (f i)) :=
by simp
lemma exists_range_iff' {p : α → Prop} :
(∃ a, a ∈ range f ∧ p a) ↔ ∃ i, p (f i) :=
by simpa only [exists_prop] using exists_range_iff
lemma exists_subtype_range_iff {p : range f → Prop} :
(∃ a : range f, p a) ↔ ∃ i, p ⟨f i, mem_range_self _⟩ :=
⟨λ ⟨⟨a, i, hi⟩, ha⟩, by { subst a, exact ⟨i, ha⟩}, λ ⟨i, hi⟩, ⟨_, hi⟩⟩
theorem range_iff_surjective : range f = univ ↔ surjective f :=
eq_univ_iff_forall
alias range_iff_surjective ↔ _ _root_.function.surjective.range_eq
@[simp] theorem image_univ {f : α → β} : f '' univ = range f :=
by { ext, simp [image, range] }
theorem image_subset_range (f : α → β) (s) : f '' s ⊆ range f :=
by rw ← image_univ; exact image_subset _ (subset_univ _)
theorem mem_range_of_mem_image (f : α → β) (s) {x : β} (h : x ∈ f '' s) : x ∈ range f :=
image_subset_range f s h
lemma _root_.nat.mem_range_succ (i : ℕ) : i ∈ range nat.succ ↔ 0 < i :=
⟨by { rintros ⟨n, rfl⟩, exact nat.succ_pos n, }, λ h, ⟨_, nat.succ_pred_eq_of_pos h⟩⟩
lemma nonempty.preimage' {s : set β} (hs : s.nonempty) {f : α → β} (hf : s ⊆ set.range f) :
(f ⁻¹' s).nonempty :=
let ⟨y, hy⟩ := hs, ⟨x, hx⟩ := hf hy in ⟨x, set.mem_preimage.2 $ hx.symm ▸ hy⟩
theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f :=
subset.antisymm
(forall_range_iff.mpr $ assume i, mem_image_of_mem g (mem_range_self _))
(ball_image_iff.mpr $ forall_range_iff.mpr mem_range_self)
theorem range_subset_iff : range f ⊆ s ↔ ∀ y, f y ∈ s :=
forall_range_iff
theorem range_eq_iff (f : α → β) (s : set β) :
range f = s ↔ (∀ a, f a ∈ s) ∧ ∀ b ∈ s, ∃ a, f a = b :=
by { rw ←range_subset_iff, exact le_antisymm_iff }
lemma range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g :=
by rw range_comp; apply image_subset_range
lemma range_nonempty_iff_nonempty : (range f).nonempty ↔ nonempty ι :=
⟨λ ⟨y, x, hxy⟩, ⟨x⟩, λ ⟨x⟩, ⟨f x, mem_range_self x⟩⟩
lemma range_nonempty [h : nonempty ι] (f : ι → α) : (range f).nonempty :=
range_nonempty_iff_nonempty.2 h
@[simp] lemma range_eq_empty_iff {f : ι → α} : range f = ∅ ↔ is_empty ι :=
by rw [← not_nonempty_iff, ← range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty]
lemma range_eq_empty [is_empty ι] (f : ι → α) : range f = ∅ := range_eq_empty_iff.2 ‹_›
instance [nonempty ι] (f : ι → α) : nonempty (range f) := (range_nonempty f).to_subtype
@[simp] lemma image_union_image_compl_eq_range (f : α → β) :
(f '' s) ∪ (f '' sᶜ) = range f :=
by rw [← image_union, ← image_univ, ← union_compl_self]
lemma insert_image_compl_eq_range (f : α → β) (x : α) :
insert (f x) (f '' {x}ᶜ) = range f :=
begin
ext y, rw [mem_range, mem_insert_iff, mem_image],
split,
{ rintro (h | ⟨x', hx', h⟩),
{ exact ⟨x, h.symm⟩ },
{ exact ⟨x', h⟩ } },
{ rintro ⟨x', h⟩,
by_cases hx : x' = x,
{ left, rw [← h, hx] },
{ right, refine ⟨_, _, h⟩, rw mem_compl_singleton_iff, exact hx } }
end
theorem image_preimage_eq_inter_range {f : α → β} {t : set β} :
f '' (f ⁻¹' t) = t ∩ range f :=
ext $ assume x, ⟨assume ⟨x, hx, heq⟩, heq ▸ ⟨hx, mem_range_self _⟩,
assume ⟨hx, ⟨y, h_eq⟩⟩, h_eq ▸ mem_image_of_mem f $
show y ∈ f ⁻¹' t, by simp [preimage, h_eq, hx]⟩
lemma image_preimage_eq_of_subset {f : α → β} {s : set β} (hs : s ⊆ range f) :
f '' (f ⁻¹' s) = s :=
by rw [image_preimage_eq_inter_range, inter_eq_self_of_subset_left hs]
lemma image_preimage_eq_iff {f : α → β} {s : set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f :=
⟨by { intro h, rw [← h], apply image_subset_range }, image_preimage_eq_of_subset⟩
lemma subset_range_iff_exists_image_eq {f : α → β} {s : set β} :
s ⊆ range f ↔ ∃ t, f '' t = s :=
⟨λ h, ⟨_, image_preimage_eq_iff.2 h⟩, λ ⟨t, ht⟩, ht ▸ image_subset_range _ _⟩
@[simp] lemma exists_subset_range_and_iff {f : α → β} {p : set β → Prop} :
(∃ s, s ⊆ range f ∧ p s) ↔ ∃ s, p (f '' s) :=
⟨λ ⟨s, hsf, hps⟩, ⟨f ⁻¹' s, (image_preimage_eq_of_subset hsf).symm ▸ hps⟩,
λ ⟨s, hs⟩, ⟨f '' s, image_subset_range _ _, hs⟩⟩
lemma exists_subset_range_iff {f : α → β} {p : set β → Prop} :
(∃ s ⊆ range f, p s) ↔ ∃ s, p (f '' s) :=
by simp only [exists_prop, exists_subset_range_and_iff]
lemma range_image (f : α → β) : range (image f) = 𝒫 (range f) :=
ext $ λ s, subset_range_iff_exists_image_eq.symm
lemma preimage_subset_preimage_iff {s t : set α} {f : β → α} (hs : s ⊆ range f) :
f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t :=
begin
split,
{ intros h x hx, rcases hs hx with ⟨y, rfl⟩, exact h hx },
intros h x, apply h
end
lemma preimage_eq_preimage' {s t : set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) :
f ⁻¹' s = f ⁻¹' t ↔ s = t :=
begin
split,
{ intro h, apply subset.antisymm, rw [←preimage_subset_preimage_iff hs, h],
rw [←preimage_subset_preimage_iff ht, h] },
rintro rfl, refl
end
@[simp] theorem preimage_inter_range {f : α → β} {s : set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s :=
set.ext $ λ x, and_iff_left ⟨x, rfl⟩
@[simp] theorem preimage_range_inter {f : α → β} {s : set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s :=
by rw [inter_comm, preimage_inter_range]
theorem preimage_image_preimage {f : α → β} {s : set β} :
f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s :=
by rw [image_preimage_eq_inter_range, preimage_inter_range]
@[simp] theorem range_id : range (@id α) = univ := range_iff_surjective.2 surjective_id
@[simp] theorem range_id' : range (λ (x : α), x) = univ := range_id
@[simp] theorem _root_.prod.range_fst [nonempty β] : range (prod.fst : α × β → α) = univ :=
prod.fst_surjective.range_eq
@[simp] theorem _root_.prod.range_snd [nonempty α] : range (prod.snd : α × β → β) = univ :=
prod.snd_surjective.range_eq
@[simp] theorem range_eval {ι : Type*} {α : ι → Sort*} [Π i, nonempty (α i)] (i : ι) :
range (eval i : (Π i, α i) → α i) = univ :=
(surjective_eval i).range_eq
theorem range_inl : range (@sum.inl α β) = {x | x.is_left} := by ext (_|_); simp
theorem range_inr : range (@sum.inr α β) = {x | x.is_right} := by ext (_|_); simp
theorem is_compl_range_inl_range_inr : is_compl (range $ @sum.inl α β) (range sum.inr) :=
is_compl.of_le
(by { rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, _⟩⟩, cc })
(by { rintro (x|y) -; [left, right]; exact mem_range_self _ })
@[simp] theorem range_inl_union_range_inr : range (sum.inl : α → α ⊕ β) ∪ range sum.inr = univ :=
is_compl_range_inl_range_inr.sup_eq_top
@[simp] theorem range_inl_inter_range_inr : range (sum.inl : α → α ⊕ β) ∩ range sum.inr = ∅ :=
is_compl_range_inl_range_inr.inf_eq_bot
@[simp] theorem range_inr_union_range_inl : range (sum.inr : β → α ⊕ β) ∪ range sum.inl = univ :=
is_compl_range_inl_range_inr.symm.sup_eq_top
@[simp] theorem range_inr_inter_range_inl : range (sum.inr : β → α ⊕ β) ∩ range sum.inl = ∅ :=
is_compl_range_inl_range_inr.symm.inf_eq_bot
@[simp] theorem preimage_inl_image_inr (s : set β) : sum.inl ⁻¹' (@sum.inr α β '' s) = ∅ :=
by { ext, simp }
@[simp] theorem preimage_inr_image_inl (s : set α) : sum.inr ⁻¹' (@sum.inl α β '' s) = ∅ :=
by { ext, simp }
@[simp] theorem preimage_inl_range_inr : sum.inl ⁻¹' range (sum.inr : β → α ⊕ β) = ∅ :=
by rw [← image_univ, preimage_inl_image_inr]
@[simp] theorem preimage_inr_range_inl : sum.inr ⁻¹' range (sum.inl : α → α ⊕ β) = ∅ :=
by rw [← image_univ, preimage_inr_image_inl]
@[simp] lemma compl_range_inl : (range (sum.inl : α → α ⊕ β))ᶜ = range (sum.inr : β → α ⊕ β) :=
is_compl.compl_eq is_compl_range_inl_range_inr
@[simp] lemma compl_range_inr : (range (sum.inr : β → α ⊕ β))ᶜ = range (sum.inl : α → α ⊕ β) :=
is_compl.compl_eq is_compl_range_inl_range_inr.symm
theorem image_preimage_inl_union_image_preimage_inr (s : set (α ⊕ β)) :
sum.inl '' (sum.inl ⁻¹' s) ∪ sum.inr '' (sum.inr ⁻¹' s) = s :=
by rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, ← inter_distrib_left,
range_inl_union_range_inr, inter_univ]
@[simp] theorem range_quot_mk (r : α → α → Prop) : range (quot.mk r) = univ :=
(surjective_quot_mk r).range_eq
@[simp] theorem range_quot_lift {r : ι → ι → Prop} (hf : ∀ x y, r x y → f x = f y) :
range (quot.lift f hf) = range f :=
ext $ λ y, (surjective_quot_mk _).exists
@[simp] theorem range_quotient_mk [setoid α] : range (λx : α, ⟦x⟧) = univ :=
range_quot_mk _
@[simp] theorem range_quotient_lift [s : setoid ι] (hf) :
range (quotient.lift f hf : quotient s → α) = range f :=
range_quot_lift _
@[simp] theorem range_quotient_mk' {s : setoid α} : range (quotient.mk' : α → quotient s) = univ :=
range_quot_mk _
@[simp] theorem range_quotient_lift_on' {s : setoid ι} (hf) :
range (λ x : quotient s, quotient.lift_on' x f hf) = range f :=
range_quot_lift _
instance can_lift (c) (p) [can_lift α β c p] :
can_lift (set α) (set β) (('') c) (λ s, ∀ x ∈ s, p x) :=
{ prf := λ s hs, subset_range_iff_exists_image_eq.mp (λ x hx, can_lift.prf _ (hs x hx)) }
lemma range_const_subset {c : α} : range (λ x : ι, c) ⊆ {c} :=
range_subset_iff.2 $ λ x, rfl
@[simp] lemma range_const : ∀ [nonempty ι] {c : α}, range (λx:ι, c) = {c}
| ⟨x⟩ c := subset.antisymm range_const_subset $
assume y hy, (mem_singleton_iff.1 hy).symm ▸ mem_range_self x
lemma range_subtype_map {p : α → Prop} {q : β → Prop} (f : α → β) (h : ∀ x, p x → q (f x)) :
range (subtype.map f h) = coe ⁻¹' (f '' {x | p x}) :=
begin
ext ⟨x, hx⟩,
simp_rw [mem_preimage, mem_range, mem_image, subtype.exists, subtype.map, subtype.coe_mk,
mem_set_of, exists_prop]
end
lemma image_swap_eq_preimage_swap : image (@prod.swap α β) = preimage prod.swap :=
image_eq_preimage_of_inverse prod.swap_left_inverse prod.swap_right_inverse
theorem preimage_singleton_nonempty {f : α → β} {y : β} :
(f ⁻¹' {y}).nonempty ↔ y ∈ range f :=
iff.rfl
theorem preimage_singleton_eq_empty {f : α → β} {y : β} :
f ⁻¹' {y} = ∅ ↔ y ∉ range f :=
not_nonempty_iff_eq_empty.symm.trans preimage_singleton_nonempty.not
lemma range_subset_singleton {f : ι → α} {x : α} : range f ⊆ {x} ↔ f = const ι x :=
by simp [range_subset_iff, funext_iff, mem_singleton]
lemma image_compl_preimage {f : α → β} {s : set β} : f '' ((f ⁻¹' s)ᶜ) = range f \ s :=
by rw [compl_eq_univ_diff, image_diff_preimage, image_univ]
/-- Any map `f : ι → β` factors through a map `range_factorization f : ι → range f`. -/
def range_factorization (f : ι → β) : ι → range f :=
λ i, ⟨f i, mem_range_self i⟩
lemma range_factorization_eq {f : ι → β} :
subtype.val ∘ range_factorization f = f :=
funext $ λ i, rfl
@[simp] lemma range_factorization_coe (f : ι → β) (a : ι) :
(range_factorization f a : β) = f a := rfl
@[simp] lemma coe_comp_range_factorization (f : ι → β) : coe ∘ range_factorization f = f := rfl
lemma surjective_onto_range : surjective (range_factorization f) :=
λ ⟨_, ⟨i, rfl⟩⟩, ⟨i, rfl⟩
lemma image_eq_range (f : α → β) (s : set α) : f '' s = range (λ(x : s), f x) :=
by { ext, split, rintro ⟨x, h1, h2⟩, exact ⟨⟨x, h1⟩, h2⟩, rintro ⟨⟨x, h1⟩, h2⟩, exact ⟨x, h1, h2⟩ }
lemma _root_.sum.range_eq (f : α ⊕ β → γ) : range f = range (f ∘ sum.inl) ∪ range (f ∘ sum.inr) :=
ext $ λ x, sum.exists
@[simp] lemma sum.elim_range (f : α → γ) (g : β → γ) : range (sum.elim f g) = range f ∪ range g :=
sum.range_eq _
lemma range_ite_subset' {p : Prop} [decidable p] {f g : α → β} :
range (if p then f else g) ⊆ range f ∪ range g :=
begin
by_cases h : p, {rw if_pos h, exact subset_union_left _ _},
{rw if_neg h, exact subset_union_right _ _}
end
lemma range_ite_subset {p : α → Prop} [decidable_pred p] {f g : α → β} :
range (λ x, if p x then f x else g x) ⊆ range f ∪ range g :=
begin
rw range_subset_iff, intro x, by_cases h : p x,
simp [if_pos h, mem_union, mem_range_self],
simp [if_neg h, mem_union, mem_range_self]
end
@[simp] lemma preimage_range (f : α → β) : f ⁻¹' (range f) = univ :=
eq_univ_of_forall mem_range_self
/-- The range of a function from a `unique` type contains just the
function applied to its single value. -/
lemma range_unique [h : unique ι] : range f = {f default} :=
begin
ext x,
rw mem_range,
split,
{ rintros ⟨i, hi⟩,
rw h.uniq i at hi,
exact hi ▸ mem_singleton _ },
{ exact λ h, ⟨default, h.symm⟩ }
end
lemma range_diff_image_subset (f : α → β) (s : set α) :
range f \ f '' s ⊆ f '' sᶜ :=
λ y ⟨⟨x, h₁⟩, h₂⟩, ⟨x, λ h, h₂ ⟨x, h, h₁⟩, h₁⟩
lemma range_diff_image {f : α → β} (H : injective f) (s : set α) :
range f \ f '' s = f '' sᶜ :=
subset.antisymm (range_diff_image_subset f s) $ λ y ⟨x, hx, hy⟩, hy ▸
⟨mem_range_self _, λ ⟨x', hx', eq⟩, hx $ H eq ▸ hx'⟩
@[simp] lemma range_inclusion (h : s ⊆ t) : range (inclusion h) = {x : t | (x:α) ∈ s} :=
by { ext ⟨x, hx⟩, simp [inclusion] }
/-- We can use the axiom of choice to pick a preimage for every element of `range f`. -/
noncomputable def range_splitting (f : α → β) : range f → α := λ x, x.2.some
-- This can not be a `@[simp]` lemma because the head of the left hand side is a variable.
lemma apply_range_splitting (f : α → β) (x : range f) : f (range_splitting f x) = x :=
x.2.some_spec
attribute [irreducible] range_splitting
@[simp] lemma comp_range_splitting (f : α → β) : f ∘ range_splitting f = coe :=
by { ext, simp only [function.comp_app], apply apply_range_splitting, }
-- When `f` is injective, see also `equiv.of_injective`.
lemma left_inverse_range_splitting (f : α → β) :
left_inverse (range_factorization f) (range_splitting f) :=
λ x, by { ext, simp only [range_factorization_coe], apply apply_range_splitting, }
lemma range_splitting_injective (f : α → β) : injective (range_splitting f) :=
(left_inverse_range_splitting f).injective
lemma right_inverse_range_splitting {f : α → β} (h : injective f) :
right_inverse (range_factorization f) (range_splitting f) :=
(left_inverse_range_splitting f).right_inverse_of_injective $
λ x y hxy, h $ subtype.ext_iff.1 hxy
lemma preimage_range_splitting {f : α → β} (hf : injective f) :
preimage (range_splitting f) = image (range_factorization f) :=
(image_eq_preimage_of_inverse (right_inverse_range_splitting hf)
(left_inverse_range_splitting f)).symm
lemma is_compl_range_some_none (α : Type*) :
is_compl (range (some : α → option α)) {none} :=
is_compl.of_le
(λ x ⟨⟨a, ha⟩, (hn : x = none)⟩, option.some_ne_none _ (ha.trans hn))
(λ x hx, option.cases_on x (or.inr rfl) (λ x, or.inl $ mem_range_self _))
@[simp] lemma compl_range_some (α : Type*) :
(range (some : α → option α))ᶜ = {none} :=
(is_compl_range_some_none α).compl_eq
@[simp] lemma range_some_inter_none (α : Type*) : range (some : α → option α) ∩ {none} = ∅ :=
(is_compl_range_some_none α).inf_eq_bot
@[simp] lemma range_some_union_none (α : Type*) : range (some : α → option α) ∪ {none} = univ :=
(is_compl_range_some_none α).sup_eq_top
@[simp] lemma insert_none_range_some (α : Type*) :
insert none (range (some : α → option α)) = univ :=
(is_compl_range_some_none α).symm.sup_eq_top
end range
section subsingleton
variables {s : set α}
/-- The image of a subsingleton is a subsingleton. -/
lemma subsingleton.image (hs : s.subsingleton) (f : α → β) : (f '' s).subsingleton :=
λ _ ⟨x, hx, Hx⟩ _ ⟨y, hy, Hy⟩, Hx ▸ Hy ▸ congr_arg f (hs hx hy)
/-- The preimage of a subsingleton under an injective map is a subsingleton. -/
theorem subsingleton.preimage {s : set β} (hs : s.subsingleton) {f : α → β}
(hf : function.injective f) : (f ⁻¹' s).subsingleton := λ a ha b hb, hf $ hs ha hb
/-- If the image of a set under an injective map is a subsingleton, the set is a subsingleton. -/
theorem subsingleton_of_image {α β : Type*} {f : α → β} (hf : function.injective f)
(s : set α) (hs : (f '' s).subsingleton) : s.subsingleton :=
(hs.preimage hf).anti $ subset_preimage_image _ _
/-- If the preimage of a set under an surjective map is a subsingleton,
the set is a subsingleton. -/
theorem subsingleton_of_preimage {α β : Type*} {f : α → β} (hf : function.surjective f)
(s : set β) (hs : (f ⁻¹' s).subsingleton) : s.subsingleton :=
λ fx hx fy hy, by { rcases ⟨hf fx, hf fy⟩ with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩, exact congr_arg f (hs hx hy) }
lemma subsingleton_range {α : Sort*} [subsingleton α] (f : α → β) : (range f).subsingleton :=
forall_range_iff.2 $ λ x, forall_range_iff.2 $ λ y, congr_arg f (subsingleton.elim x y)
/-- The preimage of a nontrivial set under a surjective map is nontrivial. -/
theorem nontrivial.preimage {s : set β} (hs : s.nontrivial) {f : α → β}
(hf : function.surjective f) : (f ⁻¹' s).nontrivial :=
begin
rcases hs with ⟨fx, hx, fy, hy, hxy⟩,
rcases ⟨hf fx, hf fy⟩ with ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩,
exact ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩
end
/-- The image of a nontrivial set under an injective map is nontrivial. -/
theorem nontrivial.image (hs : s.nontrivial)
{f : α → β} (hf : function.injective f) : (f '' s).nontrivial :=
let ⟨x, hx, y, hy, hxy⟩ := hs in ⟨f x, mem_image_of_mem f hx, f y, mem_image_of_mem f hy, hf.ne hxy⟩
/-- If the image of a set is nontrivial, the set is nontrivial. -/
lemma nontrivial_of_image (f : α → β) (s : set α) (hs : (f '' s).nontrivial) : s.nontrivial :=
let ⟨_, ⟨x, hx, rfl⟩, _, ⟨y, hy, rfl⟩, hxy⟩ := hs in ⟨x, hx, y, hy, mt (congr_arg f) hxy⟩
/-- If the preimage of a set under an injective map is nontrivial, the set is nontrivial. -/
lemma nontrivial_of_preimage {f : α → β} (hf : function.injective f) (s : set β)
(hs : (f ⁻¹' s).nontrivial) : s.nontrivial :=
(hs.image hf).mono $ image_preimage_subset _ _
end subsingleton
end set
namespace function
variables {f : α → β}
open set
lemma surjective.preimage_injective (hf : surjective f) : injective (preimage f) :=
assume s t, (preimage_eq_preimage hf).1
lemma injective.preimage_image (hf : injective f) (s : set α) : f ⁻¹' (f '' s) = s :=
preimage_image_eq s hf
lemma injective.preimage_surjective (hf : injective f) : surjective (preimage f) :=
by { intro s, use f '' s, rw hf.preimage_image }
lemma injective.subsingleton_image_iff (hf : injective f) {s : set α} :
(f '' s).subsingleton ↔ s.subsingleton :=
⟨subsingleton_of_image hf s, λ h, h.image f⟩
lemma surjective.image_preimage (hf : surjective f) (s : set β) : f '' (f ⁻¹' s) = s :=
image_preimage_eq s hf
lemma surjective.image_surjective (hf : surjective f) : surjective (image f) :=
by { intro s, use f ⁻¹' s, rw hf.image_preimage }
lemma surjective.nonempty_preimage (hf : surjective f) {s : set β} :
(f ⁻¹' s).nonempty ↔ s.nonempty :=
by rw [← nonempty_image_iff, hf.image_preimage]
lemma injective.image_injective (hf : injective f) : injective (image f) :=
by { intros s t h, rw [←preimage_image_eq s hf, ←preimage_image_eq t hf, h] }
lemma surjective.preimage_subset_preimage_iff {s t : set β} (hf : surjective f) :
f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t :=
by { apply preimage_subset_preimage_iff, rw [hf.range_eq], apply subset_univ }
lemma surjective.range_comp {f : ι → ι'} (hf : surjective f) (g : ι' → α) :
range (g ∘ f) = range g :=
ext $ λ y, (@surjective.exists _ _ _ hf (λ x, g x = y)).symm
lemma injective.mem_range_iff_exists_unique (hf : injective f) {b : β} :
b ∈ range f ↔ ∃! a, f a = b :=
⟨λ ⟨a, h⟩, ⟨a, h, λ a' ha, hf (ha.trans h.symm)⟩, exists_unique.exists⟩
lemma injective.exists_unique_of_mem_range (hf : injective f) {b : β} (hb : b ∈ range f) :
∃! a, f a = b :=
hf.mem_range_iff_exists_unique.mp hb
theorem injective.compl_image_eq (hf : injective f) (s : set α) :
(f '' s)ᶜ = f '' sᶜ ∪ (range f)ᶜ :=
begin
ext y,
rcases em (y ∈ range f) with ⟨x, rfl⟩|hx,
{ simp [hf.eq_iff] },
{ rw [mem_range, not_exists] at hx,
simp [hx] }
end
lemma left_inverse.image_image {g : β → α} (h : left_inverse g f) (s : set α) :
g '' (f '' s) = s :=
by rw [← image_comp, h.comp_eq_id, image_id]
lemma left_inverse.preimage_preimage {g : β → α} (h : left_inverse g f) (s : set α) :
f ⁻¹' (g ⁻¹' s) = s :=
by rw [← preimage_comp, h.comp_eq_id, preimage_id]
end function
namespace equiv_like
variables {E : Type*} [equiv_like E ι ι']
include ι
@[simp] lemma range_comp (f : ι' → α) (e : E) : set.range (f ∘ e) = set.range f :=
(equiv_like.surjective _).range_comp _
end equiv_like
/-! ### Image and preimage on subtypes -/
namespace subtype
open set
lemma coe_image {p : α → Prop} {s : set (subtype p)} :
coe '' s = {x | ∃h : p x, (⟨x, h⟩ : subtype p) ∈ s} :=
set.ext $ assume a,
⟨assume ⟨⟨a', ha'⟩, in_s, h_eq⟩, h_eq ▸ ⟨ha', in_s⟩,
assume ⟨ha, in_s⟩, ⟨⟨a, ha⟩, in_s, rfl⟩⟩
@[simp] lemma coe_image_of_subset {s t : set α} (h : t ⊆ s) : coe '' {x : ↥s | ↑x ∈ t} = t :=
begin
ext x,
rw set.mem_image,
exact ⟨λ ⟨x', hx', hx⟩, hx ▸ hx', λ hx, ⟨⟨x, h hx⟩, hx, rfl⟩⟩,
end
lemma range_coe {s : set α} :
range (coe : s → α) = s :=
by { rw ← set.image_univ, simp [-set.image_univ, coe_image] }
/-- A variant of `range_coe`. Try to use `range_coe` if possible.
This version is useful when defining a new type that is defined as the subtype of something.
In that case, the coercion doesn't fire anymore. -/
lemma range_val {s : set α} :
range (subtype.val : s → α) = s :=
range_coe
/-- We make this the simp lemma instead of `range_coe`. The reason is that if we write
for `s : set α` the function `coe : s → α`, then the inferred implicit arguments of `coe` are
`coe α (λ x, x ∈ s)`. -/
@[simp] lemma range_coe_subtype {p : α → Prop} :
range (coe : subtype p → α) = {x | p x} :=
range_coe
@[simp] lemma coe_preimage_self (s : set α) : (coe : s → α) ⁻¹' s = univ :=
by rw [← preimage_range (coe : s → α), range_coe]
lemma range_val_subtype {p : α → Prop} :
range (subtype.val : subtype p → α) = {x | p x} :=
range_coe
theorem coe_image_subset (s : set α) (t : set s) : coe '' t ⊆ s :=
λ x ⟨y, yt, yvaleq⟩, by rw ←yvaleq; exact y.property
theorem coe_image_univ (s : set α) : (coe : s → α) '' set.univ = s :=
image_univ.trans range_coe
@[simp] theorem image_preimage_coe (s t : set α) :
(coe : s → α) '' (coe ⁻¹' t) = t ∩ s :=
image_preimage_eq_inter_range.trans $ congr_arg _ range_coe
theorem image_preimage_val (s t : set α) :
(subtype.val : s → α) '' (subtype.val ⁻¹' t) = t ∩ s :=
image_preimage_coe s t
theorem preimage_coe_eq_preimage_coe_iff {s t u : set α} :
((coe : s → α) ⁻¹' t = coe ⁻¹' u) ↔ t ∩ s = u ∩ s :=
by rw [← image_preimage_coe, ← image_preimage_coe, coe_injective.image_injective.eq_iff]
@[simp] theorem preimage_coe_inter_self (s t : set α) :
(coe : s → α) ⁻¹' (t ∩ s) = coe ⁻¹' t :=
by rw [preimage_coe_eq_preimage_coe_iff, inter_assoc, inter_self]
theorem preimage_val_eq_preimage_val_iff (s t u : set α) :
((subtype.val : s → α) ⁻¹' t = subtype.val ⁻¹' u) ↔ (t ∩ s = u ∩ s) :=
preimage_coe_eq_preimage_coe_iff
lemma exists_set_subtype {t : set α} (p : set α → Prop) :
(∃(s : set t), p (coe '' s)) ↔ ∃(s : set α), s ⊆ t ∧ p s :=
begin
split,
{ rintro ⟨s, hs⟩, refine ⟨coe '' s, _, hs⟩,
convert image_subset_range _ _, rw [range_coe] },
rintro ⟨s, hs₁, hs₂⟩, refine ⟨coe ⁻¹' s, _⟩,
rw [image_preimage_eq_of_subset], exact hs₂, rw [range_coe], exact hs₁
end
lemma preimage_coe_nonempty {s t : set α} : ((coe : s → α) ⁻¹' t).nonempty ↔ (s ∩ t).nonempty :=
by rw [inter_comm, ← image_preimage_coe, nonempty_image_iff]
lemma preimage_coe_eq_empty {s t : set α} : (coe : s → α) ⁻¹' t = ∅ ↔ s ∩ t = ∅ :=
by simp only [← not_nonempty_iff_eq_empty, preimage_coe_nonempty]
@[simp] lemma preimage_coe_compl (s : set α) : (coe : s → α) ⁻¹' sᶜ = ∅ :=
preimage_coe_eq_empty.2 (inter_compl_self s)
@[simp] lemma preimage_coe_compl' (s : set α) : (coe : sᶜ → α) ⁻¹' s = ∅ :=
preimage_coe_eq_empty.2 (compl_inter_self s)
end subtype
/-! ### Images and preimages on `option` -/
open set
namespace option
lemma injective_iff {α β} {f : option α → β} :
injective f ↔ injective (f ∘ some) ∧ f none ∉ range (f ∘ some) :=
begin
simp only [mem_range, not_exists, (∘)],
refine ⟨λ hf, ⟨hf.comp (option.some_injective _), λ x, hf.ne $ option.some_ne_none _⟩, _⟩,
rintro ⟨h_some, h_none⟩ (_|a) (_|b) hab,
exacts [rfl, (h_none _ hab.symm).elim, (h_none _ hab).elim, congr_arg some (h_some hab)]
end
lemma range_eq {α β} (f : option α → β) : range f = insert (f none) (range (f ∘ some)) :=
set.ext $ λ y, option.exists.trans $ eq_comm.or iff.rfl
end option
lemma with_bot.range_eq {α β} (f : with_bot α → β) :
range f = insert (f ⊥) (range (f ∘ coe : α → β)) :=
option.range_eq f
lemma with_top.range_eq {α β} (f : with_top α → β) :
range f = insert (f ⊤) (range (f ∘ coe : α → β)) :=
option.range_eq f
namespace set
open function
/-! ### Injectivity and surjectivity lemmas for image and preimage -/
section image_preimage
variables {f : α → β}
@[simp] lemma preimage_injective : injective (preimage f) ↔ surjective f :=
begin
refine ⟨λ h y, _, surjective.preimage_injective⟩,
obtain ⟨x, hx⟩ : (f ⁻¹' {y}).nonempty,
{ rw [h.nonempty_apply_iff preimage_empty], apply singleton_nonempty },
exact ⟨x, hx⟩
end
@[simp]
lemma preimage_surjective : surjective (preimage f) ↔ injective f :=
begin
refine ⟨λ h x x' hx, _, injective.preimage_surjective⟩,
cases h {x} with s hs, have := mem_singleton x,
rwa [← hs, mem_preimage, hx, ← mem_preimage, hs, mem_singleton_iff, eq_comm] at this
end
@[simp] lemma image_surjective : surjective (image f) ↔ surjective f :=
begin
refine ⟨λ h y, _, surjective.image_surjective⟩,
cases h {y} with s hs,
have := mem_singleton y, rw [← hs] at this, rcases this with ⟨x, h1x, h2x⟩,
exact ⟨x, h2x⟩
end
@[simp] lemma image_injective : injective (image f) ↔ injective f :=
begin
refine ⟨λ h x x' hx, _, injective.image_injective⟩,
rw [← singleton_eq_singleton_iff], apply h,
rw [image_singleton, image_singleton, hx]
end
lemma preimage_eq_iff_eq_image {f : α → β} (hf : bijective f) {s t} :
f ⁻¹' s = t ↔ s = f '' t :=
by rw [← image_eq_image hf.1, hf.2.image_preimage]
lemma eq_preimage_iff_image_eq {f : α → β} (hf : bijective f) {s t} :
s = f ⁻¹' t ↔ f '' s = t :=
by rw [← image_eq_image hf.1, hf.2.image_preimage]
end image_preimage
end set
/-! ### Disjoint lemmas for image and preimage -/
section disjoint
variables {f : α → β} {s t : set α}
lemma disjoint.preimage (f : α → β) {s t : set β} (h : disjoint s t) :
disjoint (f ⁻¹' s) (f ⁻¹' t) :=
disjoint_iff_inf_le.mpr $ λ x hx, h.le_bot hx
namespace set
theorem disjoint_image_image {f : β → α} {g : γ → α} {s : set β} {t : set γ}
(h : ∀ b ∈ s, ∀ c ∈ t, f b ≠ g c) : disjoint (f '' s) (g '' t) :=
disjoint_iff_inf_le.mpr $ by rintro a ⟨⟨b, hb, eq⟩, c, hc, rfl⟩; exact h b hb c hc eq
lemma disjoint_image_of_injective {f : α → β} (hf : injective f) {s t : set α}
(hd : disjoint s t) : disjoint (f '' s) (f '' t) :=
disjoint_image_image $ λ x hx y hy, hf.ne $ λ H, set.disjoint_iff.1 hd ⟨hx, H.symm ▸ hy⟩
lemma _root_.disjoint.of_image (h : disjoint (f '' s) (f '' t)) : disjoint s t :=
disjoint_iff_inf_le.mpr $
λ x hx, disjoint_left.1 h (mem_image_of_mem _ hx.1) (mem_image_of_mem _ hx.2)
lemma disjoint_image_iff (hf : injective f) : disjoint (f '' s) (f '' t) ↔ disjoint s t :=
⟨disjoint.of_image, disjoint_image_of_injective hf⟩
lemma _root_.disjoint.of_preimage (hf : surjective f) {s t : set β}
(h : disjoint (f ⁻¹' s) (f ⁻¹' t)) :
disjoint s t :=
by rw [disjoint_iff_inter_eq_empty, ←image_preimage_eq (_ ∩ _) hf, preimage_inter, h.inter_eq,
image_empty]
lemma disjoint_preimage_iff (hf : surjective f) {s t : set β} :
disjoint (f ⁻¹' s) (f ⁻¹' t) ↔ disjoint s t :=
⟨disjoint.of_preimage hf, disjoint.preimage _⟩
lemma preimage_eq_empty {f : α → β} {s : set β} (h : disjoint s (range f)) :
f ⁻¹' s = ∅ :=
by simpa using h.preimage f
lemma preimage_eq_empty_iff {s : set β} : f ⁻¹' s = ∅ ↔ disjoint s (range f) :=
⟨λ h, begin
simp only [eq_empty_iff_forall_not_mem, disjoint_iff_inter_eq_empty, not_exists,
mem_inter_iff, not_and, mem_range, mem_preimage] at h ⊢,
assume y hy x hx,
rw ← hx at hy,
exact h x hy,
end, preimage_eq_empty⟩
end set
end disjoint
|
3d4e30353dd572b740925dfee25e7b7ae5b7896b | 5749d8999a76f3a8fddceca1f6941981e33aaa96 | /src/topology/subset_properties.lean | ec1a3c9ee041626bbc3b25abf5eb9abbb605e0cf | [
"Apache-2.0"
] | permissive | jdsalchow/mathlib | 13ab43ef0d0515a17e550b16d09bd14b76125276 | 497e692b946d93906900bb33a51fd243e7649406 | refs/heads/master | 1,585,819,143,348 | 1,580,072,892,000 | 1,580,072,892,000 | 154,287,128 | 0 | 0 | Apache-2.0 | 1,540,281,610,000 | 1,540,281,609,000 | null | UTF-8 | Lean | false | false | 35,156 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov
-/
import topology.continuous_on
/-!
# Properties of subsets of topological spaces
## Main definitions
`compact`, `is_clopen`, `is_irreducible`, `is_connected`, `is_totally_disconnected`, `is_totally_separated`
TODO: write better docs
-/
open set filter lattice classical
open_locale classical topological_space
universes u v
variables {α : Type u} {β : Type v} [topological_space α]
/- compact sets -/
section compact
/-- A set `s` is compact if for every filter `f` that contains `s`,
every set of `f` also meets every neighborhood of some `a ∈ s`. -/
def compact (s : set α) := ∀f, f ≠ ⊥ → f ≤ principal s → ∃a∈s, f ⊓ 𝓝 a ≠ ⊥
lemma compact.inter_right {s t : set α} (hs : compact s) (ht : is_closed t) : compact (s ∩ t) :=
assume f hnf hstf,
let ⟨a, hsa, (ha : f ⊓ 𝓝 a ≠ ⊥)⟩ := hs f hnf (le_trans hstf (le_principal_iff.2 (inter_subset_left _ _))) in
have a ∈ t,
from ht.mem_of_nhds_within_ne_bot $ ne_bot_of_le_ne_bot (by { rw inf_comm at ha, exact ha }) $
inf_le_inf (le_refl _) (le_trans hstf (le_principal_iff.2 (inter_subset_right _ _))),
⟨a, ⟨hsa, this⟩, ha⟩
lemma compact.inter_left {s t : set α} (ht : compact t) (hs : is_closed s) : compact (s ∩ t) :=
inter_comm t s ▸ ht.inter_right hs
lemma compact_diff {s t : set α} (hs : compact s) (ht : is_open t) : compact (s \ t) :=
hs.inter_right (is_closed_compl_iff.mpr ht)
lemma compact_of_is_closed_subset {s t : set α}
(hs : compact s) (ht : is_closed t) (h : t ⊆ s) : compact t :=
inter_eq_self_of_subset_right h ▸ hs.inter_right ht
lemma compact.adherence_nhdset {s t : set α} {f : filter α}
(hs : compact s) (hf₂ : f ≤ principal s) (ht₁ : is_open t) (ht₂ : ∀a∈s, 𝓝 a ⊓ f ≠ ⊥ → a ∈ t) :
t ∈ f :=
classical.by_cases mem_sets_of_eq_bot $
assume : f ⊓ principal (- t) ≠ ⊥,
let ⟨a, ha, (hfa : f ⊓ principal (-t) ⊓ 𝓝 a ≠ ⊥)⟩ := hs _ this $ inf_le_left_of_le hf₂ in
have a ∈ t,
from ht₂ a ha $ ne_bot_of_le_ne_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_left,
have nhds_within a (-t) ≠ ⊥,
from ne_bot_of_le_ne_bot hfa $ le_inf inf_le_right $ inf_le_left_of_le inf_le_right,
have ∀s∈ nhds_within a (-t), s ≠ ∅,
from forall_sets_ne_empty_iff_ne_bot.mpr this,
have false,
from this _ ⟨t, mem_nhds_sets ht₁ ‹a ∈ t›, -t, subset.refl _, subset.refl _⟩ (inter_compl_self _),
by contradiction
lemma compact_iff_ultrafilter_le_nhds {s : set α} :
compact s ↔ (∀f, is_ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ 𝓝 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, is_ultrafilter f → f ≤ principal s → ∃a∈s, f ≤ 𝓝 a),
assume f hf hfs,
let ⟨a, ha, (h : ultrafilter_of f ≤ 𝓝 a)⟩ :=
hs (ultrafilter_of f) (ultrafilter_ultrafilter_of hf) (le_trans ultrafilter_of_le hfs) in
have ultrafilter_of f ⊓ 𝓝 a ≠ ⊥,
by simp only [inf_of_le_left, h]; exact (ultrafilter_ultrafilter_of hf).left,
⟨a, ha, ne_bot_of_le_ne_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_ne_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_subset_diff_right $ sUnion_mono $ subset_union_left _ _,
principal_mono.mpr $ diff_subset_diff_right $ sUnion_mono $ subset_union_right _ _⟩)
(assume ⟨c', hc'₁, hc'₂⟩, show principal (s \ _) ≠ ⊥, by simp only [ne.def, principal_eq_bot_iff, diff_eq_empty]; exact h hc'₁ hc'₂),
have f ≤ principal s, from infi_le_of_le ⟨∅, empty_subset _, finite_empty⟩ $
show principal (s \ ⋃₀∅) ≤ principal s, from le_principal_iff.2 (diff_subset _ _),
let
⟨a, ha, (h : f ⊓ 𝓝 a ≠ ⊥)⟩ := hs f ‹f ≠ ⊥› this,
⟨t, ht₁, (ht₂ : a ∈ t)⟩ := hc₂ ha
in
have f ≤ principal (-t),
from infi_le_of_le ⟨{t}, by rwa singleton_subset_iff, finite_insert _ finite_empty⟩ $
principal_mono.mpr $
show s - ⋃₀{t} ⊆ - t, begin rw sUnion_singleton; exact assume x ⟨_, hnt⟩, hnt end,
have is_closed (- t), from is_open_compl_iff.mp $ by rw lattice.neg_neg; exact hc₁ t ht₁,
have a ∈ - t, from is_closed_iff_nhds.mp this _ $ ne_bot_of_le_ne_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 ⟨∅, empty_subset _, finite_empty, 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 rwa set.sUnion_image,
let ⟨d, hd₁, hd₂, hd₃⟩ := hs.elim_finite_subcover 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 only [f, dif_pos hid, (hf ⟨_, hid⟩).2] using hxi⟩,
⟨f '' d,
assume i ⟨j, hj, h⟩,
h ▸ by simpa only [f, dif_pos hj] using (hf ⟨_, hj⟩).1,
finite_image f hd₂,
subset.trans hd₃ $ by simpa only [subset_def, mem_sUnion, exists_imp_distrib, mem_Union, exists_prop, and_imp]⟩
section
-- this proof times out without this
local attribute [instance, priority 1000] classical.prop_decidable
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 ⊓ 𝓝 x ≠ ⊥),
have hf : ∀x∈s, 𝓝 x ⊓ f = ⊥,
by simpa only [not_exists, not_not, inf_comm],
have ¬ ∃x∈s, ∀t∈f.sets, x ∈ closure t,
from assume ⟨x, hxs, hx⟩,
have ∅ ∈ 𝓝 x ⊓ f, 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 ∅ ∈ 𝓝 x ⊓ principal t₂,
from (𝓝 x ⊓ principal t₂).sets_of_superset (inter_mem_inf_sets ht₁ (subset.refl t₂)) ht,
have 𝓝 x ⊓ principal t₂ = ⊥,
by rwa [empty_in_sets_eq_bot] at this,
by simp only [closure_eq_nhds] at hx; exact hx t₂ ht₂ this,
have ∀x∈s, ∃t∈f.sets, x ∉ closure t, by simpa only [not_exists, 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 only [subset_def, sUnion_image, mem_Union]) in
let ⟨b, hb⟩ := axiom_of_choice $
show ∀s:c', ∃t, t ∈ f ∧ - closure t = s,
from assume ⟨x, hx⟩, hcc' hx in
have (⋂s∈c', if h : s ∈ c' then b ⟨s, h⟩ else univ) ∈ f,
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,
from inter_mem_sets (le_principal_iff.1 hfs) this,
have ∅ ∈ f,
from mem_sets_of_superset this $ assume x ⟨hxs, hxi⟩,
let ⟨t, htc', hxt⟩ := (show ∃t ∈ c', x ∈ t, from hsc' hxs) in
have -closure (b ⟨t, htc'⟩) = t, from (hb _).right,
have x ∈ - t,
from this ▸ (calc x ∈ b ⟨t, htc'⟩ : by rw mem_bInter_iff at hxi; have h := hxi t htc'; rwa [dif_pos htc'] at h
... ⊆ closure (b ⟨t, htc'⟩) : subset_closure
... ⊆ - - closure (b ⟨t, htc'⟩) : by rw lattice.neg_neg; exact subset.refl _),
show false, from this hxt,
hfn $ by rwa [empty_in_sets_eq_bot] at this
end
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, hc.elim_finite_subcover, compact_of_finite_subcover⟩
lemma compact_empty : compact (∅ : set α) :=
assume f hnf hsf, not.elim hnf $
empty_in_sets_eq_bot.1 $ le_principal_iff.1 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, from mem_sUnion.1 $ singleton_subset_iff.1 hc₂) in
⟨{i}, singleton_subset_iff.2 hic, finite_singleton _, by rwa [sUnion_singleton, singleton_subset_iff]⟩
lemma set.finite.compact_bUnion {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⟩, (hf i hi).elim_finite_subcover 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_Union {f : β → set α} [fintype β]
(h : ∀i, compact (f i)) : compact (⋃i, f i) :=
by rw ← bUnion_univ; exact finite_univ.compact_bUnion (λ i _, h i)
lemma set.finite.compact {s : set α} (hs : finite s) : compact s :=
bUnion_of_singleton s ▸ hs.compact_bUnion (λ _ _, compact_singleton)
lemma compact.union {s t : set α} (hs : compact s) (ht : compact t) : compact (s ∪ t) :=
by rw union_eq_Union; exact compact_Union (λ b, by cases b; assumption)
section tube_lemma
variables [topological_space β]
/-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes
a product of an open neighborhood of `s` by an open neighborhood of `t`. -/
def nhds_contain_boxes (s : set α) (t : set β) : Prop :=
∀ (n : set (α × β)) (hn : is_open n) (hp : set.prod s t ⊆ n),
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n
lemma nhds_contain_boxes.symm {s : set α} {t : set β} :
nhds_contain_boxes s t → nhds_contain_boxes t s :=
assume H n hn hp,
let ⟨u, v, uo, vo, su, tv, p⟩ :=
H (prod.swap ⁻¹' n)
(continuous_swap n hn)
(by rwa [←image_subset_iff, prod.swap, image_swap_prod]) in
⟨v, u, vo, uo, tv, su,
by rwa [←image_subset_iff, prod.swap, image_swap_prod] at p⟩
lemma nhds_contain_boxes.comm {s : set α} {t : set β} :
nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=
iff.intro nhds_contain_boxes.symm nhds_contain_boxes.symm
lemma nhds_contain_boxes_of_singleton {x : α} {y : β} :
nhds_contain_boxes ({x} : set α) ({y} : set β) :=
assume n hn hp,
let ⟨u, v, uo, vo, xu, yv, hp'⟩ :=
is_open_prod_iff.mp hn x y (hp $ by simp) in
⟨u, v, uo, vo, by simpa, by simpa, hp'⟩
lemma nhds_contain_boxes_of_compact {s : set α} (hs : compact s) (t : set β)
(H : ∀ x ∈ s, nhds_contain_boxes ({x} : set α) t) : nhds_contain_boxes s t :=
assume n hn hp,
have ∀x : subtype s, ∃uv : set α × set β,
is_open uv.1 ∧ is_open uv.2 ∧ {↑x} ⊆ uv.1 ∧ t ⊆ uv.2 ∧ set.prod uv.1 uv.2 ⊆ n,
from assume ⟨x, hx⟩,
have set.prod {x} t ⊆ n, from
subset.trans (prod_mono (by simpa) (subset.refl _)) hp,
let ⟨ux,vx,H1⟩ := H x hx n hn this in ⟨⟨ux,vx⟩,H1⟩,
let ⟨uvs, h⟩ := classical.axiom_of_choice this in
have us_cover : s ⊆ ⋃i, (uvs i).1, from
assume x hx, set.subset_Union _ ⟨x,hx⟩ (by simpa using (h ⟨x,hx⟩).2.2.1),
let ⟨s0, _, s0_fin, s0_cover⟩ :=
hs.elim_finite_subcover_image (λi _, (h i).1) $
by rw bUnion_univ; exact us_cover in
let u := ⋃(i ∈ s0), (uvs i).1 in
let v := ⋂(i ∈ s0), (uvs i).2 in
have is_open u, from is_open_bUnion (λi _, (h i).1),
have is_open v, from is_open_bInter s0_fin (λi _, (h i).2.1),
have t ⊆ v, from subset_bInter (λi _, (h i).2.2.2.1),
have set.prod u v ⊆ n, from assume ⟨x',y'⟩ ⟨hx',hy'⟩,
have ∃i ∈ s0, x' ∈ (uvs i).1, by simpa using hx',
let ⟨i,is0,hi⟩ := this in
(h i).2.2.2.2 ⟨hi, (bInter_subset_of_mem is0 : v ⊆ (uvs i).2) hy'⟩,
⟨u, v, ‹is_open u›, ‹is_open v›, s0_cover, ‹t ⊆ v›, ‹set.prod u v ⊆ n›⟩
lemma generalized_tube_lemma {s : set α} (hs : compact s) {t : set β} (ht : compact t)
{n : set (α × β)} (hn : is_open n) (hp : set.prod s t ⊆ n) :
∃ (u : set α) (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n :=
have _, from
nhds_contain_boxes_of_compact hs t $ assume x _, nhds_contain_boxes.symm $
nhds_contain_boxes_of_compact ht {x} $ assume y _, nhds_contain_boxes_of_singleton,
this n hn hp
end tube_lemma
/-- Type class for compact spaces. Separation is sometimes included in the definition, especially
in the French literature, but we do not include it here. -/
class compact_space (α : Type*) [topological_space α] : Prop :=
(compact_univ : compact (univ : set α))
lemma compact_univ [h : compact_space α] : compact (univ : set α) := h.compact_univ
lemma is_closed.compact [compact_space α] {s : set α} (h : is_closed s) :
compact s :=
compact_of_is_closed_subset compact_univ h (subset_univ _)
variables [topological_space β]
lemma compact.image_of_continuous_on {s : set α} {f : α → β} (hs : compact s)
(hf : continuous_on f s) : compact (f '' s) :=
begin
intros l lne ls,
have ne_bot : l.comap f ⊓ principal s ≠ ⊥,
from comap_inf_principal_ne_bot_of_image_mem lne (le_principal_iff.1 ls),
rcases hs (l.comap f ⊓ principal s) ne_bot inf_le_right with ⟨a, has, ha⟩,
use [f a, mem_image_of_mem f has],
rw [inf_assoc, @inf_comm _ _ _ (𝓝 a)] at ha,
exact ne_bot_of_le_ne_bot (@@map_ne_bot f ha) (tendsto_comap.inf $ hf a has)
end
lemma compact.image {s : set α} {f : α → β} (hs : compact s) (hf : continuous f) :
compact (f '' s) :=
hs.image_of_continuous_on hf.continuous_on
lemma compact_range [compact_space α] {f : α → β} (hf : continuous f) :
compact (range f) :=
by rw ← image_univ; exact compact_univ.image hf
lemma embedding.compact_iff_compact_image {s : set α} {f : α → β} (hf : embedding f) :
compact s ↔ compact (f '' s) :=
iff.intro (assume h, h.image hf.continuous) $ assume h, begin
rw compact_iff_ultrafilter_le_nhds at ⊢ h,
intros u hu us',
let u' : filter β := map f u,
have : u' ≤ principal (f '' s), begin
rw [map_le_iff_le_comap, comap_principal], convert us',
exact preimage_image_eq _ hf.inj
end,
rcases h u' (ultrafilter_map hu) this with ⟨_, ⟨a, ha, ⟨⟩⟩, _⟩,
refine ⟨a, ha, _⟩,
rwa [hf.induced, nhds_induced, ←map_le_iff_le_comap]
end
lemma compact_iff_compact_in_subtype {p : α → Prop} {s : set {a // p a}} :
compact s ↔ compact (subtype.val '' s) :=
embedding_subtype_val.compact_iff_compact_image
lemma compact_iff_compact_univ {s : set α} : compact s ↔ compact (univ : set (subtype s)) :=
by rw [compact_iff_compact_in_subtype, image_univ, subtype.val_range]; refl
lemma compact_iff_compact_space {s : set α} : compact s ↔ compact_space s :=
compact_iff_compact_univ.trans ⟨λ h, ⟨h⟩, @compact_space.compact_univ _ _⟩
lemma compact.prod {s : set α} {t : set β} (hs : compact s) (ht : compact t) : compact (set.prod s t) :=
begin
rw compact_iff_ultrafilter_le_nhds at hs ht ⊢,
intros f hf hfs,
rw le_principal_iff at hfs,
rcases hs (map prod.fst f) (ultrafilter_map hf)
(le_principal_iff.2 (mem_map_sets_iff.2
⟨_, hfs, image_subset_iff.2 (λ s h, h.1)⟩)) with ⟨a, sa, ha⟩,
rcases ht (map prod.snd f) (ultrafilter_map hf)
(le_principal_iff.2 (mem_map_sets_iff.2
⟨_, hfs, image_subset_iff.2 (λ s h, h.2)⟩)) with ⟨b, tb, hb⟩,
rw map_le_iff_le_comap at ha hb,
refine ⟨⟨a, b⟩, ⟨sa, tb⟩, _⟩,
rw nhds_prod_eq, exact le_inf ha hb
end
/-- Finite topological spaces are compact. -/
@[priority 100] instance fintype.compact_space [fintype α] : compact_space α :=
{ compact_univ := set.finite_univ.compact }
/-- The product of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α × β) :=
⟨by { rw ← univ_prod_univ, exact compact_univ.prod compact_univ }⟩
/-- The disjoint union of two compact spaces is compact. -/
instance [compact_space α] [compact_space β] : compact_space (α ⊕ β) :=
⟨begin
rw ← range_inl_union_range_inr,
exact (compact_range continuous_inl).union (compact_range continuous_inr)
end⟩
section tychonoff
variables {ι : Type*} {π : ι → Type*} [∀i, topological_space (π i)]
/-- Tychonoff's theorem -/
lemma compact_pi_infinite {s : Πi:ι, set (π i)} :
(∀i, compact (s i)) → compact {x : Πi:ι, π i | ∀i, x i ∈ s i} :=
begin
simp [compact_iff_ultrafilter_le_nhds, nhds_pi],
exact assume h f hf hfs,
let p : Πi:ι, filter (π i) := λi, map (λx:Πi:ι, π i, x i) f in
have ∀i:ι, ∃a, a∈s i ∧ p i ≤ 𝓝 a,
from assume i, h i (p i) (ultrafilter_map hf) $
show (λx:Πi:ι, π i, x i) ⁻¹' s i ∈ f.sets,
from mem_sets_of_superset hfs $ assume x (hx : ∀i, x i ∈ s i), hx i,
let ⟨a, ha⟩ := classical.axiom_of_choice this in
⟨a, assume i, (ha i).left, assume i, map_le_iff_le_comap.mp $ (ha i).right⟩
end
instance pi.compact [∀i:ι, compact_space (π i)] : compact_space (Πi, π i) :=
⟨begin
have A : compact {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} :=
compact_pi_infinite (λi, compact_univ),
have : {x : Πi:ι, π i | ∀i, x i ∈ (univ : set (π i))} = univ := by ext; simp,
rwa this at A,
end⟩
end tychonoff
instance quot.compact_space {r : α → α → Prop} [compact_space α] :
compact_space (quot r) :=
⟨by { rw ← range_quot_mk, exact compact_range continuous_quot_mk }⟩
instance quotient.compact_space {s : setoid α} [compact_space α] :
compact_space (quotient s) :=
quot.compact_space
/-- There are various definitions of "locally compact space" in the literature, which agree for
Hausdorff spaces but not in general. This one is the precise condition on X needed for the
evaluation `map C(X, Y) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the
compact-open topology. -/
class locally_compact_space (α : Type*) [topological_space α] : Prop :=
(local_compact_nhds : ∀ (x : α) (n ∈ 𝓝 x), ∃ s ∈ 𝓝 x, s ⊆ n ∧ compact s)
end compact
section clopen
/-- A set is clopen if it is both open and closed. -/
def is_clopen (s : set α) : Prop :=
is_open s ∧ is_closed s
theorem is_clopen_union {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) :=
⟨is_open_union hs.1 ht.1, is_closed_union hs.2 ht.2⟩
theorem is_clopen_inter {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) :=
⟨is_open_inter hs.1 ht.1, is_closed_inter hs.2 ht.2⟩
@[simp] theorem is_clopen_empty : is_clopen (∅ : set α) :=
⟨is_open_empty, is_closed_empty⟩
@[simp] theorem is_clopen_univ : is_clopen (univ : set α) :=
⟨is_open_univ, is_closed_univ⟩
theorem is_clopen_compl {s : set α} (hs : is_clopen s) : is_clopen (-s) :=
⟨hs.2, is_closed_compl_iff.2 hs.1⟩
@[simp] theorem is_clopen_compl_iff {s : set α} : is_clopen (-s) ↔ is_clopen s :=
⟨λ h, compl_compl s ▸ is_clopen_compl h, is_clopen_compl⟩
theorem is_clopen_diff {s t : set α} (hs : is_clopen s) (ht : is_clopen t) : is_clopen (s-t) :=
is_clopen_inter hs (is_clopen_compl ht)
end clopen
section irreducible
/-- An irreducible set is one where there is no non-trivial pair of disjoint opens. -/
def is_irreducible (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v →
(∃ x, x ∈ s ∩ u) → (∃ x, x ∈ s ∩ v) → ∃ x, x ∈ s ∩ (u ∩ v)
theorem is_irreducible_empty : is_irreducible (∅ : set α) :=
λ _ _ _ _ _ ⟨x, h1, h2⟩, h1.elim
theorem is_irreducible_singleton {x} : is_irreducible ({x} : set α) :=
λ u v _ _ ⟨y, h1, h2⟩ ⟨z, h3, h4⟩, by rw mem_singleton_iff at h1 h3;
substs y z; exact ⟨x, or.inl rfl, h2, h4⟩
theorem is_irreducible_closure {s : set α} (H : is_irreducible s) :
is_irreducible (closure s) :=
λ u v hu hv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := exists_mem_of_ne_empty (mem_closure_iff.1 hycs u hu hyu) in
let ⟨q, hqv, hqs⟩ := exists_mem_of_ne_empty (mem_closure_iff.1 hzcs v hv hzv) in
let ⟨r, hrs, hruv⟩ := H u v hu hv ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem exists_irreducible (s : set α) (H : is_irreducible s) :
∃ t : set α, is_irreducible t ∧ s ⊆ t ∧ ∀ u, is_irreducible u → t ⊆ u → u = t :=
let ⟨m, hm, hsm, hmm⟩ := zorn.zorn_subset₀ { t : set α | is_irreducible t }
(λ c hc hcc hcn, let ⟨t, htc⟩ := exists_mem_of_ne_empty hcn in
⟨⋃₀ c, λ u v hu hv ⟨y, hy, hyu⟩ ⟨z, hz, hzv⟩,
let ⟨p, hpc, hyp⟩ := mem_sUnion.1 hy,
⟨q, hqc, hzq⟩ := mem_sUnion.1 hz in
or.cases_on (zorn.chain.total hcc hpc hqc)
(assume hpq : p ⊆ q, let ⟨x, hxp, hxuv⟩ := hc hqc u v hu hv
⟨y, hpq hyp, hyu⟩ ⟨z, hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hqc, hxuv⟩)
(assume hqp : q ⊆ p, let ⟨x, hxp, hxuv⟩ := hc hpc u v hu hv
⟨y, hyp, hyu⟩ ⟨z, hqp hzq, hzv⟩ in
⟨x, mem_sUnion_of_mem hxp hpc, hxuv⟩),
λ x hxc, set.subset_sUnion_of_mem hxc⟩) s H in
⟨m, hm, hsm, λ u hu hmu, hmm _ hu hmu⟩
/-- A maximal irreducible set that contains a given point. -/
def irreducible_component (x : α) : set α :=
classical.some (exists_irreducible {x} is_irreducible_singleton)
theorem is_irreducible_irreducible_component {x : α} : is_irreducible (irreducible_component x) :=
(classical.some_spec (exists_irreducible {x} is_irreducible_singleton)).1
theorem mem_irreducible_component {x : α} : x ∈ irreducible_component x :=
singleton_subset_iff.1
(classical.some_spec (exists_irreducible {x} is_irreducible_singleton)).2.1
theorem eq_irreducible_component {x : α} :
∀ {s : set α}, is_irreducible s → irreducible_component x ⊆ s → s = irreducible_component x :=
(classical.some_spec (exists_irreducible {x} is_irreducible_singleton)).2.2
theorem is_closed_irreducible_component {x : α} :
is_closed (irreducible_component x) :=
closure_eq_iff_is_closed.1 $ eq_irreducible_component
(is_irreducible_closure is_irreducible_irreducible_component)
subset_closure
/-- An irreducible space is one where there is no non-trivial pair of disjoint opens. -/
class irreducible_space (α : Type u) [topological_space α] : Prop :=
(is_irreducible_univ : is_irreducible (univ : set α))
theorem irreducible_exists_mem_inter [irreducible_space α] {s t : set α} :
is_open s → is_open t → (∃ x, x ∈ s) → (∃ x, x ∈ t) → ∃ x, x ∈ s ∩ t :=
by simpa only [univ_inter, univ_subset_iff] using
@irreducible_space.is_irreducible_univ α _ _ s t
end irreducible
section connected
/-- A connected set is one where there is no non-trivial open partition. -/
def is_connected (s : set α) : Prop :=
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v →
(∃ x, x ∈ s ∩ u) → (∃ x, x ∈ s ∩ v) → ∃ x, x ∈ s ∩ (u ∩ v)
theorem is_connected_of_is_irreducible {s : set α} (H : is_irreducible s) : is_connected s :=
λ _ _ hu hv _, H _ _ hu hv
theorem is_connected_empty : is_connected (∅ : set α) :=
is_connected_of_is_irreducible is_irreducible_empty
theorem is_connected_singleton {x} : is_connected ({x} : set α) :=
is_connected_of_is_irreducible is_irreducible_singleton
/-- If any point of a set is joined to a fixed point by a connected subset,
then the original set is connected as well. -/
theorem is_connected_of_forall {s : set α} (x : α)
(H : ∀ y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_connected t) :
is_connected s :=
begin
rintros u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩,
have xs : x ∈ s, by { rcases H y ys with ⟨t, ts, xt, yt, ht⟩, exact ts xt },
wlog xu : x ∈ u := hs xs using [u v y z, v u z y],
{ rcases H y ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩) },
{ rw [union_comm v, inter_comm v] at this,
apply this; assumption }
end
/-- If any two points of a set are contained in a connected subset,
then the original set is connected as well. -/
theorem is_connected_of_forall_pair {s : set α}
(H : ∀ x y ∈ s, ∃ t ⊆ s, x ∈ t ∧ y ∈ t ∧ is_connected t) :
is_connected s :=
begin
rintros u v hu hv hs ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
rcases H x y xs ys with ⟨t, ts, xt, yt, ht⟩,
have := ht u v hu hv(subset.trans ts hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩,
exact this.imp (λ z hz, ⟨ts hz.1, hz.2⟩)
end
/-- A union of a family of connected sets with a common point is connected as well. -/
theorem is_connected_sUnion (x : α) (c : set (set α)) (H1 : ∀ s ∈ c, x ∈ s)
(H2 : ∀ s ∈ c, is_connected s) : is_connected (⋃₀ c) :=
begin
apply is_connected_of_forall x,
rintros y ⟨s, sc, ys⟩,
exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩
end
theorem is_connected.union (x : α) {s t : set α} (H1 : x ∈ s) (H2 : x ∈ t)
(H3 : is_connected s) (H4 : is_connected t) : is_connected (s ∪ t) :=
sUnion_pair s t ▸ is_connected_sUnion x {s, t}
(by rintro r (rfl | rfl | h); [exact H2, exact H1, exact h.elim])
(by rintro r (rfl | rfl | h); [exact H4, exact H3, exact h.elim])
theorem is_connected.closure {s : set α} (H : is_connected s) :
is_connected (closure s) :=
λ u v hu hv hcsuv ⟨y, hycs, hyu⟩ ⟨z, hzcs, hzv⟩,
let ⟨p, hpu, hps⟩ := exists_mem_of_ne_empty (mem_closure_iff.1 hycs u hu hyu) in
let ⟨q, hqv, hqs⟩ := exists_mem_of_ne_empty (mem_closure_iff.1 hzcs v hv hzv) in
let ⟨r, hrs, hruv⟩ := H u v hu hv (subset.trans subset_closure hcsuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ in
⟨r, subset_closure hrs, hruv⟩
theorem is_connected.image [topological_space β] {s : set α} (H : is_connected s)
(f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
begin
-- Unfold/destruct definitions in hypotheses
rintros u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩,
rcases continuous_on_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩,
rcases continuous_on_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩,
-- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'`
replace huv : s ⊆ u' ∪ v',
{ rw [image_subset_iff, preimage_union] at huv,
replace huv := subset_inter huv (subset.refl _),
rw [inter_distrib_right, u'_eq, v'_eq, ← inter_distrib_right] at huv,
exact (subset_inter_iff.1 huv).1 },
-- Now `s ⊆ u' ∪ v'`, so we can apply `‹is_connected s›`
obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).nonempty,
{ refine H u' v' hu' hv' huv ⟨x, _⟩ ⟨y, _⟩; rw inter_comm,
exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] },
rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc,
inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz,
exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩
end
theorem is_connected_closed_iff {s : set α} :
is_connected s ↔ ∀ t t', is_closed t → is_closed t' → s ⊆ t ∪ t' →
(s ∩ t).nonempty → (s ∩ t').nonempty → (s ∩ (t ∩ t')).nonempty :=
⟨begin
rintros h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩,
by_contradiction h',
rw [← ne_empty_iff_nonempty, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xt' : x ∉ t', from (h' xs).elim (absurd xt) id,
have yt : y ∉ t, from (h' ys).elim id (absurd yt'),
have := ne_empty_iff_exists_mem.2 (h (-t) (-t') (is_open_compl_iff.2 ht)
(is_open_compl_iff.2 ht') h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end,
begin
rintros h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩,
by_contradiction h',
rw [← ne_empty_iff_exists_mem, ne.def, not_not, ← subset_compl_iff_disjoint, compl_inter] at h',
have xv : x ∉ v, from (h' xs).elim (absurd xu) id,
have yu : y ∉ u, from (h' ys).elim id (absurd yv),
have := ne_empty_iff_nonempty.2 (h (-u) (-v) (is_closed_compl_iff.2 hu)
(is_closed_compl_iff.2 hv) h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩),
rw [ne.def, ← compl_union, ← subset_compl_iff_disjoint, compl_compl] at this,
contradiction
end⟩
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component (x : α) : set α :=
⋃₀ { s : set α | is_connected s ∧ x ∈ s }
theorem is_connected_connected_component {x : α} : is_connected (connected_component x) :=
is_connected_sUnion x _ (λ _, and.right) (λ _, and.left)
theorem mem_connected_component {x : α} : x ∈ connected_component x :=
mem_sUnion_of_mem (mem_singleton x) ⟨is_connected_singleton, mem_singleton x⟩
theorem subset_connected_component {x : α} {s : set α} (H1 : is_connected s) (H2 : x ∈ s) :
s ⊆ connected_component x :=
λ z hz, mem_sUnion_of_mem hz ⟨H1, H2⟩
theorem is_closed_connected_component {x : α} :
is_closed (connected_component x) :=
closure_eq_iff_is_closed.1 $ subset.antisymm
(subset_connected_component
is_connected_connected_component.closure
(subset_closure mem_connected_component))
subset_closure
theorem irreducible_component_subset_connected_component {x : α} :
irreducible_component x ⊆ connected_component x :=
subset_connected_component
(is_connected_of_is_irreducible is_irreducible_irreducible_component)
mem_irreducible_component
/-- A connected space is one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] : Prop :=
(is_connected_univ : is_connected (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
⟨is_connected_of_is_irreducible $ irreducible_space.is_irreducible_univ α⟩
theorem exists_mem_inter [connected_space α] {s t : set α} :
is_open s → is_open t → s ∪ t = univ →
(∃ x, x ∈ s) → (∃ x, x ∈ t) → ∃ x, x ∈ s ∩ t :=
by simpa only [univ_inter, univ_subset_iff] using
@connected_space.is_connected_univ α _ _ s t
theorem is_clopen_iff [connected_space α] {s : set α} : is_clopen s ↔ s = ∅ ∨ s = univ :=
⟨λ hs, classical.by_contradiction $ λ h,
have h1 : s ≠ ∅ ∧ -s ≠ ∅, from ⟨mt or.inl h,
mt (λ h2, or.inr $ (by rw [← compl_compl s, h2, compl_empty] : s = univ)) h⟩,
let ⟨_, h2, h3⟩ := exists_mem_inter hs.1 hs.2 (union_compl_self s)
(ne_empty_iff_exists_mem.1 h1.1) (ne_empty_iff_exists_mem.1 h1.2) in
h3 h2,
by rintro (rfl | rfl); [exact is_clopen_empty, exact is_clopen_univ]⟩
end connected
section totally_disconnected
/-- A set is called totally disconnected if all of its connected components are singletons. -/
def is_totally_disconnected (s : set α) : Prop :=
∀ t, t ⊆ s → is_connected t → subsingleton t
theorem is_totally_disconnected_empty : is_totally_disconnected (∅ : set α) :=
λ t ht _, ⟨λ ⟨_, h⟩, (ht h).elim⟩
theorem is_totally_disconnected_singleton {x} : is_totally_disconnected ({x} : set α) :=
λ t ht _, ⟨λ ⟨p, hp⟩ ⟨q, hq⟩, subtype.eq $ show p = q,
from (eq_of_mem_singleton (ht hp)).symm ▸ (eq_of_mem_singleton (ht hq)).symm⟩
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] : Prop :=
(is_totally_disconnected_univ : is_totally_disconnected (univ : set α))
end totally_disconnected
section totally_separated
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated (s : set α) : Prop :=
∀ x ∈ s, ∀ y ∈ s, x ≠ y → ∃ u v : set α, is_open u ∧ is_open v ∧
x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty : is_totally_separated (∅ : set α) :=
λ x, false.elim
theorem is_totally_separated_singleton {x} : is_totally_separated ({x} : set α) :=
λ p hp q hq hpq, (hpq $ (eq_of_mem_singleton hp).symm ▸ (eq_of_mem_singleton hq).symm).elim
theorem is_totally_disconnected_of_is_totally_separated {s : set α}
(H : is_totally_separated s) : is_totally_disconnected s :=
λ t hts ht, ⟨λ ⟨x, hxt⟩ ⟨y, hyt⟩, subtype.eq $ classical.by_contradiction $
assume hxy : x ≠ y, let ⟨u, v, hu, hv, hxu, hyv, hsuv, huv⟩ := H x (hts hxt) y (hts hyt) hxy in
let ⟨r, hrt, hruv⟩ := ht u v hu hv (subset.trans hts hsuv) ⟨x, hxt, hxu⟩ ⟨y, hyt, hyv⟩ in
((ext_iff _ _).1 huv r).1 hruv⟩
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] : Prop :=
(is_totally_separated_univ : is_totally_separated (univ : set α))
@[priority 100] -- see Note [lower instance priority]
instance totally_separated_space.totally_disconnected_space (α : Type u) [topological_space α]
[totally_separated_space α] : totally_disconnected_space α :=
⟨is_totally_disconnected_of_is_totally_separated $ totally_separated_space.is_totally_separated_univ α⟩
end totally_separated
|
0955ba7989d5100f69788c7cf1d7fc818d9aa34a | a6ea0e5de8b451a584e78d2a3a22466083fd8069 | /src/submission/practice_1.lean | c9c06d319551e54befbe74ab069b9d7784e3ceef | [] | no_license | simonejefferson03/cs2120f21 | cabf9bb8fd636cba947d3a33383a24a9efa51e1e | ee0edf0c5e6f66f28eafbc6787681065800eb7e5 | refs/heads/main | 1,692,061,780,990 | 1,631,910,003,000 | 1,631,910,003,000 | 399,946,493 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,485 | lean | /-
EQUALITY
-/
/- #1
Suppose that x, y, z, and w are arbitrary objects of some type,
T; and suppose further that we know (have proofs of the facts)
that x = y, y = z, and w = z. Give a very, very short English
proof of the conjecture that z = w. You can use not only the
axioms of equality, but either of the theorems about properties
of equality that we have proven. Hint: There's something about
this question that makes it much easier to answer than it might
at first appear.
-/
/-you assume that for all objects of a certain type, T is true,
if we assume that x =y is true and we assume that y = z is true
then you can conclude that x = z is true -/
/- #2
Give a formal statement of the conjecture (proposition) from
#1 by filling in the "hole" in the following definition. The
def is a keyword. The name you're binding to your proposition
is prop_1. The type of the value is Prop (which is the type of
all propositions in Lean).
-/
def prop_1 : Prop :=
∀ (T : Type),
∀ (x y z w : T),
x = y →
y = z →
w = z →
z = w
/- #3 (extra credit)
Give a formal proof of the proposition from #2 by filling in
the hole in this next definition. Hint: Use Lean's versions of
the axioms and basic theorems concerning equality. They are,
again, called eq.refl, eq.subst, eq.symm, eq.trans.
-/
theorem prop_1_proof : prop_1 :=
begin
_
end
/-
FOR ALL: ∀.
-/
/- #4
Give a very brief explanation in English of the introduction
rule for ∀. For example, suppose you need to prove (∀ x, P x);
what do you do? (I'm being a little informal in leaving out the
type of X.)
-/
/-
To accomplish the proof.... we assume that give an arbatray , yet specific type of an object, for any type of that object , if we assume that the obkect contains that property , then we can assume that for every object of that type contain that proerty
-/
/- #5
Suppose you have a proof, let's call it pf, of the proposition,
(∀ x, P x), and you need a proof of P t, for some particular t.
Write an expression then uses the elimination rule for ∀ to get
such a proof. Complete the answer by replacing the underscores
in the following expression: ( _ _ ).
P t := x t
-/
/-
IMPLIES: →
In the "code" that follows, we define two predicates, each
taking one natural number as an argument. We call them ev and
odd. When applied to any value, n, ev yields the proposition
that n is even (n % 2 = 0), while odd yields the proposition
that n is odd (n % 2 = 1).
-/
def ev (n : ℕ) := n % 2 = 0
def odd (n : ℕ) := n % 2 = 1
/- #6
Write a formal version of the proposition that, for *any*
natural number n, *if* n is even, *then* n + 1 is odd. Give
your answer by filling the hole in the following definition.
Hint: put parenthesis around "n + 1" in your answer.
-/
def successor_of_even_is_odd : Prop :=
∀ (n: ℕ ),
ev n → odd (n +1)
/- #7
Suppose that "its_raining" and "the_streets_are_wet" are
propositions. (We formalize these assumptions as axioms in
what follows. Then give a formal definition of the (larger)
proposition, "if it's raining out then the streets are wet")
by filling in the hole
-/
axioms (raining streets_wet : Prop)
axiom if_raining_then_streets_wet :
∀ (T : Type)
(P : T → Prop)
(raining streets_wet : T)
(e : raining = streets_wet)
(praining : P raining),
P streets_wet
/- #9
Now suppose that in addition, its_raining is true, and
we have a proof of it, pf_its_raining. Again, we again give
you this assumption formally as an axiom below. Finish
the formal proof that the streets must be wet. Hint: here
you are asked to use the elimination rule for →.
-/
axiom pf_raining : raining
example : streets_wet :=
begin
apply if_raining_then_streets_wet,
apply pf_raining,
end
_
/-
AND: ∧
-/
/- #10
In our last class, we proved that "∧ is *commutative*."
That is, for any given *propositions*, P and Q, (P ∧ Q) →
(Q ∧ P). The way we proved it was to *assume* that we're
given such a P, Q, and proof, pq, of (P ∧ Q) -- applying
the introduction rules for ∀ and →). In this context, we
*use* the proof, pq, to derive separate proofs, let's call
them p, a proof of P, and q, a proof of Q. With these in
hand, we then apply the introduction rule for ∧ to put
them back together into a proof of (Q ∧ P). We give you
a formal version of this proof as a reminder, next.
-/
theorem and_commutative : ∀ (P Q : Prop), P ∧ Q → Q ∧ P :=
begin
assume P Q pq,
apply and.intro _ _,
exact (and.elim_right pq),
exact (and.elim_left pq),
end
/-
Your task now is to prove the theorem, "∧ is *associative*."
What this means is that for arbitrary propositions, P, Q, and
R, if (P ∧ (Q ∧ R)) is true, then ((P ∧ Q) ∧ R) is true, *and
vice versa*. You just need to prove it in the first direction.
Hint, if you have a proof, p_qr, of (P ∧ (Q ∧ R)), then the
application of and.elim_left will give you a proof of P, and
and.elim_right will give you a proof of (Q ∧ R).
To help you along, we give you the first part of the proof,
including an example of a new Lean tactic called have, which
allows you to give a name to a new value in the middle of a
proof script.
-/
theorem and_associative:
∀ (P Q R : Prop),
(P ∧ (Q ∧ R)) → ((P ∧ Q) ∧ R) :=
begin
intros P Q R h,
have p : P := and.elim_left h,
have qr : Q ∧ R := and.elim_right h,
have q : Q := and.elim_left qr,
have r : R := and.elim_right qr,
have pq : P ∧ Q := and.intro p q,
exact (and.intro pq r),
end
/- #11
Give an English language proof of the preceding
theorem. Do it by finishing off the following
partial "proof explanation."
Proof. We assume that P, Q, and R are arbitrary
but specific propositions, and that we have a
proof, let's call it p_qr, of (P ∧ (Q ∧ R)) [by
application of ∧ and → introduction.] What now
remains to be proved is ((P ∧ Q) ∧ R). We can
construct a proof of this proposition by applying
_____ to a proof of (P ∧ Q) and a proof of R.
What remains, then, is to obtain these proofs.
But this is easily done by the application of
____ to ____. QED.
-/
/-
Note that Lean includes versions of these
theorems (and many, many, many others) in
its extensive library of formalized maths,
as the following check commands reveal.
Note the difference in naming relative to
the definitions we give in this file.
-/
#check @and.comm
#check @and.assoc |
546a2bf4cf672bc65bfdc8cc860c8f0198850392 | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/hit/pushout.lean | 4d61686ba75dbd202656169a73d95594afc56625 | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 12,059 | lean | /-
Copyright (c) 2015-16 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Ulrik Buchholtz, Jakob von Raumer
Declaration and properties of the pushout
-/
import .quotient ..types.arrow_2
universes u v w
hott_theory
namespace hott
open hott.quotient hott.sum sum hott.equiv is_trunc pointed hott.sigma
namespace pushout
section
parameters {TL : Type u} {BL : Type v} {TR : Type w} (f : TL → BL) (g : TL → TR)
private abbreviation A := BL ⊎ TR
inductive pushout_rel : A → A → Type (max u v w)
| Rmk : Π(x : TL), pushout_rel (inl (f x)) (inr (g x))
open pushout_rel
private abbreviation R := pushout_rel
@[hott] def pushout : Type _ := quotient R
parameters {f g}
@[hott] def inl (x : BL) : pushout :=
class_of R (inl x)
@[hott] def inr (x : TR) : pushout :=
class_of R (inr x)
@[hott] def glue (x : TL) : inl (f x) = inr (g x) :=
eq_of_rel pushout_rel (Rmk x)
@[hott, elab_as_eliminator, induction] protected def rec {P : pushout → Type _} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(y : pushout) : P y :=
begin
hinduction y,
{ induction a,
apply Pinl,
apply Pinr},
{ induction H, apply Pglue}
end
@[hott, reducible] protected def rec_on {P : pushout → Type _} (y : pushout)
(Pinl : Π(x : BL), P (inl x)) (Pinr : Π(x : TR), P (inr x))
(Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x)) : P y :=
rec Pinl Pinr Pglue y
@[hott] theorem rec_glue {P : pushout → Type _} (Pinl : Π(x : BL), P (inl x))
(Pinr : Π(x : TR), P (inr x)) (Pglue : Π(x : TL), Pinl (f x) =[glue x] Pinr (g x))
(x : TL) : apd (rec Pinl Pinr Pglue) (glue x) = Pglue x :=
rec_eq_of_rel _ _ _
@[hott, induction, priority 1100] protected def elim {P : Type _} (Pinl : BL → P)
(Pinr : TR → P) (Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (y : pushout) : P :=
begin hinduction y, exact Pinl x, exact Pinr x, exact pathover_of_eq _ (Pglue x) end
@[hott] theorem elim_glue {P : Type _} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) (x : TL)
: ap (elim Pinl Pinr Pglue) (glue x) = Pglue x :=
begin
apply eq_of_fn_eq_fn_inv ((pathover_constant (glue x)) _ _),
refine (apd_eq_pathover_of_eq_ap _ _)⁻¹ ⬝ rec_eq_of_rel _ _ _
end
@[hott] protected def elim_type (Pinl : BL → Type _) (Pinr : TR → Type _)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) : pushout → Type _ :=
quotient.elim_type (λz, sum.rec Pinl Pinr z)
begin intros v v' r, induction r, apply Pglue end
@[hott] theorem elim_type_glue (Pinl : BL → Type _) (Pinr : TR → Type _)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (x : TL)
: transport (elim_type Pinl Pinr Pglue) (glue x) = Pglue x :=
elim_type_eq_of_rel_fn _ _ _
@[hott] theorem elim_type_glue_inv (Pinl : BL → Type _) (Pinr : TR → Type _)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x)) (x : TL)
: transport (elim_type Pinl Pinr Pglue) (glue x)⁻¹ = to_inv (Pglue x) :=
elim_type_eq_of_rel_inv _ _ _
@[hott] protected def rec_prop {P : pushout → Type _} [H : Πx, is_prop (P x)]
(Pinl : Π(x : BL), P (inl x)) (Pinr : Π(x : TR), P (inr x)) (y : pushout) :=
rec Pinl Pinr (λx, is_prop.elimo _ _ _) y
@[hott] protected def elim_prop {P : Type _} [H : is_prop P] (Pinl : BL → P) (Pinr : TR → P)
(y : pushout) : P :=
elim Pinl Pinr (λa, is_prop.elim _ _) y
end
variables {TL : Type u} {BL : Type v} {TR : Type w} (f : TL → BL) (g : TL → TR)
@[hott] protected theorem elim_inl {P : Type _} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) {b b' : BL} (p : b = b')
: ap (pushout.elim Pinl Pinr Pglue) (ap inl p) = ap Pinl p :=
(ap_compose _ _ _)⁻¹
@[hott] protected theorem elim_inr {P : Type _} (Pinl : BL → P) (Pinr : TR → P)
(Pglue : Π(x : TL), Pinl (f x) = Pinr (g x)) {b b' : TR} (p : b = b')
: ap (pushout.elim Pinl Pinr Pglue) (ap inr p) = ap Pinr p :=
(ap_compose _ _ _)⁻¹
/- The non-dependent universal property -/
@[hott] def pushout_arrow_equiv (C : Type _)
: (pushout f g → C) ≃ (Σ(i : BL → C) (j : TR → C), Πc, i (f c) = j (g c)) :=
begin
fapply equiv.MK,
{ intro f, exact ⟨λx, f (inl x), λx, f (inr x), λx, ap f (glue x)⟩},
{ intros v x, induction v with i w, induction w with j p, hinduction x,
exact (i a), exact (j a), exact (p x)},
{ intro v, induction v with i w, induction w with j p, dsimp,
apply ap, apply ap, apply eq_of_homotopy, intro x, apply elim_glue},
{ intro f, apply eq_of_homotopy, intro x, hinduction x, refl, refl, dsimp,
apply eq_pathover, apply hdeg_square, apply elim_glue},
end
/- glue squares -/
@[hott] protected def glue_square {x x' : TL} (p : x = x')
: square (glue x) (glue x') (ap inl (ap f p)) (ap inr (ap g p)) :=
by induction p; apply vrefl
end pushout
--open function --
namespace pushout
/- The flattening lemma -/
section
parameters {TL : Type _} {BL : Type _} {TR : Type _} (f : TL → BL) (g : TL → TR)
(Pinl : BL → Type u) (Pinr : TR → Type u)
(Pglue : Π(x : TL), Pinl (f x) ≃ Pinr (g x))
include Pglue
private abbreviation A := BL ⊎ TR
private abbreviation R : A → A → Type _ := pushout_rel f g
private abbreviation P := pushout.elim_type Pinl Pinr Pglue
private abbreviation F : sigma (Pinl ∘ f) → sigma Pinl :=
λz, ⟨ f z.1 , z.2 ⟩
private abbreviation G : sigma (Pinl ∘ f) → sigma Pinr :=
λz, ⟨ g z.1 , Pglue z.1 z.2 ⟩
@[hott] protected def flattening : sigma P ≃ pushout F G :=
begin
refine quotient.flattening.flattening_lemma _ _ _ ⬝e _,
fapply equiv.MK,
{ intro q, hinduction q with z z z' fr,
{ induction z with a p, induction a with x x,
{ exact inl ⟨x, p⟩ },
{ exact inr ⟨x, p⟩ } },
{ induction fr with a a' r p, induction r with x,
exact glue (⟨x, p⟩ : sigma _) } },
{ intro q, hinduction q with xp xp xp,
{ exact class_of _ ⟨sum.inl xp.1, xp.2⟩ },
{ exact class_of _ ⟨sum.inr xp.1, xp.2⟩ },
{ apply eq_of_rel, dsimp,
exact flattening.flattening_rel.mk _ (pushout_rel.Rmk _ _ _) _ } },
{ intro q, hinduction q with xp xp xp; induction xp with x p,
{ apply ap inl, reflexivity },
{ apply ap inr, reflexivity },
{ apply eq_pathover, dsimp,
rwr [ap_id, ←ap_compose' (quotient.elim _ _)],
rwr elim_glue, rwr elim_eq_of_rel, dsimp, apply hrefl } },
{ intro q, hinduction q with z z z' fr,
{ induction z with a p, induction a with x x,
{ reflexivity },
{ reflexivity } },
{ induction fr with a a' r p, induction r with x,
apply eq_pathover,
rwr [ap_id, ←ap_compose' (pushout.elim _ _ _)],
rwr elim_eq_of_rel, rwr elim_glue, apply hrefl } }
end
end
-- Commutativity of pushouts
section
variables {TL : Type u} {BL : Type v} {TR : Type w} (f : TL → BL) (g : TL → TR)
@[hott] protected def transpose : pushout f g → pushout g f :=
begin
intro x, hinduction x, apply inr a, apply inl a, exact (glue _)⁻¹
end
--TODO prove without krwr?
@[hott] protected def transpose_involutive (x : pushout f g) :
pushout.transpose g f (pushout.transpose f g x) = x :=
begin
hinduction x, apply idp, apply idp,
apply eq_pathover, refine _ ⬝hp (ap_id _)⁻¹ᵖ,
refine ap_compose (pushout.transpose _ _) _ _ ⬝ph _,
apply hdeg_square,
dsimp [pushout.transpose],
rwr [elim_glue, ap_inv, elim_glue, hott.eq.inv_inv],
end
@[hott] protected def symm : pushout f g ≃ pushout g f :=
begin
fapply equiv.MK, apply pushout.transpose, apply pushout.transpose,
intro x; apply pushout.transpose_involutive,
intro x; apply pushout.transpose_involutive
end
end
-- Functoriality of pushouts
section
section lemmas
variables {X : Type _} {x₀ x₁ x₂ x₃ : X}
(p : x₀ = x₁) (q : x₁ = x₂) (r : x₂ = x₃)
@[hott] private def is_equiv_functor_lemma₁
: (r ⬝ ((p ⬝ q ⬝ r)⁻¹ ⬝ p)) = q⁻¹ :=
by induction p; induction r; induction q; reflexivity
@[hott] private def is_equiv_functor_lemma₂
: (p ⬝ q ⬝ r)⁻¹ ⬝ (p ⬝ q) = r⁻¹ :=
by induction p; induction r; induction q; reflexivity
end lemmas
variables {TL : Type _} {BL : Type _} {TR : Type _} {f : TL → BL} {g : TL → TR}
{TL' : Type _} {BL' : Type _} {TR' : Type _} {f' : TL' → BL'} {g' : TL' → TR'}
(tl : TL → TL') (bl : BL → BL') (tr : TR → TR')
(fh : bl ∘ f ~ f' ∘ tl) (gh : tr ∘ g ~ g' ∘ tl)
include fh gh
def pushout_rel_functor {{x x' : BL ⊎ TR}}
(r : pushout_rel f g x x') : pushout_rel f' g' (x.functor bl tr) (x'.functor bl tr) :=
begin
induction r,
apply transport11 (pushout_rel f' g') (ap sum.inl (fh r)⁻¹ᵖ) (ap sum.inr (gh r)⁻¹ᵖ),
constructor
end
@[hott] protected def functor : pushout f g → pushout f' g' :=
begin
intro x, hinduction x with a b z,
{ exact inl (bl a) },
{ exact inr (tr b) },
{ exact (ap inl (fh z)) ⬝ glue (tl z) ⬝ (ap inr (gh z)⁻¹) }
end
@[hott] protected def pushout_functor_homotopy_quotient_functor :
pushout.functor tl bl tr fh gh ~
quotient.functor (sum.functor bl tr) (pushout_rel_functor tl bl tr fh gh) :=
begin
intro x, hinduction x with a b z,
{ refl },
{ refl },
{ dsimp, apply eq_pathover, apply hdeg_square,
refine elim_glue _ _ _ _ ⬝ _ ⬝ (functor_eq_of_rel _ _ _)⁻¹ᵖ,
dsimp [glue, pushout_rel_functor], rwr [ap_inv],
symmetry, apply eq_top_of_square,
refine ap_compose (class_of _) _ _ ⬝ph _ ⬝hp (ap_compose (class_of _) _ _)⁻¹ᵖ,
apply natural_square2,
rwr [←transport11_con, ap_inv, con.left_inv, ap_inv, con.left_inv] }
end
@[hott] protected def ap_functor_inl {x x' : BL} (p : x = x')
: ap (pushout.functor tl bl tr fh gh) (ap inl p) = ap inl (ap bl p) :=
by induction p; reflexivity
@[hott] protected def ap_functor_inr {x x' : TR} (p : x = x')
: ap (pushout.functor tl bl tr fh gh) (ap inr p) = ap inr (ap tr p) :=
by induction p; reflexivity
variables [ietl : is_equiv tl] [iebl : is_equiv bl] [ietr : is_equiv tr]
include ietl iebl ietr
open equiv is_equiv arrow
@[hott, instance] protected def is_equiv_functor
: is_equiv (pushout.functor tl bl tr fh gh) :=
sorry
end
/- version giving the equivalence -/
section
variables {TL : Type _} {BL : Type _} {TR : Type _} {f : TL → BL} {g : TL → TR}
{TL' : Type _} {BL' : Type _} {TR' : Type _} {f' : TL' → BL'} {g' : TL' → TR'}
(tl : TL ≃ TL') (bl : BL ≃ BL') (tr : TR ≃ TR')
(fh : bl ∘ f ~ f' ∘ tl) (gh : tr ∘ g ~ g' ∘ tl)
include fh gh
@[hott] protected def equiv : pushout f g ≃ pushout f' g' :=
equiv.mk (pushout.functor tl bl tr fh gh) (by apply_instance)
end
@[hott, instance] def pointed_pushout {TL BL TR : Type _} [HTL : pointed TL]
[HBL : pointed BL] [HTR : pointed TR] (f : TL → BL) (g : TL → TR) : pointed (pushout f g) :=
pointed.mk (inl (point _))
end pushout open pushout
@[hott] def ppushout {TL BL TR : Type*} (f : TL →* BL) (g : TL →* TR) : Type* :=
pointed.mk' (pushout f g)
namespace pushout
section
parameters {TL : Type*} {BL : Type*} {TR : Type*} (f : TL →* BL) (g : TL →* TR)
parameters {f g}
@[hott] def pinl : BL →* ppushout f g :=
pmap.mk inl idp
@[hott] def pinr : TR →* ppushout f g :=
pmap.mk inr ((ap inr (respect_pt g))⁻¹ ⬝ (glue _)⁻¹ ⬝ (ap inl (respect_pt f)))
@[hott] def pglue (x : TL) : pinl (f x) = pinr (g x) := -- TODO do we need this?
glue _
end
section
variables {TL : Type*} {BL : Type*} {TR : Type*} (f : TL →* BL) (g : TL →* TR)
@[hott] protected def psymm : ppushout f g ≃* ppushout g f :=
begin
fapply pequiv_of_equiv,
{ apply pushout.symm },
{ exact ap inr (respect_pt f)⁻¹ ⬝ (glue _)⁻¹ ⬝ ap inl (respect_pt g) }
end
end
end pushout
end hott |
628eadcf4a953ad4a4af04f07665c0f6941bed8d | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/gcd_monoid/integrally_closed.lean | ac3990150f937489a40932a646ae4e4f075f18c4 | [
"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 | 1,806 | lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import algebra.gcd_monoid.basic
import ring_theory.integrally_closed
import ring_theory.polynomial.eisenstein.basic
/-!
# GCD domains are integrally closed
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
open_locale big_operators polynomial
variables {R A : Type*} [comm_ring R] [is_domain R] [gcd_monoid R] [comm_ring A] [algebra R A]
lemma is_localization.surj_of_gcd_domain (M : submonoid R) [is_localization M A] (z : A) :
∃ a b : R, is_unit (gcd a b) ∧ z * algebra_map R A b = algebra_map R A a :=
begin
obtain ⟨x, ⟨y, hy⟩, rfl⟩ := is_localization.mk'_surjective M z,
obtain ⟨x', y', hx', hy', hu⟩ := extract_gcd x y,
use [x', y', hu],
rw [mul_comm, is_localization.mul_mk'_eq_mk'_of_mul],
convert is_localization.mk'_mul_cancel_left _ _ using 2,
{ rw [subtype.coe_mk, hy', ← mul_comm y', mul_assoc], conv_lhs { rw hx' } },
{ apply_instance },
end
@[priority 100]
instance gcd_monoid.to_is_integrally_closed : is_integrally_closed R :=
⟨λ X ⟨p, hp₁, hp₂⟩, begin
obtain ⟨x, y, hg, he⟩ := is_localization.surj_of_gcd_domain (non_zero_divisors R) X,
have := polynomial.dvd_pow_nat_degree_of_eval₂_eq_zero
(is_fraction_ring.injective R $ fraction_ring R) hp₁ y x _ hp₂ (by rw [mul_comm, he]),
have : is_unit y,
{ rw [is_unit_iff_dvd_one, ← one_pow],
exact (dvd_gcd this $ dvd_refl y).trans (gcd_pow_left_dvd_pow_gcd.trans $
pow_dvd_pow_of_dvd (is_unit_iff_dvd_one.1 hg) _) },
use x * (this.unit⁻¹ : _),
erw [map_mul, ← units.coe_map_inv, eq_comm, units.eq_mul_inv_iff_mul_eq],
exact he,
end⟩
|
5ae4208ad518b96b2b918eb1690c900358e91a1b | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/topology/uniform_space/compare_reals.lean | ded30248ad255aefe35fdad659ae984dd6a28fe9 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 4,655 | lean | /-
Copyright (c) 2019 Patrick MAssot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import topology.uniform_space.absolute_value
import topology.instances.real
import topology.instances.rat
import topology.uniform_space.completion
/-!
# Comparison of Cauchy reals and Bourbaki reals
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In `data.real.basic` real numbers are defined using the so called Cauchy construction (although
it is due to Georg Cantor). More precisely, this construction applies to commutative rings equipped
with an absolute value with values in a linear ordered field.
On the other hand, in the `uniform_space` folder, we construct completions of general uniform
spaces, which allows to construct the Bourbaki real numbers. In this file we build uniformly
continuous bijections from Cauchy reals to Bourbaki reals and back. This is a cross sanity check of
both constructions. Of course those two constructions are variations on the completion idea, simply
with different level of generality. Comparing with Dedekind cuts or quasi-morphisms would be of a
completely different nature.
Note that `metric_space/cau_seq_filter` also relates the notions of Cauchy sequences in metric
spaces and Cauchy filters in general uniform spaces, and `metric_space/completion` makes sure
the completion (as a uniform space) of a metric space is a metric space.
Historical note: mathlib used to define real numbers in an intermediate way, using completion
of uniform spaces but extending multiplication in an ad-hoc way.
TODO:
* Upgrade this isomorphism to a topological ring isomorphism.
* Do the same comparison for p-adic numbers
## Implementation notes
The heavy work is done in `topology/uniform_space/abstract_completion` which provides an abstract
caracterization of completions of uniform spaces, and isomorphisms between them. The only work left
here is to prove the uniform space structure coming from the absolute value on ℚ (with values in ℚ,
not referring to ℝ) coincides with the one coming from the metric space structure (which of course
does use ℝ).
## References
* [N. Bourbaki, *Topologie générale*][bourbaki1966]
## Tags
real numbers, completion, uniform spaces
-/
open set function filter cau_seq uniform_space
/-- The metric space uniform structure on ℚ (which presupposes the existence
of real numbers) agrees with the one coming directly from (abs : ℚ → ℚ). -/
lemma rat.uniform_space_eq :
(absolute_value.abs : absolute_value ℚ ℚ).uniform_space = pseudo_metric_space.to_uniform_space :=
begin
ext s,
rw [(absolute_value.has_basis_uniformity _).mem_iff, metric.uniformity_basis_dist_rat.mem_iff],
simp only [rat.dist_eq, absolute_value.abs_apply, ← rat.cast_sub, ← rat.cast_abs, rat.cast_lt,
abs_sub_comm]
end
/-- Cauchy reals packaged as a completion of ℚ using the absolute value route. -/
def rational_cau_seq_pkg : @abstract_completion ℚ $ (@absolute_value.abs ℚ _).uniform_space :=
{ space := ℝ,
coe := (coe : ℚ → ℝ),
uniform_struct := by apply_instance,
complete := by apply_instance,
separation := by apply_instance,
uniform_inducing := by { rw rat.uniform_space_eq,
exact rat.uniform_embedding_coe_real.to_uniform_inducing },
dense := rat.dense_embedding_coe_real.dense }
namespace compare_reals
/-- Type wrapper around ℚ to make sure the absolute value uniform space instance is picked up
instead of the metric space one. We proved in rat.uniform_space_eq that they are equal,
but they are not definitionaly equal, so it would confuse the type class system (and probably
also human readers). -/
@[derive comm_ring, derive inhabited] def Q := ℚ
instance : uniform_space Q := (@absolute_value.abs ℚ _).uniform_space
/-- Real numbers constructed as in Bourbaki. -/
@[derive inhabited]
def Bourbakiℝ : Type := completion Q
instance bourbaki.uniform_space: uniform_space Bourbakiℝ := completion.uniform_space Q
/-- Bourbaki reals packaged as a completion of Q using the general theory. -/
def Bourbaki_pkg : abstract_completion Q := completion.cpkg
/-- The uniform bijection between Bourbaki and Cauchy reals. -/
noncomputable def compare_equiv : Bourbakiℝ ≃ᵤ ℝ :=
Bourbaki_pkg.compare_equiv rational_cau_seq_pkg
lemma compare_uc : uniform_continuous (compare_equiv) :=
Bourbaki_pkg.uniform_continuous_compare_equiv _
lemma compare_uc_symm : uniform_continuous (compare_equiv).symm :=
Bourbaki_pkg.uniform_continuous_compare_equiv_symm _
end compare_reals
|
1883c2e0f9bfbb6548233803b9d4618af7a02177 | 037dba89703a79cd4a4aec5e959818147f97635d | /src/2021/functions/sheet1.lean | d3c9aa9dec6ef6c3a61a3897fa3ba99f9e9471bd | [] | no_license | ImperialCollegeLondon/M40001_lean | 3a6a09298da395ab51bc220a535035d45bbe919b | 62a76fa92654c855af2b2fc2bef8e60acd16ccec | refs/heads/master | 1,666,750,403,259 | 1,665,771,117,000 | 1,665,771,117,000 | 209,141,835 | 115 | 12 | null | 1,640,270,596,000 | 1,568,749,174,000 | Lean | UTF-8 | Lean | false | false | 5,833 | lean | /-
Copyright (c) 2021 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author : Kevin Buzzard
-/
import tactic -- imports all the Lean tactics
/-!
# Functions in Lean, example sheet 1 : injectivity and surjectivity
In this sheet we'll learn how to manipulate the concepts of
injectivity and surjectivity in Lean.
The notation for functions is the usual one in matheamtics:
if `X` and `Y` are types, then `f : X → Y` denotes a function
from `X` to `Y`. In fact what is going on here is that `X → Y`
denotes the type of all functions from `X` to `Y`, and `f : X → Y`
means that `f` is a term of type `X → Y`, i.e., a function
from `X` to `Y`.
One thing worth mentioning is that the simplest kind of function
evaluation, where you have `x : X` and `f : X → Y`, doesn't need
brackets: you can just write `f x` instead of `f(x)`. You only
need it when evaluating a function at a more complex object;
for example if we also had `g : Y → Z` then we can't write
`g f x` for `g(f(x))`, we have to write `g(f x)` otherwise
`g` would eat `f` and get confused. Without brackets,
a function just eats the next term greedily.
## Tactics
### More on `rcases` and `rintro` -- the `rfl` hack.
You don't need to know the below trick but it can make your
proofs shorter.
There is a clever hack in Lean which sometimes enables you to
do `cases` and `rw` all in one go. It works like this. Say
your tactic state is
```
h1 : ∃ a, b = f a
h2 : g b = d
⊢ b = c
```
If you do `cases h1 with a ha` or `rcases h1 with ⟨a, ha⟩` (the same thing)
then you'll end up with
```
a : X
ha : b = f a
h2 : g b = d
⊢ b = c
```
Now `ha`, our new hypothesis, is a "formula for b" and probably what you're
going to want to do next is "substitute in for b", i.e. `rw ha,`
or maybe even `rw ha at h2 ⊢,`or `rw ha at *` to replace `b` by `f a`
everywhere. Then there are no `b`s left other than in `ha` itself and
`ha` is now basically redundant.
Instead of the rewrites, you can use the `subst` tactic to do them for you;
`subst ha,` will remove `b` completely, replacing it with `f a` everywhere
and will then delete `ha` for you.
But even better, there is an approach where `ha` is never even created.
The tactic `rcases h1 with ⟨a, rfl⟩`, means "let `b` be `f a` by definition",
i.e. "replace all `b`s with `f a` and delete `b`". It is a bit of a hack
(because it means you can't have a variable called `rfl`) but it's very
convenient for making proofs shorter.
### More on `rw` -- syntactic equality.
The definition of `function.comp`, known to mathematicians via its `∘`
notation, is that `(f ∘ g) x = f (g x)` by definition. So if your
goal mentions `(f ∘ g) x` and you want it to mention `f (g x)` instead,
you can either use the `change` tactic, or you can define `comp_eval`
as I do below, and then `rw comp_eval f g x,`. Or you can just do nothing,
confident in the fact that because `(f ∘ g) x` and `f (g x)` are equal
by definition, we don't have to worry.
Except here's a case where you have to do something. Say your
tactic state looks like this:
```
h : g x = 37
⊢ (f ∘ g) x = b
```
Then, because `(f ∘ g) x` and `f (g x)` are equal *by definition*,
`rw h,` should work and change the goal to `f 37 = b`, right? Wrong :-(
The `rw` tactic works up to *syntactic equality*. Syntactic equality
is the strongest version of equality -- two terms are syntactically equal
if they are literally the same string of characters. In particular,
`(f ∘ g) x` and `f (g x)` are definitionally equal, but not syntactically
equal, so `rw h,` will fail.
This is why we define `comp_eval` below. It is a proof of `(f ∘ g) x = f (g x)`.
The proof is `refl`, because `refl` works up to definitional equality.
But because we have given the proof a name, you can `rw comp_eval,`
to change `(f ∘ g) x` to `f (g x)`. This means that with the tactic
state above, you can make progress with `rw [comp_eval, h],`.
-/
open function
-- Our functions will go between these sets, or Types as Lean calls them
variables (X Y Z : Type)
-- Let's prove some theorems, each of which are true by definition.
theorem injective_def (f : X → Y) :
injective f ↔ ∀ (a b : X), f a = f b → a = b :=
begin
refl -- this proof works, because `injective f`
-- means ∀ a b, f a = f b → a = b *by definition*
-- so the proof is "it's reflexivity of `↔`"
end
-- similarly this is the *definition* of `surjective f`
theorem surjective_def (f : X → Y) :
surjective f ↔ ∀ y : Y, ∃ x : X, f x = y :=
begin
refl
end
-- similarly the *definition* of `id x` is `x`
theorem id_eval (x : X) :
id x = x :=
begin
refl
end
-- the *definition* of (g ∘ f) (x) is g(f(x)).
theorem comp_eval (f : X → Y) (g : Y → Z) (x : X) :
(g ∘ f) x = g (f x) :=
begin
refl
end
-- Why did we just prove all those theorems with a proof
-- saying "it's true by definition"? Because now, if we want,
-- we can `rw` the theorems to replace things by their definitions.
example : injective (id : X → X) :=
begin
-- you can start with `rw injective_def` if you like
-- but because `injective_def` is true by definition
-- you can delete it later :-)
sorry
end
example : surjective (id : X → X) :=
begin
sorry
end
example (f : X → Y) (g : Y → Z) (hf : injective f) (hg : injective g) :
injective (g ∘ f) :=
begin
sorry
end
example (f : X → Y) (g : Y → Z) (hf : surjective f) (hg : surjective g) :
surjective (g ∘ f) :=
begin
sorry
end
-- This is a question on the IUM function problem sheet
example (f : X → Y) (g : Y → Z) :
injective (g ∘ f) → injective f :=
begin
sorry
end
-- This is another one
example (f : X → Y) (g : Y → Z) :
surjective (g ∘ f) → surjective g :=
begin
sorry
end
|
463df830f74cd23fd2f72d5e4b63eecd9c9d352e | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/monoidal/free/coherence.lean | 2d28aae09bc78bcb084c2b5d4581a05f2c67a301 | [
"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 | 12,094 | lean | /-
Copyright (c) 2021 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.monoidal.free.basic
import category_theory.groupoid
import category_theory.discrete_category
/-!
# The monoidal coherence theorem
In this file, we prove the monoidal coherence theorem, stated in the following form: the free
monoidal category over any type `C` is thin.
We follow a proof described by Ilya Beylin and Peter Dybjer, which has been previously formalized
in the proof assistant ALF. The idea is to declare a normal form (with regard to association and
adding units) on objects of the free monoidal category and consider the discrete subcategory of
objects that are in normal form. A normalization procedure is then just a functor
`full_normalize : free_monoidal_category C ⥤ discrete (normal_monoidal_object C)`, where
functoriality says that two objects which are related by associators and unitors have the
same normal form. Another desirable property of a normalization procedure is that an object is
isomorphic (i.e., related via associators and unitors) to its normal form. In the case of the
specific normalization procedure we use we not only get these isomorphismns, but also that they
assemble into a natural isomorphism `𝟭 (free_monoidal_category C) ≅ full_normalize ⋙ inclusion`.
But this means that any two parallel morphisms in the free monoidal category factor through a
discrete category in the same way, so they must be equal, and hence the free monoidal category
is thin.
## References
* [Ilya Beylin and Peter Dybjer, Extracting a proof of coherence for monoidal categories from a
proof of normalization for monoids][beylin1996]
-/
universe u
namespace category_theory
open monoidal_category
namespace free_monoidal_category
variables {C : Type u}
section
variables (C)
/-- We say an object in the free monoidal category is in normal form if it is of the form
`(((𝟙_ C) ⊗ X₁) ⊗ X₂) ⊗ ⋯`. -/
@[nolint has_inhabited_instance]
inductive normal_monoidal_object : Type u
| unit : normal_monoidal_object
| tensor : normal_monoidal_object → C → normal_monoidal_object
end
local notation `F` := free_monoidal_category
local notation `N` := discrete ∘ normal_monoidal_object
local infixr ` ⟶ᵐ `:10 := hom
/-- Auxiliary definition for `inclusion`. -/
@[simp] def inclusion_obj : normal_monoidal_object C → F C
| normal_monoidal_object.unit := unit
| (normal_monoidal_object.tensor n a) := tensor (inclusion_obj n) (of a)
/-- The discrete subcategory of objects in normal form includes into the free monoidal category. -/
@[simp] def inclusion : N C ⥤ F C :=
discrete.functor inclusion_obj
/-- Auxiliary definition for `normalize`. -/
@[simp] def normalize_obj : F C → normal_monoidal_object C → N C
| unit n := ⟨n⟩
| (of X) n := ⟨normal_monoidal_object.tensor n X⟩
| (tensor X Y) n := normalize_obj Y (normalize_obj X n).as
@[simp] lemma normalize_obj_unitor (n : normal_monoidal_object C) :
normalize_obj (𝟙_ (F C)) n = ⟨n⟩ :=
rfl
@[simp] lemma normalize_obj_tensor (X Y : F C) (n : normal_monoidal_object C) :
normalize_obj (X ⊗ Y) n = normalize_obj Y (normalize_obj X n).as :=
rfl
section
open hom
local attribute [tidy] tactic.discrete_cases
/-- Auxiliary definition for `normalize`. Here we prove that objects that are related by
associators and unitors map to the same normal form. -/
@[simp] def normalize_map_aux : Π {X Y : F C},
(X ⟶ᵐ Y) →
((discrete.functor (normalize_obj X) : _ ⥤ N C) ⟶ discrete.functor (normalize_obj Y))
| _ _ (id _) := 𝟙 _
| _ _ (α_hom _ _ _) := ⟨λ X, 𝟙 _, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| _ _ (α_inv _ _ _) := ⟨λ X, 𝟙 _, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| _ _ (l_hom _) := ⟨λ X, 𝟙 _, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| _ _ (l_inv _) := ⟨λ X, 𝟙 _, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| _ _ (ρ_hom _) := ⟨λ ⟨X⟩, ⟨⟨by simp⟩⟩, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| _ _ (ρ_inv _) := ⟨λ ⟨X⟩, ⟨⟨by simp⟩⟩, by { rintros ⟨X⟩ ⟨Y⟩ f, simp }⟩
| X Y (@comp _ U V W f g) := normalize_map_aux f ≫ normalize_map_aux g
| X Y (@hom.tensor _ T U V W f g) :=
⟨λ X, (normalize_map_aux g).app (normalize_obj T X.as) ≫
(discrete.functor (normalize_obj W) : _ ⥤ N C).map ((normalize_map_aux f).app X), by tidy⟩
end
section
variables (C)
/-- Our normalization procedure works by first defining a functor `F C ⥤ (N C ⥤ N C)` (which turns
out to be very easy), and then obtain a functor `F C ⥤ N C` by plugging in the normal object
`𝟙_ C`. -/
@[simp] def normalize : F C ⥤ N C ⥤ N C :=
{ obj := λ X, discrete.functor (normalize_obj X),
map := λ X Y, quotient.lift normalize_map_aux (by tidy) }
/-- A variant of the normalization functor where we consider the result as an object in the free
monoidal category (rather than an object of the discrete subcategory of objects in normal
form). -/
@[simp] def normalize' : F C ⥤ N C ⥤ F C :=
normalize C ⋙ (whiskering_right _ _ _).obj inclusion
/-- The normalization functor for the free monoidal category over `C`. -/
def full_normalize : F C ⥤ N C :=
{ obj := λ X, ((normalize C).obj X).obj ⟨normal_monoidal_object.unit⟩,
map := λ X Y f, ((normalize C).map f).app ⟨normal_monoidal_object.unit⟩ }
/-- Given an object `X` of the free monoidal category and an object `n` in normal form, taking
the tensor product `n ⊗ X` in the free monoidal category is functorial in both `X` and `n`. -/
@[simp] def tensor_func : F C ⥤ N C ⥤ F C :=
{ obj := λ X, discrete.functor (λ n, (inclusion.obj ⟨n⟩) ⊗ X),
map := λ X Y f, ⟨λ n, 𝟙 _ ⊗ f, by { rintro ⟨X⟩ ⟨Y⟩, tidy }⟩ }
lemma tensor_func_map_app {X Y : F C} (f : X ⟶ Y) (n) : ((tensor_func C).map f).app n =
𝟙 _ ⊗ f :=
rfl
lemma tensor_func_obj_map (Z : F C) {n n' : N C} (f : n ⟶ n') :
((tensor_func C).obj Z).map f = inclusion.map f ⊗ 𝟙 Z :=
by { cases n, cases n', tidy }
/-- Auxiliary definition for `normalize_iso`. Here we construct the isomorphism between
`n ⊗ X` and `normalize X n`. -/
@[simp] def normalize_iso_app :
Π (X : F C) (n : N C), ((tensor_func C).obj X).obj n ≅ ((normalize' C).obj X).obj n
| (of X) n := iso.refl _
| unit n := ρ_ _
| (tensor X Y) n :=
(α_ _ _ _).symm ≪≫ tensor_iso (normalize_iso_app X n) (iso.refl _) ≪≫ normalize_iso_app _ _
@[simp] lemma normalize_iso_app_tensor (X Y : F C) (n : N C) :
normalize_iso_app C (X ⊗ Y) n =
(α_ _ _ _).symm ≪≫ tensor_iso (normalize_iso_app C X n) (iso.refl _) ≪≫
normalize_iso_app _ _ _ :=
rfl
@[simp] lemma normalize_iso_app_unitor (n : N C) : normalize_iso_app C (𝟙_ (F C)) n = ρ_ _ :=
rfl
/-- Auxiliary definition for `normalize_iso`. -/
@[simp] def normalize_iso_aux (X : F C) : (tensor_func C).obj X ≅ (normalize' C).obj X :=
nat_iso.of_components (normalize_iso_app C X) (by { rintros ⟨X⟩ ⟨Y⟩, tidy })
section
variables {D : Type u} [category.{u} D] {I : Type u} (f : I → D) (X : discrete I)
-- TODO: move to discrete_category.lean, decide whether this should be a global simp lemma
@[simp] lemma discrete_functor_obj_eq_as : (discrete.functor f).obj X = f X.as :=
rfl
-- TODO: move to discrete_category.lean, decide whether this should be a global simp lemma
@[simp] lemma discrete_functor_map_eq_id (g : X ⟶ X) : (discrete.functor f).map g = 𝟙 _ :=
by tidy
end
/-- The isomorphism between `n ⊗ X` and `normalize X n` is natural (in both `X` and `n`, but
naturality in `n` is trivial and was "proved" in `normalize_iso_aux`). This is the real heart
of our proof of the coherence theorem. -/
def normalize_iso : tensor_func C ≅ normalize' C :=
nat_iso.of_components (normalize_iso_aux C)
begin
rintros X Y f,
apply quotient.induction_on f,
intro f,
ext n,
induction f generalizing n,
{ simp only [mk_id, functor.map_id, category.id_comp, category.comp_id] },
{ dsimp,
simp only [id_tensor_associator_inv_naturality_assoc, ←pentagon_inv_assoc,
tensor_hom_inv_id_assoc, tensor_id, category.id_comp, discrete.functor_map_id, comp_tensor_id,
iso.cancel_iso_inv_left, category.assoc],
dsimp, simp only [category.comp_id], },
{ dsimp,
simp only [discrete.functor_map_id, comp_tensor_id, category.assoc, pentagon_inv_assoc,
←associator_inv_naturality_assoc, tensor_id, iso.cancel_iso_inv_left],
dsimp, simp only [category.comp_id],},
{ dsimp,
rw triangle_assoc_comp_right_assoc,
simp only [discrete.functor_map_id, category.assoc],
cases n,
dsimp, simp only [category.comp_id] },
{ dsimp,
simp only [triangle_assoc_comp_left_inv_assoc, inv_hom_id_tensor_assoc, tensor_id,
category.id_comp, discrete.functor_map_id],
dsimp, simp only [category.comp_id],
cases n, simp },
{ dsimp,
rw [←(iso.inv_comp_eq _).2 (right_unitor_tensor _ _), category.assoc, ←right_unitor_naturality],
simp only [iso.cancel_iso_inv_left, category.assoc],
congr' 1,
convert (category.comp_id _).symm,
convert discrete_functor_map_eq_id inclusion_obj _ _,
ext,
refl },
{ dsimp,
simp only [←(iso.eq_comp_inv _).1 (right_unitor_tensor_inv _ _), right_unitor_conjugation,
category.assoc, iso.hom_inv_id, iso.hom_inv_id_assoc, iso.inv_hom_id, iso.inv_hom_id_assoc],
congr,
convert (discrete_functor_map_eq_id inclusion_obj _ _).symm,
ext, refl, },
{ dsimp at *,
rw [id_tensor_comp, category.assoc, f_ih_g ⟦f_g⟧, ←category.assoc, f_ih_f ⟦f_f⟧, category.assoc,
←functor.map_comp],
congr' 2 },
{ dsimp at *,
rw associator_inv_naturality_assoc,
slice_lhs 2 3 { rw [←tensor_comp, f_ih_f ⟦f_f⟧] },
conv_lhs { rw [←@category.id_comp (F C) _ _ _ ⟦f_g⟧] },
simp only [category.comp_id, tensor_comp, category.assoc],
congr' 2,
rw [←mk_tensor, quotient.lift_mk],
dsimp,
rw [functor.map_comp, ←category.assoc, ←f_ih_g ⟦f_g⟧, ←@category.comp_id (F C) _ _ _ ⟦f_g⟧,
←category.id_comp ((discrete.functor inclusion_obj).map _), tensor_comp],
dsimp,
simp only [category.assoc, category.comp_id],
congr' 1,
convert (normalize_iso_aux C f_Z).hom.naturality ((normalize_map_aux f_f).app n),
exact (tensor_func_obj_map _ _ _).symm }
end
/-- The isomorphism between an object and its normal form is natural. -/
def full_normalize_iso : 𝟭 (F C) ≅ full_normalize C ⋙ inclusion :=
nat_iso.of_components
(λ X, (λ_ X).symm ≪≫ ((normalize_iso C).app X).app ⟨normal_monoidal_object.unit⟩)
begin
intros X Y f,
dsimp,
rw [left_unitor_inv_naturality_assoc, category.assoc, iso.cancel_iso_inv_left],
exact congr_arg (λ f, nat_trans.app f (discrete.mk normal_monoidal_object.unit))
((normalize_iso.{u} C).hom.naturality f)
end
end
/-- The monoidal coherence theorem. -/
instance subsingleton_hom {X Y : F C} : subsingleton (X ⟶ Y) :=
⟨λ f g, have (full_normalize C).map f = (full_normalize C).map g, from subsingleton.elim _ _,
begin
rw [←functor.id_map f, ←functor.id_map g],
simp [←nat_iso.naturality_2 (full_normalize_iso.{u} C), this]
end⟩
section groupoid
section
open hom
/-- Auxiliary construction for showing that the free monoidal category is a groupoid. Do not use
this, use `is_iso.inv` instead. -/
def inverse_aux : Π {X Y : F C}, (X ⟶ᵐ Y) → (Y ⟶ᵐ X)
| _ _ (id X) := id X
| _ _ (α_hom _ _ _) := α_inv _ _ _
| _ _ (α_inv _ _ _) := α_hom _ _ _
| _ _ (ρ_hom _) := ρ_inv _
| _ _ (ρ_inv _) := ρ_hom _
| _ _ (l_hom _) := l_inv _
| _ _ (l_inv _) := l_hom _
| _ _ (comp f g) := (inverse_aux g).comp (inverse_aux f)
| _ _ (hom.tensor f g) := (inverse_aux f).tensor (inverse_aux g)
end
instance : groupoid.{u} (F C) :=
{ inv := λ X Y, quotient.lift (λ f, ⟦inverse_aux f⟧) (by tidy),
..(infer_instance : category (F C)) }
end groupoid
end free_monoidal_category
end category_theory
|
0ea52ae8fee03ca51d17fdeb5cb4e5a8f82eb931 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/meta4.lean | ea2eb872b6d45e71a5e602bfd831eb67bde9dbd5 | [
"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,358 | lean | import Lean.Meta
open Lean
open Lean.Meta
def print (msg : MessageData) : MetaM Unit := do
trace[Meta.debug] msg
def checkM (x : MetaM Bool) : MetaM Unit :=
unless (← x) do throwError "check failed"
axiom Ax : forall (α β : Type), α → β → DecidableEq β
set_option trace.Meta.debug true
def tst1 : MetaM Unit := do
let cinfo ← getConstInfo `Ax;
let (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 0);
checkM (pure (!e.hasMVar));
print e;
let (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 1);
checkM (pure e.hasMVar);
checkM (pure e.isForall);
print e;
let (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 5);
checkM (pure e.hasMVar);
checkM (pure e.isForall);
print e;
let (_, _, e) ← forallMetaTelescopeReducing cinfo.type (some 6);
checkM (pure e.hasMVar);
checkM (pure (!e.isForall));
print e;
let (_, _, e') ← forallMetaTelescopeReducing cinfo.type;
print e';
checkM (isDefEq e e');
forallBoundedTelescope cinfo.type (some 0) $ fun xs body => checkM (pure (xs.size == 0));
forallBoundedTelescope cinfo.type (some 1) $ fun xs body => checkM (pure (xs.size == 1));
forallBoundedTelescope cinfo.type (some 6) $ fun xs body => do { print xs; checkM (pure (xs.size == 6)) };
forallBoundedTelescope cinfo.type (some 10) $ fun xs body => do { print xs; checkM (pure (xs.size == 6)) };
pure ()
#eval tst1
|
53d701e302cdad863b61b5e968be10c6d8b6992a | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/algebra/ordered_ring.lean | 9250ab320085c52452de947ecfb5a11c473b91a9 | [
"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 | 51,147 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
-/
import algebra.ordered_group
import algebra.invertible
import data.set.intervals.basic
set_option old_structure_cmd true
universe u
variable {α : Type u}
/-- An `ordered_semiring α` is a semiring `α` with a partial order such that
multiplication with a positive number and addition are monotone. -/
@[protect_proj]
class ordered_semiring (α : Type u) extends semiring α, ordered_cancel_add_comm_monoid α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_lt_mul_of_pos_left : ∀ a b c : α, a < b → 0 < c → c * a < c * b)
(mul_lt_mul_of_pos_right : ∀ a b c : α, a < b → 0 < c → a * c < b * c)
section ordered_semiring
variables [ordered_semiring α] {a b c d : α}
lemma zero_le_one : 0 ≤ (1:α) :=
ordered_semiring.zero_le_one
lemma zero_le_two : 0 ≤ (2:α) :=
add_nonneg zero_le_one zero_le_one
lemma one_le_two : 1 ≤ (2:α) :=
calc (1:α) = 0 + 1 : (zero_add _).symm
... ≤ 1 + 1 : add_le_add_right zero_le_one _
section nontrivial
variables [nontrivial α]
lemma zero_lt_one : 0 < (1 : α) :=
lt_of_le_of_ne zero_le_one zero_ne_one
lemma zero_lt_two : 0 < (2:α) := add_pos zero_lt_one zero_lt_one
@[field_simps] lemma two_ne_zero : (2:α) ≠ 0 :=
ne.symm (ne_of_lt zero_lt_two)
lemma one_lt_two : 1 < (2:α) :=
calc (2:α) = 1+1 : one_add_one_eq_two
... > 1+0 : add_lt_add_left zero_lt_one _
... = 1 : add_zero 1
lemma zero_lt_three : 0 < (3:α) := add_pos zero_lt_two zero_lt_one
lemma zero_lt_four : 0 < (4:α) := add_pos zero_lt_two zero_lt_two
end nontrivial
lemma mul_lt_mul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b :=
ordered_semiring.mul_lt_mul_of_pos_left a b c h₁ h₂
lemma mul_lt_mul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c :=
ordered_semiring.mul_lt_mul_of_pos_right a b c h₁ h₂
lemma mul_le_mul_of_nonneg_left (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
cases classical.em (b ≤ a), { simp [h.antisymm h₁] },
cases classical.em (c ≤ 0), { simp [h_1.antisymm h₂] },
exact (mul_lt_mul_of_pos_left (h₁.lt_of_not_le h) (h₂.lt_of_not_le h_1)).le,
end
lemma mul_le_mul_of_nonneg_right (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c :=
begin
cases classical.em (b ≤ a), { simp [h.antisymm h₁] },
cases classical.em (c ≤ 0), { simp [h_1.antisymm h₂] },
exact (mul_lt_mul_of_pos_right (h₁.lt_of_not_le h) (h₂.lt_of_not_le h_1)).le,
end
-- TODO: there are four variations, depending on which variables we assume to be nonneg
lemma mul_le_mul (hac : a ≤ c) (hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) : a * b ≤ c * d :=
calc
a * b ≤ c * b : mul_le_mul_of_nonneg_right hac nn_b
... ≤ c * d : mul_le_mul_of_nonneg_left hbd nn_c
lemma mul_nonneg (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
have h : 0 * b ≤ a * b, from mul_le_mul_of_nonneg_right ha hb,
by rwa [zero_mul] at h
lemma mul_nonpos_of_nonneg_of_nonpos (ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 :=
have h : a * b ≤ a * 0, from mul_le_mul_of_nonneg_left hb ha,
by rwa mul_zero at h
lemma mul_nonpos_of_nonpos_of_nonneg (ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 :=
have h : a * b ≤ 0 * b, from mul_le_mul_of_nonneg_right ha hb,
by rwa zero_mul at h
lemma mul_lt_mul (hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d :=
calc
a * b < c * b : mul_lt_mul_of_pos_right hac pos_b
... ≤ c * d : mul_le_mul_of_nonneg_left hbd nn_c
lemma mul_lt_mul' (h1 : a ≤ c) (h2 : b < d) (h3 : 0 ≤ b) (h4 : 0 < c) : a * b < c * d :=
calc
a * b ≤ c * b : mul_le_mul_of_nonneg_right h1 h3
... < c * d : mul_lt_mul_of_pos_left h2 h4
lemma mul_pos (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
have h : 0 * b < a * b, from mul_lt_mul_of_pos_right ha hb,
by rwa zero_mul at h
lemma mul_neg_of_pos_of_neg (ha : 0 < a) (hb : b < 0) : a * b < 0 :=
have h : a * b < a * 0, from mul_lt_mul_of_pos_left hb ha,
by rwa mul_zero at h
lemma mul_neg_of_neg_of_pos (ha : a < 0) (hb : 0 < b) : a * b < 0 :=
have h : a * b < 0 * b, from mul_lt_mul_of_pos_right ha hb,
by rwa zero_mul at h
lemma mul_self_lt_mul_self (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
mul_lt_mul' h2.le h2 h1 $ h1.trans_lt h2
lemma strict_mono_incr_on_mul_self : strict_mono_incr_on (λ x : α, x * x) (set.Ici 0) :=
λ x hx y hy hxy, mul_self_lt_mul_self hx hxy
lemma mul_self_le_mul_self (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b :=
mul_le_mul h2 h2 h1 $ h1.trans h2
lemma mul_lt_mul'' (h1 : a < c) (h2 : b < d) (h3 : 0 ≤ a) (h4 : 0 ≤ b) : a * b < c * d :=
(lt_or_eq_of_le h4).elim
(λ b0, mul_lt_mul h1 h2.le b0 $ h3.trans h1.le)
(λ b0, by rw [← b0, mul_zero]; exact
mul_pos (h3.trans_lt h1) (h4.trans_lt h2))
lemma le_mul_of_one_le_right (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ b * a :=
suffices b * 1 ≤ b * a, by rwa mul_one at this,
mul_le_mul_of_nonneg_left h hb
lemma le_mul_of_one_le_left (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a * b :=
suffices 1 * b ≤ a * b, by rwa one_mul at this,
mul_le_mul_of_nonneg_right h hb
lemma add_le_mul_two_add {a b : α}
(a2 : 2 ≤ a) (b0 : 0 ≤ b) : a + (2 + b) ≤ a * (2 + b) :=
calc a + (2 + b) ≤ a + (a + a * b) :
add_le_add_left (add_le_add a2 (le_mul_of_one_le_left b0 (one_le_two.trans a2))) a
... ≤ a * (2 + b) : by rw [mul_add, mul_two, add_assoc]
lemma one_le_mul_of_one_le_of_one_le {a b : α} (a1 : 1 ≤ a) (b1 : 1 ≤ b) :
(1 : α) ≤ a * b :=
(mul_one (1 : α)).symm.le.trans (mul_le_mul a1 b1 zero_le_one (zero_le_one.trans a1))
/-- Pullback an `ordered_semiring` under an injective map. -/
def function.injective.ordered_semiring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
ordered_semiring β :=
{ zero_le_one := show f 0 ≤ f 1, by simp only [zero, one, zero_le_one],
mul_lt_mul_of_pos_left := λ a b c ab c0, show f (c * a) < f (c * b),
begin
rw [mul, mul],
refine mul_lt_mul_of_pos_left ab _,
rwa ← zero,
end,
mul_lt_mul_of_pos_right := λ a b c ab c0, show f (a * c) < f (b * c),
begin
rw [mul, mul],
refine mul_lt_mul_of_pos_right ab _,
rwa ← zero,
end,
..hf.ordered_cancel_add_comm_monoid f zero add,
..hf.semiring f zero one add mul }
section
variable [nontrivial α]
lemma bit1_pos (h : 0 ≤ a) : 0 < bit1 a :=
lt_add_of_le_of_pos (add_nonneg h h) zero_lt_one
lemma lt_add_one (a : α) : a < a + 1 :=
lt_add_of_le_of_pos le_rfl zero_lt_one
lemma lt_one_add (a : α) : a < 1 + a :=
by { rw [add_comm], apply lt_add_one }
end
lemma bit1_pos' (h : 0 < a) : 0 < bit1 a :=
begin
nontriviality,
exact bit1_pos h.le,
end
lemma one_lt_mul (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b :=
begin
nontriviality,
exact (one_mul (1 : α)) ▸ mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)
end
lemma mul_le_one (ha : a ≤ 1) (hb' : 0 ≤ b) (hb : b ≤ 1) : a * b ≤ 1 :=
begin rw ← one_mul (1 : α), apply mul_le_mul; {assumption <|> apply zero_le_one} end
lemma one_lt_mul_of_le_of_lt (ha : 1 ≤ a) (hb : 1 < b) : 1 < a * b :=
begin
nontriviality,
calc 1 = 1 * 1 : by rw one_mul
... < a * b : mul_lt_mul' ha hb zero_le_one (zero_lt_one.trans_le ha)
end
lemma one_lt_mul_of_lt_of_le (ha : 1 < a) (hb : 1 ≤ b) : 1 < a * b :=
begin
nontriviality,
calc 1 = 1 * 1 : by rw one_mul
... < a * b : mul_lt_mul ha hb zero_lt_one $ zero_le_one.trans ha.le
end
lemma mul_le_of_le_one_right (ha : 0 ≤ a) (hb1 : b ≤ 1) : a * b ≤ a :=
calc a * b ≤ a * 1 : mul_le_mul_of_nonneg_left hb1 ha
... = a : mul_one a
lemma mul_le_of_le_one_left (hb : 0 ≤ b) (ha1 : a ≤ 1) : a * b ≤ b :=
calc a * b ≤ 1 * b : mul_le_mul ha1 le_rfl hb zero_le_one
... = b : one_mul b
lemma mul_lt_one_of_nonneg_of_lt_one_left (ha0 : 0 ≤ a) (ha : a < 1) (hb : b ≤ 1) : a * b < 1 :=
calc a * b ≤ a : mul_le_of_le_one_right ha0 hb
... < 1 : ha
lemma mul_lt_one_of_nonneg_of_lt_one_right (ha : a ≤ 1) (hb0 : 0 ≤ b) (hb : b < 1) : a * b < 1 :=
calc a * b ≤ b : mul_le_of_le_one_left hb0 ha
... < 1 : hb
end ordered_semiring
section ordered_comm_semiring
/-- An `ordered_comm_semiring α` is a commutative semiring `α` with a partial order such that
multiplication with a positive number and addition are monotone. -/
@[protect_proj]
class ordered_comm_semiring (α : Type u) extends ordered_semiring α, comm_semiring α
/-- Pullback an `ordered_comm_semiring` under an injective map. -/
def function.injective.ordered_comm_semiring [ordered_comm_semiring α] {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
ordered_comm_semiring β :=
{ ..hf.comm_semiring f zero one add mul,
..hf.ordered_semiring f zero one add mul }
end ordered_comm_semiring
/--
A `linear_ordered_semiring α` is a nontrivial semiring `α` with a linear order
such that multiplication with a positive number and addition are monotone.
-/
-- It's not entirely clear we should assume `nontrivial` at this point;
-- it would be reasonable to explore changing this,
-- but be warned that the instances involving `domain` may cause
-- typeclass search loops.
@[protect_proj]
class linear_ordered_semiring (α : Type u) extends ordered_semiring α, linear_order α, nontrivial α
section linear_ordered_semiring
variables [linear_ordered_semiring α] {a b c d : α}
-- `norm_num` expects the lemma stating `0 < 1` to have a single typeclass argument
-- (see `norm_num.prove_pos_nat`).
-- Rather than working out how to relax that assumption,
-- we provide a synonym for `zero_lt_one` (which needs both `ordered_semiring α` and `nontrivial α`)
-- with only a `linear_ordered_semiring` typeclass argument.
lemma zero_lt_one' : 0 < (1 : α) := zero_lt_one
lemma lt_of_mul_lt_mul_left (h : c * a < c * b) (hc : 0 ≤ c) : a < b :=
lt_of_not_ge
(assume h1 : b ≤ a,
have h2 : c * b ≤ c * a, from mul_le_mul_of_nonneg_left h1 hc,
h2.not_lt h)
lemma lt_of_mul_lt_mul_right (h : a * c < b * c) (hc : 0 ≤ c) : a < b :=
lt_of_not_ge
(assume h1 : b ≤ a,
have h2 : b * c ≤ a * c, from mul_le_mul_of_nonneg_right h1 hc,
h2.not_lt h)
lemma le_of_mul_le_mul_left (h : c * a ≤ c * b) (hc : 0 < c) : a ≤ b :=
le_of_not_gt
(assume h1 : b < a,
have h2 : c * b < c * a, from mul_lt_mul_of_pos_left h1 hc,
h2.not_le h)
lemma le_of_mul_le_mul_right (h : a * c ≤ b * c) (hc : 0 < c) : a ≤ b :=
le_of_not_gt
(assume h1 : b < a,
have h2 : b * c < a * c, from mul_lt_mul_of_pos_right h1 hc,
h2.not_le h)
lemma pos_and_pos_or_neg_and_neg_of_mul_pos (hab : 0 < a * b) :
(0 < a ∧ 0 < b) ∨ (a < 0 ∧ b < 0) :=
begin
rcases lt_trichotomy 0 a with (ha|rfl|ha),
{ refine or.inl ⟨ha, _⟩,
contrapose! hab,
exact mul_nonpos_of_nonneg_of_nonpos ha.le hab },
{ rw [zero_mul] at hab, exact hab.false.elim },
{ refine or.inr ⟨ha, _⟩,
contrapose! hab,
exact mul_nonpos_of_nonpos_of_nonneg ha.le hab }
end
lemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg (hab : 0 ≤ a * b) :
(0 ≤ a ∧ 0 ≤ b) ∨ (a ≤ 0 ∧ b ≤ 0) :=
begin
contrapose! hab,
rcases lt_trichotomy 0 a with (ha|rfl|ha),
exacts [mul_neg_of_pos_of_neg ha (hab.1 ha.le), ((hab.1 le_rfl).asymm (hab.2 le_rfl)).elim,
mul_neg_of_neg_of_pos ha (hab.2 ha.le)]
end
lemma pos_of_mul_pos_left (h : 0 < a * b) (ha : 0 ≤ a) : 0 < b :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ λ h, h.1.not_le ha).2
lemma pos_of_mul_pos_right (h : 0 < a * b) (hb : 0 ≤ b) : 0 < a :=
((pos_and_pos_or_neg_and_neg_of_mul_pos h).resolve_right $ λ h, h.2.not_le hb).1
@[simp] lemma inv_of_pos [invertible a] : 0 < ⅟a ↔ 0 < a :=
begin
have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],
exact ⟨λ h, pos_of_mul_pos_right this h.le, λ h, pos_of_mul_pos_left this h.le⟩
end
@[simp] lemma inv_of_nonpos [invertible a] : ⅟a ≤ 0 ↔ a ≤ 0 :=
by simp only [← not_lt, inv_of_pos]
lemma nonneg_of_mul_nonneg_left (h : 0 ≤ a * b) (h1 : 0 < a) : 0 ≤ b :=
le_of_not_gt (assume h2 : b < 0, (mul_neg_of_pos_of_neg h1 h2).not_le h)
lemma nonneg_of_mul_nonneg_right (h : 0 ≤ a * b) (h1 : 0 < b) : 0 ≤ a :=
le_of_not_gt (assume h2 : a < 0, (mul_neg_of_neg_of_pos h2 h1).not_le h)
@[simp] lemma inv_of_nonneg [invertible a] : 0 ≤ ⅟a ↔ 0 ≤ a :=
begin
have : 0 < a * ⅟a, by simp only [mul_inv_of_self, zero_lt_one],
exact ⟨λ h, (pos_of_mul_pos_right this h).le, λ h, (pos_of_mul_pos_left this h).le⟩
end
@[simp] lemma inv_of_lt_zero [invertible a] : ⅟a < 0 ↔ a < 0 :=
by simp only [← not_le, inv_of_nonneg]
@[simp] lemma inv_of_le_one [invertible a] (h : 1 ≤ a) : ⅟a ≤ 1 :=
mul_inv_of_self a ▸ le_mul_of_one_le_left (inv_of_nonneg.2 $ zero_le_one.trans h) h
lemma neg_of_mul_neg_left (h : a * b < 0) (h1 : 0 ≤ a) : b < 0 :=
lt_of_not_ge (assume h2 : b ≥ 0, (mul_nonneg h1 h2).not_lt h)
lemma neg_of_mul_neg_right (h : a * b < 0) (h1 : 0 ≤ b) : a < 0 :=
lt_of_not_ge (assume h2 : a ≥ 0, (mul_nonneg h2 h1).not_lt h)
lemma nonpos_of_mul_nonpos_left (h : a * b ≤ 0) (h1 : 0 < a) : b ≤ 0 :=
le_of_not_gt (assume h2 : b > 0, (mul_pos h1 h2).not_le h)
lemma nonpos_of_mul_nonpos_right (h : a * b ≤ 0) (h1 : 0 < b) : a ≤ 0 :=
le_of_not_gt (assume h2 : a > 0, (mul_pos h2 h1).not_le h)
@[simp] lemma mul_le_mul_left (h : 0 < c) : c * a ≤ c * b ↔ a ≤ b :=
⟨λ h', le_of_mul_le_mul_left h' h, λ h', mul_le_mul_of_nonneg_left h' h.le⟩
@[simp] lemma mul_le_mul_right (h : 0 < c) : a * c ≤ b * c ↔ a ≤ b :=
⟨λ h', le_of_mul_le_mul_right h' h, λ h', mul_le_mul_of_nonneg_right h' h.le⟩
@[simp] lemma mul_lt_mul_left (h : 0 < c) : c * a < c * b ↔ a < b :=
⟨lt_imp_lt_of_le_imp_le $ λ h', mul_le_mul_of_nonneg_left h' h.le,
λ h', mul_lt_mul_of_pos_left h' h⟩
@[simp] lemma mul_lt_mul_right (h : 0 < c) : a * c < b * c ↔ a < b :=
⟨lt_imp_lt_of_le_imp_le $ λ h', mul_le_mul_of_nonneg_right h' h.le,
λ h', mul_lt_mul_of_pos_right h' h⟩
@[simp] lemma zero_le_mul_left (h : 0 < c) : 0 ≤ c * b ↔ 0 ≤ b :=
by { convert mul_le_mul_left h, simp }
@[simp] lemma zero_le_mul_right (h : 0 < c) : 0 ≤ b * c ↔ 0 ≤ b :=
by { convert mul_le_mul_right h, simp }
@[simp] lemma zero_lt_mul_left (h : 0 < c) : 0 < c * b ↔ 0 < b :=
by { convert mul_lt_mul_left h, simp }
@[simp] lemma zero_lt_mul_right (h : 0 < c) : 0 < b * c ↔ 0 < b :=
by { convert mul_lt_mul_right h, simp }
lemma add_le_mul_of_left_le_right (a2 : 2 ≤ a) (ab : a ≤ b) : a + b ≤ a * b :=
have 0 < b, from
calc 0 < 2 : zero_lt_two
... ≤ a : a2
... ≤ b : ab,
calc a + b ≤ b + b : add_le_add_right ab b
... = 2 * b : (two_mul b).symm
... ≤ a * b : (mul_le_mul_right this).mpr a2
lemma add_le_mul_of_right_le_left (b2 : 2 ≤ b) (ba : b ≤ a) : a + b ≤ a * b :=
have 0 < a, from
calc 0 < 2 : zero_lt_two
... ≤ b : b2
... ≤ a : ba,
calc a + b ≤ a + a : add_le_add_left ba a
... = a * 2 : (mul_two a).symm
... ≤ a * b : (mul_le_mul_left this).mpr b2
lemma add_le_mul (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ a * b :=
if hab : a ≤ b then add_le_mul_of_left_le_right a2 hab
else add_le_mul_of_right_le_left b2 (le_of_not_le hab)
lemma add_le_mul' (a2 : 2 ≤ a) (b2 : 2 ≤ b) : a + b ≤ b * a :=
(le_of_eq (add_comm _ _)).trans (add_le_mul b2 a2)
section
variables [nontrivial α]
@[simp] lemma bit0_le_bit0 : bit0 a ≤ bit0 b ↔ a ≤ b :=
by rw [bit0, bit0, ← two_mul, ← two_mul, mul_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma bit0_lt_bit0 : bit0 a < bit0 b ↔ a < b :=
by rw [bit0, bit0, ← two_mul, ← two_mul, mul_lt_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma bit1_le_bit1 : bit1 a ≤ bit1 b ↔ a ≤ b :=
(add_le_add_iff_right 1).trans bit0_le_bit0
@[simp] lemma bit1_lt_bit1 : bit1 a < bit1 b ↔ a < b :=
(add_lt_add_iff_right 1).trans bit0_lt_bit0
@[simp] lemma one_le_bit1 : (1 : α) ≤ bit1 a ↔ 0 ≤ a :=
by rw [bit1, le_add_iff_nonneg_left, bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma one_lt_bit1 : (1 : α) < bit1 a ↔ 0 < a :=
by rw [bit1, lt_add_iff_pos_left, bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma zero_le_bit0 : (0 : α) ≤ bit0 a ↔ 0 ≤ a :=
by rw [bit0, ← two_mul, zero_le_mul_left (zero_lt_two : 0 < (2:α))]
@[simp] lemma zero_lt_bit0 : (0 : α) < bit0 a ↔ 0 < a :=
by rw [bit0, ← two_mul, zero_lt_mul_left (zero_lt_two : 0 < (2:α))]
end
lemma le_mul_iff_one_le_left (hb : 0 < b) : b ≤ a * b ↔ 1 ≤ a :=
suffices 1 * b ≤ a * b ↔ 1 ≤ a, by rwa one_mul at this,
mul_le_mul_right hb
lemma lt_mul_iff_one_lt_left (hb : 0 < b) : b < a * b ↔ 1 < a :=
suffices 1 * b < a * b ↔ 1 < a, by rwa one_mul at this,
mul_lt_mul_right hb
lemma le_mul_iff_one_le_right (hb : 0 < b) : b ≤ b * a ↔ 1 ≤ a :=
suffices b * 1 ≤ b * a ↔ 1 ≤ a, by rwa mul_one at this,
mul_le_mul_left hb
lemma lt_mul_iff_one_lt_right (hb : 0 < b) : b < b * a ↔ 1 < a :=
suffices b * 1 < b * a ↔ 1 < a, by rwa mul_one at this,
mul_lt_mul_left hb
lemma lt_mul_of_one_lt_right (hb : 0 < b) : 1 < a → b < b * a :=
(lt_mul_iff_one_lt_right hb).2
theorem mul_nonneg_iff_right_nonneg_of_pos (h : 0 < a) : 0 ≤ b * a ↔ 0 ≤ b :=
⟨assume : 0 ≤ b * a, nonneg_of_mul_nonneg_right this h, assume : 0 ≤ b, mul_nonneg this h.le⟩
lemma mul_le_iff_le_one_left (hb : 0 < b) : a * b ≤ b ↔ a ≤ 1 :=
⟨ λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).2 h.not_lt),
λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_left hb).1 h.not_lt) ⟩
lemma mul_lt_iff_lt_one_left (hb : 0 < b) : a * b < b ↔ a < 1 :=
⟨ λ h, lt_of_not_ge (mt (le_mul_iff_one_le_left hb).2 h.not_le),
λ h, lt_of_not_ge (mt (le_mul_iff_one_le_left hb).1 h.not_le) ⟩
lemma mul_le_iff_le_one_right (hb : 0 < b) : b * a ≤ b ↔ a ≤ 1 :=
⟨ λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).2 h.not_lt),
λ h, le_of_not_lt (mt (lt_mul_iff_one_lt_right hb).1 h.not_lt) ⟩
lemma mul_lt_iff_lt_one_right (hb : 0 < b) : b * a < b ↔ a < 1 :=
⟨ λ h, lt_of_not_ge (mt (le_mul_iff_one_le_right hb).2 h.not_le),
λ h, lt_of_not_ge (mt (le_mul_iff_one_le_right hb).1 h.not_le) ⟩
lemma nonpos_of_mul_nonneg_left (h : 0 ≤ a * b) (hb : b < 0) : a ≤ 0 :=
le_of_not_gt (λ ha, absurd h (mul_neg_of_pos_of_neg ha hb).not_le)
lemma nonpos_of_mul_nonneg_right (h : 0 ≤ a * b) (ha : a < 0) : b ≤ 0 :=
le_of_not_gt (λ hb, absurd h (mul_neg_of_neg_of_pos ha hb).not_le)
lemma neg_of_mul_pos_left (h : 0 < a * b) (hb : b ≤ 0) : a < 0 :=
lt_of_not_ge (λ ha, absurd h (mul_nonpos_of_nonneg_of_nonpos ha hb).not_lt)
lemma neg_of_mul_pos_right (h : 0 < a * b) (ha : a ≤ 0) : b < 0 :=
lt_of_not_ge (λ hb, absurd h (mul_nonpos_of_nonpos_of_nonneg ha hb).not_lt)
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_semiring.to_no_top_order {α : Type*} [linear_ordered_semiring α] :
no_top_order α :=
⟨assume a, ⟨a + 1, lt_add_of_pos_right _ zero_lt_one⟩⟩
/-- Pullback a `linear_ordered_semiring` under an injective map. -/
def function.injective.linear_ordered_semiring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [nontrivial β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y) :
linear_ordered_semiring β :=
{ ..linear_order.lift f hf,
..‹nontrivial β›,
..hf.ordered_semiring f zero one add mul }
end linear_ordered_semiring
section mono
variables {β : Type*} [linear_ordered_semiring α] [preorder β] {f g : β → α} {a : α}
lemma monotone_mul_left_of_nonneg (ha : 0 ≤ a) : monotone (λ x, a*x) :=
assume b c b_le_c, mul_le_mul_of_nonneg_left b_le_c ha
lemma monotone_mul_right_of_nonneg (ha : 0 ≤ a) : monotone (λ x, x*a) :=
assume b c b_le_c, mul_le_mul_of_nonneg_right b_le_c ha
lemma monotone.mul_const (hf : monotone f) (ha : 0 ≤ a) :
monotone (λ x, (f x) * a) :=
(monotone_mul_right_of_nonneg ha).comp hf
lemma monotone.const_mul (hf : monotone f) (ha : 0 ≤ a) :
monotone (λ x, a * (f x)) :=
(monotone_mul_left_of_nonneg ha).comp hf
lemma monotone.mul (hf : monotone f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x) (hg0 : ∀ x, 0 ≤ g x) :
monotone (λ x, f x * g x) :=
λ x y h, mul_le_mul (hf h) (hg h) (hg0 x) (hf0 y)
lemma strict_mono_mul_left_of_pos (ha : 0 < a) : strict_mono (λ x, a * x) :=
assume b c b_lt_c, (mul_lt_mul_left ha).2 b_lt_c
lemma strict_mono_mul_right_of_pos (ha : 0 < a) : strict_mono (λ x, x * a) :=
assume b c b_lt_c, (mul_lt_mul_right ha).2 b_lt_c
lemma strict_mono.mul_const (hf : strict_mono f) (ha : 0 < a) :
strict_mono (λ x, (f x) * a) :=
(strict_mono_mul_right_of_pos ha).comp hf
lemma strict_mono.const_mul (hf : strict_mono f) (ha : 0 < a) :
strict_mono (λ x, a * (f x)) :=
(strict_mono_mul_left_of_pos ha).comp hf
lemma strict_mono.mul_monotone (hf : strict_mono f) (hg : monotone g) (hf0 : ∀ x, 0 ≤ f x)
(hg0 : ∀ x, 0 < g x) :
strict_mono (λ x, f x * g x) :=
λ x y h, mul_lt_mul (hf h) (hg h.le) (hg0 x) (hf0 y)
lemma monotone.mul_strict_mono (hf : monotone f) (hg : strict_mono g) (hf0 : ∀ x, 0 < f x)
(hg0 : ∀ x, 0 ≤ g x) :
strict_mono (λ x, f x * g x) :=
λ x y h, mul_lt_mul' (hf h.le) (hg h) (hg0 x) (hf0 y)
lemma strict_mono.mul (hf : strict_mono f) (hg : strict_mono g) (hf0 : ∀ x, 0 ≤ f x)
(hg0 : ∀ x, 0 ≤ g x) :
strict_mono (λ x, f x * g x) :=
λ x y h, mul_lt_mul'' (hf h) (hg h) (hf0 x) (hg0 x)
end mono
section linear_ordered_semiring
variables [linear_ordered_semiring α] {a b c : α}
@[simp] lemma decidable.mul_le_mul_left (h : 0 < c) : c * a ≤ c * b ↔ a ≤ b :=
decidable.le_iff_le_iff_lt_iff_lt.2 $ mul_lt_mul_left h
@[simp] lemma decidable.mul_le_mul_right (h : 0 < c) : a * c ≤ b * c ↔ a ≤ b :=
decidable.le_iff_le_iff_lt_iff_lt.2 $ mul_lt_mul_right h
lemma mul_max_of_nonneg (b c : α) (ha : 0 ≤ a) : a * max b c = max (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_max
lemma mul_min_of_nonneg (b c : α) (ha : 0 ≤ a) : a * min b c = min (a * b) (a * c) :=
(monotone_mul_left_of_nonneg ha).map_min
lemma max_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : max a b * c = max (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_max
lemma min_mul_of_nonneg (a b : α) (hc : 0 ≤ c) : min a b * c = min (a * c) (b * c) :=
(monotone_mul_right_of_nonneg hc).map_min
end linear_ordered_semiring
/-- An `ordered_ring α` is a ring `α` with a partial order such that
multiplication with a positive number and addition are monotone. -/
@[protect_proj]
class ordered_ring (α : Type u) extends ring α, ordered_add_comm_group α :=
(zero_le_one : 0 ≤ (1 : α))
(mul_pos : ∀ a b : α, 0 < a → 0 < b → 0 < a * b)
section ordered_ring
variables [ordered_ring α] {a b c : α}
lemma ordered_ring.mul_nonneg (a b : α) (h₁ : 0 ≤ a) (h₂ : 0 ≤ b) : 0 ≤ a * b :=
begin
cases classical.em (a ≤ 0), { simp [le_antisymm h h₁] },
cases classical.em (b ≤ 0), { simp [le_antisymm h_1 h₂] },
exact (le_not_le_of_lt (ordered_ring.mul_pos a b (h₁.lt_of_not_le h) (h₂.lt_of_not_le h_1))).left,
end
lemma ordered_ring.mul_le_mul_of_nonneg_left (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
rw [← sub_nonneg, ← mul_sub],
exact ordered_ring.mul_nonneg c (b - a) h₂ (sub_nonneg.2 h₁),
end
lemma ordered_ring.mul_le_mul_of_nonneg_right (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c :=
begin
rw [← sub_nonneg, ← sub_mul],
exact ordered_ring.mul_nonneg _ _ (sub_nonneg.2 h₁) h₂,
end
lemma ordered_ring.mul_lt_mul_of_pos_left (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b :=
begin
rw [← sub_pos, ← mul_sub],
exact ordered_ring.mul_pos _ _ h₂ (sub_pos.2 h₁),
end
lemma ordered_ring.mul_lt_mul_of_pos_right (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c :=
begin
rw [← sub_pos, ← sub_mul],
exact ordered_ring.mul_pos _ _ (sub_pos.2 h₁) h₂,
end
@[priority 100] -- see Note [lower instance priority]
instance ordered_ring.to_ordered_semiring : ordered_semiring α :=
{ mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add_left_cancel α _,
add_right_cancel := @add_right_cancel α _,
le_of_add_le_add_left := @le_of_add_le_add_left α _,
mul_lt_mul_of_pos_left := @ordered_ring.mul_lt_mul_of_pos_left α _,
mul_lt_mul_of_pos_right := @ordered_ring.mul_lt_mul_of_pos_right α _,
..‹ordered_ring α› }
lemma mul_le_mul_of_nonpos_left {a b c : α} (h : b ≤ a) (hc : c ≤ 0) : c * a ≤ c * b :=
have -c ≥ 0, from neg_nonneg_of_nonpos hc,
have -c * b ≤ -c * a, from mul_le_mul_of_nonneg_left h this,
have -(c * b) ≤ -(c * a), by rwa [← neg_mul_eq_neg_mul, ← neg_mul_eq_neg_mul] at this,
le_of_neg_le_neg this
lemma mul_le_mul_of_nonpos_right {a b c : α} (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c :=
have -c ≥ 0, from neg_nonneg_of_nonpos hc,
have b * -c ≤ a * -c, from mul_le_mul_of_nonneg_right h this,
have -(b * c) ≤ -(a * c), by rwa [← neg_mul_eq_mul_neg, ← neg_mul_eq_mul_neg] at this,
le_of_neg_le_neg this
lemma mul_nonneg_of_nonpos_of_nonpos {a b : α} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b :=
have 0 * b ≤ a * b, from mul_le_mul_of_nonpos_right ha hb,
by rwa zero_mul at this
lemma mul_lt_mul_of_neg_left {a b c : α} (h : b < a) (hc : c < 0) : c * a < c * b :=
have -c > 0, from neg_pos_of_neg hc,
have -c * b < -c * a, from mul_lt_mul_of_pos_left h this,
have -(c * b) < -(c * a), by rwa [← neg_mul_eq_neg_mul, ← neg_mul_eq_neg_mul] at this,
lt_of_neg_lt_neg this
lemma mul_lt_mul_of_neg_right {a b c : α} (h : b < a) (hc : c < 0) : a * c < b * c :=
have -c > 0, from neg_pos_of_neg hc,
have b * -c < a * -c, from mul_lt_mul_of_pos_right h this,
have -(b * c) < -(a * c), by rwa [← neg_mul_eq_mul_neg, ← neg_mul_eq_mul_neg] at this,
lt_of_neg_lt_neg this
lemma mul_pos_of_neg_of_neg {a b : α} (ha : a < 0) (hb : b < 0) : 0 < a * b :=
have 0 * b < a * b, from mul_lt_mul_of_neg_right ha hb,
by rwa zero_mul at this
/-- Pullback an `ordered_ring` under an injective map. -/
def function.injective.ordered_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y) :
ordered_ring β :=
{ mul_pos := λ a b a0 b0, show f 0 < f (a * b), by { rw [zero, mul], apply mul_pos; rwa ← zero },
..hf.ordered_semiring f zero one add mul,
..hf.ring f zero one add mul neg sub }
end ordered_ring
section ordered_comm_ring
/-- An `ordered_comm_ring α` is a commutative ring `α` with a partial order such that
multiplication with a positive number and addition are monotone. -/
@[protect_proj]
class ordered_comm_ring (α : Type u) extends ordered_ring α, ordered_comm_semiring α, comm_ring α
/-- Pullback an `ordered_comm_ring` under an injective map. -/
def function.injective.ordered_comm_ring [ordered_comm_ring α] {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (- x) = - f x) (sub : ∀ x y, f (x - y) = f x - f y) :
ordered_comm_ring β :=
{ ..hf.ordered_comm_semiring f zero one add mul,
..hf.ordered_ring f zero one add mul neg sub,
..hf.comm_ring f zero one add mul neg sub }
end ordered_comm_ring
/-- A `linear_ordered_ring α` is a ring `α` with a linear order such that
multiplication with a positive number and addition are monotone. -/
@[protect_proj] class linear_ordered_ring (α : Type u)
extends ordered_ring α, linear_order α, nontrivial α
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.to_linear_ordered_add_comm_group [s : linear_ordered_ring α] :
linear_ordered_add_comm_group α :=
{ .. s }
section linear_ordered_ring
variables [linear_ordered_ring α] {a b c : α}
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.to_linear_ordered_semiring : linear_ordered_semiring α :=
{ mul_zero := mul_zero,
zero_mul := zero_mul,
add_left_cancel := @add_left_cancel α _,
add_right_cancel := @add_right_cancel α _,
le_of_add_le_add_left := @le_of_add_le_add_left α _,
mul_lt_mul_of_pos_left := @mul_lt_mul_of_pos_left α _,
mul_lt_mul_of_pos_right := @mul_lt_mul_of_pos_right α _,
le_total := linear_ordered_ring.le_total,
..‹linear_ordered_ring α› }
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_ring.to_domain : domain α :=
{ eq_zero_or_eq_zero_of_mul_eq_zero :=
begin
intros a b hab,
contrapose! hab,
cases (lt_or_gt_of_ne hab.1) with ha ha; cases (lt_or_gt_of_ne hab.2) with hb hb,
exacts [(mul_pos_of_neg_of_neg ha hb).ne.symm, (mul_neg_of_neg_of_pos ha hb).ne,
(mul_neg_of_pos_of_neg ha hb).ne, (mul_pos ha hb).ne.symm]
end,
.. ‹linear_ordered_ring α› }
@[simp] lemma abs_one : abs (1 : α) = 1 := abs_of_pos zero_lt_one
@[simp] lemma abs_two : abs (2 : α) = 2 := abs_of_pos zero_lt_two
lemma abs_mul (a b : α) : abs (a * b) = abs a * abs b :=
begin
rw [abs_eq (mul_nonneg (abs_nonneg a) (abs_nonneg b))],
cases le_total a 0 with ha ha; cases le_total b 0 with hb hb;
simp [abs_of_nonpos, abs_of_nonneg, *]
end
/-- `abs` as a `monoid_with_zero_hom`. -/
def abs_hom : monoid_with_zero_hom α α := ⟨abs, abs_zero, abs_one, abs_mul⟩
@[simp] lemma abs_mul_abs_self (a : α) : abs a * abs a = a * a :=
abs_by_cases (λ x, x * x = a * a) rfl (neg_mul_neg a a)
@[simp] lemma abs_mul_self (a : α) : abs (a * a) = a * a :=
by rw [abs_mul, abs_mul_abs_self]
lemma mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 :=
⟨pos_and_pos_or_neg_and_neg_of_mul_pos,
λ h, h.elim (and_imp.2 mul_pos) (and_imp.2 mul_pos_of_neg_of_neg)⟩
lemma mul_neg_iff : a * b < 0 ↔ 0 < a ∧ b < 0 ∨ a < 0 ∧ 0 < b :=
by rw [← neg_pos, neg_mul_eq_mul_neg, mul_pos_iff, neg_pos, neg_lt_zero]
lemma mul_nonneg_iff : 0 ≤ a * b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=
⟨nonneg_and_nonneg_or_nonpos_and_nonpos_of_mul_nnonneg,
λ h, h.elim (and_imp.2 mul_nonneg) (and_imp.2 mul_nonneg_of_nonpos_of_nonpos)⟩
lemma mul_nonpos_iff : a * b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b :=
by rw [← neg_nonneg, neg_mul_eq_mul_neg, mul_nonneg_iff, neg_nonneg, neg_nonpos]
lemma mul_self_nonneg (a : α) : 0 ≤ a * a :=
abs_mul_self a ▸ abs_nonneg _
@[simp] lemma neg_le_self_iff : -a ≤ a ↔ 0 ≤ a :=
by simp [neg_le_iff_add_nonneg, ← two_mul, mul_nonneg_iff, zero_le_one, (@zero_lt_two α _ _).not_le]
@[simp] lemma neg_lt_self_iff : -a < a ↔ 0 < a :=
by simp [neg_lt_iff_pos_add, ← two_mul, mul_pos_iff, zero_lt_one, (@zero_lt_two α _ _).not_lt]
@[simp] lemma le_neg_self_iff : a ≤ -a ↔ a ≤ 0 :=
calc a ≤ -a ↔ -(-a) ≤ -a : by rw neg_neg
... ↔ 0 ≤ -a : neg_le_self_iff
... ↔ a ≤ 0 : neg_nonneg
@[simp] lemma lt_neg_self_iff : a < -a ↔ a < 0 :=
calc a < -a ↔ -(-a) < -a : by rw neg_neg
... ↔ 0 < -a : neg_lt_self_iff
... ↔ a < 0 : neg_pos
@[simp] lemma abs_eq_self : abs a = a ↔ 0 ≤ a := by simp [abs]
@[simp] lemma abs_eq_neg_self : abs a = -a ↔ a ≤ 0 := by simp [abs]
lemma gt_of_mul_lt_mul_neg_left (h : c * a < c * b) (hc : c ≤ 0) : b < a :=
have nhc : 0 ≤ -c, from neg_nonneg_of_nonpos hc,
have h2 : -(c * b) < -(c * a), from neg_lt_neg h,
have h3 : (-c) * b < (-c) * a, from calc
(-c) * b = - (c * b) : by rewrite neg_mul_eq_neg_mul
... < -(c * a) : h2
... = (-c) * a : by rewrite neg_mul_eq_neg_mul,
lt_of_mul_lt_mul_left h3 nhc
lemma neg_one_lt_zero : -1 < (0:α) := neg_lt_zero.2 zero_lt_one
lemma le_of_mul_le_of_one_le {a b c : α} (h : a * c ≤ b) (hb : 0 ≤ b) (hc : 1 ≤ c) :
a ≤ b :=
have h' : a * c ≤ b * c, from calc
a * c ≤ b : h
... = b * 1 : by rewrite mul_one
... ≤ b * c : mul_le_mul_of_nonneg_left hc hb,
le_of_mul_le_mul_right h' (zero_lt_one.trans_le hc)
lemma nonneg_le_nonneg_of_squares_le {a b : α} (hb : 0 ≤ b) (h : a * a ≤ b * b) : a ≤ b :=
le_of_not_gt (λhab, (mul_self_lt_mul_self hb hab).not_le h)
lemma mul_self_le_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a ≤ b ↔ a * a ≤ b * b :=
⟨mul_self_le_mul_self h1, nonneg_le_nonneg_of_squares_le h2⟩
lemma mul_self_lt_mul_self_iff {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a < b ↔ a * a < b * b :=
((@strict_mono_incr_on_mul_self α _).lt_iff_lt h1 h2).symm
lemma mul_self_inj {a b : α} (h1 : 0 ≤ a) (h2 : 0 ≤ b) : a * a = b * b ↔ a = b :=
(@strict_mono_incr_on_mul_self α _).inj_on.eq_iff h1 h2
@[simp] lemma mul_le_mul_left_of_neg {a b c : α} (h : c < 0) : c * a ≤ c * b ↔ b ≤ a :=
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_left h' h,
λ h', mul_le_mul_of_nonpos_left h' h.le⟩
@[simp] lemma mul_le_mul_right_of_neg {a b c : α} (h : c < 0) : a * c ≤ b * c ↔ b ≤ a :=
⟨le_imp_le_of_lt_imp_lt $ λ h', mul_lt_mul_of_neg_right h' h,
λ h', mul_le_mul_of_nonpos_right h' h.le⟩
@[simp] lemma mul_lt_mul_left_of_neg {a b c : α} (h : c < 0) : c * a < c * b ↔ b < a :=
lt_iff_lt_of_le_iff_le (mul_le_mul_left_of_neg h)
@[simp] lemma mul_lt_mul_right_of_neg {a b c : α} (h : c < 0) : a * c < b * c ↔ b < a :=
lt_iff_lt_of_le_iff_le (mul_le_mul_right_of_neg h)
lemma sub_one_lt (a : α) : a - 1 < a :=
sub_lt_iff_lt_add.2 (lt_add_one a)
lemma mul_self_pos {a : α} (ha : a ≠ 0) : 0 < a * a :=
by rcases lt_trichotomy a 0 with h|h|h;
[exact mul_pos_of_neg_of_neg h h, exact (ha h).elim, exact mul_pos h h]
lemma mul_self_le_mul_self_of_le_of_neg_le {x y : α} (h₁ : x ≤ y) (h₂ : -x ≤ y) : x * x ≤ y * y :=
begin
rw [← abs_mul_abs_self x],
exact mul_self_le_mul_self (abs_nonneg x) (abs_le.2 ⟨neg_le.2 h₂, h₁⟩)
end
lemma nonneg_of_mul_nonpos_left {a b : α} (h : a * b ≤ 0) (hb : b < 0) : 0 ≤ a :=
le_of_not_gt (λ ha, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)
lemma nonneg_of_mul_nonpos_right {a b : α} (h : a * b ≤ 0) (ha : a < 0) : 0 ≤ b :=
le_of_not_gt (λ hb, absurd h (mul_pos_of_neg_of_neg ha hb).not_le)
lemma pos_of_mul_neg_left {a b : α} (h : a * b < 0) (hb : b ≤ 0) : 0 < a :=
lt_of_not_ge (λ ha, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)
lemma pos_of_mul_neg_right {a b : α} (h : a * b < 0) (ha : a ≤ 0) : 0 < b :=
lt_of_not_ge (λ hb, absurd h (mul_nonneg_of_nonpos_of_nonpos ha hb).not_lt)
/-- The sum of two squares is zero iff both elements are zero. -/
lemma mul_self_add_mul_self_eq_zero {x y : α} : x * x + y * y = 0 ↔ x = 0 ∧ y = 0 :=
by rw [add_eq_zero_iff', mul_self_eq_zero, mul_self_eq_zero]; apply mul_self_nonneg
lemma eq_zero_of_mul_self_add_mul_self_eq_zero (h : a * a + b * b = 0) : a = 0 :=
(mul_self_add_mul_self_eq_zero.mp h).left
lemma abs_eq_iff_mul_self_eq : abs a = abs b ↔ a * a = b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact (mul_self_inj (abs_nonneg a) (abs_nonneg b)).symm,
end
lemma abs_lt_iff_mul_self_lt : abs a < abs b ↔ a * a < b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact mul_self_lt_mul_self_iff (abs_nonneg a) (abs_nonneg b)
end
lemma abs_le_iff_mul_self_le : abs a ≤ abs b ↔ a * a ≤ b * b :=
begin
rw [← abs_mul_abs_self, ← abs_mul_abs_self b],
exact mul_self_le_mul_self_iff (abs_nonneg a) (abs_nonneg b)
end
lemma abs_le_one_iff_mul_self_le_one : abs a ≤ 1 ↔ a * a ≤ 1 :=
by simpa only [abs_one, one_mul] using @abs_le_iff_mul_self_le α _ a 1
/-- Pullback a `linear_ordered_ring` under an injective map. -/
def function.injective.linear_ordered_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β] [nontrivial β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) :
linear_ordered_ring β :=
{ ..linear_order.lift f hf,
..‹nontrivial β›,
..hf.ordered_ring f zero one add mul neg sub }
end linear_ordered_ring
/-- A `linear_ordered_comm_ring α` is a commutative ring `α` with a linear order
such that multiplication with a positive number and addition are monotone. -/
@[protect_proj]
class linear_ordered_comm_ring (α : Type u) extends linear_ordered_ring α, comm_monoid α
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_comm_ring.to_ordered_comm_ring [d : linear_ordered_comm_ring α] :
ordered_comm_ring α :=
-- One might hope that `{ ..linear_ordered_ring.to_linear_ordered_semiring, ..d }`
-- achieved the same result here.
-- Unfortunately with that definition we see mismatched instances in `algebra.star.chsh`.
let s : linear_ordered_semiring α := @linear_ordered_ring.to_linear_ordered_semiring α _ in
{ zero_mul := @linear_ordered_semiring.zero_mul α s,
mul_zero := @linear_ordered_semiring.mul_zero α s,
add_left_cancel := @linear_ordered_semiring.add_left_cancel α s,
add_right_cancel := @linear_ordered_semiring.add_right_cancel α s,
le_of_add_le_add_left := @linear_ordered_semiring.le_of_add_le_add_left α s,
mul_lt_mul_of_pos_left := @linear_ordered_semiring.mul_lt_mul_of_pos_left α s,
mul_lt_mul_of_pos_right := @linear_ordered_semiring.mul_lt_mul_of_pos_right α s,
..d }
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_comm_ring.to_integral_domain [s : linear_ordered_comm_ring α] :
integral_domain α :=
{ ..linear_ordered_ring.to_domain, ..s }
@[priority 100] -- see Note [lower instance priority]
instance linear_ordered_comm_ring.to_linear_ordered_semiring [d : linear_ordered_comm_ring α] :
linear_ordered_semiring α :=
-- One might hope that `{ ..linear_ordered_ring.to_linear_ordered_semiring, ..d }`
-- achieved the same result here.
-- Unfortunately with that definition we see mismatched `preorder ℝ` instances in
-- `topology.metric_space.basic`.
let s : linear_ordered_semiring α := @linear_ordered_ring.to_linear_ordered_semiring α _ in
{ zero_mul := @linear_ordered_semiring.zero_mul α s,
mul_zero := @linear_ordered_semiring.mul_zero α s,
add_left_cancel := @linear_ordered_semiring.add_left_cancel α s,
add_right_cancel := @linear_ordered_semiring.add_right_cancel α s,
le_of_add_le_add_left := @linear_ordered_semiring.le_of_add_le_add_left α s,
mul_lt_mul_of_pos_left := @linear_ordered_semiring.mul_lt_mul_of_pos_left α s,
mul_lt_mul_of_pos_right := @linear_ordered_semiring.mul_lt_mul_of_pos_right α s,
..d }
section linear_ordered_comm_ring
variables [linear_ordered_comm_ring α] {a b c d : α}
lemma max_mul_mul_le_max_mul_max (b c : α) (ha : 0 ≤ a) (hd: 0 ≤ d) :
max (a * b) (d * c) ≤ max a c * max d b :=
have ba : b * a ≤ max d b * max c a,
from mul_le_mul (le_max_right d b) (le_max_right c a) ha (le_trans hd (le_max_left d b)),
have cd : c * d ≤ max a c * max b d,
from mul_le_mul (le_max_right a c) (le_max_right b d) hd (le_trans ha (le_max_left a c)),
max_le
(by simpa [mul_comm, max_comm] using ba)
(by simpa [mul_comm, max_comm] using cd)
lemma abs_sub_square (a b : α) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b :=
begin
rw abs_mul_abs_self,
simp [left_distrib, right_distrib, add_assoc, add_comm, add_left_comm, mul_comm, sub_eq_add_neg],
end
/-- Pullback a `linear_ordered_comm_ring` under an injective map. -/
def function.injective.linear_ordered_comm_ring {β : Type*}
[has_zero β] [has_one β] [has_add β] [has_mul β] [has_neg β] [has_sub β] [nontrivial β]
(f : β → α) (hf : function.injective f) (zero : f 0 = 0) (one : f 1 = 1)
(add : ∀ x y, f (x + y) = f x + f y) (mul : ∀ x y, f (x * y) = f x * f y)
(neg : ∀ x, f (-x) = -f x) (sub : ∀ x y, f (x - y) = f x - f y) :
linear_ordered_comm_ring β :=
{ ..linear_order.lift f hf,
..‹nontrivial β›,
..hf.ordered_comm_ring f zero one add mul neg sub }
end linear_ordered_comm_ring
/-- Extend `nonneg_add_comm_group` to support ordered rings
specified by their nonnegative elements -/
class nonneg_ring (α : Type*) extends ring α, nonneg_add_comm_group α :=
(one_nonneg : nonneg 1)
(mul_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a * b))
(mul_pos : ∀ {a b}, pos a → pos b → pos (a * b))
/-- Extend `nonneg_add_comm_group` to support linearly ordered rings
specified by their nonnegative elements -/
class linear_nonneg_ring (α : Type*) extends domain α, nonneg_add_comm_group α :=
(one_pos : pos 1)
(mul_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a * b))
(nonneg_total : ∀ a, nonneg a ∨ nonneg (-a))
namespace nonneg_ring
open nonneg_add_comm_group
variable [nonneg_ring α]
/-- `to_linear_nonneg_ring` shows that a `nonneg_ring` with a total order is a `domain`,
hence a `linear_nonneg_ring`. -/
def to_linear_nonneg_ring [nontrivial α]
(nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a))
: linear_nonneg_ring α :=
{ one_pos := (pos_iff 1).mpr ⟨one_nonneg, λ h, zero_ne_one (nonneg_antisymm one_nonneg h).symm⟩,
nonneg_total := nonneg_total,
eq_zero_or_eq_zero_of_mul_eq_zero :=
suffices ∀ {a} b : α, nonneg a → a * b = 0 → a = 0 ∨ b = 0,
from λ a b, (nonneg_total a).elim (this b)
(λ na, by simpa using this b na),
suffices ∀ {a b : α}, nonneg a → nonneg b → a * b = 0 → a = 0 ∨ b = 0,
from λ a b na, (nonneg_total b).elim (this na)
(λ nb, by simpa using this na nb),
λ a b na nb z, classical.by_cases
(λ nna : nonneg (-a), or.inl (nonneg_antisymm na nna))
(λ pa, classical.by_cases
(λ nnb : nonneg (-b), or.inr (nonneg_antisymm nb nnb))
(λ pb, absurd z $ ne_of_gt $ pos_def.1 $ mul_pos
((pos_iff _).2 ⟨na, pa⟩)
((pos_iff _).2 ⟨nb, pb⟩))),
..‹nontrivial α›,
..‹nonneg_ring α› }
end nonneg_ring
namespace linear_nonneg_ring
open nonneg_add_comm_group
variable [linear_nonneg_ring α]
@[priority 100] -- see Note [lower instance priority]
instance to_nonneg_ring : nonneg_ring α :=
{ one_nonneg := ((pos_iff _).mp one_pos).1,
mul_pos := λ a b pa pb,
let ⟨a1, a2⟩ := (pos_iff a).1 pa,
⟨b1, b2⟩ := (pos_iff b).1 pb in
have ab : nonneg (a * b), from mul_nonneg a1 b1,
(pos_iff _).2 ⟨ab, λ hn,
have a * b = 0, from nonneg_antisymm ab hn,
(eq_zero_or_eq_zero_of_mul_eq_zero _ _ this).elim
(ne_of_gt (pos_def.1 pa))
(ne_of_gt (pos_def.1 pb))⟩,
..‹linear_nonneg_ring α› }
/-- Construct `linear_order` from `linear_nonneg_ring`. This is not an instance
because we don't use it in `mathlib`. -/
local attribute [instance]
def to_linear_order [decidable_pred (nonneg : α → Prop)] : linear_order α :=
{ le_total := nonneg_total_iff.1 nonneg_total,
decidable_le := by apply_instance,
decidable_lt := by apply_instance,
..‹linear_nonneg_ring α›, ..(infer_instance : ordered_add_comm_group α) }
/-- Construct `linear_ordered_ring` from `linear_nonneg_ring`.
This is not an instance because we don't use it in `mathlib`. -/
local attribute [instance]
def to_linear_ordered_ring [decidable_pred (nonneg : α → Prop)] : linear_ordered_ring α :=
{ mul_pos := by simp [pos_def.symm]; exact @nonneg_ring.mul_pos _ _,
zero_le_one := le_of_lt $ lt_of_not_ge $ λ (h : nonneg (0 - 1)), begin
rw [zero_sub] at h,
have := mul_nonneg h h, simp at this,
exact zero_ne_one (nonneg_antisymm this h).symm
end,
..‹linear_nonneg_ring α›, ..(infer_instance : ordered_add_comm_group α),
..(infer_instance : linear_order α) }
/-- Convert a `linear_nonneg_ring` with a commutative multiplication and
decidable non-negativity into a `linear_ordered_comm_ring` -/
def to_linear_ordered_comm_ring
[decidable_pred (@nonneg α _)]
[comm : @is_commutative α (*)]
: linear_ordered_comm_ring α :=
{ mul_comm := is_commutative.comm,
..@linear_nonneg_ring.to_linear_ordered_ring _ _ _ }
end linear_nonneg_ring
/-- A canonically ordered commutative semiring is an ordered, commutative semiring
in which `a ≤ b` iff there exists `c` with `b = a + c`. This is satisfied by the
natural numbers, for example, but not the integers or other ordered groups. -/
@[protect_proj]
class canonically_ordered_comm_semiring (α : Type*) extends
canonically_ordered_add_monoid α, comm_semiring α :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0)
namespace canonically_ordered_semiring
variables [canonically_ordered_comm_semiring α] {a b : α}
open canonically_ordered_add_monoid (le_iff_exists_add)
@[priority 100] -- see Note [lower instance priority]
instance canonically_ordered_comm_semiring.to_no_zero_divisors :
no_zero_divisors α :=
⟨canonically_ordered_comm_semiring.eq_zero_or_eq_zero_of_mul_eq_zero⟩
lemma mul_le_mul {a b c d : α} (hab : a ≤ b) (hcd : c ≤ d) : a * c ≤ b * d :=
begin
rcases (le_iff_exists_add _ _).1 hab with ⟨b, rfl⟩,
rcases (le_iff_exists_add _ _).1 hcd with ⟨d, rfl⟩,
suffices : a * c ≤ a * c + (a * d + b * c + b * d), by simpa [mul_add, add_mul, add_assoc],
exact (le_iff_exists_add _ _).2 ⟨_, rfl⟩
end
lemma mul_le_mul_left' {b c : α} (h : b ≤ c) (a : α) : a * b ≤ a * c :=
mul_le_mul le_rfl h
lemma mul_le_mul_right' {b c : α} (h : b ≤ c) (a : α) : b * a ≤ c * a :=
mul_le_mul h le_rfl
/-- A version of `zero_lt_one : 0 < 1` for a `canonically_ordered_comm_semiring`. -/
lemma zero_lt_one [nontrivial α] : (0:α) < 1 := (zero_le 1).lt_of_ne zero_ne_one
lemma mul_pos : 0 < a * b ↔ (0 < a) ∧ (0 < b) :=
by simp only [pos_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib]
end canonically_ordered_semiring
namespace with_top
instance [nonempty α] : nontrivial (with_top α) :=
option.nontrivial
variable [decidable_eq α]
section has_mul
variables [has_zero α] [has_mul α]
instance : mul_zero_class (with_top α) :=
{ zero := 0,
mul := λm n, if m = 0 ∨ n = 0 then 0 else m.bind (λa, n.bind $ λb, ↑(a * b)),
zero_mul := assume a, if_pos $ or.inl rfl,
mul_zero := assume a, if_pos $ or.inr rfl }
lemma mul_def {a b : with_top α} :
a * b = if a = 0 ∨ b = 0 then 0 else a.bind (λa, b.bind $ λb, ↑(a * b)) := rfl
@[simp] lemma mul_top {a : with_top α} (h : a ≠ 0) : a * ⊤ = ⊤ :=
by cases a; simp [mul_def, h]; refl
@[simp] lemma top_mul {a : with_top α} (h : a ≠ 0) : ⊤ * a = ⊤ :=
by cases a; simp [mul_def, h]; refl
@[simp] lemma top_mul_top : (⊤ * ⊤ : with_top α) = ⊤ :=
top_mul top_ne_zero
end has_mul
section mul_zero_class
variables [mul_zero_class α]
@[norm_cast] lemma coe_mul {a b : α} : (↑(a * b) : with_top α) = a * b :=
decidable.by_cases (assume : a = 0, by simp [this]) $ assume ha,
decidable.by_cases (assume : b = 0, by simp [this]) $ assume hb,
by { simp [*, mul_def], refl }
lemma mul_coe {b : α} (hb : b ≠ 0) : ∀{a : with_top α}, a * b = a.bind (λa:α, ↑(a * b))
| none := show (if (⊤:with_top α) = 0 ∨ (b:with_top α) = 0 then 0 else ⊤ : with_top α) = ⊤,
by simp [hb]
| (some a) := show ↑a * ↑b = ↑(a * b), from coe_mul.symm
@[simp] lemma mul_eq_top_iff {a b : with_top α} : a * b = ⊤ ↔ (a ≠ 0 ∧ b = ⊤) ∨ (a = ⊤ ∧ b ≠ 0) :=
begin
cases a; cases b; simp only [none_eq_top, some_eq_coe],
{ simp [← coe_mul] },
{ suffices : ⊤ * (b : with_top α) = ⊤ ↔ b ≠ 0, by simpa,
by_cases hb : b = 0; simp [hb] },
{ suffices : (a : with_top α) * ⊤ = ⊤ ↔ a ≠ 0, by simpa,
by_cases ha : a = 0; simp [ha] },
{ simp [← coe_mul] }
end
end mul_zero_class
section no_zero_divisors
variables [mul_zero_class α] [no_zero_divisors α]
instance : no_zero_divisors (with_top α) :=
⟨λ a b, by cases a; cases b; dsimp [mul_def]; split_ifs;
simp [*, none_eq_top, some_eq_coe, mul_eq_zero] at *⟩
end no_zero_divisors
variables [canonically_ordered_comm_semiring α]
private lemma comm (a b : with_top α) : a * b = b * a :=
begin
by_cases ha : a = 0, { simp [ha] },
by_cases hb : b = 0, { simp [hb] },
simp [ha, hb, mul_def, option.bind_comm a b, mul_comm]
end
private lemma distrib' (a b c : with_top α) : (a + b) * c = a * c + b * c :=
begin
cases c,
{ show (a + b) * ⊤ = a * ⊤ + b * ⊤,
by_cases ha : a = 0; simp [ha] },
{ show (a + b) * c = a * c + b * c,
by_cases hc : c = 0, { simp [hc] },
simp [mul_coe hc], cases a; cases b,
repeat { refl <|> exact congr_arg some (add_mul _ _ _) } }
end
private lemma assoc (a b c : with_top α) : (a * b) * c = a * (b * c) :=
begin
cases a,
{ by_cases hb : b = 0; by_cases hc : c = 0;
simp [*, none_eq_top] },
cases b,
{ by_cases ha : a = 0; by_cases hc : c = 0;
simp [*, none_eq_top, some_eq_coe] },
cases c,
{ by_cases ha : a = 0; by_cases hb : b = 0;
simp [*, none_eq_top, some_eq_coe] },
simp [some_eq_coe, coe_mul.symm, mul_assoc]
end
-- `nontrivial α` is needed here as otherwise
-- we have `1 * ⊤ = ⊤` but also `= 0 * ⊤ = 0`.
private lemma one_mul' [nontrivial α] : ∀a : with_top α, 1 * a = a
| none := show ((1:α) : with_top α) * ⊤ = ⊤, by simp [-with_top.coe_one]
| (some a) := show ((1:α) : with_top α) * a = a, by simp [coe_mul.symm, -with_top.coe_one]
instance [nontrivial α] : canonically_ordered_comm_semiring (with_top α) :=
{ one := (1 : α),
right_distrib := distrib',
left_distrib := assume a b c, by rw [comm, distrib', comm b, comm c]; refl,
mul_assoc := assoc,
mul_comm := comm,
one_mul := one_mul',
mul_one := assume a, by rw [comm, one_mul'],
.. with_top.add_comm_monoid, .. with_top.mul_zero_class,
.. with_top.canonically_ordered_add_monoid,
.. with_top.no_zero_divisors, .. with_top.nontrivial }
lemma mul_lt_top [nontrivial α] {a b : with_top α} (ha : a < ⊤) (hb : b < ⊤) : a * b < ⊤ :=
begin
lift a to α using ne_top_of_lt ha,
lift b to α using ne_top_of_lt hb,
simp only [← coe_mul, coe_lt_top]
end
end with_top
|
ecdb8ad812b4fa9d3f1b80a943c4709ee8091021 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/group/type_tags.lean | 7fe91067dcb80544d4a9fb21b502076272c6e2ac | [
"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 | 12,205 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.group.hom
import data.equiv.basic
/-!
# Type tags that turn additive structures into multiplicative, and vice versa
We define two type tags:
* `additive α`: turns any multiplicative structure on `α` into the corresponding
additive structure on `additive α`;
* `multiplicative α`: turns any additive structure on `α` into the corresponding
multiplicative structure on `multiplicative α`.
We also define instances `additive.*` and `multiplicative.*` that actually transfer the structures.
-/
universes u v
variables {α : Type u} {β : Type v}
/-- If `α` carries some multiplicative structure, then `additive α` carries the corresponding
additive structure. -/
def additive (α : Type*) := α
/-- If `α` carries some additive structure, then `multiplicative α` carries the corresponding
multiplicative structure. -/
def multiplicative (α : Type*) := α
namespace additive
/-- Reinterpret `x : α` as an element of `additive α`. -/
def of_mul : α ≃ additive α := ⟨λ x, x, λ x, x, λ x, rfl, λ x, rfl⟩
/-- Reinterpret `x : additive α` as an element of `α`. -/
def to_mul : additive α ≃ α := of_mul.symm
@[simp] lemma of_mul_symm_eq : (@of_mul α).symm = to_mul := rfl
@[simp] lemma to_mul_symm_eq : (@to_mul α).symm = of_mul := rfl
end additive
namespace multiplicative
/-- Reinterpret `x : α` as an element of `multiplicative α`. -/
def of_add : α ≃ multiplicative α := ⟨λ x, x, λ x, x, λ x, rfl, λ x, rfl⟩
/-- Reinterpret `x : multiplicative α` as an element of `α`. -/
def to_add : multiplicative α ≃ α := of_add.symm
@[simp] lemma of_add_symm_eq : (@of_add α).symm = to_add := rfl
@[simp] lemma to_add_symm_eq : (@to_add α).symm = of_add := rfl
end multiplicative
@[simp] lemma to_add_of_add (x : α) : (multiplicative.of_add x).to_add = x := rfl
@[simp] lemma of_add_to_add (x : multiplicative α) : multiplicative.of_add x.to_add = x := rfl
@[simp] lemma to_mul_of_mul (x : α) : (additive.of_mul x).to_mul = x := rfl
@[simp] lemma of_mul_to_mul (x : additive α) : additive.of_mul x.to_mul = x := rfl
instance [inhabited α] : inhabited (additive α) := ⟨additive.of_mul (default α)⟩
instance [inhabited α] : inhabited (multiplicative α) := ⟨multiplicative.of_add (default α)⟩
instance [nontrivial α] : nontrivial (additive α) :=
additive.of_mul.injective.nontrivial
instance [nontrivial α] : nontrivial (multiplicative α) :=
multiplicative.of_add.injective.nontrivial
instance additive.has_add [has_mul α] : has_add (additive α) :=
{ add := λ x y, additive.of_mul (x.to_mul * y.to_mul) }
instance [has_add α] : has_mul (multiplicative α) :=
{ mul := λ x y, multiplicative.of_add (x.to_add + y.to_add) }
@[simp] lemma of_add_add [has_add α] (x y : α) :
multiplicative.of_add (x + y) = multiplicative.of_add x * multiplicative.of_add y :=
rfl
@[simp] lemma to_add_mul [has_add α] (x y : multiplicative α) :
(x * y).to_add = x.to_add + y.to_add :=
rfl
@[simp] lemma of_mul_mul [has_mul α] (x y : α) :
additive.of_mul (x * y) = additive.of_mul x + additive.of_mul y :=
rfl
@[simp] lemma to_mul_add [has_mul α] (x y : additive α) :
(x + y).to_mul = x.to_mul * y.to_mul :=
rfl
instance [semigroup α] : add_semigroup (additive α) :=
{ add_assoc := @mul_assoc α _,
..additive.has_add }
instance [add_semigroup α] : semigroup (multiplicative α) :=
{ mul_assoc := @add_assoc α _,
..multiplicative.has_mul }
instance [comm_semigroup α] : add_comm_semigroup (additive α) :=
{ add_comm := @mul_comm _ _,
..additive.add_semigroup }
instance [add_comm_semigroup α] : comm_semigroup (multiplicative α) :=
{ mul_comm := @add_comm _ _,
..multiplicative.semigroup }
instance [left_cancel_semigroup α] : add_left_cancel_semigroup (additive α) :=
{ add_left_cancel := @mul_left_cancel _ _,
..additive.add_semigroup }
instance [add_left_cancel_semigroup α] : left_cancel_semigroup (multiplicative α) :=
{ mul_left_cancel := @add_left_cancel _ _,
..multiplicative.semigroup }
instance [right_cancel_semigroup α] : add_right_cancel_semigroup (additive α) :=
{ add_right_cancel := @mul_right_cancel _ _,
..additive.add_semigroup }
instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicative α) :=
{ mul_right_cancel := @add_right_cancel _ _,
..multiplicative.semigroup }
instance [has_one α] : has_zero (additive α) := ⟨additive.of_mul 1⟩
@[simp] lemma of_mul_one [has_one α] : @additive.of_mul α 1 = 0 := rfl
@[simp] lemma of_mul_eq_zero {A : Type*} [has_one A] {x : A} :
additive.of_mul x = 0 ↔ x = 1 := iff.rfl
@[simp] lemma to_mul_zero [has_one α] : (0 : additive α).to_mul = 1 := rfl
instance [has_zero α] : has_one (multiplicative α) := ⟨multiplicative.of_add 0⟩
@[simp] lemma of_add_zero [has_zero α] : @multiplicative.of_add α 0 = 1 := rfl
@[simp] lemma of_add_eq_one {A : Type*} [has_zero A] {x : A} :
multiplicative.of_add x = 1 ↔ x = 0 := iff.rfl
@[simp] lemma to_add_one [has_zero α] : (1 : multiplicative α).to_add = 0 := rfl
instance [mul_one_class α] : add_zero_class (additive α) :=
{ zero := 0,
add := (+),
zero_add := one_mul,
add_zero := mul_one }
instance [add_zero_class α] : mul_one_class (multiplicative α) :=
{ one := 1,
mul := (*),
one_mul := zero_add,
mul_one := add_zero }
instance [h : monoid α] : add_monoid (additive α) :=
{ zero := 0,
add := (+),
nsmul := @monoid.npow α h,
nsmul_zero' := monoid.npow_zero',
nsmul_succ' := monoid.npow_succ',
..additive.add_zero_class,
..additive.add_semigroup }
instance [h : add_monoid α] : monoid (multiplicative α) :=
{ one := 1,
mul := (*),
npow := @add_monoid.nsmul α h,
npow_zero' := add_monoid.nsmul_zero',
npow_succ' := add_monoid.nsmul_succ',
..multiplicative.mul_one_class,
..multiplicative.semigroup }
instance [left_cancel_monoid α] : add_left_cancel_monoid (additive α) :=
{ .. additive.add_monoid, .. additive.add_left_cancel_semigroup }
instance [add_left_cancel_monoid α] : left_cancel_monoid (multiplicative α) :=
{ .. multiplicative.monoid, .. multiplicative.left_cancel_semigroup }
instance [right_cancel_monoid α] : add_right_cancel_monoid (additive α) :=
{ .. additive.add_monoid, .. additive.add_right_cancel_semigroup }
instance [add_right_cancel_monoid α] : right_cancel_monoid (multiplicative α) :=
{ .. multiplicative.monoid, .. multiplicative.right_cancel_semigroup }
instance [comm_monoid α] : add_comm_monoid (additive α) :=
{ .. additive.add_monoid, .. additive.add_comm_semigroup }
instance [add_comm_monoid α] : comm_monoid (multiplicative α) :=
{ ..multiplicative.monoid, .. multiplicative.comm_semigroup }
instance [has_inv α] : has_neg (additive α) := ⟨λ x, multiplicative.of_add x.to_mul⁻¹⟩
@[simp] lemma of_mul_inv [has_inv α] (x : α) : additive.of_mul x⁻¹ = -(additive.of_mul x) := rfl
@[simp] lemma to_mul_neg [has_inv α] (x : additive α) : (-x).to_mul = x.to_mul⁻¹ := rfl
instance [has_neg α] : has_inv (multiplicative α) := ⟨λ x, additive.of_mul (-x.to_add)⟩
@[simp] lemma of_add_neg [has_neg α] (x : α) :
multiplicative.of_add (-x) = (multiplicative.of_add x)⁻¹ := rfl
@[simp] lemma to_add_inv [has_neg α] (x : multiplicative α) :
(x⁻¹).to_add = -x.to_add := rfl
instance additive.has_sub [has_div α] : has_sub (additive α) :=
{ sub := λ x y, additive.of_mul (x.to_mul / y.to_mul) }
instance multiplicative.has_div [has_sub α] : has_div (multiplicative α) :=
{ div := λ x y, multiplicative.of_add (x.to_add - y.to_add) }
@[simp] lemma of_add_sub [has_sub α] (x y : α) :
multiplicative.of_add (x - y) = multiplicative.of_add x / multiplicative.of_add y :=
rfl
@[simp] lemma to_add_div [has_sub α] (x y : multiplicative α) :
(x / y).to_add = x.to_add - y.to_add :=
rfl
@[simp] lemma of_mul_div [has_div α] (x y : α) :
additive.of_mul (x / y) = additive.of_mul x - additive.of_mul y :=
rfl
@[simp] lemma to_mul_sub [has_div α] (x y : additive α) :
(x - y).to_mul = x.to_mul / y.to_mul :=
rfl
instance [div_inv_monoid α] : sub_neg_monoid (additive α) :=
{ sub_eq_add_neg := @div_eq_mul_inv α _,
zsmul := @div_inv_monoid.zpow α _,
zsmul_zero' := div_inv_monoid.zpow_zero',
zsmul_succ' := div_inv_monoid.zpow_succ',
zsmul_neg' := div_inv_monoid.zpow_neg',
.. additive.has_neg, .. additive.has_sub, .. additive.add_monoid }
instance [sub_neg_monoid α] : div_inv_monoid (multiplicative α) :=
{ div_eq_mul_inv := @sub_eq_add_neg α _,
zpow := @sub_neg_monoid.zsmul α _,
zpow_zero' := sub_neg_monoid.zsmul_zero',
zpow_succ' := sub_neg_monoid.zsmul_succ',
zpow_neg' := sub_neg_monoid.zsmul_neg',
.. multiplicative.has_inv, .. multiplicative.has_div, .. multiplicative.monoid }
instance [group α] : add_group (additive α) :=
{ add_left_neg := @mul_left_inv α _,
.. additive.sub_neg_monoid }
instance [add_group α] : group (multiplicative α) :=
{ mul_left_inv := @add_left_neg α _,
.. multiplicative.div_inv_monoid }
instance [comm_group α] : add_comm_group (additive α) :=
{ .. additive.add_group, .. additive.add_comm_monoid }
instance [add_comm_group α] : comm_group (multiplicative α) :=
{ .. multiplicative.group, .. multiplicative.comm_monoid }
/-- Reinterpret `α →+ β` as `multiplicative α →* multiplicative β`. -/
def add_monoid_hom.to_multiplicative [add_zero_class α] [add_zero_class β] :
(α →+ β) ≃ (multiplicative α →* multiplicative β) :=
⟨λ f, ⟨f.1, f.2, f.3⟩, λ f, ⟨f.1, f.2, f.3⟩, λ x, by { ext, refl, }, λ x, by { ext, refl, }⟩
/-- Reinterpret `α →* β` as `additive α →+ additive β`. -/
def monoid_hom.to_additive [mul_one_class α] [mul_one_class β] :
(α →* β) ≃ (additive α →+ additive β) :=
⟨λ f, ⟨f.1, f.2, f.3⟩, λ f, ⟨f.1, f.2, f.3⟩, λ x, by { ext, refl, }, λ x, by { ext, refl, }⟩
/-- Reinterpret `additive α →+ β` as `α →* multiplicative β`. -/
def add_monoid_hom.to_multiplicative' [mul_one_class α] [add_zero_class β] :
(additive α →+ β) ≃ (α →* multiplicative β) :=
⟨λ f, ⟨f.1, f.2, f.3⟩, λ f, ⟨f.1, f.2, f.3⟩, λ x, by { ext, refl, }, λ x, by { ext, refl, }⟩
/-- Reinterpret `α →* multiplicative β` as `additive α →+ β`. -/
def monoid_hom.to_additive' [mul_one_class α] [add_zero_class β] :
(α →* multiplicative β) ≃ (additive α →+ β) :=
add_monoid_hom.to_multiplicative'.symm
/-- Reinterpret `α →+ additive β` as `multiplicative α →* β`. -/
def add_monoid_hom.to_multiplicative'' [add_zero_class α] [mul_one_class β] :
(α →+ additive β) ≃ (multiplicative α →* β) :=
⟨λ f, ⟨f.1, f.2, f.3⟩, λ f, ⟨f.1, f.2, f.3⟩, λ x, by { ext, refl, }, λ x, by { ext, refl, }⟩
/-- Reinterpret `multiplicative α →* β` as `α →+ additive β`. -/
def monoid_hom.to_additive'' [add_zero_class α] [mul_one_class β] :
(multiplicative α →* β) ≃ (α →+ additive β) :=
add_monoid_hom.to_multiplicative''.symm
/-- If `α` has some multiplicative structure and coerces to a function,
then `additive α` should also coerce to the same function.
This allows `additive` to be used on bundled function types with a multiplicative structure, which
is often used for composition, without affecting the behavior of the function itself.
-/
instance additive.has_coe_to_fun {α : Type*} {β : α → Sort*} [has_coe_to_fun α β] :
has_coe_to_fun (additive α) (λ a, β a.to_mul) :=
⟨λ a, coe_fn a.to_mul⟩
/-- If `α` has some additive structure and coerces to a function,
then `multiplicative α` should also coerce to the same function.
This allows `multiplicative` to be used on bundled function types with an additive structure, which
is often used for composition, without affecting the behavior of the function itself.
-/
instance multiplicative.has_coe_to_fun {α : Type*} {β : α → Sort*} [has_coe_to_fun α β] :
has_coe_to_fun (multiplicative α) (λ a, β a.to_add) :=
⟨λ a, coe_fn a.to_add⟩
|
6be4347a351ea8db8ad5c71b6ee49c91e75e839d | a76f677b87d42a9470ba3a0a78cfddd3063118e6 | /src/exercise.lean | 28f6351688ee2f040e60d5a2d735ea710eb83d84 | [] | no_license | Ja1941/hilberts-axioms | 50219c732ad5fa167408432e8c8baae259777a40 | 5b653a92e448b77da41c9893066b641bc4e6b316 | refs/heads/master | 1,693,238,884,856 | 1,635,702,120,000 | 1,635,702,120,000 | 385,546,384 | 9 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 2,693 | lean | /-Some geometry exercises I did during high school
I will be gradually adding more of them here -/
import congruence.Elements
open incidence_geometry incidence_order_geometry hilbert_plane
variables [C : hilbert_plane]
include C
example {a b c d e f : pts} (habc : noncol a b c) (hd : midpt d (b-ₛc)) (haed : between a e d)
(hbef : between b e f) (hafc : between a f c) (hbeac : (b-ₛe) ≅ₛ (a-ₛc)) : (a-ₛf) ≅ₛ (e-ₛf) :=
begin
rw midpt_two_pt at hd,
have hbd := (between_neq hd.1).1,
have hcd := (between_neq hd.1).2.2.symm,
have hbda := col_noncol (col23 (between_col hd.1)) (noncol123 habc) hbd,
have hcda := col_noncol (col132 (between_col hd.1)) (noncol13 habc) hcd,
have hda := (noncol_neq hcda).2.2,
rcases extend_congr_seg' (seg_proper_iff_neq.2 hda) hda with ⟨g, hadg, hdadg, -⟩,
rw ←between_diff_side_pt at hadg,
have hdg := (between_neq hadg).2.2,
rw [seg_symm, seg_symm e f],
have haf := (between_neq hafc).1,
have hae := (between_neq haed).1,
have haec := col_noncol (col23 (between_col haed)) (noncol13 hcda) hae,
have hafe := col_noncol (col23 (between_col hafc)) (noncol23 haec) haf,
have hdgb := col_noncol (col12 (between_col hadg)) (noncol123 hbda) hdg,
apply isosceles' (noncol12 hafe),
have : ((Δ d a c) ≅ₜ (Δ d g b)),
apply SAS; unfold three_pt_triang; simp,
exact noncol123 hcda, exact hdgb,
exact hdadg,
rw [seg_symm, seg_symm d b], exact seg_congr_symm hd.2,
{ apply vertical_ang_congr (noncol13 hcda) hadg,
rw between_symm, exact hd.1 },
rw [ang_symm, ang_eq_same_side_pt e (between_same_side_pt.1 hafc).1, ang_symm,
ang_eq_same_side_pt c (between_same_side_pt.1 haed).1, ang_symm],
apply ang_congr_trans (tri_congr_ang this).1,
rw between_symm at haed hadg,
have hgde := (between_trans' hadg haed).1,
have hge := (between_neq hgde).2.1,
have hgeb := col_noncol (between_col hgde) (noncol12 hdgb) hge,
rw [ang_symm, ang_eq_same_side_pt b (between_same_side_pt.1 hgde).1],
apply ang_congr_trans,
{ apply isosceles (noncol132 hgeb),
rw seg_symm,
exact seg_congr_trans (seg_congr_symm (tri_congr_seg this).2.2) (seg_congr_symm hbeac) },
exact vertical_ang_congr (noncol13 hgeb) hbef (between_trans' hadg haed).2
end
example {a b c p d e f q : pts} (habc : noncol a b c) (hdef : noncol d e f) (hbpc : col b p c)
(heqf : col e q f) (hapb : is_right_ang (∠ a p b)) (hdqe : is_right_ang (∠ d q e))
(habde : (a-ₛb) ≅ₛ (d-ₛe)) (hacdf : (a-ₛc) ≅ₛ (d-ₛf)) (hapdq : (a-ₛp) ≅ₛ (d-ₛq)) :
((∠ a b c) ≅ₐ (∠ d e f)) ∨ ∃ α : ang, ((α ≅ₐ (∠ a b c)) ∧ supplementary α (∠ d e f)) :=
begin
sorry
end
|
cd2804c810256810c3849180baf317164a36a516 | df561f413cfe0a88b1056655515399c546ff32a5 | /3-function-world/l3.lean | da1496ac60efcd08134c916326d18b957c0be331 | [] | no_license | nicholaspun/natural-number-game-solutions | 31d5158415c6f582694680044c5c6469032c2a06 | 1e2aed86d2e76a3f4a275c6d99e795ad30cf6df0 | refs/heads/main | 1,675,123,625,012 | 1,607,633,548,000 | 1,607,633,548,000 | 318,933,860 | 3 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 191 | lean | example (P Q R S T U: Type)
(p : P)
(h : P → Q)
(i : Q → R)
(j : Q → T)
(k : S → T)
(l : T → U)
: U :=
begin
have q : Q := h(p),
have t : T := j(q),
have u : U := l(t),
exact u,
end |
b1faa0c786317f88973b1f91fc65512564298e42 | 5f83eb0c32f15aeed5993a3ad5ededb6f31fe7aa | /lean/src/jit.lean | 187dcffa821c68feadcb1abedffa38757d57ad10 | [] | no_license | uw-unsat/jitterbug | 45b54979b156c0f5330012313052f8594abd6f14 | 78d1e75ad506498b585fbac66985ff9d9d05952d | refs/heads/master | 1,689,066,921,433 | 1,687,061,448,000 | 1,688,415,161,000 | 244,440,882 | 46 | 5 | null | null | null | null | UTF-8 | Lean | false | false | 27,466 | lean |
import tactic.tauto
/-!
This file contains the metatheory of JIT correctness.
The main theorem is interpreter_equivalence, proved based on the following two sets of axioms.
Two axioms are assumed to be correct (e.g., ensured by the Linux kernel):
* ctx_correctness: the JIT computes a correct JIT context for the source program
* layout_consistency: the output of the JIT contains the output of individual parts.
Three axioms about the correctness of individal parts of the JIT are expected
to be proved separately in SMT:
* prologue_correct: running the emitted prologue from the initial target state reaches a target
state that relates to the initial source state.
* per_insn_correct: running the emitted target code preserves the relation between source and
target states and produces the same trace.
* epilogue_correct: running the emitted epilogue from a target state that relates to the final
source state reaches the final target state.
## References
* Xavier Leroy. A formally verified compiler back-end. Journal of Automated
Reasoning, 43(4):363--446, December 2009.
-/
namespace machine
section machine
parameters {CONTEXT EVENT ORACLE INPUT OUTPUT PC STATE INSN : Type}
-- A trace is a list of externally visible events.
definition TRACE : Type := list EVENT
instance : has_append TRACE := ⟨list.append⟩
-- Get program counter of machine.
parameter pc_of : STATE → PC
-- Step a given instruction, producing new state and trace.
parameter step_insn : ORACLE → INSN → STATE → option (STATE × TRACE)
-- Code is a partial map from PC to instruction. We intentionally avoid
-- using a list and favor this more abstract representation.
definition CODE : Type := PC → option INSN
-- Whether the state is an inital state.
parameter initial : STATE → CONTEXT → INPUT → Prop
-- Whether the state is a final state.
parameter final : STATE → OUTPUT → Prop
inductive step (nd : ORACLE) (code : CODE) (σ : STATE) : STATE → TRACE → Prop
-- Can take a step if there exists an instruction to execute and the state is not final.
| step_one :
∀ (insn : INSN) (σ' : STATE) (tr : TRACE),
code (pc_of σ) = some insn →
step_insn nd insn σ = some (σ', tr) →
(¬ ∃ (r : OUTPUT), final σ r) →
step σ' tr
-- Final states step to themselves.
| step_final :
∀ (o : OUTPUT),
final σ o →
step σ []
-- Step behaves like a function.
lemma step_deterministic :
∀ (nd : ORACLE) (code : CODE) (s s1' s2' : STATE) (tr1 tr2 : TRACE),
step nd code s s1' tr1 →
step nd code s s2' tr2 →
(s1' = s2' ∧ tr1 = tr2) :=
begin
intros _ _ _ _ _ _ _ S1 S2,
cases S1 with S1_insn B C S1_code S1_dostep S1_notfinal S1_r S2_final;
cases S2 with S2_insn J K S2_code S2_dostep S2_notfinal S2_r S2_final,
{ rw S1_code at *,
cases S2_code,
rw S1_dostep at *,
cases S2_dostep, by tauto,
},
{ exfalso, apply S1_notfinal,
existsi S2_r, by assumption,
},
{ exfalso, apply S2_notfinal,
existsi S1_r, by assumption,
},
{ by tauto, },
end
-- A standard way to define reachable states.
inductive star (nd : ORACLE) (code : CODE) : STATE → STATE → TRACE → Prop
| refl :
∀ (a : STATE),
star a a []
| step :
∀ (a b c : STATE) (tr₁ tr₂ : TRACE),
step nd code a b tr₁ →
star b c tr₂ →
star a c (tr₁ ++ tr₂)
-- A safe state can always fetch an instruction from any reachable state,
-- or it's the final state
definition safe (nd : ORACLE) (code : CODE) (σ : STATE) : Prop :=
∀ (σ' : STATE) (tr : TRACE),
star nd code σ σ' tr →
(∃ (insn : INSN), code (pc_of σ') = some insn) ∨ (∃ (o : OUTPUT), final σ' o)
-- If you can take one step, you can show star.
lemma star_one :
∀ (nd : ORACLE) (code : CODE) (a b : STATE) (tr : TRACE),
step nd code a b tr →
star nd code a b tr :=
begin
intros,
rw ← list.append_nil tr,
constructor,
{ assumption },
{ constructor }
end
-- Star is transitive for fixed code and appending traces.
lemma star_trans :
∀ (nd : ORACLE) (code : CODE) (a b : STATE) (tr₁ : TRACE),
star nd code a b tr₁ →
∀ (c : STATE) (tr₂ : TRACE),
star nd code b c tr₂ →
star nd code a c (tr₁ ++ tr₂) :=
begin
intros nd code _ _ _ Hab,
induction Hab with _ _ _ _ _ _ _ _ Hab_ih; intros; simp,
{ assumption },
{ constructor,
{ assumption },
{ apply Hab_ih,
assumption } }
end
-- c1 is a subset of c2 if any instruction c1 has is also in c2.
definition subset (c1 c2 : CODE) : Prop :=
∀ (idx : PC) (insn : INSN),
c1 idx = some insn →
c2 idx = some insn
local infix ` ⊆+ `:50 := subset
lemma step_subset :
∀ (nd : ORACLE) (code₁ code₂ : CODE) (s1 s2 : STATE) (tr : TRACE),
step nd code₁ s1 s2 tr →
code₁ ⊆+ code₂ →
step nd code₂ s1 s2 tr :=
begin
intros _ _ _ _ _ _ H1 H2,
cases H1 with H1_insn _ _ H1_a H1_a_1 H1_a_2 _ H1_a,
{ apply step.step_one,
apply H2,
from H1_a,
by assumption,
by assumption },
{ apply step.step_final,
from H1_a }
end
-- If you can star given some code, you can always
-- add more code and preserve star.
lemma star_subset :
∀ (nd : ORACLE) (code₁ code₂ : CODE) (s1 s2 : STATE) (tr : TRACE),
star nd code₁ s1 s2 tr →
code₁ ⊆+ code₂ →
star nd code₂ s1 s2 tr :=
begin
intros _ _ _ _ _ _ H1 _,
induction H1,
{ apply star.refl, },
econstructor,
{ apply step_subset, all_goals {assumption}, },
assumption,
end
lemma final_step :
∀ (nd : ORACLE) (s : STATE) (c : CODE) (o : OUTPUT),
final s o →
∀ (s' : STATE) (tr : TRACE),
step nd c s s' tr →
tr = [] ∧ s' = s :=
begin
intros _ _ _ _ h1 _ _ h2,
cases h2 with _ _ _ h2_a h2_a_1 h2_a_2 _ h2_a,
{ exfalso, apply h2_a_2,
existsi o, by assumption },
{ cc }
end
lemma final_star :
∀ (nd : ORACLE) (s : STATE) (c : CODE) (o : OUTPUT),
final s o →
∀ (s' : STATE) (tr : TRACE),
star nd c s s' tr →
(tr = [] ∧ s' = s) :=
begin
intros _ _ _ _ h1 _ _ h2,
induction h2 with s2 s1 s2 s3 tr1 tr2 h3 h4 IH, cc,
have : tr1 = [] ∧ s2 = s1,
by { apply final_step; assumption <|> skip, from h1 },
cases this, subst this_left, subst this_right, simp, cc,
end
-- A final state is always safe.
lemma final_safe :
∀ (nd : ORACLE) (code : CODE) (s : STATE) (o : OUTPUT),
final s o →
safe nd code s :=
begin
dsimp [safe, machine.safe], intros _ _ _ _ a _ _ a_1, right,
induction a_1 with _ _ _ _ _ _ a_1_a a_1_a_1,
{ existsi o, by assumption },
{ apply a_1_ih,
cases a_1_a with _ _ _ a_1_a_a a_1_a_a_1 a_1_a_a_2 _ a_1_a_a,
{ exfalso, apply a_1_a_a_2,
existsi o,
assumption },
{ assumption } }
end
-- A safe state can always take a step if it's not final.
lemma safe_self :
∀ (nd : ORACLE) (code : CODE) (s : STATE),
safe nd code s →
(¬ ∃ (o : OUTPUT), final s o) →
∃ (insn : INSN),
code (pc_of s) = some insn :=
begin
intros _ _ _ a a_1,
dsimp [safe] at *,
specialize a s [] (by constructor),
cases a with insn a,
by assumption,
cases a with res res_final,
exfalso, apply a_1, existsi res, by assumption,
end
-- A safe state is still safe after one step.
lemma safe_step :
∀ (nd : ORACLE) (code : CODE) (s₁ s₂ : STATE) (tr : TRACE),
safe nd code s₁ →
step nd code s₁ s₂ tr →
safe nd code s₂ :=
begin
intros _ _ _ _ _ H1 _,
simp [safe] at *,
intros _ _ _,
apply H1 _ (tr ++ tr_1),
constructor; assumption,
end
-- Safety is preserved across an arbitrary number of steps.
lemma safe_star :
∀ (nd : ORACLE) (code : CODE) (s₁ s₂ : STATE) (tr : TRACE),
safe nd code s₁ →
star nd code s₁ s₂ tr →
safe nd code s₂ :=
begin
intros _ _ _ _ _ a a_1,
induction a_1, by assumption,
apply a_1_ih,
apply safe_step; assumption,
end
-- If a state is safe, and it was obtained by taking a step,
-- then the state it stepped from is also safe.
lemma safe_step_backwards :
∀ (nd : ORACLE) (code : CODE) (s₁ s₂ : STATE) (tr : TRACE),
safe nd code s₂ →
step nd code s₁ s₂ tr →
safe nd code s₁ :=
begin
intros _ _ _ _ _ a a_1,
simp [safe] at *, intros _ _ a_2,
cases a_2 with _ _ _ _ _ _ a_2_a a_2_a_1,
{ cases a_1,
left, existsi a_1_insn, by assumption,
right, existsi a_1_o, by assumption },
{ apply a,
suffices h : a_2_b = s₂,
rw h at *,
{ rw h at *,
by assumption },
cases (step_deterministic _ _ _ _ code _ _ _ _ _ a_2_a a_1),
by assumption,
},
end
-- A state that eventually terminates is always safe.
lemma terminates_safe :
∀ (nd : ORACLE) (code : CODE) (s₁ s₂ : STATE) (tr : TRACE) (o : OUTPUT),
star nd code s₁ s₂ tr →
final s₂ o →
safe nd code s₁ :=
begin
intros _ _ _ _ _ _ a a_1,
induction a,
apply final_safe; assumption,
apply safe_step_backwards; try{assumption},
apply a_ih, assumption,
end
-- Holds if the code always terminates
definition always_terminates (code : CODE) : Prop :=
∀ (ctx : CONTEXT) (nd : ORACLE) (s : STATE) (i : INPUT),
initial s ctx i →
∃ (s' : STATE) (tr : TRACE) (o : OUTPUT),
star nd code s s' tr ∧
final s' o
-- A program which always terminates is same from the initial state.
lemma always_terminates_safe :
∀ (ctx : CONTEXT) (s : STATE) (code : CODE) (i : INPUT),
always_terminates code →
∀ (nd : ORACLE),
initial s ctx i →
safe nd code s :=
begin
intros _ _ _ _ a _ a_1,
dsimp [always_terminates] at *,
specialize a ctx nd s i a_1,
cases a with _ a,
cases a with _ a,
cases a with _ a,
cases a with _ a,
apply machine.terminates_safe; assumption,
end
end machine
end machine
-- Re-declare infix notation outside of machine scope.
local infix ` ⊆+ `:50 := machine.subset
constants CONTEXT EVENT ORACLE INPUT OUTPUT : Type
definition TRACE : Type := @machine.TRACE EVENT
noncomputable instance : has_append TRACE := ⟨list.append⟩
-- This models the behavior of the source language.
namespace source
constants INSN PC STATE : Type
constant pc_of : STATE → PC
constant step_insn : ORACLE → INSN → STATE → option (STATE × TRACE)
constant final : STATE → OUTPUT → Prop
constant initial : STATE → CONTEXT → INPUT → Prop
axiom initial_inhabited : ∀ (i : INPUT) (ctx : CONTEXT), ∃ (s : STATE), initial s ctx i
definition step := machine.step pc_of step_insn final
definition star := machine.star pc_of step_insn final
definition safe := machine.safe pc_of step_insn final
@[simp] definition always_terminates := machine.always_terminates pc_of step_insn initial final
definition CODE : Type := @machine.CODE PC INSN
-- This captures whether a JIT context is well-formed for a particular source BPF program.
constant wf : CONTEXT → CODE → Prop
end source
-- This models the behavior of the target language.
namespace target
constants INSN PC STATE : Type
constant pc_of : STATE → PC
constant step_insn : ORACLE → INSN → STATE → option (STATE × TRACE)
constant final : STATE → OUTPUT → Prop
definition CODE : Type := @machine.CODE PC INSN
constant initial : STATE → CONTEXT → INPUT → Prop
definition step := machine.step pc_of step_insn final
@[reducible] definition star := machine.star pc_of step_insn final
-- Whether the architectural invariants hold for some state
-- w.r.t an initial state
constant arch_safe : STATE → STATE → Prop
-- Inductive form of arch safety, depends on ctx.
constant arch_safe_inv : CONTEXT → STATE → STATE → Prop
-- The output of a final state is uniquely determined by the state.
axiom output_deterministic :
∀ (s : STATE) (o₁ o₂ : OUTPUT),
final s o₁ →
final s o₂ →
o₁ = o₂
end target
-- This models the JIT implementation.
namespace jit
-- Emit target code for a single source instruction.
constant emit_insn : CONTEXT → source.INSN → source.PC → option target.CODE
constant emit_prologue : CONTEXT → option target.CODE
constant emit_epilogue : CONTEXT → option target.CODE
-- Emit target code for an entire source program, including BPF checker, prologue, and epilogue.
constant compile : CONTEXT → source.CODE → option target.CODE
-- If the JIT suceeds for an entire source program,
-- it must have succeeded for each (valid) source instruction,
-- and the produced code must contain the prologue and epilogue.
--
-- This is assumed to hold.
axiom layout_consistency :
∀ (ctx : CONTEXT) (code_S : source.CODE) (code_T : target.CODE),
source.wf ctx code_S →
jit.compile ctx code_S = some code_T →
(∀ (i : source.PC) (insn : source.INSN),
code_S i = some insn →
∃ (frag_T : target.CODE),
jit.emit_insn ctx insn i = some frag_T ∧ frag_T ⊆+ code_T) ∧
(∃ (frag_T : target.CODE), jit.emit_prologue ctx = some frag_T ∧ frag_T ⊆+ code_T) ∧
(∃ (frag_T : target.CODE), jit.emit_epilogue ctx = some frag_T ∧ frag_T ⊆+ code_T)
end jit
-- JIT correctness
-- This relates source and target states, parameterized by a JIT context.
constant related : CONTEXT → source.STATE → target.STATE → Prop
notation s1 `~[`:50 ctx `]` s2:50 := related ctx s1 s2
-- Running the prologue from an initial state produces a target state related to the initial source
-- state (with no trace).
--
-- This is proved in SMT.
axiom prologue_correct :
∀ (nd : ORACLE) (ctx : CONTEXT) (σ_T : target.STATE) (σ_S : source.STATE) (i : INPUT)
(code_S : source.CODE) (code_T : target.CODE),
source.wf ctx code_S →
target.initial σ_T ctx i →
source.initial σ_S ctx i →
jit.emit_prologue ctx = some code_T →
∃ (σ_T' : target.STATE),
target.star nd code_T σ_T σ_T' [] ∧
σ_S ~[ctx] σ_T' ∧
target.arch_safe_inv ctx σ_T σ_T'
-- If the source state has reached a OUTPUT, then executing the epilogue in a related target state
-- reaches a state with the same OUTPUT (and no trace).
--
-- This is proved in SMT.
axiom epilogue_correct :
∀ (nd : ORACLE) (ctx : CONTEXT) (code_S : source.CODE) (code_T : target.CODE) (σ_S : source.STATE)
(init_T σ_T : target.STATE) (o : OUTPUT),
source.wf ctx code_S →
σ_S ~[ctx] σ_T →
target.arch_safe_inv ctx init_T σ_T →
source.final σ_S o →
jit.emit_epilogue ctx = some code_T →
∃ (σ_T' : target.STATE),
target.star nd code_T σ_T σ_T' [] ∧
target.final σ_T' o ∧
target.arch_safe init_T σ_T'
-- If the JIT produces some code for one source instruction, then starting from related source and
-- target states, stepping the source instruction is related to some state reachable from the
-- target state, for the jited code.
--
-- This is proved in SMT.
axiom per_insn_correct :
∀ (nd : ORACLE) (ctx : CONTEXT) (idx : source.PC) (code_S : source.CODE) (insn : source.INSN)
(frag_T : target.CODE) (σ_S σ_S' : source.STATE) (init_T σ_T : target.STATE) (tr : TRACE)
(code_T : target.CODE),
source.wf ctx code_S →
code_S idx = some insn →
jit.emit_insn ctx insn idx = some frag_T →
σ_S ~[ctx] σ_T →
target.arch_safe_inv ctx init_T σ_T →
source.pc_of σ_S = idx →
source.step nd code_S σ_S σ_S' tr →
∃ (σ_T' : target.STATE),
target.star nd frag_T σ_T σ_T' tr ∧ σ_S' ~[ctx] σ_T' ∧ target.arch_safe_inv ctx init_T σ_T'
lemma star_src_correct :
∀ (ctx : CONTEXT) (nd : ORACLE) (code_S : source.CODE) (σ_S σ_S' : source.STATE) (tr : TRACE),
source.wf ctx code_S →
source.safe nd code_S σ_S →
source.star nd code_S σ_S σ_S' tr →
∀ (init_T σ_T : target.STATE) (code_T : target.CODE),
σ_S ~[ctx] σ_T →
target.arch_safe_inv ctx init_T σ_T →
jit.compile ctx code_S = some code_T →
∃ (σ_T' : target.STATE),
target.star nd code_T σ_T σ_T' tr ∧
σ_S' ~[ctx] σ_T' ∧
target.arch_safe_inv ctx init_T σ_T' :=
begin
intros _ _ _ _ _ _ wf_S safe_S star_S,
induction star_S with s1 s1 s2 s3 tr1 tr2 step_S star_S' IH,
{ intros _ _ _ related archinv emitted,
existsi σ_T, split, constructor, split; assumption, },
intros _ _ _ related archinv emitted,
-- Handle the case where s1 is a final state. If it is, it steps to itself and
-- the target state can take zero steps.
cases step_S with insn _ _ code_at do_step not_final r is_final,
tactic.swap,
{ apply IH; assumption, },
have hemit : ∃ f_T, jit.emit_insn ctx insn (source.pc_of s1) = some f_T ∧ f_T ⊆+ code_T,
{
cases (jit.layout_consistency ctx code_S code_T wf_S emitted),
apply left; assumption,
},
cases hemit with f_T hemit,
cases hemit with hemit_left hemit_right,
have hstep_T : ∃ t2, target.star nd f_T σ_T t2 tr1 ∧ s2 ~[ctx] t2 ∧ target.arch_safe_inv ctx init_T t2,
{
apply per_insn_correct; try{assumption <|> reflexivity},
constructor; assumption,
},
cases hstep_T with t2 hstep_T,
cases hstep_T with hstep_T_left hstep_T_right,
have hstar_T : ∃ t3, target.star nd code_T t2 t3 tr2 ∧ s3 ~[ctx] t3 ∧ target.arch_safe_inv ctx init_T t3,
{
cases hstep_T_right,
apply IH; try{assumption},
apply machine.safe_step,
from safe_S,
constructor; assumption,
},
cases hstar_T with t3 hstar_T,
cases hstar_T with hstar_T_left hstar_T_right,
existsi t3,
split, tactic.swap, assumption,
apply machine.star_trans; try{assumption},
apply machine.star_subset; assumption,
end
-- The behavior of the source program is implemented by the jited target code.
theorem forward_simulation :
∀ (ctx : CONTEXT) (nd : ORACLE) (code_S : source.CODE) (σ_S σ_S' : source.STATE) (tr : TRACE) (i : INPUT)
(o : OUTPUT),
source.wf ctx code_S →
source.initial σ_S ctx i →
source.always_terminates code_S →
source.star nd code_S σ_S σ_S' tr →
source.final σ_S' o →
∀ (σ_T : target.STATE) (code_T : target.CODE),
target.initial σ_T ctx i →
jit.compile ctx code_S = some code_T →
∃ (σ_T' : target.STATE),
target.star nd code_T σ_T σ_T' tr ∧
target.final σ_T' o ∧
target.arch_safe σ_T σ_T' :=
begin
intros _ _ _ _ _ _ _ _ wf_S Hinitial_S terminates_S H2 H3 _ _ H4 H5,
-- Get the code to run in the target and show code_T is a superset of each component
cases (jit.layout_consistency ctx code_S code_T wf_S H5) with ec_insn ec,
cases ec with ec_prologue ec_epilogue,
cases ec_prologue with prologue prologue_subseteq,
cases prologue_subseteq with prologue_eq prologue_subseteq,
cases ec_epilogue with epilogue epilogue_subseteq,
cases epilogue_subseteq with epilogue_eq epilogue_subseteq,
-- Construct the prologue star
have hprologue : ∃ t2, target.star nd prologue σ_T t2 [] ∧
σ_S ~[ctx] t2 ∧ target.arch_safe_inv ctx σ_T t2,
{ apply prologue_correct; try{assumption},
},
cases hprologue with t2 hprologue,
cases hprologue,
-- construct the regular instr star using the lemma defined above
have hstar : ∃ t3, target.star nd code_T t2 t3 tr ∧ σ_S' ~[ctx] t3 ∧ target.arch_safe_inv ctx σ_T t3,
{
cases hprologue_right,
apply star_src_correct; try{assumption},
apply machine.always_terminates_safe; try{assumption},
},
cases hstar with t3 hstar,
cases hstar with hstar_left hstar_right,
-- construct the epilogue star
have hepilogue : ∃ t4, target.star nd epilogue t3 t4 [] ∧ target.final t4 o ∧ target.arch_safe σ_T t4,
{
cases hstar_right,
apply epilogue_correct; by assumption,
},
cases hepilogue with t4 hepilogue,
cases hepilogue,
-- Now we can glue all the steps together
existsi t4,
split, tactic.swap, split,
cases hepilogue_right with hepilogue_right regs_same,
by assumption,
cases hepilogue_right, by assumption,
-- Run the prologue
change tr with (list.nil ++ tr),
apply machine.star_trans,
{
apply machine.star_subset,
apply hprologue_left,
assumption,
},
-- Run the middle
rewrite ← list.append_nil tr,
apply machine.star_trans,
{
assumption,
},
-- Run the epilogue
apply machine.star_subset,
from hepilogue_left,
assumption,
end
lemma target_deterministic :
∀ (nd : ORACLE) (code : target.CODE) (σ σ'₁ : target.STATE) (tr₁ : TRACE) (o₁ : OUTPUT),
target.star nd code σ σ'₁ tr₁ →
target.final σ'₁ o₁ →
∀ (σ'₂ : target.STATE) (tr₂ : TRACE) (o₂ : OUTPUT),
target.star nd code σ σ'₂ tr₂ →
target.final σ'₂ o₂ →
(tr₁ = tr₂ ∧ σ'₁ = σ'₂ ∧ o₁ = o₂) :=
begin
intros _ _ _ _ _ _ h1 h2,
induction h1 with s' s' s'' s''' tr1 tr2 h1 h3 IH,
{ intros _ _ _ h4 h5,
have : tr₂ = [] ∧ σ'₂ = s',
{ apply machine.final_star, tactic.swap,
from h4,
from h2,
},
cases this,
rw this_right at *,
rw this_left at *,
have : o₁ = o₂, apply target.output_deterministic; try{assumption},
cc,
},
{ intros _ _ _ h4 h5,
cases h4 with _ _ _ h4_b h4_tr₁ h4_tr₂ h4_a h4_a_1,
{ have : tr1 = [] ∧ s'' = s',
by { apply machine.final_step, from h5, all_goals{assumption}},
cases this, subst this_left, subst this_right,
simp,
apply IH; tauto,
},
{ cases (machine.step_deterministic _ _ _ _ code _ _ _ _ _ h4_a h1),
rw left at *,
rw right at *,
suffices : tr2 = h4_tr₂ ∧ s''' = σ'₂ ∧ o₁ = o₂, by tauto,
apply IH; tauto,
} }
end
lemma source_target_deterministic :
∀ (ctx : CONTEXT) (nd : ORACLE) (code_S : source.CODE) (σ_S σ_S' : source.STATE) (tr_S : TRACE) (i : INPUT)
(o_S : OUTPUT),
source.wf ctx code_S →
source.initial σ_S ctx i →
source.always_terminates code_S →
source.star nd code_S σ_S σ_S' tr_S →
source.final σ_S' o_S →
∀ (code_T : target.CODE) (σ_T σ_T' : target.STATE) (tr_T : TRACE) (o_T : OUTPUT),
target.initial σ_T ctx i →
jit.compile ctx code_S = some code_T →
target.star nd code_T σ_T σ_T' tr_T →
target.final σ_T' o_T →
(tr_S = tr_T ∧ o_S = o_T ∧ target.arch_safe σ_T σ_T') :=
begin
intros _ _ _ _ _ _ _ _ wf_S HinitS Sterminates h1 h2 _ _ _ _ _ HinitT h3 h4 h5,
let x := forward_simulation,
specialize x ctx nd code_S σ_S σ_S' tr_S i o_S (by assumption)
(by assumption) (by assumption) (by assumption) (by assumption) σ_T code_T (by assumption)
(by assumption),
cases x with T H,
cases H with H1 H2,
cases H2,
suffices : tr_S = tr_T ∧ T = σ_T',
{ cases this with left right,
rw left at *,
rw right at *,
split, by reflexivity,
split; try{assumption},
apply target.output_deterministic; by assumption,
},
have : tr_S = tr_T ∧ T = σ_T' ∧ o_S = o_T, apply target_deterministic; assumption,
cc,
end
-- The behavior of the jited target code is allowed by the source program.
lemma backward_simulation :
∀ (ctx : CONTEXT) (code_S : source.CODE) (code_T : target.CODE) (nd : ORACLE) (σ_T σ_T' : target.STATE)
(σ_S : source.STATE) (tr : TRACE) (i : INPUT) (o : OUTPUT),
source.wf ctx code_S →
source.always_terminates code_S →
target.initial σ_T ctx i →
jit.compile ctx code_S = some code_T →
target.star nd code_T σ_T σ_T' tr →
target.final σ_T' o →
source.initial σ_S ctx i →
∃ (σ_S' : source.STATE),
source.star nd code_S σ_S σ_S' tr ∧
source.final σ_S' o ∧
target.arch_safe σ_T σ_T' :=
begin
intros _ _ _ _ _ _ _ _ _ _ wf_S terminates_S a a_1 a_2 a_3 a_4,
let y := terminates_S,
dsimp [source.always_terminates] at *,
specialize terminates_S ctx nd σ_S i a_4,
cases terminates_S with s' x,
cases x with tr' x,
cases x with res' H,
existsi s',
cases H,
suffices : tr' = tr ∧ res' = o ∧ target.arch_safe σ_T σ_T',
{ cases this with left right, rw left at *,
cases right with left right, rw left at *, rw right at *,
repeat{split <|> assumption},
},
apply source_target_deterministic; assumption,
end
theorem arch_safety :
∀ (ctx : CONTEXT) (nd : ORACLE) (code_S : source.CODE) (code_T : target.CODE) (σ_T σ_T' : target.STATE)
(i : INPUT) (o : OUTPUT) (tr : TRACE),
source.wf ctx code_S →
source.always_terminates code_S →
jit.compile ctx code_S = some code_T →
target.initial σ_T ctx i →
target.star nd code_T σ_T σ_T' tr →
target.final σ_T' o →
target.arch_safe σ_T σ_T' :=
begin
intros _ _ _ _ _ _ _ _ _ wf_S sterm comp tinit tstar tfinal,
let y := sterm,
dsimp [source.always_terminates, machine.always_terminates] at *,
specialize sterm ctx nd,
cases (source.initial_inhabited i ctx) with σ_S sinit,
specialize sterm σ_S i sinit,
cases sterm with σ_S' sterm,
cases sterm with tr2 sterm,
cases sterm with res2 sterm,
cases sterm with sstar sfinal,
cases (forward_simulation ctx nd code_S σ_S σ_S' tr2 i res2 wf_S sinit y sstar sfinal σ_T code_T tinit comp)
with σ_T2' forward,
cases forward,
cases forward_right,
have : tr = tr2 ∧ σ_T' = σ_T2' ∧ o = res2, apply target_deterministic; assumption,
cc,
end
theorem interpreter_equivalence :
∀ (ctx : CONTEXT) (nd : ORACLE) (code_S : source.CODE) (code_T : target.CODE) (σ_S : source.STATE)
(σ_T : target.STATE) (i : INPUT) (o : OUTPUT) (tr : TRACE),
source.wf ctx code_S →
source.always_terminates code_S →
jit.compile ctx code_S = some code_T →
source.initial σ_S ctx i →
target.initial σ_T ctx i →
((∃ (σ_S' : source.STATE),
source.star nd code_S σ_S σ_S' tr ∧
source.final σ_S' o)
↔
(∃ (σ_T' : target.STATE),
target.star nd code_T σ_T σ_T' tr ∧
target.final σ_T' o)) :=
begin
intros _ _ _ _ _ _ _ _ _ wf_S sterm comp inits initt,
split; intros a,
{ cases a with σ_S' a,
cases a with sstar sfinal,
cases (forward_simulation ctx nd code_S σ_S σ_S' tr i o _ _ _ sstar sfinal σ_T code_T _ _)
with σ_T' a,
cases a with tstar a,
cases a with tfinal tinv,
existsi σ_T', cc,
all_goals{assumption},
},
{ cases a with σ_T' a,
cases a with tstar tfinal,
cases (backward_simulation ctx code_S code_T nd σ_T σ_T' _ _ _ _ _ _ _ _ _ _ _) with σ_S' a; repeat{any_goals{assumption}},
cases a with sstar a,
cases a with sfinal inv,
existsi σ_S',
cc,
},
end
|
a83aa452a59412936989082ffb98ac5f96f0f73e | 618003631150032a5676f229d13a079ac875ff77 | /src/data/hash_map.lean | 11a252b8e634813a226942860a8603bbb6df6402 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 27,897 | 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, Mario Carneiro
-/
import data.pnat.basic
import data.array.lemmas
import algebra.group
import data.sigma.basic
universes u v w
/-- `bucket_array α β` is the underlying data type for `hash_map α β`,
an array of linked lists of key-value pairs. -/
def bucket_array (α : Type u) (β : α → Type v) (n : ℕ+) :=
array n.1 (list Σ a, β a)
/-- Make a hash_map index from a `nat` hash value and a (positive) buffer size -/
def hash_map.mk_idx (n : ℕ+) (i : nat) : fin n.1 :=
⟨i % n.1, nat.mod_lt _ n.2⟩
namespace bucket_array
section
parameters {α : Type u} {β : α → Type v} (hash_fn : α → nat)
variables {n : ℕ+} (data : bucket_array α β n)
instance : inhabited (bucket_array α β n) :=
⟨mk_array _ []⟩
/-- Read the bucket corresponding to an element -/
def read (a : α) : list Σ a, β a :=
let bidx := hash_map.mk_idx n (hash_fn a) in
data.read bidx
/-- Write the bucket corresponding to an element -/
def write (a : α) (l : list Σ a, β a) : bucket_array α β n :=
let bidx := hash_map.mk_idx n (hash_fn a) in
data.write bidx l
/-- Modify (read, apply `f`, and write) the bucket corresponding to an element -/
def modify (a : α) (f : list (Σ a, β a) → list (Σ a, β a)) : bucket_array α β n :=
let bidx := hash_map.mk_idx n (hash_fn a) in
array.write data bidx (f (array.read data bidx))
/-- The list of all key-value pairs in the bucket list -/
def as_list : list Σ a, β a := data.to_list.join
theorem mem_as_list {a : Σ a, β a} : a ∈ data.as_list ↔ ∃i, a ∈ array.read data i :=
have (∃ (l : list (Σ (a : α), β a)) (i : fin (n.val)), a ∈ l ∧ array.read data i = l) ↔
∃ (i : fin (n.val)), a ∈ array.read data i,
by rw exists_swap; exact exists_congr (λ i, by simp),
by simp [as_list]; simpa [array.mem.def, and_comm]
/-- Fold a function `f` over the key-value pairs in the bucket list -/
def foldl {δ : Type w} (d : δ) (f : δ → Π a, β a → δ) : δ :=
data.foldl d (λ b d, b.foldl (λ r a, f r a.1 a.2) d)
theorem foldl_eq {δ : Type w} (d : δ) (f : δ → Π a, β a → δ) :
data.foldl d f = data.as_list.foldl (λ r a, f r a.1 a.2) d :=
by rw [foldl, as_list, list.foldl_join, ← array.to_list_foldl]
end
end bucket_array
namespace hash_map
section
parameters {α : Type u} {β : α → Type v} (hash_fn : α → nat)
/-- Insert the pair `⟨a, b⟩` into the correct location in the bucket array
(without checking for duplication) -/
def reinsert_aux {n} (data : bucket_array α β n) (a : α) (b : β a) : bucket_array α β n :=
data.modify hash_fn a (λl, ⟨a, b⟩ :: l)
theorem mk_as_list (n : ℕ+) : bucket_array.as_list (mk_array n.1 [] : bucket_array α β n) = [] :=
list.eq_nil_iff_forall_not_mem.mpr $ λ x m,
let ⟨i, h⟩ := (bucket_array.mem_as_list _).1 m in h
parameter [decidable_eq α]
/-- Search a bucket for a key `a` and return the value -/
def find_aux (a : α) : list (Σ a, β a) → option (β a)
| [] := none
| (⟨a',b⟩::t) := if h : a' = a then some (eq.rec_on h b) else find_aux t
theorem find_aux_iff {a : α} {b : β a} :
Π {l : list Σ a, β a}, (l.map sigma.fst).nodup → (find_aux a l = some b ↔ sigma.mk a b ∈ l)
| [] nd := ⟨λn, by injection n, false.elim⟩
| (⟨a',b'⟩::t) nd := begin
by_cases a' = a,
{ clear find_aux_iff, subst h,
suffices : b' = b ↔ b' = b ∨ sigma.mk a' b ∈ t, {simpa [find_aux, eq_comm]},
refine (or_iff_left_of_imp (λ m, _)).symm,
have : a' ∉ t.map sigma.fst, from list.not_mem_of_nodup_cons nd,
exact this.elim (list.mem_map_of_mem sigma.fst m) },
{ have : sigma.mk a b ≠ ⟨a', b'⟩,
{ intro e, injection e with e, exact h e.symm },
simp at nd, simp [find_aux, h, ne.symm h, find_aux_iff, nd] }
end
/-- Returns `tt` if the bucket `l` contains the key `a` -/
def contains_aux (a : α) (l : list Σ a, β a) : bool :=
(find_aux a l).is_some
theorem contains_aux_iff {a : α} {l : list Σ a, β a} (nd : (l.map sigma.fst).nodup) :
contains_aux a l ↔ a ∈ l.map sigma.fst :=
begin
unfold contains_aux,
cases h : find_aux a l with b; simp,
{ assume (b : β a) (m : sigma.mk a b ∈ l),
rw (find_aux_iff nd).2 m at h,
contradiction },
{ show ∃ (b : β a), sigma.mk a b ∈ l,
exact ⟨_, (find_aux_iff nd).1 h⟩ },
end
/-- Modify a bucket to replace a value in the list. Leaves the list
unchanged if the key is not found. -/
def replace_aux (a : α) (b : β a) : list (Σ a, β a) → list (Σ a, β a)
| [] := []
| (⟨a', b'⟩::t) := if a' = a then ⟨a, b⟩::t else ⟨a', b'⟩ :: replace_aux t
/-- Modify a bucket to remove a key, if it exists. -/
def erase_aux (a : α) : list (Σ a, β a) → list (Σ a, β a)
| [] := []
| (⟨a', b'⟩::t) := if a' = a then t else ⟨a', b'⟩ :: erase_aux t
/-- The predicate `valid bkts sz` means that `bkts` satisfies the `hash_map`
invariants: There are exactly `sz` elements in it, every pair is in the
bucket determined by its key and the hash function, and no key appears
multiple times in the list. -/
structure valid {n} (bkts : bucket_array α β n) (sz : nat) : Prop :=
(len : bkts.as_list.length = sz)
(idx : ∀ {i} {a : Σ a, β a}, a ∈ array.read bkts i →
mk_idx n (hash_fn a.1) = i)
(nodup : ∀i, ((array.read bkts i).map sigma.fst).nodup)
theorem valid.idx_enum {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
{i l} (he : (i, l) ∈ bkts.to_list.enum) {a} {b : β a} (hl : sigma.mk a b ∈ l) :
∃ h, mk_idx n (hash_fn a) = ⟨i, h⟩ :=
(array.mem_to_list_enum.mp he).imp (λ h e, by subst e; exact v.idx hl)
theorem valid.idx_enum_1 {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
{i l} (he : (i, l) ∈ bkts.to_list.enum) {a} {b : β a} (hl : sigma.mk a b ∈ l) :
(mk_idx n (hash_fn a)).1 = i :=
let ⟨h, e⟩ := v.idx_enum _ he hl in by rw e; refl
theorem valid.as_list_nodup {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz) :
(bkts.as_list.map sigma.fst).nodup :=
begin
suffices : (bkts.to_list.map (list.map sigma.fst)).pairwise list.disjoint,
{ simp [bucket_array.as_list, list.nodup_join, this],
change ∀ l s, array.mem s bkts → list.map sigma.fst s = l → l.nodup,
introv m e, subst e, cases m with i e, subst e,
apply v.nodup },
rw [← list.enum_map_snd bkts.to_list, list.pairwise_map, list.pairwise_map],
have : (bkts.to_list.enum.map prod.fst).nodup := by simp [list.nodup_range],
refine list.pairwise.imp_of_mem _ ((list.pairwise_map _).1 this),
rw prod.forall, intros i l₁,
rw prod.forall, intros j l₂ me₁ me₂ ij,
simp [list.disjoint], intros a b ml₁ b' ml₂,
apply ij, rwa [← v.idx_enum_1 _ me₁ ml₁, ← v.idx_enum_1 _ me₂ ml₂]
end
theorem mk_valid (n : ℕ+) : @valid n (mk_array n.1 []) 0 :=
⟨by simp [mk_as_list], λ i a h, by cases h, λ i, list.nodup_nil⟩
theorem valid.find_aux_iff {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz) {a : α}
{b : β a} :
find_aux a (bkts.read hash_fn a) = some b ↔ sigma.mk a b ∈ bkts.as_list :=
(find_aux_iff (v.nodup _)).trans $
by rw bkts.mem_as_list; exact ⟨λ h, ⟨_, h⟩, λ ⟨i, h⟩, (v.idx h).symm ▸ h⟩
theorem valid.contains_aux_iff {n} {bkts : bucket_array α β n} {sz : nat} (v : valid bkts sz)
(a : α) :
contains_aux a (bkts.read hash_fn a) ↔ a ∈ bkts.as_list.map sigma.fst :=
by simp [contains_aux, option.is_some_iff_exists, v.find_aux_iff hash_fn]
section
parameters {n : ℕ+} {bkts : bucket_array α β n}
{bidx : fin n.1} {f : list (Σ a, β a) → list (Σ a, β a)}
(u v1 v2 w : list Σ a, β a)
local notation `L` := array.read bkts bidx
private def bkts' : bucket_array α β n := array.write bkts bidx (f L)
variables (hl : L = u ++ v1 ++ w)
(hfl : f L = u ++ v2 ++ w)
include hl hfl
theorem append_of_modify :
∃ u' w', bkts.as_list = u' ++ v1 ++ w' ∧ bkts'.as_list = u' ++ v2 ++ w' :=
begin
unfold bucket_array.as_list,
have h : bidx.1 < bkts.to_list.length, {simp [bidx.2]},
refine ⟨(bkts.to_list.take bidx.1).join ++ u, w ++ (bkts.to_list.drop (bidx.1+1)).join, _, _⟩,
{ conv { to_lhs,
rw [← list.take_append_drop bidx.1 bkts.to_list, list.drop_eq_nth_le_cons h],
simp [hl] }, simp },
{ conv { to_lhs,
rw [bkts', array.write_to_list, list.update_nth_eq_take_cons_drop _ h],
simp [hfl] }, simp }
end
variables (hvnd : (v2.map sigma.fst).nodup)
(hal : ∀ (a : Σ a, β a), a ∈ v2 → mk_idx n (hash_fn a.1) = bidx)
(djuv : (u.map sigma.fst).disjoint (v2.map sigma.fst))
(djwv : (w.map sigma.fst).disjoint (v2.map sigma.fst))
include hvnd hal djuv djwv
theorem valid.modify {sz : ℕ} (v : valid bkts sz) :
v1.length ≤ sz + v2.length ∧ valid bkts' (sz + v2.length - v1.length) :=
begin
rcases append_of_modify u v1 v2 w hl hfl with ⟨u', w', e₁, e₂⟩,
rw [← v.len, e₁],
suffices : valid bkts' (u' ++ v2 ++ w').length,
{ simpa [ge, add_comm, add_left_comm, nat.le_add_right, nat.add_sub_cancel_left] },
refine ⟨congr_arg _ e₂, λ i a, _, λ i, _⟩,
{ by_cases bidx = i,
{ subst i, rw [bkts', array.read_write, hfl],
have := @valid.idx _ _ _ v bidx a,
simp only [hl, list.mem_append, or_imp_distrib, forall_and_distrib] at this ⊢,
exact ⟨⟨this.1.1, hal _⟩, this.2⟩ },
{ rw [bkts', array.read_write_of_ne _ _ h], apply v.idx } },
{ by_cases bidx = i,
{ subst i, rw [bkts', array.read_write, hfl],
have := @valid.nodup _ _ _ v bidx,
simp [hl, list.nodup_append] at this,
simp [list.nodup_append, this, hvnd, djuv, djwv.symm] },
{ rw [bkts', array.read_write_of_ne _ _ h], apply v.nodup } }
end
end
theorem valid.replace_aux (a : α) (b : β a) : Π (l : list (Σ a, β a)), a ∈ l.map sigma.fst →
∃ (u w : list Σ a, β a) b', l = u ++ [⟨a, b'⟩] ++ w ∧ replace_aux a b l = u ++ [⟨a, b⟩] ++ w
| [] := false.elim
| (⟨a', b'⟩::t) := begin
by_cases e : a' = a,
{ subst a',
suffices : ∃ (u w : list Σ a, β a) (b'' : β a),
(sigma.mk a b') :: t = u ++ ⟨a, b''⟩ :: w ∧
replace_aux a b (⟨a, b'⟩ :: t) = u ++ ⟨a, b⟩ :: w, {simpa},
refine ⟨[], t, b', _⟩, simp [replace_aux] },
{ suffices : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (b'' : β a),
(sigma.mk a' b') :: t = u ++ ⟨a, b''⟩ :: w ∧
(sigma.mk a' b') :: (replace_aux a b t) = u ++ ⟨a, b⟩ :: w,
{ simpa [replace_aux, ne.symm e, e] },
intros x m,
have IH : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (b'' : β a),
t = u ++ ⟨a, b''⟩ :: w ∧ replace_aux a b t = u ++ ⟨a, b⟩ :: w,
{ simpa using valid.replace_aux t },
rcases IH x m with ⟨u, w, b'', hl, hfl⟩,
exact ⟨⟨a', b'⟩ :: u, w, b'', by simp [hl, hfl.symm, ne.symm e]⟩ }
end
theorem valid.replace {n : ℕ+}
{bkts : bucket_array α β n} {sz : ℕ} (a : α) (b : β a)
(Hc : contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (bkts.modify hash_fn a (replace_aux a b)) sz :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases hash_map.valid.replace_aux a b (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u, w, b', hl, hfl⟩,
simp [hl, list.nodup_append] at nd,
refine (v.modify hash_fn
u [⟨a, b'⟩] [⟨a, b⟩] w hl hfl (list.nodup_singleton _)
(λa' e, by simp at e; rw e)
(λa' e1 e2, _)
(λa' e1 e2, _)).2;
{ revert e1, simp [-sigma.exists] at e2, subst a', simp [nd] }
end
theorem valid.insert {n : ℕ+}
{bkts : bucket_array α β n} {sz : ℕ} (a : α) (b : β a)
(Hnc : ¬ contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (reinsert_aux bkts a b) (sz+1) :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
refine (v.modify hash_fn
[] [] [⟨a, b⟩] (bkts.read hash_fn a) rfl rfl (list.nodup_singleton _)
(λa' e, by simp at e; rw e)
(λa', false.elim)
(λa' e1 e2, _)).2,
simp [-sigma.exists] at e2, subst a',
exact Hnc ((contains_aux_iff nd).2 e1)
end
theorem valid.erase_aux (a : α) : Π (l : list (Σ a, β a)), a ∈ l.map sigma.fst →
∃ (u w : list Σ a, β a) b, l = u ++ [⟨a, b⟩] ++ w ∧ erase_aux a l = u ++ [] ++ w
| [] := false.elim
| (⟨a', b'⟩::t) := begin
by_cases e : a' = a,
{ subst a',
simpa [erase_aux, and_comm] using show ∃ u w (x : β a),
t = u ++ w ∧ (sigma.mk a b') :: t = u ++ ⟨a, x⟩ :: w,
from ⟨[], t, b', by simp⟩ },
{ simp [erase_aux, e, ne.symm e],
suffices : ∀ (b : β a) (_ : sigma.mk a b ∈ t), ∃ u w (x : β a),
(sigma.mk a' b') :: t = u ++ ⟨a, x⟩ :: w ∧
(sigma.mk a' b') :: (erase_aux a t) = u ++ w,
{ simpa [replace_aux, ne.symm e, e] },
intros b m,
have IH : ∀ (x : β a) (_ : sigma.mk a x ∈ t), ∃ u w (x : β a),
t = u ++ ⟨a, x⟩ :: w ∧ erase_aux a t = u ++ w,
{ simpa using valid.erase_aux t },
rcases IH b m with ⟨u, w, b'', hl, hfl⟩,
exact ⟨⟨a', b'⟩ :: u, w, b'', by simp [hl, hfl.symm]⟩ }
end
theorem valid.erase {n} {bkts : bucket_array α β n} {sz}
(a : α) (Hc : contains_aux a (bkts.read hash_fn a))
(v : valid bkts sz) : valid (bkts.modify hash_fn a (erase_aux a)) (sz-1) :=
begin
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases hash_map.valid.erase_aux a (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u, w, b, hl, hfl⟩,
refine (v.modify hash_fn u [⟨a, b⟩] [] w hl hfl list.nodup_nil _ _ _).2;
simp
end
end
end hash_map
/-- A hash map data structure, representing a finite key-value map
with key type `α` and value type `β` (which may depend on `α`). -/
structure hash_map (α : Type u) [decidable_eq α] (β : α → Type v) :=
(hash_fn : α → nat)
(size : ℕ)
(nbuckets : ℕ+)
(buckets : bucket_array α β nbuckets)
(is_valid : hash_map.valid hash_fn buckets size)
/-- Construct an empty hash map with buffer size `nbuckets` (default 8). -/
def mk_hash_map {α : Type u} [decidable_eq α] {β : α → Type v} (hash_fn : α → nat) (nbuckets := 8) :
hash_map α β :=
let n := if nbuckets = 0 then 8 else nbuckets in
let nz : n > 0 := by abstract { cases nbuckets; simp [if_pos, nat.succ_ne_zero] } in
{ hash_fn := hash_fn,
size := 0,
nbuckets := ⟨n, nz⟩,
buckets := mk_array n [],
is_valid := hash_map.mk_valid _ _ }
namespace hash_map
variables {α : Type u} {β : α → Type v} [decidable_eq α]
/-- Return the value corresponding to a key, or `none` if not found -/
def find (m : hash_map α β) (a : α) : option (β a) :=
find_aux a (m.buckets.read m.hash_fn a)
/-- Return `tt` if the key exists in the map -/
def contains (m : hash_map α β) (a : α) : bool :=
(m.find a).is_some
instance : has_mem α (hash_map α β) := ⟨λa m, m.contains a⟩
/-- Fold a function over the key-value pairs in the map -/
def fold {δ : Type w} (m : hash_map α β) (d : δ) (f : δ → Π a, β a → δ) : δ :=
m.buckets.foldl d f
/-- The list of key-value pairs in the map -/
def entries (m : hash_map α β) : list Σ a, β a :=
m.buckets.as_list
/-- The list of keys in the map -/
def keys (m : hash_map α β) : list α :=
m.entries.map sigma.fst
theorem find_iff (m : hash_map α β) (a : α) (b : β a) :
m.find a = some b ↔ sigma.mk a b ∈ m.entries :=
m.is_valid.find_aux_iff _
theorem contains_iff (m : hash_map α β) (a : α) :
m.contains a ↔ a ∈ m.keys :=
m.is_valid.contains_aux_iff _ _
theorem entries_empty (hash_fn : α → nat) (n) :
(@mk_hash_map α _ β hash_fn n).entries = [] :=
by dsimp [entries, mk_hash_map]; rw mk_as_list
theorem keys_empty (hash_fn : α → nat) (n) :
(@mk_hash_map α _ β hash_fn n).keys = [] :=
by dsimp [keys]; rw entries_empty; refl
theorem find_empty (hash_fn : α → nat) (n a) :
(@mk_hash_map α _ β hash_fn n).find a = none :=
by induction h : (@mk_hash_map α _ β hash_fn n).find a; [refl,
{ have := (find_iff _ _ _).1 h, rw entries_empty at this, contradiction }]
theorem not_contains_empty (hash_fn : α → nat) (n a) :
¬ (@mk_hash_map α _ β hash_fn n).contains a :=
by apply bool_iff_false.2; dsimp [contains]; rw [find_empty]; refl
theorem insert_lemma (hash_fn : α → nat) {n n'}
{bkts : bucket_array α β n} {sz} (v : valid hash_fn bkts sz) :
valid hash_fn (bkts.foldl (mk_array _ [] : bucket_array α β n') (reinsert_aux hash_fn)) sz :=
begin
suffices : ∀ (l : list Σ a, β a) (t : bucket_array α β n') sz,
valid hash_fn t sz → ((l ++ t.as_list).map sigma.fst).nodup →
valid hash_fn (l.foldl (λr (a : Σ a, β a), reinsert_aux hash_fn r a.1 a.2) t) (sz + l.length),
{ have p := this bkts.as_list _ _ (mk_valid _ _),
rw [mk_as_list, list.append_nil, zero_add, v.len] at p,
rw bucket_array.foldl_eq,
exact p (v.as_list_nodup _) },
intro l, induction l with c l IH; intros t sz v nd, {exact v},
rw show sz + (c :: l).length = sz + 1 + l.length, by simp [add_comm, add_assoc],
rcases (show (l.map sigma.fst).nodup ∧
((bucket_array.as_list t).map sigma.fst).nodup ∧
c.fst ∉ l.map sigma.fst ∧
c.fst ∉ (bucket_array.as_list t).map sigma.fst ∧
(l.map sigma.fst).disjoint ((bucket_array.as_list t).map sigma.fst),
by simpa [list.nodup_append, not_or_distrib, and_comm, and.left_comm] using nd)
with ⟨nd1, nd2, nm1, nm2, dj⟩,
have v' := v.insert _ _ c.2 (λHc, nm2 $ (v.contains_aux_iff _ c.1).1 Hc),
apply IH _ _ v',
suffices : ∀ ⦃a : α⦄ (b : β a), sigma.mk a b ∈ l →
∀ (b' : β a), sigma.mk a b' ∈ (reinsert_aux hash_fn t c.1 c.2).as_list → false,
{ simpa [list.nodup_append, nd1, v'.as_list_nodup _, list.disjoint] },
intros a b m1 b' m2,
rcases (reinsert_aux hash_fn t c.1 c.2).mem_as_list.1 m2 with ⟨i, im⟩,
have : sigma.mk a b' ∉ array.read t i,
{ intro m3,
have : a ∈ list.map sigma.fst t.as_list :=
list.mem_map_of_mem sigma.fst (t.mem_as_list.2 ⟨_, m3⟩),
exact dj (list.mem_map_of_mem sigma.fst m1) this },
by_cases h : mk_idx n' (hash_fn c.1) = i,
{ subst h,
have e : sigma.mk a b' = ⟨c.1, c.2⟩,
{ simpa [reinsert_aux, bucket_array.modify, array.read_write, this] using im },
injection e with e, subst a,
exact nm1.elim (@list.mem_map_of_mem _ _ sigma.fst _ _ m1) },
{ apply this,
simpa [reinsert_aux, bucket_array.modify, array.read_write_of_ne _ _ h] using im }
end
/-- Insert a key-value pair into the map. (Modifies `m` in-place when applicable) -/
def insert : Π (m : hash_map α β) (a : α) (b : β a), hash_map α β
| ⟨hash_fn, size, n, buckets, v⟩ a b :=
let bkt := buckets.read hash_fn a in
if hc : contains_aux a bkt then
{ hash_fn := hash_fn,
size := size,
nbuckets := n,
buckets := buckets.modify hash_fn a (replace_aux a b),
is_valid := v.replace _ a b hc }
else
let size' := size + 1,
buckets' := buckets.modify hash_fn a (λl, ⟨a, b⟩::l),
valid' := v.insert _ a b hc in
if size' ≤ n.1 then
{ hash_fn := hash_fn,
size := size',
nbuckets := n,
buckets := buckets',
is_valid := valid' }
else
let n' : ℕ+ := ⟨n.1 * 2, mul_pos n.2 dec_trivial⟩,
buckets'' : bucket_array α β n' :=
buckets'.foldl (mk_array _ []) (reinsert_aux hash_fn) in
{ hash_fn := hash_fn,
size := size',
nbuckets := n',
buckets := buckets'',
is_valid := insert_lemma _ valid' }
theorem mem_insert : Π (m : hash_map α β) (a b a' b'),
(sigma.mk a' b' : sigma β) ∈ (m.insert a b).entries ↔
if a = a' then b == b' else sigma.mk a' b' ∈ m.entries
| ⟨hash_fn, size, n, bkts, v⟩ a b a' b' := begin
let bkt := bkts.read hash_fn a,
have nd : (bkt.map sigma.fst).nodup := v.nodup (mk_idx n (hash_fn a)),
have lem : Π (bkts' : bucket_array α β n) (v1 u w)
(hl : bucket_array.as_list bkts = u ++ v1 ++ w)
(hfl : bucket_array.as_list bkts' = u ++ [⟨a, b⟩] ++ w)
(veq : (v1 = [] ∧ ¬ contains_aux a bkt) ∨ ∃b'', v1 = [⟨a, b''⟩]),
sigma.mk a' b' ∈ bkts'.as_list ↔
if a = a' then b == b' else sigma.mk a' b' ∈ bkts.as_list,
{ intros bkts' v1 u w hl hfl veq,
rw [hl, hfl],
by_cases h : a = a',
{ subst a',
suffices : b = b' ∨ sigma.mk a b' ∈ u ∨ sigma.mk a b' ∈ w ↔ b = b',
{ simpa [eq_comm, or.left_comm] },
refine or_iff_left_of_imp (not.elim $ not_or_distrib.2 _),
rcases veq with ⟨rfl, Hnc⟩ | ⟨b'', rfl⟩,
{ have na := (not_iff_not_of_iff $ v.contains_aux_iff _ _).1 Hnc,
simp [hl, not_or_distrib] at na, simp [na] },
{ have nd' := v.as_list_nodup _,
simp [hl, list.nodup_append] at nd', simp [nd'] } },
{ suffices : sigma.mk a' b' ∉ v1, {simp [h, ne.symm h, this]},
rcases veq with ⟨rfl, Hnc⟩ | ⟨b'', rfl⟩; simp [ne.symm h] } },
by_cases Hc : (contains_aux a bkt : Prop),
{ rcases hash_map.valid.replace_aux a b (array.read bkts (mk_idx n (hash_fn a)))
((contains_aux_iff nd).1 Hc) with ⟨u', w', b'', hl', hfl'⟩,
rcases (append_of_modify u' [⟨a, b''⟩] [⟨a, b⟩] w' hl' hfl') with ⟨u, w, hl, hfl⟩,
simpa [insert, @dif_pos (contains_aux a bkt) _ Hc]
using lem _ _ u w hl hfl (or.inr ⟨b'', rfl⟩) },
{ let size' := size + 1,
let bkts' := bkts.modify hash_fn a (λl, ⟨a, b⟩::l),
have mi : sigma.mk a' b' ∈ bkts'.as_list ↔
if a = a' then b == b' else sigma.mk a' b' ∈ bkts.as_list :=
let ⟨u, w, hl, hfl⟩ := append_of_modify [] [] [⟨a, b⟩] _ rfl rfl in
lem bkts' _ u w hl hfl $ or.inl ⟨rfl, Hc⟩,
simp [insert, @dif_neg (contains_aux a bkt) _ Hc],
by_cases h : size' ≤ n.1,
-- TODO(Mario): Why does the by_cases assumption look different than the stated one?
{ simpa [show size' ≤ n.1, from h] using mi },
{ let n' : ℕ+ := ⟨n.1 * 2, mul_pos n.2 dec_trivial⟩,
let bkts'' : bucket_array α β n' := bkts'.foldl (mk_array _ []) (reinsert_aux hash_fn),
suffices : sigma.mk a' b' ∈ bkts''.as_list ↔ sigma.mk a' b' ∈ bkts'.as_list.reverse,
{ simpa [show ¬ size' ≤ n.1, from h, mi] },
rw [show bkts'' = bkts'.as_list.foldl _ _, from bkts'.foldl_eq _ _,
← list.foldr_reverse],
induction bkts'.as_list.reverse with a l IH,
{ simp [mk_as_list] },
{ cases a with a'' b'',
let B := l.foldr (λ (y : sigma β) (x : bucket_array α β n'),
reinsert_aux hash_fn x y.1 y.2) (mk_array n'.1 []),
rcases append_of_modify [] [] [⟨a'', b''⟩] _ rfl rfl with ⟨u, w, hl, hfl⟩,
simp [IH.symm, or.left_comm, show B.as_list = _, from hl,
show (reinsert_aux hash_fn B a'' b'').as_list = _, from hfl] } } }
end
theorem find_insert_eq (m : hash_map α β) (a : α) (b : β a) : (m.insert a b).find a = some b :=
(find_iff (m.insert a b) a b).2 $ (mem_insert m a b a b).2 $ by rw if_pos rfl
theorem find_insert_ne (m : hash_map α β) (a a' : α) (b : β a) (h : a ≠ a') :
(m.insert a b).find a' = m.find a' :=
option.eq_of_eq_some $ λb',
let t := mem_insert m a b a' b' in
(find_iff _ _ _).trans $ iff.trans (by rwa if_neg h at t) (find_iff _ _ _).symm
theorem find_insert (m : hash_map α β) (a' a : α) (b : β a) :
(m.insert a b).find a' = if h : a = a' then some (eq.rec_on h b) else m.find a' :=
if h : a = a' then by rw dif_pos h; exact
match a', h with ._, rfl := find_insert_eq m a b end
else by rw dif_neg h; exact find_insert_ne m a a' b h
/-- Insert a list of key-value pairs into the map. (Modifies `m` in-place when applicable) -/
def insert_all (l : list (Σ a, β a)) (m : hash_map α β) : hash_map α β :=
l.foldl (λ m ⟨a, b⟩, insert m a b) m
/-- Construct a hash map from a list of key-value pairs. -/
def of_list (l : list (Σ a, β a)) (hash_fn) : hash_map α β :=
insert_all l (mk_hash_map hash_fn (2 * l.length))
/-- Remove a key from the map. (Modifies `m` in-place when applicable) -/
def erase (m : hash_map α β) (a : α) : hash_map α β :=
match m with ⟨hash_fn, size, n, buckets, v⟩ :=
if hc : contains_aux a (buckets.read hash_fn a) then
{ hash_fn := hash_fn,
size := size - 1,
nbuckets := n,
buckets := buckets.modify hash_fn a (erase_aux a),
is_valid := v.erase _ a hc }
else m
end
theorem mem_erase : Π (m : hash_map α β) (a a' b'),
(sigma.mk a' b' : sigma β) ∈ (m.erase a).entries ↔
a ≠ a' ∧ sigma.mk a' b' ∈ m.entries
| ⟨hash_fn, size, n, bkts, v⟩ a a' b' := begin
let bkt := bkts.read hash_fn a,
by_cases Hc : (contains_aux a bkt : Prop),
{ let bkts' := bkts.modify hash_fn a (erase_aux a),
suffices : sigma.mk a' b' ∈ bkts'.as_list ↔ a ≠ a' ∧ sigma.mk a' b' ∈ bkts.as_list,
{ simpa [erase, @dif_pos (contains_aux a bkt) _ Hc] },
have nd := v.nodup (mk_idx n (hash_fn a)),
rcases valid.erase_aux a bkt ((contains_aux_iff nd).1 Hc) with ⟨u', w', b, hl', hfl'⟩,
rcases append_of_modify u' [⟨a, b⟩] [] _ hl' hfl' with ⟨u, w, hl, hfl⟩,
suffices : ∀_:sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w, a ≠ a',
{ have : sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w ↔ (¬a = a' ∧ a' = a) ∧ b' == b ∨
¬a = a' ∧ (sigma.mk a' b' ∈ u ∨ sigma.mk a' b' ∈ w),
{ simp [eq_comm, not_and_self_iff, and_iff_right_of_imp this] },
simpa [hl, show bkts'.as_list = _, from hfl, and_or_distrib_left,
and_comm, and.left_comm, or.left_comm] },
intros m e, subst a', revert m, apply not_or_distrib.2,
have nd' := v.as_list_nodup _,
simp [hl, list.nodup_append] at nd', simp [nd'] },
{ suffices : ∀_:sigma.mk a' b' ∈ bucket_array.as_list bkts, a ≠ a',
{ simp [erase, @dif_neg (contains_aux a bkt) _ Hc, entries, and_iff_right_of_imp this] },
intros m e, subst a',
exact Hc ((v.contains_aux_iff _ _).2 (list.mem_map_of_mem sigma.fst m)) }
end
theorem find_erase_eq (m : hash_map α β) (a : α) : (m.erase a).find a = none :=
begin
cases h : (m.erase a).find a with b, {refl},
exact absurd rfl ((mem_erase m a a b).1 ((find_iff (m.erase a) a b).1 h)).left
end
theorem find_erase_ne (m : hash_map α β) (a a' : α) (h : a ≠ a') :
(m.erase a).find a' = m.find a' :=
option.eq_of_eq_some $ λb',
(find_iff _ _ _).trans $ (mem_erase m a a' b').trans $
(and_iff_right h).trans (find_iff _ _ _).symm
theorem find_erase (m : hash_map α β) (a' a : α) :
(m.erase a).find a' = if a = a' then none else m.find a' :=
if h : a = a' then by subst a'; simp [find_erase_eq m a]
else by rw if_neg h; exact find_erase_ne m a a' h
section string
variables [has_to_string α] [∀ a, has_to_string (β a)]
open prod
private def key_data_to_string (a : α) (b : β a) (first : bool) : string :=
(if first then "" else ", ") ++ sformat!"{a} ← {b}"
private def to_string (m : hash_map α β) : string :=
"⟨" ++ (fst (fold m ("", tt) (λ p a b, (fst p ++ key_data_to_string a b (snd p), ff)))) ++ "⟩"
instance : has_to_string (hash_map α β) :=
⟨to_string⟩
end string
section format
open format prod
variables [has_to_format α] [∀ a, has_to_format (β a)]
private meta def format_key_data (a : α) (b : β a) (first : bool) : format :=
(if first then to_fmt "" else to_fmt "," ++ line) ++
to_fmt a ++ space ++ to_fmt "←" ++ space ++ to_fmt b
private meta def to_format (m : hash_map α β) : format :=
group $ to_fmt "⟨" ++
nest 1 (fst (fold m (to_fmt "", tt) (λ p a b, (fst p ++ format_key_data a b (snd p), ff)))) ++
to_fmt "⟩"
meta instance : has_to_format (hash_map α β) :=
⟨to_format⟩
end format
end hash_map
|
1c6a3dc42605b6ff77317882c1517f489cc6489a | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/mvar1.lean | 56aa57c5e40047efd4c7815368158029803430bf | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 3,089 | lean | import Init.Lean.MetavarContext
open Lean
def check (b : Bool) : IO Unit :=
unless b (throw $ IO.userError "error")
def f := mkConst `f []
def g := mkConst `g []
def a := mkConst `a []
def b := mkConst `b []
def c := mkConst `c []
def b0 := mkBVar 0
def b1 := mkBVar 1
def b2 := mkBVar 2
def u := mkLevelParam `u
def typeE := mkSort levelOne
def natE := mkConst `Nat []
def boolE := mkConst `Bool []
def vecE := mkConst `Vec [levelZero]
def α := mkFVar `α
def x := mkFVar `x
def y := mkFVar `y
def z := mkFVar `z
def w := mkFVar `w
def m1 := mkMVar `m1
def m2 := mkMVar `m2
def m3 := mkMVar `m3
def m4 := mkMVar `m4
def m5 := mkMVar `m5
def m6 := mkMVar `m6
def bi := BinderInfo.default
def arrow (d b : Expr) := mkForall `_ bi d b
def lctx1 : LocalContext := {}
def lctx2 := lctx1.mkLocalDecl `α `α typeE
def lctx3 := lctx2.mkLocalDecl `x `x natE
def lctx4 := lctx3.mkLocalDecl `y `y α
def lctx5 := lctx4.mkLocalDecl `z `z (mkAppN vecE #[x])
def lctx6 := lctx5.mkLocalDecl `w `w (arrow natE (mkAppN m6 #[α, x, y]))
def t1 := lctx5.mkLambda #[α, x, y] $ mkAppN f #[α, mkAppN g #[x, y], lctx5.mkLambda #[z] (mkApp f z)]
#eval check (!t1.hasFVar)
#eval t1
def mctx1 : MetavarContext := {}
def mctx2 := mctx1.addExprMVarDecl `m1 `m1 lctx3 #[] natE
def mctx3 := mctx2.addExprMVarDecl `m2 `m2 lctx4 #[] α
def mctx4 := mctx3.addExprMVarDecl `m3 `m3 lctx4 #[] natE
def mctx5 := mctx4.addExprMVarDecl `m4 `m4 lctx1 #[] (arrow typeE (arrow natE (arrow α natE)))
def mctx6 := mctx5.addExprMVarDecl `m5 `m5 lctx5 #[] typeE
def mctx7 := mctx5.addExprMVarDecl `m6 `m6 lctx5 #[] (arrow typeE (arrow natE (arrow α natE)))
def mctx8 := mctx7.assignDelayed `m4 lctx4 #[α, x, y] m3
def mctx9 := mctx8.assignExpr `m3 (mkAppN g #[x, y])
def mctx10 := mctx9.assignExpr `m1 a
def t2 := lctx5.mkLambda #[α, x, y] $ mkAppN f #[mkAppN m4 #[α, x, y], x]
#eval check (!t2.hasFVar)
#eval t2
#eval (mctx6.instantiateMVars t2).1
#eval check (!(mctx9.instantiateMVars t2).1.hasMVar)
#eval check (!(mctx9.instantiateMVars t2).1.hasFVar)
#eval (mctx9.instantiateMVars t2).1
-- t3 is ill-formed since m3's localcontext contains ‵α`, `x` and `y`
def t3 := lctx5.mkLambda #[α, x, y] $ mkAppN f #[m3, x]
#eval check (mctx10.instantiateMVars t3).1.hasFVar
#eval (mctx7.instantiateMVars t3).1
def mkDiamond : Nat → Expr
| 0 => m1
| (n+1) => mkAppN f #[mkDiamond n, mkDiamond n]
#eval (mctx7.instantiateMVars (mkDiamond 3)).1
#eval (mctx10.instantiateMVars (mkDiamond 3)).1
#eval (mctx7.instantiateMVars (mkDiamond 100)).1.getAppFn
#eval (mctx10.instantiateMVars (mkDiamond 100)).1.getAppFn
def mctx11 := mctx10.assignDelayed `m6 lctx5 #[α, x, y] m5
def mctx12 := mctx11.assignExpr `m5 (arrow α α)
def t4 := lctx6.mkLambda #[α, x, y, w] $ mkAppN f #[mkAppN m4 #[α, x, y], x]
#eval t4
#eval (mctx9.instantiateMVars t4).1
#eval (mctx12.instantiateMVars t4).1
#eval check (mctx9.instantiateMVars t4).1.hasMVar
#eval check (!((mctx9.instantiateMVars t4).1.hasFVar))
#eval check (!(mctx12.instantiateMVars t4).1.hasMVar)
#eval check (!((mctx12.instantiateMVars t4).1.hasFVar))
|
354135f2ef818bc775556f1e5b7e7a77862aac77 | 5756a081670ba9c1d1d3fca7bd47cb4e31beae66 | /Mathport/Util/System.lean | 8ca9d5709c25d377d56870217edd53486508241c | [
"Apache-2.0"
] | permissive | leanprover-community/mathport | 2c9bdc8292168febf59799efdc5451dbf0450d4a | 13051f68064f7638970d39a8fecaede68ffbf9e1 | refs/heads/master | 1,693,841,364,079 | 1,693,813,111,000 | 1,693,813,111,000 | 379,357,010 | 27 | 10 | Apache-2.0 | 1,691,309,132,000 | 1,624,384,521,000 | Lean | UTF-8 | Lean | false | false | 402 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Daniel Selsam
-/
open System (FilePath)
def createDirectoriesIfNotExists (path : FilePath) : IO Unit := do
match System.FilePath.parent path with
| some d => discard <| IO.Process.run { cmd := "mkdir", args := #["-p", d.toString] }
| none => pure ()
|
403f053f6930290f7e21c861372233ce5ef17130 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/transfer.lean | d337bc0906ac2a1af110193c97ebee66bf5a122e | [
"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 | 7,486 | 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 (CMU)
-/
prelude
import init.meta.tactic
import init.meta.match_tactic
import init.meta.mk_dec_eq_instance
import init.data.list.instances
import logic.relator
open tactic expr list monad
namespace transfer
/- Transfer rules are of the shape:
rel_t : {u} Πx, R t₁ t₂
where `u` is a list of universe parameters, `x` is a list of dependent variables, and `R` is a
relation. Then this rule will translate `t₁` (depending on `u` and `x`) into `t₂`. `u` and `x`
will be called parameters. When `R` is a relation on functions lifted from `S` and `R` the variables
bound by `S` are called arguments. `R` is generally constructed using `⇒` (i.e. `relator.lift_fun`).
As example:
rel_eq : (R ⇒ R ⇒ iff) eq t
transfer will match this rule when it sees:
(@eq α a b) and transfer it to (t a b)
Here `α` is a parameter and `a` and `b` are arguments.
TODO: add trace statements
TODO: currently the used relation must be fixed by the matched rule or through type class
inference. Maybe we want to replace this by type inference similar to Isabelle's transfer.
-/
private meta structure rel_data :=
(in_type : expr)
(out_type : expr)
(relation : expr)
meta instance has_to_tactic_format_rel_data : has_to_tactic_format rel_data :=
⟨λr, do
R ← pp r.relation,
α ← pp r.in_type,
β ← pp r.out_type,
return format!"({R}: rel ({α}) ({β}))" ⟩
private meta structure rule_data :=
(pr : expr)
(uparams : list name) -- levels not in pat
(params : list (expr × bool)) -- fst : local constant, snd = tt → param appears in pattern
(uargs : list name) -- levels not in pat
(args : list (expr × rel_data)) -- fst : local constant
(pat : pattern) -- `R c`
(output : expr) -- right-hand side `d` of rel equation `R c d`
meta instance has_to_tactic_format_rule_data : has_to_tactic_format rule_data :=
⟨λr, do
pr ← pp r.pr,
up ← pp r.uparams,
mp ← pp r.params,
ua ← pp r.uargs,
ma ← pp r.args,
pat ← pp r.pat.target,
output ← pp r.output,
return format!"{{ ⟨{pat}⟩ pr: {pr} → {output}, {up} {mp} {ua} {ma} }" ⟩
private meta def get_lift_fun : expr → tactic (list rel_data × expr)
| e :=
do {
guardb (is_constant_of (get_app_fn e) ``relator.lift_fun),
[α, β, γ, δ, R, S] ← return $ get_app_args e,
(ps, r) ← get_lift_fun S,
return (rel_data.mk α β R :: ps, r)} <|>
return ([], e)
private meta def mark_occurences (e : expr) : list expr → list (expr × bool)
| [] := []
| (h :: t) := let xs := mark_occurences t in
(h, occurs h e || any xs (λ⟨e, oc⟩, oc && occurs h e)) :: xs
private meta def analyse_rule (u' : list name) (pr : expr) : tactic rule_data := do
t ← infer_type pr,
(params, app (app r f) g) ← mk_local_pis t,
(arg_rels, R) ← get_lift_fun r,
args ← (enum arg_rels).mmap $ λ⟨n, a⟩,
prod.mk <$> mk_local_def (mk_simple_name ("a_" ++ repr n)) a.in_type <*> pure a,
a_vars ← return $ prod.fst <$> args,
p ← head_beta (app_of_list f a_vars),
p_data ← return $ mark_occurences (app R p) params,
p_vars ← return $ list.map prod.fst (p_data.filter (λx, ↑x.2)),
u ← return $ collect_univ_params (app R p) ∩ u',
pat ← mk_pattern (level.param <$> u) (p_vars ++ a_vars) (app R p) (level.param <$> u) (p_vars ++ a_vars),
return $ rule_data.mk pr (u'.remove_all u) p_data u args pat g
meta def analyse_decls : list name → tactic (list rule_data) :=
mmap (λn, do
d ← get_decl n,
c ← return d.univ_params.length,
ls ← (repeat () c).mmap (λ_, mk_fresh_name),
analyse_rule ls (const n (ls.map level.param)))
private meta def split_params_args : list (expr × bool) → list expr → list (expr × option expr) × list expr
| ((lc, tt) :: ps) (e :: es) := let (ps', es') := split_params_args ps es in ((lc, some e) :: ps', es')
| ((lc, ff) :: ps) es := let (ps', es') := split_params_args ps es in ((lc, none) :: ps', es')
| _ es := ([], es)
private meta def param_substitutions (ctxt : list expr) :
list (expr × option expr) → tactic (list (name × expr) × list expr)
| (((local_const n _ bi t), s) :: ps) := do
(e, m) ← match s with
| (some e) := return (e, [])
| none :=
let ctxt' := list.filter (λv, occurs v t) ctxt in
let ty := pis ctxt' t in
if bi = binder_info.inst_implicit then do
guard (bi = binder_info.inst_implicit),
e ← instantiate_mvars ty >>= mk_instance,
return (e, [])
else do
mv ← mk_meta_var ty,
return (app_of_list mv ctxt', [mv])
end,
sb ← return $ instantiate_local n e,
ps ← return $ prod.map sb ((<$>) sb) <$> ps,
(ms, vs) ← param_substitutions ps,
return ((n, e) :: ms, m ++ vs)
| _ := return ([], [])
/- input expression a type `R a`, it finds a type `b`, s.t. there is a proof of the type `R a b`.
It return (`a`, pr : `R a b`) -/
meta def compute_transfer : list rule_data → list expr → expr → tactic (expr × expr × list expr)
| rds ctxt e := do
-- Select matching rule
(i, ps, args, ms, rd) ← first (rds.map (λrd, do
(l, m) ← match_pattern rd.pat e semireducible,
level_map ← rd.uparams.mmap $ λl, prod.mk l <$> mk_meta_univ,
inst_univ ← return $ λe, instantiate_univ_params e (level_map ++ zip rd.uargs l),
(ps, args) ← return $ split_params_args (rd.params.map (prod.map inst_univ id)) m,
(ps, ms) ← param_substitutions ctxt ps, /- this checks type class parameters -/
return (instantiate_locals ps ∘ inst_univ, ps, args, ms, rd))) <|>
(do trace e, fail "no matching rule"),
(bs, hs, mss) ← (zip rd.args args).mmap (λ⟨⟨_, d⟩, e⟩, do
-- Argument has function type
(args, r) ← get_lift_fun (i d.relation),
((a_vars, b_vars), (R_vars, bnds)) ← (enum args).mmap (λ⟨n, arg⟩, do
a ← mk_local_def sformat!"a{n}" arg.in_type,
b ← mk_local_def sformat!"b{n}" arg.out_type,
R ← mk_local_def sformat!"R{n}" (arg.relation a b),
return ((a, b), (R, [a, b, R]))) >>= (return ∘ prod.map unzip unzip ∘ unzip),
rds' ← R_vars.mmap (analyse_rule []),
-- Transfer argument
a ← return $ i e,
a' ← head_beta (app_of_list a a_vars),
(b, pr, ms) ← compute_transfer (rds ++ rds') (ctxt ++ a_vars) (app r a'),
b' ← head_eta (lambdas b_vars b),
return (b', [a, b', lambdas (list.join bnds) pr], ms)) >>= (return ∘ prod.map id unzip ∘ unzip),
-- Combine
b ← head_beta (app_of_list (i rd.output) bs),
pr ← return $ app_of_list (i rd.pr) (prod.snd <$> ps ++ list.join hs),
return (b, pr, ms ++ mss.join)
end transfer
open transfer
meta def tactic.transfer (ds : list name) : tactic unit := do
rds ← analyse_decls ds,
tgt ← target,
(guard (¬ tgt.has_meta_var) <|>
fail "Target contains (universe) meta variables. This is not supported by transfer."),
(new_tgt, pr, ms) ← compute_transfer rds [] ((const `iff [] : expr) tgt),
new_pr ← mk_meta_var new_tgt,
/- Setup final tactic state -/
exact ((const `iff.mpr [] : expr) tgt new_tgt pr new_pr),
ms ← ms.mmap (λm, (get_assignment m >> return []) <|> return [m]),
gs ← get_goals,
set_goals (ms.join ++ new_pr :: gs)
|
14ec2d466238ed3141d90e3b694a4b30a5134a80 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/monad/basic.lean | cc9ac77b2929baddc54fbbbc98bf13cdd2d78261 | [
"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 | 10,879 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta, Adam Topaz
-/
import category_theory.functor.category
import category_theory.functor.fully_faithful
import category_theory.functor.reflects_isomorphisms
/-!
# Monads
We construct the categories of monads and comonads, and their forgetful functors to endofunctors.
(Note that these are the category theorist's monads, not the programmers monads.
For the translation, see the file `category_theory.monad.types`.)
For the fact that monads are "just" monoids in the category of endofunctors, see the file
`category_theory.monad.equiv_mon`.
-/
namespace category_theory
open category
universes v₁ u₁ -- morphism levels before object levels. See note [category_theory universes].
variables (C : Type u₁) [category.{v₁} C]
/--
The data of a monad on C consists of an endofunctor T together with natural transformations
η : 𝟭 C ⟶ T and μ : T ⋙ T ⟶ T satisfying three equations:
- T μ_X ≫ μ_X = μ_(TX) ≫ μ_X (associativity)
- η_(TX) ≫ μ_X = 1_X (left unit)
- Tη_X ≫ μ_X = 1_X (right unit)
-/
structure monad extends C ⥤ C :=
(η' [] : 𝟭 _ ⟶ to_functor)
(μ' [] : to_functor ⋙ to_functor ⟶ to_functor)
(assoc' : ∀ X, to_functor.map (nat_trans.app μ' X) ≫ μ'.app _ = μ'.app _ ≫ μ'.app _ . obviously)
(left_unit' : ∀ X : C, η'.app (to_functor.obj X) ≫ μ'.app _ = 𝟙 _ . obviously)
(right_unit' : ∀ X : C, to_functor.map (η'.app X) ≫ μ'.app _ = 𝟙 _ . obviously)
/--
The data of a comonad on C consists of an endofunctor G together with natural transformations
ε : G ⟶ 𝟭 C and δ : G ⟶ G ⋙ G satisfying three equations:
- δ_X ≫ G δ_X = δ_X ≫ δ_(GX) (coassociativity)
- δ_X ≫ ε_(GX) = 1_X (left counit)
- δ_X ≫ G ε_X = 1_X (right counit)
-/
structure comonad extends C ⥤ C :=
(ε' [] : to_functor ⟶ 𝟭 _)
(δ' [] : to_functor ⟶ to_functor ⋙ to_functor)
(coassoc' : ∀ X, nat_trans.app δ' _ ≫ to_functor.map (δ'.app X) = δ'.app _ ≫ δ'.app _ . obviously)
(left_counit' : ∀ X : C, δ'.app X ≫ ε'.app (to_functor.obj X) = 𝟙 _ . obviously)
(right_counit' : ∀ X : C, δ'.app X ≫ to_functor.map (ε'.app X) = 𝟙 _ . obviously)
variables {C} (T : monad C) (G : comonad C)
instance coe_monad : has_coe (monad C) (C ⥤ C) := ⟨λ T, T.to_functor⟩
instance coe_comonad : has_coe (comonad C) (C ⥤ C) := ⟨λ G, G.to_functor⟩
@[simp] lemma monad_to_functor_eq_coe : T.to_functor = T := rfl
@[simp] lemma comonad_to_functor_eq_coe : G.to_functor = G := rfl
/-- The unit for the monad `T`. -/
def monad.η : 𝟭 _ ⟶ (T : C ⥤ C) := T.η'
/-- The multiplication for the monad `T`. -/
def monad.μ : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ T := T.μ'
/-- The counit for the comonad `G`. -/
def comonad.ε : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε'
/-- The comultiplication for the comonad `G`. -/
def comonad.δ : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ G := G.δ'
/-- A custom simps projection for the functor part of a monad, as a coercion. -/
def monad.simps.coe := (T : C ⥤ C)
/-- A custom simps projection for the unit of a monad, in simp normal form. -/
def monad.simps.η : 𝟭 _ ⟶ (T : C ⥤ C) := T.η
/-- A custom simps projection for the multiplication of a monad, in simp normal form. -/
def monad.simps.μ : (T : C ⥤ C) ⋙ (T : C ⥤ C) ⟶ (T : C ⥤ C) := T.μ
/-- A custom simps projection for the functor part of a comonad, as a coercion. -/
def comonad.simps.coe := (G : C ⥤ C)
/-- A custom simps projection for the counit of a comonad, in simp normal form. -/
def comonad.simps.ε : (G : C ⥤ C) ⟶ 𝟭 _ := G.ε
/-- A custom simps projection for the comultiplication of a comonad, in simp normal form. -/
def comonad.simps.δ : (G : C ⥤ C) ⟶ (G : C ⥤ C) ⋙ (G : C ⥤ C) := G.δ
initialize_simps_projections category_theory.monad (to_functor → coe, η' → η, μ' → μ)
initialize_simps_projections category_theory.comonad (to_functor → coe, ε' → ε, δ' → δ)
@[reassoc]
lemma monad.assoc (T : monad C) (X : C) :
(T : C ⥤ C).map (T.μ.app X) ≫ T.μ.app _ = T.μ.app _ ≫ T.μ.app _ :=
T.assoc' X
@[simp, reassoc] lemma monad.left_unit (T : monad C) (X : C) :
T.η.app ((T : C ⥤ C).obj X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) :=
T.left_unit' X
@[simp, reassoc] lemma monad.right_unit (T : monad C) (X : C) :
(T : C ⥤ C).map (T.η.app X) ≫ T.μ.app X = 𝟙 ((T : C ⥤ C).obj X) :=
T.right_unit' X
@[reassoc]
lemma comonad.coassoc (G : comonad C) (X : C) :
G.δ.app _ ≫ (G : C ⥤ C).map (G.δ.app X) = G.δ.app _ ≫ G.δ.app _ :=
G.coassoc' X
@[simp, reassoc] lemma comonad.left_counit (G : comonad C) (X : C) :
G.δ.app X ≫ G.ε.app ((G : C ⥤ C).obj X) = 𝟙 ((G : C ⥤ C).obj X) :=
G.left_counit' X
@[simp, reassoc] lemma comonad.right_counit (G : comonad C) (X : C) :
G.δ.app X ≫ (G : C ⥤ C).map (G.ε.app X) = 𝟙 ((G : C ⥤ C).obj X) :=
G.right_counit' X
/-- A morphism of monads is a natural transformation compatible with η and μ. -/
@[ext]
structure monad_hom (T₁ T₂ : monad C) extends nat_trans (T₁ : C ⥤ C) T₂ :=
(app_η' : ∀ X, T₁.η.app X ≫ app X = T₂.η.app X . obviously)
(app_μ' : ∀ X, T₁.μ.app X ≫ app X = ((T₁ : C ⥤ C).map (app X) ≫ app _) ≫ T₂.μ.app X . obviously)
/-- A morphism of comonads is a natural transformation compatible with ε and δ. -/
@[ext]
structure comonad_hom (M N : comonad C) extends nat_trans (M : C ⥤ C) N :=
(app_ε' : ∀ X, app X ≫ N.ε.app X = M.ε.app X . obviously)
(app_δ' : ∀ X, app X ≫ N.δ.app X = M.δ.app X ≫ app _ ≫ (N : C ⥤ C).map (app X) . obviously)
restate_axiom monad_hom.app_η'
restate_axiom monad_hom.app_μ'
attribute [simp, reassoc] monad_hom.app_η monad_hom.app_μ
restate_axiom comonad_hom.app_ε'
restate_axiom comonad_hom.app_δ'
attribute [simp, reassoc] comonad_hom.app_ε comonad_hom.app_δ
instance : category (monad C) :=
{ hom := monad_hom,
id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) },
comp := λ _ _ _ f g,
{ to_nat_trans := { app := λ X, f.app X ≫ g.app X } } }
instance : category (comonad C) :=
{ hom := comonad_hom,
id := λ M, { to_nat_trans := 𝟙 (M : C ⥤ C) },
comp := λ M N L f g,
{ to_nat_trans := { app := λ X, f.app X ≫ g.app X } } }
instance {T : monad C} : inhabited (monad_hom T T) := ⟨𝟙 T⟩
@[simp] lemma monad_hom.id_to_nat_trans (T : monad C) :
(𝟙 T : T ⟶ T).to_nat_trans = 𝟙 (T : C ⥤ C) :=
rfl
@[simp] lemma monad_hom.comp_to_nat_trans {T₁ T₂ T₃ : monad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) :
(f ≫ g).to_nat_trans =
((f.to_nat_trans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.to_nat_trans : (T₁ : C ⥤ C) ⟶ T₃) :=
rfl
instance {G : comonad C} : inhabited (comonad_hom G G) := ⟨𝟙 G⟩
@[simp] lemma comonad_hom.id_to_nat_trans (T : comonad C) :
(𝟙 T : T ⟶ T).to_nat_trans = 𝟙 (T : C ⥤ C) :=
rfl
@[simp] lemma comp_to_nat_trans {T₁ T₂ T₃ : comonad C} (f : T₁ ⟶ T₂) (g : T₂ ⟶ T₃) :
(f ≫ g).to_nat_trans =
((f.to_nat_trans : _ ⟶ (T₂ : C ⥤ C)) ≫ g.to_nat_trans : (T₁ : C ⥤ C) ⟶ T₃) :=
rfl
/-- Construct a monad isomorphism from a natural isomorphism of functors where the forward
direction is a monad morphism. -/
@[simps]
def monad_iso.mk {M N : monad C} (f : (M : C ⥤ C) ≅ N) (f_η f_μ) :
M ≅ N :=
{ hom := { to_nat_trans := f.hom, app_η' := f_η, app_μ' := f_μ },
inv :=
{ to_nat_trans := f.inv,
app_η' := λ X, by simp [←f_η],
app_μ' := λ X,
begin
rw ←nat_iso.cancel_nat_iso_hom_right f,
simp only [nat_trans.naturality, iso.inv_hom_id_app, assoc, comp_id, f_μ,
nat_trans.naturality_assoc, iso.inv_hom_id_app_assoc, ←functor.map_comp_assoc],
simp,
end } }
/-- Construct a comonad isomorphism from a natural isomorphism of functors where the forward
direction is a comonad morphism. -/
@[simps]
def comonad_iso.mk {M N : comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε f_δ) :
M ≅ N :=
{ hom := { to_nat_trans := f.hom, app_ε' := f_ε, app_δ' := f_δ },
inv :=
{ to_nat_trans := f.inv,
app_ε' := λ X, by simp [←f_ε],
app_δ' := λ X,
begin
rw ←nat_iso.cancel_nat_iso_hom_left f,
simp only [reassoc_of (f_δ X), iso.hom_inv_id_app_assoc, nat_trans.naturality_assoc],
rw [←functor.map_comp, iso.hom_inv_id_app, functor.map_id],
apply (comp_id _).symm
end } }
variable (C)
/--
The forgetful functor from the category of monads to the category of endofunctors.
-/
@[simps]
def monad_to_functor : monad C ⥤ (C ⥤ C) :=
{ obj := λ T, T,
map := λ M N f, f.to_nat_trans }
instance : faithful (monad_to_functor C) := {}.
@[simp]
lemma monad_to_functor_map_iso_monad_iso_mk {M N : monad C} (f : (M : C ⥤ C) ≅ N) (f_η f_μ) :
(monad_to_functor _).map_iso (monad_iso.mk f f_η f_μ) = f :=
by { ext, refl }
instance : reflects_isomorphisms (monad_to_functor C) :=
{ reflects := λ M N f i,
begin
resetI,
convert is_iso.of_iso (monad_iso.mk (as_iso ((monad_to_functor C).map f)) f.app_η f.app_μ),
ext; refl,
end }
/--
The forgetful functor from the category of comonads to the category of endofunctors.
-/
@[simps]
def comonad_to_functor : comonad C ⥤ (C ⥤ C) :=
{ obj := λ G, G,
map := λ M N f, f.to_nat_trans }
instance : faithful (comonad_to_functor C) := {}.
@[simp]
lemma comonad_to_functor_map_iso_comonad_iso_mk {M N : comonad C} (f : (M : C ⥤ C) ≅ N) (f_ε f_δ) :
(comonad_to_functor _).map_iso (comonad_iso.mk f f_ε f_δ) = f :=
by { ext, refl }
instance : reflects_isomorphisms (comonad_to_functor C) :=
{ reflects := λ M N f i,
begin
resetI,
convert is_iso.of_iso (comonad_iso.mk (as_iso ((comonad_to_functor C).map f)) f.app_ε f.app_δ),
ext; refl,
end }
variable {C}
/--
An isomorphism of monads gives a natural isomorphism of the underlying functors.
-/
@[simps {rhs_md := semireducible}]
def monad_iso.to_nat_iso {M N : monad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N :=
(monad_to_functor C).map_iso h
/--
An isomorphism of comonads gives a natural isomorphism of the underlying functors.
-/
@[simps {rhs_md := semireducible}]
def comonad_iso.to_nat_iso {M N : comonad C} (h : M ≅ N) : (M : C ⥤ C) ≅ N :=
(comonad_to_functor C).map_iso h
variable (C)
namespace monad
/-- The identity monad. -/
@[simps]
def id : monad C :=
{ to_functor := 𝟭 C,
η' := 𝟙 (𝟭 C),
μ' := 𝟙 (𝟭 C) }
instance : inhabited (monad C) := ⟨monad.id C⟩
end monad
namespace comonad
/-- The identity comonad. -/
@[simps]
def id : comonad C :=
{ to_functor := 𝟭 _,
ε' := 𝟙 (𝟭 C),
δ' := 𝟙 (𝟭 C) }
instance : inhabited (comonad C) := ⟨comonad.id C⟩
end comonad
end category_theory
|
40eec0a78cebd612b303194f1e1e4546ea3bbbe1 | 4aca55eba10c989f0d58647d3c2f371e7da44355 | /src/examples.lean | a8134edb251571f85b06925735e2c6450aea1d18 | [] | no_license | eric-wieser/l534zhan-my_project | f9fc75fb5454405e1a2fa9b56cf96c355f6f2336 | febc91e76b7b00fe2517f258ca04d27b7f35fcf3 | refs/heads/master | 1,689,218,910,420 | 1,630,439,440,000 | 1,630,439,440,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,519 | lean | import tactic.gptf
import data.matrix.basic
import data.complex.basic
import field_theory.finite.basic
section sec1
lemma irrelevant (P : Prop) (pf1 pf2 : P) : pf1 = pf2 := by simp
universe u
variable a : Type u
#check a -- prints `a : Type u`
#check unit
#check punit --universe polymorphic version H i₁ i₂ α β γ Prop, ℕ, ℤ, ℚ, ℝ, ℕ → ℕ, ...
#check ℕ → ℕ
#check 2 -- prints `2 : ℕ` as Lean view `2` as a natural number by default
#check (2 : ℚ) -- prints `2 : ℚ` if we claim the given `2` is a rational number
#check 2 + 3 -- prints `2 + 3 : ℕ`
def f (x : ℕ) := 2 * x -- this defines a function
#check f -- prints `f : ℕ → ℕ`
#check (4, 5) -- prints `(4, 5) : ℕ × ℕ`,
-- where `×` is the notation of the operation `prod`
#check ℕ -- prints `ℕ : Type`
#check ℕ × ℚ -- prints `ℕ × ℚ : Type`
#check bool -- prints `bool : Type`
def p := 2 + 3 = 5 -- defines `p` to be the statement `2 + 3 = 5`
#check p -- prints `p : Prop`
lemma pf : p := by simp [p] -- this constructs `pf1` as a proof of `p`
#check pf -- prints `pf : p`
#check Type -- Type : Type 1
#check Type 1 -- Type 1 : Type 2
-- ...
variables α : Type* -- declares variables `α`
variable β : Type 2 -- declares variables `b`
#check α -- prints `α : Type u_1`
#check β -- prints `β : Type 2`
#check list -- prints `list : Type u_1 → Type u_1`,
-- where `u_1` is a variable ranging over type levels
#check list ℕ -- prints `list ℕ : Type`
#check list α -- prints `list α : Type u_1`
#check prod -- prints `prod : Type u_3 → Type u_4 → Type (max u_3 u_4)`
#check ℕ × ℕ -- prints `ℕ × ℕ : Type`
#check ℕ × β -- prints `ℕ × β : Type 2`
#check α × β -- prints `α × β : Type (max u_1 2)`
namespace foo -- declares we are working in the namespace `foo`
-- Now, we are working in the namespace `foo`
def b : ℕ := 10
def f (x : ℕ) : ℕ := x + 5
def fb : ℕ := f b
namespace bar -- declares we are working in the namespace `bar`
-- Now, we are working in the namespace `foo.bar`
def ffb : ℕ := f (f b)
#check fb
#check ffb
end bar
-- Now, we back to the namespace `foo`
#check fb
-- `#check ffb` will reports error: unknown identifier 'ffb'.
#check bar.ffb
end foo
#check foo.fb
#check foo.bar.ffb
namespace foo -- We can redo `namespace foo`.
def g (x : ℕ) : ℕ := b + 5
#check g
end foo
-- #check g -- error
#check foo.g
open foo -- `open foo` allows us to use the shorter name `name`
-- for any identifier in form `foo.name`,
-- but if we declare an identifier `g` after `open foo`,
-- `g`'s full name is `g`, not `foo.g`.
#check g
#check bar.ffb
-- a term-style proof
lemma pf1 (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=
and.intro hp (and.intro hq hp)
#check and.intro -- prints `and.intro : ?M_1 → ?M_2 → ?M_1 ∧ ?M_2`,
-- where `?M_1` and `?M_2` denotes indeterminate variables
-- a tactic-style proof
lemma pf2 (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=
begin -- the `begin ... end` block allows us to write a list of tactics
split, -- splits the goal `p ∧ q ∧ p` into two goals `p` and `q ∧ p`
-- the first goal is `p`
-- I.e. Lean expects us to provide an expression of type `p`
exact hp, -- provides an exact proof term `hp`
-- this closes the first goal as `hp` has type `p`
split, -- splits `q ∧ p` into `q` and `p`
exact hq, -- provides an exact proof term `hq`
exact hp, -- provides an exact proof term `hp`
end
-- mix
lemma pf3 (p q : Prop) (hp : p) (hq : q) : p ∧ q ∧ p :=
begin
split,
exact hp, -- `hp` is a proof term
exact and.intro hq hp -- `and.intro hq hp` is a proof term
end
#check int.of_nat
#check rat.of_int --ℤ
variables m n : ℕ
variables i : ℤ
variables j : ℚ
#check i + m -- i + ↑m : ℤ
#check i + m + n -- i + ↑m + ↑n : Z
#check j + i + m -- j + ↑i + ↑m : ℚ
-- #check m + i -- error
#check ↑m + i -- ↑m + i : ℤ
#check ↑(m + n) + i -- ↑(m + n) + i : ℤ
#check ↑m + ↑n + i -- ↑m + ↑n + i : ℤ
#check ↑i + ↑m + j -- ↑i + ↑m + j : ℚ β
instance my_coe : has_coe ℝ ℂ := ⟨λ r, ⟨r, 0⟩⟩
variables (r : ℝ) (c : ℂ)
#check c + r -- c + ↑r : ℂ
end sec1
section str
-- the following is the definition of `prod` in mathlib
--structure prod (α : Type u) (β : Type v) := -- round brackets mark parameters explicitly supplied by the user
--(fst : α) (snd : β)
#check prod -- prod : Type u_1 → Type u_2 → Type (max u_1 u_2)
variables α β : Type*
#check prod α β -- α × β : Type (max u_1 u_2)
-- α × β is a new type and itself has type Type (max u_1 u_2)
variables (a : α) (b : β)
#check prod.mk a b -- (a, b) : α × β
#check (⟨a, b⟩ : prod α β) -- (a, b) : α × β
#check (a, b) -- (a, b) : α × β
#check prod.fst -- prod.fst : ?M_1 × ?M_2 → ?M_1
#reduce prod.fst (10, 20) -- 10
#reduce (10, 20).1 -- 10
#check prod.snd -- prod.snd : ?M_1 × ?M_2 → ?M_2
#reduce prod.snd (10, 20) -- 20
#reduce (10, 20).2 -- 20
structure my_str := -- a new structure with thtree fields
(f1 : ℕ) (f2 : ℕ) (f3 : ℕ)
variables n : ℕ
-- defines `triple n` to be `⟨n, n + n, n + n + n⟩`
def triple : my_str := ⟨n, n + n, n + n + n⟩
#check triple n -- triple n : my_str
#reduce (triple n).1 -- n
#reduce (triple n).2 -- n.add n
#reduce (triple n).3 -- (n.add n).add n
#reduce my_str.f3 (triple 5) -- 15
#reduce (triple 5).3 -- 15
end str
#check has_add
-- class has_add (α : Type u) := (add : α → α → α)
#check nat.has_add -- nat.has_add : has_add ℕ
-- We construt an element `my_inst` of `has_add ℕ`.
def my_inst : has_add ℕ := ⟨nat.add⟩ -- `nat.add` is a function defined in mathlib
-- Next, we declare `my_inst` to be an instance of `has_add ℕ`.
attribute [instance] my_inst
-- @[instance] def my_inst : has_add ℕ := ⟨nat.add⟩
-- instance my_inst : has_add ℕ := ⟨nat.add⟩
instance my_inst' : has_add (ℕ × ℕ):= ⟨λ ⟨a, b⟩ ⟨c, d⟩, ⟨a + c, b + c⟩⟩
--variables α : Type*
--instance my_inst'' : has_add (α × α):= ⟨λ ⟨a, b⟩ ⟨c, d⟩, ⟨a + c, b + c⟩⟩
/-
/-- `finset α` is the type of finite sets of elements of `α`. It is implemented
as a multiset (a list up to permutation) which has no duplicate elements.
`finset.nodup` is the poof that `finset.val` has no duplicate elements. -/
structure finset (α : Type*) :=
(val : multiset α)
(nodup : nodup val)
/-- `fintype α` means that `α` is finite, i.e. there are only
finitely many distinct elements of type `α`. The evidence of this
is a finset `elems` (a list up to permutation without duplicates),
together with a proof `complete` that everything of type `α` is in the list. -/
class fintype (α : Type*) :=
(elems [] : finset α)
(complete : ∀ x : α, x ∈ elems)
-/
open matrix
--variables (I α : Type*) [fintype I] [has_one α]
--#check (1 : I → α)
#check diagonal
variables (I α : Type*) [fintype I]
variables [decidable_eq I] [has_zero α] [has_one α]
#check matrix.has_one
#check (1 : matrix I I α)
#check semigroup
/-
class has_one (α : Type u) := (one : α)
class has_mul (α : Type u) := (mul : α → α → α)
class semigroup (G : Type u) extends has_mul G :=
(mul_assoc : ∀ a b c : G, a * b * c = a * (b * c))
class mul_one_class (M : Type u) extends has_one M, has_mul M :=
(one_mul : ∀ (a : M), 1 * a = a)
(mul_one : ∀ (a : M), a * 1 = a)
class monoid (M : Type u) extends semigroup M, mul_one_class M :=
(npow : ℕ → M → M := npow_rec)
(npow_zero' : ∀ x, npow 0 x = 1 . try_refl_tac)
(npow_succ' : ∀ (n : ℕ) x, npow n.succ x = x * npow n x . try_refl_tac)
-/
/-
lemma simple {a : ℕ} (h : a ∣ 4) : a = 1 ∨ a = 2 ∨ a = 4 :=
begin
dec_trivial
end
-/
example (a : ℕ) (h : a > 0) : a = a - 1 + 1 := by rw nat.sub_add_cancel h
-- rw fintype.card_eq,
example {F : Type*} [fintype F] [has_zero F] [decidable_eq F] :
fintype.card {a : F // a = 0} = 1 :=
begin
simp [fintype.card_eq_one_iff],
/-
have h: fintype.card {a : F // a = 0} = fintype.card ({0} : set F),
{ rw fintype.card_eq,
have eq : {a:F // a = 0} ≃ ({0} : set F),
{ refine {..},
exact λ a : {a:F // a = 0}, by tidy,
exact λ a : ({0} : set F), by tidy,
tidy,
},
exact ⟨eq⟩,},
simp [h],
-/
end
noncomputable
example {α : Type*} (h : ∃ a : α, true) : α :=
classical.some h |
6732a9cc0cf9e4d61733f2c0b5861076bc173e93 | 367134ba5a65885e863bdc4507601606690974c1 | /src/linear_algebra/affine_space/midpoint.lean | c2cfd6b5b1a814deb9d6fb506276b0309fce97b4 | [
"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 | 7,615 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Yury Kudryashov
-/
import algebra.invertible
import linear_algebra.affine_space.affine_equiv
/-!
# Midpoint of a segment
## Main definitions
* `midpoint R x y`: midpoint of the segment `[x, y]`. We define it for `x` and `y`
in a module over a ring `R` with invertible `2`.
* `add_monoid_hom.of_map_midpoint`: construct an `add_monoid_hom` given a map `f` such that
`f` sends zero to zero and midpoints to midpoints.
## Main theorems
* `midpoint_eq_iff`: `z` is the midpoint of `[x, y]` if and only if `x + y = z + z`,
* `midpoint_unique`: `midpoint R x y` does not depend on `R`;
* `midpoint x y` is linear both in `x` and `y`;
* `point_reflection_midpoint_left`, `point_reflection_midpoint_right`:
`equiv.point_reflection (midpoint R x y)` swaps `x` and `y`.
We do not mark most lemmas as `@[simp]` because it is hard to tell which side is simpler.
## Tags
midpoint, add_monoid_hom
-/
open affine_map affine_equiv
section
variables (R : Type*) {V V' P P' : Type*} [ring R] [invertible (2:R)]
[add_comm_group V] [semimodule R V] [add_torsor V P]
[add_comm_group V'] [semimodule R V'] [add_torsor V' P']
include V
/-- `midpoint x y` is the midpoint of the segment `[x, y]`. -/
def midpoint (x y : P) : P := line_map x y (⅟2:R)
variables {R} {x y z : P}
include V'
@[simp] lemma affine_map.map_midpoint (f : P →ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_line_map a b _
@[simp] lemma affine_equiv.map_midpoint (f : P ≃ᵃ[R] P') (a b : P) :
f (midpoint R a b) = midpoint R (f a) (f b) :=
f.apply_line_map a b _
omit V'
@[simp] lemma affine_equiv.point_reflection_midpoint_left (x y : P) :
point_reflection R (midpoint R x y) x = y :=
by rw [midpoint, point_reflection_apply, line_map_apply, vadd_vsub,
vadd_assoc, ← add_smul, ← two_mul, mul_inv_of_self, one_smul, vsub_vadd]
lemma midpoint_comm (x y : P) : midpoint R x y = midpoint R y x :=
by rw [midpoint, ← line_map_apply_one_sub, one_sub_inv_of_two, midpoint]
@[simp] lemma affine_equiv.point_reflection_midpoint_right (x y : P) :
point_reflection R (midpoint R x y) y = x :=
by rw [midpoint_comm, affine_equiv.point_reflection_midpoint_left]
lemma midpoint_vsub_midpoint (p₁ p₂ p₃ p₄ : P) :
midpoint R p₁ p₂ -ᵥ midpoint R p₃ p₄ = midpoint R (p₁ -ᵥ p₃) (p₂ -ᵥ p₄) :=
line_map_vsub_line_map _ _ _ _ _
lemma midpoint_vadd_midpoint (v v' : V) (p p' : P) :
midpoint R v v' +ᵥ midpoint R p p' = midpoint R (v +ᵥ p) (v' +ᵥ p') :=
line_map_vadd_line_map _ _ _ _ _
lemma midpoint_eq_iff {x y z : P} : midpoint R x y = z ↔ point_reflection R z x = y :=
eq_comm.trans ((injective_point_reflection_left_of_module R x).eq_iff'
(affine_equiv.point_reflection_midpoint_left x y)).symm
@[simp] lemma midpoint_vsub_left (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₁ = (⅟2:R) • (p₂ -ᵥ p₁) :=
line_map_vsub_left _ _ _
@[simp] lemma midpoint_vsub_right (p₁ p₂ : P) : midpoint R p₁ p₂ -ᵥ p₂ = (⅟2:R) • (p₁ -ᵥ p₂) :=
by rw [midpoint_comm, midpoint_vsub_left]
@[simp] lemma left_vsub_midpoint (p₁ p₂ : P) : p₁ -ᵥ midpoint R p₁ p₂ = (⅟2:R) • (p₁ -ᵥ p₂) :=
left_vsub_line_map _ _ _
@[simp] lemma right_vsub_midpoint (p₁ p₂ : P) : p₂ -ᵥ midpoint R p₁ p₂ = (⅟2:R) • (p₂ -ᵥ p₁) :=
by rw [midpoint_comm, left_vsub_midpoint]
@[simp] lemma midpoint_sub_left (v₁ v₂ : V) : midpoint R v₁ v₂ - v₁ = (⅟2:R) • (v₂ - v₁) :=
midpoint_vsub_left v₁ v₂
@[simp] lemma midpoint_sub_right (v₁ v₂ : V) : midpoint R v₁ v₂ - v₂ = (⅟2:R) • (v₁ - v₂) :=
midpoint_vsub_right v₁ v₂
@[simp] lemma left_sub_midpoint (v₁ v₂ : V) : v₁ - midpoint R v₁ v₂ = (⅟2:R) • (v₁ - v₂) :=
left_vsub_midpoint v₁ v₂
@[simp] lemma right_sub_midpoint (v₁ v₂ : V) : v₂ - midpoint R v₁ v₂ = (⅟2:R) • (v₂ - v₁) :=
right_vsub_midpoint v₁ v₂
variable (R)
lemma midpoint_eq_midpoint_iff_vsub_eq_vsub {x x' y y' : P} :
midpoint R x y = midpoint R x' y' ↔ x -ᵥ x' = y' -ᵥ y :=
by rw [← @vsub_eq_zero_iff_eq V, midpoint_vsub_midpoint, midpoint_eq_iff, point_reflection_apply,
vsub_eq_sub, zero_sub, vadd_eq_add, add_zero, neg_eq_iff_neg_eq, neg_vsub_eq_vsub_rev, eq_comm]
lemma midpoint_eq_iff' {x y z : P} : midpoint R x y = z ↔ equiv.point_reflection z x = y :=
midpoint_eq_iff
/-- `midpoint` does not depend on the ring `R`. -/
lemma midpoint_unique (R' : Type*) [ring R'] [invertible (2:R')] [semimodule R' V] (x y : P) :
midpoint R x y = midpoint R' x y :=
(midpoint_eq_iff' R).2 $ (midpoint_eq_iff' R').1 rfl
@[simp] lemma midpoint_self (x : P) : midpoint R x x = x :=
line_map_same_apply _ _
@[simp] lemma midpoint_add_self (x y : V) : midpoint R x y + midpoint R x y = x + y :=
calc midpoint R x y +ᵥ midpoint R x y = midpoint R x y +ᵥ midpoint R y x : by rw midpoint_comm
... = x + y : by rw [midpoint_vadd_midpoint, vadd_eq_add, vadd_eq_add, add_comm, midpoint_self]
lemma midpoint_zero_add (x y : V) : midpoint R 0 (x + y) = midpoint R x y :=
(midpoint_eq_midpoint_iff_vsub_eq_vsub R).2 $ by simp [sub_add_eq_sub_sub_swap]
end
lemma line_map_inv_two {R : Type*} {V P : Type*} [division_ring R] [char_zero R]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
line_map a b (2⁻¹:R) = midpoint R a b :=
rfl
lemma line_map_one_half {R : Type*} {V P : Type*} [division_ring R] [char_zero R]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
line_map a b (1/2:R) = midpoint R a b :=
by rw [one_div, line_map_inv_two]
lemma homothety_inv_of_two {R : Type*} {V P : Type*} [comm_ring R] [invertible (2:R)]
[add_comm_group V] [semimodule R V] [add_torsor V P] (a b : P) :
homothety a (⅟2:R) b = midpoint R a b :=
rfl
lemma homothety_inv_two {k : Type*} {V P : Type*} [field k] [char_zero k]
[add_comm_group V] [semimodule k V] [add_torsor V P] (a b : P) :
homothety a (2⁻¹:k) b = midpoint k a b :=
rfl
lemma homothety_one_half {k : Type*} {V P : Type*} [field k] [char_zero k]
[add_comm_group V] [semimodule k V] [add_torsor V P] (a b : P) :
homothety a (1/2:k) b = midpoint k a b :=
by rw [one_div, homothety_inv_two]
@[simp] lemma pi_midpoint_apply {k ι : Type*} {V : Π i : ι, Type*} {P : Π i : ι, Type*} [field k]
[invertible (2:k)] [Π i, add_comm_group (V i)] [Π i, semimodule k (V i)]
[Π i, add_torsor (V i) (P i)] (f g : Π i, P i) (i : ι) :
midpoint k f g i = midpoint k (f i) (g i) := rfl
namespace add_monoid_hom
variables (R R' : Type*) {E F : Type*}
[ring R] [invertible (2:R)] [add_comm_group E] [semimodule R E]
[ring R'] [invertible (2:R')] [add_comm_group F] [semimodule R' F]
/-- A map `f : E → F` sending zero to zero and midpoints to midpoints is an `add_monoid_hom`. -/
def of_map_midpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) :
E →+ F :=
{ to_fun := f,
map_zero' := h0,
map_add' := λ x y,
calc f (x + y) = f 0 + f (x + y) : by rw [h0, zero_add]
... = midpoint R' (f 0) (f (x + y)) + midpoint R' (f 0) (f (x + y)) :
(midpoint_add_self _ _ _).symm
... = f (midpoint R x y) + f (midpoint R x y) : by rw [← hm, midpoint_zero_add]
... = f x + f y : by rw [hm, midpoint_add_self] }
@[simp] lemma coe_of_map_midpoint (f : E → F) (h0 : f 0 = 0)
(hm : ∀ x y, f (midpoint R x y) = midpoint R' (f x) (f y)) :
⇑(of_map_midpoint R R' f h0 hm) = f := rfl
end add_monoid_hom
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.