filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
Fin.lean
|
/-
Copyright (c) 2021 Ivan Sadofschi Costa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ivan Sadofschi Costa
-/
import Mathlib.Data.Finsupp.Single
/-!
# `cons` and `tail` for maps `Fin n →₀ M`
We interpret maps `Fin n →₀ M` as `n`-tuples of elements of `M`,
We define the following operations:
* `Finsupp.tail` : the tail of a map `Fin (n + 1) →₀ M`, i.e., its last `n` entries;
* `Finsupp.cons` : adding an element at the beginning of an `n`-tuple, to get an `n + 1`-tuple;
In this context, we prove some usual properties of `tail` and `cons`, analogous to those of
`Data.Fin.Tuple.Basic`.
-/
open Function
noncomputable section
namespace Finsupp
variable {n : ℕ} (i : Fin n) {M : Type*} [Zero M] (y : M) (t : Fin (n + 1) →₀ M) (s : Fin n →₀ M)
/-- `tail` for maps `Fin (n + 1) →₀ M`. See `Fin.tail` for more details. -/
def tail (s : Fin (n + 1) →₀ M) : Fin n →₀ M :=
Finsupp.equivFunOnFinite.symm (Fin.tail s)
/-- `cons` for maps `Fin n →₀ M`. See `Fin.cons` for more details. -/
def cons (y : M) (s : Fin n →₀ M) : Fin (n + 1) →₀ M :=
Finsupp.equivFunOnFinite.symm (Fin.cons y s : Fin (n + 1) → M)
theorem tail_apply : tail t i = t i.succ :=
rfl
@[simp]
theorem cons_zero : cons y s 0 = y :=
rfl
@[simp]
theorem cons_succ : cons y s i.succ = s i :=
rfl
@[simp]
theorem tail_cons : tail (cons y s) = s :=
ext fun k => by simp only [tail_apply, cons_succ]
@[simp]
theorem tail_update_zero : tail (update t 0 y) = tail t := by simp [tail]
@[simp]
theorem tail_update_succ : tail (update t i.succ y) = update (tail t) i y := by ext; simp [tail]
@[simp]
theorem cons_tail : cons (t 0) (tail t) = t := by
ext a
by_cases c_a : a = 0
· rw [c_a, cons_zero]
· rw [← Fin.succ_pred a c_a, cons_succ, ← tail_apply]
@[simp]
theorem cons_zero_zero : cons 0 (0 : Fin n →₀ M) = 0 := by
ext a
by_cases c : a = 0
· simp [c]
· rw [← Fin.succ_pred a c, cons_succ]
simp
variable {s} {y}
theorem cons_ne_zero_of_left (h : y ≠ 0) : cons y s ≠ 0 := by
contrapose! h with c
rw [← cons_zero y s, c, Finsupp.coe_zero, Pi.zero_apply]
theorem cons_ne_zero_of_right (h : s ≠ 0) : cons y s ≠ 0 := by
contrapose! h with c
ext a
simp [← cons_succ a y s, c]
theorem cons_ne_zero_iff : cons y s ≠ 0 ↔ y ≠ 0 ∨ s ≠ 0 := by
refine ⟨fun h => ?_, fun h => h.casesOn cons_ne_zero_of_left cons_ne_zero_of_right⟩
refine imp_iff_not_or.1 fun h' c => h ?_
rw [h', c, Finsupp.cons_zero_zero]
lemma cons_support : (s.cons y).support ⊆ insert 0 (s.support.map (Fin.succEmb n)) := by
intro i hi
suffices i = 0 ∨ ∃ a, ¬s a = 0 ∧ a.succ = i by simpa
apply (Fin.eq_zero_or_eq_succ i).imp id (Exists.imp _)
rintro i rfl
simpa [Finsupp.mem_support_iff] using hi
lemma cons_right_injective {n : ℕ} {M : Type*} [Zero M] (y : M) :
Injective (Finsupp.cons y : (Fin n →₀ M) → Fin (n + 1) →₀ M) :=
(equivFunOnFinite.symm.injective.comp ((Fin.cons_right_injective _).comp DFunLike.coe_injective))
end Finsupp
|
AesopUnusedTactic.lean
|
/-
Copyright (c) 2024 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jannis Limperg
-/
import Aesop
import Mathlib.Tactic.Linter.UnusedTactic
set_option linter.unusedTactic true
/-
The unused tactic linter should not consider tactics unused if they appear in
Aesop's `add_aesop_rules` command...
-/
add_aesop_rules safe (by simp)
/-
... or in an `add` clause.
-/
example : True := by
aesop (add safe (by simp))
|
Periodic.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth
-/
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
import Mathlib.MeasureTheory.Measure.Haar.Quotient
import Mathlib.MeasureTheory.Integral.IntervalIntegral.Basic
import Mathlib.Topology.Algebra.Order.Floor
import Mathlib.Topology.Instances.AddCircle.Real
/-!
# Integrals of periodic functions
In this file we prove that the half-open interval `Ioc t (t + T)` in `ℝ` is a fundamental domain of
the action of the subgroup `ℤ ∙ T` on `ℝ`.
A consequence is `AddCircle.measurePreserving_mk`: the covering map from `ℝ` to the "additive
circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving, with respect to the restriction of Lebesgue measure to
`Ioc t (t + T)` (upstairs) and with respect to Haar measure (downstairs).
Another consequence (`Function.Periodic.intervalIntegral_add_eq` and related declarations) is that
`∫ x in t..t + T, f x = ∫ x in s..s + T, f x` for any (not necessarily measurable) function with
period `T`.
-/
open Set Function MeasureTheory MeasureTheory.Measure TopologicalSpace AddSubgroup intervalIntegral
open scoped MeasureTheory NNReal ENNReal
/-!
## Measures and integrability on ℝ and on the circle
-/
@[measurability]
protected theorem AddCircle.measurable_mk' {a : ℝ} :
Measurable (β := AddCircle a) ((↑) : ℝ → AddCircle a) :=
Continuous.measurable <| AddCircle.continuous_mk' a
theorem isAddFundamentalDomain_Ioc {T : ℝ} (hT : 0 < T) (t : ℝ)
(μ : Measure ℝ := by volume_tac) :
IsAddFundamentalDomain (AddSubgroup.zmultiples T) (Ioc t (t + T)) μ := by
refine IsAddFundamentalDomain.mk' nullMeasurableSet_Ioc fun x => ?_
have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) :=
(Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_left_strictMono hT).injective).bijective
refine this.existsUnique_iff.2 ?_
simpa only [add_comm x] using existsUnique_add_zsmul_mem_Ioc hT x t
theorem isAddFundamentalDomain_Ioc' {T : ℝ} (hT : 0 < T) (t : ℝ) (μ : Measure ℝ := by volume_tac) :
IsAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) (Ioc t (t + T)) μ := by
refine IsAddFundamentalDomain.mk' nullMeasurableSet_Ioc fun x => ?_
have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) :=
(Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_left_strictMono hT).injective).bijective
refine (AddSubgroup.equivOp _).bijective.comp this |>.existsUnique_iff.2 ?_
simpa using existsUnique_add_zsmul_mem_Ioc hT x t
namespace AddCircle
variable (T : ℝ) [hT : Fact (0 < T)]
/-- Equip the "additive circle" `ℝ ⧸ (ℤ ∙ T)` with, as a standard measure, the Haar measure of total
mass `T` -/
noncomputable instance measureSpace : MeasureSpace (AddCircle T) :=
{ QuotientAddGroup.measurableSpace _ with volume := ENNReal.ofReal T • addHaarMeasure ⊤ }
@[simp]
protected theorem measure_univ : volume (Set.univ : Set (AddCircle T)) = ENNReal.ofReal T := by
dsimp [volume]
rw [← PositiveCompacts.coe_top]
simp [addHaarMeasure_self (G := AddCircle T), -PositiveCompacts.coe_top]
instance : IsAddHaarMeasure (volume : Measure (AddCircle T)) :=
IsAddHaarMeasure.smul _ (by simp [hT.out]) ENNReal.ofReal_ne_top
instance isFiniteMeasure : IsFiniteMeasure (volume : Measure (AddCircle T)) where
measure_univ_lt_top := by simp
instance : HasAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) ℝ where
ExistsIsAddFundamentalDomain := ⟨Ioc 0 (0 + T), isAddFundamentalDomain_Ioc' Fact.out 0⟩
instance : AddQuotientMeasureEqMeasurePreimage volume (volume : Measure (AddCircle T)) := by
apply MeasureTheory.leftInvariantIsAddQuotientMeasureEqMeasurePreimage
simp [(isAddFundamentalDomain_Ioc' hT.out 0).covolume_eq_volume, AddCircle.measure_univ]
/-- The covering map from `ℝ` to the "additive circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving,
considered with respect to the standard measure (defined to be the Haar measure of total mass `T`)
on the additive circle, and with respect to the restriction of Lebsegue measure on `ℝ` to an
interval (t, t + T]. -/
protected theorem measurePreserving_mk (t : ℝ) :
MeasurePreserving (β := AddCircle T) ((↑) : ℝ → AddCircle T)
(volume.restrict (Ioc t (t + T))) :=
measurePreserving_quotientAddGroup_mk_of_AddQuotientMeasureEqMeasurePreimage
volume (𝓕 := Ioc t (t+T)) (isAddFundamentalDomain_Ioc' hT.out _) _
lemma add_projection_respects_measure (t : ℝ) {U : Set (AddCircle T)} (meas_U : MeasurableSet U) :
volume U = volume (QuotientAddGroup.mk ⁻¹' U ∩ (Ioc t (t + T))) :=
(isAddFundamentalDomain_Ioc' hT.out _).addProjection_respects_measure_apply
(volume : Measure (AddCircle T)) meas_U
theorem volume_closedBall {x : AddCircle T} (ε : ℝ) :
volume (Metric.closedBall x ε) = ENNReal.ofReal (min T (2 * ε)) := by
have hT' : |T| = T := abs_eq_self.mpr hT.out.le
let I := Ioc (-(T / 2)) (T / 2)
have h₁ : ε < T / 2 → Metric.closedBall (0 : ℝ) ε ∩ I = Metric.closedBall (0 : ℝ) ε := by
intro hε
rw [inter_eq_left, Real.closedBall_eq_Icc, zero_sub, zero_add]
rintro y ⟨hy₁, hy₂⟩; constructor <;> linarith
have h₂ : (↑) ⁻¹' Metric.closedBall (0 : AddCircle T) ε ∩ I =
if ε < T / 2 then Metric.closedBall (0 : ℝ) ε else I := by
conv_rhs => rw [← if_ctx_congr (Iff.rfl : ε < T / 2 ↔ ε < T / 2) h₁ fun _ => rfl, ← hT']
apply coe_real_preimage_closedBall_inter_eq
simpa only [hT', Real.closedBall_eq_Icc, zero_add, zero_sub] using Ioc_subset_Icc_self
rw [addHaar_closedBall_center, add_projection_respects_measure T (-(T/2))
measurableSet_closedBall, (by linarith : -(T / 2) + T = T / 2), h₂]
by_cases hε : ε < T / 2
· simp [hε, min_eq_right (by linarith : 2 * ε ≤ T)]
· simp [I, hε, min_eq_left (by linarith : T ≤ 2 * ε)]
instance : IsUnifLocDoublingMeasure (volume : Measure (AddCircle T)) := by
refine ⟨⟨Real.toNNReal 2, Filter.Eventually.of_forall fun ε x => ?_⟩⟩
simp only [volume_closedBall]
erw [← ENNReal.ofReal_mul zero_le_two]
apply ENNReal.ofReal_le_ofReal
rw [mul_min_of_nonneg _ _ (zero_le_two : (0 : ℝ) ≤ 2)]
exact min_le_min (by linarith [hT.out]) (le_refl _)
/-- The isomorphism `AddCircle T ≃ Ioc a (a + T)` whose inverse is the natural quotient map,
as an equivalence of measurable spaces. -/
noncomputable def measurableEquivIoc (a : ℝ) : AddCircle T ≃ᵐ Ioc a (a + T) where
toEquiv := equivIoc T a
measurable_toFun := measurable_of_measurable_on_compl_singleton _
(continuousOn_iff_continuous_restrict.mp <| continuousOn_of_forall_continuousAt fun _x hx =>
continuousAt_equivIoc T a hx).measurable
measurable_invFun := AddCircle.measurable_mk'.comp measurable_subtype_coe
/-- The isomorphism `AddCircle T ≃ Ico a (a + T)` whose inverse is the natural quotient map,
as an equivalence of measurable spaces. -/
noncomputable def measurableEquivIco (a : ℝ) : AddCircle T ≃ᵐ Ico a (a + T) where
toEquiv := equivIco T a
measurable_toFun := measurable_of_measurable_on_compl_singleton _
(continuousOn_iff_continuous_restrict.mp <| continuousOn_of_forall_continuousAt fun _x hx =>
continuousAt_equivIco T a hx).measurable
measurable_invFun := AddCircle.measurable_mk'.comp measurable_subtype_coe
attribute [local instance] Subtype.measureSpace in
/-- The lower integral of a function over `AddCircle T` is equal to the lower integral over an
interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/
protected theorem lintegral_preimage (t : ℝ) (f : AddCircle T → ℝ≥0∞) :
(∫⁻ a in Ioc t (t + T), f a) = ∫⁻ b : AddCircle T, f b := by
have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc
have := lintegral_map_equiv (μ := volume) f (measurableEquivIoc T t).symm
simp only [measurableEquivIoc, equivIoc, QuotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk,
MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk] at this
rw [← (AddCircle.measurePreserving_mk T t).map_eq]
convert this.symm using 1
· rw [← map_comap_subtype_coe m _]
exact MeasurableEmbedding.lintegral_map (MeasurableEmbedding.subtype_coe m) _
· congr 1
have : ((↑) : Ioc t (t + T) → AddCircle T) = ((↑) : ℝ → AddCircle T) ∘ ((↑) : _ → ℝ) := by
ext1 x; rfl
simp_rw [this]
rw [← map_map AddCircle.measurable_mk' measurable_subtype_coe, ← map_comap_subtype_coe m]
rfl
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
attribute [local instance] Subtype.measureSpace in
/-- The integral of an almost-everywhere strongly measurable function over `AddCircle T` is equal
to the integral over an interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/
protected theorem integral_preimage (t : ℝ) (f : AddCircle T → E) :
(∫ a in Ioc t (t + T), f a) = ∫ b : AddCircle T, f b := by
have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc
have := integral_map_equiv (μ := volume) (measurableEquivIoc T t).symm f
simp only [measurableEquivIoc, equivIoc, QuotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk,
MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk] at this
rw [← (AddCircle.measurePreserving_mk T t).map_eq, ← integral_subtype m, ← this]
have : ((↑) : Ioc t (t + T) → AddCircle T) = ((↑) : ℝ → AddCircle T) ∘ ((↑) : _ → ℝ) := by
ext1 x; rfl
simp_rw [this]
rw [← map_map AddCircle.measurable_mk' measurable_subtype_coe, ← map_comap_subtype_coe m]
rfl
/-- The integral of an almost-everywhere strongly measurable function over `AddCircle T` is equal
to the integral over an interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/
protected theorem intervalIntegral_preimage (t : ℝ) (f : AddCircle T → E) :
∫ a in t..t + T, f a = ∫ b : AddCircle T, f b := by
rw [integral_of_le, AddCircle.integral_preimage T t f]
linarith [hT.out]
end AddCircle
namespace UnitAddCircle
attribute [local instance] Real.fact_zero_lt_one
protected theorem measure_univ : volume (Set.univ : Set UnitAddCircle) = 1 := by simp
/-- The covering map from `ℝ` to the "unit additive circle" `ℝ ⧸ ℤ` is measure-preserving,
considered with respect to the standard measure (defined to be the Haar measure of total mass 1)
on the additive circle, and with respect to the restriction of Lebsegue measure on `ℝ` to an
interval (t, t + 1]. -/
protected theorem measurePreserving_mk (t : ℝ) :
MeasurePreserving (β := UnitAddCircle) ((↑) : ℝ → UnitAddCircle)
(volume.restrict (Ioc t (t + 1))) :=
AddCircle.measurePreserving_mk 1 t
/-- The integral of a measurable function over `UnitAddCircle` is equal to the integral over an
interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/
protected theorem lintegral_preimage (t : ℝ) (f : UnitAddCircle → ℝ≥0∞) :
(∫⁻ a in Ioc t (t + 1), f a) = ∫⁻ b : UnitAddCircle, f b :=
AddCircle.lintegral_preimage 1 t f
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
/-- The integral of an almost-everywhere strongly measurable function over `UnitAddCircle` is
equal to the integral over an interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/
protected theorem integral_preimage (t : ℝ) (f : UnitAddCircle → E) :
(∫ a in Ioc t (t + 1), f a) = ∫ b : UnitAddCircle, f b :=
AddCircle.integral_preimage 1 t f
/-- The integral of an almost-everywhere strongly measurable function over `UnitAddCircle` is
equal to the integral over an interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/
protected theorem intervalIntegral_preimage (t : ℝ) (f : UnitAddCircle → E) :
∫ a in t..t + 1, f a = ∫ b : UnitAddCircle, f b :=
AddCircle.intervalIntegral_preimage 1 t f
end UnitAddCircle
/-!
## Interval integrability of periodic functions
-/
namespace Function
namespace Periodic
variable {E : Type*} [NormedAddCommGroup E]
variable {f : ℝ → E} {T : ℝ}
/-- A periodic function is interval integrable over every interval if it is interval integrable
over one period. -/
theorem intervalIntegrable {t : ℝ} (h₁f : Function.Periodic f T)
(hT : 0 < T) (hT' : ‖f (min t (t + T))‖ₑ ≠ ∞ := by finiteness)
(h₂f : IntervalIntegrable f MeasureTheory.volume t (t + T)) (a₁ a₂ : ℝ) :
IntervalIntegrable f MeasureTheory.volume a₁ a₂ := by
-- Replace [a₁, a₂] by [t - n₁ * T, t + n₂ * T], where n₁ and n₂ are natural numbers
obtain ⟨n₁, hn₁⟩ := exists_nat_ge ((t - min a₁ a₂) / T)
obtain ⟨n₂, hn₂⟩ := exists_nat_ge ((max a₁ a₂ - t) / T)
have : Set.uIcc a₁ a₂ ⊆ Set.uIcc (t - n₁ * T) (t + n₂ * T) := by
rw [Set.uIcc_subset_uIcc_iff_le]
constructor
· calc min (t - n₁ * T) (t + n₂ * T)
_ ≤ (t - n₁ * T) := by apply min_le_left
_ ≤ min a₁ a₂ := by linarith [(div_le_iff₀ hT).1 hn₁]
· calc max a₁ a₂
_ ≤ t + n₂ * T := by linarith [(div_le_iff₀ hT).1 hn₂]
_ ≤ max (t - n₁ * T) (t + n₂ * T) := by apply le_max_right
apply IntervalIntegrable.mono_set _ this
-- Suffices to show integrability over shifted periods
let a : ℕ → ℝ := fun n ↦ t + (n - n₁) * T
rw [(by ring : t - n₁ * T = a 0), (by simp [a] : t + n₂ * T = a (n₁ + n₂))]
apply IntervalIntegrable.trans_iterate
-- Show integrability over a shifted period
intro k hk
convert (IntervalIntegrable.comp_sub_right h₂f ((k - n₁) * T) hT') using 1
· funext x
simpa using (h₁f.sub_int_mul_eq (k - n₁)).symm
· simp [a, Nat.cast_add]
ring
/-- Special case of Function.Periodic.intervalIntegrable: A periodic function is interval integrable
over every interval if it is interval integrable over the period starting from zero. -/
theorem intervalIntegrable₀ (h₁f : Function.Periodic f T) (hT : 0 < T)
(h₂f : IntervalIntegrable f MeasureTheory.volume 0 T) (a₁ a₂ : ℝ) :
IntervalIntegrable f MeasureTheory.volume a₁ a₂ := by
apply h₁f.intervalIntegrable hT (t := 0)
simpa
/-!
## Interval integrals of periodic functions
-/
variable [NormedSpace ℝ E]
/-- An auxiliary lemma for a more general `Function.Periodic.intervalIntegral_add_eq`. -/
theorem intervalIntegral_add_eq_of_pos (hf : Periodic f T) (hT : 0 < T) (t s : ℝ) :
∫ x in t..t + T, f x = ∫ x in s..s + T, f x := by
simp only [integral_of_le, hT.le, le_add_iff_nonneg_right]
haveI : VAddInvariantMeasure (AddSubgroup.zmultiples T) ℝ volume :=
⟨fun c s _ => measure_preimage_add _ _ _⟩
apply IsAddFundamentalDomain.setIntegral_eq (G := AddSubgroup.zmultiples T)
exacts [isAddFundamentalDomain_Ioc hT t, isAddFundamentalDomain_Ioc hT s, hf.map_vadd_zmultiples]
/-- If `f` is a periodic function with period `T`, then its integral over `[t, t + T]` does not
depend on `t`. -/
theorem intervalIntegral_add_eq (hf : Periodic f T) (t s : ℝ) :
∫ x in t..t + T, f x = ∫ x in s..s + T, f x := by
rcases lt_trichotomy (0 : ℝ) T with (hT | rfl | hT)
· exact hf.intervalIntegral_add_eq_of_pos hT t s
· simp
· rw [← neg_inj, ← integral_symm, ← integral_symm]
simpa only [← sub_eq_add_neg, add_sub_cancel_right] using
hf.neg.intervalIntegral_add_eq_of_pos (neg_pos.2 hT) (t + T) (s + T)
/-- If `f` is an integrable periodic function with period `T`, then its integral over `[t, s + T]`
is the sum of its integrals over the intervals `[t, s]` and `[t, t + T]`. -/
theorem intervalIntegral_add_eq_add (hf : Periodic f T) (t s : ℝ)
(h_int : ∀ t₁ t₂, IntervalIntegrable f MeasureSpace.volume t₁ t₂) :
∫ x in t..s + T, f x = (∫ x in t..s, f x) + ∫ x in t..t + T, f x := by
rw [hf.intervalIntegral_add_eq t s, integral_add_adjacent_intervals (h_int t s) (h_int s _)]
/-- If `f` is an integrable periodic function with period `T`, and `n` is an integer, then its
integral over `[t, t + n • T]` is `n` times its integral over `[t, t + T]`. -/
theorem intervalIntegral_add_zsmul_eq (hf : Periodic f T) (n : ℤ) (t : ℝ)
(h_int : ∀ t₁ t₂, IntervalIntegrable f MeasureSpace.volume t₁ t₂) :
∫ x in t..t + n • T, f x = n • ∫ x in t..t + T, f x := by
-- Reduce to the case `b = 0`
suffices (∫ x in (0)..(n • T), f x) = n • ∫ x in (0)..T, f x by
simp only [hf.intervalIntegral_add_eq t 0, (hf.zsmul n).intervalIntegral_add_eq t 0, zero_add,
this]
-- First prove it for natural numbers
have : ∀ m : ℕ, (∫ x in (0)..m • T, f x) = m • ∫ x in (0)..T, f x := fun m ↦ by
induction m with
| zero => simp
| succ m ih =>
simp only [succ_nsmul, hf.intervalIntegral_add_eq_add 0 (m • T) h_int, ih, zero_add]
-- Then prove it for all integers
rcases n with n | n
· simp [← this n]
· conv_rhs => rw [negSucc_zsmul]
have h₀ : Int.negSucc n • T + (n + 1) • T = 0 := by simp; linarith
rw [integral_symm, ← (hf.nsmul (n + 1)).funext, neg_inj]
simp_rw [integral_comp_add_right, h₀, zero_add, this (n + 1), add_comm T,
hf.intervalIntegral_add_eq ((n + 1) • T) 0, zero_add]
section RealValued
open Filter
variable {g : ℝ → ℝ}
variable (hg : Periodic g T)
include hg
/-- If `g : ℝ → ℝ` is periodic with period `T > 0`, then for any `t : ℝ`, the function
`t ↦ ∫ x in 0..t, g x` is bounded below by `t ↦ X + ⌊t/T⌋ • Y` for appropriate constants `X` and
`Y`. -/
theorem sInf_add_zsmul_le_integral_of_pos (h_int : IntervalIntegrable g MeasureSpace.volume 0 T)
(hT : 0 < T) (t : ℝ) :
(sInf ((fun t => ∫ x in (0)..t, g x) '' Icc 0 T) + ⌊t / T⌋ • ∫ x in (0)..T, g x) ≤
∫ x in (0)..t, g x := by
let h'_int := hg.intervalIntegrable₀ hT h_int
let ε := Int.fract (t / T) * T
conv_rhs =>
rw [← Int.fract_div_mul_self_add_zsmul_eq T t (by linarith),
← integral_add_adjacent_intervals (h'_int 0 ε) (h'_int _ _)]
rw [hg.intervalIntegral_add_zsmul_eq ⌊t / T⌋ ε (hg.intervalIntegrable₀ hT h_int),
hg.intervalIntegral_add_eq ε 0, zero_add, add_le_add_iff_right]
exact (continuous_primitive h'_int 0).continuousOn.sInf_image_Icc_le <|
mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT)
/-- If `g : ℝ → ℝ` is periodic with period `T > 0`, then for any `t : ℝ`, the function
`t ↦ ∫ x in 0..t, g x` is bounded above by `t ↦ X + ⌊t/T⌋ • Y` for appropriate constants `X` and
`Y`. -/
theorem integral_le_sSup_add_zsmul_of_pos (h_int : IntervalIntegrable g MeasureSpace.volume 0 T)
(hT : 0 < T) (t : ℝ) :
(∫ x in (0)..t, g x) ≤
sSup ((fun t => ∫ x in (0)..t, g x) '' Icc 0 T) + ⌊t / T⌋ • ∫ x in (0)..T, g x := by
let h'_int := hg.intervalIntegrable₀ hT h_int
let ε := Int.fract (t / T) * T
conv_lhs =>
rw [← Int.fract_div_mul_self_add_zsmul_eq T t (by linarith), ←
integral_add_adjacent_intervals (h'_int 0 ε) (h'_int _ _)]
rw [hg.intervalIntegral_add_zsmul_eq ⌊t / T⌋ ε h'_int, hg.intervalIntegral_add_eq ε 0, zero_add,
add_le_add_iff_right]
exact (continuous_primitive h'_int 0).continuousOn.le_sSup_image_Icc
(mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT))
/-- If `g : ℝ → ℝ` is periodic with period `T > 0` and `0 < ∫ x in 0..T, g x`, then
`t ↦ ∫ x in 0..t, g x` tends to `∞` as `t` tends to `∞`. -/
theorem tendsto_atTop_intervalIntegral_of_pos (h₀ : 0 < ∫ x in (0)..T, g x) (hT : 0 < T) :
Tendsto (fun t => ∫ x in (0)..t, g x) atTop atTop := by
have h_int := intervalIntegrable_of_integral_ne_zero h₀.ne'
apply tendsto_atTop_mono (hg.sInf_add_zsmul_le_integral_of_pos h_int hT)
apply atTop.tendsto_atTop_add_const_left (sInf <| (fun t => ∫ x in (0)..t, g x) '' Icc 0 T)
apply Tendsto.atTop_zsmul_const h₀
exact tendsto_floor_atTop.comp (tendsto_id.atTop_mul_const (inv_pos.mpr hT))
/-- If `g : ℝ → ℝ` is periodic with period `T > 0` and `0 < ∫ x in 0..T, g x`, then
`t ↦ ∫ x in 0..t, g x` tends to `-∞` as `t` tends to `-∞`. -/
theorem tendsto_atBot_intervalIntegral_of_pos (h₀ : 0 < ∫ x in (0)..T, g x) (hT : 0 < T) :
Tendsto (fun t => ∫ x in (0)..t, g x) atBot atBot := by
have h_int := intervalIntegrable_of_integral_ne_zero h₀.ne'
apply tendsto_atBot_mono (hg.integral_le_sSup_add_zsmul_of_pos h_int hT)
apply atBot.tendsto_atBot_add_const_left (sSup <| (fun t => ∫ x in (0)..t, g x) '' Icc 0 T)
apply Tendsto.atBot_zsmul_const h₀
exact tendsto_floor_atBot.comp (tendsto_id.atBot_mul_const (inv_pos.mpr hT))
/-- If `g : ℝ → ℝ` is periodic with period `T > 0` and `∀ x, 0 < g x`, then `t ↦ ∫ x in 0..t, g x`
tends to `∞` as `t` tends to `∞`. -/
theorem tendsto_atTop_intervalIntegral_of_pos'
(h_int : IntervalIntegrable g MeasureSpace.volume 0 T) (h₀ : ∀ x, 0 < g x) (hT : 0 < T) :
Tendsto (fun t => ∫ x in (0)..t, g x) atTop atTop :=
hg.tendsto_atTop_intervalIntegral_of_pos (intervalIntegral_pos_of_pos h_int h₀ hT) hT
/-- If `g : ℝ → ℝ` is periodic with period `T > 0` and `∀ x, 0 < g x`, then `t ↦ ∫ x in 0..t, g x`
tends to `-∞` as `t` tends to `-∞`. -/
theorem tendsto_atBot_intervalIntegral_of_pos'
(h_int : IntervalIntegrable g MeasureSpace.volume 0 T) (h₀ : ∀ x, 0 < g x) (hT : 0 < T) :
Tendsto (fun t => ∫ x in (0)..t, g x) atBot atBot := by
exact hg.tendsto_atBot_intervalIntegral_of_pos (intervalIntegral_pos_of_pos h_int h₀ hT) hT
end RealValued
end Periodic
end Function
|
Imo2013Q1.lean
|
/-
Copyright (c) 2021 David Renshaw. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Renshaw
-/
import Mathlib.Algebra.BigOperators.Group.Finset.Powerset
import Mathlib.Algebra.Order.Field.Rat
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Positivity.Basic
import Mathlib.Tactic.Ring
/-!
# IMO 2013 Q1
Prove that for any pair of positive integers k and n, there exist k positive integers
m₁, m₂, ..., mₖ (not necessarily different) such that
1 + (2ᵏ - 1)/ n = (1 + 1/m₁) * (1 + 1/m₂) * ... * (1 + 1/mₖ).
# Solution
Adaptation of the solution found in https://www.imo-official.org/problems/IMO2013SL.pdf
We prove a slightly more general version where k does not need to be strictly positive.
-/
namespace Imo2013Q1
theorem arith_lemma (k n : ℕ) : 0 < 2 * n + 2 ^ k.succ := by positivity
theorem prod_lemma (m : ℕ → ℕ+) (k : ℕ) (nm : ℕ+) :
∏ i ∈ Finset.range k, ((1 : ℚ) + 1 / ↑(if i < k then m i else nm)) =
∏ i ∈ Finset.range k, (1 + 1 / (m i : ℚ)) := by
suffices ∀ i, i ∈ Finset.range k → (1 : ℚ) + 1 / ↑(if i < k then m i else nm) = 1 + 1 / m i from
Finset.prod_congr rfl this
grind
end Imo2013Q1
open Imo2013Q1
theorem imo2013_q1 (n : ℕ+) (k : ℕ) :
∃ m : ℕ → ℕ+, (1 : ℚ) + (2 ^ k - 1) / n = ∏ i ∈ Finset.range k, (1 + 1 / (m i : ℚ)) := by
induction k generalizing n with
| zero => use fun (_ : ℕ) => (1 : ℕ+); simp -- For the base case, any m works.
| succ pk hpk =>
obtain ⟨t, ht : ↑n = t + t⟩ | ⟨t, ht : ↑n = 2 * t + 1⟩ := (n : ℕ).even_or_odd
· -- even case
rw [← two_mul] at ht
-- Eliminate the zero case to simplify later calculations.
obtain ⟨t, rfl⟩ := Nat.exists_eq_succ_of_ne_zero <| by
rintro (rfl : t = 0)
rw [Nat.mul_zero] at ht; exact PNat.ne_zero n ht
-- Now we have ht : ↑n = 2 * (t + 1).
let t_succ : ℕ+ := ⟨t + 1, t.succ_pos⟩
obtain ⟨pm, hpm⟩ := hpk t_succ
let m i := if i < pk then pm i else ⟨2 * t + 2 ^ pk.succ, arith_lemma pk t⟩
use m
have hmpk : (m pk : ℚ) = 2 * t + 2 ^ pk.succ := by
have : m pk = ⟨2 * t + 2 ^ pk.succ, _⟩ := if_neg (irrefl pk); simp [this]
calc
((1 : ℚ) + (2 ^ pk.succ - 1) / (n : ℚ) : ℚ)= 1 + (2 * 2 ^ pk - 1) / (2 * (t + 1) : ℕ) := by
rw [ht, pow_succ']
_ = (1 + 1 / (2 * t + 2 * 2 ^ pk)) * (1 + (2 ^ pk - 1) / (↑t + 1)) := by
field_simp
ring
_ = (1 + 1 / (2 * t + 2 ^ pk.succ)) * (1 + (2 ^ pk - 1) / t_succ) := by
simp [pow_succ', PNat.mk_coe, t_succ]
_ = (∏ i ∈ Finset.range pk, (1 + 1 / (m i : ℚ))) * (1 + 1 / m pk) := by
rw [prod_lemma, hpm, ← hmpk, mul_comm]
_ = ∏ i ∈ Finset.range pk.succ, (1 + 1 / (m i : ℚ)) := by rw [← Finset.prod_range_succ _ pk]
· -- odd case
let t_succ : ℕ+ := ⟨t + 1, t.succ_pos⟩
obtain ⟨pm, hpm⟩ := hpk t_succ
let m i := if i < pk then pm i else ⟨2 * t + 1, Nat.succ_pos _⟩
use m
have hmpk : (m pk : ℚ) = 2 * t + 1 := by
have : m pk = ⟨2 * t + 1, _⟩ := if_neg (irrefl pk)
simp [this]
calc
((1 : ℚ) + (2 ^ pk.succ - 1) / ↑n : ℚ) = 1 + (2 * 2 ^ pk - 1) / (2 * t + 1 : ℕ) := by
rw [ht, pow_succ']
_ = (1 + 1 / (2 * t + 1)) * (1 + (2 ^ pk - 1) / (t + 1)) := by
field_simp
ring
_ = (1 + 1 / (2 * t + 1)) * (1 + (2 ^ pk - 1) / t_succ) := by norm_cast
_ = (∏ i ∈ Finset.range pk, (1 + 1 / (m i : ℚ))) * (1 + 1 / ↑(m pk)) := by
rw [prod_lemma, hpm, ← hmpk, mul_comm]
_ = ∏ i ∈ Finset.range pk.succ, (1 + 1 / (m i : ℚ)) := by rw [← Finset.prod_range_succ _ pk]
|
IsGaloisGroup.lean
|
/-
Copyright (c) 2025 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.FieldTheory.Galois.Basic
import Mathlib.RingTheory.Invariant.Defs
/-!
# Predicate for Galois Groups
Given an action of a group `G` on an extension of fields `L/K`, we introduce a predicate
`IsGaloisGroup G K L` saying that `G` acts faithfully on `L` with fixed field `K`. In particular,
we do not assume that `L` is an algebraic extension of `K`.
-/
variable (G H K L : Type*) [Group G] [Group H] [Field K] [Field L] [Algebra K L]
[MulSemiringAction G L] [MulSemiringAction H L]
/-- `G` is a Galois group for `L/K` if the action on `L` is faithful with fixed field `K`.
In particular, we do not assume that `L` is an algebraic extension of `K`. -/
class IsGaloisGroup where
faithful : FaithfulSMul G L
commutes : SMulCommClass G K L
isInvariant : Algebra.IsInvariant K L G
namespace IsGaloisGroup
attribute [instance low] commutes isInvariant
theorem fixedPoints_eq_bot [IsGaloisGroup G K L] :
FixedPoints.intermediateField G = (⊥ : IntermediateField K L) := by
rw [eq_bot_iff]
exact Algebra.IsInvariant.isInvariant
/-- If `G` is a finite Galois group for `L/K`, then `L/K` is a Galois extension. -/
theorem isGalois [Finite G] [IsGaloisGroup G K L] : IsGalois K L := by
rw [← isGalois_iff_isGalois_bot, ← fixedPoints_eq_bot G]
exact IsGalois.of_fixed_field L G
/-- If `L/K` is a finite Galois extension, then `L ≃ₐ[K] L` is a Galois group for `L/K`. -/
instance of_isGalois [FiniteDimensional K L] [IsGalois K L] : IsGaloisGroup (L ≃ₐ[K] L) K L where
faithful := inferInstance
commutes := inferInstance
isInvariant := ⟨fun x ↦ (IsGalois.mem_bot_iff_fixed x).mpr⟩
theorem card_eq_finrank [IsGaloisGroup G K L] : Nat.card G = Module.finrank K L := by
rcases fintypeOrInfinite G with _ | hG
· have : FaithfulSMul G L := faithful K
rw [← IntermediateField.finrank_bot', ← fixedPoints_eq_bot G, Nat.card_eq_fintype_card]
exact (FixedPoints.finrank_eq_card G L).symm
· rw [Nat.card_eq_zero_of_infinite, eq_comm]
contrapose! hG
rw [not_infinite_iff_finite]
have : FiniteDimensional K L := FiniteDimensional.of_finrank_pos (Nat.zero_lt_of_ne_zero hG)
exact Finite.of_injective (MulSemiringAction.toAlgAut G K L)
(fun _ _ ↦ (faithful K).eq_of_smul_eq_smul ∘ DFunLike.ext_iff.mp)
theorem finiteDimensional [Finite G] [IsGaloisGroup G K L] : FiniteDimensional K L :=
FiniteDimensional.of_finrank_pos (card_eq_finrank G K L ▸ Nat.card_pos)
/-- If `G` is a finite Galois group for `L/K`, then `G` is isomorphic to `L ≃ₐ[K] L`. -/
@[simps!] noncomputable def mulEquivAlgEquiv [IsGaloisGroup G K L] [Finite G] : G ≃* (L ≃ₐ[K] L) :=
MulEquiv.ofBijective (MulSemiringAction.toAlgAut G K L) (by
have := isGalois G K L
have := finiteDimensional G K L
rw [Nat.bijective_iff_injective_and_card, card_eq_finrank G K L,
IsGalois.card_aut_eq_finrank K L]
exact ⟨fun _ _ ↦ (faithful K).eq_of_smul_eq_smul ∘ DFunLike.ext_iff.mp, rfl⟩)
/-- If `G` and `H` are finite Galois groups for `L/K`, then `G` is isomorphic to `H`. -/
noncomputable def mulEquivCongr [IsGaloisGroup G K L] [Finite G]
[IsGaloisGroup H K L] [Finite H] : G ≃* H :=
(mulEquivAlgEquiv G K L).trans (mulEquivAlgEquiv H K L).symm
@[simp]
theorem mulEquivCongr_apply_smul [IsGaloisGroup G K L] [Finite G] [IsGaloisGroup H K L] [Finite H]
(g : G) (x : L) : mulEquivCongr G H K L g • x = g • x :=
AlgEquiv.ext_iff.mp ((mulEquivAlgEquiv H K L).apply_symm_apply (mulEquivAlgEquiv G K L g)) x
end IsGaloisGroup
|
Module.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
import Mathlib.Algebra.Category.AlgCat.Basic
import Mathlib.CategoryTheory.Monoidal.Mon_
/-!
# `Mon_ (ModuleCat R) ≌ AlgCat R`
The category of internal monoid objects in `ModuleCat R`
is equivalent to the category of "native" bundled `R`-algebras.
Moreover, this equivalence is compatible with the forgetful functors to `ModuleCat R`.
-/
suppress_compilation
universe v u
open CategoryTheory
open LinearMap Mon_Class
open scoped TensorProduct
attribute [local ext] TensorProduct.ext
namespace ModuleCat
variable {R : Type u} [CommRing R]
namespace MonModuleEquivalenceAlgebra
-- Porting note: in the following proof `have := ...; convert this` is to help Lean infer what the
-- underlying rings are.
-- Porting note: `simps(!)` doesn't work, I guess we will see what `simp` lemmas are needed and
-- add them manually
-- @[simps!]
instance Ring_of_Mon_ (A : ModuleCat.{u} R) [Mon_Class A] : Ring A :=
{ (inferInstance : AddCommGroup A) with
one := η[A] (1 : R)
mul := fun x y => μ[A] (x ⊗ₜ y)
one_mul := fun x => by
convert LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (one_mul A)) ((1 : R) ⊗ₜ x)
rw [MonoidalCategory.leftUnitor_hom_apply, one_smul]
mul_one := fun x => by
convert LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (mul_one A)) (x ⊗ₜ (1 : R))
rw [MonoidalCategory.rightUnitor_hom_apply, one_smul]
mul_assoc := fun x y z => by
convert LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (mul_assoc A)) (x ⊗ₜ y ⊗ₜ z)
left_distrib := fun x y z => by
convert μ[A].hom.map_add (x ⊗ₜ y) (x ⊗ₜ z)
rw [← TensorProduct.tmul_add]
rfl
right_distrib := fun x y z => by
convert μ[A].hom.map_add (x ⊗ₜ z) (y ⊗ₜ z)
rw [← TensorProduct.add_tmul]
rfl
zero_mul := fun x => show μ[A] _ = 0 by
rw [TensorProduct.zero_tmul, map_zero]
mul_zero := fun x => show μ[A] _ = 0 by
rw [TensorProduct.tmul_zero, map_zero] }
instance Algebra_of_Mon_ (A : ModuleCat.{u} R) [Mon_Class A] : Algebra R A where
algebraMap :=
{ η[A].hom with
map_zero' := η[A].hom.map_zero
map_one' := rfl
map_mul' := fun x y => by
have h := LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (one_mul A).symm) (x ⊗ₜ η[A] y)
rwa [MonoidalCategory.leftUnitor_hom_apply, ← η[A].hom.map_smul] at h }
commutes' := fun r a => by
dsimp
have h₁ := LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (one_mul A)) (r ⊗ₜ a)
have h₂ := LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (mul_one A)) (a ⊗ₜ r)
exact h₁.trans h₂.symm
smul_def' := fun r a =>
(LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (one_mul A)) (r ⊗ₜ a)).symm
@[simp]
theorem algebraMap (A : ModuleCat.{u} R) [Mon_Class A] (r : R) : algebraMap R A r = η[A] r :=
rfl
/-- Converting a monoid object in `ModuleCat R` to a bundled algebra.
-/
@[simps!]
def functor : Mon_ (ModuleCat.{u} R) ⥤ AlgCat R where
obj A := AlgCat.of R A.X
map {_ _} f := AlgCat.ofHom
{ f.hom.hom.toAddMonoidHom with
toFun := f.hom
map_one' := LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (IsMon_Hom.one_hom f.hom)) (1 : R)
map_mul' := fun x y =>
LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (IsMon_Hom.mul_hom f.hom)) (x ⊗ₜ y)
commutes' := fun r =>
LinearMap.congr_fun (ModuleCat.hom_ext_iff.mp (IsMon_Hom.one_hom f.hom)) r }
/-- Converting a bundled algebra to a monoid object in `ModuleCat R`.
-/
@[simps]
def inverseObj (A : AlgCat.{u} R) : Mon_Class (ModuleCat.of R A) where
one := ofHom <| Algebra.linearMap R A
mul := ofHom <| LinearMap.mul' R A
one_mul := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `TensorProduct.ext`
refine TensorProduct.ext <| LinearMap.ext_ring <| LinearMap.ext fun x => ?_
rw [compr₂_apply, compr₂_apply, hom_comp, LinearMap.comp_apply]
-- Porting note: this `dsimp` does nothing
-- dsimp [AlgCat.id_apply, TensorProduct.mk_apply, Algebra.linearMap_apply,
-- LinearMap.compr₂_apply, Function.comp_apply, RingHom.map_one,
-- ModuleCat.MonoidalCategory.tensorHom_tmul, AlgCat.hom_comp,
-- ModuleCat.MonoidalCategory.leftUnitor_hom_apply]
-- Porting note: because `dsimp` is not effective, `rw` needs to be changed to `erw`
dsimp
erw [LinearMap.mul'_apply, MonoidalCategory.leftUnitor_hom_apply, ← Algebra.smul_def]
dsimp
mul_one := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `TensorProduct.ext`
refine TensorProduct.ext <| LinearMap.ext fun x => LinearMap.ext_ring ?_
-- Porting note: this `dsimp` does nothing
-- dsimp only [AlgCat.id_apply, TensorProduct.mk_apply, Algebra.linearMap_apply,
-- LinearMap.compr₂_apply, Function.comp_apply, ModuleCat.MonoidalCategory.hom_apply,
-- AlgCat.coe_comp]
-- Porting note: because `dsimp` is not effective, `rw` needs to be changed to `erw`
erw [compr₂_apply, compr₂_apply]
rw [ModuleCat.hom_comp, LinearMap.comp_apply]
erw [LinearMap.mul'_apply, ModuleCat.MonoidalCategory.rightUnitor_hom_apply, ← Algebra.commutes,
← Algebra.smul_def]
dsimp
mul_assoc := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `TensorProduct.ext`
refine TensorProduct.ext <| TensorProduct.ext <| LinearMap.ext fun x => LinearMap.ext fun y =>
LinearMap.ext fun z => ?_
dsimp only [compr₂_apply, TensorProduct.mk_apply]
rw [hom_comp, LinearMap.comp_apply, hom_comp, LinearMap.comp_apply, hom_comp,
LinearMap.comp_apply]
erw [LinearMap.mul'_apply, LinearMap.mul'_apply]
dsimp only [id_coe, id_eq]
erw [TensorProduct.mk_apply, TensorProduct.mk_apply, mul'_apply, LinearMap.id_apply, mul'_apply]
simp only [_root_.mul_assoc]
attribute [local instance] inverseObj
/-- Converting a bundled algebra to a monoid object in `ModuleCat R`.
-/
@[simps]
def inverse : AlgCat.{u} R ⥤ Mon_ (ModuleCat.{u} R) where
obj A := { X := ModuleCat.of R A, mon := inverseObj A}
map f :=
{ hom := ofHom <| f.hom.toLinearMap
is_mon_hom :=
{ one_hom := hom_ext <| LinearMap.ext f.hom.commutes
mul_hom := hom_ext <| TensorProduct.ext <| LinearMap.ext₂ <| map_mul f.hom } }
end MonModuleEquivalenceAlgebra
open MonModuleEquivalenceAlgebra
/-- The category of internal monoid objects in `ModuleCat R`
is equivalent to the category of "native" bundled `R`-algebras.
-/
def monModuleEquivalenceAlgebra : Mon_ (ModuleCat.{u} R) ≌ AlgCat R where
functor := functor
inverse := inverse
unitIso :=
NatIso.ofComponents
(fun A =>
{ hom :=
{ hom := ofHom
{ toFun := _root_.id
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
is_mon_hom :=
{ mul_hom := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `TensorProduct.ext`
refine TensorProduct.ext ?_
rfl } }
inv :=
{ hom := ofHom
{ toFun := _root_.id
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
is_mon_hom :=
{ mul_hom := by
ext : 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): `ext` did not pick up `TensorProduct.ext`
refine TensorProduct.ext ?_
rfl } } })
counitIso :=
NatIso.ofComponents
(fun A =>
{ hom := AlgCat.ofHom
{ toFun := _root_.id
map_zero' := rfl
map_add' := fun _ _ => rfl
map_one' := (algebraMap R A).map_one
map_mul' := fun x y => @LinearMap.mul'_apply R _ _ _ _ _ _ x y
commutes' := fun _ => rfl }
inv := AlgCat.ofHom
{ toFun := _root_.id
map_zero' := rfl
map_add' := fun _ _ => rfl
map_one' := (algebraMap R A).map_one.symm
map_mul' := fun x y => (@LinearMap.mul'_apply R _ _ _ _ _ _ x y).symm
commutes' := fun _ => rfl } })
/-- The equivalence `Mon_ (ModuleCat R) ≌ AlgCat R`
is naturally compatible with the forgetful functors to `ModuleCat R`.
-/
def monModuleEquivalenceAlgebraForget :
MonModuleEquivalenceAlgebra.functor ⋙ forget₂ (AlgCat.{u} R) (ModuleCat.{u} R) ≅
Mon_.forget (ModuleCat.{u} R) :=
NatIso.ofComponents
(fun A =>
{ hom := ofHom
{ toFun := _root_.id
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
inv := ofHom
{ toFun := _root_.id
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl } })
end ModuleCat
|
Basic.lean
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1
/-! # Conditional expectation
We build the conditional expectation of an integrable function `f` with value in a Banach space
with respect to a measure `μ` (defined on a measurable space structure `m₀`) and a measurable space
structure `m` with `hm : m ≤ m₀` (a sub-sigma-algebra). This is an `m`-strongly measurable
function `μ[f|hm]` which is integrable and verifies `∫ x in s, μ[f|hm] x ∂μ = ∫ x in s, f x ∂μ`
for all `m`-measurable sets `s`. It is unique as an element of `L¹`.
The construction is done in four steps:
* Define the conditional expectation of an `L²` function, as an element of `L²`. This is the
orthogonal projection on the subspace of almost everywhere `m`-measurable functions.
* Show that the conditional expectation of the indicator of a measurable set with finite measure
is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear
map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set
with value `x`.
* Extend that map to `condExpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same
construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`).
* Define the conditional expectation of a function `f : α → E`, which is an integrable function
`α → E` equal to 0 if `f` is not integrable, and equal to an `m`-measurable representative of
`condExpL1CLM` applied to `[f]`, the equivalence class of `f` in `L¹`.
The first step is done in `MeasureTheory.Function.ConditionalExpectation.CondexpL2`, the two
next steps in `MeasureTheory.Function.ConditionalExpectation.CondexpL1` and the final step is
performed in this file.
## Main results
The conditional expectation and its properties
* `condExp (m : MeasurableSpace α) (μ : Measure α) (f : α → E)`: conditional expectation of `f`
with respect to `m`.
* `integrable_condExp` : `condExp` is integrable.
* `stronglyMeasurable_condExp` : `condExp` is `m`-strongly-measurable.
* `setIntegral_condExp (hf : Integrable f μ) (hs : MeasurableSet[m] s)` : if `m ≤ m₀` (the
σ-algebra over which the measure is defined), then the conditional expectation verifies
`∫ x in s, condExp m μ f x ∂μ = ∫ x in s, f x ∂μ` for any `m`-measurable set `s`.
While `condExp` is function-valued, we also define `condExpL1` with value in `L1` and a continuous
linear map `condExpL1CLM` from `L1` to `L1`. `condExp` should be used in most cases.
Uniqueness of the conditional expectation
* `ae_eq_condExp_of_forall_setIntegral_eq`: an a.e. `m`-measurable function which verifies the
equality of integrals is a.e. equal to `condExp`.
## Notations
For a measure `μ` defined on a measurable space structure `m₀`, another measurable space structure
`m` with `hm : m ≤ m₀` (a sub-σ-algebra) and a function `f`, we define the notation
* `μ[f|m] = condExp m μ f`.
## TODO
See https://leanprover.zulipchat.com/#narrow/channel/217875-Is-there-code-for-X.3F/topic/Conditional.20expectation.20of.20product
for how to prove that we can pull `m`-measurable continuous linear maps out of the `m`-conditional
expectation. This would generalise `MeasureTheory.condExp_mul_of_stronglyMeasurable_left`.
## Tags
conditional expectation, conditional expected value
-/
open TopologicalSpace MeasureTheory.Lp Filter
open scoped ENNReal Topology MeasureTheory
namespace MeasureTheory
-- 𝕜 for ℝ or ℂ
-- E for integrals on a Lp submodule
variable {α β E 𝕜 : Type*} [RCLike 𝕜] {m m₀ : MeasurableSpace α} {μ : Measure α} {f g : α → E}
{s : Set α}
section NormedAddCommGroup
variable [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E]
open scoped Classical in
variable (m) in
/-- Conditional expectation of a function, with notation `μ[f|m]`.
It is defined as 0 if any one of the following conditions is true:
- `m` is not a sub-σ-algebra of `m₀`,
- `μ` is not σ-finite with respect to `m`,
- `f` is not integrable. -/
noncomputable irreducible_def condExp (μ : Measure[m₀] α) (f : α → E) : α → E :=
if hm : m ≤ m₀ then
if h : SigmaFinite (μ.trim hm) ∧ Integrable f μ then
if StronglyMeasurable[m] f then f
else have := h.1; aestronglyMeasurable_condExpL1.mk (condExpL1 hm μ f)
else 0
else 0
@[inherit_doc MeasureTheory.condExp]
scoped macro:max μ:term noWs "[" f:term "|" m:term "]" : term =>
`(MeasureTheory.condExp $m $μ $f)
/-- Unexpander for `μ[f|m]` notation. -/
@[app_unexpander MeasureTheory.condExp]
def condExpUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ $m $μ $f) => `($μ[$f|$m])
| _ => throw ()
/-- info: μ[f|m] : α → E -/
#guard_msgs in
#check μ[f|m]
/-- info: μ[f|m] sorry : E -/
#guard_msgs in
#check μ[f|m] (sorry : α)
theorem condExp_of_not_le (hm_not : ¬m ≤ m₀) : μ[f|m] = 0 := by rw [condExp, dif_neg hm_not]
theorem condExp_of_not_sigmaFinite (hm : m ≤ m₀) (hμm_not : ¬SigmaFinite (μ.trim hm)) :
μ[f|m] = 0 := by rw [condExp, dif_pos hm, dif_neg]; push_neg; exact fun h => absurd h hμm_not
open scoped Classical in
theorem condExp_of_sigmaFinite (hm : m ≤ m₀) [hμm : SigmaFinite (μ.trim hm)] :
μ[f|m] =
if Integrable f μ then
if StronglyMeasurable[m] f then f
else aestronglyMeasurable_condExpL1.mk (condExpL1 hm μ f)
else 0 := by
rw [condExp, dif_pos hm]
grind
theorem condExp_of_stronglyMeasurable (hm : m ≤ m₀) [hμm : SigmaFinite (μ.trim hm)] {f : α → E}
(hf : StronglyMeasurable[m] f) (hfi : Integrable f μ) : μ[f|m] = f := by
rw [condExp_of_sigmaFinite hm, if_pos hfi, if_pos hf]
@[simp]
theorem condExp_const (hm : m ≤ m₀) (c : E) [IsFiniteMeasure μ] : μ[fun _ : α ↦ c|m] = fun _ ↦ c :=
condExp_of_stronglyMeasurable hm stronglyMeasurable_const (integrable_const c)
theorem condExp_ae_eq_condExpL1 (hm : m ≤ m₀) [hμm : SigmaFinite (μ.trim hm)] (f : α → E) :
μ[f|m] =ᵐ[μ] condExpL1 hm μ f := by
rw [condExp_of_sigmaFinite hm]
by_cases hfi : Integrable f μ
· rw [if_pos hfi]
by_cases hfm : StronglyMeasurable[m] f
· rw [if_pos hfm]
exact (condExpL1_of_aestronglyMeasurable' hfm.aestronglyMeasurable hfi).symm
· rw [if_neg hfm]
exact aestronglyMeasurable_condExpL1.ae_eq_mk.symm
rw [if_neg hfi, condExpL1_undef hfi]
exact (coeFn_zero _ _ _).symm
theorem condExp_ae_eq_condExpL1CLM (hm : m ≤ m₀) [SigmaFinite (μ.trim hm)] (hf : Integrable f μ) :
μ[f|m] =ᵐ[μ] condExpL1CLM E hm μ (hf.toL1 f) := by
refine (condExp_ae_eq_condExpL1 hm f).trans (Eventually.of_forall fun x => ?_)
rw [condExpL1_eq hf]
theorem condExp_of_not_integrable (hf : ¬Integrable f μ) : μ[f|m] = 0 := by
by_cases hm : m ≤ m₀
swap; · rw [condExp_of_not_le hm]
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · rw [condExp_of_not_sigmaFinite hm hμm]
rw [condExp_of_sigmaFinite, if_neg hf]
@[simp]
theorem condExp_zero : μ[(0 : α → E)|m] = 0 := by
by_cases hm : m ≤ m₀
swap; · rw [condExp_of_not_le hm]
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · rw [condExp_of_not_sigmaFinite hm hμm]
exact condExp_of_stronglyMeasurable hm stronglyMeasurable_zero (integrable_zero _ _ _)
theorem stronglyMeasurable_condExp : StronglyMeasurable[m] (μ[f|m]) := by
by_cases hm : m ≤ m₀
swap; · rw [condExp_of_not_le hm]; exact stronglyMeasurable_zero
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · rw [condExp_of_not_sigmaFinite hm hμm]; exact stronglyMeasurable_zero
rw [condExp_of_sigmaFinite hm]
split_ifs with hfi hfm
· exact hfm
· exact aestronglyMeasurable_condExpL1.stronglyMeasurable_mk
· exact stronglyMeasurable_zero
theorem condExp_congr_ae (h : f =ᵐ[μ] g) : μ[f|m] =ᵐ[μ] μ[g|m] := by
by_cases hm : m ≤ m₀
swap; · simp_rw [condExp_of_not_le hm]; rfl
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; rfl
exact (condExp_ae_eq_condExpL1 hm f).trans
(Filter.EventuallyEq.trans (by rw [condExpL1_congr_ae hm h])
(condExp_ae_eq_condExpL1 hm g).symm)
lemma condExp_congr_ae_trim (hm : m ≤ m₀) (hfg : f =ᵐ[μ] g) :
μ[f|m] =ᵐ[μ.trim hm] μ[g|m] :=
StronglyMeasurable.ae_eq_trim_of_stronglyMeasurable hm
stronglyMeasurable_condExp stronglyMeasurable_condExp (condExp_congr_ae hfg)
theorem condExp_of_aestronglyMeasurable' (hm : m ≤ m₀) [hμm : SigmaFinite (μ.trim hm)] {f : α → E}
(hf : AEStronglyMeasurable[m] f μ) (hfi : Integrable f μ) : μ[f|m] =ᵐ[μ] f := by
refine ((condExp_congr_ae hf.ae_eq_mk).trans ?_).trans hf.ae_eq_mk.symm
rw [condExp_of_stronglyMeasurable hm hf.stronglyMeasurable_mk
((integrable_congr hf.ae_eq_mk).mp hfi)]
@[fun_prop]
theorem integrable_condExp : Integrable (μ[f|m]) μ := by
by_cases hm : m ≤ m₀
swap; · rw [condExp_of_not_le hm]; exact integrable_zero _ _ _
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · rw [condExp_of_not_sigmaFinite hm hμm]; exact integrable_zero _ _ _
exact (integrable_condExpL1 f).congr (condExp_ae_eq_condExpL1 hm f).symm
/-- The integral of the conditional expectation `μ[f|hm]` over an `m`-measurable set is equal to
the integral of `f` on that set. -/
theorem setIntegral_condExp (hm : m ≤ m₀) [SigmaFinite (μ.trim hm)] (hf : Integrable f μ)
(hs : MeasurableSet[m] s) : ∫ x in s, (μ[f|m]) x ∂μ = ∫ x in s, f x ∂μ := by
rw [setIntegral_congr_ae (hm s hs) ((condExp_ae_eq_condExpL1 hm f).mono fun x hx _ => hx)]
exact setIntegral_condExpL1 hf hs
theorem integral_condExp (hm : m ≤ m₀) [hμm : SigmaFinite (μ.trim hm)] :
∫ x, (μ[f|m]) x ∂μ = ∫ x, f x ∂μ := by
by_cases hf : Integrable f μ
· suffices ∫ x in Set.univ, (μ[f|m]) x ∂μ = ∫ x in Set.univ, f x ∂μ by
simp_rw [setIntegral_univ] at this; exact this
exact setIntegral_condExp hm hf .univ
simp only [condExp_of_not_integrable hf, Pi.zero_apply, integral_zero, integral_undef hf]
/-- **Law of total probability** using `condExp` as conditional probability. -/
theorem integral_condExp_indicator [mβ : MeasurableSpace β] {Y : α → β} (hY : Measurable Y)
[SigmaFinite (μ.trim hY.comap_le)] {A : Set α} (hA : MeasurableSet A) :
∫ x, (μ[(A.indicator fun _ ↦ (1 : ℝ))|mβ.comap Y]) x ∂μ = μ.real A := by
rw [integral_condExp, integral_indicator hA, setIntegral_const, smul_eq_mul, mul_one]
/-- **Uniqueness of the conditional expectation**
If a function is a.e. `m`-measurable, verifies an integrability condition and has same integral
as `f` on all `m`-measurable sets, then it is a.e. equal to `μ[f|hm]`. -/
theorem ae_eq_condExp_of_forall_setIntegral_eq (hm : m ≤ m₀) [SigmaFinite (μ.trim hm)]
{f g : α → E} (hf : Integrable f μ)
(hg_int_finite : ∀ s, MeasurableSet[m] s → μ s < ∞ → IntegrableOn g s μ)
(hg_eq : ∀ s : Set α, MeasurableSet[m] s → μ s < ∞ → ∫ x in s, g x ∂μ = ∫ x in s, f x ∂μ)
(hgm : AEStronglyMeasurable[m] g μ) : g =ᵐ[μ] μ[f|m] := by
refine ae_eq_of_forall_setIntegral_eq_of_sigmaFinite' hm hg_int_finite
(fun s _ _ => integrable_condExp.integrableOn) (fun s hs hμs => ?_) hgm
(StronglyMeasurable.aestronglyMeasurable stronglyMeasurable_condExp)
rw [hg_eq s hs hμs, setIntegral_condExp hm hf hs]
theorem condExp_bot' [hμ : NeZero μ] (f : α → E) :
μ[f|⊥] = fun _ => (μ.real Set.univ)⁻¹ • ∫ x, f x ∂μ := by
by_cases hμ_finite : IsFiniteMeasure μ
swap
· have h : ¬SigmaFinite (μ.trim bot_le) := by rwa [sigmaFinite_trim_bot_iff]
rw [not_isFiniteMeasure_iff] at hμ_finite
rw [condExp_of_not_sigmaFinite bot_le h]
simp only [hμ_finite, ENNReal.toReal_top, inv_zero, zero_smul, measureReal_def]
rfl
have h_meas : StronglyMeasurable[⊥] (μ[f|⊥]) := stronglyMeasurable_condExp
obtain ⟨c, h_eq⟩ := stronglyMeasurable_bot_iff.mp h_meas
rw [h_eq]
have h_integral : ∫ x, (μ[f|⊥]) x ∂μ = ∫ x, f x ∂μ := integral_condExp bot_le
simp_rw [h_eq, integral_const] at h_integral
rw [← h_integral, ← smul_assoc, smul_eq_mul, inv_mul_cancel₀, one_smul]
rw [Ne, measureReal_def, ENNReal.toReal_eq_zero_iff, not_or]
exact ⟨NeZero.ne _, measure_ne_top μ Set.univ⟩
theorem condExp_bot_ae_eq (f : α → E) :
μ[f|⊥] =ᵐ[μ] fun _ => (μ.real Set.univ)⁻¹ • ∫ x, f x ∂μ := by
rcases eq_zero_or_neZero μ with rfl | hμ
· rw [ae_zero]; exact eventually_bot
· exact Eventually.of_forall <| congr_fun (condExp_bot' f)
theorem condExp_bot [IsProbabilityMeasure μ] (f : α → E) : μ[f|⊥] = fun _ => ∫ x, f x ∂μ := by
refine (condExp_bot' f).trans ?_
rw [measureReal_univ_eq_one, inv_one, one_smul]
theorem condExp_add (hf : Integrable f μ) (hg : Integrable g μ) (m : MeasurableSpace α) :
μ[f + g|m] =ᵐ[μ] μ[f|m] + μ[g|m] := by
by_cases hm : m ≤ m₀
swap; · simp_rw [condExp_of_not_le hm]; simp
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; simp
refine (condExp_ae_eq_condExpL1 hm _).trans ?_
rw [condExpL1_add hf hg]
exact (coeFn_add _ _).trans
((condExp_ae_eq_condExpL1 hm _).symm.add (condExp_ae_eq_condExpL1 hm _).symm)
theorem condExp_finset_sum {ι : Type*} {s : Finset ι} {f : ι → α → E}
(hf : ∀ i ∈ s, Integrable (f i) μ) (m : MeasurableSpace α) :
μ[∑ i ∈ s, f i|m] =ᵐ[μ] ∑ i ∈ s, μ[f i|m] := by
classical
induction s using Finset.induction_on with
| empty => rw [Finset.sum_empty, Finset.sum_empty, condExp_zero]
| insert i s his heq =>
rw [Finset.sum_insert his, Finset.sum_insert his]
exact (condExp_add (hf i <| Finset.mem_insert_self i s)
(integrable_finset_sum' _ <| Finset.forall_of_forall_insert hf) _).trans
((EventuallyEq.refl _ _).add <| heq <| Finset.forall_of_forall_insert hf)
theorem condExp_smul [NormedSpace 𝕜 E] (c : 𝕜) (f : α → E) (m : MeasurableSpace α) :
μ[c • f|m] =ᵐ[μ] c • μ[f|m] := by
by_cases hm : m ≤ m₀
swap; · simp_rw [condExp_of_not_le hm]; simp
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; simp
refine (condExp_ae_eq_condExpL1 hm _).trans ?_
rw [condExpL1_smul c f]
refine (condExp_ae_eq_condExpL1 hm f).mp ?_
refine (coeFn_smul c (condExpL1 hm μ f)).mono fun x hx1 hx2 => ?_
simp only [hx1, hx2, Pi.smul_apply]
theorem condExp_neg (f : α → E) (m : MeasurableSpace α) : μ[-f|m] =ᵐ[μ] -μ[f|m] := by
calc
μ[-f|m] = μ[(-1 : ℝ) • f|m] := by rw [neg_one_smul ℝ f]
_ =ᵐ[μ] (-1 : ℝ) • μ[f|m] := condExp_smul ..
_ = -μ[f|m] := neg_one_smul ℝ (μ[f|m])
theorem condExp_sub (hf : Integrable f μ) (hg : Integrable g μ) (m : MeasurableSpace α) :
μ[f - g|m] =ᵐ[μ] μ[f|m] - μ[g|m] := by
simp_rw [sub_eq_add_neg]
exact (condExp_add hf hg.neg _).trans (EventuallyEq.rfl.add (condExp_neg ..))
/-- **Tower property of the conditional expectation**.
Taking the `m₂`-conditional expectation then the `m₁`-conditional expectation, where `m₁` is a
smaller σ-algebra, is the same as taking the `m₁`-conditional expectation directly. -/
theorem condExp_condExp_of_le {m₁ m₂ m₀ : MeasurableSpace α} {μ : Measure α} (hm₁₂ : m₁ ≤ m₂)
(hm₂ : m₂ ≤ m₀) [SigmaFinite (μ.trim hm₂)] : μ[μ[f|m₂]|m₁] =ᵐ[μ] μ[f|m₁] := by
by_cases hμm₁ : SigmaFinite (μ.trim (hm₁₂.trans hm₂))
swap; · simp_rw [condExp_of_not_sigmaFinite (hm₁₂.trans hm₂) hμm₁]; rfl
by_cases hf : Integrable f μ
swap; · simp_rw [condExp_of_not_integrable hf, condExp_zero]; rfl
refine ae_eq_of_forall_setIntegral_eq_of_sigmaFinite' (hm₁₂.trans hm₂)
(fun s _ _ => integrable_condExp.integrableOn) (fun s _ _ => integrable_condExp.integrableOn) ?_
stronglyMeasurable_condExp.aestronglyMeasurable
stronglyMeasurable_condExp.aestronglyMeasurable
intro s hs _
rw [setIntegral_condExp (hm₁₂.trans hm₂) integrable_condExp hs]
rw [setIntegral_condExp (hm₁₂.trans hm₂) hf hs, setIntegral_condExp hm₂ hf (hm₁₂ s hs)]
section RCLike
variable [InnerProductSpace 𝕜 E]
lemma MemLp.condExpL2_ae_eq_condExp' (hm : m ≤ m₀) (hf1 : Integrable f μ) (hf2 : MemLp f 2 μ)
[SigmaFinite (μ.trim hm)] : condExpL2 E 𝕜 hm hf2.toLp =ᵐ[μ] μ[f|m] := by
refine ae_eq_condExp_of_forall_setIntegral_eq hm hf1
(fun s hs htop ↦ integrableOn_condExpL2_of_measure_ne_top hm htop.ne _) (fun s hs htop ↦ ?_)
(aestronglyMeasurable_condExpL2 hm _)
rw [integral_condExpL2_eq hm (hf2.toLp _) hs htop.ne]
refine setIntegral_congr_ae (hm _ hs) ?_
filter_upwards [hf2.coeFn_toLp] with ω hω _ using hω
@[deprecated (since := "2025-02-21")]
alias Memℒp.condExpL2_ae_eq_condExp' := MemLp.condExpL2_ae_eq_condExp'
lemma MemLp.condExpL2_ae_eq_condExp (hm : m ≤ m₀) (hf : MemLp f 2 μ) [IsFiniteMeasure μ] :
condExpL2 E 𝕜 hm hf.toLp =ᵐ[μ] μ[f|m] :=
hf.condExpL2_ae_eq_condExp' hm (memLp_one_iff_integrable.1 <| hf.mono_exponent one_le_two)
@[deprecated (since := "2025-02-21")]
alias Memℒp.condExpL2_ae_eq_condExp := MemLp.condExpL2_ae_eq_condExp
end RCLike
section Real
variable [InnerProductSpace ℝ E]
-- TODO: Generalize via the conditional Jensen inequality
lemma eLpNorm_condExp_le : eLpNorm (μ[f|m]) 2 μ ≤ eLpNorm f 2 μ := by
by_cases hm : m ≤ m₀; swap
· simp [condExp_of_not_le hm]
by_cases hfμ : SigmaFinite (μ.trim hm); swap
· rw [condExp_of_not_sigmaFinite hm hfμ]
simp
by_cases hfi : Integrable f μ; swap
· rw [condExp_of_not_integrable hfi]
simp
obtain hf | hf := eq_or_ne (eLpNorm f 2 μ) ∞
· simp [hf]
replace hf : MemLp f 2 μ := ⟨hfi.1, Ne.lt_top' fun a ↦ hf a.symm⟩
rw [← eLpNorm_congr_ae (hf.condExpL2_ae_eq_condExp' (𝕜 := ℝ) hm hfi)]
refine le_trans (eLpNorm_condExpL2_le hm _) ?_
rw [eLpNorm_congr_ae hf.coeFn_toLp]
protected lemma MemLp.condExp (hf : MemLp f 2 μ) : MemLp (μ[f|m]) 2 μ := by
by_cases hm : m ≤ m₀
· exact ⟨(stronglyMeasurable_condExp.mono hm).aestronglyMeasurable,
eLpNorm_condExp_le.trans_lt hf.eLpNorm_lt_top⟩
· simp [condExp_of_not_le hm]
@[deprecated (since := "2025-02-21")]
alias Memℒp.condExp := MemLp.condExp
end Real
end NormedAddCommGroup
section NormedRing
variable {R : Type*} [NormedRing R] [NormedSpace ℝ R] [CompleteSpace R]
@[simp]
lemma condExp_ofNat (n : ℕ) [n.AtLeastTwo] (f : α → R) :
μ[ofNat(n) * f|m] =ᵐ[μ] ofNat(n) * μ[f|m] := by
simpa [Nat.cast_smul_eq_nsmul] using condExp_smul (μ := μ) (m := m) (n : ℝ) f
end NormedRing
section NormedLatticeAddCommGroup
variable [NormedAddCommGroup E] [CompleteSpace E] [NormedSpace ℝ E]
/-- **Lebesgue dominated convergence theorem**: sufficient conditions under which almost
everywhere convergence of a sequence of functions implies the convergence of their image by
`condExpL1`. -/
theorem tendsto_condExpL1_of_dominated_convergence (hm : m ≤ m₀) [SigmaFinite (μ.trim hm)]
{fs : ℕ → α → E} {f : α → E} (bound_fs : α → ℝ)
(hfs_meas : ∀ n, AEStronglyMeasurable (fs n) μ) (h_int_bound_fs : Integrable bound_fs μ)
(hfs_bound : ∀ n, ∀ᵐ x ∂μ, ‖fs n x‖ ≤ bound_fs x)
(hfs : ∀ᵐ x ∂μ, Tendsto (fun n => fs n x) atTop (𝓝 (f x))) :
Tendsto (fun n => condExpL1 hm μ (fs n)) atTop (𝓝 (condExpL1 hm μ f)) :=
tendsto_setToFun_of_dominated_convergence _ bound_fs hfs_meas h_int_bound_fs hfs_bound hfs
/-- If two sequences of functions have a.e. equal conditional expectations at each step, converge
and verify dominated convergence hypotheses, then the conditional expectations of their limits are
a.e. equal. -/
theorem tendsto_condExp_unique (fs gs : ℕ → α → E) (f g : α → E)
(hfs_int : ∀ n, Integrable (fs n) μ) (hgs_int : ∀ n, Integrable (gs n) μ)
(hfs : ∀ᵐ x ∂μ, Tendsto (fun n => fs n x) atTop (𝓝 (f x)))
(hgs : ∀ᵐ x ∂μ, Tendsto (fun n => gs n x) atTop (𝓝 (g x))) (bound_fs : α → ℝ)
(h_int_bound_fs : Integrable bound_fs μ) (bound_gs : α → ℝ)
(h_int_bound_gs : Integrable bound_gs μ) (hfs_bound : ∀ n, ∀ᵐ x ∂μ, ‖fs n x‖ ≤ bound_fs x)
(hgs_bound : ∀ n, ∀ᵐ x ∂μ, ‖gs n x‖ ≤ bound_gs x) (hfg : ∀ n, μ[fs n|m] =ᵐ[μ] μ[gs n|m]) :
μ[f|m] =ᵐ[μ] μ[g|m] := by
by_cases hm : m ≤ m₀; swap; · simp_rw [condExp_of_not_le hm]; rfl
by_cases hμm : SigmaFinite (μ.trim hm); swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; rfl
refine (condExp_ae_eq_condExpL1 hm f).trans ((condExp_ae_eq_condExpL1 hm g).trans ?_).symm
rw [← Lp.ext_iff]
have hn_eq : ∀ n, condExpL1 hm μ (gs n) = condExpL1 hm μ (fs n) := by
intro n
ext1
refine (condExp_ae_eq_condExpL1 hm (gs n)).symm.trans ((hfg n).symm.trans ?_)
exact condExp_ae_eq_condExpL1 hm (fs n)
have hcond_fs : Tendsto (fun n => condExpL1 hm μ (fs n)) atTop (𝓝 (condExpL1 hm μ f)) :=
tendsto_condExpL1_of_dominated_convergence hm _ (fun n => (hfs_int n).1) h_int_bound_fs
hfs_bound hfs
have hcond_gs : Tendsto (fun n => condExpL1 hm μ (gs n)) atTop (𝓝 (condExpL1 hm μ g)) :=
tendsto_condExpL1_of_dominated_convergence hm _ (fun n => (hgs_int n).1) h_int_bound_gs
hgs_bound hgs
exact tendsto_nhds_unique_of_eventuallyEq hcond_gs hcond_fs (Eventually.of_forall hn_eq)
variable [PartialOrder E] [OrderClosedTopology E] [IsOrderedAddMonoid E] [OrderedSMul ℝ E]
lemma condExp_mono (hf : Integrable f μ) (hg : Integrable g μ) (hfg : f ≤ᵐ[μ] g) :
μ[f|m] ≤ᵐ[μ] μ[g|m] := by
by_cases hm : m ≤ m₀
swap; · simp_rw [condExp_of_not_le hm]; rfl
by_cases hμm : SigmaFinite (μ.trim hm)
swap; · simp_rw [condExp_of_not_sigmaFinite hm hμm]; rfl
exact (condExp_ae_eq_condExpL1 hm _).trans_le
((condExpL1_mono hf hg hfg).trans_eq (condExp_ae_eq_condExpL1 hm _).symm)
lemma condExp_nonneg (hf : 0 ≤ᵐ[μ] f) : 0 ≤ᵐ[μ] μ[f|m] := by
by_cases hfint : Integrable f μ
· rw [(condExp_zero.symm : (0 : α → E) = μ[0|m])]
exact condExp_mono (integrable_zero _ _ _) hfint hf
· rw [condExp_of_not_integrable hfint]
lemma condExp_nonpos (hf : f ≤ᵐ[μ] 0) : μ[f|m] ≤ᵐ[μ] 0 := by
by_cases hfint : Integrable f μ
· rw [(condExp_zero.symm : (0 : α → E) = μ[0|m])]
exact condExp_mono hfint (integrable_zero _ _ _) hf
· rw [condExp_of_not_integrable hfint]
end NormedLatticeAddCommGroup
end MeasureTheory
|
Opposite.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.Ring.Opposite
import Mathlib.Data.Int.Cast.Lemmas
/-!
# Field structure on the multiplicative/additive opposite
-/
assert_not_exists RelIso
variable {α : Type*}
namespace MulOpposite
@[to_additive] instance instNNRatCast [NNRatCast α] : NNRatCast αᵐᵒᵖ := ⟨fun q ↦ op q⟩
@[to_additive] instance instRatCast [RatCast α] : RatCast αᵐᵒᵖ := ⟨fun q ↦ op q⟩
@[to_additive (attr := simp, norm_cast)]
lemma op_nnratCast [NNRatCast α] (q : ℚ≥0) : op (q : α) = q := rfl
@[to_additive (attr := simp, norm_cast)]
lemma unop_nnratCast [NNRatCast α] (q : ℚ≥0) : unop (q : αᵐᵒᵖ) = q := rfl
@[to_additive (attr := simp, norm_cast)]
lemma op_ratCast [RatCast α] (q : ℚ) : op (q : α) = q := rfl
@[to_additive (attr := simp, norm_cast)]
lemma unop_ratCast [RatCast α] (q : ℚ) : unop (q : αᵐᵒᵖ) = q := rfl
instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵐᵒᵖ where
__ := instSemiring
__ := instGroupWithZero
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
nnratCast_def q := unop_injective <| by rw [unop_nnratCast, unop_div, unop_natCast, unop_natCast,
NNRat.cast_def, div_eq_mul_inv, Nat.cast_comm]
instance instDivisionRing [DivisionRing α] : DivisionRing αᵐᵒᵖ where
__ := instRing
__ := instDivisionSemiring
qsmul := _
qsmul_def := fun _ _ => rfl
ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div,
unop_natCast, unop_intCast, Int.commute_cast, div_eq_mul_inv]
instance instSemifield [Semifield α] : Semifield αᵐᵒᵖ where
__ := instCommSemiring
__ := instDivisionSemiring
instance instField [Field α] : Field αᵐᵒᵖ where
__ := instCommRing
__ := instDivisionRing
end MulOpposite
namespace AddOpposite
instance instDivisionSemiring [DivisionSemiring α] : DivisionSemiring αᵃᵒᵖ where
__ := instSemiring
__ := instGroupWithZero
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
nnratCast_def q := unop_injective <| by rw [unop_nnratCast, unop_div, unop_natCast, unop_natCast,
NNRat.cast_def, div_eq_mul_inv]
instance instDivisionRing [DivisionRing α] : DivisionRing αᵃᵒᵖ where
__ := instRing
__ := instDivisionSemiring
qsmul := _
qsmul_def := fun _ _ => rfl
ratCast_def q := unop_injective <| by rw [unop_ratCast, Rat.cast_def, unop_div, unop_natCast,
unop_intCast, div_eq_mul_inv]
instance instSemifield [Semifield α] : Semifield αᵃᵒᵖ where
__ := instCommSemiring
__ := instDivisionSemiring
instance instField [Field α] : Field αᵃᵒᵖ where
__ := instCommRing
__ := instDivisionRing
end AddOpposite
|
Module.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Kenny Lau
-/
import Mathlib.Algebra.GroupWithZero.Action.Pi
import Mathlib.Algebra.Module.LinearMap.Defs
import Mathlib.Algebra.Module.Pi
import Mathlib.Data.DFinsupp.Defs
/-!
# Group actions on `DFinsupp`
## Main results
* `DFinsupp.module`: pointwise scalar multiplication on `DFinsupp` gives a module structure
-/
universe u u₁ u₂ v v₁ v₂ v₃ w x y l
variable {ι : Type u} {γ : Type w} {β : ι → Type v} {β₁ : ι → Type v₁} {β₂ : ι → Type v₂}
namespace DFinsupp
section Algebra
/-- Dependent functions with finite support inherit a semiring action from an action on each
coordinate. -/
instance [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)] : SMulZeroClass γ (Π₀ i, β i) where
smul c v := v.mapRange (fun _ => (c • ·)) fun _ => smul_zero _
smul_zero _ := mapRange_zero _ _
theorem smul_apply [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)] (b : γ)
(v : Π₀ i, β i) (i : ι) : (b • v) i = b • v i :=
rfl
@[simp, norm_cast]
theorem coe_smul [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)] (b : γ)
(v : Π₀ i, β i) : ⇑(b • v) = b • ⇑v :=
rfl
instance smulCommClass {δ : Type*} [∀ i, Zero (β i)]
[∀ i, SMulZeroClass γ (β i)] [∀ i, SMulZeroClass δ (β i)] [∀ i, SMulCommClass γ δ (β i)] :
SMulCommClass γ δ (Π₀ i, β i) where
smul_comm r s m := ext fun i => by simp only [smul_apply, smul_comm r s (m i)]
instance isScalarTower {δ : Type*} [∀ i, Zero (β i)]
[∀ i, SMulZeroClass γ (β i)] [∀ i, SMulZeroClass δ (β i)] [SMul γ δ]
[∀ i, IsScalarTower γ δ (β i)] : IsScalarTower γ δ (Π₀ i, β i) where
smul_assoc r s m := ext fun i => by simp only [smul_apply, smul_assoc r s (m i)]
instance isCentralScalar [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
[∀ i, SMulZeroClass γᵐᵒᵖ (β i)] [∀ i, IsCentralScalar γ (β i)] :
IsCentralScalar γ (Π₀ i, β i) where
op_smul_eq_smul r m := ext fun i => by simp only [smul_apply, op_smul_eq_smul r (m i)]
/-- Dependent functions with finite support inherit a `DistribMulAction` structure from such a
structure on each coordinate. -/
instance distribMulAction [Monoid γ] [∀ i, AddMonoid (β i)] [∀ i, DistribMulAction γ (β i)] :
DistribMulAction γ (Π₀ i, β i) :=
Function.Injective.distribMulAction coeFnAddMonoidHom DFunLike.coe_injective coe_smul
/-- Dependent functions with finite support inherit a module structure from such a structure on
each coordinate. -/
instance module [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] :
Module γ (Π₀ i, β i) :=
{ inferInstanceAs (DistribMulAction γ (Π₀ i, β i)) with
zero_smul := fun c => ext fun i => by simp only [smul_apply, zero_smul, zero_apply]
add_smul := fun c x y => ext fun i => by simp only [add_apply, smul_apply, add_smul] }
end Algebra
variable (γ) in
/-- Coercion from a `DFinsupp` to a pi type is a `LinearMap`. -/
def coeFnLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] :
(Π₀ i, β i) →ₗ[γ] ∀ i, β i where
toFun := (⇑)
map_add' := coe_add
map_smul' := coe_smul
@[simp]
lemma coeFnLinearMap_apply [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)]
(v : Π₀ i, β i) : coeFnLinearMap γ v = v :=
rfl
section FilterAndSubtypeDomain
@[simp]
theorem filter_smul [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)] (p : ι → Prop)
[DecidablePred p] (r : γ) (f : Π₀ i, β i) : (r • f).filter p = r • f.filter p := by
ext
simp [smul_apply, smul_ite]
variable (γ β)
/-- `DFinsupp.filter` as a `LinearMap`. -/
@[simps]
def filterLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)] (p : ι → Prop)
[DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i, β i where
toFun := filter p
map_add' := filter_add p
map_smul' := filter_smul p
variable {γ β}
@[simp]
theorem subtypeDomain_smul [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
{p : ι → Prop} [DecidablePred p] (r : γ) (f : Π₀ i, β i) :
(r • f).subtypeDomain p = r • f.subtypeDomain p :=
DFunLike.coe_injective rfl
variable (γ β)
/-- `DFinsupp.subtypeDomain` as a `LinearMap`. -/
@[simps]
def subtypeDomainLinearMap [Semiring γ] [∀ i, AddCommMonoid (β i)] [∀ i, Module γ (β i)]
(p : ι → Prop) [DecidablePred p] : (Π₀ i, β i) →ₗ[γ] Π₀ i : Subtype p, β i where
toFun := subtypeDomain p
map_add' := subtypeDomain_add
map_smul' := subtypeDomain_smul
end FilterAndSubtypeDomain
section DecidableEq
variable [DecidableEq ι]
section
variable [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
@[simp]
theorem mk_smul {s : Finset ι} (c : γ) (x : ∀ i : (↑s : Set ι), β (i : ι)) :
mk s (c • x) = c • mk s x :=
ext fun i => by simp only [smul_apply, mk_apply]; split_ifs <;> [rfl; rw [smul_zero]]
@[simp]
theorem single_smul {i : ι} (c : γ) (x : β i) : single i (c • x) = c • single i x :=
ext fun i => by
simp only [smul_apply, single_apply]
split_ifs with h
· cases h; rfl
· rw [smul_zero]
end
theorem support_smul {γ : Type w} [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
[∀ (i : ι) (x : β i), Decidable (x ≠ 0)] (b : γ) (v : Π₀ i, β i) :
(b • v).support ⊆ v.support :=
support_mapRange
end DecidableEq
section Equiv
open Finset
variable {κ : Type*}
@[simp]
theorem comapDomain_smul [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
(h : κ → ι) (hh : Function.Injective h) (r : γ) (f : Π₀ i, β i) :
comapDomain h hh (r • f) = r • comapDomain h hh f := by
ext
rw [smul_apply, comapDomain_apply, smul_apply, comapDomain_apply]
@[simp]
theorem comapDomain'_smul [∀ i, Zero (β i)] [∀ i, SMulZeroClass γ (β i)]
(h : κ → ι) {h' : ι → κ} (hh' : Function.LeftInverse h' h) (r : γ) (f : Π₀ i, β i) :
comapDomain' h hh' (r • f) = r • comapDomain' h hh' f := by
ext
rw [smul_apply, comapDomain'_apply, smul_apply, comapDomain'_apply]
section SigmaCurry
variable {α : ι → Type*} {δ : ∀ i, α i → Type v}
instance distribMulAction₂ [Monoid γ] [∀ i j, AddMonoid (δ i j)]
[∀ i j, DistribMulAction γ (δ i j)] : DistribMulAction γ (Π₀ (i : ι) (j : α i), δ i j) :=
@DFinsupp.distribMulAction ι _ (fun i => Π₀ j, δ i j) _ _ _
end SigmaCurry
variable {α : Option ι → Type v}
theorem equivProdDFinsupp_smul [∀ i, Zero (α i)] [∀ i, SMulZeroClass γ (α i)]
(r : γ) (f : Π₀ i, α i) : equivProdDFinsupp (r • f) = r • equivProdDFinsupp f :=
Prod.ext (smul_apply _ _ _) (comapDomain_smul _ (Option.some_injective _) _ _)
end Equiv
end DFinsupp
|
GroupCompletion.lean
|
/-
Copyright (c) 2024 Mitchell Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mitchell Lee
-/
import Mathlib.Topology.Algebra.GroupCompletion
import Mathlib.Topology.Algebra.InfiniteSum.Group
/-!
# Infinite sums in the completion of a topological group
-/
open UniformSpace.Completion
variable {α β : Type*} [AddCommGroup α] [UniformSpace α] [IsUniformAddGroup α]
/-- A function `f` has a sum in an uniform additive group `α` if and only if it has that sum in the
completion of `α`. -/
theorem hasSum_iff_hasSum_compl (f : β → α) (a : α) :
HasSum (toCompl ∘ f) a ↔ HasSum f a := (isDenseInducing_toCompl α).hasSum_iff f a
/-- A function `f` is summable in a uniform additive group `α` if and only if it is summable in
`Completion α` and its sum in `Completion α` lies in the range of `toCompl : α →+ Completion α`. -/
theorem summable_iff_summable_compl_and_tsum_mem (f : β → α) :
Summable f ↔ Summable (toCompl ∘ f) ∧ ∑' i, toCompl (f i) ∈ Set.range toCompl :=
(isDenseInducing_toCompl α).summable_iff_tsum_comp_mem_range f
/-- A function `f` is summable in a uniform additive group `α` if and only if the net of its partial
sums is Cauchy and its sum in `Completion α` lies in the range of `toCompl : α →+ Completion α`.
(The condition that the net of partial sums is Cauchy can be checked using
`cauchySeq_finset_iff_sum_vanishing` or `cauchySeq_finset_iff_tsum_vanishing`.) -/
theorem summable_iff_cauchySeq_finset_and_tsum_mem (f : β → α) :
Summable f ↔ CauchySeq (fun s : Finset β ↦ ∑ b ∈ s, f b) ∧
∑' i, toCompl (f i) ∈ Set.range toCompl := by
classical
constructor
· rintro ⟨a, ha⟩
exact ⟨ha.cauchySeq, ((summable_iff_summable_compl_and_tsum_mem f).mp ⟨a, ha⟩).2⟩
· rintro ⟨h_cauchy, h_tsum⟩
apply (summable_iff_summable_compl_and_tsum_mem f).mpr
constructor
· apply summable_iff_cauchySeq_finset.mpr
simp_rw [Function.comp_apply, ← map_sum]
exact h_cauchy.map (uniformContinuous_coe α)
· exact h_tsum
/-- If a function `f` is summable in a uniform additive group `α`, then its sum in `α` is the same
as its sum in `Completion α`. -/
theorem Summable.toCompl_tsum {f : β → α} (hf : Summable f) : ∑' i, toCompl (f i) = ∑' i, f i :=
(hf.map_tsum toCompl (continuous_coe α)).symm
|
congrm.lean
|
import Mathlib.Algebra.Ring.Nat
import Mathlib.Data.Fintype.Card
import Mathlib.Tactic.CongrM
private axiom test_sorry : ∀ {α}, α
namespace Tests.Congrm
set_option autoImplicit true
section docs
/-! These are the examples from the tactic documentation -/
example {a b c d : ℕ} :
Nat.pred a.succ * (d + (c + a.pred)) = Nat.pred b.succ * (b + (c + d.pred)) := by
congrm Nat.pred (Nat.succ ?h1) * (?h2 + ?h3)
case h1 =>
guard_target = a = b
exact test_sorry
case h2 =>
guard_target = d = b
exact test_sorry
case h3 =>
guard_target = c + a.pred = c + d.pred
exact test_sorry
example {a b : ℕ} (h : a = b) : (fun _y : ℕ => ∀ z, a + a = z) = (fun _x => ∀ z, b + a = z) := by
congrm fun x => ∀ w, ?_ + a = w
guard_hyp x : ℕ
guard_hyp w : ℕ
exact h
end docs
example (f : α → Prop) (h : ∀ a, f a ↔ True) : (∀ a : α, f a) ↔ (∀ _ : α, True) := by
fail_if_success congrm f ?_
congrm ∀ x, ?_
guard_hyp x : α
exact h x
example (f : α → Prop) (h : ∀ a, f a = True) : (∀ a : α, f a) ↔ (∀ _ : α, True) := by
congrm ∀ x, $(h _)
example (f : α → Prop) (h : ∀ a, f a ↔ True) : (∀ a : α, f a) ↔ (∀ _ : α, True) := by
congrm ∀ x, $(h _)
example (f : α → α → Prop) (h : ∀ a b, f a b ↔ True) :
(∀ a b, f a b) ↔ (∀ _ _ : α, True) := by
congrm ∀ x y, ?_
exact h x y
example {a b : ℕ} (h : a = b) : (fun y : ℕ => y + a) = (fun x => x + b) := by
congrm fun x => ?_
guard_target = x + a = x + b
rw [h]
example {a b : ℕ} (h : a = b) : (fun y : ℕ => y + a) = (fun x => x + b) := by
congrm fun (x : ℕ) => x + ?_
exact h
example (a b : ℕ) (h : a = b) (f : ℕ → ℕ) : f a = f b := by
congrm f ?_
exact h
example (a b c d : ℕ) (h : a = b) (h' : c = d) (f : ℕ → ℕ → ℕ) : f a c = f b d := by
congrm f ?_ ?_ <;> assumption
example (a b : ℕ) (h : a = b) (f : ℕ → ℕ) : f (f a) = f (f b) := by
congrm f (f ?_)
exact h
example (a b c : ℕ) (h : b = c) : a = b ↔ a = c := by
congrm _ = ?_
exact h
example (a b c : ℕ) (h : b = c) : a = b ↔ a = c := by
fail_if_success congrm b = ?_
congrm a = ?_
exact h
example {b d : ℕ} (h : b = d) : (∀ a, a = b) ↔ (∀ c, c = d) := by
congrm ∀ a, _ = ?_
guard_target = b = d
exact h
example {p q r s : Prop} (pr : p ↔ r) (qs : q ↔ s) : p ∧ q ↔ r ∧ s := by
congrm ?h1 ∧ ?h2
case h1 => guard_target = p ↔ r; assumption
case h2 => guard_target = q ↔ s; assumption
example {f : ℕ → Prop} :
(∃ k, f (3 + 2 + k) ∨ f (8 + 1 + k)) ↔ ∃ k, f (1 + 4 + k) ∨ f (2 + 7 + k) := by
congrm (∃ k, f (?_ + k) ∨ f (?_ + k))
· guard_target =ₛ 3 + 2 = 1 + 4; simp
· guard_target =ₛ 8 + 1 = 2 + 7; simp
example {a b : ℕ} (h : a = b) : (fun _ : ℕ => ∀ z, a + a = z) = (fun _ => ∀ z, b + a = z) := by
congrm fun x => ∀ w, ?_ + a = w
exact h
example (a b c : ℕ) (h : b = c) : a = b ↔ a = c := by
fail_if_success congrm Eq ?_ ?_ ?_
congrm _ = ?_
exact h
example (a b c : ℕ) (h : b = c) : a = b ↔ a = c := by
congrm _ = $h
example (f : α → Prop) (h : ∀ a, f a ↔ True) : (∀ a : α, f a) ↔ (∀ _ : α, True) := by
fail_if_success congrm f ?_
congrm ∀ _, ?_
exact h _
example (α : Nat → Type) (f : (x : Nat) → α x) (h : i = j) : f i ≍ f j := by
congrm f ?_
exact h
def foo (n : Nat) : Nat := 1 + n
@[irreducible] def foo' (n : Nat) : Nat := 1 + n
-- Unfolding
example (n m : Nat) (h : n = m) : foo (2 + n) = foo (2 + m) := by
congrm 1 + (2 + ?_)
exact h
-- Fails unfolding irreducible
example (n m : Nat) (h : n = m) : foo' (2 + n) = foo' (2 + m) := by
fail_if_success congrm 1 + (2 + ?_)
cases h
rfl
-- Reflexive relations
example (a b : Nat) (h : a = b) : 1 + a ≤ 1 + b := by
congrm 1 + ?_
exact h
-- Subsingleton instances
example [Fintype α] [Fintype β] (h : α = β) : Fintype.card α = Fintype.card β := by
congrm Fintype.card ?_
exact h
end Congrm
end Tests
|
Relations.lean
|
/-
Copyright (c) 2025 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.LinearAlgebra.RootSystem.GeckConstruction.Basic
import Mathlib.LinearAlgebra.RootSystem.GeckConstruction.Lemmas
import Mathlib.Algebra.Lie.Sl2
/-!
# Relations in Geck's construction of a Lie algebra associated to a root system
This file contains proofs that `RootPairing.GeckConstruction.lieAlgebra` contains `sl₂` triples
satisfying relations associated to the Cartan matrix of the input root system.
## Main definitions:
* `RootPairing.GeckConstruction.isSl2Triple`: a distinguished family of `sl₂` triples contained in
the Geck construction.
* `RootPairing.GeckConstruction.lie_h_e`: an interaction relation between different `sl₂` triples.
* `RootPairing.GeckConstruction.lie_h_f`: an interaction relation between different `sl₂` triples.
* `RootPairing.GeckConstruction.lie_e_f_ne`: an interaction relation between different `sl₂`
triples.
-/
noncomputable section
namespace RootPairing.GeckConstruction
open Function Module.End
open Set hiding diagonal
variable {ι R M N : Type*} [Finite ι] [CommRing R] [IsDomain R] [CharZero R]
[AddCommGroup M] [Module R M] [AddCommGroup N] [Module R N]
{P : RootSystem ι R M N} [P.IsCrystallographic] {b : P.Base} [Fintype ι]
(i j : b.support)
attribute [local simp] Ring.lie_def Matrix.mul_apply Matrix.one_apply Matrix.diagonal_apply
/-- Lemma 3.3 (a) from [Geck](Geck2017). -/
lemma lie_h_e :
⁅h j, e i⁆ = b.cartanMatrix i j • e i := by
classical
ext (k | k) (l | l)
· simp [h, e]
· simp only [h, e, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply, Fintype.sum_sum_type,
Matrix.fromBlocks_apply₁₂, Matrix.zero_apply, zero_mul, add_zero, Finset.sum_const_zero]
rw [Finset.sum_eq_ite l (by aesop)]
aesop
· simp only [h, e]
aesop
· simp only [h, e, indexNeg_neg, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply,
Fintype.sum_sum_type, Matrix.fromBlocks_apply₂₁, Matrix.zero_apply, Matrix.fromBlocks_apply₁₂,
Matrix.of_apply, mul_ite, mul_one, mul_zero, ite_self, Finset.sum_const_zero,
Matrix.fromBlocks_apply₂₂, zero_add, ite_mul, zero_mul, Matrix.smul_apply, smul_ite, smul_add,
zsmul_eq_mul, smul_zero]
rw [← Finset.sum_sub_distrib, ← Finset.sum_subset (Finset.subset_univ {k, l}) (by aesop)]
rcases eq_or_ne k l with rfl | hkl; · simp [P.ne_zero i]
simp only [Matrix.diagonal_apply, ite_mul, zero_mul, mul_ite, mul_zero, Finset.sum_sub_distrib,
Finset.mem_singleton, Finset.sum_singleton, Finset.sum_insert, hkl, not_false_eq_true,
reduceIte, right_eq_add, ite_self, add_zero, zero_add, ite_sub_ite, sub_self,
Base.cartanMatrix, Base.cartanMatrixIn_def]
refine ite_congr rfl (fun hkil ↦ ?_) (fun _ ↦ rfl)
simp only [pairingIn_eq_add_of_root_eq_add hkil, Int.cast_add]
ring
/-- Lemma 3.3 (b) from [Geck](Geck2017). -/
lemma lie_h_f :
⁅h j, f i⁆ = -b.cartanMatrix i j • f i := by
classical
suffices ω b * ⁅h j, f i⁆ = ω b * (-b.cartanMatrix i j • f i) by
replace this := congr_arg (ω b * ·) this
simpa [← mul_assoc, ω_mul_ω] using this
calc ω b * ⁅h j, f i⁆ = ω b * (h j * f i - f i * h j) := by rw [Ring.lie_def]
_ = - (h j * e i - e i * h j) * ω b := ?_
_ = - ⁅h j, e i⁆ * ω b := by rw [Ring.lie_def]
_ = - (b.cartanMatrix i j • e i) * ω b := by rw [lie_h_e]
_ = ω b * (-b.cartanMatrix i j • f i) := ?_
· rw [mul_sub, ← mul_assoc, ← mul_assoc, ω_mul_h, ω_mul_f, mul_assoc, mul_assoc, ω_mul_f, ω_mul_h,
neg_sub, neg_mul, neg_mul, mul_neg, sub_mul, mul_assoc, mul_assoc]
abel
· rw [Matrix.mul_smul, ω_mul_f]
simp [mul_assoc]
variable [P.IsReduced]
/-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_same`. -/
private lemma lie_e_f_same_aux (k : ι) (hki : k ≠ i) (hki' : k ≠ P.reflectionPerm i i) :
⁅e i, f i⁆ (Sum.inr k) (Sum.inr k) = h i (Sum.inr k) (Sum.inr k) := by
classical
have h_lin_ind : LinearIndependent R ![P.root i, P.root k] := by
rw [LinearIndependent.pair_symm_iff, IsReduced.linearIndependent_iff]; aesop
suffices (∑ x, if P.root k = P.root i + P.root x then
(P.chainBotCoeff i x + 1 : R) * (P.chainTopCoeff i k + 1) else 0) -
(∑ x, if P.root k = P.root x - P.root i then
(P.chainTopCoeff i x + 1 : R) * (P.chainBotCoeff i k + 1) else 0) =
P.chainBotCoeff i k - P.chainTopCoeff i k by
have aux (x : ι) : P.root x = P.root k - P.root i ↔ P.root k = P.root i + P.root x := by
rw [eq_sub_iff_add_eq', eq_comm]
have aux' (x : ι) : P.root x = P.root i + P.root k ↔ P.root k = P.root x - P.root i := by
rw [eq_sub_iff_add_eq', eq_comm]
simpa [e, f, h, hki, hki', aux, aux', ← ite_and, ← P.chainBotCoeff_sub_chainTopCoeff h_lin_ind]
rcases exists_or_forall_not (fun x ↦ P.root k = P.root i + P.root x) with ⟨x, hx⟩ | h₁ <;>
rcases exists_or_forall_not (fun x ↦ P.root k = P.root x - P.root i) with ⟨y, hy⟩ | h₂
· have h_lin_ind_x : LinearIndependent R ![P.root i, P.root x] := by simpa [hx] using h_lin_ind
have h_lin_ind_y : LinearIndependent R ![P.root i, P.root y] := by
rw [← add_eq_of_eq_sub hy, add_comm]; simpa
have hx' : P.chainBotCoeff i k = P.chainBotCoeff i x + 1 :=
chainBotCoeff_of_add h_lin_ind_x (add_comm (P.root i) _ ▸ hx)
have hy' : P.chainTopCoeff i k = P.chainTopCoeff i y + 1 := chainTopCoeff_of_sub h_lin_ind_y hy
rw [Finset.sum_eq_single_of_mem x (Finset.mem_univ _) (by aesop),
Finset.sum_eq_single_of_mem y (Finset.mem_univ _) (by aesop)]
simp only [hx, hy.symm, hx', hy', reduceIte, Nat.cast_add]
ring
· simp_rw [if_neg (h₂ _), Finset.sum_const_zero, sub_zero]
replace h₂ : P.chainTopCoeff i k = 0 :=
P.chainTopCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₂ x <| by simp [hx]
have h_lin_ind_x : LinearIndependent R ![P.root i, P.root x] := by simpa [hx] using h_lin_ind
have hx' : P.chainBotCoeff i k = P.chainBotCoeff i x + 1 :=
chainBotCoeff_of_add h_lin_ind_x (add_comm (P.root i) _ ▸ hx)
simp [hx, hx', h₂]
· simp_rw [if_neg (h₁ _), Finset.sum_const_zero, zero_sub]
replace h₁ : P.chainBotCoeff i k = 0 :=
P.chainBotCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₁ x <| by simp [hx]
have h_lin_ind_y : LinearIndependent R ![P.root i, P.root y] := by
rw [← add_eq_of_eq_sub hy, add_comm]; simpa
have hy' : P.chainTopCoeff i k = P.chainTopCoeff i y + 1 := chainTopCoeff_of_sub h_lin_ind_y hy
simp [hy, hy', h₁]
· suffices P.chainBotCoeff i k = 0 ∧ P.chainTopCoeff i k = 0 by simp [h₁, h₂, this]
exact ⟨P.chainBotCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₁ x <| by simp [hx],
P.chainTopCoeff_eq_zero_iff.mpr <| Or.inr fun ⟨x, hx⟩ ↦ h₂ x <| by simp [hx]⟩
/-- Lemma 3.4 from [Geck](Geck2017). -/
lemma lie_e_f_same :
⁅e i, f i⁆ = h i := by
letI _i := P.indexNeg
have _i : NoZeroSMulDivisors ℤ M := have := P.reflexive_left; .int_of_charZero R M
classical
ext (k | k) (l | l)
· simp [e, f, h]
· have h₁ (x : ι) : ¬ (P.root x = P.root l - P.root i ∧ k = i ∧ x = -i) := by
simp only [not_and]
rintro contra rfl rfl
simp [P.ne_zero, sub_eq_add_neg] at contra
have h₂ (x : ι) : ¬ (P.root x = P.root i + P.root l ∧ k = i ∧ x = i) := by
simp only [not_and]
rintro contra rfl rfl
simp [P.ne_zero] at contra
simp [e, f, h, h₁, h₂, - indexNeg_neg, ← ite_and]
· simp [e, f, h]
· rcases eq_or_ne k i with rfl | hki
· have hx (x : ι) : ¬ (P.root x = P.root i + P.root l ∧ P.root i = P.root x - P.root i) := by
rintro ⟨-, contra⟩
refine P.nsmul_notMem_range_root (n := 2) (i := i) ⟨x, ?_⟩
rwa [eq_sub_iff_add_eq, ← two_smul ℕ, eq_comm] at contra
simp only [e, f, h, P.ne_zero, P.ne_neg, Ring.lie_def, Fintype.sum_sum_type, Matrix.sub_apply,
Matrix.mul_apply, Matrix.fromBlocks_apply₂₁, Matrix.of_apply, Matrix.fromBlocks_apply₂₂,
left_eq_add, zero_mul, mul_zero, ite_mul, mul_ite, ← ite_and]
rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) (by aesop)]
simp [hx, eq_comm]
rcases eq_or_ne k (-i) with rfl | hki'
· have hx (x : ι) : ¬ (P.root x = P.root l - P.root i ∧ P.root (-i) = P.root i + P.root x) := by
rintro ⟨-, contra⟩
refine P.nsmul_notMem_range_root (n := 2) (i := -i) ⟨x, ?_⟩
replace contra : P.root x = -(P.root i + P.root i) := by
simpa [neg_eq_iff_add_eq_zero, ← add_assoc, add_eq_zero_iff_eq_neg'] using contra
simp [contra, two_smul]
have aux (x : ι) : ¬ P.root (-i) = P.root x - P.root i := by
simp [P.ne_zero x, eq_comm]
simp only [e, f, h, Ring.lie_def, Matrix.sub_apply, Matrix.mul_apply, Fintype.sum_sum_type,
Matrix.fromBlocks_apply₂₁, Matrix.of_apply, hki, reduceIte, zero_mul, Finset.sum_const_zero,
Matrix.fromBlocks_apply₂₂, mul_ite, ite_mul, mul_zero, ← ite_and, if_neg (hx _), add_zero,
aux, zero_sub, Matrix.diagonal_apply]
rw [Finset.sum_eq_single_of_mem i (Finset.mem_univ _) (by aesop)]
simp [eq_comm, apply_ite ((- ·) : R → R)]
rcases eq_or_ne k l with rfl | hkl
· exact lie_e_f_same_aux i k hki hki'
· simp_all [h, e, f]
lemma isSl2Triple [DecidableEq ι] :
IsSl2Triple (h i) (e i) (f i) where
h_ne_zero := fun contra ↦ by simpa [h] using congr_fun₂ contra (.inr i) (.inr i)
lie_e_f := by rw [lie_e_f_same]
lie_h_e_nsmul := by rw [lie_h_e]; simp
lie_h_f_nsmul := by rw [lie_h_f]; simp
section lie_e_f_ne
open scoped Matrix
variable {i j}
variable (hij : i ≠ j)
omit [P.IsReduced]
/-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/
private lemma lie_e_f_ne_aux₀ (k : b.support) (l : ι) :
⁅e i, f j⁆ (Sum.inl k) (Sum.inr l) = 0 := by
classical
letI := P.indexNeg
have aux₁ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root i + P.root l ∧ k = j ∧ x = j) := by
rintro x - ⟨hl, -, rfl⟩
exact b.sub_notMem_range_root i.property j.property ⟨-l, by simp [hl]⟩
have aux₂ : ∀ x ∈ Finset.univ, ¬ (P.root x = P.root l - P.root j ∧ k = i ∧ x = -i) := by
rintro x - ⟨hl, -, rfl⟩
replace hl : P.root i = P.root j - P.root l := by simpa [neg_eq_iff_eq_neg] using hl
exact b.sub_notMem_range_root i.property j.property ⟨-l, by simp [hl]⟩
simp [e, f, -indexNeg_neg, ← ite_and, Finset.sum_ite_of_false aux₁, Finset.sum_ite_of_false aux₂]
include hij
/-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/
private lemma lie_e_f_ne_aux₁ :
⁅e i, f j⁆ᵀ (Sum.inr j) = 0 := by
letI := P.indexNeg
classical
ext (k | k)
· rw [Matrix.transpose_apply, lie_e_f_ne_aux₀, Pi.zero_apply]
· suffices ((if k = i then ↑|b.cartanMatrix i j| else (0 : R)) -
∑ x, if P.root x = P.root i + P.root j ∧ P.root k = P.root x - P.root j then
(P.chainTopCoeff j x : R) + 1 else 0) = 0 by
have hij : (j : ι) ≠ -i := by simpa using b.root_ne_neg_of_ne j.property i.property (by aesop)
have aux : ∀ x ∈ Finset.univ,
x ≠ j → (if x = j ∧ k = i then ↑|b.cartanMatrix i x| else 0) = (0 : R) := by aesop
simpa [e, f, P.ne_zero, hij, -indexNeg_neg, -Finset.univ_eq_attach, ← ite_and,
Finset.sum_eq_single_of_mem j (Finset.mem_univ _) aux]
rcases eq_or_ne k i with rfl | hk; swap
· rw [if_neg (by tauto), Finset.sum_ite_of_false (by aesop)]; simp
by_cases hij_mem : P.root i + P.root j ∈ range P.root
· obtain ⟨m, hm⟩ := hij_mem
rw [Finset.sum_eq_single_of_mem m (Finset.mem_univ _) (by rintro x - hx; simp [← hm, hx]),
b.abs_cartanMatrix_apply, Base.cartanMatrix, Base.cartanMatrixIn_def]
have aux₁ := b.chainTopCoeff_eq_of_ne hij.symm
have aux₂ := chainTopCoeff_of_add (b.linearIndependent_pair_of_ne hij.symm) hm
norm_cast
aesop
· have aux : ∀ x ∈ Finset.univ,
¬ (P.root x = P.root i + P.root j ∧ P.root i = P.root x - P.root j) := by
rintro x - ⟨hx, -⟩; exact hij_mem ⟨x, hx⟩
simp [Finset.sum_ite_of_false aux, b.cartanMatrix_apply_eq_zero_iff hij, hij_mem]
/-- An auxiliary lemma en route to `RootPairing.Base.lie_e_f_ne`. -/
private lemma lie_e_f_ne_aux₂ :
letI := P.indexNeg
⁅e i, f j⁆ᵀ (Sum.inr (-i)) = 0 := by
letI := P.indexNeg
classical
ext (k | k)
· rw [Matrix.transpose_apply, lie_e_f_ne_aux₀, Pi.zero_apply]
· have aux : ⁅e i, f j⁆ (.inr k) (.inr (-i)) = (⁅e i, f j⁆ * ω b) (.inr k) (.inr i) := by simp [ω]
rw [Matrix.transpose_apply, aux, lie_e_f_mul_ω, ← (-ω b * ⁅e j, f i⁆).transpose_apply,
Matrix.transpose_mul, Matrix.mul_apply', lie_e_f_ne_aux₁ hij.symm]
simp
/-- Lemma 3.5 from [Geck](Geck2017). -/
lemma lie_e_f_ne [P.IsReduced] [P.IsIrreducible] :
⁅e i, f j⁆ = 0 := by
letI := P.indexNeg
classical
ext (k | k) (l | l)
· aesop (erase simp indexNeg_neg) (add simp [e, f, Matrix.mul_apply, mul_ite, ite_mul])
· exact lie_e_f_ne_aux₀ k l
· have aux₁ : P.root k ≠ P.root i - P.root j :=
fun contra ↦ b.sub_notMem_range_root i.property j.property ⟨k, contra⟩
simp [e, f, ← sub_eq_add_neg, if_neg aux₁]
· /- Geck Case 1 (covered by the auxiliary lemmas above). -/
rcases eq_or_ne l j with rfl | h₃
· rw [← ⁅e i, f j⁆.transpose_apply, lie_e_f_ne_aux₁ hij, Pi.zero_apply, Matrix.zero_apply]
rcases eq_or_ne l (-i) with rfl | h₄
· rw [← ⁅e i, f j⁆.transpose_apply, lie_e_f_ne_aux₂ hij, Pi.zero_apply, Matrix.zero_apply]
/- Geck Case 2.
It's all just definition unfolding and case analysis: the only real content is the external
lemma `chainBotCoeff_mul_chainTopCoeff`. -/
suffices
(∑ x, if P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x then
((P.chainBotCoeff i x : R) + 1) * (P.chainTopCoeff j l + 1) else 0) =
(∑ x, if P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j then
((P.chainTopCoeff j x : R) + 1) * (P.chainBotCoeff i l + 1) else 0) by
have h₁ : ∀ x ∈ Finset.univ, ¬ ((x = i ∧ l = -i) ∧ k = -j) := by
rintro - - ⟨⟨-, contra⟩, -⟩; contradiction
have h₂ : ∀ x ∈ Finset.univ, ¬ ((x = j ∧ l = j) ∧ k = i) := by
rintro - - ⟨⟨-, contra⟩, -⟩; contradiction
rw [← sub_eq_zero] at this
simpa [e, f, ← ite_and, Finset.sum_ite_of_false h₁, Finset.sum_ite_of_false h₂, -indexNeg_neg,
-Finset.univ_eq_attach]
by_cases h₅ : P.root l + P.root i - P.root j ∈ range P.root; swap
· have aux₃ : ∀ x ∈ Finset.univ,
¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by
rintro x - ⟨hx, hx'⟩; exact h₅ ⟨k, by rw [hx', hx]; abel⟩
have aux₄ : ∀ x ∈ Finset.univ,
¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by
rintro x - ⟨hx, hx'⟩; exact h₅ ⟨k, by rw [hx', hx]; abel⟩
simp [Finset.sum_ite_of_false aux₃, Finset.sum_ite_of_false aux₄]
by_cases h₆ : P.root l + P.root i ∈ range P.root; swap
· have h₇ : P.root l - P.root j ∉ range P.root := by
rwa [b.root_sub_mem_iff_root_add_mem i j l (by aesop) i.property j.property
(by aesop) (by aesop) h₅]
have aux₃ : ∀ x ∈ Finset.univ,
¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by
rintro x - ⟨hx, -⟩; exact h₆ ⟨x, by rw [hx]; abel⟩
have aux₄ : ∀ x ∈ Finset.univ,
¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by
rintro x - ⟨hx, hx'⟩; exact h₇ ⟨x, hx⟩
simp [Finset.sum_ite_of_false aux₃, Finset.sum_ite_of_false aux₄]
obtain ⟨m, hm : P.root m = P.root l - P.root j⟩ :=
b.root_sub_root_mem_of_mem_of_mem i j l (by aesop) i.property j.property h₅ h₃ h₆
obtain ⟨l', hl'⟩ := h₆
by_cases hk : P.root k = P.root l + P.root i - P.root j; swap
· grind
have aux₃ (x) (hx : x ≠ m) :
¬ (P.root x = P.root l - P.root j ∧ P.root k = P.root i + P.root x) := by
grind [EmbeddingLike.apply_eq_iff_eq]
have aux₄ (x) (hx : x ≠ l') :
¬ (P.root x = P.root i + P.root l ∧ P.root k = P.root x - P.root j) := by
grind [EmbeddingLike.apply_eq_iff_eq]
rw [Finset.sum_eq_single_of_mem m (Finset.mem_univ _) (by rintro x - h; rw [if_neg (aux₃ _ h)]),
Finset.sum_eq_single_of_mem l' (Finset.mem_univ _) (by rintro x - h; rw [if_neg (aux₄ _ h)]),
if_pos (⟨hm, by rw [hm, hk]; abel⟩), if_pos ⟨by rw [hl', add_comm], by rw [hl', hk]⟩]
have := chainBotCoeff_mul_chainTopCoeff i.property j.property (by aesop) hl'.symm hm.symm h₅
norm_cast
end lie_e_f_ne
end RootPairing.GeckConstruction
|
Basic.lean
|
/-
Copyright (c) 2021 Luke Kershaw. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Luke Kershaw
-/
import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products
import Mathlib.CategoryTheory.Limits.Shapes.BinaryBiproducts
import Mathlib.CategoryTheory.Shift.Basic
/-!
# Triangles
This file contains the definition of triangles in an additive category with an additive shift.
It also defines morphisms between these triangles.
TODO: generalise this to n-angles in n-angulated categories as in https://arxiv.org/abs/1006.4592
-/
noncomputable section
open CategoryTheory Limits
universe v v₀ v₁ v₂ u u₀ u₁ u₂
namespace CategoryTheory.Pretriangulated
open CategoryTheory.Category
/-
We work in a category `C` equipped with a shift.
-/
variable (C : Type u) [Category.{v} C] [HasShift C ℤ]
/-- A triangle in `C` is a sextuple `(X,Y,Z,f,g,h)` where `X,Y,Z` are objects of `C`,
and `f : X ⟶ Y`, `g : Y ⟶ Z`, `h : Z ⟶ X⟦1⟧` are morphisms in `C`. -/
@[stacks 0144]
structure Triangle where mk' ::
/-- the first object of a triangle -/
obj₁ : C
/-- the second object of a triangle -/
obj₂ : C
/-- the third object of a triangle -/
obj₃ : C
/-- the first morphism of a triangle -/
mor₁ : obj₁ ⟶ obj₂
/-- the second morphism of a triangle -/
mor₂ : obj₂ ⟶ obj₃
/-- the third morphism of a triangle -/
mor₃ : obj₃ ⟶ obj₁⟦(1 : ℤ)⟧
variable {C}
/-- A triangle `(X,Y,Z,f,g,h)` in `C` is defined by the morphisms `f : X ⟶ Y`, `g : Y ⟶ Z`
and `h : Z ⟶ X⟦1⟧`.
-/
@[simps]
def Triangle.mk {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (h : Z ⟶ X⟦(1 : ℤ)⟧) : Triangle C where
obj₁ := X
obj₂ := Y
obj₃ := Z
mor₁ := f
mor₂ := g
mor₃ := h
section
variable [HasZeroObject C] [HasZeroMorphisms C]
open ZeroObject
instance : Inhabited (Triangle C) :=
⟨⟨0, 0, 0, 0, 0, 0⟩⟩
/-- For each object in `C`, there is a triangle of the form `(X,X,0,𝟙 X,0,0)`
-/
@[simps!]
def contractibleTriangle (X : C) : Triangle C :=
Triangle.mk (𝟙 X) (0 : X ⟶ 0) 0
end
/-- A morphism of triangles `(X,Y,Z,f,g,h) ⟶ (X',Y',Z',f',g',h')` in `C` is a triple of morphisms
`a : X ⟶ X'`, `b : Y ⟶ Y'`, `c : Z ⟶ Z'` such that
`a ≫ f' = f ≫ b`, `b ≫ g' = g ≫ c`, and `a⟦1⟧' ≫ h = h' ≫ c`.
In other words, we have a commutative diagram:
```
f g h
X ───> Y ───> Z ───> X⟦1⟧
│ │ │ │
│a │b │c │a⟦1⟧'
V V V V
X' ───> Y' ───> Z' ───> X'⟦1⟧
f' g' h'
```
-/
@[ext, stacks 0144]
structure TriangleMorphism (T₁ : Triangle C) (T₂ : Triangle C) where
/-- the first morphism in a triangle morphism -/
hom₁ : T₁.obj₁ ⟶ T₂.obj₁
/-- the second morphism in a triangle morphism -/
hom₂ : T₁.obj₂ ⟶ T₂.obj₂
/-- the third morphism in a triangle morphism -/
hom₃ : T₁.obj₃ ⟶ T₂.obj₃
/-- the first commutative square of a triangle morphism -/
comm₁ : T₁.mor₁ ≫ hom₂ = hom₁ ≫ T₂.mor₁ := by cat_disch
/-- the second commutative square of a triangle morphism -/
comm₂ : T₁.mor₂ ≫ hom₃ = hom₂ ≫ T₂.mor₂ := by cat_disch
/-- the third commutative square of a triangle morphism -/
comm₃ : T₁.mor₃ ≫ hom₁⟦1⟧' = hom₃ ≫ T₂.mor₃ := by cat_disch
attribute [reassoc (attr := simp)] TriangleMorphism.comm₁ TriangleMorphism.comm₂
TriangleMorphism.comm₃
/-- The identity triangle morphism.
-/
@[simps]
def triangleMorphismId (T : Triangle C) : TriangleMorphism T T where
hom₁ := 𝟙 T.obj₁
hom₂ := 𝟙 T.obj₂
hom₃ := 𝟙 T.obj₃
instance (T : Triangle C) : Inhabited (TriangleMorphism T T) :=
⟨triangleMorphismId T⟩
variable {T₁ T₂ T₃ : Triangle C}
/-- Composition of triangle morphisms gives a triangle morphism.
-/
@[simps]
def TriangleMorphism.comp (f : TriangleMorphism T₁ T₂) (g : TriangleMorphism T₂ T₃) :
TriangleMorphism T₁ T₃ where
hom₁ := f.hom₁ ≫ g.hom₁
hom₂ := f.hom₂ ≫ g.hom₂
hom₃ := f.hom₃ ≫ g.hom₃
/-- Triangles with triangle morphisms form a category.
-/
@[simps]
instance triangleCategory : Category (Triangle C) where
Hom A B := TriangleMorphism A B
id A := triangleMorphismId A
comp f g := f.comp g
@[ext]
lemma Triangle.hom_ext {A B : Triangle C} (f g : A ⟶ B)
(h₁ : f.hom₁ = g.hom₁) (h₂ : f.hom₂ = g.hom₂) (h₃ : f.hom₃ = g.hom₃) : f = g :=
TriangleMorphism.ext h₁ h₂ h₃
@[simp]
lemma id_hom₁ (A : Triangle C) : TriangleMorphism.hom₁ (𝟙 A) = 𝟙 _ := rfl
@[simp]
lemma id_hom₂ (A : Triangle C) : TriangleMorphism.hom₂ (𝟙 A) = 𝟙 _ := rfl
@[simp]
lemma id_hom₃ (A : Triangle C) : TriangleMorphism.hom₃ (𝟙 A) = 𝟙 _ := rfl
@[simp, reassoc]
lemma comp_hom₁ {X Y Z : Triangle C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom₁ = f.hom₁ ≫ g.hom₁ := rfl
@[simp, reassoc]
lemma comp_hom₂ {X Y Z : Triangle C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom₂ = f.hom₂ ≫ g.hom₂ := rfl
@[simp, reassoc]
lemma comp_hom₃ {X Y Z : Triangle C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom₃ = f.hom₃ ≫ g.hom₃ := rfl
/-- Make a morphism between triangles from the required data. -/
@[simps]
def Triangle.homMk (A B : Triangle C)
(hom₁ : A.obj₁ ⟶ B.obj₁) (hom₂ : A.obj₂ ⟶ B.obj₂) (hom₃ : A.obj₃ ⟶ B.obj₃)
(comm₁ : A.mor₁ ≫ hom₂ = hom₁ ≫ B.mor₁ := by cat_disch)
(comm₂ : A.mor₂ ≫ hom₃ = hom₂ ≫ B.mor₂ := by cat_disch)
(comm₃ : A.mor₃ ≫ hom₁⟦1⟧' = hom₃ ≫ B.mor₃ := by cat_disch) :
A ⟶ B where
hom₁ := hom₁
hom₂ := hom₂
hom₃ := hom₃
comm₁ := comm₁
comm₂ := comm₂
comm₃ := comm₃
/-- Make an isomorphism between triangles from the required data. -/
@[simps]
def Triangle.isoMk (A B : Triangle C)
(iso₁ : A.obj₁ ≅ B.obj₁) (iso₂ : A.obj₂ ≅ B.obj₂) (iso₃ : A.obj₃ ≅ B.obj₃)
(comm₁ : A.mor₁ ≫ iso₂.hom = iso₁.hom ≫ B.mor₁ := by cat_disch)
(comm₂ : A.mor₂ ≫ iso₃.hom = iso₂.hom ≫ B.mor₂ := by cat_disch)
(comm₃ : A.mor₃ ≫ iso₁.hom⟦1⟧' = iso₃.hom ≫ B.mor₃ := by cat_disch) : A ≅ B where
hom := Triangle.homMk _ _ iso₁.hom iso₂.hom iso₃.hom comm₁ comm₂ comm₃
inv := Triangle.homMk _ _ iso₁.inv iso₂.inv iso₃.inv
(by simp only [← cancel_mono iso₂.hom, assoc, Iso.inv_hom_id, comp_id,
comm₁, Iso.inv_hom_id_assoc])
(by simp only [← cancel_mono iso₃.hom, assoc, Iso.inv_hom_id, comp_id,
comm₂, Iso.inv_hom_id_assoc])
(by simp only [← cancel_mono (iso₁.hom⟦(1 : ℤ)⟧'), Category.assoc, comm₃,
Iso.inv_hom_id_assoc, ← Functor.map_comp, Iso.inv_hom_id,
Functor.map_id, Category.comp_id])
lemma Triangle.isIso_of_isIsos {A B : Triangle C} (f : A ⟶ B)
(h₁ : IsIso f.hom₁) (h₂ : IsIso f.hom₂) (h₃ : IsIso f.hom₃) : IsIso f := by
let e := Triangle.isoMk A B (asIso f.hom₁) (asIso f.hom₂) (asIso f.hom₃)
(by simp) (by simp) (by simp)
exact (inferInstance : IsIso e.hom)
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.hom_inv_id_triangle_hom₁ {A B : Triangle C} (e : A ≅ B) :
e.hom.hom₁ ≫ e.inv.hom₁ = 𝟙 _ := by rw [← comp_hom₁, e.hom_inv_id, id_hom₁]
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.hom_inv_id_triangle_hom₂ {A B : Triangle C} (e : A ≅ B) :
e.hom.hom₂ ≫ e.inv.hom₂ = 𝟙 _ := by rw [← comp_hom₂, e.hom_inv_id, id_hom₂]
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.hom_inv_id_triangle_hom₃ {A B : Triangle C} (e : A ≅ B) :
e.hom.hom₃ ≫ e.inv.hom₃ = 𝟙 _ := by rw [← comp_hom₃, e.hom_inv_id, id_hom₃]
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.inv_hom_id_triangle_hom₁ {A B : Triangle C} (e : A ≅ B) :
e.inv.hom₁ ≫ e.hom.hom₁ = 𝟙 _ := by rw [← comp_hom₁, e.inv_hom_id, id_hom₁]
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.inv_hom_id_triangle_hom₂ {A B : Triangle C} (e : A ≅ B) :
e.inv.hom₂ ≫ e.hom.hom₂ = 𝟙 _ := by rw [← comp_hom₂, e.inv_hom_id, id_hom₂]
@[reassoc (attr := simp)]
lemma _root_.CategoryTheory.Iso.inv_hom_id_triangle_hom₃ {A B : Triangle C} (e : A ≅ B) :
e.inv.hom₃ ≫ e.hom.hom₃ = 𝟙 _ := by rw [← comp_hom₃, e.inv_hom_id, id_hom₃]
lemma Triangle.eqToHom_hom₁ {A B : Triangle C} (h : A = B) :
(eqToHom h).hom₁ = eqToHom (by subst h; rfl) := by subst h; rfl
lemma Triangle.eqToHom_hom₂ {A B : Triangle C} (h : A = B) :
(eqToHom h).hom₂ = eqToHom (by subst h; rfl) := by subst h; rfl
lemma Triangle.eqToHom_hom₃ {A B : Triangle C} (h : A = B) :
(eqToHom h).hom₃ = eqToHom (by subst h; rfl) := by subst h; rfl
/-- The obvious triangle `X₁ ⟶ X₁ ⊞ X₂ ⟶ X₂ ⟶ X₁⟦1⟧`. -/
@[simps!]
def binaryBiproductTriangle (X₁ X₂ : C) [HasZeroMorphisms C] [HasBinaryBiproduct X₁ X₂] :
Triangle C :=
Triangle.mk biprod.inl (Limits.biprod.snd : X₁ ⊞ X₂ ⟶ _) 0
/-- The obvious triangle `X₁ ⟶ X₁ ⨯ X₂ ⟶ X₂ ⟶ X₁⟦1⟧`. -/
@[simps!]
def binaryProductTriangle (X₁ X₂ : C) [HasZeroMorphisms C] [HasBinaryProduct X₁ X₂] :
Triangle C :=
Triangle.mk ((Limits.prod.lift (𝟙 X₁) 0)) (Limits.prod.snd : X₁ ⨯ X₂ ⟶ _) 0
/-- The canonical isomorphism of triangles
`binaryProductTriangle X₁ X₂ ≅ binaryBiproductTriangle X₁ X₂`. -/
@[simps!]
def binaryProductTriangleIsoBinaryBiproductTriangle
(X₁ X₂ : C) [HasZeroMorphisms C] [HasBinaryBiproduct X₁ X₂] :
binaryProductTriangle X₁ X₂ ≅ binaryBiproductTriangle X₁ X₂ :=
Triangle.isoMk _ _ (Iso.refl _) (biprod.isoProd X₁ X₂).symm (Iso.refl _)
(by cat_disch) (by simp) (by simp)
section
variable {J : Type*} (T : J → Triangle C)
[HasProduct (fun j => (T j).obj₁)] [HasProduct (fun j => (T j).obj₂)]
[HasProduct (fun j => (T j).obj₃)] [HasProduct (fun j => (T j).obj₁⟦(1 : ℤ)⟧)]
/-- The product of a family of triangles. -/
@[simps!]
def productTriangle : Triangle C :=
Triangle.mk (Limits.Pi.map (fun j => (T j).mor₁))
(Limits.Pi.map (fun j => (T j).mor₂))
(Limits.Pi.map (fun j => (T j).mor₃) ≫ inv (piComparison _ _))
/-- A projection from the product of a family of triangles. -/
@[simps]
def productTriangle.π (j : J) :
productTriangle T ⟶ T j where
hom₁ := Pi.π _ j
hom₂ := Pi.π _ j
hom₃ := Pi.π _ j
comm₃ := by
dsimp
rw [← piComparison_comp_π, assoc, IsIso.inv_hom_id_assoc]
simp only [limMap_π, Discrete.natTrans_app]
/-- The fan given by `productTriangle T`. -/
@[simp]
def productTriangle.fan : Fan T := Fan.mk (productTriangle T) (productTriangle.π T)
/-- A family of morphisms `T' ⟶ T j` lifts to a morphism `T' ⟶ productTriangle T`. -/
@[simps]
def productTriangle.lift {T' : Triangle C} (φ : ∀ j, T' ⟶ T j) :
T' ⟶ productTriangle T where
hom₁ := Pi.lift (fun j => (φ j).hom₁)
hom₂ := Pi.lift (fun j => (φ j).hom₂)
hom₃ := Pi.lift (fun j => (φ j).hom₃)
comm₃ := by
dsimp
rw [← cancel_mono (piComparison _ _), assoc, assoc, assoc, IsIso.inv_hom_id, comp_id]
cat_disch
/-- The triangle `productTriangle T` satisfies the universal property of the categorical
product of the triangles `T`. -/
def productTriangle.isLimitFan : IsLimit (productTriangle.fan T) :=
mkFanLimit _ (fun s => productTriangle.lift T s.proj) (fun s j => by cat_disch) (by
intro s m hm
ext1
all_goals
exact Pi.hom_ext _ _ (fun j => (by simp [← hm])))
lemma productTriangle.zero₃₁ [HasZeroMorphisms C]
(h : ∀ j, (T j).mor₃ ≫ (T j).mor₁⟦(1 : ℤ)⟧' = 0) :
(productTriangle T).mor₃ ≫ (productTriangle T).mor₁⟦1⟧' = 0 := by
have : HasProduct (fun j => (T j).obj₂⟦(1 : ℤ)⟧) :=
⟨_, isLimitFanMkObjOfIsLimit (shiftFunctor C (1 : ℤ)) _ _
(productIsProduct (fun j => (T j).obj₂))⟩
dsimp
change _ ≫ (Pi.lift (fun j => Pi.π _ j ≫ (T j).mor₁))⟦(1 : ℤ)⟧' = 0
rw [assoc, ← cancel_mono (piComparison _ _), zero_comp, assoc, assoc]
ext j
simp only [map_lift_piComparison, assoc, limit.lift_π, Fan.mk_π_app, zero_comp,
Functor.map_comp, ← piComparison_comp_π_assoc, IsIso.inv_hom_id_assoc,
limMap_π_assoc, Discrete.natTrans_app, h j, comp_zero]
end
variable (C) in
/-- The functor `C ⥤ Triangle C` which sends `X` to `contractibleTriangle X`. -/
@[simps]
def contractibleTriangleFunctor [HasZeroObject C] [HasZeroMorphisms C] : C ⥤ Triangle C where
obj X := contractibleTriangle X
map f :=
{ hom₁ := f
hom₂ := f
hom₃ := 0 }
namespace Triangle
/-- The first projection `Triangle C ⥤ C`. -/
@[simps]
def π₁ : Triangle C ⥤ C where
obj T := T.obj₁
map f := f.hom₁
/-- The second projection `Triangle C ⥤ C`. -/
@[simps]
def π₂ : Triangle C ⥤ C where
obj T := T.obj₂
map f := f.hom₂
/-- The third projection `Triangle C ⥤ C`. -/
@[simps]
def π₃ : Triangle C ⥤ C where
obj T := T.obj₃
map f := f.hom₃
section
variable {A B : Triangle C} (φ : A ⟶ B) [IsIso φ]
instance : IsIso φ.hom₁ := (inferInstance : IsIso (π₁.map φ))
instance : IsIso φ.hom₂ := (inferInstance : IsIso (π₂.map φ))
instance : IsIso φ.hom₃ := (inferInstance : IsIso (π₃.map φ))
end
end Triangle
end CategoryTheory.Pretriangulated
|
Maps.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Data.DFinsupp.Module
import Mathlib.RingTheory.Ideal.Operations
/-!
# Maps on modules and ideals
Main definitions include `Ideal.map`, `Ideal.comap`, `RingHom.ker`, `Module.annihilator`
and `Submodule.annihilator`.
-/
assert_not_exists Module.Basis -- See `RingTheory.Ideal.Basis`
Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations`
universe u v w x
open Pointwise
namespace Ideal
section MapAndComap
variable {R : Type u} {S : Type v}
section Semiring
variable {F : Type*} [Semiring R] [Semiring S]
variable [FunLike F R S]
variable (f : F)
variable {I J : Ideal R} {K L : Ideal S}
/-- `I.map f` is the span of the image of the ideal `I` under `f`, which may be bigger than
the image itself. -/
def map (I : Ideal R) : Ideal S :=
span (f '' I)
/-- `I.comap f` is the preimage of `I` under `f`. -/
def comap [RingHomClass F R S] (I : Ideal S) : Ideal R where
carrier := f ⁻¹' I
add_mem' {x y} hx hy := by
simp only [Set.mem_preimage, SetLike.mem_coe, map_add f] at hx hy ⊢
exact add_mem hx hy
zero_mem' := by simp only [Set.mem_preimage, map_zero, SetLike.mem_coe, Submodule.zero_mem]
smul_mem' c x hx := by
simp only [smul_eq_mul, Set.mem_preimage, map_mul, SetLike.mem_coe] at *
exact mul_mem_left I _ hx
@[simp]
theorem coe_comap [RingHomClass F R S] (I : Ideal S) : (comap f I : Set R) = f ⁻¹' I := rfl
lemma comap_coe [RingHomClass F R S] (I : Ideal S) : I.comap (f : R →+* S) = I.comap f := rfl
lemma map_coe [RingHomClass F R S] (I : Ideal R) : I.map (f : R →+* S) = I.map f := rfl
variable {f}
theorem map_mono (h : I ≤ J) : map f I ≤ map f J :=
span_mono <| Set.image_mono h
theorem mem_map_of_mem (f : F) {I : Ideal R} {x : R} (h : x ∈ I) : f x ∈ map f I :=
subset_span ⟨x, h, rfl⟩
theorem apply_coe_mem_map (f : F) (I : Ideal R) (x : I) : f x ∈ I.map f :=
mem_map_of_mem f x.2
theorem map_le_iff_le_comap [RingHomClass F R S] : map f I ≤ K ↔ I ≤ comap f K :=
span_le.trans Set.image_subset_iff
@[simp]
theorem mem_comap [RingHomClass F R S] {x} : x ∈ comap f K ↔ f x ∈ K :=
Iff.rfl
theorem comap_mono [RingHomClass F R S] (h : K ≤ L) : comap f K ≤ comap f L :=
Set.preimage_mono fun _ hx => h hx
variable (f)
theorem comap_ne_top [RingHomClass F R S] (hK : K ≠ ⊤) : comap f K ≠ ⊤ :=
(ne_top_iff_one _).2 <| by rw [mem_comap, map_one]; exact (ne_top_iff_one _).1 hK
lemma exists_ideal_comap_le_prime {S} [CommSemiring S] [FunLike F R S] [RingHomClass F R S]
{f : F} (P : Ideal R) [P.IsPrime] (I : Ideal S) (le : I.comap f ≤ P) :
∃ Q ≥ I, Q.IsPrime ∧ Q.comap f ≤ P :=
have ⟨Q, hQ, hIQ, disj⟩ := I.exists_le_prime_disjoint (P.primeCompl.map f) <|
Set.disjoint_left.mpr fun _ ↦ by rintro hI ⟨r, hp, rfl⟩; exact hp (le hI)
⟨Q, hIQ, hQ, fun r hp' ↦ of_not_not fun hp ↦ Set.disjoint_left.mp disj hp' ⟨_, hp, rfl⟩⟩
variable {G : Type*} [FunLike G S R]
theorem map_le_comap_of_inv_on [RingHomClass G S R] (g : G) (I : Ideal R)
(hf : Set.LeftInvOn g f I) :
I.map f ≤ I.comap g := by
refine Ideal.span_le.2 ?_
rintro x ⟨x, hx, rfl⟩
rw [SetLike.mem_coe, mem_comap, hf hx]
exact hx
theorem comap_le_map_of_inv_on [RingHomClass F R S] (g : G) (I : Ideal S)
(hf : Set.LeftInvOn g f (f ⁻¹' I)) :
I.comap f ≤ I.map g :=
fun x (hx : f x ∈ I) => hf hx ▸ Ideal.mem_map_of_mem g hx
/-- The `Ideal` version of `Set.image_subset_preimage_of_inverse`. -/
theorem map_le_comap_of_inverse [RingHomClass G S R] (g : G) (I : Ideal R)
(h : Function.LeftInverse g f) :
I.map f ≤ I.comap g :=
map_le_comap_of_inv_on _ _ _ <| h.leftInvOn _
variable [RingHomClass F R S]
instance (priority := low) [K.IsTwoSided] : (comap f K).IsTwoSided :=
⟨fun b ha ↦ by rw [mem_comap, map_mul]; exact mul_mem_right _ _ ha⟩
/-- The `Ideal` version of `Set.preimage_subset_image_of_inverse`. -/
theorem comap_le_map_of_inverse (g : G) (I : Ideal S) (h : Function.LeftInverse g f) :
I.comap f ≤ I.map g :=
comap_le_map_of_inv_on _ _ _ <| h.leftInvOn _
instance IsPrime.comap [hK : K.IsPrime] : (comap f K).IsPrime :=
⟨comap_ne_top _ hK.1, fun {x y} => by simp only [mem_comap, map_mul]; apply hK.2⟩
variable (I J K L)
theorem map_top : map f ⊤ = ⊤ :=
(eq_top_iff_one _).2 <| subset_span ⟨1, trivial, map_one f⟩
theorem gc_map_comap : GaloisConnection (Ideal.map f) (Ideal.comap f) := fun _ _ =>
Ideal.map_le_iff_le_comap
@[simp]
theorem comap_id : I.comap (RingHom.id R) = I :=
Ideal.ext fun _ => Iff.rfl
@[simp]
lemma comap_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.comap (AlgHom.id R S) I = I :=
I.comap_id
@[simp]
theorem map_id : I.map (RingHom.id R) = I :=
(gc_map_comap (RingHom.id R)).l_unique GaloisConnection.id comap_id
@[simp]
lemma map_idₐ {R S : Type*} [CommSemiring R] [Semiring S] [Algebra R S] (I : Ideal S) :
Ideal.map (AlgHom.id R S) I = I :=
I.map_id
theorem comap_comap {T : Type*} [Semiring T] {I : Ideal T} (f : R →+* S) (g : S →+* T) :
(I.comap g).comap f = I.comap (g.comp f) :=
rfl
lemma comap_comapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal C} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.comap g).comap f = I.comap (g.comp f) :=
I.comap_comap f.toRingHom g.toRingHom
theorem map_map {T : Type*} [Semiring T] {I : Ideal R} (f : R →+* S) (g : S →+* T) :
(I.map f).map g = I.map (g.comp f) :=
((gc_map_comap f).compose (gc_map_comap g)).l_unique (gc_map_comap (g.comp f)) fun _ =>
comap_comap _ _
lemma map_mapₐ {R A B C : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [Semiring B]
[Algebra R B] [Semiring C] [Algebra R C] {I : Ideal A} (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(I.map f).map g = I.map (g.comp f) :=
I.map_map f.toRingHom g.toRingHom
theorem map_span (f : F) (s : Set R) : map f (span s) = span (f '' s) := by
refine (Submodule.span_eq_of_le _ ?_ ?_).symm
· rintro _ ⟨x, hx, rfl⟩; exact mem_map_of_mem f (subset_span hx)
· rw [map_le_iff_le_comap, span_le, coe_comap, ← Set.image_subset_iff]
exact subset_span
variable {f I J K L}
theorem map_le_of_le_comap : I ≤ K.comap f → I.map f ≤ K :=
(gc_map_comap f).l_le
theorem le_comap_of_map_le : I.map f ≤ K → I ≤ K.comap f :=
(gc_map_comap f).le_u
theorem le_comap_map : I ≤ (I.map f).comap f :=
(gc_map_comap f).le_u_l _
theorem map_comap_le : (K.comap f).map f ≤ K :=
(gc_map_comap f).l_u_le _
@[simp]
theorem comap_top : (⊤ : Ideal S).comap f = ⊤ :=
(gc_map_comap f).u_top
@[simp]
theorem comap_eq_top_iff {I : Ideal S} : I.comap f = ⊤ ↔ I = ⊤ :=
⟨fun h => I.eq_top_iff_one.mpr (map_one f ▸ mem_comap.mp ((I.comap f).eq_top_iff_one.mp h)),
fun h => by rw [h, comap_top]⟩
@[simp]
theorem map_bot : (⊥ : Ideal R).map f = ⊥ :=
(gc_map_comap f).l_bot
theorem ne_bot_of_map_ne_bot (hI : map f I ≠ ⊥) : I ≠ ⊥ :=
fun h => hI (Eq.mpr (congrArg (fun I ↦ map f I = ⊥) h) map_bot)
variable (f I J K L)
@[simp]
theorem map_comap_map : ((I.map f).comap f).map f = I.map f :=
(gc_map_comap f).l_u_l_eq_l I
@[simp]
theorem comap_map_comap : ((K.comap f).map f).comap f = K.comap f :=
(gc_map_comap f).u_l_u_eq_u K
theorem map_sup : (I ⊔ J).map f = I.map f ⊔ J.map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sup
theorem comap_inf : comap f (K ⊓ L) = comap f K ⊓ comap f L :=
rfl
variable {ι : Sort*}
theorem map_iSup (K : ι → Ideal R) : (iSup K).map f = ⨆ i, (K i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
theorem comap_iInf (K : ι → Ideal S) : (iInf K).comap f = ⨅ i, (K i).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_iInf
theorem map_sSup (s : Set (Ideal R)) : (sSup s).map f = ⨆ I ∈ s, (I : Ideal R).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_sSup
theorem comap_sInf (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ s, (I : Ideal S).comap f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).u_sInf
theorem comap_sInf' (s : Set (Ideal S)) : (sInf s).comap f = ⨅ I ∈ comap f '' s, I :=
_root_.trans (comap_sInf f s) (by rw [iInf_image])
/-- Variant of `Ideal.IsPrime.comap` where ideal is explicit rather than implicit. -/
theorem comap_isPrime [H : IsPrime K] : IsPrime (comap f K) :=
H.comap f
variable {I J K L}
theorem map_inf_le : map f (I ⊓ J) ≤ map f I ⊓ map f J :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_l.map_inf_le _ _
theorem le_comap_sup : comap f K ⊔ comap f L ≤ comap f (K ⊔ L) :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).monotone_u.le_map_sup _ _
-- TODO: Should these be simp lemmas?
theorem _root_.element_smul_restrictScalars {R S M}
[CommSemiring R] [CommSemiring S] [Algebra R S] [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] (r : R) (N : Submodule S M) :
(algebraMap R S r • N).restrictScalars R = r • N.restrictScalars R :=
SetLike.coe_injective (congrArg (· '' _) (funext (algebraMap_smul S r)))
theorem smul_restrictScalars {R S M} [CommSemiring R] [CommSemiring S]
[Algebra R S] [AddCommMonoid M] [Module R M] [Module S M]
[IsScalarTower R S M] (I : Ideal R) (N : Submodule S M) :
(I.map (algebraMap R S) • N).restrictScalars R = I • N.restrictScalars R := by
simp_rw [map, Submodule.span_smul_eq, ← Submodule.coe_set_smul,
Submodule.set_smul_eq_iSup, ← element_smul_restrictScalars, iSup_image]
exact map_iSup₂ (Submodule.restrictScalarsLatticeHom R S M) _
@[simp]
theorem smul_top_eq_map {R S : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S]
(I : Ideal R) : I • (⊤ : Submodule R S) = (I.map (algebraMap R S)).restrictScalars R :=
Eq.trans (smul_restrictScalars I (⊤ : Ideal S)).symm <|
congrArg _ <| Eq.trans (Ideal.smul_eq_mul _ _) (Ideal.mul_top _)
@[simp]
theorem coe_restrictScalars {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I : Ideal S) : (I.restrictScalars R : Set S) = ↑I :=
rfl
/-- The smallest `S`-submodule that contains all `x ∈ I * y ∈ J`
is also the smallest `R`-submodule that does so. -/
@[simp]
theorem restrictScalars_mul {R S : Type*} [Semiring R] [Semiring S] [Module R S]
[IsScalarTower R S S] (I J : Ideal S) :
(I * J).restrictScalars R = I.restrictScalars R * J.restrictScalars R :=
rfl
section Surjective
section
variable (hf : Function.Surjective f)
include hf
open Function
theorem map_comap_of_surjective (I : Ideal S) : map f (comap f I) = I :=
le_antisymm (map_le_iff_le_comap.2 le_rfl) fun s hsi =>
let ⟨r, hfrs⟩ := hf s
hfrs ▸ (mem_map_of_mem f <| show f r ∈ I from hfrs.symm ▸ hsi)
/-- `map` and `comap` are adjoint, and the composition `map f ∘ comap f` is the
identity -/
def giMapComap : GaloisInsertion (map f) (comap f) :=
GaloisInsertion.monotoneIntro (gc_map_comap f).monotone_u (gc_map_comap f).monotone_l
(fun _ => le_comap_map) (map_comap_of_surjective _ hf)
theorem map_surjective_of_surjective : Surjective (map f) :=
(giMapComap f hf).l_surjective
theorem comap_injective_of_surjective : Injective (comap f) :=
(giMapComap f hf).u_injective
theorem map_sup_comap_of_surjective (I J : Ideal S) : (I.comap f ⊔ J.comap f).map f = I ⊔ J :=
(giMapComap f hf).l_sup_u _ _
theorem map_iSup_comap_of_surjective (K : ι → Ideal S) : (⨆ i, (K i).comap f).map f = iSup K :=
(giMapComap f hf).l_iSup_u _
theorem map_inf_comap_of_surjective (I J : Ideal S) : (I.comap f ⊓ J.comap f).map f = I ⊓ J :=
(giMapComap f hf).l_inf_u _ _
theorem map_iInf_comap_of_surjective (K : ι → Ideal S) : (⨅ i, (K i).comap f).map f = iInf K :=
(giMapComap f hf).l_iInf_u _
theorem mem_image_of_mem_map_of_surjective {I : Ideal R} {y} (H : y ∈ map f I) : y ∈ f '' I :=
Submodule.span_induction (hx := H) (fun _ => id) ⟨0, I.zero_mem, map_zero f⟩
(fun _ _ _ _ ⟨x1, hx1i, hxy1⟩ ⟨x2, hx2i, hxy2⟩ =>
⟨x1 + x2, I.add_mem hx1i hx2i, hxy1 ▸ hxy2 ▸ map_add f _ _⟩)
fun c _ _ ⟨x, hxi, hxy⟩ =>
let ⟨d, hdc⟩ := hf c
⟨d * x, I.mul_mem_left _ hxi, hdc ▸ hxy ▸ map_mul f _ _⟩
theorem mem_map_iff_of_surjective {I : Ideal R} {y} : y ∈ map f I ↔ ∃ x, x ∈ I ∧ f x = y :=
⟨fun h => (Set.mem_image _ _ _).2 (mem_image_of_mem_map_of_surjective f hf h), fun ⟨_, hx⟩ =>
hx.right ▸ mem_map_of_mem f hx.left⟩
theorem le_map_of_comap_le_of_surjective : comap f K ≤ I → K ≤ map f I := fun h =>
map_comap_of_surjective f hf K ▸ map_mono h
end
theorem map_comap_eq_self_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
(I : Ideal S) : map e (comap e I) = I :=
I.map_comap_of_surjective e (EquivLike.surjective e)
theorem map_eq_submodule_map (f : R →+* S) [h : RingHomSurjective f] (I : Ideal R) :
I.map f = Submodule.map f.toSemilinearMap I :=
Submodule.ext fun _ => mem_map_iff_of_surjective f h.1
instance (priority := low) (f : R →+* S) [RingHomSurjective f] (I : Ideal R) [I.IsTwoSided] :
(I.map f).IsTwoSided where
mul_mem_of_left b ha := by
rw [map_eq_submodule_map] at ha ⊢
obtain ⟨a, ha, rfl⟩ := ha
obtain ⟨b, rfl⟩ := f.surjective b
rw [RingHom.coe_toSemilinearMap, ← map_mul]
exact ⟨_, I.mul_mem_right _ ha, rfl⟩
open Function in
theorem IsMaximal.comap_piEvalRingHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
{i : ι} {I : Ideal (R i)} (h : I.IsMaximal) : (I.comap <| Pi.evalRingHom R i).IsMaximal := by
refine isMaximal_iff.mpr ⟨I.ne_top_iff_one.mp h.ne_top, fun J x le hxI hxJ ↦ ?_⟩
have ⟨r, y, hy, eq⟩ := h.exists_inv hxI
classical
convert J.add_mem (J.mul_mem_left (update 0 i r) hxJ)
(b := update 1 i y) (le <| by apply update_self i y 1 ▸ hy)
ext j
obtain rfl | ne := eq_or_ne j i
· simpa [eq_comm] using eq
· simp [update_of_ne ne]
theorem comap_le_comap_iff_of_surjective (hf : Function.Surjective f) (I J : Ideal S) :
comap f I ≤ comap f J ↔ I ≤ J :=
⟨fun h => (map_comap_of_surjective f hf I).symm.le.trans (map_le_of_le_comap h), fun h =>
le_comap_of_map_le ((map_comap_of_surjective f hf I).le.trans h)⟩
/-- The map on ideals induced by a surjective map preserves inclusion. -/
def orderEmbeddingOfSurjective (hf : Function.Surjective f) : Ideal S ↪o Ideal R where
toFun := comap f
inj' _ _ eq := SetLike.ext' (Set.preimage_injective.mpr hf <| SetLike.ext'_iff.mp eq)
map_rel_iff' := comap_le_comap_iff_of_surjective _ hf ..
theorem map_eq_top_or_isMaximal_of_surjective (hf : Function.Surjective f) {I : Ideal R}
(H : IsMaximal I) : map f I = ⊤ ∨ IsMaximal (map f I) :=
or_iff_not_imp_left.2 fun ne_top ↦ ⟨⟨ne_top, fun _J hJ ↦ comap_injective_of_surjective f hf <|
H.1.2 _ (le_comap_map.trans_lt <| (orderEmbeddingOfSurjective f hf).strictMono hJ)⟩⟩
end Surjective
section Injective
theorem comap_bot_le_of_injective (hf : Function.Injective f) : comap f ⊥ ≤ I := by
refine le_trans (fun x hx => ?_) bot_le
rw [mem_comap, Submodule.mem_bot, ← map_zero f] at hx
exact Eq.symm (hf hx) ▸ Submodule.zero_mem ⊥
theorem comap_bot_of_injective (hf : Function.Injective f) : Ideal.comap f ⊥ = ⊥ :=
le_bot_iff.mp (Ideal.comap_bot_le_of_injective f hf)
end Injective
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm (map f I) = I`. -/
@[simp]
theorem map_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.map (f : R →+* S)).map (f.symm : S →+* R) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, map_map,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, map_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`,
then `comap f (comap f.symm I) = I`. -/
@[simp]
theorem comap_of_equiv {I : Ideal R} (f : R ≃+* S) :
(I.comap (f.symm : S →+* R)).comap (f : R →+* S) = I := by
rw [← RingEquiv.toRingHom_eq_coe, ← RingEquiv.toRingHom_eq_coe, comap_comap,
RingEquiv.toRingHom_eq_coe, RingEquiv.toRingHom_eq_coe, RingEquiv.symm_comp, comap_id]
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f I = comap f.symm I`. -/
theorem map_comap_of_equiv {I : Ideal R} (f : R ≃+* S) : I.map (f : R →+* S) = I.comap f.symm :=
le_antisymm (Ideal.map_le_comap_of_inverse _ _ _ (Equiv.left_inv' _))
(Ideal.comap_le_map_of_inverse _ _ _ (Equiv.right_inv' _))
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `comap f.symm I = map f I`. -/
@[simp]
theorem comap_symm {I : Ideal R} (f : R ≃+* S) : I.comap f.symm = I.map f :=
(map_comap_of_equiv f).symm
/-- If `f : R ≃+* S` is a ring isomorphism and `I : Ideal R`, then `map f.symm I = comap f I`. -/
@[simp]
theorem map_symm {I : Ideal S} (f : R ≃+* S) : I.map f.symm = I.comap f :=
map_comap_of_equiv (RingEquiv.symm f)
@[simp]
theorem symm_apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {y : S} :
f.symm y ∈ I ↔ y ∈ I.map f := by
rw [← comap_symm, mem_comap]
@[simp]
theorem apply_mem_of_equiv_iff {I : Ideal R} {f : R ≃+* S} {x : R} :
f x ∈ I.map f ↔ x ∈ I := by
rw [← comap_symm, Ideal.mem_comap, f.symm_apply_apply]
theorem mem_map_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{I : Ideal R} (y : S) : y ∈ map e I ↔ ∃ x ∈ I, e x = y := by
constructor
· intro h
simp_rw [show map e I = _ from map_comap_of_equiv (e : R ≃+* S)] at h
exact ⟨(e : R ≃+* S).symm y, h, (e : R ≃+* S).apply_symm_apply y⟩
· rintro ⟨x, hx, rfl⟩
exact mem_map_of_mem e hx
section Bijective
variable (hf : Function.Bijective f) {I : Ideal R} {K : Ideal S}
include hf
/-- Special case of the correspondence theorem for isomorphic rings -/
def relIsoOfBijective : Ideal S ≃o Ideal R where
toFun := comap f
invFun := map f
left_inv := map_comap_of_surjective _ hf.2
right_inv J :=
le_antisymm
(fun _ h ↦ have ⟨y, hy, eq⟩ := (mem_map_iff_of_surjective _ hf.2).mp h; hf.1 eq ▸ hy)
le_comap_map
map_rel_iff' {_ _} := by
refine ⟨fun h ↦ ?_, comap_mono⟩
have := map_mono (f := f) h
simpa only [Equiv.coe_fn_mk, map_comap_of_surjective f hf.2] using this
theorem comap_le_iff_le_map : comap f K ≤ I ↔ K ≤ map f I :=
⟨fun h => le_map_of_comap_le_of_surjective f hf.right h, fun h =>
(relIsoOfBijective f hf).right_inv I ▸ comap_mono h⟩
lemma comap_map_of_bijective : (I.map f).comap f = I :=
le_antisymm ((comap_le_iff_le_map f hf).mpr fun _ ↦ id) le_comap_map
theorem isMaximal_map_iff_of_bijective : IsMaximal (map f I) ↔ IsMaximal I := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).symm.isCoatom_iff _
theorem isMaximal_comap_iff_of_bijective : IsMaximal (comap f K) ↔ IsMaximal K := by
simpa only [isMaximal_def] using (relIsoOfBijective _ hf).isCoatom_iff _
alias ⟨_, IsMaximal.map_bijective⟩ := isMaximal_map_iff_of_bijective
alias ⟨_, IsMaximal.comap_bijective⟩ := isMaximal_comap_iff_of_bijective
/-- A ring isomorphism sends a maximal ideal to a maximal ideal. -/
instance map_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal R} [hp : p.IsMaximal] : (map e p).IsMaximal :=
hp.map_bijective e (EquivLike.bijective e)
/-- The pullback of a maximal ideal under a ring isomorphism is a maximal ideal. -/
instance comap_isMaximal_of_equiv {E : Type*} [EquivLike E R S] [RingEquivClass E R S] (e : E)
{p : Ideal S} [hp : p.IsMaximal] : (comap e p).IsMaximal :=
hp.comap_bijective e (EquivLike.bijective e)
theorem isMaximal_iff_of_bijective : (⊥ : Ideal R).IsMaximal ↔ (⊥ : Ideal S).IsMaximal :=
⟨fun h ↦ map_bot (f := f) ▸ h.map_bijective f hf, fun h ↦ have e := RingEquiv.ofBijective f hf
map_bot (f := e.symm) ▸ h.map_bijective _ e.symm.bijective⟩
end Bijective
end Semiring
section Ring
variable {F : Type*} [Ring R] [Ring S]
variable [FunLike F R S] [RingHomClass F R S] (f : F) {I : Ideal R}
section Surjective
theorem comap_map_of_surjective (hf : Function.Surjective f) (I : Ideal R) :
comap f (map f I) = I ⊔ comap f ⊥ :=
le_antisymm
(fun r h =>
let ⟨s, hsi, hfsr⟩ := mem_image_of_mem_map_of_surjective f hf h
Submodule.mem_sup.2
⟨s, hsi, r - s, (Submodule.mem_bot S).2 <| by rw [map_sub, hfsr, sub_self],
add_sub_cancel s r⟩)
(sup_le (map_le_iff_le_comap.1 le_rfl) (comap_mono bot_le))
/-- Correspondence theorem -/
def relIsoOfSurjective (hf : Function.Surjective f) :
Ideal S ≃o { p : Ideal R // comap f ⊥ ≤ p } where
toFun J := ⟨comap f J, comap_mono bot_le⟩
invFun 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_rfl I.2) le_sup_left
map_rel_iff' {I1 I2} :=
⟨fun H => map_comap_of_surjective f hf I1 ▸ map_comap_of_surjective f hf I2 ▸ map_mono H,
comap_mono⟩
-- May not hold if `R` is a semiring: consider `ℕ →+* ZMod 2`.
theorem comap_isMaximal_of_surjective (hf : Function.Surjective f) {K : Ideal S} [H : IsMaximal K] :
IsMaximal (comap f K) := by
refine ⟨⟨comap_ne_top _ H.1.1, fun J hJ => ?_⟩⟩
suffices map f J = ⊤ by
have := congr_arg (comap f) this
rw [comap_top, comap_map_of_surjective _ hf, eq_top_iff] at this
rw [eq_top_iff]
exact le_trans this (sup_le (le_of_eq rfl) (le_trans (comap_mono bot_le) (le_of_lt hJ)))
refine
H.1.2 (map f J)
(lt_of_le_of_ne (le_map_of_comap_le_of_surjective _ hf (le_of_lt hJ)) fun h =>
ne_of_lt hJ (_root_.trans (congr_arg (comap f) h) ?_))
rw [comap_map_of_surjective _ hf, sup_eq_left]
exact le_trans (comap_mono bot_le) (le_of_lt hJ)
end Surjective
end Ring
section CommRing
variable {F : Type*} [CommSemiring R] [CommSemiring S]
variable [FunLike F R S] [rc : RingHomClass F R S]
variable (f : F)
variable (I J : Ideal R) (K L : Ideal S)
protected theorem map_mul {R} [Semiring R] [FunLike F R S] [RingHomClass F R S]
(f : F) (I J : Ideal R) :
map f (I * J) = map f I * map f J :=
le_antisymm
(map_le_iff_le_comap.2 <|
mul_le.2 fun r hri s hsj =>
show (f (r * s)) ∈ map f I * map f J by
rw [map_mul]; exact mul_mem_mul (mem_map_of_mem f hri) (mem_map_of_mem f hsj))
(span_mul_span (↑f '' ↑I) (↑f '' ↑J) ▸ (span_le.2 <|
Set.iUnion₂_subset fun _ ⟨r, hri, hfri⟩ =>
Set.iUnion₂_subset fun _ ⟨s, hsj, hfsj⟩ =>
Set.singleton_subset_iff.2 <|
hfri ▸ hfsj ▸ by rw [← map_mul]; exact mem_map_of_mem f (mul_mem_mul hri hsj)))
/-- The pushforward `Ideal.map` as a (semi)ring homomorphism. -/
@[simps]
def mapHom : Ideal R →+* Ideal S where
toFun := map f
map_mul' := Ideal.map_mul f
map_one' := by simp only [one_eq_top, Ideal.map_top f]
map_add' I J := Ideal.map_sup f I J
map_zero' := Ideal.map_bot
protected theorem map_pow (n : ℕ) : map f (I ^ n) = map f I ^ n :=
map_pow (mapHom f) I n
theorem comap_radical : comap f (radical K) = radical (comap f K) := by
ext
simp [radical]
variable {K}
theorem IsRadical.comap (hK : K.IsRadical) : (comap f K).IsRadical := by
rw [← hK.radical, comap_radical]
apply radical_isRadical
variable {I J L}
theorem map_radical_le : map f (radical I) ≤ radical (map f I) :=
map_le_iff_le_comap.2 fun r ⟨n, hrni⟩ => ⟨n, map_pow f r n ▸ mem_map_of_mem f hrni⟩
theorem le_comap_mul : comap f K * comap f L ≤ comap f (K * L) :=
map_le_iff_le_comap.1 <|
(Ideal.map_mul f (comap f K) (comap f L)).symm ▸
mul_mono (map_le_iff_le_comap.2 <| le_rfl) (map_le_iff_le_comap.2 <| le_rfl)
theorem le_comap_pow (n : ℕ) : K.comap f ^ n ≤ (K ^ n).comap f := by
induction' n with n n_ih
· rw [pow_zero, pow_zero, Ideal.one_eq_top, Ideal.one_eq_top]
exact rfl.le
· rw [pow_succ, pow_succ]
exact (Ideal.mul_mono_left n_ih).trans (Ideal.le_comap_mul f)
lemma disjoint_map_primeCompl_iff_comap_le {S : Type*} [Semiring S] {f : R →+* S}
{p : Ideal R} {I : Ideal S} [p.IsPrime] :
Disjoint (I : Set S) (p.primeCompl.map f) ↔ I.comap f ≤ p :=
(@Set.disjoint_image_right _ _ f p.primeCompl I).trans disjoint_compl_right_iff
/-- For a prime ideal `p` of `R`, `p` extended to `S` and
restricted back to `R` is `p` if and only if `p` is the restriction of a prime in `S`. -/
lemma comap_map_eq_self_iff_of_isPrime {S : Type*} [CommSemiring S] {f : R →+* S}
(p : Ideal R) [p.IsPrime] :
(p.map f).comap f = p ↔ (∃ (q : Ideal S), q.IsPrime ∧ q.comap f = p) := by
refine ⟨fun hp ↦ ?_, ?_⟩
· obtain ⟨q, hq₁, hq₂, hq₃⟩ := Ideal.exists_le_prime_disjoint _ _
(disjoint_map_primeCompl_iff_comap_le.mpr hp.le)
exact ⟨q, hq₁, le_antisymm (disjoint_map_primeCompl_iff_comap_le.mp hq₃)
(map_le_iff_le_comap.mp hq₂)⟩
· rintro ⟨q, hq, rfl⟩
simp
end CommRing
end MapAndComap
end Ideal
namespace RingHom
variable {R : Type u} {S : Type v} {T : Type w}
section Semiring
variable {F : Type*} {G : Type*} [Semiring R] [Semiring S] [Semiring T]
variable [FunLike F R S] [rcf : RingHomClass F R S] [FunLike G T S] [rcg : RingHomClass G T S]
variable (f : F) (g : G)
/-- Kernel of a ring homomorphism as an ideal of the domain. -/
def ker : Ideal R :=
Ideal.comap f ⊥
instance (priority := low) : (ker f).IsTwoSided := inferInstanceAs (Ideal.comap f ⊥).IsTwoSided
variable {f} in
/-- An element is in the kernel if and only if it maps to zero. -/
@[simp] theorem mem_ker {r} : r ∈ ker f ↔ f r = 0 := by rw [ker, Ideal.mem_comap, Submodule.mem_bot]
theorem ker_eq : (ker f : Set R) = Set.preimage f {0} :=
rfl
theorem ker_eq_comap_bot (f : F) : ker f = Ideal.comap f ⊥ :=
rfl
theorem comap_ker (f : S →+* R) (g : T →+* S) : (ker f).comap g = ker (f.comp g) := by
rw [RingHom.ker_eq_comap_bot, Ideal.comap_comap, RingHom.ker_eq_comap_bot]
/-- If the target is not the zero ring, then one is not in the kernel. -/
theorem one_notMem_ker [Nontrivial S] (f : F) : (1 : R) ∉ ker f := by
rw [mem_ker, map_one]
exact one_ne_zero
@[deprecated (since := "2025-05-23")] alias not_one_mem_ker := one_notMem_ker
theorem ker_ne_top [Nontrivial S] (f : F) : ker f ≠ ⊤ :=
(Ideal.ne_top_iff_one _).mpr <| one_notMem_ker f
lemma _root_.Pi.ker_ringHom {ι : Type*} {R : ι → Type*} [∀ i, Semiring (R i)]
(φ : ∀ i, S →+* R i) : ker (Pi.ringHom φ) = ⨅ i, ker (φ i) := by
ext x
simp [mem_ker, Ideal.mem_iInf, funext_iff]
@[simp]
theorem ker_rangeSRestrict (f : R →+* S) : ker f.rangeSRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
@[simp]
theorem ker_coe_equiv (f : R ≃+* S) : ker (f : R →+* S) = ⊥ := by
ext; simp
theorem ker_coe_toRingHom : ker (f : R →+* S) = ker f := rfl
@[simp]
theorem ker_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S] (f : F') :
ker f = ⊥ := by
ext; simp
lemma ker_equiv_comp (f : R →+* S) (e : S ≃+* T) :
ker (e.toRingHom.comp f) = RingHom.ker f := by
rw [← RingHom.comap_ker, RingEquiv.toRingHom_eq_coe, RingHom.ker_coe_equiv, RingHom.ker]
end Semiring
section Ring
variable {F : Type*} [Ring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F)
theorem injective_iff_ker_eq_bot : Function.Injective f ↔ ker f = ⊥ := by
rw [SetLike.ext'_iff, ker_eq, Set.ext_iff]
exact injective_iff_map_eq_zero' f
theorem ker_eq_bot_iff_eq_zero : ker f = ⊥ ↔ ∀ x, f x = 0 → x = 0 := by
rw [← injective_iff_map_eq_zero f, injective_iff_ker_eq_bot]
lemma ker_comp_of_injective [Semiring T] (g : T →+* R) {f : R →+* S} (hf : Function.Injective f) :
ker (f.comp g) = RingHom.ker g := by
rw [← RingHom.comap_ker, (injective_iff_ker_eq_bot f).mp hf, RingHom.ker]
/-- Synonym for `RingHom.ker_coe_equiv`, but given an algebra equivalence. -/
@[simp] theorem _root_.AlgHom.ker_coe_equiv {R A B : Type*} [CommSemiring R] [Semiring A]
[Semiring B] [Algebra R A] [Algebra R B] (e : A ≃ₐ[R] B) :
RingHom.ker (e : A →+* B) = ⊥ :=
RingHom.ker_coe_equiv (e.toRingEquiv)
end Ring
section RingRing
variable {F : Type*} [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S] (f : F)
theorem sub_mem_ker_iff {x y} : x - y ∈ ker f ↔ f x = f y := by rw [mem_ker, map_sub, sub_eq_zero]
@[simp]
theorem ker_rangeRestrict (f : R →+* S) : ker f.rangeRestrict = ker f :=
Ideal.ext fun _ ↦ Subtype.ext_iff
end RingRing
/-- The kernel of a homomorphism to a domain is a prime ideal. -/
theorem ker_isPrime {F : Type*} [Semiring R] [Semiring S] [IsDomain S]
[FunLike F R S] [RingHomClass F R S] (f : F) :
(ker f).IsPrime :=
have := Ideal.bot_prime (α := S)
inferInstanceAs (Ideal.comap f ⊥).IsPrime
/-- The kernel of a homomorphism to a field is a maximal ideal. -/
theorem ker_isMaximal_of_surjective {R K F : Type*} [Ring R] [DivisionRing K]
[FunLike F R K] [RingHomClass F R K] (f : F)
(hf : Function.Surjective f) : (ker f).IsMaximal :=
have := Ideal.bot_isMaximal (K := K)
Ideal.comap_isMaximal_of_surjective _ hf
end RingHom
section annihilator
section Semiring
variable {R M M' : Type*}
variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
variable (R M) in
/-- `Module.annihilator R M` is the ideal of all elements `r : R` such that `r • M = 0`. -/
def Module.annihilator : Ideal R := RingHom.ker (Module.toAddMonoidEnd R M)
theorem Module.mem_annihilator {r} : r ∈ Module.annihilator R M ↔ ∀ m : M, r • m = 0 :=
⟨fun h ↦ (congr($h ·)), (AddMonoidHom.ext ·)⟩
instance (priority := low) : (Module.annihilator R M).IsTwoSided :=
inferInstanceAs (RingHom.ker _).IsTwoSided
theorem LinearMap.annihilator_le_of_injective (f : M →ₗ[R] M') (hf : Function.Injective f) :
Module.annihilator R M' ≤ Module.annihilator R M := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢; exact fun m ↦ hf (by rw [map_smul, h, f.map_zero])
theorem LinearMap.annihilator_le_of_surjective (f : M →ₗ[R] M')
(hf : Function.Surjective f) : Module.annihilator R M ≤ Module.annihilator R M' := fun x h ↦ by
rw [Module.mem_annihilator] at h ⊢
intro m; obtain ⟨m, rfl⟩ := hf m
rw [← map_smul, h, f.map_zero]
theorem LinearEquiv.annihilator_eq (e : M ≃ₗ[R] M') :
Module.annihilator R M = Module.annihilator R M' :=
(e.annihilator_le_of_surjective e.surjective).antisymm (e.annihilator_le_of_injective e.injective)
theorem Module.comap_annihilator {R₀} [CommSemiring R₀] [Module R₀ M]
[Algebra R₀ R] [IsScalarTower R₀ R M] :
(Module.annihilator R M).comap (algebraMap R₀ R) = Module.annihilator R₀ M := by
ext x
simp [mem_annihilator]
lemma Module.annihilator_eq_bot {R M} [Ring R] [AddCommGroup M] [Module R M] :
Module.annihilator R M = ⊥ ↔ FaithfulSMul R M := by
rw [← le_bot_iff]
refine ⟨fun H ↦ ⟨fun {r s} H' ↦ ?_⟩, fun ⟨H⟩ {a} ha ↦ ?_⟩
· rw [← sub_eq_zero]
exact H (Module.mem_annihilator (r := r - s).mpr
(by simp only [sub_smul, H', sub_self, implies_true]))
· exact @H a 0 (by simp [Module.mem_annihilator.mp ha])
theorem Module.annihilator_eq_top_iff : annihilator R M = ⊤ ↔ Subsingleton M :=
⟨fun h ↦ ⟨fun m m' ↦ by
rw [← one_smul R m, ← one_smul R m']
simp_rw [mem_annihilator.mp (h ▸ Submodule.mem_top)]⟩,
fun _ ↦ top_le_iff.mp fun _ _ ↦ mem_annihilator.mpr fun _ ↦ Subsingleton.elim _ _⟩
theorem Module.annihilator_prod : annihilator R (M × M') = annihilator R M ⊓ annihilator R M' := by
ext
simp_rw [Ideal.mem_inf, mem_annihilator,
Prod.forall, Prod.smul_mk, Prod.mk_eq_zero, forall_and_left, ← forall_and_right]
theorem Module.annihilator_finsupp {ι : Type*} [Nonempty ι] :
annihilator R (ι →₀ M) = annihilator R M := by
ext r; simp_rw [mem_annihilator]
constructor <;> intro h
· refine Nonempty.elim ‹_› fun i : ι ↦ ?_
simpa using fun m ↦ congr($(h (Finsupp.single i m)) i)
· intro m; ext i; exact h _
section
variable {ι : Type*} {M : ι → Type*} [∀ i, AddCommMonoid (M i)] [∀ i, Module R (M i)]
theorem Module.annihilator_dfinsupp : annihilator R (Π₀ i, M i) = ⨅ i, annihilator R (M i) := by
ext r; simp only [mem_annihilator, Ideal.mem_iInf]
constructor <;> intro h
· intro i m
classical simpa using DFunLike.congr_fun (h (DFinsupp.single i m)) i
· intro m; ext i; exact h i _
theorem Module.annihilator_pi : annihilator R (Π i, M i) = ⨅ i, annihilator R (M i) := by
ext r; simp only [mem_annihilator, Ideal.mem_iInf]
constructor <;> intro h
· intro i m
classical simpa using congr_fun (h (Pi.single i m)) i
· intro m; ext i; exact h i _
end
namespace Submodule
/-- `N.annihilator` is the ideal of all elements `r : R` such that `r • N = 0`. -/
abbrev annihilator (N : Submodule R M) : Ideal R :=
Module.annihilator R N
theorem annihilator_top : (⊤ : Submodule R M).annihilator = Module.annihilator R M :=
topEquiv.annihilator_eq
variable {I J : Ideal R} {N P : Submodule R M}
theorem mem_annihilator {r} : r ∈ N.annihilator ↔ ∀ n ∈ N, r • n = (0 : M) := by
simp_rw [annihilator, Module.mem_annihilator, Subtype.forall, Subtype.ext_iff]; rfl
theorem annihilator_bot : (⊥ : Submodule R M).annihilator = ⊤ :=
top_le_iff.mp fun _ _ ↦ mem_annihilator.mpr fun _ ↦ by rintro rfl; rw [smul_zero]
theorem annihilator_eq_top_iff : N.annihilator = ⊤ ↔ N = ⊥ := by
rw [annihilator, Module.annihilator_eq_top_iff, Submodule.subsingleton_iff_eq_bot]
theorem annihilator_mono (h : N ≤ P) : P.annihilator ≤ N.annihilator := fun _ hrp =>
mem_annihilator.2 fun n hn => mem_annihilator.1 hrp n <| h hn
theorem annihilator_iSup (ι : Sort w) (f : ι → Submodule R M) :
annihilator (⨆ i, f i) = ⨅ i, annihilator (f i) :=
le_antisymm (le_iInf fun _ => annihilator_mono <| le_iSup _ _) fun r H =>
mem_annihilator.2 fun n hn ↦ iSup_induction f (motive := (r • · = 0)) hn
(fun i ↦ mem_annihilator.1 <| (mem_iInf _).mp H i) (smul_zero _)
fun m₁ m₂ h₁ h₂ ↦ by simp_rw [smul_add, h₁, h₂, add_zero]
theorem le_annihilator_iff {N : Submodule R M} {I : Ideal R} : I ≤ annihilator N ↔ I • N = ⊥ := by
simp_rw [← le_bot_iff, smul_le, SetLike.le_def, mem_annihilator]; rfl
@[simp]
theorem annihilator_smul (N : Submodule R M) : annihilator N • N = ⊥ :=
eq_bot_iff.2 (smul_le.2 fun _ => mem_annihilator.1)
@[simp]
theorem annihilator_mul (I : Ideal R) : annihilator I * I = ⊥ :=
annihilator_smul I
end Submodule
end Semiring
namespace Submodule
variable {R M : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M] {N : Submodule R M}
theorem mem_annihilator' {r} : r ∈ N.annihilator ↔ N ≤ comap (r • (LinearMap.id : M →ₗ[R] M)) ⊥ :=
mem_annihilator.trans ⟨fun H n hn => (mem_bot R).2 <| H n hn, fun H _ hn => (mem_bot R).1 <| H hn⟩
theorem mem_annihilator_span (s : Set M) (r : R) :
r ∈ (Submodule.span R s).annihilator ↔ ∀ n : s, r • (n : M) = 0 := by
rw [Submodule.mem_annihilator]
constructor
· intro h n
exact h _ (Submodule.subset_span n.prop)
· intro h n hn
refine Submodule.span_induction ?_ ?_ ?_ ?_ hn
· intro x hx
exact h ⟨x, hx⟩
· exact smul_zero _
· intro x y _ _ hx hy
rw [smul_add, hx, hy, zero_add]
· intro a x _ hx
rw [smul_comm, hx, smul_zero]
theorem mem_annihilator_span_singleton (g : M) (r : R) :
r ∈ (Submodule.span R ({g} : Set M)).annihilator ↔ r • g = 0 := by simp [mem_annihilator_span]
open LinearMap in
theorem annihilator_span (s : Set M) :
(Submodule.span R s).annihilator = ⨅ g : s, ker (toSpanSingleton R M g.1) := by
ext; simp [mem_annihilator_span]
open LinearMap in
theorem annihilator_span_singleton (g : M) :
(Submodule.span R {g}).annihilator = ker (toSpanSingleton R M g) := by
simp [annihilator_span]
@[simp]
theorem mul_annihilator (I : Ideal R) : I * annihilator I = ⊥ := by rw [mul_comm, annihilator_mul]
end Submodule
end annihilator
namespace Ideal
variable {R : Type*} {S : Type*} {F : Type*}
section Semiring
variable [Semiring R] [Semiring S] [FunLike F R S] [rc : RingHomClass F R S]
theorem map_eq_bot_iff_le_ker {I : Ideal R} (f : F) : I.map f = ⊥ ↔ I ≤ RingHom.ker f := by
rw [RingHom.ker, eq_bot_iff, map_le_iff_le_comap]
theorem ker_le_comap {K : Ideal S} (f : F) : RingHom.ker f ≤ comap f K := fun _ hx =>
mem_comap.2 (RingHom.mem_ker.1 hx ▸ K.zero_mem)
/-- A ring isomorphism sends a prime ideal to a prime ideal. -/
instance map_isPrime_of_equiv {F' : Type*} [EquivLike F' R S] [RingEquivClass F' R S]
(f : F') {I : Ideal R} [IsPrime I] : IsPrime (map f I) := by
have h : I.map f = I.map ((f : R ≃+* S) : R →+* S) := rfl
rw [h, map_comap_of_equiv (f : R ≃+* S)]
exact Ideal.IsPrime.comap (RingEquiv.symm (f : R ≃+* S))
theorem map_eq_bot_iff_of_injective {I : Ideal R} {f : F} (hf : Function.Injective f) :
I.map f = ⊥ ↔ I = ⊥ := by
simp [map, span_eq_bot, ← map_zero f, -map_zero, hf.eq_iff, I.eq_bot_iff]
end Semiring
section Ring
variable [Ring R] [Ring S] [FunLike F R S] [rc : RingHomClass F R S]
lemma comap_map_of_surjective' (f : F) (hf : Function.Surjective f) (I : Ideal R) :
(I.map f).comap f = I ⊔ RingHom.ker f :=
comap_map_of_surjective f hf I
theorem map_sInf {A : Set (Ideal R)} {f : F} (hf : Function.Surjective f) :
(∀ J ∈ A, RingHom.ker f ≤ J) → map f (sInf A) = sInf (map f '' A) := by
refine fun h => le_antisymm (le_sInf ?_) ?_
· intro j hj y hy
obtain ⟨x, hx⟩ := (mem_map_iff_of_surjective f hf).1 hy
obtain ⟨J, hJ⟩ := (Set.mem_image _ _ _).mp hj
rw [← hJ.right, ← hx.right]
exact mem_map_of_mem f (sInf_le_of_le hJ.left (le_of_eq rfl) hx.left)
· intro y hy
obtain ⟨x, hx⟩ := hf y
refine hx ▸ mem_map_of_mem f ?_
have : ∀ I ∈ A, y ∈ map f I := by simpa using hy
rw [Submodule.mem_sInf]
intro J hJ
rcases (mem_map_iff_of_surjective f hf).1 (this J hJ) with ⟨x', hx', rfl⟩
have : x - x' ∈ J := by
apply h J hJ
rw [RingHom.mem_ker, map_sub, hx, sub_self]
simpa only [sub_add_cancel] using J.add_mem this hx'
theorem map_isPrime_of_surjective {f : F} (hf : Function.Surjective f) {I : Ideal R} [H : IsPrime I]
(hk : RingHom.ker f ≤ I) : IsPrime (map f I) := by
refine ⟨fun h => H.ne_top (eq_top_iff.2 ?_), fun {x y} => ?_⟩
· replace h := congr_arg (comap f) h
rw [comap_map_of_surjective _ hf, comap_top] at h
exact h ▸ sup_le (le_of_eq rfl) hk
· refine fun hxy => (hf x).recOn fun a ha => (hf y).recOn fun b hb => ?_
rw [← ha, ← hb, ← map_mul f, mem_map_iff_of_surjective _ hf] at hxy
rcases hxy with ⟨c, hc, hc'⟩
rw [← sub_eq_zero, ← map_sub] at hc'
have : a * b ∈ I := by
convert I.sub_mem hc (hk (hc' : c - a * b ∈ RingHom.ker f)) using 1
abel
exact
(H.mem_or_mem this).imp (fun h => ha ▸ mem_map_of_mem f h) fun h => hb ▸ mem_map_of_mem f h
end Ring
section CommRing
variable [CommRing R] [CommRing S]
theorem map_ne_bot_of_ne_bot {S : Type*} [Ring S] [Nontrivial S] [Algebra R S]
[NoZeroSMulDivisors R S] {I : Ideal R} (h : I ≠ ⊥) : map (algebraMap R S) I ≠ ⊥ :=
(map_eq_bot_iff_of_injective (FaithfulSMul.algebraMap_injective R S)).mp.mt h
theorem map_eq_iff_sup_ker_eq_of_surjective {I J : Ideal R} (f : R →+* S)
(hf : Function.Surjective f) : map f I = map f J ↔ I ⊔ RingHom.ker f = J ⊔ RingHom.ker f := by
rw [← (comap_injective_of_surjective f hf).eq_iff, comap_map_of_surjective f hf,
comap_map_of_surjective f hf, RingHom.ker_eq_comap_bot]
theorem map_radical_of_surjective {f : R →+* S} (hf : Function.Surjective f) {I : Ideal R}
(h : RingHom.ker f ≤ I) : map f I.radical = (map f I).radical := by
rw [radical_eq_sInf, radical_eq_sInf]
have : ∀ J ∈ {J : Ideal R | I ≤ J ∧ J.IsPrime}, RingHom.ker f ≤ J := fun J hJ => h.trans hJ.left
convert map_sInf hf this
refine funext fun j => propext ⟨?_, ?_⟩
· rintro ⟨hj, hj'⟩
haveI : j.IsPrime := hj'
exact
⟨comap f j, ⟨⟨map_le_iff_le_comap.1 hj, comap_isPrime f j⟩, map_comap_of_surjective f hf j⟩⟩
· rintro ⟨J, ⟨hJ, hJ'⟩⟩
haveI : J.IsPrime := hJ.right
exact ⟨hJ' ▸ map_mono hJ.left, hJ' ▸ map_isPrime_of_surjective hf (le_trans h hJ.left)⟩
end CommRing
end Ideal
namespace RingHom
variable {A B C : Type*} [Ring A] [Ring B] [Ring C]
variable (f : A →+* B) (f_inv : B → A)
/-- Auxiliary definition used to define `liftOfRightInverse` -/
def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) :
B →+* C :=
{ AddMonoidHom.liftOfRightInverse f.toAddMonoidHom f_inv hf ⟨g.toAddMonoidHom, hg⟩ with
toFun := fun b => g (f_inv b)
map_one' := by
rw [← map_one g, ← sub_eq_zero, ← map_sub g, ← mem_ker]
apply hg
rw [mem_ker, map_sub f, sub_eq_zero, map_one f]
exact hf 1
map_mul' := by
intro x y
rw [← map_mul g, ← sub_eq_zero, ← map_sub g, ← mem_ker]
apply hg
rw [mem_ker, map_sub f, sub_eq_zero, map_mul f]
simp only [hf _] }
@[simp]
theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) (a : A) :
(f.liftOfRightInverseAux f_inv hf g hg) (f a) = g a :=
f.toAddMonoidHom.liftOfRightInverse_comp_apply f_inv hf ⟨g.toAddMonoidHom, hg⟩ a
/-- `liftOfRightInverse f hf g hg` is the unique ring homomorphism `φ`
* such that `φ.comp f = g` (`RingHom.liftOfRightInverse_comp`),
* where `f : A →+* B` has a right_inverse `f_inv` (`hf`),
* and `g : B →+* C` satisfies `hg : f.ker ≤ g.ker`.
See `RingHom.eq_liftOfRightInverse` for the uniqueness lemma.
```
A .
| \
f | \ g
| \
v \⌟
B ----> C
∃!φ
```
-/
def liftOfRightInverse (hf : Function.RightInverse f_inv f) :
{ g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) where
toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2
invFun φ := ⟨φ.comp f, fun x hx => mem_ker.mpr <| by simp [mem_ker.mp hx]⟩
left_inv g := by
ext
simp only [comp_apply, liftOfRightInverseAux_comp_apply]
right_inv φ := by
ext b
simp [liftOfRightInverseAux, hf b]
/-- A non-computable version of `RingHom.liftOfRightInverse` for when no computable right
inverse is available, that uses `Function.surjInv`. -/
@[simp]
noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) :
{ g : A →+* C // RingHom.ker f ≤ RingHom.ker g } ≃ (B →+* C) :=
f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf)
theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f)
(g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) (x : A) :
(f.liftOfRightInverse f_inv hf g) (f x) = g.1 x :=
f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x
theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f)
(g : { g : A →+* C // RingHom.ker f ≤ RingHom.ker g }) :
(f.liftOfRightInverse f_inv hf g).comp f = g :=
RingHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g
theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : A →+* C)
(hg : RingHom.ker f ≤ RingHom.ker g) (h : B →+* C) (hh : h.comp f = g) :
h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by
simp_rw [← hh]
exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm
end RingHom
namespace AlgHom
variable {R A B : Type*} [CommSemiring R] [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B] (f : A →ₐ[R] B)
lemma ker_coe : RingHom.ker f = RingHom.ker (f : A →+* B) := rfl
@[deprecated (since := "2025-02-24")] alias coe_ker := ker_coe
lemma coe_ideal_map (I : Ideal A) :
Ideal.map f I = Ideal.map (f : A →+* B) I := rfl
lemma comap_ker {C : Type*} [Semiring C] [Algebra R C] (f : B →ₐ[R] C) (g : A →ₐ[R] B) :
(RingHom.ker f).comap g = RingHom.ker (f.comp g) :=
RingHom.comap_ker f.toRingHom g.toRingHom
end AlgHom
namespace Algebra
variable {R : Type*} [CommSemiring R] (S : Type*) [Semiring S] [Algebra R S]
/-- The induced linear map from `I` to the span of `I` in an `R`-algebra `S`. -/
@[simps!]
def idealMap (I : Ideal R) : I →ₗ[R] I.map (algebraMap R S) :=
(Algebra.linearMap R S).restrict (q := (I.map (algebraMap R S)).restrictScalars R)
(fun _ ↦ Ideal.mem_map_of_mem _)
end Algebra
@[simp]
theorem FaithfulSMul.ker_algebraMap_eq_bot (R A : Type*) [CommSemiring R] [Semiring A]
[Algebra R A] [FaithfulSMul R A] : RingHom.ker (algebraMap R A) = ⊥ := by
ext; simp
section PrincipalIdeal
instance {R S : Type*} [Semiring R] [Semiring S] (f : R →+* S) (I : Ideal R) [I.IsPrincipal] :
(I.map f).IsPrincipal := by
obtain ⟨x, rfl⟩ := Submodule.IsPrincipal.principal I
exact ⟨f x, by
rw [← Ideal.span, ← Set.image_singleton, Ideal.map_span, Set.image_singleton,
Ideal.submodule_span_eq]⟩
end PrincipalIdeal
|
Topology.lean
|
/-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.Complex.UpperHalfPlane.MoebiusAction
import Mathlib.Analysis.Convex.Contractible
import Mathlib.Analysis.LocallyConvex.WithSeminorms
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Complex.ReImTopology
import Mathlib.Topology.Homotopy.Contractible
import Mathlib.Topology.PartialHomeomorph
/-!
# Topology on the upper half plane
In this file we introduce a `TopologicalSpace` structure on the upper half plane and provide
various instances.
-/
noncomputable section
open Complex Filter Function Set TopologicalSpace Topology
namespace UpperHalfPlane
instance : TopologicalSpace ℍ :=
instTopologicalSpaceSubtype
theorem isOpenEmbedding_coe : IsOpenEmbedding ((↑) : ℍ → ℂ) :=
IsOpen.isOpenEmbedding_subtypeVal <| isOpen_lt continuous_const Complex.continuous_im
theorem isEmbedding_coe : IsEmbedding ((↑) : ℍ → ℂ) :=
IsEmbedding.subtypeVal
theorem continuous_coe : Continuous ((↑) : ℍ → ℂ) :=
isEmbedding_coe.continuous
theorem continuous_re : Continuous re :=
Complex.continuous_re.comp continuous_coe
theorem continuous_im : Continuous im :=
Complex.continuous_im.comp continuous_coe
instance : SecondCountableTopology ℍ :=
TopologicalSpace.Subtype.secondCountableTopology _
instance : T3Space ℍ := Subtype.t3Space
instance : T4Space ℍ := inferInstance
instance : ContractibleSpace ℍ :=
(convex_halfSpace_im_gt 0).contractibleSpace ⟨I, one_pos.trans_eq I_im.symm⟩
instance : LocPathConnectedSpace ℍ := isOpenEmbedding_coe.locPathConnectedSpace
instance : NoncompactSpace ℍ := by
refine ⟨fun h => ?_⟩
have : IsCompact (Complex.im ⁻¹' Ioi 0) := isCompact_iff_isCompact_univ.2 h
replace := this.isClosed.closure_eq
rw [closure_preimage_im, closure_Ioi, Set.ext_iff] at this
exact absurd ((this 0).1 (@left_mem_Ici ℝ _ 0)) (@lt_irrefl ℝ _ 0)
instance : LocallyCompactSpace ℍ :=
isOpenEmbedding_coe.locallyCompactSpace
/-- Each element of `GL(2, ℝ)` defines a continuous map `ℍ → ℍ`. -/
instance instContinuousGLSMul : ContinuousConstSMul (GL (Fin 2) ℝ) ℍ where
continuous_const_smul g := by
simp_rw [continuous_induced_rng (f := UpperHalfPlane.coe), Function.comp_def,
UpperHalfPlane.coe_smul, UpperHalfPlane.σ]
refine .comp ?_ ?_
· split_ifs
exacts [continuous_id, continuous_conj]
· refine .div ?_ ?_ (fun x ↦ denom_ne_zero g x) <;>
exact (continuous_const.mul continuous_coe).add continuous_const
section strips
/-- The vertical strip of width `A` and height `B`, defined by elements whose real part has absolute
value less than or equal to `A` and imaginary part is at least `B`. -/
def verticalStrip (A B : ℝ) := {z : ℍ | |z.re| ≤ A ∧ B ≤ z.im}
theorem mem_verticalStrip_iff (A B : ℝ) (z : ℍ) : z ∈ verticalStrip A B ↔ |z.re| ≤ A ∧ B ≤ z.im :=
Iff.rfl
@[gcongr]
lemma verticalStrip_mono {A B A' B' : ℝ} (hA : A ≤ A') (hB : B' ≤ B) :
verticalStrip A B ⊆ verticalStrip A' B' := by
rintro z ⟨hzre, hzim⟩
exact ⟨hzre.trans hA, hB.trans hzim⟩
lemma verticalStrip_mono_left {A A'} (h : A ≤ A') (B) : verticalStrip A B ⊆ verticalStrip A' B :=
verticalStrip_mono h le_rfl
lemma verticalStrip_anti_right (A) {B B'} (h : B' ≤ B) : verticalStrip A B ⊆ verticalStrip A B' :=
verticalStrip_mono le_rfl h
lemma subset_verticalStrip_of_isCompact {K : Set ℍ} (hK : IsCompact K) :
∃ A B : ℝ, 0 < B ∧ K ⊆ verticalStrip A B := by
rcases K.eq_empty_or_nonempty with rfl | hne
· exact ⟨1, 1, Real.zero_lt_one, empty_subset _⟩
obtain ⟨u, _, hu⟩ := hK.exists_isMaxOn hne (_root_.continuous_abs.comp continuous_re).continuousOn
obtain ⟨v, _, hv⟩ := hK.exists_isMinOn hne continuous_im.continuousOn
exact ⟨|re u|, im v, v.im_pos, fun k hk ↦ ⟨isMaxOn_iff.mp hu _ hk, isMinOn_iff.mp hv _ hk⟩⟩
theorem ModularGroup_T_zpow_mem_verticalStrip (z : ℍ) {N : ℕ} (hn : 0 < N) :
∃ n : ℤ, ModularGroup.T ^ (N * n) • z ∈ verticalStrip N z.im := by
let n := Int.floor (z.re/N)
use -n
rw [modular_T_zpow_smul z (N * -n)]
refine ⟨?_, (by simp only [mul_neg, Int.cast_neg, Int.cast_mul, Int.cast_natCast, vadd_im,
le_refl])⟩
have h : (N * (-n : ℝ) +ᵥ z).re = -N * Int.floor (z.re / N) + z.re := by
simp only [n, mul_neg, vadd_re, neg_mul]
norm_cast at *
rw [h, add_comm]
simp only [neg_mul, Int.cast_neg, Int.cast_mul, Int.cast_natCast]
have hnn : (0 : ℝ) < (N : ℝ) := by norm_cast at *
have h2 : z.re + -(N * n) = z.re - n * N := by ring
rw [h2, abs_eq_self.2 (Int.sub_floor_div_mul_nonneg (z.re : ℝ) hnn)]
apply (Int.sub_floor_div_mul_lt (z.re : ℝ) hnn).le
end strips
section ofComplex
/-- A section `ℂ → ℍ` of the natural inclusion map, bundled as a `PartialHomeomorph`. -/
def ofComplex : PartialHomeomorph ℂ ℍ := (isOpenEmbedding_coe.toPartialHomeomorph _).symm
/-- Extend a function on `ℍ` arbitrarily to a function on all of `ℂ`. -/
scoped notation "↑ₕ" f => f ∘ ofComplex
@[simp]
lemma ofComplex_apply (z : ℍ) : ofComplex (z : ℂ) = z :=
IsOpenEmbedding.toPartialHomeomorph_left_inv ..
lemma ofComplex_apply_eq_ite (w : ℂ) :
ofComplex w = if hw : 0 < w.im then ⟨w, hw⟩ else Classical.choice inferInstance := by
split_ifs with hw
· exact ofComplex_apply ⟨w, hw⟩
· change (Function.invFunOn UpperHalfPlane.coe Set.univ w) = _
simp only [invFunOn, dite_eq_right_iff, mem_univ, true_and]
rintro ⟨a, rfl⟩
exact (a.prop.not_ge (by simpa using hw)).elim
lemma ofComplex_apply_of_im_pos {z : ℂ} (hz : 0 < z.im) :
ofComplex z = ⟨z, hz⟩ := by
simpa only [coe_mk_subtype] using ofComplex_apply ⟨z, hz⟩
lemma ofComplex_apply_of_im_nonpos {w : ℂ} (hw : w.im ≤ 0) :
ofComplex w = Classical.choice inferInstance := by
simp [ofComplex_apply_eq_ite w, hw]
lemma ofComplex_apply_eq_of_im_nonpos {w w' : ℂ} (hw : w.im ≤ 0) (hw' : w'.im ≤ 0) :
ofComplex w = ofComplex w' := by
simp [ofComplex_apply_of_im_nonpos, hw, hw']
lemma comp_ofComplex (f : ℍ → ℂ) (z : ℍ) : (↑ₕ f) z = f z :=
congrArg _ <| ofComplex_apply z
lemma comp_ofComplex_of_im_pos (f : ℍ → ℂ) (z : ℂ) (hz : 0 < z.im) : (↑ₕ f) z = f ⟨z, hz⟩ :=
congrArg _ <| ofComplex_apply ⟨z, hz⟩
lemma comp_ofComplex_of_im_le_zero (f : ℍ → ℂ) (z z' : ℂ) (hz : z.im ≤ 0) (hz' : z'.im ≤ 0) :
(↑ₕ f) z = (↑ₕ f) z' := by
simp [ofComplex_apply_of_im_nonpos, hz, hz']
lemma eventuallyEq_coe_comp_ofComplex {z : ℂ} (hz : 0 < z.im) :
UpperHalfPlane.coe ∘ ofComplex =ᶠ[𝓝 z] id := by
filter_upwards [(Complex.continuous_im.isOpen_preimage _ isOpen_Ioi).mem_nhds hz] with x hx
simp only [Function.comp_apply, ofComplex_apply_of_im_pos hx, id_eq, coe_mk_subtype]
end ofComplex
end UpperHalfPlane
|
order.lean
|
import Mathlib.Data.Matrix.Rank
import Mathlib.Tactic.Order
example (a b c : Nat) (h1 : a ≤ b) (h2 : b ≤ c) : a ≤ c := by
order
example (a b c d e : Nat) (h1 : a ≤ b) (h2 : b ≤ c) (h3 : c ≤ d) (h4 : d ≤ e) (h5 : b ≠ d) :
a < e := by
order
example (a b c : Nat) (h1 : a = b) (h2 : b = c) : a = c := by
order
example (a b : Int) (h1 : ¬(a < b)) (h2 : ¬(b < a)) : a = b := by
order
variable {α : Type*}
example [LinearOrder α] (a b : α) (h1 : ¬(a < b)) (h2 : ¬(b < a)) : a = b := by
order
example [PartialOrder α] (a b c d e : α) (h1 : a ≤ b) (h2 : b ≤ c) (h3 : c ≤ d) (h4 : d ≤ e) (h5 : b ≠ d) :
a < e := by
order
example [PartialOrder α] (s t x y : α) (h1 : s ≤ x) (h2 : x ≤ t) (h3 : s ≤ y)
(h4 : y ≤ t) (h5 : x ≠ y) :
s < t := by
order
example [PartialOrder α] (a b c d : α) (h1 : a ≤ b) (h2 : b ≤ c) (h3 : ¬(a < c))
(h4 : a ≤ d) :
c ≤ d := by
order
example [PartialOrder α] (a : α) :
¬ (a < a) := by
order
example [Preorder α] (a b c d : α) (h1 : a ≤ b) (h2 : b ≤ c) (h3 : ¬(a < c))
(h4 : a ≤ d) :
c ≤ d := by
order
example [Preorder α] (a b : α) (h1 : a < b) : b > a := by
order
example [Preorder α] (a b : α) (h1 : a > b) : b < a := by
order
example [PartialOrder α] [OrderTop α] (a : α) (h1 : ⊤ ≤ a) : a = ⊤ := by
order
example [Preorder α] [OrderTop α] (a : α) (h1 : a > ⊤) : a < a := by
order
example [Preorder α] [OrderBot α] [OrderTop α] : (⊥ : α) ≤ ⊤ := by
order
example (a b : α) [PartialOrder α] [OrderBot α] [OrderTop α] (h : (⊥ : α) = ⊤) : a = b := by
order
example (a b : α) [SemilatticeSup α] : a ≤ a ⊔ b := by
order
example (a b c : α) [SemilatticeSup α] (h1 : a ≤ c) (h2 : b ≤ c) : a ⊔ b ≤ c := by
order
example (a b c : α) [SemilatticeSup α] (h1 : a ≤ b) : a ⊔ c ≤ b ⊔ c := by
order
example (a b : α) [Lattice α] : a ⊓ b ≤ a ⊔ b := by
order
example (a b : α) [Lattice α] : a ⊓ b ≤ a ⊔ b := by
order
example (a b : α) [Lattice α] : a ⊔ b = b ⊔ a := by
order
example (a b c : α) [Lattice α] : a ⊓ (b ⊔ c) ≥ (a ⊓ b) ⊔ (a ⊓ c) := by
order
set_option trace.order true in
/--
error: No contradiction found.
Additional diagnostic information may be available using the `set_option trace.order true` command.
---
trace: [order] Working on type α (partial order)
[order] Collected atoms:
#0 := a ⊓ (b ⊔ c)
#1 := a
#2 := b ⊔ c
#3 := b
#4 := c
#5 := a ⊓ b ⊔ a ⊓ c
#6 := a ⊓ b
#7 := a ⊓ c
[order] Collected facts:
#3 ≤ #2
#4 ≤ #2
#2 := #3 ⊔ #4
#0 ≤ #1
#0 ≤ #2
#0 := #1 ⊓ #2
#6 ≤ #1
#6 ≤ #3
#6 := #1 ⊓ #3
#7 ≤ #1
#7 ≤ #4
#7 := #1 ⊓ #4
#6 ≤ #5
#7 ≤ #5
#5 := #6 ⊔ #7
#0 ≠ #5
¬ #0 < #5
[order] Working on type ℕ (linear order)
[order] Collected atoms:
#0 := x
#1 := y
[order] Collected facts:
#0 ≠ #1
#0 ≤ #1
-/
#guard_msgs in
example (a b c : α) (x y : Nat) (h : x < y) [Lattice α] : a ⊓ (b ⊔ c) ≤ (a ⊓ b) ⊔ (a ⊓ c) := by
order
-- This used to work when a different matching strategy was used in `order`.
-- This example is now considered outside the scope of the `order` tactic.
/--
error: No contradiction found.
Additional diagnostic information may be available using the `set_option trace.order true` command.
-/
#guard_msgs in
example (a b c : Set α) : a ∩ (b ∪ c) ≥ (a ∩ b) ∪ (a ∩ c) := by
order
example {n : Nat} (A B C : Matrix (Fin n) (Fin n) ℚ) : (A * B * C).rank ≤ A.rank ⊓ C.rank := by
have h1 := Matrix.rank_mul_le A B
have h2 := Matrix.rank_mul_le (A * B) C
order
-- worst case for the current algorithm
example [PartialOrder α]
(x1 y1 : α)
(x2 y2 : α)
(x3 y3 : α)
(x4 y4 : α)
(x5 y5 : α)
(x6 y6 : α)
(x7 y7 : α)
(x8 y8 : α)
(x9 y9 : α)
(x10 y10 : α)
(x11 y11 : α)
(x12 y12 : α)
(x13 y13 : α)
(x14 y14 : α)
(x15 y15 : α)
(x16 y16 : α)
(x17 y17 : α)
(x18 y18 : α)
(x19 y19 : α)
(x20 y20 : α)
(x21 y21 : α)
(x22 y22 : α)
(x23 y23 : α)
(x24 y24 : α)
(x25 y25 : α)
(x26 y26 : α)
(x27 y27 : α)
(x28 y28 : α)
(x29 y29 : α)
(x30 y30 : α)
(h0 : y1 ≤ x1)
(h1 : ¬(y1 < x1)) (h2 : y2 ≤ x1) (h3 : y1 ≤ x2)
(h4 : ¬(y2 < x2)) (h5 : y3 ≤ x2) (h6 : y2 ≤ x3)
(h7 : ¬(y3 < x3)) (h8 : y4 ≤ x3) (h9 : y3 ≤ x4)
(h10 : ¬(y4 < x4)) (h11 : y5 ≤ x4) (h12 : y4 ≤ x5)
(h13 : ¬(y5 < x5)) (h14 : y6 ≤ x5) (h15 : y5 ≤ x6)
(h16 : ¬(y6 < x6)) (h17 : y7 ≤ x6) (h18 : y6 ≤ x7)
(h19 : ¬(y7 < x7)) (h20 : y8 ≤ x7) (h21 : y7 ≤ x8)
(h22 : ¬(y8 < x8)) (h23 : y9 ≤ x8) (h24 : y8 ≤ x9)
(h25 : ¬(y9 < x9)) (h26 : y10 ≤ x9) (h27 : y9 ≤ x10)
(h28 : ¬(y10 < x10)) (h29 : y11 ≤ x10) (h30 : y10 ≤ x11)
(h31 : ¬(y11 < x11)) (h32 : y12 ≤ x11) (h33 : y11 ≤ x12)
(h34 : ¬(y12 < x12)) (h35 : y13 ≤ x12) (h36 : y12 ≤ x13)
(h37 : ¬(y13 < x13)) (h38 : y14 ≤ x13) (h39 : y13 ≤ x14)
(h40 : ¬(y14 < x14)) (h41 : y15 ≤ x14) (h42 : y14 ≤ x15)
(h43 : ¬(y15 < x15)) (h44 : y16 ≤ x15) (h45 : y15 ≤ x16)
(h46 : ¬(y16 < x16)) (h47 : y17 ≤ x16) (h48 : y16 ≤ x17)
(h49 : ¬(y17 < x17)) (h50 : y18 ≤ x17) (h51 : y17 ≤ x18)
(h52 : ¬(y18 < x18)) (h53 : y19 ≤ x18) (h54 : y18 ≤ x19)
(h55 : ¬(y19 < x19)) (h56 : y20 ≤ x19) (h57 : y19 ≤ x20)
(h58 : ¬(y20 < x20)) (h59 : y21 ≤ x20) (h60 : y20 ≤ x21)
(h61 : ¬(y21 < x21)) (h62 : y22 ≤ x21) (h63 : y21 ≤ x22)
(h64 : ¬(y22 < x22)) (h65 : y23 ≤ x22) (h66 : y22 ≤ x23)
(h67 : ¬(y23 < x23)) (h68 : y24 ≤ x23) (h69 : y23 ≤ x24)
(h70 : ¬(y24 < x24)) (h71 : y25 ≤ x24) (h72 : y24 ≤ x25)
(h73 : ¬(y25 < x25)) (h74 : y26 ≤ x25) (h75 : y25 ≤ x26)
(h76 : ¬(y26 < x26)) (h77 : y27 ≤ x26) (h78 : y26 ≤ x27)
(h79 : ¬(y27 < x27)) (h80 : y28 ≤ x27) (h81 : y27 ≤ x28)
(h82 : ¬(y28 < x28)) (h83 : y29 ≤ x28) (h84 : y28 ≤ x29)
(h85 : ¬(y29 < x29)) (h86 : y30 ≤ x29) (h87 : y29 ≤ x30)
(h88 : ¬(y30 < x30)) : x30 = y30 := by
order
|
Basic.lean
|
/-
Copyright (c) 2018 Michael Jendrusch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Jendrusch, Kim Morrison
-/
import Mathlib.CategoryTheory.Monoidal.Cartesian.Basic
import Mathlib.CategoryTheory.Monoidal.Functor
import Mathlib.CategoryTheory.Limits.Types.Shapes
/-!
# The category of types is a (symmetric) monoidal category
-/
open CategoryTheory Limits MonoidalCategory
open Tactic
universe v u
namespace CategoryTheory
instance typesCartesianMonoidalCategory : CartesianMonoidalCategory (Type u) :=
.ofChosenFiniteProducts Types.terminalLimitCone Types.binaryProductLimitCone
instance : BraidedCategory (Type u) := .ofCartesianMonoidalCategory
theorem types_tensorObj_def {X Y : Type u} : X ⊗ Y = (X × Y) := rfl
theorem types_tensorUnit_def : 𝟙_ (Type u) = PUnit := rfl
@[simp]
theorem tensor_apply {W X Y Z : Type u} (f : W ⟶ X) (g : Y ⟶ Z) (p : W ⊗ Y) :
(f ⊗ₘ g) p = (f p.1, g p.2) :=
rfl
@[simp]
theorem whiskerLeft_apply (X : Type u) {Y Z : Type u} (f : Y ⟶ Z) (p : X ⊗ Y) :
(X ◁ f) p = (p.1, f p.2) :=
rfl
@[simp]
theorem whiskerRight_apply {Y Z : Type u} (f : Y ⟶ Z) (X : Type u) (p : Y ⊗ X) :
(f ▷ X) p = (f p.1, p.2) :=
rfl
@[simp]
theorem leftUnitor_hom_apply {X : Type u} {x : X} {p : PUnit} :
((λ_ X).hom : 𝟙_ (Type u) ⊗ X → X) (p, x) = x :=
rfl
@[simp]
theorem leftUnitor_inv_apply {X : Type u} {x : X} :
((λ_ X).inv : X ⟶ 𝟙_ (Type u) ⊗ X) x = (PUnit.unit, x) :=
rfl
@[simp]
theorem rightUnitor_hom_apply {X : Type u} {x : X} {p : PUnit} :
((ρ_ X).hom : X ⊗ 𝟙_ (Type u) → X) (x, p) = x :=
rfl
@[simp]
theorem rightUnitor_inv_apply {X : Type u} {x : X} :
((ρ_ X).inv : X ⟶ X ⊗ 𝟙_ (Type u)) x = (x, PUnit.unit) :=
rfl
@[simp]
theorem associator_hom_apply {X Y Z : Type u} {x : X} {y : Y} {z : Z} :
((α_ X Y Z).hom : (X ⊗ Y) ⊗ Z → X ⊗ Y ⊗ Z) ((x, y), z) = (x, (y, z)) :=
rfl
@[simp]
theorem associator_inv_apply {X Y Z : Type u} {x : X} {y : Y} {z : Z} :
((α_ X Y Z).inv : X ⊗ Y ⊗ Z → (X ⊗ Y) ⊗ Z) (x, (y, z)) = ((x, y), z) :=
rfl
@[simp] theorem associator_hom_apply_1 {X Y Z : Type u} {x} :
(((α_ X Y Z).hom : (X ⊗ Y) ⊗ Z → X ⊗ Y ⊗ Z) x).1 = x.1.1 :=
rfl
@[simp] theorem associator_hom_apply_2_1 {X Y Z : Type u} {x} :
(((α_ X Y Z).hom : (X ⊗ Y) ⊗ Z → X ⊗ Y ⊗ Z) x).2.1 = x.1.2 :=
rfl
@[simp] theorem associator_hom_apply_2_2 {X Y Z : Type u} {x} :
(((α_ X Y Z).hom : (X ⊗ Y) ⊗ Z → X ⊗ Y ⊗ Z) x).2.2 = x.2 :=
rfl
@[simp] theorem associator_inv_apply_1_1 {X Y Z : Type u} {x} :
(((α_ X Y Z).inv : X ⊗ Y ⊗ Z → (X ⊗ Y) ⊗ Z) x).1.1 = x.1 :=
rfl
@[simp] theorem associator_inv_apply_1_2 {X Y Z : Type u} {x} :
(((α_ X Y Z).inv : X ⊗ Y ⊗ Z → (X ⊗ Y) ⊗ Z) x).1.2 = x.2.1 :=
rfl
@[simp] theorem associator_inv_apply_2 {X Y Z : Type u} {x} :
(((α_ X Y Z).inv : X ⊗ Y ⊗ Z → (X ⊗ Y) ⊗ Z) x).2 = x.2.2 :=
rfl
@[simp]
theorem braiding_hom_apply {X Y : Type u} {x : X} {y : Y} :
((β_ X Y).hom : X ⊗ Y → Y ⊗ X) (x, y) = (y, x) :=
rfl
@[simp]
theorem braiding_inv_apply {X Y : Type u} {x : X} {y : Y} :
((β_ X Y).inv : Y ⊗ X → X ⊗ Y) (y, x) = (x, y) :=
rfl
@[simp]
theorem CartesianMonoidalCategory.lift_apply {X Y Z : Type u} {f : X ⟶ Y} {g : X ⟶ Z} {x : X} :
lift f g x = (f x, g x) :=
rfl
-- We don't yet have an API for tensor products indexed by finite ordered types,
-- but it would be nice to state how monoidal functors preserve these.
/-- If `F` is a monoidal functor out of `Type`, it takes the (n+1)st cartesian power
of a type to the image of that type, tensored with the image of the nth cartesian power. -/
noncomputable def MonoidalFunctor.mapPi {C : Type*} [Category C] [MonoidalCategory C]
(F : Type _ ⥤ C) [F.Monoidal] (n : ℕ) (β : Type*) :
F.obj (Fin (n + 1) → β) ≅ F.obj β ⊗ F.obj (Fin n → β) :=
Functor.mapIso _ (Fin.consEquiv _).symm.toIso ≪≫ (Functor.Monoidal.μIso F β (Fin n → β)).symm
end CategoryTheory
|
vector.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop finfun tuple.
From mathcomp Require Import ssralg matrix mxalgebra zmodp.
(******************************************************************************)
(* Finite dimensional vector spaces *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* vectType R == interface structure for finite dimensional (more *)
(* precisely, detachable) vector spaces over R, which *)
(* should be at least a nzRingType *)
(* The HB class is called Vector. *)
(* Vector.axiom n M <-> type M is linearly isomorphic to 'rV_n *)
(* := {v2r : M -> 'rV_n| linear v2r & bijective v2r} *)
(* {vspace vT} == the type of (detachable) subspaces of vT; vT *)
(* should have a vectType structure over a fieldType *)
(* subvs_of U == the subtype of elements of V in the subspace U *)
(* This is canonically a vectType. *)
(* vsval u == linear injection of u : subvs_of U into V *)
(* vsproj U v == linear projection of v : V in subvs U *)
(* rVof e v == row vector in 'rV_(\dim vT) of coordinates of *)
(* v : vT in the basis e *)
(* vecof e v == vector in vT whose coordinates in the basis e are *)
(* given by v : 'rV_(\dim vT) *)
(* Note that this is the inverse of rVof. *)
(* mxof e e' f == \dim uT * \dim vT matrix of the linear function *)
(* f : 'Hom(uT, vT) in the bases e of uT and e' of vT,*)
(* acting on row vectors *)
(* hommx e f M == linear function in 'Hom(uT, vT) whose matrix *)
(* in the bases e and f is M : 'M_(\dim uT, \dim vT) *)
(* Note that this is the inverse of mxof. *)
(* vsof e M == the subspace of vT generated by the rows of M, *)
(* seen as coordinates in the basis e *)
(* msof e U == matrix whose rows, seen as coordinates in the *)
(* basis e, generate the subspace U of vT *)
(* Note that this is the inverse of vsof. *)
(* 'Hom(aT, rT) == the type of linear functions (homomorphisms) from *)
(* aT to rT, where aT and rT are vectType structures *)
(* Elements of 'Hom(aT, rT) coerce to Coq functions. *)
(* linfun f == a vector linear function in 'Hom(aT, rT) that *)
(* coincides with f : aT -> rT when f is linear *)
(* 'End(vT) == endomorphisms of vT (:= 'Hom(vT, vT)) *)
(* --> The types subvs_of U, 'Hom(aT, rT), 'End(vT), K^o, 'M[K]_(m, n), *)
(* vT * wT, {ffun I -> vT}, vT ^ n all have canonical vectType instances. *)
(* *)
(* Functions: *)
(* <[v]>%VS == the vector space generated by v (a line if v != 0) *)
(* 0%VS == the trivial vector subspace *)
(* fullv, {:vT} == the complete vector subspace (displays as fullv) *)
(* (U + V)%VS == the join (sum) of two subspaces U and V *)
(* (U :&: V)%VS == intersection of vector subspaces U and V *)
(* (U^C)%VS == a complement of the vector subspace U *)
(* (U :\: V)%VS == a local complement to U :& V in the subspace U *)
(* \dim U == dimension of a vector space U *)
(* span X, <<X>>%VS == the subspace spanned by the vector sequence X *)
(* coord X i v == i'th coordinate of v on X, when v \in <<X>>%VS and *)
(* where X : n.-tuple vT and i : 'I_n *)
(* Note that coord X i is a scalar function. *)
(* vpick U == a nonzero element of U if U= 0%VS, or 0 if U = 0 *)
(* vbasis U == a (\dim U).-tuple that is a basis of U *)
(* \1%VF == the identity linear function *)
(* (f \o g)%VF == the composite of two linear functions f and g *)
(* (f^-1)%VF == a linear function that is a right inverse to the *)
(* linear function f on the codomain of f *)
(* (f @: U)%VS == the image of U by the linear function f *)
(* (f @^-1: U)%VS == the pre-image of U by the linear function f *)
(* lker f == the kernel of the linear function f *)
(* limg f == the image of the linear function f *)
(* fixedSpace f == the fixed space of a linear endomorphism f *)
(* daddv_pi U V == projection onto U along V if U and V are disjoint; *)
(* daddv_pi U V + daddv_pi V U is then a projection *)
(* onto the direct sum (U + V)%VS *)
(* projv U == projection onto U (along U^C, := daddv_pi U U^C) *)
(* addv_pi1 U V == projection onto the subspace U :\: V of U along V *)
(* addv_pi2 U V == projection onto V along U :\: V; note that *)
(* addv_pi1 U V and addv_pi2 U V are (asymmetrical) *)
(* complementary projections on (U + V)%VS *)
(* sumv_pi_for defV i == for defV : V = (V \sum_(j <- r | P j) Vs j)%VS, *)
(* j ranging over an eqType, this is a projection on *)
(* a subspace of Vs i, along a complement in V, such *)
(* that \sum_(j <- r | P j) sumv_pi_for defV j is a *)
(* projection onto V if filter P r is duplicate-free *)
(* (e.g., when V := \sum_(j | P j) Vs j) *)
(* sumv_pi V i == notation the above when defV == erefl V, and V is *)
(* convertible to \sum_(j <- r | P j) Vs j)%VS *)
(* leigenspace f a == linear eigenspace of the linear function f for *)
(* the (potential) eigenvalue a *)
(* *)
(* Predicates: *)
(* v \in U == v belongs to U (:= (<[v]> <= U)%VS) *)
(* (U <= V)%VS == U is a subspace of V *)
(* free B == B is a sequence of nonzero linearly independent *)
(* vectors *)
(* basis_of U b == b is a basis of the subspace U *)
(* directv S == S is the expression for a direct sum of subspaces *)
(* leigenvalue f a == a is a linear eigenvalue of the linear function f *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope vspace_scope.
Declare Scope lfun_scope.
Local Open Scope ring_scope.
Reserved Notation "{ 'vspace' T }" (format "{ 'vspace' T }").
Reserved Notation "''Hom' ( T , rT )" (format "''Hom' ( T , rT )").
Reserved Notation "''End' ( T )" (format "''End' ( T )").
Reserved Notation "\dim A" (at level 10, A at level 8, format "\dim A").
Delimit Scope vspace_scope with VS.
Import GRing.Theory.
(* Finite dimension vector space *)
Definition vector_axiom_def (R : nzRingType) n (V : lmodType R) :=
{v2r : V -> 'rV[R]_n | linear v2r & bijective v2r}.
Arguments vector_axiom_def [R] n%_N V%_type.
HB.mixin Record Lmodule_hasFinDim (R : nzRingType) (V : Type) of GRing.Lmodule R V :=
{ dim : nat;
vector_subdef : vector_axiom_def dim V }.
#[mathcomp(axiom="vector_axiom_def"), short(type="vectType")]
HB.structure Definition Vector (R : nzRingType) :=
{ V of Lmodule_hasFinDim R V & GRing.Lmodule R V }.
#[deprecated(since="mathcomp 2.2.0", note="Use Vector.axiom instead.")]
Notation vector_axiom := Vector.axiom.
Arguments dim {R} s.
(* FIXME: S/space and H/hom were defined behind the module Vector *
* Perhaps we should change their names to avoid conflicts. *)
Section OtherDefs.
Local Coercion dim : Vector.type >-> nat.
Inductive space (K : fieldType) (vT : Vector.type K) :=
Space (mx : 'M[K]_vT) & <<mx>>%MS == mx.
Inductive hom (R : nzRingType) (vT wT : Vector.type R) :=
Hom of 'M[R]_(vT, wT).
End OtherDefs.
(* /FIXME *)
Module Import VectorExports.
Bind Scope ring_scope with Vector.sort.
Arguments space [K] vT%_type.
Notation "{ 'vspace' vT }" := (space vT) : type_scope.
Notation "''Hom' ( aT , rT )" := (hom aT rT) : type_scope.
Notation "''End' ( vT )" := (hom vT vT) : type_scope.
Prenex Implicits Hom.
Delimit Scope vspace_scope with VS.
Bind Scope vspace_scope with space.
Delimit Scope lfun_scope with VF.
Bind Scope lfun_scope with hom.
End VectorExports.
(* The contents of this module exposes the matrix encodings, and should *)
(* therefore not be used outside of the vector library implementation. *)
Module VectorInternalTheory.
Section Iso.
Variables (R : nzRingType) (vT rT : vectType R).
Local Coercion dim : Vector.type >-> nat.
Fact v2r_subproof : Vector.axiom vT vT. Proof. exact: vector_subdef. Qed.
Definition v2r := s2val v2r_subproof.
Let v2r_bij : bijective v2r := s2valP' v2r_subproof.
Fact r2v_subproof : {r2v | cancel r2v v2r}.
Proof.
have r2vP r: {v | v2r v = r}.
by apply: sig_eqW; have [v _ vK] := v2r_bij; exists (v r).
by exists (fun r => sval (r2vP r)) => r; case: (r2vP r).
Qed.
Definition r2v := sval r2v_subproof.
Lemma r2vK : cancel r2v v2r. Proof. exact: svalP r2v_subproof. Qed.
Lemma r2v_inj : injective r2v. Proof. exact: can_inj r2vK. Qed.
Lemma v2rK : cancel v2r r2v. Proof. by have/bij_can_sym:= r2vK; apply. Qed.
Lemma v2r_inj : injective v2r. Proof. exact: can_inj v2rK. Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R vT 'rV_vT _ v2r
(GRing.semilinear_linear (s2valP v2r_subproof)).
HB.instance Definition _ := GRing.isSemilinear.Build R 'rV_vT vT _ r2v
(GRing.semilinear_linear (can2_linear v2rK r2vK)).
End Iso.
Section Vspace.
Variables (K : fieldType) (vT : vectType K).
Local Coercion dim : Vector.type >-> nat.
Definition b2mx n (X : n.-tuple vT) := \matrix_i v2r (tnth X i).
Lemma b2mxK n (X : n.-tuple vT) i : r2v (row i (b2mx X)) = X`_i.
Proof. by rewrite rowK v2rK -tnth_nth. Qed.
Definition vs2mx (U : @space K vT) := let: Space mx _ := U in mx.
Lemma gen_vs2mx (U : {vspace vT}) : <<vs2mx U>>%MS = vs2mx U.
Proof. by apply/eqP; rewrite /vs2mx; case: U. Qed.
Fact mx2vs_subproof m (A : 'M[K]_(m, vT)) : <<(<<A>>)>>%MS == <<A>>%MS.
Proof. by rewrite genmx_id. Qed.
Definition mx2vs {m} A : {vspace vT} := Space (@mx2vs_subproof m A).
HB.instance Definition _ := [isSub of {vspace vT} for vs2mx].
Lemma vs2mxK : cancel vs2mx mx2vs.
Proof. by move=> v; apply: val_inj; rewrite /= gen_vs2mx. Qed.
Lemma mx2vsK m (M : 'M_(m, vT)) : (vs2mx (mx2vs M) :=: M)%MS.
Proof. exact: genmxE. Qed.
End Vspace.
Section Hom.
Variables (R : nzRingType) (aT rT : vectType R).
Definition f2mx (f : 'Hom(aT, rT)) := let: Hom A := f in A.
HB.instance Definition _ : isSub _ _ 'Hom(aT, rT) := [isNew for f2mx].
End Hom.
Arguments mx2vs {K vT m%_N} A%_MS.
Prenex Implicits v2r r2v v2rK r2vK b2mx vs2mx vs2mxK f2mx.
End VectorInternalTheory.
Export VectorExports.
Import VectorInternalTheory.
Section VspaceDefs.
Variables (K : fieldType) (vT : vectType K).
Implicit Types (u : vT) (X : seq vT) (U V : {vspace vT}).
HB.instance Definition _ := [Choice of {vspace vT} by <:].
Definition dimv U := \rank (vs2mx U).
Definition subsetv U V := (vs2mx U <= vs2mx V)%MS.
Definition vline u := mx2vs (v2r u).
(* Vspace membership is defined as line inclusion. *)
Definition pred_of_vspace (U : space vT) : {pred vT} :=
fun v => (vs2mx (vline v) <= vs2mx U)%MS.
Canonical vspace_predType := @PredType _ (unkeyed {vspace vT}) pred_of_vspace.
Definition fullv : {vspace vT} := mx2vs 1%:M.
Definition addv U V := mx2vs (vs2mx U + vs2mx V).
Definition capv U V := mx2vs (vs2mx U :&: vs2mx V).
Definition complv U := mx2vs (vs2mx U)^C.
Definition diffv U V := mx2vs (vs2mx U :\: vs2mx V).
Definition vpick U := r2v (nz_row (vs2mx U)).
Fact span_key : unit. Proof. by []. Qed.
Definition span_expanded_def X := mx2vs (b2mx (in_tuple X)).
Definition span := locked_with span_key span_expanded_def.
Canonical span_unlockable := [unlockable fun span].
Definition vbasis_def U :=
[tuple r2v (row i (row_base (vs2mx U))) | i < dimv U].
Definition vbasis := locked_with span_key vbasis_def.
Canonical vbasis_unlockable := [unlockable fun vbasis].
(* coord and directv are defined in the VectorTheory section. *)
Definition free X := dimv (span X) == size X.
Definition basis_of U X := (span X == U) && free X.
End VspaceDefs.
Coercion pred_of_vspace : space >-> pred_sort.
Notation "\dim U" := (dimv U) : nat_scope.
Notation "U <= V" := (subsetv U V) : vspace_scope.
Notation "U <= V <= W" := (subsetv U V && subsetv V W) : vspace_scope.
Notation "<[ v ] >" := (vline v) : vspace_scope.
Notation "<< X >>" := (span X) : vspace_scope.
Notation "0" := (vline 0) : vspace_scope.
Arguments fullv {K vT}.
Prenex Implicits subsetv addv capv complv diffv span free basis_of.
Notation "U + V" := (addv U V) : vspace_scope.
Notation "U :&: V" := (capv U V) : vspace_scope.
Notation "U ^C" := (complv U) : vspace_scope.
Notation "U :\: V" := (diffv U V) : vspace_scope.
Notation "{ : vT }" := (@fullv _ vT) (only parsing) : vspace_scope.
Notation "\sum_ ( i <- r | P ) U" :=
(\big[addv/0%VS]_(i <- r | P%B) U%VS) : vspace_scope.
Notation "\sum_ ( i <- r ) U" :=
(\big[addv/0%VS]_(i <- r) U%VS) : vspace_scope.
Notation "\sum_ ( m <= i < n | P ) U" :=
(\big[addv/0%VS]_(m <= i < n | P%B) U%VS) : vspace_scope.
Notation "\sum_ ( m <= i < n ) U" :=
(\big[addv/0%VS]_(m <= i < n) U%VS) : vspace_scope.
Notation "\sum_ ( i | P ) U" :=
(\big[addv/0%VS]_(i | P%B) U%VS) : vspace_scope.
Notation "\sum_ i U" :=
(\big[addv/0%VS]_i U%VS) : vspace_scope.
Notation "\sum_ ( i : t | P ) U" :=
(\big[addv/0%VS]_(i : t | P%B) U%VS) (only parsing) : vspace_scope.
Notation "\sum_ ( i : t ) U" :=
(\big[addv/0%VS]_(i : t) U%VS) (only parsing) : vspace_scope.
Notation "\sum_ ( i < n | P ) U" :=
(\big[addv/0%VS]_(i < n | P%B) U%VS) : vspace_scope.
Notation "\sum_ ( i < n ) U" :=
(\big[addv/0%VS]_(i < n) U%VS) : vspace_scope.
Notation "\sum_ ( i 'in' A | P ) U" :=
(\big[addv/0%VS]_(i in A | P%B) U%VS) : vspace_scope.
Notation "\sum_ ( i 'in' A ) U" :=
(\big[addv/0%VS]_(i in A) U%VS) : vspace_scope.
Notation "\bigcap_ ( i <- r | P ) U" :=
(\big[capv/fullv]_(i <- r | P%B) U%VS) : vspace_scope.
Notation "\bigcap_ ( i <- r ) U" :=
(\big[capv/fullv]_(i <- r) U%VS) : vspace_scope.
Notation "\bigcap_ ( m <= i < n | P ) U" :=
(\big[capv/fullv]_(m <= i < n | P%B) U%VS) : vspace_scope.
Notation "\bigcap_ ( m <= i < n ) U" :=
(\big[capv/fullv]_(m <= i < n) U%VS) : vspace_scope.
Notation "\bigcap_ ( i | P ) U" :=
(\big[capv/fullv]_(i | P%B) U%VS) : vspace_scope.
Notation "\bigcap_ i U" :=
(\big[capv/fullv]_i U%VS) : vspace_scope.
Notation "\bigcap_ ( i : t | P ) U" :=
(\big[capv/fullv]_(i : t | P%B) U%VS) (only parsing) : vspace_scope.
Notation "\bigcap_ ( i : t ) U" :=
(\big[capv/fullv]_(i : t) U%VS) (only parsing) : vspace_scope.
Notation "\bigcap_ ( i < n | P ) U" :=
(\big[capv/fullv]_(i < n | P%B) U%VS) : vspace_scope.
Notation "\bigcap_ ( i < n ) U" :=
(\big[capv/fullv]_(i < n) U%VS) : vspace_scope.
Notation "\bigcap_ ( i 'in' A | P ) U" :=
(\big[capv/fullv]_(i in A | P%B) U%VS) : vspace_scope.
Notation "\bigcap_ ( i 'in' A ) U" :=
(\big[capv/fullv]_(i in A) U%VS) : vspace_scope.
Section VectorTheory.
Variables (K : fieldType) (vT : vectType K).
Implicit Types (a : K) (u v w : vT) (X Y : seq vT) (U V W : {vspace vT}).
Local Notation subV := (@subsetv K vT) (only parsing).
Local Notation addV := (@addv K vT) (only parsing).
Local Notation capV := (@capv K vT) (only parsing).
(* begin hide *)
(* Internal theory facts *)
Let vs2mxP U V : reflect (U = V) (vs2mx U == vs2mx V)%MS.
Proof. by rewrite (sameP genmxP eqP) !gen_vs2mx; apply: eqP. Qed.
Let memvK v U : (v \in U) = (v2r v <= vs2mx U)%MS.
Proof. by rewrite -genmxE. Qed.
Let mem_r2v rv U : (r2v rv \in U) = (rv <= vs2mx U)%MS.
Proof. by rewrite memvK r2vK. Qed.
Let vs2mx0 : @vs2mx K vT 0 = 0.
Proof. by rewrite /= linear0 genmx0. Qed.
Let vs2mxD U V : vs2mx (U + V) = (vs2mx U + vs2mx V)%MS.
Proof. by rewrite /= genmx_adds !gen_vs2mx. Qed.
Let vs2mx_sum := big_morph _ vs2mxD vs2mx0.
Let vs2mxI U V : vs2mx (U :&: V) = (vs2mx U :&: vs2mx V)%MS.
Proof. by rewrite /= genmx_cap !gen_vs2mx. Qed.
Let vs2mxF : vs2mx {:vT} = 1%:M.
Proof. by rewrite /= genmx1. Qed.
Let row_b2mx n (X : n.-tuple vT) i : row i (b2mx X) = v2r X`_i.
Proof. by rewrite -tnth_nth rowK. Qed.
Let span_b2mx n (X : n.-tuple vT) : span X = mx2vs (b2mx X).
Proof. by rewrite unlock tvalK; case: _ / (esym _). Qed.
Let mul_b2mx n (X : n.-tuple vT) (rk : 'rV_n) :
\sum_i rk 0 i *: X`_i = r2v (rk *m b2mx X).
Proof.
rewrite mulmx_sum_row linear_sum; apply: eq_bigr => i _.
by rewrite row_b2mx linearZ /= v2rK.
Qed.
Let lin_b2mx n (X : n.-tuple vT) k :
\sum_(i < n) k i *: X`_i = r2v (\row_i k i *m b2mx X).
Proof. by rewrite -mul_b2mx; apply: eq_bigr => i _; rewrite mxE. Qed.
Let free_b2mx n (X : n.-tuple vT) : free X = row_free (b2mx X).
Proof. by rewrite /free /dimv span_b2mx genmxE size_tuple. Qed.
(* end hide *)
Lemma memvE v U : (v \in U) = (<[v]> <= U)%VS. Proof. by []. Qed.
Lemma vlineP v1 v2 : reflect (exists k, v1 = k *: v2) (v1 \in <[v2]>)%VS.
Proof.
apply: (iffP idP) => [|[k ->]]; rewrite memvK genmxE ?linearZ ?scalemx_sub //.
by case/sub_rVP=> k; rewrite -linearZ => /v2r_inj->; exists k.
Qed.
Fact memv_submod_closed U : submod_closed U.
Proof.
split=> [|a u v]; rewrite !memvK 1?linear0 1?sub0mx // => Uu Uv.
by rewrite linearP addmx_sub ?scalemx_sub.
Qed.
HB.instance Definition _ (U : {vspace vT}) :=
GRing.isSubmodClosed.Build K vT (pred_of_vspace U) (memv_submod_closed U).
Lemma mem0v U : 0 \in U. Proof. exact: rpred0. Qed.
Lemma memvN U v : (- v \in U) = (v \in U). Proof. exact: rpredN. Qed.
Lemma memvD U : {in U &, forall u v, u + v \in U}. Proof. exact: rpredD. Qed.
Lemma memvB U : {in U &, forall u v, u - v \in U}. Proof. exact: rpredB. Qed.
Lemma memvZ U k : {in U, forall v, k *: v \in U}. Proof. exact: rpredZ. Qed.
Lemma memv_suml I r (P : pred I) vs U :
(forall i, P i -> vs i \in U) -> \sum_(i <- r | P i) vs i \in U.
Proof. exact: rpred_sum. Qed.
Lemma memv_line u : u \in <[u]>%VS.
Proof. by apply/vlineP; exists 1; rewrite scale1r. Qed.
Lemma subvP U V : reflect {subset U <= V} (U <= V)%VS.
Proof.
apply: (iffP rV_subP) => sU12 u.
by rewrite !memvE /subsetv !genmxE => /sU12.
by have:= sU12 (r2v u); rewrite !memvE /subsetv !genmxE r2vK.
Qed.
Lemma subvv U : (U <= U)%VS. Proof. exact/subvP. Qed.
Hint Resolve subvv : core.
Lemma subv_trans : transitive subV.
Proof. by move=> U V W /subvP sUV /subvP sVW; apply/subvP=> u /sUV/sVW. Qed.
Lemma subv_anti : antisymmetric subV.
Proof. by move=> U V; apply/vs2mxP. Qed.
Lemma eqEsubv U V : (U == V) = (U <= V <= U)%VS.
Proof. by apply/eqP/idP=> [-> | /subv_anti//]; rewrite subvv. Qed.
Lemma vspaceP U V : U =i V <-> U = V.
Proof.
split=> [eqUV | -> //]; apply/subv_anti/andP.
by split; apply/subvP=> v; rewrite eqUV.
Qed.
Lemma subvPn {U V} : reflect (exists2 u, u \in U & u \notin V) (~~ (U <= V)%VS).
Proof.
apply: (iffP idP) => [|[u Uu]]; last by apply: contra => /subvP->.
case/row_subPn=> i; set vi := row i _ => V'vi.
by exists (r2v vi); rewrite memvK r2vK ?row_sub.
Qed.
(* Empty space. *)
Lemma sub0v U : (0 <= U)%VS.
Proof. exact: mem0v. Qed.
Lemma subv0 U : (U <= 0)%VS = (U == 0%VS).
Proof. by rewrite eqEsubv sub0v andbT. Qed.
Lemma memv0 v : v \in 0%VS = (v == 0).
Proof. by apply/idP/eqP=> [/vlineP[k ->] | ->]; rewrite (scaler0, mem0v). Qed.
(* Full space *)
Lemma subvf U : (U <= fullv)%VS. Proof. by rewrite /subsetv vs2mxF submx1. Qed.
Lemma memvf v : v \in fullv. Proof. exact: subvf. Qed.
(* Picking a non-zero vector in a subspace. *)
Lemma memv_pick U : vpick U \in U. Proof. by rewrite mem_r2v nz_row_sub. Qed.
Lemma vpick0 U : (vpick U == 0) = (U == 0%VS).
Proof. by rewrite -memv0 mem_r2v -subv0 /subV vs2mx0 !submx0 nz_row_eq0. Qed.
(* Sum of subspaces. *)
Lemma subv_add U V W : (U + V <= W)%VS = (U <= W)%VS && (V <= W)%VS.
Proof. by rewrite /subV vs2mxD addsmx_sub. Qed.
Lemma addvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 + V1 <= U2 + V2)%VS.
Proof. by rewrite /subV !vs2mxD; apply: addsmxS. Qed.
Lemma addvSl U V : (U <= U + V)%VS.
Proof. by rewrite /subV vs2mxD addsmxSl. Qed.
Lemma addvSr U V : (V <= U + V)%VS.
Proof. by rewrite /subV vs2mxD addsmxSr. Qed.
Lemma addvC : commutative addV.
Proof. by move=> U V; apply/vs2mxP; rewrite !vs2mxD addsmxC submx_refl. Qed.
Lemma addvA : associative addV.
Proof. by move=> U V W; apply/vs2mxP; rewrite !vs2mxD addsmxA submx_refl. Qed.
Lemma addv_idPl {U V}: reflect (U + V = U)%VS (V <= U)%VS.
Proof. by rewrite /subV (sameP addsmx_idPl eqmxP) -vs2mxD; apply: vs2mxP. Qed.
Lemma addv_idPr {U V} : reflect (U + V = V)%VS (U <= V)%VS.
Proof. by rewrite addvC; apply: addv_idPl. Qed.
Lemma addvv : idempotent_op addV.
Proof. by move=> U; apply/addv_idPl. Qed.
Lemma add0v : left_id 0%VS addV.
Proof. by move=> U; apply/addv_idPr/sub0v. Qed.
Lemma addv0 : right_id 0%VS addV.
Proof. by move=> U; apply/addv_idPl/sub0v. Qed.
Lemma sumfv : left_zero fullv addV.
Proof. by move=> U; apply/addv_idPl/subvf. Qed.
Lemma addvf : right_zero fullv addV.
Proof. by move=> U; apply/addv_idPr/subvf. Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {vspace vT} 0%VS addv
addvA addvC add0v.
Lemma memv_add u v U V : u \in U -> v \in V -> u + v \in (U + V)%VS.
Proof. by rewrite !memvK genmxE linearD; apply: addmx_sub_adds. Qed.
Lemma memv_addP {w U V} :
reflect (exists2 u, u \in U & exists2 v, v \in V & w = u + v)
(w \in U + V)%VS.
Proof.
apply: (iffP idP) => [|[u Uu [v Vv ->]]]; last exact: memv_add.
rewrite memvK genmxE => /sub_addsmxP[r /(canRL v2rK)->].
rewrite linearD /=; set u := r2v _; set v := r2v _.
by exists u; last exists v; rewrite // mem_r2v submxMl.
Qed.
Section BigSum.
Variable I : finType.
Implicit Type P : pred I.
Lemma sumv_sup i0 P U Vs :
P i0 -> (U <= Vs i0)%VS -> (U <= \sum_(i | P i) Vs i)%VS.
Proof. by move=> Pi0 /subv_trans-> //; rewrite (bigD1 i0) ?addvSl. Qed.
Arguments sumv_sup i0 [P U Vs].
Lemma subv_sumP {P Us V} :
reflect (forall i, P i -> Us i <= V)%VS (\sum_(i | P i) Us i <= V)%VS.
Proof.
apply: (iffP idP) => [sUV i Pi | sUV].
by apply: subv_trans sUV; apply: sumv_sup Pi _.
by elim/big_rec: _ => [|i W Pi sWV]; rewrite ?sub0v // subv_add sUV.
Qed.
Lemma memv_sumr P vs (Us : I -> {vspace vT}) :
(forall i, P i -> vs i \in Us i) ->
\sum_(i | P i) vs i \in (\sum_(i | P i) Us i)%VS.
Proof. by move=> Uv; apply/rpred_sum=> i Pi; apply/(sumv_sup i Pi)/Uv. Qed.
Lemma memv_sumP {P} {Us : I -> {vspace vT}} {v} :
reflect (exists2 vs, forall i, P i -> vs i \in Us i
& v = \sum_(i | P i) vs i)
(v \in \sum_(i | P i) Us i)%VS.
Proof.
apply: (iffP idP) => [|[vs Uv ->]]; last exact: memv_sumr.
rewrite memvK vs2mx_sum => /sub_sumsmxP[r /(canRL v2rK)->].
pose f i := r2v (r i *m vs2mx (Us i)); rewrite linear_sum /=.
by exists f => //= i _; rewrite mem_r2v submxMl.
Qed.
End BigSum.
(* Intersection *)
Lemma subv_cap U V W : (U <= V :&: W)%VS = (U <= V)%VS && (U <= W)%VS.
Proof. by rewrite /subV vs2mxI sub_capmx. Qed.
Lemma capvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 :&: V1 <= U2 :&: V2)%VS.
Proof. by rewrite /subV !vs2mxI; apply: capmxS. Qed.
Lemma capvSl U V : (U :&: V <= U)%VS.
Proof. by rewrite /subV vs2mxI capmxSl. Qed.
Lemma capvSr U V : (U :&: V <= V)%VS.
Proof. by rewrite /subV vs2mxI capmxSr. Qed.
Lemma capvC : commutative capV.
Proof. by move=> U V; apply/vs2mxP; rewrite !vs2mxI capmxC submx_refl. Qed.
Lemma capvA : associative capV.
Proof. by move=> U V W; apply/vs2mxP; rewrite !vs2mxI capmxA submx_refl. Qed.
Lemma capv_idPl {U V} : reflect (U :&: V = U)%VS (U <= V)%VS.
Proof. by rewrite /subV(sameP capmx_idPl eqmxP) -vs2mxI; apply: vs2mxP. Qed.
Lemma capv_idPr {U V} : reflect (U :&: V = V)%VS (V <= U)%VS.
Proof. by rewrite capvC; apply: capv_idPl. Qed.
Lemma capvv : idempotent_op capV.
Proof. by move=> U; apply/capv_idPl. Qed.
Lemma cap0v : left_zero 0%VS capV.
Proof. by move=> U; apply/capv_idPl/sub0v. Qed.
Lemma capv0 : right_zero 0%VS capV.
Proof. by move=> U; apply/capv_idPr/sub0v. Qed.
Lemma capfv : left_id fullv capV.
Proof. by move=> U; apply/capv_idPr/subvf. Qed.
Lemma capvf : right_id fullv capV.
Proof. by move=> U; apply/capv_idPl/subvf. Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {vspace vT} fullv capv
capvA capvC capfv.
Lemma memv_cap w U V : (w \in U :&: V)%VS = (w \in U) && (w \in V).
Proof. by rewrite !memvE subv_cap. Qed.
Lemma memv_capP {w U V} : reflect (w \in U /\ w \in V) (w \in U :&: V)%VS.
Proof. by rewrite memv_cap; apply: andP. Qed.
Lemma vspace_modl U V W : (U <= W -> U + (V :&: W) = (U + V) :&: W)%VS.
Proof.
by move=> sUV; apply/vs2mxP; rewrite !(vs2mxD, vs2mxI); apply/eqmxP/matrix_modl.
Qed.
Lemma vspace_modr U V W : (W <= U -> (U :&: V) + W = U :&: (V + W))%VS.
Proof. by rewrite -!(addvC W) !(capvC U); apply: vspace_modl. Qed.
Section BigCap.
Variable I : finType.
Implicit Type P : pred I.
Lemma bigcapv_inf i0 P Us V :
P i0 -> (Us i0 <= V -> \bigcap_(i | P i) Us i <= V)%VS.
Proof. by move=> Pi0; apply: subv_trans; rewrite (bigD1 i0) ?capvSl. Qed.
Lemma subv_bigcapP {P U Vs} :
reflect (forall i, P i -> U <= Vs i)%VS (U <= \bigcap_(i | P i) Vs i)%VS.
Proof.
apply: (iffP idP) => [sUV i Pi | sUV].
by rewrite (subv_trans sUV) ?(bigcapv_inf Pi).
by elim/big_rec: _ => [|i W Pi]; rewrite ?subvf // subv_cap sUV.
Qed.
End BigCap.
(* Complement *)
Lemma addv_complf U : (U + U^C)%VS = fullv.
Proof.
apply/vs2mxP; rewrite vs2mxD -gen_vs2mx -genmx_adds !genmxE submx1 sub1mx.
exact: addsmx_compl_full.
Qed.
Lemma capv_compl U : (U :&: U^C = 0)%VS.
Proof.
apply/val_inj; rewrite [val]/= vs2mx0 vs2mxI -gen_vs2mx -genmx_cap.
by rewrite capmx_compl genmx0.
Qed.
(* Difference *)
Lemma diffvSl U V : (U :\: V <= U)%VS.
Proof. by rewrite /subV genmxE diffmxSl. Qed.
Lemma capv_diff U V : ((U :\: V) :&: V = 0)%VS.
Proof.
apply/val_inj; rewrite [val]/= vs2mx0 vs2mxI -(gen_vs2mx V) -genmx_cap.
by rewrite capmx_diff genmx0.
Qed.
Lemma addv_diff_cap U V : (U :\: V + U :&: V)%VS = U.
Proof.
apply/vs2mxP; rewrite vs2mxD -genmx_adds !genmxE.
exact/eqmxP/addsmx_diff_cap_eq.
Qed.
Lemma addv_diff U V : (U :\: V + V = U + V)%VS.
Proof. by rewrite -{2}(addv_diff_cap U V) -addvA (addv_idPr (capvSr U V)). Qed.
(* Subspace dimension. *)
Lemma dimv0 : \dim (0%VS : {vspace vT}) = 0.
Proof. by rewrite /dimv vs2mx0 mxrank0. Qed.
Lemma dimv_eq0 U : (\dim U == 0) = (U == 0%VS).
Proof. by rewrite /dimv /= mxrank_eq0 [in RHS]/eq_op /= linear0 genmx0. Qed.
Lemma dimvf : \dim {:vT} = dim vT.
Proof. by rewrite /dimv vs2mxF mxrank1. Qed.
Lemma dim_vline v : \dim <[v]> = (v != 0).
Proof. by rewrite /dimv mxrank_gen rank_rV (can2_eq v2rK r2vK) linear0. Qed.
Lemma dimvS U V : (U <= V)%VS -> \dim U <= \dim V.
Proof. exact: mxrankS. Qed.
Lemma dimv_leqif_sup U V : (U <= V)%VS -> \dim U <= \dim V ?= iff (V <= U)%VS.
Proof. exact: mxrank_leqif_sup. Qed.
Lemma dimv_leqif_eq U V : (U <= V)%VS -> \dim U <= \dim V ?= iff (U == V).
Proof. by rewrite eqEsubv; apply: mxrank_leqif_eq. Qed.
Lemma eqEdim U V : (U == V) = (U <= V)%VS && (\dim V <= \dim U).
Proof. by apply/idP/andP=> [/eqP | [/dimv_leqif_eq/geq_leqif]] ->. Qed.
Lemma dimv_compl U : \dim U^C = (\dim {:vT} - \dim U)%N.
Proof. by rewrite dimvf /dimv mxrank_gen mxrank_compl. Qed.
Lemma dimv_cap_compl U V : (\dim (U :&: V) + \dim (U :\: V))%N = \dim U.
Proof. by rewrite /dimv !mxrank_gen mxrank_cap_compl. Qed.
Lemma dimv_sum_cap U V : (\dim (U + V) + \dim (U :&: V) = \dim U + \dim V)%N.
Proof. by rewrite /dimv !mxrank_gen mxrank_sum_cap. Qed.
Lemma dimv_disjoint_sum U V :
(U :&: V = 0)%VS -> \dim (U + V) = (\dim U + \dim V)%N.
Proof. by move=> dxUV; rewrite -dimv_sum_cap dxUV dimv0 addn0. Qed.
Lemma dimv_add_leqif U V :
\dim (U + V) <= \dim U + \dim V ?= iff (U :&: V <= 0)%VS.
Proof.
by rewrite /dimv /subV !mxrank_gen vs2mx0 genmxE; apply: mxrank_adds_leqif.
Qed.
Lemma diffv_eq0 U V : (U :\: V == 0)%VS = (U <= V)%VS.
Proof.
rewrite -dimv_eq0 -(eqn_add2l (\dim (U :&: V))) addn0 dimv_cap_compl eq_sym.
by rewrite (dimv_leqif_eq (capvSl _ _)) (sameP capv_idPl eqP).
Qed.
Lemma dimv_leq_sum I r (P : pred I) (Us : I -> {vspace vT}) :
\dim (\sum_(i <- r | P i) Us i) <= \sum_(i <- r | P i) \dim (Us i).
Proof.
elim/big_rec2: _ => [|i d vs _ le_vs_d]; first by rewrite dim_vline eqxx.
by apply: (leq_trans (dimv_add_leqif _ _)); rewrite leq_add2l.
Qed.
Section SumExpr.
(* The vector direct sum theory clones the interface types of the matrix *)
(* direct sum theory (see mxalgebra for the technical details), but *)
(* nevetheless reuses much of the matrix theory. *)
Structure addv_expr := Sumv {
addv_val :> wrapped {vspace vT};
addv_dim : wrapped nat;
_ : mxsum_spec (vs2mx (unwrap addv_val)) (unwrap addv_dim)
}.
(* Piggyback on mxalgebra theory. *)
Definition vs2mx_sum_expr_subproof (S : addv_expr) :
mxsum_spec (vs2mx (unwrap S)) (unwrap (addv_dim S)).
Proof. by case: S. Qed.
Canonical vs2mx_sum_expr S := ProperMxsumExpr (vs2mx_sum_expr_subproof S).
Canonical trivial_addv U := @Sumv (Wrap U) (Wrap (\dim U)) (TrivialMxsum _).
Structure proper_addv_expr := ProperSumvExpr {
proper_addv_val :> {vspace vT};
proper_addv_dim :> nat;
_ : mxsum_spec (vs2mx proper_addv_val) proper_addv_dim
}.
Definition proper_addvP (S : proper_addv_expr) :=
let: ProperSumvExpr _ _ termS := S return mxsum_spec (vs2mx S) S in termS.
Canonical proper_addv (S : proper_addv_expr) :=
@Sumv (wrap (S : {vspace vT})) (wrap (S : nat)) (proper_addvP S).
Section Binary.
Variables S1 S2 : addv_expr.
Fact binary_addv_subproof :
mxsum_spec (vs2mx (unwrap S1 + unwrap S2))
(unwrap (addv_dim S1) + unwrap (addv_dim S2)).
Proof. by rewrite vs2mxD; apply: proper_mxsumP. Qed.
Canonical binary_addv_expr := ProperSumvExpr binary_addv_subproof.
End Binary.
Section Nary.
Variables (I : Type) (r : seq I) (P : pred I) (S_ : I -> addv_expr).
Fact nary_addv_subproof :
mxsum_spec (vs2mx (\sum_(i <- r | P i) unwrap (S_ i)))
(\sum_(i <- r | P i) unwrap (addv_dim (S_ i))).
Proof. by rewrite vs2mx_sum; apply: proper_mxsumP. Qed.
Canonical nary_addv_expr := ProperSumvExpr nary_addv_subproof.
End Nary.
Definition directv_def S of phantom {vspace vT} (unwrap (addv_val S)) :=
\dim (unwrap S) == unwrap (addv_dim S).
End SumExpr.
Local Notation directv A := (directv_def (Phantom {vspace _} A%VS)).
Lemma directvE (S : addv_expr) :
directv (unwrap S) = (\dim (unwrap S) == unwrap (addv_dim S)).
Proof. by []. Qed.
Lemma directvP {S : proper_addv_expr} : reflect (\dim S = S :> nat) (directv S).
Proof. exact: eqnP. Qed.
Lemma directv_trivial U : directv (unwrap (@trivial_addv U)).
Proof. exact: eqxx. Qed.
Lemma dimv_sum_leqif (S : addv_expr) :
\dim (unwrap S) <= unwrap (addv_dim S) ?= iff directv (unwrap S).
Proof.
rewrite directvE; case: S => [[U] [d] /= defUd]; split=> //=.
rewrite /dimv; elim: {1}_ {U}_ d / defUd => // m1 m2 A1 A2 r1 r2 _ leA1 _ leA2.
by apply: leq_trans (leq_add leA1 leA2); rewrite mxrank_adds_leqif.
Qed.
Lemma directvEgeq (S : addv_expr) :
directv (unwrap S) = (\dim (unwrap S) >= unwrap (addv_dim S)).
Proof. by rewrite leq_eqVlt ltnNge eq_sym !dimv_sum_leqif orbF. Qed.
Section BinaryDirect.
Lemma directv_addE (S1 S2 : addv_expr) :
directv (unwrap S1 + unwrap S2)
= [&& directv (unwrap S1), directv (unwrap S2)
& unwrap S1 :&: unwrap S2 == 0]%VS.
Proof.
by rewrite /directv_def /dimv vs2mxD -mxdirectE mxdirect_addsE -vs2mxI -vs2mx0.
Qed.
Lemma directv_addP {U V} : reflect (U :&: V = 0)%VS (directv (U + V)).
Proof. by rewrite directv_addE !directv_trivial; apply: eqP. Qed.
Lemma directv_add_unique {U V} :
reflect (forall u1 u2 v1 v2, u1 \in U -> u2 \in U -> v1 \in V -> v2 \in V ->
(u1 + v1 == u2 + v2) = ((u1, v1) == (u2, v2)))
(directv (U + V)).
Proof.
apply: (iffP directv_addP) => [dxUV u1 u2 v1 v2 Uu1 Uu2 Vv1 Vv2 | dxUV].
apply/idP/idP=> [| /eqP[-> ->] //]; rewrite -subr_eq0 opprD addrACA addr_eq0.
move/eqP=> eq_uv; rewrite xpair_eqE -subr_eq0 eq_uv oppr_eq0 subr_eq0 andbb.
by rewrite -subr_eq0 -memv0 -dxUV memv_cap -memvN -eq_uv !memvB.
apply/eqP; rewrite -subv0; apply/subvP=> v /memv_capP[U1v U2v].
by rewrite memv0 -[v == 0]andbb {1}eq_sym -xpair_eqE -dxUV ?mem0v // addrC.
Qed.
End BinaryDirect.
Section NaryDirect.
Context {I : finType} {P : pred I}.
Lemma directv_sumP {Us : I -> {vspace vT}} :
reflect (forall i, P i -> Us i :&: (\sum_(j | P j && (j != i)) Us j) = 0)%VS
(directv (\sum_(i | P i) Us i)).
Proof.
rewrite directvE /= /dimv vs2mx_sum -mxdirectE; apply: (equivP mxdirect_sumsP).
by do [split=> dxU i /dxU; rewrite -vs2mx_sum -vs2mxI -vs2mx0] => [/val_inj|->].
Qed.
Lemma directv_sumE {Ss : I -> addv_expr} (xunwrap := unwrap) :
reflect [/\ forall i, P i -> directv (unwrap (Ss i))
& directv (\sum_(i | P i) xunwrap (Ss i))]
(directv (\sum_(i | P i) unwrap (Ss i))).
Proof.
by rewrite !directvE /= /dimv 2!{1}vs2mx_sum -!mxdirectE; apply: mxdirect_sumsE.
Qed.
Lemma directv_sum_independent {Us : I -> {vspace vT}} :
reflect (forall us,
(forall i, P i -> us i \in Us i) -> \sum_(i | P i) us i = 0 ->
(forall i, P i -> us i = 0))
(directv (\sum_(i | P i) Us i)).
Proof.
apply: (iffP directv_sumP) => [dxU us Uu u_0 i Pi | dxU i Pi].
apply/eqP; rewrite -memv0 -(dxU i Pi) memv_cap Uu //= -memvN -sub0r -{1}u_0.
by rewrite (bigD1 i) //= [_ - us i]addrC addKr memv_sumr // => j /andP[/Uu].
apply/eqP; rewrite -subv0; apply/subvP=> v.
rewrite memv_cap memv0 => /andP[Uiv /memv_sumP[us Uu Dv]].
have: \sum_(j | P j) [eta us with i |-> - v] j = 0.
rewrite (bigD1 i) //= eqxx {1}Dv addrC -sumrB big1 // => j /andP[_ i'j].
by rewrite (negPf i'j) subrr.
move/dxU/(_ i Pi); rewrite /= eqxx -oppr_eq0 => -> // j Pj.
by have [-> | i'j] := eqVneq; rewrite ?memvN // Uu ?Pj.
Qed.
Lemma directv_sum_unique {Us : I -> {vspace vT}} :
reflect (forall us vs,
(forall i, P i -> us i \in Us i) ->
(forall i, P i -> vs i \in Us i) ->
(\sum_(i | P i) us i == \sum_(i | P i) vs i)
= [forall (i | P i), us i == vs i])
(directv (\sum_(i | P i) Us i)).
Proof.
apply: (iffP directv_sum_independent) => [dxU us vs Uu Uv | dxU us Uu u_0 i Pi].
apply/idP/forall_inP=> [|eq_uv]; last by apply/eqP/eq_bigr => i /eq_uv/eqP.
rewrite -subr_eq0 -sumrB => /eqP/dxU eq_uv i Pi.
by rewrite -subr_eq0 eq_uv // => j Pj; apply: memvB; move: j Pj.
apply/eqP; have:= esym (dxU us \0 Uu _); rewrite u_0 big1_eq eqxx.
by move/(_ _)/forall_inP=> -> // j _; apply: mem0v.
Qed.
End NaryDirect.
(* Linear span generated by a list of vectors *)
Lemma memv_span X v : v \in X -> v \in <<X>>%VS.
Proof.
by case/seq_tnthP=> i {v}->; rewrite unlock memvK genmxE (eq_row_sub i) // rowK.
Qed.
Lemma memv_span1 v : v \in <<[:: v]>>%VS.
Proof. by rewrite memv_span ?mem_head. Qed.
Lemma dim_span X : \dim <<X>> <= size X.
Proof. by rewrite unlock /dimv genmxE rank_leq_row. Qed.
Lemma span_subvP {X U} : reflect {subset X <= U} (<<X>> <= U)%VS.
Proof.
rewrite /subV [@span _ _]unlock genmxE.
apply: (iffP row_subP) => /= [sXU | sXU i].
by move=> _ /seq_tnthP[i ->]; have:= sXU i; rewrite rowK memvK.
by rewrite rowK -memvK sXU ?mem_tnth.
Qed.
Lemma sub_span X Y : {subset X <= Y} -> (<<X>> <= <<Y>>)%VS.
Proof. by move=> sXY; apply/span_subvP=> v /sXY/memv_span. Qed.
Lemma eq_span X Y : X =i Y -> (<<X>> = <<Y>>)%VS.
Proof.
by move=> eqXY; apply: subv_anti; rewrite !sub_span // => u; rewrite eqXY.
Qed.
Lemma span_def X : span X = (\sum_(u <- X) <[u]>)%VS.
Proof.
apply/subv_anti/andP; split.
by apply/span_subvP=> v Xv; rewrite (big_rem v) // memvE addvSl.
by rewrite big_tnth; apply/subv_sumP=> i _; rewrite -memvE memv_span ?mem_tnth.
Qed.
Lemma span_nil : (<<Nil vT>> = 0)%VS.
Proof. by rewrite span_def big_nil. Qed.
Lemma span_seq1 v : (<<[:: v]>> = <[v]>)%VS.
Proof. by rewrite span_def big_seq1. Qed.
Lemma span_cons v X : (<<v :: X>> = <[v]> + <<X>>)%VS.
Proof. by rewrite !span_def big_cons. Qed.
Lemma span_cat X Y : (<<X ++ Y>> = <<X>> + <<Y>>)%VS.
Proof. by rewrite !span_def big_cat. Qed.
(* Coordinates function; should perhaps be generalized to nat indices. *)
Definition coord_expanded_def n (X : n.-tuple vT) i v :=
(v2r v *m pinvmx (b2mx X)) 0 i.
Definition coord := locked_with span_key coord_expanded_def.
Canonical coord_unlockable := [unlockable fun coord].
Fact coord_is_scalar n (X : n.-tuple vT) i : scalar (coord X i).
Proof. by move=> k u v; rewrite unlock linearP mulmxDl -scalemxAl !mxE. Qed.
HB.instance Definition _ n Xn i :=
GRing.isSemilinear.Build K vT K _ (coord Xn i)
(GRing.semilinear_linear (@coord_is_scalar n Xn i)).
Lemma coord_span n (X : n.-tuple vT) v :
v \in span X -> v = \sum_i coord X i v *: X`_i.
Proof.
rewrite memvK span_b2mx genmxE => Xv.
by rewrite unlock_with mul_b2mx mulmxKpV ?v2rK.
Qed.
Lemma coord0 i v : coord [tuple 0] i v = 0.
Proof.
rewrite unlock /pinvmx rank_rV; case: negP => [[] | _].
by apply/eqP/rowP=> j; rewrite !mxE (tnth_nth 0) /= linear0 mxE.
by rewrite pid_mx_0 !(mulmx0, mul0mx) mxE.
Qed.
(* Free generator sequences. *)
Lemma nil_free : free (Nil vT).
Proof. by rewrite /free span_nil dimv0. Qed.
Lemma seq1_free v : free [:: v] = (v != 0).
Proof. by rewrite /free span_seq1 dim_vline; case: (~~ _). Qed.
Lemma perm_free X Y : perm_eq X Y -> free X = free Y.
Proof.
by move=> eqXY; rewrite /free (perm_size eqXY) (eq_span (perm_mem eqXY)).
Qed.
Lemma free_directv X : free X = (0 \notin X) && directv (\sum_(v <- X) <[v]>).
Proof.
have leXi i (v := tnth (in_tuple X) i): true -> \dim <[v]> <= 1 ?= iff (v != 0).
by rewrite -seq1_free -span_seq1 => _; apply/leqif_eq/dim_span.
have [_ /=] := leqif_trans (dimv_sum_leqif _) (leqif_sum leXi).
rewrite sum1_card card_ord !directvE /= /free andbC span_def !(big_tnth _ _ X).
by congr (_ = _ && _); rewrite -has_pred1 -all_predC -big_all big_tnth big_andE.
Qed.
Lemma free_not0 v X : free X -> v \in X -> v != 0.
Proof. by rewrite free_directv andbC => /andP[_ /memPn]; apply. Qed.
Lemma freeP n (X : n.-tuple vT) :
reflect (forall k, \sum_(i < n) k i *: X`_i = 0 -> (forall i, k i = 0))
(free X).
Proof.
rewrite free_b2mx; apply: (iffP idP) => [t_free k kt0 i | t_free].
suffices /rowP/(_ i): \row_i k i = 0 by rewrite !mxE.
by apply/(row_free_inj t_free)/r2v_inj; rewrite mul0mx -lin_b2mx kt0 linear0.
rewrite -kermx_eq0; apply/rowV0P=> rk /sub_kermxP kt0.
by apply/rowP=> i; rewrite mxE {}t_free // mul_b2mx kt0 linear0.
Qed.
Lemma coord_free n (X : n.-tuple vT) (i j : 'I_n) :
free X -> coord X j (X`_i) = (i == j)%:R.
Proof.
rewrite unlock free_b2mx => /row_freeP[Ct CtK]; rewrite -row_b2mx.
rewrite -row_mul -[pinvmx _]mulmx1 -CtK (mulmxA (b2mx X)) (mulmxA _ _ Ct).
by rewrite mulmxKpV // CtK !mxE.
Qed.
Lemma coord_sum_free n (X : n.-tuple vT) k j :
free X -> coord X j (\sum_(i < n) k i *: X`_i) = k j.
Proof.
move=> Xfree; rewrite linear_sum (bigD1 j) 1?linearZ //= coord_free // eqxx.
rewrite mulr1 big1 ?addr0 // => i /negPf j'i.
by rewrite linearZ /= coord_free // j'i mulr0.
Qed.
Lemma cat_free X Y :
free (X ++ Y) = [&& free X, free Y & directv (<<X>> + <<Y>>)].
Proof.
rewrite !free_directv mem_cat directvE /= !big_cat -directvE /= directv_addE /=.
rewrite negb_or -!andbA; do !bool_congr; rewrite -!span_def.
by rewrite (sameP eqP directv_addP).
Qed.
Lemma catl_free Y X : free (X ++ Y) -> free X.
Proof. by rewrite cat_free => /and3P[]. Qed.
Lemma catr_free X Y : free (X ++ Y) -> free Y.
Proof. by rewrite cat_free => /and3P[]. Qed.
Lemma filter_free p X : free X -> free (filter p X).
Proof.
rewrite -(perm_free (etrans (perm_filterC p X _) (perm_refl X))).
exact: catl_free.
Qed.
Lemma free_cons v X : free (v :: X) = (v \notin <<X>>)%VS && free X.
Proof.
rewrite (cat_free [:: v]) seq1_free directvEgeq /= span_seq1 dim_vline.
case: eqP => [-> | _] /=; first by rewrite mem0v.
rewrite andbC ltnNge (geq_leqif (dimv_leqif_sup _)) ?addvSr //.
by rewrite subv_add subvv andbT -memvE.
Qed.
Lemma freeE n (X : n.-tuple vT) :
free X = [forall i : 'I_n, X`_i \notin <<drop i.+1 X>>%VS].
Proof.
case: X => X /= /eqP <-{n}; rewrite -(big_andE xpredT) /=.
elim: X => [|v X IH_X] /=; first by rewrite nil_free big_ord0.
by rewrite free_cons IH_X big_ord_recl drop0.
Qed.
Lemma freeNE n (X : n.-tuple vT) :
~~ free X = [exists i : 'I_n, X`_i \in <<drop i.+1 X>>%VS].
Proof. by rewrite freeE -negb_exists negbK. Qed.
Lemma free_uniq X : free X -> uniq X.
Proof.
elim: X => //= v b IH_X; rewrite free_cons => /andP[X'v /IH_X->].
by rewrite (contra _ X'v) // => /memv_span.
Qed.
Lemma free_span X v (sumX := fun k => \sum_(x <- X) k x *: x) :
free X -> v \in <<X>>%VS ->
{k | v = sumX k & forall k1, v = sumX k1 -> {in X, k1 =1 k}}.
Proof.
rewrite -{2}[X]in_tupleE => freeX /coord_span def_v.
pose k x := oapp (fun i => coord (in_tuple X) i v) 0 (insub (index x X)).
exists k => [|k1 {}def_v _ /(nthP 0)[i ltiX <-]].
rewrite /sumX (big_nth 0) big_mkord def_v; apply: eq_bigr => i _.
by rewrite /k index_uniq ?free_uniq // valK.
rewrite /k /= index_uniq ?free_uniq // insubT //= def_v.
by rewrite /sumX (big_nth 0) big_mkord coord_sum_free.
Qed.
Lemma linear_of_free (rT : lmodType K) X (fX : seq rT) :
{f : {linear vT -> rT} | free X -> size fX = size X -> map f X = fX}.
Proof.
pose f u := \sum_i coord (in_tuple X) i u *: fX`_i.
have lin_f: linear f.
move=> k u v; rewrite scaler_sumr -big_split; apply: eq_bigr => i _.
by rewrite /= scalerA -scalerDl linearP.
pose flM := GRing.isLinear.Build _ _ _ _ f lin_f.
pose fL : {linear _ -> _} := HB.pack f flM.
exists fL => freeX eq_szX.
apply/esym/(@eq_from_nth _ 0); rewrite ?size_map eq_szX // => i ltiX.
rewrite (nth_map 0) //= /f (bigD1 (Ordinal ltiX)) //=.
rewrite big1 => [|j /negbTE neqji]; rewrite (coord_free (Ordinal _)) //.
by rewrite eqxx scale1r addr0.
by rewrite eq_sym neqji scale0r.
Qed.
(* Subspace bases *)
Lemma span_basis U X : basis_of U X -> <<X>>%VS = U.
Proof. by case/andP=> /eqP. Qed.
Lemma basis_free U X : basis_of U X -> free X.
Proof. by case/andP. Qed.
Lemma coord_basis U n (X : n.-tuple vT) v :
basis_of U X -> v \in U -> v = \sum_i coord X i v *: X`_i.
Proof. by move/span_basis <-; apply: coord_span. Qed.
Lemma nil_basis : basis_of 0 (Nil vT).
Proof. by rewrite /basis_of span_nil eqxx nil_free. Qed.
Lemma seq1_basis v : v != 0 -> basis_of <[v]> [:: v].
Proof. by move=> nz_v; rewrite /basis_of span_seq1 // eqxx seq1_free. Qed.
Lemma basis_not0 x U X : basis_of U X -> x \in X -> x != 0.
Proof. by move/basis_free/free_not0; apply. Qed.
Lemma basis_mem x U X : basis_of U X -> x \in X -> x \in U.
Proof. by move/span_basis=> <- /memv_span. Qed.
Lemma cat_basis U V X Y :
directv (U + V) -> basis_of U X -> basis_of V Y -> basis_of (U + V) (X ++ Y).
Proof.
move=> dxUV /andP[/eqP defU freeX] /andP[/eqP defV freeY].
by rewrite /basis_of span_cat cat_free defU defV // eqxx freeX freeY.
Qed.
Lemma size_basis U n (X : n.-tuple vT) : basis_of U X -> \dim U = n.
Proof. by case/andP=> /eqP <- /eqnP->; apply: size_tuple. Qed.
Lemma basisEdim X U : basis_of U X = (U <= <<X>>)%VS && (size X <= \dim U).
Proof.
apply/andP/idP=> [[defU /eqnP <-]| ]; first by rewrite -eqEdim eq_sym.
case/andP=> sUX leXU; have leXX := dim_span X.
rewrite /free eq_sym eqEdim sUX eqn_leq !(leq_trans leXX) //.
by rewrite (leq_trans leXU) ?dimvS.
Qed.
Lemma basisEfree X U :
basis_of U X = [&& free X, (<<X>> <= U)%VS & \dim U <= size X].
Proof.
by rewrite andbC; apply: andb_id2r => freeX; rewrite eqEdim (eqnP freeX).
Qed.
Lemma perm_basis X Y U : perm_eq X Y -> basis_of U X = basis_of U Y.
Proof.
move=> eqXY; congr ((_ == _) && _); last exact: perm_free.
exact/eq_span/perm_mem.
Qed.
Lemma vbasisP U : basis_of U (vbasis U).
Proof.
rewrite /basis_of free_b2mx span_b2mx (sameP eqP (vs2mxP _ _)) !genmxE.
have ->: b2mx (vbasis U) = row_base (vs2mx U).
by apply/row_matrixP=> i; rewrite unlock rowK tnth_mktuple r2vK.
by rewrite row_base_free !eq_row_base submx_refl.
Qed.
Lemma vbasis_mem v U : v \in (vbasis U) -> v \in U.
Proof. exact: basis_mem (vbasisP _). Qed.
Lemma coord_vbasis v U :
v \in U -> v = \sum_(i < \dim U) coord (vbasis U) i v *: (vbasis U)`_i.
Proof. exact: coord_basis (vbasisP U). Qed.
Section BigSumBasis.
Variables (I : finType) (P : pred I) (Xs : I -> seq vT).
Lemma span_bigcat :
(<<\big[cat/[::]]_(i | P i) Xs i>> = \sum_(i | P i) <<Xs i>>)%VS.
Proof. by rewrite (big_morph _ span_cat span_nil). Qed.
Lemma bigcat_free :
directv (\sum_(i | P i) <<Xs i>>) ->
(forall i, P i -> free (Xs i)) -> free (\big[cat/[::]]_(i | P i) Xs i).
Proof.
rewrite /free directvE /= span_bigcat => /directvP-> /= freeXs.
rewrite (big_morph _ (@size_cat _) (erefl _)) /=.
by apply/eqP/eq_bigr=> i /freeXs/eqP.
Qed.
Lemma bigcat_basis Us (U := (\sum_(i | P i) Us i)%VS) :
directv U -> (forall i, P i -> basis_of (Us i) (Xs i)) ->
basis_of U (\big[cat/[::]]_(i | P i) Xs i).
Proof.
move=> dxU XsUs; rewrite /basis_of span_bigcat.
have defUs i: P i -> span (Xs i) = Us i by case/XsUs/andP=> /eqP.
rewrite (eq_bigr _ defUs) eqxx bigcat_free // => [|_ /XsUs/andP[]//].
apply/directvP; rewrite /= (eq_bigr _ defUs) (directvP dxU) /=.
by apply/eq_bigr=> i /defUs->.
Qed.
End BigSumBasis.
End VectorTheory.
#[global] Hint Resolve subvv : core.
Arguments subvP {K vT U V}.
Arguments addv_idPl {K vT U V}.
Arguments addv_idPr {K vT U V}.
Arguments memv_addP {K vT w U V }.
Arguments sumv_sup [K vT I] i0 [P U Vs].
Arguments memv_sumP {K vT I P Us v}.
Arguments subv_sumP {K vT I P Us V}.
Arguments capv_idPl {K vT U V}.
Arguments capv_idPr {K vT U V}.
Arguments memv_capP {K vT w U V}.
Arguments bigcapv_inf [K vT I] i0 [P Us V].
Arguments subv_bigcapP {K vT I P U Vs}.
Arguments directvP {K vT S}.
Arguments directv_addP {K vT U V}.
Arguments directv_add_unique {K vT U V}.
Arguments directv_sumP {K vT I P Us}.
Arguments directv_sumE {K vT I P Ss}.
Arguments directv_sum_independent {K vT I P Us}.
Arguments directv_sum_unique {K vT I P Us}.
Arguments span_subvP {K vT X U}.
Arguments freeP {K vT n X}.
Prenex Implicits coord.
Notation directv S := (directv_def (Phantom _ S%VS)).
(* Linear functions over a vectType *)
Section LfunDefs.
Variable R : nzRingType.
Implicit Types aT vT rT : vectType R.
Fact lfun_key : unit. Proof. by []. Qed.
Definition fun_of_lfun_def aT rT (f : 'Hom(aT, rT)) :=
r2v \o mulmxr (f2mx f) \o v2r.
Definition fun_of_lfun := locked_with lfun_key fun_of_lfun_def.
Canonical fun_of_lfun_unlockable := [unlockable fun fun_of_lfun].
Definition linfun_def aT rT (f : aT -> rT) :=
Hom (lin1_mx (v2r \o f \o r2v)).
Definition linfun := locked_with lfun_key linfun_def.
Canonical linfun_unlockable := [unlockable fun linfun].
Definition id_lfun vT := @linfun vT vT idfun.
Definition comp_lfun aT vT rT (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)) :=
linfun (fun_of_lfun f \o fun_of_lfun g).
End LfunDefs.
Coercion fun_of_lfun : hom >-> Funclass.
Notation "\1" := (@id_lfun _ _) : lfun_scope.
Notation "f \o g" := (comp_lfun f g) : lfun_scope.
Section LfunVspaceDefs.
Variable K : fieldType.
Implicit Types aT rT : vectType K.
Definition inv_lfun aT rT (f : 'Hom(aT, rT)) := Hom (pinvmx (f2mx f)).
Definition lker aT rT (f : 'Hom(aT, rT)) := mx2vs (kermx (f2mx f)).
Fact lfun_img_key : unit. Proof. by []. Qed.
Definition lfun_img_def aT rT f (U : {vspace aT}) : {vspace rT} :=
mx2vs (vs2mx U *m f2mx f).
Definition lfun_img := locked_with lfun_img_key lfun_img_def.
Canonical lfun_img_unlockable := [unlockable fun lfun_img].
Definition lfun_preim aT rT (f : 'Hom(aT, rT)) W :=
(lfun_img (inv_lfun f) (W :&: lfun_img f fullv) + lker f)%VS.
End LfunVspaceDefs.
Prenex Implicits linfun lfun_img lker lfun_preim.
Notation "f ^-1" := (inv_lfun f) : lfun_scope.
Notation "f @: U" := (lfun_img f%VF%R U) (at level 24) : vspace_scope.
Notation "f @^-1: W" := (lfun_preim f%VF%R W) (at level 24) : vspace_scope.
Notation limg f := (lfun_img f fullv).
Section LfunZmodType.
Variables (R : nzRingType) (aT rT : vectType R).
Implicit Types f g h : 'Hom(aT, rT).
HB.instance Definition _ := [Choice of 'Hom(aT, rT) by <:].
Fact lfun_is_linear f : linear f.
Proof. by rewrite unlock; apply: linearP. Qed.
HB.instance Definition _ (f : hom aT rT) := GRing.isSemilinear.Build R aT rT _ f
(GRing.semilinear_linear (lfun_is_linear f)).
Lemma lfunE (ff : {linear aT -> rT}) : linfun ff =1 ff.
Proof. by move=> v; rewrite 2!unlock /= mul_rV_lin1 /= !v2rK. Qed.
Lemma fun_of_lfunK : cancel (@fun_of_lfun R aT rT) linfun.
Proof.
move=> f; apply/val_inj/row_matrixP=> i.
by rewrite 2!unlock /= !rowE mul_rV_lin1 /= !r2vK.
Qed.
Lemma lfunP f g : f =1 g <-> f = g.
Proof.
split=> [eq_fg | -> //]; rewrite -[f]fun_of_lfunK -[g]fun_of_lfunK unlock.
by apply/val_inj/row_matrixP=> i; rewrite !rowE !mul_rV_lin1 /= eq_fg.
Qed.
Definition zero_lfun : 'Hom(aT, rT) := linfun \0.
Definition add_lfun f g := linfun (f \+ g).
Definition opp_lfun f := linfun (-%R \o f).
Fact lfun_addA : associative add_lfun.
Proof. by move=> f g h; apply/lfunP=> v; rewrite !lfunE /= !lfunE addrA. Qed.
Fact lfun_addC : commutative add_lfun.
Proof. by move=> f g; apply/lfunP=> v; rewrite !lfunE /= addrC. Qed.
Fact lfun_add0 : left_id zero_lfun add_lfun.
Proof. by move=> f; apply/lfunP=> v; rewrite lfunE /= lfunE add0r. Qed.
Lemma lfun_addN : left_inverse zero_lfun opp_lfun add_lfun.
Proof. by move=> f; apply/lfunP=> v; rewrite !lfunE /= lfunE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build 'Hom(aT, rT)
lfun_addA lfun_addC lfun_add0 lfun_addN.
Lemma zero_lfunE x : (0 : 'Hom(aT, rT)) x = 0. Proof. exact: lfunE. Qed.
Lemma add_lfunE f g x : (f + g) x = f x + g x. Proof. exact: lfunE. Qed.
Lemma opp_lfunE f x : (- f) x = - f x. Proof. exact: lfunE. Qed.
Lemma sum_lfunE I (r : seq I) (P : pred I) (fs : I -> 'Hom(aT, rT)) x :
(\sum_(i <- r | P i) fs i) x = \sum_(i <- r | P i) fs i x.
Proof. by elim/big_rec2: _ => [|i _ f _ <-]; rewrite lfunE. Qed.
End LfunZmodType.
Arguments fun_of_lfunK {R aT rT}.
Section LfunVectType.
Variables (R : comNzRingType) (aT rT : vectType R).
Implicit Types f : 'Hom(aT, rT).
Definition scale_lfun k f := linfun (k \*: f).
Local Infix "*:l" := scale_lfun (at level 40).
Fact lfun_scaleA k1 k2 f : k1 *:l (k2 *:l f) = (k1 * k2) *:l f.
Proof. by apply/lfunP=> v; rewrite !lfunE /= lfunE scalerA. Qed.
Fact lfun_scale1 f : 1 *:l f = f.
Proof. by apply/lfunP=> v; rewrite lfunE /= scale1r. Qed.
Fact lfun_scaleDr k f1 f2 : k *:l (f1 + f2) = k *:l f1 + k *:l f2.
Proof. by apply/lfunP=> v; rewrite !lfunE /= !lfunE scalerDr. Qed.
Fact lfun_scaleDl f k1 k2 : (k1 + k2) *:l f = k1 *:l f + k2 *:l f.
Proof. by apply/lfunP=> v; rewrite !lfunE /= !lfunE scalerDl. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isLmodule.Build _ 'Hom(aT, rT)
lfun_scaleA lfun_scale1 lfun_scaleDr lfun_scaleDl.
Lemma scale_lfunE k f x : (k *: f) x = k *: f x. Proof. exact: lfunE. Qed.
Fact lfun_vect_iso : Vector.axiom (dim aT * dim rT) 'Hom(aT, rT).
Proof.
exists (mxvec \o f2mx) => [a f g|].
rewrite /= -linearP /= -[A in _ = mxvec A]/(f2mx (Hom _)).
congr (mxvec (f2mx _)); apply/lfunP=> v; do 2!rewrite lfunE /=.
by rewrite unlock /= -linearP mulmxDr scalemxAr.
apply: Bijective (Hom \o vec_mx) _ _ => [[A]|A] /=; last exact: vec_mxK.
by rewrite mxvecK.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build _ 'Hom(aT, rT)
lfun_vect_iso.
End LfunVectType.
Section CompLfun.
Variables (R : nzRingType) (wT aT vT rT : vectType R).
Implicit Types (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)) (h : 'Hom(wT, aT)).
Lemma id_lfunE u: \1%VF u = u :> aT. Proof. exact: lfunE. Qed.
Lemma comp_lfunE f g u : (f \o g)%VF u = f (g u). Proof. exact: lfunE. Qed.
Lemma comp_lfunA f g h : (f \o (g \o h) = (f \o g) \o h)%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfun1l f : (\1 \o f)%VF = f.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfun1r f : (f \o \1)%VF = f.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfun0l g : (0 \o g)%VF = 0 :> 'Hom(aT, rT).
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfun0r f : (f \o 0)%VF = 0 :> 'Hom(aT, rT).
Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linear0. Qed.
Lemma comp_lfunDl f1 f2 g : ((f1 + f2) \o g = (f1 \o g) + (f2 \o g))%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfunDr f g1 g2 : (f \o (g1 + g2) = (f \o g1) + (f \o g2))%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearD. Qed.
Lemma comp_lfunNl f g : ((- f) \o g = - (f \o g))%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfunNr f g : (f \o (- g) = - (f \o g))%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearN. Qed.
End CompLfun.
Definition lfun_simp :=
(comp_lfunE, scale_lfunE, opp_lfunE, add_lfunE, sum_lfunE, lfunE).
Section ScaleCompLfun.
Variables (R : comNzRingType) (aT vT rT : vectType R).
Implicit Types (f : 'Hom(vT, rT)) (g : 'Hom(aT, vT)).
Lemma comp_lfunZl k f g : (k *: (f \o g) = (k *: f) \o g)%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=. Qed.
Lemma comp_lfunZr k f g : (k *: (f \o g) = f \o (k *: g))%VF.
Proof. by apply/lfunP=> u; do !rewrite lfunE /=; rewrite linearZ. Qed.
End ScaleCompLfun.
Section LinearImage.
Variables (K : fieldType) (aT rT : vectType K).
Implicit Types (f g : 'Hom(aT, rT)) (U V : {vspace aT}) (W : {vspace rT}).
Lemma limgS f U V : (U <= V)%VS -> (f @: U <= f @: V)%VS.
Proof. by rewrite unlock /subsetv !genmxE; apply: submxMr. Qed.
Lemma limg_line f v : (f @: <[v]> = <[f v]>)%VS.
Proof.
apply/eqP; rewrite 2!unlock eqEsubv /subsetv /= r2vK !genmxE.
by rewrite !(eqmxMr _ (genmxE _)) submx_refl.
Qed.
Lemma limg0 f : (f @: 0 = 0)%VS. Proof. by rewrite limg_line linear0. Qed.
Lemma memv_img f v U : v \in U -> f v \in (f @: U)%VS.
Proof. by move=> Uv; rewrite memvE -limg_line limgS. Qed.
Lemma memv_imgP f w U :
reflect (exists2 u, u \in U & w = f u) (w \in f @: U)%VS.
Proof.
apply: (iffP idP) => [|[u Uu ->]]; last exact: memv_img.
rewrite 2!unlock memvE /subsetv !genmxE => /submxP[ku Drw].
exists (r2v (ku *m vs2mx U)); last by rewrite /= r2vK -mulmxA -Drw v2rK.
by rewrite memvE /subsetv !genmxE r2vK submxMl.
Qed.
Lemma lim0g U : (0 @: U = 0 :> {vspace rT})%VS.
Proof.
apply/eqP; rewrite -subv0; apply/subvP=> _ /memv_imgP[u _ ->].
by rewrite lfunE rpred0.
Qed.
Lemma eq_in_limg V f g : {in V, f =1 g} -> (f @: V = g @: V)%VS.
Proof.
move=> eq_fg; apply/vspaceP=> y.
by apply/memv_imgP/memv_imgP=> [][x Vx ->]; exists x; rewrite ?eq_fg.
Qed.
Lemma limgD f : {morph lfun_img f : U V / U + V}%VS.
Proof.
move=> U V; apply/eqP; rewrite unlock eqEsubv /subsetv /= -genmx_adds.
by rewrite !genmxE !(eqmxMr _ (genmxE _)) !addsmxMr submx_refl.
Qed.
Lemma limg_sum f I r (P : pred I) Us :
(f @: (\sum_(i <- r | P i) Us i) = \sum_(i <- r | P i) f @: Us i)%VS.
Proof. exact: (big_morph _ (limgD f) (limg0 f)). Qed.
Lemma limg_cap f U V : (f @: (U :&: V) <= f @: U :&: f @: V)%VS.
Proof. by rewrite subv_cap !limgS ?capvSl ?capvSr. Qed.
Lemma limg_bigcap f I r (P : pred I) Us :
(f @: (\bigcap_(i <- r | P i) Us i) <= \bigcap_(i <- r | P i) f @: Us i)%VS.
Proof.
elim/big_rec2: _ => [|i V U _ sUV]; first exact: subvf.
by rewrite (subv_trans (limg_cap f _ U)) ?capvS.
Qed.
Lemma limg_span f X : (f @: <<X>> = <<map f X>>)%VS.
Proof.
by rewrite !span_def big_map limg_sum; apply: eq_bigr => x _; rewrite limg_line.
Qed.
Lemma subset_limgP f U (r : seq rT) :
{subset r <= (f @: U)%VS} <-> (exists2 a, all (mem U) a & r = map f a).
Proof.
split => [|[{}r /allP/= rE ->] _ /mapP[x xr ->]]; last by rewrite memv_img ?rE.
move=> /(_ _ _)/memv_imgP/sig2_eqW-/(all_sig_cond (0 : aT))[f' f'P].
exists (map f' r); first by apply/allP => _ /mapP [x /f'P[? ?] ->].
by symmetry; rewrite -map_comp; apply: map_id_in => x /f'P[].
Qed.
Lemma lfunPn f g : reflect (exists u, f u != g u) (f != g).
Proof.
apply: (iffP idP) => [f'g|[x]]; last by apply: contraNneq => /lfunP->.
suffices /subvPn[_ /memv_imgP[u _ ->]]: ~~ (limg (f - g) <= 0)%VS.
by rewrite lfunE /= lfunE /= memv0 subr_eq0; exists u.
apply: contra f'g => /subvP fg0; apply/eqP/lfunP=> u; apply/eqP.
by rewrite -subr_eq0 -opp_lfunE -add_lfunE -memv0 fg0 ?memv_img ?memvf.
Qed.
Lemma inv_lfun_def f : (f \o f^-1 \o f)%VF = f.
Proof.
apply/lfunP=> u; do !rewrite lfunE /=; rewrite unlock /= !r2vK.
by rewrite mulmxKpV ?submxMl.
Qed.
Lemma limg_lfunVK f : {in limg f, cancel f^-1%VF f}.
Proof. by move=> _ /memv_imgP[u _ ->]; rewrite -!comp_lfunE inv_lfun_def. Qed.
Lemma lkerE f U : (U <= lker f)%VS = (f @: U == 0)%VS.
Proof.
rewrite unlock -dimv_eq0 /dimv /subsetv !genmxE mxrank_eq0.
by rewrite (sameP sub_kermxP eqP).
Qed.
Lemma memv_ker f v : (v \in lker f) = (f v == 0).
Proof. by rewrite -memv0 !memvE subv0 lkerE limg_line. Qed.
Lemma eqlfunP f g v : reflect (f v = g v) (v \in lker (f - g)).
Proof. by rewrite memv_ker !lfun_simp subr_eq0; apply: eqP. Qed.
Lemma eqlfun_inP V f g : reflect {in V, f =1 g} (V <= lker (f - g))%VS.
Proof. by apply: (iffP subvP) => E x /E/eqlfunP. Qed.
Lemma limg_ker_compl f U : (f @: (U :\: lker f) = f @: U)%VS.
Proof.
rewrite -{2}(addv_diff_cap U (lker f)) limgD; apply/esym/addv_idPl.
by rewrite (subv_trans _ (sub0v _)) // subv0 -lkerE capvSr.
Qed.
Lemma limg_ker_dim f U : (\dim (U :&: lker f) + \dim (f @: U) = \dim U)%N.
Proof.
rewrite unlock /dimv /= genmx_cap genmx_id -genmx_cap !genmxE.
by rewrite addnC mxrank_mul_ker.
Qed.
Lemma limg_dim_eq f U : (U :&: lker f = 0)%VS -> \dim (f @: U) = \dim U.
Proof. by rewrite -(limg_ker_dim f U) => ->; rewrite dimv0. Qed.
Lemma limg_basis_of f U X :
(U :&: lker f = 0)%VS -> basis_of U X -> basis_of (f @: U) (map f X).
Proof.
move=> injUf /andP[/eqP defU /eqnP freeX].
by rewrite /basis_of /free size_map -limg_span -freeX defU limg_dim_eq ?eqxx.
Qed.
Lemma lker0P f : reflect (injective f) (lker f == 0%VS).
Proof.
rewrite -subv0; apply: (iffP subvP) => [injf u v eq_fuv | injf u].
apply/eqP; rewrite -subr_eq0 -memv0 injf //.
by rewrite memv_ker linearB /= eq_fuv subrr.
by rewrite memv_ker memv0 -(inj_eq injf) linear0.
Qed.
Lemma limg_ker0 f U V : lker f == 0%VS -> (f @: U <= f @: V)%VS = (U <= V)%VS.
Proof.
move/lker0P=> injf; apply/idP/idP=> [/subvP sfUV | ]; last exact: limgS.
by apply/subvP=> u Uu; have /memv_imgP[v Vv /injf->] := sfUV _ (memv_img f Uu).
Qed.
Lemma eq_limg_ker0 f U V : lker f == 0%VS -> (f @: U == f @: V)%VS = (U == V).
Proof. by move=> injf; rewrite !eqEsubv !limg_ker0. Qed.
Lemma lker0_lfunK f : lker f == 0%VS -> cancel f f^-1%VF.
Proof.
by move/lker0P=> injf u; apply: injf; rewrite limg_lfunVK ?memv_img ?memvf.
Qed.
Lemma lker0_compVf f : lker f == 0%VS -> (f^-1 \o f = \1)%VF.
Proof. by move/lker0_lfunK=> fK; apply/lfunP=> u; rewrite !lfunE /= fK. Qed.
Lemma lker0_img_cap f U V : lker f == 0%VS ->
(f @: (U :&: V) = f @: U :&: f @: V)%VS.
Proof.
move=> kf0; apply/eqP; rewrite eqEsubv limg_cap/=; apply/subvP => x.
rewrite memv_cap => /andP[/memv_imgP[u uU ->]] /memv_imgP[v vV].
by move=> /(lker0P _ kf0) eq_uv; rewrite memv_img// memv_cap uU eq_uv vV.
Qed.
End LinearImage.
Arguments memv_imgP {K aT rT f w U}.
Arguments lfunPn {K aT rT f g}.
Arguments lker0P {K aT rT f}.
Arguments eqlfunP {K aT rT f g v}.
Arguments eqlfun_inP {K aT rT V f g}.
Arguments limg_lfunVK {K aT rT f} [x] f_x.
Section FixedSpace.
Variables (K : fieldType) (vT : vectType K).
Implicit Types (f : 'End(vT)) (U : {vspace vT}).
Definition fixedSpace f : {vspace vT} := lker (f - \1%VF).
Lemma fixedSpaceP f a : reflect (f a = a) (a \in fixedSpace f).
Proof.
by rewrite memv_ker add_lfunE opp_lfunE id_lfunE subr_eq0; apply: eqP.
Qed.
Lemma fixedSpacesP f U : reflect {in U, f =1 id} (U <= fixedSpace f)%VS.
Proof. by apply: (iffP subvP) => cUf x /cUf/fixedSpaceP. Qed.
Lemma fixedSpace_limg f U : (U <= fixedSpace f -> f @: U = U)%VS.
Proof.
move/fixedSpacesP=> cUf; apply/vspaceP=> x.
by apply/memv_imgP/idP=> [[{}x Ux ->] | Ux]; last exists x; rewrite ?cUf.
Qed.
Lemma fixedSpace_id : fixedSpace \1 = {:vT}%VS.
Proof.
by apply/vspaceP=> x; rewrite memvf; apply/fixedSpaceP; rewrite lfunE.
Qed.
End FixedSpace.
Arguments fixedSpaceP {K vT f a}.
Arguments fixedSpacesP {K vT f U}.
Section LinAut.
Variables (K : fieldType) (vT : vectType K) (f : 'End(vT)).
Hypothesis kerf0 : lker f == 0%VS.
Lemma lker0_limgf : limg f = fullv.
Proof.
by apply/eqP; rewrite eqEdim subvf limg_dim_eq //= (eqP kerf0) capv0.
Qed.
Lemma lker0_lfunVK : cancel f^-1%VF f.
Proof. by move=> u; rewrite limg_lfunVK // lker0_limgf memvf. Qed.
Lemma lker0_compfV : (f \o f^-1 = \1)%VF.
Proof. by apply/lfunP=> u; rewrite !lfunE /= lker0_lfunVK. Qed.
Lemma lker0_compVKf aT g : (f \o (f^-1 \o g))%VF = g :> 'Hom(aT, vT).
Proof. by rewrite comp_lfunA lker0_compfV comp_lfun1l. Qed.
Lemma lker0_compKf aT g : (f^-1 \o (f \o g))%VF = g :> 'Hom(aT, vT).
Proof. by rewrite comp_lfunA lker0_compVf ?comp_lfun1l. Qed.
Lemma lker0_compfK rT h : ((h \o f) \o f^-1)%VF = h :> 'Hom(vT, rT).
Proof. by rewrite -comp_lfunA lker0_compfV comp_lfun1r. Qed.
Lemma lker0_compfVK rT h : ((h \o f^-1) \o f)%VF = h :> 'Hom(vT, rT).
Proof. by rewrite -comp_lfunA lker0_compVf ?comp_lfun1r. Qed.
End LinAut.
Section LinearImageComp.
Variables (K : fieldType) (aT vT rT : vectType K).
Implicit Types (f : 'Hom(aT, vT)) (g : 'Hom(vT, rT)) (U : {vspace aT}).
Lemma lim1g U : (\1 @: U)%VS = U.
Proof.
have /andP[/eqP <- _] := vbasisP U; rewrite limg_span map_id_in // => u _.
by rewrite lfunE.
Qed.
Lemma limg_comp f g U : ((g \o f) @: U = g @: (f @: U))%VS.
Proof.
have /andP[/eqP <- _] := vbasisP U; rewrite !limg_span; congr (span _).
by rewrite -map_comp; apply/eq_map => u; rewrite lfunE.
Qed.
End LinearImageComp.
Section LinearPreimage.
Variables (K : fieldType) (aT rT : vectType K).
Implicit Types (f : 'Hom(aT, rT)) (U : {vspace aT}) (V W : {vspace rT}).
Lemma lpreim_cap_limg f W : (f @^-1: (W :&: limg f))%VS = (f @^-1: W)%VS.
Proof. by rewrite /lfun_preim -capvA capvv. Qed.
Lemma lpreim0 f : (f @^-1: 0)%VS = lker f.
Proof. by rewrite /lfun_preim cap0v limg0 add0v. Qed.
Lemma lpreimS f V W : (V <= W)%VS-> (f @^-1: V <= f @^-1: W)%VS.
Proof. by move=> sVW; rewrite addvS // limgS // capvS. Qed.
Lemma lpreimK f W : (W <= limg f)%VS -> (f @: (f @^-1: W))%VS = W.
Proof.
move=> sWf; rewrite limgD (capv_idPl sWf) // -limg_comp.
have /eqP->: (f @: lker f == 0)%VS by rewrite -lkerE.
have /andP[/eqP defW _] := vbasisP W; rewrite addv0 -defW limg_span.
rewrite map_id_in // => x Xx; rewrite lfunE /= limg_lfunVK //.
by apply: span_subvP Xx; rewrite defW.
Qed.
Lemma memv_preim f u W : (f u \in W) = (u \in f @^-1: W)%VS.
Proof.
apply/idP/idP=> [Wfu | /(memv_img f)]; last first.
by rewrite -lpreim_cap_limg lpreimK ?capvSr // => /memv_capP[].
rewrite -[u](addNKr (f^-1%VF (f u))) memv_add ?memv_img //.
by rewrite memv_cap Wfu memv_img ?memvf.
by rewrite memv_ker addrC linearB /= subr_eq0 limg_lfunVK ?memv_img ?memvf.
Qed.
End LinearPreimage.
Arguments lpreimK {K aT rT f} [W] fW.
Section LfunAlgebra.
(* This section is a bit of a place holder: the instances we build here can't *)
(* be canonical because we are missing an interface for proper vectTypes, *)
(* would sit between Vector and Falgebra. For now, we just supply structure *)
(* definitions here and supply actual instances for F-algebras in a submodule *)
(* of the algebra library (there is currently no actual use of the End(vT) *)
(* algebra structure). Also note that the unit ring structure is missing. *)
Variables (R : comNzRingType) (vT : vectType R).
Hypothesis vT_proper : dim vT > 0.
Fact lfun1_neq0 : \1%VF != 0 :> 'End(vT).
Proof.
apply/eqP=> /lfunP/(_ (r2v (const_mx 1))); rewrite !lfunE /= => /(canRL r2vK).
by move=> /rowP/(_ (Ordinal vT_proper))/eqP; rewrite linear0 !mxE oner_eq0.
Qed.
Prenex Implicits comp_lfunA comp_lfun1l comp_lfun1r comp_lfunDl comp_lfunDr.
(* FIXME: as explained above, the following structures should not be declared *
* as canonical, so mixins and structures are built separately, and we *
* don't use HB.instance Definition _ := ... *
* This is ok, but maybe we could introduce an alias *)
Definition lfun_comp_nzRingMixin := GRing.Zmodule_isNzRing.Build 'End(vT)
comp_lfunA comp_lfun1l comp_lfun1r comp_lfunDl comp_lfunDr lfun1_neq0.
#[deprecated(since="mathcomp 2.4.0",
note="Use lfun_comp_nzRingMixin instead.")]
Notation lfun_comp_ringMixin := (lfun_comp_nzRingMixin) (only parsing).
Definition lfun_comp_nzRingType : nzRingType :=
HB.pack 'End(vT) lfun_comp_nzRingMixin.
#[deprecated(since="mathcomp 2.4.0",
note="Use lfun_comp_nzRingType instead.")]
Notation lfun_comp_ringType := (lfun_comp_nzRingType) (only parsing).
(* In the standard endomorphism ring product is categorical composition. *)
Definition lfun_nzRingType : nzRingType := lfun_comp_nzRingType^c.
#[deprecated(since="mathcomp 2.4.0",
note="Use lfun_nzRingType instead.")]
Notation lfun_ringType := (lfun_nzRingType) (only parsing).
Definition lfun_lalgMixin := GRing.Lmodule_isLalgebra.Build R lfun_nzRingType
(fun k x y => comp_lfunZr k y x).
Definition lfun_lalgType : lalgType R :=
HB.pack 'End(vT) lfun_nzRingType lfun_lalgMixin.
Definition lfun_algMixin := GRing.Lalgebra_isAlgebra.Build R lfun_lalgType
(fun k x y => comp_lfunZl k y x).
Definition lfun_algType : algType R :=
HB.pack 'End(vT) lfun_lalgType lfun_algMixin.
End LfunAlgebra.
Section Projection.
Variables (K : fieldType) (vT : vectType K).
Implicit Types U V : {vspace vT}.
Definition daddv_pi U V := Hom (proj_mx (vs2mx U) (vs2mx V)).
Definition projv U := daddv_pi U U^C.
Definition addv_pi1 U V := daddv_pi (U :\: V) V.
Definition addv_pi2 U V := daddv_pi V (U :\: V).
Lemma memv_pi U V w : (daddv_pi U V) w \in U.
Proof. by rewrite unlock memvE /subsetv genmxE /= r2vK proj_mx_sub. Qed.
Lemma memv_proj U w : projv U w \in U. Proof. exact: memv_pi. Qed.
Lemma memv_pi1 U V w : (addv_pi1 U V) w \in U.
Proof. by rewrite (subvP (diffvSl U V)) ?memv_pi. Qed.
Lemma memv_pi2 U V w : (addv_pi2 U V) w \in V. Proof. exact: memv_pi. Qed.
Lemma daddv_pi_id U V u : (U :&: V = 0)%VS -> u \in U -> daddv_pi U V u = u.
Proof.
move/eqP; rewrite -dimv_eq0 memvE /subsetv /dimv !genmxE mxrank_eq0 => /eqP.
by move=> dxUV Uu; rewrite unlock /= proj_mx_id ?v2rK.
Qed.
Lemma daddv_pi_proj U V w (pi := daddv_pi U V) :
(U :&: V = 0)%VS -> pi (pi w) = pi w.
Proof. by move/daddv_pi_id=> -> //; apply: memv_pi. Qed.
Lemma daddv_pi_add U V w :
(U :&: V = 0)%VS -> (w \in U + V)%VS -> daddv_pi U V w + daddv_pi V U w = w.
Proof.
move/eqP; rewrite -dimv_eq0 memvE /subsetv /dimv !genmxE mxrank_eq0 => /eqP.
by move=> dxUW UVw; rewrite unlock /= -linearD /= add_proj_mx ?v2rK.
Qed.
Lemma projv_id U u : u \in U -> projv U u = u.
Proof. exact: daddv_pi_id (capv_compl _). Qed.
Lemma projv_proj U w : projv U (projv U w) = projv U w.
Proof. exact: daddv_pi_proj (capv_compl _). Qed.
Lemma memv_projC U w : w - projv U w \in (U^C)%VS.
Proof.
rewrite -{1}[w](daddv_pi_add (capv_compl U)) ?addv_complf ?memvf //.
by rewrite addrC addKr memv_pi.
Qed.
Lemma limg_proj U : limg (projv U) = U.
Proof.
apply/vspaceP=> u; apply/memv_imgP/idP=> [[u1 _ ->] | ]; first exact: memv_proj.
by exists (projv U u); rewrite ?projv_id ?memv_img ?memvf.
Qed.
Lemma lker_proj U : lker (projv U) = (U^C)%VS.
Proof.
apply/eqP; rewrite eqEdim andbC; apply/andP; split.
by rewrite dimv_compl -(limg_ker_dim (projv U) fullv) limg_proj addnK capfv.
by apply/subvP=> v; rewrite memv_ker -{2}[v]subr0 => /eqP <-; apply: memv_projC.
Qed.
Lemma addv_pi1_proj U V w (pi1 := addv_pi1 U V) : pi1 (pi1 w) = pi1 w.
Proof. by rewrite daddv_pi_proj // capv_diff. Qed.
Lemma addv_pi2_id U V v : v \in V -> addv_pi2 U V v = v.
Proof. by apply: daddv_pi_id; rewrite capvC capv_diff. Qed.
Lemma addv_pi2_proj U V w (pi2 := addv_pi2 U V) : pi2 (pi2 w) = pi2 w.
Proof. by rewrite addv_pi2_id ?memv_pi2. Qed.
Lemma addv_pi1_pi2 U V w :
w \in (U + V)%VS -> addv_pi1 U V w + addv_pi2 U V w = w.
Proof. by rewrite -addv_diff; exact/daddv_pi_add/capv_diff. Qed.
Section Sumv_Pi.
Variables (I : eqType) (r0 : seq I) (P : pred I) (Vs : I -> {vspace vT}).
Let sumv_pi_rec i :=
fix loop r := if r is j :: r1 then
let V1 := (\sum_(k <- r1) Vs k)%VS in
if j == i then addv_pi1 (Vs j) V1 else (loop r1 \o addv_pi2 (Vs j) V1)%VF
else 0.
Notation sumV := (\sum_(i <- r0 | P i) Vs i)%VS.
Definition sumv_pi_for V of V = sumV := fun i => sumv_pi_rec i (filter P r0).
Variables (V : {vspace vT}) (defV : V = sumV).
Lemma memv_sum_pi i v : sumv_pi_for defV i v \in Vs i.
Proof.
rewrite /sumv_pi_for.
elim: (filter P r0) v => [|j r IHr] v /=; first by rewrite lfunE mem0v.
by case: eqP => [->|_]; rewrite ?lfunE ?memv_pi1 /=.
Qed.
Lemma sumv_pi_uniq_sum v :
uniq (filter P r0) -> v \in V ->
\sum_(i <- r0 | P i) sumv_pi_for defV i v = v.
Proof.
rewrite /sumv_pi_for defV -!(big_filter r0 P).
elim: (filter P r0) v => [|i r IHr] v /= => [_ | /andP[r'i /IHr{}IHr]].
by rewrite !big_nil memv0 => /eqP.
rewrite !big_cons eqxx => /addv_pi1_pi2; congr (_ + _ = v).
rewrite -[_ v]IHr ?memv_pi2 //; apply: eq_big_seq => j /=.
by case: eqP => [<- /idPn | _]; rewrite ?lfunE.
Qed.
End Sumv_Pi.
End Projection.
Prenex Implicits daddv_pi projv addv_pi1 addv_pi2.
Notation sumv_pi V := (sumv_pi_for (erefl V)).
Section SumvPi.
Variable (K : fieldType) (vT : vectType K).
Lemma sumv_pi_sum (I : finType) (P : pred I) Vs v (V : {vspace vT})
(defV : V = (\sum_(i | P i) Vs i)%VS) :
v \in V -> \sum_(i | P i) sumv_pi_for defV i v = v :> vT.
Proof. by apply: sumv_pi_uniq_sum; have [e _ []] := big_enumP. Qed.
Lemma sumv_pi_nat_sum m n (P : pred nat) Vs v (V : {vspace vT})
(defV : V = (\sum_(m <= i < n | P i) Vs i)%VS) :
v \in V -> \sum_(m <= i < n | P i) sumv_pi_for defV i v = v :> vT.
Proof. by apply: sumv_pi_uniq_sum; apply/filter_uniq/iota_uniq. Qed.
End SumvPi.
Section SubVector.
(* Turn a {vspace V} into a vectType *)
Variable (K : fieldType) (vT : vectType K) (U : {vspace vT}).
Inductive subvs_of : predArgType := Subvs u & u \in U.
Definition vsval w : vT := let: Subvs u _ := w in u.
HB.instance Definition _ := [isSub of subvs_of for vsval].
HB.instance Definition _ := [Choice of subvs_of by <:].
HB.instance Definition _ := [SubChoice_isSubZmodule of subvs_of by <:].
HB.instance Definition _ := [SubZmodule_isSubLmodule of subvs_of by <:].
Lemma subvsP w : vsval w \in U. Proof. exact: valP. Qed.
Lemma subvs_inj : injective vsval. Proof. exact: val_inj. Qed.
Lemma congr_subvs u v : u = v -> vsval u = vsval v. Proof. exact: congr1. Qed.
Lemma vsval_is_linear : linear vsval. Proof. by []. Qed.
HB.instance Definition _ := GRing.isSemilinear.Build K subvs_of vT _ vsval
(GRing.semilinear_linear vsval_is_linear).
Fact vsproj_key : unit. Proof. by []. Qed.
Definition vsproj_def u := Subvs (memv_proj U u).
Definition vsproj := locked_with vsproj_key vsproj_def.
Canonical vsproj_unlockable := [unlockable fun vsproj].
Lemma vsprojK : {in U, cancel vsproj vsval}.
Proof. by rewrite unlock; apply: projv_id. Qed.
Lemma vsvalK : cancel vsval vsproj.
Proof. by move=> w; apply/val_inj/vsprojK/subvsP. Qed.
Lemma vsproj_is_linear : linear vsproj.
Proof. by move=> k w1 w2; apply: val_inj; rewrite unlock /= linearP. Qed.
HB.instance Definition _ := GRing.isSemilinear.Build K vT subvs_of _ vsproj
(GRing.semilinear_linear vsproj_is_linear).
Fact subvs_vect_iso : Vector.axiom (\dim U) subvs_of.
Proof.
exists (fun w => \row_i coord (vbasis U) i (vsval w)).
by move=> k w1 w2; apply/rowP=> i; rewrite !mxE linearP.
exists (fun rw : 'rV_(\dim U) => vsproj (\sum_i rw 0 i *: (vbasis U)`_i)).
move=> w /=; congr (vsproj _ = w): (vsvalK w).
by rewrite {1}(coord_vbasis (subvsP w)); apply: eq_bigr => i _; rewrite mxE.
move=> rw; apply/rowP=> i; rewrite mxE vsprojK.
by rewrite coord_sum_free ?(basis_free (vbasisP U)).
by apply: rpred_sum => j _; rewrite rpredZ ?vbasis_mem ?memt_nth.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build K subvs_of subvs_vect_iso.
Lemma SubvsE x (xU : x \in U) : Subvs xU = vsproj x.
Proof. by apply/val_inj; rewrite /= vsprojK. Qed.
End SubVector.
Prenex Implicits vsval vsproj vsvalK.
Arguments subvs_inj {K vT U} [x1 x2].
Arguments vsprojK {K vT U} [x] Ux.
Section MatrixVectType.
Variables (R : nzRingType) (m n : nat).
(* The apparently useless => /= in line 1 of the proof performs some evar *)
(* expansions that the Ltac interpretation of exists is incapable of doing. *)
Fact matrix_vect_iso : Vector.axiom (m * n) 'M[R]_(m, n).
Proof.
exists mxvec => /=; first exact: linearP.
by exists vec_mx; [apply: mxvecK | apply: vec_mxK].
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build _ 'M[R]_(m, n) matrix_vect_iso.
Lemma dim_matrix : dim 'M[R]_(m, n) = m * n.
Proof. by []. Qed.
End MatrixVectType.
(* A ring is a one-dimension vector space *)
Section RegularVectType.
Variable R : nzRingType.
Fact regular_vect_iso : Vector.axiom 1 R^o.
Proof.
exists (fun a => a%:M) => [a b c|]; first by rewrite rmorphD scale_scalar_mx.
by exists (fun A : 'M_1 => A 0 0) => [a | A]; rewrite ?mxE // -mx11_scalar.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build _ R^o regular_vect_iso.
End RegularVectType.
(* External direct product of two vectTypes. *)
Section ProdVector.
Variables (R : nzRingType) (vT1 vT2 : vectType R).
Fact pair_vect_iso : Vector.axiom (dim vT1 + dim vT2) (vT1 * vT2).
Proof.
pose p2r (u : vT1 * vT2) := row_mx (v2r u.1) (v2r u.2).
pose r2p w := (r2v (lsubmx w) : vT1, r2v (rsubmx w) : vT2).
have r2pK : cancel r2p p2r by move=> w; rewrite /p2r !r2vK hsubmxK.
have p2rK : cancel p2r r2p by case=> u v; rewrite /r2p row_mxKl row_mxKr !v2rK.
have r2p_lin: linear r2p by move=> a u v; congr (_ , _); rewrite /= !linearP.
pose r2plM := GRing.isLinear.Build _ _ _ _ r2p r2p_lin.
pose r2pL : {linear _ -> _} := HB.pack r2p r2plM.
by exists p2r; [apply: (@can2_linear _ _ _ r2pL) | exists r2p].
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build _ (vT1 * vT2)%type
pair_vect_iso.
End ProdVector.
(* Function from a finType into a ring form a vectype. *)
Section FunVectType.
Variable (I : finType) (R : nzRingType) (vT : vectType R).
(* Type unification with exist is again a problem in this proof. *)
Fact ffun_vect_iso : Vector.axiom (#|I| * dim vT) {ffun I -> vT}.
Proof.
pose fr (f : {ffun I -> vT}) := mxvec (\matrix_(i < #|I|) v2r (f (enum_val i))).
exists fr => /= [k f g|].
rewrite -linearP; congr mxvec; apply/matrixP=> i j.
by rewrite !mxE !ffunE linearP !mxE.
exists (fun r => [ffun i => r2v (row (enum_rank i) (vec_mx r)) : vT]) => [g|r].
by apply/ffunP=> i; rewrite ffunE mxvecK rowK v2rK enum_rankK.
by apply/(canLR vec_mxK)/matrixP=> i j; rewrite mxE ffunE r2vK enum_valK mxE.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build _ {ffun I -> vT}
ffun_vect_iso.
End FunVectType.
(* Solving a tuple of linear equations. *)
Section Solver.
Variable (K : fieldType) (vT : vectType K).
Variables (n : nat) (lhs : n.-tuple 'End(vT)) (rhs : n.-tuple vT).
Let lhsf u := finfun ((tnth lhs)^~ u).
Definition vsolve_eq U := finfun (tnth rhs) \in (linfun lhsf @: U)%VS.
Lemma vsolve_eqP (U : {vspace vT}) :
reflect (exists2 u, u \in U & forall i, tnth lhs i u = tnth rhs i)
(vsolve_eq U).
Proof.
have lhsZ: linear lhsf by move=> a u v; apply/ffunP=> i; rewrite !ffunE linearP.
pose lhslM := GRing.isLinear.Build _ _ _ _ lhsf lhsZ.
pose lhsL : {linear _ -> _} := HB.pack lhsf lhslM.
apply: (iffP memv_imgP) => [] [u Uu sol_u]; exists u => //.
by move=> i; rewrite -[tnth rhs i]ffunE sol_u (lfunE lhsL) ffunE.
by apply/ffunP=> i; rewrite (lfunE lhsL) !ffunE sol_u.
Qed.
End Solver.
Section lfunP.
Variable (F : fieldType).
Context {uT vT : vectType F}.
Local Notation m := (\dim {:uT}).
Local Notation n := (\dim {:vT}).
Lemma span_lfunP (U : seq uT) (phi psi : 'Hom(uT,vT)) :
{in <<U>>%VS, phi =1 psi} <-> {in U, phi =1 psi}.
Proof.
split=> eq_phi_psi u uU; first by rewrite eq_phi_psi ?memv_span.
rewrite [u](@coord_span _ _ _ (in_tuple U))// !linear_sum/=.
by apply: eq_bigr=> i _; rewrite 2!linearZ/= eq_phi_psi// ?mem_nth.
Qed.
Lemma fullv_lfunP (U : seq uT) (phi psi : 'Hom(uT,vT)) : <<U>>%VS = fullv ->
phi = psi <-> {in U, phi =1 psi}.
Proof.
by move=> Uf; split=> [->//|/span_lfunP]; rewrite Uf=> /(_ _ (memvf _))-/lfunP.
Qed.
End lfunP.
Module passmx.
Section passmx.
Variable (F : fieldType).
Section vecmx.
Context {vT : vectType F}.
Local Notation n := (\dim {:vT}).
Variables (e : n.-tuple vT).
Definition rVof (v : vT) := \row_i coord e i v.
Lemma rVof_linear : linear rVof.
Proof. by move=> x v1 v2; apply/rowP=> i; rewrite !mxE linearP. Qed.
HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ rVof
(GRing.semilinear_linear rVof_linear).
Lemma coord_rVof i v : coord e i v = rVof v 0 i.
Proof. by rewrite !mxE. Qed.
Definition vecof (v : 'rV_n) := \sum_i v 0 i *: e`_i.
Lemma vecof_delta i : vecof (delta_mx 0 i) = e`_i.
Proof.
rewrite /vecof (bigD1 i)//= mxE !eqxx scale1r big1 ?addr0// => j neq_ji.
by rewrite mxE (negPf neq_ji) andbF scale0r.
Qed.
Lemma vecof_linear : linear vecof.
Proof.
move=> x v1 v2; rewrite linear_sum -big_split/=.
by apply: eq_bigr => i _/=; rewrite !mxE scalerDl scalerA.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ vecof
(GRing.semilinear_linear vecof_linear).
Variable e_basis : basis_of {:vT} e.
Lemma rVofK : cancel rVof vecof.
Proof.
move=> v; rewrite [v in RHS](coord_basis e_basis) ?memvf//.
by apply: eq_bigr => i; rewrite !mxE.
Qed.
Lemma vecofK : cancel vecof rVof.
Proof.
move=> v; apply/rowP=> i; rewrite !(lfunE, mxE).
by rewrite coord_sum_free ?(basis_free e_basis).
Qed.
Lemma rVofE (i : 'I_n) : rVof e`_i = delta_mx 0 i.
Proof.
apply/rowP=> k; rewrite !mxE.
by rewrite eqxx coord_free ?(basis_free e_basis)// eq_sym.
Qed.
Lemma coord_vecof i v : coord e i (vecof v) = v 0 i.
Proof. by rewrite coord_rVof vecofK. Qed.
Lemma rVof_eq0 v : (rVof v == 0) = (v == 0).
Proof. by rewrite -(inj_eq (can_inj vecofK)) rVofK linear0. Qed.
Lemma vecof_eq0 v : (vecof v == 0) = (v == 0).
Proof. by rewrite -(inj_eq (can_inj rVofK)) vecofK linear0. Qed.
End vecmx.
Section hommx.
Context {uT vT : vectType F}.
Local Notation m := (\dim {:uT}).
Local Notation n := (\dim {:vT}).
Variables (e : m.-tuple uT) (e' : n.-tuple vT).
Definition mxof (h : 'Hom(uT, vT)) := lin1_mx (rVof e' \o h \o vecof e).
Lemma mxof_linear : linear mxof.
Proof.
move=> x h1 h2; apply/matrixP=> i j; do !rewrite ?lfunE/= ?mxE.
by rewrite linearP.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build F _ _ _ mxof
(GRing.semilinear_linear mxof_linear).
Definition funmx (M : 'M[F]_(m, n)) u := vecof e' (rVof e u *m M).
Lemma funmx_linear M : linear (funmx M).
Proof.
by rewrite /funmx => x u v; rewrite linearP mulmxDl -scalemxAl linearP.
Qed.
HB.instance Definition _ M := GRing.isSemilinear.Build F _ _ _ (funmx M)
(GRing.semilinear_linear (funmx_linear M)).
Definition hommx M : 'Hom(uT, vT) := linfun (funmx M).
Lemma hommx_linear : linear hommx.
Proof.
rewrite /hommx; move=> x A B; apply/lfunP=> u; do !rewrite lfunE/=.
by rewrite /funmx mulmxDr -scalemxAr linearP.
Qed.
HB.instance Definition _ M := GRing.isSemilinear.Build F _ _ _ hommx
(GRing.semilinear_linear hommx_linear).
Hypothesis e_basis: basis_of {:uT} e.
Hypothesis f_basis: basis_of {:vT} e'.
Lemma mxofK : cancel mxof hommx.
Proof.
by move=> h; apply/lfunP=> u; rewrite lfunE/= /funmx mul_rV_lin1/= !rVofK.
Qed.
Lemma hommxK : cancel hommx mxof.
Proof.
move=> M; apply/matrixP => i j; rewrite !mxE/= lfunE/=.
by rewrite /funmx vecofK// -rowE coord_vecof// mxE.
Qed.
Lemma mul_mxof phi u : u *m mxof phi = rVof e' (phi (vecof e u)).
Proof. by rewrite mul_rV_lin1/=. Qed.
Lemma hommxE M u : hommx M u = vecof e' (rVof e u *m M).
Proof. by rewrite -[M in RHS]hommxK mul_mxof !rVofK//. Qed.
Lemma rVof_mul M u : rVof e u *m M = rVof e' (hommx M u).
Proof. by rewrite hommxE vecofK. Qed.
Lemma hom_vecof (phi : 'Hom(uT, vT)) u :
phi (vecof e u) = vecof e' (u *m mxof phi).
Proof. by rewrite mul_mxof rVofK. Qed.
Lemma rVof_app (phi : 'Hom(uT, vT)) u :
rVof e' (phi u) = rVof e u *m mxof phi.
Proof. by rewrite mul_mxof !rVofK. Qed.
Lemma vecof_mul M u : vecof e' (u *m M) = hommx M (vecof e u).
Proof. by rewrite hommxE vecofK. Qed.
Lemma mxof_eq0 phi : (mxof phi == 0) = (phi == 0).
Proof. by rewrite -(inj_eq (can_inj hommxK)) mxofK linear0. Qed.
Lemma hommx_eq0 M : (hommx M == 0) = (M == 0).
Proof. by rewrite -(inj_eq (can_inj mxofK)) hommxK linear0. Qed.
End hommx.
Section hommx_comp.
Context {uT vT wT : vectType F}.
Local Notation m := (\dim {:uT}).
Local Notation n := (\dim {:vT}).
Local Notation p := (\dim {:wT}).
Variables (e : m.-tuple uT) (f : n.-tuple vT) (g : p.-tuple wT).
Hypothesis e_basis: basis_of {:uT} e.
Hypothesis f_basis: basis_of {:vT} f.
Hypothesis g_basis: basis_of {:wT} g.
Lemma mxof_comp (phi : 'Hom(uT, vT)) (psi : 'Hom(vT, wT)) :
mxof e g (psi \o phi)%VF = mxof e f phi *m mxof f g psi.
Proof.
apply/matrixP => i k; rewrite !(mxE, comp_lfunE, lfunE) /=.
rewrite [phi _](coord_basis f_basis) ?memvf// 2!linear_sum/=.
by apply: eq_bigr => j _ /=; rewrite !mxE !linearZ/= !vecof_delta.
Qed.
Lemma hommx_mul (A : 'M_(m,n)) (B : 'M_(n, p)) :
hommx e g (A *m B) = (hommx f g B \o hommx e f A)%VF.
Proof.
by apply: (can_inj (mxofK e_basis g_basis)); rewrite mxof_comp !hommxK.
Qed.
End hommx_comp.
Section vsms.
Context {vT : vectType F}.
Local Notation n := (\dim {:vT}).
Variables (e : n.-tuple vT).
Definition msof (V : {vspace vT}) : 'M_n := mxof e e (projv V).
(* alternative *)
(* (\sum_(v <- vbasis V) <<rVof e v>>)%MS. *)
Definition vsof (M : 'M[F]_n) := limg (hommx e e M).
(* alternative *)
(* <<[seq vecof e (row i M) | i : 'I_n]>>%VS. *)
Lemma mxof1 : free e -> mxof e e \1 = 1%:M.
Proof.
by move=> eF; apply/matrixP=> i j; rewrite !mxE vecof_delta lfunE coord_free.
Qed.
Hypothesis e_basis : basis_of {:vT} e.
Lemma hommx1 : hommx e e 1%:M = \1%VF.
Proof. by rewrite -mxof1 ?(basis_free e_basis)// mxofK. Qed.
Lemma msofK : cancel msof vsof.
Proof. by rewrite /msof /vsof; move=> V; rewrite mxofK// limg_proj. Qed.
Lemma mem_vecof u (V : {vspace vT}) : (vecof e u \in V) = (u <= msof V)%MS.
Proof.
apply/idP/submxP=> [|[v ->{u}]]; last by rewrite -hom_vecof// memv_proj.
rewrite -[V in X in X -> _]msofK => /memv_imgP[v _].
by move=> /(canRL (vecofK _)) ->//; rewrite -rVof_mul//; eexists.
Qed.
Lemma rVof_sub u M : (rVof e u <= M)%MS = (u \in vsof M).
Proof.
apply/submxP/memv_imgP => [[v /(canRL (rVofK _)) ->//]|[v _ ->]]{u}.
by exists (vecof e v); rewrite ?memvf// -vecof_mul.
by exists (rVof e v); rewrite -rVof_mul.
Qed.
Lemma vsof_sub M V : (vsof M <= V)%VS = (M <= msof V)%MS.
Proof.
apply/subvP/rV_subP => [MsubV _/submxP[u ->]|VsubM _/memv_imgP[u _ ->]].
by rewrite -mem_vecof MsubV// -rVof_sub vecofK// submxMl.
by rewrite -[V]msofK -rVof_sub VsubM// -rVof_mul// submxMl.
Qed.
Lemma msof_sub V M : (msof V <= M)%MS = (V <= vsof M)%VS.
Proof.
apply/rV_subP/subvP => [VsubM v vV|MsubV _/submxP[u ->]].
by rewrite -rVof_sub VsubM// -mem_vecof rVofK.
by rewrite mul_mxof rVof_sub MsubV// memv_proj.
Qed.
Lemma vsofK M : (msof (vsof M) == M)%MS.
Proof. by rewrite msof_sub -vsof_sub subvv. Qed.
Lemma sub_msof : {mono msof : V V' / (V <= V')%VS >-> (V <= V')%MS}.
Proof. by move=> V V'; rewrite msof_sub msofK. Qed.
Lemma sub_vsof : {mono vsof : M M' / (M <= M')%MS >-> (M <= M')%VS}.
Proof. by move=> M M'; rewrite vsof_sub (eqmxP (vsofK _)). Qed.
Lemma msof0 : msof 0 = 0.
Proof.
apply/eqP; rewrite -submx0; apply/rV_subP => v.
by rewrite -mem_vecof memv0 vecof_eq0// => /eqP->; rewrite sub0mx.
Qed.
Lemma vsof0 : vsof 0 = 0%VS.
Proof. by apply/vspaceP=> v; rewrite memv0 -rVof_sub submx0 rVof_eq0. Qed.
Lemma msof_eq0 V : (msof V == 0) = (V == 0%VS).
Proof. by rewrite -(inj_eq (can_inj msofK)) msof0. Qed.
Lemma vsof_eq0 M : (vsof M == 0%VS) = (M == 0).
Proof.
rewrite (sameP eqP eqmx0P) -!(eqmxP (vsofK M)) (sameP eqmx0P eqP) -msof0.
by rewrite (inj_eq (can_inj msofK)).
Qed.
End vsms.
Section eigen.
Context {uT : vectType F}.
Definition leigenspace (phi : 'End(uT)) a := lker (phi - a *: \1%VF).
Definition leigenvalue phi a := leigenspace phi a != 0%VS.
Local Notation m := (\dim {:uT}).
Variables (e : m.-tuple uT).
Hypothesis e_basis: basis_of {:uT} e.
Let e_free := basis_free e_basis.
Lemma lker_ker phi : lker phi = vsof e (kermx (mxof e e phi)).
Proof.
apply/vspaceP => v; rewrite memv_ker -rVof_sub// (sameP sub_kermxP eqP).
by rewrite -rVof_app// rVof_eq0.
Qed.
Lemma limgE phi : limg phi = vsof e (mxof e e phi).
Proof.
apply/vspaceP => v; rewrite -rVof_sub//.
apply/memv_imgP/submxP => [[u _ ->]|[u /(canRL (rVofK _)) ->//]].
by exists (rVof e u); rewrite -rVof_app.
by exists (vecof e u); rewrite ?memvf// -hom_vecof.
Qed.
Lemma leigenspaceE f a : leigenspace f a = vsof e (eigenspace (mxof e e f) a).
Proof. by rewrite [LHS]lker_ker linearB linearZ/= mxof1// scalemx1. Qed.
End eigen.
End passmx.
End passmx.
|
cyclotomic.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
PullbackCone.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Markus Himmel, Bhavik Mehta, Andrew Yang, Emily Riehl, Calle Sönne
-/
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Cospan
/-!
# PullbackCone
This file provides API for interacting with cones (resp. cocones) in the case of pullbacks
(resp. pushouts).
# Main definitions
* `PullbackCone f g`: Given morphisms `f : X ⟶ Z` and `g : Y ⟶ Z`, a term `t : PullbackCone f g`
provides the data of a cone pictured as follows
```
t.pt ---t.snd---> Y
| |
t.fst g
| |
v v
X -----f------> Z
```
The type `PullbackCone f g` is implemented as an abbreviation for `Cone (cospan f g)`, so general
results about cones are also available for `PullbackCone f g`.
* `PushoutCone f g`: Given morphisms `f : X ⟶ Y` and `g : X ⟶ Z`, a term `t : PushoutCone f g`
provides the data of a cocone pictured as follows
```
X -----f------> Y
| |
g t.inr
| |
v v
Z ---t.inl---> t.pt
```
Similar to `PullbackCone`, `PushoutCone f g` is implemented as an abbreviation for
`Cocone (span f g)`, so general results about cocones are also available for `PushoutCone f g`.
## API
We summarize the most important parts of the API for pullback cones here. The dual notions for
pushout cones is also available in this file.
Various ways of constructing pullback cones:
* `PullbackCone.mk` constructs a term of `PullbackCone f g` given morphisms `fst` and `snd` such
that `fst ≫ f = snd ≫ g`.
* `PullbackCone.flip` is the `PullbackCone` obtained by flipping `fst` and `snd`.
Interaction with `IsLimit`:
* `PullbackCone.isLimitAux` and `PullbackCone.isLimitAux'` provide two convenient ways to show that
a given `PullbackCone` is a limit cone.
* `PullbackCone.isLimit.mk` provides a convenient way to show that a `PullbackCone` constructed
using `PullbackCone.mk` is a limit cone.
* `PullbackCone.IsLimit.lift` and `PullbackCone.IsLimit.lift'` provides convenient ways for
constructing the morphisms to the point of a limit `PullbackCone` from the universal property.
* `PullbackCone.IsLimit.hom_ext` provides a convenient way to show that two morphisms to the point
of a limit `PullbackCone` are equal.
## References
* [Stacks: Fibre products](https://stacks.math.columbia.edu/tag/001U)
* [Stacks: Pushouts](https://stacks.math.columbia.edu/tag/0025)
-/
noncomputable section
open CategoryTheory
universe w v₁ v₂ v u u₂
namespace CategoryTheory.Limits
open WalkingSpan.Hom WalkingCospan.Hom WidePullbackShape.Hom WidePushoutShape.Hom
variable {C : Type u} [Category.{v} C] {W X Y Z : C}
/-- A pullback cone is just a cone on the cospan formed by two morphisms `f : X ⟶ Z` and
`g : Y ⟶ Z`. -/
abbrev PullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) :=
Cone (cospan f g)
namespace PullbackCone
variable {f : X ⟶ Z} {g : Y ⟶ Z}
/-- The first projection of a pullback cone. -/
abbrev fst (t : PullbackCone f g) : t.pt ⟶ X :=
t.π.app WalkingCospan.left
/-- The second projection of a pullback cone. -/
abbrev snd (t : PullbackCone f g) : t.pt ⟶ Y :=
t.π.app WalkingCospan.right
theorem π_app_left (c : PullbackCone f g) : c.π.app WalkingCospan.left = c.fst := rfl
theorem π_app_right (c : PullbackCone f g) : c.π.app WalkingCospan.right = c.snd := rfl
@[simp]
theorem condition_one (t : PullbackCone f g) : t.π.app WalkingCospan.one = t.fst ≫ f := by
have w := t.π.naturality WalkingCospan.Hom.inl
dsimp at w; simpa using w
/-- A pullback cone on `f` and `g` is determined by morphisms `fst : W ⟶ X` and `snd : W ⟶ Y`
such that `fst ≫ f = snd ≫ g`. -/
@[simps]
def mk {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) : PullbackCone f g where
pt := W
π := { app := fun j => Option.casesOn j (fst ≫ f) fun j' => WalkingPair.casesOn j' fst snd
naturality := by rintro (⟨⟩ | ⟨⟨⟩⟩) (⟨⟩ | ⟨⟨⟩⟩) j <;> cases j <;> simp [eq] }
@[simp]
theorem mk_π_app_left {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app WalkingCospan.left = fst := rfl
@[simp]
theorem mk_π_app_right {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app WalkingCospan.right = snd := rfl
@[simp]
theorem mk_π_app_one {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).π.app WalkingCospan.one = fst ≫ f := rfl
@[simp]
theorem mk_fst {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).fst = fst := rfl
@[simp]
theorem mk_snd {W : C} (fst : W ⟶ X) (snd : W ⟶ Y) (eq : fst ≫ f = snd ≫ g) :
(mk fst snd eq).snd = snd := rfl
@[reassoc]
theorem condition (t : PullbackCone f g) : fst t ≫ f = snd t ≫ g :=
(t.w inl).trans (t.w inr).symm
/-- To check whether two morphisms are equalized by the maps of a pullback cone, it suffices to
check it for `fst t` and `snd t` -/
theorem equalizer_ext (t : PullbackCone f g) {W : C} {k l : W ⟶ t.pt} (h₀ : k ≫ fst t = l ≫ fst t)
(h₁ : k ≫ snd t = l ≫ snd t) : ∀ j : WalkingCospan, k ≫ t.π.app j = l ≫ t.π.app j
| some WalkingPair.left => h₀
| some WalkingPair.right => h₁
| none => by rw [← t.w inl, reassoc_of% h₀]
/-- To construct an isomorphism of pullback cones, it suffices to construct an isomorphism
of the cone points and check it commutes with `fst` and `snd`. -/
def ext {s t : PullbackCone f g} (i : s.pt ≅ t.pt) (w₁ : s.fst = i.hom ≫ t.fst := by cat_disch)
(w₂ : s.snd = i.hom ≫ t.snd := by cat_disch) : s ≅ t :=
WalkingCospan.ext i w₁ w₂
/-- The natural isomorphism between a pullback cone and the corresponding pullback cone
reconstructed using `PullbackCone.mk`. -/
@[simps!]
def eta (t : PullbackCone f g) : t ≅ mk t.fst t.snd t.condition :=
PullbackCone.ext (Iso.refl _)
/-- This is a slightly more convenient method to verify that a pullback cone is a limit cone. It
only asks for a proof of facts that carry any mathematical content -/
def isLimitAux (t : PullbackCone f g) (lift : ∀ s : PullbackCone f g, s.pt ⟶ t.pt)
(fac_left : ∀ s : PullbackCone f g, lift s ≫ t.fst = s.fst)
(fac_right : ∀ s : PullbackCone f g, lift s ≫ t.snd = s.snd)
(uniq : ∀ (s : PullbackCone f g) (m : s.pt ⟶ t.pt)
(_ : ∀ j : WalkingCospan, m ≫ t.π.app j = s.π.app j), m = lift s) : IsLimit t :=
{ lift
fac := fun s j => Option.casesOn j (by
rw [← s.w inl, ← t.w inl, ← Category.assoc]
congr
exact fac_left s)
fun j' => WalkingPair.casesOn j' (fac_left s) (fac_right s)
uniq := uniq }
/-- This is another convenient method to verify that a pullback cone is a limit cone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def isLimitAux' (t : PullbackCone f g)
(create :
∀ s : PullbackCone f g,
{ l //
l ≫ t.fst = s.fst ∧
l ≫ t.snd = s.snd ∧ ∀ {m}, m ≫ t.fst = s.fst → m ≫ t.snd = s.snd → m = l }) :
Limits.IsLimit t :=
PullbackCone.isLimitAux t (fun s => (create s).1) (fun s => (create s).2.1)
(fun s => (create s).2.2.1) fun s _ w =>
(create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right)
/-- This is a more convenient formulation to show that a `PullbackCone` constructed using
`PullbackCone.mk` is a limit cone.
-/
def IsLimit.mk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (eq : fst ≫ f = snd ≫ g)
(lift : ∀ s : PullbackCone f g, s.pt ⟶ W)
(fac_left : ∀ s : PullbackCone f g, lift s ≫ fst = s.fst)
(fac_right : ∀ s : PullbackCone f g, lift s ≫ snd = s.snd)
(uniq :
∀ (s : PullbackCone f g) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd),
m = lift s) :
IsLimit (mk fst snd eq) :=
isLimitAux _ lift fac_left fac_right fun s m w =>
uniq s m (w WalkingCospan.left) (w WalkingCospan.right)
theorem IsLimit.hom_ext {t : PullbackCone f g} (ht : IsLimit t) {W : C} {k l : W ⟶ t.pt}
(h₀ : k ≫ fst t = l ≫ fst t) (h₁ : k ≫ snd t = l ≫ snd t) : k = l :=
ht.hom_ext <| equalizer_ext _ h₀ h₁
-- Porting note: `IsLimit.lift` and the two following simp lemmas were introduced to ease the port
/-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that
`h ≫ f = k ≫ g`, then we get `l : W ⟶ t.pt`, which satisfies `l ≫ fst t = h`
and `l ≫ snd t = k`, see `IsLimit.lift_fst` and `IsLimit.lift_snd`. -/
def IsLimit.lift {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y)
(w : h ≫ f = k ≫ g) : W ⟶ t.pt :=
ht.lift <| PullbackCone.mk _ _ w
@[reassoc (attr := simp)]
lemma IsLimit.lift_fst {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y)
(w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ fst t = h := ht.fac _ _
@[reassoc (attr := simp)]
lemma IsLimit.lift_snd {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y)
(w : h ≫ f = k ≫ g) : IsLimit.lift ht h k w ≫ snd t = k := ht.fac _ _
/-- If `t` is a limit pullback cone over `f` and `g` and `h : W ⟶ X` and `k : W ⟶ Y` are such that
`h ≫ f = k ≫ g`, then we have `l : W ⟶ t.pt` satisfying `l ≫ fst t = h` and `l ≫ snd t = k`.
-/
def IsLimit.lift' {t : PullbackCone f g} (ht : IsLimit t) {W : C} (h : W ⟶ X) (k : W ⟶ Y)
(w : h ≫ f = k ≫ g) : { l : W ⟶ t.pt // l ≫ fst t = h ∧ l ≫ snd t = k } :=
⟨IsLimit.lift ht h k w, by simp⟩
/-- The pullback cone reconstructed using `PullbackCone.mk` from a pullback cone that is a
limit, is also a limit. -/
def mkSelfIsLimit {t : PullbackCone f g} (ht : IsLimit t) : IsLimit (mk t.fst t.snd t.condition) :=
IsLimit.ofIsoLimit ht (eta t)
section Flip
variable (t : PullbackCone f g)
/-- The pullback cone obtained by flipping `fst` and `snd`. -/
def flip : PullbackCone g f := PullbackCone.mk _ _ t.condition.symm
@[simp] lemma flip_pt : t.flip.pt = t.pt := rfl
@[simp] lemma flip_fst : t.flip.fst = t.snd := rfl
@[simp] lemma flip_snd : t.flip.snd = t.fst := rfl
/-- Flipping a pullback cone twice gives an isomorphic cone. -/
def flipFlipIso : t.flip.flip ≅ t := PullbackCone.ext (Iso.refl _) (by simp) (by simp)
variable {t}
/-- The flip of a pullback square is a pullback square. -/
def flipIsLimit (ht : IsLimit t) : IsLimit t.flip :=
IsLimit.mk _ (fun s => ht.lift s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by
apply IsLimit.hom_ext ht <;> simp [h₁, h₂])
/-- A square is a pullback square if its flip is. -/
def isLimitOfFlip (ht : IsLimit t.flip) : IsLimit t :=
IsLimit.ofIsoLimit (flipIsLimit ht) t.flipFlipIso
end Flip
end PullbackCone
/-- This is a helper construction that can be useful when verifying that a category has all
pullbacks. Given `F : WalkingCospan ⥤ C`, which is really the same as
`cospan (F.map inl) (F.map inr)`, and a pullback cone on `F.map inl` and `F.map inr`, we
get a cone on `F`.
If you're thinking about using this, have a look at `hasPullbacks_of_hasLimit_cospan`,
which you may find to be an easier way of achieving your goal. -/
@[simps]
def Cone.ofPullbackCone {F : WalkingCospan ⥤ C} (t : PullbackCone (F.map inl) (F.map inr)) :
Cone F where
pt := t.pt
π := t.π ≫ (diagramIsoCospan F).inv
/-- Given `F : WalkingCospan ⥤ C`, which is really the same as `cospan (F.map inl) (F.map inr)`,
and a cone on `F`, we get a pullback cone on `F.map inl` and `F.map inr`. -/
@[simps]
def PullbackCone.ofCone {F : WalkingCospan ⥤ C} (t : Cone F) :
PullbackCone (F.map inl) (F.map inr) where
pt := t.pt
π := t.π ≫ (diagramIsoCospan F).hom
/-- A diagram `WalkingCospan ⥤ C` is isomorphic to some `PullbackCone.mk` after
composing with `diagramIsoCospan`. -/
@[simps!]
def PullbackCone.isoMk {F : WalkingCospan ⥤ C} (t : Cone F) :
(Cones.postcompose (diagramIsoCospan.{v} _).hom).obj t ≅
PullbackCone.mk (t.π.app WalkingCospan.left) (t.π.app WalkingCospan.right)
((t.π.naturality inl).symm.trans (t.π.naturality inr :)) :=
Cones.ext (Iso.refl _) <| by
rintro (_ | (_ | _)) <;> simp
/-- A pushout cocone is just a cocone on the span formed by two morphisms `f : X ⟶ Y` and
`g : X ⟶ Z`. -/
abbrev PushoutCocone (f : X ⟶ Y) (g : X ⟶ Z) :=
Cocone (span f g)
namespace PushoutCocone
variable {f : X ⟶ Y} {g : X ⟶ Z}
/-- The first inclusion of a pushout cocone. -/
abbrev inl (t : PushoutCocone f g) : Y ⟶ t.pt :=
t.ι.app WalkingSpan.left
/-- The second inclusion of a pushout cocone. -/
abbrev inr (t : PushoutCocone f g) : Z ⟶ t.pt :=
t.ι.app WalkingSpan.right
@[simp]
theorem ι_app_left (c : PushoutCocone f g) : c.ι.app WalkingSpan.left = c.inl := rfl
@[simp]
theorem ι_app_right (c : PushoutCocone f g) : c.ι.app WalkingSpan.right = c.inr := rfl
@[simp]
theorem condition_zero (t : PushoutCocone f g) : t.ι.app WalkingSpan.zero = f ≫ t.inl := by
have w := t.ι.naturality WalkingSpan.Hom.fst
dsimp at w; simpa using w.symm
/-- A pushout cocone on `f` and `g` is determined by morphisms `inl : Y ⟶ W` and `inr : Z ⟶ W` such
that `f ≫ inl = g ↠ inr`. -/
@[simps]
def mk {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) : PushoutCocone f g where
pt := W
ι := { app := fun j => Option.casesOn j (f ≫ inl) fun j' => WalkingPair.casesOn j' inl inr
naturality := by
rintro (⟨⟩|⟨⟨⟩⟩) (⟨⟩|⟨⟨⟩⟩) <;> intro f <;> cases f <;> dsimp <;> aesop }
@[simp]
theorem mk_ι_app_left {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app WalkingSpan.left = inl := rfl
@[simp]
theorem mk_ι_app_right {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app WalkingSpan.right = inr := rfl
@[simp]
theorem mk_ι_app_zero {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).ι.app WalkingSpan.zero = f ≫ inl := rfl
@[simp]
theorem mk_inl {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).inl = inl := rfl
@[simp]
theorem mk_inr {W : C} (inl : Y ⟶ W) (inr : Z ⟶ W) (eq : f ≫ inl = g ≫ inr) :
(mk inl inr eq).inr = inr := rfl
@[reassoc]
theorem condition (t : PushoutCocone f g) : f ≫ inl t = g ≫ inr t :=
(t.w fst).trans (t.w snd).symm
/-- To check whether a morphism is coequalized by the maps of a pushout cocone, it suffices to check
it for `inl t` and `inr t` -/
theorem coequalizer_ext (t : PushoutCocone f g) {W : C} {k l : t.pt ⟶ W}
(h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) :
∀ j : WalkingSpan, t.ι.app j ≫ k = t.ι.app j ≫ l
| some WalkingPair.left => h₀
| some WalkingPair.right => h₁
| none => by rw [← t.w fst, Category.assoc, Category.assoc, h₀]
/-- To construct an isomorphism of pushout cocones, it suffices to construct an isomorphism
of the cocone points and check it commutes with `inl` and `inr`. -/
def ext {s t : PushoutCocone f g} (i : s.pt ≅ t.pt) (w₁ : s.inl ≫ i.hom = t.inl := by cat_disch)
(w₂ : s.inr ≫ i.hom = t.inr := by cat_disch) : s ≅ t :=
WalkingSpan.ext i w₁ w₂
/-- The natural isomorphism between a pushout cocone and the corresponding pushout cocone
reconstructed using `PushoutCocone.mk`. -/
@[simps!]
def eta (t : PushoutCocone f g) : t ≅ mk t.inl t.inr t.condition :=
PushoutCocone.ext (Iso.refl _)
/-- This is a slightly more convenient method to verify that a pushout cocone is a colimit cocone.
It only asks for a proof of facts that carry any mathematical content -/
def isColimitAux (t : PushoutCocone f g) (desc : ∀ s : PushoutCocone f g, t.pt ⟶ s.pt)
(fac_left : ∀ s : PushoutCocone f g, t.inl ≫ desc s = s.inl)
(fac_right : ∀ s : PushoutCocone f g, t.inr ≫ desc s = s.inr)
(uniq : ∀ (s : PushoutCocone f g) (m : t.pt ⟶ s.pt)
(_ : ∀ j : WalkingSpan, t.ι.app j ≫ m = s.ι.app j), m = desc s) : IsColimit t :=
{ desc
fac := fun s j =>
Option.casesOn j (by simp [← s.w fst, ← t.w fst, fac_left s]) fun j' =>
WalkingPair.casesOn j' (fac_left s) (fac_right s)
uniq := uniq }
/-- This is another convenient method to verify that a pushout cocone is a colimit cocone. It
only asks for a proof of facts that carry any mathematical content, and allows access to the
same `s` for all parts. -/
def isColimitAux' (t : PushoutCocone f g)
(create :
∀ s : PushoutCocone f g,
{ l //
t.inl ≫ l = s.inl ∧
t.inr ≫ l = s.inr ∧ ∀ {m}, t.inl ≫ m = s.inl → t.inr ≫ m = s.inr → m = l }) :
IsColimit t :=
isColimitAux t (fun s => (create s).1) (fun s => (create s).2.1) (fun s => (create s).2.2.1)
fun s _ w => (create s).2.2.2 (w WalkingCospan.left) (w WalkingCospan.right)
theorem IsColimit.hom_ext {t : PushoutCocone f g} (ht : IsColimit t) {W : C} {k l : t.pt ⟶ W}
(h₀ : inl t ≫ k = inl t ≫ l) (h₁ : inr t ≫ k = inr t ≫ l) : k = l :=
ht.hom_ext <| coequalizer_ext _ h₀ h₁
-- Porting note: `IsColimit.desc` and the two following simp lemmas were introduced to ease the port
/-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are
morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that
`inl t ≫ l = h` and `inr t ≫ l = k`, see `IsColimit.inl_desc` and `IsColimit.inr_desc`. -/
def IsColimit.desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W)
(w : f ≫ h = g ≫ k) : t.pt ⟶ W :=
ht.desc (PushoutCocone.mk _ _ w)
@[reassoc (attr := simp)]
lemma IsColimit.inl_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W)
(w : f ≫ h = g ≫ k) : inl t ≫ IsColimit.desc ht h k w = h :=
ht.fac _ _
@[reassoc (attr := simp)]
lemma IsColimit.inr_desc {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W)
(w : f ≫ h = g ≫ k) : inr t ≫ IsColimit.desc ht h k w = k :=
ht.fac _ _
/-- If `t` is a colimit pushout cocone over `f` and `g` and `h : Y ⟶ W` and `k : Z ⟶ W` are
morphisms satisfying `f ≫ h = g ≫ k`, then we have a factorization `l : t.pt ⟶ W` such that
`inl t ≫ l = h` and `inr t ≫ l = k`. -/
def IsColimit.desc' {t : PushoutCocone f g} (ht : IsColimit t) {W : C} (h : Y ⟶ W) (k : Z ⟶ W)
(w : f ≫ h = g ≫ k) : { l : t.pt ⟶ W // inl t ≫ l = h ∧ inr t ≫ l = k } :=
⟨IsColimit.desc ht h k w, by simp⟩
/-- This is a more convenient formulation to show that a `PushoutCocone` constructed using
`PushoutCocone.mk` is a colimit cocone.
-/
def IsColimit.mk {W : C} {inl : Y ⟶ W} {inr : Z ⟶ W} (eq : f ≫ inl = g ≫ inr)
(desc : ∀ s : PushoutCocone f g, W ⟶ s.pt)
(fac_left : ∀ s : PushoutCocone f g, inl ≫ desc s = s.inl)
(fac_right : ∀ s : PushoutCocone f g, inr ≫ desc s = s.inr)
(uniq :
∀ (s : PushoutCocone f g) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr),
m = desc s) :
IsColimit (mk inl inr eq) :=
isColimitAux _ desc fac_left fac_right fun s m w =>
uniq s m (w WalkingCospan.left) (w WalkingCospan.right)
/-- The pushout cocone reconstructed using `PushoutCocone.mk` from a pushout cocone that is a
colimit, is also a colimit. -/
def mkSelfIsColimit {t : PushoutCocone f g} (ht : IsColimit t) :
IsColimit (mk t.inl t.inr t.condition) :=
IsColimit.ofIsoColimit ht (eta t)
section Flip
variable (t : PushoutCocone f g)
/-- The pushout cocone obtained by flipping `inl` and `inr`. -/
def flip : PushoutCocone g f := PushoutCocone.mk _ _ t.condition.symm
@[simp] lemma flip_pt : t.flip.pt = t.pt := rfl
@[simp] lemma flip_inl : t.flip.inl = t.inr := rfl
@[simp] lemma flip_inr : t.flip.inr = t.inl := rfl
/-- Flipping a pushout cocone twice gives an isomorphic cocone. -/
def flipFlipIso : t.flip.flip ≅ t := PushoutCocone.ext (Iso.refl _) (by simp) (by simp)
variable {t}
/-- The flip of a pushout square is a pushout square. -/
def flipIsColimit (ht : IsColimit t) : IsColimit t.flip :=
IsColimit.mk _ (fun s => ht.desc s.flip) (by simp) (by simp) (fun s m h₁ h₂ => by
apply IsColimit.hom_ext ht <;> simp [h₁, h₂])
/-- A square is a pushout square if its flip is. -/
def isColimitOfFlip (ht : IsColimit t.flip) : IsColimit t :=
IsColimit.ofIsoColimit (flipIsColimit ht) t.flipFlipIso
end Flip
end PushoutCocone
/-- This is a helper construction that can be useful when verifying that a category has all
pushout. Given `F : WalkingSpan ⥤ C`, which is really the same as
`span (F.map fst) (F.map snd)`, and a pushout cocone on `F.map fst` and `F.map snd`,
we get a cocone on `F`.
If you're thinking about using this, have a look at `hasPushouts_of_hasColimit_span`, which
you may find to be an easier way of achieving your goal. -/
@[simps]
def Cocone.ofPushoutCocone {F : WalkingSpan ⥤ C} (t : PushoutCocone (F.map fst) (F.map snd)) :
Cocone F where
pt := t.pt
ι := (diagramIsoSpan F).hom ≫ t.ι
/-- Given `F : WalkingSpan ⥤ C`, which is really the same as `span (F.map fst) (F.map snd)`,
and a cocone on `F`, we get a pushout cocone on `F.map fst` and `F.map snd`. -/
@[simps]
def PushoutCocone.ofCocone {F : WalkingSpan ⥤ C} (t : Cocone F) :
PushoutCocone (F.map fst) (F.map snd) where
pt := t.pt
ι := (diagramIsoSpan F).inv ≫ t.ι
/-- A diagram `WalkingSpan ⥤ C` is isomorphic to some `PushoutCocone.mk` after composing with
`diagramIsoSpan`. -/
@[simps!]
def PushoutCocone.isoMk {F : WalkingSpan ⥤ C} (t : Cocone F) :
(Cocones.precompose (diagramIsoSpan.{v} _).inv).obj t ≅
PushoutCocone.mk (t.ι.app WalkingSpan.left) (t.ι.app WalkingSpan.right)
((t.ι.naturality fst).trans (t.ι.naturality snd).symm) :=
Cocones.ext (Iso.refl _) <| by
rintro (_ | (_ | _)) <;> simp
end CategoryTheory.Limits
|
Basic.lean
|
/-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Embedding
import Mathlib.Algebra.Order.Interval.Set.Monoid
import Mathlib.Order.Interval.Finset.Defs
/-!
# Algebraic properties of finset intervals
This file provides results about the interaction of algebra with `Finset.Ixx`.
-/
open Function OrderDual
variable {ι α : Type*}
namespace Finset
variable [AddCommMonoid α] [PartialOrder α] [IsOrderedCancelAddMonoid α]
[ExistsAddOfLE α] [LocallyFiniteOrder α]
@[simp] lemma map_add_left_Icc (a b c : α) :
(Icc a b).map (addLeftEmbedding c) = Icc (c + a) (c + b) := by
rw [← coe_inj, coe_map, coe_Icc, coe_Icc]
exact Set.image_const_add_Icc _ _ _
@[simp] lemma map_add_right_Icc (a b c : α) :
(Icc a b).map (addRightEmbedding c) = Icc (a + c) (b + c) := by
rw [← coe_inj, coe_map, coe_Icc, coe_Icc]
exact Set.image_add_const_Icc _ _ _
@[simp] lemma map_add_left_Ico (a b c : α) :
(Ico a b).map (addLeftEmbedding c) = Ico (c + a) (c + b) := by
rw [← coe_inj, coe_map, coe_Ico, coe_Ico]
exact Set.image_const_add_Ico _ _ _
@[simp] lemma map_add_right_Ico (a b c : α) :
(Ico a b).map (addRightEmbedding c) = Ico (a + c) (b + c) := by
rw [← coe_inj, coe_map, coe_Ico, coe_Ico]
exact Set.image_add_const_Ico _ _ _
@[simp] lemma map_add_left_Ioc (a b c : α) :
(Ioc a b).map (addLeftEmbedding c) = Ioc (c + a) (c + b) := by
rw [← coe_inj, coe_map, coe_Ioc, coe_Ioc]
exact Set.image_const_add_Ioc _ _ _
@[simp] lemma map_add_right_Ioc (a b c : α) :
(Ioc a b).map (addRightEmbedding c) = Ioc (a + c) (b + c) := by
rw [← coe_inj, coe_map, coe_Ioc, coe_Ioc]
exact Set.image_add_const_Ioc _ _ _
@[simp] lemma map_add_left_Ioo (a b c : α) :
(Ioo a b).map (addLeftEmbedding c) = Ioo (c + a) (c + b) := by
rw [← coe_inj, coe_map, coe_Ioo, coe_Ioo]
exact Set.image_const_add_Ioo _ _ _
@[simp] lemma map_add_right_Ioo (a b c : α) :
(Ioo a b).map (addRightEmbedding c) = Ioo (a + c) (b + c) := by
rw [← coe_inj, coe_map, coe_Ioo, coe_Ioo]
exact Set.image_add_const_Ioo _ _ _
variable [DecidableEq α]
@[simp] lemma image_add_left_Icc (a b c : α) : (Icc a b).image (c + ·) = Icc (c + a) (c + b) := by
rw [← map_add_left_Icc, map_eq_image, addLeftEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_left_Ico (a b c : α) : (Ico a b).image (c + ·) = Ico (c + a) (c + b) := by
rw [← map_add_left_Ico, map_eq_image, addLeftEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_left_Ioc (a b c : α) : (Ioc a b).image (c + ·) = Ioc (c + a) (c + b) := by
rw [← map_add_left_Ioc, map_eq_image, addLeftEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_left_Ioo (a b c : α) : (Ioo a b).image (c + ·) = Ioo (c + a) (c + b) := by
rw [← map_add_left_Ioo, map_eq_image, addLeftEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_right_Icc (a b c : α) : (Icc a b).image (· + c) = Icc (a + c) (b + c) := by
rw [← map_add_right_Icc, map_eq_image, addRightEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_right_Ico (a b c : α) : (Ico a b).image (· + c) = Ico (a + c) (b + c) := by
rw [← map_add_right_Ico, map_eq_image, addRightEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_right_Ioc (a b c : α) : (Ioc a b).image (· + c) = Ioc (a + c) (b + c) := by
rw [← map_add_right_Ioc, map_eq_image, addRightEmbedding, Embedding.coeFn_mk]
@[simp] lemma image_add_right_Ioo (a b c : α) : (Ioo a b).image (· + c) = Ioo (a + c) (b + c) := by
rw [← map_add_right_Ioo, map_eq_image, addRightEmbedding, Embedding.coeFn_mk]
end Finset
|
cyclotomic.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype tuple finfun bigop prime.
From mathcomp Require Import ssralg poly finset fingroup finalg zmodp cyclic.
From mathcomp Require Import ssrnum ssrint archimedean polydiv intdiv mxpoly.
From mathcomp Require Import rat vector falgebra fieldext separable galois algC.
(******************************************************************************)
(* This file provides few basic properties of cyclotomic polynomials. *)
(* We define: *)
(* cyclotomic z n == the factorization of the nth cyclotomic polynomial in *)
(* a ring R in which z is an nth primitive root of unity. *)
(* 'Phi_n == the nth cyclotomic polynomial in int. *)
(* This library is quite limited, and should be extended in the future. In *)
(* particular the irreducibity of 'Phi_n is only stated indirectly, as the *)
(* fact that its embedding in the algebraics (algC) is the minimal polynomial *)
(* of an nth primitive root of unity. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section CyclotomicPoly.
Section NzRing.
Variable R : nzRingType.
Definition cyclotomic (z : R) n :=
\prod_(k < n | coprime k n) ('X - (z ^+ k)%:P).
Lemma cyclotomic_monic z n : cyclotomic z n \is monic.
Proof. exact: monic_prod_XsubC. Qed.
Lemma size_cyclotomic z n : size (cyclotomic z n) = (totient n).+1.
Proof.
rewrite /cyclotomic -big_filter size_prod_XsubC; congr _.+1.
case: big_enumP => _ _ _ [_ ->].
rewrite totient_count_coprime -big_mkcond big_mkord -sum1_card.
by apply: eq_bigl => k; rewrite coprime_sym.
Qed.
End NzRing.
Lemma separable_Xn_sub_1 (R : idomainType) n :
n%:R != 0 :> R -> @separable_poly R ('X^n - 1).
Proof.
case: n => [/eqP// | n nz_n]; rewrite unlock linearB /= derivC subr0.
rewrite derivXn -scaler_nat coprimepZr //= exprS -scaleN1r coprimep_sym.
by rewrite coprimep_addl_mul coprimepZr ?coprimep1 // (signr_eq0 _ 1).
Qed.
Section Field.
Variables (F : fieldType) (n : nat) (z : F).
Hypothesis prim_z : n.-primitive_root z.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma root_cyclotomic x : root (cyclotomic z n) x = n.-primitive_root x.
Proof.
transitivity (x \in [seq z ^+ i | i : 'I_n in [pred i : 'I_n | coprime i n]]).
by rewrite -root_prod_XsubC big_image.
apply/imageP/idP=> [[k co_k_n ->] | prim_x].
by rewrite prim_root_exp_coprime.
have [k Dx] := prim_rootP prim_z (prim_expr_order prim_x).
exists (Ordinal (ltn_pmod k n_gt0)) => /=; last by rewrite prim_expr_mod.
by rewrite inE coprime_modl -(prim_root_exp_coprime k prim_z) -Dx.
Qed.
Lemma prod_cyclotomic :
'X^n - 1 = \prod_(d <- divisors n) cyclotomic (z ^+ (n %/ d)) d.
Proof.
have in_d d: (d %| n)%N -> val (@inord n d) = d by move/dvdn_leq/inordK=> /= ->.
have dv_n k: (n %/ gcdn k n %| n)%N.
by rewrite -{3}(divnK (dvdn_gcdr k n)) dvdn_mulr.
have [uDn _ inDn] := divisors_correct n_gt0.
have defDn: divisors n = map val (map (@inord n) (divisors n)).
by rewrite -map_comp map_id_in // => d; rewrite inDn => /in_d.
rewrite defDn big_map big_uniq /=; last first.
by rewrite -(map_inj_uniq val_inj) -defDn.
pose h (k : 'I_n) : 'I_n.+1 := inord (n %/ gcdn k n).
rewrite -(factor_Xn_sub_1 prim_z) big_mkord.
rewrite (partition_big h (dvdn^~ n)) /= => [|k _]; last by rewrite in_d ?dv_n.
apply: eq_big => d; first by rewrite -(mem_map val_inj) -defDn inDn.
set q := (n %/ d)%N => d_dv_n.
have [q_gt0 d_gt0]: (0 < q /\ 0 < d)%N by apply/andP; rewrite -muln_gt0 divnK.
have fP (k : 'I_d): (q * k < n)%N by rewrite divn_mulAC ?ltn_divLR ?ltn_pmul2l.
rewrite (reindex (fun k => Ordinal (fP k))); last first.
have f'P (k : 'I_n): (k %/ q < d)%N by rewrite ltn_divLR // mulnC divnK.
exists (fun k => Ordinal (f'P k)) => [k _ | k /eqnP/=].
by apply: val_inj; rewrite /= mulKn.
rewrite in_d // => Dd; apply: val_inj; rewrite /= mulnC divnK // /q -Dd.
by rewrite divnA ?mulKn ?dvdn_gcdl ?dvdn_gcdr.
apply: eq_big => k; rewrite ?exprM // -val_eqE in_d //=.
rewrite -eqn_mul ?dvdn_gcdr ?gcdn_gt0 ?n_gt0 ?orbT //.
rewrite -[n in gcdn _ n](divnK d_dv_n) -muln_gcdr mulnCA mulnA divnK //.
by rewrite mulnC eqn_mul // divnn n_gt0 eq_sym.
Qed.
End Field.
End CyclotomicPoly.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Local Definition algC_intr_inj := @intr_inj algC.
#[local] Hint Resolve algC_intr_inj : core.
Local Notation intCK := (@intrKfloor algC).
Lemma C_prim_root_exists n : (n > 0)%N -> {z : algC | n.-primitive_root z}.
Proof.
pose p : {poly algC} := 'X^n - 1; have [r Dp] := closed_field_poly_normal p.
move=> n_gt0; apply/sigW; rewrite (monicP _) ?monicXnsubC // scale1r in Dp.
have rn1: all n.-unity_root r by apply/allP=> z; rewrite -root_prod_XsubC -Dp.
have sz_r: (n < (size r).+1)%N.
by rewrite -(size_prod_XsubC r id) -Dp size_XnsubC.
have [|z] := hasP (has_prim_root n_gt0 rn1 _ sz_r); last by exists z.
by rewrite -separable_prod_XsubC -Dp separable_Xn_sub_1 // pnatr_eq0 -lt0n.
Qed.
(* (Integral) Cyclotomic polynomials. *)
Definition Cyclotomic n : {poly int} :=
let: exist z _ := C_prim_root_exists (ltn0Sn n.-1) in
map_poly Num.floor (cyclotomic z n).
Notation "''Phi_' n" := (Cyclotomic n)
(at level 8, n at level 2, format "''Phi_' n").
Lemma Cyclotomic_monic n : 'Phi_n \is monic.
Proof.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /= _.
rewrite monicE lead_coefE coef_map_id0 ?(int_algC_K 0) ?floor0 //.
by rewrite size_poly_eq -lead_coefE (monicP (cyclotomic_monic _ _)) (intCK 1).
Qed.
Lemma Cintr_Cyclotomic n z :
n.-primitive_root z -> pZtoC 'Phi_n = cyclotomic z n.
Proof.
elim/ltn_ind: n z => n IHn z0 prim_z0.
rewrite /'Phi_n; case: (C_prim_root_exists _) => z /=.
have n_gt0 := prim_order_gt0 prim_z0; rewrite prednK // => prim_z.
have [uDn _ inDn] := divisors_correct n_gt0.
pose q := \prod_(d <- rem n (divisors n)) 'Phi_d.
have mon_q: q \is monic by apply: monic_prod => d _; apply: Cyclotomic_monic.
have defXn1: cyclotomic z n * pZtoC q = 'X^n - 1.
rewrite (prod_cyclotomic prim_z) (big_rem n) ?inDn //=.
rewrite divnn n_gt0 rmorph_prod /=; congr (_ * _).
apply: eq_big_seq => d; rewrite mem_rem_uniq ?inE //= inDn => /andP[n'd ddvn].
by rewrite -IHn ?dvdn_prim_root // ltn_neqAle n'd dvdn_leq.
have mapXn1 (R1 R2 : nzRingType) (f : {rmorphism R1 -> R2}):
map_poly f ('X^n - 1) = 'X^n - 1.
- by rewrite rmorphB /= rmorph1 map_polyXn.
have nz_q: pZtoC q != 0.
by rewrite -size_poly_eq0 size_map_inj_poly // size_poly_eq0 monic_neq0.
have [r def_zn]: exists r, cyclotomic z n = pZtoC r.
have defZtoC: ZtoC =1 QtoC \o ZtoQ by move=> a; rewrite /= rmorph_int.
have /dvdpP[r0 Dr0]: map_poly ZtoQ q %| 'X^n - 1.
rewrite -(dvdp_map (@ratr algC)) mapXn1 -map_poly_comp.
by rewrite -(eq_map_poly defZtoC) -defXn1 dvdp_mull.
have [r [a nz_a Dr]] := rat_poly_scale r0.
exists (zprimitive r); apply: (mulIf nz_q); rewrite defXn1.
rewrite -rmorphM -(zprimitive_monic mon_q) -zprimitiveM /=.
have ->: r * q = a *: ('X^n - 1).
apply: (map_inj_poly (intr_inj : injective ZtoQ)) => //.
rewrite map_polyZ mapXn1 Dr0 Dr -scalerAl scalerKV ?intr_eq0 //.
by rewrite rmorphM.
by rewrite zprimitiveZ // zprimitive_monic ?monicXnsubC ?mapXn1.
rewrite floorpK; last by apply/polyOverP=> i; rewrite def_zn coef_map /=.
pose f e (k : 'I_n) := Ordinal (ltn_pmod (k * e) n_gt0).
have [e Dz0] := prim_rootP prim_z (prim_expr_order prim_z0).
have co_e_n: coprime e n by rewrite -(prim_root_exp_coprime e prim_z) -Dz0.
have injf: injective (f e).
apply: can_inj (f (egcdn e n).1) _ => k; apply: val_inj => /=.
rewrite modnMml -mulnA -modnMmr -{1}(mul1n e).
by rewrite (chinese_modr co_e_n 0) modnMmr muln1 modn_small.
rewrite [_ n](reindex_inj injf); apply: eq_big => k /=.
by rewrite coprime_modl coprimeMl co_e_n andbT.
by rewrite prim_expr_mod // mulnC exprM -Dz0.
Qed.
Lemma prod_Cyclotomic n :
(n > 0)%N -> \prod_(d <- divisors n) 'Phi_d = 'X^n - 1.
Proof.
move=> n_gt0; have [z prim_z] := C_prim_root_exists n_gt0.
apply: (map_inj_poly (intr_inj : injective ZtoC)) => //.
rewrite rmorphB rmorph1 rmorph_prod /= map_polyXn (prod_cyclotomic prim_z).
apply: eq_big_seq => d; rewrite -dvdn_divisors // => d_dv_n.
by rewrite -Cintr_Cyclotomic ?dvdn_prim_root.
Qed.
Lemma Cyclotomic0 : 'Phi_0 = 1.
Proof.
rewrite /'Phi_0; case: (C_prim_root_exists _) => z /= _.
by rewrite -[1]polyseqK /cyclotomic big_ord0 map_polyE !polyseq1 /= (intCK 1).
Qed.
Lemma size_Cyclotomic n : size 'Phi_n = (totient n).+1.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite Cyclotomic0 polyseq1.
have [z prim_z] := C_prim_root_exists n_gt0.
rewrite -(size_map_inj_poly (can_inj intCK)) //.
by rewrite (Cintr_Cyclotomic prim_z) size_cyclotomic.
Qed.
Lemma minCpoly_cyclotomic n z :
n.-primitive_root z -> minCpoly z = cyclotomic z n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
have Dpz := Cintr_Cyclotomic prim_z; set pz := cyclotomic z n in Dpz *.
have mon_pz: pz \is monic by apply: cyclotomic_monic.
have pz0: root pz z by rewrite root_cyclotomic.
have [pf [Dpf mon_pf] dv_pf] := minCpolyP z.
have /dvdpP_rat_int[f [af nz_af Df] [g /esym Dfg]]: pf %| pZtoQ 'Phi_n.
rewrite -dv_pf; congr (root _ z): pz0; rewrite -Dpz -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
without loss{nz_af} [mon_f mon_g]: af f g Df Dfg / f \is monic /\ g \is monic.
move=> IH; pose cf := lead_coef f; pose cg := lead_coef g.
have cfg1: cf * cg = 1.
by rewrite -lead_coefM Dfg (monicP (Cyclotomic_monic n)).
apply: (IH (af *~ cf) (f *~ cg) (g *~ cf)).
- by rewrite rmorphMz -scalerMzr scalerMzl -mulrzA cfg1.
- by rewrite mulrzAl mulrzAr -mulrzA cfg1.
by rewrite !(intz, =^~ scaler_int) !monicE !lead_coefZ mulrC cfg1.
have{af} Df: pQtoC pf = pZtoC f.
have:= congr1 lead_coef Df.
rewrite lead_coefZ lead_coef_map_inj //; last exact: intr_inj.
rewrite !(monicP _) // mulr1 Df => <-; rewrite scale1r -map_poly_comp.
by apply: eq_map_poly => b; rewrite /= rmorph_int.
have [/size1_polyC Dg | g_gt1] := leqP (size g) 1.
rewrite monicE Dg lead_coefC in mon_g.
by rewrite -Dpz -Dfg Dg (eqP mon_g) mulr1 Dpf.
have [zk gzk0]: exists zk, root (pZtoC g) zk.
have [rg] := closed_field_poly_normal (pZtoC g).
rewrite lead_coef_map_inj // (monicP mon_g) scale1r => Dg.
rewrite -(size_map_inj_poly (can_inj intCK)) // Dg in g_gt1.
rewrite size_prod_XsubC in g_gt1.
by exists rg`_0; rewrite Dg root_prod_XsubC mem_nth.
have [k cokn Dzk]: exists2 k, coprime k n & zk = z ^+ k.
have: root pz zk by rewrite -Dpz -Dfg rmorphM rootM gzk0 orbT.
rewrite -[pz](big_image _ _ _ _ (fun r => 'X - r%:P)) root_prod_XsubC.
by case/imageP=> k; exists k.
have co_fg (R : idomainType): n%:R != 0 :> R -> @coprimep R (intrp f) (intrp g).
move=> nz_n; have: separable_poly (intrp ('X^n - 1) : {poly R}).
by rewrite rmorphB rmorph1 /= map_polyXn separable_Xn_sub_1.
rewrite -prod_Cyclotomic // (big_rem n) -?dvdn_divisors //= -Dfg.
by rewrite !rmorphM /= !separable_mul => /and3P[] /and3P[].
suffices fzk0: root (pZtoC f) zk.
have [] // := negP (coprimep_root (co_fg _ _) fzk0).
by rewrite pnatr_eq0 -lt0n.
move: gzk0 cokn; rewrite {zk}Dzk; elim/ltn_ind: k => k IHk gzk0 cokn.
have [|k_gt1] := leqP k 1; last have [p p_pr /dvdnP[k1 Dk]] := pdivP k_gt1.
rewrite -[leq k 1](mem_iota 0 2) !inE => /pred2P[k0 | ->]; last first.
by rewrite -Df dv_pf.
have /eqP := size_Cyclotomic n; rewrite -Dfg size_Mmonic ?monic_neq0 //.
rewrite k0 /coprime gcd0n in cokn; rewrite (eqP cokn).
rewrite -(size_map_inj_poly (can_inj intCK)) // -Df -Dpf.
by rewrite -(subnKC g_gt1) -(subnKC (size_minCpoly z)) !addnS.
move: cokn; rewrite Dk coprimeMl => /andP[cok1n].
rewrite prime_coprime // (dvdn_pcharf (pchar_Fp p_pr)) => /co_fg {co_fg}.
have pcharFpX: p \in [pchar {poly 'F_p}] by rewrite (rmorph_pchar polyC) ?pchar_Fp.
rewrite -(coprimep_pexpr _ _ (prime_gt0 p_pr)) -(pFrobenius_autE pcharFpX).
rewrite -[g]comp_polyXr map_comp_poly -horner_map /= pFrobenius_autE -rmorphXn.
rewrite -!map_poly_comp (@eq_map_poly _ _ _ (polyC \o *~%R 1)); last first.
by move=> a; rewrite /= !rmorph_int.
rewrite map_poly_comp -[_.[_]]map_comp_poly /= => co_fg.
suffices: coprimep (pZtoC f) (pZtoC (g \Po 'X^p)).
move/coprimep_root=> /=/(_ (z ^+ k1))/implyP.
rewrite map_comp_poly map_polyXn horner_comp hornerXn.
rewrite -exprM -Dk [_ == 0]gzk0 implybF => /negP[].
have: root pz (z ^+ k1).
by rewrite root_cyclotomic // prim_root_exp_coprime.
rewrite -Dpz -Dfg rmorphM rootM => /orP[] //= /IHk-> //.
rewrite -[k1]muln1 Dk ltn_pmul2l ?prime_gt1 //.
by have:= ltnW k_gt1; rewrite Dk muln_gt0 => /andP[].
suffices: coprimep f (g \Po 'X^p).
case/Bezout_coprimepP=> [[u v]]; rewrite -size_poly_eq1.
rewrite -(size_map_inj_poly (can_inj intCK)) // rmorphD !rmorphM /=.
rewrite size_poly_eq1 => {}co_fg; apply/Bezout_coprimepP.
by exists (pZtoC u, pZtoC v).
apply: contraLR co_fg => /coprimepPn[|d]; first exact: monic_neq0.
rewrite andbC -size_poly_eq1 dvdp_gcd => /and3P[sz_d].
pose d1 := zprimitive d.
have d_dv_mon h: d %| h -> h \is monic -> exists h1, h = d1 * h1.
case/Pdiv.Idomain.dvdpP=> [[c h1] /= nz_c Dh] mon_h; exists (zprimitive h1).
by rewrite -zprimitiveM mulrC -Dh zprimitiveZ ?zprimitive_monic.
case/d_dv_mon=> // f1 Df1 /d_dv_mon[|f2 ->].
rewrite monicE lead_coefE size_comp_poly size_polyXn /=.
rewrite comp_polyE coef_sum polySpred ?monic_neq0 //= mulnC.
rewrite big_ord_recr /= -lead_coefE (monicP mon_g) scale1r.
rewrite -exprM coefXn eqxx big1 ?add0r // => i _.
rewrite coefZ -exprM coefXn eqn_pmul2l ?prime_gt0 //.
by rewrite eqn_leq leqNgt ltn_ord mulr0.
have monFp h: h \is monic -> size (map_poly intr h) = size h.
by move=> mon_h; rewrite size_poly_eq // -lead_coefE (monicP mon_h) oner_eq0.
apply/coprimepPn; last exists (map_poly intr d1).
by rewrite -size_poly_eq0 monFp // size_poly_eq0 monic_neq0.
rewrite Df1 !rmorphM dvdp_gcd !dvdp_mulr //= -size_poly_eq1.
rewrite monFp ?size_zprimitive //.
rewrite monicE [_ d1]intEsg sgz_lead_primitive -zprimitive_eq0 -/d1.
rewrite -lead_coef_eq0 -absz_eq0.
have/esym/eqP := congr1 (absz \o lead_coef) Df1.
by rewrite /= (monicP mon_f) lead_coefM abszM muln_eq1 => /andP[/eqP-> _].
Qed.
|
MonotoneContinuity.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Heather Macbeth
-/
import Mathlib.Topology.Homeomorph.Defs
import Mathlib.Topology.Order.LeftRightNhds
/-!
# Continuity of monotone functions
In this file we prove the following fact: if `f` is a monotone function on a neighborhood of `a`
and the image of this neighborhood is a neighborhood of `f a`, then `f` is continuous at `a`, see
`continuousWithinAt_of_monotoneOn_of_image_mem_nhds`, as well as several similar facts.
We also prove that an `OrderIso` is continuous.
## Tags
continuous, monotone
-/
open Set Filter
open Topology
section LinearOrder
variable {α β : Type*} [LinearOrder α] [TopologicalSpace α] [OrderTopology α]
variable [LinearOrder β] [TopologicalSpace β] [OrderTopology β]
/-- If `f` is a function strictly monotone on a right neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(f a, b]`, `b > f a`, then `f` is
continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x ≤ 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
theorem StrictMonoOn.continuousWithinAt_right_of_exists_between {f : α → β} {s : Set α} {a : α}
(h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≥] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) :
ContinuousWithinAt f (Ici a) a := by
have ha : a ∈ Ici a := left_mem_Ici
have has : a ∈ s := mem_of_mem_nhdsWithin ha hs
refine tendsto_order.2 ⟨fun b hb => ?_, fun b hb => ?_⟩
· filter_upwards [hs, @self_mem_nhdsWithin _ _ a (Ici a)] with _ hxs hxa using hb.trans_le
((h_mono.le_iff_le has hxs).2 hxa)
· rcases hfs b hb with ⟨c, hcs, hac, hcb⟩
rw [h_mono.lt_iff_lt has hcs] at hac
filter_upwards [hs, Ico_mem_nhdsGE hac]
rintro x hx ⟨_, hxc⟩
exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb
/-- If `f` is a monotone function on a right neighborhood of `a` and the image of this neighborhood
under `f` meets every interval `(f a, b)`, `b > f a`, then `f` is continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b` cannot be replaced by the weaker
assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` we use for strictly monotone functions
because otherwise the function `ceil : ℝ → ℤ` would be a counter-example at `a = 0`. -/
theorem continuousWithinAt_right_of_monotoneOn_of_exists_between {f : α → β} {s : Set α} {a : α}
(h_mono : MonotoneOn f s) (hs : s ∈ 𝓝[≥] a) (hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) :
ContinuousWithinAt f (Ici a) a := by
have ha : a ∈ Ici a := left_mem_Ici
have has : a ∈ s := mem_of_mem_nhdsWithin ha hs
refine tendsto_order.2 ⟨fun b hb => ?_, fun b hb => ?_⟩
· filter_upwards [hs, @self_mem_nhdsWithin _ _ a (Ici a)] with _ hxs hxa using hb.trans_le
(h_mono has hxs hxa)
· rcases hfs b hb with ⟨c, hcs, hac, hcb⟩
have : a < c := not_le.1 fun h => hac.not_ge <| h_mono hcs has h
filter_upwards [hs, Ico_mem_nhdsGE this]
rintro x hx ⟨_, hxc⟩
exact (h_mono hx hcs hxc.le).trans_lt hcb
/-- If a function `f` with a densely ordered codomain is monotone on a right neighborhood of `a` and
the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f`
is continuous at `a` from the right. -/
theorem continuousWithinAt_right_of_monotoneOn_of_closure_image_mem_nhdsWithin [DenselyOrdered β]
{f : α → β} {s : Set α} {a : α} (h_mono : MonotoneOn f s) (hs : s ∈ 𝓝[≥] a)
(hfs : closure (f '' s) ∈ 𝓝[≥] f a) : ContinuousWithinAt f (Ici a) a := by
refine continuousWithinAt_right_of_monotoneOn_of_exists_between h_mono hs fun b hb => ?_
rcases (mem_nhdsGE_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩
rcases exists_between hab' with ⟨c', hc'⟩
rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') isOpen_Ioo hc' with
⟨_, hc, ⟨c, hcs, rfl⟩⟩
exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩
/-- If a function `f` with a densely ordered codomain is monotone on a right neighborhood of `a` and
the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is continuous at
`a` from the right. -/
theorem continuousWithinAt_right_of_monotoneOn_of_image_mem_nhdsWithin [DenselyOrdered β]
{f : α → β} {s : Set α} {a : α} (h_mono : MonotoneOn f s) (hs : s ∈ 𝓝[≥] a)
(hfs : f '' s ∈ 𝓝[≥] f a) : ContinuousWithinAt f (Ici a) a :=
continuousWithinAt_right_of_monotoneOn_of_closure_image_mem_nhdsWithin h_mono hs <|
mem_of_superset hfs subset_closure
/-- If a function `f` with a densely ordered codomain is strictly monotone on a right neighborhood
of `a` and the closure of the image of this neighborhood under `f` is a right neighborhood of `f a`,
then `f` is continuous at `a` from the right. -/
theorem StrictMonoOn.continuousWithinAt_right_of_closure_image_mem_nhdsWithin [DenselyOrdered β]
{f : α → β} {s : Set α} {a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≥] a)
(hfs : closure (f '' s) ∈ 𝓝[≥] f a) : ContinuousWithinAt f (Ici a) a :=
continuousWithinAt_right_of_monotoneOn_of_closure_image_mem_nhdsWithin
(fun _ hx _ hy => (h_mono.le_iff_le hx hy).2) hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotone on a right neighborhood
of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`, then `f` is
continuous at `a` from the right. -/
theorem StrictMonoOn.continuousWithinAt_right_of_image_mem_nhdsWithin [DenselyOrdered β] {f : α → β}
{s : Set α} {a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≥] a) (hfs : f '' s ∈ 𝓝[≥] f a) :
ContinuousWithinAt f (Ici a) a :=
h_mono.continuousWithinAt_right_of_closure_image_mem_nhdsWithin hs
(mem_of_superset hfs subset_closure)
/-- If a function `f` is strictly monotone on a right neighborhood of `a` and the image of this
neighborhood under `f` includes `Ioi (f a)`, then `f` is continuous at `a` from the right. -/
theorem StrictMonoOn.continuousWithinAt_right_of_surjOn {f : α → β} {s : Set α} {a : α}
(h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≥] a) (hfs : SurjOn f s (Ioi (f a))) :
ContinuousWithinAt f (Ici a) a :=
h_mono.continuousWithinAt_right_of_exists_between hs fun _ hb =>
let ⟨c, hcs, hcb⟩ := hfs hb
⟨c, hcs, hcb.symm ▸ hb, hcb.le⟩
/-- If `f` is a strictly monotone function on a left neighborhood of `a` and the image of this
neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, then `f` is continuous at `a`
from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x < 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
theorem StrictMonoOn.continuousWithinAt_left_of_exists_between {f : α → β} {s : Set α} {a : α}
(h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≤] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) :
ContinuousWithinAt f (Iic a) a :=
h_mono.dual.continuousWithinAt_right_of_exists_between hs fun b hb =>
let ⟨c, hcs, hcb, hca⟩ := hfs b hb
⟨c, hcs, hca, hcb⟩
/-- If `f` is a monotone function on a left neighborhood of `a` and the image of this neighborhood
under `f` meets every interval `(b, f a)`, `b < f a`, then `f` is continuous at `a` from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)` cannot be replaced by the weaker
assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` we use for strictly monotone functions
because otherwise the function `floor : ℝ → ℤ` would be a counter-example at `a = 0`. -/
theorem continuousWithinAt_left_of_monotoneOn_of_exists_between {f : α → β} {s : Set α} {a : α}
(hf : MonotoneOn f s) (hs : s ∈ 𝓝[≤] a) (hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) :
ContinuousWithinAt f (Iic a) a :=
@continuousWithinAt_right_of_monotoneOn_of_exists_between αᵒᵈ βᵒᵈ _ _ _ _ _ _ f s a hf.dual hs
fun b hb =>
let ⟨c, hcs, hcb, hca⟩ := hfs b hb
⟨c, hcs, hca, hcb⟩
/-- If a function `f` with a densely ordered codomain is monotone on a left neighborhood of `a` and
the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is
continuous at `a` from the left -/
theorem continuousWithinAt_left_of_monotoneOn_of_closure_image_mem_nhdsWithin [DenselyOrdered β]
{f : α → β} {s : Set α} {a : α} (hf : MonotoneOn f s) (hs : s ∈ 𝓝[≤] a)
(hfs : closure (f '' s) ∈ 𝓝[≤] f a) : ContinuousWithinAt f (Iic a) a :=
@continuousWithinAt_right_of_monotoneOn_of_closure_image_mem_nhdsWithin αᵒᵈ βᵒᵈ _ _ _ _ _ _ _ f s
a hf.dual hs hfs
/-- If a function `f` with a densely ordered codomain is monotone on a left neighborhood of `a` and
the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is continuous at
`a` from the left. -/
theorem continuousWithinAt_left_of_monotoneOn_of_image_mem_nhdsWithin [DenselyOrdered β] {f : α → β}
{s : Set α} {a : α} (h_mono : MonotoneOn f s) (hs : s ∈ 𝓝[≤] a) (hfs : f '' s ∈ 𝓝[≤] f a) :
ContinuousWithinAt f (Iic a) a :=
continuousWithinAt_left_of_monotoneOn_of_closure_image_mem_nhdsWithin h_mono hs
(mem_of_superset hfs subset_closure)
/-- If a function `f` with a densely ordered codomain is strictly monotone on a left neighborhood of
`a` and the closure of the image of this neighborhood under `f` is a left neighborhood of `f a`,
then `f` is continuous at `a` from the left. -/
theorem StrictMonoOn.continuousWithinAt_left_of_closure_image_mem_nhdsWithin [DenselyOrdered β]
{f : α → β} {s : Set α} {a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≤] a)
(hfs : closure (f '' s) ∈ 𝓝[≤] f a) : ContinuousWithinAt f (Iic a) a :=
h_mono.dual.continuousWithinAt_right_of_closure_image_mem_nhdsWithin hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotone on a left neighborhood of
`a` and the image of this neighborhood under `f` is a left neighborhood of `f a`, then `f` is
continuous at `a` from the left. -/
theorem StrictMonoOn.continuousWithinAt_left_of_image_mem_nhdsWithin [DenselyOrdered β] {f : α → β}
{s : Set α} {a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≤] a) (hfs : f '' s ∈ 𝓝[≤] f a) :
ContinuousWithinAt f (Iic a) a :=
h_mono.dual.continuousWithinAt_right_of_image_mem_nhdsWithin hs hfs
/-- If a function `f` is strictly monotone on a left neighborhood of `a` and the image of this
neighborhood under `f` includes `Iio (f a)`, then `f` is continuous at `a` from the left. -/
theorem StrictMonoOn.continuousWithinAt_left_of_surjOn {f : α → β} {s : Set α} {a : α}
(h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝[≤] a) (hfs : SurjOn f s (Iio (f a))) :
ContinuousWithinAt f (Iic a) a :=
h_mono.dual.continuousWithinAt_right_of_surjOn hs hfs
/-- If a function `f` is strictly monotone on a neighborhood of `a` and the image of this
neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, and every interval
`(f a, b]`, `b > f a`, then `f` is continuous at `a`. -/
theorem StrictMonoOn.continuousAt_of_exists_between {f : α → β} {s : Set α} {a : α}
(h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a))
(hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) : ContinuousAt f a :=
continuousAt_iff_continuous_left_right.2
⟨h_mono.continuousWithinAt_left_of_exists_between (mem_nhdsWithin_of_mem_nhds hs) hfs_l,
h_mono.continuousWithinAt_right_of_exists_between (mem_nhdsWithin_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is strictly monotone on a neighborhood of `a`
and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
theorem StrictMonoOn.continuousAt_of_closure_image_mem_nhds [DenselyOrdered β] {f : α → β}
{s : Set α} {a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) : ContinuousAt f a :=
continuousAt_iff_continuous_left_right.2
⟨h_mono.continuousWithinAt_left_of_closure_image_mem_nhdsWithin (mem_nhdsWithin_of_mem_nhds hs)
(mem_nhdsWithin_of_mem_nhds hfs),
h_mono.continuousWithinAt_right_of_closure_image_mem_nhdsWithin
(mem_nhdsWithin_of_mem_nhds hs) (mem_nhdsWithin_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is strictly monotone on a neighborhood of `a`
and the image of this set under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/
theorem StrictMonoOn.continuousAt_of_image_mem_nhds [DenselyOrdered β] {f : α → β} {s : Set α}
{a : α} (h_mono : StrictMonoOn f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) :
ContinuousAt f a :=
h_mono.continuousAt_of_closure_image_mem_nhds hs (mem_of_superset hfs subset_closure)
/-- If `f` is a monotone function on a neighborhood of `a` and the image of this neighborhood under
`f` meets every interval `(b, f a)`, `b < f a`, and every interval `(f a, b)`, `b > f a`, then `f`
is continuous at `a`. -/
theorem continuousAt_of_monotoneOn_of_exists_between {f : α → β} {s : Set α} {a : α}
(h_mono : MonotoneOn f s) (hs : s ∈ 𝓝 a) (hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a))
(hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) : ContinuousAt f a :=
continuousAt_iff_continuous_left_right.2
⟨continuousWithinAt_left_of_monotoneOn_of_exists_between h_mono (mem_nhdsWithin_of_mem_nhds hs)
hfs_l,
continuousWithinAt_right_of_monotoneOn_of_exists_between h_mono
(mem_nhdsWithin_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is monotone on a neighborhood of `a` and the
closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
theorem continuousAt_of_monotoneOn_of_closure_image_mem_nhds [DenselyOrdered β] {f : α → β}
{s : Set α} {a : α} (h_mono : MonotoneOn f s) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) : ContinuousAt f a :=
continuousAt_iff_continuous_left_right.2
⟨continuousWithinAt_left_of_monotoneOn_of_closure_image_mem_nhdsWithin h_mono
(mem_nhdsWithin_of_mem_nhds hs) (mem_nhdsWithin_of_mem_nhds hfs),
continuousWithinAt_right_of_monotoneOn_of_closure_image_mem_nhdsWithin h_mono
(mem_nhdsWithin_of_mem_nhds hs) (mem_nhdsWithin_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is monotone on a neighborhood of `a` and the
image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is continuous at `a`. -/
theorem continuousAt_of_monotoneOn_of_image_mem_nhds [DenselyOrdered β] {f : α → β} {s : Set α}
{a : α} (h_mono : MonotoneOn f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) : ContinuousAt f a :=
continuousAt_of_monotoneOn_of_closure_image_mem_nhds h_mono hs
(mem_of_superset hfs subset_closure)
/-- A monotone function with densely ordered codomain and a dense range is continuous. -/
theorem Monotone.continuous_of_denseRange [DenselyOrdered β] {f : α → β} (h_mono : Monotone f)
(h_dense : DenseRange f) : Continuous f :=
continuous_iff_continuousAt.mpr fun a =>
continuousAt_of_monotoneOn_of_closure_image_mem_nhds (fun _ _ _ _ hxy => h_mono hxy)
univ_mem <|
by simp only [image_univ, h_dense.closure_eq, univ_mem]
/-- A monotone surjective function with a densely ordered codomain is continuous. -/
theorem Monotone.continuous_of_surjective [DenselyOrdered β] {f : α → β} (h_mono : Monotone f)
(h_surj : Function.Surjective f) : Continuous f :=
h_mono.continuous_of_denseRange h_surj.denseRange
end LinearOrder
/-!
### Continuity of order isomorphisms
In this section we prove that an `OrderIso` is continuous, hence it is a `Homeomorph`. We prove
this for an `OrderIso` between to partial orders with order topology.
-/
namespace OrderIso
variable {α β : Type*} [Preorder α] [Preorder β] [TopologicalSpace α] [TopologicalSpace β]
[OrderTopology α] [OrderTopology β]
protected theorem continuous (e : α ≃o β) : Continuous e := by
rw [‹OrderTopology β›.topology_eq_generate_intervals, continuous_generateFrom_iff]
rintro s ⟨a, rfl | rfl⟩
· rw [e.preimage_Ioi]
apply isOpen_lt'
· rw [e.preimage_Iio]
apply isOpen_gt'
/-- An order isomorphism between two linear order `OrderTopology` spaces is a homeomorphism. -/
def toHomeomorph (e : α ≃o β) : α ≃ₜ β :=
{ e with
continuous_toFun := e.continuous
continuous_invFun := e.symm.continuous }
@[simp]
theorem coe_toHomeomorph (e : α ≃o β) : ⇑e.toHomeomorph = e :=
rfl
@[simp]
theorem coe_toHomeomorph_symm (e : α ≃o β) : ⇑e.toHomeomorph.symm = e.symm :=
rfl
end OrderIso
|
SMul.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, Alexander Bentkamp
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.LinearAlgebra.Basis.Basic
/-!
# Bases and scalar multiplication
This file defines the scalar multiplication of bases by multiplying each basis vector.
-/
assert_not_exists Ordinal
noncomputable section
universe u
open Function Set Submodule Finsupp
variable {ι R R₂ M : Type*}
namespace Module.Basis
variable [Semiring R] [AddCommMonoid M] [Module R M] (b : Basis ι R M)
section SMul
variable {G G'}
variable [Group G] [Group G']
variable [DistribMulAction G M] [DistribMulAction G' M]
variable [SMulCommClass G R M] [SMulCommClass G' R M]
/-- The action on a `Basis` by acting on each element.
See also `Basis.unitsSMul` and `Basis.groupSMul`, for the cases when a different action is applied
to each basis element. -/
instance : SMul G (Basis ι R M) where
smul g b := b.map <| DistribMulAction.toLinearEquiv _ _ g
@[simp]
theorem smul_apply (g : G) (b : Basis ι R M) (i : ι) : (g • b) i = g • b i := rfl
@[norm_cast] theorem coe_smul (g : G) (b : Basis ι R M) : ⇑(g • b) = g • ⇑b := rfl
/-- When the group in question is the automorphisms, `•` coincides with `Basis.map`. -/
@[simp]
theorem smul_eq_map (g : M ≃ₗ[R] M) (b : Basis ι R M) : g • b = b.map g := rfl
@[simp] theorem repr_smul (g : G) (b : Basis ι R M) :
(g • b).repr = (DistribMulAction.toLinearEquiv _ _ g).symm.trans b.repr := rfl
instance : MulAction G (Basis ι R M) :=
Function.Injective.mulAction _ DFunLike.coe_injective coe_smul
instance [SMulCommClass G G' M] : SMulCommClass G G' (Basis ι R M) where
smul_comm _g _g' _b := DFunLike.ext _ _ fun _ => smul_comm _ _ _
instance [SMul G G'] [IsScalarTower G G' M] : IsScalarTower G G' (Basis ι R M) where
smul_assoc _g _g' _b := DFunLike.ext _ _ fun _ => smul_assoc _ _ _
end SMul
section CommSemiring
variable {v : ι → M} {x y : M}
theorem groupSMul_span_eq_top {G : Type*} [Group G] [SMul G R] [MulAction G M]
[IsScalarTower G R M] {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) {w : ι → G} :
Submodule.span R (Set.range (w • v)) = ⊤ := by
rw [eq_top_iff]
intro j hj
rw [← hv] at hj
rw [Submodule.mem_span] at hj ⊢
refine fun p hp => hj p fun u hu => ?_
obtain ⟨i, rfl⟩ := hu
have : ((w i)⁻¹ • (1 : R)) • w i • v i ∈ p := p.smul_mem ((w i)⁻¹ • (1 : R)) (hp ⟨i, rfl⟩)
rwa [smul_one_smul, inv_smul_smul] at this
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` are elements of a group,
`groupSMul` provides the basis corresponding to `w • v`. -/
def groupSMul {G : Type*} [Group G] [DistribMulAction G R] [DistribMulAction G M]
[IsScalarTower G R M] [SMulCommClass G R M] (v : Basis ι R M) (w : ι → G) : Basis ι R M :=
Basis.mk (LinearIndependent.group_smul v.linearIndependent w) (groupSMul_span_eq_top v.span_eq).ge
theorem groupSMul_apply {G : Type*} [Group G] [DistribMulAction G R] [DistribMulAction G M]
[IsScalarTower G R M] [SMulCommClass G R M] {v : Basis ι R M} {w : ι → G} (i : ι) :
v.groupSMul w i = (w • (v : ι → M)) i :=
mk_apply (LinearIndependent.group_smul v.linearIndependent w)
(groupSMul_span_eq_top v.span_eq).ge i
theorem units_smul_span_eq_top {v : ι → M} (hv : Submodule.span R (Set.range v) = ⊤) {w : ι → Rˣ} :
Submodule.span R (Set.range (w • v)) = ⊤ :=
groupSMul_span_eq_top hv
/-- Given a basis `v` and a map `w` such that for all `i`, `w i` is a unit, `unitsSMul`
provides the basis corresponding to `w • v`. -/
def unitsSMul (v : Basis ι R M) (w : ι → Rˣ) : Basis ι R M :=
Basis.mk (LinearIndependent.units_smul v.linearIndependent w)
(units_smul_span_eq_top v.span_eq).ge
theorem unitsSMul_apply {v : Basis ι R M} {w : ι → Rˣ} (i : ι) : unitsSMul v w i = w i • v i :=
mk_apply (LinearIndependent.units_smul v.linearIndependent w)
(units_smul_span_eq_top v.span_eq).ge i
variable [CommSemiring R₂] [Module R₂ M]
@[simp]
theorem coord_unitsSMul (e : Basis ι R₂ M) (w : ι → R₂ˣ) (i : ι) :
(unitsSMul e w).coord i = (w i)⁻¹ • e.coord i := by
classical
apply e.ext
intro j
trans ((unitsSMul e w).coord i) ((w j)⁻¹ • (unitsSMul e w) j)
· congr
simp [Basis.unitsSMul, ← mul_smul]
simp only [Basis.coord_apply, LinearMap.smul_apply, Basis.repr_self, Units.smul_def,
map_smul, Finsupp.single_apply]
split_ifs with h <;> simp [h]
@[simp]
theorem repr_unitsSMul (e : Basis ι R₂ M) (w : ι → R₂ˣ) (v : M) (i : ι) :
(e.unitsSMul w).repr v i = (w i)⁻¹ • e.repr v i :=
congr_arg (fun f : M →ₗ[R₂] R₂ => f v) (e.coord_unitsSMul w i)
/-- A version of `unitsSMul` that uses `IsUnit`. -/
def isUnitSMul (v : Basis ι R M) {w : ι → R} (hw : ∀ i, IsUnit (w i)) : Basis ι R M :=
unitsSMul v fun i => (hw i).unit
theorem isUnitSMul_apply {v : Basis ι R M} {w : ι → R} (hw : ∀ i, IsUnit (w i)) (i : ι) :
v.isUnitSMul hw i = w i • v i :=
unitsSMul_apply i
theorem repr_isUnitSMul {v : Basis ι R₂ M} {w : ι → R₂} (hw : ∀ i, IsUnit (w i)) (x : M) (i : ι) :
(v.isUnitSMul hw).repr x i = (hw i).unit⁻¹ • v.repr x i :=
repr_unitsSMul _ _ _ _
end CommSemiring
end Module.Basis
|
MinMax.lean
|
/-
Copyright (c) 2019 Minchao Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Minchao Wu, Chris Hughes, Mantas Bakšys
-/
import Mathlib.Data.List.Basic
import Mathlib.Order.BoundedOrder.Lattice
import Mathlib.Data.List.Induction
import Mathlib.Order.MinMax
import Mathlib.Order.WithBot
/-!
# Minimum and maximum of lists
## Main definitions
The main definitions are `argmax`, `argmin`, `minimum` and `maximum` for lists.
`argmax f l` returns `some a`, where `a` of `l` that maximises `f a`. If there are `a b` such that
`f a = f b`, it returns whichever of `a` or `b` comes first in the list.
`argmax f [] = none`
`minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for
`[]`
-/
namespace List
variable {α β : Type*}
section ArgAux
variable (r : α → α → Prop) [DecidableRel r] {l : List α} {o : Option α} {a : α}
/-- Auxiliary definition for `argmax` and `argmin`. -/
def argAux (a : Option α) (b : α) : Option α :=
Option.casesOn a (some b) fun c => if r b c then some b else some c
@[simp]
theorem foldl_argAux_eq_none : l.foldl (argAux r) o = none ↔ l = [] ∧ o = none :=
List.reverseRecOn l (by simp) fun tl hd => by
simp only [foldl_append, foldl_cons, argAux, foldl_nil, append_eq_nil_iff]
cases foldl (argAux r) o tl
· simp
· simp only
split_ifs <;> simp
private theorem foldl_argAux_mem (l) : ∀ a m : α, m ∈ foldl (argAux r) (some a) l → m ∈ a :: l :=
List.reverseRecOn l (by simp [eq_comm])
(by
intro tl hd ih a m
simp only [foldl_append, foldl_cons, foldl_nil, argAux]
cases hf : foldl (argAux r) (some a) tl
· simp +contextual
· dsimp only
split_ifs
· simp +contextual
· -- `finish [ih _ _ hf]` closes this goal
simp only [List.mem_cons] at ih
rcases ih _ _ hf with rfl | H
· simp +contextual only [Option.mem_def, Option.some.injEq,
eq_comm, mem_cons, mem_append, true_or, implies_true]
· simp +contextual [@eq_comm _ _ m, H])
@[simp]
theorem argAux_self (hr₀ : Irreflexive r) (a : α) : argAux r (some a) a = a :=
if_neg <| hr₀ _
theorem not_of_mem_foldl_argAux (hr₀ : Irreflexive r) (hr₁ : Transitive r) :
∀ {a m : α} {o : Option α}, a ∈ l → m ∈ foldl (argAux r) o l → ¬r a m := by
induction' l using List.reverseRecOn with tl a ih
· simp
intro b m o hb ho
rw [foldl_append, foldl_cons, foldl_nil, argAux] at ho
rcases hf : foldl (argAux r) o tl with - | c
· rw [hf] at ho
rw [foldl_argAux_eq_none] at hf
simp_all [hf.1, hf.2, hr₀ _]
rw [hf, Option.mem_def] at ho
dsimp only at ho
split_ifs at ho with hac <;> rcases mem_append.1 hb with h | h <;>
injection ho with ho <;> subst ho
· exact fun hba => ih h hf (hr₁ hba hac)
· simp_all [hr₀ _]
· exact ih h hf
· simp_all
end ArgAux
section Preorder
variable [Preorder β] [DecidableLT β] {f : α → β} {l : List α} {a m : α}
/-- `argmax f l` returns `some a`, where `f a` is maximal among the elements of `l`, in the sense
that there is no `b ∈ l` with `f a < f b`. If `a`, `b` are such that `f a = f b`, it returns
whichever of `a` or `b` comes first in the list. `argmax f [] = none`. -/
def argmax (f : α → β) (l : List α) : Option α :=
l.foldl (argAux fun b c => f c < f b) none
/-- `argmin f l` returns `some a`, where `f a` is minimal among the elements of `l`, in the sense
that there is no `b ∈ l` with `f b < f a`. If `a`, `b` are such that `f a = f b`, it returns
whichever of `a` or `b` comes first in the list. `argmin f [] = none`. -/
def argmin (f : α → β) (l : List α) :=
l.foldl (argAux fun b c => f b < f c) none
@[simp]
theorem argmax_nil (f : α → β) : argmax f [] = none :=
rfl
@[simp]
theorem argmin_nil (f : α → β) : argmin f [] = none :=
rfl
@[simp]
theorem argmax_singleton {f : α → β} {a : α} : argmax f [a] = a :=
rfl
@[simp]
theorem argmin_singleton {f : α → β} {a : α} : argmin f [a] = a :=
rfl
theorem not_lt_of_mem_argmax : a ∈ l → m ∈ argmax f l → ¬f m < f a :=
not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h)
(fun _ _ z hxy hyz => lt_trans (a := f z) hyz hxy)
theorem not_lt_of_mem_argmin : a ∈ l → m ∈ argmin f l → ¬f a < f m :=
not_of_mem_foldl_argAux _ (fun x h => lt_irrefl (f x) h)
(fun x _ _ hxy hyz => lt_trans (a := f x) hxy hyz)
theorem argmax_concat (f : α → β) (a : α) (l : List α) :
argmax f (l ++ [a]) =
Option.casesOn (argmax f l) (some a) fun c => if f c < f a then some a else some c := by
rw [argmax, argmax]; simp [argAux]
theorem argmin_concat (f : α → β) (a : α) (l : List α) :
argmin f (l ++ [a]) =
Option.casesOn (argmin f l) (some a) fun c => if f a < f c then some a else some c :=
@argmax_concat _ βᵒᵈ _ _ _ _ _
theorem argmax_mem : ∀ {l : List α} {m : α}, m ∈ argmax f l → m ∈ l
| [], m => by simp
| hd :: tl, m => by simpa [argmax, argAux] using foldl_argAux_mem _ tl hd m
theorem argmin_mem : ∀ {l : List α} {m : α}, m ∈ argmin f l → m ∈ l :=
@argmax_mem _ βᵒᵈ _ _ _
@[simp]
theorem argmax_eq_none : l.argmax f = none ↔ l = [] := by simp [argmax]
@[simp]
theorem argmin_eq_none : l.argmin f = none ↔ l = [] :=
@argmax_eq_none _ βᵒᵈ _ _ _ _
end Preorder
section LinearOrder
variable [LinearOrder β] {f : α → β} {l : List α} {a m : α}
theorem le_of_mem_argmax : a ∈ l → m ∈ argmax f l → f a ≤ f m := fun ha hm =>
le_of_not_gt <| not_lt_of_mem_argmax ha hm
theorem le_of_mem_argmin : a ∈ l → m ∈ argmin f l → f m ≤ f a :=
@le_of_mem_argmax _ βᵒᵈ _ _ _ _ _
theorem argmax_cons (f : α → β) (a : α) (l : List α) :
argmax f (a :: l) =
Option.casesOn (argmax f l) (some a) fun c => if f a < f c then some c else some a :=
List.reverseRecOn l rfl fun hd tl ih => by
rw [← cons_append, argmax_concat, ih, argmax_concat]
rcases h : argmax f hd with - | m
· simp
dsimp
rw [← apply_ite, ← apply_ite]
dsimp
split_ifs <;> try rfl
· exact absurd (lt_trans ‹f a < f m› ‹_›) ‹_›
· cases (‹f a < f tl›.gt_or_lt _).elim ‹_› ‹_›
theorem argmin_cons (f : α → β) (a : α) (l : List α) :
argmin f (a :: l) =
Option.casesOn (argmin f l) (some a) fun c => if f c < f a then some c else some a :=
@argmax_cons α βᵒᵈ _ _ _ _
variable [DecidableEq α]
theorem index_of_argmax :
∀ {l : List α} {m : α}, m ∈ argmax f l → ∀ {a}, a ∈ l → f m ≤ f a → l.idxOf m ≤ l.idxOf a
| [], m, _, _, _, _ => by simp
| hd :: tl, m, hm, a, ha, ham => by
simp only [idxOf_cons, argmax_cons, Option.mem_def] at hm ⊢
cases h : argmax f tl
· rw [h] at hm
simp_all
rw [h] at hm
dsimp only at hm
simp only [cond_eq_if, beq_iff_eq]
obtain ha | ha := ha <;> split_ifs at hm <;> injection hm with hm <;> subst hm
· cases not_le_of_gt ‹_› ‹_›
· rw [if_pos rfl]
· rw [if_neg, if_neg]
· exact Nat.succ_le_succ (index_of_argmax h (by assumption) ham)
· exact ne_of_apply_ne f (lt_of_lt_of_le ‹_› ‹_›).ne
· exact ne_of_apply_ne _ ‹f hd < f _›.ne
· rw [if_pos rfl]
exact Nat.zero_le _
theorem index_of_argmin :
∀ {l : List α} {m : α}, m ∈ argmin f l → ∀ {a}, a ∈ l → f a ≤ f m → l.idxOf m ≤ l.idxOf a :=
@index_of_argmax _ βᵒᵈ _ _ _
theorem mem_argmax_iff :
m ∈ argmax f l ↔
m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.idxOf m ≤ l.idxOf a :=
⟨fun hm => ⟨argmax_mem hm, fun _ ha => le_of_mem_argmax ha hm, fun _ => index_of_argmax hm⟩,
by
rintro ⟨hml, ham, hma⟩
rcases harg : argmax f l with - | n
· simp_all
· have :=
_root_.le_antisymm (hma n (argmax_mem harg) (le_of_mem_argmax hml harg))
(index_of_argmax harg hml (ham _ (argmax_mem harg)))
rw [(idxOf_inj hml (argmax_mem harg)).1 this, Option.mem_def]⟩
theorem argmax_eq_some_iff :
argmax f l = some m ↔
m ∈ l ∧ (∀ a ∈ l, f a ≤ f m) ∧ ∀ a ∈ l, f m ≤ f a → l.idxOf m ≤ l.idxOf a :=
mem_argmax_iff
theorem mem_argmin_iff :
m ∈ argmin f l ↔
m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.idxOf m ≤ l.idxOf a :=
@mem_argmax_iff _ βᵒᵈ _ _ _ _ _
theorem argmin_eq_some_iff :
argmin f l = some m ↔
m ∈ l ∧ (∀ a ∈ l, f m ≤ f a) ∧ ∀ a ∈ l, f a ≤ f m → l.idxOf m ≤ l.idxOf a :=
mem_argmin_iff
end LinearOrder
section MaximumMinimum
section Preorder
variable [Preorder α] [DecidableLT α] {l : List α} {a m : α}
/-- `maximum l` returns a `WithBot α`, the largest element of `l` for nonempty lists, and `⊥` for
`[]` -/
def maximum (l : List α) : WithBot α :=
argmax id l
/-- `minimum l` returns a `WithTop α`, the smallest element of `l` for nonempty lists, and `⊤` for
`[]` -/
def minimum (l : List α) : WithTop α :=
argmin id l
@[simp]
theorem maximum_nil : maximum ([] : List α) = ⊥ :=
rfl
@[simp]
theorem minimum_nil : minimum ([] : List α) = ⊤ :=
rfl
@[simp]
theorem maximum_singleton (a : α) : maximum [a] = a :=
rfl
@[simp]
theorem minimum_singleton (a : α) : minimum [a] = a :=
rfl
theorem maximum_mem {l : List α} {m : α} : (maximum l : WithTop α) = m → m ∈ l :=
argmax_mem
theorem minimum_mem {l : List α} {m : α} : (minimum l : WithBot α) = m → m ∈ l :=
argmin_mem
@[simp]
theorem maximum_eq_bot {l : List α} : l.maximum = ⊥ ↔ l = [] :=
argmax_eq_none
@[simp]
theorem minimum_eq_top {l : List α} : l.minimum = ⊤ ↔ l = [] :=
argmin_eq_none
theorem not_maximum_lt_of_mem : a ∈ l → (maximum l : WithBot α) = m → ¬m < a :=
not_lt_of_mem_argmax
theorem not_lt_minimum_of_mem : a ∈ l → (minimum l : WithTop α) = m → ¬a < m :=
not_lt_of_mem_argmin
theorem not_maximum_lt_of_mem' (ha : a ∈ l) : ¬maximum l < (a : WithBot α) := by
cases h : l.maximum <;> simp_all [not_maximum_lt_of_mem ha]
theorem not_lt_minimum_of_mem' (ha : a ∈ l) : ¬(a : WithTop α) < minimum l := by
cases h : l.minimum <;> simp_all [not_lt_minimum_of_mem ha]
end Preorder
section LinearOrder
variable [LinearOrder α] {l : List α} {a m : α}
theorem maximum_concat (a : α) (l : List α) : maximum (l ++ [a]) = max (maximum l) a := by
simp only [maximum, argmax_concat, id]
cases argmax id l
· exact (max_eq_right bot_le).symm
· simp [WithBot.some_eq_coe, max_def_lt, WithBot.coe_lt_coe]
theorem le_maximum_of_mem : a ∈ l → (maximum l : WithBot α) = m → a ≤ m :=
le_of_mem_argmax
theorem minimum_le_of_mem : a ∈ l → (minimum l : WithTop α) = m → m ≤ a :=
le_of_mem_argmin
theorem le_maximum_of_mem' (ha : a ∈ l) : (a : WithBot α) ≤ maximum l :=
le_of_not_gt <| not_maximum_lt_of_mem' ha
theorem minimum_le_of_mem' (ha : a ∈ l) : minimum l ≤ (a : WithTop α) :=
le_of_not_gt <| not_lt_minimum_of_mem' ha
theorem minimum_concat (a : α) (l : List α) : minimum (l ++ [a]) = min (minimum l) a :=
@maximum_concat αᵒᵈ _ _ _
theorem maximum_cons (a : α) (l : List α) : maximum (a :: l) = max ↑a (maximum l) :=
List.reverseRecOn l (by simp) fun tl hd ih => by
rw [← cons_append, maximum_concat, ih, maximum_concat, max_assoc]
theorem minimum_cons (a : α) (l : List α) : minimum (a :: l) = min ↑a (minimum l) :=
@maximum_cons αᵒᵈ _ _ _
lemma maximum_append (l₁ l₂ : List α) : (l₁ ++ l₂).maximum = max l₁.maximum l₂.maximum := by
induction l₁ with
| nil => simp
| cons _ _ ih => rw [maximum_cons, cons_append, maximum_cons, ih, ← max_assoc]
lemma minimum_append (l₁ l₂ : List α) : (l₁ ++ l₂).minimum = min l₁.minimum l₂.minimum :=
@maximum_append αᵒᵈ _ _ _
theorem maximum_le_of_forall_le {b : WithBot α} (h : ∀ a ∈ l, a ≤ b) : l.maximum ≤ b := by
induction l with
| nil => simp
| cons a l ih =>
simp only [maximum_cons, max_le_iff]
exact ⟨h a (by simp), ih fun a w => h a (mem_cons.mpr (Or.inr w))⟩
theorem le_minimum_of_forall_le {b : WithTop α} (h : ∀ a ∈ l, b ≤ a) : b ≤ l.minimum := by
induction l with
| nil => simp
| cons a l ih =>
simp only [minimum_cons, le_min_iff]
exact ⟨h a (by simp), ih fun a w => h a (mem_cons.mpr (Or.inr w))⟩
theorem maximum_mono {l₁ l₂ : List α} (h : l₁ ⊆ l₂) : l₁.maximum ≤ l₂.maximum :=
maximum_le_of_forall_le fun _ ↦ (le_maximum_of_mem' <| h ·)
theorem minimum_anti {l₁ l₂ : List α} (h : l₁ ⊆ l₂) : l₂.minimum ≤ l₁.minimum :=
@maximum_mono αᵒᵈ _ _ _ h
theorem maximum_eq_coe_iff : maximum l = m ↔ m ∈ l ∧ ∀ a ∈ l, a ≤ m := by
rw [maximum, ← WithBot.some_eq_coe, argmax_eq_some_iff]
simp only [id_eq, and_congr_right_iff, and_iff_left_iff_imp]
intro _ h a hal hma
rw [_root_.le_antisymm hma (h a hal)]
theorem minimum_eq_coe_iff : minimum l = m ↔ m ∈ l ∧ ∀ a ∈ l, m ≤ a :=
@maximum_eq_coe_iff αᵒᵈ _ _ _
theorem coe_le_maximum_iff : a ≤ l.maximum ↔ ∃ b, b ∈ l ∧ a ≤ b := by
induction' l <;> simp [maximum_cons, *]
theorem minimum_le_coe_iff : l.minimum ≤ a ↔ ∃ b, b ∈ l ∧ b ≤ a := by
induction' l <;> simp [minimum_cons, *]
theorem maximum_ne_bot_of_ne_nil (h : l ≠ []) : l.maximum ≠ ⊥ :=
match l, h with | _ :: _, _ => by simp [maximum_cons]
theorem minimum_ne_top_of_ne_nil (h : l ≠ []) : l.minimum ≠ ⊤ :=
@maximum_ne_bot_of_ne_nil αᵒᵈ _ _ h
theorem maximum_ne_bot_of_length_pos (h : 0 < l.length) : l.maximum ≠ ⊥ :=
match l, h with | _ :: _, _ => by simp [maximum_cons]
theorem minimum_ne_top_of_length_pos (h : 0 < l.length) : l.minimum ≠ ⊤ :=
maximum_ne_bot_of_length_pos (α := αᵒᵈ) h
/-- The maximum value in a non-empty `List`. -/
def maximum_of_length_pos (h : 0 < l.length) : α :=
WithBot.unbot l.maximum (maximum_ne_bot_of_length_pos h)
/-- The minimum value in a non-empty `List`. -/
def minimum_of_length_pos (h : 0 < l.length) : α :=
maximum_of_length_pos (α := αᵒᵈ) h
@[simp]
lemma coe_maximum_of_length_pos (h : 0 < l.length) :
(l.maximum_of_length_pos h : α) = l.maximum :=
WithBot.coe_unbot _ _
@[simp]
lemma coe_minimum_of_length_pos (h : 0 < l.length) :
(l.minimum_of_length_pos h : α) = l.minimum :=
WithTop.coe_untop _ _
@[simp]
theorem le_maximum_of_length_pos_iff {b : α} (h : 0 < l.length) :
b ≤ maximum_of_length_pos h ↔ b ≤ l.maximum :=
WithBot.le_unbot_iff _
@[simp]
theorem minimum_of_length_pos_le_iff {b : α} (h : 0 < l.length) :
minimum_of_length_pos h ≤ b ↔ l.minimum ≤ b :=
WithTop.untop_le_iff _
theorem maximum_of_length_pos_mem (h : 0 < l.length) :
maximum_of_length_pos h ∈ l := by
apply maximum_mem
simp only [coe_maximum_of_length_pos]
theorem minimum_of_length_pos_mem (h : 0 < l.length) :
minimum_of_length_pos h ∈ l :=
maximum_of_length_pos_mem (α := αᵒᵈ) h
theorem le_maximum_of_length_pos_of_mem (h : a ∈ l) (w : 0 < l.length) :
a ≤ l.maximum_of_length_pos w := by
simp only [le_maximum_of_length_pos_iff]
exact le_maximum_of_mem' h
theorem minimum_of_length_pos_le_of_mem (h : a ∈ l) (w : 0 < l.length) :
l.minimum_of_length_pos w ≤ a :=
le_maximum_of_length_pos_of_mem (α := αᵒᵈ) h w
theorem getElem_le_maximum_of_length_pos {i : ℕ} (w : i < l.length) (h := (Nat.zero_lt_of_lt w)) :
l[i] ≤ l.maximum_of_length_pos h := by
apply le_maximum_of_length_pos_of_mem
exact getElem_mem _
theorem minimum_of_length_pos_le_getElem {i : ℕ} (w : i < l.length) (h := (Nat.zero_lt_of_lt w)) :
l.minimum_of_length_pos h ≤ l[i] :=
getElem_le_maximum_of_length_pos (α := αᵒᵈ) w
#adaptation_note
/-- 2025-08-14: We should stop using `max?_eq_some_iff_legacy` below, by connecting up Mathlib's
order typeclasses with the new classes in Lean. -/
set_option linter.deprecated false in
lemma getD_max?_eq_unbotD_maximum (l : List α) (d : α) : l.max?.getD d = l.maximum.unbotD d := by
cases hy : l.maximum with
| bot => simp [List.maximum_eq_bot.mp hy]
| coe y =>
rw [List.maximum_eq_coe_iff] at hy
simp only [WithBot.unbotD_coe]
cases hz : l.max? with
| none => simp [List.max?_eq_none_iff.mp hz] at hy
| some z =>
have : Std.Antisymm (α := α) (· ≤ ·) := ⟨fun _ _ => _root_.le_antisymm⟩
rw [List.max?_eq_some_iff_legacy] at hz
· rw [Option.getD_some]
exact _root_.le_antisymm (hy.right _ hz.left) (hz.right _ hy.left)
all_goals simp [le_total]
@[deprecated (since := "2025-02-06")]
alias getD_max?_eq_unbot'_maximum := getD_max?_eq_unbotD_maximum
lemma getD_min?_eq_untopD_minimum (l : List α) (d : α) : l.min?.getD d = l.minimum.untopD d :=
getD_max?_eq_unbotD_maximum (α := αᵒᵈ) _ _
@[deprecated (since := "2025-02-06")]
alias getD_min?_eq_untop'_minimum := getD_min?_eq_untopD_minimum
end LinearOrder
end MaximumMinimum
section Fold
variable [LinearOrder α]
section OrderBot
variable [OrderBot α] {l : List α}
@[simp]
theorem foldr_max_of_ne_nil (h : l ≠ []) : ↑(l.foldr max ⊥) = l.maximum := by
induction' l with hd tl IH
· contradiction
· rw [maximum_cons, foldr, WithBot.coe_max]
by_cases h : tl = []
· simp [h]
· simp [IH h]
theorem max_le_of_forall_le (l : List α) (a : α) (h : ∀ x ∈ l, x ≤ a) : l.foldr max ⊥ ≤ a := by
induction' l with y l IH
· simp
· simpa [h y mem_cons_self] using IH fun x hx => h x <| mem_cons_of_mem _ hx
theorem le_max_of_le {l : List α} {a x : α} (hx : x ∈ l) (h : a ≤ x) : a ≤ l.foldr max ⊥ := by
induction' l with y l IH
· exact absurd hx not_mem_nil
· obtain hl | hl := hx
· simp only [foldr]
exact le_max_of_le_left h
· exact le_max_of_le_right (IH (by assumption))
end OrderBot
section OrderTop
variable [OrderTop α] {l : List α}
@[simp]
theorem foldr_min_of_ne_nil (h : l ≠ []) : ↑(l.foldr min ⊤) = l.minimum :=
@foldr_max_of_ne_nil αᵒᵈ _ _ _ h
theorem le_min_of_forall_le (l : List α) (a : α) (h : ∀ x ∈ l, a ≤ x) : a ≤ l.foldr min ⊤ :=
@max_le_of_forall_le αᵒᵈ _ _ _ _ h
theorem min_le_of_le (l : List α) (a : α) {x : α} (hx : x ∈ l) (h : x ≤ a) : l.foldr min ⊤ ≤ a :=
@le_max_of_le αᵒᵈ _ _ _ _ _ hx h
end OrderTop
/-- If `a ≤ x` for some `x` in the list `l`, and `b : α`, then `a ≤ l.foldr max b`. -/
theorem le_max_of_le' {l : List α} {a x : α} (b : α) (hx : x ∈ l) (h : a ≤ x) :
a ≤ l.foldr max b := by
induction l with
| nil => exact absurd hx List.not_mem_nil
| cons y l IH =>
simp only [List.foldr]
obtain rfl | hl := mem_cons.mp hx
· exact le_max_of_le_left h
· exact le_max_of_le_right (IH hl)
theorem min_le_of_le' {l : List α} {a x : α} (b : α) (hx : x ∈ l) (h : x ≤ a) : l.foldr min b ≤ a :=
@le_max_of_le' αᵒᵈ _ _ _ _ _ hx h
end Fold
end List
|
Countable.lean
|
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.EssentiallySmall
import Mathlib.CategoryTheory.FinCategory.Basic
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Countable.Small
/-!
# Countable categories
A category is countable in this sense if it has countably many objects and countably many morphisms.
-/
universe w v u
noncomputable section
namespace CategoryTheory
instance discreteCountable {α : Type*} [Countable α] : Countable (Discrete α) :=
Countable.of_equiv α discreteEquiv.symm
/-- A category with countably many objects and morphisms. -/
class CountableCategory (J : Type*) [Category J] : Prop where
countableObj : Countable J := by infer_instance
countableHom : ∀ j j' : J, Countable (j ⟶ j') := by infer_instance
attribute [instance] CountableCategory.countableObj CountableCategory.countableHom
instance countableCategoryDiscreteOfCountable (J : Type*) [Countable J] :
CountableCategory (Discrete J) where
instance : CountableCategory ℕ where
namespace CountableCategory
variable (α : Type u) [Category.{v} α] [CountableCategory α]
/-- A countable category `α` is equivalent to a category with objects in `Type`. -/
abbrev ObjAsType : Type :=
InducedCategory α (equivShrink.{0} α).symm
instance : Countable (ObjAsType α) := Countable.of_equiv α (equivShrink.{0} α)
instance {i j : ObjAsType α} : Countable (i ⟶ j) :=
CountableCategory.countableHom ((equivShrink.{0} α).symm i) _
instance : CountableCategory (ObjAsType α) where
/-- The constructed category is indeed equivalent to `α`. -/
noncomputable def objAsTypeEquiv : ObjAsType α ≌ α :=
(inducedFunctor (equivShrink.{0} α).symm).asEquivalence
/-- A countable category `α` is equivalent to a *small* category with objects in `Type`. -/
def HomAsType := ShrinkHoms (ObjAsType α)
instance : LocallySmall.{0} (ObjAsType α) where
hom_small _ _ := inferInstance
instance : SmallCategory (HomAsType α) := inferInstanceAs <| SmallCategory (ShrinkHoms _)
instance : Countable (HomAsType α) := Countable.of_equiv α (equivShrink.{0} α)
instance {i j : HomAsType α} : Countable (i ⟶ j) :=
Countable.of_equiv ((ShrinkHoms.equivalence _).inverse.obj i ⟶
(ShrinkHoms.equivalence _).inverse.obj j)
(Functor.FullyFaithful.ofFullyFaithful _).homEquiv.symm
instance : CountableCategory (HomAsType α) where
/-- The constructed category is indeed equivalent to `α`. -/
noncomputable def homAsTypeEquiv : HomAsType α ≌ α :=
(ShrinkHoms.equivalence _).symm.trans (objAsTypeEquiv _)
end CountableCategory
instance (α : Type*) [Category α] [FinCategory α] : CountableCategory α where
open Opposite
/-- The opposite of a countable category is countable. -/
instance countableCategoryOpposite {J : Type*} [Category J] [CountableCategory J] :
CountableCategory Jᵒᵖ where
countableObj := Countable.of_equiv _ equivToOpposite
countableHom j j' := Countable.of_equiv _ (opEquiv j j').symm
attribute [local instance] uliftCategory in
/-- Applying `ULift` to morphisms and objects of a category preserves countability. -/
instance countableCategoryUlift {J : Type v} [Category J] [CountableCategory J] :
CountableCategory.{max w v} (ULiftHom.{w, max w v} (ULift.{w, v} J)) where
countableObj := instCountableULift
countableHom := fun i j =>
have : Countable ((ULiftHom.objDown i).down ⟶ (ULiftHom.objDown j).down) := inferInstance
instCountableULift
end CategoryTheory
|
TermCongr2.lean
|
import Mathlib.Tactic.TermCongr
import Mathlib.Data.Fintype.Card
import Mathlib.Tactic.Ring
/-!
`congr(...)` tests with heavier imports (`TermCongr` is in `Mathlib/Tactic/Common.lean`)
-/
namespace Tests
set_option autoImplicit true
-- set_option trace.Elab.congr true
example [Fintype α] [Fintype β] (h : α = β) : Fintype.card α = Fintype.card β :=
congr(Fintype.card $h)
example (s t : Set α) [Fintype s] [Fintype t] (h : s = t) : Fintype.card s = Fintype.card t :=
congr(Fintype.card $h)
example (x y : ℤ) (h1 : 3 * x + 2 * y = 10) (h2 : 2 * x + 5 * y = 3) :
11*y = -11 := by
have := congr(-2*$h1 + 3*$h2)
guard_hyp this : -2*(3*x + 2*y) + 3*(2*x + 5*y) = -2*10 + 3*3
ring_nf at this ⊢
exact this
example (a b c d : ℚ) (h1 : a = 4) (h2 : 3 = b) (h3 : c * 3 = d) (h4 : -d = a) :
2*a - 3 + 9*c + 3*d = 8 - b + 3*d - 3*a := by
have := congr(2*$h1 -1*$h2 +3*$h3 -3*$h4)
guard_hyp this : 2*a - 1*3 + 3*(c*3) -3*(-d) = 2*4 - 1*b + 3*d - 3*a
ring_nf at this ⊢
exact this
end Tests
|
SuppressCompilation.lean
|
/-
Copyright (c) 2023 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best, Mac Malone
-/
import Mathlib.Init
import Lean.Elab.Declaration
import Lean.Elab.Notation
/-!
# Suppressing compilation to executable code in a file or in a section
Currently, the compiler may spend a lot of time trying to produce executable code for complicated
definitions. This is a waste of resources for definitions in area of mathematics that will never
lead to executable code. The command `suppress_compilation` is a hack to disable code generation
on all definitions (in a section or in a whole file). See the issue https://github.com/leanprover-community/mathlib4/issues/7103
To compile a definition even when `suppress_compilation` is active, use
`unsuppress_compilation in def foo : ...`. This is activated by default on notations to make
sure that they work properly.
Note that `suppress_compilation` does not work with `notation3`. You need to prefix such a notation
declaration with `unsuppress_compilation` if `suppress_compilation` is active.
-/
open Lean Parser Elab Command
/-- Replacing `def` and `instance` by `noncomputable def` and `noncomputable instance`, designed
to disable the compiler in a given file or a given section.
This is a hack to work around https://github.com/leanprover-community/mathlib4/issues/7103. -/
def elabSuppressCompilationDecl : CommandElab := fun
| `($[$doc?:docComment]? $(attrs?)? $(vis?)? $[noncomputable]? $(unsafe?)?
$(recKind?)? def $id $sig:optDeclSig $val:declVal) => do
elabDeclaration <| ← `($[$doc?:docComment]? $(attrs?)? $(vis?)? noncomputable $(unsafe?)?
$(recKind?)? def $id $sig:optDeclSig $val:declVal)
| `($[$doc?:docComment]? $(attrs?)? $(vis?)? $[noncomputable]? $(unsafe?)?
$(recKind?)? def $id $sig:optDeclSig $val:declVal deriving $derivs,*) => do
elabDeclaration <| ← `($[$doc?:docComment]? $(attrs?)? $(vis?)? noncomputable $(unsafe?)?
$(recKind?)? def $id $sig:optDeclSig $val:declVal deriving $derivs,*)
| `($[$doc?:docComment]? $(attrs?)? $(vis?)? $[noncomputable]? $(unsafe?)?
$(recKind?)? $(attrKind?)? instance $(prio?)? $(id?)? $sig:declSig $val:declVal) => do
elabDeclaration <| ← `($[$doc?:docComment]? $(attrs?)? $(vis?)? noncomputable $(unsafe?)?
$(recKind?)? $(attrKind?)? instance $(prio?)? $(id?)? $sig:declSig $val:declVal)
| `($[$doc?:docComment]? $(attrs?)? $(vis?)? $[noncomputable]? $(unsafe?)?
$(recKind?)? example $sig:optDeclSig $val:declVal) => do
elabDeclaration <| ← `($[$doc?:docComment]? $(attrs?)? $(vis?)? noncomputable $(unsafe?)?
$(recKind?)? example $sig:optDeclSig $val:declVal)
| `($[$doc?:docComment]? $(attrs?)? $(vis?)? $[noncomputable]? $(unsafe?)?
$(recKind?)? abbrev $id $sig:optDeclSig $val:declVal) => do
elabDeclaration <| ← `($[$doc?:docComment]? $(attrs?)? $(vis?)? noncomputable $(unsafe?)?
$(recKind?)? abbrev $id $sig:optDeclSig $val:declVal)
| _ => throwUnsupportedSyntax
/-- The command `unsuppress_compilation in def foo : ...` makes sure that the definition is
compiled to executable code, even if `suppress_compilation` is active. -/
syntax "unsuppress_compilation" (" in " command)? : command
/-- Make sure that notations are compiled, even if `suppress_compilation` is active, by prepending
them with `unsuppress_compilation`. -/
def expandSuppressCompilationNotation : Macro := fun
| `($[$doc?:docComment]? $(attrs?)? $(attrKind)? notation
$(prec?)? $(name?)? $(prio?)? $items* => $v) => do
let defn ← expandNotation <| ← `($[$doc?:docComment]? $(attrs?)? $(attrKind)? notation
$(prec?)? $(name?)? $(prio?)? $items* => $v)
`(unsuppress_compilation in $(⟨defn⟩):command)
| _ => Macro.throwUnsupported
/-- Replacing `def` and `instance` by `noncomputable def` and `noncomputable instance`, designed
to disable the compiler in a given file or a given section.
This is a hack to work around https://github.com/leanprover-community/mathlib4/issues/7103.
Note that it does not work with `notation3`. You need to prefix such a notation declaration with
`unsuppress_compilation` if `suppress_compilation` is active. -/
macro "suppress_compilation" : command => do
let declKind := mkIdent ``declaration
let notaKind := mkIdent ``«notation»
let declElab := mkCIdent ``elabSuppressCompilationDecl
let notaMacro := mkCIdent ``expandSuppressCompilationNotation
`(
attribute [local command_elab $declKind] $declElab
attribute [local macro $notaKind] $notaMacro
)
/-- The command `unsuppress_compilation in def foo : ...` makes sure that the definition is
compiled to executable code, even if `suppress_compilation` is active. -/
macro_rules
| `(unsuppress_compilation $[in $cmd?]?) => do
let declElab := mkCIdent ``elabSuppressCompilationDecl
let notaMacro := mkCIdent ``expandSuppressCompilationNotation
let attrCmds ← `(
attribute [-command_elab] $declElab
attribute [-macro] $notaMacro
)
if let some cmd := cmd? then
`($attrCmds:command $cmd:command suppress_compilation)
else
return attrCmds
|
Defs.lean
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Patrick Massot, Sébastien Gouëzel, Zhouhang Zhou, Reid Barton
-/
import Mathlib.Topology.ContinuousMap.Defs
import Mathlib.Topology.Maps.Basic
/-!
# Homeomorphisms
This file defines homeomorphisms between two topological spaces. They are bijections with both
directions continuous. We denote homeomorphisms with the notation `≃ₜ`.
# Main definitions and results
* `Homeomorph X Y`: The type of homeomorphisms from `X` to `Y`.
This type can be denoted using the following notation: `X ≃ₜ Y`.
* `HomeomorphClass`: `HomeomorphClass F A B` states that `F` is a type of homeomorphisms.
* `Homeomorph.symm`: the inverse of a homeomorphism
* `Homeomorph.trans`: composing two homeomorphisms
* Homeomorphisms are open and closed embeddings, inducing, quotient maps etc.
* `Homeomorph.homeomorphOfContinuousOpen`: A continuous bijection that is
an open map is a homeomorphism.
* `Homeomorph.homeomorphOfUnique`: if both `X` and `Y` have a unique element, then `X ≃ₜ Y`.
* `Equiv.toHomeomorph`: an equivalence between topological spaces respecting openness
is a homeomorphism.
* `IsHomeomorph`: the predicate that a function is a homeomorphism
-/
open Set Topology Filter
variable {X Y W Z : Type*}
/-- Homeomorphism between `X` and `Y`, also called topological isomorphism -/
structure Homeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y]
extends X ≃ Y where
/-- The forward map of a homeomorphism is a continuous function. -/
continuous_toFun : Continuous toFun := by continuity
/-- The inverse map of a homeomorphism is a continuous function. -/
continuous_invFun : Continuous invFun := by continuity
@[inherit_doc]
infixl:25 " ≃ₜ " => Homeomorph
namespace Homeomorph
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace W] [TopologicalSpace Z]
{X' Y' : Type*} [TopologicalSpace X'] [TopologicalSpace Y']
theorem toEquiv_injective : Function.Injective (toEquiv : X ≃ₜ Y → X ≃ Y)
| ⟨_, _, _⟩, ⟨_, _, _⟩, rfl => rfl
instance : EquivLike (X ≃ₜ Y) X Y where
coe h := h.toEquiv
inv h := h.toEquiv.symm
left_inv h := h.left_inv
right_inv h := h.right_inv
coe_injective' _ _ H _ := toEquiv_injective <| DFunLike.ext' H
@[simp] theorem homeomorph_mk_coe (a : X ≃ Y) (b c) : (Homeomorph.mk a b c : X → Y) = a :=
rfl
/-- The unique homeomorphism between two empty types. -/
protected def empty [IsEmpty X] [IsEmpty Y] : X ≃ₜ Y where
__ := Equiv.equivOfIsEmpty X Y
/-- Inverse of a homeomorphism. -/
@[symm]
protected def symm (h : X ≃ₜ Y) : Y ≃ₜ X where
continuous_toFun := h.continuous_invFun
continuous_invFun := h.continuous_toFun
toEquiv := h.toEquiv.symm
@[simp] theorem symm_symm (h : X ≃ₜ Y) : h.symm.symm = h := rfl
theorem symm_bijective : Function.Bijective (Homeomorph.symm : (X ≃ₜ Y) → Y ≃ₜ X) :=
Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩
/-- See Note [custom simps projection] -/
def Simps.symm_apply (h : X ≃ₜ Y) : Y → X :=
h.symm
initialize_simps_projections Homeomorph (toFun → apply, invFun → symm_apply)
@[simp]
theorem coe_toEquiv (h : X ≃ₜ Y) : ⇑h.toEquiv = h :=
rfl
@[simp]
theorem coe_symm_toEquiv (h : X ≃ₜ Y) : ⇑h.toEquiv.symm = h.symm :=
rfl
@[ext]
theorem ext {h h' : X ≃ₜ Y} (H : ∀ x, h x = h' x) : h = h' :=
DFunLike.ext _ _ H
/-- Identity map as a homeomorphism. -/
@[simps! -fullyApplied apply]
protected def refl (X : Type*) [TopologicalSpace X] : X ≃ₜ X where
continuous_toFun := continuous_id
continuous_invFun := continuous_id
toEquiv := Equiv.refl X
/-- Composition of two homeomorphisms. -/
@[trans]
protected def trans (h₁ : X ≃ₜ Y) (h₂ : Y ≃ₜ Z) : X ≃ₜ Z where
continuous_toFun := h₂.continuous_toFun.comp h₁.continuous_toFun
continuous_invFun := h₁.continuous_invFun.comp h₂.continuous_invFun
toEquiv := Equiv.trans h₁.toEquiv h₂.toEquiv
@[simp]
theorem trans_apply (h₁ : X ≃ₜ Y) (h₂ : Y ≃ₜ Z) (x : X) : h₁.trans h₂ x = h₂ (h₁ x) :=
rfl
@[simp]
theorem symm_trans_apply (f : X ≃ₜ Y) (g : Y ≃ₜ Z) (z : Z) :
(f.trans g).symm z = f.symm (g.symm z) := rfl
@[simp]
theorem homeomorph_mk_coe_symm (a : X ≃ Y) (b c) :
((Homeomorph.mk a b c).symm : Y → X) = a.symm :=
rfl
@[simp]
theorem refl_symm : (Homeomorph.refl X).symm = Homeomorph.refl X :=
rfl
@[continuity, fun_prop]
protected theorem continuous (h : X ≃ₜ Y) : Continuous h :=
h.continuous_toFun
-- otherwise `by continuity` can't prove continuity of `h.to_equiv.symm`
@[continuity]
protected theorem continuous_symm (h : X ≃ₜ Y) : Continuous h.symm :=
h.continuous_invFun
@[simp]
theorem apply_symm_apply (h : X ≃ₜ Y) (y : Y) : h (h.symm y) = y :=
h.toEquiv.apply_symm_apply y
@[simp]
theorem symm_apply_apply (h : X ≃ₜ Y) (x : X) : h.symm (h x) = x :=
h.toEquiv.symm_apply_apply x
@[simp]
theorem self_trans_symm (h : X ≃ₜ Y) : h.trans h.symm = Homeomorph.refl X := by
ext
apply symm_apply_apply
@[simp]
theorem symm_trans_self (h : X ≃ₜ Y) : h.symm.trans h = Homeomorph.refl Y := by
ext
apply apply_symm_apply
protected theorem bijective (h : X ≃ₜ Y) : Function.Bijective h :=
h.toEquiv.bijective
protected theorem injective (h : X ≃ₜ Y) : Function.Injective h :=
h.toEquiv.injective
protected theorem surjective (h : X ≃ₜ Y) : Function.Surjective h :=
h.toEquiv.surjective
/-- Change the homeomorphism `f` to make the inverse function definitionally equal to `g`. -/
def changeInv (f : X ≃ₜ Y) (g : Y → X) (hg : Function.RightInverse g f) : X ≃ₜ Y :=
haveI : g = f.symm := (f.left_inv.eq_rightInverse hg).symm
{ toFun := f
invFun := g
left_inv := by convert f.left_inv
right_inv := by convert f.right_inv using 1
continuous_toFun := f.continuous
continuous_invFun := by convert f.symm.continuous }
@[simp]
theorem symm_comp_self (h : X ≃ₜ Y) : h.symm ∘ h = id :=
funext h.symm_apply_apply
@[simp]
theorem self_comp_symm (h : X ≃ₜ Y) : h ∘ h.symm = id :=
funext h.apply_symm_apply
theorem range_coe (h : X ≃ₜ Y) : range h = univ := by simp
theorem image_symm (h : X ≃ₜ Y) : image h.symm = preimage h :=
funext h.symm.toEquiv.image_eq_preimage
theorem preimage_symm (h : X ≃ₜ Y) : preimage h.symm = image h :=
(funext h.toEquiv.image_eq_preimage).symm
@[simp]
theorem image_preimage (h : X ≃ₜ Y) (s : Set Y) : h '' (h ⁻¹' s) = s :=
h.toEquiv.image_preimage s
@[simp]
theorem preimage_image (h : X ≃ₜ Y) (s : Set X) : h ⁻¹' (h '' s) = s :=
h.toEquiv.preimage_image s
theorem image_eq_preimage (h : X ≃ₜ Y) (s : Set X) : h '' s = h.symm ⁻¹' s :=
h.toEquiv.image_eq_preimage s
lemma image_compl (h : X ≃ₜ Y) (s : Set X) : h '' (sᶜ) = (h '' s)ᶜ :=
h.toEquiv.image_compl s
lemma isInducing (h : X ≃ₜ Y) : IsInducing h :=
.of_comp h.continuous h.symm.continuous <| by simp only [symm_comp_self, IsInducing.id]
theorem induced_eq (h : X ≃ₜ Y) : TopologicalSpace.induced h ‹_› = ‹_› := h.isInducing.1.symm
theorem isQuotientMap (h : X ≃ₜ Y) : IsQuotientMap h :=
IsQuotientMap.of_comp h.symm.continuous h.continuous <| by
simp only [self_comp_symm, IsQuotientMap.id]
theorem coinduced_eq (h : X ≃ₜ Y) : TopologicalSpace.coinduced h ‹_› = ‹_› :=
h.isQuotientMap.2.symm
theorem isEmbedding (h : X ≃ₜ Y) : IsEmbedding h := ⟨h.isInducing, h.injective⟩
protected theorem discreteTopology [DiscreteTopology X] (h : X ≃ₜ Y) : DiscreteTopology Y :=
h.symm.isEmbedding.discreteTopology
theorem discreteTopology_iff (h : X ≃ₜ Y) : DiscreteTopology X ↔ DiscreteTopology Y :=
⟨fun _ ↦ h.discreteTopology, fun _ ↦ h.symm.discreteTopology⟩
@[simp]
theorem isOpen_preimage (h : X ≃ₜ Y) {s : Set Y} : IsOpen (h ⁻¹' s) ↔ IsOpen s :=
h.isQuotientMap.isOpen_preimage
@[simp]
theorem isOpen_image (h : X ≃ₜ Y) {s : Set X} : IsOpen (h '' s) ↔ IsOpen s := by
rw [← preimage_symm, isOpen_preimage]
protected theorem isOpenMap (h : X ≃ₜ Y) : IsOpenMap h := fun _ => h.isOpen_image.2
protected theorem isOpenQuotientMap (h : X ≃ₜ Y) : IsOpenQuotientMap h :=
⟨h.surjective, h.continuous, h.isOpenMap⟩
@[simp]
theorem isClosed_preimage (h : X ≃ₜ Y) {s : Set Y} : IsClosed (h ⁻¹' s) ↔ IsClosed s := by
simp only [← isOpen_compl_iff, ← preimage_compl, isOpen_preimage]
@[simp]
theorem isClosed_image (h : X ≃ₜ Y) {s : Set X} : IsClosed (h '' s) ↔ IsClosed s := by
rw [← preimage_symm, isClosed_preimage]
protected theorem isClosedMap (h : X ≃ₜ Y) : IsClosedMap h := fun _ => h.isClosed_image.2
theorem isOpenEmbedding (h : X ≃ₜ Y) : IsOpenEmbedding h :=
.of_isEmbedding_isOpenMap h.isEmbedding h.isOpenMap
theorem isClosedEmbedding (h : X ≃ₜ Y) : IsClosedEmbedding h :=
.of_isEmbedding_isClosedMap h.isEmbedding h.isClosedMap
theorem preimage_closure (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' closure s = closure (h ⁻¹' s) :=
h.isOpenMap.preimage_closure_eq_closure_preimage h.continuous _
theorem image_closure (h : X ≃ₜ Y) (s : Set X) : h '' closure s = closure (h '' s) := by
rw [← preimage_symm, preimage_closure]
theorem preimage_interior (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' interior s = interior (h ⁻¹' s) :=
h.isOpenMap.preimage_interior_eq_interior_preimage h.continuous _
theorem image_interior (h : X ≃ₜ Y) (s : Set X) : h '' interior s = interior (h '' s) := by
rw [← preimage_symm, preimage_interior]
theorem preimage_frontier (h : X ≃ₜ Y) (s : Set Y) : h ⁻¹' frontier s = frontier (h ⁻¹' s) :=
h.isOpenMap.preimage_frontier_eq_frontier_preimage h.continuous _
theorem image_frontier (h : X ≃ₜ Y) (s : Set X) : h '' frontier s = frontier (h '' s) := by
rw [← preimage_symm, preimage_frontier]
@[simp]
theorem comp_continuous_iff (h : X ≃ₜ Y) {f : Z → X} : Continuous (h ∘ f) ↔ Continuous f :=
h.isInducing.continuous_iff.symm
@[simp]
theorem comp_continuous_iff' (h : X ≃ₜ Y) {f : Y → Z} : Continuous (f ∘ h) ↔ Continuous f :=
h.isQuotientMap.continuous_iff.symm
theorem comp_continuousAt_iff (h : X ≃ₜ Y) (f : Z → X) (z : Z) :
ContinuousAt (h ∘ f) z ↔ ContinuousAt f z :=
h.isInducing.continuousAt_iff.symm
theorem comp_continuousAt_iff' (h : X ≃ₜ Y) (f : Y → Z) (x : X) :
ContinuousAt (f ∘ h) x ↔ ContinuousAt f (h x) :=
h.isInducing.continuousAt_iff' (by simp)
@[simp]
theorem comp_isOpenMap_iff (h : X ≃ₜ Y) {f : Z → X} : IsOpenMap (h ∘ f) ↔ IsOpenMap f := by
refine ⟨?_, fun hf => h.isOpenMap.comp hf⟩
intro hf
rw [← Function.id_comp f, ← h.symm_comp_self, Function.comp_assoc]
exact h.symm.isOpenMap.comp hf
@[simp]
theorem comp_isOpenMap_iff' (h : X ≃ₜ Y) {f : Y → Z} : IsOpenMap (f ∘ h) ↔ IsOpenMap f := by
refine ⟨?_, fun hf => hf.comp h.isOpenMap⟩
intro hf
rw [← Function.comp_id f, ← h.self_comp_symm, ← Function.comp_assoc]
exact hf.comp h.symm.isOpenMap
variable (X Y) in
/-- If both `X` and `Y` have a unique element, then `X ≃ₜ Y`. -/
@[simps!]
def homeomorphOfUnique [Unique X] [Unique Y] : X ≃ₜ Y :=
{ Equiv.ofUnique X Y with
continuous_toFun := continuous_const
continuous_invFun := continuous_const }
@[simp]
theorem map_nhds_eq (h : X ≃ₜ Y) (x : X) : map h (𝓝 x) = 𝓝 (h x) :=
h.isEmbedding.map_nhds_of_mem _ (by simp)
theorem symm_map_nhds_eq (h : X ≃ₜ Y) (x : X) : map h.symm (𝓝 (h x)) = 𝓝 x := by
rw [h.symm.map_nhds_eq, h.symm_apply_apply]
theorem nhds_eq_comap (h : X ≃ₜ Y) (x : X) : 𝓝 x = comap h (𝓝 (h x)) :=
h.isInducing.nhds_eq_comap x
@[simp]
theorem comap_nhds_eq (h : X ≃ₜ Y) (y : Y) : comap h (𝓝 y) = 𝓝 (h.symm y) := by
rw [h.nhds_eq_comap, h.apply_symm_apply]
end Homeomorph
namespace Equiv
variable {Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z]
/-- An equivalence between topological spaces respecting openness is a homeomorphism. -/
@[simps toEquiv]
def toHomeomorph (e : X ≃ Y) (he : ∀ s, IsOpen (e ⁻¹' s) ↔ IsOpen s) : X ≃ₜ Y where
toEquiv := e
continuous_toFun := continuous_def.2 fun _ ↦ (he _).2
continuous_invFun := continuous_def.2 fun s ↦ by convert (he _).1; simp
@[simp] lemma coe_toHomeomorph (e : X ≃ Y) (he) : ⇑(e.toHomeomorph he) = e := rfl
lemma toHomeomorph_apply (e : X ≃ Y) (he) (x : X) : e.toHomeomorph he x = e x := rfl
@[simp] lemma toHomeomorph_refl :
(Equiv.refl X).toHomeomorph (fun _s ↦ Iff.rfl) = Homeomorph.refl _ := rfl
@[simp] lemma toHomeomorph_symm (e : X ≃ Y) (he) :
(e.toHomeomorph he).symm = e.symm.toHomeomorph fun s ↦ by convert (he _).symm; simp := rfl
lemma toHomeomorph_trans (e : X ≃ Y) (f : Y ≃ Z) (he hf) :
(e.trans f).toHomeomorph (fun _s ↦ (he _).trans (hf _)) =
(e.toHomeomorph he).trans (f.toHomeomorph hf) := rfl
/-- An inducing equiv between topological spaces is a homeomorphism. -/
@[simps toEquiv]
def toHomeomorphOfIsInducing (f : X ≃ Y) (hf : IsInducing f) : X ≃ₜ Y :=
{ f with
continuous_toFun := hf.continuous
continuous_invFun := hf.continuous_iff.2 <| by simpa using continuous_id }
@[simp] lemma toHomeomorphOfIsInducing_apply (f : X ≃ Y) (hf : IsInducing f) :
⇑(f.toHomeomorphOfIsInducing hf) = f := rfl
@[simp] lemma toHomeomorphOfIsInducing_symm_apply (f : X ≃ Y) (hf : IsInducing f) :
⇑(f.toHomeomorphOfIsInducing hf).symm = f.symm := rfl
/-- If a bijective map `e : X ≃ Y` is continuous and open, then it is a homeomorphism. -/
@[simps! toEquiv]
def toHomeomorphOfContinuousOpen (e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsOpenMap e) : X ≃ₜ Y :=
e.toHomeomorphOfIsInducing <|
IsOpenEmbedding.of_continuous_injective_isOpenMap h₁ e.injective h₂ |>.toIsInducing
@[deprecated (since := "2025-04-16")]
alias _root_.Homeomorph.homeomorphOfContinuousOpen := toHomeomorphOfContinuousOpen
@[deprecated (since := "2025-04-16")]
alias _root_.Homeomorph.homeomorphOfContinuousOpen_toEquiv := toHomeomorphOfContinuousOpen_toEquiv
@[simp]
theorem toHomeomorphOfContinuousOpen_apply (e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsOpenMap e) :
⇑(e.toHomeomorphOfContinuousOpen h₁ h₂) = e := rfl
@[deprecated (since := "2025-04-16")]
alias _root_.Homeomorph.homeomorphOfContinuousOpen_apply := toHomeomorphOfContinuousOpen_apply
@[simp]
theorem toHomeomorphOfContinuousOpen_symm_apply (e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsOpenMap e) :
⇑(e.toHomeomorphOfContinuousOpen h₁ h₂).symm = e.symm := rfl
@[deprecated (since := "2025-04-16")]
alias _root_.Homeomorph.homeomorphOfContinuousOpen_symm_apply :=
toHomeomorphOfContinuousOpen_symm_apply
/-- If a bijective map `e : X ≃ Y` is continuous and open, then it is a homeomorphism. -/
@[simps! toEquiv]
def toHomeomorphOfContinuousClosed (e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsClosedMap e) : X ≃ₜ Y :=
e.toHomeomorphOfIsInducing <|
IsClosedEmbedding.of_continuous_injective_isClosedMap h₁ e.injective h₂ |>.toIsInducing
@[deprecated (since := "2025-04-16")]
alias _root_.Homeomorph.homeomorphOfContinuousClosed := toHomeomorphOfContinuousClosed
@[simp]
theorem toHomeomorphOfContinuousClosed_apply (e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsClosedMap e) :
⇑(e.toHomeomorphOfContinuousClosed h₁ h₂) = e := rfl
@[simp]
theorem toHomeomorphOfContinuousClosed_symm_apply
(e : X ≃ Y) (h₁ : Continuous e) (h₂ : IsClosedMap e) :
⇑(e.toHomeomorphOfContinuousClosed h₁ h₂).symm = e.symm := rfl
end Equiv
/-- `HomeomorphClass F A B` states that `F` is a type of homeomorphisms. -/
class HomeomorphClass (F : Type*) (A B : outParam Type*)
[TopologicalSpace A] [TopologicalSpace B] [h : EquivLike F A B] : Prop where
map_continuous : ∀ (f : F), Continuous f
inv_continuous : ∀ (f : F), Continuous (h.inv f)
namespace HomeomorphClass
variable {F α β : Type*} [TopologicalSpace α] [TopologicalSpace β] [EquivLike F α β]
/-- Turn an element of a type `F` satisfying `HomeomorphClass F α β` into an actual
`Homeomorph`. This is declared as the default coercion from `F` to `α ≃ₜ β`. -/
@[coe]
def toHomeomorph [h : HomeomorphClass F α β] (f : F) : α ≃ₜ β :=
{ (f : α ≃ β) with
continuous_toFun := h.map_continuous f
continuous_invFun := h.inv_continuous f }
@[simp]
theorem coe_coe [h : HomeomorphClass F α β] (f : F) : ⇑(h.toHomeomorph f) = ⇑f := rfl
instance [HomeomorphClass F α β] : CoeOut F (α ≃ₜ β) :=
⟨HomeomorphClass.toHomeomorph⟩
theorem toHomeomorph_injective [HomeomorphClass F α β] : Function.Injective ((↑) : F → α ≃ₜ β) :=
fun _ _ e ↦ DFunLike.ext _ _ fun a ↦ congr_arg (fun e : α ≃ₜ β ↦ e.toFun a) e
instance [HomeomorphClass F α β] : ContinuousMapClass F α β where
map_continuous f := map_continuous f
instance : HomeomorphClass (α ≃ₜ β) α β where
map_continuous e := e.continuous_toFun
inv_continuous e := e.continuous_invFun
end HomeomorphClass
section IsHomeomorph
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] {f : X → Y}
/-- Predicate saying that `f` is a homeomorphism.
This should be used only when `f` is a concrete function whose continuous inverse is not easy to
write down. Otherwise, `Homeomorph` should be preferred as it bundles the continuous inverse.
Having both `Homeomorph` and `IsHomeomorph` is justified by the fact that so many function
properties are unbundled in the topology part of the library, and by the fact that a homeomorphism
is not merely a continuous bijection, that is `IsHomeomorph f` is not equivalent to
`Continuous f ∧ Bijective f` but to `Continuous f ∧ Bijective f ∧ IsOpenMap f`. -/
structure IsHomeomorph (f : X → Y) : Prop where
continuous : Continuous f
isOpenMap : IsOpenMap f
bijective : Function.Bijective f
protected theorem Homeomorph.isHomeomorph (h : X ≃ₜ Y) : IsHomeomorph h :=
⟨h.continuous, h.isOpenMap, h.bijective⟩
namespace IsHomeomorph
protected lemma injective (hf : IsHomeomorph f) : Function.Injective f := hf.bijective.injective
protected lemma surjective (hf : IsHomeomorph f) : Function.Surjective f := hf.bijective.surjective
protected lemma id : IsHomeomorph (@id X) := ⟨continuous_id, .id, Function.bijective_id⟩
lemma comp {g : Y → Z} (hg : IsHomeomorph g) (hf : IsHomeomorph f) : IsHomeomorph (g ∘ f) :=
⟨hg.1.comp hf.1, hg.2.comp hf.2, hg.3.comp hf.3⟩
end IsHomeomorph
end IsHomeomorph
|
Basic.lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Group.WithOne.Defs
/-!
# More operations on `WithOne` and `WithZero`
This file defines various bundled morphisms on `WithOne` and `WithZero`
that were not available in `Algebra/Group/WithOne/Defs`.
## Main definitions
* `WithOne.lift`, `WithZero.lift`
* `WithOne.map`, `WithZero.map`
-/
assert_not_exists MonoidWithZero DenselyOrdered
universe u v w
variable {α : Type u} {β : Type v} {γ : Type w}
namespace WithOne
@[to_additive]
instance instInvolutiveInv [InvolutiveInv α] : InvolutiveInv (WithOne α) where
inv_inv a := (Option.map_map _ _ _).trans <| by simp_rw [inv_comp_inv, Option.map_id, id]
section
/-- `WithOne.coe` as a bundled morphism -/
@[to_additive (attr := simps apply) /-- `WithZero.coe` as a bundled morphism -/]
def coeMulHom [Mul α] : α →ₙ* WithOne α where
toFun := coe
map_mul' _ _ := rfl
end
section lift
variable [Mul α] [MulOneClass β]
/-- Lift a semigroup homomorphism `f` to a bundled monoid homomorphism. -/
@[to_additive /-- Lift an add semigroup homomorphism `f` to a bundled add monoid homomorphism. -/]
def lift : (α →ₙ* β) ≃ (WithOne α →* β) where
toFun f :=
{ toFun := fun x => Option.casesOn x 1 f, map_one' := rfl,
map_mul' := fun x y => WithOne.cases_on x (by rw [one_mul]; exact (one_mul _).symm)
(fun x => WithOne.cases_on y (by rw [mul_one]; exact (mul_one _).symm)
(fun y => f.map_mul x y)) }
invFun F := F.toMulHom.comp coeMulHom
right_inv F := MonoidHom.ext fun x => WithOne.cases_on x F.map_one.symm (fun _ => rfl)
variable (f : α →ₙ* β)
@[to_additive (attr := simp)]
theorem lift_coe (x : α) : lift f x = f x :=
rfl
@[to_additive (attr := simp)]
theorem lift_one : lift f 1 = 1 :=
rfl
@[to_additive]
theorem lift_unique (f : WithOne α →* β) : f = lift (f.toMulHom.comp coeMulHom) :=
(lift.apply_symm_apply f).symm
end lift
section Map
variable [Mul α] [Mul β] [Mul γ]
/-- Given a multiplicative map from `α → β` returns a monoid homomorphism
from `WithOne α` to `WithOne β` -/
@[to_additive /-- Given an additive map from `α → β` returns an add monoid homomorphism from
`WithZero α` to `WithZero β` -/]
def map (f : α →ₙ* β) : WithOne α →* WithOne β :=
lift (coeMulHom.comp f)
@[to_additive (attr := simp)]
theorem map_coe (f : α →ₙ* β) (a : α) : map f (a : WithOne α) = f a :=
rfl
@[to_additive (attr := simp)]
theorem map_id : map (MulHom.id α) = MonoidHom.id (WithOne α) := by
ext x
induction x <;> rfl
@[to_additive]
theorem map_injective {f : α →ₙ* β} (hf : Function.Injective f) : Function.Injective (map f)
| none, none, _ => rfl
| (a₁ : α), (a₂ : α), H => by simpa [hf.eq_iff] using H
@[to_additive]
theorem map_injective' : Function.Injective (WithOne.map (α := α) (β := β)) := fun f g h ↦
MulHom.ext fun x ↦ coe_injective <| by simp only [← map_coe, h]
@[to_additive (attr := simp)]
theorem map_inj {f g : α →ₙ* β} : map f = map g ↔ f = g :=
map_injective'.eq_iff
@[to_additive]
theorem map_map (f : α →ₙ* β) (g : β →ₙ* γ) (x) : map g (map f x) = map (g.comp f) x := by
induction x <;> rfl
@[to_additive (attr := simp)]
theorem map_comp (f : α →ₙ* β) (g : β →ₙ* γ) : map (g.comp f) = (map g).comp (map f) :=
MonoidHom.ext fun x => (map_map f g x).symm
/-- A version of `Equiv.optionCongr` for `WithOne`. -/
@[to_additive (attr := simps apply) /-- A version of `Equiv.optionCongr` for `WithZero`. -/]
def _root_.MulEquiv.withOneCongr (e : α ≃* β) : WithOne α ≃* WithOne β :=
{ map e.toMulHom with
toFun := map e.toMulHom, invFun := map e.symm.toMulHom,
left_inv := (by induction · <;> simp)
right_inv := (by induction · <;> simp) }
@[to_additive (attr := simp)]
theorem _root_.MulEquiv.withOneCongr_refl : (MulEquiv.refl α).withOneCongr = MulEquiv.refl _ :=
MulEquiv.toMonoidHom_injective map_id
@[to_additive (attr := simp)]
theorem _root_.MulEquiv.withOneCongr_symm (e : α ≃* β) :
e.withOneCongr.symm = e.symm.withOneCongr :=
rfl
@[to_additive (attr := simp)]
theorem _root_.MulEquiv.withOneCongr_trans (e₁ : α ≃* β) (e₂ : β ≃* γ) :
e₁.withOneCongr.trans e₂.withOneCongr = (e₁.trans e₂).withOneCongr :=
MulEquiv.toMonoidHom_injective (map_comp _ _).symm
end Map
end WithOne
|
Coherence.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 Mathlib.CategoryTheory.Monoidal.Free.Basic
import Mathlib.CategoryTheory.Discrete.Basic
/-!
# 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
`fullNormalize : FreeMonoidalCategory C ⥤ Discrete (NormalMonoidalObject 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 isomorphisms, but also that they
assemble into a natural isomorphism `𝟭 (FreeMonoidalCategory C) ≅ fullNormalize ⋙ 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 CategoryTheory
open MonoidalCategory Functor
namespace FreeMonoidalCategory
variable {C : Type u}
section
variable (C)
/-- We say an object in the free monoidal category is in normal form if it is of the form
`(((𝟙_ C) ⊗ X₁) ⊗ X₂) ⊗ ⋯`. -/
inductive NormalMonoidalObject : Type u
| unit : NormalMonoidalObject
| tensor : NormalMonoidalObject → C → NormalMonoidalObject
end
local notation "F" => FreeMonoidalCategory
local notation "N" => Discrete ∘ NormalMonoidalObject
local infixr:10 " ⟶ᵐ " => Hom
-- Porting note: this was automatic in mathlib 3
instance (x y : N C) : Subsingleton (x ⟶ y) := Discrete.instSubsingletonDiscreteHom _ _
/-- Auxiliary definition for `inclusion`. -/
@[simp]
def inclusionObj : NormalMonoidalObject C → F C
| NormalMonoidalObject.unit => unit
| NormalMonoidalObject.tensor n a => tensor (inclusionObj n) (of a)
/-- The discrete subcategory of objects in normal form includes into the free monoidal category. -/
def inclusion : N C ⥤ F C :=
Discrete.functor inclusionObj
@[simp]
theorem inclusion_obj (X : N C) :
inclusion.obj X = inclusionObj X.as :=
rfl
@[simp]
theorem inclusion_map {X Y : N C} (f : X ⟶ Y) :
inclusion.map f = eqToHom (congr_arg _ (Discrete.ext (Discrete.eq_of_hom f))) := by
rcases f with ⟨⟨⟩⟩
cases Discrete.ext (by assumption)
apply inclusion.map_id
/-- Auxiliary definition for `normalize`. -/
def normalizeObj : F C → NormalMonoidalObject C → NormalMonoidalObject C
| unit, n => n
| of X, n => NormalMonoidalObject.tensor n X
| tensor X Y, n => normalizeObj Y (normalizeObj X n)
@[simp]
theorem normalizeObj_unitor (n : NormalMonoidalObject C) : normalizeObj (𝟙_ (F C)) n = n :=
rfl
@[simp]
theorem normalizeObj_tensor (X Y : F C) (n : NormalMonoidalObject C) :
normalizeObj (X ⊗ Y) n = normalizeObj Y (normalizeObj X n) :=
rfl
/-- Auxiliary definition for `normalize`. -/
def normalizeObj' (X : F C) : N C ⥤ N C := Discrete.functor fun n ↦ ⟨normalizeObj X n⟩
section
open Hom
/-- Auxiliary definition for `normalize`. Here we prove that objects that are related by
associators and unitors map to the same normal form. -/
@[simp]
def normalizeMapAux : ∀ {X Y : F C}, (X ⟶ᵐ Y) → (normalizeObj' X ⟶ normalizeObj' Y)
| _, _, Hom.id _ => 𝟙 _
| _, _, α_hom X Y Z => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, α_inv _ _ _ => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, l_hom _ => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, l_inv _ => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, ρ_hom _ => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, ρ_inv _ => by dsimp; exact Discrete.natTrans (fun _ => 𝟙 _)
| _, _, (@Hom.comp _ _ _ _ f g) => normalizeMapAux f ≫ normalizeMapAux g
| _, _, (@Hom.tensor _ T _ _ W f g) =>
Discrete.natTrans <| fun ⟨X⟩ => (normalizeMapAux g).app ⟨normalizeObj T X⟩ ≫
(normalizeObj' W).map ((normalizeMapAux f).app ⟨X⟩)
| _, _, (@Hom.whiskerLeft _ T _ W f) =>
Discrete.natTrans <| fun ⟨X⟩ => (normalizeMapAux f).app ⟨normalizeObj T X⟩
| _, _, (@Hom.whiskerRight _ T _ f W) =>
Discrete.natTrans <| fun X => (normalizeObj' W).map <| (normalizeMapAux f).app X
end
section
variable (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 where
obj X := normalizeObj' X
map {X Y} := Quotient.lift normalizeMapAux (by cat_disch)
/-- 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 ⋙ (whiskeringRight _ _ _).obj inclusion
/-- The normalization functor for the free monoidal category over `C`. -/
def fullNormalize : F C ⥤ N C where
obj X := ((normalize C).obj X).obj ⟨NormalMonoidalObject.unit⟩
map f := ((normalize C).map f).app ⟨NormalMonoidalObject.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 tensorFunc : F C ⥤ N C ⥤ F C where
obj X := Discrete.functor fun n => inclusion.obj ⟨n⟩ ⊗ X
map f := Discrete.natTrans (fun _ => _ ◁ f)
theorem tensorFunc_map_app {X Y : F C} (f : X ⟶ Y) (n) : ((tensorFunc C).map f).app n = _ ◁ f :=
rfl
theorem tensorFunc_obj_map (Z : F C) {n n' : N C} (f : n ⟶ n') :
((tensorFunc C).obj Z).map f = inclusion.map f ▷ Z := by
cases n
cases n'
rcases f with ⟨⟨h⟩⟩
dsimp at h
subst h
simp
/-- Auxiliary definition for `normalizeIso`. Here we construct the isomorphism between
`n ⊗ X` and `normalize X n`. -/
@[simp]
def normalizeIsoApp :
∀ (X : F C) (n : N C), ((tensorFunc C).obj X).obj n ≅ ((normalize' C).obj X).obj n
| of _, _ => Iso.refl _
| unit, _ => ρ_ _
| tensor X a, n =>
(α_ _ _ _).symm ≪≫ whiskerRightIso (normalizeIsoApp X n) a ≪≫ normalizeIsoApp _ _
/-- Almost non-definitionally equal to `normalizeIsoApp`, but has a better definitional property
in the proof of `normalize_naturality`. -/
@[simp]
def normalizeIsoApp' :
∀ (X : F C) (n : NormalMonoidalObject C), inclusionObj n ⊗ X ≅ inclusionObj (normalizeObj X n)
| of _, _ => Iso.refl _
| unit, _ => ρ_ _
| tensor X Y, n =>
(α_ _ _ _).symm ≪≫ whiskerRightIso (normalizeIsoApp' X n) Y ≪≫ normalizeIsoApp' _ _
theorem normalizeIsoApp_eq :
∀ (X : F C) (n : N C), normalizeIsoApp C X n = normalizeIsoApp' C X n.as
| of _, _ => rfl
| unit, _ => rfl
| tensor X Y, n => by
rw [normalizeIsoApp, normalizeIsoApp']
rw [normalizeIsoApp_eq X n]
rw [normalizeIsoApp_eq Y ⟨normalizeObj X n.as⟩]
rfl
@[simp]
theorem normalizeIsoApp_tensor (X Y : F C) (n : N C) :
normalizeIsoApp C (X ⊗ Y) n =
(α_ _ _ _).symm ≪≫ whiskerRightIso (normalizeIsoApp C X n) Y ≪≫ normalizeIsoApp _ _ _ :=
rfl
@[simp]
theorem normalizeIsoApp_unitor (n : N C) : normalizeIsoApp C (𝟙_ (F C)) n = ρ_ _ :=
rfl
/-- Auxiliary definition for `normalizeIso`. -/
@[simps!]
def normalizeIsoAux (X : F C) : (tensorFunc C).obj X ≅ (normalize' C).obj X :=
NatIso.ofComponents (normalizeIsoApp C X)
(by
rintro ⟨X⟩ ⟨Y⟩ ⟨⟨f⟩⟩
dsimp at f
subst f
dsimp
simp)
section
variable {C}
theorem normalizeObj_congr (n : NormalMonoidalObject C) {X Y : F C} (f : X ⟶ Y) :
normalizeObj X n = normalizeObj Y n := by
rcases f with ⟨f'⟩
apply @congr_fun _ _ fun n => normalizeObj X n
clear n f
induction f' with
| comp _ _ _ _ => apply Eq.trans <;> assumption
| whiskerLeft _ _ ih => funext; apply congr_fun ih
| whiskerRight _ _ ih => funext; apply congr_arg₂ _ rfl (congr_fun ih _)
| @tensor W X Y Z _ _ ih₁ ih₂ =>
funext n
simp [congr_fun ih₁ n, congr_fun ih₂ (normalizeObj Y n)]
| _ => funext; rfl
theorem normalize_naturality (n : NormalMonoidalObject C) {X Y : F C} (f : X ⟶ Y) :
inclusionObj n ◁ f ≫ (normalizeIsoApp' C Y n).hom =
(normalizeIsoApp' C X n).hom ≫
inclusion.map (eqToHom (Discrete.ext (normalizeObj_congr n f))) := by
revert n
induction f using Hom.inductionOn
case comp f g ihf ihg => simp [ihg, reassoc_of% (ihf _)]
case whiskerLeft X' X Y f ih =>
intro n
dsimp only [normalizeObj_tensor, normalizeIsoApp', tensor_eq_tensor, Iso.trans_hom,
Iso.symm_hom, whiskerRightIso_hom, Function.comp_apply, inclusion_obj]
rw [associator_inv_naturality_right_assoc, whisker_exchange_assoc, ih]
simp
case whiskerRight X Y h η' ih =>
intro n
dsimp only [normalizeObj_tensor, normalizeIsoApp', tensor_eq_tensor, Iso.trans_hom,
Iso.symm_hom, whiskerRightIso_hom, Function.comp_apply, inclusion_obj]
rw [associator_inv_naturality_middle_assoc, ← comp_whiskerRight_assoc, ih]
have := dcongr_arg (fun x => (normalizeIsoApp' C η' x).hom) (normalizeObj_congr n h)
simp [this]
all_goals simp
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 `normalizeIsoAux`). This is the real heart
of our proof of the coherence theorem. -/
def normalizeIso : tensorFunc C ≅ normalize' C :=
NatIso.ofComponents (normalizeIsoAux C) <| by
intro X Y f
ext ⟨n⟩
convert normalize_naturality n f using 1
any_goals dsimp; rw [normalizeIsoApp_eq]
rfl
/-- The isomorphism between an object and its normal form is natural. -/
def fullNormalizeIso : 𝟭 (F C) ≅ fullNormalize C ⋙ inclusion :=
NatIso.ofComponents
(fun X => (λ_ X).symm ≪≫ ((normalizeIso C).app X).app ⟨NormalMonoidalObject.unit⟩)
(by
intro X Y f
dsimp
rw [leftUnitor_inv_naturality_assoc, Category.assoc, Iso.cancel_iso_inv_left]
exact
congr_arg (fun f => NatTrans.app f (Discrete.mk NormalMonoidalObject.unit))
((normalizeIso.{u} C).hom.naturality f))
end
/-- The monoidal coherence theorem. -/
instance subsingleton_hom : Quiver.IsThin (F C) := fun X Y =>
⟨fun f g => by
have hfg : (fullNormalize C).map f = (fullNormalize C).map g := Subsingleton.elim _ _
have hf := NatIso.naturality_2 (fullNormalizeIso.{u} C) f
have hg := NatIso.naturality_2 (fullNormalizeIso.{u} C) g
exact hf.symm.trans (Eq.trans (by simp only [Functor.comp_map, hfg]) hg)⟩
section Groupoid
section
open Hom
/-- Auxiliary construction for showing that the free monoidal category is a groupoid. Do not use
this, use `IsIso.inv` instead. -/
def inverseAux : ∀ {X Y : F C}, (X ⟶ᵐ Y) → (Y ⟶ᵐ X)
| _, _, Hom.id X => id X
| _, _, α_hom _ _ _ => α_inv _ _ _
| _, _, α_inv _ _ _ => α_hom _ _ _
| _, _, ρ_hom _ => ρ_inv _
| _, _, ρ_inv _ => ρ_hom _
| _, _, l_hom _ => l_inv _
| _, _, l_inv _ => l_hom _
| _, _, Hom.comp f g => (inverseAux g).comp (inverseAux f)
| _, _, Hom.whiskerLeft X f => (inverseAux f).whiskerLeft X
| _, _, Hom.whiskerRight f X => (inverseAux f).whiskerRight X
| _, _, Hom.tensor f g => (inverseAux f).tensor (inverseAux g)
end
instance : Groupoid.{u} (F C) :=
{ (inferInstance : Category (F C)) with
inv := Quotient.lift (fun f => ⟦inverseAux f⟧) (by cat_disch) }
end Groupoid
end FreeMonoidalCategory
end CategoryTheory
|
CompactlyGenerated.lean
|
/-
Copyright (c) 2024 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Etienne Marion
-/
import Mathlib.Topology.Compactness.CompactlyGeneratedSpace
import Mathlib.Topology.Maps.Proper.Basic
/-!
# A map is proper iff preimage of compact sets are compact
This file proves that if `Y` is a Hausdorff and compactly generated space, a continuous map
`f : X → Y` is proper if and only if preimage of compact sets are compact.
-/
open Set Filter
variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
variable [T2Space Y] [CompactlyGeneratedSpace Y]
variable {f : X → Y}
/-- If `Y` is Hausdorff and compactly generated, then proper maps `X → Y` are exactly
continuous maps such that the preimage of any compact set is compact. This is in particular true
if `Y` is Hausdorff and sequential or locally compact.
There was an older version of this theorem which was changed to this one to make use
of the `CompactlyGeneratedSpace` typeclass. (since 2024-11-10) -/
theorem isProperMap_iff_isCompact_preimage :
IsProperMap f ↔ Continuous f ∧ ∀ ⦃K⦄, IsCompact K → IsCompact (f ⁻¹' K) where
mp hf := ⟨hf.continuous, fun _ ↦ hf.isCompact_preimage⟩
mpr := fun ⟨hf, h⟩ ↦ isProperMap_iff_isClosedMap_and_compact_fibers.2
⟨hf, fun _ hs ↦ CompactlyGeneratedSpace.isClosed
fun _ hK ↦ image_inter_preimage .. ▸ (((h hK).inter_left hs).image hf).isClosed,
fun _ ↦ h isCompact_singleton⟩
/-- Version of `isProperMap_iff_isCompact_preimage` in terms of `cocompact`.
There was an older version of this theorem which was changed to this one to make use
of the `CompactlyGeneratedSpace` typeclass. (since 2024-11-10) -/
lemma isProperMap_iff_tendsto_cocompact :
IsProperMap f ↔ Continuous f ∧ Tendsto f (cocompact X) (cocompact Y) := by
simp_rw [isProperMap_iff_isCompact_preimage,
hasBasis_cocompact.tendsto_right_iff, ← mem_preimage, eventually_mem_set, preimage_compl]
refine and_congr_right fun f_cont ↦
⟨fun H K hK ↦ (H hK).compl_mem_cocompact, fun H K hK ↦ ?_⟩
rcases mem_cocompact.mp (H K hK) with ⟨K', hK', hK'y⟩
exact hK'.of_isClosed_subset (hK.isClosed.preimage f_cont)
(compl_le_compl_iff_le.mp hK'y)
|
interval.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import div fintype bigop order ssralg finset fingroup.
From mathcomp Require Import ssrnum.
(******************************************************************************)
(* Intervals in ordered types *)
(* *)
(* This file provides support for intervals in ordered types. The datatype *)
(* (interval T) gives a formal characterization of an interval, as the pair *)
(* of its right and left bounds. *)
(* interval T == the type of formal intervals on T. *)
(* x \in i == when i is a formal interval on an ordered type, *)
(* \in can be used to test membership. *)
(* itvP x_in_i == where x_in_i has type x \in i, if i is ground, *)
(* gives a set of rewrite rules that x_in_i implies *)
(* lteBSide, bnd_simp == multirules to simplify inequalities between interval *)
(* bounds *)
(* miditv i == middle point of interval i *)
(* *)
(* When using interval.v, the lemma `in_itv` is in practice very useful. For *)
(* example, the execution of the tactic `rewrite in_itv` w.r.t. an hypothesis *)
(* of the form x \in `]a, b[ into a < x < b. *)
(* *)
(* Intervals of T form an partially ordered type (porderType) whose ordering *)
(* is the subset relation. If T is a lattice, intervals also form a lattice *)
(* (latticeType) whose meet and join are intersection and convex hull *)
(* respectively. They are distributive if T is an orderType. *)
(* *)
(* We provide a set of notations to write intervals (see below) *)
(* `[a, b], `]a, b], ..., `]-oo, a], ..., `]-oo, +oo[ *)
(* The substrings "oo", "oc", "co", "cc" in the names of lemmas respectively *)
(* stand for the intervals of the shape `]a, b[, `]a, b], `[a, b[, `[a, b]. *)
(* The substrings "pinfty" and "ninfty" in the names of lemmas stand for *)
(* +oo and -oo. *)
(* We also provide the lemma subitvP which computes the inequalities one *)
(* needs to prove when trying to prove the inclusion of intervals. *)
(* *)
(* Remark that we cannot implement a boolean comparison test for intervals on *)
(* an arbitrary ordered types, for this problem might be undecidable. Note *)
(* also that type (interval R) may contain several inhabitants coding for the *)
(* same interval. However, these pathological issues do not arise when R is a *)
(* real domain: we could provide a specific theory for this important case. *)
(* *)
(* References: *)
(* - Cyril Cohen, Assia Mahboubi, Formal proofs in real algebraic geometry: *)
(* from ordered fields quantifier elimination, LMCS, 2012 *)
(* - Cyril Cohen, Formalized algebraic numbers: construction and first-order *)
(* theory, PhD thesis, 2012, section 4.3 *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "'-oo'".
Reserved Notation "'+oo'".
Reserved Notation "`[ a , b ]" (format "`[ a , b ]").
Reserved Notation "`] a , b ]" (format "`] a , b ]").
Reserved Notation "`[ a , b [" (format "`[ a , b [").
Reserved Notation "`] a , b [" (format "`] a , b [").
Reserved Notation "`] '-oo' , b ]" (format "`] '-oo' , b ]").
Reserved Notation "`] '-oo' , b [" (format "`] '-oo' , b [").
Reserved Notation "`[ a , '+oo' [" (format "`[ a , '+oo' [").
Reserved Notation "`] a , '+oo' [" (format "`] a , '+oo' [").
Reserved Notation "`] -oo , '+oo' [" (format "`] -oo , '+oo' [").
Local Open Scope order_scope.
Import Order.TTheory.
Variant itv_bound (T : Type) : Type := BSide of bool & T | BInfty of bool.
Notation BLeft := (BSide true).
Notation BRight := (BSide false).
Notation "'-oo'" := (BInfty _ true) : order_scope.
Notation "'+oo'" := (BInfty _ false) : order_scope.
Variant interval (T : Type) := Interval of itv_bound T & itv_bound T.
Coercion pair_of_interval T (I : interval T) : itv_bound T * itv_bound T :=
let: Interval b1 b2 := I in (b1, b2).
(* We provide the 9 following notations to help writing formal intervals *)
Notation "`[ a , b ]" := (Interval (BLeft a) (BRight b)) : order_scope.
Notation "`] a , b ]" := (Interval (BRight a) (BRight b)) : order_scope.
Notation "`[ a , b [" := (Interval (BLeft a) (BLeft b)) : order_scope.
Notation "`] a , b [" := (Interval (BRight a) (BLeft b)) : order_scope.
Notation "`] '-oo' , b ]" := (Interval -oo (BRight b)) : order_scope.
Notation "`] '-oo' , b [" := (Interval -oo (BLeft b)) : order_scope.
Notation "`[ a , '+oo' [" := (Interval (BLeft a) +oo) : order_scope.
Notation "`] a , '+oo' [" := (Interval (BRight a) +oo) : order_scope.
Notation "`] -oo , '+oo' [" := (Interval -oo +oo) : order_scope.
Notation "`[ a , b ]" := (Interval (BLeft a) (BRight b)) : ring_scope.
Notation "`] a , b ]" := (Interval (BRight a) (BRight b)) : ring_scope.
Notation "`[ a , b [" := (Interval (BLeft a) (BLeft b)) : ring_scope.
Notation "`] a , b [" := (Interval (BRight a) (BLeft b)) : ring_scope.
Notation "`] '-oo' , b ]" := (Interval -oo (BRight b)) : ring_scope.
Notation "`] '-oo' , b [" := (Interval -oo (BLeft b)) : ring_scope.
Notation "`[ a , '+oo' [" := (Interval (BLeft a) +oo) : ring_scope.
Notation "`] a , '+oo' [" := (Interval (BRight a) +oo) : ring_scope.
Notation "`] -oo , '+oo' [" := (Interval -oo +oo) : ring_scope.
Fact itv_bound_display (disp : Order.disp_t) : Order.disp_t. Proof. exact. Qed.
Fact interval_display (disp : Order.disp_t) : Order.disp_t. Proof. exact. Qed.
Module IntervalCan.
Section IntervalCan.
Variable T : Type.
Lemma itv_bound_can :
cancel (fun b : itv_bound T =>
match b with BSide b x => (b, Some x) | BInfty b => (b, None) end)
(fun b =>
match b with (b, Some x) => BSide b x | (b, None) => BInfty _ b end).
Proof. by case. Qed.
Lemma interval_can :
@cancel _ (interval T)
(fun '(Interval b1 b2) => (b1, b2)) (fun '(b1, b2) => Interval b1 b2).
Proof. by case. Qed.
End IntervalCan.
#[export, hnf]
HB.instance Definition _ (T : eqType) := Equality.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : eqType) := Equality.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : choiceType) := Choice.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : choiceType) := Choice.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : countType) := Countable.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : countType) := Countable.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : finType) := Finite.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : finType) := Finite.copy (interval T)
(can_type (@interval_can T)).
Module Exports. HB.reexport. End Exports.
End IntervalCan.
Export IntervalCan.Exports.
Section IntervalPOrder.
Variable (disp : Order.disp_t) (T : porderType disp).
Implicit Types (x y z : T) (b bl br : itv_bound T) (i : interval T).
Definition le_bound b1 b2 :=
match b1, b2 with
| -oo, _ | _, +oo => true
| BSide b1 x1, BSide b2 x2 => x1 < x2 ?<= if b2 ==> b1
| _, _ => false
end.
Definition lt_bound b1 b2 :=
match b1, b2 with
| -oo, +oo | -oo, BSide _ _ | BSide _ _, +oo => true
| BSide b1 x1, BSide b2 x2 => x1 < x2 ?<= if b1 && ~~ b2
| _, _ => false
end.
Lemma lt_bound_def b1 b2 : lt_bound b1 b2 = (b2 != b1) && le_bound b1 b2.
Proof. by case: b1 b2 => [[]?|[]][[]?|[]] //=; rewrite lt_def. Qed.
Lemma le_bound_refl : reflexive le_bound.
Proof. by move=> [[]?|[]] /=. Qed.
Lemma le_bound_anti : antisymmetric le_bound.
Proof. by case=> [[]?|[]] [[]?|[]] //=; case: comparableP => // ->. Qed.
Lemma le_bound_trans : transitive le_bound.
Proof.
by case=> [[]?|[]] [[]?|[]] [[]?|[]] lexy leyz //;
apply: (lteif_imply _ (lteif_trans lexy leyz)).
Qed.
HB.instance Definition _ :=
Order.isPOrder.Build (itv_bound_display disp) (itv_bound T)
lt_bound_def le_bound_refl le_bound_anti le_bound_trans.
Lemma bound_lexx c1 c2 x : (BSide c1 x <= BSide c2 x) = (c2 ==> c1).
Proof. by rewrite /<=%O /= lteifxx. Qed.
Lemma bound_ltxx c1 c2 x : (BSide c1 x < BSide c2 x) = (c1 && ~~ c2).
Proof. by rewrite /<%O /= lteifxx. Qed.
Lemma ge_pinfty b : (+oo <= b) = (b == +oo). Proof. by case: b => [|] []. Qed.
Lemma le_ninfty b : (b <= -oo) = (b == -oo). Proof. by case: b => // - []. Qed.
Lemma gt_pinfty b : (+oo < b) = false. Proof. by []. Qed.
Lemma lt_ninfty b : (b < -oo) = false. Proof. by case: b => // -[]. Qed.
Lemma ltBSide x y (b b' : bool) :
BSide b x < BSide b' y = (x < y ?<= if b && ~~ b').
Proof. by []. Qed.
Lemma leBSide x y (b b' : bool) :
BSide b x <= BSide b' y = (x < y ?<= if b' ==> b).
Proof. by []. Qed.
Definition lteBSide := (ltBSide, leBSide).
Lemma ltBRight_leBLeft b x : b < BRight x = (b <= BLeft x).
Proof. by move: b => [[] b|[]]. Qed.
Lemma leBRight_ltBLeft b x : BRight x <= b = (BLeft x < b).
Proof. by move: b => [[] b|[]]. Qed.
Let BLeft_ltE x y (b : bool) : BSide b x < BLeft y = (x < y).
Proof. by case: b. Qed.
Let BRight_leE x y (b : bool) : BSide b x <= BRight y = (x <= y).
Proof. by case: b. Qed.
Let BRight_BLeft_leE x y : BRight x <= BLeft y = (x < y).
Proof. by []. Qed.
Let BLeft_BRight_ltE x y : BLeft x < BRight y = (x <= y).
Proof. by []. Qed.
Let BRight_BSide_ltE x y (b : bool) : BRight x < BSide b y = (x < y).
Proof. by case: b. Qed.
Let BLeft_BSide_leE x y (b : bool) : BLeft x <= BSide b y = (x <= y).
Proof. by case: b. Qed.
Let BSide_ltE x y (b : bool) : BSide b x < BSide b y = (x < y).
Proof. by case: b. Qed.
Let BSide_leE x y (b : bool) : BSide b x <= BSide b y = (x <= y).
Proof. by case: b. Qed.
Let BInfty_leE a : a <= BInfty T false. Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_geE a : BInfty T true <= a. Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_le_eqE a : BInfty T false <= a = (a == BInfty T false).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ge_eqE a : a <= BInfty T true = (a == BInfty T true).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ltE a : a < BInfty T false = (a != BInfty T false).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_gtE a : BInfty T true < a = (a != BInfty T true).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ltF a : BInfty T false < a = false.
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_gtF a : a < BInfty T true = false.
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_BInfty_ltE : BInfty T true < BInfty T false. Proof. by []. Qed.
Definition bnd_simp := (BLeft_ltE, BRight_leE,
BRight_BLeft_leE, BLeft_BRight_ltE,
BRight_BSide_ltE, BLeft_BSide_leE, BSide_ltE, BSide_leE,
BInfty_leE, BInfty_geE, BInfty_BInfty_ltE,
BInfty_le_eqE, BInfty_ge_eqE, BInfty_ltE, BInfty_gtE, BInfty_ltF, BInfty_gtF,
@lexx _ T, @ltxx _ T, @eqxx T).
Lemma comparable_BSide_min s (x y : T) : (x >=< y)%O ->
BSide s (Order.min x y) = Order.min (BSide s x) (BSide s y).
Proof. by rewrite !minEle bnd_simp => /comparable_leP[]. Qed.
Lemma comparable_BSide_max s (x y : T) : (x >=< y)%O ->
BSide s (Order.max x y) = Order.max (BSide s x) (BSide s y).
Proof. by rewrite !maxEle bnd_simp => /comparable_leP[]. Qed.
Definition subitv i1 i2 :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in (b2l <= b1l) && (b1r <= b2r).
Lemma subitv_refl : reflexive subitv.
Proof. by case=> /= ? ?; rewrite !lexx. Qed.
Lemma subitv_anti : antisymmetric subitv.
Proof.
by case=> [? ?][? ?]; rewrite andbACA => /andP[] /le_anti -> /le_anti ->.
Qed.
Lemma subitv_trans : transitive subitv.
Proof.
case=> [yl yr][xl xr][zl zr] /andP [Hl Hr] /andP [Hl' Hr'] /=.
by rewrite (le_trans Hl' Hl) (le_trans Hr Hr').
Qed.
HB.instance Definition _ :=
Order.isPOrder.Build (interval_display disp) (interval T)
(fun _ _ => erefl) subitv_refl subitv_anti subitv_trans.
Definition pred_of_itv i : pred T := [pred x | `[x, x] <= i].
Canonical Structure itvPredType := PredType pred_of_itv.
Lemma subitvE b1l b1r b2l b2r :
(Interval b1l b1r <= Interval b2l b2r) = (b2l <= b1l) && (b1r <= b2r).
Proof. by []. Qed.
Lemma in_itv x i :
x \in i =
let: Interval l u := i in
match l with
| BSide b lb => lb < x ?<= if b
| BInfty b => b
end &&
match u with
| BSide b ub => x < ub ?<= if ~~ b
| BInfty b => ~~ b
end.
Proof. by case: i => [[? ?|[]][|[]]]. Qed.
Lemma itv_boundlr bl br x :
(x \in Interval bl br) = (bl <= BLeft x) && (BRight x <= br).
Proof. by []. Qed.
Lemma itv_splitI bl br x :
x \in Interval bl br = (x \in Interval bl +oo) && (x \in Interval -oo br).
Proof. by rewrite !itv_boundlr andbT. Qed.
Lemma subitvP i1 i2 : i1 <= i2 -> {subset i1 <= i2}.
Proof. by move=> ? ? /le_trans; exact. Qed.
(* Remove the line below when requiring Coq >= 8.20 *)
#[warning="-unsupported-attributes"]
#[warn(note="The lemma subset_itv was generalized in MathComp 2.4.0 and the original was renamed to subset_itv_bound.",
cats="mathcomp-subset-itv")]
Lemma subset_itv (x y z u : itv_bound T) : x <= y -> z <= u ->
{subset Interval y z <= Interval x u}.
Proof. by move=> xy zu; apply: subitvP; rewrite subitvE xy zu. Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use subset_itv instead.")]
Lemma subset_itv_bound (r s u v : bool) x y : r <= u -> v <= s ->
{subset Interval (BSide r x) (BSide s y) <= Interval (BSide u x) (BSide v y)}.
Proof.
by move: r s u v=> [] [] [] []// *; apply: subset_itv; rewrite bnd_simp.
Qed.
Lemma subset_itv_oo_cc x y : {subset `]x, y[ <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oo_oc x y : {subset `]x, y[ <= `]x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oo_co x y : {subset `]x, y[ <= `[x, y[}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oc_cc x y : {subset `]x, y] <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_co_cc x y : {subset `[x, y[ <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma itvxx x : `[x, x] =i pred1 x.
Proof. by move=> y; rewrite in_itv/= -eq_le eq_sym. Qed.
Lemma itvxxP y x : reflect (y = x) (y \in `[x, x]).
Proof. by rewrite itvxx; apply/eqP. Qed.
Lemma subitvPl b1l b2l br :
b2l <= b1l -> {subset Interval b1l br <= Interval b2l br}.
Proof. by move=> ?; apply: subitvP; rewrite subitvE lexx andbT. Qed.
Lemma subitvPr bl b1r b2r :
b1r <= b2r -> {subset Interval bl b1r <= Interval bl b2r}.
Proof. by move=> ?; apply: subitvP; rewrite subitvE lexx. Qed.
Lemma itv_xx x cl cr y :
y \in Interval (BSide cl x) (BSide cr x) = cl && ~~ cr && (y == x).
Proof. by case: cl cr => [] []; rewrite [LHS]lteif_anti // eq_sym. Qed.
Lemma boundl_in_itv c x b : x \in Interval (BSide c x) b = c && (BRight x <= b).
Proof. by rewrite itv_boundlr bound_lexx. Qed.
Lemma boundr_in_itv c x b :
x \in Interval b (BSide c x) = ~~ c && (b <= BLeft x).
Proof. by rewrite itv_boundlr bound_lexx implybF andbC. Qed.
Definition bound_in_itv := (boundl_in_itv, boundr_in_itv).
Lemma lt_in_itv bl br x : x \in Interval bl br -> bl < br.
Proof. by case/andP; apply/le_lt_trans. Qed.
Lemma lteif_in_itv cl cr yl yr x :
x \in Interval (BSide cl yl) (BSide cr yr) -> yl < yr ?<= if cl && ~~ cr.
Proof. exact: lt_in_itv. Qed.
Lemma itv_ge b1 b2 : ~~ (b1 < b2) -> Interval b1 b2 =i pred0.
Proof. by move=> ltb12 y; apply/contraNF: ltb12; apply/lt_in_itv. Qed.
Definition itv_decompose i x : Prop :=
let: Interval l u := i in
(match l return Prop with
| BSide b lb => lb < x ?<= if b
| BInfty b => b
end *
match u return Prop with
| BSide b ub => x < ub ?<= if ~~ b
| BInfty b => ~~ b
end)%type.
Lemma itv_dec : forall x i, reflect (itv_decompose i x) (x \in i).
Proof. by move=> ? [[? ?|[]][? ?|[]]]; apply: (iffP andP); case. Qed.
Arguments itv_dec {x i}.
(* we compute a set of rewrite rules associated to an interval *)
Definition itv_rewrite i x : Type :=
let: Interval l u := i in
(match l with
| BLeft a => (a <= x) * (x < a = false)
| BRight a => (a <= x) * (a < x) * (x <= a = false) * (x < a = false)
| -oo => forall x : T, x == x
| +oo => forall b : bool, unkeyed b = false
end *
match u with
| BRight b => (x <= b) * (b < x = false)
| BLeft b => (x <= b) * (x < b) * (b <= x = false) * (b < x = false)
| +oo => forall x : T, x == x
| -oo => forall b : bool, unkeyed b = false
end *
match l, u with
| BLeft a, BRight b =>
(a <= b) * (b < a = false) * (a \in `[a, b]) * (b \in `[a, b])
| BLeft a, BLeft b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| BRight a, BRight b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| BRight a, BLeft b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| _, _ => forall x : T, x == x
end)%type.
Lemma itvP x i : x \in i -> itv_rewrite i x.
Proof.
case: i => [[[]a|[]][[]b|[]]] /andP [] ha hb; rewrite /= ?bound_in_itv;
do ![split | apply/negbTE; rewrite (le_gtF, lt_geF)];
by [|apply: ltW | move: (lteif_trans ha hb) => //=; exact: ltW].
Qed.
Arguments itvP [x i].
Lemma itv_splitU1 b x : b <= BLeft x ->
Interval b (BRight x) =i [predU1 x & Interval b (BLeft x)].
Proof.
move=> bx z; rewrite !inE/= !subitvE ?bnd_simp//= lt_neqAle.
by case: (eqVneq z x) => [->|]//=; rewrite lexx bx.
Qed.
Lemma itv_split1U b x : BRight x <= b ->
Interval (BLeft x) b =i [predU1 x & Interval (BRight x) b].
Proof.
move=> bx z; rewrite !inE/= !subitvE ?bnd_simp//= lt_neqAle.
by case: (eqVneq z x) => [->|]//=; rewrite lexx bx.
Qed.
End IntervalPOrder.
Section IntervalLattice.
Variable (disp : Order.disp_t) (T : latticeType disp).
Implicit Types (x y z : T) (b bl br : itv_bound T) (i : interval T).
Definition bound_meet bl br : itv_bound T :=
match bl, br with
| -oo, _ | _, -oo => -oo
| +oo, b | b, +oo => b
| BSide xb x, BSide yb y =>
BSide (((x <= y) && xb) || ((y <= x) && yb)) (x `&` y)
end.
Definition bound_join bl br : itv_bound T :=
match bl, br with
| -oo, b | b, -oo => b
| +oo, _ | _, +oo => +oo
| BSide xb x, BSide yb y =>
BSide ((~~ (x <= y) || yb) && (~~ (y <= x) || xb)) (x `|` y)
end.
Lemma bound_meetC : commutative bound_meet.
Proof.
case=> [? ?|[]][? ?|[]] //=; rewrite meetC; congr BSide.
by case: lcomparableP; rewrite ?orbF // orbC.
Qed.
Lemma bound_joinC : commutative bound_join.
Proof.
case=> [? ?|[]][? ?|[]] //=; rewrite joinC; congr BSide.
by case: lcomparableP; rewrite ?andbT // andbC.
Qed.
Lemma bound_meetA : associative bound_meet.
Proof.
case=> [? x|[]][? y|[]][? z|[]] //=; rewrite !lexI meetA; congr BSide.
by case: (lcomparableP x y) => [|||->]; case: (lcomparableP y z) => [|||->];
case: (lcomparableP x z) => [|||//<-]; case: (lcomparableP x y);
rewrite //= ?andbF ?orbF ?lexx ?orbA //; case: (lcomparableP y z).
Qed.
Lemma bound_joinA : associative bound_join.
Proof.
case=> [? x|[]][? y|[]][? z|[]] //=; rewrite !leUx joinA; congr BSide.
by case: (lcomparableP x y) => [|||->]; case: (lcomparableP y z) => [|||->];
case: (lcomparableP x z) => [|||//<-]; case: (lcomparableP x y);
rewrite //= ?orbT ?andbT ?lexx ?andbA //; case: (lcomparableP y z).
Qed.
Lemma bound_meetKU b2 b1 : bound_join b1 (bound_meet b1 b2) = b1.
Proof.
case: b1 b2 => [? ?|[]][? ?|[]] //=;
rewrite ?meetKU ?joinxx ?leIl ?lexI ?lexx ?andbb //=; congr BSide.
by case: lcomparableP; rewrite ?orbF /= ?andbb ?orbK.
Qed.
Lemma bound_joinKI b2 b1 : bound_meet b1 (bound_join b1 b2) = b1.
Proof.
case: b1 b2 => [? ?|[]][? ?|[]] //=;
rewrite ?joinKI ?meetxx ?leUl ?leUx ?lexx ?orbb //=; congr BSide.
by case: lcomparableP; rewrite ?orbF ?orbb ?andKb.
Qed.
Lemma bound_leEmeet b1 b2 : (b1 <= b2) = (bound_meet b1 b2 == b1).
Proof.
case: b1 b2 => [[]t[][]|[][][]] //=; rewrite ?eqxx// => t';
rewrite [LHS]/<=%O /eq_op ?andbT ?andbF ?orbF/= /eq_op/= /eq_op/=;
case: lcomparableP => //=; rewrite ?eqxx//=; [| | |].
- by move/lt_eqF.
- move=> ic; apply: esym; apply: contraNF ic.
by move=> /eqP/meet_idPl; apply: le_comparable.
- by move/lt_eqF.
- move=> ic; apply: esym; apply: contraNF ic.
by move=> /eqP/meet_idPl; apply: le_comparable.
Qed.
HB.instance Definition _ :=
Order.POrder_isLattice.Build (itv_bound_display disp) (itv_bound T)
bound_meetC bound_joinC bound_meetA bound_joinA
bound_joinKI bound_meetKU bound_leEmeet.
Lemma bound_le0x b : -oo <= b. Proof. by []. Qed.
Lemma bound_lex1 b : b <= +oo. Proof. by case: b => [|[]]. Qed.
HB.instance Definition _ :=
Order.hasBottom.Build (itv_bound_display disp) (itv_bound T) bound_le0x.
HB.instance Definition _ :=
Order.hasTop.Build (itv_bound_display disp) (itv_bound T) bound_lex1.
Definition itv_meet i1 i2 : interval T :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in Interval (b1l `|` b2l) (b1r `&` b2r).
Definition itv_join i1 i2 : interval T :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in Interval (b1l `&` b2l) (b1r `|` b2r).
Lemma itv_meetC : commutative itv_meet.
Proof. by case=> [? ?][? ?] /=; rewrite meetC joinC. Qed.
Lemma itv_joinC : commutative itv_join.
Proof. by case=> [? ?][? ?] /=; rewrite meetC joinC. Qed.
Lemma itv_meetA : associative itv_meet.
Proof. by case=> [? ?][? ?][? ?] /=; rewrite meetA joinA. Qed.
Lemma itv_joinA : associative itv_join.
Proof. by case=> [? ?][? ?][? ?] /=; rewrite meetA joinA. Qed.
Lemma itv_meetKU i2 i1 : itv_join i1 (itv_meet i1 i2) = i1.
Proof. by case: i1 i2 => [? ?][? ?] /=; rewrite meetKU joinKI. Qed.
Lemma itv_joinKI i2 i1 : itv_meet i1 (itv_join i1 i2) = i1.
Proof. by case: i1 i2 => [? ?][? ?] /=; rewrite meetKU joinKI. Qed.
Lemma itv_leEmeet i1 i2 : (i1 <= i2) = (itv_meet i1 i2 == i1).
Proof.
by case: i1 i2 => [? ?] [? ?]; rewrite /eq_op/=/eq_op/= eq_meetl eq_joinl.
Qed.
HB.instance Definition _ :=
Order.POrder_isLattice.Build (interval_display disp) (interval T)
itv_meetC itv_joinC itv_meetA itv_joinA
itv_joinKI itv_meetKU itv_leEmeet.
Lemma itv_le0x i : Interval +oo -oo <= i. Proof. by case: i => [[|[]]]. Qed.
Lemma itv_lex1 i : i <= `]-oo, +oo[. Proof. by case: i => [?[|[]]]. Qed.
HB.instance Definition _ :=
Order.hasBottom.Build (interval_display disp) (interval T) itv_le0x.
HB.instance Definition _ :=
Order.hasTop.Build (interval_display disp) (interval T) itv_lex1.
Lemma in_itvI x i1 i2 : x \in i1 `&` i2 = (x \in i1) && (x \in i2).
Proof. exact: lexI. Qed.
End IntervalLattice.
Section IntervalTotal.
Variable (disp : Order.disp_t) (T : orderType disp).
Implicit Types (a b c : itv_bound T) (x y z : T) (i : interval T).
Lemma BSide_min s (x y : T) :
BSide s (Order.min x y) = Order.min (BSide s x) (BSide s y).
Proof. exact: comparable_BSide_min. Qed.
Lemma BSide_max s (x y : T) :
BSide s (Order.max x y) = Order.max (BSide s x) (BSide s y).
Proof. exact: comparable_BSide_max. Qed.
Lemma itv_bound_total : total (<=%O : rel (itv_bound T)).
Proof. by move=> [[]?|[]][[]?|[]]; rewrite /<=%O //=; case: ltgtP. Qed.
HB.instance Definition _ :=
Order.Lattice_isTotal.Build
(itv_bound_display disp) (itv_bound T) itv_bound_total.
Lemma itv_meetUl : @left_distributive (interval T) _ Order.meet Order.join.
Proof.
by move=> [? ?][? ?][? ?]; rewrite /Order.meet /Order.join /= -meetUl -joinIl.
Qed.
HB.instance Definition _ :=
Order.Lattice_Meet_isDistrLattice.Build
(interval_display disp) (interval T) itv_meetUl.
Lemma itv_splitU c a b : a <= c <= b ->
forall y, y \in Interval a b = (y \in Interval a c) || (y \in Interval c b).
Proof.
case/andP => leac lecb y.
rewrite !itv_boundlr !(ltNge (BLeft y) _ : (BRight y <= _) = _).
case: (leP a) (leP b) (leP c) => leay [] leby [] lecy //=.
- by case: leP lecy (le_trans lecb leby).
- by case: leP leay (le_trans leac lecy).
Qed.
Lemma itv_splitUeq x a b : x \in Interval a b ->
forall y, y \in Interval a b =
[|| y \in Interval a (BLeft x), y == x | y \in Interval (BRight x) b].
Proof.
case/andP => ax xb y; rewrite (@itv_splitU (BLeft x)) ?ax ?ltW //.
by congr orb; rewrite (@itv_splitU (BRight x)) ?bound_lexx // itv_xx.
Qed.
Lemma itv_total_meet3E i1 i2 i3 :
i1 `&` i2 `&` i3 \in [:: i1 `&` i2; i1 `&` i3; i2 `&` i3].
Proof.
case: i1 i2 i3 => [b1l b1r] [b2l b2r] [b3l b3r]; rewrite !inE /eq_op /=.
case: (leP b1l b2l); case: (leP b1l b3l); case: (leP b2l b3l);
case: (leP b1r b2r); case: (leP b1r b3r); case: (leP b2r b3r);
rewrite ?eqxx ?orbT //= => b23r b13r b12r b23l b13l b12l.
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13r (lt_trans b23r b12r).
Qed.
Lemma itv_total_join3E i1 i2 i3 :
i1 `|` i2 `|` i3 \in [:: i1 `|` i2; i1 `|` i3; i2 `|` i3].
Proof.
case: i1 i2 i3 => [b1l b1r] [b2l b2r] [b3l b3r]; rewrite !inE /eq_op /=.
case: (leP b1l b2l); case: (leP b1l b3l); case: (leP b2l b3l);
case: (leP b1r b2r); case: (leP b1r b3r); case: (leP b2r b3r);
rewrite ?eqxx ?orbT //= => b23r b13r b12r b23l b13l b12l.
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
Qed.
Lemma predC_itvl a : [predC Interval -oo a] =i Interval a +oo.
Proof.
case: a => [b x|[]//] y.
by rewrite !inE !subitvE/= bnd_simp andbT !lteBSide/= lteifNE negbK.
Qed.
Lemma predC_itvr a : [predC Interval a +oo] =i Interval -oo a.
Proof. by move=> y; rewrite inE/= -predC_itvl negbK. Qed.
Lemma predC_itv i : [predC i] =i [predU Interval -oo i.1 & Interval i.2 +oo].
Proof.
case: i => [a a']; move=> x; rewrite inE/= itv_splitI negb_and.
by symmetry; rewrite inE/= -predC_itvl -predC_itvr.
Qed.
End IntervalTotal.
Local Open Scope ring_scope.
Import GRing.Theory Num.Theory.
Section IntervalNumDomain.
Variable R : numDomainType.
Implicit Types x : R.
Lemma real_BSide_min b x y : x \in Num.real -> y \in Num.real ->
BSide b (Order.min x y) = Order.min (BSide b x) (BSide b y).
Proof. by move=> xr yr; apply/comparable_BSide_min/real_comparable. Qed.
Lemma real_BSide_max b x y : x \in Num.real -> y \in Num.real ->
BSide b (Order.max x y) = Order.max (BSide b x) (BSide b y).
Proof. by move=> xr yr; apply/comparable_BSide_max/real_comparable. Qed.
Lemma mem0_itvcc_xNx x : (0 \in `[- x, x]) = (0 <= x).
Proof. by rewrite itv_boundlr [in LHS]/<=%O /= oppr_le0 andbb. Qed.
Lemma mem0_itvoo_xNx x : 0 \in `]- x, x[ = (0 < x).
Proof. by rewrite itv_boundlr [in LHS]/<=%O /= oppr_lt0 andbb. Qed.
Lemma oppr_itv ba bb (xa xb x : R) :
(- x \in Interval (BSide ba xa) (BSide bb xb)) =
(x \in Interval (BSide (~~ bb) (- xb)) (BSide (~~ ba) (- xa))).
Proof.
by rewrite !itv_boundlr /<=%O /= !implybF negbK andbC lteifNl lteifNr.
Qed.
Lemma oppr_itvoo (a b x : R) : (- x \in `]a, b[) = (x \in `]- b, - a[).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvco (a b x : R) : (- x \in `[a, b[) = (x \in `]- b, - a]).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvoc (a b x : R) : (- x \in `]a, b]) = (x \in `[- b, - a[).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvcc (a b x : R) : (- x \in `[a, b]) = (x \in `[- b, - a]).
Proof. exact: oppr_itv. Qed.
Definition miditv (R : numDomainType) (i : interval R) : R :=
match i with
| Interval (BSide _ a) (BSide _ b) => (a + b) / 2%:R
| Interval -oo%O (BSide _ b) => b - 1
| Interval (BSide _ a) +oo%O => a + 1
| Interval -oo%O +oo%O => 0
| _ => 0
end.
End IntervalNumDomain.
Section IntervalField.
Variable R : numFieldType.
Implicit Types (x y z : R) (i : interval R).
Local Notation mid x y := ((x + y) / 2).
Lemma mid_in_itv : forall ba bb (xa xb : R), xa < xb ?<= if ba && ~~ bb ->
mid xa xb \in Interval (BSide ba xa) (BSide bb xb).
Proof.
by move=> [] [] xa xb /= ?; apply/itv_dec; rewrite /= ?midf_lte // ?ltW.
Qed.
Lemma mid_in_itvoo : forall (xa xb : R), xa < xb -> mid xa xb \in `]xa, xb[.
Proof. by move=> xa xb ?; apply: mid_in_itv. Qed.
Lemma mid_in_itvcc : forall (xa xb : R), xa <= xb -> mid xa xb \in `[xa, xb].
Proof. by move=> xa xb ?; apply: mid_in_itv. Qed.
Lemma mem_miditv i : (i.1 < i.2)%O -> miditv i \in i.
Proof.
move: i => [[ba a|[]] [bb b|[]]] //= ab; first exact: mid_in_itv.
by rewrite !in_itv -lteifBlDl subrr lteif01.
by rewrite !in_itv lteifBlDr -lteifBlDl subrr lteif01.
Qed.
Lemma miditv_le_left i b : (i.1 < i.2)%O -> (BSide b (miditv i) <= i.2)%O.
Proof.
case: i => [x y] lti; have := mem_miditv lti; rewrite inE => /andP[_ ].
by apply: le_trans; rewrite !bnd_simp.
Qed.
Lemma miditv_ge_right i b : (i.1 < i.2)%O -> (i.1 <= BSide b (miditv i))%O.
Proof.
case: i => [x y] lti; have := mem_miditv lti; rewrite inE => /andP[+ _].
by move=> /le_trans; apply; rewrite !bnd_simp.
Qed.
Lemma in_segmentDgt0Pr x y z :
reflect (forall e, e > 0 -> y \in `[x - e, z + e]) (y \in `[x, z]).
Proof.
apply/(iffP idP)=> [xyz e /[dup] e_gt0 /ltW e_ge0 | xyz_e].
by rewrite in_itv /= lerBDr !ler_wpDr// (itvP xyz).
by rewrite in_itv /= ; apply/andP; split; apply/ler_addgt0Pr => ? /xyz_e;
rewrite in_itv /= lerBDr => /andP [].
Qed.
Lemma in_segmentDgt0Pl x y z :
reflect (forall e, e > 0 -> y \in `[- e + x, e + z]) (y \in `[x, z]).
Proof.
apply/(equivP (in_segmentDgt0Pr x y z)).
by split=> zxy e /zxy; rewrite [z + _]addrC [_ + x]addrC.
Qed.
End IntervalField.
|
NumDen.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen
-/
import Mathlib.RingTheory.Localization.FractionRing
import Mathlib.RingTheory.Localization.Integer
import Mathlib.RingTheory.UniqueFactorizationDomain.GCDMonoid
/-!
# Numerator and denominator in a localization
## Implementation notes
See `Mathlib/RingTheory/Localization/Basic.lean` for a design overview.
## Tags
localization, ring localization, commutative ring localization, characteristic predicate,
commutative ring, field of fractions
-/
namespace IsFractionRing
open IsLocalization
section NumDen
variable (A : Type*) [CommRing A] [IsDomain A] [UniqueFactorizationMonoid A]
variable {K : Type*} [Field K] [Algebra A K] [IsFractionRing A K]
theorem exists_reduced_fraction (x : K) :
∃ (a : A) (b : nonZeroDivisors A), IsRelPrime a b ∧ mk' K a b = x := by
obtain ⟨⟨b, b_nonzero⟩, a, hab⟩ := exists_integer_multiple (nonZeroDivisors A) x
obtain ⟨a', b', c', no_factor, rfl, rfl⟩ :=
UniqueFactorizationMonoid.exists_reduced_factors' a b
(mem_nonZeroDivisors_iff_ne_zero.mp b_nonzero)
obtain ⟨_, b'_nonzero⟩ := mul_mem_nonZeroDivisors.mp b_nonzero
refine ⟨a', ⟨b', b'_nonzero⟩, no_factor, ?_⟩
refine mul_left_cancel₀ (IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors b_nonzero) ?_
simp only [RingHom.map_mul, Algebra.smul_def] at *
rw [← hab, mul_assoc, mk'_spec' _ a' ⟨b', b'_nonzero⟩]
/-- `f.num x` is the numerator of `x : f.codomain` as a reduced fraction. -/
noncomputable def num (x : K) : A :=
Classical.choose (exists_reduced_fraction A x)
/-- `f.den x` is the denominator of `x : f.codomain` as a reduced fraction. -/
noncomputable def den (x : K) : nonZeroDivisors A :=
Classical.choose (Classical.choose_spec (exists_reduced_fraction A x))
theorem num_den_reduced (x : K) : IsRelPrime (num A x) (den A x) :=
(Classical.choose_spec (Classical.choose_spec (exists_reduced_fraction A x))).1
-- @[simp] -- Porting note: LHS reduces to give the simp lemma below
theorem mk'_num_den (x : K) : mk' K (num A x) (den A x) = x :=
(Classical.choose_spec (Classical.choose_spec (exists_reduced_fraction A x))).2
@[simp]
theorem mk'_num_den' (x : K) : algebraMap A K (num A x) / algebraMap A K (den A x) = x := by
rw [← mk'_eq_div]
apply mk'_num_den
variable {A}
theorem num_mul_den_eq_num_iff_eq {x y : K} :
x * algebraMap A K (den A y) = algebraMap A K (num A y) ↔ x = y :=
⟨fun h => by simpa only [mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦
eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_den])⟩
theorem num_mul_den_eq_num_iff_eq' {x y : K} :
y * algebraMap A K (den A x) = algebraMap A K (num A x) ↔ x = y :=
⟨fun h ↦ by simpa only [eq_comm, mk'_num_den] using eq_mk'_iff_mul_eq.mpr h, fun h ↦
eq_mk'_iff_mul_eq.mp (by rw [h, mk'_num_den])⟩
theorem num_mul_den_eq_num_mul_den_iff_eq {x y : K} :
num A y * den A x = num A x * den A y ↔ x = y :=
⟨fun h ↦ by simpa only [mk'_num_den] using mk'_eq_of_eq' (S := K) h, fun h ↦ by rw [h]⟩
theorem eq_zero_of_num_eq_zero {x : K} (h : num A x = 0) : x = 0 :=
(num_mul_den_eq_num_iff_eq' (A := A)).mp (by rw [zero_mul, h, RingHom.map_zero])
@[simp]
lemma num_zero : IsFractionRing.num A (0 : K) = 0 := by
have := mk'_num_den' A (0 : K)
simp only [div_eq_zero_iff] at this
rcases this with h | h
· exact FaithfulSMul.algebraMap_injective A K (by convert h; simp)
· replace h : algebraMap A K (den A (0 : K)) = algebraMap A K 0 := by convert h; simp
absurd FaithfulSMul.algebraMap_injective A K h
apply nonZeroDivisors.coe_ne_zero
@[simp]
lemma num_eq_zero (x : K) : IsFractionRing.num A x = 0 ↔ x = 0 :=
⟨eq_zero_of_num_eq_zero, fun h ↦ h ▸ num_zero⟩
theorem isInteger_of_isUnit_den {x : K} (h : IsUnit (den A x : A)) : IsInteger A x := by
obtain ⟨d, hd⟩ := h
have d_ne_zero : algebraMap A K (den A x) ≠ 0 :=
IsFractionRing.to_map_ne_zero_of_mem_nonZeroDivisors (den A x).2
use ↑d⁻¹ * num A x
refine _root_.trans ?_ (mk'_num_den A x)
rw [map_mul, map_units_inv, hd]
apply mul_left_cancel₀ d_ne_zero
rw [← mul_assoc, mul_inv_cancel₀ d_ne_zero, one_mul, mk'_spec']
theorem isUnit_den_iff (x : K) : IsUnit (den A x : A) ↔ IsLocalization.IsInteger A x where
mp := isInteger_of_isUnit_den
mpr h := by
have ⟨v, h⟩ := h
apply IsRelPrime.isUnit_of_dvd (num_den_reduced A x).symm
use v
apply_fun algebraMap A K
· simp only [map_mul, h]
rw [mul_comm, ← div_eq_iff]
· simp only [mk'_num_den']
intro h
replace h : algebraMap A K (den A x : A) = algebraMap A K 0 := by convert h; simp
exact nonZeroDivisors.coe_ne_zero _ <| FaithfulSMul.algebraMap_injective A K h
exact FaithfulSMul.algebraMap_injective A K
theorem isUnit_den_zero : IsUnit (den A (0 : K) : A) := by
simp [isUnit_den_iff, IsLocalization.isInteger_zero]
lemma associated_den_num_inv (x : K) (hx : x ≠ 0) : Associated (den A x : A) (num A x⁻¹) :=
associated_of_dvd_dvd
(IsRelPrime.dvd_of_dvd_mul_right (IsFractionRing.num_den_reduced A x).symm <|
dvd_of_mul_left_dvd (a := (den A x⁻¹ : A)) <| dvd_of_eq <|
FaithfulSMul.algebraMap_injective A K <| Eq.symm <| eq_of_div_eq_one
(by simp [mul_div_mul_comm, hx]))
(IsRelPrime.dvd_of_dvd_mul_right (IsFractionRing.num_den_reduced A x⁻¹) <|
dvd_of_mul_left_dvd (a := (num A x : A)) <| dvd_of_eq <|
FaithfulSMul.algebraMap_injective A K <| eq_of_div_eq_one
(by simp [mul_div_mul_comm, hx]))
lemma associated_num_den_inv (x : K) (hx : x ≠ 0) : Associated (num A x : A) (den A x⁻¹) := by
have : Associated (num A x⁻¹⁻¹ : A) (den A x⁻¹) :=
(associated_den_num_inv x⁻¹ (inv_ne_zero hx)).symm
rw [inv_inv] at this
exact this
end NumDen
end IsFractionRing
|
BaseChange.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.QuadraticForm.TensorProduct
import Mathlib.LinearAlgebra.CliffordAlgebra.Conjugation
import Mathlib.LinearAlgebra.TensorProduct.Opposite
import Mathlib.RingTheory.TensorProduct.Basic
/-!
# The base change of a clifford algebra
In this file we show the isomorphism
* `CliffordAlgebra.equivBaseChange A Q` :
`CliffordAlgebra (Q.baseChange A) ≃ₐ[A] (A ⊗[R] CliffordAlgebra Q)`
with forward direction `CliffordAlgebra.toBasechange A Q` and reverse direction
`CliffordAlgebra.ofBasechange A Q`.
This covers a more general case of the complexification of clifford algebras (as described in §2.2
of https://empg.maths.ed.ac.uk/Activities/Spin/Lecture2.pdf), where ℂ and ℝ are replaced by an
`R`-algebra `A` (where `2 : R` is invertible).
We show the additional results:
* `CliffordAlgebra.toBasechange_ι`: the effect of base-changing pure vectors.
* `CliffordAlgebra.ofBasechange_tmul_ι`: the effect of un-base-changing a tensor of a pure vectors.
* `CliffordAlgebra.toBasechange_involute`: the effect of base-changing an involution.
* `CliffordAlgebra.toBasechange_reverse`: the effect of base-changing a reversal.
-/
variable {R A V : Type*}
variable [CommRing R] [CommRing A] [AddCommGroup V]
variable [Algebra R A] [Module R V]
variable [Invertible (2 : R)]
open scoped TensorProduct
namespace CliffordAlgebra
variable (A)
/-- Auxiliary construction: note this is really just a heterobasic `CliffordAlgebra.map`. -/
def ofBaseChangeAux (Q : QuadraticForm R V) :
CliffordAlgebra Q →ₐ[R] CliffordAlgebra (Q.baseChange A) :=
CliffordAlgebra.lift Q <| by
refine ⟨(ι (Q.baseChange A)).restrictScalars R ∘ₗ TensorProduct.mk R A V 1, fun v => ?_⟩
refine (CliffordAlgebra.ι_sq_scalar (Q.baseChange A) (1 ⊗ₜ v)).trans ?_
rw [QuadraticForm.baseChange_tmul, one_mul, ← Algebra.algebraMap_eq_smul_one,
← IsScalarTower.algebraMap_apply]
@[simp] theorem ofBaseChangeAux_ι (Q : QuadraticForm R V) (v : V) :
ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (1 ⊗ₜ v) :=
CliffordAlgebra.lift_ι_apply _ _ v
/-- Convert from the base-changed clifford algebra to the clifford algebra over a base-changed
module. -/
def ofBaseChange (Q : QuadraticForm R V) :
A ⊗[R] CliffordAlgebra Q →ₐ[A] CliffordAlgebra (Q.baseChange A) :=
Algebra.TensorProduct.lift (Algebra.ofId _ _) (ofBaseChangeAux A Q)
fun _a _x => Algebra.commutes _ _
@[simp] theorem ofBaseChange_tmul_ι (Q : QuadraticForm R V) (z : A) (v : V) :
ofBaseChange A Q (z ⊗ₜ ι Q v) = ι (Q.baseChange A) (z ⊗ₜ v) := by
change algebraMap _ _ z * ofBaseChangeAux A Q (ι Q v) = ι (Q.baseChange A) (z ⊗ₜ[R] v)
rw [ofBaseChangeAux_ι, ← Algebra.smul_def, ← map_smul, TensorProduct.smul_tmul', smul_eq_mul,
mul_one]
@[simp] theorem ofBaseChange_tmul_one (Q : QuadraticForm R V) (z : A) :
ofBaseChange A Q (z ⊗ₜ 1) = algebraMap _ _ z := by
change algebraMap _ _ z * ofBaseChangeAux A Q 1 = _
rw [map_one, mul_one]
/-- Convert from the clifford algebra over a base-changed module to the base-changed clifford
algebra. -/
def toBaseChange (Q : QuadraticForm R V) :
CliffordAlgebra (Q.baseChange A) →ₐ[A] A ⊗[R] CliffordAlgebra Q :=
CliffordAlgebra.lift _ <| by
refine ⟨TensorProduct.AlgebraTensorModule.map (LinearMap.id : A →ₗ[A] A) (ι Q), ?_⟩
letI : Invertible (2 : A) := (Invertible.map (algebraMap R A) 2).copy 2 (map_ofNat _ _).symm
letI : Invertible (2 : A ⊗[R] CliffordAlgebra Q) :=
(Invertible.map (algebraMap R _) 2).copy 2 (map_ofNat _ _).symm
suffices hpure_tensor : ∀ v w, (1 * 1) ⊗ₜ[R] (ι Q v * ι Q w) + (1 * 1) ⊗ₜ[R] (ι Q w * ι Q v) =
QuadraticMap.polarBilin (Q.baseChange A) (1 ⊗ₜ[R] v) (1 ⊗ₜ[R] w) ⊗ₜ[R] 1 by
-- the crux is that by converting to a statement about linear maps instead of quadratic forms,
-- we then have access to all the partially-applied `ext` lemmas.
rw [CliffordAlgebra.forall_mul_self_eq_iff (isUnit_of_invertible _)]
refine TensorProduct.AlgebraTensorModule.curry_injective ?_
ext v w
dsimp
exact hpure_tensor v w
intros v w
rw [← TensorProduct.tmul_add, CliffordAlgebra.ι_mul_ι_add_swap,
QuadraticForm.polarBilin_baseChange, LinearMap.BilinForm.baseChange_tmul, one_mul,
TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one, QuadraticMap.polarBilin_apply_apply]
@[simp] theorem toBaseChange_ι (Q : QuadraticForm R V) (z : A) (v : V) :
toBaseChange A Q (ι (Q.baseChange A) (z ⊗ₜ v)) = z ⊗ₜ ι Q v :=
CliffordAlgebra.lift_ι_apply _ _ _
theorem toBaseChange_comp_involute (Q : QuadraticForm R V) :
(toBaseChange A Q).comp (involute : CliffordAlgebra (Q.baseChange A) →ₐ[A] _) =
(Algebra.TensorProduct.map (AlgHom.id _ _) involute).comp (toBaseChange A Q) := by
ext v
change toBaseChange A Q (involute (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))
= (Algebra.TensorProduct.map (AlgHom.id _ _) involute :
A ⊗[R] CliffordAlgebra Q →ₐ[A] _)
(toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))
rw [toBaseChange_ι, involute_ι, map_neg (toBaseChange A Q), toBaseChange_ι,
Algebra.TensorProduct.map_tmul, AlgHom.id_apply, involute_ι, TensorProduct.tmul_neg]
/-- The involution acts only on the right of the tensor product. -/
theorem toBaseChange_involute (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) :
toBaseChange A Q (involute x) =
TensorProduct.map LinearMap.id (involute.toLinearMap) (toBaseChange A Q x) :=
DFunLike.congr_fun (toBaseChange_comp_involute A Q) x
open MulOpposite
/-- Auxiliary theorem used to prove `toBaseChange_reverse` without needing induction. -/
theorem toBaseChange_comp_reverseOp (Q : QuadraticForm R V) :
(toBaseChange A Q).op.comp reverseOp =
((Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q)).toAlgHom.comp <|
(Algebra.TensorProduct.map
(AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q))).comp
(toBaseChange A Q)) := by
ext v
change op (toBaseChange A Q (reverse (ι (Q.baseChange A) (1 ⊗ₜ[R] v)))) =
Algebra.TensorProduct.opAlgEquiv R A A (CliffordAlgebra Q)
(Algebra.TensorProduct.map (AlgEquiv.toOpposite A A).toAlgHom (reverseOp (Q := Q))
(toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] v))))
rw [toBaseChange_ι, reverse_ι, toBaseChange_ι, Algebra.TensorProduct.map_tmul,
Algebra.TensorProduct.opAlgEquiv_tmul, reverseOp_ι]
rfl
/-- `reverse` acts only on the right of the tensor product. -/
theorem toBaseChange_reverse (Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) :
toBaseChange A Q (reverse x) =
TensorProduct.map LinearMap.id reverse (toBaseChange A Q x) := by
have := DFunLike.congr_fun (toBaseChange_comp_reverseOp A Q) x
refine (congr_arg unop this).trans ?_; clear this
refine (LinearMap.congr_fun (TensorProduct.AlgebraTensorModule.map_comp _ _ _ _).symm _).trans ?_
rw [reverse, ← AlgEquiv.toLinearMap, ← AlgEquiv.toLinearEquiv_toLinearMap,
AlgEquiv.toLinearEquiv_toOpposite]
dsimp
-- `simp` fails here due to a timeout looking for a `Subsingleton` instance!?
rw [LinearEquiv.self_trans_symm]
rfl
attribute [ext] TensorProduct.ext
theorem toBaseChange_comp_ofBaseChange (Q : QuadraticForm R V) :
(toBaseChange A Q).comp (ofBaseChange A Q) = AlgHom.id _ _ := by
ext v
simp
@[simp] theorem toBaseChange_ofBaseChange (Q : QuadraticForm R V) (x : A ⊗[R] CliffordAlgebra Q) :
toBaseChange A Q (ofBaseChange A Q x) = x :=
AlgHom.congr_fun (toBaseChange_comp_ofBaseChange A Q :) x
theorem ofBaseChange_comp_toBaseChange (Q : QuadraticForm R V) :
(ofBaseChange A Q).comp (toBaseChange A Q) = AlgHom.id _ _ := by
ext x
change ofBaseChange A Q (toBaseChange A Q (ι (Q.baseChange A) (1 ⊗ₜ[R] x)))
= ι (Q.baseChange A) (1 ⊗ₜ[R] x)
rw [toBaseChange_ι, ofBaseChange_tmul_ι]
@[simp] theorem ofBaseChange_toBaseChange
(Q : QuadraticForm R V) (x : CliffordAlgebra (Q.baseChange A)) :
ofBaseChange A Q (toBaseChange A Q x) = x :=
AlgHom.congr_fun (ofBaseChange_comp_toBaseChange A Q :) x
/-- Base-changing the vector space of a clifford algebra is isomorphic as an A-algebra to
base-changing the clifford algebra itself; <|Cℓ(A ⊗_R V, Q_A) ≅ A ⊗_R Cℓ(V, Q)<|.
This is `CliffordAlgebra.toBaseChange` and `CliffordAlgebra.ofBaseChange` as an equivalence. -/
@[simps!]
def equivBaseChange (Q : QuadraticForm R V) :
CliffordAlgebra (Q.baseChange A) ≃ₐ[A] A ⊗[R] CliffordAlgebra Q :=
AlgEquiv.ofAlgHom (toBaseChange A Q) (ofBaseChange A Q)
(toBaseChange_comp_ofBaseChange A Q)
(ofBaseChange_comp_toBaseChange A Q)
end CliffordAlgebra
|
FundamentalTheorem.lean
|
/-
Copyright (c) 2023 Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu
-/
import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs
import Mathlib.RingTheory.MvPolynomial.Tower
import Mathlib.Data.Finsupp.Notation
import Mathlib.Data.Finsupp.WellFounded
/-!
# The Fundamental Theorem of Symmetric Polynomials
In a polynomial ring in `n` variables over a commutative ring, the subalgebra of symmetric
polynomials is freely generated by the first `n` elementary symmetric polynomials (excluding
the 0th, which is simply 1). This is expressed as an isomorphism
`MvPolynomial.esymmAlgEquiv` between `MvPolynomial (Fin n) R` and
the symmetric subalgebra of any polynomial ring `MvPolynomial σ R` with `#σ = n`.
The forward map is called `MvPolynomial.esymmAlgHom`.
## Proof strategy
We follow the alternative proof on the Wikipedia page
https://en.wikipedia.org/wiki/Elementary_symmetric_polynomial#Alternative_proof
It suffices to show `esymmAlgHom` is both injective and surjective.
Endow the Fintype `σ` with a linear order and endow the (monic) monomials in the polynomial ring
`MvPolynomial σ R` with the lexicographic order on `σ →₀ ℕ`, which is a well order.
Then any nonzero polynomial `p : MvPolynomial σ R` has a largest nonzero monomial
(`AddMonoidAlgebra.supDegree toLex p`) and the corresponding coefficient is
`AddMonoidAlgebra.leadingCoeff toLex p`. If `p` is symmetric, any permutation of a nonzero monomial
in `p` must also be a nonzero monomial in `p`, so the largest nonzero monomial must be antitone
as a function `σ → ℕ` (`MvPolynomial.IsSymmetric.antitone_supDegree`). We can then construct a
monomial in `MvPolynomial (Fin n) R` whose image under `esymmAlgHom` has the same `supDegree` and
`leadingCoeff` as `p`: `MvPolynomial.supDegree_esymmAlgHomMonomial` says that the `supDegree` of
the image is given by `Fin.accumulate`, and `Fin.accumulate_invAccumulate` says that
`Fin.invAccumulate` is inverse to `Fin.accumulate` for antitone monomials.
If we subtract the image from `p`, we are left with a symmetric polynomial of
lower `supDegree`, which we may assume to be in the image by induction,
thanks to the well-orderedness of `Lex (σ →₀ ℕ)`; the surjectivity of `esymmAlgHom`
follows. For injectivity, just notice that the images of different monic monomials in
`MvPolynomial (Fin n) R` have different `supDegree` (`Fin.accumulate_injective`), so if there is
at least one nonzero monomial, the images cannot all cancel out
(`AddMonoidAlgebra.sum_ne_zero_of_injOn_supDegree`).
We actually only define `Fin.accumulate` in the case `σ := Fin m` rather than an arbitrary Fintype
with a linear order; we show that `esymmAlgHom` is in fact surjective whenever `m ≤ n` and
injective whenever `n ≤ m`, and then transfer the results to any Fintype `σ`. See
`MvPolynomial.injective_esymmAlgHom` and `MvPolynomial.esymmAlgHom_surjective`.
-/
variable {σ τ R : Type*} {n m k : ℕ}
open AddMonoidAlgebra Finset
namespace Fin
section accumulate
/-- The `j`th entry of `accumulate n m t` is the sum of `t i` over all `i ≥ j`. -/
@[simps] def accumulate (n m : ℕ) : (Fin n → ℕ) →+ (Fin m → ℕ) where
toFun t j := ∑ i : Fin n with j.val ≤ i.val, t i
map_zero' := funext <| fun _ ↦ sum_eq_zero <| fun _ _ ↦ rfl
map_add' _ _ := funext <| fun _ ↦ sum_add_distrib
/-- The `i`th entry of `invAccumulate n m s` is `s i - s (i+1)`, where `s j = 0` if `j ≥ m`. -/
def invAccumulate (n m : ℕ) (s : Fin m → ℕ) (i : Fin n) : ℕ :=
(if hi : i < m then s ⟨i, hi⟩ else 0) - (if hi : i + 1 < m then s ⟨i + 1, hi⟩ else 0)
lemma accumulate_rec {i n m : ℕ} (hin : i < n) (him : i + 1 < m) (t : Fin n → ℕ) :
accumulate n m t ⟨i, Nat.lt_of_succ_lt him⟩ = t ⟨i, hin⟩ + accumulate n m t ⟨i + 1, him⟩ := by
simp_rw [accumulate_apply]
convert (add_sum_erase _ _ _).symm
· ext
rw [mem_erase]
simp_rw [mem_filter_univ, i.succ_le_iff, lt_iff_le_and_ne]
rw [and_comm, ne_comm, ← Fin.val_ne_iff]
· exact mem_filter.2 ⟨mem_univ _, le_rfl⟩
lemma accumulate_last {i n m : ℕ} (hin : i < n) (hmi : m = i + 1) (t : Fin n → ℕ)
(ht : ∀ j : Fin n, m ≤ j → t j = 0) :
accumulate n m t ⟨i, i.lt_succ_self.trans_eq hmi.symm⟩ = t ⟨i, hin⟩ := by
rw [accumulate_apply]
apply sum_eq_single_of_mem
· rw [mem_filter]; exact ⟨mem_univ _, le_rfl⟩
refine fun j hij hji ↦ ht j ?_
rw [mem_filter_univ] at hij
exact hmi.trans_le (hij.lt_of_ne (Fin.val_ne_iff.2 hji).symm).nat_succ_le
lemma accumulate_injective {n m} (hnm : n ≤ m) : Function.Injective (accumulate n m) := by
refine fun t s he ↦ funext fun i ↦ ?_
obtain h | h := lt_or_ge (i.1 + 1) m
· have := accumulate_rec i.2 h s
rwa [← he, accumulate_rec i.2 h t, add_right_cancel_iff] at this
· have := h.antisymm (i.2.nat_succ_le.trans hnm)
rw [← accumulate_last i.2 this t, ← accumulate_last i.2 this s, he]
iterate 2 { intro j hj; exact ((j.2.trans_le hnm).not_ge hj).elim }
lemma accumulate_invAccumulate {n m} (hmn : m ≤ n) {s : Fin m → ℕ} (hs : Antitone s) :
accumulate n m (invAccumulate n m s) = s := funext <| fun ⟨i, hi⟩ ↦ by
have := Nat.le_sub_one_of_lt hi
revert hi
refine Nat.decreasingInduction' (fun i hi _ ih him ↦ ?_) this fun hm ↦ ?_
· rw [← Nat.pred_eq_sub_one, Nat.lt_pred_iff, Nat.succ_eq_add_one] at hi
rw [accumulate_rec (him.trans_le hmn) hi, ih hi, invAccumulate, dif_pos him, dif_pos hi]
simp only
exact Nat.sub_add_cancel (hs i.le_succ)
· have := (Nat.sub_one_add_one <| Nat.ne_zero_of_lt hm).symm
rw [accumulate_last (hm.trans_le hmn) this, invAccumulate, dif_pos hm, dif_neg this.not_gt,
Nat.sub_zero]
intro j hj
rw [invAccumulate, dif_neg hj.not_gt, Nat.zero_sub]
end accumulate
end Fin
namespace MvPolynomial
open Fin
section CommSemiring
variable [CommSemiring R] [Fintype σ] [Fintype τ]
variable (σ R n) in
/-- The `R`-algebra homomorphism from $R[x_1,\dots,x_n]$ to the symmetric subalgebra of
$R[\{x_i \mid i ∈ σ\}]$ sending $x_i$ to the $i$-th elementary symmetric polynomial. -/
noncomputable def esymmAlgHom :
MvPolynomial (Fin n) R →ₐ[R] symmetricSubalgebra σ R :=
aeval (fun i ↦ ⟨esymm σ R (i + 1), esymm_isSymmetric σ R _⟩)
lemma esymmAlgHom_apply (p : MvPolynomial (Fin n) R) :
(esymmAlgHom σ R n p).val = aeval (fun i : Fin n ↦ esymm σ R (i + 1)) p :=
(Subalgebra.mvPolynomial_aeval_coe _ _ _).symm
lemma rename_esymmAlgHom (e : σ ≃ τ) :
(renameSymmetricSubalgebra e).toAlgHom.comp (esymmAlgHom σ R n) = esymmAlgHom τ R n := by
ext i : 2
simp_rw [AlgHom.comp_apply, esymmAlgHom, aeval_X, AlgEquiv.toAlgHom_eq_coe, AlgHom.coe_coe,
renameSymmetricSubalgebra_apply_coe, rename_esymm]
variable (σ) in
/-- The image of a monomial under `esymmAlgHom`. -/
noncomputable def esymmAlgHomMonomial (t : Fin n →₀ ℕ) (r : R) :
MvPolynomial σ R := (esymmAlgHom σ R n <| monomial t r).val
variable {i : Fin n} {r : R}
lemma isSymmetric_esymmAlgHomMonomial (t : Fin n →₀ ℕ) (r : R) :
(esymmAlgHomMonomial σ t r).IsSymmetric := (esymmAlgHom _ _ _ _).2
lemma esymmAlgHomMonomial_single :
esymmAlgHomMonomial σ (Finsupp.single i k) r = C r * esymm σ R (i + 1) ^ k := by
rw [esymmAlgHomMonomial, esymmAlgHom_apply, aeval_monomial, algebraMap_eq,
Finsupp.prod_single_index]
exact pow_zero _
lemma esymmAlgHomMonomial_single_one :
esymmAlgHomMonomial σ (Finsupp.single i k) 1 = esymm σ R (i + 1) ^ k := by
rw [esymmAlgHomMonomial_single, map_one, one_mul]
lemma esymmAlgHomMonomial_add {t s : Fin n →₀ ℕ} :
esymmAlgHomMonomial σ (t + s) r = esymmAlgHomMonomial σ t r * esymmAlgHomMonomial σ s 1 := by
simp_rw [esymmAlgHomMonomial, esymmAlgHom_apply, ← map_mul, monomial_mul, mul_one]
lemma esymmAlgHom_zero : esymmAlgHomMonomial σ (0 : Fin n →₀ ℕ) r = C r := by
rw [esymmAlgHomMonomial, monomial_zero', esymmAlgHom_apply, aeval_C, algebraMap_eq]
private lemma supDegree_monic_esymm [Nontrivial R] {i : ℕ} (him : i < m) :
supDegree toLex (esymm (Fin m) R (i + 1)) =
toLex (Finsupp.indicator (Iic ⟨i, him⟩) fun _ _ ↦ 1) ∧
Monic toLex (esymm (Fin m) R (i + 1)) := by
have := supDegree_leadingCoeff_sum_eq (D := toLex) (s := univ.powersetCard (i + 1))
(i := Iic (⟨i, him⟩ : Fin m)) ?_ (f := fun s ↦ monomial (∑ j ∈ s, fun₀ | j => 1) (1 : R)) ?_
· rwa [← esymm_eq_sum_monomial, ← Finsupp.indicator_eq_sum_single, ← single_eq_monomial,
supDegree_single_ne_zero _ one_ne_zero, leadingCoeff_single toLex.injective] at this
· exact mem_powersetCard.2 ⟨subset_univ _, Fin.card_Iic _⟩
intro t ht hne
have ht' : #t = #(Iic (⟨i, him⟩ : Fin m)) := by
rw [(mem_powersetCard.1 ht).2, Fin.card_Iic]
simp_rw [← single_eq_monomial, supDegree_single_ne_zero _ one_ne_zero,
← Finsupp.indicator_eq_sum_single]
rw [ne_comm, Ne, ← subset_iff_eq_of_card_le ht'.le, not_subset] at hne
simp_rw [← mem_sdiff] at hne
have hkm := mem_sdiff.1 (min'_mem _ hne)
refine ⟨min' _ hne, fun k hk ↦ ?_, ?_⟩
all_goals simp only [ofLex_toLex, Finsupp.indicator_apply]
· have hki := mem_Iic.2 (hk.le.trans <| mem_Iic.1 hkm.1)
rw [dif_pos hki, dif_pos]
by_contra h
exact lt_irrefl k <| ((lt_min'_iff _ _).1 hk) _ <| mem_sdiff.2 ⟨hki, h⟩
· rw [dif_neg hkm.2, dif_pos hkm.1]; exact Nat.zero_lt_one
lemma supDegree_esymm [Nontrivial R] (him : i < m) :
ofLex (supDegree toLex <| esymm (Fin m) R (i + 1)) = accumulate n m (Finsupp.single i 1) := by
rw [(supDegree_monic_esymm him).1, ofLex_toLex]
ext j
simp_rw [Finsupp.indicator_apply, dite_eq_ite, mem_Iic, accumulate_apply, Finsupp.single_apply,
sum_ite_eq, mem_filter_univ, Fin.le_def]
lemma monic_esymm {i : ℕ} (him : i ≤ m) : Monic toLex (esymm (Fin m) R i) := by
cases i with
| zero =>
rw [esymm_zero]
exact monic_one toLex.injective
| succ i =>
nontriviality R
exact (supDegree_monic_esymm him).2
lemma leadingCoeff_esymmAlgHomMonomial (t : Fin n →₀ ℕ) (hnm : n ≤ m) :
leadingCoeff toLex (esymmAlgHomMonomial (Fin m) t r) = r := by
induction t using Finsupp.induction₂ with
| zero => rw [esymmAlgHom_zero, leadingCoeff_toLex_C]
| add_single i _ _ _ _ ih =>
rw [esymmAlgHomMonomial_add, esymmAlgHomMonomial_single_one,
((monic_esymm <| i.2.trans_le hnm).pow toLex_add toLex.injective).leadingCoeff_mul_eq_left,
ih]
exacts [toLex.injective, toLex_add]
lemma supDegree_esymmAlgHomMonomial (hr : r ≠ 0) (t : Fin n →₀ ℕ) (hnm : n ≤ m) :
ofLex (supDegree toLex <| esymmAlgHomMonomial (Fin m) t r) = accumulate n m t := by
nontriviality R
induction t using Finsupp.induction₂ with
| zero => simp_rw [esymmAlgHom_zero, supDegree_toLex_C, ofLex_zero, Finsupp.coe_zero, map_zero]
| add_single i _ _ _ _ ih =>
have := i.2.trans_le hnm
rw [esymmAlgHomMonomial_add, esymmAlgHomMonomial_single_one,
Monic.supDegree_mul_of_ne_zero_left toLex.injective toLex_add, ofLex_add, Finsupp.coe_add,
ih, Finsupp.coe_add, map_add, Monic.supDegree_pow rfl toLex_add toLex.injective, ofLex_smul,
Finsupp.coe_smul, supDegree_esymm this, ← map_nsmul, ← Finsupp.coe_smul,
Finsupp.smul_single, nsmul_one, Nat.cast_id]
· exact monic_esymm this
· exact (monic_esymm this).pow toLex_add toLex.injective
· rwa [Ne, ← leadingCoeff_eq_zero toLex.injective, leadingCoeff_esymmAlgHomMonomial _ hnm]
omit [Fintype σ] in
lemma IsSymmetric.antitone_supDegree [LinearOrder σ] {p : MvPolynomial σ R} (hp : p.IsSymmetric) :
Antitone ↑(ofLex <| p.supDegree toLex) := by
obtain rfl | h0 := eq_or_ne p 0
· rw [supDegree_zero, Finsupp.bot_eq_zero]
exact Pi.zero_mono
rw [Antitone]
by_contra! h
obtain ⟨i, j, hle, hlt⟩ := h
apply (le_sup (s := p.support) (f := toLex) _).not_gt
pick_goal 3
· rw [← hp (Equiv.swap i j), mem_support_iff, coeff_rename_mapDomain _ (Equiv.injective _)]
rw [Ne, ← leadingCoeff_eq_zero toLex.injective, leadingCoeff_toLex] at h0
assumption
refine ⟨i, fun k hk ↦ ?_, ?_⟩
all_goals dsimp only [Pi.toLex_apply, ofLex_toLex]
· conv_rhs => rw [← Equiv.swap_apply_of_ne_of_ne hk.ne (hk.trans_le hle).ne]
rw [Finsupp.mapDomain_apply (Equiv.injective _), supDegree]; rfl
· apply hlt.trans_eq
simp_rw [Finsupp.mapDomain_equiv_apply, Equiv.symm_swap, Equiv.swap_apply_left]
end CommSemiring
section CommRing
variable (R)
variable [Fintype σ] [CommRing R]
/- Also holds for a cancellative CommSemiring. -/
lemma esymmAlgHom_fin_injective (h : n ≤ m) :
Function.Injective (esymmAlgHom (Fin m) R n) := by
rw [injective_iff_map_eq_zero]
refine fun p ↦ (fun hp ↦ ?_).mtr
rw [p.as_sum, map_sum (esymmAlgHom (Fin m) R n), ← Subalgebra.coe_eq_zero,
AddSubmonoidClass.coe_finset_sum]
refine sum_ne_zero_of_injOn_supDegree (D := toLex) (support_eq_empty.not.2 hp) (fun t ht ↦ ?_)
(fun t ht s hs he ↦ DFunLike.ext' <| accumulate_injective h ?_)
· rw [← esymmAlgHomMonomial, Ne, ← leadingCoeff_eq_zero toLex.injective,
leadingCoeff_esymmAlgHomMonomial t h]
rwa [mem_support_iff] at ht
rw [mem_coe, mem_support_iff] at ht hs
dsimp only [Function.comp] at he
rwa [← esymmAlgHomMonomial, ← esymmAlgHomMonomial, ← ofLex_inj, DFunLike.ext'_iff,
supDegree_esymmAlgHomMonomial ht t h, supDegree_esymmAlgHomMonomial hs s h] at he
lemma esymmAlgHom_injective (hn : n ≤ Fintype.card σ) :
Function.Injective (esymmAlgHom σ R n) := by
rw [← rename_esymmAlgHom (Fintype.equivFin σ).symm, AlgHom.coe_comp]
exact (AlgEquiv.injective _).comp (esymmAlgHom_fin_injective R hn)
lemma esymmAlgHom_fin_bijective (n : ℕ) :
Function.Bijective (esymmAlgHom (Fin n) R n) := by
use esymmAlgHom_fin_injective R le_rfl
rintro ⟨p, hp⟩
rw [← AlgHom.mem_range]
obtain rfl | h0 := eq_or_ne p 0
· exact Subalgebra.zero_mem _
induction' he : p.supDegree toLex using WellFoundedLT.induction with t ih generalizing p; subst he
let t := Finsupp.equivFunOnFinite.symm (invAccumulate n n <| ↑(ofLex <| p.supDegree toLex))
have hd :
(esymmAlgHomMonomial _ t <| p.leadingCoeff toLex).supDegree toLex = p.supDegree toLex := by
rw [← ofLex_inj, DFunLike.ext'_iff, supDegree_esymmAlgHomMonomial _ _ le_rfl]
· exact accumulate_invAccumulate le_rfl hp.antitone_supDegree
· rwa [Ne, leadingCoeff_eq_zero toLex.injective]
obtain he | hne := eq_or_ne p (esymmAlgHomMonomial _ t <| p.leadingCoeff toLex)
· convert AlgHom.mem_range_self _ (monomial t <| p.leadingCoeff toLex)
have := (supDegree_sub_lt_of_leadingCoeff_eq toLex.injective hd.symm ?_).resolve_right hne
· specialize ih _ this _ (Subalgebra.sub_mem _ hp <| isSymmetric_esymmAlgHomMonomial _ _) _ rfl
· rwa [sub_ne_zero]
convert ← Subalgebra.add_mem _ ih ⟨monomial t (p.leadingCoeff toLex), rfl⟩
apply sub_add_cancel p
· rw [leadingCoeff_esymmAlgHomMonomial t le_rfl]
lemma esymmAlgHom_fin_surjective (h : m ≤ n) :
Function.Surjective (esymmAlgHom (Fin m) R n) := by
intro p
obtain ⟨q, rfl⟩ := (esymmAlgHom_fin_bijective R m).2 p
rw [← AlgHom.mem_range]
induction q using MvPolynomial.induction_on with
| C r => rw [← algebraMap_eq, AlgHom.commutes]; apply Subalgebra.algebraMap_mem
| add p q hp hq => rw [map_add]; exact Subalgebra.add_mem _ hp hq
| mul_X p i hp =>
rw [map_mul]
apply Subalgebra.mul_mem _ hp
rw [AlgHom.mem_range]
refine ⟨X ⟨i, i.2.trans_le h⟩, ?_⟩
simp_rw [esymmAlgHom, aeval_X]
lemma esymmAlgHom_surjective (hn : Fintype.card σ ≤ n) :
Function.Surjective (esymmAlgHom σ R n) := by
rw [← rename_esymmAlgHom (Fintype.equivFin σ).symm, AlgHom.coe_comp]
exact (AlgEquiv.surjective _).comp (esymmAlgHom_fin_surjective R hn)
/-- If the cardinality of `σ` is `n`, then `esymmAlgHom σ R n` is an isomorphism. -/
@[simps! apply]
noncomputable def esymmAlgEquiv (hn : Fintype.card σ = n) :
MvPolynomial (Fin n) R ≃ₐ[R] symmetricSubalgebra σ R :=
AlgEquiv.ofBijective (esymmAlgHom σ R n)
⟨esymmAlgHom_injective R hn.ge, esymmAlgHom_surjective R hn.le⟩
end CommRing
end MvPolynomial
|
interval.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import div fintype bigop order ssralg finset fingroup.
From mathcomp Require Import ssrnum.
(******************************************************************************)
(* Intervals in ordered types *)
(* *)
(* This file provides support for intervals in ordered types. The datatype *)
(* (interval T) gives a formal characterization of an interval, as the pair *)
(* of its right and left bounds. *)
(* interval T == the type of formal intervals on T. *)
(* x \in i == when i is a formal interval on an ordered type, *)
(* \in can be used to test membership. *)
(* itvP x_in_i == where x_in_i has type x \in i, if i is ground, *)
(* gives a set of rewrite rules that x_in_i implies *)
(* lteBSide, bnd_simp == multirules to simplify inequalities between interval *)
(* bounds *)
(* miditv i == middle point of interval i *)
(* *)
(* When using interval.v, the lemma `in_itv` is in practice very useful. For *)
(* example, the execution of the tactic `rewrite in_itv` w.r.t. an hypothesis *)
(* of the form x \in `]a, b[ into a < x < b. *)
(* *)
(* Intervals of T form an partially ordered type (porderType) whose ordering *)
(* is the subset relation. If T is a lattice, intervals also form a lattice *)
(* (latticeType) whose meet and join are intersection and convex hull *)
(* respectively. They are distributive if T is an orderType. *)
(* *)
(* We provide a set of notations to write intervals (see below) *)
(* `[a, b], `]a, b], ..., `]-oo, a], ..., `]-oo, +oo[ *)
(* The substrings "oo", "oc", "co", "cc" in the names of lemmas respectively *)
(* stand for the intervals of the shape `]a, b[, `]a, b], `[a, b[, `[a, b]. *)
(* The substrings "pinfty" and "ninfty" in the names of lemmas stand for *)
(* +oo and -oo. *)
(* We also provide the lemma subitvP which computes the inequalities one *)
(* needs to prove when trying to prove the inclusion of intervals. *)
(* *)
(* Remark that we cannot implement a boolean comparison test for intervals on *)
(* an arbitrary ordered types, for this problem might be undecidable. Note *)
(* also that type (interval R) may contain several inhabitants coding for the *)
(* same interval. However, these pathological issues do not arise when R is a *)
(* real domain: we could provide a specific theory for this important case. *)
(* *)
(* References: *)
(* - Cyril Cohen, Assia Mahboubi, Formal proofs in real algebraic geometry: *)
(* from ordered fields quantifier elimination, LMCS, 2012 *)
(* - Cyril Cohen, Formalized algebraic numbers: construction and first-order *)
(* theory, PhD thesis, 2012, section 4.3 *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "'-oo'".
Reserved Notation "'+oo'".
Reserved Notation "`[ a , b ]" (format "`[ a , b ]").
Reserved Notation "`] a , b ]" (format "`] a , b ]").
Reserved Notation "`[ a , b [" (format "`[ a , b [").
Reserved Notation "`] a , b [" (format "`] a , b [").
Reserved Notation "`] '-oo' , b ]" (format "`] '-oo' , b ]").
Reserved Notation "`] '-oo' , b [" (format "`] '-oo' , b [").
Reserved Notation "`[ a , '+oo' [" (format "`[ a , '+oo' [").
Reserved Notation "`] a , '+oo' [" (format "`] a , '+oo' [").
Reserved Notation "`] -oo , '+oo' [" (format "`] -oo , '+oo' [").
Local Open Scope order_scope.
Import Order.TTheory.
Variant itv_bound (T : Type) : Type := BSide of bool & T | BInfty of bool.
Notation BLeft := (BSide true).
Notation BRight := (BSide false).
Notation "'-oo'" := (BInfty _ true) : order_scope.
Notation "'+oo'" := (BInfty _ false) : order_scope.
Variant interval (T : Type) := Interval of itv_bound T & itv_bound T.
Coercion pair_of_interval T (I : interval T) : itv_bound T * itv_bound T :=
let: Interval b1 b2 := I in (b1, b2).
(* We provide the 9 following notations to help writing formal intervals *)
Notation "`[ a , b ]" := (Interval (BLeft a) (BRight b)) : order_scope.
Notation "`] a , b ]" := (Interval (BRight a) (BRight b)) : order_scope.
Notation "`[ a , b [" := (Interval (BLeft a) (BLeft b)) : order_scope.
Notation "`] a , b [" := (Interval (BRight a) (BLeft b)) : order_scope.
Notation "`] '-oo' , b ]" := (Interval -oo (BRight b)) : order_scope.
Notation "`] '-oo' , b [" := (Interval -oo (BLeft b)) : order_scope.
Notation "`[ a , '+oo' [" := (Interval (BLeft a) +oo) : order_scope.
Notation "`] a , '+oo' [" := (Interval (BRight a) +oo) : order_scope.
Notation "`] -oo , '+oo' [" := (Interval -oo +oo) : order_scope.
Notation "`[ a , b ]" := (Interval (BLeft a) (BRight b)) : ring_scope.
Notation "`] a , b ]" := (Interval (BRight a) (BRight b)) : ring_scope.
Notation "`[ a , b [" := (Interval (BLeft a) (BLeft b)) : ring_scope.
Notation "`] a , b [" := (Interval (BRight a) (BLeft b)) : ring_scope.
Notation "`] '-oo' , b ]" := (Interval -oo (BRight b)) : ring_scope.
Notation "`] '-oo' , b [" := (Interval -oo (BLeft b)) : ring_scope.
Notation "`[ a , '+oo' [" := (Interval (BLeft a) +oo) : ring_scope.
Notation "`] a , '+oo' [" := (Interval (BRight a) +oo) : ring_scope.
Notation "`] -oo , '+oo' [" := (Interval -oo +oo) : ring_scope.
Fact itv_bound_display (disp : Order.disp_t) : Order.disp_t. Proof. exact. Qed.
Fact interval_display (disp : Order.disp_t) : Order.disp_t. Proof. exact. Qed.
Module IntervalCan.
Section IntervalCan.
Variable T : Type.
Lemma itv_bound_can :
cancel (fun b : itv_bound T =>
match b with BSide b x => (b, Some x) | BInfty b => (b, None) end)
(fun b =>
match b with (b, Some x) => BSide b x | (b, None) => BInfty _ b end).
Proof. by case. Qed.
Lemma interval_can :
@cancel _ (interval T)
(fun '(Interval b1 b2) => (b1, b2)) (fun '(b1, b2) => Interval b1 b2).
Proof. by case. Qed.
End IntervalCan.
#[export, hnf]
HB.instance Definition _ (T : eqType) := Equality.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : eqType) := Equality.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : choiceType) := Choice.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : choiceType) := Choice.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : countType) := Countable.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : countType) := Countable.copy (interval T)
(can_type (@interval_can T)).
#[export, hnf]
HB.instance Definition _ (T : finType) := Finite.copy (itv_bound T)
(can_type (@itv_bound_can T)).
#[export, hnf]
HB.instance Definition _ (T : finType) := Finite.copy (interval T)
(can_type (@interval_can T)).
Module Exports. HB.reexport. End Exports.
End IntervalCan.
Export IntervalCan.Exports.
Section IntervalPOrder.
Variable (disp : Order.disp_t) (T : porderType disp).
Implicit Types (x y z : T) (b bl br : itv_bound T) (i : interval T).
Definition le_bound b1 b2 :=
match b1, b2 with
| -oo, _ | _, +oo => true
| BSide b1 x1, BSide b2 x2 => x1 < x2 ?<= if b2 ==> b1
| _, _ => false
end.
Definition lt_bound b1 b2 :=
match b1, b2 with
| -oo, +oo | -oo, BSide _ _ | BSide _ _, +oo => true
| BSide b1 x1, BSide b2 x2 => x1 < x2 ?<= if b1 && ~~ b2
| _, _ => false
end.
Lemma lt_bound_def b1 b2 : lt_bound b1 b2 = (b2 != b1) && le_bound b1 b2.
Proof. by case: b1 b2 => [[]?|[]][[]?|[]] //=; rewrite lt_def. Qed.
Lemma le_bound_refl : reflexive le_bound.
Proof. by move=> [[]?|[]] /=. Qed.
Lemma le_bound_anti : antisymmetric le_bound.
Proof. by case=> [[]?|[]] [[]?|[]] //=; case: comparableP => // ->. Qed.
Lemma le_bound_trans : transitive le_bound.
Proof.
by case=> [[]?|[]] [[]?|[]] [[]?|[]] lexy leyz //;
apply: (lteif_imply _ (lteif_trans lexy leyz)).
Qed.
HB.instance Definition _ :=
Order.isPOrder.Build (itv_bound_display disp) (itv_bound T)
lt_bound_def le_bound_refl le_bound_anti le_bound_trans.
Lemma bound_lexx c1 c2 x : (BSide c1 x <= BSide c2 x) = (c2 ==> c1).
Proof. by rewrite /<=%O /= lteifxx. Qed.
Lemma bound_ltxx c1 c2 x : (BSide c1 x < BSide c2 x) = (c1 && ~~ c2).
Proof. by rewrite /<%O /= lteifxx. Qed.
Lemma ge_pinfty b : (+oo <= b) = (b == +oo). Proof. by case: b => [|] []. Qed.
Lemma le_ninfty b : (b <= -oo) = (b == -oo). Proof. by case: b => // - []. Qed.
Lemma gt_pinfty b : (+oo < b) = false. Proof. by []. Qed.
Lemma lt_ninfty b : (b < -oo) = false. Proof. by case: b => // -[]. Qed.
Lemma ltBSide x y (b b' : bool) :
BSide b x < BSide b' y = (x < y ?<= if b && ~~ b').
Proof. by []. Qed.
Lemma leBSide x y (b b' : bool) :
BSide b x <= BSide b' y = (x < y ?<= if b' ==> b).
Proof. by []. Qed.
Definition lteBSide := (ltBSide, leBSide).
Lemma ltBRight_leBLeft b x : b < BRight x = (b <= BLeft x).
Proof. by move: b => [[] b|[]]. Qed.
Lemma leBRight_ltBLeft b x : BRight x <= b = (BLeft x < b).
Proof. by move: b => [[] b|[]]. Qed.
Let BLeft_ltE x y (b : bool) : BSide b x < BLeft y = (x < y).
Proof. by case: b. Qed.
Let BRight_leE x y (b : bool) : BSide b x <= BRight y = (x <= y).
Proof. by case: b. Qed.
Let BRight_BLeft_leE x y : BRight x <= BLeft y = (x < y).
Proof. by []. Qed.
Let BLeft_BRight_ltE x y : BLeft x < BRight y = (x <= y).
Proof. by []. Qed.
Let BRight_BSide_ltE x y (b : bool) : BRight x < BSide b y = (x < y).
Proof. by case: b. Qed.
Let BLeft_BSide_leE x y (b : bool) : BLeft x <= BSide b y = (x <= y).
Proof. by case: b. Qed.
Let BSide_ltE x y (b : bool) : BSide b x < BSide b y = (x < y).
Proof. by case: b. Qed.
Let BSide_leE x y (b : bool) : BSide b x <= BSide b y = (x <= y).
Proof. by case: b. Qed.
Let BInfty_leE a : a <= BInfty T false. Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_geE a : BInfty T true <= a. Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_le_eqE a : BInfty T false <= a = (a == BInfty T false).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ge_eqE a : a <= BInfty T true = (a == BInfty T true).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ltE a : a < BInfty T false = (a != BInfty T false).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_gtE a : BInfty T true < a = (a != BInfty T true).
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_ltF a : BInfty T false < a = false.
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_gtF a : a < BInfty T true = false.
Proof. by case: a => [[] a|[]]. Qed.
Let BInfty_BInfty_ltE : BInfty T true < BInfty T false. Proof. by []. Qed.
Definition bnd_simp := (BLeft_ltE, BRight_leE,
BRight_BLeft_leE, BLeft_BRight_ltE,
BRight_BSide_ltE, BLeft_BSide_leE, BSide_ltE, BSide_leE,
BInfty_leE, BInfty_geE, BInfty_BInfty_ltE,
BInfty_le_eqE, BInfty_ge_eqE, BInfty_ltE, BInfty_gtE, BInfty_ltF, BInfty_gtF,
@lexx _ T, @ltxx _ T, @eqxx T).
Lemma comparable_BSide_min s (x y : T) : (x >=< y)%O ->
BSide s (Order.min x y) = Order.min (BSide s x) (BSide s y).
Proof. by rewrite !minEle bnd_simp => /comparable_leP[]. Qed.
Lemma comparable_BSide_max s (x y : T) : (x >=< y)%O ->
BSide s (Order.max x y) = Order.max (BSide s x) (BSide s y).
Proof. by rewrite !maxEle bnd_simp => /comparable_leP[]. Qed.
Definition subitv i1 i2 :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in (b2l <= b1l) && (b1r <= b2r).
Lemma subitv_refl : reflexive subitv.
Proof. by case=> /= ? ?; rewrite !lexx. Qed.
Lemma subitv_anti : antisymmetric subitv.
Proof.
by case=> [? ?][? ?]; rewrite andbACA => /andP[] /le_anti -> /le_anti ->.
Qed.
Lemma subitv_trans : transitive subitv.
Proof.
case=> [yl yr][xl xr][zl zr] /andP [Hl Hr] /andP [Hl' Hr'] /=.
by rewrite (le_trans Hl' Hl) (le_trans Hr Hr').
Qed.
HB.instance Definition _ :=
Order.isPOrder.Build (interval_display disp) (interval T)
(fun _ _ => erefl) subitv_refl subitv_anti subitv_trans.
Definition pred_of_itv i : pred T := [pred x | `[x, x] <= i].
Canonical Structure itvPredType := PredType pred_of_itv.
Lemma subitvE b1l b1r b2l b2r :
(Interval b1l b1r <= Interval b2l b2r) = (b2l <= b1l) && (b1r <= b2r).
Proof. by []. Qed.
Lemma in_itv x i :
x \in i =
let: Interval l u := i in
match l with
| BSide b lb => lb < x ?<= if b
| BInfty b => b
end &&
match u with
| BSide b ub => x < ub ?<= if ~~ b
| BInfty b => ~~ b
end.
Proof. by case: i => [[? ?|[]][|[]]]. Qed.
Lemma itv_boundlr bl br x :
(x \in Interval bl br) = (bl <= BLeft x) && (BRight x <= br).
Proof. by []. Qed.
Lemma itv_splitI bl br x :
x \in Interval bl br = (x \in Interval bl +oo) && (x \in Interval -oo br).
Proof. by rewrite !itv_boundlr andbT. Qed.
Lemma subitvP i1 i2 : i1 <= i2 -> {subset i1 <= i2}.
Proof. by move=> ? ? /le_trans; exact. Qed.
(* Remove the line below when requiring Coq >= 8.20 *)
#[warning="-unsupported-attributes"]
#[warn(note="The lemma subset_itv was generalized in MathComp 2.4.0 and the original was renamed to subset_itv_bound.",
cats="mathcomp-subset-itv")]
Lemma subset_itv (x y z u : itv_bound T) : x <= y -> z <= u ->
{subset Interval y z <= Interval x u}.
Proof. by move=> xy zu; apply: subitvP; rewrite subitvE xy zu. Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use subset_itv instead.")]
Lemma subset_itv_bound (r s u v : bool) x y : r <= u -> v <= s ->
{subset Interval (BSide r x) (BSide s y) <= Interval (BSide u x) (BSide v y)}.
Proof.
by move: r s u v=> [] [] [] []// *; apply: subset_itv; rewrite bnd_simp.
Qed.
Lemma subset_itv_oo_cc x y : {subset `]x, y[ <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oo_oc x y : {subset `]x, y[ <= `]x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oo_co x y : {subset `]x, y[ <= `[x, y[}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_oc_cc x y : {subset `]x, y] <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma subset_itv_co_cc x y : {subset `[x, y[ <= `[x, y]}.
Proof. by apply: subset_itv; rewrite bnd_simp. Qed.
Lemma itvxx x : `[x, x] =i pred1 x.
Proof. by move=> y; rewrite in_itv/= -eq_le eq_sym. Qed.
Lemma itvxxP y x : reflect (y = x) (y \in `[x, x]).
Proof. by rewrite itvxx; apply/eqP. Qed.
Lemma subitvPl b1l b2l br :
b2l <= b1l -> {subset Interval b1l br <= Interval b2l br}.
Proof. by move=> ?; apply: subitvP; rewrite subitvE lexx andbT. Qed.
Lemma subitvPr bl b1r b2r :
b1r <= b2r -> {subset Interval bl b1r <= Interval bl b2r}.
Proof. by move=> ?; apply: subitvP; rewrite subitvE lexx. Qed.
Lemma itv_xx x cl cr y :
y \in Interval (BSide cl x) (BSide cr x) = cl && ~~ cr && (y == x).
Proof. by case: cl cr => [] []; rewrite [LHS]lteif_anti // eq_sym. Qed.
Lemma boundl_in_itv c x b : x \in Interval (BSide c x) b = c && (BRight x <= b).
Proof. by rewrite itv_boundlr bound_lexx. Qed.
Lemma boundr_in_itv c x b :
x \in Interval b (BSide c x) = ~~ c && (b <= BLeft x).
Proof. by rewrite itv_boundlr bound_lexx implybF andbC. Qed.
Definition bound_in_itv := (boundl_in_itv, boundr_in_itv).
Lemma lt_in_itv bl br x : x \in Interval bl br -> bl < br.
Proof. by case/andP; apply/le_lt_trans. Qed.
Lemma lteif_in_itv cl cr yl yr x :
x \in Interval (BSide cl yl) (BSide cr yr) -> yl < yr ?<= if cl && ~~ cr.
Proof. exact: lt_in_itv. Qed.
Lemma itv_ge b1 b2 : ~~ (b1 < b2) -> Interval b1 b2 =i pred0.
Proof. by move=> ltb12 y; apply/contraNF: ltb12; apply/lt_in_itv. Qed.
Definition itv_decompose i x : Prop :=
let: Interval l u := i in
(match l return Prop with
| BSide b lb => lb < x ?<= if b
| BInfty b => b
end *
match u return Prop with
| BSide b ub => x < ub ?<= if ~~ b
| BInfty b => ~~ b
end)%type.
Lemma itv_dec : forall x i, reflect (itv_decompose i x) (x \in i).
Proof. by move=> ? [[? ?|[]][? ?|[]]]; apply: (iffP andP); case. Qed.
Arguments itv_dec {x i}.
(* we compute a set of rewrite rules associated to an interval *)
Definition itv_rewrite i x : Type :=
let: Interval l u := i in
(match l with
| BLeft a => (a <= x) * (x < a = false)
| BRight a => (a <= x) * (a < x) * (x <= a = false) * (x < a = false)
| -oo => forall x : T, x == x
| +oo => forall b : bool, unkeyed b = false
end *
match u with
| BRight b => (x <= b) * (b < x = false)
| BLeft b => (x <= b) * (x < b) * (b <= x = false) * (b < x = false)
| +oo => forall x : T, x == x
| -oo => forall b : bool, unkeyed b = false
end *
match l, u with
| BLeft a, BRight b =>
(a <= b) * (b < a = false) * (a \in `[a, b]) * (b \in `[a, b])
| BLeft a, BLeft b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| BRight a, BRight b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| BRight a, BLeft b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[) * (b \in `[a, b]) * (b \in `]a, b])
| _, _ => forall x : T, x == x
end)%type.
Lemma itvP x i : x \in i -> itv_rewrite i x.
Proof.
case: i => [[[]a|[]][[]b|[]]] /andP [] ha hb; rewrite /= ?bound_in_itv;
do ![split | apply/negbTE; rewrite (le_gtF, lt_geF)];
by [|apply: ltW | move: (lteif_trans ha hb) => //=; exact: ltW].
Qed.
Arguments itvP [x i].
Lemma itv_splitU1 b x : b <= BLeft x ->
Interval b (BRight x) =i [predU1 x & Interval b (BLeft x)].
Proof.
move=> bx z; rewrite !inE/= !subitvE ?bnd_simp//= lt_neqAle.
by case: (eqVneq z x) => [->|]//=; rewrite lexx bx.
Qed.
Lemma itv_split1U b x : BRight x <= b ->
Interval (BLeft x) b =i [predU1 x & Interval (BRight x) b].
Proof.
move=> bx z; rewrite !inE/= !subitvE ?bnd_simp//= lt_neqAle.
by case: (eqVneq z x) => [->|]//=; rewrite lexx bx.
Qed.
End IntervalPOrder.
Section IntervalLattice.
Variable (disp : Order.disp_t) (T : latticeType disp).
Implicit Types (x y z : T) (b bl br : itv_bound T) (i : interval T).
Definition bound_meet bl br : itv_bound T :=
match bl, br with
| -oo, _ | _, -oo => -oo
| +oo, b | b, +oo => b
| BSide xb x, BSide yb y =>
BSide (((x <= y) && xb) || ((y <= x) && yb)) (x `&` y)
end.
Definition bound_join bl br : itv_bound T :=
match bl, br with
| -oo, b | b, -oo => b
| +oo, _ | _, +oo => +oo
| BSide xb x, BSide yb y =>
BSide ((~~ (x <= y) || yb) && (~~ (y <= x) || xb)) (x `|` y)
end.
Lemma bound_meetC : commutative bound_meet.
Proof.
case=> [? ?|[]][? ?|[]] //=; rewrite meetC; congr BSide.
by case: lcomparableP; rewrite ?orbF // orbC.
Qed.
Lemma bound_joinC : commutative bound_join.
Proof.
case=> [? ?|[]][? ?|[]] //=; rewrite joinC; congr BSide.
by case: lcomparableP; rewrite ?andbT // andbC.
Qed.
Lemma bound_meetA : associative bound_meet.
Proof.
case=> [? x|[]][? y|[]][? z|[]] //=; rewrite !lexI meetA; congr BSide.
by case: (lcomparableP x y) => [|||->]; case: (lcomparableP y z) => [|||->];
case: (lcomparableP x z) => [|||//<-]; case: (lcomparableP x y);
rewrite //= ?andbF ?orbF ?lexx ?orbA //; case: (lcomparableP y z).
Qed.
Lemma bound_joinA : associative bound_join.
Proof.
case=> [? x|[]][? y|[]][? z|[]] //=; rewrite !leUx joinA; congr BSide.
by case: (lcomparableP x y) => [|||->]; case: (lcomparableP y z) => [|||->];
case: (lcomparableP x z) => [|||//<-]; case: (lcomparableP x y);
rewrite //= ?orbT ?andbT ?lexx ?andbA //; case: (lcomparableP y z).
Qed.
Lemma bound_meetKU b2 b1 : bound_join b1 (bound_meet b1 b2) = b1.
Proof.
case: b1 b2 => [? ?|[]][? ?|[]] //=;
rewrite ?meetKU ?joinxx ?leIl ?lexI ?lexx ?andbb //=; congr BSide.
by case: lcomparableP; rewrite ?orbF /= ?andbb ?orbK.
Qed.
Lemma bound_joinKI b2 b1 : bound_meet b1 (bound_join b1 b2) = b1.
Proof.
case: b1 b2 => [? ?|[]][? ?|[]] //=;
rewrite ?joinKI ?meetxx ?leUl ?leUx ?lexx ?orbb //=; congr BSide.
by case: lcomparableP; rewrite ?orbF ?orbb ?andKb.
Qed.
Lemma bound_leEmeet b1 b2 : (b1 <= b2) = (bound_meet b1 b2 == b1).
Proof.
case: b1 b2 => [[]t[][]|[][][]] //=; rewrite ?eqxx// => t';
rewrite [LHS]/<=%O /eq_op ?andbT ?andbF ?orbF/= /eq_op/= /eq_op/=;
case: lcomparableP => //=; rewrite ?eqxx//=; [| | |].
- by move/lt_eqF.
- move=> ic; apply: esym; apply: contraNF ic.
by move=> /eqP/meet_idPl; apply: le_comparable.
- by move/lt_eqF.
- move=> ic; apply: esym; apply: contraNF ic.
by move=> /eqP/meet_idPl; apply: le_comparable.
Qed.
HB.instance Definition _ :=
Order.POrder_isLattice.Build (itv_bound_display disp) (itv_bound T)
bound_meetC bound_joinC bound_meetA bound_joinA
bound_joinKI bound_meetKU bound_leEmeet.
Lemma bound_le0x b : -oo <= b. Proof. by []. Qed.
Lemma bound_lex1 b : b <= +oo. Proof. by case: b => [|[]]. Qed.
HB.instance Definition _ :=
Order.hasBottom.Build (itv_bound_display disp) (itv_bound T) bound_le0x.
HB.instance Definition _ :=
Order.hasTop.Build (itv_bound_display disp) (itv_bound T) bound_lex1.
Definition itv_meet i1 i2 : interval T :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in Interval (b1l `|` b2l) (b1r `&` b2r).
Definition itv_join i1 i2 : interval T :=
let: Interval b1l b1r := i1 in
let: Interval b2l b2r := i2 in Interval (b1l `&` b2l) (b1r `|` b2r).
Lemma itv_meetC : commutative itv_meet.
Proof. by case=> [? ?][? ?] /=; rewrite meetC joinC. Qed.
Lemma itv_joinC : commutative itv_join.
Proof. by case=> [? ?][? ?] /=; rewrite meetC joinC. Qed.
Lemma itv_meetA : associative itv_meet.
Proof. by case=> [? ?][? ?][? ?] /=; rewrite meetA joinA. Qed.
Lemma itv_joinA : associative itv_join.
Proof. by case=> [? ?][? ?][? ?] /=; rewrite meetA joinA. Qed.
Lemma itv_meetKU i2 i1 : itv_join i1 (itv_meet i1 i2) = i1.
Proof. by case: i1 i2 => [? ?][? ?] /=; rewrite meetKU joinKI. Qed.
Lemma itv_joinKI i2 i1 : itv_meet i1 (itv_join i1 i2) = i1.
Proof. by case: i1 i2 => [? ?][? ?] /=; rewrite meetKU joinKI. Qed.
Lemma itv_leEmeet i1 i2 : (i1 <= i2) = (itv_meet i1 i2 == i1).
Proof.
by case: i1 i2 => [? ?] [? ?]; rewrite /eq_op/=/eq_op/= eq_meetl eq_joinl.
Qed.
HB.instance Definition _ :=
Order.POrder_isLattice.Build (interval_display disp) (interval T)
itv_meetC itv_joinC itv_meetA itv_joinA
itv_joinKI itv_meetKU itv_leEmeet.
Lemma itv_le0x i : Interval +oo -oo <= i. Proof. by case: i => [[|[]]]. Qed.
Lemma itv_lex1 i : i <= `]-oo, +oo[. Proof. by case: i => [?[|[]]]. Qed.
HB.instance Definition _ :=
Order.hasBottom.Build (interval_display disp) (interval T) itv_le0x.
HB.instance Definition _ :=
Order.hasTop.Build (interval_display disp) (interval T) itv_lex1.
Lemma in_itvI x i1 i2 : x \in i1 `&` i2 = (x \in i1) && (x \in i2).
Proof. exact: lexI. Qed.
End IntervalLattice.
Section IntervalTotal.
Variable (disp : Order.disp_t) (T : orderType disp).
Implicit Types (a b c : itv_bound T) (x y z : T) (i : interval T).
Lemma BSide_min s (x y : T) :
BSide s (Order.min x y) = Order.min (BSide s x) (BSide s y).
Proof. exact: comparable_BSide_min. Qed.
Lemma BSide_max s (x y : T) :
BSide s (Order.max x y) = Order.max (BSide s x) (BSide s y).
Proof. exact: comparable_BSide_max. Qed.
Lemma itv_bound_total : total (<=%O : rel (itv_bound T)).
Proof. by move=> [[]?|[]][[]?|[]]; rewrite /<=%O //=; case: ltgtP. Qed.
HB.instance Definition _ :=
Order.Lattice_isTotal.Build
(itv_bound_display disp) (itv_bound T) itv_bound_total.
Lemma itv_meetUl : @left_distributive (interval T) _ Order.meet Order.join.
Proof.
by move=> [? ?][? ?][? ?]; rewrite /Order.meet /Order.join /= -meetUl -joinIl.
Qed.
HB.instance Definition _ :=
Order.Lattice_Meet_isDistrLattice.Build
(interval_display disp) (interval T) itv_meetUl.
Lemma itv_splitU c a b : a <= c <= b ->
forall y, y \in Interval a b = (y \in Interval a c) || (y \in Interval c b).
Proof.
case/andP => leac lecb y.
rewrite !itv_boundlr !(ltNge (BLeft y) _ : (BRight y <= _) = _).
case: (leP a) (leP b) (leP c) => leay [] leby [] lecy //=.
- by case: leP lecy (le_trans lecb leby).
- by case: leP leay (le_trans leac lecy).
Qed.
Lemma itv_splitUeq x a b : x \in Interval a b ->
forall y, y \in Interval a b =
[|| y \in Interval a (BLeft x), y == x | y \in Interval (BRight x) b].
Proof.
case/andP => ax xb y; rewrite (@itv_splitU (BLeft x)) ?ax ?ltW //.
by congr orb; rewrite (@itv_splitU (BRight x)) ?bound_lexx // itv_xx.
Qed.
Lemma itv_total_meet3E i1 i2 i3 :
i1 `&` i2 `&` i3 \in [:: i1 `&` i2; i1 `&` i3; i2 `&` i3].
Proof.
case: i1 i2 i3 => [b1l b1r] [b2l b2r] [b3l b3r]; rewrite !inE /eq_op /=.
case: (leP b1l b2l); case: (leP b1l b3l); case: (leP b2l b3l);
case: (leP b1r b2r); case: (leP b1r b3r); case: (leP b2r b3r);
rewrite ?eqxx ?orbT //= => b23r b13r b12r b23l b13l b12l.
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13r (lt_trans b23r b12r).
Qed.
Lemma itv_total_join3E i1 i2 i3 :
i1 `|` i2 `|` i3 \in [:: i1 `|` i2; i1 `|` i3; i2 `|` i3].
Proof.
case: i1 i2 i3 => [b1l b1r] [b2l b2r] [b3l b3r]; rewrite !inE /eq_op /=.
case: (leP b1l b2l); case: (leP b1l b3l); case: (leP b2l b3l);
case: (leP b1r b2r); case: (leP b1r b3r); case: (leP b2r b3r);
rewrite ?eqxx ?orbT //= => b23r b13r b12r b23l b13l b12l.
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13r (le_trans b12r b23r).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13l (le_trans b12l b23l).
- by case: leP b13r (lt_trans b23r b12r).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13l (lt_trans b23l b12l).
- by case: leP b13r (lt_trans b23r b12r).
Qed.
Lemma predC_itvl a : [predC Interval -oo a] =i Interval a +oo.
Proof.
case: a => [b x|[]//] y.
by rewrite !inE !subitvE/= bnd_simp andbT !lteBSide/= lteifNE negbK.
Qed.
Lemma predC_itvr a : [predC Interval a +oo] =i Interval -oo a.
Proof. by move=> y; rewrite inE/= -predC_itvl negbK. Qed.
Lemma predC_itv i : [predC i] =i [predU Interval -oo i.1 & Interval i.2 +oo].
Proof.
case: i => [a a']; move=> x; rewrite inE/= itv_splitI negb_and.
by symmetry; rewrite inE/= -predC_itvl -predC_itvr.
Qed.
End IntervalTotal.
Local Open Scope ring_scope.
Import GRing.Theory Num.Theory.
Section IntervalNumDomain.
Variable R : numDomainType.
Implicit Types x : R.
Lemma real_BSide_min b x y : x \in Num.real -> y \in Num.real ->
BSide b (Order.min x y) = Order.min (BSide b x) (BSide b y).
Proof. by move=> xr yr; apply/comparable_BSide_min/real_comparable. Qed.
Lemma real_BSide_max b x y : x \in Num.real -> y \in Num.real ->
BSide b (Order.max x y) = Order.max (BSide b x) (BSide b y).
Proof. by move=> xr yr; apply/comparable_BSide_max/real_comparable. Qed.
Lemma mem0_itvcc_xNx x : (0 \in `[- x, x]) = (0 <= x).
Proof. by rewrite itv_boundlr [in LHS]/<=%O /= oppr_le0 andbb. Qed.
Lemma mem0_itvoo_xNx x : 0 \in `]- x, x[ = (0 < x).
Proof. by rewrite itv_boundlr [in LHS]/<=%O /= oppr_lt0 andbb. Qed.
Lemma oppr_itv ba bb (xa xb x : R) :
(- x \in Interval (BSide ba xa) (BSide bb xb)) =
(x \in Interval (BSide (~~ bb) (- xb)) (BSide (~~ ba) (- xa))).
Proof.
by rewrite !itv_boundlr /<=%O /= !implybF negbK andbC lteifNl lteifNr.
Qed.
Lemma oppr_itvoo (a b x : R) : (- x \in `]a, b[) = (x \in `]- b, - a[).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvco (a b x : R) : (- x \in `[a, b[) = (x \in `]- b, - a]).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvoc (a b x : R) : (- x \in `]a, b]) = (x \in `[- b, - a[).
Proof. exact: oppr_itv. Qed.
Lemma oppr_itvcc (a b x : R) : (- x \in `[a, b]) = (x \in `[- b, - a]).
Proof. exact: oppr_itv. Qed.
Definition miditv (R : numDomainType) (i : interval R) : R :=
match i with
| Interval (BSide _ a) (BSide _ b) => (a + b) / 2%:R
| Interval -oo%O (BSide _ b) => b - 1
| Interval (BSide _ a) +oo%O => a + 1
| Interval -oo%O +oo%O => 0
| _ => 0
end.
End IntervalNumDomain.
Section IntervalField.
Variable R : numFieldType.
Implicit Types (x y z : R) (i : interval R).
Local Notation mid x y := ((x + y) / 2).
Lemma mid_in_itv : forall ba bb (xa xb : R), xa < xb ?<= if ba && ~~ bb ->
mid xa xb \in Interval (BSide ba xa) (BSide bb xb).
Proof.
by move=> [] [] xa xb /= ?; apply/itv_dec; rewrite /= ?midf_lte // ?ltW.
Qed.
Lemma mid_in_itvoo : forall (xa xb : R), xa < xb -> mid xa xb \in `]xa, xb[.
Proof. by move=> xa xb ?; apply: mid_in_itv. Qed.
Lemma mid_in_itvcc : forall (xa xb : R), xa <= xb -> mid xa xb \in `[xa, xb].
Proof. by move=> xa xb ?; apply: mid_in_itv. Qed.
Lemma mem_miditv i : (i.1 < i.2)%O -> miditv i \in i.
Proof.
move: i => [[ba a|[]] [bb b|[]]] //= ab; first exact: mid_in_itv.
by rewrite !in_itv -lteifBlDl subrr lteif01.
by rewrite !in_itv lteifBlDr -lteifBlDl subrr lteif01.
Qed.
Lemma miditv_le_left i b : (i.1 < i.2)%O -> (BSide b (miditv i) <= i.2)%O.
Proof.
case: i => [x y] lti; have := mem_miditv lti; rewrite inE => /andP[_ ].
by apply: le_trans; rewrite !bnd_simp.
Qed.
Lemma miditv_ge_right i b : (i.1 < i.2)%O -> (i.1 <= BSide b (miditv i))%O.
Proof.
case: i => [x y] lti; have := mem_miditv lti; rewrite inE => /andP[+ _].
by move=> /le_trans; apply; rewrite !bnd_simp.
Qed.
Lemma in_segmentDgt0Pr x y z :
reflect (forall e, e > 0 -> y \in `[x - e, z + e]) (y \in `[x, z]).
Proof.
apply/(iffP idP)=> [xyz e /[dup] e_gt0 /ltW e_ge0 | xyz_e].
by rewrite in_itv /= lerBDr !ler_wpDr// (itvP xyz).
by rewrite in_itv /= ; apply/andP; split; apply/ler_addgt0Pr => ? /xyz_e;
rewrite in_itv /= lerBDr => /andP [].
Qed.
Lemma in_segmentDgt0Pl x y z :
reflect (forall e, e > 0 -> y \in `[- e + x, e + z]) (y \in `[x, z]).
Proof.
apply/(equivP (in_segmentDgt0Pr x y z)).
by split=> zxy e /zxy; rewrite [z + _]addrC [_ + x]addrC.
Qed.
End IntervalField.
|
Basic.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, Kim Morrison
-/
import Mathlib.Algebra.BigOperators.Finsupp.Basic
import Mathlib.Algebra.BigOperators.Group.Finset.Preimage
import Mathlib.Algebra.Group.Indicator
import Mathlib.Data.Rat.BigOperators
/-!
# Miscellaneous definitions, lemmas, and constructions using finsupp
## Main declarations
* `Finsupp.graph`: the finset of input and output pairs with non-zero outputs.
* `Finsupp.mapRange.equiv`: `Finsupp.mapRange` as an equiv.
* `Finsupp.mapDomain`: maps the domain of a `Finsupp` by a function and by summing.
* `Finsupp.comapDomain`: postcomposition of a `Finsupp` with a function injective on the preimage
of its support.
* `Finsupp.filter`: `filter p f` is the finitely supported function that is `f a` if `p a` is true
and 0 otherwise.
* `Finsupp.frange`: the image of a finitely supported function on its support.
* `Finsupp.subtype_domain`: the restriction of a finitely supported function `f` to a subtype.
## Implementation notes
This file is a `noncomputable theory` and uses classical logic throughout.
## TODO
* Expand the list of definitions and important lemmas to the module docstring.
-/
noncomputable section
open Finset Function
variable {α β γ ι M M' N P G H R S : Type*}
namespace Finsupp
/-! ### Declarations about `graph` -/
section Graph
variable [Zero M]
/-- The graph of a finitely supported function over its support, i.e. the finset of input and output
pairs with non-zero outputs. -/
def graph (f : α →₀ M) : Finset (α × M) :=
f.support.map ⟨fun a => Prod.mk a (f a), fun _ _ h => (Prod.mk.inj h).1⟩
theorem mk_mem_graph_iff {a : α} {m : M} {f : α →₀ M} : (a, m) ∈ f.graph ↔ f a = m ∧ m ≠ 0 := by
simp_rw [graph, mem_map, mem_support_iff]
constructor
· rintro ⟨b, ha, rfl, -⟩
exact ⟨rfl, ha⟩
· rintro ⟨rfl, ha⟩
exact ⟨a, ha, rfl⟩
@[simp]
theorem mem_graph_iff {c : α × M} {f : α →₀ M} : c ∈ f.graph ↔ f c.1 = c.2 ∧ c.2 ≠ 0 := by
cases c
exact mk_mem_graph_iff
theorem mk_mem_graph (f : α →₀ M) {a : α} (ha : a ∈ f.support) : (a, f a) ∈ f.graph :=
mk_mem_graph_iff.2 ⟨rfl, mem_support_iff.1 ha⟩
theorem apply_eq_of_mem_graph {a : α} {m : M} {f : α →₀ M} (h : (a, m) ∈ f.graph) : f a = m :=
(mem_graph_iff.1 h).1
@[simp 1100] -- Higher priority shortcut instance for `mem_graph_iff`.
theorem notMem_graph_snd_zero (a : α) (f : α →₀ M) : (a, (0 : M)) ∉ f.graph := fun h =>
(mem_graph_iff.1 h).2.irrefl
@[deprecated (since := "2025-05-23")] alias not_mem_graph_snd_zero := notMem_graph_snd_zero
@[simp]
theorem image_fst_graph [DecidableEq α] (f : α →₀ M) : f.graph.image Prod.fst = f.support := by
classical
simp_rw [graph, map_eq_image, image_image, Embedding.coeFn_mk, Function.comp_def, image_id']
theorem graph_injective (α M) [Zero M] : Injective (@graph α M _) := by
intro f g h
classical
have hsup : f.support = g.support := by rw [← image_fst_graph, h, image_fst_graph]
refine ext_iff'.2 ⟨hsup, fun x hx => apply_eq_of_mem_graph <| h.symm ▸ ?_⟩
exact mk_mem_graph _ (hsup ▸ hx)
@[simp]
theorem graph_inj {f g : α →₀ M} : f.graph = g.graph ↔ f = g :=
(graph_injective α M).eq_iff
@[simp]
theorem graph_zero : graph (0 : α →₀ M) = ∅ := by simp [graph]
@[simp]
theorem graph_eq_empty {f : α →₀ M} : f.graph = ∅ ↔ f = 0 :=
(graph_injective α M).eq_iff' graph_zero
end Graph
end Finsupp
/-! ### Declarations about `mapRange` -/
section MapRange
namespace Finsupp
section Equiv
variable [Zero M] [Zero N] [Zero P]
/-- `Finsupp.mapRange` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M ≃ N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M) ≃ (α →₀ N) where
toFun := (mapRange f hf : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm hf' : (α →₀ N) → α →₀ M)
left_inv x := by
rw [← mapRange_comp] <;> simp_rw [Equiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv x := by
rw [← mapRange_comp] <;> simp_rw [Equiv.self_comp_symm]
· exact mapRange_id _
· rfl
@[simp]
theorem mapRange.equiv_refl : mapRange.equiv (Equiv.refl M) rfl rfl = Equiv.refl (α →₀ M) :=
Equiv.ext mapRange_id
theorem mapRange.equiv_trans (f : M ≃ N) (hf : f 0 = 0) (hf') (f₂ : N ≃ P) (hf₂ : f₂ 0 = 0) (hf₂') :
(mapRange.equiv (f.trans f₂) (by rw [Equiv.trans_apply, hf, hf₂])
(by rw [Equiv.symm_trans_apply, hf₂', hf']) :
(α →₀ _) ≃ _) =
(mapRange.equiv f hf hf').trans (mapRange.equiv f₂ hf₂ hf₂') :=
Equiv.ext <| mapRange_comp f₂ hf₂ f hf ((congrArg f₂ hf).trans hf₂)
@[simp]
theorem mapRange.equiv_symm (f : M ≃ N) (hf hf') :
((mapRange.equiv f hf hf').symm : (α →₀ _) ≃ _) = mapRange.equiv f.symm hf' hf :=
Equiv.ext fun _ => rfl
end Equiv
section ZeroHom
variable [Zero M] [Zero N] [Zero P]
/-- Composition with a fixed zero-preserving homomorphism is itself a zero-preserving homomorphism
on functions. -/
@[simps]
def mapRange.zeroHom (f : ZeroHom M N) : ZeroHom (α →₀ M) (α →₀ N) where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
@[simp]
theorem mapRange.zeroHom_id : mapRange.zeroHom (ZeroHom.id M) = ZeroHom.id (α →₀ M) :=
ZeroHom.ext mapRange_id
theorem mapRange.zeroHom_comp (f : ZeroHom N P) (f₂ : ZeroHom M N) :
(mapRange.zeroHom (f.comp f₂) : ZeroHom (α →₀ _) _) =
(mapRange.zeroHom f).comp (mapRange.zeroHom f₂) :=
ZeroHom.ext <| mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
end ZeroHom
section AddMonoidHom
variable [AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P]
variable {F : Type*} [FunLike F M N] [AddMonoidHomClass F M N]
/-- Composition with a fixed additive homomorphism is itself an additive homomorphism on functions.
-/
@[simps]
def mapRange.addMonoidHom (f : M →+ N) : (α →₀ M) →+ α →₀ N where
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
map_zero' := mapRange_zero
map_add' := mapRange_add f.map_add
@[simp]
theorem mapRange.addMonoidHom_id :
mapRange.addMonoidHom (AddMonoidHom.id M) = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext mapRange_id
theorem mapRange.addMonoidHom_comp (f : N →+ P) (f₂ : M →+ N) :
(mapRange.addMonoidHom (f.comp f₂) : (α →₀ _) →+ _) =
(mapRange.addMonoidHom f).comp (mapRange.addMonoidHom f₂) :=
AddMonoidHom.ext <|
mapRange_comp f (map_zero f) f₂ (map_zero f₂) (by simp only [comp_apply, map_zero])
@[simp]
theorem mapRange.addMonoidHom_toZeroHom (f : M →+ N) :
(mapRange.addMonoidHom f).toZeroHom = (mapRange.zeroHom f.toZeroHom : ZeroHom (α →₀ _) _) :=
ZeroHom.ext fun _ => rfl
theorem mapRange_multiset_sum (f : F) (m : Multiset (α →₀ M)) :
mapRange f (map_zero f) m.sum = (m.map fun x => mapRange f (map_zero f) x).sum :=
(mapRange.addMonoidHom (f : M →+ N) : (α →₀ _) →+ _).map_multiset_sum _
theorem mapRange_finset_sum (f : F) (s : Finset ι) (g : ι → α →₀ M) :
mapRange f (map_zero f) (∑ x ∈ s, g x) = ∑ x ∈ s, mapRange f (map_zero f) (g x) :=
map_sum (mapRange.addMonoidHom (f : M →+ N)) _ _
/-- `Finsupp.mapRange.AddMonoidHom` as an equiv. -/
@[simps apply]
def mapRange.addEquiv (f : M ≃+ N) : (α →₀ M) ≃+ (α →₀ N) :=
{ mapRange.addMonoidHom f.toAddMonoidHom with
toFun := (mapRange f f.map_zero : (α →₀ M) → α →₀ N)
invFun := (mapRange f.symm f.symm.map_zero : (α →₀ N) → α →₀ M)
left_inv := fun x => by
rw [← mapRange_comp] <;> simp_rw [AddEquiv.symm_comp_self]
· exact mapRange_id _
· rfl
right_inv := fun x => by
rw [← mapRange_comp] <;> simp_rw [AddEquiv.self_comp_symm]
· exact mapRange_id _
· rfl }
@[simp]
theorem mapRange.addEquiv_refl : mapRange.addEquiv (AddEquiv.refl M) = AddEquiv.refl (α →₀ M) :=
AddEquiv.ext mapRange_id
theorem mapRange.addEquiv_trans (f : M ≃+ N) (f₂ : N ≃+ P) :
(mapRange.addEquiv (f.trans f₂) : (α →₀ M) ≃+ (α →₀ P)) =
(mapRange.addEquiv f).trans (mapRange.addEquiv f₂) :=
AddEquiv.ext (mapRange_comp _ f₂.map_zero _ f.map_zero (by simp))
@[simp]
theorem mapRange.addEquiv_symm (f : M ≃+ N) :
((mapRange.addEquiv f).symm : (α →₀ _) ≃+ _) = mapRange.addEquiv f.symm :=
AddEquiv.ext fun _ => rfl
@[simp]
theorem mapRange.addEquiv_toAddMonoidHom (f : M ≃+ N) :
((mapRange.addEquiv f : (α →₀ _) ≃+ _) : _ →+ _) =
(mapRange.addMonoidHom f.toAddMonoidHom : (α →₀ _) →+ _) :=
AddMonoidHom.ext fun _ => rfl
@[simp]
theorem mapRange.addEquiv_toEquiv (f : M ≃+ N) :
↑(mapRange.addEquiv f : (α →₀ _) ≃+ _) =
(mapRange.equiv (f : M ≃ N) f.map_zero f.symm.map_zero : (α →₀ _) ≃ _) :=
Equiv.ext fun _ => rfl
end AddMonoidHom
end Finsupp
end MapRange
/-! ### Declarations about `equivCongrLeft` -/
section EquivCongrLeft
variable [Zero M]
namespace Finsupp
/-- Given `f : α ≃ β`, we can map `l : α →₀ M` to `equivMapDomain f l : β →₀ M` (computably)
by mapping the support forwards and the function backwards. -/
def equivMapDomain (f : α ≃ β) (l : α →₀ M) : β →₀ M where
support := l.support.map f.toEmbedding
toFun a := l (f.symm a)
mem_support_toFun a := by simp only [Finset.mem_map_equiv, mem_support_toFun]; rfl
@[simp]
theorem equivMapDomain_apply (f : α ≃ β) (l : α →₀ M) (b : β) :
equivMapDomain f l b = l (f.symm b) :=
rfl
theorem equivMapDomain_symm_apply (f : α ≃ β) (l : β →₀ M) (a : α) :
equivMapDomain f.symm l a = l (f a) :=
rfl
@[simp]
theorem equivMapDomain_refl (l : α →₀ M) : equivMapDomain (Equiv.refl _) l = l := by ext x; rfl
theorem equivMapDomain_refl' : equivMapDomain (Equiv.refl _) = @id (α →₀ M) := by ext x; rfl
theorem equivMapDomain_trans (f : α ≃ β) (g : β ≃ γ) (l : α →₀ M) :
equivMapDomain (f.trans g) l = equivMapDomain g (equivMapDomain f l) := by ext x; rfl
theorem equivMapDomain_trans' (f : α ≃ β) (g : β ≃ γ) :
@equivMapDomain _ _ M _ (f.trans g) = equivMapDomain g ∘ equivMapDomain f := by ext x; rfl
@[simp]
theorem equivMapDomain_single (f : α ≃ β) (a : α) (b : M) :
equivMapDomain f (single a b) = single (f a) b := by
classical
ext x
simp only [single_apply, Equiv.apply_eq_iff_eq_symm_apply, equivMapDomain_apply]
@[simp]
theorem equivMapDomain_zero {f : α ≃ β} : equivMapDomain f (0 : α →₀ M) = (0 : β →₀ M) := by
ext; simp only [equivMapDomain_apply, coe_zero, Pi.zero_apply]
@[to_additive (attr := simp)]
theorem prod_equivMapDomain [CommMonoid N] (f : α ≃ β) (l : α →₀ M) (g : β → M → N) :
prod (equivMapDomain f l) g = prod l (fun a m => g (f a) m) := by
simp [prod, equivMapDomain]
/-- Given `f : α ≃ β`, the finitely supported function spaces are also in bijection:
`(α →₀ M) ≃ (β →₀ M)`.
This is the finitely-supported version of `Equiv.piCongrLeft`. -/
def equivCongrLeft (f : α ≃ β) : (α →₀ M) ≃ (β →₀ M) := by
refine ⟨equivMapDomain f, equivMapDomain f.symm, fun f => ?_, fun f => ?_⟩ <;> ext x <;>
simp only [equivMapDomain_apply, Equiv.symm_symm, Equiv.symm_apply_apply,
Equiv.apply_symm_apply]
@[simp]
theorem equivCongrLeft_apply (f : α ≃ β) (l : α →₀ M) : equivCongrLeft f l = equivMapDomain f l :=
rfl
@[simp]
theorem equivCongrLeft_symm (f : α ≃ β) :
(@equivCongrLeft _ _ M _ f).symm = equivCongrLeft f.symm :=
rfl
end Finsupp
end EquivCongrLeft
section CastFinsupp
variable [Zero M] (f : α →₀ M)
namespace Nat
@[simp, norm_cast]
theorem cast_finsuppProd [CommSemiring R] (g : α → M → ℕ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Nat.cast_prod _ _
@[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd
@[simp, norm_cast]
theorem cast_finsupp_sum [AddCommMonoidWithOne R] (g : α → M → ℕ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Nat.cast_sum _ _
end Nat
namespace Int
@[simp, norm_cast]
theorem cast_finsuppProd [CommRing R] (g : α → M → ℤ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
Int.cast_prod _ _
@[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd
@[simp, norm_cast]
theorem cast_finsupp_sum [AddCommGroupWithOne R] (g : α → M → ℤ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
Int.cast_sum _ _
end Int
namespace Rat
@[simp, norm_cast]
theorem cast_finsupp_sum [DivisionRing R] [CharZero R] (g : α → M → ℚ) :
(↑(f.sum g) : R) = f.sum fun a b => ↑(g a b) :=
cast_sum _ _
@[simp, norm_cast]
theorem cast_finsuppProd [Field R] [CharZero R] (g : α → M → ℚ) :
(↑(f.prod g) : R) = f.prod fun a b => ↑(g a b) :=
cast_prod _ _
@[deprecated (since := "2025-04-06")] alias cast_finsupp_prod := cast_finsuppProd
end Rat
end CastFinsupp
/-! ### Declarations about `mapDomain` -/
namespace Finsupp
section MapDomain
variable [AddCommMonoid M] {v v₁ v₂ : α →₀ M}
/-- Given `f : α → β` and `v : α →₀ M`, `mapDomain f v : β →₀ M`
is the finitely supported function whose value at `a : β` is the sum
of `v x` over all `x` such that `f x = a`. -/
def mapDomain (f : α → β) (v : α →₀ M) : β →₀ M :=
v.sum fun a => single (f a)
theorem mapDomain_apply {f : α → β} (hf : Function.Injective f) (x : α →₀ M) (a : α) :
mapDomain f x (f a) = x a := by
rw [mapDomain, sum_apply, sum_eq_single a, single_eq_same]
· intro b _ hba
exact single_eq_of_ne (hf.ne hba)
· intro _
rw [single_zero, coe_zero, Pi.zero_apply]
theorem mapDomain_notin_range {f : α → β} (x : α →₀ M) (a : β) (h : a ∉ Set.range f) :
mapDomain f x a = 0 := by
rw [mapDomain, sum_apply, sum]
exact Finset.sum_eq_zero fun a' _ => single_eq_of_ne fun eq => h <| eq ▸ Set.mem_range_self _
@[simp]
theorem mapDomain_id : mapDomain id v = v :=
sum_single _
theorem mapDomain_comp {f : α → β} {g : β → γ} :
mapDomain (g ∘ f) v = mapDomain g (mapDomain f v) := by
refine ((sum_sum_index ?_ ?_).trans ?_).symm
· intro
exact single_zero _
· intro
exact single_add _
refine sum_congr fun _ _ => sum_single_index ?_
exact single_zero _
@[simp]
theorem mapDomain_single {f : α → β} {a : α} {b : M} : mapDomain f (single a b) = single (f a) b :=
sum_single_index <| single_zero _
@[simp]
theorem mapDomain_zero {f : α → β} : mapDomain f (0 : α →₀ M) = (0 : β →₀ M) :=
sum_zero_index
theorem mapDomain_congr {f g : α → β} (h : ∀ x ∈ v.support, f x = g x) :
v.mapDomain f = v.mapDomain g :=
Finset.sum_congr rfl fun _ H => by simp only [h _ H]
theorem mapDomain_add {f : α → β} : mapDomain f (v₁ + v₂) = mapDomain f v₁ + mapDomain f v₂ :=
sum_add_index' (fun _ => single_zero _) fun _ => single_add _
@[simp]
theorem mapDomain_equiv_apply {f : α ≃ β} (x : α →₀ M) (a : β) :
mapDomain f x a = x (f.symm a) := by
conv_lhs => rw [← f.apply_symm_apply a]
exact mapDomain_apply f.injective _ _
/-- `Finsupp.mapDomain` is an `AddMonoidHom`. -/
@[simps]
def mapDomain.addMonoidHom (f : α → β) : (α →₀ M) →+ β →₀ M where
toFun := mapDomain f
map_zero' := mapDomain_zero
map_add' _ _ := mapDomain_add
@[simp]
theorem mapDomain.addMonoidHom_id : mapDomain.addMonoidHom id = AddMonoidHom.id (α →₀ M) :=
AddMonoidHom.ext fun _ => mapDomain_id
theorem mapDomain.addMonoidHom_comp (f : β → γ) (g : α → β) :
(mapDomain.addMonoidHom (f ∘ g) : (α →₀ M) →+ γ →₀ M) =
(mapDomain.addMonoidHom f).comp (mapDomain.addMonoidHom g) :=
AddMonoidHom.ext fun _ => mapDomain_comp
theorem mapDomain_finset_sum {f : α → β} {s : Finset ι} {v : ι → α →₀ M} :
mapDomain f (∑ i ∈ s, v i) = ∑ i ∈ s, mapDomain f (v i) :=
map_sum (mapDomain.addMonoidHom f) _ _
theorem mapDomain_sum [Zero N] {f : α → β} {s : α →₀ N} {v : α → N → α →₀ M} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
map_finsuppSum (mapDomain.addMonoidHom f : (α →₀ M) →+ β →₀ M) _ _
theorem mapDomain_support [DecidableEq β] {f : α → β} {s : α →₀ M} :
(s.mapDomain f).support ⊆ s.support.image f :=
Finset.Subset.trans support_sum <|
Finset.Subset.trans (Finset.biUnion_mono fun _ _ => support_single_subset) <| by
rw [Finset.biUnion_singleton]
theorem mapDomain_apply' (S : Set α) {f : α → β} (x : α →₀ M) (hS : (x.support : Set α) ⊆ S)
(hf : Set.InjOn f S) {a : α} (ha : a ∈ S) : mapDomain f x (f a) = x a := by
classical
rw [mapDomain, sum_apply, sum]
simp_rw [single_apply]
by_cases hax : a ∈ x.support
· rw [← Finset.add_sum_erase _ _ hax, if_pos rfl]
convert add_zero (x a)
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact (hf.mono hS).ne (Finset.mem_of_mem_erase hi) hax (Finset.ne_of_mem_erase hi)
· rw [notMem_support_iff.1 hax]
refine Finset.sum_eq_zero fun i hi => if_neg ?_
exact hf.ne (hS hi) ha (ne_of_mem_of_not_mem hi hax)
theorem mapDomain_support_of_injOn [DecidableEq β] {f : α → β} (s : α →₀ M)
(hf : Set.InjOn f s.support) : (mapDomain f s).support = Finset.image f s.support :=
Finset.Subset.antisymm mapDomain_support <| by
intro x hx
simp only [mem_image, mem_support_iff, Ne] at hx
rcases hx with ⟨hx_w, hx_h_left, rfl⟩
simp only [mem_support_iff, Ne]
rw [mapDomain_apply' (↑s.support : Set _) _ _ hf]
· exact hx_h_left
· simp_rw [mem_coe, mem_support_iff, Ne]
exact hx_h_left
· exact Subset.refl _
theorem mapDomain_support_of_injective [DecidableEq β] {f : α → β} (hf : Function.Injective f)
(s : α →₀ M) : (mapDomain f s).support = Finset.image f s.support :=
mapDomain_support_of_injOn s hf.injOn
@[to_additive]
theorem prod_mapDomain_index [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(h_zero : ∀ b, h b 0 = 1) (h_add : ∀ b m₁ m₂, h b (m₁ + m₂) = h b m₁ * h b m₂) :
(mapDomain f s).prod h = s.prod fun a m => h (f a) m :=
(prod_sum_index h_zero h_add).trans <| prod_congr fun _ _ => prod_single_index (h_zero _)
-- Note that in `prod_mapDomain_index`, `M` is still an additive monoid,
-- so there is no analogous version in terms of `MonoidHom`.
/-- A version of `sum_mapDomain_index` that takes a bundled `AddMonoidHom`,
rather than separate linearity hypotheses.
-/
@[simp]
theorem sum_mapDomain_index_addMonoidHom [AddCommMonoid N] {f : α → β} {s : α →₀ M}
(h : β → M →+ N) : ((mapDomain f s).sum fun b m => h b m) = s.sum fun a m => h (f a) m :=
sum_mapDomain_index (fun b => (h b).map_zero) (fun b _ _ => (h b).map_add _ _)
theorem embDomain_eq_mapDomain (f : α ↪ β) (v : α →₀ M) : embDomain f v = mapDomain f v := by
ext a
by_cases h : a ∈ Set.range f
· rcases h with ⟨a, rfl⟩
rw [mapDomain_apply f.injective, embDomain_apply]
· rw [mapDomain_notin_range, embDomain_notin_range] <;> assumption
@[to_additive]
theorem prod_mapDomain_index_inj [CommMonoid N] {f : α → β} {s : α →₀ M} {h : β → M → N}
(hf : Function.Injective f) : (s.mapDomain f).prod h = s.prod fun a b => h (f a) b := by
rw [← Function.Embedding.coeFn_mk f hf, ← embDomain_eq_mapDomain, prod_embDomain]
theorem mapDomain_injective {f : α → β} (hf : Function.Injective f) :
Function.Injective (mapDomain f : (α →₀ M) → β →₀ M) := by
intro v₁ v₂ eq
ext a
have : mapDomain f v₁ (f a) = mapDomain f v₂ (f a) := by rw [eq]
rwa [mapDomain_apply hf, mapDomain_apply hf] at this
theorem mapDomain_surjective {f : α → β} (hf : f.Surjective) :
(mapDomain (M := M) f).Surjective := by
intro x
use mapDomain (surjInv hf) x
rw [← mapDomain_comp, (rightInverse_surjInv hf).id, mapDomain_id]
/-- When `f` is an embedding we have an embedding `(α →₀ ℕ) ↪ (β →₀ ℕ)` given by `mapDomain`. -/
@[simps]
def mapDomainEmbedding {α β : Type*} (f : α ↪ β) : (α →₀ ℕ) ↪ β →₀ ℕ :=
⟨Finsupp.mapDomain f, Finsupp.mapDomain_injective f.injective⟩
theorem mapDomain.addMonoidHom_comp_mapRange [AddCommMonoid N] (f : α → β) (g : M →+ N) :
(mapDomain.addMonoidHom f).comp (mapRange.addMonoidHom g) =
(mapRange.addMonoidHom g).comp (mapDomain.addMonoidHom f) := by
ext
simp
/-- When `g` preserves addition, `mapRange` and `mapDomain` commute. -/
theorem mapDomain_mapRange [AddCommMonoid N] (f : α → β) (v : α →₀ M) (g : M → N) (h0 : g 0 = 0)
(hadd : ∀ x y, g (x + y) = g x + g y) :
mapDomain f (mapRange g h0 v) = mapRange g h0 (mapDomain f v) :=
let g' : M →+ N :=
{ toFun := g
map_zero' := h0
map_add' := hadd }
DFunLike.congr_fun (mapDomain.addMonoidHom_comp_mapRange f g') v
theorem sum_update_add [AddZeroClass α] [AddCommMonoid β] (f : ι →₀ α) (i : ι) (a : α)
(g : ι → α → β) (hg : ∀ i, g i 0 = 0)
(hgg : ∀ (j : ι) (a₁ a₂ : α), g j (a₁ + a₂) = g j a₁ + g j a₂) :
(f.update i a).sum g + g i (f i) = f.sum g + g i a := by
rw [update_eq_erase_add_single, sum_add_index' hg hgg]
conv_rhs => rw [← Finsupp.update_self f i]
rw [update_eq_erase_add_single, sum_add_index' hg hgg, add_assoc, add_assoc]
congr 1
rw [add_comm, sum_single_index (hg _), sum_single_index (hg _)]
theorem mapDomain_injOn (S : Set α) {f : α → β} (hf : Set.InjOn f S) :
Set.InjOn (mapDomain f : (α →₀ M) → β →₀ M) { w | (w.support : Set α) ⊆ S } := by
intro v₁ hv₁ v₂ hv₂ eq
ext a
classical
by_cases h : a ∈ v₁.support ∪ v₂.support
· rw [← mapDomain_apply' S _ hv₁ hf _, ← mapDomain_apply' S _ hv₂ hf _, eq] <;>
· apply Set.union_subset hv₁ hv₂
exact mod_cast h
· simp_all
theorem equivMapDomain_eq_mapDomain {M} [AddCommMonoid M] (f : α ≃ β) (l : α →₀ M) :
equivMapDomain f l = mapDomain f l := by ext x; simp
end MapDomain
/-! ### Declarations about `comapDomain` -/
section ComapDomain
/-- Given `f : α → β`, `l : β →₀ M` and a proof `hf` that `f` is injective on
the preimage of `l.support`, `comapDomain f l hf` is the finitely supported function
from `α` to `M` given by composing `l` with `f`. -/
@[simps support]
def comapDomain [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support)) :
α →₀ M where
support := l.support.preimage f hf
toFun a := l (f a)
mem_support_toFun := by
intro a
rw [Finset.mem_preimage]
exact l.mem_support_toFun (f a)
@[simp]
theorem comapDomain_apply [Zero M] (f : α → β) (l : β →₀ M) (hf : Set.InjOn f (f ⁻¹' ↑l.support))
(a : α) : comapDomain f l hf a = l (f a) :=
rfl
theorem sum_comapDomain [Zero M] [AddCommMonoid N] (f : α → β) (l : β →₀ M) (g : β → M → N)
(hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) :
(comapDomain f l hf.injOn).sum (g ∘ f) = l.sum g :=
Finset.sum_preimage_of_bij f _ hf fun x => g x (l x)
theorem eq_zero_of_comapDomain_eq_zero [Zero M] (f : α → β) (l : β →₀ M)
(hf : Set.BijOn f (f ⁻¹' ↑l.support) ↑l.support) : comapDomain f l hf.injOn = 0 → l = 0 := by
rw [← support_eq_empty, ← support_eq_empty, comapDomain]
simp_rw [Finset.ext_iff, Finset.notMem_empty, iff_false, mem_preimage]
intro h a ha
obtain ⟨b, hb⟩ := hf.2.2 ha
exact h b (hb.2.symm ▸ ha)
section FInjective
section Zero
variable [Zero M]
lemma embDomain_comapDomain {f : α ↪ β} {g : β →₀ M} (hg : ↑g.support ⊆ Set.range f) :
embDomain f (comapDomain f g f.injective.injOn) = g := by
ext b
by_cases hb : b ∈ Set.range f
· obtain ⟨a, rfl⟩ := hb
rw [embDomain_apply, comapDomain_apply]
· replace hg : g b = 0 := notMem_support_iff.mp <| mt (hg ·) hb
rw [embDomain_notin_range _ _ _ hb, hg]
/-- Note the `hif` argument is needed for this to work in `rw`. -/
@[simp]
theorem comapDomain_zero (f : α → β)
(hif : Set.InjOn f (f ⁻¹' ↑(0 : β →₀ M).support) := Finset.coe_empty ▸ (Set.injOn_empty f)) :
comapDomain f (0 : β →₀ M) hif = (0 : α →₀ M) := by
ext
rfl
@[simp]
theorem comapDomain_single (f : α → β) (a : α) (m : M)
(hif : Set.InjOn f (f ⁻¹' (single (f a) m).support)) :
comapDomain f (Finsupp.single (f a) m) hif = Finsupp.single a m := by
rcases eq_or_ne m 0 with (rfl | hm)
· simp_rw [single_zero, comapDomain_zero]
· rw [eq_single_iff, comapDomain_apply, comapDomain_support, ← Finset.coe_subset, coe_preimage,
support_single_ne_zero _ hm, coe_singleton, coe_singleton, single_eq_same]
rw [support_single_ne_zero _ hm, coe_singleton] at hif
exact ⟨fun x hx => hif hx rfl hx, rfl⟩
end Zero
section AddZeroClass
variable [AddZeroClass M] {f : α → β}
theorem comapDomain_add (v₁ v₂ : β →₀ M) (hv₁ : Set.InjOn f (f ⁻¹' ↑v₁.support))
(hv₂ : Set.InjOn f (f ⁻¹' ↑v₂.support)) (hv₁₂ : Set.InjOn f (f ⁻¹' ↑(v₁ + v₂).support)) :
comapDomain f (v₁ + v₂) hv₁₂ = comapDomain f v₁ hv₁ + comapDomain f v₂ hv₂ := by
ext
simp
/-- A version of `Finsupp.comapDomain_add` that's easier to use. -/
theorem comapDomain_add_of_injective (hf : Function.Injective f) (v₁ v₂ : β →₀ M) :
comapDomain f (v₁ + v₂) hf.injOn =
comapDomain f v₁ hf.injOn + comapDomain f v₂ hf.injOn :=
comapDomain_add ..
/-- `Finsupp.comapDomain` is an `AddMonoidHom`. -/
@[simps]
def comapDomain.addMonoidHom (hf : Function.Injective f) : (β →₀ M) →+ α →₀ M where
toFun x := comapDomain f x hf.injOn
map_zero' := comapDomain_zero f
map_add' := comapDomain_add_of_injective hf
end AddZeroClass
variable [AddCommMonoid M] (f : α → β)
theorem mapDomain_comapDomain (hf : Function.Injective f) (l : β →₀ M)
(hl : ↑l.support ⊆ Set.range f) :
mapDomain f (comapDomain f l hf.injOn) = l := by
conv_rhs => rw [← embDomain_comapDomain (f := ⟨f, hf⟩) hl (M := M), embDomain_eq_mapDomain]
rfl
theorem comapDomain_mapDomain (hf : Function.Injective f) (l : α →₀ M) :
comapDomain f (mapDomain f l) hf.injOn = l := by
ext; rw [comapDomain_apply, mapDomain_apply hf]
end FInjective
end ComapDomain
/-! ### Declarations about `Finsupp.filter` -/
section Filter
section Zero
variable [Zero M] (p : α → Prop) [DecidablePred p] (f : α →₀ M)
/--
`Finsupp.filter p f` is the finitely supported function that is `f a` if `p a` is true and `0`
otherwise. -/
def filter (p : α → Prop) [DecidablePred p] (f : α →₀ M) : α →₀ M where
toFun a := if p a then f a else 0
support := f.support.filter p
mem_support_toFun a := by
split_ifs with h <;>
· simp only [h, mem_filter, mem_support_iff]
tauto
theorem filter_apply (a : α) : f.filter p a = if p a then f a else 0 := rfl
theorem filter_eq_indicator : ⇑(f.filter p) = Set.indicator { x | p x } f := by
ext
simp [filter_apply, Set.indicator_apply]
theorem filter_eq_zero_iff : f.filter p = 0 ↔ ∀ x, p x → f x = 0 := by
simp [DFunLike.ext_iff, filter_eq_indicator]
theorem filter_eq_self_iff : f.filter p = f ↔ ∀ x, f x ≠ 0 → p x := by
simp only [DFunLike.ext_iff, filter_eq_indicator, Set.indicator_apply_eq_self, Set.mem_setOf_eq,
not_imp_comm]
@[simp]
theorem filter_apply_pos {a : α} (h : p a) : f.filter p a = f a := if_pos h
@[simp]
theorem filter_apply_neg {a : α} (h : ¬p a) : f.filter p a = 0 := if_neg h
@[simp]
theorem support_filter : (f.filter p).support = {x ∈ f.support | p x} := rfl
theorem filter_zero : (0 : α →₀ M).filter p = 0 := by
classical rw [← support_eq_empty, support_filter, support_zero, Finset.filter_empty]
@[simp]
theorem filter_single_of_pos {a : α} {b : M} (h : p a) : (single a b).filter p = single a b :=
(filter_eq_self_iff _ _).2 fun _ hx => (single_apply_ne_zero.1 hx).1.symm ▸ h
@[simp]
theorem filter_single_of_neg {a : α} {b : M} (h : ¬p a) : (single a b).filter p = 0 :=
(filter_eq_zero_iff _ _).2 fun _ hpx =>
single_apply_eq_zero.2 fun hxa => absurd hpx (hxa.symm ▸ h)
@[to_additive]
theorem prod_filter_index [CommMonoid N] (g : α → M → N) :
(f.filter p).prod g = ∏ x ∈ (f.filter p).support, g x (f x) := by
refine Finset.prod_congr rfl fun x hx => ?_
rw [support_filter, Finset.mem_filter] at hx
rw [filter_apply_pos _ _ hx.2]
@[to_additive (attr := simp)]
theorem prod_filter_mul_prod_filter_not [CommMonoid N] (g : α → M → N) :
(f.filter p).prod g * (f.filter fun a => ¬p a).prod g = f.prod g := by
simp_rw [prod_filter_index, support_filter, Finset.prod_filter_mul_prod_filter_not, Finsupp.prod]
@[to_additive (attr := simp)]
theorem prod_div_prod_filter [CommGroup G] (g : α → M → G) :
f.prod g / (f.filter p).prod g = (f.filter fun a => ¬p a).prod g :=
div_eq_of_eq_mul' (prod_filter_mul_prod_filter_not _ _ _).symm
end Zero
theorem filter_pos_add_filter_neg [AddZeroClass M] (f : α →₀ M) (p : α → Prop) [DecidablePred p] :
(f.filter p + f.filter fun a => ¬p a) = f :=
DFunLike.coe_injective <| by
simp only [coe_add, filter_eq_indicator]
exact Set.indicator_self_add_compl { x | p x } f
end Filter
/-! ### Declarations about `frange` -/
section Frange
variable [Zero M]
/-- `frange f` is the image of `f` on the support of `f`. -/
def frange (f : α →₀ M) : Finset M :=
haveI := Classical.decEq M
Finset.image f f.support
theorem mem_frange {f : α →₀ M} {y : M} : y ∈ f.frange ↔ y ≠ 0 ∧ ∃ x, f x = y := by
rw [frange, @Finset.mem_image _ _ (Classical.decEq _) _ f.support]
exact ⟨fun ⟨x, hx1, hx2⟩ => ⟨hx2 ▸ mem_support_iff.1 hx1, x, hx2⟩, fun ⟨hy, x, hx⟩ =>
⟨x, mem_support_iff.2 (hx.symm ▸ hy), hx⟩⟩
theorem zero_notMem_frange {f : α →₀ M} : (0 : M) ∉ f.frange := fun H => (mem_frange.1 H).1 rfl
@[deprecated (since := "2025-05-23")] alias zero_not_mem_frange := zero_notMem_frange
theorem frange_single {x : α} {y : M} : frange (single x y) ⊆ {y} := fun r hr =>
let ⟨t, ht1, ht2⟩ := mem_frange.1 hr
ht2 ▸ by
classical
rw [single_apply] at ht2 ⊢
split_ifs at ht2 ⊢
· exact Finset.mem_singleton_self _
· exact (t ht2.symm).elim
end Frange
/-! ### Declarations about `Finsupp.subtypeDomain` -/
section SubtypeDomain
section Zero
variable [Zero M] {p : α → Prop}
/--
`subtypeDomain p f` is the restriction of the finitely supported function `f` to subtype `p`. -/
def subtypeDomain (p : α → Prop) (f : α →₀ M) : Subtype p →₀ M where
support :=
haveI := Classical.decPred p
f.support.subtype p
toFun := f ∘ Subtype.val
mem_support_toFun a := by simp only [@mem_subtype _ _ (Classical.decPred p), mem_support_iff]; rfl
@[simp]
theorem support_subtypeDomain [D : DecidablePred p] {f : α →₀ M} :
(subtypeDomain p f).support = f.support.subtype p := by rw [Subsingleton.elim D] <;> rfl
@[simp]
theorem subtypeDomain_apply {a : Subtype p} {v : α →₀ M} : (subtypeDomain p v) a = v a.val :=
rfl
@[simp]
theorem subtypeDomain_zero : subtypeDomain p (0 : α →₀ M) = 0 :=
rfl
theorem subtypeDomain_eq_iff_forall {f g : α →₀ M} :
f.subtypeDomain p = g.subtypeDomain p ↔ ∀ x, p x → f x = g x := by
simp_rw [DFunLike.ext_iff, subtypeDomain_apply, Subtype.forall]
theorem subtypeDomain_eq_iff {f g : α →₀ M}
(hf : ∀ x ∈ f.support, p x) (hg : ∀ x ∈ g.support, p x) :
f.subtypeDomain p = g.subtypeDomain p ↔ f = g :=
subtypeDomain_eq_iff_forall.trans
⟨fun H ↦ Finsupp.ext fun _a ↦ (em _).elim (H _ <| hf _ ·) fun haf ↦ (em _).elim (H _ <| hg _ ·)
fun hag ↦ (notMem_support_iff.mp haf).trans (notMem_support_iff.mp hag).symm,
fun H _ _ ↦ congr($H _)⟩
theorem subtypeDomain_eq_zero_iff' {f : α →₀ M} : f.subtypeDomain p = 0 ↔ ∀ x, p x → f x = 0 :=
subtypeDomain_eq_iff_forall (g := 0)
theorem subtypeDomain_eq_zero_iff {f : α →₀ M} (hf : ∀ x ∈ f.support, p x) :
f.subtypeDomain p = 0 ↔ f = 0 :=
subtypeDomain_eq_iff (g := 0) hf (by simp)
@[to_additive]
theorem prod_subtypeDomain_index [CommMonoid N] {v : α →₀ M} {h : α → M → N}
(hp : ∀ x ∈ v.support, p x) : (v.subtypeDomain p).prod (fun a b ↦ h a b) = v.prod h := by
refine Finset.prod_bij (fun p _ ↦ p) ?_ ?_ ?_ ?_ <;> aesop
end Zero
section AddZeroClass
variable [AddZeroClass M] {p : α → Prop} {v v' : α →₀ M}
@[simp]
theorem subtypeDomain_add {v v' : α →₀ M} :
(v + v').subtypeDomain p = v.subtypeDomain p + v'.subtypeDomain p :=
ext fun _ => rfl
/-- `subtypeDomain` but as an `AddMonoidHom`. -/
def subtypeDomainAddMonoidHom : (α →₀ M) →+ Subtype p →₀ M where
toFun := subtypeDomain p
map_zero' := subtypeDomain_zero
map_add' _ _ := subtypeDomain_add
/-- `Finsupp.filter` as an `AddMonoidHom`. -/
def filterAddHom (p : α → Prop) [DecidablePred p] : (α →₀ M) →+ α →₀ M where
toFun := filter p
map_zero' := filter_zero p
map_add' f g := DFunLike.coe_injective <| by
simp_rw [coe_add, filter_eq_indicator]
exact Set.indicator_add { x | p x } f g
@[simp]
theorem filter_add [DecidablePred p] {v v' : α →₀ M} :
(v + v').filter p = v.filter p + v'.filter p :=
(filterAddHom p).map_add v v'
end AddZeroClass
section CommMonoid
variable [AddCommMonoid M] {p : α → Prop}
theorem subtypeDomain_sum {s : Finset ι} {h : ι → α →₀ M} :
(∑ c ∈ s, h c).subtypeDomain p = ∑ c ∈ s, (h c).subtypeDomain p :=
map_sum subtypeDomainAddMonoidHom _ s
theorem subtypeDomain_finsupp_sum [Zero N] {s : β →₀ N} {h : β → N → α →₀ M} :
(s.sum h).subtypeDomain p = s.sum fun c d => (h c d).subtypeDomain p :=
subtypeDomain_sum
theorem filter_sum [DecidablePred p] (s : Finset ι) (f : ι → α →₀ M) :
(∑ a ∈ s, f a).filter p = ∑ a ∈ s, filter p (f a) :=
map_sum (filterAddHom p) f s
theorem filter_eq_sum (p : α → Prop) [DecidablePred p] (f : α →₀ M) :
f.filter p = ∑ i ∈ f.support.filter p, single i (f i) :=
(f.filter p).sum_single.symm.trans <|
Finset.sum_congr rfl fun x hx => by
rw [filter_apply_pos _ _ (mem_filter.1 hx).2]
end CommMonoid
section Group
variable [AddGroup G] {p : α → Prop} {v v' : α →₀ G}
@[simp]
theorem subtypeDomain_neg : (-v).subtypeDomain p = -v.subtypeDomain p :=
ext fun _ => rfl
@[simp]
theorem subtypeDomain_sub : (v - v').subtypeDomain p = v.subtypeDomain p - v'.subtypeDomain p :=
ext fun _ => rfl
@[simp]
theorem filter_neg (p : α → Prop) [DecidablePred p] (f : α →₀ G) : filter p (-f) = -filter p f :=
(filterAddHom p : (_ →₀ G) →+ _).map_neg f
@[simp]
theorem filter_sub (p : α → Prop) [DecidablePred p] (f₁ f₂ : α →₀ G) :
filter p (f₁ - f₂) = filter p f₁ - filter p f₂ :=
(filterAddHom p : (_ →₀ G) →+ _).map_sub f₁ f₂
end Group
end SubtypeDomain
theorem mem_support_multiset_sum [AddCommMonoid M] {s : Multiset (α →₀ M)} (a : α) :
a ∈ s.sum.support → ∃ f ∈ s, a ∈ (f : α →₀ M).support :=
Multiset.induction_on s (fun h => False.elim (by simp at h))
(by
intro f s ih ha
by_cases h : a ∈ f.support
· exact ⟨f, Multiset.mem_cons_self _ _, h⟩
· simp_rw [Multiset.sum_cons, mem_support_iff, add_apply, notMem_support_iff.1 h,
zero_add] at ha
rcases ih (mem_support_iff.2 ha) with ⟨f', h₀, h₁⟩
exact ⟨f', Multiset.mem_cons_of_mem h₀, h₁⟩)
theorem mem_support_finset_sum [AddCommMonoid M] {s : Finset ι} {h : ι → α →₀ M} (a : α)
(ha : a ∈ (∑ c ∈ s, h c).support) : ∃ c ∈ s, a ∈ (h c).support :=
let ⟨_, hf, hfa⟩ := mem_support_multiset_sum a ha
let ⟨c, hc, Eq⟩ := Multiset.mem_map.1 hf
⟨c, hc, Eq.symm ▸ hfa⟩
/-! ### Declarations about `curry` and `uncurry` -/
section Uncurry
variable [Zero M]
/-- Given a finitely supported function `f` from `α` to the type of
finitely supported functions from `β` to `M`,
`uncurry f` is the "uncurried" finitely supported function from `α × β` to `M`. -/
protected def uncurry (f : α →₀ β →₀ M) : α × β →₀ M where
toFun x := f x.1 x.2
support := f.support.disjiUnion (fun a ↦ (f a).support.map <| .sectR a _) <| by
intro a₁ _ a₂ _ hne
simp [Finset.disjoint_iff_ne, hne]
mem_support_toFun := by aesop
protected theorem uncurry_apply (f : α →₀ β →₀ M) (x : α × β) : f.uncurry x = f x.1 x.2 := rfl
@[simp]
protected theorem uncurry_apply_pair (f : α →₀ β →₀ M) (a : α) (b : β) :
f.uncurry (a, b) = f a b :=
rfl
@[simp]
lemma uncurry_single (a : α) (b : β) (m : M) :
(single a (single b m)).uncurry = single (a, b) m := by
ext ⟨x, y⟩
rcases eq_or_ne a x with rfl | hne <;> classical simp [single_apply, *]
theorem sum_uncurry_index [AddCommMonoid N] (f : α →₀ β →₀ M) (g : α × β → M → N) :
f.uncurry.sum (fun p c => g p c) = f.sum fun a f => f.sum fun b ↦ g (a, b) := by
simp [Finsupp.sum, Finsupp.uncurry, Finset.sum_disjiUnion]
theorem sum_uncurry_index' [AddCommMonoid N] (f : α →₀ β →₀ M) (g : α → β → M → N) :
f.uncurry.sum (fun p c => g p.1 p.2 c) = f.sum fun a f => f.sum (g a) :=
sum_uncurry_index ..
end Uncurry
section Curry
variable [DecidableEq α] [Zero M]
/-- Given a finitely supported function `f` from a product type `α × β` to `γ`,
`curry f` is the "curried" finitely supported function from `α` to the type of
finitely supported functions from `β` to `γ`. -/
protected def curry (f : α × β →₀ M) : α →₀ β →₀ M where
toFun a :=
{ toFun b := f (a, b)
support := f.support.filterMap (fun x ↦ if x.1 = a then x.2 else none) <| by simp +contextual
mem_support_toFun := by simp }
support := f.support.image Prod.fst
mem_support_toFun := by simp [DFunLike.ext_iff]
@[simp]
theorem curry_apply (f : α × β →₀ M) (x : α) (y : β) : f.curry x y = f (x, y) := rfl
@[simp]
theorem support_curry (f : α × β →₀ M) : f.curry.support = f.support.image Prod.fst :=
rfl
@[simp]
theorem curry_uncurry (f : α →₀ β →₀ M) : f.uncurry.curry = f := by
ext a b
simp
@[simp]
theorem uncurry_curry (f : α × β →₀ M) : f.curry.uncurry = f := by
ext ⟨a, b⟩
simp
@[simp]
lemma curry_single (a : α × β) (m : M) :
(single a m).curry = single a.1 (single a.2 m) := by
rw [← curry_uncurry (single _ _), uncurry_single]
theorem sum_curry_index [AddCommMonoid N] (f : α × β →₀ M) (g : α → β → M → N) :
(f.curry.sum fun a f => f.sum (g a)) = f.sum fun p c => g p.1 p.2 c := by
rw [← sum_uncurry_index', uncurry_curry]
/-- `finsuppProdEquiv` defines the `Equiv` between `((α × β) →₀ M)` and `(α →₀ (β →₀ M))` given by
currying and uncurrying. -/
@[simps]
def finsuppProdEquiv : (α × β →₀ M) ≃ (α →₀ β →₀ M) where
toFun := Finsupp.curry
invFun := Finsupp.uncurry
left_inv := uncurry_curry
right_inv := curry_uncurry
theorem filter_curry (f : α × β →₀ M) (p : α → Prop) [DecidablePred p] :
(f.filter fun a : α × β => p a.1).curry = f.curry.filter p := by
ext a b
simp [filter_apply, apply_ite (DFunLike.coe · b)]
end Curry
/-! ### Declarations about finitely supported functions whose support is a `Sum` type -/
section Sum
/-- `Finsupp.sumElim f g` maps `inl x` to `f x` and `inr y` to `g y`. -/
@[simps support]
def sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) : α ⊕ β →₀ γ where
support := f.support.disjSum g.support
toFun := Sum.elim f g
mem_support_toFun := by simp
@[simp, norm_cast]
theorem coe_sumElim {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) :
⇑(sumElim f g) = Sum.elim f g :=
rfl
theorem sumElim_apply {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α ⊕ β) :
sumElim f g x = Sum.elim f g x :=
rfl
theorem sumElim_inl {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : α) :
sumElim f g (Sum.inl x) = f x :=
rfl
theorem sumElim_inr {α β γ : Type*} [Zero γ] (f : α →₀ γ) (g : β →₀ γ) (x : β) :
sumElim f g (Sum.inr x) = g x :=
rfl
@[to_additive]
lemma prod_sumElim {ι₁ ι₂ α M : Type*} [Zero α] [CommMonoid M]
(f₁ : ι₁ →₀ α) (f₂ : ι₂ →₀ α) (g : ι₁ ⊕ ι₂ → α → M) :
(f₁.sumElim f₂).prod g = f₁.prod (g ∘ Sum.inl) * f₂.prod (g ∘ Sum.inr) := by
simp [Finsupp.prod, Finset.prod_disjSum]
/-- The equivalence between `(α ⊕ β) →₀ γ` and `(α →₀ γ) × (β →₀ γ)`.
This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps apply symm_apply]
def sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] : (α ⊕ β →₀ γ) ≃ (α →₀ γ) × (β →₀ γ) where
toFun f :=
⟨f.comapDomain Sum.inl Sum.inl_injective.injOn,
f.comapDomain Sum.inr Sum.inr_injective.injOn⟩
invFun fg := sumElim fg.1 fg.2
left_inv f := by
ext ab
rcases ab with a | b <;> simp
right_inv fg := by ext <;> simp
theorem fst_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (x : α) :
(sumFinsuppEquivProdFinsupp f).1 x = f (Sum.inl x) :=
rfl
theorem snd_sumFinsuppEquivProdFinsupp {α β γ : Type*} [Zero γ] (f : α ⊕ β →₀ γ) (y : β) :
(sumFinsuppEquivProdFinsupp f).2 y = f (Sum.inr y) :=
rfl
theorem sumFinsuppEquivProdFinsupp_symm_inl {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ))
(x : α) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x :=
rfl
theorem sumFinsuppEquivProdFinsupp_symm_inr {α β γ : Type*} [Zero γ] (fg : (α →₀ γ) × (β →₀ γ))
(y : β) : (sumFinsuppEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y :=
rfl
variable [AddMonoid M]
/-- The additive equivalence between `(α ⊕ β) →₀ M` and `(α →₀ M) × (β →₀ M)`.
This is the `Finsupp` version of `Equiv.sum_arrow_equiv_prod_arrow`. -/
@[simps! apply symm_apply]
def sumFinsuppAddEquivProdFinsupp {α β : Type*} : (α ⊕ β →₀ M) ≃+ (α →₀ M) × (β →₀ M) :=
{ sumFinsuppEquivProdFinsupp with
map_add' := by
intros
ext <;>
simp only [Equiv.toFun_as_coe, Prod.fst_add, Prod.snd_add, add_apply,
snd_sumFinsuppEquivProdFinsupp, fst_sumFinsuppEquivProdFinsupp] }
theorem fst_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (x : α) :
(sumFinsuppAddEquivProdFinsupp f).1 x = f (Sum.inl x) :=
rfl
theorem snd_sumFinsuppAddEquivProdFinsupp {α β : Type*} (f : α ⊕ β →₀ M) (y : β) :
(sumFinsuppAddEquivProdFinsupp f).2 y = f (Sum.inr y) :=
rfl
theorem sumFinsuppAddEquivProdFinsupp_symm_inl {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (x : α) :
(sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inl x) = fg.1 x :=
rfl
theorem sumFinsuppAddEquivProdFinsupp_symm_inr {α β : Type*} (fg : (α →₀ M) × (β →₀ M)) (y : β) :
(sumFinsuppAddEquivProdFinsupp.symm fg) (Sum.inr y) = fg.2 y :=
rfl
end Sum
section
variable [Zero R]
/-- The `Finsupp` version of `Pi.unique`. -/
instance uniqueOfRight [Subsingleton R] : Unique (α →₀ R) :=
DFunLike.coe_injective.unique
/-- The `Finsupp` version of `Pi.uniqueOfIsEmpty`. -/
instance uniqueOfLeft [IsEmpty α] : Unique (α →₀ R) :=
DFunLike.coe_injective.unique
end
section
variable {M : Type*} [Zero M] {P : α → Prop} [DecidablePred P]
/-- Combine finitely supported functions over `{a // P a}` and `{a // ¬P a}`, by case-splitting on
`P a`. -/
@[simps]
def piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) : α →₀ M where
toFun a := if h : P a then f ⟨a, h⟩ else g ⟨a, h⟩
support := (f.support.map (.subtype _)).disjUnion (g.support.map (.subtype _)) <| by
simp_rw [Finset.disjoint_left, mem_map, forall_exists_index, Embedding.coe_subtype,
Subtype.forall, Subtype.exists]
rintro _ a ha ⟨-, rfl⟩ ⟨b, hb, -, rfl⟩
exact hb ha
mem_support_toFun a := by
by_cases ha : P a <;> simp [ha]
@[simp]
theorem subtypeDomain_piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) :
subtypeDomain P (f.piecewise g) = f :=
Finsupp.ext fun a => dif_pos a.prop
@[simp]
theorem subtypeDomain_not_piecewise (f : Subtype P →₀ M) (g : {a // ¬ P a} →₀ M) :
subtypeDomain (¬P ·) (f.piecewise g) = g :=
Finsupp.ext fun a => dif_neg a.prop
/-- Extend the domain of a `Finsupp` by using `0` where `P x` does not hold. -/
@[simps! support toFun]
def extendDomain (f : Subtype P →₀ M) : α →₀ M := piecewise f 0
theorem extendDomain_eq_embDomain_subtype (f : Subtype P →₀ M) :
extendDomain f = embDomain (.subtype _) f := by
ext a
by_cases h : P a
· refine Eq.trans ?_ (embDomain_apply (.subtype P) f (Subtype.mk a h)).symm
simp [h]
· rw [embDomain_notin_range, extendDomain_toFun, dif_neg h]
simp [h]
theorem support_extendDomain_subset (f : Subtype P →₀ M) :
↑(f.extendDomain).support ⊆ {x | P x} := by
intro x
rw [extendDomain_support, mem_coe, mem_map, Embedding.coe_subtype]
rintro ⟨x, -, rfl⟩
exact x.prop
@[simp]
theorem subtypeDomain_extendDomain (f : Subtype P →₀ M) :
subtypeDomain P f.extendDomain = f :=
subtypeDomain_piecewise _ _
theorem extendDomain_subtypeDomain (f : α →₀ M) (hf : ∀ a ∈ f.support, P a) :
(subtypeDomain P f).extendDomain = f := by
ext a
by_cases h : P a
· exact dif_pos h
· dsimp [extendDomain_toFun]
rw [if_neg h, eq_comm, ← notMem_support_iff]
refine mt ?_ h
exact hf _
@[simp]
theorem extendDomain_single (a : Subtype P) (m : M) :
(single a m).extendDomain = single a.val m := by
ext a'
dsimp only [extendDomain_toFun]
obtain rfl | ha := eq_or_ne a.val a'
· simp_rw [single_eq_same, dif_pos a.prop]
· simp_rw [single_eq_of_ne ha, dite_eq_right_iff]
intro h
rw [single_eq_of_ne]
simp [Subtype.ext_iff, ha]
end
/-- Given an `AddCommMonoid M` and `s : Set α`, `restrictSupportEquiv s M` is the `Equiv`
between the subtype of finitely supported functions with support contained in `s` and
the type of finitely supported functions from `s`. -/
-- TODO: add [DecidablePred (· ∈ s)] as an assumption
@[simps apply] def restrictSupportEquiv (s : Set α) (M : Type*) [AddCommMonoid M] :
{ f : α →₀ M // ↑f.support ⊆ s } ≃ (s →₀ M) where
toFun f := subtypeDomain (· ∈ s) f.1
invFun f := letI := Classical.decPred (· ∈ s); ⟨f.extendDomain, support_extendDomain_subset _⟩
left_inv f :=
letI := Classical.decPred (· ∈ s); Subtype.ext <| extendDomain_subtypeDomain f.1 f.prop
right_inv _ := letI := Classical.decPred (· ∈ s); subtypeDomain_extendDomain _
@[simp] lemma restrictSupportEquiv_symm_apply_coe (s : Set α) (M : Type*) [AddCommMonoid M]
[DecidablePred (· ∈ s)] (f : s →₀ M) :
(restrictSupportEquiv s M).symm f = f.extendDomain := by
rw [restrictSupportEquiv, Equiv.coe_fn_symm_mk, Subtype.coe_mk]; congr
@[simp] lemma restrictSupportEquiv_symm_single (s : Set α) (M : Type*) [AddCommMonoid M]
(a : s) (x : M) :
(restrictSupportEquiv s M).symm (single a x) = single (a : α) x := by
classical simp
/-- Given `AddCommMonoid M` and `e : α ≃ β`, `domCongr e` is the corresponding `Equiv` between
`α →₀ M` and `β →₀ M`.
This is `Finsupp.equivCongrLeft` as an `AddEquiv`. -/
@[simps apply]
protected def domCongr [AddCommMonoid M] (e : α ≃ β) : (α →₀ M) ≃+ (β →₀ M) where
toFun := equivMapDomain e
invFun := equivMapDomain e.symm
left_inv v := by
simp_rw [← equivMapDomain_trans, Equiv.self_trans_symm]
exact equivMapDomain_refl _
right_inv := by
intro v
simp_rw [← equivMapDomain_trans, Equiv.symm_trans_self]
exact equivMapDomain_refl _
map_add' a b := by simp only [equivMapDomain_eq_mapDomain, mapDomain_add]
@[simp]
theorem domCongr_refl [AddCommMonoid M] :
Finsupp.domCongr (Equiv.refl α) = AddEquiv.refl (α →₀ M) :=
AddEquiv.ext fun _ => equivMapDomain_refl _
@[simp]
theorem domCongr_symm [AddCommMonoid M] (e : α ≃ β) :
(Finsupp.domCongr e).symm = (Finsupp.domCongr e.symm : (β →₀ M) ≃+ (α →₀ M)) :=
AddEquiv.ext fun _ => rfl
@[simp]
theorem domCongr_trans [AddCommMonoid M] (e : α ≃ β) (f : β ≃ γ) :
(Finsupp.domCongr e).trans (Finsupp.domCongr f) =
(Finsupp.domCongr (e.trans f) : (α →₀ M) ≃+ _) :=
AddEquiv.ext fun _ => (equivMapDomain_trans _ _ _).symm
end Finsupp
namespace Finsupp
/-! ### Declarations about sigma types -/
section Sigma
variable {αs : ι → Type*} [Zero M] (l : (Σ i, αs i) →₀ M)
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `M` and
an index element `i : ι`, `split l i` is the `i`th component of `l`,
a finitely supported function from `as i` to `M`.
This is the `Finsupp` version of `Sigma.curry`.
-/
def split (i : ι) : αs i →₀ M :=
l.comapDomain (Sigma.mk i) fun _ _ _ _ hx => heq_iff_eq.1 (Sigma.mk.inj hx).2
theorem split_apply (i : ι) (x : αs i) : split l i x = l ⟨i, x⟩ := by
rw [split, comapDomain_apply]
/-- Given `l`, a finitely supported function from the sigma type `Σ (i : ι), αs i` to `β`,
`split_support l` is the finset of indices in `ι` that appear in the support of `l`. -/
def splitSupport (l : (Σ i, αs i) →₀ M) : Finset ι :=
haveI := Classical.decEq ι
l.support.image Sigma.fst
theorem mem_splitSupport_iff_nonzero (i : ι) : i ∈ splitSupport l ↔ split l i ≠ 0 := by
classical rw [splitSupport, mem_image, Ne, ← support_eq_empty, ← Ne,
← Finset.nonempty_iff_ne_empty, split, comapDomain, Finset.Nonempty]
simp only [Finset.mem_preimage, exists_and_right, exists_eq_right, mem_support_iff,
Sigma.exists, Ne]
/-- Given `l`, a finitely supported function from the sigma type `Σ i, αs i` to `β` and
an `ι`-indexed family `g` of functions from `(αs i →₀ β)` to `γ`, `split_comp` defines a
finitely supported function from the index type `ι` to `γ` given by composing `g i` with
`split l i`. -/
def splitComp [Zero N] (g : ∀ i, (αs i →₀ M) → N) (hg : ∀ i x, x = 0 ↔ g i x = 0) : ι →₀ N where
support := splitSupport l
toFun i := g i (split l i)
mem_support_toFun := by
intro i
rw [mem_splitSupport_iff_nonzero, not_iff_not, hg]
theorem sigma_support : l.support = l.splitSupport.sigma fun i => (l.split i).support := by
simp_rw [Finset.ext_iff, splitSupport, split, comapDomain, Sigma.forall, mem_sigma, mem_image,
mem_preimage]
tauto
theorem sigma_sum [AddCommMonoid N] (f : (Σ i : ι, αs i) → M → N) :
l.sum f = ∑ i ∈ splitSupport l, (split l i).sum fun (a : αs i) b => f ⟨i, a⟩ b := by
simp only [sum, sigma_support, sum_sigma, split_apply]
variable {η : Type*} [Fintype η] {ιs : η → Type*} [Zero α]
/-- On a `Fintype η`, `Finsupp.split` is an equivalence between `(Σ (j : η), ιs j) →₀ α`
and `Π j, (ιs j →₀ α)`.
This is the `Finsupp` version of `Equiv.Pi_curry`. -/
noncomputable def sigmaFinsuppEquivPiFinsupp : ((Σ j, ιs j) →₀ α) ≃ ∀ j, ιs j →₀ α where
toFun := split
invFun f :=
onFinset (Finset.univ.sigma fun j => (f j).support) (fun ji => f ji.1 ji.2) fun _ hg =>
Finset.mem_sigma.mpr ⟨Finset.mem_univ _, mem_support_iff.mpr hg⟩
left_inv f := by
ext
simp [split]
right_inv f := by
ext
simp [split]
@[simp]
theorem sigmaFinsuppEquivPiFinsupp_apply (f : (Σ j, ιs j) →₀ α) (j i) :
sigmaFinsuppEquivPiFinsupp f j i = f ⟨j, i⟩ :=
rfl
/-- On a `Fintype η`, `Finsupp.split` is an additive equivalence between
`(Σ (j : η), ιs j) →₀ α` and `Π j, (ιs j →₀ α)`.
This is the `AddEquiv` version of `Finsupp.sigmaFinsuppEquivPiFinsupp`.
-/
noncomputable def sigmaFinsuppAddEquivPiFinsupp {α : Type*} {ιs : η → Type*} [AddMonoid α] :
((Σ j, ιs j) →₀ α) ≃+ ∀ j, ιs j →₀ α :=
{ sigmaFinsuppEquivPiFinsupp with
map_add' := fun f g => by
ext
simp }
@[simp]
theorem sigmaFinsuppAddEquivPiFinsupp_apply {α : Type*} {ιs : η → Type*} [AddMonoid α]
(f : (Σ j, ιs j) →₀ α) (j i) : sigmaFinsuppAddEquivPiFinsupp f j i = f ⟨j, i⟩ :=
rfl
end Sigma
end Finsupp
|
ssrmatching.v
|
From Corelib Require Export ssrmatching.
|
algC.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq choice.
From mathcomp Require Import div fintype path bigop finset prime order ssralg.
From mathcomp Require Import poly polydiv mxpoly generic_quotient countalg.
From mathcomp Require Import ssrnum closed_field ssrint archimedean rat intdiv.
From mathcomp Require Import algebraics_fundamentals.
(******************************************************************************)
(* This file provides an axiomatic construction of the algebraic numbers. *)
(* The construction only assumes the existence of an algebraically closed *)
(* filed with an automorphism of order 2; this amounts to the purely *)
(* algebraic contents of the Fundamenta Theorem of Algebra. *)
(* algC == the closed, countable field of algebraic numbers. *)
(* algCeq, algCnzRing, ..., algCnumField == structures for algC. *)
(* The ssrnum interfaces are implemented for algC as follows: *)
(* x <= y <=> (y - x) is a nonnegative real *)
(* x < y <=> (y - x) is a (strictly) positive real *)
(* `|z| == the complex norm of z, i.e., sqrtC (z * z^* ). *)
(* Creal == the subset of real numbers (:= Num.real for algC). *)
(* 'i == the imaginary number (:= sqrtC (-1)). *)
(* 'Re z == the real component of z. *)
(* 'Im z == the imaginary component of z. *)
(* z^* == the complex conjugate of z (:= conjC z). *)
(* sqrtC z == a nonnegative square root of z, i.e., 0 <= sqrt x if 0 <= x. *)
(* n.-root z == more generally, for n > 0, an nth root of z, chosen with a *)
(* minimal non-negative argument for n > 1 (i.e., with a *)
(* maximal real part subject to a nonnegative imaginary part). *)
(* Note that n.-root (-1) is a primitive 2nth root of unity, *)
(* an thus not equal to -1 for n odd > 1 (this will be shown in *)
(* file cyclotomic.v). *)
(* In addition, we provide: *)
(* Crat == the subset of rational numbers. *)
(* getCrat z == some a : rat such that ratr a = z, provided z \in Crat. *)
(* minCpoly z == the minimal (monic) polynomial over Crat with root z. *)
(* algC_invaut nu == an inverse of nu : {rmorphism algC -> algC}. *)
(* (x %| y)%C <=> y is an integer (Num.int) multiple of x; if x or y *)
(* (x %| y)%Cx are of type nat or int they are coerced to algC. *)
(* The (x %| y)%Cx display form is a workaround for *)
(* design limitations of the Coq Notation facilities. *)
(* (x == y %[mod z])%C <=> x and y differ by an integer (Num.int) multiple of *)
(* z; as above, arguments of type nat or int are cast to algC. *)
(* (x != y %[mod z])%C <=> x and y do not differ by an integer multiple of z. *)
(* algR == the subset of real algebraic numbers. *)
(* algR_norm x == the norm of (x : algR). *)
(* algR_pfactor x == the minimal (monic) polynomial over algR with root x. *)
(* algC_pfactor x == the minimal (monic) polynomial over algR with root x, *)
(* with coefficients in algC. *)
(* Note that in file algnum we give an alternative definition of divisibility *)
(* based on algebraic integers, overloading the notation in the %A scope. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope C_scope.
Declare Scope C_core_scope.
Declare Scope C_expanded_scope.
Import Order.TTheory GRing.Theory Num.Theory.
Local Open Scope ring_scope.
HB.factory Record isComplex L of GRing.ClosedField L := {
conj : {rmorphism L -> L};
conjK : involutive conj;
conj_nt : ~ conj =1 id
}.
HB.builders Context L of isComplex L.
Lemma nz2: 2 != 0 :> L.
Proof.
apply/eqP=> pchar2; apply: conj_nt => e; apply/eqP/idPn=> eJ.
have opp_id x: - x = x :> L.
by apply/esym/eqP; rewrite -addr_eq0 -mulr2n -mulr_natl pchar2 mul0r.
have{} pchar2: 2%N \in [pchar L] by apply/eqP.
without loss{eJ} eJ: e / conj e = e + 1.
move/(_ (e / (e + conj e))); apply.
rewrite fmorph_div rmorphD /= conjK -{1}[conj e](addNKr e) mulrDl.
by rewrite opp_id (addrC e) divff // addr_eq0 opp_id.
pose a := e * conj e; have aJ: conj a = a by rewrite rmorphM /= conjK mulrC.
have [w Dw] := @solve_monicpoly _ 2%N (nth 0 [:: e * a; - 1]) isT.
have{} Dw: w ^+ 2 + w = e * a.
by rewrite Dw !big_ord_recl big_ord0 /= mulr1 mulN1r addr0 subrK.
pose b := w + conj w; have bJ: conj b = b by rewrite rmorphD /= conjK addrC.
have Db2: b ^+ 2 + b = a.
rewrite -pFrobenius_autE // rmorphD addrACA Dw /= pFrobenius_autE -rmorphXn.
by rewrite -rmorphD Dw rmorphM /= aJ eJ -mulrDl -{1}[e]opp_id addKr mul1r.
have /eqP[] := oner_eq0 L; apply: (addrI b); rewrite addr0 -{2}bJ.
have: (b + e) * (b + conj e) == 0.
(* FIX ME : had to add pattern selection *)
rewrite mulrDl 2![_ * (b + _)]mulrDr -/a.
rewrite addrA addr_eq0 opp_id (mulrC e) -addrA.
by rewrite -mulrDr eJ addrAC -{2}[e]opp_id subrr add0r mulr1 Db2.
rewrite mulf_eq0 !addr_eq0 !opp_id => /pred2P[] -> //.
by rewrite {2}eJ rmorphD rmorph1.
Qed.
Lemma mul2I: injective (fun z : L => z *+ 2).
Proof.
have nz2 := nz2.
by move=> x y; rewrite /= -mulr_natl -(mulr_natl y) => /mulfI->.
Qed.
Definition sqrt x : L :=
sval (sig_eqW (@solve_monicpoly _ 2%N (nth 0 [:: x]) isT)).
Lemma sqrtK x: sqrt x ^+ 2 = x.
Proof.
rewrite /sqrt; case: sig_eqW => /= y ->.
by rewrite !big_ord_recl big_ord0 /= mulr1 mul0r !addr0.
Qed.
Lemma sqrtE x y: y ^+ 2 = x -> {b : bool | y = (-1) ^+ b * sqrt x}.
Proof.
move=> Dx; exists (y != sqrt x); apply/eqP; rewrite mulr_sign if_neg.
by case: ifPn => //; apply/implyP; rewrite implyNb -eqf_sqr Dx sqrtK.
Qed.
Definition i := sqrt (- 1).
Lemma sqrMi x: (i * x) ^+ 2 = - x ^+ 2.
Proof. by rewrite exprMn sqrtK mulN1r. Qed.
Lemma iJ : conj i = - i.
Proof.
have nz2 := nz2.
have /sqrtE[b]: conj i ^+ 2 = - 1 by rewrite -rmorphXn /= sqrtK rmorphN1.
rewrite mulr_sign -/i; case: b => // Ri.
case: conj_nt => z; wlog zJ: z / conj z = - z.
move/(_ (z - conj z)); rewrite !rmorphB conjK opprB => zJ.
by apply/mul2I/(canRL (subrK _)); rewrite -addrA zJ // addrC subrK.
have [-> | nz_z] := eqVneq z 0; first exact: rmorph0.
have [u Ru [v Rv Dz]]:
exists2 u, conj u = u & exists2 v, conj v = v & (u + z * v) ^+ 2 = z.
- pose y := sqrt z; exists ((y + conj y) / 2).
by rewrite fmorph_div rmorphD /= conjK addrC rmorph_nat.
exists ((y - conj y) / (z *+ 2)).
rewrite fmorph_div rmorphMn /= zJ mulNrn invrN mulrN -mulNr rmorphB opprB.
by rewrite conjK.
rewrite -(mulr_natl z) invfM (mulrC z) !mulrA divfK // -mulrDl addrACA.
(* FIX ME : had to add the explicit pattern *)
by rewrite subrr addr0 -mulr2n -[_ *+ 2]mulr_natr mulfK ?Neq0 ?sqrtK.
suff u0: u = 0 by rewrite -Dz u0 add0r rmorphXn rmorphM /= Rv zJ mulNr sqrrN.
suff [b Du]: exists b : bool, u = (-1) ^+ b * i * z * v.
apply: mul2I; rewrite mul0rn mulr2n -{2}Ru.
by rewrite Du !rmorphM /= rmorph_sign Rv Ri zJ !mulrN mulNr subrr.
have/eqP:= zJ; rewrite -addr_eq0 -{1 2}Dz rmorphXn rmorphD rmorphM /= Ru Rv zJ.
rewrite mulNr sqrrB sqrrD addrACA (addrACA (u ^+ 2)) addNr addr0 -!mulr2n.
rewrite -mulrnDl -(mul0rn _ 2) (inj_eq mul2I) /= -[rhs in _ + rhs]opprK.
rewrite -sqrMi subr_eq0 eqf_sqr -mulNr !mulrA.
by case/pred2P=> ->; [exists false | exists true]; rewrite mulr_sign.
Qed.
Definition norm x := sqrt x * conj (sqrt x).
Lemma normK x : norm x ^+ 2 = x * conj x.
Proof. by rewrite exprMn -rmorphXn sqrtK. Qed.
Lemma normE x y : y ^+ 2 = x -> norm x = y * conj y.
Proof.
rewrite /norm => /sqrtE[b /(canLR (signrMK b)) <-].
by rewrite !rmorphM /= rmorph_sign mulrACA -mulrA signrMK.
Qed.
Lemma norm_eq0 x : norm x = 0 -> x = 0.
Proof.
by move/eqP; rewrite mulf_eq0 fmorph_eq0 -mulf_eq0 -expr2 sqrtK => /eqP.
Qed.
Lemma normM x y : norm (x * y) = norm x * norm y.
Proof.
by rewrite mulrACA -rmorphM; apply: normE; rewrite exprMn !sqrtK.
Qed.
Lemma normN x : norm (- x) = norm x.
Proof.
by rewrite -mulN1r normM {1}/norm iJ mulrN -expr2 sqrtK opprK mul1r.
Qed.
Definition le x y := norm (y - x) == y - x.
Definition lt x y := (y != x) && le x y.
Lemma posE x: le 0 x = (norm x == x).
Proof. by rewrite /le subr0. Qed.
Lemma leB x y: le x y = le 0 (y - x).
Proof. by rewrite posE. Qed.
Lemma posP x : reflect (exists y, x = y * conj y) (le 0 x).
Proof.
rewrite posE; apply: (iffP eqP) => [Dx | [y {x}->]]; first by exists (sqrt x).
by rewrite (normE (normK y)) rmorphM /= conjK (mulrC (conj _)) -expr2 normK.
Qed.
Lemma posJ x : le 0 x -> conj x = x.
Proof.
by case/posP=> {x}u ->; rewrite rmorphM /= conjK mulrC.
Qed.
Lemma pos_linear x y : le 0 x -> le 0 y -> le x y || le y x.
Proof.
move=> pos_x pos_y; rewrite leB -opprB orbC leB !posE normN -eqf_sqr.
by rewrite normK rmorphB !posJ ?subrr.
Qed.
Lemma sposDl x y : lt 0 x -> le 0 y -> lt 0 (x + y).
Proof.
have sqrtJ z : le 0 z -> conj (sqrt z) = sqrt z.
rewrite posE -{2}[z]sqrtK -subr_eq0 -mulrBr mulf_eq0 subr_eq0.
by case/pred2P=> ->; rewrite ?rmorph0.
case/andP=> nz_x /sqrtJ uJ /sqrtJ vJ.
set u := sqrt x in uJ; set v := sqrt y in vJ; pose w := u + i * v.
have ->: x + y = w * conj w.
rewrite rmorphD rmorphM /= iJ uJ vJ mulNr mulrC -subr_sqr sqrMi opprK.
by rewrite !sqrtK.
apply/andP; split; last by apply/posP; exists w.
rewrite -normK expf_eq0 //=; apply: contraNneq nz_x => /norm_eq0 w0.
rewrite -[x]sqrtK expf_eq0 /= -/u -(inj_eq mul2I) !mulr2n -{2}(rmorph0 conj).
by rewrite -w0 rmorphD rmorphM /= iJ uJ vJ mulNr addrACA subrr addr0.
Qed.
Lemma sposD x y : lt 0 x -> lt 0 y -> lt 0 (x + y).
Proof.
by move=> x_gt0 /andP[_]; apply: sposDl.
Qed.
Lemma normD x y : le (norm (x + y)) (norm x + norm y).
Proof.
have sposM u v: lt 0 u -> le 0 (u * v) -> le 0 v.
by rewrite /lt !posE normM andbC => /andP[/eqP-> /mulfI/inj_eq->].
have posD u v: le 0 u -> le 0 v -> le 0 (u + v).
have [-> | nz_u u_ge0 v_ge0] := eqVneq u 0; first by rewrite add0r.
by have /andP[]: lt 0 (u + v) by rewrite sposDl // /lt nz_u.
have le_sqr u v: conj u = u -> le 0 v -> le (u ^+ 2) (v ^+ 2) -> le u v.
case: (eqVneq u 0) => [-> //|nz_u Ru v_ge0].
have [u_gt0 | u_le0 _] := boolP (lt 0 u).
by rewrite leB (leB u) subr_sqr mulrC addrC; apply: sposM; apply: sposDl.
rewrite leB posD // posE normN -addr_eq0; apply/eqP.
rewrite /lt nz_u posE -subr_eq0 in u_le0; apply: (mulfI u_le0).
by rewrite mulr0 -subr_sqr normK Ru subrr.
have pos_norm z: le 0 (norm z) by apply/posP; exists (sqrt z).
rewrite le_sqr ?posJ ?posD // sqrrD !normK -normM rmorphD mulrDl !mulrDr.
rewrite addrA addrC !addrA -(addrC (y * conj y)) !addrA.
move: (y * _ + _) => u; rewrite -!addrA leB opprD addrACA {u}subrr add0r -leB.
rewrite {}le_sqr ?posD //.
by rewrite rmorphD !rmorphM /= !conjK addrC (mulrC x) (mulrC y).
rewrite -mulr2n -mulr_natr exprMn normK -natrX mulr_natr sqrrD mulrACA.
rewrite -rmorphM (mulrC y x) addrAC leB mulrnA mulr2n opprD addrACA.
rewrite subrr addr0 {2}(mulrC x) rmorphM mulrACA -opprB addrAC -sqrrB -sqrMi.
apply/posP; exists (i * (x * conj y - y * conj x)); congr (_ * _).
rewrite !(rmorphM, rmorphB) iJ !conjK mulNr -[in RHS]mulrN opprB.
by rewrite (mulrC x) (mulrC y).
Qed.
HB.instance Definition _ :=
Num.IntegralDomain_isNumRing.Build L normD sposD norm_eq0
pos_linear normM (fun x y => erefl (le x y))
(fun x y => erefl (lt x y)).
HB.instance Definition _ :=
Num.NumField_isImaginary.Build L (sqrtK _) normK.
HB.end.
Module Algebraics.
Module Type Specification.
Parameter type : Type.
Parameter conjMixin : Num.ClosedField type.
Parameter isCountable : Countable type.
(* Note that this cannot be included in conjMixin since a few proofs
depend from nat_num being definitionally equal to (truncn x)%:R == x *)
Axiom archimedean : Num.archimedean_axiom (Num.ClosedField.Pack conjMixin).
Axiom algebraic : integralRange (@ratr (Num.ClosedField.Pack conjMixin)).
End Specification.
Module Implementation : Specification.
Definition L := tag Fundamental_Theorem_of_Algebraics.
Definition conjL : {rmorphism L -> L} :=
s2val (tagged Fundamental_Theorem_of_Algebraics).
Fact conjL_K : involutive conjL.
Proof. exact: s2valP (tagged Fundamental_Theorem_of_Algebraics). Qed.
Fact conjL_nt : ~ conjL =1 id.
Proof. exact: s2valP' (tagged Fundamental_Theorem_of_Algebraics). Qed.
Definition L' : Type := eta L.
HB.instance Definition _ := GRing.ClosedField.on L'.
HB.instance Definition _ := isComplex.Build L' conjL_K conjL_nt.
Notation cfType := (L' : closedFieldType).
Definition QtoL : {rmorphism _ -> _} := @ratr cfType.
Notation pQtoL := (map_poly QtoL).
Definition rootQtoL p_j :=
if p_j.1 == 0 then 0 else
(sval (closed_field_poly_normal (pQtoL p_j.1)))`_p_j.2.
Definition eq_root p_j q_k := rootQtoL p_j == rootQtoL q_k.
Fact eq_root_is_equiv : equiv_class_of eq_root.
Proof. by rewrite /eq_root; split=> [ ? | ? ? | ? ? ? ] // /eqP->. Qed.
Canonical eq_root_equiv := EquivRelPack eq_root_is_equiv.
Definition type : Type := {eq_quot eq_root}%qT.
HB.instance Definition _ : EqQuotient _ eq_root type := EqQuotient.on type.
HB.instance Definition _ := Choice.on type.
HB.instance Definition _ := isCountable.Build type
(pcan_pickleK (can_pcan reprK)).
Definition CtoL (u : type) := rootQtoL (repr u).
Fact CtoL_inj : injective CtoL.
Proof. by move=> u v /eqP eq_uv; rewrite -[u]reprK -[v]reprK; apply/eqmodP. Qed.
Fact CtoL_P u : integralOver QtoL (CtoL u).
Proof.
rewrite /CtoL /rootQtoL; case: (repr u) => p j /=.
case: (closed_field_poly_normal _) => r Dp /=.
case: ifPn => [_ | nz_p]; first exact: integral0.
have [/(nth_default 0)-> | lt_j_r] := leqP (size r) j; first exact: integral0.
apply/integral_algebraic; exists p; rewrite // Dp -mul_polyC rootM orbC.
by rewrite root_prod_XsubC mem_nth.
Qed.
Fact LtoC_subproof z : integralOver QtoL z -> {u | CtoL u = z}.
Proof.
case/sig2_eqW=> p mon_p pz0; rewrite /CtoL.
pose j := index z (sval (closed_field_poly_normal (pQtoL p))).
pose u := \pi_type%qT (p, j); exists u; have /eqmodP/eqP-> := reprK u.
rewrite /rootQtoL -if_neg monic_neq0 //; apply: nth_index => /=.
case: (closed_field_poly_normal _) => r /= Dp.
by rewrite Dp (monicP _) ?(monic_map QtoL) // scale1r root_prod_XsubC in pz0.
Qed.
Definition LtoC z Az := sval (@LtoC_subproof z Az).
Fact LtoC_K z Az : CtoL (@LtoC z Az) = z.
Proof. exact: (svalP (LtoC_subproof Az)). Qed.
Fact CtoL_K u : LtoC (CtoL_P u) = u.
Proof. by apply: CtoL_inj; rewrite LtoC_K. Qed.
Definition zero := LtoC (integral0 _).
Definition add u v := LtoC (integral_add (CtoL_P u) (CtoL_P v)).
Definition opp u := LtoC (integral_opp (CtoL_P u)).
Fact addA : associative add.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K addrA. Qed.
Fact addC : commutative add.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K addrC. Qed.
Fact add0 : left_id zero add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K add0r. Qed.
Fact addN : left_inverse zero opp add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0 addN.
Fact CtoL_is_zmod_morphism : zmod_morphism CtoL.
Proof. by move=> u v; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition CtoL_is_additive := CtoL_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build type L' CtoL
CtoL_is_zmod_morphism.
Definition one := LtoC (integral1 _).
Definition mul u v := LtoC (integral_mul (CtoL_P u) (CtoL_P v)).
Definition inv u := LtoC (integral_inv (CtoL_P u)).
Fact mulA : associative mul.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrA. Qed.
Fact mulC : commutative mul.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K mulrC. Qed.
Fact mul1 : left_id one mul.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K mul1r. Qed.
Fact mulD : left_distributive mul +%R.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrDl. Qed.
Fact one_nz : one != 0 :> type.
Proof. by rewrite -(inj_eq CtoL_inj) !LtoC_K oner_eq0. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build type mulA mulC mul1 mulD one_nz.
Fact CtoL_is_monoid_morphism : monoid_morphism CtoL.
Proof. by split=> [|u v]; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_is_monoid_morphism` instead")]
Definition CtoL_is_multiplicative :=
(fun g => (g.2,g.1)) CtoL_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build type L' CtoL
CtoL_is_monoid_morphism.
Fact mulVf u : u != 0 -> inv u * u = 1.
Proof.
rewrite -(inj_eq CtoL_inj) rmorph0 => nz_u.
by apply: CtoL_inj; rewrite !LtoC_K mulVf.
Qed.
Fact inv0 : inv 0 = 0. Proof. by apply: CtoL_inj; rewrite !LtoC_K invr0. Qed.
HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulVf inv0.
Fact closedFieldAxiom : GRing.closed_field_axiom type.
Proof.
move=> n a n_gt0; pose p := 'X^n - \poly_(i < n) CtoL (a i).
have Ap : {in p : seq L, integralRange QtoL}.
move=> _ /(nthP 0)[j _ <-]; rewrite coefB coefXn coef_poly.
apply: integral_sub; first exact: integral_nat.
by case: ifP => _; [apply: CtoL_P | apply: integral0].
have sz_p : size p = n.+1.
by rewrite size_polyDl size_polyXn // size_polyN ltnS size_poly.
have [z pz0] : exists z, root p z by apply/closed_rootP; rewrite sz_p eqSS -lt0n.
have Az: integralOver ratr z.
by apply: integral_root Ap; rewrite // -size_poly_gt0 sz_p.
exists (LtoC Az); apply/CtoL_inj; rewrite -[CtoL _]subr0 -(rootP pz0).
rewrite rmorphXn /= LtoC_K hornerD hornerXn hornerN opprD addNKr opprK.
rewrite horner_poly rmorph_sum; apply: eq_bigr => k _.
by rewrite rmorphM rmorphXn /= LtoC_K.
Qed.
HB.instance Definition _ := Field_isAlgClosed.Build type closedFieldAxiom.
Fact conj_subproof u : integralOver QtoL (conjL (CtoL u)).
Proof.
have [p mon_p pu0] := CtoL_P u; exists p => //.
rewrite -(fmorph_root conjL) conjL_K map_poly_id // => _ /(nthP 0)[j _ <-].
by rewrite coef_map fmorph_rat.
Qed.
Fact conj_is_nmod_morphism : nmod_morphism (fun u => LtoC (conj_subproof u)).
Proof.
by split=> [|u v]; apply: CtoL_inj; rewrite LtoC_K ?raddf0// !rmorphD/= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_nmod_morphism` instead")]
Definition conj_is_semi_additive := conj_is_nmod_morphism.
Fact conj_is_zmod_morphism : {morph (fun u => LtoC (conj_subproof u)) : x / - x}.
Proof. by move=> u; apply: CtoL_inj; rewrite LtoC_K !raddfN /= LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition conj_is_additive := conj_is_zmod_morphism.
Fact conj_is_monoid_morphism : monoid_morphism (fun u => LtoC (conj_subproof u)).
Proof.
split=> [|u v]; apply: CtoL_inj; first by rewrite !LtoC_K rmorph1.
by rewrite LtoC_K 3!{1}rmorphM /= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_monoid_morphism` instead")]
Definition conj_is_multiplicative :=
(fun g => (g.2,g.1)) conj_is_monoid_morphism.
Definition conj : {rmorphism type -> type} :=
GRing.RMorphism.Pack
(GRing.RMorphism.Class
(GRing.isNmodMorphism.Build _ _ _ conj_is_nmod_morphism)
(GRing.isMonoidMorphism.Build _ _ _ conj_is_monoid_morphism)).
Lemma conjK : involutive conj.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K conjL_K. Qed.
Fact conj_nt : ~ conj =1 id.
Proof.
have [i i2]: exists i : type, i ^+ 2 = -1.
have [i] := @solve_monicpoly _ 2%N (nth 0 [:: -1 : type]) isT.
by rewrite !big_ord_recl big_ord0 /= mul0r mulr1 !addr0; exists i.
move/(_ i)/(congr1 CtoL); rewrite LtoC_K => iL_J.
have/lt_geF/idP[] := @ltr01 cfType.
rewrite -oppr_ge0 -(rmorphN1 CtoL).
by rewrite -i2 rmorphXn /= expr2 -{2}iL_J -normCK exprn_ge0.
Qed.
HB.instance Definition _ := isComplex.Build type conjK conj_nt.
Definition conjMixin := Num.ClosedField.on type.
Lemma algebraic : integralRange (@ratr type).
Proof.
move=> u; have [p mon_p pu0] := CtoL_P u; exists p => {mon_p}//.
rewrite -(fmorph_root CtoL) -map_poly_comp; congr (root _ _):pu0.
by apply/esym/eq_map_poly; apply: fmorph_eq_rat.
Qed.
Fact archimedean : Num.archimedean_axiom type.
Proof. exact: rat_algebraic_archimedean algebraic. Qed.
Definition isCountable := Countable.on type.
End Implementation.
Definition divisor := Implementation.type.
#[export] HB.instance Definition _ := Implementation.conjMixin.
#[export] HB.instance Definition _ :=
Num.NumDomain_bounded_isArchimedean.Build Implementation.type
Implementation.archimedean.
#[export] HB.instance Definition _ := Implementation.isCountable.
Module Internals.
Import Implementation.
Local Notation algC := type.
Local Notation QtoC := (ratr : rat -> algC).
Local Notation pQtoC := (map_poly QtoC : {poly rat} -> {poly algC}).
Fact algCi_subproof : {i : algC | i ^+ 2 = -1}.
Proof. exact: GRing.imaginary_exists. Qed.
Variant getCrat_spec : Type := GetCrat_spec CtoQ of cancel QtoC CtoQ.
Fact getCrat_subproof : getCrat_spec.
Proof.
have isQ := rat_algebraic_decidable algebraic.
exists (fun z => if isQ z is left Qz then sval (sig_eqW Qz) else 0) => a.
case: (isQ _) => [Qa | []]; last by exists a.
by case: (sig_eqW _) => b /= /fmorph_inj.
Qed.
Fact minCpoly_subproof (x : algC) :
{p : {poly rat} | p \is monic & forall q, root (pQtoC q) x = (p %| q)%R}.
Proof.
have isQ := rat_algebraic_decidable algebraic.
have [p [mon_p px0 irr_p]] := minPoly_decidable_closure isQ (algebraic x).
exists p => // q; apply/idP/idP=> [qx0 | /dvdpP[r ->]]; last first.
by rewrite rmorphM rootM px0 orbT.
suffices /eqp_dvdl <-: gcdp p q %= p by apply: dvdp_gcdr.
rewrite irr_p ?dvdp_gcdl ?gtn_eqF // -(size_map_poly QtoC) gcdp_map /=.
rewrite (@root_size_gt1 _ x) ?root_gcd ?px0 //.
by rewrite gcdp_eq0 negb_and map_poly_eq0 monic_neq0.
Qed.
Definition algC_divisor (x : algC) := x : divisor.
Definition int_divisor m := m%:~R : divisor.
Definition nat_divisor n := n%:R : divisor.
End Internals.
Module Import Exports.
Import Implementation Internals.
Notation algC := type.
Delimit Scope C_scope with C.
Delimit Scope C_core_scope with Cc.
Delimit Scope C_expanded_scope with Cx.
Open Scope C_core_scope.
Notation algCeq := (type : eqType).
Notation algCzmod := (type : zmodType).
Notation algCnzRing := (type : nzRingType).
#[deprecated(since="mathcomp 2.4.0",
note="Use algCnzRing instead.")]
Notation algCring := (type : nzRingType).
Notation algCuring := (type : unitRingType).
Notation algCnum := (type : numDomainType).
Notation algCfield := (type : fieldType).
Notation algCnumField := (type : numFieldType).
Notation algCnumClosedField := (type : numClosedFieldType).
Notation Creal := (@Num.Def.Rreal algCnum).
Definition getCrat := let: GetCrat_spec CtoQ _ := getCrat_subproof in CtoQ.
Definition Crat : {pred algC} := fun x => ratr (getCrat x) == x.
Definition minCpoly x : {poly algC} :=
let: exist2 p _ _ := minCpoly_subproof x in map_poly ratr p.
Coercion nat_divisor : nat >-> divisor.
Coercion int_divisor : int >-> divisor.
Coercion algC_divisor : algC >-> divisor.
Lemma nCdivE (p : nat) : p = p%:R :> divisor. Proof. by []. Qed.
Lemma zCdivE (p : int) : p = p%:~R :> divisor. Proof. by []. Qed.
Definition CdivE := (nCdivE, zCdivE).
Definition dvdC (x : divisor) : {pred algC} :=
fun y => if x == 0 then y == 0 else y / x \in Num.int.
Notation "x %| y" := (y \in dvdC x) : C_expanded_scope.
Notation "x %| y" := (@in_mem divisor y (mem (dvdC x))) : C_scope.
Definition eqCmod (e x y : divisor) := (e %| x - y)%C.
Notation "x == y %[mod e ]" := (eqCmod e x y) : C_scope.
Notation "x != y %[mod e ]" := (~~ (x == y %[mod e])%C) : C_scope.
End Exports.
Module HBExports. HB.reexport. End HBExports.
End Algebraics.
Export Algebraics.Exports.
Export Algebraics.HBExports.
Section AlgebraicsTheory.
Implicit Types (x y z : algC) (n : nat) (m : int) (b : bool).
Import Algebraics.Internals.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation CtoQ := getCrat.
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Let intr_inj_ZtoC := (intr_inj : injective ZtoC).
#[local] Hint Resolve intr_inj_ZtoC : core.
(* Specialization of a few basic ssrnum order lemmas. *)
Definition eqC_nat n p : (n%:R == p%:R :> algC) = (n == p) := eqr_nat _ n p.
Definition leC_nat n p : (n%:R <= p%:R :> algC) = (n <= p)%N := ler_nat _ n p.
Definition ltC_nat n p : (n%:R < p%:R :> algC) = (n < p)%N := ltr_nat _ n p.
Definition Cpchar : [pchar algC] =i pred0 := @pchar_num _.
(* This can be used in the converse direction to evaluate assertions over *)
(* manifest rationals, such as 3^-1 + 7%:%^-1 < 2%:%^-1 :> algC. *)
(* Missing norm and integer exponent, due to gaps in ssrint and rat. *)
Definition CratrE :=
let CnF : numClosedFieldType := algC in
let QtoCm : {rmorphism _ -> _} := @ratr CnF in
((rmorph0 QtoCm, rmorph1 QtoCm, rmorphMn QtoCm, rmorphN QtoCm, rmorphD QtoCm),
(rmorphM QtoCm, rmorphXn QtoCm, fmorphV QtoCm),
(rmorphMz QtoCm, rmorphXz QtoCm, @ratr_norm CnF, @ratr_sg CnF),
=^~ (@ler_rat CnF, @ltr_rat CnF, (inj_eq (fmorph_inj QtoCm)))).
Definition CintrE :=
let CnF : numClosedFieldType := algC in
let ZtoCm : {rmorphism _ -> _} := *~%R (1 : CnF) in
((rmorph0 ZtoCm, rmorph1 ZtoCm, rmorphMn ZtoCm, rmorphN ZtoCm, rmorphD ZtoCm),
(rmorphM ZtoCm, rmorphXn ZtoCm),
(rmorphMz ZtoCm, @intr_norm CnF, @intr_sg CnF),
=^~ (@ler_int CnF, @ltr_int CnF, (inj_eq (@intr_inj CnF)))).
Let nz2 : 2 != 0 :> algC.
Proof. by rewrite pnatr_eq0. Qed.
(* Conjugation and norm. *)
Definition algC_algebraic x := Algebraics.Implementation.algebraic x.
(* Real number subset. *)
Lemma algCrect x : x = 'Re x + 'i * 'Im x.
Proof. by rewrite [LHS]Crect. Qed.
Lemma algCreal_Re x : 'Re x \is Creal.
Proof. by rewrite Creal_Re. Qed.
Lemma algCreal_Im x : 'Im x \is Creal.
Proof. by rewrite Creal_Im. Qed.
Hint Resolve algCreal_Re algCreal_Im : core.
(* Integer divisibility. *)
Lemma dvdCP x y : reflect (exists2 z, z \in Num.int & y = z * x) (x %| y)%C.
Proof.
rewrite unfold_in; have [-> | nz_x] := eqVneq.
by apply: (iffP eqP) => [-> | [z _ ->]]; first exists 0; rewrite ?mulr0.
apply: (iffP idP) => [Zyx | [z Zz ->]]; last by rewrite mulfK.
by exists (y / x); rewrite ?divfK.
Qed.
Lemma dvdCP_nat x y : 0 <= x -> 0 <= y -> (x %| y)%C -> {n | y = n%:R * x}.
Proof.
move=> x_ge0 y_ge0 x_dv_y; apply: sig_eqW.
case/dvdCP: x_dv_y => z Zz -> in y_ge0 *; move: x_ge0 y_ge0 Zz.
rewrite le_eqVlt => /predU1P[<- | ]; first by exists 22%N; rewrite !mulr0.
by move=> /pmulr_lge0-> /intrEge0-> /natrP[n ->]; exists n.
Qed.
Lemma dvdC0 x : (x %| 0)%C.
Proof. by apply/dvdCP; exists 0; rewrite ?mul0r. Qed.
Lemma dvd0C x : (0 %| x)%C = (x == 0).
Proof. by rewrite unfold_in eqxx. Qed.
Lemma dvdC_mull x y z : y \in Num.int -> (x %| z)%C -> (x %| y * z)%C.
Proof.
move=> Zy /dvdCP[m Zm ->]; apply/dvdCP.
by exists (y * m); rewrite ?mulrA ?rpredM.
Qed.
Lemma dvdC_mulr x y z : y \in Num.int -> (x %| z)%C -> (x %| z * y)%C.
Proof. by rewrite mulrC; apply: dvdC_mull. Qed.
Lemma dvdC_mul2r x y z : y != 0 -> (x * y %| z * y)%C = (x %| z)%C.
Proof.
move=> nz_y; rewrite !unfold_in !(mulIr_eq0 _ (mulIf nz_y)).
by rewrite mulrAC invfM mulrA divfK.
Qed.
Lemma dvdC_mul2l x y z : y != 0 -> (y * x %| y * z)%C = (x %| z)%C.
Proof. by rewrite !(mulrC y); apply: dvdC_mul2r. Qed.
Lemma dvdC_trans x y z : (x %| y)%C -> (y %| z)%C -> (x %| z)%C.
Proof. by move=> x_dv_y /dvdCP[m Zm ->]; apply: dvdC_mull. Qed.
Lemma dvdC_refl x : (x %| x)%C.
Proof. by apply/dvdCP; exists 1; rewrite ?mul1r. Qed.
Hint Resolve dvdC_refl : core.
Lemma dvdC_zmod x : zmod_closed (dvdC x).
Proof.
split=> [| _ _ /dvdCP[y Zy ->] /dvdCP[z Zz ->]]; first exact: dvdC0.
by rewrite -mulrBl dvdC_mull ?rpredB.
Qed.
HB.instance Definition _ x := GRing.isZmodClosed.Build _ (dvdC x) (dvdC_zmod x).
Lemma dvdC_nat (p n : nat) : (p %| n)%C = (p %| n)%N.
Proof.
rewrite unfold_in intrEge0 ?divr_ge0 ?invr_ge0 ?ler0n // !pnatr_eq0.
have [-> | nz_p] := eqVneq; first by rewrite dvd0n.
apply/natrP/dvdnP=> [[q def_q] | [q ->]]; exists q.
by apply/eqP; rewrite -eqC_nat natrM -def_q divfK ?pnatr_eq0.
by rewrite [num in num / _]natrM mulfK ?pnatr_eq0.
Qed.
Lemma dvdC_int (p : nat) x :
x \in Num.int -> (p %| x)%C = (p %| `|Num.floor x|)%N.
Proof.
move=> Zx; rewrite -{1}(floorK Zx) {1}[Num.floor x]intEsign.
by rewrite rmorphMsign rpredMsign dvdC_nat.
Qed.
(* Elementary modular arithmetic. *)
Lemma eqCmod_refl e x : (x == x %[mod e])%C.
Proof. by rewrite /eqCmod subrr rpred0. Qed.
Lemma eqCmodm0 e : (e == 0 %[mod e])%C. Proof. by rewrite /eqCmod subr0. Qed.
Hint Resolve eqCmod_refl eqCmodm0 : core.
Lemma eqCmod0 e x : (x == 0 %[mod e])%C = (e %| x)%C.
Proof. by rewrite /eqCmod subr0. Qed.
Lemma eqCmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%C.
Proof. by rewrite /eqCmod -opprB rpredN. Qed.
Lemma eqCmod_trans e y x z :
(x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%C.
Proof.
by move=> Exy Eyz; rewrite /eqCmod -[x](subrK y) -[_ - z]addrA rpredD.
Qed.
Lemma eqCmod_transl e x y z :
(x == y %[mod e])%C -> (x == z %[mod e])%C = (y == z %[mod e])%C.
Proof. by move/(sym_left_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmod_transr e x y z :
(x == y %[mod e])%C -> (z == x %[mod e])%C = (z == y %[mod e])%C.
Proof. by move/(sym_right_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmodN e x y : (- x == y %[mod e])%C = (x == - y %[mod e])%C.
Proof. by rewrite eqCmod_sym /eqCmod !opprK addrC. Qed.
Lemma eqCmodDr e x y z : (y + x == z + x %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite /eqCmod addrAC opprD !addrA subrK. Qed.
Lemma eqCmodDl e x y z : (x + y == x + z %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite !(addrC x) eqCmodDr. Qed.
Lemma eqCmodD e x1 x2 y1 y2 :
(x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%C.
Proof.
by rewrite -(eqCmodDl e x2 y1) -(eqCmodDr e y1); apply: eqCmod_trans.
Qed.
Lemma eqCmod_nat (e m n : nat) : (m == n %[mod e])%C = (m == n %[mod e]).
Proof.
without loss lenm: m n / (n <= m)%N.
by move=> IH; case/orP: (leq_total m n) => /IH //; rewrite eqCmod_sym eq_sym.
by rewrite /eqCmod -natrB // dvdC_nat eqn_mod_dvd.
Qed.
Lemma eqCmod0_nat (e m : nat) : (m == 0 %[mod e])%C = (e %| m)%N.
Proof. by rewrite eqCmod0 dvdC_nat. Qed.
Lemma eqCmodMr e :
{in Num.int, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%C.
Proof. by move=> z Zz x y; rewrite /eqCmod -mulrBl => /dvdC_mulr->. Qed.
Lemma eqCmodMl e :
{in Num.int, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%C.
Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqCmodMr. Qed.
Lemma eqCmodMl0 e : {in Num.int, forall x, x * e == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite -(mulr0 x) eqCmodMl. Qed.
Lemma eqCmodMr0 e : {in Num.int, forall x, e * x == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite /= mulrC eqCmodMl0. Qed.
Lemma eqCmod_addl_mul e : {in Num.int, forall x y, x * e + y == y %[mod e]}%C.
Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqCmodDr eqCmodMl0. Qed.
Lemma eqCmodM e : {in Num.int & Num.int, forall x1 y2 x2 y1,
x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%C.
Proof.
move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqCmodMl Zx1)/eqCmod_trans-> //.
exact: eqCmodMr.
Qed.
(* Rational number subset. *)
Lemma ratCK : cancel QtoC CtoQ.
Proof. by rewrite /getCrat; case: getCrat_subproof. Qed.
Lemma getCratK : {in Crat, cancel CtoQ QtoC}.
Proof. by move=> x /eqP. Qed.
Lemma Crat_rat (a : rat) : QtoC a \in Crat.
Proof. by rewrite unfold_in ratCK. Qed.
Lemma CratP x : reflect (exists a, x = QtoC a) (x \in Crat).
Proof.
by apply: (iffP eqP) => [<- | [a ->]]; [exists (CtoQ x) | rewrite ratCK].
Qed.
Lemma Crat0 : 0 \in Crat. Proof. by apply/CratP; exists 0; rewrite rmorph0. Qed.
Lemma Crat1 : 1 \in Crat. Proof. by apply/CratP; exists 1; rewrite rmorph1. Qed.
#[local] Hint Resolve Crat0 Crat1 : core.
Fact Crat_divring_closed : divring_closed Crat.
Proof.
split=> // _ _ /CratP[x ->] /CratP[y ->].
by rewrite -rmorphB Crat_rat.
by rewrite -fmorph_div Crat_rat.
Qed.
HB.instance Definition _ := GRing.isDivringClosed.Build _ Crat
Crat_divring_closed.
Lemma rpred_Crat (S : divringClosed algC) : {subset Crat <= S}.
Proof. by move=> _ /CratP[a ->]; apply: rpred_rat. Qed.
Lemma conj_Crat z : z \in Crat -> z^* = z.
Proof. by move/getCratK <-; rewrite fmorph_div !rmorph_int. Qed.
Lemma Creal_Crat : {subset Crat <= Creal}.
Proof. by move=> x /conj_Crat/CrealP. Qed.
Lemma Cint_rat a : (QtoC a \in Num.int) = (a \in Num.int).
Proof.
apply/idP/idP=> [Za | /numqK <-]; last by rewrite rmorph_int.
apply/intrP; exists (Num.floor (QtoC a)); apply: (can_inj ratCK).
by rewrite rmorph_int floorK.
Qed.
Lemma minCpolyP x :
{p : {poly rat} | minCpoly x = pQtoC p /\ p \is monic
& forall q, root (pQtoC q) x = (p %| q)%R}.
Proof. by rewrite /minCpoly; case: (minCpoly_subproof x) => p; exists p. Qed.
Lemma minCpoly_monic x : minCpoly x \is monic.
Proof. by have [p [-> mon_p] _] := minCpolyP x; rewrite map_monic. Qed.
Lemma minCpoly_eq0 x : (minCpoly x == 0) = false.
Proof. exact/negbTE/monic_neq0/minCpoly_monic. Qed.
Lemma root_minCpoly x : root (minCpoly x) x.
Proof. by have [p [-> _] ->] := minCpolyP x. Qed.
Lemma size_minCpoly x : (1 < size (minCpoly x))%N.
Proof. by apply: root_size_gt1 (root_minCpoly x); rewrite ?minCpoly_eq0. Qed.
(* Basic properties of automorphisms. *)
Section AutC.
Implicit Type nu : {rmorphism algC -> algC}.
Lemma aut_Crat nu : {in Crat, nu =1 id}.
Proof. by move=> _ /CratP[a ->]; apply: fmorph_rat. Qed.
Lemma Crat_aut nu x : (nu x \in Crat) = (x \in Crat).
Proof.
apply/idP/idP=> /CratP[a] => [|->]; last by rewrite fmorph_rat Crat_rat.
by rewrite -(fmorph_rat nu) => /fmorph_inj->; apply: Crat_rat.
Qed.
Lemma algC_invaut_subproof nu x : {y | nu y = x}.
Proof.
have [r Dp] := closed_field_poly_normal (minCpoly x).
suffices /mapP/sig2_eqW[y _ ->]: x \in map nu r by exists y.
rewrite -root_prod_XsubC; congr (root _ x): (root_minCpoly x).
have [q [Dq _] _] := minCpolyP x; rewrite Dq -(eq_map_poly (fmorph_rat nu)).
rewrite (map_poly_comp nu) -{q}Dq Dp (monicP (minCpoly_monic x)) scale1r.
rewrite rmorph_prod big_map /=; apply: eq_bigr => z _.
by rewrite rmorphB /= map_polyX map_polyC.
Qed.
Definition algC_invaut nu x := sval (algC_invaut_subproof nu x).
Lemma algC_invautK nu : cancel (algC_invaut nu) nu.
Proof. by move=> x; rewrite /algC_invaut; case: algC_invaut_subproof. Qed.
Lemma algC_autK nu : cancel nu (algC_invaut nu).
Proof. exact: inj_can_sym (algC_invautK nu) (fmorph_inj nu). Qed.
Fact algC_invaut_is_zmod_morphism nu : zmod_morphism (algC_invaut nu).
Proof. exact: can2_zmod_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_zmod_morphism` instead")]
Definition algC_invaut_is_additive := algC_invaut_is_zmod_morphism.
Fact algC_invaut_is_monoid_morphism nu : monoid_morphism (algC_invaut nu).
Proof. exact: can2_monoid_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_monoid_morphism` instead")]
Definition algC_invaut_is_multiplicative nu :=
(fun g => (g.2,g.1)) (algC_invaut_is_monoid_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isZmodMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_zmod_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isMonoidMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_monoid_morphism nu).
Lemma minCpoly_aut nu x : minCpoly (nu x) = minCpoly x.
Proof.
wlog suffices dvd_nu: nu x / (minCpoly x %| minCpoly (nu x))%R.
apply/eqP; rewrite -eqp_monic ?minCpoly_monic //; apply/andP; split=> //.
by rewrite -{2}(algC_autK nu x) dvd_nu.
have [[q [Dq _] min_q] [q1 [Dq1 _] _]] := (minCpolyP x, minCpolyP (nu x)).
rewrite Dq Dq1 dvdp_map -min_q -(fmorph_root nu) -map_poly_comp.
by rewrite (eq_map_poly (fmorph_rat nu)) -Dq1 root_minCpoly.
Qed.
End AutC.
End AlgebraicsTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use Cpchar instead.")]
Notation Cchar := (Cpchar) (only parsing).
#[global] Hint Resolve Crat0 Crat1 dvdC0 dvdC_refl eqCmod_refl eqCmodm0 : core.
Local Notation "p ^^ f" := (map_poly f p)
(at level 30, f at level 30, format "p ^^ f").
Record algR := in_algR {algRval :> algC; algRvalP : algRval \is Creal}.
HB.instance Definition _ := [isSub for algRval].
HB.instance Definition _ := [Countable of algR by <:].
HB.instance Definition _ := [SubChoice_isSubIntegralDomain of algR by <:].
HB.instance Definition _ := [SubIntegralDomain_isSubField of algR by <:].
HB.instance Definition _ : Order.isPOrder ring_display algR :=
Order.CancelPartial.Pcan _ valK.
Lemma total_algR : total (<=%O : rel (algR : porderType _)).
Proof. by move=> x y; apply/real_leVge/valP/valP. Qed.
HB.instance Definition _ := Order.POrder_isTotal.Build _ algR total_algR.
Lemma algRval_is_zmod_morphism : zmod_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_zmod_morphism` instead")]
Definition algRval_is_additive := algRval_is_zmod_morphism.
Lemma algRval_is_monoid_morphism : monoid_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_monoid_morphism` instead")]
Definition algRval_is_multiplicative :=
(fun g => (g.2,g.1)) algRval_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build algR algC algRval
algRval_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build algR algC algRval
algRval_is_monoid_morphism.
Definition algR_norm (x : algR) : algR := in_algR (normr_real (val x)).
Lemma algR_ler_normD x y : algR_norm (x + y) <= (algR_norm x + algR_norm y).
Proof. exact: ler_normD. Qed.
Lemma algR_normr0_eq0 x : algR_norm x = 0 -> x = 0.
Proof. by move=> /(congr1 val)/normr0_eq0 ?; apply/val_inj. Qed.
Lemma algR_normrMn x n : algR_norm (x *+ n) = algR_norm x *+ n.
Proof. by apply/val_inj; rewrite /= !rmorphMn/= normrMn. Qed.
Lemma algR_normrN x : algR_norm (- x) = algR_norm x.
Proof. by apply/val_inj; apply: normrN. Qed.
Section Num.
Section withz.
Let z : algR := 0.
Lemma algR_addr_gt0 (x y : algR) : z < x -> z < y -> z < x + y.
Proof. exact: addr_gt0. Qed.
Lemma algR_ger_leVge (x y : algR) : z <= x -> z <= y -> (x <= y) || (y <= x).
Proof. exact: ger_leVge. Qed.
Lemma algR_normrM : {morph algR_norm : x y / x * y}.
Proof. by move=> *; apply/val_inj; apply: normrM. Qed.
Lemma algR_ler_def (x y : algR) : (x <= y) = (algR_norm (y - x) == y - x).
Proof. by apply: ler_def. Qed.
End withz.
HB.instance Definition _ := Num.Zmodule_isNormed.Build _ algR
algR_ler_normD algR_normr0_eq0 algR_normrMn algR_normrN.
HB.instance Definition _ := Num.isNumRing.Build algR
algR_addr_gt0 algR_ger_leVge algR_normrM algR_ler_def.
End Num.
Definition algR_archiFieldMixin : Num.archimedean_axiom algR.
Proof.
move=> /= x; have := real_floorD1_gt (valP `|x|).
set n := Num.floor _ + 1 => x_lt.
exists (`|(n + 1)%R|%N); apply: (lt_le_trans x_lt _).
by rewrite /= rmorphMn/= pmulrn ler_int (le_trans _ (lez_abs _))// lerDl.
Qed.
HB.instance Definition _ := Num.NumDomain_bounded_isArchimedean.Build algR
algR_archiFieldMixin.
Definition algR_pfactor (x : algC) : {poly algR} :=
if x \is Creal =P true is ReflectT xR then 'X - (in_algR xR)%:P else
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Notation algC_pfactor x := (algR_pfactor x ^^ algRval).
Lemma algR_pfactorRE (x : algC) (xR : x \is Creal) :
algR_pfactor x = 'X - (in_algR xR)%:P.
Proof.
rewrite /algR_pfactor; case: eqP xR => //= p1 p2.
by rewrite (bool_irrelevance p1 p2).
Qed.
Lemma algC_pfactorRE (x : algC) : x \is Creal ->
algC_pfactor x = 'X - x%:P.
Proof. by move=> xR; rewrite algR_pfactorRE map_polyXsubC. Qed.
Lemma algR_pfactorCE (x : algC) : x \isn't Creal ->
algR_pfactor x =
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Proof. by rewrite /algR_pfactor; case: eqP => // p; rewrite p. Qed.
Lemma algC_pfactorCE (x : algC) : x \isn't Creal ->
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P).
Proof.
move=> xNR; rewrite algR_pfactorCE//=.
rewrite rmorphD /= rmorphB/= !map_polyZ !map_polyXn/= map_polyX.
rewrite (map_polyC algRval)/=.
rewrite mulrBl !mulrBr -!addrA; congr (_ + _).
rewrite opprD addrA opprK -opprD -rmorphM/= -normCK; congr (- _ + _).
rewrite mulrC !mul_polyC -scalerDl.
rewrite [x in RHS]algCrect conjC_rect ?Creal_Re ?Creal_Im//.
by rewrite addrACA addNr addr0.
Qed.
Lemma algC_pfactorE x :
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P) ^+ (x \isn't Creal).
Proof.
by have [/algC_pfactorRE|/algC_pfactorCE] := boolP (_ \is _); rewrite ?mulr1.
Qed.
Lemma size_algC_pfactor x : size (algC_pfactor x) = (x \isn't Creal).+2.
Proof.
have [xR|xNR] := boolP (_ \is _); first by rewrite algC_pfactorRE// size_XsubC.
by rewrite algC_pfactorCE// size_mul ?size_XsubC ?polyXsubC_eq0.
Qed.
Lemma size_algR_pfactor x : size (algR_pfactor x) = (x \isn't Creal).+2.
Proof. by have := size_algC_pfactor x; rewrite size_map_poly. Qed.
Lemma algC_pfactor_eq0 x : (algC_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algC_pfactor. Qed.
Lemma algR_pfactor_eq0 x : (algR_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algR_pfactor. Qed.
Lemma algC_pfactorCgt0 x y : x \isn't Creal -> y \is Creal ->
(algC_pfactor x).[y] > 0.
Proof.
move=> xNR yR; rewrite algC_pfactorCE// hornerM !hornerXsubC.
rewrite [x]algCrect conjC_rect ?Creal_Re ?Creal_Im// !opprD !addrA opprK.
rewrite -subr_sqr exprMn sqrCi mulN1r opprK ltr_wpDl//.
- by rewrite real_exprn_even_ge0// ?rpredB// ?Creal_Re.
by rewrite real_exprn_even_gt0 ?Creal_Im ?orTb//=; apply/eqP/Creal_ImP.
Qed.
Lemma algR_pfactorR_mul_gt0 (x a b : algC) :
x \is Creal -> a \is Creal -> b \is Creal ->
a <= b ->
((algC_pfactor x).[a] * (algC_pfactor x).[b] <= 0) =
(a <= x <= b).
Proof.
move=> xR aR bR ab; rewrite !algC_pfactorRE// !hornerXsubC.
have [lt_xa|lt_ax|->]/= := real_ltgtP xR aR; last first.
- by rewrite subrr mul0r lexx ab.
- by rewrite nmulr_rle0 ?subr_lt0 ?subr_ge0.
rewrite pmulr_rle0 ?subr_gt0// subr_le0.
by apply: negbTE; rewrite -real_ltNge// (lt_le_trans lt_xa).
Qed.
Lemma monic_algC_pfactor x : algC_pfactor x \is monic.
Proof. by rewrite algC_pfactorE rpredM ?rpredX ?monicXsubC. Qed.
Lemma monic_algR_pfactor x : algR_pfactor x \is monic.
Proof. by have := monic_algC_pfactor x; rewrite map_monic. Qed.
Lemma poly_algR_pfactor (p : {poly algR}) :
{ r : seq algC |
p ^^ algRval = val (lead_coef p) *: \prod_(z <- r) algC_pfactor z }.
Proof.
wlog p_monic : p / p \is monic => [hwlog|].
have [->|pN0] := eqVneq p 0.
by exists [::]; rewrite lead_coef0/= rmorph0 scale0r.
have [|r] := hwlog ((lead_coef p)^-1 *: p).
by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0//.
rewrite !lead_coefZ mulVf ?lead_coef_eq0//= scale1r.
rewrite map_polyZ/= => /(canRL (scalerKV _))->; first by exists r.
by rewrite fmorph_eq0 lead_coef_eq0.
suff: {r : seq algC | p ^^ algRval = \prod_(z <- r) algC_pfactor z}.
by move=> [r rP]; exists r; rewrite rP (monicP _)// scale1r.
have [/= r pr] := closed_field_poly_normal (p ^^ algRval).
rewrite (monicP _) ?monic_map ?scale1r// {p_monic} in pr *.
have [n] := ubnP (size r).
elim: n r => // n IHn [|x r]/= in p pr *.
by exists [::]; rewrite pr !big_nil.
rewrite ltnS => r_lt.
have xJxr : x^* \in x :: r.
rewrite -root_prod_XsubC -pr.
have /eq_map_poly-> : algRval =1 Num.conj_op \o algRval.
by move=> a /=; rewrite (CrealP (algRvalP _)).
by rewrite map_poly_comp mapf_root pr root_prod_XsubC mem_head.
have xJr : (x \isn't Creal) ==> (x^* \in r) by rewrite implyNb CrealE.
have pxdvdC : algC_pfactor x %| p ^^ algRval.
rewrite pr algC_pfactorE big_cons/= dvdp_mul2l ?polyXsubC_eq0//.
by case: (_ \is _) xJr; rewrite ?dvd1p// dvdp_XsubCl root_prod_XsubC.
pose pr'x := p %/ algR_pfactor x.
have [||r'] := IHn (if x \is Creal then r else rem x^* r) pr'x; last 2 first.
- by case: (_ \is _) in xJr *; rewrite ?size_rem// (leq_ltn_trans (leq_pred _)).
- move=> /eqP; rewrite map_divp -dvdp_eq_mul ?algC_pfactor_eq0//= => /eqP->.
by exists (x :: r'); rewrite big_cons mulrC.
rewrite map_divp/= pr big_cons algC_pfactorE/=.
rewrite divp_pmul2l ?expf_neq0 ?polyXsubC_eq0//.
case: (_ \is _) => /= in xJr *; first by rewrite divp1//.
by rewrite (big_rem _ xJr)/= mulKp ?polyXsubC_eq0.
Qed.
Definition algR_rcfMixin : Num.real_closed_axiom algR.
Proof.
move=> p a b le_ab /andP[pa_le0 pb_ge0]/=.
case: ltgtP pa_le0 => //= pa0 _; last first.
by exists a; rewrite ?lexx// rootE pa0.
case: ltgtP pb_ge0 => //= pb0 _; last first.
by exists b; rewrite ?lexx ?andbT// rootE -pb0.
have p_neq0 : p != 0 by apply: contraTneq pa0 => ->; rewrite horner0 ltxx.
have {pa0 pb0} pab0 : p.[a] * p.[b] < 0 by rewrite pmulr_llt0.
wlog p_monic : p p_neq0 pab0 / p \is monic => [hwlog|].
have [|||x axb] := hwlog ((lead_coef p)^-1 *: p).
- by rewrite scaler_eq0 invr_eq0 lead_coef_eq0 (negPf p_neq0).
- rewrite !hornerE/= -mulrA mulrACA -expr2 pmulr_rlt0//.
by rewrite exprn_even_gt0//= invr_eq0 lead_coef_eq0.
- by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0 ?eqxx.
by rewrite rootZ ?invr_eq0 ?lead_coef_eq0//; exists x.
have /= [rs prs] := poly_algR_pfactor p.
rewrite (monicP _) ?monic_map// scale1r {p_monic} in prs.
pose ab := [pred x | val a <= x <= val b].
have abR : {subset ab <= Creal}.
move=> x /andP[+ _].
by rewrite -subr_ge0 => /ger0_real; rewrite rpredBr// algRvalP.
wlog : p pab0 {p_neq0 prs} /
p ^^ algRval = \prod_(x <- rs | x \in ab) ('X - x%:P) => [hw|].
move: prs; rewrite -!rmorph_prod => /map_poly_inj.
rewrite (bigID ab)/=; set q := (X in X * _); set u := (X in _ * X) => pqu.
have [||] := hw q; last first.
- by move=> x; exists x => //; rewrite pqu rootM q0.
- by rewrite rmorph_prod/=; under eq_bigr do rewrite algC_pfactorRE ?abR//.
have := pab0; rewrite pqu !hornerM mulrACA [_ * _ * _ < 0]pmulr_llt0//.
rewrite !horner_prod -big_split/= prodr_gt0// => x.
have [xR|xNR] := boolP (x \is Creal); last first.
rewrite (_ : (0 < ?[a]) = (algRval 0 < algRval ?a))//=.
by rewrite -!horner_map/= mulr_gt0 ?algC_pfactorCgt0 ?algRvalP.
apply: contraNT; rewrite -leNgt.
rewrite (_ : (?[a] <= 0) = (algRval ?a <= algRval 0))//= -!horner_map/=.
by rewrite algR_pfactorR_mul_gt0 ?algRvalP.
rewrite -big_filter; have := filter_all ab rs.
set rsab := filter _ _.
have: all (mem Creal) rsab.
by apply/allP => x; rewrite mem_filter => /andP[/abR].
case: rsab => [_ _|x rsab]/=; rewrite (big_nil, big_cons).
move=> pval1; move: pab0.
have /map_poly_inj-> : p ^^ algRval = 1 ^^ algRval by rewrite rmorph1.
by rewrite !hornerE ltr10.
move=> /andP[xR rsabR] /andP[axb arsb] prsab.
exists (in_algR xR) => //=.
by rewrite -(mapf_root algRval)//= prsab rootM root_XsubC eqxx.
Qed.
HB.instance Definition _ := Num.RealField_isClosed.Build algR algR_rcfMixin.
|
presentation.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq.
From mathcomp Require Import fintype finset fingroup morphism.
(******************************************************************************)
(* Support for generator-and-relation presentations of groups. We provide the *)
(* syntax: *)
(* G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is generated by elements x_1, ..., x_m satisfying the relations *)
(* s_1 = t_1, ..., s_m = t_m, i.e., G is a homomorphic image of the *)
(* group generated by the x_i, subject to the relations s_j = t_j. *)
(* G \isog Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) *)
(* <=> G is isomorphic to the largest finite factor of the group generated *)
(* by the x_i, subject to the relations s_j = t_j. In particular, *)
(* if the abstract group defined by the presentation is finite, *)
(* it means that G is actually isomorphic to it. This is an *)
(* intensional predicate (in Prop), as even the non-triviality of a *)
(* generated group is undecidable. *)
(* Syntax details: *)
(* - Grp is a literal constant. *)
(* - There must be at least one generator and one relation. *)
(* - A relation s_j = 1 can be abbreviated as simply s_j (a.k.a. a relator). *)
(* - Two consecutive relations s_j = t, s_j+1 = t can be abbreviated *)
(* s_j = s_j+1 = t. *)
(* - The s_j and t_j are terms built from the x_i and the standard group *)
(* operators *, 1, ^-1, ^+, ^-, ^, [~ u_1, ..., u_k]; no other operator or *)
(* abbreviation may be used, as the notation is implemented using static *)
(* overloading. *)
(* - This is the closest we could get to the notation used in Aschbacher, *)
(* Grp (x_1, ... x_n : t_1,1 = ... = t_1,k1, ..., t_m,1 = ... = t_m,km) *)
(* under the current limitations of the Coq Notation facility. *)
(* Semantics details: *)
(* - G \isog Grp (...) : Prop expands to the statement *)
(* forall rT (H : {group rT}), (H \homg G) = (H \homg Grp (...)) *)
(* (with rT : finGroupType). *)
(* - G \homg Grp (x_1 : ... x_n : s_1 = t_1, ..., s_m = t_m) : bool, with *)
(* G : {set gT}, is convertible to the boolean expression *)
(* [exists t : gT * ... gT, let: (x_1, ..., x_n) := t in *)
(* (<[x_1]> <*> ... <*> <[x_n]>, (s_1, ... (s_m-1, s_m) ...)) *)
(* == (G, (t_1, ... (t_m-1, t_m) ...))] *)
(* where the tuple comparison above is convertible to the conjunction *)
(* [&& <[x_1]> <*> ... <*> <[x_n]> == G, s_1 == t_1, ... & s_m == t_m] *)
(* Thus G \homg Grp (...) can be easily exploited by destructing the tuple *)
(* created case/existsP, then destructing the tuple equality with case/eqP. *)
(* Conversely it can be proved by using apply/existsP, providing the tuple *)
(* with a single exists (u_1, ..., u_n), then using rewrite !xpair_eqE /= *)
(* to expose the conjunction, and optionally using an apply/and{m+1}P view *)
(* to split it into subgoals (in that case, the rewrite is in principle *)
(* redundant, but necessary in practice because of the poor performance of *)
(* conversion in the Coq unifier). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Module Presentation.
Section Presentation.
Implicit Types gT rT : finGroupType.
Implicit Type vT : finType. (* tuple value type *)
Inductive term :=
| Cst of nat
| Idx
| Inv of term
| Exp of term & nat
| Mul of term & term
| Conj of term & term
| Comm of term & term.
Fixpoint eval {gT} e t : gT :=
match t with
| Cst i => nth 1 e i
| Idx => 1
| Inv t1 => (eval e t1)^-1
| Exp t1 n => eval e t1 ^+ n
| Mul t1 t2 => eval e t1 * eval e t2
| Conj t1 t2 => eval e t1 ^ eval e t2
| Comm t1 t2 => [~ eval e t1, eval e t2]
end.
Inductive formula := Eq2 of term & term | And of formula & formula.
Definition Eq1 s := Eq2 s Idx.
Definition Eq3 s1 s2 t := And (Eq2 s1 t) (Eq2 s2 t).
Inductive rel_type := NoRel | Rel vT of vT & vT.
Definition bool_of_rel r := if r is Rel vT v1 v2 then v1 == v2 else true.
Local Coercion bool_of_rel : rel_type >-> bool.
Definition and_rel vT (v1 v2 : vT) r :=
if r is Rel wT w1 w2 then Rel (v1, w1) (v2, w2) else Rel v1 v2.
Fixpoint rel {gT} (e : seq gT) f r :=
match f with
| Eq2 s t => and_rel (eval e s) (eval e t) r
| And f1 f2 => rel e f1 (rel e f2 r)
end.
Inductive type := Generator of term -> type | Formula of formula.
Definition Cast p : type := p. (* syntactic scope cast *)
Local Coercion Formula : formula >-> type.
Inductive env gT := Env of {set gT} & seq gT.
Definition env1 {gT} (x : gT : finType) := Env <[x]> [:: x].
Fixpoint sat gT vT B n (s : vT -> env gT) p :=
match p with
| Formula f =>
[exists v, let: Env A e := s v in and_rel A B (rel (rev e) f NoRel)]
| Generator p' =>
let s' v := let: Env A e := s v.1 in Env (A <*> <[v.2]>) (v.2 :: e) in
sat B n.+1 s' (p' (Cst n))
end.
Definition hom gT (B : {set gT}) p := sat B 1 env1 (p (Cst 0)).
Definition iso gT (B : {set gT}) p :=
forall rT (H : {group rT}), (H \homg B) = hom H p.
End Presentation.
End Presentation.
Import Presentation.
Coercion bool_of_rel : rel_type >-> bool.
Coercion Eq1 : term >-> formula.
Coercion Formula : formula >-> type.
Declare Custom Entry group_presentation.
Notation "x * y" := (Mul x y)
(in custom group_presentation at level 40, left associativity).
Notation "x ^+ n" := (Exp x n)
(in custom group_presentation at level 29, n constr at level 28).
Notation "x ^ y" := (Conj x y)
(in custom group_presentation at level 30, right associativity).
Notation "x ^-1" := (Inv x) (in custom group_presentation at level 3).
Notation "x ^- n" := (Inv (Exp x n))
(in custom group_presentation at level 29, n constr at level 28).
Notation "[ ~ x1 , x2 , .. , xn ]" := (Comm .. (Comm x1 x2) .. xn)
(in custom group_presentation, x1, x2, xn at level 100).
Notation "x = y" := (Eq2 x y) (in custom group_presentation at level 70).
Notation "x = y = z" := (Eq3 x y z) (in custom group_presentation at level 70,
y at next level).
Notation "r1 , r2 , .. , rn" := (And .. (And r1 r2) .. rn)
(in custom group_presentation at level 200).
Notation "( p )" := p (in custom group_presentation, p at level 200).
Notation "1" := Idx (in custom group_presentation).
Notation "x" := x (in custom group_presentation at level 0, x ident).
Notation "x : p" := (Generator (fun x => Cast p))
(in custom group_presentation, x ident, p custom group_presentation at level 200).
Arguments hom _ _%_group_scope.
Arguments iso _ _%_group_scope.
Notation "H \homg 'Grp' p" := (hom H p)
(p at level 0, format "H \homg 'Grp' p") : group_scope.
Notation "H \isog 'Grp' p" := (iso H p)
(p at level 0, format "H \isog 'Grp' p") : group_scope.
Notation "H \homg 'Grp' ( x : p )" := (hom H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \homg 'Grp' ( x : p ) ']'") : group_scope.
Notation "H \isog 'Grp' ( x : p )" := (iso H (fun x => Cast p))
(x ident, p custom group_presentation at level 200,
format "'[hv' H '/ ' \isog 'Grp' ( x : p ) ']'") : group_scope.
Section PresentationTheory.
Implicit Types gT rT : finGroupType.
Import Presentation.
Lemma isoGrp_hom gT (G : {group gT}) p : G \isog Grp p -> G \homg Grp p.
Proof. by move <-; apply: homg_refl. Qed.
Lemma isoGrpP gT (G : {group gT}) p rT (H : {group rT}) :
G \isog Grp p -> reflect (#|H| = #|G| /\ H \homg Grp p) (H \isog G).
Proof.
move=> isoGp; apply: (iffP idP) => [isoGH | [oH homHp]].
by rewrite (card_isog isoGH) -isoGp isog_hom.
by rewrite isogEcard isoGp homHp /= oH.
Qed.
Lemma homGrp_trans rT gT (H : {set rT}) (G : {group gT}) p :
H \homg G -> G \homg Grp p -> H \homg Grp p.
Proof.
case/homgP=> h <-{H}; rewrite /hom; move: {p}(p _) => p.
have evalG e t: all [in G] e -> eval (map h e) t = h (eval e t).
move=> Ge; apply: (@proj2 (eval e t \in G)); elim: t => /=.
- move=> i; case: (leqP (size e) i) => [le_e_i | lt_i_e].
by rewrite !nth_default ?size_map ?morph1.
by rewrite (nth_map 1) // [_ \in G](allP Ge) ?mem_nth.
- by rewrite morph1.
- by move=> t [Gt ->]; rewrite groupV morphV.
- by move=> t [Gt ->] n; rewrite groupX ?morphX.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupM ?morphM.
- by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupJ ?morphJ.
by move=> t1 [Gt1 ->] t2 [Gt2 ->]; rewrite groupR ?morphR.
have and_relE xT x1 x2 r: @and_rel xT x1 x2 r = (x1 == x2) && r :> bool.
by case: r => //=; rewrite andbT.
have rsatG e f: all [in G] e -> rel e f NoRel -> rel (map h e) f NoRel.
move=> Ge; have: NoRel -> NoRel by []; move: NoRel {2 4}NoRel.
elim: f => [x1 x2 | f1 IH1 f2 IH2] r hr IHr; last by apply: IH1; apply: IH2.
by rewrite !and_relE !evalG //; case/andP; move/eqP->; rewrite eqxx.
set s := env1; set vT := gT : finType in s *.
set s' := env1; set vT' := rT : finType in s' *.
have (v): let: Env A e := s v in
A \subset G -> all [in G] e /\ exists v', s' v' = Env (h @* A) (map h e).
- rewrite /= cycle_subG andbT => Gv; rewrite morphim_cycle //.
by split; last exists (h v).
elim: p 1%N vT vT' s s' => /= [p IHp | f] n vT vT' s s' Gs.
apply: IHp => [[v x]] /=; case: (s v) {Gs}(Gs v) => A e /= Gs.
rewrite join_subG cycle_subG; case/andP=> sAG Gx; rewrite Gx.
have [//|-> [v' def_v']] := Gs; split=> //; exists (v', h x); rewrite def_v'.
by congr (Env _ _); rewrite morphimY ?cycle_subG // morphim_cycle.
case/existsP=> v; case: (s v) {Gs}(Gs v) => /= A e Gs.
rewrite and_relE => /andP[/eqP defA rel_f].
have{Gs} [|Ge [v' def_v']] := Gs; first by rewrite defA.
apply/existsP; exists v'; rewrite def_v' and_relE defA eqxx /=.
by rewrite -map_rev rsatG ?(eq_all_r (mem_rev e)).
Qed.
Lemma eq_homGrp gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> (G \homg Grp p) = (H \homg Grp p).
Proof.
by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homGrp_trans.
Qed.
Lemma isoGrp_trans gT rT (G : {group gT}) (H : {group rT}) p :
G \isog H -> H \isog Grp p -> G \isog Grp p.
Proof. by move=> isoGH isoHp kT K; rewrite -isoHp; apply: eq_homgr. Qed.
Lemma intro_isoGrp gT (G : {group gT}) p :
G \homg Grp p -> (forall rT (H : {group rT}), H \homg Grp p -> H \homg G) ->
G \isog Grp p.
Proof.
move=> homGp freeG rT H.
by apply/idP/idP=> [homHp|]; [apply: homGrp_trans homGp | apply: freeG].
Qed.
End PresentationTheory.
|
gseries.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import fintype bigop finset fingroup morphism.
From mathcomp Require Import automorphism quotient action commutator center.
(******************************************************************************)
(* H <|<| G <=> H is subnormal in G, i.e., H <| ... <| G. *)
(* invariant_factor A H G <=> A normalises both H and G, and H <| G. *)
(* A.-invariant <=> the (invariant_factor A) relation, in the context *)
(* of the g_rel.-series notation. *)
(* g_rel.-series H s <=> H :: s is a sequence of groups whose projection *)
(* to sets satisfies relation g_rel pairwise; for *)
(* example H <|<| G iff G = last H s for some s such *)
(* that normal.-series H s. *)
(* stable_factor A H G == H <| G and A centralises G / H. *)
(* A.-stable == the stable_factor relation, in the scope of the *)
(* r.-series notation. *)
(* G.-central == the central_factor relation, in the scope of the *)
(* r.-series notation. *)
(* maximal M G == M is a maximal proper subgroup of G. *)
(* maximal_eq M G == (M == G) or (maximal M G). *)
(* maxnormal M G N == M is a maximal subgroup of G normalized by N. *)
(* minnormal M N == M is a minimal nontrivial group normalized by N. *)
(* simple G == G is a (nontrivial) simple group. *)
(* := minnormal G G *)
(* G.-chief == the chief_factor relation, in the scope of the *)
(* r.-series notation. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope group_rel_scope.
Import GroupScope.
Section GroupDefs.
Variable gT : finGroupType.
Implicit Types A B U V : {set gT}.
Local Notation groupT := (group_of gT).
Definition subnormal A B :=
(A \subset B) && (iter #|B| (fun N => generated (class_support A N)) B == A).
Definition invariant_factor A B C :=
[&& A \subset 'N(B), A \subset 'N(C) & B <| C].
Definition group_rel_of (r : rel {set gT}) := [rel H G : groupT | r H G].
Definition stable_factor A V U :=
([~: U, A] \subset V) && (V <| U). (* this orders allows and3P to be used *)
Definition central_factor A V U :=
[&& [~: U, A] \subset V, V \subset U & U \subset A].
Definition maximal A B := [max A of G | G \proper B].
Definition maximal_eq A B := (A == B) || maximal A B.
Definition maxnormal A B U := [max A of G | G \proper B & U \subset 'N(G)].
Definition minnormal A B := [min A of G | G :!=: 1 & B \subset 'N(G)].
Definition simple A := minnormal A A.
Definition chief_factor A V U := maxnormal V U A && (U <| A).
End GroupDefs.
Arguments subnormal {gT} A%_g B%_g.
Arguments invariant_factor {gT} A%_g B%_g C%_g.
Arguments stable_factor {gT} A%_g V%_g U%_g.
Arguments central_factor {gT} A%_g V%_g U%_g.
Arguments maximal {gT} A%_g B%_g.
Arguments maximal_eq {gT} A%_g B%_g.
Arguments maxnormal {gT} A%_g B%_g U%_g.
Arguments minnormal {gT} A%_g B%_g.
Arguments simple {gT} A%_g.
Arguments chief_factor {gT} A%_g V%_g U%_g.
Notation "H <|<| G" := (subnormal H G)
(at level 70, no associativity) : group_scope.
Notation "A .-invariant" := (invariant_factor A)
(format "A .-invariant") : group_rel_scope.
Notation "A .-stable" := (stable_factor A)
(format "A .-stable") : group_rel_scope.
Notation "A .-central" := (central_factor A)
(format "A .-central") : group_rel_scope.
Notation "G .-chief" := (chief_factor G)
(format "G .-chief") : group_rel_scope.
Arguments group_rel_of {gT} r%_group_rel_scope _%_G _%_G : extra scopes.
Notation "r .-series" := (path (rel_of_simpl (group_rel_of r)))
(format "r .-series") : group_scope.
Section Subnormal.
Variable gT : finGroupType.
Implicit Types (A B C D : {set gT}) (G H K : {group gT}).
Let setIgr H G := (G :&: H)%G.
Let sub_setIgr G H : G \subset H -> G = setIgr H G.
Proof. by move/setIidPl/group_inj. Qed.
Let path_setIgr H G s :
normal.-series H s -> normal.-series (setIgr G H) (map (setIgr G) s).
Proof.
elim: s H => //= K s IHs H /andP[/andP[sHK nHK] Ksn].
by rewrite /normal setSI ?normsIG ?IHs.
Qed.
Lemma subnormalP H G :
reflect (exists2 s, normal.-series H s & last H s = G) (H <|<| G).
Proof.
apply: (iffP andP) => [[sHG snHG] | [s Hsn <-{G}]].
move: #|G| snHG => m; elim: m => [|m IHm] in G sHG *.
by exists [::]; last by apply/eqP; rewrite eq_sym.
rewrite iterSr => /IHm[|s Hsn defG].
by rewrite sub_gen // class_supportEr (bigD1 1) //= conjsg1 subsetUl.
exists (rcons s G); rewrite ?last_rcons // -cats1 cat_path Hsn defG /=.
rewrite /normal gen_subG class_support_subG //=.
by rewrite norms_gen ?class_support_norm.
set f := fun _ => <<_>>; have idf: iter _ f H == H.
by elim=> //= m IHm; rewrite (eqP IHm) /f class_support_id genGid.
have [m] := ubnP (size s); elim: m s Hsn => // m IHm /lastP[//|s G].
rewrite size_rcons last_rcons rcons_path /= ltnS.
set K := last H s => /andP[Hsn /andP[sKG nKG]] lt_s_m.
have /[1!subEproper]/predU1P[<-|prKG] := sKG; first exact: IHm.
pose L := [group of f G].
have sHK: H \subset K by case/IHm: Hsn.
have sLK: L \subset K by rewrite gen_subG class_support_sub_norm.
rewrite -(subnK (proper_card (sub_proper_trans sLK prKG))) iterD iterSr.
have defH: H = setIgr L H by rewrite -sub_setIgr ?sub_gen ?sub_class_support.
have: normal.-series H (map (setIgr L) s) by rewrite defH path_setIgr.
case/IHm=> [|_]; first by rewrite size_map.
rewrite [in last _]defH last_map (subset_trans sHK) //=.
by rewrite (setIidPr sLK) => /eqP->.
Qed.
Lemma subnormal_refl G : G <|<| G.
Proof. by apply/subnormalP; exists [::]. Qed.
Lemma subnormal_trans K H G : H <|<| K -> K <|<| G -> H <|<| G.
Proof.
case/subnormalP=> [s1 Hs1 <-] /subnormalP[s2 Hs12 <-].
by apply/subnormalP; exists (s1 ++ s2); rewrite ?last_cat // cat_path Hs1.
Qed.
Lemma normal_subnormal H G : H <| G -> H <|<| G.
Proof. by move=> nsHG; apply/subnormalP; exists [:: G]; rewrite //= nsHG. Qed.
Lemma setI_subnormal G H K : K \subset G -> H <|<| G -> H :&: K <|<| K.
Proof.
move=> sKG /subnormalP[s Hs defG]; apply/subnormalP.
exists (map (setIgr K) s); first exact: path_setIgr.
rewrite (last_map (setIgr K)) defG.
by apply: val_inj; rewrite /= (setIidPr sKG).
Qed.
Lemma subnormal_sub G H : H <|<| G -> H \subset G.
Proof. by case/andP. Qed.
Lemma invariant_subnormal A G H :
A \subset 'N(G) -> A \subset 'N(H) -> H <|<| G ->
exists2 s, (A.-invariant).-series H s & last H s = G.
Proof.
move=> nGA nHA /andP[]; move: #|G| => m.
elim: m => [|m IHm] in G nGA * => sHG.
by rewrite eq_sym; exists [::]; last apply/eqP.
rewrite iterSr; set K := <<_>>.
have nKA: A \subset 'N(K) by rewrite norms_gen ?norms_class_support.
have sHK: H \subset K by rewrite sub_gen ?sub_class_support.
case/IHm=> // s Hsn defK; exists (rcons s G); last by rewrite last_rcons.
rewrite rcons_path Hsn !andbA defK nGA nKA /= -/K.
by rewrite gen_subG class_support_subG ?norms_gen ?class_support_norm.
Qed.
Lemma subnormalEsupport G H :
H <|<| G -> H :=: G \/ <<class_support H G>> \proper G.
Proof.
case/andP=> sHG; set K := <<_>> => /eqP <-.
have: K \subset G by rewrite gen_subG class_support_subG.
rewrite subEproper; case/predU1P=> [defK|]; [left | by right].
by elim: #|G| => //= _ ->.
Qed.
Lemma subnormalEr G H : H <|<| G ->
H :=: G \/ (exists K : {group gT}, [/\ H <|<| K, K <| G & K \proper G]).
Proof.
case/subnormalP=> s Hs <-{G}.
elim/last_ind: s Hs => [|s G IHs]; first by left.
rewrite last_rcons -cats1 cat_path /= andbT; set K := last H s.
case/andP=> Hs nsKG; have /[1!subEproper] := normal_sub nsKG.
case/predU1P=> [<- | prKG]; [exact: IHs | right; exists K; split=> //].
by apply/subnormalP; exists s.
Qed.
Lemma subnormalEl G H : H <|<| G ->
H :=: G \/ (exists K : {group gT}, [/\ H <| K, K <|<| G & H \proper K]).
Proof.
case/subnormalP=> s Hs <-{G}; elim: s H Hs => /= [|K s IHs] H; first by left.
case/andP=> nsHK Ks; have /[1!subEproper] := normal_sub nsHK.
case/predU1P=> [-> | prHK]; [exact: IHs | right; exists K; split=> //].
by apply/subnormalP; exists s.
Qed.
End Subnormal.
Arguments subnormalP {gT H G}.
Section MorphSubNormal.
Variable gT : finGroupType.
Implicit Type G H K : {group gT}.
Lemma morphim_subnormal (rT : finGroupType) G (f : {morphism G >-> rT}) H K :
H <|<| K -> f @* H <|<| f @* K.
Proof.
case/subnormalP => s Hs <-{K}; apply/subnormalP.
elim: s H Hs => [|K s IHs] H /=; first by exists [::].
case/andP=> nsHK /IHs[fs Hfs <-].
by exists ([group of f @* K] :: fs); rewrite /= ?morphim_normal.
Qed.
Lemma quotient_subnormal H G K : G <|<| K -> G / H <|<| K / H.
Proof. exact: morphim_subnormal. Qed.
End MorphSubNormal.
Section MaxProps.
Variable gT : finGroupType.
Implicit Types G H M : {group gT}.
Lemma maximal_eqP M G :
reflect (M \subset G /\
forall H, M \subset H -> H \subset G -> H :=: M \/ H :=: G)
(maximal_eq M G).
Proof.
rewrite subEproper /maximal_eq; case: eqP => [->|_]; first left.
by split=> // H sGH sHG; right; apply/eqP; rewrite eqEsubset sHG.
apply: (iffP maxgroupP) => [] [sMG maxM]; split=> // H.
by move/maxM=> maxMH; rewrite subEproper; case/predU1P; auto.
by rewrite properEneq => /andP[/eqP neHG sHG] /maxM[].
Qed.
Lemma maximal_exists H G :
H \subset G ->
H :=: G \/ (exists2 M : {group gT}, maximal M G & H \subset M).
Proof.
rewrite subEproper; case/predU1P=> sHG; first by left.
suff [M *]: {M : {group gT} | maximal M G & H \subset M} by right; exists M.
exact: maxgroup_exists.
Qed.
Lemma mulg_normal_maximal G M H :
M <| G -> maximal M G -> H \subset G -> ~~ (H \subset M) -> (M * H = G)%g.
Proof.
case/andP=> sMG nMG /maxgroupP[_ maxM] sHG not_sHM.
apply/eqP; rewrite eqEproper mul_subG // -norm_joinEr ?(subset_trans sHG) //.
by apply: contra not_sHM => /maxM <-; rewrite ?joing_subl ?joing_subr.
Qed.
End MaxProps.
Section MinProps.
Variable gT : finGroupType.
Implicit Types G H M : {group gT}.
Lemma minnormal_exists G H : H :!=: 1 -> G \subset 'N(H) ->
{M : {group gT} | minnormal M G & M \subset H}.
Proof. by move=> ntH nHG; apply: mingroup_exists (H) _; rewrite ntH. Qed.
End MinProps.
Section MorphPreMax.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variables (M G : {group rT}).
Hypotheses (dM : M \subset f @* D) (dG : G \subset f @* D).
Lemma morphpre_maximal : maximal (f @*^-1 M) (f @*^-1 G) = maximal M G.
Proof.
apply/maxgroupP/maxgroupP; rewrite morphpre_proper //= => [] [ltMG maxM].
split=> // H ltHG sMH; have dH := subset_trans (proper_sub ltHG) dG.
rewrite -(morphpreK dH) [f @*^-1 H]maxM ?morphpreK ?morphpreSK //.
by rewrite morphpre_proper.
split=> // H ltHG sMH.
have dH: H \subset D := subset_trans (proper_sub ltHG) (subsetIl D _).
have defH: f @*^-1 (f @* H) = H.
by apply: morphimGK dH; apply: subset_trans sMH; apply: ker_sub_pre.
rewrite -defH morphpre_proper ?morphimS // in ltHG.
by rewrite -defH [f @* H]maxM // -(morphpreK dM) morphimS.
Qed.
Lemma morphpre_maximal_eq : maximal_eq (f @*^-1 M) (f @*^-1 G) = maximal_eq M G.
Proof. by rewrite /maximal_eq morphpre_maximal !eqEsubset !morphpreSK. Qed.
End MorphPreMax.
Section InjmMax.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variables M G L : {group gT}.
Hypothesis injf : 'injm f.
Hypotheses (dM : M \subset D) (dG : G \subset D) (dL : L \subset D).
Lemma injm_maximal : maximal (f @* M) (f @* G) = maximal M G.
Proof.
rewrite -(morphpre_invm injf) -(morphpre_invm injf G).
by rewrite morphpre_maximal ?morphim_invm.
Qed.
Lemma injm_maximal_eq : maximal_eq (f @* M) (f @* G) = maximal_eq M G.
Proof. by rewrite /maximal_eq injm_maximal // injm_eq. Qed.
Lemma injm_maxnormal : maxnormal (f @* M) (f @* G) (f @* L) = maxnormal M G L.
Proof.
pose injfm := (injm_proper injf, injm_norms, injmSK injf, subsetIl).
apply/maxgroupP/maxgroupP; rewrite !injfm // => [[nML maxM]].
split=> // H nHL sMH; have [/proper_sub sHG _] := andP nHL.
have dH := subset_trans sHG dG; apply: (injm_morphim_inj injf) => //.
by apply: maxM; rewrite !injfm.
split=> // fH nHL sMH; have [/proper_sub sfHG _] := andP nHL.
have{sfHG} dfH: fH \subset f @* D := subset_trans sfHG (morphim_sub f G).
by rewrite -(morphpreK dfH) !injfm // in nHL sMH *; rewrite (maxM _ nHL).
Qed.
Lemma injm_minnormal : minnormal (f @* M) (f @* G) = minnormal M G.
Proof.
pose injfm := (morphim_injm_eq1 injf, injm_norms, injmSK injf, subsetIl).
apply/mingroupP/mingroupP; rewrite !injfm // => [[nML minM]].
split=> // H nHG sHM; have dH := subset_trans sHM dM.
by apply: (injm_morphim_inj injf) => //; apply: minM; rewrite !injfm.
split=> // fH nHG sHM; have dfH := subset_trans sHM (morphim_sub f M).
by rewrite -(morphpreK dfH) !injfm // in nHG sHM *; rewrite (minM _ nHG).
Qed.
End InjmMax.
Section QuoMax.
Variables (gT : finGroupType) (K G H : {group gT}).
Lemma cosetpre_maximal (Q R : {group coset_of K}) :
maximal (coset K @*^-1 Q) (coset K @*^-1 R) = maximal Q R.
Proof. by rewrite morphpre_maximal ?sub_im_coset. Qed.
Lemma cosetpre_maximal_eq (Q R : {group coset_of K}) :
maximal_eq (coset K @*^-1 Q) (coset K @*^-1 R) = maximal_eq Q R.
Proof. by rewrite /maximal_eq !eqEsubset !cosetpreSK cosetpre_maximal. Qed.
Lemma quotient_maximal :
K <| G -> K <| H -> maximal (G / K) (H / K) = maximal G H.
Proof. by move=> nKG nKH; rewrite -cosetpre_maximal ?quotientGK. Qed.
Lemma quotient_maximal_eq :
K <| G -> K <| H -> maximal_eq (G / K) (H / K) = maximal_eq G H.
Proof. by move=> nKG nKH; rewrite -cosetpre_maximal_eq ?quotientGK. Qed.
Lemma maximalJ x : maximal (G :^ x) (H :^ x) = maximal G H.
Proof.
rewrite -{1}(setTI G) -{1}(setTI H) -!morphim_conj.
by rewrite injm_maximal ?subsetT ?injm_conj.
Qed.
Lemma maximal_eqJ x : maximal_eq (G :^ x) (H :^ x) = maximal_eq G H.
Proof. by rewrite /maximal_eq !eqEsubset !conjSg maximalJ. Qed.
End QuoMax.
Section MaxNormalProps.
Variables (gT : finGroupType).
Implicit Types (A B C : {set gT}) (G H K L M : {group gT}).
Lemma maxnormal_normal A B : maxnormal A B B -> A <| B.
Proof.
by case/maxsetP=> /and3P[/gen_set_id /= -> pAB nAB]; rewrite /normal proper_sub.
Qed.
Lemma maxnormal_proper A B C : maxnormal A B C -> A \proper B.
Proof.
by case/maxsetP=> /and3P[gA pAB _] _; apply: (sub_proper_trans (subset_gen A)).
Qed.
Lemma maxnormal_sub A B C : maxnormal A B C -> A \subset B.
Proof.
by move=> maxA; rewrite proper_sub //; apply: (maxnormal_proper maxA).
Qed.
Lemma ex_maxnormal_ntrivg G : G :!=: 1-> {N : {group gT} | maxnormal N G G}.
Proof.
move=> ntG; apply: ex_maxgroup; exists [1 gT]%G; rewrite norm1 proper1G.
by rewrite subsetT ntG.
Qed.
Lemma maxnormalM G H K :
maxnormal H G G -> maxnormal K G G -> H :<>: K -> H * K = G.
Proof.
move=> maxH maxK /eqP; apply: contraNeq => ltHK_G.
have [nsHG nsKG] := (maxnormal_normal maxH, maxnormal_normal maxK).
have cHK: commute H K.
exact: normC (subset_trans (normal_sub nsHG) (normal_norm nsKG)).
wlog suffices: H K {maxH} maxK nsHG nsKG cHK ltHK_G / H \subset K.
by move=> IH; rewrite eqEsubset !IH // -cHK.
have{maxK} /maxgroupP[_ maxK] := maxK.
apply/joing_idPr/maxK; rewrite ?joing_subr //= comm_joingE //.
by rewrite properEneq ltHK_G; apply: normalM.
Qed.
Lemma maxnormal_minnormal G L M :
G \subset 'N(M) -> L \subset 'N(G) -> maxnormal M G L ->
minnormal (G / M) (L / M).
Proof.
move=> nMG nGL /maxgroupP[/andP[/andP[sMG ltMG] nML] maxM]; apply/mingroupP.
rewrite -subG1 quotient_sub1 ?ltMG ?quotient_norms //.
split=> // Hb /andP[ntHb nHbL]; have nsMG: M <| G by apply/andP.
case/inv_quotientS=> // H defHb sMH sHG; rewrite defHb; congr (_ / M).
apply/eqP; rewrite eqEproper sHG /=; apply: contra ntHb => ltHG.
have nsMH: M <| H := normalS sMH sHG nsMG.
rewrite defHb quotientS1 // (maxM H) // ltHG /= -(quotientGK nsMH) -defHb.
exact: norm_quotient_pre.
Qed.
Lemma minnormal_maxnormal G L M :
M <| G -> L \subset 'N(M) -> minnormal (G / M) (L / M) -> maxnormal M G L.
Proof.
case/andP=> sMG nMG nML /mingroupP[/andP[/= ntGM _] minGM]; apply/maxgroupP.
split=> [|H /andP[/andP[sHG ltHG] nHL] sMH].
by rewrite /proper sMG nML andbT; apply: contra ntGM => /quotientS1 ->.
apply/eqP; rewrite eqEsubset sMH andbT -quotient_sub1 ?(subset_trans sHG) //.
rewrite subG1; apply: contraR ltHG => ntHM; rewrite -(quotientSGK nMG) //.
by rewrite (minGM (H / M)%G) ?quotientS // ntHM quotient_norms.
Qed.
End MaxNormalProps.
Section Simple.
Implicit Types gT rT : finGroupType.
Lemma simpleP gT (G : {group gT}) :
reflect (G :!=: 1 /\ forall H : {group gT}, H <| G -> H :=: 1 \/ H :=: G)
(simple G).
Proof.
apply: (iffP mingroupP); rewrite normG andbT => [[ntG simG]].
split=> // N /andP[sNG nNG].
by case: (eqsVneq N 1) => [|ntN]; [left | right; apply: simG; rewrite ?ntN].
split=> // N /andP[ntN nNG] sNG.
by case: (simG N) ntN => // [|->]; [apply/andP | case/eqP].
Qed.
Lemma quotient_simple gT (G H : {group gT}) :
H <| G -> simple (G / H) = maxnormal H G G.
Proof.
move=> nsHG; have nGH := normal_norm nsHG.
by apply/idP/idP; [apply: minnormal_maxnormal | apply: maxnormal_minnormal].
Qed.
Lemma isog_simple gT rT (G : {group gT}) (M : {group rT}) :
G \isog M -> simple G = simple M.
Proof.
move=> eqGM; wlog suffices: gT rT G M eqGM / simple M -> simple G.
by move=> IH; apply/idP/idP; apply: IH; rewrite // isog_sym.
case/isogP: eqGM => f injf <- /simpleP[ntGf simGf].
apply/simpleP; split=> [|N nsNG]; first by rewrite -(morphim_injm_eq1 injf).
rewrite -(morphim_invm injf (normal_sub nsNG)).
have: f @* N <| f @* G by rewrite morphim_normal.
by case/simGf=> /= ->; [left | right]; rewrite (morphim1, morphim_invm).
Qed.
Lemma simple_maxnormal gT (G : {group gT}) : simple G = maxnormal 1 G G.
Proof.
by rewrite -quotient_simple ?normal1 // -(isog_simple (quotient1_isog G)).
Qed.
End Simple.
Section Chiefs.
Variable gT : finGroupType.
Implicit Types G H U V : {group gT}.
Lemma chief_factor_minnormal G V U :
chief_factor G V U -> minnormal (U / V) (G / V).
Proof.
case/andP=> maxV /andP[sUG nUG]; apply: maxnormal_minnormal => //.
by have /andP[_ nVG] := maxgroupp maxV; apply: subset_trans sUG nVG.
Qed.
Lemma acts_irrQ G U V :
G \subset 'N(V) -> V <| U ->
acts_irreducibly G (U / V) 'Q = minnormal (U / V) (G / V).
Proof.
move=> nVG nsVU; apply/mingroupP/mingroupP; case=> /andP[->] /=.
rewrite astabsQ // subsetI nVG /= => nUG minUV.
rewrite quotient_norms //; split=> // H /andP[ntH nHG] sHU.
by apply: minUV (sHU); rewrite ntH -(cosetpreK H) actsQ // norm_quotient_pre.
rewrite sub_quotient_pre // => nUG minU; rewrite astabsQ //.
rewrite (subset_trans nUG); last first.
by rewrite subsetI subsetIl /= -{2}(quotientGK nsVU) morphpre_norm.
split=> // H /andP[ntH nHG] sHU.
rewrite -{1}(cosetpreK H) astabsQ ?normal_cosetpre ?subsetI ?nVG //= in nHG.
apply: minU sHU; rewrite ntH; apply: subset_trans (quotientS _ nHG) _.
by rewrite -{2}(cosetpreK H) quotient_norm.
Qed.
Lemma chief_series_exists H G :
H <| G -> {s | (G.-chief).-series 1%G s & last 1%G s = H}.
Proof.
have [m] := ubnP #|H|; elim: m H => // m IHm U leUm nsUG.
have [-> | ntU] := eqVneq U 1%G; first by exists [::].
have [V maxV]: {V : {group gT} | maxnormal V U G}.
by apply: ex_maxgroup; exists 1%G; rewrite proper1G ntU norms1.
have /andP[ltVU nVG] := maxgroupp maxV.
have [||s ch_s defV] := IHm V; first exact: leq_trans (proper_card ltVU) _.
by rewrite /normal (subset_trans (proper_sub ltVU) (normal_sub nsUG)).
exists (rcons s U); last by rewrite last_rcons.
by rewrite rcons_path defV /= ch_s /chief_factor; apply/and3P.
Qed.
End Chiefs.
Section Central.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types H K : {group gT}.
Lemma central_factor_central H K :
central_factor G H K -> (K / H) \subset 'Z(G / H).
Proof. by case/and3P=> /quotient_cents2r *; rewrite subsetI quotientS. Qed.
Lemma central_central_factor H K :
(K / H) \subset 'Z(G / H) -> H <| K -> H <| G -> central_factor G H K.
Proof.
case/subsetIP=> sKGb cGKb /andP[sHK nHK] /andP[sHG nHG].
by rewrite /central_factor -quotient_cents2 // cGKb sHK -(quotientSGK nHK).
Qed.
End Central.
|
CodiscreteCategory.lean
|
/-
Copyright (c) 2024 Alvaro Belmonte. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alvaro Belmonte, Joël Riou
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Pi.Basic
import Mathlib.Data.ULift
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Adjunction.Basic
/-!
# Codiscrete categories
We define `Codiscrete A` as an alias for the type `A` ,
and use this type alias to provide a `Category` instance
whose Hom type are Unit types.
`Codiscrete.functor` promotes a function `f : C → A` (for any category `C`) to a functor
`f : C ⥤ Codiscrete A`.
Similarly, `Codiscrete.natTrans` and `Codiscrete.natIso` promote `I`-indexed families of morphisms,
or `I`-indexed families of isomorphisms to natural transformations or natural isomorphism.
We define `functorToCat : Type u ⥤ Cat.{0,u}` which sends a type to the codiscrete category and show
it is right adjoint to `Cat.objects.`
-/
namespace CategoryTheory
universe u v w
-- This is intentionally a structure rather than a type synonym
-- to enforce using `CodiscreteEquiv` (or `Codiscrete.mk` and `Codiscrete.as`) to move between
-- `Codiscrete α` and `α`. Otherwise there is too much API leakage.
/-- A wrapper for promoting any type to a category,
with a unique morphisms between any two objects of the category.
-/
@[ext, aesop safe cases (rule_sets := [CategoryTheory])]
structure Codiscrete (α : Type u) where
/-- A wrapper for promoting any type to a category,
with a unique morphisms between any two objects of the category. -/
as : α
@[simp]
theorem Codiscrete.mk_as {α : Type u} (X : Codiscrete α) : Codiscrete.mk X.as = X := rfl
/-- `Codiscrete α` is equivalent to the original type `α`. -/
@[simps]
def codiscreteEquiv {α : Type u} : Codiscrete α ≃ α where
toFun := Codiscrete.as
invFun := Codiscrete.mk
left_inv := by cat_disch
right_inv := by cat_disch
instance {α : Type u} [DecidableEq α] : DecidableEq (Codiscrete α) :=
codiscreteEquiv.decidableEq
namespace Codiscrete
instance (A : Type*) : Category (Codiscrete A) where
Hom _ _ := Unit
id _ := ⟨⟩
comp _ _ := ⟨⟩
section
variable {C : Type u} [Category.{v} C] {A : Type w}
/-- Any function `C → A` lifts to a functor `C ⥤ Codiscrete A`. -/
def functor (F : C → A) : C ⥤ Codiscrete A where
obj := Codiscrete.mk ∘ F
map _ := ⟨⟩
/-- The underlying function `C → A` of a functor `C ⥤ Codiscrete A`. -/
def invFunctor (F : C ⥤ Codiscrete A) : C → A := Codiscrete.as ∘ F.obj
/-- Given two functors to a codiscrete category, there is a trivial natural transformation. -/
def natTrans {F G : C ⥤ Codiscrete A} : F ⟶ G where
app _ := ⟨⟩
/-- Given two functors into a codiscrete category, the trivial natural transformation is an
natural isomorphism. -/
def natIso {F G : C ⥤ Codiscrete A} : F ≅ G where
hom := natTrans
inv := natTrans
/-- Every functor `F` to a codiscrete category is naturally isomorphic {(actually, equal)} to
`Codiscrete.as ∘ F.obj`. -/
@[simps!]
def natIsoFunctor {F : C ⥤ Codiscrete A} : F ≅ functor (Codiscrete.as ∘ F.obj) := Iso.refl _
end
/-- A function induces a functor between codiscrete categories. -/
def functorOfFun {A B : Type*} (f : A → B) : Codiscrete A ⥤ Codiscrete B :=
functor (f ∘ Codiscrete.as)
open Opposite
/-- A codiscrete category is equivalent to its opposite category. -/
def oppositeEquivalence (A : Type*) : (Codiscrete A)ᵒᵖ ≌ Codiscrete A where
functor := functor (fun x ↦ Codiscrete.as x.unop)
inverse := (functor (fun x ↦ Codiscrete.as x.unop)).rightOp
unitIso := NatIso.ofComponents (fun _ => by exact Iso.refl _)
counitIso := natIso
/-- `Codiscrete.functorToCat` turns a type into a codiscrete category. -/
def functorToCat : Type u ⥤ Cat.{0,u} where
obj A := Cat.of (Codiscrete A)
map := functorOfFun
open Adjunction Cat
/-- For a category `C` and type `A`, there is an equivalence between functions `objects.obj C ⟶ A`
and functors `C ⥤ Codiscrete A`. -/
def equivFunctorToCodiscrete {C : Type u} [Category.{v} C] {A : Type w} :
(C → A) ≃ (C ⥤ Codiscrete A) where
toFun := functor
invFun := invFunctor
/-- The functor that turns a type into a codiscrete category is right adjoint to the objects
functor. -/
def adj : objects ⊣ functorToCat := mkOfHomEquiv {
homEquiv := fun _ _ => equivFunctorToCodiscrete
homEquiv_naturality_left_symm := fun _ _ => rfl
homEquiv_naturality_right := fun _ _ => rfl }
/-- Components of the unit of the adjunction `Cat.objects ⊣ Codiscrete.functorToCat`. -/
def unitApp (C : Type u) [Category.{v} C] : C ⥤ Codiscrete C := functor id
/-- Components of the counit of the adjunction `Cat.objects ⊣ Codiscrete.functorToCat` -/
def counitApp (A : Type u) : Codiscrete A → A := Codiscrete.as
lemma adj_unit_app (X : Cat.{0, u}) :
adj.unit.app X = unitApp X := rfl
lemma adj_counit_app (A : Type u) :
adj.counit.app A = counitApp A := rfl
/-- Left triangle equality of the adjunction `Cat.objects ⊣ Codiscrete.functorToCat`,
as a universe polymorphic statement. -/
lemma left_triangle_components (C : Type u) [Category.{v} C] :
(counitApp C).comp (unitApp C).obj = id :=
rfl
/-- Right triangle equality of the adjunction `Cat.objects ⊣ Codiscrete.functorToCat`,
stated using a composition of functors. -/
lemma right_triangle_components (X : Type u) :
unitApp (Codiscrete X) ⋙ functorOfFun (counitApp X) = 𝟭 (Codiscrete X) :=
rfl
end Codiscrete
end CategoryTheory
|
MixedCharZero.lean
|
/-
Copyright (c) 2022 Jon Eugster. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Eugster
-/
import Mathlib.Algebra.CharP.LocalRing
import Mathlib.RingTheory.Ideal.Quotient.Basic
import Mathlib.Tactic.FieldSimp
/-!
# Equal and mixed characteristic
In commutative algebra, some statements are simpler when working over a `ℚ`-algebra `R`, in which
case one also says that the ring has "equal characteristic zero". A ring that is not a
`ℚ`-algebra has either positive characteristic or there exists a prime ideal `I ⊂ R` such that
the quotient `R ⧸ I` has positive characteristic `p > 0`. In this case one speaks of
"mixed characteristic `(0, p)`", where `p` is only unique if `R` is local.
Examples of mixed characteristic rings are `ℤ` or the `p`-adic integers/numbers.
This file provides the main theorem `split_by_characteristic` that splits any proposition `P` into
the following three cases:
1) Positive characteristic: `CharP R p` (where `p ≠ 0`)
2) Equal characteristic zero: `Algebra ℚ R`
3) Mixed characteristic: `MixedCharZero R p` (where `p` is prime)
## Main definitions
- `MixedCharZero` : A ring has mixed characteristic `(0, p)` if it has characteristic zero
and there exists an ideal such that the quotient `R ⧸ I` has characteristic `p`.
## Main results
- `split_equalCharZero_mixedCharZero` : Split a statement into equal/mixed characteristic zero.
This main theorem has the following three corollaries which include the positive
characteristic case for convenience:
- `split_by_characteristic` : Generally consider positive char `p ≠ 0`.
- `split_by_characteristic_domain` : In a domain we can assume that `p` is prime.
- `split_by_characteristic_localRing` : In a local ring we can assume that `p` is a prime power.
## Implementation Notes
We use the terms `EqualCharZero` and `AlgebraRat` despite not being such definitions in mathlib.
The former refers to the statement `∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)`, the latter
refers to the existence of an instance `[Algebra ℚ R]`. The two are shown to be
equivalent conditions.
## TODO
- Relate mixed characteristic in a local ring to p-adic numbers [NumberTheory.PAdics].
-/
variable (R : Type*) [CommRing R]
/-!
### Mixed characteristic
-/
/--
A ring of characteristic zero is of "mixed characteristic `(0, p)`" if there exists an ideal
such that the quotient `R ⧸ I` has characteristic `p`.
**Remark:** For `p = 0`, `MixedChar R 0` is a meaningless definition (i.e. satisfied by any ring)
as `R ⧸ ⊥ ≅ R` has by definition always characteristic zero.
One could require `(I ≠ ⊥)` in the definition, but then `MixedChar R 0` would mean something
like `ℤ`-algebra of extension degree `≥ 1` and would be completely independent from
whether something is a `ℚ`-algebra or not (e.g. `ℚ[X]` would satisfy it but `ℚ` wouldn't).
-/
class MixedCharZero (p : ℕ) : Prop where
[toCharZero : CharZero R]
charP_quotient : ∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p
namespace MixedCharZero
/--
Reduction to `p` prime: When proving any statement `P` about mixed characteristic rings we
can always assume that `p` is prime.
-/
theorem reduce_to_p_prime {P : Prop} :
(∀ p > 0, MixedCharZero R p → P) ↔ ∀ p : ℕ, p.Prime → MixedCharZero R p → P := by
constructor
· intro h q q_prime q_mixedChar
exact h q (Nat.Prime.pos q_prime) q_mixedChar
· intro h q q_pos q_mixedChar
rcases q_mixedChar.charP_quotient with ⟨I, hI_ne_top, _⟩
-- Krull's Thm: There exists a prime ideal `P` such that `I ≤ P`
rcases Ideal.exists_le_maximal I hI_ne_top with ⟨M, hM_max, h_IM⟩
let r := ringChar (R ⧸ M)
have r_pos : r ≠ 0 := by
have q_zero :=
congr_arg (Ideal.Quotient.factor h_IM) (CharP.cast_eq_zero (R ⧸ I) q)
simp only [map_natCast, map_zero] at q_zero
apply ne_zero_of_dvd_ne_zero (ne_of_gt q_pos)
exact (CharP.cast_eq_zero_iff (R ⧸ M) r q).mp q_zero
have r_prime : Nat.Prime r :=
or_iff_not_imp_right.1 (CharP.char_is_prime_or_zero (R ⧸ M) r) r_pos
apply h r r_prime
have : CharZero R := q_mixedChar.toCharZero
exact ⟨⟨M, hM_max.ne_top, ringChar.of_eq rfl⟩⟩
/--
Reduction to `I` prime ideal: When proving statements about mixed characteristic rings,
after we reduced to `p` prime, we can assume that the ideal `I` in the definition is maximal.
-/
theorem reduce_to_maximal_ideal {p : ℕ} (hp : Nat.Prime p) :
(∃ I : Ideal R, I ≠ ⊤ ∧ CharP (R ⧸ I) p) ↔ ∃ I : Ideal R, I.IsMaximal ∧ CharP (R ⧸ I) p := by
constructor
· intro g
rcases g with ⟨I, ⟨hI_not_top, _⟩⟩
-- Krull's Thm: There exists a prime ideal `M` such that `I ≤ M`.
rcases Ideal.exists_le_maximal I hI_not_top with ⟨M, ⟨hM_max, hM_ge⟩⟩
use M
constructor
· exact hM_max
· cases CharP.exists (R ⧸ M) with
| intro r hr =>
convert hr
have r_dvd_p : r ∣ p := by
rw [← CharP.cast_eq_zero_iff (R ⧸ M) r p]
convert congr_arg (Ideal.Quotient.factor hM_ge) (CharP.cast_eq_zero (R ⧸ I) p)
symm
apply (Nat.Prime.eq_one_or_self_of_dvd hp r r_dvd_p).resolve_left
exact CharP.char_ne_one (R ⧸ M) r
· intro ⟨I, hI_max, h_charP⟩
use I
exact ⟨Ideal.IsMaximal.ne_top hI_max, h_charP⟩
end MixedCharZero
/-!
### Equal characteristic zero
A commutative ring `R` has "equal characteristic zero" if it satisfies one of the following
equivalent properties:
1) `R` is a `ℚ`-algebra.
2) The quotient `R ⧸ I` has characteristic zero for any proper ideal `I ⊂ R`.
3) `R` has characteristic zero and does not have mixed characteristic for any prime `p`.
We show `(1) ↔ (2) ↔ (3)`, and most of the following is concerned with constructing
an explicit algebra map `ℚ →+* R` (given by `x ↦ (x.num : R) /ₚ ↑x.pnatDen`)
for the direction `(1) ← (2)`.
Note: Property `(2)` is denoted as `EqualCharZero` in the statement names below.
-/
namespace EqualCharZero
/-- `ℚ`-algebra implies equal characteristic. -/
theorem of_algebraRat [Algebra ℚ R] : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
intro I hI
constructor
intro a b h_ab
contrapose! hI
-- `↑a - ↑b` is a unit contained in `I`, which contradicts `I ≠ ⊤`.
refine I.eq_top_of_isUnit_mem ?_ (IsUnit.map (algebraMap ℚ R) (IsUnit.mk0 (a - b : ℚ) ?_))
· simpa only [← Ideal.Quotient.eq_zero_iff_mem, map_sub, sub_eq_zero, map_natCast]
simpa only [Ne, sub_eq_zero] using (@Nat.cast_injective ℚ _ _).ne hI
section ConstructionAlgebraRat
variable {R}
/-- Internal: Not intended to be used outside this local construction. -/
theorem PNat.isUnit_natCast [h : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))]
(n : ℕ+) : IsUnit (n : R) := by
-- `n : R` is a unit iff `(n)` is not a proper ideal in `R`.
rw [← Ideal.span_singleton_eq_top]
-- So by contrapositive, we should show the quotient does not have characteristic zero.
apply not_imp_comm.mp (h.elim (Ideal.span {↑n}))
intro h_char_zero
-- In particular, the image of `n` in the quotient should be nonzero.
apply h_char_zero.cast_injective.ne n.ne_zero
-- But `n` generates the ideal, so its image is clearly zero.
rw [← map_natCast (Ideal.Quotient.mk _), Nat.cast_zero, Ideal.Quotient.eq_zero_iff_mem]
exact Ideal.subset_span (Set.mem_singleton _)
@[coe]
noncomputable def pnatCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ℕ+ → Rˣ :=
fun n => (PNat.isUnit_natCast n).unit
/-- Internal: Not intended to be used outside this local construction. -/
noncomputable instance coePNatUnits
[Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : Coe ℕ+ Rˣ :=
⟨EqualCharZero.pnatCast⟩
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
theorem pnatCast_one [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] : ((1 : ℕ+) : Rˣ) = 1 := by
apply Units.ext
rw [Units.val_one]
change ((PNat.isUnit_natCast (R := R) 1).unit : R) = 1
rw [IsUnit.unit_spec (PNat.isUnit_natCast 1)]
rw [PNat.one_coe, Nat.cast_one]
/-- Internal: Not intended to be used outside this local construction. -/
@[simp]
theorem pnatCast_eq_natCast [Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I))] (n : ℕ+) :
((n : Rˣ) : R) = ↑n := by
change ((PNat.isUnit_natCast (R := R) n).unit : R) = ↑n
simp only [IsUnit.unit_spec]
/-- Equal characteristic implies `ℚ`-algebra. -/
noncomputable def algebraRat (h : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) :
Algebra ℚ R :=
haveI : Fact (∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) := ⟨h⟩
RingHom.toAlgebra
{ toFun := fun x => x.num /ₚ ↑x.pnatDen
map_zero' := by simp [divp]
map_one' := by simp
map_mul' := by
intro a b
field_simp
trans (↑((a * b).num * a.den * b.den) : R)
· simp_rw [Int.cast_mul, Int.cast_natCast]
ring
rw [Rat.mul_num_den' a b]
simp
map_add' := by
intro a b
field_simp
trans (↑((a + b).num * a.den * b.den) : R)
· simp_rw [Int.cast_mul, Int.cast_natCast]
ring
rw [Rat.add_num_den' a b]
simp }
end ConstructionAlgebraRat
/-- Not mixed characteristic implies equal characteristic. -/
theorem of_not_mixedCharZero [CharZero R] (h : ∀ p > 0, ¬MixedCharZero R p) :
∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
intro I hI_ne_top
suffices CharP (R ⧸ I) 0 from CharP.charP_to_charZero _
cases CharP.exists (R ⧸ I) with
| intro p hp =>
cases p with
| zero => exact hp
| succ p =>
have h_mixed : MixedCharZero R p.succ := ⟨⟨I, ⟨hI_ne_top, hp⟩⟩⟩
exact absurd h_mixed (h p.succ p.succ_pos)
/-- Equal characteristic implies not mixed characteristic. -/
theorem to_not_mixedCharZero (h : ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) :
∀ p > 0, ¬MixedCharZero R p := by
intro p p_pos
by_contra hp_mixedChar
rcases hp_mixedChar.charP_quotient with ⟨I, hI_ne_top, hI_p⟩
replace hI_zero : CharP (R ⧸ I) 0 := @CharP.ofCharZero _ _ (h I hI_ne_top)
exact absurd (CharP.eq (R ⧸ I) hI_p hI_zero) (ne_of_gt p_pos)
/--
A ring of characteristic zero has equal characteristic iff it does not
have mixed characteristic for any `p`.
-/
theorem iff_not_mixedCharZero [CharZero R] :
(∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I)) ↔ ∀ p > 0, ¬MixedCharZero R p :=
⟨to_not_mixedCharZero R, of_not_mixedCharZero R⟩
/-- A ring is a `ℚ`-algebra iff it has equal characteristic zero. -/
theorem nonempty_algebraRat_iff :
Nonempty (Algebra ℚ R) ↔ ∀ I : Ideal R, I ≠ ⊤ → CharZero (R ⧸ I) := by
constructor
· intro h_alg
haveI h_alg' : Algebra ℚ R := h_alg.some
apply of_algebraRat
· intro h
apply Nonempty.intro
exact algebraRat h
end EqualCharZero
/--
A ring of characteristic zero is not a `ℚ`-algebra iff it has mixed characteristic for some `p`.
-/
theorem isEmpty_algebraRat_iff_mixedCharZero [CharZero R] :
IsEmpty (Algebra ℚ R) ↔ ∃ p > 0, MixedCharZero R p := by
rw [← not_iff_not]
push_neg
rw [not_isEmpty_iff, ← EqualCharZero.iff_not_mixedCharZero]
apply EqualCharZero.nonempty_algebraRat_iff
/-!
# Splitting statements into different characteristic
Statements to split a proof by characteristic. There are 3 theorems here that are very
similar. They only differ in the assumptions we can make on the positive characteristic
case:
Generally we need to consider all `p ≠ 0`, but if `R` is a local ring, we can assume
that `p` is a prime power. And if `R` is a domain, we can even assume that `p` is prime.
-/
section MainStatements
variable {P : Prop}
/-- Split a `Prop` in characteristic zero into equal and mixed characteristic. -/
theorem split_equalCharZero_mixedCharZero [CharZero R] (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
by_cases h : ∃ p > 0, MixedCharZero R p
· rcases h with ⟨p, ⟨H, hp⟩⟩
rw [← MixedCharZero.reduce_to_p_prime] at h_mixed
exact h_mixed p H hp
· apply h_equal
rw [← isEmpty_algebraRat_iff_mixedCharZero, not_isEmpty_iff] at h
exact h.some
example (n : ℕ) (h : n ≠ 0) : 0 < n :=
zero_lt_iff.mpr h
/--
Split any `Prop` over `R` into the three cases:
- positive characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic (h_pos : ∀ p : ℕ, p ≠ 0 → CharP R p → P) (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
cases CharP.exists R with
| intro p p_charP =>
by_cases h : p = 0
· rw [h] at p_charP
haveI h0 : CharZero R := CharP.charP_to_charZero R
exact split_equalCharZero_mixedCharZero R h_equal h_mixed
· exact h_pos p h p_charP
/--
In an `IsDomain R`, split any `Prop` over `R` into the three cases:
- *prime* characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic_domain [IsDomain R] (h_pos : ∀ p : ℕ, Nat.Prime p → CharP R p → P)
(h_equal : Algebra ℚ R → P) (h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
refine split_by_characteristic R ?_ h_equal h_mixed
intro p p_pos p_char
have p_prime : Nat.Prime p := or_iff_not_imp_right.mp (CharP.char_is_prime_or_zero R p) p_pos
exact h_pos p p_prime p_char
/--
In a local ring `R`, split any predicate over `R` into the three cases:
- *prime power* characteristic.
- equal characteristic zero.
- mixed characteristic `(0, p)`.
-/
theorem split_by_characteristic_localRing [IsLocalRing R]
(h_pos : ∀ p : ℕ, IsPrimePow p → CharP R p → P) (h_equal : Algebra ℚ R → P)
(h_mixed : ∀ p : ℕ, Nat.Prime p → MixedCharZero R p → P) : P := by
refine split_by_characteristic R ?_ h_equal h_mixed
intro p p_pos p_char
have p_ppow : IsPrimePow (p : ℕ) := or_iff_not_imp_left.mp (charP_zero_or_prime_power R p) p_pos
exact h_pos p p_ppow p_char
end MainStatements
|
Monotone.lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Andrew Zipperer, Haitao Zhang, Minchao Wu, Yury Kudryashov
-/
import Mathlib.Data.Set.Function
/-!
# Monotone functions over sets
-/
variable {α β γ : Type*}
open Equiv Equiv.Perm Function
namespace Set
/-! ### Congruence lemmas for monotonicity and antitonicity -/
section Order
variable {s : Set α} {f₁ f₂ : α → β} [Preorder α] [Preorder β]
theorem _root_.MonotoneOn.congr (h₁ : MonotoneOn f₁ s) (h : s.EqOn f₁ f₂) : MonotoneOn f₂ s := by
intro a ha b hb hab
rw [← h ha, ← h hb]
exact h₁ ha hb hab
theorem _root_.AntitoneOn.congr (h₁ : AntitoneOn f₁ s) (h : s.EqOn f₁ f₂) : AntitoneOn f₂ s :=
h₁.dual_right.congr h
theorem _root_.StrictMonoOn.congr (h₁ : StrictMonoOn f₁ s) (h : s.EqOn f₁ f₂) :
StrictMonoOn f₂ s := by
intro a ha b hb hab
rw [← h ha, ← h hb]
exact h₁ ha hb hab
theorem _root_.StrictAntiOn.congr (h₁ : StrictAntiOn f₁ s) (h : s.EqOn f₁ f₂) : StrictAntiOn f₂ s :=
h₁.dual_right.congr h
theorem EqOn.congr_monotoneOn (h : s.EqOn f₁ f₂) : MonotoneOn f₁ s ↔ MonotoneOn f₂ s :=
⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩
theorem EqOn.congr_antitoneOn (h : s.EqOn f₁ f₂) : AntitoneOn f₁ s ↔ AntitoneOn f₂ s :=
⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩
theorem EqOn.congr_strictMonoOn (h : s.EqOn f₁ f₂) : StrictMonoOn f₁ s ↔ StrictMonoOn f₂ s :=
⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩
theorem EqOn.congr_strictAntiOn (h : s.EqOn f₁ f₂) : StrictAntiOn f₁ s ↔ StrictAntiOn f₂ s :=
⟨fun h₁ => h₁.congr h, fun h₂ => h₂.congr h.symm⟩
end Order
/-! ### Monotonicity lemmas -/
section Mono
variable {s s₂ : Set α} {f : α → β} [Preorder α] [Preorder β]
theorem _root_.MonotoneOn.mono (h : MonotoneOn f s) (h' : s₂ ⊆ s) : MonotoneOn f s₂ :=
fun _ hx _ hy => h (h' hx) (h' hy)
theorem _root_.AntitoneOn.mono (h : AntitoneOn f s) (h' : s₂ ⊆ s) : AntitoneOn f s₂ :=
fun _ hx _ hy => h (h' hx) (h' hy)
theorem _root_.StrictMonoOn.mono (h : StrictMonoOn f s) (h' : s₂ ⊆ s) : StrictMonoOn f s₂ :=
fun _ hx _ hy => h (h' hx) (h' hy)
theorem _root_.StrictAntiOn.mono (h : StrictAntiOn f s) (h' : s₂ ⊆ s) : StrictAntiOn f s₂ :=
fun _ hx _ hy => h (h' hx) (h' hy)
protected theorem _root_.MonotoneOn.monotone (h : MonotoneOn f s) :
Monotone (f ∘ Subtype.val : s → β) :=
fun x y hle => h x.coe_prop y.coe_prop hle
protected theorem _root_.AntitoneOn.monotone (h : AntitoneOn f s) :
Antitone (f ∘ Subtype.val : s → β) :=
fun x y hle => h x.coe_prop y.coe_prop hle
protected theorem _root_.StrictMonoOn.strictMono (h : StrictMonoOn f s) :
StrictMono (f ∘ Subtype.val : s → β) :=
fun x y hlt => h x.coe_prop y.coe_prop hlt
protected theorem _root_.StrictAntiOn.strictAnti (h : StrictAntiOn f s) :
StrictAnti (f ∘ Subtype.val : s → β) :=
fun x y hlt => h x.coe_prop y.coe_prop hlt
lemma monotoneOn_insert_iff {a : α} :
MonotoneOn f (insert a s) ↔
(∀ b ∈ s, b ≤ a → f b ≤ f a) ∧ (∀ b ∈ s, a ≤ b → f a ≤ f b) ∧ MonotoneOn f s := by
simp [MonotoneOn, forall_and]
@[deprecated (since := "2025-06-14")] alias MonotoneOn_insert_iff := monotoneOn_insert_iff
lemma antitoneOn_insert_iff {a : α} :
AntitoneOn f (insert a s) ↔
(∀ b ∈ s, b ≤ a → f a ≤ f b) ∧ (∀ b ∈ s, a ≤ b → f b ≤ f a) ∧ AntitoneOn f s :=
@monotoneOn_insert_iff α βᵒᵈ _ _ _ _ _
@[deprecated (since := "2025-06-14")] alias AntitoneOn_insert_iff := antitoneOn_insert_iff
end Mono
end Set
open Function
/-! ### Monotone -/
namespace Monotone
variable [Preorder α] [Preorder β] {f : α → β}
protected theorem restrict (h : Monotone f) (s : Set α) : Monotone (s.restrict f) := fun _ _ hxy =>
h hxy
protected theorem codRestrict (h : Monotone f) {s : Set β} (hs : ∀ x, f x ∈ s) :
Monotone (s.codRestrict f hs) :=
h
protected theorem rangeFactorization (h : Monotone f) : Monotone (Set.rangeFactorization f) :=
h
end Monotone
section strictMono
variable [Preorder α] [Preorder β] {f : α → β} {s : Set α}
@[simp]
theorem strictMono_restrict :
StrictMono (s.restrict f) ↔ StrictMonoOn f s := by simp [Set.restrict, StrictMono, StrictMonoOn]
alias ⟨_root_.StrictMono.of_restrict, _root_.StrictMonoOn.restrict⟩ := strictMono_restrict
theorem StrictMono.codRestrict (hf : StrictMono f)
{s : Set β} (hs : ∀ x, f x ∈ s) : StrictMono (Set.codRestrict f s hs) :=
hf
lemma strictMonoOn_insert_iff {a : α} :
StrictMonoOn f (insert a s) ↔
(∀ b ∈ s, b < a → f b < f a) ∧ (∀ b ∈ s, a < b → f a < f b) ∧ StrictMonoOn f s := by
simp [StrictMonoOn, forall_and]
lemma strictAntiOn_insert_iff {a : α} :
StrictAntiOn f (insert a s) ↔
(∀ b ∈ s, b < a → f a < f b) ∧ (∀ b ∈ s, a < b → f b < f a) ∧ StrictAntiOn f s :=
@strictMonoOn_insert_iff α βᵒᵈ _ _ _ _ _
lemma strictMonoOn_insert_iff_of_forall_le {a : α} (ha : ∀ x ∈ s, x ≤ a) :
StrictMonoOn f (insert a s) ↔ (∀ b ∈ s, b < a → f b < f a) ∧ StrictMonoOn f s := by
rw [strictMonoOn_insert_iff]
have : ∀ b ∈ s, a < b → f a < f b := by
intro b hb hab
cases (ha _ hb).not_gt hab
tauto
lemma strictMonoOn_insert_iff_of_forall_ge {a : α} (ha : ∀ x ∈ s, a ≤ x) :
StrictMonoOn f (insert a s) ↔ (∀ b ∈ s, a < b → f a < f b) ∧ StrictMonoOn f s := by
rw [strictMonoOn_insert_iff]
have : ∀ b ∈ s, b < a → f b < f a := by
intro b hb hab
cases (ha _ hb).not_gt hab
tauto
lemma strictAntiOn_insert_iff_of_forall_le {a : α} (ha : ∀ x ∈ s, x ≤ a) :
StrictAntiOn f (insert a s) ↔ (∀ b ∈ s, b < a → f a < f b) ∧ StrictAntiOn f s := by
rw [strictAntiOn_insert_iff]
have : ∀ b ∈ s, a < b → f b < f a := by
intro b hb hab
cases (ha _ hb).not_gt hab
tauto
lemma strictAntiOn_insert_iff_of_forall_ge {a : α} (ha : ∀ x ∈ s, a ≤ x) :
StrictAntiOn f (insert a s) ↔ (∀ b ∈ s, a < b → f b < f a) ∧ StrictAntiOn f s := by
rw [strictAntiOn_insert_iff]
have : ∀ b ∈ s, b < a → f a < f b := by
intro b hb hab
cases (ha _ hb).not_gt hab
tauto
end strictMono
namespace Function
open Set
theorem monotoneOn_of_rightInvOn_of_mapsTo {α β : Type*} [PartialOrder α] [LinearOrder β]
{φ : β → α} {ψ : α → β} {t : Set β} {s : Set α} (hφ : MonotoneOn φ t)
(φψs : Set.RightInvOn ψ φ s) (ψts : Set.MapsTo ψ s t) : MonotoneOn ψ s := by
rintro x xs y ys l
rcases le_total (ψ x) (ψ y) with (ψxy|ψyx)
· exact ψxy
· have := hφ (ψts ys) (ψts xs) ψyx
rw [φψs.eq ys, φψs.eq xs] at this
induction le_antisymm l this
exact le_refl _
theorem antitoneOn_of_rightInvOn_of_mapsTo [PartialOrder α] [LinearOrder β]
{φ : β → α} {ψ : α → β} {t : Set β} {s : Set α} (hφ : AntitoneOn φ t)
(φψs : Set.RightInvOn ψ φ s) (ψts : Set.MapsTo ψ s t) : AntitoneOn ψ s :=
(monotoneOn_of_rightInvOn_of_mapsTo hφ.dual_left φψs ψts).dual_right
end Function
|
Operations.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import Mathlib.Data.ENNReal.Real
/-!
# Properties of addition, multiplication and subtraction on extended non-negative real numbers
In this file we prove elementary properties of algebraic operations on `ℝ≥0∞`, including addition,
multiplication, natural powers and truncated subtraction, as well as how these interact with the
order structure on `ℝ≥0∞`. Notably excluded from this list are inversion and division, the
definitions and properties of which can be found in `Mathlib/Data/ENNReal/Inv.lean`.
Note: the definitions of the operations included in this file can be found in
`Mathlib/Data/ENNReal/Basic.lean`.
-/
assert_not_exists Finset
open Set NNReal ENNReal
namespace ENNReal
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
section Mul
@[mono, gcongr]
theorem mul_lt_mul (ac : a < c) (bd : b < d) : a * b < c * d := WithTop.mul_lt_mul ac bd
protected lemma pow_right_strictMono {n : ℕ} (hn : n ≠ 0) : StrictMono fun a : ℝ≥0∞ ↦ a ^ n :=
WithTop.pow_right_strictMono hn
protected lemma pow_le_pow_left_iff {n : ℕ} (hn : n ≠ 0) : a ^ n ≤ b ^ n ↔ a ≤ b :=
(ENNReal.pow_right_strictMono hn).le_iff_le
protected lemma pow_lt_pow_left_iff {n : ℕ} (hn : n ≠ 0) : a ^ n < b ^ n ↔ a < b :=
(ENNReal.pow_right_strictMono hn).lt_iff_lt
@[mono, gcongr] protected lemma pow_le_pow_left {n : ℕ} (h : a ≤ b) : a ^ n ≤ b ^ n :=
pow_le_pow_left' h n
@[mono, gcongr] protected alias ⟨_, pow_lt_pow_left⟩ := ENNReal.pow_lt_pow_left_iff
-- TODO: generalize to `WithTop`
theorem mul_left_strictMono (h0 : a ≠ 0) (hinf : a ≠ ∞) : StrictMono (a * ·) := by
lift a to ℝ≥0 using hinf
rw [coe_ne_zero] at h0
intro x y h
contrapose! h
simpa only [← mul_assoc, ← coe_mul, inv_mul_cancel₀ h0, coe_one, one_mul]
using mul_le_mul_left' h (↑a⁻¹)
@[gcongr] protected theorem mul_lt_mul_left' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
a * b < a * c :=
ENNReal.mul_left_strictMono h0 hinf bc
@[gcongr] protected theorem mul_lt_mul_right' (h0 : a ≠ 0) (hinf : a ≠ ⊤) (bc : b < c) :
b * a < c * a :=
mul_comm b a ▸ mul_comm c a ▸ ENNReal.mul_left_strictMono h0 hinf bc
-- TODO: generalize to `WithTop`
protected theorem mul_right_inj (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b = a * c ↔ b = c :=
(mul_left_strictMono h0 hinf).injective.eq_iff
-- TODO: generalize to `WithTop`
protected theorem mul_left_inj (h0 : c ≠ 0) (hinf : c ≠ ∞) : a * c = b * c ↔ a = b :=
mul_comm c a ▸ mul_comm c b ▸ ENNReal.mul_right_inj h0 hinf
-- TODO: generalize to `WithTop`
theorem mul_le_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b ≤ a * c ↔ b ≤ c :=
(mul_left_strictMono h0 hinf).le_iff_le
-- TODO: generalize to `WithTop`
theorem mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_left (h0 : a ≠ 0) (hinf : a ≠ ∞) : a * b < a * c ↔ b < c :=
(mul_left_strictMono h0 hinf).lt_iff_lt
-- TODO: generalize to `WithTop`
theorem mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) :=
mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left
protected lemma mul_eq_left (ha₀ : a ≠ 0) (ha : a ≠ ∞) : a * b = a ↔ b = 1 := by
simpa using ENNReal.mul_right_inj ha₀ ha (c := 1)
protected lemma mul_eq_right (hb₀ : b ≠ 0) (hb : b ≠ ∞) : a * b = b ↔ a = 1 := by
simpa using ENNReal.mul_left_inj hb₀ hb (b := 1)
end Mul
section OperationsAndOrder
protected theorem pow_pos : 0 < a → ∀ n : ℕ, 0 < a ^ n :=
CanonicallyOrderedAdd.pow_pos
protected theorem pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a ^ n ≠ 0 := by
simpa only [pos_iff_ne_zero] using ENNReal.pow_pos
theorem not_lt_zero : ¬a < 0 := by simp
protected theorem le_of_add_le_add_left : a ≠ ∞ → a + b ≤ a + c → b ≤ c :=
WithTop.le_of_add_le_add_left
protected theorem le_of_add_le_add_right : a ≠ ∞ → b + a ≤ c + a → b ≤ c :=
WithTop.le_of_add_le_add_right
@[gcongr] protected theorem add_lt_add_left : a ≠ ∞ → b < c → a + b < a + c :=
WithTop.add_lt_add_left
@[gcongr] protected theorem add_lt_add_right : a ≠ ∞ → b < c → b + a < c + a :=
WithTop.add_lt_add_right
protected theorem add_le_add_iff_left : a ≠ ∞ → (a + b ≤ a + c ↔ b ≤ c) :=
WithTop.add_le_add_iff_left
protected theorem add_le_add_iff_right : a ≠ ∞ → (b + a ≤ c + a ↔ b ≤ c) :=
WithTop.add_le_add_iff_right
protected theorem add_lt_add_iff_left : a ≠ ∞ → (a + b < a + c ↔ b < c) :=
WithTop.add_lt_add_iff_left
protected theorem add_lt_add_iff_right : a ≠ ∞ → (b + a < c + a ↔ b < c) :=
WithTop.add_lt_add_iff_right
protected theorem add_lt_add_of_le_of_lt : a ≠ ∞ → a ≤ b → c < d → a + c < b + d :=
WithTop.add_lt_add_of_le_of_lt
protected theorem add_lt_add_of_lt_of_le : c ≠ ∞ → a < b → c ≤ d → a + c < b + d :=
WithTop.add_lt_add_of_lt_of_le
instance addLeftReflectLT : AddLeftReflectLT ℝ≥0∞ :=
WithTop.addLeftReflectLT
theorem lt_add_right (ha : a ≠ ∞) (hb : b ≠ 0) : a < a + b := by
rwa [← pos_iff_ne_zero, ← ENNReal.add_lt_add_iff_left ha, add_zero] at hb
end OperationsAndOrder
section OperationsAndInfty
variable {α : Type*} {n : ℕ}
@[simp] theorem add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := WithTop.add_eq_top
@[simp] theorem add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := WithTop.add_lt_top
theorem toNNReal_add {r₁ r₂ : ℝ≥0∞} (h₁ : r₁ ≠ ∞) (h₂ : r₂ ≠ ∞) :
(r₁ + r₂).toNNReal = r₁.toNNReal + r₂.toNNReal := by
lift r₁ to ℝ≥0 using h₁
lift r₂ to ℝ≥0 using h₂
rfl
/-- If `a ≤ b + c` and `a = ∞` whenever `b = ∞` or `c = ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add' (hle : a ≤ b + c) (hb : b = ∞ → a = ∞) (hc : c = ∞ → a = ∞) :
a.toReal ≤ b.toReal + c.toReal := by
refine le_trans (toReal_mono' hle ?_) toReal_add_le
simpa only [add_eq_top, or_imp] using And.intro hb hc
/-- If `a ≤ b + c`, `b ≠ ∞`, and `c ≠ ∞`, then
`ENNReal.toReal a ≤ ENNReal.toReal b + ENNReal.toReal c`. This lemma is useful to transfer
triangle-like inequalities from `ENNReal`s to `Real`s. -/
theorem toReal_le_add (hle : a ≤ b + c) (hb : b ≠ ∞) (hc : c ≠ ∞) :
a.toReal ≤ b.toReal + c.toReal :=
toReal_le_add' hle (flip absurd hb) (flip absurd hc)
theorem not_lt_top {x : ℝ≥0∞} : ¬x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, Classical.not_not]
theorem add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top
@[aesop (rule_sets := [finiteness]) safe apply]
protected lemma Finiteness.add_ne_top {a b : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≠ ∞) : a + b ≠ ∞ :=
ENNReal.add_ne_top.2 ⟨ha, hb⟩
theorem mul_top' : a * ∞ = if a = 0 then 0 else ∞ := by convert WithTop.mul_top' a
@[simp] theorem mul_top (h : a ≠ 0) : a * ∞ = ∞ := WithTop.mul_top h
theorem top_mul' : ∞ * a = if a = 0 then 0 else ∞ := by convert WithTop.top_mul' a
@[simp] theorem top_mul (h : a ≠ 0) : ∞ * a = ∞ := WithTop.top_mul h
theorem top_mul_top : ∞ * ∞ = ∞ := WithTop.top_mul_top
theorem mul_eq_top : a * b = ∞ ↔ a ≠ 0 ∧ b = ∞ ∨ a = ∞ ∧ b ≠ 0 :=
WithTop.mul_eq_top_iff
theorem mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ := WithTop.mul_lt_top
-- This is unsafe because we could have `a = ∞` and `b = 0` or vice-versa
@[aesop (rule_sets := [finiteness]) unsafe 75% apply]
theorem mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := WithTop.mul_ne_top
theorem lt_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a < ∞ :=
lt_top_iff_ne_top.2 fun ha => h <| mul_eq_top.2 (Or.inr ⟨ha, hb⟩)
theorem lt_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b < ∞ :=
lt_top_of_mul_ne_top_left (by rwa [mul_comm]) ha
theorem mul_lt_top_iff {a b : ℝ≥0∞} : a * b < ∞ ↔ a < ∞ ∧ b < ∞ ∨ a = 0 ∨ b = 0 := by
constructor
· intro h
rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right]
intro hb ha
exact ⟨lt_top_of_mul_ne_top_left h.ne hb, lt_top_of_mul_ne_top_right h.ne ha⟩
· rintro (⟨ha, hb⟩ | rfl | rfl) <;> [exact mul_lt_top ha hb; simp; simp]
theorem mul_self_lt_top_iff {a : ℝ≥0∞} : a * a < ⊤ ↔ a < ⊤ := by
rw [ENNReal.mul_lt_top_iff, and_self, or_self, or_iff_left_iff_imp]
rintro rfl
exact zero_lt_top
theorem mul_pos_iff : 0 < a * b ↔ 0 < a ∧ 0 < b :=
CanonicallyOrderedAdd.mul_pos
theorem mul_pos (ha : a ≠ 0) (hb : b ≠ 0) : 0 < a * b :=
mul_pos_iff.2 ⟨pos_iff_ne_zero.2 ha, pos_iff_ne_zero.2 hb⟩
@[simp] lemma top_pow {n : ℕ} (hn : n ≠ 0) : (∞ : ℝ≥0∞) ^ n = ∞ := WithTop.top_pow hn
@[simp] lemma pow_eq_top_iff : a ^ n = ∞ ↔ a = ∞ ∧ n ≠ 0 := WithTop.pow_eq_top_iff
lemma pow_ne_top_iff : a ^ n ≠ ∞ ↔ a ≠ ∞ ∨ n = 0 := WithTop.pow_ne_top_iff
@[simp] lemma pow_lt_top_iff : a ^ n < ∞ ↔ a < ∞ ∨ n = 0 := WithTop.pow_lt_top_iff
lemma eq_top_of_pow (n : ℕ) (ha : a ^ n = ∞) : a = ∞ := WithTop.eq_top_of_pow n ha
@[deprecated (since := "2025-04-24")] alias pow_eq_top := eq_top_of_pow
@[aesop (rule_sets := [finiteness]) safe apply]
lemma pow_ne_top (ha : a ≠ ∞) : a ^ n ≠ ∞ := WithTop.pow_ne_top ha
lemma pow_lt_top (ha : a < ∞) : a ^ n < ∞ := WithTop.pow_lt_top ha
end OperationsAndInfty
-- TODO: generalize to `WithTop`
@[gcongr] protected theorem add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := by
lift a to ℝ≥0 using ac.ne_top
lift b to ℝ≥0 using bd.ne_top
cases c; · simp
cases d; · simp
simp only [← coe_add, coe_lt_coe] at *
exact add_lt_add ac bd
section Cancel
-- TODO: generalize to `WithTop`
/-- An element `a` is `AddLECancellable` if `a + b ≤ a + c` implies `b ≤ c` for all `b` and `c`.
This is true in `ℝ≥0∞` for all elements except `∞`. -/
@[simp]
theorem addLECancellable_iff_ne {a : ℝ≥0∞} : AddLECancellable a ↔ a ≠ ∞ := by
constructor
· rintro h rfl
refine zero_lt_one.not_ge (h ?_)
simp
· rintro h b c hbc
apply ENNReal.le_of_add_le_add_left h hbc
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_ne {a : ℝ≥0∞} (h : a ≠ ∞) : AddLECancellable a :=
addLECancellable_iff_ne.mpr h
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_lt {a : ℝ≥0∞} (h : a < ∞) : AddLECancellable a :=
cancel_of_ne h.ne
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_of_lt' {a b : ℝ≥0∞} (h : a < b) : AddLECancellable a :=
cancel_of_ne h.ne_top
/-- This lemma has an abbreviated name because it is used frequently. -/
theorem cancel_coe {a : ℝ≥0} : AddLECancellable (a : ℝ≥0∞) :=
cancel_of_ne coe_ne_top
theorem add_right_inj (h : a ≠ ∞) : a + b = a + c ↔ b = c :=
(cancel_of_ne h).inj
theorem add_left_inj (h : a ≠ ∞) : b + a = c + a ↔ b = c :=
(cancel_of_ne h).inj_left
end Cancel
section Sub
theorem sub_eq_sInf {a b : ℝ≥0∞} : a - b = sInf { d | a ≤ d + b } :=
le_antisymm (le_sInf fun _ h => tsub_le_iff_right.mpr h) <| sInf_le <| mem_setOf.2 le_tsub_add
/-- This is a special case of `WithTop.coe_sub` in the `ENNReal` namespace -/
@[simp, norm_cast] theorem coe_sub : (↑(r - p) : ℝ≥0∞) = ↑r - ↑p := WithTop.coe_sub
/-- This is a special case of `WithTop.top_sub_coe` in the `ENNReal` namespace -/
@[simp] theorem top_sub_coe : ∞ - ↑r = ∞ := rfl
@[simp] lemma top_sub (ha : a ≠ ∞) : ∞ - a = ∞ := by lift a to ℝ≥0 using ha; exact top_sub_coe
/-- This is a special case of `WithTop.sub_top` in the `ENNReal` namespace -/
@[simp] theorem sub_top : a - ∞ = 0 := WithTop.sub_top
@[simp] theorem sub_eq_top_iff : a - b = ∞ ↔ a = ∞ ∧ b ≠ ∞ := WithTop.sub_eq_top_iff
lemma sub_ne_top_iff : a - b ≠ ∞ ↔ a ≠ ∞ ∨ b = ∞ := WithTop.sub_ne_top_iff
-- This is unsafe because we could have `a = b = ∞`
@[aesop (rule_sets := [finiteness]) unsafe 75% apply]
theorem sub_ne_top (ha : a ≠ ∞) : a - b ≠ ∞ := mt sub_eq_top_iff.mp <| mt And.left ha
@[simp, norm_cast]
theorem natCast_sub (m n : ℕ) : ↑(m - n) = (m - n : ℝ≥0∞) := by
rw [← coe_natCast, Nat.cast_tsub, coe_sub, coe_natCast, coe_natCast]
/-- See `ENNReal.sub_eq_of_eq_add'` for a version assuming that `a = c + b` itself is finite rather
than `b`. -/
protected theorem sub_eq_of_eq_add (hb : b ≠ ∞) : a = c + b → a - b = c :=
(cancel_of_ne hb).tsub_eq_of_eq_add
/-- Weaker version of `ENNReal.sub_eq_of_eq_add` assuming that `a = c + b` itself is finite rather
han `b`. -/
protected lemma sub_eq_of_eq_add' (ha : a ≠ ∞) : a = c + b → a - b = c :=
(cancel_of_ne ha).tsub_eq_of_eq_add'
/-- See `ENNReal.eq_sub_of_add_eq'` for a version assuming that `b = a + c` itself is finite rather
than `c`. -/
protected theorem eq_sub_of_add_eq (hc : c ≠ ∞) : a + c = b → a = b - c :=
(cancel_of_ne hc).eq_tsub_of_add_eq
/-- Weaker version of `ENNReal.eq_sub_of_add_eq` assuming that `b = a + c` itself is finite rather
than `c`. -/
protected lemma eq_sub_of_add_eq' (hb : b ≠ ∞) : a + c = b → a = b - c :=
(cancel_of_ne hb).eq_tsub_of_add_eq'
/-- See `ENNReal.sub_eq_of_eq_add_rev'` for a version assuming that `a = b + c` itself is finite
rather than `b`. -/
protected theorem sub_eq_of_eq_add_rev (hb : b ≠ ∞) : a = b + c → a - b = c :=
(cancel_of_ne hb).tsub_eq_of_eq_add_rev
/-- Weaker version of `ENNReal.sub_eq_of_eq_add_rev` assuming that `a = b + c` itself is finite
rather than `b`. -/
protected lemma sub_eq_of_eq_add_rev' (ha : a ≠ ∞) : a = b + c → a - b = c :=
(cancel_of_ne ha).tsub_eq_of_eq_add_rev'
protected theorem add_sub_cancel_left (ha : a ≠ ∞) : a + b - a = b := by
simp [ha]
protected theorem add_sub_cancel_right (hb : b ≠ ∞) : a + b - b = a := by
simp [hb]
protected theorem sub_add_eq_add_sub (hab : b ≤ a) (b_ne_top : b ≠ ∞) :
a - b + c = a + c - b := by
by_cases c_top : c = ∞
· simpa [c_top] using ENNReal.eq_sub_of_add_eq b_ne_top rfl
refine ENNReal.eq_sub_of_add_eq b_ne_top ?_
simp only [add_assoc, add_comm c b]
simpa only [← add_assoc] using (add_left_inj c_top).mpr <| tsub_add_cancel_of_le hab
lemma add_sub_add_eq_sub_right (hc : c ≠ ∞ := by finiteness) : (a + c) - (b + c) = a - b := by
lift c to ℝ≥0 using hc
cases a <;> cases b
· simp
· simp
· simp
· norm_cast
rw [add_tsub_add_eq_tsub_right]
lemma add_sub_add_eq_sub_left (hc : c ≠ ∞ := by finiteness) : (c + a) - (c + b) = a - b := by
simp_rw [add_comm c]
exact ENNReal.add_sub_add_eq_sub_right hc
protected theorem lt_add_of_sub_lt_left (h : a ≠ ∞ ∨ b ≠ ∞) : a - b < c → a < b + c := by
obtain rfl | hb := eq_or_ne b ∞
· rw [top_add, lt_top_iff_ne_top]
exact fun _ => h.resolve_right (Classical.not_not.2 rfl)
· exact (cancel_of_ne hb).lt_add_of_tsub_lt_left
protected theorem lt_add_of_sub_lt_right (h : a ≠ ∞ ∨ c ≠ ∞) : a - c < b → a < b + c :=
add_comm c b ▸ ENNReal.lt_add_of_sub_lt_left h
theorem le_sub_of_add_le_left (ha : a ≠ ∞) : a + b ≤ c → b ≤ c - a :=
(cancel_of_ne ha).le_tsub_of_add_le_left
theorem le_sub_of_add_le_right (hb : b ≠ ∞) : a + b ≤ c → a ≤ c - b :=
(cancel_of_ne hb).le_tsub_of_add_le_right
protected theorem sub_lt_of_lt_add (hac : c ≤ a) (h : a < b + c) : a - c < b :=
((cancel_of_lt' <| hac.trans_lt h).tsub_lt_iff_right hac).mpr h
protected theorem sub_lt_iff_lt_right (hb : b ≠ ∞) (hab : b ≤ a) : a - b < c ↔ a < c + b :=
(cancel_of_ne hb).tsub_lt_iff_right hab
protected theorem sub_lt_iff_lt_left (hb : b ≠ ∞) (hab : b ≤ a) : a - b < c ↔ a < b + c :=
(cancel_of_ne hb).tsub_lt_iff_left hab
theorem le_sub_iff_add_le_left (hc : c ≠ ∞) (hcb : c ≤ b) : a ≤ b - c ↔ c + a ≤ b :=
⟨fun h ↦ add_le_of_le_tsub_left_of_le hcb h, le_sub_of_add_le_left hc⟩
theorem le_sub_iff_add_le_right (hc : c ≠ ∞) (hcb : c ≤ b) : a ≤ b - c ↔ a + c ≤ b :=
⟨fun h ↦ add_le_of_le_tsub_right_of_le hcb h, le_sub_of_add_le_right hc⟩
protected theorem sub_lt_self (ha : a ≠ ∞) (ha₀ : a ≠ 0) (hb : b ≠ 0) : a - b < a :=
(cancel_of_ne ha).tsub_lt_self (pos_iff_ne_zero.2 ha₀) (pos_iff_ne_zero.2 hb)
protected theorem sub_lt_self_iff (ha : a ≠ ∞) : a - b < a ↔ 0 < a ∧ 0 < b :=
(cancel_of_ne ha).tsub_lt_self_iff
theorem sub_lt_of_sub_lt (h₂ : c ≤ a) (h₃ : a ≠ ∞ ∨ b ≠ ∞) (h₁ : a - b < c) : a - c < b :=
ENNReal.sub_lt_of_lt_add h₂ (add_comm c b ▸ ENNReal.lt_add_of_sub_lt_right h₃ h₁)
theorem sub_sub_cancel (h : a ≠ ∞) (h2 : b ≤ a) : a - (a - b) = b :=
(cancel_of_ne <| sub_ne_top h).tsub_tsub_cancel_of_le h2
theorem sub_right_inj {a b c : ℝ≥0∞} (ha : a ≠ ∞) (hb : b ≤ a) (hc : c ≤ a) :
a - b = a - c ↔ b = c :=
(cancel_of_ne ha).tsub_right_inj (cancel_of_ne <| ne_top_of_le_ne_top ha hb)
(cancel_of_ne <| ne_top_of_le_ne_top ha hc) hb hc
protected theorem sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := by
rcases le_or_gt a b with hab | hab; · simp [hab, mul_right_mono hab, tsub_eq_zero_of_le]
rcases eq_or_lt_of_le (zero_le b) with (rfl | hb); · simp
exact (cancel_of_ne <| mul_ne_top hab.ne_top (h hb hab)).tsub_mul
protected theorem mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by
simp only [mul_comm a]
exact ENNReal.sub_mul h
theorem sub_le_sub_iff_left (h : c ≤ a) (h' : a ≠ ∞) :
(a - b ≤ a - c) ↔ c ≤ b :=
(cancel_of_ne h').tsub_le_tsub_iff_left (cancel_of_ne (ne_top_of_le_ne_top h' h)) h
theorem le_toReal_sub {a b : ℝ≥0∞} (hb : b ≠ ∞) : a.toReal - b.toReal ≤ (a - b).toReal := by
lift b to ℝ≥0 using hb
induction a
· simp
· simp only [← coe_sub, NNReal.sub_def, Real.coe_toNNReal', coe_toReal]
exact le_max_left _ _
@[simp]
lemma toNNReal_sub (hb : b ≠ ∞) : (a - b).toNNReal = a.toNNReal - b.toNNReal := by
lift b to ℝ≥0 using hb; induction a <;> simp [← coe_sub]
@[simp]
lemma toReal_sub_of_le (hba : b ≤ a) (ha : a ≠ ∞) : (a - b).toReal = a.toReal - b.toReal := by
simp [ENNReal.toReal, ne_top_of_le_ne_top ha hba, toNNReal_mono ha hba]
theorem ofReal_sub (p : ℝ) {q : ℝ} (hq : 0 ≤ q) :
ENNReal.ofReal (p - q) = ENNReal.ofReal p - ENNReal.ofReal q := by
obtain h | h := le_total p q
· rw [ofReal_of_nonpos (sub_nonpos_of_le h), tsub_eq_zero_of_le (ofReal_le_ofReal h)]
refine ENNReal.eq_sub_of_add_eq ofReal_ne_top ?_
rw [← ofReal_add (sub_nonneg_of_le h) hq, sub_add_cancel]
end Sub
section Interval
variable {x y z : ℝ≥0∞} {ε ε₁ ε₂ : ℝ≥0∞} {s : Set ℝ≥0∞}
protected theorem Ico_eq_Iio : Ico 0 y = Iio y :=
Ico_bot
theorem mem_Iio_self_add : x ≠ ∞ → ε ≠ 0 → x ∈ Iio (x + ε) := fun xt ε0 => lt_add_right xt ε0
theorem mem_Ioo_self_sub_add : x ≠ ∞ → x ≠ 0 → ε₁ ≠ 0 → ε₂ ≠ 0 → x ∈ Ioo (x - ε₁) (x + ε₂) :=
fun xt x0 ε0 ε0' => ⟨ENNReal.sub_lt_self xt x0 ε0, lt_add_right xt ε0'⟩
@[simp]
theorem image_coe_Iic (x : ℝ≥0) : (↑) '' Iic x = Iic (x : ℝ≥0∞) := WithTop.image_coe_Iic
@[simp]
theorem image_coe_Ici (x : ℝ≥0) : (↑) '' Ici x = Ico ↑x ∞ := WithTop.image_coe_Ici
@[simp]
theorem image_coe_Iio (x : ℝ≥0) : (↑) '' Iio x = Iio (x : ℝ≥0∞) := WithTop.image_coe_Iio
@[simp]
theorem image_coe_Ioi (x : ℝ≥0) : (↑) '' Ioi x = Ioo ↑x ∞ := WithTop.image_coe_Ioi
@[simp]
theorem image_coe_Icc (x y : ℝ≥0) : (↑) '' Icc x y = Icc (x : ℝ≥0∞) y := WithTop.image_coe_Icc
@[simp]
theorem image_coe_Ico (x y : ℝ≥0) : (↑) '' Ico x y = Ico (x : ℝ≥0∞) y := WithTop.image_coe_Ico
@[simp]
theorem image_coe_Ioc (x y : ℝ≥0) : (↑) '' Ioc x y = Ioc (x : ℝ≥0∞) y := WithTop.image_coe_Ioc
@[simp]
theorem image_coe_Ioo (x y : ℝ≥0) : (↑) '' Ioo x y = Ioo (x : ℝ≥0∞) y := WithTop.image_coe_Ioo
@[simp]
theorem image_coe_uIcc (x y : ℝ≥0) : (↑) '' uIcc x y = uIcc (x : ℝ≥0∞) y := by simp [uIcc]
@[simp]
theorem image_coe_uIoc (x y : ℝ≥0) : (↑) '' uIoc x y = uIoc (x : ℝ≥0∞) y := by simp [uIoc]
@[simp]
theorem image_coe_uIoo (x y : ℝ≥0) : (↑) '' uIoo x y = uIoo (x : ℝ≥0∞) y := by simp [uIoo]
end Interval
section iInf
variable {ι : Sort*} {f g : ι → ℝ≥0∞}
variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0}
theorem toNNReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toNNReal = ⨅ i, (f i).toNNReal := by
cases isEmpty_or_nonempty ι
· rw [iInf_of_empty, toNNReal_top, NNReal.iInf_empty]
· lift f to ι → ℝ≥0 using hf
simp_rw [← coe_iInf, toNNReal_coe]
theorem toNNReal_sInf (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) :
(sInf s).toNNReal = sInf (ENNReal.toNNReal '' s) := by
have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs
simpa only [← sInf_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iInf hf)
theorem toReal_iInf (hf : ∀ i, f i ≠ ∞) : (iInf f).toReal = ⨅ i, (f i).toReal := by
simp only [ENNReal.toReal, toNNReal_iInf hf, NNReal.coe_iInf]
theorem toReal_sInf (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) :
(sInf s).toReal = sInf (ENNReal.toReal '' s) := by
simp only [ENNReal.toReal, toNNReal_sInf s hf, NNReal.coe_sInf, Set.image_image]
@[simp] lemma ofReal_iInf [Nonempty ι] (f : ι → ℝ) :
ENNReal.ofReal (⨅ i, f i) = ⨅ i, ENNReal.ofReal (f i) := by
obtain ⟨i, hi⟩ | h := em (∃ i, f i ≤ 0)
· rw [(iInf_eq_bot _).2 fun _ _ ↦ ⟨i, by simpa [ofReal_of_nonpos hi]⟩]
simp [Real.iInf_nonpos' ⟨i, hi⟩]
replace h i : 0 ≤ f i := le_of_not_ge fun hi ↦ h ⟨i, hi⟩
refine eq_of_forall_le_iff fun a ↦ ?_
obtain rfl | ha := eq_or_ne a ∞
· simp
rw [le_iInf_iff, le_ofReal_iff_toReal_le ha, le_ciInf_iff ⟨0, by simpa [mem_lowerBounds]⟩]
· exact forall_congr' fun i ↦ (le_ofReal_iff_toReal_le ha (h _)).symm
· exact Real.iInf_nonneg h
theorem iInf_add : iInf f + a = ⨅ i, f i + a :=
le_antisymm (le_iInf fun _ => add_le_add (iInf_le _ _) <| le_rfl)
(tsub_le_iff_right.1 <| le_iInf fun _ => tsub_le_iff_right.2 <| iInf_le _ _)
theorem sub_iInf : (a - ⨅ i, f i) = ⨆ i, a - f i := by
refine eq_of_forall_ge_iff fun c => ?_
rw [tsub_le_iff_right, add_comm, iInf_add]
simp [tsub_le_iff_right, add_comm]
theorem sInf_add {s : Set ℝ≥0∞} : sInf s + a = ⨅ b ∈ s, b + a := by simp [sInf_eq_iInf, iInf_add]
theorem add_iInf {a : ℝ≥0∞} : a + iInf f = ⨅ b, a + f b := by
rw [add_comm, iInf_add]; simp [add_comm]
theorem iInf_add_iInf (h : ∀ i j, ∃ k, f k + g k ≤ f i + g j) : iInf f + iInf g = ⨅ a, f a + g a :=
suffices ⨅ a, f a + g a ≤ iInf f + iInf g from
le_antisymm (le_iInf fun _ => add_le_add (iInf_le _ _) (iInf_le _ _)) this
calc
⨅ a, f a + g a ≤ ⨅ (a) (a'), f a + g a' :=
le_iInf₂ fun a a' => let ⟨k, h⟩ := h a a'; iInf_le_of_le k h
_ = iInf f + iInf g := by simp_rw [iInf_add, add_iInf]
lemma iInf_add_iInf_of_monotone {ι : Type*} [Preorder ι] [IsDirected ι (· ≥ ·)] {f g : ι → ℝ≥0∞}
(hf : Monotone f) (hg : Monotone g) : iInf f + iInf g = ⨅ a, f a + g a :=
iInf_add_iInf fun i j ↦ (exists_le_le i j).imp fun _k ⟨hi, hj⟩ ↦ by gcongr <;> apply_rules
lemma add_iInf₂ {κ : ι → Sort*} (f : (i : ι) → κ i → ℝ≥0∞) :
a + ⨅ (i) (j), f i j = ⨅ (i) (j), a + f i j := by
simp [add_iInf]
lemma iInf₂_add {κ : ι → Sort*} (f : (i : ι) → κ i → ℝ≥0∞) :
(⨅ (i) (j), f i j) + a = ⨅ (i) (j), f i j + a := by
simp only [add_comm, add_iInf₂]
lemma add_sInf {s : Set ℝ≥0∞} : a + sInf s = ⨅ b ∈ s, a + b := by
rw [sInf_eq_iInf, add_iInf₂]
variable {κ : Sort*}
lemma le_iInf_add_iInf {g : κ → ℝ≥0∞} (h : ∀ i j, a ≤ f i + g j) :
a ≤ iInf f + iInf g := by
simp_rw [iInf_add, add_iInf]; exact le_iInf₂ h
lemma le_iInf₂_add_iInf₂ {q₁ : ι → Sort*} {q₂ : κ → Sort*}
{f : (i : ι) → q₁ i → ℝ≥0∞} {g : (k : κ) → q₂ k → ℝ≥0∞}
(h : ∀ i pi k qk, a ≤ f i pi + g k qk) :
a ≤ (⨅ (i) (qi), f i qi) + ⨅ (k) (qk), g k qk := by
simp_rw [iInf₂_add, add_iInf₂]
exact le_iInf₂ fun i hi => le_iInf₂ (h i hi)
@[simp] lemma iInf_gt_eq_self (a : ℝ≥0∞) : ⨅ b, ⨅ _ : a < b, b = a := by
refine le_antisymm ?_ (le_iInf₂ fun b hb ↦ hb.le)
refine le_of_forall_gt fun c hac ↦ ?_
obtain ⟨d, had, hdc⟩ := exists_between hac
exact (iInf₂_le_of_le d had le_rfl).trans_lt hdc
lemma exists_add_lt_of_add_lt {x y z : ℝ≥0∞} (h : y + z < x) :
∃ y' > y, ∃ z' > z, y' + z' < x := by
contrapose! h
simpa using le_iInf₂_add_iInf₂ h
end iInf
section iSup
variable {ι κ : Sort*} {f g : ι → ℝ≥0∞} {s : Set ℝ≥0∞} {a : ℝ≥0∞}
theorem toNNReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toNNReal = ⨆ i, (f i).toNNReal := by
lift f to ι → ℝ≥0 using hf
simp_rw [toNNReal_coe]
by_cases h : BddAbove (range f)
· rw [← coe_iSup h, toNNReal_coe]
· rw [NNReal.iSup_of_not_bddAbove h, iSup_coe_eq_top.2 h, toNNReal_top]
theorem toNNReal_sSup (s : Set ℝ≥0∞) (hs : ∀ r ∈ s, r ≠ ∞) :
(sSup s).toNNReal = sSup (ENNReal.toNNReal '' s) := by
have hf : ∀ i, ((↑) : s → ℝ≥0∞) i ≠ ∞ := fun ⟨r, rs⟩ => hs r rs
simpa only [← sSup_range, ← image_eq_range, Subtype.range_coe_subtype] using (toNNReal_iSup hf)
theorem toReal_iSup (hf : ∀ i, f i ≠ ∞) : (iSup f).toReal = ⨆ i, (f i).toReal := by
simp only [ENNReal.toReal, toNNReal_iSup hf, NNReal.coe_iSup]
theorem toReal_sSup (s : Set ℝ≥0∞) (hf : ∀ r ∈ s, r ≠ ∞) :
(sSup s).toReal = sSup (ENNReal.toReal '' s) := by
simp only [ENNReal.toReal, toNNReal_sSup s hf, NNReal.coe_sSup, Set.image_image]
theorem iSup_sub : (⨆ i, f i) - a = ⨆ i, f i - a :=
le_antisymm (tsub_le_iff_right.2 <| iSup_le fun i => tsub_le_iff_right.1 <| le_iSup (f · - a) i)
(iSup_le fun _ => tsub_le_tsub (le_iSup _ _) (le_refl a))
@[simp] lemma iSup_eq_zero : ⨆ i, f i = 0 ↔ ∀ i, f i = 0 := iSup_eq_bot
@[simp] lemma iSup_zero : ⨆ _ : ι, (0 : ℝ≥0∞) = 0 := by simp
lemma iSup_natCast : ⨆ n : ℕ, (n : ℝ≥0∞) = ∞ :=
(iSup_eq_top _).2 fun _b hb => ENNReal.exists_nat_gt (lt_top_iff_ne_top.1 hb)
lemma add_iSup [Nonempty ι] (f : ι → ℝ≥0∞) : a + ⨆ i, f i = ⨆ i, a + f i := by
obtain rfl | ha := eq_or_ne a ∞
· simp
refine le_antisymm ?_ <| iSup_le fun i ↦ add_le_add_left (le_iSup ..) _
refine add_le_of_le_tsub_left_of_le (le_iSup_of_le (Classical.arbitrary _) le_self_add) ?_
exact iSup_le fun i ↦ ENNReal.le_sub_of_add_le_left ha <| le_iSup (a + f ·) i
lemma iSup_add [Nonempty ι] (f : ι → ℝ≥0∞) : (⨆ i, f i) + a = ⨆ i, f i + a := by
simp [add_comm, add_iSup]
lemma add_biSup' {p : ι → Prop} (h : ∃ i, p i) (f : ι → ℝ≥0∞) :
a + ⨆ i, ⨆ _ : p i, f i = ⨆ i, ⨆ _ : p i, a + f i := by
haveI : Nonempty {i // p i} := nonempty_subtype.2 h
simp only [iSup_subtype', add_iSup]
lemma biSup_add' {p : ι → Prop} (h : ∃ i, p i) (f : ι → ℝ≥0∞) :
(⨆ i, ⨆ _ : p i, f i) + a = ⨆ i, ⨆ _ : p i, f i + a := by simp only [add_comm, add_biSup' h]
lemma add_biSup {ι : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → ℝ≥0∞) :
a + ⨆ i ∈ s, f i = ⨆ i ∈ s, a + f i := add_biSup' hs _
lemma biSup_add {ι : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → ℝ≥0∞) :
(⨆ i ∈ s, f i) + a = ⨆ i ∈ s, f i + a := biSup_add' hs _
lemma add_sSup (hs : s.Nonempty) : a + sSup s = ⨆ b ∈ s, a + b := by
rw [sSup_eq_iSup, add_biSup hs]
lemma sSup_add (hs : s.Nonempty) : sSup s + a = ⨆ b ∈ s, b + a := by
rw [sSup_eq_iSup, biSup_add hs]
lemma iSup_add_iSup_le [Nonempty ι] [Nonempty κ] {g : κ → ℝ≥0∞} (h : ∀ i j, f i + g j ≤ a) :
iSup f + iSup g ≤ a := by simp_rw [iSup_add, add_iSup]; exact iSup₂_le h
lemma biSup_add_biSup_le' {p : ι → Prop} {q : κ → Prop} (hp : ∃ i, p i) (hq : ∃ j, q j)
{g : κ → ℝ≥0∞} (h : ∀ i, p i → ∀ j, q j → f i + g j ≤ a) :
(⨆ i, ⨆ _ : p i, f i) + ⨆ j, ⨆ _ : q j, g j ≤ a := by
simp_rw [biSup_add' hp, add_biSup' hq]
exact iSup₂_le fun i hi => iSup₂_le (h i hi)
lemma biSup_add_biSup_le {ι κ : Type*} {s : Set ι} {t : Set κ} (hs : s.Nonempty) (ht : t.Nonempty)
{f : ι → ℝ≥0∞} {g : κ → ℝ≥0∞} {a : ℝ≥0∞} (h : ∀ i ∈ s, ∀ j ∈ t, f i + g j ≤ a) :
(⨆ i ∈ s, f i) + ⨆ j ∈ t, g j ≤ a := biSup_add_biSup_le' hs ht h
lemma iSup_add_iSup (h : ∀ i j, ∃ k, f i + g j ≤ f k + g k) : iSup f + iSup g = ⨆ i, f i + g i := by
cases isEmpty_or_nonempty ι
· simp only [iSup_of_empty, bot_eq_zero, zero_add]
· refine le_antisymm ?_ (iSup_le fun a => add_le_add (le_iSup _ _) (le_iSup _ _))
refine iSup_add_iSup_le fun i j => ?_
rcases h i j with ⟨k, hk⟩
exact le_iSup_of_le k hk
lemma iSup_add_iSup_of_monotone {ι : Type*} [Preorder ι] [IsDirected ι (· ≤ ·)] {f g : ι → ℝ≥0∞}
(hf : Monotone f) (hg : Monotone g) : iSup f + iSup g = ⨆ a, f a + g a :=
iSup_add_iSup fun i j ↦ (exists_ge_ge i j).imp fun _k ⟨hi, hj⟩ ↦ by gcongr <;> apply_rules
lemma sub_iSup [Nonempty ι] (ha : a ≠ ∞) : a - ⨆ i, f i = ⨅ i, a - f i := by
obtain ⟨i, hi⟩ | h := em (∃ i, a < f i)
· rw [tsub_eq_zero_iff_le.2 <| le_iSup_of_le _ hi.le, (iInf_eq_bot _).2, bot_eq_zero]
exact fun x hx ↦ ⟨i, by simpa [hi.le, tsub_eq_zero_of_le]⟩
simp_rw [not_exists, not_lt] at h
refine le_antisymm (le_iInf fun i ↦ tsub_le_tsub_left (le_iSup ..) _) <|
ENNReal.le_sub_of_add_le_left (ne_top_of_le_ne_top ha <| iSup_le h) <|
add_le_of_le_tsub_right_of_le (iInf_le_of_le (Classical.arbitrary _) tsub_le_self) <|
iSup_le fun i ↦ ?_
rw [← sub_sub_cancel ha (h _)]
exact tsub_le_tsub_left (iInf_le (a - f ·) i) _
@[simp] lemma iSup_lt_eq_self (a : ℝ≥0∞) : ⨆ b, ⨆ _ : b < a, b = a := by
refine le_antisymm (iSup₂_le fun b hb ↦ hb.le) ?_
refine le_of_forall_lt fun c hca ↦ ?_
obtain ⟨d, hcd, hdb⟩ := exists_between hca
exact hcd.trans_le <| le_iSup₂_of_le d hdb le_rfl
-- TODO: Prove the two one-side versions
lemma exists_lt_add_of_lt_add {x y z : ℝ≥0∞} (h : x < y + z) (hy : y ≠ 0) (hz : z ≠ 0) :
∃ y' < y, ∃ z' < z, x < y' + z' := by
contrapose! h
simpa using biSup_add_biSup_le' (by exact ⟨0, hy.bot_lt⟩) (by exact ⟨0, hz.bot_lt⟩) h
end iSup
end ENNReal
|
ssrmatching.v
|
From Corelib Require Export ssrmatching.
|
CategoryTheory.lean
|
/-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.RingTheory.Flat.Basic
import Mathlib.Algebra.Homology.ShortComplex.ModuleCat
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
/-!
# Tensoring with a flat module is an exact functor
In this file we prove that tensoring with a flat module is an exact functor.
## Main results
- `Module.Flat.iff_lTensor_preserves_shortComplex_exact`: an `R`-module `M` is flat if and only if
for every exact sequence `A ⟶ B ⟶ C`, `M ⊗ A ⟶ M ⊗ B ⟶ M ⊗ C` is also exact.
- `Module.Flat.iff_rTensor_preserves_shortComplex_exact`: an `R`-module `M` is flat if and only if
for every short exact sequence `A ⟶ B ⟶ C`, `A ⊗ M ⟶ B ⊗ M ⟶ C ⊗ M` is also exact.
## TODO
- Prove that tensoring with a flat module is an exact functor in the sense that it preserves both
finite limits and colimits.
- Relate flatness with `Tor`
-/
universe u
open CategoryTheory MonoidalCategory ShortComplex.ShortExact
namespace Module.Flat
variable {R : Type u} [CommRing R] (M : ModuleCat.{u} R)
lemma lTensor_shortComplex_exact [Flat R M] (C : ShortComplex <| ModuleCat R) (hC : C.Exact) :
C.map (tensorLeft M) |>.Exact := by
rw [moduleCat_exact_iff_function_exact] at hC ⊢
exact lTensor_exact M hC
lemma rTensor_shortComplex_exact [Flat R M] (C : ShortComplex <| ModuleCat R) (hC : C.Exact) :
C.map (tensorRight M) |>.Exact := by
rw [moduleCat_exact_iff_function_exact] at hC ⊢
exact rTensor_exact M hC
lemma iff_lTensor_preserves_shortComplex_exact :
Flat R M ↔
∀ (C : ShortComplex <| ModuleCat R) (_ : C.Exact), (C.map (tensorLeft M) |>.Exact) :=
⟨fun _ _ ↦ lTensor_shortComplex_exact _ _, fun H ↦ iff_lTensor_exact.2
fun _ _ _ _ _ _ _ _ _ f g h ↦
moduleCat_exact_iff_function_exact _ |>.1 <|
H (.mk (ModuleCat.ofHom f) (ModuleCat.ofHom g)
(ModuleCat.hom_ext (DFunLike.ext _ _ h.apply_apply_eq_zero)))
(moduleCat_exact_iff_function_exact _ |>.2 h)⟩
lemma iff_rTensor_preserves_shortComplex_exact :
Flat R M ↔
∀ (C : ShortComplex <| ModuleCat R) (_ : C.Exact), (C.map (tensorRight M) |>.Exact) :=
⟨fun _ _ ↦ rTensor_shortComplex_exact _ _, fun H ↦ iff_rTensor_exact.2
fun _ _ _ _ _ _ _ _ _ f g h ↦
moduleCat_exact_iff_function_exact _ |>.1 <|
H (.mk (ModuleCat.ofHom f) (ModuleCat.ofHom g)
(ModuleCat.hom_ext (DFunLike.ext _ _ h.apply_apply_eq_zero)))
(moduleCat_exact_iff_function_exact _ |>.2 h)⟩
end Module.Flat
|
Filter.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 Mathlib.Order.Filter.Cofinite
/-!
# Computational realization of filters (experimental)
This file provides infrastructure to compute with filters.
## Main declarations
* `CFilter`: Realization of a filter base. Note that this is in the generality of filters on
lattices, while `Filter` is filters of sets (so corresponding to `CFilter (Set α) σ`).
* `Filter.Realizer`: Realization of a `Filter`. `CFilter` that generates the given filter.
-/
open Set Filter
-- TODO write doc strings
/-- A `CFilter α σ` is a realization of a filter (base) on `α`,
represented by a type `σ` together with operations for the top element and
the binary `inf` operation. -/
structure CFilter (α σ : Type*) [PartialOrder α] where
f : σ → α
pt : σ
inf : σ → σ → σ
inf_le_left : ∀ a b : σ, f (inf a b) ≤ f a
inf_le_right : ∀ a b : σ, f (inf a b) ≤ f b
variable {α : Type*} {β : Type*} {σ : Type*} {τ : Type*}
instance [Inhabited α] [SemilatticeInf α] : Inhabited (CFilter α α) :=
⟨{ f := id
pt := default
inf := (· ⊓ ·)
inf_le_left := fun _ _ ↦ inf_le_left
inf_le_right := fun _ _ ↦ inf_le_right }⟩
namespace CFilter
section
variable [PartialOrder α] (F : CFilter α σ)
/-
A DFunLike instance would not be mathematically meaningful here, since the coercion to f cannot b
injective.
-/
instance : CoeFun (CFilter α σ) fun _ ↦ σ → α :=
⟨CFilter.f⟩
theorem coe_mk (f pt inf h₁ h₂ a) : (@CFilter.mk α σ _ f pt inf h₁ h₂) a = f a :=
rfl
/-- Map a `CFilter` to an equivalent representation type. -/
def ofEquiv (E : σ ≃ τ) : CFilter α σ → CFilter α τ
| ⟨f, p, g, h₁, h₂⟩ =>
{ f := fun a ↦ f (E.symm a)
pt := E p
inf := fun a b ↦ E (g (E.symm a) (E.symm b))
inf_le_left := fun a b ↦ by simpa using h₁ (E.symm a) (E.symm b)
inf_le_right := fun a b ↦ by simpa using h₂ (E.symm a) (E.symm b) }
@[simp]
theorem ofEquiv_val (E : σ ≃ τ) (F : CFilter α σ) (a : τ) : F.ofEquiv E a = F (E.symm a) := by
cases F; rfl
end
/-- The filter represented by a `CFilter` is the collection of supersets of
elements of the filter base. -/
def toFilter (F : CFilter (Set α) σ) : Filter α where
sets := { a | ∃ b, F b ⊆ a }
univ_sets := ⟨F.pt, subset_univ _⟩
sets_of_superset := fun ⟨b, h⟩ s ↦ ⟨b, Subset.trans h s⟩
inter_sets := fun ⟨a, h₁⟩ ⟨b, h₂⟩ ↦ ⟨F.inf a b,
subset_inter (Subset.trans (F.inf_le_left _ _) h₁) (Subset.trans (F.inf_le_right _ _) h₂)⟩
@[simp]
theorem mem_toFilter_sets (F : CFilter (Set α) σ) {a : Set α} : a ∈ F.toFilter ↔ ∃ b, F b ⊆ a :=
Iff.rfl
end CFilter
-- TODO write doc strings
/-- A realizer for filter `f` is a cfilter which generates `f`. -/
structure Filter.Realizer (f : Filter α) where
σ : Type*
F : CFilter (Set α) σ
eq : F.toFilter = f
/-- A `CFilter` realizes the filter it generates. -/
protected def CFilter.toRealizer (F : CFilter (Set α) σ) : F.toFilter.Realizer :=
⟨σ, F, rfl⟩
namespace Filter.Realizer
theorem mem_sets {f : Filter α} (F : f.Realizer) {a : Set α} : a ∈ f ↔ ∃ b, F.F b ⊆ a := by
cases F; subst f; rfl
/-- Transfer a realizer along an equality of filter. This has better definitional equalities than
the `Eq.rec` proof. -/
def ofEq {f g : Filter α} (e : f = g) (F : f.Realizer) : g.Realizer :=
⟨F.σ, F.F, F.eq.trans e⟩
/-- A filter realizes itself. -/
def ofFilter (f : Filter α) : f.Realizer :=
⟨f.sets,
{ f := Subtype.val
pt := ⟨univ, univ_mem⟩
inf := fun ⟨_, h₁⟩ ⟨_, h₂⟩ ↦ ⟨_, inter_mem h₁ h₂⟩
inf_le_left := fun ⟨_, _⟩ ⟨_, _⟩ ↦ inter_subset_left
inf_le_right := fun ⟨_, _⟩ ⟨_, _⟩ ↦ inter_subset_right },
filter_eq <| Set.ext fun _ ↦ by simp [exists_mem_subset_iff]⟩
/-- Transfer a filter realizer to another realizer on a different base type. -/
def ofEquiv {f : Filter α} (F : f.Realizer) (E : F.σ ≃ τ) : f.Realizer :=
⟨τ, F.F.ofEquiv E, by
refine Eq.trans ?_ F.eq
exact filter_eq (Set.ext fun _ ↦
⟨fun ⟨s, h⟩ ↦ ⟨E.symm s, by simpa using h⟩, fun ⟨t, h⟩ ↦ ⟨E t, by simp [h]⟩⟩)⟩
@[simp]
theorem ofEquiv_σ {f : Filter α} (F : f.Realizer) (E : F.σ ≃ τ) : (F.ofEquiv E).σ = τ :=
rfl
@[simp]
theorem ofEquiv_F {f : Filter α} (F : f.Realizer) (E : F.σ ≃ τ) (s : τ) :
(F.ofEquiv E).F s = F.F (E.symm s) := rfl
/-- `Unit` is a realizer for the principal filter -/
protected def principal (s : Set α) : (principal s).Realizer :=
⟨Unit,
{ f := fun _ ↦ s
pt := ()
inf := fun _ _ ↦ ()
inf_le_left := fun _ _ ↦ le_rfl
inf_le_right := fun _ _ ↦ le_rfl },
filter_eq <| Set.ext fun _ ↦ ⟨fun ⟨_, s⟩ ↦ s, fun h ↦ ⟨(), h⟩⟩⟩
@[simp]
theorem principal_σ (s : Set α) : (Realizer.principal s).σ = Unit :=
rfl
@[simp]
theorem principal_F (s : Set α) (u : Unit) : (Realizer.principal s).F u = s :=
rfl
instance (s : Set α) : Inhabited (principal s).Realizer :=
⟨Realizer.principal s⟩
/-- `Unit` is a realizer for the top filter -/
protected def top : (⊤ : Filter α).Realizer :=
(Realizer.principal _).ofEq principal_univ
@[simp]
theorem top_σ : (@Realizer.top α).σ = Unit :=
rfl
@[simp]
theorem top_F (u : Unit) : (@Realizer.top α).F u = univ :=
rfl
/-- `Unit` is a realizer for the bottom filter -/
protected def bot : (⊥ : Filter α).Realizer :=
(Realizer.principal _).ofEq principal_empty
@[simp]
theorem bot_σ : (@Realizer.bot α).σ = Unit :=
rfl
@[simp]
theorem bot_F (u : Unit) : (@Realizer.bot α).F u = ∅ :=
rfl
/-- Construct a realizer for `map m f` given a realizer for `f` -/
protected def map (m : α → β) {f : Filter α} (F : f.Realizer) : (map m f).Realizer :=
⟨F.σ,
{ f := fun s ↦ image m (F.F s)
pt := F.F.pt
inf := F.F.inf
inf_le_left := fun _ _ ↦ image_mono (F.F.inf_le_left _ _)
inf_le_right := fun _ _ ↦ image_mono (F.F.inf_le_right _ _) },
filter_eq <| Set.ext fun _ ↦ by
simp only [CFilter.toFilter, image_subset_iff, mem_setOf_eq, Filter.mem_sets, mem_map]
rw [F.mem_sets]⟩
@[simp]
theorem map_σ (m : α → β) {f : Filter α} (F : f.Realizer) : (F.map m).σ = F.σ :=
rfl
@[simp]
theorem map_F (m : α → β) {f : Filter α} (F : f.Realizer) (s) : (F.map m).F s = image m (F.F s) :=
rfl
/-- Construct a realizer for `comap m f` given a realizer for `f` -/
protected def comap (m : α → β) {f : Filter β} (F : f.Realizer) : (comap m f).Realizer :=
⟨F.σ,
{ f := fun s ↦ preimage m (F.F s)
pt := F.F.pt
inf := F.F.inf
inf_le_left := fun _ _ ↦ preimage_mono (F.F.inf_le_left _ _)
inf_le_right := fun _ _ ↦ preimage_mono (F.F.inf_le_right _ _) },
filter_eq <| Set.ext fun _ ↦ by
cases F; subst f
exact ⟨fun ⟨s, h⟩ ↦ ⟨_, ⟨s, Subset.refl _⟩, h⟩,
fun ⟨_, ⟨s, h⟩, h₂⟩ ↦ ⟨s, Subset.trans (preimage_mono h) h₂⟩⟩⟩
/-- Construct a realizer for the sup of two filters -/
protected def sup {f g : Filter α} (F : f.Realizer) (G : g.Realizer) : (f ⊔ g).Realizer :=
⟨F.σ × G.σ,
{ f := fun ⟨s, t⟩ ↦ F.F s ∪ G.F t
pt := (F.F.pt, G.F.pt)
inf := fun ⟨a, a'⟩ ⟨b, b'⟩ ↦ (F.F.inf a b, G.F.inf a' b')
inf_le_left := fun _ _ ↦ union_subset_union (F.F.inf_le_left _ _) (G.F.inf_le_left _ _)
inf_le_right := fun _ _ ↦ union_subset_union (F.F.inf_le_right _ _) (G.F.inf_le_right _ _) },
filter_eq <| Set.ext fun _ ↦ by cases F; cases G; substs f g; simp [CFilter.toFilter]⟩
/-- Construct a realizer for the inf of two filters -/
protected def inf {f g : Filter α} (F : f.Realizer) (G : g.Realizer) : (f ⊓ g).Realizer :=
⟨F.σ × G.σ,
{ f := fun ⟨s, t⟩ ↦ F.F s ∩ G.F t
pt := (F.F.pt, G.F.pt)
inf := fun ⟨a, a'⟩ ⟨b, b'⟩ ↦ (F.F.inf a b, G.F.inf a' b')
inf_le_left := fun _ _ ↦ inter_subset_inter (F.F.inf_le_left _ _) (G.F.inf_le_left _ _)
inf_le_right := fun _ _ ↦ inter_subset_inter (F.F.inf_le_right _ _) (G.F.inf_le_right _ _) },
by
cases F; cases G; substs f g; simp only [CFilter.toFilter, Prod.exists]; ext
constructor
· rintro ⟨s, t, h⟩
apply mem_inf_of_inter _ _ h
· use s
· use t
· rintro ⟨_, ⟨a, ha⟩, _, ⟨b, hb⟩, rfl⟩
exact ⟨a, b, inter_subset_inter ha hb⟩⟩
/-- Construct a realizer for the cofinite filter -/
protected def cofinite [DecidableEq α] : (@cofinite α).Realizer :=
⟨Finset α,
{ f := fun s ↦ { a | a ∉ s }
pt := ∅
inf := (· ∪ ·)
inf_le_left := fun _ _ _ ↦ mt (Finset.mem_union_left _)
inf_le_right := fun _ _ _ ↦ mt (Finset.mem_union_right _) },
filter_eq <|
Set.ext fun _ ↦
⟨fun ⟨s, h⟩ ↦ s.finite_toSet.subset (compl_subset_comm.1 h), fun h ↦
⟨h.toFinset, by simp⟩⟩⟩
/-- Construct a realizer for filter bind -/
protected def bind {f : Filter α} {m : α → Filter β} (F : f.Realizer) (G : ∀ i, (m i).Realizer) :
(f.bind m).Realizer :=
⟨Σ s : F.σ, ∀ i ∈ F.F s, (G i).σ,
{ f := fun ⟨s, f⟩ ↦ ⋃ i ∈ F.F s, (G i).F (f i (by assumption))
pt := ⟨F.F.pt, fun i _ ↦ (G i).F.pt⟩
inf := fun ⟨a, f⟩ ⟨b, f'⟩ ↦
⟨F.F.inf a b, fun i h ↦
(G i).F.inf (f i (F.F.inf_le_left _ _ h)) (f' i (F.F.inf_le_right _ _ h))⟩
inf_le_left := fun _ _ _ ↦ by
simp only [mem_iUnion, forall_exists_index]
exact fun i h₁ h₂ ↦ ⟨i, F.F.inf_le_left _ _ h₁, (G i).F.inf_le_left _ _ h₂⟩
inf_le_right := fun _ _ _ ↦ by
simp only [mem_iUnion, forall_exists_index]
exact fun i h₁ h₂ ↦ ⟨i, F.F.inf_le_right _ _ h₁, (G i).F.inf_le_right _ _ h₂⟩ },
filter_eq <| Set.ext fun _ ↦ by
obtain ⟨_, F, _⟩ := F; subst f
simp only [CFilter.toFilter, iUnion_subset_iff, Sigma.exists, Filter.mem_sets, mem_bind]
exact
⟨fun ⟨s, f, h⟩ ↦
⟨F s, ⟨s, Subset.refl _⟩, fun i H ↦ (G i).mem_sets.2 ⟨f i H, fun _ h' ↦ h i H h'⟩⟩,
fun ⟨_, ⟨s, h⟩, f⟩ ↦
let ⟨f', h'⟩ := Classical.axiom_of_choice fun i : F s ↦ (G i).mem_sets.1 (f i (h i.2))
⟨s, fun i h ↦ f' ⟨i, h⟩, fun _ H _ m ↦ h' ⟨_, H⟩ m⟩⟩⟩
/-- Construct a realizer for indexed supremum -/
protected def iSup {f : α → Filter β} (F : ∀ i, (f i).Realizer) : (⨆ i, f i).Realizer :=
let F' : (⨆ i, f i).Realizer :=
(Realizer.bind Realizer.top F).ofEq <|
filter_eq <| Set.ext <| by simp [Filter.bind, iSup_sets_eq]
F'.ofEquiv <|
show (Σ _ : Unit, ∀ i : α, True → (F i).σ) ≃ ∀ i, (F i).σ from
⟨fun ⟨_, f⟩ i ↦ f i ⟨⟩, fun f ↦ ⟨(), fun i _ ↦ f i⟩, fun _ ↦ rfl, fun _ ↦ rfl⟩
/-- Construct a realizer for the product of filters -/
protected def prod {f g : Filter α} (F : f.Realizer) (G : g.Realizer) : (f ×ˢ g).Realizer :=
(F.comap _).inf (G.comap _)
theorem le_iff {f g : Filter α} (F : f.Realizer) (G : g.Realizer) :
f ≤ g ↔ ∀ b : G.σ, ∃ a : F.σ, F.F a ≤ G.F b :=
⟨fun H t ↦ F.mem_sets.1 (H (G.mem_sets.2 ⟨t, Subset.refl _⟩)), fun H _ h ↦
F.mem_sets.2 <|
let ⟨s, h₁⟩ := G.mem_sets.1 h
let ⟨t, h₂⟩ := H s
⟨t, Subset.trans h₂ h₁⟩⟩
theorem tendsto_iff (f : α → β) {l₁ : Filter α} {l₂ : Filter β} (L₁ : l₁.Realizer)
(L₂ : l₂.Realizer) : Tendsto f l₁ l₂ ↔ ∀ b, ∃ a, ∀ x ∈ L₁.F a, f x ∈ L₂.F b :=
(le_iff (L₁.map f) L₂).trans <| forall_congr' fun _ ↦ exists_congr fun _ ↦ image_subset_iff
theorem ne_bot_iff {f : Filter α} (F : f.Realizer) : f ≠ ⊥ ↔ ∀ a : F.σ, (F.F a).Nonempty := by
rw [not_iff_comm, ← le_bot_iff, F.le_iff Realizer.bot, not_forall]
simp only [Set.not_nonempty_iff_eq_empty]
exact ⟨fun ⟨x, e⟩ _ ↦ ⟨x, le_of_eq e⟩, fun h ↦
let ⟨x, h⟩ := h ()
⟨x, le_bot_iff.1 h⟩⟩
end Filter.Realizer
|
HalesJewett.lean
|
/-
Copyright (c) 2021 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.Data.Fintype.Option
import Mathlib.Data.Fintype.Shrink
import Mathlib.Data.Fintype.Sum
import Mathlib.Data.Finite.Prod
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# The Hales-Jewett theorem
We prove the Hales-Jewett theorem. We deduce Van der Waerden's theorem and the multidimensional
Hales-Jewett theorem as corollaries.
The Hales-Jewett theorem is a result in Ramsey theory dealing with *combinatorial lines*. Given
an 'alphabet' `α : Type*` and `a b : α`, an example of a combinatorial line in `α^5` is
`{ (a, x, x, b, x) | x : α }`. See `Combinatorics.Line` for a precise general definition. The
Hales-Jewett theorem states that for any fixed finite types `α` and `κ`, there exists a (potentially
huge) finite type `ι` such that whenever `ι → α` is `κ`-colored (i.e. for any coloring
`C : (ι → α) → κ`), there exists a monochromatic line. We prove the Hales-Jewett theorem using
the idea of *color focusing* and a *product argument*. See the proof of
`Combinatorics.Line.exists_mono_in_high_dimension'` for details.
*Combinatorial subspaces* are higher-dimensional analogues of combinatorial lines. See
`Combinatorics.Subspace`. The multidimensional Hales-Jewett theorem generalises the statement above
from combinatorial lines to combinatorial subspaces of a fixed dimension.
The version of Van der Waerden's theorem in this file states that whenever a commutative monoid `M`
is finitely colored and `S` is a finite subset, there exists a monochromatic homothetic copy of `S`.
This follows from the Hales-Jewett theorem by considering the map `(ι → S) → M` sending `v`
to `∑ i : ι, v i`, which sends a combinatorial line to a homothetic copy of `S`.
## Main results
- `Combinatorics.Line.exists_mono_in_high_dimension`: The Hales-Jewett theorem.
- `Combinatorics.Subspace.exists_mono_in_high_dimension`: The multidimensional Hales-Jewett theorem.
- `Combinatorics.exists_mono_homothetic_copy`: A generalization of Van der Waerden's theorem.
## Implementation details
For convenience, we work directly with finite types instead of natural numbers. That is, we write
`α, ι, κ` for (finite) types where one might traditionally use natural numbers `n, H, c`. This
allows us to work directly with `α`, `Option α`, `(ι → α) → κ`, and `ι ⊕ ι'` instead of `Fin n`,
`Fin (n+1)`, `Fin (c^(n^H))`, and `Fin (H + H')`.
## TODO
- Prove a finitary version of Van der Waerden's theorem (either by compactness or by modifying the
current proof).
- One could reformulate the proof of Hales-Jewett to give explicit upper bounds on the number of
coordinates needed.
## Tags
combinatorial line, Ramsey theory, arithmetic progression
### References
* https://en.wikipedia.org/wiki/Hales%E2%80%93Jewett_theorem
-/
open Function
open scoped Finset
universe u v
variable {η α ι κ : Type*}
namespace Combinatorics
/-- The type of combinatorial subspaces. A subspace `l : Subspace η α ι` in the hypercube `ι → α`
defines a function `(η → α) → ι → α` from `η → α` to the hypercube, such that for each coordinate
`i : ι` and direction `e : η`, the function `fun x ↦ l x i` is either `fun x ↦ x e` for some
direction `e : η` or constant. We require subspaces to be non-degenerate in the sense that, for
every `e : η`, `fun x ↦ l x i` is `fun x ↦ x e` for at least one `i`.
Formally, a subspace is represented by a word `l.idxFun : ι → α ⊕ η` which says whether
`fun x ↦ l x i` is `fun x ↦ x e` (corresponding to `l.idxFun i = Sum.inr e`) or constantly `a`
(corresponding to `l.idxFun i = Sum.inl a`).
When `α` has size `1` there can be many elements of `Subspace η α ι` defining the same function. -/
@[ext]
structure Subspace (η α ι : Type*) where
/-- The word representing a combinatorial subspace. `l.idxfun i = Sum.inr e` means that
`l x i = x e` for all `x` and `l.idxfun i = some a` means that `l x i = a` for all `x`. -/
idxFun : ι → α ⊕ η
/-- We require combinatorial subspaces to be nontrivial in the sense that `fun x ↦ l x i` is
`fun x ↦ x e` for at least one coordinate `i`. -/
proper : ∀ e, ∃ i, idxFun i = Sum.inr e
namespace Subspace
variable {η α ι κ : Type*} {l : Subspace η α ι} {x : η → α} {i : ι} {a : α} {e : η}
/-- The combinatorial subspace corresponding to the identity embedding `(ι → α) → (ι → α)`. -/
instance : Inhabited (Subspace ι α ι) := ⟨⟨Sum.inr, fun i ↦ ⟨i, rfl⟩⟩⟩
/-- Consider a subspace `l : Subspace η α ι` as a function `(η → α) → ι → α`. -/
@[coe] def toFun (l : Subspace η α ι) (x : η → α) (i : ι) : α := (l.idxFun i).elim id x
instance instCoeFun : CoeFun (Subspace η α ι) (fun _ ↦ (η → α) → ι → α) := ⟨toFun⟩
lemma coe_apply (l : Subspace η α ι) (x : η → α) (i : ι) : l x i = (l.idxFun i).elim id x := rfl
-- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions
lemma coe_injective [Nontrivial α] : Injective ((⇑) : Subspace η α ι → (η → α) → ι → α) := by
classical
rintro l m hlm
ext i
simp only [funext_iff] at hlm
cases hl : idxFun l i with
| inl a =>
obtain ⟨b, hba⟩ := exists_ne a
cases hm : idxFun m i <;> simpa [hl, hm, hba.symm, coe_apply] using hlm (const _ b) i
| inr e =>
cases hm : idxFun m i with
| inl a =>
obtain ⟨b, hba⟩ := exists_ne a
simpa [hl, hm, hba, coe_apply] using hlm (const _ b) i
| inr f =>
obtain ⟨a, b, hab⟩ := exists_pair_ne α
simp only [Sum.inr.injEq]
by_contra! hef
simpa [hl, hm, hef, hab, coe_apply] using hlm (Function.update (const _ a) f b) i
lemma apply_def (l : Subspace η α ι) (x : η → α) (i : ι) : l x i = (l.idxFun i).elim id x := rfl
lemma apply_inl (h : l.idxFun i = Sum.inl a) : l x i = a := by simp [apply_def, h]
lemma apply_inr (h : l.idxFun i = Sum.inr e) : l x i = x e := by simp [apply_def, h]
/-- Given a coloring `C` of `ι → α` and a combinatorial subspace `l` of `ι → α`, `l.IsMono C`
means that `l` is monochromatic with regard to `C`. -/
def IsMono (C : (ι → α) → κ) (l : Subspace η α ι) : Prop := ∃ c, ∀ x, C (l x) = c
variable {η' α' ι' : Type*}
/-- Change the index types of a subspace. -/
def reindex (l : Subspace η α ι) (eη : η ≃ η') (eα : α ≃ α') (eι : ι ≃ ι') : Subspace η' α' ι' where
idxFun i := (l.idxFun <| eι.symm i).map eα eη
proper e := (eι.exists_congr fun i ↦ by cases h : idxFun l i <;>
simp [*, Equiv.eq_symm_apply]).1 <| l.proper <| eη.symm e
@[simp] lemma reindex_apply (l : Subspace η α ι) (eη : η ≃ η') (eα : α ≃ α') (eι : ι ≃ ι') (x i) :
l.reindex eη eα eι x i = eα (l (eα.symm ∘ x ∘ eη) <| eι.symm i) := by
cases h : l.idxFun (eι.symm i) <;> simp [h, reindex, coe_apply]
@[simp] lemma reindex_isMono {eη : η ≃ η'} {eα : α ≃ α'} {eι : ι ≃ ι'} {C : (ι' → α') → κ} :
(l.reindex eη eα eι).IsMono C ↔ l.IsMono fun x ↦ C <| eα ∘ x ∘ eι.symm := by
simp only [IsMono, funext (reindex_apply _ _ _ _ _), coe_apply]
exact exists_congr fun c ↦ (eη.arrowCongr eα).symm.forall_congr <| by aesop
protected lemma IsMono.reindex {eη : η ≃ η'} {eα : α ≃ α'} {eι : ι ≃ ι'} {C : (ι → α) → κ}
(hl : l.IsMono C) : (l.reindex eη eα eι).IsMono fun x ↦ C <| eα.symm ∘ x ∘ eι := by
simp [reindex_isMono, Function.comp_assoc]; simpa [← Function.comp_assoc]
end Subspace
/-- The type of combinatorial lines. A line `l : Line α ι` in the hypercube `ι → α` defines a
function `α → ι → α` from `α` to the hypercube, such that for each coordinate `i : ι`, the function
`fun x ↦ l x i` is either `id` or constant. We require lines to be nontrivial in the sense that
`fun x ↦ l x i` is `id` for at least one `i`.
Formally, a line is represented by a word `l.idxFun : ι → Option α` which says whether
`fun x ↦ l x i` is `id` (corresponding to `l.idxFun i = none`) or constantly `y` (corresponding to
`l.idxFun i = some y`).
When `α` has size `1` there can be many elements of `Line α ι` defining the same function. -/
@[ext]
structure Line (α ι : Type*) where
/-- The word representing a combinatorial line. `l.idxfun i = none` means that
`l x i = x` for all `x` and `l.idxfun i = some y` means that `l x i = y`. -/
idxFun : ι → Option α
/-- We require combinatorial lines to be nontrivial in the sense that `fun x ↦ l x i` is `id` for
at least one coordinate `i`. -/
proper : ∃ i, idxFun i = none
namespace Line
variable {l : Line α ι} {i : ι} {a x : α}
/-- Consider a line `l : Line α ι` as a function `α → ι → α`. -/
@[coe] def toFun (l : Line α ι) (x : α) (i : ι) : α := (l.idxFun i).getD x
-- This lets us treat a line `l : Line α ι` as a function `α → ι → α`.
instance instCoeFun : CoeFun (Line α ι) fun _ => α → ι → α := ⟨toFun⟩
@[simp] lemma coe_apply (l : Line α ι) (x : α) (i : ι) : l x i = (l.idxFun i).getD x := rfl
-- Note: This is not made a `FunLike` instance to avoid having two syntactically different coercions
lemma coe_injective [Nontrivial α] : Injective ((⇑) : Line α ι → α → ι → α) := by
rintro l m hlm
ext i a
obtain ⟨b, hba⟩ := exists_ne a
simp only [funext_iff] at hlm ⊢
refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩
· cases hi : idxFun m i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i
· cases hi : idxFun l i <;> simpa [@eq_comm _ a, hi, h, hba] using hlm b i
/-- A line is monochromatic if all its points are the same color. -/
def IsMono {α ι κ} (C : (ι → α) → κ) (l : Line α ι) : Prop :=
∃ c, ∀ x, C (l x) = c
/-- Consider a line as a one-dimensional subspace. -/
def toSubspaceUnit (l : Line α ι) : Subspace Unit α ι where
idxFun i := (l.idxFun i).elim (.inr ()) .inl
proper _ := l.proper.imp fun i hi ↦ by simp [hi]
@[simp] lemma toSubspaceUnit_apply (l : Line α ι) (a) : ⇑l.toSubspaceUnit a = l (a ()) := by
ext i; cases h : l.idxFun i <;> simp [toSubspaceUnit, h, Subspace.coe_apply]
@[simp] lemma toSubspaceUnit_isMono {C : (ι → α) → κ} : l.toSubspaceUnit.IsMono C ↔ l.IsMono C := by
simp only [Subspace.IsMono, toSubspaceUnit_apply, IsMono]
exact exists_congr fun c ↦ ⟨fun h a ↦ h fun _ ↦ a, fun h a ↦ h _⟩
protected alias ⟨_, IsMono.toSubspaceUnit⟩ := toSubspaceUnit_isMono
/-- Consider a line in `ι → η → α` as a `η`-dimensional subspace in `ι × η → α`. -/
def toSubspace (l : Line (η → α) ι) : Subspace η α (ι × η) where
idxFun ie := (l.idxFun ie.1).elim (.inr ie.2) (fun f ↦ .inl <| f ie.2)
proper e := let ⟨i, hi⟩ := l.proper; ⟨(i, e), by simp [hi]⟩
@[simp] lemma toSubspace_apply (l : Line (η → α) ι) (a ie) :
⇑l.toSubspace a ie = l a ie.1 ie.2 := by
cases h : l.idxFun ie.1 <;> simp [toSubspace, h, coe_apply, Subspace.coe_apply]
@[simp] lemma toSubspace_isMono {l : Line (η → α) ι} {C : (ι × η → α) → κ} :
l.toSubspace.IsMono C ↔ l.IsMono fun x : ι → η → α ↦ C fun (i, e) ↦ x i e := by
simp [Subspace.IsMono, IsMono, funext (toSubspace_apply _ _)]
protected alias ⟨_, IsMono.toSubspace⟩ := toSubspace_isMono
/-- The diagonal line. It is the identity at every coordinate. -/
def diagonal (α ι) [Nonempty ι] : Line α ι where
idxFun _ := none
proper := ⟨Classical.arbitrary ι, rfl⟩
instance (α ι) [Nonempty ι] : Inhabited (Line α ι) :=
⟨diagonal α ι⟩
/-- The type of lines that are only one color except possibly at their endpoints. -/
structure AlmostMono {α ι κ : Type*} (C : (ι → Option α) → κ) where
/-- The underlying line of an almost monochromatic line, where the coordinate dimension `α` is
extended by an additional symbol `none`, thought to be marking the endpoint of the line. -/
line : Line (Option α) ι
/-- The main color of an almost monochromatic line. -/
color : κ
/-- The proposition that the underlying line of an almost monochromatic line assumes its main
color except possibly at the endpoints. -/
has_color : ∀ x : α, C (line (some x)) = color
instance {α ι κ : Type*} [Nonempty ι] [Inhabited κ] :
Inhabited (AlmostMono fun _ : ι → Option α => (default : κ)) :=
⟨{ line := default
color := default
has_color := fun _ ↦ rfl}⟩
/-- The type of collections of lines such that
- each line is only one color except possibly at its endpoint
- the lines all have the same endpoint
- the colors of the lines are distinct.
Used in the proof `exists_mono_in_high_dimension`. -/
structure ColorFocused {α ι κ : Type*} (C : (ι → Option α) → κ) where
/-- The underlying multiset of almost monochromatic lines of a color-focused collection. -/
lines : Multiset (AlmostMono C)
/-- The common endpoint of the lines in the color-focused collection. -/
focus : ι → Option α
/-- The proposition that all lines in a color-focused collection have the same endpoint. -/
is_focused : ∀ p ∈ lines, p.line none = focus
/-- The proposition that all lines in a color-focused collection of lines have distinct colors. -/
distinct_colors : (lines.map AlmostMono.color).Nodup
instance {α ι κ} (C : (ι → Option α) → κ) : Inhabited (ColorFocused C) := by
refine ⟨⟨0, fun _ => none, fun h => ?_, Multiset.nodup_zero⟩⟩
simp only [Multiset.notMem_zero, IsEmpty.forall_iff]
/-- A function `f : α → α'` determines a function `line α ι → line α' ι`. For a coordinate `i`
`l.map f` is the identity at `i` if `l` is, and constantly `f y` if `l` is constantly `y` at `i`. -/
def map {α α' ι} (f : α → α') (l : Line α ι) : Line α' ι where
idxFun i := (l.idxFun i).map f
proper := ⟨l.proper.choose, by simp only [l.proper.choose_spec, Option.map_none]⟩
/-- A point in `ι → α` and a line in `ι' → α` determine a line in `ι ⊕ ι' → α`. -/
def vertical {α ι ι'} (v : ι → α) (l : Line α ι') : Line α (ι ⊕ ι') where
idxFun := Sum.elim (some ∘ v) l.idxFun
proper := ⟨Sum.inr l.proper.choose, l.proper.choose_spec⟩
/-- A line in `ι → α` and a point in `ι' → α` determine a line in `ι ⊕ ι' → α`. -/
def horizontal {α ι ι'} (l : Line α ι) (v : ι' → α) : Line α (ι ⊕ ι') where
idxFun := Sum.elim l.idxFun (some ∘ v)
proper := ⟨Sum.inl l.proper.choose, l.proper.choose_spec⟩
/-- One line in `ι → α` and one in `ι' → α` together determine a line in `ι ⊕ ι' → α`. -/
def prod {α ι ι'} (l : Line α ι) (l' : Line α ι') : Line α (ι ⊕ ι') where
idxFun := Sum.elim l.idxFun l'.idxFun
proper := ⟨Sum.inl l.proper.choose, l.proper.choose_spec⟩
theorem apply_def (l : Line α ι) (x : α) : l x = fun i => (l.idxFun i).getD x := rfl
theorem apply_none {α ι} (l : Line α ι) (x : α) (i : ι) (h : l.idxFun i = none) : l x i = x := by
simp only [Option.getD_none, h, l.apply_def]
lemma apply_some (h : l.idxFun i = some a) : l x i = a := by simp [h]
@[simp]
theorem map_apply {α α' ι} (f : α → α') (l : Line α ι) (x : α) : l.map f (f x) = f ∘ l x := by
simp only [Line.apply_def, Line.map, Option.getD_map, comp_def]
@[simp]
theorem vertical_apply {α ι ι'} (v : ι → α) (l : Line α ι') (x : α) :
l.vertical v x = Sum.elim v (l x) := by
funext i
cases i <;> rfl
@[simp]
theorem horizontal_apply {α ι ι'} (l : Line α ι) (v : ι' → α) (x : α) :
l.horizontal v x = Sum.elim (l x) v := by
funext i
cases i <;> rfl
@[simp]
theorem prod_apply {α ι ι'} (l : Line α ι) (l' : Line α ι') (x : α) :
l.prod l' x = Sum.elim (l x) (l' x) := by
funext i
cases i <;> rfl
@[simp]
theorem diagonal_apply {α ι} [Nonempty ι] (x : α) : diagonal α ι x = fun _ => x := by
ext; simp [diagonal]
/-- The **Hales-Jewett theorem**. This version has a restriction on universe levels which is
necessary for the proof. See `exists_mono_in_high_dimension` for a fully universe-polymorphic
version. -/
private theorem exists_mono_in_high_dimension' :
∀ (α : Type u) [Finite α] (κ : Type max v u) [Finite κ],
∃ (ι : Type) (_ : Fintype ι), ∀ C : (ι → α) → κ, ∃ l : Line α ι, l.IsMono C :=
-- The proof proceeds by induction on `α`.
Finite.induction_empty_option
(-- We have to show that the theorem is invariant under `α ≃ α'` for the induction to work.
fun {α α'} e =>
forall_imp fun κ =>
forall_imp fun _ =>
Exists.imp fun ι =>
Exists.imp fun _ h C =>
let ⟨l, c, lc⟩ := h fun v => C (e ∘ v)
⟨l.map e, c, e.forall_congr_right.mp fun x => by rw [← lc x, Line.map_apply]⟩)
(by
-- This deals with the degenerate case where `α` is empty.
intro κ _
by_cases h : Nonempty κ
· refine ⟨Unit, inferInstance, fun C => ⟨default, Classical.arbitrary _, PEmpty.rec⟩⟩
· exact ⟨Empty, inferInstance, fun C => (h ⟨C (Empty.rec)⟩).elim⟩)
(by
-- Now we have to show that the theorem holds for `Option α` if it holds for `α`.
intro α _ ihα κ _
cases nonempty_fintype κ
-- Later we'll need `α` to be nonempty. So we first deal with the trivial case where `α` is
-- empty.
-- Then `Option α` has only one element, so any line is monochromatic.
by_cases h : Nonempty α
case neg =>
refine ⟨Unit, inferInstance, fun C => ⟨diagonal _ Unit, C fun _ => none, ?_⟩⟩
rintro (_ | ⟨a⟩)
· rfl
· exact (h ⟨a⟩).elim
-- The key idea is to show that for every `r`, in high dimension we can either find
-- `r` color focused lines or a monochromatic line.
suffices key :
∀ r : ℕ,
∃ (ι : Type) (_ : Fintype ι),
∀ C : (ι → Option α) → κ,
(∃ s : ColorFocused C, Multiset.card s.lines = r) ∨ ∃ l, IsMono C l by
-- Given the key claim, we simply take `r = |κ| + 1`. We cannot have this many distinct colors
-- so we must be in the second case, where there is a monochromatic line.
obtain ⟨ι, _inst, hι⟩ := key (Fintype.card κ + 1)
refine ⟨ι, _inst, fun C => (hι C).resolve_left ?_⟩
rintro ⟨s, sr⟩
apply Nat.not_succ_le_self (Fintype.card κ)
rw [← Nat.add_one, ← sr, ← Multiset.card_map, ← Finset.card_mk]
exact Finset.card_le_univ ⟨_, s.distinct_colors⟩
-- We now prove the key claim, by induction on `r`.
intro r
induction r with
-- The base case `r = 0` is trivial as the empty collection is color-focused.
| zero => exact ⟨Empty, inferInstance, fun C => Or.inl ⟨default, Multiset.card_zero⟩⟩
| succ r ihr =>
-- Supposing the key claim holds for `r`, we need to show it for `r+1`. First pick a high
-- enough dimension `ι` for `r`.
obtain ⟨ι, _inst, hι⟩ := ihr
-- Then since the theorem holds for `α` with any number of colors, pick a dimension `ι'` such
-- that `ι' → α` always has a monochromatic line whenever it is `(ι → Option α) → κ`-colored.
specialize ihα ((ι → Option α) → κ)
obtain ⟨ι', _inst, hι'⟩ := ihα
-- We claim that `ι ⊕ ι'` works for `Option α` and `κ`-coloring.
refine ⟨ι ⊕ ι', inferInstance, ?_⟩
intro C
-- A `κ`-coloring of `ι ⊕ ι' → Option α` induces an `(ι → Option α) → κ`-coloring of `ι' → α`.
specialize hι' fun v' v => C (Sum.elim v (some ∘ v'))
-- By choice of `ι'` this coloring has a monochromatic line `l'` with color class `C'`, where
-- `C'` is a `κ`-coloring of `ι → α`.
obtain ⟨l', C', hl'⟩ := hι'
-- If `C'` has a monochromatic line, then so does `C`. We use this in two places below.
have mono_of_mono : (∃ l, IsMono C' l) → ∃ l, IsMono C l := by
rintro ⟨l, c, hl⟩
refine ⟨l.horizontal (some ∘ l' (Classical.arbitrary α)), c, fun x => ?_⟩
rw [Line.horizontal_apply, ← hl, ← hl']
-- By choice of `ι`, `C'` either has `r` color-focused lines or a monochromatic line.
specialize hι C'
rcases hι with (⟨s, sr⟩ | h)
on_goal 2 => exact Or.inr (mono_of_mono h)
-- Here we assume `C'` has `r` color focused lines. We split into cases depending on whether
-- one of these `r` lines has the same color as the focus point.
by_cases h : ∃ p ∈ s.lines, (p : AlmostMono _).color = C' s.focus
-- If so then this is a `C'`-monochromatic line and we are done.
· obtain ⟨p, p_mem, hp⟩ := h
refine Or.inr (mono_of_mono ⟨p.line, p.color, ?_⟩)
rintro (_ | _)
· rw [hp, s.is_focused p p_mem]
· apply p.has_color
-- If not, we get `r+1` color focused lines by taking the product of the `r` lines with `l'`
-- and adding to this the vertical line obtained by the focus point and `l`.
refine Or.inl ⟨⟨(s.lines.map ?_).cons ⟨(l'.map some).vertical s.focus, C' s.focus, fun x => ?_⟩,
Sum.elim s.focus (l'.map some none), ?_, ?_⟩, ?_⟩
-- The product lines are almost monochromatic.
· refine fun p => ⟨p.line.prod (l'.map some), p.color, fun x => ?_⟩
rw [Line.prod_apply, Line.map_apply, ← p.has_color, ← congr_fun (hl' x)]
-- The vertical line is almost monochromatic.
· rw [vertical_apply, ← congr_fun (hl' x), Line.map_apply]
-- Our `r+1` lines have the same endpoint.
· simp_rw [Multiset.mem_cons, Multiset.mem_map]
rintro _ (rfl | ⟨q, hq, rfl⟩)
· simp only [vertical_apply]
· simp only [prod_apply, s.is_focused q hq]
-- Our `r+1` lines have distinct colors (this is why we needed to split into cases above).
· rw [Multiset.map_cons, Multiset.map_map, Multiset.nodup_cons, Multiset.mem_map]
exact ⟨fun ⟨q, hq, he⟩ => h ⟨q, hq, he⟩, s.distinct_colors⟩
-- Finally, we really do have `r+1` lines!
· rw [Multiset.card_cons, Multiset.card_map, sr])
/-- The **Hales-Jewett theorem**: For any finite types `α` and `κ`, there exists a finite type `ι`
such that whenever the hypercube `ι → α` is `κ`-colored, there is a monochromatic combinatorial
line. -/
theorem exists_mono_in_high_dimension (α : Type u) [Finite α] (κ : Type v) [Finite κ] :
∃ (ι : Type) (_ : Fintype ι), ∀ C : (ι → α) → κ, ∃ l : Line α ι, l.IsMono C :=
let ⟨ι, ιfin, hι⟩ := exists_mono_in_high_dimension'.{u,v} α (ULift.{u,v} κ)
⟨ι, ιfin, fun C =>
let ⟨l, c, hc⟩ := hι (ULift.up ∘ C)
⟨l, c.down, fun x => by rw [← hc x, Function.comp_apply]⟩⟩
end Line
/-- A generalization of Van der Waerden's theorem: if `M` is a finitely colored commutative
monoid, and `S` is a finite subset, then there exists a monochromatic homothetic copy of `S`. -/
theorem exists_mono_homothetic_copy {M κ : Type*} [AddCommMonoid M] (S : Finset M) [Finite κ]
(C : M → κ) : ∃ a > 0, ∃ (b : M) (c : κ), ∀ s ∈ S, C (a • s + b) = c := by
classical
obtain ⟨ι, _inst, hι⟩ := Line.exists_mono_in_high_dimension S κ
specialize hι fun v => C <| ∑ i, v i
obtain ⟨l, c, hl⟩ := hι
set s : Finset ι := {i | l.idxFun i = none} with hs
refine ⟨#s, Finset.card_pos.mpr ⟨l.proper.choose, ?_⟩, ∑ i ∈ sᶜ, ((l.idxFun i).map ?_).getD 0,
c, ?_⟩
· rw [hs, Finset.mem_filter]
exact ⟨Finset.mem_univ _, l.proper.choose_spec⟩
· exact fun m => m
intro x xs
rw [← hl ⟨x, xs⟩]
clear hl; congr
rw [← Finset.sum_add_sum_compl s]
congr 1
· rw [← Finset.sum_const]
apply Finset.sum_congr rfl
intro i hi
rw [hs, Finset.mem_filter] at hi
rw [l.apply_none _ _ hi.right, Subtype.coe_mk]
· apply Finset.sum_congr rfl
intro i hi
rw [hs, Finset.compl_filter, Finset.mem_filter] at hi
obtain ⟨y, hy⟩ := Option.ne_none_iff_exists.mp hi.right
simp [← hy, Option.map_some, Option.getD]
namespace Subspace
/-- The **multidimensional Hales-Jewett theorem**, aka **extended Hales-Jewett theorem**: For any
finite types `η`, `α` and `κ`, there exists a finite type `ι` such that whenever the hypercube
`ι → α` is `κ`-colored, there is a monochromatic combinatorial subspace of dimension `η`. -/
theorem exists_mono_in_high_dimension (α κ η) [Finite α] [Finite κ] [Finite η] :
∃ (ι : Type) (_ : Fintype ι), ∀ C : (ι → α) → κ, ∃ l : Subspace η α ι, l.IsMono C := by
cases nonempty_fintype η
obtain ⟨ι, _, hι⟩ := Line.exists_mono_in_high_dimension (Shrink.{0} η → α) κ
refine ⟨ι × Shrink η, inferInstance, fun C ↦ ?_⟩
obtain ⟨l, hl⟩ := hι fun x ↦ C fun (i, e) ↦ x i e
refine ⟨l.toSubspace.reindex (equivShrink.{0} η).symm (Equiv.refl _) (Equiv.refl _), ?_⟩
convert hl.toSubspace.reindex
simp
/-- A variant of the **extended Hales-Jewett theorem** `exists_mono_in_high_dimension` where the
returned type is some `Fin n` instead of a general fintype. -/
theorem exists_mono_in_high_dimension_fin (α κ η) [Finite α] [Finite κ] [Finite η] :
∃ n, ∀ C : (Fin n → α) → κ, ∃ l : Subspace η α (Fin n), l.IsMono C := by
obtain ⟨ι, ιfin, hι⟩ := exists_mono_in_high_dimension α κ η
refine ⟨Fintype.card ι, fun C ↦ ?_⟩
obtain ⟨l, c, cl⟩ := hι fun v ↦ C (v ∘ (Fintype.equivFin _).symm)
refine ⟨⟨l.idxFun ∘ (Fintype.equivFin _).symm, fun e ↦ ?_⟩, c, cl⟩
obtain ⟨i, hi⟩ := l.proper e
use Fintype.equivFin _ i
simpa using hi
end Subspace
end Combinatorics
|
Operations.lean
|
/-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Jireh Loreaux, Yunzhou Xie
-/
import Mathlib.Algebra.Group.Subgroup.Map
import Mathlib.Algebra.Module.Opposite
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.RingTheory.Congruence.Opposite
import Mathlib.RingTheory.Ideal.Defs
import Mathlib.RingTheory.TwoSidedIdeal.Lattice
import Mathlib.Algebra.Group.Pointwise.Set.Basic
/-!
# Operations on two-sided ideals
This file defines operations on two-sided ideals of a ring `R`.
## Main definitions and results
- `TwoSidedIdeal.span`: the span of `s ⊆ R` is the smallest two-sided ideal containing the set.
- `TwoSidedIdeal.mem_span_iff_mem_addSubgroup_closure_nonunital`: in an associative but non-unital
ring, an element `x` is in the two-sided ideal spanned by `s` if and only if `x` is in the closure
of `s ∪ {y * a | y ∈ s, a ∈ R} ∪ {a * y | y ∈ s, a ∈ R} ∪ {a * y * b | y ∈ s, a, b ∈ R}` as an
additive subgroup.
- `TwoSidedIdeal.mem_span_iff_mem_addSubgroup_closure`: in a unital and associative ring, an
element `x` is in the two-sided ideal spanned by `s` if and only if `x` is in the closure of
`{a*y*b | a, b ∈ R, y ∈ s}` as an additive subgroup.
- `TwoSidedIdeal.comap`: pullback of a two-sided ideal; defined as the preimage of a
two-sided ideal.
- `TwoSidedIdeal.map`: pushforward of a two-sided ideal; defined as the span of the image of a
two-sided ideal.
- `TwoSidedIdeal.ker`: the kernel of a ring homomorphism as a two-sided ideal.
- `TwoSidedIdeal.gc`: `fromIdeal` and `asIdeal` form a Galois connection where
`fromIdeal : Ideal R → TwoSidedIdeal R` is defined as the smallest two-sided ideal containing an
ideal and `asIdeal : TwoSidedIdeal R → Ideal R` the inclusion map.
-/
namespace TwoSidedIdeal
section NonUnitalNonAssocRing
variable {R S : Type*} [NonUnitalNonAssocRing R] [NonUnitalNonAssocRing S]
variable {F : Type*} [FunLike F R S]
variable (f : F)
/--
The smallest two-sided ideal containing a set.
-/
abbrev span (s : Set R) : TwoSidedIdeal R :=
{ ringCon := ringConGen (fun a b ↦ a - b ∈ s) }
lemma subset_span {s : Set R} : s ⊆ (span s : Set R) := by
intro x hx
rw [SetLike.mem_coe, mem_iff]
exact RingConGen.Rel.of _ _ (by simpa using hx)
lemma mem_span_iff {s : Set R} {x} :
x ∈ span s ↔ ∀ (I : TwoSidedIdeal R), s ⊆ I → x ∈ I := by
refine ⟨?_, fun h => h _ subset_span⟩
delta span
rw [RingCon.ringConGen_eq]
intro h I hI
refine sInf_le (α := RingCon R) ?_ h
intro x y hxy
specialize hI hxy
rwa [SetLike.mem_coe, ← rel_iff] at hI
lemma span_mono {s t : Set R} (h : s ⊆ t) : span s ≤ span t := by
intro x hx
rw [mem_span_iff] at hx ⊢
exact fun I hI => hx I <| h.trans hI
lemma span_le {s : Set R} {I : TwoSidedIdeal R} : span s ≤ I ↔ s ⊆ I := by
rw [TwoSidedIdeal.ringCon_le_iff, RingCon.gi _ |>.gc]
exact ⟨fun h x hx ↦ by aesop, fun h x y hxy ↦ (rel_iff I x y).mpr (h hxy)⟩
/-- An induction principle for span membership.
If `p` holds for 0 and all elements of `s`,
and is preserved under addition and left and right multiplication,
then `p` holds for all elements of the span of `s`. -/
@[elab_as_elim]
theorem span_induction {s : Set R}
{p : (x : R) → x ∈ TwoSidedIdeal.span s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_span h))
(zero : p 0 (zero_mem _))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem _ hx hy))
(neg : ∀ x hx, p x hx → p (-x) (neg_mem _ hx))
(left_absorb : ∀ a x hx, p x hx → p (a * x) (mul_mem_left _ _ _ hx))
(right_absorb : ∀ b x hx, p x hx → p (x * b) (mul_mem_right _ _ _ hx))
{x : R} (hx : x ∈ span s) : p x hx :=
let J : TwoSidedIdeal R := .mk'
{x | ∃ hx, p x hx}
⟨zero_mem _, zero⟩
(fun ⟨hx1, hx2⟩ ⟨hy1, hy2⟩ ↦ ⟨add_mem _ hx1 hy1, add _ _ hx1 hy1 hx2 hy2⟩)
(fun ⟨hx1, hx2⟩ ↦ ⟨neg_mem _ hx1, neg _ hx1 hx2⟩)
(fun {x' y'} ⟨hy1, hy2⟩ ↦ ⟨mul_mem_left _ _ _ hy1, left_absorb _ _ _ hy2⟩)
(fun {x' y'} ⟨hx1, hx2⟩ ↦ ⟨mul_mem_right _ _ _ hx1, right_absorb _ _ _ hx2⟩)
span_le (s := s) (I := J) |>.2
(fun x hx ↦ ⟨by simpa using (mem_span_iff.2 fun I a ↦ a hx), by simp_all⟩) hx
|>.elim fun _ ↦ by simp
/--
Pushout of a two-sided ideal. Defined as the span of the image of a two-sided ideal under a ring
homomorphism.
-/
def map (I : TwoSidedIdeal R) : TwoSidedIdeal S :=
span (f '' I)
lemma map_mono {I J : TwoSidedIdeal R} (h : I ≤ J) :
map f I ≤ map f J :=
span_mono <| Set.image_mono h
variable [NonUnitalRingHomClass F R S]
/--
Preimage of a two-sided ideal, as a two-sided ideal. -/
def comap : TwoSidedIdeal S →o TwoSidedIdeal R where
toFun I := ⟨I.ringCon.comap f⟩
monotone' := by
intro I J h
rw [le_iff] at h
intro x
specialize @h (f x)
simpa [mem_iff, RingCon.comap]
lemma comap_le_comap {I J : TwoSidedIdeal S} (h : I ≤ J) :
comap f I ≤ comap f J :=
(comap f).monotone h
lemma mem_comap {I : TwoSidedIdeal S} {x : R} :
x ∈ I.comap f ↔ f x ∈ I := by
simp [comap, RingCon.comap, mem_iff]
/--
If `R` and `S` are isomorphic as rings, then two-sided ideals of `R` and two-sided ideals of `S` are
order isomorphic.
-/
def _root_.RingEquiv.mapTwoSidedIdeal (e : R ≃+* S) : TwoSidedIdeal R ≃o TwoSidedIdeal S :=
OrderIso.ofHomInv (comap e.symm) (comap e) (by ext; simp [mem_comap])
(by ext; simp [mem_comap])
lemma _root_.RingEquiv.mapTwoSidedIdeal_apply (e : R ≃+* S) (I : TwoSidedIdeal R) :
e.mapTwoSidedIdeal I = I.comap e.symm := rfl
lemma _root_.RingEquiv.mapTwoSidedIdeal_symm (e : R ≃+* S) :
e.mapTwoSidedIdeal.symm = e.symm.mapTwoSidedIdeal := rfl
end NonUnitalNonAssocRing
section NonAssocRing
variable {R S T : Type*}
variable [NonAssocRing R] [NonAssocRing S] [NonAssocRing T]
lemma comap_comap (I : TwoSidedIdeal T) (f : R →+* S) (g : S →+* T) :
(I.comap g).comap f = I.comap (g.comp f) := by
ext; simp [mem_comap]
end NonAssocRing
section NonUnitalRing
variable {R : Type*} [NonUnitalRing R]
open AddSubgroup in
/-- If `s : Set R` is absorbing under multiplication, then its `TwoSidedIdeal.span` coincides with
its `AddSubgroup.closure`, as sets. -/
lemma mem_span_iff_mem_addSubgroup_closure_absorbing {s : Set R}
(h_left : ∀ x y, y ∈ s → x * y ∈ s) (h_right : ∀ y x, y ∈ s → y * x ∈ s) {z : R} :
z ∈ span s ↔ z ∈ closure s := by
have h_left' {x y} (hy : y ∈ closure s) : x * y ∈ closure s := by
have := (AddMonoidHom.mulLeft x).map_closure s ▸ mem_map_of_mem _ hy
refine closure_mono ?_ this
rintro - ⟨y, hy, rfl⟩
exact h_left x y hy
have h_right' {y x} (hy : y ∈ closure s) : y * x ∈ closure s := by
have := (AddMonoidHom.mulRight x).map_closure s ▸ mem_map_of_mem _ hy
refine closure_mono ?_ this
rintro - ⟨y, hy, rfl⟩
exact h_right y x hy
let I : TwoSidedIdeal R := .mk' (closure s) (AddSubgroup.zero_mem _)
(AddSubgroup.add_mem _) (AddSubgroup.neg_mem _) h_left' h_right'
suffices z ∈ span s ↔ z ∈ I by simpa only [I, mem_mk', SetLike.mem_coe]
rw [mem_span_iff]
-- Suppose that for every ideal `J` with `s ⊆ J`, then `z ∈ J`. Apply this to `I` to get `z ∈ I`.
refine ⟨fun h ↦ h I fun x hx ↦ ?mem_closure_of_forall, fun hz J hJ ↦ ?mem_ideal_of_subset⟩
case mem_closure_of_forall => simpa only [I, SetLike.mem_coe, mem_mk'] using subset_closure hx
/- Conversely, suppose that `z ∈ I` and that `J` is any ideal containing `s`. Then by the
induction principle for `AddSubgroup`, we must also have `z ∈ J`. -/
case mem_ideal_of_subset =>
simp only [I, SetLike.mem_coe, mem_mk'] at hz
induction hz using closure_induction with
| mem x hx => exact hJ hx
| one => exact zero_mem _
| mul x y _ _ hx hy => exact J.add_mem hx hy
| inv x _ hx => exact J.neg_mem hx
open Pointwise Set
lemma set_mul_subset {s : Set R} {I : TwoSidedIdeal R} (h : s ⊆ I) (t : Set R) :
t * s ⊆ I := by
rintro - ⟨r, -, x, hx, rfl⟩
exact mul_mem_left _ _ _ (h hx)
lemma subset_mul_set {s : Set R} {I : TwoSidedIdeal R} (h : s ⊆ I) (t : Set R) :
s * t ⊆ I := by
rintro - ⟨x, hx, r, -, rfl⟩
exact mul_mem_right _ _ _ (h hx)
lemma mem_span_iff_mem_addSubgroup_closure_nonunital {s : Set R} {z : R} :
z ∈ span s ↔ z ∈ AddSubgroup.closure (s ∪ s * univ ∪ univ * s ∪ univ * s * univ) := by
trans z ∈ span (s ∪ s * univ ∪ univ * s ∪ univ * s * univ)
· refine ⟨(span_mono (by simp only [Set.union_assoc, Set.subset_union_left]) ·), fun h ↦ ?_⟩
refine mem_span_iff.mp h (span s) ?_
simp only [union_subset_iff, union_assoc]
exact ⟨subset_span, subset_mul_set subset_span _, set_mul_subset subset_span _,
subset_mul_set (set_mul_subset subset_span _) _⟩
· refine mem_span_iff_mem_addSubgroup_closure_absorbing ?_ ?_
· rintro x y (((hy | ⟨y, hy, r, -, rfl⟩) | ⟨r, -, y, hy, rfl⟩) |
⟨-, ⟨r', -, y, hy, rfl⟩, r, -, rfl⟩)
· exact .inl <| .inr <| ⟨x, mem_univ _, y, hy, rfl⟩
· exact .inr <| ⟨x * y, ⟨x, mem_univ _, y, hy, rfl⟩, r, mem_univ _, mul_assoc ..⟩
· exact .inl <| .inr <| ⟨x * r, mem_univ _, y, hy, mul_assoc ..⟩
· refine .inr <| ⟨x * r' * y, ⟨x * r', mem_univ _, y, hy, ?_⟩, ⟨r, mem_univ _, ?_⟩⟩
all_goals simp [mul_assoc]
· rintro y x (((hy | ⟨y, hy, r, -, rfl⟩) | ⟨r, -, y, hy, rfl⟩) |
⟨-, ⟨r', -, y, hy, rfl⟩, r, -, rfl⟩)
· exact .inl <| .inl <| .inr ⟨y, hy, x, mem_univ _, rfl⟩
· exact .inl <| .inl <| .inr ⟨y, hy, r * x, mem_univ _, (mul_assoc ..).symm⟩
· exact .inr <| ⟨r * y, ⟨r, mem_univ _, y, hy, rfl⟩, x, mem_univ _, rfl⟩
· refine .inr <| ⟨r' * y, ⟨r', mem_univ _, y, hy, rfl⟩, r * x, mem_univ _, ?_⟩
simp [mul_assoc]
end NonUnitalRing
section Ring
variable {R : Type*} [Ring R]
open Pointwise Set in
lemma mem_span_iff_mem_addSubgroup_closure {s : Set R} {z : R} :
z ∈ span s ↔ z ∈ AddSubgroup.closure (univ * s * univ) := by
trans z ∈ span (univ * s * univ)
· refine ⟨(span_mono (fun x hx ↦ ?_) ·), fun hz ↦ ?_⟩
· exact ⟨1 * x, ⟨1, mem_univ _, x, hx, rfl⟩, 1, mem_univ _, by simp⟩
· exact mem_span_iff.mp hz (span s) <| subset_mul_set (set_mul_subset subset_span _) _
· refine mem_span_iff_mem_addSubgroup_closure_absorbing ?_ ?_
· intro x y hy
rw [mul_assoc] at hy ⊢
obtain ⟨r, -, y, hy, rfl⟩ := hy
exact ⟨x * r, mem_univ _, y, hy, mul_assoc ..⟩
· rintro - x ⟨y, hy, r, -, rfl⟩
exact ⟨y, hy, r * x, mem_univ _, (mul_assoc ..).symm⟩
variable (I : TwoSidedIdeal R)
instance : SMul R I where smul r x := ⟨r • x.1, I.mul_mem_left _ _ x.2⟩
instance : SMul Rᵐᵒᵖ I where smul r x := ⟨r • x.1, I.mul_mem_right _ _ x.2⟩
instance leftModule : Module R I :=
Function.Injective.module _ (coeAddMonoidHom I) Subtype.coe_injective fun _ _ ↦ rfl
@[simp]
lemma coe_smul {r : R} {x : I} : (r • x : R) = r * (x : R) := rfl
instance rightModule : Module Rᵐᵒᵖ I :=
Function.Injective.module _ (coeAddMonoidHom I) Subtype.coe_injective fun _ _ ↦ rfl
@[simp]
lemma coe_mop_smul {r : Rᵐᵒᵖ} {x : I} : (r • x : R) = (x : R) * r.unop := rfl
instance : SMulCommClass R Rᵐᵒᵖ I where
smul_comm r s x := Subtype.ext <| smul_comm r s x.1
/--
For any `I : RingCon R`, when we view it as an ideal, `I.subtype` is the injective `R`-linear map
`I → R`.
-/
@[simps]
def subtype : I →ₗ[R] R where
toFun x := x.1
map_add' _ _ := rfl
map_smul' _ _ := rfl
theorem subtype_injective : Function.Injective (subtype I) :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : ⇑(subtype I) = Subtype.val :=
rfl
/--
For any `RingCon R`, when we view it as an ideal in `Rᵒᵖ`, `subtype` is the injective `Rᵐᵒᵖ`-linear
map `I → Rᵐᵒᵖ`.
-/
@[simps]
def subtypeMop : I →ₗ[Rᵐᵒᵖ] Rᵐᵒᵖ where
toFun x := MulOpposite.op x.1
map_add' _ _ := rfl
map_smul' _ _ := rfl
theorem subtypeMop_injective : Function.Injective (subtypeMop I) :=
MulOpposite.op_injective.comp Subtype.coe_injective
/-- Given an ideal `I`, `span I` is the smallest two-sided ideal containing `I`. -/
def fromIdeal : Ideal R →o TwoSidedIdeal R where
toFun I := span I
monotone' _ _ := span_mono
lemma mem_fromIdeal {I : Ideal R} {x : R} :
x ∈ fromIdeal I ↔ x ∈ span I := by simp [fromIdeal]
/-- Every two-sided ideal is also a left ideal. -/
def asIdeal : TwoSidedIdeal R →o Ideal R where
toFun I :=
{ carrier := I
add_mem' := I.add_mem
zero_mem' := I.zero_mem
smul_mem' := fun r x hx => I.mul_mem_left r x hx }
monotone' _ _ h _ h' := h h'
@[simp]
lemma mem_asIdeal {I : TwoSidedIdeal R} {x : R} :
x ∈ asIdeal I ↔ x ∈ I := by simp [asIdeal]
lemma gc : GaloisConnection fromIdeal (asIdeal (R := R)) :=
fun I J => ⟨fun h x hx ↦ h <| mem_span_iff.2 fun _ H ↦ H hx, fun h x hx ↦ by
simp only [fromIdeal, OrderHom.coe_mk, mem_span_iff] at hx
exact hx _ h⟩
@[simp]
lemma coe_asIdeal {I : TwoSidedIdeal R} : (asIdeal I : Set R) = I := rfl
@[simp] lemma bot_asIdeal : (⊥ : TwoSidedIdeal R).asIdeal = ⊥ := rfl
@[simp] lemma top_asIdeal : (⊤ : TwoSidedIdeal R).asIdeal = ⊤ := rfl
instance (I : TwoSidedIdeal R) : I.asIdeal.IsTwoSided :=
⟨fun _ ↦ by simpa using I.mul_mem_right _ _⟩
/-- Every two-sided ideal is also a right ideal. -/
def asIdealOpposite : TwoSidedIdeal R →o Ideal Rᵐᵒᵖ where
toFun I := asIdeal ⟨I.ringCon.op⟩
monotone' I J h x h' := by
simp only [mem_asIdeal, mem_iff, RingCon.op_iff, MulOpposite.unop_zero] at h' ⊢
exact J.rel_iff _ _ |>.2 <| h <| I.rel_iff 0 x.unop |>.1 h'
lemma mem_asIdealOpposite {I : TwoSidedIdeal R} {x : Rᵐᵒᵖ} :
x ∈ asIdealOpposite I ↔ x.unop ∈ I := by
simpa [asIdealOpposite, asIdeal, TwoSidedIdeal.mem_iff, RingCon.op_iff] using
⟨I.ringCon.symm, I.ringCon.symm⟩
end Ring
section CommRing
variable {R : Type*} [CommRing R]
/--
When the ring is commutative, two-sided ideals are exactly the same as left ideals.
-/
def orderIsoIdeal : TwoSidedIdeal R ≃o Ideal R where
toFun := asIdeal
invFun := fromIdeal
map_rel_iff' := ⟨fun h _ hx ↦ h hx, fun h ↦ asIdeal.monotone' h⟩
left_inv _ := SetLike.ext fun _ ↦ mem_span_iff.trans <| by aesop
right_inv J := SetLike.ext fun x ↦ mem_span_iff.trans
⟨fun h ↦ mem_mk' _ _ _ _ _ _ _ |>.1 <| h (mk'
J J.zero_mem J.add_mem J.neg_mem (J.mul_mem_left _) (J.mul_mem_right _))
(fun x => by simp), by aesop⟩
end CommRing
end TwoSidedIdeal
namespace Ideal
variable {R : Type*} [Ring R]
/-- Bundle an `Ideal` that is already two-sided as a `TwoSidedIdeal`. -/
def toTwoSided (I : Ideal R) [I.IsTwoSided] : TwoSidedIdeal R :=
TwoSidedIdeal.mk' I I.zero_mem I.add_mem I.neg_mem (I.smul_mem _) (I.mul_mem_right _)
@[simp]
lemma mem_toTwoSided {I : Ideal R} [I.IsTwoSided] {x : R} :
x ∈ I.toTwoSided ↔ x ∈ I := by
simp [toTwoSided]
@[simp]
lemma coe_toTwoSided (I : Ideal R) [I.IsTwoSided] : (I.toTwoSided : Set R) = I := by
simp [toTwoSided]
@[simp]
lemma toTwoSided_asIdeal (I : TwoSidedIdeal R) : I.asIdeal.toTwoSided = I :=
by ext; simp
@[simp]
lemma asIdeal_toTwoSided (I : Ideal R) [I.IsTwoSided] : I.toTwoSided.asIdeal = I := by
ext
simp
instance : CanLift (Ideal R) (TwoSidedIdeal R) TwoSidedIdeal.asIdeal (·.IsTwoSided) where
prf I _ := ⟨I.toTwoSided, asIdeal_toTwoSided ..⟩
end Ideal
/-- A two-sided ideal is simply a left ideal that is two-sided. -/
@[simps] def TwoSidedIdeal.orderIsoIsTwoSided {R : Type*} [Ring R] :
TwoSidedIdeal R ≃o {I : Ideal R // I.IsTwoSided} where
toFun I := ⟨I.asIdeal, inferInstance⟩
invFun I := have := I.2; I.1.toTwoSided
left_inv _ := by simp
right_inv I := by simp
map_rel_iff' {I I'} := by simp [SetLike.le_def]
|
test_guard.v
|
From mathcomp Require Import all_boot.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Inductive tree := Node { children : seq tree }.
Inductive ptree (T : Type) := singleton of T | branch of list (ptree T).
(* has *)
Fixpoint tree_has (T : Type) (p : pred T) (t : ptree T) : bool :=
match t with
| singleton x => p x
| branch ts => has (tree_has p) ts
end.
(* all *)
Fixpoint tree_all (T : Type) (p : pred T) (t : ptree T) : bool :=
match t with
| singleton x => p x
| branch ts => all (tree_all p) ts
end.
(* map *)
Fixpoint traverse_id (t : tree) : tree :=
Node (map traverse_id (children t)).
(* foldr *)
Fixpoint tree_foldr (T R : Type) (f : T -> R -> R) (z : R) (t : ptree T) : R :=
match t with
| singleton x => f x z
| branch ts => foldr (fun t z' => tree_foldr f z' t) z ts
end.
(* foldl *)
Fixpoint tree_foldl (T R : Type) (f : R -> T -> R) (z : R) (t : ptree T) : R :=
match t with
| singleton x => f z x
| branch ts => foldl (tree_foldl f) z ts
end.
(* all2 *)
Fixpoint eq_tree (x y : tree) {struct x} : bool :=
all2 eq_tree (children x) (children y).
|
Split.lean
|
import Mathlib.Tactic.Basic
example : (α : Type) × List α := by
constructor
· exact [0,1]
-- example : (α : Type) × List α := by
-- fsplit
-- - exact ℕ
-- - exact [0,1]
|
ShortExact.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.HomotopyCategory.ShortExact
import Mathlib.Algebra.Homology.DerivedCategory.Basic
/-!
# The distinguished triangle attached to a short exact sequence of cochain complexes
Given a short exact short complex `S` in the category `CochainComplex C ℤ`,
we construct a distinguished triangle
`Q.obj S.X₁ ⟶ Q.obj S.X₂ ⟶ Q.obj S.X₃ ⟶ (Q.obj S.X₃)⟦1⟧`
in the derived category of `C`.
(See `triangleOfSES` and `triangleOfSES_distinguished`.)
-/
assert_not_exists TwoSidedIdeal
universe w v u
open CategoryTheory Category Pretriangulated
namespace DerivedCategory
variable {C : Type u} [Category.{v} C] [Abelian C] [HasDerivedCategory.{w} C]
{S : ShortComplex (CochainComplex C ℤ)} (hS : S.ShortExact)
/-- The connecting homomorphism `Q.obj (S.X₃) ⟶ (Q.obj S.X₁)⟦(1 : ℤ)⟧`
in the derived category when `S` is a short exact short complex of
cochain complexes in an abelian category. -/
noncomputable def triangleOfSESδ :
Q.obj (S.X₃) ⟶ (Q.obj S.X₁)⟦(1 : ℤ)⟧ :=
have := CochainComplex.mappingCone.quasiIso_descShortComplex hS
inv (Q.map (CochainComplex.mappingCone.descShortComplex S)) ≫
Q.map (CochainComplex.mappingCone.triangle S.f).mor₃ ≫
(Q.commShiftIso (1 : ℤ)).hom.app S.X₁
/-- The distinguished triangle in the derived category associated to a short
exact sequence of cochain complexes. -/
@[simps!]
noncomputable def triangleOfSES : Triangle (DerivedCategory C) :=
Triangle.mk (Q.map S.f) (Q.map S.g) (triangleOfSESδ hS)
/-- The triangle `triangleOfSES` attached to a short exact sequence `S` of cochain
complexes is isomorphism to the standard distinguished triangle associated to
the morphism `S.f`. -/
noncomputable def triangleOfSESIso :
triangleOfSES hS ≅ Q.mapTriangle.obj (CochainComplex.mappingCone.triangle S.f) := by
have := CochainComplex.mappingCone.quasiIso_descShortComplex hS
refine Iso.symm (Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _)
(asIso (Q.map (CochainComplex.mappingCone.descShortComplex S))) ?_ ?_ ?_)
· dsimp [triangleOfSES]
simp only [comp_id, id_comp]
· dsimp
simp only [← Q.map_comp, CochainComplex.mappingCone.inr_descShortComplex, id_comp]
· dsimp [triangleOfSESδ]
rw [CategoryTheory.Functor.map_id, comp_id, IsIso.hom_inv_id_assoc]
lemma triangleOfSES_distinguished :
triangleOfSES hS ∈ distTriang (DerivedCategory C) := by
rw [mem_distTriang_iff]
exact ⟨_, _, S.f, ⟨triangleOfSESIso hS⟩⟩
end DerivedCategory
|
Field.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.Algebra.Ring.Action.Basic
import Mathlib.Algebra.Field.Defs
import Mathlib.Algebra.GroupWithZero.Units.Lemmas
/-!
# Group action on fields
-/
variable {M} [Monoid M] {F} [DivisionRing F]
/-- Note that `smul_inv'` refers to the group case, and `smul_inv` has an additional inverse
on `x`. -/
@[simp]
theorem smul_inv'' [MulSemiringAction M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ :=
map_inv₀ (MulSemiringAction.toRingHom M F x) _
|
Rat.lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Algebra.Field.Defs
import Mathlib.Data.NNRat.Defs
/-!
# The rational numbers form a field
This file contains the field instance on the rational numbers.
See note [foundational algebra order theory].
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom
-/
namespace Rat
instance instField : Field ℚ where
__ := commRing
__ := commGroupWithZero
nnqsmul := _
nnqsmul_def := fun _ _ => rfl
qsmul := _
qsmul_def := fun _ _ => rfl
nnratCast_def q := by
rw [← NNRat.den_coe, ← Int.cast_natCast q.num, ← NNRat.num_coe]; exact(num_div_den _).symm
ratCast_def _ := (num_div_den _).symm
/-!
### Extra instances to short-circuit type class resolution
These also prevent non-computable instances being used to construct these instances non-computably.
-/
instance instDivisionRing : DivisionRing ℚ := inferInstance
protected lemma inv_nonneg {a : ℚ} (ha : 0 ≤ a) : 0 ≤ a⁻¹ := by
rw [inv_def']
exact divInt_nonneg (Int.natCast_nonneg a.den) (num_nonneg.mpr ha)
protected lemma div_nonneg {a b : ℚ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a / b :=
mul_nonneg ha (Rat.inv_nonneg hb)
protected lemma zpow_nonneg {a : ℚ} (ha : 0 ≤ a) : ∀ n : ℤ, 0 ≤ a ^ n
| Int.ofNat n => by simp [ha]
| Int.negSucc n => by simpa using Rat.inv_nonneg (pow_nonneg ha (n + 1))
end Rat
namespace NNRat
instance instInv : Inv ℚ≥0 where
inv x := ⟨x⁻¹, Rat.inv_nonneg x.2⟩
instance instDiv : Div ℚ≥0 where
div x y := ⟨x / y, Rat.div_nonneg x.2 y.2⟩
instance instZPow : Pow ℚ≥0 ℤ where
pow x n := ⟨x ^ n, Rat.zpow_nonneg x.2 n⟩
@[simp, norm_cast] lemma coe_inv (q : ℚ≥0) : ((q⁻¹ : ℚ≥0) : ℚ) = (q : ℚ)⁻¹ := rfl
@[simp, norm_cast] lemma coe_div (p q : ℚ≥0) : ((p / q : ℚ≥0) : ℚ) = p / q := rfl
@[simp, norm_cast] lemma coe_zpow (p : ℚ≥0) (n : ℤ) : ((p ^ n : ℚ≥0) : ℚ) = p ^ n := rfl
lemma inv_def (q : ℚ≥0) : q⁻¹ = divNat q.den q.num := by ext; simp [Rat.inv_def', num_coe, den_coe]
lemma div_def (p q : ℚ≥0) : p / q = divNat (p.num * q.den) (p.den * q.num) := by
ext; simp [Rat.div_def', num_coe, den_coe]
lemma num_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.num = q.den := by
rw [inv_def, divNat, num, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq),
Int.natAbs_natCast]
simpa using q.coprime_num_den.symm
lemma den_inv_of_ne_zero {q : ℚ≥0} (hq : q ≠ 0) : q⁻¹.den = q.num := by
rw [inv_def, divNat, den, coe_mk, Rat.divInt_ofNat, ← Rat.mk_eq_mkRat _ _ (num_ne_zero.mpr hq)]
simpa using q.coprime_num_den.symm
@[simp]
lemma num_div_den (q : ℚ≥0) : (q.num : ℚ≥0) / q.den = q := by
ext1
rw [coe_div, coe_natCast, coe_natCast, num, ← Int.cast_natCast]
exact (cast_def _).symm
instance instSemifield : Semifield ℚ≥0 where
inv_zero := by ext; simp
mul_inv_cancel q h := by ext; simp [h]
nnratCast_def q := q.num_div_den.symm
nnqsmul q a := q * a
nnqsmul_def q a := rfl
zpow n a := a ^ n
zpow_zero' a := by ext; norm_cast
zpow_succ' n a := by ext; norm_cast
zpow_neg' n a := by ext; norm_cast
end NNRat
|
ClearExcept.lean
|
import Mathlib.Tactic.ClearExcept
set_option linter.unusedTactic false
set_option linter.unusedVariables false
-- Most basic test
example (_delete_this : Nat) (dont_delete_this : Int) : Nat := by
clear * - dont_delete_this
fail_if_success assumption
exact dont_delete_this.toNat
-- Confirms that clearExcept does not delete class instances
example [dont_delete_this : Inhabited Nat] (dont_delete_this2 : Prop) : Inhabited Nat := by
clear * - dont_delete_this2
assumption
-- Confirms that clearExcept can clear hypotheses even when they have dependencies
example (delete_this : Nat) (_delete_this2 : delete_this = delete_this) (dont_delete_this : Int) :
Nat := by
clear * - dont_delete_this
fail_if_success assumption
exact dont_delete_this.toNat
-- Confirms that clearExcept does not clear hypotheses
-- when they have dependencies that should not be cleared
example (dont_delete_this : Nat) (dont_delete_this2 : dont_delete_this = dont_delete_this) :
Nat := by
clear * - dont_delete_this2
exact dont_delete_this
-- Confirms that clearExcept can preserve multiple identifiers
example (_delete_this : Nat) (dont_delete_this : Int) (dont_delete_this2 : Int) : Nat := by
clear * - dont_delete_this dont_delete_this2
fail_if_success assumption
exact dont_delete_this.toNat + dont_delete_this2.toNat
|
sesquilinear.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple bigop ssralg finset fingroup.
From mathcomp Require Import zmodp poly order ssrnum matrix mxalgebra vector.
(******************************************************************************)
(* Sesquilinear forms *)
(* *)
(* e_ j := the row matrix with a 1 in column j *)
(* M ^ phi := map_mx phi M *)
(* Notation in scope sesquilinear_scope. *)
(* M ^t phi := (M ^T) ^ phi *)
(* Notation in scope sesquilinear_scope. *)
(* involutive_rmorphism R == the type of involutive functions *)
(* R has type nzRingType. *)
(* The HB class is InvolutiveRMorphism. *)
(* *)
(* {bilinear U -> U' -> V | s & s'} == the type of bilinear forms which are *)
(* essentially functions of type U -> U' -> V *)
(* U and U' are lmodType's, V is a zmodType, s and *)
(* s' are scaling operations of type R -> V -> V. *)
(* The HB class is Bilinear. *)
(* The factory bilinear_isBilinear provides a way *)
(* to instantiate a bilinear form from two *)
(* GRing.linear_for proofs. *)
(* {bilinear U -> V -> W | s } := {bilinear U -> V -> W | s.1 & s.2} *)
(* {bilinear U -> V -> W} := {bilinear U -> V -> W | *:%R & *:%R } *)
(* {biscalar U} := {bilinear U -> U -> _ | *%R & *%R } *)
(* *)
(* applyr f x := f ^~ x with f : U -> U' -> V *)
(* form theta M u v == form defined from a matrix M *)
(* := (u *m M *m (v ^t theta)) 0 0 *)
(* u and v are row vectors, M is a square matrix, *)
(* coefficients have type R : fieldType, *)
(* theta is a morphism *)
(* *)
(* {hermitian U for eps & theta} == hermitian/skew-hermitian form *)
(* eps is a boolean flag, *)
(* (false -> hermitian, true -> skew-hermitian), *)
(* theta is a function R -> R (R : nzRingType). *)
(* The HB class is Hermitian. *)
(* *%R is used as a the first scaling operator. *)
(* theta \; *R is used as the second scaling *)
(* operation of the bilinear form. *)
(* The archetypal case is theta being the complex *)
(* conjugate. *)
(* *)
(* M \is (eps, theta).-sesqui == M is a sesquilinear form *)
(* *)
(* orthomx theta M B == M-orthogonal complement of B *)
(* := kermx (M *m B ^t theta) *)
(* M is a square matrix representing a sesquilinear *)
(* form, B is a rectangle matrix representing a *)
(* subspace *)
(* (local notation: B ^_|_) *)
(* ortho theta M B == orthomx theta M B with theta a morphism *)
(* A '_|_ B := (A%MS <= B^_|_)%MS *)
(* This is a local notation. *)
(* rad theta M := ortho theta M 1%:M *)
(* (local notation: 1%:M^_|_) *)
(* *)
(* {symmetric U} == symmetric form *)
(* := {hermitian U for false & idfun} *)
(* {skew_symmetric U} == skew-symmetric form *)
(* := {hermitian U for true & idfun} *)
(* {hermitian_sym U for theta} := hermitian form using theta (eps = false) *)
(* {dot U for theta} == type of positive definite forms *)
(* The HB class is Dot. *)
(* *)
(* is_skew eps theta form := eps = true /\ theta = idfun *)
(* is_sym eps theta form := eps = false /\ theta = idfun *)
(* is_hermsym eps theta form := eps = false *)
(* *)
(* ortho_rec s1 s2 := elements of s1 and s2 are pairwise orthogonal *)
(* pairwise_orthogonal s == elements of s are pairwise orthogonal and *)
(* s does not contain 0 *)
(* orthogonal s1 s2 == the inner product of an element of S1 and *)
(* an element of S2 is 0 *)
(* := ortho_rec s1 s2 *)
(* orthonormal s == s is an orthonormal set of unit vectors *)
(* *)
(* isometry form1 form2 tau == tau is an isometry from form1 to form2 *)
(* form1 and form2 are hermitian forms. *)
(* {in D, isometry tau, to R} == local notation for now *)
(* *)
(* orthov (V : {vspace vT}) == the space orthogonal to V *)
(* *)
(* In the following definitions, we have f : {hermitian vT for eps & theta} *)
(* with vT : vectType F (F : fieldType): *)
(* nondegenerate f == f is non-degenerated *)
(* is_symplectic f == f is a symplectic bilinear form *)
(* is_orthogonal f == f is an orthogonal form *)
(* is_unitary f == f is a unitary form *)
(* *)
(* form_of_matrix theta M U V := \tr (U *m M *m (V ^t theta)) *)
(* matrix_of_form f := \matrix_(i, j) form 'e_i 'e_j *)
(* M \is hermitianmx eps theta == same as M \is (eps, theta).-sesqui *)
(* without the constraint that theta is a morphism *)
(* *)
(* symmetricmx := hermitianmx _ false idfun *)
(* skewmx := hermitianmx _ true idfun *)
(* hermsymmx := hermitianmx _ false conjC *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "M ^t phi"
(at level 39, left associativity, format "M ^t phi").
Reserved Notation "A ^!" (format "A ^!").
Reserved Notation "A ^_|_" (format "A ^_|_").
Reserved Notation "A ''_|_' B" (at level 69, format "A ''_|_' B").
Reserved Notation "eps_theta .-sesqui" (format "eps_theta .-sesqui").
Local Open Scope ring_scope.
Import GRing.Theory Order.Theory Num.Theory.
Notation "''e_' j" := (delta_mx 0 j)
(format "''e_' j", at level 8, j at level 2) : ring_scope.
Declare Scope sesquilinear_scope.
Delimit Scope sesquilinear_scope with sesqui.
Local Open Scope sesquilinear_scope.
Notation "M ^ phi" := (map_mx phi M) : sesquilinear_scope.
Notation "M ^t phi" := ((M ^T) ^ phi) : sesquilinear_scope.
(* TODO: move? *)
Lemma eq_map_mx_id (R : nzRingType) m n (M : 'M[R]_(m, n)) (f : R -> R) :
f =1 id -> M ^ f = M.
Proof. by move=> /eq_map_mx->; rewrite map_mx_id. Qed.
HB.mixin Record isInvolutive (R : nzRingType) (f : R -> R) :=
{ involutive_subproof : involutive f }.
(* TODO: move? *)
#[short(type="involutive_rmorphism")]
HB.structure Definition InvolutiveRMorphism (R : nzRingType) :=
{ f of @GRing.RMorphism R R f & @isInvolutive R f }.
Section InvolutiveTheory.
Variable R : nzRingType.
Let idfunK : involutive (@idfun R). Proof. by []. Qed.
HB.instance Definition _ := isInvolutive.Build _ _ idfunK.
Lemma rmorphK (f : involutive_rmorphism R) : involutive f.
Proof. by move: f => [? [? ? []]]. Qed.
End InvolutiveTheory.
Definition conjC {C : numClosedFieldType} (c : C) : C := c^*.
HB.instance Definition _ (C : numClosedFieldType) :=
GRing.RMorphism.on (@conjC C).
Section conjC_involutive.
Variable C : numClosedFieldType.
Let conjCfun_involutive : involutive (@conjC C). Proof. exact: conjCK. Qed.
HB.instance Definition _ :=
isInvolutive.Build _ (@conjC C) conjCfun_involutive.
End conjC_involutive.
Lemma map_mxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) :
(A ^ conjC) ^ conjC = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
(*Structure revop X Y Z (f : Y -> X -> Z) := RevOp {
fun_of_revop :> X -> Y -> Z;
_ : forall x, f x =1 fun_of_revop^~ x
}.
Notation "[ 'revop' revop 'of' op ]" :=
(@RevOp _ _ _ revop op (fun _ _ => erefl))
(format "[ 'revop' revop 'of' op ]") : form_scope.*)
HB.mixin Record isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : U -> U' -> V) := {
zmod_morphisml_subproof : forall u', zmod_morphism (f ^~ u') ;
zmod_morphismr_subproof : forall u, zmod_morphism (f u) ;
linearl_subproof : forall u', scalable_for s (f ^~ u') ;
linearr_subproof : forall u, scalable_for s' (f u)
}.
#[short(type="bilinear")]
HB.structure Definition Bilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) :=
{f of isBilinear R U U' V s s' f}.
Definition bilinear_for (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) :=
((forall u', GRing.linear_for (s : R -> V -> V) (f ^~ u'))
* (forall u, GRing.linear_for s' (f u)))%type.
HB.factory Record bilinear_isBilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V)
(f : U -> U' -> V) := {
bilinear_subproof : bilinear_for s s' f
}.
HB.builders Context R U U' V s s' f of bilinear_isBilinear R U U' V s s' f.
HB.instance Definition _ := isBilinear.Build R U U' V s s' f
(fun u' => zmod_morphism_linear (bilinear_subproof.1 u'))
(fun u => zmod_morphism_linear (bilinear_subproof.2 u))
(fun u' => scalable_linear (bilinear_subproof.1 u'))
(fun u => scalable_linear (bilinear_subproof.2 u)).
HB.end.
Module BilinearExports.
Module Bilinear.
Section bilinear.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Local Notation bilinear f := (bilinear_for *:%R *:%R f).
Local Notation biscalar f := (bilinear_for *%R *%R f).
(* Support for right-to-left rewriting with the generic linearZ rule. *)
Notation mapUUV := (@Bilinear.type R U U' V s s').
Definition map_class := mapUUV.
Definition map_at_left (a : R) := mapUUV.
Definition map_at_right (b : R) := mapUUV.
Definition map_at_both (a b : R) := mapUUV.
Structure map_for_left a s_a :=
MapForLeft {map_for_left_map : mapUUV; _ : s a = s_a }.
Structure map_for_right b s'_b :=
MapForRight {map_for_right_map : mapUUV; _ : s' b = s'_b }.
Structure map_for_both a b s_a s'_b :=
MapForBoth {map_for_both_map : mapUUV; _ : s a = s_a ; _ : s' b = s'_b }.
Definition unify_map_at_left a (f : map_at_left a) :=
MapForLeft f (erefl (s a)).
Definition unify_map_at_right b (f : map_at_right b) :=
MapForRight f (erefl (s' b)).
Definition unify_map_at_both a b (f : map_at_both a b) :=
MapForBoth f (erefl (s a)) (erefl (s' b)).
Structure wrapped := Wrap {unwrap : mapUUV}.
Definition wrap (f : map_class) := Wrap f.
End bilinear.
End Bilinear.
Notation "{ 'bilinear' U -> V -> W | s & t }" :=
(@Bilinear.type _ U%type V%type W%type s t)
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s & t }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W | s }" :=
({bilinear U -> V -> W | s.1 & s.2})
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W }" := {bilinear U -> V -> W | *:%R & *:%R}
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W }") : ring_scope.
Notation "{ 'biscalar' U }" := {bilinear U%type -> U%type -> _ | *%R & *%R}
(format "{ 'biscalar' U }") : ring_scope.
End BilinearExports.
Export BilinearExports.
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V)
(f : {bilinear U -> U' -> V | s & s'}) (u : U)
:= @GRing.isZmodMorphism.Build U' V (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : @bilinear R U U' V s s') (u : U)
:= @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
Section applyr.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s s' : R -> V -> V).
Definition applyr_head t (f : U -> U' -> V) u v := let: tt := t in f v u.
End applyr.
Notation applyr := (applyr_head tt).
Coercion Bilinear.map_for_left_map : Bilinear.map_for_left >-> Bilinear.type.
Coercion Bilinear.map_for_right_map : Bilinear.map_for_right >-> Bilinear.type.
Coercion Bilinear.map_for_both_map : Bilinear.map_for_both >-> Bilinear.type.
Coercion Bilinear.unify_map_at_left : Bilinear.map_at_left >-> Bilinear.map_for_left.
Coercion Bilinear.unify_map_at_right : Bilinear.map_at_right >-> Bilinear.map_for_right.
Coercion Bilinear.unify_map_at_both : Bilinear.map_at_both >-> Bilinear.map_for_both.
Canonical Bilinear.unify_map_at_left.
Canonical Bilinear.unify_map_at_right.
Canonical Bilinear.unify_map_at_both.
Coercion Bilinear.unwrap : Bilinear.wrapped >-> Bilinear.type.
Coercion Bilinear.wrap : Bilinear.map_class >-> Bilinear.wrapped.
Canonical Bilinear.wrap.
Section BilinearTheory.
Variable R : nzRingType.
Section GenericProperties.
Variables (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V).
Variable f : {bilinear U -> U' -> V | s & s'}.
Section GenericPropertiesr.
Variable z : U.
Lemma linear0r : f z 0 = 0. Proof. by rewrite raddf0. Qed.
Lemma linearNr : {morph f z : x / - x}. Proof. exact: raddfN. Qed.
Lemma linearDr : {morph f z : x y / x + y}. Proof. exact: raddfD. Qed.
Lemma linearBr : {morph f z : x y / x - y}. Proof. exact: raddfB. Qed.
Lemma linearMnr n : {morph f z : x / x *+ n}. Proof. exact: raddfMn. Qed.
Lemma linearMNnr n : {morph f z : x / x *- n}. Proof. exact: raddfMNn. Qed.
Lemma linear_sumr I r (P : pred I) E :
f z (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f z (E i).
Proof. exact: raddf_sum. Qed.
Lemma linearZr_LR : scalable_for s' (f z). Proof. exact: linearZ_LR. Qed.
Lemma linearPr a : {morph f z : u v / a *: u + v >-> s' a u + v}.
Proof. exact: linearP. Qed.
End GenericPropertiesr.
Lemma applyrE x : applyr f x =1 f^~ x. Proof. by []. Qed.
Section GenericPropertiesl.
Variable z : U'.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build _ _ (applyr f z) (@zmod_morphisml_subproof _ _ _ _ _ _ f z).
HB.instance Definition _ :=
GRing.isScalable.Build _ _ _ _ (applyr f z) (@linearl_subproof _ _ _ _ _ _ f z).
Lemma linear0l : f 0 z = 0. Proof. by rewrite -applyrE raddf0. Qed.
Lemma linearNl : {morph f^~ z : x / - x}.
Proof. by move=> ?; rewrite -applyrE raddfN. Qed.
Lemma linearDl : {morph f^~ z : x y / x + y}.
Proof. by move=> ? ?; rewrite -applyrE raddfD. Qed.
Lemma linearBl : {morph f^~ z : x y / x - y}.
Proof. by move=> ? ?; rewrite -applyrE raddfB. Qed.
Lemma linearMnl n : {morph f^~ z : x / x *+ n}.
Proof. by move=> ?; rewrite -applyrE raddfMn. Qed.
Lemma linearMNnl n : {morph f^~ z : x / x *- n}.
Proof. by move=> ?; rewrite -applyrE raddfMNn. Qed.
Lemma linear_sumlz I r (P : pred I) E :
f (\sum_(i <- r | P i) E i) z = \sum_(i <- r | P i) f (E i) z.
Proof. by rewrite -applyrE raddf_sum. Qed.
Lemma linearZl_LR : scalable_for s (f ^~ z).
Proof. by move=> ? ?; rewrite -applyrE linearZ_LR. Qed.
Lemma linearPl a : {morph f^~ z : u v / a *: u + v >-> s a u + v}.
Proof. by move=> ? ?; rewrite -applyrE linearP. Qed.
End GenericPropertiesl.
End GenericProperties.
Section BidirectionalLinearZ.
Variables (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Variables (S : nzRingType) (h : GRing.Scale.law S V) (h' : GRing.Scale.law S V).
Lemma linearZl z (c : S) (a : R) (h_c := h c)
(f : Bilinear.map_for_left U U' s s' a h_c) u :
f (a *: u) z = h_c (Bilinear.wrap f u z).
Proof. by rewrite linearZl_LR; case: f => f /= ->. Qed.
Lemma linearZr z c' b (h'_c' := h' c')
(f : Bilinear.map_for_right U U' s s' b h'_c') u :
f z (b *: u) = h'_c' (Bilinear.wrap f z u).
Proof. by rewrite linearZr_LR; case: f => f /= ->. Qed.
Lemma linearZlr c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h_c (h'_c' (Bilinear.wrap f u v)).
Proof. by rewrite linearZl_LR linearZ_LR; case: f => f /= -> ->. Qed.
Lemma linearZrl c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h'_c' (h_c (Bilinear.wrap f u v)).
Proof. by rewrite linearZ_LR/= linearZl_LR; case: f => f /= -> ->. Qed.
End BidirectionalLinearZ.
End BilinearTheory.
(* TODO
Canonical rev_mulmx (R : nzRingType) m n p := [revop mulmxr of @mulmx R m n p].
*)
(*Canonical mulmx_bilinear (R : comNzRingType) m n p := [bilinear of @mulmx R m n p].*)
Lemma mulmx_is_bilinear (R : comNzRingType) m n p : bilinear_for
(GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _)
(@mulmx R m n p).
Proof.
split=> [u'|u] a x y /=.
- by rewrite mulmxDl scalemxAl.
- by rewrite mulmxDr scalemxAr.
Qed.
HB.instance Definition _ (R : comNzRingType) m n p := bilinear_isBilinear.Build R
[the lmodType R of 'M[R]_(m, n)] [the lmodType R of 'M[R]_(n, p)]
[the zmodType of 'M[R]_(m, p)] _ _ (@mulmx R m n p)
(mulmx_is_bilinear R m n p).
Section BilinearForms.
Variables (R : fieldType) (theta : {rmorphism R -> R}).
Variables (n : nat) (M : 'M[R]_n).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Definition form u v := (u *m M *m (v ^t theta)) 0 0.
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma form0l u : '[0, u] = 0. Proof. by rewrite /form !mul0mx mxE. Qed.
Lemma form0r u : '[u, 0] = 0.
Proof. by rewrite /form trmx0 map_mx0 mulmx0 mxE. Qed.
Lemma formDl u v w : '[u + v, w] = '[u, w] + '[v, w].
Proof. by rewrite /form !mulmxDl mxE. Qed.
Lemma formDr u v w : '[u, v + w] = '[u, v] + '[u, w].
Proof. by rewrite /form linearD !map_mxD !mulmxDr mxE. Qed.
Lemma formZr a u v : '[u, a *: v] = theta a * '[u, v].
Proof. by rewrite /form !(linearZ, map_mxZ) /= mxE. Qed.
Lemma formZl a u v : '[a *: u, v] = a * '[u, v].
Proof.
by do !rewrite /form -[_ *: _ *m _]/(mulmxr _ _) linearZ /=; rewrite mxE.
Qed.
Lemma formNl u v : '[- u, v] = - '[u, v].
Proof. by rewrite -scaleN1r formZl mulN1r. Qed.
Lemma formNr u v : '[u, - v] = - '[u, v].
Proof. by rewrite -scaleN1r formZr rmorphN1 mulN1r. Qed.
Lemma formee i j : '['e_i, 'e_j] = M i j.
Proof.
rewrite /form -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE !mxE.
Qed.
Lemma form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof. by rewrite/form=> -> u v; rewrite mulmx0 mul0mx mxE. Qed.
End BilinearForms.
HB.mixin Record isHermitianSesquilinear (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : U -> U -> R) := {
hermitian_subproof : forall x y : U, f x y = (-1) ^+ eps * theta (f y x)
}.
HB.structure Definition Hermitian (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) :=
{f of @Bilinear R U U _ ( *%R ) (theta \; *%R) f &
@isHermitianSesquilinear R U eps theta f}.
Notation "{ 'hermitian' U 'for' eps & theta }" := (@Hermitian.type _ U eps theta)
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Variables (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R).
Implicit Types phU : phant U.
Local Coercion GRing.Scale.op : GRing.Scale.law >-> Funclass.
Definition axiom (f : U -> U -> R) :=
forall x y : U, f x y = (-1) ^+ eps * theta (f y x).
Record class_of (f : U -> U -> R) : Prop := Class {
base : Bilinear.class_of ( *%R) (theta \; *%R) f;
mixin : axiom f
}.*)
(*Canonical additiver (u : U) := Additive (base class u).
Canonical linearr (u : U) := Linear (base class u).
Canonical additivel (u' : U) := @GRing.Additive.Pack _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical linearl (u' : U) := @GRing.Linear.Pack _ _ _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical bilinear := @Bilinear.Pack _ _ _ _ _ _ (Phant (U -> U -> R)) cF (base class).*)
(*Module Exports.
Notation "{ 'hermitian' U 'for' eps & theta }" := (map eps theta (Phant U))
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
Coercion base : class_of >-> bilmorphism_for.
Coercion apply : map >-> Funclass.
Notation "[ 'hermitian' 'of' f 'as' g ]" := (@clone _ _ _ _ _ _ f g _ idfun idfun)
(format "[ 'hermitian' 'of' f 'as' g ]") : form_scope.
Notation "[ 'hermitian' 'of' f ]" := (@clone _ _ _ _ _ _ f f _ idfun idfun)
(format "[ 'hermitian' 'of' f ]") : form_scope.
Notation hermitian_for := Hermitian.axiom.
Notation Hermitian fM := (pack (Phant _) fM idfun).
Canonical additiver.
Canonical linearr.
Canonical additivel.
Canonical linearl.
Canonical bilinear.
Notation hermapplyr := (@applyr_head _ _ _ _ tt).
End Exports.
End Hermitian.
Include Hermitian.Exports.*)
Definition orthomx {R : fieldType} (theta : R -> R) n m M (B : 'M_(m, n)) : 'M_n :=
kermx (M *m (B ^t theta)).
Section Sesquilinear.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Section Def.
Variable eps_theta : bool * {rmorphism R -> R}.
Definition sesqui :=
[qualify M : 'M_n | M == ((-1) ^+ eps_theta.1) *: M ^t eps_theta.2].
Fact sesqui_key : pred_key sesqui. Proof. by []. Qed.
Canonical sesqui_keyed := KeyedQualifier sesqui_key.
End Def.
Local Notation "eps_theta .-sesqui" := (sesqui eps_theta).
Variables (eps : bool) (theta : {rmorphism R -> R}) (M : 'M[R]_n).
Local Notation "''[' u , v ]" := (form theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma sesquiE : (M \is (eps, theta).-sesqui) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma sesquiP : reflect (M = (-1) ^+ eps *: M ^t theta)
(M \is (eps, theta).-sesqui).
Proof. by rewrite sesquiE; exact/eqP. Qed.
Hypotheses (thetaK : involutive theta) (M_sesqui : M \is (eps, theta).-sesqui).
Lemma trmx_sesqui : M^T = (-1) ^+ eps *: M ^ theta.
Proof.
rewrite [in LHS](sesquiP _) // -mul_scalar_mx trmx_mul.
by rewrite tr_scalar_mx mul_mx_scalar map_trmx trmxK.
Qed.
Lemma maptrmx_sesqui : M^t theta = (-1) ^+ eps *: M.
Proof.
by rewrite trmx_sesqui map_mxZ rmorph_sign -map_mx_comp eq_map_mx_id.
Qed.
Lemma formC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof.
rewrite /form [M in LHS](sesquiP _) // -mulmxA !mxE rmorph_sum mulr_sumr.
apply: eq_bigr => /= i _; rewrite !(mxE, mulr_sumr, mulr_suml, rmorph_sum).
apply: eq_bigr => /= j _; rewrite !mxE !rmorphM mulrCA -!mulrA.
by congr (_ * _); rewrite mulrA mulrC /= thetaK.
Qed.
Lemma form_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite formC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
Definition ortho m (B : 'M_(m, n)) := orthomx theta M B.
Local Notation "B ^_|_" := (ortho B) : ring_scope.
Local Notation "A '_|_ B" := (A%MS <= B^_|_)%MS : ring_scope.
Lemma normalE u v : (u '_|_ v) = ('[u, v] == 0).
Proof.
by rewrite (sameP sub_kermxP eqP) mulmxA [_ *m _^t _]mx11_scalar fmorph_eq0.
Qed.
Lemma form_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v).
Proof. by rewrite normalE; apply/eqP. Qed.
Lemma normalP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), (u <= A)%MS -> (v <= B)%MS -> u '_|_ v)
(A '_|_ B).
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma normalC p q (A : 'M_(p, n)) (B : 'M_(q, n)) : (A '_|_ B) = (B '_|_ A).
Proof.
gen have nC : p q A B / A '_|_ B -> B '_|_ A; last by apply/idP/idP; apply/nC.
move=> AnB; apply/normalP => u v ? ?; rewrite normalE.
rewrite formC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -normalE (normalP _ _ AnB).
Qed.
Lemma normal_ortho_mx p (A : 'M_(p, n)) : ((A^_|_) '_|_ A).
Proof. by []. Qed.
Lemma normal_mx_ortho p (A : 'M_(p, n)) : (A '_|_ (A^_|_)).
Proof. by rewrite normalC. Qed.
Lemma rank_normal u : (\rank (u ^_|_) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Definition rad := 1%:M^_|_.
Lemma rad_ker : rad = kermx M.
Proof. by rewrite /rad /ortho /orthomx trmx1 map_mx1 mulmx1. Qed.
(* Pythagoras *)
Theorem formDd u v : u '_|_ v -> '[u + v] = '[u] + '[v].
Proof.
move=> uNv; rewrite formDl !formDr ['[v, u]]formC.
by rewrite ['[u, v]](form_eq0P _) // rmorph0 mulr0 addr0 add0r.
Qed.
Lemma formZ a u : '[a *: u]= (a * theta a) * '[u].
Proof. by rewrite formZl formZr mulrA. Qed.
Lemma formN u : '[- u] = '[u].
Proof. by rewrite formNr formNl opprK. Qed.
Lemma form_sign m u : '[(-1) ^+ m *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: odd; rewrite ?formN. Qed.
Lemma formD u v : let d := '[u, v] in
'[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite formDl !formDr ['[v, _]]formC [_ + '[v]]addrC addrACA. Qed.
Lemma formB u v : let d := '[u, v] in
'[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof. by rewrite formD formN !formNr rmorphN mulrN -opprD. Qed.
Lemma formBd u v : u '_|_ v -> '[u - v] = '[u] + '[v].
Proof.
by move=> uTv; rewrite formDd ?formN // normalE formNr oppr_eq0 -normalE.
Qed.
(* Lemma formJ u v : '[u ^ theta, v ^ theta] = (-1) ^+ eps * theta '[u, v]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* Lemma formJ u : '[u ^ theta] = (-1) ^+ eps * '[u]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* rewrite !map_mxM. *)
(* rewrite -map_mx_comp eq_map_mx_id //. *)
(* !linearZr_LR /=. linearZ. *)
(* linearZl. *)
(* rewrite trmx_sesqui. *)
(* rewrite mapmx. *)
(* rewrite map *)
(* apply/matrixP. *)
(* rewrite formC. *)
(* Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. *)
(* Lemma cfCauchySchwarz u v : *)
(* `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free (u :: v). *)
(* Proof. *)
(* rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. *)
(* have [-> | nz_v] /= := altP (v =P 0). *)
(* by apply/lerifP; rewrite !cfdot0r normCK mul0r mulr0. *)
(* without loss ou: u / '[u, v] = 0. *)
(* move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. *)
(* have ou: '[u1, v] = 0. *)
(* by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. *)
(* rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. *)
(* rewrite cfdotDl ou add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). *)
(* rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ou mulr0. *)
(* by have:= IHo _ ou; rewrite mulrDl -lerif_subLR subrr ou normCK mul0r. *)
(* rewrite ou normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. *)
(* rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_v) /=. *)
(* apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ou mulr0. *)
(* by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. *)
(* Qed. *)
End Sesquilinear.
Notation "eps_theta .-sesqui" := (sesqui _ eps_theta) : ring_scope.
Notation symmetric_form := (false, idfun).-sesqui.
Notation skew := (true, idfun).-sesqui.
Notation hermitian := (false, @Num.conj_op _).-sesqui.
HB.mixin Record isDotProduct (R : numDomainType) (U : lmodType R)
(op : U -> U -> R) := { neq0_dnorm_gt0 : forall u, u != 0 -> 0 < op u u }.
HB.structure Definition Dot (R : numDomainType) (U : lmodType R)
(theta : R -> R) :=
{op of isDotProduct R U op & @Hermitian R U false theta op}.
Notation "{ 'dot' U 'for' theta }" := (@Dot.type _ U theta)
(format "{ 'dot' U 'for' theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Notation "{ 'dot' U 'for' theta }" := (map theta (Phant U))
(format "{ 'dot' U 'for' theta }") : ring_scope.
Coercion base : class_of >-> Hermitian.class_of.
Coercion apply : map >-> Funclass.
Notation "[ 'dot' 'of' f 'as' g ]" := (@clone _ _ _ _ _ f g _ idfun idfun)
(format "[ 'dot' 'of' f 'as' g ]") : form_scope.
Notation "[ 'dot' 'of' f ]" := (@clone _ _ _ _ _ f f _ idfun idfun)
(format "[ 'dot' 'of' f ]") : form_scope.
Notation Dot fM := (pack fM idfun).
Notation is_dot := Dot.axiom.*)
Notation "{ 'symmetric' U }" := ({hermitian U for false & idfun})
(format "{ 'symmetric' U }") : ring_scope.
Notation "{ 'skew_symmetric' U }" := ({hermitian U for true & idfun})
(format "{ 'skew_symmetric' U }") : ring_scope.
Notation "{ 'hermitian_sym' U 'for' theta }" := ({hermitian U for false & theta})
(format "{ 'hermitian_sym' U 'for' theta }") : ring_scope.
Definition is_skew (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = true) /\ (theta =1 id).
Definition is_sym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false) /\ (theta =1 id).
Definition is_hermsym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false).
Section HermitianModuleTheory.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma hermC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof. by move: form => [? [[? ? ? ?] []]] /=. Qed.
Lemma hnormN u : '[- u] = '[u].
Proof. by rewrite linearNl linearNr opprK. Qed.
Lemma hnorm_sign n u : '[(-1) ^+ n *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?hnormN. Qed.
Lemma hnormD u v :
let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite /= addrAC -hermC linearDl 2!linearDr !addrA. Qed.
Lemma hnormB u v :
let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof.
by rewrite /= hnormD hnormN linearNr addrA rmorphN mulrN opprD addrA.
Qed.
Lemma hnormDd u v : '[u, v] = 0 -> '[u + v] = '[u] + '[v].
Proof. by move=> ouv; rewrite hnormD ouv rmorph0 mulr0 !addr0. Qed.
Lemma hnormBd u v : '[u, v] = 0 -> '[u - v] = '[u] + '[v].
Proof.
by move=> ouv; rewrite hnormDd ?hnormN// linearNr [X in - X]ouv oppr0.
Qed.
Local Notation "u '_|_ v" := ('[u, v] == 0) : ring_scope.
Definition ortho_rec (s1 s2 : seq U) :=
all [pred u | all [pred v | u '_|_ v] s2] s1.
Fixpoint pair_ortho_rec (s : seq U) :=
if s is v :: s' then ortho_rec [:: v] s' && pair_ortho_rec s' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal s := (0 \notin s) && pair_ortho_rec s.
Definition orthogonal s1 s2 := (@ortho_rec s1 s2).
Arguments orthogonal : simpl never.
Lemma orthogonal_cons u us vs :
orthogonal (u :: us) vs = orthogonal [:: u] vs && orthogonal us vs.
Proof. by rewrite /orthogonal /= andbT. Qed.
Definition orthonormal s := all [pred v | '[v] == 1] s && pair_ortho_rec s.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= linear0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
End HermitianModuleTheory.
Arguments orthogonal {R eps theta U} form s1 s2.
Arguments pairwise_orthogonal {R eps theta U} form s.
Arguments orthonormal {R eps theta U} form s.
Section HermitianIsometry.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U1 U2 : lmodType R) (form1 : {hermitian U1 for eps & theta})
(form2 : {hermitian U2 for eps & theta}).
Local Notation "''[' u , v ]_1" := (form1 u%R v%R) : ring_scope.
Local Notation "''[' u , v ]_2" := (form2 u%R v%R) : ring_scope.
Local Notation "''[' u ]_1" := (form1 u%R u%R) : ring_scope.
Local Notation "''[' u ]_2" := (form2 u%R u%R): ring_scope.
Definition isometry tau := forall u v, form1 (tau u) (tau v) = form2 u%R v%R.
Definition isometry_from_to mD tau mR :=
prop_in2 mD (inPhantom (isometry tau)) /\
prop_in1 mD (inPhantom (forall u, in_mem (tau u) mR)).
Local Notation "{ 'in' D , 'isometry' tau , 'to' R }" :=
(isometry_from_to (mem D) tau (mem R))
(format "{ 'in' D , 'isometry' tau , 'to' R }")
: type_scope.
End HermitianIsometry.
Section HermitianVectTheory.
Variables (R : fieldType) (eps : bool) (theta : {rmorphism R -> R}).
Variable (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma herm_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite hermC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
End HermitianVectTheory.
Section HermitianFinVectTheory.
Variables (F : fieldType) (eps : bool) (theta : {rmorphism F -> F}).
Variables (vT : vectType F) (form : {hermitian vT for eps & theta}).
Let n := \dim {:vT}.
Implicit Types (u v : vT) (U V : {vspace vT}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Let alpha v := (linfun (applyr form v : vT -> F^o)).
Definition orthov V := (\bigcap_(i < \dim V) lker (alpha (vbasis V)`_i))%VS.
Local Notation "U '_|_ V" := (U <= orthov V)%VS : vspace_scope.
Lemma mem_orthovPn V u : reflect (exists2 v, v \in V & '[u, v] != 0) (u \notin orthov V).
Proof.
apply: (iffP idP) => [u_orthovV|[v /coord_vbasis-> uvNorthov]]; last first.
apply/subv_bigcapP => uP.
rewrite linear_sumr big1 ?eqxx//= in uvNorthov.
move=> i _; have := uP i isT.
by rewrite -memvE memv_ker lfunE/= linearZr/= => /eqP/= ->; rewrite mulr0.
suff /existsP [i ui_neq0] : [exists i : 'I_(\dim V), '[u, (vbasis V)`_i] != 0].
by exists (vbasis V)`_i => //; rewrite vbasis_mem ?mem_nth ?size_tuple.
apply: contraNT u_orthovV; rewrite negb_exists => /forallP ui_eq0.
apply/subv_bigcapP => i _.
by rewrite -memvE memv_ker lfunE /= -[_ == _]negbK.
Qed.
Lemma mem_orthovP V u : reflect {in V, forall v, '[u, v] = 0} (u \in orthov V).
Proof.
apply: (iffP idP) => [/mem_orthovPn orthovNu v vV|/(_ _ _)/eqP orthov_u].
by apply/eqP/negP=> /negP Northov_uv; apply: orthovNu; exists v.
by apply/mem_orthovPn => -[v /orthov_u->].
Qed.
Lemma orthov1E u : orthov <[u]> = lker (alpha u).
Proof.
apply/eqP; rewrite eqEsubv; apply/andP.
split; apply/subvP=> v; rewrite memv_ker lfunE /=.
by move=> /mem_orthovP-> //; rewrite ?memv_line.
move=> vu_eq0; apply/mem_orthovP => w /vlineP[k->].
by apply/eqP; rewrite linearZ mulf_eq0 vu_eq0 orbT.
Qed.
Lemma orthovP U V : reflect {in U & V, forall u v, '[u, v] = 0} (U '_|_ V)%VS.
Proof.
apply: (iffP subvP); last by move=> H ??; apply/mem_orthovP=> ??; apply: H.
by move=> /(_ _ _)/mem_orthovP; move=> H ????; apply: H.
Qed.
Lemma orthov_sym U V : (U '_|_ V)%VS = (V '_|_ U)%VS.
Proof. by apply/orthovP/orthovP => eq0 ????; apply/eqP; rewrite herm_eq0C eq0. Qed.
Lemma mem_orthov1 v u : (u \in orthov <[v]>) = ('[u, v] == 0).
Proof. by rewrite orthov1E memv_ker lfunE. Qed.
Lemma orthov11 u v : (<[u]> '_|_ <[v]>)%VS = ('[u, v] == 0).
Proof. exact: mem_orthov1. Qed.
Lemma mem_orthov1_sym v u : (u \in orthov <[v]>) = (v \in orthov <[u]>).
Proof. exact: orthov_sym. Qed.
Lemma orthov0 : orthov 0 = fullv.
Proof.
apply/eqP; rewrite eqEsubv subvf.
apply/subvP => x _; rewrite mem_orthov1.
by rewrite linear0r.
Qed.
Lemma mem_orthov_sym V u : (u \in orthov V) = (V <= orthov <[u]>)%VS.
Proof. exact: orthov_sym. Qed.
Lemma leq_dim_orthov1 u V : ((\dim V).-1 <= \dim (V :&: orthov <[u]>))%N.
Proof.
rewrite -(limg_ker_dim (alpha u) V) -orthov1E.
have := dimvS (subvf (alpha u @: V)); rewrite dimvf addnC.
by case: (\dim _) => [|[]] // _; rewrite leq_pred.
Qed.
Lemma dim_img_form_eq1 u V : u \notin orthov V -> \dim (alpha u @: V)%VS = 1%N.
Proof.
move=> /mem_orthovPn [v vV Northov_uv]; apply/eqP; rewrite eqn_leq /=.
rewrite -[1%N as X in (_ <= X)%N](dimvf [the vectType F of F^o]) dimvS ?subvf//=.
have := @dimvS _ _ <['[v, u] : F^o]> (alpha u @: V).
rewrite -memvE dim_vline herm_eq0C Northov_uv; apply.
by apply/memv_imgP; exists v; rewrite ?memvf// !lfunE /=.
Qed.
Lemma eq_dim_orthov1 u V : u \notin orthov V -> (\dim V).-1 = \dim (V :&: orthov <[u]>).
Proof.
rewrite -(limg_ker_dim (alpha u) V) => /dim_img_form_eq1->.
by rewrite -orthov1E addn1.
Qed.
Lemma dim_img_form_eq0 u V : u \in orthov V -> \dim (alpha u @: V)%VS = 0%N.
Proof. by move=> uV; apply/eqP; rewrite dimv_eq0 -lkerE -orthov1E orthov_sym. Qed.
Lemma neq_dim_orthov1 u V : (\dim V > 0)%N ->
u \in orthov V -> ((\dim V).-1 < \dim (V :&: orthov <[u]>))%N.
Proof.
move=> V_gt0; rewrite -(limg_ker_dim (alpha u) V) -orthov1E => u_in.
rewrite dim_img_form_eq0 // addn0 (capv_idPl _) 1?orthov_sym //.
by case: (\dim _) V_gt0.
Qed.
Lemma leqif_dim_orthov1 u V : (\dim V > 0)%N ->
((\dim V).-1 <= \dim (V :&: orthov <[u]>) ?= iff (u \notin orthov V))%N.
Proof.
move=> Vr_gt0; apply/leqifP.
by case: (boolP (u \in _)) => /= [/neq_dim_orthov1->|/eq_dim_orthov1->].
Qed.
Lemma leqif_dim_orthov1_full u : (n > 0)%N ->
((\dim {:vT}).-1 <= \dim (orthov <[u]>) ?= iff (u \notin orthov fullv))%N.
Proof.
by move=> n_gt0; have := @leqif_dim_orthov1 u fullv; rewrite capfv; apply.
Qed.
(* Link between orthov and orthovgonality of sequences *)
Lemma orthogonal1P u v : reflect ('[u, v] = 0) (orthogonal form [:: u] [:: v]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP us vs :
reflect {in us & vs, forall u v, '[u, v] = 0} (orthogonal form us vs).
Proof.
apply: (iffP allP) => ousvs u => [v /ousvs/allP opus /opus/eqP // | /ousvs opus].
by apply/allP=> v /= /opus->.
Qed.
Lemma orthogonal_oppr S R : orthogonal form S (map -%R R) = orthogonal form S R.
Proof.
wlog suffices IH: S R / orthogonal form S R -> orthogonal form S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite linearNr /= oSR ?oppr0.
Qed.
Lemma orthogonalE us vs : (orthogonal form us vs) = (<<us>> '_|_ <<vs>>)%VS.
Proof.
apply/orthogonalP/orthovP => uvsP u v; last first.
by move=> uus vvs; rewrite uvsP // memv_span.
rewrite -[us]in_tupleE -[vs]in_tupleE => /coord_span-> /coord_span->.
rewrite linear_sumr big1 //= => i _.
rewrite linear_sumlz big1 //= => j _.
by rewrite linearZlr/= uvsP ?mulr0// mem_nth.
Qed.
Lemma orthovE U V : (U '_|_ V)%VS = orthogonal form (vbasis U) (vbasis V).
Proof. by rewrite orthogonalE !(span_basis (vbasisP _)). Qed.
Notation radv := (orthov fullv).
Lemma orthoDv U V W : (U + V '_|_ W)%VS = (U '_|_ W)%VS && (V '_|_ W)%VS.
Proof. by rewrite subv_add. Qed.
Lemma orthovD U V W : (U '_|_ V + W)%VS = (U '_|_ V)%VS && (U '_|_ W)%VS.
Proof. by rewrite ![(U '_|_ _)%VS]orthov_sym orthoDv. Qed.
Definition nondegenerate := radv == 0%VS.
Definition is_psymplectic := [/\ nondegenerate, is_skew form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_porthogonal := [/\ nondegenerate, is_sym form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_unitary := nondegenerate /\ (is_hermsym form).
End HermitianFinVectTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use is_psymplectic instead.")]
Notation is_symplectic := is_psymplectic (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use is_porthogonal instead.")]
Notation is_orthogonal := is_porthogonal (only parsing).
Arguments orthogonalP {F eps theta vT form us vs}.
Arguments orthovP {F eps theta vT form U V}.
Arguments mem_orthovPn {F eps theta vT form V u}.
Arguments mem_orthovP {F eps theta vT form V u}.
Section DotVectTheory.
Variables (C : numClosedFieldType).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma dnorm_geiff0 u : 0 <= '[u] ?= iff (u == 0).
Proof.
by apply/leifP; have [->|uN0] := altP eqP; rewrite ?linear0r ?neq0_dnorm_gt0.
Qed.
Lemma dnorm_ge0 u : 0 <= '[u]. Proof. by rewrite dnorm_geiff0. Qed.
Lemma dnorm_eq0 u : ('[u] == 0) = (u == 0).
Proof. by rewrite -dnorm_geiff0 eq_sym. Qed.
Lemma dnorm_gt0 u : (0 < '[u]) = (u != 0).
Proof. by rewrite lt_def dnorm_eq0 dnorm_ge0 andbT. Qed.
Lemma sqrt_dnorm_ge0 u : 0 <= sqrtC '[u].
Proof. by rewrite sqrtC_ge0 dnorm_ge0. Qed.
Lemma sqrt_dnorm_eq0 u : (sqrtC '[u] == 0) = (u == 0).
Proof. by rewrite sqrtC_eq0 dnorm_eq0. Qed.
Lemma sqrt_dnorm_gt0 u : (sqrtC '[u] > 0) = (u != 0).
Proof. by rewrite sqrtC_gt0 dnorm_gt0. Qed.
Lemma dnormZ a u : '[a *: u]= `|a| ^+ 2 * '[u].
Proof. by rewrite linearZl_LR linearZr_LR/= mulrA normCK. Qed.
Lemma dnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + d^*).
Proof. by rewrite hnormD mul1r. Qed.
Lemma dnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + d^*).
Proof. by rewrite hnormB mul1r. Qed.
End DotVectTheory.
#[global]
Hint Extern 0 (is_true (0 <= Dot.sort _ _ _
(* NB: This Hint is assuming ^*, a more precise pattern would be welcome *)))
=> apply: dnorm_ge0 : core.
Section HermitianTheory.
Variables (C : numClosedFieldType) (eps : bool) (theta : {rmorphism C -> C}).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal form S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi {}/IH IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?dnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi; rewrite !inE => /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
apply/eqP; rewrite hermC.
by move: (opS psi Spsi) => /= /eqP ->; rewrite rmorph0 mulr0.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal form (R ++ S) =
[&& pairwise_orthogonal form R, pairwise_orthogonal form S & orthogonal form R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT// all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma orthonormal_cat R S :
orthonormal form (R ++ S) =
[&& orthonormal form R, orthonormal form S & orthogonal form R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi] = (phi == psi)%:R})
(orthonormal form S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := altP eqP.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // linear0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal form S2 -> orthonormal form S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal form [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
End HermitianTheory.
Section DotFinVectTheory.
Variable C : numClosedFieldType.
Variables (U : vectType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal form S2 -> pairwise_orthogonal form S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal form S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0] = 0 := linear0r _ _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite linearZ /= oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 linearZ mulf_eq0 conjC_eq0 dnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal form S -> pairwise_orthogonal form (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_free S : orthonormal form S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Theorem CauchySchwarz (u v : U) :
`|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] /= := altP (v =P 0).
by apply/leifP; rewrite /= !linear0r normCK mul0r mulr0.
without loss ou: u / '[u, v] = 0.
move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v.
have ou: '[u1, v] = 0.
rewrite linearBl/=.
rewrite linearZl_LR.
by rewrite divfK ?dnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //.
rewrite linearDl /= ou add0r.
rewrite linearZl_LR/= normrM (ger0_norm (dnorm_ge0 _ _)).
rewrite exprMn mulrA -dnormZ hnormDd/=; last by rewrite linearZr_LR/= ou mulr0.
have:= IHo _ ou.
by rewrite mulrDl -leifBLR subrr ou normCK mul0r.
rewrite ou normCK mul0r; split; first by rewrite mulr_ge0.
rewrite eq_sym mulf_eq0 orbC dnorm_eq0 (negPf nz_v) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite linearZr_LR/= ou mulr0.
by rewrite dnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma CauchySchwarz_sqrt u v :
`|'[u, v]| <= sqrtC '[u] * sqrtC '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?nnegrE//.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM//= ?nnegrE//=.
exact: CauchySchwarz.
Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal form [:: phi] [:: psi]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal form [:: phi] S).
Proof.
by rewrite [orthogonal form _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (orthogonal form).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite hermC /= oRS ?rmorph0 ?mulr0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal form S [:: psi]).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite hermC /= oSpsi //= conjC0 mulr0.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal form (R1 ++ R2) S = orthogonal form R1 S && orthogonal form R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal form R (S1 ++ S2) = orthogonal form R S1 && orthogonal form R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal form R = pairwise_orthogonal form S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal S0 S : perm_eq S0 S -> orthonormal form S0 = orthonormal form S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthogonal_oppl S R : orthogonal form (map -%R S) R = orthogonal form S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma triangle_lerif u v :
sqrtC '[u + v] <= sqrtC '[u] + sqrtC '[v]
?= iff ~~ free [:: u; v] && (0 <= coord [tuple v] 0 u).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?nnegrE ?sqrtC_ge0//.
rewrite andbC sqrrD !sqrtCK addrAC dnormD (mono_leif (lerD2l _))/=.
rewrite -mulr_natr -[_ + _](divfK (negbT (pnatr_eq0 C 2))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n//.
have := leif_trans (leif_Re_Creal '[u, v]) (CauchySchwarz_sqrt u v).
rewrite ReE; congr (_ <= _ ?= iff _); apply: andb_id2r.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] := altP (v =P 0); first by rewrite linear0 coord0.
case/vlineP=> [x ->]; rewrite linearZl linearZ/= pmulr_lge0 ?dnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal form S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite linear_sumlz big1 // => i _; rewrite linear_sumr big1 // => j _.
by rewrite linearZlr/= oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : U & X \in <<S>>%VS &
{Y :U | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal form [:: Y] S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal form [:: Y] S}}.
- exists X => //; exists Y.
by rewrite hermC /= (span_orthogonal oYS) ?memv_span1 ?conjC0 // mulr0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[UU S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr UU V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi; rewrite !inE => /predU1P[-> | Spsi]; last first.
by rewrite linearBl linearZl_LR /= (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite linearBl !linearDr /= (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !linearZl_LR /= (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite linear0r !mul0r subrr.
by rewrite divfK ?dnorm_eq0 ?subrr.
Qed.
End DotFinVectTheory.
Arguments orthoP {C U form phi psi}.
Arguments pairwise_orthogonalP {C U form S}.
Arguments orthonormalP {C U form S}.
Arguments orthoPl {C U form phi S}.
Arguments orthoPr {C U form S psi}.
Section BuildIsometries.
Variables (C : numClosedFieldType) (U U1 U2 : vectType C).
Variables (form : {dot U for conjC}) (form1 : {dot U1 for conjC})
(form2 : {dot U2 for conjC}).
Definition normf1 := fun u => form1 u u.
Definition normf2 := fun u => form2 u u.
Lemma isometry_of_dnorm S tauS :
pairwise_orthogonal form1 S -> pairwise_orthogonal form2 tauS ->
map normf2 tauS = map normf1 S ->
{tau : {linear U1 -> U2} | map tau S = tauS
& {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite !linearZ/= !linear_sumlz; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !linearZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite /= -[RHS](nth_map 0 0 normf1) -?[LHS](nth_map 0 0 normf2) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry form2 form1 f} ->
{tau : {linear U1 -> U2} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have {}Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _] /=.
rewrite 2!{1}linear_sum /= !{1}linear_sumlz /=; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}linear_sumr; apply/eq_big_seq=> xi2 Sxi2 /=.
by rewrite !linearZ /= !linearZl !Dtau //= If.
Qed.
Lemma isometry_raddf_inj (tau : {additive U1 -> U2}) :
{in U1 &, isometry form2 form1 tau} ->
{in U1 &, forall u v, u - v \in U1} ->
{in U1 &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -(dnorm_eq0 form2) Itau ?linU // dnorm_eq0 subr_eq0 => /eqP.
Qed.
End BuildIsometries.
Section MatrixForms.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (M N P Q : 'M[R]_n).
Section Def.
Variable theta : R -> R.
Definition form_of_matrix m M (U V : 'M_(m, n)) := \tr (U *m M *m (V ^t theta)).
Definition matrix_of_form (form : 'rV[R]_n -> 'rV[R]_n -> R) : 'M[R]_n :=
\matrix_(i, j) form 'e_i 'e_j.
Implicit Type form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formE form i j : matrix_of_form form i j = form 'e_i 'e_j.
Proof. by rewrite mxE. Qed.
End Def.
Section FormOfMatrix.
Variables (m : nat) (M : 'M[R]_n).
Implicit Types (U V : 'M[R]_(m, n)).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' U , V ]" := (form_of_matrix theta M U%R V%R) : ring_scope.
Local Notation "''[' U ]" := '[U, U]%R : ring_scope.
Let form_of_matrix_is_linear U :
linear_for (theta \; *%R) (form_of_matrix theta M U).
Proof.
rewrite /form_of_matrix => k v w; rewrite -linearP/=.
by rewrite linearP map_mxD map_mxZ !mulmxDr !scalemxAr.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrix theta M U) (form_of_matrix_is_linear U).
Definition form_of_matrixr U := (form_of_matrix theta M)^~U.
Let form_of_matrixr_is_linear U : linear_for *%R (form_of_matrixr U).
Proof.
rewrite /form_of_matrixr /form_of_matrix => k v w.
by rewrite -linearP /= !mulmxDl -!scalemxAl.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrixr U) (form_of_matrixr_is_linear U).
(* TODO
Canonical form_of_matrixr_rev :=
[revop form_of_matrixr of form_of_matrix theta M].
*)
Lemma form_of_matrix_is_bilinear :
bilinear_for
(GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M).
Proof.
split=> [u'|u] a x y /=.
- by rewrite /form_of_matrix !mulmxDl linearD/= -!scalemxAl linearZ.
- rewrite /form_of_matrix -linearZ/= -linearD/= [in LHS]linearD/= map_mxD.
rewrite mulmxDr; congr (\tr (_ + _)).
rewrite scalemxAr; congr (_ *m _).
by rewrite linearZ/= map_mxZ.
Qed.
HB.instance Definition _ :=
bilinear_isBilinear.Build R _ _ _
(GRing.Scale.Law.clone _ _ ( *%R ) _)
(GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M)
form_of_matrix_is_bilinear.
(*Canonical form_of_matrix_is_bilinear := [the @bilinear _ _ _ _ of form_of_matrix theta M].*)
End FormOfMatrix.
Section FormOfMatrix1.
Variables (M : 'M[R]_n).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma rV_formee i j : '['e_i :'rV__, 'e_j] = M i j.
Proof.
rewrite /form_of_matrix -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE trace_mx11 !mxE.
Qed.
Lemma form_of_matrixK : matrix_of_form (form_of_matrix theta M) = M.
Proof. by apply/matrixP => i j; rewrite !mxE rV_formee. Qed.
Lemma rV_form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof.
by rewrite /form_of_matrix => -> u v; rewrite mulmx0 mul0mx trace_mx11 mxE.
Qed.
End FormOfMatrix1.
Section MatrixOfForm.
Variable (theta : {rmorphism R -> R}).
Variable form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formK : form_of_matrix theta (matrix_of_form form) =2 form.
Proof.
set f := (X in X =2 _); have f_eq i j : f 'e_i 'e_j = form 'e_i 'e_j.
by rewrite /f rV_formee mxE.
move=> u v; rewrite [u]row_sum_delta [v]row_sum_delta /f.
rewrite !linear_sum/=; apply: eq_bigr => j _.
rewrite !linear_sumlz/=; apply: eq_bigr => i _.
by rewrite !linearZlr/= -f_eq.
Qed.
End MatrixOfForm.
Section HermitianMx.
Variable eps : bool.
Section HermitianMxDef.
Variable theta : R -> R.
Definition hermitianmx :=
[qualify M : 'M_n | M == ((-1) ^+ eps) *: M ^t theta].
Fact hermitianmx_key : pred_key hermitianmx. Proof. by []. Qed.
Canonical hermitianmx_keyed := KeyedQualifier hermitianmx_key.
Structure hermitian_matrix := HermitianMx {
mx_of_hermitian :> 'M[R]_n;
_ : mx_of_hermitian \is hermitianmx }.
Lemma is_hermitianmxE M :
(M \is hermitianmx) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma is_hermitianmxP M :
reflect (M = (-1) ^+ eps *: M ^t theta) (M \is hermitianmx).
Proof. by rewrite is_hermitianmxE; apply/eqP. Qed.
Lemma hermitianmxE (M : hermitian_matrix) :
M = ((-1) ^+ eps) *: M ^t theta :> 'M__.
Proof. by apply/eqP; case: M. Qed.
Lemma trmx_hermitian (M : hermitian_matrix) :
M^T = ((-1) ^+ eps) *: M ^ theta :> 'M__.
Proof. by rewrite {1}hermitianmxE linearZ /= map_trmx trmxK. Qed.
End HermitianMxDef.
Section HermitianMxTheory.
Variables (theta : involutive_rmorphism R) (M : hermitian_matrix theta).
Lemma maptrmx_hermitian : M^t theta = (-1) ^+ eps *: (M : 'M__).
Proof.
rewrite trmx_hermitian map_mxZ rmorph_sign -map_mx_comp.
by rewrite (map_mx_id (rmorphK _)).
Qed.
Lemma form_of_matrix_is_hermitian m x y :
(@form_of_matrix theta m M) x y =
(-1) ^+ eps * theta ((@form_of_matrix theta m M) y x).
Proof.
rewrite {1}hermitianmxE /form_of_matrix.
rewrite -!(scalemxAr, scalemxAl) linearZ/=; congr (_ * _).
rewrite -mxtrace_tr -trace_map_mx !(trmx_mul, map_mxM, map_trmx, trmxK).
by rewrite -mulmxA -!map_mx_comp !(map_mx_id (rmorphK _)).
Qed.
HB.instance Definition _ m := @isHermitianSesquilinear.Build _ _ _ _ _
(@form_of_matrix_is_hermitian m).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Local Notation "B ^!" := (orthomx theta M B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B%MS^!)%MS : matrix_set_scope.
Lemma orthomxE u v : (u '_|_ v)%MS = ('[u, v] == 0).
Proof.
rewrite (sameP sub_kermxP eqP) mulmxA.
by rewrite [_ *m _^t _]mx11_scalar -trace_mx11 fmorph_eq0.
Qed.
Lemma hermmx_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v)%MS.
Proof. by rewrite orthomxE; apply/eqP. Qed.
Lemma orthomxP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), u <= A -> v <= B -> u '_|_ v)%MS
(A '_|_ B)%MS.
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma orthomx_sym p q (A : 'M_(p, n)) (B :'M_(q, n)) :
(A '_|_ B)%MS = (B '_|_ A)%MS.
Proof.
gen have nC : p q A B / (A '_|_ B -> B '_|_ A)%MS; last by apply/idP/idP; apply/nC.
move=> AnB; apply/orthomxP => u v ? ?; rewrite orthomxE.
rewrite hermC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -orthomxE (orthomxP _ _ AnB).
Qed.
Lemma ortho_ortho_mx p (A : 'M_(p, n)) : (A^! '_|_ A)%MS. Proof. by []. Qed.
Lemma ortho_mx_ortho p (A : 'M_(p, n)) : (A '_|_ A^!)%MS.
Proof. by rewrite orthomx_sym. Qed.
Lemma rank_orthomx u : (\rank (u ^!) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Local Notation radmx := (1%:M^!)%MS.
Lemma radmxE : radmx = kermx M.
Proof. by rewrite /orthomx /orthomx trmx1 map_mx1 mulmx1. Qed.
Lemma orthoNmx k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
((- A) '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by rewrite eqmx_opp. Qed.
Lemma orthomxN k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
(A '_|_ (- B))%MS = (A '_|_ B)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoNmx. Qed.
Lemma orthoDmx k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A + B '_|_ C)%MS = (A '_|_ C)%MS && (B '_|_ C)%MS.
Proof. by rewrite addsmxE !(sameP sub_kermxP eqP) mul_col_mx col_mx_eq0. Qed.
Lemma orthomxD k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A '_|_ B + C)%MS = (A '_|_ B)%MS && (A '_|_ C)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoDmx. Qed.
Lemma orthoZmx p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(a *: A '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite eqmx_scale. Qed.
Lemma orthomxZ p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(A '_|_ (a *: B))%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite ![(A '_|_ _)%MS]orthomx_sym orthoZmx. Qed.
Lemma eqmx_ortho p m (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) :
(A :=: B)%MS -> (A^! :=: B^!)%MS.
Proof.
move=> eqAB; apply/eqmxP.
by rewrite orthomx_sym -eqAB ortho_mx_ortho orthomx_sym eqAB ortho_mx_ortho.
Qed.
Lemma genmx_ortho p (A : 'M[R]_(p, n)) : (<<A>>^! :=: A^!)%MS.
Proof. exact: (eqmx_ortho (genmxE _)). Qed.
End HermitianMxTheory.
End HermitianMx.
End MatrixForms.
Notation symmetricmx := (hermitianmx _ false idfun).
Notation skewmx := (hermitianmx _ true idfun).
Notation hermsymmx := (hermitianmx _ false conjC).
Lemma hermitian1mx_subproof {C : numClosedFieldType} n : (1%:M : 'M[C]_n) \is hermsymmx.
Proof.
by rewrite qualifE /= expr0 scale1r tr_scalar_mx map_scalar_mx conjC1.
Qed.
Canonical hermitian1mx {C : numClosedFieldType} n :=
HermitianMx (@hermitian1mx_subproof C n).
|
Closure.lean
|
/-
Copyright (c) 2024 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.Matroid.Map
import Mathlib.Order.Closure
import Mathlib.Order.CompleteLatticeIntervals
/-!
# Matroid Closure
A flat (`IsFlat`) of a matroid `M` is a combinatorial analogue of a subspace of a vector space,
and is defined to be a subset `F` of the ground set of `M` such that for each basis
`I` for `F`, every set having `I` as a basis is contained in `F`.
The *closure* of a set `X` in a matroid `M` is the intersection of all flats of `M` containing `X`.
This is a combinatorial analogue of the linear span of a set of vectors.
For `M : Matroid α`, this file defines a predicate `M.IsFlat : Set α → Prop` and a function
`M.closure : Set α → Set α` corresponding to these notions, and develops API for the latter.
API for `Matroid.IsFlat` will appear in another file; we include the definition here since
it is used in the definition of `Matroid.closure`.
We also define a predicate `Spanning`, to describe a set whose closure is the entire ground set.
## Main definitions
* For `M : Matroid α` and `F : Set α`, `M.IsFlat F` means that `F` is a isFlat of `M`.
* For `M : Matroid α` and `X : Set α`, `M.closure X` is the closure of `X` in `M`.
* For `M : Matroid α` and `X : ↑(Iic M.E)` (i.e. a bundled subset of `M.E`),
`M.subtypeClosure X` is the closure of `X`, viewed as a term in `↑(Iic M.E)`.
This is a `ClosureOperator` on `↑(Iic M.E)`.
* For `M : Matroid α` and `S ⊆ M.E`, `M.Spanning S` means that `S` has closure equal to `M.E`,
or equivalently that `S` contains a isBase of `M`.
## Implementation details
If `X : Set α` satisfies `X ⊆ M.E`, then it is clear how `M.closure X` should be defined.
But `M.closure X` also needs to be defined for all `X : Set α`,
so a convention is needed for how it handles sets containing junk elements outside `M.E`.
All such choices come with tradeoffs. Provided that `M.closure X` has already been defined
for `X ⊆ M.E`, the two best candidates for extending it to all `X` seem to be:
(1) The function for which `M.closure X = M.closure (X ∩ M.E)` for all `X : Set α`
(2) The function for which `M.closure X = M.closure (X ∩ M.E) ∪ X` for all `X : Set α`
For both options, the function `closure` is monotone and idempotent with no assumptions on `X`.
Choice (1) has the advantage that `M.closure X ⊆ M.E` holds for all `X` without the assumption
that `X ⊆ M.E`, which is very nice for `aesop_mat`. It is also fairly convenient to rewrite
`M.closure X` to `M.closure (X ∩ M.E)` when one needs to work with a subset of the ground set.
Its disadvantage is that the statement `X ⊆ M.closure X` is only true provided that `X ⊆ M.E`.
Choice (2) has the reverse property: we would have `X ⊆ M.closure X` for all `X`,
but the condition `M.closure X ⊆ M.E` requires `X ⊆ M.E` to hold.
It has a couple of other advantages too: it is actually the closure function of a matroid on `α`
with ground set `univ` (specifically, the direct sum of `M` and a free matroid on `M.Eᶜ`),
and because of this, it is an example of a `ClosureOperator` on `α`, which in turn gives access
to nice existing API for both `ClosureOperator` and `GaloisInsertion`.
This also relates to flats; `F ⊆ M.E ∧ ClosureOperator.IsClosed F` is equivalent to `M.IsFlat F`.
(All of this fails for choice (1), since `X ⊆ M.closure X` is required for
a `ClosureOperator`, but isn't true for non-subsets of `M.E`)
The API that choice (2) would offer is very beguiling, but after extensive experimentation in
an external repo, it seems that (1) is far less rough around the edges in practice,
so we go with (1). It may be helpful at some point to define a primed version
`Matroid.closure' : ClosureOperator (Set α)` corresponding to choice (2).
Failing that, the `ClosureOperator`/`GaloisInsertion` API is still available on
the subtype `↑(Iic M.E)` via `Matroid.SubtypeClosure`, albeit less elegantly.
## Naming conventions
In lemma names, the words `spanning` and `isFlat` are used as suffixes,
for instance we have `ground_spanning` rather than `spanning_ground`.
-/
assert_not_exists Field
open Set
namespace Matroid
variable {ι α : Type*} {M : Matroid α} {F X Y : Set α} {e f : α}
section IsFlat
/-- A flat is a maximal set having a given basis -/
@[mk_iff]
structure IsFlat (M : Matroid α) (F : Set α) : Prop where
subset_of_isBasis_of_isBasis : ∀ ⦃I X⦄, M.IsBasis I F → M.IsBasis I X → X ⊆ F
subset_ground : F ⊆ M.E
@[deprecated (since := "2025-02-14")] alias Flat := IsFlat
attribute [aesop unsafe 20% (rule_sets := [Matroid])] IsFlat.subset_ground
@[simp] lemma ground_isFlat (M : Matroid α) : M.IsFlat M.E :=
⟨fun _ _ _ ↦ IsBasis.subset_ground, Subset.rfl⟩
lemma IsFlat.iInter {ι : Type*} [Nonempty ι] {Fs : ι → Set α}
(hFs : ∀ i, M.IsFlat (Fs i)) : M.IsFlat (⋂ i, Fs i) := by
refine ⟨fun I X hI hIX ↦ subset_iInter fun i ↦ ?_,
(iInter_subset _ (Classical.arbitrary _)).trans (hFs _).subset_ground⟩
obtain ⟨J, hIJ, hJ⟩ := hI.indep.subset_isBasis_of_subset (hI.subset.trans (iInter_subset _ i))
refine subset_union_right.trans ((hFs i).1 (X := Fs i ∪ X) hIJ ?_)
convert hIJ.isBasis_union (hIX.isBasis_union_of_subset hIJ.indep hJ) using 1
rw [← union_assoc, union_eq_self_of_subset_right hIJ.subset]
/-- The property of being a flat gives rise to a `ClosureOperator` on the subsets of `M.E`,
in which the `IsClosed` sets correspond to flats.
(We can't define such an operator on all of `Set α`,
since this would incorrectly force `univ` to always be a flat.) -/
def subtypeClosure (M : Matroid α) : ClosureOperator (Iic M.E) :=
ClosureOperator.ofCompletePred (fun F ↦ M.IsFlat F.1) fun s hs ↦ by
obtain (rfl | hne) := s.eq_empty_or_nonempty
· simp
have _ := hne.coe_sort
convert IsFlat.iInter (M := M) (Fs := fun (F : s) ↦ F.1.1) (fun F ↦ hs F.1 F.2)
ext
aesop
lemma isFlat_iff_isClosed : M.IsFlat F ↔ ∃ h : F ⊆ M.E, M.subtypeClosure.IsClosed ⟨F, h⟩ := by
simpa [subtypeClosure] using IsFlat.subset_ground
lemma isClosed_iff_isFlat {F : Iic M.E} : M.subtypeClosure.IsClosed F ↔ M.IsFlat F := by
simp [subtypeClosure]
end IsFlat
/-- The closure of `X ⊆ M.E` is the intersection of all the flats of `M` containing `X`.
A set `X` that doesn't satisfy `X ⊆ M.E` has the junk value `M.closure X := M.closure (X ∩ M.E)`. -/
def closure (M : Matroid α) (X : Set α) : Set α := ⋂₀ {F | M.IsFlat F ∧ X ∩ M.E ⊆ F}
lemma closure_def (M : Matroid α) (X : Set α) : M.closure X = ⋂₀ {F | M.IsFlat F ∧ X ∩ M.E ⊆ F} :=
rfl
lemma closure_def' (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
M.closure X = ⋂₀ {F | M.IsFlat F ∧ X ⊆ F} := by
rw [closure, inter_eq_self_of_subset_left hX]
instance : Nonempty {F | M.IsFlat F ∧ X ∩ M.E ⊆ F} := ⟨M.E, M.ground_isFlat, inter_subset_right⟩
lemma closure_eq_subtypeClosure (M : Matroid α) (X : Set α) :
M.closure X = M.subtypeClosure ⟨X ∩ M.E, inter_subset_right⟩ := by
suffices ∀ (x : α), (∀ (t : Set α), M.IsFlat t → X ∩ M.E ⊆ t → x ∈ t) ↔
(x ∈ M.E ∧ ∀ a ⊆ M.E, X ∩ M.E ⊆ a → M.IsFlat a → x ∈ a) by
simpa [closure, subtypeClosure, Set.ext_iff]
exact fun x ↦ ⟨fun h ↦ ⟨h _ M.ground_isFlat inter_subset_right, fun F _ hXF hF ↦ h F hF hXF⟩,
fun ⟨_, h⟩ F hF hXF ↦ h F hF.subset_ground hXF hF⟩
@[aesop unsafe 10% (rule_sets := [Matroid])]
lemma closure_subset_ground (M : Matroid α) (X : Set α) : M.closure X ⊆ M.E :=
sInter_subset_of_mem ⟨M.ground_isFlat, inter_subset_right⟩
@[simp] lemma ground_subset_closure_iff : M.E ⊆ M.closure X ↔ M.closure X = M.E := by
simp [M.closure_subset_ground X, subset_antisymm_iff]
@[simp] lemma closure_inter_ground (M : Matroid α) (X : Set α) :
M.closure (X ∩ M.E) = M.closure X := by
simp_rw [closure_def, inter_assoc, inter_self]
lemma inter_ground_subset_closure (M : Matroid α) (X : Set α) : X ∩ M.E ⊆ M.closure X := by
simp_rw [closure_def, subset_sInter_iff]; simp
lemma mem_closure_iff_forall_mem_isFlat (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
e ∈ M.closure X ↔ ∀ F, M.IsFlat F → X ⊆ F → e ∈ F := by
simp_rw [M.closure_def' X, mem_sInter, mem_setOf, and_imp]
lemma subset_closure_iff_forall_subset_isFlat (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
Y ⊆ M.closure X ↔ ∀ F, M.IsFlat F → X ⊆ F → Y ⊆ F := by
simp_rw [M.closure_def' X, subset_sInter_iff, mem_setOf, and_imp]
lemma subset_closure (M : Matroid α) (X : Set α) (hX : X ⊆ M.E := by aesop_mat) :
X ⊆ M.closure X := by
simp [M.closure_def' X, subset_sInter_iff]
lemma IsFlat.closure (hF : M.IsFlat F) : M.closure F = F :=
(sInter_subset_of_mem (by simpa)).antisymm (M.subset_closure F)
variable (X) in
@[simp] lemma isFlat_closure : M.IsFlat (M.closure X) := by
rw [closure, sInter_eq_iInter]; exact .iInter (·.2.1)
lemma isFlat_iff_closure_eq : M.IsFlat F ↔ M.closure F = F := ⟨(·.closure), (· ▸ isFlat_closure F)⟩
@[simp] lemma closure_ground (M : Matroid α) : M.closure M.E = M.E :=
(M.closure_subset_ground M.E).antisymm (M.subset_closure M.E)
@[simp] lemma closure_univ (M : Matroid α) : M.closure univ = M.E := by
rw [← closure_inter_ground, univ_inter, closure_ground]
@[gcongr]
lemma closure_subset_closure (M : Matroid α) (h : X ⊆ Y) : M.closure X ⊆ M.closure Y :=
subset_sInter (fun _ h' ↦ sInter_subset_of_mem
⟨h'.1, subset_trans (inter_subset_inter_left _ h) h'.2⟩)
lemma closure_mono (M : Matroid α) : Monotone M.closure :=
fun _ _ ↦ M.closure_subset_closure
@[simp] lemma closure_closure (M : Matroid α) (X : Set α) : M.closure (M.closure X) = M.closure X :=
(M.subset_closure _).antisymm' (subset_sInter
(fun F hF ↦ (closure_subset_closure _ (sInter_subset_of_mem hF)).trans hF.1.closure.subset))
lemma closure_subset_closure_of_subset_closure (hXY : X ⊆ M.closure Y) :
M.closure X ⊆ M.closure Y :=
(M.closure_subset_closure hXY).trans_eq (M.closure_closure Y)
lemma closure_subset_closure_iff_subset_closure (hX : X ⊆ M.E := by aesop_mat) :
M.closure X ⊆ M.closure Y ↔ X ⊆ M.closure Y :=
⟨(M.subset_closure X).trans, closure_subset_closure_of_subset_closure⟩
lemma subset_closure_of_subset (M : Matroid α) (hXY : X ⊆ Y) (hY : Y ⊆ M.E := by aesop_mat) :
X ⊆ M.closure Y :=
hXY.trans (M.subset_closure Y)
lemma subset_closure_of_subset' (M : Matroid α) (hXY : X ⊆ Y) (hX : X ⊆ M.E := by aesop_mat) :
X ⊆ M.closure Y := by
rw [← closure_inter_ground]; exact M.subset_closure_of_subset (subset_inter hXY hX)
lemma exists_of_closure_ssubset (hXY : M.closure X ⊂ M.closure Y) : ∃ e ∈ Y, e ∉ M.closure X := by
by_contra! hcon
exact hXY.not_subset (M.closure_subset_closure_of_subset_closure hcon)
lemma mem_closure_of_mem (M : Matroid α) (h : e ∈ X) (hX : X ⊆ M.E := by aesop_mat) :
e ∈ M.closure X :=
(M.subset_closure X) h
lemma mem_closure_of_mem' (M : Matroid α) (heX : e ∈ X) (h : e ∈ M.E := by aesop_mat) :
e ∈ M.closure X := by
rw [← closure_inter_ground]
exact M.mem_closure_of_mem ⟨heX, h⟩
lemma notMem_of_mem_diff_closure (he : e ∈ M.E \ M.closure X) : e ∉ X :=
fun heX ↦ he.2 <| M.mem_closure_of_mem' heX he.1
@[deprecated (since := "2025-05-23")]
alias not_mem_of_mem_diff_closure := notMem_of_mem_diff_closure
@[aesop unsafe 10% (rule_sets := [Matroid])]
lemma mem_ground_of_mem_closure (he : e ∈ M.closure X) : e ∈ M.E :=
(M.closure_subset_ground _) he
lemma closure_iUnion_closure_eq_closure_iUnion (M : Matroid α) (Xs : ι → Set α) :
M.closure (⋃ i, M.closure (Xs i)) = M.closure (⋃ i, Xs i) := by
simp_rw [closure_eq_subtypeClosure, iUnion_inter, Subtype.coe_inj]
convert M.subtypeClosure.closure_iSup_closure (fun i ↦ ⟨Xs i ∩ M.E, inter_subset_right⟩) <;>
simp [← iUnion_inter, subtypeClosure]
lemma closure_iUnion_congr (Xs Ys : ι → Set α) (h : ∀ i, M.closure (Xs i) = M.closure (Ys i)) :
M.closure (⋃ i, Xs i) = M.closure (⋃ i, Ys i) := by
simp [h, ← M.closure_iUnion_closure_eq_closure_iUnion]
lemma closure_biUnion_closure_eq_closure_sUnion (M : Matroid α) (Xs : Set (Set α)) :
M.closure (⋃ X ∈ Xs, M.closure X) = M.closure (⋃₀ Xs) := by
rw [sUnion_eq_iUnion, biUnion_eq_iUnion, closure_iUnion_closure_eq_closure_iUnion]
lemma closure_biUnion_closure_eq_closure_biUnion (M : Matroid α) (Xs : ι → Set α) (A : Set ι) :
M.closure (⋃ i ∈ A, M.closure (Xs i)) = M.closure (⋃ i ∈ A, Xs i) := by
rw [biUnion_eq_iUnion, M.closure_iUnion_closure_eq_closure_iUnion, biUnion_eq_iUnion]
lemma closure_biUnion_congr (M : Matroid α) (Xs Ys : ι → Set α) (A : Set ι)
(h : ∀ i ∈ A, M.closure (Xs i) = M.closure (Ys i)) :
M.closure (⋃ i ∈ A, Xs i) = M.closure (⋃ i ∈ A, Ys i) := by
rw [← closure_biUnion_closure_eq_closure_biUnion, iUnion₂_congr h,
closure_biUnion_closure_eq_closure_biUnion]
lemma closure_closure_union_closure_eq_closure_union (M : Matroid α) (X Y : Set α) :
M.closure (M.closure X ∪ M.closure Y) = M.closure (X ∪ Y) := by
rw [eq_comm, union_eq_iUnion, ← closure_iUnion_closure_eq_closure_iUnion, union_eq_iUnion]
simp_rw [Bool.cond_eq_ite, apply_ite]
@[simp] lemma closure_union_closure_right_eq (M : Matroid α) (X Y : Set α) :
M.closure (X ∪ M.closure Y) = M.closure (X ∪ Y) := by
rw [← closure_closure_union_closure_eq_closure_union, closure_closure,
closure_closure_union_closure_eq_closure_union]
@[simp] lemma closure_union_closure_left_eq (M : Matroid α) (X Y : Set α) :
M.closure (M.closure X ∪ Y) = M.closure (X ∪ Y) := by
rw [← closure_closure_union_closure_eq_closure_union, closure_closure,
closure_closure_union_closure_eq_closure_union]
@[simp] lemma closure_insert_closure_eq_closure_insert (M : Matroid α) (e : α) (X : Set α) :
M.closure (insert e (M.closure X)) = M.closure (insert e X) := by
simp_rw [← singleton_union, closure_union_closure_right_eq]
lemma closure_union_congr_left {X' : Set α} (h : M.closure X = M.closure X') :
M.closure (X ∪ Y) = M.closure (X' ∪ Y) := by
rw [← M.closure_union_closure_left_eq, h, M.closure_union_closure_left_eq]
lemma closure_union_congr_right {Y' : Set α} (h : M.closure Y = M.closure Y') :
M.closure (X ∪ Y) = M.closure (X ∪ Y') := by
rw [← M.closure_union_closure_right_eq, h, M.closure_union_closure_right_eq]
lemma closure_insert_congr_right (h : M.closure X = M.closure Y) :
M.closure (insert e X) = M.closure (insert e Y) := by
simp [← union_singleton, closure_union_congr_left h]
@[simp] lemma closure_union_closure_empty_eq (M : Matroid α) (X : Set α) :
M.closure X ∪ M.closure ∅ = M.closure X :=
union_eq_self_of_subset_right (M.closure_subset_closure (empty_subset _))
@[simp] lemma closure_empty_union_closure_eq (M : Matroid α) (X : Set α) :
M.closure ∅ ∪ M.closure X = M.closure X :=
union_eq_self_of_subset_left (M.closure_subset_closure (empty_subset _))
lemma closure_insert_eq_of_mem_closure (he : e ∈ M.closure X) :
M.closure (insert e X) = M.closure X := by
rw [← closure_insert_closure_eq_closure_insert, insert_eq_of_mem he, closure_closure]
lemma mem_closure_self (M : Matroid α) (e : α) (he : e ∈ M.E := by aesop_mat) : e ∈ M.closure {e} :=
mem_closure_of_mem' M rfl
section Indep
variable {ι : Sort*} {I J B : Set α} {x : α}
lemma Indep.closure_eq_setOf_isBasis_insert (hI : M.Indep I) :
M.closure I = {x | M.IsBasis I (insert x I)} := by
set F := {x | M.IsBasis I (insert x I)}
have hIF : M.IsBasis I F := hI.isBasis_setOf_insert_isBasis
have hF : M.IsFlat F := by
refine ⟨fun J X hJF hJX e heX ↦ show M.IsBasis _ _ from ?_, hIF.subset_ground⟩
exact (hIF.isBasis_of_isBasis_of_subset_of_subset (hJX.isBasis_union hJF) hJF.subset
(hIF.subset.trans subset_union_right)).isBasis_subset (subset_insert _ _)
(insert_subset (Or.inl heX) (hIF.subset.trans subset_union_right))
rw [subset_antisymm_iff, closure_def, subset_sInter_iff, and_iff_right (sInter_subset_of_mem _)]
· rintro F' ⟨hF', hIF'⟩ e (he : M.IsBasis I (insert e I))
rw [inter_eq_left.mpr (hIF.subset.trans hIF.subset_ground)] at hIF'
obtain ⟨J, hJ, hIJ⟩ := hI.subset_isBasis_of_subset hIF' hF'.2
exact (hF'.1 hJ (he.isBasis_union_of_subset hJ.indep hIJ)) (Or.inr (mem_insert _ _))
exact ⟨hF, inter_subset_left.trans hIF.subset⟩
lemma Indep.insert_isBasis_iff_mem_closure (hI : M.Indep I) :
M.IsBasis I (insert e I) ↔ e ∈ M.closure I := by
rw [hI.closure_eq_setOf_isBasis_insert, mem_setOf]
lemma Indep.isBasis_closure (hI : M.Indep I) : M.IsBasis I (M.closure I) := by
rw [hI.closure_eq_setOf_isBasis_insert]; exact hI.isBasis_setOf_insert_isBasis
lemma IsBasis.closure_eq_closure (h : M.IsBasis I X) : M.closure I = M.closure X := by
refine subset_antisymm (M.closure_subset_closure h.subset) ?_
rw [← M.closure_closure I, h.indep.closure_eq_setOf_isBasis_insert]
exact M.closure_subset_closure fun e he ↦ (h.isBasis_subset (subset_insert _ _)
(insert_subset he h.subset))
lemma IsBasis.closure_eq_right (h : M.IsBasis I (M.closure X)) : M.closure I = M.closure X :=
M.closure_closure X ▸ h.closure_eq_closure
lemma IsBasis'.closure_eq_closure (h : M.IsBasis' I X) : M.closure I = M.closure X := by
rw [← closure_inter_ground _ X, h.isBasis_inter_ground.closure_eq_closure]
lemma IsBasis.subset_closure (h : M.IsBasis I X) : X ⊆ M.closure I := by
rw [← closure_subset_closure_iff_subset_closure, h.closure_eq_closure]
lemma IsBasis'.isBasis_closure_right (h : M.IsBasis' I X) : M.IsBasis I (M.closure X) := by
rw [← h.closure_eq_closure]; exact h.indep.isBasis_closure
lemma IsBasis.isBasis_closure_right (h : M.IsBasis I X) : M.IsBasis I (M.closure X) :=
h.isBasis'.isBasis_closure_right
lemma Indep.mem_closure_iff (hI : M.Indep I) :
x ∈ M.closure I ↔ M.Dep (insert x I) ∨ x ∈ I := by
rwa [hI.closure_eq_setOf_isBasis_insert, mem_setOf, isBasis_insert_iff]
lemma Indep.mem_closure_iff' (hI : M.Indep I) :
x ∈ M.closure I ↔ x ∈ M.E ∧ (M.Indep (insert x I) → x ∈ I) := by
rw [hI.mem_closure_iff, dep_iff, insert_subset_iff, and_iff_left hI.subset_ground,
imp_iff_not_or]
have := hI.subset_ground
aesop
lemma Indep.insert_dep_iff (hI : M.Indep I) : M.Dep (insert e I) ↔ e ∈ M.closure I \ I := by
rw [mem_diff, hI.mem_closure_iff, or_and_right, and_not_self_iff, or_false,
iff_self_and, imp_not_comm]
intro heI; rw [insert_eq_of_mem heI]; exact hI.not_dep
lemma Indep.mem_closure_iff_of_notMem (hI : M.Indep I) (heI : e ∉ I) :
e ∈ M.closure I ↔ M.Dep (insert e I) := by
rw [hI.insert_dep_iff, mem_diff, and_iff_left heI]
@[deprecated (since := "2025-05-23")]
alias Indep.mem_closure_iff_of_not_mem := Indep.mem_closure_iff_of_notMem
lemma Indep.notMem_closure_iff (hI : M.Indep I) (he : e ∈ M.E := by aesop_mat) :
e ∉ M.closure I ↔ M.Indep (insert e I) ∧ e ∉ I := by
rw [hI.mem_closure_iff, dep_iff, insert_subset_iff, and_iff_right he,
and_iff_left hI.subset_ground]; tauto
@[deprecated (since := "2025-05-23")] alias Indep.not_mem_closure_iff := Indep.notMem_closure_iff
lemma Indep.notMem_closure_iff_of_notMem (hI : M.Indep I) (heI : e ∉ I)
(he : e ∈ M.E := by aesop_mat) : e ∉ M.closure I ↔ M.Indep (insert e I) := by
rw [hI.notMem_closure_iff, and_iff_left heI]
@[deprecated (since := "2025-05-23")]
alias Indep.not_mem_closure_iff_of_not_mem := Indep.notMem_closure_iff_of_notMem
lemma Indep.insert_indep_iff_of_notMem (hI : M.Indep I) (heI : e ∉ I) :
M.Indep (insert e I) ↔ e ∈ M.E \ M.closure I := by
rw [mem_diff, hI.mem_closure_iff_of_notMem heI, dep_iff, not_and, not_imp_not, insert_subset_iff,
and_iff_left hI.subset_ground]
exact ⟨fun h ↦ ⟨h.subset_ground (mem_insert e I), fun _ ↦ h⟩, fun h ↦ h.2 h.1⟩
@[deprecated (since := "2025-05-23")]
alias Indep.insert_indep_iff_of_not_mem := Indep.insert_indep_iff_of_notMem
lemma Indep.insert_indep_iff (hI : M.Indep I) :
M.Indep (insert e I) ↔ e ∈ M.E \ M.closure I ∨ e ∈ I := by
obtain (h | h) := em (e ∈ I)
· simp_rw [insert_eq_of_mem h, iff_true_intro hI, true_iff, iff_true_intro h, or_true]
rw [hI.insert_indep_iff_of_notMem h, or_iff_left h]
lemma insert_indep_iff : M.Indep (insert e I) ↔ M.Indep I ∧ (e ∉ I → e ∈ M.E \ M.closure I) := by
by_cases hI : M.Indep I
· rw [hI.insert_indep_iff, and_iff_right hI, or_iff_not_imp_right]
simp [hI, show ¬ M.Indep (insert e I) from fun h ↦ hI <| h.subset <| subset_insert _ _]
/-- This can be used for rewriting if the LHS is inside a binder and it is unknown
whether `f = e`. -/
lemma Indep.insert_diff_indep_iff (hI : M.Indep (I \ {e})) (heI : e ∈ I) :
M.Indep (insert f I \ {e}) ↔ f ∈ M.E \ M.closure (I \ {e}) ∨ f ∈ I := by
obtain rfl | hne := eq_or_ne e f
· simp [hI, heI]
rw [← insert_diff_singleton_comm hne.symm, hI.insert_indep_iff, mem_diff_singleton,
and_iff_left hne.symm]
lemma Indep.isBasis_of_subset_of_subset_closure (hI : M.Indep I) (hIX : I ⊆ X)
(hXI : X ⊆ M.closure I) : M.IsBasis I X :=
hI.isBasis_closure.isBasis_subset hIX hXI
lemma isBasis_iff_indep_subset_closure : M.IsBasis I X ↔ M.Indep I ∧ I ⊆ X ∧ X ⊆ M.closure I :=
⟨fun h ↦ ⟨h.indep, h.subset, h.subset_closure⟩,
fun h ↦ h.1.isBasis_of_subset_of_subset_closure h.2.1 h.2.2⟩
lemma Indep.isBase_of_ground_subset_closure (hI : M.Indep I) (h : M.E ⊆ M.closure I) :
M.IsBase I := by
rw [← isBasis_ground_iff]; exact hI.isBasis_of_subset_of_subset_closure hI.subset_ground h
lemma IsBase.closure_eq (hB : M.IsBase B) : M.closure B = M.E := by
rw [← isBasis_ground_iff] at hB; rw [hB.closure_eq_closure, closure_ground]
lemma IsBase.closure_of_superset (hB : M.IsBase B) (hBX : B ⊆ X) : M.closure X = M.E :=
(M.closure_subset_ground _).antisymm (hB.closure_eq ▸ M.closure_subset_closure hBX)
lemma isBase_iff_indep_closure_eq : M.IsBase B ↔ M.Indep B ∧ M.closure B = M.E := by
rw [← isBasis_ground_iff, isBasis_iff_indep_subset_closure, and_congr_right_iff]
exact fun hI ↦ ⟨fun h ↦ (M.closure_subset_ground _).antisymm h.2,
fun h ↦ ⟨(M.subset_closure B).trans_eq h, h.symm.subset⟩⟩
lemma IsBase.exchange_base_of_notMem_closure (hB : M.IsBase B) (he : e ∈ B)
(hf : f ∉ M.closure (B \ {e})) (hfE : f ∈ M.E := by aesop_mat) :
M.IsBase (insert f (B \ {e})) := by
obtain rfl | hne := eq_or_ne f e
· simpa [he]
have ⟨hi, hfB⟩ : M.Indep (insert f (B \ {e})) ∧ f ∉ B := by
simpa [(hB.indep.diff _).notMem_closure_iff, hne] using hf
exact hB.exchange_isBase_of_indep hfB hi
@[deprecated (since := "2025-05-23")]
alias IsBase.exchange_base_of_not_mem_closure := IsBase.exchange_base_of_notMem_closure
lemma Indep.isBase_iff_ground_subset_closure (hI : M.Indep I) : M.IsBase I ↔ M.E ⊆ M.closure I :=
⟨fun h ↦ h.closure_eq.symm.subset, hI.isBase_of_ground_subset_closure⟩
lemma Indep.closure_inter_eq_self_of_subset (hI : M.Indep I) (hJI : J ⊆ I) :
M.closure J ∩ I = J := by
have hJ := hI.subset hJI
rw [subset_antisymm_iff, and_iff_left (subset_inter (M.subset_closure _) hJI)]
rintro e ⟨heJ, heI⟩
exact hJ.isBasis_closure.mem_of_insert_indep heJ (hI.subset (insert_subset heI hJI))
/-- For a nonempty collection of subsets of a given independent set,
the closure of the intersection is the intersection of the closure. -/
lemma Indep.closure_sInter_eq_biInter_closure_of_forall_subset {Js : Set (Set α)} (hI : M.Indep I)
(hne : Js.Nonempty) (hIs : ∀ J ∈ Js, J ⊆ I) : M.closure (⋂₀ Js) = (⋂ J ∈ Js, M.closure J) := by
rw [subset_antisymm_iff, subset_iInter₂_iff]
have hiX : ⋂₀ Js ⊆ I := (sInter_subset_of_mem hne.some_mem).trans (hIs _ hne.some_mem)
have hiI := hI.subset hiX
refine ⟨ fun X hX ↦ M.closure_subset_closure (sInter_subset_of_mem hX),
fun e he ↦ by_contra fun he' ↦ ?_⟩
rw [mem_iInter₂] at he
have heEI : e ∈ M.E \ I := by
refine ⟨M.closure_subset_ground _ (he _ hne.some_mem), fun heI ↦ he' ?_⟩
refine mem_closure_of_mem _ (fun X hX' ↦ ?_) hiI.subset_ground
rw [← hI.closure_inter_eq_self_of_subset (hIs X hX')]
exact ⟨he X hX', heI⟩
rw [hiI.notMem_closure_iff_of_notMem (notMem_subset hiX heEI.2)] at he'
obtain ⟨J, hJI, heJ⟩ := he'.subset_isBasis_of_subset (insert_subset_insert hiX)
(insert_subset heEI.1 hI.subset_ground)
have hIb : M.IsBasis I (insert e I) := by
rw [hI.insert_isBasis_iff_mem_closure]
exact (M.closure_subset_closure (hIs _ hne.some_mem)) (he _ hne.some_mem)
obtain ⟨f, hfIJ, hfb⟩ := hJI.exchange hIb ⟨heJ (mem_insert e _), heEI.2⟩
obtain rfl := hI.eq_of_isBasis (hfb.isBasis_subset (insert_subset hfIJ.1
(by (rw [diff_subset_iff, singleton_union]; exact hJI.subset))) (subset_insert _ _))
refine hfIJ.2 (heJ (mem_insert_of_mem _ fun X hX' ↦ by_contra fun hfX ↦ ?_))
obtain (hd | heX) := ((hI.subset (hIs X hX')).mem_closure_iff).mp (he _ hX')
· refine (hJI.indep.subset (insert_subset (heJ (mem_insert _ _)) ?_)).not_dep hd
specialize hIs _ hX'
rw [← singleton_union, ← diff_subset_iff, diff_singleton_eq_self hfX] at hIs
exact hIs.trans diff_subset
exact heEI.2 (hIs _ hX' heX)
lemma closure_iInter_eq_iInter_closure_of_iUnion_indep [hι : Nonempty ι] (Is : ι → Set α)
(h : M.Indep (⋃ i, Is i)) : M.closure (⋂ i, Is i) = (⋂ i, M.closure (Is i)) := by
convert h.closure_sInter_eq_biInter_closure_of_forall_subset (range_nonempty Is)
(by simp [subset_iUnion])
simp
lemma closure_sInter_eq_biInter_closure_of_sUnion_indep (Is : Set (Set α)) (hIs : Is.Nonempty)
(h : M.Indep (⋃₀ Is)) : M.closure (⋂₀ Is) = (⋂ I ∈ Is, M.closure I) :=
h.closure_sInter_eq_biInter_closure_of_forall_subset hIs (fun _ ↦ subset_sUnion_of_mem)
lemma closure_biInter_eq_biInter_closure_of_biUnion_indep {ι : Type*} {A : Set ι} (hA : A.Nonempty)
{I : ι → Set α} (h : M.Indep (⋃ i ∈ A, I i)) :
M.closure (⋂ i ∈ A, I i) = ⋂ i ∈ A, M.closure (I i) := by
have := hA.coe_sort
convert closure_iInter_eq_iInter_closure_of_iUnion_indep (Is := fun i : A ↦ I i) (by simpa) <;>
simp
lemma Indep.closure_iInter_eq_biInter_closure_of_forall_subset [Nonempty ι] {Js : ι → Set α}
(hI : M.Indep I) (hJs : ∀ i, Js i ⊆ I) : M.closure (⋂ i, Js i) = ⋂ i, M.closure (Js i) :=
closure_iInter_eq_iInter_closure_of_iUnion_indep _ (hI.subset <| by simpa)
lemma Indep.closure_inter_eq_inter_closure (h : M.Indep (I ∪ J)) :
M.closure (I ∩ J) = M.closure I ∩ M.closure J := by
rw [inter_eq_iInter, closure_iInter_eq_iInter_closure_of_iUnion_indep, inter_eq_iInter]
· exact iInter_congr (by simp)
rwa [← union_eq_iUnion]
lemma Indep.inter_isBasis_biInter {ι : Type*} (hI : M.Indep I) {X : ι → Set α} {A : Set ι}
(hA : A.Nonempty) (h : ∀ i ∈ A, M.IsBasis ((X i) ∩ I) (X i)) :
M.IsBasis ((⋂ i ∈ A, X i) ∩ I) (⋂ i ∈ A, X i) := by
refine (hI.inter_left _).isBasis_of_subset_of_subset_closure inter_subset_left ?_
simp_rw [← biInter_inter hA,
closure_biInter_eq_biInter_closure_of_biUnion_indep hA (I := fun i ↦ (X i) ∩ I)
(hI.subset (by simp)), subset_iInter_iff]
exact fun i hiA ↦ (biInter_subset_of_mem hiA).trans (h i hiA).subset_closure
lemma Indep.inter_isBasis_iInter [Nonempty ι] {X : ι → Set α} (hI : M.Indep I)
(h : ∀ i, M.IsBasis ((X i) ∩ I) (X i)) : M.IsBasis ((⋂ i, X i) ∩ I) (⋂ i, X i) := by
convert hI.inter_isBasis_biInter (ι := PLift ι) univ_nonempty (X := fun i ↦ X i.down)
(by simpa using fun (i : PLift ι) ↦ h i.down) <;>
· simp only [mem_univ, iInter_true]
exact (iInter_plift_down X).symm
lemma Indep.inter_isBasis_sInter {Xs : Set (Set α)} (hI : M.Indep I) (hXs : Xs.Nonempty)
(h : ∀ X ∈ Xs, M.IsBasis (X ∩ I) X) : M.IsBasis (⋂₀ Xs ∩ I) (⋂₀ Xs) := by
rw [sInter_eq_biInter]
exact hI.inter_isBasis_biInter hXs h
lemma isBasis_iff_isBasis_closure_of_subset (hIX : I ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
M.IsBasis I X ↔ M.IsBasis I (M.closure X) :=
⟨fun h ↦ h.isBasis_closure_right, fun h ↦ h.isBasis_subset hIX (M.subset_closure X hX)⟩
lemma isBasis_iff_isBasis_closure_of_subset' (hIX : I ⊆ X) :
M.IsBasis I X ↔ M.IsBasis I (M.closure X) ∧ X ⊆ M.E :=
⟨fun h ↦ ⟨h.isBasis_closure_right, h.subset_ground⟩,
fun h ↦ h.1.isBasis_subset hIX (M.subset_closure X h.2)⟩
lemma isBasis'_iff_isBasis_closure : M.IsBasis' I X ↔ M.IsBasis I (M.closure X) ∧ I ⊆ X := by
rw [← closure_inter_ground, isBasis'_iff_isBasis_inter_ground]
exact ⟨fun h ↦ ⟨h.isBasis_closure_right, h.subset.trans inter_subset_left⟩,
fun h ↦ h.1.isBasis_subset (subset_inter h.2 h.1.indep.subset_ground) (M.subset_closure _)⟩
lemma exists_isBasis_inter_ground_isBasis_closure (M : Matroid α) (X : Set α) :
∃ I, M.IsBasis I (X ∩ M.E) ∧ M.IsBasis I (M.closure X) := by
obtain ⟨I, hI⟩ := M.exists_isBasis (X ∩ M.E)
have hI' := hI.isBasis_closure_right; rw [closure_inter_ground] at hI'
exact ⟨_, hI, hI'⟩
lemma IsBasis.isBasis_of_closure_eq_closure (hI : M.IsBasis I X) (hY : I ⊆ Y)
(h : M.closure X = M.closure Y) (hYE : Y ⊆ M.E := by aesop_mat) : M.IsBasis I Y := by
refine hI.indep.isBasis_of_subset_of_subset_closure hY ?_
rw [hI.closure_eq_closure, h]
exact M.subset_closure Y
lemma isBasis_union_iff_indep_closure : M.IsBasis I (I ∪ X) ↔ M.Indep I ∧ X ⊆ M.closure I :=
⟨fun h ↦ ⟨h.indep, subset_union_right.trans h.subset_closure⟩, fun ⟨hI, hXI⟩ ↦
hI.isBasis_closure.isBasis_subset subset_union_left (union_subset (M.subset_closure I) hXI)⟩
lemma isBasis_iff_indep_closure : M.IsBasis I X ↔ M.Indep I ∧ X ⊆ M.closure I ∧ I ⊆ X :=
⟨fun h ↦ ⟨h.indep, h.subset_closure, h.subset⟩, fun h ↦
(isBasis_union_iff_indep_closure.mpr ⟨h.1, h.2.1⟩).isBasis_subset h.2.2 subset_union_right⟩
lemma Indep.inter_isBasis_closure_iff_subset_closure_inter {X : Set α} (hI : M.Indep I) :
M.IsBasis (X ∩ I) X ↔ X ⊆ M.closure (X ∩ I) :=
⟨IsBasis.subset_closure, (hI.inter_left X).isBasis_of_subset_of_subset_closure inter_subset_left⟩
lemma IsBasis.closure_inter_isBasis_closure (h : M.IsBasis (X ∩ I) X) (hI : M.Indep I) :
M.IsBasis (M.closure X ∩ I) (M.closure X) := by
rw [hI.inter_isBasis_closure_iff_subset_closure_inter] at h ⊢
exact (M.closure_subset_closure_of_subset_closure h).trans (M.closure_subset_closure
(inter_subset_inter_left _ (h.trans (M.closure_subset_closure inter_subset_left))))
lemma IsBasis.eq_of_closure_subset (hI : M.IsBasis I X) (hJI : J ⊆ I) (hJ : X ⊆ M.closure J) :
J = I := by
rw [← hI.indep.closure_inter_eq_self_of_subset hJI, inter_eq_self_of_subset_right]
exact hI.subset.trans hJ
lemma IsBasis.insert_isBasis_insert_of_notMem_closure (hIX : M.IsBasis I X) (heI : e ∉ M.closure I)
(heE : e ∈ M.E := by aesop_mat) : M.IsBasis (insert e I) (insert e X) :=
hIX.insert_isBasis_insert <| hIX.indep.insert_indep_iff.2 <| .inl ⟨heE, heI⟩
@[deprecated (since := "2025-05-23")]
alias IsBasis.insert_isBasis_insert_of_not_mem_closure :=
IsBasis.insert_isBasis_insert_of_notMem_closure
@[simp] lemma empty_isBasis_iff : M.IsBasis ∅ X ↔ X ⊆ M.closure ∅ := by
rw [isBasis_iff_indep_closure, and_iff_right M.empty_indep, and_iff_left (empty_subset _)]
lemma indep_iff_forall_notMem_closure_diff (hI : I ⊆ M.E := by aesop_mat) :
M.Indep I ↔ ∀ ⦃e⦄, e ∈ I → e ∉ M.closure (I \ {e}) := by
use fun h e heI he ↦ ((h.closure_inter_eq_self_of_subset diff_subset).subset ⟨he, heI⟩).2 rfl
intro h
obtain ⟨J, hJ⟩ := M.exists_isBasis I
convert hJ.indep
refine hJ.subset.antisymm' (fun e he ↦ by_contra fun heJ ↦ h he ?_)
exact mem_of_mem_of_subset
(hJ.subset_closure he) (M.closure_subset_closure (subset_diff_singleton hJ.subset heJ))
@[deprecated (since := "2025-05-23")]
alias indep_iff_forall_not_mem_closure_diff := indep_iff_forall_notMem_closure_diff
/-- An alternative version of `Matroid.indep_iff_forall_notMem_closure_diff` where the
hypothesis that `I ⊆ M.E` is contained in the RHS rather than the hypothesis. -/
lemma indep_iff_forall_notMem_closure_diff' :
M.Indep I ↔ I ⊆ M.E ∧ ∀ e ∈ I, e ∉ M.closure (I \ {e}) :=
⟨fun h ↦ ⟨h.subset_ground, (indep_iff_forall_notMem_closure_diff h.subset_ground).mp h⟩, fun h ↦
(indep_iff_forall_notMem_closure_diff h.1).mpr h.2⟩
@[deprecated (since := "2025-05-23")]
alias indep_iff_forall_not_mem_closure_diff' := indep_iff_forall_notMem_closure_diff'
lemma Indep.notMem_closure_diff_of_mem (hI : M.Indep I) (he : e ∈ I) : e ∉ M.closure (I \ {e}) :=
(indep_iff_forall_notMem_closure_diff'.1 hI).2 e he
@[deprecated (since := "2025-05-23")]
alias Indep.not_mem_closure_diff_of_mem := Indep.notMem_closure_diff_of_mem
lemma indep_iff_forall_closure_diff_ne :
M.Indep I ↔ ∀ ⦃e⦄, e ∈ I → M.closure (I \ {e}) ≠ M.closure I := by
rw [indep_iff_forall_notMem_closure_diff']
refine ⟨fun ⟨hIE, h⟩ e heI h_eq ↦ h e heI (h_eq.symm.subset (M.mem_closure_of_mem heI)),
fun h ↦ ⟨fun e heI ↦ by_contra fun heE ↦ h heI ?_,fun e heI hin ↦ h heI ?_⟩⟩
· rw [← closure_inter_ground, inter_comm, inter_diff_distrib_left,
inter_singleton_eq_empty.mpr heE, diff_empty, inter_comm, closure_inter_ground]
nth_rw 2 [show I = insert e (I \ {e}) by simp [heI]]
rw [← closure_insert_closure_eq_closure_insert, insert_eq_of_mem hin, closure_closure]
lemma Indep.union_indep_iff_forall_notMem_closure_right (hI : M.Indep I) (hJ : M.Indep J) :
M.Indep (I ∪ J) ↔ ∀ e ∈ J \ I, e ∉ M.closure (I ∪ (J \ {e})) := by
refine ⟨fun h e heJ hecl ↦ h.notMem_closure_diff_of_mem (.inr heJ.1) ?_, fun h ↦ ?_⟩
· rwa [union_diff_distrib, diff_singleton_eq_self heJ.2]
obtain ⟨K, hKIJ, hK⟩ := hI.subset_isBasis_of_subset (show I ⊆ I ∪ J from subset_union_left)
obtain rfl | hssu := hKIJ.subset.eq_or_ssubset
· exact hKIJ.indep
exfalso
obtain ⟨e, heI, heK⟩ := exists_of_ssubset hssu
have heJI : e ∈ J \ I := by
rw [← union_diff_right, union_comm]
exact ⟨heI, notMem_subset hK heK⟩
refine h _ heJI ?_
rw [← diff_singleton_eq_self heJI.2, ← union_diff_distrib]
exact M.closure_subset_closure (subset_diff_singleton hKIJ.subset heK) <| hKIJ.subset_closure heI
@[deprecated (since := "2025-05-23")]
alias Indep.union_indep_iff_forall_not_mem_closure_right :=
Indep.union_indep_iff_forall_notMem_closure_right
lemma Indep.union_indep_iff_forall_notMem_closure_left (hI : M.Indep I) (hJ : M.Indep J) :
M.Indep (I ∪ J) ↔ ∀ e ∈ I \ J, e ∉ M.closure ((I \ {e}) ∪ J) := by
simp_rw [union_comm I J, hJ.union_indep_iff_forall_notMem_closure_right hI, union_comm]
@[deprecated (since := "2025-05-23")]
alias Indep.union_indep_iff_forall_not_mem_closure_left :=
Indep.union_indep_iff_forall_notMem_closure_left
lemma Indep.closure_ssubset_closure (hI : M.Indep I) (hJI : J ⊂ I) : M.closure J ⊂ M.closure I := by
obtain ⟨e, heI, heJ⟩ := exists_of_ssubset hJI
exact (M.closure_subset_closure hJI.subset).ssubset_of_not_subset fun hss ↦ heJ <|
(hI.closure_inter_eq_self_of_subset hJI.subset).subset ⟨hss (M.mem_closure_of_mem heI), heI⟩
lemma indep_iff_forall_closure_ssubset_of_ssubset (hI : I ⊆ M.E := by aesop_mat) :
M.Indep I ↔ ∀ ⦃J⦄, J ⊂ I → M.closure J ⊂ M.closure I := by
refine ⟨fun h _ ↦ h.closure_ssubset_closure,
fun h ↦ (indep_iff_forall_notMem_closure_diff hI).2 fun e heI hecl ↦ ?_⟩
refine (h (diff_singleton_ssubset.2 heI)).ne ?_
rw [show I = insert e (I \ {e}) by simp [heI], ← closure_insert_closure_eq_closure_insert,
insert_eq_of_mem hecl]
simp
lemma Indep.closure_diff_ssubset (hI : M.Indep I) (hX : (I ∩ X).Nonempty) :
M.closure (I \ X) ⊂ M.closure I := by
refine hI.closure_ssubset_closure <| diff_subset.ssubset_of_ne fun h ↦ ?_
rw [sdiff_eq_left, disjoint_iff_inter_eq_empty] at h
simp [h] at hX
lemma Indep.closure_diff_singleton_ssubset (hI : M.Indep I) (he : e ∈ I) :
M.closure (I \ {e}) ⊂ M.closure I :=
hI.closure_ssubset_closure <| by simpa
end Indep
section insert
lemma mem_closure_insert (he : e ∉ M.closure X) (hef : e ∈ M.closure (insert f X)) :
f ∈ M.closure (insert e X) := by
rw [← closure_inter_ground] at *
have hfE : f ∈ M.E := by
by_contra! hfE; rw [insert_inter_of_notMem hfE] at hef; exact he hef
have heE : e ∈ M.E := (M.closure_subset_ground _) hef
rw [insert_inter_of_mem hfE] at hef; rw [insert_inter_of_mem heE]
obtain ⟨I, hI⟩ := M.exists_isBasis (X ∩ M.E)
rw [← hI.closure_eq_closure, hI.indep.notMem_closure_iff] at he
rw [← closure_insert_closure_eq_closure_insert, ← hI.closure_eq_closure,
closure_insert_closure_eq_closure_insert, he.1.mem_closure_iff] at *
rw [or_iff_not_imp_left, dep_iff, insert_comm,
and_iff_left (insert_subset heE (insert_subset hfE hI.indep.subset_ground)), not_not]
intro h
rw [(h.subset (subset_insert _ _)).mem_closure_iff, or_iff_right (h.not_dep), mem_insert_iff,
or_iff_left he.2] at hef
subst hef; apply mem_insert
lemma closure_exchange (he : e ∈ M.closure (insert f X) \ M.closure X) :
f ∈ M.closure (insert e X) \ M.closure X :=
⟨mem_closure_insert he.2 he.1, fun hf ↦ by
rwa [closure_insert_eq_of_mem_closure hf, diff_self, iff_false_intro (notMem_empty _)] at he⟩
lemma closure_exchange_iff :
e ∈ M.closure (insert f X) \ M.closure X ↔ f ∈ M.closure (insert e X) \ M.closure X :=
⟨closure_exchange, closure_exchange⟩
lemma closure_insert_congr (he : e ∈ M.closure (insert f X) \ M.closure X) :
M.closure (insert e X) = M.closure (insert f X) := by
have hf := closure_exchange he
rw [eq_comm, ← closure_closure, ← insert_eq_of_mem he.1, closure_insert_closure_eq_closure_insert,
insert_comm, ← closure_closure, ← closure_insert_closure_eq_closure_insert,
insert_eq_of_mem hf.1, closure_closure, closure_closure]
lemma closure_diff_eq_self (h : Y ⊆ M.closure (X \ Y)) : M.closure (X \ Y) = M.closure X := by
rw [← diff_union_inter X Y, ← closure_union_closure_left_eq,
union_eq_self_of_subset_right (inter_subset_right.trans h), closure_closure, diff_union_inter]
lemma closure_diff_singleton_eq_closure (h : e ∈ M.closure (X \ {e})) :
M.closure (X \ {e}) = M.closure X :=
closure_diff_eq_self (by simpa)
lemma subset_closure_diff_iff_closure_eq (h : Y ⊆ X) (hY : Y ⊆ M.E := by aesop_mat) :
Y ⊆ M.closure (X \ Y) ↔ M.closure (X \ Y) = M.closure X :=
⟨closure_diff_eq_self, fun h' ↦ (M.subset_closure_of_subset' h).trans h'.symm.subset⟩
lemma mem_closure_diff_singleton_iff_closure (he : e ∈ X) (heE : e ∈ M.E := by aesop_mat) :
e ∈ M.closure (X \ {e}) ↔ M.closure (X \ {e}) = M.closure X := by
simpa using subset_closure_diff_iff_closure_eq (Y := {e}) (X := X) (by simpa)
end insert
lemma ext_closure {M₁ M₂ : Matroid α} (h : ∀ X, M₁.closure X = M₂.closure X) : M₁ = M₂ :=
ext_indep (by simpa using h univ)
(fun _ _ ↦ by simp_rw [indep_iff_forall_closure_diff_ne, h])
section Spanning
variable {S T I B : Set α}
/-- A set is `spanning` in `M` if its closure is equal to `M.E`, or equivalently if it contains
a base of `M`. -/
@[mk_iff]
structure Spanning (M : Matroid α) (S : Set α) : Prop where
closure_eq : M.closure S = M.E
subset_ground : S ⊆ M.E
attribute [aesop unsafe 10% (rule_sets := [Matroid])] Spanning.subset_ground
lemma spanning_iff_closure_eq (hS : S ⊆ M.E := by aesop_mat) :
M.Spanning S ↔ M.closure S = M.E := by
rw [spanning_iff, and_iff_left hS]
@[simp] lemma closure_spanning_iff (hS : S ⊆ M.E := by aesop_mat) :
M.Spanning (M.closure S) ↔ M.Spanning S := by
rw [spanning_iff_closure_eq, closure_closure, ← spanning_iff_closure_eq]
lemma spanning_iff_ground_subset_closure (hS : S ⊆ M.E := by aesop_mat) :
M.Spanning S ↔ M.E ⊆ M.closure S := by
rw [spanning_iff_closure_eq, subset_antisymm_iff, and_iff_right (closure_subset_ground _ _)]
lemma not_spanning_iff_closure_ssubset (hS : S ⊆ M.E := by aesop_mat) :
¬M.Spanning S ↔ M.closure S ⊂ M.E := by
rw [spanning_iff_closure_eq, ssubset_iff_subset_ne, iff_and_self,
iff_true_intro (M.closure_subset_ground _)]
exact fun _ ↦ trivial
lemma Spanning.superset (hS : M.Spanning S) (hST : S ⊆ T) (hT : T ⊆ M.E := by aesop_mat) :
M.Spanning T :=
⟨(M.closure_subset_ground _).antisymm
(by rw [← hS.closure_eq]; exact M.closure_subset_closure hST), hT⟩
lemma Spanning.closure_eq_of_superset (hS : M.Spanning S) (hST : S ⊆ T) : M.closure T = M.E := by
rw [← closure_inter_ground, ← spanning_iff_closure_eq]
exact hS.superset (subset_inter hST hS.subset_ground)
lemma Spanning.union_left (hS : M.Spanning S) (hX : X ⊆ M.E := by aesop_mat) : M.Spanning (S ∪ X) :=
hS.superset subset_union_left
lemma Spanning.union_right (hS : M.Spanning S) (hX : X ⊆ M.E := by aesop_mat) :
M.Spanning (X ∪ S) :=
hS.superset subset_union_right
lemma IsBase.spanning (hB : M.IsBase B) : M.Spanning B :=
⟨hB.closure_eq, hB.subset_ground⟩
lemma ground_spanning (M : Matroid α) : M.Spanning M.E :=
⟨M.closure_ground, rfl.subset⟩
lemma IsBase.spanning_of_superset (hB : M.IsBase B) (hBX : B ⊆ X) (hX : X ⊆ M.E := by aesop_mat) :
M.Spanning X :=
hB.spanning.superset hBX
/-- A version of `Matroid.spanning_iff_exists_isBase_subset` in which the `S ⊆ M.E` condition
appears in the RHS of the equivalence rather than as a hypothesis. -/
lemma spanning_iff_exists_isBase_subset' : M.Spanning S ↔ (∃ B, M.IsBase B ∧ B ⊆ S) ∧ S ⊆ M.E := by
refine ⟨fun h ↦ ⟨?_, h.subset_ground⟩, fun ⟨⟨B, hB, hBS⟩, hSE⟩ ↦ hB.spanning.superset hBS⟩
obtain ⟨B, hB⟩ := M.exists_isBasis S
have hB' := hB.isBasis_closure_right
rw [h.closure_eq, isBasis_ground_iff] at hB'
exact ⟨B, hB', hB.subset⟩
lemma spanning_iff_exists_isBase_subset (hS : S ⊆ M.E := by aesop_mat) :
M.Spanning S ↔ ∃ B, M.IsBase B ∧ B ⊆ S := by
rw [spanning_iff_exists_isBase_subset', and_iff_left hS]
lemma Spanning.exists_isBase_subset (hS : M.Spanning S) : ∃ B, M.IsBase B ∧ B ⊆ S := by
rwa [spanning_iff_exists_isBase_subset] at hS
lemma coindep_iff_compl_spanning (hI : I ⊆ M.E := by aesop_mat) :
M.Coindep I ↔ M.Spanning (M.E \ I) := by
rw [coindep_iff_exists, spanning_iff_exists_isBase_subset]
lemma spanning_iff_compl_coindep (hS : S ⊆ M.E := by aesop_mat) :
M.Spanning S ↔ M.Coindep (M.E \ S) := by
rw [coindep_iff_compl_spanning, diff_diff_cancel_left hS]
lemma Coindep.compl_spanning (hI : M.Coindep I) : M.Spanning (M.E \ I) :=
(coindep_iff_compl_spanning hI.subset_ground).mp hI
lemma coindep_iff_closure_compl_eq_ground (hK : X ⊆ M.E := by aesop_mat) :
M.Coindep X ↔ M.closure (M.E \ X) = M.E := by
rw [coindep_iff_compl_spanning, spanning_iff_closure_eq]
lemma Coindep.closure_compl (hX : M.Coindep X) : M.closure (M.E \ X) = M.E :=
(coindep_iff_closure_compl_eq_ground hX.subset_ground).mp hX
lemma Indep.isBase_of_spanning (hI : M.Indep I) (hIs : M.Spanning I) : M.IsBase I := by
obtain ⟨B, hB, hBI⟩ := hIs.exists_isBase_subset; rwa [← hB.eq_of_subset_indep hI hBI]
lemma Spanning.isBase_of_indep (hIs : M.Spanning I) (hI : M.Indep I) : M.IsBase I :=
hI.isBase_of_spanning hIs
lemma Indep.eq_of_spanning_subset (hI : M.Indep I) (hS : M.Spanning S) (hSI : S ⊆ I) : S = I :=
((hI.subset hSI).isBase_of_spanning hS).eq_of_subset_indep hI hSI
lemma IsBasis.spanning_iff_spanning (hIX : M.IsBasis I X) : M.Spanning I ↔ M.Spanning X := by
rw [spanning_iff_closure_eq, spanning_iff_closure_eq, hIX.closure_eq_closure]
lemma Spanning.isBase_restrict_iff (hS : M.Spanning S) : (M ↾ S).IsBase B ↔ M.IsBase B ∧ B ⊆ S := by
rw [isBase_restrict_iff', isBasis'_iff_isBasis]
refine ⟨fun h ↦ ⟨?_, h.subset⟩, fun h ↦ h.1.indep.isBasis_of_subset_of_subset_closure h.2 ?_⟩
· exact h.indep.isBase_of_spanning <| by rwa [h.spanning_iff_spanning]
rw [h.1.closure_eq]
exact hS.subset_ground
lemma Spanning.compl_coindep (hS : M.Spanning S) : M.Coindep (M.E \ S) := by
rwa [← spanning_iff_compl_coindep]
lemma IsBasis.isBase_of_spanning (hIX : M.IsBasis I X) (hX : M.Spanning X) : M.IsBase I :=
hIX.indep.isBase_of_spanning <| by rwa [hIX.spanning_iff_spanning]
lemma Indep.exists_isBase_subset_spanning (hI : M.Indep I) (hS : M.Spanning S) (hIS : I ⊆ S) :
∃ B, M.IsBase B ∧ I ⊆ B ∧ B ⊆ S := by
obtain ⟨B, hB⟩ := hI.subset_isBasis_of_subset hIS
exact ⟨B, hB.1.isBase_of_spanning hS, hB.2, hB.1.subset⟩
lemma Restriction.isBase_iff_of_spanning {N : Matroid α} (hR : N ≤r M) (hN : M.Spanning N.E) :
N.IsBase B ↔ (M.IsBase B ∧ B ⊆ N.E) := by
obtain ⟨R, hR : R ⊆ M.E, rfl⟩ := hR
rw [Spanning.isBase_restrict_iff (show M.Spanning R from hN), restrict_ground_eq]
lemma ext_spanning {M M' : Matroid α} (h : M.E = M'.E)
(hsp : ∀ S, S ⊆ M.E → (M.Spanning S ↔ M'.Spanning S)) : M = M' := by
have hsp' : M.Spanning = M'.Spanning := by
ext S
refine (em (S ⊆ M.E)).elim (fun hSE ↦ by rw [hsp _ hSE] )
(fun hSE ↦ iff_of_false (fun h ↦ hSE h.subset_ground)
(fun h' ↦ hSE (h'.subset_ground.trans h.symm.subset)))
rw [← dual_inj, ext_iff_indep, dual_ground, dual_ground, and_iff_right h]
intro I hIE
rw [← coindep_def, ← coindep_def, coindep_iff_compl_spanning, coindep_iff_compl_spanning, hsp', h]
lemma IsBase.eq_of_superset_spanning (hB : M.IsBase B) (hX : M.Spanning X) (hXB : X ⊆ B) : B = X :=
have ⟨B', hB', hB'X⟩ := hX.exists_isBase_subset
subset_antisymm (by rwa [← hB'.eq_of_subset_isBase hB (hB'X.trans hXB)]) hXB
theorem isBase_iff_minimal_spanning : M.IsBase B ↔ Minimal M.Spanning B := by
rw [minimal_subset_iff]
refine ⟨fun h ↦ ⟨h.spanning, fun _ ↦ h.eq_of_superset_spanning⟩, fun ⟨h, h'⟩ ↦ ?_⟩
obtain ⟨B', hB', hBB'⟩ := h.exists_isBase_subset
rwa [h' hB'.spanning hBB']
theorem Spanning.isBase_of_minimal (hX : M.Spanning X) (h : ∀ ⦃Y⦄, M.Spanning Y → Y ⊆ X → X = Y) :
M.IsBase X := by
rwa [isBase_iff_minimal_spanning, minimal_subset_iff, and_iff_right hX]
end Spanning
section Constructions
variable {R S : Set α}
@[simp] lemma restrict_closure_eq' (M : Matroid α) (X R : Set α) :
(M ↾ R).closure X = (M.closure (X ∩ R) ∩ R) ∪ (R \ M.E) := by
obtain ⟨I, hI⟩ := (M ↾ R).exists_isBasis' X
obtain ⟨hI', hIR⟩ := isBasis'_restrict_iff.1 hI
ext e
rw [← hI.closure_eq_closure, ← hI'.closure_eq_closure, hI.indep.mem_closure_iff', mem_union,
mem_inter_iff, hI'.indep.mem_closure_iff', restrict_ground_eq, restrict_indep_iff, mem_diff]
by_cases he : M.Indep (insert e I)
· simp [he, and_comm, insert_subset_iff, hIR, (he.subset_ground (mem_insert ..)), imp_or]
tauto
lemma restrict_closure_eq (M : Matroid α) (hXR : X ⊆ R) (hR : R ⊆ M.E := by aesop_mat) :
(M ↾ R).closure X = M.closure X ∩ R := by
rw [restrict_closure_eq', diff_eq_empty.mpr hR, union_empty, inter_eq_self_of_subset_left hXR]
@[simp] lemma emptyOn_closure_eq (X : Set α) : (emptyOn α).closure X = ∅ :=
(closure_subset_ground ..).antisymm <| empty_subset _
@[simp] lemma loopyOn_closure_eq (E X : Set α) : (loopyOn E).closure X = E := by
simp [loopyOn, restrict_closure_eq']
@[simp] lemma loopyOn_spanning_iff {E : Set α} : (loopyOn E).Spanning X ↔ X ⊆ E := by
rw [spanning_iff, loopyOn_closure_eq, loopyOn_ground, and_iff_right rfl]
@[simp] lemma freeOn_closure_eq (E X : Set α) : (freeOn E).closure X = X ∩ E := by
simp +contextual [← closure_inter_ground _ X, Set.ext_iff, and_comm,
insert_subset_iff, freeOn_indep_iff, (freeOn_indep inter_subset_right).mem_closure_iff']
@[simp] lemma uniqueBaseOn_closure_eq (I E X : Set α) :
(uniqueBaseOn I E).closure X = (X ∩ I ∩ E) ∪ (E \ I) := by
rw [uniqueBaseOn, restrict_closure_eq', freeOn_closure_eq, inter_right_comm,
inter_assoc (c := E), inter_self, inter_right_comm, freeOn_ground]
lemma closure_empty_eq_ground_iff : M.closure ∅ = M.E ↔ M = loopyOn M.E := by
refine ⟨fun h ↦ ext_closure ?_, fun h ↦ by rw [h, loopyOn_closure_eq, loopyOn_ground]⟩
refine fun X ↦ subset_antisymm (by simp [closure_subset_ground]) ?_
rw [loopyOn_closure_eq, ← h]
exact M.closure_mono (empty_subset _)
@[simp] lemma comap_closure_eq {β : Type*} (M : Matroid β) (f : α → β) (X : Set α) :
(M.comap f).closure X = f ⁻¹' M.closure (f '' X) := by
-- Use a choice of basis and extensionality to change the goal to a statement about independence.
obtain ⟨I, hI⟩ := (M.comap f).exists_isBasis' X
obtain ⟨hI', hIinj, -⟩ := comap_isBasis'_iff.1 hI
simp_rw [← hI.closure_eq_closure, ← hI'.closure_eq_closure, Set.ext_iff,
hI.indep.mem_closure_iff', comap_ground_eq, mem_preimage, hI'.indep.mem_closure_iff',
comap_indep_iff, and_imp, mem_image, and_congr_right_iff, ← image_insert_eq]
-- the lemma now easily follows by considering elements/non-elements of `I` separately.
intro x hxE
by_cases hxI : x ∈ I
· simp [hxI, show ∃ y ∈ I, f y = f x from ⟨x, hxI, rfl⟩]
simp [hxI, injOn_insert hxI, hIinj]
@[simp] lemma map_closure_eq {β : Type*} (M : Matroid α) (f : α → β) (hf) (X : Set β) :
(M.map f hf).closure X = f '' M.closure (f ⁻¹' X) := by
-- It is enough to prove that `map` and `closure` commute for `M`-independent sets.
suffices aux : ∀ ⦃I⦄, M.Indep I → (M.map f hf).closure (f '' I) = f '' (M.closure I) by
obtain ⟨I, hI⟩ := M.exists_isBasis (f ⁻¹' X ∩ M.E)
rw [← closure_inter_ground, map_ground, ← M.closure_inter_ground, ← hI.closure_eq_closure,
← aux hI.indep, ← image_preimage_inter, ← (hI.map hf).closure_eq_closure]
-- Let `I` be independent, and transform the goal using closure/independence lemmas
refine fun I hI ↦ Set.ext fun e ↦ ?_
simp only [(hI.map f hf).mem_closure_iff', map_ground, mem_image, map_indep_iff,
forall_exists_index, and_imp, hI.mem_closure_iff']
-- The goal now easily follows from the invariance of independence under maps.
constructor
· rintro ⟨⟨x, hxE, rfl⟩, h2⟩
refine ⟨x, ⟨hxE, fun hI' ↦ ?_⟩, rfl⟩
obtain ⟨y, hyI, hfy⟩ := h2 _ hI' image_insert_eq.symm
rw [hf.eq_iff (hI.subset_ground hyI) hxE] at hfy
rwa [← hfy]
rintro ⟨x, ⟨hxE, hxi⟩, rfl⟩
refine ⟨⟨x, hxE, rfl⟩, fun J hJ hJI ↦ ⟨x, hxi ?_, rfl⟩⟩
replace hJ := hJ.map f hf
have hrw := image_insert_eq ▸ hJI
rwa [← hrw, map_image_indep_iff (insert_subset hxE hI.subset_ground)] at hJ
lemma restrict_spanning_iff (hSR : S ⊆ R) (hR : R ⊆ M.E := by aesop_mat) :
(M ↾ R).Spanning S ↔ R ⊆ M.closure S := by
rw [spanning_iff, restrict_ground_eq, and_iff_left hSR, restrict_closure_eq _ hSR, inter_eq_right]
lemma restrict_spanning_iff' : (M ↾ R).Spanning S ↔ R ∩ M.E ⊆ M.closure S ∧ S ⊆ R := by
rw [spanning_iff, restrict_closure_eq', restrict_ground_eq, and_congr_left_iff,
diff_eq_compl_inter, ← union_inter_distrib_right, inter_eq_right, union_comm,
← diff_subset_iff, diff_compl]
intro hSR
rw [inter_eq_self_of_subset_left hSR]
end Constructions
end Matroid
|
Constructions.lean
|
/-
Copyright (c) 2024 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Analysis.CStarAlgebra.Module.Defs
import Mathlib.Analysis.CStarAlgebra.Module.Synonym
import Mathlib.Topology.MetricSpace.Bilipschitz
/-! # Constructions of Hilbert C⋆-modules
In this file we define the following constructions of `CStarModule`s where `A` denotes a C⋆-algebra.
For some of the types listed below, the instance is declared on the type synonym `WithCStarModule E`
(with the notation `C⋆ᵐᵒᵈ E`), instead of on `E` itself; we explain the reasoning behind each
decision below.
1. `A` as a `CStarModule` over itself.
2. `C⋆ᵐᵒᵈ(A, E × F)` as a `CStarModule` over `A`, when `E` and `F` are themselves `CStarModule`s
over `A`.
3. `C⋆ᵐᵒᵈ (A, Π i : ι, E i)` as a `CStarModule` over `A`, when each `E i` is a `CStarModule` over
`A` and `ι` is a `Fintype`.
4. `E` as a `CStarModule` over `ℂ`, when `E` is an `InnerProductSpace` over `ℂ`.
For `E × F` and `Π i : ι, E i`, we are required to declare the instance on a type synonym rather
than on the product or pi-type itself because the existing norm on these types does not agree with
the one induced by the C⋆-module structure. Moreover, the norm induced by the C⋆-module structure
doesn't agree with any other natural norm on these types (e.g., `WithLp 2 (E × F)` unless `A := ℂ`),
so we need a new synonym.
On `A` (a C⋆-algebra) and `E` (an inner product space), we declare the instances on the types
themselves to ease the use of the C⋆-module structure. This does have the potential to cause
inconvenience (as sometimes Lean will see terms of type `A` and apply lemmas pertaining to
C⋆-modules to those terms, when the lemmas were actually intended for terms of some other
C⋆-module in context, say `F`, in which case the arguments must be provided explicitly; see for
instance the application of `CStarModule.norm_eq_sqrt_norm_inner_self` in the proof of
`WithCStarModule.max_le_prod_norm` below). However, we believe that this, hopefully rare,
inconvenience is outweighed by avoiding translating between type synonyms where possible.
For more details on the importance of the `WithCStarModule` type synonym, see the module
documentation for `Analysis.CStarAlgebra.Module.Synonym`.
## Implementation notes
When `A := ℂ` and `E := ℂ`, then `ℂ` is both a C⋆-algebra (so it inherits a `CStarModule` instance
via (1) above) and an inner product space (so it inherits a `CStarModule` instance via (4) above).
We provide a sanity check ensuring that these two instances are definitionally equal. We also ensure
that the `Inner ℂ ℂ` instance from `InnerProductSpace` is definitionally equal to the one inherited
from the `CStarModule` instances.
Note that `C⋆ᵐᵒᵈ(A, E)` is *already* equipped with a bornology and uniformity whenever `E` is
(namely, the pullback of the respective structures through `WithCStarModule.equiv`), so in each of
the above cases, it is necessary to temporarily instantiate `C⋆ᵐᵒᵈ(A, E)` with
`CStarModule.normedAddCommGroup`, show the resulting type is bilipschitz equivalent to `E` via
`WithCStarModule.equiv` (in the first and last case, this map is actually trivially an isometry),
and then replace the uniformity and bornology with the correct ones.
-/
open CStarModule CStarRing
namespace WithCStarModule
variable {A : Type*} [NonUnitalCStarAlgebra A] [PartialOrder A]
/-! ## A C⋆-algebra as a C⋆-module over itself -/
section Self
variable [StarOrderedRing A]
/-- Reinterpret a C⋆-algebra `A` as a `CStarModule` over itself. -/
instance : CStarModule A A where
inner x y := y * star x
inner_add_right := add_mul ..
inner_self_nonneg := mul_star_self_nonneg _
inner_self := CStarRing.mul_star_self_eq_zero_iff _
inner_op_smul_right := mul_assoc ..
inner_smul_right_complex := smul_mul_assoc ..
star_inner x y := by simp
norm_eq_sqrt_norm_inner_self {x} := by
rw [← sq_eq_sq₀ (norm_nonneg _) (by positivity)]
simpa [sq] using Eq.symm <| CStarRing.norm_self_mul_star
open scoped InnerProductSpace in
lemma inner_def (x y : A) : ⟪x, y⟫_A = y * star x := rfl
end Self
/-! ## Products of C⋆-modules -/
section Prod
open scoped InnerProductSpace
variable {E F : Type*}
variable [NormedAddCommGroup E] [Module ℂ E] [SMul A E]
variable [NormedAddCommGroup F] [Module ℂ F] [SMul A F]
variable [CStarModule A E] [CStarModule A F]
noncomputable instance : Norm C⋆ᵐᵒᵈ(A, E × F) where
norm x := √‖⟪x.1, x.1⟫_A + ⟪x.2, x.2⟫_A‖
lemma prod_norm (x : C⋆ᵐᵒᵈ(A, E × F)) : ‖x‖ = √‖⟪x.1, x.1⟫_A + ⟪x.2, x.2⟫_A‖ := rfl
lemma prod_norm_sq (x : C⋆ᵐᵒᵈ(A, E × F)) : ‖x‖ ^ 2 = ‖⟪x.1, x.1⟫_A + ⟪x.2, x.2⟫_A‖ := by
simp [prod_norm]
lemma prod_norm_le_norm_add (x : C⋆ᵐᵒᵈ(A, E × F)) : ‖x‖ ≤ ‖x.1‖ + ‖x.2‖ := by
refine abs_le_of_sq_le_sq' ?_ (by positivity) |>.2
calc ‖x‖ ^ 2 ≤ ‖⟪x.1, x.1⟫_A‖ + ‖⟪x.2, x.2⟫_A‖ := prod_norm_sq x ▸ norm_add_le _ _
_ = ‖x.1‖ ^ 2 + 0 + ‖x.2‖ ^ 2 := by simp [norm_sq_eq A]
_ ≤ ‖x.1‖ ^ 2 + 2 * ‖x.1‖ * ‖x.2‖ + ‖x.2‖ ^ 2 := by gcongr; positivity
_ = (‖x.1‖ + ‖x.2‖) ^ 2 := by ring
variable [StarOrderedRing A]
noncomputable instance : CStarModule A C⋆ᵐᵒᵈ(A, E × F) where
inner x y := ⟪x.1, y.1⟫_A + ⟪x.2, y.2⟫_A
inner_add_right {x y z} := by simpa using add_add_add_comm ..
inner_self_nonneg := add_nonneg CStarModule.inner_self_nonneg CStarModule.inner_self_nonneg
inner_self {x} := by
refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩
apply equiv A (E × F) |>.injective
ext
· refine inner_self.mp <| le_antisymm ?_ (inner_self_nonneg (A := A))
exact le_add_of_nonneg_right CStarModule.inner_self_nonneg |>.trans_eq h
· refine inner_self.mp <| le_antisymm ?_ (inner_self_nonneg (A := A))
exact le_add_of_nonneg_left CStarModule.inner_self_nonneg |>.trans_eq h
inner_op_smul_right := by simp [mul_add]
inner_smul_right_complex := by simp [smul_add]
star_inner x y := by simp
norm_eq_sqrt_norm_inner_self {x} := by with_reducible_and_instances rfl
lemma prod_inner (x y : C⋆ᵐᵒᵈ(A, E × F)) : ⟪x, y⟫_A = ⟪x.1, y.1⟫_A + ⟪x.2, y.2⟫_A := rfl
lemma max_le_prod_norm (x : C⋆ᵐᵒᵈ(A, E × F)) : max ‖x.1‖ ‖x.2‖ ≤ ‖x‖ := by
rw [prod_norm]
simp only [norm_eq_sqrt_norm_inner_self (A := A) (E := E),
norm_eq_sqrt_norm_inner_self (A := A) (E := F), max_le_iff, norm_nonneg,
Real.sqrt_le_sqrt_iff]
constructor
all_goals
refine CStarAlgebra.norm_le_norm_of_nonneg_of_le (A := A) ?_ ?_
all_goals
aesop (add safe apply CStarModule.inner_self_nonneg)
lemma norm_equiv_le_norm_prod (x : C⋆ᵐᵒᵈ(A, E × F)) : ‖equiv A (E × F) x‖ ≤ ‖x‖ :=
max_le_prod_norm x
section Aux
-- We temporarily disable the uniform space and bornology on `C⋆ᵐᵒᵈ A` while proving
-- that those induced by the new norm are equal to the old ones.
attribute [-instance] WithCStarModule.instUniformSpace WithCStarModule.instBornology
/-- A normed additive commutative group structure on `C⋆ᵐᵒᵈ(A, E × F)` with the wrong topology,
uniformity and bornology. This is only used to build the instance with the correct forgetful
inheritance data. -/
noncomputable def normedAddCommGroupProdAux : NormedAddCommGroup C⋆ᵐᵒᵈ(A, E × F) :=
NormedAddCommGroup.ofCore (CStarModule.normedSpaceCore A)
attribute [local instance] normedAddCommGroupProdAux
open Filter Uniformity Bornology
private lemma antilipschitzWith_two_equiv_prod_aux : AntilipschitzWith 2 (equiv A (E × F)) :=
AddMonoidHomClass.antilipschitz_of_bound (linearEquiv ℂ A (E × F)) fun x ↦ by
apply prod_norm_le_norm_add x |>.trans
simp only [NNReal.coe_ofNat, linearEquiv_apply, two_mul]
gcongr
· exact norm_fst_le x
· exact norm_snd_le x
private lemma lipschitzWith_one_equiv_prod_aux : LipschitzWith 1 (equiv A (E × F)) :=
AddMonoidHomClass.lipschitz_of_bound_nnnorm (linearEquiv ℂ A (E × F)) 1 <| by
simpa using norm_equiv_le_norm_prod
private lemma uniformity_prod_eq_aux :
𝓤[(inferInstance : UniformSpace (E × F)).comap <| equiv _ _] = 𝓤 C⋆ᵐᵒᵈ(A, E × F) :=
uniformity_eq_of_bilipschitz antilipschitzWith_two_equiv_prod_aux lipschitzWith_one_equiv_prod_aux
private lemma isBounded_prod_iff_aux (s : Set C⋆ᵐᵒᵈ(A, E × F)) :
@IsBounded _ (induced <| equiv A (E × F)) s ↔ IsBounded s :=
isBounded_iff_of_bilipschitz antilipschitzWith_two_equiv_prod_aux
lipschitzWith_one_equiv_prod_aux s
end Aux
noncomputable instance : NormedAddCommGroup C⋆ᵐᵒᵈ(A, E × F) :=
.ofCoreReplaceAll (normedSpaceCore A) uniformity_prod_eq_aux isBounded_prod_iff_aux
noncomputable instance : NormedSpace ℂ C⋆ᵐᵒᵈ(A, E × F) := .ofCore (normedSpaceCore A)
end Prod
/-! ## Pi-types of C⋆-modules -/
section Pi
open scoped InnerProductSpace
variable {ι : Type*} {E : ι → Type*} [Fintype ι]
variable [∀ i, NormedAddCommGroup (E i)] [∀ i, Module ℂ (E i)] [∀ i, SMul A (E i)]
variable [∀ i, CStarModule A (E i)]
noncomputable instance : Norm C⋆ᵐᵒᵈ(A, Π i, E i) where
norm x := √‖∑ i, ⟪x i, x i⟫_A‖
lemma pi_norm (x : C⋆ᵐᵒᵈ(A, Π i, E i)) : ‖x‖ = √‖∑ i, ⟪x i, x i⟫_A‖ := by
with_reducible_and_instances rfl
lemma pi_norm_sq (x : C⋆ᵐᵒᵈ(A, Π i, E i)) : ‖x‖ ^ 2 = ‖∑ i, ⟪x i, x i⟫_A‖ := by
simp [pi_norm]
open Finset in
lemma pi_norm_le_sum_norm (x : C⋆ᵐᵒᵈ(A, Π i, E i)) : ‖x‖ ≤ ∑ i, ‖x i‖ := by
refine abs_le_of_sq_le_sq' ?_ (by positivity) |>.2
calc ‖x‖ ^ 2 ≤ ∑ i, ‖⟪x i, x i⟫_A‖ := pi_norm_sq x ▸ norm_sum_le _ _
_ = ∑ i, ‖x i‖ ^ 2 := by simp only [norm_sq_eq A]
_ ≤ (∑ i, ‖x i‖) ^ 2 := sum_sq_le_sq_sum_of_nonneg (fun _ _ ↦ norm_nonneg _)
variable [StarOrderedRing A]
open Finset in
noncomputable instance : CStarModule A C⋆ᵐᵒᵈ(A, Π i, E i) where
inner x y := ∑ i, ⟪x i, y i⟫_A
inner_add_right {x y z} := by simp [sum_add_distrib]
inner_self_nonneg := sum_nonneg <| fun _ _ ↦ CStarModule.inner_self_nonneg
inner_self {x} := by
refine ⟨fun h ↦ ?_, fun h ↦ by simp [h]⟩
ext i
refine inner_self.mp <| le_antisymm (le_of_le_of_eq ?_ h) inner_self_nonneg
exact single_le_sum (fun i _ ↦ CStarModule.inner_self_nonneg (A := A) (x := x i)) (mem_univ _)
inner_op_smul_right := by simp [mul_sum]
inner_smul_right_complex := by simp [smul_sum]
star_inner x y := by simp
norm_eq_sqrt_norm_inner_self {x} := by with_reducible_and_instances rfl
lemma pi_inner (x y : C⋆ᵐᵒᵈ(A, Π i, E i)) : ⟪x, y⟫_A = ∑ i, ⟪x i, y i⟫_A := rfl
@[simp]
lemma inner_single_left [DecidableEq ι] (x : C⋆ᵐᵒᵈ(A, Π i, E i)) {i : ι} (y : E i) :
⟪equiv _ _ |>.symm <| Pi.single i y, x⟫_A = ⟪y, x i⟫_A := by
simp only [pi_inner, equiv_symm_pi_apply]
rw [Finset.sum_eq_single i]
all_goals simp_all
@[simp]
lemma inner_single_right [DecidableEq ι] (x : C⋆ᵐᵒᵈ(A, Π i, E i)) {i : ι} (y : E i) :
⟪x, equiv _ _ |>.symm <| Pi.single i y⟫_A = ⟪x i, y⟫_A := by
simp only [pi_inner, equiv_symm_pi_apply]
rw [Finset.sum_eq_single i]
all_goals simp_all
@[simp]
lemma norm_single [DecidableEq ι] (i : ι) (y : E i) :
‖equiv A _ |>.symm <| Pi.single i y‖ = ‖y‖ := by
let _ : NormedAddCommGroup C⋆ᵐᵒᵈ(A, Π i, E i) := normedAddCommGroup A
rw [← sq_eq_sq₀ (by positivity) (by positivity)]
simp [norm_sq_eq A]
lemma norm_apply_le_norm (x : C⋆ᵐᵒᵈ(A, Π i, E i)) (i : ι) : ‖x i‖ ≤ ‖x‖ := by
let _ : NormedAddCommGroup C⋆ᵐᵒᵈ(A, Π i, E i) := normedAddCommGroup A
refine abs_le_of_sq_le_sq' ?_ (by positivity) |>.2
rw [pi_norm_sq, norm_sq_eq A]
refine CStarAlgebra.norm_le_norm_of_nonneg_of_le inner_self_nonneg ?_
exact Finset.single_le_sum (fun j _ ↦ inner_self_nonneg (A := A) (x := x j)) (Finset.mem_univ i)
open Finset in
lemma norm_equiv_le_norm_pi (x : C⋆ᵐᵒᵈ(A, Π i, E i)) : ‖equiv _ _ x‖ ≤ ‖x‖ := by
let _ : NormedAddCommGroup C⋆ᵐᵒᵈ(A, Π i, E i) := normedAddCommGroup A
rw [pi_norm_le_iff_of_nonneg (by positivity)]
simpa using norm_apply_le_norm x
section Aux
-- We temporarily disable the uniform space and bornology on `C⋆ᵐᵒᵈ A` while proving
-- that those induced by the new norm are equal to the old ones.
attribute [-instance] WithCStarModule.instUniformSpace WithCStarModule.instBornology
/-- A normed additive commutative group structure on `C⋆ᵐᵒᵈ(A, Π i, E i)` with the wrong topology,
uniformity and bornology. This is only used to build the instance with the correct forgetful
inheritance data. -/
noncomputable def normedAddCommGroupPiAux : NormedAddCommGroup C⋆ᵐᵒᵈ(A, Π i, E i) :=
NormedAddCommGroup.ofCore (CStarModule.normedSpaceCore A)
attribute [local instance] normedAddCommGroupPiAux
open Uniformity Bornology
private lemma antilipschitzWith_card_equiv_pi_aux :
AntilipschitzWith (Fintype.card ι) (equiv A (Π i, E i)) :=
AddMonoidHomClass.antilipschitz_of_bound (linearEquiv ℂ A (Π i, E i)) fun x ↦ by
simp only [NNReal.coe_natCast, linearEquiv_apply]
calc ‖x‖ ≤ ∑ i, ‖x i‖ := pi_norm_le_sum_norm x
_ ≤ ∑ _, ‖⇑x‖ := Finset.sum_le_sum fun _ _ ↦ norm_le_pi_norm ..
_ ≤ Fintype.card ι * ‖⇑x‖ := by simp
private lemma lipschitzWith_one_equiv_pi_aux : LipschitzWith 1 (equiv A (Π i, E i)) :=
AddMonoidHomClass.lipschitz_of_bound_nnnorm (linearEquiv ℂ A (Π i, E i)) 1 <| by
simpa using norm_equiv_le_norm_pi
private lemma uniformity_pi_eq_aux :
𝓤[(inferInstance : UniformSpace (Π i, E i)).comap <| equiv A _] = 𝓤 C⋆ᵐᵒᵈ(A, Π i, E i) :=
uniformity_eq_of_bilipschitz antilipschitzWith_card_equiv_pi_aux lipschitzWith_one_equiv_pi_aux
private lemma isBounded_pi_iff_aux (s : Set C⋆ᵐᵒᵈ(A, Π i, E i)) :
@IsBounded _ (induced <| equiv A (Π i, E i)) s ↔ IsBounded s :=
isBounded_iff_of_bilipschitz antilipschitzWith_card_equiv_pi_aux lipschitzWith_one_equiv_pi_aux s
end Aux
noncomputable instance : NormedAddCommGroup C⋆ᵐᵒᵈ(A, Π i, E i) :=
.ofCoreReplaceAll (normedSpaceCore A) uniformity_pi_eq_aux isBounded_pi_iff_aux
noncomputable instance : NormedSpace ℂ C⋆ᵐᵒᵈ(A, Π i, E i) := .ofCore (normedSpaceCore A)
end Pi
/-! ## Inner product spaces as C⋆-modules -/
section InnerProductSpace
open ComplexOrder
variable {E : Type*}
variable [NormedAddCommGroup E] [InnerProductSpace ℂ E]
open scoped InnerProductSpace in
/-- Reinterpret an inner product space `E` over `ℂ` as a `CStarModule` over `ℂ`.
Note: this instance requires `SMul ℂᵐᵒᵖ E` and `IsCentralScalar ℂ E` instances to exist on `E`,
which is unlikely to occur in practice. However, in practice one could either add those instances
to the type `E` in question, or else supply them to this instance manually, which is reason behind
the naming of these two instance arguments. -/
instance instCStarModuleComplex : CStarModule ℂ E where
inner x y := ⟪x, y⟫_ℂ
inner_add_right := by simp [_root_.inner_add_right]
inner_self_nonneg {x} := by
rw [← inner_self_ofReal_re, RCLike.ofReal_nonneg]
exact inner_self_nonneg
inner_self := by simp
inner_op_smul_right := by simp [inner_smul_right]
inner_smul_right_complex := by simp [inner_smul_right, smul_eq_mul]
star_inner _ _ := by simp
norm_eq_sqrt_norm_inner_self {x} := by
simpa only [← inner_self_re_eq_norm] using norm_eq_sqrt_re_inner x
-- Ensures that the two ways to obtain `CStarModule ℂᵐᵒᵖ ℂ` are definitionally equal.
example : instCStarModule (A := ℂ) = instCStarModuleComplex := by with_reducible_and_instances rfl
/- Ensures that the two `Inner ℂ ℂ` instances are definitionally equal. Note that this cannot be at
reducible and instances transparency because the one from `InnerProductSpace` uses `StarRingEnd`
whereas `WithCStarModule.instCStarModule.toInner` uses `star` since `A` may not be commutative. -/
example : (toInner : Inner ℂ ℂ) = WithCStarModule.instCStarModule.toInner := rfl
end InnerProductSpace
end WithCStarModule
|
Periodic.lean
|
/-
Copyright (c) 2021 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import Mathlib.Algebra.Ring.NegOnePow
/-!
# Periodicity
In this file we define and then prove facts about periodic and antiperiodic functions.
## Main definitions
* `Function.Periodic`: A function `f` is *periodic* if `∀ x, f (x + c) = f x`.
`f` is referred to as periodic with period `c` or `c`-periodic.
* `Function.Antiperiodic`: A function `f` is *antiperiodic* if `∀ x, f (x + c) = -f x`.
`f` is referred to as antiperiodic with antiperiod `c` or `c`-antiperiodic.
Note that any `c`-antiperiodic function will necessarily also be `2 • c`-periodic.
## Tags
period, periodic, periodicity, antiperiodic
-/
assert_not_exists Field
variable {α β γ : Type*} {f g : α → β} {c c₁ c₂ x : α}
open Set
namespace Function
/-! ### Periodicity -/
/-- A function `f` is said to be `Periodic` with period `c` if for all `x`, `f (x + c) = f x`. -/
@[simp]
def Periodic [Add α] (f : α → β) (c : α) : Prop :=
∀ x : α, f (x + c) = f x
protected theorem Periodic.funext [Add α] (h : Periodic f c) : (fun x => f (x + c)) = f :=
funext h
protected theorem Periodic.comp [Add α] (h : Periodic f c) (g : β → γ) : Periodic (g ∘ f) c := by
simp_all
theorem Periodic.comp_addHom [Add α] [Add γ] (h : Periodic f c) (g : AddHom γ α) (g_inv : α → γ)
(hg : RightInverse g_inv g) : Periodic (f ∘ g) (g_inv c) := fun x => by
simp only [hg c, h (g x), map_add, comp_apply]
@[to_additive]
protected theorem Periodic.mul [Add α] [Mul β] (hf : Periodic f c) (hg : Periodic g c) :
Periodic (f * g) c := by simp_all
@[to_additive]
protected theorem Periodic.div [Add α] [Div β] (hf : Periodic f c) (hg : Periodic g c) :
Periodic (f / g) c := by simp_all
@[to_additive]
theorem _root_.List.periodic_prod [Add α] [MulOneClass β] (l : List (α → β))
(hl : ∀ f ∈ l, Periodic f c) : Periodic l.prod c := by
induction l with
| nil => simp
| cons g l ih =>
rw [List.forall_mem_cons] at hl
simpa only [List.prod_cons] using hl.1.mul (ih hl.2)
@[to_additive]
theorem _root_.Multiset.periodic_prod [Add α] [CommMonoid β] (s : Multiset (α → β))
(hs : ∀ f ∈ s, Periodic f c) : Periodic s.prod c :=
(s.prod_toList ▸ s.toList.periodic_prod) fun f hf => hs f <| Multiset.mem_toList.mp hf
@[to_additive]
theorem _root_.Finset.periodic_prod [Add α] [CommMonoid β] {ι : Type*} {f : ι → α → β}
(s : Finset ι) (hs : ∀ i ∈ s, Periodic (f i) c) : Periodic (∏ i ∈ s, f i) c :=
s.prod_map_toList f ▸ (s.toList.map f).periodic_prod (by simpa [-Periodic] )
@[to_additive]
protected theorem Periodic.smul [Add α] [SMul γ β] (h : Periodic f c) (a : γ) :
Periodic (a • f) c := by simp_all
protected theorem Periodic.const_smul [AddMonoid α] [Group γ] [DistribMulAction γ α]
(h : Periodic f c) (a : γ) : Periodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by
simpa only [smul_add, smul_inv_smul] using h (a • x)
theorem Periodic.const_inv_smul [AddMonoid α] [Group γ] [DistribMulAction γ α] (h : Periodic f c)
(a : γ) : Periodic (fun x => f (a⁻¹ • x)) (a • c) := by
simpa only [inv_inv] using h.const_smul a⁻¹
theorem Periodic.add_period [AddSemigroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) :
Periodic f (c₁ + c₂) := by simp_all [← add_assoc]
theorem Periodic.sub_eq [AddGroup α] (h : Periodic f c) (x : α) : f (x - c) = f x := by
simpa only [sub_add_cancel] using (h (x - c)).symm
theorem Periodic.sub_eq' [SubtractionCommMonoid α] (h : Periodic f c) : f (c - x) = f (-x) := by
simpa only [sub_eq_neg_add] using h (-x)
protected theorem Periodic.neg [AddGroup α] (h : Periodic f c) : Periodic f (-c) := by
simpa only [sub_eq_add_neg, Periodic] using h.sub_eq
theorem Periodic.sub_period [AddGroup α] (h1 : Periodic f c₁) (h2 : Periodic f c₂) :
Periodic f (c₁ - c₂) := fun x => by
rw [sub_eq_add_neg, ← add_assoc, h2.neg, h1]
theorem Periodic.const_add [AddSemigroup α] (h : Periodic f c) (a : α) :
Periodic (fun x => f (a + x)) c := fun x => by simpa [add_assoc] using h (a + x)
theorem Periodic.add_const [AddCommSemigroup α] (h : Periodic f c) (a : α) :
Periodic (fun x => f (x + a)) c := fun x => by
simpa only [add_right_comm] using h (x + a)
theorem Periodic.const_sub [AddCommGroup α] (h : Periodic f c) (a : α) :
Periodic (fun x => f (a - x)) c := fun x => by
simp only [← sub_sub, h.sub_eq]
theorem Periodic.sub_const [SubtractionCommMonoid α] (h : Periodic f c) (a : α) :
Periodic (fun x => f (x - a)) c := by
simpa only [sub_eq_add_neg] using h.add_const (-a)
theorem Periodic.nsmul [AddMonoid α] (h : Periodic f c) (n : ℕ) : Periodic f (n • c) := by
induction n <;> simp_all [add_nsmul, ← add_assoc]
theorem Periodic.nat_mul [NonAssocSemiring α] (h : Periodic f c) (n : ℕ) : Periodic f (n * c) := by
simpa only [nsmul_eq_mul] using h.nsmul n
theorem Periodic.neg_nsmul [AddGroup α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n • c)) :=
(h.nsmul n).neg
theorem Periodic.neg_nat_mul [NonAssocRing α] (h : Periodic f c) (n : ℕ) : Periodic f (-(n * c)) :=
(h.nat_mul n).neg
theorem Periodic.sub_nsmul_eq [AddGroup α] (h : Periodic f c) (n : ℕ) : f (x - n • c) = f x := by
simpa only [sub_eq_add_neg] using h.neg_nsmul n x
theorem Periodic.sub_nat_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℕ) :
f (x - n * c) = f x := by
simpa only [nsmul_eq_mul] using h.sub_nsmul_eq n
theorem Periodic.nsmul_sub_eq [SubtractionCommMonoid α] (h : Periodic f c) (n : ℕ) :
f (n • c - x) = f (-x) :=
(h.nsmul n).sub_eq'
theorem Periodic.nat_mul_sub_eq [NonAssocRing α] (h : Periodic f c) (n : ℕ) :
f (n * c - x) = f (-x) := by
simpa only [sub_eq_neg_add] using h.nat_mul n (-x)
protected theorem Periodic.zsmul [AddGroup α] (h : Periodic f c) (n : ℤ) : Periodic f (n • c) := by
rcases n with n | n
· simpa only [Int.ofNat_eq_coe, natCast_zsmul] using h.nsmul n
· simpa only [negSucc_zsmul] using (h.nsmul (n + 1)).neg
protected theorem Periodic.int_mul [NonAssocRing α] (h : Periodic f c) (n : ℤ) :
Periodic f (n * c) := by
simpa only [zsmul_eq_mul] using h.zsmul n
theorem Periodic.sub_zsmul_eq [AddGroup α] (h : Periodic f c) (n : ℤ) : f (x - n • c) = f x :=
(h.zsmul n).sub_eq x
theorem Periodic.sub_int_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) : f (x - n * c) = f x :=
(h.int_mul n).sub_eq x
theorem Periodic.zsmul_sub_eq [AddCommGroup α] (h : Periodic f c) (n : ℤ) :
f (n • c - x) = f (-x) :=
(h.zsmul _).sub_eq'
theorem Periodic.int_mul_sub_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) :
f (n * c - x) = f (-x) :=
(h.int_mul _).sub_eq'
protected theorem Periodic.eq [AddZeroClass α] (h : Periodic f c) : f c = f 0 := by
simpa only [zero_add] using h 0
protected theorem Periodic.neg_eq [AddGroup α] (h : Periodic f c) : f (-c) = f 0 :=
h.neg.eq
protected theorem Periodic.nsmul_eq [AddMonoid α] (h : Periodic f c) (n : ℕ) : f (n • c) = f 0 :=
(h.nsmul n).eq
theorem Periodic.nat_mul_eq [NonAssocSemiring α] (h : Periodic f c) (n : ℕ) : f (n * c) = f 0 :=
(h.nat_mul n).eq
theorem Periodic.zsmul_eq [AddGroup α] (h : Periodic f c) (n : ℤ) : f (n • c) = f 0 :=
(h.zsmul n).eq
theorem Periodic.int_mul_eq [NonAssocRing α] (h : Periodic f c) (n : ℤ) : f (n * c) = f 0 :=
(h.int_mul n).eq
theorem periodic_with_period_zero [AddZeroClass α] (f : α → β) : Periodic f 0 := fun x => by
rw [add_zero]
theorem Periodic.map_vadd_zmultiples [AddCommGroup α] (hf : Periodic f c)
(a : AddSubgroup.zmultiples c) (x : α) : f (a +ᵥ x) = f x := by
rcases a with ⟨_, m, rfl⟩
simp [AddSubgroup.vadd_def, add_comm _ x, hf.zsmul m x]
theorem Periodic.map_vadd_multiples [AddCommMonoid α] (hf : Periodic f c)
(a : AddSubmonoid.multiples c) (x : α) : f (a +ᵥ x) = f x := by
rcases a with ⟨_, m, rfl⟩
simp [AddSubmonoid.vadd_def, add_comm _ x, hf.nsmul m x]
/-- Lift a periodic function to a function from the quotient group. -/
def Periodic.lift [AddGroup α] (h : Periodic f c) (x : α ⧸ AddSubgroup.zmultiples c) : β :=
Quotient.liftOn' x f fun a b h' => by
rw [QuotientAddGroup.leftRel_apply] at h'
obtain ⟨k, hk⟩ := h'
exact (h.zsmul k _).symm.trans (congr_arg f (add_eq_of_eq_neg_add hk))
@[simp]
theorem Periodic.lift_coe [AddGroup α] (h : Periodic f c) (a : α) :
h.lift (a : α ⧸ AddSubgroup.zmultiples c) = f a :=
rfl
/-- A periodic function `f : R → X` on a semiring (or, more generally, `AddZeroClass`)
of non-zero period is not injective. -/
lemma Periodic.not_injective {R X : Type*} [AddZeroClass R] {f : R → X} {c : R}
(hf : Periodic f c) (hc : c ≠ 0) : ¬ Injective f := fun h ↦ hc <| h hf.eq
/-! ### Antiperiodicity -/
/-- A function `f` is said to be `antiperiodic` with antiperiod `c` if for all `x`,
`f (x + c) = -f x`. -/
@[simp]
def Antiperiodic [Add α] [Neg β] (f : α → β) (c : α) : Prop :=
∀ x : α, f (x + c) = -f x
protected theorem Antiperiodic.funext [Add α] [Neg β] (h : Antiperiodic f c) :
(fun x => f (x + c)) = -f :=
funext h
protected theorem Antiperiodic.funext' [Add α] [InvolutiveNeg β] (h : Antiperiodic f c) :
(fun x => -f (x + c)) = f :=
neg_eq_iff_eq_neg.mpr h.funext
/-- If a function is `antiperiodic` with antiperiod `c`, then it is also `Periodic` with period
`2 • c`. -/
protected theorem Antiperiodic.periodic [AddMonoid α] [InvolutiveNeg β]
(h : Antiperiodic f c) : Periodic f (2 • c) := by simp [two_nsmul, ← add_assoc, h _]
/-- If a function is `antiperiodic` with antiperiod `c`, then it is also `Periodic` with period
`2 * c`. -/
protected theorem Antiperiodic.periodic_two_mul [NonAssocSemiring α] [InvolutiveNeg β]
(h : Antiperiodic f c) : Periodic f (2 * c) := nsmul_eq_mul 2 c ▸ h.periodic
protected theorem Antiperiodic.eq [AddZeroClass α] [Neg β] (h : Antiperiodic f c) : f c = -f 0 := by
simpa only [zero_add] using h 0
theorem Antiperiodic.even_nsmul_periodic [AddMonoid α] [InvolutiveNeg β] (h : Antiperiodic f c)
(n : ℕ) : Periodic f ((2 * n) • c) := mul_nsmul c 2 n ▸ h.periodic.nsmul n
theorem Antiperiodic.nat_even_mul_periodic [NonAssocSemiring α] [InvolutiveNeg β]
(h : Antiperiodic f c) (n : ℕ) : Periodic f (n * (2 * c)) :=
h.periodic_two_mul.nat_mul n
theorem Antiperiodic.odd_nsmul_antiperiodic [AddMonoid α] [InvolutiveNeg β] (h : Antiperiodic f c)
(n : ℕ) : Antiperiodic f ((2 * n + 1) • c) := fun x => by
rw [add_nsmul, one_nsmul, ← add_assoc, h, h.even_nsmul_periodic]
theorem Antiperiodic.nat_odd_mul_antiperiodic [NonAssocSemiring α] [InvolutiveNeg β]
(h : Antiperiodic f c) (n : ℕ) : Antiperiodic f (n * (2 * c) + c) := fun x => by
rw [← add_assoc, h, h.nat_even_mul_periodic]
theorem Antiperiodic.even_zsmul_periodic [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c)
(n : ℤ) : Periodic f ((2 * n) • c) := by
rw [mul_comm, mul_zsmul, two_zsmul, ← two_nsmul]
exact h.periodic.zsmul n
theorem Antiperiodic.int_even_mul_periodic [NonAssocRing α] [InvolutiveNeg β] (h : Antiperiodic f c)
(n : ℤ) : Periodic f (n * (2 * c)) :=
h.periodic_two_mul.int_mul n
theorem Antiperiodic.odd_zsmul_antiperiodic [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c)
(n : ℤ) : Antiperiodic f ((2 * n + 1) • c) := by
intro x
rw [add_zsmul, one_zsmul, ← add_assoc, h, h.even_zsmul_periodic]
theorem Antiperiodic.int_odd_mul_antiperiodic [NonAssocRing α] [InvolutiveNeg β]
(h : Antiperiodic f c) (n : ℤ) : Antiperiodic f (n * (2 * c) + c) := fun x => by
rw [← add_assoc, h, h.int_even_mul_periodic]
theorem Antiperiodic.sub_eq [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (x : α) :
f (x - c) = -f x := by simp only [← neg_eq_iff_eq_neg, ← h (x - c), sub_add_cancel]
theorem Antiperiodic.sub_eq' [SubtractionCommMonoid α] [Neg β] (h : Antiperiodic f c) :
f (c - x) = -f (-x) := by simpa only [sub_eq_neg_add] using h (-x)
protected theorem Antiperiodic.neg [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) :
Antiperiodic f (-c) := by simpa only [sub_eq_add_neg, Antiperiodic] using h.sub_eq
theorem Antiperiodic.neg_eq [AddGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) :
f (-c) = -f 0 := by
simpa only [zero_add] using h.neg 0
theorem Antiperiodic.nat_mul_eq_of_eq_zero [NonAssocSemiring α] [NegZeroClass β]
(h : Antiperiodic f c) (hi : f 0 = 0) : ∀ n : ℕ, f (n * c) = 0
| 0 => by rwa [Nat.cast_zero, zero_mul]
| n + 1 => by simp [add_mul, h _, Antiperiodic.nat_mul_eq_of_eq_zero h hi n]
theorem Antiperiodic.int_mul_eq_of_eq_zero [NonAssocRing α] [SubtractionMonoid β]
(h : Antiperiodic f c) (hi : f 0 = 0) : ∀ n : ℤ, f (n * c) = 0
| (n : ℕ) => by rw [Int.cast_natCast, h.nat_mul_eq_of_eq_zero hi n]
| .negSucc n => by rw [Int.cast_negSucc, neg_mul, ← mul_neg, h.neg.nat_mul_eq_of_eq_zero hi]
theorem Antiperiodic.add_zsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℤ) : f (x + n • c) = (n.negOnePow : ℤ) • f x := by
rcases Int.even_or_odd' n with ⟨k, rfl | rfl⟩
· rw [h.even_zsmul_periodic, Int.negOnePow_two_mul, Units.val_one, one_zsmul]
· rw [h.odd_zsmul_antiperiodic, Int.negOnePow_two_mul_add_one, Units.val_neg,
Units.val_one, neg_zsmul, one_zsmul]
theorem Antiperiodic.sub_zsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℤ) : f (x - n • c) = (n.negOnePow : ℤ) • f x := by
simpa only [sub_eq_add_neg, neg_zsmul, Int.negOnePow_neg] using h.add_zsmul_eq (-n)
theorem Antiperiodic.zsmul_sub_eq [AddCommGroup α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℤ) : f (n • c - x) = (n.negOnePow : ℤ) • f (-x) := by
rw [sub_eq_add_neg, add_comm]
exact h.add_zsmul_eq n
theorem Antiperiodic.add_int_mul_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c)
(n : ℤ) : f (x + n * c) = (n.negOnePow : ℤ) * f x := by
simpa only [zsmul_eq_mul] using h.add_zsmul_eq n
theorem Antiperiodic.sub_int_mul_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c)
(n : ℤ) : f (x - n * c) = (n.negOnePow : ℤ) * f x := by
simpa only [zsmul_eq_mul] using h.sub_zsmul_eq n
theorem Antiperiodic.int_mul_sub_eq [NonAssocRing α] [NonAssocRing β] (h : Antiperiodic f c)
(n : ℤ) : f (n * c - x) = (n.negOnePow : ℤ) * f (-x) := by
simpa only [zsmul_eq_mul] using h.zsmul_sub_eq n
theorem Antiperiodic.add_nsmul_eq [AddMonoid α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℕ) : f (x + n • c) = (-1) ^ n • f x := by
rcases Nat.even_or_odd' n with ⟨k, rfl | rfl⟩
· rw [h.even_nsmul_periodic]
simp
· rw [h.odd_nsmul_antiperiodic]
simp [pow_add]
theorem Antiperiodic.sub_nsmul_eq [AddGroup α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℕ) : f (x - n • c) = (-1) ^ n • f x := by
simpa only [Int.reduceNeg, natCast_zsmul] using h.sub_zsmul_eq n
theorem Antiperiodic.nsmul_sub_eq [AddCommGroup α] [SubtractionMonoid β] (h : Antiperiodic f c)
(n : ℕ) : f (n • c - x) = (-1) ^ n • f (-x) := by
simpa only [Int.reduceNeg, natCast_zsmul] using h.zsmul_sub_eq n
theorem Antiperiodic.const_add [AddSemigroup α] [Neg β] (h : Antiperiodic f c) (a : α) :
Antiperiodic (fun x => f (a + x)) c := fun x => by simpa [add_assoc] using h (a + x)
theorem Antiperiodic.add_const [AddCommSemigroup α] [Neg β] (h : Antiperiodic f c) (a : α) :
Antiperiodic (fun x => f (x + a)) c := fun x => by
simpa only [add_right_comm] using h (x + a)
theorem Antiperiodic.const_sub [AddCommGroup α] [InvolutiveNeg β] (h : Antiperiodic f c) (a : α) :
Antiperiodic (fun x => f (a - x)) c := fun x => by
simp only [← sub_sub, h.sub_eq]
theorem Antiperiodic.sub_const [SubtractionCommMonoid α] [Neg β] (h : Antiperiodic f c) (a : α) :
Antiperiodic (fun x => f (x - a)) c := by
simpa only [sub_eq_add_neg] using h.add_const (-a)
theorem Antiperiodic.smul [Add α] [Monoid γ] [AddGroup β] [DistribMulAction γ β]
(h : Antiperiodic f c) (a : γ) : Antiperiodic (a • f) c := by simp_all
theorem Antiperiodic.const_smul [AddMonoid α] [Neg β] [Group γ] [DistribMulAction γ α]
(h : Antiperiodic f c) (a : γ) : Antiperiodic (fun x => f (a • x)) (a⁻¹ • c) := fun x => by
simpa only [smul_add, smul_inv_smul] using h (a • x)
theorem Antiperiodic.const_inv_smul [AddMonoid α] [Neg β] [Group γ] [DistribMulAction γ α]
(h : Antiperiodic f c) (a : γ) : Antiperiodic (fun x => f (a⁻¹ • x)) (a • c) := by
simpa only [inv_inv] using h.const_smul a⁻¹
theorem Antiperiodic.add [AddSemigroup α] [InvolutiveNeg β] (h1 : Antiperiodic f c₁)
(h2 : Antiperiodic f c₂) : Periodic f (c₁ + c₂) := by simp_all [← add_assoc]
theorem Antiperiodic.sub [AddGroup α] [InvolutiveNeg β] (h1 : Antiperiodic f c₁)
(h2 : Antiperiodic f c₂) : Periodic f (c₁ - c₂) := by
simpa only [sub_eq_add_neg] using h1.add h2.neg
theorem Periodic.add_antiperiod [AddSemigroup α] [Neg β] (h1 : Periodic f c₁)
(h2 : Antiperiodic f c₂) : Antiperiodic f (c₁ + c₂) := by simp_all [← add_assoc]
theorem Periodic.sub_antiperiod [AddGroup α] [InvolutiveNeg β] (h1 : Periodic f c₁)
(h2 : Antiperiodic f c₂) : Antiperiodic f (c₁ - c₂) := by
simpa only [sub_eq_add_neg] using h1.add_antiperiod h2.neg
theorem Periodic.add_antiperiod_eq [AddMonoid α] [Neg β] (h1 : Periodic f c₁)
(h2 : Antiperiodic f c₂) : f (c₁ + c₂) = -f 0 :=
(h1.add_antiperiod h2).eq
theorem Periodic.sub_antiperiod_eq [AddGroup α] [InvolutiveNeg β] (h1 : Periodic f c₁)
(h2 : Antiperiodic f c₂) : f (c₁ - c₂) = -f 0 :=
(h1.sub_antiperiod h2).eq
theorem Antiperiodic.mul [Add α] [Mul β] [HasDistribNeg β] (hf : Antiperiodic f c)
(hg : Antiperiodic g c) : Periodic (f * g) c := by simp_all
theorem Antiperiodic.div [Add α] [DivisionMonoid β] [HasDistribNeg β] (hf : Antiperiodic f c)
(hg : Antiperiodic g c) : Periodic (f / g) c := by simp_all [neg_div_neg_eq]
end Function
|
ValMinAbs.lean
|
/-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import Mathlib.Data.ZMod.Basic
import Mathlib.Tactic.Linarith
/-!
# Absolute value in `ZMod n`
-/
namespace ZMod
variable {n : ℕ} {a : ZMod n}
/-- Returns the integer in the same equivalence class as `x` that is closest to `0`.
The result will be in the interval `(-n/2, n/2]`. -/
def valMinAbs : ∀ {n : ℕ}, ZMod n → ℤ
| 0, x => x
| n@(_ + 1), x => if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp] lemma valMinAbs_def_zero (x : ZMod 0) : valMinAbs x = x := rfl
lemma valMinAbs_def_pos : ∀ {n : ℕ} [NeZero n] (x : ZMod n),
valMinAbs x = if x.val ≤ n / 2 then (x.val : ℤ) else x.val - n
| 0, _, x => by cases NeZero.ne 0 rfl
| n + 1, _, x => rfl
@[simp, norm_cast]
lemma coe_valMinAbs : ∀ {n : ℕ} (x : ZMod n), (x.valMinAbs : ZMod n) = x
| 0, _ => Int.cast_id
| k@(n + 1), x => by
rw [valMinAbs_def_pos]
split_ifs
· rw [Int.cast_natCast, natCast_zmod_val]
· rw [Int.cast_sub, Int.cast_natCast, natCast_zmod_val, Int.cast_natCast, natCast_self,
sub_zero]
lemma injective_valMinAbs : (valMinAbs : ZMod n → ℤ).Injective :=
Function.injective_iff_hasLeftInverse.2 ⟨_, coe_valMinAbs⟩
lemma valMinAbs_nonneg_iff [NeZero n] (x : ZMod n) : 0 ≤ x.valMinAbs ↔ x.val ≤ n / 2 := by
rw [valMinAbs_def_pos]; split_ifs with h
· exact iff_of_true (Nat.cast_nonneg _) h
· exact iff_of_false (sub_lt_zero.2 <| Int.ofNat_lt.2 x.val_lt).not_ge h
lemma valMinAbs_mul_two_eq_iff (a : ZMod n) : a.valMinAbs * 2 = n ↔ 2 * a.val = n := by
rcases n with - | n
· simp
by_cases h : a.val ≤ n.succ / 2
· dsimp [valMinAbs]
rw [if_pos h, ← Int.natCast_inj, Nat.cast_mul, Nat.cast_two, mul_comm, Int.natCast_add,
Nat.cast_one]
apply iff_of_false _ (mt _ h)
· intro he
rw [← a.valMinAbs_nonneg_iff, ← mul_nonneg_iff_left_nonneg_of_pos, he] at h
exacts [h (Nat.cast_nonneg _), zero_lt_two]
· rw [mul_comm]
exact fun h => (Nat.le_div_iff_mul_le zero_lt_two).2 h.le
lemma valMinAbs_mem_Ioc [NeZero n] (x : ZMod n) : x.valMinAbs * 2 ∈ Set.Ioc (-n : ℤ) n := by
simp_rw [valMinAbs_def_pos, Nat.le_div_two_iff_mul_two_le]; split_ifs with h
· refine ⟨(neg_lt_zero.2 <| mod_cast NeZero.pos n).trans_le (mul_nonneg ?_ ?_), h⟩
exacts [Nat.cast_nonneg _, zero_le_two]
· refine ⟨?_, le_trans (mul_nonpos_of_nonpos_of_nonneg ?_ zero_le_two) <| Nat.cast_nonneg _⟩
· linarith only [h]
· rw [sub_nonpos, Int.ofNat_le]
exact x.val_lt.le
lemma valMinAbs_spec [NeZero n] (x : ZMod n) (y : ℤ) :
x.valMinAbs = y ↔ x = y ∧ y * 2 ∈ Set.Ioc (-n : ℤ) n where
mp := by rintro rfl; exact ⟨x.coe_valMinAbs.symm, x.valMinAbs_mem_Ioc⟩
mpr h := by
rw [← sub_eq_zero]
apply @Int.eq_zero_of_abs_lt_dvd n
· rw [← intCast_zmod_eq_zero_iff_dvd, Int.cast_sub, coe_valMinAbs, h.1, sub_self]
rw [← mul_lt_mul_right (@zero_lt_two ℤ _ _ _ _ _)]
nth_rw 1 [← abs_eq_self.2 (@zero_le_two ℤ _ _ _ _)]
rw [← abs_mul, sub_mul, abs_lt]
constructor <;> linarith only [x.valMinAbs_mem_Ioc.1, x.valMinAbs_mem_Ioc.2, h.2.1, h.2.2]
lemma natAbs_valMinAbs_le [NeZero n] (x : ZMod n) : x.valMinAbs.natAbs ≤ n / 2 := by
rw [Nat.le_div_two_iff_mul_two_le]
rcases x.valMinAbs.natAbs_eq with h | h
· rw [← h]
exact x.valMinAbs_mem_Ioc.2
· rw [← neg_le_neg_iff, ← neg_mul, ← h]
exact x.valMinAbs_mem_Ioc.1.le
@[simp]
lemma valMinAbs_zero : ∀ n, (0 : ZMod n).valMinAbs = 0
| 0 => by simp only [valMinAbs_def_zero]
| n + 1 => by simp only [valMinAbs_def_pos, if_true, Int.ofNat_zero, zero_le, val_zero]
@[simp]
lemma valMinAbs_eq_zero (x : ZMod n) : x.valMinAbs = 0 ↔ x = 0 := by
rcases n with - | n
· simp
rw [← valMinAbs_zero n.succ]
apply injective_valMinAbs.eq_iff
lemma natCast_natAbs_valMinAbs [NeZero n] (a : ZMod n) :
(a.valMinAbs.natAbs : ZMod n) = if a.val ≤ (n : ℕ) / 2 then a else -a := by
have : (a.val : ℤ) - n ≤ 0 := by
rw [sub_nonpos, Int.ofNat_le]
exact a.val_le
rw [valMinAbs_def_pos]
split_ifs
· rw [Int.natAbs_natCast, natCast_zmod_val]
· rw [← Int.cast_natCast, Int.ofNat_natAbs_of_nonpos this, Int.cast_neg, Int.cast_sub,
Int.cast_natCast, Int.cast_natCast, natCast_self, sub_zero, natCast_zmod_val]
lemma valMinAbs_neg_of_ne_half (ha : 2 * a.val ≠ n) : (-a).valMinAbs = -a.valMinAbs := by
rcases eq_zero_or_neZero n with h | h
· subst h
rfl
refine (valMinAbs_spec _ _).2 ⟨?_, ?_, ?_⟩
· rw [Int.cast_neg, coe_valMinAbs]
· rw [neg_mul, neg_lt_neg_iff]
exact a.valMinAbs_mem_Ioc.2.lt_of_ne (mt a.valMinAbs_mul_two_eq_iff.1 ha)
· linarith only [a.valMinAbs_mem_Ioc.1]
@[simp]
lemma natAbs_valMinAbs_neg (a : ZMod n) : (-a).valMinAbs.natAbs = a.valMinAbs.natAbs := by
by_cases h2a : 2 * a.val = n
· rw [a.neg_eq_self_iff.2 (Or.inr h2a)]
· rw [valMinAbs_neg_of_ne_half h2a, Int.natAbs_neg]
lemma val_eq_ite_valMinAbs [NeZero n] (a : ZMod n) :
(a.val : ℤ) = a.valMinAbs + if a.val ≤ n / 2 then 0 else n := by
rw [valMinAbs_def_pos]
split_ifs <;> simp [add_zero, sub_add_cancel]
lemma prime_ne_zero (p q : ℕ) [hp : Fact p.Prime] [hq : Fact q.Prime] (hpq : p ≠ q) :
(q : ZMod p) ≠ 0 := by
rwa [← Nat.cast_zero, Ne, natCast_eq_natCast_iff, Nat.modEq_zero_iff_dvd,
← hp.1.coprime_iff_not_dvd, Nat.coprime_primes hp.1 hq.1]
variable {n a : ℕ}
lemma valMinAbs_natAbs_eq_min [hpos : NeZero n] (a : ZMod n) :
a.valMinAbs.natAbs = min a.val (n - a.val) := by
rw [valMinAbs_def_pos]
have := a.val_lt
omega
lemma valMinAbs_natCast_of_le_half (ha : a ≤ n / 2) : (a : ZMod n).valMinAbs = a := by
cases n
· simp
· simp [valMinAbs_def_pos, val_natCast, Nat.mod_eq_of_lt (ha.trans_lt <| Nat.div_lt_self' _ 0),
ha]
lemma valMinAbs_natCast_of_half_lt (ha : n / 2 < a) (ha' : a < n) :
(a : ZMod n).valMinAbs = a - n := by
cases n
· cases not_lt_bot ha'
· simp [valMinAbs_def_pos, val_natCast, Nat.mod_eq_of_lt ha', ha.not_ge]
@[simp]
lemma valMinAbs_natCast_eq_self [NeZero n] : (a : ZMod n).valMinAbs = a ↔ a ≤ n / 2 := by
refine ⟨fun ha => ?_, valMinAbs_natCast_of_le_half⟩
rw [← Int.natAbs_natCast a, ← ha]
exact natAbs_valMinAbs_le (n := n) a
lemma natAbs_valMinAbs_add_le (a b : ZMod n) :
(a + b).valMinAbs.natAbs ≤ (a.valMinAbs + b.valMinAbs).natAbs := by
rcases n with - | n
· rfl
apply natAbs_min_of_le_div_two n.succ
· simp_rw [Int.cast_add, coe_valMinAbs]
· apply natAbs_valMinAbs_le
end ZMod
|
Basic.lean
|
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.Matrix.StdBasis
import Mathlib.RingTheory.Finiteness.Cardinality
/-!
# Finite and free modules
We provide some instances for finite and free modules.
## Main results
* `Module.Free.ChooseBasisIndex.fintype` : If a free module is finite, then any basis is finite.
* `Module.Finite.of_basis` : A free module with a basis indexed by a `Fintype` is finite.
-/
universe u v w
/-- If a free module is finite, then the arbitrary basis is finite. -/
noncomputable instance Module.Free.ChooseBasisIndex.fintype (R : Type u) (M : Type v)
[Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M] [Module.Finite R M] :
Fintype (Module.Free.ChooseBasisIndex R M) := by
refine @Fintype.ofFinite _ ?_
cases subsingleton_or_nontrivial R
· have := Module.subsingleton R M
rw [ChooseBasisIndex]
infer_instance
· exact Module.Finite.finite_basis (chooseBasis _ _)
/-- A free module with a basis indexed by a `Fintype` is finite. -/
theorem Module.Finite.of_basis {R M ι : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
[_root_.Finite ι] (b : Basis ι R M) : Module.Finite R M := by
cases nonempty_fintype ι
classical
refine ⟨⟨Finset.univ.image b, ?_⟩⟩
simp only [Set.image_univ, Finset.coe_univ, Finset.coe_image, Basis.span_eq]
instance Module.Finite.matrix {R ι₁ ι₂ M : Type*}
[Semiring R] [AddCommMonoid M] [Module R M] [Module.Free R M] [Module.Finite R M]
[_root_.Finite ι₁] [_root_.Finite ι₂] :
Module.Finite R (Matrix ι₁ ι₂ M) := by
cases nonempty_fintype ι₁
cases nonempty_fintype ι₂
exact Module.Finite.of_basis <| (Free.chooseBasis _ _).matrix _ _
example {ι₁ ι₂ R : Type*} [Semiring R] [Finite ι₁] [Finite ι₂] :
Module.Finite R (Matrix ι₁ ι₂ R) := inferInstance
|
choice.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq.
(******************************************************************************)
(* Types with a choice operator *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file contains the definitions of: *)
(* choiceType == interface for types with a choice operator *)
(* The HB class is Choice. *)
(* The exact contents is documented below just before *)
(* hasChoice. *)
(* subChoiceType == interface for types that are both subType and choiceType *)
(* The HB class is SubChoice. *)
(* countType == interface for countable types (implies choiceType) *)
(* The HB class is Countable. *)
(* subCountType == interface for types that are both subType and countType *)
(* The HB class is SubCountable. *)
(* *)
(* xchoose exP == a standard x such that P x, given exP : exists x : T, P x *)
(* when T is a choiceType *)
(* The choice depends only on the extent of P (in particular,*)
(* it is independent of exP). *)
(* choose P x0 == if P x0, a standard x such that P x *)
(* pickle x == a nat encoding the value x : T, where T is a countType *)
(* unpickle n == a partial inverse to pickle: unpickle (pickle x) = Some x *)
(* pickle_inv n == a sharp partial inverse to pickle pickle_inv n = Some x *)
(* if and only if pickle x = n *)
(* *)
(* PCanIsCountable ff' == builds an instance of the isCountable interface *)
(* given ff' : pcancel f f' where the codomain of f is *)
(* a countType *)
(* CanIsCountable ff' == builds an instance of the isCountable interface *)
(* given ff' : cancel f f' where the codomain of f is *)
(* a countType *)
(* *)
(* [Choice of T by <:], [Countable of T by <:] == Choice/Countable interface *)
(* for T when T has a subType p structure with p : pred cT *)
(* and cT has a Choice/Countable interface *)
(* The corresponding structure is Canonical. This notation *)
(* is in form_scope. *)
(* *)
(* List of Choice/Countable factories with a dedicated alias: *)
(* pcan_type fK == Choice/Countable for T, given f : T -> cT where cT *)
(* has a Choice/Countable structure, a left inverse *)
(* partial function g and fK : pcancel f g *)
(* can_type fK == Choice/Countable for T, given f : T -> cT, g and *)
(* fK : cancel f g *)
(* *)
(* GenTree.tree T == generic n-ary tree type with nat-labeled nodes and *)
(* T-labeled leaves, for example GenTree.Leaf (x : T), *)
(* GenTree.Node 5 [:: t; t'] *)
(* GenTree.tree is equipped with eqType, choiceType, *)
(* and countType instances, and so simple datatypes *)
(* can be similarly equipped by encoding into *)
(* GenTree.tree and using the interfaces above. *)
(* CodeSeq.code == bijection from seq nat to nat *)
(* CodeSeq.decode == bijection inverse to CodeSeq.code *)
(* *)
(* In addition to the lemmas relevant to these definitions, this file also *)
(* contains definitions of choiceType and countType instances for all basic *)
(* basic datatypes (e.g., nat, bool, subTypes, pairs, sums, etc.). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
(* Technical definitions about coding and decoding of nat sequences, which *)
(* are used below to define various Canonical instances of the choice and *)
(* countable interfaces. *)
Module CodeSeq.
(* Goedel-style one-to-one encoding of seq nat into nat. *)
(* The code for [:: n1; ...; nk] has binary representation *)
(* 1 0 ... 0 1 ... 1 0 ... 0 1 0 ... 0 *)
(* <-----> <-----> <-----> *)
(* nk 0s n2 0s n1 0s *)
Definition code := foldr (fun n m => 2 ^ n * m.*2.+1) 0.
Fixpoint decode_rec (v q r : nat) {struct q} :=
match q, r with
| 0, _ => [:: v]
| q'.+1, 0 => v :: [rec 0, q', q']
| q'.+1, 1 => [rec v.+1, q', q']
| q'.+1, r'.+2 => [rec v, q', r']
end where "[ 'rec' v , q , r ]" := (decode_rec v q r).
Arguments decode_rec : simpl nomatch.
Definition decode n := if n is 0 then [::] else [rec 0, n.-1, n.-1].
Lemma decodeK : cancel decode code.
Proof.
have m2s: forall n, n.*2 - n = n by move=> n; rewrite -addnn addnK.
case=> //= n; rewrite -[n.+1]mul1n -(expn0 2) -[n in RHS]m2s.
elim: n {2 4}n {1 3}0 => [|q IHq] [|[|r]] v //=; rewrite {}IHq ?mul1n ?m2s //.
by rewrite expnSr -mulnA mul2n.
Qed.
Lemma codeK : cancel code decode.
Proof.
elim=> //= v s IHs; rewrite -[_ * _]prednK ?muln_gt0 ?expn_gt0 //=.
set two := 2; rewrite -[v in RHS]addn0; elim: v 0 => [|v IHv {IHs}] q.
rewrite mul1n add0n /= -{}[in RHS]IHs; case: (code s) => // u; pose n := u.+1.
by transitivity [rec q, n + u.+1, n.*2]; [rewrite addnn | elim: n => //=].
rewrite expnS -mulnA mul2n -{1}addnn -[_ * _]prednK ?muln_gt0 ?expn_gt0 //.
set u := _.-1 in IHv *; set n := u; rewrite [in u1 in _ + u1]/n.
by rewrite [in RHS]addSnnS -{}IHv; elim: n.
Qed.
Lemma ltn_code s : all (fun j => j < code s) s.
Proof.
elim: s => //= i s IHs; rewrite -[_.+1]muln1 leq_mul 1?ltn_expl //=.
apply: sub_all IHs => j /leqW lejs; rewrite -[j.+1]mul1n leq_mul ?expn_gt0 //.
by rewrite ltnS -[j]mul1n -mul2n leq_mul.
Qed.
Lemma gtn_decode n : all (ltn^~ n) (decode n).
Proof. by rewrite -{1}[n]decodeK ltn_code. Qed.
End CodeSeq.
Section OtherEncodings.
(* Miscellaneous encodings: option T -c-> seq T, T1 * T2 -c-> {i : T1 & T2} *)
(* T1 + T2 -c-> option T1 * option T2, unit -c-> bool; bool -c-> nat is *)
(* already covered in ssrnat by the nat_of_bool coercion, the odd predicate, *)
(* and their "cancellation" lemma oddb. We use these encodings to propagate *)
(* canonical structures through these type constructors so that ultimately *)
(* all Choice and Countable instanced derive from nat and the seq and sigT *)
(* constructors. *)
Variables T T1 T2 : Type.
Definition seq_of_opt := @oapp T _ (nseq 1) [::].
Lemma seq_of_optK : cancel seq_of_opt ohead. Proof. by case. Qed.
Definition tag_of_pair (p : T1 * T2) := @Tagged T1 p.1 (fun _ => T2) p.2.
Definition pair_of_tag (u : {i : T1 & T2}) := (tag u, tagged u).
Lemma tag_of_pairK : cancel tag_of_pair pair_of_tag. Proof. by case. Qed.
Lemma pair_of_tagK : cancel pair_of_tag tag_of_pair. Proof. by case. Qed.
Definition opair_of_sum (s : T1 + T2) :=
match s with inl x => (Some x, None) | inr y => (None, Some y) end.
Definition sum_of_opair p :=
oapp (some \o @inr T1 T2) (omap (@inl _ T2) p.1) p.2.
Lemma opair_of_sumK : pcancel opair_of_sum sum_of_opair. Proof. by case. Qed.
Lemma bool_of_unitK : cancel (fun _ => true) (fun _ => tt).
Proof. by case. Qed.
End OtherEncodings.
Prenex Implicits seq_of_opt tag_of_pair pair_of_tag opair_of_sum sum_of_opair.
Prenex Implicits seq_of_optK tag_of_pairK pair_of_tagK opair_of_sumK.
(* Generic variable-arity tree type, providing an encoding target for *)
(* miscellaneous user datatypes. The GenTree.tree type can be combined with *)
(* a sigT type to model multi-sorted concrete datatypes. *)
Module GenTree.
Section Def.
Variable T : Type.
Unset Elimination Schemes.
Inductive tree := Leaf of T | Node of nat & seq tree.
Definition tree_rect K IH_leaf IH_node :=
fix loop t : K t := match t with
| Leaf x => IH_leaf x
| Node n f0 =>
let fix iter_pair f : foldr (fun t => prod (K t)) unit f :=
if f is t :: f' then (loop t, iter_pair f') else tt in
IH_node n f0 (iter_pair f0)
end.
Definition tree_rec (K : tree -> Set) := @tree_rect K.
Definition tree_ind K IH_leaf IH_node :=
fix loop t : K t : Prop := match t with
| Leaf x => IH_leaf x
| Node n f0 =>
let fix iter_conj f : foldr (fun t => and (K t)) True f :=
if f is t :: f' then conj (loop t) (iter_conj f') else Logic.I
in IH_node n f0 (iter_conj f0)
end.
Fixpoint encode t : seq (nat + T) :=
match t with
| Leaf x => [:: inr _ x]
| Node n f => inl _ n.+1 :: rcons (flatten (map encode f)) (inl _ 0)
end.
Definition decode_step c fs :=
match c with
| inr x => (Leaf x :: fs.1, fs.2)
| inl 0 => ([::], fs.1 :: fs.2)
| inl n.+1 => (Node n fs.1 :: head [::] fs.2, behead fs.2)
end.
Definition decode c := ohead (foldr decode_step ([::], [::]) c).1.
Lemma codeK : pcancel encode decode.
Proof.
move=> t; rewrite /decode; set fs := (_, _).
suffices ->: foldr decode_step fs (encode t) = (t :: fs.1, fs.2) by [].
elim: t => //= n f IHt in (fs) *; elim: f IHt => //= t f IHf [].
by rewrite rcons_cat foldr_cat => -> /= /IHf[-> -> ->].
Qed.
End Def.
End GenTree.
Arguments GenTree.codeK : clear implicits.
HB.instance Definition _ (T : eqType) := Equality.copy (GenTree.tree T)
(pcan_type (GenTree.codeK T)).
(* Structures for Types with a choice function, and for Types with countably *)
(* many elements. The two concepts are closely linked: we indeed make *)
(* Countable a subclass of Choice, as countable choice is valid in CiC. This *)
(* apparent redundancy is needed to ensure the consistency of the Canonical *)
(* inference, as the canonical Choice for a given type may differ from the *)
(* countable choice for its canonical Countable structure, e.g., for options. *)
(* The Choice interface exposes two choice functions; for T : choiceType *)
(* and P : pred T, we provide: *)
(* xchoose : (exists x, P x) -> T *)
(* choose : pred T -> T -> T *)
(* While P (xchoose exP) will always hold, P (choose P x0) will be true if *)
(* and only if P x0 holds. Both xchoose and choose are extensional in P and *)
(* do not depend on the witness exP or x0 (provided P x0 holds). Note that *)
(* xchoose is slightly more powerful, but less convenient to use. *)
(* However, neither choose nor xchoose are composable: it would not be *)
(* be possible to extend the Choice structure to arbitrary pairs using only *)
(* these functions, for instance. Internally, the interfaces provides a *)
(* subtly stronger operation, Choice.InternalTheory.find, which performs a *)
(* limited search using an integer parameter only rather than a full value as *)
(* [x]choose does. This is not a restriction in a constructive theory, where *)
(* all types are concrete and hence countable. In the case of an axiomatic *)
(* theory, such as that of the Coq reals library, postulating a suitable *)
(* axiom of choice suppresses the need for guidance. Nevertheless this *)
(* operation is just what is needed to make the Choice interface compose. *)
(* The Countable interface provides three functions; for T : countType we *)
(* get pickle : T -> nat, and unpickle, pickle_inv : nat -> option T. *)
(* The functions provide an effective embedding of T in nat: unpickle is a *)
(* left inverse to pickle, which satisfies pcancel pickle unpickle, i.e., *)
(* unpickle \o pickle =1 some; pickle_inv is a more precise inverse for which *)
(* we also have ocancel pickle_inv pickle. Both unpickle and pickle need to *)
(* be partial functions to allow for possibly empty types such as {x | P x}. *)
(* The names of these functions underline the correspondence with the *)
(* notion of "Serializable" types in programming languages. *)
(* Finally, we need to provide a join class to let type inference unify *)
(* subType and countType class constraints, e.g., for a countable subType of *)
(* an uncountable choiceType (the issue does not arise earlier with eqType or *)
(* choiceType because in practice the base type of an Equality/Choice subType *)
(* is always an Equality/Choice Type). *)
HB.mixin Record hasChoice T := Mixin {
find_subdef : pred T -> nat -> option T;
choice_correct_subdef {P n x} : find_subdef P n = Some x -> P x;
choice_complete_subdef {P : pred T} :
(exists x, P x) -> exists n, find_subdef P n;
choice_extensional_subdef {P Q : pred T} :
P =1 Q -> find_subdef P =1 find_subdef Q
}.
#[short(type="choiceType")]
HB.structure Definition Choice := { T of hasChoice T & hasDecEq T}.
Module Export ChoiceNamespace.
Module Choice.
Module InternalTheory.
Notation find := find_subdef.
Notation correct := choice_correct_subdef.
Arguments correct {_ _ _ _}.
Notation complete := choice_complete_subdef.
Arguments complete {_ _}.
Notation extensional := choice_extensional_subdef.
Arguments extensional {_ _ _}.
Section InternalTheory.
Variable T : Choice.type.
Implicit Types P Q : pred T.
Fact xchoose_subproof P exP :
{x | find P (ex_minn (@choice_complete_subdef _ P exP)) = Some x}.
Proof.
case: (ex_minnP (complete exP)) => n.
by case: (find P n) => // x; exists x.
Qed.
End InternalTheory.
End InternalTheory.
End Choice.
End ChoiceNamespace.
Section ChoiceTheory.
Implicit Type T : choiceType.
Import Choice.InternalTheory CodeSeq.
Local Notation dc := decode.
Section OneType.
Variable T : choiceType.
Implicit Types P Q : pred T.
Definition xchoose P exP := sval (@xchoose_subproof T P exP).
Lemma xchooseP P exP : P (@xchoose P exP).
Proof. by rewrite /xchoose; case: (xchoose_subproof exP) => x /= /correct. Qed.
Lemma eq_xchoose P Q exP exQ : P =1 Q -> @xchoose P exP = @xchoose Q exQ.
Proof.
rewrite /xchoose => eqPQ.
case: (xchoose_subproof exP) => x; case: (xchoose_subproof exQ) => y /=.
case: ex_minnP => n; rewrite -(extensional eqPQ) => Pn minQn.
case: ex_minnP => m; rewrite !(extensional eqPQ) => Qm minPm.
by case: (eqVneq m n) => [-> -> [] //|]; rewrite eqn_leq minQn ?minPm.
Qed.
Lemma sigW P : (exists x, P x) -> {x | P x}.
Proof. by move=> exP; exists (xchoose exP); apply: xchooseP. Qed.
Lemma sig2W P Q : (exists2 x, P x & Q x) -> {x | P x & Q x}.
Proof.
move=> exPQ; have [|x /andP[]] := @sigW (predI P Q); last by exists x.
by have [x Px Qx] := exPQ; exists x; apply/andP.
Qed.
Lemma sig_eqW (vT : eqType) (lhs rhs : T -> vT) :
(exists x, lhs x = rhs x) -> {x | lhs x = rhs x}.
Proof.
move=> exP; suffices [x /eqP Ex]: {x | lhs x == rhs x} by exists x.
by apply: sigW; have [x /eqP Ex] := exP; exists x.
Qed.
Lemma sig2_eqW (vT : eqType) (P : pred T) (lhs rhs : T -> vT) :
(exists2 x, P x & lhs x = rhs x) -> {x | P x & lhs x = rhs x}.
Proof.
move=> exP; suffices [x Px /eqP Ex]: {x | P x & lhs x == rhs x} by exists x.
by apply: sig2W; have [x Px /eqP Ex] := exP; exists x.
Qed.
Definition choose P x0 :=
if insub x0 : {? x | P x} is Some (exist x Px) then
xchoose (ex_intro [eta P] x Px)
else x0.
Lemma chooseP P x0 : P x0 -> P (choose P x0).
Proof. by move=> Px0; rewrite /choose insubT xchooseP. Qed.
Lemma choose_id P x0 y0 : P x0 -> P y0 -> choose P x0 = choose P y0.
Proof. by move=> Px0 Py0; rewrite /choose !insubT /=; apply: eq_xchoose. Qed.
Lemma eq_choose P Q : P =1 Q -> choose P =1 choose Q.
Proof.
rewrite /choose => eqPQ x0.
do [case: insubP; rewrite eqPQ] => [[x Px] Qx0 _| ?]; last by rewrite insubN.
by rewrite insubT; apply: eq_xchoose.
Qed.
Section CanChoice.
Variables (sT : Type) (f : sT -> T).
Lemma PCanHasChoice f' : pcancel f f' -> hasChoice sT.
Proof.
move=> fK; pose liftP sP := [pred x | oapp sP false (f' x)].
pose sf sP := [fun n => obind f' (find (liftP sP) n)].
exists sf => [sP n x | sP [y sPy] | sP sQ eqPQ n] /=.
- by case Df: (find _ n) => //= [?] Dx; have:= correct Df; rewrite /= Dx.
- have [|n Pn] := @complete T (liftP sP); first by exists (f y); rewrite /= fK.
exists n; case Df: (find _ n) Pn => //= [x] _.
by have:= correct Df => /=; case: (f' x).
by congr (obind _ _); apply: extensional => x /=; case: (f' x) => /=.
Qed.
Definition CanHasChoice f' (fK : cancel f f') :=
PCanHasChoice (can_pcan fK).
HB.instance Definition _ f' (fK : pcancel f f') : hasChoice (pcan_type fK) :=
PCanHasChoice fK.
HB.instance Definition _ f' (fK : cancel f f') : hasChoice (can_type fK) :=
PCanHasChoice (can_pcan fK).
End CanChoice.
Section SubChoice.
Variables (P : pred T) (sT : subType P).
#[hnf] HB.instance Definition _ := Choice.copy (sub_type sT) (pcan_type valK).
End SubChoice.
Fact seq_hasChoice : hasChoice (seq T).
Proof.
pose r f := [fun xs => fun x : T => f (x :: xs) : option (seq T)].
pose fix f sP ns xs {struct ns} :=
if ns is n :: ns1 then let fr := r (f sP ns1) xs in obind fr (find fr n)
else if sP xs then Some xs else None.
exists (fun sP nn => f sP (dc nn) nil) => [sP n ys | sP [ys] | sP sQ eqPQ n].
- elim: {n}(dc n) nil => [|n ns IHs] xs /=; first by case: ifP => // sPxs [<-].
by case: (find _ n) => //= [x]; apply: IHs.
- rewrite -(cats0 ys); elim/last_ind: ys nil => [|ys y IHs] xs /=.
by move=> sPxs; exists 0; rewrite /= sPxs.
rewrite cat_rcons => /IHs[n1 sPn1] {IHs}.
have /complete[n]: exists z, f sP (dc n1) (z :: xs) by exists y.
case Df: (find _ n)=> // [x] _; exists (code (n :: dc n1)).
by rewrite codeK /= Df /= (correct Df).
elim: {n}(dc n) nil => [|n ns IHs] xs /=; first by rewrite eqPQ.
rewrite (@extensional _ _ (r (f sQ ns) xs)) => [|x]; last by rewrite IHs.
by case: find => /=.
Qed.
HB.instance Definition _ := seq_hasChoice.
End OneType.
Section TagChoice.
Variables (I : choiceType) (T_ : I -> choiceType).
Fact tagged_hasChoice : hasChoice {i : I & T_ i}.
Proof.
pose mkT i (x : T_ i) := Tagged T_ x.
pose ft tP n i := omap (mkT i) (find (tP \o mkT i) n).
pose fi tP ni nt := obind (ft tP nt) (find (ft tP nt) ni).
pose f tP n := if dc n is [:: ni; nt] then fi tP ni nt else None.
exists f => [tP n u | tP [[i x] tPxi] | sP sQ eqPQ n].
- rewrite /f /fi; case: (dc n) => [|ni [|nt []]] //=.
case: (find _ _) => //= [i]; rewrite /ft.
by case Df: (find _ _) => //= [x] [<-]; have:= correct Df.
- have /complete[nt tPnt]: exists y, (tP \o mkT i) y by exists x.
have{tPnt}: exists j, ft tP nt j by exists i; rewrite /ft; case: find tPnt.
case/complete=> ni tPn; exists (code [:: ni; nt]); rewrite /f codeK /fi.
by case Df: find tPn => //= [j] _; have:= correct Df.
rewrite /f /fi; case: (dc n) => [|ni [|nt []]] //=.
rewrite (@extensional _ _ (ft sQ nt)) => [|i].
by case: find => //= i; congr (omap _ _); apply: extensional => x /=.
by congr (omap _ _); apply: extensional => x /=.
Qed.
HB.instance Definition _ := tagged_hasChoice.
End TagChoice.
Fact nat_hasChoice : hasChoice nat.
Proof.
pose f := [fun (P : pred nat) n => if P n then Some n else None].
exists f => [P n m | P [n Pn] | P Q eqPQ n] /=; last by rewrite eqPQ.
by case: ifP => // Pn [<-].
by exists n; rewrite Pn.
Qed.
HB.instance Definition _ := nat_hasChoice.
HB.instance Definition _ := Choice.copy bool (can_type oddb).
HB.instance Definition _ := Choice.on bitseq.
HB.instance Definition _ := Choice.copy unit (can_type bool_of_unitK).
HB.instance Definition _ := Choice.copy void (pcan_type (of_voidK unit)).
HB.instance Definition _ T :=
Choice.copy (option T) (can_type (@seq_of_optK (Choice.sort T))).
HB.instance Definition _ (T1 T2 : choiceType) :=
Choice.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)).
HB.instance Definition _ (T1 T2 : choiceType) :=
Choice.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)).
HB.instance Definition _ T :=
Choice.copy (GenTree.tree T) (pcan_type (GenTree.codeK T)).
End ChoiceTheory.
#[short(type="subChoiceType")]
HB.structure Definition SubChoice T (P : pred T) :=
{ sT of Choice sT & isSub T P sT }.
Prenex Implicits xchoose choose.
Notation "[ 'Choice' 'of' T 'by' <: ]" := (Choice.copy T%type (sub_type T%type))
(format "[ 'Choice' 'of' T 'by' <: ]") : form_scope.
HB.instance Definition _ (T : choiceType) (P : pred T) :=
[Choice of {x | P x} by <:].
HB.mixin Record Choice_isCountable (T : Type) : Type := {
pickle : T -> nat;
unpickle : nat -> option T;
pickleK : pcancel pickle unpickle
}.
Arguments Choice_isCountable.axioms_ T%_type_scope.
#[short(type="countType")]
HB.structure Definition Countable := { T of Choice T & Choice_isCountable T }.
HB.factory Record isCountable (T : Type) : Type := {
pickle : T -> nat;
unpickle : nat -> option T;
pickleK : pcancel pickle unpickle
}.
HB.builders Context T of isCountable T.
HB.instance Definition _ := Equality.copy T (pcan_type pickleK).
HB.instance Definition _ := PCanHasChoice pickleK.
HB.instance Definition _ := Choice_isCountable.Build T pickleK.
HB.end.
Arguments isCountable.axioms_ T%_type_scope.
Section CountableTheory.
Variable T : countType.
Definition pickle_inv n :=
obind (fun x : T => if pickle x == n then Some x else None) (unpickle n).
Lemma pickle_invK : ocancel pickle_inv pickle.
Proof.
by rewrite /pickle_inv => n; case def_x: (unpickle n) => //= [x]; case: eqP.
Qed.
Lemma pickleK_inv : pcancel pickle pickle_inv.
Proof. by rewrite /pickle_inv => x; rewrite pickleK /= eqxx. Qed.
Lemma pcan_pickleK sT f f' :
@pcancel T sT f f' -> pcancel (pickle \o f) (pcomp f' unpickle).
Proof. by move=> fK x; rewrite /pcomp pickleK /= fK. Qed.
Definition PCanIsCountable sT (f : sT -> T) f' (fK : pcancel f f') :=
isCountable.Build sT (pcan_pickleK fK).
Definition CanIsCountable sT f f' (fK : cancel f f') :=
@PCanIsCountable sT _ _ (can_pcan fK).
HB.instance Definition _ sT (f : sT -> T) f' (fK : pcancel f f') :
isCountable (pcan_type fK) := PCanIsCountable fK.
HB.instance Definition _ sT (f : sT -> T) f' (fK : cancel f f') :
isCountable (can_type fK) := CanIsCountable fK.
#[hnf] HB.instance Definition _ (P : pred T) (sT : subType P) :=
Countable.copy (sub_type sT) (pcan_type valK).
Definition pickle_seq s := CodeSeq.code (map (@pickle T) s).
Definition unpickle_seq n := Some (pmap (@unpickle T) (CodeSeq.decode n)).
Lemma pickle_seqK : pcancel pickle_seq unpickle_seq.
Proof. by move=> s; rewrite /unpickle_seq CodeSeq.codeK (map_pK pickleK). Qed.
HB.instance Definition _ := isCountable.Build (seq T) pickle_seqK.
End CountableTheory.
Notation "[ 'Countable' 'of' T 'by' <: ]" :=
(Countable.copy T%type (sub_type T%type))
(format "[ 'Countable' 'of' T 'by' <: ]") : form_scope.
Arguments pickle_inv {T} n.
Arguments pickleK {T} x : rename.
Arguments pickleK_inv {T} x.
Arguments pickle_invK {T} n : rename.
#[short(type="subCountType")]
HB.structure Definition SubCountable T (P : pred T) :=
{ sT of Countable sT & isSub T P sT}.
Section TagCountType.
Variables (I : countType) (T_ : I -> countType).
Definition pickle_tagged (u : {i : I & T_ i}) :=
CodeSeq.code [:: pickle (tag u); pickle (tagged u)].
Definition unpickle_tagged s :=
if CodeSeq.decode s is [:: ni; nx] then
obind (fun i => omap (@Tagged I i T_) (unpickle nx)) (unpickle ni)
else None.
Lemma pickle_taggedK : pcancel pickle_tagged unpickle_tagged.
Proof.
by case=> i x; rewrite /unpickle_tagged CodeSeq.codeK /= pickleK /= pickleK.
Qed.
HB.instance Definition _ :=
Choice_isCountable.Build {i : I & T_ i} pickle_taggedK.
End TagCountType.
(* The remaining instances for standard datatypes. *)
Section CountableDataTypes.
Implicit Type T : countType.
Lemma nat_pickleK : pcancel id (@Some nat). Proof. by []. Qed.
HB.instance Definition _ := Choice_isCountable.Build nat nat_pickleK.
HB.instance Definition _ := Countable.copy bool (can_type oddb).
HB.instance Definition _ := Countable.on bitseq.
HB.instance Definition _ := Countable.copy unit (can_type bool_of_unitK).
HB.instance Definition _ := Countable.copy void
(pcan_type (of_voidK unit)).
HB.instance Definition _ T := Countable.copy (option T)
(can_type (@seq_of_optK T)).
HB.instance Definition _ T (P : pred T) := [Countable of {x | P x} by <:].
HB.instance Definition _ T1 T2 :=
Countable.copy (T1 * T2)%type (can_type (@tag_of_pairK T1 T2)).
HB.instance Definition _ (T1 T2 : countType) :=
Countable.copy (T1 + T2)%type (pcan_type (@opair_of_sumK T1 T2)).
HB.instance Definition _ T := Countable.copy (GenTree.tree T)
(pcan_type (GenTree.codeK T)).
End CountableDataTypes.
|
Order.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 Mathlib.Algebra.Order.Archimedean.Basic
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Topology.Algebra.InfiniteSum.NatInt
import Mathlib.Topology.Algebra.Order.Field
import Mathlib.Topology.Order.MonotoneConvergence
/-!
# Infinite sum or product in an order
This file provides lemmas about the interaction of infinite sums and products and order operations.
-/
open Finset Filter Function
variable {ι κ α : Type*}
section Preorder
variable [Preorder α] [CommMonoid α] [TopologicalSpace α] {a c : α} {f : ι → α}
@[to_additive]
lemma hasProd_le_of_prod_le [ClosedIicTopology α]
(hf : HasProd f a) (h : ∀ s, ∏ i ∈ s, f i ≤ c) : a ≤ c :=
le_of_tendsto' hf h
@[to_additive]
theorem le_hasProd_of_le_prod [ClosedIciTopology α]
(hf : HasProd f a) (h : ∀ s, c ≤ ∏ i ∈ s, f i) : c ≤ a :=
ge_of_tendsto' hf h
@[to_additive]
protected theorem Multipliable.tprod_le_of_prod_range_le [ClosedIicTopology α] {f : ℕ → α}
(hf : Multipliable f) (h : ∀ n, ∏ i ∈ range n, f i ≤ c) : ∏' n, f n ≤ c :=
le_of_tendsto' hf.hasProd.tendsto_prod_nat h
@[deprecated (since := "2025-04-12")] alias tsum_le_of_sum_range_le :=
Summable.tsum_le_of_sum_range_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_of_prod_range_le :=
Multipliable.tprod_le_of_prod_range_le
end Preorder
section OrderedCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
[TopologicalSpace α] [OrderClosedTopology α] {f g : ι → α}
{a a₁ a₂ : α}
@[to_additive]
theorem hasProd_le (h : ∀ i, f i ≤ g i) (hf : HasProd f a₁) (hg : HasProd g a₂) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto' hf hg fun _ ↦ prod_le_prod' fun i _ ↦ h i
@[to_additive]
theorem hasProd_mono (hf : HasProd f a₁) (hg : HasProd g a₂) (h : f ≤ g) : a₁ ≤ a₂ :=
hasProd_le h hf hg
@[to_additive]
theorem hasProd_le_inj {g : κ → α} (e : ι → κ) (he : Injective e)
(hs : ∀ c, c ∉ Set.range e → 1 ≤ g c) (h : ∀ i, f i ≤ g (e i)) (hf : HasProd f a₁)
(hg : HasProd g a₂) : a₁ ≤ a₂ := by
rw [← hasProd_extend_one he] at hf
refine hasProd_le (fun c ↦ ?_) hf hg
obtain ⟨i, rfl⟩ | h := em (c ∈ Set.range e)
· rw [he.extend_apply]
exact h _
· rw [extend_apply' _ _ _ h]
exact hs _ h
@[to_additive]
protected theorem Multipliable.tprod_le_tprod_of_inj {g : κ → α} (e : ι → κ) (he : Injective e)
(hs : ∀ c, c ∉ Set.range e → 1 ≤ g c) (h : ∀ i, f i ≤ g (e i)) (hf : Multipliable f)
(hg : Multipliable g) : tprod f ≤ tprod g :=
hasProd_le_inj _ he hs h hf.hasProd hg.hasProd
@[deprecated (since := "2025-04-12")] alias tsum_le_tsum_of_inj := Summable.tsum_le_tsum_of_inj
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_tprod_of_inj :=
Multipliable.tprod_le_tprod_of_inj
@[to_additive]
protected lemma Multipliable.tprod_subtype_le {κ γ : Type*} [CommGroup γ] [PartialOrder γ]
[IsOrderedMonoid γ] [UniformSpace γ] [IsUniformGroup γ] [OrderClosedTopology γ]
[CompleteSpace γ] (f : κ → γ) (β : Set κ) (h : ∀ a : κ, 1 ≤ f a) (hf : Multipliable f) :
(∏' (b : β), f b) ≤ (∏' (a : κ), f a) := by
apply Multipliable.tprod_le_tprod_of_inj _
(Subtype.coe_injective)
(by simp only [Subtype.range_coe_subtype, Set.setOf_mem_eq, h, implies_true])
(by simp only [le_refl, implies_true])
(by apply hf.subtype)
apply hf
@[deprecated (since := "2025-04-12")] alias tsum_subtype_le := Summable.tsum_subtype_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_subtype_le :=
Multipliable.tprod_subtype_le
@[to_additive]
theorem prod_le_hasProd (s : Finset ι) (hs : ∀ i, i ∉ s → 1 ≤ f i) (hf : HasProd f a) :
∏ i ∈ s, f i ≤ a :=
ge_of_tendsto hf (eventually_atTop.2
⟨s, fun _t hst ↦ prod_le_prod_of_subset_of_one_le' hst fun i _ hbs ↦ hs i hbs⟩)
@[to_additive]
theorem isLUB_hasProd (h : ∀ i, 1 ≤ f i) (hf : HasProd f a) :
IsLUB (Set.range fun s ↦ ∏ i ∈ s, f i) a := by
classical
exact isLUB_of_tendsto_atTop (Finset.prod_mono_set_of_one_le' h) hf
@[to_additive]
theorem le_hasProd (hf : HasProd f a) (i : ι) (hb : ∀ j, j ≠ i → 1 ≤ f j) : f i ≤ a :=
calc
f i = ∏ i ∈ {i}, f i := by rw [prod_singleton]
_ ≤ a := prod_le_hasProd _ (by simpa) hf
@[to_additive]
theorem lt_hasProd [MulRightStrictMono α] (hf : HasProd f a) (i : ι)
(hi : ∀ (j : ι), j ≠ i → 1 ≤ f j) (j : ι) (hij : j ≠ i) (hj : 1 < f j) :
f i < a := by
classical
calc
f i < f j * f i := lt_mul_of_one_lt_left' (f i) hj
_ = ∏ k ∈ {j, i}, f k := by rw [Finset.prod_pair hij]
_ ≤ a := prod_le_hasProd _ (fun k hk ↦ hi k (hk ∘ mem_insert_of_mem ∘ mem_singleton.mpr)) hf
@[to_additive]
protected theorem Multipliable.prod_le_tprod {f : ι → α} (s : Finset ι) (hs : ∀ i, i ∉ s → 1 ≤ f i)
(hf : Multipliable f) : ∏ i ∈ s, f i ≤ ∏' i, f i :=
prod_le_hasProd s hs hf.hasProd
@[deprecated (since := "2025-04-12")] alias sum_le_tsum := Summable.sum_le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias prod_le_tprod :=
Multipliable.prod_le_tprod
@[to_additive]
protected theorem Multipliable.le_tprod (hf : Multipliable f) (i : ι) (hb : ∀ j, j ≠ i → 1 ≤ f j) :
f i ≤ ∏' i, f i :=
le_hasProd hf.hasProd i hb
@[deprecated (since := "2025-04-12")] alias le_tsum := Summable.le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias le_tprod := Multipliable.le_tprod
@[to_additive (attr := gcongr)]
protected theorem Multipliable.tprod_le_tprod (h : ∀ i, f i ≤ g i) (hf : Multipliable f)
(hg : Multipliable g) : ∏' i, f i ≤ ∏' i, g i :=
hasProd_le h hf.hasProd hg.hasProd
@[deprecated (since := "2025-04-12")] alias tsum_le_tsum := Summable.tsum_le_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_tprod :=
Multipliable.tprod_le_tprod
@[to_additive (attr := mono)]
protected theorem Multipliable.tprod_mono (hf : Multipliable f) (hg : Multipliable g) (h : f ≤ g) :
∏' n, f n ≤ ∏' n, g n :=
hf.tprod_le_tprod h hg
@[deprecated (since := "2025-04-12")] alias tsum_mono := Summable.tsum_mono
@[to_additive existing (attr := mono), deprecated (since := "2025-04-12")] alias tprod_mono :=
Multipliable.tprod_mono
omit [IsOrderedMonoid α] in
@[to_additive]
protected theorem Multipliable.tprod_le_of_prod_le (hf : Multipliable f)
(h : ∀ s, ∏ i ∈ s, f i ≤ a₂) : ∏' i, f i ≤ a₂ :=
hasProd_le_of_prod_le hf.hasProd h
@[deprecated (since := "2025-04-12")] alias tsum_le_of_sum_le := Summable.tsum_le_of_sum_le
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_le_of_prod_le :=
Multipliable.tprod_le_of_prod_le
omit [IsOrderedMonoid α] in
@[to_additive]
theorem tprod_le_of_prod_le' (ha₂ : 1 ≤ a₂) (h : ∀ s, ∏ i ∈ s, f i ≤ a₂) : ∏' i, f i ≤ a₂ := by
by_cases hf : Multipliable f
· exact hf.tprod_le_of_prod_le h
· rw [tprod_eq_one_of_not_multipliable hf]
exact ha₂
@[to_additive]
theorem HasProd.one_le (h : ∀ i, 1 ≤ g i) (ha : HasProd g a) : 1 ≤ a :=
hasProd_le h hasProd_one ha
@[to_additive]
theorem HasProd.le_one (h : ∀ i, g i ≤ 1) (ha : HasProd g a) : a ≤ 1 :=
hasProd_le h ha hasProd_one
@[to_additive tsum_nonneg]
theorem one_le_tprod (h : ∀ i, 1 ≤ g i) : 1 ≤ ∏' i, g i := by
by_cases hg : Multipliable g
· exact hg.hasProd.one_le h
· rw [tprod_eq_one_of_not_multipliable hg]
@[to_additive]
theorem tprod_le_one (h : ∀ i, f i ≤ 1) : ∏' i, f i ≤ 1 := by
by_cases hf : Multipliable f
· exact hf.hasProd.le_one h
· rw [tprod_eq_one_of_not_multipliable hf]
@[to_additive]
theorem hasProd_one_iff_of_one_le (hf : ∀ i, 1 ≤ f i) : HasProd f 1 ↔ f = 1 := by
refine ⟨fun hf' ↦ ?_, ?_⟩
· ext i
exact (hf i).antisymm' (le_hasProd hf' _ fun j _ ↦ hf j)
· rintro rfl
exact hasProd_one
end OrderedCommMonoid
section OrderedCommGroup
variable [CommGroup α] [PartialOrder α] [IsOrderedMonoid α]
[TopologicalSpace α] [IsTopologicalGroup α]
[OrderClosedTopology α] {f g : ι → α} {a₁ a₂ : α} {i : ι}
@[to_additive]
theorem hasProd_lt (h : f ≤ g) (hi : f i < g i) (hf : HasProd f a₁) (hg : HasProd g a₂) :
a₁ < a₂ := by
classical
have : update f i 1 ≤ update g i 1 := update_le_update_iff.mpr ⟨rfl.le, fun i _ ↦ h i⟩
have : 1 / f i * a₁ ≤ 1 / g i * a₂ := hasProd_le this (hf.update i 1) (hg.update i 1)
simpa only [one_div, mul_inv_cancel_left] using mul_lt_mul_of_lt_of_le hi this
@[to_additive (attr := mono)]
theorem hasProd_strict_mono (hf : HasProd f a₁) (hg : HasProd g a₂) (h : f < g) : a₁ < a₂ :=
let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h
hasProd_lt hle hi hf hg
@[to_additive]
protected theorem Multipliable.tprod_lt_tprod (h : f ≤ g) (hi : f i < g i) (hf : Multipliable f)
(hg : Multipliable g) : ∏' n, f n < ∏' n, g n :=
hasProd_lt h hi hf.hasProd hg.hasProd
@[deprecated (since := "2025-04-12")] alias tsum_lt_tsum := Summable.tsum_lt_tsum
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_lt_tprod :=
Multipliable.tprod_lt_tprod
@[to_additive (attr := mono)]
protected theorem Multipliable.tprod_strict_mono (hf : Multipliable f) (hg : Multipliable g)
(h : f < g) : ∏' n, f n < ∏' n, g n :=
let ⟨hle, _i, hi⟩ := Pi.lt_def.mp h
hf.tprod_lt_tprod hle hi hg
@[deprecated (since := "2025-04-12")] alias tsum_strict_mono := Summable.tsum_strict_mono
@[to_additive existing (attr := mono), deprecated (since := "2025-04-12")] alias
tprod_strict_mono := Multipliable.tprod_strict_mono
@[to_additive Summable.tsum_pos]
protected theorem Multipliable.one_lt_tprod (hsum : Multipliable g) (hg : ∀ i, 1 ≤ g i) (i : ι)
(hi : 1 < g i) : 1 < ∏' i, g i := by
rw [← tprod_one]
exact multipliable_one.tprod_lt_tprod hg hi hsum
@[deprecated (since := "2025-04-12")] alias tsum_pos := Summable.tsum_pos
@[to_additive existing tsum_pos, deprecated (since := "2025-04-12")] alias one_lt_tprod :=
Multipliable.one_lt_tprod
end OrderedCommGroup
section CanonicallyOrderedMul
variable [CommMonoid α] [PartialOrder α] [IsOrderedMonoid α]
[CanonicallyOrderedMul α] [TopologicalSpace α]
[OrderClosedTopology α] {f : ι → α} {a : α}
@[to_additive]
theorem le_hasProd' (hf : HasProd f a) (i : ι) : f i ≤ a :=
le_hasProd hf i fun _ _ ↦ one_le _
@[to_additive]
protected theorem Multipliable.le_tprod' (hf : Multipliable f) (i : ι) : f i ≤ ∏' i, f i :=
hf.le_tprod i fun _ _ ↦ one_le _
@[deprecated (since := "2025-04-12")] alias le_tsum' := Summable.le_tsum'
@[to_additive existing, deprecated (since := "2025-04-12")] alias le_tprod' :=
Multipliable.le_tprod'
@[to_additive]
theorem hasProd_one_iff : HasProd f 1 ↔ ∀ x, f x = 1 :=
(hasProd_one_iff_of_one_le fun _ ↦ one_le _).trans funext_iff
@[to_additive]
protected theorem Multipliable.tprod_eq_one_iff (hf : Multipliable f) :
∏' i, f i = 1 ↔ ∀ x, f x = 1 := by
rw [← hasProd_one_iff, hf.hasProd_iff]
@[deprecated (since := "2025-04-12")] alias tsum_eq_zero_iff := Summable.tsum_eq_zero_iff
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_eq_one_iff :=
Multipliable.tprod_eq_one_iff
@[to_additive]
protected theorem Multipliable.tprod_ne_one_iff (hf : Multipliable f) :
∏' i, f i ≠ 1 ↔ ∃ x, f x ≠ 1 := by
rw [Ne, hf.tprod_eq_one_iff, not_forall]
@[deprecated (since := "2025-04-12")] alias tsum_ne_zero_iff := Summable.tsum_ne_zero_iff
@[to_additive existing, deprecated (since := "2025-04-12")] alias tprod_ne_one_iff :=
Multipliable.tprod_ne_one_iff
omit [IsOrderedMonoid α] in
@[to_additive]
theorem isLUB_hasProd' (hf : HasProd f a) : IsLUB (Set.range fun s ↦ ∏ i ∈ s, f i) a := by
classical
exact isLUB_of_tendsto_atTop (Finset.prod_mono_set' f) hf
end CanonicallyOrderedMul
section LinearOrder
/-!
For infinite sums taking values in a linearly ordered monoid, the existence of a least upper
bound for the finite sums is a criterion for summability.
This criterion is useful when applied in a linearly ordered monoid which is also a complete or
conditionally complete linear order, such as `ℝ`, `ℝ≥0`, `ℝ≥0∞`, because it is then easy to check
the existence of a least upper bound.
-/
@[to_additive]
theorem hasProd_of_isLUB_of_one_le [CommMonoid α] [LinearOrder α] [IsOrderedMonoid α]
[TopologicalSpace α]
[OrderTopology α] {f : ι → α} (i : α) (h : ∀ i, 1 ≤ f i)
(hf : IsLUB (Set.range fun s ↦ ∏ i ∈ s, f i) i) : HasProd f i :=
tendsto_atTop_isLUB (Finset.prod_mono_set_of_one_le' h) hf
@[to_additive]
theorem hasProd_of_isLUB [CommMonoid α] [LinearOrder α]
[CanonicallyOrderedMul α] [TopologicalSpace α]
[OrderTopology α] {f : ι → α} (b : α) (hf : IsLUB (Set.range fun s ↦ ∏ i ∈ s, f i) b) :
HasProd f b :=
tendsto_atTop_isLUB (Finset.prod_mono_set' f) hf
@[to_additive]
theorem multipliable_mabs_iff [CommGroup α] [LinearOrder α] [IsOrderedMonoid α]
[UniformSpace α] [IsUniformGroup α]
[CompleteSpace α] {f : ι → α} : (Multipliable fun x ↦ mabs (f x)) ↔ Multipliable f :=
let s := { x | 1 ≤ f x }
have h1 : ∀ x : s, mabs (f x) = f x := fun x ↦ mabs_of_one_le x.2
have h2 : ∀ x : ↑sᶜ, mabs (f x) = (f x)⁻¹ := fun x ↦ mabs_of_lt_one (not_le.1 x.2)
calc (Multipliable fun x ↦ mabs (f x)) ↔
(Multipliable fun x : s ↦ mabs (f x)) ∧ Multipliable fun x : ↑sᶜ ↦ mabs (f x) :=
multipliable_subtype_and_compl.symm
_ ↔ (Multipliable fun x : s ↦ f x) ∧ Multipliable fun x : ↑sᶜ ↦ (f x)⁻¹ := by simp only [h1, h2]
_ ↔ Multipliable f := by simp only [multipliable_inv_iff, multipliable_subtype_and_compl]
alias ⟨Summable.of_abs, Summable.abs⟩ := summable_abs_iff
theorem Finite.of_summable_const [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]
[TopologicalSpace α] [Archimedean α]
[OrderClosedTopology α] {b : α} (hb : 0 < b) (hf : Summable fun _ : ι ↦ b) :
Finite ι := by
have H : ∀ s : Finset ι, #s • b ≤ ∑' _ : ι, b := fun s ↦ by
simpa using sum_le_hasSum s (fun a _ ↦ hb.le) hf.hasSum
obtain ⟨n, hn⟩ := Archimedean.arch (∑' _ : ι, b) hb
have : ∀ s : Finset ι, #s ≤ n := fun s ↦ by
simpa [nsmul_le_nsmul_iff_left hb] using (H s).trans hn
have : Fintype ι := fintypeOfFinsetCardLe n this
infer_instance
theorem Set.Finite.of_summable_const [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α]
[TopologicalSpace α]
[Archimedean α] [OrderClosedTopology α] {b : α} (hb : 0 < b) (hf : Summable fun _ : ι ↦ b) :
(Set.univ : Set ι).Finite :=
finite_univ_iff.2 <| .of_summable_const hb hf
end LinearOrder
section LinearOrderedCommRing
variable [CommRing α] [LinearOrder α] [IsStrictOrderedRing α]
[TopologicalSpace α] [OrderTopology α] {f : ι → α} {x : α}
nonrec theorem HasProd.abs (hfx : HasProd f x) : HasProd (|f ·|) |x| := by
simpa only [HasProd, ← abs_prod] using hfx.abs
theorem Multipliable.abs (hf : Multipliable f) : Multipliable (|f ·|) :=
let ⟨x, hx⟩ := hf; ⟨|x|, hx.abs⟩
protected theorem Multipliable.abs_tprod (hf : Multipliable f) : |∏' i, f i| = ∏' i, |f i| :=
hf.hasProd.abs.tprod_eq.symm
@[deprecated (since := "2025-04-12")] alias abs_tprod := Multipliable.abs_tprod
end LinearOrderedCommRing
theorem Summable.tendsto_atTop_of_pos [Field α] [LinearOrder α] [IsStrictOrderedRing α]
[TopologicalSpace α] [OrderTopology α]
{f : ℕ → α} (hf : Summable f⁻¹) (hf' : ∀ n, 0 < f n) : Tendsto f atTop atTop :=
inv_inv f ▸ Filter.Tendsto.inv_tendsto_nhdsGT_zero <|
tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ hf.tendsto_atTop_zero <|
Eventually.of_forall fun _ ↦ inv_pos.2 (hf' _)
namespace Mathlib.Meta.Positivity
open Qq Lean Meta Finset
attribute [local instance] monadLiftOptionMetaM in
/-- Positivity extension for infinite sums.
This extension only proves non-negativity, strict positivity is more delicate for infinite sums and
requires more assumptions. -/
@[positivity tsum _]
def evalTsum : PositivityExt where eval {u α} zα pα e := do
match e with
| ~q(@tsum _ $instCommMonoid $instTopSpace $ι $f) =>
lambdaBoundedTelescope f 1 fun args (body : Q($α)) => do
let #[(i : Q($ι))] := args | failure
let rbody ← core zα pα body
let pbody ← rbody.toNonneg
let pr : Q(∀ i, 0 ≤ $f i) ← mkLambdaFVars #[i] pbody
let mα' ← synthInstanceQ q(AddCommMonoid $α)
let oα' ← synthInstanceQ q(PartialOrder $α)
let pα' ← synthInstanceQ q(IsOrderedAddMonoid $α)
let instOrderClosed ← synthInstanceQ q(OrderClosedTopology $α)
assertInstancesCommute
return .nonnegative q(@tsum_nonneg $ι $α $mα' $oα' $pα' $instTopSpace $instOrderClosed $f $pr)
| _ => throwError "not tsum"
end Mathlib.Meta.Positivity
|
Bits.lean
|
/-
Copyright (c) 2022 Praneeth Kolichala. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Praneeth Kolichala
-/
import Mathlib.Data.Nat.Basic
import Mathlib.Data.Nat.BinaryRec
import Mathlib.Data.List.Defs
import Mathlib.Tactic.Convert
import Mathlib.Tactic.GeneralizeProofs
import Mathlib.Tactic.Says
/-!
# Additional properties of binary recursion on `Nat`
This file documents additional properties of binary recursion,
which allows us to more easily work with operations which do depend
on the number of leading zeros in the binary representation of `n`.
For example, we can more easily work with `Nat.bits` and `Nat.size`.
See also: `Nat.bitwise`, `Nat.pow` (for various lemmas about `size` and `shiftLeft`/`shiftRight`),
and `Nat.digits`.
-/
assert_not_exists Monoid
-- Once we're in the `Nat` namespace, `xor` will inconveniently resolve to `Nat.xor`.
/-- `bxor` denotes the `xor` function i.e. the exclusive-or function on type `Bool`. -/
local notation "bxor" => xor
namespace Nat
universe u
variable {m n : ℕ}
/-- `boddDiv2 n` returns a 2-tuple of type `(Bool, Nat)` where the `Bool` value indicates whether
`n` is odd or not and the `Nat` value returns `⌊n/2⌋` -/
def boddDiv2 : ℕ → Bool × ℕ
| 0 => (false, 0)
| succ n =>
match boddDiv2 n with
| (false, m) => (true, m)
| (true, m) => (false, succ m)
/-- `div2 n = ⌊n/2⌋` the greatest integer smaller than `n/2` -/
def div2 (n : ℕ) : ℕ := (boddDiv2 n).2
/-- `bodd n` returns `true` if `n` is odd -/
def bodd (n : ℕ) : Bool := (boddDiv2 n).1
@[simp] lemma bodd_zero : bodd 0 = false := rfl
@[simp] lemma bodd_one : bodd 1 = true := rfl
lemma bodd_two : bodd 2 = false := rfl
@[simp]
lemma bodd_succ (n : ℕ) : bodd (succ n) = not (bodd n) := by
simp only [bodd, boddDiv2]
let ⟨b,m⟩ := boddDiv2 n
cases b <;> rfl
@[simp]
lemma bodd_add (m n : ℕ) : bodd (m + n) = bxor (bodd m) (bodd n) := by
induction n
case zero => simp
case succ n ih => simp [← Nat.add_assoc, ih]
@[simp]
lemma bodd_mul (m n : ℕ) : bodd (m * n) = (bodd m && bodd n) := by
induction n with
| zero => simp
| succ n IH =>
simp only [mul_succ, bodd_add, IH, bodd_succ]
cases bodd m <;> cases bodd n <;> rfl
lemma mod_two_of_bodd (n : ℕ) : n % 2 = (bodd n).toNat := by
have := congr_arg bodd (mod_add_div n 2)
simp? [not] at this says
simp only [bodd_add, bodd_mul, bodd_succ, not, bodd_zero, Bool.false_and, Bool.bne_false]
at this
have _ : ∀ b, and false b = false := by
intro b
cases b <;> rfl
have _ : ∀ b, bxor b false = b := by
intro b
cases b <;> rfl
rw [← this]
rcases mod_two_eq_zero_or_one n with h | h <;> rw [h] <;> rfl
@[simp] lemma div2_zero : div2 0 = 0 := rfl
@[simp] lemma div2_one : div2 1 = 0 := rfl
lemma div2_two : div2 2 = 1 := rfl
@[simp]
lemma div2_succ (n : ℕ) : div2 (n + 1) = cond (bodd n) (succ (div2 n)) (div2 n) := by
simp only [bodd, boddDiv2, div2]
rcases boddDiv2 n with ⟨_ |_ , _⟩ <;> simp
attribute [local simp] Nat.add_comm Nat.add_assoc Nat.add_left_comm Nat.mul_comm Nat.mul_assoc
lemma bodd_add_div2 : ∀ n, (bodd n).toNat + 2 * div2 n = n
| 0 => rfl
| succ n => by
simp only [bodd_succ, div2_succ, Nat.mul_comm]
refine Eq.trans ?_ (congr_arg succ (bodd_add_div2 n))
cases bodd n
· simp
· simp; omega
lemma div2_val (n) : div2 n = n / 2 := by
refine Nat.eq_of_mul_eq_mul_left (by decide)
(Nat.add_left_cancel (Eq.trans ?_ (Nat.mod_add_div n 2).symm))
rw [mod_two_of_bodd, bodd_add_div2]
lemma bit_decomp (n : Nat) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans <| (Nat.add_comm _ _).trans <| bodd_add_div2 _
lemma bit_zero : bit false 0 = 0 :=
rfl
/-- `shiftLeft' b m n` performs a left shift of `m` `n` times
and adds the bit `b` as the least significant bit each time.
Returns the corresponding natural number -/
def shiftLeft' (b : Bool) (m : ℕ) : ℕ → ℕ
| 0 => m
| n + 1 => bit b (shiftLeft' b m n)
@[simp]
lemma shiftLeft'_false : ∀ n, shiftLeft' false m n = m <<< n
| 0 => rfl
| n + 1 => by
have : 2 * (m * 2^n) = 2^(n+1)*m := by
rw [Nat.mul_comm, Nat.mul_assoc, ← Nat.pow_succ]; simp
simp [shiftLeft_eq, shiftLeft', bit_val, shiftLeft'_false, this]
/-- Lean takes the unprimed name for `Nat.shiftLeft_eq m n : m <<< n = m * 2 ^ n`. -/
@[simp] lemma shiftLeft_eq' (m n : Nat) : shiftLeft m n = m <<< n := rfl
@[simp] lemma shiftRight_eq (m n : Nat) : shiftRight m n = m >>> n := rfl
lemma binaryRec_decreasing (h : n ≠ 0) : div2 n < n := by
rw [div2_val]
apply (div_lt_iff_lt_mul <| succ_pos 1).2
have := Nat.mul_lt_mul_of_pos_left (lt_succ_self 1)
(lt_of_le_of_ne n.zero_le h.symm)
rwa [Nat.mul_one] at this
/-- `size n` : Returns the size of a natural number in
bits i.e. the length of its binary representation -/
def size : ℕ → ℕ :=
binaryRec 0 fun _ _ => succ
/-- `bits n` returns a list of Bools which correspond to the binary representation of n, where
the head of the list represents the least significant bit -/
def bits : ℕ → List Bool :=
binaryRec [] fun b _ IH => b :: IH
/-- `ldiff a b` performs bitwise set difference. For each corresponding
pair of bits taken as booleans, say `aᵢ` and `bᵢ`, it applies the
boolean operation `aᵢ ∧ ¬bᵢ` to obtain the `iᵗʰ` bit of the result. -/
def ldiff : ℕ → ℕ → ℕ :=
bitwise fun a b => a && not b
/-! bitwise ops -/
lemma bodd_bit (b n) : bodd (bit b n) = b := by
rw [bit_val]
simp only [Nat.mul_comm, Nat.add_comm, bodd_add, bodd_mul, bodd_succ, bodd_zero, Bool.not_false,
Bool.not_true, Bool.and_false, Bool.xor_false]
cases b <;> cases bodd n <;> rfl
lemma div2_bit (b n) : div2 (bit b n) = n := by
rw [bit_val, div2_val, Nat.add_comm, add_mul_div_left, div_eq_of_lt, Nat.zero_add]
<;> cases b
<;> decide
lemma shiftLeft'_add (b m n) : ∀ k, shiftLeft' b m (n + k) = shiftLeft' b (shiftLeft' b m n) k
| 0 => rfl
| k + 1 => congr_arg (bit b) (shiftLeft'_add b m n k)
lemma shiftLeft'_sub (b m) : ∀ {n k}, k ≤ n → shiftLeft' b m (n - k) = (shiftLeft' b m n) >>> k
| _, 0, _ => rfl
| n + 1, k + 1, h => by
rw [succ_sub_succ_eq_sub, shiftLeft', Nat.add_comm, shiftRight_add]
simp only [shiftLeft'_sub, Nat.le_of_succ_le_succ h, shiftRight_succ, shiftRight_zero]
simp [← div2_val, div2_bit]
lemma shiftLeft_sub : ∀ (m : Nat) {n k}, k ≤ n → m <<< (n - k) = (m <<< n) >>> k :=
fun _ _ _ hk => by simp only [← shiftLeft'_false, shiftLeft'_sub false _ hk]
lemma bodd_eq_one_and_ne_zero : ∀ n, bodd n = (1 &&& n != 0)
| 0 => rfl
| 1 => rfl
| n + 2 => by simpa using bodd_eq_one_and_ne_zero n
lemma testBit_bit_succ (m b n) : testBit (bit b n) (succ m) = testBit n m := by
have : bodd (((bit b n) >>> 1) >>> m) = bodd (n >>> m) := by
simp only [shiftRight_eq_div_pow]
simp [← div2_val, div2_bit]
rw [← shiftRight_add, Nat.add_comm] at this
simp only [bodd_eq_one_and_ne_zero] at this
exact this
/-! ### `boddDiv2_eq` and `bodd` -/
@[simp]
theorem boddDiv2_eq (n : ℕ) : boddDiv2 n = (bodd n, div2 n) := rfl
@[simp]
theorem div2_bit0 (n) : div2 (2 * n) = n :=
div2_bit false n
-- simp can prove this
theorem div2_bit1 (n) : div2 (2 * n + 1) = n :=
div2_bit true n
/-! ### `bit0` and `bit1` -/
theorem bit_add : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit false n + bit b m
| true, _, _ => by dsimp [bit]; omega
| false, _, _ => by dsimp [bit]; omega
theorem bit_add' : ∀ (b : Bool) (n m : ℕ), bit b (n + m) = bit b n + bit false m
| true, _, _ => by dsimp [bit]; omega
| false, _, _ => by dsimp [bit]; omega
theorem bit_ne_zero (b) {n} (h : n ≠ 0) : bit b n ≠ 0 := by
cases b <;> dsimp [bit] <;> omega
@[simp]
theorem bitCasesOn_bit0 {motive : ℕ → Sort u} (H : ∀ b n, motive (bit b n)) (n : ℕ) :
bitCasesOn (2 * n) H = H false n :=
bitCasesOn_bit H false n
@[simp]
theorem bitCasesOn_bit1 {motive : ℕ → Sort u} (H : ∀ b n, motive (bit b n)) (n : ℕ) :
bitCasesOn (2 * n + 1) H = H true n :=
bitCasesOn_bit H true n
theorem bit_cases_on_injective {motive : ℕ → Sort u} :
Function.Injective fun H : ∀ b n, motive (bit b n) => fun n => bitCasesOn n H := by
intro H₁ H₂ h
ext b n
simpa only [bitCasesOn_bit] using congr_fun h (bit b n)
@[simp]
theorem bit_cases_on_inj {motive : ℕ → Sort u} (H₁ H₂ : ∀ b n, motive (bit b n)) :
((fun n => bitCasesOn n H₁) = fun n => bitCasesOn n H₂) ↔ H₁ = H₂ :=
bit_cases_on_injective.eq_iff
lemma bit_le : ∀ (b : Bool) {m n : ℕ}, m ≤ n → bit b m ≤ bit b n
| true, _, _, h => by dsimp [bit]; omega
| false, _, _, h => by dsimp [bit]; omega
lemma bit_lt_bit (a b) (h : m < n) : bit a m < bit b n := calc
bit a m < 2 * n := by cases a <;> dsimp [bit] <;> omega
_ ≤ bit b n := by cases b <;> dsimp [bit] <;> omega
@[simp]
theorem zero_bits : bits 0 = [] := by simp [Nat.bits]
@[simp]
theorem bits_append_bit (n : ℕ) (b : Bool) (hn : n = 0 → b = true) :
(bit b n).bits = b :: n.bits := by
rw [Nat.bits, Nat.bits, binaryRec_eq]
simpa
@[simp]
theorem bit0_bits (n : ℕ) (hn : n ≠ 0) : (2 * n).bits = false :: n.bits :=
bits_append_bit n false fun hn' => absurd hn' hn
@[simp]
theorem bit1_bits (n : ℕ) : (2 * n + 1).bits = true :: n.bits :=
bits_append_bit n true fun _ => rfl
@[simp]
theorem one_bits : Nat.bits 1 = [true] := by
convert bit1_bits 0
simp
-- TODO Find somewhere this can live.
-- example : bits 3423 = [true, true, true, true, true, false, true, false, true, false, true, true]
-- := by norm_num
theorem bodd_eq_bits_head (n : ℕ) : n.bodd = n.bits.headI := by
induction n using Nat.binaryRec' with
| z => simp
| f _ _ h _ => simp [bodd_bit, bits_append_bit _ _ h]
theorem div2_bits_eq_tail (n : ℕ) : n.div2.bits = n.bits.tail := by
induction n using Nat.binaryRec' with
| z => simp
| f _ _ h _ => simp [div2_bit, bits_append_bit _ _ h]
end Nat
|
EpiMono.lean
|
/-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Kim Morrison
-/
import Mathlib.CategoryTheory.Opposites
import Mathlib.CategoryTheory.Groupoid
/-!
# Facts about epimorphisms and monomorphisms.
The definitions of `Epi` and `Mono` are in `CategoryTheory.Category`,
since they are used by some lemmas for `Iso`, which is used everywhere.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C]
instance unop_mono_of_epi {A B : Cᵒᵖ} (f : A ⟶ B) [Epi f] : Mono f.unop :=
⟨fun _ _ eq => Quiver.Hom.op_inj ((cancel_epi f).1 (Quiver.Hom.unop_inj eq))⟩
instance unop_epi_of_mono {A B : Cᵒᵖ} (f : A ⟶ B) [Mono f] : Epi f.unop :=
⟨fun _ _ eq => Quiver.Hom.op_inj ((cancel_mono f).1 (Quiver.Hom.unop_inj eq))⟩
instance op_mono_of_epi {A B : C} (f : A ⟶ B) [Epi f] : Mono f.op :=
⟨fun _ _ eq => Quiver.Hom.unop_inj ((cancel_epi f).1 (Quiver.Hom.op_inj eq))⟩
instance op_epi_of_mono {A B : C} (f : A ⟶ B) [Mono f] : Epi f.op :=
⟨fun _ _ eq => Quiver.Hom.unop_inj ((cancel_mono f).1 (Quiver.Hom.op_inj eq))⟩
/-- A split monomorphism is a morphism `f : X ⟶ Y` with a given retraction `retraction f : Y ⟶ X`
such that `f ≫ retraction f = 𝟙 X`.
Every split monomorphism is a monomorphism.
-/
@[ext, aesop apply safe (rule_sets := [CategoryTheory])]
structure SplitMono {X Y : C} (f : X ⟶ Y) where
/-- The map splitting `f` -/
retraction : Y ⟶ X
/-- `f` composed with `retraction` is the identity -/
id : f ≫ retraction = 𝟙 X := by cat_disch
attribute [reassoc (attr := simp)] SplitMono.id
/-- `IsSplitMono f` is the assertion that `f` admits a retraction -/
class IsSplitMono {X Y : C} (f : X ⟶ Y) : Prop where
/-- There is a splitting -/
exists_splitMono : Nonempty (SplitMono f)
/-- A composition of `SplitMono` is a `SplitMono`. -/
@[simps]
def SplitMono.comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (smf : SplitMono f) (smg : SplitMono g) :
SplitMono (f ≫ g) where
retraction := smg.retraction ≫ smf.retraction
/-- A constructor for `IsSplitMono f` taking a `SplitMono f` as an argument -/
theorem IsSplitMono.mk' {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : IsSplitMono f :=
⟨Nonempty.intro sm⟩
/-- A split epimorphism is a morphism `f : X ⟶ Y` with a given section `section_ f : Y ⟶ X`
such that `section_ f ≫ f = 𝟙 Y`.
(Note that `section` is a reserved keyword, so we append an underscore.)
Every split epimorphism is an epimorphism.
-/
@[ext, aesop apply safe (rule_sets := [CategoryTheory])]
structure SplitEpi {X Y : C} (f : X ⟶ Y) where
/-- The map splitting `f` -/
section_ : Y ⟶ X
/-- `section_` composed with `f` is the identity -/
id : section_ ≫ f = 𝟙 Y := by cat_disch
attribute [reassoc (attr := simp)] SplitEpi.id
/-- `IsSplitEpi f` is the assertion that `f` admits a section -/
class IsSplitEpi {X Y : C} (f : X ⟶ Y) : Prop where
/-- There is a splitting -/
exists_splitEpi : Nonempty (SplitEpi f)
/-- A composition of `SplitEpi` is a split `SplitEpi`. -/
@[simps]
def SplitEpi.comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (sef : SplitEpi f) (seg : SplitEpi g) :
SplitEpi (f ≫ g) where
section_ := seg.section_ ≫ sef.section_
/-- A constructor for `IsSplitEpi f` taking a `SplitEpi f` as an argument -/
theorem IsSplitEpi.mk' {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : IsSplitEpi f :=
⟨Nonempty.intro se⟩
/-- The chosen retraction of a split monomorphism. -/
noncomputable def retraction {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : Y ⟶ X :=
hf.exists_splitMono.some.retraction
@[reassoc (attr := simp)]
theorem IsSplitMono.id {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : f ≫ retraction f = 𝟙 X :=
hf.exists_splitMono.some.id
/-- The retraction of a split monomorphism has an obvious section. -/
def SplitMono.splitEpi {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : SplitEpi sm.retraction where
section_ := f
/-- The retraction of a split monomorphism is itself a split epimorphism. -/
instance retraction_isSplitEpi {X Y : C} (f : X ⟶ Y) [IsSplitMono f] :
IsSplitEpi (retraction f) :=
IsSplitEpi.mk' (SplitMono.splitEpi _)
/-- A split mono which is epi is an iso. -/
theorem isIso_of_epi_of_isSplitMono {X Y : C} (f : X ⟶ Y) [IsSplitMono f] [Epi f] : IsIso f :=
⟨⟨retraction f, ⟨by simp, by simp [← cancel_epi f]⟩⟩⟩
/-- The chosen section of a split epimorphism.
(Note that `section` is a reserved keyword, so we append an underscore.)
-/
noncomputable def section_ {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : Y ⟶ X :=
hf.exists_splitEpi.some.section_
@[reassoc (attr := simp)]
theorem IsSplitEpi.id {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : section_ f ≫ f = 𝟙 Y :=
hf.exists_splitEpi.some.id
/-- The section of a split epimorphism has an obvious retraction. -/
def SplitEpi.splitMono {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : SplitMono se.section_ where
retraction := f
/-- The section of a split epimorphism is itself a split monomorphism. -/
instance section_isSplitMono {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsSplitMono (section_ f) :=
IsSplitMono.mk' (SplitEpi.splitMono _)
/-- A split epi which is mono is an iso. -/
theorem isIso_of_mono_of_isSplitEpi {X Y : C} (f : X ⟶ Y) [Mono f] [IsSplitEpi f] : IsIso f :=
⟨⟨section_ f, ⟨by simp [← cancel_mono f], by simp⟩⟩⟩
/-- Every iso is a split mono. -/
instance (priority := 100) IsSplitMono.of_iso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsSplitMono f :=
IsSplitMono.mk' { retraction := inv f }
/-- Every iso is a split epi. -/
instance (priority := 100) IsSplitEpi.of_iso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsSplitEpi f :=
IsSplitEpi.mk' { section_ := inv f }
theorem SplitMono.mono {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : Mono f :=
{ right_cancellation := fun g h w => by replace w := w =≫ sm.retraction; simpa using w }
/-- Every split mono is a mono. -/
instance (priority := 100) IsSplitMono.mono {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : Mono f :=
hf.exists_splitMono.some.mono
theorem SplitEpi.epi {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : Epi f :=
{ left_cancellation := fun g h w => by replace w := se.section_ ≫= w; simpa using w }
/-- Every split epi is an epi. -/
instance (priority := 100) IsSplitEpi.epi {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : Epi f :=
hf.exists_splitEpi.some.epi
instance {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [hf : IsSplitMono f] [hg : IsSplitMono g] :
IsSplitMono (f ≫ g) := IsSplitMono.mk' <| hf.exists_splitMono.some.comp hg.exists_splitMono.some
instance {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} [hf : IsSplitEpi f] [hg : IsSplitEpi g] :
IsSplitEpi (f ≫ g) := IsSplitEpi.mk' <| hf.exists_splitEpi.some.comp hg.exists_splitEpi.some
/-- Every split mono whose retraction is mono is an iso. -/
theorem IsIso.of_mono_retraction' {X Y : C} {f : X ⟶ Y} (hf : SplitMono f) [Mono <| hf.retraction] :
IsIso f :=
⟨⟨hf.retraction, ⟨by simp, (cancel_mono_id <| hf.retraction).mp (by simp)⟩⟩⟩
/-- Every split mono whose retraction is mono is an iso. -/
theorem IsIso.of_mono_retraction {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f]
[hf' : Mono <| retraction f] : IsIso f :=
@IsIso.of_mono_retraction' _ _ _ _ _ hf.exists_splitMono.some hf'
/-- Every split epi whose section is epi is an iso. -/
theorem IsIso.of_epi_section' {X Y : C} {f : X ⟶ Y} (hf : SplitEpi f) [Epi <| hf.section_] :
IsIso f :=
⟨⟨hf.section_, ⟨(cancel_epi_id <| hf.section_).mp (by simp), by simp⟩⟩⟩
/-- Every split epi whose section is epi is an iso. -/
theorem IsIso.of_epi_section {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] [hf' : Epi <| section_ f] :
IsIso f :=
@IsIso.of_epi_section' _ _ _ _ _ hf.exists_splitEpi.some hf'
-- FIXME this has unnecessarily become noncomputable!
/-- A category where every morphism has a `Trunc` retraction is computably a groupoid. -/
noncomputable def Groupoid.ofTruncSplitMono
(all_split_mono : ∀ {X Y : C} (f : X ⟶ Y), Trunc (IsSplitMono f)) : Groupoid.{v₁} C := by
apply Groupoid.ofIsIso
intro X Y f
have ⟨a,_⟩ := Trunc.exists_rep <| all_split_mono f
have ⟨b,_⟩ := Trunc.exists_rep <| all_split_mono <| retraction f
apply IsIso.of_mono_retraction
section
variable (C)
/-- A split mono category is a category in which every monomorphism is split. -/
class SplitMonoCategory : Prop where
/-- All monos are split -/
isSplitMono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], IsSplitMono f
/-- A split epi category is a category in which every epimorphism is split. -/
class SplitEpiCategory : Prop where
/-- All epis are split -/
isSplitEpi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], IsSplitEpi f
end
/-- In a category in which every monomorphism is split, every monomorphism splits. This is not an
instance because it would create an instance loop. -/
theorem isSplitMono_of_mono [SplitMonoCategory C] {X Y : C} (f : X ⟶ Y) [Mono f] : IsSplitMono f :=
SplitMonoCategory.isSplitMono_of_mono _
/-- In a category in which every epimorphism is split, every epimorphism splits. This is not an
instance because it would create an instance loop. -/
theorem isSplitEpi_of_epi [SplitEpiCategory C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsSplitEpi f :=
SplitEpiCategory.isSplitEpi_of_epi _
section
variable {D : Type u₂} [Category.{v₂} D]
/-- Split monomorphisms are also absolute monomorphisms. -/
@[simps]
def SplitMono.map {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) (F : C ⥤ D) : SplitMono (F.map f) where
retraction := F.map sm.retraction
id := by rw [← Functor.map_comp, SplitMono.id, Functor.map_id]
/-- Split epimorphisms are also absolute epimorphisms. -/
@[simps]
def SplitEpi.map {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) (F : C ⥤ D) : SplitEpi (F.map f) where
section_ := F.map se.section_
id := by rw [← Functor.map_comp, SplitEpi.id, Functor.map_id]
instance {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] (F : C ⥤ D) : IsSplitMono (F.map f) :=
IsSplitMono.mk' (hf.exists_splitMono.some.map F)
instance {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] (F : C ⥤ D) : IsSplitEpi (F.map f) :=
IsSplitEpi.mk' (hf.exists_splitEpi.some.map F)
end
section
/-- When `f` is an epimorphism, `f ≫ g` is epic iff `g` is. -/
@[simp]
lemma epi_comp_iff_of_epi {X Y Z : C} (f : X ⟶ Y) [Epi f] (g : Y ⟶ Z) :
Epi (f ≫ g) ↔ Epi g :=
⟨fun _ ↦ epi_of_epi f _, fun _ ↦ inferInstance⟩
/-- When `g` is an isomorphism, `f ≫ g` is epic iff `f` is. -/
@[simp]
lemma epi_comp_iff_of_isIso {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] :
Epi (f ≫ g) ↔ Epi f := by
refine ⟨fun h ↦ ?_, fun h ↦ inferInstance⟩
simpa using (inferInstance : Epi ((f ≫ g) ≫ inv g ))
/-- When `f` is an isomorphism, `f ≫ g` is monic iff `g` is. -/
@[simp]
lemma mono_comp_iff_of_isIso {X Y Z : C} (f : X ⟶ Y) [IsIso f] (g : Y ⟶ Z) :
Mono (f ≫ g) ↔ Mono g := by
refine ⟨fun h ↦ ?_, fun h ↦ inferInstance⟩
simpa using (inferInstance : Mono (inv f ≫ f ≫ g))
/-- When `g` is a monomorphism, `f ≫ g` is monic iff `f` is. -/
@[simp]
lemma mono_comp_iff_of_mono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Mono g] :
Mono (f ≫ g) ↔ Mono f :=
⟨fun _ ↦ mono_of_mono _ g, fun _ ↦ inferInstance⟩
end
end CategoryTheory
|
Defs.lean
|
/-
Copyright (c) 2023 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.NoZeroSMulDivisors.Basic
import Mathlib.Algebra.Order.GroupWithZero.Action.Synonym
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
import Mathlib.Algebra.Order.Ring.Defs
import Mathlib.Order.Hom.Basic
/-!
# Monotonicity of scalar multiplication by positive elements
This file defines typeclasses to reason about monotonicity of the operations
* `b ↦ a • b`, "left scalar multiplication"
* `a ↦ a • b`, "right scalar multiplication"
We use eight typeclasses to encode the various properties we care about for those two operations.
These typeclasses are meant to be mostly internal to this file, to set up each lemma in the
appropriate generality.
Less granular typeclasses like `OrderedAddCommMonoid`, `LinearOrderedField`, `OrderedSMul` should be
enough for most purposes, and the system is set up so that they imply the correct granular
typeclasses here. If those are enough for you, you may stop reading here! Else, beware that what
follows is a bit technical.
## Definitions
In all that follows, `α` and `β` are orders which have a `0` and such that `α` acts on `β` by scalar
multiplication. Note however that we do not use lawfulness of this action in most of the file. Hence
`•` should be considered here as a mostly arbitrary function `α → β → β`.
We use the following four typeclasses to reason about left scalar multiplication (`b ↦ a • b`):
* `PosSMulMono`: If `a ≥ 0`, then `b₁ ≤ b₂` implies `a • b₁ ≤ a • b₂`.
* `PosSMulStrictMono`: If `a > 0`, then `b₁ < b₂` implies `a • b₁ < a • b₂`.
* `PosSMulReflectLT`: If `a ≥ 0`, then `a • b₁ < a • b₂` implies `b₁ < b₂`.
* `PosSMulReflectLE`: If `a > 0`, then `a • b₁ ≤ a • b₂` implies `b₁ ≤ b₂`.
We use the following four typeclasses to reason about right scalar multiplication (`a ↦ a • b`):
* `SMulPosMono`: If `b ≥ 0`, then `a₁ ≤ a₂` implies `a₁ • b ≤ a₂ • b`.
* `SMulPosStrictMono`: If `b > 0`, then `a₁ < a₂` implies `a₁ • b < a₂ • b`.
* `SMulPosReflectLT`: If `b ≥ 0`, then `a₁ • b < a₂ • b` implies `a₁ < a₂`.
* `SMulPosReflectLE`: If `b > 0`, then `a₁ • b ≤ a₂ • b` implies `a₁ ≤ a₂`.
## Constructors
The four typeclasses about nonnegativity can usually be checked only on positive inputs due to their
condition becoming trivial when `a = 0` or `b = 0`. We therefore make the following constructors
available: `PosSMulMono.of_pos`, `PosSMulReflectLT.of_pos`, `SMulPosMono.of_pos`,
`SMulPosReflectLT.of_pos`
## Implications
As `α` and `β` get more and more structure, those typeclasses end up being equivalent. The commonly
used implications are:
* When `α`, `β` are partial orders:
* `PosSMulStrictMono → PosSMulMono`
* `SMulPosStrictMono → SMulPosMono`
* `PosSMulReflectLE → PosSMulReflectLT`
* `SMulPosReflectLE → SMulPosReflectLT`
* When `β` is a linear order:
* `PosSMulStrictMono → PosSMulReflectLE`
* `PosSMulReflectLT → PosSMulMono` (not registered as instance)
* `SMulPosReflectLT → SMulPosMono` (not registered as instance)
* `PosSMulReflectLE → PosSMulStrictMono` (not registered as instance)
* `SMulPosReflectLE → SMulPosStrictMono` (not registered as instance)
* When `α` is a linear order:
* `SMulPosStrictMono → SMulPosReflectLE`
* When `α` is an ordered ring, `β` an ordered group and also an `α`-module:
* `PosSMulMono → SMulPosMono`
* `PosSMulStrictMono → SMulPosStrictMono`
* When `α` is an linear ordered semifield, `β` is an `α`-module:
* `PosSMulStrictMono → PosSMulReflectLT`
* `PosSMulMono → PosSMulReflectLE`
* When `α` is a semiring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `PosSMulMono → PosSMulStrictMono` (not registered as instance)
* When `α` is a ring, `β` is an `α`-module with `NoZeroSMulDivisors`:
* `SMulPosMono → SMulPosStrictMono` (not registered as instance)
Further, the bundled non-granular typeclasses imply the granular ones like so:
* `OrderedSMul → PosSMulStrictMono`
* `OrderedSMul → PosSMulReflectLT`
Unless otherwise stated, all these implications are registered as instances,
which means that in practice you should not worry about these implications.
However, if you encounter a case where you think a statement is true but
not covered by the current implications, please bring it up on Zulip!
## Implementation notes
This file uses custom typeclasses instead of abbreviations of `CovariantClass`/`ContravariantClass`
because:
* They get displayed as classes in the docs. In particular, one can see their list of instances,
instead of their instances being invariably dumped to the `CovariantClass`/`ContravariantClass`
list.
* They don't pollute other typeclass searches. Having many abbreviations of the same typeclass for
different purposes always felt like a performance issue (more instances with the same key, for no
added benefit), and indeed making the classes here abbreviation previous creates timeouts due to
the higher number of `CovariantClass`/`ContravariantClass` instances.
* `SMulPosReflectLT`/`SMulPosReflectLE` do not fit in the framework since they relate `≤` on two
different types. So we would have to generalise `CovariantClass`/`ContravariantClass` to three
types and two relations.
* Very minor, but the constructors let you work with `a : α`, `h : 0 ≤ a` instead of
`a : {a : α // 0 ≤ a}`. This actually makes some instances surprisingly cleaner to prove.
* The `CovariantClass`/`ContravariantClass` framework is only useful to automate very simple logic
anyway. It is easily copied over.
In the future, it would be good to make the corresponding typeclasses in
`Mathlib/Algebra/Order/GroupWithZero/Unbundled.lean` custom typeclasses too.
## TODO
This file acts as a substitute for `Mathlib/Algebra/Order/SMul.lean`. We now need to
* finish the transition by deleting the duplicate lemmas
* rearrange the non-duplicate lemmas into new files
* generalise (most of) the lemmas from `Mathlib/Algebra/Order/Module.lean` to here
* rethink `OrderedSMul`
-/
assert_not_exists Field
open OrderDual
variable (α β : Type*)
section Defs
variable [SMul α β] [Preorder α] [Preorder β]
section Left
variable [Zero α]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `b₁ ≤ b₂ → a • b₁ ≤ a • b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : b₁ ≤ b₂) : a • b₁ ≤ a • b₂
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `b₁ < b₂ → a • b₁ < a • b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : b₁ < b₂) : a • b₁ < a • b₂
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a • b₁ < a • b₂ → b₁ < b₂` if `0 ≤ a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 ≤ a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ < a • b₂) : b₁ < b₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a • b₁ ≤ a • b₂ → b₁ ≤ b₂` if `0 < a`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class PosSMulReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_left` instead. -/
protected elim ⦃a : α⦄ (ha : 0 < a) ⦃b₁ b₂ : β⦄ (hb : a • b₁ ≤ a • b₂) : b₁ ≤ b₂
end Left
section Right
variable [Zero β]
/-- Typeclass for monotonicity of scalar multiplication by nonnegative elements on the left,
namely `a₁ ≤ a₂ → a₁ • b ≤ a₂ • b` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosMono : Prop where
/-- Do not use this. Use `smul_le_smul_of_nonneg_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (ha : a₁ ≤ a₂) : a₁ • b ≤ a₂ • b
/-- Typeclass for strict monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ < a₂ → a₁ • b < a₂ • b` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosStrictMono : Prop where
/-- Do not use this. Use `smul_lt_smul_of_pos_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (ha : a₁ < a₂) : a₁ • b < a₂ • b
/-- Typeclass for strict reverse monotonicity of scalar multiplication by nonnegative elements on
the left, namely `a₁ • b < a₂ • b → a₁ < a₂` if `0 ≤ b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLT : Prop where
/-- Do not use this. Use `lt_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 ≤ b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b < a₂ • b) : a₁ < a₂
/-- Typeclass for reverse monotonicity of scalar multiplication by positive elements on the left,
namely `a₁ • b ≤ a₂ • b → a₁ ≤ a₂` if `0 < b`.
You should usually not use this very granular typeclass directly, but rather a typeclass like
`OrderedSMul`. -/
class SMulPosReflectLE : Prop where
/-- Do not use this. Use `le_of_smul_lt_smul_right` instead. -/
protected elim ⦃b : β⦄ (hb : 0 < b) ⦃a₁ a₂ : α⦄ (hb : a₁ • b ≤ a₂ • b) : a₁ ≤ a₂
end Right
end Defs
variable {α β} {a a₁ a₂ : α} {b b₁ b₂ : β}
section Mul
variable [Zero α] [Mul α] [Preorder α]
-- See note [lower instance priority]
instance (priority := 100) PosMulMono.toPosSMulMono [PosMulMono α] : PosSMulMono α α where
elim _a ha _b₁ _b₂ hb := mul_le_mul_of_nonneg_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulStrictMono.toPosSMulStrictMono [PosMulStrictMono α] :
PosSMulStrictMono α α where
elim _a ha _b₁ _b₂ hb := mul_lt_mul_of_pos_left hb ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLT.toPosSMulReflectLT [PosMulReflectLT α] :
PosSMulReflectLT α α where
elim _a ha _b₁ _b₂ h := lt_of_mul_lt_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) PosMulReflectLE.toPosSMulReflectLE [PosMulReflectLE α] :
PosSMulReflectLE α α where
elim _a ha _b₁ _b₂ h := le_of_mul_le_mul_left h ha
-- See note [lower instance priority]
instance (priority := 100) MulPosMono.toSMulPosMono [MulPosMono α] : SMulPosMono α α where
elim _b hb _a₁ _a₂ ha := mul_le_mul_of_nonneg_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosStrictMono.toSMulPosStrictMono [MulPosStrictMono α] :
SMulPosStrictMono α α where
elim _b hb _a₁ _a₂ ha := mul_lt_mul_of_pos_right ha hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLT.toSMulPosReflectLT [MulPosReflectLT α] :
SMulPosReflectLT α α where
elim _b hb _a₁ _a₂ h := lt_of_mul_lt_mul_right h hb
-- See note [lower instance priority]
instance (priority := 100) MulPosReflectLE.toSMulPosReflectLE [MulPosReflectLE α] :
SMulPosReflectLE α α where
elim _b hb _a₁ _a₂ h := le_of_mul_le_mul_right h hb
end Mul
section SMul
variable [SMul α β]
section Preorder
variable [Preorder α] [Preorder β]
section Left
variable [Zero α]
lemma monotone_smul_left_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) : Monotone ((a • ·) : β → β) :=
PosSMulMono.elim ha
lemma strictMono_smul_left_of_pos [PosSMulStrictMono α β] (ha : 0 < a) :
StrictMono ((a • ·) : β → β) := PosSMulStrictMono.elim ha
@[gcongr] lemma smul_le_smul_of_nonneg_left [PosSMulMono α β] (hb : b₁ ≤ b₂) (ha : 0 ≤ a) :
a • b₁ ≤ a • b₂ := monotone_smul_left_of_nonneg ha hb
@[gcongr] lemma smul_lt_smul_of_pos_left [PosSMulStrictMono α β] (hb : b₁ < b₂) (ha : 0 < a) :
a • b₁ < a • b₂ := strictMono_smul_left_of_pos ha hb
lemma lt_of_smul_lt_smul_left [PosSMulReflectLT α β] (h : a • b₁ < a • b₂) (ha : 0 ≤ a) : b₁ < b₂ :=
PosSMulReflectLT.elim ha h
lemma le_of_smul_le_smul_left [PosSMulReflectLE α β] (h : a • b₁ ≤ a • b₂) (ha : 0 < a) : b₁ ≤ b₂ :=
PosSMulReflectLE.elim ha h
alias lt_of_smul_lt_smul_of_nonneg_left := lt_of_smul_lt_smul_left
alias le_of_smul_le_smul_of_pos_left := le_of_smul_le_smul_left
@[simp]
lemma smul_le_smul_iff_of_pos_left [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) :
a • b₁ ≤ a • b₂ ↔ b₁ ≤ b₂ :=
⟨fun h ↦ le_of_smul_le_smul_left h ha, fun h ↦ smul_le_smul_of_nonneg_left h ha.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b₁ < a • b₂ ↔ b₁ < b₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_left h ha.le, fun hb ↦ smul_lt_smul_of_pos_left hb ha⟩
end Left
section Right
variable [Zero β]
lemma monotone_smul_right_of_nonneg [SMulPosMono α β] (hb : 0 ≤ b) : Monotone ((· • b) : α → β) :=
SMulPosMono.elim hb
lemma strictMono_smul_right_of_pos [SMulPosStrictMono α β] (hb : 0 < b) :
StrictMono ((· • b) : α → β) := SMulPosStrictMono.elim hb
@[gcongr] lemma smul_le_smul_of_nonneg_right [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : 0 ≤ b) :
a₁ • b ≤ a₂ • b := monotone_smul_right_of_nonneg hb ha
@[gcongr] lemma smul_lt_smul_of_pos_right [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : 0 < b) :
a₁ • b < a₂ • b := strictMono_smul_right_of_pos hb ha
lemma lt_of_smul_lt_smul_right [SMulPosReflectLT α β] (h : a₁ • b < a₂ • b) (hb : 0 ≤ b) :
a₁ < a₂ := SMulPosReflectLT.elim hb h
lemma le_of_smul_le_smul_right [SMulPosReflectLE α β] (h : a₁ • b ≤ a₂ • b) (hb : 0 < b) :
a₁ ≤ a₂ := SMulPosReflectLE.elim hb h
alias lt_of_smul_lt_smul_of_nonneg_right := lt_of_smul_lt_smul_right
alias le_of_smul_le_smul_of_pos_right := le_of_smul_le_smul_right
@[simp]
lemma smul_le_smul_iff_of_pos_right [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
a₁ • b ≤ a₂ • b ↔ a₁ ≤ a₂ :=
⟨fun h ↦ le_of_smul_le_smul_right h hb, fun ha ↦ smul_le_smul_of_nonneg_right ha hb.le⟩
@[simp]
lemma smul_lt_smul_iff_of_pos_right [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
a₁ • b < a₂ • b ↔ a₁ < a₂ :=
⟨fun h ↦ lt_of_smul_lt_smul_right h hb.le, fun ha ↦ smul_lt_smul_of_pos_right ha hb⟩
end Right
section LeftRight
variable [Zero α] [Zero β]
lemma smul_lt_smul_of_le_of_lt [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₁ : 0 < a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_lt_smul_of_le_of_lt' [PosSMulStrictMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂)
(hb : b₁ < b₂) (h₂ : 0 < a₂) (h₁ : 0 ≤ b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans_lt (smul_lt_smul_of_pos_left hb h₂)
lemma smul_lt_smul_of_lt_of_le [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₁ : 0 ≤ a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans_lt (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul_of_lt_of_le' [PosSMulMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂)
(hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb h₂)
lemma smul_lt_smul [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₁ : 0 < a₁) (h₂ : 0 < b₂) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_left hb h₁).trans (smul_lt_smul_of_pos_right ha h₂)
lemma smul_lt_smul' [PosSMulStrictMono α β] [SMulPosStrictMono α β] (ha : a₁ < a₂) (hb : b₁ < b₂)
(h₂ : 0 < a₂) (h₁ : 0 < b₁) : a₁ • b₁ < a₂ • b₂ :=
(smul_lt_smul_of_pos_right ha h₁).trans (smul_lt_smul_of_pos_left hb h₂)
lemma smul_le_smul [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂)
(h₁ : 0 ≤ a₁) (h₂ : 0 ≤ b₂) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_left hb h₁).trans (smul_le_smul_of_nonneg_right ha h₂)
lemma smul_le_smul' [PosSMulMono α β] [SMulPosMono α β] (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₂ : 0 ≤ a₂)
(h₁ : 0 ≤ b₁) : a₁ • b₁ ≤ a₂ • b₂ :=
(smul_le_smul_of_nonneg_right ha h₁).trans (smul_le_smul_of_nonneg_left hb h₂)
end LeftRight
end Preorder
section LinearOrder
variable [Preorder α] [LinearOrder β]
section Left
variable [Zero α]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulReflectLE [PosSMulStrictMono α β] :
PosSMulReflectLE α β where
elim _a ha _b₁ _b₂ := (strictMono_smul_left_of_pos ha).le_iff_le.1
lemma PosSMulReflectLE.toPosSMulStrictMono [PosSMulReflectLE α β] : PosSMulStrictMono α β where
elim _a ha _b₁ _b₂ hb := not_le.1 fun h ↦ hb.not_ge <| le_of_smul_le_smul_left h ha
lemma posSMulStrictMono_iff_PosSMulReflectLE : PosSMulStrictMono α β ↔ PosSMulReflectLE α β :=
⟨fun _ ↦ inferInstance, fun _ ↦ PosSMulReflectLE.toPosSMulStrictMono⟩
instance PosSMulMono.toPosSMulReflectLT [PosSMulMono α β] : PosSMulReflectLT α β where
elim _a ha _b₁ _b₂ := (monotone_smul_left_of_nonneg ha).reflect_lt
lemma PosSMulReflectLT.toPosSMulMono [PosSMulReflectLT α β] : PosSMulMono α β where
elim _a ha _b₁ _b₂ hb := not_lt.1 fun h ↦ hb.not_gt <| lt_of_smul_lt_smul_left h ha
lemma posSMulMono_iff_posSMulReflectLT : PosSMulMono α β ↔ PosSMulReflectLT α β :=
⟨fun _ ↦ PosSMulMono.toPosSMulReflectLT, fun _ ↦ PosSMulReflectLT.toPosSMulMono⟩
lemma smul_max_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • max b₁ b₂ = max (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_max
lemma smul_min_of_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (b₁ b₂ : β) :
a • min b₁ b₂ = min (a • b₁) (a • b₂) := (monotone_smul_left_of_nonneg ha).map_min
end Left
section Right
variable [Zero β]
lemma SMulPosReflectLE.toSMulPosStrictMono [SMulPosReflectLE α β] : SMulPosStrictMono α β where
elim _b hb _a₁ _a₂ ha := not_le.1 fun h ↦ ha.not_ge <| le_of_smul_le_smul_of_pos_right h hb
lemma SMulPosReflectLT.toSMulPosMono [SMulPosReflectLT α β] : SMulPosMono α β where
elim _b hb _a₁ _a₂ ha := not_lt.1 fun h ↦ ha.not_gt <| lt_of_smul_lt_smul_right h hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [Preorder β]
section Right
variable [Zero β]
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosReflectLE [SMulPosStrictMono α β] :
SMulPosReflectLE α β where
elim _b hb _a₁ _a₂ h := not_lt.1 fun ha ↦ h.not_gt <| smul_lt_smul_of_pos_right ha hb
lemma SMulPosMono.toSMulPosReflectLT [SMulPosMono α β] : SMulPosReflectLT α β where
elim _b hb _a₁ _a₂ h := not_le.1 fun ha ↦ h.not_ge <| smul_le_smul_of_nonneg_right ha hb
end Right
end LinearOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β]
section Right
variable [Zero β]
lemma smulPosStrictMono_iff_SMulPosReflectLE : SMulPosStrictMono α β ↔ SMulPosReflectLE α β :=
⟨fun _ ↦ SMulPosStrictMono.toSMulPosReflectLE, fun _ ↦ SMulPosReflectLE.toSMulPosStrictMono⟩
lemma smulPosMono_iff_smulPosReflectLT : SMulPosMono α β ↔ SMulPosReflectLT α β :=
⟨fun _ ↦ SMulPosMono.toSMulPosReflectLT, fun _ ↦ SMulPosReflectLT.toSMulPosMono⟩
end Right
end LinearOrder
end SMul
section SMulZeroClass
variable [Zero α] [Zero β] [SMulZeroClass α β]
section Preorder
variable [Preorder α] [Preorder β]
lemma smul_pos [PosSMulStrictMono α β] (ha : 0 < a) (hb : 0 < b) : 0 < a • b := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
lemma smul_neg_of_pos_of_neg [PosSMulStrictMono α β] (ha : 0 < a) (hb : b < 0) : a • b < 0 := by
simpa only [smul_zero] using smul_lt_smul_of_pos_left hb ha
@[simp]
lemma smul_pos_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
0 < a • b ↔ 0 < b := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₁ := 0) (b₂ := b)
lemma smul_neg_iff_of_pos_left [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a • b < 0 ↔ b < 0 := by
simpa only [smul_zero] using smul_lt_smul_iff_of_pos_left ha (b₂ := (0 : β))
lemma smul_nonneg [PosSMulMono α β] (ha : 0 ≤ a) (hb : 0 ≤ b₁) : 0 ≤ a • b₁ := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma smul_nonpos_of_nonneg_of_nonpos [PosSMulMono α β] (ha : 0 ≤ a) (hb : b ≤ 0) : a • b ≤ 0 := by
simpa only [smul_zero] using smul_le_smul_of_nonneg_left hb ha
lemma pos_of_smul_pos_left [PosSMulReflectLT α β] (h : 0 < a • b) (ha : 0 ≤ a) : 0 < b :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
lemma neg_of_smul_neg_left [PosSMulReflectLT α β] (h : a • b < 0) (ha : 0 ≤ a) : b < 0 :=
lt_of_smul_lt_smul_left (by rwa [smul_zero]) ha
end Preorder
end SMulZeroClass
section SMulWithZero
variable [Zero α] [Zero β] [SMulWithZero α β]
section Preorder
variable [Preorder α] [Preorder β]
lemma smul_pos' [SMulPosStrictMono α β] (ha : 0 < a) (hb : 0 < b) : 0 < a • b := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
lemma smul_neg_of_neg_of_pos [SMulPosStrictMono α β] (ha : a < 0) (hb : 0 < b) : a • b < 0 := by
simpa only [zero_smul] using smul_lt_smul_of_pos_right ha hb
@[simp]
lemma smul_pos_iff_of_pos_right [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
0 < a • b ↔ 0 < a := by
simpa only [zero_smul] using smul_lt_smul_iff_of_pos_right hb (a₁ := 0) (a₂ := a)
lemma smul_nonneg' [SMulPosMono α β] (ha : 0 ≤ a) (hb : 0 ≤ b₁) : 0 ≤ a • b₁ := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma smul_nonpos_of_nonpos_of_nonneg [SMulPosMono α β] (ha : a ≤ 0) (hb : 0 ≤ b) : a • b ≤ 0 := by
simpa only [zero_smul] using smul_le_smul_of_nonneg_right ha hb
lemma pos_of_smul_pos_right [SMulPosReflectLT α β] (h : 0 < a • b) (hb : 0 ≤ b) : 0 < a :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma neg_of_smul_neg_right [SMulPosReflectLT α β] (h : a • b < 0) (hb : 0 ≤ b) : a < 0 :=
lt_of_smul_lt_smul_right (by rwa [zero_smul]) hb
lemma pos_iff_pos_of_smul_pos [PosSMulReflectLT α β] [SMulPosReflectLT α β] (hab : 0 < a • b) :
0 < a ↔ 0 < b :=
⟨pos_of_smul_pos_left hab ∘ le_of_lt, pos_of_smul_pos_right hab ∘ le_of_lt⟩
end Preorder
section PartialOrder
variable [PartialOrder α] [Preorder β]
/-- A constructor for `PosSMulMono` requiring you to prove `b₁ ≤ b₂ → a • b₁ ≤ a • b₂` only when
`0 < a` -/
lemma PosSMulMono.of_pos (h₀ : ∀ a : α, 0 < a → ∀ b₁ b₂ : β, b₁ ≤ b₂ → a • b₁ ≤ a • b₂) :
PosSMulMono α β where
elim a ha b₁ b₂ h := by
obtain ha | ha := ha.eq_or_lt
· simp [← ha]
· exact h₀ _ ha _ _ h
/-- A constructor for `PosSMulReflectLT` requiring you to prove `a • b₁ < a • b₂ → b₁ < b₂` only
when `0 < a` -/
lemma PosSMulReflectLT.of_pos (h₀ : ∀ a : α, 0 < a → ∀ b₁ b₂ : β, a • b₁ < a • b₂ → b₁ < b₂) :
PosSMulReflectLT α β where
elim a ha b₁ b₂ h := by
obtain ha | ha := ha.eq_or_lt
· simp [← ha] at h
· exact h₀ _ ha _ _ h
end PartialOrder
section PartialOrder
variable [Preorder α] [PartialOrder β]
/-- A constructor for `SMulPosMono` requiring you to prove `a₁ ≤ a₂ → a₁ • b ≤ a₂ • b` only when
`0 < b` -/
lemma SMulPosMono.of_pos (h₀ : ∀ b : β, 0 < b → ∀ a₁ a₂ : α, a₁ ≤ a₂ → a₁ • b ≤ a₂ • b) :
SMulPosMono α β where
elim b hb a₁ a₂ h := by
obtain hb | hb := hb.eq_or_lt
· simp [← hb]
· exact h₀ _ hb _ _ h
/-- A constructor for `SMulPosReflectLT` requiring you to prove `a₁ • b < a₂ • b → a₁ < a₂` only
when `0 < b` -/
lemma SMulPosReflectLT.of_pos (h₀ : ∀ b : β, 0 < b → ∀ a₁ a₂ : α, a₁ • b < a₂ • b → a₁ < a₂) :
SMulPosReflectLT α β where
elim b hb a₁ a₂ h := by
obtain hb | hb := hb.eq_or_lt
· simp [← hb] at h
· exact h₀ _ hb _ _ h
end PartialOrder
section PartialOrder
variable [PartialOrder α] [PartialOrder β]
-- See note [lower instance priority]
instance (priority := 100) PosSMulStrictMono.toPosSMulMono [PosSMulStrictMono α β] :
PosSMulMono α β :=
PosSMulMono.of_pos fun _a ha ↦ (strictMono_smul_left_of_pos ha).monotone
-- See note [lower instance priority]
instance (priority := 100) SMulPosStrictMono.toSMulPosMono [SMulPosStrictMono α β] :
SMulPosMono α β :=
SMulPosMono.of_pos fun _b hb ↦ (strictMono_smul_right_of_pos hb).monotone
-- See note [lower instance priority]
instance (priority := 100) PosSMulReflectLE.toPosSMulReflectLT [PosSMulReflectLE α β] :
PosSMulReflectLT α β :=
PosSMulReflectLT.of_pos fun a ha b₁ b₂ h ↦
(le_of_smul_le_smul_of_pos_left h.le ha).lt_of_ne <| by rintro rfl; simp at h
-- See note [lower instance priority]
instance (priority := 100) SMulPosReflectLE.toSMulPosReflectLT [SMulPosReflectLE α β] :
SMulPosReflectLT α β :=
SMulPosReflectLT.of_pos fun b hb a₁ a₂ h ↦
(le_of_smul_le_smul_of_pos_right h.le hb).lt_of_ne <| by rintro rfl; simp at h
lemma smul_eq_smul_iff_eq_and_eq_of_pos [PosSMulStrictMono α β] [SMulPosStrictMono α β]
(ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₁ : 0 < a₁) (h₂ : 0 < b₂) :
a₁ • b₁ = a₂ • b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩
· exact (smul_le_smul_of_nonneg_left hb h₁.le).trans_lt (smul_lt_smul_of_pos_right ha h₂)
· exact (smul_lt_smul_of_pos_left hb h₁).trans_le (smul_le_smul_of_nonneg_right ha h₂.le)
lemma smul_eq_smul_iff_eq_and_eq_of_pos' [PosSMulStrictMono α β] [SMulPosStrictMono α β]
(ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) (h₂ : 0 < a₂) (h₁ : 0 < b₁) :
a₁ • b₁ = a₂ • b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ := by
refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩
simp only [eq_iff_le_not_lt, ha, hb, true_and]
refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩
· exact (smul_lt_smul_of_pos_right ha h₁).trans_le (smul_le_smul_of_nonneg_left hb h₂.le)
· exact (smul_le_smul_of_nonneg_right ha h₁.le).trans_lt (smul_lt_smul_of_pos_left hb h₂)
end PartialOrder
section LinearOrder
variable [LinearOrder α] [LinearOrder β]
lemma pos_and_pos_or_neg_and_neg_of_smul_pos [PosSMulMono α β] [SMulPosMono α β] (hab : 0 < a • b) :
0 < a ∧ 0 < b ∨ a < 0 ∧ b < 0 := by
obtain ha | rfl | ha := lt_trichotomy a 0
· refine Or.inr ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩
exact smul_nonpos_of_nonpos_of_nonneg ha.le hb
· rw [zero_smul] at hab
exact hab.false.elim
· refine Or.inl ⟨ha, lt_imp_lt_of_le_imp_le (fun hb ↦ ?_) hab⟩
exact smul_nonpos_of_nonneg_of_nonpos ha.le hb
lemma neg_of_smul_pos_right [PosSMulMono α β] [SMulPosMono α β] (h : 0 < a • b) (ha : a ≤ 0) :
b < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.1.not_ge ha).2
lemma neg_of_smul_pos_left [PosSMulMono α β] [SMulPosMono α β] (h : 0 < a • b) (ha : b ≤ 0) :
a < 0 := ((pos_and_pos_or_neg_and_neg_of_smul_pos h).resolve_left fun h ↦ h.2.not_ge ha).1
lemma neg_iff_neg_of_smul_pos [PosSMulMono α β] [SMulPosMono α β] (hab : 0 < a • b) :
a < 0 ↔ b < 0 :=
⟨neg_of_smul_pos_right hab ∘ le_of_lt, neg_of_smul_pos_left hab ∘ le_of_lt⟩
lemma neg_of_smul_neg_left' [SMulPosMono α β] (h : a • b < 0) (ha : 0 ≤ a) : b < 0 :=
lt_of_not_ge fun hb ↦ (smul_nonneg' ha hb).not_gt h
lemma neg_of_smul_neg_right' [PosSMulMono α β] (h : a • b < 0) (hb : 0 ≤ b) : a < 0 :=
lt_of_not_ge fun ha ↦ (smul_nonneg ha hb).not_gt h
end LinearOrder
end SMulWithZero
section MulAction
variable [Monoid α] [Zero β] [MulAction α β]
section Preorder
variable [Preorder α] [Preorder β]
@[simp]
lemma le_smul_iff_one_le_left [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
b ≤ a • b ↔ 1 ≤ a := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma lt_smul_iff_one_lt_left [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
b < a • b ↔ 1 < a := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
@[simp]
lemma smul_le_iff_le_one_left [SMulPosMono α β] [SMulPosReflectLE α β] (hb : 0 < b) :
a • b ≤ b ↔ a ≤ 1 := Iff.trans (by rw [one_smul]) (smul_le_smul_iff_of_pos_right hb)
@[simp]
lemma smul_lt_iff_lt_one_left [SMulPosStrictMono α β] [SMulPosReflectLT α β] (hb : 0 < b) :
a • b < b ↔ a < 1 := Iff.trans (by rw [one_smul]) (smul_lt_smul_iff_of_pos_right hb)
lemma smul_le_of_le_one_left [SMulPosMono α β] (hb : 0 ≤ b) (h : a ≤ 1) : a • b ≤ b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
lemma le_smul_of_one_le_left [SMulPosMono α β] (hb : 0 ≤ b) (h : 1 ≤ a) : b ≤ a • b := by
simpa only [one_smul] using smul_le_smul_of_nonneg_right h hb
lemma smul_lt_of_lt_one_left [SMulPosStrictMono α β] (hb : 0 < b) (h : a < 1) : a • b < b := by
simpa only [one_smul] using smul_lt_smul_of_pos_right h hb
lemma lt_smul_of_one_lt_left [SMulPosStrictMono α β] (hb : 0 < b) (h : 1 < a) : b < a • b := by
simpa only [one_smul] using smul_lt_smul_of_pos_right h hb
end Preorder
end MulAction
section Semiring
variable [Semiring α] [AddCommGroup β] [Module α β] [NoZeroSMulDivisors α β]
section PartialOrder
variable [Preorder α] [PartialOrder β]
lemma PosSMulMono.toPosSMulStrictMono [PosSMulMono α β] : PosSMulStrictMono α β :=
⟨fun _a ha _b₁ _b₂ hb ↦ (smul_le_smul_of_nonneg_left hb.le ha.le).lt_of_ne <|
(smul_right_injective _ ha.ne').ne hb.ne⟩
instance PosSMulReflectLT.toPosSMulReflectLE [PosSMulReflectLT α β] : PosSMulReflectLE α β :=
⟨fun _a ha _b₁ _b₂ h ↦ h.eq_or_lt.elim (fun h ↦ (smul_right_injective _ ha.ne' h).le) fun h' ↦
(lt_of_smul_lt_smul_left h' ha.le).le⟩
end PartialOrder
section PartialOrder
variable [PartialOrder α] [PartialOrder β]
lemma posSMulMono_iff_posSMulStrictMono : PosSMulMono α β ↔ PosSMulStrictMono α β :=
⟨fun _ ↦ PosSMulMono.toPosSMulStrictMono, fun _ ↦ inferInstance⟩
lemma PosSMulReflectLE_iff_posSMulReflectLT : PosSMulReflectLE α β ↔ PosSMulReflectLT α β :=
⟨fun _ ↦ inferInstance, fun _ ↦ PosSMulReflectLT.toPosSMulReflectLE⟩
end PartialOrder
end Semiring
section Ring
variable [Ring α] [AddCommGroup β] [Module α β] [NoZeroSMulDivisors α β]
section PartialOrder
variable [PartialOrder α] [PartialOrder β]
lemma SMulPosMono.toSMulPosStrictMono [SMulPosMono α β] : SMulPosStrictMono α β :=
⟨fun _b hb _a₁ _a₂ ha ↦ (smul_le_smul_of_nonneg_right ha.le hb.le).lt_of_ne <|
(smul_left_injective _ hb.ne').ne ha.ne⟩
lemma smulPosMono_iff_smulPosStrictMono : SMulPosMono α β ↔ SMulPosStrictMono α β :=
⟨fun _ ↦ SMulPosMono.toSMulPosStrictMono, fun _ ↦ inferInstance⟩
lemma SMulPosReflectLT.toSMulPosReflectLE [SMulPosReflectLT α β] : SMulPosReflectLE α β :=
⟨fun _b hb _a₁ _a₂ h ↦ h.eq_or_lt.elim (fun h ↦ (smul_left_injective _ hb.ne' h).le) fun h' ↦
(lt_of_smul_lt_smul_right h' hb.le).le⟩
lemma SMulPosReflectLE_iff_smulPosReflectLT : SMulPosReflectLE α β ↔ SMulPosReflectLT α β :=
⟨fun _ ↦ inferInstance, fun _ ↦ SMulPosReflectLT.toSMulPosReflectLE⟩
end PartialOrder
end Ring
section GroupWithZero
variable [GroupWithZero α] [Preorder α] [Preorder β] [MulAction α β]
lemma inv_smul_le_iff_of_pos [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) :
a⁻¹ • b₁ ≤ b₂ ↔ b₁ ≤ a • b₂ := by rw [← smul_le_smul_iff_of_pos_left ha, smul_inv_smul₀ ha.ne']
lemma le_inv_smul_iff_of_pos [PosSMulMono α β] [PosSMulReflectLE α β] (ha : 0 < a) :
b₁ ≤ a⁻¹ • b₂ ↔ a • b₁ ≤ b₂ := by rw [← smul_le_smul_iff_of_pos_left ha, smul_inv_smul₀ ha.ne']
lemma inv_smul_lt_iff_of_pos [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
a⁻¹ • b₁ < b₂ ↔ b₁ < a • b₂ := by rw [← smul_lt_smul_iff_of_pos_left ha, smul_inv_smul₀ ha.ne']
lemma lt_inv_smul_iff_of_pos [PosSMulStrictMono α β] [PosSMulReflectLT α β] (ha : 0 < a) :
b₁ < a⁻¹ • b₂ ↔ a • b₁ < b₂ := by rw [← smul_lt_smul_iff_of_pos_left ha, smul_inv_smul₀ ha.ne']
/-- Right scalar multiplication as an order isomorphism. -/
@[simps!]
def OrderIso.smulRight [PosSMulMono α β] [PosSMulReflectLE α β] {a : α} (ha : 0 < a) : β ≃o β where
toEquiv := Equiv.smulRight ha.ne'
map_rel_iff' := smul_le_smul_iff_of_pos_left ha
end GroupWithZero
namespace OrderDual
section Left
variable [Preorder α] [Preorder β] [SMul α β] [Zero α]
instance instPosSMulMono [PosSMulMono α β] : PosSMulMono α βᵒᵈ where
elim _a ha _b₁ _b₂ hb := smul_le_smul_of_nonneg_left (β := β) hb ha
instance instPosSMulStrictMono [PosSMulStrictMono α β] : PosSMulStrictMono α βᵒᵈ where
elim _a ha _b₁ _b₂ hb := smul_lt_smul_of_pos_left (β := β) hb ha
instance instPosSMulReflectLT [PosSMulReflectLT α β] : PosSMulReflectLT α βᵒᵈ where
elim _a ha _b₁ _b₂ h := lt_of_smul_lt_smul_of_nonneg_left (β := β) h ha
instance instPosSMulReflectLE [PosSMulReflectLE α β] : PosSMulReflectLE α βᵒᵈ where
elim _a ha _b₁ _b₂ h := le_of_smul_le_smul_of_pos_left (β := β) h ha
end Left
section Right
variable [Preorder α] [Monoid α] [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β]
[DistribMulAction α β]
instance instSMulPosMono [SMulPosMono α β] : SMulPosMono α βᵒᵈ where
elim _b hb a₁ a₂ ha := by
rw [← neg_le_neg_iff, ← smul_neg, ← smul_neg]
exact smul_le_smul_of_nonneg_right (β := β) ha <| neg_nonneg.2 hb
instance instSMulPosStrictMono [SMulPosStrictMono α β] : SMulPosStrictMono α βᵒᵈ where
elim _b hb a₁ a₂ ha := by
rw [← neg_lt_neg_iff, ← smul_neg, ← smul_neg]
exact smul_lt_smul_of_pos_right (β := β) ha <| neg_pos.2 hb
instance instSMulPosReflectLT [SMulPosReflectLT α β] : SMulPosReflectLT α βᵒᵈ where
elim _b hb a₁ a₂ h := by
rw [← neg_lt_neg_iff, ← smul_neg, ← smul_neg] at h
exact lt_of_smul_lt_smul_right (β := β) h <| neg_nonneg.2 hb
instance instSMulPosReflectLE [SMulPosReflectLE α β] : SMulPosReflectLE α βᵒᵈ where
elim _b hb a₁ a₂ h := by
rw [← neg_le_neg_iff, ← smul_neg, ← smul_neg] at h
exact le_of_smul_le_smul_right (β := β) h <| neg_pos.2 hb
end Right
end OrderDual
section OrderedAddCommMonoid
variable [Semiring α] [PartialOrder α] [IsStrictOrderedRing α] [ExistsAddOfLE α]
[AddCommMonoid β] [PartialOrder β] [IsOrderedCancelAddMonoid β] [Module α β]
section PosSMulMono
variable [PosSMulMono α β] {a₁ a₂ : α} {b₁ b₂ : β}
/-- Binary **rearrangement inequality**. -/
lemma smul_add_smul_le_smul_add_smul (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) :
a₁ • b₂ + a₂ • b₁ ≤ a₁ • b₁ + a₂ • b₂ := by
obtain ⟨a, ha₀, rfl⟩ := exists_nonneg_add_of_le ha
rw [add_smul, add_smul, add_left_comm]
gcongr
assumption
/-- Binary **rearrangement inequality**. -/
lemma smul_add_smul_le_smul_add_smul' (ha : a₂ ≤ a₁) (hb : b₂ ≤ b₁) :
a₁ • b₂ + a₂ • b₁ ≤ a₁ • b₁ + a₂ • b₂ := by
simp_rw [add_comm (a₁ • _)]; exact smul_add_smul_le_smul_add_smul ha hb
end PosSMulMono
section PosSMulStrictMono
variable [PosSMulStrictMono α β] {a₁ a₂ : α} {b₁ b₂ : β}
/-- Binary strict **rearrangement inequality**. -/
lemma smul_add_smul_lt_smul_add_smul (ha : a₁ < a₂) (hb : b₁ < b₂) :
a₁ • b₂ + a₂ • b₁ < a₁ • b₁ + a₂ • b₂ := by
obtain ⟨a, ha₀, rfl⟩ := lt_iff_exists_pos_add.1 ha
rw [add_smul, add_smul, add_left_comm]
gcongr
assumption
/-- Binary strict **rearrangement inequality**. -/
lemma smul_add_smul_lt_smul_add_smul' (ha : a₂ < a₁) (hb : b₂ < b₁) :
a₁ • b₂ + a₂ • b₁ < a₁ • b₁ + a₂ • b₂ := by
simp_rw [add_comm (a₁ • _)]; exact smul_add_smul_lt_smul_add_smul ha hb
end PosSMulStrictMono
end OrderedAddCommMonoid
section OrderedRing
variable [Ring α] [PartialOrder α] [IsOrderedRing α]
section OrderedAddCommGroup
variable [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [Module α β]
section PosSMulMono
variable [PosSMulMono α β]
lemma smul_le_smul_of_nonpos_left (h : b₁ ≤ b₂) (ha : a ≤ 0) : a • b₂ ≤ a • b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_le_neg_iff]
exact smul_le_smul_of_nonneg_left h (neg_nonneg_of_nonpos ha)
lemma antitone_smul_left (ha : a ≤ 0) : Antitone ((a • ·) : β → β) :=
fun _ _ h ↦ smul_le_smul_of_nonpos_left h ha
instance PosSMulMono.toSMulPosMono : SMulPosMono α β where
elim _b hb a₁ a₂ ha := by rw [← sub_nonneg, ← sub_smul]; exact smul_nonneg (sub_nonneg.2 ha) hb
end PosSMulMono
section PosSMulStrictMono
variable [PosSMulStrictMono α β]
lemma smul_lt_smul_of_neg_left (hb : b₁ < b₂) (ha : a < 0) : a • b₂ < a • b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_lt_neg_iff]
exact smul_lt_smul_of_pos_left hb (neg_pos_of_neg ha)
lemma strictAnti_smul_left (ha : a < 0) : StrictAnti ((a • ·) : β → β) :=
fun _ _ h ↦ smul_lt_smul_of_neg_left h ha
instance PosSMulStrictMono.toSMulPosStrictMono : SMulPosStrictMono α β where
elim _b hb a₁ a₂ ha := by rw [← sub_pos, ← sub_smul]; exact smul_pos (sub_pos.2 ha) hb
end PosSMulStrictMono
lemma le_of_smul_le_smul_of_neg [PosSMulReflectLE α β] (h : a • b₁ ≤ a • b₂) (ha : a < 0) :
b₂ ≤ b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_le_neg_iff] at h
exact le_of_smul_le_smul_of_pos_left h <| neg_pos.2 ha
lemma lt_of_smul_lt_smul_of_nonpos [PosSMulReflectLT α β] (h : a • b₁ < a • b₂) (ha : a ≤ 0) :
b₂ < b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_lt_neg_iff] at h
exact lt_of_smul_lt_smul_of_nonneg_left h (neg_nonneg_of_nonpos ha)
omit [IsOrderedRing α] in
lemma smul_nonneg_of_nonpos_of_nonpos [SMulPosMono α β] (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a • b :=
smul_nonpos_of_nonpos_of_nonneg (β := βᵒᵈ) ha hb
lemma smul_le_smul_iff_of_neg_left [PosSMulMono α β] [PosSMulReflectLE α β] (ha : a < 0) :
a • b₁ ≤ a • b₂ ↔ b₂ ≤ b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_le_neg_iff]
exact smul_le_smul_iff_of_pos_left (neg_pos_of_neg ha)
section PosSMulStrictMono
variable [PosSMulStrictMono α β] [PosSMulReflectLT α β]
lemma smul_lt_smul_iff_of_neg_left (ha : a < 0) : a • b₁ < a • b₂ ↔ b₂ < b₁ := by
rw [← neg_neg a, neg_smul, neg_smul (-a), neg_lt_neg_iff]
exact smul_lt_smul_iff_of_pos_left (neg_pos_of_neg ha)
lemma smul_pos_iff_of_neg_left (ha : a < 0) : 0 < a • b ↔ b < 0 := by
simpa only [smul_zero] using smul_lt_smul_iff_of_neg_left ha (b₁ := (0 : β))
alias ⟨_, smul_pos_of_neg_of_neg⟩ := smul_pos_iff_of_neg_left
lemma smul_neg_iff_of_neg_left (ha : a < 0) : a • b < 0 ↔ 0 < b := by
simpa only [smul_zero] using smul_lt_smul_iff_of_neg_left ha (b₂ := (0 : β))
end PosSMulStrictMono
end OrderedAddCommGroup
section LinearOrderedAddCommGroup
variable [AddCommGroup β] [LinearOrder β] [IsOrderedAddMonoid β] [Module α β] [PosSMulMono α β]
{a : α} {b b₁ b₂ : β}
lemma smul_max_of_nonpos (ha : a ≤ 0) (b₁ b₂ : β) : a • max b₁ b₂ = min (a • b₁) (a • b₂) :=
(antitone_smul_left ha : Antitone (_ : β → β)).map_max
lemma smul_min_of_nonpos (ha : a ≤ 0) (b₁ b₂ : β) : a • min b₁ b₂ = max (a • b₁) (a • b₂) :=
(antitone_smul_left ha : Antitone (_ : β → β)).map_min
end LinearOrderedAddCommGroup
end OrderedRing
section LinearOrderedRing
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α]
[AddCommGroup β] [LinearOrder β] [IsOrderedAddMonoid β] [Module α β] [PosSMulStrictMono α β]
{a : α} {b : β}
lemma nonneg_and_nonneg_or_nonpos_and_nonpos_of_smul_nonneg (hab : 0 ≤ a • b) :
0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 := by
simp only [Decidable.or_iff_not_not_and_not, not_and, not_le]
refine fun ab nab ↦ hab.not_gt ?_
obtain ha | rfl | ha := lt_trichotomy 0 a
exacts [smul_neg_of_pos_of_neg ha (ab ha.le), ((ab le_rfl).asymm (nab le_rfl)).elim,
smul_neg_of_neg_of_pos ha (nab ha.le)]
lemma smul_nonneg_iff : 0 ≤ a • b ↔ 0 ≤ a ∧ 0 ≤ b ∨ a ≤ 0 ∧ b ≤ 0 :=
⟨nonneg_and_nonneg_or_nonpos_and_nonpos_of_smul_nonneg,
fun h ↦ h.elim (and_imp.2 smul_nonneg) (and_imp.2 smul_nonneg_of_nonpos_of_nonpos)⟩
lemma smul_nonpos_iff : a • b ≤ 0 ↔ 0 ≤ a ∧ b ≤ 0 ∨ a ≤ 0 ∧ 0 ≤ b := by
rw [← neg_nonneg, ← smul_neg, smul_nonneg_iff, neg_nonneg, neg_nonpos]
lemma smul_nonneg_iff_pos_imp_nonneg : 0 ≤ a • b ↔ (0 < a → 0 ≤ b) ∧ (0 < b → 0 ≤ a) :=
smul_nonneg_iff.trans <| by grind
lemma smul_nonneg_iff_neg_imp_nonpos : 0 ≤ a • b ↔ (a < 0 → b ≤ 0) ∧ (b < 0 → a ≤ 0) := by
rw [← neg_smul_neg, smul_nonneg_iff_pos_imp_nonneg]; simp only [neg_pos, neg_nonneg]
lemma smul_nonpos_iff_pos_imp_nonpos : a • b ≤ 0 ↔ (0 < a → b ≤ 0) ∧ (b < 0 → 0 ≤ a) := by
rw [← neg_nonneg, ← smul_neg, smul_nonneg_iff_pos_imp_nonneg]; simp only [neg_pos, neg_nonneg]
lemma smul_nonpos_iff_neg_imp_nonneg : a • b ≤ 0 ↔ (a < 0 → 0 ≤ b) ∧ (0 < b → a ≤ 0) := by
rw [← neg_nonneg, ← neg_smul, smul_nonneg_iff_pos_imp_nonneg]; simp only [neg_pos, neg_nonneg]
end LinearOrderedRing
namespace Pi
variable {ι : Type*} {β : ι → Type*} [Zero α] [∀ i, Zero (β i)]
section SMulZeroClass
variable [Preorder α] [∀ i, Preorder (β i)] [∀ i, SMulZeroClass α (β i)]
instance instPosSMulMono [∀ i, PosSMulMono α (β i)] : PosSMulMono α (∀ i, β i) where
elim _a ha _b₁ _b₂ hb i := smul_le_smul_of_nonneg_left (hb i) ha
instance instSMulPosMono [∀ i, SMulPosMono α (β i)] : SMulPosMono α (∀ i, β i) where
elim _b hb _a₁ _a₂ ha i := smul_le_smul_of_nonneg_right ha (hb i)
instance instPosSMulReflectLE [∀ i, PosSMulReflectLE α (β i)] : PosSMulReflectLE α (∀ i, β i) where
elim _a ha _b₁ _b₂ h i := le_of_smul_le_smul_left (h i) ha
instance instSMulPosReflectLE [∀ i, SMulPosReflectLE α (β i)] : SMulPosReflectLE α (∀ i, β i) where
elim _b hb _a₁ _a₂ h := by
obtain ⟨-, i, hi⟩ := lt_def.1 hb; exact le_of_smul_le_smul_right (h _) hi
end SMulZeroClass
section SMulWithZero
variable [PartialOrder α] [∀ i, PartialOrder (β i)] [∀ i, SMulWithZero α (β i)]
instance instPosSMulStrictMono [∀ i, PosSMulStrictMono α (β i)] :
PosSMulStrictMono α (∀ i, β i) where
elim := by
simp_rw [lt_def]
rintro _a ha _b₁ _b₂ ⟨hb, i, hi⟩
exact ⟨smul_le_smul_of_nonneg_left hb ha.le, i, smul_lt_smul_of_pos_left hi ha⟩
instance instSMulPosStrictMono [∀ i, SMulPosStrictMono α (β i)] :
SMulPosStrictMono α (∀ i, β i) where
elim := by
simp_rw [lt_def]
rintro a ⟨ha, i, hi⟩ _b₁ _b₂ hb
exact ⟨smul_le_smul_of_nonneg_right hb.le ha, i, smul_lt_smul_of_pos_right hb hi⟩
-- Note: There is no interesting instance for `PosSMulReflectLT α (∀ i, β i)` that's not already
-- implied by the other instances
instance instSMulPosReflectLT [∀ i, SMulPosReflectLT α (β i)] : SMulPosReflectLT α (∀ i, β i) where
elim := by
simp_rw [lt_def]
rintro b hb _a₁ _a₂ ⟨-, i, hi⟩
exact lt_of_smul_lt_smul_right hi <| hb _
end SMulWithZero
end Pi
section Lift
variable {γ : Type*} [Preorder α] [Preorder β] [Preorder γ]
[SMul α β] [SMul α γ] (f : β → γ)
section
variable [Zero α]
lemma PosSMulMono.lift [PosSMulMono α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b) : PosSMulMono α β where
elim a ha b₁ b₂ hb := by simp only [← hf, smul] at *; exact smul_le_smul_of_nonneg_left hb ha
lemma PosSMulStrictMono.lift [PosSMulStrictMono α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b) : PosSMulStrictMono α β where
elim a ha b₁ b₂ hb := by
simp only [← lt_iff_lt_of_le_iff_le' hf hf, smul] at *; exact smul_lt_smul_of_pos_left hb ha
lemma PosSMulReflectLE.lift [PosSMulReflectLE α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b) : PosSMulReflectLE α β where
elim a ha b₁ b₂ h := hf.1 <| le_of_smul_le_smul_left (by simpa only [smul] using hf.2 h) ha
lemma PosSMulReflectLT.lift [PosSMulReflectLT α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b) : PosSMulReflectLT α β where
elim a ha b₁ b₂ h := by
simp only [← lt_iff_lt_of_le_iff_le' hf hf, smul] at *; exact lt_of_smul_lt_smul_left h ha
end
section
variable [Zero β] [Zero γ]
lemma SMulPosMono.lift [SMulPosMono α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b)
(zero : f 0 = 0) : SMulPosMono α β where
elim b hb a₁ a₂ ha := by
simp only [← hf, zero, smul] at *; exact smul_le_smul_of_nonneg_right ha hb
lemma SMulPosStrictMono.lift [SMulPosStrictMono α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b)
(zero : f 0 = 0) : SMulPosStrictMono α β where
elim b hb a₁ a₂ ha := by
simp only [← lt_iff_lt_of_le_iff_le' hf hf, zero, smul] at *
exact smul_lt_smul_of_pos_right ha hb
lemma SMulPosReflectLE.lift [SMulPosReflectLE α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b)
(zero : f 0 = 0) : SMulPosReflectLE α β where
elim b hb a₁ a₂ h := by
simp only [← hf, ← lt_iff_lt_of_le_iff_le' hf hf, zero, smul] at *
exact le_of_smul_le_smul_right h hb
lemma SMulPosReflectLT.lift [SMulPosReflectLT α γ]
(hf : ∀ {b₁ b₂}, f b₁ ≤ f b₂ ↔ b₁ ≤ b₂)
(smul : ∀ (a : α) b, f (a • b) = a • f b)
(zero : f 0 = 0) : SMulPosReflectLT α β where
elim b hb a₁ a₂ h := by
simp only [← hf, ← lt_iff_lt_of_le_iff_le' hf hf, zero, smul] at *
exact lt_of_smul_lt_smul_right h hb
end
end Lift
section Nat
instance OrderedSemiring.toPosSMulMonoNat [Semiring α] [PartialOrder α] [IsOrderedRing α] :
PosSMulMono ℕ α where
elim _n _ _a _b hab := nsmul_le_nsmul_right hab _
instance OrderedSemiring.toSMulPosMonoNat [Semiring α] [PartialOrder α] [IsOrderedRing α] :
SMulPosMono ℕ α where
elim _a ha _m _n hmn := nsmul_le_nsmul_left ha hmn
instance StrictOrderedSemiring.toPosSMulStrictMonoNat
[Semiring α] [PartialOrder α] [IsStrictOrderedRing α] :
PosSMulStrictMono ℕ α where
elim _n hn _a _b hab := nsmul_right_strictMono hn.ne' hab
instance StrictOrderedSemiring.toSMulPosStrictMonoNat
[Semiring α] [PartialOrder α] [IsStrictOrderedRing α] :
SMulPosStrictMono ℕ α where
elim _a ha _m _n hmn := nsmul_lt_nsmul_left ha hmn
end Nat
-- TODO: Instances for `Int` and `Rat`
|
Set.lean
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Algebra.GroupWithZero.Action.Basic
import Mathlib.Algebra.GroupWithZero.Action.Units
import Mathlib.Algebra.GroupWithZero.Pointwise.Set.Basic
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
/-!
# Pointwise operations of sets in a group with zero
This file proves properties of pointwise operations of sets in a group with zero.
## Tags
set multiplication, set addition, pointwise addition, pointwise multiplication,
pointwise subtraction
-/
assert_not_exists OrderedAddCommMonoid Ring
open Function
open scoped Pointwise
variable {α β : Type*}
namespace Set
lemma smul_set_pi₀ {M ι : Type*} {α : ι → Type*} [GroupWithZero M] [∀ i, MulAction M (α i)]
{c : M} (hc : c ≠ 0) (I : Set ι) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) :=
smul_set_pi_of_isUnit (.mk0 _ hc) I s
/-- A slightly more general version of `Set.smul_set_pi₀`. -/
lemma smul_set_pi₀' {M ι : Type*} {α : ι → Type*} [GroupWithZero M] [∀ i, MulAction M (α i)]
{c : M} {I : Set ι} (h : c ≠ 0 ∨ I = univ) (s : ∀ i, Set (α i)) : c • I.pi s = I.pi (c • s) :=
h.elim (fun hc ↦ smul_set_pi_of_isUnit (.mk0 _ hc) I s) (fun hI ↦ hI ▸ smul_set_univ_pi ..)
section SMulZeroClass
variable [Zero β] [SMulZeroClass α β] {s : Set α} {t : Set β} {a : α}
/-- If scalar multiplication by elements of `α` sends `(0 : β)` to zero,
then the same is true for `(0 : Set β)`. -/
protected def smulZeroClassSet [Zero β] [SMulZeroClass α β] : SMulZeroClass α (Set β) where
smul_zero _ := image_singleton.trans <| by rw [smul_zero, singleton_zero]
scoped[Pointwise] attribute [instance] Set.smulZeroClassSet
lemma smul_zero_subset (s : Set α) : s • (0 : Set β) ⊆ 0 := by simp [subset_def, mem_smul]
lemma Nonempty.smul_zero (hs : s.Nonempty) : s • (0 : Set β) = 0 :=
s.smul_zero_subset.antisymm <| by simpa [mem_smul] using hs
lemma zero_mem_smul_set (h : (0 : β) ∈ t) : (0 : β) ∈ a • t := ⟨0, h, smul_zero _⟩
variable [Zero α] [NoZeroSMulDivisors α β]
lemma zero_mem_smul_set_iff (ha : a ≠ 0) : (0 : β) ∈ a • t ↔ (0 : β) ∈ t := by
refine ⟨?_, zero_mem_smul_set⟩
rintro ⟨b, hb, h⟩
rwa [(eq_zero_or_eq_zero_of_smul_eq_zero h).resolve_left ha] at hb
end SMulZeroClass
section SMulWithZero
variable [Zero α] [Zero β] [SMulWithZero α β] {s : Set α} {t : Set β}
/-!
Note that we have neither `SMulWithZero α (Set β)` nor `SMulWithZero (Set α) (Set β)`
because `0 * ∅ ≠ 0`.
-/
lemma zero_smul_subset (t : Set β) : (0 : Set α) • t ⊆ 0 := by simp [subset_def, mem_smul]
lemma Nonempty.zero_smul (ht : t.Nonempty) : (0 : Set α) • t = 0 :=
t.zero_smul_subset.antisymm <| by simpa [mem_smul] using ht
/-- A nonempty set is scaled by zero to the singleton set containing 0. -/
@[simp] lemma zero_smul_set {s : Set β} (h : s.Nonempty) : (0 : α) • s = (0 : Set β) := by
simp only [← image_smul, zero_smul, h.image_const, singleton_zero]
lemma zero_smul_set_subset (s : Set β) : (0 : α) • s ⊆ 0 :=
image_subset_iff.2 fun x _ ↦ zero_smul α x
lemma subsingleton_zero_smul_set (s : Set β) : ((0 : α) • s).Subsingleton :=
subsingleton_singleton.anti <| zero_smul_set_subset s
variable [NoZeroSMulDivisors α β] {a : α}
lemma zero_mem_smul_iff : 0 ∈ s • t ↔ 0 ∈ s ∧ t.Nonempty ∨ 0 ∈ t ∧ s.Nonempty where
mp := by
rintro ⟨a, ha, b, hb, h⟩
obtain rfl | rfl := eq_zero_or_eq_zero_of_smul_eq_zero h
· exact Or.inl ⟨ha, b, hb⟩
· exact Or.inr ⟨hb, a, ha⟩
mpr := by
rintro (⟨hs, b, hb⟩ | ⟨ht, a, ha⟩)
· exact ⟨0, hs, b, hb, zero_smul _ _⟩
· exact ⟨a, ha, 0, ht, smul_zero _⟩
end SMulWithZero
/-- If the scalar multiplication `(· • ·) : α → β → β` is distributive,
then so is `(· • ·) : α → Set β → Set β`. -/
protected noncomputable def distribSMulSet [AddZeroClass β] [DistribSMul α β] :
DistribSMul α (Set β) where
smul_add _ _ _ := image_image2_distrib <| smul_add _
scoped[Pointwise] attribute [instance] Set.distribSMulSet
/-- A distributive multiplicative action of a monoid on an additive monoid `β` gives a distributive
multiplicative action on `Set β`. -/
protected noncomputable def distribMulActionSet [Monoid α] [AddMonoid β] [DistribMulAction α β] :
DistribMulAction α (Set β) where
smul_add := smul_add
smul_zero := smul_zero
/-- A multiplicative action of a monoid on a monoid `β` gives a multiplicative action on `Set β`. -/
protected noncomputable def mulDistribMulActionSet [Monoid α] [Monoid β] [MulDistribMulAction α β] :
MulDistribMulAction α (Set β) where
smul_mul _ _ _ := image_image2_distrib <| smul_mul' _
smul_one _ := image_singleton.trans <| by rw [smul_one, singleton_one]
scoped[Pointwise] attribute [instance] Set.distribMulActionSet Set.mulDistribMulActionSet
instance instNoZeroSMulDivisors [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] :
NoZeroSMulDivisors (Set α) (Set β) where
eq_zero_or_eq_zero_of_smul_eq_zero {s t} h := by
by_contra! H
have hst : (s • t).Nonempty := h.symm.subst zero_nonempty
rw [Ne, ← hst.of_smul_left.subset_zero_iff, Ne,
← hst.of_smul_right.subset_zero_iff] at H
simp only [not_subset, mem_zero] at H
obtain ⟨⟨a, hs, ha⟩, b, ht, hb⟩ := H
exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul hs ht).elim ha hb
instance noZeroSMulDivisors_set [Zero α] [Zero β] [SMul α β] [NoZeroSMulDivisors α β] :
NoZeroSMulDivisors α (Set β) where
eq_zero_or_eq_zero_of_smul_eq_zero {a s} h := by
by_contra! H
have hst : (a • s).Nonempty := h.symm.subst zero_nonempty
rw [Ne, Ne, ← hst.of_image.subset_zero_iff, not_subset] at H
obtain ⟨ha, b, ht, hb⟩ := H
exact (eq_zero_or_eq_zero_of_smul_eq_zero <| h.subset <| smul_mem_smul_set ht).elim ha hb
instance [Zero α] [Mul α] [NoZeroDivisors α] : NoZeroDivisors (Set α) where
eq_zero_or_eq_zero_of_mul_eq_zero h := eq_zero_or_eq_zero_of_smul_eq_zero h
section GroupWithZero
variable [GroupWithZero α] [MulAction α β] {s t : Set β} {a : α}
@[simp]
lemma smul_mem_smul_set_iff₀ (ha : a ≠ 0) (A : Set β) (x : β) : a • x ∈ a • A ↔ x ∈ A :=
show Units.mk0 a ha • _ ∈ _ ↔ _ from smul_mem_smul_set_iff
lemma mem_smul_set_iff_inv_smul_mem₀ (ha : a ≠ 0) (A : Set β) (x : β) : x ∈ a • A ↔ a⁻¹ • x ∈ A :=
show _ ∈ Units.mk0 a ha • _ ↔ _ from mem_smul_set_iff_inv_smul_mem
lemma mem_inv_smul_set_iff₀ (ha : a ≠ 0) (A : Set β) (x : β) : x ∈ a⁻¹ • A ↔ a • x ∈ A :=
show _ ∈ (Units.mk0 a ha)⁻¹ • _ ↔ _ from mem_inv_smul_set_iff
lemma preimage_smul₀ (ha : a ≠ 0) (t : Set β) : (fun x ↦ a • x) ⁻¹' t = a⁻¹ • t :=
preimage_smul (Units.mk0 a ha) t
lemma preimage_smul_inv₀ (ha : a ≠ 0) (t : Set β) : (fun x ↦ a⁻¹ • x) ⁻¹' t = a • t :=
preimage_smul (Units.mk0 a ha)⁻¹ t
@[simp]
lemma smul_set_subset_smul_set_iff₀ (ha : a ≠ 0) {A B : Set β} : a • A ⊆ a • B ↔ A ⊆ B :=
show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_set_subset_smul_set_iff
lemma smul_set_subset_iff₀ (ha : a ≠ 0) {A B : Set β} : a • A ⊆ B ↔ A ⊆ a⁻¹ • B :=
show Units.mk0 a ha • _ ⊆ _ ↔ _ from smul_set_subset_iff_subset_inv_smul_set
lemma subset_smul_set_iff₀ (ha : a ≠ 0) {A B : Set β} : A ⊆ a • B ↔ a⁻¹ • A ⊆ B :=
show _ ⊆ Units.mk0 a ha • _ ↔ _ from subset_smul_set_iff
lemma smul_set_inter₀ (ha : a ≠ 0) : a • (s ∩ t) = a • s ∩ a • t :=
show Units.mk0 a ha • _ = _ from smul_set_inter
lemma smul_set_sdiff₀ (ha : a ≠ 0) : a • (s \ t) = a • s \ a • t :=
image_diff (MulAction.injective₀ ha) _ _
open scoped symmDiff in
lemma smul_set_symmDiff₀ (ha : a ≠ 0) : a • s ∆ t = (a • s) ∆ (a • t) :=
image_symmDiff (MulAction.injective₀ ha) _ _
lemma smul_set_univ₀ (ha : a ≠ 0) : a • (univ : Set β) = univ :=
image_univ_of_surjective <| MulAction.surjective₀ ha
lemma smul_univ₀ {s : Set α} (hs : ¬s ⊆ 0) : s • (univ : Set β) = univ :=
let ⟨a, ha, ha₀⟩ := not_subset.1 hs
eq_univ_of_forall fun b ↦ ⟨a, ha, a⁻¹ • b, trivial, smul_inv_smul₀ ha₀ _⟩
lemma smul_univ₀' {s : Set α} (hs : s.Nontrivial) : s • (univ : Set β) = univ :=
smul_univ₀ hs.not_subset_singleton
open scoped RightActions in
@[simp] lemma inv_smul_set_distrib₀ (a : α) (s : Set α) : (a • s)⁻¹ = s⁻¹ <• a⁻¹ := by
obtain rfl | ha := eq_or_ne a 0
· obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*]
· ext; simp [mem_smul_set_iff_inv_smul_mem₀, *]
open scoped RightActions in
@[simp] lemma inv_op_smul_set_distrib₀ (a : α) (s : Set α) : (s <• a)⁻¹ = a⁻¹ • s⁻¹ := by
obtain rfl | ha := eq_or_ne a 0
· obtain rfl | hs := s.eq_empty_or_nonempty <;> simp [*]
· ext; simp [mem_smul_set_iff_inv_smul_mem₀, *]
end GroupWithZero
end Set
|
ULift.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Topology.Category.TopCat.Basic
import Mathlib.Topology.Homeomorph.Lemmas
/-!
# Lifting topological spaces to a higher universe
In this file, we construct the functor `uliftFunctor.{v, u} : TopCat.{u} ⥤ TopCat.{max u v}`
which sends a topological space `X : Type u` to a homeomorphic space in `Type (max u v)`.
-/
universe v u
open CategoryTheory
namespace TopCat
-- Note: no `@[simps!]` attribute here in order to get good simplification lemmas
-- like `uliftFunctorObjHomeo_naturality_apply` below. We should access
-- `uliftFunctor.obj X` via the homeomorphism `X.uliftFunctorObjHomeo`.
/-- The functor which sends a topological space in `Type u` to a homeomorphic
space in `Type (max u v)`. -/
def uliftFunctor : TopCat.{u} ⥤ TopCat.{max u v} where
obj X := TopCat.of (ULift.{v} X)
map {X Y} f := ofHom ⟨ULift.map f, by continuity⟩
/-- Given `X : TopCat.{u}`, this is the homeomorphism `X ≃ₜ uliftFunctor.{v}.obj X`. -/
def uliftFunctorObjHomeo (X : TopCat.{u}) : X ≃ₜ uliftFunctor.{v}.obj X :=
Homeomorph.ulift.symm
@[simp]
lemma uliftFunctorObjHomeo_naturality_apply {X Y : TopCat.{u}} (f : X ⟶ Y) (x : X) :
uliftFunctor.{v}.map f (X.uliftFunctorObjHomeo x) =
Y.uliftFunctorObjHomeo (f x) := rfl
@[simp]
lemma uliftFunctorObjHomeo_symm_naturality_apply {X Y : TopCat.{u}} (f : X ⟶ Y)
(x : uliftFunctor.{v}.obj X) :
Y.uliftFunctorObjHomeo.symm (uliftFunctor.{v}.map f x) =
f (X.uliftFunctorObjHomeo.symm x) :=
rfl
/-- The `ULift` functor on categories of topological spaces is compatible
with the one defined on categories of types. -/
@[simps!]
def uliftFunctorCompForgetIso : uliftFunctor.{v, u} ⋙ forget TopCat.{max u v} ≅
forget TopCat.{u} ⋙ CategoryTheory.uliftFunctor.{v, u} := Iso.refl _
/-- The `ULift` functor on categories of topological spaces is fully faithful. -/
def uliftFunctorFullyFaithful : uliftFunctor.{v, u}.FullyFaithful where
preimage f := ofHom ⟨ULift.down ∘ f ∘ ULift.up, by continuity⟩
instance : uliftFunctor.{v, u}.Full :=
uliftFunctorFullyFaithful.full
instance : uliftFunctor.{v, u}.Faithful :=
uliftFunctorFullyFaithful.faithful
end TopCat
|
Summable.lean
|
/-
Copyright (c) 2024 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Analysis.SpecialFunctions.Complex.LogBounds
/-!
# Summability of logarithms
We give conditions under which the logarithms of a summble sequence is summable. We also use this
to relate summability of `f` to multipliability of `1 + f`.
-/
variable {ι : Type*}
open Filter Topology NNReal
namespace Complex
variable {f : ι → ℂ} {a : ℂ}
lemma hasProd_of_hasSum_log (hfn : ∀ i, f i ≠ 0) (hf : HasSum (fun i ↦ log (f i)) a) :
HasProd f (exp a) :=
hf.cexp.congr (by simp [exp_log, hfn])
lemma multipliable_of_summable_log (hf : Summable fun i ↦ log (f i)) :
Multipliable f := by
by_cases hfn : ∃ n, f n = 0
· exact multipliable_of_exists_eq_zero hfn
· exact ⟨_, hasProd_of_hasSum_log (not_exists.mp hfn) hf.hasSum⟩
/-- The exponential of a convergent sum of complex logs is the corresponding infinite product. -/
lemma cexp_tsum_eq_tprod (hfn : ∀ i, f i ≠ 0) (hf : Summable fun i ↦ log (f i)) :
cexp (∑' i, log (f i)) = ∏' i, f i :=
(hasProd_of_hasSum_log hfn hf.hasSum).tprod_eq.symm
lemma summable_log_one_add_of_summable {f : ι → ℂ} (hf : Summable f) :
Summable (fun i ↦ log (1 + f i)) := by
apply (hf.norm.mul_left _).of_norm_bounded_eventually
filter_upwards [hf.norm.tendsto_cofinite_zero.eventually_le_const one_half_pos] with i hi
using norm_log_one_add_half_le_self hi
protected lemma multipliable_one_add_of_summable (hf : Summable f) :
Multipliable (fun i ↦ 1 + f i) :=
multipliable_of_summable_log (summable_log_one_add_of_summable hf)
end Complex
namespace Real
variable {f : ι → ℝ} {a : ℝ}
lemma hasProd_of_hasSum_log (hfn : ∀ i, 0 < f i) (hf : HasSum (fun i ↦ log (f i)) a) :
HasProd f (rexp a) :=
hf.rexp.congr (by simp [exp_log, hfn])
lemma multipliable_of_summable_log (hfn : ∀ i, 0 < f i) (hf : Summable fun i ↦ log (f i)) :
Multipliable f :=
⟨_, hasProd_of_hasSum_log hfn hf.hasSum⟩
/-- Alternate version of `Real.multipliable_of_summable_log` assuming only that positivity holds
eventually. -/
lemma multipliable_of_summable_log' (hfn : ∀ᶠ i in cofinite, 0 < f i)
(hf : Summable fun i ↦ log (f i)) : Multipliable f := by
have : Summable fun i ↦ log (if 0 < f i then f i else 1) := by
apply hf.congr_cofinite
filter_upwards [hfn] with i hi using by simp [hi]
have : Multipliable fun i ↦ if 0 < f i then f i else 1 := by
refine multipliable_of_summable_log (fun i ↦ ?_) this
split_ifs with h <;> simp [h]
refine this.congr_cofinite₀ (fun i ↦ ?_) ?_
· split_ifs with h <;> simp [h, ne_of_gt]
· filter_upwards [hfn] with i hi using by simp [hi]
/-- The exponential of a convergent sum of real logs is the corresponding infinite product. -/
lemma rexp_tsum_eq_tprod (hfn : ∀ i, 0 < f i) (hf : Summable fun i ↦ log (f i)) :
rexp (∑' i, log (f i)) = ∏' i, f i :=
(hasProd_of_hasSum_log hfn hf.hasSum).tprod_eq.symm
open Complex in
lemma summable_log_one_add_of_summable (hf : Summable f) :
Summable (fun i ↦ log (1 + f i)) := by
rw [← summable_ofReal]
apply (Complex.summable_log_one_add_of_summable (summable_ofReal.mpr hf)).congr_cofinite
filter_upwards [hf.tendsto_cofinite_zero.eventually_const_le neg_one_lt_zero] with i hi
rw [ofReal_log, ofReal_add, ofReal_one]
linarith
protected lemma multipliable_one_add_of_summable (hf : Summable f) :
Multipliable (fun i ↦ 1 + f i) := by
refine multipliable_of_summable_log' ?_ (summable_log_one_add_of_summable hf)
filter_upwards [hf.tendsto_cofinite_zero.eventually_const_lt neg_one_lt_zero] with i hi
linarith
end Real
section NormedRing
lemma Multipliable.eventually_bounded_finset_prod {v : ι → ℝ} (hv : Multipliable v) :
∃ r₁ > 0, ∃ s₁, ∀ t, s₁ ⊆ t → ∏ i ∈ t, v i ≤ r₁ := by
obtain ⟨r₁, hr₁⟩ := exists_gt (max 0 <| ∏' i, v i)
rw [max_lt_iff] at hr₁
have := hv.hasProd.eventually_le_const hr₁.2
rw [eventually_atTop] at this
exact ⟨r₁, hr₁.1, this⟩
variable {R : Type*} [NormedCommRing R] [NormOneClass R] {f : ι → R}
lemma multipliable_norm_one_add_of_summable_norm (hf : Summable fun i ↦ ‖f i‖) :
Multipliable fun i ↦ ‖1 + f i‖ := by
conv => enter [1, i]; rw [← sub_add_cancel ‖1 + f i‖ 1, add_comm]
refine Real.multipliable_one_add_of_summable <| hf.of_norm_bounded (fun i ↦ ?_)
simpa using abs_norm_sub_norm_le (1 + f i) 1
lemma Finset.norm_prod_one_add_sub_one_le (t : Finset ι) (f : ι → R) :
‖∏ i ∈ t, (1 + f i) - 1‖ ≤ Real.exp (∑ i ∈ t, ‖f i‖) - 1 := by
classical
induction t using Finset.induction_on with
| empty => simp
| insert x t hx IH =>
rw [Finset.prod_insert hx, Finset.sum_insert hx, Real.exp_add,
show (1 + f x) * ∏ i ∈ t, (1 + f i) - 1 =
(∏ i ∈ t, (1 + f i) - 1) + f x * ∏ x ∈ t, (1 + f x) by ring]
refine (norm_add_le_of_le IH (norm_mul_le _ _)).trans ?_
generalize h : Real.exp (∑ i ∈ t, ‖f i‖) = A at ⊢ IH
rw [sub_add_eq_add_sub, sub_le_sub_iff_right]
transitivity A + ‖f x‖ * A
· gcongr
rw [← sub_add_cancel (∏ x ∈ t, (1 + f x)) 1]
refine (norm_add_le _ _).trans <| (add_le_add_right IH _).trans ?_
rw [norm_one, sub_add_cancel]
rw [← one_add_mul, add_comm]
exact mul_le_mul_of_nonneg_right (Real.add_one_le_exp _) (h ▸ Real.exp_nonneg _)
lemma prod_vanishing_of_summable_norm (hf : Summable fun i ↦ ‖f i‖) {ε : ℝ} (hε : 0 < ε) :
∃ s₂, ∀ t, Disjoint t s₂ → ‖∏ i ∈ t, (1 + f i) - 1‖ < ε := by
suffices ∃ s, ∀ t, Disjoint t s → Real.exp (∑ i ∈ t, ‖f i‖) - 1 < ε from
this.imp fun s hs t ht ↦ (t.norm_prod_one_add_sub_one_le _).trans_lt (hs t ht)
suffices {x | Real.exp x - 1 < ε} ∈ 𝓝 0 from hf.vanishing this
let f (x) := Real.exp x - 1
have : Set.Iio ε ∈ nhds (f 0) := by simpa [f] using Iio_mem_nhds hε
exact ContinuousAt.preimage_mem_nhds (by fun_prop) this
open Finset in
/-- In a complete normed ring, `∏' i, (1 + f i)` is convergent if the sum of real numbers
`∑' i, ‖f i‖` is convergent. -/
lemma multipliable_one_add_of_summable [CompleteSpace R]
(hf : Summable fun i ↦ ‖f i‖) : Multipliable fun i ↦ (1 + f i) := by
classical
refine CompleteSpace.complete <| Metric.cauchy_iff.mpr ⟨by infer_instance, fun ε hε ↦ ?_⟩
obtain ⟨r₁, hr₁, s₁, hs₁⟩ :=
(multipliable_norm_one_add_of_summable_norm hf).eventually_bounded_finset_prod
obtain ⟨s₂, hs₂⟩ := prod_vanishing_of_summable_norm hf (show 0 < ε / (2 * r₁) by positivity)
simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, le_eq_subset, Set.mem_preimage]
let s := s₁ ∪ s₂
-- The idea here is that if `s` is a large enough finset, then the product over `s` is bounded
-- by some `r`, and the product over finsets disjoint from `s` is within `ε / (2 * r)` of 1.
-- From this it follows that the products over any two finsets containing `s` are within `ε` of
-- each other.
-- Here `s₁ ⊆ s` guarantees that the product over `s` is bounded, and `s₂ ⊆ s` guarantees that
-- the product over terms not in `s` is small.
refine ⟨Metric.ball (∏ i ∈ s, (1 + f i)) (ε / 2), ⟨s, fun b hb ↦ ?_⟩, ?_⟩
· rw [← union_sdiff_of_subset hb, prod_union sdiff_disjoint.symm,
Metric.mem_ball, dist_eq_norm_sub, ← mul_sub_one,
show ε / 2 = r₁ * (ε / (2 * r₁)) by field_simp [hr₁]; ring]
apply (norm_mul_le _ _).trans_lt
refine lt_of_le_of_lt (b := r₁ * ‖∏ x ∈ b \ s, (1 + f x) - 1‖) ?_ ?_
· refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)
exact (Finset.norm_prod_le _ _).trans (hs₁ _ subset_union_left)
· refine mul_lt_mul_of_pos_left (hs₂ _ ?_) hr₁
simp [s, sdiff_union_distrib, disjoint_iff_inter_eq_empty]
· intro x hx y hy
exact (dist_triangle_right _ _ (∏ i ∈ s, (1 + f i))).trans_lt (add_halves ε ▸ add_lt_add hx hy)
end NormedRing
|
ZMod.lean
|
/-
Copyright (c) 2025 Paul Lezeau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul Lezeau, Oliver Nash, Yaël Dillies
-/
import Mathlib.Order.Circular
import Mathlib.Order.Fin.Basic
import Mathlib.Data.ZMod.Defs
/-!
# The circular order on `ZMod n`
This file defines the circular order on `ZMod n`.
-/
instance : CircularOrder ℤ := LinearOrder.toCircularOrder _
variable {a b c : ℤ}
lemma Int.btw_iff : btw a b c ↔ a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b := .rfl
lemma Int.sbtw_iff : sbtw a b c ↔ a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b := .rfl
instance (n : ℕ) : CircularOrder (Fin n) := LinearOrder.toCircularOrder _
variable {n : ℕ} {a b c : Fin n}
lemma Fin.btw_iff : btw a b c ↔ a ≤ b ∧ b ≤ c ∨ b ≤ c ∧ c ≤ a ∨ c ≤ a ∧ a ≤ b := .rfl
lemma Fin.sbtw_iff : sbtw a b c ↔ a < b ∧ b < c ∨ b < c ∧ c < a ∨ c < a ∧ a < b := .rfl
instance : ∀ (n : ℕ), CircularOrder (ZMod n)
| 0 => inferInstanceAs <| CircularOrder ℤ
| n + 1 => inferInstanceAs <| CircularOrder <| Fin <| n + 1
|
BilinearForm.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying
-/
import Mathlib.LinearAlgebra.BilinearForm.Properties
import Mathlib.LinearAlgebra.Matrix.SesquilinearForm
/-!
# Bilinear form
This file defines the conversion between bilinear forms and matrices.
## Main definitions
* `Matrix.toBilin` given a basis define a bilinear form
* `Matrix.toBilin'` define the bilinear form on `n → R`
* `BilinForm.toMatrix`: calculate the matrix coefficients of a bilinear form
* `BilinForm.toMatrix'`: calculate the matrix coefficients of a bilinear form on `n → R`
## Notations
In this file we use the following type variables:
- `M₁` is a module over the commutative semiring `R₁`,
- `M₂` is a module over the commutative ring `R₂`.
## Tags
bilinear form, bilin form, BilinearForm, matrix, basis
-/
open LinearMap (BilinForm)
open Module
variable {R₁ : Type*} {M₁ : Type*} [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁]
variable {R₂ : Type*} {M₂ : Type*} [CommRing R₂] [AddCommGroup M₂] [Module R₂ M₂]
section Matrix
variable {n o : Type*}
open Finset LinearMap Matrix
open Matrix
/-- The map from `Matrix n n R` to bilinear forms on `n → R`.
This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/
def Matrix.toBilin'Aux [Fintype n] (M : Matrix n n R₁) : BilinForm R₁ (n → R₁) :=
Matrix.toLinearMap₂'Aux _ _ M
theorem Matrix.toBilin'Aux_single [Fintype n] [DecidableEq n] (M : Matrix n n R₁) (i j : n) :
M.toBilin'Aux (Pi.single i 1) (Pi.single j 1) = M i j :=
Matrix.toLinearMap₂'Aux_single _ _ _ _ _
/-- The linear map from bilinear forms to `Matrix n n R` given an `n`-indexed basis.
This is an auxiliary definition for the equivalence `Matrix.toBilin'`. -/
def BilinForm.toMatrixAux (b : n → M₁) : BilinForm R₁ M₁ →ₗ[R₁] Matrix n n R₁ :=
LinearMap.toMatrix₂Aux R₁ b b
@[simp]
theorem LinearMap.BilinForm.toMatrixAux_apply (B : BilinForm R₁ M₁) (b : n → M₁) (i j : n) :
BilinForm.toMatrixAux b B i j = B (b i) (b j) :=
LinearMap.toMatrix₂Aux_apply R₁ B _ _ _ _
variable [Fintype n] [Fintype o]
theorem toBilin'Aux_toMatrixAux [DecidableEq n] (B₂ : BilinForm R₁ (n → R₁)) :
Matrix.toBilin'Aux (BilinForm.toMatrixAux (fun j => Pi.single j 1) B₂) = B₂ := by
rw [BilinForm.toMatrixAux, Matrix.toBilin'Aux, toLinearMap₂'Aux_toMatrix₂Aux]
section ToMatrix'
/-! ### `ToMatrix'` section
This section deals with the conversion between matrices and bilinear forms on `n → R₂`.
-/
variable [DecidableEq n] [DecidableEq o]
/-- The linear equivalence between bilinear forms on `n → R` and `n × n` matrices -/
def LinearMap.BilinForm.toMatrix' : BilinForm R₁ (n → R₁) ≃ₗ[R₁] Matrix n n R₁ :=
LinearMap.toMatrix₂' R₁
/-- The linear equivalence between `n × n` matrices and bilinear forms on `n → R` -/
def Matrix.toBilin' : Matrix n n R₁ ≃ₗ[R₁] BilinForm R₁ (n → R₁) :=
BilinForm.toMatrix'.symm
@[simp]
theorem Matrix.toBilin'Aux_eq (M : Matrix n n R₁) : Matrix.toBilin'Aux M = Matrix.toBilin' M :=
rfl
theorem Matrix.toBilin'_apply (M : Matrix n n R₁) (x y : n → R₁) :
Matrix.toBilin' M x y = ∑ i, ∑ j, x i * M i j * y j :=
(Matrix.toLinearMap₂'_apply _ _ _).trans
(by simp only [smul_eq_mul, mul_comm, mul_left_comm])
theorem Matrix.toBilin'_apply' (M : Matrix n n R₁) (v w : n → R₁) :
Matrix.toBilin' M v w = v ⬝ᵥ M *ᵥ w := Matrix.toLinearMap₂'_apply' _ _ _
@[simp]
theorem Matrix.toBilin'_single (M : Matrix n n R₁) (i j : n) :
Matrix.toBilin' M (Pi.single i 1) (Pi.single j 1) = M i j := by
simp [Matrix.toBilin'_apply, Pi.single_apply]
@[simp]
theorem LinearMap.BilinForm.toMatrix'_symm :
(BilinForm.toMatrix'.symm : Matrix n n R₁ ≃ₗ[R₁] _) = Matrix.toBilin' :=
rfl
@[simp]
theorem Matrix.toBilin'_symm :
(Matrix.toBilin'.symm : _ ≃ₗ[R₁] Matrix n n R₁) = BilinForm.toMatrix' :=
BilinForm.toMatrix'.symm_symm
@[simp]
theorem Matrix.toBilin'_toMatrix' (B : BilinForm R₁ (n → R₁)) :
Matrix.toBilin' (BilinForm.toMatrix' B) = B :=
Matrix.toBilin'.apply_symm_apply B
namespace LinearMap
@[simp]
theorem BilinForm.toMatrix'_toBilin' (M : Matrix n n R₁) :
BilinForm.toMatrix' (Matrix.toBilin' M) = M :=
(LinearMap.toMatrix₂' R₁).apply_symm_apply M
@[simp]
theorem BilinForm.toMatrix'_apply (B : BilinForm R₁ (n → R₁)) (i j : n) :
BilinForm.toMatrix' B i j = B (Pi.single i 1) (Pi.single j 1) :=
LinearMap.toMatrix₂'_apply _ _ _
@[simp]
theorem BilinForm.toMatrix'_comp (B : BilinForm R₁ (n → R₁)) (l r : (o → R₁) →ₗ[R₁] n → R₁) :
(B.comp l r).toMatrix' = l.toMatrix'ᵀ * B.toMatrix' * r.toMatrix' :=
B.toMatrix₂'_compl₁₂ _ _
theorem BilinForm.toMatrix'_compLeft (B : BilinForm R₁ (n → R₁)) (f : (n → R₁) →ₗ[R₁] n → R₁) :
(B.compLeft f).toMatrix' = f.toMatrix'ᵀ * B.toMatrix' :=
B.toMatrix₂'_comp _
theorem BilinForm.toMatrix'_compRight (B : BilinForm R₁ (n → R₁)) (f : (n → R₁) →ₗ[R₁] n → R₁) :
(B.compRight f).toMatrix' = B.toMatrix' * f.toMatrix' :=
B.toMatrix₂'_compl₂ _
theorem BilinForm.mul_toMatrix'_mul (B : BilinForm R₁ (n → R₁)) (M : Matrix o n R₁)
(N : Matrix n o R₁) : M * B.toMatrix' * N = (B.comp (Mᵀ).toLin' N.toLin').toMatrix' :=
B.mul_toMatrix₂'_mul _ _
theorem BilinForm.mul_toMatrix' (B : BilinForm R₁ (n → R₁)) (M : Matrix n n R₁) :
M * B.toMatrix' = (B.compLeft (Mᵀ).toLin').toMatrix' :=
LinearMap.mul_toMatrix' B _
theorem BilinForm.toMatrix'_mul (B : BilinForm R₁ (n → R₁)) (M : Matrix n n R₁) :
BilinForm.toMatrix' B * M = BilinForm.toMatrix' (B.compRight (Matrix.toLin' M)) :=
B.toMatrix₂'_mul _
end LinearMap
theorem Matrix.toBilin'_comp (M : Matrix n n R₁) (P Q : Matrix n o R₁) :
M.toBilin'.comp P.toLin' Q.toLin' = (Pᵀ * M * Q).toBilin' :=
BilinForm.toMatrix'.injective
(by simp only [BilinForm.toMatrix'_comp, BilinForm.toMatrix'_toBilin', toMatrix'_toLin'])
end ToMatrix'
section ToMatrix
/-! ### `ToMatrix` section
This section deals with the conversion between matrices and bilinear forms on
a module with a fixed basis.
-/
variable [DecidableEq n] (b : Basis n R₁ M₁)
/-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def BilinForm.toMatrix : BilinForm R₁ M₁ ≃ₗ[R₁] Matrix n n R₁ :=
LinearMap.toMatrix₂ b b
/-- `BilinForm.toMatrix b` is the equivalence between `R`-bilinear forms on `M` and
`n`-by-`n` matrices with entries in `R`, if `b` is an `R`-basis for `M`. -/
noncomputable def Matrix.toBilin : Matrix n n R₁ ≃ₗ[R₁] BilinForm R₁ M₁ :=
(BilinForm.toMatrix b).symm
@[simp]
theorem BilinForm.toMatrix_apply (B : BilinForm R₁ M₁) (i j : n) :
BilinForm.toMatrix b B i j = B (b i) (b j) :=
LinearMap.toMatrix₂_apply _ _ B _ _
theorem BilinForm.dotProduct_toMatrix_mulVec (B : BilinForm R₁ M₁) (x y : n → R₁) :
x ⬝ᵥ (BilinForm.toMatrix b B) *ᵥ y = B (b.equivFun.symm x) (b.equivFun.symm y) := by
simp only [dotProduct, mulVec_eq_sum, op_smul_eq_smul, Finset.sum_apply, Pi.smul_apply,
transpose_apply, toMatrix_apply, smul_eq_mul, mul_sum, Basis.equivFun_symm_apply, map_sum,
map_smul, coeFn_sum, LinearMap.smul_apply]
rw [Finset.sum_comm]
refine Finset.sum_congr rfl (fun i _ ↦ Finset.sum_congr rfl fun j _ ↦ ?_)
ring
lemma BilinForm.apply_eq_dotProduct_toMatrix_mulVec (B : BilinForm R₁ M₁) (x y : M₁) :
B x y = (b.repr x) ⬝ᵥ (BilinForm.toMatrix b B) *ᵥ (b.repr y) := by
nth_rw 1 [← b.sum_repr x, ← b.sum_repr y]
suffices ∑ j, ∑ i, b.repr y j * b.repr x i * B (b i) (b j) =
∑ i, ∑ j, b.repr x i * b.repr y j * B (b i) (b j) by
simpa [dotProduct, Matrix.mulVec_eq_sum, Finset.mul_sum, -Basis.sum_repr, ← mul_assoc]
simp_rw [mul_comm (b.repr y _)]
exact Finset.sum_comm
@[simp]
theorem Matrix.toBilin_apply (M : Matrix n n R₁) (x y : M₁) :
Matrix.toBilin b M x y = ∑ i, ∑ j, b.repr x i * M i j * b.repr y j :=
(Matrix.toLinearMap₂_apply _ _ _ _ _).trans
(by simp only [smul_eq_mul, mul_comm, mul_left_comm])
-- Not a `simp` lemma since `BilinForm.toMatrix` needs an extra argument
theorem BilinearForm.toMatrixAux_eq (B : BilinForm R₁ M₁) :
BilinForm.toMatrixAux (R₁ := R₁) b B = BilinForm.toMatrix b B :=
LinearMap.toMatrix₂Aux_eq _ _ B
@[simp]
theorem BilinForm.toMatrix_symm : (BilinForm.toMatrix b).symm = Matrix.toBilin b :=
rfl
@[simp]
theorem Matrix.toBilin_symm : (Matrix.toBilin b).symm = BilinForm.toMatrix b :=
(BilinForm.toMatrix b).symm_symm
theorem Matrix.toBilin_basisFun : Matrix.toBilin (Pi.basisFun R₁ n) = Matrix.toBilin' := by
ext M
simp only [coe_comp, coe_single, Function.comp_apply, toBilin_apply, Pi.basisFun_repr,
toBilin'_apply]
theorem BilinForm.toMatrix_basisFun :
BilinForm.toMatrix (Pi.basisFun R₁ n) = BilinForm.toMatrix' := by
rw [BilinForm.toMatrix, BilinForm.toMatrix', LinearMap.toMatrix₂_basisFun]
@[simp]
theorem Matrix.toBilin_toMatrix (B : BilinForm R₁ M₁) :
Matrix.toBilin b (BilinForm.toMatrix b B) = B :=
(Matrix.toBilin b).apply_symm_apply B
@[simp]
theorem BilinForm.toMatrix_toBilin (M : Matrix n n R₁) :
BilinForm.toMatrix b (Matrix.toBilin b M) = M :=
(BilinForm.toMatrix b).apply_symm_apply M
variable {M₂' : Type*} [AddCommMonoid M₂'] [Module R₁ M₂']
variable (c : Basis o R₁ M₂')
variable [DecidableEq o]
-- Cannot be a `simp` lemma because `b` must be inferred.
theorem BilinForm.toMatrix_comp (B : BilinForm R₁ M₁) (l r : M₂' →ₗ[R₁] M₁) :
BilinForm.toMatrix c (B.comp l r) =
(LinearMap.toMatrix c b l)ᵀ * BilinForm.toMatrix b B * LinearMap.toMatrix c b r :=
LinearMap.toMatrix₂_compl₁₂ _ _ _ _ B _ _
theorem BilinForm.toMatrix_compLeft (B : BilinForm R₁ M₁) (f : M₁ →ₗ[R₁] M₁) :
BilinForm.toMatrix b (B.compLeft f) = (LinearMap.toMatrix b b f)ᵀ * BilinForm.toMatrix b B :=
LinearMap.toMatrix₂_comp _ _ _ B _
theorem BilinForm.toMatrix_compRight (B : BilinForm R₁ M₁) (f : M₁ →ₗ[R₁] M₁) :
BilinForm.toMatrix b (B.compRight f) = BilinForm.toMatrix b B * LinearMap.toMatrix b b f :=
LinearMap.toMatrix₂_compl₂ _ _ _ B _
@[simp]
theorem BilinForm.toMatrix_mul_basis_toMatrix (c : Basis o R₁ M₁) (B : BilinForm R₁ M₁) :
(b.toMatrix c)ᵀ * BilinForm.toMatrix b B * b.toMatrix c = BilinForm.toMatrix c B :=
LinearMap.toMatrix₂_mul_basis_toMatrix _ _ _ _ B
theorem BilinForm.mul_toMatrix_mul (B : BilinForm R₁ M₁) (M : Matrix o n R₁) (N : Matrix n o R₁) :
M * BilinForm.toMatrix b B * N =
BilinForm.toMatrix c (B.comp (Matrix.toLin c b Mᵀ) (Matrix.toLin c b N)) :=
LinearMap.mul_toMatrix₂_mul _ _ _ _ B _ _
theorem BilinForm.mul_toMatrix (B : BilinForm R₁ M₁) (M : Matrix n n R₁) :
M * BilinForm.toMatrix b B = BilinForm.toMatrix b (B.compLeft (Matrix.toLin b b Mᵀ)) :=
LinearMap.mul_toMatrix₂ _ _ _ B _
theorem BilinForm.toMatrix_mul (B : BilinForm R₁ M₁) (M : Matrix n n R₁) :
BilinForm.toMatrix b B * M = BilinForm.toMatrix b (B.compRight (Matrix.toLin b b M)) :=
LinearMap.toMatrix₂_mul _ _ _ B _
theorem Matrix.toBilin_comp (M : Matrix n n R₁) (P Q : Matrix n o R₁) :
(Matrix.toBilin b M).comp (toLin c b P) (toLin c b Q) = Matrix.toBilin c (Pᵀ * M * Q) := by
ext x y
rw [Matrix.toBilin, BilinForm.toMatrix, Matrix.toBilin, BilinForm.toMatrix, toMatrix₂_symm,
toMatrix₂_symm, ← Matrix.toLinearMap₂_compl₁₂ b b c c]
simp
end ToMatrix
end Matrix
section MatrixAdjoints
open Matrix
variable {n : Type*} [Fintype n]
variable (b : Basis n R₂ M₂)
variable (J J₃ A A' : Matrix n n R₂)
theorem Matrix.isAdjointPair_equiv' [DecidableEq n] (P : Matrix n n R₂) (h : IsUnit P) :
(Pᵀ * J * P).IsAdjointPair (Pᵀ * J * P) A A' ↔
J.IsAdjointPair J (P * A * P⁻¹) (P * A' * P⁻¹) :=
Matrix.isAdjointPair_equiv _ _ _ _ h
variable [DecidableEq n]
theorem mem_pairSelfAdjointMatricesSubmodule' :
A ∈ pairSelfAdjointMatricesSubmodule J J₃ ↔ Matrix.IsAdjointPair J J₃ A A := by
simp only [mem_pairSelfAdjointMatricesSubmodule]
/-- The submodule of self-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def selfAdjointMatricesSubmodule' : Submodule R₂ (Matrix n n R₂) :=
pairSelfAdjointMatricesSubmodule J J
theorem mem_selfAdjointMatricesSubmodule' :
A ∈ selfAdjointMatricesSubmodule J ↔ J.IsSelfAdjoint A := by
simp only [mem_selfAdjointMatricesSubmodule]
/-- The submodule of skew-adjoint matrices with respect to the bilinear form corresponding to
the matrix `J`. -/
def skewAdjointMatricesSubmodule' : Submodule R₂ (Matrix n n R₂) :=
pairSelfAdjointMatricesSubmodule (-J) J
theorem mem_skewAdjointMatricesSubmodule' :
A ∈ skewAdjointMatricesSubmodule J ↔ J.IsSkewAdjoint A := by
simp only [mem_skewAdjointMatricesSubmodule]
end MatrixAdjoints
namespace LinearMap
namespace BilinForm
section Det
open Matrix
variable {A : Type*} [CommRing A] [IsDomain A] [Module A M₂] (B₃ : BilinForm A M₂)
variable {ι : Type*} [DecidableEq ι] [Fintype ι]
theorem _root_.Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin {M : Matrix ι ι R₁}
(b : Basis ι R₁ M₁) : M.toBilin'.Nondegenerate ↔ (Matrix.toBilin b M).Nondegenerate :=
(nondegenerate_congr_iff b.equivFun.symm).symm
-- Lemmas transferring nondegeneracy between a matrix and its associated bilinear form
theorem _root_.Matrix.Nondegenerate.toBilin' {M : Matrix ι ι R₂} (h : M.Nondegenerate) :
M.toBilin'.Nondegenerate := fun x hx =>
h.eq_zero_of_ortho fun y => by simpa only [toBilin'_apply'] using hx y
@[simp]
theorem _root_.Matrix.nondegenerate_toBilin'_iff {M : Matrix ι ι R₂} :
M.toBilin'.Nondegenerate ↔ M.Nondegenerate := by
refine ⟨fun h ↦ Matrix.nondegenerate_def.mpr ?_, Matrix.Nondegenerate.toBilin'⟩
exact fun v hv => h v fun w => (M.toBilin'_apply' _ _).trans <| hv w
theorem _root_.Matrix.Nondegenerate.toBilin {M : Matrix ι ι R₂} (h : M.Nondegenerate)
(b : Basis ι R₂ M₂) : (Matrix.toBilin b M).Nondegenerate :=
(Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin b).mp h.toBilin'
@[simp]
theorem _root_.Matrix.nondegenerate_toBilin_iff {M : Matrix ι ι R₂} (b : Basis ι R₂ M₂) :
(Matrix.toBilin b M).Nondegenerate ↔ M.Nondegenerate := by
rw [← Matrix.nondegenerate_toBilin'_iff_nondegenerate_toBilin, Matrix.nondegenerate_toBilin'_iff]
/-! Lemmas transferring nondegeneracy between a bilinear form and its associated matrix -/
@[simp]
theorem nondegenerate_toMatrix'_iff {B : BilinForm R₂ (ι → R₂)} :
B.toMatrix'.Nondegenerate (m := ι) ↔ B.Nondegenerate :=
Matrix.nondegenerate_toBilin'_iff.symm.trans <| (Matrix.toBilin'_toMatrix' B).symm ▸ Iff.rfl
theorem Nondegenerate.toMatrix' {B : BilinForm R₂ (ι → R₂)} (h : B.Nondegenerate) :
B.toMatrix'.Nondegenerate :=
nondegenerate_toMatrix'_iff.mpr h
@[simp]
theorem nondegenerate_toMatrix_iff {B : BilinForm R₂ M₂} (b : Basis ι R₂ M₂) :
(BilinForm.toMatrix b B).Nondegenerate ↔ B.Nondegenerate :=
(Matrix.nondegenerate_toBilin_iff b).symm.trans <| (Matrix.toBilin_toMatrix b B).symm ▸ Iff.rfl
theorem Nondegenerate.toMatrix {B : BilinForm R₂ M₂} (h : B.Nondegenerate) (b : Basis ι R₂ M₂) :
(BilinForm.toMatrix b B).Nondegenerate :=
(nondegenerate_toMatrix_iff b).mpr h
/-! Some shorthands for combining the above with `Matrix.nondegenerate_of_det_ne_zero` -/
theorem nondegenerate_toBilin'_iff_det_ne_zero {M : Matrix ι ι A} :
M.toBilin'.Nondegenerate ↔ M.det ≠ 0 := by
rw [Matrix.nondegenerate_toBilin'_iff, Matrix.nondegenerate_iff_det_ne_zero]
theorem nondegenerate_toBilin'_of_det_ne_zero' (M : Matrix ι ι A) (h : M.det ≠ 0) :
M.toBilin'.Nondegenerate :=
nondegenerate_toBilin'_iff_det_ne_zero.mpr h
theorem nondegenerate_iff_det_ne_zero {B : BilinForm A M₂} (b : Basis ι A M₂) :
B.Nondegenerate ↔ (BilinForm.toMatrix b B).det ≠ 0 := by
rw [← Matrix.nondegenerate_iff_det_ne_zero, nondegenerate_toMatrix_iff]
theorem nondegenerate_of_det_ne_zero (b : Basis ι A M₂) (h : (BilinForm.toMatrix b B₃).det ≠ 0) :
B₃.Nondegenerate :=
(nondegenerate_iff_det_ne_zero b).mpr h
end Det
end BilinForm
end LinearMap
|
NonLocalRing.lean
|
/-
Copyright (c) 2025 Michal Staromiejski. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michal Staromiejski
-/
import Mathlib.Algebra.Ring.Pi
import Mathlib.Algebra.Ring.Prod
import Mathlib.RingTheory.LocalRing.MaximalIdeal.Basic
import Mathlib.RingTheory.Spectrum.Maximal.Basic
/-!
# Non-local rings
This file gathers some results about non-local rings.
## Main results
- `not_isLocalRing_of_nontrivial_pi`: for an index type `ι` with at least two elements and
an indexed family of (semi)rings `R : ι → Type*`, the indexed product (semi)ring
`Π i, R i` is not local.
- `not_isLocalRing_of_prod_of_nontrivial`: the product of two nontrivial (semi)rings is not
local.
- `not_isLocalRing_tfae`: the following conditions are equivalent for a commutative (semi)ring `R`:
* `R` is not local,
* the maximal spectrum of `R` is nontrivial,
* `R` has two distinct maximal ideals.
- `exists_surjective_of_not_isLocalRing`: there exists a surjective ring homomorphism from
a non-local commutative ring onto a product of two fields.
-/
namespace IsLocalRing
/-- If two non-units sum to 1 in a (semi)ring `R` then `R` is not local. -/
theorem not_isLocalRing_def {R : Type*} [Semiring R] {a b : R} (ha : ¬IsUnit a) (hb : ¬IsUnit b)
(hab : a + b = 1) : ¬IsLocalRing R :=
fun _ ↦ hb <| (isUnit_or_isUnit_of_add_one hab).resolve_left ha
/-- For an index type `ι` with at least two elements and an indexed family of (semi)rings
`R : ι → Type*`, the indexed product (semi)ring `Π i, R i` is not local. -/
theorem not_isLocalRing_of_nontrivial_pi {ι : Type*} [Nontrivial ι] (R : ι → Type*)
[∀ i, Semiring (R i)] [∀ i, Nontrivial (R i)] : ¬IsLocalRing (Π i, R i) := by
classical
let ⟨i₁, i₂, hi⟩ := exists_pair_ne ι
have ha : ¬IsUnit (fun i ↦ if i = i₁ then 0 else 1 : Π i, R i) :=
fun h ↦ not_isUnit_zero (M₀ := R i₁) (by simpa using h.map (Pi.evalRingHom R i₁))
have hb : ¬IsUnit (fun i ↦ if i = i₁ then 1 else 0 : Π i, R i) :=
fun h ↦ not_isUnit_zero (M₀ := R i₂) (by simpa [hi.symm] using h.map (Pi.evalRingHom R i₂))
exact not_isLocalRing_def ha hb (by ext; dsimp; split <;> simp)
/-- The product of two nontrivial (semi)rings is not local. -/
theorem not_isLocalRing_of_prod_of_nontrivial (R₁ R₂ : Type*) [Semiring R₁] [Semiring R₂]
[Nontrivial R₁] [Nontrivial R₂] : ¬IsLocalRing (R₁ × R₂) :=
have ha : ¬IsUnit ((1, 0) : R₁ × R₂) :=
fun h ↦ not_isUnit_zero (M₀ := R₁) (by simpa using h.map (RingHom.snd R₁ R₂))
have hb : ¬IsUnit ((0, 1) : R₁ × R₂) :=
fun h ↦ not_isUnit_zero (M₀ := R₂) (by simpa using h.map (RingHom.fst R₁ R₂))
not_isLocalRing_def ha hb (by simp)
/-- The following conditions are equivalent for a commutative (semi)ring `R`:
* `R` is not local,
* the maximal spectrum of `R` is nontrivial,
* `R` has two distinct maximal ideals.
-/
theorem not_isLocalRing_tfae {R : Type*} [CommSemiring R] [Nontrivial R] :
List.TFAE [
¬IsLocalRing R,
Nontrivial (MaximalSpectrum R),
∃ m₁ m₂ : Ideal R, m₁.IsMaximal ∧ m₂.IsMaximal ∧ m₁ ≠ m₂] := by
tfae_have 1 → 2
| h => not_subsingleton_iff_nontrivial.mp fun _ ↦ h of_singleton_maximalSpectrum
tfae_have 2 → 3
| ⟨⟨m₁, hm₁⟩, ⟨m₂, hm₂⟩, h⟩ => ⟨m₁, m₂, ⟨hm₁, hm₂, fun _ ↦ h (by congr)⟩⟩
tfae_have 3 → 1
| ⟨m₁, m₂, ⟨hm₁, hm₂, h⟩⟩ => fun _ ↦ h <| (eq_maximalIdeal hm₁).trans (eq_maximalIdeal hm₂).symm
tfae_finish
/-- There exists a surjective ring homomorphism from a non-local commutative ring onto a product
of two fields. -/
theorem exists_surjective_of_not_isLocalRing.{u} {R : Type u} [CommRing R] [Nontrivial R]
(h : ¬IsLocalRing R) :
∃ (K₁ K₂ : Type u) (_ : Field K₁) (_ : Field K₂) (f : R →+* K₁ × K₂),
Function.Surjective f := by
/- get two different maximal ideals and project on the product of quotients -/
obtain ⟨m₁, m₂, _, _, hm₁m₂⟩ := (not_isLocalRing_tfae.out 0 2).mp h
let e := Ideal.quotientInfEquivQuotientProd m₁ m₂ <| Ideal.isCoprime_of_isMaximal hm₁m₂
let f := e.toRingHom.comp <| Ideal.Quotient.mk (m₁ ⊓ m₂)
use R ⧸ m₁, R ⧸ m₂, Ideal.Quotient.field m₁, Ideal.Quotient.field m₂, f
apply Function.Surjective.comp e.surjective Ideal.Quotient.mk_surjective
end IsLocalRing
|
BoundedLinearMaps.lean
|
/-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import Mathlib.Analysis.NormedSpace.Multilinear.Basic
import Mathlib.Analysis.Normed.Ring.Units
import Mathlib.Analysis.NormedSpace.OperatorNorm.Mul
/-!
# Bounded linear maps
This file defines a class stating that a map between normed vector spaces is (bi)linear and
continuous.
Instead of asking for continuity, the definition takes the equivalent condition (because the space
is normed) that `‖f x‖` is bounded by a multiple of `‖x‖`. Hence the "bounded" in the name refers to
`‖f x‖/‖x‖` rather than `‖f x‖` itself.
## Main definitions
* `IsBoundedLinearMap`: Class stating that a map `f : E → F` is linear and has `‖f x‖` bounded
by a multiple of `‖x‖`.
* `IsBoundedBilinearMap`: Class stating that a map `f : E × F → G` is bilinear and continuous,
but through the simpler to provide statement that `‖f (x, y)‖` is bounded by a multiple of
`‖x‖ * ‖y‖`
* `IsBoundedBilinearMap.linearDeriv`: Derivative of a continuous bilinear map as a linear map.
* `IsBoundedBilinearMap.deriv`: Derivative of a continuous bilinear map as a continuous linear
map. The proof that it is indeed the derivative is `IsBoundedBilinearMap.hasFDerivAt` in
`Analysis.Calculus.FDeriv`.
## Main theorems
* `IsBoundedBilinearMap.continuous`: A bounded bilinear map is continuous.
* `ContinuousLinearEquiv.isOpen`: The continuous linear equivalences are an open subset of the
set of continuous linear maps between a pair of Banach spaces. Placed in this file because its
proof uses `IsBoundedBilinearMap.continuous`.
## Notes
The main use of this file is `IsBoundedBilinearMap`.
The file `Analysis.NormedSpace.Multilinear.Basic`
already expounds the theory of multilinear maps,
but the `2`-variables case is sufficiently simpler to currently deserve its own treatment.
`IsBoundedLinearMap` is effectively an unbundled version of `ContinuousLinearMap` (defined
in `Topology.Algebra.Module.Basic`, theory over normed spaces developed in
`Analysis.NormedSpace.OperatorNorm`), albeit the name disparity. A bundled
`ContinuousLinearMap` is to be preferred over an `IsBoundedLinearMap` hypothesis. Historical
artifact, really.
-/
noncomputable section
open Topology
open Filter (Tendsto)
open Metric ContinuousLinearMap
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [SeminormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type*} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type*}
[SeminormedAddCommGroup G] [NormedSpace 𝕜 G]
/-- A function `f` satisfies `IsBoundedLinearMap 𝕜 f` if it is linear and satisfies the
inequality `‖f x‖ ≤ M * ‖x‖` for some positive constant `M`. -/
structure IsBoundedLinearMap (𝕜 : Type*) [NormedField 𝕜] {E : Type*} [SeminormedAddCommGroup E]
[NormedSpace 𝕜 E] {F : Type*} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F] (f : E → F) : Prop
extends IsLinearMap 𝕜 f where
bound : ∃ M, 0 < M ∧ ∀ x : E, ‖f x‖ ≤ M * ‖x‖
lemma isBoundedLinearMap_iff {f : E → F} :
IsBoundedLinearMap 𝕜 f ↔ IsLinearMap 𝕜 f ∧ ∃ M, 0 < M ∧ ∀ x : E, ‖f x‖ ≤ M * ‖x‖ :=
⟨fun hf ↦ ⟨hf.toIsLinearMap, hf.bound⟩, fun ⟨hl, hm⟩ ↦ ⟨hl, hm⟩⟩
theorem IsLinearMap.with_bound {f : E → F} (hf : IsLinearMap 𝕜 f) (M : ℝ)
(h : ∀ x : E, ‖f x‖ ≤ M * ‖x‖) : IsBoundedLinearMap 𝕜 f :=
⟨hf,
by_cases
(fun (this : M ≤ 0) =>
⟨1, zero_lt_one, fun x =>
(h x).trans <| mul_le_mul_of_nonneg_right (this.trans zero_le_one) (norm_nonneg x)⟩)
fun (this : ¬M ≤ 0) => ⟨M, lt_of_not_ge this, h⟩⟩
/-- A continuous linear map satisfies `IsBoundedLinearMap` -/
theorem ContinuousLinearMap.isBoundedLinearMap (f : E →L[𝕜] F) : IsBoundedLinearMap 𝕜 f :=
{ f.toLinearMap.isLinear with bound := f.bound }
namespace IsBoundedLinearMap
/-- Construct a linear map from a function `f` satisfying `IsBoundedLinearMap 𝕜 f`. -/
def toLinearMap (f : E → F) (h : IsBoundedLinearMap 𝕜 f) : E →ₗ[𝕜] F :=
IsLinearMap.mk' _ h.toIsLinearMap
/-- Construct a continuous linear map from `IsBoundedLinearMap`. -/
def toContinuousLinearMap {f : E → F} (hf : IsBoundedLinearMap 𝕜 f) : E →L[𝕜] F :=
{ toLinearMap f hf with
cont :=
let ⟨C, _, hC⟩ := hf.bound
AddMonoidHomClass.continuous_of_bound (toLinearMap f hf) C hC }
theorem zero : IsBoundedLinearMap 𝕜 fun _ : E => (0 : F) :=
(0 : E →ₗ[𝕜] F).isLinear.with_bound 0 <| by simp [le_refl]
theorem id : IsBoundedLinearMap 𝕜 fun x : E => x :=
LinearMap.id.isLinear.with_bound 1 <| by simp [le_refl]
theorem fst : IsBoundedLinearMap 𝕜 fun x : E × F => x.1 := by
refine (LinearMap.fst 𝕜 E F).isLinear.with_bound 1 fun x => ?_
rw [one_mul]
exact le_max_left _ _
theorem snd : IsBoundedLinearMap 𝕜 fun x : E × F => x.2 := by
refine (LinearMap.snd 𝕜 E F).isLinear.with_bound 1 fun x => ?_
rw [one_mul]
exact le_max_right _ _
variable {f g : E → F}
theorem smul (c : 𝕜) (hf : IsBoundedLinearMap 𝕜 f) : IsBoundedLinearMap 𝕜 (c • f) :=
let ⟨hlf, M, _, hM⟩ := hf
(c • hlf.mk' f).isLinear.with_bound (‖c‖ * M) fun x =>
calc
‖c • f x‖ = ‖c‖ * ‖f x‖ := norm_smul c (f x)
_ ≤ ‖c‖ * (M * ‖x‖) := mul_le_mul_of_nonneg_left (hM _) (norm_nonneg _)
_ = ‖c‖ * M * ‖x‖ := (mul_assoc _ _ _).symm
theorem neg (hf : IsBoundedLinearMap 𝕜 f) : IsBoundedLinearMap 𝕜 fun e => -f e := by
rw [show (fun e => -f e) = fun e => (-1 : 𝕜) • f e by funext; simp]
exact smul (-1) hf
theorem add (hf : IsBoundedLinearMap 𝕜 f) (hg : IsBoundedLinearMap 𝕜 g) :
IsBoundedLinearMap 𝕜 fun e => f e + g e :=
let ⟨hlf, Mf, _, hMf⟩ := hf
let ⟨hlg, Mg, _, hMg⟩ := hg
(hlf.mk' _ + hlg.mk' _).isLinear.with_bound (Mf + Mg) fun x =>
calc
‖f x + g x‖ ≤ Mf * ‖x‖ + Mg * ‖x‖ := norm_add_le_of_le (hMf x) (hMg x)
_ ≤ (Mf + Mg) * ‖x‖ := by rw [add_mul]
theorem sub (hf : IsBoundedLinearMap 𝕜 f) (hg : IsBoundedLinearMap 𝕜 g) :
IsBoundedLinearMap 𝕜 fun e => f e - g e := by simpa [sub_eq_add_neg] using add hf (neg hg)
theorem comp {g : F → G} (hg : IsBoundedLinearMap 𝕜 g) (hf : IsBoundedLinearMap 𝕜 f) :
IsBoundedLinearMap 𝕜 (g ∘ f) :=
(hg.toContinuousLinearMap.comp hf.toContinuousLinearMap).isBoundedLinearMap
protected theorem tendsto (x : E) (hf : IsBoundedLinearMap 𝕜 f) : Tendsto f (𝓝 x) (𝓝 (f x)) :=
let ⟨hf, M, _, hM⟩ := hf
tendsto_iff_norm_sub_tendsto_zero.2 <|
squeeze_zero (fun _ => norm_nonneg _)
(fun e =>
calc
‖f e - f x‖ = ‖hf.mk' f (e - x)‖ := by rw [(hf.mk' _).map_sub e x]; rfl
_ ≤ M * ‖e - x‖ := hM (e - x)
)
(suffices Tendsto (fun e : E => M * ‖e - x‖) (𝓝 x) (𝓝 (M * 0)) by simpa
tendsto_const_nhds.mul (tendsto_norm_sub_self _))
theorem continuous (hf : IsBoundedLinearMap 𝕜 f) : Continuous f :=
continuous_iff_continuousAt.2 fun _ => hf.tendsto _
/-- A map between normed spaces is linear and continuous if and only if it is bounded. -/
theorem isLinearMap_and_continuous_iff_isBoundedLinearMap (f : E → F) :
IsLinearMap 𝕜 f ∧ Continuous f ↔ IsBoundedLinearMap 𝕜 f :=
⟨fun ⟨hlin, hcont⟩ ↦ ContinuousLinearMap.isBoundedLinearMap
⟨⟨⟨f, IsLinearMap.map_add hlin⟩, IsLinearMap.map_smul hlin⟩, hcont⟩,
fun h_bdd ↦ ⟨h_bdd.toIsLinearMap, h_bdd.continuous⟩⟩
theorem lim_zero_bounded_linear_map (hf : IsBoundedLinearMap 𝕜 f) : Tendsto f (𝓝 0) (𝓝 0) :=
(hf.1.mk' _).map_zero ▸ continuous_iff_continuousAt.1 hf.continuous 0
section
open Asymptotics Filter
theorem isBigO_id {f : E → F} (h : IsBoundedLinearMap 𝕜 f) (l : Filter E) : f =O[l] fun x => x :=
let ⟨_, _, hM⟩ := h.bound
IsBigO.of_bound _ (mem_of_superset univ_mem fun x _ => hM x)
theorem isBigO_comp {E : Type*} {g : F → G} (hg : IsBoundedLinearMap 𝕜 g) {f : E → F}
(l : Filter E) : (fun x' => g (f x')) =O[l] f :=
(hg.isBigO_id ⊤).comp_tendsto le_top
theorem isBigO_sub {f : E → F} (h : IsBoundedLinearMap 𝕜 f) (l : Filter E) (x : E) :
(fun x' => f (x' - x)) =O[l] fun x' => x' - x :=
isBigO_comp h l
end
end IsBoundedLinearMap
section
variable {ι : Type*} [Fintype ι]
/-- Taking the cartesian product of two continuous multilinear maps is a bounded linear
operation. -/
theorem isBoundedLinearMap_prod_multilinear {E : ι → Type*} [∀ i, SeminormedAddCommGroup (E i)]
[∀ i, NormedSpace 𝕜 (E i)] :
IsBoundedLinearMap 𝕜 fun p : ContinuousMultilinearMap 𝕜 E F × ContinuousMultilinearMap 𝕜 E G =>
p.1.prod p.2 :=
(ContinuousMultilinearMap.prodL 𝕜 E F G).toContinuousLinearEquiv
|>.toContinuousLinearMap.isBoundedLinearMap
/-- Given a fixed continuous linear map `g`, associating to a continuous multilinear map `f` the
continuous multilinear map `f (g m₁, ..., g mₙ)` is a bounded linear operation. -/
theorem isBoundedLinearMap_continuousMultilinearMap_comp_linear (g : G →L[𝕜] E) :
IsBoundedLinearMap 𝕜 fun f : ContinuousMultilinearMap 𝕜 (fun _ : ι => E) F =>
f.compContinuousLinearMap fun _ => g :=
(ContinuousMultilinearMap.compContinuousLinearMapL (ι := ι) (G := F) (fun _ ↦ g))
|>.isBoundedLinearMap
end
section BilinearMap
namespace ContinuousLinearMap
/-! We prove some computation rules for continuous (semi-)bilinear maps in their first argument.
If `f` is a continuous bilinear map, to use the corresponding rules for the second argument, use
`(f _).map_add` and similar.
We have to assume that `F` and `G` are normed spaces in this section, to use
`ContinuousLinearMap.toNormedAddCommGroup`, but we don't need to assume this for the first
argument of `f`.
-/
variable {R : Type*}
variable {𝕜₂ 𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NontriviallyNormedField 𝕜₂]
variable {M : Type*} [TopologicalSpace M]
variable {σ₁₂ : 𝕜 →+* 𝕜₂}
variable {G' : Type*} [SeminormedAddCommGroup G'] [NormedSpace 𝕜₂ G'] [NormedSpace 𝕜' G']
variable [SMulCommClass 𝕜₂ 𝕜' G']
section Semiring
variable [Semiring R] [AddCommMonoid M] [Module R M] {ρ₁₂ : R →+* 𝕜'}
theorem map_add₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x x' : M) (y : F) :
f (x + x') y = f x y + f x' y := by rw [f.map_add, add_apply]
theorem map_zero₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (y : F) : f 0 y = 0 := by
rw [f.map_zero, zero_apply]
theorem map_smulₛₗ₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (c : R) (x : M) (y : F) :
f (c • x) y = ρ₁₂ c • f x y := by rw [f.map_smulₛₗ, smul_apply]
end Semiring
section Ring
variable [Ring R] [AddCommGroup M] [Module R M] {ρ₁₂ : R →+* 𝕜'}
theorem map_sub₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x x' : M) (y : F) :
f (x - x') y = f x y - f x' y := by rw [f.map_sub, sub_apply]
theorem map_neg₂ (f : M →SL[ρ₁₂] F →SL[σ₁₂] G') (x : M) (y : F) : f (-x) y = -f x y := by
rw [f.map_neg, neg_apply]
end Ring
theorem map_smul₂ (f : E →L[𝕜] F →L[𝕜] G) (c : 𝕜) (x : E) (y : F) : f (c • x) y = c • f x y := by
rw [f.map_smul, smul_apply]
end ContinuousLinearMap
variable (𝕜) in
/-- A map `f : E × F → G` satisfies `IsBoundedBilinearMap 𝕜 f` if it is bilinear and
continuous. -/
structure IsBoundedBilinearMap (f : E × F → G) : Prop where
add_left : ∀ (x₁ x₂ : E) (y : F), f (x₁ + x₂, y) = f (x₁, y) + f (x₂, y)
smul_left : ∀ (c : 𝕜) (x : E) (y : F), f (c • x, y) = c • f (x, y)
add_right : ∀ (x : E) (y₁ y₂ : F), f (x, y₁ + y₂) = f (x, y₁) + f (x, y₂)
smul_right : ∀ (c : 𝕜) (x : E) (y : F), f (x, c • y) = c • f (x, y)
bound : ∃ C > 0, ∀ (x : E) (y : F), ‖f (x, y)‖ ≤ C * ‖x‖ * ‖y‖
variable {f : E × F → G}
lemma IsBoundedBilinearMap.symm (h : IsBoundedBilinearMap 𝕜 f) :
IsBoundedBilinearMap 𝕜 (fun p ↦ f (p.2, p.1)) where
add_left x₁ x₂ y := h.add_right _ _ _
smul_left c x y := h.smul_right _ _ _
add_right x y₁ y₂ := h.add_left _ _ _
smul_right c x y := h.smul_left _ _ _
bound := by
obtain ⟨C, hC_pos, hC⟩ := h.bound
exact ⟨C, hC_pos, fun x y ↦ (hC y x).trans_eq (by ring)⟩
theorem ContinuousLinearMap.isBoundedBilinearMap (f : E →L[𝕜] F →L[𝕜] G) :
IsBoundedBilinearMap 𝕜 fun x : E × F => f x.1 x.2 :=
{ add_left := f.map_add₂
smul_left := f.map_smul₂
add_right := fun x => (f x).map_add
smul_right := fun c x => (f x).map_smul c
bound :=
⟨max ‖f‖ 1, zero_lt_one.trans_le (le_max_right _ _), fun x y =>
(f.le_opNorm₂ x y).trans <| by
apply_rules [mul_le_mul_of_nonneg_right, norm_nonneg, le_max_left] ⟩ }
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11445): new definition
/-- A bounded bilinear map `f : E × F → G` defines a continuous linear map
`f : E →L[𝕜] F →L[𝕜] G`. -/
def IsBoundedBilinearMap.toContinuousLinearMap (hf : IsBoundedBilinearMap 𝕜 f) :
E →L[𝕜] F →L[𝕜] G :=
LinearMap.mkContinuousOfExistsBound₂
(LinearMap.mk₂ _ f.curry hf.add_left hf.smul_left hf.add_right hf.smul_right) <|
hf.bound.imp fun _ ↦ And.right
protected theorem IsBoundedBilinearMap.isBigO (h : IsBoundedBilinearMap 𝕜 f) :
f =O[⊤] fun p : E × F => ‖p.1‖ * ‖p.2‖ :=
let ⟨C, _, hC⟩ := h.bound
Asymptotics.IsBigO.of_bound C <|
Filter.Eventually.of_forall fun ⟨x, y⟩ => by simpa [mul_assoc] using hC x y
theorem IsBoundedBilinearMap.isBigO_comp {α : Type*} (H : IsBoundedBilinearMap 𝕜 f) {g : α → E}
{h : α → F} {l : Filter α} : (fun x => f (g x, h x)) =O[l] fun x => ‖g x‖ * ‖h x‖ :=
H.isBigO.comp_tendsto le_top
protected theorem IsBoundedBilinearMap.isBigO' (h : IsBoundedBilinearMap 𝕜 f) :
f =O[⊤] fun p : E × F => ‖p‖ * ‖p‖ :=
h.isBigO.trans <|
(@Asymptotics.isBigO_fst_prod' _ E F _ _ _ _).norm_norm.mul
(@Asymptotics.isBigO_snd_prod' _ E F _ _ _ _).norm_norm
theorem IsBoundedBilinearMap.map_sub_left (h : IsBoundedBilinearMap 𝕜 f) {x y : E} {z : F} :
f (x - y, z) = f (x, z) - f (y, z) :=
(h.toContinuousLinearMap.flip z).map_sub x y
theorem IsBoundedBilinearMap.map_sub_right (h : IsBoundedBilinearMap 𝕜 f) {x : E} {y z : F} :
f (x, y - z) = f (x, y) - f (x, z) :=
(h.toContinuousLinearMap x).map_sub y z
open Asymptotics in
/-- Useful to use together with `Continuous.comp₂`. -/
theorem IsBoundedBilinearMap.continuous (h : IsBoundedBilinearMap 𝕜 f) : Continuous f := by
refine continuous_iff_continuousAt.2 fun x ↦ tendsto_sub_nhds_zero_iff.1 ?_
suffices Tendsto (fun y : E × F ↦ f (y.1 - x.1, y.2) + f (x.1, y.2 - x.2)) (𝓝 x) (𝓝 (0 + 0)) by
simpa only [h.map_sub_left, h.map_sub_right, sub_add_sub_cancel, zero_add] using this
apply Tendsto.add
· rw [← isLittleO_one_iff ℝ, ← one_mul 1]
refine h.isBigO_comp.trans_isLittleO ?_
refine (IsLittleO.norm_left ?_).mul_isBigO (IsBigO.norm_left ?_)
· exact (isLittleO_one_iff _).2 (tendsto_sub_nhds_zero_iff.2 (continuous_fst.tendsto _))
· exact (continuous_snd.tendsto _).isBigO_one ℝ
· refine Continuous.tendsto' ?_ _ _ (by rw [h.map_sub_right, sub_self])
exact ((h.toContinuousLinearMap x.1).continuous).comp (continuous_snd.sub continuous_const)
theorem IsBoundedBilinearMap.continuous_left (h : IsBoundedBilinearMap 𝕜 f) {e₂ : F} :
Continuous fun e₁ => f (e₁, e₂) :=
h.continuous.comp (continuous_id.prodMk continuous_const)
theorem IsBoundedBilinearMap.continuous_right (h : IsBoundedBilinearMap 𝕜 f) {e₁ : E} :
Continuous fun e₂ => f (e₁, e₂) :=
h.continuous.comp (continuous_const.prodMk continuous_id)
/-- Useful to use together with `Continuous.comp₂`. -/
theorem ContinuousLinearMap.continuous₂ (f : E →L[𝕜] F →L[𝕜] G) :
Continuous (Function.uncurry fun x y => f x y) :=
f.isBoundedBilinearMap.continuous
theorem IsBoundedBilinearMap.isBoundedLinearMap_left (h : IsBoundedBilinearMap 𝕜 f) (y : F) :
IsBoundedLinearMap 𝕜 fun x => f (x, y) :=
(h.toContinuousLinearMap.flip y).isBoundedLinearMap
theorem IsBoundedBilinearMap.isBoundedLinearMap_right (h : IsBoundedBilinearMap 𝕜 f) (x : E) :
IsBoundedLinearMap 𝕜 fun y => f (x, y) :=
(h.toContinuousLinearMap x).isBoundedLinearMap
theorem isBoundedBilinearMap_smul {𝕜' : Type*} [NormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] {E : Type*}
[SeminormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedSpace 𝕜' E] [IsScalarTower 𝕜 𝕜' E] :
IsBoundedBilinearMap 𝕜 fun p : 𝕜' × E => p.1 • p.2 :=
(lsmul 𝕜 𝕜' : 𝕜' →L[𝕜] E →L[𝕜] E).isBoundedBilinearMap
theorem isBoundedBilinearMap_mul : IsBoundedBilinearMap 𝕜 fun p : 𝕜 × 𝕜 => p.1 * p.2 := by
simp_rw [← smul_eq_mul]
exact isBoundedBilinearMap_smul
theorem isBoundedBilinearMap_comp :
IsBoundedBilinearMap 𝕜 fun p : (F →L[𝕜] G) × (E →L[𝕜] F) => p.1.comp p.2 :=
(compL 𝕜 E F G).isBoundedBilinearMap
theorem ContinuousLinearMap.isBoundedLinearMap_comp_left (g : F →L[𝕜] G) :
IsBoundedLinearMap 𝕜 fun f : E →L[𝕜] F => ContinuousLinearMap.comp g f :=
isBoundedBilinearMap_comp.isBoundedLinearMap_right _
theorem ContinuousLinearMap.isBoundedLinearMap_comp_right (f : E →L[𝕜] F) :
IsBoundedLinearMap 𝕜 fun g : F →L[𝕜] G => ContinuousLinearMap.comp g f :=
isBoundedBilinearMap_comp.isBoundedLinearMap_left _
theorem isBoundedBilinearMap_apply : IsBoundedBilinearMap 𝕜 fun p : (E →L[𝕜] F) × E => p.1 p.2 :=
(ContinuousLinearMap.flip (apply 𝕜 F : E →L[𝕜] (E →L[𝕜] F) →L[𝕜] F)).isBoundedBilinearMap
/-- The function `ContinuousLinearMap.smulRight`, associating to a continuous linear map
`f : E → 𝕜` and a scalar `c : F` the tensor product `f ⊗ c` as a continuous linear map from `E` to
`F`, is a bounded bilinear map. -/
theorem isBoundedBilinearMap_smulRight :
IsBoundedBilinearMap 𝕜 fun p =>
(ContinuousLinearMap.smulRight : (E →L[𝕜] 𝕜) → F → E →L[𝕜] F) p.1 p.2 :=
(smulRightL 𝕜 E F).isBoundedBilinearMap
/-- The composition of a continuous linear map with a continuous multilinear map is a bounded
bilinear operation. -/
theorem isBoundedBilinearMap_compMultilinear {ι : Type*} {E : ι → Type*} [Fintype ι]
[∀ i, NormedAddCommGroup (E i)] [∀ i, NormedSpace 𝕜 (E i)] :
IsBoundedBilinearMap 𝕜 fun p : (F →L[𝕜] G) × ContinuousMultilinearMap 𝕜 E F =>
p.1.compContinuousMultilinearMap p.2 :=
(compContinuousMultilinearMapL 𝕜 E F G).isBoundedBilinearMap
/-- Definition of the derivative of a bilinear map `f`, given at a point `p` by
`q ↦ f(p.1, q.2) + f(q.1, p.2)` as in the standard formula for the derivative of a product.
We define this function here as a linear map `E × F →ₗ[𝕜] G`, then `IsBoundedBilinearMap.deriv`
strengthens it to a continuous linear map `E × F →L[𝕜] G`.
-/
def IsBoundedBilinearMap.linearDeriv (h : IsBoundedBilinearMap 𝕜 f) (p : E × F) : E × F →ₗ[𝕜] G :=
(h.toContinuousLinearMap.deriv₂ p).toLinearMap
/-- The derivative of a bounded bilinear map at a point `p : E × F`, as a continuous linear map
from `E × F` to `G`. The statement that this is indeed the derivative of `f` is
`IsBoundedBilinearMap.hasFDerivAt` in `Analysis.Calculus.FDeriv`. -/
def IsBoundedBilinearMap.deriv (h : IsBoundedBilinearMap 𝕜 f) (p : E × F) : E × F →L[𝕜] G :=
h.toContinuousLinearMap.deriv₂ p
@[simp]
theorem IsBoundedBilinearMap.deriv_apply (h : IsBoundedBilinearMap 𝕜 f) (p q : E × F) :
h.deriv p q = f (p.1, q.2) + f (q.1, p.2) :=
rfl
variable (𝕜) in
/-- The function `ContinuousLinearMap.mulLeftRight : 𝕜' × 𝕜' → (𝕜' →L[𝕜] 𝕜')` is a bounded
bilinear map. -/
theorem ContinuousLinearMap.mulLeftRight_isBoundedBilinear (𝕜' : Type*) [SeminormedRing 𝕜']
[NormedAlgebra 𝕜 𝕜'] :
IsBoundedBilinearMap 𝕜 fun p : 𝕜' × 𝕜' => ContinuousLinearMap.mulLeftRight 𝕜 𝕜' p.1 p.2 :=
(ContinuousLinearMap.mulLeftRight 𝕜 𝕜').isBoundedBilinearMap
/-- Given a bounded bilinear map `f`, the map associating to a point `p` the derivative of `f` at
`p` is itself a bounded linear map. -/
theorem IsBoundedBilinearMap.isBoundedLinearMap_deriv (h : IsBoundedBilinearMap 𝕜 f) :
IsBoundedLinearMap 𝕜 fun p : E × F => h.deriv p :=
h.toContinuousLinearMap.deriv₂.isBoundedLinearMap
end BilinearMap
variable {X : Type*} [TopologicalSpace X]
@[continuity, fun_prop]
theorem Continuous.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F}
(hg : Continuous g) (hf : Continuous f) : Continuous fun x => (g x).comp (f x) :=
(compL 𝕜 E F G).continuous₂.comp₂ hg hf
theorem ContinuousOn.clm_comp {g : X → F →L[𝕜] G} {f : X → E →L[𝕜] F}
{s : Set X} (hg : ContinuousOn g s) (hf : ContinuousOn f s) :
ContinuousOn (fun x => (g x).comp (f x)) s :=
(compL 𝕜 E F G).continuous₂.comp_continuousOn (hg.prodMk hf)
@[continuity, fun_prop]
theorem Continuous.clm_apply {f : X → E →L[𝕜] F} {g : X → E}
(hf : Continuous f) (hg : Continuous g) : Continuous (fun x ↦ f x (g x)) :=
isBoundedBilinearMap_apply.continuous.comp₂ hf hg
theorem ContinuousOn.clm_apply {f : X → E →L[𝕜] F} {g : X → E}
{s : Set X} (hf : ContinuousOn f s) (hg : ContinuousOn g s) :
ContinuousOn (fun x ↦ f x (g x)) s :=
isBoundedBilinearMap_apply.continuous.comp_continuousOn (hf.prodMk hg)
@[continuity, fun_prop]
theorem ContinuousAt.clm_apply {X} [TopologicalSpace X] {f : X → E →L[𝕜] F} {g : X → E} {x : X}
(hf : ContinuousAt f x) (hg : ContinuousAt g x) : ContinuousAt (fun x ↦ f x (g x)) x :=
isBoundedBilinearMap_apply.continuous.continuousAt.comp₂ hf hg
@[continuity, fun_prop]
theorem ContinuousWithinAt.clm_apply {X} [TopologicalSpace X] {f : X → E →L[𝕜] F} {g : X → E}
{s : Set X} {x : X} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) :
ContinuousWithinAt (fun x ↦ f x (g x)) s x :=
isBoundedBilinearMap_apply.continuous.continuousAt.comp_continuousWithinAt (hf.prodMk hg)
theorem ContinuousOn.continuousLinearMapCoprod
{f : X → E →L[𝕜] G} {g : X → F →L[𝕜] G} {s : Set X}
(hf : ContinuousOn f s) (hg : ContinuousOn g s) :
ContinuousOn (fun x => (f x).coprod (g x)) s := by
simp only [← comp_fst_add_comp_snd]
exact (hf.clm_comp continuousOn_const).add (hg.clm_comp continuousOn_const)
theorem Continuous.continuousLinearMapCoprod
{f : X → E →L[𝕜] G} {g : X → F →L[𝕜] G}
(hf : Continuous f) (hg : Continuous g) :
Continuous (fun x => (f x).coprod (g x)) := by
apply continuousOn_univ.mp
exact hf.continuousOn.continuousLinearMapCoprod hg.continuousOn
end
namespace ContinuousLinearEquiv
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E]
variable {F : Type*} [SeminormedAddCommGroup F] [NormedSpace 𝕜 F]
open Set
open scoped Topology
/-!
### The set of continuous linear equivalences between two Banach spaces is open
In this section we establish that the set of continuous linear equivalences between two Banach
spaces is an open subset of the space of linear maps between them.
-/
protected theorem isOpen [CompleteSpace E] : IsOpen (range ((↑) : (E ≃L[𝕜] F) → E →L[𝕜] F)) := by
rw [isOpen_iff_mem_nhds, forall_mem_range]
refine fun e => IsOpen.mem_nhds ?_ (mem_range_self _)
let O : (E →L[𝕜] F) → E →L[𝕜] E := fun f => (e.symm : F →L[𝕜] E).comp f
have h_O : Continuous O := isBoundedBilinearMap_comp.continuous_right
convert show IsOpen (O ⁻¹' { x | IsUnit x }) from Units.isOpen.preimage h_O using 1
ext f'
constructor
· rintro ⟨e', rfl⟩
exact ⟨(e'.trans e.symm).toUnit, rfl⟩
· rintro ⟨w, hw⟩
use (unitsEquiv 𝕜 E w).trans e
ext x
simp [O, hw]
protected theorem nhds [CompleteSpace E] (e : E ≃L[𝕜] F) :
range ((↑) : (E ≃L[𝕜] F) → E →L[𝕜] F) ∈ 𝓝 (e : E →L[𝕜] F) :=
IsOpen.mem_nhds ContinuousLinearEquiv.isOpen (by simp)
end ContinuousLinearEquiv
|
order.v
|
(* (c) Copyright 2006-2019 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat choice seq.
From mathcomp Require Import path fintype tuple bigop finset div prime finfun.
From mathcomp Require Import finset.
From mathcomp Require Export preorder.
(******************************************************************************)
(* Types equipped with order relations *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This files defines types equipped with order relations. *)
(* *)
(* * How to use orders in MathComp? *)
(* Use one of the following modules implementing different theories (all *)
(* located in the module Order): *)
(* Order.LTheory: partially ordered types and lattices excluding complement *)
(* and totality related theorems *)
(* Order.CTheory: complemented lattices including Order.LTheory *)
(* Order.TTheory: totally ordered types including Order.LTheory *)
(* Order.Theory: ordered types including all of the above theory modules *)
(* To access the definitions, notations, and the theory from, say, *)
(* "Order.Xyz", insert "Import Order.Xyz." at the top of your scripts. You can*)
(* also "Import Order.Def." to enjoy shorter notations (e.g., min instead of *)
(* Order.min, nondecreasing instead of Order.nondecreasing, etc.). *)
(* *)
(* In order to reason about abstract orders, notations are accessible by *)
(* opening the scope "order_scope" bound to the delimiting key "O"; however, *)
(* when dealing with another notation scope providing order notations for *)
(* a concrete instance (e.g., "ring_scope"), it is not recommended to open *)
(* "order_scope" at the same time. *)
(* *)
(* * Control of inference (parsing) and printing *)
(* One characteristic of ordered types is that one carrier type may have *)
(* several orders. For example, natural numbers can be totally or partially *)
(* ordered by the less than or equal relation, the divisibility relation, and *)
(* their dual relations. Therefore, we need a way to control inference of *)
(* ordered type instances and printing of generic relations and operations on *)
(* ordered types. As a rule of thumb, we use the carrier type or its "alias" *)
(* (named copy) to control inference (using canonical structures), and use a *)
(* "display" to control the printing of notations. *)
(* *)
(* Each generic interface and operation for ordered types has, as its first *)
(* argument, a "display" of type Order.disp_t. For example, the less than or *)
(* equal relation has type: *)
(* Order.le : forall {d : Order.disp_t} {T : porderType d}, rel T, *)
(* where porderType d is the structure of partially ordered types with *)
(* display d. (@Order.le dvd_display _ m n) is printed as m %| n because *)
(* ordered type instances associated to the display dvd_display is intended *)
(* to represent natural numbers partially ordered by the divisibility *)
(* relation. *)
(* *)
(* We stress that order structure inference can be triggered only from the *)
(* carrier type (or its alias), but not the display. For example, writing *)
(* m %| n for m and n of type nat does not trigger an inference of the *)
(* divisibility relation on natural numbers, which is associated to an alias *)
(* natdvd for nat; such an inference should be triggered through the use of *)
(* the corresponding alias, i.e., (m : natdvd) %| n. In other words, displays *)
(* are merely used to inform the user and the notation mechanism of what the *)
(* inference did; they are not additional input for the inference. *)
(* *)
(* See below for various aliases and their associated displays. *)
(* *)
(* NB: algebra/ssrnum.v provides the display ring_display to change the *)
(* scope of the usual notations to ring_scope. *)
(* *)
(* Instantiating d with Disp tt tt or an unknown display will lead to a *)
(* default display for notations. *)
(* *)
(* Alternative notation displays can be defined by : *)
(* 1. declaring a new opaque definition of type unit. Using the idiom *)
(* `Fact my_display : Order.disp_t. Proof. exact: Disp tt tt. Qed.` *)
(* 2. using this symbol to tag canonical porderType structures using *)
(* `HB.instance Definition _ := isPOrder.Build my_display my_type ...`, *)
(* 3. declaring notations for the main operations of this library, by *)
(* setting the first argument of the definition to the display, e.g. *)
(* `Notation my_syndef_le x y := @Order.le my_display _ x y.` or *)
(* `Notation "x <=< y" := @Order.lt my_display _ x y (at level ...).` *)
(* Non overloaded notations will default to the default display. *)
(* We suggest the user to refer to the example of natdvd below as a guideline *)
(* example to add their own displays. *)
(* *)
(* * Interfaces *)
(* We provide the following interfaces for types equipped with an order: *)
(* *)
(* porderType d == the type of partially ordered types *)
(* The HB class is called POrder. *)
(* bPOrderType d == porderType with a bottom element (\bot) *)
(* The HB class is called BPOrder. *)
(* tPOrderType d == porderType with a top element (\top) *)
(* The HB class is called TPOrder. *)
(* tbPOrderType d == porderType with both a top and a bottom *)
(* The HB class is called TBPOrder. *)
(* meetSemilatticeType d == the type of meet semilattices *)
(* The HB class is called MeetSemilattice. *)
(* bMeetSemilatticeType d == meetSemilatticeType with a bottom element *)
(* The HB class is called BMeetSemilattice. *)
(* tMeetSemilatticeType d == meetSemilatticeType with a top element *)
(* The HB class is called TMeetSemilattice. *)
(* tbMeetSemilatticeType d == meetSemilatticeType with both a top and a *)
(* bottom *)
(* The HB class is called TBMeetSemilattice. *)
(* joinSemilatticeType d == the type of join semilattices *)
(* The HB class is called JoinSemilattice. *)
(* bJoinSemilatticeType d == joinSemilatticeType with a bottom element *)
(* The HB class is called BJoinSemilattice. *)
(* tJoinSemilatticeType d == joinSemilatticeType with a top element *)
(* The HB class is called TJoinSemilattice. *)
(* tbJoinSemilatticeType d == joinSemilatticeType with both a top and a *)
(* bottom *)
(* The HB class is called TBJoinSemilattice. *)
(* latticeType d == the type of lattices *)
(* The HB class is called Lattice. *)
(* bLatticeType d == latticeType with a bottom element *)
(* The HB class is called BLattice. *)
(* tLatticeType d == latticeType with a top element *)
(* The HB class is called TLattice. *)
(* tbLatticeType d == latticeType with both a top and a bottom *)
(* The HB class is called TBLattice. *)
(* distrLatticeType d == the type of distributive lattices *)
(* The HB class is called DistrLattice. *)
(* bDistrLatticeType d == distrLatticeType with a bottom element *)
(* The HB class is called BDistrLattice. *)
(* tDistrLatticeType d == distrLatticeType with a top element *)
(* The HB class is called TDistrLattice. *)
(* tbDistrLatticeType d == distrLatticeType with both a top and a bottom *)
(* The HB class is called TBDistrLattice. *)
(* orderType d == the type of totally ordered types *)
(* The HB class is called Total. *)
(* bOrderType d == orderType with a bottom element *)
(* The HB class is called BTotal. *)
(* tOrderType d == orderType with a top element *)
(* The HB class is called TTotal. *)
(* tbOrderType d == orderType with both a top and a bottom *)
(* The HB class is called TBTotal. *)
(* cDistrLatticeType d == the type of relatively complemented *)
(* distributive lattices, where each interval *)
(* [a, b] is equipped with a complement operation*)
(* The HB class is called CDistrLattice. *)
(* cbDistrLatticeType d == the type of sectionally complemented *)
(* distributive lattices, equipped with a bottom,*)
(* a relative complement operation, and a *)
(* difference operation, i.e., a complement *)
(* operation for each interval of the form *)
(* [\bot, b] *)
(* The HB class is called CBDistrLattice. *)
(* ctDistrLatticeType d == the type of dually sectionally complemented *)
(* distributive lattices, equipped with a top, *)
(* a relative complement operation, and a *)
(* dual difference operation, i.e. a complement *)
(* operation for each interval of the form *)
(* [a, \top] *)
(* The HB class is called CTDistrLattice. *)
(* ctbDistrLatticeType d == the type of complemented distributive *)
(* lattices, equipped with top, bottom, *)
(* difference, dual difference, and complement *)
(* The HB class is called CTBDistrLattice. *)
(* finPOrderType d == the type of partially ordered finite types *)
(* The HB class is called FinPOrder. *)
(* finBPOrderType d == finPOrderType with a bottom element *)
(* The HB class is called FinBPOrder. *)
(* finTPOrderType d == finPOrderType with a top element *)
(* The HB class is called FinTPOrder. *)
(* finTBPOrderType d == finPOrderType with both a top and a bottom *)
(* The HB class is called FinTBPOrder. *)
(* finMeetSemilatticeType d == the type of finite meet semilattice types *)
(* The HB class is called FinMeetSemilattice. *)
(* finBMeetSemilatticeType d == finMeetSemilatticeType with a bottom element *)
(* Note that finTMeetSemilatticeType is just *)
(* finTBLatticeType. *)
(* The HB class is called FinBMeetSemilattice. *)
(* finJoinSemilatticeType d == the type of finite join semilattice types *)
(* The HB class is called FinJoinSemilattice. *)
(* finTJoinSemilatticeType d == finJoinSemilatticeType with a top element *)
(* Note that finBJoinSemilatticeType is just *)
(* finTBLatticeType. *)
(* The HB class is called FinTJoinSemilattice. *)
(* finLatticeType d == the type of finite lattices *)
(* The HB class is called FinLattice. *)
(* finTBLatticeType d == the type of nonempty finite lattices *)
(* The HB class is called FinTBLattice. *)
(* finDistrLatticeType d == the type of finite distributive lattices *)
(* The HB class is called FinDistrLattice. *)
(* finTBDistrLatticeType d == the type of nonempty finite distributive *)
(* lattices *)
(* The HB class is called FinTBDistrLattice. *)
(* finOrderType d == the type of totally ordered finite types *)
(* The HB class is called FinTotal. *)
(* finTBOrderType d == the type of nonempty totally ordered finite *)
(* types *)
(* The HB class is called FinTBTotal. *)
(* finCDistrLatticeType d == the type of finite relatively complemented *)
(* distributive lattices *)
(* The HB class is called FinCDistrLattice. *)
(* finCTBDistrLatticeType d == the type of finite complemented distributive *)
(* lattices *)
(* The HB class is called FinCTBDistrLattice. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subPOrder d T P d' == join of porderType d' and subType *)
(* (P : pred T) such that val is monotonic *)
(* The HB class is called SubPOrder. *)
(* meetSubLattice d T P d' == join of latticeType d' and subType *)
(* (P : pred T) such that val is monotonic and *)
(* a morphism for meet *)
(* The HB class is called MeetSubLattice. *)
(* joinSubLattice d T P d' == join of latticeType d' and subType *)
(* (P : pred T) such that val is monotonic and *)
(* a morphism for join *)
(* The HB class is called JoinSubLattice. *)
(* subLattice d T P d' == join of JoinSubLattice and MeetSubLattice *)
(* The HB class is called SubLattice. *)
(* bJoinSubLattice d T P d' == join of JoinSubLattice and BLattice *)
(* such that val is a morphism for \bot *)
(* The HB class is called BJoinSubLattice. *)
(* tMeetSubLattice d T P d' == join of MeetSubLattice and TLattice *)
(* such that val is a morphism for \top *)
(* The HB class is called TMeetSubLattice. *)
(* bSubLattice d T P d' == join of SubLattice and BLattice *)
(* such that val is a morphism for \bot *)
(* The HB class is called BSubLattice. *)
(* tSubLattice d T P d' == join of SubLattice and TLattice *)
(* such that val is a morphism for \top *)
(* The HB class is called BSubLattice. *)
(* subOrder d T P d' == join of orderType d' and *)
(* subLatticeType d T P d' *)
(* The HB class is called SubOrder. *)
(* subPOrderLattice d T P d' == join of SubPOrder and Lattice *)
(* The HB class is called SubPOrderLattice. *)
(* subPOrderBLattice d T P d' == join of SubPOrder and BLattice *)
(* The HB class is called SubPOrderBLattice. *)
(* subPOrderTLattice d T P d' == join of SubPOrder and TLattice *)
(* The HB class is called SubPOrderTLattice. *)
(* subPOrderTBLattice d T P d' == join of SubPOrder and TBLattice *)
(* The HB class is called SubPOrderTBLattice. *)
(* meetSubBLattice d T P d' == join of MeetSubLattice and BLattice *)
(* The HB class is called MeetSubBLattice. *)
(* meetSubTLattice d T P d' == join of MeetSubLattice and TLattice *)
(* The HB class is called MeetSubTLattice. *)
(* meetSubTBLattice d T P d' == join of MeetSubLattice and TBLattice *)
(* The HB class is called MeetSubTBLattice. *)
(* joinSubBLattice d T P d' == join of JoinSubLattice and BLattice *)
(* The HB class is called JoinSubBLattice. *)
(* joinSubTLattice d T P d' == join of JoinSubLattice and TLattice *)
(* The HB class is called JoinSubTLattice. *)
(* joinSubTBLattice d T P d' == join of JoinSubLattice and TBLattice *)
(* The HB class is called JoinSubTBLattice. *)
(* subBLattice d T P d' == join of SubLattice and BLattice *)
(* The HB class is called SubBLattice. *)
(* subTLattice d T P d' == join of SubLattice and TLattice *)
(* The HB class is called SubTLattice. *)
(* subTBLattice d T P d' == join of SubLattice and TBLattice *)
(* The HB class is called SubTBLattice. *)
(* bJoinSubTLattice d T P d' == join of BJoinSubLattice and TBLattice *)
(* The HB class is called BJoinSubTLattice. *)
(* tMeetSubBLattice d T P d' == join of TMeetSubLattice and TBLattice *)
(* The HB class is called TMeetSubBLattice. *)
(* bSubTLattice d T P d' == join of BSubLattice and TBLattice *)
(* The HB class is called BSubTLattice. *)
(* tSubBLattice d T P d' == join of TSubLattice and TBLattice *)
(* The HB class is called TSubBLattice. *)
(* tbSubBLattice d T P d' == join of BSubLattice and TSubLattice *)
(* The HB class is called TBSubLattice. *)
(* *)
(* Morphisms between the above structures: *)
(* *)
(* MeetLatticeMorphism.type d T d' T', *)
(* JoinLatticeMorphism.type d T d' T', *)
(* LatticeMorphism.type d T d' T' == nondecreasing function between two *)
(* lattices which are morphism for meet, join, and *)
(* meet/join respectively *)
(* BLatticeMorphism.type d T d' T' := {blmorphism T -> T'}, *)
(* TLatticeMorphism.type d T d' T' := {tlmorphism T -> T'}, *)
(* TBLatticeMorphism.type d T d' T' := {tblmorphism T -> T'} *)
(* == nondecreasing function between two lattices with *)
(* bottom/top which are morphism for bottom/top *)
(* *)
(* Closedness predicates for the algebraic structures: *)
(* *)
(* meetLatticeClosed d T == predicate closed under meet on T : latticeType d *)
(* The HB class is MeetLatticeClosed. *)
(* joinLatticeClosed d T == predicate closed under join on T : latticeType d *)
(* The HB class is JoinLatticeClosed. *)
(* latticeClosed d T == predicate closed under meet and join *)
(* The HB class is JoinLatticeClosed. *)
(* bLatticeClosed d T == predicate that contains bottom *)
(* The HB class is BLatticeClosed. *)
(* tLatticeClosed d T == predicate that contains top *)
(* The HB class is TLatticeClosed. *)
(* tbLatticeClosed d T == predicate that contains top and bottom *)
(* the HB class ie TBLatticeClosed. *)
(* bJoinLatticeClosed d T == predicate that contains bottom and is closed *)
(* under join *)
(* The HB class is BJoinLatticeClosed. *)
(* tMeetLatticeClosed d T == predicate that contains top and is closed under *)
(* meet *)
(* The HB class is TMeetLatticeClosed. *)
(* *)
(* * Useful lemmas: *)
(* On orderType, leP, ltP, and ltgtP are the three main lemmas for case *)
(* analysis. *)
(* On porderType, one may use comparableP, comparable_leP, comparable_ltP, *)
(* and comparable_ltgtP, which are the four main lemmas for case analysis. *)
(* *)
(* * Order relations and operations: *)
(* In general, an overloaded relation or operation on ordered types takes the *)
(* following arguments: *)
(* 1. a display d of type Order.disp_t, *)
(* 2. an instance T of the minimal structure it operates on, and *)
(* 3. operands. *)
(* Here is the exhaustive list of all such operations together with their *)
(* default notation (defined in order_scope unless specified otherwise). *)
(* *)
(* For T of type porderType d, x and y of type T, and C of type bool: *)
(* x <= y := @Order.le d T x y *)
(* <-> x is less than or equal to y. *)
(* x < y := @Order.lt d T x y *)
(* <-> x is less than y, i.e., (y != x) && (x <= y). *)
(* x >= y := y <= x *)
(* <-> x is greater than or equal to y. *)
(* x > y := y < x *)
(* <-> x is greater than y. *)
(* x >=< y := @Order.comparable d T x y (:= (x <= y) || (y <= x)) *)
(* <-> x and y are comparable. *)
(* x >< y := ~~ x >=< y *)
(* <-> x and y are incomparable. *)
(* x <= y ?= iff C := @Order.leif d T x y C (:= (x <= y) * ((x == y) = C)) *)
(* <-> x is less than y, or equal iff C is true. *)
(* x < y ?<= if C := @Order.lteif d T x y C (:= if C then x <= y else x < y)*)
(* <-> x is smaller than y, and strictly if C is false. *)
(* Order.min x y := if x < y then x else y *)
(* Order.max x y := if x < y then y else x *)
(* f \min g == the function x |-> Order.min (f x) (g x); *)
(* f \min g simplifies on application. *)
(* f \max g == the function x |-> Order.max (f x) (g x); *)
(* f \max g simplifies on application. *)
(* nondecreasing f <-> the function f : T -> T' is nondecreasing, *)
(* where T and T' are porderType *)
(* := {homo f : x y / x <= y} *)
(* Unary (partially applied) versions of order notations: *)
(* >= y := @Order.le d T y *)
(* == a predicate characterizing elements greater than or *)
(* equal to y *)
(* > y := @Order.lt d T y *)
(* <= y := @Order.ge d T y *)
(* < y := @Order.gt d T y *)
(* >=< y := [pred x | @Order.comparable d T x y] *)
(* >< y := [pred x | ~~ @Order.comparable d T x y] *)
(* 0-ary versions of order notations (in function_scope): *)
(* <=%O := @Order.le d T *)
(* <%O := @Order.lt d T *)
(* >=%O := @Order.ge d T *)
(* >%O := @Order.gt d T *)
(* >=<%O := @Order.comparable d T *)
(* <?=%O := @Order.leif d T *)
(* <?<=%O := @Order.lteif d T *)
(* -> These conventions are compatible with Haskell's, *)
(* where ((< y) x) = (x < y) = ((<) x y), *)
(* except that we write <%O instead of (<). *)
(* *)
(* For T of type bPOrderType d: *)
(* \bot := @Order.bottom d T *)
(* == the bottom element of type T *)
(* \max_<range> e := \big[Order.max / Order.bottom]_<range> e *)
(* == iterated max of a preorder with a bottom *)
(* the possible <range>s are documented in bigop.v *)
(* For T of type tPOrderType d: *)
(* \top := @Order.top d T *)
(* == the top element of type T *)
(* \min_<range> e := \big[Order.max / Order.top]_<range> e *)
(* == iterated min of a preorder with a top *)
(* the possible <range>s are documented in bigop.v *)
(* *)
(* For T of type meetSemilatticeType d, and x, y of type T: *)
(* x `&` y := @Order.meet d T x y *)
(* == the meet of x and y *)
(* For T of type joinSemilatticeType d, and x, y of type T: *)
(* x `|` y := @Order.join d T x y *)
(* == the join of x and y *)
(* *)
(* For T of type tMeetSemilatticeType d: *)
(* \meet_<range> e := \big[Order.meet / Order.top]_<range> e *)
(* == iterated meet of a meet-semilattice with a top *)
(* the possible <range>s are documented in bigop.v *)
(* For T of type bJoinSemilatticeType d: *)
(* \join_<range> e := \big[Order.join / Order.bottom]_<range> e *)
(* == iterated join of a join-semilattice with a bottom *)
(* the possible <range>s are documented in bigop.v *)
(* *)
(* For T of type cDistrLatticeType d, and x, y, z of type T: *)
(* rcompl x y z == the (relative) complement of z in [x, y] *)
(* *)
(* For T of type cbDistrLatticeType d, and x, y of type T: *)
(* x `\` y := @Order.diff d T x y *)
(* == the (sectional) complement of y in [\bot, x], *)
(* i.e., rcompl \bot x y *)
(* *)
(* For T of type ctDistrLatticeType d, and x, y of type T: *)
(* codiff x y == the (dual sectional) complement of y in [x, \top], *)
(* i.e., rcompl x \top y *)
(* *)
(* For T of type ctbDistrLatticeType d, and x of type T: *)
(* ~` x := @Order.compl d T x *)
(* == the complement of x in [\bot, \top], *)
(* i.e., rcompl \bot \top x *)
(* *)
(* For preorderType we provide the following operations: *)
(* [arg min_(i < i0 | P) M] == a value i : T minimizing M : R, subject to *)
(* the condition P (i may appear in P and M), and *)
(* provided P holds for i0. *)
(* [arg max_(i > i0 | P) M] == a value i maximizing M subject to P and *)
(* provided P holds for i0. *)
(* [arg min_(i < i0 in A) M] == an i \in A minimizing M if i0 \in A. *)
(* [arg max_(i > i0 in A) M] == an i \in A maximizing M if i0 \in A. *)
(* [arg min_(i < i0) M] == an i : T minimizing M, given i0 : T. *)
(* [arg max_(i > i0) M] == an i : T maximizing M, given i0 : T. *)
(* with head symbols Order.arg_min and Order.arg_max *)
(* The user may use extremumP or extremum_inP to eliminate them. *)
(* *)
(* -> patterns for contextual rewriting: *)
(* leLHS := (X in (X <= _)%O)%pattern *)
(* leRHS := (X in (_ <= X)%O)%pattern *)
(* ltLHS := (X in (X < _)%O)%pattern *)
(* ltRHS := (X in (_ < X)%O)%pattern *)
(* *)
(* We provide aliases for various types and their displays: *)
(* natdvd := nat (associated with display dvd_display) *)
(* == an alias for nat which is canonically ordered using *)
(* divisibility predicate dvdn *)
(* Notation %|, %<|, gcd, lcm are used instead of *)
(* <=, <, meet and join. *)
(* T^d := dual T, *)
(* where dual is a new definition for (fun T => T) *)
(* (associated with dual_display d where d is a display) *)
(* == an alias for T, such that if T is canonically *)
(* ordered, then T^d is canonically ordered with the *)
(* dual order, and displayed with an extra ^d in the *)
(* notation, i.e., <=^d, <^d, >=<^d, ><^d, `&`^d, `|`^d *)
(* are used and displayed instead of *)
(* <=, <, >=<, ><, `&`, `|` *)
(* T *prod[d] T' := T * T' *)
(* == an alias for the cartesian product such that, *)
(* if T and T' are canonically ordered, *)
(* then T *prod[d] T' is canonically ordered in product *)
(* order, i.e., *)
(* (x1, x2) <= (y1, y2) = (x1 <= y1) && (x2 <= y2), *)
(* and displayed in display d *)
(* T *p T' := T *prod[prod_display d d'] T' *)
(* where d and d' are the displays of T and T', *)
(* respectively, and prod_display adds an extra ^p to *)
(* all notations *)
(* T *lexi[d] T' := T * T' *)
(* == an alias for the cartesian product such that, *)
(* if T and T' are canonically ordered, *)
(* then T *lexi[d] T' is canonically ordered in *)
(* lexicographic order, *)
(* i.e., (x1, x2) <= (y1, y2) = *)
(* (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)) *)
(* and (x1, x2) < (y1, y2) = *)
(* (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)) *)
(* and displayed in display d *)
(* T *l T' := T *lexi[lexi_display d d'] T' *)
(* where d and d' are the displays of T and T', *)
(* respectively, and lexi_display adds an extra ^l to *)
(* all notations *)
(* seqprod_with d T := seq T *)
(* == an alias for seq, such that if T is canonically *)
(* ordered, then seqprod_with d T is canonically ordered *)
(* in product order, i.e., *)
(* [:: x1, .., xn] <= [y1, .., yn] = *)
(* (x1 <= y1) && ... && (xn <= yn) *)
(* and displayed in display d *)
(* n.-tupleprod[d] T == same with n.tuple T *)
(* seqprod T := seqprod_with (seqprod_display d) T *)
(* where d is the display of T, and seqprod_display adds *)
(* an extra ^sp to all notations *)
(* n.-tupleprod T := n.-tuple[seqprod_display d] T *)
(* where d is the display of T *)
(* seqlexi_with d T := seq T *)
(* == an alias for seq, such that if T is canonically *)
(* ordered, then seqprod_with d T is canonically ordered *)
(* in lexicographic order, i.e., *)
(* [:: x1, .., xn] <= [y1, .., yn] = *)
(* (x1 <= x2) && ((x1 >= y1) ==> ((x2 <= y2) && ...)) *)
(* and displayed in display d *)
(* n.-tuplelexi[d] T == same with n.tuple T *)
(* seqlexi T := lexiprod_with (seqlexi_display d) T *)
(* where d is the display of T, and seqlexi_display adds *)
(* an extra ^sl to all notations *)
(* n.-tuplelexi T := n.-tuple[seqlexi_display d] T *)
(* where d is the display of T *)
(* {subset[d] T} := {set T} *)
(* == an alias for set which is canonically ordered by the *)
(* subset order and displayed in display d *)
(* {subset T} := {subset[subset_display] T} *)
(* *)
(* The following notations are provided to build substructures: *)
(* [SubChoice_isSubPOrder of U by <: with disp] == *)
(* [SubChoice_isSubPOrder of U by <:] == porderType mixin for a subType *)
(* whose base type is a porderType *)
(* [SubPOrder_isSubLattice of U by <: with disp] == *)
(* [SubPOrder_isSubLattice of U by <:] == *)
(* [SubChoice_isSubLattice of U by <: with disp] == *)
(* [SubChoice_isSubLattice of U by <:] == latticeType mixin for a subType *)
(* whose base type is a latticeType and whose *)
(* predicate is a latticeClosed *)
(* [SubPOrder_isBSubLattice of U by <: with disp] == *)
(* [SubPOrder_isBSubLattice of U by <:] == *)
(* [SubChoice_isBSubLattice of U by <: with disp] == *)
(* [SubChoice_isBSubLattice of U by <:] == blatticeType mixin for a subType *)
(* whose base type is a blatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a bLatticeClosed *)
(* [SubPOrder_isTSubLattice of U by <: with disp] == *)
(* [SubPOrder_isTSubLattice of U by <:] == *)
(* [SubChoice_isTSubLattice of U by <: with disp] == *)
(* [SubChoice_isTSubLattice of U by <:] == tlatticeType mixin for a subType *)
(* whose base type is a tlatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a tLatticeClosed *)
(* [SubPOrder_isTBSubLattice of U by <: with disp] == *)
(* [SubPOrder_isTBSubLattice of U by <:] == *)
(* [SubChoice_isTBSubLattice of U by <: with disp] == *)
(* [SubChoice_isTBSubLattice of U by <:] == tblatticeType mixin for a subType *)
(* whose base type is a tblatticeType and whose *)
(* predicate is both a latticeClosed *)
(* and a tbLatticeClosed *)
(* [SubLattice_isSubOrder of U by <: with disp] == *)
(* [SubLattice_isSubOrder of U by <:] == *)
(* [SubPOrder_isSubOrder of U by <: with disp] == *)
(* [SubPOrder_isSubOrder of U by <:] == *)
(* [SubChoice_isSubOrder of U by <: with disp] == *)
(* [SubChoice_isSubOrder of U by <:] == orderType mixin for a subType whose *)
(* base type is an orderType *)
(* [POrder of U by <:] == porderType mixin for a subType whose base type is *)
(* a porderType *)
(* [Order of U by <:] == orderType mixin for a subType whose base type is *)
(* an orderType *)
(* *)
(* We provide expected instances of ordered types for bool, nat (for leq and *)
(* and dvdn), 'I_n, 'I_n.+1 (with a top and bottom), nat for dvdn, *)
(* T *prod[disp] T', T *lexi[disp] T', {t : T & T' x} (with lexicographic *)
(* ordering), seqprod_with d T (using product order), seqlexi_with d T *)
(* (with lexicographic ordering), n.-tupleprod[disp] (using product order), *)
(* n.-tuplelexi[d] T (with lexicographic ordering), on {subset[disp] T} *)
(* (using subset order) and all possible finite type instances. *)
(* (Use `HB.about type` to discover the instances on type.) *)
(* *)
(* In order to get a canonical order on prod, seq, tuple or set, one may *)
(* import modules DefaultProdOrder or DefaultProdLexiOrder, *)
(* DefaultSeqProdOrder or DefaultSeqLexiOrder, *)
(* DefaultTupleProdOrder or DefaultTupleLexiOrder, *)
(* and DefaultSetSubsetOrder. *)
(* *)
(* We also provide specialized versions of some theorems from path.v. *)
(* *)
(* We provide Order.enum_val, Order.enum_rank, and Order.enum_rank_in, which *)
(* are monotonic variations of enum_val, enum_rank, and enum_rank_in *)
(* whenever the type is porderType, and their monotonicity is provided if *)
(* this order is total. The theory is in the module Order (Order.enum_valK, *)
(* Order.enum_rank_inK, etc) but Order.Enum can be imported to shorten these. *)
(* *)
(* We provide an opaque monotonous bijection tagnat.sig / tagnat.rank between *)
(* the finite types {i : 'I_n & 'I_(p_ i)} and 'I_(\sum_i p_ i): *)
(* tagnat.sig : 'I_(\sum_i p_ i) -> {i : 'I_n & 'I_(p_ i)} *)
(* tagnat.rank : {i : 'I_n & 'I_(p_ i)} -> 'I_(\sum_i p_ i) *)
(* tagnat.sig1 : 'I_(\sum_i p_ i) -> 'I_n *)
(* tagnat.sig2 : forall p : 'I_(\sum_i p_ i), 'I_(p_ (tagnat.sig1 p)) *)
(* tagnat.Rank : forall i, 'I_(p_ i) -> 'I_(\sum_i p_ i) *)
(* *)
(* Acknowledgments: This file is based on prior work by D. Dreyer, G. *)
(* Gonthier, A. Nanevski, P-Y Strub, B. Ziliani *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope order_scope.
Delimit Scope order_scope with O.
Local Open Scope order_scope.
(* Reserved notations for lattice operations *)
Reserved Notation "A `&` B" (at level 48, left associativity).
Reserved Notation "A `|` B" (at level 52, left associativity).
Reserved Notation "A `\` B" (at level 50, left associativity).
Reserved Notation "~` A" (at level 35, right associativity).
(* Reserved notations for dual order *)
Reserved Notation "A `&^d` B" (at level 48, left associativity).
Reserved Notation "A `|^d` B" (at level 52, left associativity).
Reserved Notation "A `\^d` B" (at level 50, left associativity).
Reserved Notation "~^d` A" (at level 35, right associativity).
(* Reserved notations for product ordering of prod *)
Reserved Notation "A `&^p` B" (at level 48, left associativity).
Reserved Notation "A `|^p` B" (at level 52, left associativity).
Reserved Notation "A `\^p` B" (at level 50, left associativity).
Reserved Notation "~^p` A" (at level 35, right associativity).
(* Reserved notations for product ordering of seq *)
Reserved Notation "A `&^sp` B" (at level 48, left associativity).
Reserved Notation "A `|^sp` B" (at level 52, left associativity).
Reserved Notation "A `\^sp` B" (at level 50, left associativity).
Reserved Notation "~^sp` A" (at level 35, right associativity).
(* Reserved notations for lexicographic ordering of prod *)
Reserved Notation "A `&^l` B" (at level 48, left associativity).
Reserved Notation "A `|^l` B" (at level 52, left associativity).
Reserved Notation "A `\^l` B" (at level 50, left associativity).
Reserved Notation "~^l` A" (at level 35, right associativity).
(* Reserved notations for lexicographic ordering of seq *)
Reserved Notation "A `&^sl` B" (at level 48, left associativity).
Reserved Notation "A `|^sl` B" (at level 52, left associativity).
Reserved Notation "A `\^sl` B" (at level 50, left associativity).
Reserved Notation "~^sl` A" (at level 35, right associativity).
(* Reserved notations for divisibility *)
Reserved Notation "\gcd_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \gcd_ i '/ ' F ']'").
Reserved Notation "\gcd_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \gcd_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i <- r ) F"
(F at level 41,
format "'[' \gcd_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\gcd_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \gcd_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( m <= i < n ) F"
(F at level 41,
format "'[' \gcd_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i | P ) F"
(F at level 41,
format "'[' \gcd_ ( i | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\gcd_ ( i : t ) F" (F at level 41).
Reserved Notation "\gcd_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \gcd_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i < n ) F"
(F at level 41,
format "'[' \gcd_ ( i < n ) F ']'").
Reserved Notation "\gcd_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \gcd_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\gcd_ ( i 'in' A ) F"
(F at level 41,
format "'[' \gcd_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\lcm_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \lcm_ i '/ ' F ']'").
Reserved Notation "\lcm_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \lcm_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i <- r ) F"
(F at level 41,
format "'[' \lcm_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\lcm_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \lcm_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( m <= i < n ) F"
(F at level 41,
format "'[' \lcm_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i | P ) F"
(F at level 41,
format "'[' \lcm_ ( i | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\lcm_ ( i : t ) F" (F at level 41).
Reserved Notation "\lcm_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \lcm_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i < n ) F"
(F at level 41,
format "'[' \lcm_ ( i < n ) F ']'").
Reserved Notation "\lcm_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \lcm_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\lcm_ ( i 'in' A ) F"
(F at level 41,
format "'[' \lcm_ ( i 'in' A ) '/ ' F ']'").
(* Reserved notations for iterative meet and join *)
Reserved Notation "\meet_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet_ i '/ ' F ']'").
Reserved Notation "\meet_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i <- r ) F"
(F at level 41,
format "'[' \meet_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet_ ( i | P ) F"
(F at level 41,
format "'[' \meet_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i < n ) F"
(F at level 41,
format "'[' \meet_ ( i < n ) F ']'").
Reserved Notation "\meet_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join_ i '/ ' F ']'").
Reserved Notation "\join_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i <- r ) F"
(F at level 41,
format "'[' \join_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join_ ( i | P ) F"
(F at level 41,
format "'[' \join_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join_ ( i : t ) F" (F at level 41).
Reserved Notation "\join_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i < n ) F"
(F at level 41,
format "'[' \join_ ( i < n ) F ']'").
Reserved Notation "\join_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^d_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^d_ i '/ ' F ']'").
Reserved Notation "\meet^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i | P ) F"
(F at level 41,
format "'[' \meet^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i < n ) F"
(F at level 41,
format "'[' \meet^d_ ( i < n ) F ']'").
Reserved Notation "\meet^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^d_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^d_ i '/ ' F ']'").
Reserved Notation "\join^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i <- r ) F"
(F at level 41,
format "'[' \join^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i | P ) F"
(F at level 41,
format "'[' \join^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i < n ) F"
(F at level 41,
format "'[' \join^d_ ( i < n ) F ']'").
Reserved Notation "\join^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^p_ i '/ ' F ']'").
Reserved Notation "\meet^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i | P ) F"
(F at level 41,
format "'[' \meet^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i < n ) F"
(F at level 41,
format "'[' \meet^p_ ( i < n ) F ']'").
Reserved Notation "\meet^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^p_ i '/ ' F ']'").
Reserved Notation "\join^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i <- r ) F"
(F at level 41,
format "'[' \join^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i | P ) F"
(F at level 41,
format "'[' \join^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i < n ) F"
(F at level 41,
format "'[' \join^p_ ( i < n ) F ']'").
Reserved Notation "\join^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^p_ i '/ ' F ']'").
Reserved Notation "\min^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i <- r ) F"
(F at level 41,
format "'[' \min^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i | P ) F"
(F at level 41,
format "'[' \min^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i < n ) F"
(F at level 41,
format "'[' \min^p_ ( i < n ) F ']'").
Reserved Notation "\min^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^p_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^p_ i '/ ' F ']'").
Reserved Notation "\max^p_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^p_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i <- r ) F"
(F at level 41,
format "'[' \max^p_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^p_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^p_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^p_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i | P ) F"
(F at level 41,
format "'[' \max^p_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^p_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^p_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^p_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i < n ) F"
(F at level 41,
format "'[' \max^p_ ( i < n ) F ']'").
Reserved Notation "\max^p_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^p_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^p_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^p_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^sp_ i '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i | P ) F"
(F at level 41,
format "'[' \meet^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i < n ) F"
(F at level 41,
format "'[' \meet^sp_ ( i < n ) F ']'").
Reserved Notation "\meet^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^sp_ i '/ ' F ']'").
Reserved Notation "\join^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \join^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i | P ) F"
(F at level 41,
format "'[' \join^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i < n ) F"
(F at level 41,
format "'[' \join^sp_ ( i < n ) F ']'").
Reserved Notation "\join^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^sp_ i '/ ' F ']'").
Reserved Notation "\min^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \min^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i | P ) F"
(F at level 41,
format "'[' \min^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i < n ) F"
(F at level 41,
format "'[' \min^sp_ ( i < n ) F ']'").
Reserved Notation "\min^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^sp_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^sp_ i '/ ' F ']'").
Reserved Notation "\max^sp_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^sp_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i <- r ) F"
(F at level 41,
format "'[' \max^sp_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^sp_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^sp_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i | P ) F"
(F at level 41,
format "'[' \max^sp_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^sp_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^sp_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^sp_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i < n ) F"
(F at level 41,
format "'[' \max^sp_ ( i < n ) F ']'").
Reserved Notation "\max^sp_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^sp_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^sp_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^sp_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\meet^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \meet^l_ i '/ ' F ']'").
Reserved Notation "\meet^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \meet^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i <- r ) F"
(F at level 41,
format "'[' \meet^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \meet^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \meet^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i | P ) F"
(F at level 41,
format "'[' \meet^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\meet^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\meet^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \meet^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i < n ) F"
(F at level 41,
format "'[' \meet^l_ ( i < n ) F ']'").
Reserved Notation "\meet^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \meet^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\meet^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \meet^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\join^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \join^l_ i '/ ' F ']'").
Reserved Notation "\join^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \join^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i <- r ) F"
(F at level 41,
format "'[' \join^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\join^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \join^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \join^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i | P ) F"
(F at level 41,
format "'[' \join^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\join^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\join^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \join^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i < n ) F"
(F at level 41,
format "'[' \join^l_ ( i < n ) F ']'").
Reserved Notation "\join^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \join^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\join^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \join^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\min^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min^l_ i '/ ' F ']'").
Reserved Notation "\min^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i <- r ) F"
(F at level 41,
format "'[' \min^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i | P ) F"
(F at level 41,
format "'[' \min^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i < n ) F"
(F at level 41,
format "'[' \min^l_ ( i < n ) F ']'").
Reserved Notation "\min^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^l_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max^l_ i '/ ' F ']'").
Reserved Notation "\max^l_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^l_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i <- r ) F"
(F at level 41,
format "'[' \max^l_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^l_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^l_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^l_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i | P ) F"
(F at level 41,
format "'[' \max^l_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^l_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^l_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^l_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i < n ) F"
(F at level 41,
format "'[' \max^l_ ( i < n ) F ']'").
Reserved Notation "\max^l_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^l_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^l_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^l_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "'{' 'omorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'omorphism' U -> V }").
Reserved Notation "'{' 'mlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'mlmorphism' U -> V }").
Reserved Notation "'{' 'jlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'jlmorphism' U -> V }").
Reserved Notation "'{' 'lmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'lmorphism' U -> V }").
Reserved Notation "'{' 'blmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'blmorphism' U -> V }").
Reserved Notation "'{' 'tlmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'tlmorphism' U -> V }").
Reserved Notation "'{' 'tblmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'tblmorphism' U -> V }").
Module Order.
Export Order.
#[key="T", primitive]
HB.mixin Record Preorder_isDuallyPOrder (d : disp_t) T of Preorder d T := {
le_anti : antisymmetric (@le d T);
ge_anti : antisymmetric (fun x y => @le d T y x);
}.
#[short(type="porderType")]
HB.structure Definition POrder (d : disp_t) :=
{ T of Preorder d T & Preorder_isDuallyPOrder d T }.
#[short(type="bPOrderType")]
HB.structure Definition BPOrder d := { T of hasBottom d T & POrder d T }.
#[short(type="tPOrderType")]
HB.structure Definition TPOrder d := { T of hasTop d T & POrder d T }.
#[short(type="tbPOrderType")]
HB.structure Definition TBPOrder d := { T of hasTop d T & BPOrder d T }.
Module POrderExports.
Arguments le_trans {d s} [_ _ _].
End POrderExports.
HB.export POrderExports.
(* Bind Scope order_scope with POrder.sort. *)
#[key="T", primitive]
HB.mixin Record POrder_isMeetSemilattice d (T : Type) of POrder d T := {
meet : T -> T -> T;
lexI : forall x y z, (x <= meet y z) = (x <= y) && (x <= z);
}.
#[key="T", primitive]
HB.mixin Record POrder_isJoinSemilattice d T of POrder d T := {
join : T -> T -> T;
leUx : forall x y z, (join x y <= z) = (x <= z) && (y <= z);
}.
#[short(type="meetSemilatticeType")]
HB.structure Definition MeetSemilattice d :=
{ T of POrder d T & POrder_isMeetSemilattice d T }.
#[short(type="bMeetSemilatticeType")]
HB.structure Definition BMeetSemilattice d :=
{ T of MeetSemilattice d T & hasBottom d T }.
#[short(type="tMeetSemilatticeType")]
HB.structure Definition TMeetSemilattice d :=
{ T of MeetSemilattice d T & hasTop d T }.
#[short(type="tbMeetSemilatticeType")]
HB.structure Definition TBMeetSemilattice d :=
{ T of BMeetSemilattice d T & hasTop d T }.
#[short(type="joinSemilatticeType")]
HB.structure Definition JoinSemilattice d :=
{ T of POrder d T & POrder_isJoinSemilattice d T }.
#[short(type="bJoinSemilatticeType")]
HB.structure Definition BJoinSemilattice d :=
{ T of JoinSemilattice d T & hasBottom d T }.
#[short(type="tJoinSemilatticeType")]
HB.structure Definition TJoinSemilattice d :=
{ T of JoinSemilattice d T & hasTop d T }.
#[short(type="tbJoinSemilatticeType")]
HB.structure Definition TBJoinSemilattice d :=
{ T of BJoinSemilattice d T & hasTop d T }.
#[short(type="latticeType")]
HB.structure Definition Lattice d :=
{ T of JoinSemilattice d T & POrder_isMeetSemilattice d T }.
#[short(type="bLatticeType")]
HB.structure Definition BLattice d := { T of Lattice d T & hasBottom d T }.
#[short(type="tLatticeType")]
HB.structure Definition TLattice d := { T of Lattice d T & hasTop d T }.
#[short(type="tbLatticeType")]
HB.structure Definition TBLattice d := { T of BLattice d T & hasTop d T }.
Section LatticeDef.
Context {disp : disp_t} {T : latticeType disp}.
Variant lel_xor_gt (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set :=
| LelNotGt of x <= y : lel_xor_gt x y x x y y x x y y true false
| GtlNotLe of y < x : lel_xor_gt x y y y x x y y x x false true.
Variant ltl_xor_ge (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T -> bool -> bool -> Set :=
| LtlNotGe of x < y : ltl_xor_ge x y x x y y x x y y false true
| GelNotLt of y <= x : ltl_xor_ge x y y y x x y y x x true false.
Variant comparel (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparelLt of x < y : comparel x y
x x y y x x y y false false false true false true
| ComparelGt of y < x : comparel x y
y y x x y y x x false false true false true false
| ComparelEq of x = y : comparel x y
x x x x x x x x true true true true false false.
Variant incomparel (x y : T) :
T -> T -> T -> T -> T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| InComparelLt of x < y : incomparel x y
x x y y x x y y false false false true false true true true
| InComparelGt of y < x : incomparel x y
y y x x y y x x false false true false true false true true
| InComparel of x >< y : incomparel x y
x y y x (meet y x) (meet x y) (join y x) (join x y)
false false false false false false false false
| InComparelEq of x = y : incomparel x y
x x x x x x x x true true true true false false true true.
End LatticeDef.
Module LatticeSyntax.
Notation "x `&` y" := (meet x y) : order_scope.
Notation "x `|` y" := (join x y) : order_scope.
End LatticeSyntax.
HB.export LatticeSyntax.
Module BLatticeSyntax.
Notation "\join_ ( i <- r | P ) F" :=
(\big[@join _ _ / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join_ ( i <- r ) F" :=
(\big[@join _ _ / \bot]_(i <- r) F%O) : order_scope.
Notation "\join_ ( i | P ) F" :=
(\big[@join _ _ / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join_ i F" :=
(\big[@join _ _ / \bot]_i F%O) : order_scope.
Notation "\join_ ( i : I | P ) F" :=
(\big[@join _ _ / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join_ ( i : I ) F" :=
(\big[@join _ _ / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join_ ( m <= i < n | P ) F" :=
(\big[@join _ _ / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join_ ( m <= i < n ) F" :=
(\big[@join _ _ / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join_ ( i < n | P ) F" :=
(\big[@join _ _ / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join_ ( i < n ) F" :=
(\big[@join _ _ / \bot]_(i < n) F%O) : order_scope.
Notation "\join_ ( i 'in' A | P ) F" :=
(\big[@join _ _ / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join_ ( i 'in' A ) F" :=
(\big[@join _ _ / \bot]_(i in A) F%O) : order_scope.
End BLatticeSyntax.
HB.export BLatticeSyntax.
Module TLatticeSyntax.
Notation "\meet_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
End TLatticeSyntax.
HB.export TLatticeSyntax.
#[key="T", primitive]
HB.mixin Record Lattice_isDistributive d (T : Type) of Lattice d T := {
meetUl : @left_distributive T T meet join;
joinIl : @left_distributive T T join meet; (* dual of meetUl *)
}.
#[short(type="distrLatticeType")]
HB.structure Definition DistrLattice d :=
{ T of Lattice_isDistributive d T & Lattice d T }.
#[short(type="bDistrLatticeType")]
HB.structure Definition BDistrLattice d :=
{ T of DistrLattice d T & hasBottom d T }.
#[short(type="tDistrLatticeType")]
HB.structure Definition TDistrLattice d :=
{ T of DistrLattice d T & hasTop d T }.
#[short(type="tbDistrLatticeType")]
HB.structure Definition TBDistrLattice d :=
{ T of BDistrLattice d T & hasTop d T }.
#[key="T", primitive]
HB.mixin Record DistrLattice_isTotal d T of DistrLattice d T :=
{ le_total : total (<=%O : rel T) }.
#[short(type="orderType")]
HB.structure Definition Total d :=
{ T of DistrLattice_isTotal d T & DistrLattice d T }.
#[short(type="bOrderType")]
HB.structure Definition BTotal d := { T of Total d T & hasBottom d T }.
#[short(type="tOrderType")]
HB.structure Definition TTotal d := { T of Total d T & hasTop d T }.
#[short(type="tbOrderType")]
HB.structure Definition TBTotal d := { T of BTotal d T & hasTop d T }.
#[key="T", primitive]
HB.mixin Record DistrLattice_hasRelativeComplement d T of DistrLattice d T := {
(* rcompl x y z is the complement of z in the interval [x, y]. *)
rcompl : T -> T -> T -> T;
rcomplPmeet : forall x y z, ((x `&` y) `|` z) `&` rcompl x y z = x `&` y;
rcomplPjoin : forall x y z, ((y `|` x) `&` z) `|` rcompl x y z = y `|` x;
}.
#[short(type="cDistrLatticeType")]
HB.structure Definition CDistrLattice d :=
{ T of DistrLattice d T & DistrLattice_hasRelativeComplement d T }.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasSectionalComplement d T
of CDistrLattice d T & hasBottom d T := {
diff : T -> T -> T;
(* FIXME: a bug in HB prevents us writing "rcompl \bot x y" *)
diffErcompl : forall x y, diff x y = rcompl (\bot : T) x y;
}.
#[short(type="cbDistrLatticeType")]
HB.structure Definition CBDistrLattice d :=
{ T of CDistrLattice d T & hasBottom d T &
CDistrLattice_hasSectionalComplement d T }.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasDualSectionalComplement d T
of CDistrLattice d T & hasTop d T := {
codiff : T -> T -> T;
codiffErcompl : forall x y, codiff x y = rcompl x \top y;
}.
#[short(type="ctDistrLatticeType")]
HB.structure Definition CTDistrLattice d :=
{ T of CDistrLattice d T & hasTop d T &
CDistrLattice_hasDualSectionalComplement d T }.
Module Import CBDistrLatticeSyntax.
Notation "x `\` y" := (diff x y) : order_scope.
End CBDistrLatticeSyntax.
#[key="T", primitive]
HB.mixin Record CDistrLattice_hasComplement d T of
CTDistrLattice d T & CBDistrLattice d T := {
compl : T -> T;
(* FIXME: a bug in HB prevents us writing "\top `\` x" and "codiff \bot x" *)
complEdiff : forall x : T, compl x = (\top : T) `\` x;
complEcodiff : forall x : T, compl x = codiff (\bot : T) x;
}.
#[short(type="ctbDistrLatticeType")]
HB.structure Definition CTBDistrLattice d :=
{ T of CBDistrLattice d T & CTDistrLattice d T &
CDistrLattice_hasComplement d T }.
Module Import CTBDistrLatticeSyntax.
Notation "~` A" := (compl A) : order_scope.
End CTBDistrLatticeSyntax.
(**********)
(* FINITE *)
(**********)
#[short(type="finPOrderType")]
HB.structure Definition FinPOrder d := { T of Finite T & POrder d T }.
#[short(type="finBPOrderType")]
HB.structure Definition FinBPOrder d := { T of FinPOrder d T & hasBottom d T }.
#[short(type="finTPOrderType")]
HB.structure Definition FinTPOrder d := { T of FinPOrder d T & hasTop d T }.
#[short(type="finTBPOrderType")]
HB.structure Definition FinTBPOrder d := { T of FinBPOrder d T & hasTop d T }.
#[short(type="finMeetSemilatticeType")]
HB.structure Definition FinMeetSemilattice d :=
{ T of Finite T & MeetSemilattice d T }.
#[short(type="finBMeetSemilatticeType")]
HB.structure Definition FinBMeetSemilattice d :=
{ T of Finite T & BMeetSemilattice d T }.
#[short(type="finJoinSemilatticeType")]
HB.structure Definition FinJoinSemilattice d :=
{ T of Finite T & JoinSemilattice d T }.
#[short(type="finTJoinSemilatticeType")]
HB.structure Definition FinTJoinSemilattice d :=
{ T of Finite T & TJoinSemilattice d T }.
#[short(type="finLatticeType")]
HB.structure Definition FinLattice d := { T of Finite T & Lattice d T }.
#[short(type="finTBLatticeType")]
HB.structure Definition FinTBLattice d := { T of Finite T & TBLattice d T }.
#[short(type="finDistrLatticeType")]
HB.structure Definition FinDistrLattice d :=
{ T of Finite T & DistrLattice d T }.
#[short(type="finTBDistrLatticeType")]
HB.structure Definition FinTBDistrLattice d :=
{ T of Finite T & TBDistrLattice d T }.
#[short(type="finOrderType")]
HB.structure Definition FinTotal d := { T of Finite T & Total d T }.
#[short(type="finTBOrderType")]
HB.structure Definition FinTBTotal d := { T of Finite T & TBTotal d T }.
#[short(type="finCDistrLatticeType")]
HB.structure Definition FinCDistrLattice d :=
{ T of Finite T & CDistrLattice d T }.
#[short(type="finCTBDistrLatticeType")]
HB.structure Definition FinCTBDistrLattice d :=
{ T of Finite T & CTBDistrLattice d T }.
(********)
(* DUAL *)
(********)
Notation dual_meet := (@meet (dual_display _) _).
Notation dual_join := (@join (dual_display _) _).
Module Import DualSyntax.
Notation "x `&^d` y" := (dual_meet x y) : order_scope.
Notation "x `|^d` y" := (dual_join x y) : order_scope.
(* The following Local Notations are here to define the \join^d_ and \meet^d_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := dual_bottom.
Local Notation "\top" := dual_top.
Local Notation join := dual_join.
Local Notation meet := dual_meet.
Local Notation min := dual_min.
Local Notation max := dual_max.
Notation "\join^d_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^d_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^d_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^d_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^d_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^d_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^d_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^d_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^d_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^d_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^d_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^d_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^d_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^d_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^d_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^d_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^d_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\meet^d_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^d_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^d_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^d_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^d_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^d_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^d_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^d_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^d_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^d_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^d_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^d_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^d_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^d_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^d_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^d_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^d_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^d_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^d_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^d_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^d_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^d_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^d_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^d_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^d_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^d_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^d_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^d_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^d_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^d_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^d_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End DualSyntax.
(*
FIXME: we have two issues in the dual instance declarations in the DualOrder
module below:
1. HB.saturate is slow, and
2. if we declare them by HB.instance, some declarations fail because it unfolds
[dual] and the generated instance does not typecheck
(math-comp/hierarchy-builder#257).
*)
Module DualOrder.
HB.instance Definition _ (d : disp_t) (T : porderType d) :=
Preorder_isDuallyPOrder.Build (dual_display d) T^d
ge_anti le_anti.
HB.instance Definition _ d (T : joinSemilatticeType d) :=
POrder_isMeetSemilattice.Build (dual_display d) T^d (fun x y z => leUx y z x).
Lemma meetEdual d (T : joinSemilatticeType d) (x y : T) :
((x : T^d) `&^d` y) = (x `|` y).
Proof. by []. Qed.
HB.instance Definition _ d (T : meetSemilatticeType d) :=
POrder_isJoinSemilattice.Build (dual_display d) T^d (fun x y z => lexI z x y).
Lemma joinEdual d (T : meetSemilatticeType d) (x y : T) :
((x : T^d) `|^d` y) = (x `&` y).
Proof. by []. Qed.
HB.saturate.
HB.instance Definition _ d (T : distrLatticeType d) :=
Lattice_isDistributive.Build (dual_display d) T^d joinIl meetUl.
HB.instance Definition _ d (T : orderType d) :=
DistrLattice_isTotal.Build (dual_display d) T^d (fun x y => le_total y x).
HB.saturate.
HB.instance Definition _ d (T : cDistrLatticeType d) :=
DistrLattice_hasRelativeComplement.Build (dual_display d) T^d
(fun x y => rcomplPjoin y x) (fun x y => rcomplPmeet y x).
HB.instance Definition _ d (T : ctDistrLatticeType d) :=
CDistrLattice_hasSectionalComplement.Build (dual_display d) T^d codiffErcompl.
HB.instance Definition _ d (T : cbDistrLatticeType d) :=
CDistrLattice_hasDualSectionalComplement.Build (dual_display d) T^d
diffErcompl.
HB.instance Definition _ d (T : ctbDistrLatticeType d) :=
CDistrLattice_hasComplement.Build (dual_display d) T^d
complEcodiff complEdiff.
HB.saturate.
End DualOrder.
HB.export DualOrder.
(**********)
(* THEORY *)
(**********)
Module Import POrderTheory.
Include PreorderTheory.
Section POrderTheory.
Context {disp : disp_t} {T : porderType disp}.
Implicit Types (x y : T) (s : seq T).
Lemma le_anti: antisymmetric (<=%O : rel T).
Proof. exact: le_anti. Qed.
Lemma ge_anti: antisymmetric (>=%O : rel T).
Proof. by move=> x y /le_anti. Qed.
Lemma eq_le x y: (x == y) = (x <= y <= x).
Proof. by apply/eqP/idP => [->|/le_anti]; rewrite ?lexx. Qed.
Lemma lt_def x y : (x < y) = (y != x) && (x <= y).
Proof.
rewrite andbC lt_le_def; case/boolP: (x <= y) => //= xy.
congr negb; apply/idP/eqP => [yx|->]; last exact/lexx.
by apply/le_anti; rewrite yx.
Qed.
Lemma lt_neqAle x y: (x < y) = (x != y) && (x <= y).
Proof. by rewrite lt_def eq_sym. Qed.
Lemma le_eqVlt x y: (x <= y) = (x == y) || (x < y).
Proof. by rewrite lt_neqAle; case: eqP => //= ->; rewrite lexx. Qed.
Definition lte_anti := (=^~ eq_le, @lt_asym disp T, @lt_le_asym disp T, @le_lt_asym disp T).
Lemma lt_sorted_uniq_le s : sorted <%O s = uniq s && sorted <=%O s.
Proof.
rewrite le_sorted_pairwise lt_sorted_pairwise uniq_pairwise -pairwise_relI.
by apply/eq_pairwise => ? ?; rewrite lt_neqAle.
Qed.
Lemma le_sorted_eq s1 s2 :
sorted <=%O s1 -> sorted <=%O s2 -> perm_eq s1 s2 -> s1 = s2.
Proof. exact/sorted_eq/le_anti/le_trans. Qed.
Lemma count_lt_le_mem x s : (count (< x) s < count (<= x) s)%N = (x \in s).
Proof.
have := count_predUI (pred1 x) (< x) s.
have -> : count (predI (pred1 x) (< x)) s = 0%N.
rewrite (@eq_count _ _ pred0) ?count_pred0 // => y /=.
by rewrite lt_neqAle; case: eqP => //= ->; rewrite eqxx.
have /eq_count-> : [predU1 x & < x] =1 (<= x) by move=> y /=; rewrite le_eqVlt.
by rewrite addn0 => ->; rewrite -add1n leq_add2r -has_count has_pred1.
Qed.
Lemma comparable_ltgtP x y : x >=< y ->
compare x y (min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof.
rewrite /min /max />=<%O !le_eqVlt [y == x]eq_sym.
have := (eqVneq x y, (boolP (x < y), boolP (y < x))).
move=> [[->//|neq_xy /=] [[] xy [] //=]] ; do ?by rewrite ?ltxx; constructor.
by rewrite ltxx in xy.
by rewrite le_gtF // ltW.
Qed.
Lemma comparable_leP x y : x >=< y ->
le_xor_gt x y (min y x) (min x y) (max y x) (max x y) (x <= y) (y < x).
Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed.
Lemma comparable_ltP x y : x >=< y ->
lt_xor_ge x y (min y x) (min x y) (max y x) (max x y) (y <= x) (x < y).
Proof. by move=> /comparable_ltgtP [?|?|->]; constructor; rewrite // ltW. Qed.
Lemma comparableP x y : incompare x y
(min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y)
(y >=< x) (x >=< y).
Proof.
rewrite ![y >=< _]comparable_sym; have [c_xy|i_xy] := boolP (x >=< y).
by case: (comparable_ltgtP c_xy) => ?; constructor.
by rewrite /min /max ?incomparable_eqF ?incomparable_leF;
rewrite ?incomparable_ltF// 1?comparable_sym //; constructor.
Qed.
(* leif *)
Lemma leifP x y C : reflect (x <= y ?= iff C) (if C then x == y else x < y).
Proof.
rewrite /leif le_eqVlt; apply: (iffP idP)=> [|[]].
by case: C => [/eqP->|lxy]; rewrite ?eqxx // lxy lt_eqF.
by move=> /orP[/eqP->|lxy] <-; rewrite ?eqxx // lt_eqF.
Qed.
Lemma leif_trans x1 x2 x3 C12 C23 :
x1 <= x2 ?= iff C12 -> x2 <= x3 ?= iff C23 -> x1 <= x3 ?= iff C12 && C23.
Proof.
move=> ltx12 ltx23; apply/leifP; rewrite -ltx12.
case eqx12: (x1 == x2).
by rewrite (eqP eqx12) lt_neqAle !ltx23 andbT; case C23.
by rewrite (@lt_le_trans _ _ x2) ?ltx23 // lt_neqAle eqx12 ltx12.
Qed.
Lemma leif_le x y : x <= y -> x <= y ?= iff (x >= y).
Proof. by move=> lexy; split=> //; rewrite eq_le lexy. Qed.
Lemma leif_eq x y : x <= y -> x <= y ?= iff (x == y).
Proof. by []. Qed.
Lemma ge_leif x y C : x <= y ?= iff C -> (y <= x) = C.
Proof. by case=> le_xy; rewrite eq_le le_xy. Qed.
Lemma lt_leif x y C : x <= y ?= iff C -> (x < y) = ~~ C.
Proof. by move=> le_xy; rewrite lt_neqAle !le_xy andbT. Qed.
Lemma ltNleif x y C : x <= y ?= iff ~~ C -> (x < y) = C.
Proof. by move=> /lt_leif; rewrite negbK. Qed.
(* lteif *)
Lemma lteif_anti C1 C2 x y :
(x < y ?<= if C1) && (y < x ?<= if C2) = C1 && C2 && (x == y).
Proof. by case: C1 C2 => [][]; rewrite lte_anti. Qed.
Lemma lteifN C x y : x < y ?<= if ~~ C -> ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: comparableP. Qed.
(* min and max *)
Lemma minEle x y : min x y = if x <= y then x else y.
Proof. by case: comparableP. Qed.
Lemma maxEle x y : max x y = if x <= y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_minEgt x y : x >=< y -> min x y = if x > y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_maxEgt x y : x >=< y -> max x y = if x > y then x else y.
Proof. by case: comparableP. Qed.
Lemma comparable_minEge x y : x >=< y -> min x y = if x >= y then y else x.
Proof. by case: comparableP. Qed.
Lemma comparable_maxEge x y : x >=< y -> max x y = if x >= y then x else y.
Proof. by case: comparableP. Qed.
Lemma min_l x y : x <= y -> min x y = x. Proof. by case: comparableP. Qed.
Lemma min_r x y : y <= x -> min x y = y. Proof. by case: comparableP. Qed.
Lemma max_l x y : y <= x -> max x y = x. Proof. by case: comparableP. Qed.
Lemma max_r x y : x <= y -> max x y = y. Proof. by case: comparableP. Qed.
Lemma eq_minl x y : (min x y == x) = (x <= y).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed.
Lemma eq_maxr x y : (max x y == y) = (x <= y).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP. Qed.
Lemma min_idPl x y : reflect (min x y = x) (x <= y).
Proof. by rewrite -eq_minl; apply/eqP. Qed.
Lemma max_idPr x y : reflect (max x y = y) (x <= y).
Proof. by rewrite -eq_maxr; apply/eqP. Qed.
Section Comparable2.
Context (z x y : T) (cmp_xy : x >=< y).
Lemma comparable_minC : min x y = min y x.
Proof. by case: comparableP cmp_xy. Qed.
Lemma comparable_maxC : max x y = max y x.
Proof. by case: comparableP cmp_xy. Qed.
Lemma comparable_eq_minr : (min x y == y) = (y <= x).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed.
Lemma comparable_eq_maxl : (max x y == x) = (y <= x).
Proof. by rewrite !(fun_if, if_arg) eqxx; case: comparableP cmp_xy. Qed.
Lemma comparable_min_idPr : reflect (min x y = y) (y <= x).
Proof. by rewrite -comparable_eq_minr; apply/eqP. Qed.
Lemma comparable_max_idPl : reflect (max x y = x) (y <= x).
Proof. by rewrite -comparable_eq_maxl; apply/eqP. Qed.
Lemma comparable_lteifNE C : x >=< y -> x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: comparableP. Qed.
End Comparable2.
Section Comparable3.
Context (x y z : T) (cmp_xy : x >=< y) (cmp_xz : x >=< z) (cmp_yz : y >=< z).
Let P := comparableP.
Lemma comparable_max_minl : max (min x y) z = min (max x z) (max y z).
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/=.
move: (P x y) (P x z) (P y z).
move=> [xy|xy|xy|<-] [xz|xz|xz|<-] [yz|yz|yz|//->]//= _; rewrite ?ltxx//.
- by have := lt_trans xy (lt_trans yz xz); rewrite ltxx.
- by have := lt_trans xy (lt_trans xz yz); rewrite ltxx.
Qed.
End Comparable3.
Section Comparable4.
Context (x y z w : T) (cmp_xy : x >=< y) (cmp_zw : z >=< w).
Lemma comparable_le_min2 : x <= z -> y <= w ->
Order.min x y <= Order.min z w.
Proof.
move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw.
- exact: le_trans xy yw.
- exact: le_trans (ltW xy) xz.
Qed.
Lemma comparable_le_max2 : x <= z -> y <= w ->
Order.max x y <= Order.max z w.
Proof.
move: cmp_xy cmp_zw => /comparable_leP[] xy /comparable_leP[] zw // xz yw.
- exact: le_trans yw (ltW zw).
- exact: le_trans xz zw.
Qed.
End Comparable4.
Lemma comparable_minAC x y z : x >=< y -> x >=< z -> y >=< z ->
min (min x y) z = min (min x z) y.
Proof.
move=> xy xz yz; rewrite -comparable_minA// [min y z]comparable_minC//.
by rewrite comparable_minA// 1?comparable_sym.
Qed.
Lemma comparable_maxAC x y z : x >=< y -> x >=< z -> y >=< z ->
max (max x y) z = max (max x z) y.
Proof.
move=> xy xz yz; rewrite -comparable_maxA// [max y z]comparable_maxC//.
by rewrite comparable_maxA// 1?comparable_sym.
Qed.
Lemma comparable_minCA x y z : x >=< y -> x >=< z -> y >=< z ->
min x (min y z) = min y (min x z).
Proof.
move=> xy xz yz; rewrite comparable_minA// [min x y]comparable_minC//.
by rewrite -comparable_minA// 1?comparable_sym.
Qed.
Lemma comparable_maxCA x y z : x >=< y -> x >=< z -> y >=< z ->
max x (max y z) = max y (max x z).
Proof.
move=> xy xz yz; rewrite comparable_maxA// [max x y]comparable_maxC//.
by rewrite -comparable_maxA// 1?comparable_sym.
Qed.
Lemma comparable_minACA x y z t :
x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t ->
min (min x y) (min z t) = min (min x z) (min y t).
Proof.
move=> xy xz xt yz yt zt; rewrite comparable_minA// ?comparable_minl//.
rewrite [min _ z]comparable_minAC// -comparable_minA// ?comparable_minl//.
by rewrite inE comparable_sym.
Qed.
Lemma comparable_maxACA x y z t :
x >=< y -> x >=< z -> x >=< t -> y >=< z -> y >=< t -> z >=< t ->
max (max x y) (max z t) = max (max x z) (max y t).
Proof.
move=> xy xz xt yz yt zt; rewrite comparable_maxA// ?comparable_maxl//.
rewrite [max _ z]comparable_maxAC// -comparable_maxA// ?comparable_maxl//.
by rewrite inE comparable_sym.
Qed.
Lemma comparable_min_maxr x y z : x >=< y -> x >=< z -> y >=< z ->
min x (max y z) = max (min x y) (min x z).
Proof.
move=> xy xz yz; rewrite ![min x _]comparable_minC// ?comparable_maxr//.
by rewrite comparable_min_maxl// 1?comparable_sym.
Qed.
(* monotonicity *)
Lemma mono_in_leif (A : {pred T}) (f : T -> T) C :
{in A &, {mono f : x y / x <= y}} ->
{in A &, forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C)}.
Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed.
Lemma mono_leif (f : T -> T) C :
{mono f : x y / x <= y} ->
forall x y, (f x <= f y ?= iff C) = (x <= y ?= iff C).
Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed.
Lemma nmono_in_leif (A : {pred T}) (f : T -> T) C :
{in A &, {mono f : x y /~ x <= y}} ->
{in A &, forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C)}.
Proof. by move=> mf x y Ax Ay; rewrite /leif !eq_le !mf. Qed.
Lemma nmono_leif (f : T -> T) C : {mono f : x y /~ x <= y} ->
forall x y, (f x <= f y ?= iff C) = (y <= x ?= iff C).
Proof. by move=> mf x y; rewrite /leif !eq_le !mf. Qed.
Section bigminmax.
Context (I : Type) (r : seq I) (f : I -> T) (x0 x : T) (P : pred I).
Lemma bigmax_le : x0 <= x -> (forall i, P i -> f i <= x) ->
\big[max/x0]_(i <- r | P i) f i <= x.
Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite maxEle; case: ifPn. Qed.
Lemma le_bigmin : x <= x0 -> (forall i, P i -> x <= f i) ->
x <= \big[min/x0]_(i <- r | P i) f i.
Proof. by move=> ? ?; elim/big_ind: _ => // *; rewrite minEle; case: ifPn. Qed.
End bigminmax.
End POrderTheory.
#[global] Hint Resolve comparable_minr comparable_minl : core.
#[global] Hint Resolve comparable_maxr comparable_maxl : core.
Section ContraTheory.
Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : porderType disp2}.
Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop).
Lemma contra_leT b x y : (~~ b -> x < y) -> (y <= x -> b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_ltT b x y : (~~ b -> x <= y) -> (y < x -> b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_leN b x y : (b -> x < y) -> (y <= x -> ~~ b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_ltN b x y : (b -> x <= y) -> (y < x -> ~~ b).
Proof. by case: comparableP; case: b. Qed.
Lemma contra_le_not P x y : (P -> x < y) -> (y <= x -> ~ P).
Proof. by case: comparableP => // _ PF _ /PF. Qed.
Lemma contra_lt_not P x y : (P -> x <= y) -> (y < x -> ~ P).
Proof. by case: comparableP => // _ PF _ /PF. Qed.
Lemma contra_leF b x y : (b -> x < y) -> (y <= x -> b = false).
Proof. by case: comparableP; case: b => // _ /implyP. Qed.
Lemma contra_ltF b x y : (b -> x <= y) -> (y < x -> b = false).
Proof. by case: comparableP; case: b => // _ /implyP. Qed.
Lemma contra_le_leq x y m n : ((n < m)%N -> y < x) -> (x <= y -> (m <= n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_le_ltn x y m n : ((n <= m)%N -> y < x) -> (x <= y -> (m < n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_lt_leq x y m n : ((n < m)%N -> y <= x) -> (x < y -> (m <= n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
Lemma contra_lt_ltn x y m n : ((n <= m)%N -> y <= x) -> (x < y -> (m < n)%N).
Proof. by case: comparableP; case: ltngtP. Qed.
End ContraTheory.
Section POrderMonotonyTheory.
Context {disp disp' : disp_t} {T : porderType disp} {T' : porderType disp'}.
Context (D D' : {pred T}) (f : T -> T').
Let leT_anti := @le_anti _ T.
Hint Resolve lexx lt_neqAle : core.
Let ge_antiT : antisymmetric (>=%O : rel T).
Proof. by move=> ? ? /le_anti. Qed.
Lemma ltW_homo : {homo f : x y / x < y} -> {homo f : x y / x <= y}.
Proof. exact: homoW. Qed.
Lemma ltW_nhomo : {homo f : x y /~ x < y} -> {homo f : x y /~ x <= y}.
Proof. by apply: homoW=> // x y; rewrite eq_sym. Qed.
Lemma inj_homo_lt :
injective f -> {homo f : x y / x <= y} -> {homo f : x y / x < y}.
Proof. exact: inj_homo. Qed.
Lemma inj_nhomo_lt :
injective f -> {homo f : x y /~ x <= y} -> {homo f : x y /~ x < y}.
Proof. by apply: inj_homo=> // x y; rewrite eq_sym. Qed.
Lemma inc_inj : {mono f : x y / x <= y} -> injective f.
Proof. exact: mono_inj. Qed.
Lemma dec_inj : {mono f : x y /~ x <= y} -> injective f.
Proof. exact: mono_inj. Qed.
(* Monotony in D D' *)
Lemma ltW_homo_in :
{in D & D', {homo f : x y / x < y}} -> {in D & D', {homo f : x y / x <= y}}.
Proof. exact: homoW_in. Qed.
Lemma ltW_nhomo_in :
{in D & D', {homo f : x y /~ x < y}} -> {in D & D', {homo f : x y /~ x <= y}}.
Proof. by apply: homoW_in=> // x y; rewrite eq_sym. Qed.
Lemma inj_homo_lt_in :
{in D & D', injective f} -> {in D & D', {homo f : x y / x <= y}} ->
{in D & D', {homo f : x y / x < y}}.
Proof. exact: inj_homo_in. Qed.
Lemma inj_nhomo_lt_in :
{in D & D', injective f} -> {in D & D', {homo f : x y /~ x <= y}} ->
{in D & D', {homo f : x y /~ x < y}}.
Proof. by apply: inj_homo_in=> // x y; rewrite eq_sym. Qed.
Lemma inc_inj_in : {in D &, {mono f : x y / x <= y}} ->
{in D &, injective f}.
Proof. exact: mono_inj_in. Qed.
Lemma dec_inj_in :
{in D &, {mono f : x y /~ x <= y}} -> {in D &, injective f}.
Proof. exact: mono_inj_in. Qed.
End POrderMonotonyTheory.
End POrderTheory.
Arguments leifP {disp T x y C}.
Arguments mono_in_leif [disp T A f C].
Arguments nmono_in_leif [disp T A f C].
Arguments mono_leif [disp T f C].
Arguments nmono_leif [disp T f C].
Arguments min_idPl {disp T x y}.
Arguments max_idPr {disp T x y}.
Arguments comparable_min_idPr {disp T x y _}.
Arguments comparable_max_idPl {disp T x y _}.
Module Import BPOrderTheory.
Export BPreorderTheory.
Section BPOrderTheory.
Context {disp : disp_t} {T : bPOrderType disp}.
Implicit Types (x y : T).
Lemma lex0 x : (x <= \bot) = (x == \bot).
Proof. by rewrite le_eqVlt ltx0 orbF. Qed.
Lemma lt0x x : (\bot < x) = (x != \bot).
Proof. by rewrite lt_def le0x andbT. Qed.
Variant eq0_xor_gt0 x : bool -> bool -> Set :=
Eq0NotPOs : x = \bot -> eq0_xor_gt0 x true false
| POsNotEq0 : \bot < x -> eq0_xor_gt0 x false true.
Lemma posxP x : eq0_xor_gt0 x (x == \bot) (\bot < x).
Proof. by rewrite lt0x; have [] := eqVneq; constructor; rewrite ?lt0x. Qed.
End BPOrderTheory.
End BPOrderTheory.
Module Import TPOrderTheory.
Section TPOrderTheory.
Context {disp : disp_t} {T : tPOrderType disp}.
Implicit Types (x y : T).
Lemma le1x x : (\top <= x) = (x == \top). Proof. exact: (@lex0 _ T^d). Qed.
Lemma ltx1 x : (x < \top) = (x != \top). Proof. exact: (@lt0x _ T^d). Qed.
End TPOrderTheory.
End TPOrderTheory.
Module Import MeetTheory.
Section MeetTheory.
Context {disp : disp_t} {L : meetSemilatticeType disp}.
Implicit Types (x y : L).
(* interaction with order *)
Lemma lexI x y z : (x <= y `&` z) = (x <= y) && (x <= z).
Proof. exact: lexI. Qed.
Lemma leIr x y : y `&` x <= x.
Proof. by have:= le_refl (meet y x); rewrite lexI => /andP []. Qed.
Lemma leIl x y : x `&` y <= x.
Proof. by have:= le_refl (meet x y); rewrite lexI => /andP []. Qed.
Lemma leIxl x y z : y <= x -> y `&` z <= x.
Proof. exact/le_trans/leIl. Qed.
Lemma leIxr x y z : z <= x -> y `&` z <= x.
Proof. exact/le_trans/leIr. Qed.
Lemma leIx2 x y z : (y <= x) || (z <= x) -> y `&` z <= x.
Proof. by case/orP => [/leIxl|/leIxr]. Qed.
Lemma leEmeet x y : (x <= y) = (x `&` y == x).
Proof. by rewrite eq_le lexI leIl lexx. Qed.
Lemma eq_meetl x y : (x `&` y == x) = (x <= y).
Proof. by apply/esym/leEmeet. Qed.
Lemma eq_meetr x y : (x `&` y == y) = (y <= x).
Proof. by rewrite eq_le lexI leIr lexx andbT. Qed.
Lemma meet_idPl {x y} : reflect (x `&` y = x) (x <= y).
Proof. by rewrite -eq_meetl; apply/eqP. Qed.
Lemma meet_idPr {x y} : reflect (y `&` x = x) (x <= y).
Proof. by rewrite -eq_meetr; apply/eqP. Qed.
Lemma meet_l x y : x <= y -> x `&` y = x. Proof. exact/meet_idPl. Qed.
Lemma meet_r x y : y <= x -> x `&` y = y. Proof. exact/meet_idPr. Qed.
Lemma leIidl x y : (x <= x `&` y) = (x <= y).
Proof. by rewrite lexI lexx. Qed.
Lemma leIidr x y : (x <= y `&` x) = (x <= y).
Proof. by rewrite lexI lexx andbT. Qed.
Lemma leI2 x y z t : x <= z -> y <= t -> x `&` y <= z `&` t.
Proof. by move=> xz yt; rewrite lexI !leIx2 ?xz ?yt ?orbT //. Qed.
(* algebraic properties *)
Lemma meetC : commutative (@meet _ L).
Proof. by move=> x y; apply: le_anti; rewrite !lexI !leIr !leIl. Qed.
Lemma meetA : associative (@meet _ L).
Proof.
move=> x y z; apply: le_anti.
rewrite !lexI leIr leIl /= andbT -andbA.
rewrite ![_ `&` (_ `&` _) <= _]leIxr ?(leIr, leIl) //=.
by rewrite leIxl ?leIl // leIxl // leIr.
Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build L meet meetA meetC.
Lemma meetxx : idempotent_op (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meetAC : right_commutative (@meet _ L).
Proof. by move=> x y z; rewrite -!meetA [X in _ `&` X]meetC. Qed.
Lemma meetCA : left_commutative (@meet _ L).
Proof. by move=> x y z; rewrite !meetA [X in X `&` _]meetC. Qed.
Lemma meetACA : interchange (@meet _ L) (@meet _ L).
Proof. by move=> x y z t; rewrite !meetA [X in X `&` _]meetAC. Qed.
Lemma meetKI y x : x `&` (x `&` y) = x `&` y.
Proof. by rewrite meetA meetxx. Qed.
Lemma meetIK y x : (x `&` y) `&` y = x `&` y.
Proof. by rewrite -meetA meetxx. Qed.
Lemma meetKIC y x : x `&` (y `&` x) = x `&` y.
Proof. by rewrite meetC meetIK meetC. Qed.
Lemma meetIKC y x : y `&` x `&` y = x `&` y.
Proof. by rewrite meetAC meetC meetxx. Qed.
End MeetTheory.
End MeetTheory.
Arguments meet_idPl {disp L x y}.
Arguments meet_idPr {disp L x y}.
Module Import BMeetTheory.
Section BMeetTheory.
Context {disp : disp_t} {L : bMeetSemilatticeType disp}.
Lemma meet0x : left_zero \bot (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meetx0 : right_zero \bot (@meet _ L).
Proof. by move=> x; rewrite meetC meet0x. Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build L \bot meet meet0x meetx0.
End BMeetTheory.
End BMeetTheory.
Module Import TMeetTheory.
Section TMeetTheory.
Context {disp : disp_t} {L : tMeetSemilatticeType disp}.
Implicit Types (I : finType) (T : eqType) (x y : L).
Lemma meetx1 : right_id \top (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Lemma meet1x : left_id \top (@meet _ L).
Proof. by move=> x; apply/eqP; rewrite meetC meetx1. Qed.
Lemma meet_eq1 x y : (x `&` y == \top) = (x == \top) && (y == \top).
Proof.
apply/idP/idP; last by move=> /andP[/eqP-> /eqP->]; rewrite meetx1.
by move=> /eqP xIy1; rewrite -!le1x -xIy1 leIl leIr.
Qed.
HB.instance Definition _ := Monoid.isMonoidLaw.Build L \top meet meet1x meetx1.
Lemma meets_inf_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) :
x \in r -> P x -> \meet_(i <- r | P i) F i <= F x.
Proof. by move=> xr Px; rewrite (big_rem x) ?Px //= leIl. Qed.
Lemma meets_max_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (u : L) :
x \in r -> P x -> F x <= u -> \meet_(x <- r | P x) F x <= u.
Proof. by move=> ? ?; apply/le_trans/meets_inf_seq. Qed.
Lemma meets_inf I (j : I) (P : {pred I}) (F : I -> L) :
P j -> \meet_(i | P i) F i <= F j.
Proof. exact: meets_inf_seq. Qed.
Lemma meets_max I (j : I) (u : L) (P : {pred I}) (F : I -> L) :
P j -> F j <= u -> \meet_(i | P i) F i <= u.
Proof. exact: meets_max_seq. Qed.
Lemma meets_ge J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) :
(forall x : J, P x -> u <= F x) -> u <= \meet_(x <- r | P x) F x.
Proof. by move=> leFm; elim/big_rec: _ => // i x Px xu; rewrite lexI leFm. Qed.
Lemma meetsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (l : L) :
reflect (forall x : T, x \in r -> P x -> l <= F x)
(l <= \meet_(x <- r | P x) F x).
Proof.
apply: (iffP idP) => leFm => [x xr Px|].
exact/(le_trans leFm)/meets_inf_seq.
by rewrite big_seq_cond meets_ge// => x /andP[/leFm].
Qed.
Lemma meetsP I (l : L) (P : {pred I}) (F : I -> L) :
reflect (forall i : I, P i -> l <= F i) (l <= \meet_(i | P i) F i).
Proof. by apply: (iffP (meetsP_seq _ _ _ _)) => H ? ?; apply: H. Qed.
Lemma le_meets I (A B : {set I}) (F : I -> L) :
A \subset B -> \meet_(i in B) F i <= \meet_(i in A) F i.
Proof. by move=> /subsetP AB; apply/meetsP => i iA; apply/meets_inf/AB. Qed.
Lemma meets_setU I (A B : {set I}) (F : I -> L) :
\meet_(i in (A :|: B)) F i = \meet_(i in A) F i `&` \meet_(i in B) F i.
Proof.
rewrite -!big_enum; have /= <- := @big_cat _ _ meet.
apply/eq_big_idem; first exact: meetxx.
by move=> ?; rewrite mem_cat !fintype.mem_enum inE.
Qed.
Lemma meets_seq I (r : seq I) (F : I -> L) :
\meet_(i <- r) F i = \meet_(i in r) F i.
Proof.
by rewrite -big_enum; apply/eq_big_idem => ?; rewrite /= ?meetxx ?fintype.mem_enum.
Qed.
End TMeetTheory.
End TMeetTheory.
Module Import JoinTheory.
Section JoinTheory.
Context {disp : disp_t} {L : joinSemilatticeType disp}.
Implicit Types (x y : L).
(* interaction with order *)
Lemma leUx x y z : (x `|` y <= z) = (x <= z) && (y <= z).
Proof. exact: leUx. Qed.
Lemma leUr x y : x <= y `|` x. Proof. exact: (@leIr _ L^d). Qed.
Lemma leUl x y : x <= x `|` y. Proof. exact: (@leIl _ L^d). Qed.
Lemma lexUl x y z : x <= y -> x <= y `|` z.
Proof. exact: (@leIxl _ L^d). Qed.
Lemma lexUr x y z : x <= z -> x <= y `|` z.
Proof. exact: (@leIxr _ L^d). Qed.
Lemma lexU2 x y z : (x <= y) || (x <= z) -> x <= y `|` z.
Proof. exact: (@leIx2 _ L^d). Qed.
Lemma leEjoin x y : (x <= y) = (x `|` y == y).
Proof. by rewrite [LHS](@leEmeet _ L^d) meetC. Qed.
Lemma eq_joinl x y : (x `|` y == x) = (y <= x).
Proof. exact: (@eq_meetl _ L^d). Qed.
Lemma eq_joinr x y : (x `|` y == y) = (x <= y).
Proof. exact: (@eq_meetr _ L^d). Qed.
Lemma join_idPl {x y} : reflect (y `|` x = y) (x <= y).
Proof. exact: (@meet_idPl _ L^d). Qed.
Lemma join_idPr {x y} : reflect (x `|` y = y) (x <= y).
Proof. exact: (@meet_idPr _ L^d). Qed.
Lemma join_l x y : y <= x -> x `|` y = x. Proof. exact/join_idPl. Qed.
Lemma join_r x y : x <= y -> x `|` y = y. Proof. exact/join_idPr. Qed.
Lemma leUidl x y : (x `|` y <= y) = (x <= y).
Proof. exact: (@leIidr _ L^d). Qed.
Lemma leUidr x y : (y `|` x <= y) = (x <= y).
Proof. exact: (@leIidl _ L^d). Qed.
Lemma leU2 x y z t : x <= z -> y <= t -> x `|` y <= z `|` t.
Proof. exact: (@leI2 _ L^d). Qed.
(* algebraic properties *)
Lemma joinC : commutative (@join _ L). Proof. exact: (@meetC _ L^d). Qed.
Lemma joinA : associative (@join _ L). Proof. exact: (@meetA _ L^d). Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build L join joinA joinC.
Lemma joinxx : idempotent_op (@join _ L).
Proof. exact: (@meetxx _ L^d). Qed.
Lemma joinAC : right_commutative (@join _ L).
Proof. exact: (@meetAC _ L^d). Qed.
Lemma joinCA : left_commutative (@join _ L).
Proof. exact: (@meetCA _ L^d). Qed.
Lemma joinACA : interchange (@join _ L) (@join _ L).
Proof. exact: (@meetACA _ L^d). Qed.
Lemma joinKU y x : x `|` (x `|` y) = x `|` y.
Proof. exact: (@meetKI _ L^d). Qed.
Lemma joinUK y x : (x `|` y) `|` y = x `|` y.
Proof. exact: (@meetIK _ L^d). Qed.
Lemma joinKUC y x : x `|` (y `|` x) = x `|` y.
Proof. exact: (@meetKIC _ L^d). Qed.
Lemma joinUKC y x : y `|` x `|` y = x `|` y.
Proof. exact: (@meetIKC _ L^d). Qed.
End JoinTheory.
End JoinTheory.
Arguments join_idPl {disp L x y}.
Arguments join_idPr {disp L x y}.
Module Import BJoinTheory.
Section BJoinTheory.
Context {disp : disp_t} {L : bJoinSemilatticeType disp}.
Implicit Types (I : finType) (T : eqType) (x y : L).
Lemma joinx0 : right_id \bot (@join _ L).
Proof. exact: (@meetx1 _ L^d). Qed.
Lemma join0x : left_id \bot (@join _ L).
Proof. exact: (@meet1x _ L^d). Qed.
Lemma join_eq0 x y : (x `|` y == \bot) = (x == \bot) && (y == \bot).
Proof. exact: (@meet_eq1 _ L^d). Qed.
HB.instance Definition _ := Monoid.isMonoidLaw.Build L \bot join join0x joinx0.
Lemma joins_sup_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) :
x \in r -> P x -> F x <= \join_(i <- r | P i) F i.
Proof. exact: (@meets_inf_seq _ L^d). Qed.
Lemma joins_min_seq T (r : seq T) (P : {pred T}) (F : T -> L) (x : T) (l : L) :
x \in r -> P x -> l <= F x -> l <= \join_(x <- r | P x) F x.
Proof. exact: (@meets_max_seq _ L^d). Qed.
Lemma joins_sup I (j : I) (P : {pred I}) (F : I -> L) :
P j -> F j <= \join_(i | P i) F i.
Proof. exact: (@meets_inf _ L^d). Qed.
Lemma joins_min I (j : I) (l : L) (P : {pred I}) (F : I -> L) :
P j -> l <= F j -> l <= \join_(i | P i) F i.
Proof. exact: (@meets_max _ L^d). Qed.
Lemma joins_le J (r : seq J) (P : {pred J}) (F : J -> L) (u : L) :
(forall x : J, P x -> F x <= u) -> \join_(x <- r | P x) F x <= u.
Proof. exact: (@meets_ge _ L^d). Qed.
Lemma joinsP_seq T (r : seq T) (P : {pred T}) (F : T -> L) (u : L) :
reflect (forall x : T, x \in r -> P x -> F x <= u)
(\join_(x <- r | P x) F x <= u).
Proof. exact: (@meetsP_seq _ L^d). Qed.
Lemma joinsP I (u : L) (P : {pred I}) (F : I -> L) :
reflect (forall i : I, P i -> F i <= u) (\join_(i | P i) F i <= u).
Proof. exact: (@meetsP _ L^d). Qed.
Lemma le_joins I (A B : {set I}) (F : I -> L) :
A \subset B -> \join_(i in A) F i <= \join_(i in B) F i.
Proof. exact: (@le_meets _ L^d). Qed.
Lemma joins_setU I (A B : {set I}) (F : I -> L) :
\join_(i in (A :|: B)) F i = \join_(i in A) F i `|` \join_(i in B) F i.
Proof. exact: (@meets_setU _ L^d). Qed.
Lemma joins_seq I (r : seq I) (F : I -> L) :
\join_(i <- r) F i = \join_(i in r) F i.
Proof. exact: (@meets_seq _ L^d). Qed.
End BJoinTheory.
End BJoinTheory.
Module Import TJoinTheory.
Section TJoinTheory.
Context {disp : disp_t} {L : tJoinSemilatticeType disp}.
Lemma joinx1 : right_zero \top (@join _ L). Proof. exact: (@meetx0 _ L^d). Qed.
Lemma join1x : left_zero \top (@join _ L). Proof. exact: (@meet0x _ L^d). Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build L \top join join1x joinx1.
End TJoinTheory.
End TJoinTheory.
Module Import LatticeTheory.
Section LatticeTheory.
Context {disp : disp_t} {L : latticeType disp}.
Implicit Types (x y : L).
Lemma meetUK x y : (x `&` y) `|` y = y. Proof. exact/join_idPr/leIr. Qed.
Lemma meetUKC x y : (y `&` x) `|` y = y. Proof. by rewrite meetC meetUK. Qed.
Lemma meetKUC y x : x `|` (y `&` x) = x. Proof. by rewrite joinC meetUK. Qed.
Lemma meetKU y x : x `|` (x `&` y) = x. Proof. by rewrite meetC meetKUC. Qed.
Lemma joinIK x y : (x `|` y) `&` y = y. Proof. exact/meet_idPr/leUr. Qed.
Lemma joinIKC x y : (y `|` x) `&` y = y. Proof. by rewrite joinC joinIK. Qed.
Lemma joinKIC y x : x `&` (y `|` x) = x. Proof. by rewrite meetC joinIK. Qed.
Lemma joinKI y x : x `&` (x `|` y) = x. Proof. by rewrite joinC joinKIC. Qed.
(* comparison predicates *)
Lemma lcomparableP x y : incomparel x y
(min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y) (y >=< x) (x >=< y).
Proof.
by case: (comparableP x) => [hxy|hxy|hxy|->]; do 1?have hxy' := ltW hxy;
rewrite ?(meetxx, joinxx);
rewrite ?(meet_l hxy', meet_r hxy', join_l hxy', join_r hxy');
constructor.
Qed.
Lemma lcomparable_ltgtP x y : x >=< y ->
comparel x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof. by case: (lcomparableP x) => // *; constructor. Qed.
Lemma lcomparable_leP x y : x >=< y ->
lel_xor_gt x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y) (x <= y) (y < x).
Proof. by move/lcomparable_ltgtP => [/ltW xy|xy|->]; constructor. Qed.
Lemma lcomparable_ltP x y : x >=< y ->
ltl_xor_ge x y (min y x) (min x y) (max y x) (max x y)
(y `&` x) (x `&` y) (y `|` x) (x `|` y) (y <= x) (x < y).
Proof. by move=> /lcomparable_ltgtP [xy|/ltW xy|->]; constructor. Qed.
End LatticeTheory.
End LatticeTheory.
Module Import DistrLatticeTheory.
Section DistrLatticeTheory.
Context {disp : disp_t} {L : distrLatticeType disp}.
Lemma meetUl : left_distributive (@meet _ L) (@join _ L).
Proof. exact: meetUl. Qed.
Lemma meetUr : right_distributive (@meet _ L) (@join _ L).
Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed.
Lemma joinIl : left_distributive (@join _ L) (@meet _ L).
Proof. exact: joinIl. Qed.
Lemma joinIr : right_distributive (@join _ L) (@meet _ L).
Proof. by move=> x y z; rewrite ![x `|` _]joinC joinIl. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := Monoid.isAddLaw.Build L meet join meetUl meetUr.
HB.instance Definition _ := Monoid.isAddLaw.Build L join meet joinIl joinIr.
End DistrLatticeTheory.
End DistrLatticeTheory.
Module Import BDistrLatticeTheory.
Section BDistrLatticeTheory.
Context {disp : disp_t} {L : bDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma leU2l_le y t x z : x `&` t = \bot -> x `|` y <= z `|` t -> x <= z.
Proof.
by move=> xIt0 /(leI2 (lexx x)); rewrite joinKI meetUr xIt0 joinx0 leIidl.
Qed.
Lemma leU2r_le y t x z : x `&` t = \bot -> y `|` x <= t `|` z -> x <= z.
Proof. by rewrite joinC [_ `|` z]joinC => /leU2l_le H /H. Qed.
Lemma disjoint_lexUl z x y : x `&` z = \bot -> (x <= y `|` z) = (x <= y).
Proof.
move=> xz0; apply/idP/idP=> xy; last by rewrite lexU2 ?xy.
by apply: (@leU2l_le x z); rewrite ?joinxx.
Qed.
Lemma disjoint_lexUr z x y : x `&` z = \bot -> (x <= z `|` y) = (x <= y).
Proof. by move=> xz0; rewrite joinC; rewrite disjoint_lexUl. Qed.
Lemma leU2E x y z t : x `&` t = \bot -> y `&` z = \bot ->
(x `|` y <= z `|` t) = (x <= z) && (y <= t).
Proof.
move=> dxt dyz; apply/idP/andP; last by case=> ? ?; exact: leU2.
by move=> lexyzt; rewrite (leU2l_le _ lexyzt) // (leU2r_le _ lexyzt).
Qed.
Lemma joins_disjoint (I : finType) (d : L) (P : {pred I}) (F : I -> L) :
(forall i : I, P i -> d `&` F i = \bot) -> d `&` \join_(i | P i) F i = \bot.
Proof.
move=> d_Fi_disj; have : \big[andb/true]_(i | P i) (d `&` F i == \bot).
rewrite big_all_cond; apply/allP => i _ /=.
by apply/implyP => /d_Fi_disj ->.
elim/big_rec2: _ => [|i y]; first by rewrite meetx0.
case; rewrite (andbF, andbT) // => Pi /(_ isT) dy /eqP dFi.
by rewrite meetUr dy dFi joinxx.
Qed.
End BDistrLatticeTheory.
End BDistrLatticeTheory.
Module Import TDistrLatticeTheory.
Section TDistrLatticeTheory.
Context {disp : disp_t} {L : tDistrLatticeType disp}.
Implicit Types (x y : L).
Lemma leI2l_le y t x z : y `|` z = \top -> x `&` y <= z `&` t -> x <= z.
Proof. by rewrite joinC; exact: (@leU2l_le _ L^d). Qed.
Lemma leI2r_le y t x z : y `|` z = \top -> y `&` x <= t `&` z -> x <= z.
Proof. by rewrite joinC; exact: (@leU2r_le _ L^d). Qed.
Lemma cover_leIxl z x y : z `|` y = \top -> (x `&` z <= y) = (x <= y).
Proof. by rewrite joinC; exact: (@disjoint_lexUl _ L^d). Qed.
Lemma cover_leIxr z x y : z `|` y = \top -> (z `&` x <= y) = (x <= y).
Proof. by rewrite joinC; exact: (@disjoint_lexUr _ L^d). Qed.
Lemma leI2E x y z t : x `|` t = \top -> y `|` z = \top ->
(x `&` y <= z `&` t) = (x <= z) && (y <= t).
Proof. by move=> ? ?; apply: (@leU2E _ L^d); rewrite meetC. Qed.
Lemma meets_total (I : finType) (d : L) (P : {pred I}) (F : I -> L) :
(forall i : I, P i -> d `|` F i = \top) -> d `|` \meet_(i | P i) F i = \top.
Proof. exact: (@joins_disjoint _ L^d). Qed.
End TDistrLatticeTheory.
End TDistrLatticeTheory.
Module Import TotalTheory.
Section TotalTheory.
Context {disp : disp_t} {T : orderType disp}.
Implicit Types (x y z t : T) (s : seq T).
Definition le_total : total (<=%O : rel T) := le_total.
Hint Resolve le_total : core.
Lemma ge_total : total (>=%O : rel T).
Proof. by move=> ? ?; apply: le_total. Qed.
Hint Resolve ge_total : core.
Lemma comparableT x y : x >=< y. Proof. exact: le_total. Qed.
Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT] : core.
Lemma sort_le_sorted s : sorted <=%O (sort <=%O s).
Proof. exact: sort_sorted. Qed.
Hint Resolve sort_le_sorted : core.
Lemma sort_lt_sorted s : sorted <%O (sort <=%O s) = uniq s.
Proof. by rewrite lt_sorted_uniq_le sort_uniq sort_le_sorted andbT. Qed.
Lemma perm_sort_leP s1 s2 : reflect (sort <=%O s1 = sort <=%O s2) (perm_eq s1 s2).
Proof. exact/perm_sortP/le_anti/le_trans/le_total. Qed.
Lemma filter_sort_le p s : filter p (sort <=%O s) = sort <=%O (filter p s).
Proof. exact/filter_sort/le_trans/le_total. Qed.
Lemma mask_sort_le s (m : bitseq) :
{m_s : bitseq | mask m_s (sort <=%O s) = sort <=%O (mask m s)}.
Proof. exact/mask_sort/le_trans/le_total. Qed.
Lemma sorted_mask_sort_le s (m : bitseq) :
sorted <=%O (mask m s) -> {m_s : bitseq | mask m_s (sort <=%O s) = mask m s}.
Proof. exact/sorted_mask_sort/le_trans/le_total. Qed.
Lemma subseq_sort_le : {homo sort <=%O : s1 s2 / @subseq T s1 s2}.
Proof. exact/subseq_sort/le_trans/le_total. Qed.
Lemma sorted_subseq_sort_le s1 s2 :
subseq s1 s2 -> sorted <=%O s1 -> subseq s1 (sort <=%O s2).
Proof. exact/sorted_subseq_sort/le_trans/le_total. Qed.
Lemma mem2_sort_le s x y : x <= y -> mem2 s x y -> mem2 (sort <=%O s) x y.
Proof. exact/mem2_sort/le_trans/le_total. Qed.
Lemma leNgt x y : (x <= y) = ~~ (y < x). Proof. exact: comparable_leNgt. Qed.
Lemma ltNge x y : (x < y) = ~~ (y <= x). Proof. exact: comparable_ltNge. Qed.
Definition ltgtP x y := LatticeTheory.lcomparable_ltgtP (comparableT x y).
Definition leP x y := LatticeTheory.lcomparable_leP (comparableT x y).
Definition ltP x y := LatticeTheory.lcomparable_ltP (comparableT x y).
Lemma wlog_le P :
(forall x y, P y x -> P x y) -> (forall x y, x <= y -> P x y) ->
forall x y, P x y.
Proof. by move=> sP hP x y; case: (leP x y) => [| /ltW] /hP // /sP. Qed.
Lemma wlog_lt P :
(forall x, P x x) ->
(forall x y, (P y x -> P x y)) -> (forall x y, x < y -> P x y) ->
forall x y, P x y.
Proof. by move=> rP sP hP x y; case: (ltgtP x y) => [||->] // /hP // /sP. Qed.
Lemma neq_lt x y : (x != y) = (x < y) || (y < x). Proof. by case: ltgtP. Qed.
Lemma lt_total x y : x != y -> (x < y) || (y < x). Proof. by case: ltgtP. Qed.
Lemma eq_leLR x y z t :
(x <= y -> z <= t) -> (y < x -> t < z) -> (x <= y) = (z <= t).
Proof. by rewrite !ltNge => ? /contraTT ?; apply/idP/idP. Qed.
Lemma eq_leRL x y z t :
(x <= y -> z <= t) -> (y < x -> t < z) -> (z <= t) = (x <= y).
Proof. by move=> *; apply/esym/eq_leLR. Qed.
Lemma eq_ltLR x y z t :
(x < y -> z < t) -> (y <= x -> t <= z) -> (x < y) = (z < t).
Proof. by rewrite !leNgt => ? /contraTT ?; apply/idP/idP. Qed.
Lemma eq_ltRL x y z t :
(x < y -> z < t) -> (y <= x -> t <= z) -> (z < t) = (x < y).
Proof. by move=> *; apply/esym/eq_ltLR. Qed.
(* max and min is join and meet *)
Lemma meetEtotal x y : x `&` y = min x y. Proof. by case: leP. Qed.
Lemma joinEtotal x y : x `|` y = max x y. Proof. by case: leP. Qed.
(* max and min theory *)
Lemma minEgt x y : min x y = if x > y then y else x. Proof. by case: ltP. Qed.
Lemma maxEgt x y : max x y = if x > y then x else y. Proof. by case: ltP. Qed.
Lemma minEge x y : min x y = if x >= y then y else x. Proof. by case: leP. Qed.
Lemma maxEge x y : max x y = if x >= y then x else y. Proof. by case: leP. Qed.
Lemma minC : commutative (min : T -> T -> T).
Proof. by move=> x y; apply: comparable_minC. Qed.
Lemma maxC : commutative (max : T -> T -> T).
Proof. by move=> x y; apply: comparable_maxC. Qed.
Lemma minA : associative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minA. Qed.
Lemma maxA : associative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxA. Qed.
Lemma minAC : right_commutative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minAC. Qed.
Lemma maxAC : right_commutative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxAC. Qed.
Lemma minCA : left_commutative (min : T -> T -> T).
Proof. by move=> x y z; apply: comparable_minCA. Qed.
Lemma maxCA : left_commutative (max : T -> T -> T).
Proof. by move=> x y z; apply: comparable_maxCA. Qed.
Lemma minACA : interchange (min : T -> T -> T) min.
Proof. by move=> x y z t; apply: comparable_minACA. Qed.
Lemma maxACA : interchange (max : T -> T -> T) max.
Proof. by move=> x y z t; apply: comparable_maxACA. Qed.
Lemma eq_minr x y : (min x y == y) = (y <= x).
Proof. exact: comparable_eq_minr. Qed.
Lemma eq_maxl x y : (max x y == x) = (y <= x).
Proof. exact: comparable_eq_maxl. Qed.
Lemma min_idPr x y : reflect (min x y = y) (y <= x).
Proof. exact: comparable_min_idPr. Qed.
Lemma max_idPl x y : reflect (max x y = x) (y <= x).
Proof. exact: comparable_max_idPl. Qed.
Lemma le_min z x y : (z <= min x y) = (z <= x) && (z <= y).
Proof. exact: comparable_le_min. Qed.
Lemma ge_min z x y : (min x y <= z) = (x <= z) || (y <= z).
Proof. exact: comparable_ge_min. Qed.
Lemma lt_min z x y : (z < min x y) = (z < x) && (z < y).
Proof. exact: comparable_lt_min. Qed.
Lemma gt_min z x y : (min x y < z) = (x < z) || (y < z).
Proof. exact: comparable_gt_min. Qed.
Lemma le_max z x y : (z <= max x y) = (z <= x) || (z <= y).
Proof. exact: comparable_le_max. Qed.
Lemma ge_max z x y : (max x y <= z) = (x <= z) && (y <= z).
Proof. exact: comparable_ge_max. Qed.
Lemma lt_max z x y : (z < max x y) = (z < x) || (z < y).
Proof. exact: comparable_lt_max. Qed.
Lemma gt_max z x y : (max x y < z) = (x < z) && (y < z).
Proof. exact: comparable_gt_max. Qed.
Lemma minxK x y : max (min x y) y = y. Proof. exact: comparable_minxK. Qed.
Lemma minKx x y : max x (min x y) = x. Proof. exact: comparable_minKx. Qed.
Lemma maxxK x y : min (max x y) y = y. Proof. exact: comparable_maxxK. Qed.
Lemma maxKx x y : min x (max x y) = x. Proof. exact: comparable_maxKx. Qed.
Lemma max_minl : left_distributive (max : T -> T -> T) min.
Proof. by move=> x y z; apply: comparable_max_minl. Qed.
Lemma min_maxl : left_distributive (min : T -> T -> T) max.
Proof. by move=> x y z; apply: comparable_min_maxl. Qed.
Lemma max_minr : right_distributive (max : T -> T -> T) min.
Proof. by move=> x y z; apply: comparable_max_minr. Qed.
Lemma min_maxr : right_distributive (min : T -> T -> T) max.
Proof. by move=> x y z; apply: comparable_min_maxr. Qed.
HB.instance Definition _ := SemiGroup.isComLaw.Build T max maxA maxC.
HB.instance Definition _ := SemiGroup.isComLaw.Build T min minA minC.
Lemma leIx x y z : (meet y z <= x) = (y <= x) || (z <= x).
Proof. by rewrite meetEtotal ge_min. Qed.
Lemma lexU x y z : (x <= join y z) = (x <= y) || (x <= z).
Proof. by rewrite joinEtotal le_max. Qed.
Lemma ltxI x y z : (x < meet y z) = (x < y) && (x < z).
Proof. by rewrite !ltNge leIx negb_or. Qed.
Lemma ltIx x y z : (meet y z < x) = (y < x) || (z < x).
Proof. by rewrite !ltNge lexI negb_and. Qed.
Lemma ltxU x y z : (x < join y z) = (x < y) || (x < z).
Proof. by rewrite !ltNge leUx negb_and. Qed.
Lemma ltUx x y z : (join y z < x) = (y < x) && (z < x).
Proof. by rewrite !ltNge lexU negb_or. Qed.
Definition ltexI := (@lexI _ T, ltxI).
Definition lteIx := (leIx, ltIx).
Definition ltexU := (lexU, ltxU).
Definition lteUx := (@leUx _ T, ltUx).
Lemma le_min2 x y z t : x <= z -> y <= t -> Order.min x y <= Order.min z t.
Proof. exact: comparable_le_min2. Qed.
Lemma le_max2 x y z t : x <= z -> y <= t -> Order.max x y <= Order.max z t.
Proof. exact: comparable_le_max2. Qed.
(* lteif *)
Lemma lteifNE x y C : x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by case: C => /=; case: leP. Qed.
Lemma lteif_minr z x y C :
(z < min x y ?<= if C) = (z < x ?<= if C) && (z < y ?<= if C).
Proof. by case: C; rewrite /= (le_min, lt_min). Qed.
Lemma lteif_minl z x y C :
(min x y < z ?<= if C) = (x < z ?<= if C) || (y < z ?<= if C).
Proof. by case: C; rewrite /= (ge_min, gt_min). Qed.
Lemma lteif_maxr z x y C :
(z < max x y ?<= if C) = (z < x ?<= if C) || (z < y ?<= if C).
Proof. by case: C; rewrite /= (le_max, lt_max). Qed.
Lemma lteif_maxl z x y C :
(max x y < z ?<= if C) = (x < z ?<= if C) && (y < z ?<= if C).
Proof. by case: C; rewrite /= (ge_max, gt_max). Qed.
Section ArgExtremum.
Context (I : finType) (i0 : I) (P : {pred I}) (F : I -> T) (Pi0 : P i0).
Lemma arg_minP: extremum_spec <=%O P F (arg_min i0 P F).
Proof. by apply: extremumP => //; apply: le_trans. Qed.
Lemma arg_maxP: extremum_spec >=%O P F (arg_max i0 P F).
Proof. by apply: extremumP => //; [apply: ge_refl | apply: ge_trans]. Qed.
End ArgExtremum.
Lemma count_le_gt x s : count (<= x) s = size s - count (> x) s.
Proof.
by rewrite -(count_predC (> x)) addKn; apply: eq_count => y; rewrite /= leNgt.
Qed.
Lemma count_lt_ge x s : count (< x) s = size s - count (>= x) s.
Proof.
by rewrite -(count_predC (>= x)) addKn; apply: eq_count => y; rewrite /= ltNge.
Qed.
Section bigminmax_Type.
Context (I : Type) (r : seq I) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigmin_mkcond P F : \big[min/x]_(i <- r | P i) F i =
\big[min/x]_(i <- r) (if P i then F i else x).
Proof. by rewrite big_mkcond_idem //= minxx. Qed.
Lemma bigmax_mkcond P F :
\big[max/x]_(i <- r | P i) F i = \big[max/x]_(i <- r) if P i then F i else x.
Proof. by rewrite big_mkcond_idem //= maxxx. Qed.
Lemma bigmin_mkcondl P Q F :
\big[min/x]_(i <- r | P i && Q i) F i
= \big[min/x]_(i <- r | Q i) if P i then F i else x.
Proof.
rewrite bigmin_mkcond [RHS]bigmin_mkcond.
by apply: eq_bigr => i _; case: P; case: Q.
Qed.
Lemma bigmin_mkcondr P Q F :
\big[min/x]_(i <- r | P i && Q i) F i
= \big[min/x]_(i <- r | P i) if Q i then F i else x.
Proof. by under eq_bigl do rewrite andbC; apply: bigmin_mkcondl. Qed.
Lemma bigmax_mkcondl P Q F :
\big[max/x]_(i <- r | P i && Q i) F i
= \big[max/x]_(i <- r | Q i) if P i then F i else x.
Proof.
rewrite bigmax_mkcond [RHS]bigmax_mkcond.
by apply: eq_bigr => i _; case: P; case: Q.
Qed.
Lemma bigmax_mkcondr P Q F :
\big[max/x]_(i <- r | P i && Q i) F i
= \big[max/x]_(i <- r | P i) if Q i then F i else x.
Proof. by under eq_bigl do rewrite andbC; apply: bigmax_mkcondl. Qed.
Lemma bigmin_split P F1 F2 :
\big[min/x]_(i <- r | P i) (min (F1 i) (F2 i)) =
min (\big[min/x]_(i <- r | P i) F1 i) (\big[min/x]_(i <- r | P i) F2 i).
Proof. by rewrite big_split_idem //= minxx. Qed.
Lemma bigmax_split P F1 F2 :
\big[max/x]_(i <- r | P i) (max (F1 i) (F2 i)) =
max (\big[max/x]_(i <- r | P i) F1 i) (\big[max/x]_(i <- r | P i) F2 i).
Proof. by rewrite big_split_idem //= maxxx. Qed.
Lemma bigmin_idl P F :
\big[min/x]_(i <- r | P i) F i = min x (\big[min/x]_(i <- r | P i) F i).
Proof. by rewrite minC big_id_idem //= minxx. Qed.
Lemma bigmax_idl P F :
\big[max/x]_(i <- r | P i) F i = max x (\big[max/x]_(i <- r | P i) F i).
Proof. by rewrite maxC big_id_idem //= maxxx. Qed.
Lemma bigmin_idr P F :
\big[min/x]_(i <- r | P i) F i = min (\big[min/x]_(i <- r | P i) F i) x.
Proof. by rewrite [LHS]bigmin_idl minC. Qed.
Lemma bigmax_idr P F :
\big[max/x]_(i <- r | P i) F i = max (\big[max/x]_(i <- r | P i) F i) x.
Proof. by rewrite [LHS]bigmax_idl maxC. Qed.
Lemma bigminID a P F : \big[min/x]_(i <- r | P i) F i =
min (\big[min/x]_(i <- r | P i && a i) F i)
(\big[min/x]_(i <- r | P i && ~~ a i) F i).
Proof. by rewrite (bigID_idem _ _ a) //= minxx. Qed.
Lemma bigmaxID a P F : \big[max/x]_(i <- r | P i) F i =
max (\big[max/x]_(i <- r | P i && a i) F i)
(\big[max/x]_(i <- r | P i && ~~ a i) F i).
Proof. by rewrite (bigID_idem _ _ a) //= maxxx. Qed.
End bigminmax_Type.
Let ge_min_id (x y : T) : x >= min x y. Proof. by rewrite ge_min lexx. Qed.
Let le_max_id (x y : T) : x <= max x y. Proof. by rewrite le_max lexx. Qed.
Lemma sub_bigmin [x0] I r (P P' : {pred I}) (F : I -> T) :
(forall i, P' i -> P i) ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i.
Proof. exact: (sub_le_big ge_refl). Qed.
Lemma sub_bigmax [x0] I r (P P' : {pred I}) (F : I -> T) :
(forall i, P i -> P' i) ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i.
Proof. exact: sub_le_big. Qed.
(* FIXME: Remove that. *)
Local Notation "'{subset' x '<=' y '}'" :=
(sub_mem (mem x) (mem y)) (at level 0, x, y at level 1).
Lemma sub_bigmin_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r' <= r} ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r' | P i) F i.
Proof. exact: (idem_sub_le_big ge_refl _ minxx). Qed.
Lemma sub_bigmax_seq [x0] (I : eqType) r r' P (F : I -> T) : {subset r <= r'} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P i) F i.
Proof. exact: (idem_sub_le_big _ _ maxxx). Qed.
Lemma sub_bigmin_cond [x0] (I : eqType) r r' P P' (F : I -> T) :
{subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} ->
\big[min/x0]_(i <- r' | P' i) F i <= \big[min/x0]_(i <- r | P i) F i.
Proof. exact: (idem_sub_le_big_cond ge_refl _ minxx). Qed.
Lemma sub_bigmax_cond [x0] (I : eqType) r r' P P' (F : I -> T) :
{subset ([seq i <- r | P i]) <= ([seq i <- r' | P' i])} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r' | P' i) F i.
Proof. exact: (idem_sub_le_big_cond _ _ maxxx). Qed.
Lemma sub_in_bigmin [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F :
{in r, forall i, P' i -> P i} ->
\big[min/x0]_(i <- r | P i) F i <= \big[min/x0]_(i <- r | P' i) F i.
Proof. exact: (sub_in_le_big ge_refl). Qed.
Lemma sub_in_bigmax [x0] [I : eqType] (r : seq I) (P P' : {pred I}) F :
{in r, forall i, P i -> P' i} ->
\big[max/x0]_(i <- r | P i) F i <= \big[max/x0]_(i <- r | P' i) F i.
Proof. exact: sub_in_le_big. Qed.
Lemma le_bigmin_nat [x0] n m n' m' P (F : nat -> T) :
(n <= n')%N -> (m' <= m)%N ->
\big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P i) F i.
Proof. exact: (le_big_nat ge_refl). Qed.
Lemma le_bigmax_nat [x0] n m n' m' P (F : nat -> T) :
(n' <= n)%N -> (m <= m')%N ->
\big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P i) F i.
Proof. exact: le_big_nat. Qed.
Lemma le_bigmin_nat_cond [x0] n m n' m' (P P' : pred nat) (F : nat -> T) :
(n <= n')%N -> (m' <= m)%N -> (forall i, (n' <= i < m')%N -> P' i -> P i) ->
\big[min/x0]_(n <= i < m | P i) F i <= \big[min/x0]_(n' <= i < m' | P' i) F i.
Proof. exact: (le_big_nat_cond ge_refl). Qed.
Lemma le_bigmax_nat_cond [x0] n m n' m' (P P' : {pred nat}) (F : nat -> T) :
(n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) ->
\big[max/x0]_(n <= i < m | P i) F i <= \big[max/x0]_(n' <= i < m' | P' i) F i.
Proof. exact: le_big_nat_cond. Qed.
Lemma le_bigmin_ord [x0] n m (P : pred nat) (F : nat -> T) : (m <= n)%N ->
\big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P i) F i.
Proof. exact: (le_big_ord ge_refl). Qed.
Lemma le_bigmax_ord [x0] n m (P : {pred nat}) (F : nat -> T) : (n <= m)%N ->
\big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P i) F i.
Proof. exact: le_big_ord. Qed.
Lemma le_bigmin_ord_cond [x0] n m (P P' : pred nat) (F : nat -> T) :
(m <= n)%N -> (forall i : 'I_m, P' i -> P i) ->
\big[min/x0]_(i < n | P i) F i <= \big[min/x0]_(i < m | P' i) F i.
Proof. exact: (le_big_ord_cond ge_refl). Qed.
Lemma le_bigmax_ord_cond [x0] n m (P P' : {pred nat}) (F : nat -> T) :
(n <= m)%N -> (forall i : 'I_n, P i -> P' i) ->
\big[max/x0]_(i < n | P i) F i <= \big[max/x0]_(i < m | P' i) F i.
Proof. exact: le_big_ord_cond. Qed.
Lemma subset_bigmin [x0] [I : finType] [A A' P : {pred I}] (F : I -> T) :
A' \subset A ->
\big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P i) F i.
Proof. exact: (subset_le_big ge_refl). Qed.
Lemma subset_bigmax [x0] [I : finType] (A A' P : {pred I}) (F : I -> T) :
A \subset A' ->
\big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P i) F i.
Proof. exact: subset_le_big. Qed.
Lemma subset_bigmin_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) :
[set i in A' | P' i] \subset [set i in A | P i] ->
\big[min/x0]_(i in A | P i) F i <= \big[min/x0]_(i in A' | P' i) F i.
Proof. exact: (subset_le_big_cond ge_refl). Qed.
Lemma subset_bigmax_cond [x0] (I : finType) (A A' P P' : {pred I}) (F : I -> T) :
[set i in A | P i] \subset [set i in A' | P' i] ->
\big[max/x0]_(i in A | P i) F i <= \big[max/x0]_(i in A' | P' i) F i.
Proof. exact: subset_le_big_cond. Qed.
Section bigminmax_eqType.
Context (I : eqType) (r : seq I) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigmin_le_id P F : \big[min/x]_(i <- r | P i) F i <= x.
Proof. by rewrite bigmin_idl. Qed.
Lemma bigmax_ge_id P F : \big[max/x]_(i <- r | P i) F i >= x.
Proof. by rewrite bigmax_idl. Qed.
Lemma bigmin_eq_id P F :
(forall i, P i -> x <= F i) -> \big[min/x]_(i <- r | P i) F i = x.
Proof. by move=> x_le; apply: le_anti; rewrite bigmin_le_id le_bigmin. Qed.
Lemma bigmax_eq_id P F :
(forall i, P i -> x >= F i) -> \big[max/x]_(i <- r | P i) F i = x.
Proof. by move=> x_ge; apply: le_anti; rewrite bigmax_ge_id bigmax_le. Qed.
End bigminmax_eqType.
Section bigminmax_finType.
Context (I : finType) (x : T).
Implicit Types (P : pred I) (F : I -> T).
Lemma bigminD1 j P F : P j ->
\big[min/x]_(i | P i) F i = min (F j) (\big[min/x]_(i | P i && (i != j)) F i).
Proof. by move/(bigD1 _) ->. Qed.
Lemma bigmaxD1 j P F : P j ->
\big[max/x]_(i | P i) F i = max (F j) (\big[max/x]_(i | P i && (i != j)) F i).
Proof. by move/(bigD1 _) ->. Qed.
Lemma bigmin_le_cond j P F : P j -> \big[min/x]_(i | P i) F i <= F j.
Proof.
have := mem_index_enum j; rewrite unlock; elim: (index_enum I) => //= i l ih.
rewrite inE => /orP [/eqP-> ->|/ih leminlfi Pi]; first by rewrite ge_min lexx.
by case: ifPn => Pj; [rewrite ge_min leminlfi// orbC|exact: leminlfi].
Qed.
Lemma le_bigmax_cond j P F : P j -> F j <= \big[max/x]_(i | P i) F i.
Proof. by move=> Pj; rewrite (bigmaxD1 _ Pj) le_max lexx. Qed.
Lemma bigmin_le j F : \big[min/x]_i F i <= F j.
Proof. exact: bigmin_le_cond. Qed.
Lemma le_bigmax F j : F j <= \big[max/x]_i F i.
Proof. exact: le_bigmax_cond. Qed.
Lemma bigmin_inf j P m F : P j -> F j <= m -> \big[min/x]_(i | P i) F i <= m.
Proof. by move=> Pj ?; apply: le_trans (bigmin_le_cond _ Pj) _. Qed.
(* NB: as of [2022-08-02], bigop.bigmax_sup already exists for nat *)
Lemma bigmax_sup j P m F : P j -> m <= F j -> m <= \big[max/x]_(i | P i) F i.
Proof. by move=> Pj ?; apply: le_trans (le_bigmax_cond _ Pj). Qed.
Lemma bigmin_geP m P F :
reflect (m <= x /\ forall i, P i -> m <= F i)
(m <= \big[min/x]_(i | P i) F i).
Proof.
apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: le_bigmin].
- by rewrite (le_trans lemFi)// bigmin_idl ge_min lexx.
- by move=> i Pi; rewrite (le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx.
Qed.
Lemma bigmax_leP m P F :
reflect (x <= m /\ forall i, P i -> F i <= m)
(\big[max/x]_(i | P i) F i <= m).
Proof.
apply: (iffP idP) => [|[? ?]]; last exact: bigmax_le.
rewrite bigmax_idl ge_max => /andP[-> leFm]; split=> // i Pi.
by apply: le_trans leFm; exact: le_bigmax_cond.
Qed.
Lemma bigmin_gtP m P F :
reflect (m < x /\ forall i, P i -> m < F i) (m < \big[min/x]_(i | P i) F i).
Proof.
apply: (iffP idP) => [lemFi|[lemx lemPi]]; [split|exact: lt_bigmin].
- by rewrite (lt_le_trans lemFi)// bigmin_idl ge_min lexx.
- by move=> i Pi; rewrite (lt_le_trans lemFi)// (bigminD1 _ Pi)// le_minl lexx.
Qed.
Lemma bigmax_ltP m P F :
reflect (x < m /\ forall i, P i -> F i < m) (\big[max/x]_(i | P i) F i < m).
Proof.
apply: (iffP idP) => [|[? ?]]; last exact: bigmax_lt.
rewrite bigmax_idl gt_max => /andP[-> ltFm]; split=> // i Pi.
by apply: le_lt_trans ltFm; exact: le_bigmax_cond.
Qed.
Lemma bigmin_eq_arg j P F : P j -> (forall i, P i -> F i <= x) ->
\big[min/x]_(i | P i) F i = F [arg min_(i < j | P i) F i].
Proof.
move=> Pi0; case: arg_minP => //= i Pi PF PFx.
apply/eqP; rewrite eq_le bigmin_le_cond //=.
by apply/bigmin_geP; split => //; exact: PFx.
Qed.
Lemma bigmax_eq_arg j P F : P j -> (forall i, P i -> x <= F i) ->
\big[max/x]_(i | P i) F i = F [arg max_(i > j | P i) F i].
Proof.
move=> Pi0; case: arg_maxP => //= i Pi PF PxF.
apply/eqP; rewrite eq_le le_bigmax_cond // andbT.
by apply/bigmax_leP; split => //; exact: PxF.
Qed.
Lemma eq_bigmin j P F : P j -> (forall i, P i -> F i <= x) ->
{i0 | i0 \in P & \big[min/x]_(i | P i) F i = F i0}.
Proof.
by move=> Pi0 Hx; rewrite (bigmin_eq_arg Pi0) //; eexists=> //; case: arg_minP.
Qed.
Lemma eq_bigmax j P F : P j -> (forall i, P i -> x <= F i) ->
{i0 | i0 \in P & \big[max/x]_(i | P i) F i = F i0}.
Proof.
by move=> Pi0 Hx; rewrite (bigmax_eq_arg Pi0) //; eexists=> //; case: arg_maxP.
Qed.
Lemma le_bigmin2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) ->
\big[min/x]_(i | P i) F1 i <= \big[min/x]_(i | P i) F2 i.
Proof.
move=> FG; elim/big_ind2 : _ => // a b e f ba fe.
rewrite ge_min 2!le_min ba fe /= andbT.
move: (le_total a e) => /orP[/(le_trans ba)-> // | /(le_trans fe)->].
by rewrite orbT.
Qed.
Lemma le_bigmax2 P F1 F2 : (forall i, P i -> F1 i <= F2 i) ->
\big[max/x]_(i | P i) F1 i <= \big[max/x]_(i | P i) F2 i.
Proof.
move=> FG; elim/big_ind2 : _ => // a b e f ba fe.
rewrite le_max 2!ge_max ba fe /= andbT; have [//|/= af] := leP f a.
by rewrite (le_trans ba) // (le_trans _ fe) // ltW.
Qed.
Lemma bigmaxUl (A B : {set I}) F :
\big[max/x]_(i in A) F i <= \big[max/x]_(i in A :|: B) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setU => ->. Qed.
Lemma bigmaxUr (A B : {set I}) F :
\big[max/x]_(i in B) F i <= \big[max/x]_(i in A :|: B) F i.
Proof. by under [leRHS]eq_bigl do rewrite setUC; apply: bigmaxUl. Qed.
Lemma bigminUl (A B : {set I}) F :
\big[min/x]_(i in A) F i >= \big[min/x]_(i in A :|: B) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setU => ->. Qed.
Lemma bigminUr (A B : {set I}) F :
\big[min/x]_(i in B) F i >= \big[min/x]_(i in A :|: B) F i.
Proof. by under [leLHS]eq_bigl do rewrite setUC; apply: bigminUl. Qed.
Lemma bigmaxIl (A B : {set I}) F :
\big[max/x]_(i in A) F i >= \big[max/x]_(i in A :&: B) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setI => /andP[-> _]. Qed.
Lemma bigmaxIr (A B : {set I}) F :
\big[max/x]_(i in B) F i >= \big[max/x]_(i in A :&: B) F i.
Proof. by under eq_bigl do rewrite setIC; apply: bigmaxIl. Qed.
Lemma bigminIl (A B : {set I}) F :
\big[min/x]_(i in A) F i <= \big[min/x]_(i in A :&: B) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setI => /andP[->_]. Qed.
Lemma bigminIr (A B : {set I}) F :
\big[min/x]_(i in B) F i <= \big[min/x]_(i in A :&: B) F i.
Proof. by under [leRHS]eq_bigl do rewrite setIC; apply: bigminIl. Qed.
Lemma bigmaxD (A B : {set I}) F :
\big[max/x]_(i in B) F i >= \big[max/x]_(i in B :\: A) F i.
Proof. by apply: sub_bigmax => t; rewrite in_setD => /andP[_->]. Qed.
Lemma bigminD (A B : {set I}) F :
\big[min/x]_(i in B) F i <= \big[min/x]_(i in B :\: A) F i.
Proof. by apply: sub_bigmin => t; rewrite in_setD => /andP[_->]. Qed.
Lemma bigmaxU (A B : {set I}) F :
\big[max/x]_(i in A :|: B) F i
= max (\big[max/x]_(i in A) F i) (\big[max/x]_(i in B) F i).
Proof.
apply: le_anti; rewrite ge_max bigmaxUl bigmaxUr !andbT; apply/bigmax_leP.
split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite le_max bigmax_ge_id.
- by rewrite le_max le_bigmax_cond.
- by rewrite le_max orbC le_bigmax_cond.
Qed.
Lemma bigminU (A B : {set I}) F :
\big[min/x]_(i in A :|: B) F i
= min (\big[min/x]_(i in A) F i) (\big[min/x]_(i in B) F i).
Proof.
apply: le_anti; rewrite le_min bigminUl bigminUr !andbT; apply/bigmin_geP.
split=> [|i /[!in_setU]/orP[iA|iB]]; first by rewrite ge_min bigmin_le_id.
- by rewrite ge_min bigmin_le_cond.
- by rewrite ge_min orbC bigmin_le_cond.
Qed.
Lemma bigmin_set1 j F : \big[min/x]_(i in [set j]) F i = min (F j) x.
Proof. exact: big_set1E. Qed.
Lemma bigmax_set1 j F : \big[max/x]_(i in [set j]) F i = max (F j) x.
Proof. exact: big_set1E. Qed.
End bigminmax_finType.
Lemma bigmin_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) :
\big[min/x]_(j in [set h x | x in A]) F j = \big[min/x]_(i in A) F (h i).
Proof. by apply: big_imset_idem; apply: minxx. Qed.
Lemma bigmax_imset [I J : finType] x [h : I -> J] [A : {set I}] (F : J -> T) :
\big[max/x]_(j in [set h x | x in A]) F j = \big[max/x]_(i in A) F (h i).
Proof. by apply: big_imset_idem; apply: maxxx. Qed.
End TotalTheory.
#[global] Hint Resolve le_total : core.
#[global] Hint Resolve ge_total : core.
#[global] Hint Extern 0 (is_true (_ >=< _)%O) => solve [apply: comparableT]
: core.
#[global] Hint Resolve sort_le_sorted : core.
Arguments min_idPr {disp T x y}.
Arguments max_idPl {disp T x y}.
Arguments bigmin_mkcond {disp T I r}.
Arguments bigmax_mkcond {disp T I r}.
Arguments bigminID {disp T I r}.
Arguments bigmaxID {disp T I r}.
Arguments bigminD1 {disp T I x} j.
Arguments bigmaxD1 {disp T I x} j.
Arguments bigmin_inf {disp T I x} j.
Arguments bigmax_sup {disp T I x} j.
Arguments bigmin_eq_arg {disp T I} x j.
Arguments bigmax_eq_arg {disp T I} x j.
Arguments eq_bigmin {disp T I x} j.
Arguments eq_bigmax {disp T I x} j.
(* FIXME: some lemmas in the following section should hold for any porderType *)
Module Import DualTotalTheory.
Section DualTotalTheory.
Context {disp : disp_t} {T : orderType disp}.
Implicit Type s : seq T.
Lemma sorted_filter_gt x s :
sorted <=%O s -> [seq y <- s | x < y] = drop (count (<= x) s) s.
Proof.
move=> s_sorted; rewrite count_le_gt -[LHS]revK -filter_rev.
rewrite (@sorted_filter_lt _ T^d); first by rewrite take_rev revK count_rev.
by rewrite rev_sorted.
Qed.
Lemma sorted_filter_ge x s :
sorted <=%O s -> [seq y <- s | x <= y] = drop (count (< x) s) s.
Proof.
move=> s_sorted; rewrite count_lt_ge -[LHS]revK -filter_rev.
rewrite (@sorted_filter_le _ T^d); first by rewrite take_rev revK count_rev.
by rewrite rev_sorted.
Qed.
Lemma nth_count_ge x x0 s i : sorted <=%O s ->
(count (< x) s <= i < size s)%N -> x <= nth x0 s i.
Proof.
move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_ge //.
apply/(all_nthP _ (filter_all _ _)).
by rewrite size_filter ltn_subLR // count_lt_ge subnK // count_size.
Qed.
Lemma nth_count_gt x x0 s i : sorted <=%O s ->
(count (<= x) s <= i < size s)%N -> x < nth x0 s i.
Proof.
move=> ss /andP[ige ilt]; rewrite -(subnKC ige) -nth_drop -sorted_filter_gt //.
apply/(all_nthP _ (filter_all _ _)).
by rewrite size_filter ltn_subLR // count_le_gt subnK // count_size.
Qed.
Lemma nth_count_eq x x0 s i : sorted <=%O s ->
(count (< x) s <= i < count (<= x) s)%N -> nth x0 s i = x.
Proof.
move=> ss /andP[ige ilt]; apply/le_anti.
by rewrite nth_count_le// nth_count_ge// ige (leq_trans ilt (count_size _ _)).
Qed.
End DualTotalTheory.
End DualTotalTheory.
(* contra lemmas *)
Section ContraTheory.
Context {disp1 disp2 : disp_t} {T1 : porderType disp1} {T2 : orderType disp2}.
Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop).
Lemma contraTle b z t : (t < z -> ~~ b) -> (b -> z <= t).
Proof. exact: comparable_contraTle. Qed.
Lemma contraTlt b z t : (t <= z -> ~~ b) -> (b -> z < t).
Proof. exact: comparable_contraTlt. Qed.
Lemma contraPle P z t : (t < z -> ~ P) -> (P -> z <= t).
Proof. exact: comparable_contraPle. Qed.
Lemma contraPlt P z t : (t <= z -> ~ P) -> (P -> z < t).
Proof. exact: comparable_contraPlt. Qed.
Lemma contraNle b z t : (t < z -> b) -> (~~ b -> z <= t).
Proof. exact: comparable_contraNle. Qed.
Lemma contraNlt b z t : (t <= z -> b) -> (~~ b -> z < t).
Proof. exact: comparable_contraNlt. Qed.
Lemma contra_not_le P z t : (t < z -> P) -> (~ P -> z <= t).
Proof. exact: comparable_contra_not_le. Qed.
Lemma contra_not_lt P z t : (t <= z -> P) -> (~ P -> z < t).
Proof. exact: comparable_contra_not_lt. Qed.
Lemma contraFle b z t : (t < z -> b) -> (b = false -> z <= t).
Proof. exact: comparable_contraFle. Qed.
Lemma contraFlt b z t : (t <= z -> b) -> (b = false -> z < t).
Proof. exact: comparable_contraFlt. Qed.
Lemma contra_leq_le m n z t : (t < z -> (n < m)%N) -> ((m <= n)%N -> z <= t).
Proof. exact: comparable_contra_leq_le. Qed.
Lemma contra_leq_lt m n z t : (t <= z -> (n < m)%N) -> ((m <= n)%N -> z < t).
Proof. exact: comparable_contra_leq_lt. Qed.
Lemma contra_ltn_le m n z t : (t < z -> (n <= m)%N) -> ((m < n)%N -> z <= t).
Proof. exact: comparable_contra_ltn_le. Qed.
Lemma contra_ltn_lt m n z t : (t <= z -> (n <= m)%N) -> ((m < n)%N -> z < t).
Proof. exact: comparable_contra_ltn_lt. Qed.
Lemma contra_le x y z t : (t < z -> y < x) -> (x <= y -> z <= t).
Proof. exact: comparable_contra_le. Qed.
Lemma contra_le_lt x y z t : (t <= z -> y < x) -> (x <= y -> z < t).
Proof. exact: comparable_contra_le_lt. Qed.
Lemma contra_lt_le x y z t : (t < z -> y <= x) -> (x < y -> z <= t).
Proof. exact: comparable_contra_lt_le. Qed.
Lemma contra_lt x y z t : (t <= z -> y <= x) -> (x < y -> z < t).
Proof. exact: comparable_contra_lt. Qed.
End ContraTheory.
Section TotalMonotonyTheory.
Context {disp disp' : disp_t} {T : orderType disp} {T' : porderType disp'}.
Context (D : {pred T}) (f : T -> T').
Implicit Types (x y z : T) (u v w : T').
Let leT_anti := @le_anti _ T.
Let leT'_anti := @le_anti _ T'.
Let ltT_neqAle := @lt_neqAle _ T.
Let ltT'_neqAle := @lt_neqAle _ T'.
Let ltT_def := @lt_def _ T.
Let leT_total := @le_total _ T.
Lemma le_mono : {homo f : x y / x < y} -> {mono f : x y / x <= y}.
Proof. exact: total_homo_mono. Qed.
Lemma le_nmono : {homo f : x y /~ x < y} -> {mono f : x y /~ x <= y}.
Proof. by apply: total_homo_mono => // x y; rewrite eq_sym. Qed.
Lemma le_mono_in :
{in D &, {homo f : x y / x < y}} -> {in D &, {mono f : x y / x <= y}}.
Proof. exact: total_homo_mono_in. Qed.
Lemma le_nmono_in :
{in D &, {homo f : x y /~ x < y}} -> {in D &, {mono f : x y /~ x <= y}}.
Proof. by apply: total_homo_mono_in => // x y; rewrite eq_sym. Qed.
End TotalMonotonyTheory.
End TotalTheory.
Module Import CDistrLatticeTheory.
Section CDistrLatticeTheory.
Context {disp : disp_t} {L : cDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. exact: rcomplPmeet. Qed.
Lemma rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. exact: rcomplPjoin. Qed.
Lemma rcomplKI x y z : x <= y -> (x `|` z) `&` rcompl x y z = x.
Proof. by move=> lexy; have := rcomplPmeet x y z; rewrite (meet_l lexy). Qed.
Lemma rcomplKU x y z : x <= y -> (y `&` z) `|` rcompl x y z = y.
Proof. by move=> lexy; have := rcomplPjoin x y z; rewrite (join_l lexy). Qed.
End CDistrLatticeTheory.
End CDistrLatticeTheory.
Module Import CBDistrLatticeTheory.
Section CBDistrLatticeTheory.
Context {disp : disp_t} {L : cbDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma diffErcompl x y : x `\` y = rcompl \bot x y.
Proof. exact: diffErcompl. Qed.
Lemma diffKI x y : y `&` (x `\` y) = \bot.
Proof. by have := rcomplKI y (le0x x); rewrite join0x diffErcompl. Qed.
Lemma diffIK x y : (x `\` y) `&` y = \bot.
Proof. by rewrite meetC diffKI. Qed.
Lemma meetIB z x y : (z `&` y) `&` (x `\` y) = \bot.
Proof. by rewrite -meetA diffKI meetx0. Qed.
Lemma meetBI z x y : (x `\` y) `&` (z `&` y) = \bot.
Proof. by rewrite meetC meetIB. Qed.
Lemma joinIB y x : (x `&` y) `|` (x `\` y) = x.
Proof. by rewrite diffErcompl rcomplKU. Qed.
Lemma joinBI y x : (x `\` y) `|` (x `&` y) = x.
Proof. by rewrite joinC joinIB. Qed.
Lemma joinIBC y x : (y `&` x) `|` (x `\` y) = x.
Proof. by rewrite meetC joinIB. Qed.
Lemma joinBIC y x : (x `\` y) `|` (y `&` x) = x.
Proof. by rewrite meetC joinBI. Qed.
Lemma leBx x y : x `\` y <= x.
Proof. by rewrite -[leRHS](joinIB y) leUr. Qed.
Hint Resolve leBx : core.
Lemma diffxx x : x `\` x = \bot.
Proof. by have := diffKI x x; rewrite meet_r. Qed.
Lemma leBl z x y : x <= y -> x `\` z <= y `\` z.
Proof.
rewrite -[leLHS](joinIB z) -[leRHS](joinIB z).
by rewrite leU2E ?meetIB ?meetBI // => /andP [].
Qed.
Lemma diffKU y x : y `|` (x `\` y) = y `|` x.
Proof.
apply/eqP; rewrite eq_le leU2 //= leUx leUl.
by apply/meet_idPl; have := joinIB y x; rewrite joinIl join_l.
Qed.
Lemma diffUK y x : (x `\` y) `|` y = x `|` y.
Proof. by rewrite joinC diffKU joinC. Qed.
Lemma leBKU y x : y <= x -> y `|` (x `\` y) = x.
Proof. by move=> /join_r {2}<-; rewrite diffKU. Qed.
Lemma leBUK y x : y <= x -> (x `\` y) `|` y = x.
Proof. by move=> leyx; rewrite joinC leBKU. Qed.
Lemma leBLR x y z : (x `\` y <= z) = (x <= y `|` z).
Proof.
apply/idP/idP; first by move=> /join_r <-; rewrite joinA diffKU joinAC leUr.
by rewrite -{1}[x](joinIB y) => /(leU2r_le (diffIK _ _)).
Qed.
Lemma diffUx x y z : (x `|` y) `\` z = (x `\` z) `|` (y `\` z).
Proof.
apply/eqP; rewrite eq_le leUx !leBl ?leUr ?leUl ?andbT //.
by rewrite leBLR joinA diffKU joinAC diffKU joinAC -joinA leUr.
Qed.
Lemma diff_eq0 x y : (x `\` y == \bot) = (x <= y).
Proof. by rewrite -lex0 leBLR joinx0. Qed.
Lemma joinxB x y z : x `|` (y `\` z) = ((x `|` y) `\` z) `|` (x `&` z).
Proof. by rewrite diffUx joinAC joinBI. Qed.
Lemma joinBx x y z : (y `\` z) `|` x = ((y `|` x) `\` z) `|` (z `&` x).
Proof. by rewrite ![_ `|` x]joinC ![_ `&` x]meetC joinxB. Qed.
Lemma leBr z x y : x <= y -> z `\` y <= z `\` x.
Proof. by move=> lexy; rewrite leBLR joinxB meet_r ?leBUK ?leUr ?lexUl. Qed.
Lemma leB2 x y z t : x <= z -> t <= y -> x `\` y <= z `\` t.
Proof. by move=> /(@leBl t) ? /(@leBr x) /le_trans ->. Qed.
Lemma meet_eq0E_diff z x y : x <= z -> (x `&` y == \bot) = (x <= z `\` y).
Proof.
move=> xz; apply/idP/idP; last by move=> /meet_r <-; rewrite -meetA meetBI.
by move=> /eqP xIy_eq0; rewrite -[x](joinIB y) xIy_eq0 join0x leBl.
Qed.
Lemma leBRL x y z : (x <= z `\` y) = (x <= z) && (x `&` y == \bot).
Proof.
apply/idP/idP => [xyz|]; first by rewrite (@meet_eq0E_diff z) // (le_trans xyz).
by move=> /andP [?]; rewrite -meet_eq0E_diff.
Qed.
Lemma eq_diff x y z : (x `\` y == z) = (z <= x <= y `|` z) && (z `&` y == \bot).
Proof. by rewrite eq_le leBLR leBRL andbCA andbA. Qed.
Lemma diffxU x y z : z `\` (x `|` y) = (z `\` x) `&` (z `\` y).
Proof.
apply/eqP; rewrite eq_le lexI !leBr ?leUl ?leUr //=.
rewrite leBRL leIx2 ?leBx //= meetUr meetAC diffIK -meetA diffIK.
by rewrite meet0x meetx0 joinx0.
Qed.
Lemma diffx0 x : x `\` \bot = x.
Proof. by apply/eqP; rewrite eq_diff join0x meetx0 lexx eqxx. Qed.
Lemma diff0x x : \bot `\` x = \bot.
Proof. by apply/eqP; rewrite eq_diff joinx0 meet0x lexx eqxx le0x. Qed.
Lemma diffIx x y z : (x `&` y) `\` z = (x `\` z) `&` (y `\` z).
Proof.
apply/eqP; rewrite eq_diff joinIr ?leI2 ?diffKU ?leUr ?leBx //=.
by rewrite -meetA diffIK meetx0.
Qed.
Lemma meetxB x y z : x `&` (y `\` z) = (x `&` y) `\` z.
Proof. by rewrite diffIx -{1}[x](joinBI z) meetUl meetIB joinx0. Qed.
Lemma meetBx x y z : (x `\` y) `&` z = (x `&` z) `\` y.
Proof. by rewrite ![_ `&` z]meetC meetxB. Qed.
Lemma diffxI x y z : x `\` (y `&` z) = (x `\` y) `|` (x `\` z).
Proof.
apply/eqP; rewrite eq_diff leUx !leBx //= joinIl joinA joinCA !diffKU.
rewrite joinCA -joinA [_ `|` x]joinC ![x `|` _]join_l //.
by rewrite -joinIl leUr /= meetUl {1}[_ `&` z]meetC ?meetBI joinx0.
Qed.
Lemma diffBx x y z : (x `\` y) `\` z = x `\` (y `|` z).
Proof.
apply/eqP; rewrite eq_diff leBr ?leUl //=.
by rewrite diffxU joinIr diffKU -joinIr meet_l ?leUr //= -meetA diffIK meetx0.
Qed.
Lemma diffxB x y z : x `\` (y `\` z) = (x `\` y) `|` (x `&` z).
Proof.
rewrite -[y in RHS](joinIB z) diffxU joinIl diffxI -joinA joinBI join_r //.
by rewrite joinBx meetKU meetA meetAC diffIK meet0x joinx0 meet_r.
Qed.
Lemma joinBK x y : (y `|` x) `\` x = (y `\` x).
Proof. by rewrite diffUx diffxx joinx0. Qed.
Lemma joinBKC x y : (x `|` y) `\` x = (y `\` x).
Proof. by rewrite diffUx diffxx join0x. Qed.
Lemma disj_le x y : x `&` y == \bot -> x <= y = (x == \bot).
Proof. by rewrite [x == \bot]eq_sym -eq_meetl => /eqP ->. Qed.
Lemma disj_leC x y : y `&` x == \bot -> x <= y = (x == \bot).
Proof. by rewrite meetC => /disj_le. Qed.
Lemma disj_diffl x y : x `&` y == \bot -> x `\` y = x.
Proof. by move=> dxy; apply/eqP; rewrite eq_diff dxy lexx leUr. Qed.
Lemma disj_diffr x y : x `&` y == \bot -> y `\` x = y.
Proof. by rewrite meetC => /disj_diffl. Qed.
Lemma lt0B x y : x < y -> \bot < y `\` x.
Proof. by move=> ?; rewrite lt_leAnge le0x leBLR joinx0 /= lt_geF. Qed.
End CBDistrLatticeTheory.
End CBDistrLatticeTheory.
Module Import CTDistrLatticeTheory.
Section CTDistrLatticeTheory.
Context {disp : disp_t} {L : ctDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. exact: codiffErcompl. Qed.
(* TODO: complete this theory module *)
End CTDistrLatticeTheory.
End CTDistrLatticeTheory.
Module Import CTBDistrLatticeTheory.
Section CTBDistrLatticeTheory.
Context {disp : disp_t} {L : ctbDistrLatticeType disp}.
Implicit Types (x y z : L).
Lemma complEdiff x : ~` x = \top `\` x. Proof. exact: complEdiff. Qed.
#[deprecated(since="mathcomp 2.3.0", note="Use complEdiff instead.")]
Notation complE := complEdiff.
Lemma complEcodiff x : ~` x = codiff \bot x. Proof. exact: complEcodiff. Qed.
Lemma complErcompl x : ~` x = rcompl \bot \top x.
Proof. by rewrite complEdiff diffErcompl. Qed.
Lemma diff1x x : \top `\` x = ~` x.
Proof. exact/esym/complEdiff. Qed.
Lemma diffE x y : x `\` y = x `&` ~` y.
Proof. by rewrite complEdiff meetxB meetx1. Qed.
Lemma complK : involutive (@compl _ L).
Proof. by move=> x; rewrite !complEdiff diffxB diffxx meet1x join0x. Qed.
Lemma compl_inj : injective (@compl _ L).
Proof. exact/inv_inj/complK. Qed.
Lemma disj_leC x y : (x `&` y == \bot) = (x <= ~` y).
Proof. by rewrite -diff_eq0 diffE complK. Qed.
Lemma leCx x y : (~` x <= y) = (~` y <= x).
Proof. by rewrite !complEdiff !leBLR joinC. Qed.
Lemma lexC x y : (x <= ~` y) = (y <= ~` x).
Proof. by rewrite -[x in LHS]complK leCx complK. Qed.
Lemma leC x y : (~` x <= ~` y) = (y <= x).
Proof. by rewrite leCx complK. Qed.
Lemma complU x y : ~` (x `|` y) = ~` x `&` ~` y.
Proof. by rewrite !complEdiff diffxU. Qed.
Lemma complI x y : ~` (x `&` y) = ~` x `|` ~` y.
Proof. by rewrite !complEdiff diffxI. Qed.
Lemma joinxC x : x `|` ~` x = \top.
Proof. by rewrite complEdiff diffKU joinx1. Qed.
Lemma joinCx x : ~` x `|` x = \top.
Proof. by rewrite joinC joinxC. Qed.
Lemma meetxC x : x `&` ~` x = \bot.
Proof. by rewrite complEdiff diffKI. Qed.
Lemma meetCx x : ~` x `&` x = \bot.
Proof. by rewrite meetC meetxC. Qed.
Lemma compl1 : ~` \top = \bot :> L.
Proof. by rewrite complEdiff diffxx. Qed.
Lemma compl0 : ~` \bot = \top :> L.
Proof. by rewrite -compl1 complK. Qed.
Lemma complB x y : ~` (x `\` y) = ~` x `|` y.
Proof. by rewrite diffE complI complK. Qed.
Lemma leBC x y : x `\` y <= ~` y.
Proof. by rewrite leBLR joinxC lex1. Qed.
Lemma compl_joins (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) :
~` (\join_(j <- r | P j) F j) = \meet_(j <- r | P j) ~` F j.
Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl0 ?complU. Qed.
Lemma compl_meets (J : Type) (r : seq J) (P : {pred J}) (F : J -> L) :
~` (\meet_(j <- r | P j) F j) = \join_(j <- r | P j) ~` F j.
Proof. by elim/big_rec2: _=> [|i x y ? <-]; rewrite ?compl1 ?complI. Qed.
End CTBDistrLatticeTheory.
End CTBDistrLatticeTheory.
(*************)
(* FACTORIES *)
(*************)
(* porderType *)
HB.factory Record Preorder_isPOrder (d : disp_t) T of Preorder d T := {
le_anti : antisymmetric (@le d T);
}.
HB.builders Context (d : disp_t) T of Preorder_isPOrder d T.
Let ge_anti : antisymmetric (fun x y => @le d T y x).
Proof. by move=> x y; rewrite andbC; apply: le_anti. Qed.
HB.instance Definition _ := Preorder_isDuallyPOrder.Build d T le_anti ge_anti.
HB.end.
HB.factory Record isPOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
lt_def : forall x y, lt x y = (y != x) && (le x y);
le_refl : reflexive le;
le_anti : antisymmetric le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of isPOrder d T.
Let lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite lt_def andbC; case /boolP: (le x y) => //= xy.
have [->|/negP xyE /=] := eqVneq y x; first by rewrite le_refl.
by apply/esym/negP => yx; apply/xyE/eqP/le_anti; rewrite yx.
Qed.
HB.instance Definition _ := isPreorder.Build d T lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record Le_isPOrder (d : disp_t) T of Choice T := {
le : rel T;
le_refl : reflexive le;
le_anti : antisymmetric le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of Le_isPOrder d T.
(* TODO: print nice error message when keyed type is not provided *)
HB.instance Definition _ := @Le_isPreorder.Build d T le le_refl le_trans.
HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record LtLe_isPOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
le_def : forall x y, le x y = (x == y) || lt x y;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
}.
HB.builders Context (d : disp_t) T of LtLe_isPOrder d T.
HB.instance Definition _ := @LtLe_isPreorder.Build d T le lt le_def lt_irr lt_trans.
Let le_anti : antisymmetric le.
Proof.
move=> x y; rewrite !le_def [y == _]eq_sym.
have [//|neq_xy/=] := eqVneq x y => /andP[xy yx].
by have := lt_trans xy yx; rewrite lt_irr.
Qed.
HB.instance Definition _ := @Preorder_isPOrder.Build d T le_anti.
HB.end.
HB.factory Record Lt_isPOrder (d : disp_t) T of Choice T := {
lt : rel T;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
}.
HB.builders Context d T of Lt_isPOrder d T.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @LtLe_isPOrder.Build d T
_ lt (fun _ _ => erefl) lt_irr lt_trans.
HB.end.
(* meetSemilatticeType and joinSemilatticeType *)
HB.factory Record POrder_Meet_isSemilattice d T of POrder d T := {
meet : T -> T -> T;
meetC : commutative meet;
meetA : associative meet;
leEmeet : forall x y, (x <= y) = (meet x y == x);
}.
HB.builders Context d T of POrder_Meet_isSemilattice d T.
Fact meetxx : idempotent_op meet.
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof.
rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite meetA -meetA meetxx.
by rewrite -!meetA (meetC z) (meetA y) meetxx.
by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx.
Qed.
HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet lexI.
HB.end.
HB.factory Record POrder_Join_isSemilattice d T of POrder d T := {
join : T -> T -> T;
joinC : commutative join;
joinA : associative join;
leEjoin : forall x y, (y <= x) = (join x y == x);
}.
HB.builders Context d T of POrder_Join_isSemilattice d T.
Fact joinxx : idempotent_op join.
Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed.
Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z).
rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite joinA -joinA joinxx.
by rewrite -joinA (joinC _ x) (joinA x) joinxx.
by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx.
Qed.
HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join leUx.
HB.end.
(* latticeType *)
HB.factory Record POrder_MeetJoin_isLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetP : forall x y z, (x <= meet y z) = (x <= y) && (x <= z);
joinP : forall x y z, (join x y <= z) = (x <= z) && (y <= z);
}.
HB.builders Context d T of POrder_MeetJoin_isLattice d T.
HB.instance Definition _ := @POrder_isMeetSemilattice.Build d T meet meetP.
HB.instance Definition _ := @POrder_isJoinSemilattice.Build d T join joinP.
HB.end.
HB.factory Record POrder_isLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x, meet x (join x y) = x;
meetKU : forall y x, join x (meet x y) = x;
leEmeet : forall x y, (x <= y) = (meet x y == x);
}.
HB.builders Context d T of POrder_isLattice d T.
Fact leEjoin x y : (y <= x) = (join x y == x).
Proof.
rewrite leEmeet; apply/eqP/eqP => <-.
by rewrite meetC meetKU.
by rewrite joinC joinKI.
Qed.
Fact meetxx : idempotent_op meet.
Proof. by move=> x; apply/eqP; rewrite -leEmeet. Qed.
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof.
rewrite !leEmeet; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite meetA -meetA meetxx.
by rewrite -!meetA (meetC z) (meetA y) meetxx.
by rewrite -!meetA (meetC z) -meetA (meetA y) !meetxx.
Qed.
Fact joinxx : idempotent_op join.
Proof. by move=> x; apply/eqP; rewrite -leEjoin. Qed.
Fact leUx x y z : (join x y <= z) = (x <= z) && (y <= z).
rewrite !leEjoin; apply/eqP/andP => [<-|[/eqP<- /eqP<-]].
split; apply/eqP; last by rewrite joinA -joinA joinxx.
by rewrite -joinA (joinC _ x) (joinA x) joinxx.
by rewrite -!joinA (joinC y) -joinA (joinA x) !joinxx.
Qed.
HB.instance Definition _ := @POrder_MeetJoin_isLattice.Build d T
meet join lexI leUx.
HB.end.
(* distrLatticeType *)
HB.factory Record Lattice_Meet_isDistrLattice d T of Lattice d T := {
meetUl : @left_distributive T T meet join;
}.
HB.builders Context d T of Lattice_Meet_isDistrLattice d T.
Let meetUr : right_distributive (@meet _ T) (@join _ T).
Proof. by move=> x y z; rewrite ![x `&` _]meetC meetUl. Qed.
Let joinIl : left_distributive (@join _ T) (@meet _ T).
Proof. by move=> x y z; rewrite meetUr joinIK meetUl -joinA meetUKC. Qed.
HB.instance Definition _ := Lattice_isDistributive.Build d T meetUl joinIl.
HB.end.
HB.factory Record POrder_Meet_isDistrLattice d T of POrder d T := {
meet : T -> T -> T;
join : T -> T -> T;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x, meet x (join x y) = x;
meetKU : forall y x, join x (meet x y) = x;
leEmeet : forall x y, (x <= y) = (meet x y == x);
meetUl : left_distributive meet join;
}.
HB.builders Context d T of POrder_Meet_isDistrLattice d T.
HB.instance Definition _ := @POrder_isLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU leEmeet.
HB.instance Definition _ :=
Lattice_Meet_isDistrLattice.Build d T meetUl.
HB.end.
HB.factory Record isMeetJoinDistrLattice (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
le_def : forall x y : T, le x y = (meet x y == x);
lt_def : forall x y : T, lt x y = (y != x) && le x y;
meetC : commutative meet;
joinC : commutative join;
meetA : associative meet;
joinA : associative join;
joinKI : forall y x : T, meet x (join x y) = x;
meetKU : forall y x : T, join x (meet x y) = x;
meetUl : left_distributive meet join;
meetxx : idempotent_op meet;
}.
HB.builders Context d T of isMeetJoinDistrLattice d T.
Fact le_refl : reflexive le. Proof. by move=> x; rewrite le_def meetxx. Qed.
Fact le_anti : antisymmetric le.
Proof. by move=> x y; rewrite !le_def meetC => /andP [] /eqP {2}<- /eqP ->. Qed.
Fact le_trans : transitive le.
Proof.
move=> y x z; rewrite !le_def => /eqP lexy /eqP leyz; apply/eqP.
by rewrite -[in LHS]lexy -meetA leyz lexy.
Qed.
Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x).
Proof.
rewrite lt_def andbC; case/boolP: (le x y) => //= xy.
congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl.
by apply/le_anti/andP; split.
Qed.
HB.instance Definition _ := isPreorder.Build d T
lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl.
HB.end.
(* complemented lattices *)
HB.factory Record BDistrLattice_hasSectionalComplement d T
of BDistrLattice d T := {
diff : T -> T -> T;
diffKI : forall x y, y `&` diff x y = \bot;
joinIB : forall x y, (x `&` y) `|` diff x y = x;
}.
Module hasRelativeComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use BDistrLattice_hasSectionalComplement.Build instead.")]
Notation Build d T :=
(BDistrLattice_hasSectionalComplement.Build d T) (only parsing).
End hasRelativeComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use BDistrLattice_hasSectionalComplement instead.")]
Notation hasRelativeComplement d T :=
(BDistrLattice_hasSectionalComplement d T) (only parsing).
HB.builders Context d T of BDistrLattice_hasSectionalComplement d T.
Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z.
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite meetUr joinIKC meetUl diffKI joinx0 meetKU. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by rewrite joinCA joinIB joinA meetUK joinC. Qed.
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin.
Fact diffErcompl x y : diff x y = rcompl \bot x y.
Proof. by rewrite /rcompl meet0x join0x joinx0. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build d T diff diffErcompl.
HB.end.
HB.factory Record TDistrLattice_hasDualSectionalComplement d T
of TDistrLattice d T := {
codiff : T -> T -> T;
codiffKU : forall x y, y `|` codiff x y = \top;
meetUB : forall x y, (x `|` y) `&` codiff x y = x;
}.
HB.builders Context d T of TDistrLattice_hasDualSectionalComplement d T.
Definition rcompl x y z := (y `|` x) `&` codiff (x `&` y) z.
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite meetCA meetUB meetA joinIK. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by rewrite joinIr meetUKC joinIl codiffKU meetx1 joinKI. Qed.
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build d T rcompl rcomplPmeet rcomplPjoin.
Fact codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. by rewrite /rcompl join1x meet1x meetx1. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl.
HB.end.
HB.factory Record CBDistrLattice_hasComplement d T
of CBDistrLattice d T & hasTop d T := {
compl : T -> T;
complEdiff : forall x, compl x = (\top : T) `\` x; (* FIXME *)
}.
Module hasComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use CBDistrLattice_hasComplement.Build instead.")]
Notation Build d T := (CBDistrLattice_hasComplement.Build d T) (only parsing).
End hasComplement.
#[deprecated(since="mathcomp 2.3.0",
note="Use CBDistrLattice_hasComplement instead.")]
Notation hasComplement d T := (CBDistrLattice_hasComplement d T) (only parsing).
HB.builders Context d T of CBDistrLattice_hasComplement d T.
HB.instance Definition _ := @CDistrLattice_hasDualSectionalComplement.Build d T
(fun x y => rcompl x \top y) (fun _ _ => erefl).
Fact complEcodiff (x : T) : compl x = codiff (\bot : T) x.
Proof. by rewrite complEdiff diffErcompl. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
HB.factory Record CTDistrLattice_hasComplement d T
of CTDistrLattice d T & hasBottom d T := {
compl : T -> T;
complEcodiff : forall x, compl x = codiff (\bot : T) x;
}.
HB.builders Context d T of CTDistrLattice_hasComplement d T.
HB.instance Definition _ := @CDistrLattice_hasSectionalComplement.Build d T
(fun x y => rcompl (\bot : T) x y) (fun _ _ => erefl).
Fact complEdiff (x : T) : compl x = (\top : T) `\` x.
Proof. by rewrite complEcodiff codiffErcompl. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
HB.factory Record TBDistrLattice_hasComplement d T of TBDistrLattice d T := {
compl : T -> T;
joinxC : forall x, x `|` compl x = \top;
meetxC : forall x, x `&` compl x = \bot;
}.
HB.builders Context d T of TBDistrLattice_hasComplement d T.
Definition diff x y := x `&` compl y.
Definition codiff x y := x `|` compl y.
Definition rcompl x y z := (x `&` y) `|` diff (y `|` x) z.
Fact diffKI x y : y `&` diff x y = \bot.
Proof. by rewrite meetCA meetxC meetx0. Qed.
Fact joinIB x y : (x `&` y) `|` diff x y = x.
Proof. by rewrite -meetUr joinxC meetx1. Qed.
HB.instance Definition _ :=
@BDistrLattice_hasSectionalComplement.Build d T diff diffKI joinIB.
Fact codiffErcompl x y : codiff x y = rcompl x \top y.
Proof. by rewrite /rcompl /diff join1x meetx1 meet1x. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build d T codiff codiffErcompl.
Fact complEdiff x : compl x = diff \top x. Proof. exact/esym/meet1x. Qed.
Fact complEcodiff x : compl x = codiff \bot x. Proof. exact/esym/join0x. Qed.
HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build d T compl complEdiff complEcodiff.
HB.end.
(* orderType *)
HB.factory Record Lattice_isTotal d T of Lattice d T := {
le_total : total (<=%O : rel T)
}.
HB.builders Context d T of Lattice_isTotal d T.
Fact meetUl : @left_distributive T T meet join.
Proof.
pose leP x y := lcomparable_leP (le_total x y); move=> x y z; apply/esym.
by case: (leP x y) (leP x z) (leP y z) => [|/ltW] xy [|/ltW] xz [|/ltW] yz;
(apply/join_idPl || apply/join_idPr) => //; apply: le_trans xy.
Qed.
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build d T meetUl.
HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total.
HB.end.
HB.factory Record POrder_isTotal d T of POrder d T := {
le_total : total (<=%O : rel T) }.
HB.builders Context d T of POrder_isTotal d T.
Implicit Types (x y z : T).
Let comparableT x y : x >=< y := le_total x y.
Fact ltgtP x y :
compare x y (min y x) (min x y) (max y x) (max x y)
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof. exact: comparable_ltgtP. Qed.
Fact leP x y : le_xor_gt x y
(min y x) (min x y) (max y x) (max x y) (x <= y) (y < x).
Proof. exact: comparable_leP. Qed.
Definition meet := @min _ T.
Definition join := @max _ T.
Fact meetC : commutative meet.
Proof. by move=> x y; rewrite /meet; have [] := ltgtP. Qed.
Fact joinC : commutative join.
Proof. by move=> x y; rewrite /join; have [] := ltgtP. Qed.
Fact meetA : associative meet.
Proof.
move=> x y z; rewrite /meet /min !(fun_if, if_arg).
case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=.
by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx.
by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx).
Qed.
Fact joinA : associative join.
Proof.
move=> x y z; rewrite /meet /min !(fun_if, if_arg).
case: (leP z y) (leP y x) (leP z x) => [] zy [] yx [] zx//=.
by have := le_lt_trans (le_trans zy yx) zx; rewrite ltxx.
by apply/eqP; rewrite eq_le zx ltW// (lt_trans yx).
Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof.
rewrite /meet /join /min /max !(fun_if, if_arg).
by have []// := ltgtP x y; rewrite ltxx.
Qed.
Fact meetKU y x : join x (meet x y) = x.
Proof.
rewrite /meet /join /min /max !(fun_if, if_arg).
by have []// := ltgtP x y; rewrite ltxx.
Qed.
Fact leEmeet x y : (x <= y) = (meet x y == x).
Proof. by rewrite /meet; case: leP => ?; rewrite ?eqxx ?lt_eqF. Qed.
HB.instance Definition _ := @POrder_isLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU leEmeet.
HB.instance Definition _ :=
Lattice_isTotal.Build d T comparableT.
HB.end.
HB.factory Record isOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
lt_def : forall x y, lt x y = (y != x) && le x y;
meet_def : forall x y, meet x y = if lt x y then x else y;
join_def : forall x y, join x y = if lt x y then y else x;
le_anti : antisymmetric le;
le_trans : transitive le;
le_total : total le;
}.
HB.builders Context d T of isOrder d T.
Fact le_refl : reflexive le.
Proof. by move=> x; case: (le x x) (le_total x x). Qed.
Fact lt_le_def x y : lt x y = (le x y) && ~~ (le y x).
Proof.
rewrite lt_def andbC; case/boolP: (le x y) => //= xy.
congr negb; apply/eqP/idP => [->|yx]; first exact/le_refl.
by apply/le_anti/andP; split.
Qed.
HB.instance Definition _ := isPreorder.Build d T
lt_le_def le_refl le_trans.
HB.instance Definition _ := Preorder_isPOrder.Build d T le_anti.
Section GeneratedOrder.
Local Definition T' := T.
HB.instance Definition _ := POrder.on T'.
HB.instance Definition _ := POrder_isTotal.Build d T' le_total.
Implicit Types (x y z : T').
Fact meetE x y : meet x y = x `&` y. Proof. by rewrite meet_def. Qed.
Fact joinE x y : join x y = x `|` y. Proof. by rewrite join_def. Qed.
Fact meetC : commutative meet.
Proof. by move=> *; rewrite !meetE meetC. Qed.
Fact joinC : commutative join.
Proof. by move=> *; rewrite !joinE joinC. Qed.
Fact meetA : associative meet.
Proof. by move=> *; rewrite !meetE meetA. Qed.
Fact joinA : associative join.
Proof. by move=> *; rewrite !joinE joinA. Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof. by rewrite meetE joinE joinKI. Qed.
Fact meetKU y x : join x (meet x y) = x.
Proof. by rewrite meetE joinE meetKU. Qed.
Fact meetUl : left_distributive meet join.
Proof. by move=> *; rewrite !meetE !joinE meetUl. Qed.
Fact meetxx : idempotent_op meet.
Proof. by move=> *; rewrite meetE meetxx. Qed.
Fact le_def x y : x <= y = (meet x y == x).
Proof. by rewrite meetE (eq_meetl x y). Qed.
End GeneratedOrder.
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build d T
meet join meetC joinC meetA joinA joinKI meetKU le_def meetUl.
HB.instance Definition _ := DistrLattice_isTotal.Build d T le_total.
HB.end.
HB.factory Record LtOrder (d : disp_t) T of Choice T := {
le : rel T;
lt : rel T;
meet : T -> T -> T;
join : T -> T -> T;
le_def : forall x y, le x y = (x == y) || lt x y;
meet_def : forall x y, meet x y = if lt x y then x else y;
join_def : forall x y, join x y = if lt x y then y else x;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
lt_total : forall x y, x != y -> lt x y || lt y x;
}.
HB.builders Context d T of LtOrder d T.
Fact lt_def x y : lt x y = (y != x) && le x y.
Proof. by rewrite le_def; case: eqVneq => //= ->; rewrite lt_irr. Qed.
Fact meet_def_le x y : meet x y = if lt x y then x else y.
Proof. by rewrite meet_def lt_def; case: eqP. Qed.
Fact join_def_le x y : join x y = if lt x y then y else x.
Proof. by rewrite join_def lt_def; case: eqP. Qed.
Fact le_anti : antisymmetric le.
Proof.
move=> x y; rewrite !le_def; case: eqVneq => //= _ /andP [] hxy.
by move/(lt_trans hxy); rewrite lt_irr.
Qed.
Fact le_trans : transitive le.
Proof.
move=> y x z; rewrite !le_def; case: eqVneq => [->|_] //=.
by case: eqVneq => [-> ->|_ hxy /(lt_trans hxy) ->]; rewrite orbT.
Qed.
Fact le_total : total le.
Proof. by move=> x y; rewrite !le_def; case: eqVneq => //; exact: lt_total. Qed.
HB.instance Definition _ :=
isOrder.Build d T lt_def meet_def_le join_def_le le_anti le_trans le_total.
HB.end.
HB.factory Record MonoTotal disp T of POrder disp T := {
disp' : disp_t;
T' : orderType disp';
f : T -> T';
f_mono : {mono f : x y / x <= y}
}.
HB.builders Context disp T of MonoTotal disp T.
Fact totalT : total (<=%O : rel T).
Proof. by move=> x y; rewrite -!f_mono le_total. Qed.
HB.instance Definition _ := POrder_isTotal.Build disp T totalT.
HB.end.
Module CancelPartial.
Import PreCancelPartial.
Section CancelPartial.
Variables (disp : disp_t) (T : choiceType).
Variables (disp' : disp_t) (T' : porderType disp') (f : T -> T').
Section Pcan.
Variables (f' : T' -> option T) (f_can : pcancel f f').
Fact anti : antisymmetric (le f).
Proof. by move=> ? ? /le_anti; apply: pcan_inj. Qed.
Fact lt_def x y :
lt f x y = (y != x) && le f x y.
Proof. by rewrite /lt lt_def (inj_eq (pcan_inj f_can)). Qed.
Definition Pcan := isPOrder.Build disp (Choice.Pack (Choice.class T))
lt_def (@refl T disp' T' f) anti (@trans T disp' T' f).
End Pcan.
Definition Can f' (f_can : cancel f f') := Pcan (can_pcan f_can).
End CancelPartial.
End CancelPartial.
Notation PCanIsPartial := CancelPartial.Pcan.
Notation CanIsPartial := CancelPartial.Can.
#[export]
HB.instance Definition _ (disp : disp_t) (T : choiceType)
(disp' : disp_t) (T' : porderType disp') (f : T -> T')
(f' : T' -> option T) (f_can : pcancel f f') :=
Preorder_isPOrder.Build disp (pcan_type f_can) (CancelPartial.anti f_can).
#[export]
HB.instance Definition _ (disp : disp_t) (T : choiceType)
(disp' : disp_t) (T' : porderType disp') (f : T -> T') (f' : T' -> T)
(f_can : cancel f f') :=
Preorder_isPOrder.Build disp (can_type f_can)
(CancelPartial.anti (can_pcan f_can)).
Section CancelTotal.
Variables (disp : disp_t) (T : choiceType).
Variables (disp' : disp_t) (T' : orderType disp') (f : T -> T').
Section PCan.
Variables (f' : T' -> option T) (f_can : pcancel f f').
#[local]
HB.instance Definition _ :=
MonoTotal.Build disp (pcan_type f_can) (fun _ _ => erefl).
Definition PCanIsTotal : DistrLattice_isTotal _ (pcan_type f_can) :=
Total.on (pcan_type f_can).
End PCan.
Section Can.
Variables (f' : T' -> T) (f_can : cancel f f').
#[local]
HB.instance Definition _ :=
MonoTotal.Build disp (can_type f_can) (fun _ _ => erefl).
Definition CanIsTotal : DistrLattice_isTotal _ (can_type f_can) :=
Total.on (can_type f_can).
End Can.
End CancelTotal.
HB.factory Record IsoLattice disp T of POrder disp T := {
disp' : disp_t;
T' : latticeType disp';
f : T -> T';
f' : T' -> T;
f_can : cancel f f';
f'_can : cancel f' f;
f_mono : {mono f : x y / x <= y};
}.
HB.builders Context disp T of IsoLattice disp T.
Definition meet (x y : T) := f' (meet (f x) (f y)).
Definition join (x y : T) := f' (join (f x) (f y)).
Fact meetC : commutative meet. Proof. by move=> x y; rewrite /meet meetC. Qed.
Fact joinC : commutative join. Proof. by move=> x y; rewrite /join joinC. Qed.
Fact meetA : associative meet.
Proof. by move=> y x z; rewrite /meet !f'_can meetA. Qed.
Fact joinA : associative join.
Proof. by move=> y x z; rewrite /join !f'_can joinA. Qed.
Fact joinKI y x : meet x (join x y) = x.
Proof. by rewrite /meet /join f'_can joinKI f_can. Qed.
Fact meetKI y x : join x (meet x y) = x.
Proof. by rewrite /join /meet f'_can meetKU f_can. Qed.
Fact meet_eql x y : (x <= y) = (meet x y == x).
Proof. by rewrite /meet -(can_eq f_can) f'_can eq_meetl f_mono. Qed.
HB.instance Definition _ := POrder_isLattice.Build _ T
meetC joinC meetA joinA joinKI meetKI meet_eql.
HB.end.
HB.factory Record IsoDistrLattice disp T of POrder disp T := {
disp' : disp_t;
T' : distrLatticeType disp';
f : T -> T';
f' : T' -> T;
f_can : cancel f f';
f'_can : cancel f' f;
f_mono : {mono f : x y / x <= y};
}.
HB.builders Context disp T of IsoDistrLattice disp T.
HB.instance Definition _ := IsoLattice.Build _ T f_can f'_can f_mono.
Fact meetUl : left_distributive (meet : T -> T -> T) join.
Proof. by move=> x y z; rewrite /meet /join /= !f'_can meetUl. Qed.
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ T meetUl.
HB.end.
(* Morphism hierarchy. *)
Export OrderMorphismTheory.
Lemma omorph_lt (d : disp_t) (T : porderType d) (d' : disp_t) (T' : porderType d')
(f : {omorphism T -> T'}) : injective f -> {homo f : x y / x < y}.
Proof. by move/inj_homo_lt; apply; apply: omorph_le. Qed.
Definition meet_morphism d (T : latticeType d) d' (T' : latticeType d')
(f : T -> T') : Prop := {morph f : x y / x `&` y}.
Definition join_morphism d (T : latticeType d) d' (T' : latticeType d')
(f : T -> T') : Prop := {morph f : x y / x `|` y}.
HB.mixin Record isMeetLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (apply : T -> T') := {
omorphI_subproof : meet_morphism apply;
}.
HB.mixin Record isJoinLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (apply : T -> T') := {
omorphU_subproof : join_morphism apply;
}.
HB.structure Definition MeetLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of isMeetLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}.
HB.structure Definition JoinLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of isJoinLatticeMorphism d T d' T' f & @OrderMorphism d T d' T' f}.
HB.structure Definition LatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') :=
{f of @MeetLatticeMorphism d T d' T' f & @JoinLatticeMorphism d T d' T' f}.
HB.factory Record isLatticeMorphism d (T : latticeType d)
d' (T' : latticeType d') (f : T -> T') of @OrderMorphism d T d' T' f := {
omorphI_subproof : meet_morphism f;
omorphU_subproof : join_morphism f;
}.
HB.builders Context d T d' T' f of isLatticeMorphism d T d' T' f.
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d' T' f
omorphI_subproof.
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d' T' f
omorphU_subproof.
HB.end.
Module LatticeMorphismExports.
Notation "{ 'mlmorphism' T -> T' }" :=
(@MeetLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'jlmorphism' T -> T' }" :=
(@JoinLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'lmorphism' T -> T' }" :=
(@LatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "[ 'mlmorphism' 'of' f 'as' g ]" :=
(MeetLatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'mlmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'mlmorphism' 'of' f ]" :=
(MeetLatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'mlmorphism' 'of' f ]") : form_scope.
Notation "[ 'jlmorphism' 'of' f 'as' g ]" :=
(JoinLatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'jlmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'jlmorphism' 'of' f ]" :=
(JoinLatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'jlmorphism' 'of' f ]") : form_scope.
Notation "[ 'lmorphism' 'of' f 'as' g ]" :=
(LatticeMorphism.clone _ _ _ _ f%function g)
(format "[ 'lmorphism' 'of' f 'as' g ]") : form_scope.
Notation "[ 'lmorphism' 'of' f ]" :=
(LatticeMorphism.clone _ _ _ _ f%function _)
(format "[ 'lmorphism' 'of' f ]") : form_scope.
End LatticeMorphismExports.
HB.export LatticeMorphismExports.
Module Import LatticeMorphismTheory.
Section LatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d').
Lemma omorphI (f : {mlmorphism T -> T'}) : {morph f : x y / x `&` y}.
Proof. exact: omorphI_subproof. Qed.
Lemma omorphU (f : {jlmorphism T -> T'}) : {morph f : x y / x `|` y}.
Proof. exact: omorphU_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : latticeType d) (d' : disp_t) (T' : latticeType d').
Variables (d'' : disp_t) (T'' : latticeType d'').
Section MeetCompFun.
Variables (f : {mlmorphism T' -> T''}) (g : {mlmorphism T -> T'}).
Fact idfun_is_meet_morphism : meet_morphism (@idfun T). Proof. by []. Qed.
#[export]
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d T idfun
idfun_is_meet_morphism.
Fact comp_is_meet_morphism : meet_morphism (f \o g).
Proof. by move=> x y; rewrite /= !omorphI. Qed.
#[export]
HB.instance Definition _ := isMeetLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_meet_morphism.
End MeetCompFun.
Section JoinCompFun.
Variables (f : {jlmorphism T' -> T''}) (g : {jlmorphism T -> T'}).
Fact idfun_is_join_morphism : join_morphism (@idfun T). Proof. by []. Qed.
#[export]
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d T idfun
idfun_is_join_morphism.
Fact comp_is_join_morphism : join_morphism (f \o g).
Proof. by move=> x y; rewrite /= !omorphU. Qed.
#[export]
HB.instance Definition _ := isJoinLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_join_morphism.
End JoinCompFun.
End IdCompFun.
End LatticeMorphismTheory.
End LatticeMorphismTheory.
HB.mixin Record isBLatticeMorphism d (T : bLatticeType d)
d' (T' : bLatticeType d') (apply : T -> T') := {
omorph0_subproof : apply \bot = \bot;
}.
HB.mixin Record isTLatticeMorphism d (T : tLatticeType d)
d' (T' : tLatticeType d') (apply : T -> T') := {
omorph1_subproof : apply \top = \top;
}.
HB.structure Definition BLatticeMorphism d (T : bLatticeType d)
d' (T' : bLatticeType d') := {f of isBLatticeMorphism d T d' T' f}.
HB.structure Definition TLatticeMorphism d (T : tLatticeType d)
d' (T' : tLatticeType d') := {f of isTLatticeMorphism d T d' T' f}.
HB.structure Definition TBLatticeMorphism d (T : tbLatticeType d)
d' (T' : tbLatticeType d') :=
{f of @BLatticeMorphism d T d' T' f & @TLatticeMorphism d T d' T' f}.
Module TBLatticeMorphismExports.
Notation "{ 'blmorphism' T -> T' }" :=
(@BLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'tlmorphism' T -> T' }" :=
(@TLatticeMorphism.type _ T%type _ T'%type) : type_scope.
Notation "{ 'tblmorphism' T -> T' }" :=
(@TBLatticeMorphism.type _ T%type _ T'%type) : type_scope.
End TBLatticeMorphismExports.
HB.export TBLatticeMorphismExports.
Module Import BLatticeMorphismTheory.
Section BLatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : bLatticeType d).
Variables (d' : disp_t) (T' : bLatticeType d').
Variables (f : {blmorphism T -> T'}).
Lemma omorph0 : f \bot = \bot.
Proof. exact: omorph0_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : bLatticeType d).
Variables (d' : disp_t) (T' : bLatticeType d').
Variables (d'' : disp_t) (T'' : bLatticeType d'').
Variables (f : {blmorphism T' -> T''}) (g : {blmorphism T -> T'}).
Fact idfun_is_bottom_morphism : (@idfun T) \bot = \bot. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isBLatticeMorphism.Build d T d T idfun
idfun_is_bottom_morphism.
Fact comp_is_bottom_morphism : (f \o g) \bot = \bot.
Proof. by rewrite /= !omorph0. Qed.
#[export]
HB.instance Definition _ := isBLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_bottom_morphism.
End IdCompFun.
End BLatticeMorphismTheory.
End BLatticeMorphismTheory.
Module Import TLatticeMorphismTheory.
Section TLatticeMorphismTheory.
Section Properties.
Variables (d : disp_t) (T : tLatticeType d).
Variables (d' : disp_t) (T' : tLatticeType d').
Variables (f : {tlmorphism T -> T'}).
Lemma omorph1 : f \top = \top.
Proof. exact: omorph1_subproof. Qed.
End Properties.
Section IdCompFun.
Variables (d : disp_t) (T : tLatticeType d).
Variables (d' : disp_t) (T' : tLatticeType d').
Variables (d'' : disp_t) (T'' : tLatticeType d'').
Variables (f : {tlmorphism T' -> T''}) (g : {tlmorphism T -> T'}).
Fact idfun_is_top_morphism : (@idfun T) \top = \top. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isTLatticeMorphism.Build d T d T idfun
idfun_is_top_morphism.
Fact comp_is_top_morphism : (f \o g) \top = \top.
Proof. by rewrite /= !omorph1. Qed.
#[export]
HB.instance Definition _ := isTLatticeMorphism.Build d T d'' T'' (f \o g)
comp_is_top_morphism.
End IdCompFun.
End TLatticeMorphismTheory.
End TLatticeMorphismTheory.
Module Import ClosedPredicates.
Section ClosedPredicates.
Variable (d : disp_t) (T : latticeType d).
Variable S : {pred T}.
Definition meet_closed := {in S &, forall u v, u `&` v \in S}.
Definition join_closed := {in S &, forall u v, u `|` v \in S}.
End ClosedPredicates.
End ClosedPredicates.
(* Mixins for stability properties *)
HB.mixin Record isMeetLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredI : meet_closed S;
}.
HB.mixin Record isJoinLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredU : join_closed S;
}.
HB.mixin Record isBLatticeClosed d (T : bLatticeType d) (S : {pred T}) := {
opred0 : \bot \in S;
}.
HB.mixin Record isTLatticeClosed d (T : tLatticeType d) (S : {pred T}) := {
opred1 : \top \in S;
}.
(* Structures for stability properties *)
#[short(type="meetLatticeClosed")]
HB.structure Definition MeetLatticeClosed d T :=
{S of isMeetLatticeClosed d T S}.
#[short(type="joinLatticeClosed")]
HB.structure Definition JoinLatticeClosed d T :=
{S of isJoinLatticeClosed d T S}.
#[short(type="latticeClosed")]
HB.structure Definition LatticeClosed d T :=
{S of @MeetLatticeClosed d T S & @JoinLatticeClosed d T S}.
#[short(type="bLatticeClosed")]
HB.structure Definition BLatticeClosed d T := {S of isBLatticeClosed d T S}.
#[short(type="bJoinLatticeClosed")]
HB.structure Definition BJoinLatticeClosed d T :=
{S of isBLatticeClosed d T S & @JoinLatticeClosed d T S}.
#[short(type="tLatticeClosed")]
HB.structure Definition TLatticeClosed d T := {S of isTLatticeClosed d T S}.
#[short(type="tMeetLatticeClosed")]
HB.structure Definition TMeetLatticeClosed d T :=
{S of isTLatticeClosed d T S & @MeetLatticeClosed d T S}.
#[short(type="tbLatticeClosed")]
HB.structure Definition TBLatticeClosed d (T : tbLatticeType d) :=
{S of @BLatticeClosed d T S & @TLatticeClosed d T S}.
HB.factory Record isLatticeClosed d (T : latticeType d) (S : {pred T}) := {
opredI : meet_closed S;
opredU : join_closed S;
}.
HB.builders Context d T S of isLatticeClosed d T S.
HB.instance Definition _ := isMeetLatticeClosed.Build d T S opredI.
HB.instance Definition _ := isJoinLatticeClosed.Build d T S opredU.
HB.end.
HB.factory Record isTBLatticeClosed d (T : tbLatticeType d) (S : {pred T}) := {
opredI : meet_closed S;
opredU : join_closed S;
opred0 : \bot \in S;
opred1 : \top \in S;
}.
HB.builders Context d T S of isTBLatticeClosed d T S.
HB.instance Definition _ := isLatticeClosed.Build d T S opredI opredU.
HB.instance Definition _ := isBLatticeClosed.Build d T S opred0.
HB.instance Definition _ := isTLatticeClosed.Build d T S opred1.
HB.end.
Module Import LatticePred.
Section LatticePred.
Variables (d : disp_t) (T : latticeType d).
Lemma opredI (S : meetLatticeClosed T) : {in S &, forall u v, u `&` v \in S}.
Proof. exact: opredI. Qed.
Lemma opredU (S : joinLatticeClosed T) : {in S &, forall u v, u `|` v \in S}.
Proof. exact: opredU. Qed.
End LatticePred.
Section BLatticePred.
Variables (d : disp_t) (T : bLatticeType d).
Lemma opred0 (S : bLatticeClosed T) : \bot \in S.
Proof. exact: opred0. Qed.
Lemma opred_joins (S : bJoinLatticeClosed T) I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \join_(i <- r | P i) F i \in S.
Proof. by move=> FS; elim/big_ind: _; [exact: opred0 | exact: opredU |]. Qed.
End BLatticePred.
Section TLatticePred.
Variables (d : disp_t) (T : tLatticeType d).
Lemma opred1 (S : tLatticeClosed T) : \top \in S.
Proof. exact: opred1. Qed.
Lemma opred_meets (S : tMeetLatticeClosed T) I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \meet_(i <- r | P i) F i \in S.
Proof. by move=> FS; elim/big_ind: _; [exact: opred1 | exact: opredI |]. Qed.
End TLatticePred.
End LatticePred.
#[short(type="subPOrder")]
HB.structure Definition SubPOrder d (T : porderType d) S d' :=
{ U of SubEquality T S U & POrder d' U & isSubPreorder d T S d' U }.
HB.factory Record SubChoice_isSubPOrder d (T : porderType d) S (d' : disp_t) U
of SubChoice T S U := {}.
HB.builders Context d T S d' U of SubChoice_isSubPOrder d T S d' U.
HB.instance Definition _ := SubChoice_isSubPreorder.Build d T S d' U.
HB.instance Definition _ := Preorder_isPOrder.Build d' U
(@CancelPartial.anti U d T _ _ (@valK _ _ U)).
HB.end.
#[export]
HB.instance Definition _ d (T : porderType d) (S : pred T) (d' : disp_t)
(U : subType S) := SubChoice_isSubPOrder.Build d T S d' (sub_type U).
HB.mixin Record isMeetSubLattice d (T : latticeType d) (S : pred T) d' U
of SubType T S U & Lattice d' U := {
valI_subproof : {morph (val : U -> T) : x y / x `&` y};
}.
HB.mixin Record isJoinSubLattice d (T : latticeType d) (S : pred T) d' U
of SubType T S U & Lattice d' U := {
valU_subproof : {morph (val : U -> T) : x y / x `|` y};
}.
#[short(type="subPOrderLattice")]
HB.structure Definition SubPOrderLattice d (T : latticeType d) S d' :=
{ U of @SubPOrder d T S d' U & Lattice d' U }.
#[short(type="subPOrderBLattice")]
HB.structure Definition SubPOrderBLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & BLattice d' U }.
#[short(type="subPOrderTLattice")]
HB.structure Definition SubPOrderTLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & TLattice d' U }.
#[short(type="subPOrderTBLattice")]
HB.structure Definition SubPOrderTBLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & TBLattice d' U }.
#[short(type="meetSubLattice")]
HB.structure Definition MeetSubLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & isMeetSubLattice d T S d' U }.
#[short(type="meetSubBLattice")]
HB.structure Definition MeetSubBLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & BLattice d' U }.
#[short(type="meetSubTLattice")]
HB.structure Definition MeetSubTLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TLattice d' U }.
#[short(type="meetSubTBLattice")]
HB.structure Definition MeetSubTBLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TBLattice d' U }.
#[short(type="joinSubLattice")]
HB.structure Definition JoinSubLattice d (T : latticeType d) S d' :=
{ U of @SubPOrderLattice d T S d' U & isJoinSubLattice d T S d' U }.
#[short(type="joinSubBLattice")]
HB.structure Definition JoinSubBLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & BLattice d' U }.
#[short(type="joinSubTLattice")]
HB.structure Definition JoinSubTLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & TLattice d' U }.
#[short(type="joinSubTBLattice")]
HB.structure Definition JoinSubTBLattice d (T : latticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & TBLattice d' U }.
#[short(type="subLattice")]
HB.structure Definition SubLattice d (T : latticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & @JoinSubLattice d T S d' U }.
#[short(type="subBLattice")]
HB.structure Definition SubBLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & BLattice d' U }.
#[short(type="subTLattice")]
HB.structure Definition SubTLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & TLattice d' U }.
#[short(type="subTBLattice")]
HB.structure Definition SubTBLattice d (T : latticeType d) S d' :=
{ U of @SubLattice d T S d' U & TBLattice d' U }.
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T)
d' (U : MeetSubLattice.type S d') :=
isMeetLatticeMorphism.Build d' U d T val valI_subproof.
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (d : disp_t) (T : latticeType d) (S : pred T)
d' (U : JoinSubLattice.type S d') :=
isJoinLatticeMorphism.Build d' U d T val valU_subproof.
HB.factory Record SubPOrder_isSubLattice d (T : latticeType d) S d' U
of @SubPOrder d T S d' U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
}.
HB.builders Context d T S d' U of SubPOrder_isSubLattice d T S d' U.
HB.instance Definition _ := isLatticeClosed.Build d T S
opredI_subproof opredU_subproof.
Let inU v Sv : U := Sub v Sv.
Let meetU (u1 u2 : U) : U := inU (opredI (valP u1) (valP u2)).
Let joinU (u1 u2 : U) : U := inU (opredU (valP u1) (valP u2)).
Let meetUC : commutative meetU.
Proof. by move=> x y; apply: val_inj; rewrite !SubK meetC. Qed.
Let joinUC : commutative joinU.
Proof. by move=> x y; apply: val_inj; rewrite !SubK joinC. Qed.
Let meetUA : associative meetU.
Proof. by move=> x y z; apply: val_inj; rewrite !SubK meetA. Qed.
Let joinUA : associative joinU.
Proof. by move=> x y z; apply: val_inj; rewrite !SubK joinA. Qed.
Lemma joinUKI y x : meetU x (joinU x y) = x.
Proof. by apply: val_inj; rewrite !SubK joinKI. Qed.
Let meetUKU y x : joinU x (meetU x y) = x.
Proof. by apply: val_inj; rewrite !SubK meetKU. Qed.
Let le_meetU x y : (x <= y) = (meetU x y == x).
Proof. by rewrite -le_val -(inj_eq val_inj) SubK leEmeet. Qed.
HB.instance Definition _ := POrder_isLattice.Build d' U
meetUC joinUC meetUA joinUA joinUKI meetUKU le_meetU.
Fact valI : meet_morphism (val : U -> T).
Proof. by move=> x y; rewrite !SubK. Qed.
Fact valU : join_morphism (val : U -> T).
Proof. by move=> x y; rewrite !SubK. Qed.
HB.instance Definition _ := isMeetSubLattice.Build d T S d' U valI.
HB.instance Definition _ := isJoinSubLattice.Build d T S d' U valU.
HB.end.
HB.factory Record SubChoice_isSubLattice d (T : latticeType d) S (d' : disp_t) U
of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
}.
HB.builders Context d T S d' U of SubChoice_isSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U.
HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.end.
HB.mixin Record isBSubLattice d (T : bLatticeType d) (S : pred T) d' U
of SubType T S U & BLattice d' U := {
val0_subproof : (val : U -> T) \bot = \bot;
}.
#[short(type="bJoinSubLattice")]
HB.structure Definition BJoinSubLattice d (T : bLatticeType d) S d' :=
{ U of @JoinSubLattice d T S d' U & BLattice d' U & isBSubLattice d T S d' U }.
#[short(type="bJoinSubTLattice")]
HB.structure Definition BJoinSubTLattice d (T : bLatticeType d) S d' :=
{ U of @BJoinSubLattice d T S d' U & TBLattice d' U }.
#[short(type="bSubLattice")]
HB.structure Definition BSubLattice d (T : bLatticeType d) S d' :=
{ U of @SubLattice d T S d' U & @BJoinSubLattice d T S d' U }.
#[short(type="bSubTLattice")]
HB.structure Definition BSubTLattice d (T : bLatticeType d) S d' :=
{ U of @BSubLattice d T S d' U & TBLattice d' U }.
#[export]
HB.instance Definition _ (d : disp_t) (T : bLatticeType d) (S : pred T)
d' (U : BJoinSubLattice.type S d') :=
isBLatticeMorphism.Build d' U d T val val0_subproof.
HB.factory Record SubPOrder_isBSubLattice d (T : bLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred0_subproof : \bot \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isBSubLattice d T S d' U.
Let inU v Sv : U := Sub v Sv.
Let zeroU : U := inU opred0_subproof.
Fact le0x x : zeroU <= x. Proof. by rewrite -le_val /= SubK le0x. Qed.
HB.instance Definition _ := hasBottom.Build d' U le0x.
Fact val0 : (val : U -> T) \bot = \bot. Proof. by rewrite SubK. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := isBSubLattice.Build d T S d' U val0.
HB.end.
HB.factory Record SubChoice_isBSubLattice
d (T : bLatticeType d) S (d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred0_subproof : \bot \in S;
}.
HB.builders Context d T S d' U of SubChoice_isBSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U
opred0_subproof.
HB.end.
HB.mixin Record isTSubLattice d (T : tLatticeType d) (S : pred T) d' U
of SubType T S U & TLattice d' U := {
val1_subproof : (val : U -> T) \top = \top;
}.
#[short(type="tMeetSubLattice")]
HB.structure Definition TMeetSubLattice d (T : tLatticeType d) S d' :=
{ U of @MeetSubLattice d T S d' U & TLattice d' U & isTSubLattice d T S d' U }.
#[short(type="tMeetSubBLattice")]
HB.structure Definition TMeetSubBLattice d (T : tLatticeType d) S d' :=
{ U of @TMeetSubLattice d T S d' U & TBLattice d' U }.
#[short(type="tSubLattice")]
HB.structure Definition TSubLattice d (T : tLatticeType d) S d' :=
{ U of @SubLattice d T S d' U & @TMeetSubLattice d T S d' U }.
#[short(type="tSubBLattice")]
HB.structure Definition TSubBLattice d (T : tLatticeType d) S d' :=
{ U of @TSubLattice d T S d' U & TBLattice d' U }.
#[export]
HB.instance Definition _ (d : disp_t) (T : tLatticeType d) (S : pred T)
d' (U : TMeetSubLattice.type S d') :=
isTLatticeMorphism.Build d' U d T val val1_subproof.
HB.factory Record SubPOrder_isTSubLattice d (T : tLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isTSubLattice d T S d' U.
Let inU v Sv : U := Sub v Sv.
Let oneU : U := inU opred1_subproof.
Fact lex1 x : x <= oneU. Proof. by rewrite -le_val /= SubK lex1. Qed.
HB.instance Definition _ := hasTop.Build d' U lex1.
Fact val1 : (val : U -> T) \top = \top. Proof. by rewrite SubK. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := isTSubLattice.Build d T S d' U val1.
HB.end.
HB.factory Record SubChoice_isTSubLattice
d (T : tLatticeType d) S (d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubChoice_isTSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U
opred1_subproof.
HB.end.
#[short(type="tbSubLattice")]
HB.structure Definition TBSubLattice d (T : tbLatticeType d) S d' :=
{ U of @BSubLattice d T S d' U & @TSubLattice d T S d' U}.
#[export]
HB.instance Definition _ (d : disp_t) (T : tbLatticeType d) (S : pred T) d'
(U : TBSubLattice.type S d') := BLatticeMorphism.on (val : U -> T).
HB.factory Record SubPOrder_isTBSubLattice d (T : tbLatticeType d) S d' U
of @SubPOrder d T S d' U & Lattice d' U := {
opred0_subproof : \bot \in S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubPOrder_isTBSubLattice d T S d' U.
HB.instance Definition _ := SubPOrder_isBSubLattice.Build d T S d' U
opred0_subproof.
HB.instance Definition _ := SubPOrder_isTSubLattice.Build d T S d' U
opred1_subproof.
HB.end.
HB.factory Record SubChoice_isTBSubLattice d (T : tbLatticeType d) S
(d' : disp_t) U of SubChoice T S U := {
opredI_subproof : meet_closed S;
opredU_subproof : join_closed S;
opred0_subproof : \bot \in S;
opred1_subproof : \top \in S;
}.
HB.builders Context d T S d' U of SubChoice_isTBSubLattice d T S d' U.
HB.instance Definition _ := SubChoice_isSubLattice.Build d T S d' U
opredI_subproof opredU_subproof.
HB.instance Definition _ := SubPOrder_isTBSubLattice.Build d T S d' U
opred0_subproof opred1_subproof.
HB.end.
#[short(type="subOrder")]
HB.structure Definition SubOrder d (T : orderType d) S d' :=
{ U of @SubLattice d T S d' U & Total d' U }.
HB.factory Record SubLattice_isSubOrder d (T : orderType d) S d' U
of @SubLattice d T S d' U := {}.
HB.builders Context d T S d' U of SubLattice_isSubOrder d T S d' U.
Lemma totalU : total (<=%O : rel U).
Proof. by move=> x y; rewrite -!le_val le_total. Qed.
HB.instance Definition _ := Lattice_isTotal.Build d' U totalU.
HB.end.
HB.factory Record SubPOrder_isSubOrder d (T : orderType d) S d' U
of @SubPOrder d T S d' U := {}.
HB.builders Context d T S d' U of SubPOrder_isSubOrder d T S d' U.
Fact opredI : meet_closed S.
Proof. by move=> x y Sx Sy; rewrite meetEtotal; case: leP. Qed.
Fact opredU : join_closed S.
Proof. by move=> x y Sx Sy; rewrite joinEtotal; case: leP. Qed.
HB.instance Definition _ := SubPOrder_isSubLattice.Build d T S d' U opredI opredU.
HB.instance Definition _ := SubLattice_isSubOrder.Build d T S d' U.
HB.end.
HB.factory Record SubChoice_isSubOrder d (T : orderType d) S (d' : disp_t) U
of @SubChoice T S U := {}.
HB.builders Context d T S d' U of SubChoice_isSubOrder d T S d' U.
HB.instance Definition _ := SubChoice_isSubPOrder.Build d T S d' U.
HB.instance Definition _ := SubPOrder_isSubOrder.Build d T S d' U.
HB.end.
Module SubOrderExports.
Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]" :=
(SubChoice_isSubPOrder.Build _ _ _ _ U)
(format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubPOrder.Build _ _ _ disp U)
(format "[ 'SubChoice_isSubPOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubPOrder_isSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isSubLattice.Build _ _ _ _ U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubLattice.Build _ _ _ disp U (@opredI _ _ _) (@opredU _ _ _))
(format "[ 'SubChoice_isSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isBSubLattice.Build _ _ _ _ U (opred0 _))
(format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isBSubLattice.Build _ _ _ disp U (opred0 _))
(format "[ 'SubPOrder_isBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isBSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _))
(format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isBSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _))
(format "[ 'SubChoice_isBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isTSubLattice.Build _ _ _ _ U (opred1 _))
(format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isTSubLattice.Build _ _ _ disp U (opred1 _))
(format "[ 'SubPOrder_isTSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isTSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred1 _))
(format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isTSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred1 _))
(format "[ 'SubChoice_isTSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]" :=
(SubPOrder_isTBSubLattice.Build _ _ _ _ U (opred0 _) (opred1 _))
(format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isTBSubLattice.Build _ _ _ disp U (opred0 _) (opred1 _))
(format "[ 'SubPOrder_isTBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]" :=
(SubChoice_isTBSubLattice.Build _ _ _ _ U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _))
(format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isTBSubLattice.Build _ _ _ disp U
(@opredI _ _ _) (@opredU _ _ _) (opred0 _) (opred1 _))
(format "[ 'SubChoice_isTBSubLattice' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]" :=
(SubLattice_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubLattice_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubLattice_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]" :=
(SubPOrder_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubPOrder_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubPOrder_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]" :=
(SubChoice_isSubOrder.Build _ _ _ _ U)
(format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubOrder.Build _ _ _ disp U)
(format "[ 'SubChoice_isSubOrder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
End SubOrderExports.
HB.export SubOrderExports.
Module DeprecatedSubOrder.
Section Total.
Context {disp : disp_t} {T : orderType disp} (P : {pred T}) (sT : subType P).
#[export]
HB.instance Definition _ :=
SubPOrder_isSubOrder.Build disp T P disp (sub_type sT).
End Total.
Module Exports.
HB.reexport DeprecatedSubOrder.
Notation "[ 'POrder' 'of' T 'by' <: ]" :=
(POrder.copy T%type (sub_type T%type))
(format "[ 'POrder' 'of' T 'by' <: ]") : form_scope.
Notation "[ 'Order' 'of' T 'by' <: ]" :=
(Total.copy T%type (sub_type T%type))
(only parsing) : form_scope.
End Exports.
End DeprecatedSubOrder.
HB.export DeprecatedSubOrder.Exports.
(*************)
(* INSTANCES *)
(*************)
(********************)
(* Instances on nat *)
(********************)
(******************************************************************************)
(* This is an example of creation of multiple instances on the same type, *)
(* with distinct displays, using natural numbers. *)
(* We declare two distinct canonical orders: *)
(* - leq which is total, and where meet and join are minn and maxn, on nat *)
(* - dvdn which is partial, and where meet and join are gcdn and lcmn, *)
(* on natdvd *)
(******************************************************************************)
(******************************************************************************)
(* The Module NatOrder defines leq as the canonical order on the type nat, *)
(* i.e., without creating an alias. We define and use nat_display and proceed *)
(* like a standard canonical structure declaration, except that we use this *)
(* display. We also use a single factory LeOrderMixin to instantiate three *)
(* different canonical declarations porderType, distrLatticeType, orderType. *)
(* We finish by providing theorems to convert the operations of ordered and *)
(* lattice types to their definition without structure abstraction. *)
(******************************************************************************)
Module NatOrder.
Section NatOrder.
Export NatOrder.
#[export]
HB.instance Definition _ :=
Preorder_isPOrder.Build nat_display nat anti_leq.
#[export]
HB.instance Definition _ :=
POrder_isTotal.Build nat_display nat leq_total.
End NatOrder.
Module Exports.
HB.reexport NatOrder.
End Exports.
End NatOrder.
HB.export NatOrder.Exports.
Module NatMonotonyTheory.
Section NatMonotonyTheory.
Export NatMonotonyTheory.
Context {disp : disp_t} {T : porderType disp}.
Variables (D : {pred nat}) (f : nat -> T).
Hypothesis Dconvex : {in D &, forall i j k, i < k < j -> k \in D}.
Lemma incn_inP : {in D, forall i, i.+1 \in D -> f i < f i.+1} ->
{in D &, {mono f : i j / i <= j}}.
Proof. by move=> f_inc; apply/le_mono_in/homo_ltn_lt_in. Qed.
Lemma decn_inP : {in D, forall i, i.+1 \in D -> f i > f i.+1} ->
{in D &, {mono f : i j /~ i <= j}}.
Proof. by move=> f_dec; apply/le_nmono_in/nhomo_ltn_lt_in. Qed.
Lemma incnP : (forall i, f i < f i.+1) -> {mono f : i j / i <= j}.
Proof. by move=> f_inc; apply/le_mono/homo_ltn_lt. Qed.
Lemma decnP : (forall i, f i > f i.+1) -> {mono f : i j /~ i <= j}.
Proof. by move=> f_dec; apply/le_nmono/nhomo_ltn_lt. Qed.
End NatMonotonyTheory.
Arguments incn_inP {disp T} [D f].
Arguments decn_inP {disp T} [D f].
Arguments incnP {disp T} [f].
Arguments decnP {disp T} [f].
End NatMonotonyTheory.
(****************************************************************************)
(* The Module DvdSyntax introduces a new set of notations using the newly *)
(* created display dvd_display. We first define the display as an opaque *)
(* definition of type disp_t, and we use it as the first argument of the *)
(* operator which display we want to change from the default one (here le, *)
(* lt, dvd sdvd, meet, join, top and bottom, as well as big op notations on *)
(* gcd and lcm). This notations will now be used for any ordered type which *)
(* first parameter is set to dvd_display. *)
(****************************************************************************)
Module DvdSyntax.
Export DvdSyntax.
Notation gcd := (@meet dvd_display _).
Notation "@ 'gcd' T" := (@meet dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation lcm := (@join dvd_display _).
Notation "@ 'lcm' T" := (@join dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation "\gcd_ ( i <- r | P ) F" :=
(\big[gcd/nat0]_(i <- r | P%B) F%O) : order_scope.
Notation "\gcd_ ( i <- r ) F" :=
(\big[gcd/nat0]_(i <- r) F%O) : order_scope.
Notation "\gcd_ ( i | P ) F" :=
(\big[gcd/nat0]_(i | P%B) F%O) : order_scope.
Notation "\gcd_ i F" :=
(\big[gcd/nat0]_i F%O) : order_scope.
Notation "\gcd_ ( i : I | P ) F" :=
(\big[gcd/nat0]_(i : I | P%B) F%O) (only parsing) :
order_scope.
Notation "\gcd_ ( i : I ) F" :=
(\big[gcd/nat0]_(i : I) F%O) (only parsing) : order_scope.
Notation "\gcd_ ( m <= i < n | P ) F" :=
(\big[gcd/nat0]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\gcd_ ( m <= i < n ) F" :=
(\big[gcd/nat0]_(m <= i < n) F%O) : order_scope.
Notation "\gcd_ ( i < n | P ) F" :=
(\big[gcd/nat0]_(i < n | P%B) F%O) : order_scope.
Notation "\gcd_ ( i < n ) F" :=
(\big[gcd/nat0]_(i < n) F%O) : order_scope.
Notation "\gcd_ ( i 'in' A | P ) F" :=
(\big[gcd/nat0]_(i in A | P%B) F%O) : order_scope.
Notation "\gcd_ ( i 'in' A ) F" :=
(\big[gcd/nat0]_(i in A) F%O) : order_scope.
Notation "\lcm_ ( i <- r | P ) F" :=
(\big[lcm/nat1]_(i <- r | P%B) F%O) : order_scope.
Notation "\lcm_ ( i <- r ) F" :=
(\big[lcm/nat1]_(i <- r) F%O) : order_scope.
Notation "\lcm_ ( i | P ) F" :=
(\big[lcm/nat1]_(i | P%B) F%O) : order_scope.
Notation "\lcm_ i F" :=
(\big[lcm/nat1]_i F%O) : order_scope.
Notation "\lcm_ ( i : I | P ) F" :=
(\big[lcm/nat1]_(i : I | P%B) F%O) (only parsing) :
order_scope.
Notation "\lcm_ ( i : I ) F" :=
(\big[lcm/nat1]_(i : I) F%O) (only parsing) : order_scope.
Notation "\lcm_ ( m <= i < n | P ) F" :=
(\big[lcm/nat1]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\lcm_ ( m <= i < n ) F" :=
(\big[lcm/nat1]_(m <= i < n) F%O) : order_scope.
Notation "\lcm_ ( i < n | P ) F" :=
(\big[lcm/nat1]_(i < n | P%B) F%O) : order_scope.
Notation "\lcm_ ( i < n ) F" :=
(\big[lcm/nat1]_(i < n) F%O) : order_scope.
Notation "\lcm_ ( i 'in' A | P ) F" :=
(\big[lcm/nat1]_(i in A | P%B) F%O) : order_scope.
Notation "\lcm_ ( i 'in' A ) F" :=
(\big[lcm/nat1]_(i in A) F%O) : order_scope.
End DvdSyntax.
(******************************************************************************)
(* The Module NatDvd defines dvdn as the canonical order on NatDvd.t, which *)
(* is abbreviated using the notation natdvd at the end of the module. *)
(* We use the newly defined dvd_display, described above. *)
(* We first recover structures that are common to both nat and natdvd *)
(* (eqType, choiceType, countType) through the copy mechanism, then we use *)
(* a single factory MeetJoinMixin to instantiate both porderType and *)
(* distrLatticeType canonical structures, and end with top and bottom. *)
(* We finish by providing theorems to convert the operations of ordered and *)
(* lattice types to their definition without structure abstraction. *)
(******************************************************************************)
Module NatDvd.
Export NatDvd.
Section NatDvd.
Implicit Types (m n p : natdvd).
Lemma lcmnn n : lcmn n n = n.
Proof. by case: n => // n; rewrite /lcmn gcdnn mulnK. Qed.
Lemma le_def m n : m %| n = (gcdn m n == m)%N.
Proof. by apply/gcdn_idPl/eqP. Qed.
Lemma joinKI n m : gcdn m (lcmn m n) = m.
Proof. by rewrite (gcdn_idPl _)// dvdn_lcml. Qed.
Lemma meetKU n m : lcmn m (gcdn m n) = m.
Proof. by rewrite (lcmn_idPl _)// dvdn_gcdl. Qed.
Lemma meetUl : left_distributive gcdn lcmn.
Proof.
move=> [|m'] [|n'] [|p'] //=; rewrite ?lcmnn ?lcm0n ?lcmn0 ?gcd0n ?gcdn0//.
- by rewrite gcdnC meetKU.
- by rewrite lcmnC gcdnC meetKU.
apply: eqn_from_log; rewrite ?(gcdn_gt0, lcmn_gt0)//= => p.
by rewrite !(logn_gcd, logn_lcm) ?(gcdn_gt0, lcmn_gt0)// minn_maxl.
Qed.
Fact dvdn_anti : antisymmetric dvdn.
Proof. by move=> a b => /andP[] /gcdn_idPl + /gcdn_idPr => ->. Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build dvd_display t dvdn_anti.
#[export]
HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build dvd_display t
gcdn lcmn gcdnC lcmnC gcdnA lcmnA joinKI meetKU le_def meetUl.
Import DvdSyntax.
Lemma sdvdE (m n : t) : m %<| n = (n != m) && (m %| n).
Proof. exact/lt_def. Qed.
Lemma gcdE : gcd = gcdn :> (t -> t -> t). Proof. by []. Qed.
Lemma lcmE : lcm = lcmn :> (t -> t -> t). Proof. by []. Qed.
End NatDvd.
Module Exports.
HB.reexport NatDvd.
Definition sdvdEnat := sdvdE.
Definition gcdEnat := gcdE.
Definition lcmEnat := lcmE.
End Exports.
End NatDvd.
HB.export NatDvd.Exports.
(************************)
(* Instances on ordinal *)
(************************)
Module OrdinalOrder.
Export OrdinalOrder.
#[export]
HB.instance Definition _ (n : nat) :=
[SubChoice_isSubOrder of 'I_n by <: with ord_display].
End OrdinalOrder.
HB.export OrdinalOrder.
(*********************)
(* Instances on bool *)
(*********************)
Module BoolOrder.
Export BoolOrder.
Section BoolOrder.
Implicit Types (x y : bool).
Fact andbE x y : x && y = if (x < y)%N then x else y.
Proof. by case: x y => [] []. Qed.
Fact orbE x y : x || y = if (x < y)%N then y else x.
Proof. by case: x y => [] []. Qed.
Fact anti : antisymmetric (leq : rel bool).
Proof. by move=> x y /anti_leq /(congr1 odd); rewrite !oddb. Qed.
#[export] HB.instance Definition _ := Preorder_isPOrder.Build bool_display bool
anti.
Fact orKb b a : a && (a || b) = a.
Proof. by rewrite orbC orKb. Qed.
Fact andKb y x : x || x && y = x.
Proof. by rewrite andbC andKb. Qed.
Fact leEmeet x y : (x <= y) = (x && y == x).
Proof. by case: x; case: y. Qed.
#[export] HB.instance Definition _ := @POrder_Meet_isDistrLattice.Build
bool_display bool andb orb andbC orbC andbA orbA orKb andKb leEmeet andb_orl.
#[export] HB.instance Definition _ := DistrLattice_isTotal.Build bool_display
bool leq_total.
#[export] HB.instance Definition _ :=
@TBDistrLattice_hasComplement.Build _ bool negb orbN andbN.
Lemma andEbool : meet = andb. Proof. by []. Qed.
Lemma orEbool : meet = andb. Proof. by []. Qed.
Lemma subEbool x y : x `\` y = x && ~~ y. Proof. by []. Qed.
Lemma complEbool : compl = negb. Proof. by []. Qed.
End BoolOrder.
Module Exports.
HB.reexport BoolOrder.
Definition leEbool := leEbool.
Definition ltEbool := ltEbool.
Definition andEbool := andEbool.
Definition orEbool := orEbool.
Definition subEbool := subEbool.
Definition complEbool := complEbool.
End Exports.
End BoolOrder.
HB.export BoolOrder.Exports.
(******************************)
(* Definition of prod_display *)
(******************************)
Module Import ProdSyntax.
Export ProdSyntax.
(* The following Local Notations are here to define the \join^p_ and \meet^p_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (prod_display _ _) _).
Local Notation "\top" := (@top (prod_display _ _) _).
Local Notation meet := (@meet (prod_display _ _) _).
Local Notation join := (@join (prod_display _ _) _).
Local Notation min := (@min (prod_display _ _) _).
Local Notation max := (@max (prod_display _ _) _).
Notation "x `&^p` y" := (meet x y) : order_scope.
Notation "x `|^p` y" := (join x y) : order_scope.
Notation "\join^p_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^p_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^p_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^p_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^p_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^p_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^p_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^p_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^p_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^p_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^p_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^p_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^p_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^p_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^p_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^p_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^p_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^p_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^p_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^p_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^p_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^p_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^p_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^p_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^p_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^p_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^p_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^p_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^p_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^p_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^p_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^p_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^p_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^p_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^p_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^p_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^p_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^p_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^p_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^p_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^p_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^p_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^p_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^p_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^p_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^p_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End ProdSyntax.
Module Import SeqProdSyntax.
Export SeqProdSyntax.
(* The following Local Notations are here to define the \join^sp_ and *)
(* \meet^sp_ notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (seqprod_display _) _).
Local Notation "\top" := (@top (seqprod_display _) _).
Local Notation meet := (@meet (seqprod_display _) _).
Local Notation join := (@join (seqprod_display _) _).
Local Notation min := (@min (seqprod_display _) _).
Local Notation max := (@max (seqprod_display _) _).
Notation "x `&^sp` y" := (meet x y) : order_scope.
Notation "x `|^sp` y" := (join x y) : order_scope.
Notation "\join^sp_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^sp_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^sp_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^sp_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^sp_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^sp_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^sp_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^sp_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^sp_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^sp_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^sp_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^sp_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^sp_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^sp_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^sp_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^sp_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^sp_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^sp_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^sp_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^sp_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^sp_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^sp_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^sp_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^sp_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^sp_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^sp_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^sp_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^sp_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^sp_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^sp_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^sp_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^sp_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^sp_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^sp_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^sp_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^sp_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^sp_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End SeqProdSyntax.
Module Import LexiSyntax.
Export LexiSyntax.
Notation meetlexi := (@meet (lexi_display _ _) _).
Notation joinlexi := (@join (lexi_display _ _) _).
Notation "x `&^l` y" := (meetlexi x y) : order_scope.
Notation "x `|^l` y" := (joinlexi x y) : order_scope.
(* The following Local Notations are here to define the \join^l_ and \meet^l_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (lexi_display _ _) _).
Local Notation "\top" := (@top (lexi_display _ _) _).
Local Notation meet := (@meet (lexi_display _ _) _).
Local Notation join := (@join (lexi_display _ _) _).
Local Notation min := (@min (lexi_display _ _) _).
Local Notation max := (@max (lexi_display _ _) _).
Notation "\join^l_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^l_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^l_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^l_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^l_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^l_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^l_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^l_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^l_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^l_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^l_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^l_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^l_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^l_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^l_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^l_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^l_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^l_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^l_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End LexiSyntax.
Module Import SeqLexiSyntax.
Export SeqLexiSyntax.
Notation meetlexi := (@meet (seqlexi_display _) _).
Notation joinlexi := (@join (seqlexi_display _) _).
Notation "x `&^l` y" := (meetlexi x y) : order_scope.
Notation "x `|^l` y" := (joinlexi x y) : order_scope.
(* The following Local Notations are here to define the \join^l_ and \meet^l_ *)
(* notations later. Do not remove them. *)
Local Notation "\bot" := (@bottom (lexi_display _ _) _).
Local Notation "\top" := (@top (lexi_display _ _) _).
Local Notation meet := (@meet (lexi_display _ _) _).
Local Notation join := (@join (lexi_display _ _) _).
Local Notation min := (@min (lexi_display _ _) _).
Local Notation max := (@max (lexi_display _ _) _).
Notation "\join^l_ ( i <- r | P ) F" :=
(\big[join / \bot]_(i <- r | P%B) F%O) : order_scope.
Notation "\join^l_ ( i <- r ) F" :=
(\big[join / \bot]_(i <- r) F%O) : order_scope.
Notation "\join^l_ ( i | P ) F" :=
(\big[join / \bot]_(i | P%B) F%O) : order_scope.
Notation "\join^l_ i F" :=
(\big[join / \bot]_i F%O) : order_scope.
Notation "\join^l_ ( i : I | P ) F" :=
(\big[join / \bot]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( i : I ) F" :=
(\big[join / \bot]_(i : I) F%O) (only parsing) : order_scope.
Notation "\join^l_ ( m <= i < n | P ) F" :=
(\big[join / \bot]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( m <= i < n ) F" :=
(\big[join / \bot]_(m <= i < n) F%O) : order_scope.
Notation "\join^l_ ( i < n | P ) F" :=
(\big[join / \bot]_(i < n | P%B) F%O) : order_scope.
Notation "\join^l_ ( i < n ) F" :=
(\big[join / \bot]_(i < n) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A | P ) F" :=
(\big[join / \bot]_(i in A | P%B) F%O) : order_scope.
Notation "\join^l_ ( i 'in' A ) F" :=
(\big[join / \bot]_(i in A) F%O) : order_scope.
Notation "\meet^l_ ( i <- r | P ) F" :=
(\big[meet / \top]_(i <- r | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i <- r ) F" :=
(\big[meet / \top]_(i <- r) F%O) : order_scope.
Notation "\meet^l_ ( i | P ) F" :=
(\big[meet / \top]_(i | P%B) F%O) : order_scope.
Notation "\meet^l_ i F" :=
(\big[meet / \top]_i F%O) : order_scope.
Notation "\meet^l_ ( i : I | P ) F" :=
(\big[meet / \top]_(i : I | P%B) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( i : I ) F" :=
(\big[meet / \top]_(i : I) F%O) (only parsing) : order_scope.
Notation "\meet^l_ ( m <= i < n | P ) F" :=
(\big[meet / \top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( m <= i < n ) F" :=
(\big[meet / \top]_(m <= i < n) F%O) : order_scope.
Notation "\meet^l_ ( i < n | P ) F" :=
(\big[meet / \top]_(i < n | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i < n ) F" :=
(\big[meet / \top]_(i < n) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A | P ) F" :=
(\big[meet / \top]_(i in A | P%B) F%O) : order_scope.
Notation "\meet^l_ ( i 'in' A ) F" :=
(\big[meet / \top]_(i in A) F%O) : order_scope.
Notation "\min^l_ i F" :=
(\big[min/top]_i F) : order_scope.
Notation "\min^l_ ( i <- r | P ) F" :=
(\big[min/top]_(i <- r | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < r ) F" :=
(\big[min/top]_(i <- r) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n | P ) F" :=
(\big[min/top]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( m <= i < n ) F" :=
(\big[min/top]_(m <= i < n) F%O) : order_scope.
Notation "\min^l_ ( i | P ) F" :=
(\big[min/top]_(i | P%B) F%O) : order_scope.
Notation "\min^l_ ( i : t | P ) F" :=
(\big[min/top]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i : t ) F" :=
(\big[min/top]_(i : t) F%O) (only parsing) : order_scope.
Notation "\min^l_ ( i < n | P ) F" :=
(\big[min/top]_(i < n | P%B) F%O) : order_scope.
Notation "\min^l_ ( i < n ) F" :=
(\big[min/top]_(i < n) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A | P ) F" :=
(\big[min/top]_(i in A | P%B) F%O) : order_scope.
Notation "\min^l_ ( i 'in' A ) F" :=
(\big[min/top]_(i in A) F%O) : order_scope.
Notation "\max^l_ i F" :=
(\big[max/bottom]_i F%O) : order_scope.
Notation "\max^l_ ( i <- r | P ) F" :=
(\big[max/bottom]_(i <- r | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < r ) F" :=
(\big[max/bottom]_(i <- r) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n | P ) F" :=
(\big[max/bottom]_(m <= i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( m <= i < n ) F" :=
(\big[max/bottom]_(m <= i < n) F%O) : order_scope.
Notation "\max^l_ ( i | P ) F" :=
(\big[max/bottom]_(i | P%B) F%O) : order_scope.
Notation "\max^l_ ( i : t | P ) F" :=
(\big[max/bottom]_(i : t | P%B) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i : t ) F" :=
(\big[max/bottom]_(i : t) F%O) (only parsing) : order_scope.
Notation "\max^l_ ( i < n | P ) F" :=
(\big[max/bottom]_(i < n | P%B) F%O) : order_scope.
Notation "\max^l_ ( i < n ) F" :=
(\big[max/bottom]_(i < n) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A | P ) F" :=
(\big[max/bottom]_(i in A | P%B) F%O) : order_scope.
Notation "\max^l_ ( i 'in' A ) F" :=
(\big[max/bottom]_(i in A) F%O) : order_scope.
End SeqLexiSyntax.
(************************************************)
(* We declare an alias of the cartesian product *)
(* which has canonical product order. *)
(************************************************)
Module ProdOrder.
Export ProdOrder.
Local Open Scope type_scope. (* FIXME *)
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2).
Proof.
case=> [? ?] [? ?].
by rewrite andbAC andbA andbAC -andbA => /= /andP [] /le_anti -> /le_anti ->.
Qed.
End POrder.
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := POrder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := POrder.on T2'.
#[export]
HB.instance Definition _ :=
Preorder_isDuallyPOrder.Build disp3 (T1 * T2)
(@anti _ _ T1' T2') (@anti _ _ T1^d T2^d).
Lemma ltEprod x y : (x < y) = [&& x != y, x.1 <= y.1 & x.2 <= y.2].
Proof. by rewrite lt_neqAle. Qed.
Lemma lt_pair (x1 y1 : T1) (x2 y2 : T2) : (x1, x2) < (y1, y2) :> T1 * T2 =
[&& (x1 != y1) || (x2 != y2), x1 <= y1 & x2 <= y2].
Proof. by rewrite ltEprod negb_and. Qed.
End POrder.
Section MeetSemilattice.
Context (disp1 disp2 : disp_t).
Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let meet x y := (x.1 `&` y.1, x.2 `&` y.2).
Fact lexI x y z : (x <= meet y z) = (x <= y) && (x <= z).
Proof. by rewrite leEprod !lexI andbACA. Qed.
End MeetSemilattice.
Section MeetSemilattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := MeetSemilattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := MeetSemilattice.on T2'.
Definition meet x y := (x.1 `&` y.1, x.2 `&` y.2).
#[export]
HB.instance Definition _ :=
@POrder_isMeetSemilattice.Build disp3 (T1 * T2) meet (@lexI _ _ T1' T2').
Lemma meetEprod x y : x `&` y = (x.1 `&` y.1, x.2 `&` y.2). Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Definition join x y := (x.1 `|` y.1, x.2 `|` y.2).
#[export]
HB.instance Definition _ :=
@POrder_isJoinSemilattice.Build disp3 (T1 * T2) join
(fun x y z => @lexI _ _ T1^d T2^d z x y).
Lemma joinEprod x y : x `|` y = (x.1 `|` y.1, x.2 `|` y.2). Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bPOrderType disp1) (T2 : bPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tPOrderType disp1) (T2 : tPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : latticeType disp1) (T2 : latticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bLatticeType disp1) (T2 : bLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tLatticeType disp1) (T2 : tLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
(* /FIXME *)
Section DistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Fact meetUl : @left_distributive (T1 * T2) _ Order.meet Order.join.
Proof. by move=> ? ? ?; rewrite meetEprod !meetUl. Qed.
End DistrLattice.
Section DistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Let T1' : Type := T1.
HB.instance Definition _ := DistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := DistrLattice.on T2'.
#[export]
HB.instance Definition _ := Lattice_isDistributive.Build disp3 (T1 * T2)
(@meetUl _ _ T1' T2') (@meetUl _ _ T1^d T2^d).
End DistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) :=
POrder.on (type disp3 T1 T2).
(* /FIXME *)
Section CDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y z : T1 * T2).
Let rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2).
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by rewrite !(meetEprod, joinEprod) !rcomplPmeet. Qed.
End CDistrLattice.
Section CDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y z : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CDistrLattice.on T2'.
Definition rcompl x y z := (rcompl x.1 y.1 z.1, rcompl x.2 y.2 z.2).
#[export]
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build disp3 (T1 * T2)
rcompl (@rcomplPmeet _ _ T1' T2')
(fun x y => @rcomplPmeet _ _ T1^d T2^d y x).
Lemma rcomplEprod x y z :
rcompl x y z = (Order.rcompl x.1 y.1 z.1, Order.rcompl x.2 y.2 z.2).
Proof. by []. Qed.
End CDistrLattice.
Section CBDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let diff x y := (diff x.1 y.1, diff x.2 y.2).
Fact diffErcompl x y : diff x y = rcompl \bot x y.
Proof. by rewrite /diff !diffErcompl. Qed.
End CBDistrLattice.
Section CBDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CBDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CBDistrLattice.on T2'.
Definition diff x y := (diff x.1 y.1, diff x.2 y.2).
#[export]
HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build disp3 (T1 * T2)
diff (@diffErcompl _ _ T1' T2').
Lemma diffEprod x y : x `\` y = (x.1 `\` y.1, x.2 `\` y.2). Proof. by []. Qed.
End CBDistrLattice.
Section CTDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Definition codiff x y := (codiff x.1 y.1, codiff x.2 y.2).
#[export]
HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build disp3 (T1 * T2)
codiff (@diffErcompl _ _ T1^d T2^d).
Lemma codiffEprod x y :
codiff x y = (Order.codiff x.1 y.1, Order.codiff x.2 y.2).
Proof. by []. Qed.
End CTDistrLattice.
Section CTBDistrLattice.
Context (disp1 disp2 : disp_t).
Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Let compl x := (~` x.1, ~` x.2).
Fact complEdiff x : compl x = (\top : T1 * T2) `\` x.
Proof. by rewrite /compl !complEdiff. Qed.
End CTBDistrLattice.
Section CTBDistrLattice.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := CTBDistrLattice.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := CTBDistrLattice.on T2'.
Definition compl x := (~` x.1, ~` x.2).
#[export]
HB.instance Definition _ := @CDistrLattice_hasComplement.Build _ (T1 * T2) compl
(@complEdiff _ _ T1' T2') (@complEdiff _ _ T1^d T2^d).
Lemma complEprod x : ~` x = (~` x.1, ~` x.2). Proof. by []. Qed.
End CTBDistrLattice.
(* FIXME: use HB.saturate *)
Section FinOrder.
Context (disp1 disp2 disp3 : disp_t).
#[export]
HB.instance Definition _ (T1 : finPOrderType disp1)
(T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPOrderType disp1)
(T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPOrderType disp1)
(T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPOrderType disp1)
(T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finMeetSemilatticeType disp1)
(T2 : finMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBMeetSemilatticeType disp1)
(T2 : finBMeetSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finJoinSemilatticeType disp1)
(T2 : finJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTJoinSemilatticeType disp1)
(T2 : finTJoinSemilatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finLatticeType disp1)
(T2 : finLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBLatticeType disp1)
(T2 : finTBLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finDistrLatticeType disp1)
(T2 : finDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBDistrLatticeType disp1)
(T2 : finTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finCDistrLatticeType disp1)
(T2 : finCDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finCTBDistrLatticeType disp1)
(T2 : finCTBDistrLatticeType disp2) := POrder.on (type disp3 T1 T2).
End FinOrder.
(* /FIXME *)
Module Exports.
HB.reexport ProdOrder.
Definition ltEprod := @ltEprod.
Definition lt_pair := @lt_pair.
Definition meetEprod := @meetEprod.
Definition joinEprod := @joinEprod.
Definition rcomplEprod := @rcomplEprod.
Definition diffEprod := @diffEprod.
Definition codiffEprod := @codiffEprod.
Definition complEprod := @complEprod.
End Exports.
End ProdOrder.
HB.export ProdOrder.Exports.
Module DefaultProdOrder.
Export DefaultProdOrder.
Section DefaultProdOrder.
Context {disp1 disp2 : disp_t}.
Let prod T1 T2 := T1 *prod[prod_display disp1 disp2] T2.
(* FIXME: Scopes of arguments are broken in several places. *)
(* FIXME: Declaring a bunch of copies is still a bit painful. *)
HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) :=
POrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : bPOrderType disp1) (T2 : bPOrderType disp2) :=
BPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tPOrderType disp1) (T2 : tPOrderType disp2) :=
TPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tbPOrderType disp1) (T2 : tbPOrderType disp2) :=
TBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : meetSemilatticeType disp1) (T2 : meetSemilatticeType disp2) :=
MeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bMeetSemilatticeType disp1) (T2 : bMeetSemilatticeType disp2) :=
BMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tMeetSemilatticeType disp1) (T2 : tMeetSemilatticeType disp2) :=
TMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbMeetSemilatticeType disp1) (T2 : tbMeetSemilatticeType disp2) :=
TBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : joinSemilatticeType disp1) (T2 : joinSemilatticeType disp2) :=
JoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bJoinSemilatticeType disp1) (T2 : bJoinSemilatticeType disp2) :=
BJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tJoinSemilatticeType disp1) (T2 : tJoinSemilatticeType disp2) :=
TJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbJoinSemilatticeType disp1) (T2 : tbJoinSemilatticeType disp2) :=
TBJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : latticeType disp1) (T2 : latticeType disp2) :=
Lattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : bLatticeType disp1) (T2 : bLatticeType disp2) :=
BLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tLatticeType disp1) (T2 : tLatticeType disp2) :=
TLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbLatticeType disp1) (T2 : tbLatticeType disp2) :=
TBLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : distrLatticeType disp1) (T2 : distrLatticeType disp2) :=
DistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : bDistrLatticeType disp1) (T2 : bDistrLatticeType disp2) :=
BDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tDistrLatticeType disp1) (T2 : tDistrLatticeType disp2) :=
TDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : tbDistrLatticeType disp1) (T2 : tbDistrLatticeType disp2) :=
TBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : cDistrLatticeType disp1) (T2 : cDistrLatticeType disp2) :=
CDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : cbDistrLatticeType disp1) (T2 : cbDistrLatticeType disp2) :=
CBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : ctDistrLatticeType disp1) (T2 : ctDistrLatticeType disp2) :=
CTDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : ctbDistrLatticeType disp1) (T2 : ctbDistrLatticeType disp2) :=
CTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finPOrderType disp1) (T2 : finPOrderType disp2) :=
FinPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) :=
FinBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) :=
FinTPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) :=
FinTBPOrder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finMeetSemilatticeType disp1) (T2 : finMeetSemilatticeType disp2) :=
FinMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finBMeetSemilatticeType disp1) (T2 : finBMeetSemilatticeType disp2) :=
FinBMeetSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finJoinSemilatticeType disp1) (T2 : finJoinSemilatticeType disp2) :=
FinJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTJoinSemilatticeType disp1) (T2 : finTJoinSemilatticeType disp2) :=
FinTJoinSemilattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finLatticeType disp1) (T2 : finLatticeType disp2) :=
FinLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBLatticeType disp1) (T2 : finTBLatticeType disp2) :=
FinTBLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finDistrLatticeType disp1) (T2 : finDistrLatticeType disp2) :=
FinDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBDistrLatticeType disp1) (T2 : finTBDistrLatticeType disp2) :=
FinTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finCDistrLatticeType disp1) (T2 : finCDistrLatticeType disp2) :=
FinCDistrLattice.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finCTBDistrLatticeType disp1) (T2 : finCTBDistrLatticeType disp2) :=
FinCTBDistrLattice.copy (T1 * T2)%type (prod T1 T2).
(* /FIXME *)
End DefaultProdOrder.
End DefaultProdOrder.
(*********************************************************)
(* We declare lexicographic ordering on dependent pairs. *)
(*********************************************************)
Module SigmaOrder.
Section SigmaOrder.
Context {disp1 disp2 : disp_t}.
Section POrder.
Context (T : porderType disp1) (T' : T -> porderType disp2).
Implicit Types (x y : {t : T & T' t}).
Definition le x y := (tag x <= tag y) &&
((tag x >= tag y) ==> (tagged x <= tagged_as x y)).
Definition lt x y := (tag x <= tag y) &&
((tag x >= tag y) ==> (tagged x < tagged_as x y)).
Fact refl : reflexive le.
Proof. by move=> [x x']; rewrite /le tagged_asE/= !lexx. Qed.
Fact anti : antisymmetric le.
Proof.
rewrite /le => -[x x'] [y y']/=; case: comparableP => //= eq_xy.
by case: _ / eq_xy in y' *; rewrite !tagged_asE => /le_anti ->.
Qed.
Fact trans : transitive le.
Proof.
move=> [y y'] [x x'] [z z'] /andP[/= lexy lexy'] /andP[/= leyz leyz'].
rewrite /= /le (le_trans lexy) //=; apply/implyP => lezx.
elim: _ / (@le_anti _ _ x y) in y' z' lexy' leyz' *; last first.
by rewrite lexy (le_trans leyz).
elim: _ / (@le_anti _ _ x z) in z' leyz' *; last by rewrite (le_trans lexy).
by rewrite lexx !tagged_asE/= in lexy' leyz' *; rewrite (le_trans lexy').
Qed.
Fact lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite /lt /le; case: x y => [x x'] [y y']//=.
case: (comparableP x y) => //= xy.
by subst y; rewrite !tagged_asE lt_le_def.
Qed.
#[export]
HB.instance Definition _ :=
isPreorder.Build disp2 {t : T & T' t} lt_le_def refl trans.
#[export]
HB.instance Definition _ :=
Preorder_isPOrder.Build disp2 {t : T & T' t} anti.
Lemma leEsig x y : x <= y =
(tag x <= tag y) && ((tag x >= tag y) ==> (tagged x <= tagged_as x y)).
Proof. by []. Qed.
Lemma ltEsig x y : x < y =
(tag x <= tag y) && ((tag x >= tag y) ==> (tagged x < tagged_as x y)).
Proof. by []. Qed.
Lemma le_Taggedl x (u : T' (tag x)) : (Tagged T' u <= x) = (u <= tagged x).
Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed.
Lemma le_Taggedr x (u : T' (tag x)) : (x <= Tagged T' u) = (tagged x <= u).
Proof. by case: x => [t v]/= in u *; rewrite leEsig/= lexx/= tagged_asE. Qed.
Lemma lt_Taggedl x (u : T' (tag x)) : (Tagged T' u < x) = (u < tagged x).
Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed.
Lemma lt_Taggedr x (u : T' (tag x)) : (x < Tagged T' u) = (tagged x < u).
Proof. by case: x => [t v]/= in u *; rewrite ltEsig/= lexx/= tagged_asE. Qed.
End POrder.
Section BPOrder.
Context (T : bPOrderType disp1) (T' : T -> bPOrderType disp2).
Fact le0x (x : {t : T & T' t}) : Tagged T' (\bot : T' \bot) <= x.
Proof. by rewrite leEsig /= !le0x implybT. Qed.
#[export]
HB.instance Definition _ := hasBottom.Build _ {t : T & T' t} le0x.
Lemma botEsig : \bot = Tagged T' (\bot : T' \bot). Proof. by []. Qed.
End BPOrder.
Section TPOrder.
Context (T : tPOrderType disp1) (T' : T -> tPOrderType disp2).
Fact lex1 (x : {t : T & T' t}) : x <= Tagged T' (\top : T' \top).
Proof.
rewrite leEsig /=; case: comparableP (lex1 (tag x)) => //=.
by case: x => //= x px x0; rewrite x0 in px *; rewrite tagged_asE lex1.
Qed.
#[export]
HB.instance Definition _ := hasTop.Build _ {t : T & T' t} lex1.
Lemma topEsig : \top = Tagged T' (\top : T' \top). Proof. by []. Qed.
End TPOrder.
Section Total.
Context (T : orderType disp1) (T' : T -> orderType disp2).
Implicit Types (x y : {t : T & T' t}).
Fact total : total (<=%O : rel {t : T & T' t}).
Proof.
move=> x y; rewrite !leEsig; case: (ltgtP (tag x) (tag y)) => //=.
case: x y => [x x'] [y y']/= eqxy; elim: _ /eqxy in y' *.
by rewrite !tagged_asE le_total.
Qed.
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ {t : T & T' t} total.
End Total.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (T : bOrderType disp1)
(T' : T -> bOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : tOrderType disp1)
(T' : T -> tOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : tbOrderType disp1)
(T' : T -> tbOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finPOrderType disp1)
(T' : T -> finPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finBPOrderType disp1)
(T' : T -> finBPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTPOrderType disp1)
(T' : T -> finTPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTBPOrderType disp1)
(T' : T -> finTBPOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finOrderType disp1)
(T' : T -> finOrderType disp2) := POrder.on {t : T & T' t}.
#[export]
HB.instance Definition _ (T : finTBOrderType disp1)
(T' : T -> finTBOrderType disp2) := POrder.on {t : T & T' t}.
(* /FIXME *)
End SigmaOrder.
Module Exports.
HB.reexport SigmaOrder.
Definition leEsig := @leEsig.
Definition ltEsig := @ltEsig.
Definition le_Taggedl := @le_Taggedl.
Definition lt_Taggedl := @lt_Taggedl.
Definition le_Taggedr := @le_Taggedr.
Definition lt_Taggedr := @lt_Taggedr.
Definition topEsig := @topEsig.
Definition botEsig := @botEsig.
End Exports.
End SigmaOrder.
HB.export SigmaOrder.Exports.
(*************************************************)
(* We declare an alias of the cartesian product, *)
(* which has canonical lexicographic order. *)
(*************************************************)
Module ProdLexiOrder.
Export ProdLexiOrder.
Local Open Scope type_scope. (* FIXME *)
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Fact anti : antisymmetric (@le disp1 disp2 disp2 T1 T2).
Proof.
by rewrite /le => -[x x'] [y y'] /=; case: comparableP => //= -> /le_anti->.
Qed.
End POrder.
Section POrder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : porderType disp1) (T2 : porderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := POrder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := POrder.on T2'.
#[export]
HB.instance Definition _ :=
Preorder_isDuallyPOrder.Build disp3 (T1 * T2)
(@anti _ _ T1' T2') (@anti _ _ T1^d T2^d).
End POrder.
Section Total.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : orderType disp1) (T2 : orderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Fact total : total (<=%O : rel (T1 * T2)).
Proof.
by move=> x y; rewrite !leEprodlexi; case: ltgtP => //= _; exact: le_total.
Qed.
(* FIXME: In order to dualize this instance, we have to dualize the *)
(* [POrder_isTotal] factory. However, [min] and max are not definitional dual *)
(* (while [min x y] and [max y x] are). *)
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ (T1 * T2) total.
End Total.
(* FIXME: use HB.saturate *)
Section ProdLexiOrder.
Context (disp1 disp2 disp3 : disp_t).
#[export]
HB.instance Definition _ (T1 : finPOrderType disp1)
(T2 : finPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPOrderType disp1)
(T2 : finBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPOrderType disp1)
(T2 : finTPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPOrderType disp1)
(T2 : finTBPOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finOrderType disp1)
(T2 : finOrderType disp2) := POrder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBOrderType disp1)
(T2 : finTBOrderType disp2) := POrder.on (type disp3 T1 T2).
End ProdLexiOrder.
(* /FIXME *)
Module Exports.
HB.reexport ProdLexiOrder.
End Exports.
End ProdLexiOrder.
HB.export ProdLexiOrder.Exports.
Module DefaultProdLexiOrder.
Export DefaultProdLexiOrder.
Section DefaultProdLexiOrder.
Context {disp1 disp2 : disp_t}.
Let prodlexi T1 T2 := T1 *lexi[lexi_display disp1 disp2] T2.
(* FIXME: Scopes of arguments are broken in several places. *)
(* FIXME: Declaring a bunch of copies is still a bit painful. *)
HB.instance Definition _ (T1 : porderType disp1) (T2 : porderType disp2) :=
POrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _ (T1 : orderType disp1) (T2 : orderType disp2) :=
Total.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finPOrderType disp1) (T2 : finPOrderType disp2) :=
FinPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finBPOrderType disp1) (T2 : finBPOrderType disp2) :=
FinBPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTPOrderType disp1) (T2 : finTPOrderType disp2) :=
FinTPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTBPOrderType disp1) (T2 : finTBPOrderType disp2) :=
FinTBPOrder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finOrderType disp1) (T2 : finOrderType disp2) :=
FinTotal.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTBOrderType disp1) (T2 : finTBOrderType disp2) :=
FinTBTotal.copy (T1 * T2)%type (prodlexi T1 T2).
(* /FIXME *)
End DefaultProdLexiOrder.
End DefaultProdLexiOrder.
(*****************************************)
(* We declare an alias of the sequences, *)
(* which has canonical product order. *)
(*****************************************)
Module SeqProdOrder.
Export SeqProdOrder.
Section SeqProdOrder.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
Section POrder.
Variable T : porderType disp.
Implicit Types s : seq T.
Fact anti : antisymmetric (@le disp disp' T).
Proof.
by elim=> [|x s ihs] [|y s'] //=; rewrite andbACA => /andP[/le_anti-> /ihs->].
Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti.
End POrder.
Section MeetSemilattice.
Context (T : meetSemilatticeType disp).
Implicit Types (s : seq T).
Fixpoint meet s1 s2 :=
match s1, s2 with
| x1 :: s1', x2 :: s2' => (x1 `&` x2) :: meet s1' s2'
| _, _ => [::]
end.
Fact lexI s1 s2 s3 : (s1 <= meet s2 s3) = (s1 <= s2) && (s1 <= s3).
Proof.
elim: s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbF.
by rewrite leEseq lexI IHs1 andbACA.
Qed.
#[export]
HB.instance Definition _ := @POrder_isMeetSemilattice.Build _ (seq T) meet lexI.
Lemma meetEseq s1 s2 : s1 `&` s2 = [seq x.1 `&` x.2 | x <- zip s1 s2].
Proof. by elim: s1 s2 => [|x s1 ihs1] [|y s2]//=; rewrite -ihs1. Qed.
Lemma meet_cons x1 s1 x2 s2 :
(x1 :: s1 : seq T) `&` (x2 :: s2) = (x1 `&` x2) :: s1 `&` s2.
Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (T : joinSemilatticeType disp).
Implicit Types (s : seq T).
Fixpoint join s1 s2 :=
match s1, s2 with
| [::], _ => s2 | _, [::] => s1
| x1 :: s1', x2 :: s2' => (x1 `|` x2) :: join s1' s2'
end.
Fact leUx s1 s2 s3 : (join s1 s2 <= s3) = (s1 <= s3) && (s2 <= s3).
Proof.
elim : s1 s2 s3 => [|x s1 IHs1] [|y s2] [|z s3] //=; first by rewrite andbT.
by rewrite leEseq leUx IHs1 andbACA.
Qed.
#[export]
HB.instance Definition _ := @POrder_isJoinSemilattice.Build _ (seq T) join leUx.
Lemma joinEseq s1 s2 : s1 `|` s2 =
match s1, s2 with
| [::], _ => s2 | _, [::] => s1
| x1 :: s1', x2 :: s2' => (x1 `|` x2) :: ((s1' : seq _) `|` s2')
end.
Proof. by case: s1. Qed.
Lemma join_cons x1 s1 x2 s2 :
(x1 :: s1 : seq T) `|` (x2 :: s2) = (x1 `|` x2) :: s1 `|` s2.
Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (T : latticeType disp) := POrder.on (seq T).
(* /FIXME *)
Section DistrLattice.
Context (T : distrLatticeType disp).
Fact meetUl : left_distributive (@meet T) (@join T).
Proof. by elim=> [|? ? ih] [|? ?] [|? ?] //=; rewrite meetUl ih. Qed.
#[export]
HB.instance Definition _ := Lattice_Meet_isDistrLattice.Build _ (seq T) meetUl.
End DistrLattice.
End SeqProdOrder.
Module Exports.
HB.reexport SeqProdOrder.
Definition meetEseq := @meetEseq.
Definition meet_cons := @meet_cons.
Definition joinEseq := @joinEseq.
End Exports.
End SeqProdOrder.
HB.export SeqProdOrder.Exports.
Module DefaultSeqProdOrder.
Export DefaultSeqProdOrder.
Section DefaultSeqProdOrder.
Context {disp : disp_t}.
HB.instance Definition _ (T : porderType disp) :=
POrder.copy (seq T) (seqprod T).
HB.instance Definition _ (T : meetSemilatticeType disp) :=
BMeetSemilattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : joinSemilatticeType disp) :=
BJoinSemilattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : latticeType disp) :=
BLattice.copy (seq T) (seqprod T).
HB.instance Definition _ (T : distrLatticeType disp) :=
BDistrLattice.copy (seq T) (seqprod T).
End DefaultSeqProdOrder.
End DefaultSeqProdOrder.
(*********************************************)
(* We declare an alias of the sequences, *)
(* which has canonical lexicographic order. *)
(*********************************************)
Module SeqLexiOrder.
Export SeqLexiOrder.
Section SeqLexiOrder.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
Section POrder.
Variable T : porderType disp.
Implicit Types s : seq T.
Fact anti: antisymmetric (@le disp disp' T).
Proof.
move=> x y /andP []; elim: x y => [|x sx ih] [|y sy] //=.
by case: comparableP => //= -> lesxsy /(ih _ lesxsy) ->.
Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp' (seq T) anti.
Lemma neqhead_lexiE (x y : T) s1 s2 : x != y ->
(x :: s1 <= y :: s2 :> seq _) = (x < y).
Proof. by rewrite lexi_cons; case: comparableP. Qed.
Lemma neqhead_ltxiE (x y : T) s1 s2 : x != y ->
(x :: s1 < y :: s2 :> seq _) = (x < y).
Proof. by rewrite ltxi_cons; case: (comparableP x y). Qed.
End POrder.
Section Total.
Context (T : orderType disp).
Fact total : total (<=%O : rel (seq T)).
Proof.
by elim=> [|x1 s1 ihs1] [|x2 s2]//=; rewrite !lexi_cons; case: ltgtP => /=.
Qed.
#[export]
HB.instance Definition _ := POrder_isTotal.Build _ (seq T) total.
End Total.
End SeqLexiOrder.
Module Exports.
HB.reexport SeqLexiOrder.
Definition neqhead_lexiE := @neqhead_lexiE.
Definition neqhead_ltxiE := @neqhead_ltxiE.
End Exports.
End SeqLexiOrder.
HB.export SeqLexiOrder.Exports.
Module DefaultSeqLexiOrder.
Export DefaultSeqLexiOrder.
Section DefaultSeqLexiOrder.
Context {disp : disp_t}.
HB.instance Definition _ (T : porderType disp) :=
POrder.copy (seq T) (seqlexi T).
HB.instance Definition _ (T : orderType disp) :=
BTotal.copy (seq T) (seqlexi T).
End DefaultSeqLexiOrder.
End DefaultSeqLexiOrder.
(***************************************)
(* We declare an alias of the tuples, *)
(* which has canonical product order. *)
(***************************************)
Module TupleProdOrder.
Export TupleProdOrder.
Import DefaultSeqProdOrder.
Section TupleProdOrder.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section POrder.
Implicit Types (T : porderType disp).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ n T := SubChoice.on (n.-tuple T).
#[export]
HB.instance Definition _ n T :=
[SubChoice_isSubPOrder of n.-tuple T by <: with disp'].
End POrder.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bPOrderType disp) :=
POrder.on (n.-tuple T).
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : tPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbPOrderType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
Section MeetSemilattice.
Context (n : nat) (T : meetSemilatticeType disp).
Implicit Types (t : n.-tuple T).
Definition meet t1 t2 : n.-tuple T := [tuple tnth t1 i `&` tnth t2 i | i < n].
Fact lexI t1 t2 t3 : (t1 <= meet t2 t3) = (t1 <= t2) && (t1 <= t3).
Proof.
rewrite !leEtprod; apply/forallP/andP => [H|[Ht12 Ht13] i]; last first.
by rewrite tnth_mktuple lexI (forallP Ht12) (forallP Ht13).
by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple lexI => /andP[].
Qed.
#[export]
HB.instance Definition _ :=
@POrder_isMeetSemilattice.Build _ (n.-tuple T) meet lexI.
Lemma tnth_meet t1 t2 i : tnth (t1 `&` t2) i = tnth t1 i `&` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma meetEtprod t1 t2 : t1 `&` t2 = [tuple tnth t1 i `&` tnth t2 i | i < n].
Proof. by []. Qed.
End MeetSemilattice.
Section JoinSemilattice.
Context (n : nat) (T : joinSemilatticeType disp).
Implicit Types (t : n.-tuple T).
Definition join t1 t2 : n.-tuple T := [tuple tnth t1 i `|` tnth t2 i | i < n].
Fact leUx t1 t2 t3 : (join t1 t2 <= t3) = (t1 <= t3) && (t2 <= t3).
Proof.
rewrite !leEtprod; apply/forallP/andP => [H|[Ht13 Ht23] i]; last first.
by rewrite tnth_mktuple leUx (forallP Ht13) (forallP Ht23).
by split; apply/forallP => i; move: (H i); rewrite tnth_mktuple leUx => /andP[].
Qed.
#[export]
HB.instance Definition _ :=
@POrder_isJoinSemilattice.Build _ (n.-tuple T) join leUx.
Lemma tnth_join t1 t2 i : tnth (t1 `|` t2) i = tnth t1 i `|` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma joinEtprod t1 t2 : t1 `|` t2 = [tuple tnth t1 i `|` tnth t2 i | i < n].
Proof. by []. Qed.
End JoinSemilattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : latticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbLatticeType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
Section DistrLattice.
Context (n : nat) (T : distrLatticeType disp).
Implicit Types (t : n.-tuple T).
Fact meetUl : left_distributive (@meet n T) (@join n T).
Proof.
by move=> t1 t2 t3; apply: eq_from_tnth => i; rewrite !tnth_mktuple meetUl.
Qed.
#[export]
HB.instance Definition _ :=
Lattice_Meet_isDistrLattice.Build _ (n.-tuple T) meetUl.
End DistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbDistrLatticeType disp) :=
DistrLattice.on (n.-tuple T).
(* /FIXME *)
Section CDistrLattice.
Context (n : nat) (T : cDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition rcompl t1 t2 t3 :=
[tuple rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n].
Fact rcomplPmeet x y z : ((x `&` y) `|` z) `&` rcompl x y z = x `&` y.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPmeet. Qed.
Fact rcomplPjoin x y z : ((y `|` x) `&` z) `|` rcompl x y z = y `|` x.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple rcomplPjoin. Qed.
#[export]
HB.instance Definition _ :=
@DistrLattice_hasRelativeComplement.Build _ (n.-tuple T)
rcompl rcomplPmeet rcomplPjoin.
Lemma tnth_rcompl t1 t2 t3 i :
tnth (Order.rcompl t1 t2 t3) i =
Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i).
Proof. exact: tnth_mktuple. Qed.
Lemma rcomplEtprod t1 t2 t3 :
Order.rcompl t1 t2 t3 =
[tuple Order.rcompl (tnth t1 i) (tnth t2 i) (tnth t3 i) | i < n].
Proof. by []. Qed.
End CDistrLattice.
Section CBDistrLattice.
Context (n : nat) (T : cbDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition diff t1 t2 : n.-tuple T := [tuple tnth t1 i `\` tnth t2 i | i < n].
Fact diffErcompl t1 t2 : diff t1 t2 = rcompl \bot t1 t2.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple diffErcompl. Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasSectionalComplement.Build _ (n.-tuple T) diff diffErcompl.
Lemma tnth_diff t1 t2 i : tnth (diff t1 t2) i = tnth t1 i `\` tnth t2 i.
Proof. exact: tnth_mktuple. Qed.
Lemma diffEtprod t1 t2 : t1 `\` t2 = [tuple tnth t1 i `\` tnth t2 i | i < n].
Proof. by []. Qed.
End CBDistrLattice.
Section CTDistrLattice.
Context (n : nat) (T : ctDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition codiff t1 t2 : n.-tuple T :=
[tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n].
Fact codiffErcompl t1 t2 : codiff t1 t2 = rcompl t1 \top t2.
Proof. by apply: eq_from_tnth => i; rewrite !tnth_mktuple codiffErcompl. Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasDualSectionalComplement.Build _ (n.-tuple T)
codiff codiffErcompl.
Lemma tnth_codiff t1 t2 i :
tnth (Order.codiff t1 t2) i = Order.codiff (tnth t1 i) (tnth t2 i).
Proof. exact: tnth_mktuple. Qed.
Lemma codiffEtprod t1 t2 :
Order.codiff t1 t2 = [tuple Order.codiff (tnth t1 i) (tnth t2 i) | i < n].
Proof. by []. Qed.
End CTDistrLattice.
Section CTBDistrLattice.
Context (n : nat) (T : ctbDistrLatticeType disp).
Implicit Types (t : n.-tuple T).
Definition compl t : n.-tuple T := map_tuple compl t.
Fact complEdiff t : compl t = (\top : n.-tuple T) `\` t.
Proof.
by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEdiff.
Qed.
Fact complEcodiff t : compl t = codiff (\bot : n.-tuple T) t.
Proof.
by apply: eq_from_tnth => i; rewrite tnth_map !tnth_mktuple complEcodiff.
Qed.
#[export] HB.instance Definition _ :=
@CDistrLattice_hasComplement.Build _ (n.-tuple T)
compl complEdiff complEcodiff.
Lemma tnth_compl t i : tnth (~` t) i = ~` tnth t i.
Proof. by rewrite tnth_map. Qed.
Lemma complEtprod t : ~` t = map_tuple Order.compl t.
Proof. by []. Qed.
End CTBDistrLattice.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : finPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBMeetSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTJoinSemilatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finCDistrLatticeType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finCTBDistrLatticeType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
End TupleProdOrder.
Module Exports.
HB.reexport TupleProdOrder.
Definition tnth_meet := @tnth_meet.
Definition meetEtprod := @meetEtprod.
Definition tnth_join := @tnth_join.
Definition joinEtprod := @joinEtprod.
Definition tnth_rcompl := @tnth_rcompl.
Definition rcomplEtprod := @rcomplEtprod.
Definition tnth_diff := @tnth_diff.
Definition diffEtprod := @diffEtprod.
Definition tnth_codiff := @tnth_codiff.
Definition codiffEtprod := @codiffEtprod.
Definition tnth_compl := @tnth_compl.
Definition complEtprod := @complEtprod.
End Exports.
End TupleProdOrder.
HB.export TupleProdOrder.Exports.
Module DefaultTupleProdOrder.
Export DefaultTupleProdOrder.
Section DefaultTupleProdOrder.
Context {disp : disp_t}.
HB.instance Definition _ n (T : porderType disp) :=
POrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bPOrderType disp) :=
BPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tPOrderType disp) :=
TPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbPOrderType disp) :=
TBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : meetSemilatticeType disp) :=
MeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bMeetSemilatticeType disp) :=
BMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tMeetSemilatticeType disp) :=
TMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbMeetSemilatticeType disp) :=
TBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : joinSemilatticeType disp) :=
JoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bJoinSemilatticeType disp) :=
BJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tJoinSemilatticeType disp) :=
TJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbJoinSemilatticeType disp) :=
TBJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : latticeType disp) :=
Lattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bLatticeType disp) :=
BLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tLatticeType disp) :=
TLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbLatticeType disp) :=
TBLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : distrLatticeType disp) :=
DistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bDistrLatticeType disp) :=
BDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tDistrLatticeType disp) :=
TDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbDistrLatticeType disp) :=
TBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : cDistrLatticeType disp) :=
CDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : cbDistrLatticeType disp) :=
CBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : ctDistrLatticeType disp) :=
CTDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : ctbDistrLatticeType disp) :=
CTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finPOrderType disp) :=
FinPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finBPOrderType disp) :=
FinBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTPOrderType disp) :=
FinTPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBPOrderType disp) :=
FinTBPOrder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finMeetSemilatticeType disp) :=
FinMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finBMeetSemilatticeType disp) :=
FinBMeetSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finJoinSemilatticeType disp) :=
FinJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTJoinSemilatticeType disp) :=
FinTJoinSemilattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finLatticeType disp) :=
FinLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBLatticeType disp) :=
FinTBLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finDistrLatticeType disp) :=
FinDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finTBDistrLatticeType disp) :=
FinTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finCDistrLatticeType disp) :=
FinCDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : finCTBDistrLatticeType disp) :=
FinCTBDistrLattice.copy (n.-tuple T) (n.-tupleprod T).
End DefaultTupleProdOrder.
End DefaultTupleProdOrder.
(*********************************************)
(* We declare an alias of the tuples, *)
(* which has canonical lexicographic order. *)
(*********************************************)
Module TupleLexiOrder.
Export TupleLexiOrder.
Section TupleLexiOrder.
Import DefaultSeqLexiOrder.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section POrder.
Implicit Types (n : nat) (T : porderType disp).
#[export] HB.instance Definition _ n T :=
[SubChoice_isSubPOrder of n.-tuple T by <: with disp'].
Lemma lexi_tupleP n T (t1 t2 : n.-tuple T) :
reflect (exists k : 'I_n.+1, forall i : 'I_n, (i <= k)%N ->
tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 <= t2).
Proof.
elim: n => [|n IHn] in t1 t2 *.
by rewrite tuple0 [t2]tuple0/= lexx; constructor; exists ord0 => -[].
case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2].
rewrite [_ <= _]lexi_cons; apply: (iffP idP) => [|[k leif_xt12]].
case: comparableP => //= [ltx12 _|-> /IHn[k kP]].
exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->.
by apply/leifP; rewrite !tnth0.
exists (lift ord0 k) => i; case: (unliftP ord0 i) => [j ->|-> _].
by rewrite !ltnS => /kP; rewrite !tnthS.
by apply/leifP; rewrite !tnth0 eqxx.
have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12.
rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP.
case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12.
rewrite lexx implyTb; apply/IHn; exists k => i le_ik.
by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS.
Qed.
Lemma ltxi_tupleP n T (t1 t2 : n.-tuple T) :
reflect (exists k : 'I_n, forall i : 'I_n, (i <= k)%N ->
tnth t1 i <= tnth t2 i ?= iff (i != k :> nat)) (t1 < t2).
Proof.
elim: n => [|n IHn] in t1 t2 *.
by rewrite tuple0 [t2]tuple0/= ltxx; constructor => - [] [].
case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2].
rewrite [_ < _]ltxi_cons; apply: (iffP idP) => [|[k leif_xt12]].
case: (comparableP x1 x2) => //= [ltx12 _|-> /IHn[k kP]].
exists ord0 => i; rewrite leqn0 => /eqP/(@ord_inj n.+1 i ord0)->.
by apply/leifP; rewrite !tnth0.
exists (lift ord0 k) => i; case: (unliftP ord0 i) => {i} [i ->|-> _].
by rewrite !ltnS => /kP; rewrite !tnthS.
by apply/leifP; rewrite !tnth0 eqxx.
have /= := leif_xt12 ord0 isT; rewrite !tnth0 => leif_x12.
rewrite leif_x12/=; move: leif_x12 leif_xt12 => /leifP.
case: (unliftP ord0 k) => {k} [k-> /eqP<-{x2}|-> /lt_geF->//] leif_xt12.
rewrite lexx implyTb; apply/IHn; exists k => i le_ik.
by have := leif_xt12 (lift ord0 i) le_ik; rewrite !tnthS.
Qed.
Lemma ltxi_tuplePlt n T (t1 t2 : n.-tuple T) : reflect
(exists2 k : 'I_n, forall i : 'I_n, (i < k)%N -> tnth t1 i = tnth t2 i
& tnth t1 k < tnth t2 k)
(t1 < t2).
Proof.
apply: (iffP (ltxi_tupleP _ _)) => [[k kP]|[k kP ltk12]].
exists k => [i i_lt|]; last by rewrite (lt_leif (kP _ _)) ?eqxx ?leqnn.
by have /eqTleif->// := kP i (ltnW i_lt); rewrite ltn_eqF.
by exists k => i; case: ltngtP => //= [/kP-> _|/ord_inj-> _]; apply/leifP.
Qed.
End POrder.
#[export] HB.instance Definition _ n (T : orderType disp) :=
[SubChoice_isSubOrder of n.-tuple T by <: with disp'].
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : bPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : bOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBPOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finOrderType disp) :=
POrder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBOrderType disp) :=
POrder.on (n.-tuple T).
(* /FIXME *)
End TupleLexiOrder.
Module Exports.
HB.reexport TupleLexiOrder.
Definition lexi_tupleP := @lexi_tupleP.
Arguments lexi_tupleP {disp disp' n T t1 t2}.
Definition ltxi_tupleP := @ltxi_tupleP.
Arguments ltxi_tupleP {disp disp' n T t1 t2}.
Definition ltxi_tuplePlt := @ltxi_tuplePlt.
Arguments ltxi_tuplePlt {disp disp' n T t1 t2}.
End Exports.
End TupleLexiOrder.
HB.export TupleLexiOrder.Exports.
Module DefaultTupleLexiOrder.
Export DefaultTupleLexiOrder.
Section DefaultTupleLexiOrder.
Context {disp : disp_t}.
HB.instance Definition _ n (T : porderType disp) :=
POrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : bPOrderType disp) :=
BPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tPOrderType disp) :=
TPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tbPOrderType disp) :=
TBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
Lattice.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
DistrLattice.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : orderType disp) :=
Total.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : bOrderType disp) :=
BTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tOrderType disp) :=
TTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tbOrderType disp) :=
TBTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finPOrderType disp) :=
FinPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finBPOrderType disp) :=
FinBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTPOrderType disp) :=
FinTPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTBPOrderType disp) :=
FinTBPOrder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finOrderType disp) :=
FinTotal.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : finTBOrderType disp) :=
FinTBTotal.copy (n.-tuple T) (n.-tuplelexi T).
End DefaultTupleLexiOrder.
End DefaultTupleLexiOrder.
(*********************************************)
(* We declare an alias of the sets, *)
(* which is canonically ordered by inclusion *)
(*********************************************)
Module SetSubsetOrder.
Export SetSubsetOrder.
Section SetSubsetOrder.
Context {disp : disp_t} {T : finType}.
Local Notation "{ 'subset' T }" := (type disp T).
Implicit Type (A B C : type disp T).
Lemma setKUC B A : A :&: (A :|: B) = A.
Proof. by rewrite setUC setKU. Qed.
Lemma setKIC B A : A :|: (A :&: B) = A.
Proof. by rewrite setIC setKI. Qed.
Fact le_anti : antisymmetric (fun A B => A \subset B).
Proof. by move=> A B ABA; apply/eqP; rewrite eqEsubset. Qed.
#[export]
HB.instance Definition _ := Preorder_isPOrder.Build disp {subset T} le_anti.
#[export]
HB.instance Definition _ := POrder_Meet_isDistrLattice.Build disp {subset T}
(@setIC _) (@setUC _) (@setIA _) (@setUA _) setKUC setKIC le_def (@setIUl _).
Lemma setIDv A B : B :&: (A :\: B) = set0.
Proof.
apply/eqP; rewrite -subset0; apply/subsetP => x.
by rewrite !inE => /and3P[->].
Qed.
#[export]
HB.instance Definition _ :=
@BDistrLattice_hasSectionalComplement.Build disp {subset T}
(@setD _) setIDv (@setID _).
Lemma setTDsym A : ~: A = setT :\: A.
Proof. by rewrite setTD. Qed.
#[export]
HB.instance Definition _ :=
CBDistrLattice_hasComplement.Build disp {subset T} setTDsym.
Lemma meetEsubset A B : A `&` B = A :&: B.
Proof. by []. Qed.
Lemma joinEsubset A B : A `|` B = A :|: B.
Proof. by []. Qed.
Lemma botEsubset : \bot = set0 :> {subset T}.
Proof. by []. Qed.
Lemma topEsubset : \top = setT :> {subset T}.
Proof. by []. Qed.
Lemma subEsubset A B : A `\` B = A :\: B.
Proof. by []. Qed.
Lemma complEsubset A : ~` A = ~: A.
Proof. by []. Qed.
End SetSubsetOrder.
Module Exports.
HB.reexport.
Definition meetEsubset := @meetEsubset.
Definition joinEsubset := @joinEsubset.
Definition botEsubset := @botEsubset.
Definition topEsubset := @topEsubset.
Definition subEsubset := @subEsubset.
Definition complEsubset := @complEsubset.
End Exports.
End SetSubsetOrder.
Export SetSubsetOrder.Exports.
Module DefaultSetSubsetOrder.
Export DefaultSetSubsetOrder.
HB.instance Definition _ (T : finType) :=
CTBDistrLattice.copy {set T} {subset T}.
End DefaultSetSubsetOrder.
Lemma mono_unique d (T T' : finPOrderType d) (f g : T -> T') :
total (<=%O : rel T) -> (#|T'| <= #|T|)%N ->
{mono f : x y / x <= y} -> {mono g : x y / x <= y} ->
f =1 g.
Proof.
move=> le_total leT'T lef leg x0; move: {+}x0.
suff: finfun f = finfun g by move=> /ffunP + x => /(_ x); rewrite !ffunE.
apply: (can_inj fgraphK); apply/val_inj => /=; rewrite !codomE.
under eq_map do rewrite ffunE; under [RHS]eq_map do rewrite ffunE.
have [finj ginj] := (inc_inj lef, inc_inj leg).
have [f' fK f'K] := inj_card_bij finj leT'T.
have [g' gK g'K] := inj_card_bij ginj leT'T.
apply/eqP; have : [seq f i | i <- enum T] = [seq g i | i <- enum T].
apply: (@sorted_eq _ <=%O le_trans le_anti); rewrite ?mono_sorted_enum//.
apply: uniq_perm; rewrite ?map_inj_uniq ?sort_uniq ?fintype.enum_uniq//.
move=> x; apply/mapP/mapP => -[y _ ->].
by exists (g' (f y)); rewrite ?mem_enum.
by exists (f' (g y)); rewrite ?mem_enum.
move=> /eqP; rewrite !eq_map_all all_map [in X in _ -> X]all_map.
by have /permPl/perm_all-> := perm_sort <=%O (fintype.enum T).
Qed.
(* This module should be exported on demand, as in module tagnat below *)
Module Import EnumVal.
Export EnumVal.
Section EnumVal.
Import OrdinalOrder.Exports.
Variables (d : disp_t) (T : finPOrderType d).
Implicit Types (x : T) (A : {pred T}).
Section total.
(* We circumvent a shortcoming of finOrderType *)
(* which requires the type to be nonempty and we do not want to rule this out *)
Hypothesis (leT_total : total (<=%O : rel T)).
Lemma le_enum_val A : {mono @enum_val _ _ A : i j / i <= j}.
Proof.
apply: le_mono => i j le_ij.
rewrite /enum_val (set_nth_default (enum_default j)) -?cardE//.
apply: (sorted_ltn_nth lt_trans); rewrite -?topredE/= -?cardE//.
by rewrite lt_sorted_uniq_le enum_uniq/= sort_sorted.
Qed.
Lemma le_enum_rank_in x0 A (Ax0 : x0 \in A) :
{in A &, {mono enum_rank_in Ax0 : x y / x <= y}}.
Proof.
apply: can_mono_in (@in2W _ _ predT predT _ (@le_enum_val A)) => //.
exact/onW_can_in/enum_rankK_in.
Qed.
Lemma le_enum_rank : {mono @enum_rank d T : i j / i <= j}.
Proof. exact: (can_mono (@enum_rankK _ _) (@le_enum_val predT)). Qed.
End total.
End EnumVal.
End EnumVal.
Notation le_enum_val := le_enum_val.
Notation le_enum_rank_in := le_enum_rank_in.
Notation le_enum_rank := le_enum_rank.
Module Syntax.
Export PreOSyntax.
Export DualSyntax.
Export DvdSyntax.
Export LatticeSyntax.
Export BLatticeSyntax.
Export TLatticeSyntax.
Export CBDistrLatticeSyntax.
Export CTBDistrLatticeSyntax.
Export DualSyntax.
Export DvdSyntax.
End Syntax.
Module LTheory.
Export PreorderTheory.
Export BPreorderTheory.
Export TPreorderTheory.
Export DualPreorder. (* FIXME? *)
Export PreOCoercions.
Export PreorderTheory.
Export POrderTheory.
Export BPOrderTheory.
Export TPOrderTheory.
Export MeetTheory.
Export BMeetTheory.
Export TMeetTheory.
Export JoinTheory.
Export BJoinTheory.
Export TJoinTheory.
Export LatticeTheory.
Export DistrLatticeTheory.
Export BDistrLatticeTheory.
Export TDistrLatticeTheory.
Export DualTotalTheory. (* FIXME? *)
Export DualOrder. (* FIXME? *)
Export OrderMorphismTheory.
Export LatticeMorphismTheory.
Export BLatticeMorphismTheory.
Export TLatticeMorphismTheory.
Export ClosedPredicates.
Export LatticePred.
Export SubPreorderTheory.
End LTheory.
Module CTheory.
Export LTheory.
Export CDistrLatticeTheory.
Export CBDistrLatticeTheory.
Export CTDistrLatticeTheory.
Export CTBDistrLatticeTheory.
End CTheory.
Module TTheory.
Export LTheory TotalTheory.
End TTheory.
Module Theory.
Export CTheory TotalTheory.
End Theory.
Module Exports.
HB.reexport.
End Exports.
End Order.
Export Order.Exports.
Export Order.Syntax.
Export order.Order.Exports.
Export Order.POrder.Exports.
Export Order.BPOrder.Exports.
Export Order.TPOrder.Exports.
Export Order.TBPOrder.Exports.
Export Order.MeetSemilattice.Exports.
Export Order.BMeetSemilattice.Exports.
Export Order.TMeetSemilattice.Exports.
Export Order.TBMeetSemilattice.Exports.
Export Order.JoinSemilattice.Exports.
Export Order.BJoinSemilattice.Exports.
Export Order.TJoinSemilattice.Exports.
Export Order.TBJoinSemilattice.Exports.
Export Order.Lattice.Exports.
Export Order.BLattice.Exports.
Export Order.TLattice.Exports.
Export Order.TBLattice.Exports.
Export Order.DistrLattice.Exports.
Export Order.BDistrLattice.Exports.
Export Order.TDistrLattice.Exports.
Export Order.TBDistrLattice.Exports.
Export Order.Total.Exports.
Export Order.BTotal.Exports.
Export Order.TTotal.Exports.
Export Order.TBTotal.Exports.
Export Order.CDistrLattice.Exports.
Export Order.CBDistrLattice.Exports.
Export Order.CTDistrLattice.Exports.
Export Order.CTBDistrLattice.Exports.
Export Order.FinPOrder.Exports.
Export Order.FinBPOrder.Exports.
Export Order.FinTPOrder.Exports.
Export Order.FinTBPOrder.Exports.
Export Order.FinMeetSemilattice.Exports.
Export Order.FinBMeetSemilattice.Exports.
Export Order.FinJoinSemilattice.Exports.
Export Order.FinTJoinSemilattice.Exports.
Export Order.FinLattice.Exports.
Export Order.FinTBLattice.Exports.
Export Order.FinDistrLattice.Exports.
Export Order.FinTBDistrLattice.Exports.
Export Order.FinTotal.Exports.
Export Order.FinTBTotal.Exports.
Export Order.FinCDistrLattice.Exports.
Export Order.FinCTBDistrLattice.Exports.
(* FIXME: check if covered by Order.Exports *)
(* Export Order.NatOrder.Exports. *)
(* Export Order.NatMonotonyTheory. *)
(* Export Order.NatDvd.Exports. *)
(* Export Order.OrdinalOrder.Exports. *)
(* Export Order.BoolOrder.Exports. *)
(* Export Order.ProdOrder.Exports. *)
(* Export Order.SigmaOrder.Exports. *)
(* Export Order.ProdLexiOrder.Exports. *)
(* Export Order.SeqProdOrder.Exports. *)
(* Export Order.SeqLexiOrder.Exports. *)
(* Export Order.TupleProdOrder.Exports. *)
(* Export Order.TupleLexiOrder.Exports. *)
Module DefaultProdOrder := Order.DefaultProdOrder.
Module DefaultSeqProdOrder := Order.DefaultSeqProdOrder.
Module DefaultTupleProdOrder := Order.DefaultTupleProdOrder.
Module DefaultProdLexiOrder := Order.DefaultProdLexiOrder.
Module DefaultSeqLexiOrder := Order.DefaultSeqLexiOrder.
Module DefaultTupleLexiOrder := Order.DefaultTupleLexiOrder.
Import Order.Theory.
Module tagnat.
Section tagnat.
Import Order.EnumVal.
Context {n : nat} {p_ : 'I_n -> nat}.
Local Notation ordsum := 'I_(\sum_i p_ i)%N.
Local Notation T := {i & 'I_(p_ i)}.
Implicit Types (i : 'I_n) (s : ordsum) (p : T).
Lemma card : #|{: T}| = \sum_i p_ i.
Proof.
rewrite card_tagged sumnE/= big_map big_enum.
by apply: eq_bigr => i _; rewrite card_ord.
Qed.
Definition sig : ordsum -> T := enum_val \o cast_ord (esym card).
Definition rank : T -> ordsum := cast_ord card \o enum_rank.
Lemma sigK : cancel sig rank.
Proof.
by move=> s; rewrite /sig/rank/= enum_valK cast_ord_comp cast_ord_id.
Qed.
Lemma sig_inj : injective sig. Proof. exact: can_inj sigK. Qed.
Lemma rankK : cancel rank sig.
Proof.
by move=> p; rewrite /sig/rank/= cast_ord_comp cast_ord_id enum_rankK.
Qed.
Lemma rank_inj : injective rank. Proof. exact: can_inj rankK. Qed.
Definition sig1 s : 'I_n := tag (sig s).
Definition sig2 s : 'I_(p_ (sig1 s)) := tagged (sig s).
Definition Rank i (j : 'I_(p_ i)) := rank (Tagged _ j).
Lemma sigE12 s : sig s = @Tagged _ (sig1 s) _ (sig2 s).
Proof. by rewrite /sig1 /sig2; case: sig. Qed.
Lemma rankE p : rank p = @Rank (tag p) (tagged p). Proof. by case: p. Qed.
Lemma sig2K s : Rank (sig2 s) = s. Proof. by rewrite -rankE sigK. Qed.
Lemma Rank1K i0 (k : 'I_(p_ i0)) : sig1 (Rank k) = i0.
Proof. by rewrite /sig1 /Rank/= rankK/=. Qed.
Lemma Rank2K i0 (k : 'I_(p_ i0)) :
sig2 (Rank k) = cast_ord (congr1 p_ (esym (Rank1K k))) k.
Proof. by apply: val_inj; rewrite /sig2/sig1/Rank/= rankK. Qed.
#[local] Hint Resolve sigK rankK : core.
Lemma rank_bij : bijective rank. Proof. by exists sig. Qed.
Lemma sig_bij : bijective sig. Proof. by exists rank. Qed.
Lemma rank_bij_on : {on [pred _ | true], bijective rank}.
Proof. exact/onW_bij/rank_bij. Qed.
Lemma sig_bij_on : {on [pred _ | true], bijective sig}.
Proof. exact/onW_bij/sig_bij. Qed.
Lemma le_sig : {mono sig : i j / i <= j}.
Proof. by move=> i j; rewrite /sig/= le_enum_val//; apply: le_total. Qed.
Lemma le_sig1 : {homo sig1 : i j / i <= j}.
Proof. by move=> i j; rewrite /sig1/= -le_sig leEsig/=; case: leP. Qed.
Lemma le_rank : {mono rank : p q / p <= q}.
Proof. exact: can_mono le_sig. Qed.
Lemma le_Rank i : {mono @Rank i : j k / j <= k}.
Proof. by move=> j k; rewrite /Rank le_rank/= leEsig/= tagged_asE lexx. Qed.
Lemma lt_sig : {mono sig : i j / i < j}.
Proof. by move=> i j; rewrite !ltNge le_sig. Qed.
Lemma lt_rank : {mono rank : p q / p < q}.
Proof. by move=> p q; rewrite !ltNge le_rank. Qed.
Lemma lt_Rank i : {mono @Rank i : j k / j < k}.
Proof. by move=> j k; rewrite !ltNge le_Rank. Qed.
Lemma eq_Rank i i' (j : 'I_(p_ i)) (j': 'I_(p_ i')) :
(Rank j == Rank j' :> nat) = (i == i') && (j == j' :> nat).
Proof.
rewrite val_eqE /Rank -(can_eq sigK) !rankK.
case: (i =P i') => ii' /=; last by case: eqVneq => // -[].
by case: _ / ii' in j' *; rewrite eq_Tagged.
Qed.
Lemma rankEsum p : rank p = \sum_(i < n | (i < tag p)%N) p_ i + tagged p :> nat.
Proof.
pose sum p := \sum_(i < n | (i < tag p)%N) p_ i + tagged p.
rewrite -/(sum _); have sumlt : forall p, (sum p < \sum_i p_ i)%N.
rewrite /sum => -[/= i j].
rewrite [ltnRHS](bigID [pred i' : 'I__ | (i' < i)%N])/= ltn_add2l.
by rewrite (bigD1 i) ?ltnn//= ltn_addr.
suff: rank =1 (fun p => Ordinal (sumlt p)) by move=> /(_ p)/(congr1 val).
apply: (Order.mono_unique _ _ le_rank) => //=.
- exact: le_total.
- by rewrite card card_ord.
apply: le_mono => /= -[i j] -[i' j']; rewrite ltEsig/= !ltEord/= /sum leEord/=.
case: (ltngtP i i') => //= [ltii' _|/val_inj ii']; last first.
by rewrite -ii' in j' *; rewrite tagged_asE => ltjj'; rewrite ltn_add2l.
rewrite ltn_addr// (@leq_trans (\sum_(i0 < n | (i0 < i)%N) p_ i0 + p_ i))%N//.
by rewrite ltn_add2l.
rewrite [leqRHS](bigID [pred i' : 'I__ | (i' < i)%N])/=.
rewrite leq_add//; last first.
by rewrite (bigD1 i) ?ltnn ?ltii'//= leq_addr.
rewrite [leqRHS](eq_bigl [pred k : 'I_n | (k < i)%N])// => k/=.
by case: (ltnP k i); rewrite ?andbF// => /ltn_trans->.
Qed.
Lemma RankEsum i j : @Rank i j = \sum_(k < n | (k < i)%N) p_ k + j :> nat.
Proof. by rewrite /Rank rankEsum/=. Qed.
Lemma rect s : s = \sum_(i < n | (i < sig1 s)%N) p_ i + sig2 s :> nat.
Proof. by rewrite -[s]sigK rankEsum /= sigK. Qed.
Lemma eqRank (i0 j : nat) (li0 : (i0 < n)%N) (lj : (j < p_ (Ordinal li0))%N) :
(\sum_(i < n | (i < i0)%N) p_ i) + j = Rank (Ordinal lj) :> nat.
Proof. by rewrite RankEsum. Qed.
End tagnat.
End tagnat.
Arguments tagnat.Rank {n p_}.
|
LeastGreatest.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Algebra.Order.Group.OrderIso
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Find
import Mathlib.Order.Bounds.Defs
/-! # Least upper bound and greatest lower bound properties for integers
In this file we prove that a bounded above nonempty set of integers has the greatest element, and a
counterpart of this statement for the least element.
## Main definitions
* `Int.leastOfBdd`: if `P : ℤ → Prop` is a decidable predicate, `b` is a lower bound of the set
`{m | P m}`, and there exists `m : ℤ` such that `P m` (this time, no witness is required), then
`Int.leastOfBdd` returns the least number `m` such that `P m`, together with proofs of `P m` and
of the minimality. This definition is computable and does not rely on the axiom of choice.
* `Int.greatestOfBdd`: a similar definition with all inequalities reversed.
## Main statements
* `Int.exists_least_of_bdd`: if `P : ℤ → Prop` is a predicate such that the set `{m : P m}` is
bounded below and nonempty, then this set has the least element. This lemma uses classical logic
to avoid assumption `[DecidablePred P]`. See `Int.leastOfBdd` for a constructive counterpart.
* `Int.coe_leastOfBdd_eq`: `(Int.leastOfBdd b Hb Hinh : ℤ)` does not depend on `b`.
* `Int.exists_greatest_of_bdd`, `Int.coe_greatest_of_bdd_eq`: versions of the above lemmas with all
inequalities reversed.
## Tags
integer numbers, least element, greatest element
-/
namespace Int
/-- A computable version of `exists_least_of_bdd`: given a decidable predicate on the
integers, with an explicit lower bound and a proof that it is somewhere true, return
the least value for which the predicate is true. -/
def leastOfBdd {P : ℤ → Prop} [DecidablePred P] (b : ℤ) (Hb : ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : { lb : ℤ // P lb ∧ ∀ z : ℤ, P z → lb ≤ z } :=
have EX : ∃ n : ℕ, P (b + n) :=
let ⟨elt, Helt⟩ := Hinh
match elt, le.dest (Hb _ Helt), Helt with
| _, ⟨n, rfl⟩, Hn => ⟨n, Hn⟩
⟨b + (Nat.find EX : ℤ), Nat.find_spec EX, fun z h =>
match z, le.dest (Hb _ h), h with
| _, ⟨_, rfl⟩, h => add_le_add_left (Int.ofNat_le.2 <| Nat.find_min' _ h) _⟩
/-- `Int.leastOfBdd` is the least integer satisfying a predicate which is false for all `z : ℤ` with
`z < b` for some fixed `b : ℤ`. -/
lemma isLeast_coe_leastOfBdd {P : ℤ → Prop} [DecidablePred P] (b : ℤ) (Hb : ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : IsLeast {z | P z} (leastOfBdd b Hb Hinh : ℤ) :=
(leastOfBdd b Hb Hinh).2
/--
If `P : ℤ → Prop` is a predicate such that the set `{m : P m}` is bounded below and nonempty,
then this set has the least element. This lemma uses classical logic to avoid assumption
`[DecidablePred P]`. See `Int.leastOfBdd` for a constructive counterpart. -/
theorem exists_least_of_bdd
{P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ ∀ z : ℤ, P z → lb ≤ z := by
classical
let ⟨b, Hb⟩ := Hbdd
let ⟨lb, H⟩ := leastOfBdd b Hb Hinh
exact ⟨lb, H⟩
theorem coe_leastOfBdd_eq {P : ℤ → Prop} [DecidablePred P] {b b' : ℤ} (Hb : ∀ z : ℤ, P z → b ≤ z)
(Hb' : ∀ z : ℤ, P z → b' ≤ z) (Hinh : ∃ z : ℤ, P z) :
(leastOfBdd b Hb Hinh : ℤ) = leastOfBdd b' Hb' Hinh := by
rcases leastOfBdd b Hb Hinh with ⟨n, hn, h2n⟩
rcases leastOfBdd b' Hb' Hinh with ⟨n', hn', h2n'⟩
exact le_antisymm (h2n _ hn') (h2n' _ hn)
/-- A computable version of `exists_greatest_of_bdd`: given a decidable predicate on the
integers, with an explicit upper bound and a proof that it is somewhere true, return
the greatest value for which the predicate is true. -/
def greatestOfBdd {P : ℤ → Prop} [DecidablePred P] (b : ℤ) (Hb : ∀ z : ℤ, P z → z ≤ b)
(Hinh : ∃ z : ℤ, P z) : { ub : ℤ // P ub ∧ ∀ z : ℤ, P z → z ≤ ub } :=
have Hbdd' : ∀ z : ℤ, P (-z) → -b ≤ z := fun _ h => neg_le.1 (Hb _ h)
have Hinh' : ∃ z : ℤ, P (-z) :=
let ⟨elt, Helt⟩ := Hinh
⟨-elt, by rw [neg_neg]; exact Helt⟩
let ⟨lb, Plb, al⟩ := leastOfBdd (-b) Hbdd' Hinh'
⟨-lb, Plb, fun z h => le_neg.1 <| al _ <| by rwa [neg_neg]⟩
/-- `Int.greatestOfBdd` is the greatest integer satisfying a predicate which is false for all
`z : ℤ` with `b < z` for some fixed `b : ℤ`. -/
lemma isGreatest_coe_greatestOfBdd {P : ℤ → Prop} [DecidablePred P] (b : ℤ)
(Hb : ∀ z : ℤ, P z → z ≤ b) (Hinh : ∃ z : ℤ, P z) :
IsGreatest {z | P z} (greatestOfBdd b Hb Hinh : ℤ) :=
(greatestOfBdd b Hb Hinh).2
/--
If `P : ℤ → Prop` is a predicate such that the set `{m : P m}` is bounded above and nonempty,
then this set has the greatest element. This lemma uses classical logic to avoid assumption
`[DecidablePred P]`. See `Int.greatestOfBdd` for a constructive counterpart. -/
theorem exists_greatest_of_bdd
{P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b)
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ ∀ z : ℤ, P z → z ≤ ub := by
classical
let ⟨b, Hb⟩ := Hbdd
let ⟨lb, H⟩ := greatestOfBdd b Hb Hinh
exact ⟨lb, H⟩
theorem coe_greatestOfBdd_eq {P : ℤ → Prop} [DecidablePred P] {b b' : ℤ}
(Hb : ∀ z : ℤ, P z → z ≤ b) (Hb' : ∀ z : ℤ, P z → z ≤ b') (Hinh : ∃ z : ℤ, P z) :
(greatestOfBdd b Hb Hinh : ℤ) = greatestOfBdd b' Hb' Hinh := by
rcases greatestOfBdd b Hb Hinh with ⟨n, hn, h2n⟩
rcases greatestOfBdd b' Hb' Hinh with ⟨n', hn', h2n'⟩
exact le_antisymm (h2n' _ hn) (h2n _ hn')
end Int
|
ToMulBot.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl
-/
import Mathlib.Algebra.Order.GroupWithZero.Canonical
import Mathlib.Algebra.Order.Monoid.Unbundled.TypeTags
import Mathlib.Algebra.Order.Monoid.Unbundled.WithTop
/-!
Making an additive monoid multiplicative then adding a zero is the same as adding a bottom
element then making it multiplicative.
-/
universe u
variable {α : Type u}
namespace WithZero
variable [Add α]
/-- Making an additive monoid multiplicative then adding a zero is the same as adding a bottom
element then making it multiplicative. -/
def toMulBot : WithZero (Multiplicative α) ≃* Multiplicative (WithBot α) :=
MulEquiv.refl _
@[simp]
theorem toMulBot_zero : toMulBot (0 : WithZero (Multiplicative α)) = Multiplicative.ofAdd ⊥ :=
rfl
@[simp]
theorem toMulBot_coe (x : Multiplicative α) :
toMulBot ↑x = Multiplicative.ofAdd (↑x.toAdd : WithBot α) :=
rfl
@[simp]
theorem toMulBot_symm_bot : toMulBot.symm (Multiplicative.ofAdd (⊥ : WithBot α)) = 0 :=
rfl
@[simp]
theorem toMulBot_coe_ofAdd (x : α) :
toMulBot.symm (Multiplicative.ofAdd (x : WithBot α)) = Multiplicative.ofAdd x :=
rfl
variable [Preorder α] (a b : WithZero (Multiplicative α))
theorem toMulBot_strictMono : StrictMono (@toMulBot α _) := fun _ _ => id
@[simp]
theorem toMulBot_le : toMulBot a ≤ toMulBot b ↔ a ≤ b :=
Iff.rfl
@[simp]
theorem toMulBot_lt : toMulBot a < toMulBot b ↔ a < b :=
Iff.rfl
end WithZero
|
Defs.lean
|
/-
Copyright (c) 2020 Ashvni Narayanan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ashvni Narayanan
-/
import Mathlib.Algebra.Ring.Subsemiring.Defs
import Mathlib.RingTheory.NonUnitalSubring.Defs
/-!
# Subrings
Let `R` be a ring. This file defines the "bundled" subring type `Subring R`, a type
whose terms correspond to subrings of `R`. This is the preferred way to talk
about subrings in mathlib. Unbundled subrings (`s : Set R` and `IsSubring s`)
are not in this file, and they will ultimately be deprecated.
We prove that subrings are a complete lattice, and that you can `map` (pushforward) and
`comap` (pull back) them along ring homomorphisms.
We define the `closure` construction from `Set R` to `Subring R`, sending a subset of `R`
to the subring it generates, and prove that it is a Galois insertion.
## Main definitions
Notation used here:
`(R : Type u) [Ring R] (S : Type u) [Ring S] (f g : R →+* S)`
`(A : Subring R) (B : Subring S) (s : Set R)`
* `Subring R` : the type of subrings of a ring `R`.
* `instance : CompleteLattice (Subring R)` : the complete lattice structure on the subrings.
* `Subring.center` : the center of a ring `R`.
* `Subring.closure` : subring closure of a set, i.e., the smallest subring that includes the set.
* `Subring.gi` : `closure : Set M → Subring M` and coercion `(↑) : Subring M → et M`
form a `GaloisInsertion`.
* `comap f B : Subring A` : the preimage of a subring `B` along the ring homomorphism `f`
* `map f A : Subring B` : the image of a subring `A` along the ring homomorphism `f`.
* `prod A B : Subring (R × S)` : the product of subrings
* `f.range : Subring B` : the range of the ring homomorphism `f`.
* `eqLocus f g : Subring R` : given ring homomorphisms `f g : R →+* S`,
the subring of `R` where `f x = g x`
## Implementation notes
A subring is implemented as a subsemiring which is also an additive subgroup.
The initial PR was as a submonoid which is also an additive subgroup.
Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although
`∈` is defined as membership of a subring's underlying set.
## Tags
subring, subrings
-/
assert_not_exists RelIso Even OrderedCommMonoid
universe u v w
variable {R : Type u} {S : Type v} {T : Type w} [Ring R]
section SubringClass
/-- `SubringClass S R` states that `S` is a type of subsets `s ⊆ R` that
are both a multiplicative submonoid and an additive subgroup. -/
class SubringClass (S : Type*) (R : outParam (Type u)) [Ring R] [SetLike S R] : Prop
extends SubsemiringClass S R, NegMemClass S R
-- See note [lower instance priority]
instance (priority := 100) SubringClass.addSubgroupClass (S : Type*) (R : Type u)
[SetLike S R] [Ring R] [h : SubringClass S R] : AddSubgroupClass S R :=
{ h with }
instance (priority := 100) SubringClass.nonUnitalSubringClass (S : Type*) (R : Type u)
[SetLike S R] [Ring R] [SubringClass S R] : NonUnitalSubringClass S R where
variable [SetLike S R] [hSR : SubringClass S R] (s : S)
@[simp, aesop safe (rule_sets := [SetLike])]
theorem intCast_mem (n : ℤ) : (n : R) ∈ s := by simp only [← zsmul_one, zsmul_mem, one_mem]
namespace SubringClass
instance (priority := 75) toHasIntCast : IntCast s :=
⟨fun n => ⟨n, intCast_mem s n⟩⟩
-- Prefer subclasses of `Ring` over subclasses of `SubringClass`.
/-- A subring of a ring inherits a ring structure -/
instance (priority := 75) toRing : Ring s := fast_instance%
Subtype.coe_injective.ring Subtype.val rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl)
(fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl
-- Prefer subclasses of `Ring` over subclasses of `SubringClass`.
/-- A subring of a `CommRing` is a `CommRing`. -/
instance (priority := 75) toCommRing {R} [CommRing R] [SetLike S R] [SubringClass S R] :
CommRing s := fast_instance%
Subtype.coe_injective.commRing Subtype.val rfl rfl (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl)
(fun _ => rfl) fun _ => rfl
-- Prefer subclasses of `Ring` over subclasses of `SubringClass`.
/-- A subring of a domain is a domain. -/
instance (priority := 75) {R} [Ring R] [IsDomain R] [SetLike S R] [SubringClass S R] : IsDomain s :=
NoZeroDivisors.to_isDomain _
/-- The natural ring hom from a subring of ring `R` to `R`. -/
def subtype (s : S) : s →+* R :=
{ SubmonoidClass.subtype s, AddSubgroupClass.subtype s with
toFun := (↑) }
variable {s} in
@[simp]
lemma subtype_apply (x : s) :
SubringClass.subtype s x = x := rfl
lemma subtype_injective :
Function.Injective (subtype s) :=
Subtype.coe_injective
@[simp]
theorem coe_subtype : (subtype s : s → R) = ((↑) : s → R) :=
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
@[simp, norm_cast]
theorem coe_natCast (n : ℕ) : ((n : s) : R) = n := rfl
@[simp, norm_cast]
theorem coe_intCast (n : ℤ) : ((n : s) : R) = n := rfl
end SubringClass
end SubringClass
variable [Ring S] [Ring T]
/-- `Subring R` is the type of subrings of `R`. A subring of `R` is a subset `s` that is a
multiplicative submonoid and an additive subgroup. Note in particular that it shares the
same 0 and 1 as R. -/
structure Subring (R : Type u) [Ring R] extends Subsemiring R, AddSubgroup R
/-- Reinterpret a `Subring` as a `Subsemiring`. -/
add_decl_doc Subring.toSubsemiring
/-- Reinterpret a `Subring` as an `AddSubgroup`. -/
add_decl_doc Subring.toAddSubgroup
namespace Subring
-- Porting note: there is no `Subring.toSubmonoid` but we can't define it because there is a
-- projection `s.toSubmonoid`
instance : SetLike (Subring R) R where
coe s := s.carrier
coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h
initialize_simps_projections Subring (carrier → coe, as_prefix coe)
/-- The actual `Subring` obtained from an element of a `SubringClass`. -/
@[simps]
def ofClass {S R : Type*} [Ring R] [SetLike S R] [SubringClass S R]
(s : S) : Subring R where
carrier := s
add_mem' := add_mem
zero_mem' := zero_mem _
mul_mem' := mul_mem
neg_mem' := neg_mem
one_mem' := one_mem _
instance (priority := 100) : CanLift (Set R) (Subring R) (↑)
(fun s ↦ 0 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x + y ∈ s) ∧ 1 ∈ s ∧
(∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ {x}, x ∈ s → -x ∈ s) where
prf s h :=
⟨ { carrier := s
zero_mem' := h.1
add_mem' := h.2.1
one_mem' := h.2.2.1
mul_mem' := h.2.2.2.1
neg_mem' := h.2.2.2.2 },
rfl ⟩
instance : SubringClass (Subring R) R where
zero_mem s := s.zero_mem'
add_mem {s} := s.add_mem'
one_mem s := s.one_mem'
mul_mem {s} := s.mul_mem'
neg_mem {s} := s.neg_mem'
/-- Turn a `Subring` into a `NonUnitalSubring` by forgetting that it contains `1`. -/
def toNonUnitalSubring (S : Subring R) : NonUnitalSubring R where __ := S
@[simp]
theorem mem_toSubsemiring {s : Subring R} {x : R} : x ∈ s.toSubsemiring ↔ x ∈ s := Iff.rfl
theorem mem_carrier {s : Subring R} {x : R} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mem_mk {S : Subsemiring R} {x : R} (h) : x ∈ (⟨S, h⟩ : Subring R) ↔ x ∈ S := Iff.rfl
@[simp] theorem coe_set_mk (S : Subsemiring R) (h) : ((⟨S, h⟩ : Subring R) : Set R) = S := rfl
@[simp]
theorem mk_le_mk {S S' : Subsemiring R} (h₁ h₂) :
(⟨S, h₁⟩ : Subring R) ≤ (⟨S', h₂⟩ : Subring R) ↔ S ≤ S' :=
Iff.rfl
lemma one_mem_toNonUnitalSubring (S : Subring R) : 1 ∈ S.toNonUnitalSubring := S.one_mem
/-- Two subrings are equal if they have the same elements. -/
@[ext]
theorem ext {S T : Subring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
/-- Copy of a subring with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
@[simps coe toSubsemiring]
protected def copy (S : Subring R) (s : Set R) (hs : s = ↑S) : Subring R :=
{ S.toSubsemiring.copy s hs with
carrier := s
neg_mem' := hs.symm ▸ S.neg_mem' }
theorem copy_eq (S : Subring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
theorem toSubsemiring_injective : Function.Injective (toSubsemiring : Subring R → Subsemiring R)
| _, _, h => ext (SetLike.ext_iff.mp h :)
theorem toAddSubgroup_injective : Function.Injective (toAddSubgroup : Subring R → AddSubgroup R)
| _, _, h => ext (SetLike.ext_iff.mp h :)
theorem toSubmonoid_injective : Function.Injective (fun s : Subring R => s.toSubmonoid)
| _, _, h => ext (SetLike.ext_iff.mp h :)
/-- Construct a `Subring R` from a set `s`, a submonoid `sm`, and an additive
subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/
@[simps! coe]
protected def mk' (s : Set R) (sm : Submonoid R) (sa : AddSubgroup R) (hm : ↑sm = s)
(ha : ↑sa = s) : Subring R :=
{ sm.copy s hm.symm, sa.copy s ha.symm with }
@[simp]
theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s)
{x : R} : x ∈ Subring.mk' s sm sa hm ha ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toSubmonoid = sm :=
SetLike.coe_injective hm.symm
@[simp]
theorem mk'_toAddSubgroup {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R}
(ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toAddSubgroup = sa :=
SetLike.coe_injective ha.symm
end Subring
/-- A `Subsemiring` containing -1 is a `Subring`. -/
@[simps toSubsemiring]
def Subsemiring.toSubring (s : Subsemiring R) (hneg : (-1 : R) ∈ s) : Subring R where
toSubsemiring := s
neg_mem' h := by
rw [← neg_one_mul]
exact mul_mem hneg h
namespace Subring
variable (s : Subring R)
/-- A subring contains the ring's 1. -/
protected theorem one_mem : (1 : R) ∈ s :=
one_mem _
/-- A subring contains the ring's 0. -/
protected theorem zero_mem : (0 : R) ∈ s :=
zero_mem _
/-- A subring is closed under multiplication. -/
protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s :=
mul_mem
/-- A subring is closed under addition. -/
protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s :=
add_mem
/-- A subring is closed under negation. -/
protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s :=
neg_mem
/-- A subring is closed under subtraction -/
protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s :=
sub_mem hx hy
/-- A subring of a ring inherits a ring structure -/
instance toRing : Ring s := SubringClass.toRing s
protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s :=
zsmul_mem hx n
protected theorem pow_mem {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s :=
pow_mem hx n
@[simp, norm_cast]
theorem coe_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y :=
rfl
@[simp, norm_cast]
theorem coe_neg (x : s) : (↑(-x) : R) = -↑x :=
rfl
@[simp, norm_cast]
theorem coe_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y :=
rfl
@[simp, norm_cast]
theorem coe_zero : ((0 : s) : R) = 0 :=
rfl
@[simp, norm_cast]
theorem coe_one : ((1 : s) : R) = 1 :=
rfl
@[simp, norm_cast]
theorem coe_pow (x : s) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n :=
SubmonoidClass.coe_pow x n
theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 :=
⟨fun h => Subtype.ext (Trans.trans h s.coe_zero.symm), fun h => h.symm ▸ s.coe_zero⟩
/-- A subring of a `CommRing` is a `CommRing`. -/
instance toCommRing {R} [CommRing R] (s : Subring R) : CommRing s :=
SubringClass.toCommRing s
/-- A subring of a non-trivial ring is non-trivial. -/
instance {R} [Ring R] [Nontrivial R] (s : Subring R) : Nontrivial s :=
s.toSubsemiring.nontrivial
/-- A subring of a ring with no zero divisors has no zero divisors. -/
instance {R} [Ring R] [NoZeroDivisors R] (s : Subring R) : NoZeroDivisors s :=
s.toSubsemiring.noZeroDivisors
/-- A subring of a domain is a domain. -/
instance {R} [Ring R] [IsDomain R] (s : Subring R) : IsDomain s :=
NoZeroDivisors.to_isDomain _
/-- The natural ring hom from a subring of ring `R` to `R`. -/
def subtype (s : Subring R) : s →+* R :=
{ s.toSubmonoid.subtype, s.toAddSubgroup.subtype with toFun := (↑) }
@[simp]
lemma subtype_apply {s : Subring R} (x : s) :
s.subtype x = x := rfl
lemma subtype_injective (s : Subring R) :
Function.Injective s.subtype :=
s.toSubmonoid.subtype_injective
@[simp]
theorem coe_subtype : ⇑s.subtype = ((↑) : s → R) :=
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
@[norm_cast]
theorem coe_natCast (n : ℕ) : ((n : s) : R) = n := rfl
@[norm_cast]
theorem coe_intCast (n : ℤ) : ((n : s) : R) = n := rfl
/-! ## Partial order -/
@[simp]
theorem coe_toSubsemiring (s : Subring R) : (s.toSubsemiring : Set R) = s :=
rfl
theorem mem_toSubmonoid {s : Subring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toSubmonoid (s : Subring R) : (s.toSubmonoid : Set R) = s :=
rfl
theorem mem_toAddSubgroup {s : Subring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s :=
Iff.rfl
@[simp]
theorem coe_toAddSubgroup (s : Subring R) : (s.toAddSubgroup : Set R) = s :=
rfl
end Subring
/-- Turn a non-unital subring containing `1` into a subring. -/
def NonUnitalSubring.toSubring (S : NonUnitalSubring R) (h1 : (1 : R) ∈ S) : Subring R where
__ := S
one_mem' := h1
lemma Subring.toNonUnitalSubring_toSubring (S : Subring R) :
S.toNonUnitalSubring.toSubring S.one_mem = S := by cases S; rfl
lemma NonUnitalSubring.toSubring_toNonUnitalSubring (S : NonUnitalSubring R) (h1 : (1 : R) ∈ S) :
(NonUnitalSubring.toSubring S h1).toNonUnitalSubring = S := by cases S; rfl
|
Basic.lean
|
/-
Copyright (c) 2019 Kevin Kappelmann. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Kappelmann
-/
import Mathlib.Data.Seq.Seq
import Mathlib.Algebra.Field.Defs
/-!
# Basic Definitions/Theorems for Continued Fractions
## Summary
We define generalised, simple, and regular continued fractions and functions to evaluate their
convergents. We follow the naming conventions from Wikipedia and [wall2018analytic], Chapter 1.
## Main definitions
1. Generalised continued fractions (gcfs)
2. Simple continued fractions (scfs)
3. (Regular) continued fractions ((r)cfs)
4. Computation of convergents using the recurrence relation in `convs`.
5. Computation of convergents by directly evaluating the fraction described by the gcf in `convs'`.
## Implementation notes
1. The most commonly used kind of continued fractions in the literature are regular continued
fractions. We hence just call them `ContFract` in the library.
2. We use sequences from `Data.Seq` to encode potentially infinite sequences.
## References
- <https://en.wikipedia.org/wiki/Generalized_continued_fraction>
- [Wall, H.S., *Analytic Theory of Continued Fractions*][wall2018analytic]
## Tags
numerics, number theory, approximations, fractions
-/
-- Fix a carrier `α`.
variable (α : Type*)
/-!### Definitions -/
/-- We collect a partial numerator `aᵢ` and partial denominator `bᵢ` in a pair `⟨aᵢ, bᵢ⟩`. -/
structure GenContFract.Pair where
/-- Partial numerator -/
a : α
/-- Partial denominator -/
b : α
deriving Inhabited
open GenContFract
/-! Interlude: define some expected coercions and instances. -/
namespace GenContFract.Pair
variable {α}
/-- Make a `GenContFract.Pair` printable. -/
instance [Repr α] : Repr (Pair α) :=
⟨fun p _ ↦ "(a : " ++ repr p.a ++ ", b : " ++ repr p.b ++ ")"⟩
/-- Maps a function `f` on both components of a given pair. -/
def map {β : Type*} (f : α → β) (gp : Pair α) : Pair β :=
⟨f gp.a, f gp.b⟩
section coe
-- Fix another type `β` which we will convert to.
variable {β : Type*} [Coe α β]
/-- The coercion between numerator-denominator pairs happens componentwise. -/
@[coe]
def coeFn : Pair α → Pair β := map (↑)
/-- Coerce a pair by elementwise coercion. -/
instance : Coe (Pair α) (Pair β) :=
⟨coeFn⟩
@[simp, norm_cast]
theorem coe_toPair {a b : α} : (↑(Pair.mk a b) : Pair β) = Pair.mk (a : β) (b : β) := rfl
end coe
end GenContFract.Pair
/-- A *generalised continued fraction* (gcf) is a potentially infinite expression of the form
$$
h + \dfrac{a_0}
{b_0 + \dfrac{a_1}
{b_1 + \dfrac{a_2}
{b_2 + \dfrac{a_3}
{b_3 + \dots}}}}
$$
where `h` is called the *head term* or *integer part*, the `aᵢ` are called the
*partial numerators* and the `bᵢ` the *partial denominators* of the gcf.
We store the sequence of partial numerators and denominators in a sequence of `GenContFract.Pair`s
`s`.
For convenience, one often writes `[h; (a₀, b₀), (a₁, b₁), (a₂, b₂),...]`.
-/
@[ext]
structure GenContFract where
/-- Head term -/
h : α
/-- Sequence of partial numerator and denominator pairs. -/
s : Stream'.Seq <| Pair α
variable {α}
namespace GenContFract
/-- Constructs a generalized continued fraction without fractional part. -/
def ofInteger (a : α) : GenContFract α :=
⟨a, Stream'.Seq.nil⟩
instance [Inhabited α] : Inhabited (GenContFract α) :=
⟨ofInteger default⟩
/-- Returns the sequence of partial numerators `aᵢ` of `g`. -/
def partNums (g : GenContFract α) : Stream'.Seq α :=
g.s.map Pair.a
/-- Returns the sequence of partial denominators `bᵢ` of `g`. -/
def partDens (g : GenContFract α) : Stream'.Seq α :=
g.s.map Pair.b
/-- A gcf terminated at position `n` if its sequence terminates at position `n`. -/
def TerminatedAt (g : GenContFract α) (n : ℕ) : Prop :=
g.s.TerminatedAt n
/-- It is decidable whether a gcf terminated at a given position. -/
instance terminatedAtDecidable (g : GenContFract α) (n : ℕ) :
Decidable (g.TerminatedAt n) := by
unfold TerminatedAt
infer_instance
/-- A gcf terminates if its sequence terminates. -/
def Terminates (g : GenContFract α) : Prop :=
g.s.Terminates
section coe
/-! Interlude: define some expected coercions. -/
-- Fix another type `β` which we will convert to.
variable {β : Type*} [Coe α β]
/-- The coercion between `GenContFract` happens on the head term
and all numerator-denominator pairs componentwise. -/
@[coe]
def coeFn : GenContFract α → GenContFract β :=
fun g ↦ ⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩
/-- Coerce a gcf by elementwise coercion. -/
instance : Coe (GenContFract α) (GenContFract β) :=
⟨coeFn⟩
@[simp, norm_cast]
theorem coe_toGenContFract {g : GenContFract α} :
(g : GenContFract β) =
⟨(g.h : β), (g.s.map (↑) : Stream'.Seq <| Pair β)⟩ := rfl
end coe
end GenContFract
/-- A generalized continued fraction is a *simple continued fraction* if all partial numerators are
equal to one.
$$
h + \dfrac{1}
{b_0 + \dfrac{1}
{b_1 + \dfrac{1}
{b_2 + \dfrac{1}
{b_3 + \dots}}}}
$$
-/
def GenContFract.IsSimpContFract (g : GenContFract α)
[One α] : Prop :=
∀ (n : ℕ) (aₙ : α), g.partNums.get? n = some aₙ → aₙ = 1
variable (α) in
/-- A *simple continued fraction* (scf) is a generalized continued fraction (gcf) whose partial
numerators are equal to one.
$$
h + \dfrac{1}
{b_0 + \dfrac{1}
{b_1 + \dfrac{1}
{b_2 + \dfrac{1}
{b_3 + \dots}}}}
$$
For convenience, one often writes `[h; b₀, b₁, b₂,...]`.
It is encoded as the subtype of gcfs that satisfy `GenContFract.IsSimpContFract`.
-/
def SimpContFract [One α] :=
{ g : GenContFract α // g.IsSimpContFract }
-- Interlude: define some expected coercions.
namespace SimpContFract
variable [One α]
/-- Constructs a simple continued fraction without fractional part. -/
def ofInteger (a : α) : SimpContFract α :=
⟨GenContFract.ofInteger a, fun n aₙ h ↦ by cases h⟩
instance : Inhabited (SimpContFract α) :=
⟨ofInteger 1⟩
/-- Lift a scf to a gcf using the inclusion map. -/
instance : Coe (SimpContFract α) (GenContFract α) :=
⟨Subtype.val⟩
end SimpContFract
/--
A simple continued fraction is a *(regular) continued fraction* ((r)cf) if all partial denominators
`bᵢ` are positive, i.e. `0 < bᵢ`.
-/
def SimpContFract.IsContFract [One α] [Zero α] [LT α]
(s : SimpContFract α) : Prop :=
∀ (n : ℕ) (bₙ : α),
(↑s : GenContFract α).partDens.get? n = some bₙ → 0 < bₙ
variable (α) in
/-- A *(regular) continued fraction* ((r)cf) is a simple continued fraction (scf) whose partial
denominators are all positive. It is the subtype of scfs that satisfy `SimpContFract.IsContFract`.
-/
def ContFract [One α] [Zero α] [LT α] :=
{ s : SimpContFract α // s.IsContFract }
/-! Interlude: define some expected coercions. -/
namespace ContFract
variable [One α] [Zero α] [LT α]
/-- Constructs a continued fraction without fractional part. -/
def ofInteger (a : α) : ContFract α :=
⟨SimpContFract.ofInteger a, fun n bₙ h ↦ by cases h⟩
instance : Inhabited (ContFract α) :=
⟨ofInteger 0⟩
/-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (SimpContFract α) :=
⟨Subtype.val⟩
/-- Lift a cf to a scf using the inclusion map. -/
instance : Coe (ContFract α) (GenContFract α) :=
⟨fun c ↦ c.val⟩
end ContFract
namespace GenContFract
/-!
### Computation of Convergents
We now define how to compute the convergents of a gcf. There are two standard ways to do this:
directly evaluating the (infinite) fraction described by the gcf or using a recurrence relation.
For (r)cfs, these computations are equivalent as shown in
`Algebra.ContinuedFractions.ConvergentsEquiv`.
-/
-- Fix a division ring for the computations.
variable {K : Type*} [DivisionRing K]
/-!
We start with the definition of the recurrence relation. Given a gcf `g`, for all `n ≥ 1`, we define
- `A₋₁ = 1, A₀ = h, Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, and
- `B₋₁ = 0, B₀ = 1, Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`.
`Aₙ, Bₙ` are called the *nth continuants*, `Aₙ` the *nth numerator*, and `Bₙ` the
*nth denominator* of `g`. The *nth convergent* of `g` is given by `Aₙ / Bₙ`.
-/
/-- Returns the next numerator `Aₙ = bₙ₋₁ * Aₙ₋₁ + aₙ₋₁ * Aₙ₋₂`, where `predA` is `Aₙ₋₁`,
`ppredA` is `Aₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextNum (a b ppredA predA : K) : K :=
b * predA + a * ppredA
/-- Returns the next denominator `Bₙ = bₙ₋₁ * Bₙ₋₁ + aₙ₋₁ * Bₙ₋₂`, where `predB` is `Bₙ₋₁` and
`ppredB` is `Bₙ₋₂`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextDen (aₙ bₙ ppredB predB : K) : K :=
bₙ * predB + aₙ * ppredB
/--
Returns the next continuants `⟨Aₙ, Bₙ⟩` using `nextNum` and `nextDen`, where `pred`
is `⟨Aₙ₋₁, Bₙ₋₁⟩`, `ppred` is `⟨Aₙ₋₂, Bₙ₋₂⟩`, `a` is `aₙ₋₁`, and `b` is `bₙ₋₁`.
-/
def nextConts (a b : K) (ppred pred : Pair K) : Pair K :=
⟨nextNum a b ppred.a pred.a, nextDen a b ppred.b pred.b⟩
/-- Returns the continuants `⟨Aₙ₋₁, Bₙ₋₁⟩` of `g`. -/
def contsAux (g : GenContFract K) : Stream' (Pair K)
| 0 => ⟨1, 0⟩
| 1 => ⟨g.h, 1⟩
| n + 2 =>
match g.s.get? n with
| none => contsAux g (n + 1)
| some gp => nextConts gp.a gp.b (contsAux g n) (contsAux g (n + 1))
/-- Returns the continuants `⟨Aₙ, Bₙ⟩` of `g`. -/
def conts (g : GenContFract K) : Stream' (Pair K) :=
g.contsAux.tail
/-- Returns the numerators `Aₙ` of `g`. -/
def nums (g : GenContFract K) : Stream' K :=
g.conts.map Pair.a
/-- Returns the denominators `Bₙ` of `g`. -/
def dens (g : GenContFract K) : Stream' K :=
g.conts.map Pair.b
/-- Returns the convergents `Aₙ / Bₙ` of `g`, where `Aₙ, Bₙ` are the nth continuants of `g`. -/
def convs (g : GenContFract K) : Stream' K :=
fun n : ℕ ↦ g.nums n / g.dens n
/--
Returns the approximation of the fraction described by the given sequence up to a given position n.
For example, `convs'Aux [(1, 2), (3, 4), (5, 6)] 2 = 1 / (2 + 3 / 4)` and
`convs'Aux [(1, 2), (3, 4), (5, 6)] 0 = 0`.
-/
def convs'Aux : Stream'.Seq (Pair K) → ℕ → K
| _, 0 => 0
| s, n + 1 =>
match s.head with
| none => 0
| some gp => gp.a / (gp.b + convs'Aux s.tail n)
/-- Returns the convergents of `g` by evaluating the fraction described by `g` up to a given
position `n`. For example, `convs' [9; (1, 2), (3, 4), (5, 6)] 2 = 9 + 1 / (2 + 3 / 4)` and
`convs' [9; (1, 2), (3, 4), (5, 6)] 0 = 9`
-/
def convs' (g : GenContFract K) (n : ℕ) : K :=
g.h + convs'Aux g.s n
end GenContFract
|
Center.lean
|
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.GroupWithZero.Units.Basic
import Mathlib.GroupTheory.Subgroup.Center
/-!
# The center of a group with zero
-/
assert_not_exists Ring
/-- For a group with zero, the center of the units is the same as the units of the center. -/
@[simps! apply_val_coe symm_apply_coe_val]
def Subgroup.centerUnitsEquivUnitsCenter (G₀ : Type*) [GroupWithZero G₀] :
center G₀ˣ ≃* (Submonoid.center G₀)ˣ where
toFun := MonoidHom.toHomUnits
{ toFun u := by
refine ⟨(u : G₀ˣ), Submonoid.mem_center_iff.mpr fun r ↦ ?_⟩
obtain rfl | hr := eq_or_ne r 0
· rw [mul_zero, zero_mul]
· exact congrArg Units.val <| (u.2.comm <| Units.mk0 r hr).symm
map_one' := rfl
map_mul' _ _ := rfl }
invFun u := unitsCenterToCenterUnits G₀ u
map_mul' := map_mul _
|
Discharger.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, David Renshaw
-/
import Mathlib.Tactic.Positivity.Core
import Mathlib.Util.DischargerAsTactic
/-!
# Discharger for `field_simp` tactic
The `field_simp` tactic (implemented downstream from this file) clears denominators in algebraic
expressions. In order to do this, the denominators need to be certified as nonzero. This file
contains the discharger which carries out these checks.
Currently the discharger tries four strategies:
1. `assumption`
2. `positivity`
3. `norm_num`
4. `simp` with the same simp-context as the `field_simp` call which invoked it
TODO: Ideally the discharger would be just `positivity` (which, despite the name, has robust
handling of general `≠ 0` goals, not just `> 0` goals). We need the other strategies currently to
get (a cheap approximation of) `positivity` on fields without a partial order.
The refactor of `positivity` to avoid a partial order assumption would be large but not
fundamentally difficult.
### Main declarations
* `Mathlib.Tactic.FieldSimp.discharge`: the discharger, of type `Expr → SimpM (Option Expr)`
* `field_simp_discharge`: tactic syntax for the discharger (most useful for testing/debugging)
-/
namespace Mathlib.Tactic.FieldSimp
open Lean Elab.Tactic Parser.Tactic Lean.Meta
open Qq
/-- Constructs a trace message for the `discharge` function. -/
private def dischargerTraceMessage {ε : Type*} (prop : Expr) :
Except ε (Option Expr) → SimpM MessageData
| .error _ | .ok none => return m!"{crossEmoji} discharge {prop}"
| .ok (some _) => return m!"{checkEmoji} discharge {prop}"
open private Simp.dischargeUsingAssumption? from Lean.Meta.Tactic.Simp.Rewrite
/-- Discharge strategy for the `field_simp` tactic. -/
partial def discharge (prop : Expr) : SimpM (Option Expr) :=
withTraceNode `Tactic.field_simp (dischargerTraceMessage prop) do
-- Discharge strategy 1: Use assumptions
if let some r ← Simp.dischargeUsingAssumption? prop then
return some r
-- Discharge strategy 2: Normalize inequalities using NormNum
let prop : Q(Prop) ← (do pure prop)
let pf? ← match prop with
| ~q(($e : $α) ≠ $b) =>
try
let res ← Mathlib.Meta.NormNum.derive prop
match res with
| .isTrue pf => pure (some pf)
| _ => pure none
catch _ =>
pure none
| _ => pure none
if let some pf := pf? then return some pf
-- Discharge strategy 3: Use positivity
let pf? ←
try some <$> Mathlib.Meta.Positivity.solve prop
catch _ => pure none
if let some pf := pf? then return some pf
-- Discharge strategy 4: Use the simplifier
Simp.withIncDischargeDepth do
let ctx ← readThe Simp.Context
let stats : Simp.Stats := { (← get) with }
-- Porting note: mathlib3's analogous field_simp discharger `field_simp.ne_zero`
-- does not explicitly call `simp` recursively like this. It's unclear to me
-- whether this is because
-- 1) Lean 3 simp dischargers automatically call `simp` recursively. (Do they?),
-- 2) mathlib3 norm_num1 is able to handle any needed discharging, or
-- 3) some other reason?
let ⟨simpResult, stats'⟩ ←
simp prop ctx #[(← Simp.getSimprocs)]
discharge stats
set { (← get) with usedTheorems := stats'.usedTheorems, diag := stats'.diag }
if simpResult.expr.isConstOf ``True then
try
return some (← mkOfEqTrue (← simpResult.getProof))
catch _ =>
return none
else
return none
@[inherit_doc discharge]
elab "field_simp_discharge" : tactic => wrapSimpDischarger Mathlib.Tactic.FieldSimp.discharge
end Mathlib.Tactic.FieldSimp
|
PiTensorProduct.lean
|
/-
Copyright (c) 2024 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang
-/
import Mathlib.LinearAlgebra.PiTensorProduct
import Mathlib.Algebra.Algebra.Bilinear
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Data.Finset.NoncommProd
/-!
# Tensor product of `R`-algebras and rings
If `(Aᵢ)` is a family of `R`-algebras then the `R`-tensor product `⨂ᵢ Aᵢ` is an `R`-algebra as well
with structure map defined by `r ↦ r • 1`.
In particular if we take `R` to be `ℤ`, then this collapses into the tensor product of rings.
-/
open TensorProduct Function
variable {ι R' R : Type*} {A : ι → Type*}
namespace PiTensorProduct
noncomputable section AddCommMonoidWithOne
variable [CommSemiring R] [∀ i, AddCommMonoidWithOne (A i)] [∀ i, Module R (A i)]
instance instOne : One (⨂[R] i, A i) where
one := tprod R 1
lemma one_def : 1 = tprod R (1 : Π i, A i) := rfl
instance instAddCommMonoidWithOne : AddCommMonoidWithOne (⨂[R] i, A i) where
__ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i))
__ := instOne
end AddCommMonoidWithOne
noncomputable section NonUnitalNonAssocSemiring
variable [CommSemiring R] [∀ i, NonUnitalNonAssocSemiring (A i)]
variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)]
attribute [aesop safe] mul_add mul_smul_comm smul_mul_assoc add_mul in
/--
The multiplication in tensor product of rings is induced by `(xᵢ) * (yᵢ) = (xᵢ * yᵢ)`
-/
def mul : (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) →ₗ[R] (⨂[R] i, A i) :=
PiTensorProduct.piTensorHomMap₂ <| tprod R fun _ ↦ LinearMap.mul _ _
@[simp] lemma mul_tprod_tprod (x y : (i : ι) → A i) :
mul (tprod R x) (tprod R y) = tprod R (x * y) := by
simp only [mul, piTensorHomMap₂_tprod_tprod_tprod, LinearMap.mul_apply', Pi.mul_def]
instance instMul : Mul (⨂[R] i, A i) where
mul x y := mul x y
lemma mul_def (x y : ⨂[R] i, A i) : x * y = mul x y := rfl
@[simp] lemma tprod_mul_tprod (x y : (i : ι) → A i) :
tprod R x * tprod R y = tprod R (x * y) :=
mul_tprod_tprod x y
theorem _root_.SemiconjBy.tprod {a₁ a₂ a₃ : Π i, A i}
(ha : SemiconjBy a₁ a₂ a₃) :
SemiconjBy (tprod R a₁) (tprod R a₂) (tprod R a₃) := by
rw [SemiconjBy, tprod_mul_tprod, tprod_mul_tprod, ha]
nonrec theorem _root_.Commute.tprod {a₁ a₂ : Π i, A i} (ha : Commute a₁ a₂) :
Commute (tprod R a₁) (tprod R a₂) :=
ha.tprod
lemma smul_tprod_mul_smul_tprod (r s : R) (x y : Π i, A i) :
(r • tprod R x) * (s • tprod R y) = (r * s) • tprod R (x * y) := by
simp only [mul_def, map_smul, LinearMap.smul_apply, mul_tprod_tprod, mul_comm r s, mul_smul]
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (⨂[R] i, A i) where
__ := instMul
__ := inferInstanceAs (AddCommMonoid (⨂[R] i, A i))
left_distrib _ _ _ := (mul _).map_add _ _
right_distrib _ _ _ := mul.map_add₂ _ _ _
zero_mul _ := mul.map_zero₂ _
mul_zero _ := map_zero (mul _)
end NonUnitalNonAssocSemiring
noncomputable section NonAssocSemiring
variable [CommSemiring R] [∀ i, NonAssocSemiring (A i)]
variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)]
protected lemma one_mul (x : ⨂[R] i, A i) : mul (tprod R 1) x = x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod => simp
| add _ _ h1 h2 => simp [map_add, h1, h2]
protected lemma mul_one (x : ⨂[R] i, A i) : mul x (tprod R 1) = x := by
induction x using PiTensorProduct.induction_on with
| smul_tprod => simp
| add _ _ h1 h2 => simp [h1, h2]
instance instNonAssocSemiring : NonAssocSemiring (⨂[R] i, A i) where
__ := instNonUnitalNonAssocSemiring
one_mul := PiTensorProduct.one_mul
mul_one := PiTensorProduct.mul_one
variable (R) in
/-- `PiTensorProduct.tprod` as a `MonoidHom`. -/
@[simps]
def tprodMonoidHom : (Π i, A i) →* ⨂[R] i, A i where
toFun := tprod R
map_one' := rfl
map_mul' x y := (tprod_mul_tprod x y).symm
end NonAssocSemiring
noncomputable section NonUnitalSemiring
variable [CommSemiring R] [∀ i, NonUnitalSemiring (A i)]
variable [∀ i, Module R (A i)] [∀ i, SMulCommClass R (A i) (A i)] [∀ i, IsScalarTower R (A i) (A i)]
protected lemma mul_assoc (x y z : ⨂[R] i, A i) : mul (mul x y) z = mul x (mul y z) := by
-- restate as an equality of morphisms so that we can use `ext`
suffices LinearMap.llcomp R _ _ _ mul ∘ₗ mul =
(LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <|
LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by
exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z
ext x y z
dsimp [← mul_def]
simpa only [tprod_mul_tprod] using congr_arg (tprod R) (mul_assoc x y z)
instance instNonUnitalSemiring : NonUnitalSemiring (⨂[R] i, A i) where
__ := instNonUnitalNonAssocSemiring
mul_assoc := PiTensorProduct.mul_assoc
end NonUnitalSemiring
noncomputable section Semiring
variable [CommSemiring R'] [CommSemiring R] [∀ i, Semiring (A i)]
variable [Algebra R' R] [∀ i, Algebra R (A i)] [∀ i, Algebra R' (A i)]
variable [∀ i, IsScalarTower R' R (A i)]
instance instSemiring : Semiring (⨂[R] i, A i) where
__ := instNonUnitalSemiring
__ := instNonAssocSemiring
instance instAlgebra : Algebra R' (⨂[R] i, A i) where
__ := hasSMul'
algebraMap :=
{ toFun := (· • 1)
map_one' := by simp
map_mul' r s := show (r * s) • 1 = mul (r • 1) (s • 1) by
rw [LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower, LinearMap.smul_apply, mul_comm,
mul_smul]
congr
change (1 : ⨂[R] i, A i) = 1 * 1
rw [mul_one]
map_zero' := by simp
map_add' := by simp [add_smul] }
commutes' r x := by
simp only [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
change mul _ _ = mul _ _
rw [LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower, LinearMap.smul_apply]
change r • (1 * x) = r • (x * 1)
rw [mul_one, one_mul]
smul_def' r x := by
simp only [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk]
change _ = mul _ _
rw [LinearMap.map_smul_of_tower, LinearMap.smul_apply]
change _ = r • (1 * x)
rw [one_mul]
lemma algebraMap_apply (r : R') (i : ι) [DecidableEq ι] :
algebraMap R' (⨂[R] i, A i) r = tprod R (Pi.mulSingle i (algebraMap R' (A i) r)) := by
change r • tprod R 1 = _
have : Pi.mulSingle i (algebraMap R' (A i) r) = update (fun i ↦ 1) i (r • 1) := by
rw [Algebra.algebraMap_eq_smul_one]; rfl
rw [this, ← smul_one_smul R r (1 : A i), MultilinearMap.map_update_smul, update_eq_self,
smul_one_smul, Pi.one_def]
/--
The map `Aᵢ ⟶ ⨂ᵢ Aᵢ` given by `a ↦ 1 ⊗ ... ⊗ a ⊗ 1 ⊗ ...`
-/
@[simps]
def singleAlgHom [DecidableEq ι] (i : ι) : A i →ₐ[R] ⨂[R] i, A i where
toFun a := tprod R (MonoidHom.mulSingle _ i a)
map_one' := by simp only [map_one]; rfl
map_mul' a a' := by simp [map_mul]
map_zero' := MultilinearMap.map_update_zero _ _ _
map_add' _ _ := MultilinearMap.map_update_add _ _ _ _ _
commutes' r := show tprodCoeff R _ _ = r • tprodCoeff R _ _ by
rw [Algebra.algebraMap_eq_smul_one, ← Pi.one_apply, MonoidHom.mulSingle_apply, Pi.mulSingle,
smul_tprodCoeff]
rfl
/--
Lifting a multilinear map to an algebra homomorphism from tensor product
-/
@[simps!]
def liftAlgHom {S : Type*} [Semiring S] [Algebra R S]
(f : MultilinearMap R A S)
(one : f 1 = 1) (mul : ∀ x y, f (x * y) = f x * f y) : (⨂[R] i, A i) →ₐ[R] S :=
AlgHom.ofLinearMap (lift f) (show lift f (tprod R 1) = 1 by simp [one]) <|
LinearMap.map_mul_iff _ |>.mpr <| by aesop
@[simp] lemma tprod_noncommProd {κ : Type*} (s : Finset κ) (x : κ → Π i, A i) (hx) :
tprod R (s.noncommProd x hx) = s.noncommProd (fun k => tprod R (x k))
(hx.imp fun _ _ => Commute.tprod) :=
Finset.map_noncommProd s x _ (tprodMonoidHom R)
/-- To show two algebra morphisms from finite tensor products are equal, it suffices to show that
they agree on elements of the form $1 ⊗ ⋯ ⊗ a ⊗ 1 ⊗ ⋯$. -/
@[ext high]
theorem algHom_ext {S : Type*} [Finite ι] [DecidableEq ι] [Semiring S] [Algebra R S]
⦃f g : (⨂[R] i, A i) →ₐ[R] S⦄ (h : ∀ i, f.comp (singleAlgHom i) = g.comp (singleAlgHom i)) :
f = g :=
AlgHom.toLinearMap_injective <| PiTensorProduct.ext <| MultilinearMap.ext fun x =>
suffices f.toMonoidHom.comp (tprodMonoidHom R) = g.toMonoidHom.comp (tprodMonoidHom R) from
DFunLike.congr_fun this x
MonoidHom.pi_ext fun i xi => DFunLike.congr_fun (h i) xi
end Semiring
noncomputable section Ring
variable [CommRing R] [∀ i, Ring (A i)] [∀ i, Algebra R (A i)]
instance instRing : Ring (⨂[R] i, A i) where
__ := instSemiring
__ := inferInstanceAs <| AddCommGroup (⨂[R] i, A i)
end Ring
noncomputable section CommSemiring
variable [CommSemiring R] [∀ i, CommSemiring (A i)] [∀ i, Algebra R (A i)]
protected lemma mul_comm (x y : ⨂[R] i, A i) : mul x y = mul y x := by
suffices mul (R := R) (A := A) = mul.flip from
DFunLike.congr_fun (DFunLike.congr_fun this x) y
ext x y
dsimp
simp only [mul_tprod_tprod, mul_tprod_tprod, mul_comm x y]
instance instCommSemiring : CommSemiring (⨂[R] i, A i) where
__ := instSemiring
__ := inferInstanceAs <| AddCommMonoid (⨂[R] i, A i)
mul_comm := PiTensorProduct.mul_comm
@[simp] lemma tprod_prod {κ : Type*} (s : Finset κ) (x : κ → Π i, A i) :
tprod R (∏ k ∈ s, x k) = ∏ k ∈ s, tprod R (x k) :=
map_prod (tprodMonoidHom R) x s
section
variable [Fintype ι]
variable (R ι)
/--
The algebra equivalence from the tensor product of the constant family with
value `R` to `R`, given by multiplication of the entries.
-/
noncomputable def constantBaseRingEquiv : (⨂[R] _ : ι, R) ≃ₐ[R] R :=
letI toFun := lift (MultilinearMap.mkPiAlgebra R ι R)
AlgEquiv.ofAlgHom
(AlgHom.ofLinearMap
toFun
((lift.tprod _).trans Finset.prod_const_one)
(by
-- one of these is required, the other is a performance optimization
letI : IsScalarTower R (⨂[R] x : ι, R) (⨂[R] x : ι, R) :=
IsScalarTower.right (R := R) (A := ⨂[R] (x : ι), R)
letI : SMulCommClass R (⨂[R] x : ι, R) (⨂[R] x : ι, R) :=
Algebra.to_smulCommClass (R := R) (A := ⨂[R] x : ι, R)
rw [LinearMap.map_mul_iff]
ext
change toFun (tprod R _ * tprod R _) = toFun (tprod R _) * toFun (tprod R _)
simp_rw [tprod_mul_tprod, toFun, lift.tprod, MultilinearMap.mkPiAlgebra_apply,
Pi.mul_apply, Finset.prod_mul_distrib]))
(Algebra.ofId _ _)
(by ext)
(by classical ext)
variable {R ι}
@[simp]
theorem constantBaseRingEquiv_tprod (x : ι → R) :
constantBaseRingEquiv ι R (tprod R x) = ∏ i, x i := by
simp [constantBaseRingEquiv]
@[simp]
theorem constantBaseRingEquiv_symm (r : R) :
(constantBaseRingEquiv ι R).symm r = algebraMap _ _ r := rfl
end
end CommSemiring
noncomputable section CommRing
variable [CommRing R] [∀ i, CommRing (A i)] [∀ i, Algebra R (A i)]
instance instCommRing : CommRing (⨂[R] i, A i) where
__ := instCommSemiring
__ := inferInstanceAs <| AddCommGroup (⨂[R] i, A i)
end CommRing
end PiTensorProduct
|
AssertNoSorry.lean
|
/-
Copyright (c) 2023 David Renshaw. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Renshaw
-/
import Mathlib.Init
import Lean.Util.CollectAxioms
import Lean.Elab.Command
/-!
# Defines the `assert_no_sorry` command.
Throws an error if the given identifier uses sorryAx.
-/
open Lean Meta Elab Command
/-- Throws an error if the given identifier uses sorryAx. -/
elab "assert_no_sorry " n:ident : command => do
let name ← liftCoreM <| Lean.Elab.realizeGlobalConstNoOverloadWithInfo n
let axioms ← Lean.collectAxioms name
if axioms.contains ``sorryAx
then throwError "{n} contains sorry"
|
Defs.lean
|
/-
Copyright (c) 2020 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang, Johan Commelin
-/
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Combinatorics.Enumerative.Partition
/-!
# Symmetric Polynomials and Elementary Symmetric Polynomials
This file defines symmetric `MvPolynomial`s and the bases of elementary, complete homogeneous,
power sum, and monomial symmetric `MvPolynomial`s. We also prove some basic facts about them.
## Main declarations
* `MvPolynomial.IsSymmetric`
* `MvPolynomial.symmetricSubalgebra`
* `MvPolynomial.esymm`
* `MvPolynomial.hsymm`
* `MvPolynomial.psum`
* `MvPolynomial.msymm`
## Notation
+ `esymm σ R n` is the `n`th elementary symmetric polynomial in `MvPolynomial σ R`.
+ `hsymm σ R n` is the `n`th complete homogeneous symmetric polynomial in `MvPolynomial σ R`.
+ `psum σ R n` is the degree-`n` power sum in `MvPolynomial σ R`, i.e. the sum of monomials
`(X i)^n` over `i ∈ σ`.
+ `msymm σ R μ` is the monomial symmetric polynomial whose exponents set are the parts
of `μ ⊢ n` in `MvPolynomial σ R`.
As in other polynomial files, we typically use the notation:
+ `σ τ : Type*` (indexing the variables)
+ `R S : Type*` `[CommSemiring R]` `[CommSemiring S]` (the coefficients)
+ `r : R` elements of the coefficient ring
+ `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians
+ `φ ψ : MvPolynomial σ R`
-/
open Equiv (Perm)
noncomputable section
namespace Multiset
variable {R : Type*} [CommSemiring R]
/-- The `n`th elementary symmetric function evaluated at the elements of `s` -/
def esymm (s : Multiset R) (n : ℕ) : R :=
((s.powersetCard n).map Multiset.prod).sum
theorem _root_.Finset.esymm_map_val {σ} (f : σ → R) (s : Finset σ) (n : ℕ) :
(s.val.map f).esymm n = (s.powersetCard n).sum fun t => t.prod f := by
simp only [esymm, powersetCard_map, ← Finset.map_val_val_powersetCard, map_map]
rfl
lemma pow_smul_esymm {S : Type*} [Monoid S] [DistribMulAction S R] [IsScalarTower S R R]
[SMulCommClass S R R] (s : S) (n : ℕ) (m : Multiset R) :
s ^ n • m.esymm n = (m.map (s • ·)).esymm n := by
rw [esymm, smul_sum, map_map]
trans ((powersetCard n m).map (fun x : Multiset R ↦ s ^ card x • x.prod)).sum
· refine congr_arg _ (map_congr rfl (fun x hx ↦ ?_))
rw [Function.comp_apply, (mem_powersetCard.1 hx).2]
· simp_rw [smul_prod, esymm, powersetCard_map, map_map, Function.comp_def]
-- TODO: `Multiset.insert_eq_cons` being simp means that `esymm {x, y}` is not simp normal form
@[simp] lemma esymm_pair_one (x y : R) :
esymm (x ::ₘ {y}) 1 = x + y := by
simp [esymm, powersetCard_one, add_comm]
@[simp] lemma esymm_pair_two (x y : R) :
esymm (x ::ₘ {y}) 2 = x * y := by
simp [esymm, powersetCard_one]
end Multiset
namespace MvPolynomial
variable {σ τ : Type*} {R S : Type*}
/-- A `MvPolynomial φ` is symmetric if it is invariant under
permutations of its variables by the `rename` operation -/
def IsSymmetric [CommSemiring R] (φ : MvPolynomial σ R) : Prop :=
∀ e : Perm σ, rename e φ = φ
/-- The subalgebra of symmetric `MvPolynomial`s. -/
def symmetricSubalgebra (σ R : Type*) [CommSemiring R] : Subalgebra R (MvPolynomial σ R) where
carrier := setOf IsSymmetric
algebraMap_mem' r e := rename_C e r
mul_mem' ha hb e := by rw [map_mul, ha, hb]
add_mem' ha hb e := by rw [map_add, ha, hb]
@[simp]
theorem mem_symmetricSubalgebra [CommSemiring R] (p : MvPolynomial σ R) :
p ∈ symmetricSubalgebra σ R ↔ p.IsSymmetric :=
Iff.rfl
namespace IsSymmetric
section CommSemiring
variable [CommSemiring R] [CommSemiring S] {φ ψ : MvPolynomial σ R}
@[simp]
theorem C (r : R) : IsSymmetric (C r : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).algebraMap_mem r
@[simp]
theorem zero : IsSymmetric (0 : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).zero_mem
@[simp]
theorem one : IsSymmetric (1 : MvPolynomial σ R) :=
(symmetricSubalgebra σ R).one_mem
theorem add (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ + ψ) :=
(symmetricSubalgebra σ R).add_mem hφ hψ
theorem mul (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ * ψ) :=
(symmetricSubalgebra σ R).mul_mem hφ hψ
theorem smul (r : R) (hφ : IsSymmetric φ) : IsSymmetric (r • φ) :=
(symmetricSubalgebra σ R).smul_mem hφ r
@[simp]
theorem map (hφ : IsSymmetric φ) (f : R →+* S) : IsSymmetric (map f φ) := fun e => by
rw [← map_rename, hφ]
protected theorem rename (hφ : φ.IsSymmetric) (e : σ ≃ τ) : (rename e φ).IsSymmetric := fun _ => by
apply rename_injective _ e.symm.injective
simp_rw [rename_rename, ← Equiv.coe_trans, Equiv.self_trans_symm, Equiv.coe_refl, rename_id_apply]
rw [hφ]
@[simp]
theorem _root_.MvPolynomial.isSymmetric_rename {e : σ ≃ τ} :
(MvPolynomial.rename e φ).IsSymmetric ↔ φ.IsSymmetric :=
⟨fun h => by simpa using (IsSymmetric.rename (R := R) h e.symm), (IsSymmetric.rename · e)⟩
end CommSemiring
section CommRing
variable [CommRing R] {φ ψ : MvPolynomial σ R}
theorem neg (hφ : IsSymmetric φ) : IsSymmetric (-φ) :=
(symmetricSubalgebra σ R).neg_mem hφ
theorem sub (hφ : IsSymmetric φ) (hψ : IsSymmetric ψ) : IsSymmetric (φ - ψ) :=
(symmetricSubalgebra σ R).sub_mem hφ hψ
end CommRing
end IsSymmetric
/-- `MvPolynomial.rename` induces an isomorphism between the symmetric subalgebras. -/
@[simps!]
def renameSymmetricSubalgebra [CommSemiring R] (e : σ ≃ τ) :
symmetricSubalgebra σ R ≃ₐ[R] symmetricSubalgebra τ R :=
AlgEquiv.ofAlgHom
(((rename e).comp (symmetricSubalgebra σ R).val).codRestrict _ <| fun x => x.2.rename e)
(((rename e.symm).comp <| Subalgebra.val _).codRestrict _ <| fun x => x.2.rename e.symm)
(AlgHom.ext <| fun p => Subtype.ext <| by simp)
(AlgHom.ext <| fun p => Subtype.ext <| by simp)
variable (σ R : Type*) [CommSemiring R] [CommSemiring S] [Fintype σ] [Fintype τ]
section ElementarySymmetric
open Finset
/-- The `n`th elementary symmetric `MvPolynomial σ R`.
It is the sum over all the degree n squarefree monomials in `MvPolynomial σ R`. -/
def esymm (n : ℕ) : MvPolynomial σ R :=
∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i
/--
`esymmPart` is the product of the symmetric polynomials `esymm μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition.
-/
def esymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (esymm σ R)).prod
/-- The `n`th elementary symmetric `MvPolynomial σ R` is obtained by evaluating the
`n`th elementary symmetric at the `Multiset` of the monomials -/
theorem esymm_eq_multiset_esymm : esymm σ R = (univ.val.map X).esymm := by
exact funext fun n => (esymm_map_val X _ n).symm
theorem aeval_esymm_eq_multiset_esymm [Algebra R S] (n : ℕ) (f : σ → S) :
aeval f (esymm σ R n) = (univ.val.map f).esymm n := by
simp_rw [esymm, aeval_sum, aeval_prod, aeval_X, esymm_map_val]
/-- We can define `esymm σ R n` by summing over a subtype instead of over `powerset_len`. -/
theorem esymm_eq_sum_subtype (n : ℕ) :
esymm σ R n = ∑ t : {s : Finset σ // #s = n}, ∏ i ∈ (t : Finset σ), X i :=
sum_subtype _ (fun _ => mem_powersetCard_univ) _
/-- We can define `esymm σ R n` as a sum over explicit monomials -/
theorem esymm_eq_sum_monomial (n : ℕ) :
esymm σ R n = ∑ t ∈ powersetCard n univ, monomial (∑ i ∈ t, Finsupp.single i 1) 1 := by
simp_rw [monomial_sum_one]
rfl
@[simp]
theorem esymm_zero : esymm σ R 0 = 1 := by
simp only [esymm, powersetCard_zero, sum_singleton, prod_empty]
@[simp]
theorem esymm_one : esymm σ R 1 = ∑ i, X i := by simp [esymm, powersetCard_one]
theorem esymmPart_zero : esymmPart σ R (.indiscrete 0) = 1 := by simp [esymmPart]
@[simp]
theorem esymmPart_indiscrete (n : ℕ) : esymmPart σ R (.indiscrete n) = esymm σ R n := by
cases n <;> simp [esymmPart]
theorem map_esymm (n : ℕ) (f : R →+* S) : map f (esymm σ R n) = esymm σ S n := by
simp_rw [esymm, map_sum, map_prod, map_X]
theorem rename_esymm (n : ℕ) (e : σ ≃ τ) : rename e (esymm σ R n) = esymm τ R n :=
calc
rename e (esymm σ R n) = ∑ x ∈ powersetCard n univ, ∏ i ∈ x, X (e i) := by
simp_rw [esymm, map_sum, map_prod, rename_X]
_ = ∑ t ∈ powersetCard n (univ.map e.toEmbedding), ∏ i ∈ t, X i := by
simp [powersetCard_map, -map_univ_equiv]
-- Porting note: Why did `mapEmbedding_apply` not work?
dsimp [mapEmbedding, OrderEmbedding.ofMapLEIff]
simp
_ = ∑ t ∈ powersetCard n univ, ∏ i ∈ t, X i := by rw [map_univ_equiv]
theorem esymm_isSymmetric (n : ℕ) : IsSymmetric (esymm σ R n) := by
intro
rw [rename_esymm]
theorem support_esymm'' [DecidableEq σ] [Nontrivial R] (n : ℕ) :
(esymm σ R n).support =
(powersetCard n (univ : Finset σ)).biUnion fun t =>
(Finsupp.single (∑ i ∈ t, Finsupp.single i 1) (1 : R)).support := by
rw [esymm_eq_sum_monomial]
simp only [← single_eq_monomial]
refine Finsupp.support_sum_eq_biUnion (powersetCard n (univ : Finset σ)) ?_
intro s t hst
rw [disjoint_left, Finsupp.support_single_ne_zero _ one_ne_zero]
rw [Finsupp.support_single_ne_zero _ one_ne_zero]
simp only [mem_singleton]
rintro a h rfl
have := congr_arg Finsupp.support h
rw [Finsupp.support_sum_eq_biUnion, Finsupp.support_sum_eq_biUnion] at this
· have hsingle : ∀ s : Finset σ, ∀ x : σ, x ∈ s → (Finsupp.single x 1).support = {x} := by
intros _ x _
rw [Finsupp.support_single_ne_zero x one_ne_zero]
have hs := biUnion_congr (of_eq_true (eq_self s)) (hsingle s)
have ht := biUnion_congr (of_eq_true (eq_self t)) (hsingle t)
rw [hs, ht] at this
· simp only [biUnion_singleton_eq_self] at this
exact absurd this hst.symm
all_goals intro x y; simp [Finsupp.support_single_disjoint]
theorem support_esymm' [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support =
(powersetCard n (univ : Finset σ)).biUnion fun t => {∑ i ∈ t, Finsupp.single i 1} := by
rw [support_esymm'']
congr
funext
exact Finsupp.support_single_ne_zero _ one_ne_zero
theorem support_esymm [DecidableEq σ] [Nontrivial R] (n : ℕ) : (esymm σ R n).support =
(powersetCard n (univ : Finset σ)).image fun t => ∑ i ∈ t, Finsupp.single i 1 := by
rw [support_esymm']
exact biUnion_singleton
theorem degrees_esymm [Nontrivial R] {n : ℕ} (hpos : 0 < n) (hn : n ≤ Fintype.card σ) :
(esymm σ R n).degrees = (univ : Finset σ).val := by
classical
have :
(Finsupp.toMultiset ∘ fun t : Finset σ => ∑ i ∈ t, Finsupp.single i 1) = val := by
funext
simp
rw [degrees_def, support_esymm, sup_image, this]
have : ((powersetCard n univ).sup (fun (x : Finset σ) => x)).val
= sup (powersetCard n univ) val := by
refine comp_sup_eq_sup_comp _ ?_ ?_
· intros
simp only [union_val, sup_eq_union]
congr
· rfl
rw [← this]
obtain ⟨k, rfl⟩ := Nat.exists_eq_succ_of_ne_zero hpos.ne'
simpa using powersetCard_sup _ _ (Nat.lt_of_succ_le hn)
end ElementarySymmetric
section CompleteHomogeneousSymmetric
open Finset Multiset Sym
variable [DecidableEq σ] [DecidableEq τ]
/-- The `n`th complete homogeneous symmetric `MvPolynomial σ R`.
It is the sum over all the degree n monomials in `MvPolynomial σ R`. -/
def hsymm (n : ℕ) : MvPolynomial σ R := ∑ s : Sym σ n, (s.1.map X).prod
/-- `hsymmPart` is the product of the symmetric polynomials `hsymm μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition. -/
def hsymmPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (hsymm σ R)).prod
@[simp]
theorem hsymm_zero : hsymm σ R 0 = 1 := by simp [hsymm, eq_nil_of_card_zero]
@[simp]
theorem hsymm_one : hsymm σ R 1 = ∑ i, X i := by
symm
apply Fintype.sum_equiv oneEquiv
simp only [oneEquiv_apply, Multiset.map_singleton, Multiset.prod_singleton, implies_true]
theorem hsymmPart_zero : hsymmPart σ R (.indiscrete 0) = 1 := by simp [hsymmPart]
@[simp]
theorem hsymmPart_indiscrete (n : ℕ) : hsymmPart σ R (.indiscrete n) = hsymm σ R n := by
cases n <;> simp [hsymmPart]
theorem map_hsymm (n : ℕ) (f : R →+* S) : map f (hsymm σ R n) = hsymm σ S n := by
simp [hsymm, ← Multiset.prod_hom']
theorem rename_hsymm (n : ℕ) (e : σ ≃ τ) : rename e (hsymm σ R n) = hsymm τ R n := by
simp_rw [hsymm, map_sum, ← prod_hom', rename_X]
apply Fintype.sum_equiv (equivCongr e)
simp
theorem hsymm_isSymmetric (n : ℕ) : IsSymmetric (hsymm σ R n) := rename_hsymm _ _ n
end CompleteHomogeneousSymmetric
section PowerSum
open Finset
/-- The degree-`n` power sum symmetric `MvPolynomial σ R`.
It is the sum over all the `n`-th powers of the variables. -/
def psum (n : ℕ) : MvPolynomial σ R := ∑ i, X i ^ n
/-- `psumPart` is the product of the symmetric polynomials `psum μᵢ`,
where `μ = (μ₁, μ₂, ...)` is a partition. -/
def psumPart {n : ℕ} (μ : n.Partition) : MvPolynomial σ R := (μ.parts.map (psum σ R)).prod
@[simp]
theorem psum_zero : psum σ R 0 = Fintype.card σ := by simp [psum]
@[simp]
theorem psum_one : psum σ R 1 = ∑ i, X i := by simp [psum]
@[simp]
theorem psumPart_zero : psumPart σ R (.indiscrete 0) = 1 := by simp [psumPart]
@[simp]
theorem psumPart_indiscrete {n : ℕ} (npos : n ≠ 0) :
psumPart σ R (.indiscrete n) = psum σ R n := by simp [psumPart, npos]
@[simp]
theorem rename_psum (n : ℕ) (e : σ ≃ τ) : rename e (psum σ R n) = psum τ R n := by
simp_rw [psum, map_sum, map_pow, rename_X, e.sum_comp (X · ^ n)]
theorem psum_isSymmetric (n : ℕ) : IsSymmetric (psum σ R n) := rename_psum _ _ n
end PowerSum
section MonomialSymmetric
variable [DecidableEq σ] [DecidableEq τ] {n : ℕ}
/-- The monomial symmetric `MvPolynomial σ R` with exponent set μ.
It is the sum over all the monomials in `MvPolynomial σ R` such that
the multiset of exponents is equal to the multiset of parts of μ. -/
def msymm (μ : n.Partition) : MvPolynomial σ R :=
∑ s : {a : Sym σ n // .ofSym a = μ}, (s.1.1.map X).prod
@[simp]
theorem msymm_zero : msymm σ R (.indiscrete 0) = 1 := by
rw [msymm, Fintype.sum_subsingleton _ ⟨(Sym.nil : Sym σ 0), rfl⟩]
simp
@[simp]
theorem msymm_one : msymm σ R (.indiscrete 1) = ∑ i, X i := by
have : (fun (x : Sym σ 1) ↦ x ∈ Set.univ) =
(fun x ↦ Nat.Partition.ofSym x = Nat.Partition.indiscrete 1) := by
simp_rw [Set.mem_univ, Nat.Partition.ofSym_one]
symm
rw [Fintype.sum_equiv (Equiv.trans Sym.oneEquiv (Equiv.Set.univ (Sym σ 1)).symm)
_ (fun s ↦ (s.1.1.map X).prod)]
· apply Fintype.sum_equiv (Equiv.subtypeEquivProp this)
intro x
congr
· intro x
rw [← Multiset.prod_singleton (X x), ← Multiset.map_singleton]
congr
@[simp]
theorem rename_msymm (μ : n.Partition) (e : σ ≃ τ) :
rename e (msymm σ R μ) = msymm τ R μ := by
rw [msymm, map_sum]
apply Fintype.sum_equiv (Nat.Partition.ofSymShapeEquiv μ e)
intro
rw [← Multiset.prod_hom, Multiset.map_map, Nat.Partition.ofSymShapeEquiv]
simp
theorem msymm_isSymmetric (μ : n.Partition) : IsSymmetric (msymm σ R μ) :=
rename_msymm _ _ μ
end MonomialSymmetric
end MvPolynomial
|
test_intro_rw.v
|
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat.
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Lemma test_dup1 : forall n : nat, odd n.
Proof. move=> /[dup] m n; suff: odd n by []. Abort.
Lemma test_dup2 : let n := 1 in False.
Proof. move=> /[dup] m n; have : m = n := erefl. Abort.
Lemma test_swap1 : forall (n : nat) (b : bool), odd n = b.
Proof. move=> /[swap] b n; suff: odd n = b by []. Abort.
Lemma test_swap1 : let n := 1 in let b := true in False.
Proof. move=> /[swap] b n; have : odd n = b := erefl. Abort.
Lemma test_apply A B : forall (f : A -> B) (a : A), False.
Proof.
move=> /[apply] b.
Check (b : B).
Abort.
Lemma test_swap_plus P Q : P -> Q -> False.
Proof.
move=> + /[dup] q.
suff: P -> Q -> False by [].
Abort.
Lemma test_dup_plus2 P : P -> let x := 0 in False.
Proof.
move=> + /[dup] y.
suff: P -> let x := 0 in False by [].
Abort.
Lemma test_swap_plus P Q R : P -> Q -> R -> False.
Proof.
move=> + /[swap].
suff: P -> R -> Q -> False by [].
Abort.
Lemma test_swap_plus2 P : P -> let x := 0 in let y := 1 in False.
Proof.
move=> + /[swap].
suff: P -> let y := 1 in let x := 0 in False by [].
Abort.
|
Stalks.lean
|
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Justus Springer
-/
import Mathlib.Topology.Category.TopCat.OpenNhds
import Mathlib.Topology.Sheaves.SheafCondition.UniqueGluing
/-!
# Stalks
For a presheaf `F` on a topological space `X`, valued in some category `C`, the *stalk* of `F`
at the point `x : X` is defined as the colimit of the composition of the inclusion of categories
`(OpenNhds x)ᵒᵖ ⥤ (Opens X)ᵒᵖ` and the functor `F : (Opens X)ᵒᵖ ⥤ C`.
For an open neighborhood `U` of `x`, we define the map `F.germ x : F.obj (op U) ⟶ F.stalk x` as the
canonical morphism into this colimit.
Taking stalks is functorial: For every point `x : X` we define a functor `stalkFunctor C x`,
sending presheaves on `X` to objects of `C`. Furthermore, for a map `f : X ⟶ Y` between
topological spaces, we define `stalkPushforward` as the induced map on the stalks
`(f _* ℱ).stalk (f x) ⟶ ℱ.stalk x`.
Some lemmas about stalks and germs only hold for certain classes of concrete categories. A basic
property of forgetful functors of categories of algebraic structures (like `MonCat`,
`CommRingCat`,...) is that they preserve filtered colimits. Since stalks are filtered colimits,
this ensures that the stalks of presheaves valued in these categories behave exactly as for
`Type`-valued presheaves. For example, in `germ_exist` we prove that in such a category, every
element of the stalk is the germ of a section.
Furthermore, if we require the forgetful functor to reflect isomorphisms and preserve limits (as
is the case for most algebraic structures), we have access to the unique gluing API and can prove
further properties. Most notably, in `is_iso_iff_stalk_functor_map_iso`, we prove that in such
a category, a morphism of sheaves is an isomorphism if and only if all of its stalk maps are
isomorphisms.
See also the definition of "algebraic structures" in the stacks project:
https://stacks.math.columbia.edu/tag/007L
-/
assert_not_exists OrderedCommMonoid
noncomputable section
universe v u v' u'
open CategoryTheory
open TopCat
open CategoryTheory.Limits CategoryTheory.Functor
open TopologicalSpace Topology
open Opposite
open scoped AlgebraicGeometry
variable {C : Type u} [Category.{v} C]
variable [HasColimits.{v} C]
variable {X Y Z : TopCat.{v}}
namespace TopCat.Presheaf
variable (C) in
/-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/
def stalkFunctor (x : X) : X.Presheaf C ⥤ C :=
(whiskeringLeft _ _ C).obj (OpenNhds.inclusion x).op ⋙ colim
/-- The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor
nbhds x ⥤ opens F.X ⥤ C
-/
def stalk (ℱ : X.Presheaf C) (x : X) : C :=
(stalkFunctor C x).obj ℱ
-- -- colimit ((open_nhds.inclusion x).op ⋙ ℱ)
@[simp]
theorem stalkFunctor_obj (ℱ : X.Presheaf C) (x : X) : (stalkFunctor C x).obj ℱ = ℱ.stalk x :=
rfl
/-- The germ of a section of a presheaf over an open at a point of that open.
-/
def germ (F : X.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) : F.obj (op U) ⟶ stalk F x :=
colimit.ι ((OpenNhds.inclusion x).op ⋙ F) (op ⟨U, hx⟩)
/-- The germ of a global section of a presheaf at a point. -/
def Γgerm (F : X.Presheaf C) (x : X) : F.obj (op ⊤) ⟶ stalk F x :=
F.germ ⊤ x True.intro
@[reassoc]
theorem germ_res (F : X.Presheaf C) {U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) :
F.map i.op ≫ F.germ U x hx = F.germ V x (i.le hx) :=
let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.le hx⟩ := i
colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op
/-- A variant of `germ_res` with `op V ⟶ op U`
so that the LHS is more general and simp fires more easier. -/
@[reassoc (attr := simp)]
theorem germ_res' (F : X.Presheaf C) {U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) :
F.map i ≫ F.germ U x hx = F.germ V x (i.unop.le hx) :=
let i' : (⟨U, hx⟩ : OpenNhds x) ⟶ ⟨V, i.unop.le hx⟩ := i.unop
colimit.w ((OpenNhds.inclusion x).op ⋙ F) i'.op
@[reassoc]
lemma map_germ_eq_Γgerm (F : X.Presheaf C) {U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) :
F.map i.op ≫ F.germ U x hx = F.Γgerm x :=
germ_res F i x hx
variable {FC : C → C → Type*} {CC : C → Type*} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)]
theorem germ_res_apply (F : X.Presheaf C)
{U V : Opens X} (i : U ⟶ V) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i.op s) = F.germ V x (i.le hx) s := by
rw [← ConcreteCategory.comp_apply, germ_res]
theorem germ_res_apply' (F : X.Presheaf C)
{U V : Opens X} (i : op V ⟶ op U) (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i s) = F.germ V x (i.unop.le hx) s := by
rw [← ConcreteCategory.comp_apply, germ_res']
lemma Γgerm_res_apply (F : X.Presheaf C)
{U : Opens X} {i : U ⟶ ⊤} (x : X) (hx : x ∈ U) [ConcreteCategory C FC] (s) :
F.germ U x hx (F.map i.op s) = F.Γgerm x s :=
F.germ_res_apply i x hx s
/-- A morphism from the stalk of `F` at `x` to some object `Y` is completely determined by its
composition with the `germ` morphisms.
-/
@[ext]
theorem stalk_hom_ext (F : X.Presheaf C) {x} {Y : C} {f₁ f₂ : F.stalk x ⟶ Y}
(ih : ∀ (U : Opens X) (hxU : x ∈ U), F.germ U x hxU ≫ f₁ = F.germ U x hxU ≫ f₂) : f₁ = f₂ :=
colimit.hom_ext fun U => by
induction U with | op U => obtain ⟨U, hxU⟩ := U; exact ih U hxU
@[reassoc (attr := simp)]
theorem stalkFunctor_map_germ {F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) :
F.germ U x hx ≫ (stalkFunctor C x).map f = f.app (op U) ≫ G.germ U x hx :=
colimit.ι_map (whiskerLeft (OpenNhds.inclusion x).op f) (op ⟨U, hx⟩)
theorem stalkFunctor_map_germ_apply [ConcreteCategory C FC]
{F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) (s) :
(stalkFunctor C x).map f (F.germ U x hx s) = G.germ U x hx (f.app (op U) s) := by
rw [← ConcreteCategory.comp_apply, ← stalkFunctor_map_germ, ConcreteCategory.comp_apply]
rfl
-- a variant of `stalkFunctor_map_germ_apply` that makes simpNF happy.
@[simp]
theorem stalkFunctor_map_germ_apply' [ConcreteCategory C FC]
{F G : X.Presheaf C} (U : Opens X) (x : X) (hx : x ∈ U) (f : F ⟶ G) (s) :
DFunLike.coe (F := ToHom (F.stalk x) (G.stalk x))
(ConcreteCategory.hom ((stalkFunctor C x).map f)) (F.germ U x hx s) =
G.germ U x hx (f.app (op U) s) :=
stalkFunctor_map_germ_apply U x hx f s
variable (C)
/-- For a presheaf `F` on a space `X`, a continuous map `f : X ⟶ Y` induces a morphisms between the
stalk of `f _ * F` at `f x` and the stalk of `F` at `x`.
-/
def stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) (x : X) : (f _* F).stalk (f x) ⟶ F.stalk x := by
-- This is a hack; Lean doesn't like to elaborate the term written directly.
refine ?_ ≫ colimit.pre _ (OpenNhds.map f x).op
exact colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) F)
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem stalkPushforward_germ (f : X ⟶ Y) (F : X.Presheaf C) (U : Opens Y)
(x : X) (hx : f x ∈ U) :
(f _* F).germ U (f x) hx ≫ F.stalkPushforward C f x = F.germ ((Opens.map f).obj U) x hx := by
simp [germ, stalkPushforward]
-- Here are two other potential solutions, suggested by @fpvandoorn at
-- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240>
-- However, I can't get the subsequent two proofs to work with either one.
-- def stalkPushforward'' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) :
-- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=
-- colim.map ((Functor.associator _ _ _).inv ≫
-- whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) ≫
-- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op
-- def stalkPushforward''' (f : X ⟶ Y) (ℱ : X.Presheaf C) (x : X) :
-- (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=
-- (colim.map (whiskerRight (NatTrans.op (OpenNhds.inclusionMapIso f x).inv) ℱ) :
-- colim.obj ((OpenNhds.inclusion (f x) ⋙ Opens.map f).op ⋙ ℱ) ⟶ _) ≫
-- colimit.pre ((OpenNhds.inclusion x).op ⋙ ℱ) (OpenNhds.map f x).op
namespace stalkPushforward
@[simp]
theorem id (ℱ : X.Presheaf C) (x : X) :
ℱ.stalkPushforward C (𝟙 X) x = (stalkFunctor C x).map (Pushforward.id ℱ).hom := by
ext
simp only [stalkPushforward, germ, colim_map, ι_colimMap_assoc, whiskerRight_app]
erw [CategoryTheory.Functor.map_id]
simp [stalkFunctor]
@[simp]
theorem comp (ℱ : X.Presheaf C) (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) :
ℱ.stalkPushforward C (f ≫ g) x =
(f _* ℱ).stalkPushforward C g (f x) ≫ ℱ.stalkPushforward C f x := by
ext
simp [germ, stalkPushforward]
theorem stalkPushforward_iso_of_isInducing {f : X ⟶ Y} (hf : IsInducing f)
(F : X.Presheaf C) (x : X) : IsIso (F.stalkPushforward _ f x) := by
haveI := Functor.initial_of_adjunction (hf.adjunctionNhds x)
convert (Functor.Final.colimitIso (OpenNhds.map f x).op ((OpenNhds.inclusion x).op ⋙ F)).isIso_hom
refine stalk_hom_ext _ fun U hU ↦ (stalkPushforward_germ _ f F _ x hU).trans ?_
symm
exact colimit.ι_pre ((OpenNhds.inclusion x).op ⋙ F) (OpenNhds.map f x).op _
end stalkPushforward
section stalkPullback
/-- The morphism `ℱ_{f x} ⟶ (f⁻¹ℱ)ₓ` that factors through `(f_*f⁻¹ℱ)_{f x}`. -/
def stalkPullbackHom (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) :
F.stalk (f x) ⟶ ((pullback C f).obj F).stalk x :=
(stalkFunctor _ (f x)).map ((pushforwardPullbackAdjunction C f).unit.app F) ≫
stalkPushforward _ _ _ x
@[reassoc (attr := simp)]
lemma germ_stalkPullbackHom
(f : X ⟶ Y) (F : Y.Presheaf C) (x : X) (U : Opens Y) (hU : f x ∈ U) :
F.germ U (f x) hU ≫ stalkPullbackHom C f F x =
((pushforwardPullbackAdjunction C f).unit.app F).app _ ≫
((pullback C f).obj F).germ ((Opens.map f).obj U) x hU := by
simp [stalkPullbackHom, germ, stalkFunctor, stalkPushforward]
/-- The morphism `(f⁻¹ℱ)(U) ⟶ ℱ_{f(x)}` for some `U ∋ x`. -/
def germToPullbackStalk (f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) :
((pullback C f).obj F).obj (op U) ⟶ F.stalk (f x) :=
((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F (op U)).desc
{ pt := F.stalk ((f : X → Y) (x : X))
ι :=
{ app := fun V => F.germ _ (f x) (V.hom.unop.le hx)
naturality := fun _ _ i => by simp } }
variable {C} in
@[ext]
lemma pullback_obj_obj_ext {Z : C} {f : X ⟶ Y} {F : Y.Presheaf C} (U : (Opens X)ᵒᵖ)
{φ ψ : ((pullback C f).obj F).obj U ⟶ Z}
(h : ∀ (V : Opens Y) (hV : U.unop ≤ (Opens.map f).obj V),
((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫
((pullback C f).obj F).map (homOfLE hV).op ≫ φ =
((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫
((pullback C f).obj F).map (homOfLE hV).op ≫ ψ) : φ = ψ := by
obtain ⟨U⟩ := U
apply ((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F _).hom_ext
rintro ⟨⟨V⟩, ⟨⟩, ⟨b⟩⟩
simpa [pushforwardPullbackAdjunction, Functor.lanAdjunction_unit]
using h V (leOfHom b)
@[reassoc (attr := simp)]
lemma pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk
(f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) (V : Opens Y)
(hV : U ≤ (Opens.map f).obj V) :
((pushforwardPullbackAdjunction C f).unit.app F).app (op V) ≫
((pullback C f).obj F).map (homOfLE hV).op ≫ germToPullbackStalk C f F U x hx =
F.germ _ (f x) (hV hx) := by
simpa [pushforwardPullbackAdjunction] using
((Opens.map f).op.isPointwiseLeftKanExtensionLeftKanExtensionUnit F (op U)).fac _
(CostructuredArrow.mk (homOfLE hV).op)
@[reassoc (attr := simp)]
lemma germToPullbackStalk_stalkPullbackHom
(f : X ⟶ Y) (F : Y.Presheaf C) (U : Opens X) (x : X) (hx : x ∈ U) :
germToPullbackStalk C f F U x hx ≫ stalkPullbackHom C f F x =
((pullback C f).obj F).germ _ x hx := by
ext V hV
dsimp
simp only [pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk_assoc,
germ_stalkPullbackHom, germ_res]
@[reassoc (attr := simp)]
lemma pushforwardPullbackAdjunction_unit_app_app_germToPullbackStalk
(f : X ⟶ Y) (F : Y.Presheaf C) (V : (Opens Y)ᵒᵖ) (x : X) (hx : f x ∈ V.unop) :
((pushforwardPullbackAdjunction C f).unit.app F).app V ≫ germToPullbackStalk C f F _ x hx =
F.germ _ (f x) hx := by
simpa using pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk
C f F ((Opens.map f).obj V.unop) x hx V.unop (by rfl)
/-- The morphism `(f⁻¹ℱ)ₓ ⟶ ℱ_{f(x)}`. -/
def stalkPullbackInv (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) :
((pullback C f).obj F).stalk x ⟶ F.stalk (f x) :=
colimit.desc ((OpenNhds.inclusion x).op ⋙ (Presheaf.pullback C f).obj F)
{ pt := F.stalk (f x)
ι :=
{ app := fun U => F.germToPullbackStalk _ f (unop U).1 x (unop U).2
naturality := fun U V i => by
dsimp
ext W hW
dsimp [OpenNhds.inclusion]
rw [Category.comp_id, ← Functor.map_comp_assoc,
pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk]
erw [pushforwardPullbackAdjunction_unit_pullback_map_germToPullbackStalk] } }
@[reassoc (attr := simp)]
lemma germ_stalkPullbackInv (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) (V : Opens X) (hV : x ∈ V) :
((pullback C f).obj F).germ _ x hV ≫ stalkPullbackInv C f F x =
F.germToPullbackStalk _ f V x hV := by
apply colimit.ι_desc
/-- The isomorphism `ℱ_{f(x)} ≅ (f⁻¹ℱ)ₓ`. -/
def stalkPullbackIso (f : X ⟶ Y) (F : Y.Presheaf C) (x : X) :
F.stalk (f x) ≅ ((pullback C f).obj F).stalk x where
hom := stalkPullbackHom _ _ _ _
inv := stalkPullbackInv _ _ _ _
hom_inv_id := by
ext U hU
dsimp
rw [germ_stalkPullbackHom_assoc, germ_stalkPullbackInv, Category.comp_id,
pushforwardPullbackAdjunction_unit_app_app_germToPullbackStalk]
inv_hom_id := by
ext V hV
dsimp
rw [germ_stalkPullbackInv_assoc, Category.comp_id, germToPullbackStalk_stalkPullbackHom]
end stalkPullback
section stalkSpecializes
variable {C}
/-- If `x` specializes to `y`, then there is a natural map `F.stalk y ⟶ F.stalk x`. -/
noncomputable def stalkSpecializes (F : X.Presheaf C) {x y : X} (h : x ⤳ y) :
F.stalk y ⟶ F.stalk x := by
refine colimit.desc _ ⟨_, fun U => ?_, ?_⟩
· exact
colimit.ι ((OpenNhds.inclusion x).op ⋙ F)
(op ⟨(unop U).1, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 :)⟩)
· intro U V i
dsimp
rw [Category.comp_id]
let U' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop U).1.2 (unop U).2 :)⟩
let V' : OpenNhds x := ⟨_, (specializes_iff_forall_open.mp h _ (unop V).1.2 (unop V).2 :)⟩
exact colimit.w ((OpenNhds.inclusion x).op ⋙ F) (show V' ⟶ U' from i.unop).op
@[reassoc (attr := simp), elementwise nosimp]
theorem germ_stalkSpecializes (F : X.Presheaf C)
{U : Opens X} {y : X} (hy : y ∈ U) {x : X} (h : x ⤳ y) :
F.germ U y hy ≫ F.stalkSpecializes h = F.germ U x (h.mem_open U.isOpen hy) :=
colimit.ι_desc _ _
@[simp]
theorem stalkSpecializes_refl {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat}
(F : X.Presheaf C) (x : X) : F.stalkSpecializes (specializes_refl x) = 𝟙 _ := by
ext
simp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem stalkSpecializes_comp {C : Type*} [Category C] [Limits.HasColimits C] {X : TopCat}
(F : X.Presheaf C) {x y z : X} (h : x ⤳ y) (h' : y ⤳ z) :
F.stalkSpecializes h' ≫ F.stalkSpecializes h = F.stalkSpecializes (h.trans h') := by
ext
simp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem stalkSpecializes_stalkFunctor_map {F G : X.Presheaf C} (f : F ⟶ G) {x y : X} (h : x ⤳ y) :
F.stalkSpecializes h ≫ (stalkFunctor C x).map f =
(stalkFunctor C y).map f ≫ G.stalkSpecializes h := by
change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _)
ext; delta stalkFunctor; simpa [stalkSpecializes] using by rfl
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem stalkSpecializes_stalkPushforward (f : X ⟶ Y) (F : X.Presheaf C) {x y : X} (h : x ⤳ y) :
(f _* F).stalkSpecializes (f.hom.map_specializes h) ≫ F.stalkPushforward _ f x =
F.stalkPushforward _ f y ≫ F.stalkSpecializes h := by
change (_ : colimit _ ⟶ _) = (_ : colimit _ ⟶ _)
ext; delta stalkPushforward
simp only [stalkSpecializes, colimit.ι_desc_assoc, colimit.ι_map_assoc, colimit.ι_pre,
Category.assoc, colimit.pre_desc, colimit.ι_desc]
rfl
/-- The stalks are isomorphic on inseparable points -/
@[simps]
def stalkCongr {X : TopCat} {C : Type*} [Category C] [HasColimits C] (F : X.Presheaf C) {x y : X}
(e : Inseparable x y) : F.stalk x ≅ F.stalk y :=
⟨F.stalkSpecializes e.ge, F.stalkSpecializes e.le, by simp, by simp⟩
end stalkSpecializes
section Concrete
variable {C} {CC : C → Type v} [∀ X Y, FunLike (FC X Y) (CC X) (CC Y)]
variable [instCC : ConcreteCategory.{v} C FC]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: @[ext] attribute only applies to structures or lemmas proving x = y
-- @[ext]
theorem germ_ext (F : X.Presheaf C) {U V : Opens X} {x : X} {hxU : x ∈ U} {hxV : x ∈ V}
(W : Opens X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V)
{sU : ToType (F.obj (op U))} {sV : ToType (F.obj (op V))}
(ih : F.map iWU.op sU = F.map iWV.op sV) :
F.germ _ x hxU sU = F.germ _ x hxV sV := by
rw [← F.germ_res iWU x hxW, ← F.germ_res iWV x hxW, ConcreteCategory.comp_apply,
ConcreteCategory.comp_apply, ih]
variable [PreservesFilteredColimits (forget C)]
/--
For presheaves valued in a concrete category whose forgetful functor preserves filtered colimits,
every element of the stalk is the germ of a section.
-/
theorem germ_exist (F : X.Presheaf C) (x : X) (t : ToType (stalk.{v, u} F x)) :
∃ (U : Opens X) (m : x ∈ U) (s : ToType (F.obj (op U))), F.germ _ x m s = t := by
obtain ⟨U, s, e⟩ :=
Types.jointly_surjective.{v, v} _ (isColimitOfPreserves (forget C) (colimit.isColimit _)) t
revert s e
induction U with | op U => ?_
obtain ⟨V, m⟩ := U
intro s e
exact ⟨V, m, s, e⟩
theorem germ_eq (F : X.Presheaf C) {U V : Opens X} (x : X) (mU : x ∈ U) (mV : x ∈ V)
(s : ToType (F.obj (op U))) (t : ToType (F.obj (op V)))
(h : F.germ U x mU s = F.germ V x mV t) :
∃ (W : Opens X) (_m : x ∈ W) (iU : W ⟶ U) (iV : W ⟶ V), F.map iU.op s = F.map iV.op t := by
obtain ⟨W, iU, iV, e⟩ :=
(Types.FilteredColimit.isColimit_eq_iff.{v, v} _
(isColimitOfPreserves (forget C) (colimit.isColimit ((OpenNhds.inclusion x).op ⋙ F)))).mp
h
exact ⟨(unop W).1, (unop W).2, iU.unop, iV.unop, e⟩
theorem stalkFunctor_map_injective_of_app_injective {F G : Presheaf C X} {f : F ⟶ G}
(h : ∀ U : Opens X, Function.Injective (f.app (op U))) (x : X) :
Function.Injective ((stalkFunctor C x).map f) := fun s t hst => by
rcases germ_exist F x s with ⟨U₁, hxU₁, s, rfl⟩
rcases germ_exist F x t with ⟨U₂, hxU₂, t, rfl⟩
rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply] at hst
obtain ⟨W, hxW, iWU₁, iWU₂, heq⟩ := G.germ_eq x hxU₁ hxU₂ _ _ hst
rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, ← f.naturality, ← f.naturality,
ConcreteCategory.comp_apply, ConcreteCategory.comp_apply] at heq
replace heq := h W heq
convert congr_arg (F.germ _ x hxW) heq using 1
exacts [(F.germ_res_apply iWU₁ x hxW s).symm, (F.germ_res_apply iWU₂ x hxW t).symm]
section IsBasis
variable {B : Set (Opens X)} (hB : Opens.IsBasis B)
include hB
lemma germ_exist_of_isBasis (F : X.Presheaf C) (x : X) (t : ToType (F.stalk x)) :
∃ (U : Opens X) (m : x ∈ U) (_ : U ∈ B) (s : ToType (F.obj (op U))), F.germ _ x m s = t := by
obtain ⟨U, hxU, s, rfl⟩ := F.germ_exist x t
obtain ⟨_, ⟨V, hV, rfl⟩, hxV, hVU⟩ := hB.exists_subset_of_mem_open hxU U.2
exact ⟨V, hxV, hV, F.map (homOfLE hVU).op s, by rw [← ConcreteCategory.comp_apply, F.germ_res']⟩
lemma germ_eq_of_isBasis (F : X.Presheaf C) {U V : Opens X} (x : X) (mU : x ∈ U) (mV : x ∈ V)
{s : ToType (F.obj (op U))} {t : ToType (F.obj (op V))}
(h : F.germ U x mU s = F.germ V x mV t) :
∃ (W : Opens X) (_ : x ∈ W) (_ : W ∈ B) (hWU : W ≤ U) (hWV : W ≤ V),
F.map (homOfLE hWU).op s = F.map (homOfLE hWV).op t := by
obtain ⟨W, hxW, hWU, hWV, e⟩ := F.germ_eq x mU mV _ _ h
obtain ⟨_, ⟨W', hW', rfl⟩, hxW', hW'W⟩ := hB.exists_subset_of_mem_open hxW W.2
refine ⟨W', hxW', hW', hW'W.trans hWU.le, hW'W.trans hWV.le, ?_⟩
simpa only [← ConcreteCategory.comp_apply, ← F.map_comp] using
DFunLike.congr_arg (ConcreteCategory.hom (F.map (homOfLE hW'W).op)) e
lemma stalkFunctor_map_injective_of_isBasis
{F G : X.Presheaf C} {α : F ⟶ G} (hα : ∀ U ∈ B, Function.Injective (α.app (op U))) (x : X) :
Function.Injective ((stalkFunctor _ x).map α) := by
intro s t hst
obtain ⟨U₁, hxU₁, hU₁, s, rfl⟩ := germ_exist_of_isBasis hB _ x s
obtain ⟨U₂, hxU₂, hU₂, t, rfl⟩ := germ_exist_of_isBasis hB _ x t
rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply] at hst
obtain ⟨W, hxW, hW, iWU₁, iWU₂, heq⟩ := germ_eq_of_isBasis hB _ _ hxU₁ hxU₂ hst
simp only [← α.naturality_apply, (hα W hW).eq_iff] at heq
simpa [germ_res_apply'] using congr(F.germ W x hxW $heq)
end IsBasis
variable [HasLimits C] [PreservesLimits (forget C)] [(forget C).ReflectsIsomorphisms]
/-- Let `F` be a sheaf valued in a concrete category, whose forgetful functor reflects isomorphisms,
preserves limits and filtered colimits. Then two sections who agree on every stalk must be equal.
-/
theorem section_ext (F : Sheaf C X) (U : Opens X) (s t : ToType (F.1.obj (op U)))
(h : ∀ (x : X) (hx : x ∈ U), F.presheaf.germ U x hx s = F.presheaf.germ U x hx t) : s = t := by
-- We use `germ_eq` and the axiom of choice, to pick for every point `x` a neighbourhood
-- `V x`, such that the restrictions of `s` and `t` to `V x` coincide.
choose V m i₁ i₂ heq using fun x : U => F.presheaf.germ_eq x.1 x.2 x.2 s t (h x.1 x.2)
-- Since `F` is a sheaf, we can prove the equality locally, if we can show that these
-- neighborhoods form a cover of `U`.
apply F.eq_of_locally_eq' V U i₁
· intro x hxU
simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe]
exact ⟨⟨x, hxU⟩, m ⟨x, hxU⟩⟩
· intro x
rw [heq, Subsingleton.elim (i₁ x) (i₂ x)]
/-
Note that the analogous statement for surjectivity is false: Surjectivity on stalks does not
imply surjectivity of the components of a sheaf morphism. However it does imply that the morphism
is an epi, but this fact is not yet formalized.
-/
theorem app_injective_of_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X} (f : F.1 ⟶ G)
(U : Opens X) (h : ∀ x ∈ U, Function.Injective ((stalkFunctor C x).map f)) :
Function.Injective (f.app (op U)) := fun s t hst =>
section_ext F _ _ _ fun x hx =>
h x hx <| by rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply, hst]
theorem app_injective_iff_stalkFunctor_map_injective {F : Sheaf C X} {G : Presheaf C X}
(f : F.1 ⟶ G) :
(∀ x : X, Function.Injective ((stalkFunctor C x).map f)) ↔
∀ U : Opens X, Function.Injective (f.app (op U)) :=
⟨fun h U => app_injective_of_stalkFunctor_map_injective f U fun x _ => h x,
stalkFunctor_map_injective_of_app_injective⟩
instance stalkFunctor_preserves_mono (x : X) :
Functor.PreservesMonomorphisms (Sheaf.forget.{v} C X ⋙ stalkFunctor C x) :=
⟨@fun _𝓐 _𝓑 f _ =>
ConcreteCategory.mono_of_injective _ <|
(app_injective_iff_stalkFunctor_map_injective f.1).mpr
(fun c =>
(ConcreteCategory.mono_iff_injective_of_preservesPullback (f.1.app (op c))).mp
((NatTrans.mono_iff_mono_app f.1).mp
(CategoryTheory.presheaf_mono_of_mono ..) <|
op c))
x⟩
include instCC in
theorem stalk_mono_of_mono {F G : Sheaf C X} (f : F ⟶ G) [Mono f] :
∀ x, Mono <| (stalkFunctor C x).map f.1 :=
fun x => Functor.map_mono (Sheaf.forget.{v} C X ⋙ stalkFunctor C x) f
include instCC in
theorem mono_of_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) [∀ x, Mono <| (stalkFunctor C x).map f.1] :
Mono f :=
(Sheaf.Hom.mono_iff_presheaf_mono _ _ _).mpr <|
(NatTrans.mono_iff_mono_app _).mpr fun U =>
(ConcreteCategory.mono_iff_injective_of_preservesPullback _).mpr <|
app_injective_of_stalkFunctor_map_injective f.1 U.unop fun _x _hx =>
(ConcreteCategory.mono_iff_injective_of_preservesPullback
((stalkFunctor C _).map f.val)).mp <| inferInstance
include instCC in
theorem mono_iff_stalk_mono {F G : Sheaf C X} (f : F ⟶ G) :
Mono f ↔ ∀ x, Mono ((stalkFunctor C x).map f.1) :=
⟨fun _ => stalk_mono_of_mono _, fun _ => mono_of_stalk_mono _⟩
/-- For surjectivity, we are given an arbitrary section `t` and need to find a preimage for it.
We claim that it suffices to find preimages *locally*. That is, for each `x : U` we construct
a neighborhood `V ≤ U` and a section `s : F.obj (op V))` such that `f.app (op V) s` and `t`
agree on `V`. -/
theorem app_surjective_of_injective_of_locally_surjective {F G : Sheaf C X} (f : F ⟶ G)
(U : Opens X) (hinj : ∀ x ∈ U, Function.Injective ((stalkFunctor C x).map f.1))
(hsurj : ∀ (t x) (_ : x ∈ U), ∃ (V : Opens X) (_ : x ∈ V) (iVU : V ⟶ U)
(s : ToType (F.1.obj (op V))), f.1.app (op V) s = G.1.map iVU.op t) :
Function.Surjective (f.1.app (op U)) := by
conv at hsurj =>
enter [t]
rw [Subtype.forall' (p := (· ∈ U))]
intro t
-- We use the axiom of choice to pick around each point `x` an open neighborhood `V` and a
-- preimage under `f` on `V`.
choose V mV iVU sf heq using hsurj t
-- These neighborhoods clearly cover all of `U`.
have V_cover : U ≤ iSup V := by
intro x hxU
simp only [Opens.coe_iSup, Set.mem_iUnion, SetLike.mem_coe]
exact ⟨⟨x, hxU⟩, mV ⟨x, hxU⟩⟩
suffices IsCompatible F.val V sf by
-- Since `F` is a sheaf, we can glue all the local preimages together to get a global preimage.
obtain ⟨s, s_spec, -⟩ := F.existsUnique_gluing' V U iVU V_cover sf this
· use s
apply G.eq_of_locally_eq' V U iVU V_cover
intro x
rw [← ConcreteCategory.comp_apply, ← f.1.naturality, ConcreteCategory.comp_apply, s_spec, heq]
intro x y
-- What's left to show here is that the sections `sf` are compatible, i.e. they agree on
-- the intersections `V x ⊓ V y`. We prove this by showing that all germs are equal.
apply section_ext
intro z hz
-- Here, we need to use injectivity of the stalk maps.
apply hinj z ((iVU x).le ((inf_le_left : V x ⊓ V y ≤ V x) hz))
dsimp only
rw [stalkFunctor_map_germ_apply, stalkFunctor_map_germ_apply]
simp_rw [← ConcreteCategory.comp_apply, f.1.naturality, ConcreteCategory.comp_apply, heq,
← ConcreteCategory.comp_apply, ← G.1.map_comp]
rfl
theorem app_surjective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X)
(h : ∀ x ∈ U, Function.Bijective ((stalkFunctor C x).map f.1)) :
Function.Surjective (f.1.app (op U)) := by
refine app_surjective_of_injective_of_locally_surjective f U (And.left <| h · ·) fun t x hx => ?_
-- Now we need to prove our initial claim: That we can find preimages of `t` locally.
-- Since `f` is surjective on stalks, we can find a preimage `s₀` of the germ of `t` at `x`
obtain ⟨s₀, hs₀⟩ := (h x hx).2 (G.presheaf.germ U x hx t)
-- ... and this preimage must come from some section `s₁` defined on some open neighborhood `V₁`
obtain ⟨V₁, hxV₁, s₁, hs₁⟩ := F.presheaf.germ_exist x s₀
subst hs₁; rename' hs₀ => hs₁
rw [stalkFunctor_map_germ_apply V₁ x hxV₁ f.1 s₁] at hs₁
-- Now, the germ of `f.app (op V₁) s₁` equals the germ of `t`, hence they must coincide on
-- some open neighborhood `V₂`.
obtain ⟨V₂, hxV₂, iV₂V₁, iV₂U, heq⟩ := G.presheaf.germ_eq x hxV₁ hx _ _ hs₁
-- The restriction of `s₁` to that neighborhood is our desired local preimage.
use V₂, hxV₂, iV₂U, F.1.map iV₂V₁.op s₁
rw [← ConcreteCategory.comp_apply, f.1.naturality, ConcreteCategory.comp_apply, heq]
theorem app_bijective_of_stalkFunctor_map_bijective {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X)
(h : ∀ x ∈ U, Function.Bijective ((stalkFunctor C x).map f.1)) :
Function.Bijective (f.1.app (op U)) :=
⟨app_injective_of_stalkFunctor_map_injective f.1 U fun x hx => (h x hx).1,
app_surjective_of_stalkFunctor_map_bijective f U h⟩
include instCC in
theorem app_isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) (U : Opens X)
[∀ x : U, IsIso ((stalkFunctor C x.val).map f.1)] : IsIso (f.1.app (op U)) := by
-- Since the forgetful functor of `C` reflects isomorphisms, it suffices to see that the
-- underlying map between types is an isomorphism, i.e. bijective.
suffices IsIso ((forget C).map (f.1.app (op U))) by
exact isIso_of_reflects_iso (f.1.app (op U)) (forget C)
rw [isIso_iff_bijective]
apply app_bijective_of_stalkFunctor_map_bijective
intro x hx
apply (isIso_iff_bijective _).mp
exact Functor.map_isIso (forget C) ((stalkFunctor C (⟨x, hx⟩ : U).1).map f.1)
include instCC in
-- Making this an instance would cause a loop in typeclass resolution with `Functor.map_isIso`
/-- Let `F` and `G` be sheaves valued in a concrete category, whose forgetful functor reflects
isomorphisms, preserves limits and filtered colimits. Then if the stalk maps of a morphism
`f : F ⟶ G` are all isomorphisms, `f` must be an isomorphism.
-/
theorem isIso_of_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G)
[∀ x : X, IsIso ((stalkFunctor C x).map f.1)] : IsIso f := by
-- Since the inclusion functor from sheaves to presheaves is fully faithful, it suffices to
-- show that `f`, as a morphism between _presheaves_, is an isomorphism.
suffices IsIso ((Sheaf.forget C X).map f) by exact isIso_of_fully_faithful (Sheaf.forget C X) f
-- We show that all components of `f` are isomorphisms.
suffices ∀ U : (Opens X)ᵒᵖ, IsIso (f.1.app U) by
exact @NatIso.isIso_of_isIso_app _ _ _ _ F.1 G.1 f.1 this
intro U; induction U
apply app_isIso_of_stalkFunctor_map_iso
include instCC in
/-- Let `F` and `G` be sheaves valued in a concrete category, whose forgetful functor reflects
isomorphisms, preserves limits and filtered colimits. Then a morphism `f : F ⟶ G` is an
isomorphism if and only if all of its stalk maps are isomorphisms.
-/
theorem isIso_iff_stalkFunctor_map_iso {F G : Sheaf C X} (f : F ⟶ G) :
IsIso f ↔ ∀ x : X, IsIso ((stalkFunctor C x).map f.1) :=
⟨fun _ x =>
@Functor.map_isIso _ _ _ _ _ _ (stalkFunctor C x) f.1 ((Sheaf.forget C X).map_isIso f),
fun _ => isIso_of_stalkFunctor_map_iso f⟩
end Concrete
end TopCat.Presheaf
|
Biproducts.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.Algebra.Category.Grp.Limits
import Mathlib.Tactic.CategoryTheory.Elementwise
/-!
# The category of abelian groups has finite biproducts
-/
open CategoryTheory
open CategoryTheory.Limits
universe w u
namespace AddCommGrp
-- As `AddCommGrp` is preadditive, and has all limits, it automatically has biproducts.
instance : HasBinaryBiproducts AddCommGrp :=
HasBinaryBiproducts.of_hasBinaryProducts
instance : HasFiniteBiproducts AddCommGrp :=
HasFiniteBiproducts.of_hasFiniteProducts
-- We now construct explicit limit data,
-- so we can compare the biproducts to the usual unbundled constructions.
/-- Construct limit data for a binary product in `AddCommGrp`, using
`AddCommGrp.of (G × H)`.
-/
@[simps! cone_pt isLimit_lift]
def binaryProductLimitCone (G H : AddCommGrp.{u}) : Limits.LimitCone (pair G H) where
cone := BinaryFan.mk (ofHom (AddMonoidHom.fst G H)) (ofHom (AddMonoidHom.snd G H))
isLimit := BinaryFan.IsLimit.mk _ (fun l r => ofHom (AddMonoidHom.prod l.hom r.hom))
(fun _ _ => rfl) (fun _ _ => rfl) (by cat_disch)
@[simp]
theorem binaryProductLimitCone_cone_π_app_left (G H : AddCommGrp.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.left⟩ = ofHom (AddMonoidHom.fst G H) :=
rfl
@[simp]
theorem binaryProductLimitCone_cone_π_app_right (G H : AddCommGrp.{u}) :
(binaryProductLimitCone G H).cone.π.app ⟨WalkingPair.right⟩ = ofHom (AddMonoidHom.snd G H) :=
rfl
/-- We verify that the biproduct in `AddCommGrp` is isomorphic to
the cartesian product of the underlying types:
-/
noncomputable def biprodIsoProd (G H : AddCommGrp.{u}) :
(G ⊞ H : AddCommGrp) ≅ AddCommGrp.of (G × H) :=
IsLimit.conePointUniqueUpToIso (BinaryBiproduct.isLimit G H) (binaryProductLimitCone G H).isLimit
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_fst (G H : AddCommGrp.{u}) :
(biprodIsoProd G H).inv ≫ biprod.fst = ofHom (AddMonoidHom.fst G H) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.left)
@[simp, elementwise]
theorem biprodIsoProd_inv_comp_snd (G H : AddCommGrp.{u}) :
(biprodIsoProd G H).inv ≫ biprod.snd = ofHom (AddMonoidHom.snd G H) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk WalkingPair.right)
namespace HasLimit
variable {J : Type w} (f : J → AddCommGrp.{max w u})
/-- The map from an arbitrary cone over an indexed family of abelian groups
to the cartesian product of those groups.
-/
@[simps!]
def lift (s : Fan f) : s.pt ⟶ AddCommGrp.of (∀ j, f j) :=
ofHom
{ toFun x j := s.π.app ⟨j⟩ x
map_zero' := by
simp only [Functor.const_obj_obj, map_zero]
rfl
map_add' x y := by
simp only [Functor.const_obj_obj, map_add]
rfl }
/-- Construct limit data for a product in `AddCommGrp`, using
`AddCommGrp.of (∀ j, F.obj j)`.
-/
@[simps]
def productLimitCone : Limits.LimitCone (Discrete.functor f) where
cone :=
{ pt := AddCommGrp.of (∀ j, f j)
π := Discrete.natTrans fun j => ofHom <| Pi.evalAddMonoidHom (fun j => f j) j.as }
isLimit :=
{ lift := lift.{_, u} f
fac := fun _ _ => rfl
uniq := fun s m w => by
ext x j
exact CategoryTheory.congr_fun (w ⟨j⟩) x }
end HasLimit
open HasLimit
variable {J : Type} [Finite J]
/-- We verify that the biproduct we've just defined is isomorphic to the `AddCommGrp` structure
on the dependent function type.
-/
noncomputable def biproductIsoPi (f : J → AddCommGrp.{u}) :
(⨁ f : AddCommGrp) ≅ AddCommGrp.of (∀ j, f j) :=
IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (productLimitCone f).isLimit
@[simp, elementwise]
theorem biproductIsoPi_inv_comp_π (f : J → AddCommGrp.{u}) (j : J) :
(biproductIsoPi f).inv ≫ biproduct.π f j = ofHom (Pi.evalAddMonoidHom (fun j => f j) j) :=
IsLimit.conePointUniqueUpToIso_inv_comp _ _ (Discrete.mk j)
end AddCommGrp
|
Sigma.lean
|
/-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yaël Dillies, Bhavik Mehta
-/
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Set.Sigma
import Mathlib.Order.CompleteLattice.Finset
/-!
# Finite sets in a sigma type
This file defines a few `Finset` constructions on `Σ i, α i`.
## Main declarations
* `Finset.sigma`: Given a finset `s` in `ι` and finsets `t i` in each `α i`, `s.sigma t` is the
finset of the dependent sum `Σ i, α i`
* `Finset.sigmaLift`: Lifts maps `α i → β i → Finset (γ i)` to a map
`Σ i, α i → Σ i, β i → Finset (Σ i, γ i)`.
## TODO
`Finset.sigmaLift` can be generalized to any alternative functor. But to make the generalization
worth it, we must first refactor the functor library so that the `alternative` instance for `Finset`
is computable and universe-polymorphic.
-/
open Function Multiset
variable {ι : Type*}
namespace Finset
section Sigma
variable {α : ι → Type*} {β : Type*} (s s₁ s₂ : Finset ι) (t t₁ t₂ : ∀ i, Finset (α i))
/-- `s.sigma t` is the finset of dependent pairs `⟨i, a⟩` such that `i ∈ s` and `a ∈ t i`. -/
protected def sigma : Finset (Σ i, α i) :=
⟨_, s.nodup.sigma fun i => (t i).nodup⟩
variable {s s₁ s₂ t t₁ t₂}
@[simp]
theorem mem_sigma {a : Σ i, α i} : a ∈ s.sigma t ↔ a.1 ∈ s ∧ a.2 ∈ t a.1 :=
Multiset.mem_sigma
@[simp, norm_cast]
theorem coe_sigma (s : Finset ι) (t : ∀ i, Finset (α i)) :
(s.sigma t : Set (Σ i, α i)) = (s : Set ι).sigma fun i ↦ (t i : Set (α i)) :=
Set.ext fun _ => mem_sigma
@[simp]
theorem sigma_nonempty : (s.sigma t).Nonempty ↔ ∃ i ∈ s, (t i).Nonempty := by simp [Finset.Nonempty]
@[aesop safe apply (rule_sets := [finsetNonempty])]
alias ⟨_, Aesop.sigma_nonempty_of_exists_nonempty⟩ := sigma_nonempty
@[simp]
theorem sigma_eq_empty : s.sigma t = ∅ ↔ ∀ i ∈ s, t i = ∅ := by
simp only [← not_nonempty_iff_eq_empty, sigma_nonempty, not_exists, not_and]
@[mono]
theorem sigma_mono (hs : s₁ ⊆ s₂) (ht : ∀ i, t₁ i ⊆ t₂ i) : s₁.sigma t₁ ⊆ s₂.sigma t₂ :=
fun ⟨i, _⟩ h =>
let ⟨hi, ha⟩ := mem_sigma.1 h
mem_sigma.2 ⟨hs hi, ht i ha⟩
theorem pairwiseDisjoint_map_sigmaMk :
(s : Set ι).PairwiseDisjoint fun i => (t i).map (Embedding.sigmaMk i) := by
intro i _ j _ hij
rw [Function.onFun, disjoint_left]
simp_rw [mem_map, Function.Embedding.sigmaMk_apply]
rintro _ ⟨y, _, rfl⟩ ⟨z, _, hz'⟩
exact hij (congr_arg Sigma.fst hz'.symm)
@[simp]
theorem disjiUnion_map_sigma_mk :
s.disjiUnion (fun i => (t i).map (Embedding.sigmaMk i)) pairwiseDisjoint_map_sigmaMk =
s.sigma t :=
rfl
theorem sigma_eq_biUnion [DecidableEq (Σ i, α i)] (s : Finset ι) (t : ∀ i, Finset (α i)) :
s.sigma t = s.biUnion fun i => (t i).map <| Embedding.sigmaMk i := by
ext ⟨x, y⟩
simp [and_left_comm]
variable (s t) (f : (Σ i, α i) → β)
theorem sup_sigma [SemilatticeSup β] [OrderBot β] :
(s.sigma t).sup f = s.sup fun i => (t i).sup fun b => f ⟨i, b⟩ := by
simp only [le_antisymm_iff, Finset.sup_le_iff, mem_sigma, and_imp, Sigma.forall]
exact
⟨fun i a hi ha => (le_sup hi).trans' <| le_sup (f := fun a => f ⟨i, a⟩) ha, fun i hi a ha =>
le_sup <| mem_sigma.2 ⟨hi, ha⟩⟩
theorem inf_sigma [SemilatticeInf β] [OrderTop β] :
(s.sigma t).inf f = s.inf fun i => (t i).inf fun b => f ⟨i, b⟩ :=
@sup_sigma _ _ βᵒᵈ _ _ _ _ _
theorem _root_.biSup_finsetSigma [CompleteLattice β] (s : Finset ι) (t : ∀ i, Finset (α i))
(f : Sigma α → β) : ⨆ ij ∈ s.sigma t, f ij = ⨆ (i ∈ s) (j ∈ t i), f ⟨i, j⟩ := by
simp_rw [← Finset.iSup_coe, Finset.coe_sigma, biSup_sigma]
theorem _root_.biSup_finsetSigma' [CompleteLattice β] (s : Finset ι) (t : ∀ i, Finset (α i))
(f : ∀ i, α i → β) : ⨆ (i ∈ s) (j ∈ t i), f i j = ⨆ ij ∈ s.sigma t, f ij.fst ij.snd :=
Eq.symm (biSup_finsetSigma _ _ _)
theorem _root_.biInf_finsetSigma [CompleteLattice β] (s : Finset ι) (t : ∀ i, Finset (α i))
(f : Sigma α → β) : ⨅ ij ∈ s.sigma t, f ij = ⨅ (i ∈ s) (j ∈ t i), f ⟨i, j⟩ :=
biSup_finsetSigma (β := βᵒᵈ) _ _ _
theorem _root_.biInf_finsetSigma' [CompleteLattice β] (s : Finset ι) (t : ∀ i, Finset (α i))
(f : ∀ i, α i → β) : ⨅ (i ∈ s) (j ∈ t i), f i j = ⨅ ij ∈ s.sigma t, f ij.fst ij.snd :=
Eq.symm (biInf_finsetSigma _ _ _)
theorem _root_.Set.biUnion_finsetSigma (s : Finset ι) (t : ∀ i, Finset (α i))
(f : Sigma α → Set β) : ⋃ ij ∈ s.sigma t, f ij = ⋃ i ∈ s, ⋃ j ∈ t i, f ⟨i, j⟩ :=
biSup_finsetSigma _ _ _
theorem _root_.Set.biUnion_finsetSigma' (s : Finset ι) (t : ∀ i, Finset (α i))
(f : ∀ i, α i → Set β) : ⋃ i ∈ s, ⋃ j ∈ t i, f i j = ⋃ ij ∈ s.sigma t, f ij.fst ij.snd :=
biSup_finsetSigma' _ _ _
theorem _root_.Set.biInter_finsetSigma (s : Finset ι) (t : ∀ i, Finset (α i))
(f : Sigma α → Set β) : ⋂ ij ∈ s.sigma t, f ij = ⋂ i ∈ s, ⋂ j ∈ t i, f ⟨i, j⟩ :=
biInf_finsetSigma _ _ _
theorem _root_.Set.biInter_finsetSigma' (s : Finset ι) (t : ∀ i, Finset (α i))
(f : ∀ i, α i → Set β) : ⋂ i ∈ s, ⋂ j ∈ t i, f i j = ⋂ ij ∈ s.sigma t, f ij.1 ij.2 :=
biInf_finsetSigma' _ _ _
end Sigma
section SigmaLift
variable {α β γ : ι → Type*} [DecidableEq ι]
/-- Lifts maps `α i → β i → Finset (γ i)` to a map `Σ i, α i → Σ i, β i → Finset (Σ i, γ i)`. -/
def sigmaLift (f : ∀ ⦃i⦄, α i → β i → Finset (γ i)) (a : Sigma α) (b : Sigma β) :
Finset (Sigma γ) :=
dite (a.1 = b.1) (fun h => (f (h ▸ a.2) b.2).map <| Embedding.sigmaMk _) fun _ => ∅
theorem mem_sigmaLift (f : ∀ ⦃i⦄, α i → β i → Finset (γ i)) (a : Sigma α) (b : Sigma β)
(x : Sigma γ) :
x ∈ sigmaLift f a b ↔ ∃ (ha : a.1 = x.1) (hb : b.1 = x.1), x.2 ∈ f (ha ▸ a.2) (hb ▸ b.2) := by
obtain ⟨⟨i, a⟩, j, b⟩ := a, b
obtain rfl | h := Decidable.eq_or_ne i j
· constructor
· simp_rw [sigmaLift]
simp only [dite_eq_ite, ite_true, mem_map, Embedding.sigmaMk_apply, forall_exists_index,
and_imp]
rintro x hx rfl
exact ⟨rfl, rfl, hx⟩
· rintro ⟨⟨⟩, ⟨⟩, hx⟩
rw [sigmaLift, dif_pos rfl, mem_map]
exact ⟨_, hx, by simp⟩
· rw [sigmaLift, dif_neg h]
refine iff_of_false (notMem_empty _) ?_
rintro ⟨⟨⟩, ⟨⟩, _⟩
exact h rfl
theorem mk_mem_sigmaLift (f : ∀ ⦃i⦄, α i → β i → Finset (γ i)) (i : ι) (a : α i) (b : β i)
(x : γ i) : (⟨i, x⟩ : Sigma γ) ∈ sigmaLift f ⟨i, a⟩ ⟨i, b⟩ ↔ x ∈ f a b := by
rw [sigmaLift, dif_pos rfl, mem_map]
refine ⟨?_, fun hx => ⟨_, hx, rfl⟩⟩
rintro ⟨x, hx, _, rfl⟩
exact hx
theorem notMem_sigmaLift_of_ne_left (f : ∀ ⦃i⦄, α i → β i → Finset (γ i)) (a : Sigma α)
(b : Sigma β) (x : Sigma γ) (h : a.1 ≠ x.1) : x ∉ sigmaLift f a b := by
rw [mem_sigmaLift]
exact fun H => h H.fst
@[deprecated (since := "2025-05-23")]
alias not_mem_sigmaLift_of_ne_left := notMem_sigmaLift_of_ne_left
theorem notMem_sigmaLift_of_ne_right (f : ∀ ⦃i⦄, α i → β i → Finset (γ i)) {a : Sigma α}
(b : Sigma β) {x : Sigma γ} (h : b.1 ≠ x.1) : x ∉ sigmaLift f a b := by
rw [mem_sigmaLift]
exact fun H => h H.snd.fst
@[deprecated (since := "2025-05-23")]
alias not_mem_sigmaLift_of_ne_right := notMem_sigmaLift_of_ne_right
variable {f g : ∀ ⦃i⦄, α i → β i → Finset (γ i)} {a : Σ i, α i} {b : Σ i, β i}
theorem sigmaLift_nonempty :
(sigmaLift f a b).Nonempty ↔ ∃ h : a.1 = b.1, (f (h ▸ a.2) b.2).Nonempty := by
simp_rw [nonempty_iff_ne_empty, sigmaLift]
split_ifs with h <;> simp [h]
theorem sigmaLift_eq_empty : sigmaLift f a b = ∅ ↔ ∀ h : a.1 = b.1, f (h ▸ a.2) b.2 = ∅ := by
simp_rw [sigmaLift]
split_ifs with h
· simp [h]
· simp [h]
theorem sigmaLift_mono
(h : ∀ ⦃i⦄ ⦃a : α i⦄ ⦃b : β i⦄, f a b ⊆ g a b) (a : Σ i, α i) (b : Σ i, β i) :
sigmaLift f a b ⊆ sigmaLift g a b := by
rintro x hx
rw [mem_sigmaLift] at hx ⊢
obtain ⟨ha, hb, hx⟩ := hx
exact ⟨ha, hb, h hx⟩
variable (f a b)
theorem card_sigmaLift :
(sigmaLift f a b).card = dite (a.1 = b.1) (fun h => (f (h ▸ a.2) b.2).card) fun _ => 0 := by
simp_rw [sigmaLift]
split_ifs with h <;> simp
end SigmaLift
end Finset
|
countalg.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop ssralg.
(*****************************************************************************)
(* The algebraic part of the algebraic hierarchy for countable types *)
(* *)
(* This file clones part of ssralg hierarchy for countable types; it does *)
(* not cover the left module / algebra interfaces, providing only *)
(* countNmodType == countable nmodType interface *)
(* countZmodType == countable zmodType interface *)
(* countPzSemiRingType == countable pzSemiRingType interface *)
(* countNzSemiRingType == countable nzSemiRingType interface *)
(* countPzRingType == countable pzRingType interface *)
(* countNzRingType == countable nzRingType interface *)
(* countComPzSemiRingType == countable comPzSemiRingType interface *)
(* countComNzSemiRingType == countable comNzSemiRingType interface *)
(* countComPzRingType == countable comPzRingType interface *)
(* countComNzRingType == countable comNzRingType interface *)
(* countUnitRingType == countable unitRingType interface *)
(* countComUnitRingType == countable comUnitRingType interface *)
(* countIdomainType == countable idomainType interface *)
(* countFieldType == countable fieldType interface *)
(* countDecFieldType == countable decFieldType interface *)
(* countClosedFieldType == countable closedFieldType interface *)
(* *)
(* This file provides constructions for both simple extension and algebraic *)
(* closure of countable fields. *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory CodeSeq.
Module CountRing.
Import GRing.Theory.
#[short(type="countNmodType")]
HB.structure Definition Nmodule := {M of GRing.Nmodule M & Countable M}.
#[short(type="countZmodType")]
HB.structure Definition Zmodule := {M of GRing.Zmodule M & Countable M}.
#[short(type="countPzSemiRingType")]
HB.structure Definition PzSemiRing := {R of GRing.PzSemiRing R & Countable R}.
#[short(type="countNzSemiRingType")]
HB.structure Definition NzSemiRing := {R of GRing.NzSemiRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing instead.")]
Notation SemiRing R := (NzSemiRing R) (only parsing).
Module SemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.sort instead.")]
Notation sort := (NzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.on instead.")]
Notation on R := (NzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzSemiRing.copy instead.")]
Notation copy T U := (NzSemiRing.copy T U) (only parsing).
End SemiRing.
#[short(type="countPzRingType")]
HB.structure Definition PzRing := {R of GRing.PzRing R & Countable R}.
#[short(type="countNzRingType")]
HB.structure Definition NzRing := {R of GRing.NzRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing instead.")]
Notation Ring R := (NzRing R) (only parsing).
Module Ring.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.sort instead.")]
Notation sort := (NzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.on instead.")]
Notation on R := (NzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.NzRing.copy instead.")]
Notation copy T U := (NzRing.copy T U) (only parsing).
End Ring.
#[short(type="countComPzSemiRingType")]
HB.structure Definition ComPzSemiRing :=
{R of GRing.ComPzSemiRing R & Countable R}.
#[short(type="countComNzSemiRingType")]
HB.structure Definition ComNzSemiRing :=
{R of GRing.ComNzSemiRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing instead.")]
Notation ComSemiRing R := (ComNzSemiRing R) (only parsing).
Module ComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.sort instead.")]
Notation sort := (ComNzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.on instead.")]
Notation on R := (ComNzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzSemiRing.copy instead.")]
Notation copy T U := (ComNzSemiRing.copy T U) (only parsing).
End ComSemiRing.
#[short(type="countComPzRingType")]
HB.structure Definition ComPzRing := {R of GRing.ComPzRing R & Countable R}.
#[short(type="countComNzRingType")]
HB.structure Definition ComNzRing := {R of GRing.ComNzRing R & Countable R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing instead.")]
Notation ComRing R := (ComNzRing R) (only parsing).
Module ComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.sort instead.")]
Notation sort := (ComNzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.on instead.")]
Notation on R := (ComNzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use CountRing.ComNzRing.copy instead.")]
Notation copy T U := (ComNzRing.copy T U) (only parsing).
End ComRing.
#[short(type="countUnitRingType")]
HB.structure Definition UnitRing := {R of GRing.UnitRing R & Countable R}.
#[short(type="countComUnitRingType")]
HB.structure Definition ComUnitRing := {R of GRing.ComUnitRing R & Countable R}.
#[short(type="countIdomainType")]
HB.structure Definition IntegralDomain :=
{R of GRing.IntegralDomain R & Countable R}.
#[short(type="countFieldType")]
HB.structure Definition Field := {R of GRing.Field R & Countable R}.
#[short(type="countDecFieldType")]
HB.structure Definition DecidableField :=
{R of GRing.DecidableField R & Countable R}.
#[short(type="countClosedFieldType")]
HB.structure Definition ClosedField := {R of GRing.ClosedField R & Countable R}.
Module ReguralExports.
HB.instance Definition _ (R : countType) := Countable.on R^o.
HB.instance Definition _ (R : countNmodType) := Nmodule.on R^o.
HB.instance Definition _ (R : countZmodType) := Zmodule.on R^o.
HB.instance Definition _ (R : countPzSemiRingType) := PzSemiRing.on R^o.
HB.instance Definition _ (R : countNzSemiRingType) := NzSemiRing.on R^o.
HB.instance Definition _ (R : countPzRingType) := PzRing.on R^o.
HB.instance Definition _ (R : countNzRingType) := NzRing.on R^o.
HB.instance Definition _ (R : countComPzSemiRingType) := ComPzSemiRing.on R^o.
HB.instance Definition _ (R : countComNzSemiRingType) := ComNzSemiRing.on R^o.
HB.instance Definition _ (R : countComPzRingType) := ComPzRing.on R^o.
HB.instance Definition _ (R : countComNzRingType) := ComNzRing.on R^o.
HB.instance Definition _ (R : countUnitRingType) := UnitRing.on R^o.
HB.instance Definition _ (R : countComUnitRingType) := ComUnitRing.on R^o.
HB.instance Definition _ (R : countIdomainType) := IntegralDomain.on R^o.
HB.instance Definition _ (R : countFieldType) := Field.on R^o.
HB.instance Definition _ (R : countDecFieldType) := DecidableField.on R^o.
HB.instance Definition _ (R : countClosedFieldType) := ClosedField.on R^o.
End ReguralExports.
HB.export ReguralExports.
End CountRing.
Import CountRing.
HB.reexport.
#[deprecated(since="mathcomp 2.4.0",
note="Use countNzSemiRingType instead.")]
Notation countSemiRingType := (countNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countNzRingType instead.")]
Notation countRingType := (countNzRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countComNzSemiRingType instead.")]
Notation countComSemiRingType := (countComNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use countComNzRingType instead.")]
Notation countComRingType := (countComNzRingType) (only parsing).
|
Superscript.lean
|
/-
Copyright (c) 2023 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Init
import Batteries.Tactic.Lint
/-!
# A parser for superscripts and subscripts
This is intended for use in local notations. Basic usage is:
```
local syntax:arg term:max superscript(term) : term
local macro_rules | `($a:term $b:superscript) => `($a ^ $b)
```
where `superscript(term)` indicates that it will parse a superscript, and the `$b:superscript`
antiquotation binds the `term` argument of the superscript. Given a notation like this,
the expression `2⁶⁴` parses and expands to `2 ^ 64`.
The superscript body is considered to be the longest contiguous sequence of superscript tokens and
whitespace, so no additional bracketing is required (unless you want to separate two superscripts).
However, note that Unicode has a rather restricted character set for superscripts and subscripts
(see `Mapping.superscript` and `Mapping.subscript` in this file), so you should not use this
parser for complex expressions.
-/
universe u
namespace Mathlib.Tactic
open Lean Parser PrettyPrinter Delaborator Std
namespace Superscript
instance : Hashable Char := ⟨fun c => hash c.1⟩
/-- A bidirectional character mapping. -/
structure Mapping where
/-- Map from "special" (e.g. superscript) characters to "normal" characters. -/
toNormal : Std.HashMap Char Char := {}
/-- Map from "normal" text to "special" (e.g. superscript) characters. -/
toSpecial : Std.HashMap Char Char := {}
deriving Inhabited
/-- Constructs a mapping (intended for compile time use). Panics on violated invariants. -/
def mkMapping (s₁ s₂ : String) : Mapping := Id.run do
let mut toNormal := {}
let mut toSpecial := {}
assert! s₁.length == s₂.length
for sp in s₁.toSubstring, nm in s₂ do
assert! !toNormal.contains sp
assert! !toSpecial.contains nm
toNormal := toNormal.insert sp nm
toSpecial := toSpecial.insert nm sp
pure { toNormal, toSpecial }
/-- A mapping from superscripts to and from regular text. -/
def Mapping.superscript := mkMapping
"⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖ𐞥ʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾꟴᴿᵀᵁⱽᵂᵝᵞᵟᵋᶿᶥᶹᵠᵡ⁺⁻⁼⁽⁾"
"0123456789abcdefghijklmnopqrstuvwxyzABDEGHIJKLMNOPQRTUVWβγδεθιυφχ+-=()"
/-- A mapping from subscripts to and from regular text. -/
def Mapping.subscript := mkMapping
"₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘꞯʀꜱᴛᴜᴠᴡʏᴢᵦᵧᵨᵩᵪ₊₋₌₍₎"
"0123456789aehijklmnoprstuvxABCDEFGHIJKLMNOPQRSTUVWYZβγρφχ+-=()"
/-- Collects runs of text satisfying `p` followed by whitespace. Fails if the first character does
not satisfy `p`. If `many` is true, it will parse 1 or more many whitespace-separated runs,
otherwise it will parse only 1. If successful, it passes the result to `k` as an array `(a, b, c)`
where `a..b` is a token and `b..c` is whitespace.
-/
partial def satisfyTokensFn (p : Char → Bool) (errorMsg : String) (many := true)
(k : Array (String.Pos × String.Pos × String.Pos) → ParserState → ParserState) :
ParserFn := fun c s =>
let start := s.pos
let s := takeWhile1Fn p errorMsg c s
if s.hasError then s else
let stop := s.pos
let s := whitespace c s
let toks := #[(start, stop, s.pos)]
if many then
let rec /-- Loop body of `satisfyTokensFn` -/
loop (toks) (s : ParserState) : ParserState :=
let start := s.pos
let s := takeWhileFn p c s
if s.pos == start then k toks s else
let stop := s.pos
let s := whitespace c s
let toks := toks.push (start, stop, s.pos)
loop toks s
loop toks s
else k toks s
variable {α : Type u} [Inhabited α] (as : Array α) (leftOfPartition : α → Bool) in
/-- Given a predicate `leftOfPartition` which is true for indexes `< i` and false for `≥ i`,
returns `i`, by binary search. -/
@[specialize]
def partitionPoint (lo := 0) (hi := as.size) : Nat :=
if lo < hi then
let m := (lo + hi)/2
let a := as[m]!
if leftOfPartition a then
partitionPoint (m+1) hi
else
partitionPoint lo m
else lo
termination_by hi - lo
/-- The core function for super/subscript parsing. It consists of three stages:
1. Parse a run of superscripted characters, skipping whitespace and stopping when we hit a
non-superscript character.
2. Un-superscript the text and pass the body to the inner parser (usually `term`).
3. Take the resulting `Syntax` object and align all the positions to fit back into the original
text (which as a side effect also rewrites all the substrings to be in subscript text).
If `many` is false, then whitespace (and comments) are not allowed inside the superscript.
-/
partial def scriptFnNoAntiquot (m : Mapping) (errorMsg : String) (p : ParserFn)
(many := true) : ParserFn := fun c s =>
let start := s.pos
satisfyTokensFn m.toNormal.contains errorMsg many c s (k := fun toks s => Id.run do
let input := c.input
let mut newStr := ""
-- This consists of a sorted array of `(from, to)` pairs, where indexes `from+i` in `newStr`
-- such that `from+i < from'` for the next element of the array, are mapped to `to+i`.
let mut aligns := #[((0 : String.Pos), start)]
for (start, stopTk, stopWs) in toks do
let mut pos := start
while pos < stopTk do
let c := input.get pos
let c' := m.toNormal[c]!
newStr := newStr.push c'
pos := pos + c
if c.utf8Size != c'.utf8Size then
aligns := aligns.push (newStr.endPos, pos)
newStr := newStr.push ' '
if stopWs.1 - stopTk.1 != 1 then
aligns := aligns.push (newStr.endPos, stopWs)
let ictx := mkInputContext newStr "<superscript>"
let s' := p.run ictx c.toParserModuleContext c.tokens (mkParserState newStr)
let rec /-- Applies the alignment mapping to a position. -/
align (pos : String.Pos) :=
let i := partitionPoint aligns (·.1 ≤ pos)
let (a, b) := aligns[i - 1]!
pos - a + b
let s := { s with pos := align s'.pos, errorMsg := s'.errorMsg }
if s.hasError then return s
let rec
/-- Applies the alignment mapping to a `Substring`. -/
alignSubstr : Substring → Substring
| ⟨_newStr, start, stop⟩ => ⟨input, align start, align stop⟩,
/-- Applies the alignment mapping to a `SourceInfo`. -/
alignInfo : SourceInfo → SourceInfo
| .original leading pos trailing endPos =>
-- Marking these as original breaks semantic highlighting,
-- marking them as canonical breaks the unused variables linter. :(
.original (alignSubstr leading) (align pos) (alignSubstr trailing) (align endPos)
| .synthetic pos endPos canonical =>
.synthetic (align pos) (align endPos) canonical
| .none => .none,
/-- Applies the alignment mapping to a `Syntax`. -/
alignSyntax : Syntax → Syntax
| .missing => .missing
| .node info kind args => .node (alignInfo info) kind (args.map alignSyntax)
| .atom info val =>
-- We have to preserve the unsubscripted `val` even though it breaks `Syntax.reprint`
-- because basic parsers like `num` read the `val` directly
.atom (alignInfo info) val
| .ident info rawVal val preresolved =>
.ident (alignInfo info) (alignSubstr rawVal) val preresolved
s.pushSyntax (alignSyntax s'.stxStack.back)
)
/-- The super/subscript parser.
* `m`: the character mapping
* `antiquotName`: the name to use for antiquotation bindings `$a:antiquotName`.
Note that the actual syntax kind bound will be the body kind (parsed by `p`), not `kind`.
* `errorMsg`: shown when the parser does not match
* `p`: the inner parser (usually `term`), to be called on the body of the superscript
* `many`: if false, whitespace is not allowed inside the superscript
* `kind`: the term will be wrapped in a node with this kind;
generally this is a name of the parser declaration itself.
-/
def scriptParser (m : Mapping) (antiquotName errorMsg : String) (p : Parser)
(many := true) (kind : SyntaxNodeKind := by exact decl_name%) : Parser :=
let tokens := "$" :: (m.toNormal.toArray.map (·.1.toString) |>.qsort (·<·)).toList
let antiquotP := mkAntiquot antiquotName `term (isPseudoKind := true)
let p := Superscript.scriptFnNoAntiquot m errorMsg p.fn many
node kind {
info.firstTokens := .tokens tokens
info.collectTokens := (tokens ++ ·)
fn := withAntiquotFn antiquotP.fn p (isCatAntiquot := true)
}
/-- Parenthesizer for the script parser. -/
def scriptParser.parenthesizer (k : SyntaxNodeKind) (p : Parenthesizer) : Parenthesizer :=
Parenthesizer.node.parenthesizer k p
/-- Map over the strings in a `Format`. -/
def _root_.Std.Format.mapStringsM {m} [Monad m] (f : Format) (f' : String → m String) : m Format :=
match f with
| .group f b => (.group · b) <$> Std.Format.mapStringsM f f'
| .tag t g => .tag t <$> Std.Format.mapStringsM g f'
| .append f g => .append <$> Std.Format.mapStringsM f f' <*> Std.Format.mapStringsM g f'
| .nest n f => .nest n <$> Std.Format.mapStringsM f f'
| .text s => .text <$> f' s
| .align _ | .line | .nil => pure f
/-- Formatter for the script parser. -/
def scriptParser.formatter (name : String) (m : Mapping) (k : SyntaxNodeKind) (p : Formatter) :
Formatter := do
let stack ← modifyGet fun s => (s.stack, {s with stack := #[]})
Formatter.node.formatter k p
let st ← get
let transformed : Except String _ := st.stack.mapM (·.mapStringsM fun s => do
let .some s := s.toList.mapM (m.toSpecial.insert ' ' ' ').get? | .error s
.ok ⟨s⟩)
match transformed with
| .error err =>
-- TODO: this only appears if the caller explicitly calls the pretty-printer
Lean.logErrorAt (← get).stxTrav.cur s!"Not a {name}: '{err}'"
set { st with stack := stack ++ st.stack }
| .ok newStack =>
set { st with stack := stack ++ newStack }
end Superscript
/--
The parser `superscript(term)` parses a superscript. Basic usage is:
```
local syntax:arg term:max superscript(term) : term
local macro_rules | `($a:term $b:superscript) => `($a ^ $b)
```
Given a notation like this, the expression `2⁶⁴` parses and expands to `2 ^ 64`.
Note that because of Unicode limitations, not many characters can actually be typed inside the
superscript, so this should not be used for complex expressions. Legal superscript characters:
```
⁰¹²³⁴⁵⁶⁷⁸⁹ᵃᵇᶜᵈᵉᶠᵍʰⁱʲᵏˡᵐⁿᵒᵖ𐞥ʳˢᵗᵘᵛʷˣʸᶻᴬᴮᴰᴱᴳᴴᴵᴶᴷᴸᴹᴺᴼᴾꟴᴿᵀᵁⱽᵂᵝᵞᵟᵋᶿᶥᶹᵠᵡ⁺⁻⁼⁽⁾
```
-/
def superscript (p : Parser) : Parser :=
Superscript.scriptParser .superscript "superscript" "expected superscript character" p
/-- Formatter for the superscript parser. -/
@[combinator_parenthesizer superscript]
def superscript.parenthesizer := Superscript.scriptParser.parenthesizer ``superscript
/-- Formatter for the superscript parser. -/
@[combinator_formatter superscript]
def superscript.formatter :=
Superscript.scriptParser.formatter "superscript" .superscript ``superscript
/-- Shorthand for `superscript(term)`.
This is needed because the initializer below does not always run, and if it has not run then
downstream parsers using the combinators will crash.
See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476
for some context. -/
@[term_parser]
def superscriptTerm := leading_parser (withAnonymousAntiquot := false) superscript termParser
initialize register_parser_alias superscript
/--
The parser `subscript(term)` parses a subscript. Basic usage is:
```
local syntax:arg term:max subscript(term) : term
local macro_rules | `($a:term $i:subscript) => `($a $i)
```
Given a notation like this, the expression `(a)ᵢ` parses and expands to `a i`. (Either parentheses
or a whitespace as in `a ᵢ` is required, because `aᵢ` is considered as an identifier.)
Note that because of Unicode limitations, not many characters can actually be typed inside the
subscript, so this should not be used for complex expressions. Legal subscript characters:
```
₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᴀʙᴄᴅᴇꜰɢʜɪᴊᴋʟᴍɴᴏᴘꞯʀꜱᴛᴜᴠᴡʏᴢᵦᵧᵨᵩᵪ₊₋₌₍₎
```
-/
def subscript (p : Parser) : Parser :=
Superscript.scriptParser .subscript "subscript" "expected subscript character" p
/-- Formatter for the subscript parser. -/
@[combinator_parenthesizer subscript]
def subscript.parenthesizer := Superscript.scriptParser.parenthesizer ``subscript
/-- Formatter for the subscript parser. -/
@[combinator_formatter subscript]
def subscript.formatter := Superscript.scriptParser.formatter "subscript" .subscript ``subscript
/-- Shorthand for `subscript(term)`.
This is needed because the initializer below does not always run, and if it has not run then
downstream parsers using the combinators will crash.
See https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Non-builtin.20parser.20aliases/near/365125476
for some context. -/
@[term_parser]
def subscriptTerm := leading_parser (withAnonymousAntiquot := false) subscript termParser
initialize register_parser_alias subscript
/-- Returns true if every character in `stx : Syntax` can be superscripted
(or subscripted). -/
private partial def Superscript.isValid (m : Mapping) : Syntax → Bool
| .node _ kind args => kind == hygieneInfoKind || (!(scripted kind) && args.all (isValid m))
| .atom _ s => valid s
| .ident _ _ s _ => valid s.toString
| _ => false
where
valid (s : String) : Bool :=
s.all ((m.toSpecial.insert ' ' ' ').contains ·)
scripted : SyntaxNodeKind → Bool :=
#[``subscript, ``superscript].contains
/-- Successfully delaborates only if the resulting expression can be superscripted.
See `Mapping.superscript` in this file for legal superscript characters. -/
def delabSuperscript : Delab := do
let stx ← delab
if Superscript.isValid .superscript stx.raw then pure stx else failure
/-- Successfully delaborates only if the resulting expression can be subscripted.
See `Mapping.subscript` in this file for legal subscript characters. -/
def delabSubscript : Delab := do
let stx ← delab
if Superscript.isValid .subscript stx.raw then pure stx else failure
end Mathlib.Tactic
|
Submodule.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Lie.Subalgebra
import Mathlib.LinearAlgebra.Finsupp.Span
/-!
# Lie submodules of a Lie algebra
In this file we define Lie submodules, we construct the lattice structure on Lie submodules and we
use it to define various important operations, notably the Lie span of a subset of a Lie module.
## Main definitions
* `LieSubmodule`
* `LieSubmodule.wellFounded_of_noetherian`
* `LieSubmodule.lieSpan`
* `LieSubmodule.map`
* `LieSubmodule.comap`
## Tags
lie algebra, lie submodule, lie ideal, lattice structure
-/
universe u v w w₁ w₂
section LieSubmodule
variable (R : Type u) (L : Type v) (M : Type w)
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
/-- A Lie submodule of a Lie module is a submodule that is closed under the Lie bracket.
This is a sufficient condition for the subset itself to form a Lie module. -/
structure LieSubmodule extends Submodule R M where
lie_mem : ∀ {x : L} {m : M}, m ∈ carrier → ⁅x, m⁆ ∈ carrier
attribute [nolint docBlame] LieSubmodule.toSubmodule
attribute [coe] LieSubmodule.toSubmodule
namespace LieSubmodule
variable {R L M}
variable (N N' : LieSubmodule R L M)
instance : SetLike (LieSubmodule R L M) M where
coe s := s.carrier
coe_injective' N O h := by cases N; cases O; congr; exact SetLike.coe_injective' h
instance : AddSubgroupClass (LieSubmodule R L M) M where
add_mem {N} _ _ := N.add_mem'
zero_mem N := N.zero_mem'
neg_mem {N} x hx := show -x ∈ N.toSubmodule from neg_mem hx
instance instSMulMemClass : SMulMemClass (LieSubmodule R L M) R M where
smul_mem {s} c _ h := s.smul_mem' c h
/-- The zero module is a Lie submodule of any Lie module. -/
instance : Zero (LieSubmodule R L M) :=
⟨{ (0 : Submodule R M) with
lie_mem := fun {x m} h ↦ by rw [(Submodule.mem_bot R).1 h]; apply lie_zero }⟩
instance : Inhabited (LieSubmodule R L M) :=
⟨0⟩
instance (priority := high) coeSort : CoeSort (LieSubmodule R L M) (Type w) where
coe N := { x : M // x ∈ N }
instance (priority := mid) coeSubmodule : CoeOut (LieSubmodule R L M) (Submodule R M) :=
⟨toSubmodule⟩
instance : CanLift (Submodule R M) (LieSubmodule R L M) (·)
(fun N ↦ ∀ {x : L} {m : M}, m ∈ N → ⁅x, m⁆ ∈ N) where
prf N hN := ⟨⟨N, hN⟩, rfl⟩
@[norm_cast]
theorem coe_toSubmodule : ((N : Submodule R M) : Set M) = N :=
rfl
theorem mem_carrier {x : M} : x ∈ N.carrier ↔ x ∈ (N : Set M) :=
Iff.rfl
theorem mem_mk_iff (S : Set M) (h₁ h₂ h₃ h₄) {x : M} :
x ∈ (⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) ↔ x ∈ S :=
Iff.rfl
@[simp]
theorem mem_mk_iff' (p : Submodule R M) (h) {x : M} :
x ∈ (⟨p, h⟩ : LieSubmodule R L M) ↔ x ∈ p :=
Iff.rfl
@[simp]
theorem mem_toSubmodule {x : M} : x ∈ (N : Submodule R M) ↔ x ∈ N :=
Iff.rfl
theorem mem_coe {x : M} : x ∈ (N : Set M) ↔ x ∈ N :=
Iff.rfl
protected theorem zero_mem : (0 : M) ∈ N :=
zero_mem N
@[simp]
theorem mk_eq_zero {x} (h : x ∈ N) : (⟨x, h⟩ : N) = 0 ↔ x = 0 :=
Subtype.ext_iff_val
@[simp]
theorem coe_toSet_mk (S : Set M) (h₁ h₂ h₃ h₄) :
((⟨⟨⟨⟨S, h₁⟩, h₂⟩, h₃⟩, h₄⟩ : LieSubmodule R L M) : Set M) = S :=
rfl
theorem toSubmodule_mk (p : Submodule R M) (h) :
(({ p with lie_mem := h } : LieSubmodule R L M) : Submodule R M) = p := by cases p; rfl
theorem toSubmodule_injective :
Function.Injective (toSubmodule : LieSubmodule R L M → Submodule R M) := fun x y h ↦ by
cases x; cases y; congr
@[ext]
theorem ext (h : ∀ m, m ∈ N ↔ m ∈ N') : N = N' :=
SetLike.ext h
@[simp]
theorem toSubmodule_inj : (N : Submodule R M) = (N' : Submodule R M) ↔ N = N' :=
toSubmodule_injective.eq_iff
/-- Copy of a `LieSubmodule` with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
protected def copy (s : Set M) (hs : s = ↑N) : LieSubmodule R L M where
carrier := s
zero_mem' := by simp [hs]
add_mem' x y := by rw [hs] at x y ⊢; exact N.add_mem' x y
smul_mem' := by exact hs.symm ▸ N.smul_mem'
lie_mem := by exact hs.symm ▸ N.lie_mem
@[simp]
theorem coe_copy (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : (S.copy s hs : Set M) = s :=
rfl
theorem copy_eq (S : LieSubmodule R L M) (s : Set M) (hs : s = ↑S) : S.copy s hs = S :=
SetLike.coe_injective hs
instance : LieRingModule L N where
bracket (x : L) (m : N) := ⟨⁅x, m.val⁆, N.lie_mem m.property⟩
add_lie := by intro x y m; apply SetCoe.ext; apply add_lie
lie_add := by intro x m n; apply SetCoe.ext; apply lie_add
leibniz_lie := by intro x y m; apply SetCoe.ext; apply leibniz_lie
@[simp, norm_cast]
theorem coe_zero : ((0 : N) : M) = (0 : M) :=
rfl
@[simp, norm_cast]
theorem coe_add (m m' : N) : (↑(m + m') : M) = (m : M) + (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_neg (m : N) : (↑(-m) : M) = -(m : M) :=
rfl
@[simp, norm_cast]
theorem coe_sub (m m' : N) : (↑(m - m') : M) = (m : M) - (m' : M) :=
rfl
@[simp, norm_cast]
theorem coe_smul (t : R) (m : N) : (↑(t • m) : M) = t • (m : M) :=
rfl
@[simp, norm_cast]
theorem coe_bracket (x : L) (m : N) :
(↑⁅x, m⁆ : M) = ⁅x, ↑m⁆ :=
rfl
-- Copying instances from `Submodule` for correct discrimination keys
instance [IsNoetherian R M] (N : LieSubmodule R L M) : IsNoetherian R N :=
inferInstanceAs <| IsNoetherian R N.toSubmodule
instance [IsArtinian R M] (N : LieSubmodule R L M) : IsArtinian R N :=
inferInstanceAs <| IsArtinian R N.toSubmodule
instance [NoZeroSMulDivisors R M] : NoZeroSMulDivisors R N :=
inferInstanceAs <| NoZeroSMulDivisors R N.toSubmodule
variable [LieAlgebra R L] [LieModule R L M]
instance instLieModule : LieModule R L N where
lie_smul := by intro t x y; apply SetCoe.ext; apply lie_smul
smul_lie := by intro t x y; apply SetCoe.ext; apply smul_lie
instance [Subsingleton M] : Unique (LieSubmodule R L M) :=
⟨⟨0⟩, fun _ ↦ (toSubmodule_inj _ _).mp (Subsingleton.elim _ _)⟩
end LieSubmodule
variable {R M}
theorem Submodule.exists_lieSubmodule_coe_eq_iff (p : Submodule R M) :
(∃ N : LieSubmodule R L M, ↑N = p) ↔ ∀ (x : L) (m : M), m ∈ p → ⁅x, m⁆ ∈ p := by
constructor
· rintro ⟨N, rfl⟩ _ _; exact N.lie_mem
· intro h; use { p with lie_mem := @h }
namespace LieSubalgebra
variable {L}
variable [LieAlgebra R L]
variable (K : LieSubalgebra R L)
/-- Given a Lie subalgebra `K ⊆ L`, if we view `L` as a `K`-module by restriction, it contains
a distinguished Lie submodule for the action of `K`, namely `K` itself. -/
def toLieSubmodule : LieSubmodule R K L :=
{ (K : Submodule R L) with lie_mem := fun {x _} hy ↦ K.lie_mem x.property hy }
@[simp]
theorem coe_toLieSubmodule : (K.toLieSubmodule : Submodule R L) = K := rfl
variable {K}
@[simp]
theorem mem_toLieSubmodule (x : L) : x ∈ K.toLieSubmodule ↔ x ∈ K :=
Iff.rfl
end LieSubalgebra
end LieSubmodule
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L] [AddCommGroup M] [Module R M]
variable [LieRingModule L M]
variable (N N' : LieSubmodule R L M)
section LatticeStructure
open Set
theorem coe_injective : Function.Injective ((↑) : LieSubmodule R L M → Set M) :=
SetLike.coe_injective
@[simp, norm_cast]
theorem toSubmodule_le_toSubmodule : (N : Submodule R M) ≤ N' ↔ N ≤ N' :=
Iff.rfl
instance : Bot (LieSubmodule R L M) :=
⟨0⟩
instance instUniqueBot : Unique (⊥ : LieSubmodule R L M) :=
inferInstanceAs <| Unique (⊥ : Submodule R M)
@[simp]
theorem bot_coe : ((⊥ : LieSubmodule R L M) : Set M) = {0} :=
rfl
@[simp]
theorem bot_toSubmodule : ((⊥ : LieSubmodule R L M) : Submodule R M) = ⊥ :=
rfl
@[simp]
theorem toSubmodule_eq_bot : (N : Submodule R M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[simp] theorem mk_eq_bot_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊥ ↔ N = ⊥ := by
rw [← toSubmodule_inj, bot_toSubmodule]
@[simp]
theorem mem_bot (x : M) : x ∈ (⊥ : LieSubmodule R L M) ↔ x = 0 :=
mem_singleton_iff
instance : Top (LieSubmodule R L M) :=
⟨{ (⊤ : Submodule R M) with lie_mem := fun {x m} _ ↦ mem_univ ⁅x, m⁆ }⟩
@[simp]
theorem top_coe : ((⊤ : LieSubmodule R L M) : Set M) = univ :=
rfl
@[simp]
theorem top_toSubmodule : ((⊤ : LieSubmodule R L M) : Submodule R M) = ⊤ :=
rfl
@[simp]
theorem toSubmodule_eq_top : (N : Submodule R M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[simp] theorem mk_eq_top_iff {N : Submodule R M} {h} :
(⟨N, h⟩ : LieSubmodule R L M) = ⊤ ↔ N = ⊤ := by
rw [← toSubmodule_inj, top_toSubmodule]
@[simp]
theorem mem_top (x : M) : x ∈ (⊤ : LieSubmodule R L M) :=
mem_univ x
instance : Min (LieSubmodule R L M) :=
⟨fun N N' ↦
{ (N ⊓ N' : Submodule R M) with
lie_mem := fun h ↦ mem_inter (N.lie_mem h.1) (N'.lie_mem h.2) }⟩
instance : InfSet (LieSubmodule R L M) :=
⟨fun S ↦
{ toSubmodule := sInf {(s : Submodule R M) | s ∈ S}
lie_mem := fun {x m} h ↦ by
simp only [Submodule.mem_carrier, mem_iInter, Submodule.sInf_coe, mem_setOf_eq,
forall_apply_eq_imp_iff₂, forall_exists_index, and_imp] at h ⊢
intro N hN; apply N.lie_mem (h N hN) }⟩
@[simp]
theorem inf_coe : (↑(N ⊓ N') : Set M) = ↑N ∩ ↑N' :=
rfl
@[norm_cast, simp]
theorem inf_toSubmodule :
(↑(N ⊓ N') : Submodule R M) = (N : Submodule R M) ⊓ (N' : Submodule R M) :=
rfl
@[simp]
theorem sInf_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = sInf {(s : Submodule R M) | s ∈ S} :=
rfl
theorem sInf_toSubmodule_eq_iInf (S : Set (LieSubmodule R L M)) :
(↑(sInf S) : Submodule R M) = ⨅ N ∈ S, (N : Submodule R M) := by
rw [sInf_toSubmodule, ← Set.image, sInf_image]
@[simp]
theorem iInf_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨅ i, p i) : Submodule R M) = ⨅ i, (p i : Submodule R M) := by
rw [iInf, sInf_toSubmodule]; ext; simp
@[simp]
theorem sInf_coe (S : Set (LieSubmodule R L M)) : (↑(sInf S) : Set M) = ⋂ s ∈ S, (s : Set M) := by
rw [← LieSubmodule.coe_toSubmodule, sInf_toSubmodule, Submodule.sInf_coe]
ext m
simp only [mem_iInter, mem_setOf_eq, forall_apply_eq_imp_iff₂, exists_imp,
and_imp, SetLike.mem_coe, mem_toSubmodule]
@[simp]
theorem iInf_coe {ι} (p : ι → LieSubmodule R L M) : (↑(⨅ i, p i) : Set M) = ⋂ i, ↑(p i) := by
rw [iInf, sInf_coe]; simp only [Set.mem_range, Set.iInter_exists, Set.iInter_iInter_eq']
@[simp]
theorem mem_iInf {ι} (p : ι → LieSubmodule R L M) {x} : (x ∈ ⨅ i, p i) ↔ ∀ i, x ∈ p i := by
rw [← SetLike.mem_coe, iInf_coe, Set.mem_iInter]; rfl
instance : Max (LieSubmodule R L M) where
max N N' :=
{ toSubmodule := (N : Submodule R M) ⊔ (N' : Submodule R M)
lie_mem := by
rintro x m (hm : m ∈ (N : Submodule R M) ⊔ (N' : Submodule R M))
change ⁅x, m⁆ ∈ (N : Submodule R M) ⊔ (N' : Submodule R M)
rw [Submodule.mem_sup] at hm ⊢
obtain ⟨y, hy, z, hz, rfl⟩ := hm
exact ⟨⁅x, y⁆, N.lie_mem hy, ⁅x, z⁆, N'.lie_mem hz, (lie_add _ _ _).symm⟩ }
instance : SupSet (LieSubmodule R L M) where
sSup S :=
{ toSubmodule := sSup {(p : Submodule R M) | p ∈ S}
lie_mem := by
intro x m (hm : m ∈ sSup {(p : Submodule R M) | p ∈ S})
change ⁅x, m⁆ ∈ sSup {(p : Submodule R M) | p ∈ S}
obtain ⟨s, hs, hsm⟩ := Submodule.mem_sSup_iff_exists_finset.mp hm
clear hm
classical
induction s using Finset.induction_on generalizing m with
| empty =>
replace hsm : m = 0 := by simpa using hsm
simp [hsm]
| insert q t hqt ih =>
rw [Finset.iSup_insert] at hsm
obtain ⟨m', hm', u, hu, rfl⟩ := Submodule.mem_sup.mp hsm
rw [lie_add]
refine add_mem ?_ (ih (Subset.trans (by simp) hs) hu)
obtain ⟨p, hp, rfl⟩ : ∃ p ∈ S, ↑p = q := hs (Finset.mem_insert_self q t)
suffices p ≤ sSup {(p : Submodule R M) | p ∈ S} by exact this (p.lie_mem hm')
exact le_sSup ⟨p, hp, rfl⟩ }
@[norm_cast, simp]
theorem sup_toSubmodule :
(↑(N ⊔ N') : Submodule R M) = (N : Submodule R M) ⊔ (N' : Submodule R M) := by
rfl
@[simp]
theorem sSup_toSubmodule (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = sSup {(s : Submodule R M) | s ∈ S} :=
rfl
theorem sSup_toSubmodule_eq_iSup (S : Set (LieSubmodule R L M)) :
(↑(sSup S) : Submodule R M) = ⨆ N ∈ S, (N : Submodule R M) := by
rw [sSup_toSubmodule, ← Set.image, sSup_image]
@[simp]
theorem iSup_toSubmodule {ι} (p : ι → LieSubmodule R L M) :
(↑(⨆ i, p i) : Submodule R M) = ⨆ i, (p i : Submodule R M) := by
rw [iSup, sSup_toSubmodule]; ext; simp [Submodule.mem_sSup, Submodule.mem_iSup]
/-- The set of Lie submodules of a Lie module form a complete lattice. -/
instance : CompleteLattice (LieSubmodule R L M) :=
{ toSubmodule_injective.completeLattice toSubmodule sup_toSubmodule inf_toSubmodule
sSup_toSubmodule_eq_iSup sInf_toSubmodule_eq_iInf rfl rfl with
toPartialOrder := SetLike.instPartialOrder }
theorem mem_iSup_of_mem {ι} {b : M} {N : ι → LieSubmodule R L M} (i : ι) (h : b ∈ N i) :
b ∈ ⨆ i, N i :=
(le_iSup N i) h
@[elab_as_elim]
lemma iSup_induction {ι} (N : ι → LieSubmodule R L M) {motive : M → Prop} {x : M}
(hx : x ∈ ⨆ i, N i) (mem : ∀ i, ∀ y ∈ N i, motive y) (zero : motive 0)
(add : ∀ y z, motive y → motive z → motive (y + z)) : motive x := by
rw [← LieSubmodule.mem_toSubmodule, LieSubmodule.iSup_toSubmodule] at hx
exact Submodule.iSup_induction (motive := motive) (fun i ↦ (N i : Submodule R M)) hx mem zero add
@[elab_as_elim]
theorem iSup_induction' {ι} (N : ι → LieSubmodule R L M) {motive : (x : M) → (x ∈ ⨆ i, N i) → Prop}
(mem : ∀ (i) (x) (hx : x ∈ N i), motive x (mem_iSup_of_mem i hx)) (zero : motive 0 (zero_mem _))
(add : ∀ x y hx hy, motive x hx → motive y hy → motive (x + y) (add_mem ‹_› ‹_›)) {x : M}
(hx : x ∈ ⨆ i, N i) : motive x hx := by
refine Exists.elim ?_ fun (hx : x ∈ ⨆ i, N i) (hc : motive x hx) => hc
refine iSup_induction N (motive := fun x : M ↦ ∃ (hx : x ∈ ⨆ i, N i), motive x hx) hx
(fun i x hx => ?_) ?_ fun x y => ?_
· exact ⟨_, mem _ _ hx⟩
· exact ⟨_, zero⟩
· rintro ⟨_, Cx⟩ ⟨_, Cy⟩
exact ⟨_, add _ _ _ _ Cx Cy⟩
variable {N N'}
@[simp] lemma disjoint_toSubmodule :
Disjoint (N : Submodule R M) (N' : Submodule R M) ↔ Disjoint N N' := by
rw [disjoint_iff, disjoint_iff, ← toSubmodule_inj, inf_toSubmodule, bot_toSubmodule,
← disjoint_iff]
@[deprecated disjoint_toSubmodule (since := "2025-04-03")]
theorem disjoint_iff_toSubmodule :
Disjoint N N' ↔ Disjoint (N : Submodule R M) (N' : Submodule R M) := disjoint_toSubmodule.symm
@[simp] lemma codisjoint_toSubmodule :
Codisjoint (N : Submodule R M) (N' : Submodule R M) ↔ Codisjoint N N' := by
rw [codisjoint_iff, codisjoint_iff, ← toSubmodule_inj, sup_toSubmodule,
top_toSubmodule, ← codisjoint_iff]
@[deprecated codisjoint_toSubmodule (since := "2025-04-03")]
theorem codisjoint_iff_toSubmodule :
Codisjoint N N' ↔ Codisjoint (N : Submodule R M) (N' : Submodule R M) :=
codisjoint_toSubmodule.symm
@[simp] lemma isCompl_toSubmodule :
IsCompl (N : Submodule R M) (N' : Submodule R M) ↔ IsCompl N N' := by
simp [isCompl_iff]
@[deprecated isCompl_toSubmodule (since := "2025-04-03")]
theorem isCompl_iff_toSubmodule :
IsCompl N N' ↔ IsCompl (N : Submodule R M) (N' : Submodule R M) := isCompl_toSubmodule.symm
@[simp] lemma iSupIndep_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep (fun i ↦ (N i : Submodule R M)) ↔ iSupIndep N := by
simp [iSupIndep_def, ← disjoint_toSubmodule]
@[deprecated iSupIndep_toSubmodule (since := "2025-04-03")]
theorem iSupIndep_iff_toSubmodule {ι : Type*} {N : ι → LieSubmodule R L M} :
iSupIndep N ↔ iSupIndep fun i ↦ (N i : Submodule R M) := iSupIndep_toSubmodule.symm
@[simp] lemma iSup_toSubmodule_eq_top {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, (N i : Submodule R M) = ⊤ ↔ ⨆ i, N i = ⊤ := by
rw [← iSup_toSubmodule, ← top_toSubmodule (L := L), toSubmodule_inj]
@[deprecated iSup_toSubmodule_eq_top (since := "2025-04-03")]
theorem iSup_eq_top_iff_toSubmodule {ι : Sort*} {N : ι → LieSubmodule R L M} :
⨆ i, N i = ⊤ ↔ ⨆ i, (N i : Submodule R M) = ⊤ := iSup_toSubmodule_eq_top.symm
instance : Add (LieSubmodule R L M) where add := max
instance : Zero (LieSubmodule R L M) where zero := ⊥
instance : AddCommMonoid (LieSubmodule R L M) where
add_assoc := sup_assoc
zero_add := bot_sup_eq
add_zero := sup_bot_eq
add_comm := sup_comm
nsmul := nsmulRec
variable (N N')
@[simp]
theorem add_eq_sup : N + N' = N ⊔ N' :=
rfl
@[simp]
theorem mem_inf (x : M) : x ∈ N ⊓ N' ↔ x ∈ N ∧ x ∈ N' := by
rw [← mem_toSubmodule, ← mem_toSubmodule, ← mem_toSubmodule, inf_toSubmodule,
Submodule.mem_inf]
theorem mem_sup (x : M) : x ∈ N ⊔ N' ↔ ∃ y ∈ N, ∃ z ∈ N', y + z = x := by
rw [← mem_toSubmodule, sup_toSubmodule, Submodule.mem_sup]; exact Iff.rfl
nonrec theorem eq_bot_iff : N = ⊥ ↔ ∀ m : M, m ∈ N → m = 0 := by rw [eq_bot_iff]; exact Iff.rfl
instance subsingleton_of_bot : Subsingleton (LieSubmodule R L (⊥ : LieSubmodule R L M)) := by
apply subsingleton_of_bot_eq_top
subsingleton
instance : IsModularLattice (LieSubmodule R L M) where
sup_inf_le_assoc_of_le _ _ := by
simp only [← toSubmodule_le_toSubmodule, sup_toSubmodule, inf_toSubmodule]
exact IsModularLattice.sup_inf_le_assoc_of_le _
variable (R L M)
/-- The natural functor that forgets the action of `L` as an order embedding. -/
@[simps] def toSubmodule_orderEmbedding : LieSubmodule R L M ↪o Submodule R M :=
{ toFun := (↑)
inj' := toSubmodule_injective
map_rel_iff' := Iff.rfl }
instance wellFoundedGT_of_noetherian [IsNoetherian R M] : WellFoundedGT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).dual.ltEmbedding
theorem wellFoundedLT_of_isArtinian [IsArtinian R M] : WellFoundedLT (LieSubmodule R L M) :=
RelHomClass.isWellFounded (toSubmodule_orderEmbedding R L M).ltEmbedding
instance [IsArtinian R M] : IsAtomic (LieSubmodule R L M) :=
isAtomic_of_orderBot_wellFounded_lt <| (wellFoundedLT_of_isArtinian R L M).wf
@[simp]
theorem subsingleton_iff : Subsingleton (LieSubmodule R L M) ↔ Subsingleton M :=
have h : Subsingleton (LieSubmodule R L M) ↔ Subsingleton (Submodule R M) := by
rw [← subsingleton_iff_bot_eq_top, ← subsingleton_iff_bot_eq_top, ← toSubmodule_inj,
top_toSubmodule, bot_toSubmodule]
h.trans <| Submodule.subsingleton_iff R
@[simp]
theorem nontrivial_iff : Nontrivial (LieSubmodule R L M) ↔ Nontrivial M :=
not_iff_not.mp
((not_nontrivial_iff_subsingleton.trans <| subsingleton_iff R L M).trans
not_nontrivial_iff_subsingleton.symm)
instance [Nontrivial M] : Nontrivial (LieSubmodule R L M) :=
(nontrivial_iff R L M).mpr ‹_›
theorem nontrivial_iff_ne_bot {N : LieSubmodule R L M} : Nontrivial N ↔ N ≠ ⊥ := by
constructor <;> contrapose!
· rintro rfl
⟨⟨m₁, h₁ : m₁ ∈ (⊥ : LieSubmodule R L M)⟩, ⟨m₂, h₂ : m₂ ∈ (⊥ : LieSubmodule R L M)⟩, h₁₂⟩
simp [(LieSubmodule.mem_bot _).mp h₁, (LieSubmodule.mem_bot _).mp h₂] at h₁₂
· rw [not_nontrivial_iff_subsingleton, LieSubmodule.eq_bot_iff]
rintro ⟨h⟩ m hm
simpa using h ⟨m, hm⟩ ⟨_, N.zero_mem⟩
variable {R L M}
section InclusionMaps
/-- The inclusion of a Lie submodule into its ambient space is a morphism of Lie modules. -/
def incl : N →ₗ⁅R,L⁆ M :=
{ Submodule.subtype (N : Submodule R M) with map_lie' := fun {_ _} ↦ rfl }
@[simp]
theorem incl_coe : (N.incl : N →ₗ[R] M) = (N : Submodule R M).subtype :=
rfl
@[simp]
theorem incl_apply (m : N) : N.incl m = m :=
rfl
theorem incl_eq_val : (N.incl : N → M) = Subtype.val :=
rfl
theorem injective_incl : Function.Injective N.incl := Subtype.coe_injective
variable {N N'}
variable (h : N ≤ N')
/-- Given two nested Lie submodules `N ⊆ N'`,
the inclusion `N ↪ N'` is a morphism of Lie modules. -/
def inclusion : N →ₗ⁅R,L⁆ N' where
__ := Submodule.inclusion (show N.toSubmodule ≤ N'.toSubmodule from h)
map_lie' := rfl
@[simp]
theorem coe_inclusion (m : N) : (inclusion h m : M) = m :=
rfl
theorem inclusion_apply (m : N) : inclusion h m = ⟨m.1, h m.2⟩ :=
rfl
theorem inclusion_injective : Function.Injective (inclusion h) := fun x y ↦ by
simp only [inclusion_apply, imp_self, Subtype.mk_eq_mk, SetLike.coe_eq_coe]
end InclusionMaps
section LieSpan
variable (R L) (s : Set M)
/-- The `lieSpan` of a set `s ⊆ M` is the smallest Lie submodule of `M` that contains `s`. -/
def lieSpan : LieSubmodule R L M :=
sInf { N | s ⊆ N }
variable {R L s}
theorem mem_lieSpan {x : M} : x ∈ lieSpan R L s ↔ ∀ N : LieSubmodule R L M, s ⊆ N → x ∈ N := by
rw [← SetLike.mem_coe, lieSpan, sInf_coe]
exact mem_iInter₂
theorem subset_lieSpan : s ⊆ lieSpan R L s := by
intro m hm
rw [SetLike.mem_coe, mem_lieSpan]
intro N hN
exact hN hm
theorem submodule_span_le_lieSpan : Submodule.span R s ≤ lieSpan R L s := by
rw [Submodule.span_le]
apply subset_lieSpan
@[simp]
theorem lieSpan_le {N} : lieSpan R L s ≤ N ↔ s ⊆ N := by
constructor
· exact Subset.trans subset_lieSpan
· intro hs m hm; rw [mem_lieSpan] at hm; exact hm _ hs
@[gcongr]
theorem lieSpan_mono {t : Set M} (h : s ⊆ t) : lieSpan R L s ≤ lieSpan R L t := by
rw [lieSpan_le]
exact Subset.trans h subset_lieSpan
theorem lieSpan_eq (N : LieSubmodule R L M) : lieSpan R L (N : Set M) = N :=
le_antisymm (lieSpan_le.mpr rfl.subset) subset_lieSpan
theorem coe_lieSpan_submodule_eq_iff {p : Submodule R M} :
(lieSpan R L (p : Set M) : Submodule R M) = p ↔ ∃ N : LieSubmodule R L M, ↑N = p := by
rw [p.exists_lieSubmodule_coe_eq_iff L]; constructor <;> intro h
· intro x m hm; rw [← h, mem_toSubmodule]; exact lie_mem _ (subset_lieSpan hm)
· rw [← toSubmodule_mk p @h, coe_toSubmodule, toSubmodule_inj, lieSpan_eq]
variable (R L M)
/-- `lieSpan` forms a Galois insertion with the coercion from `LieSubmodule` to `Set`. -/
protected def gi : GaloisInsertion (lieSpan R L : Set M → LieSubmodule R L M) (↑) where
choice s _ := lieSpan R L s
gc _ _ := lieSpan_le
le_l_u _ := subset_lieSpan
choice_eq _ _ := rfl
@[simp]
theorem span_empty : lieSpan R L (∅ : Set M) = ⊥ :=
(LieSubmodule.gi R L M).gc.l_bot
@[simp]
theorem span_univ : lieSpan R L (Set.univ : Set M) = ⊤ :=
eq_top_iff.2 <| SetLike.le_def.2 <| subset_lieSpan
theorem lieSpan_eq_bot_iff : lieSpan R L s = ⊥ ↔ ∀ m ∈ s, m = (0 : M) := by
rw [_root_.eq_bot_iff, lieSpan_le, bot_coe, subset_singleton_iff]
variable {M}
theorem span_union (s t : Set M) : lieSpan R L (s ∪ t) = lieSpan R L s ⊔ lieSpan R L t :=
(LieSubmodule.gi R L M).gc.l_sup
theorem span_iUnion {ι} (s : ι → Set M) : lieSpan R L (⋃ i, s i) = ⨆ i, lieSpan R L (s i) :=
(LieSubmodule.gi R L M).gc.l_iSup
/-- An induction principle for span membership. If `p` holds for 0 and all elements of `s`, and is
preserved under addition, scalar multiplication and the Lie bracket, then `p` holds for all
elements of the Lie submodule spanned by `s`. -/
@[elab_as_elim]
theorem lieSpan_induction {p : (x : M) → x ∈ lieSpan R L s → Prop}
(mem : ∀ (x) (h : x ∈ s), p x (subset_lieSpan h))
(zero : p 0 (LieSubmodule.zero_mem _))
(add : ∀ x y hx hy, p x hx → p y hy → p (x + y) (add_mem ‹_› ‹_›))
(smul : ∀ (a : R) (x hx), p x hx → p (a • x) (SMulMemClass.smul_mem _ hx)) {x}
(lie : ∀ (x : L) (y hy), p y hy → p (⁅x, y⁆) (LieSubmodule.lie_mem _ ‹_›))
(hx : x ∈ lieSpan R L s) : p x hx := by
let p : LieSubmodule R L M :=
{ carrier := { x | ∃ hx, p x hx }
add_mem' := fun ⟨_, hpx⟩ ⟨_, hpy⟩ ↦ ⟨_, add _ _ _ _ hpx hpy⟩
zero_mem' := ⟨_, zero⟩
smul_mem' := fun r ↦ fun ⟨_, hpx⟩ ↦ ⟨_, smul r _ _ hpx⟩
lie_mem := fun ⟨_, hpy⟩ ↦ ⟨_, lie _ _ _ hpy⟩ }
exact lieSpan_le (N := p) |>.mpr (fun y hy ↦ ⟨subset_lieSpan hy, mem y hy⟩) hx |>.elim fun _ ↦ id
lemma isCompactElement_lieSpan_singleton (m : M) :
CompleteLattice.IsCompactElement (lieSpan R L {m}) := by
rw [CompleteLattice.isCompactElement_iff_le_of_directed_sSup_le]
intro s hne hdir hsup
replace hsup : m ∈ (↑(sSup s) : Set M) := (SetLike.le_def.mp hsup) (subset_lieSpan rfl)
suffices (↑(sSup s) : Set M) = ⋃ N ∈ s, ↑N by simp_all
replace hne : Nonempty s := Set.nonempty_coe_sort.mpr hne
have := Submodule.coe_iSup_of_directed _ hdir.directed_val
simp_rw [← iSup_toSubmodule, Set.iUnion_coe_set, coe_toSubmodule] at this
rw [← this, SetLike.coe_set_eq, sSup_eq_iSup, iSup_subtype]
@[simp]
lemma sSup_image_lieSpan_singleton : sSup ((fun x ↦ lieSpan R L {x}) '' N) = N := by
refine le_antisymm (sSup_le <| by simp) ?_
simp_rw [← toSubmodule_le_toSubmodule, sSup_toSubmodule, Set.mem_image, SetLike.mem_coe]
refine fun m hm ↦ Submodule.mem_sSup.mpr fun N' hN' ↦ ?_
replace hN' : ∀ m ∈ N, lieSpan R L {m} ≤ N' := by simpa using hN'
exact hN' _ hm (subset_lieSpan rfl)
instance instIsCompactlyGenerated : IsCompactlyGenerated (LieSubmodule R L M) :=
⟨fun N ↦ ⟨(fun x ↦ lieSpan R L {x}) '' N, fun _ ⟨m, _, hm⟩ ↦
hm ▸ isCompactElement_lieSpan_singleton R L m, N.sSup_image_lieSpan_singleton⟩⟩
end LieSpan
end LatticeStructure
end LieSubmodule
section LieSubmoduleMapAndComap
variable {R : Type u} {L : Type v} {L' : Type w₂} {M : Type w} {M' : Type w₁}
variable [CommRing R] [LieRing L] [LieRing L'] [LieAlgebra R L']
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup M'] [Module R M'] [LieRingModule L M']
namespace LieSubmodule
variable (f : M →ₗ⁅R,L⁆ M') (N N₂ : LieSubmodule R L M) (N' : LieSubmodule R L M')
/-- A morphism of Lie modules `f : M → M'` pushes forward Lie submodules of `M` to Lie submodules
of `M'`. -/
def map : LieSubmodule R L M' :=
{ (N : Submodule R M).map (f : M →ₗ[R] M') with
lie_mem := fun {x m'} h ↦ by
rcases h with ⟨m, hm, hfm⟩; use ⁅x, m⁆; constructor
· apply N.lie_mem hm
· norm_cast at hfm; simp [hfm] }
@[simp] theorem coe_map : (N.map f : Set M') = f '' N := rfl
@[simp]
theorem toSubmodule_map : (N.map f : Submodule R M') = (N : Submodule R M).map (f : M →ₗ[R] M') :=
rfl
/-- A morphism of Lie modules `f : M → M'` pulls back Lie submodules of `M'` to Lie submodules of
`M`. -/
def comap : LieSubmodule R L M :=
{ (N' : Submodule R M').comap (f : M →ₗ[R] M') with
lie_mem := fun {x m} h ↦ by
suffices ⁅x, f m⁆ ∈ N' by simp [this]
apply N'.lie_mem h }
@[simp]
theorem toSubmodule_comap :
(N'.comap f : Submodule R M) = (N' : Submodule R M').comap (f : M →ₗ[R] M') :=
rfl
variable {f N N₂ N'}
theorem map_le_iff_le_comap : map f N ≤ N' ↔ N ≤ comap f N' :=
Set.image_subset_iff
variable (f) in
theorem gc_map_comap : GaloisConnection (map f) (comap f) := fun _ _ ↦ map_le_iff_le_comap
theorem map_inf_le : (N ⊓ N₂).map f ≤ N.map f ⊓ N₂.map f :=
Set.image_inter_subset f N N₂
theorem map_inf (hf : Function.Injective f) :
(N ⊓ N₂).map f = N.map f ⊓ N₂.map f :=
SetLike.coe_injective <| Set.image_inter hf
@[simp]
theorem map_sup : (N ⊔ N₂).map f = N.map f ⊔ N₂.map f :=
(gc_map_comap f).l_sup
@[simp]
theorem comap_inf {N₂' : LieSubmodule R L M'} :
(N' ⊓ N₂').comap f = N'.comap f ⊓ N₂'.comap f :=
rfl
@[simp]
theorem map_iSup {ι : Sort*} (N : ι → LieSubmodule R L M) :
(⨆ i, N i).map f = ⨆ i, (N i).map f :=
(gc_map_comap f : GaloisConnection (map f) (comap f)).l_iSup
@[simp]
theorem mem_map (m' : M') : m' ∈ N.map f ↔ ∃ m, m ∈ N ∧ f m = m' :=
Submodule.mem_map
theorem mem_map_of_mem {m : M} (h : m ∈ N) : f m ∈ N.map f :=
Set.mem_image_of_mem _ h
@[simp]
theorem mem_comap {m : M} : m ∈ comap f N' ↔ f m ∈ N' :=
Iff.rfl
theorem comap_incl_eq_top : N₂.comap N.incl = ⊤ ↔ N ≤ N₂ := by
rw [← LieSubmodule.toSubmodule_inj, LieSubmodule.toSubmodule_comap, LieSubmodule.incl_coe,
LieSubmodule.top_toSubmodule, Submodule.comap_subtype_eq_top, toSubmodule_le_toSubmodule]
theorem comap_incl_eq_bot : N₂.comap N.incl = ⊥ ↔ N ⊓ N₂ = ⊥ := by
simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, bot_toSubmodule,
inf_toSubmodule]
rw [← Submodule.disjoint_iff_comap_eq_bot, disjoint_iff]
@[gcongr, mono]
theorem map_mono (h : N ≤ N₂) : N.map f ≤ N₂.map f :=
Set.image_mono h
theorem map_comp
{M'' : Type*} [AddCommGroup M''] [Module R M''] [LieRingModule L M''] {g : M' →ₗ⁅R,L⁆ M''} :
N.map (g.comp f) = (N.map f).map g :=
SetLike.coe_injective <| by
simp only [← Set.image_comp, coe_map, LieModuleHom.coe_comp]
@[simp]
theorem map_id : N.map LieModuleHom.id = N := by ext; simp
@[simp] theorem map_bot :
(⊥ : LieSubmodule R L M).map f = ⊥ := by
ext m; simp [eq_comm]
lemma map_le_map_iff (hf : Function.Injective f) :
N.map f ≤ N₂.map f ↔ N ≤ N₂ :=
Set.image_subset_image_iff hf
lemma map_injective_of_injective (hf : Function.Injective f) :
Function.Injective (map f) := fun {N N'} h ↦
SetLike.coe_injective <| hf.image_injective <| by simp only [← coe_map, h]
/-- An injective morphism of Lie modules embeds the lattice of submodules of the domain into that
of the target. -/
@[simps] def mapOrderEmbedding {f : M →ₗ⁅R,L⁆ M'} (hf : Function.Injective f) :
LieSubmodule R L M ↪o LieSubmodule R L M' where
toFun := LieSubmodule.map f
inj' := map_injective_of_injective hf
map_rel_iff' := Set.image_subset_image_iff hf
variable (N) in
/-- For an injective morphism of Lie modules, any Lie submodule is equivalent to its image. -/
noncomputable def equivMapOfInjective (hf : Function.Injective f) :
N ≃ₗ⁅R,L⁆ N.map f :=
{ Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N with
-- Note: https://github.com/leanprover-community/mathlib4/pull/8386 had to specify `invFun` explicitly this way, otherwise we'd get a type mismatch
invFun := by exact DFunLike.coe (Submodule.equivMapOfInjective (f : M →ₗ[R] M') hf N).symm
map_lie' := by rintro x ⟨m, hm : m ∈ N⟩; ext; exact f.map_lie x m }
/-- An equivalence of Lie modules yields an order-preserving equivalence of their lattices of Lie
Submodules. -/
@[simps] def orderIsoMapComap (e : M ≃ₗ⁅R,L⁆ M') :
LieSubmodule R L M ≃o LieSubmodule R L M' where
toFun := map e
invFun := comap e
left_inv := fun N ↦ by ext; simp
right_inv := fun N ↦ by ext; simp [e.apply_eq_iff_eq_symm_apply]
map_rel_iff' := fun {_ _} ↦ Set.image_subset_image_iff e.injective
end LieSubmodule
end LieSubmoduleMapAndComap
namespace LieModuleHom
variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable [AddCommGroup N] [Module R N] [LieRingModule L N]
variable (f : M →ₗ⁅R,L⁆ N)
/-- The kernel of a morphism of Lie algebras, as an ideal in the domain. -/
def ker : LieSubmodule R L M :=
LieSubmodule.comap f ⊥
@[simp]
theorem ker_toSubmodule : (f.ker : Submodule R M) = LinearMap.ker (f : M →ₗ[R] N) :=
rfl
theorem ker_eq_bot : f.ker = ⊥ ↔ Function.Injective f := by
rw [← LieSubmodule.toSubmodule_inj, ker_toSubmodule, LieSubmodule.bot_toSubmodule,
LinearMap.ker_eq_bot, coe_toLinearMap]
variable {f}
@[simp]
theorem mem_ker {m : M} : m ∈ f.ker ↔ f m = 0 :=
Iff.rfl
@[simp]
theorem ker_id : (LieModuleHom.id : M →ₗ⁅R,L⁆ M).ker = ⊥ :=
rfl
@[simp]
theorem comp_ker_incl : f.comp f.ker.incl = 0 := by ext ⟨m, hm⟩; exact mem_ker.mp hm
theorem le_ker_iff_map (M' : LieSubmodule R L M) : M' ≤ f.ker ↔ LieSubmodule.map f M' = ⊥ := by
rw [ker, eq_bot_iff, LieSubmodule.map_le_iff_le_comap]
variable (f)
/-- The range of a morphism of Lie modules `f : M → N` is a Lie submodule of `N`.
See Note [range copy pattern]. -/
def range : LieSubmodule R L N :=
(LieSubmodule.map f ⊤).copy (Set.range f) Set.image_univ.symm
@[simp]
theorem coe_range : f.range = Set.range f :=
rfl
@[simp]
theorem toSubmodule_range : f.range = LinearMap.range (f : M →ₗ[R] N) :=
rfl
@[simp]
theorem mem_range (n : N) : n ∈ f.range ↔ ∃ m, f m = n :=
Iff.rfl
@[simp]
theorem map_top : LieSubmodule.map f ⊤ = f.range := by ext; simp [LieSubmodule.mem_map]
theorem range_eq_top : f.range = ⊤ ↔ Function.Surjective f := by
rw [SetLike.ext'_iff, coe_range, LieSubmodule.top_coe, Set.range_eq_univ]
/-- A morphism of Lie modules `f : M → N` whose values lie in a Lie submodule `P ⊆ N` can be
restricted to a morphism of Lie modules `M → P`. -/
def codRestrict (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) :
M →ₗ⁅R,L⁆ P where
toFun := f.toLinearMap.codRestrict P h
__ := f.toLinearMap.codRestrict P h
map_lie' {x m} := by ext; simp
@[simp]
lemma codRestrict_apply (P : LieSubmodule R L N) (f : M →ₗ⁅R,L⁆ N) (h : ∀ m, f m ∈ P) (m : M) :
(f.codRestrict P h m : N) = f m :=
rfl
end LieModuleHom
namespace LieSubmodule
variable {R : Type u} {L : Type v} {M : Type w}
variable [CommRing R] [LieRing L]
variable [AddCommGroup M] [Module R M] [LieRingModule L M]
variable (N : LieSubmodule R L M)
@[simp]
theorem ker_incl : N.incl.ker = ⊥ := (LieModuleHom.ker_eq_bot N.incl).mpr <| injective_incl N
@[simp]
theorem range_incl : N.incl.range = N := by
simp only [← toSubmodule_inj, LieModuleHom.toSubmodule_range, incl_coe]
rw [Submodule.range_subtype]
@[simp]
theorem comap_incl_self : comap N.incl N = ⊤ := by
simp only [← toSubmodule_inj, toSubmodule_comap, incl_coe, top_toSubmodule]
rw [Submodule.comap_subtype_self]
theorem map_incl_top : (⊤ : LieSubmodule R L N).map N.incl = N := by simp
variable {N}
@[simp]
lemma map_le_range {M' : Type*}
[AddCommGroup M'] [Module R M'] [LieRingModule L M'] (f : M →ₗ⁅R,L⁆ M') :
N.map f ≤ f.range := by
rw [← LieModuleHom.map_top]
exact LieSubmodule.map_mono le_top
@[simp]
lemma map_incl_lt_iff_lt_top {N' : LieSubmodule R L N} :
N'.map (LieSubmodule.incl N) < N ↔ N' < ⊤ := by
convert (LieSubmodule.mapOrderEmbedding (f := N.incl) Subtype.coe_injective).lt_iff_lt
simp
@[simp]
lemma map_incl_le {N' : LieSubmodule R L N} :
N'.map N.incl ≤ N := by
conv_rhs => rw [← N.map_incl_top]
exact LieSubmodule.map_mono le_top
end LieSubmodule
section TopEquiv
variable (R : Type u) (L : Type v)
variable [CommRing R] [LieRing L]
variable (M : Type*) [AddCommGroup M] [Module R M] [LieRingModule L M]
/-- The natural equivalence between the 'top' Lie submodule and the enclosing Lie module. -/
def LieModuleEquiv.ofTop : (⊤ : LieSubmodule R L M) ≃ₗ⁅R,L⁆ M :=
{ LinearEquiv.ofTop ⊤ rfl with
map_lie' := rfl }
variable {R L}
lemma LieModuleEquiv.ofTop_apply (x : (⊤ : LieSubmodule R L M)) :
LieModuleEquiv.ofTop R L M x = x :=
rfl
@[simp] lemma LieModuleEquiv.range_coe {M' : Type*}
[AddCommGroup M'] [Module R M'] [LieRingModule L M'] (e : M ≃ₗ⁅R,L⁆ M') :
LieModuleHom.range (e : M →ₗ⁅R,L⁆ M') = ⊤ := by
rw [LieModuleHom.range_eq_top]
exact e.surjective
variable [LieAlgebra R L] [LieModule R L M]
/-- The natural equivalence between the 'top' Lie subalgebra and the enclosing Lie algebra.
This is the Lie subalgebra version of `Submodule.topEquiv`. -/
def LieSubalgebra.topEquiv : (⊤ : LieSubalgebra R L) ≃ₗ⁅R⁆ L :=
{ (⊤ : LieSubalgebra R L).incl with
invFun := fun x ↦ ⟨x, Set.mem_univ x⟩ }
@[simp]
theorem LieSubalgebra.topEquiv_apply (x : (⊤ : LieSubalgebra R L)) : LieSubalgebra.topEquiv x = x :=
rfl
end TopEquiv
|
Resolution.lean
|
/-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Localization.LocalizerMorphism
/-!
# Resolutions for a morphism of localizers
Given a morphism of localizers `Φ : LocalizerMorphism W₁ W₂` (i.e. `W₁` and `W₂` are
morphism properties on categories `C₁` and `C₂`, and we have a functor
`Φ.functor : C₁ ⥤ C₂` which sends morphisms in `W₁` to morphisms in `W₂`), we introduce
the notion of right resolutions of objects in `C₂`: if `X₂ : C₂`.
A right resolution consists of an object `X₁ : C₁` and a morphism
`w : X₂ ⟶ Φ.functor.obj X₁` that is in `W₂`. Then, the typeclass
`Φ.HasRightResolutions` holds when any `X₂ : C₂` has a right resolution.
The type of right resolutions `Φ.RightResolution X₂` is endowed with a category
structure.
Similar definitions are done for left resolutions.
## Future works
* show that if `C` is an abelian category with enough injectives, there is a derivability
structure associated to the inclusion of the full subcategory of complexes of injective
objects into the bounded below homotopy category of `C` (TODO @joelriou)
* formalize dual results
## References
* [Bruno Kahn and Georges Maltsiniotis, *Structures de dérivabilité*][KahnMaltsiniotis2008]
-/
universe v₁ v₂ v₂' u₁ u₂ u₂'
namespace CategoryTheory
open Category Localization
variable {C₁ C₂ D₂ H : Type*} [Category C₁] [Category C₂] [Category D₂] [Category H]
{W₁ : MorphismProperty C₁} {W₂ : MorphismProperty C₂}
namespace LocalizerMorphism
variable (Φ : LocalizerMorphism W₁ W₂)
/-- The category of right resolutions of an object in the target category
of a localizer morphism. -/
structure RightResolution (X₂ : C₂) where
/-- an object in the source category -/
{X₁ : C₁}
/-- a morphism to an object of the form `Φ.functor.obj X₁` -/
w : X₂ ⟶ Φ.functor.obj X₁
hw : W₂ w
/-- The category of left resolutions of an object in the target category
of a localizer morphism. -/
structure LeftResolution (X₂ : C₂) where
/-- an object in the source category -/
{X₁ : C₁}
/-- a morphism from an object of the form `Φ.functor.obj X₁` -/
w : Φ.functor.obj X₁ ⟶ X₂
hw : W₂ w
variable {Φ X₂} in
lemma RightResolution.mk_surjective (R : Φ.RightResolution X₂) :
∃ (X₁ : C₁) (w : X₂ ⟶ Φ.functor.obj X₁) (hw : W₂ w), R = RightResolution.mk w hw :=
⟨_, R.w, R.hw, rfl⟩
variable {Φ X₂} in
lemma LeftResolution.mk_surjective (L : Φ.LeftResolution X₂) :
∃ (X₁ : C₁) (w : Φ.functor.obj X₁ ⟶ X₂) (hw : W₂ w), L = LeftResolution.mk w hw :=
⟨_, L.w, L.hw, rfl⟩
/-- A localizer morphism has right resolutions when any object has a right resolution. -/
abbrev HasRightResolutions := ∀ (X₂ : C₂), Nonempty (Φ.RightResolution X₂)
/-- A localizer morphism has right resolutions when any object has a right resolution. -/
abbrev HasLeftResolutions := ∀ (X₂ : C₂), Nonempty (Φ.LeftResolution X₂)
namespace RightResolution
variable {Φ} {X₂ : C₂}
/-- The type of morphisms in the category `Φ.RightResolution X₂`. -/
@[ext]
structure Hom (R R' : Φ.RightResolution X₂) where
/-- a morphism in the source category -/
f : R.X₁ ⟶ R'.X₁
comm : R.w ≫ Φ.functor.map f = R'.w := by cat_disch
attribute [reassoc (attr := simp)] Hom.comm
/-- The identity of a object in `Φ.RightResolution X₂`. -/
@[simps]
def Hom.id (R : Φ.RightResolution X₂) : Hom R R where
f := 𝟙 _
/-- The composition of morphisms in `Φ.RightResolution X₂`. -/
@[simps]
def Hom.comp {R R' R'' : Φ.RightResolution X₂}
(φ : Hom R R') (ψ : Hom R' R'') :
Hom R R'' where
f := φ.f ≫ ψ.f
instance : Category (Φ.RightResolution X₂) where
Hom := Hom
id := Hom.id
comp := Hom.comp
@[simp]
lemma id_f (R : Φ.RightResolution X₂) : Hom.f (𝟙 R) = 𝟙 R.X₁ := rfl
@[simp, reassoc]
lemma comp_f {R R' R'' : Φ.RightResolution X₂} (φ : R ⟶ R') (ψ : R' ⟶ R'') :
(φ ≫ ψ).f = φ.f ≫ ψ.f := rfl
@[ext]
lemma hom_ext {R R' : Φ.RightResolution X₂} {φ₁ φ₂ : R ⟶ R'} (h : φ₁.f = φ₂.f) :
φ₁ = φ₂ :=
Hom.ext h
end RightResolution
namespace LeftResolution
variable {Φ} {X₂ : C₂}
/-- The type of morphisms in the category `Φ.LeftResolution X₂`. -/
@[ext]
structure Hom (L L' : Φ.LeftResolution X₂) where
/-- a morphism in the source category -/
f : L.X₁ ⟶ L'.X₁
comm : Φ.functor.map f ≫ L'.w = L.w := by cat_disch
attribute [reassoc (attr := simp)] Hom.comm
/-- The identity of a object in `Φ.LeftResolution X₂`. -/
@[simps]
def Hom.id (L : Φ.LeftResolution X₂) : Hom L L where
f := 𝟙 _
/-- The composition of morphisms in `Φ.LeftResolution X₂`. -/
@[simps]
def Hom.comp {L L' L'' : Φ.LeftResolution X₂}
(φ : Hom L L') (ψ : Hom L' L'') :
Hom L L'' where
f := φ.f ≫ ψ.f
instance : Category (Φ.LeftResolution X₂) where
Hom := Hom
id := Hom.id
comp := Hom.comp
@[simp]
lemma id_f (L : Φ.LeftResolution X₂) : Hom.f (𝟙 L) = 𝟙 L.X₁ := rfl
@[simp, reassoc]
lemma comp_f {L L' L'' : Φ.LeftResolution X₂} (φ : L ⟶ L') (ψ : L' ⟶ L'') :
(φ ≫ ψ).f = φ.f ≫ ψ.f := rfl
@[ext]
lemma hom_ext {L L' : Φ.LeftResolution X₂} {φ₁ φ₂ : L ⟶ L'} (h : φ₁.f = φ₂.f) :
φ₁ = φ₂ :=
Hom.ext h
end LeftResolution
variable {Φ}
/-- The canonical map `Φ.LeftResolution X₂ → Φ.op.RightResolution (Opposite.op X₂)`. -/
@[simps]
def LeftResolution.op {X₂ : C₂} (L : Φ.LeftResolution X₂) :
Φ.op.RightResolution (Opposite.op X₂) where
X₁ := Opposite.op L.X₁
w := L.w.op
hw := L.hw
/-- The canonical map `Φ.op.LeftResolution X₂ → Φ.RightResolution X₂`. -/
@[simps]
def LeftResolution.unop {X₂ : C₂ᵒᵖ} (L : Φ.op.LeftResolution X₂) :
Φ.RightResolution X₂.unop where
X₁ := Opposite.unop L.X₁
w := L.w.unop
hw := L.hw
/-- The canonical map `Φ.RightResolution X₂ → Φ.op.LeftResolution (Opposite.op X₂)`. -/
@[simps]
def RightResolution.op {X₂ : C₂} (L : Φ.RightResolution X₂) :
Φ.op.LeftResolution (Opposite.op X₂) where
X₁ := Opposite.op L.X₁
w := L.w.op
hw := L.hw
/-- The canonical map `Φ.op.RightResolution X₂ → Φ.LeftResolution X₂`. -/
@[simps]
def RightResolution.unop {X₂ : C₂ᵒᵖ} (L : Φ.op.RightResolution X₂) :
Φ.LeftResolution X₂.unop where
X₁ := Opposite.unop L.X₁
w := L.w.unop
hw := L.hw
variable (Φ)
lemma nonempty_leftResolution_iff_op (X₂ : C₂) :
Nonempty (Φ.LeftResolution X₂) ↔ Nonempty (Φ.op.RightResolution (Opposite.op X₂)) :=
Equiv.nonempty_congr
{ toFun := fun L => L.op
invFun := fun R => R.unop }
lemma nonempty_rightResolution_iff_op (X₂ : C₂) :
Nonempty (Φ.RightResolution X₂) ↔ Nonempty (Φ.op.LeftResolution (Opposite.op X₂)) :=
Equiv.nonempty_congr
{ toFun := fun R => R.op
invFun := fun L => L.unop }
lemma hasLeftResolutions_iff_op : Φ.HasLeftResolutions ↔ Φ.op.HasRightResolutions :=
⟨fun _ X₂ => ⟨(Classical.arbitrary (Φ.LeftResolution X₂.unop)).op⟩,
fun _ X₂ => ⟨(Classical.arbitrary (Φ.op.RightResolution (Opposite.op X₂))).unop⟩⟩
lemma hasRightResolutions_iff_op : Φ.HasRightResolutions ↔ Φ.op.HasLeftResolutions :=
⟨fun _ X₂ => ⟨(Classical.arbitrary (Φ.RightResolution X₂.unop)).op⟩,
fun _ X₂ => ⟨(Classical.arbitrary (Φ.op.LeftResolution (Opposite.op X₂))).unop⟩⟩
instance [Φ.HasRightResolutions] : Φ.op.HasLeftResolutions := by
rwa [← hasRightResolutions_iff_op]
instance [Φ.HasLeftResolutions] : Φ.op.HasRightResolutions := by
rwa [← hasLeftResolutions_iff_op]
/-- The functor `(Φ.LeftResolution X₂)ᵒᵖ ⥤ Φ.op.RightResolution (Opposite.op X₂)`. -/
@[simps]
def LeftResolution.opFunctor (X₂ : C₂) :
(Φ.LeftResolution X₂)ᵒᵖ ⥤ Φ.op.RightResolution (Opposite.op X₂) where
obj L := L.unop.op
map φ :=
{ f := φ.unop.f.op
comm := Quiver.Hom.unop_inj φ.unop.comm }
/-- The functor `(Φ.op.RightResolution X₂)ᵒᵖ ⥤ Φ.LeftResolution X₂.unop`. -/
@[simps]
def RightResolution.unopFunctor (X₂ : C₂ᵒᵖ) :
(Φ.op.RightResolution X₂)ᵒᵖ ⥤ Φ.LeftResolution X₂.unop where
obj R := R.unop.unop
map φ :=
{ f := φ.unop.f.unop
comm := Quiver.Hom.op_inj φ.unop.comm }
/-- The equivalence of categories
`(Φ.LeftResolution X₂)ᵒᵖ ≌ Φ.op.RightResolution (Opposite.op X₂)`. -/
@[simps]
def LeftResolution.opEquivalence (X₂ : C₂) :
(Φ.LeftResolution X₂)ᵒᵖ ≌ Φ.op.RightResolution (Opposite.op X₂) where
functor := LeftResolution.opFunctor Φ X₂
inverse := (RightResolution.unopFunctor Φ (Opposite.op X₂)).rightOp
unitIso := Iso.refl _
counitIso := Iso.refl _
section
variable (L₂ : C₂ ⥤ D₂) [L₂.IsLocalization W₂]
lemma essSurj_of_hasRightResolutions [Φ.HasRightResolutions] : (Φ.functor ⋙ L₂).EssSurj where
mem_essImage X₂ := by
have := Localization.essSurj L₂ W₂
have R : Φ.RightResolution (L₂.objPreimage X₂) := Classical.arbitrary _
exact ⟨R.X₁, ⟨(Localization.isoOfHom L₂ W₂ _ R.hw).symm ≪≫ L₂.objObjPreimageIso X₂⟩⟩
lemma isIso_iff_of_hasRightResolutions [Φ.HasRightResolutions] {F G : D₂ ⥤ H} (α : F ⟶ G) :
IsIso α ↔ ∀ (X₁ : C₁), IsIso (α.app (L₂.obj (Φ.functor.obj X₁))) := by
constructor
· intros
infer_instance
· intro hα
have : ∀ (X₂ : D₂), IsIso (α.app X₂) := fun X₂ => by
have := Φ.essSurj_of_hasRightResolutions L₂
rw [← NatTrans.isIso_app_iff_of_iso α ((Φ.functor ⋙ L₂).objObjPreimageIso X₂)]
apply hα
exact NatIso.isIso_of_isIso_app α
lemma essSurj_of_hasLeftResolutions [Φ.HasLeftResolutions] : (Φ.functor ⋙ L₂).EssSurj where
mem_essImage X₂ := by
have := Localization.essSurj L₂ W₂
have L : Φ.LeftResolution (L₂.objPreimage X₂) := Classical.arbitrary _
exact ⟨L.X₁, ⟨Localization.isoOfHom L₂ W₂ _ L.hw ≪≫ L₂.objObjPreimageIso X₂⟩⟩
lemma isIso_iff_of_hasLeftResolutions [Φ.HasLeftResolutions] {F G : D₂ ⥤ H} (α : F ⟶ G) :
IsIso α ↔ ∀ (X₁ : C₁), IsIso (α.app (L₂.obj (Φ.functor.obj X₁))) := by
constructor
· intros
infer_instance
· intro hα
have : ∀ (X₂ : D₂), IsIso (α.app X₂) := fun X₂ => by
have := Φ.essSurj_of_hasLeftResolutions L₂
rw [← NatTrans.isIso_app_iff_of_iso α ((Φ.functor ⋙ L₂).objObjPreimageIso X₂)]
apply hα
exact NatIso.isIso_of_isIso_app α
end
end LocalizerMorphism
end CategoryTheory
|
ReflQuiv.lean
|
/-
Copyright (c) 2024 Mario Carneiro and Emily Riehl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Emily Riehl
-/
import Mathlib.Combinatorics.Quiver.ReflQuiver
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Category.Quiv
/-!
# The category of refl quivers
The category `ReflQuiv` of (bundled) reflexive quivers, and the free/forgetful adjunction between
`Cat` and `ReflQuiv`.
-/
namespace CategoryTheory
universe v u v₁ v₂ u₁ u₂
/-- Category of refl quivers. -/
@[nolint checkUnivs]
def ReflQuiv :=
Bundled ReflQuiver.{v + 1, u}
namespace ReflQuiv
instance : CoeSort ReflQuiv (Type u) where coe := Bundled.α
instance (C : ReflQuiv.{v, u}) : ReflQuiver.{v + 1, u} C := C.str
/-- The underlying quiver of a reflexive quiver -/
def toQuiv (C : ReflQuiv.{v, u}) : Quiv.{v, u} := Quiv.of C.α
/-- Construct a bundled `ReflQuiv` from the underlying type and the typeclass. -/
def of (C : Type u) [ReflQuiver.{v + 1} C] : ReflQuiv.{v, u} := Bundled.of C
instance : Inhabited ReflQuiv := ⟨ReflQuiv.of (Discrete default)⟩
@[simp] theorem of_val (C : Type u) [ReflQuiver C] : (ReflQuiv.of C) = C := rfl
/-- Category structure on `ReflQuiv` -/
instance category : LargeCategory.{max v u} ReflQuiv.{v, u} where
Hom C D := ReflPrefunctor C D
id C := ReflPrefunctor.id C
comp F G := ReflPrefunctor.comp F G
theorem id_eq_id (X : ReflQuiv) : 𝟙 X = 𝟭rq X := rfl
theorem comp_eq_comp {X Y Z : ReflQuiv} (F : X ⟶ Y) (G : Y ⟶ Z) : F ≫ G = F ⋙rq G := rfl
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forget : Cat.{v, u} ⥤ ReflQuiv.{v, u} where
obj C := ReflQuiv.of C
map F := F.toReflPrefunctor
theorem forget_faithful {C D : Cat.{v, u}} (F G : C ⥤ D)
(hyp : forget.map F = forget.map G) : F = G := by
cases F; cases G; cases hyp; rfl
instance forget.Faithful : Functor.Faithful (forget) where
map_injective := fun hyp ↦ forget_faithful _ _ hyp
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forgetToQuiv : ReflQuiv.{v, u} ⥤ Quiv.{v, u} where
obj V := Quiv.of V
map F := F.toPrefunctor
theorem forgetToQuiv_faithful {V W : ReflQuiv} (F G : V ⥤rq W)
(hyp : forgetToQuiv.map F = forgetToQuiv.map G) : F = G := by
cases F; cases G; cases hyp; rfl
instance forgetToQuiv.Faithful : Functor.Faithful forgetToQuiv where
map_injective := fun hyp ↦ forgetToQuiv_faithful _ _ hyp
theorem forget_forgetToQuiv : forget ⋙ forgetToQuiv = Quiv.forget := rfl
/-- An isomorphism of quivers lifts to an isomorphism of reflexive quivers given a suitable
compatibility with the identities. -/
def isoOfQuivIso {V W : Type u} [ReflQuiver V] [ReflQuiver W]
(e : Quiv.of V ≅ Quiv.of W)
(h_id : ∀ (X : V), e.hom.map (𝟙rq X) = ReflQuiver.id (obj := W) (e.hom.obj X)) :
ReflQuiv.of V ≅ ReflQuiv.of W where
hom := ReflPrefunctor.mk e.hom h_id
inv := ReflPrefunctor.mk e.inv
(fun Y => (Quiv.homEquivOfIso e).injective (by simp [Quiv.hom_map_inv_map_of_iso, h_id]))
hom_inv_id := by
apply forgetToQuiv.map_injective
exact e.hom_inv_id
inv_hom_id := by
apply forgetToQuiv.map_injective
exact e.inv_hom_id
/-- Compatible equivalences of types and hom-types induce an isomorphism of reflexive quivers. -/
def isoOfEquiv {V W : Type u} [ReflQuiver V] [ReflQuiver W] (e : V ≃ W)
(he : ∀ (X Y : V), (X ⟶ Y) ≃ (e X ⟶ e Y))
(h_id : ∀ (X : V), he _ _ (𝟙rq X) = ReflQuiver.id (obj := W) (e X)) :
ReflQuiv.of V ≅ ReflQuiv.of W := isoOfQuivIso (Quiv.isoOfEquiv e he) h_id
end ReflQuiv
namespace ReflPrefunctor
/-- A refl prefunctor can be promoted to a functor if it respects composition. -/
def toFunctor {C D : Cat} (F : (ReflQuiv.of C) ⟶ (ReflQuiv.of D))
(hyp : ∀ {X Y Z : ↑C} (f : X ⟶ Y) (g : Y ⟶ Z),
F.map (CategoryStruct.comp (obj := C) f g) =
CategoryStruct.comp (obj := D) (F.map f) (F.map g)) : C ⥤ D where
obj := F.obj
map := F.map
map_id := F.map_id
map_comp := hyp
end ReflPrefunctor
namespace Cat
/-- The hom relation that identifies the specified reflexivity arrows with the nil paths -/
inductive FreeReflRel {V} [ReflQuiver V] : (X Y : Paths V) → (f g : X ⟶ Y) → Prop
| mk {X : V} : FreeReflRel X X (Quiver.Hom.toPath (𝟙rq X)) .nil
/-- A reflexive quiver generates a free category, defined as as quotient of the free category
on its underlying quiver (called the "path category") by the hom relation that uses the specified
reflexivity arrows as the identity arrows. -/
def FreeRefl (V) [ReflQuiver V] := Quotient (C := Paths V) (FreeReflRel (V := V))
instance (V) [ReflQuiver V] : Category (FreeRefl V) :=
inferInstanceAs (Category (Quotient _))
/-- The quotient functor associated to a quotient category defines a natural map from the free
category on the underlying quiver of a refl quiver to the free category on the reflexive quiver. -/
def FreeRefl.quotientFunctor (V) [ReflQuiver V] : Paths V ⥤ FreeRefl V :=
Quotient.functor (C := Paths V) (FreeReflRel (V := V))
/-- This is a specialization of `Quotient.lift_unique'` rather than `Quotient.lift_unique`, hence
the prime in the name. -/
theorem FreeRefl.lift_unique' {V} [ReflQuiver V] {D} [Category D] (F₁ F₂ : FreeRefl V ⥤ D)
(h : quotientFunctor V ⋙ F₁ = quotientFunctor V ⋙ F₂) :
F₁ = F₂ :=
Quotient.lift_unique' (C := Cat.free.obj (Quiv.of V)) (FreeReflRel (V := V)) _ _ h
@[simp]
lemma FreeRefl.quotientFunctor_map_id (V) [ReflQuiver V] (X : V) :
(FreeRefl.quotientFunctor V).map (𝟙rq X).toPath = 𝟙 _ :=
Quotient.sound _ .mk
instance (V : Type*) [ReflQuiver V] [Unique V] : Unique (FreeRefl V) :=
letI : Unique (Paths V) := inferInstanceAs (Unique V)
inferInstanceAs (Unique (Quotient _))
instance (V : Type*) [ReflQuiver V] [Unique V]
[∀ (x y : V), Unique (x ⟶ y)] (x y : FreeRefl V) :
Unique (x ⟶ y) where
default := (FreeRefl.quotientFunctor V).map ((Paths.of V).map default)
uniq f := by
letI : Unique (Paths V) := inferInstanceAs (Unique V)
induction f using Quotient.induction with | @h x y f =>
rw [← FreeRefl.quotientFunctor]
symm
induction f using Paths.induction with
| id =>
apply Quotient.sound
obtain rfl : x = y := by subsingleton
rw [show (Paths.of V).map default = (𝟙rq _).toPath by congr; subsingleton]
exact .mk
| @comp x y z f g hrec =>
obtain rfl : x = z := by subsingleton
obtain rfl : x = y := by subsingleton
obtain rfl : g = 𝟙rq _ := by subsingleton
simp only [Paths.of_obj, ↓hrec, Paths.of_map, Functor.map_comp,
FreeRefl.quotientFunctor_map_id, Category.comp_id]
/-- A refl prefunctor `V ⥤rq W` induces a functor `FreeRefl V ⥤ FreeRefl W` defined using
`freeMap` and the quotient functor. -/
@[simps!]
def freeReflMap {V W : Type*} [ReflQuiver.{v₁ + 1} V] [ReflQuiver.{v₂ + 1} W] (F : V ⥤rq W) :
FreeRefl V ⥤ FreeRefl W :=
Quotient.lift _ (freeMap F.toPrefunctor ⋙ FreeRefl.quotientFunctor W) (by
rintro _ _ _ _ ⟨hfg⟩
apply Quotient.sound
simp [ReflPrefunctor.map_id]
constructor)
theorem freeReflMap_naturality
{V W : Type*} [ReflQuiver.{v₁ + 1} V] [ReflQuiver.{v₂ + 1} W] (F : V ⥤rq W) :
FreeRefl.quotientFunctor V ⋙ freeReflMap F =
freeMap F.toPrefunctor ⋙ FreeRefl.quotientFunctor W :=
Quotient.lift_spec _ _ _
/-- The functor sending a reflexive quiver to the free category it generates, a quotient of
its path category -/
@[simps!]
def freeRefl : ReflQuiv.{v, u} ⥤ Cat.{max u v, u} where
obj V := Cat.of (FreeRefl V)
map F := freeReflMap F
map_id X := by
refine (Quotient.lift_unique _ _ _ _ ((Functor.comp_id _).trans <|
(Functor.id_comp _).symm.trans ?_)).symm
congr 1
exact (free.map_id X.toQuiv).symm
map_comp {X Y Z} f g := by
apply (Quotient.lift_unique _ _ _ _ _).symm
change FreeRefl.quotientFunctor _ ⋙ _ = _
rw [Cat.comp_eq_comp, ← Functor.assoc, freeReflMap_naturality, Functor.assoc,
freeReflMap_naturality, ← Functor.assoc]
have : freeMap (f ≫ g).toPrefunctor =
freeMap f.toPrefunctor ⋙ freeMap g.toPrefunctor := by rw [← freeMap_comp]; rfl
rw [this]
/-- We will make use of the natural quotient map from the free category on the underlying
quiver of a refl quiver to the free category on the reflexive quiver. -/
def freeReflNatTrans : ReflQuiv.forgetToQuiv ⋙ Cat.free ⟶ freeRefl where
app V := FreeRefl.quotientFunctor V
naturality _ _ f := freeReflMap_naturality f
end Cat
namespace ReflQuiv
open Category Functor
/-- The unit components are defined as the composite of the corresponding unit component for the
adjunction between categories and quivers with the map underlying the quotient functor. -/
@[simps! toPrefunctor obj map]
def adj.unit.app (V : Type u) [ReflQuiver V] :
V ⥤rq forget.obj (Cat.freeRefl.obj (ReflQuiv.of V)) where
toPrefunctor := Paths.of V ⋙q (Cat.FreeRefl.quotientFunctor V).toPrefunctor
map_id := fun _ => Quotient.sound _ ⟨⟩
/-- This is used in the proof of both triangle equalities. -/
theorem adj.unit.map_app_eq (V : ReflQuiv.{max u v, u}) :
forgetToQuiv.map (adj.unit.app V) = Quiv.adj.unit.app (V.toQuiv) ≫
Quiv.forget.map (Y := Cat.of _) (Cat.FreeRefl.quotientFunctor V) := rfl
/-- The counit components are defined using the universal property of the quotient
from the corresponding counit component for the adjunction between categories and quivers. -/
@[simps!]
def adj.counit.app (C : Type u) [Category.{max u v} C] :
Cat.freeRefl.obj (ReflQuiv.of C) ⥤ C :=
Quotient.lift Cat.FreeReflRel (pathComposition C) (by
intro x y f g rel
cases rel
unfold pathComposition
simp only [composePath_toPath]
rfl)
/-- The counit of `ReflQuiv.adj` is closely related to the counit of `Quiv.adj`. -/
@[simp]
theorem adj.counit.comp_app_eq (C : Type u) [Category C] :
Cat.FreeRefl.quotientFunctor C ⋙ adj.counit.app C = pathComposition (Cat.of C) :=
rfl
/--
The adjunction between forming the free category on a reflexive quiver, and forgetting a category
to a reflexive quiver.
-/
nonrec def adj : Cat.freeRefl.{max u v, u} ⊣ ReflQuiv.forget :=
Adjunction.mkOfUnitCounit {
unit := {
app _ := adj.unit.app _
naturality _ _ _ := rfl
}
counit := {
app _ := adj.counit.app _
naturality _ _ F := Quotient.lift_unique' _ _ _ (Quiv.adj.counit.naturality F)
}
left_triangle := by
ext V
apply Cat.FreeRefl.lift_unique'
dsimp
conv => rhs; rw [Cat.id_eq_id]; apply Functor.comp_id
simp only [id_comp]
rw [Cat.comp_eq_comp, ← Functor.assoc]
change (Cat.FreeRefl.quotientFunctor _ ⋙ Cat.freeReflMap _) ⋙ _ = _
rw [Cat.freeReflMap_naturality, Functor.assoc]
dsimp only [Cat.freeRefl, Cat.free_obj, Cat.of_α, of_val, forget_obj,
adj.unit.app_toPrefunctor]
rw [adj.counit.comp_app_eq]
dsimp only [Cat.of_α]
rw [Cat.freeMap_comp, Functor.assoc, Quiv.pathComposition_naturality]
rw [← Functor.assoc]
have := Quiv.freeMap_pathsOf_pathComposition
simp only at this
rw [this]
exact Functor.id_comp _
right_triangle := by
ext C
dsimp
exact forgetToQuiv_faithful _ _ (Quiv.adj.right_triangle_components C)
}
end ReflQuiv
end CategoryTheory
|
all_solvable.v
|
From mathcomp Require Export abelian.
From mathcomp Require Export alt.
From mathcomp Require Export burnside_app.
From mathcomp Require Export center.
From mathcomp Require Export commutator.
From mathcomp Require Export cyclic.
From mathcomp Require Export extraspecial.
From mathcomp Require Export extremal.
From mathcomp Require Export finmodule.
From mathcomp Require Export frobenius.
From mathcomp Require Export gfunctor.
From mathcomp Require Export gseries.
From mathcomp Require Export hall.
From mathcomp Require Export jordanholder.
From mathcomp Require Export maximal.
From mathcomp Require Export nilpotent.
From mathcomp Require Export pgroup.
From mathcomp Require Export primitive_action.
From mathcomp Require Export sylow.
|
bigop.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div fintype tuple finfun.
(******************************************************************************)
(* Finitely iterated operators *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file provides a generic definition for iterating an operator over a *)
(* set of indices (bigop); this big operator is parameterized by the return *)
(* type (R), the type of indices (I), the operator (op), the default value on *)
(* empty lists (idx), the range of indices (r), the filter applied on this *)
(* range (P) and the expression we are iterating (F). The definition is not *)
(* to be used directly, but via the wide range of notations provided and *)
(* which support a natural use of big operators. *)
(* To improve performance of the Coq typechecker on large expressions, the *)
(* bigop constant is OPAQUE. It can however be unlocked to reveal the *)
(* transparent constant reducebig, to let Coq expand summation on an explicit *)
(* sequence with an explicit test. *)
(* The lemmas can be classified according to the operator being iterated: *)
(* 1. Results independent of the operator: extensionality with respect to *)
(* the range of indices, to the filtering predicate or to the expression *)
(* being iterated; reindexing, widening or narrowing of the range of *)
(* indices; we provide lemmas for the special cases where indices are *)
(* natural numbers or bounded natural numbers ("ordinals"). We supply *)
(* several "functional" induction principles that can be used with the *)
(* ssreflect 1.3 "elim" tactic to do induction over the index range for *)
(* up to 3 bigops simultaneously. *)
(* 2. Results depending on the properties of the operator: *)
(* We distinguish: *)
(* - semigroup laws (op is associative) *)
(* - commutative semigroup laws (semigroup laws, op is commutative) *)
(* - monoid laws (semigroup laws, idx is an identity element) *)
(* - abelian monoid laws (op is also commutative) *)
(* - laws with a distributive operation (semirings) *)
(* Examples of such results are splitting, permuting, and exchanging *)
(* bigops. *)
(* A special section is dedicated to big operators on natural numbers. *)
(******************************************************************************)
(* Notations: *)
(* The general form for iterated operators is *)
(* <bigop>_<range> <general_term> *)
(* - <bigop> is one of \big[op/idx], \sum, \prod, or \max (see below). *)
(* - <general_term> can be any expression. *)
(* - <range> binds an index variable in <general_term>; <range> is one of *)
(* (i <- s) i ranges over the sequence s. *)
(* (m <= i < n) i ranges over the nat interval m, m+1, ..., n-1. *)
(* (i < n) i ranges over the (finite) type 'I_n (i.e., ordinal n). *)
(* (i : T) i ranges over the finite type T. *)
(* i or (i) i ranges over its (inferred) finite type. *)
(* (i in A) i ranges over the elements that satisfy the collective *)
(* predicate A (the domain of A must be a finite type). *)
(* (i <- s | <condition>) limits the range to the i for which <condition> *)
(* holds. <condition> can be any expression that coerces to *)
(* bool, and may mention the bound index i. All six kinds of *)
(* ranges above can have a <condition> part. *)
(* - One can use the "\big[op/idx]" notations for any operator. *)
(* - BIG_F and BIG_P are pattern abbreviations for the <general_term> and *)
(* <condition> part of a \big ... expression; for (i in A) and (i in A | C) *)
(* ranges the term matched by BIG_P will include the i \in A condition. *)
(* - The (locked) head constant of a \big notation is bigop. *)
(* - The "\sum", "\prod" and "\max" notations in the %N scope are used for *)
(* natural numbers with addition, multiplication and maximum (and their *)
(* corresponding neutral elements), respectively. *)
(* - The "\sum" and "\prod" reserved notations are overloaded in ssralg in *)
(* the %R scope; in mxalgebra, vector & falgebra in the %MS and %VS scopes; *)
(* "\prod" is also overloaded in fingroup, in the %g and %G scopes. *)
(* - We reserve "\bigcup" and "\bigcap" notations for iterated union and *)
(* intersection (of sets, groups, vector spaces, etc.). *)
(******************************************************************************)
(* Tips for using lemmas in this file: *)
(* To apply a lemma for a specific operator: if no special property is *)
(* required for the operator, simply apply the lemma; if the lemma needs *)
(* certain properties for the operator, make sure the appropriate instances *)
(* are declared using, e.g., Check addn : Monoid.law _. to check that addn *)
(* is equipped with the monoid laws. *)
(******************************************************************************)
(* Interfaces for operator properties are packaged in the SemiGroup and *)
(* Monoid submodules: *)
(* SemiGroup.law == interface (keyed on the operator) for associative *)
(* operators *)
(* The HB class is SemiGroup. *)
(* SemiGroup.com_law == interface for associative and commutative operators *)
(* The HB class is SemiGroup.ComLaw. *)
(* Monoid.law idx == interface for associative operators with identity *)
(* element idx *)
(* The HB class is Monoid.Law. *)
(* Monoid.com_law idx == extension of Monoid.law for operators that are also *)
(* commutative *)
(* The HB class is Monoid.ComLaw. *)
(* Monoid.mul_law abz == interface for operators with absorbing (zero) *)
(* element abz *)
(* The HB class is Monoid.MulLaw. *)
(* Monoid.add_law idx mop == extension of Monoid.com_law for operators over *)
(* which operation mop distributes (mop will often also *)
(* have a Monoid.mul_law idx structure) *)
(* The HB class is Monoid.AddLaw. *)
(* SemiGroup.Theory == submodule containing basic generic algebra lemmas *)
(* for operators satisfying the SemiGroup interfaces *)
(* Monoid.Theory == submodule containing basic generic algebra lemmas *)
(* for operators satisfying the Monoid interfaces, *)
(* exports SemiGroup.Theory *)
(* Monoid.simpm == generic monoid simplification rewrite multirule *)
(* oAC op == convert an AC operator op : T -> T -> T *)
(* to a Monoid.com_law on option T *)
(* Monoid structures are predeclared for many basic operators: (_ && _)%B, *)
(* (_ || _)%B, (_ (+) _)%B (exclusive or), (_ + _)%N, (_ * _)%N, maxn, *)
(* gcdn, lcmn and (_ ++ _)%SEQ (list concatenation) *)
(******************************************************************************)
(* Reference: Y. Bertot, G. Gonthier, S. Ould Biha, I. Pasca, Canonical Big *)
(* Operators, TPHOLs 2008, LNCS vol. 5170, Springer, available at: *)
(* http://hal.inria.fr/docs/00/33/11/93/PDF/main.pdf *)
(******************************************************************************)
(* Examples of use in: poly.v, matrix.v *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope big_scope.
Reserved Notation "\big [ op / idx ]_ i F"
(at level 36, F at level 36, op, idx at level 10, i at level 0,
right associativity,
format "'[' \big [ op / idx ]_ i '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i <- r | P ) F"
(F at level 36, i, r at level 60,
format "'[' \big [ op / idx ]_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i <- r ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( m <= i < n | P ) F"
(F at level 36, i, n at level 60,
format "'[' \big [ op / idx ]_ ( m <= i < n | P ) F ']'").
Reserved Notation "\big [ op / idx ]_ ( m <= i < n ) F"
(at level 36, F at level 36,
format "'[' \big [ op / idx ]_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i | P ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i : t | P ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i : t ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i : t ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i < n | P ) F"
(F at level 36, n at level 60,
format "'[' \big [ op / idx ]_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i < n ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i < n ) F ']'").
Reserved Notation "\big [ op / idx ]_ ( i 'in' A | P ) F"
(F at level 36, A at level 60,
format "'[' \big [ op / idx ]_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\big [ op / idx ]_ ( i 'in' A ) F"
(F at level 36,
format "'[' \big [ op / idx ]_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\sum_ i F"
(at level 34, F at level 41, i at level 0,
right associativity,
format "'[' \sum_ i '/ ' F ']'").
Reserved Notation "\sum_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \sum_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i <- r ) F"
(F at level 41,
format "'[' \sum_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\sum_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \sum_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( m <= i < n ) F"
(F at level 41,
format "'[' \sum_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\sum_ ( i | P ) F"
(F at level 41,
format "'[' \sum_ ( i | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i : t | P ) F" (F at level 41). (* only parsing *)
Reserved Notation "\sum_ ( i : t ) F" (F at level 41). (* only parsing *)
Reserved Notation "\sum_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \sum_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i < n ) F"
(F at level 41,
format "'[' \sum_ ( i < n ) '/ ' F ']'").
Reserved Notation "\sum_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \sum_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\sum_ ( i 'in' A ) F"
(F at level 41,
format "'[' \sum_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \max_ i '/ ' F ']'").
Reserved Notation "\max_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i <- r ) F"
(F at level 41,
format "'[' \max_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max_ ( i | P ) F"
(F at level 41,
format "'[' \max_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i : t | P ) F" (F at level 41). (* only parsing *)
Reserved Notation "\max_ ( i : t ) F" (F at level 41). (* only parsing *)
Reserved Notation "\max_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i < n ) F"
(F at level 41, n at level 60,
format "'[' \max_ ( i < n ) F ']'").
Reserved Notation "\max_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\prod_ i F"
(at level 34, F at level 36, i at level 0,
format "'[' \prod_ i '/ ' F ']'").
Reserved Notation "\prod_ ( i <- r | P ) F"
(F at level 36, i, r at level 60,
format "'[' \prod_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i <- r ) F"
(F at level 36,
format "'[' \prod_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\prod_ ( m <= i < n | P ) F"
(F at level 36, i, n at level 60,
format "'[' \prod_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( m <= i < n ) F"
(F at level 36,
format "'[' \prod_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\prod_ ( i | P ) F"
(F at level 36,
format "'[' \prod_ ( i | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i : t | P ) F" (F at level 36). (* only parsing *)
Reserved Notation "\prod_ ( i : t ) F" (F at level 36). (* only parsing *)
Reserved Notation "\prod_ ( i < n | P ) F"
(F at level 36, n at level 60,
format "'[' \prod_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\prod_ ( i < n ) F"
(F at level 36,
format "'[' \prod_ ( i < n ) '/ ' F ']'").
Reserved Notation "\prod_ ( i 'in' A | P ) F"
(F at level 36, A at level 60,
format "'[' \prod_ ( i 'in' A | P ) F ']'").
Reserved Notation "\prod_ ( i 'in' A ) F"
(F at level 36,
format "'[' \prod_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\bigcup_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \bigcup_ i '/ ' F ']'").
Reserved Notation "\bigcup_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \bigcup_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i <- r ) F"
(F at level 41,
format "'[' \bigcup_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \bigcup_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( m <= i < n ) F"
(F at level 41,
format "'[' \bigcup_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i | P ) F"
(F at level 41,
format "'[' \bigcup_ ( i | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i : t | P ) F"
(F at level 41,
format "'[' \bigcup_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i : t ) F"
(F at level 41,
format "'[' \bigcup_ ( i : t ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \bigcup_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i < n ) F"
(F at level 41,
format "'[' \bigcup_ ( i < n ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \bigcup_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\bigcup_ ( i 'in' A ) F"
(F at level 41,
format "'[' \bigcup_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\bigcap_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \bigcap_ i '/ ' F ']'").
Reserved Notation "\bigcap_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \bigcap_ ( i <- r | P ) F ']'").
Reserved Notation "\bigcap_ ( i <- r ) F"
(F at level 41,
format "'[' \bigcap_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \bigcap_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( m <= i < n ) F"
(F at level 41,
format "'[' \bigcap_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i | P ) F"
(F at level 41,
format "'[' \bigcap_ ( i | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i : t | P ) F"
(F at level 41,
format "'[' \bigcap_ ( i : t | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i : t ) F"
(F at level 41,
format "'[' \bigcap_ ( i : t ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \bigcap_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i < n ) F"
(F at level 41,
format "'[' \bigcap_ ( i < n ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \bigcap_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\bigcap_ ( i 'in' A ) F"
(F at level 41,
format "'[' \bigcap_ ( i 'in' A ) '/ ' F ']'").
Module SemiGroup.
HB.mixin Record isLaw T (op : T -> T -> T) := {
opA : associative op;
}.
#[export]
HB.structure Definition Law T := {op of isLaw T op}.
Notation law := Law.type.
HB.mixin Record isCommutativeLaw T (op : T -> T -> T) := {
opC : commutative op;
}.
#[export]
HB.structure Definition ComLaw T := {op of Law T op & isCommutativeLaw T op}.
Notation com_law := ComLaw.type.
HB.factory Record isComLaw T (op : T -> T -> T) := {
opA : associative op;
opC : commutative op;
}.
HB.builders Context T op of isComLaw T op.
HB.instance Definition _ := isLaw.Build T op opA.
HB.instance Definition _ := isCommutativeLaw.Build T op opC.
HB.end.
Module Import Exports. HB.reexport. End Exports.
Module Theory.
Section Theory.
Variables (T : Type).
Section Plain.
Variable mul : law T.
Lemma mulmA : associative mul. Proof. exact: opA. Qed.
End Plain.
Section Commutative.
Variable mul : com_law T.
Lemma mulmC : commutative mul. Proof. exact: opC. Qed.
Lemma mulmCA : left_commutative mul.
Proof. by move=> x y z; rewrite !mulmA [_ x _]mulmC. Qed.
Lemma mulmAC : right_commutative mul.
Proof. by move=> x y z; rewrite -!mulmA [_ y _]mulmC. Qed.
Lemma mulmACA : interchange mul mul.
Proof. by move=> x y z t; rewrite -!mulmA [_ y _]mulmCA. Qed.
End Commutative.
End Theory.
End Theory.
Include Theory.
End SemiGroup.
Export SemiGroup.Exports.
Module Monoid.
Export SemiGroup.
HB.mixin Record isMonoidLaw T (idm : T) (op : T -> T -> T) := {
op1m : left_id idm op;
opm1 : right_id idm op;
}.
#[export]
HB.structure Definition Law T idm :=
{op of SemiGroup.Law T op & isMonoidLaw T idm op}.
Notation law := Law.type.
HB.factory Record isLaw T (idm : T) (op : T -> T -> T) := {
opA : associative op;
op1m : left_id idm op;
opm1 : right_id idm op;
}.
HB.builders Context T idm op of isLaw T idm op.
HB.instance Definition _ := SemiGroup.isLaw.Build T op opA.
HB.instance Definition _ := isMonoidLaw.Build T idm op op1m opm1.
HB.end.
#[export]
HB.structure Definition ComLaw T idm :=
{op of Law T idm op & isCommutativeLaw T op}.
Notation com_law := ComLaw.type.
HB.factory Record isComLaw T (idm : T) (op : T -> T -> T) := {
opA : associative op;
opC : commutative op;
op1m : left_id idm op;
}.
HB.builders Context T idm op of isComLaw T idm op.
Lemma opm1 : right_id idm op. Proof. by move=> x; rewrite opC op1m. Qed.
HB.instance Definition _ := isLaw.Build T idm op opA op1m opm1.
HB.instance Definition _ := isCommutativeLaw.Build T op opC.
HB.end.
HB.mixin Record isMulLaw T (zero : T) (mul : T -> T -> T) := {
mul_zerol : left_zero zero mul;
mul_zeror : right_zero zero mul;
}.
#[export]
HB.structure Definition MulLaw T zero := {mul of isMulLaw T zero mul}.
Notation mul_law := MulLaw.type.
HB.mixin Record isAddLaw T (mul : T -> T -> T) (op : T -> T -> T) := {
mul_op_Dl : left_distributive mul op;
mul_op_Dr : right_distributive mul op;
}.
#[export]
HB.structure Definition AddLaw T zero mul :=
{add of ComLaw T zero add & isAddLaw T mul add}.
Notation add_law := AddLaw.type.
Module Import Exports. HB.reexport. End Exports.
Section CommutativeAxioms.
Variable (T : Type) (zero one : T) (mul add : T -> T -> T).
Hypothesis mulC : commutative mul.
Lemma mulC_id : left_id one mul -> right_id one mul.
Proof. by move=> mul1x x; rewrite mulC. Qed.
Lemma mulC_zero : left_zero zero mul -> right_zero zero mul.
Proof. by move=> mul0x x; rewrite mulC. Qed.
Lemma mulC_dist : left_distributive mul add -> right_distributive mul add.
Proof. by move=> mul_addl x y z; rewrite !(mulC x). Qed.
End CommutativeAxioms.
Module Theory.
Export SemiGroup.Theory.
Section Theory.
Variables (T : Type) (idm : T).
Section Plain.
Variable mul : law idm.
Lemma mul1m : left_id idm mul. Proof. exact: op1m. Qed.
Lemma mulm1 : right_id idm mul. Proof. exact: opm1. Qed.
Lemma iteropE n x : iterop n mul x idm = iter n (mul x) idm.
Proof. by case: n => // n; rewrite iterSr mulm1 iteropS. Qed.
End Plain.
Section Mul.
Variable mul : mul_law idm.
Lemma mul0m : left_zero idm mul. Proof. exact: mul_zerol. Qed.
Lemma mulm0 : right_zero idm mul. Proof. exact: mul_zeror. Qed.
End Mul.
Section Add.
Variables (mul : T -> T -> T) (add : add_law idm mul).
Lemma addmA : associative add. Proof. exact: mulmA. Qed.
Lemma addmC : commutative add. Proof. exact: mulmC. Qed.
Lemma addmCA : left_commutative add. Proof. exact: mulmCA. Qed.
Lemma addmAC : right_commutative add. Proof. exact: mulmAC. Qed.
Lemma add0m : left_id idm add. Proof. exact: mul1m. Qed.
Lemma addm0 : right_id idm add. Proof. exact: mulm1. Qed.
Lemma mulmDl : left_distributive mul add. Proof. exact: mul_op_Dl. Qed.
Lemma mulmDr : right_distributive mul add. Proof. exact: mul_op_Dr. Qed.
End Add.
Definition simpm := (mulm1, mulm0, mul1m, mul0m, mulmA).
End Theory.
End Theory.
Include SemiGroup.Theory.
Include Theory.
End Monoid.
Export Monoid.Exports.
Section PervasiveMonoids.
Import Monoid.
HB.instance Definition _ := isComLaw.Build bool true andb andbA andbC andTb.
HB.instance Definition _ := isMulLaw.Build bool false andb andFb andbF.
HB.instance Definition _ := isComLaw.Build bool false orb orbA orbC orFb.
HB.instance Definition _ := isMulLaw.Build bool true orb orTb orbT.
HB.instance Definition _ := isComLaw.Build bool false addb addbA addbC addFb.
HB.instance Definition _ := isAddLaw.Build bool andb orb andb_orl andb_orr.
HB.instance Definition _ := isAddLaw.Build bool orb andb orb_andl orb_andr.
HB.instance Definition _ := isAddLaw.Build bool andb addb andb_addl andb_addr.
HB.instance Definition _ := isComLaw.Build nat 0 addn addnA addnC add0n.
HB.instance Definition _ := isComLaw.Build nat 1 muln mulnA mulnC mul1n.
HB.instance Definition _ := isMulLaw.Build nat 0 muln mul0n muln0.
HB.instance Definition _ := isAddLaw.Build nat muln addn mulnDl mulnDr.
HB.instance Definition _ := isComLaw.Build nat 0 maxn maxnA maxnC max0n.
HB.instance Definition _ := isAddLaw.Build nat muln maxn maxnMl maxnMr.
HB.instance Definition _ := isComLaw.Build nat 0 gcdn gcdnA gcdnC gcd0n.
HB.instance Definition _ := isAddLaw.Build nat muln gcdn muln_gcdl muln_gcdr.
HB.instance Definition _ := isComLaw.Build nat 1 lcmn lcmnA lcmnC lcm1n.
HB.instance Definition _ := isAddLaw.Build nat muln lcmn muln_lcml muln_lcmr.
HB.instance Definition _ T := isLaw.Build (seq T) nil cat
(@catA T) (@cat0s T) (@cats0 T).
End PervasiveMonoids.
(* Unit test for the [...law of ...] Notations
Definition myp := addn. Definition mym := muln.
Canonical myp_mon := [law of myp].
Canonical myp_cmon := [com_law of myp].
Canonical mym_mul := [mul_law of mym].
Canonical myp_add := [add_law _ of myp].
Print myp_add.
Print Canonical Projections.
*)
Delimit Scope big_scope with BIG.
Open Scope big_scope.
(* The bigbody wrapper is a workaround for a quirk of the Coq pretty-printer, *)
(* which would fail to redisplay the \big notation when the <general_term> or *)
(* <condition> do not depend on the bound index. The BigBody constructor *)
(* packages both in in a term in which i occurs; it also depends on the *)
(* iterated <op>, as this can give more information on the expected type of *)
(* the <general_term>, thus allowing for the insertion of coercions. *)
Variant bigbody R I := BigBody of I & (R -> R -> R) & bool & R.
Definition applybig {R I} (body : bigbody R I) x :=
let: BigBody _ op b v := body in if b then op v x else x.
Definition reducebig R I idx r (body : I -> bigbody R I) :=
foldr (applybig \o body) idx r.
HB.lock Definition bigop := reducebig.
Canonical bigop_unlock := Unlockable bigop.unlock.
Definition index_iota m n := iota m (n - m).
Lemma mem_index_iota m n i : i \in index_iota m n = (m <= i < n).
Proof.
rewrite mem_iota; case le_m_i: (m <= i) => //=.
by rewrite -leq_subLR subSn // -subn_gt0 -subnDA subnKC // subn_gt0.
Qed.
(* Legacy mathcomp scripts have been relying on the fact that enum A and *)
(* filter A (index_enum T) are convertible. This is likely to change in the *)
(* next mathcomp release when enum, pick, subset and card are generalised to *)
(* predicates with finite support in a choiceType - in fact the two will only *)
(* be equal up to permutation in this new theory. *)
(* It is therefore advisable to stop relying on this, and use the new *)
(* facilities provided in this library: lemmas big_enumP, big_enum, big_image *)
(* and such. Users wishing to test compliance should change the Defined in *)
(* index_enum_key to Qed, and comment out the filter_index_enum compatibility *)
(* definition below. *)
Fact index_enum_key : unit. Proof. split. Defined. (* Qed. *)
Definition index_enum (T : finType) :=
locked_with index_enum_key (Finite.enum T).
Lemma deprecated_filter_index_enum T P : filter P (index_enum T) = enum P.
Proof. by rewrite [index_enum T]unlock. Qed.
Lemma mem_index_enum T i : i \in index_enum T.
Proof. by rewrite [index_enum T]unlock -enumT mem_enum. Qed.
#[global] Hint Resolve mem_index_enum : core.
Lemma index_enum_uniq T : uniq (index_enum T).
Proof. by rewrite [index_enum T]unlock -enumT enum_uniq. Qed.
Notation "\big [ op / idx ]_ ( i <- r | P ) F" :=
(bigop idx r (fun i => BigBody i op P%B F)) : big_scope.
Notation "\big [ op / idx ]_ ( i <- r ) F" :=
(bigop idx r (fun i => BigBody i op true F)) : big_scope.
Notation "\big [ op / idx ]_ ( m <= i < n | P ) F" :=
(bigop idx (index_iota m n) (fun i : nat => BigBody i op P%B F))
: big_scope.
Notation "\big [ op / idx ]_ ( m <= i < n ) F" :=
(bigop idx (index_iota m n) (fun i : nat => BigBody i op true F))
: big_scope.
Notation "\big [ op / idx ]_ ( i | P ) F" :=
(bigop idx (index_enum _) (fun i => BigBody i op P%B F)) : big_scope.
Notation "\big [ op / idx ]_ i F" :=
(bigop idx (index_enum _) (fun i => BigBody i op true F)) : big_scope.
Notation "\big [ op / idx ]_ ( i : t | P ) F" :=
(bigop idx (index_enum _) (fun i : t => BigBody i op P%B F))
(only parsing) : big_scope.
Notation "\big [ op / idx ]_ ( i : t ) F" :=
(bigop idx (index_enum _) (fun i : t => BigBody i op true F))
(only parsing) : big_scope.
Notation "\big [ op / idx ]_ ( i < n | P ) F" :=
(\big[op/idx]_(i : ordinal n | P%B) F) : big_scope.
Notation "\big [ op / idx ]_ ( i < n ) F" :=
(\big[op/idx]_(i : ordinal n) F) : big_scope.
Notation "\big [ op / idx ]_ ( i 'in' A | P ) F" :=
(\big[op/idx]_(i | (i \in A) && P) F) : big_scope.
Notation "\big [ op / idx ]_ ( i 'in' A ) F" :=
(\big[op/idx]_(i | i \in A) F) : big_scope.
Notation BIG_F := (F in \big[_/_]_(i <- _ | _) F i)%pattern.
Notation BIG_P := (P in \big[_/_]_(i <- _ | P i) _)%pattern.
Local Notation "+%N" := addn (only parsing).
Notation "\sum_ ( i <- r | P ) F" :=
(\big[+%N/0%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\sum_ ( i <- r ) F" :=
(\big[+%N/0%N]_(i <- r) F%N) : nat_scope.
Notation "\sum_ ( m <= i < n | P ) F" :=
(\big[+%N/0%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\sum_ ( m <= i < n ) F" :=
(\big[+%N/0%N]_(m <= i < n) F%N) : nat_scope.
Notation "\sum_ ( i | P ) F" :=
(\big[+%N/0%N]_(i | P%B) F%N) : nat_scope.
Notation "\sum_ i F" :=
(\big[+%N/0%N]_i F%N) : nat_scope.
Notation "\sum_ ( i : t | P ) F" :=
(\big[+%N/0%N]_(i : t | P%B) F%N) (only parsing) : nat_scope.
Notation "\sum_ ( i : t ) F" :=
(\big[+%N/0%N]_(i : t) F%N) (only parsing) : nat_scope.
Notation "\sum_ ( i < n | P ) F" :=
(\big[+%N/0%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\sum_ ( i < n ) F" :=
(\big[+%N/0%N]_(i < n) F%N) : nat_scope.
Notation "\sum_ ( i 'in' A | P ) F" :=
(\big[+%N/0%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\sum_ ( i 'in' A ) F" :=
(\big[+%N/0%N]_(i in A) F%N) : nat_scope.
Local Notation "*%N" := muln (only parsing).
Notation "\prod_ ( i <- r | P ) F" :=
(\big[*%N/1%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\prod_ ( i <- r ) F" :=
(\big[*%N/1%N]_(i <- r) F%N) : nat_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
(\big[*%N/1%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\prod_ ( m <= i < n ) F" :=
(\big[*%N/1%N]_(m <= i < n) F%N) : nat_scope.
Notation "\prod_ ( i | P ) F" :=
(\big[*%N/1%N]_(i | P%B) F%N) : nat_scope.
Notation "\prod_ i F" :=
(\big[*%N/1%N]_i F%N) : nat_scope.
Notation "\prod_ ( i : t | P ) F" :=
(\big[*%N/1%N]_(i : t | P%B) F%N) (only parsing) : nat_scope.
Notation "\prod_ ( i : t ) F" :=
(\big[*%N/1%N]_(i : t) F%N) (only parsing) : nat_scope.
Notation "\prod_ ( i < n | P ) F" :=
(\big[*%N/1%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\prod_ ( i < n ) F" :=
(\big[*%N/1%N]_(i < n) F%N) : nat_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
(\big[*%N/1%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\prod_ ( i 'in' A ) F" :=
(\big[*%N/1%N]_(i in A) F%N) : nat_scope.
Notation "\max_ ( i <- r | P ) F" :=
(\big[maxn/0%N]_(i <- r | P%B) F%N) : nat_scope.
Notation "\max_ ( i <- r ) F" :=
(\big[maxn/0%N]_(i <- r) F%N) : nat_scope.
Notation "\max_ ( i | P ) F" :=
(\big[maxn/0%N]_(i | P%B) F%N) : nat_scope.
Notation "\max_ i F" :=
(\big[maxn/0%N]_i F%N) : nat_scope.
Notation "\max_ ( i : I | P ) F" :=
(\big[maxn/0%N]_(i : I | P%B) F%N) (only parsing) : nat_scope.
Notation "\max_ ( i : I ) F" :=
(\big[maxn/0%N]_(i : I) F%N) (only parsing) : nat_scope.
Notation "\max_ ( m <= i < n | P ) F" :=
(\big[maxn/0%N]_(m <= i < n | P%B) F%N) : nat_scope.
Notation "\max_ ( m <= i < n ) F" :=
(\big[maxn/0%N]_(m <= i < n) F%N) : nat_scope.
Notation "\max_ ( i < n | P ) F" :=
(\big[maxn/0%N]_(i < n | P%B) F%N) : nat_scope.
Notation "\max_ ( i < n ) F" :=
(\big[maxn/0%N]_(i < n) F%N) : nat_scope.
Notation "\max_ ( i 'in' A | P ) F" :=
(\big[maxn/0%N]_(i in A | P%B) F%N) : nat_scope.
Notation "\max_ ( i 'in' A ) F" :=
(\big[maxn/0%N]_(i in A) F%N) : nat_scope.
(* Induction loading *)
Lemma big_load R (K K' : R -> Type) idx op I r (P : pred I) F :
K (\big[op/idx]_(i <- r | P i) F i) * K' (\big[op/idx]_(i <- r | P i) F i)
-> K' (\big[op/idx]_(i <- r | P i) F i).
Proof. by case. Qed.
Arguments big_load [R] K [K'] idx op [I].
Section Elim3.
Variables (R1 R2 R3 : Type) (K : R1 -> R2 -> R3 -> Type).
Variables (id1 : R1) (op1 : R1 -> R1 -> R1).
Variables (id2 : R2) (op2 : R2 -> R2 -> R2).
Variables (id3 : R3) (op3 : R3 -> R3 -> R3).
Hypothesis Kid : K id1 id2 id3.
Lemma big_rec3 I r (P : pred I) F1 F2 F3
(K_F : forall i y1 y2 y3, P i -> K y1 y2 y3 ->
K (op1 (F1 i) y1) (op2 (F2 i) y2) (op3 (F3 i) y3)) :
K (\big[op1/id1]_(i <- r | P i) F1 i)
(\big[op2/id2]_(i <- r | P i) F2 i)
(\big[op3/id3]_(i <- r | P i) F3 i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed.
Hypothesis Kop : forall x1 x2 x3 y1 y2 y3,
K x1 x2 x3 -> K y1 y2 y3-> K (op1 x1 y1) (op2 x2 y2) (op3 x3 y3).
Lemma big_ind3 I r (P : pred I) F1 F2 F3
(K_F : forall i, P i -> K (F1 i) (F2 i) (F3 i)) :
K (\big[op1/id1]_(i <- r | P i) F1 i)
(\big[op2/id2]_(i <- r | P i) F2 i)
(\big[op3/id3]_(i <- r | P i) F3 i).
Proof. by apply: big_rec3 => i x1 x2 x3 /K_F; apply: Kop. Qed.
End Elim3.
Arguments big_rec3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ [I r P F1 F2 F3].
Arguments big_ind3 [R1 R2 R3] K [id1 op1 id2 op2 id3 op3] _ _ [I r P F1 F2 F3].
Section Elim2.
Variables (R1 R2 : Type) (K : R1 -> R2 -> Type) (f : R2 -> R1).
Variables (id1 : R1) (op1 : R1 -> R1 -> R1).
Variables (id2 : R2) (op2 : R2 -> R2 -> R2).
Hypothesis Kid : K id1 id2.
Lemma big_rec2 I r (P : pred I) F1 F2
(K_F : forall i y1 y2, P i -> K y1 y2 ->
K (op1 (F1 i) y1) (op2 (F2 i) y2)) :
K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: K_F. Qed.
Hypothesis Kop : forall x1 x2 y1 y2,
K x1 x2 -> K y1 y2 -> K (op1 x1 y1) (op2 x2 y2).
Lemma big_ind2 I r (P : pred I) F1 F2 (K_F : forall i, P i -> K (F1 i) (F2 i)) :
K (\big[op1/id1]_(i <- r | P i) F1 i) (\big[op2/id2]_(i <- r | P i) F2 i).
Proof. by apply: big_rec2 => i x1 x2 /K_F; apply: Kop. Qed.
Hypotheses (f_op : {morph f : x y / op2 x y >-> op1 x y}) (f_id : f id2 = id1).
Lemma big_morph I r (P : pred I) F :
f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i).
Proof. by rewrite unlock; elim: r => //= i r <-; rewrite -f_op -fun_if. Qed.
End Elim2.
Arguments big_rec2 [R1 R2] K [id1 op1 id2 op2] _ [I r P F1 F2].
Arguments big_ind2 [R1 R2] K [id1 op1 id2 op2] _ _ [I r P F1 F2].
Arguments big_morph [R1 R2] f [id1 op1 id2 op2] _ _ [I].
Section Elim1.
Variables (R : Type) (K : R -> Type) (f : R -> R).
Variables (idx : R) (op op' : R -> R -> R).
Hypothesis Kid : K idx.
Lemma big_rec I r (P : pred I) F
(Kop : forall i x, P i -> K x -> K (op (F i) x)) :
K (\big[op/idx]_(i <- r | P i) F i).
Proof. by rewrite unlock; elim: r => //= i r; case: ifP => //; apply: Kop. Qed.
Hypothesis Kop : forall x y, K x -> K y -> K (op x y).
Lemma big_ind I r (P : pred I) F (K_F : forall i, P i -> K (F i)) :
K (\big[op/idx]_(i <- r | P i) F i).
Proof. by apply: big_rec => // i x /K_F /Kop; apply. Qed.
Hypothesis Kop' : forall x y, K x -> K y -> op x y = op' x y.
Lemma eq_big_op I r (P : pred I) F (K_F : forall i, P i -> K (F i)) :
\big[op/idx]_(i <- r | P i) F i = \big[op'/idx]_(i <- r | P i) F i.
Proof.
by elim/(big_load K): _; elim/big_rec2: _ => // i _ y Pi [Ky <-]; auto.
Qed.
Hypotheses (fM : {morph f : x y / op x y}) (f_id : f idx = idx).
Lemma big_endo I r (P : pred I) F :
f (\big[op/idx]_(i <- r | P i) F i) = \big[op/idx]_(i <- r | P i) f (F i).
Proof. exact: big_morph. Qed.
End Elim1.
Arguments big_rec [R] K [idx op] _ [I r P F].
Arguments big_ind [R] K [idx op] _ _ [I r P F].
Arguments eq_big_op [R] K [idx op] op' _ _ _ [I].
Arguments big_endo [R] f [idx op] _ _ [I].
Lemma big_morph_in (R1 R2 : Type) (Q : {pred R2}) (f : R2 -> R1)
(id1 : R1) (op1 : R1 -> R1 -> R1)
(id2 : R2) (op2 : R2 -> R2 -> R2) :
{in Q &, forall x y, op2 x y \in Q} ->
id2 \in Q ->
{in Q &, {morph f : x y / op2 x y >-> op1 x y}} ->
f id2 = id1 ->
forall [I : Type] (r : seq I) (P : pred I) (F : I -> R2),
(forall i, P i -> F i \in Q) ->
f (\big[op2/id2]_(i <- r | P i) F i) = \big[op1/id1]_(i <- r | P i) f (F i).
Proof.
move=> Qop Qid fop fid I r P F QF; elim/(big_load Q): _.
by elim/big_rec2: _ => // j x y Pj [Qx <-]; rewrite [Q _]Qop ?fop ?QF.
Qed.
Arguments big_morph_in [R1 R2] Q f [id1 op1 id2 op2].
Section oAC.
Variables (T : Type) (op : T -> T -> T).
Definition oAC of associative op & commutative op :=
fun x => oapp (fun y => Some (oapp (op^~ y) y x)) x.
Arguments oAC : simpl never.
Hypothesis (opA : associative op) (opC : commutative op).
Local Notation oop := (oAC opA opC).
Lemma oACE x y : oop (Some x) (Some y) = some (op x y). Proof. by []. Qed.
Lemma oopA_subdef : associative oop.
Proof. by move=> [x|] [y|] [z|]//; rewrite /oAC/= opA. Qed.
Lemma oopx1_subdef : left_id None oop. Proof. by case. Qed.
Lemma oop1x_subdef : right_id None oop. Proof. by []. Qed.
Lemma oopC_subdef : commutative oop.
Proof. by move=> [x|] [y|]//; rewrite /oAC/= opC. Qed.
HB.instance Definition _ := Monoid.isComLaw.Build (option T) None oop
oopA_subdef oopC_subdef oopx1_subdef.
Context [x : T].
Lemma some_big_AC_mk_monoid [I : Type] r P (F : I -> T) :
Some (\big[op/x]_(i <- r | P i) F i) =
oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x).
Proof. by elim/big_rec2 : _ => //= i [y|] _ Pi [] -> //=; rewrite opA. Qed.
Lemma big_AC_mk_monoid [I : Type] r P (F : I -> T) :
\big[op/x]_(i <- r | P i) F i =
odflt x (oop (\big[oop/None]_(i <- r | P i) Some (F i)) (Some x)).
Proof. by apply: Some_inj; rewrite some_big_AC_mk_monoid. Qed.
End oAC.
Arguments oAC : simpl never.
Section Extensionality.
Variables (R : Type) (idx : R) (op : R -> R -> R).
Section SeqExtension.
Variable I : Type.
Lemma foldrE r : foldr op idx r = \big[op/idx]_(x <- r) x.
Proof. by rewrite unlock. Qed.
Lemma big_filter r (P : pred I) F :
\big[op/idx]_(i <- filter P r) F i = \big[op/idx]_(i <- r | P i) F i.
Proof. by rewrite unlock; elim: r => //= i r <-; case (P i). Qed.
Lemma big_filter_cond r (P1 P2 : pred I) F :
\big[op/idx]_(i <- filter P1 r | P2 i) F i
= \big[op/idx]_(i <- r | P1 i && P2 i) F i.
Proof.
rewrite -big_filter -(big_filter r); congr bigop.
by rewrite -filter_predI; apply: eq_filter => i; apply: andbC.
Qed.
Lemma eq_bigl r (P1 P2 : pred I) F :
P1 =1 P2 ->
\big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i.
Proof. by move=> eqP12; rewrite -!(big_filter r) (eq_filter eqP12). Qed.
(* A lemma to permute aggregate conditions. *)
Lemma big_andbC r (P Q : pred I) F :
\big[op/idx]_(i <- r | P i && Q i) F i
= \big[op/idx]_(i <- r | Q i && P i) F i.
Proof. by apply: eq_bigl => i; apply: andbC. Qed.
Lemma eq_bigr r (P : pred I) F1 F2 : (forall i, P i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r | P i) F1 i = \big[op/idx]_(i <- r | P i) F2 i.
Proof. by move=> eqF12; elim/big_rec2: _ => // i x _ /eqF12-> ->. Qed.
Lemma eq_big r (P1 P2 : pred I) F1 F2 :
P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r | P1 i) F1 i = \big[op/idx]_(i <- r | P2 i) F2 i.
Proof. by move/eq_bigl <-; move/eq_bigr->. Qed.
Lemma congr_big r1 r2 (P1 P2 : pred I) F1 F2 :
r1 = r2 -> P1 =1 P2 -> (forall i, P1 i -> F1 i = F2 i) ->
\big[op/idx]_(i <- r1 | P1 i) F1 i = \big[op/idx]_(i <- r2 | P2 i) F2 i.
Proof. by move=> <-{r2}; apply: eq_big. Qed.
Lemma big_nil (P : pred I) F : \big[op/idx]_(i <- [::] | P i) F i = idx.
Proof. by rewrite unlock. Qed.
Lemma big_cons i r (P : pred I) F :
let x := \big[op/idx]_(j <- r | P j) F j in
\big[op/idx]_(j <- i :: r | P j) F j = if P i then op (F i) x else x.
Proof. by rewrite unlock. Qed.
Lemma big_rcons_op i r (P : pred I) F :
let idx' := if P i then op (F i) idx else idx in
\big[op/idx]_(j <- rcons r i | P j) F j = \big[op/idx']_(j <- r | P j) F j.
Proof.
by elim: r => /= [|j r]; rewrite !(big_nil, big_cons, unlock)// => ->.
Qed.
Lemma big_map J (h : J -> I) r (P : pred I) F :
\big[op/idx]_(i <- map h r | P i) F i
= \big[op/idx]_(j <- r | P (h j)) F (h j).
Proof. by rewrite unlock; elim: r => //= j r ->. Qed.
Lemma big_nth x0 r (P : pred I) F :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(0 <= i < size r | P (nth x0 r i)) (F (nth x0 r i)).
Proof. by rewrite -[r in LHS](mkseq_nth x0) big_map /index_iota subn0. Qed.
Lemma big_hasC r (P : pred I) F :
~~ has P r -> \big[op/idx]_(i <- r | P i) F i = idx.
Proof.
by rewrite -big_filter has_count -size_filter -eqn0Ngt unlock => /nilP->.
Qed.
Lemma big_pred0_eq (r : seq I) F : \big[op/idx]_(i <- r | false) F i = idx.
Proof. by rewrite big_hasC // has_pred0. Qed.
Lemma big_pred0 r (P : pred I) F :
P =1 xpred0 -> \big[op/idx]_(i <- r | P i) F i = idx.
Proof. by move/eq_bigl->; apply: big_pred0_eq. Qed.
Lemma big_cat_nested r1 r2 (P : pred I) F :
let x := \big[op/idx]_(i <- r2 | P i) F i in
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/x]_(i <- r1 | P i) F i.
Proof. by rewrite unlock /reducebig foldr_cat. Qed.
Lemma big_catl r1 r2 (P : pred I) F :
~~ has P r2 ->
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r1 | P i) F i.
Proof. by rewrite big_cat_nested => /big_hasC->. Qed.
Lemma big_catr r1 r2 (P : pred I) F :
~~ has P r1 ->
\big[op/idx]_(i <- r1 ++ r2 | P i) F i = \big[op/idx]_(i <- r2 | P i) F i.
Proof.
rewrite -big_filter -(big_filter r2) filter_cat.
by rewrite has_count -size_filter; case: filter.
Qed.
End SeqExtension.
Lemma big_map_id J (h : J -> R) r (P : pred R) :
\big[op/idx]_(i <- map h r | P i) i
= \big[op/idx]_(j <- r | P (h j)) h j.
Proof. exact: big_map. Qed.
Lemma big_condT (J : finType) (A : {pred J}) F :
\big[op/idx]_(i in A | true) F i = \big[op/idx]_(i in A) F i.
Proof. by apply: eq_bigl => i; exact: andbT. Qed.
(* The following lemmas can be used to localise extensionality to a specific *)
(* index sequence. This is done by ssreflect rewriting, before applying *)
(* congruence or induction lemmas. *)
Lemma big_seq_cond (I : eqType) r (P : pred I) F :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(i <- r | (i \in r) && P i) F i.
Proof.
by rewrite -!(big_filter r); congr bigop; apply: eq_in_filter => i ->.
Qed.
Lemma big_seq (I : eqType) (r : seq I) F :
\big[op/idx]_(i <- r) F i = \big[op/idx]_(i <- r | i \in r) F i.
Proof. by rewrite big_seq_cond big_andbC. Qed.
Lemma eq_big_seq (I : eqType) (r : seq I) F1 F2 :
{in r, F1 =1 F2} -> \big[op/idx]_(i <- r) F1 i = \big[op/idx]_(i <- r) F2 i.
Proof. by move=> eqF; rewrite !big_seq (eq_bigr _ eqF). Qed.
(* Similar lemmas for exposing integer indexing in the predicate. *)
Lemma big_nat_cond m n (P : pred nat) F :
\big[op/idx]_(m <= i < n | P i) F i
= \big[op/idx]_(m <= i < n | (m <= i < n) && P i) F i.
Proof.
by rewrite big_seq_cond; apply: eq_bigl => i; rewrite mem_index_iota.
Qed.
Lemma big_nat m n F :
\big[op/idx]_(m <= i < n) F i = \big[op/idx]_(m <= i < n | m <= i < n) F i.
Proof. by rewrite big_nat_cond big_andbC. Qed.
Lemma congr_big_nat m1 n1 m2 n2 P1 P2 F1 F2 :
m1 = m2 -> n1 = n2 ->
(forall i, m1 <= i < n2 -> P1 i = P2 i) ->
(forall i, P1 i && (m1 <= i < n2) -> F1 i = F2 i) ->
\big[op/idx]_(m1 <= i < n1 | P1 i) F1 i
= \big[op/idx]_(m2 <= i < n2 | P2 i) F2 i.
Proof.
move=> <- <- eqP12 eqF12; rewrite big_seq_cond (big_seq_cond _ P2).
apply: eq_big => i; rewrite ?inE /= !mem_index_iota.
by apply: andb_id2l; apply: eqP12.
by rewrite andbC; apply: eqF12.
Qed.
Lemma eq_big_nat m n F1 F2 :
(forall i, m <= i < n -> F1 i = F2 i) ->
\big[op/idx]_(m <= i < n) F1 i = \big[op/idx]_(m <= i < n) F2 i.
Proof. by move=> eqF; apply: congr_big_nat. Qed.
Lemma big_geq m n (P : pred nat) F :
m >= n -> \big[op/idx]_(m <= i < n | P i) F i = idx.
Proof. by move=> ge_m_n; rewrite /index_iota (eqnP ge_m_n) big_nil. Qed.
Lemma big_ltn_cond m n (P : pred nat) F :
m < n -> let x := \big[op/idx]_(m.+1 <= i < n | P i) F i in
\big[op/idx]_(m <= i < n | P i) F i = if P m then op (F m) x else x.
Proof. by case: n => [//|n] le_m_n; rewrite /index_iota subSn // big_cons. Qed.
Lemma big_ltn m n F :
m < n ->
\big[op/idx]_(m <= i < n) F i = op (F m) (\big[op/idx]_(m.+1 <= i < n) F i).
Proof. by move=> lt_mn; apply: big_ltn_cond. Qed.
Lemma big_addn m n a (P : pred nat) F :
\big[op/idx]_(m + a <= i < n | P i) F i =
\big[op/idx]_(m <= i < n - a | P (i + a)) F (i + a).
Proof.
rewrite /index_iota -subnDA addnC iotaDl big_map.
by apply: eq_big => ? *; rewrite addnC.
Qed.
Lemma big_add1 m n (P : pred nat) F :
\big[op/idx]_(m.+1 <= i < n | P i) F i =
\big[op/idx]_(m <= i < n.-1 | P (i.+1)) F (i.+1).
Proof.
by rewrite -addn1 big_addn subn1; apply: eq_big => ? *; rewrite addn1.
Qed.
Lemma big_nat_recl n m F : m <= n ->
\big[op/idx]_(m <= i < n.+1) F i =
op (F m) (\big[op/idx]_(m <= i < n) F i.+1).
Proof. by move=> lemn; rewrite big_ltn // big_add1. Qed.
Lemma big_mkord n (P : pred nat) F :
\big[op/idx]_(0 <= i < n | P i) F i = \big[op/idx]_(i < n | P i) F i.
Proof.
rewrite /index_iota subn0 -(big_map (@nat_of_ord n)).
by congr bigop; rewrite /index_enum 2!unlock val_ord_enum.
Qed.
Lemma big_mknat n (P : pred 'I_n.+1) F :
\big[op/idx]_(i < n.+1 | P i) F i
= \big[op/idx]_(0 <= i < n.+1 | P (inord i)) F (inord i).
Proof. by rewrite big_mkord; apply: eq_big => ?; rewrite inord_val. Qed.
Lemma big_nat_widen m n1 n2 (P : pred nat) F :
n1 <= n2 ->
\big[op/idx]_(m <= i < n1 | P i) F i
= \big[op/idx]_(m <= i < n2 | P i && (i < n1)) F i.
Proof.
move=> len12; symmetry; rewrite -big_filter filter_predI big_filter.
have [ltn_trans eq_by_mem] := (ltn_trans, irr_sorted_eq ltn_trans ltnn).
congr bigop; apply: eq_by_mem; rewrite ?sorted_filter ?iota_ltn_sorted // => i.
rewrite mem_filter !mem_index_iota andbCA andbA andb_idr => // /andP[_].
by move/leq_trans->.
Qed.
Lemma big_ord_widen_cond n1 n2 (P : pred nat) (F : nat -> R) :
n1 <= n2 ->
\big[op/idx]_(i < n1 | P i) F i
= \big[op/idx]_(i < n2 | P i && (i < n1)) F i.
Proof. by move/big_nat_widen=> len12; rewrite -big_mkord len12 big_mkord. Qed.
Lemma big_ord_widen n1 n2 (F : nat -> R) :
n1 <= n2 ->
\big[op/idx]_(i < n1) F i = \big[op/idx]_(i < n2 | i < n1) F i.
Proof. by move=> le_n12; apply: (big_ord_widen_cond (predT)). Qed.
Lemma big_ord_widen_leq n1 n2 (P : pred 'I_(n1.+1)) F :
n1 < n2 ->
\big[op/idx]_(i < n1.+1 | P i) F i
= \big[op/idx]_(i < n2 | P (inord i) && (i <= n1)) F (inord i).
Proof.
move=> len12; pose g G i := G (inord i : 'I_(n1.+1)).
rewrite -(big_ord_widen_cond (g _ P) (g _ F) len12) {}/g.
by apply: eq_big => i *; rewrite inord_val.
Qed.
Lemma big_ord0 P F : \big[op/idx]_(i < 0 | P i) F i = idx.
Proof. by rewrite big_pred0 => [|[]]. Qed.
Lemma big_mask_tuple I n m (t : n.-tuple I) (P : pred I) F :
\big[op/idx]_(i <- mask m t | P i) F i
= \big[op/idx]_(i < n | nth false m i && P (tnth t i)) F (tnth t i).
Proof.
rewrite [t in LHS]tuple_map_ord/= -map_mask big_map.
by rewrite mask_enum_ord big_filter_cond/= enumT.
Qed.
Lemma big_mask I r m (P : pred I) (F : I -> R) (r_ := tnth (in_tuple r)) :
\big[op/idx]_(i <- mask m r | P i) F i
= \big[op/idx]_(i < size r | nth false m i && P (r_ i)) F (r_ i).
Proof. exact: (big_mask_tuple _ (in_tuple r)). Qed.
Lemma big_tnth I r (P : pred I) F (r_ := tnth (in_tuple r)) :
\big[op/idx]_(i <- r | P i) F i
= \big[op/idx]_(i < size r | P (r_ i)) (F (r_ i)).
Proof.
rewrite /= -[r in LHS](mask_true (leqnn (size r))) big_mask//.
by apply: eq_bigl => i /=; rewrite nth_nseq ltn_ord.
Qed.
Lemma big_index_uniq (I : eqType) (r : seq I) (E : 'I_(size r) -> R) :
uniq r ->
\big[op/idx]_i E i = \big[op/idx]_(x <- r) oapp E idx (insub (index x r)).
Proof.
move=> Ur; apply/esym; rewrite big_tnth.
by under [LHS]eq_bigr do rewrite index_uniq// valK.
Qed.
Lemma big_tuple I n (t : n.-tuple I) (P : pred I) F :
\big[op/idx]_(i <- t | P i) F i
= \big[op/idx]_(i < n | P (tnth t i)) F (tnth t i).
Proof. by rewrite big_tnth tvalK; case: _ / (esym _). Qed.
Lemma big_ord_narrow_cond n1 n2 (P : pred 'I_n2) F (le_n12 : n1 <= n2) :
let w := widen_ord le_n12 in
\big[op/idx]_(i < n2 | P i && (i < n1)) F i
= \big[op/idx]_(i < n1 | P (w i)) F (w i).
Proof.
case: n1 => [|n1] /= in le_n12 *.
by rewrite big_ord0 big_pred0 // => i; rewrite andbF.
rewrite (big_ord_widen_leq _ _ le_n12); apply: eq_big => i.
by apply: andb_id2r => le_i_n1; congr P; apply: val_inj; rewrite /= inordK.
by case/andP=> _ le_i_n1; congr F; apply: val_inj; rewrite /= inordK.
Qed.
Lemma big_ord_narrow_cond_leq n1 n2 (P : pred _) F (le_n12 : n1 <= n2) :
let w := @widen_ord n1.+1 n2.+1 le_n12 in
\big[op/idx]_(i < n2.+1 | P i && (i <= n1)) F i
= \big[op/idx]_(i < n1.+1 | P (w i)) F (w i).
Proof. exact: (@big_ord_narrow_cond n1.+1 n2.+1). Qed.
Lemma big_ord_narrow n1 n2 F (le_n12 : n1 <= n2) :
let w := widen_ord le_n12 in
\big[op/idx]_(i < n2 | i < n1) F i = \big[op/idx]_(i < n1) F (w i).
Proof. exact: (big_ord_narrow_cond (predT)). Qed.
Lemma big_ord_narrow_leq n1 n2 F (le_n12 : n1 <= n2) :
let w := @widen_ord n1.+1 n2.+1 le_n12 in
\big[op/idx]_(i < n2.+1 | i <= n1) F i = \big[op/idx]_(i < n1.+1) F (w i).
Proof. exact: (big_ord_narrow_cond_leq (predT)). Qed.
Lemma big_ord_recl n F :
\big[op/idx]_(i < n.+1) F i =
op (F ord0) (\big[op/idx]_(i < n) F (@lift n.+1 ord0 i)).
Proof.
pose G i := F (inord i); have eqFG i: F i = G i by rewrite /G inord_val.
under eq_bigr do rewrite eqFG; under [in RHS]eq_bigr do rewrite eqFG.
by rewrite -(big_mkord _ (fun _ => _) G) eqFG big_ltn // big_add1 /= big_mkord.
Qed.
Lemma big_nseq_cond I n a (P : pred I) F :
\big[op/idx]_(i <- nseq n a | P i) F i
= if P a then iter n (op (F a)) idx else idx.
Proof. by rewrite unlock; elim: n => /= [|n ->]; case: (P a). Qed.
Lemma big_nseq I n a (F : I -> R):
\big[op/idx]_(i <- nseq n a) F i = iter n (op (F a)) idx.
Proof. exact: big_nseq_cond. Qed.
End Extensionality.
Variant big_enum_spec (I : finType) (P : pred I) : seq I -> Type :=
BigEnumSpec e of
forall R idx op (F : I -> R),
\big[op/idx]_(i <- e) F i = \big[op/idx]_(i | P i) F i
& uniq e /\ (forall i, i \in e = P i)
& (let cP := [pred i | P i] in perm_eq e (enum cP) /\ size e = #|cP|)
: big_enum_spec P e.
(* This lemma can be used to introduce an enumeration into a non-abelian *)
(* bigop, in one of three ways: *)
(* have [e big_e [Ue mem_e] [e_enum size_e]] := big_enumP P. *)
(* gives a permutation e of enum P alongside a equation big_e for converting *)
(* between bigops iterating on (i <- e) and ones on (i | P i). Usually not *)
(* all properties of e are needed, but see below the big_distr_big_dep proof *)
(* where most are. *)
(* rewrite -big_filter; have [e ...] := big_enumP. *)
(* uses big_filter to do this conversion first, and then abstracts the *)
(* resulting filter P (index_enum T) enumeration as an e with the same *)
(* properties (see big_enum_cond below for an example of this usage). *)
(* Finally *)
(* rewrite -big_filter; case def_e: _ / big_enumP => [e ...] *)
(* does the same while remembering the definition of e. *)
Lemma big_enumP I P : big_enum_spec P (filter P (index_enum I)).
Proof.
set e := filter P _; have Ue: uniq e by apply/filter_uniq/index_enum_uniq.
have mem_e i: i \in e = P i by rewrite mem_filter mem_index_enum andbT.
split=> // [R idx op F | cP]; first by rewrite big_filter.
suffices De: perm_eq e (enum cP) by rewrite (perm_size De) cardE.
by apply/uniq_perm=> // [|i]; rewrite ?enum_uniq ?mem_enum ?mem_e.
Qed.
Section BigConst.
Variables (R : Type) (idx : R) (op : R -> R -> R).
Lemma big_const_seq I r (P : pred I) x :
\big[op/idx]_(i <- r | P i) x = iter (count P r) (op x) idx.
Proof. by rewrite unlock; elim: r => //= i r ->; case: (P i). Qed.
Lemma big_const (I : finType) (A : {pred I}) x :
\big[op/idx]_(i in A) x = iter #|A| (op x) idx.
Proof.
by have [e <- _ [_ <-]] := big_enumP A; rewrite big_const_seq count_predT.
Qed.
Lemma big_const_nat m n x :
\big[op/idx]_(m <= i < n) x = iter (n - m) (op x) idx.
Proof. by rewrite big_const_seq count_predT size_iota. Qed.
Lemma big_const_ord n x :
\big[op/idx]_(i < n) x = iter n (op x) idx.
Proof. by rewrite big_const card_ord. Qed.
End BigConst.
Section Plain.
Variable R : Type.
Variable op : R -> R -> R.
Variable x : R.
Lemma big_seq1_id I (i : I) (F : I -> R) :
\big[op/x]_(j <- [:: i]) F j = op (F i) x.
Proof. by rewrite big_cons big_nil. Qed.
Lemma big_nat1_id n F : \big[op/x]_(n <= i < n.+1) F i = op (F n) x.
Proof. by rewrite big_ltn // big_geq // mulm1. Qed.
Lemma big_pred1_eq_id (I : finType) (i : I) F :
\big[op/x]_(j | j == i) F j = op (F i) x.
Proof.
have [e1 <- _ [e_enum _]] := big_enumP (pred1 i).
by rewrite (perm_small_eq _ e_enum) enum1 ?big_seq1_id.
Qed.
Lemma big_pred1_id (I : finType) i (P : pred I) F :
P =1 pred1 i -> \big[op/x]_(j | P j) F j = op (F i) x.
Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq_id. Qed.
End Plain.
Section SemiGroupProperties.
Variable R : Type.
#[local] Notation opA := SemiGroup.opA.
#[local] Notation opC := SemiGroup.opC.
Section Id.
Variable op : SemiGroup.law R.
Variable x : R.
Hypothesis opxx : op x x = x.
Lemma big_const_idem I (r : seq I) P : \big[op/x]_(i <- r | P i) x = x.
Proof. by elim/big_ind : _ => // _ _ -> ->. Qed.
Lemma big1_idem I r (P : pred I) F :
(forall i, P i -> F i = x) -> \big[op/x]_(i <- r | P i) F i = x.
Proof.
move=> Fix; under eq_bigr => ? ? do rewrite Fix//; exact: big_const_idem.
Qed.
Lemma big_id_idem I (r : seq I) P F :
op (\big[op/x]_(i <- r | P i) F i) x = \big[op/x]_(i <- r | P i) F i.
Proof. by elim/big_rec : _ => // ? ? ?; rewrite -opA => ->. Qed.
End Id.
Section Abelian.
Variable op : SemiGroup.com_law R.
Let opCA : left_commutative op.
Proof. by move=> x *; rewrite !opA /= (opC x). Qed.
Variable x : R.
Lemma big_rem_AC (I : eqType) (r : seq I) z (P : pred I) F : z \in r ->
\big[op/x]_(y <- r | P y) F y
= if P z then op (F z) (\big[op/x]_(y <- rem z r | P y) F y)
else \big[op/x]_(y <- rem z r | P y) F y.
Proof.
elim: r =>// i r ih; rewrite big_cons rem_cons inE =>/predU1P[-> /[!eqxx]//|zr].
by case: eqP => [-> //|]; rewrite ih// big_cons; case: ifPn; case: ifPn.
Qed.
Lemma big_undup (I : eqType) (r : seq I) (P : pred I) F :
idempotent_op op ->
\big[op/x]_(i <- undup r | P i) F i = \big[op/x]_(i <- r | P i) F i.
Proof.
move=> opxx; rewrite -!(big_filter _ _ _ P) filter_undup.
elim: {P r}(filter P r) => //= i r IHr.
case: ifP => [r_i | _]; rewrite !big_cons {}IHr //.
by rewrite (big_rem_AC _ _ r_i) opA /= opxx.
Qed.
Lemma perm_big (I : eqType) r1 r2 (P : pred I) F :
perm_eq r1 r2 ->
\big[op/x]_(i <- r1 | P i) F i = \big[op/x]_(i <- r2 | P i) F i.
Proof.
elim: r1 r2 => [|i r1 IHr1] r2 eq_r12.
by case: r2 eq_r12 => [//|i r2] /[1!perm_sym] /perm_nilP.
have r2i: i \in r2 by rewrite -has_pred1 has_count -(permP eq_r12) /= eqxx.
rewrite big_cons (IHr1 (rem i r2)) -?big_rem_AC// -(perm_cons i).
exact: perm_trans (perm_to_rem _).
Qed.
Lemma big_enum_cond (I : finType) (A : {pred I}) (P : pred I) F :
\big[op/x]_(i <- enum A | P i) F i = \big[op/x]_(i in A | P i) F i.
Proof.
by rewrite -big_filter_cond; have [e _ _ [/perm_big->]] := big_enumP.
Qed.
Lemma big_enum (I : finType) (A : {pred I}) F :
\big[op/x]_(i <- enum A) F i = \big[op/x]_(i in A) F i.
Proof. by rewrite big_enum_cond big_andbC. Qed.
Lemma big_uniq (I : finType) (r : seq I) F :
uniq r -> \big[op/x]_(i <- r) F i = \big[op/x]_(i in r) F i.
Proof.
move=> uniq_r; rewrite -big_enum; apply: perm_big.
by rewrite uniq_perm ?enum_uniq // => i; rewrite mem_enum.
Qed.
Lemma bigD1 (I : finType) j (P : pred I) F :
P j -> \big[op/x]_(i | P i) F i
= op (F j) (\big[op/x]_(i | P i && (i != j)) F i).
Proof.
rewrite (big_rem_AC _ _ (mem_index_enum j)) => ->.
by rewrite rem_filter ?index_enum_uniq// big_filter_cond big_andbC.
Qed.
Arguments bigD1 [I] j [P F].
Lemma bigD1_seq (I : eqType) (r : seq I) j F :
j \in r -> uniq r ->
\big[op/x]_(i <- r) F i = op (F j) (\big[op/x]_(i <- r | i != j) F i).
Proof. by move=> /big_rem_AC-> /rem_filter->; rewrite big_filter. Qed.
Lemma big_image_cond I (J : finType) (h : J -> I) (A : pred J) (P : pred I) F :
\big[op/x]_(i <- [seq h j | j in A] | P i) F i
= \big[op/x]_(j in A | P (h j)) F (h j).
Proof. by rewrite big_map big_enum_cond. Qed.
Lemma big_image I (J : finType) (h : J -> I) (A : pred J) F :
\big[op/x]_(i <- [seq h j | j in A]) F i = \big[op/x]_(j in A) F (h j).
Proof. by rewrite big_map big_enum. Qed.
Lemma cardD1x (I : finType) (A : pred I) j :
A j -> #|SimplPred A| = 1 + #|[pred i | A i & i != j]|.
Proof.
move=> Aj; rewrite (cardD1 j) [j \in A]Aj; congr (_ + _).
by apply: eq_card => i; rewrite inE /= andbC.
Qed.
Arguments cardD1x [I A].
Lemma reindex_omap (I J : finType) (h : J -> I) h' (P : pred I) F :
(forall i, P i -> omap h (h' i) = some i) ->
\big[op/x]_(i | P i) F i =
\big[op/x]_(j | P (h j) && (h' (h j) == some j)) F (h j).
Proof.
move=> h'K; have [n lePn] := ubnP #|P|; elim: n => // n IHn in P h'K lePn *.
case: (pickP P) => [i Pi | P0]; last first.
by rewrite !big_pred0 // => j; rewrite P0.
have := h'K i Pi; case h'i_eq : (h' i) => [/= j|//] [hj_eq].
rewrite (bigD1 i Pi) (bigD1 j) hj_eq ?Pi ?h'i_eq ?eqxx //=; congr (op : _ -> _).
rewrite {}IHn => [|k /andP[]|]; [|by auto | by rewrite (cardD1x i) in lePn].
apply: eq_bigl => k; rewrite andbC -andbA (andbCA (P _)); case: eqP => //= hK.
congr (_ && ~~ _); apply/eqP/eqP => [|->//].
by move=> /(congr1 h'); rewrite h'i_eq hK => -[].
Qed.
Arguments reindex_omap [I J] h h' [P F].
Lemma reindex_onto (I J : finType) (h : J -> I) h' (P : pred I) F :
(forall i, P i -> h (h' i) = i) ->
\big[op/x]_(i | P i) F i =
\big[op/x]_(j | P (h j) && (h' (h j) == j)) F (h j).
Proof.
by move=> h'K; rewrite (reindex_omap h (some \o h'))//= => i Pi; rewrite h'K.
Qed.
Arguments reindex_onto [I J] h h' [P F].
Lemma reindex (I J : finType) (h : J -> I) (P : pred I) F :
{on [pred i | P i], bijective h} ->
\big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j).
Proof.
case=> h' hK h'K; rewrite (reindex_onto h h' h'K).
by apply: eq_bigl => j /[!inE]; case Pi: (P _); rewrite //= hK ?eqxx.
Qed.
Arguments reindex [I J] h [P F].
Lemma reindex_inj (I : finType) (h : I -> I) (P : pred I) F :
injective h -> \big[op/x]_(i | P i) F i = \big[op/x]_(j | P (h j)) F (h j).
Proof. by move=> injh; apply: reindex (onW_bij _ (injF_bij injh)). Qed.
Arguments reindex_inj [I h P F].
Lemma bigD1_ord n j (P : pred 'I_n) F :
P j -> \big[op/x]_(i < n | P i) F i
= op (F j) (\big[op/x]_(i < n.-1 | P (lift j i)) F (lift j i)).
Proof.
move=> Pj; rewrite (bigD1 j Pj) (reindex_omap (lift j) (unlift j))/=.
by under eq_bigl do rewrite liftK eq_sym eqxx neq_lift ?andbT.
by move=> i; case: unliftP => [k ->|->]; rewrite ?eqxx ?andbF.
Qed.
Lemma big_enum_val_cond (I : finType) (A : pred I) (P : pred I) F :
\big[op/x]_(x in A | P x) F x =
\big[op/x]_(i < #|A| | P (enum_val i)) F (enum_val i).
Proof.
have [A_eq0|/card_gt0P[x0 x0A]] := posnP #|A|.
rewrite !big_pred0 // => i; last by rewrite card0_eq.
by have: false by move: i => []; rewrite A_eq0.
rewrite (reindex (enum_val : 'I_#|A| -> I)).
by apply: eq_big => [y|y Py]; rewrite ?enum_valP.
by apply: subon_bij (enum_val_bij_in x0A) => y /andP[].
Qed.
Arguments big_enum_val_cond [I A] P F.
Lemma big_enum_rank_cond (I : finType) (A : pred I) z (zA : z \in A) P F
(h := enum_rank_in zA) :
\big[op/x]_(i < #|A| | P i) F i = \big[op/x]_(s in A | P (h s)) F (h s).
Proof.
rewrite big_enum_val_cond {}/h.
by apply: eq_big => [i|i Pi]; rewrite ?enum_valK_in.
Qed.
Arguments big_enum_rank_cond [I A z] zA P F.
Lemma big_nat_rev m n P F :
\big[op/x]_(m <= i < n | P i) F i
= \big[op/x]_(m <= i < n | P (m + n - i.+1)) F (m + n - i.+1).
Proof.
case: (ltnP m n) => ltmn; last by rewrite !big_geq.
rewrite -{3 4}(subnK (ltnW ltmn)) addnA.
do 2!rewrite (big_addn _ _ 0) big_mkord; rewrite (reindex_inj rev_ord_inj)/=.
by apply: eq_big => [i | i _]; rewrite /= -addSn subnDr addnC addnBA.
Qed.
Lemma big_rev_mkord m n P F :
\big[op/x]_(m <= k < n | P k) F k
= \big[op/x]_(k < n - m | P (n - k.+1)) F (n - k.+1).
Proof.
rewrite big_nat_rev (big_addn _ _ 0) big_mkord.
by apply: eq_big => [i|i _]; rewrite -addSn addnC subnDr.
Qed.
Section Id.
Hypothesis opxx : op x x = x.
Lemma big_mkcond_idem I r (P : pred I) F :
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) (if P i then F i else x).
Proof.
elim: r => [|i r]; rewrite ?(big_nil, big_cons)//.
by case: ifPn => Pi ->//; rewrite -[in LHS]big_id_idem // opC.
Qed.
Lemma big_mkcondr_idem I r (P Q : pred I) F :
\big[op/x]_(i <- r | P i && Q i) F i =
\big[op/x]_(i <- r | P i) (if Q i then F i else x).
Proof. by rewrite -big_filter_cond big_mkcond_idem big_filter. Qed.
Lemma big_mkcondl_idem I r (P Q : pred I) F :
\big[op/x]_(i <- r | P i && Q i) F i =
\big[op/x]_(i <- r | Q i) (if P i then F i else x).
Proof. by rewrite big_andbC big_mkcondr_idem. Qed.
Lemma big_rmcond_idem I (r : seq I) (P : pred I) F :
(forall i, ~~ P i -> F i = x) ->
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_mkcond_idem; apply: eq_bigr => i.
by case: (P i) (F_eq1 i) => // ->.
Qed.
Lemma big_rmcond_in_idem (I : eqType) (r : seq I) (P : pred I) F :
(forall i, i \in r -> ~~ P i -> F i = x) ->
\big[op/x]_(i <- r | P i) F i = \big[op/x]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl_idem.
by rewrite big_rmcond_idem => // i /F_eq1; case: ifP => // _ ->.
Qed.
Lemma big_cat_idem I r1 r2 (P : pred I) F :
\big[op/x]_(i <- r1 ++ r2 | P i) F i =
op (\big[op/x]_(i <- r1 | P i) F i) (\big[op/x]_(i <- r2 | P i) F i).
Proof.
elim: r1 => [/=|i r1 IHr1]; first by rewrite big_nil opC big_id_idem.
by rewrite /= big_cons IHr1 big_cons; case: (P i); rewrite // opA.
Qed.
Lemma big_allpairs_dep_idem I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J)
(r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) :
\big[op/x]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i =
\big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2 i1) F (h i1 i2).
Proof.
elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil.
by rewrite big_cat_idem IHr1 big_cons big_map.
Qed.
Lemma big_allpairs_idem I1 I2 (r1 : seq I1) (r2 : seq I2) F :
\big[op/x]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i =
\big[op/x]_(i1 <- r1) \big[op/x]_(i2 <- r2) F (i1, i2).
Proof. exact: big_allpairs_dep_idem. Qed.
Lemma big_cat_nat_idem n m p (P : pred nat) F : m <= n -> n <= p ->
\big[op/x]_(m <= i < p | P i) F i =
op (\big[op/x]_(m <= i < n | P i) F i) (\big[op/x]_(n <= i < p | P i) F i).
Proof.
move=> le_mn le_np; rewrite -big_cat_idem -{2}(subnKC le_mn) -iotaD subnDA.
by rewrite subnKC // leq_sub.
Qed.
Lemma big_split_idem I r (P : pred I) F1 F2 :
\big[op/x]_(i <- r | P i) op (F1 i) (F2 i) =
op (\big[op/x]_(i <- r | P i) F1 i) (\big[op/x]_(i <- r | P i) F2 i).
Proof.
by elim/big_rec3: _ => [|i x' y _ _ ->]; rewrite ?opxx// opCA -!opA opCA.
Qed.
Lemma big_id_idem_AC I (r : seq I) P F :
\big[op/x]_(i <- r | P i) op (F i) x = \big[op/x]_(i <- r | P i) F i.
Proof. by rewrite big_split_idem big_const_idem ?big_id_idem. Qed.
Lemma bigID_idem I r (a P : pred I) F :
\big[op/x]_(i <- r | P i) F i =
op (\big[op/x]_(i <- r | P i && a i) F i)
(\big[op/x]_(i <- r | P i && ~~ a i) F i).
Proof.
rewrite -big_id_idem_AC big_mkcond_idem !(big_mkcond_idem _ _ F) -big_split_idem.
by apply: eq_bigr => i; case: ifPn => //=; case: ifPn; rewrite // opC.
Qed.
Arguments bigID_idem [I r].
Lemma bigU_idem (I : finType) (A B : pred I) F :
[disjoint A & B] ->
\big[op/x]_(i in [predU A & B]) F i =
op (\big[op/x]_(i in A) F i) (\big[op/x]_(i in B) F i).
Proof.
move=> dAB; rewrite (bigID_idem (mem A)).
congr (op : _ -> _); apply: eq_bigl => i; first by rewrite orbK.
by have:= pred0P dAB i; rewrite andbC /= !inE; case: (i \in A).
Qed.
Lemma partition_big_idem I (s : seq I)
(J : finType) (P : pred I) (p : I -> J) (Q : pred J) F :
(forall i, P i -> Q (p i)) ->
\big[op/x]_(i <- s | P i) F i =
\big[op/x]_(j : J | Q j) \big[op/x]_(i <- s | (P i) && (p i == j)) F i.
Proof.
move=> Qp; transitivity (\big[op/x]_(i <- s | P i && Q (p i)) F i).
by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp.
have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *.
case: (pickP Q) => [j Qj | Q0]; last first.
by rewrite !big_pred0 // => i; rewrite Q0 andbF.
rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x j Qj) in leQn.
rewrite (bigID_idem (fun i => p i == j)).
congr (op : _ -> _); apply: eq_bigl => i; last by rewrite andbA.
by case: eqP => [->|_]; rewrite !(Qj, andbT, andbF).
Qed.
Arguments partition_big_idem [I s J P] p Q [F].
Lemma sig_big_dep_idem (I : finType) (J : I -> finType)
(P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) :
\big[op/x]_(i | P i) \big[op/x]_(j : J i | Q j) F j =
\big[op/x]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p).
Proof.
pose s := [seq Tagged J j | i <- index_enum I, j <- index_enum (J i)].
rewrite [LHS]big_mkcond_idem big_mkcondl_idem.
rewrite [RHS]big_mkcond_idem -[RHS](@perm_big _ s).
rewrite big_allpairs_dep_idem/=; apply: eq_bigr => i _.
by rewrite -big_mkcond_idem/=; case: P; rewrite // big1_idem.
rewrite uniq_perm ?index_enum_uniq//.
by rewrite allpairs_uniq_dep// => [|i|[i j] []]; rewrite ?index_enum_uniq.
by move=> [i j]; rewrite ?mem_index_enum; apply/allpairsPdep; exists i, j.
Qed.
Lemma pair_big_dep_idem (I J : finType) (P : pred I) (Q : I -> pred J) F :
\big[op/x]_(i | P i) \big[op/x]_(j | Q i j) F i j =
\big[op/x]_(p | P p.1 && Q p.1 p.2) F p.1 p.2.
Proof.
rewrite sig_big_dep_idem; apply: (reindex (fun x => Tagged (fun=> J) x.2)).
by exists (fun x => (projT1 x, projT2 x)) => -[].
Qed.
Lemma pair_big_idem (I J : finType) (P : pred I) (Q : pred J) F :
\big[op/x]_(i | P i) \big[op/x]_(j | Q j) F i j =
\big[op/x]_(p | P p.1 && Q p.2) F p.1 p.2.
Proof. exact: pair_big_dep_idem. Qed.
Lemma pair_bigA_idem (I J : finType) (F : I -> J -> R) :
\big[op/x]_i \big[op/x]_j F i j = \big[op/x]_p F p.1 p.2.
Proof. exact: pair_big_dep_idem. Qed.
Lemma exchange_big_dep_idem I J rI rJ (P : pred I) (Q : I -> pred J)
(xQ : pred J) F :
(forall i j, P i -> Q i j -> xQ j) ->
\big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q i j) F i j =
\big[op/x]_(j <- rJ | xQ j) \big[op/x]_(i <- rI | P i && Q i j) F i j.
Proof.
move=> PQxQ; pose p u := (u.2, u.1).
under [LHS]eq_bigr do rewrite big_tnth; rewrite [LHS]big_tnth.
under [RHS]eq_bigr do rewrite big_tnth; rewrite [RHS]big_tnth.
rewrite !pair_big_dep_idem (reindex_onto (p _ _) (p _ _)) => [|[]] //=.
apply: eq_big => [] [j i] //=; symmetry; rewrite eqxx andbT andb_idl //.
by case/andP; apply: PQxQ.
Qed.
Arguments exchange_big_dep_idem [I J rI rJ P Q] xQ [F].
Lemma exchange_big_idem I J rI rJ (P : pred I) (Q : pred J) F :
\big[op/x]_(i <- rI | P i) \big[op/x]_(j <- rJ | Q j) F i j =
\big[op/x]_(j <- rJ | Q j) \big[op/x]_(i <- rI | P i) F i j.
Proof.
rewrite (exchange_big_dep_idem Q) //.
by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT.
Qed.
Lemma exchange_big_dep_nat_idem m1 n1 m2 n2 (P : pred nat) (Q : rel nat)
(xQ : pred nat) F :
(forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) ->
\big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q i j) F i j =
\big[op/x]_(m2 <= j < n2 | xQ j)
\big[op/x]_(m1 <= i < n1 | P i && Q i j) F i j.
Proof.
move=> PQxQ; under eq_bigr do rewrite big_seq_cond.
rewrite big_seq_cond /= (exchange_big_dep_idem xQ) => [|i j]; last first.
by rewrite !mem_index_iota => /andP[mn_i Pi] /andP[mn_j /PQxQ->].
rewrite 2!(big_seq_cond _ _ _ xQ); apply: eq_bigr => j /andP[-> _] /=.
by rewrite [rhs in _ = rhs]big_seq_cond; apply: eq_bigl => i; rewrite -andbA.
Qed.
Arguments exchange_big_dep_nat_idem [m1 n1 m2 n2 P Q] xQ [F].
Lemma exchange_big_nat_idem m1 n1 m2 n2 (P Q : pred nat) F :
\big[op/x]_(m1 <= i < n1 | P i) \big[op/x]_(m2 <= j < n2 | Q j) F i j =
\big[op/x]_(m2 <= j < n2 | Q j) \big[op/x]_(m1 <= i < n1 | P i) F i j.
Proof.
rewrite (exchange_big_dep_nat_idem Q) //.
by under eq_bigr => i Qi do under eq_bigl do rewrite Qi andbT.
Qed.
End Id.
End Abelian.
End SemiGroupProperties.
Arguments big_undup [R op x I].
Arguments perm_big [R op x I r1 r2].
Arguments bigD1 [R op x I] j [P F].
Arguments reindex_omap [R op x I J] h h' [P F].
Arguments reindex_onto [R op x I J] h h' [P F].
Arguments reindex [R op x I J] h [P F].
Arguments reindex_inj [R op x I h P F].
Arguments big_enum_val_cond [R op x I A] P F.
Arguments big_enum_rank_cond [R op x I A z] zA P F.
Section MonoidProperties.
Import Monoid.Theory.
Variable R : Type.
Variable idx : R.
Local Notation "1" := idx.
Section Plain.
Variable op : Monoid.law 1.
Local Notation "*%M" := op.
Local Notation "x * y" := (op x y).
Lemma foldlE x r : foldl *%M x r = \big[*%M/1]_(y <- x :: r) y.
Proof.
by rewrite -foldrE; elim: r => [|y r IHr]/= in x *; rewrite ?mulm1 ?mulmA ?IHr.
Qed.
Lemma foldl_idx r : foldl *%M 1 r = \big[*%M/1]_(x <- r) x.
Proof. by rewrite foldlE big_cons mul1m. Qed.
Lemma eq_big_idx_seq idx' I r (P : pred I) F :
right_id idx' *%M -> has P r ->
\big[*%M/idx']_(i <- r | P i) F i = \big[*%M/1]_(i <- r | P i) F i.
Proof.
move=> op_idx'; rewrite -!(big_filter _ _ r) has_count -size_filter.
case/lastP: (filter P r) => {r}// r i _.
by rewrite -cats1 !(big_cat_nested, big_cons, big_nil) op_idx' mulm1.
Qed.
Lemma eq_big_idx idx' (I : finType) i0 (P : pred I) F :
P i0 -> right_id idx' *%M ->
\big[*%M/idx']_(i | P i) F i = \big[*%M/1]_(i | P i) F i.
Proof.
by move=> Pi0 op_idx'; apply: eq_big_idx_seq => //; apply/hasP; exists i0.
Qed.
Lemma big_change_idx I x r (P : pred I) F :
\big[*%M/x]_(j <- r | P j) F j = (\big[*%M/1]_(j <- r | P j) F j) * x.
Proof.
elim: r => [|i r]; rewrite ?(big_nil, big_cons, mul1m)// => ->.
by case: ifP => // Pi; rewrite mulmA.
Qed.
Lemma big1_eq I r (P : pred I) : \big[*%M/1]_(i <- r | P i) 1 = 1.
Proof. by rewrite big1_idem //= mul1m. Qed.
Lemma big1 I r (P : pred I) F :
(forall i, P i -> F i = 1) -> \big[*%M/1]_(i <- r | P i) F i = 1.
Proof. by move/(eq_bigr _)->; apply: big1_eq. Qed.
Lemma big1_seq (I : eqType) r (P : pred I) F :
(forall i, P i && (i \in r) -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = 1.
Proof. by move=> eqF1; rewrite big_seq_cond big_andbC big1. Qed.
Lemma big_seq1 I (i : I) F : \big[*%M/1]_(j <- [:: i]) F j = F i.
Proof. by rewrite big_seq1_id mulm1. Qed.
Lemma big_rcons I i r (P : pred I) F :
\big[*%M/1]_(j <- rcons r i | P j) F j =
(\big[*%M/1]_(j <- r | P j) F j) * (if P i then F i else idx).
Proof. by rewrite big_rcons_op big_change_idx mulm1. Qed.
Lemma big_mkcond I r (P : pred I) F :
\big[*%M/1]_(i <- r | P i) F i =
\big[*%M/1]_(i <- r) (if P i then F i else 1).
Proof. by rewrite unlock; elim: r => //= i r ->; case P; rewrite ?mul1m. Qed.
Lemma big_mkcondr I r (P Q : pred I) F :
\big[*%M/1]_(i <- r | P i && Q i) F i =
\big[*%M/1]_(i <- r | P i) (if Q i then F i else 1).
Proof. by rewrite -big_filter_cond big_mkcond big_filter. Qed.
Lemma big_mkcondl I r (P Q : pred I) F :
\big[*%M/1]_(i <- r | P i && Q i) F i =
\big[*%M/1]_(i <- r | Q i) (if P i then F i else 1).
Proof. by rewrite big_andbC big_mkcondr. Qed.
Lemma big_rmcond I (r : seq I) (P : pred I) F :
(forall i, ~~ P i -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_mkcond; apply: eq_bigr => i.
by case: (P i) (F_eq1 i) => // ->.
Qed.
Lemma big_rmcond_in (I : eqType) (r : seq I) (P : pred I) F :
(forall i, i \in r -> ~~ P i -> F i = 1) ->
\big[*%M/1]_(i <- r | P i) F i = \big[*%M/1]_(i <- r) F i.
Proof.
move=> F_eq1; rewrite big_seq_cond [RHS]big_seq_cond !big_mkcondl big_rmcond//.
by move=> i /F_eq1; case: ifP => // _ ->.
Qed.
Lemma big_cat I r1 r2 (P : pred I) F :
\big[*%M/1]_(i <- r1 ++ r2 | P i) F i =
\big[*%M/1]_(i <- r1 | P i) F i * \big[*%M/1]_(i <- r2 | P i) F i.
Proof.
rewrite !(big_mkcond _ P) unlock.
by elim: r1 => /= [|i r1 ->]; rewrite (mul1m, mulmA).
Qed.
Lemma big_allpairs_dep I1 (I2 : I1 -> Type) J (h : forall i1, I2 i1 -> J)
(r1 : seq I1) (r2 : forall i1, seq (I2 i1)) (F : J -> R) :
\big[*%M/1]_(i <- [seq h i1 i2 | i1 <- r1, i2 <- r2 i1]) F i =
\big[*%M/1]_(i1 <- r1) \big[*%M/1]_(i2 <- r2 i1) F (h i1 i2).
Proof.
elim: r1 => [|i1 r1 IHr1]; first by rewrite !big_nil.
by rewrite big_cat IHr1 big_cons big_map.
Qed.
Lemma big_allpairs I1 I2 (r1 : seq I1) (r2 : seq I2) F :
\big[*%M/1]_(i <- [seq (i1, i2) | i1 <- r1, i2 <- r2]) F i =
\big[*%M/1]_(i1 <- r1) \big[op/idx]_(i2 <- r2) F (i1, i2).
Proof. exact: big_allpairs_dep. Qed.
Lemma rev_big_rev I (r : seq I) P F :
\big[*%M/1]_(i <- rev r | P i) F i =
\big[(fun x y => y * x)/1]_(i <- r | P i) F i.
Proof.
elim: r => [|i r IHr]; rewrite ?big_nil// big_cons rev_cons big_rcons IHr.
by case: (P i); rewrite ?mulm1.
Qed.
Lemma big_only1 (I : finType) (i : I) (P : pred I) (F : I -> R) : P i ->
(forall j, j != i -> P j -> F j = idx) ->
\big[op/idx]_(j | P j) F j = F i.
Proof.
move=> Pi Fisx; have := index_enum_uniq I.
have : i \in index_enum I by rewrite mem_index_enum.
elim: index_enum => //= j r IHr /[!inE]; case: eqVneq => [<-|nij]//=.
move=> _ /andP[iNr runiq]; rewrite big_cons/= Pi big1_seq ?Monoid.mulm1//.
by move=> {}j /andP[/Fisx + jr] => ->//; apply: contraNneq iNr => <-.
move=> ir /andP[jNr runiq]; rewrite big_cons IHr//.
by case: ifPn => // /Fisx->; rewrite 1?eq_sym// Monoid.mul1m.
Qed.
Lemma big_pred1_eq (I : finType) (i : I) F : \big[*%M/1]_(j | j == i) F j = F i.
Proof. by rewrite (@big_only1 _ i)// => j /negPf->. Qed.
Lemma big_pred1 (I : finType) i (P : pred I) F :
P =1 pred1 i -> \big[*%M/1]_(j | P j) F j = F i.
Proof. by move/(eq_bigl _ _)->; apply: big_pred1_eq. Qed.
Lemma big_ord1 F : \big[op/idx]_(i < 1) F i = F ord0.
Proof. by rewrite big_ord_recl big_ord0 Monoid.mulm1. Qed.
Lemma big_ord1_cond P F :
\big[op/idx]_(i < 1 | P i) F i = if P ord0 then F ord0 else idx.
Proof. by rewrite big_mkcond big_ord1. Qed.
Lemma big_ord1_eq (F : nat -> R) i n :
\big[op/idx]_(j < n | j == i :> nat) F j = if i < n then F i else idx.
Proof.
case: ltnP => [i_lt|i_ge]; first by rewrite (big_pred1_eq (Ordinal _)).
by rewrite big_pred0// => j; apply: contra_leqF i_ge => /eqP <-.
Qed.
Lemma big_ord1_cond_eq (F : nat -> R) (P : pred nat) i n :
\big[op/idx]_(j < n | P j && (j == i :> nat)) F j =
if (i < n) && P i then F i else idx.
Proof.
by rewrite big_mkcondl if_and (big_ord1_eq (fun j => if P j then F j else _)).
Qed.
Lemma big_cat_nat n m p (P : pred nat) F : m <= n -> n <= p ->
\big[*%M/1]_(m <= i < p | P i) F i =
(\big[*%M/1]_(m <= i < n | P i) F i) * (\big[*%M/1]_(n <= i < p | P i) F i).
Proof.
move=> le_mn le_np; rewrite -big_cat -{2}(subnKC le_mn) -iotaD subnDA.
by rewrite subnKC // leq_sub.
Qed.
Lemma big_nat_widenl (m1 m2 n : nat) (P : pred nat) F :
m2 <= m1 ->
\big[op/idx]_(m1 <= i < n | P i) F i =
\big[op/idx]_(m2 <= i < n | P i && (m1 <= i)) F i.
Proof.
move=> le_m21; have [le_nm1|lt_m1n] := leqP n m1.
rewrite big_geq// big_nat_cond big1//.
by move=> i /and3P[/andP[_ /leq_trans/(_ le_nm1)/ltn_geF->]].
rewrite big_mkcond big_mkcondl (big_cat_nat _ _ le_m21) 1?ltnW//.
rewrite [X in op X]big_nat_cond [X in op X]big_pred0; last first.
by move=> k; case: ltnP; rewrite andbF.
by rewrite Monoid.mul1m; apply: congr_big_nat => // k /andP[].
Qed.
Lemma big_geq_mkord (m n : nat) (P : pred nat) F :
\big[op/idx]_(m <= i < n | P i) F i =
\big[op/idx]_(i < n | P i && (m <= i)) F i.
Proof. by rewrite (@big_nat_widenl _ 0)// big_mkord. Qed.
Lemma big_nat1_eq (F : nat -> R) i m n :
\big[op/idx]_(m <= j < n | j == i) F j = if m <= i < n then F i else idx.
Proof. by rewrite big_geq_mkord big_andbC big_ord1_cond_eq andbC. Qed.
Lemma big_nat1_cond_eq (F : nat -> R) (P : pred nat) i m n :
\big[op/idx]_(m <= j < n | P j && (j == i)) F j =
if (m <= i < n) && P i then F i else idx.
Proof. by rewrite big_mkcondl big_nat1_eq -if_and. Qed.
Lemma big_nat1 n F : \big[*%M/1]_(n <= i < n.+1) F i = F n.
Proof. by rewrite big_ltn // big_geq // mulm1. Qed.
Lemma big_nat_recr n m F : m <= n ->
\big[*%M/1]_(m <= i < n.+1) F i = (\big[*%M/1]_(m <= i < n) F i) * F n.
Proof. by move=> lemn; rewrite (@big_cat_nat n) ?leqnSn // big_nat1. Qed.
Lemma big_nat_mul n k F :
\big[*%M/1]_(0 <= i < n * k) F i =
\big[*%M/1]_(0 <= i < n) \big[*%M/1]_(i * k <= j < i.+1 * k) F j.
Proof.
elim: n => [|n ih]; first by rewrite mul0n 2!big_nil.
rewrite [in RHS]big_nat_recr//= -ih mulSn addnC [in LHS]/index_iota subn0 iotaD.
rewrite big_cat /= [in X in _ = X * _]/index_iota subn0; congr (_ * _).
by rewrite add0n /index_iota (addnC _ k) addnK.
Qed.
Lemma big_ord_recr n F :
\big[*%M/1]_(i < n.+1) F i =
(\big[*%M/1]_(i < n) F (widen_ord (leqnSn n) i)) * F ord_max.
Proof.
transitivity (\big[*%M/1]_(0 <= i < n.+1) F (inord i)).
by rewrite big_mkord; apply: eq_bigr=> i _; rewrite inord_val.
rewrite big_nat_recr // big_mkord; congr (_ * F _); last first.
by apply: val_inj; rewrite /= inordK.
by apply: eq_bigr => [] i _; congr F; apply: ord_inj; rewrite inordK //= leqW.
Qed.
Lemma big_sumType (I1 I2 : finType) (P : pred (I1 + I2)) F :
\big[*%M/1]_(i | P i) F i =
(\big[*%M/1]_(i | P (inl _ i)) F (inl _ i))
* (\big[*%M/1]_(i | P (inr _ i)) F (inr _ i)).
Proof.
by rewrite ![index_enum _]unlock [@Finite.enum in LHS]unlock/= big_cat !big_map.
Qed.
Lemma big_split_ord m n (P : pred 'I_(m + n)) F :
\big[*%M/1]_(i | P i) F i =
(\big[*%M/1]_(i | P (lshift n i)) F (lshift n i))
* (\big[*%M/1]_(i | P (rshift m i)) F (rshift m i)).
Proof.
rewrite -(big_map _ _ (lshift n) _ P F) -(big_map _ _ (@rshift m _) _ P F).
rewrite -big_cat; congr bigop; apply: (inj_map val_inj).
rewrite map_cat -!map_comp (map_comp (addn m)) /=.
by rewrite ![index_enum _]unlock unlock !val_ord_enum -iotaDl addn0 iotaD.
Qed.
Lemma big_flatten I rr (P : pred I) F :
\big[*%M/1]_(i <- flatten rr | P i) F i
= \big[*%M/1]_(r <- rr) \big[*%M/1]_(i <- r | P i) F i.
Proof.
by elim: rr => [|r rr IHrr]; rewrite ?big_nil //= big_cat big_cons -IHrr.
Qed.
Lemma big_pmap J I (h : J -> option I) (r : seq J) F :
\big[op/idx]_(i <- pmap h r) F i = \big[op/idx]_(j <- r) oapp F idx (h j).
Proof.
elim: r => [| r0 r IHr]/=; first by rewrite !big_nil.
rewrite /= big_cons; case: (h r0) => [i|] /=; last by rewrite mul1m.
by rewrite big_cons IHr.
Qed.
Lemma telescope_big (f : nat -> nat -> R) (n m : nat) :
(forall k, n < k < m -> op (f n k) (f k k.+1) = f n k.+1) ->
\big[op/idx]_(n <= i < m) f i i.+1 = if n < m then f n m else idx.
Proof.
elim: m => [//| m IHm]; first by rewrite ltn0 big_geq.
move=> tm; rewrite ltnS; case: ltnP=> // mn; first by rewrite big_geq.
rewrite big_nat_recr// IHm//; last first.
by move=> k /andP[nk /ltnW nm]; rewrite tm// nk.
by case: ltngtP mn=> //= [nm|<-]; rewrite ?mul1m// tm// nm leqnn.
Qed.
End Plain.
Section Abelian.
Variable op : Monoid.com_law 1.
Local Notation "'*%M'" := op.
Local Notation "x * y" := (op x y).
Lemma big_rem (I : eqType) r x (P : pred I) F :
x \in r ->
\big[*%M/1]_(y <- r | P y) F y
= (if P x then F x else 1) * \big[*%M/1]_(y <- rem x r | P y) F y.
Proof.
by move/perm_to_rem/(perm_big _)->; rewrite !(big_mkcond _ _ P) big_cons.
Qed.
Lemma big_rev I (r : seq I) P F :
\big[*%M/1]_(i <- rev r | P i) F i = \big[*%M/1]_(i <- r | P i) F i.
Proof.
by rewrite rev_big_rev; apply: (eq_big_op (fun=> True)) => // *; apply: mulmC.
Qed.
Lemma eq_big_idem (I : eqType) (r1 r2 : seq I) (P : pred I) F :
idempotent_op *%M -> r1 =i r2 ->
\big[*%M/1]_(i <- r1 | P i) F i = \big[*%M/1]_(i <- r2 | P i) F i.
Proof.
move=> idM eq_r; rewrite -big_undup // -(big_undup r2) //; apply/perm_big.
by rewrite uniq_perm ?undup_uniq // => i; rewrite !mem_undup eq_r.
Qed.
Lemma big_undup_iterop_count (I : eqType) (r : seq I) (P : pred I) F :
\big[*%M/1]_(i <- undup r | P i) iterop (count_mem i r) *%M (F i) 1
= \big[*%M/1]_(i <- r | P i) F i.
Proof.
rewrite -[RHS](perm_big _ F (perm_count_undup _)) big_flatten big_map.
by rewrite [LHS]big_mkcond; apply: eq_bigr=> i _; rewrite big_nseq_cond iteropE.
Qed.
Lemma big_split I r (P : pred I) F1 F2 :
\big[*%M/1]_(i <- r | P i) (F1 i * F2 i) =
\big[*%M/1]_(i <- r | P i) F1 i * \big[*%M/1]_(i <- r | P i) F2 i.
Proof. exact/big_split_idem/mul1m. Qed.
Lemma bigID I r (a P : pred I) F :
\big[*%M/1]_(i <- r | P i) F i =
\big[*%M/1]_(i <- r | P i && a i) F i *
\big[*%M/1]_(i <- r | P i && ~~ a i) F i.
Proof. exact/bigID_idem/mul1m. Qed.
Arguments bigID [I r].
Lemma big_if I r (P Q : pred I) F G :
\big[*%M/1]_(i <- r | P i) (if Q i then F i else G i) =
\big[*%M/1]_(i <- r | P i && Q i) F i *
\big[*%M/1]_(i <- r | P i && ~~ Q i) G i.
Proof.
rewrite (bigID Q); congr (_ * _); apply: eq_bigr => i /andP[_].
by move=> ->.
by move=> /negPf ->.
Qed.
Lemma bigU (I : finType) (A B : pred I) F :
[disjoint A & B] ->
\big[*%M/1]_(i in [predU A & B]) F i =
(\big[*%M/1]_(i in A) F i) * (\big[*%M/1]_(i in B) F i).
Proof. exact/bigU_idem/mul1m. Qed.
Lemma partition_big I (s : seq I)
(J : finType) (P : pred I) (p : I -> J) (Q : pred J) F :
(forall i, P i -> Q (p i)) ->
\big[*%M/1]_(i <- s | P i) F i =
\big[*%M/1]_(j : J | Q j) \big[*%M/1]_(i <- s | (P i) && (p i == j)) F i.
Proof.
move=> Qp; transitivity (\big[*%M/1]_(i <- s | P i && Q (p i)) F i).
by apply: eq_bigl => i; case Pi: (P i); rewrite // Qp.
have [n leQn] := ubnP #|Q|; elim: n => // n IHn in Q {Qp} leQn *.
case: (pickP Q) => [j Qj | Q0]; last first.
by rewrite !big_pred0 // => i; rewrite Q0 andbF.
rewrite (bigD1 j) // -IHn; last by rewrite ltnS (cardD1x Qj) in leQn.
rewrite (bigID (fun i => p i == j)); congr (_ * _); apply: eq_bigl => i.
by case: eqP => [-> | _]; rewrite !(Qj, simpm).
by rewrite andbA.
Qed.
Arguments partition_big [I s J P] p Q [F].
Lemma big_enum_val (I : finType) (A : pred I) F :
\big[op/idx]_(x in A) F x = \big[op/idx]_(i < #|A|) F (enum_val i).
Proof. by rewrite -(big_enum_val_cond predT) big_mkcondr. Qed.
Arguments big_enum_val [I A] F.
Lemma big_enum_rank (I : finType) (A : pred I) x (xA : x \in A) F
(h := enum_rank_in xA) :
\big[op/idx]_(i < #|A|) F i = \big[op/idx]_(s in A) F (h s).
Proof. by rewrite (big_enum_rank_cond xA) big_mkcondr. Qed.
Arguments big_enum_rank [I A x] xA F.
Lemma big_sub_cond (I : finType) (A P : {pred I}) (F : I -> R) :
\big[*%M/1]_(i in A | P i) F i =
\big[*%M/1]_(x : {x in A} | P (val x)) F (val x).
Proof.
rewrite (reindex_omap (val : {x in A} -> I) insub); last first.
by move=> i /andP[iA Pi]; rewrite insubT.
by apply: eq_bigl=> -[i iA]/=; rewrite insubT ?iA /= eqxx andbT.
Qed.
Lemma big_sub (I : finType) (A : {pred I}) (F : I -> R) :
\big[*%M/1]_(i in A) F i = \big[*%M/1]_(x : {x in A}) F (val x).
Proof. by rewrite -(big_sub_cond A xpredT) big_mkcondr. Qed.
Lemma sig_big_dep (I : finType) (J : I -> finType)
(P : pred I) (Q : forall {i}, pred (J i)) (F : forall {i}, J i -> R) :
\big[op/idx]_(i | P i) \big[op/idx]_(j : J i | Q j) F j =
\big[op/idx]_(p : {i : I & J i} | P (tag p) && Q (tagged p)) F (tagged p).
Proof. exact/sig_big_dep_idem/mul1m. Qed.
Lemma pair_big_dep (I J : finType) (P : pred I) (Q : I -> pred J) F :
\big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q i j) F i j =
\big[*%M/1]_(p | P p.1 && Q p.1 p.2) F p.1 p.2.
Proof. exact/pair_big_dep_idem/mul1m. Qed.
Lemma pair_big (I J : finType) (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i | P i) \big[*%M/1]_(j | Q j) F i j =
\big[*%M/1]_(p | P p.1 && Q p.2) F p.1 p.2.
Proof. exact/pair_big_idem/mul1m. Qed.
Lemma pair_bigA (I J : finType) (F : I -> J -> R) :
\big[*%M/1]_i \big[*%M/1]_j F i j = \big[*%M/1]_p F p.1 p.2.
Proof. exact/pair_bigA_idem/mul1m. Qed.
Lemma exchange_big_dep I J rI rJ (P : pred I) (Q : I -> pred J)
(xQ : pred J) F :
(forall i j, P i -> Q i j -> xQ j) ->
\big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q i j) F i j =
\big[*%M/1]_(j <- rJ | xQ j) \big[*%M/1]_(i <- rI | P i && Q i j) F i j.
Proof. exact/exchange_big_dep_idem/mul1m. Qed.
Arguments exchange_big_dep [I J rI rJ P Q] xQ [F].
Lemma exchange_big I J rI rJ (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i <- rI | P i) \big[*%M/1]_(j <- rJ | Q j) F i j =
\big[*%M/1]_(j <- rJ | Q j) \big[*%M/1]_(i <- rI | P i) F i j.
Proof. exact/exchange_big_idem/mul1m. Qed.
Lemma exchange_big_dep_nat m1 n1 m2 n2 (P : pred nat) (Q : rel nat)
(xQ : pred nat) F :
(forall i j, m1 <= i < n1 -> m2 <= j < n2 -> P i -> Q i j -> xQ j) ->
\big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q i j) F i j =
\big[*%M/1]_(m2 <= j < n2 | xQ j)
\big[*%M/1]_(m1 <= i < n1 | P i && Q i j) F i j.
Proof. exact/exchange_big_dep_nat_idem/mul1m. Qed.
Arguments exchange_big_dep_nat [m1 n1 m2 n2 P Q] xQ [F].
Lemma exchange_big_nat m1 n1 m2 n2 (P Q : pred nat) F :
\big[*%M/1]_(m1 <= i < n1 | P i) \big[*%M/1]_(m2 <= j < n2 | Q j) F i j =
\big[*%M/1]_(m2 <= j < n2 | Q j) \big[*%M/1]_(m1 <= i < n1 | P i) F i j.
Proof. exact/exchange_big_nat_idem/mul1m. Qed.
End Abelian.
End MonoidProperties.
Arguments big_filter [R idx op I].
Arguments big_filter_cond [R idx op I].
Arguments congr_big [R idx op I r1] r2 [P1] P2 [F1] F2.
Arguments eq_big [R idx op I r P1] P2 [F1] F2.
Arguments eq_bigl [R idx op I r P1] P2.
Arguments eq_bigr [R idx op I r P F1] F2.
Arguments eq_big_idx [R idx op idx' I] i0 [P F].
Arguments big_seq_cond [R idx op I r].
Arguments eq_big_seq [R idx op I r F1] F2.
Arguments congr_big_nat [R idx op m1 n1] m2 n2 [P1] P2 [F1] F2.
Arguments big_map [R idx op I J] h [r].
Arguments big_nth [R idx op I] x0 [r].
Arguments big_catl [R idx op I r1 r2 P F].
Arguments big_catr [R idx op I r1 r2 P F].
Arguments big_geq [R idx op m n P F].
Arguments big_ltn_cond [R idx op m n P F].
Arguments big_ltn [R idx op m n F].
Arguments big_addn [R idx op].
Arguments big_mkord [R idx op n].
Arguments big_nat_widen [R idx op].
Arguments big_nat_widenl [R idx op].
Arguments big_geq_mkord [R idx op].
Arguments big_ord_widen_cond [R idx op n1].
Arguments big_ord_widen [R idx op n1].
Arguments big_ord_widen_leq [R idx op n1].
Arguments big_ord_narrow_cond [R idx op n1 n2 P F].
Arguments big_ord_narrow_cond_leq [R idx op n1 n2 P F].
Arguments big_ord_narrow [R idx op n1 n2 F].
Arguments big_ord_narrow_leq [R idx op n1 n2 F].
Arguments big_mkcond [R idx op I r].
Arguments big1_eq [R idx op I].
Arguments big1_seq [R idx op I].
Arguments big1 [R idx op I].
Arguments big_only1 {R idx op I} i [P F].
Arguments big_pred1 [R idx op I] i [P F].
Arguments perm_big [R op x I r1] r2 [P F].
Arguments big_uniq [R op x I] r [F].
Arguments big_rem [R idx op I r] x [P F].
Arguments bigID [R idx op I r].
Arguments bigU [R idx op I].
Arguments bigD1 [R op x I] j [P F].
Arguments bigD1_seq [R op x I r] j [F].
Arguments bigD1_ord [R op x n] j [P F].
Arguments partition_big [R idx op I s J P] p Q [F].
Arguments reindex_omap [R op x I J] h h' [P F].
Arguments reindex_onto [R op x I J] h h' [P F].
Arguments reindex [R op x I J] h [P F].
Arguments reindex_inj [R op x I h P F].
Arguments big_enum_val_cond [R op x I A] P F.
Arguments big_enum_rank_cond [R op x I A z] zA P F.
Arguments big_enum_val [R idx op I A] F.
Arguments big_enum_rank [R idx op I A x] xA F.
Arguments big_sub_cond [R idx op I].
Arguments big_sub [R idx op I].
Arguments sig_big_dep [R idx op I J].
Arguments pair_big_dep [R idx op I J].
Arguments pair_big [R idx op I J].
Arguments big_allpairs_dep {R idx op I1 I2 J h r1 r2 F}.
Arguments big_allpairs {R idx op I1 I2 r1 r2 F}.
Arguments exchange_big_dep [R idx op I J rI rJ P Q] xQ [F].
Arguments exchange_big_dep_nat [R idx op m1 n1 m2 n2 P Q] xQ [F].
Arguments big_ord_recl [R idx op].
Arguments big_ord_recr [R idx op].
Arguments big_nat_recl [R idx op].
Arguments big_nat_recr [R idx op].
Arguments big_cat_nat_idem [R op x] opxx [n m p P F].
Arguments big_cat_nat [R idx op n m p P F].
Arguments big_pmap [R idx op J I] h [r].
Arguments telescope_big [R idx op] f [n m].
Section IncreasingSemiGroup.
Variables (R : Type) (op : SemiGroup.com_law R).
Variable le : rel R.
Hypothesis le_refl : reflexive le.
Hypothesis op_incr : forall x y, le x (op x y).
Context [x : R].
Local Notation opA := SemiGroup.opA.
Local Notation opC := SemiGroup.opC.
Lemma sub_le_big I [s] (P P' : {pred I}) (F : I -> R) :
(forall i, P i -> P' i) ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i).
Proof.
move=> PP'; rewrite [X in le _ X](big_AC_mk_monoid opA opC) (bigID P P') /=.
under [in X in le _ X]eq_bigl do rewrite (andb_idl (PP' _)).
rewrite [X in le X _](big_AC_mk_monoid opA opC).
case: (bigop _ _ _) (bigop _ _ _) => [y|] [z|]//=.
by rewrite -opA [_ y x]opC opA op_incr.
by rewrite opC op_incr.
Qed.
Lemma sub_le_big_seq (I : eqType) s s' P (F : I -> R) :
(forall i, count_mem i s <= count_mem i s')%N ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
rewrite (big_AC_mk_monoid opA opC) => /count_subseqP[_ /subseqP[m sm ->]].
move/(perm_big _)->; rewrite big_mask [X in le _ X]big_tnth.
by rewrite -!(big_AC_mk_monoid opA opC) sub_le_big // => j /andP[].
Qed.
Lemma sub_le_big_seq_cond (I : eqType) s s' P P' (F : I -> R) :
(forall i, count_mem i (filter P s) <= count_mem i (filter P' s'))%N ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> /(sub_le_big_seq xpredT F); rewrite !big_filter. Qed.
Lemma uniq_sub_le_big (I : eqType) s s' P (F : I -> R) : uniq s -> uniq s' ->
{subset s <= s'} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
move=> us us' ss'; rewrite sub_le_big_seq => // i; rewrite !count_uniq_mem//.
by have /implyP := ss' i; case: (_ \in s) (_ \in s') => [] [].
Qed.
Lemma uniq_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) :
uniq (filter P s) -> uniq (filter P' s') ->
{subset [seq i <- s | P i] <= [seq i <- s' | P' i]} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> u v /(uniq_sub_le_big xpredT F u v); rewrite !big_filter. Qed.
Section Id.
Hypothesis opK : idempotent_op op.
Lemma idem_sub_le_big (I : eqType) s s' P (F : I -> R) :
{subset s <= s'} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P i) F i).
Proof.
move=> ss'; rewrite -big_undup// -[X in le _ X]big_undup//.
by rewrite uniq_sub_le_big ?undup_uniq// => i; rewrite !mem_undup; apply: ss'.
Qed.
Lemma idem_sub_le_big_cond (I : eqType) s s' P P' (F : I -> R) :
{subset [seq i <- s | P i] <= [seq i <- s' | P' i]} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s' | P' i) F i).
Proof. by move=> /(idem_sub_le_big xpredT F); rewrite !big_filter. Qed.
End Id.
Lemma sub_in_le_big [I : eqType] (s : seq I) (P P' : {pred I}) (F : I -> R) :
{in s, forall i, P i -> P' i} ->
le (\big[op/x]_(i <- s | P i) F i) (\big[op/x]_(i <- s | P' i) F i).
Proof.
move=> PP'; apply: sub_le_big_seq_cond => i; rewrite leq_count_subseq//.
rewrite subseq_filter filter_subseq andbT; apply/allP => j.
by rewrite !mem_filter => /andP[/PP'/[apply]->].
Qed.
Lemma le_big_ord n m [P : {pred nat}] [F : nat -> R] : (n <= m)%N ->
le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P i) F i).
Proof.
by move=> nm; rewrite (big_ord_widen_cond m)// sub_le_big => //= ? /andP[].
Qed.
Lemma subset_le_big [I : finType] [A A' P : {pred I}] (F : I -> R) :
A \subset A' ->
le (\big[op/x]_(i in A | P i) F i) (\big[op/x]_(i in A' | P i) F i).
Proof.
move=> AA'; apply: sub_le_big => y /andP[yA yP]; apply/andP; split => //.
exact: subsetP yA.
Qed.
Lemma le_big_nat_cond n m n' m' (P P' : {pred nat}) (F : nat -> R) :
(n' <= n)%N -> (m <= m')%N -> (forall i, (n <= i < m)%N -> P i -> P' i) ->
le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P' i) F i).
Proof.
move=> len'n lemm' PP'i; rewrite uniq_sub_le_big_cond ?filter_uniq ?iota_uniq//.
move=> i; rewrite !mem_filter !mem_index_iota => /and3P[Pi ni im].
by rewrite PP'i ?ni//= (leq_trans _ ni)// (leq_trans im).
Qed.
Lemma le_big_nat n m n' m' [P] [F : nat -> R] : (n' <= n)%N -> (m <= m')%N ->
le (\big[op/x]_(n <= i < m | P i) F i) (\big[op/x]_(n' <= i < m' | P i) F i).
Proof. by move=> len'n lemm'; rewrite le_big_nat_cond. Qed.
Lemma le_big_ord_cond n m (P P' : {pred nat}) (F : nat -> R) :
(n <= m)%N -> (forall i : 'I_n, P i -> P' i) ->
le (\big[op/x]_(i < n | P i) F i) (\big[op/x]_(i < m | P' i) F i).
Proof.
move=> nm PP'; rewrite -!big_mkord le_big_nat_cond//= => i ni.
by have := PP' (Ordinal ni).
Qed.
End IncreasingSemiGroup.
Section EqSupport.
Variables (R : eqType) (idx : R).
Section MonoidSupport.
Variables (op : Monoid.law idx) (I : Type).
Lemma eq_bigl_supp (r : seq I) (P1 : pred I) (P2 : pred I) (F : I -> R) :
{in [pred x | F x != idx], P1 =1 P2} ->
\big[op/idx]_(i <- r | P1 i) F i = \big[op/idx]_(i <- r | P2 i) F i.
Proof.
move=> P12; rewrite big_mkcond [RHS]big_mkcond; apply: eq_bigr => i _.
by case: (eqVneq (F i) idx) => [->|/P12->]; rewrite ?if_same.
Qed.
End MonoidSupport.
Section ComoidSupport.
Variables (op : Monoid.com_law idx) (I : eqType).
Lemma perm_big_supp_cond [r s : seq I] [P : pred I] (F : I -> R) :
perm_eq
[seq i <- r | P i && (F i != idx)]
[seq i <- s | P i && (F i != idx)] ->
\big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i.
Proof.
move=> prs; rewrite !(bigID [pred i | F i == idx] P F)/=.
rewrite big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->].
rewrite [in RHS]big1 ?Monoid.mul1m; last by move=> i /andP[_ /eqP->].
by rewrite -[in LHS]big_filter -[in RHS]big_filter; apply perm_big.
Qed.
Lemma perm_big_supp [r s : seq I] [P : pred I] (F : I -> R) :
perm_eq [seq i <- r | F i != idx] [seq i <- s | F i != idx] ->
\big[op/idx]_(i <- r | P i) F i = \big[op/idx]_(i <- s | P i) F i.
Proof.
by move=> ?; apply: perm_big_supp_cond; rewrite !filter_predI perm_filter.
Qed.
End ComoidSupport.
End EqSupport.
Arguments eq_bigl_supp [R idx op I r P1].
Arguments perm_big_supp_cond [R idx op I r s P].
Arguments perm_big_supp [R idx op I r s P].
Section Distributivity.
Import Monoid.Theory.
Variable R : Type.
Variables zero one : R.
Local Notation "0" := zero.
Local Notation "1" := one.
Variable times : Monoid.mul_law 0.
Local Notation "*%M" := times.
Local Notation "x * y" := (times x y).
Variable plus : Monoid.add_law 0 *%M.
Local Notation "+%M" := plus.
Local Notation "x + y" := (plus x y).
Lemma big_distrl I r a (P : pred I) F :
\big[+%M/0]_(i <- r | P i) F i * a = \big[+%M/0]_(i <- r | P i) (F i * a).
Proof. by rewrite (big_endo ( *%M^~ a)) ?mul0m // => x y; apply: mulmDl. Qed.
Lemma big_distrr I r a (P : pred I) F :
a * \big[+%M/0]_(i <- r | P i) F i = \big[+%M/0]_(i <- r | P i) (a * F i).
Proof. by rewrite big_endo ?mulm0 // => x y; apply: mulmDr. Qed.
Lemma big_distrlr I J rI rJ (pI : pred I) (pJ : pred J) F G :
(\big[+%M/0]_(i <- rI | pI i) F i) * (\big[+%M/0]_(j <- rJ | pJ j) G j)
= \big[+%M/0]_(i <- rI | pI i) \big[+%M/0]_(j <- rJ | pJ j) (F i * G j).
Proof. by rewrite big_distrl; under eq_bigr do rewrite big_distrr. Qed.
Lemma big_distr_big_dep (I J : finType) j0 (P : pred I) (Q : I -> pred J) F :
\big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q i j) F i j =
\big[+%M/0]_(f in pfamily j0 P Q) \big[*%M/1]_(i | P i) F i (f i).
Proof.
pose fIJ := {ffun I -> J}; pose Pf := pfamily j0 (_ : seq I) Q.
have [r big_r [Ur mem_r] _] := big_enumP P.
symmetry; transitivity (\big[+%M/0]_(f in Pf r) \big[*%M/1]_(i <- r) F i (f i)).
by apply: eq_big => // f; apply: eq_forallb => i; rewrite /= mem_r.
rewrite -{P mem_r}big_r; elim: r Ur => /= [_ | i r IHr].
rewrite (big_pred1 [ffun=> j0]) ?big_nil //= => f.
apply/familyP/eqP=> /= [Df |->{f} i]; last by rewrite ffunE !inE.
by apply/ffunP=> i; rewrite ffunE; apply/eqP/Df.
case/andP=> /negbTE nri; rewrite big_cons big_distrl => {}/IHr<-.
rewrite (partition_big (fun f : fIJ => f i) (Q i)) => [|f]; last first.
by move/familyP/(_ i); rewrite /= inE /= eqxx.
pose seti j (f : fIJ) := [ffun k => if k == i then j else f k].
apply: eq_bigr => j Qij.
rewrite (reindex_onto (seti j) (seti j0)) => [|f /andP[_ /eqP fi]]; last first.
by apply/ffunP=> k; rewrite !ffunE; case: eqP => // ->.
rewrite big_distrr; apply: eq_big => [f | f eq_f]; last first.
rewrite big_cons ffunE eqxx !big_seq; congr (_ * _).
by apply: eq_bigr => k; rewrite ffunE; case: eqP nri => // -> ->.
rewrite !ffunE !eqxx andbT; apply/andP/familyP=> /= [[Pjf fij0] k | Pff].
have /[!(ffunE, inE)] := familyP Pjf k; case: eqP => // -> _.
by rewrite nri -(eqP fij0) !ffunE !inE !eqxx.
(split; [apply/familyP | apply/eqP/ffunP]) => k; have /[!(ffunE, inE)]:= Pff k.
by case: eqP => // ->.
by case: eqP => // ->; rewrite nri /= => /eqP.
Qed.
Lemma big_distr_big (I J : finType) j0 (P : pred I) (Q : pred J) F :
\big[*%M/1]_(i | P i) \big[+%M/0]_(j | Q j) F i j =
\big[+%M/0]_(f in pffun_on j0 P Q) \big[*%M/1]_(i | P i) F i (f i).
Proof.
rewrite (big_distr_big_dep j0); apply: eq_bigl => f.
by apply/familyP/familyP=> Pf i; case: ifP (Pf i).
Qed.
Lemma bigA_distr_big_dep (I J : finType) (Q : I -> pred J) F :
\big[*%M/1]_i \big[+%M/0]_(j | Q i j) F i j
= \big[+%M/0]_(f in family Q) \big[*%M/1]_i F i (f i).
Proof.
have [j _ | J0] := pickP J; first by rewrite (big_distr_big_dep j).
have Q0 i: Q i =i pred0 by move=> /J0/esym/notF[].
transitivity (iter #|I| ( *%M 0) 1).
by rewrite -big_const; apply/eq_bigr=> i; have /(big_pred0 _)-> := Q0 i.
have [i _ | I0] := pickP I.
rewrite (cardD1 i) //= mul0m big_pred0 // => f.
by apply/familyP=> /(_ i); rewrite Q0.
have f: I -> J by move=> /I0/esym/notF[].
rewrite eq_card0 // (big_pred1 (finfun f)) ?big_pred0 // => g.
by apply/familyP/eqP=> _; first apply/ffunP; move=> /I0/esym/notF[].
Qed.
Lemma bigA_distr_big (I J : finType) (Q : pred J) (F : I -> J -> R) :
\big[*%M/1]_i \big[+%M/0]_(j | Q j) F i j
= \big[+%M/0]_(f in ffun_on Q) \big[*%M/1]_i F i (f i).
Proof. exact: bigA_distr_big_dep. Qed.
Lemma bigA_distr_bigA (I J : finType) F :
\big[*%M/1]_(i : I) \big[+%M/0]_(j : J) F i j
= \big[+%M/0]_(f : {ffun I -> J}) \big[*%M/1]_i F i (f i).
Proof. by rewrite bigA_distr_big; apply: eq_bigl => ?; apply/familyP. Qed.
End Distributivity.
Arguments big_distrl [R zero times plus I r].
Arguments big_distrr [R zero times plus I r].
Arguments big_distr_big_dep [R zero one times plus I J].
Arguments big_distr_big [R zero one times plus I J].
Arguments bigA_distr_big_dep [R zero one times plus I J].
Arguments bigA_distr_big [R zero one times plus I J].
Arguments bigA_distr_bigA [R zero one times plus I J].
Section BigBool.
Section Seq.
Variables (I : Type) (r : seq I) (P B : pred I).
Lemma big_has : \big[orb/false]_(i <- r) B i = has B r.
Proof. by rewrite unlock. Qed.
Lemma big_all : \big[andb/true]_(i <- r) B i = all B r.
Proof. by rewrite unlock. Qed.
Lemma big_has_cond : \big[orb/false]_(i <- r | P i) B i = has (predI P B) r.
Proof. by rewrite big_mkcond unlock. Qed.
Lemma big_all_cond :
\big[andb/true]_(i <- r | P i) B i = all [pred i | P i ==> B i] r.
Proof. by rewrite big_mkcond unlock. Qed.
Lemma big_bool R (idx : R) (op : Monoid.com_law idx) (F : bool -> R):
\big[op/idx]_(i : bool) F i = op (F true) (F false).
Proof. by rewrite /index_enum !unlock /= Monoid.mulm1. Qed.
End Seq.
Section FinType.
Variables (I : finType) (P B : pred I).
Lemma big_orE : \big[orb/false]_(i | P i) B i = [exists (i | P i), B i].
Proof. by rewrite big_has_cond; apply/hasP/existsP=> [] [i]; exists i. Qed.
Lemma big_andE : \big[andb/true]_(i | P i) B i = [forall (i | P i), B i].
Proof.
rewrite big_all_cond; apply/allP/forallP=> /= allB i; rewrite allB //.
exact: mem_index_enum.
Qed.
End FinType.
End BigBool.
Section NatConst.
Variables (I : finType) (A : pred I).
Lemma sum_nat_const n : \sum_(i in A) n = #|A| * n.
Proof. by rewrite big_const iter_addn_0 mulnC. Qed.
Lemma sum1_card : \sum_(i in A) 1 = #|A|.
Proof. by rewrite sum_nat_const muln1. Qed.
Lemma sum1_count J (r : seq J) (a : pred J) : \sum_(j <- r | a j) 1 = count a r.
Proof. by rewrite big_const_seq iter_addn_0 mul1n. Qed.
Lemma sum1_size J (r : seq J) : \sum_(j <- r) 1 = size r.
Proof. by rewrite sum1_count count_predT. Qed.
Lemma prod_nat_const n : \prod_(i in A) n = n ^ #|A|.
Proof. by rewrite big_const -Monoid.iteropE. Qed.
Lemma sum_nat_const_nat n1 n2 n : \sum_(n1 <= i < n2) n = (n2 - n1) * n.
Proof. by rewrite big_const_nat iter_addn_0 mulnC. Qed.
Lemma prod_nat_const_nat n1 n2 n : \prod_(n1 <= i < n2) n = n ^ (n2 - n1).
Proof. by rewrite big_const_nat -Monoid.iteropE. Qed.
End NatConst.
Lemma telescope_sumn_in n m f : n <= m ->
(forall i, n <= i < m -> f i <= f i.+1) ->
\sum_(n <= k < m) (f k.+1 - f k) = f m - f n.
Proof.
move=> nm fle; rewrite (telescope_big (fun i j => f j - f i)).
by case: ltngtP nm => // ->; rewrite subnn.
move=> k /andP[nk km]; rewrite /= addnBAC ?subnKC ?fle ?(ltnW nk)//.
elim: k nk km => [//| k IHk /[!ltnS]/[1!leq_eqVlt]+ km].
move=> /predU1P[/[dup]nk -> | nk]; first by rewrite fle ?nk ?leqnn 1?ltnW.
by rewrite (leq_trans (IHk _ _) (fle _ _))// ltnW// ltnW.
Qed.
Lemma telescope_sumn n m f : {homo f : x y / x <= y} ->
\sum_(n <= k < m) (f k.+1 - f k) = f m - f n.
Proof.
move=> fle; case: (ltnP n m) => nm.
by apply: (telescope_sumn_in (ltnW nm)) => ? ?; apply: fle.
by apply/esym/eqP; rewrite big_geq// subn_eq0 fle.
Qed.
Lemma sumnE r : sumn r = \sum_(i <- r) i. Proof. exact: foldrE. Qed.
Lemma card_bseq n (T : finType) : #|{bseq n of T}| = \sum_(i < n.+1) #|T| ^ i.
Proof.
rewrite (bij_eq_card bseq_tagged_tuple_bij) card_tagged sumnE big_map big_enum.
by under eq_bigr do rewrite card_tuple.
Qed.
Lemma leqif_sum (I : finType) (P C : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i ?= iff C i) ->
\sum_(i | P i) E1 i <= \sum_(i | P i) E2 i ?= iff [forall (i | P i), C i].
Proof.
move=> leE12; rewrite -big_andE.
by elim/big_rec3: _ => // i Ci m1 m2 /leE12; apply: leqif_add.
Qed.
Lemma leq_sum I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\sum_(i <- r | P i) E1 i <= \sum_(i <- r | P i) E2 i.
Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_add. Qed.
Lemma sumnB I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\sum_(i <- r | P i) (E2 i - E1 i) =
\sum_(i <- r | P i) E2 i - \sum_(i <- r | P i) E1 i.
Proof. by move=> /(_ _ _)/subnK-/(eq_bigr _)<-; rewrite big_split addnK. Qed.
Lemma sum_nat_eq0 (I : finType) (P : pred I) (E : I -> nat) :
(\sum_(i | P i) E i == 0)%N = [forall (i | P i), E i == 0%N].
Proof. by rewrite eq_sym -(@leqif_sum I P _ (fun _ => 0%N) E) ?big1_eq. Qed.
Lemma sum_nat_seq_eq0 I r (P : pred I) F :
(\sum_(i <- r | P i) F i == 0)%N = all (fun i => P i ==> (F i == 0%N)) r.
Proof. by rewrite (big_morph _ (id1:=true) addn_eq0)// big_all_cond. Qed.
Lemma sum_nat_seq_neq0 I r (P : pred I) F :
(\sum_(i <- r | P i) F i != 0)%N = has (fun i => P i && (F i != 0)%N) r.
Proof.
by rewrite sum_nat_seq_eq0// -has_predC; apply: eq_has => x /=; case Px: (P x).
Qed.
Lemma sum_nat_eq1 (I : finType) (P : pred I) (F : I -> nat) :
reflect
(exists i : I, [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]%N)
(\sum_(i | P i) F i == 1)%N.
Proof.
apply/(iffP idP) => [sumF_eq1 | [i [Pi Fi1 zFj]]]; last first.
rewrite (bigD1 i)//= Fi1 addn_eq1//= orbF sum_nat_eq0.
by apply/forall_inP => j /andP[Pj ji]; apply/eqP/zFj.
have /forall_inPn [i Pi FiN0]: ~~ [forall i in P, F i == 0].
by apply: contraTN sumF_eq1 => /'forall_in_eqP F0; rewrite big1.
move: sumF_eq1; rewrite (bigD1 i)//= addn_eq1 (negPf FiN0)/= orbF.
move=> /andP[/eqP Fi1]; rewrite sum_nat_eq0 => /'forall_in_eqP FNi0.
by exists i; split; rewrite // => j /[swap] Nij /(conj Nij)/andP/FNi0.
Qed.
Lemma sum_nat_seq_eq1 (I : eqType) r (P : pred I) (F : I -> nat) :
(\sum_(i <- r | P i) F i = 1)%N ->
exists i, [/\ i \in r, P i, F i = 1
& forall j, j != i -> j \in r -> P j -> F j = 0]%N.
Proof.
rewrite big_tnth/= => /eqP/sum_nat_eq1[/= i [Pi Fi FNi]].
exists (tnth (in_tuple r) i); split; rewrite //= ?mem_tnth// => j.
move=> /[swap] /(tnthP (in_tuple r))[{} j -> Nij /FNi->//].
by apply: contra_neq Nij => ->.
Qed.
Lemma prod_nat_seq_eq0 I r (P : pred I) F :
(\prod_(i <- r | P i) F i == 0)%N = has (fun i => P i && (F i == 0%N)) r.
Proof. by rewrite (big_morph _ (id1 := false) muln_eq0)// big_has_cond. Qed.
Lemma prod_nat_seq_neq0 I r (P : pred I) F :
(\prod_(i <- r | P i) F i != 0)%N = all (fun i => P i ==> (F i != 0%N)) r.
Proof.
by rewrite prod_nat_seq_eq0 -all_predC; apply: eq_all => i /=; case: (P i).
Qed.
Lemma prod_nat_seq_eq1 I r (P : pred I) F :
(\prod_(i <- r | P i) F i == 1)%N = all (fun i => P i ==> (F i == 1%N)) r.
Proof. by rewrite (big_morph _ (id1:=true) muln_eq1)// big_all_cond. Qed.
Lemma prod_nat_seq_neq1 I r (P : pred I) F :
(\prod_(i <- r | P i) F i != 1)%N = has (fun i => P i && (F i != 1%N)) r.
Proof.
by rewrite prod_nat_seq_eq1 -has_predC; apply: eq_has => i /=; case: (P i).
Qed.
Lemma leq_prod I r (P : pred I) (E1 E2 : I -> nat) :
(forall i, P i -> E1 i <= E2 i) ->
\prod_(i <- r | P i) E1 i <= \prod_(i <- r | P i) E2 i.
Proof. by move=> leE12; elim/big_ind2: _ => // m1 m2 n1 n2; apply: leq_mul. Qed.
Arguments leq_prod [I r P E1 E2].
Lemma prodn_cond_gt0 I r (P : pred I) F :
(forall i, P i -> 0 < F i) -> 0 < \prod_(i <- r | P i) F i.
Proof. by move=> Fpos; elim/big_ind: _ => // n1 n2; rewrite muln_gt0 => ->. Qed.
Arguments prodn_cond_gt0 [I r P F].
Lemma prodn_gt0 I r (P : pred I) F :
(forall i, 0 < F i) -> 0 < \prod_(i <- r | P i) F i.
Proof. by move=> Fpos; apply: prodn_cond_gt0. Qed.
Arguments prodn_gt0 [I r P F].
Lemma gt0_prodn_seq (I : eqType) r (P : pred I) F :
0 < \prod_(i <- r | P i) F i -> forall i, i \in r -> P i -> 0 < F i.
Proof.
move=> + i ri Pi; rewrite !lt0n; apply: contra_neq => Fi_eq0.
by case: (path.splitP ri) => *; rewrite big_cat big_rcons Pi Fi_eq0/= muln0.
Qed.
Arguments gt0_prodn_seq [I r P F].
Lemma gt0_prodn (I : finType) (P : pred I) F :
0 < \prod_(i | P i) F i -> forall i, P i -> 0 < F i.
Proof. by move=> /gt0_prodn_seq + i => /[apply]; apply. Qed.
Arguments gt0_prodn [I P F].
Lemma leq_bigmax_seq (I : eqType) r (P : pred I) F i0 :
i0 \in r -> P i0 -> F i0 <= \max_(i <- r | P i) F i.
Proof.
move=> + Pi0; elim: r => // h t ih; rewrite inE big_cons.
move=> /predU1P[<-|i0t]; first by rewrite Pi0 leq_maxl.
by case: ifPn => Ph; [rewrite leq_max ih// orbT|rewrite ih].
Qed.
Arguments leq_bigmax_seq [I r P F].
Lemma leq_bigmax_cond (I : finType) (P : pred I) F i0 :
P i0 -> F i0 <= \max_(i | P i) F i.
Proof. exact: leq_bigmax_seq. Qed.
Arguments leq_bigmax_cond [I P F].
Lemma leq_bigmax (I : finType) F (i0 : I) : F i0 <= \max_i F i.
Proof. exact: leq_bigmax_cond. Qed.
Arguments leq_bigmax [I F].
Lemma bigmax_leqP (I : finType) (P : pred I) m F :
reflect (forall i, P i -> F i <= m) (\max_(i | P i) F i <= m).
Proof.
apply: (iffP idP) => leFm => [i Pi|].
by apply: leq_trans leFm; apply: leq_bigmax_cond.
by elim/big_ind: _ => // m1 m2; rewrite geq_max => ->.
Qed.
Lemma bigmax_leqP_seq (I : eqType) r (P : pred I) m F :
reflect (forall i, i \in r -> P i -> F i <= m) (\max_(i <- r | P i) F i <= m).
Proof.
apply: (iffP idP) => leFm => [i ri Pi|].
exact/(leq_trans _ leFm)/leq_bigmax_seq.
rewrite big_seq_cond; elim/big_ind: _ => // [m1 m2|i /andP[ri]].
by rewrite geq_max => ->.
exact: leFm.
Qed.
Lemma bigmax_sup (I : finType) i0 (P : pred I) m F :
P i0 -> m <= F i0 -> m <= \max_(i | P i) F i.
Proof. by move=> Pi0 le_m_Fi0; apply: leq_trans (leq_bigmax_cond i0 Pi0). Qed.
Arguments bigmax_sup [I] i0 [P m F].
Lemma bigmax_sup_seq (I : eqType) r i0 (P : pred I) m F :
i0 \in r -> P i0 -> m <= F i0 -> m <= \max_(i <- r | P i) F i.
Proof. by move=> i0r Pi0 ?; apply: leq_trans (leq_bigmax_seq i0 _ _). Qed.
Arguments bigmax_sup_seq [I r] i0 [P m F].
Lemma bigmax_eq_arg (I : finType) i0 (P : pred I) F :
P i0 -> \max_(i | P i) F i = F [arg max_(i > i0 | P i) F i].
Proof.
move=> Pi0; case: arg_maxnP => //= i Pi maxFi.
by apply/eqP; rewrite eqn_leq leq_bigmax_cond // andbT; apply/bigmax_leqP.
Qed.
Arguments bigmax_eq_arg [I] i0 [P F].
Lemma eq_bigmax_cond (I : finType) (A : pred I) F :
#|A| > 0 -> {i0 | i0 \in A & \max_(i in A) F i = F i0}.
Proof.
case: (pickP A) => [i0 Ai0 _ | ]; last by move/eq_card0->.
by exists [arg max_(i > i0 in A) F i]; [case: arg_maxnP | apply: bigmax_eq_arg].
Qed.
Lemma eq_bigmax (I : finType) F : #|I| > 0 -> {i0 : I | \max_i F i = F i0}.
Proof. by case/(eq_bigmax_cond F) => x _ ->; exists x. Qed.
Lemma expn_sum m I r (P : pred I) F :
(m ^ (\sum_(i <- r | P i) F i) = \prod_(i <- r | P i) m ^ F i)%N.
Proof. exact: (big_morph _ (expnD m)). Qed.
Lemma dvdn_biglcmP (I : finType) (P : pred I) F m :
reflect (forall i, P i -> F i %| m) (\big[lcmn/1%N]_(i | P i) F i %| m).
Proof.
apply: (iffP idP) => [dvFm i Pi | dvFm].
by rewrite (bigD1 i) // dvdn_lcm in dvFm; case/andP: dvFm.
by elim/big_ind: _ => // p q p_m; rewrite dvdn_lcm p_m.
Qed.
Lemma biglcmn_sup (I : finType) i0 (P : pred I) F m :
P i0 -> m %| F i0 -> m %| \big[lcmn/1%N]_(i | P i) F i.
Proof.
by move=> Pi0 m_Fi0; rewrite (dvdn_trans m_Fi0) // (bigD1 i0) ?dvdn_lcml.
Qed.
Arguments biglcmn_sup [I] i0 [P F m].
Lemma dvdn_biggcdP (I : finType) (P : pred I) F m :
reflect (forall i, P i -> m %| F i) (m %| \big[gcdn/0]_(i | P i) F i).
Proof.
apply: (iffP idP) => [dvmF i Pi | dvmF].
by rewrite (bigD1 i) // dvdn_gcd in dvmF; case/andP: dvmF.
by elim/big_ind: _ => // p q m_p; rewrite dvdn_gcd m_p.
Qed.
Lemma biggcdn_inf (I : finType) i0 (P : pred I) F m :
P i0 -> F i0 %| m -> \big[gcdn/0]_(i | P i) F i %| m.
Proof. by move=> Pi0; apply: dvdn_trans; rewrite (bigD1 i0) ?dvdn_gcdl. Qed.
Arguments biggcdn_inf [I] i0 [P F m].
|
Finset.lean
|
/-
Copyright (c) 2022 Eric Wieser, Yaël Dillies, Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Yaël Dillies, Andrew Yang
-/
import Mathlib.Algebra.Order.Ring.Canonical
import Mathlib.Data.Finset.Lattice.Fold
import Mathlib.Data.Nat.Cast.Order.Ring
/-!
# `Finset.sup` and ring operations
-/
open Finset
namespace Nat
variable {ι R : Type*}
section LinearOrderedSemiring
variable [Semiring R] [LinearOrder R] [IsStrictOrderedRing R] {s : Finset ι}
set_option linter.docPrime false in
@[simp, norm_cast]
lemma cast_finsetSup' (f : ι → ℕ) (hs) : ((s.sup' hs f : ℕ) : R) = s.sup' hs fun i ↦ (f i : R) :=
comp_sup'_eq_sup'_comp _ _ cast_max
set_option linter.docPrime false in
@[simp, norm_cast]
lemma cast_finsetInf' (f : ι → ℕ) (hs) : (↑(s.inf' hs f) : R) = s.inf' hs fun i ↦ (f i : R) :=
comp_inf'_eq_inf'_comp _ _ cast_min
@[simp, norm_cast]
lemma cast_finsetSup [OrderBot R] [CanonicallyOrderedAdd R] (s : Finset ι) (f : ι → ℕ) :
(↑(s.sup f) : R) = s.sup fun i ↦ (f i : R) :=
comp_sup_eq_sup_comp _ cast_max (by simp)
end LinearOrderedSemiring
end Nat
section
variable {R ι : Type*} [LinearOrder R] [NonUnitalNonAssocSemiring R]
[CanonicallyOrderedAdd R] [OrderBot R]
lemma Finset.mul_sup₀ (s : Finset ι) (f : ι → R) (a : R) :
a * s.sup f = s.sup (a * f ·) := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ _ IH => simp only [sup_insert, mul_max, ← IH]
/-- Also see `Finset.sup'_mul₀` for a version for `GroupWithZero`s. -/
lemma Finset.sup_mul₀ (s : Finset ι) (f : ι → R) (a : R) :
s.sup f * a = s.sup (f · * a) := by
classical
induction s using Finset.induction with
| empty => simp
| insert _ _ _ IH => simp only [sup_insert, max_mul, ← IH]
end
|
automorphism.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat fintype.
From mathcomp Require Import finset fingroup perm morphism.
(******************************************************************************)
(* Group automorphisms and characteristic subgroups. *)
(* Unlike morphisms on a group G, which are functions of type gT -> rT, with *)
(* a canonical structure of dependent type {morphim G >-> rT}, automorphisms *)
(* are permutations of type {perm gT} contained in Aut G : {set {perm gT}}. *)
(* This lets us use the finGroupType of {perm gT}. Note also that while *)
(* morphisms on G are undefined outside G, automorphisms have their support *)
(* in G, i.e., they are the identity outside G. *)
(* Definitions: *)
(* Aut G (or [Aut G]) == the automorphism group of G. *)
(* [Aut G]%G == the group structure for Aut G. *)
(* autm AutGa == the morphism on G induced by a, given *)
(* AutGa : a \in Aut G. *)
(* perm_in injf fA == the permutation with support B in induced by f, *)
(* given injf : {in A &, injective f} and *)
(* fA : f @: A \subset A. *)
(* aut injf fG == the automorphism of G induced by the morphism f, *)
(* given injf : 'injm f and fG : f @* G \subset G. *)
(* Aut_isom injf sDom == the injective homomorphism that maps Aut G to *)
(* Aut (f @* G), with f : {morphism D >-> rT} and *)
(* given injf: 'injm f and sDom : G \subset D. *)
(* conjgm G == the conjugation automorphism on G. *)
(* H \char G == H is a characteristic subgroup of G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
(***********************************************************************)
(* A group automorphism, defined as a permutation on a subset of a *)
(* finGroupType that respects the morphism law. *)
(* Here perm_on is used as a closure rule for the set A. *)
(***********************************************************************)
Section Automorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Types a b : {perm gT}.
Definition Aut A := [set a | perm_on A a & morphic A a].
Lemma Aut_morphic A a : a \in Aut A -> morphic A a.
Proof. by case/setIdP. Qed.
Lemma out_Aut A a x : a \in Aut A -> x \notin A -> a x = x.
Proof. by case/setIdP=> Aa _; apply: out_perm. Qed.
Lemma eq_Aut A : {in Aut A &, forall a b, {in A, a =1 b} -> a = b}.
Proof.
move=> a g Aa Ag /= eqag; apply/permP=> x.
by have [/eqag // | /out_Aut out] := boolP (x \in A); rewrite !out.
Qed.
(* The morphism that is represented by a given element of Aut A. *)
Definition autm A a (AutAa : a \in Aut A) := morphm (Aut_morphic AutAa).
Lemma autmE A a (AutAa : a \in Aut A) : autm AutAa = a.
Proof. by []. Qed.
Canonical autm_morphism A a aM := Eval hnf in [morphism of @autm A a aM].
Section AutGroup.
Variable G : {group gT}.
Lemma Aut_group_set : group_set (Aut G).
Proof.
apply/group_setP; split=> [|a b].
by rewrite inE perm_on1; apply/morphicP=> ? *; rewrite !permE.
rewrite !inE => /andP[Ga aM] /andP[Gb bM]; rewrite perm_onM //=.
apply/morphicP=> x y Gx Gy; rewrite !permM (morphicP aM) //.
by rewrite (morphicP bM) ?perm_closed.
Qed.
Canonical Aut_group := group Aut_group_set.
Variable (a : {perm gT}) (AutGa : a \in Aut G).
Notation f := (autm AutGa).
Notation fE := (autmE AutGa).
Lemma injm_autm : 'injm f.
Proof. by apply/injmP; apply: in2W; apply: perm_inj. Qed.
Lemma ker_autm : 'ker f = 1. Proof. by move/trivgP: injm_autm. Qed.
Lemma im_autm : f @* G = G.
Proof.
apply/setP=> x; rewrite morphimEdom (can_imset_pre _ (permK a)) inE.
by have /[1!inE] /andP[/perm_closed <-] := AutGa; rewrite permKV.
Qed.
Lemma Aut_closed x : x \in G -> a x \in G.
Proof. by move=> Gx; rewrite -im_autm; apply: mem_morphim. Qed.
End AutGroup.
Lemma Aut1 : Aut 1 = 1.
Proof.
apply/trivgP/subsetP=> a /= AutGa; apply/set1P.
apply: eq_Aut (AutGa) (group1 _) _ => _ /set1P->.
by rewrite -(autmE AutGa) morph1 perm1.
Qed.
End Automorphism.
Arguments Aut _ _%_g.
Notation "[ 'Aut' G ]" := (Aut_group G) (format "[ 'Aut' G ]") : Group_scope.
Notation "[ 'Aut' G ]" := (Aut G) (only parsing) : group_scope.
Prenex Implicits Aut autm.
(* The permutation function (total on the underlying groupType) that is the *)
(* representant of a given morphism f with domain A in (Aut A). *)
Section PermIn.
Variables (T : finType) (A : {set T}) (f : T -> T).
Hypotheses (injf : {in A &, injective f}) (sBf : f @: A \subset A).
Lemma perm_in_inj : injective (fun x => if x \in A then f x else x).
Proof.
move=> x y /=; wlog Ay: x y / y \in A.
by move=> IH eqfxy; case: ifP (eqfxy); [symmetry | case: ifP => //]; auto.
rewrite Ay; case: ifP => [Ax | nAx def_x]; first exact: injf.
by case/negP: nAx; rewrite def_x (subsetP sBf) ?imset_f.
Qed.
Definition perm_in := perm perm_in_inj.
Lemma perm_in_on : perm_on A perm_in.
Proof.
by apply/subsetP=> x; rewrite inE /= permE; case: ifP => // _; case/eqP.
Qed.
Lemma perm_inE : {in A, perm_in =1 f}.
Proof. by move=> x Ax; rewrite /= permE Ax. Qed.
End PermIn.
(* properties of injective endomorphisms *)
Section MakeAut.
Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> gT}).
Implicit Type A : {set gT}.
Hypothesis injf : 'injm f.
Lemma morphim_fixP A : A \subset G -> reflect (f @* A = A) (f @* A \subset A).
Proof.
rewrite /morphim => sAG; have:= eqEcard (f @: A) A.
rewrite (setIidPr sAG) card_in_imset ?leqnn ?andbT => [<-|]; first exact: eqP.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
Qed.
Hypothesis Gf : f @* G = G.
Lemma aut_closed : f @: G \subset G.
Proof. by rewrite -morphimEdom; apply/morphim_fixP. Qed.
Definition aut := perm_in (injmP injf) aut_closed.
Lemma autE : {in G, aut =1 f}.
Proof. exact: perm_inE. Qed.
Lemma morphic_aut : morphic G aut.
Proof. by apply/morphicP=> x y Gx Gy /=; rewrite !autE ?groupM // morphM. Qed.
Lemma Aut_aut : aut \in Aut G.
Proof. by rewrite inE morphic_aut perm_in_on. Qed.
Lemma imset_autE A : A \subset G -> aut @: A = f @* A.
Proof.
move=> sAG; rewrite /morphim (setIidPr sAG).
by apply: eq_in_imset; apply: sub_in1 autE; apply/subsetP.
Qed.
Lemma preim_autE A : A \subset G -> aut @^-1: A = f @*^-1 A.
Proof.
move=> sAG; apply/setP=> x; rewrite !inE permE /=.
by case Gx: (x \in G) => //; apply/negP=> Ax; rewrite (subsetP sAG) in Gx.
Qed.
End MakeAut.
Arguments morphim_fixP {gT G f}.
Prenex Implicits aut.
Section AutIsom.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma Aut_isom_subproof a :
{a' | a' \in Aut (f @* G) & a \in Aut G -> {in G, a' \o f =1 f \o a}}.
Proof.
set Aut_a := autm (subgP (subg [Aut G] a)).
have aDom: 'dom (f \o Aut_a \o invm injf) = f @* G.
rewrite /dom /= morphpre_invm -morphpreIim; congr (f @* _).
by rewrite [_ :&: D](setIidPl _) ?injmK ?injm_autm ?im_autm.
have [af [def_af ker_af _ im_af]] := domP _ aDom.
have inj_a': 'injm af by rewrite ker_af !injm_comp ?injm_autm ?injm_invm.
have im_a': af @* (f @* G) = f @* G.
by rewrite im_af !morphim_comp morphim_invm // im_autm.
pose a' := aut inj_a' im_a'; exists a' => [|AutGa x Gx]; first exact: Aut_aut.
have Dx := domG Gx; rewrite /= [a' _]autE ?mem_morphim //.
by rewrite def_af /= invmE // autmE subgK.
Qed.
Definition Aut_isom a := s2val (Aut_isom_subproof a).
Lemma Aut_Aut_isom a : Aut_isom a \in Aut (f @* G).
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomE a : a \in Aut G -> {in G, forall x, Aut_isom a (f x) = f (a x)}.
Proof. by rewrite /Aut_isom; case: (Aut_isom_subproof a). Qed.
Lemma Aut_isomM : {in Aut G &, {morph Aut_isom: x y / x * y}}.
Proof.
move=> a b AutGa AutGb.
apply: (eq_Aut (Aut_Aut_isom _)); rewrite ?groupM ?Aut_Aut_isom // => fx.
case/morphimP=> x Dx Gx ->{fx}.
by rewrite permM !Aut_isomE ?groupM /= ?permM ?Aut_closed.
Qed.
Canonical Aut_isom_morphism := Morphism Aut_isomM.
Lemma injm_Aut_isom : 'injm Aut_isom.
Proof.
apply/injmP=> a b AutGa AutGb eq_ab'; apply: (eq_Aut AutGa AutGb) => x Gx.
by apply: (injmP injf); rewrite ?domG ?Aut_closed // -!Aut_isomE //= eq_ab'.
Qed.
End AutIsom.
Section InjmAut.
Variables (gT rT : finGroupType) (G D : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let domG := subsetP sGD.
Lemma im_Aut_isom : Aut_isom injf sGD @* Aut G = Aut (f @* G).
Proof.
apply/eqP; rewrite eqEcard; apply/andP; split.
by apply/subsetP=> _ /morphimP[a _ AutGa ->]; apply: Aut_Aut_isom.
have inj_isom' := injm_Aut_isom (injm_invm injf) (morphimS _ sGD).
rewrite card_injm ?injm_Aut_isom // -(card_injm inj_isom') ?subset_leq_card //.
apply/subsetP=> a /morphimP[a' _ AutfGa' def_a].
by rewrite -(morphim_invm injf sGD) def_a Aut_Aut_isom.
Qed.
Lemma Aut_isomP : isom (Aut G) (Aut (f @* G)) (Aut_isom injf sGD).
Proof. by apply/isomP; split; [apply: injm_Aut_isom | apply: im_Aut_isom]. Qed.
Lemma injm_Aut : Aut (f @* G) \isog Aut G.
Proof. by rewrite isog_sym (isom_isog _ _ Aut_isomP). Qed.
End InjmAut.
(* conjugation automorphism *)
Section ConjugationMorphism.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Definition conjgm of {set gT} := fun x y : gT => y ^ x.
Lemma conjgmE A x y : conjgm A x y = y ^ x. Proof. by []. Qed.
Canonical conjgm_morphism A x :=
@Morphism _ _ A (conjgm A x) (in2W (fun y z => conjMg y z x)).
Lemma morphim_conj A x B : conjgm A x @* B = (A :&: B) :^ x.
Proof. by []. Qed.
Variable G : {group gT}.
Lemma injm_conj x : 'injm (conjgm G x).
Proof. by apply/injmP; apply: in2W; apply: conjg_inj. Qed.
Lemma conj_isom x : isom G (G :^ x) (conjgm G x).
Proof. by apply/isomP; rewrite morphim_conj setIid injm_conj. Qed.
Lemma conj_isog x : G \isog G :^ x.
Proof. exact: isom_isog (conj_isom x). Qed.
Lemma norm_conjg_im x : x \in 'N(G) -> conjgm G x @* G = G.
Proof. by rewrite morphimEdom; apply: normP. Qed.
Lemma norm_conj_isom x : x \in 'N(G) -> isom G G (conjgm G x).
Proof. by move/norm_conjg_im/restr_isom_to/(_ (conj_isom x))->. Qed.
Definition conj_aut x := aut (injm_conj _) (norm_conjg_im (subgP (subg _ x))).
Lemma norm_conj_autE : {in 'N(G) & G, forall x y, conj_aut x y = y ^ x}.
Proof. by move=> x y nGx Gy; rewrite /= autE //= subgK. Qed.
Lemma conj_autE : {in G &, forall x y, conj_aut x y = y ^ x}.
Proof. by apply: sub_in11 norm_conj_autE => //; apply: subsetP (normG G). Qed.
Lemma conj_aut_morphM : {in 'N(G) &, {morph conj_aut : x y / x * y}}.
Proof.
move=> x y nGx nGy; apply/permP=> z /=; rewrite permM.
case Gz: (z \in G); last by rewrite !permE /= !Gz.
by rewrite !norm_conj_autE // (conjgM, memJ_norm, groupM).
Qed.
Canonical conj_aut_morphism := Morphism conj_aut_morphM.
Lemma ker_conj_aut : 'ker conj_aut = 'C(G).
Proof.
apply/setP=> x /[1!inE]; case nGx: (x \in 'N(G)); last first.
by symmetry; apply/idP=> cGx; rewrite (subsetP (cent_sub G)) in nGx.
rewrite 2!inE /=; apply/eqP/centP=> [cx1 y Gy | cGx].
by rewrite /commute (conjgC y) -norm_conj_autE // cx1 perm1.
apply/permP=> y; case Gy: (y \in G); last by rewrite !permE Gy.
by rewrite perm1 norm_conj_autE // conjgE -cGx ?mulKg.
Qed.
Lemma Aut_conj_aut A : conj_aut @* A \subset Aut G.
Proof. by apply/subsetP=> _ /imsetP[x _ ->]; apply: Aut_aut. Qed.
End ConjugationMorphism.
Arguments conjgm _ _%_g.
Prenex Implicits conjgm conj_aut.
Reserved Notation "G \char H" (at level 70).
(* Characteristic subgroup *)
Section Characteristicity.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H K L : {group gT}.
Definition characteristic A B :=
(A \subset B) && [forall f in Aut B, f @: A \subset A].
Infix "\char" := characteristic.
Lemma charP H G :
let fixH (f : {morphism G >-> gT}) := 'injm f -> f @* G = G -> f @* H = H in
reflect [/\ H \subset G & forall f, fixH f] (H \char G).
Proof.
do [apply: (iffP andP) => -[sHG chHG]; split] => // [f injf Gf|].
by apply/morphim_fixP; rewrite // -imset_autE ?(forall_inP chHG) ?Aut_aut.
apply/forall_inP=> f Af; rewrite -(autmE Af) -morphimEsub //.
by rewrite chHG ?injm_autm ?im_autm.
Qed.
(* Characteristic subgroup properties : composition, relational properties *)
Lemma char1 G : 1 \char G.
Proof. by apply/charP; split=> [|f _ _]; rewrite (sub1G, morphim1). Qed.
Lemma char_refl G : G \char G.
Proof. exact/charP. Qed.
Lemma char_trans H G K : K \char H -> H \char G -> K \char G.
Proof.
case/charP=> sKH chKH; case/charP=> sHG chHG.
apply/charP; split=> [|f injf Gf]; first exact: subset_trans sHG.
rewrite -{1}(setIidPr sKH) -(morphim_restrm sHG) chKH //.
by rewrite ker_restrm; move/trivgP: injf => ->; apply: subsetIr.
by rewrite morphim_restrm setIid chHG.
Qed.
Lemma char_norms H G : H \char G -> 'N(G) \subset 'N(H).
Proof.
case/charP=> sHG chHG; apply/normsP=> x /normP-Nx.
have:= chHG [morphism of conjgm G x] => /=.
by rewrite !morphimEsub //=; apply; rewrite // injm_conj.
Qed.
Lemma char_sub A B : A \char B -> A \subset B.
Proof. by case/andP. Qed.
Lemma char_norm_trans H G A : H \char G -> A \subset 'N(G) -> A \subset 'N(H).
Proof. by move/char_norms=> nHnG nGA; apply: subset_trans nHnG. Qed.
Lemma char_normal_trans H G K : K \char H -> H <| G -> K <| G.
Proof.
move=> chKH /andP[sHG nHG].
by rewrite /normal (subset_trans (char_sub chKH)) // (char_norm_trans chKH).
Qed.
Lemma char_normal H G : H \char G -> H <| G.
Proof. by move/char_normal_trans; apply; apply/andP; rewrite normG. Qed.
Lemma char_norm H G : H \char G -> G \subset 'N(H).
Proof. by case/char_normal/andP. Qed.
Lemma charI G H K : H \char G -> K \char G -> H :&: K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> _ chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite subIset // sHG.
by rewrite morphimGI ?(chHG, chKG) //; apply: subset_trans (sub1G H).
Qed.
Lemma charY G H K : H \char G -> K \char G -> H <*> K \char G.
Proof.
case/charP=> sHG chHG; case/charP=> sKG chKG.
apply/charP; split=> [|f injf Gf]; first by rewrite gen_subG subUset sHG.
by rewrite morphim_gen ?(morphimU, subUset, sHG, chHG, chKG).
Qed.
Lemma charM G H K : H \char G -> K \char G -> H * K \char G.
Proof.
move=> chHG chKG; rewrite -norm_joinEl ?charY //.
exact: subset_trans (char_sub chHG) (char_norm chKG).
Qed.
Lemma lone_subgroup_char G H :
H \subset G -> (forall K, K \subset G -> K \isog H -> K \subset H) ->
H \char G.
Proof.
move=> sHG Huniq; apply/charP; split=> // f injf Gf; apply/eqP.
have{} injf: {in H &, injective f}.
by move/injmP: injf; apply: sub_in2; apply/subsetP.
have fH: f @* H = f @: H by rewrite /morphim (setIidPr sHG).
rewrite eqEcard {2}fH card_in_imset ?{}Huniq //=.
by rewrite -{3}Gf morphimS.
rewrite isog_sym; apply/isogP.
exists [morphism of restrm sHG f] => //=; first exact/injmP.
by rewrite morphimEdom fH.
Qed.
End Characteristicity.
Arguments characteristic _ _%_g _%_g.
Notation "H \char G" := (characteristic H G) : group_scope.
#[global] Hint Resolve char_refl : core.
Section InjmChar.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma injm_char (G H : {group aT}) :
G \subset D -> H \char G -> f @* H \char f @* G.
Proof.
move=> sGD /charP[sHG charH].
apply/charP; split=> [|g injg gfG]; first exact: morphimS.
have /domP[h [_ ker_h _ im_h]]: 'dom (invm injf \o g \o f) = G.
by rewrite /dom /= -(morphpreIim g) (setIidPl _) ?injmK // gfG morphimS.
have hH: h @* H = H.
apply: charH; first by rewrite ker_h !injm_comp ?injm_invm.
by rewrite im_h !morphim_comp gfG morphim_invm.
rewrite /= -{2}hH im_h !morphim_comp morphim_invmE morphpreK //.
by rewrite (subset_trans _ (morphimS f sGD)) //= -{3}gfG !morphimS.
Qed.
End InjmChar.
Section CharInjm.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Lemma char_injm (G H : {group aT}) :
G \subset D -> H \subset D -> (f @* H \char f @* G) = (H \char G).
Proof.
move=> sGD sHD; apply/idP/idP; last exact: injm_char.
by move/(injm_char (injm_invm injf)); rewrite !morphim_invm ?morphimS // => ->.
Qed.
End CharInjm.
Unset Implicit Arguments.
|
Exponential.lean
|
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Eric Wieser
-/
import Mathlib.Algebra.Ring.Action.ConjAct
import Mathlib.Analysis.Analytic.ChangeOrigin
import Mathlib.Analysis.Complex.Basic
import Mathlib.Data.Nat.Choose.Cast
import Mathlib.Analysis.Analytic.OfScalars
import Mathlib.Analysis.SpecificLimits.RCLike
/-!
# Exponential in a Banach algebra
In this file, we define `NormedSpace.exp 𝕂 : 𝔸 → 𝔸`,
the exponential map in a topological algebra `𝔸` over a field `𝕂`.
While for most interesting results we need `𝔸` to be normed algebra, we do not require this in the
definition in order to make `NormedSpace.exp` independent of a particular choice of norm. The
definition also does not require that `𝔸` be complete, but we need to assume it for most results.
We then prove some basic results, but we avoid importing derivatives here to minimize dependencies.
Results involving derivatives and comparisons with `Real.exp` and `Complex.exp` can be found in
`Analysis.SpecialFunctions.Exponential`.
## Main results
We prove most result for an arbitrary field `𝕂`, and then specialize to `𝕂 = ℝ` or `𝕂 = ℂ`.
### General case
- `NormedSpace.exp_add_of_commute_of_mem_ball` : if `𝕂` has characteristic zero,
then given two commuting elements `x` and `y` in the disk of convergence, we have
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`
- `NormedSpace.exp_add_of_mem_ball` : if `𝕂` has characteristic zero and `𝔸` is commutative,
then given two elements `x` and `y` in the disk of convergence, we have
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`
- `NormedSpace.exp_neg_of_mem_ball` : if `𝕂` has characteristic zero and `𝔸` is a division ring,
then given an element `x` in the disk of convergence,
we have `NormedSpace.exp 𝕂 (-x) = (NormedSpace.exp 𝕂 x)⁻¹`.
### `𝕂 = ℝ` or `𝕂 = ℂ`
- `expSeries_radius_eq_top` : the `FormalMultilinearSeries` defining `NormedSpace.exp 𝕂`
has infinite radius of convergence
- `NormedSpace.exp_add_of_commute` : given two commuting elements `x` and `y`, we have
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`
- `NormedSpace.exp_add` : if `𝔸` is commutative, then we have
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)` for any `x` and `y`
- `NormedSpace.exp_neg` : if `𝔸` is a division ring, then we have
`NormedSpace.exp 𝕂 (-x) = (NormedSpace.exp 𝕂 x)⁻¹`.
- `NormedSpace.exp_sum_of_commute` : the analogous result to `NormedSpace.exp_add_of_commute`
for `Finset.sum`.
- `NormedSpace.exp_sum` : the analogous result to `NormedSpace.exp_add` for `Finset.sum`.
- `NormedSpace.exp_nsmul` : repeated addition in the domain corresponds to
repeated multiplication in the codomain.
- `NormedSpace.exp_zsmul` : repeated addition in the domain corresponds to
repeated multiplication in the codomain.
### Other useful compatibility results
- `NormedSpace.exp_eq_exp` : if `𝔸` is a normed algebra over two fields `𝕂` and `𝕂'`,
then `NormedSpace.exp 𝕂 = NormedSpace.exp 𝕂' 𝔸`
### Notes
We put nearly all the statements in this file in the `NormedSpace` namespace,
to avoid collisions with the `Real` or `Complex` namespaces.
As of 2023-11-16 due to bad instances in Mathlib
```
import Mathlib
open Real
#time example (x : ℝ) : 0 < exp x := exp_pos _ -- 250ms
#time example (x : ℝ) : 0 < Real.exp x := exp_pos _ -- 2ms
```
This is because `exp x` tries the `NormedSpace.exp` function defined here,
and generates a slow coercion search from `Real` to `Type`, to fit the first argument here.
We will resolve this slow coercion separately,
but we want to move `exp` out of the root namespace in any case to avoid this ambiguity.
In the long term is may be possible to replace `Real.exp` and `Complex.exp` with this one.
-/
namespace NormedSpace
open Filter RCLike ContinuousMultilinearMap NormedField Asymptotics FormalMultilinearSeries
open scoped Nat Topology ENNReal
section TopologicalAlgebra
variable (𝕂 𝔸 : Type*) [Field 𝕂] [Ring 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸] [IsTopologicalRing 𝔸]
/-- `expSeries 𝕂 𝔸` is the `FormalMultilinearSeries` whose `n`-th term is the map
`(xᵢ) : 𝔸ⁿ ↦ (1/n! : 𝕂) • ∏ xᵢ`. Its sum is the exponential map `NormedSpace.exp 𝕂 : 𝔸 → 𝔸`. -/
def expSeries : FormalMultilinearSeries 𝕂 𝔸 𝔸 := fun n =>
(n !⁻¹ : 𝕂) • ContinuousMultilinearMap.mkPiAlgebraFin 𝕂 n 𝔸
/-- The exponential series as an `ofScalars` series. -/
theorem expSeries_eq_ofScalars : expSeries 𝕂 𝔸 = ofScalars 𝔸 fun n ↦ (n !⁻¹ : 𝕂) := by
simp_rw [FormalMultilinearSeries.ext_iff, expSeries, ofScalars, implies_true]
variable {𝔸}
/-- `NormedSpace.exp 𝕂 : 𝔸 → 𝔸` is the exponential map determined by the action of `𝕂` on `𝔸`.
It is defined as the sum of the `FormalMultilinearSeries` `expSeries 𝕂 𝔸`.
Note that when `𝔸 = Matrix n n 𝕂`, this is the **Matrix Exponential**; see
[`MatrixExponential`](./Mathlib/Analysis/Normed/Algebra/MatrixExponential) for lemmas
specific to that case. -/
noncomputable def exp (x : 𝔸) : 𝔸 :=
(expSeries 𝕂 𝔸).sum x
variable {𝕂}
theorem expSeries_apply_eq (x : 𝔸) (n : ℕ) :
(expSeries 𝕂 𝔸 n fun _ => x) = (n !⁻¹ : 𝕂) • x ^ n := by simp [expSeries]
theorem expSeries_apply_eq' (x : 𝔸) :
(fun n => expSeries 𝕂 𝔸 n fun _ => x) = fun n => (n !⁻¹ : 𝕂) • x ^ n :=
funext (expSeries_apply_eq x)
theorem expSeries_sum_eq (x : 𝔸) : (expSeries 𝕂 𝔸).sum x = ∑' n : ℕ, (n !⁻¹ : 𝕂) • x ^ n :=
tsum_congr fun n => expSeries_apply_eq x n
theorem exp_eq_tsum : exp 𝕂 = fun x : 𝔸 => ∑' n : ℕ, (n !⁻¹ : 𝕂) • x ^ n :=
funext expSeries_sum_eq
/-- The exponential sum as an `ofScalarsSum`. -/
theorem exp_eq_ofScalarsSum : exp 𝕂 = ofScalarsSum (E := 𝔸) fun n ↦ (n !⁻¹ : 𝕂) := by
rw [exp_eq_tsum, ofScalarsSum_eq_tsum]
theorem expSeries_apply_zero (n : ℕ) :
expSeries 𝕂 𝔸 n (fun _ => (0 : 𝔸)) = Pi.single (M := fun _ => 𝔸) 0 1 n := by
rw [expSeries_apply_eq]
rcases n with - | n
· rw [pow_zero, Nat.factorial_zero, Nat.cast_one, inv_one, one_smul, Pi.single_eq_same]
· rw [zero_pow (Nat.succ_ne_zero _), smul_zero, Pi.single_eq_of_ne n.succ_ne_zero]
@[simp]
theorem exp_zero : exp 𝕂 (0 : 𝔸) = 1 := by
simp_rw [exp_eq_tsum, ← expSeries_apply_eq, expSeries_apply_zero, tsum_pi_single]
@[simp]
theorem exp_op [T2Space 𝔸] (x : 𝔸) : exp 𝕂 (MulOpposite.op x) = MulOpposite.op (exp 𝕂 x) := by
simp_rw [exp, expSeries_sum_eq, ← MulOpposite.op_pow, ← MulOpposite.op_smul, tsum_op]
@[simp]
theorem exp_unop [T2Space 𝔸] (x : 𝔸ᵐᵒᵖ) :
exp 𝕂 (MulOpposite.unop x) = MulOpposite.unop (exp 𝕂 x) := by
simp_rw [exp, expSeries_sum_eq, ← MulOpposite.unop_pow, ← MulOpposite.unop_smul, tsum_unop]
theorem star_exp [T2Space 𝔸] [StarRing 𝔸] [ContinuousStar 𝔸] (x : 𝔸) :
star (exp 𝕂 x) = exp 𝕂 (star x) := by
simp_rw [exp_eq_tsum, ← star_pow, ← star_inv_natCast_smul, ← tsum_star]
variable (𝕂)
@[aesop safe apply]
theorem _root_.IsSelfAdjoint.exp [T2Space 𝔸] [StarRing 𝔸] [ContinuousStar 𝔸] {x : 𝔸}
(h : IsSelfAdjoint x) : IsSelfAdjoint (exp 𝕂 x) :=
(star_exp x).trans <| h.symm ▸ rfl
theorem _root_.Commute.exp_right [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) :
Commute x (exp 𝕂 y) := by
rw [exp_eq_tsum]
exact Commute.tsum_right x fun n => (h.pow_right n).smul_right _
theorem _root_.Commute.exp_left [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) : Commute (exp 𝕂 x) y :=
(h.symm.exp_right 𝕂).symm
theorem _root_.Commute.exp [T2Space 𝔸] {x y : 𝔸} (h : Commute x y) : Commute (exp 𝕂 x) (exp 𝕂 y) :=
(h.exp_left _).exp_right _
end TopologicalAlgebra
section TopologicalDivisionAlgebra
variable {𝕂 𝔸 : Type*} [Field 𝕂] [DivisionRing 𝔸] [Algebra 𝕂 𝔸] [TopologicalSpace 𝔸]
[IsTopologicalRing 𝔸]
theorem expSeries_apply_eq_div (x : 𝔸) (n : ℕ) : (expSeries 𝕂 𝔸 n fun _ => x) = x ^ n / n ! := by
rw [div_eq_mul_inv, ← (Nat.cast_commute n ! (x ^ n)).inv_left₀.eq, ← smul_eq_mul,
expSeries_apply_eq, inv_natCast_smul_eq 𝕂 𝔸]
theorem expSeries_apply_eq_div' (x : 𝔸) :
(fun n => expSeries 𝕂 𝔸 n fun _ => x) = fun n => x ^ n / n ! :=
funext (expSeries_apply_eq_div x)
theorem expSeries_sum_eq_div (x : 𝔸) : (expSeries 𝕂 𝔸).sum x = ∑' n : ℕ, x ^ n / n ! :=
tsum_congr (expSeries_apply_eq_div x)
theorem exp_eq_tsum_div : exp 𝕂 = fun x : 𝔸 => ∑' n : ℕ, x ^ n / n ! :=
funext expSeries_sum_eq_div
end TopologicalDivisionAlgebra
section Normed
section AnyFieldAnyAlgebra
variable {𝕂 𝔸 𝔹 : Type*} [NontriviallyNormedField 𝕂]
variable [NormedRing 𝔸] [NormedRing 𝔹] [NormedAlgebra 𝕂 𝔸] [NormedAlgebra 𝕂 𝔹]
theorem norm_expSeries_summable_of_mem_ball (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
Summable fun n => ‖expSeries 𝕂 𝔸 n fun _ => x‖ :=
(expSeries 𝕂 𝔸).summable_norm_apply hx
theorem norm_expSeries_summable_of_mem_ball' (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
Summable fun n => ‖(n !⁻¹ : 𝕂) • x ^ n‖ := by
change Summable (norm ∘ _)
rw [← expSeries_apply_eq']
exact norm_expSeries_summable_of_mem_ball x hx
section CompleteAlgebra
variable [CompleteSpace 𝔸]
theorem expSeries_summable_of_mem_ball (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
Summable fun n => expSeries 𝕂 𝔸 n fun _ => x :=
(norm_expSeries_summable_of_mem_ball x hx).of_norm
theorem expSeries_summable_of_mem_ball' (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
Summable fun n => (n !⁻¹ : 𝕂) • x ^ n :=
(norm_expSeries_summable_of_mem_ball' x hx).of_norm
theorem expSeries_hasSum_exp_of_mem_ball (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
HasSum (fun n => expSeries 𝕂 𝔸 n fun _ => x) (exp 𝕂 x) :=
FormalMultilinearSeries.hasSum (expSeries 𝕂 𝔸) hx
theorem expSeries_hasSum_exp_of_mem_ball' (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
HasSum (fun n => (n !⁻¹ : 𝕂) • x ^ n) (exp 𝕂 x) := by
rw [← expSeries_apply_eq']
exact expSeries_hasSum_exp_of_mem_ball x hx
theorem hasFPowerSeriesOnBall_exp_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) :
HasFPowerSeriesOnBall (exp 𝕂) (expSeries 𝕂 𝔸) 0 (expSeries 𝕂 𝔸).radius :=
(expSeries 𝕂 𝔸).hasFPowerSeriesOnBall h
theorem hasFPowerSeriesAt_exp_zero_of_radius_pos (h : 0 < (expSeries 𝕂 𝔸).radius) :
HasFPowerSeriesAt (exp 𝕂) (expSeries 𝕂 𝔸) 0 :=
(hasFPowerSeriesOnBall_exp_of_radius_pos h).hasFPowerSeriesAt
theorem continuousOn_exp : ContinuousOn (exp 𝕂 : 𝔸 → 𝔸) (EMetric.ball 0 (expSeries 𝕂 𝔸).radius) :=
FormalMultilinearSeries.continuousOn
theorem analyticAt_exp_of_mem_ball (x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
AnalyticAt 𝕂 (exp 𝕂) x := by
by_cases h : (expSeries 𝕂 𝔸).radius = 0
· rw [h] at hx; exact (ENNReal.not_lt_zero hx).elim
· have h := pos_iff_ne_zero.mpr h
exact (hasFPowerSeriesOnBall_exp_of_radius_pos h).analyticAt_of_mem hx
/-- In a Banach-algebra `𝔸` over a normed field `𝕂` of characteristic zero, if `x` and `y` are
in the disk of convergence and commute, then
`NormedSpace.exp 𝕂 (x + y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`. -/
theorem exp_add_of_commute_of_mem_ball [CharZero 𝕂] {x y : 𝔸} (hxy : Commute x y)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius)
(hy : y ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y := by
rw [exp_eq_tsum,
tsum_mul_tsum_eq_tsum_sum_antidiagonal_of_summable_norm
(norm_expSeries_summable_of_mem_ball' x hx) (norm_expSeries_summable_of_mem_ball' y hy)]
dsimp only
conv_lhs =>
congr
ext
rw [hxy.add_pow' _, Finset.smul_sum]
refine tsum_congr fun n => Finset.sum_congr rfl fun kl hkl => ?_
rw [← Nat.cast_smul_eq_nsmul 𝕂, smul_smul, smul_mul_smul_comm, ← Finset.mem_antidiagonal.mp hkl,
Nat.cast_add_choose, Finset.mem_antidiagonal.mp hkl]
congr 1
have : (n ! : 𝕂) ≠ 0 := Nat.cast_ne_zero.mpr n.factorial_ne_zero
field_simp [this]
/-- `NormedSpace.exp 𝕂 x` has explicit two-sided inverse `NormedSpace.exp 𝕂 (-x)`. -/
noncomputable def invertibleExpOfMemBall [CharZero 𝕂] {x : 𝔸}
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Invertible (exp 𝕂 x) where
invOf := exp 𝕂 (-x)
invOf_mul_self := by
have hnx : -x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := by
rw [EMetric.mem_ball, ← neg_zero, edist_neg_neg]
exact hx
rw [← exp_add_of_commute_of_mem_ball (Commute.neg_left <| Commute.refl x) hnx hx,
neg_add_cancel, exp_zero]
mul_invOf_self := by
have hnx : -x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius := by
rw [EMetric.mem_ball, ← neg_zero, edist_neg_neg]
exact hx
rw [← exp_add_of_commute_of_mem_ball (Commute.neg_right <| Commute.refl x) hx hnx,
add_neg_cancel, exp_zero]
theorem isUnit_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸}
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : IsUnit (exp 𝕂 x) :=
@isUnit_of_invertible _ _ _ (invertibleExpOfMemBall hx)
theorem invOf_exp_of_mem_ball [CharZero 𝕂] {x : 𝔸}
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) [Invertible (exp 𝕂 x)] :
⅟(exp 𝕂 x) = exp 𝕂 (-x) := by
letI := invertibleExpOfMemBall hx; convert (rfl : ⅟(exp 𝕂 x) = _)
/-- Any continuous ring homomorphism commutes with `NormedSpace.exp`. -/
theorem map_exp_of_mem_ball {F} [FunLike F 𝔸 𝔹] [RingHomClass F 𝔸 𝔹] (f : F) (hf : Continuous f)
(x : 𝔸) (hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
f (exp 𝕂 x) = exp 𝕂 (f x) := by
rw [exp_eq_tsum, exp_eq_tsum]
refine ((expSeries_summable_of_mem_ball' _ hx).hasSum.map f hf).tsum_eq.symm.trans ?_
dsimp only [Function.comp_def]
simp_rw [map_inv_natCast_smul f 𝕂 𝕂, map_pow]
end CompleteAlgebra
theorem algebraMap_exp_comm_of_mem_ball [CompleteSpace 𝕂] (x : 𝕂)
(hx : x ∈ EMetric.ball (0 : 𝕂) (expSeries 𝕂 𝕂).radius) :
algebraMap 𝕂 𝔸 (exp 𝕂 x) = exp 𝕂 (algebraMap 𝕂 𝔸 x) :=
map_exp_of_mem_ball _ (continuous_algebraMap 𝕂 𝔸) _ hx
end AnyFieldAnyAlgebra
section AnyFieldDivisionAlgebra
variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸]
variable (𝕂)
theorem norm_expSeries_div_summable_of_mem_ball (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
Summable fun n => ‖x ^ n / (n ! : 𝔸)‖ := by
change Summable (norm ∘ _)
rw [← expSeries_apply_eq_div' (𝕂 := 𝕂) x]
exact norm_expSeries_summable_of_mem_ball x hx
theorem expSeries_div_summable_of_mem_ball [CompleteSpace 𝔸] (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : Summable fun n => x ^ n / n ! :=
(norm_expSeries_div_summable_of_mem_ball 𝕂 x hx).of_norm
theorem expSeries_div_hasSum_exp_of_mem_ball [CompleteSpace 𝔸] (x : 𝔸)
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) :
HasSum (fun n => x ^ n / n !) (exp 𝕂 x) := by
rw [← expSeries_apply_eq_div' (𝕂 := 𝕂) x]
exact expSeries_hasSum_exp_of_mem_ball x hx
variable {𝕂}
theorem exp_neg_of_mem_ball [CharZero 𝕂] [CompleteSpace 𝔸] {x : 𝔸}
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (-x) = (exp 𝕂 x)⁻¹ :=
letI := invertibleExpOfMemBall hx
invOf_eq_inv (exp 𝕂 x)
end AnyFieldDivisionAlgebra
section AnyFieldCommAlgebra
variable {𝕂 𝔸 : Type*} [NontriviallyNormedField 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸]
[CompleteSpace 𝔸]
/-- In a commutative Banach-algebra `𝔸` over a normed field `𝕂` of characteristic zero,
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`
for all `x`, `y` in the disk of convergence. -/
theorem exp_add_of_mem_ball [CharZero 𝕂] {x y : 𝔸}
(hx : x ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius)
(hy : y ∈ EMetric.ball (0 : 𝔸) (expSeries 𝕂 𝔸).radius) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y :=
exp_add_of_commute_of_mem_ball (Commute.all x y) hx hy
end AnyFieldCommAlgebra
section RCLike
section AnyAlgebra
variable (𝕂 𝔸 𝔹 : Type*) [RCLike 𝕂] [NormedRing 𝔸] [NormedAlgebra 𝕂 𝔸]
variable [NormedRing 𝔹] [NormedAlgebra 𝕂 𝔹]
/-- In a normed algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`, the series defining the exponential map
has an infinite radius of convergence. -/
theorem expSeries_radius_eq_top : (expSeries 𝕂 𝔸).radius = ∞ := by
have {n : ℕ} : (Nat.factorial n : 𝕂) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero n)
apply expSeries_eq_ofScalars 𝕂 𝔸 ▸
ofScalars_radius_eq_top_of_tendsto 𝔸 _ (Eventually.of_forall fun n => ?_)
· simp_rw [← norm_div, Nat.factorial_succ, Nat.cast_mul, mul_inv_rev, mul_div_right_comm,
inv_div_inv, norm_mul, div_self this, norm_one, one_mul]
apply norm_zero (E := 𝕂) ▸ Filter.Tendsto.norm
apply (Filter.tendsto_add_atTop_iff_nat (f := fun n => (n : 𝕂)⁻¹) 1).mpr
exact RCLike.tendsto_inverse_atTop_nhds_zero_nat 𝕂
· simp [this]
theorem expSeries_radius_pos : 0 < (expSeries 𝕂 𝔸).radius := by
rw [expSeries_radius_eq_top]
exact WithTop.top_pos
variable {𝕂 𝔸 𝔹}
theorem norm_expSeries_summable (x : 𝔸) : Summable fun n => ‖expSeries 𝕂 𝔸 n fun _ => x‖ :=
norm_expSeries_summable_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
theorem norm_expSeries_summable' (x : 𝔸) : Summable fun n => ‖(n !⁻¹ : 𝕂) • x ^ n‖ :=
norm_expSeries_summable_of_mem_ball' x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
section CompleteAlgebra
variable [CompleteSpace 𝔸]
theorem expSeries_summable (x : 𝔸) : Summable fun n => expSeries 𝕂 𝔸 n fun _ => x :=
(norm_expSeries_summable x).of_norm
theorem expSeries_summable' (x : 𝔸) : Summable fun n => (n !⁻¹ : 𝕂) • x ^ n :=
(norm_expSeries_summable' x).of_norm
theorem expSeries_hasSum_exp (x : 𝔸) : HasSum (fun n => expSeries 𝕂 𝔸 n fun _ => x) (exp 𝕂 x) :=
expSeries_hasSum_exp_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
theorem exp_series_hasSum_exp' (x : 𝔸) : HasSum (fun n => (n !⁻¹ : 𝕂) • x ^ n) (exp 𝕂 x) :=
expSeries_hasSum_exp_of_mem_ball' x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
theorem exp_hasFPowerSeriesOnBall : HasFPowerSeriesOnBall (exp 𝕂) (expSeries 𝕂 𝔸) 0 ∞ :=
expSeries_radius_eq_top 𝕂 𝔸 ▸ hasFPowerSeriesOnBall_exp_of_radius_pos (expSeries_radius_pos _ _)
theorem exp_hasFPowerSeriesAt_zero : HasFPowerSeriesAt (exp 𝕂) (expSeries 𝕂 𝔸) 0 :=
exp_hasFPowerSeriesOnBall.hasFPowerSeriesAt
@[continuity, fun_prop]
theorem exp_continuous : Continuous (exp 𝕂 : 𝔸 → 𝔸) := by
rw [← continuousOn_univ, ← Metric.eball_top_eq_univ (0 : 𝔸), ←
expSeries_radius_eq_top 𝕂 𝔸]
exact continuousOn_exp
open Topology in
lemma _root_.Filter.Tendsto.exp {α : Type*} {l : Filter α} {f : α → 𝔸} {a : 𝔸}
(hf : Tendsto f l (𝓝 a)) :
Tendsto (fun x => exp 𝕂 (f x)) l (𝓝 (exp 𝕂 a)) :=
(exp_continuous.tendsto _).comp hf
theorem exp_analytic (x : 𝔸) : AnalyticAt 𝕂 (exp 𝕂) x :=
analyticAt_exp_of_mem_ball x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
/-- In a Banach-algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`, if `x` and `y` commute, then
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`. -/
theorem exp_add_of_commute {x y : 𝔸} (hxy : Commute x y) : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y :=
exp_add_of_commute_of_mem_ball hxy ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
section
variable (𝕂)
/-- `NormedSpace.exp 𝕂 x` has explicit two-sided inverse `NormedSpace.exp 𝕂 (-x)`. -/
noncomputable def invertibleExp (x : 𝔸) : Invertible (exp 𝕂 x) :=
invertibleExpOfMemBall <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _
theorem isUnit_exp (x : 𝔸) : IsUnit (exp 𝕂 x) :=
isUnit_exp_of_mem_ball <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _
theorem invOf_exp (x : 𝔸) [Invertible (exp 𝕂 x)] : ⅟(exp 𝕂 x) = exp 𝕂 (-x) :=
invOf_exp_of_mem_ball <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _
theorem _root_.Ring.inverse_exp (x : 𝔸) : Ring.inverse (exp 𝕂 x) = exp 𝕂 (-x) :=
letI := invertibleExp 𝕂 x
Ring.inverse_invertible _
theorem exp_mem_unitary_of_mem_skewAdjoint [StarRing 𝔸] [ContinuousStar 𝔸] {x : 𝔸}
(h : x ∈ skewAdjoint 𝔸) : exp 𝕂 x ∈ unitary 𝔸 := by
rw [unitary.mem_iff, star_exp, skewAdjoint.mem_iff.mp h, ←
exp_add_of_commute (Commute.refl x).neg_left, ← exp_add_of_commute (Commute.refl x).neg_right,
neg_add_cancel, add_neg_cancel, exp_zero, and_self_iff]
end
open scoped Function in -- required for scoped `on` notation
/-- In a Banach-algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`, if a family of elements `f i` mutually
commute then `NormedSpace.exp 𝕂 (∑ i, f i) = ∏ i, NormedSpace.exp 𝕂 (f i)`. -/
theorem exp_sum_of_commute {ι} (s : Finset ι) (f : ι → 𝔸)
(h : (s : Set ι).Pairwise (Commute on f)) :
exp 𝕂 (∑ i ∈ s, f i) =
s.noncommProd (fun i => exp 𝕂 (f i)) fun _ hi _ hj _ => (h.of_refl hi hj).exp 𝕂 := by
classical
induction' s using Finset.induction_on with a s ha ih
· simp
rw [Finset.noncommProd_insert_of_notMem _ _ _ _ ha, Finset.sum_insert ha, exp_add_of_commute,
ih (h.mono <| Finset.subset_insert _ _)]
refine Commute.sum_right _ _ _ fun i hi => ?_
exact h.of_refl (Finset.mem_insert_self _ _) (Finset.mem_insert_of_mem hi)
theorem exp_nsmul (n : ℕ) (x : 𝔸) : exp 𝕂 (n • x) = exp 𝕂 x ^ n := by
induction n with
| zero => rw [zero_smul, pow_zero, exp_zero]
| succ n ih => rw [succ_nsmul, pow_succ, exp_add_of_commute ((Commute.refl x).smul_left n), ih]
variable (𝕂)
/-- Any continuous ring homomorphism commutes with `NormedSpace.exp`. -/
theorem map_exp {F} [FunLike F 𝔸 𝔹] [RingHomClass F 𝔸 𝔹] (f : F) (hf : Continuous f) (x : 𝔸) :
f (exp 𝕂 x) = exp 𝕂 (f x) :=
map_exp_of_mem_ball f hf x <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _
theorem exp_smul {G} [Monoid G] [MulSemiringAction G 𝔸] [ContinuousConstSMul G 𝔸] (g : G) (x : 𝔸) :
exp 𝕂 (g • x) = g • exp 𝕂 x :=
(map_exp 𝕂 (MulSemiringAction.toRingHom G 𝔸 g) (continuous_const_smul g) x).symm
theorem exp_units_conj (y : 𝔸ˣ) (x : 𝔸) : exp 𝕂 (y * x * ↑y⁻¹ : 𝔸) = y * exp 𝕂 x * ↑y⁻¹ :=
exp_smul _ (ConjAct.toConjAct y) x
theorem exp_units_conj' (y : 𝔸ˣ) (x : 𝔸) : exp 𝕂 (↑y⁻¹ * x * y) = ↑y⁻¹ * exp 𝕂 x * y :=
exp_units_conj _ _ _
@[simp]
theorem _root_.Prod.fst_exp [CompleteSpace 𝔹] (x : 𝔸 × 𝔹) : (exp 𝕂 x).fst = exp 𝕂 x.fst :=
map_exp _ (RingHom.fst 𝔸 𝔹) continuous_fst x
@[simp]
theorem _root_.Prod.snd_exp [CompleteSpace 𝔹] (x : 𝔸 × 𝔹) : (exp 𝕂 x).snd = exp 𝕂 x.snd :=
map_exp _ (RingHom.snd 𝔸 𝔹) continuous_snd x
@[simp]
theorem _root_.Pi.coe_exp {ι : Type*} {𝔸 : ι → Type*} [Finite ι] [∀ i, NormedRing (𝔸 i)]
[∀ i, NormedAlgebra 𝕂 (𝔸 i)] [∀ i, CompleteSpace (𝔸 i)] (x : ∀ i, 𝔸 i) (i : ι) :
exp 𝕂 x i = exp 𝕂 (x i) :=
let ⟨_⟩ := nonempty_fintype ι
map_exp _ (Pi.evalRingHom 𝔸 i) (continuous_apply _) x
theorem _root_.Pi.exp_def {ι : Type*} {𝔸 : ι → Type*} [Finite ι] [∀ i, NormedRing (𝔸 i)]
[∀ i, NormedAlgebra 𝕂 (𝔸 i)] [∀ i, CompleteSpace (𝔸 i)] (x : ∀ i, 𝔸 i) :
exp 𝕂 x = fun i => exp 𝕂 (x i) :=
funext <| Pi.coe_exp 𝕂 x
theorem _root_.Function.update_exp {ι : Type*} {𝔸 : ι → Type*} [Finite ι] [DecidableEq ι]
[∀ i, NormedRing (𝔸 i)] [∀ i, NormedAlgebra 𝕂 (𝔸 i)] [∀ i, CompleteSpace (𝔸 i)] (x : ∀ i, 𝔸 i)
(j : ι) (xj : 𝔸 j) :
Function.update (exp 𝕂 x) j (exp 𝕂 xj) = exp 𝕂 (Function.update x j xj) := by
ext i
simp_rw [Pi.exp_def]
exact (Function.apply_update (fun i => exp 𝕂) x j xj i).symm
end CompleteAlgebra
theorem algebraMap_exp_comm (x : 𝕂) : algebraMap 𝕂 𝔸 (exp 𝕂 x) = exp 𝕂 (algebraMap 𝕂 𝔸 x) :=
algebraMap_exp_comm_of_mem_ball x <| (expSeries_radius_eq_top 𝕂 𝕂).symm ▸ edist_lt_top _ _
end AnyAlgebra
section DivisionAlgebra
variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedDivisionRing 𝔸] [NormedAlgebra 𝕂 𝔸]
variable (𝕂)
include 𝕂
theorem norm_expSeries_div_summable (x : 𝔸) : Summable fun n => ‖(x ^ n / n ! : 𝔸)‖ :=
norm_expSeries_div_summable_of_mem_ball 𝕂 x
((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
variable [CompleteSpace 𝔸]
theorem expSeries_div_summable (x : 𝔸) : Summable fun n => x ^ n / n ! :=
(norm_expSeries_div_summable 𝕂 x).of_norm
theorem expSeries_div_hasSum_exp (x : 𝔸) : HasSum (fun n => x ^ n / n !) (exp 𝕂 x) :=
expSeries_div_hasSum_exp_of_mem_ball 𝕂 x ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
variable {𝕂}
theorem exp_neg (x : 𝔸) : exp 𝕂 (-x) = (exp 𝕂 x)⁻¹ :=
exp_neg_of_mem_ball <| (expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _
theorem exp_zsmul (z : ℤ) (x : 𝔸) : exp 𝕂 (z • x) = exp 𝕂 x ^ z := by
obtain ⟨n, rfl | rfl⟩ := z.eq_nat_or_neg
· rw [zpow_natCast, natCast_zsmul, exp_nsmul]
· rw [zpow_neg, zpow_natCast, neg_smul, exp_neg, natCast_zsmul, exp_nsmul]
theorem exp_conj (y : 𝔸) (x : 𝔸) (hy : y ≠ 0) : exp 𝕂 (y * x * y⁻¹) = y * exp 𝕂 x * y⁻¹ :=
exp_units_conj _ (Units.mk0 y hy) x
theorem exp_conj' (y : 𝔸) (x : 𝔸) (hy : y ≠ 0) : exp 𝕂 (y⁻¹ * x * y) = y⁻¹ * exp 𝕂 x * y :=
exp_units_conj' _ (Units.mk0 y hy) x
end DivisionAlgebra
section CommAlgebra
variable {𝕂 𝔸 : Type*} [RCLike 𝕂] [NormedCommRing 𝔸] [NormedAlgebra 𝕂 𝔸] [CompleteSpace 𝔸]
/-- In a commutative Banach-algebra `𝔸` over `𝕂 = ℝ` or `𝕂 = ℂ`,
`NormedSpace.exp 𝕂 (x+y) = (NormedSpace.exp 𝕂 x) * (NormedSpace.exp 𝕂 y)`. -/
theorem exp_add {x y : 𝔸} : exp 𝕂 (x + y) = exp 𝕂 x * exp 𝕂 y :=
exp_add_of_mem_ball ((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
((expSeries_radius_eq_top 𝕂 𝔸).symm ▸ edist_lt_top _ _)
/-- A version of `NormedSpace.exp_sum_of_commute` for a commutative Banach-algebra. -/
theorem exp_sum {ι} (s : Finset ι) (f : ι → 𝔸) : exp 𝕂 (∑ i ∈ s, f i) = ∏ i ∈ s, exp 𝕂 (f i) := by
rw [exp_sum_of_commute, Finset.noncommProd_eq_prod]
exact fun i _hi j _hj _ => Commute.all _ _
end CommAlgebra
end RCLike
end Normed
section ScalarTower
variable (𝕂 𝕂' 𝔸 : Type*) [Field 𝕂] [Field 𝕂'] [Ring 𝔸] [Algebra 𝕂 𝔸] [Algebra 𝕂' 𝔸]
[TopologicalSpace 𝔸] [IsTopologicalRing 𝔸]
/-- If a normed ring `𝔸` is a normed algebra over two fields, then they define the same
`expSeries` on `𝔸`. -/
theorem expSeries_eq_expSeries (n : ℕ) (x : 𝔸) :
(expSeries 𝕂 𝔸 n fun _ => x) = expSeries 𝕂' 𝔸 n fun _ => x := by
rw [expSeries_apply_eq, expSeries_apply_eq, inv_natCast_smul_eq 𝕂 𝕂']
/-- If a normed ring `𝔸` is a normed algebra over two fields, then they define the same
exponential function on `𝔸`. -/
theorem exp_eq_exp : (exp 𝕂 : 𝔸 → 𝔸) = exp 𝕂' := by
ext x
rw [exp, exp]
refine tsum_congr fun n => ?_
rw [expSeries_eq_expSeries 𝕂 𝕂' 𝔸 n x]
theorem exp_ℝ_ℂ_eq_exp_ℂ_ℂ : (exp ℝ : ℂ → ℂ) = exp ℂ :=
exp_eq_exp ℝ ℂ ℂ
/-- A version of `Complex.ofReal_exp` for `NormedSpace.exp` instead of `Complex.exp` -/
@[simp, norm_cast]
theorem of_real_exp_ℝ_ℝ (r : ℝ) : ↑(exp ℝ r) = exp ℂ (r : ℂ) :=
(map_exp ℝ (algebraMap ℝ ℂ) (continuous_algebraMap _ _) r).trans (congr_fun exp_ℝ_ℂ_eq_exp_ℂ_ℂ _)
end ScalarTower
end NormedSpace
|
PrimesCongruentOne.lean
|
/-
Copyright (c) 2020 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.Polynomial.Cyclotomic.Eval
/-!
# Primes congruent to one
We prove that, for any positive `k : ℕ`, there are infinitely many primes `p` such that
`p ≡ 1 [MOD k]`.
-/
namespace Nat
open Polynomial Nat Filter
open scoped Nat
/-- For any positive `k : ℕ` there exists an arbitrarily large prime `p` such that
`p ≡ 1 [MOD k]`. -/
theorem exists_prime_gt_modEq_one {k : ℕ} (n : ℕ) (hk0 : k ≠ 0) :
∃ p : ℕ, Nat.Prime p ∧ n < p ∧ p ≡ 1 [MOD k] := by
rcases (one_le_iff_ne_zero.2 hk0).eq_or_lt with (rfl | hk1)
· rcases exists_infinite_primes (n + 1) with ⟨p, hnp, hp⟩
exact ⟨p, hp, hnp, modEq_one⟩
let b := k * (n !)
have hgt : 1 < (eval (↑b) (cyclotomic k ℤ)).natAbs := by
rcases le_iff_exists_add'.1 hk1.le with ⟨k, rfl⟩
have hb : 2 ≤ b := le_mul_of_le_of_one_le hk1 n.factorial_pos
calc
1 ≤ b - 1 := le_tsub_of_add_le_left hb
_ < (eval (b : ℤ) (cyclotomic (k + 1) ℤ)).natAbs :=
sub_one_lt_natAbs_cyclotomic_eval hk1 (succ_le_iff.1 hb).ne'
let p := minFac (eval (↑b) (cyclotomic k ℤ)).natAbs
haveI hprime : Fact p.Prime := ⟨minFac_prime (ne_of_lt hgt).symm⟩
have hroot : IsRoot (cyclotomic k (ZMod p)) (castRingHom (ZMod p) b) := by
have : ((b : ℤ) : ZMod p) = ↑(Int.castRingHom (ZMod p) b) := by simp
rw [IsRoot.def, ← map_cyclotomic_int k (ZMod p), eval_map, coe_castRingHom,
← Int.cast_natCast, this, eval₂_hom, Int.coe_castRingHom, ZMod.intCast_zmod_eq_zero_iff_dvd]
apply Int.dvd_natAbs.1
exact mod_cast minFac_dvd (eval (↑b) (cyclotomic k ℤ)).natAbs
have hpb : ¬p ∣ b :=
hprime.1.coprime_iff_not_dvd.1 (coprime_of_root_cyclotomic hk0.bot_lt hroot).symm
refine ⟨p, hprime.1, not_le.1 fun habs => ?_, ?_⟩
· exact hpb (dvd_mul_of_dvd_right (dvd_factorial (minFac_pos _) habs) _)
· have hdiv : orderOf (b : ZMod p) ∣ p - 1 :=
ZMod.orderOf_dvd_card_sub_one (mt (CharP.cast_eq_zero_iff _ _ _).1 hpb)
haveI : NeZero (k : ZMod p) :=
NeZero.of_not_dvd (ZMod p) fun hpk => hpb (dvd_mul_of_dvd_left hpk _)
have : k = orderOf (b : ZMod p) := (isRoot_cyclotomic_iff.mp hroot).eq_orderOf
rw [← this] at hdiv
exact ((modEq_iff_dvd' hprime.1.pos).2 hdiv).symm
theorem frequently_atTop_modEq_one {k : ℕ} (hk0 : k ≠ 0) :
∃ᶠ p in atTop, Nat.Prime p ∧ p ≡ 1 [MOD k] := by
refine frequently_atTop.2 fun n => ?_
obtain ⟨p, hp⟩ := exists_prime_gt_modEq_one n hk0
exact ⟨p, ⟨hp.2.1.le, hp.1, hp.2.2⟩⟩
/-- For any positive `k : ℕ` there are infinitely many primes `p` such that `p ≡ 1 [MOD k]`. -/
theorem infinite_setOf_prime_modEq_one {k : ℕ} (hk0 : k ≠ 0) :
Set.Infinite {p : ℕ | Nat.Prime p ∧ p ≡ 1 [MOD k]} :=
frequently_atTop_iff_infinite.1 (frequently_atTop_modEq_one hk0)
end Nat
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.