filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
Defs.lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes HΓΆlzl, Mario Carneiro, Anne Baanen,
FrΓ©dΓ©ric Dupuis, Heather Macbeth
-/
import Mathlib.Algebra.Module.LinearMap.Defs
/-!
# (Semi)linear equivalences
In this file we define
* `LinearEquiv Ο M Mβ`, `M βββ[Ο] Mβ`: an invertible semilinear map. Here, `Ο` is a `RingHom`
from `R` to `Rβ` and an `e : M βββ[Ο] Mβ` satisfies `e (c β’ x) = (Ο c) β’ (e x)`. The plain
linear version, with `Ο` being `RingHom.id R`, is denoted by `M ββ[R] Mβ`, and the
star-linear version (with `Ο` being `starRingEnd`) is denoted by `M βββ[R] Mβ`.
## Implementation notes
To ensure that composition works smoothly for semilinear equivalences, we use the typeclasses
`RingHomCompTriple`, `RingHomInvPair` and `RingHomSurjective` from
`Algebra/Ring/CompTypeclasses`.
The group structure on automorphisms, `LinearEquiv.automorphismGroup`, is provided elsewhere.
## TODO
* Parts of this file have not yet been generalized to semilinear maps
## Tags
linear equiv, linear equivalences, linear isomorphism, linear isomorphic
-/
assert_not_exists Field Pi.module
open Function
variable {R Rβ Rβ Rβ Rβ S M Mβ Mβ Mβ Mβ Nβ Nβ : Type*}
section
/-- A linear equivalence is an invertible linear map. -/
structure LinearEquiv {R : Type*} {S : Type*} [Semiring R] [Semiring S] (Ο : R β+* S)
{Ο' : S β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο] (M : Type*) (Mβ : Type*)
[AddCommMonoid M] [AddCommMonoid Mβ] [Module R M] [Module S Mβ] extends LinearMap Ο M Mβ, M β+ Mβ
attribute [coe] LinearEquiv.toLinearMap
/-- The linear map underlying a linear equivalence. -/
add_decl_doc LinearEquiv.toLinearMap
/-- The additive equivalence of types underlying a linear equivalence. -/
add_decl_doc LinearEquiv.toAddEquiv
/-- The backwards directed function underlying a linear equivalence. -/
add_decl_doc LinearEquiv.invFun
/-- `LinearEquiv.invFun` is a right inverse to the linear equivalence's underlying function. -/
add_decl_doc LinearEquiv.right_inv
/-- `LinearEquiv.invFun` is a left inverse to the linear equivalence's underlying function. -/
add_decl_doc LinearEquiv.left_inv
/-- `M βββ[Ο] Mβ` denotes the type of linear equivalences between `M` and `Mβ` over a
ring homomorphism `Ο`. -/
notation:50 M " βββ[" Ο "] " Mβ => LinearEquiv Ο M Mβ
/-- `M ββ[R] Mβ` denotes the type of linear equivalences between `M` and `Mβ` over
a plain linear map `M ββ Mβ`. -/
notation:50 M " ββ[" R "] " Mβ => LinearEquiv (RingHom.id R) M Mβ
/-- `SemilinearEquivClass F Ο M Mβ` asserts `F` is a type of bundled `Ο`-semilinear equivs
`M β Mβ`.
See also `LinearEquivClass F R M Mβ` for the case where `Ο` is the identity map on `R`.
A map `f` between an `R`-module and an `S`-module over a ring homomorphism `Ο : R β+* S`
is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and
`f (c β’ x) = (Ο c) β’ f x`. -/
class SemilinearEquivClass (F : Type*) {R S : outParam Type*} [Semiring R] [Semiring S]
(Ο : outParam <| R β+* S) {Ο' : outParam <| S β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
(M Mβ : outParam Type*) [AddCommMonoid M] [AddCommMonoid Mβ] [Module R M] [Module S Mβ]
[EquivLike F M Mβ] : Prop
extends AddEquivClass F M Mβ where
/-- Applying a semilinear equivalence `f` over `Ο` to `r β’ x` equals `Ο r β’ f x`. -/
map_smulββ : β (f : F) (r : R) (x : M), f (r β’ x) = Ο r β’ f x
-- `R, S, Ο, Ο'` become metavars, but it's OK since they are outparams.
/-- `LinearEquivClass F R M Mβ` asserts `F` is a type of bundled `R`-linear equivs `M β Mβ`.
This is an abbreviation for `SemilinearEquivClass F (RingHom.id R) M Mβ`.
-/
abbrev LinearEquivClass (F : Type*) (R M Mβ : outParam Type*) [Semiring R] [AddCommMonoid M]
[AddCommMonoid Mβ] [Module R M] [Module R Mβ] [EquivLike F M Mβ] :=
SemilinearEquivClass F (RingHom.id R) M Mβ
end
namespace SemilinearEquivClass
variable (F : Type*) [Semiring R] [Semiring S]
variable [AddCommMonoid M] [AddCommMonoid Mβ] [AddCommMonoid Mβ]
variable [Module R M] [Module S Mβ] {Ο : R β+* S} {Ο' : S β+* R}
instance (priority := 100) [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
[EquivLike F M Mβ] [s : SemilinearEquivClass F Ο M Mβ] : SemilinearMapClass F Ο M Mβ :=
{ s with }
variable {F}
/-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/
@[coe]
def semilinearEquiv [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
[EquivLike F M Mβ] [SemilinearEquivClass F Ο M Mβ] (f : F) : M βββ[Ο] Mβ :=
{ (f : M β+ Mβ), (f : M βββ[Ο] Mβ) with }
/-- Reinterpret an element of a type of semilinear equivalences as a semilinear equivalence. -/
instance instCoeToSemilinearEquiv [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
[EquivLike F M Mβ] [SemilinearEquivClass F Ο M Mβ] : CoeHead F (M βββ[Ο] Mβ) where
coe f := semilinearEquiv f
end SemilinearEquivClass
namespace LinearEquiv
section AddCommMonoid
variable [Semiring R] [Semiring S]
section
variable [AddCommMonoid M] [AddCommMonoid Mβ] [AddCommMonoid Mβ]
variable [Module R M] [Module S Mβ] {Ο : R β+* S} {Ο' : S β+* R}
variable [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
instance : Coe (M βββ[Ο] Mβ) (M βββ[Ο] Mβ) :=
β¨toLinearMapβ©
-- This exists for compatibility, previously `ββ[R]` extended `β` instead of `β+`.
/-- The equivalence of types underlying a linear equivalence. -/
def toEquiv : (M βββ[Ο] Mβ) β M β Mβ := fun f β¦ f.toAddEquiv.toEquiv
theorem toEquiv_injective : Function.Injective (toEquiv : (M βββ[Ο] Mβ) β M β Mβ) :=
fun β¨β¨β¨_, _β©, _β©, _, _, _β© β¨β¨β¨_, _β©, _β©, _, _, _β© h β¦
(LinearEquiv.mk.injEq _ _ _ _ _ _ _ _).mpr
β¨LinearMap.ext (congr_fun (Equiv.mk.inj h).1), (Equiv.mk.inj h).2β©
@[simp]
theorem toEquiv_inj {eβ eβ : M βββ[Ο] Mβ} : eβ.toEquiv = eβ.toEquiv β eβ = eβ :=
toEquiv_injective.eq_iff
theorem toLinearMap_injective : Injective (toLinearMap : (M βββ[Ο] Mβ) β M βββ[Ο] Mβ) :=
fun _ _ H β¦ toEquiv_injective <| Equiv.ext <| LinearMap.congr_fun H
@[simp, norm_cast]
theorem toLinearMap_inj {eβ eβ : M βββ[Ο] Mβ} : (βeβ : M βββ[Ο] Mβ) = eβ β eβ = eβ :=
toLinearMap_injective.eq_iff
instance : EquivLike (M βββ[Ο] Mβ) M Mβ where
coe e := e.toFun
inv := LinearEquiv.invFun
coe_injective' _ _ h _ := toLinearMap_injective (DFunLike.coe_injective h)
left_inv := LinearEquiv.left_inv
right_inv := LinearEquiv.right_inv
instance : SemilinearEquivClass (M βββ[Ο] Mβ) Ο M Mβ where
map_add := (Β·.map_add')
map_smulββ := (Β·.map_smul')
theorem toLinearMap_eq_coe {e : M βββ[Ο] Mβ} : e.toLinearMap = SemilinearMapClass.semilinearMap e :=
rfl
@[simp]
theorem coe_mk {f invFun left_inv right_inv} :
((β¨f, invFun, left_inv, right_invβ© : M βββ[Ο] Mβ) : M β Mβ) = f := rfl
theorem coe_injective : @Injective (M βββ[Ο] Mβ) (M β Mβ) DFunLike.coe :=
DFunLike.coe_injective
@[simp]
lemma _root_.SemilinearEquivClass.semilinearEquiv_apply {F : Type*} [EquivLike F M Mβ]
[SemilinearEquivClass F Ο M Mβ] (f : F) (x : M) :
SemilinearEquivClass.semilinearEquiv (Mβ := Mβ) f x = f x := rfl
end
section
variable [Semiring Rβ] [Semiring Rβ] [Semiring Rβ] [Semiring Rβ]
variable [AddCommMonoid M] [AddCommMonoid Mβ] [AddCommMonoid Mβ] [AddCommMonoid Mβ]
variable [AddCommMonoid Mβ]
variable [AddCommMonoid Nβ] [AddCommMonoid Nβ]
variable {module_M : Module R M} {module_S_Mβ : Module S Mβ} {Ο : R β+* S} {Ο' : S β+* R}
variable {reβ : RingHomInvPair Ο Ο'} {reβ : RingHomInvPair Ο' Ο}
variable (e e' : M βββ[Ο] Mβ)
@[simp, norm_cast]
theorem coe_coe : β(e : M βββ[Ο] Mβ) = e :=
rfl
@[simp]
theorem coe_toEquiv : β(e.toEquiv) = e :=
rfl
@[simp]
theorem coe_toLinearMap : βe.toLinearMap = e :=
rfl
theorem toFun_eq_coe : e.toFun = e := by dsimp
section
variable {e e'}
@[ext]
theorem ext (h : β x, e x = e' x) : e = e' :=
DFunLike.ext _ _ h
protected theorem congr_arg {x x'} : x = x' β e x = e x' :=
DFunLike.congr_arg e
protected theorem congr_fun (h : e = e') (x : M) : e x = e' x :=
DFunLike.congr_fun h x
end
section
variable (M R)
/-- The identity map is a linear equivalence. -/
@[refl]
def refl [Module R M] : M ββ[R] M :=
{ LinearMap.id, Equiv.refl M with }
end
@[simp]
theorem refl_apply [Module R M] (x : M) : refl R M x = x :=
rfl
/-- Linear equivalences are symmetric. -/
@[symm]
def symm (e : M βββ[Ο] Mβ) : Mβ βββ[Ο'] M :=
{ e.toLinearMap.inverse e.invFun e.left_inv e.right_inv,
e.toEquiv.symm with
toFun := e.toLinearMap.inverse e.invFun e.left_inv e.right_inv
invFun := e.toEquiv.symm.invFun
map_smul' r x := by rw [map_smulββ] }
/-- See Note [custom simps projection] -/
def Simps.apply {R : Type*} {S : Type*} [Semiring R] [Semiring S]
{Ο : R β+* S} {Ο' : S β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
{M : Type*} {Mβ : Type*} [AddCommMonoid M] [AddCommMonoid Mβ] [Module R M] [Module S Mβ]
(e : M βββ[Ο] Mβ) : M β Mβ :=
e
/-- See Note [custom simps projection] -/
def Simps.symm_apply {R S : Type*} [Semiring R] [Semiring S]
{Ο : R β+* S} {Ο' : S β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
{M Mβ : Type*} [AddCommMonoid M] [AddCommMonoid Mβ] [Module R M] [Module S Mβ]
(e : M βββ[Ο] Mβ) : Mβ β M :=
e.symm
initialize_simps_projections LinearEquiv (toFun β apply, invFun β symm_apply)
@[simp]
theorem invFun_eq_symm : e.invFun = e.symm :=
rfl
theorem coe_toEquiv_symm : e.toEquiv.symm = e.symm := rfl
@[simp]
theorem toEquiv_symm : e.symm.toEquiv = e.toEquiv.symm :=
rfl
@[simp]
theorem coe_symm_toEquiv : βe.toEquiv.symm = e.symm := rfl
variable {module_Mβ : Module Rβ Mβ} {module_Mβ : Module Rβ Mβ} {module_Mβ : Module Rβ Mβ}
variable {module_Mβ : Module Rβ Mβ} {module_Nβ : Module Rβ Nβ} {module_Nβ : Module Rβ Nβ}
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ}
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ} [RingHomInvPair Οββ Οββ] [RingHomInvPair Οββ Οββ]
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ} [RingHomInvPair Οββ Οββ] [RingHomInvPair Οββ Οββ]
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ}
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ} [RingHomInvPair Οββ Οββ] [RingHomInvPair Οββ Οββ]
variable {Οββ : Rβ β+* Rβ} {Οββ : Rβ β+* Rβ} [RingHomInvPair Οββ Οββ] [RingHomInvPair Οββ Οββ]
variable {reββ : RingHomInvPair Οββ Οββ} {reββ : RingHomInvPair Οββ Οββ}
variable {reββ : RingHomInvPair Οββ Οββ} {reββ : RingHomInvPair Οββ Οββ}
variable [RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
variable [RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
variable [RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
variable [RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
variable (eββ : Mβ βββ[Οββ] Mβ) (eββ : Mβ βββ[Οββ] Mβ)
/-- Linear equivalences are transitive. -/
-- Note: the `RingHomCompTriple Οββ Οββ Οββ` is unused, but is convenient to carry around
-- implicitly for lemmas like `LinearEquiv.self_trans_symm`.
@[trans, nolint unusedArguments]
def trans
[RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
{reββ : RingHomInvPair Οββ Οββ} {reββ : RingHomInvPair Οββ Οββ}
[RingHomInvPair Οββ Οββ] {reββ : RingHomInvPair Οββ Οββ}
{reββ : RingHomInvPair Οββ Οββ} [RingHomInvPair Οββ Οββ]
(eββ : Mβ βββ[Οββ] Mβ) (eββ : Mβ βββ[Οββ] Mβ) : Mβ βββ[Οββ] Mβ :=
{ eββ.toLinearMap.comp eββ.toLinearMap, eββ.toEquiv.trans eββ.toEquiv with }
/-- `eβ βͺβ«β eβ` denotes the composition of the linear equivalences `eβ` and `eβ`. -/
notation3:80 (name := transNotation) eβ:80 " βͺβ«β " eβ:81 =>
@LinearEquiv.trans _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (RingHom.id _) (RingHom.id _) (RingHom.id _)
(RingHom.id _) (RingHom.id _) (RingHom.id _) RingHomCompTriple.ids RingHomCompTriple.ids
RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids RingHomInvPair.ids
RingHomInvPair.ids eβ eβ
/-- `LinearEquiv.symm` defines an equivalence between `Ξ± βββ[Ο] Ξ²` and `Ξ² βββ[Ο] Ξ±`. -/
@[simps!]
def symmEquiv : (M βββ[Ο] Mβ) β (Mβ βββ[Ο'] M) where
toFun := .symm
invFun := .symm
variable {eββ} {eββ}
theorem coe_toAddEquiv : e.toAddEquiv = e :=
rfl
@[simp]
lemma coe_addEquiv_apply (x : M) : (e : M β+ Mβ) x = e x :=
rfl
/-- The two paths coercion can take to an `AddMonoidHom` are equivalent -/
theorem toAddMonoidHom_commutes : e.toLinearMap.toAddMonoidHom = e.toAddEquiv.toAddMonoidHom :=
rfl
lemma coe_toAddEquiv_symm : (eββ.symm : Mβ β+ Mβ) = (eββ : Mβ β+ Mβ).symm :=
rfl
@[simp]
theorem trans_apply (c : Mβ) : (eββ.trans eββ : Mβ βββ[Οββ] Mβ) c = eββ (eββ c) :=
rfl
theorem coe_trans :
(eββ.trans eββ : Mβ βββ[Οββ] Mβ) = (eββ : Mβ βββ[Οββ] Mβ).comp (eββ : Mβ βββ[Οββ] Mβ) :=
rfl
@[simp]
theorem apply_symm_apply (c : Mβ) : e (e.symm c) = c :=
e.right_inv c
@[simp]
theorem symm_apply_apply (b : M) : e.symm (e b) = b :=
e.left_inv b
theorem comp_symm : e.toLinearMap βββ e.symm.toLinearMap = LinearMap.id :=
LinearMap.ext e.apply_symm_apply
theorem symm_comp : e.symm.toLinearMap βββ e.toLinearMap = LinearMap.id :=
LinearMap.ext e.symm_apply_apply
@[simp]
theorem trans_symm : (eββ.trans eββ : Mβ βββ[Οββ] Mβ).symm = eββ.symm.trans eββ.symm :=
rfl
theorem symm_trans_apply (c : Mβ) :
(eββ.trans eββ : Mβ βββ[Οββ] Mβ).symm c = eββ.symm (eββ.symm c) :=
rfl
@[simp]
theorem trans_refl : e.trans (refl S Mβ) = e :=
toEquiv_injective e.toEquiv.trans_refl
@[simp]
theorem refl_trans : (refl R M).trans e = e :=
toEquiv_injective e.toEquiv.refl_trans
theorem symm_apply_eq {x y} : e.symm x = y β x = e y :=
e.toEquiv.symm_apply_eq
theorem eq_symm_apply {x y} : y = e.symm x β e y = x :=
e.toEquiv.eq_symm_apply
theorem eq_comp_symm {Ξ± : Type*} (f : Mβ β Ξ±) (g : Mβ β Ξ±) : f = g β eββ.symm β f β eββ = g :=
eββ.toEquiv.eq_comp_symm f g
theorem comp_symm_eq {Ξ± : Type*} (f : Mβ β Ξ±) (g : Mβ β Ξ±) : g β eββ.symm = f β g = f β eββ :=
eββ.toEquiv.comp_symm_eq f g
theorem eq_symm_comp {Ξ± : Type*} (f : Ξ± β Mβ) (g : Ξ± β Mβ) : f = eββ.symm β g β eββ β f = g :=
eββ.toEquiv.eq_symm_comp f g
theorem symm_comp_eq {Ξ± : Type*} (f : Ξ± β Mβ) (g : Ξ± β Mβ) : eββ.symm β g = f β g = eββ β f :=
eββ.toEquiv.symm_comp_eq f g
@[simp]
theorem comp_coe (f : Mβ βββ[Οββ] Mβ) (f' : Mβ βββ[Οββ] Mβ) :
(f' : Mβ βββ[Οββ] Mβ).comp (f : Mβ βββ[Οββ] Mβ) = (f.trans f' : Mβ βββ[Οββ] Mβ) :=
rfl
lemma trans_assoc (eββ : Mβ βββ[Οββ] Mβ) (eββ : Mβ βββ[Οββ] Mβ) (eββ : Mβ βββ[Οββ] Mβ) :
(eββ.trans eββ).trans eββ = eββ.trans (eββ.trans eββ) := rfl
variable [RingHomCompTriple Οββ Οββ Οββ] [RingHomCompTriple Οββ Οββ Οββ]
theorem eq_comp_toLinearMap_symm (f : Mβ βββ[Οββ] Mβ) (g : Mβ βββ[Οββ] Mβ) :
f = g.comp eββ.symm.toLinearMap β f.comp eββ.toLinearMap = g := by
constructor <;> intro H <;> ext
Β· simp [H]
Β· simp [β H]
theorem comp_toLinearMap_symm_eq (f : Mβ βββ[Οββ] Mβ) (g : Mβ βββ[Οββ] Mβ) :
g.comp eββ.symm.toLinearMap = f β g = f.comp eββ.toLinearMap := by
constructor <;> intro H <;> ext
Β· simp [β H]
Β· simp [H]
theorem eq_toLinearMap_symm_comp (f : Mβ βββ[Οββ] Mβ) (g : Mβ βββ[Οββ] Mβ) :
f = eββ.symm.toLinearMap.comp g β eββ.toLinearMap.comp f = g := by
constructor <;> intro H <;> ext
Β· simp [H]
Β· simp [β H]
theorem toLinearMap_symm_comp_eq (f : Mβ βββ[Οββ] Mβ) (g : Mβ βββ[Οββ] Mβ) :
eββ.symm.toLinearMap.comp g = f β g = eββ.toLinearMap.comp f := by
constructor <;> intro H <;> ext
Β· simp [β H]
Β· simp [H]
@[simp]
theorem comp_toLinearMap_eq_iff (f g : Mβ βββ[Οββ] Mβ) :
eββ.toLinearMap.comp f = eββ.toLinearMap.comp g β f = g := by
refine β¨fun h => ?_, congrArg eββ.compβ©
rw [β (toLinearMap_symm_comp_eq g (eββ.toLinearMap.comp f)).mpr h, eq_toLinearMap_symm_comp]
@[simp]
theorem eq_comp_toLinearMap_iff (f g : Mβ βββ[Οββ] Mβ) :
f.comp eββ.toLinearMap = g.comp eββ.toLinearMap β f = g := by
refine β¨fun h => ?_, fun a β¦ congrFun (congrArg LinearMap.comp a) eββ.toLinearMapβ©
rw [(eq_comp_toLinearMap_symm g (f.comp eββ.toLinearMap)).mpr h.symm, eq_comp_toLinearMap_symm]
lemma comp_symm_cancel_left (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
e.toLinearMap βββ (e.symm.toLinearMap βββ f) = f := by ext; simp
lemma symm_comp_cancel_left (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
e.symm.toLinearMap βββ (e.toLinearMap βββ f) = f := by ext; simp
lemma comp_symm_cancel_right (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
(f βββ e.toLinearMap) βββ e.symm.toLinearMap = f := by ext; simp
lemma symm_comp_cancel_right (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
(f βββ e.symm.toLinearMap) βββ e.toLinearMap = f := by ext; simp
lemma trans_symm_cancel_left (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
e.trans (e.symm.trans f) = f := by ext; simp
lemma symm_trans_cancel_left (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
e.symm.trans (e.trans f) = f := by ext; simp
lemma trans_symm_cancel_right (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
(f.trans e).trans e.symm = f := by ext; simp
lemma symm_trans_cancel_right (e : Mβ βββ[Οββ] Mβ) (f : Mβ βββ[Οββ] Mβ) :
(f.trans e.symm).trans e = f := by ext; simp
@[simp]
theorem refl_symm [Module R M] : (refl R M).symm = LinearEquiv.refl R M :=
rfl
@[simp]
theorem self_trans_symm (f : Mβ βββ[Οββ] Mβ) : f.trans f.symm = LinearEquiv.refl Rβ Mβ := by
ext x
simp
@[simp]
theorem symm_trans_self (f : Mβ βββ[Οββ] Mβ) : f.symm.trans f = LinearEquiv.refl Rβ Mβ := by
ext x
simp
@[simp]
theorem refl_toLinearMap [Module R M] : (LinearEquiv.refl R M : M ββ[R] M) = LinearMap.id :=
rfl
@[simp]
theorem mk_coe (f hβ hβ) : (LinearEquiv.mk e f hβ hβ : M βββ[Ο] Mβ) = e :=
ext fun _ β¦ rfl
protected theorem map_add (a b : M) : e (a + b) = e a + e b :=
map_add e a b
protected theorem map_zero : e 0 = 0 :=
map_zero e
protected theorem map_smulββ (c : R) (x : M) : e (c β’ x) = (Ο : R β S) c β’ e x :=
e.map_smul' c x
theorem map_smul (e : Nβ ββ[Rβ] Nβ) (c : Rβ) (x : Nβ) : e (c β’ x) = c β’ e x :=
map_smulββ e c x
theorem map_eq_zero_iff {x : M} : e x = 0 β x = 0 :=
e.toAddEquiv.map_eq_zero_iff
theorem map_ne_zero_iff {x : M} : e x β 0 β x β 0 :=
e.toAddEquiv.map_ne_zero_iff
@[simp]
theorem symm_symm (e : M βββ[Ο] Mβ) : e.symm.symm = e := rfl
theorem symm_bijective [Module R M] [Module S Mβ] [RingHomInvPair Ο' Ο] [RingHomInvPair Ο Ο'] :
Function.Bijective (symm : (M βββ[Ο] Mβ) β Mβ βββ[Ο'] M) :=
Function.bijective_iff_has_inverse.mpr β¨_, symm_symm, symm_symmβ©
@[simp]
theorem mk_coe' (f hβ hβ hβ hβ) :
(LinearEquiv.mk β¨β¨f, hββ©, hββ© (βe) hβ hβ : Mβ βββ[Ο'] M) = e.symm :=
symm_bijective.injective <| ext fun _ β¦ rfl
/-- Auxiliary definition to avoid looping in `dsimp` with `LinearEquiv.symm_mk`. -/
protected def symm_mk.aux (f hβ hβ hβ hβ) := (β¨β¨β¨e, hββ©, hββ©, f, hβ, hββ© : M βββ[Ο] Mβ).symm
@[simp]
theorem symm_mk (f hβ hβ hβ hβ) :
(β¨β¨β¨e, hββ©, hββ©, f, hβ, hββ© : M βββ[Ο] Mβ).symm =
{ symm_mk.aux e f hβ hβ hβ hβ with
toFun := f
invFun := e } :=
rfl
@[simp]
theorem coe_symm_mk [Module R M] [Module R Mβ]
{to_fun inv_fun map_add map_smul left_inv right_inv} :
β(β¨β¨β¨to_fun, map_addβ©, map_smulβ©, inv_fun, left_inv, right_invβ© : M ββ[R] Mβ).symm = inv_fun :=
rfl
protected theorem bijective : Function.Bijective e :=
e.toEquiv.bijective
protected theorem injective : Function.Injective e :=
e.toEquiv.injective
protected theorem surjective : Function.Surjective e :=
e.toEquiv.surjective
protected theorem image_eq_preimage (s : Set M) : e '' s = e.symm β»ΒΉ' s :=
e.toEquiv.image_eq_preimage s
protected theorem image_symm_eq_preimage (s : Set Mβ) : e.symm '' s = e β»ΒΉ' s :=
e.toEquiv.symm.image_eq_preimage s
end
/-- Interpret a `RingEquiv` `f` as an `f`-semilinear equiv. -/
@[simps]
def _root_.RingEquiv.toSemilinearEquiv (f : R β+* S) :
haveI := RingHomInvPair.of_ringEquiv f
haveI := RingHomInvPair.symm (βf : R β+* S) (f.symm : S β+* R)
R βββ[(βf : R β+* S)] S :=
haveI := RingHomInvPair.of_ringEquiv f
haveI := RingHomInvPair.symm (βf : R β+* S) (f.symm : S β+* R)
{ f with
toFun := f
map_smul' := f.map_mul }
variable [AddCommMonoid M]
/-- An involutive linear map is a linear equivalence. -/
def ofInvolutive {Ο Ο' : R β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
{_ : Module R M} (f : M βββ[Ο] M) (hf : Involutive f) : M βββ[Ο] M :=
{ f, hf.toPerm f with }
@[simp]
theorem coe_ofInvolutive {Ο Ο' : R β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
{_ : Module R M} (f : M βββ[Ο] M) (hf : Involutive f) : β(ofInvolutive f hf) = f :=
rfl
end AddCommMonoid
end LinearEquiv
|
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.
|
Behrend.lean
|
/-
Copyright (c) 2022 YaΓ«l Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Bhavik Mehta
-/
import Mathlib.Analysis.InnerProductSpace.Convex
import Mathlib.Analysis.InnerProductSpace.PiL2
import Mathlib.Combinatorics.Additive.AP.Three.Defs
import Mathlib.Combinatorics.Pigeonhole
import Mathlib.Data.Complex.ExponentialBounds
/-!
# Behrend's bound on Roth numbers
This file proves Behrend's lower bound on Roth numbers. This says that we can find a subset of
`{1, ..., n}` of size `n / exp (O (sqrt (log n)))` which does not contain arithmetic progressions of
length `3`.
The idea is that the sphere (in the `n` dimensional Euclidean space) doesn't contain arithmetic
progressions (literally) because the corresponding ball is strictly convex. Thus we can take
integer points on that sphere and map them onto `β` in a way that preserves arithmetic progressions
(`Behrend.map`).
## Main declarations
* `Behrend.sphere`: The intersection of the Euclidean sphere with the positive integer quadrant.
This is the set that we will map on `β`.
* `Behrend.map`: Given a natural number `d`, `Behrend.map d : ββΏ β β` reads off the coordinates as
digits in base `d`.
* `Behrend.card_sphere_le_rothNumberNat`: Implicit lower bound on Roth numbers in terms of
`Behrend.sphere`.
* `Behrend.roth_lower_bound`: Behrend's explicit lower bound on Roth numbers.
## References
* [Bryan Gillespie, *Behrendβs Construction*]
(http://www.epsilonsmall.com/resources/behrends-construction/behrend.pdf)
* Behrend, F. A., "On sets of integers which contain no three terms in arithmetical progression"
* [Wikipedia, *Salem-Spencer set*](https://en.wikipedia.org/wiki/SalemβSpencer_set)
## Tags
3AP-free, Salem-Spencer, Behrend construction, arithmetic progression, sphere, strictly convex
-/
assert_not_exists IsConformalMap Conformal
open Nat hiding log
open Finset Metric Real
open scoped Pointwise
/-- The frontier of a closed strictly convex set only contains trivial arithmetic progressions.
The idea is that an arithmetic progression is contained on a line and the frontier of a strictly
convex set does not contain lines. -/
lemma threeAPFree_frontier {π E : Type*} [Field π] [LinearOrder π] [IsStrictOrderedRing π]
[TopologicalSpace E]
[AddCommMonoid E] [Module π E] {s : Set E} (hsβ : IsClosed s) (hsβ : StrictConvex π s) :
ThreeAPFree (frontier s) := by
intro a ha b hb c hc habc
obtain rfl : (1 / 2 : π) β’ a + (1 / 2 : π) β’ c = b := by
rwa [β smul_add, one_div, inv_smul_eq_iffβ (show (2 : π) β 0 by simp), two_smul]
have :=
hsβ.eq (hsβ.frontier_subset ha) (hsβ.frontier_subset hc) one_half_pos one_half_pos
(add_halves _) hb.2
simp [this, β add_smul]
ring_nf
simp
lemma threeAPFree_sphere {E : Type*} [NormedAddCommGroup E] [NormedSpace β E]
[StrictConvexSpace β E] (x : E) (r : β) : ThreeAPFree (sphere x r) := by
obtain rfl | hr := eq_or_ne r 0
Β· rw [sphere_zero]
exact threeAPFree_singleton _
Β· convert threeAPFree_frontier isClosed_closedBall (strictConvex_closedBall β x r)
exact (frontier_closedBall _ hr).symm
namespace Behrend
variable {n d k N : β} {x : Fin n β β}
/-!
### Turning the sphere into 3AP-free set
We define `Behrend.sphere`, the intersection of the $L^2$ sphere with the positive quadrant of
integer points. Because the $L^2$ closed ball is strictly convex, the $L^2$ sphere and
`Behrend.sphere` are 3AP-free (`threeAPFree_sphere`). Then we can turn this set in
`Fin n β β` into a set in `β` using `Behrend.map`, which preserves `ThreeAPFree` because it is
an additive monoid homomorphism.
-/
/-- The box `{0, ..., d - 1}^n` as a `Finset`. -/
def box (n d : β) : Finset (Fin n β β) :=
Fintype.piFinset fun _ => range d
theorem mem_box : x β box n d β β i, x i < d := by simp only [box, Fintype.mem_piFinset, mem_range]
@[simp]
theorem card_box : #(box n d) = d ^ n := by simp [box]
@[simp]
theorem box_zero : box (n + 1) 0 = β
:= by simp [box]
/-- The intersection of the sphere of radius `βk` with the integer points in the positive
quadrant. -/
def sphere (n d k : β) : Finset (Fin n β β) := {x β box n d | β i, x i ^ 2 = k}
theorem sphere_zero_subset : sphere n d 0 β 0 := fun x => by simp [sphere, funext_iff]
@[simp]
theorem sphere_zero_right (n k : β) : sphere (n + 1) 0 k = β
:= by simp [sphere]
theorem sphere_subset_box : sphere n d k β box n d :=
filter_subset _ _
theorem norm_of_mem_sphere {x : Fin n β β} (hx : x β sphere n d k) :
βWithLp.toLp 2 ((β) β x : Fin n β β)β = ββk := by
rw [EuclideanSpace.norm_eq]
dsimp
simp_rw [abs_cast, β cast_pow, β cast_sum, (mem_filter.1 hx).2]
theorem sphere_subset_preimage_metric_sphere : (sphere n d k : Set (Fin n β β)) β
(fun x : Fin n β β => WithLp.toLp 2 ((β) β x : Fin n β β)) β»ΒΉ'
Metric.sphere (0 : PiLp 2 fun _ : Fin n => β) (ββk) :=
fun x hx => by rw [Set.mem_preimage, mem_sphere_zero_iff_norm, norm_of_mem_sphere hx]
/-- The map that appears in Behrend's bound on Roth numbers. -/
@[simps]
def map (d : β) : (Fin n β β) β+ β where
toFun a := β i, a i * d ^ (i : β)
map_zero' := by simp_rw [Pi.zero_apply, zero_mul, sum_const_zero]
map_add' a b := by simp_rw [Pi.add_apply, add_mul, sum_add_distrib]
theorem map_zero (d : β) (a : Fin 0 β β) : map d a = 0 := by simp [map]
theorem map_succ (a : Fin (n + 1) β β) :
map d a = a 0 + (β x : Fin n, a x.succ * d ^ (x : β)) * d := by
simp [map, Fin.sum_univ_succ, _root_.pow_succ, β mul_assoc, β sum_mul]
theorem map_succ' (a : Fin (n + 1) β β) : map d a = a 0 + map d (a β Fin.succ) * d :=
map_succ _
theorem map_monotone (d : β) : Monotone (map d : (Fin n β β) β β) := fun x y h => by
dsimp; exact sum_le_sum fun i _ => Nat.mul_le_mul_right _ <| h i
theorem map_mod (a : Fin n.succ β β) : map d a % d = a 0 % d := by
rw [map_succ, Nat.add_mul_mod_self_right]
theorem map_eq_iff {xβ xβ : Fin n.succ β β} (hxβ : β i, xβ i < d) (hxβ : β i, xβ i < d) :
map d xβ = map d xβ β xβ 0 = xβ 0 β§ map d (xβ β Fin.succ) = map d (xβ β Fin.succ) := by
refine β¨fun h => ?_, fun h => by rw [map_succ', map_succ', h.1, h.2]β©
have : xβ 0 = xβ 0 := by
rw [β mod_eq_of_lt (hxβ _), β map_mod, β mod_eq_of_lt (hxβ _), β map_mod, h]
rw [map_succ, map_succ, this, add_right_inj, mul_eq_mul_right_iff] at h
exact β¨this, h.resolve_right (pos_of_gt (hxβ 0)).ne'β©
theorem map_injOn : {x : Fin n β β | β i, x i < d}.InjOn (map d) := by
intro xβ hxβ xβ hxβ h
induction n with
| zero => simp [eq_iff_true_of_subsingleton]
| succ n ih =>
ext i
have x := (map_eq_iff hxβ hxβ).1 h
exact Fin.cases x.1 (congr_fun <| ih (fun _ => hxβ _) (fun _ => hxβ _) x.2) i
theorem map_le_of_mem_box (hx : x β box n d) :
map (2 * d - 1) x β€ β i : Fin n, (d - 1) * (2 * d - 1) ^ (i : β) :=
map_monotone (2 * d - 1) fun _ => Nat.le_sub_one_of_lt <| mem_box.1 hx _
nonrec theorem threeAPFree_sphere : ThreeAPFree (sphere n d k : Set (Fin n β β)) := by
set f : (Fin n β β) β+ EuclideanSpace β (Fin n) :=
{ toFun := fun f => ((β) : β β β) β f
map_zero' := funext fun _ => cast_zero
map_add' := fun _ _ => funext fun _ => cast_add _ _ }
refine ThreeAPFree.of_image (AddMonoidHomClass.isAddFreimanHom f (Set.mapsTo_image _ _))
cast_injective.comp_left.injOn (Set.subset_univ _) ?_
refine (threeAPFree_sphere 0 (ββk)).mono (Set.image_subset_iff.2 fun x => ?_)
rw [Set.mem_preimage, mem_sphere_zero_iff_norm]
exact norm_of_mem_sphere
theorem threeAPFree_image_sphere :
ThreeAPFree ((sphere n d k).image (map (2 * d - 1)) : Set β) := by
rw [coe_image]
apply ThreeAPFree.image' (Ξ± := Fin n β β) (Ξ² := β) (s := sphere n d k) (map (2 * d - 1))
(map_injOn.mono _) threeAPFree_sphere
rw [Set.add_subset_iff]
rintro a ha b hb i
have hai := mem_box.1 (sphere_subset_box ha) i
have hbi := mem_box.1 (sphere_subset_box hb) i
rw [lt_tsub_iff_right, β succ_le_iff, two_mul]
exact (add_add_add_comm _ _ 1 1).trans_le (_root_.add_le_add hai hbi)
theorem sum_sq_le_of_mem_box (hx : x β box n d) : β i : Fin n, x i ^ 2 β€ n * (d - 1) ^ 2 := by
rw [mem_box] at hx
have : β i, x i ^ 2 β€ (d - 1) ^ 2 := fun i =>
Nat.pow_le_pow_left (Nat.le_sub_one_of_lt (hx i)) _
exact (sum_le_card_nsmul univ _ _ fun i _ => this i).trans (by rw [Finset.card_fin, smul_eq_mul])
theorem sum_eq : (β i : Fin n, d * (2 * d + 1) ^ (i : β)) = ((2 * d + 1) ^ n - 1) / 2 := by
refine (Nat.div_eq_of_eq_mul_left zero_lt_two ?_).symm
rw [β sum_range fun i => d * (2 * d + 1) ^ (i : β), β mul_sum, mul_right_comm, mul_comm d, β
geom_sum_mul_add, add_tsub_cancel_right, mul_comm]
theorem sum_lt : (β i : Fin n, d * (2 * d + 1) ^ (i : β)) < (2 * d + 1) ^ n :=
sum_eq.trans_lt <| (Nat.div_le_self _ 2).trans_lt <| pred_lt (pow_pos (succ_pos _) _).ne'
theorem card_sphere_le_rothNumberNat (n d k : β) :
#(sphere n d k) β€ rothNumberNat ((2 * d - 1) ^ n) := by
cases n
Β· dsimp; refine (card_le_univ _).trans_eq ?_; rfl
cases d
Β· simp
apply threeAPFree_image_sphere.le_rothNumberNat _ _ (card_image_of_injOn _)
Β· simp only [mem_image, and_imp, forall_exists_index,
sphere, mem_filter]
rintro _ x hx _ rfl
exact (map_le_of_mem_box hx).trans_lt sum_lt
apply map_injOn.mono fun x => ?_
simp only [mem_coe, sphere, mem_filter, mem_box, and_imp, two_mul]
exact fun h _ i => (h i).trans_le le_self_add
/-!
### Optimization
Now that we know how to turn the integer points of any sphere into a 3AP-free set, we find a
sphere containing many integer points by the pigeonhole principle. This gives us an implicit bound
that we then optimize by tweaking the parameters. The (almost) optimal parameters are
`Behrend.nValue` and `Behrend.dValue`.
-/
theorem exists_large_sphere_aux (n d : β) : β k β range (n * (d - 1) ^ 2 + 1),
(β(d ^ n) / ((n * (d - 1) ^ 2 :) + 1) : β) β€ #(sphere n d k) := by
refine exists_le_card_fiber_of_nsmul_le_card_of_maps_to (fun x hx => ?_) nonempty_range_succ ?_
Β· rw [mem_range, Nat.lt_succ_iff]
exact sum_sq_le_of_mem_box hx
Β· rw [card_range, nsmul_eq_mul, mul_div_assoc', cast_add_one, mul_div_cancel_leftβ, card_box]
exact (cast_add_one_pos _).ne'
theorem exists_large_sphere (n d : β) :
β k, ((d ^ n :) / (n * d ^ 2 :) : β) β€ #(sphere n d k) := by
obtain β¨k, -, hkβ© := exists_large_sphere_aux n d
refine β¨k, ?_β©
obtain rfl | hn := n.eq_zero_or_pos
Β· simp
obtain rfl | hd := d.eq_zero_or_pos
Β· simp
refine (div_le_div_of_nonneg_left ?_ ?_ ?_).trans hk
Β· exact cast_nonneg _
Β· exact cast_add_one_pos _
simp only [β le_sub_iff_add_le', cast_mul, β mul_sub, cast_pow, cast_sub hd, sub_sq, one_pow,
cast_one, mul_one, sub_add, sub_sub_self]
apply one_le_mul_of_one_le_of_one_le
Β· rwa [one_le_cast]
rw [_root_.le_sub_iff_add_le]
norm_num
exact one_le_cast.2 hd
theorem bound_aux' (n d : β) : ((d ^ n :) / (n * d ^ 2 :) : β) β€ rothNumberNat ((2 * d - 1) ^ n) :=
let β¨_, hβ© := exists_large_sphere n d
h.trans <| cast_le.2 <| card_sphere_le_rothNumberNat _ _ _
theorem bound_aux (hd : d β 0) (hn : 2 β€ n) :
(d ^ (n - 2 :) / n : β) β€ rothNumberNat ((2 * d - 1) ^ n) := by
convert bound_aux' n d using 1
rw [cast_mul, cast_pow, mul_comm, β div_div, pow_subβ _ _ hn, β div_eq_mul_inv, cast_pow]
rwa [cast_ne_zero]
open scoped Filter Topology
open Real
section NumericalBounds
theorem log_two_mul_two_le_sqrt_log_eight : log 2 * 2 β€ β(log 8) := by
rw [show (8 : β) = 2 ^ 3 by norm_num1, Real.log_pow, Nat.cast_ofNat]
apply le_sqrt_of_sq_le
rw [mul_pow, sq (log 2), mul_assoc, mul_comm]
gcongr
linarith only [log_two_lt_d9.le]
theorem two_div_one_sub_two_div_e_le_eight : 2 / (1 - 2 / exp 1) β€ 8 := by
rw [div_le_iffβ, mul_sub, mul_one, mul_div_assoc', le_sub_comm, div_le_iffβ (exp_pos _)]
Β· linarith [exp_one_gt_d9]
rw [sub_pos, div_lt_one] <;> exact exp_one_gt_d9.trans' (by norm_num)
theorem le_sqrt_log (hN : 4096 β€ N) : log (2 / (1 - 2 / exp 1)) * (69 / 50) β€ β(log βN) := by
calc
_ β€ log (2 ^ 3) * (69 / 50) := by
gcongr
Β· field_simp [show 2 < Real.exp 1 from lt_trans (by norm_num1) exp_one_gt_d9]
Β· norm_num1
exact two_div_one_sub_two_div_e_le_eight
_ β€ β(log (2 ^ 12)) := by
simp only [Real.log_pow, Nat.cast_ofNat]
apply le_sqrt_of_sq_le
nlinarith [log_two_lt_d9, log_two_gt_d9]
_ β€ β(log βN) := by
gcongr
exact mod_cast hN
theorem exp_neg_two_mul_le {x : β} (hx : 0 < x) : exp (-2 * x) < exp (2 - βxββ) / βxββ := by
have hβ := ceil_lt_add_one hx.le
have hβ : 1 - x β€ 2 - βxββ := by linarith
calc
_ β€ exp (1 - x) / (x + 1) := ?_
_ β€ exp (2 - βxββ) / (x + 1) := by gcongr
_ < _ := by gcongr
rw [le_div_iffβ (add_pos hx zero_lt_one), β le_div_iffβ' (exp_pos _), β exp_sub, neg_mul,
sub_neg_eq_add, two_mul, sub_add_add_cancel, add_comm _ x]
exact le_trans (le_add_of_nonneg_right zero_le_one) (add_one_le_exp _)
theorem div_lt_floor {x : β} (hx : 2 / (1 - 2 / exp 1) β€ x) : x / exp 1 < (βx / 2ββ : β) := by
apply lt_of_le_of_lt _ (sub_one_lt_floor _)
have : 0 < 1 - 2 / exp 1 := by
rw [sub_pos, div_lt_one (exp_pos _)]
exact lt_of_le_of_lt (by norm_num) exp_one_gt_d9
rwa [le_sub_comm, div_eq_mul_one_div x, div_eq_mul_one_div x, β mul_sub, div_sub', β
div_eq_mul_one_div, mul_div_assoc', one_le_div, β div_le_iffβ this]
Β· exact zero_lt_two
Β· exact two_ne_zero
theorem ceil_lt_mul {x : β} (hx : 50 / 19 β€ x) : (βxββ : β) < 1.38 * x := by
refine (ceil_lt_add_one <| hx.trans' <| by norm_num).trans_le ?_
rw [β le_sub_iff_add_le', β sub_one_mul]
have : (1.38 : β) = 69 / 50 := by norm_num
rwa [this, show (69 / 50 - 1 : β) = (50 / 19)β»ΒΉ by norm_num1, β
div_eq_inv_mul, one_le_div]
norm_num1
end NumericalBounds
/-- The (almost) optimal value of `n` in `Behrend.bound_aux`. -/
noncomputable def nValue (N : β) : β :=
ββ(log N)ββ
/-- The (almost) optimal value of `d` in `Behrend.bound_aux`. -/
noncomputable def dValue (N : β) : β := β(N : β) ^ (nValue N : β)β»ΒΉ / 2ββ
theorem nValue_pos (hN : 2 β€ N) : 0 < nValue N :=
ceil_pos.2 <| Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| hN
theorem three_le_nValue (hN : 64 β€ N) : 3 β€ nValue N := by
rw [nValue, β lt_iff_add_one_le, lt_ceil, cast_two]
apply lt_sqrt_of_sq_lt
have : (2 : β) ^ ((6 : β) : β) β€ N := by
rw [rpow_natCast]
exact (cast_le.2 hN).trans' (by norm_num1)
apply lt_of_lt_of_le _ (log_le_log (rpow_pos_of_pos zero_lt_two _) this)
rw [log_rpow zero_lt_two, β div_lt_iffβ']
Β· exact log_two_gt_d9.trans_le' (by norm_num1)
Β· norm_num1
theorem dValue_pos (hNβ : 8 β€ N) : 0 < dValue N := by
have hNβ : 0 < (N : β) := cast_pos.2 (succ_pos'.trans_le hNβ)
rw [dValue, floor_pos, β log_le_log_iff zero_lt_one, log_one, log_div _ two_ne_zero, log_rpow hNβ,
inv_mul_eq_div, sub_nonneg, le_div_iffβ]
Β· have : (nValue N : β) β€ 2 * β(log N) := by
apply (ceil_lt_add_one <| sqrt_nonneg _).le.trans
rw [two_mul, add_le_add_iff_left]
apply le_sqrt_of_sq_le
rw [one_pow, le_log_iff_exp_le hNβ]
exact (exp_one_lt_d9.le.trans <| by norm_num).trans (cast_le.2 hNβ)
apply (mul_le_mul_of_nonneg_left this <| log_nonneg one_le_two).trans _
rw [β mul_assoc, β le_div_iffβ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 _), div_sqrt]
Β· apply log_two_mul_two_le_sqrt_log_eight.trans
apply Real.sqrt_le_sqrt
exact log_le_log (by norm_num) (mod_cast hNβ)
exact hNβ.trans_lt' (by norm_num)
Β· exact cast_pos.2 (nValue_pos <| hNβ.trans' <| by norm_num)
Β· exact (rpow_pos_of_pos hNβ _).ne'
Β· exact div_pos (rpow_pos_of_pos hNβ _) zero_lt_two
theorem le_N (hN : 2 β€ N) : (2 * dValue N - 1) ^ nValue N β€ N := by
have : (2 * dValue N - 1) ^ nValue N β€ (2 * dValue N) ^ nValue N :=
Nat.pow_le_pow_left (Nat.sub_le _ _) _
apply this.trans
suffices ((2 * dValue N) ^ nValue N : β) β€ N from mod_cast this
suffices i : (2 * dValue N : β) β€ (N : β) ^ (nValue N : β)β»ΒΉ by
rw [β rpow_natCast]
apply (rpow_le_rpow (mul_nonneg zero_le_two (cast_nonneg _)) i (cast_nonneg _)).trans
rw [β rpow_mul (cast_nonneg _), inv_mul_cancelβ, rpow_one]
rw [cast_ne_zero]
apply (nValue_pos hN).ne'
rw [β le_div_iffβ']
Β· exact floor_le (div_nonneg (rpow_nonneg (cast_nonneg _) _) zero_le_two)
apply zero_lt_two
theorem bound (hN : 4096 β€ N) : (N : β) ^ (nValue N : β)β»ΒΉ / exp 1 < dValue N := by
apply div_lt_floor _
rw [β log_le_log_iff, log_rpow, mul_comm, β div_eq_mul_inv]
Β· apply le_trans _ (div_le_div_of_nonneg_left _ _ (ceil_lt_mul _).le)
Β· rw [mul_comm, β div_div, div_sqrt, le_div_iffβ]
Β· norm_num [le_sqrt_log hN]
Β· norm_num1
Β· apply log_nonneg
rw [one_le_cast]
exact hN.trans' (by norm_num1)
Β· rw [cast_pos, lt_ceil, cast_zero, Real.sqrt_pos]
refine log_pos ?_
rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
apply le_sqrt_of_sq_le
have : (12 : β) * log 2 β€ log N := by
rw [β log_rpow zero_lt_two, rpow_natCast]
exact log_le_log (by positivity) (mod_cast hN)
refine le_trans ?_ this
rw [β div_le_iffβ']
Β· exact log_two_gt_d9.le.trans' (by norm_num1)
Β· norm_num1
Β· rw [cast_pos]
exact hN.trans_lt' (by norm_num1)
Β· refine div_pos zero_lt_two ?_
rw [sub_pos, div_lt_one (exp_pos _)]
exact lt_of_le_of_lt (by norm_num1) exp_one_gt_d9
positivity
theorem roth_lower_bound_explicit (hN : 4096 β€ N) :
(N : β) * exp (-4 * β(log N)) < rothNumberNat N := by
let n := nValue N
have hn : 0 < (n : β) := cast_pos.2 (nValue_pos <| hN.trans' <| by norm_num1)
have hd : 0 < dValue N := dValue_pos (hN.trans' <| by norm_num1)
have hNβ : 0 < (N : β) := cast_pos.2 (hN.trans' <| by norm_num1)
have hnβ : 2 < n := three_le_nValue <| hN.trans' <| by norm_num1
have : (2 * dValue N - 1) ^ n β€ N := le_N (hN.trans' <| by norm_num1)
calc
_ β€ (N ^ (nValue N : β)β»ΒΉ / rexp 1 : β) ^ (n - 2) / n := ?_
_ < _ := by gcongr; exacts [(tsub_pos_of_lt hnβ).ne', bound hN]
_ β€ rothNumberNat ((2 * dValue N - 1) ^ n) := bound_aux hd.ne' hnβ.le
_ β€ rothNumberNat N := mod_cast rothNumberNat.mono this
rw [β rpow_natCast, div_rpow (rpow_nonneg hNβ.le _) (exp_pos _).le, β rpow_mul hNβ.le,
inv_mul_eq_div, cast_sub hnβ.le, cast_two, same_sub_div hn.ne', exp_one_rpow,
div_div, rpow_sub hNβ, rpow_one, div_div, div_eq_mul_inv]
gcongr _ * ?_
rw [mul_inv, mul_inv, β exp_neg, β rpow_neg (cast_nonneg _), neg_sub, β div_eq_mul_inv]
have : exp (-4 * β(log N)) = exp (-2 * β(log N)) * exp (-2 * β(log N)) := by
rw [β exp_add, β add_mul]
norm_num
rw [this]
gcongr
Β· rw [β le_log_iff_exp_le (rpow_pos_of_pos hNβ _), log_rpow hNβ, β le_div_iffβ, mul_div_assoc,
div_sqrt, neg_mul, neg_le_neg_iff, div_mul_eq_mul_div, div_le_iffβ hn]
Β· gcongr
apply le_ceil
refine Real.sqrt_pos.2 (log_pos ?_)
rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
Β· refine (exp_neg_two_mul_le <| Real.sqrt_pos.2 <| log_pos ?_).le
rw [one_lt_cast]
exact hN.trans_lt' (by norm_num1)
theorem exp_four_lt : exp 4 < 64 := by
rw [show (64 : β) = 2 ^ ((6 : β) : β) by rw [rpow_natCast]; norm_num1,
β lt_log_iff_exp_lt (rpow_pos_of_pos zero_lt_two _), log_rpow zero_lt_two, β div_lt_iffβ']
Β· exact log_two_gt_d9.trans_le' (by norm_num1)
Β· norm_num
theorem four_zero_nine_six_lt_exp_sixteen : 4096 < exp 16 := by
rw [β log_lt_iff_lt_exp (show (0 : β) < 4096 by norm_num), show (4096 : β) = 2 ^ 12 by norm_cast,
β rpow_natCast, log_rpow zero_lt_two, cast_ofNat]
linarith [log_two_lt_d9]
theorem lower_bound_le_one' (hN : 2 β€ N) (hN' : N β€ 4096) :
(N : β) * exp (-4 * β(log N)) β€ 1 := by
rw [β log_le_log_iff (mul_pos (cast_pos.2 (zero_lt_two.trans_le hN)) (exp_pos _)) zero_lt_one,
log_one, log_mul (cast_pos.2 (zero_lt_two.trans_le hN)).ne' (exp_pos _).ne', log_exp, neg_mul, β
sub_eq_add_neg, sub_nonpos, β
div_le_iffβ (Real.sqrt_pos.2 <| log_pos <| one_lt_cast.2 <| one_lt_two.trans_le hN), div_sqrt,
sqrt_le_left zero_le_four, log_le_iff_le_exp (cast_pos.2 (zero_lt_two.trans_le hN))]
norm_num1
apply le_trans _ four_zero_nine_six_lt_exp_sixteen.le
exact mod_cast hN'
theorem lower_bound_le_one (hN : 1 β€ N) (hN' : N β€ 4096) :
(N : β) * exp (-4 * β(log N)) β€ 1 := by
obtain rfl | hN := hN.eq_or_lt
Β· norm_num
Β· exact lower_bound_le_one' hN hN'
theorem roth_lower_bound : (N : β) * exp (-4 * β(log N)) β€ rothNumberNat N := by
obtain rfl | hN := Nat.eq_zero_or_pos N
Β· norm_num
obtain hβ | hβ := le_or_gt 4096 N
Β· exact (roth_lower_bound_explicit hβ).le
Β· apply (lower_bound_le_one hN hβ.le).trans
simpa using rothNumberNat.monotone hN
end Behrend
|
CompactlyCoherentSpace.lean
|
/-
Copyright (c) 2025 Floris van Doorn and Hannah Scholz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Hannah Scholz
-/
import Mathlib.Topology.Coherent
import Mathlib.Topology.Compactness.Compact
/-!
# Compactly coherent spaces and the k-ification
In this file we will define compactly coherent spaces and prove basic properties about them.
This is a weaker version of `CompactlyGeneratedSpace`. These notions agree on Hausdorff spaces. They
are both referred to as compactly generated spaces in the literature.
## Main definitions
* `CompactlyCoherentSpace`: A compactly coherent space is a topological space in which a set `A` is
open iff for every compact set `B`, the intersection `A β© B` is open in `B`.
## Main results
* `CompactlyCoherentSpace.of_weaklyLocallyCompactSpace`: every weakly locally compact space is a
compactly coherent space.
* `CompactlyCoherentSpace.of_sequentialSpace`: every sequential space is a compactly coherent space.
## References
* [J. Munkres, *Topology*][Munkres2000]
* <https://en.wikipedia.org/wiki/Compactly_generated_space>
-/
noncomputable section
open Set Set.Notation Topology
/-! ### Compactly coherent spaces-/
/-- A space is a compactly coherent space if the topology is generated by the compact sets. -/
class CompactlyCoherentSpace (X : Type*) [TopologicalSpace X] : Prop where
/-- A space is a compactly coherent space if the topology is generated by the compact sets. -/
isCoherentWith : IsCoherentWith (X := X) {K | IsCompact K}
namespace CompactlyCoherentSpace
universe u
variable {X : Type u} [TopologicalSpace X]
/-- A set `A` in a compactly coherent space is open iff for every compact set `K`, the intersection
`K β© A` is open in `K`. -/
lemma isOpen_iff [CompactlyCoherentSpace X] {A : Set X} :
IsOpen A β β K, IsCompact K β IsOpen (K ββ© A) :=
IsCoherentWith.isOpen_iff isCoherentWith
/-- A set `A` in a compactly coherent space is closed iff for every compact set `K`, the
intersection `K β© A` is closed in `K`. -/
lemma isClosed_iff [CompactlyCoherentSpace X] (A : Set X) :
IsClosed A β β K, IsCompact K β IsClosed (K ββ© A) :=
IsCoherentWith.isClosed_iff isCoherentWith
/-- If every set `A` is open if for every compact `K` the intersection `K β© A` is open in `K`,
then the space is a compactly coherent space. -/
lemma of_isOpen (h : β (A : Set X), (β K, IsCompact K β IsOpen (K ββ© A)) β IsOpen A) :
CompactlyCoherentSpace X where
isCoherentWith := {isOpen_of_forall_induced := h}
/-- If every set `A` is closed if for every compact `K` the intersection `K β© A` is closed in `K`,
then the space is a compactly coherent space. -/
lemma of_isClosed (h : β (A : Set X), (β K, IsCompact K β IsClosed (K ββ© A)) β IsClosed A) :
CompactlyCoherentSpace X where
isCoherentWith := IsCoherentWith.of_isClosed h
/-- Every weakly locally compact space is a compactly coherent space. -/
instance of_weaklyLocallyCompactSpace [WeaklyLocallyCompactSpace X] : CompactlyCoherentSpace X where
isCoherentWith := IsCoherentWith.of_nhds exists_compact_mem_nhds
@[deprecated (since := "2025-05-30")] alias
_root_.Topology.IsCoherentWith.isCompact_of_weaklyLocallyCompact := of_weaklyLocallyCompactSpace
/-- Every sequential space is a compactly coherent space. -/
instance of_sequentialSpace [SequentialSpace X] : CompactlyCoherentSpace X where
isCoherentWith := IsCoherentWith.of_seq fun _u _x hux β¦ hux.isCompact_insert_range
@[deprecated (since := "2025-05-30")] alias
_root_.Topology.IsCoherentWith.isCompact_of_seq := of_sequentialSpace
/-- In a compactly coherent space `X`, a set `s` is open iff `f β»ΒΉ' s` is open for every continuous
map from a compact space. -/
lemma isOpen_iff_forall_compactSpace [CompactlyCoherentSpace X] (s : Set X) :
IsOpen s β
β (K : Type u) [TopologicalSpace K] [CompactSpace K],
β (f : K β X), Continuous f β IsOpen (f β»ΒΉ' s) := by
refine β¨fun hs _ _ _ _ hf β¦ hs.preimage hf, fun hs β¦ isOpen_iff |>.mpr ?_β©
intro K hK
have : CompactSpace K := isCompact_iff_compactSpace.mp hK
exact hs K Subtype.val continuous_subtype_val
/-- A topological space `X` is compactly coherent if a set `s` is open when `f β»ΒΉ' s?` is open for
every continuous map `f : K β X`, where `K` is compact. -/
lemma of_isOpen_forall_compactSpace (h : β (s : Set X), (β (K : Type u) [TopologicalSpace K],
[CompactSpace K] β β (f : K β X), Continuous f β IsOpen (f β»ΒΉ' s)) β IsOpen s) :
CompactlyCoherentSpace X := by
refine of_isOpen fun A hA β¦ h A fun K _ _ f hf β¦ ?_
specialize hA (range f) (isCompact_range hf)
have := hA.preimage (hf.codRestrict mem_range_self)
rwa [β preimage_comp] at this
end CompactlyCoherentSpace
|
Equiv.lean
|
/-
Copyright (c) 2018 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl, Callum Sutton, Yury Kudryashov
-/
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Units.Hom
/-!
# Multiplicative and additive equivalence acting on units.
-/
assert_not_exists MonoidWithZero DenselyOrdered
variable {F Ξ± M N G : Type*}
/-- A group is isomorphic to its group of units. -/
@[to_additive (attr := simps apply_val symm_apply)
/-- An additive group is isomorphic to its group of additive units -/]
def toUnits [Group G] : G β* GΛ£ where
toFun x := β¨x, xβ»ΒΉ, mul_inv_cancel _, inv_mul_cancel _β©
invFun x := x
map_mul' _ _ := Units.ext rfl
@[to_additive (attr := simp)]
lemma toUnits_val_apply {G : Type*} [Group G] (x : GΛ£) : toUnits (x : G) = x := by
simp_rw [MulEquiv.apply_eq_iff_symm_apply, toUnits_symm_apply]
namespace Units
variable [Monoid M] [Monoid N]
/-- A multiplicative equivalence of monoids defines a multiplicative equivalence
of their groups of units. -/
def mapEquiv (h : M β* N) : MΛ£ β* NΛ£ :=
{ map h.toMonoidHom with
invFun := map h.symm.toMonoidHom,
left_inv := fun u => ext <| h.left_inv u,
right_inv := fun u => ext <| h.right_inv u }
@[simp]
theorem mapEquiv_symm (h : M β* N) : (mapEquiv h).symm = mapEquiv h.symm :=
rfl
@[simp]
theorem coe_mapEquiv (h : M β* N) (x : MΛ£) : (mapEquiv h x : N) = h x :=
rfl
/-- Left multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive (attr := simps -fullyApplied apply)
/-- Left addition of an additive unit is a permutation of the underlying type. -/]
def mulLeft (u : MΛ£) : Equiv.Perm M where
toFun x := u * x
invFun x := uβ»ΒΉ * x
left_inv := u.inv_mul_cancel_left
right_inv := u.mul_inv_cancel_left
@[to_additive (attr := simp)]
theorem mulLeft_symm (u : MΛ£) : u.mulLeft.symm = uβ»ΒΉ.mulLeft :=
Equiv.ext fun _ => rfl
@[to_additive]
theorem mulLeft_bijective (a : MΛ£) : Function.Bijective ((a * Β·) : M β M) :=
(mulLeft a).bijective
/-- Right multiplication by a unit of a monoid is a permutation of the underlying type. -/
@[to_additive (attr := simps -fullyApplied apply)
/-- Right addition of an additive unit is a permutation of the underlying type. -/]
def mulRight (u : MΛ£) : Equiv.Perm M where
toFun x := x * u
invFun x := x * βuβ»ΒΉ
left_inv x := mul_inv_cancel_right x u
right_inv x := inv_mul_cancel_right x u
@[to_additive (attr := simp)]
theorem mulRight_symm (u : MΛ£) : u.mulRight.symm = uβ»ΒΉ.mulRight :=
Equiv.ext fun _ => rfl
@[to_additive]
theorem mulRight_bijective (a : MΛ£) : Function.Bijective ((Β· * a) : M β M) :=
(mulRight a).bijective
end Units
namespace Equiv
section Group
variable [Group G]
/-- Left multiplication in a `Group` is a permutation of the underlying type. -/
@[to_additive /-- Left addition in an `AddGroup` is a permutation of the underlying type. -/]
protected def mulLeft (a : G) : Perm G :=
(toUnits a).mulLeft
@[to_additive (attr := simp)]
theorem coe_mulLeft (a : G) : β(Equiv.mulLeft a) = (a * Β·) :=
rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[to_additive (attr := simp)
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/]
theorem mulLeft_symm_apply (a : G) : ((Equiv.mulLeft a).symm : G β G) = (aβ»ΒΉ * Β·) :=
rfl
@[to_additive (attr := simp)]
theorem mulLeft_symm (a : G) : (Equiv.mulLeft a).symm = Equiv.mulLeft aβ»ΒΉ :=
ext fun _ => rfl
@[to_additive]
theorem _root_.Group.mulLeft_bijective (a : G) : Function.Bijective (a * Β·) :=
(Equiv.mulLeft a).bijective
/-- Right multiplication in a `Group` is a permutation of the underlying type. -/
@[to_additive /-- Right addition in an `AddGroup` is a permutation of the underlying type. -/]
protected def mulRight (a : G) : Perm G :=
(toUnits a).mulRight
@[to_additive (attr := simp)]
theorem coe_mulRight (a : G) : β(Equiv.mulRight a) = fun x => x * a :=
rfl
@[to_additive (attr := simp)]
theorem mulRight_symm (a : G) : (Equiv.mulRight a).symm = Equiv.mulRight aβ»ΒΉ :=
ext fun _ => rfl
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/
@[to_additive (attr := simp)
/-- Extra simp lemma that `dsimp` can use. `simp` will never use this. -/]
theorem mulRight_symm_apply (a : G) : ((Equiv.mulRight a).symm : G β G) = fun x => x * aβ»ΒΉ :=
rfl
@[to_additive]
theorem _root_.Group.mulRight_bijective (a : G) : Function.Bijective (Β· * a) :=
(Equiv.mulRight a).bijective
/-- A version of `Equiv.mulLeft a bβ»ΒΉ` that is defeq to `a / b`. -/
@[to_additive (attr := simps) /-- A version of `Equiv.addLeft a (-b)` that is defeq to `a - b`. -/]
protected def divLeft (a : G) : G β G where
toFun b := a / b
invFun b := bβ»ΒΉ * a
left_inv b := by simp [div_eq_mul_inv]
right_inv b := by simp [div_eq_mul_inv]
@[to_additive]
theorem divLeft_eq_inv_trans_mulLeft (a : G) :
Equiv.divLeft a = (Equiv.inv G).trans (Equiv.mulLeft a) :=
ext fun _ => div_eq_mul_inv _ _
/-- A version of `Equiv.mulRight aβ»ΒΉ b` that is defeq to `b / a`. -/
@[to_additive (attr := simps) /-- A version of `Equiv.addRight (-a) b` that is defeq to `b - a`. -/]
protected def divRight (a : G) : G β G where
toFun b := b / a
invFun b := b * a
left_inv b := by simp [div_eq_mul_inv]
right_inv b := by simp [div_eq_mul_inv]
@[to_additive]
theorem divRight_eq_mulRight_inv (a : G) : Equiv.divRight a = Equiv.mulRight aβ»ΒΉ :=
ext fun _ => div_eq_mul_inv _ _
end Group
section CommGroup
variable [CommGroup G]
@[to_additive]
lemma symm_divLeft (a : G) : (Equiv.divLeft a).symm = Equiv.divLeft a :=
ext fun _ β¦ inv_mul_eq_div _ _
@[to_additive (attr := simp)]
lemma divLeft_involutive (a : G) : Function.Involutive (Equiv.divLeft a) :=
fun _ β¦ div_div_cancel ..
end CommGroup
end Equiv
variable (Ξ±) in
/-- The `Ξ±Λ£` type is equivalent to a subtype of `Ξ± Γ Ξ±`. -/
@[simps]
def unitsEquivProdSubtype [Monoid Ξ±] : Ξ±Λ£ β {p : Ξ± Γ Ξ± // p.1 * p.2 = 1 β§ p.2 * p.1 = 1} where
toFun u := β¨(u, βuβ»ΒΉ), u.val_inv, u.inv_valβ©
invFun p := Units.mk (p : Ξ± Γ Ξ±).1 (p : Ξ± Γ Ξ±).2 p.prop.1 p.prop.2
/-- In a `DivisionCommMonoid`, `Equiv.inv` is a `MulEquiv`. There is a variant of this
`MulEquiv.inv' G : G β* Gα΅α΅α΅` for the non-commutative case. -/
@[to_additive (attr := simps apply)
/-- When the `AddGroup` is commutative, `Equiv.neg` is an `AddEquiv`. -/]
def MulEquiv.inv (G : Type*) [DivisionCommMonoid G] : G β* G :=
{ Equiv.inv G with toFun := Inv.inv, invFun := Inv.inv, map_mul' := mul_inv }
@[to_additive (attr := simp)]
theorem MulEquiv.inv_symm (G : Type*) [DivisionCommMonoid G] :
(MulEquiv.inv G).symm = MulEquiv.inv G :=
rfl
section EquivLike
variable [Monoid M] [Monoid N] [EquivLike F M N] [MulEquivClass F M N] (f : F) {x : M}
-- Higher priority to take over the non-additivisable `isUnit_map_iff`
@[to_additive (attr := simp high)]
lemma MulEquiv.isUnit_map : IsUnit (f x) β IsUnit x where
mp hx := by
simpa using hx.map <| MonoidHom.mk β¨EquivLike.inv f, EquivLike.injective f <| by simpβ©
fun x y β¦ EquivLike.injective f <| by simp
mpr := .map f
@[instance] theorem isLocalHom_equiv : IsLocalHom f where map_nonunit := by simp
end EquivLike
|
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.
|
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.
|
Pullbacks.lean
|
/-
Copyright (c) 2025 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.HasPullback
/-!
# Pullbacks in functor categories
We prove the isomorphism `(pullback f g).obj d β
pullback (f.app d) (g.app d)`.
-/
universe vβ vβ uβ uβ
namespace CategoryTheory.Limits
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D] {F G H : D β₯€ C}
section Pullback
variable [HasPullbacks C]
/-- Evaluating a pullback amounts to taking the pullback of the evaluations. -/
noncomputable def pullbackObjIso (f : F βΆ H) (g : G βΆ H) (d : D) :
(pullback f g).obj d β
pullback (f.app d) (g.app d) :=
limitObjIsoLimitCompEvaluation (cospan f g) d βͺβ« HasLimit.isoOfNatIso (diagramIsoCospan _)
@[reassoc (attr := simp)]
theorem pullbackObjIso_hom_comp_fst (f : F βΆ H) (g : G βΆ H) (d : D) :
(pullbackObjIso f g d).hom β« pullback.fst (f.app d) (g.app d) = (pullback.fst f g).app d := by
simp [pullbackObjIso]
@[reassoc (attr := simp)]
theorem pullbackObjIso_hom_comp_snd (f : F βΆ H) (g : G βΆ H) (d : D) :
(pullbackObjIso f g d).hom β« pullback.snd (f.app d) (g.app d) = (pullback.snd f g).app d := by
simp [pullbackObjIso]
@[reassoc (attr := simp)]
theorem pullbackObjIso_inv_comp_fst (f : F βΆ H) (g : G βΆ H) (d : D) :
(pullbackObjIso f g d).inv β« (pullback.fst f g).app d = pullback.fst (f.app d) (g.app d) := by
simp [pullbackObjIso]
@[reassoc (attr := simp)]
theorem pullbackObjIso_inv_comp_snd (f : F βΆ H) (g : G βΆ H) (d : D) :
(pullbackObjIso f g d).inv β« (pullback.snd f g).app d = pullback.snd (f.app d) (g.app d) := by
simp [pullbackObjIso]
end Pullback
section Pushout
variable [HasPushouts C]
/-- Evaluating a pushout amounts to taking the pushout of the evaluations. -/
noncomputable def pushoutObjIso (f : F βΆ G) (g : F βΆ H) (d : D) :
(pushout f g).obj d β
pushout (f.app d) (g.app d) :=
colimitObjIsoColimitCompEvaluation (span f g) d βͺβ« HasColimit.isoOfNatIso (diagramIsoSpan _)
@[reassoc (attr := simp)]
theorem inl_comp_pushoutObjIso_hom (f : F βΆ G) (g : F βΆ H) (d : D) :
(pushout.inl f g).app d β« (pushoutObjIso f g d).hom = pushout.inl (f.app d) (g.app d) := by
simp [pushoutObjIso]
@[reassoc (attr := simp)]
theorem inr_comp_pushoutObjIso_hom (f : F βΆ G) (g : F βΆ H) (d : D) :
(pushout.inr f g).app d β« (pushoutObjIso f g d).hom = pushout.inr (f.app d) (g.app d) := by
simp [pushoutObjIso]
@[reassoc (attr := simp)]
theorem inl_comp_pushoutObjIso_inv (f : F βΆ G) (g : F βΆ H) (d : D) :
pushout.inl (f.app d) (g.app d) β« (pushoutObjIso f g d).inv = (pushout.inl f g).app d := by
simp [pushoutObjIso]
@[reassoc (attr := simp)]
theorem inr_comp_pushoutObjIso_inv (f : F βΆ G) (g : F βΆ H) (d : D) :
pushout.inr (f.app d) (g.app d) β« (pushoutObjIso f g d).inv = (pushout.inr f g).app d := by
simp [pushoutObjIso]
end Pushout
end CategoryTheory.Limits
|
ReflectsIso.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.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
/-!
A `forgetβ C D` forgetful functor between concrete categories `C` and `D`
whose forgetful functors both reflect isomorphisms, itself reflects isomorphisms.
-/
universe u
namespace CategoryTheory
instance : (forget (Type u)).ReflectsIsomorphisms where reflects _ _ _ {i} := i
variable (C : Type (u + 1)) [Category C] [HasForget.{u} C]
variable (D : Type (u + 1)) [Category D] [HasForget.{u} D]
-- This should not be an instance, as it causes a typeclass loop
-- with `CategoryTheory.hasForgetToType`.
/-- A `forgetβ C D` forgetful functor between concrete categories `C` and `D`
where `forget C` reflects isomorphisms, itself reflects isomorphisms.
-/
theorem reflectsIsomorphisms_forgetβ [HasForgetβ C D] [(forget C).ReflectsIsomorphisms] :
(forgetβ C D).ReflectsIsomorphisms :=
{ reflects := fun X Y f {i} => by
haveI i' : IsIso ((forget D).map ((forgetβ C D).map f)) := Functor.map_isIso (forget D) _
haveI : IsIso ((forget C).map f) := by
have := @HasForgetβ.forget_comp C D
rwa [β this]
apply isIso_of_reflects_iso f (forget C) }
end CategoryTheory
|
Prufer.lean
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Group.Action.Pointwise.Set.Basic
import Mathlib.Dynamics.FixedPoints.Basic
/-!
# Results about pointwise operations on sets with iteration.
-/
open Pointwise
open Set Function
/-- Let `n : β€` and `s` a subset of a commutative group `G` that is invariant under preimage for
the map `x β¦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements
`g : G` such that `g^(n^j) = 1` for some `j : β`. (This subgroup is called the PrΓΌfer subgroup when
`G` is the `Circle` and `n` is prime.) -/
@[to_additive
/-- Let `n : β€` and `s` a subset of an additive commutative group `G` that is invariant
under preimage for the map `x β¦ n β’ x`. Then `s` is invariant under the pointwise action of
the additive subgroup of elements `g : G` such that `(n^j) β’ g = 0` for some `j : β`.
(This additive subgroup is called the PrΓΌfer subgroup when `G` is the `AddCircle` and `n` is
prime.) -/]
theorem smul_eq_self_of_preimage_zpow_eq_self {G : Type*} [CommGroup G] {n : β€} {s : Set G}
(hs : (fun x => x ^ n) β»ΒΉ' s = s) {g : G} {j : β} (hg : g ^ n ^ j = 1) : g β’ s = s := by
suffices β {g' : G} (_ : g' ^ n ^ j = 1), g' β’ s β s by
refine le_antisymm (this hg) ?_
conv_lhs => rw [β smul_inv_smul g s]
replace hg : gβ»ΒΉ ^ n ^ j = 1 := by rw [inv_zpow, hg, inv_one]
simpa only [le_eq_subset, smul_set_subset_smul_set_iff] using this hg
rw [(IsFixedPt.preimage_iterate hs j : (zpowGroupHom n)^[j] β»ΒΉ' s = s).symm]
rintro g' hg' - β¨y, hy, rflβ©
change (zpowGroupHom n)^[j] (g' * y) β s
replace hg' : (zpowGroupHom n)^[j] g' = 1 := by simpa [zpowGroupHom]
rwa [iterate_map_mul, hg', one_mul]
|
Basic.lean
|
/-
Copyright (c) 2025 Yunzhou Xie. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yunzhou Xie, Jujian Zhang
-/
import Mathlib.Algebra.Azumaya.Defs
import Mathlib.LinearAlgebra.Matrix.ToLin
import Mathlib.RingTheory.Finiteness.Basic
import Mathlib.GroupTheory.GroupAction.Hom
/-!
# Basic properties of Azumaya algebras
In this file we prove basic facts about Azumaya algebras such as `R` is an Azumaya algebra
over itself where `R` is a commutative ring.
## Main Results
- `IsAzumaya.id`: `R` is an Azumaya algebra over itself.
- `IsAzumaya.ofAlgEquiv`: If `A` is an Azumaya algebra over `R` and `A` is isomorphic to `B`
as an `R`-algebra, then `B` is an Azumaya algebra over `R`.
## Tags
Noncommutative algebra, Azumaya algebra, Brauer Group
-/
open scoped TensorProduct
open MulOpposite
namespace IsAzumaya
variable (R A B : Type*) [CommSemiring R] [Ring A] [Ring B] [Algebra R A] [Algebra R B]
lemma AlgHom.mulLeftRight_bij [h : IsAzumaya R A] :
Function.Bijective (AlgHom.mulLeftRight R A) := h.bij
/-- The "canonical" isomorphism between `R β Rα΅α΅` and `End R R` which is equal
to `AlgHom.mulLeftRight R R`. -/
abbrev tensorEquivEnd : R β[R] Rα΅α΅α΅ ββ[R] Module.End R R :=
Algebra.TensorProduct.lid R Rα΅α΅α΅|>.trans <| .moduleEndSelf R
lemma coe_tensorEquivEnd : tensorEquivEnd R = AlgHom.mulLeftRight R R := by
ext; simp
instance id : IsAzumaya R R where
bij := by rw [β coe_tensorEquivEnd]; exact tensorEquivEnd R |>.bijective
/--
The following diagram commutes:
```
e β eα΅α΅
A β Aα΅α΅α΅ ------------> B β Bα΅α΅α΅
| |
| |
| mulLeftRight R A | mulLeftRight R B
| |
V V
End R A ------------> End R B
e.conj
```
-/
lemma mulLeftRight_comp_congr (e : A ββ[R] B) :
(AlgHom.mulLeftRight R B).comp (Algebra.TensorProduct.congr e e.op).toAlgHom =
(e.toLinearEquiv.algConj R).toAlgHom.comp (AlgHom.mulLeftRight R A) := by
ext <;> simp
theorem of_AlgEquiv (e : A ββ[R] B) [IsAzumaya R A] : IsAzumaya R B :=
let _ : Module.Projective R B := .of_equiv e.toLinearEquiv
let _ : FaithfulSMul R B := .of_injective e e.injective
let _ : Module.Finite R B := .equiv e.toLinearEquiv
β¨Function.Bijective.of_comp_iff (AlgHom.mulLeftRight R B)
(Algebra.TensorProduct.congr e e.op).bijective |>.1 <| by
rw [β AlgEquiv.coe_algHom, β AlgHom.coe_comp, mulLeftRight_comp_congr]
simp [AlgHom.mulLeftRight_bij]β©
end IsAzumaya
|
Equalizers.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Shapes.SplitCoequalizer
import Mathlib.CategoryTheory.Limits.Shapes.SplitEqualizer
import Mathlib.CategoryTheory.Limits.Preserves.Basic
/-!
# Preserving (co)equalizers
Constructions to relate the notions of preserving (co)equalizers and reflecting (co)equalizers
to concrete (co)forks.
In particular, we show that `equalizerComparison f g G` is an isomorphism iff `G` preserves
the limit of the parallel pair `f,g`, as well as the dual result.
-/
noncomputable section
universe w vβ vβ uβ uβ
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
variable {C : Type uβ} [Category.{vβ} C]
variable {D : Type uβ} [Category.{vβ} D]
variable (G : C β₯€ D)
namespace CategoryTheory.Limits
section Equalizers
variable {X Y Z : C} {f g : X βΆ Y} {h : Z βΆ X} (w : h β« f = h β« g)
/-- The map of a fork is a limit iff the fork consisting of the mapped morphisms is a limit. This
essentially lets us commute `Fork.ofΞΉ` with `Functor.mapCone`.
-/
def isLimitMapConeForkEquiv :
IsLimit (G.mapCone (Fork.ofΞΉ h w)) β
IsLimit (Fork.ofΞΉ (G.map h) (by simp only [β G.map_comp, w]) : Fork (G.map f) (G.map g)) :=
(IsLimit.postcomposeHomEquiv (diagramIsoParallelPair _) _).symm.trans
(IsLimit.equivIsoLimit (Fork.ext (Iso.refl _) (by simp [Fork.ΞΉ])))
/-- The property of preserving equalizers expressed in terms of forks. -/
def isLimitForkMapOfIsLimit [PreservesLimit (parallelPair f g) G] (l : IsLimit (Fork.ofΞΉ h w)) :
IsLimit (Fork.ofΞΉ (G.map h) (by simp only [β G.map_comp, w]) : Fork (G.map f) (G.map g)) :=
isLimitMapConeForkEquiv G w (isLimitOfPreserves G l)
/-- The property of reflecting equalizers expressed in terms of forks. -/
def isLimitOfIsLimitForkMap [ReflectsLimit (parallelPair f g) G]
(l : IsLimit (Fork.ofΞΉ (G.map h) (by simp only [β G.map_comp, w]) : Fork (G.map f) (G.map g))) :
IsLimit (Fork.ofΞΉ h w) :=
isLimitOfReflects G ((isLimitMapConeForkEquiv G w).symm l)
variable (f g)
variable [HasEqualizer f g]
/--
If `G` preserves equalizers and `C` has them, then the fork constructed of the mapped morphisms of
a fork is a limit.
-/
def isLimitOfHasEqualizerOfPreservesLimit [PreservesLimit (parallelPair f g) G] :
IsLimit (Fork.ofΞΉ
(G.map (equalizer.ΞΉ f g)) (by simp only [β G.map_comp]; rw [equalizer.condition]) :
Fork (G.map f) (G.map g)) :=
isLimitForkMapOfIsLimit G _ (equalizerIsEqualizer f g)
variable [HasEqualizer (G.map f) (G.map g)]
/-- If the equalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the
equalizer of `(f,g)`.
-/
lemma PreservesEqualizer.of_iso_comparison [i : IsIso (equalizerComparison f g G)] :
PreservesLimit (parallelPair f g) G := by
apply preservesLimit_of_preserves_limit_cone (equalizerIsEqualizer f g)
apply (isLimitMapConeForkEquiv _ _).symm _
exact @IsLimit.ofPointIso _ _ _ _ _ _ _ (limit.isLimit (parallelPair (G.map f) (G.map g))) i
variable [PreservesLimit (parallelPair f g) G]
/--
If `G` preserves the equalizer of `(f,g)`, then the equalizer comparison map for `G` at `(f,g)` is
an isomorphism.
-/
def PreservesEqualizer.iso : G.obj (equalizer f g) β
equalizer (G.map f) (G.map g) :=
IsLimit.conePointUniqueUpToIso (isLimitOfHasEqualizerOfPreservesLimit G f g) (limit.isLimit _)
@[simp]
theorem PreservesEqualizer.iso_hom :
(PreservesEqualizer.iso G f g).hom = equalizerComparison f g G :=
rfl
@[simp]
theorem PreservesEqualizer.iso_inv_ΞΉ :
(PreservesEqualizer.iso G f g).inv β« G.map (equalizer.ΞΉ f g) =
equalizer.ΞΉ (G.map f) (G.map g) := by
rw [β Iso.cancel_iso_hom_left (PreservesEqualizer.iso G f g), β Category.assoc, Iso.hom_inv_id]
simp
instance : IsIso (equalizerComparison f g G) := by
rw [β PreservesEqualizer.iso_hom]
infer_instance
end Equalizers
section Coequalizers
variable {X Y Z : C} {f g : X βΆ Y} {h : Y βΆ Z} (w : f β« h = g β« h)
/-- The map of a cofork is a colimit iff the cofork consisting of the mapped morphisms is a colimit.
This essentially lets us commute `Cofork.ofΟ` with `Functor.mapCocone`.
-/
def isColimitMapCoconeCoforkEquiv :
IsColimit (G.mapCocone (Cofork.ofΟ h w)) β
IsColimit
(Cofork.ofΟ (G.map h) (by simp only [β G.map_comp, w]) : Cofork (G.map f) (G.map g)) :=
(IsColimit.precomposeInvEquiv (diagramIsoParallelPair _) _).symm.trans <|
IsColimit.equivIsoColimit <|
Cofork.ext (Iso.refl _) <| by
dsimp only [Cofork.Ο, Cofork.ofΟ_ΞΉ_app]
dsimp; rw [Category.comp_id, Category.id_comp]
/-- The property of preserving coequalizers expressed in terms of coforks. -/
def isColimitCoforkMapOfIsColimit [PreservesColimit (parallelPair f g) G]
(l : IsColimit (Cofork.ofΟ h w)) :
IsColimit
(Cofork.ofΟ (G.map h) (by simp only [β G.map_comp, w]) : Cofork (G.map f) (G.map g)) :=
isColimitMapCoconeCoforkEquiv G w (isColimitOfPreserves G l)
/-- The property of reflecting coequalizers expressed in terms of coforks. -/
def isColimitOfIsColimitCoforkMap [ReflectsColimit (parallelPair f g) G]
(l :
IsColimit
(Cofork.ofΟ (G.map h) (by simp only [β G.map_comp, w]) : Cofork (G.map f) (G.map g))) :
IsColimit (Cofork.ofΟ h w) :=
isColimitOfReflects G ((isColimitMapCoconeCoforkEquiv G w).symm l)
variable (f g)
variable [HasCoequalizer f g]
/--
If `G` preserves coequalizers and `C` has them, then the cofork constructed of the mapped morphisms
of a cofork is a colimit.
-/
def isColimitOfHasCoequalizerOfPreservesColimit [PreservesColimit (parallelPair f g) G] :
IsColimit (Cofork.ofΟ (G.map (coequalizer.Ο f g)) (by
simp only [β G.map_comp]; rw [coequalizer.condition]) : Cofork (G.map f) (G.map g)) :=
isColimitCoforkMapOfIsColimit G _ (coequalizerIsCoequalizer f g)
variable [HasCoequalizer (G.map f) (G.map g)]
/-- If the coequalizer comparison map for `G` at `(f,g)` is an isomorphism, then `G` preserves the
coequalizer of `(f,g)`.
-/
lemma of_iso_comparison [i : IsIso (coequalizerComparison f g G)] :
PreservesColimit (parallelPair f g) G := by
apply preservesColimit_of_preserves_colimit_cocone (coequalizerIsCoequalizer f g)
apply (isColimitMapCoconeCoforkEquiv _ _).symm _
exact
@IsColimit.ofPointIso _ _ _ _ _ _ _ (colimit.isColimit (parallelPair (G.map f) (G.map g))) i
variable [PreservesColimit (parallelPair f g) G]
/--
If `G` preserves the coequalizer of `(f,g)`, then the coequalizer comparison map for `G` at `(f,g)`
is an isomorphism.
-/
def PreservesCoequalizer.iso : coequalizer (G.map f) (G.map g) β
G.obj (coequalizer f g) :=
IsColimit.coconePointUniqueUpToIso (colimit.isColimit _)
(isColimitOfHasCoequalizerOfPreservesColimit G f g)
@[simp]
theorem PreservesCoequalizer.iso_hom :
(PreservesCoequalizer.iso G f g).hom = coequalizerComparison f g G :=
rfl
instance : IsIso (coequalizerComparison f g G) := by
rw [β PreservesCoequalizer.iso_hom]
infer_instance
instance map_Ο_epi : Epi (G.map (coequalizer.Ο f g)) :=
β¨fun {W} h k => by
rw [β ΞΉ_comp_coequalizerComparison]
haveI : Epi (coequalizer.Ο (G.map f) (G.map g) β« coequalizerComparison f g G) := by
apply epi_comp
apply (cancel_epi _).1β©
@[reassoc]
theorem map_Ο_preserves_coequalizer_inv :
G.map (coequalizer.Ο f g) β« (PreservesCoequalizer.iso G f g).inv =
coequalizer.Ο (G.map f) (G.map g) := by
rw [β ΞΉ_comp_coequalizerComparison_assoc, β PreservesCoequalizer.iso_hom, Iso.hom_inv_id,
comp_id]
@[reassoc]
theorem map_Ο_preserves_coequalizer_inv_desc {W : D} (k : G.obj Y βΆ W)
(wk : G.map f β« k = G.map g β« k) : G.map (coequalizer.Ο f g) β«
(PreservesCoequalizer.iso G f g).inv β« coequalizer.desc k wk = k := by
rw [β Category.assoc, map_Ο_preserves_coequalizer_inv, coequalizer.Ο_desc]
@[reassoc]
theorem map_Ο_preserves_coequalizer_inv_colimMap {X' Y' : D} (f' g' : X' βΆ Y')
[HasCoequalizer f' g'] (p : G.obj X βΆ X') (q : G.obj Y βΆ Y') (wf : G.map f β« q = p β« f')
(wg : G.map g β« q = p β« g') :
G.map (coequalizer.Ο f g) β«
(PreservesCoequalizer.iso G f g).inv β«
colimMap (parallelPairHom (G.map f) (G.map g) f' g' p q wf wg) =
q β« coequalizer.Ο f' g' := by
rw [β Category.assoc, map_Ο_preserves_coequalizer_inv, ΞΉ_colimMap, parallelPairHom_app_one]
@[reassoc]
theorem map_Ο_preserves_coequalizer_inv_colimMap_desc {X' Y' : D} (f' g' : X' βΆ Y')
[HasCoequalizer f' g'] (p : G.obj X βΆ X') (q : G.obj Y βΆ Y') (wf : G.map f β« q = p β« f')
(wg : G.map g β« q = p β« g') {Z' : D} (h : Y' βΆ Z') (wh : f' β« h = g' β« h) :
G.map (coequalizer.Ο f g) β«
(PreservesCoequalizer.iso G f g).inv β«
colimMap (parallelPairHom (G.map f) (G.map g) f' g' p q wf wg) β« coequalizer.desc h wh =
q β« h := by
slice_lhs 1 3 => rw [map_Ο_preserves_coequalizer_inv_colimMap]
slice_lhs 2 3 => rw [coequalizer.Ο_desc]
/-- Any functor preserves coequalizers of split pairs. -/
instance (priority := 1) preservesSplitCoequalizers (f g : X βΆ Y) [HasSplitCoequalizer f g] :
PreservesColimit (parallelPair f g) G := by
apply
preservesColimit_of_preserves_colimit_cocone
(HasSplitCoequalizer.isSplitCoequalizer f g).isCoequalizer
apply
(isColimitMapCoconeCoforkEquiv G _).symm
((HasSplitCoequalizer.isSplitCoequalizer f g).map G).isCoequalizer
instance (priority := 1) preservesSplitEqualizers (f g : X βΆ Y) [HasSplitEqualizer f g] :
PreservesLimit (parallelPair f g) G := by
apply
preservesLimit_of_preserves_limit_cone
(HasSplitEqualizer.isSplitEqualizer f g).isEqualizer
apply
(isLimitMapConeForkEquiv G _).symm
((HasSplitEqualizer.isSplitEqualizer f g).map G).isEqualizer
end Coequalizers
end CategoryTheory.Limits
|
Four.lean
|
/-
Copyright (c) 2020 Paul van Wamelen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Paul van Wamelen
-/
import Mathlib.Data.Nat.Factors
import Mathlib.NumberTheory.FLT.Basic
import Mathlib.NumberTheory.PythagoreanTriples
import Mathlib.RingTheory.Coprime.Lemmas
import Mathlib.Tactic.LinearCombination
/-!
# Fermat's Last Theorem for the case n = 4
There are no non-zero integers `a`, `b` and `c` such that `a ^ 4 + b ^ 4 = c ^ 4`.
-/
assert_not_exists TwoSidedIdeal
noncomputable section
/-- Shorthand for three non-zero integers `a`, `b`, and `c` satisfying `a ^ 4 + b ^ 4 = c ^ 2`.
We will show that no integers satisfy this equation. Clearly Fermat's Last theorem for n = 4
follows. -/
def Fermat42 (a b c : β€) : Prop :=
a β 0 β§ b β 0 β§ a ^ 4 + b ^ 4 = c ^ 2
namespace Fermat42
theorem comm {a b c : β€} : Fermat42 a b c β Fermat42 b a c := by
delta Fermat42
rw [add_comm]
tauto
theorem mul {a b c k : β€} (hk0 : k β 0) :
Fermat42 a b c β Fermat42 (k * a) (k * b) (k ^ 2 * c) := by
delta Fermat42
constructor
Β· intro f42
constructor
Β· exact mul_ne_zero hk0 f42.1
constructor
Β· exact mul_ne_zero hk0 f42.2.1
Β· have H : a ^ 4 + b ^ 4 = c ^ 2 := f42.2.2
linear_combination k ^ 4 * H
Β· intro f42
constructor
Β· exact right_ne_zero_of_mul f42.1
constructor
Β· exact right_ne_zero_of_mul f42.2.1
apply (mul_right_inj' (pow_ne_zero 4 hk0)).mp
linear_combination f42.2.2
theorem ne_zero {a b c : β€} (h : Fermat42 a b c) : c β 0 := by
apply ne_zero_pow two_ne_zero _; apply ne_of_gt
rw [β h.2.2, (by ring : a ^ 4 + b ^ 4 = (a ^ 2) ^ 2 + (b ^ 2) ^ 2)]
exact
add_pos (sq_pos_of_ne_zero (pow_ne_zero 2 h.1)) (sq_pos_of_ne_zero (pow_ne_zero 2 h.2.1))
/-- We say a solution to `a ^ 4 + b ^ 4 = c ^ 2` is minimal if there is no other solution with
a smaller `c` (in absolute value). -/
def Minimal (a b c : β€) : Prop :=
Fermat42 a b c β§ β a1 b1 c1 : β€, Fermat42 a1 b1 c1 β Int.natAbs c β€ Int.natAbs c1
/-- if we have a solution to `a ^ 4 + b ^ 4 = c ^ 2` then there must be a minimal one. -/
theorem exists_minimal {a b c : β€} (h : Fermat42 a b c) : β a0 b0 c0, Minimal a0 b0 c0 := by
classical
let S : Set β := { n | β s : β€ Γ β€ Γ β€, Fermat42 s.1 s.2.1 s.2.2 β§ n = Int.natAbs s.2.2 }
have S_nonempty : S.Nonempty := by
use Int.natAbs c
rw [Set.mem_setOf_eq]
use β¨a, β¨b, cβ©β©
let m : β := Nat.find S_nonempty
have m_mem : m β S := Nat.find_spec S_nonempty
rcases m_mem with β¨s0, hs0, hs1β©
use s0.1, s0.2.1, s0.2.2, hs0
intro a1 b1 c1 h1
rw [β hs1]
apply Nat.find_min'
use β¨a1, β¨b1, c1β©β©
/-- a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` must have `a` and `b` coprime. -/
theorem coprime_of_minimal {a b c : β€} (h : Minimal a b c) : IsCoprime a b := by
apply Int.isCoprime_iff_gcd_eq_one.mpr
by_contra hab
obtain β¨p, hp, hpa, hpbβ© := Nat.Prime.not_coprime_iff_dvd.mp hab
obtain β¨a1, rflβ© := Int.natCast_dvd.mpr hpa
obtain β¨b1, rflβ© := Int.natCast_dvd.mpr hpb
have hpc : (p : β€) ^ 2 β£ c := by
rw [β Int.pow_dvd_pow_iff two_ne_zero, β h.1.2.2]
apply Dvd.intro (a1 ^ 4 + b1 ^ 4)
ring
obtain β¨c1, rflβ© := hpc
have hf : Fermat42 a1 b1 c1 :=
(Fermat42.mul (Int.natCast_ne_zero.mpr (Nat.Prime.ne_zero hp))).mpr h.1
apply Nat.le_lt_asymm (h.2 _ _ _ hf)
rw [Int.natAbs_mul, lt_mul_iff_one_lt_left, Int.natAbs_pow, Int.natAbs_natCast]
Β· exact Nat.one_lt_pow two_ne_zero (Nat.Prime.one_lt hp)
Β· exact Nat.pos_of_ne_zero (Int.natAbs_ne_zero.2 (ne_zero hf))
/-- We can swap `a` and `b` in a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2`. -/
theorem minimal_comm {a b c : β€} : Minimal a b c β Minimal b a c := fun β¨h1, h2β© =>
β¨Fermat42.comm.mp h1, h2β©
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has positive `c`. -/
theorem neg_of_minimal {a b c : β€} : Minimal a b c β Minimal a b (-c) := by
rintro β¨β¨ha, hb, heqβ©, h2β©
constructor
Β· apply And.intro ha (And.intro hb _)
rw [heq]
exact (neg_sq c).symm
rwa [Int.natAbs_neg c]
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd. -/
theorem exists_odd_minimal {a b c : β€} (h : Fermat42 a b c) :
β a0 b0 c0, Minimal a0 b0 c0 β§ a0 % 2 = 1 := by
obtain β¨a0, b0, c0, hfβ© := exists_minimal h
rcases Int.emod_two_eq_zero_or_one a0 with hap | hap
Β· rcases Int.emod_two_eq_zero_or_one b0 with hbp | hbp
Β· exfalso
have h1 : 2 β£ (Int.gcd a0 b0 : β€) :=
Int.dvd_coe_gcd (Int.dvd_of_emod_eq_zero hap) (Int.dvd_of_emod_eq_zero hbp)
rw [Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal hf)] at h1
revert h1
decide
Β· exact β¨b0, β¨a0, β¨c0, minimal_comm hf, hbpβ©β©β©
exact β¨a0, β¨b0, β¨c0, hf, hapβ©β©β©
/-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has
`a` odd and `c` positive. -/
theorem exists_pos_odd_minimal {a b c : β€} (h : Fermat42 a b c) :
β a0 b0 c0, Minimal a0 b0 c0 β§ a0 % 2 = 1 β§ 0 < c0 := by
obtain β¨a0, b0, c0, hf, hcβ© := exists_odd_minimal h
rcases lt_trichotomy 0 c0 with (h1 | h1 | h1)
Β· use a0, b0, c0
Β· exfalso
exact ne_zero hf.1 h1.symm
Β· use a0, b0, -c0, neg_of_minimal hf, hc
exact neg_pos.mpr h1
end Fermat42
theorem Int.isCoprime_of_sq_sum {r s : β€} (h2 : IsCoprime s r) : IsCoprime (r ^ 2 + s ^ 2) r := by
rw [sq, sq]
exact (IsCoprime.mul_left h2 h2).mul_add_left_left r
theorem Int.isCoprime_of_sq_sum' {r s : β€} (h : IsCoprime r s) :
IsCoprime (r ^ 2 + s ^ 2) (r * s) := by
apply IsCoprime.mul_right (Int.isCoprime_of_sq_sum (isCoprime_comm.mp h))
rw [add_comm]; apply Int.isCoprime_of_sq_sum h
namespace Fermat42
-- If we have a solution to a ^ 4 + b ^ 4 = c ^ 2, we can construct a smaller one. This
-- implies there can't be a smallest solution.
theorem not_minimal {a b c : β€} (h : Minimal a b c) (ha2 : a % 2 = 1) (hc : 0 < c) : False := by
-- Use the fact that a ^ 2, b ^ 2, c form a pythagorean triple to obtain m and n such that
-- a ^ 2 = m ^ 2 - n ^ 2, b ^ 2 = 2 * m * n and c = m ^ 2 + n ^ 2
-- first the formula:
have ht : PythagoreanTriple (a ^ 2) (b ^ 2) c := by
delta PythagoreanTriple
linear_combination h.1.2.2
-- coprime requirement:
have h2 : Int.gcd (a ^ 2) (b ^ 2) = 1 :=
Int.isCoprime_iff_gcd_eq_one.mp (coprime_of_minimal h).pow
-- in order to reduce the possibilities we get from the classification of pythagorean triples
-- it helps if we know the parity of a ^ 2 (and the sign of c):
have ha22 : a ^ 2 % 2 = 1 := by
rw [sq, Int.mul_emod, ha2]
decide
obtain β¨m, n, ht1, ht2, ht3, ht4, ht5, ht6β© := ht.coprime_classification' h2 ha22 hc
-- Now a, n, m form a pythagorean triple and so we can obtain r and s such that
-- a = r ^ 2 - s ^ 2, n = 2 * r * s and m = r ^ 2 + s ^ 2
-- formula:
have htt : PythagoreanTriple a n m := by
delta PythagoreanTriple
linear_combination ht1
-- a and n are coprime, because a ^ 2 = m ^ 2 - n ^ 2 and m and n are coprime.
have h3 : Int.gcd a n = 1 := by
apply Int.isCoprime_iff_gcd_eq_one.mp
apply @IsCoprime.of_mul_left_left _ _ _ a
rw [β sq, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + -n * n)]
exact (Int.isCoprime_iff_gcd_eq_one.mpr ht4).pow_left.add_mul_right_left (-n)
-- m is positive because b is non-zero and b ^ 2 = 2 * m * n and we already have 0 β€ m.
have hb20 : b ^ 2 β 0 := mt pow_eq_zero h.1.2.1
have h4 : 0 < m := by
apply lt_of_le_of_ne ht6
rintro rfl
omega
obtain β¨r, s, _, htt2, htt3, htt4, htt5, htt6β© := htt.coprime_classification' h3 ha2 h4
-- Now use the fact that (b / 2) ^ 2 = m * r * s, and m, r and s are pairwise coprime to obtain
-- i, j and k such that m = i ^ 2, r = j ^ 2 and s = k ^ 2.
-- m and r * s are coprime because m = r ^ 2 + s ^ 2 and r and s are coprime.
have hcp : Int.gcd m (r * s) = 1 := by
rw [htt3]
exact Int.isCoprime_iff_gcd_eq_one.mp
(Int.isCoprime_of_sq_sum' (Int.isCoprime_iff_gcd_eq_one.mpr htt4))
-- b is even because b ^ 2 = 2 * m * n.
have hb2 : 2 β£ b := by
apply @Int.Prime.dvd_pow' _ 2 _ Nat.prime_two
rw [ht2, mul_assoc]
exact dvd_mul_right 2 (m * n)
obtain β¨b', hb2'β© := hb2
have hs : b' ^ 2 = m * (r * s) := by
apply (mul_right_inj' (by simp : (4 : β€) β 0)).mp
linear_combination (-b - 2 * b') * hb2' + ht2 + 2 * m * htt2
have hrsz : r * s β 0 := by grind
have h2b0 : b' β 0 := by grind
obtain β¨i, hiβ© := Int.sq_of_gcd_eq_one hcp hs.symm
-- use m is positive to exclude m = - i ^ 2
have hi' : Β¬m = -i ^ 2 := by
by_contra h1
have hit : -i ^ 2 β€ 0 := neg_nonpos.mpr (sq_nonneg i)
rw [β h1] at hit
apply absurd h4 (not_lt.mpr hit)
replace hi : m = i ^ 2 := Or.resolve_right hi hi'
rw [mul_comm] at hs
rw [Int.gcd_comm] at hcp
-- obtain d such that r * s = d ^ 2
obtain β¨d, hdβ© := Int.sq_of_gcd_eq_one hcp hs.symm
-- (b / 2) ^ 2 and m are positive so r * s is positive
have hd' : Β¬r * s = -d ^ 2 := by
by_contra h1
rw [h1] at hs
have h2 : b' ^ 2 β€ 0 := by
rw [hs, (by ring : -d ^ 2 * m = -(d ^ 2 * m))]
exact neg_nonpos.mpr ((mul_nonneg_iff_of_pos_right h4).mpr (sq_nonneg d))
have h2' : 0 β€ b' ^ 2 := by apply sq_nonneg b'
exact absurd (lt_of_le_of_ne h2' (Ne.symm (pow_ne_zero _ h2b0))) (not_lt.mpr h2)
replace hd : r * s = d ^ 2 := Or.resolve_right hd hd'
-- r = +/- j ^ 2
obtain β¨j, hjβ© := Int.sq_of_gcd_eq_one htt4 hd
have hj0 : j β 0 := by grind
rw [mul_comm] at hd
rw [Int.gcd_comm] at htt4
-- s = +/- k ^ 2
obtain β¨k, hkβ© := Int.sq_of_gcd_eq_one htt4 hd
have hk0 : k β 0 := by grind
have hj2 : r ^ 2 = j ^ 4 := by grind
have hk2 : s ^ 2 = k ^ 4 := by grind
-- from m = r ^ 2 + s ^ 2 we now get a new solution to a ^ 4 + b ^ 4 = c ^ 2:
have hh : i ^ 2 = j ^ 4 + k ^ 4 := by grind
have hn : n β 0 := by grind
-- and it has a smaller c: from c = m ^ 2 + n ^ 2 we see that m is smaller than c, and i ^ 2 = m.
have hic : Int.natAbs i < Int.natAbs c := by
apply Int.ofNat_lt.mp
rw [β Int.eq_natAbs_of_nonneg (le_of_lt hc)]
apply lt_of_le_of_lt (Int.natAbs_le_self_sq i)
rw [β hi, ht3]
apply lt_of_le_of_lt (Int.le_self_sq m)
exact lt_add_of_pos_right (m ^ 2) (sq_pos_of_ne_zero hn)
have hic' : Int.natAbs c β€ Int.natAbs i := by
apply h.2 j k i
exact β¨hj0, hk0, hh.symmβ©
apply absurd (not_le_of_gt hic) (not_not.mpr hic')
end Fermat42
theorem not_fermat_42 {a b c : β€} (ha : a β 0) (hb : b β 0) : a ^ 4 + b ^ 4 β c ^ 2 := by
intro h
obtain β¨a0, b0, c0, β¨hf, h2, hpβ©β© :=
Fermat42.exists_pos_odd_minimal (And.intro ha (And.intro hb h))
apply Fermat42.not_minimal hf h2 hp
/--
Fermat's Last Theorem for $n=4$: if `a b c : β` are all non-zero
then `a ^ 4 + b ^ 4 β c ^ 4`.
-/
theorem fermatLastTheoremFour : FermatLastTheoremFor 4 := by
rw [fermatLastTheoremFor_iff_int]
intro a b c ha hb _ heq
apply @not_fermat_42 _ _ (c ^ 2) ha hb
rw [heq]; ring
/--
To prove Fermat's Last Theorem, it suffices to prove it for odd prime exponents.
-/
theorem FermatLastTheorem.of_odd_primes
(hprimes : β p : β, Nat.Prime p β Odd p β FermatLastTheoremFor p) : FermatLastTheorem := by
intro n h
obtain hdvd | β¨p, hpprime, hdvd, hpoddβ© := Nat.four_dvd_or_exists_odd_prime_and_dvd_of_two_lt h
<;> apply FermatLastTheoremWith.mono hdvd
Β· exact fermatLastTheoremFour
Β· exact hprimes p hpprime hpodd
|
Measure.lean
|
/-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Group.Pointwise.Set.Card
import Mathlib.MeasureTheory.Group.Action
import Mathlib.MeasureTheory.Measure.Prod
import Mathlib.Topology.Algebra.Module.Equiv
import Mathlib.Topology.ContinuousMap.CocompactMap
import Mathlib.Topology.Algebra.ContinuousMonoidHom
/-!
# Measures on Groups
We develop some properties of measures on (topological) groups
* We define properties on measures: measures that are left or right invariant w.r.t. multiplication.
* We define the measure `ΞΌ.inv : A β¦ ΞΌ(Aβ»ΒΉ)` and show that it is right invariant iff
`ΞΌ` is left invariant.
* We define a class `IsHaarMeasure ΞΌ`, requiring that the measure `ΞΌ` is left-invariant, finite
on compact sets, and positive on open sets.
We also give analogues of all these notions in the additive world.
-/
noncomputable section
open scoped NNReal ENNReal Pointwise Topology
open Inv Set Function MeasureTheory.Measure Filter
variable {G H : Type*} [MeasurableSpace G] [MeasurableSpace H]
namespace MeasureTheory
section Mul
variable [Mul G] {ΞΌ : Measure G}
@[to_additive]
theorem map_mul_left_eq_self (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (g : G) :
map (g * Β·) ΞΌ = ΞΌ :=
IsMulLeftInvariant.map_mul_left_eq_self g
@[to_additive]
theorem map_mul_right_eq_self (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) : map (Β· * g) ΞΌ = ΞΌ :=
IsMulRightInvariant.map_mul_right_eq_self g
@[to_additive MeasureTheory.isAddLeftInvariant_smul]
instance isMulLeftInvariant_smul [IsMulLeftInvariant ΞΌ] (c : ββ₯0β) : IsMulLeftInvariant (c β’ ΞΌ) :=
β¨fun g => by rw [Measure.map_smul, map_mul_left_eq_self]β©
@[to_additive MeasureTheory.isAddRightInvariant_smul]
instance isMulRightInvariant_smul [IsMulRightInvariant ΞΌ] (c : ββ₯0β) :
IsMulRightInvariant (c β’ ΞΌ) :=
β¨fun g => by rw [Measure.map_smul, map_mul_right_eq_self]β©
@[to_additive MeasureTheory.isAddLeftInvariant_smul_nnreal]
instance isMulLeftInvariant_smul_nnreal [IsMulLeftInvariant ΞΌ] (c : ββ₯0) :
IsMulLeftInvariant (c β’ ΞΌ) :=
MeasureTheory.isMulLeftInvariant_smul (c : ββ₯0β)
@[to_additive MeasureTheory.isAddRightInvariant_smul_nnreal]
instance isMulRightInvariant_smul_nnreal [IsMulRightInvariant ΞΌ] (c : ββ₯0) :
IsMulRightInvariant (c β’ ΞΌ) :=
MeasureTheory.isMulRightInvariant_smul (c : ββ₯0β)
section MeasurableMul
variable [MeasurableMul G]
@[to_additive]
theorem measurePreserving_mul_left (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (g : G) :
MeasurePreserving (g * Β·) ΞΌ ΞΌ :=
β¨measurable_const_mul g, map_mul_left_eq_self ΞΌ gβ©
@[to_additive]
theorem MeasurePreserving.mul_left (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (g : G) {X : Type*}
[MeasurableSpace X] {ΞΌ' : Measure X} {f : X β G} (hf : MeasurePreserving f ΞΌ' ΞΌ) :
MeasurePreserving (fun x => g * f x) ΞΌ' ΞΌ :=
(measurePreserving_mul_left ΞΌ g).comp hf
@[to_additive]
theorem measurePreserving_mul_right (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) :
MeasurePreserving (Β· * g) ΞΌ ΞΌ :=
β¨measurable_mul_const g, map_mul_right_eq_self ΞΌ gβ©
@[to_additive]
theorem MeasurePreserving.mul_right (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) {X : Type*}
[MeasurableSpace X] {ΞΌ' : Measure X} {f : X β G} (hf : MeasurePreserving f ΞΌ' ΞΌ) :
MeasurePreserving (fun x => f x * g) ΞΌ' ΞΌ :=
(measurePreserving_mul_right ΞΌ g).comp hf
@[to_additive]
instance Subgroup.smulInvariantMeasure {G Ξ± : Type*} [Group G] [MulAction G Ξ±] [MeasurableSpace Ξ±]
{ΞΌ : Measure Ξ±} [SMulInvariantMeasure G Ξ± ΞΌ] (H : Subgroup G) : SMulInvariantMeasure H Ξ± ΞΌ :=
β¨fun y s hs => by convert SMulInvariantMeasure.measure_preimage_smul (ΞΌ := ΞΌ) (y : G) hsβ©
/-- An alternative way to prove that `ΞΌ` is left invariant under multiplication. -/
@[to_additive /-- An alternative way to prove that `ΞΌ` is left invariant under addition. -/]
theorem forall_measure_preimage_mul_iff (ΞΌ : Measure G) :
(β (g : G) (A : Set G), MeasurableSet A β ΞΌ ((fun h => g * h) β»ΒΉ' A) = ΞΌ A) β
IsMulLeftInvariant ΞΌ := by
trans β g, map (g * Β·) ΞΌ = ΞΌ
Β· simp_rw [Measure.ext_iff]
refine forall_congr' fun g => forall_congr' fun A => forall_congr' fun hA => ?_
rw [map_apply (measurable_const_mul g) hA]
exact β¨fun h => β¨hβ©, fun h => h.1β©
/-- An alternative way to prove that `ΞΌ` is right invariant under multiplication. -/
@[to_additive /-- An alternative way to prove that `ΞΌ` is right invariant under addition. -/]
theorem forall_measure_preimage_mul_right_iff (ΞΌ : Measure G) :
(β (g : G) (A : Set G), MeasurableSet A β ΞΌ ((fun h => h * g) β»ΒΉ' A) = ΞΌ A) β
IsMulRightInvariant ΞΌ := by
trans β g, map (Β· * g) ΞΌ = ΞΌ
Β· simp_rw [Measure.ext_iff]
refine forall_congr' fun g => forall_congr' fun A => forall_congr' fun hA => ?_
rw [map_apply (measurable_mul_const g) hA]
exact β¨fun h => β¨hβ©, fun h => h.1β©
@[to_additive]
instance Measure.prod.instIsMulLeftInvariant [IsMulLeftInvariant ΞΌ] [SFinite ΞΌ] {H : Type*}
[Mul H] {mH : MeasurableSpace H} {Ξ½ : Measure H} [MeasurableMul H] [IsMulLeftInvariant Ξ½]
[SFinite Ξ½] : IsMulLeftInvariant (ΞΌ.prod Ξ½) := by
constructor
rintro β¨g, hβ©
change map (Prod.map (g * Β·) (h * Β·)) (ΞΌ.prod Ξ½) = ΞΌ.prod Ξ½
rw [β map_prod_map _ _ (measurable_const_mul g) (measurable_const_mul h),
map_mul_left_eq_self ΞΌ g, map_mul_left_eq_self Ξ½ h]
@[to_additive]
instance Measure.prod.instIsMulRightInvariant [IsMulRightInvariant ΞΌ] [SFinite ΞΌ] {H : Type*}
[Mul H] {mH : MeasurableSpace H} {Ξ½ : Measure H} [MeasurableMul H] [IsMulRightInvariant Ξ½]
[SFinite Ξ½] : IsMulRightInvariant (ΞΌ.prod Ξ½) := by
constructor
rintro β¨g, hβ©
change map (Prod.map (Β· * g) (Β· * h)) (ΞΌ.prod Ξ½) = ΞΌ.prod Ξ½
rw [β map_prod_map _ _ (measurable_mul_const g) (measurable_mul_const h),
map_mul_right_eq_self ΞΌ g, map_mul_right_eq_self Ξ½ h]
@[to_additive]
theorem isMulLeftInvariant_map {H : Type*} [MeasurableSpace H] [Mul H] [MeasurableMul H]
[IsMulLeftInvariant ΞΌ] (f : G ββ* H) (hf : Measurable f) (h_surj : Surjective f) :
IsMulLeftInvariant (Measure.map f ΞΌ) := by
refine β¨fun h => ?_β©
rw [map_map (measurable_const_mul _) hf]
obtain β¨g, rflβ© := h_surj h
conv_rhs => rw [β map_mul_left_eq_self ΞΌ g]
rw [map_map hf (measurable_const_mul _)]
congr 2
ext y
simp only [comp_apply, map_mul]
end MeasurableMul
end Mul
section Semigroup
variable [Semigroup G] [MeasurableMul G] {ΞΌ : Measure G}
/-- The image of a left invariant measure under a left action is left invariant, assuming that
the action preserves multiplication. -/
@[to_additive /-- The image of a left invariant measure under a left additive action is left
invariant, assuming that the action preserves addition. -/]
theorem isMulLeftInvariant_map_smul
{Ξ±} [SMul Ξ± G] [SMulCommClass Ξ± G G] [MeasurableSpace Ξ±] [MeasurableSMul Ξ± G]
[IsMulLeftInvariant ΞΌ] (a : Ξ±) :
IsMulLeftInvariant (map (a β’ Β· : G β G) ΞΌ) :=
(forall_measure_preimage_mul_iff _).1 fun x _ hs =>
(smulInvariantMeasure_map_smul ΞΌ a).measure_preimage_smul x hs
/-- The image of a right invariant measure under a left action is right invariant, assuming that
the action preserves multiplication. -/
@[to_additive /-- The image of a right invariant measure under a left additive action is right
invariant, assuming that the action preserves addition. -/]
theorem isMulRightInvariant_map_smul
{Ξ±} [SMul Ξ± G] [SMulCommClass Ξ± Gα΅α΅α΅ G] [MeasurableSpace Ξ±] [MeasurableSMul Ξ± G]
[IsMulRightInvariant ΞΌ] (a : Ξ±) :
IsMulRightInvariant (map (a β’ Β· : G β G) ΞΌ) :=
(forall_measure_preimage_mul_right_iff _).1 fun x _ hs =>
(smulInvariantMeasure_map_smul ΞΌ a).measure_preimage_smul (MulOpposite.op x) hs
/-- The image of a left invariant measure under right multiplication is left invariant. -/
@[to_additive isMulLeftInvariant_map_add_right
/-- The image of a left invariant measure under right addition is left invariant. -/]
instance isMulLeftInvariant_map_mul_right [IsMulLeftInvariant ΞΌ] (g : G) :
IsMulLeftInvariant (map (Β· * g) ΞΌ) :=
isMulLeftInvariant_map_smul (MulOpposite.op g)
/-- The image of a right invariant measure under left multiplication is right invariant. -/
@[to_additive isMulRightInvariant_map_add_left
/-- The image of a right invariant measure under left addition is right invariant. -/]
instance isMulRightInvariant_map_mul_left [IsMulRightInvariant ΞΌ] (g : G) :
IsMulRightInvariant (map (g * Β·) ΞΌ) :=
isMulRightInvariant_map_smul g
end Semigroup
section DivInvMonoid
variable [DivInvMonoid G]
@[to_additive]
theorem map_div_right_eq_self (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) :
map (Β· / g) ΞΌ = ΞΌ := by simp_rw [div_eq_mul_inv, map_mul_right_eq_self ΞΌ gβ»ΒΉ]
end DivInvMonoid
section Group
variable [Group G] [MeasurableMul G]
@[to_additive]
theorem measurePreserving_div_right (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) :
MeasurePreserving (Β· / g) ΞΌ ΞΌ := by simp_rw [div_eq_mul_inv, measurePreserving_mul_right ΞΌ gβ»ΒΉ]
/-- We shorten this from `measure_preimage_mul_left`, since left invariant is the preferred option
for measures in this formalization. -/
@[to_additive (attr := simp)
/-- We shorten this from `measure_preimage_add_left`, since left invariant is the preferred option
for measures in this formalization. -/]
theorem measure_preimage_mul (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (g : G) (A : Set G) :
ΞΌ ((fun h => g * h) β»ΒΉ' A) = ΞΌ A :=
calc
ΞΌ ((fun h => g * h) β»ΒΉ' A) = map (fun h => g * h) ΞΌ A :=
((MeasurableEquiv.mulLeft g).map_apply A).symm
_ = ΞΌ A := by rw [map_mul_left_eq_self ΞΌ g]
@[to_additive (attr := simp)]
theorem measure_preimage_mul_right (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (g : G) (A : Set G) :
ΞΌ ((fun h => h * g) β»ΒΉ' A) = ΞΌ A :=
calc
ΞΌ ((fun h => h * g) β»ΒΉ' A) = map (fun h => h * g) ΞΌ A :=
((MeasurableEquiv.mulRight g).map_apply A).symm
_ = ΞΌ A := by rw [map_mul_right_eq_self ΞΌ g]
@[to_additive]
theorem map_mul_left_ae (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (x : G) :
Filter.map (fun h => x * h) (ae ΞΌ) = ae ΞΌ :=
((MeasurableEquiv.mulLeft x).map_ae ΞΌ).trans <| congr_arg ae <| map_mul_left_eq_self ΞΌ x
@[to_additive]
theorem map_mul_right_ae (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (x : G) :
Filter.map (fun h => h * x) (ae ΞΌ) = ae ΞΌ :=
((MeasurableEquiv.mulRight x).map_ae ΞΌ).trans <| congr_arg ae <| map_mul_right_eq_self ΞΌ x
@[to_additive]
theorem map_div_right_ae (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (x : G) :
Filter.map (fun t => t / x) (ae ΞΌ) = ae ΞΌ :=
((MeasurableEquiv.divRight x).map_ae ΞΌ).trans <| congr_arg ae <| map_div_right_eq_self ΞΌ x
@[to_additive]
theorem eventually_mul_left_iff (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (t : G) {p : G β Prop} :
(βα΅ x βΞΌ, p (t * x)) β βα΅ x βΞΌ, p x := by
conv_rhs => rw [Filter.Eventually, β map_mul_left_ae ΞΌ t]
rfl
@[to_additive]
theorem eventually_mul_right_iff (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (t : G) {p : G β Prop} :
(βα΅ x βΞΌ, p (x * t)) β βα΅ x βΞΌ, p x := by
conv_rhs => rw [Filter.Eventually, β map_mul_right_ae ΞΌ t]
rfl
@[to_additive]
theorem eventually_div_right_iff (ΞΌ : Measure G) [IsMulRightInvariant ΞΌ] (t : G) {p : G β Prop} :
(βα΅ x βΞΌ, p (x / t)) β βα΅ x βΞΌ, p x := by
conv_rhs => rw [Filter.Eventually, β map_div_right_ae ΞΌ t]
rfl
end Group
namespace Measure
-- TODO: noncomputable has to be specified explicitly. https://github.com/leanprover-community/mathlib4/issues/1074 (item 8)
/-- The measure `A β¦ ΞΌ (Aβ»ΒΉ)`, where `Aβ»ΒΉ` is the pointwise inverse of `A`. -/
@[to_additive /-- The measure `A β¦ ΞΌ (- A)`, where `- A` is the pointwise negation of `A`. -/]
protected noncomputable def inv [Inv G] (ΞΌ : Measure G) : Measure G :=
Measure.map inv ΞΌ
/-- A measure is invariant under negation if `- ΞΌ = ΞΌ`. Equivalently, this means that for all
measurable `A` we have `ΞΌ (- A) = ΞΌ A`, where `- A` is the pointwise negation of `A`. -/
class IsNegInvariant [Neg G] (ΞΌ : Measure G) : Prop where
neg_eq_self : ΞΌ.neg = ΞΌ
/-- A measure is invariant under inversion if `ΞΌβ»ΒΉ = ΞΌ`. Equivalently, this means that for all
measurable `A` we have `ΞΌ (Aβ»ΒΉ) = ΞΌ A`, where `Aβ»ΒΉ` is the pointwise inverse of `A`. -/
@[to_additive existing]
class IsInvInvariant [Inv G] (ΞΌ : Measure G) : Prop where
inv_eq_self : ΞΌ.inv = ΞΌ
section Inv
variable [Inv G]
@[to_additive]
theorem inv_def (ΞΌ : Measure G) : ΞΌ.inv = Measure.map inv ΞΌ := rfl
@[to_additive (attr := simp)]
theorem inv_eq_self (ΞΌ : Measure G) [IsInvInvariant ΞΌ] : ΞΌ.inv = ΞΌ :=
IsInvInvariant.inv_eq_self
@[to_additive (attr := simp)]
theorem map_inv_eq_self (ΞΌ : Measure G) [IsInvInvariant ΞΌ] : map Inv.inv ΞΌ = ΞΌ :=
IsInvInvariant.inv_eq_self
variable [MeasurableInv G]
@[to_additive]
theorem measurePreserving_inv (ΞΌ : Measure G) [IsInvInvariant ΞΌ] : MeasurePreserving Inv.inv ΞΌ ΞΌ :=
β¨measurable_inv, map_inv_eq_self ΞΌβ©
@[to_additive]
instance inv.instSFinite (ΞΌ : Measure G) [SFinite ΞΌ] : SFinite ΞΌ.inv := by
rw [Measure.inv]; infer_instance
end Inv
section InvolutiveInv
variable [InvolutiveInv G] [MeasurableInv G]
@[to_additive (attr := simp)]
theorem inv_apply (ΞΌ : Measure G) (s : Set G) : ΞΌ.inv s = ΞΌ sβ»ΒΉ :=
(MeasurableEquiv.inv G).map_apply s
@[to_additive (attr := simp)]
protected theorem inv_inv (ΞΌ : Measure G) : ΞΌ.inv.inv = ΞΌ :=
(MeasurableEquiv.inv G).map_symm_map
@[to_additive (attr := simp)]
theorem measure_inv (ΞΌ : Measure G) [IsInvInvariant ΞΌ] (A : Set G) : ΞΌ Aβ»ΒΉ = ΞΌ A := by
rw [β inv_apply, inv_eq_self]
@[to_additive]
theorem measure_preimage_inv (ΞΌ : Measure G) [IsInvInvariant ΞΌ] (A : Set G) :
ΞΌ (Inv.inv β»ΒΉ' A) = ΞΌ A :=
ΞΌ.measure_inv A
@[to_additive]
instance inv.instSigmaFinite (ΞΌ : Measure G) [SigmaFinite ΞΌ] : SigmaFinite ΞΌ.inv :=
(MeasurableEquiv.inv G).sigmaFinite_map
end InvolutiveInv
section DivisionMonoid
variable [DivisionMonoid G] [MeasurableMul G] [MeasurableInv G] {ΞΌ : Measure G}
@[to_additive]
instance inv.instIsMulRightInvariant [IsMulLeftInvariant ΞΌ] : IsMulRightInvariant ΞΌ.inv := by
constructor
intro g
conv_rhs => rw [β map_mul_left_eq_self ΞΌ gβ»ΒΉ]
simp_rw [Measure.inv, map_map (measurable_mul_const g) measurable_inv,
map_map measurable_inv (measurable_const_mul gβ»ΒΉ), Function.comp_def, mul_inv_rev, inv_inv]
@[to_additive]
instance inv.instIsMulLeftInvariant [IsMulRightInvariant ΞΌ] : IsMulLeftInvariant ΞΌ.inv := by
constructor
intro g
conv_rhs => rw [β map_mul_right_eq_self ΞΌ gβ»ΒΉ]
simp_rw [Measure.inv, map_map (measurable_const_mul g) measurable_inv,
map_map measurable_inv (measurable_mul_const gβ»ΒΉ), Function.comp_def, mul_inv_rev, inv_inv]
@[to_additive]
theorem measurePreserving_div_left (ΞΌ : Measure G) [IsInvInvariant ΞΌ] [IsMulLeftInvariant ΞΌ]
(g : G) : MeasurePreserving (fun t => g / t) ΞΌ ΞΌ := by
simp_rw [div_eq_mul_inv]
exact (measurePreserving_mul_left ΞΌ g).comp (measurePreserving_inv ΞΌ)
@[to_additive]
theorem map_div_left_eq_self (ΞΌ : Measure G) [IsInvInvariant ΞΌ] [IsMulLeftInvariant ΞΌ] (g : G) :
map (fun t => g / t) ΞΌ = ΞΌ :=
(measurePreserving_div_left ΞΌ g).map_eq
@[to_additive]
theorem measurePreserving_mul_right_inv (ΞΌ : Measure G) [IsInvInvariant ΞΌ] [IsMulLeftInvariant ΞΌ]
(g : G) : MeasurePreserving (fun t => (g * t)β»ΒΉ) ΞΌ ΞΌ :=
(measurePreserving_inv ΞΌ).comp <| measurePreserving_mul_left ΞΌ g
@[to_additive]
theorem map_mul_right_inv_eq_self (ΞΌ : Measure G) [IsInvInvariant ΞΌ] [IsMulLeftInvariant ΞΌ]
(g : G) : map (fun t => (g * t)β»ΒΉ) ΞΌ = ΞΌ :=
(measurePreserving_mul_right_inv ΞΌ g).map_eq
end DivisionMonoid
section Group
variable [Group G] {ΞΌ : Measure G}
section MeasurableMul
variable [MeasurableMul G]
@[to_additive]
instance : (count : Measure G).IsMulLeftInvariant where
map_mul_left_eq_self g := by
ext s hs
rw [count_apply hs, map_apply (measurable_const_mul _) hs,
count_apply (measurable_const_mul _ hs),
encard_preimage_of_bijective (Group.mulLeft_bijective _)]
@[to_additive]
instance : (count : Measure G).IsMulRightInvariant where
map_mul_right_eq_self g := by
ext s hs
rw [count_apply hs, map_apply (measurable_mul_const _) hs,
count_apply (measurable_mul_const _ hs),
encard_preimage_of_bijective (Group.mulRight_bijective _)]
@[to_additive]
protected theorem IsMulLeftInvariant.comap {H} [Group H] {mH : MeasurableSpace H} [MeasurableMul H]
(ΞΌ : Measure H) [IsMulLeftInvariant ΞΌ] {f : G β* H} (hf : MeasurableEmbedding f) :
(ΞΌ.comap f).IsMulLeftInvariant where
map_mul_left_eq_self g := by
ext s hs
rw [map_apply (by fun_prop) hs]
repeat rw [hf.comap_apply]
have : f '' ((g * Β·) β»ΒΉ' s) = (f g * Β·) β»ΒΉ' (f '' s) := by
ext
constructor
Β· rintro β¨y, hy, rflβ©
exact β¨g * y, hy, by simpβ©
Β· intro β¨y, yins, hyβ©
exact β¨gβ»ΒΉ * y, by simp [yins], by simp [hy]β©
rw [this, β map_apply (by fun_prop), IsMulLeftInvariant.map_mul_left_eq_self]
exact hf.measurableSet_image.mpr hs
end MeasurableMul
variable [MeasurableInv G]
@[to_additive]
instance : (count : Measure G).IsInvInvariant where
inv_eq_self := by ext s hs; rw [count_apply hs, inv_apply, count_apply hs.inv, encard_inv]
variable [MeasurableMul G]
@[to_additive]
theorem map_div_left_ae (ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] [IsInvInvariant ΞΌ] (x : G) :
Filter.map (fun t => x / t) (ae ΞΌ) = ae ΞΌ :=
((MeasurableEquiv.divLeft x).map_ae ΞΌ).trans <| congr_arg ae <| map_div_left_eq_self ΞΌ x
end Group
end Measure
section IsTopologicalGroup
variable [TopologicalSpace G] [BorelSpace G] {ΞΌ : Measure G} [Group G]
@[to_additive]
instance Measure.IsFiniteMeasureOnCompacts.inv [ContinuousInv G] [IsFiniteMeasureOnCompacts ΞΌ] :
IsFiniteMeasureOnCompacts ΞΌ.inv :=
IsFiniteMeasureOnCompacts.map ΞΌ (Homeomorph.inv G)
@[to_additive]
instance Measure.IsOpenPosMeasure.inv [ContinuousInv G] [IsOpenPosMeasure ΞΌ] :
IsOpenPosMeasure ΞΌ.inv :=
(Homeomorph.inv G).continuous.isOpenPosMeasure_map (Homeomorph.inv G).surjective
@[to_additive]
instance Measure.Regular.inv [ContinuousInv G] [Regular ΞΌ] : Regular ΞΌ.inv :=
Regular.map (Homeomorph.inv G)
@[to_additive]
instance Measure.InnerRegular.inv [ContinuousInv G] [InnerRegular ΞΌ] : InnerRegular ΞΌ.inv :=
InnerRegular.map (Homeomorph.inv G)
/-- The image of an inner regular measure under map of a left action is again inner regular. -/
@[to_additive
/-- The image of a inner regular measure under map of a left additive action is again
inner regular -/]
instance innerRegular_map_smul {Ξ±} [Monoid Ξ±] [MulAction Ξ± G] [ContinuousConstSMul Ξ± G]
[InnerRegular ΞΌ] (a : Ξ±) : InnerRegular (Measure.map (a β’ Β· : G β G) ΞΌ) :=
InnerRegular.map_of_continuous (continuous_const_smul a)
/-- The image of an inner regular measure under left multiplication is again inner regular. -/
@[to_additive
/-- The image of an inner regular measure under left addition is again inner regular. -/]
instance innerRegular_map_mul_left [IsTopologicalGroup G] [InnerRegular ΞΌ] (g : G) :
InnerRegular (Measure.map (g * Β·) ΞΌ) := InnerRegular.map_of_continuous (continuous_mul_left g)
/-- The image of an inner regular measure under right multiplication is again inner regular. -/
@[to_additive
/-- The image of an inner regular measure under right addition is again inner regular. -/]
instance innerRegular_map_mul_right [IsTopologicalGroup G] [InnerRegular ΞΌ] (g : G) :
InnerRegular (Measure.map (Β· * g) ΞΌ) := InnerRegular.map_of_continuous (continuous_mul_right g)
variable [IsTopologicalGroup G]
@[to_additive]
theorem regular_inv_iff : ΞΌ.inv.Regular β ΞΌ.Regular :=
Regular.map_iff (Homeomorph.inv G)
@[to_additive]
theorem innerRegular_inv_iff : ΞΌ.inv.InnerRegular β ΞΌ.InnerRegular :=
InnerRegular.map_iff (Homeomorph.inv G)
/-- Continuity of the measure of translates of a compact set: Given a compact set `k` in a
topological group, for `g` close enough to the origin, `ΞΌ (g β’ k \ k)` is arbitrarily small. -/
@[to_additive]
lemma eventually_nhds_one_measure_smul_diff_lt [LocallyCompactSpace G]
[IsFiniteMeasureOnCompacts ΞΌ] [InnerRegularCompactLTTop ΞΌ] {k : Set G}
(hk : IsCompact k) (h'k : IsClosed k) {Ξ΅ : ββ₯0β} (hΞ΅ : Ξ΅ β 0) :
βαΆ g in π (1 : G), ΞΌ (g β’ k \ k) < Ξ΅ := by
obtain β¨U, hUk, hU, hΞΌUkβ© : β (U : Set G), k β U β§ IsOpen U β§ ΞΌ U < ΞΌ k + Ξ΅ :=
hk.exists_isOpen_lt_add hΞ΅
obtain β¨V, hV1, hVkUβ© : β V β π (1 : G), V * k β U := compact_open_separated_mul_left hk hU hUk
filter_upwards [hV1] with g hg
calc
ΞΌ (g β’ k \ k) β€ ΞΌ (U \ k) := by
gcongr
exact (smul_set_subset_smul hg).trans hVkU
_ < Ξ΅ := measure_diff_lt_of_lt_add h'k.nullMeasurableSet hUk hk.measure_lt_top.ne hΞΌUk
/-- Continuity of the measure of translates of a compact set:
Given a closed compact set `k` in a topological group,
the measure of `g β’ k \ k` tends to zero as `g` tends to `1`. -/
@[to_additive]
lemma tendsto_measure_smul_diff_isCompact_isClosed [LocallyCompactSpace G]
[IsFiniteMeasureOnCompacts ΞΌ] [InnerRegularCompactLTTop ΞΌ] {k : Set G}
(hk : IsCompact k) (h'k : IsClosed k) :
Tendsto (fun g : G β¦ ΞΌ (g β’ k \ k)) (π 1) (π 0) :=
ENNReal.nhds_zero_basis.tendsto_right_iff.mpr <| fun _ h β¦
eventually_nhds_one_measure_smul_diff_lt hk h'k h.ne'
section IsMulLeftInvariant
variable [IsMulLeftInvariant ΞΌ]
/-- If a left-invariant measure gives positive mass to a compact set, then it gives positive mass to
any open set. -/
@[to_additive
/-- If a left-invariant measure gives positive mass to a compact set, then it gives positive mass to
any open set. -/]
theorem isOpenPosMeasure_of_mulLeftInvariant_of_compact (K : Set G) (hK : IsCompact K)
(h : ΞΌ K β 0) : IsOpenPosMeasure ΞΌ := by
refine β¨fun U hU hne => ?_β©
contrapose! h
rw [β nonpos_iff_eq_zero]
rw [β hU.interior_eq] at hne
obtain β¨t, hKtβ© : β t : Finset G, K β β (g : G) (_ : g β t), (fun h : G => g * h) β»ΒΉ' U :=
compact_covered_by_mul_left_translates hK hne
calc
ΞΌ K β€ ΞΌ (β (g : G) (_ : g β t), (fun h : G => g * h) β»ΒΉ' U) := measure_mono hKt
_ β€ β g β t, ΞΌ ((fun h : G => g * h) β»ΒΉ' U) := measure_biUnion_finset_le _ _
_ = 0 := by simp [measure_preimage_mul, h]
/-- A nonzero left-invariant regular measure gives positive mass to any open set. -/
@[to_additive /-- A nonzero left-invariant regular measure gives positive mass to any open set. -/]
instance (priority := 80) isOpenPosMeasure_of_mulLeftInvariant_of_regular [Regular ΞΌ] [NeZero ΞΌ] :
IsOpenPosMeasure ΞΌ :=
let β¨K, hK, h2Kβ© := Regular.exists_isCompact_not_null.mpr (NeZero.ne ΞΌ)
isOpenPosMeasure_of_mulLeftInvariant_of_compact K hK h2K
/-- A nonzero left-invariant inner regular measure gives positive mass to any open set. -/
@[to_additive
/-- A nonzero left-invariant inner regular measure gives positive mass to any open set. -/]
instance (priority := 80) isOpenPosMeasure_of_mulLeftInvariant_of_innerRegular
[InnerRegular ΞΌ] [NeZero ΞΌ] :
IsOpenPosMeasure ΞΌ :=
let β¨K, hK, h2Kβ© := InnerRegular.exists_isCompact_not_null.mpr (NeZero.ne ΞΌ)
isOpenPosMeasure_of_mulLeftInvariant_of_compact K hK h2K
@[to_additive]
theorem null_iff_of_isMulLeftInvariant [Regular ΞΌ] {s : Set G} (hs : IsOpen s) :
ΞΌ s = 0 β s = β
β¨ ΞΌ = 0 := by
rcases eq_zero_or_neZero ΞΌ with rfl | hΞΌ
Β· simp
Β· simp only [or_false, hs.measure_eq_zero_iff ΞΌ, NeZero.ne ΞΌ]
@[to_additive]
theorem measure_ne_zero_iff_nonempty_of_isMulLeftInvariant [Regular ΞΌ] (hΞΌ : ΞΌ β 0) {s : Set G}
(hs : IsOpen s) : ΞΌ s β 0 β s.Nonempty := by
simpa [null_iff_of_isMulLeftInvariant (ΞΌ := ΞΌ) hs, hΞΌ] using nonempty_iff_ne_empty.symm
@[to_additive]
theorem measure_pos_iff_nonempty_of_isMulLeftInvariant [Regular ΞΌ] (h3ΞΌ : ΞΌ β 0) {s : Set G}
(hs : IsOpen s) : 0 < ΞΌ s β s.Nonempty :=
pos_iff_ne_zero.trans <| measure_ne_zero_iff_nonempty_of_isMulLeftInvariant h3ΞΌ hs
/-- If a left-invariant measure gives finite mass to a nonempty open set, then it gives finite mass
to any compact set. -/
@[to_additive
/-- If a left-invariant measure gives finite mass to a nonempty open set, then it gives finite mass
to any compact set. -/]
theorem measure_lt_top_of_isCompact_of_isMulLeftInvariant (U : Set G) (hU : IsOpen U)
(h'U : U.Nonempty) (h : ΞΌ U β β) {K : Set G} (hK : IsCompact K) : ΞΌ K < β := by
rw [β hU.interior_eq] at h'U
obtain β¨t, hKtβ© : β t : Finset G, K β β g β t, (fun h : G => g * h) β»ΒΉ' U :=
compact_covered_by_mul_left_translates hK h'U
exact (measure_mono hKt).trans_lt <| measure_biUnion_lt_top t.finite_toSet <| by simp [h.lt_top]
/-- If a left-invariant measure gives finite mass to a set with nonempty interior, then
it gives finite mass to any compact set. -/
@[to_additive
/-- If a left-invariant measure gives finite mass to a set with nonempty interior, then it gives
finite mass to any compact set. -/]
theorem measure_lt_top_of_isCompact_of_isMulLeftInvariant' {U : Set G}
(hU : (interior U).Nonempty) (h : ΞΌ U β β) {K : Set G} (hK : IsCompact K) : ΞΌ K < β :=
measure_lt_top_of_isCompact_of_isMulLeftInvariant (interior U) isOpen_interior hU
((measure_mono interior_subset).trans_lt (lt_top_iff_ne_top.2 h)).ne hK
/-- In a noncompact locally compact group, a left-invariant measure which is positive
on open sets has infinite mass. -/
@[to_additive (attr := simp)
/-- In a noncompact locally compact additive group, a left-invariant measure which is positive on
open sets has infinite mass. -/]
theorem measure_univ_of_isMulLeftInvariant [WeaklyLocallyCompactSpace G] [NoncompactSpace G]
(ΞΌ : Measure G) [IsOpenPosMeasure ΞΌ] [ΞΌ.IsMulLeftInvariant] : ΞΌ univ = β := by
/- Consider a closed compact set `K` with nonempty interior. For any compact set `L`, one may
find `g = g (L)` such that `L` is disjoint from `g β’ K`. Iterating this, one finds
infinitely many translates of `K` which are disjoint from each other. As they all have the
same positive mass, it follows that the space has infinite measure. -/
obtain β¨K, K1, hK, Kclosedβ© : β K β π (1 : G), IsCompact K β§ IsClosed K :=
exists_mem_nhds_isCompact_isClosed 1
have K_pos : 0 < ΞΌ K := measure_pos_of_mem_nhds ΞΌ K1
have A : β L : Set G, IsCompact L β β g : G, Disjoint L (g β’ K) := fun L hL =>
exists_disjoint_smul_of_isCompact hL hK
choose! g hg using A
set L : β β Set G := fun n => (fun T => T βͺ g T β’ K)^[n] K
have Lcompact : β n, IsCompact (L n) := fun n β¦ by
induction n with
| zero => exact hK
| succ n IH =>
simp_rw [L, iterate_succ']
apply IsCompact.union IH (hK.smul (g (L n)))
have Lclosed : β n, IsClosed (L n) := fun n β¦ by
induction n with
| zero => exact Kclosed
| succ n IH =>
simp_rw [L, iterate_succ']
apply IsClosed.union IH (Kclosed.smul (g (L n)))
have M : β n, ΞΌ (L n) = (n + 1 : β) * ΞΌ K := fun n β¦ by
induction n with
| zero => simp only [L, one_mul, Nat.cast_one, iterate_zero, id, Nat.zero_add]
| succ n IH =>
calc
ΞΌ (L (n + 1)) = ΞΌ (L n) + ΞΌ (g (L n) β’ K) := by
simp_rw [L, iterate_succ']
exact measure_union' (hg _ (Lcompact _)) (Lclosed _).measurableSet
_ = (n + 1 + 1 : β) * ΞΌ K := by
simp only [IH, measure_smul, add_mul, Nat.cast_add, Nat.cast_one, one_mul]
have N : Tendsto (fun n => ΞΌ (L n)) atTop (π (β * ΞΌ K)) := by
simp_rw [M]
apply ENNReal.Tendsto.mul_const _ (Or.inl ENNReal.top_ne_zero)
exact ENNReal.tendsto_nat_nhds_top.comp (tendsto_add_atTop_nat _)
simp only [ENNReal.top_mul', K_pos.ne', if_false] at N
apply top_le_iff.1
exact le_of_tendsto' N fun n => measure_mono (subset_univ _)
@[to_additive]
lemma _root_.MeasurableSet.mul_closure_one_eq {s : Set G} (hs : MeasurableSet s) :
s * (closure {1} : Set G) = s := by
induction s, hs using MeasurableSet.induction_on_open with
| isOpen U hU => exact hU.mul_closure_one_eq
| compl t _ iht => exact compl_mul_closure_one_eq_iff.2 iht
| iUnion f _ _ ihf => simp_rw [iUnion_mul f, ihf]
@[to_additive (attr := simp)]
lemma measure_mul_closure_one (s : Set G) (ΞΌ : Measure G) :
ΞΌ (s * (closure {1} : Set G)) = ΞΌ s := by
apply le_antisymm ?_ (measure_mono (subset_mul_closure_one s))
conv_rhs => rw [measure_eq_iInf]
simp only [le_iInf_iff]
intro t kt t_meas
apply measure_mono
rw [β t_meas.mul_closure_one_eq]
exact smul_subset_smul_right kt
end IsMulLeftInvariant
@[to_additive]
lemma innerRegularWRT_isCompact_isClosed_measure_ne_top_of_group [h : InnerRegularCompactLTTop ΞΌ] :
InnerRegularWRT ΞΌ (fun s β¦ IsCompact s β§ IsClosed s) (fun s β¦ MeasurableSet s β§ ΞΌ s β β) := by
intro s β¨s_meas, ΞΌsβ© r hr
rcases h.innerRegular β¨s_meas, ΞΌsβ© r hr with β¨K, Ks, K_comp, hKβ©
refine β¨closure K, ?_, β¨K_comp.closure, isClosed_closureβ©, ?_β©
Β· exact IsCompact.closure_subset_measurableSet K_comp s_meas Ks
Β· rwa [K_comp.measure_closure]
end IsTopologicalGroup
section CommSemigroup
variable [CommSemigroup G]
/-- In an abelian group every left invariant measure is also right-invariant.
We don't declare the converse as an instance, since that would loop type-class inference, and
we use `IsMulLeftInvariant` as the default hypothesis in abelian groups. -/
@[to_additive IsAddLeftInvariant.isAddRightInvariant
/-- In an abelian additive group every left invariant measure is also right-invariant. We don't
declare the converse as an instance, since that would loop type-class inference, and we use
`IsAddLeftInvariant` as the default hypothesis in abelian groups. -/]
instance (priority := 100) IsMulLeftInvariant.isMulRightInvariant {ΞΌ : Measure G}
[IsMulLeftInvariant ΞΌ] : IsMulRightInvariant ΞΌ :=
β¨fun g => by simp_rw [mul_comm, map_mul_left_eq_self]β©
end CommSemigroup
section Haar
namespace Measure
/-- A measure on an additive group is an additive Haar measure if it is left-invariant, and
gives finite mass to compact sets and positive mass to open sets.
Textbooks generally require an additional regularity assumption to ensure nice behavior on
arbitrary locally compact groups. Use `[IsAddHaarMeasure ΞΌ] [Regular ΞΌ]` or
`[IsAddHaarMeasure ΞΌ] [InnerRegular ΞΌ]` in these situations. Note that a Haar measure in our
sense is automatically regular and inner regular on second countable locally compact groups, as
checked just below this definition. -/
class IsAddHaarMeasure {G : Type*} [AddGroup G] [TopologicalSpace G] [MeasurableSpace G]
(ΞΌ : Measure G) : Prop
extends IsFiniteMeasureOnCompacts ΞΌ, IsAddLeftInvariant ΞΌ, IsOpenPosMeasure ΞΌ
/-- A measure on a group is a Haar measure if it is left-invariant, and gives finite mass to
compact sets and positive mass to open sets.
Textbooks generally require an additional regularity assumption to ensure nice behavior on
arbitrary locally compact groups. Use `[IsHaarMeasure ΞΌ] [Regular ΞΌ]` or
`[IsHaarMeasure ΞΌ] [InnerRegular ΞΌ]` in these situations. Note that a Haar measure in our
sense is automatically regular and inner regular on second countable locally compact groups, as
checked just below this definition. -/
@[to_additive existing]
class IsHaarMeasure {G : Type*} [Group G] [TopologicalSpace G] [MeasurableSpace G]
(ΞΌ : Measure G) : Prop
extends IsFiniteMeasureOnCompacts ΞΌ, IsMulLeftInvariant ΞΌ, IsOpenPosMeasure ΞΌ
variable [Group G] [TopologicalSpace G] (ΞΌ : Measure G) [IsHaarMeasure ΞΌ]
@[to_additive (attr := simp)]
theorem haar_singleton [ContinuousMul G] [BorelSpace G] (g : G) : ΞΌ {g} = ΞΌ {(1 : G)} := by
convert measure_preimage_mul ΞΌ gβ»ΒΉ _
simp only [mul_one, preimage_mul_left_singleton, inv_inv]
@[to_additive IsAddHaarMeasure.smul]
theorem IsHaarMeasure.smul {c : ββ₯0β} (cpos : c β 0) (ctop : c β β) : IsHaarMeasure (c β’ ΞΌ) :=
{ lt_top_of_isCompact := fun _K hK => ENNReal.mul_lt_top ctop.lt_top hK.measure_lt_top
toIsOpenPosMeasure := isOpenPosMeasure_smul ΞΌ cpos }
@[to_additive IsAddHaarMeasure.nnreal_smul]
lemma IsHaarMeasure.nnreal_smul {c : ββ₯0} (hc : c β 0) : IsHaarMeasure (c β’ ΞΌ) :=
.smul _ (by simp [hc]) (Option.some_ne_none _)
/-- If a left-invariant measure gives positive mass to some compact set with nonempty interior, then
it is a Haar measure. -/
@[to_additive
/-- If a left-invariant measure gives positive mass to some compact set with nonempty interior, then
it is an additive Haar measure. -/]
theorem isHaarMeasure_of_isCompact_nonempty_interior [IsTopologicalGroup G] [BorelSpace G]
(ΞΌ : Measure G) [IsMulLeftInvariant ΞΌ] (K : Set G) (hK : IsCompact K)
(h'K : (interior K).Nonempty) (h : ΞΌ K β 0) (h' : ΞΌ K β β) : IsHaarMeasure ΞΌ :=
{ lt_top_of_isCompact := fun _L hL =>
measure_lt_top_of_isCompact_of_isMulLeftInvariant' h'K h' hL
toIsOpenPosMeasure := isOpenPosMeasure_of_mulLeftInvariant_of_compact K hK h }
/-- The image of a Haar measure under a continuous surjective proper group homomorphism is again
a Haar measure. See also `MulEquiv.isHaarMeasure_map` and `ContinuousMulEquiv.isHaarMeasure_map`. -/
@[to_additive
/-- The image of an additive Haar measure under a continuous surjective proper additive group
homomorphism is again an additive Haar measure. See also `AddEquiv.isAddHaarMeasure_map`,
`ContinuousAddEquiv.isAddHaarMeasure_map` and `ContinuousLinearEquiv.isAddHaarMeasure_map`. -/]
theorem isHaarMeasure_map [BorelSpace G] [ContinuousMul G] {H : Type*} [Group H]
[TopologicalSpace H] [MeasurableSpace H] [BorelSpace H] [IsTopologicalGroup H]
(f : G β* H) (hf : Continuous f) (h_surj : Surjective f)
(h_prop : Tendsto f (cocompact G) (cocompact H)) : IsHaarMeasure (Measure.map f ΞΌ) :=
{ toIsMulLeftInvariant := isMulLeftInvariant_map f.toMulHom hf.measurable h_surj
lt_top_of_isCompact := by
intro K hK
rw [β hK.measure_closure, map_apply hf.measurable isClosed_closure.measurableSet]
set g : CocompactMap G H := β¨β¨f, hfβ©, h_propβ©
exact IsCompact.measure_lt_top (g.isCompact_preimage_of_isClosed hK.closure isClosed_closure)
toIsOpenPosMeasure := hf.isOpenPosMeasure_map h_surj }
protected theorem IsHaarMeasure.comap [BorelSpace G] [MeasurableMul G]
[Group H] [TopologicalSpace H] [BorelSpace H] {mH : MeasurableMul H}
(ΞΌ : Measure H) [IsHaarMeasure ΞΌ] {f : G β* H} (hf : Topology.IsOpenEmbedding f) :
(ΞΌ.comap f).IsHaarMeasure where
map_mul_left_eq_self := (IsMulLeftInvariant.comap ΞΌ hf.measurableEmbedding).map_mul_left_eq_self
lt_top_of_isCompact := (IsFiniteMeasureOnCompacts.comap' ΞΌ hf.continuous
hf.measurableEmbedding).lt_top_of_isCompact
open_pos := (IsOpenPosMeasure.comap ΞΌ hf).open_pos
/-- The image of a finite Haar measure under a continuous surjective group homomorphism is again
a Haar measure. See also `isHaarMeasure_map`. -/
@[to_additive
/-- The image of a finite additive Haar measure under a continuous surjective additive group
homomorphism is again an additive Haar measure. See also `isAddHaarMeasure_map`. -/]
theorem isHaarMeasure_map_of_isFiniteMeasure
[BorelSpace G] [ContinuousMul G] {H : Type*} [Group H]
[TopologicalSpace H] [MeasurableSpace H] [BorelSpace H] [ContinuousMul H]
[IsFiniteMeasure ΞΌ] (f : G β* H) (hf : Continuous f) (h_surj : Surjective f) :
IsHaarMeasure (Measure.map f ΞΌ) where
toIsMulLeftInvariant := isMulLeftInvariant_map f.toMulHom hf.measurable h_surj
toIsOpenPosMeasure := hf.isOpenPosMeasure_map h_surj
/-- The image of a Haar measure under map of a left action is again a Haar measure. -/
@[to_additive
/-- The image of a Haar measure under map of a left additive action is again a Haar measure -/]
instance isHaarMeasure_map_smul {Ξ±} [BorelSpace G] [IsTopologicalGroup G]
[Group Ξ±] [MulAction Ξ± G] [SMulCommClass Ξ± G G] [MeasurableSpace Ξ±] [MeasurableSMul Ξ± G]
[ContinuousConstSMul Ξ± G] (a : Ξ±) : IsHaarMeasure (Measure.map (a β’ Β· : G β G) ΞΌ) where
toIsMulLeftInvariant := isMulLeftInvariant_map_smul _
lt_top_of_isCompact K hK := by
let F := (Homeomorph.smul a (Ξ± := G)).toMeasurableEquiv
change map F ΞΌ K < β
rw [F.map_apply K]
exact IsCompact.measure_lt_top <| (Homeomorph.isCompact_preimage (Homeomorph.smul a)).2 hK
toIsOpenPosMeasure :=
(continuous_const_smul a).isOpenPosMeasure_map (MulAction.surjective a)
/-- The image of a Haar measure under right multiplication is again a Haar measure. -/
@[to_additive isHaarMeasure_map_add_right
/-- The image of a Haar measure under right addition is again a Haar measure. -/]
instance isHaarMeasure_map_mul_right [BorelSpace G] [IsTopologicalGroup G] (g : G) :
IsHaarMeasure (Measure.map (Β· * g) ΞΌ) :=
isHaarMeasure_map_smul ΞΌ (MulOpposite.op g)
/-- A convenience wrapper for `MeasureTheory.Measure.isHaarMeasure_map`. -/
@[to_additive /-- A convenience wrapper for `MeasureTheory.Measure.isAddHaarMeasure_map`. -/]
nonrec theorem _root_.MulEquiv.isHaarMeasure_map [BorelSpace G] [ContinuousMul G] {H : Type*}
[Group H] [TopologicalSpace H] [MeasurableSpace H] [BorelSpace H]
[IsTopologicalGroup H] (e : G β* H) (he : Continuous e) (hesymm : Continuous e.symm) :
IsHaarMeasure (Measure.map e ΞΌ) :=
let f : G ββ H := .mk e
-- We need to write `e.toMonoidHom` instead of just `e`, to avoid unification issues.
isHaarMeasure_map ΞΌ e.toMonoidHom he e.surjective f.isClosedEmbedding.tendsto_cocompact
/--
A convenience wrapper for MeasureTheory.Measure.isHaarMeasure_map.
-/
@[to_additive /-- A convenience wrapper for MeasureTheory.Measure.isAddHaarMeasure_map. -/]
instance _root_.ContinuousMulEquiv.isHaarMeasure_map [BorelSpace G] [IsTopologicalGroup G]
{H : Type*} [Group H] [TopologicalSpace H] [MeasurableSpace H] [BorelSpace H]
[IsTopologicalGroup H] (e : G ββ* H) : (ΞΌ.map e).IsHaarMeasure :=
e.toMulEquiv.isHaarMeasure_map ΞΌ e.continuous e.symm.continuous
/-- A convenience wrapper for MeasureTheory.Measure.isAddHaarMeasure_map`. -/
instance _root_.ContinuousLinearEquiv.isAddHaarMeasure_map
{E F R S : Type*} [Semiring R] [Semiring S]
[AddCommGroup E] [Module R E] [AddCommGroup F] [Module S F]
[TopologicalSpace E] [IsTopologicalAddGroup E] [TopologicalSpace F]
[IsTopologicalAddGroup F]
{Ο : R β+* S} {Ο' : S β+* R} [RingHomInvPair Ο Ο'] [RingHomInvPair Ο' Ο]
[MeasurableSpace E] [BorelSpace E] [MeasurableSpace F] [BorelSpace F]
(L : E βSL[Ο] F) (ΞΌ : Measure E) [IsAddHaarMeasure ΞΌ] :
IsAddHaarMeasure (ΞΌ.map L) :=
AddEquiv.isAddHaarMeasure_map _ (L : E β+ F) L.continuous L.symm.continuous
/-- A Haar measure on a Ο-compact space is Ο-finite.
See Note [lower instance priority] -/
@[to_additive
/-- A Haar measure on a Ο-compact space is Ο-finite.
See Note [lower instance priority] -/]
instance (priority := 100) IsHaarMeasure.sigmaFinite [SigmaCompactSpace G] : SigmaFinite ΞΌ :=
β¨β¨{ set := compactCovering G
set_mem := fun _ => mem_univ _
finite := fun n => IsCompact.measure_lt_top <| isCompact_compactCovering G n
spanning := iUnion_compactCovering G }β©β©
@[to_additive]
instance prod.instIsHaarMeasure {G : Type*} [Group G] [TopologicalSpace G] {_ : MeasurableSpace G}
{H : Type*} [Group H] [TopologicalSpace H] {_ : MeasurableSpace H} (ΞΌ : Measure G)
(Ξ½ : Measure H) [IsHaarMeasure ΞΌ] [IsHaarMeasure Ξ½] [SFinite ΞΌ] [SFinite Ξ½]
[MeasurableMul G] [MeasurableMul H] : IsHaarMeasure (ΞΌ.prod Ξ½) where
/-- If the neutral element of a group is not isolated, then a Haar measure on this group has
no atoms.
The additive version of this instance applies in particular to show that an additive Haar
measure on a nontrivial finite-dimensional real vector space has no atom. -/
@[to_additive
/-- If the zero element of an additive group is not isolated, then an additive Haar measure on this
group has no atoms.
This applies in particular to show that an additive Haar measure on a nontrivial
finite-dimensional real vector space has no atom. -/]
instance (priority := 100) IsHaarMeasure.noAtoms [IsTopologicalGroup G] [BorelSpace G] [T1Space G]
[WeaklyLocallyCompactSpace G] [(π[β ] (1 : G)).NeBot] (ΞΌ : Measure G) [ΞΌ.IsHaarMeasure] :
NoAtoms ΞΌ := by
cases eq_or_ne (ΞΌ 1) 0 with
| inl h => constructor; simpa
| inr h =>
obtain β¨K, K_compact, K_nhdsβ© : β K : Set G, IsCompact K β§ K β π 1 := exists_compact_mem_nhds 1
have K_inf : Set.Infinite K := infinite_of_mem_nhds (1 : G) K_nhds
exact absurd (K_inf.meas_eq_top β¨_, h, fun x _ β¦ (haar_singleton _ _).geβ©)
K_compact.measure_lt_top.ne
instance IsAddHaarMeasure.domSMul {G A : Type*} [Group G] [AddCommGroup A] [DistribMulAction G A]
[MeasurableSpace A] [TopologicalSpace A] [BorelSpace A] [IsTopologicalAddGroup A]
[ContinuousConstSMul G A] {ΞΌ : Measure A} [ΞΌ.IsAddHaarMeasure] (g : Gα΅α΅α΅) :
(g β’ ΞΌ).IsAddHaarMeasure :=
(DistribMulAction.toAddEquiv _ (DomMulAct.mk.symm gβ»ΒΉ)).isAddHaarMeasure_map _
(continuous_const_smul _) (continuous_const_smul _)
end Measure
end Haar
end MeasureTheory
|
UniformConvergence.lean
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.Algebra.UniformMulAction
import Mathlib.Algebra.Module.Pi
import Mathlib.Topology.UniformSpace.UniformConvergenceTopology
/-!
# Algebraic facts about the topology of uniform convergence
This file contains algebraic compatibility results about the uniform structure of uniform
convergence / `π`-convergence. They will mostly be useful for defining strong topologies on the
space of continuous linear maps between two topological vector spaces.
## Main statements
* `UniformFun.uniform_group` : if `G` is a uniform group, then `Ξ± βα΅€ G` a uniform group
* `UniformOnFun.uniform_group` : if `G` is a uniform group, then for any `π : Set (Set Ξ±)`,
`Ξ± βα΅€[π] G` a uniform group.
## Implementation notes
Like in `Mathlib/Topology/UniformSpace/UniformConvergenceTopology.lean`, we use the type aliases
`UniformFun` (denoted `Ξ± βα΅€ Ξ²`) and `UniformOnFun` (denoted `Ξ± βα΅€[π] Ξ²`) for functions from `Ξ±`
to `Ξ²` endowed with the structures of uniform convergence and `π`-convergence.
## References
* [N. Bourbaki, *General Topology, Chapter X*][bourbaki1966]
* [N. Bourbaki, *Topological Vector Spaces*][bourbaki1987]
## Tags
uniform convergence, strong dual
-/
open Filter
open scoped Topology Pointwise UniformConvergence Uniformity
section AlgebraicInstances
variable {Ξ± Ξ² ΞΉ R : Type*} {π : Set <| Set Ξ±} {x : Ξ±}
@[to_additive] instance [One Ξ²] : One (Ξ± βα΅€ Ξ²) := Pi.instOne
@[to_additive (attr := simp)]
lemma UniformFun.toFun_one [One Ξ²] : toFun (1 : Ξ± βα΅€ Ξ²) = 1 := rfl
@[to_additive (attr := simp)]
lemma UniformFun.ofFun_one [One Ξ²] : ofFun (1 : Ξ± β Ξ²) = 1 := rfl
@[to_additive] instance [One Ξ²] : One (Ξ± βα΅€[π] Ξ²) := Pi.instOne
@[to_additive (attr := simp)]
lemma UniformOnFun.toFun_one [One Ξ²] : toFun π (1 : Ξ± βα΅€[π] Ξ²) = 1 := rfl
@[to_additive (attr := simp)]
lemma UniformOnFun.one_apply [One Ξ²] : ofFun π (1 : Ξ± β Ξ²) = 1 := rfl
@[to_additive] instance [Mul Ξ²] : Mul (Ξ± βα΅€ Ξ²) := Pi.instMul
@[to_additive (attr := simp)]
lemma UniformFun.toFun_mul [Mul Ξ²] (f g : Ξ± βα΅€ Ξ²) : toFun (f * g) = toFun f * toFun g := rfl
@[to_additive (attr := simp)]
lemma UniformFun.ofFun_mul [Mul Ξ²] (f g : Ξ± β Ξ²) : ofFun (f * g) = ofFun f * ofFun g := rfl
@[to_additive] instance [Mul Ξ²] : Mul (Ξ± βα΅€[π] Ξ²) := Pi.instMul
@[to_additive (attr := simp)]
lemma UniformOnFun.toFun_mul [Mul Ξ²] (f g : Ξ± βα΅€[π] Ξ²) :
toFun π (f * g) = toFun π f * toFun π g :=
rfl
@[to_additive (attr := simp)]
lemma UniformOnFun.ofFun_mul [Mul Ξ²] (f g : Ξ± β Ξ²) : ofFun π (f * g) = ofFun π f * ofFun π g := rfl
@[to_additive] instance [Inv Ξ²] : Inv (Ξ± βα΅€ Ξ²) := Pi.instInv
@[to_additive (attr := simp)]
lemma UniformFun.toFun_inv [Inv Ξ²] (f : Ξ± βα΅€ Ξ²) : toFun (fβ»ΒΉ) = (toFun f)β»ΒΉ := rfl
@[to_additive (attr := simp)]
lemma UniformFun.ofFun_inv [Inv Ξ²] (f : Ξ± β Ξ²) : ofFun (fβ»ΒΉ) = (ofFun f)β»ΒΉ := rfl
@[to_additive] instance [Inv Ξ²] : Inv (Ξ± βα΅€[π] Ξ²) := Pi.instInv
@[to_additive (attr := simp)]
lemma UniformOnFun.toFun_inv [Inv Ξ²] (f : Ξ± βα΅€[π] Ξ²) : toFun π (fβ»ΒΉ) = (toFun π f)β»ΒΉ := rfl
@[to_additive (attr := simp)]
lemma UniformOnFun.ofFun_inv [Inv Ξ²] (f : Ξ± β Ξ²) : ofFun π (fβ»ΒΉ) = (ofFun π f)β»ΒΉ := rfl
@[to_additive] instance [Div Ξ²] : Div (Ξ± βα΅€ Ξ²) := Pi.instDiv
@[to_additive (attr := simp)]
lemma UniformFun.toFun_div [Div Ξ²] (f g : Ξ± βα΅€ Ξ²) : toFun (f / g) = toFun f / toFun g := rfl
@[to_additive (attr := simp)]
lemma UniformFun.ofFun_div [Div Ξ²] (f g : Ξ± β Ξ²) : ofFun (f / g) = ofFun f / ofFun g := rfl
@[to_additive] instance [Div Ξ²] : Div (Ξ± βα΅€[π] Ξ²) := Pi.instDiv
@[to_additive (attr := simp)]
lemma UniformOnFun.toFun_div [Div Ξ²] (f g : Ξ± βα΅€[π] Ξ²) :
toFun π (f / g) = toFun π f / toFun π g :=
rfl
@[to_additive (attr := simp)]
lemma UniformOnFun.ofFun_div [Div Ξ²] (f g : Ξ± β Ξ²) : ofFun π (f / g) = ofFun π f / ofFun π g := rfl
@[to_additive]
instance [Monoid Ξ²] : Monoid (Ξ± βα΅€ Ξ²) :=
Pi.monoid
@[to_additive]
instance [Monoid Ξ²] : Monoid (Ξ± βα΅€[π] Ξ²) :=
Pi.monoid
@[to_additive]
instance [CommMonoid Ξ²] : CommMonoid (Ξ± βα΅€ Ξ²) :=
Pi.commMonoid
@[to_additive]
instance [CommMonoid Ξ²] : CommMonoid (Ξ± βα΅€[π] Ξ²) :=
Pi.commMonoid
@[to_additive]
instance [Group Ξ²] : Group (Ξ± βα΅€ Ξ²) :=
Pi.group
@[to_additive]
instance [Group Ξ²] : Group (Ξ± βα΅€[π] Ξ²) :=
Pi.group
@[to_additive]
instance [CommGroup Ξ²] : CommGroup (Ξ± βα΅€ Ξ²) :=
Pi.commGroup
@[to_additive]
instance [CommGroup Ξ²] : CommGroup (Ξ± βα΅€[π] Ξ²) :=
Pi.commGroup
instance {M : Type*} [SMul M Ξ²] : SMul M (Ξ± βα΅€ Ξ²) := Pi.instSMul
@[simp]
lemma UniformFun.toFun_smul {M : Type*} [SMul M Ξ²] (c : M) (f : Ξ± βα΅€ Ξ²) :
toFun (c β’ f) = c β’ toFun f :=
rfl
@[simp]
lemma UniformFun.ofFun_smul {M : Type*} [SMul M Ξ²] (c : M) (f : Ξ± β Ξ²) :
ofFun (c β’ f) = c β’ ofFun f :=
rfl
instance {M : Type*} [SMul M Ξ²] : SMul M (Ξ± βα΅€[π] Ξ²) := Pi.instSMul
@[simp]
lemma UniformOnFun.toFun_smul {M : Type*} [SMul M Ξ²] (c : M) (f : Ξ± βα΅€[π] Ξ²) :
toFun π (c β’ f) = c β’ toFun π f :=
rfl
@[simp]
lemma UniformOnFun.ofFun_smul {M : Type*} [SMul M Ξ²] (c : M) (f : Ξ± β Ξ²) :
ofFun π (c β’ f) = c β’ ofFun π f :=
rfl
instance {M N : Type*} [SMul M N] [SMul M Ξ²] [SMul N Ξ²] [IsScalarTower M N Ξ²] :
IsScalarTower M N (Ξ± βα΅€ Ξ²) :=
Pi.isScalarTower
instance {M N : Type*} [SMul M N] [SMul M Ξ²] [SMul N Ξ²] [IsScalarTower M N Ξ²] :
IsScalarTower M N (Ξ± βα΅€[π] Ξ²) :=
Pi.isScalarTower
instance {M N : Type*} [SMul M Ξ²] [SMul N Ξ²] [SMulCommClass M N Ξ²] :
SMulCommClass M N (Ξ± βα΅€ Ξ²) :=
Pi.smulCommClass
instance {M N : Type*} [SMul M Ξ²] [SMul N Ξ²] [SMulCommClass M N Ξ²] :
SMulCommClass M N (Ξ± βα΅€[π] Ξ²) :=
Pi.smulCommClass
instance {M : Type*} [Monoid M] [MulAction M Ξ²] : MulAction M (Ξ± βα΅€ Ξ²) := Pi.mulAction _
instance {M : Type*} [Monoid M] [MulAction M Ξ²] : MulAction M (Ξ± βα΅€[π] Ξ²) := Pi.mulAction _
instance {M : Type*} [Monoid M] [AddMonoid Ξ²] [DistribMulAction M Ξ²] :
DistribMulAction M (Ξ± βα΅€ Ξ²) :=
Pi.distribMulAction _
instance {M : Type*} [Monoid M] [AddMonoid Ξ²] [DistribMulAction M Ξ²] :
DistribMulAction M (Ξ± βα΅€[π] Ξ²) :=
Pi.distribMulAction _
instance [Semiring R] [AddCommMonoid Ξ²] [Module R Ξ²] : Module R (Ξ± βα΅€ Ξ²) :=
Pi.module _ _ _
instance [Semiring R] [AddCommMonoid Ξ²] [Module R Ξ²] : Module R (Ξ± βα΅€[π] Ξ²) :=
Pi.module _ _ _
end AlgebraicInstances
section Group
variable {Ξ± G ΞΉ : Type*} [Group G] {π : Set <| Set Ξ±} [UniformSpace G] [IsUniformGroup G]
/-- If `G` is a uniform group, then `Ξ± βα΅€ G` is a uniform group as well. -/
@[to_additive /-- If `G` is a uniform additive group,
then `Ξ± βα΅€ G` is a uniform additive group as well. -/]
instance : IsUniformGroup (Ξ± βα΅€ G) :=
β¨(-- Since `(/) : G Γ G β G` is uniformly continuous,
-- `UniformFun.postcomp_uniformContinuous` tells us that
-- `((/) β β) : (Ξ± βα΅€ G Γ G) β (Ξ± βα΅€ G)` is uniformly continuous too. By precomposing with
-- `UniformFun.uniformEquivProdArrow`, this gives that
-- `(/) : (Ξ± βα΅€ G) Γ (Ξ± βα΅€ G) β (Ξ± βα΅€ G)` is also uniformly continuous
UniformFun.postcomp_uniformContinuous uniformContinuous_div).comp
UniformFun.uniformEquivProdArrow.symm.uniformContinuousβ©
@[to_additive]
protected theorem UniformFun.hasBasis_nhds_one_of_basis {p : ΞΉ β Prop} {b : ΞΉ β Set G}
(h : (π 1 : Filter G).HasBasis p b) :
(π 1 : Filter (Ξ± βα΅€ G)).HasBasis p fun i => { f : Ξ± βα΅€ G | β x, toFun f x β b i } := by
convert UniformFun.hasBasis_nhds_of_basis Ξ± _ (1 : Ξ± βα΅€ G) h.uniformity_of_nhds_one
simp
@[to_additive]
protected theorem UniformFun.hasBasis_nhds_one :
(π 1 : Filter (Ξ± βα΅€ G)).HasBasis (fun V : Set G => V β (π 1 : Filter G)) fun V =>
{ f : Ξ± β G | β x, f x β V } :=
UniformFun.hasBasis_nhds_one_of_basis (basis_sets _)
/-- Let `π : Set (Set Ξ±)`. If `G` is a uniform group, then `Ξ± βα΅€[π] G` is a uniform group as
well. -/
@[to_additive /-- Let `π : Set (Set Ξ±)`. If `G` is a uniform additive group,
then `Ξ± βα΅€[π] G` is a uniform additive group as well. -/]
instance : IsUniformGroup (Ξ± βα΅€[π] G) :=
β¨(-- Since `(/) : G Γ G β G` is uniformly continuous,
-- `UniformOnFun.postcomp_uniformContinuous` tells us that
-- `((/) β β) : (Ξ± βα΅€[π] G Γ G) β (Ξ± βα΅€[π] G)` is uniformly continuous too. By precomposing with
-- `UniformOnFun.uniformEquivProdArrow`, this gives that
-- `(/) : (Ξ± βα΅€[π] G) Γ (Ξ± βα΅€[π] G) β (Ξ± βα΅€[π] G)` is also uniformly continuous
UniformOnFun.postcomp_uniformContinuous uniformContinuous_div).comp
UniformOnFun.uniformEquivProdArrow.symm.uniformContinuousβ©
@[to_additive]
protected theorem UniformOnFun.hasBasis_nhds_one_of_basis (π : Set <| Set Ξ±) (hπβ : π.Nonempty)
(hπβ : DirectedOn (Β· β Β·) π) {p : ΞΉ β Prop} {b : ΞΉ β Set G}
(h : (π 1 : Filter G).HasBasis p b) :
(π 1 : Filter (Ξ± βα΅€[π] G)).HasBasis (fun Si : Set Ξ± Γ ΞΉ => Si.1 β π β§ p Si.2) fun Si =>
{ f : Ξ± βα΅€[π] G | β x β Si.1, toFun π f x β b Si.2 } := by
convert UniformOnFun.hasBasis_nhds_of_basis Ξ± _ π (1 : Ξ± βα΅€[π] G) hπβ hπβ <|
h.uniformity_of_nhds_one_swapped
simp [UniformOnFun.gen]
@[to_additive]
protected theorem UniformOnFun.hasBasis_nhds_one (π : Set <| Set Ξ±) (hπβ : π.Nonempty)
(hπβ : DirectedOn (Β· β Β·) π) :
(π 1 : Filter (Ξ± βα΅€[π] G)).HasBasis
(fun SV : Set Ξ± Γ Set G => SV.1 β π β§ SV.2 β (π 1 : Filter G)) fun SV =>
{ f : Ξ± βα΅€[π] G | β x β SV.1, f x β SV.2 } :=
UniformOnFun.hasBasis_nhds_one_of_basis π hπβ hπβ (basis_sets _)
@[to_additive (attr := simp)]
lemma UniformOnFun.ofFun_prod {Ξ² : Type*} [CommMonoid Ξ²] {f : ΞΉ β Ξ± β Ξ²} (I : Finset ΞΉ) :
ofFun π (β i β I, f i) = β i β I, ofFun π (f i) :=
rfl
@[to_additive (attr := simp)]
lemma UniformOnFun.toFun_prod {Ξ² : Type*} [CommMonoid Ξ²] {f : ΞΉ β Ξ± β Ξ²} (I : Finset ΞΉ) :
toFun π (β i β I, f i) = β i β I, toFun π (f i) :=
rfl
@[to_additive (attr := simp)]
lemma UniformFun.ofFun_prod {Ξ² : Type*} [CommMonoid Ξ²] {f : ΞΉ β Ξ± β Ξ²} (I : Finset ΞΉ) :
ofFun (β i β I, f i) = β i β I, ofFun (f i) :=
rfl
@[to_additive (attr := simp)]
lemma UniformFun.toFun_prod {Ξ² : Type*} [CommMonoid Ξ²] {f : ΞΉ β Ξ± β Ξ²} (I : Finset ΞΉ) :
toFun (β i β I, f i) = β i β I, toFun (f i) :=
rfl
end Group
section ConstSMul
variable (M Ξ± X : Type*) [SMul M X] [UniformSpace X] [UniformContinuousConstSMul M X]
instance UniformFun.uniformContinuousConstSMul :
UniformContinuousConstSMul M (Ξ± βα΅€ X) where
uniformContinuous_const_smul c := UniformFun.postcomp_uniformContinuous <|
uniformContinuous_const_smul c
instance UniformFunOn.uniformContinuousConstSMul {π : Set (Set Ξ±)} :
UniformContinuousConstSMul M (Ξ± βα΅€[π] X) where
uniformContinuous_const_smul c := UniformOnFun.postcomp_uniformContinuous <|
uniformContinuous_const_smul c
end ConstSMul
|
sylow.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 div.
From mathcomp Require Import fintype prime bigop finset fingroup morphism.
From mathcomp Require Import automorphism quotient action cyclic gproduct .
From mathcomp Require Import gfunctor commutator pgroup center nilpotent.
(******************************************************************************)
(* The Sylow theorem and its consequences, including the Frattini argument, *)
(* the nilpotence of p-groups, and the Baer-Suzuki theorem. *)
(* This file also defines: *)
(* Zgroup G == G is a Z-group, i.e., has only cyclic Sylow p-subgroups. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
(* The mod p lemma for the action of p-groups. *)
Section ModP.
Variable (aT : finGroupType) (sT : finType) (D : {group aT}).
Variable to : action D sT.
Lemma pgroup_fix_mod (p : nat) (G : {group aT}) (S : {set sT}) :
p.-group G -> [acts G, on S | to] -> #|S| = #|'Fix_(S | to)(G)| %[mod p].
Proof.
move=> pG nSG; have sGD: G \subset D := acts_dom nSG.
apply/eqP; rewrite -(cardsID 'Fix_to(G)) eqn_mod_dvd (leq_addr, addKn) //.
have: [acts G, on S :\: 'Fix_to(G) | to]; last move/acts_sum_card_orbit <-.
rewrite actsD // -(setIidPr sGD); apply: subset_trans (acts_subnorm_fix _ _).
by rewrite setIS ?normG.
apply: dvdn_sum => _ /imsetP[x /setDP[_ nfx] ->].
have [k oGx]: {k | #|orbit to G x| = (p ^ k)%N}.
by apply: p_natP; apply: pnat_dvd pG; rewrite card_orbit_in ?dvdn_indexg.
case: k oGx => [/card_orbit1 fix_x | k ->]; last by rewrite expnS dvdn_mulr.
by case/afixP: nfx => a Ga; apply/set1P; rewrite -fix_x mem_orbit.
Qed.
End ModP.
Section ModularGroupAction.
Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}).
Variables (to : groupAction D R) (p : nat).
Implicit Types (G H : {group aT}) (M : {group rT}).
Lemma nontrivial_gacent_pgroup G M :
p.-group G -> p.-group M -> {acts G, on group M | to} ->
M :!=: 1 -> 'C_(M | to)(G) :!=: 1.
Proof.
move=> pG pM [nMG sMR] ntM; have [p_pr p_dv_M _] := pgroup_pdiv pM ntM.
rewrite -cardG_gt1 (leq_trans (prime_gt1 p_pr)) 1?dvdn_leq ?cardG_gt0 //= /dvdn.
by rewrite gacentE ?(acts_dom nMG) // setIA (setIidPl sMR) -pgroup_fix_mod.
Qed.
Lemma pcore_sub_astab_irr G M :
p.-group M -> M \subset R -> acts_irreducibly G M to ->
'O_p(G) \subset 'C_G(M | to).
Proof.
move=> pM sMR /mingroupP[/andP[ntM nMG] minM].
have /andP[sGpG nGpG]: 'O_p(G) <| G := gFnormal _ G.
have sGD := acts_dom nMG; have sGpD: 'O_p(G) \subset D := gFsub_trans _ sGD.
rewrite subsetI sGpG -gacentC //=; apply/setIidPl; apply: minM (subsetIl _ _).
rewrite nontrivial_gacent_pgroup ?pcore_pgroup //=; last first.
by split; rewrite ?gFsub_trans.
by apply: subset_trans (acts_subnorm_subgacent sGpD nMG); rewrite subsetI subxx.
Qed.
Lemma pcore_faithful_irr_act G M :
p.-group M -> M \subset R -> acts_irreducibly G M to ->
[faithful G, on M | to] ->
'O_p(G) = 1.
Proof.
move=> pM sMR irrG ffulG; apply/trivgP; apply: subset_trans ffulG.
exact: pcore_sub_astab_irr.
Qed.
End ModularGroupAction.
Section Sylow.
Variables (p : nat) (gT : finGroupType) (G : {group gT}).
Implicit Types P Q H K : {group gT}.
Theorem Sylow's_theorem :
[/\ forall P, [max P | p.-subgroup(G) P] = p.-Sylow(G) P,
[transitive G, on 'Syl_p(G) | 'JG],
forall P, p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)|
& prime p -> #|'Syl_p(G)| %% p = 1%N].
Proof.
pose maxp A P := [max P | p.-subgroup(A) P]; pose S := [set P | maxp G P].
pose oG := orbit 'JG%act G.
have actS: [acts G, on S | 'JG].
apply/subsetP=> x Gx; rewrite 3!inE; apply/subsetP=> P; rewrite 3!inE.
exact: max_pgroupJ.
have S_pG P: P \in S -> P \subset G /\ p.-group P.
by rewrite inE => /maxgroupp/andP[].
have SmaxN P Q: Q \in S -> Q \subset 'N(P) -> maxp 'N_G(P) Q.
rewrite inE => /maxgroupP[/andP[sQG pQ] maxQ] nPQ.
apply/maxgroupP; rewrite /psubgroup subsetI sQG nPQ.
by split=> // R; rewrite subsetI -andbA andbCA => /andP[_]; apply: maxQ.
have nrmG P: P \subset G -> P <| 'N_G(P).
by move=> sPG; rewrite /normal subsetIr subsetI sPG normG.
have sylS P: P \in S -> p.-Sylow('N_G(P)) P.
move=> S_P; have [sPG pP] := S_pG P S_P.
by rewrite normal_max_pgroup_Hall ?nrmG //; apply: SmaxN; rewrite ?normG.
have{SmaxN} defCS P: P \in S -> 'Fix_(S |'JG)(P) = [set P].
move=> S_P; apply/setP=> Q; rewrite {1}in_setI {1}afixJG.
apply/andP/set1P=> [[S_Q nQP]|->{Q}]; last by rewrite normG.
apply/esym/val_inj; case: (S_pG Q) => //= sQG _.
by apply: uniq_normal_Hall (SmaxN Q _ _ _) => //=; rewrite ?sylS ?nrmG.
have{defCS} oG_mod: {in S &, forall P Q, #|oG P| = (Q \in oG P) %[mod p]}.
move=> P Q S_P S_Q; have [sQG pQ] := S_pG _ S_Q.
have soP_S: oG P \subset S by rewrite acts_sub_orbit.
have /pgroup_fix_mod-> //: [acts Q, on oG P | 'JG].
apply/actsP=> x /(subsetP sQG) Gx R; apply: orbit_transl.
exact: mem_orbit.
rewrite -{1}(setIidPl soP_S) -setIA defCS // (cardsD1 Q) setDE.
by rewrite -setIA setICr setI0 cards0 addn0 inE set11 andbT.
have [P S_P]: exists P, P \in S.
have: p.-subgroup(G) 1 by rewrite /psubgroup sub1G pgroup1.
by case/(@maxgroup_exists _ (p.-subgroup(G))) => P; exists P; rewrite inE.
have trS: [transitive G, on S | 'JG].
apply/imsetP; exists P => //; apply/eqP.
rewrite eqEsubset andbC acts_sub_orbit // S_P; apply/subsetP=> Q S_Q.
have /[1!inE] /maxgroupP[/andP[_ pP]] := S_P.
have [-> max1 | ntP _] := eqVneq P 1%G.
move/andP/max1: (S_pG _ S_Q) => Q1.
by rewrite (group_inj (Q1 (sub1G Q))) orbit_refl.
have:= oG_mod _ _ S_P S_P; rewrite (oG_mod _ Q) // orbit_refl.
have p_gt1: p > 1 by apply: prime_gt1; case/pgroup_pdiv: pP.
by case: (Q \in oG P) => //; rewrite mod0n modn_small.
have oS1: prime p -> #|S| %% p = 1%N.
move/prime_gt1 => p_gt1.
by rewrite -(atransP trS P S_P) (oG_mod P P) // orbit_refl modn_small.
have oSiN Q: Q \in S -> #|S| = #|G : 'N_G(Q)|.
by move=> S_Q; rewrite -(atransP trS Q S_Q) card_orbit astab1JG.
have sylP: p.-Sylow(G) P.
rewrite pHallE; case: (S_pG P) => // -> /= pP.
case p_pr: (prime p); last first.
rewrite p_part lognE p_pr /= -trivg_card1; apply/idPn=> ntP.
by case/pgroup_pdiv: pP p_pr => // ->.
rewrite -(LagrangeI G 'N(P)) /= mulnC partnM ?cardG_gt0 // part_p'nat.
by rewrite mul1n (card_Hall (sylS P S_P)).
by rewrite p'natE // -indexgI -oSiN // /dvdn oS1.
have eqS Q: maxp G Q = p.-Sylow(G) Q.
apply/idP/idP=> [S_Q|]; last exact: Hall_max.
have{} S_Q: Q \in S by rewrite inE.
rewrite pHallE -(card_Hall sylP); case: (S_pG Q) => // -> _ /=.
by case: (atransP2 trS S_P S_Q) => x _ ->; rewrite cardJg.
have ->: 'Syl_p(G) = S by apply/setP=> Q; rewrite 2!inE.
by split=> // Q sylQ; rewrite -oSiN ?inE ?eqS.
Qed.
Lemma max_pgroup_Sylow P : [max P | p.-subgroup(G) P] = p.-Sylow(G) P.
Proof. by case Sylow's_theorem. Qed.
Lemma Sylow_superset Q :
Q \subset G -> p.-group Q -> {P : {group gT} | p.-Sylow(G) P & Q \subset P}.
Proof.
move=> sQG pQ.
have [|P] := @maxgroup_exists _ (p.-subgroup(G)) Q; first exact/andP.
by rewrite max_pgroup_Sylow; exists P.
Qed.
Lemma Sylow_exists : {P : {group gT} | p.-Sylow(G) P}.
Proof. by case: (Sylow_superset (sub1G G) (pgroup1 _ p)) => P; exists P. Qed.
Lemma Syl_trans : [transitive G, on 'Syl_p(G) | 'JG].
Proof. by case Sylow's_theorem. Qed.
Lemma Sylow_trans P Q :
p.-Sylow(G) P -> p.-Sylow(G) Q -> exists2 x, x \in G & Q :=: P :^ x.
Proof.
move=> sylP sylQ; have /[!inE] := (atransP2 Syl_trans) P Q.
by case=> // x Gx ->; exists x.
Qed.
Lemma Sylow_subJ P Q :
p.-Sylow(G) P -> Q \subset G -> p.-group Q ->
exists2 x, x \in G & Q \subset P :^ x.
Proof.
move=> sylP sQG pQ; have [Px sylPx] := Sylow_superset sQG pQ.
by have [x Gx ->] := Sylow_trans sylP sylPx; exists x.
Qed.
Lemma Sylow_Jsub P Q :
p.-Sylow(G) P -> Q \subset G -> p.-group Q ->
exists2 x, x \in G & Q :^ x \subset P.
Proof.
move=> sylP sQG pQ; have [x Gx] := Sylow_subJ sylP sQG pQ.
by exists x^-1; rewrite (groupV, sub_conjgV).
Qed.
Lemma card_Syl P : p.-Sylow(G) P -> #|'Syl_p(G)| = #|G : 'N_G(P)|.
Proof. by case: Sylow's_theorem P. Qed.
Lemma card_Syl_dvd : #|'Syl_p(G)| %| #|G|.
Proof. by case Sylow_exists => P /card_Syl->; apply: dvdn_indexg. Qed.
Lemma card_Syl_mod : prime p -> #|'Syl_p(G)| %% p = 1%N.
Proof. by case Sylow's_theorem. Qed.
Lemma Frattini_arg H P : G <| H -> p.-Sylow(G) P -> G * 'N_H(P) = H.
Proof.
case/andP=> sGH nGH sylP; rewrite -normC ?subIset ?nGH ?orbT // -astab1JG.
move/subgroup_transitiveP: Syl_trans => ->; rewrite ?inE //.
apply/imsetP; exists P; rewrite ?inE //.
apply/eqP; rewrite eqEsubset -{1}((atransP Syl_trans) P) ?inE // imsetS //=.
by apply/subsetP=> _ /imsetP[x Hx ->]; rewrite inE -(normsP nGH x Hx) pHallJ2.
Qed.
End Sylow.
Section MoreSylow.
Variables (gT : finGroupType) (p : nat).
Implicit Types G H P : {group gT}.
Lemma Sylow_setI_normal G H P :
G <| H -> p.-Sylow(H) P -> p.-Sylow(G) (G :&: P).
Proof.
case/normalP=> sGH nGH sylP; have [Q sylQ] := Sylow_exists p G.
have /maxgroupP[/andP[sQG pQ] maxQ] := Hall_max sylQ.
have [R sylR sQR] := Sylow_superset (subset_trans sQG sGH) pQ.
have [[x Hx ->] pR] := (Sylow_trans sylR sylP, pHall_pgroup sylR).
rewrite -(nGH x Hx) -conjIg pHallJ2.
have /maxQ-> //: Q \subset G :&: R by rewrite subsetI sQG.
by rewrite /psubgroup subsetIl (pgroupS _ pR) ?subsetIr.
Qed.
Lemma normal_sylowP G :
reflect (exists2 P : {group gT}, p.-Sylow(G) P & P <| G)
(#|'Syl_p(G)| == 1%N).
Proof.
apply: (iffP idP) => [syl1 | [P sylP nPG]]; last first.
by rewrite (card_Syl sylP) (setIidPl _) (indexgg, normal_norm).
have [P sylP] := Sylow_exists p G; exists P => //.
rewrite /normal (pHall_sub sylP); apply/setIidPl; apply/eqP.
rewrite eqEcard subsetIl -(LagrangeI G 'N(P)) -indexgI /=.
by rewrite -(card_Syl sylP) (eqP syl1) muln1.
Qed.
Lemma trivg_center_pgroup P : p.-group P -> 'Z(P) = 1 -> P :=: 1.
Proof.
move=> pP Z1; apply/eqP/idPn=> ntP.
have{ntP} [p_pr p_dv_P _] := pgroup_pdiv pP ntP.
suff: p %| #|'Z(P)| by rewrite Z1 cards1 gtnNdvd ?prime_gt1.
by rewrite /center /dvdn -afixJ -pgroup_fix_mod // astabsJ normG.
Qed.
Lemma p2group_abelian P : p.-group P -> logn p #|P| <= 2 -> abelian P.
Proof.
move=> pP lePp2; pose Z := 'Z(P); have sZP: Z \subset P := center_sub P.
have [/(trivg_center_pgroup pP) ->|] := eqVneq Z 1; first exact: abelian1.
case/(pgroup_pdiv (pgroupS sZP pP)) => p_pr _ [k oZ].
apply: cyclic_center_factor_abelian.
have [->|] := eqVneq (P / Z) 1; first exact: cyclic1.
have pPq := quotient_pgroup 'Z(P) pP; case/(pgroup_pdiv pPq) => _ _ [j oPq].
rewrite prime_cyclic // oPq; case: j oPq lePp2 => //= j.
rewrite card_quotient ?gFnorm //.
by rewrite -(Lagrange sZP) lognM // => ->; rewrite oZ !pfactorK ?addnS.
Qed.
Lemma card_p2group_abelian P : prime p -> #|P| = (p ^ 2)%N -> abelian P.
Proof.
move=> primep oP; have pP: p.-group P by rewrite /pgroup oP pnatX pnat_id.
by rewrite (p2group_abelian pP) // oP pfactorK.
Qed.
Lemma Sylow_transversal_gen (T : {set {group gT}}) G :
(forall P, P \in T -> P \subset G) ->
(forall p, p \in \pi(G) -> exists2 P, P \in T & p.-Sylow(G) P) ->
<< \bigcup_(P in T) P >> = G.
Proof.
move=> G_T T_G; apply/eqP; rewrite eqEcard gen_subG.
apply/andP; split; first exact/bigcupsP.
apply: dvdn_leq (cardG_gt0 _) _; apply/dvdn_partP=> // q /T_G[P T_P sylP].
by rewrite -(card_Hall sylP); apply: cardSg; rewrite sub_gen // bigcup_sup.
Qed.
Lemma Sylow_gen G : <<\bigcup_(P : {group gT} | Sylow G P) P>> = G.
Proof.
set T := [set P : {group gT} | Sylow G P].
rewrite -{2}(@Sylow_transversal_gen T G) => [|P | q _].
- by congr <<_>>; apply: eq_bigl => P; rewrite inE.
- by rewrite inE => /and3P[].
by case: (Sylow_exists q G) => P sylP; exists P; rewrite // inE (p_Sylow sylP).
Qed.
End MoreSylow.
Section SomeHall.
Variable gT : finGroupType.
Implicit Types (p : nat) (pi : nat_pred) (G H K P R : {group gT}).
Lemma Hall_pJsub p pi G H P :
pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P ->
exists2 x, x \in G & P :^ x \subset H.
Proof.
move=> hallH pi_p sPG pP.
have [S sylS] := Sylow_exists p H; have sylS_G := subHall_Sylow hallH pi_p sylS.
have [x Gx sPxS] := Sylow_Jsub sylS_G sPG pP; exists x => //.
exact: subset_trans sPxS (pHall_sub sylS).
Qed.
Lemma Hall_psubJ p pi G H P :
pi.-Hall(G) H -> p \in pi -> P \subset G -> p.-group P ->
exists2 x, x \in G & P \subset H :^ x.
Proof.
move=> hallH pi_p sPG pP; have [x Gx sPxH] := Hall_pJsub hallH pi_p sPG pP.
by exists x^-1; rewrite ?groupV -?sub_conjg.
Qed.
Lemma Hall_setI_normal pi G K H :
K <| G -> pi.-Hall(G) H -> pi.-Hall(K) (H :&: K).
Proof.
move=> nsKG hallH; have [sHG piH _] := and3P hallH.
have [sHK_H sHK_K] := (subsetIl H K, subsetIr H K).
rewrite pHallE sHK_K /= -(part_pnat_id (pgroupS sHK_H piH)); apply/eqP.
rewrite (widen_partn _ (subset_leq_card sHK_K)); apply: eq_bigr => p pi_p.
have [P sylP] := Sylow_exists p H.
have sylPK := Sylow_setI_normal nsKG (subHall_Sylow hallH pi_p sylP).
rewrite -!p_part -(card_Hall sylPK); symmetry; apply: card_Hall.
by rewrite (pHall_subl _ sHK_K) //= setIC setSI ?(pHall_sub sylP).
Qed.
Lemma coprime_mulG_setI_norm H G K R :
K * R = G -> G \subset 'N(H) -> coprime #|K| #|R| ->
(K :&: H) * (R :&: H) = G :&: H.
Proof.
move=> defG nHG coKR; apply/eqP; rewrite eqEcard mulG_subG /= -defG.
rewrite !setSI ?mulG_subl ?mulG_subr //=.
rewrite coprime_cardMg ?(coKR, coprimeSg (subsetIl _ _), coprime_sym) //=.
pose pi := \pi(K); have piK: pi.-group K by apply: pgroup_pi.
have pi'R: pi^'.-group R by rewrite /pgroup -coprime_pi' /=.
have [hallK hallR] := coprime_mulpG_Hall defG piK pi'R.
have nsHG: H :&: G <| G by rewrite /normal subsetIr normsI ?normG.
rewrite -!(setIC H) defG -(partnC pi (cardG_gt0 _)).
rewrite -(card_Hall (Hall_setI_normal nsHG hallR)) /= setICA.
rewrite -(card_Hall (Hall_setI_normal nsHG hallK)) /= setICA.
by rewrite -defG (setIidPl (mulG_subl _ _)) (setIidPl (mulG_subr _ _)).
Qed.
End SomeHall.
Section Nilpotent.
Variable gT : finGroupType.
Implicit Types (G H K P L : {group gT}) (p q : nat).
Lemma pgroup_nil p P : p.-group P -> nilpotent P.
Proof.
move: {2}_.+1 (ltnSn #|P|) => n.
elim: n gT P => // n IHn pT P; rewrite ltnS=> lePn pP.
have [Z1 | ntZ] := eqVneq 'Z(P) 1.
by rewrite (trivg_center_pgroup pP Z1) nilpotent1.
rewrite -quotient_center_nil IHn ?morphim_pgroup // (leq_trans _ lePn) //.
rewrite card_quotient ?normal_norm ?center_normal // -divgS ?subsetIl //.
by rewrite ltn_Pdiv // ltnNge -trivg_card_le1.
Qed.
Lemma pgroup_sol p P : p.-group P -> solvable P.
Proof. by move/pgroup_nil; apply: nilpotent_sol. Qed.
Lemma small_nil_class G : nil_class G <= 5 -> nilpotent G.
Proof.
move=> leK5; case: (ltnP 5 #|G|) => [lt5G | leG5 {leK5}].
by rewrite nilpotent_class (leq_ltn_trans leK5).
apply: pgroup_nil (pdiv #|G|) _ _; apply/andP; split=> //.
by case: #|G| leG5 => //; do 5!case=> //.
Qed.
Lemma nil_class2 G : (nil_class G <= 2) = (G^`(1) \subset 'Z(G)).
Proof.
rewrite subsetI der_sub; apply/idP/commG1P=> [clG2 | L3G1].
by apply/(lcn_nil_classP 2); rewrite ?small_nil_class ?(leq_trans clG2).
by apply/(lcn_nil_classP 2) => //; apply/lcnP; exists 2.
Qed.
Lemma nil_class3 G : (nil_class G <= 3) = ('L_3(G) \subset 'Z(G)).
Proof.
rewrite subsetI lcn_sub; apply/idP/commG1P=> [clG3 | L4G1].
by apply/(lcn_nil_classP 3); rewrite ?small_nil_class ?(leq_trans clG3).
by apply/(lcn_nil_classP 3) => //; apply/lcnP; exists 3.
Qed.
Lemma nilpotent_maxp_normal pi G H :
nilpotent G -> [max H | pi.-subgroup(G) H] -> H <| G.
Proof.
move=> nilG /maxgroupP[/andP[sHG piH] maxH].
have nHN: H <| 'N_G(H) by rewrite normal_subnorm.
have{maxH} hallH: pi.-Hall('N_G(H)) H.
apply: normal_max_pgroup_Hall => //; apply/maxgroupP.
rewrite /psubgroup normal_sub // piH; split=> // K.
by rewrite subsetI -andbA andbCA => /andP[_ /maxH].
rewrite /normal sHG; apply/setIidPl/esym.
apply: nilpotent_sub_norm; rewrite ?subsetIl ?setIS //= char_norms //.
by congr (_ \char _): (pcore_char pi 'N_G(H)); apply: normal_Hall_pcore.
Qed.
Lemma nilpotent_Hall_pcore pi G H :
nilpotent G -> pi.-Hall(G) H -> H :=: 'O_pi(G).
Proof.
move=> nilG hallH; have maxH := Hall_max hallH; apply/eqP.
rewrite eqEsubset pcore_max ?(pHall_pgroup hallH) //.
by rewrite (normal_sub_max_pgroup maxH) ?pcore_pgroup ?pcore_normal.
exact: nilpotent_maxp_normal maxH.
Qed.
Lemma nilpotent_pcore_Hall pi G : nilpotent G -> pi.-Hall(G) 'O_pi(G).
Proof.
move=> nilG; case: (@maxgroup_exists _ (psubgroup pi G) 1) => [|H maxH _].
by rewrite /psubgroup sub1G pgroup1.
have hallH := normal_max_pgroup_Hall maxH (nilpotent_maxp_normal nilG maxH).
by rewrite -(nilpotent_Hall_pcore nilG hallH).
Qed.
Lemma nilpotent_pcoreC pi G : nilpotent G -> 'O_pi(G) \x 'O_pi^'(G) = G.
Proof.
move=> nilG; have trO: 'O_pi(G) :&: 'O_pi^'(G) = 1.
by apply: coprime_TIg; apply: (@pnat_coprime pi); apply: pcore_pgroup.
rewrite dprodE //.
apply/eqP; rewrite eqEcard mul_subG ?pcore_sub // (TI_cardMg trO).
by rewrite !(card_Hall (nilpotent_pcore_Hall _ _)) // partnC ?leqnn.
rewrite (sameP commG1P trivgP) -trO subsetI commg_subl commg_subr.
by rewrite !gFsub_trans ?gFnorm.
Qed.
Lemma sub_nilpotent_cent2 H K G :
nilpotent G -> K \subset G -> H \subset G -> coprime #|K| #|H| ->
H \subset 'C(K).
Proof.
move=> nilG sKG sHG; rewrite coprime_pi' // => p'H.
have sub_Gp := sub_Hall_pcore (nilpotent_pcore_Hall _ nilG).
have [_ _ cGpp' _] := dprodP (nilpotent_pcoreC \pi(K) nilG).
by apply: centSS cGpp'; rewrite sub_Gp ?pgroup_pi.
Qed.
Lemma pi_center_nilpotent G : nilpotent G -> \pi('Z(G)) = \pi(G).
Proof.
move=> nilG; apply/eq_piP => /= p.
apply/idP/idP=> [|pG]; first exact: (piSg (center_sub _)).
move: (pG); rewrite !mem_primes !cardG_gt0; case/andP=> p_pr _.
pose Z := 'O_p(G) :&: 'Z(G); have ntZ: Z != 1.
rewrite meet_center_nil ?pcore_normal // trivg_card_le1 -ltnNge.
rewrite (card_Hall (nilpotent_pcore_Hall p nilG)) p_part.
by rewrite (ltn_exp2l 0 _ (prime_gt1 p_pr)) logn_gt0.
have pZ: p.-group Z := pgroupS (subsetIl _ _) (pcore_pgroup _ _).
have{ntZ pZ} [_ pZ _] := pgroup_pdiv pZ ntZ.
by rewrite p_pr (dvdn_trans pZ) // cardSg ?subsetIr.
Qed.
Lemma Sylow_subnorm p G P : p.-Sylow('N_G(P)) P = p.-Sylow(G) P.
Proof.
apply/idP/idP=> sylP; last first.
apply: pHall_subl (subsetIl _ _) (sylP).
by rewrite subsetI normG (pHall_sub sylP).
have [/subsetIP[sPG sPN] pP _] := and3P sylP.
have [Q sylQ sPQ] := Sylow_superset sPG pP; have [sQG pQ _] := and3P sylQ.
rewrite -(nilpotent_sub_norm (pgroup_nil pQ) sPQ) {sylQ}//.
rewrite subEproper eq_sym eqEcard subsetI sPQ sPN dvdn_leq //.
rewrite -(part_pnat_id (pgroupS (subsetIl _ _) pQ)) (card_Hall sylP).
by rewrite partn_dvd // cardSg ?setSI.
Qed.
End Nilpotent.
Lemma nil_class_pgroup (gT : finGroupType) (p : nat) (P : {group gT}) :
p.-group P -> nil_class P <= maxn 1 (logn p #|P|).-1.
Proof.
move=> pP; move def_c: (nil_class P) => c.
elim: c => // c IHc in gT P def_c pP *; set e := logn p _.
have nilP := pgroup_nil pP; have sZP := center_sub P.
have [e_le2 | e_gt2] := leqP e 2.
by rewrite -def_c leq_max nil_class1 (p2group_abelian pP).
have pPq: p.-group (P / 'Z(P)) by apply: quotient_pgroup.
rewrite -(subnKC e_gt2) ltnS (leq_trans (IHc _ _ _ pPq)) //.
by rewrite nil_class_quotient_center ?def_c.
rewrite geq_max /= -add1n -leq_subLR -subn1 -subnDA -subSS leq_sub2r //.
rewrite ltn_log_quotient //= -(setIidPr sZP) meet_center_nil //.
by rewrite -nil_class0 def_c.
Qed.
Definition Zgroup (gT : finGroupType) (A : {set gT}) :=
[forall (V : {group gT} | Sylow A V), cyclic V].
Section Zgroups.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Implicit Types G H K : {group gT}.
Lemma ZgroupS G H : H \subset G -> Zgroup G -> Zgroup H.
Proof.
move=> sHG /forallP zgG; apply/forall_inP=> V /SylowP[p p_pr /and3P[sVH]].
case/(Sylow_superset (subset_trans sVH sHG))=> P sylP sVP _.
by have:= zgG P; rewrite (p_Sylow sylP); apply: cyclicS.
Qed.
Lemma morphim_Zgroup G : Zgroup G -> Zgroup (f @* G).
Proof.
move=> zgG; wlog sGD: G zgG / G \subset D.
by rewrite -morphimIdom; apply; rewrite (ZgroupS _ zgG, subsetIl) ?subsetIr.
apply/forall_inP=> fV /SylowP[p pr_p sylfV].
have [P sylP] := Sylow_exists p G.
have [|z _ ->] := @Sylow_trans p _ _ (f @* P)%G _ _ sylfV.
by apply: morphim_pHall (sylP); apply: subset_trans (pHall_sub sylP) sGD.
by rewrite cyclicJ morphim_cyclic ?(forall_inP zgG) //; apply/SylowP; exists p.
Qed.
Lemma nil_Zgroup_cyclic G : Zgroup G -> nilpotent G -> cyclic G.
Proof.
have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn ZgG nilG.
have [->|[p pr_p pG]] := trivgVpdiv G; first by rewrite -cycle1 cycle_cyclic.
have /dprodP[_ defG Cpp' _] := nilpotent_pcoreC p nilG.
have /cyclicP[x def_p]: cyclic 'O_p(G).
have:= forallP ZgG 'O_p(G)%G.
by rewrite (p_Sylow (nilpotent_pcore_Hall p nilG)).
have /cyclicP[x' def_p']: cyclic 'O_p^'(G).
have sp'G := pcore_sub p^' G.
apply: IHn (leq_trans _ leGn) (ZgroupS sp'G _) (nilpotentS sp'G _) => //.
rewrite proper_card // properEneq sp'G andbT; case: eqP => //= def_p'.
by have:= pcore_pgroup p^' G; rewrite def_p' /pgroup p'natE ?pG.
apply/cyclicP; exists (x * x'); rewrite -{}defG def_p def_p' cycleM //.
by red; rewrite -(centsP Cpp') // (def_p, def_p') cycle_id.
by rewrite /order -def_p -def_p' (@pnat_coprime p) //; apply: pcore_pgroup.
Qed.
End Zgroups.
Arguments Zgroup {gT} A%_g.
Section NilPGroups.
Variables (p : nat) (gT : finGroupType).
Implicit Type G P N : {group gT}.
(* B & G 1.22 p.9 *)
Lemma normal_pgroup r P N :
p.-group P -> N <| P -> r <= logn p #|N| ->
exists Q : {group gT}, [/\ Q \subset N, Q <| P & #|Q| = (p ^ r)%N].
Proof.
elim: r gT P N => [|r IHr] gTr P N pP nNP le_r.
by exists (1%G : {group gTr}); rewrite sub1G normal1 cards1.
have [NZ_1 | ntNZ] := eqVneq (N :&: 'Z(P)) 1.
by rewrite (TI_center_nil (pgroup_nil pP)) // cards1 logn1 in le_r.
have: p.-group (N :&: 'Z(P)) by apply: pgroupS pP; rewrite /= setICA subsetIl.
case/pgroup_pdiv=> // p_pr /Cauchy[// | z].
rewrite -cycle_subG !subsetI => /and3P[szN szP cPz] ozp _.
have{cPz} nzP: P \subset 'N(<[z]>) by rewrite cents_norm // centsC.
have: N / <[z]> <| P / <[z]> by rewrite morphim_normal.
case/IHr=> [||Qb [sQNb nQPb]]; first exact: morphim_pgroup.
rewrite card_quotient ?(subset_trans (normal_sub nNP)) // -ltnS.
apply: (leq_trans le_r); rewrite -(Lagrange szN) [#|_|]ozp.
by rewrite lognM // ?prime_gt0 // logn_prime ?eqxx.
case/(inv_quotientN _): nQPb sQNb => [|Q -> szQ nQP]; first exact/andP.
have nzQ := subset_trans (normal_sub nQP) nzP.
rewrite quotientSGK // card_quotient // => sQN izQ.
by exists Q; split=> //; rewrite expnS -izQ -ozp Lagrange.
Qed.
Theorem Baer_Suzuki x G :
x \in G -> (forall y, y \in G -> p.-group <<[set x; x ^ y]>>) ->
x \in 'O_p(G).
Proof.
have [n] := ubnP #|G|; elim: n G x => // n IHn G x /ltnSE-leGn Gx pE.
set E := x ^: G; have{} pE: {in E &, forall x1 x2, p.-group <<[set x1; x2]>>}.
move=> _ _ /imsetP[y1 Gy1 ->] /imsetP[y2 Gy2 ->].
rewrite -(mulgKV y1 y2) conjgM -2!conjg_set1 -conjUg genJ pgroupJ.
by rewrite pE // groupMl ?groupV.
have sEG: <<E>> \subset G by rewrite gen_subG class_subG.
have nEG: G \subset 'N(E) by apply: class_norm.
have Ex: x \in E by apply: class_refl.
have [P Px sylP]: exists2 P : {group gT}, x \in P & p.-Sylow(<<E>>) P.
have sxxE: <<[set x; x]>> \subset <<E>> by rewrite genS // setUid sub1set.
have{sxxE} [P sylP sxxP] := Sylow_superset sxxE (pE _ _ Ex Ex).
by exists P => //; rewrite (subsetP sxxP) ?mem_gen ?setU11.
case sEP: (E \subset P).
apply: subsetP Ex; rewrite -gen_subG; apply: pcore_max.
by apply: pgroupS (pHall_pgroup sylP); rewrite gen_subG.
by rewrite /normal gen_subG class_subG // norms_gen.
pose P_yD D := [pred y in E :\: P | p.-group <<y |: D>>].
pose P_D := [pred D : {set gT} | D \subset P :&: E & [exists y, P_yD D y]].
have{Ex Px}: P_D [set x].
rewrite /= sub1set inE Px Ex; apply/existsP=> /=.
by case/subsetPn: sEP => y Ey Py; exists y; rewrite inE Ey Py pE.
case/(@maxset_exists _ P_D)=> D /maxsetP[]; rewrite {P_yD P_D}/=.
rewrite subsetI sub1set -andbA => /and3P[sDP sDE /existsP[y0]].
set B := _ |: D; rewrite inE -andbA => /and3P[Py0 Ey0 pB] maxD Dx.
have sDgE: D \subset <<E>> by apply: sub_gen.
have sDG: D \subset G by apply: subset_trans sEG.
have sBE: B \subset E by rewrite subUset sub1set Ey0.
have sBG: <<B>> \subset G by apply: subset_trans (genS _) sEG.
have sDB: D \subset B by rewrite subsetUr.
have defD: D :=: P :&: <<B>> :&: E.
apply/eqP; rewrite eqEsubset ?subsetI sDP sDE sub_gen //=.
apply/setUidPl; apply: maxD; last apply: subsetUl.
rewrite subUset subsetI sDP sDE setIAC subsetIl.
apply/existsP; exists y0; rewrite inE Py0 Ey0 /= setUA -/B.
by rewrite -[<<_>>]joing_idl joingE setKI genGid.
have nDD: D \subset 'N(D).
apply/subsetP=> z Dz; rewrite inE defD.
apply/subsetP=> _ /imsetP[y /setIP[PBy Ey] ->].
rewrite inE groupJ // ?inE ?(subsetP sDP) ?mem_gen ?setU1r //= memJ_norm //.
exact: (subsetP (subset_trans sDG nEG)).
case nDG: (G \subset 'N(D)).
apply: subsetP Dx; rewrite -gen_subG pcore_max ?(pgroupS (genS _) pB) //.
by rewrite /normal gen_subG sDG norms_gen.
have{n leGn IHn nDG} pN: p.-group <<'N_E(D)>>.
apply: pgroupS (pcore_pgroup p 'N_G(D)); rewrite gen_subG /=.
apply/subsetP=> x1 /setIP[Ex1 Nx1]; apply: IHn => [||y Ny].
- apply: leq_trans leGn; rewrite proper_card // /proper subsetIl.
by rewrite subsetI nDG andbF.
- by rewrite inE Nx1 (subsetP sEG) ?mem_gen.
have Ex1y: x1 ^ y \in E.
by rewrite -mem_conjgV (normsP nEG) // groupV; case/setIP: Ny.
by apply: pgroupS (genS _) (pE _ _ Ex1 Ex1y); apply/subsetP => u /[!inE].
have [y1 Ny1 Py1]: exists2 y1, y1 \in 'N_E(D) & y1 \notin P.
case sNN: ('N_<<B>>('N_<<B>>(D)) \subset 'N_<<B>>(D)).
exists y0 => //; have By0: y0 \in <<B>> by rewrite mem_gen ?setU11.
rewrite inE Ey0 -By0 -in_setI.
by rewrite -['N__(D)](nilpotent_sub_norm (pgroup_nil pB)) ?subsetIl.
case/subsetPn: sNN => z /setIP[Bz NNz]; rewrite inE Bz inE.
case/subsetPn=> y; rewrite mem_conjg => Dzy Dy.
have:= Dzy; rewrite {1}defD; do 2![case/setIP]=> _ Bzy Ezy.
have Ey: y \in E by rewrite -(normsP nEG _ (subsetP sBG z Bz)) mem_conjg.
have /setIP[By Ny]: y \in 'N_<<B>>(D).
by rewrite -(normP NNz) mem_conjg inE Bzy ?(subsetP nDD).
exists y; first by rewrite inE Ey.
by rewrite defD 2!inE Ey By !andbT in Dy.
have [y2 Ny2 Dy2]: exists2 y2, y2 \in 'N_(P :&: E)(D) & y2 \notin D.
case sNN: ('N_P('N_P(D)) \subset 'N_P(D)).
have [z /= Ez sEzP] := Sylow_Jsub sylP (genS sBE) pB.
have Gz: z \in G by apply: subsetP Ez.
have /subsetPn[y Bzy Dy]: ~~ (B :^ z \subset D).
apply/negP; move/subset_leq_card; rewrite cardJg cardsU1.
by rewrite {1}defD 2!inE (negPf Py0) ltnn.
exists y => //; apply: subsetP Bzy.
rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV // sBE.
have nilP := pgroup_nil (pHall_pgroup sylP).
by rewrite -['N__(_)](nilpotent_sub_norm nilP) ?subsetIl // -gen_subG genJ.
case/subsetPn: sNN => z /setIP[Pz NNz]; rewrite 2!inE Pz.
case/subsetPn=> y Dzy Dy; exists y => //; apply: subsetP Dzy.
rewrite -setIA setICA subsetI sub_conjg (normsP nEG) ?groupV //.
by rewrite sDE -(normP NNz); rewrite conjSg subsetI sDP.
by apply: subsetP Pz; apply: (subset_trans (pHall_sub sylP)).
suff{Dy2} Dy2D: y2 |: D = D by rewrite -Dy2D setU11 in Dy2.
apply: maxD; last by rewrite subsetUr.
case/setIP: Ny2 => PEy2 Ny2; case/setIP: Ny1 => Ey1 Ny1.
rewrite subUset sub1set PEy2 subsetI sDP sDE.
apply/existsP; exists y1; rewrite inE Ey1 Py1; apply: pgroupS pN.
rewrite genS // !subUset !sub1set !in_setI Ey1 Ny1.
by case/setIP: PEy2 => _ ->; rewrite Ny2 subsetI sDE.
Qed.
End NilPGroups.
|
Colimits.lean
|
/-
Copyright (c) 2019 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Sophie Morel
-/
import Mathlib.Algebra.Category.Grp.Preadditive
import Mathlib.Algebra.Group.Shrink
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
import Mathlib.Data.DFinsupp.BigOperators
import Mathlib.Data.DFinsupp.Small
import Mathlib.GroupTheory.QuotientGroup.Defs
/-!
# The category of additive commutative groups has all colimits.
This file constructs colimits in the category of additive commutative groups, as
quotients of finitely supported functions.
-/
universe u' w u v
open CategoryTheory Limits
namespace AddCommGrp
variable {J : Type u} [Category.{v} J] (F : J β₯€ AddCommGrp.{w})
namespace Colimits
/-!
We build the colimit of a diagram in `AddCommGrp` by constructing the
free group on the disjoint union of all the abelian groups in the diagram,
then taking the quotient by the abelian group laws within each abelian group,
and the identifications given by the morphisms in the diagram.
-/
/--
The relations between elements of the direct sum of the `F.obj j` given by the
morphisms in the diagram `J`.
-/
abbrev Relations [DecidableEq J] : AddSubgroup (DFinsupp (fun j β¦ F.obj j)) :=
AddSubgroup.closure {x | β (j j' : J) (u : j βΆ j') (a : F.obj j),
x = DFinsupp.single j' (F.map u a) - DFinsupp.single j a}
/--
The candidate for the colimit of `F`, defined as the quotient of the direct sum
of the commutative groups `F.obj j` by the relations given by the morphisms in
the diagram.
-/
def Quot [DecidableEq J] : Type (max u w) :=
DFinsupp (fun j β¦ F.obj j) β§Έ Relations F
instance [DecidableEq J] : AddCommGroup (Quot F) :=
QuotientAddGroup.Quotient.addCommGroup (Relations F)
/-- Inclusion of `F.obj j` into the candidate colimit.
-/
def Quot.ΞΉ [DecidableEq J] (j : J) : F.obj j β+ Quot F :=
(QuotientAddGroup.mk' _).comp (DFinsupp.singleAddHom (fun j β¦ F.obj j) j)
lemma Quot.addMonoidHom_ext [DecidableEq J] {Ξ± : Type*} [AddMonoid Ξ±] {f g : Quot F β+ Ξ±}
(h : β (j : J) (x : F.obj j), f (Quot.ΞΉ F j x) = g (Quot.ΞΉ F j x)) : f = g :=
QuotientAddGroup.addMonoidHom_ext _ (DFinsupp.addHom_ext h)
variable (c : Cocone F)
/-- (implementation detail) Part of the universal property of the colimit cocone, but without
assuming that `Quot F` lives in the correct universe. -/
def Quot.desc [DecidableEq J] : Quot.{w} F β+ c.pt := by
refine QuotientAddGroup.lift _ (DFinsupp.sumAddHom fun x => (c.ΞΉ.app x).hom) ?_
dsimp
rw [AddSubgroup.closure_le]
intro _ β¨_, _, _, _, eqβ©
rw [eq]
simp only [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single]
change (F.map _ β« c.ΞΉ.app _) _ - _ = 0
rw [c.ΞΉ.naturality]
simp only [Functor.const_obj_obj, Functor.const_obj_map, Category.comp_id, sub_self]
@[simp]
lemma Quot.ΞΉ_desc [DecidableEq J] (j : J) (x : F.obj j) :
Quot.desc F c (Quot.ΞΉ F j x) = c.ΞΉ.app j x := by
dsimp [desc, ΞΉ]
erw [QuotientAddGroup.lift_mk']
simp
@[simp]
lemma Quot.map_ΞΉ [DecidableEq J] {j j' : J} {f : j βΆ j'} (x : F.obj j) :
Quot.ΞΉ F j' (F.map f x) = Quot.ΞΉ F j x := by
dsimp [ΞΉ]
refine eq_of_sub_eq_zero ?_
erw [β (QuotientAddGroup.mk' (Relations F)).map_sub, β AddMonoidHom.mem_ker]
rw [QuotientAddGroup.ker_mk']
simp only [DFinsupp.singleAddHom_apply]
exact AddSubgroup.subset_closure β¨j, j', f, x, rflβ©
/--
The obvious additive map from `Quot F` to `Quot (F β uliftFunctor.{u'})`.
-/
def quotToQuotUlift [DecidableEq J] : Quot F β+ Quot (F β uliftFunctor.{u'}) := by
refine QuotientAddGroup.lift (Relations F) (DFinsupp.sumAddHom (fun j β¦ (Quot.ΞΉ _ j).comp
AddEquiv.ulift.symm.toAddMonoidHom)) ?_
rw [AddSubgroup.closure_le]
intro _ hx
obtain β¨j, j', u, a, rflβ© := hx
rw [SetLike.mem_coe, AddMonoidHom.mem_ker, map_sub, DFinsupp.sumAddHom_single,
DFinsupp.sumAddHom_single]
change Quot.ΞΉ (F β uliftFunctor) j' ((F β uliftFunctor).map u (AddEquiv.ulift.symm a)) - _ = _
rw [Quot.map_ΞΉ]
dsimp
rw [sub_self]
lemma quotToQuotUlift_ΞΉ [DecidableEq J] (j : J) (x : F.obj j) :
quotToQuotUlift F (Quot.ΞΉ F j x) = Quot.ΞΉ _ j (ULift.up x) := by
dsimp [quotToQuotUlift, Quot.ΞΉ]
conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations F))
(DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk']
simp only [DFinsupp.singleAddHom_apply, DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp,
AddMonoidHom.coe_coe, Function.comp_apply]
rfl
/--
The obvious additive map from `Quot (F β uliftFunctor.{u'})` to `Quot F`.
-/
def quotUliftToQuot [DecidableEq J] : Quot (F β uliftFunctor.{u'}) β+ Quot F := by
refine QuotientAddGroup.lift (Relations (F β uliftFunctor))
(DFinsupp.sumAddHom (fun j β¦ (Quot.ΞΉ _ j).comp AddEquiv.ulift.toAddMonoidHom)) ?_
rw [AddSubgroup.closure_le]
intro _ hx
obtain β¨j, j', u, a, rflβ© := hx
simp
lemma quotUliftToQuot_ΞΉ [DecidableEq J] (j : J) (x : (F β uliftFunctor.{u'}).obj j) :
quotUliftToQuot F (Quot.ΞΉ _ j x) = Quot.ΞΉ F j x.down := by
dsimp [quotUliftToQuot, Quot.ΞΉ]
conv_lhs => erw [AddMonoidHom.comp_apply (QuotientAddGroup.mk' (Relations (F β uliftFunctor)))
(DFinsupp.singleAddHom _ j), QuotientAddGroup.lift_mk']
simp only [Functor.comp_obj, uliftFunctor_obj, DFinsupp.singleAddHom_apply,
DFinsupp.sumAddHom_single, AddMonoidHom.coe_comp, AddMonoidHom.coe_coe, Function.comp_apply]
rfl
/--
The additive equivalence between `Quot F` and `Quot (F β uliftFunctor.{u'})`.
-/
@[simp]
def quotQuotUliftAddEquiv [DecidableEq J] : Quot F β+ Quot (F β uliftFunctor.{u'}) where
toFun := quotToQuotUlift F
invFun := quotUliftToQuot F
left_inv x := by
conv_rhs => rw [β AddMonoidHom.id_apply _ x]
rw [β AddMonoidHom.comp_apply, Quot.addMonoidHom_ext F (f := (quotUliftToQuot F).comp
(quotToQuotUlift F)) (fun j a β¦ ?_)]
rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotToQuotUlift_ΞΉ, quotUliftToQuot_ΞΉ]
right_inv x := by
conv_rhs => rw [β AddMonoidHom.id_apply _ x]
rw [β AddMonoidHom.comp_apply, Quot.addMonoidHom_ext _ (f := (quotToQuotUlift F).comp
(quotUliftToQuot F)) (fun j a β¦ ?_)]
rw [AddMonoidHom.comp_apply, AddMonoidHom.id_apply, quotUliftToQuot_ΞΉ, quotToQuotUlift_ΞΉ]
rfl
map_add' _ _ := by simp
lemma Quot.desc_quotQuotUliftAddEquiv [DecidableEq J] (c : Cocone F) :
(Quot.desc (F β uliftFunctor.{u'}) (uliftFunctor.{u'}.mapCocone c)).comp
(quotQuotUliftAddEquiv F).toAddMonoidHom =
AddEquiv.ulift.symm.toAddMonoidHom.comp (Quot.desc F c) := by
refine Quot.addMonoidHom_ext _ (fun j a β¦ ?_)
dsimp
simp only [quotToQuotUlift_ΞΉ, Functor.comp_obj, uliftFunctor_obj, ΞΉ_desc, Functor.const_obj_obj,
ΞΉ_desc]
erw [Quot.ΞΉ_desc]
rfl
/-- (implementation detail) A morphism of commutative additive groups `Quot F β+ A`
induces a cocone on `F` as long as the universes work out.
-/
@[simps]
def toCocone [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F β+ A) : Cocone F where
pt := AddCommGrp.of A
ΞΉ.app j := ofHom <| f.comp (Quot.ΞΉ F j)
lemma Quot.desc_toCocone_desc [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F β+ A)
(hc : IsColimit c) : (hc.desc (toCocone F f)).hom.comp (Quot.desc F c) = f := by
refine Quot.addMonoidHom_ext F (fun j x β¦ ?_)
rw [AddMonoidHom.comp_apply, ΞΉ_desc]
change (c.ΞΉ.app j β« hc.desc (toCocone F f)) _ = _
rw [hc.fac]
simp
lemma Quot.desc_toCocone_desc_app [DecidableEq J] {A : Type w} [AddCommGroup A] (f : Quot F β+ A)
(hc : IsColimit c) (x : Quot F) : hc.desc (toCocone F f) (Quot.desc F c x) = f x := by
conv_rhs => rw [β Quot.desc_toCocone_desc F c f hc]
dsimp
/--
If `c` is a cocone of `F` such that `Quot.desc F c` is bijective, then `c` is a colimit
cocone of `F`.
-/
noncomputable def isColimit_of_bijective_desc [DecidableEq J]
(h : Function.Bijective (Quot.desc F c)) : IsColimit c where
desc s := AddCommGrp.ofHom ((Quot.desc F s).comp (AddEquiv.ofBijective
(Quot.desc F c) h).symm.toAddMonoidHom)
fac s j := by
ext x
dsimp
conv_lhs => erw [β Quot.ΞΉ_desc F c j x]
rw [β AddEquiv.ofBijective_apply _ h, AddEquiv.symm_apply_apply]
simp only [Quot.ΞΉ_desc, Functor.const_obj_obj]
uniq s m hm := by
ext x
obtain β¨x, rflβ© := h.2 x
dsimp
rw [β AddEquiv.ofBijective_apply _ h, AddEquiv.symm_apply_apply]
suffices eq : m.hom.comp (AddEquiv.ofBijective (Quot.desc F c) h) = Quot.desc F s by
rw [β eq]; rfl
exact Quot.addMonoidHom_ext F (by simp [β hm])
/-- (internal implementation) The colimit cocone of a functor `F`, implemented as a quotient of
`DFinsupp (fun j β¦ F.obj j)`, under the assumption that said quotient is small.
-/
@[simps pt ΞΉ_app]
noncomputable def colimitCocone [DecidableEq J] [Small.{w} (Quot.{w} F)] : Cocone F where
pt := AddCommGrp.of (Shrink (Quot F))
ΞΉ :=
{ app j :=
AddCommGrp.ofHom (Shrink.addEquiv.symm.toAddMonoidHom.comp (Quot.ΞΉ F j))
naturality _ _ _ := by
ext
dsimp
change Shrink.addEquiv.symm _ = _
rw [Quot.map_ΞΉ] }
@[simp]
theorem Quot.desc_colimitCocone [DecidableEq J] (F : J β₯€ AddCommGrp.{w}) [Small.{w} (Quot F)] :
Quot.desc F (colimitCocone F) = (Shrink.addEquiv (Ξ± := Quot F)).symm.toAddMonoidHom := by
refine Quot.addMonoidHom_ext F (fun j x β¦ ?_)
simpa only [colimitCocone_pt, AddEquiv.toAddMonoidHom_eq_coe, AddMonoidHom.coe_coe]
using Quot.ΞΉ_desc F (colimitCocone F) j x
/-- (internal implementation) The fact that the candidate colimit cocone constructed in
`colimitCocone` is the colimit.
-/
noncomputable def colimitCoconeIsColimit [DecidableEq J] [Small.{w} (Quot F)] :
IsColimit (colimitCocone F) := by
refine isColimit_of_bijective_desc F _ ?_
rw [Quot.desc_colimitCocone]
exact Shrink.addEquiv.symm.bijective
end Colimits
open Colimits
lemma hasColimit_of_small_quot [DecidableEq J] (h : Small.{w} (Quot F)) : HasColimit F :=
β¨_, colimitCoconeIsColimit Fβ©
instance [DecidableEq J] [Small.{w} J] : Small.{w} (Quot F) :=
small_of_surjective (QuotientAddGroup.mk'_surjective _)
instance hasColimit [Small.{w} J] (F : J β₯€ AddCommGrp.{w}) : HasColimit F := by
classical
exact hasColimit_of_small_quot F inferInstance
/--
If `J` is `w`-small, then any functor `J β₯€ AddCommGrp.{w}` has a colimit.
-/
instance hasColimitsOfShape [Small.{w} J] : HasColimitsOfShape J (AddCommGrp.{w}) where
/-- The category of additive commutative groups has all small colimits.
-/
instance (priority := 1300) hasColimitsOfSize [UnivLE.{u, w}] :
HasColimitsOfSize.{v, u} (AddCommGrp.{w}) where
end AddCommGrp
namespace AddCommGrp
open QuotientAddGroup
/-- The categorical cokernel of a morphism in `AddCommGrp`
agrees with the usual group-theoretical quotient.
-/
noncomputable def cokernelIsoQuotient {G H : AddCommGrp.{u}} (f : G βΆ H) :
cokernel f β
AddCommGrp.of (H β§Έ AddMonoidHom.range f.hom) where
hom := cokernel.desc f (ofHom (mk' _)) <| by
ext x
simp
inv := ofHom <|
QuotientAddGroup.lift _ (cokernel.Ο f).hom <| by
rintro _ β¨x, rflβ©
exact cokernel.condition_apply f x
hom_inv_id := by
refine coequalizer.hom_ext ?_
simp only [coequalizer_as_cokernel, cokernel.Ο_desc_assoc, Category.comp_id]
rfl
inv_hom_id := by
ext x
dsimp only [hom_comp, hom_ofHom, hom_zero, AddMonoidHom.coe_comp, coe_mk',
Function.comp_apply, AddMonoidHom.zero_apply, id_eq, lift_mk, hom_id, AddMonoidHom.coe_id]
exact QuotientAddGroup.induction_on (Ξ± := H) x <| cokernel.Ο_desc_apply f _ _
end AddCommGrp
|
ULift.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Jannis Limperg
-/
import Mathlib.Init
/-!
# Monadic instances for `ULift` and `PLift`
In this file we define `Monad` and `IsLawfulMonad` instances on `PLift` and `ULift`. -/
universe u v u' v'
namespace PLift
variable {Ξ± : Sort u} {Ξ² : Sort v}
/-- Functorial action. -/
protected def map (f : Ξ± β Ξ²) (a : PLift Ξ±) : PLift Ξ² :=
PLift.up (f a.down)
@[simp]
theorem map_up (f : Ξ± β Ξ²) (a : Ξ±) : (PLift.up a).map f = PLift.up (f a) :=
rfl
/-- Embedding of pure values. -/
@[simp]
protected def pure : Ξ± β PLift Ξ± :=
up
/-- Applicative sequencing. -/
protected def seq (f : PLift (Ξ± β Ξ²)) (x : Unit β PLift Ξ±) : PLift Ξ² :=
PLift.up (f.down (x ()).down)
@[simp]
theorem seq_up (f : Ξ± β Ξ²) (x : Ξ±) : (PLift.up f).seq (fun _ => PLift.up x) = PLift.up (f x) :=
rfl
/-- Monadic bind. -/
protected def bind (a : PLift Ξ±) (f : Ξ± β PLift Ξ²) : PLift Ξ² :=
f a.down
@[simp]
theorem bind_up (a : Ξ±) (f : Ξ± β PLift Ξ²) : (PLift.up a).bind f = f a :=
rfl
instance : Monad PLift where
map := @PLift.map
pure := @PLift.pure
seq := @PLift.seq
bind := @PLift.bind
instance : LawfulFunctor PLift where
id_map := @fun _ β¨_β© => rfl
comp_map := @fun _ _ _ _ _ β¨_β© => rfl
map_const := @fun _ _ => rfl
instance : LawfulApplicative PLift where
seqLeft_eq := @fun _ _ _ _ => rfl
seqRight_eq := @fun _ _ _ _ => rfl
pure_seq := @fun _ _ _ β¨_β© => rfl
map_pure := @fun _ _ _ _ => rfl
seq_pure := @fun _ _ β¨_β© _ => rfl
seq_assoc := @fun _ _ _ β¨_β© β¨_β© β¨_β© => rfl
instance : LawfulMonad PLift where
bind_pure_comp := @fun _ _ _ β¨_β© => rfl
bind_map := @fun _ _ β¨_β© β¨_β© => rfl
pure_bind := @fun _ _ _ _ => rfl
bind_assoc := @fun _ _ _ β¨_β© _ _ => rfl
@[simp]
theorem rec.constant {Ξ± : Sort u} {Ξ² : Type v} (b : Ξ²) :
(@PLift.rec Ξ± (fun _ => Ξ²) fun _ => b) = fun _ => b := rfl
end PLift
namespace ULift
variable {Ξ± : Type u} {Ξ² : Type v}
/-- Functorial action. -/
protected def map (f : Ξ± β Ξ²) (a : ULift.{u'} Ξ±) : ULift.{v'} Ξ² := ULift.up.{v'} (f a.down)
@[simp]
theorem map_up (f : Ξ± β Ξ²) (a : Ξ±) : (ULift.up.{u'} a).map f = ULift.up.{v'} (f a) := rfl
/-- Embedding of pure values. -/
@[simp]
protected def pure : Ξ± β ULift Ξ± :=
up
/-- Applicative sequencing. -/
protected def seq {Ξ± Ξ²} (f : ULift (Ξ± β Ξ²)) (x : Unit β ULift Ξ±) : ULift Ξ² :=
ULift.up.{u} (f.down (x ()).down)
@[simp]
theorem seq_up (f : Ξ± β Ξ²) (x : Ξ±) : (ULift.up f).seq (fun _ => ULift.up x) = ULift.up (f x) :=
rfl
/-- Monadic bind. -/
protected def bind (a : ULift Ξ±) (f : Ξ± β ULift Ξ²) : ULift Ξ² :=
f a.down
@[simp]
theorem bind_up (a : Ξ±) (f : Ξ± β ULift Ξ²) : (ULift.up a).bind f = f a :=
rfl
instance : Monad ULift where
map := @ULift.map
pure := @ULift.pure
seq := @ULift.seq
bind := @ULift.bind
instance : LawfulFunctor ULift where
id_map := @fun _ β¨_β© => rfl
comp_map := @fun _ _ _ _ _ β¨_β© => rfl
map_const := @fun _ _ => rfl
instance : LawfulApplicative ULift where
seqLeft_eq := @fun _ _ _ _ => rfl
seqRight_eq := @fun _ _ _ _ => rfl
pure_seq := @fun _ _ _ β¨_β© => rfl
map_pure := @fun _ _ _ _ => rfl
seq_pure := @fun _ _ β¨_β© _ => rfl
seq_assoc := @fun _ _ _ β¨_β© β¨_β© β¨_β© => rfl
instance : LawfulMonad ULift where
bind_pure_comp := @fun _ _ _ β¨_β© => rfl
bind_map := @fun _ _ β¨_β© β¨_β© => rfl
pure_bind := @fun _ _ _ _ => rfl
bind_assoc := @fun _ _ _ β¨_β© _ _ => rfl
@[simp]
theorem rec.constant {Ξ± : Type u} {Ξ² : Sort v} (b : Ξ²) :
(@ULift.rec Ξ± (fun _ => Ξ²) fun _ => b) = fun _ => b := rfl
end ULift
|
KanComplex.lean
|
/-
Copyright (c) 2023 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, JoΓ«l Riou
-/
import Mathlib.AlgebraicTopology.ModelCategory.IsCofibrant
import Mathlib.AlgebraicTopology.SimplicialSet.CategoryWithFibrations
import Mathlib.AlgebraicTopology.SimplicialSet.Subcomplex
/-!
# Kan complexes
In this file, the abbreviation `KanComplex` is introduced for
fibrant objects in the category `SSet` which is equipped with
Kan fibrations.
In `Mathlib/AlgebraicTopology/Quasicategory/Basic.lean`
we show that every Kan complex is a quasicategory.
## TODO
- Show that the singular simplicial set of a topological space is a Kan complex.
-/
universe u
namespace SSet
open CategoryTheory Simplicial Limits
open modelCategoryQuillen in
/-- A simplicial set `S` is a Kan complex if it is fibrant, which means that
the projection `S βΆ β€_ _` has the right lifting property with respect to horn inclusions. -/
abbrev KanComplex (S : SSet.{u}) : Prop := HomotopicalAlgebra.IsFibrant S
/-- A Kan complex `S` satisfies the following horn-filling condition:
for every nonzero `n : β` and `0 β€ i β€ n`,
every map of simplicial sets `Οβ : Ξ[n, i] β S` can be extended to a map `Ο : Ξ[n] β S`. -/
lemma KanComplex.hornFilling {S : SSet.{u}} [KanComplex S]
{n : β} {i : Fin (n + 2)} (Οβ : (Ξ[n + 1, i] : SSet) βΆ S) :
β Ο : Ξ[n + 1] βΆ S, Οβ = Ξ[n + 1, i].ΞΉ β« Ο := by
have sq' : CommSq Οβ Ξ[n + 1, i].ΞΉ (terminal.from S) (terminal.from _) := β¨by simpβ©
exact β¨sq'.lift, by simpβ©
end SSet
|
Strong.lean
|
/-
Copyright (c) 2023 YaΓ«l Dillies, Chenyi Li. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chenyi Li, Ziyu Wang, YaΓ«l Dillies
-/
import Mathlib.Analysis.Convex.Function
import Mathlib.Analysis.InnerProductSpace.Basic
/-!
# Uniformly and strongly convex functions
In this file, we define uniformly convex functions and strongly convex functions.
For a real normed space `E`, a uniformly convex function with modulus `Ο : β β β` is a function
`f : E β β` such that `f (t β’ x + (1 - t) β’ y) β€ t β’ f x + (1 - t) β’ f y - t * (1 - t) * Ο βx - yβ`
for all `t β [0, 1]`.
A `m`-strongly convex function is a uniformly convex function with modulus `fun r β¦ m / 2 * r ^ 2`.
If `E` is an inner product space, this is equivalent to `x β¦ f x - m / 2 * βxβ ^ 2` being convex.
## TODO
Prove derivative properties of strongly convex functions.
-/
open Real
variable {E : Type*} [NormedAddCommGroup E]
section NormedSpace
variable [NormedSpace β E] {Ο Ο : β β β} {s : Set E} {m : β} {f g : E β β}
/-- A function `f` from a real normed space is uniformly convex with modulus `Ο` if
`f (t β’ x + (1 - t) β’ y) β€ t β’ f x + (1 - t) β’ f y - t * (1 - t) * Ο βx - yβ` for all `t β [0, 1]`.
`Ο` is usually taken to be a monotone function such that `Ο r = 0 β r = 0`. -/
def UniformConvexOn (s : Set E) (Ο : β β β) (f : E β β) : Prop :=
Convex β s β§ β β¦xβ¦, x β s β β β¦yβ¦, y β s β β β¦a b : ββ¦, 0 β€ a β 0 β€ b β a + b = 1 β
f (a β’ x + b β’ y) β€ a β’ f x + b β’ f y - a * b * Ο βx - yβ
/-- A function `f` from a real normed space is uniformly concave with modulus `Ο` if
`t β’ f x + (1 - t) β’ f y + t * (1 - t) * Ο βx - yβ β€ f (t β’ x + (1 - t) β’ y)` for all `t β [0, 1]`.
`Ο` is usually taken to be a monotone function such that `Ο r = 0 β r = 0`. -/
def UniformConcaveOn (s : Set E) (Ο : β β β) (f : E β β) : Prop :=
Convex β s β§ β β¦xβ¦, x β s β β β¦yβ¦, y β s β β β¦a b : ββ¦, 0 β€ a β 0 β€ b β a + b = 1 β
a β’ f x + b β’ f y + a * b * Ο βx - yβ β€ f (a β’ x + b β’ y)
@[simp] lemma uniformConvexOn_zero : UniformConvexOn s 0 f β ConvexOn β s f := by
simp [UniformConvexOn, ConvexOn]
@[simp] lemma uniformConcaveOn_zero : UniformConcaveOn s 0 f β ConcaveOn β s f := by
simp [UniformConcaveOn, ConcaveOn]
protected alias β¨_, ConvexOn.uniformConvexOn_zeroβ© := uniformConvexOn_zero
protected alias β¨_, ConcaveOn.uniformConcaveOn_zeroβ© := uniformConcaveOn_zero
lemma UniformConvexOn.mono (hΟΟ : Ο β€ Ο) (hf : UniformConvexOn s Ο f) : UniformConvexOn s Ο f :=
β¨hf.1, fun x hx y hy a b ha hb hab β¦ (hf.2 hx hy ha hb hab).trans <| by gcongr; apply hΟΟβ©
lemma UniformConcaveOn.mono (hΟΟ : Ο β€ Ο) (hf : UniformConcaveOn s Ο f) : UniformConcaveOn s Ο f :=
β¨hf.1, fun x hx y hy a b ha hb hab β¦ (hf.2 hx hy ha hb hab).trans' <| by gcongr; apply hΟΟβ©
lemma UniformConvexOn.convexOn (hf : UniformConvexOn s Ο f) (hΟ : 0 β€ Ο) : ConvexOn β s f := by
simpa using hf.mono hΟ
lemma UniformConcaveOn.concaveOn (hf : UniformConcaveOn s Ο f) (hΟ : 0 β€ Ο) : ConcaveOn β s f := by
simpa using hf.mono hΟ
lemma UniformConvexOn.strictConvexOn (hf : UniformConvexOn s Ο f) (hΟ : β r, r β 0 β 0 < Ο r) :
StrictConvexOn β s f := by
refine β¨hf.1, fun x hx y hy hxy a b ha hb hab β¦ (hf.2 hx hy ha.le hb.le hab).trans_lt <|
sub_lt_self _ ?_β©
rw [β sub_ne_zero, β norm_pos_iff] at hxy
have := hΟ _ hxy.ne'
positivity
lemma UniformConcaveOn.strictConcaveOn (hf : UniformConcaveOn s Ο f) (hΟ : β r, r β 0 β 0 < Ο r) :
StrictConcaveOn β s f := by
refine β¨hf.1, fun x hx y hy hxy a b ha hb hab β¦ (hf.2 hx hy ha.le hb.le hab).trans_lt' <|
lt_add_of_pos_right _ ?_β©
rw [β sub_ne_zero, β norm_pos_iff] at hxy
have := hΟ _ hxy.ne'
positivity
lemma UniformConvexOn.add (hf : UniformConvexOn s Ο f) (hg : UniformConvexOn s Ο g) :
UniformConvexOn s (Ο + Ο) (f + g) := by
refine β¨hf.1, fun x hx y hy a b ha hb hab β¦ ?_β©
simpa [mul_add, add_add_add_comm, sub_add_sub_comm]
using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConcaveOn.add (hf : UniformConcaveOn s Ο f) (hg : UniformConcaveOn s Ο g) :
UniformConcaveOn s (Ο + Ο) (f + g) := by
refine β¨hf.1, fun x hx y hy a b ha hb hab β¦ ?_β©
simpa [mul_add, add_add_add_comm] using add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab)
lemma UniformConvexOn.neg (hf : UniformConvexOn s Ο f) : UniformConcaveOn s Ο (-f) := by
refine β¨hf.1, fun x hx y hy a b ha hb hab β¦ le_of_neg_le_neg ?_β©
simpa [add_comm, -neg_le_neg_iff, le_sub_iff_add_le'] using hf.2 hx hy ha hb hab
lemma UniformConcaveOn.neg (hf : UniformConcaveOn s Ο f) : UniformConvexOn s Ο (-f) := by
refine β¨hf.1, fun x hx y hy a b ha hb hab β¦ le_of_neg_le_neg ?_β©
simpa [add_comm, -neg_le_neg_iff, β le_sub_iff_add_le', sub_eq_add_neg, neg_add]
using hf.2 hx hy ha hb hab
lemma UniformConvexOn.sub (hf : UniformConvexOn s Ο f) (hg : UniformConcaveOn s Ο g) :
UniformConvexOn s (Ο + Ο) (f - g) := by simpa using hf.add hg.neg
lemma UniformConcaveOn.sub (hf : UniformConcaveOn s Ο f) (hg : UniformConvexOn s Ο g) :
UniformConcaveOn s (Ο + Ο) (f - g) := by simpa using hf.add hg.neg
/-- A function `f` from a real normed space is `m`-strongly convex if it is uniformly convex with
modulus `Ο(r) = m / 2 * r ^ 2`.
In an inner product space, this is equivalent to `x β¦ f x - m / 2 * βxβ ^ 2` being convex. -/
def StrongConvexOn (s : Set E) (m : β) : (E β β) β Prop :=
UniformConvexOn s fun r β¦ m / (2 : β) * r ^ 2
/-- A function `f` from a real normed space is `m`-strongly concave if is strongly concave with
modulus `Ο(r) = m / 2 * r ^ 2`.
In an inner product space, this is equivalent to `x β¦ f x + m / 2 * βxβ ^ 2` being concave. -/
def StrongConcaveOn (s : Set E) (m : β) : (E β β) β Prop :=
UniformConcaveOn s fun r β¦ m / (2 : β) * r ^ 2
variable {s : Set E} {f : E β β} {m n : β}
nonrec lemma StrongConvexOn.mono (hmn : m β€ n) (hf : StrongConvexOn s n f) : StrongConvexOn s m f :=
hf.mono fun r β¦ by gcongr
nonrec lemma StrongConcaveOn.mono (hmn : m β€ n) (hf : StrongConcaveOn s n f) :
StrongConcaveOn s m f := hf.mono fun r β¦ by gcongr
@[simp] lemma strongConvexOn_zero : StrongConvexOn s 0 f β ConvexOn β s f := by
simp [StrongConvexOn, β Pi.zero_def]
@[simp] lemma strongConcaveOn_zero : StrongConcaveOn s 0 f β ConcaveOn β s f := by
simp [StrongConcaveOn, β Pi.zero_def]
nonrec lemma StrongConvexOn.strictConvexOn (hf : StrongConvexOn s m f) (hm : 0 < m) :
StrictConvexOn β s f := hf.strictConvexOn fun r hr β¦ by positivity
nonrec lemma StrongConcaveOn.strictConcaveOn (hf : StrongConcaveOn s m f) (hm : 0 < m) :
StrictConcaveOn β s f := hf.strictConcaveOn fun r hr β¦ by positivity
end NormedSpace
section InnerProductSpace
variable [InnerProductSpace β E] {s : Set E} {a b m : β} {x y : E} {f : E β β}
private lemma aux_sub (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1) :
a * (f x - m / (2 : β) * βxβ ^ 2) + b * (f y - m / (2 : β) * βyβ ^ 2) +
m / (2 : β) * βa β’ x + b β’ yβ ^ 2
= a * f x + b * f y - m / (2 : β) * a * b * βx - yβ ^ 2 := by
rw [norm_add_sq_real, norm_sub_sq_real, norm_smul, norm_smul, real_inner_smul_left,
inner_smul_right, norm_of_nonneg ha, norm_of_nonneg hb, mul_pow, mul_pow]
obtain rfl := eq_sub_of_add_eq hab
ring_nf
private lemma aux_add (ha : 0 β€ a) (hb : 0 β€ b) (hab : a + b = 1) :
a * (f x + m / (2 : β) * βxβ ^ 2) + b * (f y + m / (2 : β) * βyβ ^ 2) -
m / (2 : β) * βa β’ x + b β’ yβ ^ 2
= a * f x + b * f y + m / (2 : β) * a * b * βx - yβ ^ 2 := by
simpa [neg_div] using aux_sub (E := E) (m := -m) ha hb hab
lemma strongConvexOn_iff_convex :
StrongConvexOn s m f β ConvexOn β s fun x β¦ f x - m / (2 : β) * βxβ ^ 2 := by
refine and_congr_right fun _ β¦ forallβ_congr fun x _ y _ β¦ forallβ
_congr fun a b ha hb hab β¦ ?_
simp_rw [sub_le_iff_le_add, smul_eq_mul, aux_sub ha hb hab, mul_assoc, mul_left_comm]
lemma strongConcaveOn_iff_convex :
StrongConcaveOn s m f β ConcaveOn β s fun x β¦ f x + m / (2 : β) * βxβ ^ 2 := by
refine and_congr_right fun _ β¦ forallβ_congr fun x _ y _ β¦ forallβ
_congr fun a b ha hb hab β¦ ?_
simp_rw [β sub_le_iff_le_add, smul_eq_mul, aux_add ha hb hab, mul_assoc, mul_left_comm]
end InnerProductSpace
|
OneDim.lean
|
/-
Copyright (c) 2022 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Covering.DensityTheorem
import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar
/-!
# Covering theorems for Lebesgue measure in one dimension
We have a general theory of covering theorems for doubling measures, developed notably
in `DensityTheorem.lean`. In this file, we expand the API for this theory in one dimension,
by showing that intervals belong to the relevant Vitali family.
-/
open Set MeasureTheory IsUnifLocDoublingMeasure Filter
open scoped Topology
namespace Real
theorem Icc_mem_vitaliFamily_at_right {x y : β} (hxy : x < y) :
Icc x y β (vitaliFamily (volume : Measure β) 1).setsAt x := by
rw [Icc_eq_closedBall]
refine closedBall_mem_vitaliFamily_of_dist_le_mul _ ?_ (by linarith)
rw [dist_comm, Real.dist_eq, abs_of_nonneg] <;> linarith
theorem tendsto_Icc_vitaliFamily_right (x : β) :
Tendsto (fun y => Icc x y) (π[>] x) ((vitaliFamily (volume : Measure β) 1).filterAt x) := by
refine (VitaliFamily.tendsto_filterAt_iff _).2 β¨?_, ?_β©
Β· filter_upwards [self_mem_nhdsWithin] with y hy using Icc_mem_vitaliFamily_at_right hy
Β· intro Ξ΅ Ξ΅pos
filter_upwards [Icc_mem_nhdsGT <| show x < x + Ξ΅ by linarith] with y hy
rw [closedBall_eq_Icc]
exact Icc_subset_Icc (by linarith) hy.2
theorem Icc_mem_vitaliFamily_at_left {x y : β} (hxy : x < y) :
Icc x y β (vitaliFamily (volume : Measure β) 1).setsAt y := by
rw [Icc_eq_closedBall]
refine closedBall_mem_vitaliFamily_of_dist_le_mul _ ?_ (by linarith)
rw [Real.dist_eq, abs_of_nonneg] <;> linarith
theorem tendsto_Icc_vitaliFamily_left (x : β) :
Tendsto (fun y => Icc y x) (π[<] x) ((vitaliFamily (volume : Measure β) 1).filterAt x) := by
refine (VitaliFamily.tendsto_filterAt_iff _).2 β¨?_, ?_β©
Β· filter_upwards [self_mem_nhdsWithin] with y hy using Icc_mem_vitaliFamily_at_left hy
Β· intro Ξ΅ Ξ΅pos
filter_upwards [Icc_mem_nhdsLT <| show x - Ξ΅ < x by linarith] with y hy
rw [closedBall_eq_Icc]
exact Icc_subset_Icc hy.1 (by linarith)
end Real
|
separable.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 div.
From mathcomp Require Import choice fintype tuple finfun bigop finset prime.
From mathcomp Require Import binomial ssralg poly polydiv fingroup perm.
From mathcomp Require Import morphism quotient gproduct finalg zmodp cyclic.
From mathcomp Require Import matrix mxalgebra mxpoly polyXY vector falgebra.
From mathcomp Require Import fieldext.
(******************************************************************************)
(* This file provides a theory of separable and inseparable field extensions. *)
(* *)
(* separable_poly p <=> p has no multiple roots in any field extension. *)
(* separable_element K x <=> the minimal polynomial of x over K is separable. *)
(* separable K E <=> every member of E is separable over K. *)
(* separable_generator K E == some x \in E that generates the largest *)
(* subfield K[x] that is separable over K. *)
(* purely_inseparable_element K x <=> there is a [pchar L].-nat n such that *)
(* x ^+ n \in K. *)
(* purely_inseparable K E <=> every member of E is purely inseparable over K. *)
(* *)
(* Derivations are introduced to prove the adjoin_separableP Lemma: *)
(* Derivation K D <=> the linear operator D satisfies the Leibniz *)
(* product rule inside K. *)
(* extendDerivation x D K == given a derivation D on K and a separable *)
(* element x over K, this function returns the *)
(* unique extension of D to K(x). *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import GRing.Theory.
HB.lock
Definition separable_poly {R : idomainType} (p : {poly R}) := coprimep p p^`().
Canonical separable_poly_unlockable := Unlockable separable_poly.unlock.
Section SeparablePoly.
Variable R : idomainType.
Implicit Types p q d u v : {poly R}.
Local Notation separable := (@separable_poly R).
Local Notation lcn_neq0 := (Pdiv.Idomain.lc_expn_scalp_neq0 _).
Lemma separable_poly_neq0 p : separable p -> p != 0.
Proof.
by apply: contraTneq => ->; rewrite unlock deriv0 coprime0p eqp01.
Qed.
Lemma poly_square_freeP p :
(forall u v, u * v %| p -> coprimep u v)
<-> (forall u, size u != 1 -> ~~ (u ^+ 2 %| p)).
Proof.
split=> [sq'p u | sq'p u v dvd_uv_p].
by apply: contra => /sq'p; rewrite coprimepp.
rewrite coprimep_def (contraLR (sq'p _)) // (dvdp_trans _ dvd_uv_p) //.
by rewrite dvdp_mul ?dvdp_gcdl ?dvdp_gcdr.
Qed.
Lemma separable_polyP {p} :
reflect [/\ forall u v, u * v %| p -> coprimep u v
& forall u, u %| p -> 1 < size u -> u^`() != 0]
(separable p).
Proof.
apply: (iffP idP) => [sep_p | [sq'p nz_der1p]].
split=> [u v | u u_dv_p]; last first.
apply: contraTneq => u'0; rewrite unlock in sep_p; rewrite -leqNgt -(eqnP sep_p).
rewrite dvdp_leq -?size_poly_eq0 ?(eqnP sep_p) // dvdp_gcd u_dv_p.
have /dvdpZr <-: lead_coef u ^+ scalp p u != 0 by rewrite lcn_neq0.
by rewrite -derivZ -Pdiv.Idomain.divpK //= derivM u'0 mulr0 addr0 dvdp_mull.
rewrite Pdiv.Idomain.dvdp_eq mulrCA mulrA; set c := _ ^+ _ => /eqP Dcp.
have nz_c: c != 0 by rewrite lcn_neq0.
move: sep_p; rewrite coprimep_sym unlock -(coprimepZl _ _ nz_c).
rewrite -(coprimepZr _ _ nz_c) -derivZ Dcp derivM coprimepMl.
by rewrite coprimep_addl_mul !coprimepMr -andbA => /and4P[].
rewrite unlock coprimep_def eqn_leq size_poly_gt0; set g := gcdp _ _.
have nz_g: g != 0.
rewrite -dvd0p dvdp_gcd -(mulr0 0); apply/nandP; left.
by have /poly_square_freeP-> := sq'p; rewrite ?size_poly0.
have [g_p]: g %| p /\ g %| p^`() by rewrite dvdp_gcdr ?dvdp_gcdl.
pose c := lead_coef g ^+ scalp p g; have nz_c: c != 0 by rewrite lcn_neq0.
have Dcp: c *: p = p %/ g * g by rewrite Pdiv.Idomain.divpK.
rewrite nz_g andbT leqNgt -(dvdpZr _ _ nz_c) -derivZ Dcp derivM.
rewrite dvdp_addr; last by rewrite dvdp_mull.
rewrite Gauss_dvdpr; last by rewrite sq'p // mulrC -Dcp dvdpZl.
by apply: contraL => /nz_der1p nz_g'; rewrite gtNdvdp ?nz_g' ?lt_size_deriv.
Qed.
Lemma separable_coprime p u v : separable p -> u * v %| p -> coprimep u v.
Proof. by move=> /separable_polyP[sq'p _] /sq'p. Qed.
Lemma separable_nosquare p u k :
separable p -> 1 < k -> size u != 1 -> (u ^+ k %| p) = false.
Proof.
move=> /separable_polyP[/poly_square_freeP sq'p _] /subnKC <- /sq'p.
by apply: contraNF; apply: dvdp_trans; rewrite exprD dvdp_mulr.
Qed.
Lemma separable_deriv_eq0 p u :
separable p -> u %| p -> 1 < size u -> (u^`() == 0) = false.
Proof. by move=> /separable_polyP[_ nz_der1p] u_p /nz_der1p/negPf->. Qed.
Lemma dvdp_separable p q : q %| p -> separable p -> separable q.
Proof.
move=> /(dvdp_trans _)q_dv_p /separable_polyP[sq'p nz_der1p].
by apply/separable_polyP; split=> [u v /q_dv_p/sq'p | u /q_dv_p/nz_der1p].
Qed.
Lemma separable_mul p q :
separable (p * q) = [&& separable p, separable q & coprimep p q].
Proof.
apply/idP/and3P => [sep_pq | [sep_p sep_q co_pq]].
rewrite !(dvdp_separable _ sep_pq) ?dvdp_mulIr ?dvdp_mulIl //.
by rewrite (separable_coprime sep_pq).
rewrite unlock in sep_p sep_q *.
rewrite derivM coprimepMl {1}addrC mulrC !coprimep_addl_mul.
by rewrite !coprimepMr (coprimep_sym q p) co_pq !andbT; apply/andP.
Qed.
Lemma eqp_separable p q : p %= q -> separable p = separable q.
Proof. by case/andP=> p_q q_p; apply/idP/idP=> /dvdp_separable->. Qed.
Lemma separable_root p x :
separable (p * ('X - x%:P)) = separable p && ~~ root p x.
Proof.
rewrite separable_mul; apply: andb_id2l => seq_p.
by rewrite unlock derivXsubC coprimep1 coprimep_XsubC.
Qed.
Lemma separable_prod_XsubC (r : seq R) :
separable (\prod_(x <- r) ('X - x%:P)) = uniq r.
Proof.
elim: r => [|x r IH]; first by rewrite big_nil unlock /separable_poly coprime1p.
by rewrite big_cons mulrC separable_root IH root_prod_XsubC andbC.
Qed.
Lemma make_separable p : p != 0 -> separable (p %/ gcdp p p^`()).
Proof.
set g := gcdp p p^`() => nz_p; apply/separable_polyP.
have max_dvd_u (u : {poly R}): 1 < size u -> exists k, ~~ (u ^+ k %| p).
move=> u_gt1; exists (size p); rewrite gtNdvdp // polySpred //.
by rewrite -(ltn_subRL 1) subn1 size_exp leq_pmull // -(subnKC u_gt1).
split=> [|u u_pg u_gt1]; last first.
apply/eqP=> u'0 /=; have [k /negP[]] := max_dvd_u u u_gt1.
elim: k => [|k IHk]; first by rewrite dvd1p.
suffices: u ^+ k.+1 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite exprS dvdp_mul // dvdp_gcd IHk //=.
suffices: u ^+ k %| (p %/ u ^+ k * u ^+ k)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE u'0 mul0r mul0rn mulr0 addr0 dvdp_mull.
have pg_dv_p: p %/ g %| p by rewrite divp_dvd ?dvdp_gcdl.
apply/poly_square_freeP=> u; rewrite neq_ltn ltnS leqn0 size_poly_eq0.
case/predU1P=> [-> | /max_dvd_u[k]].
by apply: contra nz_p; rewrite expr0n -dvd0p => /dvdp_trans->.
apply: contra => u2_dv_pg; case: k; [by rewrite dvd1p | elim=> [|n IHn]].
exact: dvdp_trans (dvdp_mulr _ _) (dvdp_trans u2_dv_pg pg_dv_p).
suff: u ^+ n.+2 %| (p %/ g) * g.
by rewrite Pdiv.Idomain.divpK ?dvdp_gcdl // dvdpZr ?lcn_neq0.
rewrite -add2n exprD dvdp_mul // dvdp_gcd.
rewrite (dvdp_trans _ IHn) ?exprS ?dvdp_mull //=.
suff: u ^+ n %| ((p %/ u ^+ n.+1) * u ^+ n.+1)^`().
by rewrite Pdiv.Idomain.divpK // derivZ dvdpZr ?lcn_neq0.
by rewrite !derivCE dvdp_add // -1?mulr_natl ?exprS !dvdp_mull.
Qed.
End SeparablePoly.
Arguments separable_polyP {R p}.
Lemma separable_map (F : fieldType) (R : idomainType)
(f : {rmorphism F -> R}) (p : {poly F}) :
separable_poly (map_poly f p) = separable_poly p.
Proof.
by rewrite unlock deriv_map /coprimep -gcdp_map size_map_poly.
Qed.
Section InfinitePrimitiveElementTheorem.
Local Notation "p ^ f" := (map_poly f p) : ring_scope.
Variables (F L : fieldType) (iota : {rmorphism F -> L}).
Variables (x y : L) (p : {poly F}).
Hypotheses (nz_p : p != 0) (px_0 : root (p ^ iota) x).
Let inFz z w := exists q, (q ^ iota).[z] = w.
Lemma large_field_PET q :
root (q ^ iota) y -> separable_poly q ->
exists2 r, r != 0
& forall t (z := iota t * y - x), ~~ root r (iota t) -> inFz z x /\ inFz z y.
Proof.
move=> qy_0 sep_q; have nz_q := separable_poly_neq0 sep_q.
have /factor_theorem[q0 Dq] := qy_0.
set p1 := p ^ iota \Po ('X + x%:P); set q1 := q0 \Po ('X + y%:P).
have nz_p1: p1 != 0.
apply: contraNneq nz_p => /(canRL (fun r => comp_polyXaddC_K r _))/eqP.
by rewrite comp_poly0 map_poly_eq0.
have{sep_q} nz_q10: q1.[0] != 0.
move: sep_q; rewrite -(separable_map iota) Dq separable_root => /andP[_].
by rewrite horner_comp !hornerE.
have nz_q1: q1 != 0 by apply: contraNneq nz_q10 => ->; rewrite horner0.
pose p2 := p1 ^ polyC \Po ('X * 'Y); pose q2 := q1 ^ polyC.
have /Bezout_coprimepP[[u v]]: coprimep p2 q2.
rewrite coprimep_def eqn_leq leqNgt andbC size_poly_gt0 gcdp_eq0 poly_XmY_eq0.
by rewrite map_polyC_eq0 (negPf nz_p1) -resultant_eq0 div_annihilant_neq0.
rewrite -size_poly_eq1 => /size_poly1P[r nzr Dr]; exists r => {nzr}// t z nz_rt.
have [r1 nz_r1 r1z_0]: algebraicOver iota z.
apply/algebraic_sub; last by exists p.
by apply: algebraic_mul; [apply: algebraic_id | exists q].
pose Fz := subFExtend iota z r1; pose kappa : Fz -> L := subfx_inj.
pose kappa' := inj_subfx iota z r1.
have /eq_map_poly Diota: kappa \o kappa' =1 iota.
by move=> w; rewrite /kappa /= subfx_inj_eval // map_polyC hornerC.
suffices [y3]: exists y3, y = kappa y3.
have [q3 ->] := subfxE y3; rewrite /kappa subfx_inj_eval // => Dy.
split; [exists (t *: q3 - 'X) | by exists q3].
by rewrite rmorphB /= linearZ map_polyX !hornerE -Dy opprB addrC addrNK.
pose p0 := p ^ iota \Po (iota t *: 'X - z%:P).
have co_p0_q0: coprimep p0 q0.
pose at_t := horner_eval (iota t); have at_t0: at_t 0 = 0 by apply: rmorph0.
have /map_polyK polyCK: cancel polyC at_t by move=> w; apply: hornerC.
have ->: p0 = p2 ^ at_t \Po ('X - y%:P).
rewrite map_comp_poly polyCK // rmorphM /= map_polyC map_polyX /=.
rewrite horner_evalE hornerX.
rewrite -!comp_polyA comp_polyM comp_polyD !comp_polyC !comp_polyX.
by rewrite mulrC mulrBr mul_polyC addrAC -addrA -opprB -rmorphM -rmorphB.
have ->: q0 = q2 ^ at_t \Po ('X - y%:P) by rewrite polyCK ?comp_polyXaddC_K.
apply/coprimep_comp_poly/Bezout_coprimepP; exists (u ^ at_t, v ^ at_t).
by rewrite /= -!rmorphM -rmorphD Dr /= map_polyC polyC_eqp1.
have{co_p0_q0}: gcdp p0 (q ^ iota) %= 'X - y%:P.
rewrite /eqp Dq (eqp_dvdl _ (Gauss_gcdpr _ _)) // dvdp_gcdr dvdp_gcd.
rewrite dvdp_mull // -root_factor_theorem rootE horner_comp !hornerE.
by rewrite opprB addrC subrK.
have{p0} [p3 ->]: exists p3, p0 = p3 ^ kappa.
exists (p ^ kappa' \Po (kappa' t *: 'X - (subfx_eval iota z r1 'X)%:P)).
rewrite map_comp_poly rmorphB /= linearZ /= map_polyC map_polyX /=.
rewrite !subfx_inj_eval // map_polyC hornerC map_polyX hornerX.
by rewrite -map_poly_comp Diota.
rewrite -Diota map_poly_comp -gcdp_map /= -/kappa.
move: (gcdp _ _) => r3 /eqpf_eq[c nz_c Dr3].
exists (- (r3`_0 / r3`_1)); rewrite [kappa _]rmorphN fmorph_div -!coef_map Dr3.
by rewrite !coefZ polyseqXsubC mulr1 mulrC mulKf ?opprK.
Qed.
Lemma pchar0_PET (q : {poly F}) :
q != 0 -> root (q ^ iota) y -> [pchar F] =i pred0 ->
exists n, let z := y *+ n - x in inFz z x /\ inFz z y.
Proof.
move=> nz_q qy_0 /pcharf0P pcharF0.
without loss{nz_q} sep_q: q qy_0 / separable_poly q.
move=> IHq; apply: IHq (make_separable nz_q).
have /dvdpP[q1 Dq] := dvdp_gcdl q q^`().
rewrite {1}Dq mulpK ?gcdp_eq0; last by apply/nandP; left.
have [n [r nz_ry Dr]] := multiplicity_XsubC (q ^ iota) y.
rewrite map_poly_eq0 nz_q /= in nz_ry.
case: n => [|n] in Dr; first by rewrite Dr mulr1 (negPf nz_ry) in qy_0.
have: ('X - y%:P) ^+ n.+1 %| q ^ iota by rewrite Dr dvdp_mulIr.
rewrite Dq rmorphM /= gcdp_map -(eqp_dvdr _ (gcdp_mul2l _ _ _)) -deriv_map Dr.
rewrite dvdp_gcd derivM deriv_exp derivXsubC mul1r !mulrA dvdp_mulIr /=.
rewrite mulrDr mulrA dvdp_addr ?dvdp_mulIr // exprS -scaler_nat -!scalerAr.
rewrite dvdpZr -?(rmorph_nat iota) ?fmorph_eq0 ?pcharF0 //.
rewrite mulrA dvdp_mul2r ?expf_neq0 ?polyXsubC_eq0 //.
by rewrite Gauss_dvdpl ?dvdp_XsubCl // coprimep_sym coprimep_XsubC.
have [r nz_r PETxy] := large_field_PET qy_0 sep_q.
pose ts := mkseq (fun n => iota n%:R) (size r).
have /(max_ring_poly_roots nz_r)/=/implyP: uniq_roots ts.
rewrite uniq_rootsE mkseq_uniq // => m n eq_mn; apply/eqP; rewrite eqn_leq.
wlog suffices: m n eq_mn / m <= n by move=> IHmn; rewrite !IHmn.
move/fmorph_inj/eqP: eq_mn; rewrite -subr_eq0 leqNgt; apply: contraL => lt_mn.
by rewrite -natrB ?(ltnW lt_mn) // pcharF0 -lt0n subn_gt0.
rewrite size_mkseq ltnn implybF all_map => /allPn[n _ /= /PETxy].
by rewrite rmorph_nat mulr_natl; exists n.
Qed.
End InfinitePrimitiveElementTheorem.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_PET instead.")]
Notation char0_PET := (pchar0_PET) (only parsing).
Section Separable.
Variables (F : fieldType) (L : fieldExtType F).
Implicit Types (U V W : {vspace L}) (E K M : {subfield L}) (D : 'End(L)).
Section Derivation.
Variables (K : {vspace L}) (D : 'End(L)).
(* A deriviation only needs to be additive and satisfy Lebniz's law, but all *)
(* the deriviations used here are going to be linear, so we only define *)
(* the Derivation predicate for linear endomorphisms. *)
Definition Derivation : bool :=
all2rel (fun u v => D (u * v) == D u * v + u * D v) (vbasis K).
Hypothesis derD : Derivation.
Lemma Derivation_mul : {in K &, forall u v, D (u * v) = D u * v + u * D v}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite !(mulr_sumr, linear_sum) -big_split; apply: eq_bigr => /= j _.
rewrite !mulr_suml linear_sum -big_split; apply: eq_bigr => /= i _.
rewrite !(=^~ scalerAl, linearZZ) -!scalerAr linearZZ -!scalerDr !scalerA /=.
by congr (_ *: _); apply/eqP/(allrelP derD); exact: memt_nth.
Qed.
Lemma Derivation_mul_poly (Dp := map_poly D) :
{in polyOver K &, forall p q, Dp (p * q) = Dp p * q + p * Dp q}.
Proof.
move=> p q Kp Kq; apply/polyP=> i; rewrite {}/Dp coefD coef_map /= !coefM.
rewrite linear_sum -big_split; apply: eq_bigr => /= j _.
by rewrite !{1}coef_map Derivation_mul ?(polyOverP _).
Qed.
End Derivation.
Lemma DerivationS E K D : (K <= E)%VS -> Derivation E D -> Derivation K D.
Proof.
move/subvP=> sKE derD; apply/allrelP=> x y Kx Ky; apply/eqP.
by rewrite (Derivation_mul derD) ?sKE // vbasis_mem.
Qed.
Section DerivationAlgebra.
Variables (E : {subfield L}) (D : 'End(L)).
Hypothesis derD : Derivation E D.
Lemma Derivation1 : D 1 = 0.
Proof.
apply: (addIr (D (1 * 1))); rewrite add0r {1}mul1r.
by rewrite (Derivation_mul derD) ?mem1v // mulr1 mul1r.
Qed.
Lemma Derivation_scalar x : x \in 1%VS -> D x = 0.
Proof. by case/vlineP=> y ->; rewrite linearZ /= Derivation1 scaler0. Qed.
Lemma Derivation_exp x m : x \in E -> D (x ^+ m) = x ^+ m.-1 *+ m * D x.
Proof.
move=> Ex; case: m; first by rewrite expr0 mulr0n mul0r Derivation1.
elim=> [|m IHm]; first by rewrite mul1r.
rewrite exprS (Derivation_mul derD) //; last by apply: rpredX.
by rewrite mulrC IHm mulrA mulrnAr -exprS -mulrDl.
Qed.
Lemma Derivation_horner p x :
p \is a polyOver E -> x \in E ->
D p.[x] = (map_poly D p).[x] + p^`().[x] * D x.
Proof.
move=> Ep Ex; elim/poly_ind: p Ep => [|p c IHp] /polyOverP EpXc.
by rewrite !(raddf0, horner0) mul0r add0r.
have Ep: p \is a polyOver E.
by apply/polyOverP=> i; have:= EpXc i.+1; rewrite coefD coefMX coefC addr0.
have->: map_poly D (p * 'X + c%:P) = map_poly D p * 'X + (D c)%:P.
apply/polyP=> i; rewrite !(coefD, coefMX, coef_map) /= linearD /= !coefC.
by rewrite !(fun_if D) linear0.
rewrite derivMXaddC !hornerE mulrDl mulrAC addrAC linearD /=; congr (_ + _).
by rewrite addrCA -mulrDl -IHp // addrC (Derivation_mul derD) ?rpred_horner.
Qed.
End DerivationAlgebra.
Definition separable_element U x := separable_poly (minPoly U x).
Section SeparableElement.
Variables (K : {subfield L}) (x : L).
(* begin hide *)
Let sKxK : (K <= <<K; x>>)%VS := subv_adjoin K x.
Let Kx_x : x \in <<K; x>>%VS := memv_adjoin K x.
(* end hide *)
Lemma separable_elementP :
reflect (exists f, [/\ f \is a polyOver K, root f x & separable_poly f])
(separable_element K x).
Proof.
apply: (iffP idP) => [sep_x | [f [Kf /(minPoly_dvdp Kf)/dvdpP[g ->]]]].
by exists (minPoly K x); rewrite minPolyOver root_minPoly.
by rewrite separable_mul => /and3P[].
Qed.
Lemma base_separable : x \in K -> separable_element K x.
Proof.
move=> Kx; apply/separable_elementP; exists ('X - x%:P).
by rewrite polyOverXsubC root_XsubC unlock !derivCE coprimep1.
Qed.
Lemma separable_nz_der : separable_element K x = ((minPoly K x)^`() != 0).
Proof.
rewrite /separable_element unlock.
apply/idP/idP=> [|nzPx'].
by apply: contraTneq => ->; rewrite coprimep0 -size_poly_eq1 size_minPoly.
have gcdK : gcdp (minPoly K x) (minPoly K x)^`() \in polyOver K.
by rewrite gcdp_polyOver ?polyOver_deriv // minPolyOver.
rewrite -gcdp_eqp1 -size_poly_eq1 -dvdp1.
have /orP[/andP[_]|/andP[]//] := minPoly_irr gcdK (dvdp_gcdl _ _).
rewrite dvdp_gcd dvdpp /= => /(dvdp_leq nzPx')/leq_trans/(_ (size_poly _ _)).
by rewrite size_minPoly ltnn.
Qed.
Lemma separablePn_pchar :
reflect (exists2 p, p \in [pchar L] &
exists2 g, g \is a polyOver K & minPoly K x = g \Po 'X^p)
(~~ separable_element K x).
Proof.
rewrite separable_nz_der negbK; set f := minPoly K x.
apply: (iffP eqP) => [f'0 | [p Hp [g _ ->]]]; last first.
by rewrite deriv_comp derivXn -scaler_nat (pcharf0 Hp) scale0r mulr0.
pose n := adjoin_degree K x; have sz_f: size f = n.+1 := size_minPoly K x.
have fn1: f`_n = 1 by rewrite -(monicP (monic_minPoly K x)) lead_coefE sz_f.
have dimKx: (adjoin_degree K x)%:R == 0 :> L.
by rewrite -(coef0 _ n.-1) -f'0 coef_deriv fn1.
have /natf0_pchar[// | p pcharLp] := dimKx.
have /dvdnP[r Dn]: (p %| n)%N by rewrite (dvdn_pcharf pcharLp).
exists p => //; exists (\poly_(i < r.+1) f`_(i * p)).
by apply: polyOver_poly => i _; rewrite (polyOverP _) ?minPolyOver.
rewrite comp_polyE size_poly_eq -?Dn ?fn1 ?oner_eq0 //.
have pr_p := pcharf_prime pcharLp; have p_gt0 := prime_gt0 pr_p.
apply/polyP=> i; rewrite coef_sum.
have [[{}i ->] | p'i] := altP (@dvdnP p i); last first.
rewrite big1 => [|j _]; last first.
rewrite coefZ -exprM coefXn [_ == _](contraNF _ p'i) ?mulr0 // => /eqP->.
by rewrite dvdn_mulr.
rewrite (dvdn_pcharf pcharLp) in p'i; apply: mulfI p'i _ _ _.
by rewrite mulr0 mulr_natl; case: i => // i; rewrite -coef_deriv f'0 coef0.
have [ltri | leir] := leqP r.+1 i.
rewrite nth_default ?sz_f ?Dn ?ltn_pmul2r ?big1 // => j _.
rewrite coefZ -exprM coefXn mulnC gtn_eqF ?mulr0 //.
by rewrite ltn_pmul2l ?(leq_trans _ ltri).
rewrite (bigD1 (Sub i _)) //= big1 ?addr0 => [|j i'j]; last first.
by rewrite coefZ -exprM coefXn mulnC eqn_pmul2l // mulr_natr mulrb ifN_eqC.
by rewrite coef_poly leir coefZ -exprM coefXn mulnC eqxx mulr1.
Qed.
Lemma separable_root_der : separable_element K x (+) root (minPoly K x)^`() x.
Proof.
have KpKx': _^`() \is a polyOver K := polyOver_deriv (minPolyOver K x).
rewrite separable_nz_der addNb (root_small_adjoin_poly KpKx') ?addbb //.
by rewrite (leq_trans (size_poly _ _)) ?size_minPoly.
Qed.
Lemma Derivation_separable D :
Derivation <<K; x>> D -> separable_element K x ->
D x = - (map_poly D (minPoly K x)).[x] / (minPoly K x)^`().[x].
Proof.
move=> derD sepKx; have:= separable_root_der; rewrite {}sepKx -sub0r => nzKx'x.
apply: canRL (mulfK nzKx'x) (canRL (addrK _) _); rewrite mulrC addrC.
rewrite -(Derivation_horner derD) ?minPolyxx ?linear0 //.
exact: polyOverSv sKxK _ (minPolyOver _ _).
Qed.
Section ExtendDerivation.
Variable D : 'End(L).
Let Dx E := - (map_poly D (minPoly E x)).[x] / ((minPoly E x)^`()).[x].
Fact extendDerivation_zmod_morphism_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
zmod_morphism body.
Proof.
move: Dx => C /= u v; rewrite /adjEx.
rewrite raddfB /= derivB -/adjEx !hornerE /= raddfB /= !hornerE.
by rewrite mulrBl addrACA opprD.
Qed.
Fact extendDerivation_scalable_subproof E (adjEx := Fadjoin_poly E x) :
let body y (p := adjEx y) := (map_poly D p).[x] + p^`().[x] * Dx E in
scalable body.
Proof.
move: Dx => C /= a u; rewrite /adjEx linearZ /= derivZ -/adjEx.
rewrite hornerE -[RHS]mulr_algl mulrDr mulrA -[in RHS]hornerZ.
congr (_.[x] + _); apply/polyP=> i.
by rewrite coefZ !coef_map coefZ !mulr_algl /= linearZ.
Qed.
Section DerivationLinear.
Variable (E : {subfield L}).
Let body (y : L) (p := Fadjoin_poly E x y) : L :=
(map_poly D p).[x] + p^`().[x] * Dx E.
HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ body
(extendDerivation_zmod_morphism_subproof E).
HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ body
(extendDerivation_scalable_subproof E).
Let extendDerivationLinear := Eval hnf in (body : {linear _ -> _}).
Definition extendDerivation : 'End(L) := linfun extendDerivationLinear.
End DerivationLinear.
Hypothesis derD : Derivation K D.
Lemma extendDerivation_id y : y \in K -> extendDerivation K y = D y.
Proof.
move=> yK; rewrite lfunE /= Fadjoin_polyC // derivC map_polyC hornerC.
by rewrite horner0 mul0r addr0.
Qed.
Lemma extendDerivation_horner p :
p \is a polyOver K -> separable_element K x ->
extendDerivation K p.[x] = (map_poly D p).[x] + p^`().[x] * Dx K.
Proof.
move=> Kp sepKx; have:= separable_root_der; rewrite {}sepKx /= => nz_pKx'x.
rewrite [in RHS](divp_eq p (minPoly K x)) lfunE /= Fadjoin_poly_mod ?raddfD //=.
rewrite (Derivation_mul_poly derD) ?divp_polyOver ?minPolyOver //.
rewrite derivM !{1}hornerD !{1}hornerM minPolyxx !{1}mulr0 !{1}add0r.
rewrite mulrDl addrA [_ + (_ * _ * _)]addrC {2}/Dx -mulrA -/Dx.
by rewrite [_ / _]mulrC (mulVKf nz_pKx'x) mulrN addKr.
Qed.
Lemma extendDerivationP :
separable_element K x -> Derivation <<K; x>> (extendDerivation K).
Proof.
move=> sep; apply/allrelP=> u v /vbasis_mem Hu /vbasis_mem Hv; apply/eqP.
rewrite -(Fadjoin_poly_eq Hu) -(Fadjoin_poly_eq Hv) -hornerM.
rewrite !{1}extendDerivation_horner ?{1}rpredM ?Fadjoin_polyOver //.
rewrite (Derivation_mul_poly derD) ?Fadjoin_polyOver //.
rewrite derivM !{1}hornerD !{1}hornerM !{1}mulrDl !{1}mulrDr -!addrA.
congr (_ + _); rewrite [Dx K]lock -!{1}mulrA !{1}addrA; congr (_ + _).
by rewrite addrC; congr (_ * _ + _); rewrite mulrC.
Qed.
End ExtendDerivation.
(* Reference:
http://www.math.uconn.edu/~kconrad/blurbs/galoistheory/separable2.pdf *)
Lemma Derivation_separableP :
reflect
(forall D, Derivation <<K; x>> D -> K <= lker D -> <<K; x>> <= lker D)%VS
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx D derD /subvP DK_0 | derKx_0].
have{} DK_0 q: q \is a polyOver K -> map_poly D q = 0.
move=> /polyOverP Kq; apply/polyP=> i; apply/eqP.
by rewrite coef0 coef_map -memv_ker DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->]; rewrite memv_ker.
rewrite (Derivation_horner derD) ?(polyOverSv sKxK) //.
rewrite (Derivation_separable derD sepKx) !DK_0 ?minPolyOver //.
by rewrite horner0 oppr0 mul0r mulr0 addr0.
apply: wlog_neg; rewrite {1}separable_nz_der negbK => /eqP pKx'_0.
pose Df := fun y => (Fadjoin_poly K x y)^`().[x].
have Dlin: linear Df.
move=> a u v; rewrite /Df linearP /= -mul_polyC derivD derivM derivC.
by rewrite mul0r add0r hornerD hornerM hornerC -scalerAl mul1r.
pose DlinM := GRing.isLinear.Build _ _ _ _ Df Dlin.
pose DL : {linear _ -> _} := HB.pack Df DlinM.
pose D := linfun DL; apply: base_separable.
have DK_0: (K <= lker D)%VS.
apply/subvP=> v Kv; rewrite memv_ker lfunE /= /Df Fadjoin_polyC //.
by rewrite derivC horner0.
have Dder: Derivation <<K; x>> D.
apply/allrelP=> u v /vbasis_mem Kx_u /vbasis_mem Kx_v; apply/eqP.
rewrite !lfunE /= /Df; set Px := Fadjoin_poly K x.
set Px_u := Px u; rewrite -(Fadjoin_poly_eq Kx_u) -/Px -/Px_u.
set Px_v := Px v; rewrite -(Fadjoin_poly_eq Kx_v) -/Px -/Px_v.
rewrite -!hornerM -hornerD -derivM.
rewrite /Px Fadjoin_poly_mod ?rpredM ?Fadjoin_polyOver //.
rewrite [in RHS](divp_eq (Px_u * Px_v) (minPoly K x)) derivD derivM.
by rewrite pKx'_0 mulr0 addr0 hornerD hornerM minPolyxx mulr0 add0r.
have{Dder DK_0}: x \in lker D by apply: subvP Kx_x; apply: derKx_0.
apply: contraLR => K'x; rewrite memv_ker lfunE /= /Df Fadjoin_polyX //.
by rewrite derivX hornerC oner_eq0.
Qed.
End SeparableElement.
#[deprecated(since="mathcomp 2.4.0", note="Use separablePn_pchar instead.")]
Notation separablePn := (separablePn_pchar) (only parsing).
Arguments separable_elementP {K x}.
Lemma separable_elementS K E x :
(K <= E)%VS -> separable_element K x -> separable_element E x.
Proof.
move=> sKE /separable_elementP[f [fK rootf sepf]]; apply/separable_elementP.
by exists f; rewrite (polyOverSv sKE).
Qed.
Lemma adjoin_separableP {K x} :
reflect (forall y, y \in <<K; x>>%VS -> separable_element K y)
(separable_element K x).
Proof.
apply: (iffP idP) => [sepKx | -> //]; last exact: memv_adjoin.
move=> _ /Fadjoin_polyP[q Kq ->]; apply/Derivation_separableP=> D derD DK_0.
apply/subvP=> _ /Fadjoin_polyP[p Kp ->].
rewrite memv_ker -(extendDerivation_id x D (mempx_Fadjoin _ Kp)).
have sepFyx: (separable_element <<K; q.[x]>> x).
by apply: (separable_elementS (subv_adjoin _ _)).
have KyxEqKx: (<< <<K; q.[x]>>; x>> = <<K; x>>)%VS.
apply/eqP; rewrite eqEsubv andbC adjoinSl ?subv_adjoin //=.
apply/FadjoinP/andP; rewrite memv_adjoin andbT.
by apply/FadjoinP/andP; rewrite subv_adjoin mempx_Fadjoin.
have /[!KyxEqKx] derDx := extendDerivationP derD sepFyx.
rewrite -horner_comp (Derivation_horner derDx) ?memv_adjoin //; last first.
by apply: (polyOverSv (subv_adjoin _ _)); apply: polyOver_comp.
set Dx_p := map_poly _; have Dx_p_0 t: t \is a polyOver K -> (Dx_p t).[x] = 0.
move/polyOverP=> Kt; congr (_.[x] = 0): (horner0 x); apply/esym/polyP => i.
have /eqP Dti_0: D t`_i == 0 by rewrite -memv_ker (subvP DK_0) ?Kt.
by rewrite coef0 coef_map /= {1}extendDerivation_id ?subvP_adjoin.
rewrite (Derivation_separable derDx sepKx) -/Dx_p Dx_p_0 ?polyOver_comp //.
by rewrite add0r mulrCA Dx_p_0 ?minPolyOver ?oppr0 ?mul0r.
Qed.
Lemma separable_exponent_pchar K x :
exists n, [pchar L].-nat n && separable_element K (x ^+ n).
Proof.
pose d := adjoin_degree K x; move: {2}d.+1 (ltnSn d) => n.
elim: n => // n IHn in x @d *; rewrite ltnS => le_d_n.
have [[p pcharLp]|] := altP (separablePn_pchar K x); last by rewrite negbK; exists 1.
case=> g Kg defKx; have p_pr := pcharf_prime pcharLp.
suffices /IHn[m /andP[pcharLm sepKxpm]]: adjoin_degree K (x ^+ p) < n.
by exists (p * m)%N; rewrite pnatM pnatE // pcharLp pcharLm exprM.
apply: leq_trans le_d_n; rewrite -ltnS -!size_minPoly.
have nzKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have nzg: g != 0 by apply: contra_eqN defKx => /eqP->; rewrite comp_poly0.
apply: leq_ltn_trans (dvdp_leq nzg _) _.
by rewrite minPoly_dvdp // rootE -hornerXn -horner_comp -defKx minPolyxx.
rewrite (polySpred nzKx) ltnS defKx size_comp_poly size_polyXn /=.
suffices g_gt1: 1 < size g by rewrite -(subnKC g_gt1) ltn_Pmulr ?prime_gt1.
apply: contra_eqT (size_minPoly K x); rewrite defKx -leqNgt => /size1_polyC->.
by rewrite comp_polyC size_polyC; case: (_ != 0).
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use separable_exponent_pchar instead.")]
Notation separable_exponent := (separable_exponent_pchar) (only parsing).
Lemma pcharf0_separable K : [pchar L] =i pred0 -> forall x, separable_element K x.
Proof.
move=> pcharL0 x; have [n /andP[pcharLn]] := separable_exponent_pchar K x.
by rewrite (pnat_1 pcharLn (sub_in_pnat _ pcharLn)) // => p _; rewrite pcharL0.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0_separable instead.")]
Notation charf0_separable := (pcharf0_separable) (only parsing).
Lemma pcharf_p_separable K x e p :
p \in [pchar L] -> separable_element K x = (x \in <<K; x ^+ (p ^ e.+1)>>%VS).
Proof.
move=> pcharLp; apply/idP/idP=> [sepKx | /Fadjoin_poly_eq]; last first.
set m := p ^ _; set f := Fadjoin_poly K _ x => Dx; apply/separable_elementP.
have mL0: m%:R = 0 :> L by apply/eqP; rewrite -(dvdn_pcharf pcharLp) dvdn_exp.
exists ('X - (f \Po 'X^m)); split.
- by rewrite rpredB ?polyOver_comp ?rpredX ?polyOverX ?Fadjoin_polyOver.
- by rewrite rootE !hornerE horner_comp hornerXn Dx subrr.
rewrite unlock !(derivE, deriv_comp) -mulr_natr -rmorphMn /= mL0.
by rewrite !mulr0 subr0 coprimep1.
without loss{e} ->: e x sepKx / e = 0.
move=> IH; elim: {e}e.+1 => [|e]; [exact: memv_adjoin | apply: subvP].
apply/FadjoinP/andP; rewrite subv_adjoin expnSr exprM (IH 0) //.
by have /adjoin_separableP-> := sepKx; rewrite ?rpredX ?memv_adjoin.
set K' := <<K; x ^+ p>>%VS; have sKK': (K <= K')%VS := subv_adjoin _ _.
pose q := minPoly K' x; pose g := 'X^p - (x ^+ p)%:P.
have [K'g]: g \is a polyOver K' /\ q \is a polyOver K'.
by rewrite minPolyOver rpredB ?rpredX ?polyOverX // polyOverC memv_adjoin.
have /dvdpP[c Dq]: 'X - x%:P %| q by rewrite dvdp_XsubCl root_minPoly.
have co_c_g: coprimep c g.
have pcharPp: p \in [pchar {poly L}] := rmorph_pchar polyC pcharLp.
rewrite /g polyC_exp -!(pFrobenius_autE pcharPp) -rmorphB coprimep_expr //.
have: separable_poly q := separable_elementS sKK' sepKx.
by rewrite Dq separable_mul => /and3P[].
have{g K'g co_c_g} /size_poly1P[a nz_a Dc]: size c == 1.
suffices c_dv_g: c %| g by rewrite -(eqp_size (dvdp_gcd_idl c_dv_g)).
have: q %| g by rewrite minPoly_dvdp // rootE !hornerE subrr.
by apply: dvdp_trans; rewrite Dq dvdp_mulIl.
rewrite {q}Dq {c}Dc mulrBr -rmorphM -rmorphN -cons_poly_def qualifE /=.
by rewrite polyseq_cons !polyseqC nz_a /= rpredN andbCA => /and3P[/fpredMl->].
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_p_separable instead.")]
Notation charf_p_separable := (pcharf_p_separable) (only parsing).
Lemma pcharf_n_separable K x n :
[pchar L].-nat n -> 1 < n -> separable_element K x = (x \in <<K; x ^+ n>>%VS).
Proof.
rewrite -pi_pdiv; set p := pdiv n => pcharLn pi_n_p.
have pcharLp: p \in [pchar L] := pnatPpi pcharLn pi_n_p.
have <-: (n`_p)%N = n by rewrite -(eq_partn n (pcharf_eq pcharLp)) part_pnat_id.
by rewrite p_part lognE -mem_primes pi_n_p -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_n_separable instead.")]
Notation charf_n_separable := (pcharf_n_separable) (only parsing).
Definition purely_inseparable_element U x :=
x ^+ ex_minn (separable_exponent_pchar <<U>> x) \in U.
Lemma purely_inseparable_elementP_pchar {K x} :
reflect (exists2 n, [pchar L].-nat n & x ^+ n \in K)
(purely_inseparable_element K x).
Proof.
rewrite /purely_inseparable_element.
case: ex_minnP => n /andP[pcharLn /=]; rewrite subfield_closed => sepKxn min_xn.
apply: (iffP idP) => [Kxn | [m pcharLm Kxm]]; first by exists n.
have{min_xn}: n <= m by rewrite min_xn ?pcharLm ?base_separable.
rewrite leq_eqVlt => /predU1P[-> // | ltnm]; pose p := pdiv m.
have m_gt1: 1 < m by have [/leq_ltn_trans->] := andP pcharLn.
have pcharLp: p \in [pchar L] by rewrite (pnatPpi pcharLm) ?pi_pdiv.
have [/p_natP[em Dm] /p_natP[en Dn]]: p.-nat m /\ p.-nat n.
by rewrite -!(eq_pnat _ (pcharf_eq pcharLp)).
rewrite Dn Dm ltn_exp2l ?prime_gt1 ?pdiv_prime // in ltnm.
rewrite -(Fadjoin_idP Kxm) Dm -(subnKC ltnm) addSnnS expnD exprM -Dn.
by rewrite -pcharf_p_separable.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use purely_inseparable_elementP_pchar instead.")]
Notation purely_inseparable_elementP := (purely_inseparable_elementP_pchar) (only parsing).
Lemma separable_inseparable_element K x :
separable_element K x && purely_inseparable_element K x = (x \in K).
Proof.
rewrite /purely_inseparable_element; case: ex_minnP => [[|m]] //=.
rewrite subfield_closed; case: m => /= [-> //| m _ /(_ 1)/implyP/= insepKx].
by rewrite (negPf insepKx) (contraNF (@base_separable K x) insepKx).
Qed.
Lemma base_inseparable K x : x \in K -> purely_inseparable_element K x.
Proof. by rewrite -separable_inseparable_element => /andP[]. Qed.
Lemma sub_inseparable K E x :
(K <= E)%VS -> purely_inseparable_element K x ->
purely_inseparable_element E x.
Proof.
move/subvP=> sKE /purely_inseparable_elementP_pchar[n pcharLn /sKE Exn].
by apply/purely_inseparable_elementP_pchar; exists n.
Qed.
Section PrimitiveElementTheorem.
Variables (K : {subfield L}) (x y : L).
Section FiniteCase.
Variable N : nat.
Let K_is_large := exists s, [/\ uniq s, {subset s <= K} & N < size s].
Let cyclic_or_large (z : L) : z != 0 -> K_is_large \/ exists a, z ^+ a.+1 = 1.
Proof.
move=> nz_z; pose d := adjoin_degree K z.
pose h0 (i : 'I_(N ^ d).+1) (j : 'I_d) := (Fadjoin_poly K z (z ^+ i))`_j.
pose s := undup [seq h0 i j | i <- enum 'I_(N ^ d).+1, j <- enum 'I_d].
have s_h0 i j: h0 i j \in s.
by rewrite mem_undup; apply/allpairsP; exists (i, j); rewrite !mem_enum.
pose h i := [ffun j => Ordinal (etrans (index_mem _ _) (s_h0 i j))].
pose h' (f : {ffun 'I_d -> 'I_(size s)}) := \sum_(j < d) s`_(f j) * z ^+ j.
have hK i: h' (h i) = z ^+ i.
have Kz_zi: z ^+ i \in <<K; z>>%VS by rewrite rpredX ?memv_adjoin.
rewrite -(Fadjoin_poly_eq Kz_zi) (horner_coef_wide z (size_poly _ _)) -/d.
by apply: eq_bigr => j _; rewrite ffunE /= nth_index.
have [inj_h | ] := altP (@injectiveP _ _ h).
left; exists s; split=> [|zi_j|]; rewrite ?undup_uniq ?mem_undup //=.
by case/allpairsP=> ij [_ _ ->]; apply/polyOverP/Fadjoin_polyOver.
rewrite -[size s]card_ord -(@ltn_exp2r _ _ d) // -{2}[d]card_ord -card_ffun.
by rewrite -[_.+1]card_ord -(card_image inj_h) max_card.
case/injectivePn=> i1 [i2 i1'2 /(congr1 h')]; rewrite !hK => eq_zi12; right.
without loss{i1'2} lti12: i1 i2 eq_zi12 / i1 < i2.
by move=> IH; move: i1'2; rewrite neq_ltn => /orP[]; apply: IH.
by exists (i2 - i1.+1)%N; rewrite subnSK ?expfB // eq_zi12 divff ?expf_neq0.
Qed.
Lemma finite_PET : K_is_large \/ exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have [-> | /cyclic_or_large[|[a Dxa]]] := eqVneq x 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists y.
have [-> | /cyclic_or_large[|[b Dyb]]] := eqVneq y 0; first 2 [by left].
by rewrite addv0 subfield_closed; right; exists x.
pose h0 (ij : 'I_a.+1 * 'I_b.+1) := x ^+ ij.1 * y ^+ ij.2.
pose H := <<[set ij | h0 ij == 1%R]>>%G; pose h (u : coset_of H) := h0 (repr u).
have h0M: {morph h0: ij1 ij2 / (ij1 * ij2)%g >-> ij1 * ij2}.
by rewrite /h0 => [] [i1 j1] [i2 j2] /=; rewrite mulrACA -!exprD !expr_mod.
have memH ij: (ij \in H) = (h0 ij == 1).
rewrite /= gen_set_id ?inE //; apply/group_setP; rewrite inE [h0 _]mulr1.
by split=> // ? ? /[!(inE, h0M)] /eqP-> /eqP->; rewrite mulr1.
have nH ij: ij \in 'N(H)%g.
by apply/(subsetP (cent_sub _))/centP=> ij1 _; congr (_, _); rewrite Zp_mulgC.
have hE ij: h (coset H ij) = h0 ij.
rewrite /h val_coset //; case: repr_rcosetP => ij1.
by rewrite memH h0M => /eqP->; rewrite mul1r.
have h1: h 1%g = 1 by rewrite /h repr_coset1 [h0 _]mulr1.
have hM: {morph h: u v / (u * v)%g >-> u * v}.
by do 2![move=> u; have{u} [? _ ->] := cosetP u]; rewrite -morphM // !hE h0M.
have /cyclicP[w defW]: cyclic [set: coset_of H].
apply: field_mul_group_cyclic (in2W hM) _ => u _; have [ij _ ->] := cosetP u.
by split=> [/eqP | -> //]; rewrite hE -memH => /coset_id.
have Kw_h ij t: h0 ij = t -> t \in <<K; h w>>%VS.
have /cycleP[k Dk]: coset H ij \in <[w]>%g by rewrite -defW inE.
rewrite -hE {}Dk => <-; elim: k => [|k IHk]; first by rewrite h1 rpred1.
by rewrite expgS hM rpredM // memv_adjoin.
right; exists (h w); apply/eqP; rewrite eqEsubv !(sameP FadjoinP andP).
rewrite subv_adjoin (subv_trans (subv_adjoin K y)) ?subv_adjoin //=.
rewrite (Kw_h (0, inZp 1)) 1?(Kw_h (inZp 1, 0)) /h0 ?mulr1 ?mul1r ?expr_mod //=.
by rewrite rpredM ?rpredX ?memv_adjoin // subvP_adjoin ?memv_adjoin.
Qed.
End FiniteCase.
Hypothesis sepKy : separable_element K y.
Lemma Primitive_Element_Theorem : exists z, (<< <<K; y>>; x>> = <<K; z>>)%VS.
Proof.
have /polyOver_subvs[p Dp]: minPoly K x \is a polyOver K := minPolyOver K x.
have nz_pKx: minPoly K x != 0 by rewrite monic_neq0 ?monic_minPoly.
have{nz_pKx} nz_p: p != 0 by rewrite Dp map_poly_eq0 in nz_pKx.
have{Dp} px0: root (map_poly vsval p) x by rewrite -Dp root_minPoly.
have [q0 [Kq0 q0y0 sepKq0]] := separable_elementP sepKy.
have /polyOver_subvs[q Dq]: minPoly K y \is a polyOver K := minPolyOver K y.
have qy0: root (map_poly vsval q) y by rewrite -Dq root_minPoly.
have sep_pKy: separable_poly (minPoly K y).
by rewrite (dvdp_separable _ sepKq0) ?minPoly_dvdp.
have{sep_pKy} sep_q: separable_poly q by rewrite Dq separable_map in sep_pKy.
have [r nz_r PETr] := large_field_PET nz_p px0 qy0 sep_q.
have [[s [Us Ks /ltnW leNs]] | //] := finite_PET (size r).
have{s Us leNs} /allPn[t {}/Ks Kt nz_rt]: ~~ all (root r) s.
by apply: contraTN leNs; rewrite -ltnNge => /max_poly_roots->.
have{PETr} [/= [p1 Dx] [q1 Dy]] := PETr (Subvs Kt) nz_rt.
set z := t * y - x in Dx Dy; exists z; apply/eqP.
rewrite eqEsubv !(sameP FadjoinP andP) subv_adjoin.
have Kz_p1z (r1 : {poly subvs_of K}): (map_poly vsval r1).[z] \in <<K; z>>%VS.
rewrite rpred_horner ?memv_adjoin ?(polyOverSv (subv_adjoin K z)) //.
by apply/polyOver_subvs; exists r1.
rewrite -{1}Dx -{1}Dy !{Dx Dy}Kz_p1z /=.
rewrite (subv_trans (subv_adjoin K y)) ?subv_adjoin // rpredB ?memv_adjoin //.
by rewrite subvP_adjoin // rpredM ?memv_adjoin ?subvP_adjoin.
Qed.
Lemma adjoin_separable : separable_element <<K; y>> x -> separable_element K x.
Proof.
have /Derivation_separableP derKy := sepKy => /Derivation_separableP derKy_x.
have [z defKz] := Primitive_Element_Theorem.
suffices /adjoin_separableP: separable_element K z.
by apply; rewrite -defKz memv_adjoin.
apply/Derivation_separableP=> D; rewrite -defKz => derKxyD DK_0.
suffices derKyD: Derivation <<K; y>>%VS D by rewrite derKy_x // derKy.
by apply: DerivationS derKxyD; apply: subv_adjoin.
Qed.
End PrimitiveElementTheorem.
Lemma strong_Primitive_Element_Theorem K x y :
separable_element <<K; x>> y ->
exists2 z : L, (<< <<K; y>>; x>> = <<K; z>>)%VS
& separable_element K x -> separable_element K y.
Proof.
move=> sepKx_y; have [n /andP[pcharLn sepKyn]] := separable_exponent_pchar K y.
have adjK_C z t: (<<<<K; z>>; t>> = <<<<K; t>>; z>>)%VS.
by rewrite !agenv_add_id -!addvA (addvC <[_]>%VS).
have [z defKz] := Primitive_Element_Theorem x sepKyn.
exists z => [|/adjoin_separable->]; rewrite ?sepKx_y // -defKz.
have [|n_gt1|-> //] := ltngtP n 1; first by case: (n) pcharLn.
apply/eqP; rewrite !(adjK_C _ x) eqEsubv; apply/andP.
split; apply/FadjoinP/andP; rewrite subv_adjoin ?rpredX ?memv_adjoin //=.
by rewrite -pcharf_n_separable ?sepKx_y.
Qed.
Definition separable U W : bool :=
all (separable_element U) (vbasis W).
Definition purely_inseparable U W : bool :=
all (purely_inseparable_element U) (vbasis W).
Lemma separable_add K x y :
separable_element K x -> separable_element K y -> separable_element K (x + y).
Proof.
move/(separable_elementS (subv_adjoin K y))=> sepKy_x sepKy.
have [z defKz] := Primitive_Element_Theorem x sepKy.
have /(adjoin_separableP _): x + y \in <<K; z>>%VS.
by rewrite -defKz rpredD ?memv_adjoin // subvP_adjoin ?memv_adjoin.
apply; apply: adjoin_separable sepKy (adjoin_separable sepKy_x _).
by rewrite defKz base_separable ?memv_adjoin.
Qed.
Lemma separable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> separable_element K (v_ i)) ->
separable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> sepKi.
by elim/big_ind: _; [apply/base_separable/mem0v | apply: separable_add |].
Qed.
Lemma inseparable_add K x y :
purely_inseparable_element K x -> purely_inseparable_element K y ->
purely_inseparable_element K (x + y).
Proof.
have insepP := purely_inseparable_elementP_pchar.
move=> /insepP[n pcharLn Kxn] /insepP[m pcharLm Kym]; apply/insepP.
have pcharLnm: [pchar L].-nat (n * m)%N by rewrite pnatM pcharLn.
by exists (n * m)%N; rewrite ?exprDn_pchar // {2}mulnC !exprM memvD // rpredX.
Qed.
Lemma inseparable_sum I r (P : pred I) (v_ : I -> L) K :
(forall i, P i -> purely_inseparable_element K (v_ i)) ->
purely_inseparable_element K (\sum_(i <- r | P i) v_ i).
Proof.
move=> insepKi.
by elim/big_ind: _; [apply/base_inseparable/mem0v | apply: inseparable_add |].
Qed.
Lemma separableP {K E} :
reflect (forall y, y \in E -> separable_element K y) (separable K E).
Proof.
apply/(iffP idP)=> [/allP|] sepK_E; last by apply/allP=> x /vbasis_mem/sepK_E.
move=> y /coord_vbasis->; apply/separable_sum=> i _.
have: separable_element K (vbasis E)`_i by apply/sepK_E/memt_nth.
by move/adjoin_separableP; apply; rewrite rpredZ ?memv_adjoin.
Qed.
Lemma purely_inseparableP {K E} :
reflect (forall y, y \in E -> purely_inseparable_element K y)
(purely_inseparable K E).
Proof.
apply/(iffP idP)=> [/allP|] sep'K_E; last by apply/allP=> x /vbasis_mem/sep'K_E.
move=> y /coord_vbasis->; apply/inseparable_sum=> i _.
have: purely_inseparable_element K (vbasis E)`_i by apply/sep'K_E/memt_nth.
case/purely_inseparable_elementP_pchar=> n pcharLn K_Ein.
by apply/purely_inseparable_elementP_pchar; exists n; rewrite // exprZn rpredZ.
Qed.
Lemma adjoin_separable_eq K x : separable_element K x = separable K <<K; x>>%VS.
Proof. exact: sameP adjoin_separableP separableP. Qed.
Lemma separable_inseparable_decomposition E K :
{x | x \in E /\ separable_element K x & purely_inseparable <<K; x>> E}.
Proof.
without loss sKE: K / (K <= E)%VS.
case/(_ _ (capvSr K E)) => x [Ex sepKEx] /purely_inseparableP sep'KExE.
exists x; first by split; last exact/(separable_elementS _ sepKEx)/capvSl.
apply/purely_inseparableP=> y /sep'KExE; apply: sub_inseparable.
exact/adjoinSl/capvSl.
pose E_ i := (vbasis E)`_i; pose fP i := separable_exponent_pchar K (E_ i).
pose f i := E_ i ^+ ex_minn (fP i); pose s := mkseq f (\dim E).
pose K' := <<K & s>>%VS.
have sepKs: all (separable_element K) s.
by rewrite all_map /f; apply/allP=> i _ /=; case: ex_minnP => m /andP[].
have [x sepKx defKx]: {x | x \in E /\ separable_element K x & K' = <<K; x>>%VS}.
have: all [in E] s.
rewrite all_map; apply/allP=> i; rewrite mem_iota => ltis /=.
by rewrite rpredX // vbasis_mem // memt_nth.
rewrite {}/K'; elim/last_ind: s sepKs => [|s t IHs].
by exists 0; [rewrite base_separable mem0v | rewrite adjoin_nil addv0].
rewrite adjoin_rcons !all_rcons => /andP[sepKt sepKs] /andP[/= Et Es].
have{IHs sepKs Es} [y [Ey sepKy] ->{s}] := IHs sepKs Es.
have /sig_eqW[x defKx] := Primitive_Element_Theorem t sepKy.
exists x; [split | exact: defKx].
suffices: (<<K; x>> <= E)%VS by case/FadjoinP.
by rewrite -defKx !(sameP FadjoinP andP) sKE Ey Et.
apply/adjoin_separableP=> z; rewrite -defKx => Kyt_z.
apply: adjoin_separable sepKy _; apply: adjoin_separableP Kyt_z.
exact: separable_elementS (subv_adjoin K y) sepKt.
exists x; rewrite // -defKx; apply/(all_nthP 0)=> i; rewrite size_tuple => ltiE.
apply/purely_inseparable_elementP_pchar.
exists (ex_minn (fP i)); first by case: ex_minnP => n /andP[].
by apply/seqv_sub_adjoin/map_f; rewrite mem_iota.
Qed.
Definition separable_generator K E : L :=
s2val (locked (separable_inseparable_decomposition E K)).
Lemma separable_generator_mem E K : separable_generator K E \in E.
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generatorP E K : separable_element K (separable_generator K E).
Proof. by rewrite /separable_generator; case: (locked _) => ? []. Qed.
Lemma separable_generator_maximal E K :
purely_inseparable <<K; separable_generator K E>> E.
Proof. by rewrite /separable_generator; case: (locked _). Qed.
Lemma sub_adjoin_separable_generator E K :
separable K E -> (E <= <<K; separable_generator K E>>)%VS.
Proof.
move/separableP=> sepK_E; apply/subvP=> v Ev.
rewrite -separable_inseparable_element.
have /purely_inseparableP-> // := separable_generator_maximal E K.
by rewrite (separable_elementS _ (sepK_E _ Ev)) // subv_adjoin.
Qed.
Lemma eq_adjoin_separable_generator E K :
separable K E -> (K <= E)%VS ->
E = <<K; separable_generator K E>>%VS :> {vspace _}.
Proof.
move=> sepK_E sKE; apply/eqP; rewrite eqEsubv sub_adjoin_separable_generator //.
by apply/FadjoinP/andP; rewrite sKE separable_generator_mem.
Qed.
Lemma separable_refl K : separable K K.
Proof. exact/separableP/base_separable. Qed.
Lemma separable_trans M K E : separable K M -> separable M E -> separable K E.
Proof.
move/sub_adjoin_separable_generator.
set x := separable_generator K M => sMKx /separableP sepM_E.
apply/separableP => w /sepM_E/(separable_elementS sMKx).
case/strong_Primitive_Element_Theorem => _ _ -> //.
exact: separable_generatorP.
Qed.
Lemma separableS K1 K2 E2 E1 :
(K1 <= K2)%VS -> (E2 <= E1)%VS -> separable K1 E1 -> separable K2 E2.
Proof.
move=> sK12 /subvP sE21 /separableP sepK1_E1.
by apply/separableP=> y /sE21/sepK1_E1/(separable_elementS sK12).
Qed.
Lemma separableSl K M E : (K <= M)%VS -> separable K E -> separable M E.
Proof. by move/separableS; apply. Qed.
Lemma separableSr K M E : (M <= E)%VS -> separable K E -> separable K M.
Proof. exact: separableS. Qed.
Lemma separable_Fadjoin_seq K rs :
all (separable_element K) rs -> separable K <<K & rs>>.
Proof.
elim/last_ind: rs => [|s x IHs] in K *.
by rewrite adjoin_nil subfield_closed separable_refl.
rewrite all_rcons adjoin_rcons => /andP[sepKx /IHs/separable_trans-> //].
by rewrite -adjoin_separable_eq (separable_elementS _ sepKx) ?subv_adjoin_seq.
Qed.
Lemma purely_inseparable_refl K : purely_inseparable K K.
Proof. by apply/purely_inseparableP; apply: base_inseparable. Qed.
Lemma purely_inseparable_trans M K E :
purely_inseparable K M -> purely_inseparable M E -> purely_inseparable K E.
Proof.
have insepP := purely_inseparableP => /insepP insepK_M /insepP insepM_E.
have insepPe := purely_inseparable_elementP_pchar.
apply/insepP=> x /insepM_E/insepPe[n pcharLn /insepK_M/insepPe[m pcharLm Kxnm]].
by apply/insepPe; exists (n * m)%N; rewrite ?exprM // pnatM pcharLn pcharLm.
Qed.
End Separable.
Arguments separable_elementP {F L K x}.
Arguments separablePn_pchar {F L K x}.
Arguments Derivation_separableP {F L K x}.
Arguments adjoin_separableP {F L K x}.
Arguments purely_inseparable_elementP_pchar {F L K x}.
Arguments separableP {F L K E}.
Arguments purely_inseparableP {F L K E}.
|
CMField.lean
|
/-
Copyright (c) 2025 X. Roblot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Roblot
-/
import Mathlib.NumberTheory.NumberField.InfinitePlace.TotallyRealComplex
import Mathlib.NumberTheory.NumberField.Units.DirichletTheorem
/-!
# CM-extension of number fields
A CM-extension `K/F` of number fields is an extension where `K` is totally complex, `F` is
totally real and `K` is a quadratic extension of `F`. In this situation, the totally real
subfield `F` is (isomorphic to) the maximal real subfield of `K`.
## Main definitions
* `NumberField.CMExtension.complexConj`: the complex conjugation of a CM-extension.
* `NumberField.CMExtension.isConj_complexConj`: the complex conjugation is the conjugation
of any complex embedding of a `CM`-extension.
* `NumberField.IsCMField`: A predicate that says that if a number field is CM, then it is a totally
complex quadratic extension of its totally real subfield
* `NumberField.CMExtension.equivMaximalRealSubfield`: Any field `F` such that `K/F` is a
CM-extension is isomorphic to the maximal real subfield of `K`.
* `NumberField.IsCM.ofIsCMExtension`: Assume that there exists `F` such that `K/F` is a
CM-extension. Then `K` is CM.
* `NumberField.IsCMField.of_isMulCommutative`: A totally complex abelian extension of `β` is CM.
## Implementation note
Most result are proved under the general hypothesis: `K/F` quadratic extension of number fields
with `F` totally real and `K` totally complex and then, if relevant, we deduce the special case
`F = maximalRealSubfield K`. Results of the first kind live in the `NumberField.CMExtension`
namespace whereas results of the second kind live in the `NumberField.IsCMField` namespace.
-/
open NumberField ComplexEmbedding InfinitePlace Algebra
open scoped ComplexConjugate
namespace NumberField
namespace CMExtension
variable (F K : Type*) [Field F] [NumberField F] [IsTotallyReal F] [Field K] [NumberField K]
[IsTotallyComplex K] [Algebra F K] [IsQuadraticExtension F K]
theorem card_infinitePlace_eq_card_infinitePlace :
Fintype.card (InfinitePlace F) = Fintype.card (InfinitePlace K) := by
rw [card_eq_nrRealPlaces_add_nrComplexPlaces, card_eq_nrRealPlaces_add_nrComplexPlaces,
IsTotallyComplex.nrRealPlaces_eq_zero K, IsTotallyReal.nrComplexPlaces_eq_zero F, zero_add,
add_zero, β IsTotallyReal.finrank, β Nat.mul_left_cancel_iff zero_lt_two,
β IsTotallyComplex.finrank, β Module.finrank_mul_finrank β F K, mul_comm,
IsQuadraticExtension.finrank_eq_two F K]
theorem units_rank_eq_units_rank :
Units.rank F = Units.rank K := by
rw [Units.rank, Units.rank, card_infinitePlace_eq_card_infinitePlace F K]
variable {K}
theorem exists_isConj (Ο : K β+* β) :
β Ο : K ββ[F] K, IsConj Ο Ο :=
exists_isConj_of_isRamified <|
isRamified_iff.mpr β¨IsTotallyComplex.isComplex _, IsTotallyReal.isReal _β©
omit [IsTotallyReal F] in
/--
All the conjugations of a `CM`-extension are the same.
-/
theorem isConj_eq_isConj {Ο Ο : K β+* β} {Ο Ο : K ββ[F] K} (hΟ : IsConj Ο Ο) (hΟ : IsConj Ο Ο) :
Ο = Ο := by
have : Nat.card (K ββ[F] K) = 2 :=
(IsQuadraticExtension.finrank_eq_two F K) βΈ IsGalois.card_aut_eq_finrank F K
rw [Nat.card_eq_two_iff' 1] at this
exact ExistsUnique.unique this
((isConj_ne_one_iff hΟ).mpr <| IsTotallyComplex.complexEmbedding_not_isReal Ο)
((isConj_ne_one_iff hΟ).mpr <| IsTotallyComplex.complexEmbedding_not_isReal Ο)
variable (K) in
/--
The complex conjugation of a `CM`-extension.
-/
noncomputable def complexConj : K ββ[F] K :=
(exists_isConj F (Classical.choice (inferInstance : Nonempty _))).choose
/--
The complex conjugation is the conjugation of any complex embedding of a `CM`-extension.
-/
theorem isConj_complexConj (Ο : K β+* β) :
IsConj Ο (complexConj F K) := by
obtain β¨Ο, hΟβ© := exists_isConj F Ο
have := (exists_isConj F (Classical.choice (inferInstance : Nonempty (K β+* β)))).choose_spec
rwa [isConj_eq_isConj F hΟ this] at hΟ
variable (K) in
theorem complexConj_ne_one :
complexConj F K β (1 : K ββ[F] K) :=
(isConj_ne_one_iff
(exists_isConj F (Classical.choice (inferInstance : Nonempty _))).choose_spec).mpr <|
IsTotallyComplex.complexEmbedding_not_isReal _
@[simp]
theorem complexEmbedding_complexConj (Ο : K β+* β) (x : K) :
Ο (complexConj F K x) = conj (Ο x) := by
rw [IsConj.eq (isConj_complexConj F Ο), RCLike.star_def]
@[simp]
theorem complexConj_apply_apply (x : K) :
complexConj F K (complexConj F K x) = x := by
let Ο : K β+* β := Classical.choice (inferInstance : Nonempty _)
exact isConj_apply_apply (isConj_complexConj F Ο) x
variable (K) in
/--
The complex conjugation is an automorphism of degree `2`.
-/
theorem orderOf_complexConj :
orderOf (complexConj F K : K ββ[F] K) = 2 :=
orderOf_eq_prime_iff.mpr β¨by ext; simp, complexConj_ne_one F Kβ©
variable (K) in
/--
The complex conjugation generates the Galois group of `K/F`.
-/
theorem zpowers_complexConj_eq_top :
Subgroup.zpowers (complexConj F K) = β€ := by
refine Subgroup.eq_top_of_card_eq _ ?_
rw [Nat.card_zpowers, orderOf_complexConj, IsGalois.card_aut_eq_finrank,
IsQuadraticExtension.finrank_eq_two]
theorem eq_maximalRealSubfield (E : Subfield K) [IsTotallyReal E] [IsQuadraticExtension E K] :
E = maximalRealSubfield K := by
refine le_antisymm (IsTotallyReal.le_maximalRealSubfield E) ?_
by_contra! h
have h' : E β (maximalRealSubfield K) = β€ := by
let L : IntermediateField E K := (E β (maximalRealSubfield K)).toIntermediateField
(fun x β¦ (le_sup_left (a := E)) x.prop)
have := ((IntermediateField.isSimpleOrder_of_finrank_prime E K
(IsQuadraticExtension.finrank_eq_two E K βΈ Nat.prime_two)).eq_bot_or_eq_top L).resolve_left ?_
Β· simpa [L] using congr_arg IntermediateField.toSubfield this
Β· contrapose! h
rw [β SetLike.coe_set_eq, Subfield.coe_toIntermediateField] at h
rw [β sup_eq_left, β SetLike.coe_set_eq, h, IntermediateField.coe_bot]
aesop
have : IsTotallyReal K := (h' βΈ isTotallyReal_sup).ofRingEquiv Subring.topEquiv
obtain w : InfinitePlace K := Classical.choice (inferInstance : Nonempty _)
exact (not_isReal_iff_isComplex.mpr (IsTotallyComplex.isComplex w)) (IsTotallyReal.isReal w)
variable (K)
/--
Any field `F` such that `K/F` is a CM-extension is isomorphic to the maximal real subfield of `K`.
-/
noncomputable def equivMaximalRealSubfield :
F β+* maximalRealSubfield K :=
(algebraMap F K).rangeRestrictFieldEquiv.trans (RingEquiv.subfieldCongr (by
have := IsTotallyReal.ofRingEquiv (algebraMap F K).rangeRestrictFieldEquiv
have : IsQuadraticExtension (algebraMap F K).fieldRange K :=
{ finrank_eq_two' :=
(IsQuadraticExtension.finrank_eq_two F K) βΈ Algebra.finrank_eq_of_equiv_equiv
(algebraMap F K).rangeRestrictFieldEquiv.symm (RingEquiv.refl K) (by ext; simp; rfl) }
exact eq_maximalRealSubfield (algebraMap F K).fieldRange))
@[simp]
theorem equivMaximalRealSubfield_apply (x : F) :
equivMaximalRealSubfield F K x = algebraMap F K x := rfl
@[simp]
theorem algebraMap_equivMaximalRealSubfield_symm_apply (x : maximalRealSubfield K) :
algebraMap F K ((CMExtension.equivMaximalRealSubfield F K).symm x) =
algebraMap (maximalRealSubfield K) K x := by
simpa using (equivMaximalRealSubfield_apply F K ((equivMaximalRealSubfield F K).symm x)).symm
end CMExtension
section maximalRealSubfield
/--
A number field `K` is `CM` if `K` is a totally complex quadratic extension of its maximal
real subfield.
-/
class IsCMField (K : Type*) [Field K] [NumberField K] [IsTotallyComplex K] : Prop where
is_quadratic : IsQuadraticExtension (maximalRealSubfield K) K
namespace IsCMField
variable (F K : Type*) [Field K] [NumberField K] [IsTotallyComplex K]
theorem ofCMExtension [Field F] [NumberField F] [IsTotallyReal F] [Algebra F K]
[IsQuadraticExtension F K] :
IsCMField K where
is_quadratic := β¨(IsQuadraticExtension.finrank_eq_two F K) βΈ finrank_eq_of_equiv_equiv
(CMExtension.equivMaximalRealSubfield F K).symm (RingEquiv.refl K) (by ext; simp)β©
open IntermediateField in
/--
A totally complex field that has a unique complex conjugation is CM.
-/
theorem of_forall_isConj {Ο : K ββ[β] K} (hΟ : β Ο : K β+* β, IsConj Ο Ο) :
IsCMField K := by
have : IsTotallyReal (fixedField (Subgroup.zpowers Ο)) := β¨fun w β¦ by
obtain β¨W, rflβ© := w.comap_surjective (K := K)
let Ο := subgroupEquivAlgEquiv _ β¨Ο, Subgroup.mem_zpowers Οβ©
have hΟ : IsConj W.embedding Ο := hΟ _
simpa [β isReal_mk_iff, β InfinitePlace.comap_mk, mk_embedding] using hΟ.isReal_compβ©
have : IsQuadraticExtension (fixedField (Subgroup.zpowers Ο)) K := β¨by
let Ο : K β+* β := Classical.choice (inferInstance : Nonempty _)
have hΟ' : Ο β 1 :=
(isConj_ne_one_iff (hΟ Ο)).mpr <| IsTotallyComplex.complexEmbedding_not_isReal Ο
rw [finrank_fixedField_eq_card, Nat.card_zpowers, orderOf_isConj_two_of_ne_one (hΟ Ο) hΟ']β©
exact ofCMExtension (fixedField (Subgroup.zpowers Ο)) K
/--
A totally complex abelian extension of `β` is CM.
-/
instance of_isMulCommutative [IsGalois β K] [IsMulCommutative (K ββ[β] K)] :
IsCMField K := by
let Ο : K β+* β := Classical.choice (inferInstance : Nonempty _)
obtain β¨Ο, hΟββ© : β Ο : K ββ[β] K, ComplexEmbedding.IsConj Ο Ο :=
exists_isConj_of_isRamified <|
isRamified_iff.mpr β¨IsTotallyComplex.isComplex _, IsTotallyReal.isReal _β©
have hΟβ : β (Ο : K β+* β), ComplexEmbedding.IsConj Ο Ο := by
intro Ο
obtain β¨Ξ½, rflβ© := ComplexEmbedding.exists_comp_symm_eq_of_comp_eq (k := β) Ο Ο (by ext; simp)
rw [show Ο = Ξ½.symmβ»ΒΉ * Ο * Ξ½.symm by simp]
exact hΟβ.comp _
exact of_forall_isConj K hΟβ
variable [IsCMField K]
instance isQuadraticExtension : IsQuadraticExtension (maximalRealSubfield K) K :=
IsCMField.is_quadratic
noncomputable instance starRing : StarRing K where
star := CMExtension.complexConj (maximalRealSubfield K) K
star_involutive _ := CMExtension.complexConj_apply_apply _ _
star_mul _ _ := by rw [map_mul, mul_comm]
star_add _ _ := by rw [map_add]
theorem card_infinitePlace_eq_card_infinitePlace :
Fintype.card (InfinitePlace (maximalRealSubfield K)) = Fintype.card (InfinitePlace K) :=
CMExtension.card_infinitePlace_eq_card_infinitePlace _ _
theorem units_rank_eq_units_rank :
Units.rank (maximalRealSubfield K) = Units.rank K :=
CMExtension.units_rank_eq_units_rank _ _
end IsCMField
end maximalRealSubfield
end NumberField
|
Lattice.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.Order.BoundedOrder.Basic
import Mathlib.Order.Lattice
/-!
# Bounded lattices
This file defines top and bottom elements (greatest and least elements) of a type, the bounded
variants of different kinds of lattices, sets up the typeclass hierarchy between them, and provides
instances for `Prop` and `fun`.
## Common lattices
* Distributive lattices with a bottom element. Notated by `[DistribLattice Ξ±] [OrderBot Ξ±]`.
It captures the properties of `Disjoint` that are common to `GeneralizedBooleanAlgebra` and
`DistribLattice` when `OrderBot`.
* Bounded and distributive lattice. Notated by `[DistribLattice Ξ±] [BoundedOrder Ξ±]`.
Typical examples include `Prop` and `Set Ξ±`.
-/
open Function OrderDual
universe u v
variable {Ξ± : Type u} {Ξ² : Type v}
/-! ### Top, bottom element -/
section SemilatticeSupTop
variable [SemilatticeSup Ξ±] [OrderTop Ξ±]
theorem top_sup_eq (a : Ξ±) : β€ β a = β€ :=
sup_of_le_left le_top
theorem sup_top_eq (a : Ξ±) : a β β€ = β€ :=
sup_of_le_right le_top
end SemilatticeSupTop
section SemilatticeSupBot
variable [SemilatticeSup Ξ±] [OrderBot Ξ±] {a b : Ξ±}
theorem bot_sup_eq (a : Ξ±) : β₯ β a = a :=
sup_of_le_right bot_le
theorem sup_bot_eq (a : Ξ±) : a β β₯ = a :=
sup_of_le_left bot_le
@[simp]
theorem sup_eq_bot_iff : a β b = β₯ β a = β₯ β§ b = β₯ := by rw [eq_bot_iff, sup_le_iff]; simp
end SemilatticeSupBot
section SemilatticeInfTop
variable [SemilatticeInf Ξ±] [OrderTop Ξ±] {a b : Ξ±}
lemma top_inf_eq (a : Ξ±) : β€ β a = a := inf_of_le_right le_top
lemma inf_top_eq (a : Ξ±) : a β β€ = a := inf_of_le_left le_top
@[simp]
theorem inf_eq_top_iff : a β b = β€ β a = β€ β§ b = β€ :=
@sup_eq_bot_iff Ξ±α΅α΅ _ _ _ _
end SemilatticeInfTop
section SemilatticeInfBot
variable [SemilatticeInf Ξ±] [OrderBot Ξ±]
lemma bot_inf_eq (a : Ξ±) : β₯ β a = β₯ := inf_of_le_left bot_le
lemma inf_bot_eq (a : Ξ±) : a β β₯ = β₯ := inf_of_le_right bot_le
end SemilatticeInfBot
section Logic
/-!
#### In this section we prove some properties about monotone and antitone operations on `Prop`
-/
section SemilatticeSup
variable [SemilatticeSup Ξ±]
theorem exists_ge_and_iff_exists {P : Ξ± β Prop} {xβ : Ξ±} (hP : Monotone P) :
(β x, xβ β€ x β§ P x) β β x, P x :=
β¨fun h => h.imp fun _ h => h.2, fun β¨x, hxβ© => β¨x β xβ, le_sup_right, hP le_sup_left hxβ©β©
lemma exists_and_iff_of_monotone {P Q : Ξ± β Prop} (hP : Monotone P) (hQ : Monotone Q) :
((β x, P x) β§ β x, Q x) β (β x, P x β§ Q x) :=
β¨fun β¨β¨x, hPxβ©, β¨y, hQxβ©β© β¦ β¨x β y, β¨hP le_sup_left hPx, hQ le_sup_right hQxβ©β©,
fun β¨x, hPx, hQxβ© β¦ β¨β¨x, hPxβ©, β¨x, hQxβ©β©β©
end SemilatticeSup
section SemilatticeInf
variable [SemilatticeInf Ξ±]
theorem exists_le_and_iff_exists {P : Ξ± β Prop} {xβ : Ξ±} (hP : Antitone P) :
(β x, x β€ xβ β§ P x) β β x, P x :=
exists_ge_and_iff_exists <| hP.dual_left
lemma exists_and_iff_of_antitone {P Q : Ξ± β Prop} (hP : Antitone P) (hQ : Antitone Q) :
((β x, P x) β§ β x, Q x) β (β x, P x β§ Q x) :=
β¨fun β¨β¨x, hPxβ©, β¨y, hQxβ©β© β¦ β¨x β y, β¨hP inf_le_left hPx, hQ inf_le_right hQxβ©β©,
fun β¨x, hPx, hQxβ© β¦ β¨β¨x, hPxβ©, β¨x, hQxβ©β©β©
end SemilatticeInf
end Logic
section LinearOrder
variable [LinearOrder Ξ±]
-- `simp` can prove these, so they shouldn't be simp-lemmas.
theorem min_bot_left [OrderBot Ξ±] (a : Ξ±) : min β₯ a = β₯ := bot_inf_eq _
theorem max_top_left [OrderTop Ξ±] (a : Ξ±) : max β€ a = β€ := top_sup_eq _
theorem min_top_left [OrderTop Ξ±] (a : Ξ±) : min β€ a = a := top_inf_eq _
theorem max_bot_left [OrderBot Ξ±] (a : Ξ±) : max β₯ a = a := bot_sup_eq _
theorem min_top_right [OrderTop Ξ±] (a : Ξ±) : min a β€ = a := inf_top_eq _
theorem max_bot_right [OrderBot Ξ±] (a : Ξ±) : max a β₯ = a := sup_bot_eq _
theorem min_bot_right [OrderBot Ξ±] (a : Ξ±) : min a β₯ = β₯ := inf_bot_eq _
theorem max_top_right [OrderTop Ξ±] (a : Ξ±) : max a β€ = β€ := sup_top_eq _
theorem max_eq_bot [OrderBot Ξ±] {a b : Ξ±} : max a b = β₯ β a = β₯ β§ b = β₯ :=
sup_eq_bot_iff
theorem min_eq_top [OrderTop Ξ±] {a b : Ξ±} : min a b = β€ β a = β€ β§ b = β€ :=
inf_eq_top_iff
@[simp]
theorem min_eq_bot [OrderBot Ξ±] {a b : Ξ±} : min a b = β₯ β a = β₯ β¨ b = β₯ := by
simp_rw [β le_bot_iff, inf_le_iff]
@[simp]
theorem max_eq_top [OrderTop Ξ±] {a b : Ξ±} : max a b = β€ β a = β€ β¨ b = β€ :=
@min_eq_bot Ξ±α΅α΅ _ _ a b
@[aesop (rule_sets := [finiteness]) safe apply]
lemma max_ne_top [OrderTop Ξ±] {a b : Ξ±} (ha : a β β€) (hb : b β β€) : max a b β β€ := by
by_contra h
obtain (h | h) := max_eq_top.mp h
all_goals simp_all
end LinearOrder
/-! ### Induction on `WellFoundedGT` and `WellFoundedLT` -/
section WellFounded
@[elab_as_elim]
theorem WellFoundedGT.induction_top [Preorder Ξ±] [WellFoundedGT Ξ±] [OrderTop Ξ±]
{P : Ξ± β Prop} (hexists : β M, P M) (hind : β N β β€, P N β β M > N, P M) : P β€ := by
contrapose! hexists
intro M
induction M using WellFoundedGT.induction with
| ind x IH =>
by_cases hx : x = β€
Β· exact hx βΈ hexists
Β· intro hx'
obtain β¨M, hM, hM'β© := hind x hx hx'
exact IH _ hM hM'
@[elab_as_elim]
theorem WellFoundedLT.induction_bot [Preorder Ξ±] [WellFoundedLT Ξ±] [OrderBot Ξ±]
{P : Ξ± β Prop} (hexists : β M, P M) (hind : β N β β₯, P N β β M < N, P M) : P β₯ := by
contrapose! hexists
intro M
induction M using WellFoundedLT.induction with
| ind x IH =>
by_cases hx : x = β₯
Β· exact hx βΈ hexists
Β· intro hx'
obtain β¨M, hM, hM'β© := hind x hx hx'
exact IH _ hM hM'
end WellFounded
|
frobenius.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat div.
From mathcomp Require Import fintype bigop prime finset fingroup morphism.
From mathcomp Require Import perm action quotient gproduct cyclic center.
From mathcomp Require Import pgroup nilpotent sylow hall abelian.
(******************************************************************************)
(* Definition of Frobenius groups, some basic results, and the Frobenius *)
(* theorem on the number of solutions of x ^+ n = 1. *)
(* semiregular K H <-> *)
(* the internal action of H on K is semiregular, i.e., no nontrivial *)
(* elements of H and K commute; note that this is actually a symmetric *)
(* condition. *)
(* semiprime K H <-> *)
(* the internal action of H on K is "prime", i.e., an element of K that *)
(* centralises a nontrivial element of H must centralise all of H. *)
(* normedTI A G L <=> *)
(* A is nonempty, strictly disjoint from its conjugates in G, and has *)
(* normaliser L in G. *)
(* [Frobenius G = K ><| H] <=> *)
(* G is (isomorphic to) a Frobenius group with kernel K and complement *)
(* H. This is an effective predicate (in bool), which tests the *)
(* equality with the semidirect product, and then the fact that H is a *)
(* proper self-normalizing TI-subgroup of G. *)
(* [Frobenius G with kernel H] <=> *)
(* G is (isomorphic to) a Frobenius group with kernel K; same as above, *)
(* but without the semi-direct product. *)
(* [Frobenius G with complement H] <=> *)
(* G is (isomorphic to) a Frobenius group with complement H; same as *)
(* above, but without the semi-direct product. The proof that this form *)
(* is equivalent to the above (i.e., the existence of Frobenius *)
(* kernels) requires character theory and will only be proved in the *)
(* vcharacter.v file. *)
(* [Frobenius G] <=> G is a Frobenius group. *)
(* Frobenius_action G H S to <-> *)
(* The action to of G on S defines an isomorphism of G with a *)
(* (permutation) Frobenius group, i.e., to is faithful and transitive *)
(* on S, no nontrivial element of G fixes more than one point in S, and *)
(* H is the stabilizer of some element of S, and non-trivial. Thus, *)
(* Frobenius_action G H S 'P *)
(* asserts that G is a Frobenius group in the classic sense. *)
(* has_Frobenius_action G H <-> *)
(* Frobenius_action G H S to holds for some sT : finType, S : {set st} *)
(* and to : {action gT &-> sT}. This is a predicate in Prop, but is *)
(* exactly reflected by [Frobenius G with complement H] : bool. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Definitions.
Variable gT : finGroupType.
Implicit Types A G K H L : {set gT}.
(* Corresponds to "H acts on K in a regular manner" in B & G. *)
Definition semiregular K H := {in H^#, forall x, 'C_K[x] = 1}.
(* Corresponds to "H acts on K in a prime manner" in B & G. *)
Definition semiprime K H := {in H^#, forall x, 'C_K[x] = 'C_K(H)}.
Definition normedTI A G L := [&& A != set0, trivIset (A :^: G) & 'N_G(A) == L].
Definition Frobenius_group_with_complement G H := (H != G) && normedTI H^# G H.
Definition Frobenius_group G :=
[exists H : {group gT}, Frobenius_group_with_complement G H].
Definition Frobenius_group_with_kernel_and_complement G K H :=
(K ><| H == G) && Frobenius_group_with_complement G H.
Definition Frobenius_group_with_kernel G K :=
[exists H : {group gT}, Frobenius_group_with_kernel_and_complement G K H].
Section FrobeniusAction.
Variables G H : {set gT}.
Variables (sT : finType) (S : {set sT}) (to : {action gT &-> sT}).
Definition Frobenius_action :=
[/\ [faithful G, on S | to],
[transitive G, on S | to],
{in G^#, forall x, #|'Fix_(S | to)[x]| <= 1},
H != 1
& exists2 u, u \in S & H = 'C_G[u | to]].
End FrobeniusAction.
Variant has_Frobenius_action G H : Prop :=
hasFrobeniusAction sT S to of @Frobenius_action G H sT S to.
End Definitions.
Arguments semiregular {gT} K%_g H%_g.
Arguments semiprime {gT} K%_g H%_g.
Arguments normedTI {gT} A%_g G%_g L%_g.
Arguments Frobenius_group_with_complement {gT} G%_g H%_g.
Arguments Frobenius_group {gT} G%_g.
Arguments Frobenius_group_with_kernel {gT} G%_g K%_g.
Arguments Frobenius_group_with_kernel_and_complement {gT} G%_g K%_g H%_g.
Arguments Frobenius_action {gT} G%_g H%_g {sT} S%_g to%_act.
Arguments has_Frobenius_action {gT} G%_g H%_g.
Notation "[ 'Frobenius' G 'with' 'complement' H ]" :=
(Frobenius_group_with_complement G H)
(G at level 50,
format "[ 'Frobenius' G 'with' 'complement' H ]") : group_scope.
Notation "[ 'Frobenius' G 'with' 'kernel' K ]" :=
(Frobenius_group_with_kernel G K)
(format "[ 'Frobenius' G 'with' 'kernel' K ]") : group_scope.
Notation "[ 'Frobenius' G ]" := (Frobenius_group G)
(format "[ 'Frobenius' G ]") : group_scope.
Notation "[ 'Frobenius' G = K ><| H ]" :=
(Frobenius_group_with_kernel_and_complement G K H)
(K, H at level 35,
format "[ 'Frobenius' G = K ><| H ]") : group_scope.
Section FrobeniusBasics.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H K L R X : {group gT}).
Lemma semiregular1l H : semiregular 1 H.
Proof. by move=> x _ /=; rewrite setI1g. Qed.
Lemma semiregular1r K : semiregular K 1.
Proof. by move=> x; rewrite setDv inE. Qed.
Lemma semiregular_sym H K : semiregular K H -> semiregular H K.
Proof.
move=> regH x /setD1P[ntx Kx]; apply: contraNeq ntx.
rewrite -subG1 -setD_eq0 -setIDAC => /set0Pn[y /setIP[Hy cxy]].
by rewrite (sameP eqP set1gP) -(regH y Hy) inE Kx cent1C.
Qed.
Lemma semiregularS K1 K2 A1 A2 :
K1 \subset K2 -> A1 \subset A2 -> semiregular K2 A2 -> semiregular K1 A1.
Proof.
move=> sK12 sA12 regKA2 x /setD1P[ntx /(subsetP sA12)A2x].
by apply/trivgP; rewrite -(regKA2 x) ?inE ?ntx ?setSI.
Qed.
Lemma semiregular_prime H K : semiregular K H -> semiprime K H.
Proof.
move=> regH x Hx; apply/eqP; rewrite eqEsubset {1}regH // sub1G.
by rewrite -cent_set1 setIS ?centS // sub1set; case/setD1P: Hx.
Qed.
Lemma semiprime_regular H K : semiprime K H -> 'C_K(H) = 1 -> semiregular K H.
Proof. by move=> prKH tiKcH x Hx; rewrite prKH. Qed.
Lemma semiprimeS K1 K2 A1 A2 :
K1 \subset K2 -> A1 \subset A2 -> semiprime K2 A2 -> semiprime K1 A1.
Proof.
move=> sK12 sA12 prKA2 x /setD1P[ntx A1x].
apply/eqP; rewrite eqEsubset andbC -{1}cent_set1 setIS ?centS ?sub1set //=.
rewrite -(setIidPl sK12) -!setIA prKA2 ?setIS ?centS //.
by rewrite !inE ntx (subsetP sA12).
Qed.
Lemma cent_semiprime H K X :
semiprime K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 'C_K(H).
Proof.
move=> prKH sXH /trivgPn[x Xx ntx]; apply/eqP.
rewrite eqEsubset -{1}(prKH x) ?inE ?(subsetP sXH) ?ntx //=.
by rewrite -cent_cycle !setIS ?centS ?cycle_subG.
Qed.
Lemma stab_semiprime H K X :
semiprime K H -> X \subset K -> 'C_H(X) != 1 -> 'C_H(X) = H.
Proof.
move=> prKH sXK ntCHX; apply/setIidPl; rewrite centsC -subsetIidl.
rewrite -{2}(setIidPl sXK) -setIA -(cent_semiprime prKH _ ntCHX) ?subsetIl //.
by rewrite !subsetI subxx sXK centsC subsetIr.
Qed.
Lemma cent_semiregular H K X :
semiregular K H -> X \subset H -> X :!=: 1 -> 'C_K(X) = 1.
Proof.
move=> regKH sXH /trivgPn[x Xx ntx]; apply/trivgP.
rewrite -(regKH x) ?inE ?(subsetP sXH) ?ntx ?setIS //=.
by rewrite -cent_cycle centS ?cycle_subG.
Qed.
Lemma regular_norm_dvd_pred K H :
H \subset 'N(K) -> semiregular K H -> #|H| %| #|K|.-1.
Proof.
move=> nKH regH; have actsH: [acts H, on K^# | 'J] by rewrite astabsJ normD1.
rewrite (cardsD1 1 K) group1 -(acts_sum_card_orbit actsH) /=.
rewrite (eq_bigr (fun _ => #|H|)) ?sum_nat_const ?dvdn_mull //.
move=> _ /imsetP[x /setIdP[ntx Kx] ->]; rewrite card_orbit astab1J.
rewrite ['C_H[x]](trivgP _) ?indexg1 //=.
apply/subsetP=> y /setIP[Hy cxy]; apply: contraR ntx => nty.
by rewrite -[[set 1]](regH y) inE ?nty // Kx cent1C.
Qed.
Lemma regular_norm_coprime K H :
H \subset 'N(K) -> semiregular K H -> coprime #|K| #|H|.
Proof.
move=> nKH regH.
by rewrite (coprime_dvdr (regular_norm_dvd_pred nKH regH)) ?coprimenP.
Qed.
Lemma semiregularJ K H x : semiregular K H -> semiregular (K :^ x) (H :^ x).
Proof.
move=> regH yx; rewrite -conjD1g => /imsetP[y Hy ->].
by rewrite cent1J -conjIg regH ?conjs1g.
Qed.
Lemma semiprimeJ K H x : semiprime K H -> semiprime (K :^ x) (H :^ x).
Proof.
move=> prH yx; rewrite -conjD1g => /imsetP[y Hy ->].
by rewrite cent1J centJ -!conjIg prH.
Qed.
Lemma normedTI_P A G L :
reflect [/\ A != set0, L \subset 'N_G(A)
& {in G, forall g, ~~ [disjoint A & A :^ g] -> g \in L}]
(normedTI A G L).
Proof.
apply: (iffP and3P) => [[nzA /trivIsetP tiAG /eqP <-] | [nzA sLN tiAG]].
split=> // g Gg; rewrite inE Gg (sameP normP eqP) /= eq_sym; apply: contraR.
by apply: tiAG; rewrite ?mem_orbit ?orbit_refl.
have [/set0Pn[a Aa] /subsetIP[_ nAL]] := (nzA, sLN); split=> //; last first.
rewrite eqEsubset sLN andbT; apply/subsetP=> x /setIP[Gx nAx].
by apply/tiAG/pred0Pn=> //; exists a; rewrite /= (normP nAx) Aa.
apply/trivIsetP=> _ _ /imsetP[x Gx ->] /imsetP[y Gy ->]; apply: contraR.
rewrite -setI_eq0 -(mulgKV x y) conjsgM; set g := (y * x^-1)%g.
have Gg: g \in G by rewrite groupMl ?groupV.
rewrite -conjIg (inj_eq (act_inj 'Js x)) (eq_sym A) (sameP eqP normP).
by rewrite -cards_eq0 cardJg cards_eq0 setI_eq0 => /tiAG/(subsetP nAL)->.
Qed.
Arguments normedTI_P {A G L}.
Lemma normedTI_memJ_P A G L :
reflect [/\ A != set0, L \subset G
& {in A & G, forall a g, (a ^ g \in A) = (g \in L)}]
(normedTI A G L).
Proof.
apply: (iffP normedTI_P) => [[-> /subsetIP[sLG nAL] tiAG] | [-> sLG tiAG]].
split=> // a g Aa Gg; apply/idP/idP=> [Aag | Lg]; last first.
by rewrite memJ_norm ?(subsetP nAL).
by apply/tiAG/pred0Pn=> //; exists (a ^ g)%g; rewrite /= Aag memJ_conjg.
split=> // [ | g Gg /pred0Pn[ag /=]]; last first.
by rewrite andbC => /andP[/imsetP[a Aa ->]]; rewrite tiAG.
apply/subsetP=> g Lg; have Gg := subsetP sLG g Lg.
by rewrite !inE Gg; apply/subsetP=> _ /imsetP[a Aa ->]; rewrite tiAG.
Qed.
Lemma partition_class_support A G :
A != set0 -> trivIset (A :^: G) -> partition (A :^: G) (class_support A G).
Proof.
rewrite /partition cover_imset -class_supportEr eqxx => nzA ->.
by apply: contra nzA => /imsetP[x _ /eqP]; rewrite eq_sym -!cards_eq0 cardJg.
Qed.
Lemma partition_normedTI A G L :
normedTI A G L -> partition (A :^: G) (class_support A G).
Proof. by case/and3P=> ntA tiAG _; apply: partition_class_support. Qed.
Lemma card_support_normedTI A G L :
normedTI A G L -> #|class_support A G| = (#|A| * #|G : L|)%N.
Proof.
case/and3P=> ntA tiAG /eqP <-; rewrite -card_conjugates mulnC.
apply: card_uniform_partition (partition_class_support ntA tiAG).
by move=> _ /imsetP[y _ ->]; rewrite cardJg.
Qed.
Lemma normedTI_S A B G L :
A != set0 -> L \subset 'N(A) -> A \subset B -> normedTI B G L ->
normedTI A G L.
Proof.
move=> nzA /subsetP nAL /subsetP sAB /normedTI_memJ_P[nzB sLG tiB].
apply/normedTI_memJ_P; split=> // a x Aa Gx.
by apply/idP/idP => [Aax | /nAL/memJ_norm-> //]; rewrite -(tiB a) ?sAB.
Qed.
Lemma cent1_normedTI A G L :
normedTI A G L -> {in A, forall x, 'C_G[x] \subset L}.
Proof.
case/normedTI_memJ_P=> [_ _ tiAG] x Ax; apply/subsetP=> y /setIP[Gy cxy].
by rewrite -(tiAG x) // /(x ^ y) -(cent1P cxy) mulKg.
Qed.
Lemma Frobenius_actionP G H :
reflect (has_Frobenius_action G H) [Frobenius G with complement H].
Proof.
apply: (iffP andP) => [[neqHG] | [sT S to [ffulG transG regG ntH [u Su defH]]]].
case/normedTI_P=> nzH /subsetIP[sHG _] tiHG.
suffices: Frobenius_action G H (rcosets H G) 'Rs by apply: hasFrobeniusAction.
pose Hfix x := 'Fix_(rcosets H G | 'Rs)[x].
have regG: {in G^#, forall x, #|Hfix x| <= 1}.
move=> x /setD1P[ntx Gx].
apply: wlog_neg; rewrite -ltnNge => /ltnW/card_gt0P/=[Hy].
rewrite -(cards1 Hy) => /setIP[/imsetP[y Gy ->{Hy}] cHyx].
apply/subset_leq_card/subsetP=> _ /setIP[/imsetP[z Gz ->] cHzx].
rewrite -!sub_astab1 !astab1_act !sub1set astab1Rs in cHyx cHzx *.
rewrite !rcosetE; apply/set1P/rcoset_eqP; rewrite mem_rcoset.
apply: tiHG; [by rewrite !in_group | apply/pred0Pn; exists (x ^ y^-1)].
by rewrite conjD1g !inE conjg_eq1 ntx -mem_conjg cHyx conjsgM memJ_conjg.
have ntH: H :!=: 1 by rewrite -subG1 -setD_eq0.
split=> //; first 1 last; first exact: transRs_rcosets.
by exists (val H); rewrite ?orbit_refl // astab1Rs (setIidPr sHG).
apply/subsetP=> y /setIP[Gy cHy]; apply: contraR neqHG => nt_y.
rewrite (index1g sHG) //; apply/eqP; rewrite eqn_leq indexg_gt0 andbT.
apply: leq_trans (regG y _); last by rewrite setDE 2!inE Gy nt_y /=.
by rewrite /Hfix (setIidPl _) -1?astabC ?sub1set.
have sHG: H \subset G by rewrite defH subsetIl.
split.
apply: contraNneq ntH => /= defG.
suffices defS: S = [set u] by rewrite -(trivgP ffulG) /= defS defH.
apply/eqP; rewrite eq_sym eqEcard sub1set Su.
by rewrite -(atransP transG u Su) card_orbit -defH defG indexgg cards1.
apply/normedTI_P; rewrite setD_eq0 subG1 normD1 subsetI sHG normG.
split=> // x Gx; rewrite -setI_eq0 conjD1g defH inE Gx conjIg conjGid //.
rewrite -setDIl -setIIr -astab1_act setDIl => /set0Pn[y /setIP[Gy /setD1P[_]]].
case/setIP; rewrite 2!(sameP astab1P afix1P) => cuy cuxy; apply/astab1P.
apply: contraTeq (regG y Gy) => cu'x.
rewrite (cardD1 u) (cardD1 (to u x)) inE Su cuy inE /= inE cu'x cuxy.
by rewrite (actsP (atrans_acts transG)) ?Su.
Qed.
Section FrobeniusProperties.
Variables G H K : {group gT}.
Hypothesis frobG : [Frobenius G = K ><| H].
Lemma FrobeniusWker : [Frobenius G with kernel K].
Proof. by apply/existsP; exists H. Qed.
Lemma FrobeniusWcompl : [Frobenius G with complement H].
Proof. by case/andP: frobG. Qed.
Lemma FrobeniusW : [Frobenius G].
Proof. by apply/existsP; exists H; apply: FrobeniusWcompl. Qed.
Lemma Frobenius_context :
[/\ K ><| H = G, K :!=: 1, H :!=: 1, K \proper G & H \proper G].
Proof.
have [/eqP defG neqHG ntH _] := and4P frobG; rewrite setD_eq0 subG1 in ntH.
have ntK: K :!=: 1 by apply: contraNneq neqHG => K1; rewrite -defG K1 sdprod1g.
rewrite properEcard properEneq neqHG; have /mulG_sub[-> ->] := sdprodW defG.
by rewrite -(sdprod_card defG) ltn_Pmulr ?cardG_gt1.
Qed.
Lemma Frobenius_partition : partition (gval K |: (H^# :^: K)) G.
Proof.
have [/eqP defG _ tiHG] := and3P frobG; have [_ tiH1G /eqP defN] := and3P tiHG.
have [[_ /mulG_sub[sKG sHG] nKH tiKH] mulHK] := (sdprodP defG, sdprodWC defG).
set HG := H^# :^: K; set KHG := _ |: _.
have defHG: HG = H^# :^: G.
have: 'C_G[H^# | 'Js] * K = G by rewrite astab1Js defN mulHK.
move/subgroup_transitiveP/atransP.
by apply; rewrite ?atrans_orbit ?orbit_refl.
have /and3P[defHK _ nzHG] := partition_normedTI tiHG.
rewrite -defHG in defHK nzHG tiH1G.
have [tiKHG HG'K]: trivIset KHG /\ gval K \notin HG.
apply: trivIsetU1 => // _ /imsetP[x Kx ->]; rewrite -setI_eq0.
by rewrite -(conjGid Kx) -conjIg setIDA tiKH setDv conj0g.
rewrite /partition andbC tiKHG !inE negb_or nzHG eq_sym -card_gt0 cardG_gt0 /=.
rewrite eqEcard; apply/andP; split.
rewrite /cover big_setU1 //= subUset sKG -/(cover HG) (eqP defHK).
by rewrite class_support_subG // (subset_trans _ sHG) ?subD1set.
rewrite -(eqnP tiKHG) big_setU1 //= (eqnP tiH1G) (eqP defHK).
rewrite (card_support_normedTI tiHG) -(Lagrange sHG) (cardsD1 1) group1 mulSn.
by rewrite leq_add2r -mulHK indexMg -indexgI tiKH indexg1.
Qed.
Lemma Frobenius_cent1_ker : {in K^#, forall x, 'C_G[x] \subset K}.
Proof.
have [/eqP defG _ /normedTI_memJ_P[_ _ tiHG]] := and3P frobG.
move=> x /setD1P[ntx Kx]; have [_ /mulG_sub[sKG _] _ tiKH] := sdprodP defG.
have [/eqP <- _ _] := and3P Frobenius_partition; rewrite big_distrl /=.
apply/bigcupsP=> _ /setU1P[|/imsetP[y Ky]] ->; first exact: subsetIl.
apply: contraR ntx => /subsetPn[z]; rewrite inE mem_conjg => /andP[Hzy cxz] _.
rewrite -(conjg_eq1 x y^-1) -in_set1 -set1gE -tiKH inE andbC.
rewrite -(tiHG _ _ Hzy) ?(subsetP sKG) ?in_group // Ky andbT -conjJg.
by rewrite /(z ^ x) (cent1P cxz) mulKg.
Qed.
Lemma Frobenius_reg_ker : semiregular K H.
Proof.
move=> x /setD1P[ntx Hx].
apply/trivgP/subsetP=> y /setIP[Ky cxy]; apply: contraR ntx => nty.
have K1y: y \in K^# by rewrite inE nty.
have [/eqP/sdprod_context[_ sHG _ _ tiKH] _] := andP frobG.
suffices: x \in K :&: H by rewrite tiKH inE.
by rewrite inE (subsetP (Frobenius_cent1_ker K1y)) // inE cent1C (subsetP sHG).
Qed.
Lemma Frobenius_reg_compl : semiregular H K.
Proof. by apply: semiregular_sym; apply: Frobenius_reg_ker. Qed.
Lemma Frobenius_dvd_ker1 : #|H| %| #|K|.-1.
Proof.
apply: regular_norm_dvd_pred Frobenius_reg_ker.
by have[/sdprodP[]] := Frobenius_context.
Qed.
Lemma ltn_odd_Frobenius_ker : odd #|G| -> #|H|.*2 < #|K|.
Proof.
move/oddSg=> oddG.
have [/sdprodW/mulG_sub[sKG sHG] ntK _ _ _] := Frobenius_context.
by rewrite dvdn_double_ltn ?oddG ?cardG_gt1 ?Frobenius_dvd_ker1.
Qed.
Lemma Frobenius_index_dvd_ker1 : #|G : K| %| #|K|.-1.
Proof.
have[defG _ _ /andP[sKG _] _] := Frobenius_context.
by rewrite -divgS // -(sdprod_card defG) mulKn ?Frobenius_dvd_ker1.
Qed.
Lemma Frobenius_coprime : coprime #|K| #|H|.
Proof. by rewrite (coprime_dvdr Frobenius_dvd_ker1) ?coprimenP. Qed.
Lemma Frobenius_trivg_cent : 'C_K(H) = 1.
Proof.
by apply: (cent_semiregular Frobenius_reg_ker); case: Frobenius_context.
Qed.
Lemma Frobenius_index_coprime : coprime #|K| #|G : K|.
Proof. by rewrite (coprime_dvdr Frobenius_index_dvd_ker1) ?coprimenP. Qed.
Lemma Frobenius_ker_Hall : Hall G K.
Proof.
have [_ _ _ /andP[sKG _] _] := Frobenius_context.
by rewrite /Hall sKG Frobenius_index_coprime.
Qed.
Lemma Frobenius_compl_Hall : Hall G H.
Proof.
have [defG _ _ _ _] := Frobenius_context.
by rewrite -(sdprod_Hall defG) Frobenius_ker_Hall.
Qed.
End FrobeniusProperties.
Lemma normedTI_J x A G L : normedTI (A :^ x) (G :^ x) (L :^ x) = normedTI A G L.
Proof.
rewrite {1}/normedTI normJ -conjIg -(conj0g x) !(can_eq (conjsgK x)).
congr [&& _, _ == _ & _]; rewrite /cover (reindex_inj (@conjsg_inj _ x)).
by apply: eq_big => Hy; rewrite ?orbit_conjsg ?cardJg.
by rewrite bigcupJ cardJg (eq_bigl _ _ (orbit_conjsg _ _ _ _)).
Qed.
Lemma FrobeniusJcompl x G H :
[Frobenius G :^ x with complement H :^ x] = [Frobenius G with complement H].
Proof.
by congr (_ && _); rewrite ?(can_eq (conjsgK x)) // -conjD1g normedTI_J.
Qed.
Lemma FrobeniusJ x G K H :
[Frobenius G :^ x = K :^ x ><| H :^ x] = [Frobenius G = K ><| H].
Proof.
by congr (_ && _); rewrite ?FrobeniusJcompl // -sdprodJ (can_eq (conjsgK x)).
Qed.
Lemma FrobeniusJker x G K :
[Frobenius G :^ x with kernel K :^ x] = [Frobenius G with kernel K].
Proof.
apply/existsP/existsP=> [] [H]; last by exists (H :^ x)%G; rewrite FrobeniusJ.
by rewrite -(conjsgKV x H) FrobeniusJ; exists (H :^ x^-1)%G.
Qed.
Lemma FrobeniusJgroup x G : [Frobenius G :^ x] = [Frobenius G].
Proof.
apply/existsP/existsP=> [] [H].
by rewrite -(conjsgKV x H) FrobeniusJcompl; exists (H :^ x^-1)%G.
by exists (H :^ x)%G; rewrite FrobeniusJcompl.
Qed.
Lemma Frobenius_ker_dvd_ker1 G K :
[Frobenius G with kernel K] -> #|G : K| %| #|K|.-1.
Proof. by case/existsP=> H; apply: Frobenius_index_dvd_ker1. Qed.
Lemma Frobenius_ker_coprime G K :
[Frobenius G with kernel K] -> coprime #|K| #|G : K|.
Proof. by case/existsP=> H; apply: Frobenius_index_coprime. Qed.
Lemma Frobenius_semiregularP G K H :
K ><| H = G -> K :!=: 1 -> H :!=: 1 ->
reflect (semiregular K H) [Frobenius G = K ><| H].
Proof.
move=> defG ntK ntH.
apply: (iffP idP) => [|regG]; first exact: Frobenius_reg_ker.
have [nsKG sHG defKH nKH tiKH]:= sdprod_context defG; have [sKG _]:= andP nsKG.
apply/and3P; split; first by rewrite defG.
by rewrite eqEcard sHG -(sdprod_card defG) -ltnNge ltn_Pmull ?cardG_gt1.
apply/normedTI_memJ_P; rewrite setD_eq0 subG1 sHG -defKH -(normC nKH).
split=> // z _ /setD1P[ntz Hz] /mulsgP[y x Hy Kx ->]; rewrite groupMl // !inE.
rewrite conjg_eq1 ntz; apply/idP/idP=> [Hzxy | Hx]; last by rewrite !in_group.
apply: (subsetP (sub1G H)); have Hzy: z ^ y \in H by apply: groupJ.
rewrite -(regG (z ^ y)); last by apply/setD1P; rewrite conjg_eq1.
rewrite inE Kx cent1C (sameP cent1P commgP) -in_set1 -[[set 1]]tiKH inE /=.
rewrite andbC groupM ?groupV -?conjgM //= commgEr groupMr //.
by rewrite memJ_norm ?(subsetP nKH) ?groupV.
Qed.
Lemma prime_FrobeniusP G K H :
K :!=: 1 -> prime #|H| ->
reflect (K ><| H = G /\ 'C_K(H) = 1) [Frobenius G = K ><| H].
Proof.
move=> ntK H_pr; have ntH: H :!=: 1 by rewrite -cardG_gt1 prime_gt1.
have [defG | not_sdG] := eqVneq (K ><| H) G; last first.
by apply: (iffP andP) => [] [defG]; rewrite defG ?eqxx in not_sdG.
apply: (iffP (Frobenius_semiregularP defG ntK ntH)) => [regH | [_ regH x]].
split=> //; have [x defH] := cyclicP (prime_cyclic H_pr).
by rewrite defH cent_cycle regH // !inE defH cycle_id andbT -cycle_eq1 -defH.
case/setD1P=> nt_x Hx; apply/trivgP; rewrite -regH setIS //= -cent_cycle.
by rewrite centS // prime_meetG // (setIidPr _) ?cycle_eq1 ?cycle_subG.
Qed.
Lemma Frobenius_subl G K K1 H :
K1 :!=: 1 -> K1 \subset K -> H \subset 'N(K1) -> [Frobenius G = K ><| H] ->
[Frobenius K1 <*> H = K1 ><| H].
Proof.
move=> ntK1 sK1K nK1H frobG; have [_ _ ntH _ _] := Frobenius_context frobG.
apply/Frobenius_semiregularP=> //.
by rewrite sdprodEY ?coprime_TIg ?(coprimeSg sK1K) ?(Frobenius_coprime frobG).
by move=> x /(Frobenius_reg_ker frobG) cKx1; apply/trivgP; rewrite -cKx1 setSI.
Qed.
Lemma Frobenius_subr G K H H1 :
H1 :!=: 1 -> H1 \subset H -> [Frobenius G = K ><| H] ->
[Frobenius K <*> H1 = K ><| H1].
Proof.
move=> ntH1 sH1H frobG; have [defG ntK _ _ _] := Frobenius_context frobG.
apply/Frobenius_semiregularP=> //.
have [_ _ /(subset_trans sH1H) nH1K tiHK] := sdprodP defG.
by rewrite sdprodEY //; apply/trivgP; rewrite -tiHK setIS.
by apply: sub_in1 (Frobenius_reg_ker frobG); apply/subsetP/setSD.
Qed.
Lemma Frobenius_kerP G K :
reflect [/\ K :!=: 1, K \proper G, K <| G
& {in K^#, forall x, 'C_G[x] \subset K}]
[Frobenius G with kernel K].
Proof.
apply: (iffP existsP) => [[H frobG] | [ntK ltKG nsKG regK]].
have [/sdprod_context[nsKG _ _ _ _] ntK _ ltKG _] := Frobenius_context frobG.
by split=> //; apply: Frobenius_cent1_ker frobG.
have /andP[sKG nKG] := nsKG.
have hallK: Hall G K.
rewrite /Hall sKG //= coprime_sym coprime_pi' //.
apply: sub_pgroup (pgroup_pi K) => p; have [P sylP] := Sylow_exists p G.
have [[sPG pP p'GiP] sylPK] := (and3P sylP, Hall_setI_normal nsKG sylP).
rewrite -p_rank_gt0 -(rank_Sylow sylPK) rank_gt0 => ntPK.
rewrite inE /= -p'natEpi // (pnat_dvd _ p'GiP) ?indexgS //.
have /trivgPn[z]: P :&: K :&: 'Z(P) != 1.
by rewrite meet_center_nil ?(pgroup_nil pP) ?(normalGI sPG nsKG).
rewrite !inE -andbA -sub_cent1=> /and4P[_ Kz _ cPz] ntz.
by apply: subset_trans (regK z _); [apply/subsetIP | apply/setD1P].
have /splitsP[H /complP[tiKH defG]] := SchurZassenhaus_split hallK nsKG.
have [_ sHG] := mulG_sub defG; have nKH := subset_trans sHG nKG.
exists H; apply/Frobenius_semiregularP; rewrite ?sdprodE //.
by apply: contraNneq (proper_subn ltKG) => H1; rewrite -defG H1 mulg1.
apply: semiregular_sym => x Kx; apply/trivgP; rewrite -tiKH.
by rewrite subsetI subsetIl (subset_trans _ (regK x _)) ?setSI.
Qed.
Lemma set_Frobenius_compl G K H :
K ><| H = G -> [Frobenius G with kernel K] -> [Frobenius G = K ><| H].
Proof.
move=> defG /Frobenius_kerP[ntK ltKG _ regKG].
apply/Frobenius_semiregularP=> //.
by apply: contraTneq ltKG => H_1; rewrite -defG H_1 sdprodg1 properxx.
apply: semiregular_sym => y /regKG sCyK.
have [_ sHG _ _ tiKH] := sdprod_context defG.
by apply/trivgP; rewrite /= -(setIidPr sHG) setIAC -tiKH setSI.
Qed.
Lemma Frobenius_kerS G K G1 :
G1 \subset G -> K \proper G1 ->
[Frobenius G with kernel K] -> [Frobenius G1 with kernel K].
Proof.
move=> sG1G ltKG1 /Frobenius_kerP[ntK _ /andP[_ nKG] regKG].
apply/Frobenius_kerP; rewrite /normal proper_sub // (subset_trans sG1G) //.
by split=> // x /regKG; apply: subset_trans; rewrite setSI.
Qed.
Lemma Frobenius_action_kernel_def G H K sT S to :
K ><| H = G -> @Frobenius_action _ G H sT S to ->
K :=: 1 :|: [set x in G | 'Fix_(S | to)[x] == set0].
Proof.
move=> defG FrobG.
have partG: partition (gval K |: (H^# :^: K)) G.
apply: Frobenius_partition; apply/andP; rewrite defG; split=> //.
by apply/Frobenius_actionP; apply: hasFrobeniusAction FrobG.
have{FrobG} [ffulG transG regG ntH [u Su defH]]:= FrobG.
apply/setP=> x /[!inE]; have [-> | ntx] := eqVneq; first exact: group1.
rewrite /= -(cover_partition partG) /cover.
have neKHy y: gval K <> H^# :^ y.
by move/setP/(_ 1); rewrite group1 conjD1g setD11.
rewrite big_setU1 /= ?inE; last by apply/imsetP=> [[y _ /neKHy]].
have [nsKG sHG _ _ tiKH] := sdprod_context defG; have [sKG nKG]:= andP nsKG.
symmetry; case Kx: (x \in K) => /=.
apply/set0Pn=> [[v /setIP[Sv]]]; have [y Gy ->] := atransP2 transG Su Sv.
rewrite -sub1set -astabC sub1set astab1_act mem_conjg => Hxy.
case/negP: ntx; rewrite -in_set1 -(conjgKV y x) -mem_conjgV conjs1g -tiKH.
by rewrite defH setIA inE -mem_conjg (setIidPl sKG) (normsP nKG) ?Kx.
apply/andP=> [[/bigcupP[_ /imsetP[y Ky ->] Hyx] /set0Pn[]]]; exists (to u y).
rewrite inE (actsP (atrans_acts transG)) ?(subsetP sKG) // Su.
rewrite -sub1set -astabC sub1set astab1_act.
by rewrite conjD1g defH conjIg !inE in Hyx; case/and3P: Hyx.
Qed.
End FrobeniusBasics.
Arguments normedTI_P {gT A G L}.
Arguments normedTI_memJ_P {gT A G L}.
Arguments Frobenius_kerP {gT G K}.
Lemma Frobenius_coprime_quotient (gT : finGroupType) (G K H N : {group gT}) :
K ><| H = G -> N <| G -> coprime #|K| #|H| /\ H :!=: 1%g ->
N \proper K /\ {in H^#, forall x, 'C_K[x] \subset N} ->
[Frobenius G / N = (K / N) ><| (H / N)]%g.
Proof.
move=> defG nsNG [coKH ntH] [ltNK regH].
have [[sNK _] [_ /mulG_sub[sKG sHG] _ _]] := (andP ltNK, sdprodP defG).
have [_ nNG] := andP nsNG; have nNH := subset_trans sHG nNG.
apply/Frobenius_semiregularP; first exact: quotient_coprime_sdprod.
- by rewrite quotient_neq1 ?(normalS _ sKG).
- by rewrite -(isog_eq1 (quotient_isog _ _)) ?coprime_TIg ?(coprimeSg sNK).
move=> _ /(subsetP (quotientD1 _ _))/morphimP[x nNx H1x ->].
rewrite -cent_cycle -quotient_cycle //=.
rewrite -strongest_coprime_quotient_cent ?cycle_subG //.
- by rewrite cent_cycle quotientS1 ?regH.
- by rewrite subIset ?sNK.
- rewrite (coprimeSg (subsetIl N _)) ?(coprimeSg sNK) ?(coprimegS _ coKH) //.
by rewrite cycle_subG; case/setD1P: H1x.
by rewrite orbC abelian_sol ?cycle_abelian.
Qed.
Section InjmFrobenius.
Variables (gT rT : finGroupType) (D G : {group gT}) (f : {morphism D >-> rT}).
Implicit Types (H K : {group gT}) (sGD : G \subset D) (injf : 'injm f).
Lemma injm_Frobenius_compl H sGD injf :
[Frobenius G with complement H] -> [Frobenius f @* G with complement f @* H].
Proof.
case/andP=> neqGH /normedTI_P[nzH /subsetIP[sHG _] tiHG].
have sHD := subset_trans sHG sGD; have sH1D := subset_trans (subD1set H 1) sHD.
apply/andP; rewrite (can_in_eq (injmK injf)) //; split=> //.
apply/normedTI_P; rewrite normD1 -injmD1 // -!cards_eq0 card_injm // in nzH *.
rewrite subsetI normG morphimS //; split=> // _ /morphimP[x Dx Gx ->] ti'fHx.
rewrite mem_morphim ?tiHG //; apply: contra ti'fHx; rewrite -!setI_eq0 => tiHx.
by rewrite -morphimJ // -injmI ?conj_subG // (eqP tiHx) morphim0.
Qed.
Lemma injm_Frobenius H K sGD injf :
[Frobenius G = K ><| H] -> [Frobenius f @* G = f @* K ><| f @* H].
Proof.
case/andP=> /eqP defG frobG.
by apply/andP; rewrite (injm_sdprod _ injf defG) // eqxx injm_Frobenius_compl.
Qed.
Lemma injm_Frobenius_ker K sGD injf :
[Frobenius G with kernel K] -> [Frobenius f @* G with kernel f @* K].
Proof.
case/existsP=> H frobG; apply/existsP.
by exists (f @* H)%G; apply: injm_Frobenius.
Qed.
Lemma injm_Frobenius_group sGD injf : [Frobenius G] -> [Frobenius f @* G].
Proof.
case/existsP=> H frobG; apply/existsP; exists (f @* H)%G.
exact: injm_Frobenius_compl.
Qed.
End InjmFrobenius.
Theorem Frobenius_Ldiv (gT : finGroupType) (G : {group gT}) n :
n %| #|G| -> n %| #|'Ldiv_n(G)|.
Proof.
move=> nG; move: {2}_.+1 (ltnSn (#|G| %/ n)) => mq.
elim: mq => // mq IHm in gT G n nG *; case/dvdnP: nG => q oG.
have [q_gt0 n_gt0] : 0 < q /\ 0 < n by apply/andP; rewrite -muln_gt0 -oG.
rewrite ltnS oG mulnK // => leqm.
have:= q_gt0; rewrite leq_eqVlt => /predU1P[q1 | lt1q].
rewrite -(mul1n n) q1 -oG (setIidPl _) //.
by apply/subsetP=> x Gx; rewrite inE -order_dvdn order_dvdG.
pose p := pdiv q; have pr_p: prime p by apply: pdiv_prime.
have lt1p: 1 < p := prime_gt1 pr_p; have p_gt0 := ltnW lt1p.
have{leqm} lt_qp_mq: q %/ p < mq by apply: leq_trans leqm; rewrite ltn_Pdiv.
have: n %| #|'Ldiv_(p * n)(G)|.
have: p * n %| #|G| by rewrite oG dvdn_pmul2r ?pdiv_dvd.
move/IHm=> IH; apply: dvdn_trans (IH _); first exact: dvdn_mull.
by rewrite oG divnMr.
rewrite -(cardsID 'Ldiv_n()) dvdn_addl.
rewrite -setIA ['Ldiv_n(_)](setIidPr _) //.
by apply/subsetP=> x; rewrite !inE -!order_dvdn; apply: dvdn_mull.
rewrite -setIDA; set A := _ :\: _.
have pA x: x \in A -> #[x]`_p = (n`_p * p)%N.
rewrite !inE -!order_dvdn => /andP[xn xnp].
rewrite !p_part // -expnSr; congr (p ^ _)%N; apply/eqP.
rewrite eqn_leq -{1}addn1 -(pfactorK 1 pr_p) -lognM ?expn1 // mulnC.
rewrite dvdn_leq_log ?muln_gt0 ?p_gt0 //= ltnNge; apply: contra xn => xn.
move: xnp; rewrite -[#[x]](partnC p) //.
rewrite !Gauss_dvd ?coprime_partC //; case/andP=> _.
rewrite p_part ?pfactor_dvdn // xn Gauss_dvdr // coprime_sym.
exact: pnat_coprime (pnat_id _) (part_pnat _ _).
rewrite -(partnC p n_gt0) Gauss_dvd ?coprime_partC //; apply/andP; split.
rewrite -sum1_card (partition_big_imset (@cycle _)) /=.
apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->].
rewrite (eq_bigl (generator <[x]>)) => [|y].
rewrite sum1dep_card -totient_gen -[#[x]](partnC p) //.
rewrite totient_coprime ?coprime_partC // dvdn_mulr // .
by rewrite (pA x Ax) p_part // -expnSr totient_pfactor // dvdn_mull.
rewrite /generator eq_sym andbC; case xy: {+}(_ == _) => //.
rewrite !inE -!order_dvdn in Ax *.
by rewrite -cycle_subG /order -(eqP xy) cycle_subG Gx.
rewrite -sum1_card (partition_big_imset (fun x => x.`_p ^: G)) /=.
apply: dvdn_sum => _ /imsetP[x /setIP[Gx Ax] ->].
set y := x.`_p; have oy: #[y] = (n`_p * p)%N by rewrite order_constt pA.
rewrite (partition_big (fun x => x.`_p) [in y ^: G]) /= => [|z]; last first.
by case/andP=> _ /eqP <-; rewrite /= class_refl.
pose G' := ('C_G[y] / <[y]>)%G; pose n' := gcdn #|G'| n`_p^'.
have n'_gt0: 0 < n' by rewrite gcdn_gt0 cardG_gt0.
rewrite (eq_bigr (fun _ => #|'Ldiv_n'(G')|)) => [|_ /imsetP[a Ga ->]].
rewrite sum_nat_const -index_cent1 indexgI.
rewrite -(dvdn_pmul2l (cardG_gt0 'C_G[y])) mulnA LagrangeI.
have oCy: #|'C_G[y]| = (#[y] * #|G'|)%N.
rewrite card_quotient ?subcent1_cycle_norm // Lagrange //.
by rewrite subcent1_cycle_sub ?groupX.
rewrite oCy -mulnA -(muln_lcm_gcd #|G'|) -/n' mulnA dvdn_mul //.
rewrite muln_lcmr -oCy order_constt pA // mulnAC partnC // dvdn_lcm.
by rewrite cardSg ?subsetIl // mulnC oG dvdn_pmul2r ?pdiv_dvd.
apply: IHm; [exact: dvdn_gcdl | apply: leq_ltn_trans lt_qp_mq].
rewrite -(@divnMr n`_p^') // -muln_lcm_gcd mulnC divnMl //.
rewrite leq_divRL // divn_mulAC ?leq_divLR ?dvdn_mulr ?dvdn_lcmr //.
rewrite dvdn_leq ?muln_gt0 ?q_gt0 //= mulnC muln_lcmr dvdn_lcm.
rewrite -(@dvdn_pmul2l n`_p) // mulnA -oy -oCy mulnCA partnC // -oG.
by rewrite cardSg ?subsetIl // dvdn_mul ?pdiv_dvd.
pose h := [fun z => coset <[y]> (z ^ a^-1)].
pose h' := [fun Z : coset_of <[y]> => (y * (repr Z).`_p^') ^ a].
rewrite -sum1_card (reindex_onto h h') /= => [|Z]; last first.
rewrite conjgK coset_kerl ?cycle_id ?morph_constt ?repr_coset_norm //.
rewrite /= coset_reprK 2!inE -order_dvdn dvdn_gcd => /and3P[_ _ p'Z].
by apply: constt_p_elt (pnat_dvd p'Z _); apply: part_pnat.
apply: eq_bigl => z; apply/andP/andP=> [[]|[]].
rewrite inE -andbA => /and3P[Gz Az _] /eqP zp_ya.
have czy: z ^ a^-1 \in 'C[y].
rewrite -mem_conjg -normJ conjg_set1 -zp_ya.
by apply/cent1P; apply: commuteX.
have Nz: z ^ a^-1 \in 'N(<[y]>) by apply: subsetP czy; apply: norm_gen.
have G'z: h z \in G' by rewrite mem_morphim //= inE groupJ // groupV.
rewrite inE G'z inE -order_dvdn dvdn_gcd order_dvdG //=.
rewrite /order -morphim_cycle // -quotientE card_quotient ?cycle_subG //.
rewrite -(@dvdn_pmul2l #[y]) // Lagrange; last first.
by rewrite /= cycleJ cycle_subG mem_conjgV -zp_ya mem_cycle.
rewrite oy mulnAC partnC // [#|_|]orderJ; split.
by rewrite !inE -!order_dvdn mulnC in Az; case/andP: Az.
set Z := coset _ _; have NZ := repr_coset_norm Z; have:= coset_reprK Z.
case/kercoset_rcoset=> {NZ}// _ /cycleP[i ->] ->{Z}.
rewrite consttM; last exact/commute_sym/commuteX/cent1P.
rewrite (constt1P _) ?p_eltNK 1?p_eltX ?p_elt_constt // mul1g.
by rewrite conjMg consttJ conjgKV -zp_ya consttC.
rewrite 2!inE -order_dvdn; set Z := coset _ _ => /andP[Cz n'Z] /eqP def_z.
have Nz: z ^ a^-1 \in 'N(<[y]>).
rewrite -def_z conjgK groupMr; first by rewrite -(cycle_subG y) normG.
by rewrite groupX ?repr_coset_norm.
have{Cz} /setIP[Gz Cz]: z ^ a^-1 \in 'C_G[y].
case/morphimP: Cz => u Nu Cu /kercoset_rcoset[] // _ /cycleP[i ->] ->.
by rewrite groupMr // groupX // inE groupX //; apply/cent1P.
have{def_z} zp_ya: z.`_p = y ^ a.
rewrite -def_z consttJ consttM.
rewrite constt_p_elt ?p_elt_constt //.
by rewrite (constt1P _) ?p_eltNK ?p_elt_constt ?mulg1.
apply: commute_sym; apply/cent1P.
by rewrite -def_z conjgK groupMl // in Cz; apply/cent1P.
have ozp: #[z ^ a^-1]`_p = #[y] by rewrite -order_constt consttJ zp_ya conjgK.
split; rewrite zp_ya // -class_lcoset lcoset_id // eqxx andbT.
rewrite -(conjgKV a z) !inE groupJ //= -!order_dvdn orderJ; apply/andP; split.
apply: contra (partn_dvd p n_gt0) _.
by rewrite ozp -(muln1 n`_p) oy dvdn_pmul2l // dvdn1 neq_ltn lt1p orbT.
rewrite -(partnC p n_gt0) mulnCA mulnA -oy -(@partnC p #[_]) // ozp.
apply dvdn_mul => //; apply: dvdn_trans (dvdn_trans n'Z (dvdn_gcdr _ _)).
rewrite {2}/order -morphim_cycle // -quotientE card_quotient ?cycle_subG //.
rewrite -(@dvdn_pmul2l #|<[z ^ a^-1]> :&: <[y]>|) ?cardG_gt0 // LagrangeI.
rewrite -[#|<[_]>|](partnC p) ?order_gt0 // dvdn_pmul2r // ozp.
by rewrite cardSg ?subsetIr.
Qed.
|
Defs.lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Neil Strickland
-/
import Mathlib.Data.Int.Order.Basic
import Mathlib.Data.Nat.Basic
import Mathlib.Data.PNat.Notation
import Mathlib.Order.Basic
import Mathlib.Tactic.Coe
import Mathlib.Tactic.Lift
/-!
# The positive natural numbers
This file contains the definitions, and basic results.
Most algebraic facts are deferred to `Data.PNat.Basic`, as they need more imports.
-/
deriving instance LinearOrder for PNat
instance : One β+ :=
β¨β¨1, Nat.zero_lt_oneβ©β©
instance (n : β) [NeZero n] : OfNat β+ n :=
β¨β¨n, Nat.pos_of_ne_zero <| NeZero.ne nβ©β©
namespace PNat
-- Note: similar to Subtype.coe_mk
@[simp]
theorem mk_coe (n h) : (PNat.val (β¨n, hβ© : β+) : β) = n :=
rfl
/-- Predecessor of a `β+`, as a `β`. -/
def natPred (i : β+) : β :=
i - 1
@[simp]
theorem natPred_eq_pred {n : β} (h : 0 < n) : natPred (β¨n, hβ© : β+) = n.pred :=
rfl
end PNat
namespace Nat
/-- Convert a natural number to a positive natural number. The
positivity assumption is inferred by `dec_trivial`. -/
def toPNat (n : β) (h : 0 < n := by decide) : β+ :=
β¨n, hβ©
/-- Write a successor as an element of `β+`. -/
def succPNat (n : β) : β+ :=
β¨succ n, succ_pos nβ©
@[simp]
theorem succPNat_coe (n : β) : (succPNat n : β) = succ n :=
rfl
@[simp]
theorem natPred_succPNat (n : β) : n.succPNat.natPred = n :=
rfl
@[simp]
theorem _root_.PNat.succPNat_natPred (n : β+) : n.natPred.succPNat = n :=
Subtype.eq <| succ_pred_eq_of_pos n.2
/-- Convert a natural number to a `PNat`. `n+1` is mapped to itself,
and `0` becomes `1`. -/
def toPNat' (n : β) : β+ :=
succPNat (pred n)
@[simp]
theorem toPNat'_zero : Nat.toPNat' 0 = 1 := rfl
@[simp]
theorem toPNat'_coe : β n : β, (toPNat' n : β) = ite (0 < n) n 1
| 0 => rfl
| m + 1 => by
rw [if_pos (succ_pos m)]
rfl
end Nat
namespace PNat
open Nat
/-- We now define a long list of structures on β+ induced by
similar structures on β. Most of these behave in a completely
obvious way, but there are a few things to be said about
subtraction, division and powers.
-/
theorem mk_le_mk (n k : β) (hn : 0 < n) (hk : 0 < k) : (β¨n, hnβ© : β+) β€ β¨k, hkβ© β n β€ k := by simp
theorem mk_lt_mk (n k : β) (hn : 0 < n) (hk : 0 < k) : (β¨n, hnβ© : β+) < β¨k, hkβ© β n < k := by simp
@[simp, norm_cast]
theorem coe_le_coe (n k : β+) : (n : β) β€ k β n β€ k :=
Iff.rfl
@[simp, norm_cast]
theorem coe_lt_coe (n k : β+) : (n : β) < k β n < k :=
Iff.rfl
@[simp]
theorem pos (n : β+) : 0 < (n : β) :=
n.2
theorem eq {m n : β+} : (m : β) = n β m = n :=
Subtype.eq
theorem coe_injective : Function.Injective PNat.val :=
Subtype.coe_injective
@[simp]
theorem ne_zero (n : β+) : (n : β) β 0 :=
n.2.ne'
instance _root_.NeZero.pnat {a : β+} : NeZero (a : β) :=
β¨a.ne_zeroβ©
theorem toPNat'_coe {n : β} : 0 < n β (n.toPNat' : β) = n :=
succ_pred_eq_of_pos
@[simp]
theorem coe_toPNat' (n : β+) : (n : β).toPNat' = n :=
eq (toPNat'_coe n.pos)
@[simp]
theorem one_le (n : β+) : (1 : β+) β€ n :=
n.2
@[simp]
theorem not_lt_one (n : β+) : Β¬n < 1 :=
not_lt_of_ge n.one_le
instance : Inhabited β+ :=
β¨1β©
-- Some lemmas that rewrite `PNat.mk n h`, for `n` an explicit numeral, into explicit numerals.
@[simp]
theorem mk_one {h} : (β¨1, hβ© : β+) = (1 : β+) :=
rfl
@[norm_cast]
theorem one_coe : ((1 : β+) : β) = 1 :=
rfl
@[simp, norm_cast]
theorem coe_eq_one_iff {m : β+} : (m : β) = 1 β m = 1 :=
Subtype.coe_injective.eq_iff' one_coe
instance : WellFoundedRelation β+ :=
measure (fun (a : β+) => (a : β))
/-- Strong induction on `β+`. -/
def strongInductionOn {p : β+ β Sort*} (n : β+) : (β k, (β m, m < k β p m) β p k) β p n
| IH => IH _ fun a _ => strongInductionOn a IH
termination_by n.1
/-- We define `m % k` and `m / k` in the same way as for `β`
except that when `m = n * k` we take `m % k = k` and
`m / k = n - 1`. This ensures that `m % k` is always positive
and `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k`
in the case where `k` divides `m`.
-/
def modDivAux : β+ β β β β β β+ Γ β
| k, 0, q => β¨k, q.predβ©
| _, r + 1, q => β¨β¨r + 1, Nat.succ_pos rβ©, qβ©
/-- `mod_div m k = (m % k, m / k)`.
We define `m % k` and `m / k` in the same way as for `β`
except that when `m = n * k` we take `m % k = k` and
`m / k = n - 1`. This ensures that `m % k` is always positive
and `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k`
in the case where `k` divides `m`.
-/
def modDiv (m k : β+) : β+ Γ β :=
modDivAux k ((m : β) % (k : β)) ((m : β) / (k : β))
/-- We define `m % k` in the same way as for `β`
except that when `m = n * k` we take `m % k = k` This ensures that `m % k` is always positive.
-/
def mod (m k : β+) : β+ :=
(modDiv m k).1
/-- We define `m / k` in the same way as for `β` except that when `m = n * k` we take
`m / k = n - 1`. This ensures that `m = (m % k) + k * (m / k)` in all cases. Later we
define a function `div_exact` which gives the usual `m / k` in the case where `k` divides `m`.
-/
def div (m k : β+) : β :=
(modDiv m k).2
theorem mod_coe (m k : β+) :
(mod m k : β) = ite ((m : β) % (k : β) = 0) (k : β) ((m : β) % (k : β)) := by
dsimp [mod, modDiv]
cases (m : β) % (k : β) with
| zero =>
rw [if_pos rfl]
rfl
| succ n =>
rw [if_neg n.succ_ne_zero]
rfl
theorem div_coe (m k : β+) :
(div m k : β) = ite ((m : β) % (k : β) = 0) ((m : β) / (k : β)).pred ((m : β) / (k : β)) := by
dsimp [div, modDiv]
cases (m : β) % (k : β) with
| zero =>
rw [if_pos rfl]
rfl
| succ n =>
rw [if_neg n.succ_ne_zero]
rfl
/-- If `h : k | m`, then `k * (div_exact m k) = m`. Note that this is not equal to `m / k`. -/
def divExact (m k : β+) : β+ :=
β¨(div m k).succ, Nat.succ_pos _β©
end PNat
section CanLift
instance Nat.canLiftPNat : CanLift β β+ (β) (fun n => 0 < n) :=
β¨fun n hn => β¨Nat.toPNat' n, PNat.toPNat'_coe hnβ©β©
instance Int.canLiftPNat : CanLift β€ β+ (β) ((0 < Β·)) :=
β¨fun n hn =>
β¨Nat.toPNat' (Int.natAbs n), by
rw [Nat.toPNat'_coe, if_pos (Int.natAbs_pos.2 hn.ne'),
Int.natAbs_of_nonneg hn.le]β©β©
end CanLift
|
Nonempty.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.SmallObject.Iteration.Basic
import Mathlib.CategoryTheory.SmallObject.Iteration.ExtendToSucc
import Mathlib.CategoryTheory.SmallObject.Iteration.FunctorOfCocone
/-!
# Existence of the iteration of a successor structure
Given `Ξ¦ : SuccStruct C`, we show by transfinite induction
that for any element `j` in a well ordered set `J`,
the type `Ξ¦.Iteration j` is nonempty.
-/
universe u
namespace CategoryTheory
namespace SmallObject
namespace SuccStruct
open Category Limits
variable {C : Type*} [Category C] (Ξ¦ : SuccStruct C)
{J : Type u} [LinearOrder J] [OrderBot J] [SuccOrder J] [WellFoundedLT J]
[HasIterationOfShape J C]
namespace Iteration
variable (J) in
/-- The obvious term in `Ξ¦.Iteration Ξ΅ β₯` that is given by `Ξ¦.Xβ`. -/
def mkOfBot : Ξ¦.Iteration (β₯ : J) where
F := (Functor.const _).obj Ξ¦.Xβ
obj_bot := rfl
arrowSucc_eq _ h := by simp at h
arrowMap_limit _ hβ hβ := (hβ.not_isMin (by simpa using hβ)).elim
variable {Ξ¦}
open Functor in
/-- When `j : J` is not maximal, this is the extension in `Ξ¦.Iteration (Order.succ j)`
of any `iter : Ξ¦.Iteration j`. -/
noncomputable def mkOfSucc {j : J} (hj : Β¬IsMax j) (iter : Ξ¦.Iteration j) :
Ξ¦.Iteration (Order.succ j) where
F := extendToSucc hj iter.F (Ξ¦.toSucc _)
obj_bot := by rw [extendToSucc_obj_eq _ _ _ _ bot_le, obj_bot]
arrowSucc_eq i hiβ := by
rw [Order.lt_succ_iff_of_not_isMax hj] at hiβ
obtain hiβ | rfl := hiβ.lt_or_eq
Β· rw [arrowSucc_def, arrowMap_extendToSucc _ _ _ _ _ _ (Order.succ_le_of_lt hiβ),
β arrowSucc_def _ _ hiβ, iter.arrowSucc_eq i hiβ,
extendToSucc_obj_eq hj iter.F (Ξ¦.toSucc _) i hiβ.le]
Β· rw [arrowSucc_extendToSucc, toSuccArrow,
extendToSucc_obj_eq hj iter.F (Ξ¦.toSucc _) i]
arrowMap_limit i hi hij k hk := by
have hij' := (Order.IsSuccLimit.le_succ_iff hi).1 hij
rw [arrowMap_extendToSucc _ _ _ _ _ _ hij', arrowMap_limit _ _ hi _ _ hk]
congr 1
apply Arrow.functor_ext
rintro β¨kβ, hββ© β¨kβ, hββ© f
dsimp
rw [β arrowMap, β arrowMap, arrowMap_extendToSucc]
rfl
namespace mkOfLimit
open Functor
variable {j : J} (hj : Order.IsSuccLimit j) (iter : β (i : J), i < j β Ξ¦.Iteration i)
/-- Assuming `j : J` is a limit element and that we have `β (i : J), i < j β Ξ¦.Iteration i`,
this is the inductive system `Set.Iio j β₯€ C` which sends `β¨i, _β©` to
`(iter i _).F.obj β¨i, _β©`. -/
@[simps]
noncomputable def inductiveSystem : Set.Iio j β₯€ C where
obj i := (iter i.1 i.2).F.obj β¨i.1, by simpβ©
map {iβ iβ} f := mapObj (iter iβ.1 iβ.2) (iter iβ.1 iβ.2) (leOfHom f)
(by simp) (by simp) (leOfHom f)
/-- The extension of `inductiveSystem iter` to a functor `Set.Iic j β₯€ C` which
sends the top element to the colimit of `inductiveSystem iter`. -/
noncomputable def functor : Set.Iic j β₯€ C :=
letI := hasColimitsOfShape_of_isSuccLimit C j hj
ofCocone (colimit.cocone (inductiveSystem iter))
lemma functor_obj (i : J) (hi : i < j) {k : J} (iter' : Ξ¦.Iteration k) (hk : i β€ k) :
(functor hj iter).obj β¨i, hi.leβ© = iter'.F.obj β¨i, hkβ© := by
dsimp only [functor]
rw [ofCocone_obj_eq _ _ hi]
apply congr_obj
lemma arrowMap_functor (iβ iβ : J) (hββ : iβ β€ iβ) (hβ : iβ < j) :
arrowMap (functor hj iter) iβ iβ hββ hβ.le =
Arrow.mk (mapObj (iter iβ (lt_of_le_of_lt hββ hβ)) (iter iβ hβ) hββ
(by simp) (by simp) hββ) :=
arrowMap_ofCocone _ _ _ _ hβ
lemma arrowMap_functor_to_top (i : J) (hi : i < j) :
letI := hasColimitsOfShape_of_isSuccLimit C j hj
arrowMap (functor hj iter) i j hi.le (by simp) =
Arrow.mk (colimit.ΞΉ (inductiveSystem iter) β¨i, hiβ©) :=
arrowMap_ofCocone_to_top _ _ _
end mkOfLimit
open mkOfLimit in
/-- When `j` is a limit element, this is the element in `Ξ¦.Iteration j`
that is constructed from elements in `Ξ¦.Iteration i` for all `i < j`. -/
noncomputable def mkOfLimit {j : J} (hj : Order.IsSuccLimit j)
(iter : β (i : J), i < j β Ξ¦.Iteration i) :
Ξ¦.Iteration j where
F := functor hj iter
obj_bot := functor_obj hj iter β₯ (Order.IsSuccLimit.bot_lt hj) (mkOfBot Ξ¦ J) (by rfl)
arrowSucc_eq i hi := by
rw [arrowSucc_def, arrowMap_functor _ _ _ _ (Order.le_succ i)
((Order.IsSuccLimit.succ_lt_iff hj).2 hi), arrow_mk_mapObj,
β arrowSucc_def _ _ ((Order.lt_succ_of_le_of_not_isMax (by rfl) (not_isMax_of_lt hi))),
arrowSucc_eq, functor_obj _ _ _ hi]
arrowMap_limit i hi hij k hk := by
obtain hij | rfl := hij.lt_or_eq
Β· rw [arrowMap_functor _ _ _ _ _ hij, arrow_mk_mapObj,
arrowMap_limit _ _ hi _ _ hk]
congr 1
apply Arrow.functor_ext
rintro β¨lβ, hlββ© β¨lβ, hlββ© f
dsimp
generalize_proofs
rw [β arrowMap, β arrowMap, arrowMap_functor hj iter lβ lβ _ (hlβ.trans hij),
arrow_mk_mapObj]
apply congr_arrowMap
Β· rw [arrowMap_functor_to_top _ _ _ hk, β arrowΞΉ_def _ hi]
congr 1
apply Arrow.functor_ext
rintro β¨lβ, hlββ© β¨lβ, hlββ© f
dsimp
generalize_proofs
rw [β arrowMap, arrow_mk_mapObj, arrowMap_functor _ _ _ _ _ hlβ, arrow_mk_mapObj]
variable (Ξ¦)
instance nonempty (j : J) : Nonempty (Ξ¦.Iteration j) := by
induction j using SuccOrder.limitRecOn with
| isMin i hi =>
obtain rfl : i = β₯ := by simpa using hi
exact β¨mkOfBot Ξ¦ Jβ©
| succ i hi hi' => exact β¨mkOfSucc hi hi'.someβ©
| isSuccLimit i hi hi' => exact β¨mkOfLimit hi (fun a ha β¦ (hi' a ha).some)β©
end Iteration
end SuccStruct
end SmallObject
end CategoryTheory
|
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.
|
CommandStart.lean
|
import Aesop.Frontend.Attribute
import Mathlib.Tactic.Linter.CommandStart
import Mathlib.Tactic.Lemma
set_option linter.style.commandStart true
/--
warning: missing space in the source
This part of the code
'example: True'
should be written as
'example : True'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example: True := trivial
-- Constructs that are ignored by the linter, and (former) false positives.
section noFalsePositives
-- Explicit name literals: used to error (and the suggested replacement is invalid syntax).
structure foo (name: Lean.Name) where
#guard_msgs in
def bar (_param : List (foo ``String)) := 1
-- This example would trigger the linter if we did not special case
-- `where` in `Mathlib.Linter.Style.CommandStart.getUnlintedRanges`.
/-- A -/
example := aux
where
/-- A -/
aux : Unit := ()
-- For structure fields, all field definitions are linted.
-- TODO: currently, only the first field is linted
/--
warning: extra space in the source
This part of the code
'field1 : Nat'
should be written as
'field1 : Nat'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
structure A where
field1 : Nat
field2 : Nat
-- TODO: this is not linted yet!
structure B where
field1 : Nat
field2 : Nat
-- TODO: this is not linted yet!
structure C where
field1 : Nat
field2 : Nat
-- Note that the linter does not attempt to recognise or respect manual alignment of fields:
-- this is often brittle and should usually be removed.
/--
warning: extra space in the source
This part of the code
'field1 : '
should be written as
'field1 : Nat'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
structure D where
field1 : Nat
field2 : Nat
-- This also applies to consecutive declarations.
/--
warning: declaration uses 'sorry'
---
warning: extra space in the source
This part of the code
'instance {R}'
should be written as
'instance {R} :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
instance {R} : Add R := sorry
/--
warning: declaration uses 'sorry'
---
warning: extra space in the source
This part of the code
'instance {R}'
should be written as
'instance {R} :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
instance {R} : Add R := sorry
-- Strings are ignored by the linter.
variable (a : String := " ")
-- The linter skips double-quoted names.
variable (d : Lean.Name := ``Nat) in open Nat
-- Code inside `run_cmd` is not checked at all.
run_cmd
for _ in [0] do
let _ β `(
end)
def Card : Type β Nat := fun _ => 0
/-- Symbols for use by all kinds of grammars. -/
inductive Symbol (T N : Type)
/-- Terminal symbols (of the same type as the language) -/
| terminal (t : T) : Symbol T N
/-- Nonterminal symbols (must not be present when the word being generated is finalized) -/
| nonterminal (n : N) : Symbol T N
deriving
DecidableEq, Repr
-- embedded comments do not cause problems!
#guard_msgs in
open Nat in -- hi
example : True := trivial
-- embedded comments do not cause problems!
#guard_msgs in
open Nat in
-- hi
example : True := trivial
-- embedded comments do not cause problems!
#guard_msgs in
open Nat in
-- hi
example : True := trivial
structure X where
/-- A doc -/
x : Nat
open Nat in /- hi -/
example : True := trivial
-- The notation `0::[]` disables the linter
variable (h : 0::[] = [])
/-- A doc string -/
-- comment
example : True := trivial
-- Test that `Prop` and `Type` that are not escaped with `Β«...Β»` do not cause problems.
def Prop.Hello := 0
def Type.Hello := 0
/--
warning: extra space in the source
This part of the code
'F : True'
should be written as
'F : True'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
lemma F : True := trivial
namespace List
variable {Ξ± Ξ² : Type} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop)
-- The two infix are needed. They "hide" a `quotPrecheck`
local infixl:50 " βΌ " => r
-- The two infix are needed. They "hide" a `quotPrecheck`
local infixl:50 " βΌ " => s
/--
warning: The `commandStart` linter had some parsing issues: feel free to silence it and report this error!
Note: This linter can be disabled with `set_option linter.style.commandStart.verbose false`
-/
#guard_msgs in
set_option linter.style.commandStart.verbose true in
example {a : Ξ±} (_ : a βΌ a) : 0 = 0 := rfl
end List
end noFalsePositives
-- Miscellaneous constructs: variable, include, omit statements; aesop rulesets
section misc
variable [h : Add Nat] [Add Nat]
/--
warning: extra space in the source
This part of the code
'variable [ h'
should be written as
'variable [h :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: extra space in the source
This part of the code
'[ h '
should be written as
'[h : Add'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: extra space in the source
This part of the code
'h : Add'
should be written as
'[h : Add'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: extra space in the source
This part of the code
'Nat ] ['
should be written as
'Nat] [Add'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: extra space in the source
This part of the code
'[ Add'
should be written as
'[Add Nat]'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
variable [ h : Add Nat ] [ Add Nat]
/--
warning: extra space in the source
This part of the code
'omit [h :'
should be written as
'omit [h :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: extra space in the source
This part of the code
'Nat] [Add'
should be written as
' [Add'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
omit [h : Add Nat] [Add Nat]
-- Include statements are not linted.
include h
/--
warning: extra space in the source
This part of the code
'@[aesop (rule_sets'
should be written as
'@[aesop (rule_sets'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
@[aesop (rule_sets := [builtin]) safe apply] example : True := trivial
end misc
/--
warning: 'section' starts on column 1, but all commands should start at the beginning of the line.
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
section
/--
warning: extra space in the source
This part of the code
'example : True'
should be written as
'example : True'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example : True := trivial
-- Additional spaces after the colon are not linted yet.
#guard_msgs in
example : True := trivial
/--
warning: extra space in the source
This part of the code
'example : True'
should be written as
'example : True'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example : True :=trivial
/--
warning: missing space in the source
This part of the code
'(a: Nat)'
should be written as
'(a : Nat)'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
variable (a: Nat)
/--
warning: missing space in the source
This part of the code
'(_a: Nat)'
should be written as
'(_a : Nat)'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example (_a: Nat) : True := trivial
/--
warning: missing space in the source
This part of the code
'{a: Nat}'
should be written as
'{a : Nat}'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {a: Nat} : a = a := rfl
/--
a
b
c
d -/
example (_a : Nat) (_b : Int) : True := trivial
/--
warning: missing space in the source
This part of the code
':Nat}'
should be written as
': Nat}'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {a :Nat} : a = a := rfl
/--
warning: extra space in the source
This part of the code
'example {a :Nat}'
should be written as
'example {a :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
---
warning: missing space in the source
This part of the code
':Nat}'
should be written as
': Nat}'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {a :Nat} : a = a := rfl
/--
warning: unused variable `b`
Note: This linter can be disabled with `set_option linter.unusedVariables false`
---
warning: missing space in the source
This part of the code
'Nat}{b :'
should be written as
'Nat} {b :'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {a : Nat}{b : Nat} : a = a := rfl
/--
warning: extra space in the source
This part of the code
'Nat} : a'
should be written as
'Nat} : a ='
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {a : Nat} : a = a := rfl
/--
warning: extra space in the source
This part of the code
'alpha ] {a'
should be written as
'alpha] {a'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
example {alpha} [Neg alpha ] {a : Nat} : a = a := rfl
/--
warning: extra space in the source
This part of the code
'example : True'
should be written as
'example : True'
Note: This linter can be disabled with `set_option linter.style.commandStart false`
-/
#guard_msgs in
/-- Check that doc/strings do not get removed as comments. -/
example : True := trivial
-- Unit tests for internal functions in the linter.
section internal
/--
info: #[srcNat: 12, srcPos: 12, fmtPos: 2, msg: extra space, length: 7
, srcNat: 4, srcPos: 4, fmtPos: 1, msg: extra space, length: 3
]
-/
#guard_msgs in
#eval
let s := "example f g"
let t := "example fg"
Mathlib.Linter.parallelScan s t
/--
info: #[srcNat: 19, srcPos: 19, fmtPos: 21, msg: extra space, length: 1
, srcNat: 16, srcPos: 16, fmtPos: 19, msg: extra space, length: 2
, srcNat: 7, srcPos: 7, fmtPos: 12, msg: missing space, length: 1
]
-/
#guard_msgs in
#eval
let s := "example : True :=trivial"
let t := "example : True :=
trivial"
Mathlib.Linter.parallelScan s t
/--
info: #[srcNat: 4, srcPos: 4, fmtPos: 5, msg: missing space, length: 1
, srcNat: 2, srcPos: 2, fmtPos: 1, msg: extra space, length: 1
]
-/
#guard_msgs in
#eval
let l := "hac d"
let m := "h acd"
Mathlib.Linter.parallelScan l m
-- Starting from `c` (due to the `"d ef gh".length` input), form a "window" of successive sizes
-- `1, 2,..., 6`. The output is trimmed and contains only full words, even partially overlapping
-- with the given lengths.
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 1 == "cd"
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 2 == "cd"
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 3 == "cd ef"
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 4 == "cd ef"
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 5 == "cd ef"
#guard Mathlib.Linter.Style.CommandStart.mkWindow "ab cd ef gh" "d ef gh".length 6 == "cd ef gh"
end internal
|
FreeGroupoid.lean
|
/-
Copyright (c) 2022 RΓ©mi Bottinelli. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©mi Bottinelli
-/
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PathCategory.Basic
/-!
# Free groupoid on a quiver
This file defines the free groupoid on a quiver, the lifting of a prefunctor to its unique
extension as a functor from the free groupoid, and proves uniqueness of this extension.
## Main results
Given the type `V` and a quiver instance on `V`:
- `FreeGroupoid V`: a type synonym for `V`.
- `FreeGroupoid.instGroupoid`: the `Groupoid` instance on `FreeGroupoid V`.
- `lift`: the lifting of a prefunctor from `V` to `V'` where `V'` is a groupoid, to a functor.
`FreeGroupoid V β₯€ V'`.
- `lift_spec` and `lift_unique`: the proofs that, respectively, `lift` indeed is a lifting
and is the unique one.
## Implementation notes
The free groupoid is first defined by symmetrifying the quiver, taking the induced path category
and finally quotienting by the reducibility relation.
-/
open Set Function
namespace CategoryTheory
namespace Groupoid
namespace Free
universe u v u' v' u'' v''
variable {V : Type u} [Quiver.{v + 1} V]
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev _root_.Quiver.Hom.toPosPath {X Y : V} (f : X βΆ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom X Y :=
f.toPos.toPath
/-- Shorthand for the "forward" arrow corresponding to `f` in `paths <| symmetrify V` -/
abbrev _root_.Quiver.Hom.toNegPath {X Y : V} (f : X βΆ Y) :
(CategoryTheory.Paths.categoryPaths <| Quiver.Symmetrify V).Hom Y X :=
f.toNeg.toPath
/-- The "reduction" relation -/
inductive redStep : HomRel (Paths (Quiver.Symmetrify V))
| step (X Z : Quiver.Symmetrify V) (f : X βΆ Z) :
redStep (π ((Paths.of (Quiver.Symmetrify V)).obj X)) (f.toPath β« (Quiver.reverse f).toPath)
/-- The underlying vertices of the free groupoid -/
def _root_.CategoryTheory.FreeGroupoid (V) [Q : Quiver V] :=
Quotient (@redStep V Q)
instance {V} [Quiver V] [Nonempty V] : Nonempty (FreeGroupoid V) := by
inhabit V; exact β¨β¨@default V _β©β©
theorem congr_reverse {X Y : Paths <| Quiver.Symmetrify V} (p q : X βΆ Y) :
Quotient.CompClosure redStep p q β Quotient.CompClosure redStep p.reverse q.reverse := by
rintro β¨XW, pp, qq, WY, _, Z, fβ©
have : Quotient.CompClosure redStep (WY.reverse β« π _ β« XW.reverse)
(WY.reverse β« (f.toPath β« (Quiver.reverse f).toPath) β« XW.reverse) := by
constructor
constructor
simpa only [CategoryStruct.comp, CategoryStruct.id, Quiver.Path.reverse, Quiver.Path.nil_comp,
Quiver.Path.reverse_comp, Quiver.reverse_reverse, Quiver.Path.reverse_toPath,
Quiver.Path.comp_assoc] using this
open Relation in
theorem congr_comp_reverse {X Y : Paths <| Quiver.Symmetrify V} (p : X βΆ Y) :
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p β« p.reverse) =
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (π X) := by
apply Quot.eqvGen_sound
induction p with
| nil => apply EqvGen.refl
| cons q f ih =>
simp only [Quiver.Path.reverse]
fapply EqvGen.trans
-- Porting note: `Quiver.Path.*` and `Quiver.Hom.*` notation not working
Β· exact q β« Quiver.Path.reverse q
Β· apply EqvGen.symm
apply EqvGen.rel
have : Quotient.CompClosure redStep (q β« π _ β« Quiver.Path.reverse q)
(q β« (Quiver.Hom.toPath f β« Quiver.Hom.toPath (Quiver.reverse f)) β«
Quiver.Path.reverse q) := by
apply Quotient.CompClosure.intro
apply redStep.step
simp only [Category.assoc, Category.id_comp] at this β’
-- Porting note: `simp` cannot see how `Quiver.Path.comp_assoc` is relevant, so change to
-- category notation
change Quotient.CompClosure redStep (q β« Quiver.Path.reverse q)
(Quiver.Path.cons q f β« (Quiver.Hom.toPath (Quiver.reverse f)) β« (Quiver.Path.reverse q))
simp only [β Category.assoc] at this β’
exact this
Β· exact ih
theorem congr_reverse_comp {X Y : Paths <| Quiver.Symmetrify V} (p : X βΆ Y) :
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (p.reverse β« p) =
Quot.mk (@Quotient.CompClosure _ _ redStep _ _) (π Y) := by
nth_rw 2 [β Quiver.Path.reverse_reverse p]
apply congr_comp_reverse
instance : Category (FreeGroupoid V) :=
Quotient.category redStep
/-- The inverse of an arrow in the free groupoid -/
def quotInv {X Y : FreeGroupoid V} (f : X βΆ Y) : Y βΆ X :=
Quot.liftOn f (fun pp => Quot.mk _ <| pp.reverse) fun pp qq con =>
Quot.sound <| congr_reverse pp qq con
instance _root_.CategoryTheory.FreeGroupoid.instGroupoid : Groupoid (FreeGroupoid V) where
inv := quotInv
inv_comp p := Quot.inductionOn p fun pp => congr_reverse_comp pp
comp_inv p := Quot.inductionOn p fun pp => congr_comp_reverse pp
/-- The inclusion of the quiver on `V` to the underlying quiver on `FreeGroupoid V` -/
def of (V) [Quiver V] : V β₯€q FreeGroupoid V where
obj X := β¨Xβ©
map f := Quot.mk _ f.toPosPath
theorem of_eq :
of V = (Quiver.Symmetrify.of βq (Paths.of (Quiver.Symmetrify V))).comp
(Quotient.functor <| @redStep V _).toPrefunctor := rfl
section UniversalProperty
variable {V' : Type u'} [Groupoid V']
/-- The lift of a prefunctor to a groupoid, to a functor from `FreeGroupoid V` -/
def lift (Ο : V β₯€q V') : FreeGroupoid V β₯€ V' :=
Quotient.lift _ (Paths.lift <| Quiver.Symmetrify.lift Ο) <| by
rintro _ _ _ _ β¨X, Y, fβ©
-- Porting note: `simp` does not work, so manually `rewrite`
erw [Paths.lift_nil, Paths.lift_cons, Quiver.Path.comp_nil, Paths.lift_toPath,
Quiver.Symmetrify.lift_reverse]
symm
apply Groupoid.comp_inv
theorem lift_spec (Ο : V β₯€q V') : of V βq (lift Ο).toPrefunctor = Ο := by
rw [of_eq, Prefunctor.comp_assoc, Prefunctor.comp_assoc, Functor.toPrefunctor_comp]
dsimp [lift]
rw [Quotient.lift_spec, Paths.lift_spec, Quiver.Symmetrify.lift_spec]
theorem lift_unique (Ο : V β₯€q V') (Ξ¦ : FreeGroupoid V β₯€ V') (hΞ¦ : of V βq Ξ¦.toPrefunctor = Ο) :
Ξ¦ = lift Ο := by
apply Quotient.lift_unique
apply Paths.lift_unique
fapply @Quiver.Symmetrify.lift_unique _ _ _ _ _ _ _ _ _
Β· rw [β Functor.toPrefunctor_comp]
exact hΦ
Β· rintro X Y f
simp only [β Functor.toPrefunctor_comp, Prefunctor.comp_map, Paths.of_map]
change Ξ¦.map (inv ((Quotient.functor redStep).toPrefunctor.map f.toPath)) =
inv (Ξ¦.map ((Quotient.functor redStep).toPrefunctor.map f.toPath))
have := Functor.map_inv Ξ¦ ((Quotient.functor redStep).toPrefunctor.map f.toPath)
convert this <;> simp only [inv_eq_inv]
end UniversalProperty
section Functoriality
variable {V' : Type u'} [Quiver.{v' + 1} V'] {V'' : Type u''} [Quiver.{v'' + 1} V'']
/-- The functor of free groupoid induced by a prefunctor of quivers -/
def _root_.CategoryTheory.freeGroupoidFunctor (Ο : V β₯€q V') : FreeGroupoid V β₯€ FreeGroupoid V' :=
lift (Ο βq of V')
theorem freeGroupoidFunctor_id :
freeGroupoidFunctor (Prefunctor.id V) = Functor.id (FreeGroupoid V) := by
dsimp only [freeGroupoidFunctor]; symm
apply lift_unique; rfl
theorem freeGroupoidFunctor_comp (Ο : V β₯€q V') (Ο' : V' β₯€q V'') :
freeGroupoidFunctor (Ο βq Ο') = freeGroupoidFunctor Ο β freeGroupoidFunctor Ο' := by
dsimp only [freeGroupoidFunctor]; symm
apply lift_unique; rfl
end Functoriality
end Free
end Groupoid
end CategoryTheory
|
UniversallyInjective.lean
|
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.PullbackCarrier
import Mathlib.Topology.LocalAtTarget
/-!
# Universally injective morphism
A morphism of schemes `f : X βΆ Y` is universally injective if `X Γ[Y] Y' βΆ Y'` is injective
for all base changes `Y' βΆ Y`. This is equivalent to the diagonal morphism being surjective
(`AlgebraicGeometry.UniversallyInjective.iff_diagonal`).
We show that being universally injective is local at the target, and is stable under
compositions and base changes.
## TODO
- https://stacks.math.columbia.edu/tag/01S4
Show that this is equivalent to radicial morphisms
(injective + purely inseparable residue field extensions)
-/
noncomputable section
open CategoryTheory CategoryTheory.Limits Opposite TopologicalSpace
universe v u
namespace AlgebraicGeometry
variable {X Y : Scheme.{u}} (f : X βΆ Y)
open CategoryTheory.MorphismProperty Function
/--
A morphism of schemes `f : X βΆ Y` is universally injective if the base change `X Γ[Y] Y' βΆ Y'`
along any morphism `Y' βΆ Y` is injective (on points).
-/
@[mk_iff]
class UniversallyInjective (f : X βΆ Y) : Prop where
universally_injective : universally (topologically (Injective Β·)) f
theorem Scheme.Hom.injective (f : X.Hom Y) [UniversallyInjective f] :
Function.Injective f.base :=
UniversallyInjective.universally_injective _ _ _ .of_id_snd
theorem universallyInjective_eq :
@UniversallyInjective = universally (topologically (Injective Β·)) := by
ext X Y f; rw [universallyInjective_iff]
theorem universallyInjective_eq_diagonal :
@UniversallyInjective = diagonal @Surjective := by
apply le_antisymm
Β· intro X Y f hf
refine β¨fun x β¦ β¨(pullback.fst f f).base x, hf.1 _ _ _ (IsPullback.of_hasPullback f f) ?_β©β©
rw [β Scheme.comp_base_apply, pullback.diagonal_fst]
rfl
Β· rw [β universally_eq_iff.mpr (inferInstanceAs (IsStableUnderBaseChange (diagonal @Surjective))),
universallyInjective_eq]
apply universally_mono
intro X Y f hf xβ xβ e
obtain β¨t, htβ, htββ© := Scheme.Pullback.exists_preimage_pullback _ _ e
obtain β¨t, rflβ© := hf.1 t
rw [β htβ, β htβ, β Scheme.comp_base_apply, β Scheme.comp_base_apply, pullback.diagonal_fst,
pullback.diagonal_snd]
theorem UniversallyInjective.iff_diagonal :
UniversallyInjective f β Surjective (pullback.diagonal f) := by
rw [universallyInjective_eq_diagonal]; rfl
instance (priority := 900) [Mono f] : UniversallyInjective f :=
have := (pullback.isIso_diagonal_iff f).mpr inferInstance
(UniversallyInjective.iff_diagonal f).mpr inferInstance
theorem UniversallyInjective.respectsIso : RespectsIso @UniversallyInjective :=
universallyInjective_eq_diagonal.symm βΈ inferInstance
instance UniversallyInjective.isStableUnderBaseChange :
IsStableUnderBaseChange @UniversallyInjective :=
universallyInjective_eq_diagonal.symm βΈ inferInstance
instance universallyInjective_isStableUnderComposition :
IsStableUnderComposition @UniversallyInjective :=
universallyInjective_eq βΈ inferInstance
instance : MorphismProperty.IsMultiplicative @UniversallyInjective where
id_mem _ := inferInstance
instance universallyInjective_isLocalAtTarget : IsLocalAtTarget @UniversallyInjective :=
universallyInjective_eq_diagonal.symm βΈ inferInstance
end AlgebraicGeometry
|
SpecificAsymptotics.lean
|
/-
Copyright (c) 2021 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent
import Mathlib.Analysis.SpecialFunctions.Pow.Continuity
/-!
# A collection of specific asymptotic results
This file contains specific lemmas about asymptotics which don't have their place in the general
theory developed in `Mathlib/Analysis/Asymptotics/Asymptotics.lean`.
-/
open Filter Asymptotics
open Topology
section NormedField
/-- If `f : π β E` is bounded in a punctured neighborhood of `a`, then `f(x) = o((x - a)β»ΒΉ)` as
`x β a`, `x β a`. -/
theorem Filter.IsBoundedUnder.isLittleO_sub_self_inv {π E : Type*} [NormedField π] [Norm E] {a : π}
{f : π β E} (h : IsBoundedUnder (Β· β€ Β·) (π[β ] a) (norm β f)) :
f =o[π[β ] a] fun x => (x - a)β»ΒΉ := by
refine (h.isBigO_const (one_ne_zero' β)).trans_isLittleO (isLittleO_const_left.2 <| Or.inr ?_)
simp only [Function.comp_def, norm_inv]
exact (tendsto_norm_sub_self_nhdsNE a).inv_tendsto_nhdsGT_zero
end NormedField
section LinearOrderedField
variable {π : Type*} [Field π] [LinearOrder π] [IsStrictOrderedRing π]
theorem pow_div_pow_eventuallyEq_atTop {p q : β} :
(fun x : π => x ^ p / x ^ q) =αΆ [atTop] fun x => x ^ ((p : β€) - q) := by
apply (eventually_gt_atTop (0 : π)).mono fun x hx => _
intro x hx
simp [zpow_subβ hx.ne']
theorem pow_div_pow_eventuallyEq_atBot {p q : β} :
(fun x : π => x ^ p / x ^ q) =αΆ [atBot] fun x => x ^ ((p : β€) - q) := by
apply (eventually_lt_atBot (0 : π)).mono fun x hx => _
intro x hx
simp [zpow_subβ hx.ne]
theorem tendsto_pow_div_pow_atTop_atTop {p q : β} (hpq : q < p) :
Tendsto (fun x : π => x ^ p / x ^ q) atTop atTop := by
rw [tendsto_congr' pow_div_pow_eventuallyEq_atTop]
apply tendsto_zpow_atTop_atTop
omega
theorem tendsto_pow_div_pow_atTop_zero [TopologicalSpace π] [OrderTopology π] {p q : β}
(hpq : p < q) : Tendsto (fun x : π => x ^ p / x ^ q) atTop (π 0) := by
rw [tendsto_congr' pow_div_pow_eventuallyEq_atTop]
apply tendsto_zpow_atTop_zero
omega
end LinearOrderedField
section NormedLinearOrderedField
variable {π : Type*} [NormedField π]
theorem Asymptotics.isLittleO_pow_pow_atTop_of_lt
[LinearOrder π] [IsStrictOrderedRing π] [OrderTopology π] {p q : β} (hpq : p < q) :
(fun x : π => x ^ p) =o[atTop] fun x => x ^ q := by
refine (isLittleO_iff_tendsto' ?_).mpr (tendsto_pow_div_pow_atTop_zero hpq)
exact (eventually_gt_atTop 0).mono fun x hx hxq => (pow_ne_zero q hx.ne' hxq).elim
theorem Asymptotics.IsBigO.trans_tendsto_norm_atTop {Ξ± : Type*} {u v : Ξ± β π} {l : Filter Ξ±}
(huv : u =O[l] v) (hu : Tendsto (fun x => βu xβ) l atTop) :
Tendsto (fun x => βv xβ) l atTop := by
rcases huv.exists_pos with β¨c, hc, hcuvβ©
rw [IsBigOWith] at hcuv
convert Tendsto.atTop_div_const hc (tendsto_atTop_mono' l hcuv hu)
rw [mul_div_cancel_leftβ _ hc.ne.symm]
end NormedLinearOrderedField
section Real
theorem Asymptotics.IsEquivalent.rpow {Ξ± : Type*} {u v : Ξ± β β} {l : Filter Ξ±}
(hv : 0 β€ v) (h : u ~[l] v) {r : β} :
u ^ r ~[l] v ^ r := by
obtain β¨Ο, hΟ, huΟvβ© := IsEquivalent.exists_eq_mul h
rw [isEquivalent_iff_exists_eq_mul]
have hΟr : Tendsto ((fun x β¦ x ^ r) β Ο) l (π 1) := by
rw [β Real.one_rpow r]
exact Tendsto.comp (Real.continuousAt_rpow_const _ _ (by left; norm_num)) hΟ
use (Β· ^ r) β Ο, hΟr
conv => enter [3]; change fun x β¦ Ο x ^ r * v x ^ r
filter_upwards [Tendsto.eventually_const_lt (zero_lt_one) hΟ, huΟv] with x hΟ_pos huv'
simp [β Real.mul_rpow (le_of_lt hΟ_pos) (hv x), huv']
open Finset
theorem Asymptotics.IsLittleO.sum_range {Ξ± : Type*} [NormedAddCommGroup Ξ±] {f : β β Ξ±} {g : β β β}
(h : f =o[atTop] g) (hg : 0 β€ g) (h'g : Tendsto (fun n => β i β range n, g i) atTop atTop) :
(fun n => β i β range n, f i) =o[atTop] fun n => β i β range n, g i := by
have A : β i, βg iβ = g i := fun i => Real.norm_of_nonneg (hg i)
have B : β n, ββ i β range n, g iβ = β i β range n, g i := fun n => by
rwa [Real.norm_eq_abs, abs_sum_of_nonneg']
apply isLittleO_iff.2 fun Ξ΅ Ξ΅pos => _
intro Ξ΅ Ξ΅pos
obtain β¨N, hNβ© : β N : β, β b : β, N β€ b β βf bβ β€ Ξ΅ / 2 * g b := by
simpa only [A, eventually_atTop] using isLittleO_iff.mp h (half_pos Ξ΅pos)
have : (fun _ : β => β i β range N, f i) =o[atTop] fun n : β => β i β range n, g i := by
apply isLittleO_const_left.2
exact Or.inr (h'g.congr fun n => (B n).symm)
filter_upwards [isLittleO_iff.1 this (half_pos Ξ΅pos), Ici_mem_atTop N] with n hn Nn
calc
ββ i β range n, f iβ = β(β i β range N, f i) + β i β Ico N n, f iβ := by
rw [sum_range_add_sum_Ico _ Nn]
_ β€ ββ i β range N, f iβ + ββ i β Ico N n, f iβ := norm_add_le _ _
_ β€ ββ i β range N, f iβ + β i β Ico N n, Ξ΅ / 2 * g i :=
(add_le_add le_rfl (norm_sum_le_of_le _ fun i hi => hN _ (mem_Ico.1 hi).1))
_ β€ ββ i β range N, f iβ + β i β range n, Ξ΅ / 2 * g i := by
gcongr
Β· exact fun i _ _ β¦ mul_nonneg (half_pos Ξ΅pos).le (hg i)
Β· rw [range_eq_Ico]
exact Ico_subset_Ico (zero_le _) le_rfl
_ β€ Ξ΅ / 2 * ββ i β range n, g iβ + Ξ΅ / 2 * β i β range n, g i := by rw [β mul_sum]; gcongr
_ = Ξ΅ * ββ i β range n, g iβ := by
simp only [B]
ring
theorem Asymptotics.isLittleO_sum_range_of_tendsto_zero {Ξ± : Type*} [NormedAddCommGroup Ξ±]
{f : β β Ξ±} (h : Tendsto f atTop (π 0)) :
(fun n => β i β range n, f i) =o[atTop] fun n => (n : β) := by
have := ((isLittleO_one_iff β).2 h).sum_range fun i => zero_le_one
simp only [sum_const, card_range, Nat.smul_one_eq_cast] at this
exact this tendsto_natCast_atTop_atTop
/-- The Cesaro average of a converging sequence converges to the same limit. -/
theorem Filter.Tendsto.cesaro_smul {E : Type*} [NormedAddCommGroup E] [NormedSpace β E] {u : β β E}
{l : E} (h : Tendsto u atTop (π l)) :
Tendsto (fun n : β => (nβ»ΒΉ : β) β’ β i β range n, u i) atTop (π l) := by
rw [β tendsto_sub_nhds_zero_iff, β isLittleO_one_iff β]
have := Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 h)
apply ((isBigO_refl (fun n : β => (n : β)β»ΒΉ) atTop).smul_isLittleO this).congr' _ _
Β· filter_upwards [Ici_mem_atTop 1] with n npos
have nposβ : (0 : β) < n := Nat.cast_pos.2 npos
simp only [smul_sub, sum_sub_distrib, sum_const, card_range, sub_right_inj]
rw [β Nat.cast_smul_eq_nsmul β, smul_smul, inv_mul_cancelβ nposβ.ne', one_smul]
Β· filter_upwards [Ici_mem_atTop 1] with n npos
have nposβ : (0 : β) < n := Nat.cast_pos.2 npos
rw [Algebra.id.smul_eq_mul, inv_mul_cancelβ nposβ.ne']
/-- The Cesaro average of a converging sequence converges to the same limit. -/
theorem Filter.Tendsto.cesaro {u : β β β} {l : β} (h : Tendsto u atTop (π l)) :
Tendsto (fun n : β => (nβ»ΒΉ : β) * β i β range n, u i) atTop (π l) :=
h.cesaro_smul
end Real
section NormedLinearOrderedField
variable {R : Type*} [NormedField R] [LinearOrder R] [IsStrictOrderedRing R]
[OrderTopology R] [FloorRing R]
theorem Asymptotics.isEquivalent_nat_floor :
(fun (x : R) β¦ ββxββ) ~[atTop] (fun x β¦ x) := by
refine isEquivalent_of_tendsto_one ?_ tendsto_nat_floor_div_atTop
filter_upwards with x hx using by rw [hx, Nat.floor_zero, Nat.cast_eq_zero]
theorem Asymptotics.isEquivalent_nat_ceil :
(fun (x : R) β¦ ββxββ) ~[atTop] (fun x β¦ x) := by
refine isEquivalent_of_tendsto_one ?_ tendsto_nat_ceil_div_atTop
filter_upwards with x hx using by rw [hx, Nat.ceil_zero, Nat.cast_eq_zero]
end NormedLinearOrderedField
|
Mem.lean
|
/-
Copyright (c) 2022 Devon Tuma. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
import Mathlib.Data.Vector.Basic
/-!
# Theorems about membership of elements in vectors
This file contains theorems for membership in a `v.toList` for a vector `v`.
Having the length available in the type allows some of the lemmas to be
simpler and more general than the original version for lists.
In particular we can avoid some assumptions about types being `Inhabited`,
and make more general statements about `head` and `tail`.
-/
namespace List
namespace Vector
variable {Ξ± Ξ² : Type*} {n : β} (a a' : Ξ±)
@[simp]
theorem get_mem (i : Fin n) (v : Vector Ξ± n) : v.get i β v.toList := List.get_mem _ _
theorem mem_iff_get (v : Vector Ξ± n) : a β v.toList β β i, v.get i = a := by
simp only [List.mem_iff_get, Fin.exists_iff, Vector.get_eq_get_toList]
exact
β¨fun β¨i, hi, hβ© => β¨i, by rwa [toList_length] at hi, hβ©, fun β¨i, hi, hβ© =>
β¨i, by rwa [toList_length], hβ©β©
theorem notMem_nil : a β (Vector.nil : Vector Ξ± 0).toList := by
unfold Vector.nil
simp
@[deprecated (since := "2025-05-23")] alias not_mem_nil := notMem_nil
theorem notMem_zero (v : Vector Ξ± 0) : a β v.toList :=
(Vector.eq_nil v).symm βΈ notMem_nil a
@[deprecated (since := "2025-05-23")] alias not_mem_zero := notMem_zero
theorem mem_cons_iff (v : Vector Ξ± n) : a' β (a ::α΅₯ v).toList β a' = a β¨ a' β v.toList := by
rw [Vector.toList_cons, List.mem_cons]
theorem mem_succ_iff (v : Vector Ξ± (n + 1)) : a β v.toList β a = v.head β¨ a β v.tail.toList := by
obtain β¨a', v', hβ© := exists_eq_cons v
simp_rw [h, Vector.mem_cons_iff, Vector.head_cons, Vector.tail_cons]
theorem mem_cons_self (v : Vector Ξ± n) : a β (a ::α΅₯ v).toList :=
(Vector.mem_iff_get a (a ::α΅₯ v)).2 β¨0, Vector.get_cons_zero a vβ©
@[simp]
theorem head_mem (v : Vector Ξ± (n + 1)) : v.head β v.toList :=
(Vector.mem_iff_get v.head v).2 β¨0, Vector.get_zero vβ©
theorem mem_cons_of_mem (v : Vector Ξ± n) (ha' : a' β v.toList) : a' β (a ::α΅₯ v).toList :=
(Vector.mem_cons_iff a a' v).2 (Or.inr ha')
theorem mem_of_mem_tail (v : Vector Ξ± n) (ha : a β v.tail.toList) : a β v.toList := by
induction n with
| zero => exact False.elim (Vector.notMem_zero a v.tail ha)
| succ n _ => exact (mem_succ_iff a v).2 (Or.inr ha)
theorem mem_map_iff (b : Ξ²) (v : Vector Ξ± n) (f : Ξ± β Ξ²) :
b β (v.map f).toList β β a : Ξ±, a β v.toList β§ f a = b := by
rw [Vector.toList_map, List.mem_map]
theorem notMem_map_zero (b : Ξ²) (v : Vector Ξ± 0) (f : Ξ± β Ξ²) : b β (v.map f).toList := by
simpa only [Vector.eq_nil v, Vector.map_nil, Vector.toList_nil] using List.not_mem_nil
@[deprecated (since := "2025-05-23")] alias not_mem_map_zero := notMem_map_zero
theorem mem_map_succ_iff (b : Ξ²) (v : Vector Ξ± (n + 1)) (f : Ξ± β Ξ²) :
b β (v.map f).toList β f v.head = b β¨ β a : Ξ±, a β v.tail.toList β§ f a = b := by
rw [mem_succ_iff, head_map, tail_map, mem_map_iff, @eq_comm _ b]
end Vector
end List
|
Exact.lean
|
/-
Copyright (c) 2023 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.ShortComplex.PreservesHomology
import Mathlib.Algebra.Homology.ShortComplex.Abelian
import Mathlib.Algebra.Homology.ShortComplex.QuasiIso
import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor
import Mathlib.CategoryTheory.Preadditive.Injective.Basic
/-!
# Exact short complexes
When `S : ShortComplex C`, this file defines a structure
`S.Exact` which expresses the exactness of `S`, i.e. there
exists a homology data `h : S.HomologyData` such that
`h.left.H` is zero. When `[S.HasHomology]`, it is equivalent
to the assertion `IsZero S.homology`.
Almost by construction, this notion of exactness is self dual,
see `Exact.op` and `Exact.unop`.
-/
namespace CategoryTheory
open Category Limits ZeroObject Preadditive
variable {C D : Type*} [Category C] [Category D]
namespace ShortComplex
section
variable
[HasZeroMorphisms C] [HasZeroMorphisms D] (S : ShortComplex C) {Sβ Sβ : ShortComplex C}
/-- The assertion that the short complex `S : ShortComplex C` is exact. -/
structure Exact : Prop where
/-- the condition that there exists an homology data whose `left.H` field is zero -/
condition : β (h : S.HomologyData), IsZero h.left.H
variable {S}
lemma Exact.hasHomology (h : S.Exact) : S.HasHomology :=
HasHomology.mk' h.condition.choose
lemma Exact.hasZeroObject (h : S.Exact) : HasZeroObject C :=
β¨h.condition.choose.left.H, h.condition.choose_specβ©
variable (S)
lemma exact_iff_isZero_homology [S.HasHomology] :
S.Exact β IsZero S.homology := by
constructor
Β· rintro β¨β¨h', zβ©β©
exact IsZero.of_iso z h'.left.homologyIso
Β· intro h
exact β¨β¨_, hβ©β©
variable {S}
lemma LeftHomologyData.exact_iff [S.HasHomology]
(h : S.LeftHomologyData) :
S.Exact β IsZero h.H := by
rw [S.exact_iff_isZero_homology]
exact Iso.isZero_iff h.homologyIso
lemma RightHomologyData.exact_iff [S.HasHomology]
(h : S.RightHomologyData) :
S.Exact β IsZero h.H := by
rw [S.exact_iff_isZero_homology]
exact Iso.isZero_iff h.homologyIso
variable (S)
lemma exact_iff_isZero_leftHomology [S.HasHomology] :
S.Exact β IsZero S.leftHomology :=
LeftHomologyData.exact_iff _
lemma exact_iff_isZero_rightHomology [S.HasHomology] :
S.Exact β IsZero S.rightHomology :=
RightHomologyData.exact_iff _
variable {S}
lemma HomologyData.exact_iff (h : S.HomologyData) :
S.Exact β IsZero h.left.H := by
haveI := HasHomology.mk' h
exact LeftHomologyData.exact_iff h.left
lemma HomologyData.exact_iff' (h : S.HomologyData) :
S.Exact β IsZero h.right.H := by
haveI := HasHomology.mk' h
exact RightHomologyData.exact_iff h.right
variable (S)
lemma exact_iff_homology_iso_zero [S.HasHomology] [HasZeroObject C] :
S.Exact β Nonempty (S.homology β
0) := by
rw [exact_iff_isZero_homology]
constructor
Β· intro h
exact β¨h.isoZeroβ©
Β· rintro β¨eβ©
exact IsZero.of_iso (isZero_zero C) e
lemma exact_of_iso (e : Sβ β
Sβ) (h : Sβ.Exact) : Sβ.Exact := by
obtain β¨β¨h, zβ©β© := h
exact β¨β¨HomologyData.ofIso e h, zβ©β©
lemma exact_iff_of_iso (e : Sβ β
Sβ) : Sβ.Exact β Sβ.Exact :=
β¨exact_of_iso e, exact_of_iso e.symmβ©
lemma exact_and_mono_f_iff_of_iso (e : Sβ β
Sβ) :
Sβ.Exact β§ Mono Sβ.f β Sβ.Exact β§ Mono Sβ.f := by
have : Mono Sβ.f β Mono Sβ.f :=
(MorphismProperty.monomorphisms C).arrow_mk_iso_iff
(Arrow.isoMk (ShortComplex.Οβ.mapIso e) (ShortComplex.Οβ.mapIso e) e.hom.commββ)
rw [exact_iff_of_iso e, this]
lemma exact_and_epi_g_iff_of_iso (e : Sβ β
Sβ) :
Sβ.Exact β§ Epi Sβ.g β Sβ.Exact β§ Epi Sβ.g := by
have : Epi Sβ.g β Epi Sβ.g :=
(MorphismProperty.epimorphisms C).arrow_mk_iso_iff
(Arrow.isoMk (ShortComplex.Οβ.mapIso e) (ShortComplex.Οβ.mapIso e) e.hom.commββ)
rw [exact_iff_of_iso e, this]
lemma exact_of_isZero_Xβ (h : IsZero S.Xβ) : S.Exact := by
rw [(HomologyData.ofZeros S (IsZero.eq_of_tgt h _ _) (IsZero.eq_of_src h _ _)).exact_iff]
exact h
lemma exact_iff_of_epi_of_isIso_of_mono (Ο : Sβ βΆ Sβ) [Epi Ο.Οβ] [IsIso Ο.Οβ] [Mono Ο.Οβ] :
Sβ.Exact β Sβ.Exact := by
constructor
Β· rintro β¨hβ, zββ©
exact β¨HomologyData.ofEpiOfIsIsoOfMono Ο hβ, zββ©
Β· rintro β¨hβ, zββ©
exact β¨HomologyData.ofEpiOfIsIsoOfMono' Ο hβ, zββ©
variable {S}
lemma HomologyData.exact_iff_i_p_zero (h : S.HomologyData) :
S.Exact β h.left.i β« h.right.p = 0 := by
haveI := HasHomology.mk' h
rw [h.left.exact_iff, β h.comm]
constructor
Β· intro z
rw [IsZero.eq_of_src z h.iso.hom 0, zero_comp, comp_zero]
Β· intro eq
simp only [IsZero.iff_id_eq_zero, β cancel_mono h.iso.hom, id_comp, β cancel_mono h.right.ΞΉ,
β cancel_epi h.left.Ο, eq, zero_comp, comp_zero]
variable (S)
lemma exact_iff_i_p_zero [S.HasHomology] (hβ : S.LeftHomologyData)
(hβ : S.RightHomologyData) :
S.Exact β hβ.i β« hβ.p = 0 :=
(HomologyData.ofIsIsoLeftRightHomologyComparison' hβ hβ).exact_iff_i_p_zero
lemma exact_iff_iCycles_pOpcycles_zero [S.HasHomology] :
S.Exact β S.iCycles β« S.pOpcycles = 0 :=
S.exact_iff_i_p_zero _ _
lemma exact_iff_kernel_ΞΉ_comp_cokernel_Ο_zero [S.HasHomology]
[HasKernel S.g] [HasCokernel S.f] :
S.Exact β kernel.ΞΉ S.g β« cokernel.Ο S.f = 0 := by
haveI := HasLeftHomology.hasCokernel S
haveI := HasRightHomology.hasKernel S
exact S.exact_iff_i_p_zero (LeftHomologyData.ofHasKernelOfHasCokernel S)
(RightHomologyData.ofHasCokernelOfHasKernel S)
variable {S}
lemma Exact.op (h : S.Exact) : S.op.Exact := by
obtain β¨h, zβ© := h
exact β¨β¨h.op, (IsZero.of_iso z h.iso.symm).opβ©β©
lemma Exact.unop {S : ShortComplex Cα΅α΅} (h : S.Exact) : S.unop.Exact := by
obtain β¨h, zβ© := h
exact β¨β¨h.unop, (IsZero.of_iso z h.iso.symm).unopβ©β©
variable (S)
@[simp]
lemma exact_op_iff : S.op.Exact β S.Exact :=
β¨Exact.unop, Exact.opβ©
@[simp]
lemma exact_unop_iff (S : ShortComplex Cα΅α΅) : S.unop.Exact β S.Exact :=
S.unop.exact_op_iff.symm
variable {S}
lemma LeftHomologyData.exact_map_iff (h : S.LeftHomologyData) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] :
(S.map F).Exact β IsZero (F.obj h.H) :=
(h.map F).exact_iff
lemma RightHomologyData.exact_map_iff (h : S.RightHomologyData) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [h.IsPreservedBy F] [(S.map F).HasHomology] :
(S.map F).Exact β IsZero (F.obj h.H) :=
(h.map F).exact_iff
lemma Exact.map_of_preservesLeftHomologyOf (h : S.Exact) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S]
[(S.map F).HasHomology] : (S.map F).Exact := by
have := h.hasHomology
rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h
rw [S.leftHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero,
β F.map_id, h, F.map_zero]
lemma Exact.map_of_preservesRightHomologyOf (h : S.Exact) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [F.PreservesRightHomologyOf S]
[(S.map F).HasHomology] : (S.map F).Exact := by
have : S.HasHomology := h.hasHomology
rw [S.rightHomologyData.exact_iff, IsZero.iff_id_eq_zero] at h
rw [S.rightHomologyData.exact_map_iff F, IsZero.iff_id_eq_zero,
β F.map_id, h, F.map_zero]
lemma Exact.map (h : S.Exact) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S]
[F.PreservesRightHomologyOf S] : (S.map F).Exact := by
have := h.hasHomology
exact h.map_of_preservesLeftHomologyOf F
variable (S)
lemma exact_map_iff_of_faithful [S.HasHomology]
(F : C β₯€ D) [F.PreservesZeroMorphisms] [F.PreservesLeftHomologyOf S]
[F.PreservesRightHomologyOf S] [F.Faithful] :
(S.map F).Exact β S.Exact := by
constructor
Β· intro h
rw [S.leftHomologyData.exact_iff, IsZero.iff_id_eq_zero]
rw [(S.leftHomologyData.map F).exact_iff, IsZero.iff_id_eq_zero,
LeftHomologyData.map_H] at h
apply F.map_injective
rw [F.map_id, F.map_zero, h]
Β· intro h
exact h.map F
variable {S}
@[reassoc]
lemma Exact.comp_eq_zero (h : S.Exact) {X Y : C} {a : X βΆ S.Xβ} (ha : a β« S.g = 0)
{b : S.Xβ βΆ Y} (hb : S.f β« b = 0) : a β« b = 0 := by
have := h.hasHomology
have eq := h
rw [exact_iff_iCycles_pOpcycles_zero] at eq
rw [β S.liftCycles_i a ha, β S.p_descOpcycles b hb, assoc, reassoc_of% eq,
zero_comp, comp_zero]
lemma Exact.isZero_of_both_zeros (ex : S.Exact) (hf : S.f = 0) (hg : S.g = 0) :
IsZero S.Xβ :=
(ShortComplex.HomologyData.ofZeros S hf hg).exact_iff.1 ex
end
section Preadditive
variable [Preadditive C] [Preadditive D] (S : ShortComplex C)
lemma exact_iff_mono [HasZeroObject C] (hf : S.f = 0) :
S.Exact β Mono S.g := by
constructor
Β· intro h
have := h.hasHomology
simp only [exact_iff_isZero_homology] at h
have := S.isIso_pOpcycles hf
have := mono_of_isZero_kernel' _ S.homologyIsKernel h
rw [β S.p_fromOpcycles]
apply mono_comp
Β· intro
rw [(HomologyData.ofIsLimitKernelFork S hf _
(KernelFork.IsLimit.ofMonoOfIsZero (KernelFork.ofΞΉ (0 : 0 βΆ S.Xβ) zero_comp)
inferInstance (isZero_zero C))).exact_iff]
exact isZero_zero C
lemma exact_iff_epi [HasZeroObject C] (hg : S.g = 0) :
S.Exact β Epi S.f := by
constructor
Β· intro h
have := h.hasHomology
simp only [exact_iff_isZero_homology] at h
haveI := S.isIso_iCycles hg
haveI : Epi S.toCycles := epi_of_isZero_cokernel' _ S.homologyIsCokernel h
rw [β S.toCycles_i]
apply epi_comp
Β· intro
rw [(HomologyData.ofIsColimitCokernelCofork S hg _
(CokernelCofork.IsColimit.ofEpiOfIsZero (CokernelCofork.ofΟ (0 : S.Xβ βΆ 0) comp_zero)
inferInstance (isZero_zero C))).exact_iff]
exact isZero_zero C
variable {S}
lemma Exact.epi_f' (hS : S.Exact) (h : LeftHomologyData S) : Epi h.f' :=
epi_of_isZero_cokernel' _ h.hΟ (by
haveI := hS.hasHomology
dsimp
simpa only [β h.exact_iff] using hS)
lemma Exact.mono_g' (hS : S.Exact) (h : RightHomologyData S) : Mono h.g' :=
mono_of_isZero_kernel' _ h.hΞΉ (by
haveI := hS.hasHomology
dsimp
simpa only [β h.exact_iff] using hS)
lemma Exact.epi_toCycles (hS : S.Exact) [S.HasLeftHomology] : Epi S.toCycles :=
hS.epi_f' _
lemma Exact.mono_fromOpcycles (hS : S.Exact) [S.HasRightHomology] : Mono S.fromOpcycles :=
hS.mono_g' _
lemma LeftHomologyData.exact_iff_epi_f' [S.HasHomology] (h : LeftHomologyData S) :
S.Exact β Epi h.f' := by
constructor
Β· intro hS
exact hS.epi_f' h
Β· intro
simp only [h.exact_iff, IsZero.iff_id_eq_zero, β cancel_epi h.Ο, β cancel_epi h.f',
comp_id, h.f'_Ο, comp_zero]
lemma RightHomologyData.exact_iff_mono_g' [S.HasHomology] (h : RightHomologyData S) :
S.Exact β Mono h.g' := by
constructor
Β· intro hS
exact hS.mono_g' h
Β· intro
simp only [h.exact_iff, IsZero.iff_id_eq_zero, β cancel_mono h.ΞΉ, β cancel_mono h.g',
id_comp, h.ΞΉ_g', zero_comp]
/-- Given an exact short complex `S` and a limit kernel fork `kf` for `S.g`, this is the
left homology data for `S` with `K := kf.pt` and `H := 0`. -/
@[simps]
noncomputable def Exact.leftHomologyDataOfIsLimitKernelFork
(hS : S.Exact) [HasZeroObject C] (kf : KernelFork S.g) (hkf : IsLimit kf) :
S.LeftHomologyData where
K := kf.pt
H := 0
i := kf.ΞΉ
Ο := 0
wi := kf.condition
hi := IsLimit.ofIsoLimit hkf (Fork.ext (Iso.refl _) (by simp))
wΟ := comp_zero
hΟ := CokernelCofork.IsColimit.ofEpiOfIsZero _ (by
have := hS.hasHomology
refine ((MorphismProperty.epimorphisms C).arrow_mk_iso_iff ?_).1
hS.epi_toCycles
refine Arrow.isoMk (Iso.refl _)
(IsLimit.conePointUniqueUpToIso S.cyclesIsKernel hkf) ?_
apply Fork.IsLimit.hom_ext hkf
simp [IsLimit.conePointUniqueUpToIso]) (isZero_zero C)
/-- Given an exact short complex `S` and a colimit cokernel cofork `cc` for `S.f`, this is the
right homology data for `S` with `Q := cc.pt` and `H := 0`. -/
@[simps]
noncomputable def Exact.rightHomologyDataOfIsColimitCokernelCofork
(hS : S.Exact) [HasZeroObject C] (cc : CokernelCofork S.f) (hcc : IsColimit cc) :
S.RightHomologyData where
Q := cc.pt
H := 0
p := cc.Ο
ΞΉ := 0
wp := cc.condition
hp := IsColimit.ofIsoColimit hcc (Cofork.ext (Iso.refl _) (by simp))
wΞΉ := zero_comp
hΞΉ := KernelFork.IsLimit.ofMonoOfIsZero _ (by
have := hS.hasHomology
refine ((MorphismProperty.monomorphisms C).arrow_mk_iso_iff ?_).2
hS.mono_fromOpcycles
refine Arrow.isoMk (IsColimit.coconePointUniqueUpToIso hcc S.opcyclesIsCokernel)
(Iso.refl _) ?_
apply Cofork.IsColimit.hom_ext hcc
simp [IsColimit.coconePointUniqueUpToIso]) (isZero_zero C)
variable (S)
lemma exact_iff_epi_toCycles [S.HasHomology] : S.Exact β Epi S.toCycles :=
S.leftHomologyData.exact_iff_epi_f'
lemma exact_iff_mono_fromOpcycles [S.HasHomology] : S.Exact β Mono S.fromOpcycles :=
S.rightHomologyData.exact_iff_mono_g'
lemma exact_iff_epi_kernel_lift [S.HasHomology] [HasKernel S.g] :
S.Exact β Epi (kernel.lift S.g S.f S.zero) := by
rw [exact_iff_epi_toCycles]
apply (MorphismProperty.epimorphisms C).arrow_mk_iso_iff
exact Arrow.isoMk (Iso.refl _) S.cyclesIsoKernel (by cat_disch)
lemma exact_iff_mono_cokernel_desc [S.HasHomology] [HasCokernel S.f] :
S.Exact β Mono (cokernel.desc S.f S.g S.zero) := by
rw [exact_iff_mono_fromOpcycles]
refine (MorphismProperty.monomorphisms C).arrow_mk_iso_iff (Iso.symm ?_)
exact Arrow.isoMk S.opcyclesIsoCokernel.symm (Iso.refl _) (by cat_disch)
lemma QuasiIso.exact_iff {Sβ Sβ : ShortComplex C} (Ο : Sβ βΆ Sβ)
[Sβ.HasHomology] [Sβ.HasHomology] [QuasiIso Ο] : Sβ.Exact β Sβ.Exact := by
simp only [exact_iff_isZero_homology]
exact Iso.isZero_iff (asIso (homologyMap Ο))
lemma exact_of_f_is_kernel (hS : IsLimit (KernelFork.ofΞΉ S.f S.zero))
[S.HasHomology] : S.Exact := by
rw [exact_iff_epi_toCycles]
have : IsSplitEpi S.toCycles :=
β¨β¨{ section_ := hS.lift (KernelFork.ofΞΉ S.iCycles S.iCycles_g)
id := by
rw [β cancel_mono S.iCycles, assoc, toCycles_i, id_comp]
exact Fork.IsLimit.lift_ΞΉ hS }β©β©
infer_instance
lemma exact_of_g_is_cokernel (hS : IsColimit (CokernelCofork.ofΟ S.g S.zero))
[S.HasHomology] : S.Exact := by
rw [exact_iff_mono_fromOpcycles]
have : IsSplitMono S.fromOpcycles :=
β¨β¨{ retraction := hS.desc (CokernelCofork.ofΟ S.pOpcycles S.f_pOpcycles)
id := by
rw [β cancel_epi S.pOpcycles, p_fromOpcycles_assoc, comp_id]
exact Cofork.IsColimit.Ο_desc hS }β©β©
infer_instance
variable {S}
lemma Exact.mono_g (hS : S.Exact) (hf : S.f = 0) : Mono S.g := by
have := hS.hasHomology
have := hS.epi_toCycles
have : S.iCycles = 0 := by rw [β cancel_epi S.toCycles, comp_zero, toCycles_i, hf]
apply Preadditive.mono_of_cancel_zero
intro A xβ hxβ
rw [β S.liftCycles_i xβ hxβ, this, comp_zero]
lemma Exact.epi_f (hS : S.Exact) (hg : S.g = 0) : Epi S.f := by
have := hS.hasHomology
have := hS.mono_fromOpcycles
have : S.pOpcycles = 0 := by rw [β cancel_mono S.fromOpcycles, zero_comp, p_fromOpcycles, hg]
apply Preadditive.epi_of_cancel_zero
intro A xβ hxβ
rw [β S.p_descOpcycles xβ hxβ, this, zero_comp]
lemma Exact.mono_g_iff (hS : S.Exact) : Mono S.g β S.f = 0 := by
constructor
Β· intro
rw [β cancel_mono S.g, zero, zero_comp]
Β· exact hS.mono_g
lemma Exact.epi_f_iff (hS : S.Exact) : Epi S.f β S.g = 0 := by
constructor
Β· intro
rw [β cancel_epi S.f, zero, comp_zero]
Β· exact hS.epi_f
lemma Exact.isZero_Xβ (hS : S.Exact) (hf : S.f = 0) (hg : S.g = 0) : IsZero S.Xβ := by
have := hS.mono_g hf
rw [IsZero.iff_id_eq_zero, β cancel_mono S.g, hg, comp_zero, comp_zero]
lemma Exact.isZero_Xβ_iff (hS : S.Exact) : IsZero S.Xβ β S.f = 0 β§ S.g = 0 := by
constructor
Β· intro h
exact β¨h.eq_of_tgt _ _, h.eq_of_src _ _β©
Β· rintro β¨hf, hgβ©
exact hS.isZero_Xβ hf hg
variable (S)
/-- A splitting for a short complex `S` consists of the data of a retraction `r : Xβ βΆ Xβ`
of `S.f` and section `s : Xβ βΆ Xβ` of `S.g` which satisfy `r β« S.f + S.g β« s = π _` -/
structure Splitting (S : ShortComplex C) where
/-- a retraction of `S.f` -/
r : S.Xβ βΆ S.Xβ
/-- a section of `S.g` -/
s : S.Xβ βΆ S.Xβ
/-- the condition that `r` is a retraction of `S.f` -/
f_r : S.f β« r = π _ := by cat_disch
/-- the condition that `s` is a section of `S.g` -/
s_g : s β« S.g = π _ := by cat_disch
/-- the compatibility between the given section and retraction -/
id : r β« S.f + S.g β« s = π _ := by cat_disch
namespace Splitting
attribute [reassoc (attr := simp)] f_r s_g
variable {S}
@[reassoc]
lemma r_f (s : S.Splitting) : s.r β« S.f = π _ - S.g β« s.s := by rw [β s.id, add_sub_cancel_right]
@[reassoc]
lemma g_s (s : S.Splitting) : S.g β« s.s = π _ - s.r β« S.f := by rw [β s.id, add_sub_cancel_left]
/-- Given a splitting of a short complex `S`, this shows that `S.f` is a split monomorphism. -/
@[simps] def splitMono_f (s : S.Splitting) : SplitMono S.f := β¨s.r, s.f_rβ©
lemma isSplitMono_f (s : S.Splitting) : IsSplitMono S.f := β¨β¨s.splitMono_fβ©β©
lemma mono_f (s : S.Splitting) : Mono S.f := by
have := s.isSplitMono_f
infer_instance
/-- Given a splitting of a short complex `S`, this shows that `S.g` is a split epimorphism. -/
@[simps] def splitEpi_g (s : S.Splitting) : SplitEpi S.g := β¨s.s, s.s_gβ©
lemma isSplitEpi_g (s : S.Splitting) : IsSplitEpi S.g := β¨β¨s.splitEpi_gβ©β©
lemma epi_g (s : S.Splitting) : Epi S.g := by
have := s.isSplitEpi_g
infer_instance
@[reassoc (attr := simp)]
lemma s_r (s : S.Splitting) : s.s β« s.r = 0 := by
have := s.epi_g
simp only [β cancel_epi S.g, comp_zero, g_s_assoc, sub_comp, id_comp,
assoc, f_r, comp_id, sub_self]
lemma ext_r (s s' : S.Splitting) (h : s.r = s'.r) : s = s' := by
have := s.epi_g
have eq := s.id
rw [β s'.id, h, add_right_inj, cancel_epi S.g] at eq
cases s
congr
lemma ext_s (s s' : S.Splitting) (h : s.s = s'.s) : s = s' := by
have := s.mono_f
have eq := s.id
rw [β s'.id, h, add_left_inj, cancel_mono S.f] at eq
cases s
congr
/-- The left homology data on a short complex equipped with a splitting. -/
@[simps]
noncomputable def leftHomologyData [HasZeroObject C] (s : S.Splitting) :
LeftHomologyData S := by
have hi := KernelFork.IsLimit.ofΞΉ S.f S.zero
(fun x _ => x β« s.r)
(fun x hx => by simp only [assoc, s.r_f, comp_sub, comp_id,
sub_eq_self, reassoc_of% hx, zero_comp])
(fun x _ b hb => by simp only [β hb, assoc, f_r, comp_id])
let f' := hi.lift (KernelFork.ofΞΉ S.f S.zero)
have hf' : f' = π _ := by
apply Fork.IsLimit.hom_ext hi
dsimp
erw [Fork.IsLimit.lift_ΞΉ hi]
simp only [Fork.ΞΉ_ofΞΉ, id_comp]
have wΟ : f' β« (0 : S.Xβ βΆ 0) = 0 := comp_zero
have hΟ : IsColimit (CokernelCofork.ofΟ 0 wΟ) := CokernelCofork.IsColimit.ofEpiOfIsZero _
(by rw [hf']; infer_instance) (isZero_zero _)
exact
{ K := S.Xβ
H := 0
i := S.f
wi := S.zero
hi := hi
Ο := 0
wΟ := wΟ
hΟ := hΟ }
/-- The right homology data on a short complex equipped with a splitting. -/
@[simps]
noncomputable def rightHomologyData [HasZeroObject C] (s : S.Splitting) :
RightHomologyData S := by
have hp := CokernelCofork.IsColimit.ofΟ S.g S.zero
(fun x _ => s.s β« x)
(fun x hx => by simp only [s.g_s_assoc, sub_comp, id_comp, sub_eq_self, assoc, hx, comp_zero])
(fun x _ b hb => by simp only [β hb, s.s_g_assoc])
let g' := hp.desc (CokernelCofork.ofΟ S.g S.zero)
have hg' : g' = π _ := by
apply Cofork.IsColimit.hom_ext hp
dsimp
erw [Cofork.IsColimit.Ο_desc hp]
simp only [Cofork.Ο_ofΟ, comp_id]
have wΞΉ : (0 : 0 βΆ S.Xβ) β« g' = 0 := zero_comp
have hΞΉ : IsLimit (KernelFork.ofΞΉ 0 wΞΉ) := KernelFork.IsLimit.ofMonoOfIsZero _
(by rw [hg']; dsimp; infer_instance) (isZero_zero _)
exact
{ Q := S.Xβ
H := 0
p := S.g
wp := S.zero
hp := hp
ΞΉ := 0
wΞΉ := wΞΉ
hΞΉ := hΞΉ }
/-- The homology data on a short complex equipped with a splitting. -/
@[simps]
noncomputable def homologyData [HasZeroObject C] (s : S.Splitting) : S.HomologyData where
left := s.leftHomologyData
right := s.rightHomologyData
iso := Iso.refl 0
/-- A short complex equipped with a splitting is exact. -/
lemma exact [HasZeroObject C] (s : S.Splitting) : S.Exact :=
β¨s.homologyData, isZero_zero _β©
/-- If a short complex `S` is equipped with a splitting, then `S.Xβ` is the kernel of `S.g`. -/
noncomputable def fIsKernel [HasZeroObject C] (s : S.Splitting) :
IsLimit (KernelFork.ofΞΉ S.f S.zero) :=
s.homologyData.left.hi
/-- If a short complex `S` is equipped with a splitting, then `S.Xβ` is the cokernel of `S.f`. -/
noncomputable def gIsCokernel [HasZeroObject C] (s : S.Splitting) :
IsColimit (CokernelCofork.ofΟ S.g S.zero) :=
s.homologyData.right.hp
/-- If a short complex `S` has a splitting and `F` is an additive functor, then
`S.map F` also has a splitting. -/
@[simps]
def map (s : S.Splitting) (F : C β₯€ D) [F.Additive] : (S.map F).Splitting where
r := F.map s.r
s := F.map s.s
f_r := by
dsimp [ShortComplex.map]
rw [β F.map_comp, f_r, F.map_id]
s_g := by
dsimp [ShortComplex.map]
simp only [β F.map_comp, s_g, F.map_id]
id := by
dsimp [ShortComplex.map]
simp only [β F.map_id, β s.id, Functor.map_comp, Functor.map_add]
/-- A splitting on a short complex induces splittings on isomorphic short complexes. -/
@[simps]
def ofIso {Sβ Sβ : ShortComplex C} (s : Sβ.Splitting) (e : Sβ β
Sβ) : Sβ.Splitting where
r := e.inv.Οβ β« s.r β« e.hom.Οβ
s := e.inv.Οβ β« s.s β« e.hom.Οβ
f_r := by rw [β e.inv.commββ_assoc, s.f_r_assoc, β comp_Οβ, e.inv_hom_id, id_Οβ]
s_g := by rw [assoc, assoc, e.hom.commββ, s.s_g_assoc, β comp_Οβ, e.inv_hom_id, id_Οβ]
id := by
have eq := e.inv.Οβ β«= s.id =β« e.hom.Οβ
rw [id_comp, β comp_Οβ, e.inv_hom_id, id_Οβ] at eq
rw [β eq, assoc, assoc, add_comp, assoc, assoc, comp_add,
e.hom.commββ, e.inv.commββ_assoc]
/-- The obvious splitting of the short complex `Xβ βΆ Xβ β Xβ βΆ Xβ`. -/
noncomputable def ofHasBinaryBiproduct (Xβ Xβ : C) [HasBinaryBiproduct Xβ Xβ] :
Splitting (ShortComplex.mk (biprod.inl : Xβ βΆ _) (biprod.snd : _ βΆ Xβ) (by simp)) where
r := biprod.fst
s := biprod.inr
variable (S)
/-- The obvious splitting of a short complex when `S.Xβ` is zero and `S.g` is an isomorphism. -/
noncomputable def ofIsZeroOfIsIso (hf : IsZero S.Xβ) (hg : IsIso S.g) : Splitting S where
r := 0
s := inv S.g
f_r := hf.eq_of_src _ _
/-- The obvious splitting of a short complex when `S.f` is an isomorphism and `S.Xβ` is zero. -/
noncomputable def ofIsIsoOfIsZero (hf : IsIso S.f) (hg : IsZero S.Xβ) : Splitting S where
r := inv S.f
s := 0
s_g := hg.eq_of_src _ _
variable {S}
/-- The splitting of the short complex `S.op` deduced from a splitting of `S`. -/
@[simps]
def op (h : Splitting S) : Splitting S.op where
r := h.s.op
s := h.r.op
f_r := Quiver.Hom.unop_inj (by simp)
s_g := Quiver.Hom.unop_inj (by simp)
id := Quiver.Hom.unop_inj (by
simp only [op_Xβ, Opposite.unop_op, op_Xβ, op_f, op_Xβ, op_g, unop_add, unop_comp,
Quiver.Hom.unop_op, unop_id, β h.id]
abel)
/-- The splitting of the short complex `S.unop` deduced from a splitting of `S`. -/
@[simps]
def unop {S : ShortComplex Cα΅α΅} (h : Splitting S) : Splitting S.unop where
r := h.s.unop
s := h.r.unop
f_r := Quiver.Hom.op_inj (by simp)
s_g := Quiver.Hom.op_inj (by simp)
id := Quiver.Hom.op_inj (by
simp only [unop_Xβ, Opposite.op_unop, unop_Xβ, unop_f, unop_Xβ, unop_g, op_add,
op_comp, Quiver.Hom.op_unop, op_id, β h.id]
abel)
/-- The isomorphism `S.Xβ β
S.Xβ β S.Xβ` induced by a splitting of the short complex `S`. -/
@[simps]
noncomputable def isoBinaryBiproduct (h : Splitting S) [HasBinaryBiproduct S.Xβ S.Xβ] :
S.Xβ β
S.Xβ β S.Xβ where
hom := biprod.lift h.r S.g
inv := biprod.desc S.f h.s
hom_inv_id := by simp [h.id]
end Splitting
section Balanced
variable {S}
variable [Balanced C]
namespace Exact
lemma isIso_f' (hS : S.Exact) (h : S.LeftHomologyData) [Mono S.f] :
IsIso h.f' := by
have := hS.epi_f' h
have := mono_of_mono_fac h.f'_i
exact isIso_of_mono_of_epi h.f'
lemma isIso_toCycles (hS : S.Exact) [Mono S.f] [S.HasLeftHomology] :
IsIso S.toCycles :=
hS.isIso_f' _
lemma isIso_g' (hS : S.Exact) (h : S.RightHomologyData) [Epi S.g] :
IsIso h.g' := by
have := hS.mono_g' h
have := epi_of_epi_fac h.p_g'
exact isIso_of_mono_of_epi h.g'
lemma isIso_fromOpcycles (hS : S.Exact) [Epi S.g] [S.HasRightHomology] :
IsIso S.fromOpcycles :=
hS.isIso_g' _
/-- In a balanced category, if a short complex `S` is exact and `S.f` is a mono, then
`S.Xβ` is the kernel of `S.g`. -/
noncomputable def fIsKernel (hS : S.Exact) [Mono S.f] : IsLimit (KernelFork.ofΞΉ S.f S.zero) := by
have := hS.hasHomology
have := hS.isIso_toCycles
exact IsLimit.ofIsoLimit S.cyclesIsKernel
(Fork.ext (asIso S.toCycles).symm (by simp))
lemma map_of_mono_of_preservesKernel (hS : S.Exact) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [(S.map F).HasHomology] (_ : Mono S.f)
(_ : PreservesLimit (parallelPair S.g 0) F) :
(S.map F).Exact :=
exact_of_f_is_kernel _ (KernelFork.mapIsLimit _ hS.fIsKernel F)
/-- In a balanced category, if a short complex `S` is exact and `S.g` is an epi, then
`S.Xβ` is the cokernel of `S.g`. -/
noncomputable def gIsCokernel (hS : S.Exact) [Epi S.g] :
IsColimit (CokernelCofork.ofΟ S.g S.zero) := by
have := hS.hasHomology
have := hS.isIso_fromOpcycles
exact IsColimit.ofIsoColimit S.opcyclesIsCokernel
(Cofork.ext (asIso S.fromOpcycles) (by simp))
lemma map_of_epi_of_preservesCokernel (hS : S.Exact) (F : C β₯€ D)
[F.PreservesZeroMorphisms] [(S.map F).HasHomology] (_ : Epi S.g)
(_ : PreservesColimit (parallelPair S.f 0) F) :
(S.map F).Exact :=
exact_of_g_is_cokernel _ (CokernelCofork.mapIsColimit _ hS.gIsCokernel F)
/-- If a short complex `S` in a balanced category is exact and such that `S.f` is a mono,
then a morphism `k : A βΆ S.Xβ` such that `k β« S.g = 0` lifts to a morphism `A βΆ S.Xβ`. -/
noncomputable def lift (hS : S.Exact) {A : C} (k : A βΆ S.Xβ) (hk : k β« S.g = 0) [Mono S.f] :
A βΆ S.Xβ := hS.fIsKernel.lift (KernelFork.ofΞΉ k hk)
@[reassoc (attr := simp)]
lemma lift_f (hS : S.Exact) {A : C} (k : A βΆ S.Xβ) (hk : k β« S.g = 0) [Mono S.f] :
hS.lift k hk β« S.f = k :=
Fork.IsLimit.lift_ΞΉ _
lemma lift' (hS : S.Exact) {A : C} (k : A βΆ S.Xβ) (hk : k β« S.g = 0) [Mono S.f] :
β (l : A βΆ S.Xβ), l β« S.f = k :=
β¨hS.lift k hk, by simpβ©
/-- If a short complex `S` in a balanced category is exact and such that `S.g` is an epi,
then a morphism `k : S.Xβ βΆ A` such that `S.f β« k = 0` descends to a morphism `S.Xβ βΆ A`. -/
noncomputable def desc (hS : S.Exact) {A : C} (k : S.Xβ βΆ A) (hk : S.f β« k = 0) [Epi S.g] :
S.Xβ βΆ A := hS.gIsCokernel.desc (CokernelCofork.ofΟ k hk)
@[reassoc (attr := simp)]
lemma g_desc (hS : S.Exact) {A : C} (k : S.Xβ βΆ A) (hk : S.f β« k = 0) [Epi S.g] :
S.g β« hS.desc k hk = k :=
Cofork.IsColimit.Ο_desc (hS.gIsCokernel)
lemma desc' (hS : S.Exact) {A : C} (k : S.Xβ βΆ A) (hk : S.f β« k = 0) [Epi S.g] :
β (l : S.Xβ βΆ A), S.g β« l = k :=
β¨hS.desc k hk, by simpβ©
end Exact
lemma mono_Οβ_of_exact_of_mono {Sβ Sβ : ShortComplex C} (Ο : Sβ βΆ Sβ)
(hβ : Sβ.Exact) [Mono Sβ.f] [Mono Sβ.f] [Mono Ο.Οβ] [Mono Ο.Οβ] : Mono Ο.Οβ := by
rw [mono_iff_cancel_zero]
intro A xβ hxβ
obtain β¨xβ, hxββ© : β xβ, xβ β« Sβ.f = xβ := β¨_, hβ.lift_f xβ
(by simp only [β cancel_mono Ο.Οβ, assoc, zero_comp, β Ο.commββ, reassoc_of% hxβ])β©
suffices xβ = 0 by rw [β hxβ, this, zero_comp]
simp only [β cancel_mono Ο.Οβ, β cancel_mono Sβ.f, assoc, Ο.commββ, zero_comp,
reassoc_of% hxβ, hxβ]
attribute [local instance] balanced_opposite
lemma epi_Οβ_of_exact_of_epi {Sβ Sβ : ShortComplex C} (Ο : Sβ βΆ Sβ)
(hβ : Sβ.Exact) [Epi Sβ.g] [Epi Sβ.g] [Epi Ο.Οβ] [Epi Ο.Οβ] : Epi Ο.Οβ := by
have : Mono Sβ.op.f := by dsimp; infer_instance
have : Mono Sβ.op.f := by dsimp; infer_instance
have : Mono (opMap Ο).Οβ := by dsimp; infer_instance
have : Mono (opMap Ο).Οβ := by dsimp; infer_instance
have := mono_Οβ_of_exact_of_mono (opMap Ο) hβ.op
exact unop_epi_of_mono (opMap Ο).Οβ
variable (S)
lemma exact_and_mono_f_iff_f_is_kernel [S.HasHomology] :
S.Exact β§ Mono S.f β Nonempty (IsLimit (KernelFork.ofΞΉ S.f S.zero)) := by
constructor
Β· intro β¨hS, _β©
exact β¨hS.fIsKernelβ©
Β· intro β¨hSβ©
exact β¨S.exact_of_f_is_kernel hS, mono_of_isLimit_fork hSβ©
lemma exact_and_epi_g_iff_g_is_cokernel [S.HasHomology] :
S.Exact β§ Epi S.g β Nonempty (IsColimit (CokernelCofork.ofΟ S.g S.zero)) := by
constructor
Β· intro β¨hS, _β©
exact β¨hS.gIsCokernelβ©
Β· intro β¨hSβ©
exact β¨S.exact_of_g_is_cokernel hS, epi_of_isColimit_cofork hSβ©
end Balanced
end Preadditive
section Abelian
variable [Abelian C]
/-- Given a morphism of short complexes `Ο : Sβ βΆ Sβ` in an abelian category, if `Sβ.f`
and `Sβ.g` are zero (e.g. when `Sβ` is of the form `0 βΆ Sβ.Xβ βΆ 0`) and `Sβ.f = 0`
(e.g when `Sβ` is of the form `0 βΆ Sβ.Xβ βΆ Sβ.Xβ`), then `Ο` is a quasi-isomorphism iff
the obvious short complex `Sβ.Xβ βΆ Sβ.Xβ βΆ Sβ.Xβ` is exact and `Ο.Οβ` is a mono). -/
lemma quasiIso_iff_of_zeros {Sβ Sβ : ShortComplex C} (Ο : Sβ βΆ Sβ)
(hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) (hfβ : Sβ.f = 0) :
QuasiIso Ο β
(ShortComplex.mk Ο.Οβ Sβ.g (by rw [Ο.commββ, hgβ, zero_comp])).Exact β§ Mono Ο.Οβ := by
have w : Ο.Οβ β« Sβ.g = 0 := by rw [Ο.commββ, hgβ, zero_comp]
rw [quasiIso_iff_isIso_liftCycles Ο hfβ hgβ hfβ]
constructor
Β· intro h
have : Mono Ο.Οβ := by
rw [β Sβ.liftCycles_i Ο.Οβ w]
apply mono_comp
refine β¨?_, thisβ©
apply exact_of_f_is_kernel
exact IsLimit.ofIsoLimit Sβ.cyclesIsKernel
(Fork.ext (asIso (Sβ.liftCycles Ο.Οβ w)).symm (by simp))
Β· rintro β¨hβ, hββ©
refine β¨β¨hβ.lift Sβ.iCycles (by simp), ?_, ?_β©β©
Β· rw [β cancel_mono Ο.Οβ, assoc, hβ.lift_f, liftCycles_i, id_comp]
Β· rw [β cancel_mono Sβ.iCycles, assoc, liftCycles_i, hβ.lift_f, id_comp]
/-- Given a morphism of short complexes `Ο : Sβ βΆ Sβ` in an abelian category, if `Sβ.g = 0`
(e.g when `Sβ` is of the form `Sβ.Xβ βΆ Sβ.Xβ βΆ 0`) and both `Sβ.f` and `Sβ.g` are zero
(e.g when `Sβ` is of the form `0 βΆ Sβ.Xβ βΆ 0`), then `Ο` is a quasi-isomorphism iff
the obvious short complex `Sβ.Xβ βΆ Sβ.Xβ βΆ Sβ.Xβ` is exact and `Ο.Οβ` is an epi). -/
lemma quasiIso_iff_of_zeros' {Sβ Sβ : ShortComplex C} (Ο : Sβ βΆ Sβ)
(hgβ : Sβ.g = 0) (hfβ : Sβ.f = 0) (hgβ : Sβ.g = 0) :
QuasiIso Ο β
(ShortComplex.mk Sβ.f Ο.Οβ (by rw [β Ο.commββ, hfβ, comp_zero])).Exact β§ Epi Ο.Οβ := by
rw [β quasiIso_opMap_iff, quasiIso_iff_of_zeros]
rotate_left
Β· dsimp
rw [hgβ, op_zero]
Β· dsimp
rw [hfβ, op_zero]
Β· dsimp
rw [hgβ, op_zero]
rw [β exact_unop_iff]
have : Mono Ο.Οβ.op β Epi Ο.Οβ :=
β¨fun _ => unop_epi_of_mono Ο.Οβ.op, fun _ => op_mono_of_epi _β©
tauto
variable {S : ShortComplex C}
/-- If `S` is an exact short complex and `f : S.Xβ βΆ J` is a morphism to an injective object `J`
such that `S.f β« f = 0`, this is a morphism `Ο : S.Xβ βΆ J` such that `S.g β« Ο = f`. -/
noncomputable def Exact.descToInjective
(hS : S.Exact) {J : C} (f : S.Xβ βΆ J) [Injective J] (hf : S.f β« f = 0) :
S.Xβ βΆ J := by
have := hS.mono_fromOpcycles
exact Injective.factorThru (S.descOpcycles f hf) S.fromOpcycles
@[reassoc (attr := simp, nolint unusedHavesSuffices)]
lemma Exact.comp_descToInjective
(hS : S.Exact) {J : C} (f : S.Xβ βΆ J) [Injective J] (hf : S.f β« f = 0) :
S.g β« hS.descToInjective f hf = f := by
have := hS.mono_fromOpcycles
dsimp [descToInjective]
simp only [β p_fromOpcycles, assoc, Injective.comp_factorThru, p_descOpcycles]
/-- If `S` is an exact short complex and `f : P βΆ S.Xβ` is a morphism from a projective object `P`
such that `f β« S.g = 0`, this is a morphism `Ο : P βΆ S.Xβ` such that `Ο β« S.f = f`. -/
noncomputable def Exact.liftFromProjective
(hS : S.Exact) {P : C} (f : P βΆ S.Xβ) [Projective P] (hf : f β« S.g = 0) :
P βΆ S.Xβ := by
have := hS.epi_toCycles
exact Projective.factorThru (S.liftCycles f hf) S.toCycles
@[reassoc (attr := simp, nolint unusedHavesSuffices)]
lemma Exact.liftFromProjective_comp
(hS : S.Exact) {P : C} (f : P βΆ S.Xβ) [Projective P] (hf : f β« S.g = 0) :
hS.liftFromProjective f hf β« S.f = f := by
have := hS.epi_toCycles
dsimp [liftFromProjective]
rw [β toCycles_i, Projective.factorThru_comp_assoc, liftCycles_i]
end Abelian
end ShortComplex
namespace Functor
variable (F : C β₯€ D) [Preadditive C] [Preadditive D] [HasZeroObject C]
[HasZeroObject D] [F.PreservesZeroMorphisms] [F.PreservesHomology]
instance : F.PreservesMonomorphisms where
preserves {X Y} f hf := by
let S := ShortComplex.mk (0 : X βΆ X) f zero_comp
exact ((S.map F).exact_iff_mono (by simp [S])).1
(((S.exact_iff_mono rfl).2 hf).map F)
instance : F.PreservesEpimorphisms where
preserves {X Y} f hf := by
let S := ShortComplex.mk f (0 : Y βΆ Y) comp_zero
exact ((S.map F).exact_iff_epi (by simp [S])).1
(((S.exact_iff_epi rfl).2 hf).map F)
end Functor
namespace ShortComplex
namespace Splitting
variable [Preadditive C] [Balanced C]
/-- This is the splitting of a short complex `S` in a balanced category induced by
a section of the morphism `S.g : S.Xβ βΆ S.Xβ` -/
noncomputable def ofExactOfSection (S : ShortComplex C) (hS : S.Exact) (s : S.Xβ βΆ S.Xβ)
(s_g : s β« S.g = π S.Xβ) (hf : Mono S.f) :
S.Splitting where
r := hS.lift (π S.Xβ - S.g β« s) (by simp [s_g])
s := s
f_r := by rw [β cancel_mono S.f, assoc, Exact.lift_f, comp_sub, comp_id,
zero_assoc, zero_comp, sub_zero, id_comp]
s_g := s_g
/-- This is the splitting of a short complex `S` in a balanced category induced by
a retraction of the morphism `S.f : S.Xβ βΆ S.Xβ` -/
noncomputable def ofExactOfRetraction (S : ShortComplex C) (hS : S.Exact) (r : S.Xβ βΆ S.Xβ)
(f_r : S.f β« r = π S.Xβ) (hg : Epi S.g) :
S.Splitting where
r := r
s := hS.desc (π S.Xβ - r β« S.f) (by simp [reassoc_of% f_r])
f_r := f_r
s_g := by
rw [β cancel_epi S.g, Exact.g_desc_assoc, sub_comp, id_comp, assoc, zero,
comp_zero, sub_zero, comp_id]
end Splitting
end ShortComplex
end CategoryTheory
|
Degeneracies.lean
|
/-
Copyright (c) 2022 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.AlgebraicTopology.DoldKan.Decomposition
import Mathlib.Tactic.FinCases
/-!
# Behaviour of P_infty with respect to degeneracies
For any `X : SimplicialObject C` where `C` is an abelian category,
the projector `PInfty : K[X] βΆ K[X]` is supposed to be the projection
on the normalized subcomplex, parallel to the degenerate subcomplex, i.e.
the subcomplex generated by the images of all `X.Ο i`.
In this file, we obtain `degeneracy_comp_P_infty` which states that
if `X : SimplicialObject C` with `C` a preadditive category,
`ΞΈ : β¦nβ¦ βΆ Ξ'` is a non injective map in `SimplexCategory`, then
`X.map ΞΈ.op β« P_infty.f n = 0`. It follows from the more precise
statement vanishing statement `Ο_comp_P_eq_zero` for the `P q`.
(See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.)
-/
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits
CategoryTheory.Preadditive Simplicial
namespace AlgebraicTopology
namespace DoldKan
variable {C : Type*} [Category C] [Preadditive C]
theorem HigherFacesVanish.comp_Ο {Y : C} {X : SimplicialObject C} {n b q : β} {Ο : Y βΆ X _β¦n + 1β¦}
(v : HigherFacesVanish q Ο) (hnbq : n + 1 = b + q) :
HigherFacesVanish q
(Ο β«
X.Ο β¨b, by
simp only [hnbq, Nat.lt_add_one_iff, le_add_iff_nonneg_right, zero_le]β©) :=
fun j hj => by
rw [assoc, SimplicialObject.Ξ΄_comp_Ο_of_gt', Fin.pred_succ, v.comp_Ξ΄_eq_zero_assoc _ _ hj,
zero_comp]
Β· dsimp
rw [Fin.lt_iff_val_lt_val, Fin.val_succ]
linarith
Β· intro hj'
simp only [hnbq, add_comm b, add_assoc, hj', Fin.val_zero, zero_add, add_le_iff_nonpos_right,
nonpos_iff_eq_zero, add_eq_zero, false_and, reduceCtorEq] at hj
theorem Ο_comp_P_eq_zero (X : SimplicialObject C) {n q : β} (i : Fin (n + 1)) (hi : n + 1 β€ i + q) :
X.Ο i β« (P q).f (n + 1) = 0 := by
revert i hi
induction' q with q hq
Β· intro i (hi : n + 1 β€ i)
omega
Β· intro i (hi : n + 1 β€ i + q + 1)
by_cases h : n + 1 β€ (i : β) + q
Β· rw [P_succ, HomologicalComplex.comp_f, β assoc, hq i h, zero_comp]
Β· replace hi : n = i + q := by
obtain β¨j, hjβ© := le_iff_exists_add.mp hi
rw [β Nat.lt_succ_iff, Nat.succ_eq_add_one, hj, not_lt, add_le_iff_nonpos_right,
nonpos_iff_eq_zero] at h
rw [β add_left_inj 1, hj, left_eq_add, h]
rcases n with _ | n
Β· fin_cases i
dsimp at h hi
rw [show q = 0 by omega]
change X.Ο 0 β« (P 1).f 1 = 0
simp only [P_succ, HomologicalComplex.add_f_apply, comp_add,
AlternatingFaceMapComplex.obj_d_eq, HΟ,
HomologicalComplex.comp_f, Homotopy.nullHomotopicMap'_f (c_mk 2 1 rfl) (c_mk 1 0 rfl),
comp_id]
rw [hΟ'_eq' (zero_add 0).symm, hΟ'_eq' (add_zero 1).symm]
dsimp [P_zero]
rw [comp_id, Fin.sum_univ_two,
Fin.sum_univ_succ, Fin.sum_univ_two]
simp only [Fin.val_zero, pow_zero, pow_one, pow_add, one_smul, neg_smul, Fin.val_succ,
Fin.val_one, mul_neg, one_mul, neg_mul, neg_neg, id_comp, add_comp, comp_add, neg_comp,
comp_neg, Fin.succ_zero_eq_one]
rw [β Fin.castSucc_one, SimplicialObject.Ξ΄_comp_Ο_self, β Fin.castSucc_zero (n := 1),
SimplicialObject.Ξ΄_comp_Ο_self_assoc,
SimplicialObject.Ξ΄_comp_Ο_succ, comp_id, β Fin.castSucc_zero (n := 2),
β Fin.succ_zero_eq_one,
SimplicialObject.Ξ΄_comp_Ο_of_le X
(show (0 : Fin 2) β€ Fin.castSucc 0 by rw [Fin.castSucc_zero]),
β Fin.castSucc_zero (n := 1), SimplicialObject.Ξ΄_comp_Ο_self_assoc,
SimplicialObject.Ξ΄_comp_Ο_succ_assoc]
simp only [add_neg_cancel, add_zero, zero_add]
Β· rw [β id_comp (X.Ο i), β (P_add_Q_f q n.succ : _ = π (X.obj _)), add_comp, add_comp,
P_succ]
have v : HigherFacesVanish q ((P q).f n.succ β« X.Ο i) :=
(HigherFacesVanish.of_P q n).comp_Ο hi
dsimp only [AlternatingFaceMapComplex.obj_X, Nat.succ_eq_add_one, HomologicalComplex.comp_f,
HomologicalComplex.add_f_apply, HomologicalComplex.id_f]
rw [β assoc, v.comp_P_eq_self, Preadditive.comp_add,
comp_id, v.comp_HΟ_eq hi, assoc, β Fin.succ_mk, SimplicialObject.Ξ΄_comp_Ο_succ_assoc,
Fin.eta, decomposition_Q n q, sum_comp, sum_comp, Finset.sum_eq_zero, add_zero,
add_neg_eq_zero]
intro j hj
simp only [Finset.mem_univ, Finset.mem_filter] at hj
obtain β¨k, hkβ© := Nat.le.dest (Nat.lt_succ_iff.mp (Fin.is_lt j))
rw [add_comm] at hk
have hi' : i = Fin.castSucc β¨i, by omegaβ© := by
ext
simp only [Fin.castSucc_mk, Fin.eta]
have eq := hq j.rev.succ (by
simp only [β hk, Fin.rev_eq j hk.symm, Fin.succ_mk, Fin.val_mk]
omega)
rw [assoc, assoc, assoc, hi',
SimplicialObject.Ο_comp_Ο_assoc, reassoc_of% eq, zero_comp, comp_zero, comp_zero,
comp_zero]
simp only [Fin.rev_eq j hk.symm, Fin.le_iff_val_le_val]
omega
@[reassoc (attr := simp)]
theorem Ο_comp_PInfty (X : SimplicialObject C) {n : β} (i : Fin (n + 1)) :
X.Ο i β« PInfty.f (n + 1) = 0 := by
rw [PInfty_f, Ο_comp_P_eq_zero X i]
simp only [le_add_iff_nonneg_left, zero_le]
@[reassoc]
theorem degeneracy_comp_PInfty (X : SimplicialObject C) (n : β) {Ξ' : SimplexCategory}
(ΞΈ : β¦nβ¦ βΆ Ξ') (hΞΈ : Β¬Mono ΞΈ) : X.map ΞΈ.op β« PInfty.f n = 0 := by
rw [SimplexCategory.mono_iff_injective] at hΞΈ
cases n
Β· exfalso
apply hΞΈ
intro x y h
fin_cases x
fin_cases y
rfl
Β· obtain β¨i, Ξ±, hβ© := SimplexCategory.eq_Ο_comp_of_not_injective ΞΈ hΞΈ
rw [h, op_comp, X.map_comp, assoc, show X.map (SimplexCategory.Ο i).op = X.Ο i by rfl,
Ο_comp_PInfty, comp_zero]
end DoldKan
end AlgebraicTopology
|
character.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 choice ssrnat seq.
From mathcomp Require Import path div fintype tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset gproduct fingroup morphism.
From mathcomp Require Import perm automorphism quotient finalg action zmodp.
From mathcomp Require Import commutator cyclic center pgroup nilpotent sylow.
From mathcomp Require Import abelian matrix mxalgebra mxpoly mxrepresentation.
From mathcomp Require Import vector ssrnum algC classfun archimedean.
(******************************************************************************)
(* This file contains the basic notions of character theory, based on Isaacs. *)
(* irr G == tuple of the elements of 'CF(G) that are irreducible *)
(* characters of G. *)
(* Nirr G == number of irreducible characters of G. *)
(* Iirr G == index type for the irreducible characters of G. *)
(* := 'I_(Nirr G). *)
(* 'chi_i == the i-th element of irr G, for i : Iirr G. *)
(* 'chi[G]_i Note that 'chi_0 = 1, the principal character of G. *)
(* 'Chi_i == an irreducible representation that affords 'chi_i. *)
(* socle_of_Iirr i == the Wedderburn component of the regular representation *)
(* of G, corresponding to 'Chi_i. *)
(* Iirr_of_socle == the inverse of socle_of_Iirr (which is one-to-one). *)
(* phi.[A]%CF == the image of A \in group_ring G under phi : 'CF(G). *)
(* cfRepr rG == the character afforded by the representation rG of G. *)
(* cfReg G == the regular character, afforded by the regular *)
(* representation of G. *)
(* detRepr rG == the linear character afforded by the determinant of rG. *)
(* cfDet phi == the linear character afforded by the determinant of a *)
(* representation affording phi. *)
(* 'o(phi) == the "determinential order" of phi (the multiplicative *)
(* order of cfDet phi. *)
(* phi \is a character <=> phi : 'CF(G) is a character of G or 0. *)
(* i \in irr_constt phi <=> 'chi_i is an irreducible constituent of phi: phi *)
(* has a non-zero coordinate on 'chi_i over the basis irr G. *)
(* xi \is a linear_char xi <=> xi : 'CF(G) is a linear character of G. *)
(* 'Z(chi)%CF == the center of chi when chi is a character of G, i.e., *)
(* rcenter rG where rG is a representation that affords phi. *)
(* If phi is not a character then 'Z(chi)%CF = cfker phi. *)
(* aut_Iirr u i == the index of cfAut u 'chi_i in irr G. *)
(* conjC_Iirr i == the index of 'chi_i^*%CF in irr G. *)
(* morph_Iirr i == the index of cfMorph 'chi[f @* G]_i in irr G. *)
(* isom_Iirr isoG i == the index of cfIsom isoG 'chi[G]_i in irr R. *)
(* mod_Iirr i == the index of ('chi[G / H]_i %% H)%CF in irr G. *)
(* quo_Iirr i == the index of ('chi[G]_i / H)%CF in irr (G / H). *)
(* Ind_Iirr G i == the index of 'Ind[G, H] 'chi_i, provided it is an *)
(* irreducible character (such as when if H is the inertia *)
(* group of 'chi_i). *)
(* Res_Iirr H i == the index of 'Res[H, G] 'chi_i, provided it is an *)
(* irreducible character (such as when 'chi_i is linear). *)
(* sdprod_Iirr defG i == the index of cfSdprod defG 'chi_i in irr G, given *)
(* defG : K ><| H = G. *)
(* And, for KxK : K \x H = G. *)
(* dprodl_Iirr KxH i == the index of cfDprodl KxH 'chi[K]_i in irr G. *)
(* dprodr_Iirr KxH j == the index of cfDprodr KxH 'chi[H]_j in irr G. *)
(* dprod_Iirr KxH (i, j) == the index of cfDprod KxH 'chi[K]_i 'chi[H]_j. *)
(* inv_dprod_Iirr KxH == the inverse of dprod_Iirr KxH. *)
(* The following are used to define and exploit the character table: *)
(* character_table G == the character table of G, whose i-th row lists the *)
(* values taken by 'chi_i on the conjugacy classes *)
(* of G; this is a square Nirr G x NirrG matrix. *)
(* irr_class i == the conjugacy class of G with index i : Iirr G. *)
(* class_Iirr xG == the index of xG \in classes G, in Iirr G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Section AlgC.
Variable (gT : finGroupType).
Lemma groupC : group_closure_field algC gT.
Proof. exact: group_closure_closed_field. Qed.
End AlgC.
Section Tensor.
Variable (F : fieldType).
Fixpoint trow (n1 : nat) :
forall (A : 'rV[F]_n1) m2 n2 (B : 'M[F]_(m2,n2)), 'M[F]_(m2,n1 * n2) :=
if n1 is n'1.+1
then
fun (A : 'M[F]_(1,(1 + n'1))) m2 n2 (B : 'M[F]_(m2,n2)) =>
(row_mx (lsubmx A 0 0 *: B) (trow (rsubmx A) B))
else (fun _ _ _ _ => 0).
Lemma trow0 n1 m2 n2 B : @trow n1 0 m2 n2 B = 0.
Proof.
elim: n1=> //= n1 IH.
rewrite !mxE scale0r linear0.
rewrite IH //; apply/matrixP=> i j; rewrite !mxE.
by case: split=> *; rewrite mxE.
Qed.
Definition trowb n1 m2 n2 B A := @trow n1 A m2 n2 B.
Lemma trowbE n1 m2 n2 A B : trowb B A = @trow n1 A m2 n2 B.
Proof. by []. Qed.
Lemma trowb_is_linear n1 m2 n2 (B : 'M_(m2,n2)) : linear (@trowb n1 m2 n2 B).
Proof.
elim: n1=> [|n1 IH] //= k A1 A2 /=; first by rewrite scaler0 add0r.
rewrite !linearD /= !linearZ /= IH 2!mxE.
by rewrite scalerDl -scalerA -add_row_mx -scale_row_mx.
Qed.
HB.instance Definition _ n1 m2 n2 B :=
GRing.isSemilinear.Build _ _ _ _ (trowb B)
(GRing.semilinear_linear (@trowb_is_linear n1 m2 n2 B)).
Lemma trow_is_linear n1 m2 n2 (A : 'rV_n1) : linear (@trow n1 A m2 n2).
Proof.
elim: n1 A => [|n1 IH] //= A k A1 A2 /=; first by rewrite scaler0 add0r.
rewrite linearP /=; apply/matrixP=> i j; rewrite !mxE.
by case: split=> a; rewrite ?IH !mxE.
Qed.
HB.instance Definition _ n1 m2 n2 A :=
GRing.isSemilinear.Build _ _ _ _ (@trow n1 A m2 n2)
(GRing.semilinear_linear (@trow_is_linear n1 m2 n2 A)).
Fixpoint tprod (m1 : nat) :
forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)),
'M[F]_(m1 * m2,n1 * n2) :=
if m1 is m'1.+1
return forall n1 (A : 'M[F]_(m1,n1)) m2 n2 (B : 'M[F]_(m2,n2)),
'M[F]_(m1 * m2,n1 * n2)
then
fun n1 (A : 'M[F]_(1 + m'1,n1)) m2 n2 B =>
(col_mx (trow (usubmx A) B) (tprod (dsubmx A) B))
else (fun _ _ _ _ _ => 0).
Lemma dsumx_mul m1 m2 n p A B :
dsubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = dsubmx (A : 'M_(m1 + m2, p)) *m B.
Proof.
apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _.
by rewrite !mxE.
Qed.
Lemma usumx_mul m1 m2 n p A B :
usubmx ((A *m B) : 'M[F]_(m1 + m2, n)) = usubmx (A : 'M_(m1 + m2, p)) *m B.
Proof.
by apply/matrixP=> i j /[!mxE]; apply: eq_bigr=> k _ /[!mxE].
Qed.
Let trow_mul (m1 m2 n2 p2 : nat)
(A : 'rV_m1) (B1: 'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) :
trow A (B1 *m B2) = B1 *m trow A B2.
Proof.
elim: m1 A => [|m1 IH] A /=; first by rewrite mulmx0.
by rewrite IH mul_mx_row -scalemxAr.
Qed.
Lemma tprodE m1 n1 p1 (A1 :'M[F]_(m1,n1)) (A2 :'M[F]_(n1,p1))
m2 n2 p2 (B1 :'M[F]_(m2,n2)) (B2 :'M[F]_(n2,p2)) :
tprod (A1 *m A2) (B1 *m B2) = (tprod A1 B1) *m (tprod A2 B2).
Proof.
elim: m1 n1 p1 A1 A2 m2 n2 p2 B1 B2 => /= [|m1 IH].
by move=> *; rewrite mul0mx.
move=> n1 p1 A1 A2 m2 n2 p2 B1 B2.
rewrite mul_col_mx -IH.
congr col_mx; last by rewrite dsumx_mul.
rewrite usumx_mul.
elim: n1 {A1}(usubmx (A1: 'M_(1 + m1, n1))) p1 A2=> //= [u p1 A2|].
by rewrite [A2](flatmx0) !mulmx0 -trowbE linear0.
move=> n1 IH1 A p1 A2 //=.
set Al := lsubmx _; set Ar := rsubmx _.
set Su := usubmx _; set Sd := dsubmx _.
rewrite mul_row_col -IH1.
rewrite -{1}(@hsubmxK F 1 1 n1 A).
rewrite -{1}(@vsubmxK F 1 n1 p1 A2).
rewrite (@mul_row_col F 1 1 n1 p1).
rewrite -trowbE linearD /= trowbE -/Al.
congr (_ + _).
rewrite {1}[Al]mx11_scalar mul_scalar_mx.
by rewrite -trowbE linearZ /= trowbE -/Su trow_mul scalemxAl.
Qed.
Let tprod_tr m1 n1 (A :'M[F]_(m1, 1 + n1)) m2 n2 (B :'M[F]_(m2, n2)) :
tprod A B = row_mx (trow (lsubmx A)^T B^T)^T (tprod (rsubmx A) B).
Proof.
elim: m1 n1 A m2 n2 B=> [|m1 IH] n1 A m2 n2 B //=.
by rewrite trmx0 row_mx0.
rewrite !IH.
pose A1 := A : 'M_(1 + m1, 1 + n1).
have F1: dsubmx (rsubmx A1) = rsubmx (dsubmx A1).
by apply/matrixP=> i j; rewrite !mxE.
have F2: rsubmx (usubmx A1) = usubmx (rsubmx A1).
by apply/matrixP=> i j; rewrite !mxE.
have F3: lsubmx (dsubmx A1) = dsubmx (lsubmx A1).
by apply/matrixP=> i j; rewrite !mxE.
rewrite tr_row_mx -block_mxEv -block_mxEh !(F1,F2,F3); congr block_mx.
- by rewrite !mxE linearZ /= trmxK.
by rewrite -trmx_dsub.
Qed.
Lemma tprod1 m n : tprod (1%:M : 'M[F]_(m,m)) (1%:M : 'M[F]_(n,n)) = 1%:M.
Proof.
elim: m n => [|m IH] n //=; first by rewrite [1%:M]flatmx0.
rewrite tprod_tr.
set u := rsubmx _; have->: u = 0.
apply/matrixP=> i j; rewrite !mxE.
by case: i; case: j=> /= j Hj; case.
set v := lsubmx (dsubmx _); have->: v = 0.
apply/matrixP=> i j; rewrite !mxE.
by case: i; case: j; case.
set w := rsubmx _; have->: w = 1%:M.
apply/matrixP=> i j; rewrite !mxE.
by case: i; case: j; case.
rewrite IH -!trowbE !linear0.
rewrite -block_mxEv.
set z := (lsubmx _) 0 0; have->: z = 1.
by rewrite /z !mxE eqxx.
by rewrite scale1r scalar_mx_block.
Qed.
Lemma mxtrace_prod m n (A :'M[F]_(m)) (B :'M[F]_(n)) :
\tr (tprod A B) = \tr A * \tr B.
Proof.
elim: m n A B => [|m IH] n A B //=.
by rewrite [A]flatmx0 mxtrace0 mul0r.
rewrite tprod_tr -block_mxEv mxtrace_block IH.
rewrite linearZ/= -mulrDl -trace_mx11; congr (_ * _).
pose A1 := A : 'M_(1 + m).
rewrite -[A in RHS](@submxK _ 1 m 1 m A1).
by rewrite (@mxtrace_block _ _ _ (ulsubmx A1)).
Qed.
End Tensor.
(* Representation sigma type and standard representations. *)
Section StandardRepresentation.
Variables (R : fieldType) (gT : finGroupType) (G : {group gT}).
Local Notation reprG := (mx_representation R G).
Record representation :=
Representation {rdegree; mx_repr_of_repr :> reprG rdegree}.
Lemma mx_repr0 : mx_repr G (fun _ : gT => 1%:M : 'M[R]_0).
Proof. by split=> // g h Hg Hx; rewrite mulmx1. Qed.
Definition grepr0 := Representation (MxRepresentation mx_repr0).
Lemma add_mx_repr (rG1 rG2 : representation) :
mx_repr G (fun g => block_mx (rG1 g) 0 0 (rG2 g)).
Proof.
split=> [|x y Hx Hy]; first by rewrite !repr_mx1 -scalar_mx_block.
by rewrite mulmx_block !(mulmx0, mul0mx, addr0, add0r, repr_mxM).
Qed.
Definition dadd_grepr rG1 rG2 :=
Representation (MxRepresentation (add_mx_repr rG1 rG2)).
Section DsumRepr.
Variables (n : nat) (rG : reprG n).
Lemma mx_rsim_dadd (U V W : 'M_n) (rU rV : representation)
(modU : mxmodule rG U) (modV : mxmodule rG V) (modW : mxmodule rG W) :
(U + V :=: W)%MS -> mxdirect (U + V) ->
mx_rsim (submod_repr modU) rU -> mx_rsim (submod_repr modV) rV ->
mx_rsim (submod_repr modW) (dadd_grepr rU rV).
Proof.
case: rU; case: rV=> nV rV nU rU defW dxUV /=.
have tiUV := mxdirect_addsP dxUV.
move=> [fU def_nU]; rewrite -{nU}def_nU in rU fU * => inv_fU hom_fU.
move=> [fV def_nV]; rewrite -{nV}def_nV in rV fV * => inv_fV hom_fV.
pose pU := in_submod U (proj_mx U V) *m fU.
pose pV := in_submod V (proj_mx V U) *m fV.
exists (val_submod 1%:M *m row_mx pU pV) => [||g Gg].
- by rewrite -defW (mxdirectP dxUV).
- apply/row_freeP.
pose pU' := invmx fU *m val_submod 1%:M.
pose pV' := invmx fV *m val_submod 1%:M.
exists (in_submod _ (col_mx pU' pV')).
rewrite in_submodE mulmxA -in_submodE -mulmxA mul_row_col mulmxDr.
rewrite -[pU *m _]mulmxA -[pV *m _]mulmxA !mulKVmx -?row_free_unit //.
rewrite addrC (in_submodE V) 2![val_submod 1%:M *m _]mulmxA -in_submodE.
rewrite addrC (in_submodE U) 2![val_submod 1%:M *m _ in X in X + _]mulmxA.
rewrite -in_submodE -!val_submodE !in_submodK ?proj_mx_sub //.
by rewrite add_proj_mx ?val_submodK // val_submod1 defW.
rewrite mulmxA -val_submodE -[submod_repr _ g]mul1mx val_submodJ //.
rewrite -(mulmxA _ (rG g)) mul_mx_row -[in RHS]mulmxA mul_row_block.
rewrite !mulmx0 addr0 add0r !mul_mx_row.
set W' := val_submod 1%:M; congr (row_mx _ _).
rewrite 3!mulmxA in_submodE mulmxA.
have hom_pU: (W' <= dom_hom_mx rG (proj_mx U V))%MS.
by rewrite val_submod1 -defW proj_mx_hom.
rewrite (hom_mxP hom_pU) // -in_submodE (in_submodJ modU) ?proj_mx_sub //.
rewrite -(mulmxA _ _ fU) hom_fU // in_submodE -2!(mulmxA W') -in_submodE.
by rewrite -mulmxA (mulmxA _ fU).
rewrite 3!mulmxA in_submodE mulmxA.
have hom_pV: (W' <= dom_hom_mx rG (proj_mx V U))%MS.
by rewrite val_submod1 -defW addsmxC proj_mx_hom // capmxC.
rewrite (hom_mxP hom_pV) // -in_submodE (in_submodJ modV) ?proj_mx_sub //.
rewrite -(mulmxA _ _ fV) hom_fV // in_submodE -2!(mulmxA W') -in_submodE.
by rewrite -mulmxA (mulmxA _ fV).
Qed.
Lemma mx_rsim_dsum (I : finType) (P : pred I) U rU (W : 'M_n)
(modU : forall i, mxmodule rG (U i)) (modW : mxmodule rG W) :
let S := (\sum_(i | P i) U i)%MS in (S :=: W)%MS -> mxdirect S ->
(forall i, mx_rsim (submod_repr (modU i)) (rU i : representation)) ->
mx_rsim (submod_repr modW) (\big[dadd_grepr/grepr0]_(i | P i) rU i).
Proof.
move=> /= defW dxW rsimU.
rewrite mxdirectE /= -!(big_filter _ P) in dxW defW *.
elim: {P}(filter P _) => [|i e IHe] in W modW dxW defW *.
rewrite !big_nil /= in defW *.
by exists 0 => [||? _]; rewrite ?mul0mx ?mulmx0 // /row_free -defW !mxrank0.
rewrite !big_cons /= in dxW defW *.
rewrite 2!(big_nth i) !big_mkord /= in IHe dxW defW.
set Wi := (\sum_i _)%MS in defW dxW IHe.
rewrite -mxdirectE mxdirect_addsE !mxdirectE eqxx /= -/Wi in dxW.
have modWi: mxmodule rG Wi by apply: sumsmx_module.
case/andP: dxW; move/(IHe Wi modWi) {IHe}; move/(_ (eqmx_refl _))=> rsimWi.
by move/eqP; move/mxdirect_addsP=> dxUiWi; apply: mx_rsim_dadd (rsimU i) rsimWi.
Qed.
Definition muln_grepr rW k := \big[dadd_grepr/grepr0]_(i < k) rW.
Lemma mx_rsim_socle (sG : socleType rG) (W : sG) (rW : representation) :
let modW : mxmodule rG W := component_mx_module rG (socle_base W) in
mx_rsim (socle_repr W) rW ->
mx_rsim (submod_repr modW) (muln_grepr rW (socle_mult W)).
Proof.
set M := socle_base W => modW rsimM.
have simM: mxsimple rG M := socle_simple W.
have rankM_gt0: (\rank M > 0)%N by rewrite lt0n mxrank_eq0; case: simM.
have [I /= U_I simU]: mxsemisimple rG W by apply: component_mx_semisimple.
pose U (i : 'I_#|I|) := U_I (enum_val i).
have reindexI := reindex _ (onW_bij I (enum_val_bij I)).
rewrite mxdirectE /= !reindexI -mxdirectE /= => defW dxW.
have isoU: forall i, mx_iso rG M (U i).
move=> i; have sUiW: (U i <= W)%MS by rewrite -defW (sumsmx_sup i).
exact: component_mx_iso (simU _) sUiW.
have ->: socle_mult W = #|I|.
rewrite -(mulnK #|I| rankM_gt0); congr (_ %/ _)%N.
rewrite -defW (mxdirectP dxW) /= -sum_nat_const reindexI /=.
by apply: eq_bigr => i _; rewrite -(mxrank_iso (isoU i)).
have modU: mxmodule rG (U _) := mxsimple_module (simU _).
suff: mx_rsim (submod_repr (modU _)) rW by apply: mx_rsim_dsum defW dxW.
by move=> i; apply: mx_rsim_trans (mx_rsim_sym _) rsimM; apply/mx_rsim_iso.
Qed.
End DsumRepr.
Section ProdRepr.
Variables (n1 n2 : nat) (rG1 : reprG n1) (rG2 : reprG n2).
Lemma prod_mx_repr : mx_repr G (fun g => tprod (rG1 g) (rG2 g)).
Proof.
split=>[|i j InG JnG]; first by rewrite !repr_mx1 tprod1.
by rewrite !repr_mxM // tprodE.
Qed.
Definition prod_repr := MxRepresentation prod_mx_repr.
End ProdRepr.
Lemma prod_repr_lin n2 (rG1 : reprG 1) (rG2 : reprG n2) :
{in G, forall x, let cast_n2 := esym (mul1n n2) in
prod_repr rG1 rG2 x = castmx (cast_n2, cast_n2) (rG1 x 0 0 *: rG2 x)}.
Proof.
move=> x Gx /=; set cast_n2 := esym _; rewrite /prod_repr /= !mxE !lshift0.
apply/matrixP=> i j; rewrite castmxE /=.
do 2![rewrite mxE; case: splitP => [? ? | []//]].
by congr ((_ *: rG2 x) _ _); apply: val_inj.
Qed.
End StandardRepresentation.
Arguments grepr0 {R gT G}.
Prenex Implicits dadd_grepr.
Section Char.
Variables (gT : finGroupType) (G : {group gT}).
Fact cfRepr_subproof n (rG : mx_representation algC G n) :
is_class_fun <<G>> [ffun x => \tr (rG x) *+ (x \in G)].
Proof.
rewrite genGid; apply: intro_class_fun => [x y Gx Gy | _ /negbTE-> //].
by rewrite groupJr // !repr_mxM ?groupM ?groupV // mxtrace_mulC repr_mxK.
Qed.
Definition cfRepr n rG := Cfun 0 (@cfRepr_subproof n rG).
Lemma cfRepr1 n rG : @cfRepr n rG 1%g = n%:R.
Proof. by rewrite cfunE group1 repr_mx1 mxtrace1. Qed.
Lemma cfRepr_sim n1 n2 rG1 rG2 :
mx_rsim rG1 rG2 -> @cfRepr n1 rG1 = @cfRepr n2 rG2.
Proof.
case/mx_rsim_def=> f12 [f21] fK def_rG1; apply/cfun_inP=> x Gx.
by rewrite !cfunE def_rG1 // mxtrace_mulC mulmxA fK mul1mx.
Qed.
Lemma cfRepr0 : cfRepr grepr0 = 0.
Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace1. Qed.
Lemma cfRepr_dadd rG1 rG2 :
cfRepr (dadd_grepr rG1 rG2) = cfRepr rG1 + cfRepr rG2.
Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx mxtrace_block. Qed.
Lemma cfRepr_dsum I r (P : pred I) rG :
cfRepr (\big[dadd_grepr/grepr0]_(i <- r | P i) rG i)
= \sum_(i <- r | P i) cfRepr (rG i).
Proof. exact: (big_morph _ cfRepr_dadd cfRepr0). Qed.
Lemma cfRepr_muln rG k : cfRepr (muln_grepr rG k) = cfRepr rG *+ k.
Proof. by rewrite cfRepr_dsum /= sumr_const card_ord. Qed.
Section StandardRepr.
Variables (n : nat) (rG : mx_representation algC G n).
Let sG := DecSocleType rG.
Let iG : irrType algC G := DecSocleType _.
Definition standard_irr (W : sG) := irr_comp iG (socle_repr W).
Definition standard_socle i := pick [pred W | standard_irr W == i].
Local Notation soc := standard_socle.
Definition standard_irr_coef i := oapp (fun W => socle_mult W) 0 (soc i).
Definition standard_grepr :=
\big[dadd_grepr/grepr0]_i
muln_grepr (Representation (socle_repr i)) (standard_irr_coef i).
Lemma mx_rsim_standard : mx_rsim rG standard_grepr.
Proof.
pose W i := oapp val 0 (soc i); pose S := (\sum_i W i)%MS.
have C'G: [pchar algC]^'.-group G := algC'G_pchar G.
have [defS dxS]: (S :=: 1%:M)%MS /\ mxdirect S.
rewrite /S mxdirectE /= !(bigID soc xpredT) /=.
rewrite addsmxC big1 => [|i]; last by rewrite /W; case (soc i).
rewrite adds0mx_id addnC (@big1 nat) ?add0n => [|i]; last first.
by rewrite /W; case: (soc i); rewrite ?mxrank0.
have <-: Socle sG = 1%:M := reducible_Socle1 sG (mx_Maschke_pchar rG C'G).
have [W0 _ | noW] := pickP sG; last first.
suff no_i: (soc : pred iG) =1 xpred0 by rewrite /Socle !big_pred0 ?mxrank0.
by move=> i; rewrite /soc; case: pickP => // W0; have:= noW W0.
have irrK Wi: soc (standard_irr Wi) = Some Wi.
rewrite /soc; case: pickP => [W' | /(_ Wi)] /= /eqP // eqWi.
apply/eqP/socle_rsimP.
apply: mx_rsim_trans
(rsim_irr_comp_pchar iG C'G (socle_irr _)) (mx_rsim_sym _).
by rewrite [irr_comp _ _]eqWi; apply: rsim_irr_comp_pchar (socle_irr _).
have bij_irr: {on [pred i | soc i], bijective standard_irr}.
exists (odflt W0 \o soc) => [Wi _ | i]; first by rewrite /= irrK.
by rewrite inE /soc /=; case: pickP => //= Wi; move/eqP.
rewrite !(reindex standard_irr) {bij_irr}//=.
have all_soc Wi: soc (standard_irr Wi) by rewrite irrK.
rewrite (eq_bigr val) => [|Wi _]; last by rewrite /W irrK.
rewrite !(eq_bigl _ _ all_soc); split=> //.
rewrite (eq_bigr (mxrank \o val)) => [|Wi _]; last by rewrite /W irrK.
by rewrite -mxdirectE /= Socle_direct.
pose modW i : mxmodule rG (W i) :=
if soc i is Some Wi as oWi return mxmodule rG (oapp val 0 oWi) then
component_mx_module rG (socle_base Wi)
else mxmodule0 rG n.
apply: mx_rsim_trans (mx_rsim_sym (rsim_submod1 (mxmodule1 rG) _)) _ => //.
apply: mx_rsim_dsum (modW) _ defS dxS _ => i.
rewrite /W /standard_irr_coef /modW /soc; case: pickP => [Wi|_] /=; last first.
rewrite /muln_grepr big_ord0.
by exists 0 => [||x _]; rewrite /row_free ?mxrank0 ?mulmx0 ?mul0mx.
move/eqP=> <-; apply: mx_rsim_socle.
exact: rsim_irr_comp_pchar (socle_irr Wi).
Qed.
End StandardRepr.
Definition cfReg (B : {set gT}) : 'CF(B) := #|B|%:R *: '1_[1].
Lemma cfRegE x : @cfReg G x = #|G|%:R *+ (x == 1%g).
Proof. by rewrite cfunE cfuniE ?normal1 // inE mulr_natr. Qed.
(* This is Isaacs, Lemma (2.10). *)
Lemma cfReprReg : cfRepr (regular_repr algC G) = cfReg G.
Proof.
apply/cfun_inP=> x Gx; rewrite cfRegE.
have [-> | ntx] := eqVneq x 1%g; first by rewrite cfRepr1.
rewrite cfunE Gx [\tr _]big1 // => i _; rewrite 2!mxE /=.
rewrite -(inj_eq enum_val_inj) gring_indexK ?groupM ?enum_valP //.
by rewrite eq_mulVg1 mulKg (negbTE ntx).
Qed.
Definition xcfun (chi : 'CF(G)) A :=
(gring_row A *m (\col_(i < #|G|) chi (enum_val i))) 0 0.
Lemma xcfun_is_zmod_morphism phi : zmod_morphism (xcfun phi).
Proof. by move=> A B; rewrite /xcfun [gring_row _]linearB mulmxBl !mxE. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `xcfun_is_zmod_morphism` instead")]
Definition xcfun_is_additive := xcfun_is_zmod_morphism.
HB.instance Definition _ phi :=
GRing.isZmodMorphism.Build 'M_(gcard G) _ (xcfun phi) (xcfun_is_zmod_morphism phi).
Lemma xcfunZr a phi A : xcfun phi (a *: A) = a * xcfun phi A.
Proof. by rewrite /xcfun linearZ -scalemxAl mxE. Qed.
(* In order to add a second canonical structure on xcfun *)
Definition xcfun_r A phi := xcfun phi A.
Arguments xcfun_r A phi /.
Lemma xcfun_rE A chi : xcfun_r A chi = xcfun chi A. Proof. by []. Qed.
Fact xcfun_r_is_zmod_morphism A : zmod_morphism (xcfun_r A).
Proof.
move=> phi psi; rewrite /= /xcfun !mxE -sumrB; apply: eq_bigr => i _.
by rewrite !mxE !cfunE mulrBr.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `xcfun_r_is_zmod_morphism` instead")]
Definition xcfun_r_is_additive := xcfun_r_is_zmod_morphism.
HB.instance Definition _ A := GRing.isZmodMorphism.Build _ _ (xcfun_r A)
(xcfun_r_is_zmod_morphism A).
Lemma xcfunZl a phi A : xcfun (a *: phi) A = a * xcfun phi A.
Proof.
rewrite /xcfun !mxE big_distrr; apply: eq_bigr => i _ /=.
by rewrite !mxE cfunE mulrCA.
Qed.
Lemma xcfun_repr n rG A : xcfun (@cfRepr n rG) A = \tr (gring_op rG A).
Proof.
rewrite gring_opE [gring_row A]row_sum_delta !linear_sum /xcfun !mxE.
apply: eq_bigr => i _; rewrite !mxE /= !linearZ cfunE enum_valP /=.
by congr (_ * \tr _); rewrite {A}/gring_mx /= -rowE rowK mxvecK.
Qed.
End Char.
Arguments xcfun_r {_ _} A phi /.
Notation "phi .[ A ]" := (xcfun phi A) : cfun_scope.
Definition pred_Nirr gT B := #|@classes gT B|.-1.
Arguments pred_Nirr {gT} B%_g.
Notation Nirr G := (pred_Nirr G).+1.
Notation Iirr G := 'I_(Nirr G).
Section IrrClassDef.
Variables (gT : finGroupType) (G : {group gT}).
Let sG := DecSocleType (regular_repr algC G).
Lemma NirrE : Nirr G = #|classes G|.
Proof. by rewrite /pred_Nirr (cardD1 [1]) classes1. Qed.
Fact Iirr_cast : Nirr G = #|sG|.
Proof. by rewrite NirrE ?card_irr_pchar ?algC'G_pchar //; apply: groupC. Qed.
Let offset := cast_ord (esym Iirr_cast) (enum_rank [1 sG]%irr).
Definition socle_of_Iirr (i : Iirr G) : sG :=
enum_val (cast_ord Iirr_cast (i + offset)).
Definition irr_of_socle (Wi : sG) : Iirr G :=
cast_ord (esym Iirr_cast) (enum_rank Wi) - offset.
Local Notation W := socle_of_Iirr.
Lemma socle_Iirr0 : W 0 = [1 sG]%irr.
Proof. by rewrite /W add0r cast_ordKV enum_rankK. Qed.
Lemma socle_of_IirrK : cancel W irr_of_socle.
Proof. by move=> i; rewrite /irr_of_socle enum_valK cast_ordK addrK. Qed.
Lemma irr_of_socleK : cancel irr_of_socle W.
Proof. by move=> Wi; rewrite /W subrK cast_ordKV enum_rankK. Qed.
Hint Resolve socle_of_IirrK irr_of_socleK : core.
Lemma irr_of_socle_bij (A : {pred (Iirr G)}) : {on A, bijective irr_of_socle}.
Proof. by apply: onW_bij; exists W. Qed.
Lemma socle_of_Iirr_bij (A : {pred sG}) : {on A, bijective W}.
Proof. by apply: onW_bij; exists irr_of_socle. Qed.
End IrrClassDef.
Prenex Implicits socle_of_IirrK irr_of_socleK.
Arguments socle_of_Iirr {gT G%_G} i%_R.
Notation "''Chi_' i" := (irr_repr (socle_of_Iirr i))
(at level 8, i at level 2, format "''Chi_' i").
HB.lock Definition irr gT B : (Nirr B).-tuple 'CF(B) :=
let irr_of i := 'Res[B, <<B>>] (@cfRepr gT _ _ 'Chi_(inord i)) in
[tuple of mkseq irr_of (Nirr B)].
Arguments irr {gT} B%_g.
Notation "''chi_' i" := (tnth (irr _) i%R)
(at level 8, i at level 2, format "''chi_' i") : ring_scope.
Notation "''chi[' G ]_ i" := (tnth (irr G) i%R)
(at level 8, i at level 2, only parsing) : ring_scope.
Section IrrClass.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (i : Iirr G) (B : {set gT}).
Open Scope group_ring_scope.
Lemma congr_irr i1 i2 : i1 = i2 -> 'chi_i1 = 'chi_i2. Proof. by move->. Qed.
Lemma Iirr1_neq0 : G :!=: 1%g -> inord 1 != 0 :> Iirr G.
Proof. by rewrite -classes_gt1 -NirrE -val_eqE /= => /inordK->. Qed.
Lemma has_nonprincipal_irr : G :!=: 1%g -> {i : Iirr G | i != 0}.
Proof. by move/Iirr1_neq0; exists (inord 1). Qed.
Lemma irrRepr i : cfRepr 'Chi_i = 'chi_i.
Proof.
rewrite irr.unlock (tnth_nth 0) nth_mkseq // -[<<G>>]/(gval _) genGidG.
by rewrite cfRes_id inord_val.
Qed.
Lemma irr0 : 'chi[G]_0 = 1.
Proof.
apply/cfun_inP=> x Gx; rewrite -irrRepr cfun1E cfunE Gx.
by rewrite socle_Iirr0 irr1_repr // mxtrace1 degree_irr1.
Qed.
Lemma cfun1_irr : 1 \in irr G.
Proof. by rewrite -irr0 mem_tnth. Qed.
Lemma mem_irr i : 'chi_i \in irr G.
Proof. exact: mem_tnth. Qed.
Lemma irrP xi : reflect (exists i, xi = 'chi_i) (xi \in irr G).
Proof.
apply: (iffP idP) => [/(nthP 0)[i] | [i ->]]; last exact: mem_irr.
rewrite size_tuple => lt_i_G <-.
by exists (Ordinal lt_i_G); rewrite (tnth_nth 0).
Qed.
Let sG := DecSocleType (regular_repr algC G).
Let C'G := algC'G_pchar G.
Let closG := @groupC _ G.
Local Notation W i := (@socle_of_Iirr _ G i).
Local Notation "''n_' i" := 'n_(W i).
Local Notation "''R_' i" := 'R_(W i).
Local Notation "''e_' i" := 'e_(W i).
Lemma irr1_degree i : 'chi_i 1%g = ('n_i)%:R.
Proof. by rewrite -irrRepr cfRepr1. Qed.
Lemma Cnat_irr1 i : 'chi_i 1%g \in Num.nat.
Proof. by rewrite irr1_degree rpred_nat. Qed.
Lemma irr1_gt0 i : 0 < 'chi_i 1%g.
Proof. by rewrite irr1_degree ltr0n irr_degree_gt0. Qed.
Lemma irr1_neq0 i : 'chi_i 1%g != 0.
Proof. by rewrite eq_le lt_geF ?irr1_gt0. Qed.
Lemma irr_neq0 i : 'chi_i != 0.
Proof. by apply: contraNneq (irr1_neq0 i) => ->; rewrite cfunE. Qed.
Local Remark cfIirr_key : unit. Proof. by []. Qed.
Definition cfIirr : forall B, 'CF(B) -> Iirr B :=
locked_with cfIirr_key (fun B chi => inord (index chi (irr B))).
Lemma cfIirrE chi : chi \in irr G -> 'chi_(cfIirr chi) = chi.
Proof.
move=> chi_irr; rewrite (tnth_nth 0) [cfIirr]unlock inordK ?nth_index //.
by rewrite -index_mem size_tuple in chi_irr.
Qed.
Lemma cfIirrPE J (f : J -> 'CF(G)) (P : pred J) :
(forall j, P j -> f j \in irr G) ->
forall j, P j -> 'chi_(cfIirr (f j)) = f j.
Proof. by move=> irr_f j /irr_f; apply: cfIirrE. Qed.
(* This is Isaacs, Corollary (2.7). *)
Corollary irr_sum_square : \sum_i ('chi[G]_i 1%g) ^+ 2 = #|G|%:R.
Proof.
rewrite -(sum_irr_degree_pchar sG) // natr_sum.
rewrite (reindex _ (socle_of_Iirr_bij _)) /=.
by apply: eq_bigr => i _; rewrite irr1_degree natrX.
Qed.
(* This is Isaacs, Lemma (2.11). *)
Lemma cfReg_sum : cfReg G = \sum_i 'chi_i 1%g *: 'chi_i.
Proof.
apply/cfun_inP=> x Gx.
rewrite -cfReprReg cfunE Gx (mxtrace_regular_pchar sG) //=.
rewrite sum_cfunE (reindex _ (socle_of_Iirr_bij _)); apply: eq_bigr => i _.
by rewrite -irrRepr cfRepr1 !cfunE Gx mulr_natl.
Qed.
Let aG := regular_repr algC G.
Let R_G := group_ring algC G.
Lemma xcfun_annihilate i j A : i != j -> (A \in 'R_j)%MS -> ('chi_i).[A]%CF = 0.
Proof.
move=> neq_ij RjA; rewrite -irrRepr xcfun_repr.
rewrite (irr_repr'_op0_pchar _ _ RjA) ?raddf0 //.
by rewrite eq_sym (can_eq socle_of_IirrK).
Qed.
Lemma xcfunG phi x : x \in G -> phi.[aG x]%CF = phi x.
Proof.
by move=> Gx; rewrite /xcfun /gring_row rowK -rowE !mxE !(gring_indexK, mul1g).
Qed.
Lemma xcfun_mul_id i A :
(A \in R_G)%MS -> ('chi_i).['e_i *m A]%CF = ('chi_i).[A]%CF.
Proof.
move=> RG_A; rewrite -irrRepr !xcfun_repr gring_opM //.
by rewrite op_Wedderburn_id_pchar ?mul1mx.
Qed.
Lemma xcfun_id i j : ('chi_i).['e_j]%CF = 'chi_i 1%g *+ (i == j).
Proof.
have [<-{j} | /xcfun_annihilate->//] := eqVneq; last exact: Wedderburn_id_mem.
by rewrite -xcfunG // repr_mx1 -(xcfun_mul_id _ (envelop_mx1 _)) mulmx1.
Qed.
Lemma irr_free : free (irr G).
Proof.
apply/freeP=> s s0 i; apply: (mulIf (irr1_neq0 i)).
rewrite mul0r -(raddf0 (xcfun_r 'e_i)) -{}s0 raddf_sum /=.
rewrite (bigD1 i)//= -tnth_nth xcfunZl xcfun_id eqxx big1 ?addr0 // => j ne_ji.
by rewrite -tnth_nth xcfunZl xcfun_id (negbTE ne_ji) mulr0.
Qed.
Lemma irr_inj : injective (tnth (irr G)).
Proof. by apply/injectiveP/free_uniq; rewrite map_tnth_enum irr_free. Qed.
Lemma irrK : cancel (tnth (irr G)) (@cfIirr G).
Proof. by move=> i; apply: irr_inj; rewrite cfIirrE ?mem_irr. Qed.
Lemma irr_eq1 i : ('chi_i == 1) = (i == 0).
Proof. by rewrite -irr0 (inj_eq irr_inj). Qed.
Lemma cforder_irr_eq1 i : (#['chi_i]%CF == 1) = (i == 0).
Proof. by rewrite -dvdn1 dvdn_cforder irr_eq1. Qed.
Lemma irr_basis : basis_of 'CF(G)%VS (irr G).
Proof.
rewrite /basis_of irr_free andbT -dimv_leqif_eq ?subvf //.
by rewrite dim_cfun (eqnP irr_free) size_tuple NirrE.
Qed.
Lemma eq_sum_nth_irr a : \sum_i a i *: 'chi[G]_i = \sum_i a i *: (irr G)`_i.
Proof. by apply: eq_bigr => i; rewrite -tnth_nth. Qed.
(* This is Isaacs, Theorem (2.8). *)
Theorem cfun_irr_sum phi : {a | phi = \sum_i a i *: 'chi[G]_i}.
Proof.
rewrite (coord_basis irr_basis (memvf phi)) -eq_sum_nth_irr.
by exists ((coord (irr G))^~ phi).
Qed.
Lemma cfRepr_standard n (rG : mx_representation algC G n) :
cfRepr (standard_grepr rG)
= \sum_i (standard_irr_coef rG (W i))%:R *: 'chi_i.
Proof.
rewrite cfRepr_dsum (reindex _ (socle_of_Iirr_bij _)).
by apply: eq_bigr => i _; rewrite scaler_nat cfRepr_muln irrRepr.
Qed.
Lemma cfRepr_inj n1 n2 rG1 rG2 :
@cfRepr _ G n1 rG1 = @cfRepr _ G n2 rG2 -> mx_rsim rG1 rG2.
Proof.
move=> eq_repr12; pose c i : algC := (standard_irr_coef _ (W i))%:R.
have [rsim1 rsim2] := (mx_rsim_standard rG1, mx_rsim_standard rG2).
apply: mx_rsim_trans (rsim1) (mx_rsim_sym _).
suffices ->: standard_grepr rG1 = standard_grepr rG2 by [].
apply: eq_bigr => Wi _; congr (muln_grepr _ _); apply/eqP; rewrite -eqC_nat.
rewrite -[Wi]irr_of_socleK -!/(c _ _ _) -!(coord_sum_free (c _ _) _ irr_free).
rewrite -!eq_sum_nth_irr -!cfRepr_standard.
by rewrite -(cfRepr_sim rsim1) -(cfRepr_sim rsim2) eq_repr12.
Qed.
Lemma cfRepr_rsimP n1 n2 rG1 rG2 :
reflect (mx_rsim rG1 rG2) (@cfRepr _ G n1 rG1 == @cfRepr _ G n2 rG2).
Proof. by apply: (iffP eqP) => [/cfRepr_inj | /cfRepr_sim]. Qed.
Lemma irr_reprP xi :
reflect (exists2 rG : representation _ G, mx_irreducible rG & xi = cfRepr rG)
(xi \in irr G).
Proof.
apply: (iffP (irrP xi)) => [[i ->] | [[n rG] irr_rG ->]].
by exists (Representation 'Chi_i); [apply: socle_irr | rewrite irrRepr].
exists (irr_of_socle (irr_comp sG rG)); rewrite -irrRepr irr_of_socleK /=.
exact/cfRepr_sim/rsim_irr_comp_pchar.
Qed.
(* This is Isaacs, Theorem (2.12). *)
Lemma Wedderburn_id_expansion i :
'e_i = #|G|%:R^-1 *: (\sum_(x in G) 'chi_i 1%g * 'chi_i x^-1%g *: aG x).
Proof.
have Rei: ('e_i \in 'R_i)%MS by apply: Wedderburn_id_mem.
have /envelop_mxP[a def_e]: ('e_i \in R_G)%MS; last rewrite -/aG in def_e.
by move: Rei; rewrite genmxE mem_sub_gring => /andP[].
apply: canRL (scalerK (neq0CG _)) _; rewrite def_e linear_sum /=.
apply: eq_bigr => x Gx; have Gx' := groupVr Gx; rewrite scalerA; congr (_ *: _).
transitivity (cfReg G).['e_i *m aG x^-1%g]%CF.
rewrite def_e mulmx_suml raddf_sum (bigD1 x) //= -scalemxAl xcfunZr.
rewrite -repr_mxM // mulgV xcfunG // cfRegE eqxx mulrC big1 ?addr0 //.
move=> y /andP[Gy /negbTE neq_xy]; rewrite -scalemxAl xcfunZr -repr_mxM //.
by rewrite xcfunG ?groupM // cfRegE -eq_mulgV1 neq_xy mulr0.
rewrite cfReg_sum -xcfun_rE raddf_sum /= (bigD1 i) //= xcfunZl.
rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG ?groupV ?big1 ?addr0 // => j ne_ji.
rewrite xcfunZl (xcfun_annihilate ne_ji) ?mulr0 //.
have /andP[_ /(submx_trans _)-> //] := Wedderburn_ideal (W i).
by rewrite mem_mulsmx // envelop_mx_id ?groupV.
Qed.
End IrrClass.
Arguments cfReg {gT} B%_g.
Prenex Implicits cfIirr irrK.
Arguments irrP {gT G xi}.
Arguments irr_reprP {gT G xi}.
Arguments irr_inj {gT G} [x1 x2].
Section IsChar.
Variable gT : finGroupType.
Definition character_pred {G : {set gT}} :=
fun phi : 'CF(G) => [forall i, coord (irr G) i phi \in Num.nat].
Arguments character_pred _ _ /.
Definition character {G : {set gT}} := [qualify a phi | @character_pred G phi].
Variable G : {group gT}.
Implicit Types (phi chi xi : 'CF(G)) (i : Iirr G).
Lemma irr_char i : 'chi_i \is a character.
Proof. by apply/forallP=> j; rewrite (tnth_nth 0) coord_free ?irr_free. Qed.
Lemma cfun1_char : (1 : 'CF(G)) \is a character.
Proof. by rewrite -irr0 irr_char. Qed.
Lemma cfun0_char : (0 : 'CF(G)) \is a character.
Proof. by apply/forallP=> i; rewrite linear0 rpred0. Qed.
Fact add_char : addr_closed (@character G).
Proof.
split=> [|chi xi /forallP-Nchi /forallP-Nxi]; first exact: cfun0_char.
by apply/forallP=> i; rewrite linearD rpredD /=.
Qed.
HB.instance Definition _ := GRing.isAddClosed.Build (classfun G) character_pred
add_char.
Lemma char_sum_irrP {phi} :
reflect (exists n, phi = \sum_i (n i)%:R *: 'chi_i) (phi \is a character).
Proof.
apply: (iffP idP)=> [/forallP-Nphi | [n ->]]; last first.
by apply: rpred_sum => i _; rewrite scaler_nat rpredMn // irr_char.
do [have [a ->] := cfun_irr_sum phi] in Nphi *; exists (Num.truncn \o a).
apply: eq_bigr => i _; congr (_ *: _); have:= eqP (Nphi i).
by rewrite eq_sum_nth_irr coord_sum_free ?irr_free.
Qed.
Lemma char_sum_irr chi :
chi \is a character -> {r | chi = \sum_(i <- r) 'chi_i}.
Proof.
move=> Nchi; apply: sig_eqW; case/char_sum_irrP: Nchi => n {chi}->.
elim/big_rec: _ => [|i _ _ [r ->]]; first by exists nil; rewrite big_nil.
exists (ncons (n i) i r); rewrite scaler_nat.
by elim: {n}(n i) => [|n IHn]; rewrite ?add0r //= big_cons mulrS -addrA IHn.
Qed.
Lemma Cnat_char1 chi : chi \is a character -> chi 1%g \in Num.nat.
Proof.
case/char_sum_irr=> r ->{chi}.
by elim/big_rec: _ => [|i chi _ Nchi1]; rewrite cfunE ?rpredD // Cnat_irr1.
Qed.
Lemma char1_ge0 chi : chi \is a character -> 0 <= chi 1%g.
Proof. by move/Cnat_char1/natr_ge0. Qed.
Lemma char1_eq0 chi : chi \is a character -> (chi 1%g == 0) = (chi == 0).
Proof.
case/char_sum_irr=> r ->; apply/idP/idP=> [|/eqP->]; last by rewrite cfunE.
case: r => [|i r]; rewrite ?big_nil // sum_cfunE big_cons.
rewrite paddr_eq0 ?sumr_ge0 => // [||j _]; rewrite 1?ltW ?irr1_gt0 //.
by rewrite (negbTE (irr1_neq0 i)).
Qed.
Lemma char1_gt0 chi : chi \is a character -> (0 < chi 1%g) = (chi != 0).
Proof. by move=> Nchi; rewrite -char1_eq0 // natr_gt0 ?Cnat_char1. Qed.
Lemma char_reprP phi :
reflect (exists rG : representation algC G, phi = cfRepr rG)
(phi \is a character).
Proof.
apply: (iffP char_sum_irrP) => [[n ->] | [[n rG] ->]]; last first.
exists (fun i => standard_irr_coef rG (socle_of_Iirr i)).
by rewrite -cfRepr_standard (cfRepr_sim (mx_rsim_standard rG)).
exists (\big[dadd_grepr/grepr0]_i muln_grepr (Representation 'Chi_i) (n i)).
rewrite cfRepr_dsum; apply: eq_bigr => i _.
by rewrite cfRepr_muln irrRepr scaler_nat.
Qed.
Local Notation reprG := (mx_representation algC G).
Lemma cfRepr_char n (rG : reprG n) : cfRepr rG \is a character.
Proof. by apply/char_reprP; exists (Representation rG). Qed.
Lemma cfReg_char : cfReg G \is a character.
Proof. by rewrite -cfReprReg cfRepr_char. Qed.
Lemma cfRepr_prod n1 n2 (rG1 : reprG n1) (rG2 : reprG n2) :
cfRepr rG1 * cfRepr rG2 = cfRepr (prod_repr rG1 rG2).
Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE /= Gx mxtrace_prod. Qed.
Lemma mul_char : mulr_closed (@character G).
Proof.
split=> [|_ _ /char_reprP[rG1 ->] /char_reprP[rG2 ->]]; first exact: cfun1_char.
apply/char_reprP; exists (Representation (prod_repr rG1 rG2)).
by rewrite cfRepr_prod.
Qed.
HB.instance Definition _ := GRing.isMulClosed.Build (classfun G) character_pred
mul_char.
End IsChar.
Prenex Implicits character.
Arguments character_pred _ _ _ /.
Arguments char_reprP {gT G phi}.
Section AutChar.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Type u : {rmorphism algC -> algC}.
Implicit Type chi : 'CF(G).
Lemma cfRepr_map u n (rG : mx_representation algC G n) :
cfRepr (map_repr u rG) = cfAut u (cfRepr rG).
Proof. by apply/cfun_inP=> x Gx; rewrite !cfunE Gx map_reprE trace_map_mx. Qed.
Lemma cfAut_char u chi : (cfAut u chi \is a character) = (chi \is a character).
Proof.
without loss /char_reprP[rG ->]: u chi / chi \is a character.
by move=> IHu; apply/idP/idP=> ?; first rewrite -(cfAutK u chi); rewrite IHu.
rewrite cfRepr_char; apply/char_reprP.
by exists (Representation (map_repr u rG)); rewrite cfRepr_map.
Qed.
Lemma cfConjC_char chi : (chi^*%CF \is a character) = (chi \is a character).
Proof. exact: cfAut_char. Qed.
Lemma cfAut_char1 u (chi : 'CF(G)) :
chi \is a character -> cfAut u chi 1%g = chi 1%g.
Proof. by move/Cnat_char1=> Nchi1; rewrite cfunE /= aut_natr. Qed.
Lemma cfAut_irr1 u i : (cfAut u 'chi[G]_i) 1%g = 'chi_i 1%g.
Proof. exact: cfAut_char1 (irr_char i). Qed.
Lemma cfConjC_char1 (chi : 'CF(G)) :
chi \is a character -> chi^*%CF 1%g = chi 1%g.
Proof. exact: cfAut_char1. Qed.
Lemma cfConjC_irr1 u i : ('chi[G]_i)^*%CF 1%g = 'chi_i 1%g.
Proof. exact: cfAut_irr1. Qed.
End AutChar.
Section Linear.
Variables (gT : finGroupType) (G : {group gT}).
Definition linear_char_pred {B : {set gT}} :=
fun phi : 'CF(B) => (phi \is a character) && (phi 1%g == 1).
Arguments linear_char_pred _ _ /.
Definition linear_char {B : {set gT}} :=
[qualify a phi | @linear_char_pred B phi].
Section OneChar.
Variable xi : 'CF(G).
Hypothesis CFxi : xi \is a linear_char.
Lemma lin_char1: xi 1%g = 1.
Proof. by case/andP: CFxi => _ /eqP. Qed.
Lemma lin_charW : xi \is a character.
Proof. by case/andP: CFxi. Qed.
Lemma cfun1_lin_char : (1 : 'CF(G)) \is a linear_char.
Proof. by rewrite qualifE/= cfun1_char /= cfun11. Qed.
Lemma lin_charM : {in G &, {morph xi : x y / (x * y)%g >-> x * y}}.
Proof.
move=> x y Gx Gy; case/andP: CFxi => /char_reprP[[n rG] -> /=].
rewrite cfRepr1 pnatr_eq1 => /eqP n1; rewrite {n}n1 in rG *.
rewrite !cfunE Gx Gy groupM //= !mulr1n repr_mxM //.
by rewrite [rG x]mx11_scalar [rG y]mx11_scalar -scalar_mxM !mxtrace_scalar.
Qed.
Lemma lin_char_prod I r (P : pred I) (x : I -> gT) :
(forall i, P i -> x i \in G) ->
xi (\prod_(i <- r | P i) x i)%g = \prod_(i <- r | P i) xi (x i).
Proof.
move=> Gx; elim/(big_load (fun y => y \in G)): _.
elim/big_rec2: _ => [|i a y Pi [Gy <-]]; first by rewrite lin_char1.
by rewrite groupM ?lin_charM ?Gx.
Qed.
Let xiMV x : x \in G -> xi x * xi (x^-1)%g = 1.
Proof. by move=> Gx; rewrite -lin_charM ?groupV // mulgV lin_char1. Qed.
Lemma lin_char_neq0 x : x \in G -> xi x != 0.
Proof.
by move/xiMV/(congr1 (predC1 0)); rewrite /= oner_eq0 mulf_eq0 => /norP[].
Qed.
Lemma lin_charV x : x \in G -> xi x^-1%g = (xi x)^-1.
Proof. by move=> Gx; rewrite -[_^-1]mulr1 -(xiMV Gx) mulKf ?lin_char_neq0. Qed.
Lemma lin_charX x n : x \in G -> xi (x ^+ n)%g = xi x ^+ n.
Proof.
move=> Gx; elim: n => [|n IHn]; first exact: lin_char1.
by rewrite expgS exprS lin_charM ?groupX ?IHn.
Qed.
Lemma lin_char_unity_root x : x \in G -> xi x ^+ #[x] = 1.
Proof. by move=> Gx; rewrite -lin_charX // expg_order lin_char1. Qed.
Lemma normC_lin_char x : x \in G -> `|xi x| = 1.
Proof.
move=> Gx; apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) //.
by rewrite -normrX // lin_char_unity_root ?normr1.
Qed.
Lemma lin_charV_conj x : x \in G -> xi x^-1%g = (xi x)^*.
Proof.
move=> Gx; rewrite lin_charV // invC_norm mulrC normC_lin_char //.
by rewrite expr1n divr1.
Qed.
Lemma lin_char_irr : xi \in irr G.
Proof.
case/andP: CFxi => /char_reprP[rG ->]; rewrite cfRepr1 pnatr_eq1 => /eqP n1.
by apply/irr_reprP; exists rG => //; apply/mx_abs_irrW/linear_mx_abs_irr.
Qed.
Lemma mul_conjC_lin_char : xi * xi^*%CF = 1.
Proof.
apply/cfun_inP=> x Gx.
by rewrite !cfunE cfun1E Gx -normCK normC_lin_char ?expr1n.
Qed.
Lemma lin_char_unitr : xi \in GRing.unit.
Proof. by apply/unitrPr; exists xi^*%CF; apply: mul_conjC_lin_char. Qed.
Lemma invr_lin_char : xi^-1 = xi^*%CF.
Proof. by rewrite -[_^-1]mulr1 -mul_conjC_lin_char mulKr ?lin_char_unitr. Qed.
Lemma fful_lin_char_inj : cfaithful xi -> {in G &, injective xi}.
Proof.
move=> fful_phi x y Gx Gy xi_xy; apply/eqP; rewrite eq_mulgV1 -in_set1.
rewrite (subsetP fful_phi) // inE groupM ?groupV //=; apply/forallP=> z.
have [Gz | G'z] := boolP (z \in G); last by rewrite !cfun0 ?groupMl ?groupV.
by rewrite -mulgA lin_charM ?xi_xy -?lin_charM ?groupM ?groupV // mulKVg.
Qed.
End OneChar.
Lemma cfAut_lin_char u (xi : 'CF(G)) :
(cfAut u xi \is a linear_char) = (xi \is a linear_char).
Proof. by rewrite qualifE/= cfAut_char; apply/andb_id2l=> /cfAut_char1->. Qed.
Lemma cfConjC_lin_char (xi : 'CF(G)) :
(xi^*%CF \is a linear_char) = (xi \is a linear_char).
Proof. exact: cfAut_lin_char. Qed.
Lemma card_Iirr_abelian : abelian G -> #|Iirr G| = #|G|.
Proof. by rewrite card_ord NirrE card_classes_abelian => /eqP. Qed.
Lemma card_Iirr_cyclic : cyclic G -> #|Iirr G| = #|G|.
Proof. by move/cyclic_abelian/card_Iirr_abelian. Qed.
Lemma char_abelianP :
reflect (forall i : Iirr G, 'chi_i \is a linear_char) (abelian G).
Proof.
apply: (iffP idP) => [cGG i | CF_G].
rewrite qualifE/= irr_char /= irr1_degree.
by rewrite irr_degree_abelian //; last apply: groupC.
rewrite card_classes_abelian -NirrE -eqC_nat -irr_sum_square //.
rewrite -{1}[Nirr G]card_ord -sumr_const; apply/eqP/eq_bigr=> i _.
by rewrite lin_char1 ?expr1n ?CF_G.
Qed.
Lemma irr_repr_lin_char (i : Iirr G) x :
x \in G -> 'chi_i \is a linear_char ->
irr_repr (socle_of_Iirr i) x = ('chi_i x)%:M.
Proof.
move=> Gx CFi; rewrite -irrRepr cfunE Gx.
move: (_ x); rewrite -[irr_degree _](@natrK algC) -irr1_degree lin_char1 //.
by rewrite (natrK 1) => A; rewrite trace_mx11 -mx11_scalar.
Qed.
Fact linear_char_divr : divr_closed (@linear_char G).
Proof.
split=> [|chi xi Lchi Lxi]; first exact: cfun1_lin_char.
rewrite invr_lin_char // qualifE/= cfunE.
by rewrite rpredM ?lin_char1 ?mulr1 ?lin_charW //= cfConjC_lin_char.
Qed.
HB.instance Definition _ :=
GRing.isDivClosed.Build (classfun G) linear_char_pred linear_char_divr.
Lemma irr_cyclic_lin i : cyclic G -> 'chi[G]_i \is a linear_char.
Proof. by move/cyclic_abelian/char_abelianP. Qed.
Lemma irr_prime_lin i : prime #|G| -> 'chi[G]_i \is a linear_char.
Proof. by move/prime_cyclic/irr_cyclic_lin. Qed.
End Linear.
Prenex Implicits linear_char.
Arguments linear_char_pred _ _ _ /.
Section OrthogonalityRelations.
Variables aT gT : finGroupType.
(* This is Isaacs, Lemma (2.15) *)
Lemma repr_rsim_diag (G : {group gT}) f (rG : mx_representation algC G f) x :
x \in G -> let chi := cfRepr rG in
exists e,
[/\ (*a*) exists2 B, B \in unitmx & rG x = invmx B *m diag_mx e *m B,
(*b*) (forall i, e 0 i ^+ #[x] = 1) /\ (forall i, `|e 0 i| = 1),
(*c*) chi x = \sum_i e 0 i /\ `|chi x| <= chi 1%g
& (*d*) chi x^-1%g = (chi x)^*].
Proof.
move=> Gx; without loss cGG: G rG Gx / abelian G.
have sXG: <[x]> \subset G by rewrite cycle_subG.
move/(_ _ (subg_repr rG sXG) (cycle_id x) (cycle_abelian x)).
by rewrite /= !cfunE !groupV Gx (cycle_id x) !group1.
have [I U W simU W1 dxW]: mxsemisimple rG 1%:M.
rewrite -(reducible_Socle1 (DecSocleType rG)
(mx_Maschke_pchar _ (algC'G_pchar G))).
exact: Socle_semisimple.
have linU i: \rank (U i) = 1.
by apply: mxsimple_abelian_linear cGG (simU i); apply: groupC.
have castI: f = #|I|.
by rewrite -(mxrank1 algC f) -W1 (eqnP dxW) /= -sum1_card; apply/eq_bigr.
pose B := \matrix_j nz_row (U (enum_val (cast_ord castI j))).
have rowU i: (nz_row (U i) :=: U i)%MS.
apply/eqmxP; rewrite -(geq_leqif (mxrank_leqif_eq (nz_row_sub _))) linU.
by rewrite lt0n mxrank_eq0 (nz_row_mxsimple (simU i)).
have unitB: B \in unitmx.
rewrite -row_full_unit -sub1mx -W1; apply/sumsmx_subP=> i _.
pose j := cast_ord (esym castI) (enum_rank i).
by rewrite (submx_trans _ (row_sub j B)) // rowK cast_ordKV enum_rankK rowU.
pose e := \row_j row j (B *m rG x *m invmx B) 0 j.
have rGx: rG x = invmx B *m diag_mx e *m B.
rewrite -mulmxA; apply: canRL (mulKmx unitB) _.
apply/row_matrixP=> j; rewrite 2!row_mul; set u := row j B.
have /sub_rVP[a def_ux]: (u *m rG x <= u)%MS.
rewrite /u rowK rowU (eqmxMr _ (rowU _)).
exact: (mxmoduleP (mxsimple_module (simU _))).
rewrite def_ux [u]rowE scalemxAl; congr (_ *m _).
apply/rowP=> k; rewrite 5!mxE !row_mul def_ux [u]rowE scalemxAl mulmxK //.
by rewrite !mxE !eqxx !mulr_natr eq_sym.
have exp_e j: e 0 j ^+ #[x] = 1.
suffices: (diag_mx e j j) ^+ #[x] = (B *m rG (x ^+ #[x])%g *m invmx B) j j.
by rewrite expg_order repr_mx1 mulmx1 mulmxV // [e]lock !mxE eqxx.
elim: #[x] => [|n IHn]; first by rewrite repr_mx1 mulmx1 mulmxV // !mxE eqxx.
rewrite expgS repr_mxM ?groupX // {1}rGx -!mulmxA mulKVmx //.
by rewrite mul_diag_mx mulmxA [M in _ = M]mxE -IHn exprS {1}mxE eqxx.
have norm1_e j: `|e 0 j| = 1.
by apply/eqP; rewrite -(@pexpr_eq1 _ _ #[x]) // -normrX exp_e normr1.
exists e; split=> //; first by exists B.
rewrite cfRepr1 !cfunE Gx rGx mxtrace_mulC mulKVmx // mxtrace_diag.
split=> //=; apply: (le_trans (ler_norm_sum _ _ _)).
by rewrite (eq_bigr _ (in1W norm1_e)) sumr_const card_ord lexx.
rewrite !cfunE groupV !mulrb Gx rGx mxtrace_mulC mulKVmx //.
rewrite -trace_map_mx map_diag_mx; set d' := diag_mx _.
rewrite -[d'](mulKVmx unitB) mxtrace_mulC -[_ *m _](repr_mxK rG Gx) rGx.
rewrite -!mulmxA mulKVmx // (mulmxA d').
suffices->: d' *m diag_mx e = 1%:M by rewrite mul1mx mulKmx.
rewrite mulmx_diag -diag_const_mx; congr diag_mx; apply/rowP=> j.
by rewrite [e]lock !mxE mulrC -normCK -lock norm1_e expr1n.
Qed.
Variables (A : {group aT}) (G : {group gT}).
(* This is Isaacs, Lemma (2.15) (d). *)
Lemma char_inv (chi : 'CF(G)) x : chi \is a character -> chi x^-1%g = (chi x)^*.
Proof.
case Gx: (x \in G); last by rewrite !cfun0 ?rmorph0 ?groupV ?Gx.
by case/char_reprP=> rG ->; have [e [_ _ _]] := repr_rsim_diag rG Gx.
Qed.
Lemma irr_inv i x : 'chi[G]_i x^-1%g = ('chi_i x)^*.
Proof. exact/char_inv/irr_char. Qed.
(* This is Isaacs, Theorem (2.13). *)
Theorem generalized_orthogonality_relation y (i j : Iirr G) :
#|G|%:R^-1 * (\sum_(x in G) 'chi_i (x * y)%g * 'chi_j x^-1%g)
= (i == j)%:R * ('chi_i y / 'chi_i 1%g).
Proof.
pose W := @socle_of_Iirr _ G; pose e k := Wedderburn_id (W k).
pose aG := regular_repr algC G.
have [Gy | notGy] := boolP (y \in G); last first.
rewrite cfun0 // mul0r big1 ?mulr0 // => x Gx.
by rewrite cfun0 ?groupMl ?mul0r.
transitivity (('chi_i).[e j *m aG y]%CF / 'chi_j 1%g).
rewrite [e j]Wedderburn_id_expansion -scalemxAl xcfunZr -mulrA; congr (_ * _).
rewrite mulmx_suml raddf_sum big_distrl; apply: eq_bigr => x Gx /=.
rewrite -scalemxAl xcfunZr -repr_mxM // xcfunG ?groupM // mulrAC mulrC.
by congr (_ * _); rewrite mulrC mulKf ?irr1_neq0.
rewrite mulr_natl mulrb; have [<-{j} | neq_ij] := eqVneq.
by congr (_ / _); rewrite xcfun_mul_id ?envelop_mx_id ?xcfunG.
rewrite (xcfun_annihilate neq_ij) ?mul0r //.
case/andP: (Wedderburn_ideal (W j)) => _; apply: submx_trans.
by rewrite mem_mulsmx ?Wedderburn_id_mem ?envelop_mx_id.
Qed.
(* This is Isaacs, Corollary (2.14). *)
Corollary first_orthogonality_relation (i j : Iirr G) :
#|G|%:R^-1 * (\sum_(x in G) 'chi_i x * 'chi_j x^-1%g) = (i == j)%:R.
Proof.
have:= generalized_orthogonality_relation 1 i j.
rewrite mulrA mulfK ?irr1_neq0 // => <-; congr (_ * _).
by apply: eq_bigr => x; rewrite mulg1.
Qed.
(* The character table. *)
Definition irr_class i := enum_val (cast_ord (NirrE G) i).
Definition class_Iirr xG :=
cast_ord (esym (NirrE G)) (enum_rank_in (classes1 G) xG).
Local Notation c := irr_class.
Local Notation g i := (repr (c i)).
Local Notation iC := class_Iirr.
Definition character_table := \matrix_(i, j) 'chi[G]_i (g j).
Local Notation X := character_table.
Lemma irr_classP i : c i \in classes G.
Proof. exact: enum_valP. Qed.
Lemma repr_irr_classK i : g i ^: G = c i.
Proof. by case/repr_classesP: (irr_classP i). Qed.
Lemma irr_classK : cancel c iC.
Proof. by move=> i; rewrite /iC enum_valK_in cast_ordK. Qed.
Lemma class_IirrK : {in classes G, cancel iC c}.
Proof. by move=> xG GxG; rewrite /c cast_ordKV enum_rankK_in. Qed.
Lemma reindex_irr_class R idx (op : @Monoid.com_law R idx) F :
\big[op/idx]_(xG in classes G) F xG = \big[op/idx]_i F (c i).
Proof.
rewrite (reindex c); first by apply: eq_bigl => i; apply: enum_valP.
by exists iC; [apply: in1W; apply: irr_classK | apply: class_IirrK].
Qed.
(* The explicit value of the inverse is needed for the proof of the second *)
(* orthogonality relation. *)
Let X' := \matrix_(i, j) (#|'C_G[g i]|%:R^-1 * ('chi[G]_j (g i))^*).
Let XX'_1: X *m X' = 1%:M.
Proof.
apply/matrixP=> i j; rewrite !mxE -first_orthogonality_relation mulr_sumr.
rewrite sum_by_classes => [|u v Gu Gv]; last by rewrite -conjVg !cfunJ.
rewrite reindex_irr_class /=; apply/esym/eq_bigr=> k _.
rewrite !mxE irr_inv // -/(g k) -divg_index -indexgI /=.
rewrite (pchar0_natf_div Cpchar) ?dvdn_indexg // index_cent1 invfM invrK.
by rewrite repr_irr_classK mulrCA mulrA mulrCA.
Qed.
Lemma character_table_unit : X \in unitmx.
Proof. by case/mulmx1_unit: XX'_1. Qed.
Let uX := character_table_unit.
(* This is Isaacs, Theorem (2.18). *)
Theorem second_orthogonality_relation x y :
y \in G ->
\sum_i 'chi[G]_i x * ('chi_i y)^* = #|'C_G[x]|%:R *+ (x \in y ^: G).
Proof.
move=> Gy; pose i_x := iC (x ^: G); pose i_y := iC (y ^: G).
have [Gx | notGx] := boolP (x \in G); last first.
rewrite (contraNF (subsetP _ x) notGx) ?class_subG ?big1 // => i _.
by rewrite cfun0 ?mul0r.
transitivity ((#|'C_G[repr (y ^: G)]|%:R *: (X' *m X)) i_y i_x).
rewrite scalemxAl !mxE; apply: eq_bigr => k _; rewrite !mxE mulrC -!mulrA.
by rewrite !class_IirrK ?mem_classes // !cfun_repr mulVKf ?neq0CG.
rewrite mulmx1C // !mxE -!divg_index; do 2!rewrite -indexgI index_cent1.
rewrite (class_eqP (mem_repr y _)) ?class_refl // mulr_natr.
rewrite (can_in_eq class_IirrK) ?mem_classes //.
have [-> | not_yGx] := eqVneq; first by rewrite class_refl.
by rewrite [x \in _](contraNF _ not_yGx) // => /class_eqP->.
Qed.
Lemma eq_irr_mem_classP x y :
y \in G -> reflect (forall i, 'chi[G]_i x = 'chi_i y) (x \in y ^: G).
Proof.
move=> Gy; apply: (iffP idP) => [/imsetP[z Gz ->] i | xGy]; first exact: cfunJ.
have Gx: x \in G.
congr is_true: Gy; apply/eqP; rewrite -(can_eq oddb) -eqC_nat -!cfun1E.
by rewrite -irr0 xGy.
congr is_true: (class_refl G x); apply/eqP; rewrite -(can_eq oddb).
rewrite -(eqn_pmul2l (cardG_gt0 'C_G[x])) -eqC_nat !mulrnA; apply/eqP.
by rewrite -!second_orthogonality_relation //; apply/eq_bigr=> i _; rewrite xGy.
Qed.
(* This is Isaacs, Theorem (6.32) (due to Brauer). *)
Lemma card_afix_irr_classes (ito : action A (Iirr G)) (cto : action A _) a :
a \in A -> [acts A, on classes G | cto] ->
(forall i x y, x \in G -> y \in cto (x ^: G) a ->
'chi_i x = 'chi_(ito i a) y) ->
#|'Fix_ito[a]| = #|'Fix_(classes G | cto)[a]|.
Proof.
move=> Aa actsAG stabAchi; apply/eqP; rewrite -eqC_nat; apply/eqP.
have [[cP cK] iCK] := (irr_classP, irr_classK, class_IirrK).
pose icto b i := iC (cto (c i) b).
have Gca i: cto (c i) a \in classes G by rewrite (acts_act actsAG).
have inj_qa: injective (icto a).
by apply: can_inj (icto a^-1%g) _ => i; rewrite /icto iCK ?actKin ?cK.
pose Pa : 'M[algC]_(Nirr G) := perm_mx (actperm ito a).
pose qa := perm inj_qa; pose Qa : 'M[algC]_(Nirr G) := perm_mx qa^-1^-1%g.
transitivity (\tr Pa).
rewrite -sumr_const big_mkcond; apply: eq_bigr => i _.
by rewrite !mxE permE inE sub1set inE; case: ifP.
symmetry; transitivity (\tr Qa).
rewrite cardsE -sumr_const -big_filter_cond big_mkcond big_filter /=.
rewrite reindex_irr_class; apply: eq_bigr => i _; rewrite !mxE invgK permE.
by rewrite inE sub1set inE -(can_eq cK) iCK //; case: ifP.
rewrite -[Pa](mulmxK uX) -[Qa](mulKmx uX) mxtrace_mulC; congr (\tr(_ *m _)).
rewrite -row_permE -col_permE; apply/matrixP=> i j; rewrite !mxE.
rewrite -{2}[j](permKV qa); move: {j}(_ j) => j; rewrite !permE iCK //.
apply: stabAchi; first by case/repr_classesP: (cP j).
by rewrite repr_irr_classK (mem_repr_classes (Gca _)).
Qed.
End OrthogonalityRelations.
Prenex Implicits irr_class class_Iirr irr_classK.
Arguments class_IirrK {gT G%_G} [xG%_g] GxG : rename.
Arguments character_table {gT} G%_g.
Section InnerProduct.
Variable (gT : finGroupType) (G : {group gT}).
Lemma cfdot_irr i j : '['chi_i, 'chi_j]_G = (i == j)%:R.
Proof.
rewrite -first_orthogonality_relation; congr (_ * _).
by apply: eq_bigr => x Gx; rewrite irr_inv.
Qed.
Lemma cfnorm_irr i : '['chi[G]_i] = 1.
Proof. by rewrite cfdot_irr eqxx. Qed.
Lemma irr_orthonormal : orthonormal (irr G).
Proof.
apply/orthonormalP; split; first exact: free_uniq (irr_free G).
move=> _ _ /irrP[i ->] /irrP[j ->].
by rewrite cfdot_irr (inj_eq irr_inj).
Qed.
Lemma coord_cfdot phi i : coord (irr G) i phi = '[phi, 'chi_i].
Proof.
rewrite {2}(coord_basis (irr_basis G) (memvf phi)).
rewrite cfdot_suml (bigD1 i) // cfdotZl /= -tnth_nth cfdot_irr eqxx mulr1.
rewrite big1 ?addr0 // => j neq_ji; rewrite cfdotZl /= -tnth_nth cfdot_irr.
by rewrite (negbTE neq_ji) mulr0.
Qed.
Lemma cfun_sum_cfdot phi : phi = \sum_i '[phi, 'chi_i]_G *: 'chi_i.
Proof.
rewrite {1}(coord_basis (irr_basis G) (memvf phi)).
by apply: eq_bigr => i _; rewrite coord_cfdot -tnth_nth.
Qed.
Lemma cfdot_sum_irr phi psi :
'[phi, psi]_G = \sum_i '[phi, 'chi_i] * '[psi, 'chi_i]^*.
Proof.
rewrite {1}[phi]cfun_sum_cfdot cfdot_suml; apply: eq_bigr => i _.
by rewrite cfdotZl -cfdotC.
Qed.
Lemma Cnat_cfdot_char_irr i phi :
phi \is a character -> '[phi, 'chi_i]_G \in Num.nat.
Proof. by move/forallP/(_ i); rewrite coord_cfdot. Qed.
Lemma cfdot_char_r phi chi :
chi \is a character -> '[phi, chi]_G = \sum_i '[phi, 'chi_i] * '[chi, 'chi_i].
Proof.
move=> Nchi; rewrite cfdot_sum_irr; apply: eq_bigr => i _; congr (_ * _).
by rewrite conj_natr ?Cnat_cfdot_char_irr.
Qed.
Lemma Cnat_cfdot_char chi xi :
chi \is a character -> xi \is a character -> '[chi, xi]_G \in Num.nat.
Proof.
move=> Nchi Nxi; rewrite cfdot_char_r ?rpred_sum // => i _.
by rewrite rpredM ?Cnat_cfdot_char_irr.
Qed.
Lemma cfdotC_char chi xi :
chi \is a character-> xi \is a character -> '[chi, xi]_G = '[xi, chi].
Proof. by move=> Nchi Nxi; rewrite cfdotC conj_natr ?Cnat_cfdot_char. Qed.
Lemma irrEchar chi : (chi \in irr G) = (chi \is a character) && ('[chi] == 1).
Proof.
apply/irrP/andP=> [[i ->] | [Nchi]]; first by rewrite irr_char cfnorm_irr.
rewrite cfdot_sum_irr => /eqP/natr_sum_eq1[i _| i [_ ci1 cj0]].
by rewrite rpredM // ?conj_natr ?Cnat_cfdot_char_irr.
exists i; rewrite [chi]cfun_sum_cfdot (bigD1 i) //=.
rewrite -(normr_idP (natr_ge0 (Cnat_cfdot_char_irr i Nchi))).
rewrite normC_def {}ci1 sqrtC1 scale1r big1 ?addr0 // => j neq_ji.
by rewrite (('[_] =P 0) _) ?scale0r // -normr_eq0 normC_def cj0 ?sqrtC0.
Qed.
Lemma irrWchar chi : chi \in irr G -> chi \is a character.
Proof. by rewrite irrEchar => /andP[]. Qed.
Lemma irrWnorm chi : chi \in irr G -> '[chi] = 1.
Proof. by rewrite irrEchar => /andP[_ /eqP]. Qed.
Lemma mul_lin_irr xi chi :
xi \is a linear_char -> chi \in irr G -> xi * chi \in irr G.
Proof.
move=> Lxi; rewrite !irrEchar => /andP[Nphi /eqP <-].
rewrite rpredM // ?lin_charW //=; apply/eqP; congr (_ * _).
apply: eq_bigr=> x Gx; rewrite !cfunE rmorphM/= mulrACA -(lin_charV_conj Lxi)//.
by rewrite -lin_charM ?groupV // mulgV lin_char1 ?mul1r.
Qed.
Lemma eq_scaled_irr a b i j :
(a *: 'chi[G]_i == b *: 'chi_j) = (a == b) && ((a == 0) || (i == j)).
Proof.
apply/eqP/andP=> [|[/eqP-> /pred2P[]-> //]]; last by rewrite !scale0r.
move/(congr1 (cfdotr 'chi__)) => /= eq_ai_bj.
move: {eq_ai_bj}(eq_ai_bj i) (esym (eq_ai_bj j)); rewrite !cfdotZl !cfdot_irr.
by rewrite !mulr_natr !mulrb !eqxx eq_sym orbC; case: ifP => _ -> //= ->.
Qed.
Lemma eq_signed_irr (s t : bool) i j :
((-1) ^+ s *: 'chi[G]_i == (-1) ^+ t *: 'chi_j) = (s == t) && (i == j).
Proof. by rewrite eq_scaled_irr signr_eq0 (inj_eq signr_inj). Qed.
Lemma eq_scale_irr a (i j : Iirr G) :
(a *: 'chi_i == a *: 'chi_j) = (a == 0) || (i == j).
Proof. by rewrite eq_scaled_irr eqxx. Qed.
Lemma eq_addZ_irr a b (i j r t : Iirr G) :
(a *: 'chi_i + b *: 'chi_j == a *: 'chi_r + b *: 'chi_t)
= [|| [&& (a == 0) || (i == r) & (b == 0) || (j == t)],
[&& i == t, j == r & a == b] | [&& i == j, r == t & a == - b]].
Proof.
rewrite -!eq_scale_irr; apply/eqP/idP; last first.
case/orP; first by case/andP=> /eqP-> /eqP->.
case/orP=> /and3P[/eqP-> /eqP-> /eqP->]; first by rewrite addrC.
by rewrite !scaleNr !addNr.
have [-> /addrI/eqP-> // | /=] := eqVneq.
rewrite eq_scale_irr => /norP[/negP nz_a /negPf neq_ir].
move/(congr1 (cfdotr 'chi__))/esym/eqP => /= eq_cfdot.
move: {eq_cfdot}(eq_cfdot i) (eq_cfdot r); rewrite eq_sym !cfdotDl !cfdotZl.
rewrite !cfdot_irr !mulr_natr !mulrb !eqxx -!(eq_sym i) neq_ir !add0r.
have [<- _ | _] := i =P t; first by rewrite neq_ir addr0; case: ifP => // _ ->.
rewrite 2!fun_if if_arg addr0 addr_eq0; case: eqP => //= <- ->.
by rewrite neq_ir 2!fun_if if_arg eq_sym addr0; case: ifP.
Qed.
Lemma eq_subZnat_irr (a b : nat) (i j r t : Iirr G) :
(a%:R *: 'chi_i - b%:R *: 'chi_j == a%:R *: 'chi_r - b%:R *: 'chi_t)
= [|| a == 0 | i == r] && [|| b == 0 | j == t]
|| [&& i == j, r == t & a == b].
Proof.
rewrite -!scaleNr eq_addZ_irr oppr_eq0 opprK -addr_eq0 -natrD eqr_nat.
by rewrite !pnatr_eq0 addn_eq0; case: a b => [|a] [|b]; rewrite ?andbF.
Qed.
End InnerProduct.
Section IrrConstt.
Variable (gT : finGroupType) (G H : {group gT}).
Lemma char1_ge_norm (chi : 'CF(G)) x :
chi \is a character -> `|chi x| <= chi 1%g.
Proof.
case/char_reprP=> rG ->; case Gx: (x \in G); last first.
by rewrite cfunE cfRepr1 Gx normr0 ler0n.
by have [e [_ _ []]] := repr_rsim_diag rG Gx.
Qed.
Lemma max_cfRepr_norm_scalar n (rG : mx_representation algC G n) x :
x \in G -> `|cfRepr rG x| = cfRepr rG 1%g ->
exists2 c, `|c| = 1 & rG x = c%:M.
Proof.
move=> Gx; have [e [[B uB def_x] [_ e1] [-> _] _]] := repr_rsim_diag rG Gx.
rewrite cfRepr1 -[n in n%:R]card_ord -sumr_const -(eq_bigr _ (in1W e1)).
case/normC_sum_eq1=> [i _ | c /eqP norm_c_1 def_e]; first by rewrite e1.
have{} def_e: e = const_mx c by apply/rowP=> i; rewrite mxE def_e ?andbT.
by exists c => //; rewrite def_x def_e diag_const_mx scalar_mxC mulmxKV.
Qed.
Lemma max_cfRepr_mx1 n (rG : mx_representation algC G n) x :
x \in G -> cfRepr rG x = cfRepr rG 1%g -> rG x = 1%:M.
Proof.
move=> Gx kerGx; have [|c _ def_x] := @max_cfRepr_norm_scalar n rG x Gx.
by rewrite kerGx cfRepr1 normr_nat.
move/eqP: kerGx; rewrite cfRepr1 cfunE Gx {rG}def_x mxtrace_scalar.
case: n => [_|n]; first by rewrite ![_%:M]flatmx0.
rewrite mulrb -subr_eq0 -mulrnBl -mulr_natl mulf_eq0 pnatr_eq0 /=.
by rewrite subr_eq0 => /eqP->.
Qed.
Definition irr_constt (B : {set gT}) phi := [pred i | '[phi, 'chi_i]_B != 0].
Lemma irr_consttE i phi : (i \in irr_constt phi) = ('[phi, 'chi_i]_G != 0).
Proof. by []. Qed.
Lemma constt_charP (i : Iirr G) chi :
chi \is a character ->
reflect (exists2 chi', chi' \is a character & chi = 'chi_i + chi')
(i \in irr_constt chi).
Proof.
move=> Nchi; apply: (iffP idP) => [i_in_chi| [chi' Nchi' ->]]; last first.
rewrite inE /= cfdotDl cfdot_irr eqxx -(eqP (Cnat_cfdot_char_irr i Nchi')).
by rewrite -natrD pnatr_eq0.
exists (chi - 'chi_i); last by rewrite addrC subrK.
apply/forallP=> j; rewrite coord_cfdot cfdotBl cfdot_irr.
have [<- | _] := eqP; last by rewrite subr0 Cnat_cfdot_char_irr.
move: i_in_chi; rewrite inE; case/natrP: (Cnat_cfdot_char_irr i Nchi) => n ->.
by rewrite pnatr_eq0 -lt0n => /natrB <-; apply: rpred_nat.
Qed.
Lemma cfun_sum_constt (phi : 'CF(G)) :
phi = \sum_(i in irr_constt phi) '[phi, 'chi_i] *: 'chi_i.
Proof.
rewrite {1}[phi]cfun_sum_cfdot (bigID [pred i | '[phi, 'chi_i] == 0]) /=.
by rewrite big1 ?add0r // => i /eqP->; rewrite scale0r.
Qed.
Lemma neq0_has_constt (phi : 'CF(G)) :
phi != 0 -> exists i, i \in irr_constt phi.
Proof.
move=> nz_phi; apply/existsP; apply: contra nz_phi => /pred0P phi0.
by rewrite [phi]cfun_sum_constt big_pred0.
Qed.
Lemma constt_irr i : irr_constt 'chi[G]_i =i pred1 i.
Proof.
by move=> j; rewrite !inE cfdot_irr pnatr_eq0 (eq_sym j); case: (i == j).
Qed.
Lemma char1_ge_constt (i : Iirr G) chi :
chi \is a character -> i \in irr_constt chi -> 'chi_i 1%g <= chi 1%g.
Proof.
move=> {chi} _ /constt_charP[// | chi Nchi ->].
by rewrite cfunE addrC -subr_ge0 addrK char1_ge0.
Qed.
Lemma constt_ortho_char (phi psi : 'CF(G)) i j :
phi \is a character -> psi \is a character ->
i \in irr_constt phi -> j \in irr_constt psi ->
'[phi, psi] = 0 -> '['chi_i, 'chi_j] = 0.
Proof.
move=> _ _ /constt_charP[//|phi1 Nphi1 ->] /constt_charP[//|psi1 Npsi1 ->].
rewrite cfdot_irr; case: eqP => // -> /eqP/idPn[].
rewrite cfdotDl !cfdotDr cfnorm_irr -addrA gt_eqF ?ltr_wpDr ?ltr01 //.
by rewrite natr_ge0 ?rpredD ?Cnat_cfdot_char ?irr_char.
Qed.
End IrrConstt.
Arguments irr_constt {gT B%_g} phi%_CF.
Section Kernel.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (phi chi xi : 'CF(G)) (H : {group gT}).
Lemma cfker_repr n (rG : mx_representation algC G n) :
cfker (cfRepr rG) = rker rG.
Proof.
apply/esym/setP=> x; rewrite inE mul1mx /=.
case Gx: (x \in G); last by rewrite inE Gx.
apply/eqP/idP=> Kx; last by rewrite max_cfRepr_mx1 // cfker1.
rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !mulrb groupMl //.
by case: ifP => // Gy; rewrite repr_mxM // Kx mul1mx.
Qed.
Lemma cfkerEchar chi :
chi \is a character -> cfker chi = [set x in G | chi x == chi 1%g].
Proof.
move=> Nchi; apply/setP=> x; apply/idP/setIdP=> [Kx | [Gx /eqP chi_x]].
by rewrite (subsetP (cfker_sub chi)) // cfker1.
case/char_reprP: Nchi => rG -> in chi_x *; rewrite inE Gx; apply/forallP=> y.
rewrite !cfunE groupMl // !mulrb; case: ifP => // Gy.
by rewrite repr_mxM // max_cfRepr_mx1 ?mul1mx.
Qed.
Lemma cfker_nzcharE chi :
chi \is a character -> chi != 0 -> cfker chi = [set x | chi x == chi 1%g].
Proof.
move=> Nchi nzchi; apply/setP=> x; rewrite cfkerEchar // !inE andb_idl //.
by apply: contraLR => /cfun0-> //; rewrite eq_sym char1_eq0.
Qed.
Lemma cfkerEirr i : cfker 'chi[G]_i = [set x | 'chi_i x == 'chi_i 1%g].
Proof. by rewrite cfker_nzcharE ?irr_char ?irr_neq0. Qed.
Lemma cfker_irr0 : cfker 'chi[G]_0 = G.
Proof. by rewrite irr0 cfker_cfun1. Qed.
Lemma cfaithful_reg : cfaithful (cfReg G).
Proof.
apply/subsetP=> x; rewrite cfkerEchar ?cfReg_char // !inE !cfRegE eqxx.
by case/andP=> _; apply: contraLR => /negbTE->; rewrite eq_sym neq0CG.
Qed.
Lemma cfkerE chi :
chi \is a character ->
cfker chi = G :&: \bigcap_(i in irr_constt chi) cfker 'chi_i.
Proof.
move=> Nchi; rewrite cfkerEchar //; apply/setP=> x; rewrite !inE.
apply: andb_id2l => Gx; rewrite {1 2}[chi]cfun_sum_constt !sum_cfunE.
apply/eqP/bigcapP=> [Kx i Ci | Kx]; last first.
by apply: eq_bigr => i /Kx Kx_i; rewrite !cfunE cfker1.
rewrite cfkerEirr inE /= -(inj_eq (mulfI Ci)).
have:= (normC_sum_upper _ Kx) i; rewrite !cfunE => -> // {Ci}i _.
have chi_i_ge0: 0 <= '[chi, 'chi_i].
by rewrite natr_ge0 ?Cnat_cfdot_char_irr.
by rewrite !cfunE normrM (normr_idP _) ?ler_wpM2l ?char1_ge_norm ?irr_char.
Qed.
Lemma TI_cfker_irr : \bigcap_i cfker 'chi[G]_i = [1].
Proof.
apply/trivgP; apply: subset_trans cfaithful_reg; rewrite cfkerE ?cfReg_char //.
rewrite subsetI (bigcap_min 0) //=; last by rewrite cfker_irr0.
by apply/bigcapsP=> i _; rewrite bigcap_inf.
Qed.
Lemma cfker_constt i chi :
chi \is a character -> i \in irr_constt chi ->
cfker chi \subset cfker 'chi[G]_i.
Proof. by move=> Nchi Ci; rewrite cfkerE ?subIset ?(bigcap_min i) ?orbT. Qed.
Section KerLin.
Variable xi : 'CF(G).
Hypothesis lin_xi : xi \is a linear_char.
Let Nxi: xi \is a character. Proof. by have [] := andP lin_xi. Qed.
Lemma lin_char_der1 : G^`(1)%g \subset cfker xi.
Proof.
rewrite gen_subG /=; apply/subsetP=> _ /imset2P[x y Gx Gy ->].
rewrite cfkerEchar // inE groupR //= !lin_charM ?lin_charV ?in_group //.
by rewrite mulrCA mulKf ?mulVf ?lin_char_neq0 // lin_char1.
Qed.
Lemma cforder_lin_char : #[xi]%CF = exponent (G / cfker xi)%g.
Proof.
apply/eqP; rewrite eqn_dvd; apply/andP; split.
apply/dvdn_cforderP=> x Gx; rewrite -lin_charX // -cfQuoEker ?groupX //.
rewrite morphX ?(subsetP (cfker_norm xi)) //= expg_exponent ?mem_quotient //.
by rewrite cfQuo1 ?cfker_normal ?lin_char1.
have abGbar: abelian (G / cfker xi) := sub_der1_abelian lin_char_der1.
have [_ /morphimP[x Nx Gx ->] ->] := exponent_witness (abelian_nil abGbar).
rewrite order_dvdn -morphX //= coset_id cfkerEchar // !inE groupX //=.
by rewrite lin_charX ?lin_char1 // (dvdn_cforderP _ _ _).
Qed.
Lemma cforder_lin_char_dvdG : #[xi]%CF %| #|G|.
Proof.
by rewrite cforder_lin_char (dvdn_trans (exponent_dvdn _)) ?dvdn_morphim.
Qed.
Lemma cforder_lin_char_gt0 : (0 < #[xi]%CF)%N.
Proof. by rewrite cforder_lin_char exponent_gt0. Qed.
End KerLin.
End Kernel.
Section Restrict.
Variable (gT : finGroupType) (G H : {group gT}).
Lemma cfRepr_sub n (rG : mx_representation algC G n) (sHG : H \subset G) :
cfRepr (subg_repr rG sHG) = 'Res[H] (cfRepr rG).
Proof.
by apply/cfun_inP => x Hx; rewrite cfResE // !cfunE Hx (subsetP sHG).
Qed.
Lemma cfRes_char chi : chi \is a character -> 'Res[H, G] chi \is a character.
Proof.
have [sHG | not_sHG] := boolP (H \subset G).
by case/char_reprP=> rG ->; rewrite -(cfRepr_sub rG sHG) cfRepr_char.
by move/Cnat_char1=> Nchi1; rewrite cfResEout // rpredZ_nat ?rpred1.
Qed.
Lemma cfRes_eq0 phi : phi \is a character -> ('Res[H, G] phi == 0) = (phi == 0).
Proof. by move=> Nchi; rewrite -!char1_eq0 ?cfRes_char // cfRes1. Qed.
Lemma cfRes_lin_char chi :
chi \is a linear_char -> 'Res[H, G] chi \is a linear_char.
Proof. by case/andP=> Nchi; rewrite qualifE/= cfRes_char ?cfRes1. Qed.
Lemma Res_irr_neq0 i : 'Res[H, G] 'chi_i != 0.
Proof. by rewrite cfRes_eq0 ?irr_neq0 ?irr_char. Qed.
Lemma cfRes_lin_lin (chi : 'CF(G)) :
chi \is a character -> 'Res[H] chi \is a linear_char -> chi \is a linear_char.
Proof. by rewrite !qualifE/= !qualifE/= cfRes1 => -> /andP[]. Qed.
Lemma cfRes_irr_irr chi :
chi \is a character -> 'Res[H] chi \in irr H -> chi \in irr G.
Proof.
have [sHG /char_reprP[rG ->] | not_sHG Nchi] := boolP (H \subset G).
rewrite -(cfRepr_sub _ sHG) => /irr_reprP[rH irrH def_rH]; apply/irr_reprP.
suffices /subg_mx_irr: mx_irreducible (subg_repr rG sHG) by exists rG.
by apply: mx_rsim_irr irrH; apply/cfRepr_rsimP/eqP.
rewrite cfResEout // => /irrP[j Dchi_j]; apply/lin_char_irr/cfRes_lin_lin=> //.
suffices j0: j = 0 by rewrite cfResEout // Dchi_j j0 irr0 rpred1.
apply: contraNeq (irr1_neq0 j) => nz_j.
have:= xcfun_id j 0; rewrite -Dchi_j cfunE xcfunZl -irr0 xcfun_id eqxx => ->.
by rewrite (negPf nz_j).
Qed.
Definition Res_Iirr (A B : {set gT}) i := cfIirr ('Res[B, A] 'chi_i).
Lemma Res_Iirr0 : Res_Iirr H (0 : Iirr G) = 0.
Proof. by rewrite /Res_Iirr irr0 rmorph1 -irr0 irrK. Qed.
Lemma lin_Res_IirrE i : 'chi[G]_i 1%g = 1 -> 'chi_(Res_Iirr H i) = 'Res 'chi_i.
Proof.
move=> chi1; rewrite cfIirrE ?lin_char_irr ?cfRes_lin_char //.
by rewrite qualifE/= irr_char /= chi1.
Qed.
End Restrict.
Arguments Res_Iirr {gT A%_g} B%_g i%_R.
Section MoreConstt.
Variables (gT : finGroupType) (G H : {group gT}).
Lemma constt_Ind_Res i j :
i \in irr_constt ('Ind[G] 'chi_j) = (j \in irr_constt ('Res[H] 'chi_i)).
Proof. by rewrite !irr_consttE cfdotC conjC_eq0 -cfdot_Res_l. Qed.
Lemma cfdot_Res_ge_constt i j psi :
psi \is a character -> j \in irr_constt psi ->
'['Res[H, G] 'chi_j, 'chi_i] <= '['Res[H] psi, 'chi_i].
Proof.
move=> {psi} _ /constt_charP[// | psi Npsi ->].
rewrite linearD cfdotDl addrC -subr_ge0 addrK natr_ge0 //=.
by rewrite Cnat_cfdot_char_irr // cfRes_char.
Qed.
Lemma constt_Res_trans j psi :
psi \is a character -> j \in irr_constt psi ->
{subset irr_constt ('Res[H, G] 'chi_j) <= irr_constt ('Res[H] psi)}.
Proof.
move=> Npsi Cj i; apply: contraNneq; rewrite eq_le => {1}<-.
rewrite cfdot_Res_ge_constt ?natr_ge0 ?Cnat_cfdot_char_irr //.
by rewrite cfRes_char ?irr_char.
Qed.
End MoreConstt.
Section Morphim.
Variables (aT rT : finGroupType) (G D : {group aT}) (f : {morphism D >-> rT}).
Implicit Type chi : 'CF(f @* G).
Lemma cfRepr_morphim n (rfG : mx_representation algC (f @* G) n) sGD :
cfRepr (morphim_repr rfG sGD) = cfMorph (cfRepr rfG).
Proof.
apply/cfun_inP=> x Gx; have Dx: x \in D := subsetP sGD x Gx.
by rewrite cfMorphE // !cfunE ?mem_morphim ?Gx.
Qed.
Lemma cfMorph_char chi : chi \is a character -> cfMorph chi \is a character.
Proof.
have [sGD /char_reprP[rfG ->] | outGD Nchi] := boolP (G \subset D); last first.
by rewrite cfMorphEout // rpredZ_nat ?rpred1 ?Cnat_char1.
apply/char_reprP; exists (Representation (morphim_repr rfG sGD)).
by rewrite cfRepr_morphim.
Qed.
Lemma cfMorph_lin_char chi :
chi \is a linear_char -> cfMorph chi \is a linear_char.
Proof. by case/andP=> Nchi; rewrite qualifE/= cfMorph1 cfMorph_char. Qed.
Lemma cfMorph_charE chi :
G \subset D -> (cfMorph chi \is a character) = (chi \is a character).
Proof.
move=> sGD; apply/idP/idP=> [/char_reprP[[n rG] /=Dfchi] | /cfMorph_char//].
pose H := 'ker_G f; have kerH: H \subset rker rG.
by rewrite -cfker_repr -Dfchi cfker_morph // setIS // ker_sub_pre.
have nHG: G \subset 'N(H) by rewrite normsI // (subset_trans sGD) ?ker_norm.
have [h injh im_h] := first_isom_loc f sGD; rewrite -/H in h injh im_h.
have DfG: invm injh @*^-1 (G / H) == (f @* G)%g by rewrite morphpre_invm im_h.
pose rfG := eqg_repr (morphpre_repr _ (quo_repr kerH nHG)) DfG.
apply/char_reprP; exists (Representation rfG).
apply/cfun_inP=> _ /morphimP[x Dx Gx ->]; rewrite -cfMorphE // Dfchi !cfunE Gx.
pose xH := coset H x; have GxH: xH \in (G / H)%g by apply: mem_quotient.
suffices Dfx: f x = h xH by rewrite mem_morphim //= Dfx invmE ?quo_repr_coset.
by apply/set1_inj; rewrite -?morphim_set1 ?im_h ?(subsetP nHG) ?sub1set.
Qed.
Lemma cfMorph_lin_charE chi :
G \subset D -> (cfMorph chi \is a linear_char) = (chi \is a linear_char).
Proof. by rewrite qualifE/= cfMorph1 => /cfMorph_charE->. Qed.
Lemma cfMorph_irr chi :
G \subset D -> (cfMorph chi \in irr G) = (chi \in irr (f @* G)).
Proof. by move=> sGD; rewrite !irrEchar cfMorph_charE // cfMorph_iso. Qed.
Definition morph_Iirr i := cfIirr (cfMorph 'chi[f @* G]_i).
Lemma morph_Iirr0 : morph_Iirr 0 = 0.
Proof. by rewrite /morph_Iirr irr0 rmorph1 -irr0 irrK. Qed.
Hypothesis sGD : G \subset D.
Lemma morph_IirrE i : 'chi_(morph_Iirr i) = cfMorph 'chi_i.
Proof. by rewrite cfIirrE ?cfMorph_irr ?mem_irr. Qed.
Lemma morph_Iirr_inj : injective morph_Iirr.
Proof.
by move=> i j eq_ij; apply/irr_inj/cfMorph_inj; rewrite // -!morph_IirrE eq_ij.
Qed.
Lemma morph_Iirr_eq0 i : (morph_Iirr i == 0) = (i == 0).
Proof. by rewrite -!irr_eq1 morph_IirrE cfMorph_eq1. Qed.
End Morphim.
Section Isom.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variables (R : {group rT}) (isoGR : isom G R f).
Implicit Type chi : 'CF(G).
Lemma cfIsom_char chi :
(cfIsom isoGR chi \is a character) = (chi \is a character).
Proof.
rewrite [cfIsom _]locked_withE cfMorph_charE //.
by rewrite (isom_im (isom_sym _)) cfRes_id.
Qed.
Lemma cfIsom_lin_char chi :
(cfIsom isoGR chi \is a linear_char) = (chi \is a linear_char).
Proof. by rewrite qualifE/= cfIsom_char cfIsom1. Qed.
Lemma cfIsom_irr chi : (cfIsom isoGR chi \in irr R) = (chi \in irr G).
Proof. by rewrite !irrEchar cfIsom_char cfIsom_iso. Qed.
Definition isom_Iirr i := cfIirr (cfIsom isoGR 'chi_i).
Lemma isom_IirrE i : 'chi_(isom_Iirr i) = cfIsom isoGR 'chi_i.
Proof. by rewrite cfIirrE ?cfIsom_irr ?mem_irr. Qed.
Lemma isom_Iirr_inj : injective isom_Iirr.
Proof.
by move=> i j eqij; apply/irr_inj/(cfIsom_inj isoGR); rewrite -!isom_IirrE eqij.
Qed.
Lemma isom_Iirr_eq0 i : (isom_Iirr i == 0) = (i == 0).
Proof. by rewrite -!irr_eq1 isom_IirrE cfIsom_eq1. Qed.
Lemma isom_Iirr0 : isom_Iirr 0 = 0.
Proof. by apply/eqP; rewrite isom_Iirr_eq0. Qed.
End Isom.
Arguments isom_Iirr_inj {aT rT G f R} isoGR [i1 i2] : rename.
Section IsomInv.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variables (R : {group rT}) (isoGR : isom G R f).
Lemma isom_IirrK : cancel (isom_Iirr isoGR) (isom_Iirr (isom_sym isoGR)).
Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomK. Qed.
Lemma isom_IirrKV : cancel (isom_Iirr (isom_sym isoGR)) (isom_Iirr isoGR).
Proof. by move=> i; apply: irr_inj; rewrite !isom_IirrE cfIsomKV. Qed.
End IsomInv.
Section Sdprod.
Variables (gT : finGroupType) (K H G : {group gT}).
Hypothesis defG : K ><| H = G.
Let nKG: G \subset 'N(K). Proof. by have [/andP[]] := sdprod_context defG. Qed.
Lemma cfSdprod_char chi :
(cfSdprod defG chi \is a character) = (chi \is a character).
Proof. by rewrite unlock cfMorph_charE // cfIsom_char. Qed.
Lemma cfSdprod_lin_char chi :
(cfSdprod defG chi \is a linear_char) = (chi \is a linear_char).
Proof. by rewrite qualifE/= cfSdprod_char cfSdprod1. Qed.
Lemma cfSdprod_irr chi : (cfSdprod defG chi \in irr G) = (chi \in irr H).
Proof. by rewrite !irrEchar cfSdprod_char cfSdprod_iso. Qed.
Definition sdprod_Iirr j := cfIirr (cfSdprod defG 'chi_j).
Lemma sdprod_IirrE j : 'chi_(sdprod_Iirr j) = cfSdprod defG 'chi_j.
Proof. by rewrite cfIirrE ?cfSdprod_irr ?mem_irr. Qed.
Lemma sdprod_IirrK : cancel sdprod_Iirr (Res_Iirr H).
Proof. by move=> j; rewrite /Res_Iirr sdprod_IirrE cfSdprodK irrK. Qed.
Lemma sdprod_Iirr_inj : injective sdprod_Iirr.
Proof. exact: can_inj sdprod_IirrK. Qed.
Lemma sdprod_Iirr_eq0 i : (sdprod_Iirr i == 0) = (i == 0).
Proof. by rewrite -!irr_eq1 sdprod_IirrE cfSdprod_eq1. Qed.
Lemma sdprod_Iirr0 : sdprod_Iirr 0 = 0.
Proof. by apply/eqP; rewrite sdprod_Iirr_eq0. Qed.
Lemma Res_sdprod_irr phi :
K \subset cfker phi -> phi \in irr G -> 'Res phi \in irr H.
Proof.
move=> kerK /irrP[i Dphi]; rewrite irrEchar -(cfSdprod_iso defG).
by rewrite cfRes_sdprodK // Dphi cfnorm_irr cfRes_char ?irr_char /=.
Qed.
Lemma sdprod_Res_IirrE i :
K \subset cfker 'chi[G]_i -> 'chi_(Res_Iirr H i) = 'Res 'chi_i.
Proof. by move=> kerK; rewrite cfIirrE ?Res_sdprod_irr ?mem_irr. Qed.
Lemma sdprod_Res_IirrK i :
K \subset cfker 'chi_i -> sdprod_Iirr (Res_Iirr H i) = i.
Proof.
by move=> kerK; rewrite /sdprod_Iirr sdprod_Res_IirrE ?cfRes_sdprodK ?irrK.
Qed.
End Sdprod.
Arguments sdprod_Iirr_inj {gT K H G} defG [i1 i2] : rename.
Section DProd.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis KxH : K \x H = G.
Lemma cfDprodKl_abelian j : abelian H -> cancel ((cfDprod KxH)^~ 'chi_j) 'Res.
Proof. by move=> cHH; apply: cfDprodKl; apply/lin_char1/char_abelianP. Qed.
Lemma cfDprodKr_abelian i : abelian K -> cancel (cfDprod KxH 'chi_i) 'Res.
Proof. by move=> cKK; apply: cfDprodKr; apply/lin_char1/char_abelianP. Qed.
Lemma cfDprodl_char phi :
(cfDprodl KxH phi \is a character) = (phi \is a character).
Proof. exact: cfSdprod_char. Qed.
Lemma cfDprodr_char psi :
(cfDprodr KxH psi \is a character) = (psi \is a character).
Proof. exact: cfSdprod_char. Qed.
Lemma cfDprod_char phi psi :
phi \is a character -> psi \is a character ->
cfDprod KxH phi psi \is a character.
Proof. by move=> Nphi Npsi; rewrite rpredM ?cfDprodl_char ?cfDprodr_char. Qed.
Lemma cfDprod_eq1 phi psi :
phi \is a character -> psi \is a character ->
(cfDprod KxH phi psi == 1) = (phi == 1) && (psi == 1).
Proof.
move=> /Cnat_char1 Nphi /Cnat_char1 Npsi.
apply/eqP/andP=> [phi_psi_1 | [/eqP-> /eqP->]]; last by rewrite cfDprod_cfun1.
have /andP[/eqP phi1 /eqP psi1]: (phi 1%g == 1) && (psi 1%g == 1).
by rewrite -natr_mul_eq1 // -(cfDprod1 KxH) phi_psi_1 cfun11.
rewrite -[phi](cfDprodKl KxH psi1) -{2}[psi](cfDprodKr KxH phi1) phi_psi_1.
by rewrite !rmorph1.
Qed.
Lemma cfDprodl_lin_char phi :
(cfDprodl KxH phi \is a linear_char) = (phi \is a linear_char).
Proof. exact: cfSdprod_lin_char. Qed.
Lemma cfDprodr_lin_char psi :
(cfDprodr KxH psi \is a linear_char) = (psi \is a linear_char).
Proof. exact: cfSdprod_lin_char. Qed.
Lemma cfDprod_lin_char phi psi :
phi \is a linear_char -> psi \is a linear_char ->
cfDprod KxH phi psi \is a linear_char.
Proof. by move=> Nphi Npsi; rewrite rpredM ?cfSdprod_lin_char. Qed.
Lemma cfDprodl_irr chi : (cfDprodl KxH chi \in irr G) = (chi \in irr K).
Proof. exact: cfSdprod_irr. Qed.
Lemma cfDprodr_irr chi : (cfDprodr KxH chi \in irr G) = (chi \in irr H).
Proof. exact: cfSdprod_irr. Qed.
Definition dprodl_Iirr i := cfIirr (cfDprodl KxH 'chi_i).
Lemma dprodl_IirrE i : 'chi_(dprodl_Iirr i) = cfDprodl KxH 'chi_i.
Proof. exact: sdprod_IirrE. Qed.
Lemma dprodl_IirrK : cancel dprodl_Iirr (Res_Iirr K).
Proof. exact: sdprod_IirrK. Qed.
Lemma dprodl_Iirr_eq0 i : (dprodl_Iirr i == 0) = (i == 0).
Proof. exact: sdprod_Iirr_eq0. Qed.
Lemma dprodl_Iirr0 : dprodl_Iirr 0 = 0.
Proof. exact: sdprod_Iirr0. Qed.
Definition dprodr_Iirr j := cfIirr (cfDprodr KxH 'chi_j).
Lemma dprodr_IirrE j : 'chi_(dprodr_Iirr j) = cfDprodr KxH 'chi_j.
Proof. exact: sdprod_IirrE. Qed.
Lemma dprodr_IirrK : cancel dprodr_Iirr (Res_Iirr H).
Proof. exact: sdprod_IirrK. Qed.
Lemma dprodr_Iirr_eq0 j : (dprodr_Iirr j == 0) = (j == 0).
Proof. exact: sdprod_Iirr_eq0. Qed.
Lemma dprodr_Iirr0 : dprodr_Iirr 0 = 0.
Proof. exact: sdprod_Iirr0. Qed.
Lemma cfDprod_irr i j : cfDprod KxH 'chi_i 'chi_j \in irr G.
Proof.
rewrite irrEchar cfDprod_char ?irr_char //=.
by rewrite cfdot_dprod !cfdot_irr !eqxx mul1r.
Qed.
Definition dprod_Iirr ij := cfIirr (cfDprod KxH 'chi_ij.1 'chi_ij.2).
Lemma dprod_IirrE i j : 'chi_(dprod_Iirr (i, j)) = cfDprod KxH 'chi_i 'chi_j.
Proof. by rewrite cfIirrE ?cfDprod_irr. Qed.
Lemma dprod_IirrEl i : 'chi_(dprod_Iirr (i, 0)) = cfDprodl KxH 'chi_i.
Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mulr1. Qed.
Lemma dprod_IirrEr j : 'chi_(dprod_Iirr (0, j)) = cfDprodr KxH 'chi_j.
Proof. by rewrite dprod_IirrE /cfDprod irr0 rmorph1 mul1r. Qed.
Lemma dprod_Iirr_inj : injective dprod_Iirr.
Proof.
move=> [i1 j1] [i2 j2] /eqP; rewrite -[_ == _]oddb -(@natrK algC (_ == _)).
rewrite -cfdot_irr !dprod_IirrE cfdot_dprod !cfdot_irr -natrM mulnb.
by rewrite natrK oddb -xpair_eqE => /eqP.
Qed.
Lemma dprod_Iirr0 : dprod_Iirr (0, 0) = 0.
Proof. by apply/irr_inj; rewrite dprod_IirrE !irr0 cfDprod_cfun1. Qed.
Lemma dprod_Iirr0l j : dprod_Iirr (0, j) = dprodr_Iirr j.
Proof.
by apply/irr_inj; rewrite dprod_IirrE irr0 dprodr_IirrE cfDprod_cfun1l.
Qed.
Lemma dprod_Iirr0r i : dprod_Iirr (i, 0) = dprodl_Iirr i.
Proof.
by apply/irr_inj; rewrite dprod_IirrE irr0 dprodl_IirrE cfDprod_cfun1r.
Qed.
Lemma dprod_Iirr_eq0 i j : (dprod_Iirr (i, j) == 0) = (i == 0) && (j == 0).
Proof. by rewrite -xpair_eqE -(inj_eq dprod_Iirr_inj) dprod_Iirr0. Qed.
Lemma cfdot_dprod_irr i1 i2 j1 j2 :
'['chi_(dprod_Iirr (i1, j1)), 'chi_(dprod_Iirr (i2, j2))]
= ((i1 == i2) && (j1 == j2))%:R.
Proof. by rewrite cfdot_irr (inj_eq dprod_Iirr_inj). Qed.
Lemma dprod_Iirr_onto k : k \in codom dprod_Iirr.
Proof.
set D := codom _; have Df: dprod_Iirr _ \in D := codom_f dprod_Iirr _.
have: 'chi_k 1%g ^+ 2 != 0 by rewrite mulf_neq0 ?irr1_neq0.
apply: contraR => notDk; move/eqP: (irr_sum_square G).
rewrite (bigID [in D]) (reindex _ (bij_on_codom dprod_Iirr_inj (0, 0))) /=.
have ->: #|G|%:R = \sum_i \sum_j 'chi_(dprod_Iirr (i, j)) 1%g ^+ 2.
rewrite -(dprod_card KxH) natrM.
do 2![rewrite -irr_sum_square (mulr_suml, mulr_sumr); apply: eq_bigr => ? _].
by rewrite dprod_IirrE -exprMn -{3}(mulg1 1%g) cfDprodE.
rewrite (eq_bigl _ _ Df) pair_bigA addrC -subr_eq0 addrK.
by move/eqP/psumr_eq0P=> -> //= i _; rewrite irr1_degree -natrX ler0n.
Qed.
Definition inv_dprod_Iirr i := iinv (dprod_Iirr_onto i).
Lemma dprod_IirrK : cancel dprod_Iirr inv_dprod_Iirr.
Proof. by move=> p; apply: (iinv_f dprod_Iirr_inj). Qed.
Lemma inv_dprod_IirrK : cancel inv_dprod_Iirr dprod_Iirr.
Proof. by move=> i; apply: f_iinv. Qed.
Lemma inv_dprod_Iirr0 : inv_dprod_Iirr 0 = (0, 0).
Proof. by apply/(canLR dprod_IirrK); rewrite dprod_Iirr0. Qed.
End DProd.
Arguments dprod_Iirr_inj {gT G K H} KxH [i1 i2] : rename.
Lemma dprod_IirrC (gT : finGroupType) (G K H : {group gT})
(KxH : K \x H = G) (HxK : H \x K = G) i j :
dprod_Iirr KxH (i, j) = dprod_Iirr HxK (j, i).
Proof. by apply: irr_inj; rewrite !dprod_IirrE; apply: cfDprodC. Qed.
Section BigDprod.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Let sAG i : P i -> A i \subset G.
Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed.
Lemma cfBigdprodi_char i (phi : 'CF(A i)) :
phi \is a character -> cfBigdprodi defG phi \is a character.
Proof. by move=> Nphi; rewrite cfDprodl_char cfRes_char. Qed.
Lemma cfBigdprodi_charE i (phi : 'CF(A i)) :
P i -> (cfBigdprodi defG phi \is a character) = (phi \is a character).
Proof. by move=> Pi; rewrite cfDprodl_char Pi cfRes_id. Qed.
Lemma cfBigdprod_char phi :
(forall i, P i -> phi i \is a character) ->
cfBigdprod defG phi \is a character.
Proof.
by move=> Nphi; apply: rpred_prod => i /Nphi; apply: cfBigdprodi_char.
Qed.
Lemma cfBigdprodi_lin_char i (phi : 'CF(A i)) :
phi \is a linear_char -> cfBigdprodi defG phi \is a linear_char.
Proof. by move=> Lphi; rewrite cfDprodl_lin_char ?cfRes_lin_char. Qed.
Lemma cfBigdprodi_lin_charE i (phi : 'CF(A i)) :
P i -> (cfBigdprodi defG phi \is a linear_char) = (phi \is a linear_char).
Proof. by move=> Pi; rewrite qualifE/= cfBigdprodi_charE // cfBigdprodi1. Qed.
Lemma cfBigdprod_lin_char phi :
(forall i, P i -> phi i \is a linear_char) ->
cfBigdprod defG phi \is a linear_char.
Proof.
by move=> Lphi; apply/rpred_prod=> i /Lphi; apply: cfBigdprodi_lin_char.
Qed.
Lemma cfBigdprodi_irr i chi :
P i -> (cfBigdprodi defG chi \in irr G) = (chi \in irr (A i)).
Proof. by move=> Pi; rewrite !irrEchar cfBigdprodi_charE ?cfBigdprodi_iso. Qed.
Lemma cfBigdprod_irr chi :
(forall i, P i -> chi i \in irr (A i)) -> cfBigdprod defG chi \in irr G.
Proof.
move=> Nchi; rewrite irrEchar cfBigdprod_char => [|i /Nchi/irrWchar] //=.
by rewrite cfdot_bigdprod big1 // => i /Nchi/irrWnorm.
Qed.
Lemma cfBigdprod_eq1 phi :
(forall i, P i -> phi i \is a character) ->
(cfBigdprod defG phi == 1) = [forall (i | P i), phi i == 1].
Proof.
move=> Nphi; set Phi := cfBigdprod defG phi.
apply/eqP/eqfun_inP=> [Phi1 i Pi | phi1]; last first.
by apply: big1 => i /phi1->; rewrite rmorph1.
have Phi1_1: Phi 1%g = 1 by rewrite Phi1 cfun1E group1.
have nz_Phi1: Phi 1%g != 0 by rewrite Phi1_1 oner_eq0.
have [_ <-] := cfBigdprodK nz_Phi1 Pi.
rewrite Phi1_1 divr1 -/Phi Phi1 rmorph1.
rewrite prod_cfunE // in Phi1_1; have := natr_prod_eq1 _ Phi1_1 Pi.
rewrite -(cfRes1 (A i)) cfBigdprodiK // => ->; first by rewrite scale1r.
by move=> {i Pi} j /Nphi Nphi_j; rewrite Cnat_char1 ?cfBigdprodi_char.
Qed.
Lemma cfBigdprod_Res_lin chi :
chi \is a linear_char -> cfBigdprod defG (fun i => 'Res[A i] chi) = chi.
Proof.
move=> Lchi; apply/cfun_inP=> _ /(mem_bigdprod defG)[x [Ax -> _]].
rewrite (lin_char_prod Lchi) ?cfBigdprodE // => [|i Pi]; last first.
by rewrite (subsetP (sAG Pi)) ?Ax.
by apply/eq_bigr=> i Pi; rewrite cfResE ?sAG ?Ax.
Qed.
Lemma cfBigdprodKlin phi :
(forall i, P i -> phi i \is a linear_char) ->
forall i, P i -> 'Res (cfBigdprod defG phi) = phi i.
Proof.
move=> Lphi i Pi; have Lpsi := cfBigdprod_lin_char Lphi.
have [_ <-] := cfBigdprodK (lin_char_neq0 Lpsi (group1 G)) Pi.
by rewrite !lin_char1 ?Lphi // divr1 scale1r.
Qed.
Lemma cfBigdprodKabelian Iphi (phi := fun i => 'chi_(Iphi i)) :
abelian G -> forall i, P i -> 'Res (cfBigdprod defG phi) = 'chi_(Iphi i).
Proof.
move=> /(abelianS _) cGG.
by apply: cfBigdprodKlin => i /sAG/cGG/char_abelianP->.
Qed.
End BigDprod.
Section Aut.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Type u : {rmorphism algC -> algC}.
Lemma conjC_charAut u (chi : 'CF(G)) x :
chi \is a character -> (u (chi x))^* = u (chi x)^*.
Proof.
have [Gx | /cfun0->] := boolP (x \in G); last by rewrite !rmorph0.
case/char_reprP=> rG ->; have [e [_ [en1 _] [-> _] _]] := repr_rsim_diag rG Gx.
by rewrite !rmorph_sum; apply: eq_bigr => i _; apply: aut_unity_rootC (en1 i).
Qed.
Lemma conjC_irrAut u i x : (u ('chi[G]_i x))^* = u ('chi_i x)^*.
Proof. exact: conjC_charAut (irr_char i). Qed.
Lemma cfdot_aut_char u (phi chi : 'CF(G)) :
chi \is a character -> '[cfAut u phi, cfAut u chi] = u '[phi, chi].
Proof. by move/conjC_charAut=> Nchi; apply: cfdot_cfAut => _ /mapP[x _ ->]. Qed.
Lemma cfdot_aut_irr u phi i :
'[cfAut u phi, cfAut u 'chi[G]_i] = u '[phi, 'chi_i].
Proof. exact: cfdot_aut_char (irr_char i). Qed.
Lemma cfAut_irr u chi : (cfAut u chi \in irr G) = (chi \in irr G).
Proof.
rewrite !irrEchar cfAut_char; apply/andb_id2l=> /cfdot_aut_char->.
exact: fmorph_eq1.
Qed.
Lemma cfConjC_irr i : (('chi_i)^*)%CF \in irr G.
Proof. by rewrite cfAut_irr mem_irr. Qed.
Lemma irr_aut_closed u : cfAut_closed u (irr G).
Proof. by move=> chi; rewrite /= cfAut_irr. Qed.
Definition aut_Iirr u i := cfIirr (cfAut u 'chi[G]_i).
Lemma aut_IirrE u i : 'chi_(aut_Iirr u i) = cfAut u 'chi_i.
Proof. by rewrite cfIirrE ?cfAut_irr ?mem_irr. Qed.
Definition conjC_Iirr := aut_Iirr conjC.
Lemma conjC_IirrE i : 'chi[G]_(conjC_Iirr i) = ('chi_i)^*%CF.
Proof. exact: aut_IirrE. Qed.
Lemma conjC_IirrK : involutive conjC_Iirr.
Proof. by move=> i; apply: irr_inj; rewrite !conjC_IirrE cfConjCK. Qed.
Lemma aut_Iirr0 u : aut_Iirr u 0 = 0 :> Iirr G.
Proof. by apply/irr_inj; rewrite aut_IirrE irr0 cfAut_cfun1. Qed.
Lemma conjC_Iirr0 : conjC_Iirr 0 = 0 :> Iirr G.
Proof. exact: aut_Iirr0. Qed.
Lemma aut_Iirr_eq0 u i : (aut_Iirr u i == 0) = (i == 0).
Proof. by rewrite -!irr_eq1 aut_IirrE cfAut_eq1. Qed.
Lemma conjC_Iirr_eq0 i : (conjC_Iirr i == 0 :> Iirr G) = (i == 0).
Proof. exact: aut_Iirr_eq0. Qed.
Lemma aut_Iirr_inj u : injective (aut_Iirr u).
Proof.
by move=> i j eq_ij; apply/irr_inj/(cfAut_inj u); rewrite -!aut_IirrE eq_ij.
Qed.
End Aut.
Arguments aut_Iirr_inj {gT G} u [i1 i2] : rename.
Arguments conjC_IirrK {gT G} i : rename.
Section Coset.
Variable (gT : finGroupType).
Implicit Types G H : {group gT}.
Lemma cfQuo_char G H (chi : 'CF(G)) :
chi \is a character -> (chi / H)%CF \is a character.
Proof.
move=> Nchi; without loss kerH: / H \subset cfker chi.
move/contraNF=> IHchi; apply/wlog_neg=> N'chiH.
suffices ->: (chi / H)%CF = (chi 1%g)%:A.
by rewrite rpredZ_nat ?Cnat_char1 ?rpred1.
by apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr cfunElock IHchi.
without loss nsHG: G chi Nchi kerH / H <| G.
move=> IHchi; have nsHN := normalSG (subset_trans kerH (cfker_sub chi)).
rewrite cfQuoInorm//; apply/cfRes_char/IHchi => //; first exact: cfRes_char.
by apply: sub_cfker_Res => //; apply: normal_sub.
have [rG Dchi] := char_reprP Nchi; rewrite Dchi cfker_repr in kerH.
apply/char_reprP; exists (Representation (quo_repr kerH (normal_norm nsHG))).
apply/cfun_inP=> _ /morphimP[x nHx Gx ->]; rewrite Dchi cfQuoE ?cfker_repr //=.
by rewrite !cfunE Gx quo_repr_coset ?mem_quotient.
Qed.
Lemma cfQuo_lin_char G H (chi : 'CF(G)) :
chi \is a linear_char -> (chi / H)%CF \is a linear_char.
Proof. by case/andP=> Nchi; rewrite qualifE/= cfQuo_char ?cfQuo1. Qed.
Lemma cfMod_char G H (chi : 'CF(G / H)) :
chi \is a character -> (chi %% H)%CF \is a character.
Proof. exact: cfMorph_char. Qed.
Lemma cfMod_lin_char G H (chi : 'CF(G / H)) :
chi \is a linear_char -> (chi %% H)%CF \is a linear_char.
Proof. exact: cfMorph_lin_char. Qed.
Lemma cfMod_charE G H (chi : 'CF(G / H)) :
H <| G -> (chi %% H \is a character)%CF = (chi \is a character).
Proof. by case/andP=> _; apply: cfMorph_charE. Qed.
Lemma cfMod_lin_charE G H (chi : 'CF(G / H)) :
H <| G -> (chi %% H \is a linear_char)%CF = (chi \is a linear_char).
Proof. by case/andP=> _; apply: cfMorph_lin_charE. Qed.
Lemma cfQuo_charE G H (chi : 'CF(G)) :
H <| G -> H \subset cfker chi ->
(chi / H \is a character)%CF = (chi \is a character).
Proof. by move=> nsHG kerH; rewrite -cfMod_charE ?cfQuoK. Qed.
Lemma cfQuo_lin_charE G H (chi : 'CF(G)) :
H <| G -> H \subset cfker chi ->
(chi / H \is a linear_char)%CF = (chi \is a linear_char).
Proof. by move=> nsHG kerH; rewrite -cfMod_lin_charE ?cfQuoK. Qed.
Lemma cfMod_irr G H chi :
H <| G -> (chi %% H \in irr G)%CF = (chi \in irr (G / H)).
Proof. by case/andP=> _; apply: cfMorph_irr. Qed.
Definition mod_Iirr G H i := cfIirr ('chi[G / H]_i %% H)%CF.
Lemma mod_Iirr0 G H : mod_Iirr (0 : Iirr (G / H)) = 0.
Proof. exact: morph_Iirr0. Qed.
Lemma mod_IirrE G H i : H <| G -> 'chi_(mod_Iirr i) = ('chi[G / H]_i %% H)%CF.
Proof. by move=> nsHG; rewrite cfIirrE ?cfMod_irr ?mem_irr. Qed.
Lemma mod_Iirr_eq0 G H i :
H <| G -> (mod_Iirr i == 0) = (i == 0 :> Iirr (G / H)).
Proof. by case/andP=> _ /morph_Iirr_eq0->. Qed.
Lemma cfQuo_irr G H chi :
H <| G -> H \subset cfker chi ->
((chi / H)%CF \in irr (G / H)) = (chi \in irr G).
Proof. by move=> nsHG kerH; rewrite -cfMod_irr ?cfQuoK. Qed.
Definition quo_Iirr G H i := cfIirr ('chi[G]_i / H)%CF.
Lemma quo_Iirr0 G H : quo_Iirr H (0 : Iirr G) = 0.
Proof. by rewrite /quo_Iirr irr0 cfQuo_cfun1 -irr0 irrK. Qed.
Lemma quo_IirrE G H i :
H <| G -> H \subset cfker 'chi[G]_i -> 'chi_(quo_Iirr H i) = ('chi_i / H)%CF.
Proof. by move=> nsHG kerH; rewrite cfIirrE ?cfQuo_irr ?mem_irr. Qed.
Lemma quo_Iirr_eq0 G H i :
H <| G -> H \subset cfker 'chi[G]_i -> (quo_Iirr H i == 0) = (i == 0).
Proof. by move=> nsHG kerH; rewrite -!irr_eq1 quo_IirrE ?cfQuo_eq1. Qed.
Lemma mod_IirrK G H : H <| G -> cancel (@mod_Iirr G H) (@quo_Iirr G H).
Proof.
move=> nsHG i; apply: irr_inj.
by rewrite quo_IirrE ?mod_IirrE ?cfker_mod // cfModK.
Qed.
Lemma quo_IirrK G H i :
H <| G -> H \subset cfker 'chi[G]_i -> mod_Iirr (quo_Iirr H i) = i.
Proof.
by move=> nsHG kerH; apply: irr_inj; rewrite mod_IirrE ?quo_IirrE ?cfQuoK.
Qed.
Lemma quo_IirrKeq G H :
H <| G ->
forall i, (mod_Iirr (quo_Iirr H i) == i) = (H \subset cfker 'chi[G]_i).
Proof.
move=> nsHG i; apply/eqP/idP=> [<- | ]; last exact: quo_IirrK.
by rewrite mod_IirrE ?cfker_mod.
Qed.
Lemma mod_Iirr_bij H G :
H <| G -> {on [pred i | H \subset cfker 'chi_i], bijective (@mod_Iirr G H)}.
Proof.
by exists (quo_Iirr H) => [i _ | i]; [apply: mod_IirrK | apply: quo_IirrK].
Qed.
Lemma sum_norm_irr_quo H G x :
x \in G -> H <| G ->
\sum_i `|'chi[G / H]_i (coset H x)| ^+ 2
= \sum_(i | H \subset cfker 'chi_i) `|'chi[G]_i x| ^+ 2.
Proof.
move=> Gx nsHG; rewrite (reindex _ (mod_Iirr_bij nsHG)) /=.
by apply/esym/eq_big=> [i | i _]; rewrite mod_IirrE ?cfker_mod ?cfModE.
Qed.
Lemma cap_cfker_normal G H :
H <| G -> \bigcap_(i | H \subset cfker 'chi[G]_i) (cfker 'chi_i) = H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG; set lhs := \bigcap_(i | _) _.
have nHlhs: lhs \subset 'N(H) by rewrite (bigcap_min 0) ?cfker_irr0.
apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) //= -quotient_sub1 //.
rewrite -(TI_cfker_irr (G / H)); apply/bigcapsP=> i _.
rewrite sub_quotient_pre // (bigcap_min (mod_Iirr i)) ?mod_IirrE ?cfker_mod //.
by rewrite cfker_morph ?subsetIr.
Qed.
Lemma cfker_reg_quo G H : H <| G -> cfker (cfReg (G / H)%g %% H) = H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG.
apply/setP=> x; rewrite cfkerEchar ?cfMod_char ?cfReg_char //.
rewrite -[in RHS in _ = RHS](setIidPr sHG) !inE; apply: andb_id2l => Gx.
rewrite !cfModE // !cfRegE // morph1 eqxx.
rewrite (sameP eqP (kerP _ (subsetP nHG x Gx))) ker_coset.
by rewrite -!mulrnA eqr_nat eqn_pmul2l ?cardG_gt0 // (can_eq oddb) eqb_id.
Qed.
End Coset.
Section DerivedGroup.
Variable gT : finGroupType.
Implicit Types G H : {group gT}.
Lemma lin_irr_der1 G i :
('chi_i \is a linear_char) = (G^`(1)%g \subset cfker 'chi[G]_i).
Proof.
apply/idP/idP=> [|sG'K]; first exact: lin_char_der1.
have nsG'G: G^`(1) <| G := der_normal 1 G.
rewrite qualifE/= irr_char -[i](quo_IirrK nsG'G) // mod_IirrE //=.
by rewrite cfModE // morph1 lin_char1 //; apply/char_abelianP/der_abelian.
Qed.
Lemma subGcfker G i : (G \subset cfker 'chi[G]_i) = (i == 0).
Proof.
rewrite -irr_eq1; apply/idP/eqP=> [chiG1 | ->]; last by rewrite cfker_cfun1.
apply/cfun_inP=> x Gx; rewrite cfun1E Gx cfker1 ?(subsetP chiG1) ?lin_char1 //.
by rewrite lin_irr_der1 (subset_trans (der_sub 1 G)).
Qed.
Lemma irr_prime_injP G i :
prime #|G| -> reflect {in G &, injective 'chi[G]_i} (i != 0).
Proof.
move=> pr_G; apply: (iffP idP) => [nz_i | inj_chi].
apply: fful_lin_char_inj (irr_prime_lin i pr_G) _.
by rewrite cfaithfulE -(setIidPr (cfker_sub _)) prime_TIg // subGcfker.
have /trivgPn[x Gx ntx]: G :!=: 1%g by rewrite -cardG_gt1 prime_gt1.
apply: contraNneq ntx => i0; apply/eqP/inj_chi=> //.
by rewrite i0 irr0 !cfun1E Gx group1.
Qed.
(* This is Isaacs (2.23)(a). *)
Lemma cap_cfker_lin_irr G :
\bigcap_(i | 'chi[G]_i \is a linear_char) (cfker 'chi_i) = G^`(1)%g.
Proof.
rewrite -(cap_cfker_normal (der_normal 1 G)).
by apply: eq_bigl => i; rewrite lin_irr_der1.
Qed.
(* This is Isaacs (2.23)(b) *)
Lemma card_lin_irr G :
#|[pred i | 'chi[G]_i \is a linear_char]| = #|G : G^`(1)%g|.
Proof.
have nsG'G := der_normal 1 G; rewrite (eq_card (@lin_irr_der1 G)).
rewrite -(on_card_preimset (mod_Iirr_bij nsG'G)).
rewrite -card_quotient ?normal_norm //.
move: (der_abelian 0 G); rewrite card_classes_abelian; move/eqP<-.
rewrite -NirrE -[RHS]card_ord.
by apply: eq_card => i; rewrite !inE mod_IirrE ?cfker_mod.
(* Alternative: use the equivalent result in modular representation theory
transitivity #|@socle_of_Iirr _ G @^-1: linear_irr _|; last first.
rewrite (on_card_preimset (socle_of_Iirr_bij _)).
by rewrite card_linear_irr ?algC'G; last apply: groupC.
by apply: eq_card => i; rewrite !inE /lin_char irr_char irr1_degree -eqC_nat.
*)
Qed.
(* A non-trivial solvable group has a nonprincipal linear character. *)
Lemma solvable_has_lin_char G :
G :!=: 1%g -> solvable G ->
exists2 i, 'chi[G]_i \is a linear_char & 'chi_i != 1.
Proof.
move=> ntG solG.
suff /subsetPn[i]: ~~ ([pred i | 'chi[G]_i \is a linear_char] \subset pred1 0).
by rewrite !inE -(inj_eq irr_inj) irr0; exists i.
rewrite (contra (@subset_leq_card _ _ _)) // -ltnNge card1 card_lin_irr.
by rewrite indexg_gt1 proper_subn // (sol_der1_proper solG).
Qed.
(* A combinatorial group isommorphic to the linear characters. *)
Lemma lin_char_group G :
{linG : finGroupType & {cF : linG -> 'CF(G) |
[/\ injective cF, #|linG| = #|G : G^`(1)|,
forall u, cF u \is a linear_char
& forall phi, phi \is a linear_char -> exists u, phi = cF u]
& [/\ cF 1%g = 1%R,
{morph cF : u v / (u * v)%g >-> (u * v)%R},
forall k, {morph cF : u / (u^+ k)%g >-> u ^+ k},
{morph cF: u / u^-1%g >-> u^-1%CF}
& {mono cF: u / #[u]%g >-> #[u]%CF} ]}}.
Proof.
pose linT := {i : Iirr G | 'chi_i \is a linear_char}.
pose cF (u : linT) := 'chi_(sval u).
have cFlin u: cF u \is a linear_char := svalP u.
have cFinj: injective cF := inj_comp irr_inj val_inj.
have inT xi : xi \is a linear_char -> {u | cF u = xi}.
move=> lin_xi; have /irrP/sig_eqW[i Dxi] := lin_char_irr lin_xi.
by apply: (exist _ (Sub i _)) => //; rewrite -Dxi.
have [one cFone] := inT 1 (rpred1 _).
pose inv u := sval (inT _ (rpredVr (cFlin u))).
pose mul u v := sval (inT _ (rpredM (cFlin u) (cFlin v))).
have cFmul u v: cF (mul u v) = cF u * cF v := svalP (inT _ _).
have cFinv u: cF (inv u) = (cF u)^-1 := svalP (inT _ _).
have mulA: associative mul by move=> u v w; apply: cFinj; rewrite !cFmul mulrA.
have mul1: left_id one mul by move=> u; apply: cFinj; rewrite cFmul cFone mul1r.
have mulV: left_inverse one inv mul.
by move=> u; apply: cFinj; rewrite cFmul cFinv cFone mulVr ?lin_char_unitr.
pose imA := isMulGroup.Build linT mulA mul1 mulV.
pose linG : finGroupType := HB.pack linT imA.
have cFexp k: {morph cF : u / ((u : linG) ^+ k)%g >-> u ^+ k}.
by move=> u; elim: k => // k IHk; rewrite expgS exprS cFmul IHk.
do [exists linG, cF; split=> //] => [|xi /inT[u <-]|u]; first 2 [by exists u].
have inj_cFI: injective (cfIirr \o cF).
apply: can_inj (insubd one) _ => u; apply: val_inj.
by rewrite insubdK /= ?irrK //; apply: cFlin.
rewrite -(card_image inj_cFI) -card_lin_irr.
apply/eq_card=> i /[1!inE]; apply/codomP/idP=> [[u ->] | /inT[u Du]].
by rewrite /= irrK; apply: cFlin.
by exists u; apply: irr_inj; rewrite /= irrK.
apply/eqP; rewrite eqn_dvd; apply/andP; split.
by rewrite dvdn_cforder; rewrite -cFexp expg_order cFone.
by rewrite order_dvdn -(inj_eq cFinj) cFone cFexp exp_cforder.
Qed.
Lemma cfExp_prime_transitive G (i j : Iirr G) :
prime #|G| -> i != 0 -> j != 0 ->
exists2 k, coprime k #['chi_i]%CF & 'chi_j = 'chi_i ^+ k.
Proof.
set p := #|G| => pr_p nz_i nz_j; have cycG := prime_cyclic pr_p.
have [L [h [injh oL Lh h_ontoL]] [h1 hM hX _ o_h]] := lin_char_group G.
rewrite (derG1P (cyclic_abelian cycG)) indexg1 -/p in oL.
have /fin_all_exists[h' h'K] := h_ontoL _ (irr_cyclic_lin _ cycG).
have o_h' k: k != 0 -> #[h' k] = p.
rewrite -cforder_irr_eq1 h'K -o_h => nt_h'k.
by apply/prime_nt_dvdP=> //; rewrite cforder_lin_char_dvdG.
have{oL} genL k: k != 0 -> generator [set: L] (h' k).
move=> /o_h' o_h'k; rewrite /generator eq_sym eqEcard subsetT /=.
by rewrite cardsT oL -o_h'k.
have [/(_ =P <[_]>)-> gen_j] := (genL i nz_i, genL j nz_j).
have /cycleP[k Dj] := cycle_generator gen_j.
by rewrite !h'K Dj o_h hX generator_coprime coprime_sym in gen_j *; exists k.
Qed.
(* This is Isaacs (2.24). *)
Lemma card_subcent1_coset G H x :
x \in G -> H <| G -> (#|'C_(G / H)[coset H x]| <= #|'C_G[x]|)%N.
Proof.
move=> Gx nsHG; rewrite -leC_nat.
move: (second_orthogonality_relation x Gx); rewrite mulrb class_refl => <-.
have GHx: coset H x \in (G / H)%g by apply: mem_quotient.
move: (second_orthogonality_relation (coset H x) GHx).
rewrite mulrb class_refl => <-.
rewrite -2!(eq_bigr _ (fun _ _ => normCK _)) sum_norm_irr_quo // -subr_ge0.
rewrite (bigID (fun i => H \subset cfker 'chi[G]_i)) //= [X in X + _]addrC addrK.
by apply: sumr_ge0 => i _; rewrite normCK mul_conjC_ge0.
Qed.
End DerivedGroup.
Arguments irr_prime_injP {gT G i}.
(* Determinant characters and determinential order. *)
Section DetRepr.
Variables (gT : finGroupType) (G : {group gT}).
Variables (n : nat) (rG : mx_representation algC G n).
Definition det_repr_mx x : 'M_1 := (\det (rG x))%:M.
Fact det_is_repr : mx_repr G det_repr_mx.
Proof.
split=> [|g h Gg Gh]; first by rewrite /det_repr_mx repr_mx1 det1.
by rewrite /det_repr_mx repr_mxM // det_mulmx !mulmxE scalar_mxM.
Qed.
Canonical det_repr := MxRepresentation det_is_repr.
Definition detRepr := cfRepr det_repr.
Lemma detRepr_lin_char : detRepr \is a linear_char.
Proof.
by rewrite qualifE/= cfRepr_char cfunE group1 repr_mx1 mxtrace1 mulr1n /=.
Qed.
End DetRepr.
HB.lock
Definition cfDet (gT : finGroupType) (G : {group gT}) phi :=
\prod_i detRepr 'Chi_i ^+ Num.truncn '[phi, 'chi[G]_i].
Canonical cfDet_unlockable := Unlockable cfDet.unlock.
Section DetOrder.
Variables (gT : finGroupType) (G : {group gT}).
Local Notation cfDet := (@cfDet gT G).
Lemma cfDet_lin_char phi : cfDet phi \is a linear_char.
Proof.
rewrite unlock; apply: rpred_prod => i _; apply: rpredX.
exact: detRepr_lin_char.
Qed.
Lemma cfDetD :
{in character &, {morph cfDet : phi psi / phi + psi >-> phi * psi}}.
Proof.
move=> phi psi Nphi Npsi; rewrite unlock /= -big_split; apply: eq_bigr => i _ /=.
by rewrite -exprD cfdotDl truncnD ?nnegrE ?natr_ge0 // Cnat_cfdot_char_irr.
Qed.
Lemma cfDet0 : cfDet 0 = 1.
Proof. by rewrite unlock big1 // => i _; rewrite cfdot0l truncn0. Qed.
Lemma cfDetMn k :
{in character, {morph cfDet : phi / phi *+ k >-> phi ^+ k}}.
Proof.
move=> phi Nphi; elim: k => [|k IHk]; rewrite ?cfDet0 // mulrS exprS -{}IHk.
by rewrite cfDetD ?rpredMn.
Qed.
Lemma cfDetRepr n rG : cfDet (cfRepr rG) = @detRepr _ _ n rG.
Proof.
transitivity (\prod_W detRepr (socle_repr W) ^+ standard_irr_coef rG W).
rewrite (reindex _ (socle_of_Iirr_bij _)) unlock /=.
apply: eq_bigr => i _; congr (_ ^+ _).
rewrite (cfRepr_sim (mx_rsim_standard rG)) cfRepr_standard.
rewrite cfdot_suml (bigD1 i) ?big1 //= => [|j i'j]; last first.
by rewrite cfdotZl cfdot_irr (negPf i'j) mulr0.
by rewrite cfdotZl cfnorm_irr mulr1 addr0 natrK.
apply/cfun_inP=> x Gx; rewrite prod_cfunE //.
transitivity (detRepr (standard_grepr rG) x); last first.
rewrite !cfunE Gx !trace_mx11 !mxE eqxx !mulrb.
case: (standard_grepr rG) (mx_rsim_standard rG) => /= n1 rG1 [B Dn1].
rewrite -{n1}Dn1 in rG1 B *; rewrite row_free_unit => uB rG_B.
by rewrite -[rG x](mulmxK uB) rG_B // !det_mulmx mulrC -!det_mulmx mulKmx.
rewrite /standard_grepr; elim/big_rec2: _ => [|W y _ _ ->].
by rewrite cfunE trace_mx11 mxE Gx det1.
rewrite !cfunE Gx /= !{1}trace_mx11 !{1}mxE det_ublock; congr (_ * _).
rewrite exp_cfunE //; elim: (standard_irr_coef rG W) => /= [|k IHk].
by rewrite /muln_grepr big_ord0 det1.
rewrite exprS /muln_grepr big_ord_recl det_ublock -IHk; congr (_ * _).
by rewrite cfunE trace_mx11 mxE Gx.
Qed.
Lemma cfDet_id xi : xi \is a linear_char -> cfDet xi = xi.
Proof.
move=> lin_xi; have /irrP[i Dxi] := lin_char_irr lin_xi.
apply/cfun_inP=> x Gx; rewrite Dxi -irrRepr cfDetRepr !cfunE trace_mx11 mxE.
move: lin_xi (_ x) => /andP[_]; rewrite Dxi irr1_degree pnatr_eq1 => /eqP-> X.
by rewrite {1}[X]mx11_scalar det_scalar1 trace_mx11.
Qed.
Definition cfDet_order phi := #[cfDet phi]%CF.
Definition cfDet_order_lin xi :
xi \is a linear_char -> cfDet_order xi = #[xi]%CF.
Proof. by rewrite /cfDet_order => /cfDet_id->. Qed.
Definition cfDet_order_dvdG phi : cfDet_order phi %| #|G|.
Proof. by rewrite cforder_lin_char_dvdG ?cfDet_lin_char. Qed.
End DetOrder.
Notation "''o' ( phi )" := (cfDet_order phi)
(format "''o' ( phi )") : cfun_scope.
Section CfDetOps.
Implicit Types gT aT rT : finGroupType.
Lemma cfDetRes gT (G H : {group gT}) phi :
phi \is a character -> cfDet ('Res[H, G] phi) = 'Res (cfDet phi).
Proof.
move=> Nphi; have [sGH | not_sHG] := boolP (H \subset G); last first.
have /natrP[n Dphi1] := Cnat_char1 Nphi.
rewrite !cfResEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r.
by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n.
have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_sub, cfDetRepr) //.
apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx.
by rewrite mulmx1 mul1mx.
Qed.
Lemma cfDetMorph aT rT (D G : {group aT}) (f : {morphism D >-> rT})
(phi : 'CF(f @* G)) :
phi \is a character -> cfDet (cfMorph phi) = cfMorph (cfDet phi).
Proof.
move=> Nphi; have [sGD | not_sGD] := boolP (G \subset D); last first.
have /natrP[n Dphi1] := Cnat_char1 Nphi.
rewrite !cfMorphEout // Dphi1 lin_char1 ?cfDet_lin_char // scale1r.
by rewrite scaler_nat cfDetMn ?cfDet_id ?rpred1 // expr1n.
have [rG ->] := char_reprP Nphi; rewrite !(=^~ cfRepr_morphim, cfDetRepr) //.
apply: cfRepr_sim; exists 1%:M; rewrite ?row_free_unit ?unitmx1 // => x Hx.
by rewrite mulmx1 mul1mx.
Qed.
Lemma cfDetIsom aT rT (G : {group aT}) (R : {group rT})
(f : {morphism G >-> rT}) (isoGR : isom G R f) phi :
cfDet (cfIsom isoGR phi) = cfIsom isoGR (cfDet phi).
Proof.
rewrite unlock rmorph_prod (reindex (isom_Iirr isoGR)); last first.
by exists (isom_Iirr (isom_sym isoGR)) => i; rewrite ?isom_IirrK ?isom_IirrKV.
apply: eq_bigr=> i; rewrite -!cfDetRepr !irrRepr isom_IirrE rmorphXn cfIsom_iso.
by rewrite /= ![in cfIsom _]unlock cfDetMorph ?cfRes_char ?cfDetRes ?irr_char.
Qed.
Lemma cfDet_mul_lin gT (G : {group gT}) (lambda phi : 'CF(G)) :
lambda \is a linear_char -> phi \is a character ->
cfDet (lambda * phi) = lambda ^+ Num.truncn (phi 1%g) * cfDet phi.
Proof.
case/andP=> /char_reprP[[n1 rG1] ->] /= n1_1 /char_reprP[[n2 rG2] ->] /=.
do [rewrite !cfRepr1 pnatr_eq1 natrK; move/eqP] in n1_1 *.
rewrite {n1}n1_1 in rG1 *; rewrite cfRepr_prod cfDetRepr.
apply/cfun_inP=> x Gx; rewrite !cfunE cfDetRepr cfunE Gx !mulrb !trace_mx11.
rewrite !mxE prod_repr_lin ?mulrb //=; case: _ / (esym _); rewrite detZ.
congr (_ * _); case: {rG2}n2 => [|n2]; first by rewrite cfun1E Gx.
by rewrite expS_cfunE //= cfunE Gx trace_mx11.
Qed.
End CfDetOps.
Definition cfcenter (gT : finGroupType) (G : {set gT}) (phi : 'CF(G)) :=
if phi \is a character then [set g in G | `|phi g| == phi 1%g] else cfker phi.
Notation "''Z' ( phi )" := (cfcenter phi) : cfun_scope.
Section Center.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (phi chi : 'CF(G)) (H : {group gT}).
(* This is Isaacs (2.27)(a). *)
Lemma cfcenter_repr n (rG : mx_representation algC G n) :
'Z(cfRepr rG)%CF = rcenter rG.
Proof.
rewrite /cfcenter /rcenter cfRepr_char /=.
apply/setP=> x /[!inE]; apply/andb_id2l=> Gx.
apply/eqP/is_scalar_mxP=> [|[c rG_c]].
by case/max_cfRepr_norm_scalar=> // c; exists c.
rewrite -(sqrCK (char1_ge0 (cfRepr_char rG))) normC_def; congr (sqrtC _).
rewrite expr2 -{2}(mulgV x) -char_inv ?cfRepr_char ?cfunE ?groupM ?groupV //.
rewrite Gx group1 repr_mx1 repr_mxM ?repr_mxV ?groupV // !mulrb rG_c.
by rewrite invmx_scalar -scalar_mxM !mxtrace_scalar mulrnAr mulrnAl mulr_natl.
Qed.
(* This is part of Isaacs (2.27)(b). *)
Fact cfcenter_group_set phi : group_set ('Z(phi))%CF.
Proof.
have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ G phi).
by rewrite cfcenter_repr groupP.
by rewrite /cfcenter notNphi groupP.
Qed.
Canonical cfcenter_group f := Group (cfcenter_group_set f).
Lemma char_cfcenterE chi x :
chi \is a character -> x \in G ->
(x \in ('Z(chi))%CF) = (`|chi x| == chi 1%g).
Proof. by move=> Nchi Gx; rewrite /cfcenter Nchi inE Gx. Qed.
Lemma irr_cfcenterE i x :
x \in G -> (x \in 'Z('chi[G]_i)%CF) = (`|'chi_i x| == 'chi_i 1%g).
Proof. by move/char_cfcenterE->; rewrite ?irr_char. Qed.
(* This is also Isaacs (2.27)(b). *)
Lemma cfcenter_sub phi : ('Z(phi))%CF \subset G.
Proof. by rewrite /cfcenter /cfker !setIdE -fun_if subsetIl. Qed.
Lemma cfker_center_normal phi : cfker phi <| 'Z(phi)%CF.
Proof.
apply: normalS (cfcenter_sub phi) (cfker_normal phi).
rewrite /= /cfcenter; case: ifP => // Hphi; rewrite cfkerEchar //.
apply/subsetP=> x /[!inE] /andP[-> /eqP->] /=.
by rewrite ger0_norm ?char1_ge0.
Qed.
Lemma cfcenter_normal phi : 'Z(phi)%CF <| G.
Proof.
have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ phi).
by rewrite cfcenter_repr rcenter_normal.
by rewrite /cfcenter notNphi cfker_normal.
Qed.
(* This is Isaacs (2.27)(c). *)
Lemma cfcenter_Res chi :
exists2 chi1, chi1 \is a linear_char & 'Res['Z(chi)%CF] chi = chi 1%g *: chi1.
Proof.
have [[rG ->] | /negbTE notNphi] := altP (@char_reprP _ _ chi); last first.
exists 1; first exact: cfun1_lin_char.
rewrite /cfcenter notNphi; apply/cfun_inP=> x Kx.
by rewrite cfunE cfun1E Kx mulr1 cfResE ?cfker_sub // cfker1.
rewrite cfcenter_repr -(cfRepr_sub _ (normal_sub (rcenter_normal _))).
case: rG => [[|n] rG] /=; rewrite cfRepr1.
exists 1; first exact: cfun1_lin_char.
by apply/cfun_inP=> x Zx; rewrite scale0r !cfunE flatmx0 raddf0 Zx.
pose rZmx x := ((rG x 0 0)%:M : 'M_(1,1)).
have rZmxP: mx_repr [group of rcenter rG] rZmx.
split=> [|x y]; first by rewrite /rZmx repr_mx1 mxE eqxx.
move=> /setIdP[Gx /is_scalar_mxP[a rGx]] /setIdP[Gy /is_scalar_mxP[b rGy]].
by rewrite /rZmx repr_mxM // rGx rGy -!scalar_mxM !mxE.
exists (cfRepr (MxRepresentation rZmxP)).
by rewrite qualifE/= cfRepr_char cfRepr1 eqxx.
apply/cfun_inP=> x Zx; rewrite !cfunE Zx /= /rZmx mulr_natl.
by case/setIdP: Zx => Gx /is_scalar_mxP[a ->]; rewrite mxE !mxtrace_scalar.
Qed.
(* This is Isaacs (2.27)(d). *)
Lemma cfcenter_cyclic chi : cyclic ('Z(chi)%CF / cfker chi)%g.
Proof.
case Nchi: (chi \is a character); last first.
by rewrite /cfcenter Nchi trivg_quotient cyclic1.
have [-> | nz_chi] := eqVneq chi 0.
rewrite quotientS1 ?cyclic1 //= /cfcenter cfkerEchar ?cfun0_char //.
by apply/subsetP=> x /setIdP[Gx _]; rewrite inE Gx /= !cfunE.
have [xi Lxi def_chi] := cfcenter_Res chi.
set Z := ('Z(_))%CF in xi Lxi def_chi *.
have sZG: Z \subset G by apply: cfcenter_sub.
have ->: cfker chi = cfker xi.
rewrite -(setIidPr (normal_sub (cfker_center_normal _))) -/Z.
rewrite !cfkerEchar // ?lin_charW //= -/Z.
apply/setP=> x /[!inE]; apply: andb_id2l => Zx.
rewrite (subsetP sZG) //= -!(cfResE chi sZG) ?group1 // def_chi !cfunE.
by rewrite (inj_eq (mulfI _)) ?char1_eq0.
have: abelian (Z / cfker xi) by rewrite sub_der1_abelian ?lin_char_der1.
have /irr_reprP[rG irrG ->] := lin_char_irr Lxi; rewrite cfker_repr.
apply: mx_faithful_irr_abelian_cyclic (kquo_mx_faithful rG) _.
exact/quo_mx_irr.
Qed.
(* This is Isaacs (2.27)(e). *)
Lemma cfcenter_subset_center chi :
('Z(chi)%CF / cfker chi)%g \subset 'Z(G / cfker chi)%g.
Proof.
case Nchi: (chi \is a character); last first.
by rewrite /cfcenter Nchi trivg_quotient sub1G.
rewrite subsetI quotientS ?cfcenter_sub // quotient_cents2r //=.
case/char_reprP: Nchi => rG ->{chi}; rewrite cfker_repr cfcenter_repr gen_subG.
apply/subsetP=> _ /imset2P[x y /setIdP[Gx /is_scalar_mxP[c rGx]] Gy ->].
rewrite inE groupR //= !repr_mxM ?groupM ?groupV // rGx -(scalar_mxC c) -rGx.
by rewrite !mulmxA !repr_mxKV.
Qed.
(* This is Isaacs (2.27)(f). *)
Lemma cfcenter_eq_center (i : Iirr G) :
('Z('chi_i)%CF / cfker 'chi_i)%g = 'Z(G / cfker 'chi_i)%g.
Proof.
apply/eqP; rewrite eqEsubset; rewrite cfcenter_subset_center ?irr_char //.
apply/subsetP=> _ /setIP[/morphimP[x /= _ Gx ->] cGx]; rewrite mem_quotient //=.
rewrite -irrRepr cfker_repr cfcenter_repr inE Gx in cGx *.
apply: mx_abs_irr_cent_scalar 'Chi_i _ _ _; first exact/groupC/socle_irr.
have nKG: G \subset 'N(rker 'Chi_i) by apply: rker_norm.
(* GG -- locking here is critical to prevent Coq kernel divergence. *)
apply/centgmxP=> y Gy; rewrite [eq]lock -2?(quo_repr_coset (subxx _) nKG) //.
move: (quo_repr _ _) => rG; rewrite -2?repr_mxM ?mem_quotient // -lock.
by rewrite (centP cGx) // mem_quotient.
Qed.
(* This is Isaacs (2.28). *)
Lemma cap_cfcenter_irr : \bigcap_i 'Z('chi[G]_i)%CF = 'Z(G).
Proof.
apply/esym/eqP; rewrite eqEsubset (introT bigcapsP) /= => [|i _]; last first.
rewrite -(quotientSGK _ (normal_sub (cfker_center_normal _))).
by rewrite cfcenter_eq_center morphim_center.
by rewrite subIset // normal_norm // cfker_normal.
set Z := \bigcap_i _.
have sZG: Z \subset G by rewrite (bigcap_min 0) ?cfcenter_sub.
rewrite subsetI sZG (sameP commG1P trivgP) -(TI_cfker_irr G).
apply/bigcapsP=> i _; have nKiG := normal_norm (cfker_normal 'chi_i).
rewrite -quotient_cents2 ?(subset_trans sZG) //.
rewrite (subset_trans (quotientS _ (bigcap_inf i _))) //.
by rewrite cfcenter_eq_center subsetIr.
Qed.
(* This is Isaacs (2.29). *)
Lemma cfnorm_Res_leif H phi :
H \subset G ->
'['Res[H] phi] <= #|G : H|%:R * '[phi] ?= iff (phi \in 'CF(G, H)).
Proof.
move=> sHG; rewrite cfun_onE mulrCA natf_indexg // -mulrA mulKf ?neq0CG //.
rewrite (big_setID H) (setIidPr sHG) /= addrC.
rewrite (mono_leif (ler_pM2l _)) ?invr_gt0 ?gt0CG // -leifBLR -sumrB.
rewrite big1 => [|x Hx]; last by rewrite !cfResE ?subrr.
have ->: (support phi \subset H) = (G :\: H \subset [set x | phi x == 0]).
rewrite subDset setUC -subDset; apply: eq_subset => x.
by rewrite !inE (andb_idr (contraR _)) // => /cfun0->.
rewrite (sameP subsetP forall_inP); apply: leif_0_sum => x _.
by rewrite !inE /<?=%R mul_conjC_ge0 eq_sym mul_conjC_eq0.
Qed.
(* This is Isaacs (2.30). *)
Lemma irr1_bound (i : Iirr G) :
('chi_i 1%g) ^+ 2 <= #|G : 'Z('chi_i)%CF|%:R
?= iff ('chi_i \in 'CF(G, 'Z('chi_i)%CF)).
Proof.
congr (_ <= _ ?= iff _): (cfnorm_Res_leif 'chi_i (cfcenter_sub 'chi_i)).
have [xi Lxi ->] := cfcenter_Res 'chi_i.
have /irrP[j ->] := lin_char_irr Lxi; rewrite cfdotZl cfdotZr cfdot_irr eqxx.
by rewrite mulr1 irr1_degree conjC_nat.
by rewrite cfdot_irr eqxx mulr1.
Qed.
(* This is Isaacs (2.31). *)
Lemma irr1_abelian_bound (i : Iirr G) :
abelian (G / 'Z('chi_i)%CF) -> ('chi_i 1%g) ^+ 2 = #|G : 'Z('chi_i)%CF|%:R.
Proof.
move=> AbGc; apply/eqP; rewrite irr1_bound cfun_onE; apply/subsetP=> x nz_chi_x.
have Gx: x \in G by apply: contraR nz_chi_x => /cfun0->.
have nKx := subsetP (normal_norm (cfker_normal 'chi_i)) _ Gx.
rewrite -(quotientGK (cfker_center_normal _)) inE nKx inE /=.
rewrite cfcenter_eq_center inE mem_quotient //=.
apply/centP=> _ /morphimP[y nKy Gy ->]; apply/commgP; rewrite -morphR //=.
set z := [~ x, y]; rewrite coset_id //.
have: z \in 'Z('chi_i)%CF.
apply: subsetP (mem_commg Gx Gy).
by rewrite der1_min // normal_norm ?cfcenter_normal.
rewrite -irrRepr cfker_repr cfcenter_repr !inE in nz_chi_x *.
case/andP=> Gz /is_scalar_mxP[c Chi_z]; rewrite Gz Chi_z mul1mx /=.
apply/eqP; congr _%:M; apply: (mulIf nz_chi_x); rewrite mul1r.
rewrite -{2}(cfunJ _ x Gy) conjg_mulR -/z !cfunE Gx groupM // !{1}mulrb.
by rewrite repr_mxM // Chi_z mul_mx_scalar mxtraceZ.
Qed.
(* This is Isaacs (2.32)(a). *)
Lemma irr_faithful_center i : cfaithful 'chi[G]_i -> cyclic 'Z(G).
Proof.
rewrite (isog_cyclic (isog_center (quotient1_isog G))) /=.
by move/trivgP <-; rewrite -cfcenter_eq_center cfcenter_cyclic.
Qed.
Lemma cfcenter_fful_irr i : cfaithful 'chi[G]_i -> 'Z('chi_i)%CF = 'Z(G).
Proof.
move/trivgP=> Ki1; have:= cfcenter_eq_center i; rewrite {}Ki1.
have inj1: 'injm (@coset gT 1%g) by rewrite ker_coset.
by rewrite -injm_center; first apply: injm_morphim_inj; rewrite ?norms1.
Qed.
(* This is Isaacs (2.32)(b). *)
Lemma pgroup_cyclic_faithful (p : nat) :
p.-group G -> cyclic 'Z(G) -> exists i, cfaithful 'chi[G]_i.
Proof.
pose Z := 'Ohm_1('Z(G)) => pG cycZG; have nilG := pgroup_nil pG.
have [-> | ntG] := eqsVneq G [1]; first by exists 0; apply: cfker_sub.
have{pG} [[p_pr _ _] pZ] := (pgroup_pdiv pG ntG, pgroupS (center_sub G) pG).
have ntZ: 'Z(G) != [1] by rewrite center_nil_eq1.
have{pZ} oZ: #|Z| = p by apply: Ohm1_cyclic_pgroup_prime.
apply/existsP; apply: contraR ntZ => /existsPn-not_ffulG.
rewrite -Ohm1_eq1 -subG1 /= -/Z -(TI_cfker_irr G); apply/bigcapsP=> i _.
rewrite prime_meetG ?oZ // setIC meet_Ohm1 // meet_center_nil ?cfker_normal //.
by rewrite -subG1 not_ffulG.
Qed.
End Center.
Section Induced.
Variables (gT : finGroupType) (G H : {group gT}).
Implicit Types (phi : 'CF(G)) (chi : 'CF(H)).
Lemma cfInd_char chi : chi \is a character -> 'Ind[G] chi \is a character.
Proof.
move=> Nchi; apply/forallP=> i; rewrite coord_cfdot -Frobenius_reciprocity //.
by rewrite Cnat_cfdot_char ?cfRes_char ?irr_char.
Qed.
Lemma cfInd_eq0 chi :
H \subset G -> chi \is a character -> ('Ind[G] chi == 0) = (chi == 0).
Proof.
move=> sHG Nchi; rewrite -!(char1_eq0) ?cfInd_char // cfInd1 //.
by rewrite (mulrI_eq0 _ (mulfI _)) ?neq0CiG.
Qed.
Lemma Ind_irr_neq0 i : H \subset G -> 'Ind[G, H] 'chi_i != 0.
Proof. by move/cfInd_eq0->; rewrite ?irr_neq0 ?irr_char. Qed.
Definition Ind_Iirr (A B : {set gT}) i := cfIirr ('Ind[B, A] 'chi_i).
Lemma constt_cfRes_irr i : {j | j \in irr_constt ('Res[H, G] 'chi_i)}.
Proof. apply/sigW/neq0_has_constt/Res_irr_neq0. Qed.
Lemma constt_cfInd_irr i :
H \subset G -> {j | j \in irr_constt ('Ind[G, H] 'chi_i)}.
Proof. by move=> sHG; apply/sigW/neq0_has_constt/Ind_irr_neq0. Qed.
Lemma cfker_Res phi :
H \subset G -> phi \is a character -> cfker ('Res[H] phi) = H :&: cfker phi.
Proof.
move=> sHG Nphi; apply/setP=> x; rewrite !cfkerEchar ?cfRes_char // !inE.
by apply/andb_id2l=> Hx; rewrite (subsetP sHG) ?cfResE.
Qed.
(* This is Isaacs Lemma (5.11). *)
Lemma cfker_Ind chi :
H \subset G -> chi \is a character -> chi != 0 ->
cfker ('Ind[G, H] chi) = gcore (cfker chi) G.
Proof.
move=> sHG Nchi nzchi; rewrite !cfker_nzcharE ?cfInd_char ?cfInd_eq0 //.
apply/setP=> x; rewrite inE cfIndE // (can2_eq (mulVKf _) (mulKf _)) ?neq0CG //.
rewrite cfInd1 // mulrA -natrM Lagrange // mulr_natl -sumr_const.
apply/eqP/bigcapP=> [/normC_sum_upper ker_chiG_x y Gy | ker_chiG_x].
by rewrite mem_conjg inE ker_chiG_x ?groupV // => z _; apply: char1_ge_norm.
by apply: eq_bigr => y /groupVr/ker_chiG_x; rewrite mem_conjgV inE => /eqP.
Qed.
Lemma cfker_Ind_irr i :
H \subset G -> cfker ('Ind[G, H] 'chi_i) = gcore (cfker 'chi_i) G.
Proof. by move/cfker_Ind->; rewrite ?irr_neq0 ?irr_char. Qed.
End Induced.
Arguments Ind_Iirr {gT A%_g} B%_g i%_R.
|
Nat.lean
|
/-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Data.Nat.Find
import Mathlib.Order.BoundedOrder.Basic
import Mathlib.Order.Bounds.Defs
/-!
# The natural numbers form a linear order
This file contains the linear order instance on the natural numbers.
See note [foundational algebra order theory].
## TODO
Move the `LinearOrder β` instance here (https://github.com/leanprover-community/mathlib4/pull/13092).
-/
namespace Nat
instance instOrderBot : OrderBot β where
bot := 0
bot_le := zero_le
instance instNoMaxOrder : NoMaxOrder β where
exists_gt n := β¨n + 1, n.lt_succ_selfβ©
/-! ### Miscellaneous lemmas -/
@[simp high] protected lemma bot_eq_zero : β₯ = 0 := rfl
/-- `Nat.find` is the minimum natural number satisfying a predicate `p`. -/
lemma isLeast_find {p : β β Prop} [DecidablePred p] (hp : β n, p n) :
IsLeast {n | p n} (Nat.find hp) :=
β¨Nat.find_spec hp, fun _ β¦ Nat.find_min' hpβ©
end Nat
/-- `Nat.find` is the minimum element of a nonempty set of natural numbers. -/
lemma Set.Nonempty.isLeast_natFind {s : Set β} [DecidablePred (Β· β s)] (hs : s.Nonempty) :
IsLeast s (Nat.find hs) :=
Nat.isLeast_find hs
|
gfunctor.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 bigop finset fingroup morphism automorphism.
From mathcomp Require Import quotient gproduct.
(******************************************************************************)
(* This file provides basic interfaces for the notion of "generic" *)
(* characteristic subgroups; these amount to subfunctors of the identity *)
(* functor in some category of groups. *)
(* See "Generic Proof Tools And Finite Group Theory", *)
(* Francois Garillot, PhD, 2011, Chapter 3. *)
(* The implementation proposed here is fairly basic, relying on first order *)
(* function matching and on structure telescopes, both of which are somewhat *)
(* limited and fragile. It should switch in the future to more general and *)
(* more robust quotation matching. *)
(* The definitions in this file (types, properties and structures) are all *)
(* packaged under the GFunctor submodule, i.e., client code should refer to *)
(* GFunctor.continuous, GFunctor.map, etc. Notations, Coercions and Lemmas *)
(* are exported and thus directly available, however. *)
(* We provide the following: *)
(* object_map == the type of the (polymorphic) object map of a group *)
(* functor; the %gF scope is bound to object_map. *)
(* := forall gT : finGroupType, {set gT} -> {set gT}. *)
(* We define two operations on object_map (with notations in the %gF scope): *)
(* F1 \o F2 == the composite map; (F1 \o F2) G expands to F1 (F2 G). *)
(* F1 %% F2 == F1 computed modulo F2; we have *)
(* (F1 %% F2) G / F2 G = F1 (G / F2 G) *)
(* We define the following (type-polymorphic) properties of an object_map F: *)
(* group_valued F <-> F G is a group when G is a group *)
(* closed F <-> F G is a subgroup o fG when G is a group *)
(* continuous F <-> F is continuous with respect to morphism image: *)
(* for any f : {morphism G >-> ..}, f @* (F G) is a *)
(* a subgroup of F (f @* G); equivalently, F is *)
(* functorial in the category Grp of groups. *)
(* Most common "characteristic subgroup" are produced *)
(* continuous object maps. *)
(* iso_continuous F <-> F is continuous with respect to isomorphism image; *)
(* equivalently, F is functorial in the Grp groupoid. *)
(* The Puig and the Thompson J subgroups are examples *)
(* of iso_continuous maps that are not continuous. *)
(* pcontinuous F <-> F is continuous with respect to partial morphism *)
(* image, i.e., functorial in the category of groups *)
(* and partial morphisms. The center and p-core are *)
(* examples of pcontinuous maps. *)
(* hereditary F <-> inclusion in the image of F is hereditary, i.e., *)
(* for any subgroup H of G, the intersection of H with *)
(* F G is included in H. Note that F is pcontinuous *)
(* iff it is continuous and hereditary; indeed proofs *)
(* of pcontinuous F coerce to proofs of hereditary F *)
(* and continuous F. *)
(* monotonic F <-> F is monotonic with respect to inclusion: for any *)
(* subgroup H of G, F H is a subgroup of F G. The *)
(* derived and lower central series are examples of *)
(* monotonic maps. *)
(* Four structures provide interfaces to these properties: *)
(* GFunctor.iso_map == structure for object maps that are group_valued, *)
(* closed, and iso_continuous. *)
(* [igFun by Fsub & !Fcont] == the iso_map structure for an object map F *)
(* such that F G is canonically a group when G is, and *)
(* given Fsub : closed F and Fcont : iso_continuous F. *)
(* [igFun by Fsub & Fcont] == as above, but expecting Fcont : continuous F. *)
(* [igFun of F] == clone an existing GFunctor.iso_map structure for F. *)
(* GFunctor.map == structure for continuous object maps, inheriting *)
(* from the GFunctor.iso_map structure. *)
(* [gFun by Fcont] == the map structure for an F with a canonical iso_map *)
(* structure, given Fcont : continuous F. *)
(* [gFun of F] == clone an existing GFunctor.map structure for F. *)
(* GFunctor.pmap == structure for pcontinuous object maps, inheriting *)
(* from the GFunctor.map structure. *)
(* [pgFun by Fher] == the pmap structure for an F with a canonical map *)
(* structure, given Fher : hereditary F. *)
(* [pgFun of F] == clone an existing GFunctor.pmap structure for F. *)
(* GFunctor.mono_map == structure for monotonic, continuous object maps *)
(* inheriting from the GFunctor.map structure. *)
(* [mgFun by Fmon] == the mono_map structure for an F with a canonical *)
(* map structure, given Fmon : monotonic F. *)
(* [mgFun of F] == clone an existing GFunctor.mono_map structure for F *)
(* Lemmas for these group functors use either a 'gF' prefix or an 'F' suffix. *)
(* The (F1 \o F2) and (F1 %% F2) operations have canonical GFunctor.map *)
(* structures when F1 is monotonic or hereditary, respectively. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope gFun_scope.
Import GroupScope.
Delimit Scope gFun_scope with gF.
Module GFunctor.
Definition object_map := forall gT : finGroupType, {set gT} -> {set gT}.
Bind Scope gFun_scope with object_map.
Section Definitions.
Implicit Types gT hT : finGroupType.
Variable F : object_map.
(* Group closure. *)
Definition group_valued := forall gT (G : {group gT}), group_set (F G).
(* Subgroup closure. *)
Definition closed := forall gT (G : {group gT}), F G \subset G.
(* General functoriality, i.e., continuity of the object map *)
Definition continuous :=
forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}),
phi @* F G \subset F (phi @* G).
(* Functoriality on the Grp groupoid (arrows are restricted to isos). *)
Definition iso_continuous :=
forall gT hT (G : {group gT}) (phi : {morphism G >-> hT}),
'injm phi -> phi @* F G \subset F (phi @* G).
Lemma continuous_is_iso_continuous : continuous -> iso_continuous.
Proof. by move=> Fcont gT hT G phi inj_phi; apply: Fcont. Qed.
(* Functoriality on Grp with partial morphisms. *)
Definition pcontinuous :=
forall gT hT (G D : {group gT}) (phi : {morphism D >-> hT}),
phi @* F G \subset F (phi @* G).
Lemma pcontinuous_is_continuous : pcontinuous -> continuous.
Proof. by move=> Fcont gT hT G; apply: Fcont. Qed.
(* Heredity with respect to inclusion *)
Definition hereditary :=
forall gT (H G : {group gT}), H \subset G -> F G :&: H \subset F H.
Lemma pcontinuous_is_hereditary : pcontinuous -> hereditary.
Proof.
move=> Fcont gT H G sHG; rewrite -{2}(setIidPl sHG) setIC.
by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom ?Fcont.
Qed.
(* Monotonicity with respect to inclusion *)
Definition monotonic :=
forall gT (H G : {group gT}), H \subset G -> F H \subset F G.
(* Self-expanding composition, and modulo *)
Variables (F1 F2 : object_map).
Definition comp : object_map := fun gT A => F1 (F2 A).
Definition modulo : object_map :=
fun gT A => coset (F2 A) @*^-1 (F1 (A / (F2 A))).
End Definitions.
Section ClassDefinitions.
Structure iso_map := IsoMap {
apply : object_map;
_ : group_valued apply;
_ : closed apply;
_ : iso_continuous apply
}.
Local Coercion apply : iso_map >-> object_map.
Structure map := Map { iso_of_map : iso_map; _ : continuous iso_of_map }.
Local Coercion iso_of_map : map >-> iso_map.
Structure pmap := Pmap { map_of_pmap : map; _ : hereditary map_of_pmap }.
Local Coercion map_of_pmap : pmap >-> map.
Structure mono_map := MonoMap { map_of_mono : map; _ : monotonic map_of_mono }.
Local Coercion map_of_mono : mono_map >-> map.
Definition pack_iso F Fcont Fgrp Fsub := @IsoMap F Fgrp Fsub Fcont.
Definition clone_iso (F : object_map) :=
fun Fgrp Fsub Fcont (isoF := @IsoMap F Fgrp Fsub Fcont) =>
fun isoF0 & phant_id (apply isoF0) F & phant_id isoF isoF0 => isoF.
Definition clone (F : object_map) :=
fun isoF & phant_id (apply isoF) F =>
fun (funF0 : map) & phant_id (apply funF0) F =>
fun Fcont (funF := @Map isoF Fcont) & phant_id funF0 funF => funF.
Definition clone_pmap (F : object_map) :=
fun (funF : map) & phant_id (apply funF) F =>
fun (pfunF0 : pmap) & phant_id (apply pfunF0) F =>
fun Fher (pfunF := @Pmap funF Fher) & phant_id pfunF0 pfunF => pfunF.
Definition clone_mono (F : object_map) :=
fun (funF : map) & phant_id (apply funF) F =>
fun (mfunF0 : mono_map) & phant_id (apply mfunF0) F =>
fun Fmon (mfunF := @MonoMap funF Fmon) & phant_id mfunF0 mfunF => mfunF.
End ClassDefinitions.
Module Exports.
Identity Coercion fun_of_object_map : object_map >-> Funclass.
Coercion apply : iso_map >-> object_map.
Coercion iso_of_map : map >-> iso_map.
Coercion map_of_pmap : pmap >-> map.
Coercion map_of_mono : mono_map >-> map.
Coercion continuous_is_iso_continuous : continuous >-> iso_continuous.
Coercion pcontinuous_is_continuous : pcontinuous >-> continuous.
Coercion pcontinuous_is_hereditary : pcontinuous >-> hereditary.
Notation "[ 'igFun' 'by' Fsub & Fcont ]" :=
(pack_iso (continuous_is_iso_continuous Fcont) (fun gT G => groupP _) Fsub)
(format "[ 'igFun' 'by' Fsub & Fcont ]") : form_scope.
Notation "[ 'igFun' 'by' Fsub & ! Fcont ]" :=
(pack_iso Fcont (fun gT G => groupP _) Fsub)
(format "[ 'igFun' 'by' Fsub & ! Fcont ]") : form_scope.
Notation "[ 'igFun' 'of' F ]" := (@clone_iso F _ _ _ _ id id)
(format "[ 'igFun' 'of' F ]") : form_scope.
Notation "[ 'gFun' 'by' Fcont ]" := (Map Fcont)
(format "[ 'gFun' 'by' Fcont ]") : form_scope.
Notation "[ 'gFun' 'of' F ]" := (@clone F _ id _ id _ id)
(format "[ 'gFun' 'of' F ]") : form_scope.
Notation "[ 'pgFun' 'by' Fher ]" := (Pmap Fher)
(format "[ 'pgFun' 'by' Fher ]") : form_scope.
Notation "[ 'pgFun' 'of' F ]" := (@clone_pmap F _ id _ id _ id)
(format "[ 'pgFun' 'of' F ]") : form_scope.
Notation "[ 'mgFun' 'by' Fmon ]" := (MonoMap Fmon)
(format "[ 'mgFun' 'by' Fmon ]") : form_scope.
Notation "[ 'mgFun' 'of' F ]" := (@clone_mono F _ id _ id _ id)
(format "[ 'mgFun' 'of' F ]") : form_scope.
End Exports.
End GFunctor.
Export GFunctor.Exports.
Bind Scope gFun_scope with GFunctor.object_map.
Arguments GFunctor.comp F1 F2 _ /.
Notation "F1 \o F2" := (GFunctor.comp F1 F2) : gFun_scope.
Notation "F1 %% F2" := (GFunctor.modulo F1 F2) : gFun_scope.
Section FunctorGroup.
Variables (F : GFunctor.iso_map) (gT : finGroupType) (G : {group gT}).
Lemma gFgroupset : group_set (F gT G). Proof. by case: F. Qed.
Canonical gFgroup := Group gFgroupset.
End FunctorGroup.
Canonical gFmod_group
(F1 : GFunctor.iso_map) (F2 : GFunctor.object_map)
(gT : finGroupType) (G : {group gT}) :=
[group of (F1 %% F2)%gF gT G].
Section IsoFunctorTheory.
Implicit Types gT rT : finGroupType.
Variable F : GFunctor.iso_map.
Lemma gFsub gT (G : {group gT}) : F gT G \subset G.
Proof. by case: F gT G. Qed.
Lemma gFsub_trans gT (G : {group gT}) (A : {pred gT}) :
G \subset A -> F gT G \subset A.
Proof. exact/subset_trans/gFsub. Qed.
Lemma gF1 gT : F gT 1 = 1. Proof. exact/trivgP/gFsub. Qed.
Lemma gFiso_cont : GFunctor.iso_continuous F.
Proof. by case F. Qed.
Lemma gFchar gT (G : {group gT}) : F gT G \char G.
Proof.
apply/andP; split => //; first by apply: gFsub.
apply/forall_inP=> f Af; rewrite -{2}(im_autm Af) -(autmE Af).
by rewrite -morphimEsub ?gFsub ?gFiso_cont ?injm_autm.
Qed.
Lemma gFnorm gT (G : {group gT}) : G \subset 'N(F gT G).
Proof. exact/char_norm/gFchar. Qed.
Lemma gFnorms gT (G : {group gT}) : 'N(G) \subset 'N(F gT G).
Proof. exact/char_norms/gFchar. Qed.
Lemma gFnormal gT (G : {group gT}) : F gT G <| G.
Proof. exact/char_normal/gFchar. Qed.
Lemma gFchar_trans gT (G H : {group gT}) : H \char G -> F gT H \char G.
Proof. exact/char_trans/gFchar. Qed.
Lemma gFnormal_trans gT (G H : {group gT}) : H <| G -> F gT H <| G.
Proof. exact/char_normal_trans/gFchar. Qed.
Lemma gFnorm_trans gT (A : {pred gT}) (G : {group gT}) :
A \subset 'N(G) -> A \subset 'N(F gT G).
Proof. by move/subset_trans/(_ (gFnorms G)). Qed.
Lemma injmF_sub gT rT (G D : {group gT}) (f : {morphism D >-> rT}) :
'injm f -> G \subset D -> f @* (F gT G) \subset F rT (f @* G).
Proof.
move=> injf sGD; have:= gFiso_cont (injm_restrm sGD injf).
by rewrite im_restrm morphim_restrm (setIidPr _) ?gFsub.
Qed.
Lemma injmF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) :
'injm f -> G \subset D -> f @* (F gT G) = F rT (f @* G).
Proof.
move=> injf sGD; have [sfGD injf'] := (morphimS f sGD, injm_invm injf).
apply/esym/eqP; rewrite eqEsubset -(injmSK injf') ?gFsub_trans //.
by rewrite !(subset_trans (injmF_sub _ _)) ?morphim_invm // gFsub_trans.
Qed.
Lemma gFisom gT rT (G D : {group gT}) R (f : {morphism D >-> rT}) :
G \subset D -> isom G (gval R) f -> isom (F gT G) (F rT R) f.
Proof.
case/(restrmP f)=> g [gf _ _ _]; rewrite -{f}gf => /isomP[injg <-].
by rewrite sub_isom ?gFsub ?injmF.
Qed.
Lemma gFisog gT rT (G : {group gT}) (R : {group rT}) :
G \isog R -> F gT G \isog F rT R.
Proof. by case/isogP=> f injf <-; rewrite -injmF // sub_isog ?gFsub. Qed.
End IsoFunctorTheory.
Section FunctorTheory.
Implicit Types gT rT : finGroupType.
Variable F : GFunctor.map.
Lemma gFcont : GFunctor.continuous F.
Proof. by case F. Qed.
Lemma morphimF gT rT (G D : {group gT}) (f : {morphism D >-> rT}) :
G \subset D -> f @* (F gT G) \subset F rT (f @* G).
Proof.
move=> sGD; rewrite -(setIidPr (gFsub F G)).
by rewrite -{3}(setIid G) -!(morphim_restrm sGD) gFcont.
Qed.
End FunctorTheory.
Section PartialFunctorTheory.
Implicit Types gT rT : finGroupType.
Section BasicTheory.
Variable F : GFunctor.pmap.
Lemma gFhereditary : GFunctor.hereditary F.
Proof. by case F. Qed.
Lemma gFunctorI gT (G H : {group gT}) :
F gT G :&: H = F gT G :&: F gT (G :&: H).
Proof.
rewrite -{1}(setIidPr (gFsub F G)) setIAC setIC.
rewrite -(setIidPr (gFhereditary (subsetIl G H))).
by rewrite setIC -setIA (setIidPr (gFsub F (G :&: H))).
Qed.
Lemma pmorphimF : GFunctor.pcontinuous F.
Proof.
move=> gT rT G D f; rewrite -morphimIdom -(setIidPl (gFsub F G)) setICA.
apply: (subset_trans (morphimS f (gFhereditary (subsetIr D G)))).
by rewrite (subset_trans (morphimF F _ _ )) ?morphimIdom ?subsetIl.
Qed.
Lemma gFid gT (G : {group gT}) : F gT (F gT G) = F gT G.
Proof.
apply/eqP; rewrite eqEsubset gFsub.
by move/gFhereditary: (gFsub F G); rewrite setIid /=.
Qed.
End BasicTheory.
Section Modulo.
Variables (F1 : GFunctor.pmap) (F2 : GFunctor.map).
Lemma gFmod_closed : GFunctor.closed (F1 %% F2).
Proof. by move=> gT G; rewrite sub_cosetpre_quo ?gFsub ?gFnormal. Qed.
Lemma gFmod_cont : GFunctor.continuous (F1 %% F2).
Proof.
move=> gT rT G f; have nF2 := gFnorm F2.
have sDF: G \subset 'dom (coset (F2 _ G)) by rewrite nF2.
have sDFf: G \subset 'dom (coset (F2 _ (f @* G)) \o f).
by rewrite -sub_morphim_pre ?subsetIl // nF2.
pose K := 'ker (restrm sDFf (coset (F2 _ (f @* G)) \o f)).
have sFK: 'ker (restrm sDF (coset (F2 _ G))) \subset K.
rewrite {}/K !ker_restrm ker_comp /= subsetI subsetIl !ker_coset /=.
by rewrite -sub_morphim_pre ?subsetIl // morphimIdom ?morphimF.
have sOF := gFsub F1 (G / F2 _ G); have sGG: G \subset G by [].
rewrite -sub_quotient_pre; last first.
by apply: subset_trans (nF2 _ _); rewrite morphimS ?gFmod_closed.
suffices im_fact H : F2 _ G \subset gval H -> H \subset G ->
factm sFK sGG @* (H / F2 _ G) = f @* H / F2 _ (f @* G).
- rewrite -2?im_fact ?gFmod_closed ?gFsub //.
by rewrite cosetpreK morphimF /= ?morphim_restrm ?setIid.
by rewrite -sub_quotient_pre ?normG //= trivg_quotient sub1G.
move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm /= setIid.
rewrite -morphimIG ?ker_coset // -(morphim_restrm sDF) morphim_factm.
by rewrite morphim_restrm morphim_comp -quotientE morphimIdom.
Qed.
Canonical gFmod_igFun := [igFun by gFmod_closed & gFmod_cont].
Canonical gFmod_gFun := [gFun by gFmod_cont].
End Modulo.
Variables F1 F2 : GFunctor.pmap.
Lemma gFmod_hereditary : GFunctor.hereditary (F1 %% F2).
Proof.
move=> gT H G sHG; set FGH := _ :&: H; have nF2H := gFnorm F2 H.
rewrite -sub_quotient_pre; last exact: subset_trans (subsetIr _ _) _.
pose rH := restrm nF2H (coset (F2 _ H)); pose rHM := [morphism of rH].
have rnorm_simpl: rHM @* H = H / F2 _ H by rewrite morphim_restrm setIid.
have nF2G := subset_trans sHG (gFnorm F2 G).
pose rG := restrm nF2G (coset (F2 _ G)); pose rGM := [morphism of rG].
have sqKfK: 'ker rGM \subset 'ker rHM.
rewrite !ker_restrm !ker_coset (setIidPr (gFsub F2 _)) setIC /=.
exact: gFhereditary.
have sHH := subxx H; rewrite -rnorm_simpl /= -(morphim_factm sqKfK sHH) /=.
apply: subset_trans (gFcont F1 _); rewrite /= {2}morphim_restrm setIid /=.
apply: subset_trans (morphimS _ (gFhereditary _ (quotientS _ sHG))) => /=.
have ->: FGH / _ = restrm nF2H (coset _) @* FGH.
by rewrite morphim_restrm setICA setIid.
rewrite -(morphim_factm sqKfK sHH) morphimS //= morphim_restrm -quotientE.
by rewrite setICA setIid (subset_trans (quotientI _ _ _)) // cosetpreK.
Qed.
Canonical gFmod_pgFun := [pgFun by gFmod_hereditary].
End PartialFunctorTheory.
Section MonotonicFunctorTheory.
Implicit Types gT rT : finGroupType.
Lemma gFunctorS (F : GFunctor.mono_map) : GFunctor.monotonic F.
Proof. by case: F. Qed.
Section Composition.
Variables (F1 : GFunctor.mono_map) (F2 : GFunctor.map).
Lemma gFcomp_closed : GFunctor.closed (F1 \o F2).
Proof. by move=> gT G; rewrite !gFsub_trans. Qed.
Lemma gFcomp_cont : GFunctor.continuous (F1 \o F2).
Proof.
move=> gT rT G phi; rewrite (subset_trans (morphimF _ _ (gFsub _ _))) //.
by rewrite (subset_trans (gFunctorS F1 (gFcont F2 phi))).
Qed.
Canonical gFcomp_igFun := [igFun by gFcomp_closed & gFcomp_cont].
Canonical gFcomp_gFun :=[gFun by gFcomp_cont].
End Composition.
Variables F1 F2 : GFunctor.mono_map.
Lemma gFcompS : GFunctor.monotonic (F1 \o F2).
Proof. by move=> gT H G sHG; rewrite !gFunctorS. Qed.
Canonical gFcomp_mgFun := [mgFun by gFcompS].
End MonotonicFunctorTheory.
Section GFunctorExamples.
Implicit Types gT : finGroupType.
Definition idGfun gT := @id {set gT}.
Lemma idGfun_closed : GFunctor.closed idGfun. Proof. by []. Qed.
Lemma idGfun_cont : GFunctor.continuous idGfun. Proof. by []. Qed.
Lemma idGfun_monotonic : GFunctor.monotonic idGfun. Proof. by []. Qed.
Canonical bgFunc_id := [igFun by idGfun_closed & idGfun_cont].
Canonical gFunc_id := [gFun by idGfun_cont].
Canonical mgFunc_id := [mgFun by idGfun_monotonic].
Definition trivGfun gT of {set gT} := [1 gT].
Lemma trivGfun_cont : GFunctor.pcontinuous trivGfun.
Proof. by move=> gT rT D G f; rewrite morphim1. Qed.
Canonical trivGfun_igFun := [igFun by sub1G & trivGfun_cont].
Canonical trivGfun_gFun := [gFun by trivGfun_cont].
Canonical trivGfun_pgFun := [pgFun by trivGfun_cont].
End GFunctorExamples.
|
Images.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Reid Barton
-/
import Mathlib.CategoryTheory.Limits.Types.Limits
import Mathlib.CategoryTheory.Limits.Shapes.Images
/-!
# Images in the category of types
In this file, it is shown that the category of types has categorical images,
and that these agree with the range of a function.
-/
universe v u
namespace CategoryTheory.Limits.Types
variable {Ξ± Ξ² : Type u} (f : Ξ± βΆ Ξ²)
section
-- implementation of `HasImage`
/-- the image of a morphism in Type is just `Set.range f` -/
def Image : Type u :=
Set.range f
instance [Inhabited Ξ±] : Inhabited (Image f) where default := β¨f default, β¨_, rflβ©β©
/-- the inclusion of `Image f` into the target -/
def Image.ΞΉ : Image f βΆ Ξ² :=
Subtype.val
instance : Mono (Image.ΞΉ f) :=
(mono_iff_injective _).2 Subtype.val_injective
variable {f}
/-- the universal property for the image factorisation -/
noncomputable def Image.lift (F' : MonoFactorisation f) : Image f βΆ F'.I :=
(fun x => F'.e (Classical.indefiniteDescription _ x.2).1 : Image f β F'.I)
theorem Image.lift_fac (F' : MonoFactorisation f) : Image.lift F' β« F'.m = Image.ΞΉ f := by
funext x
change (F'.e β« F'.m) _ = _
rw [F'.fac, (Classical.indefiniteDescription _ x.2).2]
rfl
end
/-- the factorisation of any morphism in Type through a mono. -/
def monoFactorisation : MonoFactorisation f where
I := Image f
m := Image.ΞΉ f
e := Set.rangeFactorization f
/-- the factorisation through a mono has the universal property of the image. -/
noncomputable def isImage : IsImage (monoFactorisation f) where
lift := Image.lift
lift_fac := Image.lift_fac
instance : HasImage f :=
HasImage.mk β¨_, isImage fβ©
instance : HasImages (Type u) where
has_image := by infer_instance
instance : HasImageMaps (Type u) where
has_image_map {f g} st :=
HasImageMap.transport st (monoFactorisation f.hom) (isImage g.hom)
(fun x => β¨st.right x.1, β¨st.left (Classical.choose x.2), by
have p := st.w
replace p := congr_fun p (Classical.choose x.2)
simp only [Functor.id_obj, Functor.id_map, types_comp_apply] at p
rw [p, Classical.choose_spec x.2]β©β©) rfl
variable {F : βα΅α΅ β₯€ Type u} {c : Cone F}
(hF : β n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op))
private noncomputable def limitOfSurjectionsSurjective.preimage
(a : F.obj β¨0β©) : (n : β) β F.obj β¨nβ©
| 0 => a
| n + 1 => (hF n (preimage a n)).choose
include hF in
open limitOfSurjectionsSurjective in
/-- Auxiliary lemma. Use `limit_of_surjections_surjective` instead. -/
lemma surjective_Ο_app_zero_of_surjective_map_aux :
Function.Surjective ((limitCone F).Ο.app β¨0β©) := by
intro a
refine β¨β¨fun β¨nβ© β¦ preimage hF a n, ?_β©, rflβ©
intro β¨nβ© β¨mβ© β¨β¨β¨(h : m β€ n)β©β©β©
induction h with
| refl =>
erw [CategoryTheory.Functor.map_id, types_id_apply]
| @step p h ih =>
rw [β ih]
have h' : m β€ p := h
erw [CategoryTheory.Functor.map_comp (f := (homOfLE (Nat.le_succ p)).op) (g := (homOfLE h').op),
types_comp_apply, (hF p _).choose_spec]
rfl
/--
Given surjections `β― βΆ Xβββ βΆ Xβ βΆ β― βΆ Xβ`, the projection map `lim Xβ βΆ Xβ` is surjective.
-/
lemma surjective_Ο_app_zero_of_surjective_map
(hc : IsLimit c)
(hF : β n, Function.Surjective (F.map (homOfLE (Nat.le_succ n)).op)) :
Function.Surjective (c.Ο.app β¨0β©) := by
let i := hc.conePointUniqueUpToIso (limitConeIsLimit F)
have : c.Ο.app β¨0β© = i.hom β« (limitCone F).Ο.app β¨0β© := by simp [i]
rw [this]
apply Function.Surjective.comp
Β· exact surjective_Ο_app_zero_of_surjective_map_aux hF
Β· rw [β epi_iff_surjective]
infer_instance
end CategoryTheory.Limits.Types
|
Four.lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, JoΓ«l Riou
-/
import Mathlib.Algebra.Homology.ExactSequence
import Mathlib.CategoryTheory.Abelian.Refinements
/-!
# The four and five lemmas
Consider the following commutative diagram with exact rows in an abelian category `C`:
```
A ---f--> B ---g--> C ---h--> D ---i--> E
| | | | |
Ξ± Ξ² Ξ³ Ξ΄ Ξ΅
| | | | |
v v v v v
A' --f'-> B' --g'-> C' --h'-> D' --i'-> E'
```
We show:
- the "mono" version of the four lemma: if `Ξ±` is an epimorphism and `Ξ²` and `Ξ΄` are monomorphisms,
then `Ξ³` is a monomorphism,
- the "epi" version of the four lemma: if `Ξ²` and `Ξ΄` are epimorphisms and `Ξ΅` is a monomorphism,
then `Ξ³` is an epimorphism,
- the five lemma: if `Ξ±`, `Ξ²`, `Ξ΄` and `Ξ΅` are isomorphisms, then `Ξ³` is an isomorphism.
## Implementation details
The diagram of the five lemmas is given by a morphism in the category `ComposableArrows C 4`
between two objects which satisfy `ComposableArrows.Exact`. Similarly, the two versions of the
four lemma are stated in terms of the category `ComposableArrows C 3`.
The five lemmas is deduced from the two versions of the four lemma. Both of these versions
are proved separately. It would be easy to deduce the epi version from the mono version
using duality, but this would require lengthy API developments for `ComposableArrows` (TODO).
## Tags
four lemma, five lemma, diagram lemma, diagram chase
-/
namespace CategoryTheory
open Category Limits Preadditive
namespace Abelian
variable {C : Type*} [Category C] [Abelian C]
open ComposableArrows
section Four
variable {Rβ Rβ : ComposableArrows C 3} (Ο : Rβ βΆ Rβ)
theorem mono_of_epi_of_mono_of_mono' (hRβ : Rβ.map' 0 2 = 0)
(hRβ' : (mkβ (Rβ.map' 1 2) (Rβ.map' 2 3)).Exact)
(hRβ : (mkβ (Rβ.map' 0 1) (Rβ.map' 1 2)).Exact)
(hβ : Epi (app' Ο 0)) (hβ : Mono (app' Ο 1)) (hβ : Mono (app' Ο 3)) :
Mono (app' Ο 2) := by
apply mono_of_cancel_zero
intro A fβ hβ
have hβ : fβ β« Rβ.map' 2 3 = 0 := by
rw [β cancel_mono (app' Ο 3 _), assoc, NatTrans.naturality, reassoc_of% hβ,
zero_comp, zero_comp]
obtain β¨Aβ, Οβ, _, fβ, hfββ© := (hRβ'.exact 0).exact_up_to_refinements fβ hβ
dsimp at hfβ
have hβ : (fβ β« app' Ο 1) β« Rβ.map' 1 2 = 0 := by
rw [assoc, β NatTrans.naturality, β reassoc_of% hfβ, hβ, comp_zero]
obtain β¨Aβ, Οβ, _, gβ, hgββ© := (hRβ.exact 0).exact_up_to_refinements _ hβ
obtain β¨Aβ, Οβ, _, fβ, hfββ© := surjective_up_to_refinements_of_epi (app' Ο 0 _) gβ
have hβ : fβ β« Rβ.map' 0 1 = Οβ β« Οβ β« fβ := by
rw [β cancel_mono (app' Ο 1 _), assoc, assoc, assoc, NatTrans.naturality,
β reassoc_of% hfβ, hgβ]
rfl
rw [β cancel_epi Οβ, comp_zero, hfβ, β cancel_epi Οβ, β cancel_epi Οβ, comp_zero,
comp_zero, β reassoc_of% hβ, β Rβ.map'_comp 0 1 2, hRβ, comp_zero]
theorem mono_of_epi_of_mono_of_mono (hRβ : Rβ.Exact) (hRβ : Rβ.Exact)
(hβ : Epi (app' Ο 0)) (hβ : Mono (app' Ο 1)) (hβ : Mono (app' Ο 3)) :
Mono (app' Ο 2) :=
mono_of_epi_of_mono_of_mono' Ο
(by simpa only [Rβ.map'_comp 0 1 2] using hRβ.toIsComplex.zero 0)
(hRβ.exact 1).exact_toComposableArrows (hRβ.exact 0).exact_toComposableArrows hβ hβ hβ
theorem epi_of_epi_of_epi_of_mono'
(hRβ : (mkβ (Rβ.map' 1 2) (Rβ.map' 2 3)).Exact)
(hRβ : (mkβ (Rβ.map' 0 1) (Rβ.map' 1 2)).Exact) (hRβ' : Rβ.map' 1 3 = 0)
(hβ : Epi (app' Ο 0)) (hβ : Epi (app' Ο 2)) (hβ : Mono (app' Ο 3)) :
Epi (app' Ο 1) := by
rw [epi_iff_surjective_up_to_refinements]
intro A gβ
obtain β¨Aβ, Οβ, _, fβ, hββ© :=
surjective_up_to_refinements_of_epi (app' Ο 2 _) (gβ β« Rβ.map' 1 2)
have hβ : fβ β« Rβ.map' 2 3 = 0 := by
rw [β cancel_mono (app' Ο 3 _), assoc, zero_comp, NatTrans.naturality, β reassoc_of% hβ,
β Rβ.map'_comp 1 2 3, hRβ', comp_zero, comp_zero]
obtain β¨Aβ, Οβ, _, fβ, hββ© := (hRβ.exact 0).exact_up_to_refinements _ hβ
dsimp at fβ hβ
have hβ : (Οβ β« Οβ β« gβ - fβ β« app' Ο 1 _) β« Rβ.map' 1 2 = 0 := by
rw [sub_comp, assoc, assoc, assoc, β NatTrans.naturality, β reassoc_of% hβ, hβ, sub_self]
obtain β¨Aβ, Οβ, _, gβ, hβ
β© := (hRβ.exact 0).exact_up_to_refinements _ hβ
dsimp at gβ hβ
rw [comp_sub] at hβ
obtain β¨Aβ, Οβ, _, fβ, hββ© := surjective_up_to_refinements_of_epi (app' Ο 0 _) gβ
refine β¨Aβ, Οβ β« Οβ β« Οβ β« Οβ, inferInstance,
Οβ β« Οβ β« fβ + fβ β« (by exact Rβ.map' 0 1), ?_β©
rw [assoc, assoc, assoc, add_comp, assoc, assoc, assoc, NatTrans.naturality,
β reassoc_of% hβ, β hβ
, comp_sub]
dsimp
rw [add_sub_cancel]
theorem epi_of_epi_of_epi_of_mono (hRβ : Rβ.Exact) (hRβ : Rβ.Exact)
(hβ : Epi (app' Ο 0)) (hβ : Epi (app' Ο 2)) (hβ : Mono (app' Ο 3)) :
Epi (app' Ο 1) :=
epi_of_epi_of_epi_of_mono' Ο (hRβ.exact 1).exact_toComposableArrows
(hRβ.exact 0).exact_toComposableArrows
(by simpa only [Rβ.map'_comp 1 2 3] using hRβ.toIsComplex.zero 1) hβ hβ hβ
end Four
section Five
variable {Rβ Rβ : ComposableArrows C 4} (hRβ : Rβ.Exact) (hRβ : Rβ.Exact) (Ο : Rβ βΆ Rβ)
include hRβ hRβ
/-- The five lemma. -/
theorem isIso_of_epi_of_isIso_of_isIso_of_mono (hβ : Epi (app' Ο 0)) (hβ : IsIso (app' Ο 1))
(hβ : IsIso (app' Ο 3)) (hβ : Mono (app' Ο 4)) : IsIso (app' Ο 2) := by
dsimp at hβ hβ hβ hβ
have : Mono (app' Ο 2) := by
apply mono_of_epi_of_mono_of_mono (Ξ΄lastFunctor.map Ο) (Rβ.exact_iff_Ξ΄last.1 hRβ).1
(Rβ.exact_iff_Ξ΄last.1 hRβ).1 <;> dsimp <;> infer_instance
have : Epi (app' Ο 2) := by
apply epi_of_epi_of_epi_of_mono (Ξ΄βFunctor.map Ο) (Rβ.exact_iff_Ξ΄β.1 hRβ).2
(Rβ.exact_iff_Ξ΄β.1 hRβ).2 <;> dsimp <;> infer_instance
apply isIso_of_mono_of_epi
end Five
/-! The following "three lemmas" for morphisms in `ComposableArrows C 2` are
special cases of "four lemmas" applied to diagrams where some of the
leftmost or rightmost maps (or objects) are zero. -/
section Three
variable {Rβ Rβ : ComposableArrows C 2} (Ο : Rβ βΆ Rβ)
attribute [local simp] Precomp.map
theorem mono_of_epi_of_epi_mono' (hRβ : Rβ.map' 0 2 = 0) (hRβ' : Epi (Rβ.map' 1 2))
(hRβ : Rβ.Exact) (hβ : Epi (app' Ο 0)) (hβ : Mono (app' Ο 1)) :
Mono (app' Ο 2) := by
let Ο : mkβ (Rβ.map' 0 1) (Rβ.map' 1 2) (0 : _ βΆ Rβ.obj' 0) βΆ
mkβ (Rβ.map' 0 1) (Rβ.map' 1 2) (0 : _ βΆ Rβ.obj' 0) := homMkβ (app' Ο 0) (app' Ο 1)
(app' Ο 2) (π _) (naturality' Ο 0 1) (naturality' Ο 1 2) (by simp)
refine mono_of_epi_of_mono_of_mono' Ο ?_ (exactβ_mk _ (by simp) ?_)
(hRβ.exact 0).exact_toComposableArrows hβ hβ (by dsimp [Ο]; infer_instance)
Β· dsimp
rw [β Functor.map_comp]
exact hRβ
Β· rw [ShortComplex.exact_iff_epi _ (by simp)]
exact hRβ'
theorem mono_of_epi_of_epi_of_mono (hRβ : Rβ.Exact) (hRβ : Rβ.Exact)
(hRβ' : Epi (Rβ.map' 1 2)) (hβ : Epi (app' Ο 0)) (hβ : Mono (app' Ο 1)) :
Mono (app' Ο 2) :=
mono_of_epi_of_epi_mono' Ο (by simpa only [map'_comp Rβ 0 1 2] using hRβ.toIsComplex.zero 0)
hRβ' hRβ hβ hβ
theorem epi_of_mono_of_epi_of_mono' (hRβ : Rβ.Exact) (hRβ : Rβ.map' 0 2 = 0)
(hRβ' : Mono (Rβ.map' 0 1)) (hβ : Epi (app' Ο 1)) (hβ : Mono (app' Ο 2)) :
Epi (app' Ο 0) := by
let Ο : mkβ (0 : Rβ.obj' 0 βΆ _) (Rβ.map' 0 1) (Rβ.map' 1 2) βΆ
mkβ (0 : Rβ.obj' 0 βΆ _) (Rβ.map' 0 1) (Rβ.map' 1 2) := homMkβ (π _) (app' Ο 0) (app' Ο 1)
(app' Ο 2) (by simp) (naturality' Ο 0 1) (naturality' Ο 1 2)
refine epi_of_epi_of_epi_of_mono' Ο (hRβ.exact 0).exact_toComposableArrows
(exactβ_mk _ (by simp) ?_) ?_ (by dsimp [Ο]; infer_instance) hβ hβ
Β· rw [ShortComplex.exact_iff_mono _ (by simp)]
exact hRβ'
Β· dsimp
rw [β Functor.map_comp]
exact hRβ
theorem epi_of_mono_of_epi_of_mono (hRβ : Rβ.Exact) (hRβ : Rβ.Exact)
(hRβ' : Mono (Rβ.map' 0 1)) (hβ : Epi (app' Ο 1)) (hβ : Mono (app' Ο 2)) :
Epi (app' Ο 0) :=
epi_of_mono_of_epi_of_mono' Ο hRβ
(by simpa only [map'_comp Rβ 0 1 2] using hRβ.toIsComplex.zero 0) hRβ' hβ hβ
theorem mono_of_mono_of_mono_of_mono (hRβ : Rβ.Exact)
(hRβ' : Mono (Rβ.map' 0 1))
(hβ : Mono (app' Ο 0))
(hβ : Mono (app' Ο 2)) :
Mono (app' Ο 1) := by
let Ο : mkβ (0 : Rβ.obj' 0 βΆ _) (Rβ.map' 0 1) (Rβ.map' 1 2) βΆ
mkβ (0 : Rβ.obj' 0 βΆ _) (Rβ.map' 0 1) (Rβ.map' 1 2) := homMkβ (π _) (app' Ο 0) (app' Ο 1)
(app' Ο 2) (by simp) (naturality' Ο 0 1) (naturality' Ο 1 2)
refine mono_of_epi_of_mono_of_mono' Ο (by simp)
(hRβ.exact 0).exact_toComposableArrows
(exactβ_mk _ (by simp) ?_) (by dsimp [Ο]; infer_instance) hβ hβ
rw [ShortComplex.exact_iff_mono _ (by simp)]
exact hRβ'
theorem epi_of_epi_of_epi_of_epi (hRβ : Rβ.Exact) (hRβ' : Epi (Rβ.map' 1 2))
(hβ : Epi (app' Ο 0)) (hβ : Epi (app' Ο 2)) :
Epi (app' Ο 1) := by
let Ο : mkβ (Rβ.map' 0 1) (Rβ.map' 1 2) (0 : _ βΆ Rβ.obj' 0) βΆ
mkβ (Rβ.map' 0 1) (Rβ.map' 1 2) (0 : _ βΆ Rβ.obj' 0) := homMkβ (app' Ο 0) (app' Ο 1)
(app' Ο 2) (π _) (naturality' Ο 0 1) (naturality' Ο 1 2) (by simp)
refine epi_of_epi_of_epi_of_mono' Ο (exactβ_mk _ (by simp) ?_)
(hRβ.exact 0).exact_toComposableArrows (by simp)
hβ hβ (by dsimp [Ο]; infer_instance)
rw [ShortComplex.exact_iff_epi _ (by simp)]
exact hRβ'
end Three
end Abelian
namespace ShortComplex
variable {C : Type*} [Category C] [Abelian C]
variable {Rβ Rβ : ShortComplex C} (Ο : Rβ βΆ Rβ)
attribute [local simp] ComposableArrows.Precomp.map
theorem mono_of_epi_of_epi_of_mono (hRβ : Rβ.Exact) (hRβ' : Epi Rβ.g)
(hβ : Epi Ο.Οβ) (hβ : Mono Ο.Οβ) : Mono (Ο.Οβ) :=
Abelian.mono_of_epi_of_epi_mono' (ShortComplex.mapToComposableArrows Ο)
(by simp) hRβ' hRβ.exact_toComposableArrows hβ hβ
theorem epi_of_mono_of_epi_of_mono (hRβ : Rβ.Exact)
(hRβ' : Mono Rβ.f) (hβ : Epi Ο.Οβ) (hβ : Mono Ο.Οβ) : Epi Ο.Οβ :=
Abelian.epi_of_mono_of_epi_of_mono' (ShortComplex.mapToComposableArrows Ο)
hRβ.exact_toComposableArrows (by simp) hRβ' hβ hβ
theorem mono_of_mono_of_mono_of_mono (hRβ : Rβ.Exact) (hRβ' : Mono Rβ.f) (hβ : Mono Ο.Οβ)
(hβ : Mono Ο.Οβ) : Mono Ο.Οβ :=
Abelian.mono_of_mono_of_mono_of_mono (ShortComplex.mapToComposableArrows Ο)
hRβ.exact_toComposableArrows hRβ' hβ hβ
theorem epi_of_epi_of_epi_of_epi (hRβ : Rβ.Exact) (hRβ' : Epi Rβ.g) (hβ : Epi Ο.Οβ)
(hβ : Epi Ο.Οβ) : Epi Ο.Οβ :=
Abelian.epi_of_epi_of_epi_of_epi (ShortComplex.mapToComposableArrows Ο)
hRβ.exact_toComposableArrows hRβ' hβ hβ
end ShortComplex
end CategoryTheory
|
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_}.
|
AddCircle.lean
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Order.Ring.Abs
import Mathlib.Dynamics.FixedPoints.Prufer
import Mathlib.Dynamics.Ergodic.Ergodic
import Mathlib.MeasureTheory.Covering.DensityTheorem
import Mathlib.MeasureTheory.Group.AddCircle
import Mathlib.MeasureTheory.Measure.Haar.Unique
/-!
# Ergodic maps of the additive circle
This file contains proofs of ergodicity for maps of the additive circle.
## Main definitions:
* `AddCircle.ergodic_zsmul`: given `n : β€` such that `1 < |n|`, the self map `y β¦ n β’ y` on
the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_nsmul`: given `n : β` such that `1 < n`, the self map `y β¦ n β’ y` on
the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_zsmul_add`: given `n : β€` such that `1 < |n|` and `x : AddCircle T`, the
self map `y β¦ n β’ y + x` on the additive circle is ergodic (wrt the Haar measure).
* `AddCircle.ergodic_nsmul_add`: given `n : β` such that `1 < n` and `x : AddCircle T`, the
self map `y β¦ n β’ y + x` on the additive circle is ergodic (wrt the Haar measure).
-/
open Set Function MeasureTheory MeasureTheory.Measure Filter Metric
open scoped MeasureTheory NNReal ENNReal Topology Pointwise
namespace AddCircle
variable {T : β} [hT : Fact (0 < T)]
/-- If a null-measurable subset of the circle is almost invariant under rotation by a family of
rational angles with denominators tending to infinity, then it must be almost empty or almost full.
-/
theorem ae_empty_or_univ_of_forall_vadd_ae_eq_self {s : Set <| AddCircle T}
(hs : NullMeasurableSet s volume) {ΞΉ : Type*} {l : Filter ΞΉ} [l.NeBot] {u : ΞΉ β AddCircle T}
(huβ : β i, (u i +α΅₯ s : Set _) =α΅[volume] s) (huβ : Tendsto (addOrderOf β u) l atTop) :
s =α΅[volume] (β
: Set <| AddCircle T) β¨ s =α΅[volume] univ := by
/- Sketch of proof:
Assume `T = 1` for simplicity and let `ΞΌ` be the Haar measure. We may assume `s` has positive
measure since otherwise there is nothing to prove. In this case, by Lebesgue's density theorem,
there exists a point `d` of positive density. Let `Iβ±Ό` be the sequence of closed balls about `d`
of diameter `1 / nβ±Ό` where `nβ±Ό` is the additive order of `uβ±Ό`. Since `d` has positive density we
must have `ΞΌ (s β© Iβ±Ό) / ΞΌ Iβ±Ό β 1` along `l`. However since `s` is invariant under the action of
`uβ±Ό` and since `Iβ±Ό` is a fundamental domain for this action, we must have
`ΞΌ (s β© Iβ±Ό) = nβ±Ό * ΞΌ s = (ΞΌ Iβ±Ό) * ΞΌ s`. We thus have `ΞΌ s β 1` and thus `ΞΌ s = 1`. -/
set ΞΌ := (volume : Measure <| AddCircle T)
set n : ΞΉ β β := addOrderOf β u
have hTβ : 0 < T := hT.out
have hTβ : ENNReal.ofReal T β 0 := by simpa
rw [ae_eq_empty, ae_eq_univ_iff_measure_eq hs, AddCircle.measure_univ]
rcases eq_or_ne (ΞΌ s) 0 with h | h; Β· exact Or.inl h
right
obtain β¨d, -, hdβ© : β d, d β s β§ β {ΞΉ'} {l : Filter ΞΉ'} (w : ΞΉ' β AddCircle T) (Ξ΄ : ΞΉ' β β),
Tendsto Ξ΄ l (π[>] 0) β (βαΆ j in l, d β closedBall (w j) (1 * Ξ΄ j)) β
Tendsto (fun j => ΞΌ (s β© closedBall (w j) (Ξ΄ j)) / ΞΌ (closedBall (w j) (Ξ΄ j))) l (π 1) :=
exists_mem_of_measure_ne_zero_of_ae h
(IsUnifLocDoublingMeasure.ae_tendsto_measure_inter_div ΞΌ s 1)
let I : ΞΉ β Set (AddCircle T) := fun j => closedBall d (T / (2 * β(n j)))
replace hd : Tendsto (fun j => ΞΌ (s β© I j) / ΞΌ (I j)) l (π 1) := by
let Ξ΄ : ΞΉ β β := fun j => T / (2 * β(n j))
have hΞ΄β : βαΆ j in l, 0 < Ξ΄ j :=
(huβ.eventually_gt_atTop 0).mono fun j hj => div_pos hTβ <| by positivity
have hΞ΄β : Tendsto Ξ΄ l (π[>] 0) := by
refine tendsto_nhdsWithin_iff.mpr β¨?_, hΞ΄ββ©
replace huβ : Tendsto (fun j => Tβ»ΒΉ * 2 * n j) l atTop :=
(tendsto_natCast_atTop_iff.mpr huβ).const_mul_atTop (by positivity : 0 < Tβ»ΒΉ * 2)
convert huβ.inv_tendsto_atTop
ext j
simp only [Ξ΄, Pi.inv_apply, mul_inv_rev, inv_inv, div_eq_inv_mul, β mul_assoc]
have hw : βαΆ j in l, d β closedBall d (1 * Ξ΄ j) := hΞ΄β.mono fun j hj => by
simp only [one_mul, mem_closedBall, dist_self]
apply hj.le
exact hd _ Ξ΄ hΞ΄β hw
suffices βαΆ j in l, ΞΌ (s β© I j) / ΞΌ (I j) = ΞΌ s / ENNReal.ofReal T by
replace hd := hd.congr' this
rwa [tendsto_const_nhds_iff, ENNReal.div_eq_one_iff hTβ ENNReal.ofReal_ne_top] at hd
refine (huβ.eventually_gt_atTop 0).mono fun j hj => ?_
have : addOrderOf (u j) = n j := rfl
have huj : IsOfFinAddOrder (u j) := addOrderOf_pos_iff.mp hj
have huj' : 1 β€ (β(n j) : β) := by norm_cast
have hIβ : ΞΌ (I j) β 0 := (measure_closedBall_pos _ d <| by positivity).ne.symm
have hIβ : ΞΌ (I j) β β€ := measure_ne_top _ _
have hIβ : ΞΌ (I j) * β(n j) = ENNReal.ofReal T := by
rw [volume_closedBall, mul_div, mul_div_mul_left T _ two_ne_zero,
min_eq_right (div_le_self hTβ.le huj'), mul_comm, β nsmul_eq_mul, β ENNReal.ofReal_nsmul,
nsmul_eq_mul, mul_div_cancelβ]
exact Nat.cast_ne_zero.mpr hj.ne'
rw [ENNReal.div_eq_div_iff hTβ ENNReal.ofReal_ne_top hIβ hIβ,
volume_of_add_preimage_eq s _ (u j) d huj (huβ j) closedBall_ae_eq_ball, nsmul_eq_mul, β
mul_assoc, this, hIβ]
theorem ergodic_zsmul {n : β€} (hn : 1 < |n|) : Ergodic fun y : AddCircle T => n β’ y :=
{ measurePreserving_zsmul volume (abs_pos.mp <| lt_trans zero_lt_one hn) with
aeconst_set := fun s hs hs' => by
let u : β β AddCircle T := fun j => β((β1 : β) / β(n.natAbs ^ j) * T)
replace hn : 1 < n.natAbs := by rwa [Int.abs_eq_natAbs, Nat.one_lt_cast] at hn
have huβ : β j, addOrderOf (u j) = n.natAbs ^ j := fun j => by
convert addOrderOf_div_of_gcd_eq_one (p := T) (m := 1)
(pow_pos (pos_of_gt hn) j) (gcd_one_left _)
norm_cast
have hnu : β j, n ^ j β’ u j = 0 := fun j => by
rw [β addOrderOf_dvd_iff_zsmul_eq_zero, huβ, Int.natCast_pow, Int.natCast_natAbs, β abs_pow,
abs_dvd]
have huβ : β j, (u j +α΅₯ s : Set _) =α΅[volume] s := fun j => by
rw [vadd_eq_self_of_preimage_zsmul_eq_self hs' (hnu j)]
have huβ : Tendsto (fun j => addOrderOf <| u j) atTop atTop := by
simp_rw [huβ]; exact Nat.tendsto_pow_atTop_atTop_of_one_lt hn
rw [eventuallyConst_set']
exact ae_empty_or_univ_of_forall_vadd_ae_eq_self hs.nullMeasurableSet huβ huβ }
theorem ergodic_nsmul {n : β} (hn : 1 < n) : Ergodic fun y : AddCircle T => n β’ y :=
ergodic_zsmul (by simp [hn] : 1 < |(n : β€)|)
theorem ergodic_zsmul_add (x : AddCircle T) {n : β€} (h : 1 < |n|) : Ergodic fun y => n β’ y + x := by
set f : AddCircle T β AddCircle T := fun y => n β’ y + x
let e : AddCircle T βα΅ AddCircle T := MeasurableEquiv.addLeft (DivisibleBy.div x <| n - 1)
have he : MeasurePreserving e volume volume :=
measurePreserving_add_left volume (DivisibleBy.div x <| n - 1)
suffices e β f β e.symm = fun y => n β’ y by
rw [β he.ergodic_conjugate_iff, this]; exact ergodic_zsmul h
replace h : n - 1 β 0 := by
rw [β abs_one] at h; rw [sub_ne_zero]; exact ne_of_apply_ne _ (ne_of_gt h)
have hnx : n β’ DivisibleBy.div x (n - 1) = x + DivisibleBy.div x (n - 1) := by
conv_rhs => congr; rw [β DivisibleBy.div_cancel x h]
rw [sub_smul, one_smul, sub_add_cancel]
ext y
simp only [f, e, hnx, MeasurableEquiv.coe_addLeft, MeasurableEquiv.symm_addLeft, comp_apply,
smul_add, zsmul_neg', neg_smul, neg_add_rev]
abel
theorem ergodic_nsmul_add (x : AddCircle T) {n : β} (h : 1 < n) : Ergodic fun y => n β’ y + x :=
ergodic_zsmul_add x (by simp [h] : 1 < |(n : β€)|)
end AddCircle
|
RCLike.lean
|
/-
Copyright (c) 2023 Xavier GΓ©nΓ©reux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier GΓ©nΓ©reux, Patrick Massot
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Analysis.RCLike.Basic
/-!
# A collection of specific limit computations for `RCLike`
-/
open Set Algebra Filter
open scoped Topology
namespace RCLike
variable (π : Type*) [RCLike π]
theorem tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : β => (n : π)β»ΒΉ) atTop (π 0) := by
convert tendsto_algebraMap_inverse_atTop_nhds_zero_nat π
simp
theorem tendsto_ofReal_cobounded_cobounded :
Tendsto ofReal (Bornology.cobounded β) (Bornology.cobounded π) :=
tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_norm_cobounded_atTop)
theorem tendsto_ofReal_atTop_cobounded :
Tendsto ofReal atTop (Bornology.cobounded π) :=
tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_abs_atTop_atTop)
theorem tendsto_ofReal_atBot_cobounded :
Tendsto ofReal atBot (Bornology.cobounded π) :=
tendsto_norm_atTop_iff_cobounded.mp (mod_cast tendsto_abs_atBot_atTop)
variable {π}
theorem tendsto_add_mul_div_add_mul_atTop_nhds (a b c : π) {d : π} (hd : d β 0) :
Tendsto (fun k : β β¦ (a + c * k) / (b + d * k)) atTop (π (c / d)) := by
apply Filter.Tendsto.congr'
case fβ => exact fun k β¦ (a * (βk)β»ΒΉ + c) / (b * (βk)β»ΒΉ + d)
Β· refine (eventually_ne_atTop 0).mp (Eventually.of_forall ?_)
intro h hx
field_simp [hx]
Β· apply Filter.Tendsto.div _ _ hd
all_goals
apply zero_add (_ : π) βΈ Filter.Tendsto.add_const _ _
apply mul_zero (_ : π) βΈ Filter.Tendsto.const_mul _ _
exact tendsto_inverse_atTop_nhds_zero_nat π
end RCLike
|
Continuous.lean
|
/-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, SΓ©bastien GouΓ«zel, FrΓ©dΓ©ric Dupuis
-/
import Mathlib.Analysis.InnerProductSpace.Basic
import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps
/-!
# Continuity of inner product
We show that the inner product is continuous, `continuous_inner`.
## Tags
inner product space, Hilbert space, norm
-/
noncomputable section
open RCLike Real Filter Topology ComplexConjugate Finsupp
open LinearMap renaming BilinForm β BilinForm
variable {π E F : Type*} [RCLike π]
section Continuous
variable [SeminormedAddCommGroup E] [InnerProductSpace π E]
local notation "βͺ" x ", " y "β«" => inner π x y
/-!
### Continuity of the inner product
-/
/-- When an inner product space `E` over `π` is considered as a real normed space, its inner
product satisfies `IsBoundedBilinearMap`.
In order to state these results, we need a `NormedSpace β E` instance. We will later establish
such an instance by restriction-of-scalars, `InnerProductSpace.rclikeToReal π E`, but this
instance may be not definitionally equal to some other βnaturalβ instance. So, we assume
`[NormedSpace β E]`.
-/
theorem _root_.isBoundedBilinearMap_inner [NormedSpace β E] [IsScalarTower β π E] :
IsBoundedBilinearMap β fun p : E Γ E => βͺp.1, p.2β« :=
{ add_left := inner_add_left
smul_left := fun r x y => by
simp only [β algebraMap_smul π r x, algebraMap_eq_ofReal, inner_smul_real_left]
add_right := inner_add_right
smul_right := fun r x y => by
simp only [β algebraMap_smul π r y, algebraMap_eq_ofReal, inner_smul_real_right]
bound :=
β¨1, zero_lt_one, fun x y => by
rw [one_mul]
exact norm_inner_le_norm x yβ© }
theorem continuous_inner : Continuous fun p : E Γ E => βͺp.1, p.2β« :=
letI : InnerProductSpace β E := InnerProductSpace.rclikeToReal π E
letI : IsScalarTower β π E := RestrictScalars.isScalarTower _ _ _
isBoundedBilinearMap_inner.continuous
variable {Ξ± : Type*}
theorem Filter.Tendsto.inner {f g : Ξ± β E} {l : Filter Ξ±} {x y : E} (hf : Tendsto f l (π x))
(hg : Tendsto g l (π y)) : Tendsto (fun t => βͺf t, g tβ«) l (π βͺx, yβ«) :=
(continuous_inner.tendsto _).comp (hf.prodMk_nhds hg)
variable [TopologicalSpace Ξ±] {f g : Ξ± β E} {x : Ξ±} {s : Set Ξ±}
theorem ContinuousWithinAt.inner (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) :
ContinuousWithinAt (fun t => βͺf t, g tβ«) s x :=
Filter.Tendsto.inner hf hg
@[fun_prop]
theorem ContinuousAt.inner (hf : ContinuousAt f x) (hg : ContinuousAt g x) :
ContinuousAt (fun t => βͺf t, g tβ«) x :=
Filter.Tendsto.inner hf hg
@[fun_prop]
theorem ContinuousOn.inner (hf : ContinuousOn f s) (hg : ContinuousOn g s) :
ContinuousOn (fun t => βͺf t, g tβ«) s := fun x hx => (hf x hx).inner (hg x hx)
@[continuity, fun_prop]
theorem Continuous.inner (hf : Continuous f) (hg : Continuous g) : Continuous fun t => βͺf t, g tβ« :=
continuous_iff_continuousAt.2 fun _x => by fun_prop
end Continuous
|
Cardinality.lean
|
/-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Order.Group.Pointwise.Interval
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.Rat.Cardinal
import Mathlib.SetTheory.Cardinal.Continuum
/-!
# The cardinality of the reals
This file shows that the real numbers have cardinality continuum, i.e. `#β = π `.
We show that `#β β€ π ` by noting that every real number is determined by a Cauchy-sequence of the
form `β β β`, which has cardinality `π `. To show that `#β β₯ π ` we define an injection from
`{0, 1} ^ β` to `β` with `f β¦ Ξ£ n, f n * (1 / 3) ^ n`.
We conclude that all intervals with distinct endpoints have cardinality continuum.
## Main definitions
* `Cardinal.cantorFunction` is the function that sends `f` in `{0, 1} ^ β` to `β` by
`f β¦ Ξ£' n, f n * (1 / 3) ^ n`
## Main statements
* `Cardinal.mk_real : #β = π `: the reals have cardinality continuum.
* `Cardinal.not_countable_real`: the universal set of real numbers is not countable.
We can use this same proof to show that all the other sets in this file are not countable.
* 8 lemmas of the form `mk_Ixy_real` for `x,y β {i,o,c}` state that intervals on the reals
have cardinality continuum.
## Notation
* `π ` : notation for `Cardinal.continuum` in locale `Cardinal`, defined in `SetTheory.Continuum`.
## Tags
continuum, cardinality, reals, cardinality of the reals
-/
open Nat Set
open Cardinal
noncomputable section
namespace Cardinal
variable {c : β} {f g : β β Bool} {n : β}
/-- The body of the sum in `cantorFunction`.
`cantorFunctionAux c f n = c ^ n` if `f n = true`;
`cantorFunctionAux c f n = 0` if `f n = false`. -/
def cantorFunctionAux (c : β) (f : β β Bool) (n : β) : β :=
cond (f n) (c ^ n) 0
@[simp]
theorem cantorFunctionAux_true (h : f n = true) : cantorFunctionAux c f n = c ^ n := by
simp [cantorFunctionAux, h]
@[simp]
theorem cantorFunctionAux_false (h : f n = false) : cantorFunctionAux c f n = 0 := by
simp [cantorFunctionAux, h]
theorem cantorFunctionAux_nonneg (h : 0 β€ c) : 0 β€ cantorFunctionAux c f n := by
cases h' : f n
Β· simp [h']
Β· simpa [h'] using pow_nonneg h _
theorem cantorFunctionAux_eq (h : f n = g n) :
cantorFunctionAux c f n = cantorFunctionAux c g n := by simp [cantorFunctionAux, h]
theorem cantorFunctionAux_zero (f : β β Bool) : cantorFunctionAux c f 0 = cond (f 0) 1 0 := by
cases h : f 0 <;> simp [h]
theorem cantorFunctionAux_succ (f : β β Bool) :
(fun n => cantorFunctionAux c f (n + 1)) = fun n =>
c * cantorFunctionAux c (fun n => f (n + 1)) n := by
ext n
cases h : f (n + 1) <;> simp [h, _root_.pow_succ']
theorem summable_cantor_function (f : β β Bool) (h1 : 0 β€ c) (h2 : c < 1) :
Summable (cantorFunctionAux c f) := by
apply (summable_geometric_of_lt_one h1 h2).summable_of_eq_zero_or_self
intro n; cases h : f n <;> simp [h]
/-- `cantorFunction c (f : β β Bool)` is `Ξ£ n, f n * c ^ n`, where `true` is interpreted as `1` and
`false` is interpreted as `0`. It is implemented using `cantorFunctionAux`. -/
def cantorFunction (c : β) (f : β β Bool) : β :=
β' n, cantorFunctionAux c f n
theorem cantorFunction_le (h1 : 0 β€ c) (h2 : c < 1) (h3 : β n, f n β g n) :
cantorFunction c f β€ cantorFunction c g := by
apply (summable_cantor_function f h1 h2).tsum_le_tsum _ (summable_cantor_function g h1 h2)
intro n; cases h : f n
Β· simp [h, cantorFunctionAux_nonneg h1]
replace h3 : g n = true := h3 n h; simp [h, h3]
theorem cantorFunction_succ (f : β β Bool) (h1 : 0 β€ c) (h2 : c < 1) :
cantorFunction c f = cond (f 0) 1 0 + c * cantorFunction c fun n => f (n + 1) := by
rw [cantorFunction, (summable_cantor_function f h1 h2).tsum_eq_zero_add]
rw [cantorFunctionAux_succ, tsum_mul_left, cantorFunctionAux, pow_zero, cantorFunction]
/-- `cantorFunction c` is strictly increasing with if `0 < c < 1/2`, if we endow `β β Bool` with a
lexicographic order. The lexicographic order doesn't exist for these infinitary products, so we
explicitly write out what it means. -/
theorem increasing_cantorFunction (h1 : 0 < c) (h2 : c < 1 / 2) {n : β} {f g : β β Bool}
(hn : β k < n, f k = g k) (fn : f n = false) (gn : g n = true) :
cantorFunction c f < cantorFunction c g := by
have h3 : c < 1 := by
apply h2.trans
norm_num
induction' n with n ih generalizing f g
Β· let f_max : β β Bool := fun n => Nat.rec false (fun _ _ => true) n
have hf_max : β n, f n β f_max n := by
intro n hn
cases n
Β· rw [fn] at hn
contradiction
simp [f_max]
let g_min : β β Bool := fun n => Nat.rec true (fun _ _ => false) n
have hg_min : β n, g_min n β g n := by
intro n hn
cases n
Β· rw [gn]
simp at hn
apply (cantorFunction_le (le_of_lt h1) h3 hf_max).trans_lt
refine lt_of_lt_of_le ?_ (cantorFunction_le (le_of_lt h1) h3 hg_min)
have : c / (1 - c) < 1 := by
rw [div_lt_one, lt_sub_iff_add_lt]
Β· convert _root_.add_lt_add h2 h2
norm_num
rwa [sub_pos]
convert this
Β· rw [cantorFunction_succ _ (le_of_lt h1) h3, div_eq_mul_inv, β
tsum_geometric_of_lt_one (le_of_lt h1) h3]
apply zero_add
Β· refine (tsum_eq_single 0 ?_).trans ?_
Β· intro n hn
cases n
Β· contradiction
simp [g_min]
Β· exact cantorFunctionAux_zero _
rw [cantorFunction_succ f (le_of_lt h1) h3, cantorFunction_succ g (le_of_lt h1) h3]
rw [hn 0 <| zero_lt_succ n]
apply add_lt_add_left
rw [mul_lt_mul_left h1]
exact ih (fun k hk => hn _ <| Nat.succ_lt_succ hk) fn gn
/-- `cantorFunction c` is injective if `0 < c < 1/2`. -/
theorem cantorFunction_injective (h1 : 0 < c) (h2 : c < 1 / 2) :
Function.Injective (cantorFunction c) := by
intro f g hfg
classical
contrapose hfg with h
have : β n, f n β g n := Function.ne_iff.mp h
let n := Nat.find this
have hn : β k : β, k < n β f k = g k := by
intro k hk
apply of_not_not
exact Nat.find_min this hk
cases fn : f n
Β· apply _root_.ne_of_lt
refine increasing_cantorFunction h1 h2 hn fn ?_
apply Bool.eq_true_of_not_eq_false
rw [β fn]
apply Ne.symm
exact Nat.find_spec this
Β· apply _root_.ne_of_gt
refine increasing_cantorFunction h1 h2 (fun k hk => (hn k hk).symm) ?_ fn
apply Bool.eq_false_of_not_eq_true
rw [β fn]
apply Ne.symm
exact Nat.find_spec this
/-- The cardinality of the reals, as a type. -/
theorem mk_real : #β = π := by
apply le_antisymm
Β· rw [Real.equivCauchy.cardinal_eq]
apply mk_quotient_le.trans
apply (mk_subtype_le _).trans_eq
rw [β power_def, mk_nat, mkRat, aleph0_power_aleph0]
Β· convert mk_le_of_injective (cantorFunction_injective _ _)
Β· rw [β power_def, mk_bool, mk_nat, two_power_aleph0]
Β· exact 1 / 3
Β· norm_num
Β· norm_num
/-- The cardinality of the reals, as a set. -/
theorem mk_univ_real : #(Set.univ : Set β) = π := by rw [mk_univ, mk_real]
/-- **Non-Denumerability of the Continuum**: The reals are not countable. -/
instance : Uncountable β := by
rw [β aleph0_lt_mk_iff, mk_real]
exact aleph0_lt_continuum
theorem not_countable_real : Β¬(Set.univ : Set β).Countable :=
not_countable_univ
/-- The cardinality of the interval (a, β). -/
theorem mk_Ioi_real (a : β) : #(Ioi a) = π := by
refine le_antisymm (mk_real βΈ mk_set_le _) ?_
rw [β not_lt]
intro h
refine _root_.ne_of_lt ?_ mk_univ_real
have hu : Iio a βͺ {a} βͺ Ioi a = Set.univ := by
convert @Iic_union_Ioi β _ _
exact Iio_union_right
rw [β hu]
refine lt_of_le_of_lt (mk_union_le _ _) ?_
refine lt_of_le_of_lt (add_le_add_right (mk_union_le _ _) _) ?_
have h2 : (fun x => a + a - x) '' Ioi a = Iio a := by
convert @image_const_sub_Ioi β _ _ _
simp
rw [β h2]
refine add_lt_of_lt (cantor _).le ?_ h
refine add_lt_of_lt (cantor _).le (mk_image_le.trans_lt h) ?_
rw [mk_singleton]
exact one_lt_aleph0.trans (cantor _)
/-- The cardinality of the interval [a, β). -/
theorem mk_Ici_real (a : β) : #(Ici a) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioi_real a βΈ mk_le_mk_of_subset Ioi_subset_Ici_self)
/-- The cardinality of the interval (-β, a). -/
theorem mk_Iio_real (a : β) : #(Iio a) = π := by
refine le_antisymm (mk_real βΈ mk_set_le _) ?_
have h2 : (fun x => a + a - x) '' Iio a = Ioi a := by
simp only [image_const_sub_Iio, add_sub_cancel_right]
exact mk_Ioi_real a βΈ h2 βΈ mk_image_le
/-- The cardinality of the interval (-β, a]. -/
theorem mk_Iic_real (a : β) : #(Iic a) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Iio_real a βΈ mk_le_mk_of_subset Iio_subset_Iic_self)
/-- The cardinality of the interval (a, b). -/
theorem mk_Ioo_real {a b : β} (h : a < b) : #(Ioo a b) = π := by
refine le_antisymm (mk_real βΈ mk_set_le _) ?_
have h1 : #((fun x => x - a) '' Ioo a b) β€ #(Ioo a b) := mk_image_le
refine le_trans ?_ h1
rw [image_sub_const_Ioo, sub_self]
replace h := sub_pos_of_lt h
have h2 : #(Inv.inv '' Ioo 0 (b - a)) β€ #(Ioo 0 (b - a)) := mk_image_le
refine le_trans ?_ h2
rw [image_inv_eq_inv, inv_Ioo_0_left h, mk_Ioi_real]
/-- The cardinality of the interval [a, b). -/
theorem mk_Ico_real {a b : β} (h : a < b) : #(Ico a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Ico_self)
/-- The cardinality of the interval [a, b]. -/
theorem mk_Icc_real {a b : β} (h : a < b) : #(Icc a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Icc_self)
/-- The cardinality of the interval (a, b]. -/
theorem mk_Ioc_real {a b : β} (h : a < b) : #(Ioc a b) = π :=
le_antisymm (mk_real βΈ mk_set_le _) (mk_Ioo_real h βΈ mk_le_mk_of_subset Ioo_subset_Ioc_self)
end Cardinal
|
PiLex.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.Order.WellFounded
import Mathlib.Tactic.Common
/-!
# Lexicographic order on Pi types
This file defines the lexicographic order for Pi types. `a` is less than `b` if `a i = b i` for all
`i` up to some point `k`, and `a k < b k`.
## Notation
* `Ξ β i, Ξ± i`: Pi type equipped with the lexicographic order. Type synonym of `Ξ i, Ξ± i`.
## See also
Related files are:
* `Data.Finset.Colex`: Colexicographic order on finite sets.
* `Data.List.Lex`: Lexicographic order on lists.
* `Data.Sigma.Order`: Lexicographic order on `Ξ£β i, Ξ± i`.
* `Data.PSigma.Order`: Lexicographic order on `Ξ£β' i, Ξ± i`.
* `Data.Prod.Lex`: Lexicographic order on `Ξ± Γ Ξ²`.
-/
assert_not_exists Monoid
variable {ΞΉ : Type*} {Ξ² : ΞΉ β Type*} (r : ΞΉ β ΞΉ β Prop) (s : β {i}, Ξ² i β Ξ² i β Prop)
namespace Pi
/-- The lexicographic relation on `Ξ i : ΞΉ, Ξ² i`, where `ΞΉ` is ordered by `r`,
and each `Ξ² i` is ordered by `s`. -/
protected def Lex (x y : β i, Ξ² i) : Prop :=
β i, (β j, r j i β x j = y j) β§ s (x i) (y i)
/- This unfortunately results in a type that isn't delta-reduced, so we keep the notation out of the
basic API, just in case -/
/-- The notation `Ξ β i, Ξ± i` refers to a pi type equipped with the lexicographic order. -/
notation3 (prettyPrint := false) "Ξ β "(...)", "r:(scoped p => Lex (β i, p i)) => r
@[simp]
theorem toLex_apply (x : β i, Ξ² i) (i : ΞΉ) : toLex x i = x i :=
rfl
@[simp]
theorem ofLex_apply (x : Lex (β i, Ξ² i)) (i : ΞΉ) : ofLex x i = x i :=
rfl
theorem lex_lt_of_lt_of_preorder [β i, Preorder (Ξ² i)] {r} (hwf : WellFounded r) {x y : β i, Ξ² i}
(hlt : x < y) : β i, (β j, r j i β x j β€ y j β§ y j β€ x j) β§ x i < y i :=
let h' := Pi.lt_def.1 hlt
let β¨i, hi, hlβ© := hwf.has_min _ h'.2
β¨i, fun j hj => β¨h'.1 j, not_not.1 fun h => hl j (lt_of_le_not_ge (h'.1 j) h) hjβ©, hiβ©
theorem lex_lt_of_lt [β i, PartialOrder (Ξ² i)] {r} (hwf : WellFounded r) {x y : β i, Ξ² i}
(hlt : x < y) : Pi.Lex r (@fun _ => (Β· < Β·)) x y := by
simp_rw [Pi.Lex, le_antisymm_iff]
exact lex_lt_of_lt_of_preorder hwf hlt
theorem isTrichotomous_lex [β i, IsTrichotomous (Ξ² i) s] (wf : WellFounded r) :
IsTrichotomous (β i, Ξ² i) (Pi.Lex r @s) :=
{ trichotomous := fun a b => by
rcases eq_or_ne a b with hab | hab
Β· exact Or.inr (Or.inl hab)
Β· rw [Function.ne_iff] at hab
let i := wf.min _ hab
have hri : β j, r j i β a j = b j := by
intro j
rw [β not_imp_not]
exact fun h' => wf.not_lt_min _ _ h'
have hne : a i β b i := wf.min_mem _ hab
rcases trichotomous_of s (a i) (b i) with hi | hi
exacts [Or.inl β¨i, hri, hiβ©,
Or.inr <| Or.inr <| β¨i, fun j hj => (hri j hj).symm, hi.resolve_left hneβ©] }
instance [LT ΞΉ] [β a, LT (Ξ² a)] : LT (Lex (β i, Ξ² i)) :=
β¨Pi.Lex (Β· < Β·) @fun _ => (Β· < Β·)β©
instance Lex.isStrictOrder [LinearOrder ΞΉ] [β a, PartialOrder (Ξ² a)] :
IsStrictOrder (Lex (β i, Ξ² i)) (Β· < Β·) where
irrefl := fun a β¨k, _, hkββ© => lt_irrefl (a k) hkβ
trans := by
rintro a b c β¨Nβ, lt_Nβ, a_lt_bβ© β¨Nβ, lt_Nβ, b_lt_cβ©
rcases lt_trichotomy Nβ Nβ with (H | rfl | H)
exacts [β¨Nβ, fun j hj => (lt_Nβ _ hj).trans (lt_Nβ _ <| hj.trans H), lt_Nβ _ H βΈ a_lt_bβ©,
β¨Nβ, fun j hj => (lt_Nβ _ hj).trans (lt_Nβ _ hj), a_lt_b.trans b_lt_cβ©,
β¨Nβ, fun j hj => (lt_Nβ _ (hj.trans H)).trans (lt_Nβ _ hj), (lt_Nβ _ H).symm βΈ b_lt_cβ©]
instance [LinearOrder ΞΉ] [β a, PartialOrder (Ξ² a)] : PartialOrder (Lex (β i, Ξ² i)) :=
partialOrderOfSO (Β· < Β·)
/-- `Ξ β i, Ξ± i` is a linear order if the original order is well-founded. -/
noncomputable instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [β a, LinearOrder (Ξ² a)] :
LinearOrder (Lex (β i, Ξ² i)) :=
@linearOrderOfSTO (Ξ β i, Ξ² i) (Β· < Β·)
{ trichotomous := (isTrichotomous_lex _ _ IsWellFounded.wf).1 } (Classical.decRel _)
section PartialOrder
variable [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [β i, PartialOrder (Ξ² i)] {x : β i, Ξ² i} {i : ΞΉ}
{a : Ξ² i}
open Function
theorem toLex_monotone : Monotone (@toLex (β i, Ξ² i)) := fun a b h =>
or_iff_not_imp_left.2 fun hne =>
let β¨i, hi, hlβ© := IsWellFounded.wf.has_min (r := (Β· < Β·)) { i | a i β b i }
(Function.ne_iff.1 hne)
β¨i, fun j hj => by
contrapose! hl
exact β¨j, hl, hjβ©, (h i).lt_of_ne hiβ©
theorem toLex_strictMono : StrictMono (@toLex (β i, Ξ² i)) := fun a b h =>
let β¨i, hi, hlβ© := IsWellFounded.wf.has_min (r := (Β· < Β·)) { i | a i β b i }
(Function.ne_iff.1 h.ne)
β¨i, fun j hj => by
contrapose! hl
exact β¨j, hl, hjβ©, (h.le i).lt_of_ne hiβ©
@[simp]
theorem lt_toLex_update_self_iff : toLex x < toLex (update x i a) β x i < a := by
refine β¨?_, fun h => toLex_strictMono <| lt_update_self_iff.2 hβ©
rintro β¨j, hj, hβ©
dsimp at h
obtain rfl : j = i := by
by_contra H
rw [update_of_ne H] at h
exact h.false
rwa [update_self] at h
@[simp]
theorem toLex_update_lt_self_iff : toLex (update x i a) < toLex x β a < x i := by
refine β¨?_, fun h => toLex_strictMono <| update_lt_self_iff.2 hβ©
rintro β¨j, hj, hβ©
dsimp at h
obtain rfl : j = i := by
by_contra H
rw [update_of_ne H] at h
exact h.false
rwa [update_self] at h
@[simp]
theorem le_toLex_update_self_iff : toLex x β€ toLex (update x i a) β x i β€ a := by
simp_rw [le_iff_lt_or_eq, lt_toLex_update_self_iff, toLex_inj, eq_update_self_iff]
@[simp]
theorem toLex_update_le_self_iff : toLex (update x i a) β€ toLex x β a β€ x i := by
simp_rw [le_iff_lt_or_eq, toLex_update_lt_self_iff, toLex_inj, update_eq_self_iff]
end PartialOrder
instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [β a, PartialOrder (Ξ² a)] [β a, OrderBot (Ξ² a)] :
OrderBot (Lex (β a, Ξ² a)) where
bot := toLex β₯
bot_le _ := toLex_monotone bot_le
instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [β a, PartialOrder (Ξ² a)] [β a, OrderTop (Ξ² a)] :
OrderTop (Lex (β a, Ξ² a)) where
top := toLex β€
le_top _ := toLex_monotone le_top
instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [β a, PartialOrder (Ξ² a)]
[β a, BoundedOrder (Ξ² a)] : BoundedOrder (Lex (β a, Ξ² a)) :=
{ }
instance [Preorder ΞΉ] [β i, LT (Ξ² i)] [β i, DenselyOrdered (Ξ² i)] :
DenselyOrdered (Lex (β i, Ξ² i)) :=
β¨by
rintro _ aβ β¨i, h, hiβ©
obtain β¨a, haβ, haββ© := exists_between hi
classical
refine β¨Function.update aβ _ a, β¨i, fun j hj => ?_, ?_β©, i, fun j hj => ?_, ?_β©
Β· rw [h j hj]
dsimp only at hj
rw [Function.update_of_ne hj.ne a]
Β· rwa [Function.update_self i a]
Β· rw [Function.update_of_ne hj.ne a]
Β· rwa [Function.update_self i a]β©
theorem Lex.noMaxOrder' [Preorder ΞΉ] [β i, LT (Ξ² i)] (i : ΞΉ) [NoMaxOrder (Ξ² i)] :
NoMaxOrder (Lex (β i, Ξ² i)) :=
β¨fun a => by
let β¨b, hbβ© := exists_gt (a i)
classical
exact β¨Function.update a i b, i, fun j hj =>
(Function.update_of_ne hj.ne b a).symm, by rwa [Function.update_self i b]β©β©
instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [Nonempty ΞΉ] [β i, PartialOrder (Ξ² i)]
[β i, NoMaxOrder (Ξ² i)] : NoMaxOrder (Lex (β i, Ξ² i)) :=
β¨fun a =>
let β¨_, hbβ© := exists_gt (ofLex a)
β¨_, toLex_strictMono hbβ©β©
instance [LinearOrder ΞΉ] [WellFoundedLT ΞΉ] [Nonempty ΞΉ] [β i, PartialOrder (Ξ² i)]
[β i, NoMinOrder (Ξ² i)] : NoMinOrder (Lex (β i, Ξ² i)) :=
β¨fun a =>
let β¨_, hbβ© := exists_lt (ofLex a)
β¨_, toLex_strictMono hbβ©β©
/-- If we swap two strictly decreasing values in a function, then the result is lexicographically
smaller than the original function. -/
theorem lex_desc {Ξ±} [Preorder ΞΉ] [DecidableEq ΞΉ] [LT Ξ±] {f : ΞΉ β Ξ±} {i j : ΞΉ} (hβ : i β€ j)
(hβ : f j < f i) : toLex (f β Equiv.swap i j) < toLex f :=
β¨i, fun _ hik => congr_arg f (Equiv.swap_apply_of_ne_of_ne hik.ne (hik.trans_le hβ).ne), by
simpa only [Pi.toLex_apply, Function.comp_apply, Equiv.swap_apply_left] using hββ©
end Pi
|
GromovHausdorff.lean
|
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.Logic.Encodable.Pi
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Topology.MetricSpace.Closeds
import Mathlib.Topology.MetricSpace.Completion
import Mathlib.Topology.MetricSpace.GromovHausdorffRealized
import Mathlib.Topology.MetricSpace.Kuratowski
/-!
# Gromov-Hausdorff distance
This file defines the Gromov-Hausdorff distance on the space of nonempty compact metric spaces
up to isometry.
We introduce the space of all nonempty compact metric spaces, up to isometry,
called `GHSpace`, and endow it with a metric space structure. The distance,
known as the Gromov-Hausdorff distance, is defined as follows: given two
nonempty compact spaces `X` and `Y`, their distance is the minimum Hausdorff distance
between all possible isometric embeddings of `X` and `Y` in all metric spaces.
To define properly the Gromov-Hausdorff space, we consider the non-empty
compact subsets of `β^β(β)` up to isometry, which is a well-defined type,
and define the distance as the infimum of the Hausdorff distance over all
embeddings in `β^β(β)`. We prove that this coincides with the previous description,
as all separable metric spaces embed isometrically into `β^β(β)`, through an
embedding called the Kuratowski embedding.
To prove that we have a distance, we should show that if spaces can be coupled
to be arbitrarily close, then they are isometric. More generally, the Gromov-Hausdorff
distance is realized, i.e., there is a coupling for which the Hausdorff distance
is exactly the Gromov-Hausdorff distance. This follows from a compactness
argument, essentially following from Arzela-Ascoli.
## Main results
We prove the most important properties of the Gromov-Hausdorff space: it is a polish space,
i.e., it is complete and second countable. We also prove the Gromov compactness criterion.
-/
noncomputable section
open scoped Topology ENNReal Cardinal
open Set Function TopologicalSpace Filter Metric Quotient Bornology
open BoundedContinuousFunction Nat Int kuratowskiEmbedding
open Sum (inl inr)
local notation "β_infty_β" => lp (fun n : β => β) β
universe u v w
attribute [local instance] metricSpaceSum
namespace GromovHausdorff
/-! In this section, we define the Gromov-Hausdorff space, denoted `GHSpace` as the quotient
of nonempty compact subsets of `β^β(β)` by identifying isometric sets.
Using the Kuratwoski embedding, we get a canonical map `toGHSpace` mapping any nonempty
compact type to `GHSpace`. -/
section GHSpace
/-- Equivalence relation identifying two nonempty compact sets which are isometric -/
private def IsometryRel (x : NonemptyCompacts β_infty_β) (y : NonemptyCompacts β_infty_β) : Prop :=
Nonempty (x βα΅’ y)
/-- This is indeed an equivalence relation -/
private theorem equivalence_isometryRel : Equivalence IsometryRel :=
β¨fun _ => Nonempty.intro (IsometryEquiv.refl _), fun β¨eβ© => β¨e.symmβ©, fun β¨eβ© β¨fβ© => β¨e.trans fβ©β©
/-- setoid instance identifying two isometric nonempty compact subspaces of β^β(β) -/
instance IsometryRel.setoid : Setoid (NonemptyCompacts β_infty_β) :=
Setoid.mk IsometryRel equivalence_isometryRel
/-- The Gromov-Hausdorff space -/
def GHSpace : Type :=
Quotient IsometryRel.setoid
/-- Map any nonempty compact type to `GHSpace` -/
def toGHSpace (X : Type u) [MetricSpace X] [CompactSpace X] [Nonempty X] : GHSpace :=
β¦NonemptyCompacts.kuratowskiEmbedding Xβ§
instance : Inhabited GHSpace :=
β¨Quot.mk _ β¨β¨{0}, isCompact_singletonβ©, singleton_nonempty _β©β©
/-- A metric space representative of any abstract point in `GHSpace` -/
def GHSpace.Rep (p : GHSpace) : Type :=
(Quotient.out p : NonemptyCompacts β_infty_β)
theorem eq_toGHSpace_iff {X : Type u} [MetricSpace X] [CompactSpace X] [Nonempty X]
{p : NonemptyCompacts β_infty_β} :
β¦pβ§ = toGHSpace X β β Ξ¨ : X β β_infty_β, Isometry Ξ¨ β§ range Ξ¨ = p := by
simp only [toGHSpace, Quotient.eq]
refine β¨fun h => ?_, ?_β©
Β· rcases Setoid.symm h with β¨eβ©
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange.trans e
use fun x => f x, isometry_subtype_coe.comp f.isometry
rw [range_comp', f.range_eq_univ, Set.image_univ, Subtype.range_coe]
Β· rintro β¨Ξ¨, β¨isomΞ¨, rangeΞ¨β©β©
have f :=
((kuratowskiEmbedding.isometry X).isometryEquivOnRange.symm.trans
isomΨ.isometryEquivOnRange).symm
have E : (range Ξ¨ βα΅’ NonemptyCompacts.kuratowskiEmbedding X)
= (p βα΅’ range (kuratowskiEmbedding X)) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rw [rangeΨ]; rfl
exact β¨cast E fβ©
theorem eq_toGHSpace {p : NonemptyCompacts β_infty_β} : β¦pβ§ = toGHSpace p :=
eq_toGHSpace_iff.2 β¨fun x => x, isometry_subtype_coe, Subtype.range_coeβ©
section
instance repGHSpaceMetricSpace {p : GHSpace} : MetricSpace p.Rep :=
inferInstanceAs <| MetricSpace p.out
instance rep_gHSpace_compactSpace {p : GHSpace} : CompactSpace p.Rep :=
inferInstanceAs <| CompactSpace p.out
instance rep_gHSpace_nonempty {p : GHSpace} : Nonempty p.Rep :=
inferInstanceAs <| Nonempty p.out
end
theorem GHSpace.toGHSpace_rep (p : GHSpace) : toGHSpace p.Rep = p := by
change toGHSpace (Quot.out p : NonemptyCompacts β_infty_β) = p
rw [β eq_toGHSpace]
exact Quot.out_eq p
/-- Two nonempty compact spaces have the same image in `GHSpace` if and only if they are
isometric. -/
theorem toGHSpace_eq_toGHSpace_iff_isometryEquiv {X : Type u} [MetricSpace X] [CompactSpace X]
[Nonempty X] {Y : Type v} [MetricSpace Y] [CompactSpace Y] [Nonempty Y] :
toGHSpace X = toGHSpace Y β Nonempty (X βα΅’ Y) :=
β¨by
simp only [toGHSpace]
rw [Quotient.eq]
rintro β¨eβ©
have I :
(NonemptyCompacts.kuratowskiEmbedding X βα΅’ NonemptyCompacts.kuratowskiEmbedding Y) =
(range (kuratowskiEmbedding X) βα΅’ range (kuratowskiEmbedding Y)) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rfl
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange
have g := (kuratowskiEmbedding.isometry Y).isometryEquivOnRange.symm
exact β¨f.trans <| (cast I e).trans gβ©, by
rintro β¨eβ©
simp only [toGHSpace]
have f := (kuratowskiEmbedding.isometry X).isometryEquivOnRange.symm
have g := (kuratowskiEmbedding.isometry Y).isometryEquivOnRange
have I :
(range (kuratowskiEmbedding X) βα΅’ range (kuratowskiEmbedding Y)) =
(NonemptyCompacts.kuratowskiEmbedding X βα΅’ NonemptyCompacts.kuratowskiEmbedding Y) := by
dsimp only [NonemptyCompacts.kuratowskiEmbedding]; rfl
rw [Quotient.eq]
exact β¨cast I ((f.trans e).trans g)β©β©
/-- Distance on `GHSpace`: the distance between two nonempty compact spaces is the infimum
Hausdorff distance between isometric copies of the two spaces in a metric space. For the definition,
we only consider embeddings in `β^β(β)`, but we will prove below that it works for all spaces. -/
instance : Dist GHSpace where
dist x y := sInf <| (fun p : NonemptyCompacts β_infty_β Γ NonemptyCompacts β_infty_β =>
hausdorffDist (p.1 : Set β_infty_β) p.2) '' { a | β¦aβ§ = x } ΓΛ’ { b | β¦bβ§ = y }
/-- The Gromov-Hausdorff distance between two nonempty compact metric spaces, equal by definition to
the distance of the equivalence classes of these spaces in the Gromov-Hausdorff space. -/
def ghDist (X : Type u) (Y : Type v) [MetricSpace X] [Nonempty X] [CompactSpace X] [MetricSpace Y]
[Nonempty Y] [CompactSpace Y] : β :=
dist (toGHSpace X) (toGHSpace Y)
theorem dist_ghDist (p q : GHSpace) : dist p q = ghDist p.Rep q.Rep := by
rw [ghDist, p.toGHSpace_rep, q.toGHSpace_rep]
/-- The Gromov-Hausdorff distance between two spaces is bounded by the Hausdorff distance
of isometric copies of the spaces, in any metric space. -/
theorem ghDist_le_hausdorffDist {X : Type u} [MetricSpace X] [CompactSpace X] [Nonempty X]
{Y : Type v} [MetricSpace Y] [CompactSpace Y] [Nonempty Y] {Ξ³ : Type w} [MetricSpace Ξ³]
{Ξ¦ : X β Ξ³} {Ξ¨ : Y β Ξ³} (ha : Isometry Ξ¦) (hb : Isometry Ξ¨) :
ghDist X Y β€ hausdorffDist (range Ξ¦) (range Ξ¨) := by
/- For the proof, we want to embed `Ξ³` in `β^β(β)`, to say that the Hausdorff distance is realized
in `β^β(β)` and therefore bounded below by the Gromov-Hausdorff-distance. However, `Ξ³` is not
separable in general. We restrict to the union of the images of `X` and `Y` in `Ξ³`, which is
separable and therefore embeddable in `β^β(β)`. -/
rcases exists_mem_of_nonempty X with β¨xX, _β©
let s : Set Ξ³ := range Ξ¦ βͺ range Ξ¨
let Ξ¦' : X β Subtype s := fun y => β¨Ξ¦ y, mem_union_left _ (mem_range_self _)β©
let Ξ¨' : Y β Subtype s := fun y => β¨Ξ¨ y, mem_union_right _ (mem_range_self _)β©
have IΦ' : Isometry Φ' := fun x y => ha x y
have IΨ' : Isometry Ψ' := fun x y => hb x y
have : IsCompact s := (isCompact_range ha.continuous).union (isCompact_range hb.continuous)
let _ : MetricSpace (Subtype s) := by infer_instance
have : CompactSpace (Subtype s) := β¨isCompact_iff_isCompact_univ.1 βΉIsCompact sβΊβ©
have ΦΦ' : Ξ¦ = Subtype.val β Ξ¦' := rfl
have ΨΨ' : Ξ¨ = Subtype.val β Ξ¨' := rfl
have : hausdorffDist (range Ξ¦) (range Ξ¨) = hausdorffDist (range Ξ¦') (range Ξ¨') := by
rw [ΦΦ', ΨΨ', range_comp, range_comp]
exact hausdorffDist_image isometry_subtype_coe
rw [this]
-- Embed `s` in `β^β(β)` through its Kuratowski embedding
let F := kuratowskiEmbedding (Subtype s)
have : hausdorffDist (F '' range Ξ¦') (F '' range Ξ¨') = hausdorffDist (range Ξ¦') (range Ξ¨') :=
hausdorffDist_image (kuratowskiEmbedding.isometry _)
rw [β this]
-- Let `A` and `B` be the images of `X` and `Y` under this embedding. They are in `β^β(β)`, and
-- their Hausdorff distance is the same as in the original space.
let A : NonemptyCompacts β_infty_β :=
β¨β¨F '' range Ξ¦',
(isCompact_range IΞ¦'.continuous).image (kuratowskiEmbedding.isometry _).continuousβ©,
(range_nonempty _).image _β©
let B : NonemptyCompacts β_infty_β :=
β¨β¨F '' range Ξ¨',
(isCompact_range IΞ¨'.continuous).image (kuratowskiEmbedding.isometry _).continuousβ©,
(range_nonempty _).image _β©
have AX : β¦Aβ§ = toGHSpace X := by
rw [eq_toGHSpace_iff]
exact β¨fun x => F (Ξ¦' x), (kuratowskiEmbedding.isometry _).comp IΞ¦', range_comp _ _β©
have BY : β¦Bβ§ = toGHSpace Y := by
rw [eq_toGHSpace_iff]
exact β¨fun x => F (Ξ¨' x), (kuratowskiEmbedding.isometry _).comp IΞ¨', range_comp _ _β©
refine csInf_le β¨0, ?_β© ?_
Β· simp only [lowerBounds, mem_image, mem_prod, mem_setOf_eq, Prod.exists, and_imp,
forall_exists_index]
intro t _ _ _ _ ht
rw [β ht]
exact hausdorffDist_nonneg
apply (mem_image _ _ _).2
exists (β¨A, Bβ© : NonemptyCompacts β_infty_β Γ NonemptyCompacts β_infty_β)
/-- The optimal coupling constructed above realizes exactly the Gromov-Hausdorff distance,
essentially by design. -/
theorem hausdorffDist_optimal {X : Type u} [MetricSpace X] [CompactSpace X] [Nonempty X]
{Y : Type v} [MetricSpace Y] [CompactSpace Y] [Nonempty Y] :
hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) = ghDist X Y := by
inhabit X; inhabit Y
/- we only need to check the inequality `β€`, as the other one follows from the previous lemma.
As the Gromov-Hausdorff distance is an infimum, we need to check that the Hausdorff distance
in the optimal coupling is smaller than the Hausdorff distance of any coupling.
First, we check this for couplings which already have small Hausdorff distance: in this
case, the induced "distance" on `X β Y` belongs to the candidates family introduced in the
definition of the optimal coupling, and the conclusion follows from the optimality
of the optimal coupling within this family.
-/
have A :
β p q : NonemptyCompacts β_infty_β,
β¦pβ§ = toGHSpace X β
β¦qβ§ = toGHSpace Y β
hausdorffDist (p : Set β_infty_β) q < diam (univ : Set X) + 1 + diam (univ : Set Y) β
hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) β€
hausdorffDist (p : Set β_infty_β) q := by
intro p q hp hq bound
rcases eq_toGHSpace_iff.1 hp with β¨Ξ¦, β¨Ξ¦isom, Ξ¦rangeβ©β©
rcases eq_toGHSpace_iff.1 hq with β¨Ξ¨, β¨Ξ¨isom, Ξ¨rangeβ©β©
have I : diam (range Ξ¦ βͺ range Ξ¨) β€ 2 * diam (univ : Set X) + 1 + 2 * diam (univ : Set Y) := by
rcases exists_mem_of_nonempty X with β¨xX, _β©
have : β y β range Ξ¨, dist (Ξ¦ xX) y < diam (univ : Set X) + 1 + diam (univ : Set Y) := by
rw [Ξ¨range]
have : Ξ¦ xX β (p : Set _) := Ξ¦range βΈ (mem_range_self _)
exact
exists_dist_lt_of_hausdorffDist_lt this bound
(hausdorffEdist_ne_top_of_nonempty_of_bounded p.nonempty q.nonempty
p.isCompact.isBounded q.isCompact.isBounded)
rcases this with β¨y, hy, dyβ©
rcases mem_range.1 hy with β¨z, hzyβ©
rw [β hzy] at dy
have DΦ : diam (range Φ) = diam (univ : Set X) := Φisom.diam_range
have DΨ : diam (range Ψ) = diam (univ : Set Y) := Ψisom.diam_range
calc
diam (range Ξ¦ βͺ range Ξ¨) β€ diam (range Ξ¦) + dist (Ξ¦ xX) (Ξ¨ z) + diam (range Ξ¨) :=
diam_union (mem_range_self _) (mem_range_self _)
_ β€
diam (univ : Set X) + (diam (univ : Set X) + 1 + diam (univ : Set Y)) +
diam (univ : Set Y) := by
rw [DΦ, DΨ]
gcongr
_ = 2 * diam (univ : Set X) + 1 + 2 * diam (univ : Set Y) := by ring
let f : X β Y β β_infty_β := fun x =>
match x with
| inl y => Ξ¦ y
| inr z => Ξ¨ z
let F : (X β Y) Γ (X β Y) β β := fun p => dist (f p.1) (f p.2)
-- check that the induced "distance" is a candidate
have Fgood : F β candidates X Y := by
simp only [F, candidates, forall_const,
dist_eq_zero, Set.mem_setOf_eq]
repeat' constructor
Β· exact fun x y =>
calc
F (inl x, inl y) = dist (Ξ¦ x) (Ξ¦ y) := rfl
_ = dist x y := Ξ¦isom.dist_eq x y
Β· exact fun x y =>
calc
F (inr x, inr y) = dist (Ξ¨ x) (Ξ¨ y) := rfl
_ = dist x y := Ξ¨isom.dist_eq x y
Β· exact fun x y => dist_comm _ _
Β· exact fun x y z => dist_triangle _ _ _
Β· exact fun x y =>
calc
F (x, y) β€ diam (range Ξ¦ βͺ range Ξ¨) := by
have A : β z : X β Y, f z β range Ξ¦ βͺ range Ξ¨ := by
intro z
cases z
Β· apply mem_union_left; apply mem_range_self
Β· apply mem_union_right; apply mem_range_self
refine dist_le_diam_of_mem ?_ (A _) (A _)
rw [Ξ¦range, Ξ¨range]
exact (p β q).isCompact.isBounded
_ β€ 2 * diam (univ : Set X) + 1 + 2 * diam (univ : Set Y) := I
let Fb := candidatesBOfCandidates F Fgood
have : hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) β€ HD Fb :=
hausdorffDist_optimal_le_HD _ _ (candidatesBOfCandidates_mem F Fgood)
refine le_trans this (le_of_forall_gt_imp_ge_of_dense fun r hr => ?_)
have I1 : β x : X, (β¨
y, Fb (inl x, inr y)) β€ r := by
intro x
have : f (inl x) β (p : Set _) := Ξ¦range βΈ (mem_range_self _)
rcases exists_dist_lt_of_hausdorffDist_lt this hr
(hausdorffEdist_ne_top_of_nonempty_of_bounded p.nonempty q.nonempty p.isCompact.isBounded
q.isCompact.isBounded) with
β¨z, zq, hzβ©
have : z β range Ξ¨ := by rwa [β Ξ¨range] at zq
rcases mem_range.1 this with β¨y, hyβ©
calc
(β¨
y, Fb (inl x, inr y)) β€ Fb (inl x, inr y) :=
ciInf_le (by simpa only [add_zero] using HD_below_aux1 0) y
_ = dist (Ξ¦ x) (Ξ¨ y) := rfl
_ = dist (f (inl x)) z := by rw [hy]
_ β€ r := le_of_lt hz
have I2 : β y : Y, (β¨
x, Fb (inl x, inr y)) β€ r := by
intro y
have : f (inr y) β (q : Set _) := Ξ¨range βΈ (mem_range_self _)
rcases exists_dist_lt_of_hausdorffDist_lt' this hr
(hausdorffEdist_ne_top_of_nonempty_of_bounded p.nonempty q.nonempty p.isCompact.isBounded
q.isCompact.isBounded) with
β¨z, zq, hzβ©
have : z β range Ξ¦ := by rwa [β Ξ¦range] at zq
rcases mem_range.1 this with β¨x, hxβ©
calc
(β¨
x, Fb (inl x, inr y)) β€ Fb (inl x, inr y) :=
ciInf_le (by simpa only [add_zero] using HD_below_aux2 0) x
_ = dist (Ξ¦ x) (Ξ¨ y) := rfl
_ = dist z (f (inr y)) := by rw [hx]
_ β€ r := le_of_lt hz
simp only [HD, ciSup_le I1, ciSup_le I2, max_le_iff, and_self_iff]
/- Get the same inequality for any coupling. If the coupling is quite good, the desired
inequality has been proved above. If it is bad, then the inequality is obvious. -/
have B :
β p q : NonemptyCompacts β_infty_β,
β¦pβ§ = toGHSpace X β
β¦qβ§ = toGHSpace Y β
hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) β€
hausdorffDist (p : Set β_infty_β) q := by
intro p q hp hq
by_cases h :
hausdorffDist (p : Set β_infty_β) q < diam (univ : Set X) + 1 + diam (univ : Set Y)
Β· exact A p q hp hq h
Β· calc
hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) β€
HD (candidatesBDist X Y) :=
hausdorffDist_optimal_le_HD _ _ candidatesBDist_mem_candidatesB
_ β€ diam (univ : Set X) + 1 + diam (univ : Set Y) := HD_candidatesBDist_le
_ β€ hausdorffDist (p : Set β_infty_β) q := not_lt.1 h
refine le_antisymm ?_ ?_
Β· apply le_csInf
Β· refine (Set.Nonempty.prod ?_ ?_).image _ <;> exact β¨_, rflβ©
Β· rintro b β¨β¨p, qβ©, β¨hp, hqβ©, rflβ©
exact B p q hp hq
Β· exact ghDist_le_hausdorffDist (isometry_optimalGHInjl X Y) (isometry_optimalGHInjr X Y)
/-- The Gromov-Hausdorff distance can also be realized by a coupling in `β^β(β)`, by embedding
the optimal coupling through its Kuratowski embedding. -/
theorem ghDist_eq_hausdorffDist (X : Type u) [MetricSpace X] [CompactSpace X] [Nonempty X]
(Y : Type v) [MetricSpace Y] [CompactSpace Y] [Nonempty Y] :
β Ξ¦ : X β β_infty_β,
β Ξ¨ : Y β β_infty_β,
Isometry Ξ¦ β§ Isometry Ξ¨ β§ ghDist X Y = hausdorffDist (range Ξ¦) (range Ξ¨) := by
let F := kuratowskiEmbedding (OptimalGHCoupling X Y)
let Ξ¦ := F β optimalGHInjl X Y
let Ξ¨ := F β optimalGHInjr X Y
refine β¨Ξ¦, Ξ¨, ?_, ?_, ?_β©
Β· exact (kuratowskiEmbedding.isometry _).comp (isometry_optimalGHInjl X Y)
Β· exact (kuratowskiEmbedding.isometry _).comp (isometry_optimalGHInjr X Y)
Β· rw [β image_univ, β image_univ, image_comp F, image_univ, image_comp F (optimalGHInjr X Y),
image_univ, β hausdorffDist_optimal]
exact (hausdorffDist_image (kuratowskiEmbedding.isometry _)).symm
/-- The Gromov-Hausdorff distance defines a genuine distance on the Gromov-Hausdorff space. -/
instance : MetricSpace GHSpace where
dist := dist
dist_self x := by
rcases exists_rep x with β¨y, hyβ©
refine le_antisymm ?_ ?_
Β· apply csInf_le
Β· exact β¨0, by rintro b β¨β¨u, vβ©, -, rflβ©; exact hausdorffDist_nonnegβ©
Β· simp only [mem_image, mem_prod, mem_setOf_eq, Prod.exists]
exists y, y
simpa only [and_self_iff, hausdorffDist_self_zero, eq_self_iff_true, and_true]
Β· apply le_csInf
Β· exact Set.Nonempty.image _ <| Set.Nonempty.prod β¨y, hyβ© β¨y, hyβ©
Β· rintro b β¨β¨u, vβ©, -, rflβ©; exact hausdorffDist_nonneg
dist_comm x y := by
have A :
(fun p : NonemptyCompacts β_infty_β Γ NonemptyCompacts β_infty_β =>
hausdorffDist (p.1 : Set β_infty_β) p.2) ''
{ a | β¦aβ§ = x } ΓΛ’ { b | β¦bβ§ = y } =
(fun p : NonemptyCompacts β_infty_β Γ NonemptyCompacts β_infty_β =>
hausdorffDist (p.1 : Set β_infty_β) p.2) β
Prod.swap ''
{ a | β¦aβ§ = x } ΓΛ’ { b | β¦bβ§ = y } := by
funext
simp only [comp_apply, Prod.fst_swap, Prod.snd_swap]
congr
-- The next line had `singlePass := true` before https://github.com/leanprover-community/mathlib4/pull/9928,
-- then was changed to be `simp only [hausdorffDist_comm]`,
-- then `singlePass := true` was readded in https://github.com/leanprover-community/mathlib4/pull/8386 because of timeouts.
-- TODO: figure out what causes the slowdown and make it a `simp only` again?
simp +singlePass only [hausdorffDist_comm]
simp only [dist, A, image_comp, image_swap_prod]
eq_of_dist_eq_zero {x} {y} hxy := by
/- To show that two spaces at zero distance are isometric,
we argue that the distance is realized by some coupling.
In this coupling, the two spaces are at zero Hausdorff distance,
i.e., they coincide. Therefore, the original spaces are isometric. -/
rcases ghDist_eq_hausdorffDist x.Rep y.Rep with β¨Ξ¦, Ξ¨, Ξ¦isom, Ξ¨isom, DΦΨβ©
rw [β dist_ghDist, hxy] at DΦΨ
have : range Ξ¦ = range Ξ¨ := by
have hΦ : IsCompact (range Φ) := isCompact_range Φisom.continuous
have hΨ : IsCompact (range Ψ) := isCompact_range Ψisom.continuous
apply (IsClosed.hausdorffDist_zero_iff_eq _ _ _).1 DΦΨ.symm
· exact hΦ.isClosed
· exact hΨ.isClosed
Β· exact hausdorffEdist_ne_top_of_nonempty_of_bounded (range_nonempty _) (range_nonempty _)
hΦ.isBounded hΨ.isBounded
have T : (range Ξ¨ βα΅’ y.Rep) = (range Ξ¦ βα΅’ y.Rep) := by rw [this]
have eΨ := cast T Ψisom.isometryEquivOnRange.symm
have e := Φisom.isometryEquivOnRange.trans eΨ
rw [β x.toGHSpace_rep, β y.toGHSpace_rep, toGHSpace_eq_toGHSpace_iff_isometryEquiv]
exact β¨eβ©
dist_triangle x y z := by
/- To show the triangular inequality between `X`, `Y` and `Z`,
realize an optimal coupling between `X` and `Y` in a space `Ξ³1`,
and an optimal coupling between `Y` and `Z` in a space `Ξ³2`.
Then, glue these metric spaces along `Y`. We get a new space `Ξ³`
in which `X` and `Y` are optimally coupled, as well as `Y` and `Z`.
Apply the triangle inequality for the Hausdorff distance in `Ξ³`
to conclude. -/
let X := x.Rep
let Y := y.Rep
let Z := z.Rep
let Ξ³1 := OptimalGHCoupling X Y
let Ξ³2 := OptimalGHCoupling Y Z
let Ξ¦ : Y β Ξ³1 := optimalGHInjr X Y
have hΦ : Isometry Φ := isometry_optimalGHInjr X Y
let Ξ¨ : Y β Ξ³2 := optimalGHInjl Y Z
have hΨ : Isometry Ψ := isometry_optimalGHInjl Y Z
have Comm : toGlueL hΞ¦ hΞ¨ β optimalGHInjr X Y = toGlueR hΞ¦ hΞ¨ β optimalGHInjl Y Z :=
toGlue_commute hΦ hΨ
calc
dist x z = dist (toGHSpace X) (toGHSpace Z) := by
rw [x.toGHSpace_rep, z.toGHSpace_rep]
_ β€ hausdorffDist (range (toGlueL hΞ¦ hΞ¨ β optimalGHInjl X Y))
(range (toGlueR hΞ¦ hΞ¨ β optimalGHInjr Y Z)) :=
(ghDist_le_hausdorffDist ((toGlueL_isometry hΦ hΨ).comp (isometry_optimalGHInjl X Y))
((toGlueR_isometry hΦ hΨ).comp (isometry_optimalGHInjr Y Z)))
_ β€ hausdorffDist (range (toGlueL hΞ¦ hΞ¨ β optimalGHInjl X Y))
(range (toGlueL hΞ¦ hΞ¨ β optimalGHInjr X Y)) +
hausdorffDist (range (toGlueL hΞ¦ hΞ¨ β optimalGHInjr X Y))
(range (toGlueR hΞ¦ hΞ¨ β optimalGHInjr Y Z)) := by
refine hausdorffDist_triangle <| hausdorffEdist_ne_top_of_nonempty_of_bounded
(range_nonempty _) (range_nonempty _) ?_ ?_
Β· exact (isCompact_range (Isometry.continuous
((toGlueL_isometry hΦ hΨ).comp (isometry_optimalGHInjl X Y)))).isBounded
Β· exact (isCompact_range (Isometry.continuous
((toGlueL_isometry hΦ hΨ).comp (isometry_optimalGHInjr X Y)))).isBounded
_ = hausdorffDist (toGlueL hΦ hΨ '' range (optimalGHInjl X Y))
(toGlueL hΦ hΨ '' range (optimalGHInjr X Y)) +
hausdorffDist (toGlueR hΦ hΨ '' range (optimalGHInjl Y Z))
(toGlueR hΦ hΨ '' range (optimalGHInjr Y Z)) := by
simp only [β range_comp, Comm]
_ = hausdorffDist (range (optimalGHInjl X Y)) (range (optimalGHInjr X Y)) +
hausdorffDist (range (optimalGHInjl Y Z)) (range (optimalGHInjr Y Z)) := by
rw [hausdorffDist_image (toGlueL_isometry hΦ hΨ),
hausdorffDist_image (toGlueR_isometry hΦ hΨ)]
_ = dist (toGHSpace X) (toGHSpace Y) + dist (toGHSpace Y) (toGHSpace Z) := by
rw [hausdorffDist_optimal, hausdorffDist_optimal, ghDist, ghDist]
_ = dist x y + dist y z := by rw [x.toGHSpace_rep, y.toGHSpace_rep, z.toGHSpace_rep]
end GHSpace --section
end GromovHausdorff
/-- In particular, nonempty compacts of a metric space map to `GHSpace`.
We register this in the `TopologicalSpace` namespace to take advantage
of the notation `p.toGHSpace`. -/
def TopologicalSpace.NonemptyCompacts.toGHSpace {X : Type u} [MetricSpace X]
(p : NonemptyCompacts X) : GromovHausdorff.GHSpace :=
GromovHausdorff.toGHSpace p
namespace GromovHausdorff
section NonemptyCompacts
variable {X : Type u} [MetricSpace X]
theorem ghDist_le_nonemptyCompacts_dist (p q : NonemptyCompacts X) :
dist p.toGHSpace q.toGHSpace β€ dist p q := by
have ha : Isometry ((β) : p β X) := isometry_subtype_coe
have hb : Isometry ((β) : q β X) := isometry_subtype_coe
have A : dist p q = hausdorffDist (p : Set X) q := rfl
have I : βp = range ((β) : p β X) := Subtype.range_coe_subtype.symm
have J : βq = range ((β) : q β X) := Subtype.range_coe_subtype.symm
rw [A, I, J]
exact ghDist_le_hausdorffDist ha hb
theorem toGHSpace_lipschitz :
LipschitzWith 1 (NonemptyCompacts.toGHSpace : NonemptyCompacts X β GHSpace) :=
LipschitzWith.mk_one ghDist_le_nonemptyCompacts_dist
theorem toGHSpace_continuous :
Continuous (NonemptyCompacts.toGHSpace : NonemptyCompacts X β GHSpace) :=
toGHSpace_lipschitz.continuous
end NonemptyCompacts
section
/- In this section, we show that if two metric spaces are isometric up to `Ξ΅β`, then their
Gromov-Hausdorff distance is bounded by `Ξ΅β / 2`. More generally, if there are subsets which are
`Ξ΅β`-dense and `Ξ΅β`-dense in two spaces, and isometric up to `Ξ΅β`, then the Gromov-Hausdorff
distance between the spaces is bounded by `Ξ΅β + Ξ΅β/2 + Ξ΅β`. For this, we construct a suitable
coupling between the two spaces, by gluing them (approximately) along the two matching subsets. -/
variable {X : Type u} [MetricSpace X] [CompactSpace X] [Nonempty X] {Y : Type v} [MetricSpace Y]
[CompactSpace Y] [Nonempty Y]
/-- If there are subsets which are `Ξ΅β`-dense and `Ξ΅β`-dense in two spaces, and
isometric up to `Ξ΅β`, then the Gromov-Hausdorff distance between the spaces is bounded by
`Ξ΅β + Ξ΅β/2 + Ξ΅β`. -/
theorem ghDist_le_of_approx_subsets {s : Set X} (Ξ¦ : s β Y) {Ξ΅β Ξ΅β Ξ΅β : β}
(hs : β x : X, β y β s, dist x y β€ Ξ΅β) (hs' : β x : Y, β y : s, dist x (Ξ¦ y) β€ Ξ΅β)
(H : β x y : s, |dist x y - dist (Ξ¦ x) (Ξ¦ y)| β€ Ξ΅β) : ghDist X Y β€ Ξ΅β + Ξ΅β / 2 + Ξ΅β := by
refine le_of_forall_pos_le_add fun Ξ΄ Ξ΄0 => ?_
rcases exists_mem_of_nonempty X with β¨xX, _β©
rcases hs xX with β¨xs, hxs, Dxsβ©
have sne : s.Nonempty := β¨xs, hxsβ©
let _ : Nonempty s := sne.to_subtype
have : 0 β€ Ξ΅β := le_trans (abs_nonneg _) (H β¨xs, hxsβ© β¨xs, hxsβ©)
have : β p q : s, |dist p q - dist (Ξ¦ p) (Ξ¦ q)| β€ 2 * (Ξ΅β / 2 + Ξ΄) := fun p q =>
calc
|dist p q - dist (Ξ¦ p) (Ξ¦ q)| β€ Ξ΅β := H p q
_ β€ 2 * (Ξ΅β / 2 + Ξ΄) := by linarith
-- glue `X` and `Y` along the almost matching subsets
let _ : MetricSpace (X β Y) :=
glueMetricApprox (fun x : s => (x : X)) (fun x => Ξ¦ x) (Ξ΅β / 2 + Ξ΄) (by linarith) this
let Fl := @Sum.inl X Y
let Fr := @Sum.inr X Y
have Il : Isometry Fl := Isometry.of_dist_eq fun x y => rfl
have Ir : Isometry Fr := Isometry.of_dist_eq fun x y => rfl
/- The proof goes as follows : the `ghDist` is bounded by the Hausdorff distance of the images
in the coupling, which is bounded (using the triangular inequality) by the sum of the Hausdorff
distances of `X` and `s` (in the coupling or, equivalently in the original space), of `s` and
`Ξ¦ s`, and of `Ξ¦ s` and `Y` (in the coupling or, equivalently, in the original space).
The first term is bounded by `Ξ΅β`, by `Ξ΅β`-density. The third one is bounded by `Ξ΅β`.
And the middle one is bounded by `Ξ΅β/2` as in the coupling the points `x` and `Ξ¦ x` are
at distance `Ξ΅β/2` by construction of the coupling (in fact `Ξ΅β/2 + Ξ΄` where `Ξ΄` is an
arbitrarily small positive constant where positivity is used to ensure that the coupling
is really a metric space and not a premetric space on `X β Y`). -/
have : ghDist X Y β€ hausdorffDist (range Fl) (range Fr) := ghDist_le_hausdorffDist Il Ir
have :
hausdorffDist (range Fl) (range Fr) β€
hausdorffDist (range Fl) (Fl '' s) + hausdorffDist (Fl '' s) (range Fr) :=
have B : IsBounded (range Fl) := (isCompact_range Il.continuous).isBounded
hausdorffDist_triangle
(hausdorffEdist_ne_top_of_nonempty_of_bounded (range_nonempty _) (sne.image _) B
(B.subset (image_subset_range _ _)))
have :
hausdorffDist (Fl '' s) (range Fr) β€
hausdorffDist (Fl '' s) (Fr '' range Ξ¦) + hausdorffDist (Fr '' range Ξ¦) (range Fr) :=
have B : IsBounded (range Fr) := (isCompact_range Ir.continuous).isBounded
hausdorffDist_triangle'
(hausdorffEdist_ne_top_of_nonempty_of_bounded ((range_nonempty _).image _) (range_nonempty _)
(B.subset (image_subset_range _ _)) B)
have : hausdorffDist (range Fl) (Fl '' s) β€ Ξ΅β := by
rw [β image_univ, hausdorffDist_image Il]
have : 0 β€ Ξ΅β := le_trans dist_nonneg Dxs
refine hausdorffDist_le_of_mem_dist this (fun x _ => hs x) fun x _ =>
β¨x, mem_univ _, by simpa only [dist_self]β©
have : hausdorffDist (Fl '' s) (Fr '' range Ξ¦) β€ Ξ΅β / 2 + Ξ΄ := by
refine hausdorffDist_le_of_mem_dist (by linarith) ?_ ?_
Β· intro x' hx'
rcases (Set.mem_image _ _ _).1 hx' with β¨x, β¨x_in_s, xx'β©β©
rw [β xx']
use Fr (Ξ¦ β¨x, x_in_sβ©), mem_image_of_mem Fr (mem_range_self _)
exact le_of_eq (glueDist_glued_points (fun x : s => (x : X)) Ξ¦ (Ξ΅β / 2 + Ξ΄) β¨x, x_in_sβ©)
Β· intro x' hx'
rcases (Set.mem_image _ _ _).1 hx' with β¨y, β¨y_in_s', yx'β©β©
rcases mem_range.1 y_in_s' with β¨x, xyβ©
use Fl x, mem_image_of_mem _ x.2
rw [β yx', β xy, dist_comm]
exact le_of_eq (glueDist_glued_points (Z := s) (@Subtype.val X s) Ξ¦ (Ξ΅β / 2 + Ξ΄) x)
have : hausdorffDist (Fr '' range Ξ¦) (range Fr) β€ Ξ΅β := by
rw [β @image_univ _ _ Fr, hausdorffDist_image Ir]
rcases exists_mem_of_nonempty Y with β¨xY, _β©
rcases hs' xY with β¨xs', Dxs'β©
have : 0 β€ Ξ΅β := le_trans dist_nonneg Dxs'
refine hausdorffDist_le_of_mem_dist this
(fun x _ => β¨x, mem_univ _, by simpa only [dist_self]β©)
fun x _ => ?_
rcases hs' x with β¨y, Dyβ©
exact β¨Ξ¦ y, mem_range_self _, Dyβ©
linarith
end
--section
/-- The Gromov-Hausdorff space is second countable. -/
instance : SecondCountableTopology GHSpace := by
refine secondCountable_of_countable_discretization fun Ξ΄ Ξ΄pos => ?_
let Ξ΅ := 2 / 5 * Ξ΄
have Ξ΅pos : 0 < Ξ΅ := mul_pos (by simp) Ξ΄pos
have : β p : GHSpace, β s : Set p.Rep, s.Finite β§ univ β β x β s, ball x Ξ΅ := fun p => by
simpa only [subset_univ, true_and] using
finite_cover_balls_of_compact (X := p.Rep) isCompact_univ Ξ΅pos
-- for each `p`, `s p` is a finite `Ξ΅`-dense subset of `p` (or rather the metric space
-- `p.rep` representing `p`)
choose s hs using this
have : β p : GHSpace, β t : Set p.Rep, t.Finite β β n : β, β _ : Equiv t (Fin n), True := by
intro p t ht
let _ : Fintype t := Finite.fintype ht
exact β¨Fintype.card t, Fintype.equivFin t, trivialβ©
choose N e _ using this
-- cardinality of the nice finite subset `s p` of `p.rep`, called `N p`
let N := fun p : GHSpace => N p (s p) (hs p).1
-- equiv from `s p`, a nice finite subset of `p.rep`, to `Fin (N p)`, called `E p`
let E := fun p : GHSpace => e p (s p) (hs p).1
-- A function `F` associating to `p : GHSpace` the data of all distances between points
-- in the `Ξ΅`-dense set `s p`.
let F : GHSpace β Ξ£ n : β, Fin n β Fin n β β€ := fun p =>
β¨N p, fun a b => βΞ΅β»ΒΉ * dist ((E p).symm a) ((E p).symm b)ββ©
refine β¨Ξ£ n, Fin n β Fin n β β€, by infer_instance, F, fun p q hpq => ?_β©
/- As the target space of F is countable, it suffices to show that two points
`p` and `q` with `F p = F q` are at distance `β€ Ξ΄`.
For this, we construct a map `Ξ¦` from `s p β p.rep` (representing `p`)
to `q.rep` (representing `q`) which is almost an isometry on `s p`, and
with image `s q`. For this, we compose the identification of `s p` with `Fin (N p)`
and the inverse of the identification of `s q` with `Fin (N q)`. Together with
the fact that `N p = N q`, this constructs `Ξ¨` between `s p` and `s q`, and then
composing with the canonical inclusion we get `Ξ¦`. -/
have Npq : N p = N q := (Sigma.mk.inj_iff.1 hpq).1
let Ξ¨ : s p β s q := fun x => (E q).symm (Fin.cast Npq ((E p) x))
let Ξ¦ : s p β q.Rep := fun x => Ξ¨ x
-- Use the almost isometry `Ξ¦` to show that `p.rep` and `q.rep`
-- are within controlled Gromov-Hausdorff distance.
have main : ghDist p.Rep q.Rep β€ Ξ΅ + Ξ΅ / 2 + Ξ΅ := by
refine ghDist_le_of_approx_subsets Ξ¦ ?_ ?_ ?_
Β· show β x : p.Rep, β y β s p, dist x y β€ Ξ΅
-- by construction, `s p` is `Ξ΅`-dense
intro x
have : x β β y β s p, ball y Ξ΅ := (hs p).2 (mem_univ _)
rcases mem_iUnionβ.1 this with β¨y, ys, hyβ©
exact β¨y, ys, le_of_lt hyβ©
Β· show β x : q.Rep, β z : s p, dist x (Ξ¦ z) β€ Ξ΅
-- by construction, `s q` is `Ξ΅`-dense, and it is the range of `Ξ¦`
intro x
have : x β β y β s q, ball y Ξ΅ := (hs q).2 (mem_univ _)
rcases mem_iUnionβ.1 this with β¨y, ys, hyβ©
let i : β := E q β¨y, ysβ©
let hi := ((E q) β¨y, ysβ©).is_lt
have ihi_eq : (β¨i, hiβ© : Fin (N q)) = (E q) β¨y, ysβ© := by rw [Fin.ext_iff, Fin.val_mk]
have hiq : i < N q := hi
have hip : i < N p := by rwa [Npq.symm] at hiq
let z := (E p).symm β¨i, hipβ©
use z
have C1 : (E p) z = β¨i, hipβ© := (E p).apply_symm_apply β¨i, hipβ©
have C2 : Fin.cast Npq β¨i, hipβ© = β¨i, hiβ© := rfl
have C3 : (E q).symm β¨i, hiβ© = β¨y, ysβ© := by
rw [ihi_eq]; exact (E q).symm_apply_apply β¨y, ysβ©
have : Ξ¦ z = y := by simp only [Ξ¦, Ξ¨]; rw [C1, C2, C3]
rw [this]
exact le_of_lt hy
Β· show β x y : s p, |dist x y - dist (Ξ¦ x) (Ξ¦ y)| β€ Ξ΅
/- the distance between `x` and `y` is encoded in `F p`, and the distance between
`Ξ¦ x` and `Ξ¦ y` (two points of `s q`) is encoded in `F q`, all this up to `Ξ΅`.
As `F p = F q`, the distances are almost equal. -/
-- Porting note: we have to circumvent the absence of `change β¦ with β¦ `
intro x y
-- have : dist (Ξ¦ x) (Ξ¦ y) = dist (Ξ¨ x) (Ξ¨ y) := rfl
rw [show dist (Ξ¦ x) (Ξ¦ y) = dist (Ξ¨ x) (Ξ¨ y) from rfl]
-- introduce `i`, that codes both `x` and `Ξ¦ x` in `Fin (N p) = Fin (N q)`
let i : β := E p x
have hip : i < N p := ((E p) x).2
have hiq : i < N q := by rwa [Npq] at hip
have i' : i = (E q) (Ξ¨ x) := by simp only [i, Ξ¨, Equiv.apply_symm_apply, Fin.coe_cast]
-- introduce `j`, that codes both `y` and `Ξ¦ y` in `Fin (N p) = Fin (N q)`
let j : β := E p y
have hjp : j < N p := ((E p) y).2
have hjq : j < N q := by rwa [Npq] at hjp
have j' : j = ((E q) (Ξ¨ y)).1 := by
simp only [j, Ξ¨, Equiv.apply_symm_apply, Fin.coe_cast]
-- Express `dist x y` in terms of `F p`
have : (F p).2 ((E p) x) ((E p) y) = βΞ΅β»ΒΉ * dist x yβ := by
simp only [F, (E p).symm_apply_apply]
have Ap : (F p).2 β¨i, hipβ© β¨j, hjpβ© = βΞ΅β»ΒΉ * dist x yβ := by rw [β this]
-- Express `dist (Ξ¦ x) (Ξ¦ y)` in terms of `F q`
have : (F q).2 ((E q) (Ξ¨ x)) ((E q) (Ξ¨ y)) = βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)β := by
simp only [F, (E q).symm_apply_apply]
have Aq : (F q).2 β¨i, hiqβ© β¨j, hjqβ© = βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)β := by
rw [β this]
-- Porting note: `congr` fails to make progress
refine congr_argβ (F q).2 ?_ ?_ <;> ext1
exacts [i', j']
-- use the equality between `F p` and `F q` to deduce that the distances have equal
-- integer parts
have : (F p).2 β¨i, hipβ© β¨j, hjpβ© = (F q).2 β¨i, hiqβ© β¨j, hjqβ© := by
have hpq' : (F p).snd β (F q).snd := (Sigma.mk.inj_iff.1 hpq).2
rw [Fin.heq_funβ_iff Npq Npq] at hpq'
rw [β hpq']
rw [Ap, Aq] at this
-- deduce that the distances coincide up to `Ξ΅`, by a straightforward computation
-- that should be automated
have I :=
calc
|Ξ΅β»ΒΉ| * |dist x y - dist (Ξ¨ x) (Ξ¨ y)| = |Ξ΅β»ΒΉ * (dist x y - dist (Ξ¨ x) (Ξ¨ y))| :=
(abs_mul _ _).symm
_ = |Ξ΅β»ΒΉ * dist x y - Ξ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)| := by congr; ring
_ β€ 1 := le_of_lt (abs_sub_lt_one_of_floor_eq_floor this)
calc
|dist x y - dist (Ξ¨ x) (Ξ¨ y)| = Ξ΅ * Ξ΅β»ΒΉ * |dist x y - dist (Ξ¨ x) (Ξ¨ y)| := by
rw [mul_inv_cancelβ (ne_of_gt Ξ΅pos), one_mul]
_ = Ξ΅ * (|Ξ΅β»ΒΉ| * |dist x y - dist (Ξ¨ x) (Ξ¨ y)|) := by
rw [abs_of_nonneg (le_of_lt (inv_pos.2 Ξ΅pos)), mul_assoc]
_ β€ Ξ΅ * 1 := mul_le_mul_of_nonneg_left I (le_of_lt Ξ΅pos)
_ = Ξ΅ := mul_one _
calc
dist p q = ghDist p.Rep q.Rep := dist_ghDist p q
_ β€ Ξ΅ + Ξ΅ / 2 + Ξ΅ := main
_ = Ξ΄ := by ring
/-- Compactness criterion: a closed set of compact metric spaces is compact if the spaces have
a uniformly bounded diameter, and for all `Ξ΅` the number of balls of radius `Ξ΅` required
to cover the spaces is uniformly bounded. This is an equivalence, but we only prove the
interesting direction that these conditions imply compactness. -/
theorem totallyBounded {t : Set GHSpace} {C : β} {u : β β β} {K : β β β}
(ulim : Tendsto u atTop (π 0)) (hdiam : β p β t, diam (univ : Set (GHSpace.Rep p)) β€ C)
(hcov : β p β t, β n : β, β s : Set (GHSpace.Rep p),
(#s) β€ K n β§ univ β β x β s, ball x (u n)) :
TotallyBounded t := by
/- Let `Ξ΄>0`, and `Ξ΅ = Ξ΄/5`. For each `p`, we construct a finite subset `s p` of `p`, which
is `Ξ΅`-dense and has cardinality at most `K n`. Encoding the mutual distances of points
in `s p`, up to `Ξ΅`, we will get a map `F` associating to `p` finitely many data, and making
it possible to reconstruct `p` up to `Ξ΅`. This is enough to prove total boundedness. -/
refine Metric.totallyBounded_of_finite_discretization fun Ξ΄ Ξ΄pos => ?_
let Ξ΅ := 1 / 5 * Ξ΄
have Ξ΅pos : 0 < Ξ΅ := mul_pos (by simp) Ξ΄pos
-- choose `n` for which `u n < Ξ΅`
rcases Metric.tendsto_atTop.1 ulim Ξ΅ Ξ΅pos with β¨n, hnβ©
have u_le_Ξ΅ : u n β€ Ξ΅ := by
have := hn n le_rfl
simp only [Real.dist_eq, add_zero, sub_eq_add_neg, neg_zero] at this
exact le_of_lt (lt_of_le_of_lt (le_abs_self _) this)
-- construct a finite subset `s p` of `p` which is `Ξ΅`-dense and has cardinal `β€ K n`
have :
β p : GHSpace,
β s : Set p.Rep, β N β€ K n, β _ : Equiv s (Fin N), p β t β univ β β x β s, ball x (u n) := by
intro p
by_cases hp : p β t
Β· have : Nonempty (Equiv (β
: Set p.Rep) (Fin 0)) := by
rw [β Fintype.card_eq, card_empty, Fintype.card_fin]
use β
, 0, bot_le, this.some
exact fun hp' => (hp hp').elim
Β· rcases hcov _ (Set.not_notMem.1 hp) n with β¨s, β¨scard, scoverβ©β©
rcases Cardinal.lt_aleph0.1 (lt_of_le_of_lt scard (Cardinal.nat_lt_aleph0 _)) with β¨N, hNβ©
rw [hN, Nat.cast_le] at scard
have : #s = #(Fin N) := by rw [hN, Cardinal.mk_fin]
obtain β¨Eβ© := Quotient.exact this
use s, N, scard, E
simp only [scover, imp_true_iff]
choose s N hN E hs using this
-- Define a function `F` taking values in a finite type and associating to `p` enough data
-- to reconstruct it up to `Ξ΅`, namely the (discretized) distances between elements of `s p`.
let M := βΞ΅β»ΒΉ * max C 0ββ
let F : GHSpace β Ξ£ k : Fin (K n).succ, Fin k β Fin k β Fin M.succ := fun p =>
β¨β¨N p, lt_of_le_of_lt (hN p) (Nat.lt_succ_self _)β©, fun a b =>
β¨min M βΞ΅β»ΒΉ * dist ((E p).symm a) ((E p).symm b)ββ,
(min_le_left _ _).trans_lt (Nat.lt_succ_self _)β©β©
refine β¨_, ?_, fun p => F p, ?_β©
Β· infer_instance
-- It remains to show that if `F p = F q`, then `p` and `q` are `Ξ΅`-close
rintro β¨p, ptβ© β¨q, qtβ© hpq
have Npq : N p = N q := Fin.ext_iff.1 (Sigma.mk.inj_iff.1 hpq).1
let Ξ¨ : s p β s q := fun x => (E q).symm (Fin.cast Npq ((E p) x))
let Ξ¦ : s p β q.Rep := fun x => Ξ¨ x
have main : ghDist p.Rep q.Rep β€ Ξ΅ + Ξ΅ / 2 + Ξ΅ := by
-- to prove the main inequality, argue that `s p` is `Ξ΅`-dense in `p`, and `s q` is `Ξ΅`-dense
-- in `q`, and `s p` and `s q` are almost isometric. Then closeness follows
-- from `ghDist_le_of_approx_subsets`
refine ghDist_le_of_approx_subsets Ξ¦ ?_ ?_ ?_
Β· show β x : p.Rep, β y β s p, dist x y β€ Ξ΅
-- by construction, `s p` is `Ξ΅`-dense
intro x
have : x β β y β s p, ball y (u n) := (hs p pt) (mem_univ _)
rcases mem_iUnionβ.1 this with β¨y, ys, hyβ©
exact β¨y, ys, le_trans (le_of_lt hy) u_le_Ξ΅β©
Β· show β x : q.Rep, β z : s p, dist x (Ξ¦ z) β€ Ξ΅
-- by construction, `s q` is `Ξ΅`-dense, and it is the range of `Ξ¦`
intro x
have : x β β y β s q, ball y (u n) := (hs q qt) (mem_univ _)
rcases mem_iUnionβ.1 this with β¨y, ys, hyβ©
let i : β := E q β¨y, ysβ©
let hi := ((E q) β¨y, ysβ©).2
have ihi_eq : (β¨i, hiβ© : Fin (N q)) = (E q) β¨y, ysβ© := by rw [Fin.ext_iff, Fin.val_mk]
have hiq : i < N q := hi
have hip : i < N p := by rwa [Npq.symm] at hiq
let z := (E p).symm β¨i, hipβ©
use z
have C1 : (E p) z = β¨i, hipβ© := (E p).apply_symm_apply β¨i, hipβ©
have C2 : Fin.cast Npq β¨i, hipβ© = β¨i, hiβ© := rfl
have C3 : (E q).symm β¨i, hiβ© = β¨y, ysβ© := by
rw [ihi_eq]; exact (E q).symm_apply_apply β¨y, ysβ©
have : Ξ¦ z = y := by simp only [Ξ¨, Ξ¦]; rw [C1, C2, C3]
rw [this]
exact le_trans (le_of_lt hy) u_le_Ξ΅
Β· show β x y : s p, |dist x y - dist (Ξ¦ x) (Ξ¦ y)| β€ Ξ΅
/- the distance between `x` and `y` is encoded in `F p`, and the distance between
`Ξ¦ x` and `Ξ¦ y` (two points of `s q`) is encoded in `F q`, all this up to `Ξ΅`.
As `F p = F q`, the distances are almost equal. -/
intro x y
have : dist (Ξ¦ x) (Ξ¦ y) = dist (Ξ¨ x) (Ξ¨ y) := rfl
rw [this]
-- introduce `i`, that codes both `x` and `Ξ¦ x` in `Fin (N p) = Fin (N q)`
let i : β := E p x
have hip : i < N p := ((E p) x).2
have hiq : i < N q := by rwa [Npq] at hip
have i' : i = (E q) (Ξ¨ x) := by simp only [i, Ξ¨, Equiv.apply_symm_apply, Fin.coe_cast]
-- introduce `j`, that codes both `y` and `Ξ¦ y` in `Fin (N p) = Fin (N q)`
let j : β := E p y
have hjp : j < N p := ((E p) y).2
have hjq : j < N q := by rwa [Npq] at hjp
have j' : j = (E q) (Ξ¨ y) := by simp only [j, Ξ¨, Equiv.apply_symm_apply, Fin.coe_cast]
-- Express `dist x y` in terms of `F p`
have Ap : ((F p).2 β¨i, hipβ© β¨j, hjpβ©).1 = βΞ΅β»ΒΉ * dist x yββ :=
calc
((F p).2 β¨i, hipβ© β¨j, hjpβ©).1 = ((F p).2 ((E p) x) ((E p) y)).1 := by
congr
_ = min M βΞ΅β»ΒΉ * dist x yββ := by simp only [F, (E p).symm_apply_apply]
_ = βΞ΅β»ΒΉ * dist x yββ := by
refine min_eq_right (Nat.floor_mono ?_)
refine mul_le_mul_of_nonneg_left (le_trans ?_ (le_max_left _ _)) (inv_pos.2 Ξ΅pos).le
change dist (x : p.Rep) y β€ C
refine (dist_le_diam_of_mem isCompact_univ.isBounded (mem_univ _) (mem_univ _)).trans ?_
exact hdiam p pt
-- Express `dist (Ξ¦ x) (Ξ¦ y)` in terms of `F q`
have Aq : ((F q).2 β¨i, hiqβ© β¨j, hjqβ©).1 = βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)ββ :=
calc
((F q).2 β¨i, hiqβ© β¨j, hjqβ©).1 = ((F q).2 ((E q) (Ξ¨ x)) ((E q) (Ξ¨ y))).1 := by
-- Porting note: `congr` drops `Fin.val` but fails to make further progress
exact congr_argβ (Fin.val <| (F q).2 Β· Β·) (Fin.ext i') (Fin.ext j')
_ = min M βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)ββ := by simp only [F, (E q).symm_apply_apply]
_ = βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)ββ := by
refine min_eq_right (Nat.floor_mono ?_)
refine mul_le_mul_of_nonneg_left (le_trans ?_ (le_max_left _ _)) (inv_pos.2 Ξ΅pos).le
change dist (Ξ¨ x : q.Rep) (Ξ¨ y) β€ C
refine (dist_le_diam_of_mem isCompact_univ.isBounded (mem_univ _) (mem_univ _)).trans ?_
exact hdiam q qt
-- use the equality between `F p` and `F q` to deduce that the distances have equal
-- integer parts
have : ((F p).2 β¨i, hipβ© β¨j, hjpβ©).1 = ((F q).2 β¨i, hiqβ© β¨j, hjqβ©).1 := by
have hpq' : (F p).snd β (F q).snd := (Sigma.mk.inj_iff.1 hpq).2
rw [Fin.heq_funβ_iff Npq Npq] at hpq'
rw [β hpq']
have : βΞ΅β»ΒΉ * dist x yβ = βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)β := by
rw [Ap, Aq] at this
have D : 0 β€ βΞ΅β»ΒΉ * dist x yβ :=
floor_nonneg.2 (mul_nonneg (le_of_lt (inv_pos.2 Ξ΅pos)) dist_nonneg)
have D' : 0 β€ βΞ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)β :=
floor_nonneg.2 (mul_nonneg (le_of_lt (inv_pos.2 Ξ΅pos)) dist_nonneg)
rw [β Int.toNat_of_nonneg D, β Int.toNat_of_nonneg D', Int.floor_toNat, Int.floor_toNat,
this]
-- deduce that the distances coincide up to `Ξ΅`, by a straightforward computation
-- that should be automated
have I :=
calc
|Ξ΅β»ΒΉ| * |dist x y - dist (Ξ¨ x) (Ξ¨ y)| = |Ξ΅β»ΒΉ * (dist x y - dist (Ξ¨ x) (Ξ¨ y))| :=
(abs_mul _ _).symm
_ = |Ξ΅β»ΒΉ * dist x y - Ξ΅β»ΒΉ * dist (Ξ¨ x) (Ξ¨ y)| := by congr; ring
_ β€ 1 := le_of_lt (abs_sub_lt_one_of_floor_eq_floor this)
calc
|dist x y - dist (Ξ¨ x) (Ξ¨ y)| = Ξ΅ * Ξ΅β»ΒΉ * |dist x y - dist (Ξ¨ x) (Ξ¨ y)| := by
rw [mul_inv_cancelβ (ne_of_gt Ξ΅pos), one_mul]
_ = Ξ΅ * (|Ξ΅β»ΒΉ| * |dist x y - dist (Ξ¨ x) (Ξ¨ y)|) := by
rw [abs_of_nonneg (le_of_lt (inv_pos.2 Ξ΅pos)), mul_assoc]
_ β€ Ξ΅ * 1 := mul_le_mul_of_nonneg_left I (le_of_lt Ξ΅pos)
_ = Ξ΅ := mul_one _
calc
dist p q = ghDist p.Rep q.Rep := dist_ghDist p q
_ β€ Ξ΅ + Ξ΅ / 2 + Ξ΅ := main
_ = Ξ΄ / 2 := by simp only [Ξ΅, one_div]; ring
_ < Ξ΄ := half_lt_self Ξ΄pos
section Complete
/- We will show that a sequence `u n` of compact metric spaces satisfying
`dist (u n) (u (n+1)) < 1/2^n` converges, which implies completeness of the Gromov-Hausdorff space.
We need to exhibit the limiting compact metric space. For this, start from
a sequence `X n` of representatives of `u n`, and glue in an optimal way `X n` to `X (n+1)`
for all `n`, in a common metric space. Formally, this is done as follows.
Start from `Y 0 = X 0`. Then, glue `X 0` to `X 1` in an optimal way, yielding a space
`Y 1` (with an embedding of `X 1`). Then, consider an optimal gluing of `X 1` and `X 2`, and
glue it to `Y 1` along their common subspace `X 1`. This gives a new space `Y 2`, with an
embedding of `X 2`. Go on, to obtain a sequence of spaces `Y n`. Let `Z0` be the inductive
limit of the `Y n`, and finally let `Z` be the completion of `Z0`.
The images `X2 n` of `X n` in `Z` are at Hausdorff distance `< 1/2^n` by construction, hence they
form a Cauchy sequence for the Hausdorff distance. By completeness (of `Z`, and therefore of its
set of nonempty compact subsets), they converge to a limit `L`. This is the nonempty
compact metric space we are looking for. -/
variable (X : β β Type) [β n, MetricSpace (X n)] [β n, CompactSpace (X n)] [β n, Nonempty (X n)]
/-- Auxiliary structure used to glue metric spaces below, recording an isometric embedding
of a type `A` in another metric space. -/
structure AuxGluingStruct (A : Type) [MetricSpace A] : Type 1 where
Space : Type
metric : MetricSpace Space
embed : A β Space
isom : Isometry embed
attribute [local instance] AuxGluingStruct.metric
instance (A : Type) [MetricSpace A] : Inhabited (AuxGluingStruct A) :=
β¨{ Space := A
metric := by infer_instance
embed := id
isom _ _ := rfl }β©
/-- Auxiliary sequence of metric spaces, containing copies of `X 0`, ..., `X n`, where each
`X i` is glued to `X (i+1)` in an optimal way. The space at step `n+1` is obtained from the space
at step `n` by adding `X (n+1)`, glued in an optimal way to the `X n` already sitting there. -/
def auxGluing (n : β) : AuxGluingStruct (X n) :=
Nat.recOn n default fun n Y =>
{ Space := GlueSpace Y.isom (isometry_optimalGHInjl (X n) (X (n + 1)))
metric := by infer_instance
embed :=
toGlueR Y.isom (isometry_optimalGHInjl (X n) (X (n + 1))) β optimalGHInjr (X n) (X (n + 1))
isom := (toGlueR_isometry _ _).comp (isometry_optimalGHInjr (X n) (X (n + 1))) }
/-- The Gromov-Hausdorff space is complete. -/
instance : CompleteSpace GHSpace := by
set d := fun n : β β¦ ((1 : β) / 2) ^ n
have : β n : β, 0 < d n := fun _ β¦ by positivity
-- start from a sequence of nonempty compact metric spaces within distance `1/2^n` of each other
refine Metric.complete_of_convergent_controlled_sequences d this fun u hu => ?_
-- `X n` is a representative of `u n`
let X n := (u n).Rep
-- glue them together successively in an optimal way, getting a sequence of metric spaces `Y n`
let Y := auxGluing X
-- this equality is true by definition but Lean unfolds some defs in the wrong order
have E :
β n : β,
GlueSpace (Y n).isom (isometry_optimalGHInjl (X n) (X (n + 1))) = (Y (n + 1)).Space :=
fun n => by dsimp only [Y, auxGluing]
let c n := cast (E n)
have ic : β n, Isometry (c n) := fun n x y => by dsimp only [Y, auxGluing]; exact rfl
-- there is a canonical embedding of `Y n` in `Y (n+1)`, by construction
let f : β n, (Y n).Space β (Y (n + 1)).Space := fun n =>
c n β toGlueL (Y n).isom (isometry_optimalGHInjl (X n) (X n.succ))
have I : β n, Isometry (f n) := fun n => (ic n).comp (toGlueL_isometry _ _)
-- consider the inductive limit `Z0` of the `Y n`, and then its completion `Z`
let Z0 := Metric.InductiveLimit I
let Z := UniformSpace.Completion Z0
let Ξ¦ := toInductiveLimit I
let coeZ := ((β) : Z0 β Z)
-- let `X2 n` be the image of `X n` in the space `Z`
let X2 n := range (coeZ β Ξ¦ n β (Y n).embed)
have isom : β n, Isometry (coeZ β Ξ¦ n β (Y n).embed) := by
intro n
refine UniformSpace.Completion.coe_isometry.comp ?_
exact (toInductiveLimit_isometry _ _).comp (Y n).isom
-- The Hausdorff distance of `X2 n` and `X2 (n+1)` is by construction the distance between
-- `u n` and `u (n+1)`, therefore bounded by `1/2^n`
have X2n : β n, X2 n =
range ((coeZ β Ξ¦ n.succ β c n β toGlueR (Y n).isom
(isometry_optimalGHInjl (X n) (X n.succ))) β optimalGHInjl (X n) (X n.succ)) := by
intro n
change X2 n = range (coeZ β Ξ¦ n.succ β c n β
toGlueR (Y n).isom (isometry_optimalGHInjl (X n) (X n.succ)) β
optimalGHInjl (X n) (X n.succ))
simp only [X2, Ξ¦]
rw [β toInductiveLimit_commute I]
simp only [f, β toGlue_commute, Function.comp_assoc]
have X2nsucc : β n, X2 n.succ =
range ((coeZ β Ξ¦ n.succ β c n β toGlueR (Y n).isom
(isometry_optimalGHInjl (X n) (X n.succ))) β optimalGHInjr (X n) (X n.succ)) := by
intro n
rfl
have D2 : β n, hausdorffDist (X2 n) (X2 n.succ) < d n := fun n β¦ by
rw [X2n n, X2nsucc n, range_comp, range_comp, hausdorffDist_image,
hausdorffDist_optimal, β dist_ghDist]
Β· exact hu n n n.succ (le_refl n) (le_succ n)
Β· apply UniformSpace.Completion.coe_isometry.comp _
exact (toInductiveLimit_isometry _ _).comp ((ic n).comp (toGlueR_isometry _ _))
-- consider `X2 n` as a member `X3 n` of the type of nonempty compact subsets of `Z`, which
-- is a metric space
let X3 : β β NonemptyCompacts Z := fun n =>
β¨β¨X2 n, isCompact_range (isom n).continuousβ©, range_nonempty _β©
-- `X3 n` is a Cauchy sequence by construction, as the successive distances are
-- bounded by `(1/2)^n`
have : CauchySeq X3 := by
refine cauchySeq_of_le_geometric (1 / 2) 1 (by norm_num) fun n => ?_
rw [one_mul]
exact le_of_lt (D2 n)
-- therefore, it converges to a limit `L`
rcases cauchySeq_tendsto_of_complete this with β¨L, hLβ©
-- By construction, the image of `X3 n` in the Gromov-Hausdorff space is `u n`.
have : β n, (NonemptyCompacts.toGHSpace β X3) n = u n := by
intro n
rw [Function.comp_apply, NonemptyCompacts.toGHSpace, β (u n).toGHSpace_rep,
toGHSpace_eq_toGHSpace_iff_isometryEquiv]
constructor
convert (isom n).isometryEquivOnRange.symm
-- the images of `X3 n` in the Gromov-Hausdorff space converge to the image of `L`
-- so the images of `u n` converge to the image of `L` as well
use L.toGHSpace
apply Filter.Tendsto.congr this
refine Tendsto.comp ?_ hL
apply toGHSpace_continuous.tendsto
end Complete --section
end GromovHausdorff --namespace
|
Prod.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.Algebra.NoZeroSMulDivisors.Defs
import Mathlib.Algebra.Notation.Prod
/-!
# Prod instances for NoZeroSMulDivisors
This file defines a NoZeroSMulDivisors instance for the binary product of actions.
-/
variable {R M N : Type*}
namespace Prod
instance noZeroSMulDivisors [Zero R] [Zero M] [Zero N]
[SMulWithZero R M] [SMulWithZero R N] [NoZeroSMulDivisors R M] [NoZeroSMulDivisors R N] :
NoZeroSMulDivisors R (M Γ N) where
eq_zero_or_eq_zero_of_smul_eq_zero {c xy} h := by simpa [Prod.ext_iff, or_and_left] using h
end Prod
|
cyclic.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 choice.
From mathcomp Require Import div fintype bigop prime finset fingroup morphism.
From mathcomp Require Import perm automorphism quotient gproduct ssralg.
From mathcomp Require Import finalg zmodp poly.
(******************************************************************************)
(* Properties of cyclic groups. *)
(* Definitions: *)
(* Defined in fingroup.v: *)
(* <[x]> == the cycle (cyclic group) generated by x. *)
(* #[x] == the order of x, i.e., the cardinal of <[x]>. *)
(* Defined in prime.v: *)
(* totient n == Euler's totient function *)
(* Definitions in this file: *)
(* cyclic G <=> G is a cyclic group. *)
(* metacyclic G <=> G is a metacyclic group (i.e., a cyclic extension of a *)
(* cyclic group). *)
(* generator G x <=> x is a generator of the (cyclic) group G. *)
(* Zpm x == the isomorphism mapping the additive group of integers *)
(* mod #[x] to the cyclic group <[x]>. *)
(* cyclem x n == the endomorphism y |-> y ^+ n of <[x]>. *)
(* Zp_unitm x == the isomorphism mapping the multiplicative group of the *)
(* units of the ring of integers mod #[x] to the group of *)
(* automorphisms of <[x]> (i.e., Aut <[x]>). *)
(* Zp_unitm x maps u to cyclem x u. *)
(* eltm dvd_y_x == the smallest morphism (with domain <[x]>) mapping x to *)
(* y, given a proof dvd_y_x : #[y] %| #[x]. *)
(* expg_invn G k == if coprime #|G| k, the inverse of exponent k in G. *)
(* Basic results for these notions, plus the classical result that any finite *)
(* group isomorphic to a subgroup of a field is cyclic, hence that Aut G is *)
(* cyclic when G is of prime order. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope GRing.Theory.
(***********************************************************************)
(* Cyclic groups. *)
(***********************************************************************)
Section Cyclic.
Variable gT : finGroupType.
Implicit Types (a x y : gT) (A B : {set gT}) (G K H : {group gT}).
Definition cyclic A := [exists x, A == <[x]>].
Lemma cyclicP A : reflect (exists x, A = <[x]>) (cyclic A).
Proof. exact: exists_eqP. Qed.
Lemma cycle_cyclic x : cyclic <[x]>.
Proof. by apply/cyclicP; exists x. Qed.
Lemma cyclic1 : cyclic [1 gT].
Proof. by rewrite -cycle1 cycle_cyclic. Qed.
(***********************************************************************)
(* Isomorphism with the additive group *)
(***********************************************************************)
Section Zpm.
Variable a : gT.
Definition Zpm (i : 'Z_#[a]) := a ^+ i.
Lemma ZpmM : {in Zp #[a] &, {morph Zpm : x y / x * y}}.
Proof.
rewrite /Zpm; case: (eqVneq a 1) => [-> | nta] i j _ _.
by rewrite !expg1n ?mulg1.
by rewrite /= {3}Zp_cast ?order_gt1 // expg_mod_order expgD.
Qed.
Canonical Zpm_morphism := Morphism ZpmM.
Lemma im_Zpm : Zpm @* Zp #[a] = <[a]>.
Proof.
apply/eqP; rewrite eq_sym eqEcard cycle_subG /= andbC morphimEdom.
rewrite (leq_trans (leq_imset_card _ _)) ?card_Zp //= /Zp order_gt1.
case: eqP => /= [a1 | _]; first by rewrite imset_set1 morph1 a1 set11.
by apply/imsetP; exists 1%R; rewrite ?expg1 ?inE.
Qed.
Lemma injm_Zpm : 'injm Zpm.
Proof.
apply/injmP/dinjectiveP/card_uniqP.
rewrite size_map -cardE card_Zp //= {7}/order -im_Zpm morphimEdom /=.
by apply: eq_card => x; apply/imageP/imsetP=> [] [i Zp_i ->]; exists i.
Qed.
Lemma eq_expg_mod_order m n : (a ^+ m == a ^+ n) = (m == n %[mod #[a]]).
Proof.
have [->|] := eqVneq a 1; first by rewrite order1 !modn1 !expg1n eqxx.
rewrite -order_gt1 => lt1a; have ZpT: Zp #[a] = setT by rewrite /Zp lt1a.
have: injective Zpm by move=> i j; apply (injmP injm_Zpm); rewrite /= ZpT inE.
move/inj_eq=> eqZ; symmetry; rewrite -(Zp_cast lt1a).
by rewrite -[_ == _](eqZ (inZp m) (inZp n)) /Zpm /= Zp_cast ?expg_mod_order.
Qed.
Lemma eq_expg_ord d (m n : 'I_d) :
d <= #[a]%g -> (a ^+ m == a ^+ n) = (m == n).
Proof.
by move=> d_leq; rewrite eq_expg_mod_order !modn_small// (leq_trans _ d_leq).
Qed.
Lemma expgD_Zp d (n m : 'Z_d) : (d > 0)%N ->
#[a]%g %| d -> a ^+ (n + m)%R = a ^+ n * a ^+ m.
Proof.
move=> d_gt0 xdvd; apply/eqP; rewrite -expgD eq_expg_mod_order/= modn_dvdm//.
by case: d d_gt0 {m n} xdvd => [|[|[]]]//= _; rewrite dvdn1 => /eqP->.
Qed.
Lemma Zp_isom : isom (Zp #[a]) <[a]> Zpm.
Proof. by apply/isomP; rewrite injm_Zpm im_Zpm. Qed.
Lemma Zp_isog : isog (Zp #[a]) <[a]>.
Proof. exact: isom_isog Zp_isom. Qed.
End Zpm.
(***********************************************************************)
(* Central and direct product of cycles *)
(***********************************************************************)
Lemma cyclic_abelian A : cyclic A -> abelian A.
Proof. by case/cyclicP=> a ->; apply: cycle_abelian. Qed.
Lemma cycleMsub a b :
commute a b -> coprime #[a] #[b] -> <[a]> \subset <[a * b]>.
Proof.
move=> cab co_ab; apply/subsetP=> _ /cycleP[k ->].
apply/cycleP; exists (chinese #[a] #[b] k 0); symmetry.
rewrite expgMn // -expg_mod_order chinese_modl // expg_mod_order.
by rewrite /chinese addn0 -mulnA mulnCA expgM expg_order expg1n mulg1.
Qed.
Lemma cycleM a b :
commute a b -> coprime #[a] #[b] -> <[a * b]> = <[a]> * <[b]>.
Proof.
move=> cab co_ab; apply/eqP; rewrite eqEsubset -(cent_joinEl (cents_cycle cab)).
rewrite join_subG {3}cab !cycleMsub // 1?coprime_sym //.
by rewrite -genM_join cycle_subG mem_gen // imset2_f ?cycle_id.
Qed.
Lemma cyclicM A B :
cyclic A -> cyclic B -> B \subset 'C(A) -> coprime #|A| #|B| ->
cyclic (A * B).
Proof.
move=> /cyclicP[a ->] /cyclicP[b ->]; rewrite cent_cycle cycle_subG => cab coab.
by rewrite -cycleM ?cycle_cyclic //; apply/esym/cent1P.
Qed.
Lemma cyclicY K H :
cyclic K -> cyclic H -> H \subset 'C(K) -> coprime #|K| #|H| ->
cyclic (K <*> H).
Proof. by move=> cycK cycH cKH coKH; rewrite cent_joinEr // cyclicM. Qed.
(***********************************************************************)
(* Order properties *)
(***********************************************************************)
Lemma order_dvdn a n : #[a] %| n = (a ^+ n == 1).
Proof. by rewrite (eq_expg_mod_order a n 0) mod0n. Qed.
Lemma order_inf a n : a ^+ n.+1 == 1 -> #[a] <= n.+1.
Proof. by rewrite -order_dvdn; apply: dvdn_leq. Qed.
Lemma order_dvdG G a : a \in G -> #[a] %| #|G|.
Proof. by move=> Ga; apply: cardSg; rewrite cycle_subG. Qed.
Lemma expg_cardG G a : a \in G -> a ^+ #|G| = 1.
Proof. by move=> Ga; apply/eqP; rewrite -order_dvdn order_dvdG. Qed.
Lemma expg_znat G x k : x \in G -> x ^+ (k%:R : 'Z_(#|G|))%R = x ^+ k.
Proof.
case: (eqsVneq G 1) => [-> /set1P-> | ntG Gx]; first by rewrite !expg1n.
apply/eqP; rewrite val_Zp_nat ?cardG_gt1 // eq_expg_mod_order.
by rewrite modn_dvdm ?order_dvdG.
Qed.
Lemma expg_zneg G x (k : 'Z_(#|G|)) : x \in G -> x ^+ (- k)%R = x ^- k.
Proof.
move=> Gx; apply/eqP; rewrite eq_sym eq_invg_mul -expgD.
by rewrite -(expg_znat _ Gx) natrD natr_Zp natr_negZp subrr.
Qed.
Lemma nt_gen_prime G x : prime #|G| -> x \in G^# -> G :=: <[x]>.
Proof.
move=> Gpr /setD1P[]; rewrite -cycle_subG -cycle_eq1 => ntX sXG.
apply/eqP; rewrite eqEsubset sXG andbT.
by apply: contraR ntX => /(prime_TIg Gpr); rewrite (setIidPr sXG) => ->.
Qed.
Lemma nt_prime_order p x : prime p -> x ^+ p = 1 -> x != 1 -> #[x] = p.
Proof.
move=> p_pr xp ntx; apply/prime_nt_dvdP; rewrite ?order_eq1 //.
by rewrite order_dvdn xp.
Qed.
Lemma orderXdvd a n : #[a ^+ n] %| #[a].
Proof. by apply: order_dvdG; apply: mem_cycle. Qed.
Lemma orderXgcd a n : #[a ^+ n] = #[a] %/ gcdn #[a] n.
Proof.
apply/eqP; rewrite eqn_dvd; apply/andP; split.
rewrite order_dvdn -expgM -muln_divCA_gcd //.
by rewrite expgM expg_order expg1n.
have [-> | n_gt0] := posnP n; first by rewrite gcdn0 divnn order_gt0 dvd1n.
rewrite -(dvdn_pmul2r n_gt0) divn_mulAC ?dvdn_gcdl // dvdn_lcm.
by rewrite order_dvdn mulnC expgM expg_order eqxx dvdn_mulr.
Qed.
Lemma orderXdiv a n : n %| #[a] -> #[a ^+ n] = #[a] %/ n.
Proof. by case/dvdnP=> q defq; rewrite orderXgcd {2}defq gcdnC gcdnMl. Qed.
Lemma orderXexp p m n x : #[x] = (p ^ n)%N -> #[x ^+ (p ^ m)] = (p ^ (n - m))%N.
Proof.
move=> ox; have [n_le_m | m_lt_n] := leqP n m.
rewrite -(subnKC n_le_m) subnDA subnn expnD expgM -ox.
by rewrite expg_order expg1n order1.
rewrite orderXdiv ox ?dvdn_exp2l ?expnB ?(ltnW m_lt_n) //.
by have:= order_gt0 x; rewrite ox expn_gt0 orbC -(ltn_predK m_lt_n).
Qed.
Lemma orderXpfactor p k n x :
#[x ^+ (p ^ k)] = n -> prime p -> p %| n -> #[x] = (p ^ k * n)%N.
Proof.
move=> oxp p_pr dv_p_n.
suffices pk_x: p ^ k %| #[x] by rewrite -oxp orderXdiv // mulnC divnK.
rewrite pfactor_dvdn // leqNgt; apply: contraL dv_p_n => lt_x_k.
rewrite -oxp -p'natE // -(subnKC (ltnW lt_x_k)) expnD expgM.
rewrite (pnat_dvd (orderXdvd _ _)) // -p_part // orderXdiv ?dvdn_part //.
by rewrite -{1}[#[x]](partnC p) // mulKn // part_pnat.
Qed.
Lemma orderXprime p n x :
#[x ^+ p] = n -> prime p -> p %| n -> #[x] = (p * n)%N.
Proof. exact: (@orderXpfactor p 1). Qed.
Lemma orderXpnat m n x : #[x ^+ m] = n -> \pi(n).-nat m -> #[x] = (m * n)%N.
Proof.
move=> oxm n_m; have [m_gt0 _] := andP n_m.
suffices m_x: m %| #[x] by rewrite -oxm orderXdiv // mulnC divnK.
apply/dvdn_partP=> // p; rewrite mem_primes => /and3P[p_pr _ p_m].
have n_p: p \in \pi(n) by apply: (pnatP _ _ n_m).
have p_oxm: p %| #[x ^+ (p ^ logn p m)].
apply: dvdn_trans (orderXdvd _ m`_p^'); rewrite -expgM -p_part ?partnC //.
by rewrite oxm; rewrite mem_primes in n_p; case/and3P: n_p.
by rewrite (orderXpfactor (erefl _) p_pr p_oxm) p_part // dvdn_mulr.
Qed.
Lemma orderM a b :
commute a b -> coprime #[a] #[b] -> #[a * b] = (#[a] * #[b])%N.
Proof. by move=> cab co_ab; rewrite -coprime_cardMg -?cycleM. Qed.
Definition expg_invn A k := (egcdn k #|A|).1.
Lemma expgK G k :
coprime #|G| k -> {in G, cancel (expgn^~ k) (expgn^~ (expg_invn G k))}.
Proof.
move=> coGk x /order_dvdG Gx; apply/eqP.
rewrite -expgM (eq_expg_mod_order _ _ 1) -(modn_dvdm 1 Gx).
by rewrite -(chinese_modl coGk 1 0) /chinese mul1n addn0 modn_dvdm.
Qed.
Lemma cyclic_dprod K H G :
K \x H = G -> cyclic K -> cyclic H -> cyclic G = coprime #|K| #|H| .
Proof.
case/dprodP=> _ defKH cKH tiKH cycK cycH; pose m := lcmn #|K| #|H|.
apply/idP/idP=> [/cyclicP[x defG] | coKH]; last by rewrite -defKH cyclicM.
rewrite /coprime -dvdn1 -(@dvdn_pmul2l m) ?lcmn_gt0 ?cardG_gt0 //.
rewrite muln_lcm_gcd muln1 -TI_cardMg // defKH defG order_dvdn.
have /mulsgP[y z Ky Hz ->]: x \in K * H by rewrite defKH defG cycle_id.
rewrite -[1]mulg1 expgMn; last exact/commute_sym/(centsP cKH).
apply/eqP; congr (_ * _); apply/eqP; rewrite -order_dvdn.
exact: dvdn_trans (order_dvdG Ky) (dvdn_lcml _ _).
exact: dvdn_trans (order_dvdG Hz) (dvdn_lcmr _ _).
Qed.
(***********************************************************************)
(* Generator *)
(***********************************************************************)
Definition generator (A : {set gT}) a := A == <[a]>.
Lemma generator_cycle a : generator <[a]> a.
Proof. exact: eqxx. Qed.
Lemma cycle_generator a x : generator <[a]> x -> x \in <[a]>.
Proof. by move/(<[a]> =P _)->; apply: cycle_id. Qed.
Lemma generator_order a b : generator <[a]> b -> #[a] = #[b].
Proof. by rewrite /order => /(<[a]> =P _)->. Qed.
End Cyclic.
Arguments cyclic {gT} A%_g.
Arguments generator {gT} A%_g a%_g.
Arguments expg_invn {gT} A%_g k%_N.
Arguments cyclicP {gT A}.
Prenex Implicits cyclic Zpm.
(* Euler's theorem *)
Theorem Euler_exp_totient a n : coprime a n -> a ^ totient n = 1 %[mod n].
Proof.
(case: n => [|[|n']] //; [by rewrite !modn1 | set n := n'.+2]) => co_a_n.
have{co_a_n} Ua: coprime n (inZp a : 'I_n) by rewrite coprime_sym coprime_modl.
have: FinRing.unit 'Z_n Ua ^+ totient n == 1.
by rewrite -card_units_Zp // -order_dvdn order_dvdG ?inE.
by rewrite -2!val_eqE unit_Zp_expg /= -/n modnXm => /eqP.
Qed.
Section Eltm.
Variables (aT rT : finGroupType) (x : aT) (y : rT).
Definition eltm of #[y] %| #[x] := fun x_i => y ^+ invm (injm_Zpm x) x_i.
Hypothesis dvd_y_x : #[y] %| #[x].
Lemma eltmE i : eltm dvd_y_x (x ^+ i) = y ^+ i.
Proof.
apply/eqP; rewrite eq_expg_mod_order.
have [x_le1 | x_gt1] := leqP #[x] 1.
suffices: #[y] %| 1 by rewrite dvdn1 => /eqP->; rewrite !modn1.
by rewrite (dvdn_trans dvd_y_x) // dvdn1 order_eq1 -cycle_eq1 trivg_card_le1.
rewrite -(expg_znat i (cycle_id x)) invmE /=; last by rewrite /Zp x_gt1 inE.
by rewrite val_Zp_nat // modn_dvdm.
Qed.
Lemma eltm_id : eltm dvd_y_x x = y. Proof. exact: (eltmE 1). Qed.
Lemma eltmM : {in <[x]> &, {morph eltm dvd_y_x : x_i x_j / x_i * x_j}}.
Proof.
move=> _ _ /cycleP[i ->] /cycleP[j ->].
by apply/eqP; rewrite -expgD !eltmE expgD.
Qed.
Canonical eltm_morphism := Morphism eltmM.
Lemma im_eltm : eltm dvd_y_x @* <[x]> = <[y]>.
Proof. by rewrite morphim_cycle ?cycle_id //= eltm_id. Qed.
Lemma ker_eltm : 'ker (eltm dvd_y_x) = <[x ^+ #[y]]>.
Proof.
apply/eqP; rewrite eq_sym eqEcard cycle_subG 3!inE mem_cycle /= eltmE.
rewrite expg_order eqxx (orderE y) -im_eltm card_morphim setIid -orderE.
by rewrite orderXdiv ?dvdn_indexg //= leq_divRL ?indexg_gt0 ?Lagrange ?subsetIl.
Qed.
Lemma injm_eltm : 'injm (eltm dvd_y_x) = (#[x] %| #[y]).
Proof. by rewrite ker_eltm subG1 cycle_eq1 -order_dvdn. Qed.
End Eltm.
Section CycleSubGroup.
Variable gT : finGroupType.
(* Gorenstein, 1.3.1 (i) *)
Lemma cycle_sub_group (a : gT) m :
m %| #[a] ->
[set H : {group gT} | H \subset <[a]> & #|H| == m]
= [set <[a ^+ (#[a] %/ m)]>%G].
Proof.
move=> m_dv_a; have m_gt0: 0 < m by apply: dvdn_gt0 m_dv_a.
have oam: #|<[a ^+ (#[a] %/ m)]>| = m.
apply/eqP; rewrite [#|_|]orderXgcd -(divnMr m_gt0) muln_gcdl divnK //.
by rewrite gcdnC gcdnMr mulKn.
apply/eqP; rewrite eqEsubset sub1set inE /= cycleX oam eqxx !andbT.
apply/subsetP=> X; rewrite in_set1 inE -val_eqE /= eqEcard oam.
case/andP=> sXa /eqP oX; rewrite oX leqnn andbT.
apply/subsetP=> x Xx; case/cycleP: (subsetP sXa _ Xx) => k def_x.
have: (x ^+ m == 1)%g by rewrite -oX -order_dvdn cardSg // gen_subG sub1set.
rewrite {x Xx}def_x -expgM -order_dvdn -[#[a]](Lagrange sXa) -oX mulnC.
rewrite dvdn_pmul2r // mulnK // => /dvdnP[i ->].
by rewrite mulnC expgM groupX // cycle_id.
Qed.
Lemma cycle_subgroup_char a (H : {group gT}) : H \subset <[a]> -> H \char <[a]>.
Proof.
move=> sHa; apply: lone_subgroup_char => // J sJa isoJH.
have dvHa: #|H| %| #[a] by apply: cardSg.
have{dvHa} /setP Huniq := esym (cycle_sub_group dvHa).
move: (Huniq H) (Huniq J); rewrite !inE /=.
by rewrite sHa sJa (card_isog isoJH) eqxx => /eqP<- /eqP<-.
Qed.
End CycleSubGroup.
(***********************************************************************)
(* Reflected boolean property and morphic image, injection, bijection *)
(***********************************************************************)
Section MorphicImage.
Variables aT rT : finGroupType.
Variables (D : {group aT}) (f : {morphism D >-> rT}) (x : aT).
Hypothesis Dx : x \in D.
Lemma morph_order : #[f x] %| #[x].
Proof. by rewrite order_dvdn -morphX // expg_order morph1. Qed.
Lemma morph_generator A : generator A x -> generator (f @* A) (f x).
Proof. by move/(A =P _)->; rewrite /generator morphim_cycle. Qed.
End MorphicImage.
Section CyclicProps.
Variables gT : finGroupType.
Implicit Types (aT rT : finGroupType) (G H K : {group gT}).
Lemma cyclicS G H : H \subset G -> cyclic G -> cyclic H.
Proof.
move=> sHG /cyclicP[x defG]; apply/cyclicP.
exists (x ^+ (#[x] %/ #|H|)); apply/congr_group/set1P.
by rewrite -cycle_sub_group /order -defG ?cardSg // inE sHG eqxx.
Qed.
Lemma cyclicJ G x : cyclic (G :^ x) = cyclic G.
Proof.
apply/cyclicP/cyclicP=> [[y /(canRL (conjsgK x))] | [y ->]].
by rewrite -cycleJ; exists (y ^ x^-1).
by exists (y ^ x); rewrite cycleJ.
Qed.
Lemma eq_subG_cyclic G H K :
cyclic G -> H \subset G -> K \subset G -> (H :==: K) = (#|H| == #|K|).
Proof.
case/cyclicP=> x -> sHx sKx; apply/eqP/eqP=> [-> //| eqHK].
have def_GHx := cycle_sub_group (cardSg sHx); set GHx := [set _] in def_GHx.
have []: H \in GHx /\ K \in GHx by rewrite -def_GHx !inE sHx sKx eqHK /=.
by do 2!move/set1P->.
Qed.
Lemma cardSg_cyclic G H K :
cyclic G -> H \subset G -> K \subset G -> (#|H| %| #|K|) = (H \subset K).
Proof.
move=> cycG sHG sKG; apply/idP/idP; last exact: cardSg.
case/cyclicP: (cyclicS sKG cycG) => x defK; rewrite {K}defK in sKG *.
case/dvdnP=> k ox; suffices ->: H :=: <[x ^+ k]> by apply: cycleX.
apply/eqP; rewrite (eq_subG_cyclic cycG) ?(subset_trans (cycleX _ _)) //.
rewrite -orderE orderXdiv orderE ox ?dvdn_mulr ?mulKn //.
by have:= order_gt0 x; rewrite orderE ox; case k.
Qed.
Lemma sub_cyclic_char G H : cyclic G -> (H \char G) = (H \subset G).
Proof.
case/cyclicP=> x ->; apply/idP/idP => [/andP[] //|].
exact: cycle_subgroup_char.
Qed.
Lemma morphim_cyclic rT G H (f : {morphism G >-> rT}) :
cyclic H -> cyclic (f @* H).
Proof.
move=> cycH; wlog sHG: H cycH / H \subset G.
by rewrite -morphimIdom; apply; rewrite (cyclicS _ cycH, subsetIl) ?subsetIr.
case/cyclicP: cycH sHG => x ->; rewrite gen_subG sub1set => Gx.
by apply/cyclicP; exists (f x); rewrite morphim_cycle.
Qed.
Lemma quotient_cycle x H : x \in 'N(H) -> <[x]> / H = <[coset H x]>.
Proof. exact: morphim_cycle. Qed.
Lemma quotient_cyclic G H : cyclic G -> cyclic (G / H).
Proof. exact: morphim_cyclic. Qed.
Lemma quotient_generator x G H :
x \in 'N(H) -> generator G x -> generator (G / H) (coset H x).
Proof. by move=> Nx; apply: morph_generator. Qed.
Lemma prime_cyclic G : prime #|G| -> cyclic G.
Proof.
case/primeP; rewrite ltnNge -trivg_card_le1.
case/trivgPn=> x Gx ntx /(_ _ (order_dvdG Gx)).
rewrite order_eq1 (negbTE ntx) => /eqnP oxG; apply/cyclicP.
by exists x; apply/eqP; rewrite eq_sym eqEcard -oxG cycle_subG Gx leqnn.
Qed.
Lemma dvdn_prime_cyclic G p : prime p -> #|G| %| p -> cyclic G.
Proof.
move=> p_pr pG; case: (eqsVneq G 1) => [-> | ntG]; first exact: cyclic1.
by rewrite prime_cyclic // (prime_nt_dvdP p_pr _ pG) -?trivg_card1.
Qed.
Lemma cyclic_small G : #|G| <= 3 -> cyclic G.
Proof.
rewrite 4!(ltnS, leq_eqVlt) -trivg_card_le1 orbA orbC.
case/predU1P=> [-> | oG]; first exact: cyclic1.
by apply: prime_cyclic; case/pred2P: oG => ->.
Qed.
End CyclicProps.
Section IsoCyclic.
Variables gT rT : finGroupType.
Implicit Types (G H : {group gT}) (M : {group rT}).
Lemma injm_cyclic G H (f : {morphism G >-> rT}) :
'injm f -> H \subset G -> cyclic (f @* H) = cyclic H.
Proof.
move=> injf sHG; apply/idP/idP; last exact: morphim_cyclic.
by rewrite -{2}(morphim_invm injf sHG); apply: morphim_cyclic.
Qed.
Lemma isog_cyclic G M : G \isog M -> cyclic G = cyclic M.
Proof. by case/isogP=> f injf <-; rewrite injm_cyclic. Qed.
Lemma isog_cyclic_card G M : cyclic G -> isog G M = cyclic M && (#|M| == #|G|).
Proof.
move=> cycG; apply/idP/idP=> [isoGM | ].
by rewrite (card_isog isoGM) -(isog_cyclic isoGM) cycG /=.
case/cyclicP: cycG => x ->{G} /andP[/cyclicP[y ->] /eqP oy].
by apply: isog_trans (isog_symr _) (Zp_isog y); rewrite /order oy Zp_isog.
Qed.
Lemma injm_generator G H (f : {morphism G >-> rT}) x :
'injm f -> x \in G -> H \subset G ->
generator (f @* H) (f x) = generator H x.
Proof.
move=> injf Gx sHG; apply/idP/idP; last exact: morph_generator.
rewrite -{2}(morphim_invm injf sHG) -{2}(invmE injf Gx).
by apply: morph_generator; apply: mem_morphim.
Qed.
End IsoCyclic.
(* Metacyclic groups. *)
Section Metacyclic.
Variable gT : finGroupType.
Implicit Types (A : {set gT}) (G H : {group gT}).
Definition metacyclic A :=
[exists H : {group gT}, [&& cyclic H, H <| A & cyclic (A / H)]].
Lemma metacyclicP A :
reflect (exists H : {group gT}, [/\ cyclic H, H <| A & cyclic (A / H)])
(metacyclic A).
Proof. exact: 'exists_and3P. Qed.
Lemma metacyclic1 : metacyclic 1.
Proof.
by apply/existsP; exists 1%G; rewrite normal1 trivg_quotient !cyclic1.
Qed.
Lemma cyclic_metacyclic A : cyclic A -> metacyclic A.
Proof.
case/cyclicP=> x ->; apply/existsP; exists (<[x]>)%G.
by rewrite normal_refl cycle_cyclic trivg_quotient cyclic1.
Qed.
Lemma metacyclicS G H : H \subset G -> metacyclic G -> metacyclic H.
Proof.
move=> sHG /metacyclicP[K [cycK nsKG cycGq]]; apply/metacyclicP.
exists (H :&: K)%G; rewrite (cyclicS (subsetIr H K)) ?(normalGI sHG) //=.
rewrite setIC (isog_cyclic (second_isog _)) ?(cyclicS _ cycGq) ?quotientS //.
by rewrite (subset_trans sHG) ?normal_norm.
Qed.
End Metacyclic.
Arguments metacyclic {gT} A%_g.
Arguments metacyclicP {gT A}.
(* Automorphisms of cyclic groups. *)
Section CyclicAutomorphism.
Variable gT : finGroupType.
Section CycleAutomorphism.
Variable a : gT.
Section CycleMorphism.
Variable n : nat.
Definition cyclem of gT := fun x : gT => x ^+ n.
Lemma cyclemM : {in <[a]> & , {morph cyclem a : x y / x * y}}.
Proof.
by move=> x y ax ay; apply: expgMn; apply: (centsP (cycle_abelian a)).
Qed.
Canonical cyclem_morphism := Morphism cyclemM.
End CycleMorphism.
Section ZpUnitMorphism.
Variable u : {unit 'Z_#[a]}.
Lemma injm_cyclem : 'injm (cyclem (val u) a).
Proof.
apply/subsetP=> x /setIdP[ax]; rewrite !inE -order_dvdn.
have [a1 | nta] := eqVneq a 1; first by rewrite a1 cycle1 inE in ax.
rewrite -order_eq1 -dvdn1; move/eqnP: (valP u) => /= <-.
by rewrite dvdn_gcd [in X in X && _]Zp_cast ?order_gt1 // order_dvdG.
Qed.
Lemma im_cyclem : cyclem (val u) a @* <[a]> = <[a]>.
Proof.
apply/morphim_fixP=> //; first exact: injm_cyclem.
by rewrite morphim_cycle ?cycle_id ?cycleX.
Qed.
Definition Zp_unitm := aut injm_cyclem im_cyclem.
End ZpUnitMorphism.
Lemma Zp_unitmM : {in units_Zp #[a] &, {morph Zp_unitm : u v / u * v}}.
Proof.
move=> u v _ _; apply: (eq_Aut (Aut_aut _ _)) => [|x a_x].
by rewrite groupM ?Aut_aut.
rewrite permM !autE ?groupX //= /cyclem -expgM.
rewrite -expg_mod_order modn_dvdm ?expg_mod_order //.
case: (leqP #[a] 1) => [lea1 | lt1a]; last by rewrite Zp_cast ?order_dvdG.
by rewrite card_le1_trivg // in a_x; rewrite (set1P a_x) order1 dvd1n.
Qed.
Canonical Zp_unit_morphism := Morphism Zp_unitmM.
Lemma injm_Zp_unitm : 'injm Zp_unitm.
Proof.
have [a1 | nta] := eqVneq a 1.
by rewrite subIset //= card_le1_trivg ?subxx // card_units_Zp a1 order1.
apply/subsetP=> /= u /morphpreP[_ /set1P/= um1].
have{um1}: Zp_unitm u a == Zp_unitm 1 a by rewrite um1 morph1.
rewrite !autE ?cycle_id // eq_expg_mod_order.
by rewrite -[n in _ == _ %[mod n]]Zp_cast ?order_gt1 // !modZp inE.
Qed.
Lemma generator_coprime m : generator <[a]> (a ^+ m) = coprime #[a] m.
Proof.
rewrite /generator eq_sym eqEcard cycleX -/#[a] [#|_|]orderXgcd /=.
apply/idP/idP=> [le_a_am|co_am]; last by rewrite (eqnP co_am) divn1.
have am_gt0: 0 < gcdn #[a] m by rewrite gcdn_gt0 order_gt0.
by rewrite /coprime eqn_leq am_gt0 andbT -(@leq_pmul2l #[a]) ?muln1 -?leq_divRL.
Qed.
Lemma im_Zp_unitm : Zp_unitm @* units_Zp #[a] = Aut <[a]>.
Proof.
rewrite morphimEdom; apply/setP=> f; pose n := invm (injm_Zpm a) (f a).
apply/imsetP/idP=> [[u _ ->] | Af]; first exact: Aut_aut.
have [a1 | nta] := eqVneq a 1.
by rewrite a1 cycle1 Aut1 in Af; exists 1; rewrite // morph1 (set1P Af).
have a_fa: <[a]> = <[f a]>.
by rewrite -(autmE Af) -morphim_cycle ?im_autm ?cycle_id.
have def_n: a ^+ n = f a.
by rewrite -/(Zpm n) invmK // im_Zpm a_fa cycle_id.
have co_a_n: coprime #[a].-2.+2 n.
by rewrite {1}Zp_cast ?order_gt1 // -generator_coprime def_n; apply/eqP.
exists (FinRing.unit 'Z_#[a] co_a_n); rewrite ?inE //.
apply: eq_Aut (Af) (Aut_aut _ _) _ => x ax.
rewrite autE //= /cyclem; case/cycleP: ax => k ->{x}.
by rewrite -(autmE Af) morphX ?cycle_id //= autmE -def_n -!expgM mulnC.
Qed.
Lemma Zp_unit_isom : isom (units_Zp #[a]) (Aut <[a]>) Zp_unitm.
Proof. by apply/isomP; rewrite ?injm_Zp_unitm ?im_Zp_unitm. Qed.
Lemma Zp_unit_isog : isog (units_Zp #[a]) (Aut <[a]>).
Proof. exact: isom_isog Zp_unit_isom. Qed.
Lemma card_Aut_cycle : #|Aut <[a]>| = totient #[a].
Proof. by rewrite -(card_isog Zp_unit_isog) card_units_Zp. Qed.
Lemma totient_gen : totient #[a] = #|[set x | generator <[a]> x]|.
Proof.
have [lea1 | lt1a] := leqP #[a] 1.
rewrite /order card_le1_trivg // cards1 (@eq_card1 _ 1) // => x.
by rewrite !inE -cycle_eq1 eq_sym.
rewrite -(card_injm (injm_invm (injm_Zpm a))) /= ?im_Zpm; last first.
by apply/subsetP=> x /[1!inE]; apply: cycle_generator.
rewrite -card_units_Zp // cardsE card_sub morphim_invmE; apply: eq_card => /= d.
by rewrite !inE /= qualifE /= /Zp lt1a inE /= generator_coprime {1}Zp_cast.
Qed.
Lemma Aut_cycle_abelian : abelian (Aut <[a]>).
Proof. by rewrite -im_Zp_unitm morphim_abelian ?units_Zp_abelian. Qed.
End CycleAutomorphism.
Variable G : {group gT}.
Lemma Aut_cyclic_abelian : cyclic G -> abelian (Aut G).
Proof. by case/cyclicP=> x ->; apply: Aut_cycle_abelian. Qed.
Lemma card_Aut_cyclic : cyclic G -> #|Aut G| = totient #|G|.
Proof. by case/cyclicP=> x ->; apply: card_Aut_cycle. Qed.
Lemma sum_ncycle_totient :
\sum_(d < #|G|.+1) #|[set <[x]> | x in G & #[x] == d]| * totient d = #|G|.
Proof.
pose h (x : gT) : 'I_#|G|.+1 := inord #[x].
symmetry; rewrite -{1}sum1_card (partition_big h xpredT) //=.
apply: eq_bigr => d _; set Gd := finset _.
rewrite -sum_nat_const sum1dep_card -sum1_card (_ : finset _ = Gd); last first.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by rewrite /eq_op /= inordK // ltnS subset_leq_card ?cycle_subG.
rewrite (partition_big_imset cycle) {}/Gd; apply: eq_bigr => C /=.
case/imsetP=> x /setIdP[Gx /eqP <-] -> {C d}.
rewrite sum1dep_card totient_gen; apply: eq_card => y; rewrite !inE /generator.
move: Gx; rewrite andbC eq_sym -!cycle_subG /order.
by case: eqP => // -> ->; rewrite eqxx.
Qed.
End CyclicAutomorphism.
Lemma sum_totient_dvd n : \sum_(d < n.+1 | d %| n) totient d = n.
Proof.
case: n => [|[|n']]; try by rewrite big_mkcond !big_ord_recl big_ord0.
set n := n'.+2; pose x1 : 'Z_n := 1%R.
have ox1: #[x1] = n by rewrite /order -Zp_cycle card_Zp.
rewrite -[rhs in _ = rhs]ox1 -[#[_]]sum_ncycle_totient [#|_|]ox1 big_mkcond /=.
apply: eq_bigr => d _; rewrite -{2}ox1; case: ifP => [|ndv_dG]; last first.
rewrite eq_card0 // => C; apply/imsetP=> [[x /setIdP[Gx oxd] _{C}]].
by rewrite -(eqP oxd) order_dvdG in ndv_dG.
move/cycle_sub_group; set Gd := [set _] => def_Gd.
rewrite (_ : _ @: _ = @gval _ @: Gd); first by rewrite imset_set1 cards1 mul1n.
apply/setP=> C; apply/idP/imsetP=> [| [gC GdC ->{C}]].
case/imsetP=> x /setIdP[_ oxd] ->; exists <[x]>%G => //.
by rewrite -def_Gd inE -Zp_cycle subsetT.
have:= GdC; rewrite -def_Gd => /setIdP[_ /eqP <-].
by rewrite (set1P GdC) /= imset_f // inE eqxx (mem_cycle x1).
Qed.
Section FieldMulCyclic.
(***********************************************************************)
(* A classic application to finite multiplicative subgroups of fields. *)
(***********************************************************************)
Import GRing.Theory.
Variables (gT : finGroupType) (G : {group gT}).
Lemma order_inj_cyclic :
{in G &, forall x y, #[x] = #[y] -> <[x]> = <[y]>} -> cyclic G.
Proof.
move=> ucG; apply: negbNE (contra _ (negbT (ltnn #|G|))) => ncG.
rewrite -{2}[#|G|]sum_totient_dvd big_mkcond (bigD1 ord_max) ?dvdnn //=.
rewrite -{1}[#|G|]sum_ncycle_totient (bigD1 ord_max) //= -addSn leq_add //.
rewrite eq_card0 ?totient_gt0 ?cardG_gt0 // => C.
apply/imsetP=> [[x /setIdP[Gx /eqP oxG]]]; case/cyclicP: ncG.
by exists x; apply/eqP; rewrite eq_sym eqEcard cycle_subG Gx -oxG /=.
elim/big_ind2: _ => // [m1 n1 m2 n2 | d _]; first exact: leq_add.
set Gd := _ @: _; case: (set_0Vmem Gd) => [-> | [C]]; first by rewrite cards0.
rewrite {}/Gd => /imsetP[x /setIdP[Gx /eqP <-] _ {C d}].
rewrite order_dvdG // (@eq_card1 _ <[x]>) ?mul1n // => C.
apply/idP/eqP=> [|-> {C}]; last by rewrite imset_f // inE Gx eqxx.
by case/imsetP=> y /setIdP[Gy /eqP/ucG->].
Qed.
Lemma div_ring_mul_group_cyclic (R : unitRingType) (f : gT -> R) :
f 1 = 1%R -> {in G &, {morph f : u v / u * v >-> (u * v)%R}} ->
{in G^#, forall x, f x - 1 \in GRing.unit}%R ->
abelian G -> cyclic G.
Proof.
move=> f1 fM f1P abelG.
have fX n: {in G, {morph f : u / u ^+ n >-> (u ^+ n)%R}}.
by case: n => // n x Gx; elim: n => //= n IHn; rewrite expgS fM ?groupX ?IHn.
have fU x: x \in G -> f x \in GRing.unit.
by move=> Gx; apply/unitrP; exists (f x^-1); rewrite -!fM ?groupV ?gsimp.
apply: order_inj_cyclic => x y Gx Gy; set n := #[x] => yn.
apply/eqP; rewrite eq_sym eqEcard -[#|_|]/n yn leqnn andbT cycle_subG /=.
suff{y Gy yn} ->: <[x]> = G :&: [set z | #[z] %| n] by rewrite !inE Gy yn /=.
apply/eqP; rewrite eqEcard subsetI cycle_subG {}Gx /= cardE; set rs := enum _.
apply/andP; split; first by apply/subsetP=> y xy; rewrite inE order_dvdG.
pose P : {poly R} := ('X^n - 1)%R; have n_gt0: n > 0 by apply: order_gt0.
have szP : size P = n.+1.
by rewrite size_polyDl size_polyXn ?size_polyN ?size_poly1.
rewrite -ltnS -szP -(size_map f) max_ring_poly_roots -?size_poly_eq0 ?{}szP //.
apply/allP=> fy /mapP[y]; rewrite mem_enum !inE order_dvdn => /andP[Gy].
move/eqP=> yn1 ->{fy}; apply/eqP.
by rewrite !(hornerE, hornerXn) -fX // yn1 f1 subrr.
have: uniq rs by apply: enum_uniq.
have: all [in G] rs by apply/allP=> y; rewrite mem_enum; case/setIP.
elim: rs => //= y rs IHrs /andP[Gy Grs] /andP[y_rs]; rewrite andbC.
move/IHrs=> -> {IHrs}//; apply/allP=> _ /mapP[z rs_z ->].
have{Grs} Gz := allP Grs z rs_z; rewrite /diff_roots -!fM // (centsP abelG) //.
rewrite eqxx -[f y]mul1r -(mulgKV y z) fM ?groupM ?groupV //=.
rewrite -mulNr -mulrDl unitrMl ?fU ?f1P // !inE.
by rewrite groupM ?groupV // andbT -eq_mulgV1; apply: contra y_rs; move/eqP <-.
Qed.
Lemma field_mul_group_cyclic (F : fieldType) (f : gT -> F) :
{in G &, {morph f : u v / u * v >-> (u * v)%R}} ->
{in G, forall x, f x = 1%R <-> x = 1} ->
cyclic G.
Proof.
move=> fM f1P; have f1 : f 1 = 1%R by apply/f1P.
apply: (div_ring_mul_group_cyclic f1 fM) => [x|].
case/setD1P=> x1 Gx; rewrite unitfE; apply: contra x1.
by rewrite subr_eq0 => /eqP/f1P->.
apply/centsP=> x Gx y Gy; apply/commgP/eqP.
apply/f1P; rewrite ?fM ?groupM ?groupV //.
by rewrite mulrCA -!fM ?groupM ?groupV // mulKg mulVg.
Qed.
End FieldMulCyclic.
Lemma field_unit_group_cyclic (F : finFieldType) (G : {group {unit F}}) :
cyclic G.
Proof.
apply: field_mul_group_cyclic FinRing.uval _ _ => // u _.
by split=> /eqP ?; apply/eqP.
Qed.
Lemma units_Zp_cyclic p : prime p -> cyclic (units_Zp p).
Proof. by move/pdiv_id <-; exact: field_unit_group_cyclic. Qed.
Section PrimitiveRoots.
Open Scope ring_scope.
Import GRing.Theory.
(* This subproof has been extracted out of [has_prim_root] for performance reasons.
See github PR #1059 for further documentation and investigation on this problem. *)
Lemma has_prim_root_subproof (F : fieldType) (n : nat) (rs : seq F)
(n_gt0 : n > 0)
(rsn1 : all n.-unity_root rs)
(Urs : uniq rs)
(sz_rs : size rs = n)
(r := fun s => val (s : seq_sub rs))
(rn1 : forall x : seq_sub rs, r x ^+ n = 1)
(prim_r : forall z : F, z ^+ n = 1 -> z \in rs)
(r' := (fun s (e : s ^+ n = 1) => {| ssval := s; ssvalP := prim_r s e |})
: forall s : F, s ^+ n = 1 -> seq_sub rs)
(sG_1 := r' 1 (expr1n F n) : seq_sub rs)
(sG_VP : forall s : seq_sub rs, r s ^+ n.-1 ^+ n = 1)
(sG_MP : forall s s0 : seq_sub rs, (r s * r s0) ^+ n = 1)
(sG_V := (fun s : seq_sub rs => r' (r s ^+ n.-1) (sG_VP s))
: seq_sub rs -> seq_sub rs)
(sG_M := (fun s s0 : seq_sub rs => r' (r s * r s0) (sG_MP s s0))
: seq_sub rs -> seq_sub rs -> seq_sub rs)
(sG_Ag : associative sG_M)
(sG_1g : left_id sG_1 sG_M)
(sG_Vg : left_inverse sG_1 sG_V sG_M) :
has n.-primitive_root rs.
Proof.
pose ssMG : isMulGroup (seq_sub rs) := isMulGroup.Build (seq_sub rs) sG_Ag sG_1g sG_Vg.
pose gT : finGroupType := HB.pack (seq_sub rs) ssMG.
have /cyclicP[x gen_x]: @cyclic gT setT.
apply: (@field_mul_group_cyclic gT [set: _] F r) => // x _.
by split=> [ri1 | ->]; first apply: val_inj.
apply/hasP; exists (r x); first exact: (valP x).
have [m prim_x dvdmn] := prim_order_exists n_gt0 (rn1 x).
rewrite -((m =P n) _) // eqn_dvd {}dvdmn -sz_rs -(card_seq_sub Urs) -cardsT.
rewrite gen_x (@order_dvdn gT) /(_ == _) /= -{prim_x}(prim_expr_order prim_x).
by apply/eqP; elim: m => //= m IHm; rewrite exprS expgS /= -IHm.
Qed.
Lemma has_prim_root (F : fieldType) (n : nat) (rs : seq F) :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs >= n ->
has n.-primitive_root rs.
Proof.
move=> n_gt0 rsn1 Urs; rewrite leq_eqVlt ltnNge max_unity_roots // orbF eq_sym.
move/eqP=> sz_rs; pose r := val (_ : seq_sub rs).
have rn1 x: r x ^+ n = 1.
by apply/eqP; rewrite -unity_rootE (allP rsn1) ?(valP x).
have prim_r z: z ^+ n = 1 -> z \in rs.
by move/eqP; rewrite -unity_rootE -(mem_unity_roots n_gt0).
pose r' := SeqSub (prim_r _ _); pose sG_1 := r' _ (expr1n _ _).
have sG_VP: r _ ^+ n.-1 ^+ n = 1.
by move=> x; rewrite -exprM mulnC exprM rn1 expr1n.
have sG_MP: (r _ * r _) ^+ n = 1 by move=> x y; rewrite exprMn !rn1 mul1r.
pose sG_V := r' _ (sG_VP _); pose sG_M := r' _ (sG_MP _ _).
have sG_Ag: associative sG_M by move=> x y z; apply: val_inj; rewrite /= mulrA.
have sG_1g: left_id sG_1 sG_M by move=> x; apply: val_inj; rewrite /= mul1r.
have sG_Vg: left_inverse sG_1 sG_V sG_M.
by move=> x; apply: val_inj; rewrite /= -exprSr prednK ?rn1.
exact: has_prim_root_subproof.
Qed.
End PrimitiveRoots.
(***********************************************************************)
(* Cycles of prime order *)
(***********************************************************************)
Section AutPrime.
Variable gT : finGroupType.
Lemma Aut_prime_cycle_cyclic (a : gT) : prime #[a] -> cyclic (Aut <[a]>).
Proof.
move=> pr_a; have inj_um := injm_Zp_unitm a.
have /eq_S/eq_S eq_a := Fp_Zcast pr_a.
pose fm := cast_ord (esym eq_a) \o val \o invm inj_um.
apply: (@field_mul_group_cyclic _ _ _ fm) => [f g Af Ag | f Af] /=.
by apply: val_inj; rewrite /= morphM ?im_Zp_unitm //= eq_a.
split=> [/= fm1 |->]; last by apply: val_inj; rewrite /= morph1.
apply: (injm1 (injm_invm inj_um)); first by rewrite /= im_Zp_unitm.
by do 2!apply: val_inj; move/(congr1 val): fm1.
Qed.
Lemma Aut_prime_cyclic (G : {group gT}) : prime #|G| -> cyclic (Aut G).
Proof.
move=> pr_G; case/cyclicP: (prime_cyclic pr_G) (pr_G) => x ->.
exact: Aut_prime_cycle_cyclic.
Qed.
End AutPrime.
|
Comparison.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.Sites.Coherent.Basic
import Mathlib.CategoryTheory.EffectiveEpi.Comp
import Mathlib.CategoryTheory.EffectiveEpi.Extensive
/-!
# Connections between the regular, extensive and coherent topologies
This file compares the regular, extensive and coherent topologies.
## Main results
* `instance : Precoherent C` given `Preregular C` and `FinitaryPreExtensive C`.
* `extensive_union_regular_generates_coherent`: the union of the regular and extensive coverages
generates the coherent topology on `C` if `C` is precoherent, preextensive and preregular.
-/
namespace CategoryTheory
open Limits GrothendieckTopology Sieve
variable (C : Type*) [Category C]
instance [Precoherent C] [HasFiniteCoproducts C] : Preregular C where
exists_fac {X Y Z} f g _ := by
have hp := Precoherent.pullback f PUnit (fun () β¦ Z) (fun () β¦ g)
simp only [exists_const] at hp
rw [β effectiveEpi_iff_effectiveEpiFamily g] at hp
obtain β¨Ξ², _, Xβ, Οβ, h, ΞΉ, hΞΉβ© := hp inferInstance
refine β¨β Xβ, Sigma.desc Οβ, inferInstance, Sigma.desc ΞΉ, ?_β©
ext b
simpa using hΞΉ b
instance [FinitaryPreExtensive C] [Preregular C] : Precoherent C where
pullback {Bβ Bβ} f Ξ± _ Xβ Οβ h := by
refine β¨Ξ±, inferInstance, ?_β©
obtain β¨Y, g, _, g', hgβ© := Preregular.exists_fac f (Sigma.desc Οβ)
let Xβ := fun a β¦ pullback g' (Sigma.ΞΉ Xβ a)
let Οβ := fun a β¦ pullback.fst g' (Sigma.ΞΉ Xβ a) β« g
let Ο' := fun a β¦ pullback.fst g' (Sigma.ΞΉ Xβ a)
have _ := FinitaryPreExtensive.isIso_sigmaDesc_fst (fun a β¦ Sigma.ΞΉ Xβ a) g' inferInstance
refine β¨Xβ, Οβ, ?_, ?_β©
Β· have : (Sigma.desc Ο' β« g) = Sigma.desc Οβ := by ext; simp [Οβ, Ο']
rw [β effectiveEpi_desc_iff_effectiveEpiFamily, β this]
infer_instance
Β· refine β¨id, fun b β¦ pullback.snd _ _, fun b β¦ ?_β©
simp only [Xβ, Οβ, id_eq, Category.assoc, β hg]
rw [β Category.assoc, pullback.condition]
simp
/-- The union of the extensive and regular coverages generates the coherent topology on `C`. -/
theorem extensive_regular_generate_coherent [Preregular C] [FinitaryPreExtensive C] :
((extensiveCoverage C) β (regularCoverage C)).toGrothendieck =
(coherentTopology C) := by
ext B S
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· induction h with
| of Y T hT =>
apply Coverage.Saturate.of
simp only [Coverage.sup_covering, Set.mem_union] at hT
exact Or.elim hT
(fun β¨Ξ±, x, X, Ο, β¨h, _β©β© β¦ β¨Ξ±, x, X, Ο, β¨h, inferInstanceβ©β©)
(fun β¨Z, f, β¨h, _β©β© β¦ β¨Unit, inferInstance, fun _ β¦ Z, fun _ β¦ f, β¨h, inferInstanceβ©β©)
| top => apply Coverage.Saturate.top
| transitive Y T => apply Coverage.Saturate.transitive Y T<;> [assumption; assumption]
Β· induction h with
| of Y T hT =>
obtain β¨I, _, X, f, rfl, hTβ© := hT
apply Coverage.Saturate.transitive Y (generate (Presieve.ofArrows
(fun (_ : Unit) β¦ (β fun (i : I) => X i)) (fun (_ : Unit) β¦ Sigma.desc f)))
Β· apply Coverage.Saturate.of
simp only [Coverage.sup_covering, extensiveCoverage, regularCoverage, Set.mem_union,
Set.mem_setOf_eq]
exact Or.inr β¨_, Sigma.desc f, β¨rfl, inferInstanceβ©β©
Β· rintro R g β¨W, Ο, Ο, β¨β©, rflβ©
change _ β ((extensiveCoverage C) β (regularCoverage C)).toGrothendieck _ R
rw [Sieve.pullback_comp]
apply pullback_stable
have : generate (Presieve.ofArrows X fun (i : I) β¦ Sigma.ΞΉ X i) β€
(generate (Presieve.ofArrows X f)).pullback (Sigma.desc f) := by
rintro Q q β¨E, e, r, β¨hq, rflβ©β©
exact β¨E, e, r β« (Sigma.desc f), by cases hq; simpa using Presieve.ofArrows.mk _, by simpβ©
apply Coverage.saturate_of_superset _ this
apply Coverage.Saturate.of
refine Or.inl β¨I, inferInstance, _, _, β¨rfl, ?_β©β©
convert IsIso.id _
aesop
| top => apply Coverage.Saturate.top
| transitive Y T => apply Coverage.Saturate.transitive Y T<;> [assumption; assumption]
end CategoryTheory
|
Vandermonde.lean
|
/-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Polynomial.Coeff
import Mathlib.Data.Nat.Choose.Basic
/-!
# Vandermonde's identity
In this file we prove Vandermonde's identity (`Nat.add_choose_eq`):
`(m + n).choose k = β (i, j) β antidiagonal k, m.choose i * n.choose j`
We follow the algebraic proof from
https://en.wikipedia.org/wiki/Vandermonde%27s_identity#Algebraic_proof .
-/
open Polynomial Finset Finset.Nat
/-- Vandermonde's identity -/
theorem Nat.add_choose_eq (m n k : β) :
(m + n).choose k = β ij β antidiagonal k, m.choose ij.1 * n.choose ij.2 := by
calc
(m + n).choose k = ((X + 1) ^ (m + n)).coeff k := by rw [coeff_X_add_one_pow, Nat.cast_id]
_ = ((X + 1) ^ m * (X + 1) ^ n).coeff k := by rw [pow_add]
_ = β ij β antidiagonal k, m.choose ij.1 * n.choose ij.2 := by
rw [coeff_mul, Finset.sum_congr rfl]
simp only [coeff_X_add_one_pow, Nat.cast_id, imp_true_iff]
|
PeakFunction.lean
|
/-
Copyright (c) 2023 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Integral.IntegralEqImproper
/-!
# Integrals against peak functions
A sequence of peak functions is a sequence of functions with average one concentrating around
a point `xβ`. Given such a sequence `Οβ`, then `β« Οβ g` tends to `g xβ` in many situations, with
a whole zoo of possible assumptions on `Οβ` and `g`. This file is devoted to such results. Such
functions are also called approximations of unity, or approximations of identity.
## Main results
* `tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto`: If a sequence of peak
functions `Οα΅’` converges uniformly to zero away from a point `xβ`, and
`g` is integrable and continuous at `xβ`, then `β« Οα΅’ β’ g` converges to `g xβ`.
* `tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`:
If a continuous function `c` realizes its maximum at a unique point `xβ` in a compact set `s`,
then the sequence of functions `(c x) ^ n / β« (c x) ^ n` is a sequence of peak functions
concentrating around `xβ`. Therefore, `β« (c x) ^ n * g / β« (c x) ^ n` converges to `g xβ`
if `g` is continuous on `s`.
* `tendsto_integral_comp_smul_smul_of_integrable`:
If a nonnegative function `Ο` has integral one and decays quickly enough at infinity,
then its renormalizations `x β¦ c ^ d * Ο (c β’ x)` form a sequence of peak functions as `c β β`.
Therefore, `β« (c ^ d * Ο (c β’ x)) β’ g x` converges to `g 0` as `c β β` if `g` is continuous
at `0` and integrable.
Note that there are related results about convolution with respect to peak functions in the file
`Mathlib/Analysis/Convolution.lean`, such as `MeasureTheory.convolution_tendsto_right` there.
-/
open Set Filter MeasureTheory MeasureTheory.Measure TopologicalSpace Metric
open scoped Topology ENNReal
/-!
### General convergent result for integrals against a sequence of peak functions
-/
open Set
variable {Ξ± E ΞΉ : Type*} {hm : MeasurableSpace Ξ±} {ΞΌ : Measure Ξ±} [TopologicalSpace Ξ±]
[BorelSpace Ξ±] [NormedAddCommGroup E] [NormedSpace β E] {g : Ξ± β E} {l : Filter ΞΉ} {xβ : Ξ±}
{s t : Set Ξ±} {Ο : ΞΉ β Ξ± β β} {a : E}
/-- If a sequence of peak functions `Οα΅’` converges uniformly to zero away from a point `xβ`, and
`g` is integrable and has a limit at `xβ`, then `Οα΅’ β’ g` is eventually integrable. -/
theorem integrableOn_peak_smul_of_integrableOn_of_tendsto
(hs : MeasurableSet s) (h'st : t β π[s] xβ)
(hlΟ : β u : Set Ξ±, IsOpen u β xβ β u β TendstoUniformlyOn Ο 0 l (s \ u))
(hiΟ : Tendsto (fun i β¦ β« x in t, Ο i x βΞΌ) l (π 1))
(h'iΟ : βαΆ i in l, AEStronglyMeasurable (Ο i) (ΞΌ.restrict s))
(hmg : IntegrableOn g s ΞΌ) (hcg : Tendsto g (π[s] xβ) (π a)) :
βαΆ i in l, IntegrableOn (fun x => Ο i x β’ g x) s ΞΌ := by
obtain β¨u, u_open, xβu, ut, huβ© :
β u, IsOpen u β§ xβ β u β§ s β© u β t β§ β x β u β© s, g x β ball a 1 := by
rcases mem_nhdsWithin.1 (Filter.inter_mem h'st (hcg (ball_mem_nhds _ zero_lt_one)))
with β¨u, u_open, xβu, huβ©
refine β¨u, u_open, xβu, ?_, hu.trans inter_subset_rightβ©
rw [inter_comm]
exact hu.trans inter_subset_left
rw [tendsto_iff_norm_sub_tendsto_zero] at hiΟ
filter_upwards [tendstoUniformlyOn_iff.1 (hlΟ u u_open xβu) 1 zero_lt_one,
(tendsto_order.1 hiΟ).2 1 zero_lt_one, h'iΟ] with i hi h'i h''i
have I : IntegrableOn (Ο i) t ΞΌ := .of_integral_ne_zero (fun h β¦ by simp [h] at h'i)
have A : IntegrableOn (fun x => Ο i x β’ g x) (s \ u) ΞΌ := by
refine Integrable.smul_of_top_right (hmg.mono diff_subset le_rfl) ?_
apply memLp_top_of_bound (h''i.mono_set diff_subset) 1
filter_upwards [self_mem_ae_restrict (hs.diff u_open.measurableSet)] with x hx
simpa only [Pi.zero_apply, dist_zero_left] using (hi x hx).le
have B : IntegrableOn (fun x => Ο i x β’ g x) (s β© u) ΞΌ := by
apply Integrable.smul_of_top_left
Β· exact IntegrableOn.mono_set I ut
Β· apply
memLp_top_of_bound (hmg.mono_set inter_subset_left).aestronglyMeasurable (βaβ + 1)
filter_upwards [self_mem_ae_restrict (hs.inter u_open.measurableSet)] with x hx
rw [inter_comm] at hx
exact (norm_lt_of_mem_ball (hu x hx)).le
convert A.union B
simp only [diff_union_inter]
/-- If a sequence of peak functions `Οα΅’` converges uniformly to zero away from a point `xβ` and its
integral on some finite-measure neighborhood of `xβ` converges to `1`, and `g` is integrable and
has a limit `a` at `xβ`, then `β« Οα΅’ β’ g` converges to `a`.
Auxiliary lemma where one assumes additionally `a = 0`. -/
theorem tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto_aux
(hs : MeasurableSet s) (ht : MeasurableSet t) (hts : t β s) (h'ts : t β π[s] xβ)
(hnΟ : βαΆ i in l, β x β s, 0 β€ Ο i x)
(hlΟ : β u : Set Ξ±, IsOpen u β xβ β u β TendstoUniformlyOn Ο 0 l (s \ u))
(hiΟ : Tendsto (fun i β¦ β« x in t, Ο i x βΞΌ) l (π 1))
(h'iΟ : βαΆ i in l, AEStronglyMeasurable (Ο i) (ΞΌ.restrict s))
(hmg : IntegrableOn g s ΞΌ) (hcg : Tendsto g (π[s] xβ) (π 0)) :
Tendsto (fun i : ΞΉ => β« x in s, Ο i x β’ g x βΞΌ) l (π 0) := by
refine Metric.tendsto_nhds.2 fun Ξ΅ Ξ΅pos => ?_
obtain β¨Ξ΄, hΞ΄, Ξ΄pos, Ξ΄oneβ© : β Ξ΄, (Ξ΄ * β« x in s, βg xβ βΞΌ) + 2 * Ξ΄ < Ξ΅ β§ 0 < Ξ΄ β§ Ξ΄ < 1 := by
have A :
Tendsto (fun Ξ΄ => (Ξ΄ * β« x in s, βg xβ βΞΌ) + 2 * Ξ΄) (π[>] 0)
(π ((0 * β« x in s, βg xβ βΞΌ) + 2 * 0)) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact (tendsto_id.mul tendsto_const_nhds).add (tendsto_id.const_mul _)
rw [zero_mul, zero_add, mul_zero] at A
have : Ioo (0 : β) 1 β π[>] 0 := Ioo_mem_nhdsGT zero_lt_one
rcases (((tendsto_order.1 A).2 Ξ΅ Ξ΅pos).and this).exists with β¨Ξ΄, hΞ΄, h'Ξ΄β©
exact β¨Ξ΄, hΞ΄, h'Ξ΄.1, h'Ξ΄.2β©
suffices βαΆ i in l, ββ« x in s, Ο i x β’ g x βΞΌβ β€ (Ξ΄ * β« x in s, βg xβ βΞΌ) + 2 * Ξ΄ by
filter_upwards [this] with i hi
simp only [dist_zero_right]
exact hi.trans_lt hΞ΄
obtain β¨u, u_open, xβu, ut, huβ© :
β u, IsOpen u β§ xβ β u β§ s β© u β t β§ β x β u β© s, g x β ball 0 Ξ΄ := by
rcases mem_nhdsWithin.1 (Filter.inter_mem h'ts (hcg (ball_mem_nhds _ Ξ΄pos)))
with β¨u, u_open, xβu, huβ©
refine β¨u, u_open, xβu, ?_, hu.trans inter_subset_rightβ©
rw [inter_comm]
exact hu.trans inter_subset_left
filter_upwards [tendstoUniformlyOn_iff.1 (hlΟ u u_open xβu) Ξ΄ Ξ΄pos,
(tendsto_order.1 (tendsto_iff_norm_sub_tendsto_zero.1 hiΟ)).2 Ξ΄ Ξ΄pos, hnΟ,
integrableOn_peak_smul_of_integrableOn_of_tendsto hs h'ts hlΟ hiΟ h'iΟ hmg hcg]
with i hi h'i hΟpos h''i
have I : IntegrableOn (Ο i) t ΞΌ := by
apply Integrable.of_integral_ne_zero (fun h β¦ ?_)
simp [h] at h'i
linarith
have B : ββ« x in s β© u, Ο i x β’ g x βΞΌβ β€ 2 * Ξ΄ :=
calc
ββ« x in s β© u, Ο i x β’ g x βΞΌβ β€ β« x in s β© u, βΟ i x β’ g xβ βΞΌ :=
norm_integral_le_integral_norm _
_ β€ β« x in s β© u, βΟ i xβ * Ξ΄ βΞΌ := by
refine setIntegral_mono_on ?_ ?_ (hs.inter u_open.measurableSet) fun x hx => ?_
Β· exact IntegrableOn.mono_set h''i.norm inter_subset_left
Β· exact IntegrableOn.mono_set (I.norm.mul_const _) ut
rw [norm_smul]
gcongr
rw [inter_comm] at hu
exact (mem_ball_zero_iff.1 (hu x hx)).le
_ β€ β« x in t, βΟ i xβ * Ξ΄ βΞΌ := by
apply setIntegral_mono_set
Β· exact I.norm.mul_const _
Β· exact Eventually.of_forall fun x => mul_nonneg (norm_nonneg _) Ξ΄pos.le
Β· exact Eventually.of_forall ut
_ = β« x in t, Ο i x * Ξ΄ βΞΌ := by
apply setIntegral_congr_fun ht fun x hx => ?_
rw [Real.norm_of_nonneg (hΟpos _ (hts hx))]
_ = (β« x in t, Ο i x βΞΌ) * Ξ΄ := by rw [integral_mul_const]
_ β€ 2 * Ξ΄ := by gcongr; linarith [(le_abs_self _).trans h'i.le]
have C : ββ« x in s \ u, Ο i x β’ g x βΞΌβ β€ Ξ΄ * β« x in s, βg xβ βΞΌ :=
calc
ββ« x in s \ u, Ο i x β’ g x βΞΌβ β€ β« x in s \ u, βΟ i x β’ g xβ βΞΌ :=
norm_integral_le_integral_norm _
_ β€ β« x in s \ u, Ξ΄ * βg xβ βΞΌ := by
refine setIntegral_mono_on ?_ ?_ (hs.diff u_open.measurableSet) fun x hx => ?_
Β· exact IntegrableOn.mono_set h''i.norm diff_subset
Β· exact IntegrableOn.mono_set (hmg.norm.const_mul _) diff_subset
rw [norm_smul]
gcongr
simpa only [Pi.zero_apply, dist_zero_left] using (hi x hx).le
_ β€ Ξ΄ * β« x in s, βg xβ βΞΌ := by
rw [integral_const_mul]
apply mul_le_mul_of_nonneg_left (setIntegral_mono_set hmg.norm _ _) Ξ΄pos.le
Β· filter_upwards with x using norm_nonneg _
Β· filter_upwards using diff_subset (s := s) (t := u)
calc
ββ« x in s, Ο i x β’ g x βΞΌβ =
β(β« x in s \ u, Ο i x β’ g x βΞΌ) + β« x in s β© u, Ο i x β’ g x βΞΌβ := by
conv_lhs => rw [β diff_union_inter s u]
rw [setIntegral_union disjoint_sdiff_inter (hs.inter u_open.measurableSet)
(h''i.mono_set diff_subset) (h''i.mono_set inter_subset_left)]
_ β€ ββ« x in s \ u, Ο i x β’ g x βΞΌβ + ββ« x in s β© u, Ο i x β’ g x βΞΌβ := norm_add_le _ _
_ β€ (Ξ΄ * β« x in s, βg xβ βΞΌ) + 2 * Ξ΄ := add_le_add C B
variable [CompleteSpace E]
/-- If a sequence of peak functions `Οα΅’` converges uniformly to zero away from a point `xβ` and its
integral on some finite-measure neighborhood of `xβ` converges to `1`, and `g` is integrable and
has a limit `a` at `xβ`, then `β« Οα΅’ β’ g` converges to `a`. Version localized to a subset. -/
theorem tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto
(hs : MeasurableSet s) {t : Set Ξ±} (ht : MeasurableSet t) (hts : t β s) (h'ts : t β π[s] xβ)
(h't : ΞΌ t β β) (hnΟ : βαΆ i in l, β x β s, 0 β€ Ο i x)
(hlΟ : β u : Set Ξ±, IsOpen u β xβ β u β TendstoUniformlyOn Ο 0 l (s \ u))
(hiΟ : Tendsto (fun i β¦ β« x in t, Ο i x βΞΌ) l (π 1))
(h'iΟ : βαΆ i in l, AEStronglyMeasurable (Ο i) (ΞΌ.restrict s))
(hmg : IntegrableOn g s ΞΌ) (hcg : Tendsto g (π[s] xβ) (π a)) :
Tendsto (fun i : ΞΉ β¦ β« x in s, Ο i x β’ g x βΞΌ) l (π a) := by
let h := g - t.indicator (fun _ β¦ a)
have A : Tendsto (fun i : ΞΉ => (β« x in s, Ο i x β’ h x βΞΌ) + (β« x in t, Ο i x βΞΌ) β’ a) l
(π (0 + (1 : β) β’ a)) := by
refine Tendsto.add ?_ (Tendsto.smul hiΟ tendsto_const_nhds)
apply tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto_aux hs ht hts h'ts
hnΟ hlΟ hiΟ h'iΟ
Β· apply hmg.sub
simp only [integrable_indicator_iff ht, integrableOn_const_iff (C := a), ht,
Measure.restrict_apply]
right
exact lt_of_le_of_lt (measure_mono inter_subset_left) (h't.lt_top)
Β· rw [β sub_self a]
apply Tendsto.sub hcg
apply tendsto_const_nhds.congr'
filter_upwards [h'ts] with x hx using by simp [hx]
simp only [one_smul, zero_add] at A
refine Tendsto.congr' ?_ A
filter_upwards [integrableOn_peak_smul_of_integrableOn_of_tendsto hs h'ts
hlΟ hiΟ h'iΟ hmg hcg,
(tendsto_order.1 (tendsto_iff_norm_sub_tendsto_zero.1 hiΟ)).2 1 zero_lt_one] with i hi h'i
simp only [h, Pi.sub_apply, smul_sub, β indicator_smul_apply]
rw [integral_sub hi, setIntegral_indicator ht, inter_eq_right.mpr hts,
integral_smul_const, sub_add_cancel]
rw [integrable_indicator_iff ht]
apply Integrable.smul_const
rw [restrict_restrict ht, inter_eq_left.mpr hts]
exact .of_integral_ne_zero (fun h β¦ by simp [h] at h'i)
/-- If a sequence of peak functions `Οα΅’` converges uniformly to zero away from a point `xβ` and its
integral on some finite-measure neighborhood of `xβ` converges to `1`, and `g` is integrable and
has a limit `a` at `xβ`, then `β« Οα΅’ β’ g` converges to `a`. -/
theorem tendsto_integral_peak_smul_of_integrable_of_tendsto
{t : Set Ξ±} (ht : MeasurableSet t) (h'ts : t β π xβ)
(h't : ΞΌ t β β) (hnΟ : βαΆ i in l, β x, 0 β€ Ο i x)
(hlΟ : β u : Set Ξ±, IsOpen u β xβ β u β TendstoUniformlyOn Ο 0 l uαΆ)
(hiΟ : Tendsto (fun i β¦ β« x in t, Ο i x βΞΌ) l (π 1))
(h'iΟ : βαΆ i in l, AEStronglyMeasurable (Ο i) ΞΌ)
(hmg : Integrable g ΞΌ) (hcg : Tendsto g (π xβ) (π a)) :
Tendsto (fun i : ΞΉ β¦ β« x, Ο i x β’ g x βΞΌ) l (π a) := by
suffices Tendsto (fun i : ΞΉ β¦ β« x in univ, Ο i x β’ g x βΞΌ) l (π a) by simpa
exact tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto MeasurableSet.univ ht (xβ := xβ)
(subset_univ _) (by simpa [nhdsWithin_univ]) h't (by simpa)
(by simpa [β compl_eq_univ_diff] using hlΟ) hiΟ
(by simpa) (by simpa) (by simpa [nhdsWithin_univ])
/-!
### Peak functions of the form `x β¦ (c x) ^ n / β« (c y) ^ n`
-/
/-- If a continuous function `c` realizes its maximum at a unique point `xβ` in a compact set `s`,
then the sequence of functions `(c x) ^ n / β« (c x) ^ n` is a sequence of peak functions
concentrating around `xβ`. Therefore, `β« (c x) ^ n * g / β« (c x) ^ n` converges to `g xβ` if `g` is
integrable on `s` and continuous at `xβ`.
Version assuming that `ΞΌ` gives positive mass to all neighborhoods of `xβ` within `s`.
For a less precise but more usable version, see
`tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`.
-/
theorem tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_measure_nhdsWithin_pos
[MetrizableSpace Ξ±] [IsLocallyFiniteMeasure ΞΌ] (hs : IsCompact s)
(hΞΌ : β u, IsOpen u β xβ β u β 0 < ΞΌ (u β© s)) {c : Ξ± β β} (hc : ContinuousOn c s)
(h'c : β y β s, y β xβ β c y < c xβ) (hnc : β x β s, 0 β€ c x) (hncβ : 0 < c xβ) (hβ : xβ β s)
(hmg : IntegrableOn g s ΞΌ) (hcg : ContinuousWithinAt g s xβ) :
Tendsto (fun n : β => (β« x in s, c x ^ n βΞΌ)β»ΒΉ β’ β« x in s, c x ^ n β’ g x βΞΌ)
atTop (π (g xβ)) := by
/- We apply the general result
`tendsto_setIntegral_peak_smul_of_integrableOn_of_continuousWithinAt` to the sequence of
peak functions `Οβ = (c x) ^ n / β« (c x) ^ n`. The only nontrivial bit is to check that this
sequence converges uniformly to zero on any set `s \ u` away from `xβ`. By compactness, the
function `c` is bounded by `t < c xβ` there. Consider `t' β (t, c xβ)`, and a neighborhood `v`
of `xβ` where `c x β₯ t'`, by continuity. Then `β« (c x) ^ n` is bounded below by `t' ^ n ΞΌ v`.
It follows that, on `s \ u`, then `Οβ x β€ t ^ n / (t' ^ n ΞΌ v)`,
which tends (exponentially fast) to zero with `n`. -/
let Ο : β β Ξ± β β := fun n x => (β« x in s, c x ^ n βΞΌ)β»ΒΉ * c x ^ n
have hnΟ : β n, β x β s, 0 β€ Ο n x := by
intro n x hx
apply mul_nonneg (inv_nonneg.2 _) (pow_nonneg (hnc x hx) _)
exact setIntegral_nonneg hs.measurableSet fun x hx => pow_nonneg (hnc x hx) _
have I : β n, IntegrableOn (fun x => c x ^ n) s ΞΌ := fun n =>
ContinuousOn.integrableOn_compact hs (hc.pow n)
have J : β n, 0 β€α΅[ΞΌ.restrict s] fun x : Ξ± => c x ^ n := by
intro n
filter_upwards [ae_restrict_mem hs.measurableSet] with x hx
exact pow_nonneg (hnc x hx) n
have P : β n, (0 : β) < β« x in s, c x ^ n βΞΌ := by
intro n
refine (setIntegral_pos_iff_support_of_nonneg_ae (J n) (I n)).2 ?_
obtain β¨u, u_open, xβ_u, huβ© : β u : Set Ξ±, IsOpen u β§ xβ β u β§ u β© s β c β»ΒΉ' Ioi 0 :=
_root_.continuousOn_iff.1 hc xβ hβ (Ioi (0 : β)) isOpen_Ioi hncβ
apply (hΞΌ u u_open xβ_u).trans_le
exact measure_mono fun x hx => β¨ne_of_gt (pow_pos (a := c x) (hu hx) _), hx.2β©
have hiΟ : β n, β« x in s, Ο n x βΞΌ = 1 := fun n => by
rw [integral_const_mul, inv_mul_cancelβ (P n).ne']
have A : β u : Set Ξ±, IsOpen u β xβ β u β TendstoUniformlyOn Ο 0 atTop (s \ u) := by
intro u u_open xβu
obtain β¨t, t_pos, txβ, htβ© : β t, 0 β€ t β§ t < c xβ β§ β x β s \ u, c x β€ t := by
rcases eq_empty_or_nonempty (s \ u) with (h | h)
Β· exact
β¨0, le_rfl, hncβ, by simp only [h, mem_empty_iff_false, IsEmpty.forall_iff, imp_true_iff]β©
obtain β¨x, hx, h'xβ© : β x β s \ u, β y β s \ u, c y β€ c x :=
IsCompact.exists_isMaxOn (hs.diff u_open) h (hc.mono diff_subset)
refine β¨c x, hnc x hx.1, h'c x hx.1 ?_, h'xβ©
rintro rfl
exact hx.2 xβu
obtain β¨t', tt', t'xββ© : β t', t < t' β§ t' < c xβ := exists_between txβ
have t'_pos : 0 < t' := t_pos.trans_lt tt'
obtain β¨v, v_open, xβ_v, hvβ© : β v : Set Ξ±, IsOpen v β§ xβ β v β§ v β© s β c β»ΒΉ' Ioi t' :=
_root_.continuousOn_iff.1 hc xβ hβ (Ioi t') isOpen_Ioi t'xβ
have M : β n, β x β s \ u, Ο n x β€ (ΞΌ.real (v β© s))β»ΒΉ * (t / t') ^ n := by
intro n x hx
have B : t' ^ n * ΞΌ.real (v β© s) β€ β« y in s, c y ^ n βΞΌ :=
calc
t' ^ n * ΞΌ.real (v β© s) = β« _ in v β© s, t' ^ n βΞΌ := by simp [mul_comm]
_ β€ β« y in v β© s, c y ^ n βΞΌ := by
apply setIntegral_mono_on _ _ (v_open.measurableSet.inter hs.measurableSet) _
Β· refine integrableOn_const (C := t' ^ n) ?_
exact (lt_of_le_of_lt (measure_mono inter_subset_right) hs.measure_lt_top).ne
Β· exact (I n).mono inter_subset_right le_rfl
Β· intro x hx
exact pow_le_pow_leftβ t'_pos.le (hv hx).le _
_ β€ β« y in s, c y ^ n βΞΌ :=
setIntegral_mono_set (I n) (J n) (Eventually.of_forall inter_subset_right)
simp_rw [Ο, β div_eq_inv_mul, div_pow, div_div]
have := ENNReal.toReal_pos (hΞΌ v v_open xβ_v).ne'
((measure_mono inter_subset_right).trans_lt hs.measure_lt_top).ne
gcongr
Β· exact hnc _ hx.1
Β· exact ht x hx
have N :
Tendsto (fun n => (ΞΌ.real (v β© s))β»ΒΉ * (t / t') ^ n) atTop
(π ((ΞΌ.real (v β© s))β»ΒΉ * 0)) := by
apply Tendsto.mul tendsto_const_nhds _
apply tendsto_pow_atTop_nhds_zero_of_lt_one (div_nonneg t_pos t'_pos.le)
exact (div_lt_one t'_pos).2 tt'
rw [mul_zero] at N
refine tendstoUniformlyOn_iff.2 fun Ξ΅ Ξ΅pos => ?_
filter_upwards [(tendsto_order.1 N).2 Ξ΅ Ξ΅pos] with n hn x hx
simp only [Pi.zero_apply, dist_zero_left, Real.norm_of_nonneg (hnΟ n x hx.1)]
exact (M n x hx).trans_lt hn
have : Tendsto (fun i : β => β« x : Ξ± in s, Ο i x β’ g x βΞΌ) atTop (π (g xβ)) := by
have B : Tendsto (fun i β¦ β« (x : Ξ±) in s, Ο i x βΞΌ) atTop (π 1) :=
tendsto_const_nhds.congr (fun n β¦ (hiΟ n).symm)
have C : βαΆ (i : β) in atTop, AEStronglyMeasurable (fun x β¦ Ο i x) (ΞΌ.restrict s) := by
apply Eventually.of_forall (fun n β¦ ((I n).const_mul _).aestronglyMeasurable)
exact tendsto_setIntegral_peak_smul_of_integrableOn_of_tendsto hs.measurableSet
hs.measurableSet (Subset.rfl) (self_mem_nhdsWithin)
hs.measure_lt_top.ne (Eventually.of_forall hnΟ) A B C hmg hcg
convert this
simp_rw [Ο, β smul_smul, integral_smul]
/-- If a continuous function `c` realizes its maximum at a unique point `xβ` in a compact set `s`,
then the sequence of functions `(c x) ^ n / β« (c x) ^ n` is a sequence of peak functions
concentrating around `xβ`. Therefore, `β« (c x) ^ n * g / β« (c x) ^ n` converges to `g xβ` if `g` is
integrable on `s` and continuous at `xβ`.
Version assuming that `ΞΌ` gives positive mass to all open sets.
For a less precise but more usable version, see
`tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`.
-/
theorem tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_integrableOn
[MetrizableSpace Ξ±] [IsLocallyFiniteMeasure ΞΌ] [IsOpenPosMeasure ΞΌ] (hs : IsCompact s)
{c : Ξ± β β} (hc : ContinuousOn c s) (h'c : β y β s, y β xβ β c y < c xβ)
(hnc : β x β s, 0 β€ c x) (hncβ : 0 < c xβ) (hβ : xβ β closure (interior s))
(hmg : IntegrableOn g s ΞΌ) (hcg : ContinuousWithinAt g s xβ) :
Tendsto (fun n : β => (β« x in s, c x ^ n βΞΌ)β»ΒΉ β’ β« x in s, c x ^ n β’ g x βΞΌ) atTop
(π (g xβ)) := by
have : xβ β s := by rw [β hs.isClosed.closure_eq]; exact closure_mono interior_subset hβ
apply
tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_measure_nhdsWithin_pos hs _ hc
h'c hnc hncβ this hmg hcg
intro u u_open xβ_u
calc
0 < ΞΌ (u β© interior s) :=
(u_open.inter isOpen_interior).measure_pos ΞΌ (_root_.mem_closure_iff.1 hβ u u_open xβ_u)
_ β€ ΞΌ (u β© s) := by gcongr; apply interior_subset
/-- If a continuous function `c` realizes its maximum at a unique point `xβ` in a compact set `s`,
then the sequence of functions `(c x) ^ n / β« (c x) ^ n` is a sequence of peak functions
concentrating around `xβ`. Therefore, `β« (c x) ^ n * g / β« (c x) ^ n` converges to `g xβ` if `g` is
continuous on `s`. -/
theorem tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn
[MetrizableSpace Ξ±] [IsLocallyFiniteMeasure ΞΌ] [IsOpenPosMeasure ΞΌ] (hs : IsCompact s)
{c : Ξ± β β} (hc : ContinuousOn c s) (h'c : β y β s, y β xβ β c y < c xβ)
(hnc : β x β s, 0 β€ c x) (hncβ : 0 < c xβ) (hβ : xβ β closure (interior s))
(hmg : ContinuousOn g s) :
Tendsto (fun n : β => (β« x in s, c x ^ n βΞΌ)β»ΒΉ β’ β« x in s, c x ^ n β’ g x βΞΌ) atTop (π (g xβ)) :=
haveI : xβ β s := by rw [β hs.isClosed.closure_eq]; exact closure_mono interior_subset hβ
tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_integrableOn hs hc h'c hnc hncβ hβ
(hmg.integrableOn_compact hs) (hmg xβ this)
/-!
### Peak functions of the form `x β¦ c ^ dim * Ο (c x)`
-/
open Module Bornology
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace β F] [FiniteDimensional β F]
[MeasurableSpace F] [BorelSpace F] {ΞΌ : Measure F} [IsAddHaarMeasure ΞΌ]
/-- Consider a nonnegative function `Ο` with integral one, decaying quickly enough at infinity.
Then suitable renormalizations of `Ο` form a sequence of peak functions around the origin:
`β« (c ^ d * Ο (c β’ x)) β’ g x` converges to `g 0` as `c β β` if `g` is continuous at `0`
and integrable. -/
theorem tendsto_integral_comp_smul_smul_of_integrable
{Ο : F β β} (hΟ : β x, 0 β€ Ο x) (h'Ο : β« x, Ο x βΞΌ = 1)
(h : Tendsto (fun x β¦ βxβ ^ finrank β F * Ο x) (cobounded F) (π 0))
{g : F β E} (hg : Integrable g ΞΌ) (h'g : ContinuousAt g 0) :
Tendsto (fun (c : β) β¦ β« x, (c ^ (finrank β F) * Ο (c β’ x)) β’ g x βΞΌ) atTop (π (g 0)) := by
have I : Integrable Ο ΞΌ := integrable_of_integral_eq_one h'Ο
apply tendsto_integral_peak_smul_of_integrable_of_tendsto (t := closedBall 0 1) (xβ := 0)
Β· exact isClosed_closedBall.measurableSet
Β· exact closedBall_mem_nhds _ zero_lt_one
Β· exact (isCompact_closedBall 0 1).measure_ne_top
Β· filter_upwards [Ici_mem_atTop 0] with c (hc : 0 β€ c) x using mul_nonneg (by positivity) (hΟ _)
Β· intro u u_open hu
apply tendstoUniformlyOn_iff.2 (fun Ξ΅ Ξ΅pos β¦ ?_)
obtain β¨Ξ΄, Ξ΄pos, h'uβ© : β Ξ΄ > 0, ball 0 Ξ΄ β u := Metric.isOpen_iff.1 u_open _ hu
obtain β¨M, Mpos, hMβ© : β M > 0, β β¦x : Fβ¦, x β (closedBall 0 M)αΆ β
βxβ ^ finrank β F * Ο x < Ξ΄ ^ finrank β F * Ξ΅ := by
rcases (hasBasis_cobounded_compl_closedBall (0 : F)).eventually_iff.1
((tendsto_order.1 h).2 (Ξ΄ ^ finrank β F * Ξ΅) (by positivity)) with β¨M, -, hMβ©
refine β¨max M 1, zero_lt_one.trans_le (le_max_right _ _), fun x hx β¦ hM ?_β©
simp only [mem_compl_iff, mem_closedBall, dist_zero_right, le_max_iff, not_or, not_le] at hx
simpa using hx.1
filter_upwards [Ioi_mem_atTop (M / Ξ΄)] with c (hc : M / Ξ΄ < c) x hx
have cpos : 0 < c := lt_trans (by positivity) hc
suffices c ^ finrank β F * Ο (c β’ x) < Ξ΅ by simpa [abs_of_nonneg (hΟ _), abs_of_nonneg cpos.le]
have hΞ΄x : Ξ΄ β€ βxβ := by
have : x β (ball 0 Ξ΄)αΆ := fun h β¦ hx (h'u h)
simpa only [mem_compl_iff, mem_ball, dist_zero_right, not_lt]
suffices Ξ΄ ^ finrank β F * (c ^ finrank β F * Ο (c β’ x)) < Ξ΄ ^ finrank β F * Ξ΅ by
rwa [mul_lt_mul_iff_of_pos_left (by positivity)] at this
calc
Ξ΄ ^ finrank β F * (c ^ finrank β F * Ο (c β’ x))
_ β€ βxβ ^ finrank β F * (c ^ finrank β F * Ο (c β’ x)) := by
gcongr; exact mul_nonneg (by positivity) (hΟ _)
_ = βc β’ xβ ^ finrank β F * Ο (c β’ x) := by
simp [norm_smul, abs_of_pos cpos, mul_pow]; ring
_ < Ξ΄ ^ finrank β F * Ξ΅ := by
apply hM
rw [div_lt_iffβ Ξ΄pos] at hc
simp only [mem_compl_iff, mem_closedBall, dist_zero_right, norm_smul, Real.norm_eq_abs,
abs_of_nonneg cpos.le, not_le]
exact hc.trans_le (by gcongr)
Β· have : Tendsto (fun c β¦ β« (x : F) in closedBall 0 c, Ο x βΞΌ) atTop (π 1) := by
rw [β h'Ο]
exact (aecover_closedBall tendsto_id).integral_tendsto_of_countably_generated I
apply this.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
rw [integral_const_mul, setIntegral_comp_smul_of_pos _ _ _ hc, smul_eq_mul, β mul_assoc,
mul_inv_cancelβ (by positivity), _root_.smul_closedBall _ _ zero_le_one]
simp [abs_of_nonneg hc.le]
Β· filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
exact (I.comp_smul hc.ne').aestronglyMeasurable.const_mul _
Β· exact hg
Β· exact h'g
/-- Consider a nonnegative function `Ο` with integral one, decaying quickly enough at infinity.
Then suitable renormalizations of `Ο` form a sequence of peak functions around any point:
`β« (c ^ d * Ο (c β’ (xβ - x)) β’ g x` converges to `g xβ` as `c β β` if `g` is continuous at `xβ`
and integrable. -/
theorem tendsto_integral_comp_smul_smul_of_integrable'
{Ο : F β β} (hΟ : β x, 0 β€ Ο x) (h'Ο : β« x, Ο x βΞΌ = 1)
(h : Tendsto (fun x β¦ βxβ ^ finrank β F * Ο x) (cobounded F) (π 0))
{g : F β E} {xβ : F} (hg : Integrable g ΞΌ) (h'g : ContinuousAt g xβ) :
Tendsto (fun (c : β) β¦ β« x, (c ^ (finrank β F) * Ο (c β’ (xβ - x))) β’ g x βΞΌ)
atTop (π (g xβ)) := by
let f := fun x β¦ g (xβ - x)
have If : Integrable f ΞΌ := by simpa [f, sub_eq_add_neg] using (hg.comp_add_left xβ).comp_neg
have : Tendsto (fun (c : β) β¦ β« x, (c ^ (finrank β F) * Ο (c β’ x)) β’ f x βΞΌ)
atTop (π (f 0)) := by
apply tendsto_integral_comp_smul_smul_of_integrable hΟ h'Ο h If
have A : ContinuousAt g (xβ - 0) := by simpa using h'g
exact A.comp <| by fun_prop
simp only [f, sub_zero] at this
convert this using 2 with c
conv_rhs => rw [β integral_add_left_eq_self xβ (ΞΌ := ΞΌ)
(f := fun x β¦ (c ^ finrank β F * Ο (c β’ x)) β’ g (xβ - x)), β integral_neg_eq_self]
simp [sub_eq_add_neg]
|
Functor.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, Kim Morrison
-/
import Mathlib.Data.Finset.Lattice.Union
import Mathlib.Data.Finset.NAry
import Mathlib.Data.Multiset.Functor
/-!
# Functoriality of `Finset`
This file defines the functor structure of `Finset`.
## TODO
Currently, all instances are classical because the functor classes want to run over all types. If
instead we could state that a functor is lawful/applicative/traversable... between two given types,
then we could provide the instances for types with decidable equality.
-/
universe u
open Function
namespace Finset
/-! ### Functor -/
section Functor
variable {Ξ± Ξ² : Type u} [β P, Decidable P]
/-- Because `Finset.image` requires a `DecidableEq` instance for the target type, we can only
construct `Functor Finset` when working classically. -/
protected instance functor : Functor Finset where map f s := s.image f
instance lawfulFunctor : LawfulFunctor Finset where
id_map _ := image_id
comp_map _ _ _ := image_image.symm
map_const {Ξ±} {Ξ²} := by simp only [Functor.mapConst, Functor.map]
@[simp]
theorem fmap_def {s : Finset Ξ±} (f : Ξ± β Ξ²) : f <$> s = s.image f := rfl
end Functor
/-! ### Pure -/
protected instance pure : Pure Finset :=
β¨fun x => {x}β©
@[simp]
theorem pure_def {Ξ±} : (pure : Ξ± β Finset Ξ±) = singleton := rfl
/-! ### Applicative functor -/
section Applicative
variable {Ξ± Ξ² : Type u} [β P, Decidable P]
protected instance applicative : Applicative Finset :=
{ Finset.functor, Finset.pure with
seq := fun t s => t.sup fun f => (s ()).image f
seqLeft := fun s t => if t () = β
then β
else s
seqRight := fun s t => if s = β
then β
else t () }
@[simp]
theorem seq_def (s : Finset Ξ±) (t : Finset (Ξ± β Ξ²)) : t <*> s = t.sup fun f => s.image f :=
rfl
@[simp]
theorem seqLeft_def (s : Finset Ξ±) (t : Finset Ξ²) : s <* t = if t = β
then β
else s :=
rfl
@[simp]
theorem seqRight_def (s : Finset Ξ±) (t : Finset Ξ²) : s *> t = if s = β
then β
else t :=
rfl
/-- `Finset.imageβ` in terms of monadic operations. Note that this can't be taken as the definition
because of the lack of universe polymorphism. -/
theorem imageβ_def {Ξ± Ξ² Ξ³ : Type u} (f : Ξ± β Ξ² β Ξ³) (s : Finset Ξ±) (t : Finset Ξ²) :
imageβ f s t = f <$> s <*> t := by
ext
simp [mem_sup]
instance lawfulApplicative : LawfulApplicative Finset :=
{ Finset.lawfulFunctor with
seqLeft_eq := fun s t => by
rw [seq_def, fmap_def, seqLeft_def]
obtain rfl | ht := t.eq_empty_or_nonempty
Β· simp_rw [image_empty, if_true]
exact (sup_bot _).symm
Β· ext a
rw [if_neg ht.ne_empty, mem_sup]
refine β¨fun ha => β¨const _ a, mem_image_of_mem _ ha, mem_image_const_self.2 htβ©, ?_β©
rintro β¨f, hf, haβ©
rw [mem_image] at hf ha
obtain β¨b, hb, rflβ© := hf
obtain β¨_, _, rflβ© := ha
exact hb
seqRight_eq := fun s t => by
rw [seq_def, fmap_def, seqRight_def]
obtain rfl | hs := s.eq_empty_or_nonempty
Β· rw [if_pos rfl, image_empty, sup_empty, bot_eq_empty]
Β· ext a
rw [if_neg hs.ne_empty, mem_sup]
refine β¨fun ha => β¨id, mem_image_const_self.2 hs, by rwa [image_id]β©, ?_β©
rintro β¨f, hf, haβ©
rw [mem_image] at hf ha
obtain β¨b, hb, rflβ© := ha
obtain β¨_, _, rflβ© := hf
exact hb
pure_seq := fun f s => by simp only [pure_def, seq_def, sup_singleton, fmap_def]
map_pure := fun _ _ => image_singleton _ _
seq_pure := fun _ _ => sup_singleton_apply _ _
seq_assoc := fun s t u => by
ext a
simp_rw [seq_def, fmap_def]
simp only [mem_sup, mem_image]
constructor
Β· rintro β¨g, hg, b, β¨f, hf, a, ha, rflβ©, rflβ©
exact β¨g β f, β¨comp g, β¨g, hg, rflβ©, f, hf, rflβ©, a, ha, rflβ©
Β· rintro β¨c, β¨_, β¨g, hg, rflβ©, f, hf, rflβ©, a, ha, rflβ©
exact β¨g, hg, f a, β¨f, hf, a, ha, rflβ©, rflβ© }
instance commApplicative : CommApplicative Finset :=
{ Finset.lawfulApplicative with
commutative_prod := fun s t => by
simp_rw [seq_def, fmap_def, sup_image, sup_eq_biUnion]
change (s.biUnion fun a => t.image fun b => (a, b))
= t.biUnion fun b => s.image fun a => (a, b)
trans s ΓΛ’ t <;> [rw [product_eq_biUnion]; rw [product_eq_biUnion_right]] }
end Applicative
/-! ### Monad -/
section Monad
variable [β P, Decidable P]
instance : Monad Finset :=
{ Finset.applicative with bind := sup }
@[simp]
theorem bind_def {Ξ± Ξ²} : (Β· >>= Β·) = sup (Ξ± := Finset Ξ±) (Ξ² := Ξ²) :=
rfl
instance : LawfulMonad Finset :=
{ Finset.lawfulApplicative with
bind_pure_comp := fun _ _ => sup_singleton_apply _ _
bind_map := fun _ _ => rfl
pure_bind := fun _ _ => sup_singleton
bind_assoc := fun s f g => by simp only [bind, sup_eq_biUnion, biUnion_biUnion] }
end Monad
/-! ### Alternative functor -/
section Alternative
variable [β P, Decidable P]
instance : Alternative Finset :=
{ Finset.applicative with
orElse := fun s t => (s βͺ t ())
failure := β
}
end Alternative
/-! ### Traversable functor -/
section Traversable
variable {Ξ± Ξ² Ξ³ : Type u} {F G : Type u β Type u} [Applicative F] [Applicative G]
[CommApplicative F] [CommApplicative G]
/-- Traverse function for `Finset`. -/
def traverse [DecidableEq Ξ²] (f : Ξ± β F Ξ²) (s : Finset Ξ±) : F (Finset Ξ²) :=
Multiset.toFinset <$> Multiset.traverse f s.1
@[simp]
theorem id_traverse [DecidableEq Ξ±] (s : Finset Ξ±) : traverse (pure : Ξ± β Id Ξ±) s = pure s := by
rw [traverse, Multiset.id_traverse]
exact s.val_toFinset
open scoped Classical in
@[simp]
theorem map_comp_coe (h : Ξ± β Ξ²) :
Functor.map h β Multiset.toFinset = Multiset.toFinset β Functor.map h :=
funext fun _ => image_toFinset
open scoped Classical in
@[simp]
theorem map_comp_coe_apply (h : Ξ± β Ξ²) (s : Multiset Ξ±) :
s.toFinset.image h = (h <$> s).toFinset :=
congrFun (map_comp_coe h) s
open scoped Classical in
theorem map_traverse (g : Ξ± β G Ξ²) (h : Ξ² β Ξ³) (s : Finset Ξ±) :
Functor.map h <$> traverse g s = traverse (Functor.map h β g) s := by
unfold traverse
simp only [Functor.map_map, fmap_def, map_comp_coe_apply, Multiset.fmap_def, β
Multiset.map_traverse]
end Traversable
end Finset
|
CauSeqFilter.lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.Normed.Field.Basic
import Mathlib.Topology.MetricSpace.Cauchy
/-!
# Completeness in terms of `Cauchy` filters vs `isCauSeq` sequences
In this file we apply `Metric.complete_of_cauchySeq_tendsto` to prove that a `NormedRing`
is complete in terms of `Cauchy` filter if and only if it is complete in terms
of `CauSeq` Cauchy sequences.
-/
universe u v
open Set Filter Topology
variable {Ξ² : Type v}
theorem CauSeq.tendsto_limit [NormedRing Ξ²] [hn : IsAbsoluteValue (norm : Ξ² β β)]
(f : CauSeq Ξ² norm) [CauSeq.IsComplete Ξ² norm] : Tendsto f atTop (π f.lim) :=
tendsto_nhds.mpr
(by
intro s os lfs
suffices β a : β, β b : β, b β₯ a β f b β s by simpa using this
rcases Metric.isOpen_iff.1 os _ lfs with β¨Ξ΅, β¨hΞ΅, hΞ΅sβ©β©
obtain β¨N, hNβ© := Setoid.symm (CauSeq.equiv_lim f) _ hΞ΅
exists N
intro b hb
apply hΞ΅s
dsimp [Metric.ball]
rw [dist_comm, dist_eq_norm]
solve_by_elim)
variable [NormedField Ξ²]
/-
This section shows that if we have a uniform space generated by an absolute value, topological
completeness and Cauchy sequence completeness coincide. The problem is that there isn't
a good notion of "uniform space generated by an absolute value", so right now this is
specific to norm. Furthermore, norm only instantiates IsAbsoluteValue on NormedDivisionRing.
This needs to be fixed, since it prevents showing that β€_[hp] is complete.
-/
open Metric
theorem CauchySeq.isCauSeq {f : β β Ξ²} (hf : CauchySeq f) : IsCauSeq norm f := by
obtain β¨hf1, hf2β© := cauchy_iff.1 hf
intro Ξ΅ hΞ΅
rcases hf2 { x | dist x.1 x.2 < Ξ΅ } (dist_mem_uniformity hΞ΅) with β¨t, β¨ht, htsubβ©β©
simp only [mem_map, mem_atTop_sets, mem_preimage] at ht; obtain β¨N, hNβ© := ht
exists N
intro j hj
rw [β dist_eq_norm]
apply @htsub (f j, f N)
apply Set.mk_mem_prod <;> solve_by_elim [le_refl]
theorem CauSeq.cauchySeq (f : CauSeq Ξ² norm) : CauchySeq f := by
refine cauchy_iff.2 β¨by infer_instance, fun s hs => ?_β©
rcases mem_uniformity_dist.1 hs with β¨Ξ΅, β¨hΞ΅, hΞ΅sβ©β©
obtain β¨N, hNβ© := CauSeq.cauchyβ f hΞ΅
exists { n | n β₯ N }.image f
simp only [mem_atTop_sets, mem_map]
constructor
Β· exists N
intro b hb
exists b
Β· rintro β¨a, bβ© β¨β¨a', β¨ha'1, ha'2β©β©, β¨b', β¨hb'1, hb'2β©β©β©
dsimp at ha'1 ha'2 hb'1 hb'2
rw [β ha'2, β hb'2]
apply hΞ΅s
rw [dist_eq_norm]
apply hN <;> assumption
/-- In a normed field, `CauSeq` coincides with the usual notion of Cauchy sequences. -/
theorem isCauSeq_iff_cauchySeq {Ξ± : Type u} [NormedField Ξ±] {u : β β Ξ±} :
IsCauSeq norm u β CauchySeq u :=
β¨fun h => CauSeq.cauchySeq β¨u, hβ©, fun h => h.isCauSeqβ©
-- see Note [lower instance priority]
/-- A complete normed field is complete as a metric space, as Cauchy sequences converge by
assumption and this suffices to characterize completeness. -/
instance (priority := 100) completeSpace_of_cauSeq_isComplete [CauSeq.IsComplete Ξ² norm] :
CompleteSpace Ξ² := by
apply complete_of_cauchySeq_tendsto
intro u hu
have C : IsCauSeq norm u := isCauSeq_iff_cauchySeq.2 hu
exists CauSeq.lim β¨u, Cβ©
rw [Metric.tendsto_atTop]
intro Ξ΅ Ξ΅pos
obtain β¨N, hNβ© := (CauSeq.equiv_lim β¨u, Cβ©) _ Ξ΅pos
exists N
simpa [dist_eq_norm] using hN
|
NotNormal.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Real.Cardinality
import Mathlib.Topology.TietzeExtension
/-!
# Not normal topological spaces
In this file we prove (see `IsClosed.not_normal_of_continuum_le_mk`) that a separable space with a
discrete subspace of cardinality continuum is not a normal topological space.
-/
open Set Function Cardinal Topology TopologicalSpace
universe u
variable {X : Type u} [TopologicalSpace X] [SeparableSpace X]
/-- Let `s` be a closed set in a separable normal space. If the induced topology on `s` is discrete,
then `s` has cardinality less than continuum.
The proof follows
https://en.wikipedia.org/wiki/Moore_plane#Proof_that_the_Moore_plane_is_not_normal -/
theorem IsClosed.mk_lt_continuum [NormalSpace X] {s : Set X} (hs : IsClosed s)
[DiscreteTopology s] : #s < π := by
-- Proof by contradiction: assume `π β€ #s`
by_contra! h
-- Choose a countable dense set `t : Set X`
rcases exists_countable_dense X with β¨t, htc, htdβ©
haveI := htc.to_subtype
-- To obtain a contradiction, we will prove `2 ^ π β€ π `.
refine (Cardinal.cantor π ).not_ge ?_
calc
-- Any function `s β β` is continuous, hence `2 ^ π β€ #C(s, β)`
2 ^ π β€ #C(s, β) := by
rw [ContinuousMap.equivFnOfDiscrete.cardinal_eq, mk_arrow, mk_real, lift_continuum,
lift_uzero]
exact (power_le_power_left two_ne_zero h).trans (power_le_power_right (nat_lt_continuum 2).le)
-- By the Tietze Extension Theorem, any function `f : C(s, β)` can be extended to `C(X, β)`,
-- hence `#C(s, β) β€ #C(X, β)`
_ β€ #C(X, β) := by
choose f hf using ContinuousMap.exists_restrict_eq (Y := β) hs
have hfi : Injective f := LeftInverse.injective hf
exact mk_le_of_injective hfi
-- Since `t` is dense, restriction `C(X, β) β C(t, β)` is injective, hence `#C(X, β) β€ #C(t, β)`
_ β€ #C(t, β) := mk_le_of_injective <| ContinuousMap.injective_restrict htd
_ β€ #(t β β) := mk_le_of_injective DFunLike.coe_injective
-- Since `t` is countable, we have `#(t β β) β€ π `
_ β€ π := by
rw [mk_arrow, mk_real, lift_uzero, lift_continuum, continuum, β power_mul]
exact power_le_power_left two_ne_zero mk_le_aleph0
/-- Let `s` be a closed set in a separable space. If the induced topology on `s` is discrete and `s`
has cardinality at least continuum, then the ambient space is not a normal space. -/
theorem IsClosed.not_normal_of_continuum_le_mk {s : Set X} (hs : IsClosed s) [DiscreteTopology s]
(hmk : π β€ #s) : Β¬NormalSpace X := fun _ β¦ hs.mk_lt_continuum.not_ge hmk
|
Defs.lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.Init
import Batteries.Util.ExtendedBinder
import Lean.Elab.Term
/-!
# Sets
This file sets up the theory of sets whose elements have a given type.
## Main definitions
Given a type `X` and a predicate `p : X β Prop`:
* `Set X` : the type of sets whose elements have type `X`
* `{a : X | p a} : Set X` : the set of all elements of `X` satisfying `p`
* `{a | p a} : Set X` : a more concise notation for `{a : X | p a}`
* `{f x y | (x : X) (y : Y)} : Set Z` : a more concise notation for `{z : Z | β x y, f x y = z}`
* `{a β S | p a} : Set X` : given `S : Set X`, the subset of `S` consisting of
its elements satisfying `p`.
## Implementation issues
As in Lean 3, `Set X := X β Prop`
This file is a port of the core Lean 3 file `lib/lean/library/init/data/set.lean`.
-/
open Lean Elab Term Meta Batteries.ExtendedBinder
universe u
variable {Ξ± : Type u}
/-- A set is a collection of elements of some type `Ξ±`.
Although `Set` is defined as `Ξ± β Prop`, this is an implementation detail which should not be
relied on. Instead, `setOf` and membership of a set (`β`) should be used to convert between sets
and predicates.
-/
def Set (Ξ± : Type u) := Ξ± β Prop
/-- Turn a predicate `p : Ξ± β Prop` into a set, also written as `{x | p x}` -/
def setOf {Ξ± : Type u} (p : Ξ± β Prop) : Set Ξ± :=
p
namespace Set
/-- Membership in a set -/
protected def Mem (s : Set Ξ±) (a : Ξ±) : Prop :=
s a
instance : Membership Ξ± (Set Ξ±) :=
β¨Set.Memβ©
theorem ext {a b : Set Ξ±} (h : β (x : Ξ±), x β a β x β b) : a = b :=
funext (fun x β¦ propext (h x))
attribute [local ext] ext in
attribute [grind ext] ext
/-- The subset relation on sets. `s β t` means that all elements of `s` are elements of `t`.
Note that you should **not** use this definition directly, but instead write `s β t`. -/
protected def Subset (sβ sβ : Set Ξ±) :=
β β¦aβ¦, a β sβ β a β sβ
/-- We introduce `β€` before `β` to help the unifier when applying lattice theorems
to subset hypotheses. -/
instance : LE (Set Ξ±) :=
β¨Set.Subsetβ©
instance : HasSubset (Set Ξ±) :=
β¨(Β· β€ Β·)β©
instance : EmptyCollection (Set Ξ±) :=
β¨fun _ β¦ Falseβ©
end Set
namespace Mathlib.Meta
/-- Set builder syntax. This can be elaborated to either a `Set` or a `Finset` depending on context.
The elaborators for this syntax are located in:
* `Data.Set.Defs` for the `Set` builder notation elaborator for syntax of the form `{x | p x}`,
`{x : Ξ± | p x}`, `{binder x | p x}`.
* `Data.Finset.Basic` for the `Finset` builder notation elaborator for syntax of the form
`{x β s | p x}`.
* `Data.Fintype.Basic` for the `Finset` builder notation elaborator for syntax of the form
`{x | p x}`, `{x : Ξ± | p x}`, `{x β s | p x}`, `{x β a | p x}`.
* `Order.LocallyFinite.Basic` for the `Finset` builder notation elaborator for syntax of the form
`{x β€ a | p x}`, `{x β₯ a | p x}`, `{x < a | p x}`, `{x > a | p x}`.
-/
syntax (name := setBuilder) "{" extBinder " | " term "}" : term
/-- Elaborate set builder notation for `Set`.
* `{x | p x}` is elaborated as `Set.setOf fun x β¦ p x`
* `{x : Ξ± | p x}` is elaborated as `Set.setOf fun x : Ξ± β¦ p x`
* `{binder x | p x}`, where `x` is bound by the `binder` binder, is elaborated as
`{x | binder x β§ p x}`. The typical example is `{x β s | p x}`, which is elaborated as
`{x | x β s β§ p x}`. The possible binders are
* `Β· β s`, `Β· β s`
* `Β· β s`, `Β· β s`, `Β· β s`, `Β· β s`
* `Β· β€ a`, `Β· β₯ a`, `Β· < a`, `Β· > a`, `Β· β a`
More binders can be declared using the `binder_predicate` command, see `Init.BinderPredicates` for
more info.
See also
* `Data.Finset.Basic` for the `Finset` builder notation elaborator partly overriding this one for
syntax of the form `{x β s | p x}`.
* `Data.Fintype.Basic` for the `Finset` builder notation elaborator partly overriding this one for
syntax of the form `{x | p x}`, `{x : Ξ± | p x}`, `{x β s | p x}`, `{x β a | p x}`.
* `Order.LocallyFinite.Basic` for the `Finset` builder notation elaborator partly overriding this
one for syntax of the form `{x β€ a | p x}`, `{x β₯ a | p x}`, `{x < a | p x}`, `{x > a | p x}`.
-/
@[term_elab setBuilder]
def elabSetBuilder : TermElab
| `({ $x:ident | $p }), expectedType? => do
elabTerm (β `(setOf fun $x:ident β¦ $p)) expectedType?
| `({ $x:ident : $t | $p }), expectedType? => do
elabTerm (β `(setOf fun $x:ident : $t β¦ $p)) expectedType?
| `({ $x:ident $b:binderPred | $p }), expectedType? => do
elabTerm (β `(setOf fun $x:ident β¦ satisfies_binder_pred% $x $b β§ $p)) expectedType?
| _, _ => throwUnsupportedSyntax
/-- Unexpander for set builder notation. -/
@[app_unexpander setOf]
def setOf.unexpander : Lean.PrettyPrinter.Unexpander
| `($_ fun $x:ident β¦ $p) => `({ $x:ident | $p })
| `($_ fun ($x:ident : $ty:term) β¦ $p) => `({ $x:ident : $ty:term | $p })
| _ => throw ()
open Batteries.ExtendedBinder in
/--
`{ f x y | (x : X) (y : Y) }` is notation for the set of elements `f x y` constructed from the
binders `x` and `y`, equivalent to `{z : Z | β x y, f x y = z}`.
If `f x y` is a single identifier, it must be parenthesized to avoid ambiguity with `{x | p x}`;
for instance, `{(x) | (x : Nat) (y : Nat) (_hxy : x = y^2)}`.
-/
macro (priority := low) "{" t:term " | " bs:extBinders "}" : term =>
`({x | βα΅ $bs:extBinders, $t = x})
/--
* `{ pat : X | p }` is notation for pattern matching in set-builder notation,
where `pat` is a pattern that is matched by all objects of type `X`
and `p` is a proposition that can refer to variables in the pattern.
It is the set of all objects of type `X` which, when matched with the pattern `pat`,
make `p` come out true.
* `{ pat | p }` is the same, but in the case when the type `X` can be inferred.
For example, `{ (m, n) : β Γ β | m * n = 12 }` denotes the set of all ordered pairs of
natural numbers whose product is 12.
Note that if the type ascription is left out and `p` can be interpreted as an extended binder,
then the extended binder interpretation will be used. For example, `{ n + 1 | n < 3 }` will
be interpreted as `{ x : Nat | β n < 3, n + 1 = x }` rather than using pattern matching.
-/
macro (name := macroPattSetBuilder) (priority := low - 1)
"{" pat:term " : " t:term " | " p:term "}" : term =>
`({ x : $t | match x with | $pat => $p })
@[inherit_doc macroPattSetBuilder]
macro (priority := low - 1) "{" pat:term " | " p:term "}" : term =>
`({ x | match x with | $pat => $p })
/-- Pretty printing for set-builder notation with pattern matching. -/
@[app_unexpander setOf]
def setOfPatternMatchUnexpander : Lean.PrettyPrinter.Unexpander
| `($_ fun $x:ident β¦ match $y:ident with | $pat => $p) =>
if x == y then
`({ $pat:term | $p:term })
else
throw ()
| `($_ fun ($x:ident : $ty:term) β¦ match $y:ident with | $pat => $p) =>
if x == y then
`({ $pat:term : $ty:term | $p:term })
else
throw ()
| _ => throw ()
end Mathlib.Meta
namespace Set
/-- The universal set on a type `Ξ±` is the set containing all elements of `Ξ±`.
This is conceptually the "same as" `Ξ±` (in set theory, it is actually the same), but type theory
makes the distinction that `Ξ±` is a type while `Set.univ` is a term of type `Set Ξ±`. `Set.univ` can
itself be coerced to a type `β₯Set.univ` which is in bijection with (but distinct from) `Ξ±`. -/
def univ : Set Ξ± := {_a | True}
/-- `Set.insert a s` is the set `{a} βͺ s`.
Note that you should **not** use this definition directly, but instead write `insert a s` (which is
mediated by the `Insert` typeclass). -/
protected def insert (a : Ξ±) (s : Set Ξ±) : Set Ξ± := {b | b = a β¨ b β s}
instance : Insert Ξ± (Set Ξ±) := β¨Set.insertβ©
/-- The singleton of an element `a` is the set with `a` as a single element.
Note that you should **not** use this definition directly, but instead write `{a}`. -/
protected def singleton (a : Ξ±) : Set Ξ± := {b | b = a}
instance instSingletonSet : Singleton Ξ± (Set Ξ±) := β¨Set.singletonβ©
/-- The union of two sets `s` and `t` is the set of elements contained in either `s` or `t`.
Note that you should **not** use this definition directly, but instead write `s βͺ t`. -/
protected def union (sβ sβ : Set Ξ±) : Set Ξ± := {a | a β sβ β¨ a β sβ}
instance : Union (Set Ξ±) := β¨Set.unionβ©
/-- The intersection of two sets `s` and `t` is the set of elements contained in both `s` and `t`.
Note that you should **not** use this definition directly, but instead write `s β© t`. -/
protected def inter (sβ sβ : Set Ξ±) : Set Ξ± := {a | a β sβ β§ a β sβ}
instance : Inter (Set Ξ±) := β¨Set.interβ©
/-- The complement of a set `s` is the set of elements not contained in `s`.
Note that you should **not** use this definition directly, but instead write `sαΆ`. -/
protected def compl (s : Set Ξ±) : Set Ξ± := {a | a β s}
/-- The difference of two sets `s` and `t` is the set of elements contained in `s` but not in `t`.
Note that you should **not** use this definition directly, but instead write `s \ t`. -/
protected def diff (s t : Set Ξ±) : Set Ξ± := {a β s | a β t}
instance : SDiff (Set Ξ±) := β¨Set.diffβ©
/-- `π« s` is the set of all subsets of `s`. -/
def powerset (s : Set Ξ±) : Set (Set Ξ±) := {t | t β s}
@[inherit_doc] prefix:100 "π«" => powerset
universe v in
/-- The image of `s : Set Ξ±` by `f : Ξ± β Ξ²`, written `f '' s`, is the set of `b : Ξ²` such that
`f a = b` for some `a β s`. -/
def image {Ξ² : Type v} (f : Ξ± β Ξ²) (s : Set Ξ±) : Set Ξ² := {f a | a β s}
instance : Functor Set where map := @Set.image
instance : LawfulFunctor Set where
id_map _ := funext fun _ β¦ propext β¨fun β¨_, sb, rflβ© β¦ sb, fun sb β¦ β¨_, sb, rflβ©β©
comp_map g h _ := funext <| fun c β¦ propext
β¨fun β¨a, β¨hβ, hββ©β© β¦ β¨g a, β¨β¨a, β¨hβ, rflβ©β©, hββ©β©,
fun β¨_, β¨β¨a, β¨hβ, hββ©β©, hββ©β© β¦ β¨a, β¨hβ, show h (g a) = c from hβ βΈ hββ©β©β©
map_const := rfl
/-- The property `s.Nonempty` expresses the fact that the set `s` is not empty. It should be used
in theorem assumptions instead of `β x, x β s` or `s β β
` as it gives access to a nice API thanks
to the dot notation. -/
protected def Nonempty (s : Set Ξ±) : Prop :=
β x, x β s
end Set
|
Colimit.lean
|
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Comma.Presheaf.Basic
import Mathlib.CategoryTheory.Limits.Preserves.Yoneda
import Mathlib.CategoryTheory.Limits.Over
/-!
# Relative Yoneda preserves certain colimits
In this file we turn the statement `yonedaYonedaColimit` from
`CategoryTheory.Limits.Preserves.Yoneda` from a functor `F : J β₯€ Cα΅α΅ β₯€ Type v` into a statement
about families of presheaves over `A`, i.e., functors `F : J β₯€ Over A`.
-/
namespace CategoryTheory
open Category Opposite Limits
universe w v u
variable {C : Type u} [Category.{v} C] {A : Cα΅α΅ β₯€ Type v}
variable {J : Type v} [SmallCategory J] {A : Cα΅α΅ β₯€ Type v} (F : J β₯€ Over A)
-- We introduce some local notation to reduce visual noise in the following proof
local notation "E" => Equivalence.functor (overEquivPresheafCostructuredArrow A)
local notation "E.obj" =>
Functor.obj (Equivalence.functor (overEquivPresheafCostructuredArrow A))
/-- Naturally in `X`, we have `Hom(YX, colim_i Fi) β
colim_i Hom(YX, Fi)`, where `Y` is the
"Yoneda embedding" `CostructuredArrow.toOver yoneda A`. This is a relative version of
`yonedaYonedaColimit`. -/
noncomputable def CostructuredArrow.toOverCompYonedaColimit :
(CostructuredArrow.toOver yoneda A).op β yoneda.obj (colimit F) β
(CostructuredArrow.toOver yoneda A).op β colimit (F β yoneda) := calc
(CostructuredArrow.toOver yoneda A).op β yoneda.obj (colimit F)
β
yoneda.op β yoneda.obj (E.obj (colimit F)) :=
CostructuredArrow.toOverCompYoneda A _
_ β
yoneda.op β yoneda.obj (colimit (F β E)) :=
Functor.isoWhiskerLeft yoneda.op (yoneda.mapIso (preservesColimitIso E F))
_ β
yoneda.op β colimit ((F β E) β yoneda) :=
yonedaYonedaColimit _
_ β
yoneda.op β ((F β E) β yoneda).flip β colim :=
Functor.isoWhiskerLeft _ (colimitIsoFlipCompColim _)
_ β
(yoneda.op β coyoneda β (Functor.whiskeringLeft _ _ _).obj E) β
(Functor.whiskeringLeft _ _ _).obj F β colim :=
Iso.refl _
_ β
(CostructuredArrow.toOver yoneda A).op β coyoneda β
(Functor.whiskeringLeft _ _ _).obj F β colim :=
Functor.isoWhiskerRight (CostructuredArrow.toOverCompCoyoneda _).symm _
_ β
(CostructuredArrow.toOver yoneda A).op β (F β yoneda).flip β colim :=
Iso.refl _
_ β
(CostructuredArrow.toOver yoneda A).op β colimit (F β yoneda) :=
Functor.isoWhiskerLeft _ (colimitIsoFlipCompColim _).symm
end CategoryTheory
|
GradedMonoid.lean
|
/-
Copyright (c) 2021 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.BigOperators.Group.List.Lemmas
import Mathlib.Algebra.Group.Action.Hom
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Data.List.FinRange
import Mathlib.Data.SetLike.Basic
import Mathlib.Data.Sigma.Basic
import Lean.Elab.Tactic
import Mathlib.Algebra.BigOperators.Group.Finset.Basic
/-!
# Additively-graded multiplicative structures
This module provides a set of heterogeneous typeclasses for defining a multiplicative structure
over the sigma type `GradedMonoid A` such that `(*) : A i β A j β A (i + j)`; that is to say, `A`
forms an additively-graded monoid. The typeclasses are:
* `GradedMonoid.GOne A`
* `GradedMonoid.GMul A`
* `GradedMonoid.GMonoid A`
* `GradedMonoid.GCommMonoid A`
These respectively imbue:
* `One (GradedMonoid A)`
* `Mul (GradedMonoid A)`
* `Monoid (GradedMonoid A)`
* `CommMonoid (GradedMonoid A)`
the base type `A 0` with:
* `GradedMonoid.GradeZero.One`
* `GradedMonoid.GradeZero.Mul`
* `GradedMonoid.GradeZero.Monoid`
* `GradedMonoid.GradeZero.CommMonoid`
and the `i`th grade `A i` with `A 0`-actions (`β’`) defined as left-multiplication:
* (nothing)
* `GradedMonoid.GradeZero.SMul (A 0)`
* `GradedMonoid.GradeZero.MulAction (A 0)`
* (nothing)
For now, these typeclasses are primarily used in the construction of `DirectSum.Ring` and the rest
of that file.
## Dependent graded products
This also introduces `List.dProd`, which takes the (possibly non-commutative) product of a list
of graded elements of type `A i`. This definition primarily exists to allow `GradedMonoid.mk`
and `DirectSum.of` to be pulled outside a product, such as in `GradedMonoid.mk_list_dProd` and
`DirectSum.of_list_dProd`.
## Internally graded monoids
In addition to the above typeclasses, in the most frequent case when `A` is an indexed collection of
`SetLike` subobjects (such as `AddSubmonoid`s, `AddSubgroup`s, or `Submodule`s), this file
provides the `Prop` typeclasses:
* `SetLike.GradedOne A` (which provides the obvious `GradedMonoid.GOne A` instance)
* `SetLike.GradedMul A` (which provides the obvious `GradedMonoid.GMul A` instance)
* `SetLike.GradedMonoid A` (which provides the obvious `GradedMonoid.GMonoid A` and
`GradedMonoid.GCommMonoid A` instances)
which respectively provide the API lemmas
* `SetLike.one_mem_graded`
* `SetLike.mul_mem_graded`
* `SetLike.pow_mem_graded`, `SetLike.list_prod_map_mem_graded`
Strictly this last class is unnecessary as it has no fields not present in its parents, but it is
included for convenience. Note that there is no need for `SetLike.GradedRing` or similar, as all
the information it would contain is already supplied by `GradedMonoid` when `A` is a collection
of objects satisfying `AddSubmonoidClass` such as `Submodule`s. These constructions are explored
in `Algebra.DirectSum.Internal`.
This file also defines:
* `SetLike.IsHomogeneousElem A` (which says that `a` is homogeneous iff `a β A i` for some `i : ΞΉ`)
* `SetLike.homogeneousSubmonoid A`, which is, as the name suggests, the submonoid consisting of
all the homogeneous elements.
## Tags
graded monoid
-/
variable {ΞΉ : Type*}
/-- A type alias of sigma types for graded monoids. -/
def GradedMonoid (A : ΞΉ β Type*) :=
Sigma A
namespace GradedMonoid
instance {A : ΞΉ β Type*} [Inhabited ΞΉ] [Inhabited (A default)] : Inhabited (GradedMonoid A) :=
inferInstanceAs <| Inhabited (Sigma _)
/-- Construct an element of a graded monoid. -/
def mk {A : ΞΉ β Type*} : β i, A i β GradedMonoid A :=
Sigma.mk
/-! ### Actions -/
section actions
variable {Ξ± Ξ²} {A : ΞΉ β Type*}
/-- If `R` acts on each `A i`, then it acts on `GradedMonoid A` via the `.2` projection. -/
instance [β i, SMul Ξ± (A i)] : SMul Ξ± (GradedMonoid A) where
smul r g := GradedMonoid.mk g.1 (r β’ g.2)
@[simp] theorem fst_smul [β i, SMul Ξ± (A i)] (a : Ξ±) (x : GradedMonoid A) :
(a β’ x).fst = x.fst := rfl
@[simp] theorem snd_smul [β i, SMul Ξ± (A i)] (a : Ξ±) (x : GradedMonoid A) :
(a β’ x).snd = a β’ x.snd := rfl
theorem smul_mk [β i, SMul Ξ± (A i)] {i} (c : Ξ±) (a : A i) :
c β’ mk i a = mk i (c β’ a) :=
rfl
instance [β i, SMul Ξ± (A i)] [β i, SMul Ξ² (A i)]
[β i, SMulCommClass Ξ± Ξ² (A i)] :
SMulCommClass Ξ± Ξ² (GradedMonoid A) where
smul_comm a b g := Sigma.ext rfl <| heq_of_eq <| smul_comm a b g.2
instance [SMul Ξ± Ξ²] [β i, SMul Ξ± (A i)] [β i, SMul Ξ² (A i)]
[β i, IsScalarTower Ξ± Ξ² (A i)] :
IsScalarTower Ξ± Ξ² (GradedMonoid A) where
smul_assoc a b g := Sigma.ext rfl <| heq_of_eq <| smul_assoc a b g.2
instance [Monoid Ξ±] [β i, MulAction Ξ± (A i)] :
MulAction Ξ± (GradedMonoid A) where
one_smul g := Sigma.ext rfl <| heq_of_eq <| one_smul _ g.2
mul_smul rβ rβ g := Sigma.ext rfl <| heq_of_eq <| mul_smul rβ rβ g.2
end actions
/-! ### Typeclasses -/
section Defs
variable (A : ΞΉ β Type*)
/-- A graded version of `One`, which must be of grade 0. -/
class GOne [Zero ΞΉ] where
/-- The term `one` of grade 0 -/
one : A 0
/-- `GOne` implies `One (GradedMonoid A)` -/
instance GOne.toOne [Zero ΞΉ] [GOne A] : One (GradedMonoid A) :=
β¨β¨_, GOne.oneβ©β©
@[simp] theorem fst_one [Zero ΞΉ] [GOne A] : (1 : GradedMonoid A).fst = 0 := rfl
@[simp] theorem snd_one [Zero ΞΉ] [GOne A] : (1 : GradedMonoid A).snd = GOne.one := rfl
/-- A graded version of `Mul`. Multiplication combines grades additively, like
`AddMonoidAlgebra`. -/
class GMul [Add ΞΉ] where
/-- The homogeneous multiplication map `mul` -/
mul {i j} : A i β A j β A (i + j)
/-- `GMul` implies `Mul (GradedMonoid A)`. -/
instance GMul.toMul [Add ΞΉ] [GMul A] : Mul (GradedMonoid A) :=
β¨fun x y : GradedMonoid A => β¨_, GMul.mul x.snd y.sndβ©β©
@[simp] theorem fst_mul [Add ΞΉ] [GMul A] (x y : GradedMonoid A) :
(x * y).fst = x.fst + y.fst := rfl
@[simp] theorem snd_mul [Add ΞΉ] [GMul A] (x y : GradedMonoid A) :
(x * y).snd = GMul.mul x.snd y.snd := rfl
theorem mk_mul_mk [Add ΞΉ] [GMul A] {i j} (a : A i) (b : A j) :
mk i a * mk j b = mk (i + j) (GMul.mul a b) :=
rfl
namespace GMonoid
variable {A}
variable [AddMonoid ΞΉ] [GMul A] [GOne A]
/-- A default implementation of power on a graded monoid, like `npowRec`.
`GMonoid.gnpow` should be used instead. -/
def gnpowRec : β (n : β) {i}, A i β A (n β’ i)
| 0, i, _ => cast (congr_arg A (zero_nsmul i).symm) GOne.one
| n + 1, i, a => cast (congr_arg A (succ_nsmul i n).symm) (GMul.mul (gnpowRec _ a) a)
@[simp]
theorem gnpowRec_zero (a : GradedMonoid A) : GradedMonoid.mk _ (gnpowRec 0 a.snd) = 1 :=
Sigma.ext (zero_nsmul _) (heq_of_cast_eq _ rfl).symm
@[simp]
theorem gnpowRec_succ (n : β) (a : GradedMonoid A) :
(GradedMonoid.mk _ <| gnpowRec n.succ a.snd) = β¨_, gnpowRec n a.sndβ© * a :=
Sigma.ext (succ_nsmul _ _) (heq_of_cast_eq _ rfl).symm
end GMonoid
/-- A tactic to for use as an optional value for `GMonoid.gnpow_zero'`. -/
macro "apply_gmonoid_gnpowRec_zero_tac" : tactic => `(tactic| apply GMonoid.gnpowRec_zero)
/-- A tactic to for use as an optional value for `GMonoid.gnpow_succ'`. -/
macro "apply_gmonoid_gnpowRec_succ_tac" : tactic => `(tactic| apply GMonoid.gnpowRec_succ)
/-- A graded version of `Monoid`
Like `Monoid.npow`, this has an optional `GMonoid.gnpow` field to allow definitional control of
natural powers of a graded monoid. -/
class GMonoid [AddMonoid ΞΉ] extends GMul A, GOne A where
/-- Multiplication by `one` on the left is the identity -/
one_mul (a : GradedMonoid A) : 1 * a = a
/-- Multiplication by `one` on the right is the identity -/
mul_one (a : GradedMonoid A) : a * 1 = a
/-- Multiplication is associative -/
mul_assoc (a b c : GradedMonoid A) : a * b * c = a * (b * c)
/-- Optional field to allow definitional control of natural powers -/
gnpow : β (n : β) {i}, A i β A (n β’ i) := GMonoid.gnpowRec
/-- The zeroth power will yield 1 -/
gnpow_zero' : β a : GradedMonoid A, GradedMonoid.mk _ (gnpow 0 a.snd) = 1 := by
apply_gmonoid_gnpowRec_zero_tac
/-- Successor powers behave as expected -/
gnpow_succ' :
β (n : β) (a : GradedMonoid A),
(GradedMonoid.mk _ <| gnpow n.succ a.snd) = β¨_, gnpow n a.sndβ© * a := by
apply_gmonoid_gnpowRec_succ_tac
/-- `GMonoid` implies a `Monoid (GradedMonoid A)`. -/
instance GMonoid.toMonoid [AddMonoid ΞΉ] [GMonoid A] : Monoid (GradedMonoid A) where
one := 1
mul := (Β· * Β·)
npow n a := GradedMonoid.mk _ (GMonoid.gnpow n a.snd)
npow_zero a := GMonoid.gnpow_zero' a
npow_succ n a := GMonoid.gnpow_succ' n a
one_mul := GMonoid.one_mul
mul_one := GMonoid.mul_one
mul_assoc := GMonoid.mul_assoc
@[simp] theorem fst_pow [AddMonoid ΞΉ] [GMonoid A] (x : GradedMonoid A) (n : β) :
(x ^ n).fst = n β’ x.fst := rfl
@[simp] theorem snd_pow [AddMonoid ΞΉ] [GMonoid A] (x : GradedMonoid A) (n : β) :
(x ^ n).snd = GMonoid.gnpow n x.snd := rfl
theorem mk_pow [AddMonoid ΞΉ] [GMonoid A] {i} (a : A i) (n : β) :
mk i a ^ n = mk (n β’ i) (GMonoid.gnpow _ a) := rfl
/-- A graded version of `CommMonoid`. -/
class GCommMonoid [AddCommMonoid ΞΉ] extends GMonoid A where
/-- Multiplication is commutative -/
mul_comm (a : GradedMonoid A) (b : GradedMonoid A) : a * b = b * a
/-- `GCommMonoid` implies a `CommMonoid (GradedMonoid A)`, although this is only used as an
instance locally to define notation in `gmonoid` and similar typeclasses. -/
instance GCommMonoid.toCommMonoid [AddCommMonoid ΞΉ] [GCommMonoid A] : CommMonoid (GradedMonoid A) :=
{ GMonoid.toMonoid A with mul_comm := GCommMonoid.mul_comm }
end Defs
/-! ### Instances for `A 0`
The various `g*` instances are enough to promote the `AddCommMonoid (A 0)` structure to various
types of multiplicative structure.
-/
section GradeZero
variable (A : ΞΉ β Type*)
section One
variable [Zero ΞΉ] [GOne A]
/-- `1 : A 0` is the value provided in `GOne.one`. -/
@[nolint unusedArguments]
instance GradeZero.one : One (A 0) :=
β¨GOne.oneβ©
end One
section Mul
variable [AddZeroClass ΞΉ] [GMul A]
/-- `(β’) : A 0 β A i β A i` is the value provided in `GradedMonoid.GMul.mul`, composed with
an `Eq.rec` to turn `A (0 + i)` into `A i`.
-/
instance GradeZero.smul (i : ΞΉ) : SMul (A 0) (A i) where
smul x y := @Eq.rec ΞΉ (0+i) (fun a _ => A a) (GMul.mul x y) i (zero_add i)
/-- `(*) : A 0 β A 0 β A 0` is the value provided in `GradedMonoid.GMul.mul`, composed with
an `Eq.rec` to turn `A (0 + 0)` into `A 0`.
-/
instance GradeZero.mul : Mul (A 0) where mul := (Β· β’ Β·)
variable {A}
@[simp]
theorem mk_zero_smul {i} (a : A 0) (b : A i) : mk _ (a β’ b) = mk _ a * mk _ b :=
Sigma.ext (zero_add _).symm <| eqRec_heq _ _
@[scoped simp]
theorem GradeZero.smul_eq_mul (a b : A 0) : a β’ b = a * b :=
rfl
end Mul
section Monoid
variable [AddMonoid ΞΉ] [GMonoid A]
instance : NatPow (A 0) where
pow x n := @Eq.rec ΞΉ (n β’ (0 : ΞΉ)) (fun a _ => A a) (GMonoid.gnpow n x) 0 (nsmul_zero n)
variable {A} in
@[simp]
theorem mk_zero_pow (a : A 0) (n : β) : mk _ (a ^ n) = mk _ a ^ n :=
Sigma.ext (nsmul_zero n).symm <| eqRec_heq _ _
/-- The `Monoid` structure derived from `GMonoid A`. -/
instance GradeZero.monoid : Monoid (A 0) :=
Function.Injective.monoid (mk 0) sigma_mk_injective rfl mk_zero_smul mk_zero_pow
end Monoid
section Monoid
variable [AddCommMonoid ΞΉ] [GCommMonoid A]
/-- The `CommMonoid` structure derived from `GCommMonoid A`. -/
instance GradeZero.commMonoid : CommMonoid (A 0) :=
Function.Injective.commMonoid (mk 0) sigma_mk_injective rfl mk_zero_smul mk_zero_pow
end Monoid
section MulAction
variable [AddMonoid ΞΉ] [GMonoid A]
/-- `GradedMonoid.mk 0` is a `MonoidHom`, using the `GradedMonoid.GradeZero.monoid` structure.
-/
def mkZeroMonoidHom : A 0 β* GradedMonoid A where
toFun := mk 0
map_one' := rfl
map_mul' := mk_zero_smul
/-- Each grade `A i` derives an `A 0`-action structure from `GMonoid A`. -/
instance GradeZero.mulAction {i} : MulAction (A 0) (A i) :=
letI := MulAction.compHom (GradedMonoid A) (mkZeroMonoidHom A)
Function.Injective.mulAction (mk i) sigma_mk_injective mk_zero_smul
end MulAction
end GradeZero
end GradedMonoid
/-! ### Dependent products of graded elements -/
section DProd
variable {Ξ± : Type*} {A : ΞΉ β Type*} [AddMonoid ΞΉ] [GradedMonoid.GMonoid A]
/-- The index used by `List.dProd`. Propositionally this is equal to `(l.map fΞΉ).Sum`, but
definitionally it needs to have a different form to avoid introducing `Eq.rec`s in `List.dProd`. -/
def List.dProdIndex (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) : ΞΉ :=
l.foldr (fun i b => fΞΉ i + b) 0
@[simp]
theorem List.dProdIndex_nil (fΞΉ : Ξ± β ΞΉ) : ([] : List Ξ±).dProdIndex fΞΉ = 0 :=
rfl
@[simp]
theorem List.dProdIndex_cons (a : Ξ±) (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) :
(a :: l).dProdIndex fΞΉ = fΞΉ a + l.dProdIndex fΞΉ :=
rfl
theorem List.dProdIndex_eq_map_sum (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) :
l.dProdIndex fΞΉ = (l.map fΞΉ).sum := by
match l with
| [] => simp
| head::tail => simp [List.dProdIndex_eq_map_sum tail fΞΉ]
/-- A dependent product for graded monoids represented by the indexed family of types `A i`.
This is a dependent version of `(l.map fA).prod`.
For a list `l : List Ξ±`, this computes the product of `fA a` over `a`, where each `fA` is of type
`A (fΞΉ a)`. -/
def List.dProd (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) (fA : β a, A (fΞΉ a)) : A (l.dProdIndex fΞΉ) :=
l.foldrRecOn _ GradedMonoid.GOne.one fun _ x a _ => GradedMonoid.GMul.mul (fA a) x
@[simp]
theorem List.dProd_nil (fΞΉ : Ξ± β ΞΉ) (fA : β a, A (fΞΉ a)) :
(List.nil : List Ξ±).dProd fΞΉ fA = GradedMonoid.GOne.one :=
rfl
-- the `( :)` in this lemma statement results in the type on the RHS not being unfolded, which
-- is nicer in the goal view.
@[simp]
theorem List.dProd_cons (fΞΉ : Ξ± β ΞΉ) (fA : β a, A (fΞΉ a)) (a : Ξ±) (l : List Ξ±) :
(a :: l).dProd fΞΉ fA = (GradedMonoid.GMul.mul (fA a) (l.dProd fΞΉ fA) :) :=
rfl
theorem GradedMonoid.mk_list_dProd (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) (fA : β a, A (fΞΉ a)) :
GradedMonoid.mk _ (l.dProd fΞΉ fA) = (l.map fun a => GradedMonoid.mk (fΞΉ a) (fA a)).prod := by
match l with
| [] => simp only [List.dProdIndex_nil, List.dProd_nil, List.map_nil, List.prod_nil]; rfl
| head::tail =>
simp [β GradedMonoid.mk_list_dProd tail _ _, GradedMonoid.mk_mul_mk, List.prod_cons]
/-- A variant of `GradedMonoid.mk_list_dProd` for rewriting in the other direction. -/
theorem GradedMonoid.list_prod_map_eq_dProd (l : List Ξ±) (f : Ξ± β GradedMonoid A) :
(l.map f).prod = GradedMonoid.mk _ (l.dProd (fun i => (f i).1) fun i => (f i).2) := by
rw [GradedMonoid.mk_list_dProd, GradedMonoid.mk]
simp_rw [Sigma.eta]
theorem GradedMonoid.list_prod_ofFn_eq_dProd {n : β} (f : Fin n β GradedMonoid A) :
(List.ofFn f).prod =
GradedMonoid.mk _ ((List.finRange n).dProd (fun i => (f i).1) fun i => (f i).2) := by
rw [List.ofFn_eq_map, GradedMonoid.list_prod_map_eq_dProd]
end DProd
/-! ### Concrete instances -/
section
variable (ΞΉ) {R : Type*}
@[simps one]
instance One.gOne [Zero ΞΉ] [One R] : GradedMonoid.GOne fun _ : ΞΉ => R where one := 1
@[simps mul]
instance Mul.gMul [Add ΞΉ] [Mul R] : GradedMonoid.GMul fun _ : ΞΉ => R where mul x y := x * y
/-- If all grades are the same type and themselves form a monoid, then there is a trivial grading
structure. -/
@[simps gnpow]
instance Monoid.gMonoid [AddMonoid ΞΉ] [Monoid R] : GradedMonoid.GMonoid fun _ : ΞΉ => R :=
-- { Mul.gMul ΞΉ, One.gOne ΞΉ with
{ One.gOne ΞΉ with
mul := fun x y => x * y
one_mul := fun _ => Sigma.ext (zero_add _) (heq_of_eq (one_mul _))
mul_one := fun _ => Sigma.ext (add_zero _) (heq_of_eq (mul_one _))
mul_assoc := fun _ _ _ => Sigma.ext (add_assoc _ _ _) (heq_of_eq (mul_assoc _ _ _))
gnpow := fun n _ a => a ^ n
gnpow_zero' := fun _ => Sigma.ext (zero_nsmul _) (heq_of_eq (Monoid.npow_zero _))
gnpow_succ' := fun _ β¨_, _β© => Sigma.ext (succ_nsmul _ _) (heq_of_eq (Monoid.npow_succ _ _)) }
/-- If all grades are the same type and themselves form a commutative monoid, then there is a
trivial grading structure. -/
instance CommMonoid.gCommMonoid [AddCommMonoid ΞΉ] [CommMonoid R] :
GradedMonoid.GCommMonoid fun _ : ΞΉ => R :=
{ Monoid.gMonoid ΞΉ with
mul_comm := fun _ _ => Sigma.ext (add_comm _ _) (heq_of_eq (mul_comm _ _)) }
/-- When all the indexed types are the same, the dependent product is just the regular product. -/
@[simp]
theorem List.dProd_monoid {Ξ±} [AddMonoid ΞΉ] [Monoid R] (l : List Ξ±) (fΞΉ : Ξ± β ΞΉ) (fA : Ξ± β R) :
@List.dProd _ _ (fun _ : ΞΉ => R) _ _ l fΞΉ fA = (l.map fA).prod := by
match l with
| [] =>
rw [List.dProd_nil, List.map_nil, List.prod_nil]
rfl
| head::tail =>
rw [List.dProd_cons, List.map_cons, List.prod_cons, List.dProd_monoid tail _ _]
rfl
end
/-! ### Shorthands for creating instance of the above typeclasses for collections of subobjects -/
section Subobjects
variable {R : Type*}
/-- A version of `GradedMonoid.GOne` for internally graded objects. -/
class SetLike.GradedOne {S : Type*} [SetLike S R] [One R] [Zero ΞΉ] (A : ΞΉ β S) : Prop where
/-- One has grade zero -/
one_mem : (1 : R) β A 0
theorem SetLike.one_mem_graded {S : Type*} [SetLike S R] [One R] [Zero ΞΉ] (A : ΞΉ β S)
[SetLike.GradedOne A] : (1 : R) β A 0 :=
SetLike.GradedOne.one_mem
instance SetLike.gOne {S : Type*} [SetLike S R] [One R] [Zero ΞΉ] (A : ΞΉ β S)
[SetLike.GradedOne A] : GradedMonoid.GOne fun i => A i where
one := β¨1, SetLike.one_mem_graded _β©
@[simp]
theorem SetLike.coe_gOne {S : Type*} [SetLike S R] [One R] [Zero ΞΉ] (A : ΞΉ β S)
[SetLike.GradedOne A] : β(@GradedMonoid.GOne.one _ (fun i => A i) _ _) = (1 : R) :=
rfl
/-- A version of `GradedMonoid.ghas_one` for internally graded objects. -/
class SetLike.GradedMul {S : Type*} [SetLike S R] [Mul R] [Add ΞΉ] (A : ΞΉ β S) : Prop where
/-- Multiplication is homogeneous -/
mul_mem : β β¦i jβ¦ {gi gj}, gi β A i β gj β A j β gi * gj β A (i + j)
theorem SetLike.mul_mem_graded {S : Type*} [SetLike S R] [Mul R] [Add ΞΉ] {A : ΞΉ β S}
[SetLike.GradedMul A] β¦i jβ¦ {gi gj} (hi : gi β A i) (hj : gj β A j) : gi * gj β A (i + j) :=
SetLike.GradedMul.mul_mem hi hj
instance SetLike.gMul {S : Type*} [SetLike S R] [Mul R] [Add ΞΉ] (A : ΞΉ β S)
[SetLike.GradedMul A] : GradedMonoid.GMul fun i => A i where
mul := fun a b => β¨(a * b : R), SetLike.mul_mem_graded a.prop b.propβ©
@[simp]
theorem SetLike.coe_gMul {S : Type*} [SetLike S R] [Mul R] [Add ΞΉ] (A : ΞΉ β S)
[SetLike.GradedMul A] {i j : ΞΉ} (x : A i) (y : A j) :
β(@GradedMonoid.GMul.mul _ (fun i => A i) _ _ _ _ x y) = (x * y : R) :=
rfl
/-- A version of `GradedMonoid.GMonoid` for internally graded objects. -/
class SetLike.GradedMonoid {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ΞΉ] (A : ΞΉ β S) : Prop
extends SetLike.GradedOne A, SetLike.GradedMul A
namespace SetLike
variable {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ΞΉ]
variable {A : ΞΉ β S} [SetLike.GradedMonoid A]
namespace GradeZero
variable (A) in
/-- The submonoid `A 0` of `R`. -/
@[simps]
def submonoid : Submonoid R where
carrier := A 0
mul_mem' ha hb := add_zero (0 : ΞΉ) βΈ SetLike.mul_mem_graded ha hb
one_mem' := SetLike.one_mem_graded A
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The monoid `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instMonoid : Monoid (A 0) := inferInstanceAs <| Monoid (GradeZero.submonoid A)
-- TODO: it might be expensive to unify `A` in this instances in practice
/-- The commutative monoid `A 0` inherited from `R` in the presence of `SetLike.GradedMonoid A`. -/
instance instCommMonoid
{R S : Type*} [SetLike S R] [CommMonoid R]
{A : ΞΉ β S} [SetLike.GradedMonoid A] :
CommMonoid (A 0) :=
inferInstanceAs <| CommMonoid (GradeZero.submonoid A)
@[simp, norm_cast] theorem coe_one : β(1 : A 0) = (1 : R) := rfl
@[simp, norm_cast] theorem coe_mul (a b : A 0) : β(a * b) = (βa * βb : R) := rfl
@[simp, norm_cast] theorem coe_pow (a : A 0) (n : β) : β(a ^ n) = (βa : R) ^ n := rfl
end GradeZero
theorem pow_mem_graded (n : β) {r : R} {i : ΞΉ} (h : r β A i) : r ^ n β A (n β’ i) := by
match n with
| 0 =>
rw [pow_zero, zero_nsmul]
exact one_mem_graded _
| n + 1 =>
rw [pow_succ', succ_nsmul']
exact mul_mem_graded h (pow_mem_graded n h)
theorem list_prod_map_mem_graded {ΞΉ'} (l : List ΞΉ') (i : ΞΉ' β ΞΉ) (r : ΞΉ' β R)
(h : β j β l, r j β A (i j)) : (l.map r).prod β A (l.map i).sum := by
match l with
| [] =>
rw [List.map_nil, List.map_nil, List.prod_nil, List.sum_nil]
exact one_mem_graded _
| head::tail =>
rw [List.map_cons, List.map_cons, List.prod_cons, List.sum_cons]
exact
mul_mem_graded (h _ List.mem_cons_self)
(list_prod_map_mem_graded tail _ _ fun j hj => h _ <| List.mem_cons_of_mem _ hj)
theorem list_prod_ofFn_mem_graded {n} (i : Fin n β ΞΉ) (r : Fin n β R) (h : β j, r j β A (i j)) :
(List.ofFn r).prod β A (List.ofFn i).sum := by
rw [List.ofFn_eq_map, List.ofFn_eq_map]
exact list_prod_map_mem_graded _ _ _ fun _ _ => h _
end SetLike
/-- Build a `GMonoid` instance for a collection of subobjects. -/
instance SetLike.gMonoid {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ΞΉ] (A : ΞΉ β S)
[SetLike.GradedMonoid A] : GradedMonoid.GMonoid fun i => A i :=
{ SetLike.gOne A,
SetLike.gMul A with
one_mul := fun β¨_, _, _β© => Sigma.subtype_ext (zero_add _) (one_mul _)
mul_one := fun β¨_, _, _β© => Sigma.subtype_ext (add_zero _) (mul_one _)
mul_assoc := fun β¨_, _, _β© β¨_, _, _β© β¨_, _, _β© =>
Sigma.subtype_ext (add_assoc _ _ _) (mul_assoc _ _ _)
gnpow := fun n _ a => β¨(a:R)^n, SetLike.pow_mem_graded n a.propβ©
gnpow_zero' := fun _ => Sigma.subtype_ext (zero_nsmul _) (pow_zero _)
gnpow_succ' := fun _ _ => Sigma.subtype_ext (succ_nsmul _ _) (pow_succ _ _) }
@[simp]
theorem SetLike.coe_gnpow {S : Type*} [SetLike S R] [Monoid R] [AddMonoid ΞΉ] (A : ΞΉ β S)
[SetLike.GradedMonoid A] {i : ΞΉ} (x : A i) (n : β) :
β(@GradedMonoid.GMonoid.gnpow _ (fun i => A i) _ _ n _ x) = (x:R)^n :=
rfl
/-- Build a `GCommMonoid` instance for a collection of subobjects. -/
instance SetLike.gCommMonoid {S : Type*} [SetLike S R] [CommMonoid R] [AddCommMonoid ΞΉ] (A : ΞΉ β S)
[SetLike.GradedMonoid A] : GradedMonoid.GCommMonoid fun i => A i :=
{ SetLike.gMonoid A with
mul_comm := fun β¨_, _, _β© β¨_, _, _β© => Sigma.subtype_ext (add_comm _ _) (mul_comm _ _) }
section DProd
open SetLike SetLike.GradedMonoid
variable {Ξ± S : Type*} [SetLike S R] [Monoid R] [AddMonoid ΞΉ]
@[simp]
theorem SetLike.coe_list_dProd (A : ΞΉ β S) [SetLike.GradedMonoid A] (fΞΉ : Ξ± β ΞΉ)
(fA : β a, A (fΞΉ a)) (l : List Ξ±) : β(@List.dProd _ _ (fun i => β₯(A i)) _ _ l fΞΉ fA)
= (List.prod (l.map fun a => fA a) : R) := by
match l with
| [] =>
rw [List.dProd_nil, coe_gOne, List.map_nil, List.prod_nil]
| head::tail =>
rw [List.dProd_cons, coe_gMul, List.map_cons, List.prod_cons,
SetLike.coe_list_dProd _ _ _ tail]
/-- A version of `List.coe_dProd_set_like` with `Subtype.mk`. -/
theorem SetLike.list_dProd_eq (A : ΞΉ β S) [SetLike.GradedMonoid A] (fΞΉ : Ξ± β ΞΉ) (fA : β a, A (fΞΉ a))
(l : List Ξ±) :
(@List.dProd _ _ (fun i => β₯(A i)) _ _ l fΞΉ fA) =
β¨List.prod (l.map fun a => fA a),
(l.dProdIndex_eq_map_sum fΞΉ).symm βΈ
list_prod_map_mem_graded l _ _ fun i _ => (fA i).propβ© :=
Subtype.ext <| SetLike.coe_list_dProd _ _ _ _
end DProd
end Subobjects
section HomogeneousElements
variable {R S : Type*} [SetLike S R]
/-- An element `a : R` is said to be homogeneous if there is some `i : ΞΉ` such that `a β A i`. -/
def SetLike.IsHomogeneousElem (A : ΞΉ β S) (a : R) : Prop :=
β i, a β A i
@[simp]
theorem SetLike.isHomogeneousElem_coe {A : ΞΉ β S} {i} (x : A i) :
SetLike.IsHomogeneousElem A (x : R) :=
β¨i, x.propβ©
theorem SetLike.isHomogeneousElem_one [Zero ΞΉ] [One R] (A : ΞΉ β S) [SetLike.GradedOne A] :
SetLike.IsHomogeneousElem A (1 : R) :=
β¨0, SetLike.one_mem_graded _β©
theorem SetLike.IsHomogeneousElem.mul [Add ΞΉ] [Mul R] {A : ΞΉ β S} [SetLike.GradedMul A] {a b : R} :
SetLike.IsHomogeneousElem A a β SetLike.IsHomogeneousElem A b β
SetLike.IsHomogeneousElem A (a * b)
| β¨i, hiβ©, β¨j, hjβ© => β¨i + j, SetLike.mul_mem_graded hi hjβ©
/-- When `A` is a `SetLike.GradedMonoid A`, then the homogeneous elements forms a submonoid. -/
def SetLike.homogeneousSubmonoid [AddMonoid ΞΉ] [Monoid R] (A : ΞΉ β S) [SetLike.GradedMonoid A] :
Submonoid R where
carrier := { a | SetLike.IsHomogeneousElem A a }
one_mem' := SetLike.isHomogeneousElem_one A
mul_mem' a b := SetLike.IsHomogeneousElem.mul a b
end HomogeneousElements
section CommMonoid
namespace SetLike
variable {ΞΉ R S : Type*} [SetLike S R] [CommMonoid R] [AddCommMonoid ΞΉ]
variable (A : ΞΉ β S) [SetLike.GradedMonoid A]
variable {ΞΊ : Type*} (i : ΞΊ β ΞΉ) (g : ΞΊ β R) {F : Finset ΞΊ}
theorem prod_mem_graded (hF : β k β F, g k β A (i k)) : β k β F, g k β A (β k β F, i k) := by
classical
induction F using Finset.induction_on
Β· simp [GradedOne.one_mem]
Β· case insert j F' hF2 h3 =>
rw [Finset.prod_insert hF2, Finset.sum_insert hF2]
apply SetLike.mul_mem_graded (by grind)
grind
theorem prod_pow_mem_graded (n : ΞΊ β β) (hF : β k β F, g k β A (i k)) :
β k β F, g k ^ n k β A (β k β F, n k β’ i k) :=
prod_mem_graded A _ _ fun k hk β¦ pow_mem_graded _ (hF k hk)
end SetLike
end CommMonoid
|
Rotation.lean
|
/-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Heather Macbeth
-/
import Mathlib.Analysis.SpecialFunctions.Complex.Circle
import Mathlib.Geometry.Euclidean.Angle.Oriented.Basic
/-!
# Rotations by oriented angles.
This file defines rotations by oriented angles in real inner product spaces.
## Main definitions
* `Orientation.rotation` is the rotation by an oriented angle with respect to an orientation.
-/
noncomputable section
open Module Complex
open scoped Real RealInnerProductSpace ComplexConjugate
namespace Orientation
attribute [local instance] Complex.finrank_real_complex_fact
variable {V V' : Type*}
variable [NormedAddCommGroup V] [NormedAddCommGroup V']
variable [InnerProductSpace β V] [InnerProductSpace β V']
variable [Fact (finrank β V = 2)] [Fact (finrank β V' = 2)] (o : Orientation β V (Fin 2))
local notation "J" => o.rightAngleRotation
/-- Auxiliary construction to build a rotation by the oriented angle `ΞΈ`. -/
def rotationAux (ΞΈ : Real.Angle) : V ββα΅’[β] V :=
LinearMap.isometryOfInner
(Real.Angle.cos ΞΈ β’ LinearMap.id +
Real.Angle.sin ΞΈ β’ (LinearIsometryEquiv.toLinearEquiv J).toLinearMap)
(by
intro x y
simp only [RCLike.conj_to_real, id, LinearMap.smul_apply, LinearMap.add_apply,
LinearMap.id_coe, LinearEquiv.coe_coe, LinearIsometryEquiv.coe_toLinearEquiv,
Orientation.areaForm_rightAngleRotation_left, Orientation.inner_rightAngleRotation_left,
Orientation.inner_rightAngleRotation_right, inner_add_left, inner_smul_left,
inner_add_right, inner_smul_right]
linear_combination βͺx, yβ« * ΞΈ.cos_sq_add_sin_sq)
@[simp]
theorem rotationAux_apply (ΞΈ : Real.Angle) (x : V) :
o.rotationAux ΞΈ x = Real.Angle.cos ΞΈ β’ x + Real.Angle.sin ΞΈ β’ J x :=
rfl
/-- A rotation by the oriented angle `ΞΈ`. -/
def rotation (ΞΈ : Real.Angle) : V ββα΅’[β] V :=
LinearIsometryEquiv.ofLinearIsometry (o.rotationAux ΞΈ)
(Real.Angle.cos ΞΈ β’ LinearMap.id -
Real.Angle.sin ΞΈ β’ (LinearIsometryEquiv.toLinearEquiv J).toLinearMap)
(by
ext x
convert congr_arg (fun t : β => t β’ x) ΞΈ.cos_sq_add_sin_sq using 1
Β· simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply,
Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap,
LinearIsometryEquiv.coe_toLinearEquiv, map_smul, map_sub, LinearMap.coe_comp,
LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply]
module
Β· simp)
(by
ext x
convert congr_arg (fun t : β => t β’ x) ΞΈ.cos_sq_add_sin_sq using 1
Β· simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply,
Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap,
LinearIsometryEquiv.coe_toLinearEquiv, map_add, map_smul, LinearMap.coe_comp,
LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply]
module
Β· simp)
theorem rotation_apply (ΞΈ : Real.Angle) (x : V) :
o.rotation ΞΈ x = Real.Angle.cos ΞΈ β’ x + Real.Angle.sin ΞΈ β’ J x :=
rfl
theorem rotation_symm_apply (ΞΈ : Real.Angle) (x : V) :
(o.rotation ΞΈ).symm x = Real.Angle.cos ΞΈ β’ x - Real.Angle.sin ΞΈ β’ J x :=
rfl
theorem rotation_eq_matrix_toLin (ΞΈ : Real.Angle) {x : V} (hx : x β 0) :
(o.rotation ΞΈ).toLinearMap =
Matrix.toLin (o.basisRightAngleRotation x hx) (o.basisRightAngleRotation x hx)
!![ΞΈ.cos, -ΞΈ.sin; ΞΈ.sin, ΞΈ.cos] := by
apply (o.basisRightAngleRotation x hx).ext
intro i
fin_cases i
Β· rw [Matrix.toLin_self]
simp [rotation_apply, Fin.sum_univ_succ]
Β· rw [Matrix.toLin_self]
simp [rotation_apply, Fin.sum_univ_succ, add_comm]
/-- The determinant of `rotation` (as a linear map) is equal to `1`. -/
@[simp]
theorem det_rotation (ΞΈ : Real.Angle) : LinearMap.det (o.rotation ΞΈ).toLinearMap = 1 := by
haveI : Nontrivial V := nontrivial_of_finrank_eq_succ (@Fact.out (finrank β V = 2) _)
obtain β¨x, hxβ© : β x, x β (0 : V) := exists_ne (0 : V)
rw [o.rotation_eq_matrix_toLin ΞΈ hx]
simpa [sq] using ΞΈ.cos_sq_add_sin_sq
/-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/
@[simp]
theorem linearEquiv_det_rotation (ΞΈ : Real.Angle) :
LinearEquiv.det (o.rotation ΞΈ).toLinearEquiv = 1 :=
Units.ext <| by
-- Porting note: Lean can't see through `LinearEquiv.coe_det` and needed the rewrite
-- in mathlib3 this was just `units.ext <| o.det_rotation ΞΈ`
simpa only [LinearEquiv.coe_det, Units.val_one] using o.det_rotation ΞΈ
/-- The inverse of `rotation` is rotation by the negation of the angle. -/
@[simp]
theorem rotation_symm (ΞΈ : Real.Angle) : (o.rotation ΞΈ).symm = o.rotation (-ΞΈ) := by
ext; simp [o.rotation_apply, o.rotation_symm_apply, sub_eq_add_neg]
/-- Rotation by 0 is the identity. -/
@[simp]
theorem rotation_zero : o.rotation 0 = LinearIsometryEquiv.refl β V := by ext; simp [rotation]
/-- Rotation by Ο is negation. -/
@[simp]
theorem rotation_pi : o.rotation Ο = LinearIsometryEquiv.neg β := by
ext x
simp [rotation]
/-- Rotation by Ο is negation. -/
theorem rotation_pi_apply (x : V) : o.rotation Ο x = -x := by simp
/-- Rotation by Ο / 2 is the "right-angle-rotation" map `J`. -/
theorem rotation_pi_div_two : o.rotation (Ο / 2 : β) = J := by
ext x
simp [rotation]
/-- Rotating twice is equivalent to rotating by the sum of the angles. -/
@[simp]
theorem rotation_rotation (ΞΈβ ΞΈβ : Real.Angle) (x : V) :
o.rotation ΞΈβ (o.rotation ΞΈβ x) = o.rotation (ΞΈβ + ΞΈβ) x := by
simp only [o.rotation_apply, Real.Angle.cos_add, Real.Angle.sin_add, LinearIsometryEquiv.map_add,
map_smul, rightAngleRotation_rightAngleRotation]
module
/-- Rotating twice is equivalent to rotating by the sum of the angles. -/
@[simp]
theorem rotation_trans (ΞΈβ ΞΈβ : Real.Angle) :
(o.rotation ΞΈβ).trans (o.rotation ΞΈβ) = o.rotation (ΞΈβ + ΞΈβ) :=
LinearIsometryEquiv.ext fun _ => by rw [β rotation_rotation, LinearIsometryEquiv.trans_apply]
/-- Rotating the first of two vectors by `ΞΈ` scales their Kahler form by `cos ΞΈ - sin ΞΈ * I`. -/
@[simp]
theorem kahler_rotation_left (x y : V) (ΞΈ : Real.Angle) :
o.kahler (o.rotation ΞΈ x) y = conj (ΞΈ.toCircle : β) * o.kahler x y := by
-- Porting note: this needed the `Complex.conj_ofReal` instead of `RCLike.conj_ofReal`;
-- I believe this is because the respective coercions are no longer defeq, and
-- `Real.Angle.coe_toCircle` uses the `Complex` version.
simp only [o.rotation_apply, map_add, map_mul, LinearMap.map_smulββ, RingHom.id_apply,
LinearMap.add_apply, LinearMap.smul_apply, real_smul, kahler_rightAngleRotation_left,
Real.Angle.coe_toCircle, Complex.conj_ofReal, conj_I]
ring
/-- Negating a rotation is equivalent to rotation by Ο plus the angle. -/
theorem neg_rotation (ΞΈ : Real.Angle) (x : V) : -o.rotation ΞΈ x = o.rotation (Ο + ΞΈ) x := by
rw [β o.rotation_pi_apply, rotation_rotation]
/-- Negating a rotation by -Ο / 2 is equivalent to rotation by Ο / 2. -/
@[simp]
theorem neg_rotation_neg_pi_div_two (x : V) :
-o.rotation (-Ο / 2 : β) x = o.rotation (Ο / 2 : β) x := by
rw [neg_rotation, β Real.Angle.coe_add, neg_div, β sub_eq_add_neg, sub_half]
/-- Negating a rotation by Ο / 2 is equivalent to rotation by -Ο / 2. -/
theorem neg_rotation_pi_div_two (x : V) : -o.rotation (Ο / 2 : β) x = o.rotation (-Ο / 2 : β) x :=
(neg_eq_iff_eq_neg.mp <| o.neg_rotation_neg_pi_div_two _).symm
/-- Rotating the first of two vectors by `ΞΈ` scales their Kahler form by `cos (-ΞΈ) + sin (-ΞΈ) * I`.
-/
theorem kahler_rotation_left' (x y : V) (ΞΈ : Real.Angle) :
o.kahler (o.rotation ΞΈ x) y = (-ΞΈ).toCircle * o.kahler x y := by
simp only [Real.Angle.toCircle_neg, Circle.coe_inv_eq_conj, kahler_rotation_left]
/-- Rotating the second of two vectors by `ΞΈ` scales their Kahler form by `cos ΞΈ + sin ΞΈ * I`. -/
@[simp]
theorem kahler_rotation_right (x y : V) (ΞΈ : Real.Angle) :
o.kahler x (o.rotation ΞΈ y) = ΞΈ.toCircle * o.kahler x y := by
simp only [o.rotation_apply, map_add, LinearMap.map_smulββ, RingHom.id_apply, real_smul,
kahler_rightAngleRotation_right, Real.Angle.coe_toCircle]
ring
/-- Rotating the first vector by `ΞΈ` subtracts `ΞΈ` from the angle between two vectors. -/
@[simp]
theorem oangle_rotation_left {x y : V} (hx : x β 0) (hy : y β 0) (ΞΈ : Real.Angle) :
o.oangle (o.rotation ΞΈ x) y = o.oangle x y - ΞΈ := by
simp only [oangle, o.kahler_rotation_left']
rw [Complex.arg_mul_coe_angle, Real.Angle.arg_toCircle]
Β· abel
Β· exact Circle.coe_ne_zero _
Β· exact o.kahler_ne_zero hx hy
/-- Rotating the second vector by `ΞΈ` adds `ΞΈ` to the angle between two vectors. -/
@[simp]
theorem oangle_rotation_right {x y : V} (hx : x β 0) (hy : y β 0) (ΞΈ : Real.Angle) :
o.oangle x (o.rotation ΞΈ y) = o.oangle x y + ΞΈ := by
simp only [oangle, o.kahler_rotation_right]
rw [Complex.arg_mul_coe_angle, Real.Angle.arg_toCircle]
Β· abel
Β· exact Circle.coe_ne_zero _
Β· exact o.kahler_ne_zero hx hy
/-- The rotation of a vector by `ΞΈ` has an angle of `-ΞΈ` from that vector. -/
theorem oangle_rotation_self_left {x : V} (hx : x β 0) (ΞΈ : Real.Angle) :
o.oangle (o.rotation ΞΈ x) x = -ΞΈ := by simp [hx]
/-- A vector has an angle of `ΞΈ` from the rotation of that vector by `ΞΈ`. -/
theorem oangle_rotation_self_right {x : V} (hx : x β 0) (ΞΈ : Real.Angle) :
o.oangle x (o.rotation ΞΈ x) = ΞΈ := by simp [hx]
/-- Rotating the first vector by the angle between the two vectors results in an angle of 0. -/
@[simp]
theorem oangle_rotation_oangle_left (x y : V) : o.oangle (o.rotation (o.oangle x y) x) y = 0 := by
by_cases hx : x = 0
Β· simp [hx]
Β· by_cases hy : y = 0
Β· simp [hy]
Β· simp [hx, hy]
/-- Rotating the first vector by the angle between the two vectors and swapping the vectors
results in an angle of 0. -/
@[simp]
theorem oangle_rotation_oangle_right (x y : V) : o.oangle y (o.rotation (o.oangle x y) x) = 0 := by
rw [oangle_rev]
simp
/-- Rotating both vectors by the same angle does not change the angle between those vectors. -/
@[simp]
theorem oangle_rotation (x y : V) (ΞΈ : Real.Angle) :
o.oangle (o.rotation ΞΈ x) (o.rotation ΞΈ y) = o.oangle x y := by
by_cases hx : x = 0 <;> by_cases hy : y = 0 <;> simp [hx, hy]
/-- A rotation of a nonzero vector equals that vector if and only if the angle is zero. -/
@[simp]
theorem rotation_eq_self_iff_angle_eq_zero {x : V} (hx : x β 0) (ΞΈ : Real.Angle) :
o.rotation ΞΈ x = x β ΞΈ = 0 := by
constructor
Β· intro h
rw [eq_comm]
simpa [hx, h] using o.oangle_rotation_right hx hx ΞΈ
Β· intro h
simp [h]
/-- A nonzero vector equals a rotation of that vector if and only if the angle is zero. -/
@[simp]
theorem eq_rotation_self_iff_angle_eq_zero {x : V} (hx : x β 0) (ΞΈ : Real.Angle) :
x = o.rotation ΞΈ x β ΞΈ = 0 := by rw [β o.rotation_eq_self_iff_angle_eq_zero hx, eq_comm]
/-- A rotation of a vector equals that vector if and only if the vector or the angle is zero. -/
theorem rotation_eq_self_iff (x : V) (ΞΈ : Real.Angle) : o.rotation ΞΈ x = x β x = 0 β¨ ΞΈ = 0 := by
by_cases h : x = 0 <;> simp [h]
/-- A vector equals a rotation of that vector if and only if the vector or the angle is zero. -/
theorem eq_rotation_self_iff (x : V) (ΞΈ : Real.Angle) : x = o.rotation ΞΈ x β x = 0 β¨ ΞΈ = 0 := by
rw [β rotation_eq_self_iff, eq_comm]
/-- Rotating a vector by the angle to another vector gives the second vector if and only if the
norms are equal. -/
@[simp]
theorem rotation_oangle_eq_iff_norm_eq (x y : V) : o.rotation (o.oangle x y) x = y β βxβ = βyβ := by
constructor
Β· intro h
rw [β h, LinearIsometryEquiv.norm_map]
Β· intro h
rw [o.eq_iff_oangle_eq_zero_of_norm_eq] <;> simp [h]
/-- The angle between two nonzero vectors is `ΞΈ` if and only if the second vector is the first
rotated by `ΞΈ` and scaled by the ratio of the norms. -/
theorem oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero {x y : V} (hx : x β 0) (hy : y β 0)
(ΞΈ : Real.Angle) : o.oangle x y = ΞΈ β y = (βyβ / βxβ) β’ o.rotation ΞΈ x := by
have hp := div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx)
constructor
Β· rintro rfl
rw [β LinearIsometryEquiv.map_smul, β o.oangle_smul_left_of_pos x y hp, eq_comm,
rotation_oangle_eq_iff_norm_eq, norm_smul, Real.norm_of_nonneg hp.le,
div_mul_cancelβ _ (norm_ne_zero_iff.2 hx)]
Β· intro hye
rw [hye, o.oangle_smul_right_of_pos _ _ hp, o.oangle_rotation_self_right hx]
/-- The angle between two nonzero vectors is `ΞΈ` if and only if the second vector is the first
rotated by `ΞΈ` and scaled by a positive real. -/
theorem oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero {x y : V} (hx : x β 0) (hy : y β 0)
(ΞΈ : Real.Angle) : o.oangle x y = ΞΈ β β r : β, 0 < r β§ y = r β’ o.rotation ΞΈ x := by
constructor
Β· intro h
rw [o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy] at h
exact β¨βyβ / βxβ, div_pos (norm_pos_iff.2 hy) (norm_pos_iff.2 hx), hβ©
Β· rintro β¨r, hr, rflβ©
rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx]
/-- The angle between two vectors is `ΞΈ` if and only if they are nonzero and the second vector
is the first rotated by `ΞΈ` and scaled by the ratio of the norms, or `ΞΈ` and at least one of the
vectors are zero. -/
theorem oangle_eq_iff_eq_norm_div_norm_smul_rotation_or_eq_zero {x y : V} (ΞΈ : Real.Angle) :
o.oangle x y = ΞΈ β
x β 0 β§ y β 0 β§ y = (βyβ / βxβ) β’ o.rotation ΞΈ x β¨ ΞΈ = 0 β§ (x = 0 β¨ y = 0) := by
by_cases hx : x = 0
Β· simp [hx, eq_comm]
Β· by_cases hy : y = 0
Β· simp [hy, eq_comm]
Β· rw [o.oangle_eq_iff_eq_norm_div_norm_smul_rotation_of_ne_zero hx hy]
simp [hx, hy]
/-- The angle between two vectors is `ΞΈ` if and only if they are nonzero and the second vector
is the first rotated by `ΞΈ` and scaled by a positive real, or `ΞΈ` and at least one of the
vectors are zero. -/
theorem oangle_eq_iff_eq_pos_smul_rotation_or_eq_zero {x y : V} (ΞΈ : Real.Angle) :
o.oangle x y = ΞΈ β
(x β 0 β§ y β 0 β§ β r : β, 0 < r β§ y = r β’ o.rotation ΞΈ x) β¨ ΞΈ = 0 β§ (x = 0 β¨ y = 0) := by
by_cases hx : x = 0
Β· simp [hx, eq_comm]
Β· by_cases hy : y = 0
Β· simp [hy, eq_comm]
Β· rw [o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero hx hy]
simp [hx, hy]
/-- Any linear isometric equivalence in `V` with positive determinant is `rotation`. -/
theorem exists_linearIsometryEquiv_eq_of_det_pos {f : V ββα΅’[β] V}
(hd : 0 < LinearMap.det (f.toLinearEquiv : V ββ[β] V)) :
β ΞΈ : Real.Angle, f = o.rotation ΞΈ := by
haveI : Nontrivial V := nontrivial_of_finrank_eq_succ (@Fact.out (finrank β V = 2) _)
obtain β¨x, hxβ© : β x, x β (0 : V) := exists_ne (0 : V)
use o.oangle x (f x)
apply LinearIsometryEquiv.toLinearEquiv_injective
apply LinearEquiv.toLinearMap_injective
apply (o.basisRightAngleRotation x hx).ext
intro i
symm
fin_cases i
Β· simp
have : o.oangle (J x) (f (J x)) = o.oangle x (f x) := by
simp only [oangle, o.linearIsometryEquiv_comp_rightAngleRotation f hd,
o.kahler_comp_rightAngleRotation]
simp [β this]
theorem rotation_map (ΞΈ : Real.Angle) (f : V ββα΅’[β] V') (x : V') :
(Orientation.map (Fin 2) f.toLinearEquiv o).rotation ΞΈ x = f (o.rotation ΞΈ (f.symm x)) := by
simp [rotation_apply, o.rightAngleRotation_map]
@[simp]
protected theorem _root_.Complex.rotation (ΞΈ : Real.Angle) (z : β) :
Complex.orientation.rotation ΞΈ z = ΞΈ.toCircle * z := by
simp only [rotation_apply, Complex.rightAngleRotation, Real.Angle.coe_toCircle, real_smul]
ring
/-- Rotation in an oriented real inner product space of dimension 2 can be evaluated in terms of a
complex-number representation of the space. -/
theorem rotation_map_complex (ΞΈ : Real.Angle) (f : V ββα΅’[β] β)
(hf : Orientation.map (Fin 2) f.toLinearEquiv o = Complex.orientation) (x : V) :
f (o.rotation ΞΈ x) = ΞΈ.toCircle * f x := by
rw [β Complex.rotation, β hf, o.rotation_map, LinearIsometryEquiv.symm_apply_apply]
/-- Negating the orientation negates the angle in `rotation`. -/
theorem rotation_neg_orientation_eq_neg (ΞΈ : Real.Angle) : (-o).rotation ΞΈ = o.rotation (-ΞΈ) :=
LinearIsometryEquiv.ext <| by simp [rotation_apply]
/-- The inner product between a `Ο / 2` rotation of a vector and that vector is zero. -/
@[simp]
theorem inner_rotation_pi_div_two_left (x : V) : βͺo.rotation (Ο / 2 : β) x, xβ« = 0 := by
rw [rotation_pi_div_two, inner_rightAngleRotation_self]
/-- The inner product between a vector and a `Ο / 2` rotation of that vector is zero. -/
@[simp]
theorem inner_rotation_pi_div_two_right (x : V) : βͺx, o.rotation (Ο / 2 : β) xβ« = 0 := by
rw [real_inner_comm, inner_rotation_pi_div_two_left]
/-- The inner product between a multiple of a `Ο / 2` rotation of a vector and that vector is
zero. -/
@[simp]
theorem inner_smul_rotation_pi_div_two_left (x : V) (r : β) :
βͺr β’ o.rotation (Ο / 2 : β) x, xβ« = 0 := by
rw [inner_smul_left, inner_rotation_pi_div_two_left, mul_zero]
/-- The inner product between a vector and a multiple of a `Ο / 2` rotation of that vector is
zero. -/
@[simp]
theorem inner_smul_rotation_pi_div_two_right (x : V) (r : β) :
βͺx, r β’ o.rotation (Ο / 2 : β) xβ« = 0 := by
rw [real_inner_comm, inner_smul_rotation_pi_div_two_left]
/-- The inner product between a `Ο / 2` rotation of a vector and a multiple of that vector is
zero. -/
@[simp]
theorem inner_rotation_pi_div_two_left_smul (x : V) (r : β) :
βͺo.rotation (Ο / 2 : β) x, r β’ xβ« = 0 := by
rw [inner_smul_right, inner_rotation_pi_div_two_left, mul_zero]
/-- The inner product between a multiple of a vector and a `Ο / 2` rotation of that vector is
zero. -/
@[simp]
theorem inner_rotation_pi_div_two_right_smul (x : V) (r : β) :
βͺr β’ x, o.rotation (Ο / 2 : β) xβ« = 0 := by
rw [real_inner_comm, inner_rotation_pi_div_two_left_smul]
/-- The inner product between a multiple of a `Ο / 2` rotation of a vector and a multiple of
that vector is zero. -/
@[simp]
theorem inner_smul_rotation_pi_div_two_smul_left (x : V) (rβ rβ : β) :
βͺrβ β’ o.rotation (Ο / 2 : β) x, rβ β’ xβ« = 0 := by
rw [inner_smul_right, inner_smul_rotation_pi_div_two_left, mul_zero]
/-- The inner product between a multiple of a vector and a multiple of a `Ο / 2` rotation of
that vector is zero. -/
@[simp]
theorem inner_smul_rotation_pi_div_two_smul_right (x : V) (rβ rβ : β) :
βͺrβ β’ x, rβ β’ o.rotation (Ο / 2 : β) xβ« = 0 := by
rw [real_inner_comm, inner_smul_rotation_pi_div_two_smul_left]
/-- The inner product between two vectors is zero if and only if the first vector is zero or
the second is a multiple of a `Ο / 2` rotation of that vector. -/
theorem inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two {x y : V} :
βͺx, yβ« = 0 β x = 0 β¨ β r : β, r β’ o.rotation (Ο / 2 : β) x = y := by
rw [β o.eq_zero_or_oangle_eq_iff_inner_eq_zero]
refine β¨fun h => ?_, fun h => ?_β©
Β· rcases h with (rfl | rfl | h | h)
Β· exact Or.inl rfl
Β· exact Or.inr β¨0, zero_smul _ _β©
Β· obtain β¨r, _, rflβ© :=
(o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero (o.left_ne_zero_of_oangle_eq_pi_div_two h)
(o.right_ne_zero_of_oangle_eq_pi_div_two h) _).1 h
exact Or.inr β¨r, rflβ©
Β· obtain β¨r, _, rflβ© :=
(o.oangle_eq_iff_eq_pos_smul_rotation_of_ne_zero
(o.left_ne_zero_of_oangle_eq_neg_pi_div_two h)
(o.right_ne_zero_of_oangle_eq_neg_pi_div_two h) _).1 h
refine Or.inr β¨-r, ?_β©
rw [neg_smul, β smul_neg, o.neg_rotation_pi_div_two]
Β· rcases h with (rfl | β¨r, rflβ©)
Β· exact Or.inl rfl
Β· by_cases hx : x = 0; Β· exact Or.inl hx
rcases lt_trichotomy r 0 with (hr | rfl | hr)
Β· refine Or.inr (Or.inr (Or.inr ?_))
rw [o.oangle_smul_right_of_neg _ _ hr, o.neg_rotation_pi_div_two,
o.oangle_rotation_self_right hx]
Β· exact Or.inr (Or.inl (zero_smul _ _))
Β· refine Or.inr (Or.inr (Or.inl ?_))
rw [o.oangle_smul_right_of_pos _ _ hr, o.oangle_rotation_self_right hx]
end Orientation
|
preorder.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.
(******************************************************************************)
(* Types equipped with order relations *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file and order.v define types equipped with order relations. *)
(* *)
(* * How to use preorders in MathComp? *)
(* Use the module PreorderTheory implementing the theories (located in the *)
(* module Order):$ *)
(* 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: *)
(* *)
(* preorderType d == the type of preordered types *)
(* The HB class is called Preorder. *)
(* bPreorderType d == preorderType with a bottom element (\bot) *)
(* The HB class is called BPreorder. *)
(* tPreorderType d == preorderType with a top element (\top) *)
(* The HB class is called TPreorder. *)
(* tbPreorderType d == preorderType with both a top and a bottom *)
(* The HB class is called TBPreorder. *)
(* finPreorderType d == the type of partially preordered finite types *)
(* The HB class is called FinPreorder. *)
(* finBPreorderType d == finPreorderType with a bottom element *)
(* The HB class is called FinBPreorder. *)
(* finTPreorderType d == finPreorderType with a top element *)
(* The HB class is called FinTPreorder. *)
(* finTBPreorderType d == finPreorderType with both a top and a bottom *)
(* The HB class is called FinTBPreorder. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subPreorder d T P d' == join of preorderType d' and subType *)
(* (P : pred T) such that val is monotonic *)
(* The HB class is called SubPreorder. *)
(* *)
(* Morphisms between the above structures: *)
(* *)
(* OrderMorphism.type d T d' T' == nondecreasing function between the two *)
(* preorder *)
(* := {omorphism T -> T'} *)
(* *)
(* TODO: Check this section * 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 preorderType 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 bPreorderType d: *)
(* \bot := @Order.bottom d T *)
(* == the bottom element of type T *)
(* For T of type tPreorderType d: *)
(* \top := @Order.top d T *)
(* == the top element of type T *)
(* *)
(* 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_isSubPreorder of U by <: with disp] == *)
(* [SubChoice_isSubPreorder of U by <:] == preorderType mixin for a subType *)
(* whose base type is a preorderType *)
(* *)
(* 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 Notation "<= y" (at level 35).
Reserved Notation ">= y" (at level 35).
Reserved Notation "< y" (at level 35).
Reserved Notation "> y" (at level 35).
Reserved Notation "<= y :> T" (at level 35, y at next level).
Reserved Notation ">= y :> T" (at level 35, y at next level).
Reserved Notation "< y :> T" (at level 35, y at next level).
Reserved Notation "> y :> T" (at level 35, y at next level).
Reserved Notation "x >=< y" (at level 70, no associativity).
Reserved Notation ">=< y" (at level 35).
Reserved Notation ">=< y :> T" (at level 35, y at next level).
Reserved Notation "x >< y" (at level 70, no associativity).
Reserved Notation ">< x" (at level 35).
Reserved Notation ">< y :> T" (at level 35, y at next level).
Reserved Notation "f \min g" (at level 50, left associativity).
Reserved Notation "f \max g" (at level 50, left associativity).
Reserved Notation "x < y ?<= 'if' c" (c at next level,
format "x '[hv' < y '/' ?<= 'if' c ']'").
Reserved Notation "x < y ?<= 'if' c :> T" (
format "x '[hv' < y '/' ?<= 'if' c :> T ']'").
(* Reserved notations for bottom/top elements *)
Reserved Notation "\bot".
Reserved Notation "\top".
(* Reserved notations for dual order *)
Reserved Notation "x <=^d y" (at level 70, y at next level).
Reserved Notation "x >=^d y" (at level 70, y at next level).
Reserved Notation "x <^d y" (at level 70, y at next level).
Reserved Notation "x >^d y" (at level 70, y at next level).
Reserved Notation "x <=^d y :> T" (at level 70, y at next level).
Reserved Notation "x >=^d y :> T" (at level 70, y at next level).
Reserved Notation "x <^d y :> T" (at level 70, y at next level).
Reserved Notation "x >^d y :> T" (at level 70, y at next level).
Reserved Notation "<=^d y" (at level 35).
Reserved Notation ">=^d y" (at level 35).
Reserved Notation "<^d y" (at level 35).
Reserved Notation ">^d y" (at level 35).
Reserved Notation "<=^d y :> T" (at level 35, y at next level).
Reserved Notation ">=^d y :> T" (at level 35, y at next level).
Reserved Notation "<^d y :> T" (at level 35, y at next level).
Reserved Notation ">^d y :> T" (at level 35, y at next level).
Reserved Notation "x >=<^d y" (at level 70, no associativity).
Reserved Notation ">=<^d y" (at level 35).
Reserved Notation ">=<^d y :> T" (at level 35, y at next level).
Reserved Notation "x ><^d y" (at level 70, no associativity).
Reserved Notation "><^d x" (at level 35).
Reserved Notation "><^d y :> T" (at level 35, y at next level).
Reserved Notation "x <=^d y <=^d z" (at level 70, y, z at next level).
Reserved Notation "x <^d y <=^d z" (at level 70, y, z at next level).
Reserved Notation "x <=^d y <^d z" (at level 70, y, z at next level).
Reserved Notation "x <^d y <^d z" (at level 70, y, z at next level).
Reserved Notation "x <=^d y ?= 'iff' c" (at level 70, y, c at next level,
format "x '[hv' <=^d y '/' ?= 'iff' c ']'").
Reserved Notation "x <=^d y ?= 'iff' c :> T" (at level 70, y, c at next level,
format "x '[hv' <=^d y '/' ?= 'iff' c :> T ']'").
Reserved Notation "x <^d y ?<= 'if' c" (at level 70, y, c at next level,
format "x '[hv' <^d y '/' ?<= 'if' c ']'").
Reserved Notation "x <^d y ?<= 'if' c :> T" (at level 70, y, c at next level,
format "x '[hv' <^d y '/' ?<= 'if' c :> T ']'").
Reserved Notation "\bot^d".
Reserved Notation "\top^d".
(* Reserved notations for product ordering of prod *)
Reserved Notation "x <=^p y" (at level 70, y at next level).
Reserved Notation "x >=^p y" (at level 70, y at next level).
Reserved Notation "x <^p y" (at level 70, y at next level).
Reserved Notation "x >^p y" (at level 70, y at next level).
Reserved Notation "x <=^p y :> T" (at level 70, y at next level).
Reserved Notation "x >=^p y :> T" (at level 70, y at next level).
Reserved Notation "x <^p y :> T" (at level 70, y at next level).
Reserved Notation "x >^p y :> T" (at level 70, y at next level).
Reserved Notation "<=^p y" (at level 35).
Reserved Notation ">=^p y" (at level 35).
Reserved Notation "<^p y" (at level 35).
Reserved Notation ">^p y" (at level 35).
Reserved Notation "<=^p y :> T" (at level 35, y at next level).
Reserved Notation ">=^p y :> T" (at level 35, y at next level).
Reserved Notation "<^p y :> T" (at level 35, y at next level).
Reserved Notation ">^p y :> T" (at level 35, y at next level).
Reserved Notation "x >=<^p y" (at level 70, no associativity).
Reserved Notation ">=<^p x" (at level 35).
Reserved Notation ">=<^p y :> T" (at level 35, y at next level).
Reserved Notation "x ><^p y" (at level 70, no associativity).
Reserved Notation "><^p x" (at level 35).
Reserved Notation "><^p y :> T" (at level 35, y at next level).
Reserved Notation "x <=^p y <=^p z" (at level 70, y, z at next level).
Reserved Notation "x <^p y <=^p z" (at level 70, y, z at next level).
Reserved Notation "x <=^p y <^p z" (at level 70, y, z at next level).
Reserved Notation "x <^p y <^p z" (at level 70, y, z at next level).
Reserved Notation "x <=^p y ?= 'iff' c" (at level 70, y, c at next level,
format "x '[hv' <=^p y '/' ?= 'iff' c ']'").
Reserved Notation "x <=^p y ?= 'iff' c :> T" (at level 70, y, c at next level,
format "x '[hv' <=^p y '/' ?= 'iff' c :> T ']'").
Reserved Notation "\bot^p".
Reserved Notation "\top^p".
(* Reserved notations for product ordering of seq *)
Reserved Notation "x <=^sp y" (at level 70, y at next level).
Reserved Notation "x >=^sp y" (at level 70, y at next level).
Reserved Notation "x <^sp y" (at level 70, y at next level).
Reserved Notation "x >^sp y" (at level 70, y at next level).
Reserved Notation "x <=^sp y :> T" (at level 70, y at next level).
Reserved Notation "x >=^sp y :> T" (at level 70, y at next level).
Reserved Notation "x <^sp y :> T" (at level 70, y at next level).
Reserved Notation "x >^sp y :> T" (at level 70, y at next level).
Reserved Notation "<=^sp y" (at level 35).
Reserved Notation ">=^sp y" (at level 35).
Reserved Notation "<^sp y" (at level 35).
Reserved Notation ">^sp y" (at level 35).
Reserved Notation "<=^sp y :> T" (at level 35, y at next level).
Reserved Notation ">=^sp y :> T" (at level 35, y at next level).
Reserved Notation "<^sp y :> T" (at level 35, y at next level).
Reserved Notation ">^sp y :> T" (at level 35, y at next level).
Reserved Notation "x >=<^sp y" (at level 70, no associativity).
Reserved Notation ">=<^sp x" (at level 35).
Reserved Notation ">=<^sp y :> T" (at level 35, y at next level).
Reserved Notation "x ><^sp y" (at level 70, no associativity).
Reserved Notation "><^sp x" (at level 35).
Reserved Notation "><^sp y :> T" (at level 35, y at next level).
Reserved Notation "x <=^sp y <=^sp z" (at level 70, y, z at next level).
Reserved Notation "x <^sp y <=^sp z" (at level 70, y, z at next level).
Reserved Notation "x <=^sp y <^sp z" (at level 70, y, z at next level).
Reserved Notation "x <^sp y <^sp z" (at level 70, y, z at next level).
Reserved Notation "x <=^sp y ?= 'iff' c" (at level 70, y, c at next level,
format "x '[hv' <=^sp y '/' ?= 'iff' c ']'").
Reserved Notation "x <=^sp y ?= 'iff' c :> T" (at level 70, y, c at next level,
format "x '[hv' <=^sp y '/' ?= 'iff' c :> T ']'").
Reserved Notation "\bot^sp".
Reserved Notation "\top^sp".
(* Reserved notations for lexicographic ordering of prod *)
Reserved Notation "x <=^l y" (at level 70, y at next level).
Reserved Notation "x >=^l y" (at level 70, y at next level).
Reserved Notation "x <^l y" (at level 70, y at next level).
Reserved Notation "x >^l y" (at level 70, y at next level).
Reserved Notation "x <=^l y :> T" (at level 70, y at next level).
Reserved Notation "x >=^l y :> T" (at level 70, y at next level).
Reserved Notation "x <^l y :> T" (at level 70, y at next level).
Reserved Notation "x >^l y :> T" (at level 70, y at next level).
Reserved Notation "<=^l y" (at level 35).
Reserved Notation ">=^l y" (at level 35).
Reserved Notation "<^l y" (at level 35).
Reserved Notation ">^l y" (at level 35).
Reserved Notation "<=^l y :> T" (at level 35, y at next level).
Reserved Notation ">=^l y :> T" (at level 35, y at next level).
Reserved Notation "<^l y :> T" (at level 35, y at next level).
Reserved Notation ">^l y :> T" (at level 35, y at next level).
Reserved Notation "x >=<^l y" (at level 70, no associativity).
Reserved Notation ">=<^l x" (at level 35).
Reserved Notation ">=<^l y :> T" (at level 35, y at next level).
Reserved Notation "x ><^l y" (at level 70, no associativity).
Reserved Notation "><^l x" (at level 35).
Reserved Notation "><^l y :> T" (at level 35, y at next level).
Reserved Notation "x <=^l y <=^l z" (at level 70, y, z at next level).
Reserved Notation "x <^l y <=^l z" (at level 70, y, z at next level).
Reserved Notation "x <=^l y <^l z" (at level 70, y, z at next level).
Reserved Notation "x <^l y <^l z" (at level 70, y, z at next level).
Reserved Notation "x <=^l y ?= 'iff' c" (at level 70, y, c at next level,
format "x '[hv' <=^l y '/' ?= 'iff' c ']'").
Reserved Notation "x <=^l y ?= 'iff' c :> T" (at level 70, y, c at next level,
format "x '[hv' <=^l y '/' ?= 'iff' c :> T ']'").
Reserved Notation "\bot^l".
Reserved Notation "\top^l".
(* Reserved notations for lexicographic ordering of seq *)
Reserved Notation "x <=^sl y" (at level 70, y at next level).
Reserved Notation "x >=^sl y" (at level 70, y at next level).
Reserved Notation "x <^sl y" (at level 70, y at next level).
Reserved Notation "x >^sl y" (at level 70, y at next level).
Reserved Notation "x <=^sl y :> T" (at level 70, y at next level).
Reserved Notation "x >=^sl y :> T" (at level 70, y at next level).
Reserved Notation "x <^sl y :> T" (at level 70, y at next level).
Reserved Notation "x >^sl y :> T" (at level 70, y at next level).
Reserved Notation "<=^sl y" (at level 35).
Reserved Notation ">=^sl y" (at level 35).
Reserved Notation "<^sl y" (at level 35).
Reserved Notation ">^sl y" (at level 35).
Reserved Notation "<=^sl y :> T" (at level 35, y at next level).
Reserved Notation ">=^sl y :> T" (at level 35, y at next level).
Reserved Notation "<^sl y :> T" (at level 35, y at next level).
Reserved Notation ">^sl y :> T" (at level 35, y at next level).
Reserved Notation "x >=<^sl y" (at level 70, no associativity).
Reserved Notation ">=<^sl x" (at level 35).
Reserved Notation ">=<^sl y :> T" (at level 35, y at next level).
Reserved Notation "x ><^sl y" (at level 70, no associativity).
Reserved Notation "><^sl x" (at level 35).
Reserved Notation "><^sl y :> T" (at level 35, y at next level).
Reserved Notation "x <=^sl y <=^sl z" (at level 70, y, z at next level).
Reserved Notation "x <^sl y <=^sl z" (at level 70, y, z at next level).
Reserved Notation "x <=^sl y <^sl z" (at level 70, y, z at next level).
Reserved Notation "x <^sl y <^sl z" (at level 70, y, z at next level).
Reserved Notation "x <=^sl y ?= 'iff' c" (at level 70, y, c at next level,
format "x '[hv' <=^sl y '/' ?= 'iff' c ']'").
Reserved Notation "x <=^sl y ?= 'iff' c :> T" (at level 70, y, c at next level,
format "x '[hv' <=^sl y '/' ?= 'iff' c :> T ']'").
Reserved Notation "\bot^sl".
Reserved Notation "\top^sl".
(* Reserved notations for divisibility *)
Reserved Notation "x %<| y" (at level 70, no associativity).
Reserved Notation "\min_ i F"
(at level 34, F at level 41, i at level 0,
format "'[' \min_ i '/ ' F ']'").
Reserved Notation "\min_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min_ ( i <- r ) F"
(F at level 41,
format "'[' \min_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min_ ( i | P ) F"
(F at level 41,
format "'[' \min_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min_ ( i : t ) F" (F at level 41).
Reserved Notation "\min_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min_ ( i < n ) F"
(F at level 41,
format "'[' \min_ ( i < n ) F ']'").
Reserved Notation "\min_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min_ ( 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).
Reserved Notation "\max_ ( i : t ) F" (F at level 41).
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,
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 "\min^d_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \min^d_ i '/ ' F ']'").
Reserved Notation "\min^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \min^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\min^d_ ( i <- r ) F"
(F at level 41, r at level 60,
format "'[' \min^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\min^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \min^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\min^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \min^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\min^d_ ( i | P ) F"
(F at level 41,
format "'[' \min^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\min^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\min^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\min^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \min^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\min^d_ ( i < n ) F"
(F at level 41,
format "'[' \min^d_ ( i < n ) F ']'").
Reserved Notation "\min^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \min^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\min^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \min^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "\max^d_ i F"
(at level 41, F at level 41, i at level 0,
format "'[' \max^d_ i '/ ' F ']'").
Reserved Notation "\max^d_ ( i <- r | P ) F"
(F at level 41, i, r at level 60,
format "'[' \max^d_ ( i <- r | P ) '/ ' F ']'").
Reserved Notation "\max^d_ ( i <- r ) F"
(F at level 41, r at level 60,
format "'[' \max^d_ ( i <- r ) '/ ' F ']'").
Reserved Notation "\max^d_ ( m <= i < n | P ) F"
(F at level 41, i, n at level 60,
format "'[' \max^d_ ( m <= i < n | P ) '/ ' F ']'").
Reserved Notation "\max^d_ ( m <= i < n ) F"
(F at level 41,
format "'[' \max^d_ ( m <= i < n ) '/ ' F ']'").
Reserved Notation "\max^d_ ( i | P ) F"
(F at level 41,
format "'[' \max^d_ ( i | P ) '/ ' F ']'").
Reserved Notation "\max^d_ ( i : t | P ) F" (F at level 41).
Reserved Notation "\max^d_ ( i : t ) F" (F at level 41).
Reserved Notation "\max^d_ ( i < n | P ) F"
(F at level 41, n at level 60,
format "'[' \max^d_ ( i < n | P ) '/ ' F ']'").
Reserved Notation "\max^d_ ( i < n ) F"
(F at level 41,
format "'[' \max^d_ ( i < n ) F ']'").
Reserved Notation "\max^d_ ( i 'in' A | P ) F"
(F at level 41, A at level 60,
format "'[' \max^d_ ( i 'in' A | P ) '/ ' F ']'").
Reserved Notation "\max^d_ ( i 'in' A ) F"
(F at level 41,
format "'[' \max^d_ ( i 'in' A ) '/ ' F ']'").
Reserved Notation "'{' 'omorphism' U '->' V '}'"
(at level 0, U at level 98, V at level 99,
format "{ 'omorphism' U -> V }").
Module Order.
#[projections(primitive)] Record disp_t := Disp {d1 : unit; d2 : unit}.
#[key="T", primitive]
HB.mixin Record isDuallyPreorder (d : disp_t) T of Equality T := {
le : rel T;
lt : rel T;
lt_def : forall x y, lt x y = (le x y) && ~~ (le y x);
gt_def : forall x y, lt y x = (le y x) && ~~ (le x y);
le_refl : reflexive le;
ge_refl : reflexive (fun x y => le y x);
le_trans : transitive le;
ge_trans : transitive (fun x y => le y x);
}.
#[short(type="preorderType")]
HB.structure Definition Preorder (d : disp_t) :=
{ T of Choice T & isDuallyPreorder d T }.
#[key="T", primitive]
HB.mixin Record hasBottom d T of Preorder d T := {
bottom : T;
le0x : forall x, le bottom x;
}.
#[key="T", primitive]
HB.mixin Record hasTop d T of Preorder d T := {
top : T;
lex1 : forall x, le x top;
}.
#[short(type="bPreorderType")]
HB.structure Definition BPreorder d := { T of hasBottom d T & Preorder d T }.
#[short(type="tPreorderType")]
HB.structure Definition TPreorder d := { T of hasTop d T & Preorder d T }.
#[short(type="tbPreorderType")]
HB.structure Definition TBPreorder d := { T of hasTop d T & BPreorder d T }.
Section PreorderDef.
Variable (disp : disp_t) (T : preorderType disp).
Local Notation "x <= y" := (le x y) : order_scope.
Local Notation "x < y" := (lt x y) : order_scope.
Definition comparable : rel T := fun (x y : T) => (x <= y) || (y <= x).
Local Notation "x >=< y" := (comparable x y) : order_scope.
Local Notation "x >< y" := (~~ (x >=< y)) : order_scope.
Definition ge : simpl_rel T := [rel x y | y <= x].
Definition gt : simpl_rel T := [rel x y | y < x].
Definition leif (x y : T) C : Prop := ((x <= y) * ((x == y) = C))%type.
Definition le_of_leif x y C (le_xy : @leif x y C) := le_xy.1 : le x y.
Definition lteif (x y : T) C := if C then x <= y else x < y.
Variant le_xor_gt (x y : T) :
T -> T -> T -> T -> bool -> bool -> Set :=
| LeNotGt of x <= y : le_xor_gt x y x x y y true false
| GtNotLe of y < x : le_xor_gt x y y y x x false true.
Variant lt_xor_ge (x y : T) :
T -> T -> T -> T -> bool -> bool -> Set :=
| LtNotGe of x < y : lt_xor_ge x y x x y y false true
| GeNotLt of y <= x : lt_xor_ge x y y y x x true false.
Definition min (x y : T) := if x < y then x else y.
Definition max (x y : T) := if x < y then y else x.
Variant compare (x y : T) :
T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| CompareLt of x < y : compare x y
x x y y false false false true false true
| CompareGt of y < x : compare x y
y y x x false false true false true false
| CompareEq of x = y : compare x y
x x x x true true true true false false.
Variant incompare (x y : T) :
T -> T -> T -> T ->
bool -> bool -> bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| InCompareLt of x < y : incompare x y
x x y y false false false true false true true true
| InCompareGt of y < x : incompare x y
y y x x false false true false true false true true
| InCompare of x >< y : incompare x y
x y y x false false false false false false false false
| InCompareEq of x = y : incompare x y
x x x x true true true true false false true true.
Definition arg_min {I : finType} := @extremum T I le.
Definition arg_max {I : finType} := @extremum T I ge.
(* Lifted min/max operations. *)
Section LiftedPreorder.
Variable T' : Type.
Implicit Type f : T' -> T.
Definition min_fun f g x := min (f x) (g x).
Definition max_fun f g x := max (f x) (g x).
End LiftedPreorder.
Definition nondecreasing disp' (T' : preorderType disp') (f : T -> T') : Prop :=
{homo f : x y / x <= y}.
End PreorderDef.
Prenex Implicits lt le leif lteif.
Arguments ge {_ _}.
Arguments gt {_ _}.
Arguments min {_ _}.
Arguments max {_ _}.
Arguments comparable {_ _}.
Arguments min_fun {_ _ _} f g _ /.
Arguments max_fun {_ _ _} f g _ /.
Module Import Def.
Notation nondecreasing := nondecreasing.
Notation min := min.
Notation max := max.
End Def.
Module Import PreOSyntax.
Notation "<=%O" := le : function_scope.
Notation ">=%O" := ge : function_scope.
Notation "<%O" := lt : function_scope.
Notation ">%O" := gt : function_scope.
Notation "<?=%O" := leif : function_scope.
Notation "<?<=%O" := lteif : function_scope.
Notation ">=<%O" := comparable : function_scope.
Notation "><%O" := (fun x y => ~~ (comparable x y)) : function_scope.
Notation "<= y" := (ge y) : order_scope.
Notation "<= y :> T" := (<= (y : T)) (only parsing) : order_scope.
Notation ">= y" := (le y) : order_scope.
Notation ">= y :> T" := (>= (y : T)) (only parsing) : order_scope.
Notation "< y" := (gt y) : order_scope.
Notation "< y :> T" := (< (y : T)) (only parsing) : order_scope.
Notation "> y" := (lt y) : order_scope.
Notation "> y :> T" := (> (y : T)) (only parsing) : order_scope.
Notation "x <= y" := (le x y) : order_scope.
Notation "x <= y :> T" := ((x : T) <= (y : T)) (only parsing) : order_scope.
Notation "x >= y" := (y <= x) (only parsing) : order_scope.
Notation "x >= y :> T" := ((x : T) >= (y : T)) (only parsing) : order_scope.
Notation "x < y" := (lt x y) : order_scope.
Notation "x < y :> T" := ((x : T) < (y : T)) (only parsing) : order_scope.
Notation "x > y" := (y < x) (only parsing) : order_scope.
Notation "x > y :> T" := ((x : T) > (y : T)) (only parsing) : order_scope.
Notation "x <= y <= z" := ((x <= y) && (y <= z)) : order_scope.
Notation "x < y <= z" := ((x < y) && (y <= z)) : order_scope.
Notation "x <= y < z" := ((x <= y) && (y < z)) : order_scope.
Notation "x < y < z" := ((x < y) && (y < z)) : order_scope.
Notation "x <= y ?= 'iff' C" := (leif x y C) : order_scope.
Notation "x <= y ?= 'iff' C :> T" := ((x : T) <= (y : T) ?= iff C)
(only parsing) : order_scope.
Notation "x < y ?<= 'if' C" := (lteif x y C) : order_scope.
Notation "x < y ?<= 'if' C :> T" := ((x : T) < (y : T) ?<= if C)
(only parsing) : order_scope.
Notation ">=< y" := [pred x | comparable x y] : order_scope.
Notation ">=< y :> T" := (>=< (y : T)) (only parsing) : order_scope.
Notation "x >=< y" := (comparable x y) : order_scope.
Notation ">< y" := [pred x | ~~ comparable x y] : order_scope.
Notation ">< y :> T" := (>< (y : T)) (only parsing) : order_scope.
Notation "x >< y" := (~~ (comparable x y)) : order_scope.
Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" :=
(arg_min i0 (fun i => P%B) (fun i => F))
(i, i0 at level 10,
format "[ 'arg' 'min_' ( i < i0 | P ) F ]") : order_scope.
Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" :=
[arg min_(i < i0 | i \in A) F]
(format "[ 'arg' 'min_' ( i < i0 'in' A ) F ]") : order_scope.
Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F]
(i0 at level 10,
format "[ 'arg' 'min_' ( i < i0 ) F ]") : order_scope.
Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" :=
(arg_max i0 (fun i => P%B) (fun i => F))
(i, i0 at level 10,
format "[ 'arg' 'max_' ( i > i0 | P ) F ]") : order_scope.
Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" :=
[arg max_(i > i0 | i \in A) F]
(i, i0 at level 10,
format "[ 'arg' 'max_' ( i > i0 'in' A ) F ]") : order_scope.
Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F]
(i, i0 at level 10,
format "[ 'arg' 'max_' ( i > i0 ) F ]") : order_scope.
Notation "f \min g" := (min_fun f g) : function_scope.
Notation "f \max g" := (max_fun f g) : function_scope.
Notation leLHS := (X in (X <= _)%O)%pattern.
Notation leRHS := (X in (_ <= X)%O)%pattern.
Notation ltLHS := (X in (X < _)%O)%pattern.
Notation ltRHS := (X in (_ < X)%O)%pattern.
Notation "\bot" := bottom : order_scope.
Notation "\top" := top : order_scope.
End PreOSyntax.
HB.export PreOSyntax.
Module PreOCoercions.
Coercion le_of_leif : leif >-> is_true.
End PreOCoercions.
HB.export PreOCoercions.
(**********)
(* FINITE *)
(**********)
#[short(type="finPreorderType")]
HB.structure Definition FinPreorder d := { T of Finite T & Preorder d T }.
#[short(type="finBPreorderType")]
HB.structure Definition FinBPreorder d := { T of FinPreorder d T & hasBottom d T }.
#[short(type="finTPreorderType")]
HB.structure Definition FinTPreorder d := { T of FinPreorder d T & hasTop d T }.
#[short(type="finTBPreorderType")]
HB.structure Definition FinTBPreorder d := { T of FinBPreorder d T & hasTop d T }.
(********)
(* DUAL *)
(********)
Definition dual T : Type := T.
Definition dual_display (d : disp_t) := {| d1 := d2 d; d2 := d1 d |}.
Notation dual_le := (@le (dual_display _) _).
Notation dual_lt := (@lt (dual_display _) _).
Notation dual_comparable := (@comparable (dual_display _) _).
Notation dual_ge := (@ge (dual_display _) _).
Notation dual_gt := (@gt (dual_display _) _).
Notation dual_leif := (@leif (dual_display _) _).
Notation dual_lteif := (@lteif (dual_display _) _).
Notation dual_max := (@max (dual_display _) _).
Notation dual_min := (@min (dual_display _) _).
Notation dual_bottom := (@bottom (dual_display _) _).
Notation dual_top := (@top (dual_display _) _).
Module Import DualSyntax.
Notation "T ^d" := (dual T) (format "T ^d") : type_scope.
Notation "<=^d%O" := dual_le : function_scope.
Notation ">=^d%O" := dual_ge : function_scope.
Notation "<^d%O" := dual_lt : function_scope.
Notation ">^d%O" := dual_gt : function_scope.
Notation "<?=^d%O" := dual_leif : function_scope.
Notation "<?<=^d%O" := dual_lteif : function_scope.
Notation ">=<^d%O" := dual_comparable : function_scope.
Notation "><^d%O" := (fun x y => ~~ dual_comparable x y) : function_scope.
Notation "<=^d y" := (>=^d%O y) : order_scope.
Notation "<=^d y :> T" := (<=^d (y : T)) (only parsing) : order_scope.
Notation ">=^d y" := (<=^d%O y) : order_scope.
Notation ">=^d y :> T" := (>=^d (y : T)) (only parsing) : order_scope.
Notation "<^d y" := (>^d%O y) : order_scope.
Notation "<^d y :> T" := (<^d (y : T)) (only parsing) : order_scope.
Notation ">^d y" := (<^d%O y) : order_scope.
Notation ">^d y :> T" := (>^d (y : T)) (only parsing) : order_scope.
Notation "x <=^d y" := (<=^d%O x y) : order_scope.
Notation "x <=^d y :> T" := ((x : T) <=^d (y : T)) (only parsing) : order_scope.
Notation "x >=^d y" := (y <=^d x) (only parsing) : order_scope.
Notation "x >=^d y :> T" := ((x : T) >=^d (y : T)) (only parsing) : order_scope.
Notation "x <^d y" := (<^d%O x y) : order_scope.
Notation "x <^d y :> T" := ((x : T) <^d (y : T)) (only parsing) : order_scope.
Notation "x >^d y" := (y <^d x) (only parsing) : order_scope.
Notation "x >^d y :> T" := ((x : T) >^d (y : T)) (only parsing) : order_scope.
Notation "x <=^d y <=^d z" := ((x <=^d y) && (y <=^d z)) : order_scope.
Notation "x <^d y <=^d z" := ((x <^d y) && (y <=^d z)) : order_scope.
Notation "x <=^d y <^d z" := ((x <=^d y) && (y <^d z)) : order_scope.
Notation "x <^d y <^d z" := ((x <^d y) && (y <^d z)) : order_scope.
Notation "x <=^d y ?= 'iff' C" := (<?=^d%O x y C) : order_scope.
Notation "x <=^d y ?= 'iff' C :> T" := ((x : T) <=^d (y : T) ?= iff C)
(only parsing) : order_scope.
Notation "x <^d y ?<= 'if' C" := (<?<=^d%O x y C) : order_scope.
Notation "x <^d y ?<= 'if' C :> T" := ((x : T) <^d (y : T) ?<= if C)
(only parsing) : order_scope.
Notation ">=<^d x" := (>=<^d%O x) : order_scope.
Notation ">=<^d y :> T" := (>=<^d (y : T)) (only parsing) : order_scope.
Notation "x >=<^d y" := (>=<^d%O x y) : order_scope.
Notation "><^d y" := [pred x | ~~ dual_comparable x y] : order_scope.
Notation "><^d y :> T" := (><^d (y : T)) (only parsing) : order_scope.
Notation "x ><^d y" := (~~ (><^d%O x y)) : order_scope.
Notation "\bot^d" := dual_bottom : order_scope.
Notation "\top^d" := dual_top : order_scope.
End DualSyntax.
Module DualPreorder.
HB.instance Definition _ (T : eqType) := Equality.on T^d.
HB.instance Definition _ (T : choiceType) := Choice.on T^d.
HB.instance Definition _ (T : countType) := Countable.on T^d.
HB.instance Definition _ (T : finType) := Finite.on T^d.
HB.instance Definition _ (d : disp_t) (T : preorderType d) :=
isDuallyPreorder.Build (dual_display d) T^d
gt_def lt_def ge_refl le_refl ge_trans le_trans.
Lemma leEdual (d : disp_t) (T : preorderType d) (x y : T) :
(x <=^d y :> T^d) = (y <= x).
Proof. by []. Qed.
Lemma ltEdual (d : disp_t) (T : preorderType d) (x y : T) :
(x <^d y :> T^d) = (y < x).
Proof. by []. Qed.
HB.instance Definition _ d (T : tPreorderType d) :=
hasBottom.Build (dual_display d) T^d lex1.
Lemma botEdual d (T : tPreorderType d) : (dual_bottom : T^d) = \top :> T.
Proof. by []. Qed.
HB.instance Definition _ d (T : bPreorderType d) :=
hasTop.Build (dual_display d) T^d le0x.
Lemma topEdual d (T : bPreorderType d) : (dual_top : T^d) = \bot :> T.
Proof. by []. Qed.
End DualPreorder.
HB.export DualPreorder.
(**********)
(* THEORY *)
(**********)
Module Import PreorderTheory.
Section PreorderTheory.
Context {disp : disp_t} {T : preorderType disp}.
Implicit Types (x y : T) (s : seq T).
Definition nondecreasing disp' (T' : preorderType disp') (f : T -> T') : Prop :=
{homo f : x y / x <= y}.
Lemma geE x y : ge x y = (y <= x). Proof. by []. Qed.
Lemma gtE x y : gt x y = (y < x). Proof. by []. Qed.
Lemma lexx (x : T) : x <= x.
Proof. exact: le_refl. Qed.
Hint Resolve lexx : core.
Definition le_refl : reflexive le := lexx.
Definition ge_refl : reflexive ge := lexx.
Hint Resolve le_refl : core.
Lemma le_trans: transitive (<=%O : rel T).
Proof. exact: le_trans. Qed.
Lemma ge_trans: transitive (>=%O : rel T).
Proof. by move=> ? ? ? ? /le_trans; apply. Qed.
Lemma le_le_trans x y z t : z <= x -> y <= t -> x <= y -> z <= t.
Proof. by move=> + /(le_trans _)/[apply]; apply: le_trans. Qed.
Lemma lt_le_def x y: (x < y) = (x <= y) && ~~ (y <= x).
Proof. exact: lt_def. Qed.
Lemma ltxx x: x < x = false.
Proof. by rewrite lt_le_def andbN. Qed.
Definition lt_irreflexive : irreflexive lt := ltxx.
Hint Resolve lt_irreflexive : core.
Definition ltexx := (lexx, ltxx).
Lemma lt_eqF x y: x < y -> x == y = false.
Proof. by apply: contraTF => /eqP ->; rewrite ltxx. Qed.
Lemma gt_eqF x y : y < x -> x == y = false.
Proof. by move=> /lt_eqF; rewrite eq_sym. Qed.
Lemma ltW x y: x < y -> x <= y.
Proof. by rewrite lt_le_def => /andP[]. Qed.
Lemma lt_le_trans y x z: x < y -> y <= z -> x < z.
Proof.
rewrite !lt_le_def => /andP[] xy /negP yx yz.
apply/andP; split; first exact/(le_trans xy).
by apply/negP => /(le_trans yz).
Qed.
Lemma lt_trans: transitive (<%O : rel T).
Proof. by move=> y x z le1 /ltW le2; apply/(@lt_le_trans y). Qed.
Lemma le_lt_trans y x z: x <= y -> y < z -> x < z.
Proof.
rewrite !lt_le_def => xy /andP[] yz /negP zy.
apply/andP; split; first exact/(le_trans xy).
by apply/negP => /(fun zx => le_trans zx xy).
Qed.
Lemma lt_nsym x y : x < y -> y < x -> False.
Proof. by move=> xy /(lt_trans xy); rewrite ltxx. Qed.
Lemma lt_asym x y : x < y < x = false.
Proof. by apply/negP => /andP []; apply: lt_nsym. Qed.
Lemma le_gtF x y: x <= y -> y < x = false.
Proof.
by move=> le_xy; apply/negP => /lt_le_trans /(_ le_xy); rewrite ltxx.
Qed.
Lemma lt_geF x y : x < y -> y <= x = false.
Proof. by apply: contraTF => /le_gtF ->. Qed.
Definition lt_gtF x y hxy := le_gtF (@ltW x y hxy).
Lemma lt_leAnge x y : (x < y) = (x <= y) && ~~ (y <= x).
Proof. exact: lt_le_def. Qed.
Lemma lt_le_asym x y : x < y <= x = false.
Proof. by apply/negP; move=> /andP[] xy /(lt_le_trans xy); rewrite ltxx. Qed.
Lemma le_lt_asym x y : x <= y < x = false.
Proof. by rewrite andbC lt_le_asym. Qed.
Lemma le_path_min x s : path <=%O x s -> all (>= x) s.
Proof. exact/order_path_min/le_trans. Qed.
Lemma lt_path_min x s : path <%O x s -> all (> x) s.
Proof. exact/order_path_min/lt_trans. Qed.
Lemma le_path_sortedE x s : path <=%O x s = all (>= x) s && sorted <=%O s.
Proof. exact/path_sortedE/le_trans. Qed.
Lemma lt_path_sortedE x s : path <%O x s = all (> x) s && sorted <%O s.
Proof. exact/path_sortedE/lt_trans. Qed.
Lemma le_sorted_pairwise s : sorted <=%O s = pairwise <=%O s.
Proof. exact/sorted_pairwise/le_trans. Qed.
Lemma lt_sorted_pairwise s : sorted <%O s = pairwise <%O s.
Proof. exact/sorted_pairwise/lt_trans. Qed.
Lemma le_path_pairwise x s : path <=%O x s = pairwise <=%O (x :: s).
Proof. exact/path_pairwise/le_trans. Qed.
Lemma lt_path_pairwise x s : path <%O x s = pairwise <%O (x :: s).
Proof. exact/path_pairwise/lt_trans. Qed.
Lemma lt_sorted_is_uniq_le s : sorted <%O s -> uniq s && sorted <=%O s.
Proof.
rewrite le_sorted_pairwise lt_sorted_pairwise uniq_pairwise -pairwise_relI.
apply/sub_pairwise => x y/= /[dup] + /ltW ->.
by case: eqVneq => // ->; rewrite ltxx.
Qed.
Lemma le_sorted_mask m s : sorted <=%O s -> sorted <=%O (mask m s).
Proof. exact/sorted_mask/le_trans. Qed.
Lemma lt_sorted_mask m s : sorted <%O s -> sorted <%O (mask m s).
Proof. exact/sorted_mask/lt_trans. Qed.
Lemma le_sorted_filter a s : sorted <=%O s -> sorted <=%O (filter a s).
Proof. exact/sorted_filter/le_trans. Qed.
Lemma lt_sorted_filter a s : sorted <%O s -> sorted <%O (filter a s).
Proof. exact/sorted_filter/lt_trans. Qed.
Lemma le_path_mask x m s : path <=%O x s -> path <=%O x (mask m s).
Proof. exact/path_mask/le_trans. Qed.
Lemma lt_path_mask x m s : path <%O x s -> path <%O x (mask m s).
Proof. exact/path_mask/lt_trans. Qed.
Lemma le_path_filter x a s : path <=%O x s -> path <=%O x (filter a s).
Proof. exact/path_filter/le_trans. Qed.
Lemma lt_path_filter x a s : path <%O x s -> path <%O x (filter a s).
Proof. exact/path_filter/lt_trans. Qed.
Lemma le_sorted_ltn_nth (x0 : T) (s : seq T) : sorted <=%O s ->
{in [pred n | (n < size s)%N] &,
{homo nth x0 s : i j / (i < j)%N >-> i <= j}}.
Proof. exact/sorted_ltn_nth/le_trans. Qed.
Lemma le_sorted_leq_nth (x0 : T) (s : seq T) : sorted <=%O s ->
{in [pred n | (n < size s)%N] &,
{homo nth x0 s : i j / (i <= j)%N >-> i <= j}}.
Proof. exact/sorted_leq_nth/le_refl/le_trans. Qed.
Lemma lt_sorted_leq_nth (x0 : T) (s : seq T) : sorted <%O s ->
{in [pred n | (n < size s)%N] &,
{mono nth x0 s : i j / (i <= j)%N >-> i <= j}}.
Proof.
move=> /[dup] lt_s /lt_sorted_is_uniq_le /andP[s_uniq le_s] i j ilt jlt.
case/boolP: (i <= j)%N; first exact/le_sorted_leq_nth.
rewrite -ltnNge => /(sorted_ltn_nth lt_trans x0 lt_s j i jlt ilt).
by rewrite lt_le_def => /andP[_] /negPf.
Qed.
Lemma lt_sorted_ltn_nth (x0 : T) (s : seq T) : sorted <%O s ->
{in [pred n | (n < size s)%N] &,
{mono nth x0 s : i j / (i < j)%N >-> i < j}}.
Proof.
move=> ss i j ilt jlt.
rewrite lt_le_def (lt_sorted_leq_nth x0 ss)// (lt_sorted_leq_nth x0 ss)//.
by rewrite -ltnNge andbC ltn_neqAle -andbA andbb.
Qed.
Lemma subseq_le_path x s1 s2 : subseq s1 s2 -> path <=%O x s2 -> path <=%O x s1.
Proof. exact/subseq_path/le_trans. Qed.
Lemma subseq_lt_path x s1 s2 : subseq s1 s2 -> path <%O x s2 -> path <%O x s1.
Proof. exact/subseq_path/lt_trans. Qed.
Lemma subseq_le_sorted s1 s2 : subseq s1 s2 -> sorted <=%O s2 -> sorted <=%O s1.
Proof. exact/subseq_sorted/le_trans. Qed.
Lemma subseq_lt_sorted s1 s2 : subseq s1 s2 -> sorted <%O s2 -> sorted <%O s1.
Proof. exact/subseq_sorted/lt_trans. Qed.
Lemma lt_sorted_uniq s : sorted <%O s -> uniq s.
Proof. exact/sorted_uniq/ltxx/lt_trans. Qed.
Lemma lt_sorted_eq s1 s2 :
sorted <%O s1 -> sorted <%O s2 -> s1 =i s2 -> s1 = s2.
Proof. exact/irr_sorted_eq/ltxx/lt_trans. Qed.
Lemma filter_lt_nth x0 s i : sorted <%O s -> (i < size s)%N ->
[seq x <- s | x < nth x0 s i] = take i s.
Proof.
move=> ss i_lt/=; rewrite -[X in filter _ X](mkseq_nth x0) filter_map.
under eq_in_filter => j do
[rewrite ?mem_iota => j_s /=; rewrite lt_sorted_ltn_nth//].
by rewrite (filter_iota_ltn 0) ?map_nth_iota0 // ltnW.
Qed.
Lemma count_lt_nth x0 s i : sorted <%O s -> (i < size s)%N ->
count (< nth x0 s i) s = i.
Proof.
by move=> ss i_lt; rewrite -size_filter/= filter_lt_nth// size_take i_lt.
Qed.
Lemma filter_le_nth x0 s i : sorted <%O s -> (i < size s)%N ->
[seq x <- s | x <= nth x0 s i] = take i.+1 s.
Proof.
move=> ss i_lt/=; rewrite -[X in filter _ X](mkseq_nth x0) filter_map.
under eq_in_filter => j do
[rewrite ?mem_iota => j_s /=; rewrite lt_sorted_leq_nth//].
by rewrite (filter_iota_leq 0)// map_nth_iota0.
Qed.
Lemma count_le_nth x0 s i : sorted <%O s -> (i < size s)%N ->
count (<= nth x0 s i) s = i.+1.
Proof.
by move=> ss i_lt; rewrite -size_filter/= filter_le_nth// size_takel.
Qed.
Lemma sorted_filter_lt x s :
sorted <=%O s -> [seq y <- s | y < x] = take (count (< x) s) s.
Proof.
elim: s => [//|y s IHs]/=; rewrite (path_sortedE le_trans) => /andP[le_y_s ss].
case: ifP => [|ltyxF]; rewrite IHs//.
rewrite (@eq_in_count _ _ pred0) ?count_pred0/= ?take0// => z.
by move=> /(allP le_y_s) yz; apply: contraFF ltyxF; apply: le_lt_trans.
Qed.
Lemma sorted_filter_le x s :
sorted <=%O s -> [seq y <- s | y <= x] = take (count (<= x) s) s.
Proof.
elim: s => [//|y s IHs]/=; rewrite (path_sortedE le_trans) => /andP[le_y_s ss].
case: ifP => [|leyxF]; rewrite IHs//.
rewrite (@eq_in_count _ _ pred0) ?count_pred0/= ?take0// => z.
by move=> /(allP le_y_s) yz; apply: contraFF leyxF; apply: le_trans.
Qed.
Lemma nth_count_le x x0 s i : sorted <=%O s ->
(i < count (<= x) s)%N -> nth x0 s i <= x.
Proof.
move=> ss iltc; rewrite -(nth_take _ iltc) -sorted_filter_le //.
by apply/(all_nthP _ (filter_all (<= x) _)); rewrite size_filter.
Qed.
Lemma nth_count_lt x x0 s i : sorted <=%O s ->
(i < count (< x) s)%N -> nth x0 s i < x.
Proof.
move=> ss iltc; rewrite -(nth_take _ iltc) -sorted_filter_lt //.
by apply/(all_nthP _ (filter_all (< x) _)); rewrite size_filter.
Qed.
Lemma sort_le_id s : sorted <=%O s -> sort <=%O s = s.
Proof. exact/sorted_sort/le_trans. Qed.
Lemma sort_lt_id s : sorted <%O s -> sort <%O s = s.
Proof. exact/sorted_sort/lt_trans. Qed.
Lemma comparable_leNgt x y : x >=< y -> (x <= y) = ~~ (y < x).
Proof.
rewrite /comparable lt_le_def.
by case: (x <= y) => //=; case: (y <= x).
Qed.
Lemma comparable_ltNge x y : x >=< y -> (x < y) = ~~ (y <= x).
Proof.
rewrite /comparable lt_le_def.
by case: (x <= y) => //=; case: (y <= x).
Qed.
Lemma comparable_sym x y : (y >=< x) = (x >=< y).
Proof. by rewrite /comparable orbC. Qed.
Lemma comparablexx x : x >=< x.
Proof. by rewrite /comparable lexx. Qed.
Lemma incomparable_eqF x y : (x >< y) -> (x == y) = false.
Proof. by apply: contraNF => /eqP ->; rewrite comparablexx. Qed.
Lemma incomparable_leF x y : (x >< y) -> (x <= y) = false.
Proof. by apply: contraNF; rewrite /comparable => ->. Qed.
Lemma incomparable_ltF x y : (x >< y) -> (x < y) = false.
Proof. by rewrite lt_le_def => /incomparable_leF ->. Qed.
Lemma le_comparable (x y : T) : x <= y -> x >=< y.
Proof. by rewrite /comparable => ->. Qed.
Lemma lt_comparable (x y : T) : x < y -> x >=< y.
Proof. by rewrite /comparable => /ltW ->. Qed.
Lemma ge_comparable (x y : T) : y <= x -> x >=< y.
Proof. by rewrite /comparable orbC => ->. Qed.
Lemma gt_comparable (x y : T) : y < x -> x >=< y.
Proof. by rewrite /comparable orbC => /ltW ->. Qed.
(* leif *)
Lemma leif_refl x C : reflect (x <= x ?= iff C) C.
Proof. by apply: (iffP idP) => [-> | <-] //; split; rewrite ?eqxx. Qed.
Lemma eq_leif x y C : x <= y ?= iff C -> (x == y) = C.
Proof. by move=> []. Qed.
Lemma eqTleif x y C : x <= y ?= iff C -> C -> x = y.
Proof. by move=> [] _ <- /eqP. Qed.
(* lteif *)
Lemma lteif_trans x y z C1 C2 :
x < y ?<= if C1 -> y < z ?<= if C2 -> x < z ?<= if C1 && C2.
Proof.
case: C1 C2 => [][];
[exact: le_trans | exact: le_lt_trans | exact: lt_le_trans | exact: lt_trans].
Qed.
Lemma lteifxx x C : (x < x ?<= if C) = C.
Proof. by case: C; rewrite /= ltexx. Qed.
Lemma lteifNF x y C : y < x ?<= if ~~ C -> x < y ?<= if C = false.
Proof. by case: C => [/lt_geF|/le_gtF]. Qed.
Lemma lteifS x y C : x < y -> x < y ?<= if C.
Proof. by case: C => //= /ltW. Qed.
Lemma lteifT x y : x < y ?<= if true = (x <= y). Proof. by []. Qed.
Lemma lteifF x y : x < y ?<= if false = (x < y). Proof. by []. Qed.
Lemma lteif_orb x y : {morph lteif x y : p q / p || q}.
Proof.
case=> [][] /=.
- by rewrite orbb.
- by case/boolP: (x < y) => [/ltW -> //|_]; rewrite orbF.
- by case/boolP: (x < y) => [/ltW ->|].
- by rewrite orbb.
Qed.
Lemma lteif_andb x y : {morph lteif x y : p q / p && q}.
Proof.
case=> [][] /=.
- by rewrite andbb.
- by rewrite lt_le_def andbA andbb.
- by rewrite andbC lt_le_def andbA andbb.
- by rewrite andbb.
Qed.
Lemma lteif_imply C1 C2 x y : C1 ==> C2 -> x < y ?<= if C1 -> x < y ?<= if C2.
Proof. by case: C1 C2 => [][] //= _ /ltW. Qed.
Lemma lteifW C x y : x < y ?<= if C -> x <= y.
Proof. by case: C => // /ltW. Qed.
Lemma ltrW_lteif C x y : x < y -> x < y ?<= if C.
Proof. by case: C => // /ltW. Qed.
(* min and max *)
Lemma minElt x y : min x y = if x < y then x else y. Proof. by []. Qed.
Lemma maxElt x y : max x y = if x < y then y else x. Proof. by []. Qed.
Lemma minxx : idempotent_op (min : T -> T -> T).
Proof. by rewrite /min => x; rewrite ltxx. Qed.
Lemma maxxx : idempotent_op (max : T -> T -> T).
Proof. by rewrite /max => x; rewrite ltxx. Qed.
Lemma min_minKx x y : min (min x y) y = min x y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma min_minxK x y : min x (min x y) = min x y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma max_maxKx x y : max (max x y) y = max x y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma max_maxxK x y : max x (max x y) = max x y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma comparable_minl z : {in >=< z &, forall x y, min x y >=< z}.
Proof. by move=> x y cmp_xz cmp_yz; rewrite /min; case: ifP. Qed.
Lemma comparable_minr z : {in >=<%O z &, forall x y, z >=< min x y}.
Proof. by move=> x y cmp_xz cmp_yz; rewrite /min; case: ifP. Qed.
Lemma comparable_maxl z : {in >=< z &, forall x y, max x y >=< z}.
Proof. by move=> x y cmp_xz cmp_yz; rewrite /max; case: ifP. Qed.
Lemma comparable_maxr z : {in >=<%O z &, forall x y, z >=< max x y}.
Proof. by move=> x y cmp_xz cmp_yz; rewrite /max; case: ifP. Qed.
Section Comparable2.
Variables (z x y : T) (cmp_xy : x >=< y).
Lemma comparable_le_min : (z <= min x y) = (z <= x) && (z <= y).
Proof.
move: cmp_xy; rewrite /min /comparable lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- by rewrite andbC; case/boolP: (z <= y) => zy //=; apply/esym/(le_trans zy).
- by case/boolP: (z <= x) => zx //=; apply/esym/(le_trans zx).
- by rewrite andbC; case/boolP: (z <= y) => zy //=; apply/esym/(le_trans zy).
Qed.
Lemma comparable_ge_min : (min x y <= z) = (x <= z) || (y <= z).
Proof.
move: cmp_xy; rewrite /min /comparable lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- rewrite orbC; case/boolP: (y <= z) => //= /negP yz.
by apply/esym/negP => /(le_trans yx).
- by case/boolP: (x <= z) => //= /negP xz; apply/esym/negP => /(le_trans xy).
- rewrite orbC; case/boolP: (y <= z) => //= /negP yz.
by apply/esym/negP => /(le_trans yx).
Qed.
Lemma comparable_lt_min : (z < min x y) = (z < x) && (z < y).
Proof.
move: cmp_xy; rewrite /min /comparable !lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx.
by apply/negP => zy; apply/zx/(lt_le_trans zy).
- rewrite -!lt_le_def; case/boolP: (z < x) => //= zx; apply/esym/(lt_trans zx).
by rewrite lt_le_def xy yx.
- rewrite -!lt_le_def andbC; case/boolP: (z < y) => //= zy; apply/esym/(lt_trans zy).
by rewrite lt_le_def xy yx.
Qed.
Lemma comparable_gt_min : (min x y < z) = (x < z) || (y < z).
Proof.
move: cmp_xy; rewrite /min /comparable !lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- rewrite -!lt_le_def orbC; case/boolP: (y < z) => //= /negP yz.
by apply/esym/negP => xz; apply/yz/(le_lt_trans yx).
- rewrite -!lt_le_def; case/boolP: (x < z) => //= /negP xz.
by apply/esym/negP => yz; apply/xz/(le_lt_trans xy).
- rewrite -!lt_le_def orbC; case/boolP: (y < z) => //= /negP yz.
by apply/esym/negP => xz; apply/yz/(le_lt_trans yx).
Qed.
Lemma comparable_le_max : (z <= max x y) = (z <= x) || (z <= y).
Proof.
move: cmp_xy; rewrite /max /comparable lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- case/boolP: (z <= x) => //= /negP zx.
by apply/esym/negP => zy; apply/zx/(le_trans zy).
- rewrite orbC; case/boolP: (z <= y) => //= /negP zy.
by apply/esym/negP => zx; apply/zy/(le_trans zx).
- case/boolP: (z <= x) => //= /negP zx.
by apply/esym/negP => zy; apply/zx/(le_trans zy).
Qed.
Lemma comparable_ge_max : (max x y <= z) = (x <= z) && (y <= z).
Proof.
move: cmp_xy; rewrite /max /comparable lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- case/boolP: (x <= z) => //= xz.
by apply/esym/(le_trans yx).
- rewrite andbC; case/boolP: (y <= z) => //= yz.
by apply/esym/(le_trans xy).
- case/boolP: (x <= z) => //= xz.
by apply/esym/(le_trans yx).
Qed.
Lemma comparable_lt_max : (z < max x y) = (z < x) || (z < y).
Proof.
move: cmp_xy; rewrite /max /comparable !lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx.
by apply/esym/negP => zy; apply/zx/(lt_le_trans zy).
- rewrite -!lt_le_def orbC; case/boolP: (z < y) => //= /negP zy.
by apply/esym/negP => zx; apply/zy/(lt_le_trans zx).
- rewrite -!lt_le_def; case/boolP: (z < x) => //= /negP zx.
by apply/esym/negP => zy; apply/zx/(lt_le_trans zy).
Qed.
Lemma comparable_gt_max : (max x y < z) = (x < z) && (y < z).
Proof.
move: cmp_xy; rewrite /max /comparable !lt_le_def.
case/boolP: (x <= y) => xy/=; case/boolP: (y <= x) => yx//= _.
- rewrite -!lt_le_def; case/boolP: (x < z) => //= xz.
by apply/esym/(le_lt_trans yx).
- rewrite -!lt_le_def andbC; case/boolP: (y < z) => //= yz.
by apply/esym/(le_lt_trans xy).
- rewrite -!lt_le_def; case/boolP: (x < z) => //= xz.
by apply/esym/(le_lt_trans yx).
Qed.
Lemma comparable_minxK : max (min x y) y = y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma comparable_minKx : max x (min x y) = x.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma comparable_maxxK : min (max x y) y = y.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma comparable_maxKx : min x (max x y) = x.
Proof. by rewrite !(fun_if, if_arg) ltxx/=; case: (x < y). Qed.
Lemma comparable_lteif_minr C :
(z < min x y ?<= if C) = (z < x ?<= if C) && (z < y ?<= if C).
Proof. by case: C; rewrite /= (comparable_le_min, comparable_lt_min). Qed.
Lemma comparable_lteif_minl C :
(min x y < z ?<= if C) = (x < z ?<= if C) || (y < z ?<= if C).
Proof. by case: C; rewrite /= (comparable_ge_min, comparable_gt_min). Qed.
Lemma comparable_lteif_maxr C :
(z < max x y ?<= if C) = (z < x ?<= if C) || (z < y ?<= if C).
Proof. by case: C; rewrite /= (comparable_le_max, comparable_lt_max). Qed.
Lemma comparable_lteif_maxl C :
(max x y < z ?<= if C) = (x < z ?<= if C) && (y < z ?<= if C).
Proof. by case: C; rewrite /= (comparable_ge_max, comparable_gt_max). Qed.
End Comparable2.
Section Comparable3.
Variables (x y z : T) (cmp_xy : x >=< y) (cmp_xz : x >=< z) (cmp_yz : y >=< z).
Lemma comparable_minA : min x (min y z) = min (min x y) z.
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def.
case/boolP: (x <= y) => xy;
case/boolP: (y <= x) => yx;
case/boolP: (x <= z) => xz;
case/boolP: (z <= x) => zx;
case/boolP: (y <= z) => yz;
case/boolP: (z <= y) => zy //= _ _ _.
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
- by move: zy; rewrite (le_trans zx xy).
- by move: zy; rewrite (le_trans zx xy).
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
Qed.
Lemma comparable_maxA : max x (max y z) = max (max x y) z.
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def.
case/boolP: (x <= y) => xy;
case/boolP: (y <= x) => yx;
case/boolP: (x <= z) => xz;
case/boolP: (z <= x) => zx;
case/boolP: (y <= z) => yz;
case/boolP: (z <= y) => zy //= _ _ _.
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
- by move: zy; rewrite (le_trans zx xy).
- by move: zy; rewrite (le_trans zx xy).
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
Qed.
Lemma comparable_min_maxl : min (max x y) z = max (min x z) (min y z).
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def.
case/boolP: (x <= y) => xy;
case/boolP: (y <= x) => yx;
case/boolP: (x <= z) => xz;
case/boolP: (z <= x) => zx;
case/boolP: (y <= z) => yz;
case/boolP: (z <= y) => zy;
rewrite ?lexx => //= _ _ _.
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
- by move: zy; rewrite (le_trans zx xy).
- by move: zy; rewrite (le_trans zx xy).
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
Qed.
Lemma comparable_max_minr :
max x (min y z) = min (max x y) (max x z).
Proof.
move: cmp_xy cmp_xz cmp_yz; rewrite !(fun_if, if_arg)/= !lt_le_def.
case/boolP: (x <= y) => xy;
case/boolP: (y <= x) => yx;
case/boolP: (x <= z) => xz;
case/boolP: (z <= x) => zx;
case/boolP: (y <= z) => yz;
case/boolP: (z <= y) => zy;
rewrite ?lexx => //= _ _ _.
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
- by move: zy; rewrite (le_trans zx xy).
- by move: zy; rewrite (le_trans zx xy).
- by move: zx; rewrite (le_trans zy yx).
- by move: zx; rewrite (le_trans zy yx).
Qed.
End Comparable3.
Section ArgExtremum.
Context (I : finType) (i0 : I) (P : {pred I}) (F : I -> T) (Pi0 : P i0).
Hypothesis F_comparable : {in P &, forall i j, F i >=< F j}.
Lemma comparable_arg_minP: extremum_spec <=%O P F (arg_min i0 P F).
Proof.
by apply: extremum_inP => // [x _|y x z _ _ _]; [apply: lexx|apply: le_trans].
Qed.
Lemma comparable_arg_maxP: extremum_spec >=%O P F (arg_max i0 P F).
Proof.
apply: extremum_inP => // [x _|y x z _ _ _|]; [exact: lexx|exact: ge_trans|].
by move=> x y xP yP; rewrite orbC [_ || _]F_comparable.
Qed.
End ArgExtremum.
(* monotonicity *)
Lemma comparable_bigl x x0 op I (P : pred I) F (s : seq I) :
{in >=< x &, forall y z, op y z >=< x} -> x0 >=< x ->
{in P, forall i, F i >=< x} -> \big[op/x0]_(i <- s | P i) F i >=< x.
Proof. by move=> *; elim/big_ind : _. Qed.
Lemma comparable_bigr x x0 op I (P : pred I) F (s : seq I) :
{in >=<%O x &, forall y z, x >=< op y z} -> x >=< x0 ->
{in P, forall i, x >=< F i} -> x >=< \big[op/x0]_(i <- s | P i) F i.
Proof. by move=> *; elim/big_ind : _. Qed.
Section bigminmax.
Variables (I : Type) (r : seq I) (f : I -> T) (x0 x : T) (P : pred I).
Lemma bigmax_lt : 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 maxElt; case: ifPn. Qed.
Lemma lt_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 minElt; case: ifPn. Qed.
End bigminmax.
End PreorderTheory.
#[global] Hint Resolve comparable_minr comparable_minl : core.
#[global] Hint Resolve comparable_maxr comparable_maxl : core.
Section ContraTheory.
Context {disp1 disp2 : disp_t} {T1 : preorderType disp1} {T2 : preorderType disp2}.
Implicit Types (x y : T1) (z t : T2) (b : bool) (m n : nat) (P : Prop).
Lemma comparable_contraTle b x y : x >=< y -> (y < x -> ~~ b) -> (b -> x <= y).
Proof. by move=> /comparable_leNgt ->; case: (y < x); case: b. Qed.
Lemma comparable_contraTlt b x y : x >=< y -> (y <= x -> ~~ b) -> (b -> x < y).
Proof. by move=> /comparable_ltNge ->; case: (y <= x); case: b. Qed.
Lemma comparable_contraPle P x y : x >=< y -> (y < x -> ~ P) -> (P -> x <= y).
Proof. by move=> /comparable_leNgt -> np p; apply/negP => /np. Qed.
Lemma comparable_contraPlt P x y : x >=< y -> (y <= x -> ~ P) -> (P -> x < y).
Proof. by move=> /comparable_ltNge -> np p; apply/negP => /np. Qed.
Lemma comparable_contraNle b x y : x >=< y -> (y < x -> b) -> (~~ b -> x <= y).
Proof. by move=> /comparable_leNgt ->; case: (y < x); case: b. Qed.
Lemma comparable_contraNlt b x y : x >=< y -> (y <= x -> b) -> (~~ b -> x < y).
Proof. by move=> /comparable_ltNge ->; case: (y <= x); case: b. Qed.
Lemma comparable_contra_not_le P x y : x >=< y -> (y < x -> P) -> (~ P -> x <= y).
Proof. by move=> /comparable_leNgt -> np p; apply/negP => /np. Qed.
Lemma comparable_contra_not_lt P x y : x >=< y -> (y <= x -> P) -> (~ P -> x < y).
Proof. by move=> /comparable_ltNge -> np p; apply/negP => /np. Qed.
Lemma comparable_contraFle b x y : x >=< y -> (y < x -> b) -> (b = false -> x <= y).
Proof. by move=> /comparable_leNgt -> np /negP p; apply/negP => /np. Qed.
Lemma comparable_contraFlt b x y : x >=< y -> (y <= x -> b) -> (b = false -> x < y).
Proof. by move=> /comparable_ltNge -> np /negP p; apply/negP => /np. Qed.
Lemma comparable_contra_leq_le m n x y : x >=< y ->
(y < x -> (n < m)%N) -> ((m <= n)%N -> x <= y).
Proof. by rewrite ltnNge; apply/comparable_contraTle. Qed.
Lemma comparable_contra_leq_lt m n x y : x >=< y ->
(y <= x -> (n < m)%N) -> ((m <= n)%N -> x < y).
Proof. by rewrite ltnNge; apply/comparable_contraTlt. Qed.
Lemma comparable_contra_ltn_le m n x y : x >=< y ->
(y < x -> (n <= m)%N) -> ((m < n)%N -> x <= y).
Proof. by rewrite ltnNge; apply/comparable_contraNle. Qed.
Lemma comparable_contra_ltn_lt m n x y : x >=< y ->
(y <= x -> (n <= m)%N) -> ((m < n)%N -> x < y).
Proof. by rewrite ltnNge; apply/comparable_contraNlt. Qed.
Lemma comparable_contra_le x y z t : z >=< t ->
(t < z -> y < x) -> (x <= y -> z <= t).
Proof.
rewrite /comparable lt_le_def; case: (z <= t) => //= -> /(_ erefl) yx.
by move=> /(lt_le_trans yx); rewrite ltxx.
Qed.
Lemma comparable_contra_le_lt x y z t : z >=< t ->
(t <= z -> y < x) -> (x <= y -> z < t).
Proof.
rewrite /comparable [z < t]lt_le_def orbC; case: (t <= z) => /= [_|-> //].
by move=> /(_ erefl) yx /(lt_le_trans yx); rewrite ltxx.
Qed.
Lemma comparable_contra_lt_le x y z t : z >=< t ->
(t < z -> y <= x) -> (x < y -> z <= t).
Proof.
rewrite /comparable lt_le_def; case: (z <= t) => //= -> /(_ erefl) yx.
by move=> /(le_lt_trans yx); rewrite ltxx.
Qed.
Lemma comparable_contra_lt x y z t : z >=< t ->
(t <= z -> y <= x) -> (x < y -> z < t).
Proof.
rewrite /comparable [z < t]lt_le_def orbC; case: (t <= z) => /= [_|-> //].
by move=> /(_ erefl) yx /(le_lt_trans yx); rewrite ltxx.
Qed.
End ContraTheory.
Section PreorderMonotonyTheory.
Context {disp disp' : disp_t}.
Context {T : preorderType disp} {T' : preorderType disp'}.
Implicit Types (m n p : nat) (x y z : T) (u v w : T').
Variables (D D' : {pred T}) (f : T -> T').
Hint Resolve lexx lt_le_def : core.
Lemma leW_mono : {mono f : x y / x <= y} -> {mono f : x y / x < y}.
Proof. by move=> fmono x y; rewrite !lt_le_def !fmono. Qed.
Lemma leW_nmono : {mono f : x y /~ x <= y} -> {mono f : x y /~ x < y}.
Proof. by move=> fmono x y; rewrite !lt_le_def !fmono. Qed.
Lemma leW_mono_in :
{in D &, {mono f : x y / x <= y}} -> {in D &, {mono f : x y / x < y}}.
Proof. by move=> fmono x y xD yD; rewrite !lt_le_def !fmono. Qed.
Lemma leW_nmono_in :
{in D &, {mono f : x y /~ x <= y}} -> {in D &, {mono f : x y /~ x < y}}.
Proof. by move=> fmono x y xD yD; rewrite !lt_le_def !fmono. Qed.
End PreorderMonotonyTheory.
End PreorderTheory.
#[global] Hint Resolve lexx le_refl ltxx lt_irreflexive ltW lt_eqF : core.
Arguments leif_refl {disp T x C}.
Module Import BPreorderTheory.
Section BPreorderTheory.
Context {disp : disp_t} {T : bPreorderType disp}.
Implicit Types (x y : T).
Lemma le0x x : \bot <= x. Proof. exact: le0x. Qed.
Lemma ltx0 x : (x < \bot) = false.
Proof. exact/le_gtF/le0x. Qed.
End BPreorderTheory.
End BPreorderTheory.
Module Import TPreorderTheory.
Section TPreorderTheory.
Context {disp : disp_t} {T : tPreorderType disp}.
Implicit Types (x y : T).
Lemma lex1 x : x <= \top. Proof. exact: lex1. Qed.
Lemma lt1x x : (\top < x) = false. Proof. exact: (@ltx0 _ T^d). Qed.
End TPreorderTheory.
End TPreorderTheory.
#[global] Hint Extern 0 (is_true (\bot <= _)) => exact: le0x : core.
#[global] Hint Extern 0 (is_true (_ <= \top)) => exact: lex1 : core.
(*************)
(* FACTORIES *)
(*************)
(* preorder *)
HB.factory Record isPreorder (d : disp_t) T of Equality T := {
le : rel T;
lt : rel T;
lt_def : forall x y, lt x y = (le x y) && ~~ (le y x);
le_refl : reflexive le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of isPreorder d T.
(* TODO: print nice error message when keyed type is not provided *)
Let ge_trans : transitive (fun x y => le y x).
Proof. by move=> x y z /[swap]; apply: le_trans. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @isDuallyPreorder.Build d T
le _ lt_def (fun x y => lt_def y x) le_refl le_refl le_trans ge_trans.
HB.end.
HB.factory Record Le_isPreorder (d : disp_t) T of Equality T := {
le : rel T;
le_refl : reflexive le;
le_trans : transitive le;
}.
HB.builders Context (d : disp_t) T of Le_isPreorder d T.
(* TODO: print nice error message when keyed type is not provided *)
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @isPreorder.Build d T
le _ (fun _ _ => erefl) le_refl le_trans.
HB.end.
HB.factory Record LtLe_isPreorder (d : disp_t) T of Equality 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_isPreorder d T.
Let le_refl : reflexive le. Proof. by move=> x; rewrite le_def eqxx. Qed.
Let le_trans : transitive le.
Proof.
move=> y x z; rewrite !le_def; case: (eqVneq x y) => [->|]//= neq_xy.
by case: (eqVneq y z) => /= [<- ->|_ /lt_trans yx /yx ->]; rewrite orbT.
Qed.
Let lt_le_def x y : lt x y = (le x y) && ~~ (le y x).
Proof.
rewrite !le_def eq_sym; have [->|_ /=] := eqVneq x y; first by rewrite lt_irr.
case/boolP: (lt x y) => //= xy; apply/esym/negP => /(lt_trans xy).
by rewrite lt_irr.
Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @isPreorder.Build d T
le lt lt_le_def le_refl le_trans .
HB.end.
HB.factory Record Lt_isPreorder (d : disp_t) T of Equality T := {
lt : rel T;
lt_irr : irreflexive lt;
lt_trans : transitive lt;
}.
HB.builders Context (d : disp_t) (T : Type) of Lt_isPreorder d T.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := @LtLe_isPreorder.Build d T
_ lt (fun _ _ => erefl) lt_irr lt_trans.
HB.end.
Module PreCancelPartial.
Section PreCancelPartial.
Variables (disp : disp_t) (T : choiceType).
Variables (disp' : disp_t) (T' : preorderType disp') (f : T -> T').
Definition le (x y : T) := f x <= f y.
Definition lt (x y : T) := f x < f y.
Fact refl : reflexive le. Proof. by move=> ?; apply: lexx. Qed.
Fact trans : transitive le. Proof. by move=> ? ? ?; apply: le_trans. Qed.
Fact ge_trans : transitive (fun x y => le y x). Proof. by move=> ? ? ?; apply: ge_trans. Qed.
Fact lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof. exact: lt_le_def. Qed.
Definition PrePcan := isPreorder.Build disp T lt_le_def refl trans.
End PreCancelPartial.
End PreCancelPartial.
(* FIXME
Fail #[export]
HB.instance Definition _ (disp : disp_t) (T : choiceType)
(disp' : disp_t) (T' : porderType disp') (f : T -> T')
(f_inj : injective f): isPreorder disp (inj_type f_inj) :=
@PreCancelPartial.PrePcan disp (inj_type f_inj) disp' T' f.
*)
#[export]
HB.instance Definition _ (disp : disp_t) (T : Type)
(disp' : disp_t) (T' : preorderType disp') (f : T -> T')
(f' : T' -> option T) (f_can : pcancel f f') : isPreorder disp (pcan_type f_can) :=
@PreCancelPartial.PrePcan disp (pcan_type f_can) disp' T' f.
#[export]
HB.instance Definition _ (disp : disp_t) (T : Type)
(disp' : disp_t) (T' : preorderType disp') (f : T -> T')
(f' : T' -> T) (f_can : cancel f f') : isPreorder disp (can_type f_can) :=
@PreCancelPartial.PrePcan disp (can_type f_can) disp' T' f.
(* Morphism hierarchy. *)
Definition order_morphism d (T : preorderType d) d' (T' : preorderType d')
(f : T -> T') : Prop := {mono f : x y / x <= y}.
HB.mixin Record isOrderMorphism d (T : preorderType d) d' (T' : preorderType d')
(apply : T -> T') := {
omorph_le_subproof : {homo apply : x y / x <= y} ;
}.
HB.structure Definition OrderMorphism d (T : preorderType d)
d' (T' : preorderType d') := {f of isOrderMorphism d T d' T' f}.
Module OrderMorphismExports.
Notation "{ 'omorphism' T -> T' }" :=
(@OrderMorphism.type _ T%type _ T'%type) : type_scope.
End OrderMorphismExports.
HB.export OrderMorphismExports.
Module Import OrderMorphismTheory.
Section OrderMorphismTheory.
Lemma omorph_le (d : disp_t) (T : preorderType d) (d' : disp_t) (T' : preorderType d')
(f : {omorphism T -> T'}) : {homo f : x y / x <= y}.
Proof. exact: omorph_le_subproof. Qed.
Section IdCompFun.
Variables (d : disp_t) (T : preorderType d) (d' : disp_t) (T' : preorderType d').
Variables (d'' : disp_t) (T'' : preorderType d'').
Variables (f : {omorphism T' -> T''}) (g : {omorphism T -> T'}).
Fact idfun_is_nondecreasing : nondecreasing (@idfun T).
Proof. by []. Qed.
#[export]
HB.instance Definition _ := isOrderMorphism.Build d T d T idfun
idfun_is_nondecreasing.
Fact comp_is_nondecreasing : nondecreasing (f \o g).
Proof. by move=> ? ? ?; do 2 apply: omorph_le. Qed.
#[export]
HB.instance Definition _ := isOrderMorphism.Build d T d'' T'' (f \o g)
comp_is_nondecreasing.
End IdCompFun.
End OrderMorphismTheory.
End OrderMorphismTheory.
HB.mixin Record isSubPreorder d (T : preorderType d) (S : pred T) d' U
of SubType T S U & Preorder d' U := {
le_val : {mono (val : U -> T) : x y / x <= y};
}.
#[short(type="subPreorder")]
HB.structure Definition SubPreorder d (T : preorderType d) S d' :=
{ U of SubEquality T S U & Preorder d' U & isSubPreorder d T S d' U }.
Module Import SubPreorderTheory.
Section SubPreorderTheory.
Context (d : disp_t) (T : preorderType d) (S : pred T).
Context (d' : disp_t) (U : SubPreorder.type S d').
Local Notation val := (val : U -> T).
#[deprecated(since="mathcomp 2.3.0", note="Use le_val instead.")]
Lemma leEsub x y : (x <= y) = (val x <= val y). Proof. by rewrite le_val. Qed.
Lemma lt_val : {mono val : x y / x < y}.
Proof. by move=> x y; rewrite !lt_leAnge !le_val. Qed.
#[deprecated(since="mathcomp 2.3.0", note="Use lt_val instead.")]
Lemma ltEsub x y : (x < y) = (val x < val y). Proof. by rewrite lt_val. Qed.
Lemma le_wval : {homo val : x y / x <= y}. Proof. exact/mono2W/le_val. Qed.
Lemma lt_wval : {homo val : x y / x < y}. Proof. exact/mono2W/lt_val. Qed.
HB.instance Definition _ := isOrderMorphism.Build d' U d T val le_wval.
End SubPreorderTheory.
Arguments lt_val {d T S d' U} x y.
Arguments le_wval {d T S d' U} x y.
Arguments lt_wval {d T S d' U} x y.
End SubPreorderTheory.
HB.factory Record SubChoice_isSubPreorder d (T : preorderType d) S (d' : disp_t) U
of SubChoice T S U := {}.
HB.builders Context d T S d' U of SubChoice_isSubPreorder d T S d' U.
HB.instance Definition _ : isPreorder d' U :=
@PreCancelPartial.PrePcan d' U d T val.
Fact valD : order_morphism (val : U -> T). Proof. by []. Qed.
HB.instance Definition _ := isSubPreorder.Build d T S d' U valD.
HB.end.
Module SubOrderExports.
Notation "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: ]" :=
(SubChoice_isSubPreorder.Build _ _ _ _ U)
(at level 0, format "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: 'with' disp ]" :=
(SubChoice_isSubPreorder.Build _ _ _ disp U)
(at level 0, format "[ 'SubChoice_isSubPreorder' 'of' U 'by' <: 'with' disp ]")
: form_scope.
End SubOrderExports.
HB.export SubOrderExports.
(*************)
(* 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.
Fact nat_display : disp_t. Proof. exact. Qed.
Lemma ltn_def x y : (x < y)%N = (x <= y)%N && ~~ (y <= x)%N.
Proof. by rewrite -ltnNge andbC; case: (ltnP x y) => //= /ltnW. Qed.
#[export]
HB.instance Definition _ :=
isPreorder.Build nat_display nat ltn_def leqnn leq_trans.
#[export]
HB.instance Definition _ := hasBottom.Build nat_display nat leq0n.
Lemma leEnat : le = leq. Proof. by []. Qed.
Lemma ltEnat : lt = ltn. Proof. by []. Qed.
Lemma minEnat : min = minn. Proof. by []. Qed.
Lemma maxEnat : max = maxn. Proof. by []. Qed.
Lemma botEnat : \bot = 0%N :> nat. Proof. by []. Qed.
End NatOrder.
Module Exports.
HB.reexport NatOrder.
Definition leEnat := leEnat.
Definition ltEnat := ltEnat.
Definition minEnat := minEnat.
Definition maxEnat := maxEnat.
Definition botEnat := botEnat.
End Exports.
End NatOrder.
HB.export NatOrder.Exports.
Module NatMonotonyTheory.
Section NatMonotonyTheory.
Context {disp : disp_t} {T : preorderType disp}.
Variables (D : {pred nat}) (f : nat -> T).
Hypothesis Dconvex : {in D &, forall i j k, i < k < j -> k \in D}.
Lemma homo_ltn_lt_in : {in D, forall i, i.+1 \in D -> f i < f i.+1} ->
{in D &, {homo f : i j / i < j}}.
Proof. by apply: homo_ltn_in Dconvex; apply: lt_trans. Qed.
Lemma nondecn_inP : {in D, forall i, i.+1 \in D -> f i <= f i.+1} ->
{in D &, {homo f : i j / i <= j}}.
Proof. by apply: homo_leq_in Dconvex => //; apply: le_trans. Qed.
Lemma nhomo_ltn_lt_in : {in D, forall i, i.+1 \in D -> f i > f i.+1} ->
{in D &, {homo f : i j /~ i < j}}.
Proof.
move=> f_dec; apply: homo_sym_in.
by apply: homo_ltn_in Dconvex f_dec => ? ? ? ? /lt_trans->.
Qed.
Lemma nonincn_inP : {in D, forall i, i.+1 \in D -> f i >= f i.+1} ->
{in D &, {homo f : i j /~ i <= j}}.
Proof.
move=> /= f_dec; apply: homo_sym_in.
by apply: homo_leq_in Dconvex f_dec => //= ? ? ? ? /le_trans->.
Qed.
Lemma homo_ltn_lt : (forall i, f i < f i.+1) -> {homo f : i j / i < j}.
Proof. by apply: homo_ltn; apply: lt_trans. Qed.
Lemma nondecnP : (forall i, f i <= f i.+1) -> {homo f : i j / i <= j}.
Proof. by apply: homo_leq => //; apply: le_trans. Qed.
Lemma nhomo_ltn_lt : (forall i, f i > f i.+1) -> {homo f : i j /~ i < j}.
Proof.
move=> f_dec; apply: homo_sym.
by apply: homo_ltn f_dec => ? ? ? ? /lt_trans->.
Qed.
Lemma nonincnP : (forall i, f i >= f i.+1) -> {homo f : i j /~ i <= j}.
Proof.
move=> /= f_dec; apply: homo_sym.
by apply: homo_leq f_dec => //= ? ? ? ? /le_trans->.
Qed.
End NatMonotonyTheory.
Arguments homo_ltn_lt_in {disp T} [D f].
Arguments nondecn_inP {disp T} [D f].
Arguments nhomo_ltn_lt_in {disp T} [D f].
Arguments nonincn_inP {disp T} [D f].
Arguments homo_ltn_lt {disp T} [f].
Arguments nondecnP {disp T} [f].
Arguments nhomo_ltn_lt {disp T} [f].
Arguments nonincnP {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. *)
(****************************************************************************)
Fact dvd_display : disp_t. Proof. exact. Qed.
Module DvdSyntax.
Notation dvd := (@le dvd_display _).
Notation "@ 'dvd' T" := (@le dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation sdvd := (@lt dvd_display _).
Notation "@ 'sdvd' T" := (@lt dvd_display T)
(at level 10, T at level 8, only parsing) : function_scope.
Notation "x %| y" := (dvd x y) : order_scope.
Notation "x %<| y" := (sdvd x y) : order_scope.
Notation nat0 := (@top dvd_display _).
Notation nat1 := (@bottom dvd_display _).
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.
Section NatDvd.
Implicit Types (m n p : nat).
Definition t := nat.
#[export]
HB.instance Definition _ := Choice.copy t nat.
(* Note that this where the dvd_display is associated with the type NatDvd.t. *)
#[export]
HB.instance Definition _ := @Le_isPreorder.Build
dvd_display t dvdn dvdnn dvdn_trans.
(* NatDvd.t is associated below with the notation "natdvd". *)
#[export]
HB.instance Definition _ := @hasBottom.Build _ t 1 dvd1n.
#[export]
HB.instance Definition _ := @hasTop.Build _ t 0 dvdn0.
Import DvdSyntax.
Lemma dvdE : dvd = dvdn :> rel t. Proof. by []. Qed.
Lemma nat1E : nat1 = 1%N :> t. Proof. by []. Qed.
Lemma nat0E : nat0 = 0%N :> t. Proof. by []. Qed.
End NatDvd.
Module Exports.
HB.reexport NatDvd.
Notation natdvd := t.
Definition dvdEnat := dvdE.
Definition nat1E := nat1E.
Definition nat0E := nat0E.
End Exports.
End NatDvd.
HB.export NatDvd.Exports.
(************************)
(* Instances on ordinal *)
(************************)
Module OrdinalOrder.
Section OrdinalOrder.
Fact ord_display : disp_t. Proof. exact. Qed.
Section PossiblyTrivial.
Context (n : nat).
#[export]
HB.instance Definition _ :=
[SubChoice_isSubPreorder of 'I_n by <: with ord_display].
Lemma leEord : (le : rel 'I_n) = leq. Proof. by []. Qed.
Lemma ltEord : (lt : rel 'I_n) = (fun m n => m < n)%N. Proof. by []. Qed.
End PossiblyTrivial.
Section NonTrivial.
Context (n' : nat).
Let n := n'.+1.
#[export] HB.instance Definition _ := @hasBottom.Build _ 'I_n ord0 leq0n.
#[export] HB.instance Definition _ := @hasTop.Build _ 'I_n ord_max (@leq_ord _).
Lemma botEord : \bot = ord0. Proof. by []. Qed.
Lemma topEord : \top = ord_max. Proof. by []. Qed.
End NonTrivial.
End OrdinalOrder.
Module Exports.
HB.reexport OrdinalOrder.
Definition leEord := leEord.
Definition ltEord := ltEord.
Definition botEord := botEord.
Definition topEord := topEord.
End Exports.
End OrdinalOrder.
HB.export OrdinalOrder.Exports.
(*********************)
(* Instances on bool *)
(*********************)
Module BoolOrder.
Section BoolOrder.
Implicit Types (x y : bool).
Fact bool_display : disp_t. Proof. exact. Qed.
Fact ltn_def x y : (x < y)%N = (x <= y)%N && ~~ (y <= x)%N.
Proof. by case: x y => [] []. Qed.
#[export] HB.instance Definition _ := @isPreorder.Build bool_display bool
_ _ ltn_def leqnn leq_trans.
#[export] HB.instance Definition _ := @hasBottom.Build _ bool false leq0n.
#[export] HB.instance Definition _ := @hasTop.Build _ bool true leq_b1.
Lemma leEbool : le = (leq : rel bool). Proof. by []. Qed.
Lemma ltEbool x y : (x < y) = (x < y)%N. Proof. by []. Qed.
End BoolOrder.
Module Exports.
HB.reexport BoolOrder.
Definition leEbool := leEbool.
Definition ltEbool := ltEbool.
End Exports.
End BoolOrder.
HB.export BoolOrder.Exports.
(******************************)
(* Definition of prod_display *)
(******************************)
Fact prod_display_unit (_ _ : unit) : unit. Proof. exact: tt. Qed.
Definition prod_display (displ dispr : disp_t) : disp_t :=
Disp (prod_display_unit (d1 displ) (d1 dispr))
(prod_display_unit (d2 displ) (d2 dispr)).
Fact seqprod_display (disp : disp_t) : disp_t. Proof. exact: disp. Qed.
Module Import ProdSyntax.
Notation "<=^p%O" := (@le (prod_display _ _) _) : function_scope.
Notation ">=^p%O" := (@ge (prod_display _ _) _) : function_scope.
Notation ">=^p%O" := (@ge (prod_display _ _) _) : function_scope.
Notation "<^p%O" := (@lt (prod_display _ _) _) : function_scope.
Notation ">^p%O" := (@gt (prod_display _ _) _) : function_scope.
Notation "<?=^p%O" := (@leif (prod_display _ _) _) : function_scope.
Notation ">=<^p%O" := (@comparable (prod_display _ _) _) : function_scope.
Notation "><^p%O" := (fun x y => ~~ (@comparable (prod_display _ _) _ x y)) :
function_scope.
Notation "<=^p y" := (>=^p%O y) : order_scope.
Notation "<=^p y :> T" := (<=^p (y : T)) (only parsing) : order_scope.
Notation ">=^p y" := (<=^p%O y) : order_scope.
Notation ">=^p y :> T" := (>=^p (y : T)) (only parsing) : order_scope.
Notation "<^p y" := (>^p%O y) : order_scope.
Notation "<^p y :> T" := (<^p (y : T)) (only parsing) : order_scope.
Notation ">^p y" := (<^p%O y) : order_scope.
Notation ">^p y :> T" := (>^p (y : T)) (only parsing) : order_scope.
Notation "x <=^p y" := (<=^p%O x y) : order_scope.
Notation "x <=^p y :> T" := ((x : T) <=^p (y : T)) (only parsing) : order_scope.
Notation "x >=^p y" := (y <=^p x) (only parsing) : order_scope.
Notation "x >=^p y :> T" := ((x : T) >=^p (y : T)) (only parsing) : order_scope.
Notation "x <^p y" := (<^p%O x y) : order_scope.
Notation "x <^p y :> T" := ((x : T) <^p (y : T)) (only parsing) : order_scope.
Notation "x >^p y" := (y <^p x) (only parsing) : order_scope.
Notation "x >^p y :> T" := ((x : T) >^p (y : T)) (only parsing) : order_scope.
Notation "x <=^p y <=^p z" := ((x <=^p y) && (y <=^p z)) : order_scope.
Notation "x <^p y <=^p z" := ((x <^p y) && (y <=^p z)) : order_scope.
Notation "x <=^p y <^p z" := ((x <=^p y) && (y <^p z)) : order_scope.
Notation "x <^p y <^p z" := ((x <^p y) && (y <^p z)) : order_scope.
Notation "x <=^p y ?= 'iff' C" := (<?=^p%O x y C) : order_scope.
Notation "x <=^p y ?= 'iff' C :> T" := ((x : T) <=^p (y : T) ?= iff C)
(only parsing) : order_scope.
Notation ">=<^p y" := [pred x | >=<^p%O x y] : order_scope.
Notation ">=<^p y :> T" := (>=<^p (y : T)) (only parsing) : order_scope.
Notation "x >=<^p y" := (>=<^p%O x y) : order_scope.
Notation "><^p y" := [pred x | ~~ (>=<^p%O x y)] : order_scope.
Notation "><^p y :> T" := (><^p (y : T)) (only parsing) : order_scope.
Notation "x ><^p y" := (~~ (><^p%O x y)) : order_scope.
End ProdSyntax.
Module Import SeqProdSyntax.
Notation "<=^sp%O" := (@le (seqprod_display _) _) : function_scope.
Notation ">=^sp%O" := (@ge (seqprod_display _) _) : function_scope.
Notation ">=^sp%O" := (@ge (seqprod_display _) _) : function_scope.
Notation "<^sp%O" := (@lt (seqprod_display _) _) : function_scope.
Notation ">^sp%O" := (@gt (seqprod_display _) _) : function_scope.
Notation "<?=^sp%O" := (@leif (seqprod_display _) _) : function_scope.
Notation ">=<^sp%O" := (@comparable (seqprod_display _) _) : function_scope.
Notation "><^sp%O" := (fun x y => ~~ (@comparable (seqprod_display _) _ x y)) :
function_scope.
Notation "<=^sp y" := (>=^sp%O y) : order_scope.
Notation "<=^sp y :> T" := (<=^sp (y : T)) (only parsing) : order_scope.
Notation ">=^sp y" := (<=^sp%O y) : order_scope.
Notation ">=^sp y :> T" := (>=^sp (y : T)) (only parsing) : order_scope.
Notation "<^sp y" := (>^sp%O y) : order_scope.
Notation "<^sp y :> T" := (<^sp (y : T)) (only parsing) : order_scope.
Notation ">^sp y" := (<^sp%O y) : order_scope.
Notation ">^sp y :> T" := (>^sp (y : T)) (only parsing) : order_scope.
Notation "x <=^sp y" := (<=^sp%O x y) : order_scope.
Notation "x <=^sp y :> T" := ((x : T) <=^sp (y : T)) (only parsing) : order_scope.
Notation "x >=^sp y" := (y <=^sp x) (only parsing) : order_scope.
Notation "x >=^sp y :> T" := ((x : T) >=^sp (y : T)) (only parsing) : order_scope.
Notation "x <^sp y" := (<^sp%O x y) : order_scope.
Notation "x <^sp y :> T" := ((x : T) <^sp (y : T)) (only parsing) : order_scope.
Notation "x >^sp y" := (y <^sp x) (only parsing) : order_scope.
Notation "x >^sp y :> T" := ((x : T) >^sp (y : T)) (only parsing) : order_scope.
Notation "x <=^sp y <=^sp z" := ((x <=^sp y) && (y <=^sp z)) : order_scope.
Notation "x <^sp y <=^sp z" := ((x <^sp y) && (y <=^sp z)) : order_scope.
Notation "x <=^sp y <^sp z" := ((x <=^sp y) && (y <^sp z)) : order_scope.
Notation "x <^sp y <^sp z" := ((x <^sp y) && (y <^sp z)) : order_scope.
Notation "x <=^sp y ?= 'iff' C" := (<?=^sp%O x y C) : order_scope.
Notation "x <=^sp y ?= 'iff' C :> T" := ((x : T) <=^sp (y : T) ?= iff C)
(only parsing) : order_scope.
Notation ">=<^sp y" := [pred x | >=<^sp%O x y] : order_scope.
Notation ">=<^sp y :> T" := (>=<^sp (y : T)) (only parsing) : order_scope.
Notation "x >=<^sp y" := (>=<^sp%O x y) : order_scope.
Notation "><^sp y" := [pred x | ~~ (>=<^sp%O x y)] : order_scope.
Notation "><^sp y :> T" := (><^sp (y : T)) (only parsing) : order_scope.
Notation "x ><^sp y" := (~~ (><^sp%O x y)) : order_scope.
End SeqProdSyntax.
(******************************)
(* Definition of lexi_display *)
(******************************)
Fact lexi_display (disp _ : disp_t) : disp_t. Proof. exact: disp. Qed.
Fact seqlexi_display (disp : disp_t) : disp_t. Proof. exact: disp. Qed.
Module Import LexiSyntax.
Notation "<=^l%O" := (@le (lexi_display _ _) _) : function_scope.
Notation ">=^l%O" := (@ge (lexi_display _ _) _) : function_scope.
Notation ">=^l%O" := (@ge (lexi_display _ _) _) : function_scope.
Notation "<^l%O" := (@lt (lexi_display _ _) _) : function_scope.
Notation ">^l%O" := (@gt (lexi_display _ _) _) : function_scope.
Notation "<?=^l%O" := (@leif (lexi_display _ _) _) : function_scope.
Notation ">=<^l%O" := (@comparable (lexi_display _ _) _) : function_scope.
Notation "><^l%O" := (fun x y => ~~ (@comparable (lexi_display _ _) _ x y)) :
function_scope.
Notation "<=^l y" := (>=^l%O y) : order_scope.
Notation "<=^l y :> T" := (<=^l (y : T)) (only parsing) : order_scope.
Notation ">=^l y" := (<=^l%O y) : order_scope.
Notation ">=^l y :> T" := (>=^l (y : T)) (only parsing) : order_scope.
Notation "<^l y" := (>^l%O y) : order_scope.
Notation "<^l y :> T" := (<^l (y : T)) (only parsing) : order_scope.
Notation ">^l y" := (<^l%O y) : order_scope.
Notation ">^l y :> T" := (>^l (y : T)) (only parsing) : order_scope.
Notation "x <=^l y" := (<=^l%O x y) : order_scope.
Notation "x <=^l y :> T" := ((x : T) <=^l (y : T)) (only parsing) : order_scope.
Notation "x >=^l y" := (y <=^l x) (only parsing) : order_scope.
Notation "x >=^l y :> T" := ((x : T) >=^l (y : T)) (only parsing) : order_scope.
Notation "x <^l y" := (<^l%O x y) : order_scope.
Notation "x <^l y :> T" := ((x : T) <^l (y : T)) (only parsing) : order_scope.
Notation "x >^l y" := (y <^l x) (only parsing) : order_scope.
Notation "x >^l y :> T" := ((x : T) >^l (y : T)) (only parsing) : order_scope.
Notation "x <=^l y <=^l z" := ((x <=^l y) && (y <=^l z)) : order_scope.
Notation "x <^l y <=^l z" := ((x <^l y) && (y <=^l z)) : order_scope.
Notation "x <=^l y <^l z" := ((x <=^l y) && (y <^l z)) : order_scope.
Notation "x <^l y <^l z" := ((x <^l y) && (y <^l z)) : order_scope.
Notation "x <=^l y ?= 'iff' C" := (<?=^l%O x y C) : order_scope.
Notation "x <=^l y ?= 'iff' C :> T" := ((x : T) <=^l (y : T) ?= iff C)
(only parsing) : order_scope.
Notation ">=<^l y" := [pred x | >=<^l%O x y] : order_scope.
Notation ">=<^l y :> T" := (>=<^l (y : T)) (only parsing) : order_scope.
Notation "x >=<^l y" := (>=<^l%O x y) : order_scope.
Notation "><^l y" := [pred x | ~~ (>=<^l%O x y)] : order_scope.
Notation "><^l y :> T" := (><^l (y : T)) (only parsing) : order_scope.
Notation "x ><^l y" := (~~ (><^l%O x y)) : order_scope.
End LexiSyntax.
Module Import SeqLexiSyntax.
Notation "<=^l%O" := (@le (seqlexi_display _ _) _) : function_scope.
Notation ">=^l%O" := (@ge (seqlexi_display _ _) _) : function_scope.
Notation ">=^l%O" := (@ge (seqlexi_display _ _) _) : function_scope.
Notation "<^l%O" := (@lt (seqlexi_display _ _) _) : function_scope.
Notation ">^l%O" := (@gt (seqlexi_display _ _) _) : function_scope.
Notation "<?=^l%O" := (@leif (seqlexi_display _ _) _) : function_scope.
Notation ">=<^l%O" := (@comparable (seqlexi_display _ _) _) : function_scope.
Notation "><^l%O" := (fun x y => ~~ (@comparable (seqlexi_display _ _) _ x y)) :
function_scope.
Notation "<=^l y" := (>=^l%O y) : order_scope.
Notation "<=^l y :> T" := (<=^l (y : T)) (only parsing) : order_scope.
Notation ">=^l y" := (<=^l%O y) : order_scope.
Notation ">=^l y :> T" := (>=^l (y : T)) (only parsing) : order_scope.
Notation "<^l y" := (>^l%O y) : order_scope.
Notation "<^l y :> T" := (<^l (y : T)) (only parsing) : order_scope.
Notation ">^l y" := (<^l%O y) : order_scope.
Notation ">^l y :> T" := (>^l (y : T)) (only parsing) : order_scope.
Notation "x <=^l y" := (<=^l%O x y) : order_scope.
Notation "x <=^l y :> T" := ((x : T) <=^l (y : T)) (only parsing) : order_scope.
Notation "x >=^l y" := (y <=^l x) (only parsing) : order_scope.
Notation "x >=^l y :> T" := ((x : T) >=^l (y : T)) (only parsing) : order_scope.
Notation "x <^l y" := (<^l%O x y) : order_scope.
Notation "x <^l y :> T" := ((x : T) <^l (y : T)) (only parsing) : order_scope.
Notation "x >^l y" := (y <^l x) (only parsing) : order_scope.
Notation "x >^l y :> T" := ((x : T) >^l (y : T)) (only parsing) : order_scope.
Notation "x <=^l y <=^l z" := ((x <=^l y) && (y <=^l z)) : order_scope.
Notation "x <^l y <=^l z" := ((x <^l y) && (y <=^l z)) : order_scope.
Notation "x <=^l y <^l z" := ((x <=^l y) && (y <^l z)) : order_scope.
Notation "x <^l y <^l z" := ((x <^l y) && (y <^l z)) : order_scope.
Notation "x <=^l y ?= 'iff' C" := (<?=^l%O x y C) : order_scope.
Notation "x <=^l y ?= 'iff' C :> T" := ((x : T) <=^l (y : T) ?= iff C)
(only parsing) : order_scope.
Notation ">=<^l y" := [pred x | >=<^l%O x y] : order_scope.
Notation ">=<^l y :> T" := (>=<^l (y : T)) (only parsing) : order_scope.
Notation "x >=<^l y" := (>=<^l%O x y) : order_scope.
Notation "><^l y" := [pred x | ~~ (>=<^l%O x y)] : order_scope.
Notation "><^l y :> T" := (><^l (y : T)) (only parsing) : order_scope.
Notation "x ><^l y" := (~~ (><^l%O x y)) : order_scope.
End SeqLexiSyntax.
(************************************************)
(* We declare an alias of the cartesian product *)
(* which has canonical product order. *)
(************************************************)
Module ProdOrder.
Local Open Scope type_scope. (* FIXME *)
Definition type (disp : disp_t) (T T' : Type) := T * T'.
Definition type_
(disp1 disp2 : disp_t) (T : preorderType disp1) (T' : preorderType disp2) :=
type (prod_display disp1 disp2) T T'.
Section Basis.
Context {disp : disp_t}.
Local Notation "T * T'" := (type disp T T') : type_scope.
#[export] HB.instance Definition _ (T T' : eqType) := Equality.on (T * T').
#[export] HB.instance Definition _ (T T' : choiceType) := Choice.on (T * T').
#[export] HB.instance Definition _ (T T' : countType) := Countable.on (T * T').
#[export] HB.instance Definition _ (T T' : finType) := Finite.on (T * T').
End Basis.
Section Preorder.
Context (disp1 disp2 : disp_t).
Context (T1 : preorderType disp1) (T2 : preorderType disp2).
Implicit Types (x y : T1 * T2).
Let le x y := (x.1 <= y.1) && (x.2 <= y.2).
Let lt x y := (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2).
Fact lt_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite /lt /le !lt_leAnge -andbA -andb_orr.
by rewrite [~~ _ && _]andbC -andb_orr andbA negb_and.
Qed.
Fact refl : reflexive le. Proof. by move=> ?; rewrite /le !lexx. Qed.
Fact trans : transitive le.
Proof.
rewrite /le => y x z /andP [] hxy ? /andP [] /(le_trans hxy) ->.
by apply: le_trans.
Qed.
End Preorder.
Section Preorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : preorderType disp1) (T2 : preorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := Preorder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := Preorder.on T2'.
Definition le x y := (x.1 <= y.1) && (x.2 <= y.2).
Definition lt x y := (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2).
#[export]
HB.instance Definition _ := @isDuallyPreorder.Build disp3 (T1 * T2) le lt
(@lt_def _ _ T1' T2') (@lt_def _ _ T1^d T2^d)
(@refl _ _ T1' T2') (@refl _ _ T1^d T2^d)
(@trans _ _ T1' T2') (@trans _ _ T1^d T2^d).
Lemma leEprod x y : (x <= y) = (x.1 <= y.1) && (x.2 <= y.2). Proof. by []. Qed.
Lemma ltEprod x y :
(x < y) = (x.1 < y.1) && (x.2 <= y.2) || (x.1 <= y.1) && (x.2 < y.2).
Proof.
rewrite lt_leAnge !leEprod negb_and andb_orr andbAC -lt_leAnge -andbA.
by rewrite -lt_leAnge.
Qed.
Lemma le_pair (x1 y1 : T1) (x2 y2 : T2) :
(x1, x2) <= (y1, y2) :> T1 * T2 = (x1 <= y1) && (x2 <= y2).
Proof. by []. 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. exact/ltEprod. Qed.
End Preorder.
Section BPreorder.
Context (disp1 disp2 : disp_t).
Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Fact le0x x : (\bot, \bot) <= x :> T1 * T2.
Proof. by rewrite leEprod !le0x. Qed.
End BPreorder.
Section BPreorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Let T1' : Type := T1.
HB.instance Definition _ := BPreorder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := BPreorder.on T2'.
#[export]
HB.instance Definition _ :=
@hasBottom.Build disp3 (T1 * T2) (\bot, \bot) (@le0x _ _ T1' T2').
Lemma botEprod : \bot = (\bot, \bot) :> T1 * T2. Proof. by []. Qed.
End BPreorder.
Section TPreorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : tPreorderType disp1) (T2 : tPreorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
#[export]
HB.instance Definition _ :=
@hasTop.Build disp3 (T1 * T2) (\top, \top) (@le0x _ _ T1^d T2^d).
Lemma topEprod : \top = (\top, \top) :> T1 * T2. Proof. by []. Qed.
End TPreorder.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) :=
Preorder.on (type disp3 T1 T2).
(* FIXME: use HB.saturate *)
Section FinPreorder.
Context (disp1 disp2 disp3 : disp_t).
#[export]
HB.instance Definition _ (T1 : finPreorderType disp1)
(T2 : finPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPreorderType disp1)
(T2 : finBPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPreorderType disp1)
(T2 : finTPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPreorderType disp1)
(T2 : finTBPreorderType disp2) := Preorder.on (type disp3 T1 T2).
End FinPreorder.
Module Exports.
HB.reexport ProdOrder.
Notation "T *prod[ d ] T'" := (type d T T')
(at level 70, d at next level, format "T *prod[ d ] T'") : type_scope.
Notation "T *p T'" := (type_ T T')
(at level 70, format "T *p T'") : type_scope.
Definition leEprod := @leEprod.
Definition ltEprod := @ltEprod.
Definition le_pair := @le_pair.
Definition lt_pair := @lt_pair.
Definition botEprod := @botEprod.
Definition topEprod := @topEprod.
End Exports.
End ProdOrder.
HB.export ProdOrder.Exports.
Module 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 _ (T : preorderType disp1) (T' : preorderType disp2) :=
Preorder.copy (T * T')%type (T *p T').
HB.instance Definition _ (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) :=
BPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) :=
TPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _ (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) :=
TBPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finPreorderType disp1) (T2 : finPreorderType disp2) :=
FinPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) :=
FinBPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) :=
FinTPreorder.copy (T1 * T2)%type (prod T1 T2).
HB.instance Definition _
(T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) :=
FinTBPreorder.copy (T1 * T2)%type (prod T1 T2).
End DefaultProdOrder.
End DefaultProdOrder.
(*************************************************)
(* We declare an alias of the cartesian product, *)
(* which has canonical lexicographic order. *)
(*************************************************)
Module ProdLexiOrder.
Local Open Scope type_scope. (* FIXME *)
Definition type (disp : disp_t) (T T' : Type) := T * T'.
Definition type_
(disp1 disp2 : disp_t) (T : preorderType disp1) (T' : preorderType disp2) :=
type (lexi_display disp1 disp2) T T'.
Section Basis.
Context {disp : disp_t}.
Local Notation "T * T'" := (type disp T T') : type_scope.
#[export] HB.instance Definition _ (T T' : eqType) := Equality.on (T * T').
#[export] HB.instance Definition _ (T T' : choiceType) := Choice.on (T * T').
#[export] HB.instance Definition _ (T T' : countType) := Countable.on (T * T').
#[export] HB.instance Definition _ (T T' : finType) := Finite.on (T * T').
End Basis.
Section Preorder.
Context (disp1 disp2 : disp_t).
Context (T1 : preorderType disp1) (T2 : preorderType disp2).
Implicit Types (x y : T1 * T2).
Let le x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)).
Let lt x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)).
Fact refl : reflexive le.
Proof. by move=> ?; rewrite /le !lexx. Qed.
Fact trans : transitive le.
Proof.
move=> y x z /andP [hxy /implyP hxy'] /andP [hyz /implyP hyz'].
rewrite /le (le_trans hxy) //=; apply/implyP => hzx.
by apply/le_trans/hxy'/(le_trans hyz): (hyz' (le_trans hzx hxy)).
Qed.
Fact lt_le_def x y : lt x y = le x y && ~~ le y x.
Proof.
rewrite /lt /le; case: x y => [x1 x2] [y1 y2]/=.
case/boolP: (x1 <= y1); case/boolP: (y1 <= x1) => //= _ _.
exact/lt_le_def.
Qed.
End Preorder.
Section Preorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : preorderType disp1) (T2 : preorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Implicit Types (x y : T1 * T2).
Let T1' : Type := T1.
HB.instance Definition _ := Preorder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := Preorder.on T2'.
Definition le x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)).
Definition lt x y := (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)).
#[export]
HB.instance Definition _ := @isDuallyPreorder.Build disp3 (T1 * T2) le lt
(@lt_le_def _ _ T1' T2') (@lt_le_def _ _ T1^d T2^d)
(@refl _ _ T1' T2') (@refl _ _ T1^d T2^d)
(@trans _ _ T1' T2') (@trans _ _ T1^d T2^d).
Lemma leEprodlexi x y :
(x <= y) = (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 <= y.2)).
Proof. by []. Qed.
Lemma ltEprodlexi x y :
(x < y) = (x.1 <= y.1) && ((x.1 >= y.1) ==> (x.2 < y.2)).
Proof. by []. Qed.
Lemma lexi_pair (x1 y1 : T1) (x2 y2 : T2) :
(x1, x2) <= (y1, y2) :> T1 * T2 = (x1 <= y1) && ((x1 >= y1) ==> (x2 <= y2)).
Proof. by []. Qed.
Lemma ltxi_pair (x1 y1 : T1) (x2 y2 : T2) :
(x1, x2) < (y1, y2) :> T1 * T2 = (x1 <= y1) && ((x1 >= y1) ==> (x2 < y2)).
Proof. by []. Qed.
End Preorder.
Section BPreorder.
Context (disp1 disp2 : disp_t).
Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2).
Local Notation "T1 * T2" := (type (Disp tt tt) T1 T2) : type_scope.
Implicit Types (x : T1 * T2).
Fact le0x x : (\bot, \bot) <= x :> T1 * T2.
Proof. by rewrite leEprodlexi !le0x implybT. Qed.
End BPreorder.
Section BPreorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : bPreorderType disp1) (T2 : bPreorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
Let T1' : Type := T1.
HB.instance Definition _ := BPreorder.on T1'.
Let T2' : Type := T2.
HB.instance Definition _ := BPreorder.on T2'.
#[export]
HB.instance Definition _ :=
@hasBottom.Build disp3 (T1 * T2) (\bot, \bot) (@le0x _ _ T1' T2').
Lemma botEprodlexi : \bot = (\bot, \bot) :> T1 * T2. Proof. by []. Qed.
End BPreorder.
Section TPreorder.
Context (disp1 disp2 disp3 : disp_t).
Context (T1 : tPreorderType disp1) (T2 : tPreorderType disp2).
Local Notation "T1 * T2" := (type disp3 T1 T2) : type_scope.
#[export]
HB.instance Definition _ :=
@hasTop.Build disp3 (T1 * T2) (\top, \top) (@le0x _ _ T1^d T2^d).
Lemma topEprodlexi : \top = (\top, \top) :> T1 * T2. Proof. by []. Qed.
End TPreorder.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (disp1 disp2 disp3 : disp_t)
(T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) :=
Preorder.on (type disp3 T1 T2).
Lemma sub_prod_lexi (disp1 disp2 disp3 disp4 : disp_t)
(T1 : preorderType disp1) (T2 : preorderType disp2) :
subrel (<=%O : rel (T1 *prod[disp3] T2)) (<=%O : rel (type disp4 T1 T2)).
Proof.
case=> [x1 x2] [y1 y2]; rewrite leEprod leEprodlexi /= => /andP[] -> ->.
exact: implybT.
Qed.
(* FIXME: use HB.saturate *)
Section ProdLexiOrder.
Context (disp1 disp2 disp3 : disp_t).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (T1 : bPreorderType disp1)
(T2 : bPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (T1 : tPreorderType disp1)
(T2 : tPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (T1 : tbPreorderType disp1)
(T2 : tbPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finPreorderType disp1)
(T2 : finPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finBPreorderType disp1)
(T2 : finBPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTPreorderType disp1)
(T2 : finTPreorderType disp2) := Preorder.on (type disp3 T1 T2).
#[export]
HB.instance Definition _ (T1 : finTBPreorderType disp1)
(T2 : finTBPreorderType disp2) := Preorder.on (type disp3 T1 T2).
End ProdLexiOrder.
Module Exports.
HB.reexport ProdLexiOrder.
Notation "T *lexi[ d ] T'" := (type d T T')
(at level 70, d at next level, format "T *lexi[ d ] T'") : type_scope.
Notation "T *l T'" := (type_ T T')
(at level 70, format "T *l T'") : type_scope.
Definition leEprodlexi := @leEprodlexi.
Definition ltEprodlexi := @ltEprodlexi.
Definition lexi_pair := @lexi_pair.
Definition ltxi_pair := @ltxi_pair.
Definition topEprodlexi := @topEprodlexi.
Definition botEprodlexi := @botEprodlexi.
Definition sub_prod_lexi := @sub_prod_lexi.
End Exports.
End ProdLexiOrder.
HB.export ProdLexiOrder.Exports.
Module 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 : preorderType disp1) (T2 : preorderType disp2) :=
Preorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _ (T1 : bPreorderType disp1) (T2 : bPreorderType disp2) :=
BPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _ (T1 : tPreorderType disp1) (T2 : tPreorderType disp2) :=
TPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _ (T1 : tbPreorderType disp1) (T2 : tbPreorderType disp2) :=
TBPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finPreorderType disp1) (T2 : finPreorderType disp2) :=
FinPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finBPreorderType disp1) (T2 : finBPreorderType disp2) :=
FinBPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTPreorderType disp1) (T2 : finTPreorderType disp2) :=
FinTPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
HB.instance Definition _
(T1 : finTBPreorderType disp1) (T2 : finTBPreorderType disp2) :=
FinTBPreorder.copy (T1 * T2)%type (prodlexi T1 T2).
End DefaultProdLexiOrder.
End DefaultProdLexiOrder.
(*****************************************)
(* We declare an alias of the sequences, *)
(* which has canonical product order. *)
(*****************************************)
Module SeqProdOrder.
Section SeqProdOrder.
Definition type (disp : disp_t) T := seq T.
Definition type_ (disp : disp_t) (T : preorderType disp) :=
type (seqprod_display disp) T.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
#[export] HB.instance Definition _ (T : eqType) := Equality.on (seq T).
#[export] HB.instance Definition _ (T : choiceType) := Choice.on (seq T).
#[export] HB.instance Definition _ (T : countType) := Countable.on (seq T).
Section Preorder.
Context (T : preorderType disp).
Implicit Types (s : seq T).
Fixpoint le s1 s2 := if s1 isn't x1 :: s1' then true else
if s2 isn't x2 :: s2' then false else
(x1 <= x2) && le s1' s2'.
Fact refl : reflexive le. Proof. by elim=> //= ? ? ?; rewrite !lexx. Qed.
Fact trans : transitive le.
Proof.
elim=> [|y ys ihs] [|x xs] [|z zs] //= /andP[xy xys] /andP[yz yzs].
by rewrite (le_trans xy)// ihs.
Qed.
#[export]
HB.instance Definition _ := isPreorder.Build disp' (seq T) (rrefl _) refl trans.
Lemma leEseq s1 s2 : s1 <= s2 = if s1 isn't x1 :: s1' then true else
if s2 isn't x2 :: s2' then false else
(x1 <= x2) && (s1' <= s2' :> seq _).
Proof. by case: s1. Qed.
Lemma le0s s : [::] <= s :> seq _. Proof. by []. Qed.
Lemma les0 s : s <= [::] = (s == [::]). Proof. by rewrite leEseq. Qed.
Lemma le_cons x1 s1 x2 s2 :
x1 :: s1 <= x2 :: s2 :> seq _ = (x1 <= x2) && (s1 <= s2).
Proof. by []. Qed.
#[export]
HB.instance Definition _ := hasBottom.Build _ (seq T) le0s.
Lemma botEseq : \bot = [::] :> seq T.
Proof. by []. Qed.
End Preorder.
End SeqProdOrder.
Module Exports.
HB.reexport SeqProdOrder.
Notation seqprod_with := type.
Notation seqprod := type_.
Definition leEseq := @leEseq.
Definition le0s := @le0s.
Definition les0 := @les0.
Definition le_cons := @le_cons.
Definition botEseq := @botEseq.
End Exports.
End SeqProdOrder.
HB.export SeqProdOrder.Exports.
Module DefaultSeqProdOrder.
Section DefaultSeqProdOrder.
Context {disp : disp_t}.
Notation seqprod := (seqprod_with (seqprod_display disp)).
HB.instance Definition _ (T : preorderType disp) :=
Preorder.copy (seq T) (seqprod T).
HB.instance Definition _ (T : preorderType disp) :=
BPreorder.copy (seq T) (seqprod T).
End DefaultSeqProdOrder.
End DefaultSeqProdOrder.
(*********************************************)
(* We declare an alias of the sequences, *)
(* which has canonical lexicographic order. *)
(*********************************************)
Module SeqLexiOrder.
Section SeqLexiOrder.
Definition type (disp : disp_t) T := seq T.
Definition type_ (disp : disp_t) (T : preorderType disp) :=
type (seqlexi_display disp) T.
Context {disp disp' : disp_t}.
Local Notation seq := (type disp').
#[export] HB.instance Definition _ (T : eqType) := Equality.on (seq T).
#[export] HB.instance Definition _ (T : choiceType) := Choice.on (seq T).
#[export] HB.instance Definition _ (T : countType) := Countable.on (seq T).
Section Preorder.
Context (T : preorderType disp).
Implicit Types (s : seq T).
Fixpoint le s1 s2 := if s1 isn't x1 :: s1' then true else
if s2 isn't x2 :: s2' then false else
(x1 <= x2) && ((x1 >= x2) ==> le s1' s2').
Fixpoint lt s1 s2 := if s2 isn't x2 :: s2' then false else
if s1 isn't x1 :: s1' then true else
(x1 <= x2) && ((x1 >= x2) ==> lt s1' s2').
Fact refl: reflexive le.
Proof. by elim => [|x s ih] //=; rewrite lexx. Qed.
Fact trans: transitive le.
Proof.
elim=> [|y sy ihs] [|x sx] [|z sz] //= /andP[] xy /implyP yx /andP[] yz /implyP zy /=.
rewrite (le_trans xy yz)/=; apply/implyP => zx.
apply/ihs; first exact/yx/(le_trans yz zx).
exact/zy/(le_trans zx xy).
Qed.
Lemma lt_le_def s1 s2 : lt s1 s2 = le s1 s2 && ~~ le s2 s1.
Proof.
elim: s1 s2 => [|x s1 ihs1] [|y s2]//=; rewrite ihs1.
by case: (x <= y); case (y <= x).
Qed.
#[export]
HB.instance Definition _ := isPreorder.Build disp' (seq T) lt_le_def refl trans.
Lemma leEseqlexi s1 s2 :
s1 <= s2 = if s1 isn't x1 :: s1' then true else
if s2 isn't x2 :: s2' then false else
(x1 <= x2) && ((x1 >= x2) ==> (s1' <= s2' :> seq T)).
Proof. by case: s1. Qed.
Lemma ltEseqlexi s1 s2 :
s1 < s2 = if s2 isn't x2 :: s2' then false else
if s1 isn't x1 :: s1' then true else
(x1 <= x2) && ((x1 >= x2) ==> (s1' < s2' :> seq T)).
Proof. by case: s1. Qed.
Lemma lexi0s s : [::] <= s :> seq T. Proof. by []. Qed.
Lemma lexis0 s : s <= [::] = (s == [::]). Proof. by rewrite leEseqlexi. Qed.
Lemma ltxi0s s : ([::] < s :> seq T) = (s != [::]). Proof. by case: s. Qed.
Lemma ltxis0 s : s < [::] = false. Proof. by rewrite ltEseqlexi. Qed.
Lemma lexi_cons x1 s1 x2 s2 :
x1 :: s1 <= x2 :: s2 :> seq T = (x1 <= x2) && ((x1 >= x2) ==> (s1 <= s2)).
Proof. by []. Qed.
Lemma ltxi_cons x1 s1 x2 s2 :
x1 :: s1 < x2 :: s2 :> seq T = (x1 <= x2) && ((x1 >= x2) ==> (s1 < s2)).
Proof. by []. Qed.
Lemma lexi_lehead x s1 y s2 : x :: s1 <= y :: s2 :> seq T -> x <= y.
Proof. by rewrite lexi_cons => /andP[]. Qed.
Lemma ltxi_lehead x s1 y s2 : x :: s1 < y :: s2 :> seq T -> x <= y.
Proof. by rewrite ltxi_cons => /andP[]. Qed.
Lemma eqhead_lexiE (x : T) s1 s2 : (x :: s1 <= x :: s2 :> seq _) = (s1 <= s2).
Proof. by rewrite lexi_cons lexx. Qed.
Lemma eqhead_ltxiE (x : T) s1 s2 : (x :: s1 < x :: s2 :> seq _) = (s1 < s2).
Proof. by rewrite ltxi_cons lexx. Qed.
#[export]
HB.instance Definition _ := hasBottom.Build _ (seq T) lexi0s.
End Preorder.
Lemma sub_seqprod_lexi d (T : preorderType disp) :
subrel (<=%O : rel (seqprod_with d T)) (<=%O : rel (seq T)).
Proof.
elim=> [|x1 s1 ihs1] [|x2 s2]//=; rewrite le_cons lexi_cons /=.
by move=> /andP[-> /ihs1->]; rewrite implybT.
Qed.
End SeqLexiOrder.
Module Exports.
HB.reexport SeqLexiOrder.
Notation seqlexi_with := type.
Notation seqlexi := type_.
Definition leEseqlexi := @leEseqlexi.
Definition lexi0s := @lexi0s.
Definition lexis0 := @lexis0.
Definition lexi_cons := @lexi_cons.
Definition lexi_lehead := @lexi_lehead.
Definition eqhead_lexiE := @eqhead_lexiE.
Definition ltEseqltxi := @ltEseqlexi.
Definition ltxi0s := @ltxi0s.
Definition ltxis0 := @ltxis0.
Definition ltxi_cons := @ltxi_cons.
Definition ltxi_lehead := @ltxi_lehead.
Definition eqhead_ltxiE := @eqhead_ltxiE.
Definition sub_seqprod_lexi := @sub_seqprod_lexi.
End Exports.
End SeqLexiOrder.
HB.export SeqLexiOrder.Exports.
Module DefaultSeqLexiOrder.
Section DefaultSeqLexiOrder.
Context {disp : disp_t}.
Notation seqlexi := (seqlexi_with (seqlexi_display disp)).
HB.instance Definition _ (T : preorderType disp) :=
Preorder.copy (seq T) (seqlexi T).
HB.instance Definition _ (T : preorderType disp) :=
BPreorder.copy (seq T) (seqlexi T).
End DefaultSeqLexiOrder.
End DefaultSeqLexiOrder.
(***************************************)
(* We declare an alias of the tuples, *)
(* which has canonical product order. *)
(***************************************)
Module TupleProdOrder.
Import DefaultSeqProdOrder.
Section TupleProdOrder.
Definition type (disp : disp_t) n T := n.-tuple T.
Definition type_ (disp : disp_t) n (T : preorderType disp) :=
type (seqprod_display disp) n T.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section Basics.
Context (n : nat).
#[export] HB.instance Definition _ (T : eqType) := Equality.on (n.-tuple T).
#[export] HB.instance Definition _ (T : eqType) := SubEquality.on (n.-tuple T).
#[export] HB.instance Definition _ (T : choiceType) :=
SubChoice.on (n.-tuple T).
#[export] HB.instance Definition _ (T : countType) :=
SubCountable.on (n.-tuple T).
#[export] HB.instance Definition _ (T : finType) := SubFinite.on (n.-tuple T).
End Basics.
Section Preorder.
Implicit Types (n : nat) (T : preorderType disp).
(* FIXME: this instance should be dualizable, but then we should not depend *)
(* on the subtype mechanism, because the pointwise order on seq cannot be the *)
(* dual of itself. *)
#[export] HB.instance Definition _ n T :=
[SubChoice_isSubPreorder of n.-tuple T by <: with disp'].
Lemma leEtprod n T (t1 t2 : n.-tuple T) :
t1 <= t2 = [forall i, tnth t1 i <= tnth t2 i].
Proof.
elim: n => [|n IHn] in t1 t2 *.
by rewrite tuple0 [t2]tuple0/= lexx; symmetry; apply/forallP => [].
case: (tupleP t1) (tupleP t2) => [x1 {}t1] [x2 {}t2].
rewrite [_ <= _]le_cons [t1 <= t2 :> seq _]IHn.
apply/idP/forallP => [/andP[lex12 /forallP/= let12 i]|lext12].
by case: (unliftP ord0 i) => [j ->|->]//; rewrite !tnthS.
rewrite (lext12 ord0)/=; apply/forallP=> i.
by have := lext12 (lift ord0 i); rewrite !tnthS.
Qed.
Lemma ltEtprod n T (t1 t2 : n.-tuple T) :
t1 < t2 = [exists i, tnth t1 i < tnth t2 i] &&
[forall i, tnth t1 i <= tnth t2 i].
Proof.
rewrite lt_leAnge !leEtprod negb_forall andbC.
apply/andP/andP => -[] /existsP[x] xlt le; split=> //; apply/existsP; exists x.
rewrite lt_leAnge xlt.
by move: le => /forallP ->.
by move: xlt; rewrite lt_leAnge => /andP[].
Qed.
End Preorder.
Section BPreorder.
Context (n : nat) (T : bPreorderType disp).
Implicit Types (t : n.-tuple T).
Fact le0x t : [tuple \bot | _ < n] <= t :> n.-tuple T.
Proof. by rewrite leEtprod; apply/forallP => i; rewrite tnth_mktuple le0x. Qed.
#[export]
HB.instance Definition _ := hasBottom.Build _ (n.-tuple T) le0x.
Lemma botEtprod : \bot = [tuple \bot | _ < n] :> n.-tuple T.
Proof. by []. Qed.
End BPreorder.
Section TPreorder.
Context (n : nat) (T : tPreorderType disp).
Implicit Types (t : n.-tuple T).
Fact lex1 t : t <= [tuple \top | _ < n] :> n.-tuple T.
Proof. by rewrite leEtprod; apply/forallP => i; rewrite tnth_mktuple lex1. Qed.
#[export]
HB.instance Definition _ := hasTop.Build _ (n.-tuple T) lex1.
Lemma topEtprod : \top = [tuple \top | _ < n] :> n.-tuple T.
Proof. by []. Qed.
End TPreorder.
(* FIXME: use HB.saturate *)
#[export]
HB.instance Definition _ (n : nat) (T : tbPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (n : nat) (T : finPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finBPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : finTBPreorderType disp) :=
Preorder.on (n.-tuple T).
End TupleProdOrder.
Module Exports.
HB.reexport TupleProdOrder.
Notation "n .-tupleprod[ disp ]" := (type disp n)
(format "n .-tupleprod[ disp ]") : type_scope.
Notation "n .-tupleprod" := (type_ n)
(format "n .-tupleprod") : type_scope.
Definition leEtprod := @leEtprod.
Definition ltEtprod := @ltEtprod.
Definition botEtprod := @botEtprod.
Definition topEtprod := @topEtprod.
End Exports.
End TupleProdOrder.
HB.export TupleProdOrder.Exports.
Module DefaultTupleProdOrder.
Section DefaultTupleProdOrder.
Context {disp : disp_t}.
Notation "n .-tupleprod" := n.-tupleprod[seqprod_display disp].
HB.instance Definition _ n (T : preorderType disp) :=
Preorder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : bPreorderType disp) :=
BPreorder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tPreorderType disp) :=
TPreorder.copy (n.-tuple T) (n.-tupleprod T).
HB.instance Definition _ n (T : tbPreorderType disp) :=
TBPreorder.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.
Section TupleLexiOrder.
Import DefaultSeqLexiOrder.
Definition type (disp : disp_t) n T := n.-tuple T.
Definition type_ (disp : disp_t) n (T : preorderType disp) :=
type (seqlexi_display disp) n T.
Context {disp disp' : disp_t}.
Local Notation "n .-tuple" := (type disp' n) : type_scope.
Section Basics.
Context (n : nat).
#[export] HB.instance Definition _ (T : eqType) := Equality.on (n.-tuple T).
#[export] HB.instance Definition _ (T : choiceType) :=
SubChoice.on (n.-tuple T).
#[export] HB.instance Definition _ (T : countType) :=
SubCountable.on (n.-tuple T).
#[export] HB.instance Definition _ (T : finType) :=
SubFinite.on (n.-tuple T).
End Basics.
Section Preorder.
Implicit Types (T : preorderType disp).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ n T := SubChoice.on (n.-tuple T).
#[export]
HB.instance Definition _ n T :=
[SubChoice_isSubPreorder of n.-tuple T by <: with disp'].
End Preorder.
Section BPreorder.
Context (n : nat) (T : bPreorderType disp).
Implicit Types (t : n.-tuple T).
Fact le0x t : [tuple \bot | _ < n] <= t :> n.-tuple T.
Proof. by apply: sub_seqprod_lexi; apply: le0x (t : n.-tupleprod T). Qed.
#[export] HB.instance Definition _ := hasBottom.Build _ (n.-tuple T) le0x.
Lemma botEtlexi : \bot = [tuple \bot | _ < n] :> n.-tuple T. Proof. by []. Qed.
End BPreorder.
Section TPreorder.
Context (n : nat) (T : tPreorderType disp).
Implicit Types (t : n.-tuple T).
Fact lex1 t : t <= [tuple \top | _ < n].
Proof. by apply: sub_seqprod_lexi; apply: lex1 (t : n.-tupleprod T). Qed.
#[export] HB.instance Definition _ := hasTop.Build _ (n.-tuple T) lex1.
Lemma topEtlexi : \top = [tuple \top | _ < n] :> n.-tuple T. Proof. by []. Qed.
End TPreorder.
(* FIXME: use HB.saturate *)
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (n : nat) (T : bPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export, warning="-HB.no-new-instance"]
HB.instance Definition _ (n : nat) (T : tPreorderType disp) :=
Preorder.on (n.-tuple T).
#[export]
HB.instance Definition _ (n : nat) (T : tbPreorderType disp) :=
Preorder.on (n.-tuple T).
Lemma sub_tprod_lexi d n (T : preorderType disp) :
subrel (<=%O : rel (n.-tupleprod[d] T)) (<=%O : rel (n.-tuple T)).
Proof. exact: sub_seqprod_lexi. Qed.
End TupleLexiOrder.
Module Exports.
HB.reexport TupleLexiOrder.
Notation "n .-tuplelexi[ disp ]" := (type disp n)
(format "n .-tuplelexi[ disp ]") : type_scope.
Notation "n .-tuplelexi" := (type_ n)
(format "n .-tuplelexi") : type_scope.
Definition topEtlexi := @topEtlexi.
Definition botEtlexi := @botEtlexi.
Definition sub_tprod_lexi := @sub_tprod_lexi.
End Exports.
End TupleLexiOrder.
HB.export TupleLexiOrder.Exports.
Module DefaultTupleLexiOrder.
Section DefaultTupleLexiOrder.
Context {disp : disp_t}.
Notation "n .-tuplelexi" := n.-tuplelexi[seqlexi_display disp].
HB.instance Definition _ n (T : preorderType disp) :=
Preorder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : bPreorderType disp) :=
BPreorder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tPreorderType disp) :=
TPreorder.copy (n.-tuple T) (n.-tuplelexi T).
HB.instance Definition _ n (T : tbPreorderType disp) :=
TBPreorder.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.
Section SetSubsetOrder.
Fact subset_display : disp_t. Proof. exact. Qed.
Definition type (disp : disp_t) (T : finType) := {set T}.
Context {disp : disp_t} {T : finType}.
Local Notation "{ 'subset' T }" := (type disp T).
Implicit Type (A B C : {subset T}).
Lemma le_def A B : A \subset B = (A :&: B == A).
Proof. exact/setIidPl/eqP. Qed.
#[export]
HB.instance Definition _ := Choice.on {subset T}.
#[export]
HB.instance Definition _ := Le_isPreorder.Build disp {subset T}
(@subxx _ _) (fun A B => @subset_trans _ B A).
#[export]
HB.instance Definition _ := hasBottom.Build disp {subset T} (@sub0set _).
#[export]
HB.instance Definition _ := hasTop.Build disp {subset T} (@subsetT _).
Lemma leEsubset A B : (A <= B) = (A \subset B).
Proof. by []. Qed.
End SetSubsetOrder.
Module Exports.
Arguments type disp T%_type.
Notation "{ 'subset' [ d ] T }" := (type d T)
(d at next level, format "{ 'subset' [ d ] T }") : type_scope.
Notation "{ 'subset' T }" := {subset[subset_display] T}
(format "{ 'subset' T }") : type_scope.
HB.reexport.
Definition leEsubset := @leEsubset.
End Exports.
End SetSubsetOrder.
Export SetSubsetOrder.Exports.
Module DefaultSetSubsetOrder.
HB.instance Definition _ (T : finType) :=
TBPreorder.copy {set T} {subset T}.
End DefaultSetSubsetOrder.
Notation enum A := (sort <=%O (enum A)).
Section Enum.
Variables (d : disp_t) (T : finPreorderType d).
Lemma cardE (A : {pred T}) : #|A| = size (enum A).
Proof. by rewrite size_sort cardE. Qed.
Lemma mem_enum (A : {pred T}) : enum A =i A.
Proof. by move=> x; rewrite mem_sort mem_enum. Qed.
Lemma enum_uniq (A : {pred T}) : uniq (enum A).
Proof. by rewrite sort_uniq enum_uniq. Qed.
Lemma cardT : #|T| = size (enum T).
Proof. by rewrite cardT size_sort. Qed.
Lemma enumT : enum T = sort <=%O (Finite.enum T).
Proof. by rewrite enumT. Qed.
Lemma enum0 : enum (pred0 : {pred T}) = [::].
Proof. by rewrite enum0. Qed.
Lemma enum1 (x : T) : enum (pred1 x) = [:: x].
Proof. by rewrite enum1. Qed.
Lemma eq_enum (A B : {pred T}) : A =i B -> enum A = enum B.
Proof. by move=> /eq_enum->. Qed.
Lemma eq_cardT (A : {pred T}) : A =i predT -> #|A| = size (enum T).
Proof. by move=> /eq_enum<-; rewrite cardE. Qed.
Lemma set_enum (A : {set T}) : [set x in enum A] = A.
Proof. by apply/setP => x; rewrite inE mem_enum. Qed.
Lemma enum_set0 : enum (set0 : {set T}) = [::].
Proof. by rewrite enum_set0. Qed.
Lemma enum_setT : enum [set: T] = sort <=%O (Finite.enum T).
Proof. by rewrite enum_setT. Qed.
Lemma enum_set1 (a : T) : enum [set a] = [:: a].
Proof. by rewrite enum_set1. Qed.
End Enum.
Section Ordinal.
Import OrdinalOrder.Exports.
Lemma enum_ord n : enum 'I_n = fintype.enum 'I_n.
Proof.
rewrite (sorted_sort le_trans)// -(@sorted_map _ _ (val : 'I_n -> nat))/=.
by rewrite val_enum_ord iota_sorted.
Qed.
Lemma val_enum_ord n : [seq val i | i <- enum 'I_n] = iota 0 n.
Proof. by rewrite enum_ord val_enum_ord. Qed.
Lemma size_enum_ord n : size (enum 'I_n) = n.
Proof. by rewrite -cardE card_ord. Qed.
Lemma nth_enum_ord (n : nat) (i0 : 'I_n) (m : nat) :
(m < n)%N -> nth i0 (enum 'I_n) m = m :> nat.
Proof. by move=> lemn; rewrite enum_ord nth_enum_ord. Qed.
Lemma nth_ord_enum (n : nat) (i0 i : 'I_n) : nth i0 (enum 'I_n) i = i.
Proof. by rewrite enum_ord nth_ord_enum. Qed.
Lemma index_enum_ord (n : nat) (i : 'I_n) : index i (enum 'I_n) = i.
Proof. by rewrite enum_ord index_enum_ord. Qed.
End Ordinal.
Lemma mono_sorted_enum d d' (T : finPreorderType d)
(T' : preorderType d') (f : T -> T') :
total (<=%O : rel T) -> {mono f : x y / (x <= y)%O} ->
sorted <=%O [seq f x | x <- enum T].
Proof.
move=> /sort_sorted ss_sorted lef; wlog [x0 x'0] : / (T * T')%type.
by case: (enum T) => // x ? => /(_ (x, f x)).
rewrite (sorted_pairwise le_trans).
apply/(pairwiseP x'0) => i j; rewrite !inE !size_map -!cardT.
move=> ilt jlt ij; rewrite !(nth_map x0) -?cardT// lef.
by rewrite (sorted_leq_nth le_trans le_refl) ?inE -?cardT// 1?ltnW.
Qed.
(* This module should be exported on demand, as in module tagnat below *)
Module Import EnumVal.
Section EnumVal.
Import OrdinalOrder.Exports.
Variables (d : disp_t) (T : finPreorderType d).
Implicit Types (x : T) (A : {pred T}).
Definition enum_rank_in x0 A (Ax0 : x0 \in A) x :=
insubd (Ordinal (@enum_rank_subproof _ x0 A Ax0)) (index x (enum A)).
Definition enum_rank x := @enum_rank_in x T (erefl true) x.
Definition enum_val A i := nth (@enum_default _ A i) (enum A) i.
Prenex Implicits enum_val.
Lemma enum_valP A i : @enum_val A i \in A.
Proof.
suff: enum_val i \in enum A by rewrite mem_enum.
by apply: mem_nth; rewrite -cardE.
Qed.
Lemma enum_val_nth A x i : @enum_val A i = nth x (enum A) i.
Proof. by apply: set_nth_default; rewrite cardE in i *. Qed.
Lemma nth_enum_rank_in x00 x0 A Ax0 :
{in A, cancel (@enum_rank_in x0 A Ax0) (nth x00 (enum A))}.
Proof.
move=> x Ax; rewrite /= insubdK ?nth_index ?mem_enum //.
by rewrite cardE [_ \in _]index_mem mem_enum.
Qed.
Lemma nth_enum_rank x0 : cancel enum_rank (nth x0 (enum T)).
Proof. by move=> x; apply: nth_enum_rank_in. Qed.
Lemma enum_rankK_in x0 A Ax0 :
{in A, cancel (@enum_rank_in x0 A Ax0) enum_val}.
Proof. by move=> x; apply: nth_enum_rank_in. Qed.
Lemma enum_rankK : cancel enum_rank enum_val.
Proof. by move=> x; apply: enum_rankK_in. Qed.
Lemma enum_valK_in x0 A Ax0 : cancel enum_val (@enum_rank_in x0 A Ax0).
Proof.
move=> x; apply: ord_inj; rewrite insubdK; last first.
by rewrite cardE [_ \in _]index_mem mem_nth // -cardE.
by rewrite index_uniq ?enum_uniq // -cardE.
Qed.
Lemma enum_valK : cancel enum_val enum_rank.
Proof. by move=> x; apply: enum_valK_in. Qed.
Lemma enum_rank_inj : injective enum_rank.
Proof. exact: can_inj enum_rankK. Qed.
Lemma enum_val_inj A : injective (@enum_val A).
Proof. by move=> i; apply: can_inj (enum_valK_in (enum_valP i)) (i). Qed.
Lemma enum_val_bij_in x0 A : x0 \in A -> {on A, bijective (@enum_val A)}.
Proof.
move=> Ax0; exists (enum_rank_in Ax0) => [i _|]; last exact: enum_rankK_in.
exact: enum_valK_in.
Qed.
Lemma eq_enum_rank_in (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) :
{in A, enum_rank_in Ax0 =1 enum_rank_in Ay0}.
Proof. by move=> x xA; apply: enum_val_inj; rewrite !enum_rankK_in. Qed.
Lemma enum_rank_in_inj (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) :
{in A &, forall x y, enum_rank_in Ax0 x = enum_rank_in Ay0 y -> x = y}.
Proof. by move=> x y xA yA /(congr1 enum_val); rewrite !enum_rankK_in. Qed.
Lemma enum_rank_bij : bijective enum_rank.
Proof. by move: enum_rankK enum_valK; exists (@enum_val T). Qed.
Lemma enum_val_bij : bijective (@enum_val T).
Proof. by move: enum_rankK enum_valK; exists enum_rank. Qed.
End EnumVal.
Arguments enum_val {d T A}.
Arguments enum_rank {d T}.
End EnumVal.
Notation enum_val := enum_val.
Notation enum_rank_in := enum_rank_in.
Notation enum_rank := enum_rank.
Notation enum_valP := enum_valP.
Notation enum_val_nth := enum_val_nth.
Notation nth_enum_rank_in := nth_enum_rank_in.
Notation nth_enum_rank := nth_enum_rank.
Notation enum_rankK_in := enum_rankK_in.
Notation enum_rankK := enum_rankK.
Notation enum_valK_in := enum_valK_in.
Notation enum_valK := enum_valK.
Notation enum_rank_inj := enum_rank_inj.
Notation enum_val_inj := enum_val_inj.
Notation enum_val_bij_in := enum_val_bij_in.
Notation eq_enum_rank_in := eq_enum_rank_in.
Notation enum_rank_in_inj := enum_rank_in_inj.
Notation enum_rank_bij := enum_rank_bij.
Notation enum_val_bij := enum_val_bij.
Module Syntax.
Export PreOSyntax.
Export DualSyntax.
Export DvdSyntax.
End Syntax.
Module Theory.
Export PreorderTheory.
Export PreOCoercions.
Export BPreorderTheory.
Export TPreorderTheory.
Export DualPreorder. (* FIXME? *)
Export OrderMorphismTheory.
Export SubPreorderTheory.
End Theory.
Module Exports.
HB.reexport.
End Exports.
End Order.
Export Order.Exports.
Export Order.Syntax.
Export Order.Preorder.Exports.
Export Order.BPreorder.Exports.
Export Order.TPreorder.Exports.
Export Order.TBPreorder.Exports.
Export Order.FinPreorder.Exports.
Export Order.FinBPreorder.Exports.
Export Order.FinTPreorder.Exports.
Export Order.FinTBPreorder.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.
|
ZeroObjects.lean
|
/-
Copyright (c) 2022 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
import Mathlib.CategoryTheory.Limits.Constructions.BinaryProducts
/-!
# Limits involving zero objects
Binary products and coproducts with a zero object always exist,
and pullbacks/pushouts over a zero object are products/coproducts.
-/
noncomputable section
open CategoryTheory
variable {C : Type*} [Category C]
namespace CategoryTheory.Limits
variable [HasZeroObject C] [HasZeroMorphisms C]
open ZeroObject
/-- The limit cone for the product with a zero object. -/
def binaryFanZeroLeft (X : C) : BinaryFan (0 : C) X :=
BinaryFan.mk 0 (π X)
/-- The limit cone for the product with a zero object is limiting. -/
def binaryFanZeroLeftIsLimit (X : C) : IsLimit (binaryFanZeroLeft X) :=
BinaryFan.isLimitMk (fun s => BinaryFan.snd s) (by cat_disch) (by simp)
(fun s m _ hβ => by simpa using hβ)
instance hasBinaryProduct_zero_left (X : C) : HasBinaryProduct (0 : C) X :=
HasLimit.mk β¨_, binaryFanZeroLeftIsLimit Xβ©
/-- A zero object is a left unit for categorical product. -/
def zeroProdIso (X : C) : (0 : C) β¨― X β
X :=
limit.isoLimitCone β¨_, binaryFanZeroLeftIsLimit Xβ©
@[simp]
theorem zeroProdIso_hom (X : C) : (zeroProdIso X).hom = prod.snd :=
rfl
@[simp]
theorem zeroProdIso_inv_snd (X : C) : (zeroProdIso X).inv β« prod.snd = π X := by
dsimp [zeroProdIso, binaryFanZeroLeft]
simp
/-- The limit cone for the product with a zero object. -/
def binaryFanZeroRight (X : C) : BinaryFan X (0 : C) :=
BinaryFan.mk (π X) 0
/-- The limit cone for the product with a zero object is limiting. -/
def binaryFanZeroRightIsLimit (X : C) : IsLimit (binaryFanZeroRight X) :=
BinaryFan.isLimitMk (fun s => BinaryFan.fst s) (by simp) (by cat_disch)
(fun s m hβ _ => by simpa using hβ)
instance hasBinaryProduct_zero_right (X : C) : HasBinaryProduct X (0 : C) :=
HasLimit.mk β¨_, binaryFanZeroRightIsLimit Xβ©
/-- A zero object is a right unit for categorical product. -/
def prodZeroIso (X : C) : X β¨― (0 : C) β
X :=
limit.isoLimitCone β¨_, binaryFanZeroRightIsLimit Xβ©
@[simp]
theorem prodZeroIso_hom (X : C) : (prodZeroIso X).hom = prod.fst :=
rfl
@[simp]
theorem prodZeroIso_iso_inv_snd (X : C) : (prodZeroIso X).inv β« prod.fst = π X := by
dsimp [prodZeroIso, binaryFanZeroRight]
simp
/-- The colimit cocone for the coproduct with a zero object. -/
def binaryCofanZeroLeft (X : C) : BinaryCofan (0 : C) X :=
BinaryCofan.mk 0 (π X)
/-- The colimit cocone for the coproduct with a zero object is colimiting. -/
def binaryCofanZeroLeftIsColimit (X : C) : IsColimit (binaryCofanZeroLeft X) :=
BinaryCofan.isColimitMk (fun s => BinaryCofan.inr s) (by cat_disch) (by simp)
(fun s m _ hβ => by simpa using hβ)
instance hasBinaryCoproduct_zero_left (X : C) : HasBinaryCoproduct (0 : C) X :=
HasColimit.mk β¨_, binaryCofanZeroLeftIsColimit Xβ©
/-- A zero object is a left unit for categorical coproduct. -/
def zeroCoprodIso (X : C) : (0 : C) β¨Ώ X β
X :=
colimit.isoColimitCocone β¨_, binaryCofanZeroLeftIsColimit Xβ©
@[simp]
theorem inr_zeroCoprodIso_hom (X : C) : coprod.inr β« (zeroCoprodIso X).hom = π X := by
dsimp [zeroCoprodIso, binaryCofanZeroLeft]
simp
@[simp]
theorem zeroCoprodIso_inv (X : C) : (zeroCoprodIso X).inv = coprod.inr :=
rfl
/-- The colimit cocone for the coproduct with a zero object. -/
def binaryCofanZeroRight (X : C) : BinaryCofan X (0 : C) :=
BinaryCofan.mk (π X) 0
/-- The colimit cocone for the coproduct with a zero object is colimiting. -/
def binaryCofanZeroRightIsColimit (X : C) : IsColimit (binaryCofanZeroRight X) :=
BinaryCofan.isColimitMk (fun s => BinaryCofan.inl s) (by simp) (by cat_disch)
(fun s m hβ _ => by simpa using hβ)
instance hasBinaryCoproduct_zero_right (X : C) : HasBinaryCoproduct X (0 : C) :=
HasColimit.mk β¨_, binaryCofanZeroRightIsColimit Xβ©
/-- A zero object is a right unit for categorical coproduct. -/
def coprodZeroIso (X : C) : X β¨Ώ (0 : C) β
X :=
colimit.isoColimitCocone β¨_, binaryCofanZeroRightIsColimit Xβ©
@[simp]
theorem inr_coprodZeroIso_hom (X : C) : coprod.inl β« (coprodZeroIso X).hom = π X := by
dsimp [coprodZeroIso, binaryCofanZeroRight]
simp
@[simp]
theorem coprodZeroIso_inv (X : C) : (coprodZeroIso X).inv = coprod.inl :=
rfl
instance hasPullback_over_zero (X Y : C) [HasBinaryProduct X Y] :
HasPullback (0 : X βΆ 0) (0 : Y βΆ 0) :=
HasLimit.mk
β¨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)β©
/-- The pullback over the zero object is the product. -/
def pullbackZeroZeroIso (X Y : C) [HasBinaryProduct X Y] :
pullback (0 : X βΆ 0) (0 : Y βΆ 0) β
X β¨― Y :=
limit.isoLimitCone
β¨_, isPullbackOfIsTerminalIsProduct _ _ _ _ HasZeroObject.zeroIsTerminal (prodIsProd X Y)β©
@[simp]
theorem pullbackZeroZeroIso_inv_fst (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).inv β« pullback.fst 0 0 = prod.fst := by
dsimp [pullbackZeroZeroIso]
simp
@[simp]
theorem pullbackZeroZeroIso_inv_snd (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).inv β« pullback.snd 0 0 = prod.snd := by
dsimp [pullbackZeroZeroIso]
simp
@[simp]
theorem pullbackZeroZeroIso_hom_fst (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).hom β« prod.fst = pullback.fst 0 0 := by simp [β Iso.eq_inv_comp]
@[simp]
theorem pullbackZeroZeroIso_hom_snd (X Y : C) [HasBinaryProduct X Y] :
(pullbackZeroZeroIso X Y).hom β« prod.snd = pullback.snd 0 0 := by simp [β Iso.eq_inv_comp]
instance hasPushout_over_zero (X Y : C) [HasBinaryCoproduct X Y] :
HasPushout (0 : 0 βΆ X) (0 : 0 βΆ Y) :=
HasColimit.mk
β¨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)β©
/-- The pushout over the zero object is the coproduct. -/
def pushoutZeroZeroIso (X Y : C) [HasBinaryCoproduct X Y] :
pushout (0 : 0 βΆ X) (0 : 0 βΆ Y) β
X β¨Ώ Y :=
colimit.isoColimitCocone
β¨_, isPushoutOfIsInitialIsCoproduct _ _ _ _ HasZeroObject.zeroIsInitial (coprodIsCoprod X Y)β©
@[simp]
theorem inl_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :
pushout.inl _ _ β« (pushoutZeroZeroIso X Y).hom = coprod.inl := by
dsimp [pushoutZeroZeroIso]
simp
@[simp]
theorem inr_pushoutZeroZeroIso_hom (X Y : C) [HasBinaryCoproduct X Y] :
pushout.inr _ _ β« (pushoutZeroZeroIso X Y).hom = coprod.inr := by
dsimp [pushoutZeroZeroIso]
simp
@[simp]
theorem inl_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :
coprod.inl β« (pushoutZeroZeroIso X Y).inv = pushout.inl _ _ := by simp [Iso.comp_inv_eq]
@[simp]
theorem inr_pushoutZeroZeroIso_inv (X Y : C) [HasBinaryCoproduct X Y] :
coprod.inr β« (pushoutZeroZeroIso X Y).inv = pushout.inr _ _ := by simp [Iso.comp_inv_eq]
end CategoryTheory.Limits
|
FullyFaithful.lean
|
/-
Copyright (c) 2018 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.CategoryTheory.NatIso
import Mathlib.Logic.Equiv.Defs
/-!
# Full and faithful functors
We define typeclasses `Full` and `Faithful`, decorating functors. These typeclasses
carry no data. However, we also introduce a structure `Functor.FullyFaithful` which
contains the data of the inverse map `(F.obj X βΆ F.obj Y) βΆ (X βΆ Y)` of the
map induced on morphisms by a functor `F`.
## Main definitions and results
* Use `F.map_injective` to retrieve the fact that `F.map` is injective when `[Faithful F]`.
* Similarly, `F.map_surjective` states that `F.map` is surjective when `[Full F]`.
* Use `F.preimage` to obtain preimages of morphisms when `[Full F]`.
* We prove some basic "cancellation" lemmas for full and/or faithful functors, as well as a
construction for "dividing" a functor by a faithful functor, see `Faithful.div`.
See `CategoryTheory.Equivalence.of_fullyFaithful_ess_surj` for the fact that a functor is an
equivalence if and only if it is fully faithful and essentially surjective.
-/
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe vβ vβ vβ uβ uβ uβ
namespace CategoryTheory
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D] {E : Type*} [Category E]
namespace Functor
/-- A functor `F : C β₯€ D` is full if for each `X Y : C`, `F.map` is surjective. -/
@[stacks 001C]
class Full (F : C β₯€ D) : Prop where
map_surjective {X Y : C} : Function.Surjective (F.map (X := X) (Y := Y))
/-- A functor `F : C β₯€ D` is faithful if for each `X Y : C`, `F.map` is injective. -/
@[stacks 001C]
class Faithful (F : C β₯€ D) : Prop where
/-- `F.map` is injective for each `X Y : C`. -/
map_injective : β {X Y : C}, Function.Injective (F.map : (X βΆ Y) β (F.obj X βΆ F.obj Y)) := by
cat_disch
variable {X Y : C}
theorem map_injective (F : C β₯€ D) [Faithful F] :
Function.Injective <| (F.map : (X βΆ Y) β (F.obj X βΆ F.obj Y)) :=
Faithful.map_injective
lemma map_injective_iff (F : C β₯€ D) [Faithful F] {X Y : C} (f g : X βΆ Y) :
F.map f = F.map g β f = g :=
β¨fun h => F.map_injective h, fun h => by rw [h]β©
theorem mapIso_injective (F : C β₯€ D) [Faithful F] :
Function.Injective <| (F.mapIso : (X β
Y) β (F.obj X β
F.obj Y)) := fun _ _ h =>
Iso.ext (map_injective F (congr_arg Iso.hom h :))
theorem map_surjective (F : C β₯€ D) [Full F] :
Function.Surjective (F.map : (X βΆ Y) β (F.obj X βΆ F.obj Y)) :=
Full.map_surjective
/-- The choice of a preimage of a morphism under a full functor. -/
noncomputable def preimage (F : C β₯€ D) [Full F] (f : F.obj X βΆ F.obj Y) : X βΆ Y :=
(F.map_surjective f).choose
@[simp]
theorem map_preimage (F : C β₯€ D) [Full F] {X Y : C} (f : F.obj X βΆ F.obj Y) :
F.map (preimage F f) = f :=
(F.map_surjective f).choose_spec
variable {F : C β₯€ D} {X Y Z : C}
section
variable [Full F] [F.Faithful]
@[simp]
theorem preimage_id : F.preimage (π (F.obj X)) = π X :=
F.map_injective (by simp)
@[simp]
theorem preimage_comp (f : F.obj X βΆ F.obj Y) (g : F.obj Y βΆ F.obj Z) :
F.preimage (f β« g) = F.preimage f β« F.preimage g :=
F.map_injective (by simp)
@[simp]
theorem preimage_map (f : X βΆ Y) : F.preimage (F.map f) = f :=
F.map_injective (by simp)
variable (F)
/-- If `F : C β₯€ D` is fully faithful, every isomorphism `F.obj X β
F.obj Y` has a preimage. -/
@[simps]
noncomputable def preimageIso (f : F.obj X β
F.obj Y) :
X β
Y where
hom := F.preimage f.hom
inv := F.preimage f.inv
hom_inv_id := F.map_injective (by simp)
inv_hom_id := F.map_injective (by simp)
@[simp]
theorem preimageIso_mapIso (f : X β
Y) : F.preimageIso (F.mapIso f) = f := by
ext
simp
end
variable (F) in
/-- Structure containing the data of inverse map `(F.obj X βΆ F.obj Y) βΆ (X βΆ Y)` of `F.map`
in order to express that `F` is a fully faithful functor. -/
structure FullyFaithful where
/-- The inverse map `(F.obj X βΆ F.obj Y) βΆ (X βΆ Y)` of `F.map`. -/
preimage {X Y : C} (f : F.obj X βΆ F.obj Y) : X βΆ Y
map_preimage {X Y : C} (f : F.obj X βΆ F.obj Y) : F.map (preimage f) = f := by cat_disch
preimage_map {X Y : C} (f : X βΆ Y) : preimage (F.map f) = f := by cat_disch
namespace FullyFaithful
attribute [simp] map_preimage preimage_map
variable (F) in
/-- A `FullyFaithful` structure can be obtained from the assumption the `F` is both
full and faithful. -/
noncomputable def ofFullyFaithful [F.Full] [F.Faithful] :
F.FullyFaithful where
preimage := F.preimage
variable (C) in
/-- The identity functor is fully faithful. -/
@[simps]
def id : (π C).FullyFaithful where
preimage f := f
section
variable (hF : F.FullyFaithful)
include hF
/-- The equivalence `(X βΆ Y) β (F.obj X βΆ F.obj Y)` given by `h : F.FullyFaithful`. -/
@[simps]
def homEquiv {X Y : C} : (X βΆ Y) β (F.obj X βΆ F.obj Y) where
toFun := F.map
invFun := hF.preimage
left_inv _ := by simp
right_inv _ := by simp
lemma map_injective {X Y : C} {f g : X βΆ Y} (h : F.map f = F.map g) : f = g :=
hF.homEquiv.injective h
lemma map_surjective {X Y : C} :
Function.Surjective (F.map : (X βΆ Y) β (F.obj X βΆ F.obj Y)) :=
hF.homEquiv.surjective
lemma map_bijective (X Y : C) :
Function.Bijective (F.map : (X βΆ Y) β (F.obj X βΆ F.obj Y)) :=
hF.homEquiv.bijective
@[simp]
lemma preimage_id {X : C} :
hF.preimage (π (F.obj X)) = π X :=
hF.map_injective (by simp)
@[simp, reassoc]
lemma preimage_comp {X Y Z : C} (f : F.obj X βΆ F.obj Y) (g : F.obj Y βΆ F.obj Z) :
hF.preimage (f β« g) = hF.preimage f β« hF.preimage g :=
hF.map_injective (by simp)
lemma full : F.Full where
map_surjective := hF.map_surjective
lemma faithful : F.Faithful where
map_injective := hF.map_injective
instance : Subsingleton F.FullyFaithful where
allEq hβ hβ := by
have := hβ.faithful
cases hβ with | mk fβ hfβ _ => cases hβ with | mk fβ hfβ _ =>
simp only [Functor.FullyFaithful.mk.injEq]
ext
apply F.map_injective
rw [hfβ, hfβ]
/-- The unique isomorphism `X β
Y` which induces an isomorphism `F.obj X β
F.obj Y`
when `hF : F.FullyFaithful`. -/
@[simps]
def preimageIso {X Y : C} (e : F.obj X β
F.obj Y) : X β
Y where
hom := hF.preimage e.hom
inv := hF.preimage e.inv
hom_inv_id := hF.map_injective (by simp)
inv_hom_id := hF.map_injective (by simp)
lemma isIso_of_isIso_map {X Y : C} (f : X βΆ Y) [IsIso (F.map f)] :
IsIso f := by
simpa using (hF.preimageIso (asIso (F.map f))).isIso_hom
/-- The equivalence `(X β
Y) β (F.obj X β
F.obj Y)` given by `h : F.FullyFaithful`. -/
@[simps]
def isoEquiv {X Y : C} : (X β
Y) β (F.obj X β
F.obj Y) where
toFun := F.mapIso
invFun := hF.preimageIso
left_inv := by cat_disch
right_inv := by cat_disch
/-- Fully faithful functors are stable by composition. -/
@[simps]
def comp {G : D β₯€ E} (hG : G.FullyFaithful) : (F β G).FullyFaithful where
preimage f := hF.preimage (hG.preimage f)
end
/-- If `F β G` is fully faithful and `G` is faithful, then `F` is fully faithful. -/
def ofCompFaithful {G : D β₯€ E} [G.Faithful] (hFG : (F β G).FullyFaithful) :
F.FullyFaithful where
preimage f := hFG.preimage (G.map f)
map_preimage f := G.map_injective (hFG.map_preimage (G.map f))
preimage_map f := hFG.preimage_map f
end FullyFaithful
end Functor
section
variable (F : C β₯€ D) [F.Full] [F.Faithful] {X Y : C}
/-- If the image of a morphism under a fully faithful functor in an isomorphism,
then the original morphisms is also an isomorphism.
-/
theorem isIso_of_fully_faithful (f : X βΆ Y) [IsIso (F.map f)] : IsIso f :=
β¨β¨F.preimage (inv (F.map f)), β¨F.map_injective (by simp), F.map_injective (by simp)β©β©β©
end
end CategoryTheory
namespace CategoryTheory
namespace Functor
variable {C : Type uβ} [Category.{vβ} C]
instance Full.id : Full (π C) where map_surjective := Function.surjective_id
instance Faithful.id : Functor.Faithful (π C) := { }
variable {D : Type uβ} [Category.{vβ} D] {E : Type uβ} [Category.{vβ} E]
variable (F F' : C β₯€ D) (G : D β₯€ E)
instance Faithful.comp [F.Faithful] [G.Faithful] : (F β G).Faithful where
map_injective p := F.map_injective (G.map_injective p)
theorem Faithful.of_comp [(F β G).Faithful] : F.Faithful :=
-- Porting note: (F β G).map_injective.of_comp has the incorrect type
{ map_injective := fun {_ _} => Function.Injective.of_comp (F β G).map_injective }
instance (priority := 100) [Quiver.IsThin C] : F.Faithful where
section
variable {F F'}
/-- If `F` is full, and naturally isomorphic to some `F'`, then `F'` is also full. -/
lemma Full.of_iso [Full F] (Ξ± : F β
F') : Full F' where
map_surjective {X Y} f :=
β¨F.preimage ((Ξ±.app X).hom β« f β« (Ξ±.app Y).inv), by simp [β NatIso.naturality_1 Ξ±]β©
theorem Faithful.of_iso [F.Faithful] (Ξ± : F β
F') : F'.Faithful :=
{ map_injective := fun h =>
F.map_injective (by rw [β NatIso.naturality_1 Ξ±.symm, h, NatIso.naturality_1 Ξ±.symm]) }
end
variable {F G}
theorem Faithful.of_comp_iso {H : C β₯€ E} [H.Faithful] (h : F β G β
H) : F.Faithful :=
@Faithful.of_comp _ _ _ _ _ _ F G (Faithful.of_iso h.symm)
alias _root_.CategoryTheory.Iso.faithful_of_comp := Faithful.of_comp_iso
-- We could prove this from `Faithful.of_comp_iso` using `eq_to_iso`,
-- but that would introduce a cyclic import.
theorem Faithful.of_comp_eq {H : C β₯€ E} [β : H.Faithful] (h : F β G = H) : F.Faithful :=
@Faithful.of_comp _ _ _ _ _ _ F G (h.symm βΈ β)
alias _root_.Eq.faithful_of_comp := Faithful.of_comp_eq
variable (F G)
/-- βDivideβ a functor by a faithful functor. -/
protected def Faithful.div (F : C β₯€ E) (G : D β₯€ E) [G.Faithful] (obj : C β D)
(h_obj : β X, G.obj (obj X) = F.obj X) (map : β {X Y}, (X βΆ Y) β (obj X βΆ obj Y))
(h_map : β {X Y} {f : X βΆ Y}, G.map (map f) β F.map f) : C β₯€ D :=
{ obj, map := @map,
map_id := by
intros X
apply G.map_injective
apply eq_of_heq
trans F.map (π X)
Β· exact h_map
Β· rw [F.map_id, G.map_id, h_obj X]
map_comp := by
intros X Y Z f g
refine G.map_injective <| eq_of_heq <| h_map.trans ?_
simp only [Functor.map_comp]
grind }
-- This follows immediately from `Functor.hext` (`Functor.hext h_obj @h_map`),
-- but importing `CategoryTheory.EqToHom` causes an import loop:
-- CategoryTheory.EqToHom β CategoryTheory.Opposites β
-- CategoryTheory.Equivalence β CategoryTheory.FullyFaithful
theorem Faithful.div_comp (F : C β₯€ E) [F.Faithful] (G : D β₯€ E) [G.Faithful] (obj : C β D)
(h_obj : β X, G.obj (obj X) = F.obj X) (map : β {X Y}, (X βΆ Y) β (obj X βΆ obj Y))
(h_map : β {X Y} {f : X βΆ Y}, G.map (map f) β F.map f) :
Faithful.div F G obj @h_obj @map @h_map β G = F := by
obtain β¨F_obj, _, _, _β© := F; obtain β¨G_obj, _, _, _β© := G
unfold Faithful.div Functor.comp
have : F_obj = G_obj β obj := (funext h_obj).symm
subst this
congr
simp only [Function.comp_apply, heq_eq_eq] at h_map
ext
exact h_map
theorem Faithful.div_faithful (F : C β₯€ E) [F.Faithful] (G : D β₯€ E) [G.Faithful] (obj : C β D)
(h_obj : β X, G.obj (obj X) = F.obj X) (map : β {X Y}, (X βΆ Y) β (obj X βΆ obj Y))
(h_map : β {X Y} {f : X βΆ Y}, G.map (map f) β F.map f) :
Functor.Faithful (Faithful.div F G obj @h_obj @map @h_map) :=
(Faithful.div_comp F G _ h_obj _ @h_map).faithful_of_comp
instance Full.comp [Full F] [Full G] : Full (F β G) where
map_surjective f := β¨F.preimage (G.preimage f), by simpβ©
/-- If `F β G` is full and `G` is faithful, then `F` is full. -/
lemma Full.of_comp_faithful [Full <| F β G] [G.Faithful] : Full F where
map_surjective f := β¨(F β G).preimage (G.map f), G.map_injective ((F β G).map_preimage _)β©
/-- If `F β G` is full and `G` is faithful, then `F` is full. -/
lemma Full.of_comp_faithful_iso {F : C β₯€ D} {G : D β₯€ E} {H : C β₯€ E} [Full H] [G.Faithful]
(h : F β G β
H) : Full F := by
have := Full.of_iso h.symm
exact Full.of_comp_faithful F G
/-- Given a natural isomorphism between `F β H` and `G β H` for a fully faithful functor `H`, we
can 'cancel' it to give a natural iso between `F` and `G`.
-/
noncomputable def fullyFaithfulCancelRight {F G : C β₯€ D} (H : D β₯€ E) [Full H] [H.Faithful]
(comp_iso : F β H β
G β H) : F β
G :=
NatIso.ofComponents (fun X => H.preimageIso (comp_iso.app X)) fun f =>
H.map_injective (by simpa using comp_iso.hom.naturality f)
@[simp]
theorem fullyFaithfulCancelRight_hom_app {F G : C β₯€ D} {H : D β₯€ E} [Full H] [H.Faithful]
(comp_iso : F β H β
G β H) (X : C) :
(fullyFaithfulCancelRight H comp_iso).hom.app X = H.preimage (comp_iso.hom.app X) :=
rfl
@[simp]
theorem fullyFaithfulCancelRight_inv_app {F G : C β₯€ D} {H : D β₯€ E} [Full H] [H.Faithful]
(comp_iso : F β H β
G β H) (X : C) :
(fullyFaithfulCancelRight H comp_iso).inv.app X = H.preimage (comp_iso.inv.app X) :=
rfl
end Functor
end CategoryTheory
|
matrix.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 choice.
From mathcomp Require Import fintype finfun finset fingroup perm order div.
From mathcomp Require Import prime binomial ssralg countalg finalg zmodp bigop.
(******************************************************************************)
(* Basic concrete linear algebra : definition of type for matrices, and all *)
(* basic matrix operations including determinant, trace and support for block *)
(* decomposition. Matrices are represented by a row-major list of their *)
(* coefficients but this implementation is hidden by three levels of wrappers *)
(* (Matrix/Finfun/Tuple) so the matrix type should be treated as abstract and *)
(* handled using only the operations described below: *)
(* 'M[R]_(m, n) == the type of m rows by n columns matrices with *)
(* 'M_(m, n) coefficients in R; the [R] is optional and is usually *)
(* omitted. *)
(* 'M[R]_n, 'M_n == the type of n x n square matrices. *)
(* 'rV[R]_n, 'rV_n == the type of 1 x n row vectors. *)
(* 'cV[R]_n, 'cV_n == the type of n x 1 column vectors. *)
(* \matrix_(i < m, j < n) Expr(i, j) == *)
(* the m x n matrix with general coefficient Expr(i, j), *)
(* with i : 'I_m and j : 'I_n. the < m bound can be omitted *)
(* if it is equal to n, though usually both bounds are *)
(* omitted as they can be inferred from the context. *)
(* \row_(j < n) Expr(j), \col_(i < m) Expr(i) *)
(* the row / column vectors with general term Expr; the *)
(* parentheses can be omitted along with the bound. *)
(* \matrix_(i < m) RowExpr(i) == *)
(* the m x n matrix with row i given by RowExpr(i) : 'rV_n. *)
(* A i j == the coefficient of matrix A : 'M_(m, n) in column j of *)
(* row i, where i : 'I_m, and j : 'I_n (via the coercion *)
(* fun_of_matrix : matrix >-> Funclass). *)
(* const_mx a == the constant matrix whose entries are all a (dimensions *)
(* should be determined by context). *)
(* map_mx f A == the pointwise image of A by f, i.e., the matrix Af *)
(* congruent to A with Af i j = f (A i j) for all i and j. *)
(* map2_mx f A B == the pointwise image of A and B by f, i.e., the matrix *)
(* ABf congruent to A with ABf i j = f (A i j) (B i j) *)
(* for all i and j. *)
(* A^T == the matrix transpose of A. *)
(* row i A == the i'th row of A (this is a row vector). *)
(* col j A == the j'th column of A (a column vector). *)
(* row' i A == A with the i'th row spliced out. *)
(* col' i A == A with the j'th column spliced out. *)
(* xrow i1 i2 A == A with rows i1 and i2 interchanged. *)
(* xcol j1 j2 A == A with columns j1 and j2 interchanged. *)
(* row_perm s A == A : 'M_(m, n) with rows permuted by s : 'S_m. *)
(* col_perm s A == A : 'M_(m, n) with columns permuted by s : 'S_n. *)
(* row_mx Al Ar == the row block matrix <Al Ar> obtained by concatenating *)
(* two matrices Al and Ar of the same height. *)
(* col_mx Au Ad == the column block matrix / Au \ (Au and Ad must have the *)
(* same width). \ Ad / *)
(* block_mx Aul Aur Adl Adr == the block matrix / Aul Aur \ *)
(* \ Adl Adr / *)
(* \mxblock_(i < m, j < n) B i j *)
(* == the block matrix of type 'M_(\sum_i p_ i, \sum_j q_ j) *)
(* / (B 0 0) β― (B 0 j) β― (B 0 n) \ *)
(* | ... ... ... | *)
(* | (B i 0) β― (B i j) β― (B i n) | *)
(* | ... ... ... | *)
(* \ (B m 0) β― (B m j) β― (B m n) / *)
(* where each block (B i j) has type 'M_(p_ i, q_ j). *)
(* \mxdiag_(i < n) B i == the block square matrix of type 'M_(\sum_i p_ i) *)
(* / (B 0) 0 \ *)
(* | ... ... | *)
(* | 0 (B i) 0 | *)
(* | ... ... | *)
(* \ 0 (B n) / *)
(* where each block (B i) has type 'M_(p_ i). *)
(* \mxrow_(j < n) B j == the block matrix of type 'M_(m, \sum_j q_ j). *)
(* < (B 0) ... (B n) > *)
(* where each block (B j) has type 'M_(m, q_ j). *)
(* \mxcol_(i < m) B i == the block matrix of type 'M_(\sum_i p_ i, n) *)
(* / (B 0) \ *)
(* | ... | *)
(* \ (B m) / *)
(* where each block (B i) has type 'M(p_ i, n). *)
(* [l|r]submx A == the left/right submatrices of a row block matrix A. *)
(* Note that the type of A, 'M_(m, n1 + n2) indicates how A *)
(* should be decomposed. *)
(* [u|d]submx A == the up/down submatrices of a column block matrix A. *)
(* [u|d][l|r]submx A == the upper left, etc submatrices of a block matrix A. *)
(* submxblock A i j == the block submatrix of type 'M_(p_ i, q_ j) of A. *)
(* The type of A, 'M_(\sum_i p_ i, \sum_i q_ i) *)
(* indicates how A should be decomposed. *)
(* There is no analogous for mxdiag since one can use *)
(* submxblock A i i to extract a diagonal block. *)
(* submxrow A j == the submatrix of type 'M_(m, q_ j) of A. The type of A, *)
(* 'M_(m, \sum_j q_ j) indicates how A should be decomposed.*)
(* submxrow A j == the submatrix of type 'M_(p_ i, n) of A. The type of A, *)
(* 'M_(\sum_i p_ i, n) indicates how A should be decomposed.*)
(* mxsub f g A == generic reordered submatrix, given by functions f and g *)
(* which specify which subset of rows and columns to take *)
(* and how to reorder them, e.g. picking f and g to be *)
(* increasing yields traditional submatrices. *)
(* := \matrix_(i, j) A (f i) (g i) *)
(* rowsub f A := mxsub f id A *)
(* colsub g A := mxsub id g A *)
(* castmx eq_mn A == A : 'M_(m, n) cast to 'M_(m', n') using the equation *)
(* pair eq_mn : (m = m') * (n = n'). This is the usual *)
(* workaround for the syntactic limitations of dependent *)
(* types in Coq, and can be used to introduce a block *)
(* decomposition. It simplifies to A when eq_mn is the *)
(* pair (erefl m, erefl n) (using rewrite /castmx /=). *)
(* conform_mx B A == A if A and B have the same dimensions, else B. *)
(* mxvec A == a row vector of width m * n holding all the entries of *)
(* the m x n matrix A. *)
(* mxvec_index i j == the index of A i j in mxvec A. *)
(* vec_mx v == the inverse of mxvec, reshaping a vector of width m * n *)
(* back into into an m x n rectangular matrix. *)
(* In 'M[R]_(m, n), R can be any type, but 'M[R]_(m, n) inherits the eqType, *)
(* choiceType, countType, finType, nmodType, and zmodType structures from R; *)
(* 'M[R]_(m, n) also forms a natural lmodType R when R is a pzRingType. *)
(* Square matrices of type 'M[R]_n (resp. non-trivial square matrices of type *)
(* 'M[R]_n.+1) inherit the pz(Semi)RingType (resp. nz(Semi)RingType) structure*)
(* from R; indeed they then have an algebra structure (lalgType R, or algType *)
(* R if R is a comNzRingType, or even unitAlgType if R is a comUnitRingType). *)
(* We thus provide separate syntax for the general matrix multiplication, *)
(* and other operations for matrices over a pzRingType R: *)
(* A *m B == the matrix product of A and B; the width of A must be *)
(* equal to the height of B. *)
(* a%:M == the scalar matrix with a's on the main diagonal; in *)
(* particular 1%:M denotes the identity matrix, and is *)
(* equal to 1%R when n is of the form n'.+1 (e.g., n >= 1). *)
(* is_scalar_mx A <=> A is a scalar matrix (A = a%:M for some A). *)
(* diag_mx d == the diagonal matrix whose main diagonal is d : 'rV_n. *)
(* is_diag_mx A <=> A is a diagonal matrix: forall i j, i != j -> A i j = 0 *)
(* is_trig_mx A <=> A is a triangular matrix: forall i j, i < j -> A i j = 0 *)
(* delta_mx i j == the matrix with a 1 in row i, column j and 0 elsewhere. *)
(* pid_mx r == the partial identity matrix with 1s only on the r first *)
(* coefficients of the main diagonal; the dimensions of *)
(* pid_mx r are determined by the context, and pid_mx r can *)
(* be rectangular. *)
(* copid_mx r == the complement to 1%:M of pid_mx r: a square diagonal *)
(* matrix with 1s on all but the first r coefficients on *)
(* its main diagonal. *)
(* perm_mx s == the n x n permutation matrix for s : 'S_n. *)
(* tperm_mx i1 i2 == the permutation matrix that exchanges i1 i2 : 'I_n. *)
(* is_perm_mx A == A is a permutation matrix. *)
(* lift0_mx A == the 1 + n square matrix block_mx 1 0 0 A when A : 'M_n. *)
(* \tr A == the trace of a square matrix A. *)
(* \det A == the determinant of A, using the Leibnitz formula. *)
(* cofactor i j A == the i, j cofactor of A (the signed i, j minor of A), *)
(* \adj A == the adjugate matrix of A (\adj A i j = cofactor j i A). *)
(* A \in unitmx == A is invertible (R must be a comUnitRingType). *)
(* invmx A == the inverse matrix of A if A \in unitmx A, otherwise A. *)
(* A \is a mxOver S == the matrix A has its coefficients in S. *)
(* comm_mx A B := A *m B = B *m A *)
(* comm_mxb A B := A *m B == B *m A *)
(* all_comm_mx As fs := all2rel comm_mxb fs *)
(* The following operations provide a correspondence between linear functions *)
(* and matrices: *)
(* lin1_mx f == the m x n matrix that emulates via right product *)
(* a (linear) function f : 'rV_m -> 'rV_n on ROW VECTORS *)
(* lin_mx f == the (m1 * n1) x (m2 * n2) matrix that emulates, via the *)
(* right multiplication on the mxvec encodings, a linear *)
(* function f : 'M_(m1, n1) -> 'M_(m2, n2) *)
(* lin_mul_row u := lin1_mx (mulmx u \o vec_mx) (applies a row-encoded *)
(* function to the row-vector u). *)
(* mulmx A == partially applied matrix multiplication (mulmx A B is *)
(* displayed as A *m B), with, for A : 'M_(m, n), a *)
(* canonical {linear 'M_(n, p) -> 'M(m, p}} structure. *)
(* mulmxr A == self-simplifying right-hand matrix multiplication, i.e., *)
(* mulmxr A B simplifies to B *m A, with, for A : 'M_(n, p), *)
(* a canonical {linear 'M_(m, n) -> 'M(m, p}} structure. *)
(* lin_mulmx A := lin_mx (mulmx A). *)
(* lin_mulmxr A := lin_mx (mulmxr A). *)
(* We also extend any finType structure of R to 'M[R]_(m, n), and define: *)
(* {'GL_n[R]} == the finGroupType of units of 'M[R]_n.-1.+1. *)
(* 'GL_n[R] == the general linear group of all matrices in {'GL_n(R)}. *)
(* 'GL_n(p) == 'GL_n['F_p], the general linear group of a prime field. *)
(* GLval u == the coercion of u : {'GL_n(R)} to a matrix. *)
(* In addition to the lemmas relevant to these definitions, this file also *)
(* proves several classic results, including : *)
(* - The determinant is a multilinear alternate form. *)
(* - The Laplace determinant expansion formulas: expand_det_[row|col]. *)
(* - The Cramer rule : mul_mx_adj & mul_adj_mx. *)
(* Vandermonde m a == the 'M[R]_(m, n) Vandermonde matrix, given a : 'rV_n *)
(* / 1 ... 1 \ *)
(* | (a 0 0) ... (a 0 (n - 1)) | *)
(* | (a 0 0 ^+ 2) ... (a 0 (n - 1) ^+ 2) | *)
(* | ... ... | *)
(* \ (a 0 0 ^+ (m - 1)) ... (a 0 (n - 1) ^+ (m - 1)) / *)
(* := \matrix_(i < m, j < n) a 0 j ^+ i. *)
(* Finally, as an example of the use of block products, we program and prove *)
(* the correctness of a classical linear algebra algorithm: *)
(* cormen_lup A == the triangular decomposition (L, U, P) of a nontrivial *)
(* square matrix A into a lower triagular matrix L with 1s *)
(* on the main diagonal, an upper matrix U, and a *)
(* permutation matrix P, such that P * A = L * U. *)
(* This is example only; we use a different, more precise algorithm to *)
(* develop the theory of matrix ranks and row spaces in mxalgebra.v *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Import GRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "''M_' n" (at level 0, n at level 2, format "''M_' n").
Reserved Notation "''rV_' n" (at level 0, n at level 2, format "''rV_' n").
Reserved Notation "''cV_' n" (at level 0, n at level 2, format "''cV_' n").
Reserved Notation "''M_' ( n )". (* only parsing *)
Reserved Notation "''M_' ( m , n )" (format "''M_' ( m , n )").
Reserved Notation "''M[' R ]_ n" (at level 0, n at level 2). (* only parsing *)
Reserved Notation "''rV[' R ]_ n" (at level 0, n at level 2). (* only parsing *)
Reserved Notation "''cV[' R ]_ n" (at level 0, n at level 2). (* only parsing *)
Reserved Notation "''M[' R ]_ ( n )". (* only parsing *)
Reserved Notation "''M[' R ]_ ( m , n )". (* only parsing *)
Reserved Notation "\matrix_ i E"
(at level 34, E at level 39, i at level 2, format "\matrix_ i E").
Reserved Notation "\matrix_ ( i < n ) E"
(E at level 39, i, n at level 50). (* only parsing *)
Reserved Notation "\matrix_ ( i , j ) E"
(E at level 39, j at level 50, format "\matrix_ ( i , j ) E").
Reserved Notation "\matrix[ k ]_ ( i , j ) E"
(at level 34, E at level 39, i, j at level 50,
format "\matrix[ k ]_ ( i , j ) E").
Reserved Notation "\matrix_ ( i < m , j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "\matrix_ ( i , j < n ) E"
(E at level 39, n at level 50). (* only parsing *)
Reserved Notation "\row_ j E"
(at level 34, E at level 39, j at level 2, format "\row_ j E").
Reserved Notation "\row_ ( j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "\col_ j E"
(at level 34, E at level 39, j at level 2, format "\col_ j E").
Reserved Notation "\col_ ( j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "\mxblock_ ( i , j ) E"
(at level 34, E at level 39, i, j at level 50,
format "\mxblock_ ( i , j ) E").
Reserved Notation "\mxblock_ ( i < m , j < n ) E"
(E at level 39, m, j, n at level 50). (* only parsing *)
Reserved Notation "\mxblock_ ( i , j < n ) E"
(E at level 39, n at level 50). (* only parsing *)
Reserved Notation "\mxrow_ j E"
(at level 34, E at level 39, j at level 2, format "\mxrow_ j E").
Reserved Notation "\mxrow_ ( j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "\mxcol_ j E"
(at level 34, E at level 39, j at level 2, format "\mxcol_ j E").
Reserved Notation "\mxcol_ ( j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "\mxdiag_ j E"
(at level 34, E at level 39, j at level 2, format "\mxdiag_ j E").
Reserved Notation "\mxdiag_ ( j < n ) E"
(E at level 39, j, n at level 50). (* only parsing *)
Reserved Notation "x %:M" (format "x %:M").
Reserved Notation "A *m B" (at level 40, left associativity, format "A *m B").
Reserved Notation "A ^T" (format "A ^T").
Reserved Notation "\tr A" (at level 10, A at level 8, format "\tr A").
Reserved Notation "\det A" (at level 10, A at level 8, format "\det A").
Reserved Notation "\adj A" (at level 10, A at level 8, format "\adj A").
Reserved Notation "{ ''GL_' n [ R ] }"
(n at level 2, format "{ ''GL_' n [ R ] }").
Reserved Notation "{ ''GL_' n ( p ) }"
(p at level 10, format "{ ''GL_' n ( p ) }").
Local Notation simp := (Monoid.Theory.simpm, oppr0).
(*****************************************************************************)
(****************************Type Definition**********************************)
(*****************************************************************************)
Section MatrixDef.
Variable R : Type.
Variables m n : nat.
(* Basic linear algebra (matrices). *)
(* We use dependent types (ordinals) for the indices so that ranges are *)
(* mostly inferred automatically *)
Variant matrix : predArgType := Matrix of {ffun 'I_m * 'I_n -> R}.
Definition mx_val A := let: Matrix g := A in g.
HB.instance Definition _ := [isNew for mx_val].
Definition fun_of_matrix A (i : 'I_m) (j : 'I_n) := mx_val A (i, j).
Coercion fun_of_matrix : matrix >-> Funclass.
End MatrixDef.
Fact matrix_key : unit. Proof. by []. Qed.
HB.lock
Definition matrix_of_fun R (m n : nat) (k : unit) (F : 'I_m -> 'I_n -> R) :=
@Matrix R m n [ffun ij => F ij.1 ij.2].
Canonical matrix_unlockable := Unlockable matrix_of_fun.unlock.
Section MatrixDef2.
Variable R : Type.
Variables m n : nat.
Implicit Type F : 'I_m -> 'I_n -> R.
Lemma mxE k F : matrix_of_fun k F =2 F.
Proof. by move=> i j; rewrite unlock /fun_of_matrix /= ffunE. Qed.
Lemma matrixP (A B : matrix R m n) : A =2 B <-> A = B.
Proof.
rewrite /fun_of_matrix; split=> [/= eqAB | -> //].
by apply/val_inj/ffunP=> [[i j]]; apply: eqAB.
Qed.
Lemma eq_mx k F1 F2 : (F1 =2 F2) -> matrix_of_fun k F1 = matrix_of_fun k F2.
Proof. by move=> eq_F; apply/matrixP => i j; rewrite !mxE eq_F. Qed.
End MatrixDef2.
Arguments eq_mx {R m n k} [F1] F2 eq_F12.
Bind Scope ring_scope with matrix.
Notation "''M[' R ]_ ( m , n )" := (matrix R m n) (only parsing): type_scope.
Notation "''rV[' R ]_ n" := 'M[R]_(1, n) (only parsing) : type_scope.
Notation "''cV[' R ]_ n" := 'M[R]_(n, 1) (only parsing) : type_scope.
Notation "''M[' R ]_ n" := 'M[R]_(n, n) (only parsing) : type_scope.
Notation "''M[' R ]_ ( n )" := 'M[R]_n (only parsing) : type_scope.
Notation "''M_' ( m , n )" := 'M[_]_(m, n) : type_scope.
Notation "''rV_' n" := 'M_(1, n) : type_scope.
Notation "''cV_' n" := 'M_(n, 1) : type_scope.
Notation "''M_' n" := 'M_(n, n) : type_scope.
Notation "''M_' ( n )" := 'M_n (only parsing) : type_scope.
Notation "\matrix[ k ]_ ( i , j ) E" := (matrix_of_fun k (fun i j => E)) :
ring_scope.
Notation "\matrix_ ( i < m , j < n ) E" :=
(@matrix_of_fun _ m n matrix_key (fun i j => E)) (only parsing) : ring_scope.
Notation "\matrix_ ( i , j < n ) E" :=
(\matrix_(i < n, j < n) E) (only parsing) : ring_scope.
Notation "\matrix_ ( i , j ) E" := (\matrix_(i < _, j < _) E) : ring_scope.
Notation "\matrix_ ( i < m ) E" :=
(\matrix_(i < m, j < _) @fun_of_matrix _ 1 _ E 0 j)
(only parsing) : ring_scope.
Notation "\matrix_ i E" := (\matrix_(i < _) E) : ring_scope.
Notation "\col_ ( i < n ) E" := (@matrix_of_fun _ n 1 matrix_key (fun i _ => E))
(only parsing) : ring_scope.
Notation "\col_ i E" := (\col_(i < _) E) : ring_scope.
Notation "\row_ ( j < n ) E" := (@matrix_of_fun _ 1 n matrix_key (fun _ j => E))
(only parsing) : ring_scope.
Notation "\row_ j E" := (\row_(j < _) E) : ring_scope.
HB.instance Definition _ (R : eqType) m n := [Equality of 'M[R]_(m, n) by <:].
HB.instance Definition _ (R : choiceType) m n := [Choice of 'M[R]_(m, n) by <:].
HB.instance Definition _ (R : countType) m n := [Countable of 'M[R]_(m, n) by <:].
HB.instance Definition _ (R : finType) m n := [Finite of 'M[R]_(m, n) by <:].
Lemma card_mx (F : finType) m n : (#|{: 'M[F]_(m, n)}| = #|F| ^ (m * n))%N.
Proof. by rewrite card_sub card_ffun card_prod !card_ord. Qed.
(*****************************************************************************)
(****** Matrix structural operations (transpose, permutation, blocks) ********)
(*****************************************************************************)
Section MatrixStructural.
Variable R : Type.
(* Constant matrix *)
Fact const_mx_key : unit. Proof. by []. Qed.
Definition const_mx m n a : 'M[R]_(m, n) := \matrix[const_mx_key]_(i, j) a.
Arguments const_mx {m n}.
Section FixedDim.
(* Definitions and properties for which we can work with fixed dimensions. *)
Variables m n : nat.
Implicit Type A : 'M[R]_(m, n).
(* Reshape a matrix, to accommodate the block functions for instance. *)
Definition castmx m' n' (eq_mn : (m = m') * (n = n')) A : 'M_(m', n') :=
let: erefl in _ = m' := eq_mn.1 return 'M_(m', n') in
let: erefl in _ = n' := eq_mn.2 return 'M_(m, n') in A.
Definition conform_mx m' n' B A :=
match m =P m', n =P n' with
| ReflectT eq_m, ReflectT eq_n => castmx (eq_m, eq_n) A
| _, _ => B
end.
(* Transpose a matrix *)
Fact trmx_key : unit. Proof. by []. Qed.
Definition trmx A := \matrix[trmx_key]_(i, j) A j i.
(* Permute a matrix vertically (rows) or horizontally (columns) *)
Fact row_perm_key : unit. Proof. by []. Qed.
Definition row_perm (s : 'S_m) A := \matrix[row_perm_key]_(i, j) A (s i) j.
Fact col_perm_key : unit. Proof. by []. Qed.
Definition col_perm (s : 'S_n) A := \matrix[col_perm_key]_(i, j) A i (s j).
(* Exchange two rows/columns of a matrix *)
Definition xrow i1 i2 := row_perm (tperm i1 i2).
Definition xcol j1 j2 := col_perm (tperm j1 j2).
(* Row/Column sub matrices of a matrix *)
Definition row i0 A := \row_j A i0 j.
Definition col j0 A := \col_i A i j0.
(* Removing a row/column from a matrix *)
Definition row' i0 A := \matrix_(i, j) A (lift i0 i) j.
Definition col' j0 A := \matrix_(i, j) A i (lift j0 j).
(* reindexing/subindex a matrix *)
Definition mxsub m' n' f g A := \matrix_(i < m', j < n') A (f i) (g j).
Local Notation colsub g := (mxsub id g).
Local Notation rowsub f := (mxsub f id).
Lemma castmx_const m' n' (eq_mn : (m = m') * (n = n')) a :
castmx eq_mn (const_mx a) = const_mx a.
Proof. by case: eq_mn; case: m' /; case: n' /. Qed.
Lemma trmx_const a : trmx (const_mx a) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma row_perm_const s a : row_perm s (const_mx a) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma col_perm_const s a : col_perm s (const_mx a) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma xrow_const i1 i2 a : xrow i1 i2 (const_mx a) = const_mx a.
Proof. exact: row_perm_const. Qed.
Lemma xcol_const j1 j2 a : xcol j1 j2 (const_mx a) = const_mx a.
Proof. exact: col_perm_const. Qed.
Lemma rowP (u v : 'rV[R]_n) : u 0 =1 v 0 <-> u = v.
Proof. by split=> [eq_uv | -> //]; apply/matrixP=> i; rewrite ord1. Qed.
Lemma rowK u_ i0 : row i0 (\matrix_i u_ i) = u_ i0.
Proof. by apply/rowP=> i'; rewrite !mxE. Qed.
Lemma row_matrixP A B : (forall i, row i A = row i B) <-> A = B.
Proof.
split=> [eqAB | -> //]; apply/matrixP=> i j.
by move/rowP/(_ j): (eqAB i); rewrite !mxE.
Qed.
Lemma colP (u v : 'cV[R]_m) : u^~ 0 =1 v^~ 0 <-> u = v.
Proof. by split=> [eq_uv | -> //]; apply/matrixP=> i j; rewrite ord1. Qed.
Lemma row_const i0 a : row i0 (const_mx a) = const_mx a.
Proof. by apply/rowP=> j; rewrite !mxE. Qed.
Lemma col_const j0 a : col j0 (const_mx a) = const_mx a.
Proof. by apply/colP=> i; rewrite !mxE. Qed.
Lemma row'_const i0 a : row' i0 (const_mx a) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma col'_const j0 a : col' j0 (const_mx a) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma col_perm1 A : col_perm 1 A = A.
Proof. by apply/matrixP=> i j; rewrite mxE perm1. Qed.
Lemma row_perm1 A : row_perm 1 A = A.
Proof. by apply/matrixP=> i j; rewrite mxE perm1. Qed.
Lemma col_permM s t A : col_perm (s * t) A = col_perm s (col_perm t A).
Proof. by apply/matrixP=> i j; rewrite !mxE permM. Qed.
Lemma row_permM s t A : row_perm (s * t) A = row_perm s (row_perm t A).
Proof. by apply/matrixP=> i j; rewrite !mxE permM. Qed.
Lemma col_row_permC s t A :
col_perm s (row_perm t A) = row_perm t (col_perm s A).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma rowEsub i : row i = rowsub (fun=> i). Proof. by []. Qed.
Lemma colEsub j : col j = colsub (fun=> j). Proof. by []. Qed.
Lemma row'Esub i : row' i = rowsub (lift i). Proof. by []. Qed.
Lemma col'Esub j : col' j = colsub (lift j). Proof. by []. Qed.
Lemma row_permEsub s : row_perm s = rowsub s.
Proof. by rewrite /row_perm /mxsub !unlock. Qed.
Lemma col_permEsub s : col_perm s = colsub s.
Proof. by rewrite /col_perm /mxsub !unlock. Qed.
Lemma xrowEsub i1 i2 : xrow i1 i2 = rowsub (tperm i1 i2).
Proof. exact: row_permEsub. Qed.
Lemma xcolEsub j1 j2 : xcol j1 j2 = colsub (tperm j1 j2).
Proof. exact: col_permEsub. Qed.
Lemma mxsub_id : mxsub id id =1 id.
Proof. by move=> A; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma eq_mxsub m' n' f f' g g' : f =1 f' -> g =1 g' ->
@mxsub m' n' f g =1 mxsub f' g'.
Proof. by move=> eq_f eq_g A; apply/matrixP => i j; rewrite !mxE eq_f eq_g. Qed.
Lemma eq_rowsub m' (f f' : 'I_m' -> 'I_m) : f =1 f' -> rowsub f =1 rowsub f'.
Proof. by move=> /eq_mxsub; apply. Qed.
Lemma eq_colsub n' (g g' : 'I_n' -> 'I_n) : g =1 g' -> colsub g =1 colsub g'.
Proof. by move=> /eq_mxsub; apply. Qed.
Lemma mxsub_eq_id f g : f =1 id -> g =1 id -> mxsub f g =1 id.
Proof. by move=> fid gid A; rewrite (eq_mxsub fid gid) mxsub_id. Qed.
Lemma mxsub_eq_colsub n' f g : f =1 id -> @mxsub _ n' f g =1 colsub g.
Proof. by move=> f_id; apply: eq_mxsub. Qed.
Lemma mxsub_eq_rowsub m' f g : g =1 id -> @mxsub m' _ f g =1 rowsub f.
Proof. exact: eq_mxsub. Qed.
Lemma mxsub_ffunl m' n' f g : @mxsub m' n' (finfun f) g =1 mxsub f g.
Proof. by apply: eq_mxsub => // i; rewrite ffunE. Qed.
Lemma mxsub_ffunr m' n' f g : @mxsub m' n' f (finfun g) =1 mxsub f g.
Proof. by apply: eq_mxsub => // i; rewrite ffunE. Qed.
Lemma mxsub_ffun m' n' f g : @mxsub m' n' (finfun f) (finfun g) =1 mxsub f g.
Proof. by move=> A; rewrite mxsub_ffunl mxsub_ffunr. Qed.
Lemma mxsub_const m' n' f g a : @mxsub m' n' f g (const_mx a) = const_mx a.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
End FixedDim.
Local Notation colsub g := (mxsub id g).
Local Notation rowsub f := (mxsub f id).
Local Notation "A ^T" := (trmx A) : ring_scope.
Lemma castmx_id m n erefl_mn (A : 'M_(m, n)) : castmx erefl_mn A = A.
Proof. by case: erefl_mn => e_m e_n; rewrite [e_m]eq_axiomK [e_n]eq_axiomK. Qed.
Lemma castmx_comp m1 n1 m2 n2 m3 n3 (eq_m1 : m1 = m2) (eq_n1 : n1 = n2)
(eq_m2 : m2 = m3) (eq_n2 : n2 = n3) A :
castmx (eq_m2, eq_n2) (castmx (eq_m1, eq_n1) A)
= castmx (etrans eq_m1 eq_m2, etrans eq_n1 eq_n2) A.
Proof.
by case: m2 / eq_m1 eq_m2; case: m3 /; case: n2 / eq_n1 eq_n2; case: n3 /.
Qed.
Lemma castmxK m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) :
cancel (castmx (eq_m, eq_n)) (castmx (esym eq_m, esym eq_n)).
Proof. by case: m2 / eq_m; case: n2 / eq_n. Qed.
Lemma castmxKV m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) :
cancel (castmx (esym eq_m, esym eq_n)) (castmx (eq_m, eq_n)).
Proof. by case: m2 / eq_m; case: n2 / eq_n. Qed.
(* This can be use to reverse an equation that involves a cast. *)
Lemma castmx_sym m1 n1 m2 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) A1 A2 :
A1 = castmx (eq_m, eq_n) A2 -> A2 = castmx (esym eq_m, esym eq_n) A1.
Proof. by move/(canLR (castmxK _ _)). Qed.
Lemma eq_castmx m1 n1 m2 n2 (eq_mn eq_mn' : (m1 = m2) * (n1 = n2)) :
castmx eq_mn =1 castmx eq_mn'.
Proof.
case: eq_mn eq_mn' => [em en] [em' en'] A.
by apply: (canRL (castmxKV _ _)); rewrite castmx_comp castmx_id.
Qed.
Lemma castmxE m1 n1 m2 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A i j :
castmx eq_mn A i j =
A (cast_ord (esym eq_mn.1) i) (cast_ord (esym eq_mn.2) j).
Proof.
by do [case: eq_mn; case: m2 /; case: n2 /] in A i j *; rewrite !cast_ord_id.
Qed.
Lemma conform_mx_id m n (B A : 'M_(m, n)) : conform_mx B A = A.
Proof. by rewrite /conform_mx; do 2!case: eqP => // *; rewrite castmx_id. Qed.
Lemma nonconform_mx m m' n n' (B : 'M_(m', n')) (A : 'M_(m, n)) :
(m != m') || (n != n') -> conform_mx B A = B.
Proof. by rewrite /conform_mx; do 2!case: eqP. Qed.
Lemma conform_castmx m1 n1 m2 n2 m3 n3
(e_mn : (m2 = m3) * (n2 = n3)) (B : 'M_(m1, n1)) A :
conform_mx B (castmx e_mn A) = conform_mx B A.
Proof. by do [case: e_mn; case: m3 /; case: n3 /] in A *. Qed.
Lemma trmxK m n : cancel (@trmx m n) (@trmx n m).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma trmx_inj m n : injective (@trmx m n).
Proof. exact: can_inj (@trmxK m n). Qed.
Lemma trmx_cast m1 n1 m2 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A :
(castmx eq_mn A)^T = castmx (eq_mn.2, eq_mn.1) A^T.
Proof.
by case: eq_mn => eq_m eq_n; apply/matrixP=> i j; rewrite !(mxE, castmxE).
Qed.
Lemma trmx_conform m' n' m n (B : 'M_(m', n')) (A : 'M_(m, n)) :
(conform_mx B A)^T = conform_mx B^T A^T.
Proof.
rewrite /conform_mx; do !case: eqP; rewrite ?mxE// => en em.
by rewrite trmx_cast.
Qed.
Lemma tr_row_perm m n s (A : 'M_(m, n)) : (row_perm s A)^T = col_perm s A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_col_perm m n s (A : 'M_(m, n)) : (col_perm s A)^T = row_perm s A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_xrow m n i1 i2 (A : 'M_(m, n)) : (xrow i1 i2 A)^T = xcol i1 i2 A^T.
Proof. exact: tr_row_perm. Qed.
Lemma tr_xcol m n j1 j2 (A : 'M_(m, n)) : (xcol j1 j2 A)^T = xrow j1 j2 A^T.
Proof. exact: tr_col_perm. Qed.
Lemma row_id n i (V : 'rV_n) : row i V = V.
Proof. by apply/rowP=> j; rewrite mxE [i]ord1. Qed.
Lemma col_id n j (V : 'cV_n) : col j V = V.
Proof. by apply/colP=> i; rewrite mxE [j]ord1. Qed.
Lemma row_eq m1 m2 n i1 i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
row i1 A1 = row i2 A2 -> A1 i1 =1 A2 i2.
Proof. by move/rowP=> eqA12 j; have /[!mxE] := eqA12 j. Qed.
Lemma col_eq m n1 n2 j1 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
col j1 A1 = col j2 A2 -> A1^~ j1 =1 A2^~ j2.
Proof. by move/colP=> eqA12 i; have /[!mxE] := eqA12 i. Qed.
Lemma row'_eq m n i0 (A B : 'M_(m, n)) :
row' i0 A = row' i0 B -> {in predC1 i0, A =2 B}.
Proof.
move=> /matrixP eqAB' i /[!inE]/[1!eq_sym]/unlift_some[i' -> _] j.
by have /[!mxE] := eqAB' i' j.
Qed.
Lemma col'_eq m n j0 (A B : 'M_(m, n)) :
col' j0 A = col' j0 B -> forall i, {in predC1 j0, A i =1 B i}.
Proof.
move=> /matrixP eqAB' i j /[!inE]/[1!eq_sym]/unlift_some[j' -> _].
by have /[!mxE] := eqAB' i j'.
Qed.
Lemma tr_row m n i0 (A : 'M_(m, n)) : (row i0 A)^T = col i0 A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_row' m n i0 (A : 'M_(m, n)) : (row' i0 A)^T = col' i0 A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_col m n j0 (A : 'M_(m, n)) : (col j0 A)^T = row j0 A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_col' m n j0 (A : 'M_(m, n)) : (col' j0 A)^T = row' j0 A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxsub_comp m1 m2 m3 n1 n2 n3
(f : 'I_m2 -> 'I_m1) (f' : 'I_m3 -> 'I_m2)
(g : 'I_n2 -> 'I_n1) (g' : 'I_n3 -> 'I_n2) (A : 'M_(m1, n1)) :
mxsub (f \o f') (g \o g') A = mxsub f' g' (mxsub f g A).
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma rowsub_comp m1 m2 m3 n
(f : 'I_m2 -> 'I_m1) (f' : 'I_m3 -> 'I_m2) (A : 'M_(m1, n)) :
rowsub (f \o f') A = rowsub f' (rowsub f A).
Proof. exact: mxsub_comp. Qed.
Lemma colsub_comp m n n2 n3
(g : 'I_n2 -> 'I_n) (g' : 'I_n3 -> 'I_n2) (A : 'M_(m, n)) :
colsub (g \o g') A = colsub g' (colsub g A).
Proof. exact: mxsub_comp. Qed.
Lemma mxsubrc m1 m2 n n2 f g (A : 'M_(m1, n)) :
mxsub f g A = rowsub f (colsub g A) :> 'M_(m2, n2).
Proof. exact: mxsub_comp. Qed.
Lemma mxsubcr m1 m2 n n2 f g (A : 'M_(m1, n)) :
mxsub f g A = colsub g (rowsub f A) :> 'M_(m2, n2).
Proof. exact: mxsub_comp. Qed.
Lemma rowsub_cast m1 m2 n (eq_m : m1 = m2) (A : 'M_(m2, n)) :
rowsub (cast_ord eq_m) A = castmx (esym eq_m, erefl) A.
Proof. by case: _ / eq_m in A *; apply: (mxsub_eq_id (cast_ord_id _)). Qed.
Lemma colsub_cast m n1 n2 (eq_n : n1 = n2) (A : 'M_(m, n2)) :
colsub (cast_ord eq_n) A = castmx (erefl, esym eq_n) A.
Proof. by case: _ / eq_n in A *; apply: (mxsub_eq_id _ (cast_ord_id _)). Qed.
Lemma mxsub_cast m1 m2 n1 n2 (eq_m : m1 = m2) (eq_n : n1 = n2) A :
mxsub (cast_ord eq_m) (cast_ord eq_n) A = castmx (esym eq_m, esym eq_n) A.
Proof. by rewrite mxsubrc rowsub_cast colsub_cast castmx_comp/= etrans_id. Qed.
Lemma castmxEsub m1 m2 n1 n2 (eq_mn : (m1 = m2) * (n1 = n2)) A :
castmx eq_mn A = mxsub (cast_ord (esym eq_mn.1)) (cast_ord (esym eq_mn.2)) A.
Proof. by rewrite mxsub_cast !esymK; case: eq_mn. Qed.
Lemma trmx_mxsub m1 m2 n1 n2 f g (A : 'M_(m1, n1)) :
(mxsub f g A)^T = mxsub g f A^T :> 'M_(n2, m2).
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma row_mxsub m1 m2 n1 n2
(f : 'I_m2 -> 'I_m1) (g : 'I_n2 -> 'I_n1) (A : 'M_(m1, n1)) i :
row i (mxsub f g A) = row (f i) (colsub g A).
Proof. by rewrite !rowEsub -!mxsub_comp. Qed.
Lemma col_mxsub m1 m2 n1 n2
(f : 'I_m2 -> 'I_m1) (g : 'I_n2 -> 'I_n1) (A : 'M_(m1, n1)) i :
col i (mxsub f g A) = col (g i) (rowsub f A).
Proof. by rewrite !colEsub -!mxsub_comp. Qed.
Lemma row_rowsub m1 m2 n (f : 'I_m2 -> 'I_m1) (A : 'M_(m1, n)) i :
row i (rowsub f A) = row (f i) A.
Proof. by rewrite row_mxsub mxsub_id. Qed.
Lemma col_colsub m n1 n2 (g : 'I_n2 -> 'I_n1) (A : 'M_(m, n1)) i :
col i (colsub g A) = col (g i) A.
Proof. by rewrite col_mxsub mxsub_id. Qed.
Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?].
Section CutPaste.
Variables m m1 m2 n n1 n2 : nat.
(* Concatenating two matrices, in either direction. *)
Fact row_mx_key : unit. Proof. by []. Qed.
Definition row_mx (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) : 'M[R]_(m, n1 + n2) :=
\matrix[row_mx_key]_(i, j)
match split j with inl j1 => A1 i j1 | inr j2 => A2 i j2 end.
Fact col_mx_key : unit. Proof. by []. Qed.
Definition col_mx (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) : 'M[R]_(m1 + m2, n) :=
\matrix[col_mx_key]_(i, j)
match split i with inl i1 => A1 i1 j | inr i2 => A2 i2 j end.
(* Left/Right | Up/Down submatrices of a rows | columns matrix. *)
(* The shape of the (dependent) width parameters of the type of A *)
(* determines which submatrix is selected. *)
Fact lsubmx_key : unit. Proof. by []. Qed.
Definition lsubmx (A : 'M[R]_(m, n1 + n2)) :=
\matrix[lsubmx_key]_(i, j) A i (lshift n2 j).
Fact rsubmx_key : unit. Proof. by []. Qed.
Definition rsubmx (A : 'M[R]_(m, n1 + n2)) :=
\matrix[rsubmx_key]_(i, j) A i (rshift n1 j).
Fact usubmx_key : unit. Proof. by []. Qed.
Definition usubmx (A : 'M[R]_(m1 + m2, n)) :=
\matrix[usubmx_key]_(i, j) A (lshift m2 i) j.
Fact dsubmx_key : unit. Proof. by []. Qed.
Definition dsubmx (A : 'M[R]_(m1 + m2, n)) :=
\matrix[dsubmx_key]_(i, j) A (rshift m1 i) j.
Lemma row_mxEl A1 A2 i j : row_mx A1 A2 i (lshift n2 j) = A1 i j.
Proof. by rewrite mxE (unsplitK (inl _ _)). Qed.
Lemma row_mxKl A1 A2 : lsubmx (row_mx A1 A2) = A1.
Proof. by apply/matrixP=> i j; rewrite mxE row_mxEl. Qed.
Lemma row_mxEr A1 A2 i j : row_mx A1 A2 i (rshift n1 j) = A2 i j.
Proof. by rewrite mxE (unsplitK (inr _ _)). Qed.
Lemma row_mxKr A1 A2 : rsubmx (row_mx A1 A2) = A2.
Proof. by apply/matrixP=> i j; rewrite mxE row_mxEr. Qed.
Lemma hsubmxK A : row_mx (lsubmx A) (rsubmx A) = A.
Proof. by apply/matrixP=> i j /[!mxE]; case: split_ordP => k -> /[!mxE]. Qed.
Lemma col_mxEu A1 A2 i j : col_mx A1 A2 (lshift m2 i) j = A1 i j.
Proof. by rewrite mxE (unsplitK (inl _ _)). Qed.
Lemma col_mxKu A1 A2 : usubmx (col_mx A1 A2) = A1.
Proof. by apply/matrixP=> i j; rewrite mxE col_mxEu. Qed.
Lemma col_mxEd A1 A2 i j : col_mx A1 A2 (rshift m1 i) j = A2 i j.
Proof. by rewrite mxE (unsplitK (inr _ _)). Qed.
Lemma col_mxKd A1 A2 : dsubmx (col_mx A1 A2) = A2.
Proof. by apply/matrixP=> i j; rewrite mxE col_mxEd. Qed.
Lemma lsubmxEsub : lsubmx = colsub (lshift _).
Proof. by rewrite /lsubmx /mxsub !unlock. Qed.
Lemma rsubmxEsub : rsubmx = colsub (@rshift _ _).
Proof. by rewrite /rsubmx /mxsub !unlock. Qed.
Lemma usubmxEsub : usubmx = rowsub (lshift _).
Proof. by rewrite /usubmx /mxsub !unlock. Qed.
Lemma dsubmxEsub : dsubmx = rowsub (@rshift _ _).
Proof. by rewrite /dsubmx /mxsub !unlock. Qed.
Lemma eq_row_mx A1 A2 B1 B2 : row_mx A1 A2 = row_mx B1 B2 -> A1 = B1 /\ A2 = B2.
Proof.
move=> eqAB; move: (congr1 lsubmx eqAB) (congr1 rsubmx eqAB).
by rewrite !(row_mxKl, row_mxKr).
Qed.
Lemma eq_col_mx A1 A2 B1 B2 : col_mx A1 A2 = col_mx B1 B2 -> A1 = B1 /\ A2 = B2.
Proof.
move=> eqAB; move: (congr1 usubmx eqAB) (congr1 dsubmx eqAB).
by rewrite !(col_mxKu, col_mxKd).
Qed.
Lemma lsubmx_const (r : R) : lsubmx (const_mx r : 'M_(m, n1 + n2)) = const_mx r.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma rsubmx_const (r : R) : rsubmx (const_mx r : 'M_(m, n1 + n2)) = const_mx r.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma row_mx_const a : row_mx (const_mx a) (const_mx a) = const_mx a.
Proof. by split_mxE. Qed.
Lemma col_mx_const a : col_mx (const_mx a) (const_mx a) = const_mx a.
Proof. by split_mxE. Qed.
Lemma row_usubmx A i : row i (usubmx A) = row (lshift m2 i) A.
Proof. by apply/rowP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed.
Lemma row_dsubmx A i : row i (dsubmx A) = row (rshift m1 i) A.
Proof. by apply/rowP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed.
Lemma col_lsubmx A i : col i (lsubmx A) = col (lshift n2 i) A.
Proof. by apply/colP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed.
Lemma col_rsubmx A i : col i (rsubmx A) = col (rshift n1 i) A.
Proof. by apply/colP=> j; rewrite !mxE; congr (A _ _); apply/val_inj. Qed.
End CutPaste.
Lemma row_thin_mx m n (A : 'M_(m,0)) (B : 'M_(m,n)) : row_mx A B = B.
Proof.
apply/matrixP=> i j; rewrite mxE; case: splitP=> [|k H]; first by case.
by congr fun_of_matrix; exact: val_inj.
Qed.
Lemma col_flat_mx m n (A : 'M_(0,n)) (B : 'M_(m,n)) : col_mx A B = B.
Proof.
apply/matrixP=> i j; rewrite mxE; case: splitP => [|k H]; first by case.
by congr fun_of_matrix; exact: val_inj.
Qed.
Lemma trmx_lsub m n1 n2 (A : 'M_(m, n1 + n2)) : (lsubmx A)^T = usubmx A^T.
Proof. by split_mxE. Qed.
Lemma trmx_rsub m n1 n2 (A : 'M_(m, n1 + n2)) : (rsubmx A)^T = dsubmx A^T.
Proof. by split_mxE. Qed.
Lemma tr_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
(row_mx A1 A2)^T = col_mx A1^T A2^T.
Proof. by split_mxE. Qed.
Lemma tr_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
(col_mx A1 A2)^T = row_mx A1^T A2^T.
Proof. by split_mxE. Qed.
Lemma trmx_usub m1 m2 n (A : 'M_(m1 + m2, n)) : (usubmx A)^T = lsubmx A^T.
Proof. by split_mxE. Qed.
Lemma trmx_dsub m1 m2 n (A : 'M_(m1 + m2, n)) : (dsubmx A)^T = rsubmx A^T.
Proof. by split_mxE. Qed.
Lemma vsubmxK m1 m2 n (A : 'M_(m1 + m2, n)) : col_mx (usubmx A) (dsubmx A) = A.
Proof. by apply: trmx_inj; rewrite tr_col_mx trmx_usub trmx_dsub hsubmxK. Qed.
Lemma cast_row_mx m m' n1 n2 (eq_m : m = m') A1 A2 :
castmx (eq_m, erefl _) (row_mx A1 A2)
= row_mx (castmx (eq_m, erefl n1) A1) (castmx (eq_m, erefl n2) A2).
Proof. by case: m' / eq_m. Qed.
Lemma cast_col_mx m1 m2 n n' (eq_n : n = n') A1 A2 :
castmx (erefl _, eq_n) (col_mx A1 A2)
= col_mx (castmx (erefl m1, eq_n) A1) (castmx (erefl m2, eq_n) A2).
Proof. by case: n' / eq_n. Qed.
(* This lemma has Prenex Implicits to help RL rewriting with castmx_sym. *)
Lemma row_mxA m n1 n2 n3 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) (A3 : 'M_(m, n3)) :
let cast := (erefl m, esym (addnA n1 n2 n3)) in
row_mx A1 (row_mx A2 A3) = castmx cast (row_mx (row_mx A1 A2) A3).
Proof.
apply: (canRL (castmxKV _ _)); apply/matrixP=> i j.
rewrite castmxE !mxE cast_ord_id; case: splitP => j1 /= def_j.
have: (j < n1 + n2) && (j < n1) by rewrite def_j lshift_subproof /=.
by move: def_j; do 2![case: splitP => // ? ->; rewrite ?mxE] => /ord_inj->.
case: splitP def_j => j2 ->{j} def_j /[!mxE].
have: ~~ (j2 < n1) by rewrite -leqNgt def_j leq_addr.
have: j1 < n2 by rewrite -(ltn_add2l n1) -def_j.
by move: def_j; do 2![case: splitP => // ? ->] => /addnI/val_inj->.
have: ~~ (j1 < n2) by rewrite -leqNgt -(leq_add2l n1) -def_j leq_addr.
by case: splitP def_j => // ? ->; rewrite addnA => /addnI/val_inj->.
Qed.
Definition row_mxAx := row_mxA. (* bypass Prenex Implicits. *)
(* This lemma has Prenex Implicits to help RL rewrititng with castmx_sym. *)
Lemma col_mxA m1 m2 m3 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) (A3 : 'M_(m3, n)) :
let cast := (esym (addnA m1 m2 m3), erefl n) in
col_mx A1 (col_mx A2 A3) = castmx cast (col_mx (col_mx A1 A2) A3).
Proof. by apply: trmx_inj; rewrite trmx_cast !tr_col_mx -row_mxA. Qed.
Definition col_mxAx := col_mxA. (* bypass Prenex Implicits. *)
Lemma row_row_mx m n1 n2 i0 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
row i0 (row_mx A1 A2) = row_mx (row i0 A1) (row i0 A2).
Proof.
by apply/matrixP=> i j /[!mxE]; case: (split j) => j' /[1!mxE].
Qed.
Lemma col_col_mx m1 m2 n j0 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
col j0 (col_mx A1 A2) = col_mx (col j0 A1) (col j0 A2).
Proof. by apply: trmx_inj; rewrite !(tr_col, tr_col_mx, row_row_mx). Qed.
Lemma row'_row_mx m n1 n2 i0 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
row' i0 (row_mx A1 A2) = row_mx (row' i0 A1) (row' i0 A2).
Proof.
by apply/matrixP=> i j /[!mxE]; case: (split j) => j' /[1!mxE].
Qed.
Lemma col'_col_mx m1 m2 n j0 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
col' j0 (col_mx A1 A2) = col_mx (col' j0 A1) (col' j0 A2).
Proof. by apply: trmx_inj; rewrite !(tr_col', tr_col_mx, row'_row_mx). Qed.
Lemma colKl m n1 n2 j1 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
col (lshift n2 j1) (row_mx A1 A2) = col j1 A1.
Proof. by apply/matrixP=> i j; rewrite !(row_mxEl, mxE). Qed.
Lemma colKr m n1 n2 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
col (rshift n1 j2) (row_mx A1 A2) = col j2 A2.
Proof. by apply/matrixP=> i j; rewrite !(row_mxEr, mxE). Qed.
Lemma rowKu m1 m2 n i1 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
row (lshift m2 i1) (col_mx A1 A2) = row i1 A1.
Proof. by apply/matrixP=> i j; rewrite !(col_mxEu, mxE). Qed.
Lemma rowKd m1 m2 n i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
row (rshift m1 i2) (col_mx A1 A2) = row i2 A2.
Proof. by apply/matrixP=> i j; rewrite !(col_mxEd, mxE). Qed.
Lemma col'Kl m n1 n2 j1 (A1 : 'M_(m, n1.+1)) (A2 : 'M_(m, n2)) :
col' (lshift n2 j1) (row_mx A1 A2) = row_mx (col' j1 A1) A2.
Proof.
apply/matrixP=> i /= j; symmetry; rewrite 2!mxE; case: split_ordP => j' ->.
by rewrite mxE -(row_mxEl _ A2); congr (row_mx _ _ _); apply: ord_inj.
rewrite -(row_mxEr A1); congr (row_mx _ _ _); apply: ord_inj => /=.
by rewrite /bump -ltnS -addSn ltn_addr.
Qed.
Lemma row'Ku m1 m2 n i1 (A1 : 'M_(m1.+1, n)) (A2 : 'M_(m2, n)) :
row' (lshift m2 i1) (@col_mx m1.+1 m2 n A1 A2) = col_mx (row' i1 A1) A2.
Proof.
by apply: trmx_inj; rewrite tr_col_mx !(@tr_row' _.+1) (@tr_col_mx _.+1) col'Kl.
Qed.
Lemma mx'_cast m n : 'I_n -> (m + n.-1)%N = (m + n).-1.
Proof. by case=> j /ltn_predK <-; rewrite addnS. Qed.
Lemma col'Kr m n1 n2 j2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
col' (rshift n1 j2) (@row_mx m n1 n2 A1 A2)
= castmx (erefl m, mx'_cast n1 j2) (row_mx A1 (col' j2 A2)).
Proof.
apply/matrixP=> i j; symmetry; rewrite castmxE mxE cast_ord_id.
case: splitP => j' /= def_j.
rewrite mxE -(row_mxEl _ A2); congr (row_mx _ _ _); apply: ord_inj.
by rewrite /= def_j /bump leqNgt ltn_addr.
rewrite 2!mxE -(row_mxEr A1); congr (row_mx _ _ _ _); apply: ord_inj.
by rewrite /= def_j /bump leq_add2l addnCA.
Qed.
Lemma row'Kd m1 m2 n i2 (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
row' (rshift m1 i2) (col_mx A1 A2)
= castmx (mx'_cast m1 i2, erefl n) (col_mx A1 (row' i2 A2)).
Proof. by apply: trmx_inj; rewrite trmx_cast !(tr_row', tr_col_mx) col'Kr. Qed.
Section Block.
Variables m1 m2 n1 n2 : nat.
(* Building a block matrix from 4 matrices : *)
(* up left, up right, down left and down right components *)
Definition block_mx Aul Aur Adl Adr : 'M_(m1 + m2, n1 + n2) :=
col_mx (row_mx Aul Aur) (row_mx Adl Adr).
Lemma eq_block_mx Aul Aur Adl Adr Bul Bur Bdl Bdr :
block_mx Aul Aur Adl Adr = block_mx Bul Bur Bdl Bdr ->
[/\ Aul = Bul, Aur = Bur, Adl = Bdl & Adr = Bdr].
Proof. by case/eq_col_mx; do 2!case/eq_row_mx=> -> ->. Qed.
Lemma block_mx_const a :
block_mx (const_mx a) (const_mx a) (const_mx a) (const_mx a) = const_mx a.
Proof. by split_mxE. Qed.
Section CutBlock.
Variable A : matrix R (m1 + m2) (n1 + n2).
Definition ulsubmx := lsubmx (usubmx A).
Definition ursubmx := rsubmx (usubmx A).
Definition dlsubmx := lsubmx (dsubmx A).
Definition drsubmx := rsubmx (dsubmx A).
Lemma submxK : block_mx ulsubmx ursubmx dlsubmx drsubmx = A.
Proof. by rewrite /block_mx !hsubmxK vsubmxK. Qed.
Lemma ulsubmxEsub : ulsubmx = mxsub (lshift _) (lshift _) A.
Proof. by rewrite /ulsubmx lsubmxEsub usubmxEsub -mxsub_comp. Qed.
Lemma dlsubmxEsub : dlsubmx = mxsub (@rshift _ _) (lshift _) A.
Proof. by rewrite /dlsubmx lsubmxEsub dsubmxEsub -mxsub_comp. Qed.
Lemma ursubmxEsub : ursubmx = mxsub (lshift _) (@rshift _ _) A.
Proof. by rewrite /ursubmx rsubmxEsub usubmxEsub -mxsub_comp. Qed.
Lemma drsubmxEsub : drsubmx = mxsub (@rshift _ _) (@rshift _ _) A.
Proof. by rewrite /drsubmx rsubmxEsub dsubmxEsub -mxsub_comp. Qed.
End CutBlock.
Section CatBlock.
Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)).
Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)).
Let A := block_mx Aul Aur Adl Adr.
Lemma block_mxEul i j : A (lshift m2 i) (lshift n2 j) = Aul i j.
Proof. by rewrite col_mxEu row_mxEl. Qed.
Lemma block_mxKul : ulsubmx A = Aul.
Proof. by rewrite /ulsubmx col_mxKu row_mxKl. Qed.
Lemma block_mxEur i j : A (lshift m2 i) (rshift n1 j) = Aur i j.
Proof. by rewrite col_mxEu row_mxEr. Qed.
Lemma block_mxKur : ursubmx A = Aur.
Proof. by rewrite /ursubmx col_mxKu row_mxKr. Qed.
Lemma block_mxEdl i j : A (rshift m1 i) (lshift n2 j) = Adl i j.
Proof. by rewrite col_mxEd row_mxEl. Qed.
Lemma block_mxKdl : dlsubmx A = Adl.
Proof. by rewrite /dlsubmx col_mxKd row_mxKl. Qed.
Lemma block_mxEdr i j : A (rshift m1 i) (rshift n1 j) = Adr i j.
Proof. by rewrite col_mxEd row_mxEr. Qed.
Lemma block_mxKdr : drsubmx A = Adr.
Proof. by rewrite /drsubmx col_mxKd row_mxKr. Qed.
Lemma block_mxEv : A = col_mx (row_mx Aul Aur) (row_mx Adl Adr).
Proof. by []. Qed.
End CatBlock.
End Block.
Section TrCutBlock.
Variables m1 m2 n1 n2 : nat.
Variable A : 'M[R]_(m1 + m2, n1 + n2).
Lemma trmx_ulsub : (ulsubmx A)^T = ulsubmx A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma trmx_ursub : (ursubmx A)^T = dlsubmx A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma trmx_dlsub : (dlsubmx A)^T = ursubmx A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma trmx_drsub : (drsubmx A)^T = drsubmx A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
End TrCutBlock.
Section TrBlock.
Variables m1 m2 n1 n2 : nat.
Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)).
Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)).
Lemma tr_block_mx :
(block_mx Aul Aur Adl Adr)^T = block_mx Aul^T Adl^T Aur^T Adr^T.
Proof.
rewrite -[_^T]submxK -trmx_ulsub -trmx_ursub -trmx_dlsub -trmx_drsub.
by rewrite block_mxKul block_mxKur block_mxKdl block_mxKdr.
Qed.
Lemma block_mxEh :
block_mx Aul Aur Adl Adr = row_mx (col_mx Aul Adl) (col_mx Aur Adr).
Proof. by apply: trmx_inj; rewrite tr_block_mx tr_row_mx 2!tr_col_mx. Qed.
End TrBlock.
(* This lemma has Prenex Implicits to help RL rewrititng with castmx_sym. *)
Lemma block_mxA m1 m2 m3 n1 n2 n3
(A11 : 'M_(m1, n1)) (A12 : 'M_(m1, n2)) (A13 : 'M_(m1, n3))
(A21 : 'M_(m2, n1)) (A22 : 'M_(m2, n2)) (A23 : 'M_(m2, n3))
(A31 : 'M_(m3, n1)) (A32 : 'M_(m3, n2)) (A33 : 'M_(m3, n3)) :
let cast := (esym (addnA m1 m2 m3), esym (addnA n1 n2 n3)) in
let row1 := row_mx A12 A13 in let col1 := col_mx A21 A31 in
let row3 := row_mx A31 A32 in let col3 := col_mx A13 A23 in
block_mx A11 row1 col1 (block_mx A22 A23 A32 A33)
= castmx cast (block_mx (block_mx A11 A12 A21 A22) col3 row3 A33).
Proof.
rewrite /= block_mxEh !col_mxA -cast_row_mx -block_mxEv -block_mxEh.
rewrite block_mxEv block_mxEh !row_mxA -cast_col_mx -block_mxEh -block_mxEv.
by rewrite castmx_comp etrans_id.
Qed.
Definition block_mxAx := block_mxA. (* Bypass Prenex Implicits *)
Section Induction.
Lemma row_ind m (P : forall n, 'M[R]_(m, n) -> Type) :
(forall A, P 0 A) ->
(forall n c A, P n A -> P (1 + n)%N (row_mx c A)) ->
forall n A, P n A.
Proof.
move=> P0 PS; elim=> [//|n IHn] A.
by rewrite -[n.+1]/(1 + n)%N in A *; rewrite -[A]hsubmxK; apply: PS.
Qed.
Lemma col_ind n (P : forall m, 'M[R]_(m, n) -> Type) :
(forall A, P 0 A) ->
(forall m r A, P m A -> P (1 + m)%N (col_mx r A)) ->
forall m A, P m A.
Proof.
move=> P0 PS; elim=> [//|m IHm] A.
by rewrite -[m.+1]/(1 + m)%N in A *; rewrite -[A]vsubmxK; apply: PS.
Qed.
Lemma mx_ind (P : forall m n, 'M[R]_(m, n) -> Type) :
(forall m A, P m 0 A) ->
(forall n A, P 0 n A) ->
(forall m n x r c A, P m n A -> P (1 + m)%N (1 + n)%N (block_mx x r c A)) ->
forall m n A, P m n A.
Proof.
move=> P0l P0r PS; elim=> [|m IHm] [|n] A; do ?by [apply: P0l|apply: P0r].
by rewrite -[A](@submxK 1 _ 1); apply: PS.
Qed.
Definition matrix_rect := mx_ind.
Definition matrix_rec := mx_ind.
Definition matrix_ind := mx_ind.
Lemma sqmx_ind (P : forall n, 'M[R]_n -> Type) :
(forall A, P 0 A) ->
(forall n x r c A, P n A -> P (1 + n)%N (block_mx x r c A)) ->
forall n A, P n A.
Proof.
by move=> P0 PS; elim=> [//|n IHn] A; rewrite -[A](@submxK 1 _ 1); apply: PS.
Qed.
Lemma ringmx_ind (P : forall n, 'M[R]_n.+1 -> Type) :
(forall x, P 0 x) ->
(forall n x (r : 'rV_n.+1) (c : 'cV_n.+1) A,
P n A -> P (1 + n)%N (block_mx x r c A)) ->
forall n A, P n A.
Proof.
by move=> P0 PS; elim=> [//|n IHn] A; rewrite -[A](@submxK 1 _ 1); apply: PS.
Qed.
Lemma mxsub_ind
(weight : forall m n, 'M[R]_(m, n) -> nat)
(sub : forall m n m' n', ('I_m' -> 'I_m) -> ('I_n' -> 'I_n) -> Prop)
(P : forall m n, 'M[R]_(m, n) -> Type) :
(forall m n (A : 'M[R]_(m, n)),
(forall m' n' f g, weight m' n' (mxsub f g A) < weight m n A ->
sub m n m' n' f g ->
P m' n' (mxsub f g A)) -> P m n A) ->
forall m n A, P m n A.
Proof.
move=> Psub m n A; have [k] := ubnP (weight m n A).
elim: k => [//|k IHk] in m n A *.
rewrite ltnS => lt_A_k; apply: Psub => m' n' f g lt_A'_A ?.
by apply: IHk; apply: leq_trans lt_A_k.
Qed.
End Induction.
(* Bijections mxvec : 'M_(m, n) <----> 'rV_(m * n) : vec_mx *)
Section VecMatrix.
Variables m n : nat.
Lemma mxvec_cast : #|{:'I_m * 'I_n}| = (m * n)%N.
Proof. by rewrite card_prod !card_ord. Qed.
Definition mxvec_index (i : 'I_m) (j : 'I_n) :=
cast_ord mxvec_cast (enum_rank (i, j)).
Variant is_mxvec_index : 'I_(m * n) -> Type :=
isMxvecIndex i j : is_mxvec_index (mxvec_index i j).
Lemma mxvec_indexP k : is_mxvec_index k.
Proof.
rewrite -[k](cast_ordK (esym mxvec_cast)) esymK.
by rewrite -[_ k]enum_valK; case: (enum_val _).
Qed.
Coercion pair_of_mxvec_index k (i_k : is_mxvec_index k) :=
let: isMxvecIndex i j := i_k in (i, j).
Definition mxvec (A : 'M[R]_(m, n)) :=
castmx (erefl _, mxvec_cast) (\row_k A (enum_val k).1 (enum_val k).2).
Fact vec_mx_key : unit. Proof. by []. Qed.
Definition vec_mx (u : 'rV[R]_(m * n)) :=
\matrix[vec_mx_key]_(i, j) u 0 (mxvec_index i j).
Lemma mxvecE A i j : mxvec A 0 (mxvec_index i j) = A i j.
Proof. by rewrite castmxE mxE cast_ordK enum_rankK. Qed.
Lemma mxvecK : cancel mxvec vec_mx.
Proof. by move=> A; apply/matrixP=> i j; rewrite mxE mxvecE. Qed.
Lemma vec_mxK : cancel vec_mx mxvec.
Proof.
by move=> u; apply/rowP=> k; case/mxvec_indexP: k => i j; rewrite mxvecE mxE.
Qed.
Lemma curry_mxvec_bij : {on 'I_(m * n), bijective (uncurry mxvec_index)}.
Proof.
exists (enum_val \o cast_ord (esym mxvec_cast)) => [[i j] _ | k _] /=.
by rewrite cast_ordK enum_rankK.
by case/mxvec_indexP: k => i j /=; rewrite cast_ordK enum_rankK.
Qed.
End VecMatrix.
End MatrixStructural.
Arguments const_mx {R m n}.
Arguments row_mxA {R m n1 n2 n3 A1 A2 A3}.
Arguments col_mxA {R m1 m2 m3 n A1 A2 A3}.
Arguments block_mxA {R m1 m2 m3 n1 n2 n3 A11 A12 A13 A21 A22 A23 A31 A32 A33}.
Prenex Implicits castmx trmx trmxK lsubmx rsubmx usubmx dsubmx row_mx col_mx.
Prenex Implicits block_mx ulsubmx ursubmx dlsubmx drsubmx.
Prenex Implicits mxvec vec_mx mxvec_indexP mxvecK vec_mxK.
Arguments trmx_inj {R m n} [A1 A2] eqA12t : rename.
Notation "A ^T" := (trmx A) : ring_scope.
Notation colsub g := (mxsub id g).
Notation rowsub f := (mxsub f id).
Arguments eq_mxsub [R m n m' n' f] f' [g] g' _.
Arguments eq_rowsub [R m n m' f] f' _.
Arguments eq_colsub [R m n n' g] g' _.
(* Matrix parametricity. *)
Section MapMatrix.
Variables (aT rT : Type) (f : aT -> rT).
Fact map_mx_key : unit. Proof. by []. Qed.
Definition map_mx m n (A : 'M_(m, n)) := \matrix[map_mx_key]_(i, j) f (A i j).
Notation "A ^f" := (map_mx A) : ring_scope.
Section OneMatrix.
Variables (m n : nat) (A : 'M[aT]_(m, n)).
Lemma map_trmx : A^f^T = A^T^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_const_mx a : (const_mx a)^f = const_mx (f a) :> 'M_(m, n).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_row i : (row i A)^f = row i A^f.
Proof. by apply/rowP=> j; rewrite !mxE. Qed.
Lemma map_col j : (col j A)^f = col j A^f.
Proof. by apply/colP=> i; rewrite !mxE. Qed.
Lemma map_row' i0 : (row' i0 A)^f = row' i0 A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_col' j0 : (col' j0 A)^f = col' j0 A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_mxsub m' n' g h : (@mxsub _ _ _ m' n' g h A)^f = mxsub g h A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_row_perm s : (row_perm s A)^f = row_perm s A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_col_perm s : (col_perm s A)^f = col_perm s A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_xrow i1 i2 : (xrow i1 i2 A)^f = xrow i1 i2 A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_xcol j1 j2 : (xcol j1 j2 A)^f = xcol j1 j2 A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_castmx m' n' c : (castmx c A)^f = castmx c A^f :> 'M_(m', n').
Proof. by apply/matrixP=> i j; rewrite !(castmxE, mxE). Qed.
Lemma map_conform_mx m' n' (B : 'M_(m', n')) :
(conform_mx B A)^f = conform_mx B^f A^f.
Proof.
move: B; have [[<- <-] B|] := eqVneq (m, n) (m', n').
by rewrite !conform_mx_id.
by rewrite negb_and => neq_mn B; rewrite !nonconform_mx.
Qed.
Lemma map_mxvec : (mxvec A)^f = mxvec A^f.
Proof. by apply/rowP=> i; rewrite !(castmxE, mxE). Qed.
Lemma map_vec_mx (v : 'rV_(m * n)) : (vec_mx v)^f = vec_mx v^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
End OneMatrix.
Section Block.
Variables m1 m2 n1 n2 : nat.
Variables (Aul : 'M[aT]_(m1, n1)) (Aur : 'M[aT]_(m1, n2)).
Variables (Adl : 'M[aT]_(m2, n1)) (Adr : 'M[aT]_(m2, n2)).
Variables (Bh : 'M[aT]_(m1, n1 + n2)) (Bv : 'M[aT]_(m1 + m2, n1)).
Variable B : 'M[aT]_(m1 + m2, n1 + n2).
Lemma map_row_mx : (row_mx Aul Aur)^f = row_mx Aul^f Aur^f.
Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed.
Lemma map_col_mx : (col_mx Aul Adl)^f = col_mx Aul^f Adl^f.
Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed.
Lemma map_block_mx :
(block_mx Aul Aur Adl Adr)^f = block_mx Aul^f Aur^f Adl^f Adr^f.
Proof. by apply/matrixP=> i j; do 3![rewrite !mxE //; case: split => ?]. Qed.
Lemma map_lsubmx : (lsubmx Bh)^f = lsubmx Bh^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_rsubmx : (rsubmx Bh)^f = rsubmx Bh^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_usubmx : (usubmx Bv)^f = usubmx Bv^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_dsubmx : (dsubmx Bv)^f = dsubmx Bv^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_ulsubmx : (ulsubmx B)^f = ulsubmx B^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_ursubmx : (ursubmx B)^f = ursubmx B^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_dlsubmx : (dlsubmx B)^f = dlsubmx B^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map_drsubmx : (drsubmx B)^f = drsubmx B^f.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
End Block.
End MapMatrix.
Arguments map_mx {aT rT} f {m n} A.
Section MultipleMapMatrix.
Context {R S T : Type} {m n : nat}.
Local Notation "M ^ phi" := (map_mx phi M).
Lemma map_mx_comp (f : R -> S) (g : S -> T)
(M : 'M_(m, n)) : M ^ (g \o f) = (M ^ f) ^ g.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma eq_in_map_mx (g f : R -> S) (M : 'M_(m, n)) :
(forall i j, f (M i j) = g (M i j)) -> M ^ f = M ^ g.
Proof. by move=> fg; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma eq_map_mx (g f : R -> S) : f =1 g ->
forall (M : 'M_(m, n)), M ^ f = M ^ g.
Proof. by move=> eq_fg M; apply/eq_in_map_mx. Qed.
Lemma map_mx_id_in (f : R -> R) (M : 'M_(m, n)) :
(forall i j, f (M i j) = M i j) -> M ^ f = M.
Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma map_mx_id (f : R -> R) : f =1 id -> forall M : 'M_(m, n), M ^ f = M.
Proof. by move=> fid M; rewrite map_mx_id_in. Qed.
End MultipleMapMatrix.
Arguments eq_map_mx {R S m n} g [f].
Arguments eq_in_map_mx {R S m n} g [f M].
Arguments map_mx_id_in {R m n} [f M].
Arguments map_mx_id {R m n} [f].
(*****************************************************************************)
(********************* Matrix lifted laws *******************)
(*****************************************************************************)
Section Map2Matrix.
Context {R S T : Type} (f : R -> S -> T).
Fact map2_mx_key : unit. Proof. by []. Qed.
Definition map2_mx m n (A : 'M_(m, n)) (B : 'M_(m, n)) :=
\matrix[map2_mx_key]_(i, j) f (A i j) (B i j).
Section OneMatrix.
Variables (m n : nat) (A : 'M[R]_(m, n)) (B : 'M[S]_(m, n)).
Lemma map2_trmx : (map2_mx A B)^T = map2_mx A^T B^T.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_const_mx a b :
map2_mx (const_mx a) (const_mx b) = const_mx (f a b) :> 'M_(m, n).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_row i : map2_mx (row i A) (row i B) = row i (map2_mx A B).
Proof. by apply/rowP=> j; rewrite !mxE. Qed.
Lemma map2_col j : map2_mx (col j A) (col j B) = col j (map2_mx A B).
Proof. by apply/colP=> i; rewrite !mxE. Qed.
Lemma map2_row' i0 : map2_mx (row' i0 A) (row' i0 B) = row' i0 (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_col' j0 : map2_mx (col' j0 A) (col' j0 B) = col' j0 (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_mxsub m' n' g h :
map2_mx (@mxsub _ _ _ m' n' g h A) (@mxsub _ _ _ m' n' g h B) =
mxsub g h (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_row_perm s :
map2_mx (row_perm s A) (row_perm s B) = row_perm s (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_col_perm s :
map2_mx (col_perm s A) (col_perm s B) = col_perm s (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_xrow i1 i2 :
map2_mx (xrow i1 i2 A) (xrow i1 i2 B) = xrow i1 i2 (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_xcol j1 j2 :
map2_mx (xcol j1 j2 A) (xcol j1 j2 B) = xcol j1 j2 (map2_mx A B).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_castmx m' n' c :
map2_mx (castmx c A) (castmx c B) = castmx c (map2_mx A B) :> 'M_(m', n').
Proof. by apply/matrixP=> i j; rewrite !(castmxE, mxE). Qed.
Lemma map2_conform_mx m' n' (A' : 'M_(m', n')) (B' : 'M_(m', n')) :
map2_mx (conform_mx A' A) (conform_mx B' B) =
conform_mx (map2_mx A' B') (map2_mx A B).
Proof.
move: A' B'; have [[<- <-] A' B'|] := eqVneq (m, n) (m', n').
by rewrite !conform_mx_id.
by rewrite negb_and => neq_mn A' B'; rewrite !nonconform_mx.
Qed.
Lemma map2_mxvec : map2_mx (mxvec A) (mxvec B) = mxvec (map2_mx A B).
Proof. by apply/rowP=> i; rewrite !(castmxE, mxE). Qed.
Lemma map2_vec_mx (v : 'rV_(m * n)) (w : 'rV_(m * n)) :
map2_mx (vec_mx v) (vec_mx w) = vec_mx (map2_mx v w).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
End OneMatrix.
Section Block.
Variables m1 m2 n1 n2 : nat.
Variables (Aul : 'M[R]_(m1, n1)) (Aur : 'M[R]_(m1, n2)).
Variables (Adl : 'M[R]_(m2, n1)) (Adr : 'M[R]_(m2, n2)).
Variables (Bh : 'M[R]_(m1, n1 + n2)) (Bv : 'M[R]_(m1 + m2, n1)).
Variable B : 'M[R]_(m1 + m2, n1 + n2).
Variables (A'ul : 'M[S]_(m1, n1)) (A'ur : 'M[S]_(m1, n2)).
Variables (A'dl : 'M[S]_(m2, n1)) (A'dr : 'M[S]_(m2, n2)).
Variables (B'h : 'M[S]_(m1, n1 + n2)) (B'v : 'M[S]_(m1 + m2, n1)).
Variable B' : 'M[S]_(m1 + m2, n1 + n2).
Lemma map2_row_mx :
map2_mx (row_mx Aul Aur) (row_mx A'ul A'ur) =
row_mx (map2_mx Aul A'ul) (map2_mx Aur A'ur).
Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed.
Lemma map2_col_mx :
map2_mx (col_mx Aul Adl) (col_mx A'ul A'dl) =
col_mx (map2_mx Aul A'ul) (map2_mx Adl A'dl).
Proof. by apply/matrixP=> i j; do 2![rewrite !mxE //; case: split => ?]. Qed.
Lemma map2_block_mx :
map2_mx (block_mx Aul Aur Adl Adr) (block_mx A'ul A'ur A'dl A'dr) =
block_mx
(map2_mx Aul A'ul) (map2_mx Aur A'ur) (map2_mx Adl A'dl) (map2_mx Adr A'dr).
Proof. by apply/matrixP=> i j; do 3![rewrite !mxE //; case: split => ?]. Qed.
Lemma map2_lsubmx : map2_mx (lsubmx Bh) (lsubmx B'h) = lsubmx (map2_mx Bh B'h).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_rsubmx : map2_mx (rsubmx Bh) (rsubmx B'h) = rsubmx (map2_mx Bh B'h).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_usubmx : map2_mx (usubmx Bv) (usubmx B'v) = usubmx (map2_mx Bv B'v).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_dsubmx : map2_mx (dsubmx Bv) (dsubmx B'v) = dsubmx (map2_mx Bv B'v).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_ulsubmx : map2_mx (ulsubmx B) (ulsubmx B') = ulsubmx (map2_mx B B').
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_ursubmx : map2_mx (ursubmx B) (ursubmx B') = ursubmx (map2_mx B B').
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_dlsubmx : map2_mx (dlsubmx B) (dlsubmx B') = dlsubmx (map2_mx B B').
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma map2_drsubmx : map2_mx (drsubmx B) (drsubmx B') = drsubmx (map2_mx B B').
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
End Block.
End Map2Matrix.
Section Map2Eq.
Context {R S T : Type} {m n : nat}.
Lemma eq_in_map2_mx (f g : R -> S -> T) (M : 'M[R]_(m, n)) (M' : 'M[S]_(m, n)) :
(forall i j, f (M i j) (M' i j) = g (M i j) (M' i j)) ->
map2_mx f M M' = map2_mx g M M'.
Proof. by move=> fg; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma eq_map2_mx (f g : R -> S -> T) : f =2 g ->
@map2_mx _ _ _ f m n =2 @map2_mx _ _ _ g m n.
Proof. by move=> eq_fg M M'; apply/eq_in_map2_mx. Qed.
Lemma map2_mx_left_in (f : R -> R -> R) (M : 'M_(m, n)) (M' : 'M_(m, n)) :
(forall i j, f (M i j) (M' i j) = M i j) -> map2_mx f M M' = M.
Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma map2_mx_left (f : R -> R -> R) : f =2 (fun x _ => x) ->
forall (M : 'M_(m, n)) (M' : 'M_(m, n)), map2_mx f M M' = M.
Proof. by move=> fl M M'; rewrite map2_mx_left_in// =>i j; rewrite fl. Qed.
Lemma map2_mx_right_in (f : R -> R -> R) (M : 'M_(m, n)) (M' : 'M_(m, n)) :
(forall i j, f (M i j) (M' i j) = M' i j) -> map2_mx f M M' = M'.
Proof. by move=> fM; apply/matrixP => i j; rewrite !mxE. Qed.
Lemma map2_mx_right (f : R -> R -> R) : f =2 (fun _ x => x) ->
forall (M : 'M_(m, n)) (M' : 'M_(m, n)), map2_mx f M M' = M'.
Proof. by move=> fr M M'; rewrite map2_mx_right_in// =>i j; rewrite fr. Qed.
End Map2Eq.
Section MatrixLaws.
Context {T : Type} {m n : nat} {idm : T}.
Lemma map2_mxA {opm : Monoid.law idm} : associative (@map2_mx _ _ _ opm m n).
Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmA. Qed.
Lemma map2_1mx {opm : Monoid.law idm} :
left_id (const_mx idm) (@map2_mx _ _ _ opm m n).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mul1m. Qed.
Lemma map2_mx1 {opm : Monoid.law idm} :
right_id (const_mx idm) (@map2_mx _ _ _ opm m n).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mulm1. Qed.
HB.instance Definition _ {opm : Monoid.law idm} :=
Monoid.isLaw.Build 'M_(m, n) (const_mx idm) (@map2_mx _ _ _ opm _ _)
map2_mxA map2_1mx map2_mx1.
Lemma map2_mxC {opm : Monoid.com_law idm} :
commutative (@map2_mx _ _ _ opm m n).
Proof. by move=> A B; apply/matrixP=> i j; rewrite !mxE Monoid.mulmC. Qed.
HB.instance Definition _ {opm : Monoid.com_law idm} :=
SemiGroup.isCommutativeLaw.Build 'M_(m, n) (@map2_mx _ _ _ opm _ _) map2_mxC.
Lemma map2_0mx {opm : Monoid.mul_law idm} :
left_zero (const_mx idm) (@map2_mx _ _ _ opm m n).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mul0m. Qed.
Lemma map2_mx0 {opm : Monoid.mul_law idm} :
right_zero (const_mx idm) (@map2_mx _ _ _ opm m n).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE Monoid.mulm0. Qed.
HB.instance Definition _ {opm : Monoid.mul_law idm} :=
Monoid.isMulLaw.Build 'M_(m, n) (const_mx idm) (@map2_mx _ _ _ opm _ _)
map2_0mx map2_mx0.
Lemma map2_mxDl {mul : T -> T -> T} {add : Monoid.add_law idm mul} :
left_distributive (@map2_mx _ _ _ mul m n) (@map2_mx _ _ _ add m n).
Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmDl. Qed.
Lemma map2_mxDr {mul : T -> T -> T} {add : Monoid.add_law idm mul} :
right_distributive (@map2_mx _ _ _ mul m n) (@map2_mx _ _ _ add m n).
Proof. by move=> A B C; apply/matrixP=> i j; rewrite !mxE Monoid.mulmDr. Qed.
HB.instance Definition _ {mul : T -> T -> T} {add : Monoid.add_law idm mul} :=
Monoid.isAddLaw.Build 'M_(m, n)
(@map2_mx _ _ _ mul _ _) (@map2_mx _ _ _ add _ _)
map2_mxDl map2_mxDr.
End MatrixLaws.
(*****************************************************************************)
(************* Matrix Nmodule (additive abelian monoid) structure ************)
(*****************************************************************************)
Section MatrixNmodule.
Variable V : nmodType.
Section FixedDim.
Variables m n : nat.
Implicit Types A B : 'M[V]_(m, n).
Fact addmx_key : unit. Proof. by []. Qed.
Definition addmx := @map2_mx V V V +%R m n.
Definition addmxA : associative addmx := map2_mxA.
Definition addmxC : commutative addmx := map2_mxC.
Definition add0mx : left_id (const_mx 0) addmx := map2_1mx.
HB.instance Definition _ := GRing.isNmodule.Build 'M[V]_(m, n)
addmxA addmxC add0mx.
Lemma mulmxnE A d i j : (A *+ d) i j = A i j *+ d.
Proof. by elim: d => [|d IHd]; rewrite ?mulrS mxE ?IHd. Qed.
Lemma summxE I r (P : pred I) (E : I -> 'M_(m, n)) i j :
(\sum_(k <- r | P k) E k) i j = \sum_(k <- r | P k) E k i j.
Proof. by apply: (big_morph (fun A => A i j)) => [A B|]; rewrite mxE. Qed.
Fact const_mx_is_nmod_morphism : nmod_morphism const_mx.
Proof. by split=> [|a b]; apply/matrixP => // i j; rewrite !mxE. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `const_mx_is_nmod_morphism` instead")]
Definition const_mx_is_semi_additive := const_mx_is_nmod_morphism.
HB.instance Definition _ := GRing.isNmodMorphism.Build V 'M[V]_(m, n) const_mx
const_mx_is_nmod_morphism.
End FixedDim.
Section SemiAdditive.
Variables (m n p q : nat) (f : 'I_p -> 'I_q -> 'I_m) (g : 'I_p -> 'I_q -> 'I_n).
Definition swizzle_mx k (A : 'M[V]_(m, n)) :=
\matrix[k]_(i, j) A (f i j) (g i j).
Fact swizzle_mx_is_nmod_morphism k : nmod_morphism (swizzle_mx k).
Proof. by split=> [|A B]; apply/matrixP => i j; rewrite !mxE. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `swizzle_mx_is_nmod_morphism` instead")]
Definition swizzle_mx_is_semi_additive := swizzle_mx_is_nmod_morphism.
HB.instance Definition _ k := GRing.isNmodMorphism.Build 'M_(m, n) 'M_(p, q)
(swizzle_mx k) (swizzle_mx_is_nmod_morphism k).
End SemiAdditive.
Local Notation SwizzleAdd op := (GRing.Additive.copy op (swizzle_mx _ _ _)).
HB.instance Definition _ m n := SwizzleAdd (@trmx V m n).
HB.instance Definition _ m n i := SwizzleAdd (@row V m n i).
HB.instance Definition _ m n j := SwizzleAdd (@col V m n j).
HB.instance Definition _ m n i := SwizzleAdd (@row' V m n i).
HB.instance Definition _ m n j := SwizzleAdd (@col' V m n j).
HB.instance Definition _ m n m' n' f g := SwizzleAdd (@mxsub V m n m' n' f g).
HB.instance Definition _ m n s := SwizzleAdd (@row_perm V m n s).
HB.instance Definition _ m n s := SwizzleAdd (@col_perm V m n s).
HB.instance Definition _ m n i1 i2 := SwizzleAdd (@xrow V m n i1 i2).
HB.instance Definition _ m n j1 j2 := SwizzleAdd (@xcol V m n j1 j2).
HB.instance Definition _ m n1 n2 := SwizzleAdd (@lsubmx V m n1 n2).
HB.instance Definition _ m n1 n2 := SwizzleAdd (@rsubmx V m n1 n2).
HB.instance Definition _ m1 m2 n := SwizzleAdd (@usubmx V m1 m2 n).
HB.instance Definition _ m1 m2 n := SwizzleAdd (@dsubmx V m1 m2 n).
HB.instance Definition _ m n := SwizzleAdd (@vec_mx V m n).
HB.instance Definition _ m n := GRing.isNmodMorphism.Build 'M_(m, n) 'rV_(m * n)
mxvec (can2_nmod_morphism (@vec_mxK V m n) mxvecK).
Lemma flatmx0 n : all_equal_to (0 : 'M_(0, n)).
Proof. by move=> A; apply/matrixP=> [] []. Qed.
Lemma thinmx0 n : all_equal_to (0 : 'M_(n, 0)).
Proof. by move=> A; apply/matrixP=> i []. Qed.
Lemma trmx0 m n : (0 : 'M_(m, n))^T = 0.
Proof. exact: trmx_const. Qed.
Lemma row0 m n i0 : row i0 (0 : 'M_(m, n)) = 0.
Proof. exact: row_const. Qed.
Lemma col0 m n j0 : col j0 (0 : 'M_(m, n)) = 0.
Proof. exact: col_const. Qed.
Lemma mxvec_eq0 m n (A : 'M_(m, n)) : (mxvec A == 0) = (A == 0).
Proof. by rewrite (can2_eq mxvecK vec_mxK) raddf0. Qed.
Lemma vec_mx_eq0 m n (v : 'rV_(m * n)) : (vec_mx v == 0) = (v == 0).
Proof. by rewrite (can2_eq vec_mxK mxvecK) raddf0. Qed.
Lemma row_mx0 m n1 n2 : row_mx 0 0 = 0 :> 'M_(m, n1 + n2).
Proof. exact: row_mx_const. Qed.
Lemma col_mx0 m1 m2 n : col_mx 0 0 = 0 :> 'M_(m1 + m2, n).
Proof. exact: col_mx_const. Qed.
Lemma block_mx0 m1 m2 n1 n2 : block_mx 0 0 0 0 = 0 :> 'M_(m1 + m2, n1 + n2).
Proof. exact: block_mx_const. Qed.
Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?].
Lemma add_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) B1 B2 :
row_mx A1 A2 + row_mx B1 B2 = row_mx (A1 + B1) (A2 + B2).
Proof. by split_mxE. Qed.
Lemma add_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) B1 B2 :
col_mx A1 A2 + col_mx B1 B2 = col_mx (A1 + B1) (A2 + B2).
Proof. by split_mxE. Qed.
Lemma add_block_mx m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2))
Bul Bur Bdl Bdr :
let A := block_mx Aul Aur Adl Adr in let B := block_mx Bul Bur Bdl Bdr in
A + B = block_mx (Aul + Bul) (Aur + Bur) (Adl + Bdl) (Adr + Bdr).
Proof. by rewrite /= add_col_mx !add_row_mx. Qed.
Lemma row_mx_eq0 (m n1 n2 : nat) (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)):
(row_mx A1 A2 == 0) = (A1 == 0) && (A2 == 0).
Proof.
apply/eqP/andP; last by case=> /eqP-> /eqP->; rewrite row_mx0.
by rewrite -row_mx0 => /eq_row_mx [-> ->].
Qed.
Lemma col_mx_eq0 (m1 m2 n : nat) (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)):
(col_mx A1 A2 == 0) = (A1 == 0) && (A2 == 0).
Proof. by rewrite - !trmx0 tr_col_mx row_mx_eq0. Qed.
Lemma block_mx_eq0 m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2)) :
(block_mx Aul Aur Adl Adr == 0) =
[&& Aul == 0, Aur == 0, Adl == 0 & Adr == 0].
Proof. by rewrite col_mx_eq0 !row_mx_eq0 !andbA. Qed.
Lemma trmx_eq0 m n (A : 'M_(m, n)) : (A^T == 0) = (A == 0).
Proof. by rewrite -trmx0 (inj_eq trmx_inj). Qed.
Lemma matrix_eq0 m n (A : 'M_(m, n)) :
(A == 0) = [forall i, forall j, A i j == 0].
Proof.
apply/eqP/'forall_'forall_eqP => [-> i j|A_eq0]; first by rewrite !mxE.
by apply/matrixP => i j; rewrite A_eq0 !mxE.
Qed.
Lemma matrix0Pn m n (A : 'M_(m, n)) : reflect (exists i j, A i j != 0) (A != 0).
Proof.
by rewrite matrix_eq0; apply/(iffP forallPn) => -[i /forallPn]; exists i.
Qed.
Lemma rV0Pn n (v : 'rV_n) : reflect (exists i, v 0 i != 0) (v != 0).
Proof.
apply: (iffP (matrix0Pn _)) => [[i [j]]|[j]]; last by exists 0, j.
by rewrite ord1; exists j.
Qed.
Lemma cV0Pn n (v : 'cV_n) : reflect (exists i, v i 0 != 0) (v != 0).
Proof.
apply: (iffP (matrix0Pn _)) => [[i] [j]|[i]]; last by exists i, 0.
by rewrite ord1; exists i.
Qed.
Definition nz_row m n (A : 'M_(m, n)) :=
oapp (fun i => row i A) 0 [pick i | row i A != 0].
Lemma nz_row_eq0 m n (A : 'M_(m, n)) : (nz_row A == 0) = (A == 0).
Proof.
rewrite /nz_row; symmetry; case: pickP => [i /= nzAi | Ai0].
by rewrite (negPf nzAi); apply: contraTF nzAi => /eqP->; rewrite row0 eqxx.
by rewrite eqxx; apply/eqP/row_matrixP=> i; move/eqP: (Ai0 i) ->; rewrite row0.
Qed.
Definition is_diag_mx m n (A : 'M[V]_(m, n)) :=
[forall i : 'I__, forall j : 'I__, (i != j :> nat) ==> (A i j == 0)].
Lemma is_diag_mxP m n (A : 'M[V]_(m, n)) :
reflect (forall i j : 'I__, i != j :> nat -> A i j = 0) (is_diag_mx A).
Proof. by apply: (iffP 'forall_'forall_implyP) => /(_ _ _ _)/eqP. Qed.
Lemma mx0_is_diag m n : is_diag_mx (0 : 'M[V]_(m, n)).
Proof. by apply/is_diag_mxP => i j _; rewrite mxE. Qed.
Lemma mx11_is_diag (M : 'M_1) : is_diag_mx M.
Proof. by apply/is_diag_mxP => i j; rewrite !ord1 eqxx. Qed.
Definition is_trig_mx m n (A : 'M[V]_(m, n)) :=
[forall i : 'I__, forall j : 'I__, (i < j)%N ==> (A i j == 0)].
Lemma is_trig_mxP m n (A : 'M[V]_(m, n)) :
reflect (forall i j : 'I__, (i < j)%N -> A i j = 0) (is_trig_mx A).
Proof. by apply: (iffP 'forall_'forall_implyP) => /(_ _ _ _)/eqP. Qed.
Lemma is_diag_mx_is_trig m n (A : 'M[V]_(m, n)) : is_diag_mx A -> is_trig_mx A.
Proof.
by move=> /is_diag_mxP A_eq0; apply/is_trig_mxP=> i j lt_ij;
rewrite A_eq0// ltn_eqF.
Qed.
Lemma mx0_is_trig m n : is_trig_mx (0 : 'M[V]_(m, n)).
Proof. by apply/is_trig_mxP => i j _; rewrite mxE. Qed.
Lemma mx11_is_trig (M : 'M_1) : is_trig_mx M.
Proof. by apply/is_trig_mxP => i j; rewrite !ord1 ltnn. Qed.
Lemma is_diag_mxEtrig m n (A : 'M[V]_(m, n)) :
is_diag_mx A = is_trig_mx A && is_trig_mx A^T.
Proof.
apply/is_diag_mxP/andP => [Adiag|[/is_trig_mxP Atrig /is_trig_mxP ATtrig]].
by split; apply/is_trig_mxP => i j lt_ij; rewrite ?mxE ?Adiag//;
[rewrite ltn_eqF|rewrite gtn_eqF].
by move=> i j; case: ltngtP => // [/Atrig|/ATtrig]; rewrite ?mxE.
Qed.
Lemma is_diag_trmx m n (A : 'M[V]_(m, n)) : is_diag_mx A^T = is_diag_mx A.
Proof. by rewrite !is_diag_mxEtrig trmxK andbC. Qed.
Lemma ursubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
m1 <= n1 -> is_trig_mx A -> ursubmx A = 0.
Proof.
move=> leq_m1_n1 /is_trig_mxP Atrig; apply/matrixP => i j.
by rewrite !mxE Atrig//= ltn_addr// (@leq_trans m1).
Qed.
Lemma dlsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
n1 <= m1 -> is_diag_mx A -> dlsubmx A = 0.
Proof.
move=> leq_m2_n2 /is_diag_mxP Adiag; apply/matrixP => i j.
by rewrite !mxE Adiag// gtn_eqF//= ltn_addr// (@leq_trans n1).
Qed.
Lemma ulsubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
is_trig_mx A -> is_trig_mx (ulsubmx A).
Proof.
move=> /is_trig_mxP Atrig; apply/is_trig_mxP => i j lt_ij.
by rewrite !mxE Atrig.
Qed.
Lemma drsubmx_trig m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
m1 <= n1 -> is_trig_mx A -> is_trig_mx (drsubmx A).
Proof.
move=> leq_m1_n1 /is_trig_mxP Atrig; apply/is_trig_mxP => i j lt_ij.
by rewrite !mxE Atrig//= -addnS leq_add.
Qed.
Lemma ulsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
is_diag_mx A -> is_diag_mx (ulsubmx A).
Proof.
rewrite !is_diag_mxEtrig trmx_ulsub.
by move=> /andP[/ulsubmx_trig-> /ulsubmx_trig->].
Qed.
Lemma drsubmx_diag m1 m2 n1 n2 (A : 'M[V]_(m1 + m2, n1 + n2)) :
m1 = n1 -> is_diag_mx A -> is_diag_mx (drsubmx A).
Proof.
move=> eq_m1_n1 /is_diag_mxP Adiag; apply/is_diag_mxP => i j neq_ij.
by rewrite !mxE Adiag//= eq_m1_n1 eqn_add2l.
Qed.
Lemma is_trig_block_mx m1 m2 n1 n2 ul ur dl dr : m1 = n1 ->
@is_trig_mx (m1 + m2) (n1 + n2) (block_mx ul ur dl dr) =
[&& ur == 0, is_trig_mx ul & is_trig_mx dr].
Proof.
move=> eq_m1_n1; rewrite {}eq_m1_n1 in ul ur dl dr *.
apply/is_trig_mxP/and3P => [Atrig|]; last first.
move=> [/eqP-> /is_trig_mxP ul_trig /is_trig_mxP dr_trig] i j; rewrite !mxE.
do 2![case: split_ordP => ? ->; rewrite ?mxE//=] => lt_ij; rewrite ?ul_trig//.
move: lt_ij; rewrite ltnNge -ltnS.
by rewrite (leq_trans (ltn_ord _))// -addnS leq_addr.
by rewrite dr_trig//; move: lt_ij; rewrite ltn_add2l.
split.
- apply/eqP/matrixP => i j; have := Atrig (lshift _ i) (rshift _ j).
rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE.
case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP-> /eqP<- <- //.
by rewrite /= (leq_trans (ltn_ord _)) ?leq_addr.
- apply/is_trig_mxP => i j lt_ij; have := Atrig (lshift _ i) (lshift _ j).
rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE.
by case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP<- /eqP<- ->.
- apply/is_trig_mxP => i j lt_ij; have := Atrig (rshift _ i) (rshift _ j).
rewrite !mxE; case: split_ordP => k /eqP; rewrite eq_shift// ?mxE.
case: split_ordP => l /eqP; rewrite eq_shift// ?mxE => /eqP<- /eqP<- -> //.
by rewrite /= ltn_add2l.
Qed.
Lemma trigmx_ind (P : forall m n, 'M_(m, n) -> Type) :
(forall m, P m 0 0) ->
(forall n, P 0 n 0) ->
(forall m n x c A, is_trig_mx A ->
P m n A -> P (1 + m)%N (1 + n)%N (block_mx x 0 c A)) ->
forall m n A, is_trig_mx A -> P m n A.
Proof.
move=> P0l P0r PS m n A; elim: A => {m n} [m|n|m n xx r c] A PA;
do ?by rewrite (flatmx0, thinmx0); by [apply: P0l|apply: P0r].
by rewrite is_trig_block_mx => // /and3P[/eqP-> _ Atrig]; apply: PS (PA _).
Qed.
Lemma trigsqmx_ind (P : forall n, 'M[V]_n -> Type) : (P 0 0) ->
(forall n x c A, is_trig_mx A -> P n A -> P (1 + n)%N (block_mx x 0 c A)) ->
forall n A, is_trig_mx A -> P n A.
Proof.
move=> P0 PS n A; elim/sqmx_ind: A => {n} [|n x r c] A PA.
by rewrite thinmx0; apply: P0.
by rewrite is_trig_block_mx => // /and3P[/eqP-> _ Atrig]; apply: PS (PA _).
Qed.
Lemma is_diag_block_mx m1 m2 n1 n2 ul ur dl dr : m1 = n1 ->
@is_diag_mx (m1 + m2) (n1 + n2) (block_mx ul ur dl dr) =
[&& ur == 0, dl == 0, is_diag_mx ul & is_diag_mx dr].
Proof.
move=> eq_m1_n1.
rewrite !is_diag_mxEtrig tr_block_mx !is_trig_block_mx// trmx_eq0.
by rewrite andbACA -!andbA; congr [&& _, _, _ & _]; rewrite andbCA.
Qed.
Lemma diagmx_ind (P : forall m n, 'M_(m, n) -> Type) :
(forall m, P m 0 0) ->
(forall n, P 0 n 0) ->
(forall m n x c A, is_diag_mx A ->
P m n A -> P (1 + m)%N (1 + n)%N (block_mx x 0 c A)) ->
forall m n A, is_diag_mx A -> P m n A.
Proof.
move=> P0l P0r PS m n A Adiag; have Atrig := is_diag_mx_is_trig Adiag.
elim/trigmx_ind: Atrig Adiag => // {}m {}n r c {}A _ PA.
rewrite is_diag_block_mx => // /and4P[_ /eqP-> _ Adiag].
exact: PS (PA _).
Qed.
Lemma diagsqmx_ind (P : forall n, 'M[V]_n -> Type) :
(P 0 0) ->
(forall n x c A, is_diag_mx A -> P n A -> P (1 + n)%N (block_mx x 0 c A)) ->
forall n A, is_diag_mx A -> P n A.
Proof.
move=> P0 PS n A; elim/sqmx_ind: A => [|{}n x r c] A PA.
by rewrite thinmx0; apply: P0.
rewrite is_diag_block_mx => // /and4P[/eqP-> /eqP-> _ Adiag].
exact: PS (PA _).
Qed.
(* Diagonal matrices *)
Fact diag_mx_key : unit. Proof. by []. Qed.
Definition diag_mx n (d : 'rV[V]_n) :=
\matrix[diag_mx_key]_(i, j) (d 0 i *+ (i == j)).
Lemma tr_diag_mx n (d : 'rV_n) : (diag_mx d)^T = diag_mx d.
Proof. by apply/matrixP=> i j /[!mxE]; case: eqVneq => // ->. Qed.
Fact diag_mx_is_nmod_morphism n : nmod_morphism (@diag_mx n).
Proof.
by split=> [|A B]; apply/matrixP => i j; rewrite !mxE ?mul0rn// mulrnDl.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `diag_mx_is_nmod_morphism` instead")]
Definition diag_mx_is_semi_additive := diag_mx_is_nmod_morphism.
HB.instance Definition _ n := GRing.isNmodMorphism.Build 'rV_n 'M_n (@diag_mx n)
(@diag_mx_is_nmod_morphism n).
Lemma diag_mx_row m n (l : 'rV_n) (r : 'rV_m) :
diag_mx (row_mx l r) = block_mx (diag_mx l) 0 0 (diag_mx r).
Proof.
apply/matrixP => i j.
by do ?[rewrite !mxE; case: split_ordP => ? ->]; rewrite mxE eq_shift.
Qed.
Lemma diag_mxP n (A : 'M[V]_n) :
reflect (exists d : 'rV_n, A = diag_mx d) (is_diag_mx A).
Proof.
apply: (iffP (is_diag_mxP A)) => [Adiag|[d ->] i j neq_ij]; last first.
by rewrite !mxE -val_eqE (negPf neq_ij).
exists (\row_i A i i); apply/matrixP => i j; rewrite !mxE.
by case: (altP (i =P j)) => [->|/Adiag->].
Qed.
Lemma diag_mx_is_diag n (r : 'rV[V]_n) : is_diag_mx (diag_mx r).
Proof. by apply/diag_mxP; exists r. Qed.
Lemma diag_mx_is_trig n (r : 'rV[V]_n) : is_trig_mx (diag_mx r).
Proof. exact/is_diag_mx_is_trig/diag_mx_is_diag. Qed.
(* Scalar matrix : a diagonal matrix with a constant on the diagonal *)
Section ScalarMx.
Variable n : nat.
Fact scalar_mx_key : unit. Proof. by []. Qed.
Definition scalar_mx x : 'M[V]_n :=
\matrix[scalar_mx_key]_(i , j) (x *+ (i == j)).
Notation "x %:M" := (scalar_mx x) : ring_scope.
Lemma diag_const_mx a : diag_mx (const_mx a) = a%:M :> 'M_n.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma tr_scalar_mx a : (a%:M)^T = a%:M.
Proof. by apply/matrixP=> i j; rewrite !mxE eq_sym. Qed.
Fact scalar_mx_is_nmod_morphism : nmod_morphism scalar_mx.
Proof. by split=> [|a b]; rewrite -!diag_const_mx ?raddf0// !raddfD. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `scalar_mx_is_nmod_morphism` instead")]
Definition scalar_mx_is_semi_additive := scalar_mx_is_nmod_morphism.
HB.instance Definition _ := GRing.isNmodMorphism.Build V 'M_n scalar_mx
scalar_mx_is_nmod_morphism.
Definition is_scalar_mx (A : 'M[V]_n) :=
if insub 0 is Some i then A == (A i i)%:M else true.
Lemma is_scalar_mxP A : reflect (exists a, A = a%:M) (is_scalar_mx A).
Proof.
rewrite /is_scalar_mx; case: insubP => [i _ _ | ].
by apply: (iffP eqP) => [|[a ->]]; [exists (A i i) | rewrite mxE eqxx].
rewrite -eqn0Ngt => /eqP n0; left; exists 0.
by rewrite raddf0; rewrite n0 in A *; rewrite [A]flatmx0.
Qed.
Lemma scalar_mx_is_scalar a : is_scalar_mx a%:M.
Proof. by apply/is_scalar_mxP; exists a. Qed.
Lemma mx0_is_scalar : is_scalar_mx 0.
Proof. by apply/is_scalar_mxP; exists 0; rewrite raddf0. Qed.
Lemma scalar_mx_is_diag a : is_diag_mx a%:M.
Proof. by rewrite -diag_const_mx diag_mx_is_diag. Qed.
Lemma is_scalar_mx_is_diag A : is_scalar_mx A -> is_diag_mx A.
Proof. by move=> /is_scalar_mxP[a ->]; apply: scalar_mx_is_diag. Qed.
Lemma scalar_mx_is_trig a : is_trig_mx a%:M.
Proof. by rewrite is_diag_mx_is_trig// scalar_mx_is_diag. Qed.
Lemma is_scalar_mx_is_trig A : is_scalar_mx A -> is_trig_mx A.
Proof. by move=> /is_scalar_mx_is_diag /is_diag_mx_is_trig. Qed.
End ScalarMx.
Notation "x %:M" := (scalar_mx _ x) : ring_scope.
Lemma mx11_scalar (A : 'M_1) : A = (A 0 0)%:M.
Proof. by apply/rowP=> j; rewrite ord1 mxE. Qed.
Lemma scalar_mx_block n1 n2 a : a%:M = block_mx a%:M 0 0 a%:M :> 'M_(n1 + n2).
Proof.
apply/matrixP=> i j; rewrite !mxE.
by do 2![case: split_ordP => ? ->; rewrite !mxE]; rewrite ?eq_shift.
Qed.
(* The trace. *)
Section Trace.
Variable n : nat.
(*TODO: undergeneralize to monoid *)
Definition mxtrace (A : 'M[V]_n) := \sum_i A i i.
Local Notation "'\tr' A" := (mxtrace A) : ring_scope.
Lemma mxtrace_tr A : \tr A^T = \tr A.
Proof. by apply: eq_bigr=> i _; rewrite mxE. Qed.
Fact mxtrace_is_nmod_morphism : nmod_morphism mxtrace.
Proof.
split=> [|A B]; first by apply: big1 => i; rewrite mxE.
by rewrite -big_split /=; apply: eq_bigr => i _; rewrite mxE.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `mxtrace_is_nmod_morphism` instead")]
Definition mxtrace_is_semi_additive := mxtrace_is_nmod_morphism.
HB.instance Definition _ := GRing.isNmodMorphism.Build 'M_n V mxtrace
mxtrace_is_nmod_morphism.
Lemma mxtrace0 : \tr 0 = 0. Proof. exact: raddf0. Qed.
Lemma mxtraceD A B : \tr (A + B) = \tr A + \tr B. Proof. exact: raddfD. Qed.
Lemma mxtrace_diag D : \tr (diag_mx D) = \sum_j D 0 j.
Proof. by apply: eq_bigr => j _; rewrite mxE eqxx. Qed.
Lemma mxtrace_scalar a : \tr a%:M = a *+ n.
Proof.
rewrite -diag_const_mx mxtrace_diag; under eq_bigr do rewrite mxE.
by rewrite sumr_const card_ord.
Qed.
End Trace.
Local Notation "'\tr' A" := (mxtrace A) : ring_scope.
Lemma trace_mx11 (A : 'M_1) : \tr A = A 0 0.
Proof. by rewrite [A in LHS]mx11_scalar mxtrace_scalar. Qed.
Lemma mxtrace_block n1 n2 (Aul : 'M_n1) Aur Adl (Adr : 'M_n2) :
\tr (block_mx Aul Aur Adl Adr) = \tr Aul + \tr Adr.
Proof.
rewrite /(\tr _) big_split_ord /=.
by congr (_ + _); under eq_bigr do rewrite (block_mxEul, block_mxEdr).
Qed.
End MatrixNmodule.
Arguments is_diag_mx {V m n}.
Arguments is_diag_mxP {V m n A}.
Arguments is_trig_mx {V m n}.
Arguments is_trig_mxP {V m n A}.
Arguments scalar_mx {V n}.
Arguments is_scalar_mxP {V n A}.
Notation "\tr A" := (mxtrace A) : ring_scope.
(* Parametricity over the semi-additive structure. *)
Section MapNmodMatrix.
Variables (aR rR : nmodType) (f : {additive aR -> rR}) (m n : nat).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Implicit Type A : 'M[aR]_(m, n).
Lemma map_mx0 : 0^f = 0 :> 'M_(m, n).
Proof. by rewrite map_const_mx raddf0. Qed.
Lemma map_mxD A B : (A + B)^f = A^f + B^f.
Proof. by apply/matrixP=> i j; rewrite !mxE raddfD. Qed.
Definition map_mx_sum := big_morph _ map_mxD map_mx0.
HB.instance Definition _ :=
GRing.isNmodMorphism.Build 'M[aR]_(m, n) 'M[rR]_(m, n) (map_mx f)
(map_mx0, map_mxD).
End MapNmodMatrix.
Section MatrixZmodule.
Variable V : zmodType.
Section FixedDim.
Variables m n : nat.
Implicit Types A B : 'M[V]_(m, n).
Fact oppmx_key : unit. Proof. by []. Qed.
Definition oppmx := @map_mx V V -%R m n.
Lemma addNmx : left_inverse (const_mx 0) oppmx (@addmx V m n).
Proof. by move=> A; apply/matrixP=> i j; rewrite !mxE addNr. Qed.
HB.instance Definition _ := GRing.Nmodule_isZmodule.Build 'M[V]_(m, n) addNmx.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")]
Fact const_mx_is_zmod_morphism : zmod_morphism const_mx.
Proof. exact: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"),
warning="-deprecated"]
Definition const_mx_is_additive := const_mx_is_zmod_morphism.
End FixedDim.
Section Additive.
Variables (m n p q : nat) (f : 'I_p -> 'I_q -> 'I_m) (g : 'I_p -> 'I_q -> 'I_n).
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")]
Fact swizzle_mx_is_zmod_morphism k : zmod_morphism (swizzle_mx f g k).
Proof. exact: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"),
warning="-deprecated"]
Definition swizzle_mx_is_additive := swizzle_mx_is_zmod_morphism.
End Additive.
Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?].
Lemma opp_row_mx m n1 n2 (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
- row_mx A1 A2 = row_mx (- A1) (- A2).
Proof. by split_mxE. Qed.
Lemma opp_col_mx m1 m2 n (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
- col_mx A1 A2 = col_mx (- A1) (- A2).
Proof. by split_mxE. Qed.
Lemma opp_block_mx m1 m2 n1 n2 (Aul : 'M_(m1, n1)) Aur Adl (Adr : 'M_(m2, n2)) :
- block_mx Aul Aur Adl Adr = block_mx (- Aul) (- Aur) (- Adl) (- Adr).
Proof. by rewrite opp_col_mx !opp_row_mx. Qed.
(* Diagonal matrices *)
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")]
Fact diag_mx_is_zmod_morphism n : zmod_morphism (@diag_mx V n).
Proof. exact: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"),
warning="-deprecated"]
Definition diag_mx_is_additive := diag_mx_is_zmod_morphism.
(* Scalar matrix : a diagonal matrix with a constant on the diagonal *)
Section ScalarMx.
Variable n : nat.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")]
Fact scalar_mx_is_zmod_morphism : zmod_morphism (@scalar_mx V n).
Proof. exact: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"),
warning="-deprecated"]
Definition scalar_mx_is_additive := scalar_mx_is_zmod_morphism.
End ScalarMx.
(* The trace. *)
Section Trace.
Variable n : nat.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead")]
Fact mxtrace_is_zmod_morphism : zmod_morphism (@mxtrace V n).
Proof. exact: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `raddfB` instead"),
warning="-deprecated"]
Definition mxtrace_is_additive := mxtrace_is_zmod_morphism.
End Trace.
End MatrixZmodule.
(* Parametricity over the additive structure. *)
Section MapZmodMatrix.
Variables (aR rR : zmodType) (f : {additive aR -> rR}) (m n : nat).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Implicit Type A : 'M[aR]_(m, n).
Lemma map_mxN A : (- A)^f = - A^f.
Proof. exact: raddfN. Qed.
Lemma map_mxB A B : (A - B)^f = A^f - B^f.
Proof. exact: raddfB. Qed.
End MapZmodMatrix.
(*****************************************************************************)
(*********** Matrix ring module, graded ring, and ring structures ************)
(*****************************************************************************)
Section MatrixAlgebra.
Variable R : pzSemiRingType.
Section SemiRingModule.
(* The ring module/vector space structure *)
Variables m n : nat.
Implicit Types A B : 'M[R]_(m, n).
Fact scalemx_key : unit. Proof. by []. Qed.
Definition scalemx x A := \matrix[scalemx_key]_(i, j) (x * A i j).
(* Basis *)
Fact delta_mx_key : unit. Proof. by []. Qed.
Definition delta_mx i0 j0 : 'M[R]_(m, n) :=
\matrix[delta_mx_key]_(i, j) ((i == i0) && (j == j0))%:R.
Local Notation "x *m: A" := (scalemx x A) (at level 40) : ring_scope.
Fact scale0mx A : 0 *m: A = 0.
Proof. by apply/matrixP=> i j; rewrite !mxE mul0r. Qed.
Fact scale1mx A : 1 *m: A = A.
Proof. by apply/matrixP=> i j; rewrite !mxE mul1r. Qed.
Fact scalemxDl A x y : (x + y) *m: A = x *m: A + y *m: A.
Proof. by apply/matrixP=> i j; rewrite !mxE mulrDl. Qed.
Fact scalemxDr x A B : x *m: (A + B) = x *m: A + x *m: B.
Proof. by apply/matrixP=> i j; rewrite !mxE mulrDr. Qed.
Fact scalemxA x y A : x *m: (y *m: A) = (x * y) *m: A.
Proof. by apply/matrixP=> i j; rewrite !mxE mulrA. Qed.
HB.instance Definition _ :=
GRing.Nmodule_isLSemiModule.Build R 'M[R]_(m, n)
scalemxA scale0mx scale1mx scalemxDr scalemxDl.
Lemma scalemx_const a b : a *: const_mx b = const_mx (a * b).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma matrix_sum_delta A : A = \sum_(i < m) \sum_(j < n) A i j *: delta_mx i j.
Proof.
apply/matrixP=> i j.
rewrite summxE (bigD1_ord i) // summxE (bigD1_ord j) //= !mxE !eqxx mulr1.
rewrite !big1 ?addr0 //= => [i' | j'] _.
by rewrite summxE big1// => j' _; rewrite !mxE eq_liftF mulr0.
by rewrite !mxE eqxx eq_liftF mulr0.
Qed.
End SemiRingModule.
Lemma trmx_delta m n i j : (delta_mx i j)^T = delta_mx j i :> 'M[R]_(n, m).
Proof. by apply/matrixP=> i' j'; rewrite !mxE andbC. Qed.
Lemma delta_mx_lshift m n1 n2 i j :
delta_mx i (lshift n2 j) = row_mx (delta_mx i j) 0 :> 'M_(m, n1 + n2).
Proof.
apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inl _ _)).
by case: split => ?; rewrite mxE ?andbF.
Qed.
Lemma delta_mx_rshift m n1 n2 i j :
delta_mx i (rshift n1 j) = row_mx 0 (delta_mx i j) :> 'M_(m, n1 + n2).
Proof.
apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inr _ _)).
by case: split => ?; rewrite mxE ?andbF.
Qed.
Lemma delta_mx_ushift m1 m2 n i j :
delta_mx (lshift m2 i) j = col_mx (delta_mx i j) 0 :> 'M_(m1 + m2, n).
Proof.
apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inl _ _)).
by case: split => ?; rewrite mxE.
Qed.
Lemma delta_mx_dshift m1 m2 n i j :
delta_mx (rshift m1 i) j = col_mx 0 (delta_mx i j) :> 'M_(m1 + m2, n).
Proof.
apply/matrixP=> i' j'; rewrite !mxE -(can_eq splitK) (unsplitK (inr _ _)).
by case: split => ?; rewrite mxE.
Qed.
Lemma vec_mx_delta m n i j :
vec_mx (delta_mx 0 (mxvec_index i j)) = delta_mx i j :> 'M_(m, n).
Proof.
by apply/matrixP=> i' j'; rewrite !mxE /= [_ == _](inj_eq enum_rank_inj).
Qed.
Lemma mxvec_delta m n i j :
mxvec (delta_mx i j) = delta_mx 0 (mxvec_index i j) :> 'rV_(m * n).
Proof. by rewrite -vec_mx_delta vec_mxK. Qed.
Ltac split_mxE := apply/matrixP=> i j; do ![rewrite mxE | case: split => ?].
(* Scalar matrix *)
Notation "x %:M" := (scalar_mx x) : ring_scope.
Lemma trmx1 n : (1%:M)^T = 1%:M :> 'M[R]_n. Proof. exact: tr_scalar_mx. Qed.
Lemma row1 n i : row i (1%:M : 'M_n) = delta_mx 0 i.
Proof. by apply/rowP=> j; rewrite !mxE eq_sym. Qed.
Lemma col1 n i : col i (1%:M : 'M_n) = delta_mx i 0.
Proof. by apply/colP => j; rewrite !mxE eqxx andbT. Qed.
(* Matrix multiplication using bigops. *)
Fact mulmx_key : unit. Proof. by []. Qed.
Definition mulmx {m n p} (A : 'M_(m, n)) (B : 'M_(n, p)) : 'M[R]_(m, p) :=
\matrix[mulmx_key]_(i, k) \sum_j (A i j * B j k).
Local Notation "A *m B" := (mulmx A B) : ring_scope.
Lemma mulmxA m n p q (A : 'M_(m, n)) (B : 'M_(n, p)) (C : 'M_(p, q)) :
A *m (B *m C) = A *m B *m C.
Proof.
apply/matrixP=> i l /[!mxE]; under eq_bigr do rewrite mxE big_distrr/=.
rewrite exchange_big; apply: eq_bigr => j _; rewrite mxE big_distrl /=.
by under eq_bigr do rewrite mulrA.
Qed.
Lemma mul0mx m n p (A : 'M_(n, p)) : 0 *m A = 0 :> 'M_(m, p).
Proof.
by apply/matrixP=> i k; rewrite !mxE big1 //= => j _; rewrite mxE mul0r.
Qed.
Lemma mulmx0 m n p (A : 'M_(m, n)) : A *m 0 = 0 :> 'M_(m, p).
Proof.
by apply/matrixP=> i k; rewrite !mxE big1 // => j _; rewrite mxE mulr0.
Qed.
Lemma mulmxDl m n p (A1 A2 : 'M_(m, n)) (B : 'M_(n, p)) :
(A1 + A2) *m B = A1 *m B + A2 *m B.
Proof.
apply/matrixP=> i k; rewrite !mxE -big_split /=.
by apply: eq_bigr => j _; rewrite !mxE -mulrDl.
Qed.
Lemma mulmxDr m n p (A : 'M_(m, n)) (B1 B2 : 'M_(n, p)) :
A *m (B1 + B2) = A *m B1 + A *m B2.
Proof.
apply/matrixP=> i k; rewrite !mxE -big_split /=.
by apply: eq_bigr => j _; rewrite mxE mulrDr.
Qed.
HB.instance Definition _ m n p A :=
GRing.isNmodMorphism.Build 'M_(n, p) 'M_(m, p) (mulmx A)
(mulmx0 _ A, mulmxDr A).
Lemma scalemxAl m n p a (A : 'M_(m, n)) (B : 'M_(n, p)) :
a *: (A *m B) = (a *: A) *m B.
Proof.
apply/matrixP=> i k; rewrite !mxE big_distrr /=.
by apply: eq_bigr => j _; rewrite mulrA mxE.
Qed.
Lemma mulmx_suml m n p (A : 'M_(n, p)) I r P (B_ : I -> 'M_(m, n)) :
(\sum_(i <- r | P i) B_ i) *m A = \sum_(i <- r | P i) B_ i *m A.
Proof.
by apply: (big_morph (mulmx^~ A)) => [B C|]; rewrite ?mul0mx ?mulmxDl.
Qed.
Lemma mulmx_sumr m n p (A : 'M_(m, n)) I r P (B_ : I -> 'M_(n, p)) :
A *m (\sum_(i <- r | P i) B_ i) = \sum_(i <- r | P i) A *m B_ i.
Proof. exact: raddf_sum. Qed.
Lemma rowE m n i (A : 'M_(m, n)) : row i A = delta_mx 0 i *m A.
Proof.
apply/rowP=> j; rewrite !mxE (bigD1_ord i) //= mxE !eqxx mul1r.
by rewrite big1 ?addr0 // => i'; rewrite mxE /= lift_eqF mul0r.
Qed.
Lemma colE m n i (A : 'M_(m, n)) : col i A = A *m delta_mx i 0.
Proof.
apply/colP=> j; rewrite !mxE (bigD1_ord i) //= mxE !eqxx mulr1.
by rewrite big1 ?addr0 // => i'; rewrite mxE /= lift_eqF mulr0.
Qed.
Lemma mul_rVP m n A B : ((@mulmx 1 m n)^~ A =1 mulmx^~ B) <-> (A = B).
Proof. by split=> [eqAB|->//]; apply/row_matrixP => i; rewrite !rowE eqAB. Qed.
Lemma row_mul m n p (i : 'I_m) A (B : 'M_(n, p)) :
row i (A *m B) = row i A *m B.
Proof. by rewrite !rowE mulmxA. Qed.
Lemma mxsub_mul m n m' n' p f g (A : 'M_(m, p)) (B : 'M_(p, n)) :
mxsub f g (A *m B) = rowsub f A *m colsub g B :> 'M_(m', n').
Proof. by split_mxE; under [RHS]eq_bigr do rewrite !mxE. Qed.
Lemma mul_rowsub_mx m n m' p f (A : 'M_(m, p)) (B : 'M_(p, n)) :
rowsub f A *m B = rowsub f (A *m B) :> 'M_(m', n).
Proof. by rewrite mxsub_mul mxsub_id. Qed.
Lemma mulmx_colsub m n n' p g (A : 'M_(m, p)) (B : 'M_(p, n)) :
A *m colsub g B = colsub g (A *m B) :> 'M_(m, n').
Proof. by rewrite mxsub_mul mxsub_id. Qed.
Lemma mul_delta_mx_cond m n p (j1 j2 : 'I_n) (i1 : 'I_m) (k2 : 'I_p) :
delta_mx i1 j1 *m delta_mx j2 k2 = delta_mx i1 k2 *+ (j1 == j2).
Proof.
apply/matrixP => i k; rewrite !mxE (bigD1_ord j1) //=.
rewrite mulmxnE !mxE !eqxx andbT -natrM -mulrnA !mulnb !andbA andbAC.
by rewrite big1 ?addr0 // => j; rewrite !mxE andbC -natrM lift_eqF.
Qed.
Lemma mul_delta_mx m n p (j : 'I_n) (i : 'I_m) (k : 'I_p) :
delta_mx i j *m delta_mx j k = delta_mx i k.
Proof. by rewrite mul_delta_mx_cond eqxx. Qed.
Lemma mul_delta_mx_0 m n p (j1 j2 : 'I_n) (i1 : 'I_m) (k2 : 'I_p) :
j1 != j2 -> delta_mx i1 j1 *m delta_mx j2 k2 = 0.
Proof. by rewrite mul_delta_mx_cond => /negPf->. Qed.
Lemma mul_diag_mx m n d (A : 'M_(m, n)) :
diag_mx d *m A = \matrix_(i, j) (d 0 i * A i j).
Proof.
apply/matrixP=> i j; rewrite !mxE (bigD1 i) //= mxE eqxx big1 ?addr0 // => i'.
by rewrite mxE eq_sym mulrnAl => /negPf->.
Qed.
Lemma mul_mx_diag m n (A : 'M_(m, n)) d :
A *m diag_mx d = \matrix_(i, j) (A i j * d 0 j).
Proof.
apply/matrixP=> i j; rewrite !mxE (bigD1 j) //= mxE eqxx big1 ?addr0 // => i'.
by rewrite mxE eq_sym mulrnAr; move/negPf->.
Qed.
Lemma mulmx_diag n (d e : 'rV_n) :
diag_mx d *m diag_mx e = diag_mx (\row_j (d 0 j * e 0 j)).
Proof. by apply/matrixP=> i j; rewrite mul_diag_mx !mxE mulrnAr. Qed.
Lemma scalar_mxM n a b : (a * b)%:M = a%:M *m b%:M :> 'M_n.
Proof.
rewrite -[in RHS]diag_const_mx mul_diag_mx.
by apply/matrixP => i j; rewrite !mxE mulrnAr.
Qed.
Lemma mul1mx m n (A : 'M_(m, n)) : 1%:M *m A = A.
Proof.
by rewrite -diag_const_mx mul_diag_mx; apply/matrixP => i j; rewrite !mxE mul1r.
Qed.
Lemma mulmx1 m n (A : 'M_(m, n)) : A *m 1%:M = A.
Proof.
by rewrite -diag_const_mx mul_mx_diag; apply/matrixP=> i j; rewrite !mxE mulr1.
Qed.
Lemma rowsubE m m' n f (A : 'M_(m, n)) :
rowsub f A = rowsub f 1%:M *m A :> 'M_(m', n).
Proof. by rewrite mul_rowsub_mx mul1mx. Qed.
(* mulmx and col_perm, row_perm, xcol, xrow *)
Lemma mul_col_perm m n p s (A : 'M_(m, n)) (B : 'M_(n, p)) :
col_perm s A *m B = A *m row_perm s^-1 B.
Proof.
apply/matrixP=> i k; rewrite !mxE (reindex_perm s^-1).
by apply: eq_bigr => j _ /=; rewrite !mxE permKV.
Qed.
Lemma mul_row_perm m n p s (A : 'M_(m, n)) (B : 'M_(n, p)) :
A *m row_perm s B = col_perm s^-1 A *m B.
Proof. by rewrite mul_col_perm invgK. Qed.
Lemma mul_xcol m n p j1 j2 (A : 'M_(m, n)) (B : 'M_(n, p)) :
xcol j1 j2 A *m B = A *m xrow j1 j2 B.
Proof. by rewrite mul_col_perm tpermV. Qed.
(* Permutation matrix *)
Definition perm_mx n s : 'M_n := row_perm s (1%:M : 'M[R]_n).
Definition tperm_mx n i1 i2 : 'M_n := perm_mx (tperm i1 i2).
Lemma col_permE m n s (A : 'M_(m, n)) : col_perm s A = A *m perm_mx s^-1.
Proof. by rewrite mul_row_perm mulmx1 invgK. Qed.
Lemma row_permE m n s (A : 'M_(m, n)) : row_perm s A = perm_mx s *m A.
Proof.
by rewrite -[perm_mx _]mul1mx mul_row_perm mulmx1 -mul_row_perm mul1mx.
Qed.
Lemma xcolE m n j1 j2 (A : 'M_(m, n)) : xcol j1 j2 A = A *m tperm_mx j1 j2.
Proof. by rewrite /xcol col_permE tpermV. Qed.
Lemma xrowE m n i1 i2 (A : 'M_(m, n)) : xrow i1 i2 A = tperm_mx i1 i2 *m A.
Proof. exact: row_permE. Qed.
Lemma perm_mxEsub n s : @perm_mx n s = rowsub s 1%:M.
Proof. by rewrite /perm_mx row_permEsub. Qed.
Lemma tperm_mxEsub n i1 i2 : @tperm_mx n i1 i2 = rowsub (tperm i1 i2) 1%:M.
Proof. by rewrite /tperm_mx perm_mxEsub. Qed.
Lemma tr_perm_mx n (s : 'S_n) : (perm_mx s)^T = perm_mx s^-1.
Proof. by rewrite -[_^T]mulmx1 tr_row_perm mul_col_perm trmx1 mul1mx. Qed.
Lemma tr_tperm_mx n i1 i2 : (tperm_mx i1 i2)^T = tperm_mx i1 i2 :> 'M_n.
Proof. by rewrite tr_perm_mx tpermV. Qed.
Lemma perm_mx1 n : perm_mx 1 = 1%:M :> 'M_n.
Proof. exact: row_perm1. Qed.
Lemma perm_mxM n (s t : 'S_n) : perm_mx (s * t) = perm_mx s *m perm_mx t.
Proof. by rewrite -row_permE -row_permM. Qed.
Definition is_perm_mx n (A : 'M_n) := [exists s, A == perm_mx s].
Lemma is_perm_mxP n (A : 'M_n) :
reflect (exists s, A = perm_mx s) (is_perm_mx A).
Proof. by apply: (iffP existsP) => [] [s /eqP]; exists s. Qed.
Lemma perm_mx_is_perm n (s : 'S_n) : is_perm_mx (perm_mx s).
Proof. by apply/is_perm_mxP; exists s. Qed.
Lemma is_perm_mx1 n : is_perm_mx (1%:M : 'M_n).
Proof. by rewrite -perm_mx1 perm_mx_is_perm. Qed.
Lemma is_perm_mxMl n (A B : 'M_n) :
is_perm_mx A -> is_perm_mx (A *m B) = is_perm_mx B.
Proof.
case/is_perm_mxP=> s ->.
apply/is_perm_mxP/is_perm_mxP=> [[t def_t] | [t ->]]; last first.
by exists (s * t)%g; rewrite perm_mxM.
exists (s^-1 * t)%g.
by rewrite perm_mxM -def_t -!row_permE -row_permM mulVg row_perm1.
Qed.
Lemma is_perm_mx_tr n (A : 'M_n) : is_perm_mx A^T = is_perm_mx A.
Proof.
apply/is_perm_mxP/is_perm_mxP=> [[t def_t] | [t ->]]; exists t^-1%g.
by rewrite -tr_perm_mx -def_t trmxK.
by rewrite tr_perm_mx.
Qed.
Lemma is_perm_mxMr n (A B : 'M_n) :
is_perm_mx B -> is_perm_mx (A *m B) = is_perm_mx A.
Proof.
case/is_perm_mxP=> s ->.
rewrite -[s]invgK -col_permE -is_perm_mx_tr tr_col_perm row_permE.
by rewrite is_perm_mxMl (perm_mx_is_perm, is_perm_mx_tr).
Qed.
(* Partial identity matrix (used in rank decomposition). *)
Fact pid_mx_key : unit. Proof. by []. Qed.
Definition pid_mx {m n} r : 'M[R]_(m, n) :=
\matrix[pid_mx_key]_(i, j) ((i == j :> nat) && (i < r))%:R.
Lemma pid_mx_0 m n : pid_mx 0 = 0 :> 'M_(m, n).
Proof. by apply/matrixP=> i j; rewrite !mxE andbF. Qed.
Lemma pid_mx_1 r : pid_mx r = 1%:M :> 'M_r.
Proof. by apply/matrixP=> i j; rewrite !mxE ltn_ord andbT. Qed.
Lemma pid_mx_row n r : pid_mx r = row_mx 1%:M 0 :> 'M_(r, r + n).
Proof.
apply/matrixP=> i j; rewrite !mxE ltn_ord andbT.
by case: split_ordP => j' ->; rewrite !mxE// (val_eqE (lshift n i)) eq_shift.
Qed.
Lemma pid_mx_col m r : pid_mx r = col_mx 1%:M 0 :> 'M_(r + m, r).
Proof.
apply/matrixP=> i j; rewrite !mxE andbC.
by case: split_ordP => ? ->; rewrite !mxE//.
Qed.
Lemma pid_mx_block m n r : pid_mx r = block_mx 1%:M 0 0 0 :> 'M_(r + m, r + n).
Proof.
apply/matrixP=> i j; rewrite !mxE row_mx0 andbC.
do ![case: split_ordP => ? -> /[!mxE]//].
by rewrite (val_eqE (lshift n _)) eq_shift.
Qed.
Lemma tr_pid_mx m n r : (pid_mx r)^T = pid_mx r :> 'M_(n, m).
Proof. by apply/matrixP=> i j /[!mxE]; case: eqVneq => // ->. Qed.
Lemma pid_mx_minv m n r : pid_mx (minn m r) = pid_mx r :> 'M_(m, n).
Proof. by apply/matrixP=> i j; rewrite !mxE leq_min ltn_ord. Qed.
Lemma pid_mx_minh m n r : pid_mx (minn n r) = pid_mx r :> 'M_(m, n).
Proof. by apply: trmx_inj; rewrite !tr_pid_mx pid_mx_minv. Qed.
Lemma mul_pid_mx m n p q r :
(pid_mx q : 'M_(m, n)) *m (pid_mx r : 'M_(n, p)) = pid_mx (minn n (minn q r)).
Proof.
apply/matrixP=> i k; rewrite !mxE !leq_min.
have [le_n_i | lt_i_n] := leqP n i.
rewrite andbF big1 // => j _.
by rewrite -pid_mx_minh !mxE leq_min ltnNge le_n_i andbF mul0r.
rewrite (bigD1 (Ordinal lt_i_n)) //= big1 ?addr0 => [|j].
by rewrite !mxE eqxx /= -natrM mulnb andbCA.
by rewrite -val_eqE /= !mxE eq_sym -natrM => /negPf->.
Qed.
Lemma pid_mx_id m n p r :
r <= n -> (pid_mx r : 'M_(m, n)) *m (pid_mx r : 'M_(n, p)) = pid_mx r.
Proof. by move=> le_r_n; rewrite mul_pid_mx minnn (minn_idPr _). Qed.
Lemma pid_mxErow m n (le_mn : m <= n) :
pid_mx m = rowsub (widen_ord le_mn) 1%:M.
Proof. by apply/matrixP=> i j; rewrite !mxE -!val_eqE/= ltn_ord andbT. Qed.
Lemma pid_mxEcol m n (le_mn : m <= n) :
pid_mx n = colsub (widen_ord le_mn) 1%:M.
Proof. by apply/matrixP=> i j; rewrite !mxE -!val_eqE/= ltn_ord andbT. Qed.
(* Block products; we cover all 1 x 2, 2 x 1, and 2 x 2 block products. *)
Lemma mul_mx_row m n p1 p2 (A : 'M_(m, n)) (Bl : 'M_(n, p1)) (Br : 'M_(n, p2)) :
A *m row_mx Bl Br = row_mx (A *m Bl) (A *m Br).
Proof.
apply/matrixP=> i k; rewrite !mxE.
by case defk: (split k) => /[!mxE]; under eq_bigr do rewrite mxE defk.
Qed.
Lemma mul_col_mx m1 m2 n p (Au : 'M_(m1, n)) (Ad : 'M_(m2, n)) (B : 'M_(n, p)) :
col_mx Au Ad *m B = col_mx (Au *m B) (Ad *m B).
Proof.
apply/matrixP=> i k; rewrite !mxE.
by case defi: (split i) => /[!mxE]; under eq_bigr do rewrite mxE defi.
Qed.
Lemma mul_row_col m n1 n2 p (Al : 'M_(m, n1)) (Ar : 'M_(m, n2))
(Bu : 'M_(n1, p)) (Bd : 'M_(n2, p)) :
row_mx Al Ar *m col_mx Bu Bd = Al *m Bu + Ar *m Bd.
Proof.
apply/matrixP=> i k; rewrite !mxE big_split_ord /=.
congr (_ + _); apply: eq_bigr => j _; first by rewrite row_mxEl col_mxEu.
by rewrite row_mxEr col_mxEd.
Qed.
Lemma mul_col_row m1 m2 n p1 p2 (Au : 'M_(m1, n)) (Ad : 'M_(m2, n))
(Bl : 'M_(n, p1)) (Br : 'M_(n, p2)) :
col_mx Au Ad *m row_mx Bl Br
= block_mx (Au *m Bl) (Au *m Br) (Ad *m Bl) (Ad *m Br).
Proof. by rewrite mul_col_mx !mul_mx_row. Qed.
Lemma mul_row_block m n1 n2 p1 p2 (Al : 'M_(m, n1)) (Ar : 'M_(m, n2))
(Bul : 'M_(n1, p1)) (Bur : 'M_(n1, p2))
(Bdl : 'M_(n2, p1)) (Bdr : 'M_(n2, p2)) :
row_mx Al Ar *m block_mx Bul Bur Bdl Bdr
= row_mx (Al *m Bul + Ar *m Bdl) (Al *m Bur + Ar *m Bdr).
Proof. by rewrite block_mxEh mul_mx_row !mul_row_col. Qed.
Lemma mul_block_col m1 m2 n1 n2 p (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2))
(Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2))
(Bu : 'M_(n1, p)) (Bd : 'M_(n2, p)) :
block_mx Aul Aur Adl Adr *m col_mx Bu Bd
= col_mx (Aul *m Bu + Aur *m Bd) (Adl *m Bu + Adr *m Bd).
Proof. by rewrite mul_col_mx !mul_row_col. Qed.
Lemma mulmx_block m1 m2 n1 n2 p1 p2 (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2))
(Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2))
(Bul : 'M_(n1, p1)) (Bur : 'M_(n1, p2))
(Bdl : 'M_(n2, p1)) (Bdr : 'M_(n2, p2)) :
block_mx Aul Aur Adl Adr *m block_mx Bul Bur Bdl Bdr
= block_mx (Aul *m Bul + Aur *m Bdl) (Aul *m Bur + Aur *m Bdr)
(Adl *m Bul + Adr *m Bdl) (Adl *m Bur + Adr *m Bdr).
Proof. by rewrite mul_col_mx !mul_row_block. Qed.
Lemma mulmx_lsub m n p k (A : 'M_(m, n)) (B : 'M_(n, p + k)) :
A *m lsubmx B = lsubmx (A *m B).
Proof. by rewrite !lsubmxEsub mulmx_colsub. Qed.
Lemma mulmx_rsub m n p k (A : 'M_(m, n)) (B : 'M_(n, p + k)) :
A *m rsubmx B = rsubmx (A *m B).
Proof. by rewrite !rsubmxEsub mulmx_colsub. Qed.
Lemma mul_usub_mx m k n p (A : 'M_(m + k, n)) (B : 'M_(n, p)) :
usubmx A *m B = usubmx (A *m B).
Proof. by rewrite !usubmxEsub mul_rowsub_mx. Qed.
Lemma mul_dsub_mx m k n p (A : 'M_(m + k, n)) (B : 'M_(n, p)) :
dsubmx A *m B = dsubmx (A *m B).
Proof. by rewrite !dsubmxEsub mul_rowsub_mx. Qed.
(* The trace *)
Section Trace.
Variable n : nat.
Lemma mxtrace1 : \tr (1%:M : 'M[R]_n) = n%:R. Proof. exact: mxtrace_scalar. Qed.
Lemma mxtraceZ a (A : 'M_n) : \tr (a *: A) = a * \tr A.
Proof. by rewrite mulr_sumr; apply: eq_bigr=> i _; rewrite mxE. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build R 'M_n R _ (@mxtrace _ n) mxtraceZ.
End Trace.
Section StructuralLinear.
Fact swizzle_mx_is_scalable m n p q f g k :
scalable (@swizzle_mx R m n p q f g k).
Proof. by move=> a A; apply/matrixP=> i j; rewrite !mxE. Qed.
HB.instance Definition _ m n p q f g k :=
GRing.isScalable.Build R 'M[R]_(m, n) 'M[R]_(p, q) *:%R (swizzle_mx f g k)
(swizzle_mx_is_scalable f g k).
Local Notation SwizzleLin op := (GRing.Linear.copy op (swizzle_mx _ _ _)).
HB.instance Definition _ m n := SwizzleLin (@trmx R m n).
HB.instance Definition _ m n i := SwizzleLin (@row R m n i).
HB.instance Definition _ m n j := SwizzleLin (@col R m n j).
HB.instance Definition _ m n i := SwizzleLin (@row' R m n i).
HB.instance Definition _ m n j := SwizzleLin (@col' R m n j).
HB.instance Definition _ m n m' n' f g := SwizzleLin (@mxsub R m n m' n' f g).
HB.instance Definition _ m n s := SwizzleLin (@row_perm R m n s).
HB.instance Definition _ m n s := SwizzleLin (@col_perm R m n s).
HB.instance Definition _ m n i1 i2 := SwizzleLin (@xrow R m n i1 i2).
HB.instance Definition _ m n j1 j2 := SwizzleLin (@xcol R m n j1 j2).
HB.instance Definition _ m n1 n2 := SwizzleLin (@lsubmx R m n1 n2).
HB.instance Definition _ m n1 n2 := SwizzleLin (@rsubmx R m n1 n2).
HB.instance Definition _ m1 m2 n := SwizzleLin (@usubmx R m1 m2 n).
HB.instance Definition _ m1 m2 n := SwizzleLin (@dsubmx R m1 m2 n).
HB.instance Definition _ m n := SwizzleLin (@vec_mx R m n).
Definition mxvec_is_scalable m n := can2_scalable (@vec_mxK R m n) mxvecK.
HB.instance Definition _ m n :=
GRing.isScalable.Build R 'M_(m, n) 'rV_(m * n) *:%R mxvec
(@mxvec_is_scalable m n).
End StructuralLinear.
Lemma row_sum_delta n (u : 'rV_n) : u = \sum_(j < n) u 0 j *: delta_mx 0 j.
Proof. by rewrite [u in LHS]matrix_sum_delta big_ord1. Qed.
Lemma scale_row_mx m n1 n2 a (A1 : 'M_(m, n1)) (A2 : 'M_(m, n2)) :
a *: row_mx A1 A2 = row_mx (a *: A1) (a *: A2).
Proof. by split_mxE. Qed.
Lemma scale_col_mx m1 m2 n a (A1 : 'M_(m1, n)) (A2 : 'M_(m2, n)) :
a *: col_mx A1 A2 = col_mx (a *: A1) (a *: A2).
Proof. by split_mxE. Qed.
Lemma scale_block_mx m1 m2 n1 n2 a (Aul : 'M_(m1, n1)) (Aur : 'M_(m1, n2))
(Adl : 'M_(m2, n1)) (Adr : 'M_(m2, n2)) :
a *: block_mx Aul Aur Adl Adr
= block_mx (a *: Aul) (a *: Aur) (a *: Adl) (a *: Adr).
Proof. by rewrite scale_col_mx !scale_row_mx. Qed.
(* Diagonal matrices *)
Fact diag_mx_is_scalable n : scalable (@diag_mx R n).
Proof. by move=> a A; apply/matrixP=> i j; rewrite !mxE mulrnAr. Qed.
HB.instance Definition _ n :=
GRing.isScalable.Build R 'rV_n 'M_n _ (@diag_mx _ n) (@diag_mx_is_scalable n).
Lemma diag_mx_sum_delta n (d : 'rV_n) :
diag_mx d = \sum_i d 0 i *: delta_mx i i.
Proof.
apply/matrixP=> i j; rewrite summxE (bigD1_ord i) //= !mxE eqxx /=.
by rewrite eq_sym mulr_natr big1 ?addr0 // => i'; rewrite !mxE eq_liftF mulr0.
Qed.
Lemma row_diag_mx n (d : 'rV_n) i : row i (diag_mx d) = d 0 i *: delta_mx 0 i.
Proof. by apply/rowP => j; rewrite !mxE eqxx eq_sym mulr_natr. Qed.
(* Scalar matrix *)
Lemma scale_scalar_mx n a1 a2 : a1 *: a2%:M = (a1 * a2)%:M :> 'M_n.
Proof. by apply/matrixP=> i j; rewrite !mxE mulrnAr. Qed.
Lemma scalemx1 n a : a *: 1%:M = a%:M :> 'M_n.
Proof. by rewrite scale_scalar_mx mulr1. Qed.
Lemma scalar_mx_sum_delta n a : a%:M = \sum_i a *: delta_mx i i :> 'M_n.
Proof.
by rewrite -diag_const_mx diag_mx_sum_delta; under eq_bigr do rewrite mxE.
Qed.
Lemma mx1_sum_delta n : 1%:M = \sum_i delta_mx i i :> 'M[R]_n.
Proof. by rewrite [1%:M]scalar_mx_sum_delta -scaler_sumr scale1r. Qed.
(* Right scaling associativity requires a commutative ring *)
Lemma mulmx_sum_row m n (u : 'rV_m) (A : 'M_(m, n)) :
u *m A = \sum_i u 0 i *: row i A.
Proof. by apply/rowP => j /[!(mxE, summxE)]; apply: eq_bigr => i _ /[!mxE]. Qed.
Lemma mul_scalar_mx m n a (A : 'M_(m, n)) : a%:M *m A = a *: A.
Proof.
by rewrite -diag_const_mx mul_diag_mx; apply/matrixP=> i j; rewrite !mxE.
Qed.
Section MatrixSemiRing.
Variable n : nat.
HB.instance Definition _ := GRing.Nmodule_isPzSemiRing.Build 'M[R]_n
(@mulmxA n n n n) (@mul1mx n n) (@mulmx1 n n)
(@mulmxDl n n n) (@mulmxDr n n n) (@mul0mx n n n) (@mulmx0 n n n).
Lemma mulmxE : mulmx = *%R. Proof. by []. Qed.
Lemma idmxE : 1%:M = 1 :> 'M_n. Proof. by []. Qed.
Fact scalar_mx_is_monoid_morphism : monoid_morphism (@scalar_mx R n).
Proof. by split=> //; apply: scalar_mxM. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `scalar_mx_is_monoid_morphism` instead")]
Definition scalar_mx_is_multiplicative := scalar_mx_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R 'M_n (@scalar_mx _ n)
scalar_mx_is_monoid_morphism.
End MatrixSemiRing.
(* Correspondence between matrices and linear function on row vectors. *)
Section LinRowVector.
Variables m n : nat.
Fact lin1_mx_key : unit. Proof. by []. Qed.
Definition lin1_mx (f : 'rV[R]_m -> 'rV[R]_n) :=
\matrix[lin1_mx_key]_(i, j) f (delta_mx 0 i) 0 j.
Variable f : {linear 'rV[R]_m -> 'rV[R]_n}.
Lemma mul_rV_lin1 u : u *m lin1_mx f = f u.
Proof.
rewrite [u in RHS]matrix_sum_delta big_ord1 linear_sum; apply/rowP=> i.
by rewrite mxE summxE; apply: eq_bigr => j _; rewrite linearZ !mxE.
Qed.
End LinRowVector.
(* Correspondence between matrices and linear function on matrices. *)
Section LinMatrix.
Variables m1 n1 m2 n2 : nat.
Definition lin_mx (f : 'M[R]_(m1, n1) -> 'M[R]_(m2, n2)) :=
lin1_mx (mxvec \o f \o vec_mx).
Variable f : {linear 'M[R]_(m1, n1) -> 'M[R]_(m2, n2)}.
Lemma mul_rV_lin u : u *m lin_mx f = mxvec (f (vec_mx u)).
Proof. exact: mul_rV_lin1. Qed.
Lemma mul_vec_lin A : mxvec A *m lin_mx f = mxvec (f A).
Proof. by rewrite mul_rV_lin mxvecK. Qed.
Lemma mx_rV_lin u : vec_mx (u *m lin_mx f) = f (vec_mx u).
Proof. by rewrite mul_rV_lin mxvecK. Qed.
Lemma mx_vec_lin A : vec_mx (mxvec A *m lin_mx f) = f A.
Proof. by rewrite mul_rV_lin !mxvecK. Qed.
End LinMatrix.
Section Mulmxr.
Variables m n p : nat.
Implicit Type A : 'M[R]_(m, n).
Implicit Type B : 'M[R]_(n, p).
Definition mulmxr B A := mulmx A B.
Arguments mulmxr B A /.
Fact mulmxr_is_semilinear B : semilinear (mulmxr B).
Proof. by split=> [a A|A1 A2]; rewrite /= (mulmxDl, scalemxAl). Qed.
HB.instance Definition _ (B : 'M_(n, p)) :=
GRing.isSemilinear.Build R 'M_(m, n) 'M_(m, p) _ (mulmxr B)
(mulmxr_is_semilinear B).
Definition lin_mulmxr B := lin_mx (mulmxr B).
Fact lin_mulmxr_is_semilinear : semilinear lin_mulmxr.
Proof.
split=> [a A|A B]; apply/row_matrixP; case/mxvec_indexP=> i j;
rewrite (linearZ, linearD) /= !rowE !mul_rV_lin /= vec_mx_delta;
rewrite -(linearZ, linearD) 1?mulmxDr //=.
congr mxvec; apply/row_matrixP=> k.
rewrite linearZ /= !row_mul rowE mul_delta_mx_cond.
by case: (k == i); [rewrite -!rowE linearZ | rewrite !mul0mx raddf0].
Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R 'M_(n, p) 'M_(m * n, m * p) _ lin_mulmxr
lin_mulmxr_is_semilinear.
End Mulmxr.
Section LiftPerm.
(* Block expression of a lifted permutation matrix, for the Cormen LUP. *)
Variable n : nat.
(* These could be in zmodp, but that would introduce a dependency on perm. *)
Definition lift0_perm s : 'S_n.+1 := lift_perm 0 0 s.
Lemma lift0_perm0 s : lift0_perm s 0 = 0.
Proof. exact: lift_perm_id. Qed.
Lemma lift0_perm_lift s k' :
lift0_perm s (lift 0 k') = lift (0 : 'I_n.+1) (s k').
Proof. exact: lift_perm_lift. Qed.
Lemma lift0_permK s : cancel (lift0_perm s) (lift0_perm s^-1).
Proof. by move=> i; rewrite /lift0_perm -lift_permV permK. Qed.
Lemma lift0_perm_eq0 s i : (lift0_perm s i == 0) = (i == 0).
Proof. by rewrite (canF_eq (lift0_permK s)) lift0_perm0. Qed.
(* Block expression of a lifted permutation matrix *)
Definition lift0_mx A : 'M_(1 + n) := block_mx 1 0 0 A.
Lemma lift0_mx_perm s : lift0_mx (perm_mx s) = perm_mx (lift0_perm s).
Proof.
apply/matrixP=> /= i j; rewrite !mxE split1 /=; case: unliftP => [i'|] -> /=.
rewrite lift0_perm_lift !mxE split1 /=.
by case: unliftP => [j'|] ->; rewrite ?(inj_eq (lift_inj _)) /= !mxE.
rewrite lift0_perm0 !mxE split1 /=.
by case: unliftP => [j'|] ->; rewrite /= mxE.
Qed.
Lemma lift0_mx_is_perm s : is_perm_mx (lift0_mx (perm_mx s)).
Proof. by rewrite lift0_mx_perm perm_mx_is_perm. Qed.
End LiftPerm.
Lemma exp_block_diag_mx m n (A: 'M_m.+1) (B : 'M_n.+1) k :
(block_mx A 0 0 B) ^+ k = block_mx (A ^+ k) 0 0 (B ^+ k).
Proof.
elim: k=> [|k IHk]; first by rewrite !expr0 -scalar_mx_block.
rewrite !exprS IHk [LHS](mulmx_block A _ _ _ (A ^+ k)).
by rewrite !mulmx0 !mul0mx !add0r !addr0.
Qed.
End MatrixAlgebra.
Arguments delta_mx {R m n}.
Arguments perm_mx {R n}.
Arguments tperm_mx {R n}.
Arguments pid_mx {R m n}.
Arguments lin_mulmxr {R m n p}.
Prenex Implicits diag_mx is_scalar_mx.
Prenex Implicits mulmx mxtrace.
Arguments mul_delta_mx {R m n p}.
Arguments mulmxr {_ _ _ _} B A /.
#[global] Hint Extern 0 (is_true (is_diag_mx (scalar_mx _))) =>
apply: scalar_mx_is_diag : core.
#[global] Hint Extern 0 (is_true (is_trig_mx (scalar_mx _))) =>
apply: scalar_mx_is_trig : core.
#[global] Hint Extern 0 (is_true (is_diag_mx (diag_mx _))) =>
apply: diag_mx_is_diag : core.
#[global] Hint Extern 0 (is_true (is_trig_mx (diag_mx _))) =>
apply: diag_mx_is_trig : core.
Notation "a %:M" := (scalar_mx a) : ring_scope.
Notation "A *m B" := (mulmx A B) : ring_scope.
(* Non-commutative transpose requires multiplication in the converse ring. *)
Lemma trmx_mul_rev (R : pzSemiRingType) m n p
(A : 'M[R]_(m, n)) (B : 'M[R]_(n, p)) :
(A *m B)^T = (B : 'M[R^c]_(n, p))^T *m (A : 'M[R^c]_(m, n))^T.
Proof. by apply/matrixP=> k i /[!mxE]; apply: eq_bigr => j _ /[!mxE]. Qed.
HB.instance Definition _ (R : pzRingType) m n :=
GRing.LSemiModule.on 'M[R]_(m, n).
HB.instance Definition _ (R : pzRingType) n := GRing.PzSemiRing.on 'M[R]_n.
Section MatrixNzSemiRing.
Variables (R : nzSemiRingType) (n' : nat).
Local Notation n := n'.+1.
Lemma matrix_nonzero1 : 1%:M != 0 :> 'M[R]_n.
Proof. by apply/eqP=> /matrixP/(_ 0 0)/eqP; rewrite !mxE oner_eq0. Qed.
HB.instance Definition _ :=
GRing.PzSemiRing_isNonZero.Build 'M[R]_n matrix_nonzero1.
HB.instance Definition _ :=
GRing.LSemiModule_isLSemiAlgebra.Build R 'M[R]_n (@scalemxAl R n n n).
End MatrixNzSemiRing.
HB.instance Definition _ (R : nzRingType) n := GRing.NzSemiRing.on 'M[R]_n.+1.
HB.instance Definition _ (M : countNmodType) m n :=
[Countable of 'M[M]_(m, n) by <:].
HB.instance Definition _ (M : countZmodType) m n :=
[Countable of 'M[M]_(m, n) by <:].
HB.instance Definition _ (R : countNzSemiRingType) n :=
[Countable of 'M[R]_n.+1 by <:].
HB.instance Definition _ (R : countNzRingType) n :=
[Countable of 'M[R]_n.+1 by <:].
HB.instance Definition _ (V : finNmodType) (m n : nat) :=
[Finite of 'M[V]_(m, n) by <:].
HB.instance Definition _ (V : finZmodType) (m n : nat) :=
[Finite of 'M[V]_(m, n) by <:].
#[compress_coercions]
HB.instance Definition _ (V : finZmodType) (m n : nat) :=
[finGroupMixin of 'M[V]_(m, n) for +%R].
#[compress_coercions]
HB.instance Definition _ (R : finNzSemiRingType) n :=
[Finite of 'M[R]_n.+1 by <:].
#[compress_coercions]
HB.instance Definition _ (R : finNzRingType) (m n : nat) :=
FinRing.Zmodule.on 'M[R]_(m, n).
#[compress_coercions]
HB.instance Definition _ (R : finNzRingType) n := [Finite of 'M[R]_n.+1 by <:].
(* Parametricity over the algebra structure. *)
Section MapSemiRingMatrix.
Variables (aR rR : pzSemiRingType) (f : {rmorphism aR -> rR}).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Section FixedSize.
Variables m n p : nat.
Implicit Type A : 'M[aR]_(m, n).
Lemma map_mxZ a A : (a *: A)^f = f a *: A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE rmorphM. Qed.
Lemma map_mxM A B : (A *m B)^f = A^f *m B^f :> 'M_(m, p).
Proof.
apply/matrixP=> i k; rewrite !mxE rmorph_sum //.
by apply: eq_bigr => j; rewrite !mxE rmorphM.
Qed.
Lemma map_delta_mx i j : (delta_mx i j)^f = delta_mx i j :> 'M_(m, n).
Proof. by apply/matrixP=> i' j'; rewrite !mxE rmorph_nat. Qed.
Lemma map_diag_mx d : (diag_mx d)^f = diag_mx d^f :> 'M_n.
Proof. by apply/matrixP=> i j; rewrite !mxE rmorphMn. Qed.
Lemma map_scalar_mx a : a%:M^f = (f a)%:M :> 'M_n.
Proof. by apply/matrixP=> i j; rewrite !mxE rmorphMn. Qed.
Lemma map_mx1 : 1%:M^f = 1%:M :> 'M_n.
Proof. by rewrite map_scalar_mx rmorph1. Qed.
Lemma map_perm_mx (s : 'S_n) : (perm_mx s)^f = perm_mx s.
Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed.
Lemma map_tperm_mx (i1 i2 : 'I_n) : (tperm_mx i1 i2)^f = tperm_mx i1 i2.
Proof. exact: map_perm_mx. Qed.
Lemma map_pid_mx r : (pid_mx r)^f = pid_mx r :> 'M_(m, n).
Proof. by apply/matrixP=> i j; rewrite !mxE rmorph_nat. Qed.
Lemma trace_map_mx (A : 'M_n) : \tr A^f = f (\tr A).
Proof. by rewrite rmorph_sum; apply: eq_bigr => i _; rewrite mxE. Qed.
End FixedSize.
Lemma map_lin1_mx m n (g : 'rV_m -> 'rV_n) gf :
(forall v, (g v)^f = gf v^f) -> (lin1_mx g)^f = lin1_mx gf.
Proof.
by move=> def_gf; apply/matrixP => i j; rewrite !mxE -map_delta_mx -def_gf mxE.
Qed.
Lemma map_lin_mx m1 n1 m2 n2 (g : 'M_(m1, n1) -> 'M_(m2, n2)) gf :
(forall A, (g A)^f = gf A^f) -> (lin_mx g)^f = lin_mx gf.
Proof.
move=> def_gf; apply: map_lin1_mx => A /=.
by rewrite map_mxvec def_gf map_vec_mx.
Qed.
Fact map_mx_is_monoid_morphism n : monoid_morphism (map_mx f : 'M_n -> 'M_n).
Proof. by split; [apply: map_mx1 | apply: map_mxM]. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_mx_is_monoid_morphism` instead")]
Definition map_mx_is_multiplicative := map_mx_is_monoid_morphism.
HB.instance Definition _ n :=
GRing.isMonoidMorphism.Build 'M[aR]_n 'M[rR]_n (map_mx f)
(map_mx_is_monoid_morphism n).
End MapSemiRingMatrix.
Section CommMx.
(***********************************************************************)
(************* Commutation property specialized to 'M[R]_n *************)
(***********************************************************************)
(* GRing.comm is bound to (non trivial) rings, and matrices form a *)
(* (non trivial) ring only when they are square and of manifestly *)
(* positive size. However during proofs in endomorphism reduction, we *)
(* take restrictions, which are matrices of size #|V| (with V a matrix *)
(* space) and it becomes cumbersome to state commutation between *)
(* restrictions, unless we relax the setting, and this relaxation *)
(* corresponds to comm_mx A B := A *m B = B *m A. *)
(* As witnessed by comm_mxE, when A and B have type 'M_n.+1, *)
(* comm_mx A B is convertible to GRing.comm A B. *)
(* The boolean version comm_mxb is designed to be used with seq.allrel *)
(***********************************************************************)
Context {R : pzSemiRingType} {n : nat}.
Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type).
Definition comm_mx f g : Prop := f *m g = g *m f.
Definition comm_mxb f g : bool := f *m g == g *m f.
Lemma comm_mx_sym f g : comm_mx f g -> comm_mx g f.
Proof. by rewrite /comm_mx. Qed.
Lemma comm_mx_refl f : comm_mx f f. Proof. by []. Qed.
Lemma comm_mx0 f : comm_mx f 0. Proof. by rewrite /comm_mx mulmx0 mul0mx. Qed.
Lemma comm0mx f : comm_mx 0 f. Proof. by rewrite /comm_mx mulmx0 mul0mx. Qed.
Lemma comm_mx1 f : comm_mx f 1%:M.
Proof. by rewrite /comm_mx mulmx1 mul1mx. Qed.
Lemma comm1mx f : comm_mx 1%:M f.
Proof. by rewrite /comm_mx mulmx1 mul1mx. Qed.
Hint Resolve comm_mx0 comm0mx comm_mx1 comm1mx : core.
Lemma comm_mxD f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g + g').
Proof. by rewrite /comm_mx mulmxDl mulmxDr => -> ->. Qed.
Lemma comm_mxM f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g *m g').
Proof. by rewrite /comm_mx mulmxA => ->; rewrite -!mulmxA => ->. Qed.
Lemma comm_mx_sum I (s : seq I) (P : pred I) (F : I -> 'M[R]_n) (f : 'M[R]_n) :
(forall i : I, P i -> comm_mx f (F i)) -> comm_mx f (\sum_(i <- s | P i) F i).
Proof. by move=> comm_mxfF; elim/big_ind: _ => // g h; apply: comm_mxD. Qed.
Lemma comm_mxP f g : reflect (comm_mx f g) (comm_mxb f g).
Proof. exact: eqP. Qed.
Notation all_comm_mx fs := (all2rel comm_mxb fs).
Lemma all_comm_mxP fs :
reflect {in fs &, forall f g, f *m g = g *m f} (all_comm_mx fs).
Proof. by apply: (iffP allrelP) => fsP ? ? ? ?; apply/eqP/fsP. Qed.
Lemma all_comm_mx1 f : all_comm_mx [:: f].
Proof. by rewrite /comm_mxb all2rel1. Qed.
Lemma all_comm_mx2P f g : reflect (f *m g = g *m f) (all_comm_mx [:: f; g]).
Proof. by rewrite /comm_mxb /= all2rel2 ?eqxx //; exact: eqP. Qed.
Lemma all_comm_mx_cons f fs :
all_comm_mx (f :: fs) = all (comm_mxb f) fs && all_comm_mx fs.
Proof. by rewrite /comm_mxb /= all2rel_cons //= eqxx. Qed.
Lemma comm_mxE : comm_mx = @GRing.comm _. Proof. by []. Qed.
End CommMx.
Notation all_comm_mx := (allrel comm_mxb).
Section ComMatrix.
(* Lemmas for matrices with coefficients in a commutative ring *)
Variable R : comPzSemiRingType.
Section AssocLeft.
Variables m n p : nat.
Implicit Type A : 'M[R]_(m, n).
Implicit Type B : 'M[R]_(n, p).
Lemma trmx_mul A B : (A *m B)^T = B^T *m A^T.
Proof.
rewrite trmx_mul_rev; apply/matrixP=> k i; rewrite !mxE.
by apply: eq_bigr => j _; rewrite mulrC.
Qed.
Lemma scalemxAr a A B : a *: (A *m B) = A *m (a *: B).
Proof. by apply: trmx_inj; rewrite trmx_mul !linearZ /= trmx_mul scalemxAl. Qed.
Fact mulmx_is_scalable A : scalable (@mulmx _ m n p A).
Proof. by move=> a B; rewrite scalemxAr. Qed.
HB.instance Definition _ A :=
GRing.isScalable.Build R 'M[R]_(n, p) 'M[R]_(m, p) *:%R (mulmx A)
(mulmx_is_scalable A).
Definition lin_mulmx A : 'M[R]_(n * p, m * p) := lin_mx (mulmx A).
Fact lin_mulmx_is_semilinear : semilinear lin_mulmx.
Proof.
by split=> [a A|A B]; apply/row_matrixP=> i; rewrite (linearZ, linearD) /=;
rewrite !rowE !mul_rV_lin /= -(linearZ, linearD) /= (scalemxAl, mulmxDl).
Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R 'M[R]_(m, n) 'M[R]_(n * p, m * p) _ lin_mulmx
lin_mulmx_is_semilinear.
End AssocLeft.
Section LinMulRow.
Variables m n : nat.
Definition lin_mul_row u : 'M[R]_(m * n, n) := lin1_mx (mulmx u \o vec_mx).
Fact lin_mul_row_is_semilinear : semilinear lin_mul_row.
Proof.
by split=> [a u|u v]; apply/row_matrixP=> i; rewrite (linearZ, linearD) /=;
rewrite !rowE !mul_rV_lin1 /= (mulmxDl, scalemxAl).
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R _ _ _ lin_mul_row
lin_mul_row_is_semilinear.
Lemma mul_vec_lin_row A u : mxvec A *m lin_mul_row u = u *m A.
Proof. by rewrite mul_rV_lin1 /= mxvecK. Qed.
End LinMulRow.
Lemma diag_mxC n (d e : 'rV[R]_n) :
diag_mx d *m diag_mx e = diag_mx e *m diag_mx d.
Proof.
by rewrite !mulmx_diag; congr (diag_mx _); apply/rowP=> i; rewrite !mxE mulrC.
Qed.
Lemma diag_mx_comm n (d e : 'rV[R]_n) : comm_mx (diag_mx d) (diag_mx e).
Proof. exact: diag_mxC. Qed.
Lemma scalar_mxC m n a (A : 'M[R]_(m, n)) : A *m a%:M = a%:M *m A.
Proof.
rewrite -!diag_const_mx mul_mx_diag mul_diag_mx.
by apply/matrixP => i j; rewrite !mxE mulrC.
Qed.
Lemma comm_mx_scalar n a (A : 'M[R]_n) : comm_mx A a%:M.
Proof. exact: scalar_mxC. Qed.
Lemma comm_scalar_mx n a (A : 'M[R]_n) : comm_mx a%:M A.
Proof. exact/comm_mx_sym/comm_mx_scalar. Qed.
Lemma mxtrace_mulC m n (A : 'M[R]_(m, n)) B : \tr (A *m B) = \tr (B *m A).
Proof.
have expand_trM C D: \tr (C *m D) = \sum_i \sum_j C i j * D j i.
by apply: eq_bigr => i _; rewrite mxE.
rewrite !{}expand_trM exchange_big /=.
by do 2!apply: eq_bigr => ? _; apply: mulrC.
Qed.
Lemma mxvec_dotmul m n (A : 'M[R]_(m, n)) u v :
mxvec (u^T *m v) *m (mxvec A)^T = u *m A *m v^T.
Proof.
transitivity (\sum_i \sum_j (u 0 i * A i j *: row j v^T)).
apply/rowP=> i; rewrite {i}ord1 mxE (reindex _ (curry_mxvec_bij _ _)) /=.
rewrite pair_bigA summxE; apply: eq_bigr => [[i j]] /= _.
by rewrite !mxE !mxvecE mxE big_ord1 mxE mulrAC.
rewrite mulmx_sum_row exchange_big; apply: eq_bigr => j _ /=.
by rewrite mxE -scaler_suml.
Qed.
Lemma mul_mx_scalar m n a (A : 'M[R]_(m, n)) : A *m a%:M = a *: A.
Proof. by rewrite scalar_mxC mul_scalar_mx. Qed.
End ComMatrix.
Arguments lin_mulmx {R m n p} A.
Arguments lin_mul_row {R m n} u.
Arguments diag_mx_comm {R n}.
Arguments comm_mx_scalar {R n}.
Arguments comm_scalar_mx {R n}.
#[global] Hint Resolve comm_mx_scalar comm_scalar_mx : core.
Section MatrixAlgebra.
Variable R : pzRingType.
(* Diagonal matrices *)
#[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")]
Fact diag_mx_is_linear n : linear (@diag_mx R n). Proof. exact: linearP. Qed.
(* Scalar matrix *)
Lemma mulmxN m n p (A : 'M[R]_(m, n)) (B : 'M_(n, p)) : A *m (- B) = - (A *m B).
Proof. exact: raddfN. Qed.
Lemma mulNmx m n p (A : 'M[R]_(m, n)) (B : 'M_(n, p)) : - A *m B = - (A *m B).
Proof. exact: (raddfN (mulmxr _)). Qed.
Lemma mulmxBl m n p (A1 A2 : 'M[R]_(m, n)) (B : 'M_(n, p)) :
(A1 - A2) *m B = A1 *m B - A2 *m B.
Proof. exact: (raddfB (mulmxr _)). Qed.
Lemma mulmxBr m n p (A : 'M[R]_(m, n)) (B1 B2 : 'M_(n, p)) :
A *m (B1 - B2) = A *m B1 - A *m B2.
Proof. exact: raddfB. Qed.
(* Partial identity matrix (used in rank decomposition). *)
Definition copid_mx {n} r : 'M[R]_n := 1%:M - pid_mx r.
Lemma mul_copid_mx_pid m n r :
r <= m -> copid_mx r *m pid_mx r = 0 :> 'M_(m, n).
Proof. by move=> le_r_m; rewrite mulmxBl mul1mx pid_mx_id ?subrr. Qed.
Lemma mul_pid_mx_copid m n r :
r <= n -> pid_mx r *m copid_mx r = 0 :> 'M_(m, n).
Proof. by move=> le_r_n; rewrite mulmxBr mulmx1 pid_mx_id ?subrr. Qed.
Lemma copid_mx_id n r : r <= n -> copid_mx r *m copid_mx r = copid_mx r :> 'M_n.
Proof.
by move=> le_r_n; rewrite mulmxBl mul1mx mul_pid_mx_copid // oppr0 addr0.
Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")]
Fact mulmxr_is_linear m n p B : linear (@mulmxr R m n p B).
Proof. exact: linearP. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")]
Fact lin_mulmxr_is_linear m n p : linear (@lin_mulmxr R m n p).
Proof. exact: linearP. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `scalarP` instead")]
Fact mxtrace_is_scalar n : scalar (@mxtrace R n).
Proof. exact: scalarP. Qed.
(* Determinants and adjugates are defined here, but most of their properties *)
(* only hold for matrices over a commutative ring, so their theory is *)
(* deferred to that section. *)
(* The determinant, in one line with the Leibniz Formula *)
Definition determinant n (A : 'M_n) : R :=
\sum_(s : 'S_n) (-1) ^+ s * \prod_i A i (s i).
(* The cofactor of a matrix on the indexes i and j *)
Definition cofactor n A (i j : 'I_n) : R :=
(-1) ^+ (i + j) * determinant (row' i (col' j A)).
(* The adjugate matrix : defined as the transpose of the matrix of cofactors *)
Fact adjugate_key : unit. Proof. by []. Qed.
Definition adjugate n (A : 'M_n) := \matrix[adjugate_key]_(i, j) cofactor A j i.
End MatrixAlgebra.
Arguments copid_mx {R n}.
Prenex Implicits determinant cofactor adjugate.
Notation "'\det' A" := (determinant A) : ring_scope.
Notation "'\adj' A" := (adjugate A) : ring_scope.
(* Parametricity over the algebra structure. *)
Section MapRingMatrix.
Variables (aR rR : pzRingType) (f : {rmorphism aR -> rR}).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Section FixedSize.
Variables m n p : nat.
Implicit Type A : 'M[aR]_(m, n).
Lemma det_map_mx n' (A : 'M_n') : \det A^f = f (\det A).
Proof.
rewrite rmorph_sum //; apply: eq_bigr => s _.
rewrite rmorphM /= rmorph_sign rmorph_prod; congr (_ * _).
by apply: eq_bigr => i _; rewrite mxE.
Qed.
Lemma cofactor_map_mx (A : 'M_n) i j : cofactor A^f i j = f (cofactor A i j).
Proof. by rewrite rmorphM /= rmorph_sign -det_map_mx map_row' map_col'. Qed.
Lemma map_mx_adj (A : 'M_n) : (\adj A)^f = \adj A^f.
Proof. by apply/matrixP=> i j; rewrite !mxE cofactor_map_mx. Qed.
End FixedSize.
Lemma map_copid_mx n r : (copid_mx r)^f = copid_mx r :> 'M_n.
Proof. by rewrite map_mxB map_mx1 map_pid_mx. Qed.
End MapRingMatrix.
Section CommMx.
(***********************************************************************)
(************* Commutation property specialized to 'M[R]_n *************)
(***********************************************************************)
(* See comment on top of NzSemiRing section CommMx above. *)
(***********************************************************************)
Context {R : pzRingType} {n : nat}.
Implicit Types (f g p : 'M[R]_n) (fs : seq 'M[R]_n) (d : 'rV[R]_n) (I : Type).
Lemma comm_mxN f g : comm_mx f g -> comm_mx f (- g).
Proof. by rewrite /comm_mx mulmxN mulNmx => ->. Qed.
Lemma comm_mxN1 f : comm_mx f (- 1%:M). Proof. exact/comm_mxN/comm_mx1. Qed.
Lemma comm_mxB f g g' : comm_mx f g -> comm_mx f g' -> comm_mx f (g - g').
Proof. by move=> fg fg'; apply/comm_mxD => //; apply/comm_mxN. Qed.
End CommMx.
(* Lemmas for matrices with coefficients in a commutative ring *)
Section ComMatrix.
Variable R : comPzRingType.
#[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")]
Fact lin_mulmx_is_linear m n p : linear (@lin_mulmx R m n p).
Proof. exact: linearP. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `linearP` instead")]
Fact lin_mul_row_is_linear m n : linear (@lin_mul_row R m n).
Proof. exact: linearP. Qed.
(* The theory of determinants *)
Lemma determinant_multilinear n (A B C : 'M[R]_n) i0 b c :
row i0 A = b *: row i0 B + c *: row i0 C ->
row' i0 B = row' i0 A ->
row' i0 C = row' i0 A ->
\det A = b * \det B + c * \det C.
Proof.
rewrite -[_ + _](row_id 0); move/row_eq=> ABC.
move/row'_eq=> BA; move/row'_eq=> CA.
rewrite !big_distrr -big_split; apply: eq_bigr => s _ /=.
rewrite -!(mulrCA (_ ^+s)) -mulrDr; congr (_ * _).
rewrite !(bigD1 i0 (_ : predT i0)) //= {}ABC !mxE mulrDl !mulrA.
by congr (_ * _ + _ * _); apply: eq_bigr => i i0i; rewrite ?BA ?CA.
Qed.
Lemma determinant_alternate n (A : 'M[R]_n) i1 i2 :
i1 != i2 -> A i1 =1 A i2 -> \det A = 0.
Proof.
move=> neq_i12 eqA12; pose t := tperm i1 i2.
have oddMt s: (t * s)%g = ~~ s :> bool by rewrite odd_permM odd_tperm neq_i12.
rewrite [\det A](bigID (@odd_perm _)) /=.
apply: canLR (subrK _) _; rewrite add0r -sumrN.
rewrite (reindex_inj (mulgI t)); apply: eq_big => //= s.
rewrite oddMt => /negPf->; rewrite mulN1r mul1r; congr (- _).
rewrite (reindex_perm t); apply: eq_bigr => /= i _.
by rewrite permM tpermK /t; case: tpermP => // ->; rewrite eqA12.
Qed.
Lemma det_tr n (A : 'M[R]_n) : \det A^T = \det A.
Proof.
rewrite [\det A^T](reindex_inj invg_inj) /=.
apply: eq_bigr => s _ /=; rewrite !odd_permV (reindex_perm s) /=.
by congr (_ * _); apply: eq_bigr => i _; rewrite mxE permK.
Qed.
Lemma det_perm n (s : 'S_n) : \det (perm_mx s) = (-1) ^+ s :> R.
Proof.
rewrite [\det _](bigD1 s) //= big1 => [|i _]; last by rewrite /= !mxE eqxx.
rewrite mulr1 big1 ?addr0 => //= t Dst.
case: (pickP (fun i => s i != t i)) => [i ist | Est].
by rewrite (bigD1 i) // mulrCA /= !mxE (negPf ist) mul0r.
by case/eqP: Dst; apply/permP => i; move/eqP: (Est i).
Qed.
Lemma det1 n : \det (1%:M : 'M[R]_n) = 1.
Proof. by rewrite -perm_mx1 det_perm odd_perm1. Qed.
Lemma det_mx00 (A : 'M[R]_0) : \det A = 1.
Proof. by rewrite flatmx0 -(flatmx0 1%:M) det1. Qed.
Lemma detZ n a (A : 'M[R]_n) : \det (a *: A) = a ^+ n * \det A.
Proof.
rewrite big_distrr /=; apply: eq_bigr => s _; rewrite mulrCA; congr (_ * _).
rewrite -[n in a ^+ n]card_ord -prodr_const -big_split /=.
by apply: eq_bigr=> i _; rewrite mxE.
Qed.
Lemma det0 n' : \det (0 : 'M[R]_n'.+1) = 0.
Proof. by rewrite -(scale0r 0) detZ exprS !mul0r. Qed.
Lemma det_scalar n a : \det (a%:M : 'M[R]_n) = a ^+ n.
Proof. by rewrite -{1}(mulr1 a) -scale_scalar_mx detZ det1 mulr1. Qed.
Lemma det_scalar1 a : \det (a%:M : 'M[R]_1) = a.
Proof. exact: det_scalar. Qed.
Lemma det_mx11 (M : 'M[R]_1) : \det M = M 0 0.
Proof. by rewrite {1}[M]mx11_scalar det_scalar. Qed.
Lemma det_mulmx n (A B : 'M[R]_n) : \det (A *m B) = \det A * \det B.
Proof.
rewrite big_distrl /=.
pose F := ('I_n ^ n)%type; pose AB s i j := A i j * B j (s i).
transitivity (\sum_(f : F) \sum_(s : 'S_n) (-1) ^+ s * \prod_i AB s i (f i)).
rewrite exchange_big; apply: eq_bigr => /= s _; rewrite -big_distrr /=.
congr (_ * _); rewrite -(bigA_distr_bigA (AB s)) /=.
by apply: eq_bigr => x _; rewrite mxE.
rewrite (bigID (fun f : F => injectiveb f)) /= addrC big1 ?add0r => [|f Uf].
rewrite (reindex (@pval _)) /=; last first.
pose in_Sn := insubd (1%g : 'S_n).
by exists in_Sn => /= f Uf; first apply: val_inj; apply: insubdK.
apply: eq_big => /= [s | s _]; rewrite ?(valP s) // big_distrr /=.
rewrite (reindex_inj (mulgI s)); apply: eq_bigr => t _ /=.
rewrite big_split /= [in LHS]mulrA mulrCA mulrA mulrCA mulrA.
rewrite -signr_addb odd_permM !pvalE; congr (_ * _); symmetry.
by rewrite (reindex_perm s); apply: eq_bigr => i; rewrite permM.
transitivity (\det (\matrix_(i, j) B (f i) j) * \prod_i A i (f i)).
rewrite mulrC big_distrr /=; apply: eq_bigr => s _.
rewrite mulrCA big_split //=; congr (_ * (_ * _)).
by apply: eq_bigr => x _; rewrite mxE.
case/injectivePn: Uf => i1 [i2 Di12 Ef12].
by rewrite (determinant_alternate Di12) ?simp //= => j; rewrite !mxE Ef12.
Qed.
Lemma detM n' (A B : 'M[R]_n'.+1) : \det (A * B) = \det A * \det B.
Proof. exact: det_mulmx. Qed.
(* Laplace expansion lemma *)
Lemma expand_cofactor n (A : 'M[R]_n) i j :
cofactor A i j =
\sum_(s : 'S_n | s i == j) (-1) ^+ s * \prod_(k | i != k) A k (s k).
Proof.
case: n A i j => [|n] A i0 j0; first by case: i0.
rewrite (reindex (lift_perm i0 j0)); last first.
pose ulsf i (s : 'S_n.+1) k := odflt k (unlift (s i) (s (lift i k))).
have ulsfK i (s : 'S_n.+1) k: lift (s i) (ulsf i s k) = s (lift i k).
rewrite /ulsf; have:= neq_lift i k.
by rewrite -(can_eq (permK s)) => /unlift_some[] ? ? ->.
have inj_ulsf: injective (ulsf i0 _).
move=> s; apply: can_inj (ulsf (s i0) s^-1%g) _ => k'.
by rewrite {1}/ulsf ulsfK !permK liftK.
exists (fun s => perm (inj_ulsf s)) => [s _ | s].
by apply/permP=> k'; rewrite permE /ulsf lift_perm_lift lift_perm_id liftK.
move/(s _ =P _) => si0; apply/permP=> k.
case: (unliftP i0 k) => [k'|] ->; rewrite ?lift_perm_id //.
by rewrite lift_perm_lift -si0 permE ulsfK.
rewrite /cofactor big_distrr /=.
apply: eq_big => [s | s _]; first by rewrite lift_perm_id eqxx.
rewrite -signr_odd mulrA -signr_addb oddD -odd_lift_perm; congr (_ * _).
case: (pickP 'I_n) => [k0 _ | n0]; last first.
by rewrite !big1 // => [j /unlift_some[i] | i _]; have:= n0 i.
rewrite (reindex (lift i0)).
by apply: eq_big => [k | k _] /=; rewrite ?neq_lift // !mxE lift_perm_lift.
exists (fun k => odflt k0 (unlift i0 k)) => k; first by rewrite liftK.
by case/unlift_some=> k' -> ->.
Qed.
Lemma expand_det_row n (A : 'M[R]_n) i0 :
\det A = \sum_j A i0 j * cofactor A i0 j.
Proof.
rewrite /(\det A) (partition_big (fun s : 'S_n => s i0) predT) //=.
apply: eq_bigr => j0 _; rewrite expand_cofactor big_distrr /=.
apply: eq_bigr => s /eqP Dsi0.
rewrite mulrCA (bigID (pred1 i0)) /= big_pred1_eq Dsi0; congr (_ * (_ * _)).
by apply: eq_bigl => i; rewrite eq_sym.
Qed.
Lemma cofactor_tr n (A : 'M[R]_n) i j : cofactor A^T i j = cofactor A j i.
Proof.
rewrite /cofactor addnC; congr (_ * _).
rewrite -tr_row' -tr_col' det_tr; congr (\det _).
by apply/matrixP=> ? ?; rewrite !mxE.
Qed.
Lemma cofactorZ n a (A : 'M[R]_n) i j :
cofactor (a *: A) i j = a ^+ n.-1 * cofactor A i j.
Proof. by rewrite {1}/cofactor !linearZ detZ mulrCA mulrA. Qed.
Lemma expand_det_col n (A : 'M[R]_n) j0 :
\det A = \sum_i (A i j0 * cofactor A i j0).
Proof.
rewrite -det_tr (expand_det_row _ j0).
by under eq_bigr do rewrite cofactor_tr mxE.
Qed.
Lemma trmx_adj n (A : 'M[R]_n) : (\adj A)^T = \adj A^T.
Proof. by apply/matrixP=> i j; rewrite !mxE cofactor_tr. Qed.
Lemma adjZ n a (A : 'M[R]_n) : \adj (a *: A) = a^+n.-1 *: \adj A.
Proof. by apply/matrixP=> i j; rewrite !mxE cofactorZ. Qed.
(* Cramer Rule : adjugate on the left *)
Lemma mul_mx_adj n (A : 'M[R]_n) : A *m \adj A = (\det A)%:M.
Proof.
apply/matrixP=> i1 i2 /[!mxE]; have [->|Di] := eqVneq.
rewrite (expand_det_row _ i2) //=.
by apply: eq_bigr => j _; congr (_ * _); rewrite mxE.
pose B := \matrix_(i, j) (if i == i2 then A i1 j else A i j).
have EBi12: B i1 =1 B i2 by move=> j; rewrite /= !mxE eqxx (negPf Di).
rewrite -[_ *+ _](determinant_alternate Di EBi12) (expand_det_row _ i2).
apply: eq_bigr => j _; rewrite !mxE eqxx; congr (_ * (_ * _)).
apply: eq_bigr => s _; congr (_ * _); apply: eq_bigr => i _.
by rewrite !mxE eq_sym -if_neg neq_lift.
Qed.
(* Cramer rule : adjugate on the right *)
Lemma mul_adj_mx n (A : 'M[R]_n) : \adj A *m A = (\det A)%:M.
Proof.
by apply: trmx_inj; rewrite trmx_mul trmx_adj mul_mx_adj det_tr tr_scalar_mx.
Qed.
Lemma adj1 n : \adj (1%:M) = 1%:M :> 'M[R]_n.
Proof. by rewrite -{2}(det1 n) -mul_adj_mx mulmx1. Qed.
(* Left inverses are right inverses. *)
Lemma mulmx1C n (A B : 'M[R]_n) : A *m B = 1%:M -> B *m A = 1%:M.
Proof.
move=> AB1; pose A' := \det B *: \adj A.
suffices kA: A' *m A = 1%:M by rewrite -[B]mul1mx -kA -(mulmxA A') AB1 mulmx1.
by rewrite -scalemxAl mul_adj_mx scale_scalar_mx mulrC -det_mulmx AB1 det1.
Qed.
Lemma det_ublock n1 n2 Aul (Aur : 'M[R]_(n1, n2)) Adr :
\det (block_mx Aul Aur 0 Adr) = \det Aul * \det Adr.
Proof.
elim: n1 => [|n1 IHn1] in Aul Aur *.
have ->: Aul = 1%:M by apply/matrixP=> i [].
rewrite det1 mul1r; congr (\det _); apply/matrixP=> i j.
by do 2![rewrite !mxE; case: splitP => [[]|k] //=; move/val_inj=> <- {k}].
rewrite (expand_det_col _ (lshift n2 0)) big_split_ord /=.
rewrite addrC big1 1?simp => [|i _]; last by rewrite block_mxEdl mxE simp.
rewrite (expand_det_col _ 0) big_distrl /=; apply: eq_bigr=> i _.
rewrite block_mxEul -!mulrA; do 2!congr (_ * _).
by rewrite col'_col_mx !col'Kl raddf0 row'Ku row'_row_mx IHn1.
Qed.
Lemma det_lblock n1 n2 Aul (Adl : 'M[R]_(n2, n1)) Adr :
\det (block_mx Aul 0 Adl Adr) = \det Aul * \det Adr.
Proof. by rewrite -det_tr tr_block_mx trmx0 det_ublock !det_tr. Qed.
Lemma det_trig n (A : 'M[R]_n) : is_trig_mx A -> \det A = \prod_(i < n) A i i.
Proof.
elim/trigsqmx_ind => [|k x c B Bt IHB]; first by rewrite ?big_ord0 ?det_mx00.
rewrite det_lblock big_ord_recl det_mx11 IHB//; congr (_ * _).
by rewrite -[ord0](lshift0 _ 0) block_mxEul.
by apply: eq_bigr => i; rewrite -!rshift1 block_mxEdr.
Qed.
Lemma det_diag n (d : 'rV[R]_n) : \det (diag_mx d) = \prod_i d 0 i.
Proof. by rewrite det_trig//; apply: eq_bigr => i; rewrite !mxE eqxx. Qed.
End ComMatrix.
Arguments lin_mul_row {R m n} u.
Arguments lin_mulmx {R m n p} A.
HB.instance Definition _ (R : comNzSemiRingType) n :=
GRing.LSemiAlgebra_isSemiAlgebra.Build R 'M[R]_n.+1 (fun k => scalemxAr k).
HB.instance Definition _ (R : comNzRingType) (n' : nat) :=
GRing.LSemiAlgebra.on 'M[R]_n'.+1.
HB.instance Definition _ (R : finComNzRingType) (n' : nat) :=
[Finite of 'M[R]_n'.+1 by <:].
(* Only tall matrices have inverses. *)
Lemma mulmx1_min (R : comNzRingType) m n (A : 'M[R]_(m, n)) B :
A *m B = 1%:M -> m <= n.
Proof.
move=> AB1; rewrite leqNgt; apply/negP=> /subnKC; rewrite addSnnS.
move: (_ - _)%N => m' def_m; move: AB1; rewrite -{m}def_m in A B *.
rewrite -(vsubmxK A) -(hsubmxK B) mul_col_row scalar_mx_block.
case/eq_block_mx=> /mulmx1C BlAu1 AuBr0 _ => /eqP/idPn[].
by rewrite -[_ B]mul1mx -BlAu1 -mulmxA AuBr0 !mulmx0 eq_sym oner_neq0.
Qed.
(*****************************************************************************)
(********************** Matrix unit ring and inverse matrices ****************)
(*****************************************************************************)
Section MatrixInv.
Variables R : comUnitRingType.
Section Defs.
Variable n : nat.
Implicit Type A : 'M[R]_n.
Definition unitmx : pred 'M[R]_n := fun A => \det A \is a GRing.unit.
Definition invmx A := if A \in unitmx then (\det A)^-1 *: \adj A else A.
Lemma unitmxE A : (A \in unitmx) = (\det A \is a GRing.unit).
Proof. by []. Qed.
Lemma unitmx1 : 1%:M \in unitmx. Proof. by rewrite unitmxE det1 unitr1. Qed.
Lemma unitmx_perm s : perm_mx s \in unitmx.
Proof. by rewrite unitmxE det_perm unitrX ?unitrN ?unitr1. Qed.
Lemma unitmx_tr A : (A^T \in unitmx) = (A \in unitmx).
Proof. by rewrite unitmxE det_tr. Qed.
Lemma unitmxZ a A : a \is a GRing.unit -> (a *: A \in unitmx) = (A \in unitmx).
Proof. by move=> Ua; rewrite !unitmxE detZ unitrM unitrX. Qed.
Lemma invmx1 : invmx 1%:M = 1%:M.
Proof. by rewrite /invmx det1 invr1 scale1r adj1 if_same. Qed.
Lemma invmxZ a A : a *: A \in unitmx -> invmx (a *: A) = a^-1 *: invmx A.
Proof.
rewrite /invmx !unitmxE detZ unitrM => /andP[Ua U_A].
rewrite Ua U_A adjZ !scalerA invrM {U_A}//=.
case: (posnP n) A => [-> | n_gt0] A; first by rewrite flatmx0 [_ *: _]flatmx0.
rewrite unitrX_pos // in Ua; rewrite -[_ * _](mulrK Ua) mulrC -!mulrA.
by rewrite -exprSr prednK // !mulrA divrK ?unitrX.
Qed.
Lemma invmx_scalar a : invmx a%:M = a^-1%:M.
Proof.
case Ua: (a%:M \in unitmx).
by rewrite -scalemx1 in Ua *; rewrite invmxZ // invmx1 scalemx1.
rewrite /invmx Ua; have [->|n_gt0] := posnP n; first by rewrite ![_%:M]flatmx0.
by rewrite unitmxE det_scalar unitrX_pos // in Ua; rewrite invr_out ?Ua.
Qed.
Lemma mulVmx : {in unitmx, left_inverse 1%:M invmx mulmx}.
Proof.
by move=> A nsA; rewrite /invmx nsA -scalemxAl mul_adj_mx scale_scalar_mx mulVr.
Qed.
Lemma mulmxV : {in unitmx, right_inverse 1%:M invmx mulmx}.
Proof.
by move=> A nsA; rewrite /invmx nsA -scalemxAr mul_mx_adj scale_scalar_mx mulVr.
Qed.
Lemma mulKmx m : {in unitmx, @left_loop _ 'M_(n, m) invmx mulmx}.
Proof. by move=> A uA /= B; rewrite mulmxA mulVmx ?mul1mx. Qed.
Lemma mulKVmx m : {in unitmx, @rev_left_loop _ 'M_(n, m) invmx mulmx}.
Proof. by move=> A uA /= B; rewrite mulmxA mulmxV ?mul1mx. Qed.
Lemma mulmxK m : {in unitmx, @right_loop 'M_(m, n) _ invmx mulmx}.
Proof. by move=> A uA /= B; rewrite -mulmxA mulmxV ?mulmx1. Qed.
Lemma mulmxKV m : {in unitmx, @rev_right_loop 'M_(m, n) _ invmx mulmx}.
Proof. by move=> A uA /= B; rewrite -mulmxA mulVmx ?mulmx1. Qed.
Lemma det_inv A : \det (invmx A) = (\det A)^-1.
Proof.
case uA: (A \in unitmx); last by rewrite /invmx uA invr_out ?negbT.
by apply: (mulrI uA); rewrite -det_mulmx mulmxV ?divrr ?det1.
Qed.
Lemma unitmx_inv A : (invmx A \in unitmx) = (A \in unitmx).
Proof. by rewrite !unitmxE det_inv unitrV. Qed.
Lemma unitmx_mul A B : (A *m B \in unitmx) = (A \in unitmx) && (B \in unitmx).
Proof. by rewrite -unitrM -det_mulmx. Qed.
Lemma trmx_inv (A : 'M_n) : (invmx A)^T = invmx (A^T).
Proof. by rewrite (fun_if trmx) linearZ /= trmx_adj -unitmx_tr -det_tr. Qed.
Lemma invmxK : involutive invmx.
Proof.
move=> A; case uA : (A \in unitmx); last by rewrite /invmx !uA.
by apply: (can_inj (mulKVmx uA)); rewrite mulVmx // mulmxV ?unitmx_inv.
Qed.
Lemma mulmx1_unit A B : A *m B = 1%:M -> A \in unitmx /\ B \in unitmx.
Proof. by move=> AB1; apply/andP; rewrite -unitmx_mul AB1 unitmx1. Qed.
Lemma intro_unitmx A B : B *m A = 1%:M /\ A *m B = 1%:M -> unitmx A.
Proof. by case=> _ /mulmx1_unit[]. Qed.
Lemma invmx_out : {in [predC unitmx], invmx =1 id}.
Proof. by move=> A; rewrite inE /= /invmx -if_neg => ->. Qed.
End Defs.
Variable n' : nat.
Local Notation n := n'.+1.
HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'M[R]_n
(@mulVmx n) (@mulmxV n) (@intro_unitmx n) (@invmx_out n).
(* Lemmas requiring that the coefficients are in a unit ring *)
Lemma detV (A : 'M_n) : \det A^-1 = (\det A)^-1.
Proof. exact: det_inv. Qed.
Lemma unitr_trmx (A : 'M_n) : (A^T \is a GRing.unit) = (A \is a GRing.unit).
Proof. exact: unitmx_tr. Qed.
Lemma trmxV (A : 'M_n) : A^-1^T = (A^T)^-1.
Proof. exact: trmx_inv. Qed.
Lemma perm_mxV (s : 'S_n) : perm_mx s^-1 = (perm_mx s)^-1.
Proof.
rewrite -[_^-1]mul1r; apply: (canRL (mulmxK (unitmx_perm s))).
by rewrite -perm_mxM mulVg perm_mx1.
Qed.
Lemma is_perm_mxV (A : 'M_n) : is_perm_mx A^-1 = is_perm_mx A.
Proof.
apply/is_perm_mxP/is_perm_mxP=> [] [s defA]; exists s^-1%g.
by rewrite -(invrK A) defA perm_mxV.
by rewrite defA perm_mxV.
Qed.
End MatrixInv.
Prenex Implicits unitmx invmx invmxK.
Lemma block_diag_mx_unit (R : comUnitRingType) n1 n2
(Aul : 'M[R]_n1) (Adr : 'M[R]_n2) :
(block_mx Aul 0 0 Adr \in unitmx) = (Aul \in unitmx) && (Adr \in unitmx).
Proof. by rewrite !unitmxE det_ublock unitrM. Qed.
Lemma invmx_block_diag (R : comUnitRingType) n1 n2
(Aul : 'M[R]_n1) (Adr : 'M[R]_n2) :
block_mx Aul 0 0 Adr \in unitmx ->
invmx (block_mx Aul 0 0 Adr) = block_mx (invmx Aul) 0 0 (invmx Adr).
Proof.
move=> /[dup] Aunit; rewrite block_diag_mx_unit => /andP[Aul_unit Adr_unit].
rewrite -[LHS]mul1mx; apply: (canLR (mulmxK _)) => //.
rewrite [RHS](mulmx_block (invmx Aul)) !(mulmx0, mul0mx, add0r, addr0).
by rewrite !mulVmx// -?scalar_mx_block.
Qed.
HB.instance Definition _ (R : countComUnitRingType) (n' : nat) :=
[Countable of 'M[R]_n'.+1 by <:].
HB.instance Definition _ (n : nat) (R : finComUnitRingType) :=
[Finite of 'M[R]_n.+1 by <:].
(* Finite inversible matrices and the general linear group. *)
Section FinUnitMatrix.
Variable n : nat.
Definition GLtype (R : finComUnitRingType) := {unit 'M[R]_n.-1.+1}.
Coercion GLval R (u : GLtype R) : 'M[R]_n.-1.+1 :=
let: FinRing.Unit A _ := u in A.
End FinUnitMatrix.
Bind Scope group_scope with GLtype.
Arguments GLtype n%_N R%_type.
Arguments GLval {n%_N R} u%_g.
Notation "{ ''GL_' n [ R ] }" := (GLtype n R) : type_scope.
Notation "{ ''GL_' n ( p ) }" := {'GL_n['F_p]} : type_scope.
HB.instance Definition _ (n : nat) (R : finComUnitRingType) :=
[isSub of {'GL_n[R]} for GLval].
Section GL_unit.
Variables (n : nat) (R : finComUnitRingType).
HB.instance Definition _ := [Finite of {'GL_n[R]} by <:].
HB.instance Definition _ := FinGroup.on {'GL_n[R]}.
Definition GLgroup := [set: {'GL_n[R]}].
Canonical GLgroup_group := Eval hnf in [group of GLgroup].
Implicit Types u v : {'GL_n[R]}.
Lemma GL_1E : GLval 1 = 1. Proof. by []. Qed.
Lemma GL_VE u : GLval u^-1 = (GLval u)^-1. Proof. by []. Qed.
Lemma GL_VxE u : GLval u^-1 = invmx u. Proof. by []. Qed.
Lemma GL_ME u v : GLval (u * v) = GLval u * GLval v. Proof. by []. Qed.
Lemma GL_MxE u v : GLval (u * v) = u *m v. Proof. by []. Qed.
Lemma GL_unit u : GLval u \is a GRing.unit. Proof. exact: valP. Qed.
Lemma GL_unitmx u : val u \in unitmx. Proof. exact: GL_unit. Qed.
Lemma GL_det u : \det u != 0.
Proof.
by apply: contraL (GL_unitmx u); rewrite unitmxE => /eqP->; rewrite unitr0.
Qed.
End GL_unit.
Arguments GLgroup n%_N R%_type.
Arguments GLgroup_group n%_N R%_type.
Notation "''GL_' n [ R ]" := (GLgroup n R)
(n at level 2, format "''GL_' n [ R ]") : group_scope.
Notation "''GL_' n ( p )" := 'GL_n['F_p]
(p at level 10, format "''GL_' n ( p )") : group_scope.
Notation "''GL_' n [ R ]" := (GLgroup_group n R) : Group_scope.
Notation "''GL_' n ( p )" := (GLgroup_group n 'F_p) : Group_scope.
(*****************************************************************************)
(********************** Matrices over a domain *******************************)
(*****************************************************************************)
Section MatrixDomain.
Variable R : idomainType.
Lemma scalemx_eq0 m n a (A : 'M[R]_(m, n)) :
(a *: A == 0) = (a == 0) || (A == 0).
Proof.
case nz_a: (a == 0) / eqP => [-> | _]; first by rewrite scale0r eqxx.
apply/eqP/eqP=> [aA0 | ->]; last exact: scaler0.
apply/matrixP=> i j; apply/eqP; move/matrixP/(_ i j)/eqP: aA0.
by rewrite !mxE mulf_eq0 nz_a.
Qed.
Lemma scalemx_inj m n a :
a != 0 -> injective ( *:%R a : 'M[R]_(m, n) -> 'M[R]_(m, n)).
Proof.
move=> nz_a A B eq_aAB; apply: contraNeq nz_a.
rewrite -[A == B]subr_eq0 -[a == 0]orbF => /negPf<-.
by rewrite -scalemx_eq0 linearB subr_eq0 /= eq_aAB.
Qed.
Lemma det0P n (A : 'M[R]_n) :
reflect (exists2 v : 'rV[R]_n, v != 0 & v *m A = 0) (\det A == 0).
Proof.
apply: (iffP eqP) => [detA0 | [v n0v vA0]]; last first.
apply: contraNeq n0v => nz_detA; rewrite -(inj_eq (scalemx_inj nz_detA)).
by rewrite scaler0 -mul_mx_scalar -mul_mx_adj mulmxA vA0 mul0mx.
elim: n => [|n IHn] in A detA0 *.
by case/idP: (oner_eq0 R); rewrite -detA0 [A]thinmx0 -(thinmx0 1%:M) det1.
have [{detA0}A'0 | nzA'] := eqVneq (row 0 (\adj A)) 0; last first.
exists (row 0 (\adj A)) => //; rewrite rowE -mulmxA mul_adj_mx detA0.
by rewrite mul_mx_scalar scale0r.
pose A' := col' 0 A; pose vA := col 0 A.
have defA: A = row_mx vA A'.
apply/matrixP=> i j /[!mxE].
by case: split_ordP => j' -> /[!(mxE, ord1)]; congr (A i _); apply: val_inj.
have{IHn} w_ j : exists w : 'rV_n.+1, [/\ w != 0, w 0 j = 0 & w *m A' = 0].
have [|wj nzwj wjA'0] := IHn (row' j A').
by apply/eqP; move/rowP/(_ j)/eqP: A'0; rewrite !mxE mulf_eq0 signr_eq0.
exists (\row_k oapp (wj 0) 0 (unlift j k)).
rewrite !mxE unlift_none -wjA'0; split=> //.
apply: contraNneq nzwj => w0; apply/eqP/rowP=> k'.
by move/rowP/(_ (lift j k')): w0; rewrite !mxE liftK.
apply/rowP=> k; rewrite !mxE (bigD1_ord j) //= mxE unlift_none mul0r add0r.
by apply: eq_big => //= k'; rewrite !mxE/= liftK.
have [w0 [/rV0Pn[j nz_w0j] w00_0 w0A']] := w_ 0; pose a0 := (w0 *m vA) 0 0.
have{w_} [wj [nz_wj wj0_0 wjA']] := w_ j; pose aj := (wj *m vA) 0 0.
have [aj0 | nz_aj] := eqVneq aj 0.
exists wj => //; rewrite defA (@mul_mx_row _ _ _ 1) [_ *m _]mx11_scalar -/aj.
by rewrite aj0 raddf0 wjA' row_mx0.
exists (aj *: w0 - a0 *: wj).
apply: contraNneq nz_aj; move/rowP/(_ j)/eqP; rewrite !mxE wj0_0 mulr0 subr0.
by rewrite mulf_eq0 (negPf nz_w0j) orbF.
rewrite defA (@mul_mx_row _ _ _ 1) !mulmxBl -!scalemxAl w0A' wjA' !linear0.
by rewrite -mul_mx_scalar -mul_scalar_mx -!mx11_scalar subrr addr0 row_mx0.
Qed.
End MatrixDomain.
Arguments det0P {R n A}.
(* Parametricity at the field level (mx_is_scalar, unit and inverse are only *)
(* mapped at this level). *)
Section MapFieldMatrix.
Variables (aF : fieldType) (rF : comUnitRingType) (f : {rmorphism aF -> rF}).
Local Notation "A ^f" := (map_mx f A) : ring_scope.
Lemma map_mx_inj {m n} : injective (map_mx f : 'M_(m, n) -> 'M_(m, n)).
Proof.
move=> A B eq_AB; apply/matrixP=> i j.
by move/matrixP/(_ i j): eq_AB => /[!mxE]; apply: fmorph_inj.
Qed.
Lemma map_mx_is_scalar n (A : 'M_n) : is_scalar_mx A^f = is_scalar_mx A.
Proof.
rewrite /is_scalar_mx; case: (insub _) => // i.
by rewrite mxE -map_scalar_mx inj_eq //; apply: map_mx_inj.
Qed.
Lemma map_unitmx n (A : 'M_n) : (A^f \in unitmx) = (A \in unitmx).
Proof. by rewrite unitmxE det_map_mx // fmorph_unit // -unitfE. Qed.
Lemma map_mx_unit n' (A : 'M_n'.+1) :
(A^f \is a GRing.unit) = (A \is a GRing.unit).
Proof. exact: map_unitmx. Qed.
Lemma map_invmx n (A : 'M_n) : (invmx A)^f = invmx A^f.
Proof.
rewrite /invmx map_unitmx (fun_if (map_mx f)).
by rewrite map_mxZ map_mx_adj det_map_mx fmorphV.
Qed.
Lemma map_mx_inv n' (A : 'M_n'.+1) : A^-1^f = A^f^-1.
Proof. exact: map_invmx. Qed.
Lemma map_mx_eq0 m n (A : 'M_(m, n)) : (A^f == 0) = (A == 0).
Proof. by rewrite -(inj_eq map_mx_inj) raddf0. Qed.
End MapFieldMatrix.
Arguments map_mx_inj {aF rF f m n} [A1 A2] eqA12f : rename.
(*****************************************************************************)
(***************************** LUP decomposition *****************************)
(*****************************************************************************)
Section CormenLUP.
Variable F : fieldType.
(* Decomposition of the matrix A to P A = L U with *)
(* - P a permutation matrix *)
(* - L a unipotent lower triangular matrix *)
(* - U an upper triangular matrix *)
Fixpoint cormen_lup {n} :=
match n return let M := 'M[F]_n.+1 in M -> M * M * M with
| 0 => fun A => (1, 1, A)
| _.+1 => fun A =>
let k := odflt 0 [pick k | A k 0 != 0] in
let A1 : 'M_(1 + _) := xrow 0 k A in
let P1 : 'M_(1 + _) := tperm_mx 0 k in
let Schur := ((A k 0)^-1 *: dlsubmx A1) *m ursubmx A1 in
let: (P2, L2, U2) := cormen_lup (drsubmx A1 - Schur) in
let P := block_mx 1 0 0 P2 *m P1 in
let L := block_mx 1 0 ((A k 0)^-1 *: (P2 *m dlsubmx A1)) L2 in
let U := block_mx (ulsubmx A1) (ursubmx A1) 0 U2 in
(P, L, U)
end.
Lemma cormen_lup_perm n (A : 'M_n.+1) : is_perm_mx (cormen_lup A).1.1.
Proof.
elim: n => [|n IHn] /= in A *; first exact: is_perm_mx1.
set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/=.
rewrite (is_perm_mxMr _ (perm_mx_is_perm _ _)).
by case/is_perm_mxP => s ->; apply: lift0_mx_is_perm.
Qed.
Lemma cormen_lup_correct n (A : 'M_n.+1) :
let: (P, L, U) := cormen_lup A in P * A = L * U.
Proof.
elim: n => [|n IHn] /= in A *; first by rewrite !mul1r.
set k := odflt _ _; set A1 : 'M_(1 + _) := xrow _ _ _.
set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P' L' U']] /= IHn.
rewrite -mulrA -!mulmxE -xrowE -/A1 /= -[n.+2]/(1 + n.+1)%N -{1}(submxK A1).
rewrite !mulmx_block !mul0mx !mulmx0 !add0r !addr0 !mul1mx -{L' U'}[L' *m _]IHn.
rewrite -scalemxAl !scalemxAr -!mulmxA addrC -mulrDr {A'}subrK.
congr (block_mx _ _ (_ *m _) _).
rewrite [_ *: _]mx11_scalar !mxE lshift0 tpermL {}/A1 {}/k.
case: pickP => /= [k nzAk0 | no_k]; first by rewrite mulVf ?mulmx1.
rewrite (_ : dlsubmx _ = 0) ?mul0mx //; apply/colP=> i.
by rewrite !mxE lshift0 (elimNf eqP (no_k _)).
Qed.
Lemma cormen_lup_detL n (A : 'M_n.+1) : \det (cormen_lup A).1.2 = 1.
Proof.
elim: n => [|n IHn] /= in A *; first by rewrite det1.
set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= detL.
by rewrite (@det_lblock _ 1) det1 mul1r.
Qed.
Lemma cormen_lup_lower n A (i j : 'I_n.+1) :
i <= j -> (cormen_lup A).1.2 i j = (i == j)%:R.
Proof.
elim: n => [|n IHn] /= in A i j *; first by rewrite [i]ord1 [j]ord1 mxE.
set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= Ll.
rewrite !mxE split1; case: unliftP => [i'|] -> /=; rewrite !mxE split1.
by case: unliftP => [j'|] -> //; apply: Ll.
by case: unliftP => [j'|] ->; rewrite /= mxE.
Qed.
Lemma cormen_lup_upper n A (i j : 'I_n.+1) :
j < i -> (cormen_lup A).2 i j = 0 :> F.
Proof.
elim: n => [|n IHn] /= in A i j *; first by rewrite [i]ord1.
set A' := _ - _; move/(_ A'): IHn; case: cormen_lup => [[P L U]] {A'}/= Uu.
rewrite !mxE split1; case: unliftP => [i'|] -> //=; rewrite !mxE split1.
by case: unliftP => [j'|] ->; [apply: Uu | rewrite /= mxE].
Qed.
End CormenLUP.
Section mxOver.
Section mxOverType.
Context {m n : nat} {T : Type}.
Implicit Types (S : {pred T}).
Definition mxOver_pred (S : {pred T}) :=
fun M : 'M[T]_(m, n) => [forall i, [forall j, M i j \in S]].
Arguments mxOver_pred _ _ /.
Definition mxOver (S : {pred T}) := [qualify a M | mxOver_pred S M].
Lemma mxOverP {S : {pred T}} {M : 'M[T]__} :
reflect (forall i j, M i j \in S) (M \is a mxOver S).
Proof. exact/'forall_forallP. Qed.
Lemma mxOverS (S1 S2 : {pred T}) :
{subset S1 <= S2} -> {subset mxOver S1 <= mxOver S2}.
Proof. by move=> sS12 M /mxOverP S1M; apply/mxOverP=> i j; apply/sS12/S1M. Qed.
Lemma mxOver_const c S : c \in S -> const_mx c \is a mxOver S.
Proof. by move=> cS; apply/mxOverP => i j; rewrite !mxE. Qed.
Lemma mxOver_constE c S : (m > 0)%N -> (n > 0)%N ->
(const_mx c \is a mxOver S) = (c \in S).
Proof.
move=> m_gt0 n_gt0; apply/idP/idP; last exact: mxOver_const.
by move=> /mxOverP /(_ (Ordinal m_gt0) (Ordinal n_gt0)); rewrite mxE.
Qed.
End mxOverType.
Lemma thinmxOver {n : nat} {T : Type} (M : 'M[T]_(n, 0)) S : M \is a mxOver S.
Proof. by apply/mxOverP => ? []. Qed.
Lemma flatmxOver {n : nat} {T : Type} (M : 'M[T]_(0, n)) S : M \is a mxOver S.
Proof. by apply/mxOverP => - []. Qed.
Section mxOverZmodule.
Context {M : zmodType} {m n : nat}.
Implicit Types (S : {pred M}).
Lemma mxOver0 S : 0 \in S -> 0 \is a @mxOver m n _ S.
Proof. exact: mxOver_const. Qed.
Section mxOverAdd.
Variable addS : addrClosed M.
Fact mxOver_add_subproof : addr_closed (@mxOver m n _ addS).
Proof.
split=> [|p q Sp Sq]; first by rewrite mxOver0 // ?rpred0.
by apply/mxOverP=> i j; rewrite mxE rpredD // !(mxOverP _).
Qed.
HB.instance Definition _ :=
GRing.isAddClosed.Build 'M[M]_(m, n) (mxOver_pred addS)
mxOver_add_subproof.
End mxOverAdd.
Section mxOverOpp.
Variable oppS : opprClosed M.
Fact mxOver_opp_subproof : oppr_closed (@mxOver m n _ oppS).
Proof. by move=> A /mxOverP SA; apply/mxOverP=> i j; rewrite mxE rpredN. Qed.
HB.instance Definition _ :=
GRing.isOppClosed.Build 'M[M]_(m, n) (mxOver_pred oppS)
mxOver_opp_subproof.
End mxOverOpp.
HB.instance Definition _ (zmodS : zmodClosed M) :=
GRing.OppClosed.on (mxOver_pred zmodS).
End mxOverZmodule.
Section mxOverRing.
Context {R : pzSemiRingType} {m n : nat}.
Lemma mxOver_scalar S c : 0 \in S -> c \in S -> c%:M \is a @mxOver n n R S.
Proof. by move=> S0 cS; apply/mxOverP => i j; rewrite !mxE; case: eqP. Qed.
Lemma mxOver_scalarE S c : (n > 0)%N ->
(c%:M \is a @mxOver n n R S) = ((n > 1) ==> (0 \in S)) && (c \in S).
Proof.
case: n => [|[|k]]//= _.
by apply/mxOverP/idP => [/(_ ord0 ord0)|cij i j]; rewrite ?mxE ?ord1.
apply/mxOverP/andP => [cij|[S0 cij] i j]; last by rewrite !mxE; case: eqP.
by split; [have := cij 0 1|have := cij 0 0]; rewrite !mxE.
Qed.
Lemma mxOverZ (S : mulrClosed R) :
{in S & mxOver S, forall a : R, forall v : 'M[R]_(m, n),
a *: v \is a mxOver S}.
Proof.
by move=> a v aS /mxOverP vS; apply/mxOverP => i j; rewrite !mxE rpredM.
Qed.
Lemma mxOver_diag (S : {pred R}) k (D : 'rV[R]_k) :
0 \in S -> D \is a mxOver S -> diag_mx D \is a mxOver S.
Proof.
move=> S0 DS; apply/mxOverP => i j; rewrite !mxE.
by case: eqP => //; rewrite (mxOverP DS).
Qed.
Lemma mxOver_diagE (S : {pred R}) k (D : 'rV[R]_k) : k > 0 ->
(diag_mx D \is a mxOver S) = ((k > 1) ==> (0 \in S)) && (D \is a mxOver S).
Proof.
case: k => [|[|k]]//= in D * => _.
by rewrite [diag_mx _]mx11_scalar [D in RHS]mx11_scalar !mxE.
apply/idP/andP => [/mxOverP DS|[S0 DS]]; last exact: mxOver_diag.
split; first by have /[!mxE] := DS 0 1.
by apply/mxOverP => i j; have := DS j j; rewrite ord1 !mxE eqxx.
Qed.
Lemma mxOverM (S : semiringClosed R) p q r : {in mxOver S & mxOver S,
forall u : 'M[R]_(p, q), forall v : 'M[R]_(q, r), u *m v \is a mxOver S}.
Proof.
move=> M N /mxOverP MS /mxOverP NS; apply/mxOverP => i j.
by rewrite !mxE rpred_sum // => k _; rewrite rpredM.
Qed.
End mxOverRing.
Section mxRingOver.
Context {R : pzSemiRingType} {n : nat} (S : semiringClosed R).
Fact mxOver_mul_subproof : mulr_closed (@mxOver n n _ S).
Proof. by split; rewrite ?mxOver_scalar ?rpred0 ?rpred1//; apply: mxOverM. Qed.
HB.instance Definition _ := GRing.isMulClosed.Build _ (mxOver_pred S)
mxOver_mul_subproof.
End mxRingOver.
HB.instance Definition _ {R : pzRingType} {n : nat} (S : subringClosed R) :=
GRing.MulClosed.on (@mxOver_pred n n _ S).
End mxOver.
Section BlockMatrix.
Import tagnat.
Context {T : Type} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}.
Notation sp := (\sum_i p_ i)%N.
Notation sq := (\sum_i q_ i)%N.
Implicit Type (s : 'I_sp) (t : 'I_sq).
Definition mxblock (B_ : forall i j, 'M[T]_(p_ i, q_ j)) :=
\matrix_(j, k) B_ (sig1 j) (sig1 k) (sig2 j) (sig2 k).
Local Notation "\mxblock_ ( i , j ) E" := (mxblock (fun i j => E)) : ring_scope.
Definition mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) :=
\matrix_(j, k) B_ (sig1 k) j (sig2 k).
Local Notation "\mxrow_ i E" := (mxrow (fun i => E)) : ring_scope.
Definition mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) :=
\matrix_(j, k) B_ (sig1 j) (sig2 j) k.
Local Notation "\mxcol_ i E" := (mxcol (fun i => E)) : ring_scope.
Definition submxblock (A : 'M[T]_(sp, sq)) i j := mxsub (Rank i) (Rank j) A.
Definition submxrow m (A : 'M[T]_(m, sq)) j := colsub (Rank j) A.
Definition submxcol n (A : 'M[T]_(sp, n)) i := rowsub (Rank i) A.
Lemma mxblockEh B_ : \mxblock_(i, j) B_ i j = \mxrow_j \mxcol_i B_ i j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma mxblockEv B_ : \mxblock_(i, j) B_ i j = \mxcol_i \mxrow_j B_ i j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma submxblockEh A i j : submxblock A i j = submxcol (submxrow A j) i.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma submxblockEv A i j : submxblock A i j = submxrow (submxcol A i) j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma mxblockK B_ i j : submxblock (\mxblock_(i, j) B_ i j) i j = B_ i j.
Proof.
apply/matrixP => k l; rewrite !mxE !Rank2K.
by do !case: _ / esym; rewrite !cast_ord_id.
Qed.
Lemma mxrowK m B_ j : @submxrow m (\mxrow_j B_ j) j = B_ j.
Proof.
apply/matrixP => k l; rewrite !mxE !Rank2K.
by do !case: _ / esym; rewrite !cast_ord_id.
Qed.
Lemma mxcolK n B_ i : @submxcol n (\mxcol_i B_ i) i = B_ i.
Proof.
apply/matrixP => k l; rewrite !mxE !Rank2K.
by do !case: _ / esym; rewrite !cast_ord_id.
Qed.
Lemma submxrow_matrix B_ j :
submxrow (\mxblock_(i, j) B_ i j) j = \mxcol_i B_ i j.
Proof. by rewrite mxblockEh mxrowK. Qed.
Lemma submxcol_matrix B_ i :
submxcol (\mxblock_(i, j) B_ i j) i = \mxrow_j B_ i j.
Proof. by rewrite mxblockEv mxcolK. Qed.
Lemma submxblockK A : \mxblock_(i, j) (submxblock A i j) = A.
Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed.
Lemma submxrowK m (A : 'M[T]_(m, sq)) : \mxrow_j (submxrow A j) = A.
Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed.
Lemma submxcolK n (A : 'M[T]_(sp, n)) : \mxcol_i (submxcol A i) = A.
Proof. by apply/matrixP => k l; rewrite !mxE !sig2K. Qed.
Lemma mxblockP A B :
(forall i j, submxblock A i j = submxblock B i j) <-> A = B.
Proof.
split=> [eqAB|->//]; apply/matrixP=> s t;
have /matrixP := eqAB (sig1 s) (sig1 t).
by move=> /(_ (sig2 s) (sig2 t)); rewrite !mxE !sig2K.
Qed.
Lemma mxrowP m (A B : 'M_(m, sq)) :
(forall j, submxrow A j = submxrow B j) <-> A = B.
Proof.
split=> [eqAB|->//]; apply/matrixP=> i t; have /matrixP := eqAB (sig1 t).
by move=> /(_ i (sig2 t)); rewrite !mxE !sig2K.
Qed.
Lemma mxcolP n (A B : 'M_(sp, n)) :
(forall i, submxcol A i = submxcol B i) <-> A = B.
Proof.
split=> [eqAB|->//]; apply/matrixP=> s j; have /matrixP := eqAB (sig1 s).
by move=> /(_ (sig2 s) j); rewrite !mxE !sig2K.
Qed.
Lemma eq_mxblockP A_ B_ :
(forall i j, A_ i j = B_ i j) <->
(\mxblock_(i, j) A_ i j = \mxblock_(i, j) B_ i j).
Proof.
split; first by move=> e; apply/mxblockP => i j; rewrite !mxblockK.
by move=> + i j => /mxblockP/(_ i j); rewrite !mxblockK.
Qed.
Lemma eq_mxblock A_ B_ :
(forall i j, A_ i j = B_ i j) ->
(\mxblock_(i, j) A_ i j = \mxblock_(i, j) B_ i j).
Proof. by move=> /eq_mxblockP. Qed.
Lemma eq_mxrowP m (A_ B_ : forall j, 'M[T]_(m, q_ j)) :
(forall j, A_ j = B_ j) <-> (\mxrow_j A_ j = \mxrow_j B_ j).
Proof.
split; first by move=> e; apply/mxrowP => j; rewrite !mxrowK.
by move=> + j => /mxrowP/(_ j); rewrite !mxrowK.
Qed.
Lemma eq_mxrow m (A_ B_ : forall j, 'M[T]_(m, q_ j)) :
(forall j, A_ j = B_ j) -> (\mxrow_j A_ j = \mxrow_j B_ j).
Proof. by move=> /eq_mxrowP. Qed.
Lemma eq_mxcolP n (A_ B_ : forall i, 'M[T]_(p_ i, n)) :
(forall i, A_ i = B_ i) <-> (\mxcol_i A_ i = \mxcol_i B_ i).
Proof.
split; first by move=> e; apply/mxcolP => i; rewrite !mxcolK.
by move=> + i => /mxcolP/(_ i); rewrite !mxcolK.
Qed.
Lemma eq_mxcol n (A_ B_ : forall i, 'M[T]_(p_ i, n)) :
(forall i, A_ i = B_ i) -> (\mxcol_i A_ i = \mxcol_i B_ i).
Proof. by move=> /eq_mxcolP. Qed.
Lemma row_mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) i :
row i (\mxrow_j B_ j) = \mxrow_j (row i (B_ j)).
Proof. by apply/rowP => l; rewrite !mxE. Qed.
Lemma col_mxrow m (B_ : forall j, 'M[T]_(m, q_ j)) j :
col j (\mxrow_j B_ j) = col (sig2 j) (B_ (sig1 j)).
Proof. by apply/colP => l; rewrite !mxE. Qed.
Lemma row_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) i :
row i (\mxcol_i B_ i) = row (sig2 i) (B_ (sig1 i)).
Proof. by apply/rowP => l; rewrite !mxE. Qed.
Lemma col_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) j :
col j (\mxcol_i B_ i) = \mxcol_i (col j (B_ i)).
Proof. by apply/colP => l; rewrite !mxE. Qed.
Lemma row_mxblock B_ i :
row i (\mxblock_(i, j) B_ i j) = \mxrow_j row (sig2 i) (B_ (sig1 i) j).
Proof. by apply/rowP => l; rewrite !mxE. Qed.
Lemma col_mxblock B_ j :
col j (\mxblock_(i, j) B_ i j) = \mxcol_i col (sig2 j) (B_ i (sig1 j)).
Proof. by apply/colP => l; rewrite !mxE. Qed.
End BlockMatrix.
Notation "\mxblock_ ( i < m , j < n ) E" :=
(mxblock (fun (i : 'I_m) (j : 'I_ n) => E)) (only parsing) : ring_scope.
Notation "\mxblock_ ( i , j < n ) E" :=
(\mxblock_(i < n, j < n) E) (only parsing) : ring_scope.
Notation "\mxblock_ ( i , j ) E" := (\mxblock_(i < _, j < _) E) : ring_scope.
Notation "\mxrow_ ( j < m ) E" := (mxrow (fun (j : 'I_m) => E))
(only parsing) : ring_scope.
Notation "\mxrow_ j E" := (\mxrow_(j < _) E) : ring_scope.
Notation "\mxcol_ ( i < m ) E" := (mxcol (fun (i : 'I_m) => E))
(only parsing) : ring_scope.
Notation "\mxcol_ i E" := (\mxcol_(i < _) E) : ring_scope.
Lemma tr_mxblock {T : Type} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}
(B_ : forall i j, 'M[T]_(p_ i, q_ j)) :
(\mxblock_(i, j) B_ i j)^T = \mxblock_(i, j) (B_ j i)^T.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Section SquareBlockMatrix.
Context {T : Type} {p : nat} {p_ : 'I_p -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma tr_mxrow n (B_ : forall j, 'M[T]_(n, p_ j)) :
(\mxrow_j B_ j)^T = \mxcol_i (B_ i)^T.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma tr_mxcol n (B_ : forall i, 'M[T]_(p_ i, n)) :
(\mxcol_i B_ i)^T = \mxrow_i (B_ i)^T.
Proof. by apply/matrixP => i j; rewrite !mxE. Qed.
Lemma tr_submxblock (A : 'M[T]_sp) i j :
(submxblock A i j)^T = (submxblock A^T j i).
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma tr_submxrow n (A : 'M[T]_(n, sp)) j :
(submxrow A j)^T = (submxcol A^T j).
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma tr_submxcol n (A : 'M[T]_(sp, n)) i :
(submxcol A i)^T = (submxrow A^T i).
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
End SquareBlockMatrix.
Section BlockRowRecL.
Import tagnat.
Context {T : Type} {m : nat} {p_ : 'I_m.+1 -> nat}.
Notation sp := (\sum_i p_ i)%N.
Lemma mxsize_recl : (p_ ord0 + \sum_i p_ (lift ord0 i) = (\sum_i p_ i))%N.
Proof. by rewrite big_ord_recl. Qed.
Lemma mxrow_recl n (B_ : forall j, 'M[T]_(n, p_ j)) :
\mxrow_j B_ j = castmx (erefl, mxsize_recl)
(row_mx (B_ 0) (\mxrow_j B_ (lift ord0 j))).
Proof.
apply/mxrowP => i; rewrite mxrowK.
apply/matrixP => j k; rewrite !(castmxE, mxE)/=.
case: splitP => l /=; do [
rewrite [LHS]RankEsum big_mkcond big_ord_recl -big_mkcond/=;
rewrite /bump/= -addnA cast_ord_id;
under eq_bigl do rewrite add1n -ltn_predRL/=].
case: posnP => i0; last first.
by move=> lE; have := ltn_ord l; rewrite /= -lE -ltn_subRL subnn.
by rewrite (@val_inj _ _ _ i 0 i0) big_pred0_eq in k * => /val_inj->.
case: posnP => i0.
rewrite (@val_inj _ _ _ i 0 i0) big_pred0_eq in k l * => kE.
by have := ltn_ord k; rewrite /= [val k]kE -ltn_subRL subnn.
have i_lt : i.-1 < m by rewrite -subn1 ltn_subLR.
set i' := lift ord0 (Ordinal i_lt).
have ii' : i = i' by apply/val_inj; rewrite /=/bump/= add1n prednK.
have k_lt : k < p_ i' by rewrite -ii'.
move=> /addnI; rewrite eqRank => /val_inj/= /[dup] kl<-; rewrite mxE.
rewrite Rank2K//; case: _ / esym; rewrite cast_ord_id/=.
rewrite -/i'; set j' := Ordinal _; have : k = j' :> nat by [].
by move: j'; rewrite -ii' => j' /val_inj->.
Qed.
End BlockRowRecL.
Lemma mxcol_recu {T : Type} {p : nat} {p_ : 'I_p.+1 -> nat} m
(B_ : forall j, 'M[T]_(p_ j, m)) :
\mxcol_j B_ j = castmx (mxsize_recl, erefl)
(col_mx (B_ 0) (\mxcol_j B_ (lift ord0 j))).
Proof.
by apply: trmx_inj; rewrite trmx_cast tr_col_mx !tr_mxcol mxrow_recl.
Qed.
Section BlockMatrixRec.
Local Notation e := (mxsize_recl, mxsize_recl).
Local Notation l0 := (lift ord0).
Context {T : Type}.
Lemma mxblock_recu {p q : nat} {p_ : 'I_p.+1 -> nat} {q_ : 'I_q -> nat}
(B_ : forall i j, 'M[T]_(p_ i, q_ j)) :
\mxblock_(i, j) B_ i j = castmx (mxsize_recl, erefl) (col_mx
(\mxrow_j B_ ord0 j)
(\mxblock_(i, j) B_ (l0 i) j)).
Proof. by rewrite !mxblockEv mxcol_recu. Qed.
Lemma mxblock_recl {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q.+1 -> nat}
(B_ : forall i j, 'M[T]_(p_ i, q_ j)) :
\mxblock_(i, j) B_ i j = castmx (erefl, mxsize_recl)
(row_mx (\mxcol_i B_ i ord0) (\mxblock_(i, j) B_ i (l0 j))).
Proof. by rewrite !mxblockEh mxrow_recl. Qed.
Lemma mxblock_recul {p q : nat} {p_ : 'I_p.+1 -> nat} {q_ : 'I_q.+1 -> nat}
(B_ : forall i j, 'M[T]_(p_ i, q_ j)) :
\mxblock_(i, j) B_ i j = castmx e (block_mx
(B_ 0 0) (\mxrow_j B_ ord0 (l0 j))
(\mxcol_i B_ (l0 i) ord0) (\mxblock_(i, j) B_ (l0 i) (l0 j))).
Proof.
rewrite mxblock_recl mxcol_recu mxblock_recu -cast_row_mx -block_mxEh.
by rewrite castmx_comp; apply: eq_castmx.
Qed.
Lemma mxrowEblock {q : nat} {q_ : 'I_q -> nat} m
(R_ : forall j, 'M[T]_(m, q_ j)) :
(\mxrow_j R_ j) =
castmx (big_ord1 _ (fun=> m), erefl) (\mxblock_(i < 1, j < q) R_ j).
Proof.
rewrite mxblock_recu castmx_comp.
apply/matrixP => i j; rewrite !castmxE !mxE/=; case: splitP => //=.
by move=> k /val_inj->; rewrite ?cast_ord_id ?mxE//=.
by move=> [k klt]; suff: false by []; rewrite big_ord0 in klt.
Qed.
Lemma mxcolEblock {p : nat} {p_ : 'I_p -> nat} n
(C_ : forall i, 'M[T]_(p_ i, n)) :
(\mxcol_i C_ i) =
castmx (erefl, big_ord1 _ (fun=> n)) (\mxblock_(i < p, j < 1) C_ i).
Proof.
by apply: trmx_inj; rewrite tr_mxcol mxrowEblock trmx_cast tr_mxblock.
Qed.
Lemma mxEmxrow m n (A : 'M[T]_(m, n)) :
A = castmx (erefl, big_ord1 _ (fun=> n)) (\mxrow__ A).
Proof.
apply/matrixP => i j; rewrite castmxE !mxE/= cast_ord_id.
congr (A i); set j' := cast_ord _ _.
suff -> : j' = (tagnat.Rank 0 j) by apply/val_inj; rewrite tagnat.Rank2K.
by apply/val_inj; rewrite [RHS]tagnat.RankEsum/= big_pred0_eq add0n.
Qed.
Lemma mxEmxcol m n (A : 'M[T]_(m, n)) :
A = castmx (big_ord1 _ (fun=> m), erefl) (\mxcol__ A).
Proof. by apply: trmx_inj; rewrite trmx_cast tr_mxcol [LHS]mxEmxrow. Qed.
Lemma mxEmxblock m n (A : 'M[T]_(m, n)) :
A = castmx (big_ord1 _ (fun=> m), big_ord1 _ (fun=> n))
(\mxblock_(i < 1, j < 1) A).
Proof. by rewrite [LHS]mxEmxrow mxrowEblock castmx_comp; apply: eq_castmx. Qed.
End BlockMatrixRec.
Section BlockRowNmod.
Context {V : nmodType} {q : nat} {q_ : 'I_q -> nat}.
Notation sq := (\sum_i q_ i)%N.
Implicit Type (s : 'I_sq).
Lemma mxrowD m (R_ R'_ : forall j, 'M[V]_(m, q_ j)) :
\mxrow_j (R_ j + R'_ j) = \mxrow_j (R_ j) + \mxrow_j (R'_ j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxrow0 m : \mxrow_j (0 : 'M[V]_(m, q_ j)) = 0.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxrow_const m a : \mxrow_j (const_mx a : 'M[V]_(m, q_ j)) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxrow_sum (J : finType) m
(R_ : forall i j, 'M[V]_(m, q_ j)) (P : {pred J}) :
\mxrow_j (\sum_(i | P i) R_ i j) = \sum_(i | P i) \mxrow_j (R_ i j).
Proof.
apply/matrixP => i j; rewrite !(mxE, summxE).
by apply: eq_bigr => l; rewrite !mxE.
Qed.
Lemma submxrowD m (B B' : 'M[V]_(m, sq)) j :
submxrow (B + B') j = submxrow B j + submxrow B' j.
Proof. by apply/matrixP => i i'; rewrite !mxE. Qed.
Lemma submxrow0 m j : submxrow (0 : 'M[V]_(m, sq)) j = 0.
Proof. by apply/matrixP=> i i'; rewrite !mxE. Qed.
Lemma submxrow_sum (J : finType) m
(R_ : forall i, 'M[V]_(m, sq)) (P : {pred J}) j:
submxrow (\sum_(i | P i) R_ i) j = \sum_(i | P i) submxrow (R_ i) j.
Proof.
apply/matrixP => i i'; rewrite !(mxE, summxE).
by apply: eq_bigr => l; rewrite !mxE.
Qed.
End BlockRowNmod.
Section BlockRowZmod.
Context {V : zmodType} {q : nat} {q_ : 'I_q -> nat}.
Notation sq := (\sum_i q_ i)%N.
Implicit Type (s : 'I_sq).
Lemma mxrowN m (R_ : forall j, 'M[V]_(m, q_ j)) :
\mxrow_j (- R_ j) = - \mxrow_j (R_ j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxrowB m (R_ R'_ : forall j, 'M[V]_(m, q_ j)) :
\mxrow_j (R_ j - R'_ j) = \mxrow_j (R_ j) - \mxrow_j (R'_ j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma submxrowN m (B : 'M[V]_(m, sq)) j :
submxrow (- B) j = - submxrow B j.
Proof. by apply/matrixP => i i'; rewrite !mxE. Qed.
Lemma submxrowB m (B B' : 'M[V]_(m, sq)) j :
submxrow (B - B') j = submxrow B j - submxrow B' j.
Proof. by apply/matrixP => i i'; rewrite !mxE. Qed.
End BlockRowZmod.
Section BlockRowSemiRing.
Context {R : pzSemiRingType} {n : nat} {q_ : 'I_n -> nat}.
Notation sq := (\sum_i q_ i)%N.
Implicit Type (s : 'I_sq).
Lemma mul_mxrow m n' (A : 'M[R]_(m, n')) (R_ : forall j, 'M[R]_(n', q_ j)) :
A *m \mxrow_j R_ j= \mxrow_j (A *m R_ j).
Proof.
by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE.
Qed.
Lemma mul_submxrow m n' (A : 'M[R]_(m, n')) (B : 'M[R]_(n', sq)) j :
A *m submxrow B j= submxrow (A *m B) j.
Proof.
by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE.
Qed.
End BlockRowSemiRing.
Section BlockColNmod.
Context {V : nmodType} {n : nat} {p_ : 'I_n -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma mxcolD m (C_ C'_ : forall i, 'M[V]_(p_ i, m)) :
\mxcol_i (C_ i + C'_ i) = \mxcol_i (C_ i) + \mxcol_i (C'_ i).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxcol0 m : \mxcol_i (0 : 'M[V]_(p_ i, m)) = 0.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxcol_const m a : \mxcol_j (const_mx a : 'M[V]_(p_ j, m)) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxcol_sum
(I : finType) m (C_ : forall j i, 'M[V]_(p_ i, m)) (P : {pred I}):
\mxcol_i (\sum_(j | P j) C_ j i) = \sum_(j | P j) \mxcol_i (C_ j i).
Proof.
apply/matrixP => i j; rewrite !(mxE, summxE).
by apply: eq_bigr => l; rewrite !mxE.
Qed.
Lemma submxcolD m (B B' : 'M[V]_(sp, m)) i :
submxcol (B + B') i = submxcol B i + submxcol B' i.
Proof. by apply/matrixP => j j'; rewrite !mxE. Qed.
Lemma submxcol0 m i : submxcol (0 : 'M[V]_(sp, m)) i = 0.
Proof. by apply/matrixP=> j j'; rewrite !mxE. Qed.
Lemma submxcol_sum (I : finType) m
(C_ : forall j, 'M[V]_(sp, m)) (P : {pred I}) i :
submxcol (\sum_(j | P j) C_ j) i = \sum_(j | P j) submxcol (C_ j) i.
Proof.
apply/matrixP => j j'; rewrite !(mxE, summxE).
by apply: eq_bigr => l; rewrite !mxE.
Qed.
End BlockColNmod.
Section BlockColZmod.
Context {V : zmodType} {n : nat} {p_ : 'I_n -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma mxcolN m (C_ : forall i, 'M[V]_(p_ i, m)) :
\mxcol_i (- C_ i) = - \mxcol_i (C_ i).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxcolB m (C_ C'_ : forall i, 'M[V]_(p_ i, m)) :
\mxcol_i (C_ i - C'_ i) = \mxcol_i (C_ i) - \mxcol_i (C'_ i).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma submxcolN m (B : 'M[V]_(sp, m)) i :
submxcol (- B) i = - submxcol B i.
Proof. by apply/matrixP => j j'; rewrite !mxE. Qed.
Lemma submxcolB m (B B' : 'M[V]_(sp, m)) i :
submxcol (B - B') i = submxcol B i - submxcol B' i.
Proof. by apply/matrixP => j j'; rewrite !mxE. Qed.
End BlockColZmod.
Section BlockColSemiRing.
Context {R : pzSemiRingType} {n : nat} {p_ : 'I_n -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma mxcol_mul n' m (C_ : forall i, 'M[R]_(p_ i, n')) (A : 'M[R]_(n', m)) :
\mxcol_i C_ i *m A = \mxcol_i (C_ i *m A).
Proof.
by apply/matrixP=> i s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE.
Qed.
Lemma submxcol_mul n' m (B : 'M[R]_(sp, n')) (A : 'M[R]_(n', m)) i :
submxcol B i *m A = submxcol (B *m A) i.
Proof.
by apply/matrixP=> j s; rewrite !mxE; under [LHS]eq_bigr do rewrite !mxE.
Qed.
End BlockColSemiRing.
Section BlockMatrixNmod.
Context {V : nmodType} {m n : nat}.
Context {p_ : 'I_m -> nat} {q_ : 'I_n -> nat}.
Notation sp := (\sum_i p_ i)%N.
Notation sq := (\sum_i q_ i)%N.
Lemma mxblockD (B_ B'_ : forall i j, 'M[V]_(p_ i, q_ j)) :
\mxblock_(i, j) (B_ i j + B'_ i j) =
\mxblock_(i, j) (B_ i j) + \mxblock_(i, j) (B'_ i j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxblock0 : \mxblock_(i, j) (0 : 'M[V]_(p_ i, q_ j)) = 0.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxblock_const a :
\mxblock_(i, j) (const_mx a : 'M[V]_(p_ i, q_ j)) = const_mx a.
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxblock_sum (I : finType)
(B_ : forall k i j, 'M[V]_(p_ i, q_ j)) (P : {pred I}):
\mxblock_(i, j) (\sum_(k | P k) B_ k i j) =
\sum_(k | P k) \mxblock_(i, j) (B_ k i j).
Proof.
apply/matrixP => i j; rewrite !(mxE, summxE).
by apply: eq_bigr => l; rewrite !mxE.
Qed.
Lemma submxblockD (B B' : 'M[V]_(sp, sq)) i j :
submxblock (B + B') i j = submxblock B i j + submxblock B' i j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma submxblock0 i j : submxblock (0 : 'M[V]_(sp, sq)) i j = 0.
Proof. by apply/matrixP=> k l; rewrite !mxE. Qed.
Lemma submxblock_sum (I : finType)
(B_ : forall k, 'M[V]_(sp, sq)) (P : {pred I}) i j :
submxblock (\sum_(k | P k) B_ k) i j = \sum_(k | P k) submxblock (B_ k) i j.
Proof.
apply/matrixP => k l; rewrite !(mxE, summxE).
by apply: eq_bigr => p; rewrite !mxE.
Qed.
End BlockMatrixNmod.
Section BlockMatrixZmod.
Context {V : zmodType} {m n : nat}.
Context {p_ : 'I_m -> nat} {q_ : 'I_n -> nat}.
Notation sp := (\sum_i p_ i)%N.
Notation sq := (\sum_i q_ i)%N.
Lemma mxblockN (B_ : forall i j, 'M[V]_(p_ i, q_ j)) :
\mxblock_(i, j) (- B_ i j) = - \mxblock_(i, j) (B_ i j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma mxblockB (B_ B'_ : forall i j, 'M[V]_(p_ i, q_ j)) :
\mxblock_(i, j) (B_ i j - B'_ i j) =
\mxblock_(i, j) (B_ i j) - \mxblock_(i, j) (B'_ i j).
Proof. by apply/matrixP=> i j; rewrite !mxE. Qed.
Lemma submxblockN (B : 'M[V]_(sp, sq)) i j :
submxblock (- B) i j = - submxblock B i j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
Lemma submxblockB (B B' : 'M[V]_(sp, sq)) i j :
submxblock (B - B') i j = submxblock B i j - submxblock B' i j.
Proof. by apply/matrixP => k l; rewrite !mxE. Qed.
End BlockMatrixZmod.
Section BlockMatrixSemiRing.
Context {R : pzSemiRingType} {p q : nat} {p_ : 'I_p -> nat} {q_ : 'I_q -> nat}.
Notation sp := (\sum_i p_ i)%N.
Notation sq := (\sum_i q_ i)%N.
Lemma mul_mxrow_mxcol m n
(R_ : forall j, 'M[R]_(m, p_ j)) (C_ : forall i, 'M[R]_(p_ i, n)) :
\mxrow_j R_ j *m \mxcol_i C_ i = \sum_i (R_ i *m C_ i).
Proof.
apply/matrixP => i j; rewrite !mxE summxE; under [RHS]eq_bigr do rewrite !mxE.
rewrite sig_big_dep/= (reindex _ tagnat.sig_bij_on)/=.
by apply: eq_bigr=> l _; rewrite !mxE.
Qed.
Lemma mul_mxcol_mxrow m
(C_ : forall i, 'M[R]_(p_ i, m)) (R_ : forall j, 'M[R]_(m, q_ j)) :
\mxcol_i C_ i*m \mxrow_j R_ j = \mxblock_(i, j) (C_ i *m R_ j).
Proof.
apply/mxblockP => i j; rewrite mxblockK.
by rewrite submxblockEh -mul_submxrow -submxcol_mul mxcolK mxrowK.
Qed.
Lemma mul_mxrow_mxblock m
(R_ : forall i, 'M[R]_(m, p_ i)) (B_ : forall i j, 'M[R]_(p_ i, q_ j)) :
\mxrow_i R_ i *m \mxblock_(i, j) B_ i j = \mxrow_j (\sum_i (R_ i *m B_ i j)).
Proof.
rewrite mxblockEv mul_mxrow_mxcol mxrow_sum.
by apply: eq_bigr => i _; rewrite mul_mxrow.
Qed.
Lemma mul_mxblock_mxrow m
(B_ : forall i j, 'M[R]_(q_ i, p_ j)) (C_ : forall i, 'M[R]_(p_ i, m)) :
\mxblock_(i, j) B_ i j *m \mxcol_j C_ j = \mxcol_i (\sum_j (B_ i j *m C_ j)).
Proof.
rewrite mxblockEh mul_mxrow_mxcol mxcol_sum.
by apply: eq_bigr => i _; rewrite mxcol_mul.
Qed.
End BlockMatrixSemiRing.
Lemma mul_mxblock {R : pzSemiRingType} {p q r : nat}
{p_ : 'I_p -> nat} {q_ : 'I_q -> nat} {r_ : 'I_r -> nat}
(A_ : forall i j, 'M[R]_(p_ i, q_ j)) (B_ : forall j k, 'M_(q_ j, r_ k)) :
\mxblock_(i, j) A_ i j *m \mxblock_(j, k) B_ j k =
\mxblock_(i, k) \sum_j (A_ i j *m B_ j k).
Proof.
rewrite mxblockEh mul_mxrow_mxblock mxblockEh; apply: eq_mxrow => i.
by under [LHS]eq_bigr do rewrite mxcol_mul; rewrite -mxcol_sum.
Qed.
Section SquareBlockMatrixNmod.
Import Order.TTheory tagnat.
Context {V : nmodType} {p : nat} {p_ : 'I_p -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma is_trig_mxblockP (B_ : forall i j, 'M[V]_(p_ i, p_ j)) :
reflect [/\ forall (i j : 'I_p), (i < j)%N -> B_ i j = 0 &
forall i, is_trig_mx (B_ i i)]
(is_trig_mx (\mxblock_(i, j) B_ i j)).
Proof.
apply: (iffP is_trig_mxP); last first.
move=> [Blt1 /(_ _)/is_trig_mxP Blt2]/= s s'; rewrite !mxE.
rewrite -[_ < _]lt_sig ltEsig/= /sig1 /sig2 leEord.
case: ltngtP => //= ii'; first by rewrite (Blt1 _ _ ii') mxE.
move: (sig s) (sig s') ii' => -[/= i j] [/= i' +] /val_inj ii'.
by case: _ / ii' => j'; rewrite tagged_asE => /Blt2->.
move=> Btrig; split=> [i i' lti|i].
apply/matrixP => j j'; have := Btrig (Rank _ j) (Rank _ j').
rewrite !mxE !Rank2K; do !case: _ / esym; rewrite !cast_ord_id.
rewrite /Rank [_ <= _]lt_rank.
by rewrite ltEsig/= leEord ltnW//= (ltn_geF lti)//= => /(_ isT).
apply/is_trig_mxP => j j' ltj; have := Btrig (Rank _ j) (Rank _ j').
rewrite !mxE !Rank2K; do! case: _ / esym; rewrite !cast_ord_id.
by rewrite [_ <= _]lt_rank ltEsig/= !leEord leqnn/= tagged_asE; apply.
Qed.
Lemma is_trig_mxblock (B_ : forall i j, 'M[V]_(p_ i, p_ j)) :
is_trig_mx (\mxblock_(i, j) B_ i j) =
([forall i : 'I_p, forall j : 'I_p, (i < j)%N ==> (B_ i j == 0)] &&
[forall i, is_trig_mx (B_ i i)]).
Proof.
by apply/is_trig_mxblockP/andP => -[] => [/(_ _ _ _)/eqP|]
=> /'forall_'forall_implyP => [|/(_ _ _ _)/eqP] Blt /forallP.
Qed.
Lemma is_diag_mxblockP (B_ : forall i j, 'M[V]_(p_ i, p_ j)) :
reflect [/\ forall (i j : 'I_p), i != j -> B_ i j = 0 &
forall i, is_diag_mx (B_ i i)]
(is_diag_mx (\mxblock_(i, j) B_ i j)).
Proof.
apply: (iffP is_diag_mxP); last first.
move=> [Bneq1 /(_ _)/is_diag_mxP Bneq2]/= s s'; rewrite !mxE.
rewrite val_eqE -(can_eq sigK) /sig1 /sig2.
move: (sig s) (sig s') => -[/= i j] [/= i' j'].
rewrite -tag_eqE/= /tag_eq/= negb_and.
case: eqVneq => /= [ii'|/Bneq1->]; last by rewrite !mxE.
by rewrite -ii' in j' *; rewrite tagged_asE => /Bneq2.
move=> Bdiag; split=> [i i' Ni|i].
apply/matrixP => j j'; have := Bdiag (Rank _ j) (Rank _ j').
rewrite !mxE !Rank2K; do !case: _ / esym; rewrite !cast_ord_id.
by rewrite eq_Rank negb_and Ni; apply.
apply/is_diag_mxP => j j' Nj; have := Bdiag (Rank _ j) (Rank _ j').
rewrite !mxE !Rank2K; do! case: _ / esym; rewrite !cast_ord_id.
by rewrite eq_Rank negb_and val_eqE Nj orbT; apply.
Qed.
Lemma is_diag_mxblock (B_ : forall i j, 'M[V]_(p_ i, p_ j)) :
is_diag_mx (\mxblock_(i, j) B_ i j) =
([forall i : 'I_p, forall j : 'I_p, (i != j) ==> (B_ i j == 0)] &&
[forall i, is_diag_mx (B_ i i)]).
Proof.
by apply/is_diag_mxblockP/andP => -[] => [/(_ _ _ _)/eqP|]
=> /'forall_'forall_implyP => [|/(_ _ _ _)/eqP] Blt /forallP.
Qed.
Definition mxdiag (B_ : forall i, 'M[V]_(p_ i)) : 'M[V]_(\sum_i p_ i) :=
\mxblock_(j, k) if j == k then conform_mx 0 (B_ j) else 0.
Local Notation "\mxdiag_ i E" := (mxdiag (fun i => E)) : ring_scope.
Lemma submxblock_diag (B_ : forall i, 'M[V]_(p_ i)) i :
submxblock (\mxdiag_i B_ i) i i = B_ i.
Proof. by rewrite mxblockK conform_mx_id eqxx. Qed.
Lemma eq_mxdiagP (B_ B'_ : forall i, 'M[V]_(p_ i)) :
(forall i, B_ i = B'_ i) <-> (\mxdiag_i B_ i = \mxdiag_i B'_ i).
Proof.
rewrite /mxdiag; split; first by move=> e; apply/eq_mxblockP => i j; rewrite e.
by move=> + i => /eq_mxblockP/(_ i i); rewrite eqxx !conform_mx_id.
Qed.
Lemma eq_mxdiag (B_ B'_ : forall i, 'M[V]_(p_ i)) :
(forall i, B_ i = B'_ i) -> (\mxdiag_i B_ i = \mxdiag_i B'_ i).
Proof. by move=> /eq_mxdiagP. Qed.
Lemma mxdiagD (B_ B'_ : forall i, 'M[V]_(p_ i)) :
\mxdiag_i (B_ i + B'_ i) = \mxdiag_i (B_ i) + \mxdiag_i (B'_ i).
Proof.
rewrite /mxdiag -mxblockD; apply/eq_mxblock => i j.
by case: eqVneq => [->|]; rewrite ?conform_mx_id ?addr0.
Qed.
Lemma mxdiag_sum (I : finType) (B_ : forall k i, 'M[V]_(p_ i)) (P : {pred I}) :
\mxdiag_i (\sum_(k | P k) B_ k i) = \sum_(k | P k) \mxdiag_i (B_ k i).
Proof.
rewrite /mxdiag -mxblock_sum; apply/eq_mxblock => i j.
case: eqVneq => [->|]; rewrite ?conform_mx_id//; last by rewrite big1.
by apply: eq_bigr => k; rewrite conform_mx_id.
Qed.
Lemma tr_mxdiag (B_ : forall i, 'M[V]_(p_ i)) :
(\mxdiag_i B_ i)^T = \mxdiag_i (B_ i)^T.
Proof.
rewrite tr_mxblock; apply/eq_mxblock => i j.
by case: eqVneq => [->|]; rewrite ?trmx_conform ?trmx0.
Qed.
Lemma row_mxdiag (B_ : forall i, 'M[V]_(p_ i)) k :
let B'_ i := if sig1 k == i then conform_mx 0 (B_ i) else 0 in
row k (\mxdiag_ i B_ i) = row (sig2 k) (\mxrow_i B'_ i).
Proof.
rewrite /= row_mxblock row_mxrow; apply/eq_mxrow => i.
by case: eqVneq => // e; congr row; rewrite e.
Qed.
Lemma col_mxdiag (B_ : forall i, 'M[V]_(p_ i)) k :
let B'_ i := if sig1 k == i then conform_mx 0 (B_ i) else 0 in
col k (\mxdiag_ i B_ i) = col (sig2 k) (\mxcol_i B'_ i).
Proof.
by rewrite /= col_mxblock col_mxcol; apply/eq_mxcol => i; rewrite eq_sym.
Qed.
End SquareBlockMatrixNmod.
Notation "\mxdiag_ ( i < n ) E" := (mxdiag (fun i : 'I_n => E))
(only parsing) : ring_scope.
Notation "\mxdiag_ i E" := (\mxdiag_(i < _) E) : ring_scope.
Section SquareBlockMatrixZmod.
Import Order.TTheory tagnat.
Context {V : zmodType} {p : nat} {p_ : 'I_p -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma mxdiagN (B_ : forall i, 'M[V]_(p_ i)) :
\mxdiag_i (- B_ i) = - \mxdiag_i (B_ i).
Proof.
rewrite /mxdiag -mxblockN; apply/eq_mxblock => i j.
by case: eqVneq => [->|]; rewrite ?conform_mx_id ?oppr0.
Qed.
Lemma mxdiagB (B_ B'_ : forall i, 'M[V]_(p_ i)) :
\mxdiag_i (B_ i - B'_ i) = \mxdiag_i (B_ i) - \mxdiag_i (B'_ i).
Proof. by rewrite mxdiagD mxdiagN. Qed.
Lemma mxdiag0 : \mxdiag_i (0 : 'M[V]_(p_ i)) = 0.
Proof. by under [LHS]eq_mxdiag do rewrite -[0]subr0; rewrite mxdiagB subrr. Qed.
End SquareBlockMatrixZmod.
Lemma mxdiag_recl {V : nmodType} {m : nat} {p_ : 'I_m.+1 -> nat}
(B_ : forall i, 'M[V]_(p_ i)) :
\mxdiag_i B_ i = castmx (mxsize_recl, mxsize_recl)
(block_mx (B_ 0) 0 0 (\mxdiag_i B_ (lift ord0 i))).
Proof.
rewrite /mxdiag mxblock_recul/= !conform_mx_id.
by congr (castmx _ (block_mx _ _ _ _)); rewrite ?mxrow0 ?mxcol0.
Qed.
Section SquareBlockMatrixSemiRing.
Import tagnat.
Context {R : pzSemiRingType} {p : nat} {p_ : 'I_p -> nat}.
Notation sp := (\sum_i p_ i)%N.
Implicit Type (s : 'I_sp).
Lemma mxtrace_mxblock (B_ : forall i j, 'M[R]_(p_ i, p_ j)) :
\tr (\mxblock_(i, j) B_ i j) = \sum_i \tr (B_ i i).
Proof.
rewrite /mxtrace sig_big_dep (reindex _ sig_bij_on)/=.
by apply: eq_bigr => i _; rewrite !mxE.
Qed.
Lemma mxdiagZ a : \mxdiag_i (a%:M : 'M[R]_(p_ i)) = a%:M.
Proof.
apply/matrixP => s t; rewrite !mxE -(can_eq sigK) /sig1 /sig2.
case: (sig s) (sig t) => [/= i j] [/= i' j'].
case: eqP => [<-|ni] in j' *; last by rewrite !mxE; case: eqVneq => // -[].
by rewrite conform_mx_id eq_Tagged/= mxE.
Qed.
Lemma diag_mxrow (B_ : forall j, 'rV[R]_(p_ j)) :
diag_mx (\mxrow_j B_ j) = \mxdiag_j (diag_mx (B_ j)).
Proof.
apply/matrixP => s s'; rewrite !mxE/= -(can_eq sigK) /sig1 /sig2.
case: (sig s) (sig s') => [/= i j] [/= i' j'].
rewrite -tag_eqE /tag_eq/=; case: (eqVneq i i') => ii'; rewrite ?mxE//=.
by case: _ / ii' in j' *; rewrite tagged_asE/= conform_mx_id mxE.
Qed.
Lemma mxtrace_mxdiag (B_ : forall i, 'M[R]_(p_ i)) :
\tr (\mxdiag_i B_ i) = \sum_i \tr (B_ i).
Proof.
by rewrite mxtrace_mxblock; apply: eq_bigr => i _; rewrite eqxx/= conform_mx_id.
Qed.
Lemma mul_mxdiag_mxcol m
(D_ : forall i, 'M[R]_(p_ i)) (C_ : forall i, 'M[R]_(p_ i, m)):
\mxdiag_i D_ i *m \mxcol_i C_ i = \mxcol_i (D_ i *m C_ i).
Proof.
rewrite /mxdiag mxblockEh mul_mxrow_mxcol.
under [LHS]eq_bigr do rewrite mxcol_mul; rewrite -mxcol_sum.
apply/eq_mxcol => i; rewrite (bigD1 i)//= eqxx conform_mx_id big1 ?addr0//.
by move=> j; case: eqVneq => //=; rewrite mul0mx.
Qed.
End SquareBlockMatrixSemiRing.
Lemma mul_mxrow_mxdiag {R : pzSemiRingType} {p : nat} {p_ : 'I_p -> nat} m
(R_ : forall i, 'M[R]_(m, p_ i)) (D_ : forall i, 'M[R]_(p_ i)) :
\mxrow_i R_ i *m \mxdiag_i D_ i = \mxrow_i (R_ i *m D_ i).
Proof.
apply: trmx_inj; rewrite trmx_mul_rev !tr_mxrow tr_mxdiag mul_mxdiag_mxcol.
by apply/ eq_mxcol => i; rewrite trmx_mul_rev.
Qed.
Lemma mul_mxblock_mxdiag {R : pzSemiRingType} {p q : nat}
{p_ : 'I_p -> nat} {q_ : 'I_q -> nat}
(B_ : forall i j, 'M[R]_(p_ i, q_ j)) (D_ : forall j, 'M[R]_(q_ j)) :
\mxblock_(i, j) B_ i j *m \mxdiag_j D_ j = \mxblock_(i, j) (B_ i j *m D_ j).
Proof.
by rewrite !mxblockEh mul_mxrow_mxdiag; under eq_mxrow do rewrite mxcol_mul.
Qed.
Lemma mul_mxdiag_mxblock {R : pzSemiRingType} {p q : nat}
{p_ : 'I_p -> nat} {q_ : 'I_q -> nat}
(D_ : forall j, 'M[R]_(p_ j)) (B_ : forall i j, 'M[R]_(p_ i, q_ j)):
\mxdiag_j D_ j *m \mxblock_(i, j) B_ i j = \mxblock_(i, j) (D_ i *m B_ i j).
Proof.
by rewrite !mxblockEv mul_mxdiag_mxcol; under eq_mxcol do rewrite mul_mxrow.
Qed.
Definition Vandermonde (R : pzRingType) (m n : nat) (a : 'rV[R]_n) :=
\matrix_(i < m, j < n) a 0 j ^+ i.
Lemma det_Vandermonde (R : comPzRingType) (n : nat) (a : 'rV[R]_n) :
\det (Vandermonde n a) = \prod_(i < n) \prod_(j < n | i < j) (a 0 j - a 0 i).
Proof.
set V := @Vandermonde R.
elim: n => [|n IHn] in a *; first by rewrite det_mx00 big1// => -[] [].
pose b : 'rV_n := \row_i a 0 (lift 0 i).
pose C : 'M_n := diag_mx (\row_(i < n) (b 0 i - a 0 0)).
pose D : 'M_n.+1 := 1 - a 0 0 *: \matrix_(i, j) (i == j.+1 :> nat)%:R.
have detD : \det D = 1.
rewrite det_trig ?big_ord_recl ?mxE ?mulr0 ?subr0 ?eqxx.
by rewrite ?big1 ?mulr1// => i; rewrite !mxE eqxx ltn_eqF// mulr0 subr0.
by apply/is_trig_mxP => *; rewrite !mxE ![_ == _]ltn_eqF ?mulr0 ?subr0 ?leqW.
suff: D * V _ _ a = block_mx 1 (const_mx 1) 0 (V _ _ b *m C) :> 'M_(1 + n).
move=> /(congr1 determinant); rewrite detM detD mul1r => ->.
rewrite det_ublock det1 mul1r det_mulmx IHn big_ord_recl mulrC; congr (_ * _).
rewrite big_mkcond big_ord_recl/= mul1r det_diag.
by under eq_bigr do rewrite !mxE.
apply: eq_bigr => i _; under eq_bigr do rewrite !mxE.
by rewrite big_mkcond [RHS]big_mkcond big_ord_recl/= mul1r.
rewrite mulrBl mul1r -[_ * _]scalemxAl; apply/matrixP => i j; rewrite !mxE.
under eq_bigr do rewrite !mxE; case: splitP => [{i}_ -> /[!ord1]|{}i ->].
rewrite !expr0 big1; last by move=> ?; rewrite mul0r.
by rewrite ?mulr0 ?subr0 ?mxE; case: splitP => k; rewrite ?ord1 mxE//.
under eq_bigr do rewrite eqSS mulr_natl mulrb eq_sym.
rewrite -big_mkcond/= big_ord1_eq exprS ifT// ?leqW// -mulrBl !mxE/=.
case: split_ordP => [{j}_ -> /[!ord1]|{}j ->]; rewrite ?lshift0 ?rshift1 ?mxE.
by rewrite ?subrr ?mul0r//.
under eq_bigr do rewrite !mxE mulrnAr mulrb.
by rewrite -big_mkcond big_pred1_eq /= mulrC.
Qed.
|
ContinuousLinearMap.lean
|
/-
Copyright (c) 2020 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import Mathlib.Analysis.NormedSpace.OperatorNorm.Bilinear
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
import Mathlib.Topology.Algebra.Module.FiniteDimension
/-!
# Measurable functions in normed spaces
-/
open MeasureTheory
variable {Ξ± : Type*} [MeasurableSpace Ξ±]
namespace ContinuousLinearMap
variable {R E F : Type*} [Semiring R]
[SeminormedAddCommGroup E] [Module R E] [MeasurableSpace E] [OpensMeasurableSpace E]
[SeminormedAddCommGroup F] [Module R F] [MeasurableSpace F] [BorelSpace F]
@[fun_prop, measurability]
protected theorem measurable (L : E βL[R] F) : Measurable L :=
L.continuous.measurable
@[fun_prop]
theorem measurable_comp (L : E βL[R] F) {Ο : Ξ± β E} (Ο_meas : Measurable Ο) :
Measurable fun a : Ξ± => L (Ο a) :=
L.measurable.comp Ο_meas
end ContinuousLinearMap
namespace ContinuousLinearMap
variable {π : Type*} [NontriviallyNormedField π]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace π E] {F : Type*} [NormedAddCommGroup F]
[NormedSpace π F]
instance instMeasurableSpace : MeasurableSpace (E βL[π] F) :=
borel _
instance instBorelSpace : BorelSpace (E βL[π] F) :=
β¨rflβ©
@[fun_prop, measurability]
theorem measurable_apply [MeasurableSpace F] [BorelSpace F] (x : E) :
Measurable fun f : E βL[π] F => f x :=
(apply π F x).continuous.measurable
@[measurability]
theorem measurable_apply' [MeasurableSpace E] [OpensMeasurableSpace E] [MeasurableSpace F]
[BorelSpace F] : Measurable fun (x : E) (f : E βL[π] F) => f x :=
measurable_pi_lambda _ fun f => f.measurable
@[measurability]
theorem measurable_coe [MeasurableSpace F] [BorelSpace F] :
Measurable fun (f : E βL[π] F) (x : E) => f x :=
measurable_pi_lambda _ measurable_apply
end ContinuousLinearMap
section ContinuousLinearMapNontriviallyNormedField
variable {π : Type*} [NontriviallyNormedField π]
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace π E] [MeasurableSpace E] [BorelSpace E]
{F : Type*} [NormedAddCommGroup F] [NormedSpace π F]
@[fun_prop, measurability]
theorem Measurable.apply_continuousLinearMap {Ο : Ξ± β F βL[π] E} (hΟ : Measurable Ο) (v : F) :
Measurable fun a => Ο a v :=
(ContinuousLinearMap.apply π E v).measurable.comp hΟ
@[measurability]
theorem AEMeasurable.apply_continuousLinearMap {Ο : Ξ± β F βL[π] E} {ΞΌ : Measure Ξ±}
(hΟ : AEMeasurable Ο ΞΌ) (v : F) : AEMeasurable (fun a => Ο a v) ΞΌ :=
(ContinuousLinearMap.apply π E v).measurable.comp_aemeasurable hΟ
end ContinuousLinearMapNontriviallyNormedField
section NormedSpace
variable {π : Type*} [NontriviallyNormedField π] [CompleteSpace π] [MeasurableSpace π]
variable [BorelSpace π] {E : Type*} [NormedAddCommGroup E] [NormedSpace π E] [MeasurableSpace E]
[BorelSpace E]
theorem measurable_smul_const {f : Ξ± β π} {c : E} (hc : c β 0) :
(Measurable fun x => f x β’ c) β Measurable f :=
(isClosedEmbedding_smul_left hc).measurableEmbedding.measurable_comp_iff
theorem aemeasurable_smul_const {f : Ξ± β π} {ΞΌ : Measure Ξ±} {c : E} (hc : c β 0) :
AEMeasurable (fun x => f x β’ c) ΞΌ β AEMeasurable f ΞΌ :=
(isClosedEmbedding_smul_left hc).measurableEmbedding.aemeasurable_comp_iff
end NormedSpace
|
fin_cases.lean
|
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.NormNum.Basic
import Mathlib.Order.Interval.Finset.Nat
example {x : Nat} (h : x β [0, 2, 37]) : x β€ 57 := by
fin_cases h
repeat decide
example {x : Nat} (h : x β [0, 2, 37]) : x = 0 β¨ x = 2 β¨ x = 37 := by
fin_cases h
repeat simp
example {x : Nat} (h : x β List.range 5) : x β€ 4 := by
fin_cases h
repeat decide
example {p : Fin 4 β Prop} (i : Fin 4) (h : p i) : p i := by
fin_cases i
repeat exact h
example (f : Nat β Prop) (p : Fin 3) (h0 : f 0) (h1 : f 1) (h2 : f 2) : f p.val := by
fin_cases p
all_goals
assumption
example (f : Nat β Prop) (p : Fin 0) : f p.val := by
fin_cases p
example (x2 : Fin 2) (x3 : Fin 3) : True := by
fin_cases x2, x3
all_goals trivial
-- Checking that `fin_cases` can handle a metavariable for the type
example (p : β) (h2 : 2 < p) (h5 : p < 5) : p = 3 β¨ p = 4 := by
have hp : ?_ := ?foo
case foo => exact (Finset.mem_Ioo).2 β¨h2, h5β©
fin_cases hp
Β· norm_num
Β· norm_num
-- Check naming of cases
/--
trace: case Β«0Β».Β«0Β»
β’ True
case Β«0Β».Β«1Β»
β’ True
case Β«1Β».Β«0Β»
β’ True
case Β«1Β».Β«1Β»
β’ True
-/
#guard_msgs in
example (x y : Fin 2): True := by
fin_cases x, y
trace_state
all_goals trivial
-- TODO Restore the remaining tests from mathlib3:
-- Some of these test the `with` and `using` clauses which haven't been re-implemented.
set_option linter.unusedVariables false in
example (x2 : Fin 2) (x3 : Fin 3) (n : Nat) (y : Fin n) : x2.val * x3.val = x3.val * x2.val := by
fin_cases x2 <;> fin_cases x3
fail_if_success
fin_cases y
all_goals rfl
-- example (x : β) (h : x β [2,3,5,7]) : True := by
-- fail_if_success
-- fin_cases h with [3,3,5,7]
-- trivial
-- example (x : List Nat) (h : x β [[1],[2]]) : x.length = 1 := by
-- fin_cases h with [[1],[1+1]]
-- Β· simp
-- Β· guard_target = [1 + 1].length = 1
-- simp
-- -- testing that `with` arguments are elaborated with respect to the expected type:
-- example (x : Int) (h : x β ([2,3] : List Int)) : x = 2 β¨ x = 3 := by
-- fin_cases h with [2,3]
-- all_goals simp
-- example (n : β) (h : n % 3 β [0,1]) : True := by
-- fin_cases h
-- Β· guard_hyp h : n % 3 = 0
-- trivial
-- Β· guard_hyp h : n % 3 = 1
-- trivial
-- instance (n : β) : Decidable (Nat.Prime n) := decidablePrime_1 n
-- example (x : β) (h : x β (List.range 10).filter Nat.prime) : x = 2 β¨ x = 3 β¨ x = 5 β¨ x = 7 := by
-- fin_cases h <;> decide
-- open Equiv.Perm
-- example (x : (Ξ£ (a : Fin 4), Fin 4)) (h : x β finPairsLT 4) : x.1.val < 4 := by
-- fin_cases h; simp
-- any_goals exact dec_trivial
-- /-
-- In some circumstances involving `let`,
-- the temporary hypothesis that `fin_cases` creates does not get deleted.
-- We test that this is correctly named and that the name can be changed.
-- Note: after `fin_cases`, we have `this : (a : Fin 3) = (0 : Fin (2 + 1))`
-- for some reason. I don't know why, and it complicates the test.
-- -/
-- example (f : β β Fin 3) : true := by
-- let a := f 3
-- fin_cases a
-- guard_hyp a := f 3
-- guard_hyp this : a = (0 : Fin (2 + 1))
-- trivial; trivial
-- let b := f 2
-- fin_cases b using what
-- guard_hyp what : b = (0 : Fin (2 + 1))
-- all_goals trivial
-- /-
-- The behavior above can be worked around with `fin_cases with`.
-- -/
-- example (f : β β Fin 3) : true := by
-- let a := f 3
-- fin_cases a with [0, 1, 2]
-- guard_hyp a := f 3
-- guard_hyp this : a = 0
-- trivial
-- guard_hyp this : a = 1
-- trivial
-- guard_hyp this : a = 2
-- let b := f 2
-- fin_cases b with [0, 1, 2] using what
-- guard_hyp what : b = 0
-- all_goals trivial
|
Sampleable.lean
|
/-
Copyright (c) 2022 Henrik BΓΆving. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Henrik BΓΆving, Simon Hudon
-/
import Batteries.Data.Rat.Basic
import Mathlib.Data.Int.Order.Basic
import Mathlib.Data.List.Monad
import Mathlib.Data.PNat.Defs
import Plausible.Sampleable
/-!
This module contains `Plausible.Shrinkable` and `Plausible.SampleableExt` instances for mathlib
types.
-/
namespace Plausible
open Random Gen
section Shrinkers
instance Rat.shrinkable : Shrinkable Rat where
shrink r :=
(Shrinkable.shrink r.num).flatMap fun d => Nat.shrink r.den |>.map fun n => Rat.divInt d n
instance PNat.shrinkable : Shrinkable PNat where
shrink m := Nat.shrink m.natPred |>.map Nat.succPNat
end Shrinkers
section Samplers
open SampleableExt
instance Rat.sampleableExt : SampleableExt Rat :=
mkSelfContained (do
let d β choose Int (-(β getSize)) (β getSize)
(le_trans (Int.neg_nonpos_of_nonneg (Int.ofNat_zero_le _)) (Int.ofNat_zero_le _))
let n β choose Nat 0 (β getSize) (Nat.zero_le _)
return Rat.divInt d n)
instance PNat.sampleableExt : SampleableExt PNat :=
mkSelfContained (do
let n β chooseNat
return Nat.succPNat n)
end Samplers
end Plausible
|
Pi.lean
|
/-
Copyright (c) 2024 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.Pi
import Mathlib.LinearAlgebra.Multilinear.Basic
/-!
# Interactions between (dependent) functions and multilinear maps
## Main definitions
* `MultilinearMap.pi_ext`, a multilinear version of `LinearMap.pi_ext`
* `MultilinearMap.piFamily`, which satisfies `piFamily f x p = f p (fun i => x i (p i))`.
This is useful because all the intermediate results are bundled:
- `MultilinearMap.piFamily f` is a `MultilinearMap` operating on functions `x`.
- `MultilinearMap.piFamilyβ` is a `LinearMap`, linear in the family of multilinear maps `f`.
-/
universe uΞΉ uΞΊ uS uR uM uN
variable {ΞΉ : Type uΞΉ} {ΞΊ : ΞΉ β Type uΞΊ}
variable {S : Type uS} {R : Type uR}
namespace MultilinearMap
section Semiring
variable {M : β i, ΞΊ i β Type uM} {N : Type uN}
variable [Semiring R]
variable [β i k, AddCommMonoid (M i k)] [AddCommMonoid N]
variable [β i k, Module R (M i k)] [Module R N]
/-- Two multilinear maps from finite families are equal if they agree on the generators.
This is a multilinear version of `LinearMap.pi_ext`. -/
@[ext]
theorem pi_ext [Finite ΞΉ] [β i, Finite (ΞΊ i)] [β i, DecidableEq (ΞΊ i)]
β¦f g : MultilinearMap R (fun i β¦ Ξ j : ΞΊ i, M i j) Nβ¦
(h : β p : Ξ i, ΞΊ i,
f.compLinearMap (fun i => LinearMap.single R _ (p i)) =
g.compLinearMap (fun i => LinearMap.single R _ (p i))) : f = g := by
ext x
change f (fun i β¦ x i) = g (fun i β¦ x i)
obtain β¨iβ© := nonempty_fintype ΞΉ
have (i : _) := (nonempty_fintype (ΞΊ i)).some
have := Classical.decEq ΞΉ
rw [funext (fun i β¦ Eq.symm (Finset.univ_sum_single (x i)))]
simp_rw [MultilinearMap.map_sum_finset]
congr! 1 with p
simp_rw [MultilinearMap.ext_iff] at h
exact h _ _
end Semiring
section piFamily
variable {M : β i, ΞΊ i β Type uM} {N : (Ξ i, ΞΊ i) β Type uN}
section Semiring
variable [Semiring R]
variable [β i k, AddCommMonoid (M i k)] [β p, AddCommMonoid (N p)]
variable [β i k, Module R (M i k)] [β p, Module R (N p)]
/--
Given a family of indices `ΞΊ` and a multilinear map `f p` for each way `p` to select one index from
each family, `piFamily f` maps a family of functions (one for each domain `ΞΊ i`) into a function
from each selection of indices (with domain `Ξ i, ΞΊ i`).
-/
@[simps]
def piFamily (f : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p)) :
MultilinearMap R (fun i => Ξ j : ΞΊ i, M i j) (Ξ t : Ξ i, ΞΊ i, N t) where
toFun x := fun p => f p (fun i => x i (p i))
map_update_add' {dec} m i x y := funext fun p => by
dsimp
simp_rw [Function.apply_update (fun i m => m (p i)) m, Pi.add_apply, (f p).map_update_add]
map_update_smul' {dec} m i c x := funext fun p => by
dsimp
simp_rw [Function.apply_update (fun i m => m (p i)) m, Pi.smul_apply, (f p).map_update_smul]
/-- When applied to a family of finitely-supported functions each supported on a single element,
`piFamily` is itself supported on a single element, with value equal to the map `f` applied
at that point. -/
@[simp]
theorem piFamily_single [Fintype ΞΉ] [β i, DecidableEq (ΞΊ i)]
(f : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p))
(p : β i, ΞΊ i) (m : β i, M i (p i)) :
piFamily f (fun i => Pi.single (p i) (m i)) = Pi.single p (f p m) := by
ext q
obtain rfl | hpq := eq_or_ne p q
Β· simp
Β· rw [Pi.single_eq_of_ne' hpq]
rw [Function.ne_iff] at hpq
obtain β¨i, hpqiβ© := hpq
apply (f q).map_coord_zero i
simp_rw [Pi.single_eq_of_ne' hpqi]
/-- When only one member of the family of multilinear maps is nonzero, the result consists only of
the component from that member. -/
@[simp]
theorem piFamily_single_left_apply [Fintype ΞΉ] [β i, DecidableEq (ΞΊ i)]
(p : Ξ i, ΞΊ i) (f : MultilinearMap R (fun i β¦ M i (p i)) (N p)) (x : Ξ i j, M i j) :
piFamily (Pi.single p f) x = Pi.single p (f fun i => x i (p i)) := by
ext p'
obtain rfl | hp := eq_or_ne p p'
Β· simp
Β· simp [hp]
theorem piFamily_single_left [Fintype ΞΉ] [β i, DecidableEq (ΞΊ i)]
(p : Ξ i, ΞΊ i) (f : MultilinearMap R (fun i β¦ M i (p i)) (N p)) :
piFamily (Pi.single p f) =
(LinearMap.single R _ p).compMultilinearMap (f.compLinearMap fun i => .proj (p i)) :=
ext <| piFamily_single_left_apply _ _
@[simp]
theorem piFamily_compLinearMap_lsingle [Fintype ΞΉ] [β i, DecidableEq (ΞΊ i)]
(f : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p)) (p : β i, ΞΊ i) :
(piFamily f).compLinearMap (fun i => LinearMap.single _ _ (p i))
= (LinearMap.single _ _ p).compMultilinearMap (f p) :=
MultilinearMap.ext <| piFamily_single f p
@[simp]
theorem piFamily_zero :
piFamily (0 : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p)) = 0 := by
ext; simp
@[simp]
theorem piFamily_add (f g : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p)) :
piFamily (f + g) = piFamily f + piFamily g := by
ext; simp
@[simp]
theorem piFamily_smul
[Monoid S] [β p, DistribMulAction S (N p)] [β p, SMulCommClass R S (N p)]
(s : S) (f : Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p)) :
piFamily (s β’ f) = s β’ piFamily f := by
ext; simp
end Semiring
section CommSemiring
variable [CommSemiring R]
variable [β i k, AddCommMonoid (M i k)] [β p, AddCommMonoid (N p)]
variable [β i k, Module R (M i k)] [β p, Module R (N p)]
/-- `MultilinearMap.piFamily` as a linear map. -/
@[simps]
def piFamilyβ :
(Ξ (p : Ξ i, ΞΊ i), MultilinearMap R (fun i β¦ M i (p i)) (N p))
ββ[R] MultilinearMap R (fun i => Ξ j : ΞΊ i, M i j) (Ξ t : Ξ i, ΞΊ i, N t) where
toFun := piFamily
map_add' := piFamily_add
map_smul' := piFamily_smul
end CommSemiring
end piFamily
end MultilinearMap
|
numdomain.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 ssrAC div fintype path bigop order finset fingroup.
From mathcomp Require Import ssralg poly orderedzmod.
(******************************************************************************)
(* Number structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines some classes to manipulate number structures, i.e, *)
(* structures with an order and a norm. To use this file, insert *)
(* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *)
(* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *)
(* of Num.leif, etc.). *)
(* *)
(* This file defines the following number structures: *)
(* *)
(* semiNormedZmodType == Zmodule with a semi-norm *)
(* The HB class is called SemiNormedZmodule. *)
(* normedZmodType == Zmodule with a norm *)
(* The HB class is called NormedZmodule. *)
(* numDomainType == Integral domain with an order and a norm *)
(* The HB class is called NumDomain. *)
(* *)
(* Over these structures, we have the following operations: *)
(* `|x| == norm of x *)
(* Num.sg x == sign of x: equal to 0 iff x = 0, to 1 iff x > 0, and *)
(* to -1 in all other cases (including x < 0) *)
(* *)
(* - list of prefixes : *)
(* p : positive *)
(* n : negative *)
(* sp : strictly positive *)
(* sn : strictly negative *)
(* i : interior = in [0, 1] or ]0, 1[ *)
(* e : exterior = in [1, +oo[ or ]1; +oo[ *)
(* w : non strict (weak) monotony *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope order_scope.
Local Open Scope group_scope.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory.
Import orderedzmod.Num.
Module Num.
HB.mixin Record Zmodule_isSemiNormed (R : POrderedZmodule.type) M
of GRing.Zmodule M := {
norm : M -> R;
ler_normD : forall x y, norm (x + y) <= norm x + norm y;
normrMn : forall x n, norm (x *+ n) = norm x *+ n;
normrN : forall x, norm (- x) = norm x;
}.
#[short(type="semiNormedZmodType")]
HB.structure Definition SemiNormedZmodule (R : porderZmodType) :=
{ M of Zmodule_isSemiNormed R M & GRing.Zmodule M }.
HB.mixin Record SemiNormedZmodule_isPositiveDefinite
(R : POrderedZmodule.type) M of @SemiNormedZmodule R M := {
normr0_eq0 : forall x : M, norm x = 0 -> x = 0;
}.
#[short(type="normedZmodType")]
HB.structure Definition NormedZmodule (R : porderZmodType) :=
{ M of SemiNormedZmodule_isPositiveDefinite R M & SemiNormedZmodule R M }.
Arguments norm {R M} x : rename.
HB.factory Record Zmodule_isNormed (R : POrderedZmodule.type) M
of GRing.Zmodule M := {
norm : M -> R;
ler_normD : forall x y, norm (x + y) <= norm x + norm y;
normr0_eq0 : forall x, norm x = 0 -> x = 0;
normrMn : forall x n, norm (x *+ n) = norm x *+ n;
normrN : forall x, norm (- x) = norm x;
}.
HB.builders Context (R : POrderedZmodule.type) M of Zmodule_isNormed R M.
HB.instance Definition _ :=
Zmodule_isSemiNormed.Build R M ler_normD normrMn normrN.
HB.instance Definition _ :=
SemiNormedZmodule_isPositiveDefinite.Build R M normr0_eq0.
HB.end.
Module NormedZmoduleExports.
Bind Scope ring_scope with NormedZmodule.sort.
(* Notation "[ 'normedZmodType' R 'of' T 'for' cT ]" :=
(@clone _ (Phant R) T cT _ idfun)
(format "[ 'normedZmodType' R 'of' T 'for' cT ]") :
form_scope.
Notation "[ 'normedZmodType' R 'of' T ]" := (@clone _ (Phant R) T _ _ id)
(format "[ 'normedZmodType' R 'of' T ]") : form_scope. *)
End NormedZmoduleExports.
HB.export NormedZmoduleExports.
HB.mixin Record isNumRing R of GRing.NzRing R & POrderedZmodule R
& NormedZmodule (POrderedZmodule.clone R _) R := {
addr_gt0 : forall x y : R, 0 < x -> 0 < y -> 0 < (x + y);
ger_leVge : forall x y : R, 0 <= x -> 0 <= y -> (x <= y) || (y <= x);
normrM : {morph (norm : R -> R) : x y / x * y};
ler_def : forall x y : R, (x <= y) = (norm (y - x) == (y - x));
}.
#[short(type="numDomainType")]
HB.structure Definition NumDomain := { R of
GRing.IntegralDomain R &
POrderedZmodule R &
NormedZmodule (POrderedZmodule.clone R _) R &
isNumRing R
}.
Arguments addr_gt0 {_} [x y] : rename.
Arguments ger_leVge {_} [x y] : rename.
(* TODO: make isNumDomain depend on intermediate structures *)
(* TODO: make isNumDomain.sort canonically a NumDomain *)
Module NumDomainExports.
Bind Scope ring_scope with NumDomain.sort.
End NumDomainExports.
HB.export NumDomainExports.
Module Export Def.
Notation normr := norm.
Notation "`| x |" := (norm x) : ring_scope.
Section NumDomainDef.
Context {R : numDomainType}.
Definition sgr (x : R) : R := if x == 0 then 0 else if x < 0 then -1 else 1.
End NumDomainDef.
End Def.
Notation sg := sgr.
(* (Exported) symbolic syntax. *)
Module Export Syntax.
Notation "`| x |" := (norm x) : ring_scope.
End Syntax.
Section ExtensionAxioms.
Variable R : numDomainType.
Definition real_axiom : Prop := forall x : R, x \is real.
Definition archimedean_axiom : Prop := forall x : R, exists ub, `|x| < ub%:R.
Definition real_closed_axiom : Prop :=
forall (p : {poly R}) (a b : R),
a <= b -> p.[a] <= 0 <= p.[b] -> exists2 x, a <= x <= b & root p x.
End ExtensionAxioms.
(* The rest of the numbers interface hierarchy. *)
#[short(type="realDomainType")]
HB.structure Definition RealDomain :=
{ R of Order.Total ring_display R & NumDomain R }.
Module RealDomainExports.
Bind Scope ring_scope with RealDomain.sort.
End RealDomainExports.
HB.export RealDomainExports.
(* The elementary theory needed to support the definition of the derived *)
(* operations for the extensions described above. *)
Module Import Internals.
Section NumDomain.
Variable R : numDomainType.
Implicit Types x y : R.
(* Basic consequences (just enough to get predicate closure properties). *)
Lemma ger0_def x : (0 <= x) = (`|x| == x).
Proof. by rewrite ler_def subr0. Qed.
Lemma subr_ge0 x y : (0 <= x - y) = (y <= x).
Proof. by rewrite ger0_def -ler_def. Qed.
Lemma oppr_ge0 x : (0 <= - x) = (x <= 0).
Proof. by rewrite -sub0r subr_ge0. Qed.
Lemma ler01 : 0 <= 1 :> R.
Proof.
have n1_nz: `|1 : R| != 0 by apply: contraNneq (@oner_neq0 R) => /normr0_eq0->.
by rewrite ger0_def -(inj_eq (mulfI n1_nz)) -normrM !mulr1.
Qed.
Lemma ltr01 : 0 < 1 :> R. Proof. by rewrite lt_def oner_neq0 ler01. Qed.
Lemma le0r x : (0 <= x) = (x == 0) || (0 < x).
Proof. by rewrite le_eqVlt eq_sym. Qed.
Lemma addr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof.
rewrite le0r; case/predU1P=> [-> | x_pos]; rewrite ?add0r // le0r.
by case/predU1P=> [-> | y_pos]; rewrite ltW ?addr0 ?addr_gt0.
Qed.
Lemma pmulr_rgt0 x y : 0 < x -> (0 < x * y) = (0 < y).
Proof.
rewrite !lt_def !ger0_def normrM mulf_eq0 negb_or => /andP[x_neq0 /eqP->].
by rewrite x_neq0 (inj_eq (mulfI x_neq0)).
Qed.
(* Closure properties of the real predicates. *)
Lemma posrE x : (x \is pos) = (0 < x). Proof. by []. Qed.
Lemma nnegrE x : (x \is nneg) = (0 <= x). Proof. by []. Qed.
Lemma realE x : (x \is real) = (0 <= x) || (x <= 0). Proof. by []. Qed.
Fact pos_divr_closed : divr_closed (@pos R).
Proof.
split=> [|x y x_gt0 y_gt0]; rewrite posrE ?ltr01 //.
have [Uy|/invr_out->] := boolP (y \is a GRing.unit); last by rewrite pmulr_rgt0.
by rewrite -(pmulr_rgt0 _ y_gt0) mulrC divrK.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rpos_pred
pos_divr_closed.
Fact nneg_divr_closed : divr_closed (@nneg R).
Proof.
split=> [|x y]; rewrite !nnegrE ?ler01 ?le0r // -!posrE.
case/predU1P=> [-> _ | x_gt0]; first by rewrite mul0r eqxx.
by case/predU1P=> [-> | y_gt0]; rewrite ?invr0 ?mulr0 ?eqxx // orbC rpred_div.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rnneg_pred
nneg_divr_closed.
Fact nneg_addr_closed : addr_closed (@nneg R).
Proof. by split; [apply: lexx | apply: addr_ge0]. Qed.
#[export]
HB.instance Definition _ := GRing.isAddClosed.Build R Rnneg_pred
nneg_addr_closed.
Fact real_oppr_closed : oppr_closed (@real R).
Proof. by move=> x; rewrite /= !realE oppr_ge0 orbC -!oppr_ge0 opprK. Qed.
#[export]
HB.instance Definition _ := GRing.isOppClosed.Build R Rreal_pred
real_oppr_closed.
Fact real_addr_closed : addr_closed (@real R).
Proof.
split=> [|x y Rx Ry]; first by rewrite realE lexx.
without loss{Rx} x_ge0: x y Ry / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN opprD; apply; rewrite ?rpredN ?oppr_ge0.
case/orP: Ry => [y_ge0 | y_le0]; first by rewrite realE -nnegrE rpredD.
by rewrite realE -[y]opprK orbC -oppr_ge0 opprB !subr_ge0 ger_leVge ?oppr_ge0.
Qed.
#[export]
HB.instance Definition _ := GRing.isAddClosed.Build R Rreal_pred
real_addr_closed.
Fact real_divr_closed : divr_closed (@real R).
Proof.
split=> [|x y Rx Ry]; first by rewrite realE ler01.
without loss{Rx} x_ge0: x / 0 <= x.
case/orP: Rx => [? | x_le0]; first exact.
by rewrite -rpredN -mulNr; apply; rewrite ?oppr_ge0.
without loss{Ry} y_ge0: y / 0 <= y; last by rewrite realE -nnegrE rpred_div.
case/orP: Ry => [? | y_le0]; first exact.
by rewrite -rpredN -mulrN -invrN; apply; rewrite ?oppr_ge0.
Qed.
#[export]
HB.instance Definition _ := GRing.isDivClosed.Build R Rreal_pred
real_divr_closed.
End NumDomain.
Lemma num_real (R : realDomainType) (x : R) : x \is real.
Proof. exact: le_total. Qed.
Module Exports. HB.reexport. End Exports.
End Internals.
Module PredInstances.
Export Internals.Exports.
End PredInstances.
Module Export Theory.
Section NumIntegralDomainTheory.
Variable R : numDomainType.
Implicit Types (V : semiNormedZmodType R) (x y z t : R).
Implicit Types (W : normedZmodType R).
(* Lemmas from the signature (reexported). *)
Definition ler_normD V (x y : V) : `|x + y| <= `|x| + `|y| :=
ler_normD x y.
Definition addr_gt0 x y : 0 < x -> 0 < y -> 0 < x + y := @addr_gt0 R x y.
Definition normr0_eq0 W (x : W) : `|x| = 0 -> x = 0 := @normr0_eq0 R W x.
Definition ger_leVge x y : 0 <= x -> 0 <= y -> (x <= y) || (y <= x) :=
@ger_leVge R x y.
Definition normrM : {morph norm : x y / (x : R) * y} := @normrM R.
Definition ler_def x y : (x <= y) = (`|y - x| == y - x) := ler_def x y.
Definition normrMn V (x : V) n : `|x *+ n| = `|x| *+ n := normrMn x n.
Definition normrN V (x : V) : `|- x| = `|x| := normrN x.
(* Predicate definitions. *)
Lemma posrE x : (x \is pos) = (0 < x). Proof. by []. Qed.
Lemma negrE x : (x \is neg) = (x < 0). Proof. by []. Qed.
Lemma nnegrE x : (x \is nneg) = (0 <= x). Proof. by []. Qed.
Lemma nposrE x : (x \is npos) = (x <= 0). Proof. by []. Qed.
Lemma realE x : (x \is real) = (0 <= x) || (x <= 0). Proof. by []. Qed.
(* General properties of <= and < *)
Lemma lt0r x : (0 < x) = (x != 0) && (0 <= x). Proof. exact: lt_def. Qed.
Lemma le0r x : (0 <= x) = (x == 0) || (0 < x). Proof. exact: le0r. Qed.
Lemma lt0r_neq0 (x : R) : 0 < x -> x != 0. Proof. by move=> /gt_eqF ->. Qed.
Lemma ltr0_neq0 (x : R) : x < 0 -> x != 0. Proof. by move=> /lt_eqF ->. Qed.
Lemma pmulr_rgt0 x y : 0 < x -> (0 < x * y) = (0 < y).
Proof. exact: pmulr_rgt0. Qed.
Lemma pmulr_rge0 x y : 0 < x -> (0 <= x * y) = (0 <= y).
Proof. by move=> x_gt0; rewrite !le0r mulf_eq0 pmulr_rgt0 // gt_eqF. Qed.
(* Integer comparisons and characteristic 0. *)
Lemma ler01 : 0 <= 1 :> R. Proof. exact: ler01. Qed.
Lemma ltr01 : 0 < 1 :> R. Proof. exact: ltr01. Qed.
Lemma ler0n n : 0 <= n%:R :> R. Proof. by rewrite -nnegrE rpred_nat. Qed.
Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler01) : core.
Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr01) : core.
Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler0n) : core.
Lemma ltr0Sn n : 0 < n.+1%:R :> R.
Proof. by elim: n => // n; apply: addr_gt0. Qed.
Lemma ltr0n n : (0 < n%:R :> R) = (0 < n)%N.
Proof. by case: n => //= n; apply: ltr0Sn. Qed.
Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr0Sn) : core.
Lemma pnatr_eq0 n : (n%:R == 0 :> R) = (n == 0)%N.
Proof. by case: n => [|n]; rewrite ?mulr0n ?eqxx // gt_eqF. Qed.
Lemma pchar_num : [pchar R] =i pred0.
Proof. by case=> // p /=; rewrite !inE pnatr_eq0 andbF. Qed.
(* Properties of the norm. *)
Lemma ger0_def x : (0 <= x) = (`|x| == x). Proof. exact: ger0_def. Qed.
Lemma normr_idP {x} : reflect (`|x| = x) (0 <= x).
Proof. by rewrite ger0_def; apply: eqP. Qed.
Lemma ger0_norm x : 0 <= x -> `|x| = x. Proof. exact: normr_idP. Qed.
Lemma normr1 : `|1 : R| = 1. Proof. exact: ger0_norm. Qed.
Lemma normr_nat n : `|n%:R : R| = n%:R. Proof. exact: ger0_norm. Qed.
Lemma normr_prod I r (P : pred I) (F : I -> R) :
`|\prod_(i <- r | P i) F i| = \prod_(i <- r | P i) `|F i|.
Proof. exact: (big_morph norm normrM normr1). Qed.
Lemma normrX n x : `|x ^+ n| = `|x| ^+ n.
Proof. by rewrite -(card_ord n) -!prodr_const normr_prod. Qed.
Lemma normr_unit : {homo (@norm _ (* R *) R) : x / x \is a GRing.unit}.
Proof.
move=> x /= /unitrP [y [yx xy]]; apply/unitrP; exists `|y|.
by rewrite -!normrM xy yx normr1.
Qed.
Lemma normrV : {in GRing.unit, {morph (@norm _ (* R *) R) : x / x ^-1}}.
Proof.
move=> x ux; apply: (mulrI (normr_unit ux)).
by rewrite -normrM !divrr ?normr1 ?normr_unit.
Qed.
Lemma normrN1 : `|-1 : R| = 1.
Proof.
have: `|-1 : R| ^+ 2 == 1 by rewrite -normrX -signr_odd normr1.
rewrite sqrf_eq1 => /orP[/eqP //|]; rewrite -ger0_def le0r oppr_eq0 oner_eq0.
by move/(addr_gt0 ltr01); rewrite subrr ltxx.
Qed.
Lemma big_real x0 op I (P : pred I) F (s : seq I) :
{in real &, forall x y, op x y \is real} -> x0 \is real ->
{in P, forall i, F i \is real} -> \big[op/x0]_(i <- s | P i) F i \is real.
Proof. exact: comparable_bigr. Qed.
Lemma sum_real I (P : pred I) (F : I -> R) (s : seq I) :
{in P, forall i, F i \is real} -> \sum_(i <- s | P i) F i \is real.
Proof. by apply/big_real; [apply: rpredD | apply: rpred0]. Qed.
Lemma prod_real I (P : pred I) (F : I -> R) (s : seq I) :
{in P, forall i, F i \is real} -> \prod_(i <- s | P i) F i \is real.
Proof. by apply/big_real; [apply: rpredM | apply: rpred1]. Qed.
Section SemiNormedZmoduleTheory.
Variable V : semiNormedZmodType R.
Implicit Types (v w : V).
Lemma normr0 : `|0 : V| = 0.
Proof. by rewrite -(mulr0n 0) normrMn mulr0n. Qed.
Lemma distrC v w : `|v - w| = `|w - v|.
Proof. by rewrite -opprB normrN. Qed.
Lemma normr_id v : `| `|v| | = `|v|.
Proof.
have nz2: 2 != 0 :> R by rewrite pnatr_eq0.
apply: (mulfI nz2); rewrite -{1}normr_nat -normrM mulr_natl mulr2n ger0_norm //.
by rewrite -{2}normrN -normr0 -(subrr v) ler_normD.
Qed.
Lemma normr_ge0 v : 0 <= `|v|. Proof. by rewrite ger0_def normr_id. Qed.
Lemma normr_lt0 v : `|v| < 0 = false.
Proof. by rewrite le_gtF// normr_ge0. Qed.
Lemma gtr0_norm_neq0 v : `|v| > 0 -> (v != 0).
Proof. by apply: contra_ltN => /eqP->; rewrite normr0. Qed.
Lemma gtr0_norm_eq0F v : `|v| > 0 -> (v == 0) = false.
Proof. by move=> /gtr0_norm_neq0/negPf->. Qed.
End SemiNormedZmoduleTheory.
Section NormedZmoduleTheory.
Variable V : normedZmodType R.
Implicit Types (v w : V).
Lemma normr0P v : reflect (`|v| = 0) (v == 0).
Proof. by apply: (iffP eqP)=> [->|/normr0_eq0 //]; apply: normr0. Qed.
Definition normr_eq0 v := sameP (`|v| =P 0) (normr0P v).
Lemma normr_le0 v : `|v| <= 0 = (v == 0).
Proof. by rewrite -normr_eq0 eq_le normr_ge0 andbT. Qed.
Lemma normr_gt0 v : `|v| > 0 = (v != 0).
Proof. by rewrite lt_def normr_eq0 normr_ge0 andbT. Qed.
End NormedZmoduleTheory.
Definition normrE := (normr_id, normr0, normr1, normrN1, normr_ge0, normr_eq0,
normr_lt0, normr_le0, normr_gt0, normrN).
Lemma ler0_def x : (x <= 0) = (`|x| == - x).
Proof. by rewrite ler_def sub0r normrN. Qed.
Lemma ler0_norm x : x <= 0 -> `|x| = - x.
Proof. by move=> x_le0; rewrite -[r in _ = r]ger0_norm ?normrN ?oppr_ge0. Qed.
Definition gtr0_norm x (hx : 0 < x) := ger0_norm (ltW hx).
Definition ltr0_norm x (hx : x < 0) := ler0_norm (ltW hx).
Lemma ger0_le_norm :
{in nneg &, {mono (@normr _ R) : x y / x <= y}}.
Proof. by move=> x y; rewrite !nnegrE => x0 y0; rewrite !ger0_norm. Qed.
Lemma gtr0_le_norm :
{in pos &, {mono (@normr _ R) : x y / x <= y}}.
Proof. by move=> x y; rewrite !posrE => /ltW x0 /ltW y0; exact: ger0_le_norm. Qed.
Lemma ler0_ge_norm :
{in npos &, {mono (@normr _ R) : x y / x <= y >-> x >= y}}.
Proof.
move=> x y; rewrite !nposrE => x0 y0.
by rewrite !ler0_norm// -[LHS]subr_ge0 opprK addrC subr_ge0.
Qed.
Lemma ltr0_ge_norm :
{in neg &, {mono (@normr _ R) : x y / x <= y >-> x >= y}}.
Proof. by move=> x y; rewrite !negrE => /ltW x0 /ltW y0; exact: ler0_ge_norm. Qed.
(* Comparison to 0 of a difference *)
Lemma subr_ge0 x y : (0 <= y - x) = (x <= y). Proof. exact: subr_ge0. Qed.
Lemma subr_gt0 x y : (0 < y - x) = (x < y).
Proof. by rewrite !lt_def subr_eq0 subr_ge0. Qed.
Lemma subr_le0 x y : (y - x <= 0) = (y <= x).
Proof. by rewrite -[LHS]subr_ge0 opprB add0r subr_ge0. Qed. (* FIXME: rewrite pattern *)
Lemma subr_lt0 x y : (y - x < 0) = (y < x).
Proof. by rewrite -[LHS]subr_gt0 opprB add0r subr_gt0. Qed. (* FIXME: rewrite pattern *)
Definition subr_lte0 := (subr_le0, subr_lt0).
Definition subr_gte0 := (subr_ge0, subr_gt0).
Definition subr_cp0 := (subr_lte0, subr_gte0).
(* Comparability in a numDomain *)
Lemma comparable0r x : (0 >=< x)%R = (x \is Num.real). Proof. by []. Qed.
Lemma comparabler0 x : (x >=< 0)%R = (x \is Num.real).
Proof. by rewrite comparable_sym. Qed.
Lemma subr_comparable0 x y : (x - y >=< 0)%R = (x >=< y)%R.
Proof. by rewrite /comparable subr_ge0 subr_le0. Qed.
Lemma comparablerE x y : (x >=< y)%R = (x - y \is Num.real).
Proof. by rewrite -comparabler0 subr_comparable0. Qed.
Lemma comparabler_trans : transitive (comparable : rel R).
Proof.
move=> y x z; rewrite !comparablerE => xBy_real yBz_real.
by have := rpredD xBy_real yBz_real; rewrite addrA addrNK.
Qed.
(* Ordered ring properties. *)
Definition lter01 := (ler01, ltr01).
Lemma addr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof. exact: addr_ge0. Qed.
End NumIntegralDomainTheory.
#[deprecated(since="mathcomp 2.4.0",note="Use pchar_num instead.")]
Notation char_num := pchar_num (only parsing).
Arguments ler01 {R}.
Arguments ltr01 {R}.
Arguments normr_idP {R x}.
Arguments normr0P {R V v}.
#[global] Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler01) : core.
#[global] Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr01) : core.
#[global] Hint Extern 0 (is_true (@Order.le ring_display _ _ _)) =>
(apply: ler0n) : core.
#[global] Hint Extern 0 (is_true (@Order.lt ring_display _ _ _)) =>
(apply: ltr0Sn) : core.
#[global] Hint Extern 0 (is_true (0 <= norm _)) => apply: normr_ge0 : core.
Lemma normr_nneg (R : numDomainType) (x : R) : `|x| \is Num.nneg.
Proof. by rewrite qualifE /=. Qed.
#[global] Hint Resolve normr_nneg : core.
Section NumDomainOperationTheory.
Variable R : numDomainType.
Implicit Types x y z t : R.
(* Comparison and opposite. *)
Lemma lerN2 : {mono -%R : x y /~ x <= y :> R}.
Proof. by move=> x y /=; rewrite -subr_ge0 opprK addrC subr_ge0. Qed.
Hint Resolve lerN2 : core.
Lemma ltrN2 : {mono -%R : x y /~ x < y :> R}.
Proof. by move=> x y /=; rewrite leW_nmono. Qed.
Hint Resolve ltrN2 : core.
Definition lterN2 := (lerN2, ltrN2).
Lemma lerNr x y : (x <= - y) = (y <= - x).
Proof. by rewrite (monoRL opprK lerN2). Qed.
Lemma ltrNr x y : (x < - y) = (y < - x).
Proof. by rewrite (monoRL opprK (leW_nmono _)). Qed.
Definition lterNr := (lerNr, ltrNr).
Lemma lerNl x y : (- x <= y) = (- y <= x).
Proof. by rewrite (monoLR opprK lerN2). Qed.
Lemma ltrNl x y : (- x < y) = (- y < x).
Proof. by rewrite (monoLR opprK (leW_nmono _)). Qed.
Definition lterNl := (lerNl, ltrNl).
Lemma oppr_ge0 x : (0 <= - x) = (x <= 0). Proof. by rewrite lerNr oppr0. Qed.
Lemma oppr_gt0 x : (0 < - x) = (x < 0). Proof. by rewrite ltrNr oppr0. Qed.
Definition oppr_gte0 := (oppr_ge0, oppr_gt0).
Lemma oppr_le0 x : (- x <= 0) = (0 <= x). Proof. by rewrite lerNl oppr0. Qed.
Lemma oppr_lt0 x : (- x < 0) = (0 < x). Proof. by rewrite ltrNl oppr0. Qed.
Lemma gtrN x : 0 < x -> - x < x.
Proof. by move=> n0; rewrite -subr_lt0 -opprD oppr_lt0 addr_gt0. Qed.
Definition oppr_lte0 := (oppr_le0, oppr_lt0).
Definition oppr_cp0 := (oppr_gte0, oppr_lte0).
Definition lterNE := (oppr_cp0, lterN2).
Lemma ge0_cp x : 0 <= x -> (- x <= 0) * (- x <= x).
Proof. by move=> hx; rewrite oppr_cp0 hx (@le_trans _ _ 0) ?oppr_cp0. Qed.
Lemma gt0_cp x : 0 < x ->
(0 <= x) * (- x <= 0) * (- x <= x) * (- x < 0) * (- x < x).
Proof.
move=> hx; move: (ltW hx) => hx'; rewrite !ge0_cp hx' //.
by rewrite oppr_cp0 hx // (@lt_trans _ _ 0) ?oppr_cp0.
Qed.
Lemma le0_cp x : x <= 0 -> (0 <= - x) * (x <= - x).
Proof. by move=> hx; rewrite oppr_cp0 hx (@le_trans _ _ 0) ?oppr_cp0. Qed.
Lemma lt0_cp x :
x < 0 -> (x <= 0) * (0 <= - x) * (x <= - x) * (0 < - x) * (x < - x).
Proof.
move=> hx; move: (ltW hx) => hx'; rewrite !le0_cp // hx'.
by rewrite oppr_cp0 hx // (@lt_trans _ _ 0) ?oppr_cp0.
Qed.
(* Properties of the real subset. *)
Lemma ger0_real x : 0 <= x -> x \is real.
Proof. by rewrite realE => ->. Qed.
Lemma ler0_real x : x <= 0 -> x \is real.
Proof. by rewrite realE orbC => ->. Qed.
Lemma gtr0_real x : 0 < x -> x \is real. Proof. by move=> /ltW/ger0_real. Qed.
Lemma ltr0_real x : x < 0 -> x \is real. Proof. by move=> /ltW/ler0_real. Qed.
Lemma real0 : 0 \is @real R. Proof. exact: rpred0. Qed.
Lemma real1 : 1 \is @real R. Proof. exact: rpred1. Qed.
Lemma realn n : n%:R \is @real R. Proof. exact: rpred_nat. Qed.
#[local] Hint Resolve real0 real1 : core.
Lemma ler_leVge x y : x <= 0 -> y <= 0 -> (x <= y) || (y <= x).
Proof. by rewrite -!oppr_ge0 => /(ger_leVge _) /[apply]; rewrite !lerN2. Qed.
Lemma real_leVge x y : x \is real -> y \is real -> (x <= y) || (y <= x).
Proof. by rewrite -comparabler0 -comparable0r => /comparabler_trans P/P. Qed.
Lemma real_comparable x y : x \is real -> y \is real -> x >=< y.
Proof. exact: real_leVge. Qed.
Lemma realB : {in real &, forall x y, x - y \is real}.
Proof. exact: rpredB. Qed.
Lemma realN : {mono (@GRing.opp R) : x / x \is real}.
Proof. exact: rpredN. Qed.
Lemma realBC x y : (x - y \is real) = (y - x \is real).
Proof. exact: rpredBC. Qed.
Lemma realD : {in real &, forall x y, x + y \is real}.
Proof. exact: rpredD. Qed.
(* dichotomy and trichotomy *)
Variant ler_xor_gt (x y : R) : R -> R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| LerNotGt of x <= y : ler_xor_gt x y x x y y (y - x) (y - x) true false
| GtrNotLe of y < x : ler_xor_gt x y y y x x (x - y) (x - y) false true.
Variant ltr_xor_ge (x y : R) : R -> R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| LtrNotGe of x < y : ltr_xor_ge x y x x y y (y - x) (y - x) false true
| GerNotLt of y <= x : ltr_xor_ge x y y y x x (x - y) (x - y) true false.
Variant comparer x y : R -> R -> R -> R -> R -> R ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparerLt of x < y : comparer x y x x y y (y - x) (y - x)
false false false true false true
| ComparerGt of x > y : comparer x y y y x x (x - y) (x - y)
false false true false true false
| ComparerEq of x = y : comparer x y x x x x 0 0
true true true true false false.
Lemma real_leP x y : x \is real -> y \is real ->
ler_xor_gt x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (x <= y) (y < x).
Proof.
move=> xR yR; case: (comparable_leP (real_leVge xR yR)) => xy.
- by rewrite [`|x - y|]distrC !ger0_norm ?subr_cp0 //; constructor.
- by rewrite [`|y - x|]distrC !gtr0_norm ?subr_cp0 //; constructor.
Qed.
Lemma real_ltP x y : x \is real -> y \is real ->
ltr_xor_ge x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y <= x) (x < y).
Proof. by move=> xR yR; case: real_leP=> //; constructor. Qed.
Lemma real_ltNge : {in real &, forall x y, (x < y) = ~~ (y <= x)}.
Proof. by move=> x y xR yR /=; case: real_leP. Qed.
Lemma real_leNgt : {in real &, forall x y, (x <= y) = ~~ (y < x)}.
Proof. by move=> x y xR yR /=; case: real_leP. Qed.
Lemma real_ltgtP x y : x \is real -> y \is real ->
comparer x y (min y x) (min x y) (max y x) (max x y) `|x - y| `|y - x|
(y == x) (x == y) (x >= y) (x <= y) (x > y) (x < y).
Proof.
move=> xR yR; case: (comparable_ltgtP (real_leVge yR xR)) => [?|?|->].
- by rewrite [`|y - x|]distrC !gtr0_norm ?subr_gt0//; constructor.
- by rewrite [`|x - y|]distrC !gtr0_norm ?subr_gt0//; constructor.
- by rewrite subrr normr0; constructor.
Qed.
Variant ger0_xor_lt0 (x : R) : R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| Ger0NotLt0 of 0 <= x : ger0_xor_lt0 x 0 0 x x x false true
| Ltr0NotGe0 of x < 0 : ger0_xor_lt0 x x x 0 0 (- x) true false.
Variant ler0_xor_gt0 (x : R) : R -> R -> R -> R -> R ->
bool -> bool -> Set :=
| Ler0NotLe0 of x <= 0 : ler0_xor_gt0 x x x 0 0 (- x) false true
| Gtr0NotGt0 of 0 < x : ler0_xor_gt0 x 0 0 x x x true false.
Variant comparer0 x : R -> R -> R -> R -> R ->
bool -> bool -> bool -> bool -> bool -> bool -> Set :=
| ComparerGt0 of 0 < x : comparer0 x 0 0 x x x false false false true false true
| ComparerLt0 of x < 0 : comparer0 x x x 0 0 (- x) false false true false true false
| ComparerEq0 of x = 0 : comparer0 x 0 0 0 0 0 true true true true false false.
Lemma real_ge0P x : x \is real -> ger0_xor_lt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (x < 0) (0 <= x).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: real_leP;
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma real_le0P x : x \is real -> ler0_xor_gt0 x
(min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 < x) (x <= 0).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: real_ltP;
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma real_ltgt0P x : x \is real ->
comparer0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 == x) (x == 0) (x <= 0) (0 <= x) (x < 0) (x > 0).
Proof.
move=> hx; rewrite -[X in `|X|]subr0; case: (@real_ltgtP 0 x);
by rewrite ?subr0 ?sub0r //; constructor.
Qed.
Lemma max_real : {in real &, forall x y, max x y \is real}.
Proof. exact: comparable_maxr. Qed.
Lemma min_real : {in real &, forall x y, min x y \is real}.
Proof. exact: comparable_minr. Qed.
Lemma bigmax_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is real -> {in P, forall i : I, f i \is real} ->
\big[max/x0]_(i <- r | P i) f i \is real.
Proof. exact/big_real/max_real. Qed.
Lemma bigmin_real I x0 (r : seq I) (P : pred I) (f : I -> R):
x0 \is real -> {in P, forall i : I, f i \is real} ->
\big[min/x0]_(i <- r | P i) f i \is real.
Proof. exact/big_real/min_real. Qed.
Lemma real_neqr_lt : {in real &, forall x y, (x != y) = (x < y) || (y < x)}.
Proof. by move=> * /=; case: real_ltgtP. Qed.
Lemma lerB_real x y : x <= y -> y - x \is real.
Proof. by move=> le_xy; rewrite ger0_real // subr_ge0. Qed.
Lemma gerB_real x y : x <= y -> x - y \is real.
Proof. by move=> le_xy; rewrite ler0_real // subr_le0. Qed.
Lemma ler_real y x : x <= y -> (x \is real) = (y \is real).
Proof. by move=> le_xy; rewrite -(addrNK x y) rpredDl ?lerB_real. Qed.
Lemma ger_real x y : y <= x -> (x \is real) = (y \is real).
Proof. by move=> le_yx; rewrite -(ler_real le_yx). Qed.
Lemma ger1_real x : 1 <= x -> x \is real. Proof. by move=> /ger_real->. Qed.
Lemma ler1_real x : x <= 1 -> x \is real. Proof. by move=> /ler_real->. Qed.
Lemma Nreal_leF x y : y \is real -> x \notin real -> (x <= y) = false.
Proof. by move=> yR; apply: contraNF=> /ler_real->. Qed.
Lemma Nreal_geF x y : y \is real -> x \notin real -> (y <= x) = false.
Proof. by move=> yR; apply: contraNF=> /ger_real->. Qed.
Lemma Nreal_ltF x y : y \is real -> x \notin real -> (x < y) = false.
Proof. by move=> yR xNR; rewrite lt_def Nreal_leF ?andbF. Qed.
Lemma Nreal_gtF x y : y \is real -> x \notin real -> (y < x) = false.
Proof. by move=> yR xNR; rewrite lt_def Nreal_geF ?andbF. Qed.
(* real wlog *)
Lemma real_wlog_ler P :
(forall a b, P b a -> P a b) -> (forall a b, a <= b -> P a b) ->
forall a b : R, a \is real -> b \is real -> P a b.
Proof.
move=> sP hP a b ha hb; wlog: a b ha hb / a <= b => [hwlog|]; last exact: hP.
by case: (real_leP ha hb)=> [/hP //|/ltW hba]; apply/sP/hP.
Qed.
Lemma real_wlog_ltr P :
(forall a, P a a) -> (forall a b, (P b a -> P a b)) ->
(forall a b, a < b -> P a b) ->
forall a b : R, a \is real -> b \is real -> P a b.
Proof.
move=> rP sP hP; apply: real_wlog_ler=> // a b.
by rewrite le_eqVlt; case: eqVneq => [->|] //= _ /hP.
Qed.
(* Monotony of addition *)
Lemma lerD2l x : {mono +%R x : y z / y <= z}.
Proof. by move=> y z; rewrite -subr_ge0 opprD addrAC addNKr addrC subr_ge0. Qed.
Lemma lerD2r x : {mono +%R^~ x : y z / y <= z}.
Proof. by move=> y z; rewrite ![_ + x]addrC lerD2l. Qed.
Lemma ltrD2l x : {mono +%R x : y z / y < z}.
Proof. by move=> y z; rewrite (leW_mono (lerD2l _)). Qed.
Lemma ltrD2r x : {mono +%R^~ x : y z / y < z}.
Proof. by move=> y z /=; rewrite (leW_mono (lerD2r _)). Qed.
Definition lerD2 := (lerD2l, lerD2r).
Definition ltrD2 := (ltrD2l, ltrD2r).
Definition lterD2 := (lerD2, ltrD2).
(* Addition, subtraction and transitivity *)
Lemma lerD x y z t : x <= y -> z <= t -> x + z <= y + t.
Proof. by move=> lxy lzt; rewrite (@le_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ler_ltD x y z t : x <= y -> z < t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite (@le_lt_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ltr_leD x y z t : x < y -> z <= t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite (@lt_le_trans _ _ (y + z)) ?lterD2. Qed.
Lemma ltrD x y z t : x < y -> z < t -> x + z < y + t.
Proof. by move=> lxy lzt; rewrite ltr_leD // ltW. Qed.
Lemma lerB x y z t : x <= y -> t <= z -> x - z <= y - t.
Proof. by move=> lxy ltz; rewrite lerD // lterN2. Qed.
Lemma ler_ltB x y z t : x <= y -> t < z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ler_ltD // lterN2. Qed.
Lemma ltr_leB x y z t : x < y -> t <= z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ltr_leD // lterN2. Qed.
Lemma ltrB x y z t : x < y -> t < z -> x - z < y - t.
Proof. by move=> lxy lzt; rewrite ltrD // lterN2. Qed.
Lemma lerBlDr x y z : (x - y <= z) = (x <= z + y).
Proof. by rewrite (monoLR (addrK _) (lerD2r _)). Qed.
Lemma ltrBlDr x y z : (x - y < z) = (x < z + y).
Proof. by rewrite (monoLR (addrK _) (ltrD2r _)). Qed.
Lemma lerBrDr x y z : (x <= y - z) = (x + z <= y).
Proof. by rewrite (monoLR (addrNK _) (lerD2r _)). Qed.
Lemma ltrBrDr x y z : (x < y - z) = (x + z < y).
Proof. by rewrite (monoLR (addrNK _) (ltrD2r _)). Qed.
Definition lerBDr := (lerBlDr, lerBrDr).
Definition ltrBDr := (ltrBlDr, ltrBrDr).
Definition lterBDr := (lerBDr, ltrBDr).
Lemma lerBlDl x y z : (x - y <= z) = (x <= y + z).
Proof. by rewrite lterBDr addrC. Qed.
Lemma ltrBlDl x y z : (x - y < z) = (x < y + z).
Proof. by rewrite lterBDr addrC. Qed.
Lemma lerBrDl x y z : (x <= y - z) = (z + x <= y).
Proof. by rewrite lerBrDr addrC. Qed.
Lemma ltrBrDl x y z : (x < y - z) = (z + x < y).
Proof. by rewrite lterBDr addrC. Qed.
Definition lerBDl := (lerBlDl, lerBrDl).
Definition ltrBDl := (ltrBlDl, ltrBrDl).
Definition lterBDl := (lerBDl, ltrBDl).
Lemma lerDl x y : (x <= x + y) = (0 <= y).
Proof. by rewrite -{1}[x]addr0 lterD2. Qed.
Lemma ltrDl x y : (x < x + y) = (0 < y).
Proof. by rewrite -{1}[x]addr0 lterD2. Qed.
Lemma lerDr x y : (x <= y + x) = (0 <= y).
Proof. by rewrite -{1}[x]add0r lterD2. Qed.
Lemma ltrDr x y : (x < y + x) = (0 < y).
Proof. by rewrite -{1}[x]add0r lterD2. Qed.
Lemma gerDl x y : (x + y <= x) = (y <= 0).
Proof. by rewrite -{2}[x]addr0 lterD2. Qed.
Lemma gerBl x y : (x - y <= x) = (0 <= y).
Proof. by rewrite lerBlDl lerDr. Qed.
Lemma gtrDl x y : (x + y < x) = (y < 0).
Proof. by rewrite -{2}[x]addr0 lterD2. Qed.
Lemma gtrBl x y : (x - y < x) = (0 < y).
Proof. by rewrite ltrBlDl ltrDr. Qed.
Lemma gerDr x y : (y + x <= x) = (y <= 0).
Proof. by rewrite -{2}[x]add0r lterD2. Qed.
Lemma gtrDr x y : (y + x < x) = (y < 0).
Proof. by rewrite -{2}[x]add0r lterD2. Qed.
Definition cprD := (lerDl, lerDr, gerDl, gerDl,
ltrDl, ltrDr, gtrDl, gtrDl).
(* Addition with left member known to be positive/negative *)
Lemma ler_wpDl y x z : 0 <= x -> y <= z -> y <= x + z.
Proof. by move=> *; rewrite -[y]add0r lerD. Qed.
Lemma ltr_wpDl y x z : 0 <= x -> y < z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ler_ltD. Qed.
Lemma ltr_pwDl y x z : 0 < x -> y <= z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ltr_leD. Qed.
Lemma ltr_pDl y x z : 0 < x -> y < z -> y < x + z.
Proof. by move=> *; rewrite -[y]add0r ltrD. Qed.
Lemma ler_wnDl y x z : x <= 0 -> y <= z -> x + y <= z.
Proof. by move=> *; rewrite -[z]add0r lerD. Qed.
Lemma ltr_wnDl y x z : x <= 0 -> y < z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ler_ltD. Qed.
Lemma ltr_nwDl y x z : x < 0 -> y <= z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ltr_leD. Qed.
Lemma ltr_nDl y x z : x < 0 -> y < z -> x + y < z.
Proof. by move=> *; rewrite -[z]add0r ltrD. Qed.
(* Addition with right member we know positive/negative *)
Lemma ler_wpDr y x z : 0 <= x -> y <= z -> y <= z + x.
Proof. by move=> *; rewrite addrC ler_wpDl. Qed.
Lemma ltr_wpDr y x z : 0 <= x -> y < z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_wpDl. Qed.
Lemma ltr_pwDr y x z : 0 < x -> y <= z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_pwDl. Qed.
Lemma ltr_pDr y x z : 0 < x -> y < z -> y < z + x.
Proof. by move=> *; rewrite addrC ltr_pDl. Qed.
Lemma ler_wnDr y x z : x <= 0 -> y <= z -> y + x <= z.
Proof. by move=> *; rewrite addrC ler_wnDl. Qed.
Lemma ltr_wnDr y x z : x <= 0 -> y < z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_wnDl. Qed.
Lemma ltr_nwDr y x z : x < 0 -> y <= z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_nwDl. Qed.
Lemma ltr_nDr y x z : x < 0 -> y < z -> y + x < z.
Proof. by move=> *; rewrite addrC ltr_nDl. Qed.
(* x and y have the same sign and their sum is null *)
Lemma paddr_eq0 (x y : R) :
0 <= x -> 0 <= y -> (x + y == 0) = (x == 0) && (y == 0).
Proof.
rewrite le0r; case/orP=> [/eqP->|hx]; first by rewrite add0r eqxx.
by rewrite (gt_eqF hx) /= => hy; rewrite gt_eqF // ltr_pwDl.
Qed.
Lemma naddr_eq0 (x y : R) :
x <= 0 -> y <= 0 -> (x + y == 0) = (x == 0) && (y == 0).
Proof.
by move=> lex0 ley0; rewrite -oppr_eq0 opprD paddr_eq0 ?oppr_cp0 // !oppr_eq0.
Qed.
Lemma addr_ss_eq0 (x y : R) :
(0 <= x) && (0 <= y) || (x <= 0) && (y <= 0) ->
(x + y == 0) = (x == 0) && (y == 0).
Proof. by case/orP=> /andP []; [apply: paddr_eq0 | apply: naddr_eq0]. Qed.
(* big sum and ler *)
Lemma sumr_ge0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> 0 <= \sum_(i <- r | P i) (F i).
Proof. exact: (big_ind _ _ (@ler_wpDl 0)). Qed.
Lemma sumr_le0 I (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> F i <= 0) -> \sum_(i <- r | P i) F i <= 0.
Proof. by move=> F0; elim/big_ind : _ => // i x Pi; exact/ler_wnDl. Qed.
Lemma ler_sum I (r : seq I) (P : pred I) (F G : I -> R) :
(forall i, P i -> F i <= G i) ->
\sum_(i <- r | P i) F i <= \sum_(i <- r | P i) G i.
Proof. exact: (big_ind2 _ (lexx _) lerD). Qed.
Lemma ler_sum_nat (m n : nat) (F G : nat -> R) :
(forall i, (m <= i < n)%N -> F i <= G i) ->
\sum_(m <= i < n) F i <= \sum_(m <= i < n) G i.
Proof. by move=> le_FG; rewrite !big_nat ler_sum. Qed.
Lemma ltr_sum I (r : seq I) (P : pred I) (F G : I -> R) :
has P r -> (forall i, P i -> F i < G i) ->
\sum_(i <- r | P i) F i < \sum_(i <- r | P i) G i.
Proof.
rewrite -big_filter -[ltRHS]big_filter -size_filter_gt0.
case: filter (filter_all P r) => //= x {}r /andP[Px Pr] _ ltFG.
rewrite !big_cons ltr_leD// ?ltFG// -(all_filterP Pr) !big_filter.
by rewrite ler_sum => // i Pi; rewrite ltW ?ltFG.
Qed.
Lemma ltr_sum_nat (m n : nat) (F G : nat -> R) :
(m < n)%N -> (forall i, (m <= i < n)%N -> F i < G i) ->
\sum_(m <= i < n) F i < \sum_(m <= i < n) G i.
Proof.
move=> lt_mn i; rewrite big_nat [ltRHS]big_nat ltr_sum//.
by apply/hasP; exists m; rewrite ?mem_index_iota leqnn lt_mn.
Qed.
Lemma psumr_eq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) == 0) = (all (fun i => (P i) ==> (F i == 0)) r).
Proof.
elim: r=> [|a r ihr hr] /=; rewrite (big_nil, big_cons); first by rewrite eqxx.
by case: ifP=> pa /=; rewrite ?paddr_eq0 ?ihr ?hr // sumr_ge0.
Qed.
(* :TODO: Cyril : See which form to keep *)
Lemma psumr_eq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i = 0 ->
(forall i, P i -> F i = 0).
Proof.
move=> F_ge0 /eqP; rewrite psumr_eq0 // -big_all big_andE => /forallP hF i Pi.
by move: (hF i); rewrite implyTb Pi /= => /eqP.
Qed.
Lemma psumr_neq0 (I : eqType) (r : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) ->
(\sum_(i <- r | P i) (F i) != 0) = (has (fun i => P i && (0 < F i)) r).
Proof.
move=> F_ge0; rewrite psumr_eq0// -has_predC; apply: eq_has => x /=.
by case Px: (P x); rewrite //= lt_def F_ge0 ?andbT.
Qed.
Lemma psumr_neq0P (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i) -> \sum_(i | P i) F i <> 0 ->
(exists i, P i && (0 < F i)).
Proof. by move=> ? /eqP; rewrite psumr_neq0// => /hasP[x _ ?]; exists x. Qed.
(* mulr and ler/ltr *)
Lemma ler_pM2l x : 0 < x -> {mono *%R x : x y / x <= y}.
Proof.
by move=> x_gt0 y z /=; rewrite -subr_ge0 -mulrBr pmulr_rge0 // subr_ge0.
Qed.
Lemma ltr_pM2l x : 0 < x -> {mono *%R x : x y / x < y}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pM2l _). Qed.
Definition lter_pM2l := (ler_pM2l, ltr_pM2l).
Lemma ler_pM2r x : 0 < x -> {mono *%R^~ x : x y / x <= y}.
Proof. by move=> x_gt0 y z /=; rewrite ![_ * x]mulrC ler_pM2l. Qed.
Lemma ltr_pM2r x : 0 < x -> {mono *%R^~ x : x y / x < y}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pM2r _). Qed.
Definition lter_pM2r := (ler_pM2r, ltr_pM2r).
Lemma ler_nM2l x : x < 0 -> {mono *%R x : x y /~ x <= y}.
Proof. by move=> x_lt0 y z /=; rewrite -lerN2 -!mulNr ler_pM2l ?oppr_gt0. Qed.
Lemma ltr_nM2l x : x < 0 -> {mono *%R x : x y /~ x < y}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nM2l _). Qed.
Definition lter_nM2l := (ler_nM2l, ltr_nM2l).
Lemma ler_nM2r x : x < 0 -> {mono *%R^~ x : x y /~ x <= y}.
Proof. by move=> x_lt0 y z /=; rewrite ![_ * x]mulrC ler_nM2l. Qed.
Lemma ltr_nM2r x : x < 0 -> {mono *%R^~ x : x y /~ x < y}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nM2r _). Qed.
Definition lter_nM2r := (ler_nM2r, ltr_nM2r).
Lemma ler_wpM2l x : 0 <= x -> {homo *%R x : y z / y <= z}.
Proof.
by rewrite le0r => /orP[/eqP-> y z | /ler_pM2l/mono2W//]; rewrite !mul0r.
Qed.
Lemma ler_wpM2r x : 0 <= x -> {homo *%R^~ x : y z / y <= z}.
Proof. by move=> x_ge0 y z leyz; rewrite ![_ * x]mulrC ler_wpM2l. Qed.
Lemma ler_wnM2l x : x <= 0 -> {homo *%R x : y z /~ y <= z}.
by move=> x_le0 y z leyz; rewrite -![x * _]mulrNN ler_wpM2l ?lterNE. Qed.
Lemma ler_wnM2r x : x <= 0 -> {homo *%R^~ x : y z /~ y <= z}.
Proof. by move=> x_le0 y z leyz; rewrite -![_ * x]mulrNN ler_wpM2r ?lterNE. Qed.
(* Binary forms, for backchaining. *)
Lemma ler_pM x1 y1 x2 y2 :
0 <= x1 -> 0 <= x2 -> x1 <= y1 -> x2 <= y2 -> x1 * x2 <= y1 * y2.
Proof.
move=> x1ge0 x2ge0 le_xy1 le_xy2; have y1ge0 := le_trans x1ge0 le_xy1.
exact: le_trans (ler_wpM2r x2ge0 le_xy1) (ler_wpM2l y1ge0 le_xy2).
Qed.
Lemma ltr_pM x1 y1 x2 y2 :
0 <= x1 -> 0 <= x2 -> x1 < y1 -> x2 < y2 -> x1 * x2 < y1 * y2.
Proof.
move=> x1ge0 x2ge0 lt_xy1 lt_xy2; have y1gt0 := le_lt_trans x1ge0 lt_xy1.
by rewrite (le_lt_trans (ler_wpM2r x2ge0 (ltW lt_xy1))) ?ltr_pM2l.
Qed.
(* complement for x *+ n and <= or < *)
Lemma ler_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x <= y}.
Proof.
by case: n => // n _ x y /=; rewrite -mulr_natl -[y *+ _]mulr_natl ler_pM2l.
Qed.
Lemma ltr_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x < y}.
Proof. by move/ler_pMn2r/leW_mono. Qed.
Lemma pmulrnI n : (0 < n)%N -> injective ((@GRing.natmul R)^~ n).
Proof. by move/ler_pMn2r/inc_inj. Qed.
Lemma eqr_pMn2r n : (0 < n)%N -> {mono (@GRing.natmul R)^~ n : x y / x == y}.
Proof. by move/pmulrnI/inj_eq. Qed.
Lemma pmulrn_lgt0 x n : (0 < n)%N -> (0 < x *+ n) = (0 < x).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ltr_pMn2r // mul0rn. Qed.
Lemma pmulrn_llt0 x n : (0 < n)%N -> (x *+ n < 0) = (x < 0).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ltr_pMn2r // mul0rn. Qed.
Lemma pmulrn_lge0 x n : (0 < n)%N -> (0 <= x *+ n) = (0 <= x).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ler_pMn2r // mul0rn. Qed.
Lemma pmulrn_lle0 x n : (0 < n)%N -> (x *+ n <= 0) = (x <= 0).
Proof. by move=> n_gt0; rewrite -(mul0rn _ n) ler_pMn2r // mul0rn. Qed.
Lemma ltr_wMn2r x y n : x < y -> (x *+ n < y *+ n) = (0 < n)%N.
Proof. by move=> ltxy; case: n=> // n; rewrite ltr_pMn2r. Qed.
Lemma ltr_wpMn2r n : (0 < n)%N -> {homo (@GRing.natmul R)^~ n : x y / x < y}.
Proof. by move=> n_gt0 x y /= / ltr_wMn2r ->. Qed.
Lemma ler_wMn2r n : {homo (@GRing.natmul R)^~ n : x y / x <= y}.
Proof. by move=> x y hxy /=; case: n=> // n; rewrite ler_pMn2r. Qed.
Lemma mulrn_wge0 x n : 0 <= x -> 0 <= x *+ n.
Proof. by move=> /(ler_wMn2r n); rewrite mul0rn. Qed.
Lemma mulrn_wle0 x n : x <= 0 -> x *+ n <= 0.
Proof. by move=> /(ler_wMn2r n); rewrite mul0rn. Qed.
Lemma lerMn2r n x y : (x *+ n <= y *+ n) = ((n == 0) || (x <= y)).
Proof. by case: n => [|n]; rewrite ?lexx ?eqxx // ler_pMn2r. Qed.
Lemma ltrMn2r n x y : (x *+ n < y *+ n) = ((0 < n)%N && (x < y)).
Proof. by case: n => [|n]; rewrite ?lexx ?eqxx // ltr_pMn2r. Qed.
Lemma eqrMn2r n x y : (x *+ n == y *+ n) = (n == 0)%N || (x == y).
Proof. by rewrite !(@eq_le _ R) !lerMn2r -orb_andr. Qed.
(* More characteristic zero properties. *)
Lemma mulrn_eq0 x n : (x *+ n == 0) = ((n == 0)%N || (x == 0)).
Proof. by rewrite -mulr_natl mulf_eq0 pnatr_eq0. Qed.
Lemma eqNr x : (- x == x) = (x == 0).
Proof. by rewrite eq_sym -addr_eq0 -mulr2n mulrn_eq0. Qed.
Lemma mulrIn x : x != 0 -> injective (GRing.natmul x).
Proof.
move=> x_neq0 m n; without loss /subnK <-: m n / (n <= m)%N.
by move=> IH eq_xmn; case/orP: (leq_total m n) => /IH->.
by move/eqP; rewrite mulrnDr -subr_eq0 addrK mulrn_eq0 => /predU1P[-> | /idPn].
Qed.
Lemma ler_wpMn2l x :
0 <= x -> {homo (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof. by move=> xge0 m n /subnK <-; rewrite mulrnDr ler_wpDl ?mulrn_wge0. Qed.
Lemma ler_wnMn2l x :
x <= 0 -> {homo (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Proof.
by move=> xle0 m n hmn /=; rewrite -lerN2 -!mulNrn ler_wpMn2l // oppr_cp0.
Qed.
Lemma mulrn_wgt0 x n : 0 < x -> 0 < x *+ n = (0 < n)%N.
Proof. by case: n => // n hx; rewrite pmulrn_lgt0. Qed.
Lemma mulrn_wlt0 x n : x < 0 -> x *+ n < 0 = (0 < n)%N.
Proof. by case: n => // n hx; rewrite pmulrn_llt0. Qed.
Lemma ler_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> x_gt0 m n /=; case: leqP => hmn; first by rewrite ler_wpMn2l // ltW.
by rewrite -(subnK (ltnW hmn)) mulrnDr gerDr lt_geF // mulrn_wgt0 // subn_gt0.
Qed.
Lemma ltr_pMn2l x :
0 < x -> {mono (@GRing.natmul R x) : m n / (m < n)%N >-> m < n}.
Proof. by move=> x_gt0; apply: leW_mono (ler_pMn2l _). Qed.
Lemma ler_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n <= m)%N >-> m <= n}.
Proof. by move=> xlt0 m n /=; rewrite -lerN2 -!mulNrn ler_pMn2l// oppr_gt0. Qed.
Lemma ltr_nMn2l x :
x < 0 -> {mono (@GRing.natmul R x) : m n / (n < m)%N >-> m < n}.
Proof. by move=> x_lt0; apply: leW_nmono (ler_nMn2l _). Qed.
Lemma ler_nat m n : (m%:R <= n%:R :> R) = (m <= n)%N.
Proof. by rewrite ler_pMn2l. Qed.
Lemma ltr_nat m n : (m%:R < n%:R :> R) = (m < n)%N.
Proof. by rewrite ltr_pMn2l. Qed.
Lemma eqr_nat m n : (m%:R == n%:R :> R) = (m == n)%N.
Proof. by rewrite (inj_eq (mulrIn _)) ?oner_eq0. Qed.
Lemma pnatr_eq1 n : (n%:R == 1 :> R) = (n == 1)%N.
Proof. exact: eqr_nat 1. Qed.
Lemma lern0 n : (n%:R <= 0 :> R) = (n == 0).
Proof. by rewrite -[0]/0%:R ler_nat leqn0. Qed.
Lemma ltrn0 n : (n%:R < 0 :> R) = false.
Proof. by rewrite -[0]/0%:R ltr_nat ltn0. Qed.
Lemma ler1n n : 1 <= n%:R :> R = (1 <= n)%N. Proof. by rewrite -ler_nat. Qed.
Lemma ltr1n n : 1 < n%:R :> R = (1 < n)%N. Proof. by rewrite -ltr_nat. Qed.
Lemma lern1 n : n%:R <= 1 :> R = (n <= 1)%N. Proof. by rewrite -ler_nat. Qed.
Lemma ltrn1 n : n%:R < 1 :> R = (n < 1)%N. Proof. by rewrite -ltr_nat. Qed.
Lemma ltrN10 : -1 < 0 :> R. Proof. by rewrite oppr_lt0. Qed.
Lemma lerN10 : -1 <= 0 :> R. Proof. by rewrite oppr_le0. Qed.
Lemma ltr10 : 1 < 0 :> R = false. Proof. by rewrite le_gtF. Qed.
Lemma ler10 : 1 <= 0 :> R = false. Proof. by rewrite lt_geF. Qed.
Lemma ltr0N1 : 0 < -1 :> R = false. Proof. by rewrite le_gtF // lerN10. Qed.
Lemma ler0N1 : 0 <= -1 :> R = false. Proof. by rewrite lt_geF // ltrN10. Qed.
#[deprecated(since="mathcomp 2.4.0", note="use `mulrn_wgt0` instead")]
Lemma pmulrn_rgt0 x n : 0 < x -> 0 < x *+ n = (0 < n)%N.
Proof. exact: mulrn_wgt0. Qed.
Lemma pmulrn_rlt0 x n : 0 < x -> x *+ n < 0 = false.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ltr_pMn2l. Qed.
Lemma pmulrn_rge0 x n : 0 < x -> 0 <= x *+ n.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ler_pMn2l. Qed.
Lemma pmulrn_rle0 x n : 0 < x -> x *+ n <= 0 = (n == 0)%N.
Proof. by move=> x_gt0; rewrite -(mulr0n x) ler_pMn2l ?leqn0. Qed.
Lemma nmulrn_rgt0 x n : x < 0 -> 0 < x *+ n = false.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ltr_nMn2l. Qed.
Lemma nmulrn_rge0 x n : x < 0 -> 0 <= x *+ n = (n == 0)%N.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ler_nMn2l ?leqn0. Qed.
Lemma nmulrn_rle0 x n : x < 0 -> x *+ n <= 0.
Proof. by move=> x_lt0; rewrite -(mulr0n x) ler_nMn2l. Qed.
(* (x * y) compared to 0 *)
(* Remark : pmulr_rgt0 and pmulr_rge0 are defined above *)
(* x positive and y right *)
Lemma pmulr_rlt0 x y : 0 < x -> (x * y < 0) = (y < 0).
Proof.
by move=> x_gt0; rewrite -[LHS]oppr_gt0 -mulrN pmulr_rgt0 // oppr_gt0.
Qed.
Lemma pmulr_rle0 x y : 0 < x -> (x * y <= 0) = (y <= 0).
Proof.
by move=> x_gt0; rewrite -[LHS]oppr_ge0 -mulrN pmulr_rge0 // oppr_ge0.
Qed.
(* x positive and y left *)
Lemma pmulr_lgt0 x y : 0 < x -> (0 < y * x) = (0 < y).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rgt0. Qed.
Lemma pmulr_lge0 x y : 0 < x -> (0 <= y * x) = (0 <= y).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rge0. Qed.
Lemma pmulr_llt0 x y : 0 < x -> (y * x < 0) = (y < 0).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rlt0. Qed.
Lemma pmulr_lle0 x y : 0 < x -> (y * x <= 0) = (y <= 0).
Proof. by move=> x_gt0; rewrite mulrC pmulr_rle0. Qed.
(* x negative and y right *)
Lemma nmulr_rgt0 x y : x < 0 -> (0 < x * y) = (y < 0).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rgt0 lterNE. Qed.
Lemma nmulr_rge0 x y : x < 0 -> (0 <= x * y) = (y <= 0).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rge0 lterNE. Qed.
Lemma nmulr_rlt0 x y : x < 0 -> (x * y < 0) = (0 < y).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rlt0 lterNE. Qed.
Lemma nmulr_rle0 x y : x < 0 -> (x * y <= 0) = (0 <= y).
Proof. by move=> x_lt0; rewrite -mulrNN pmulr_rle0 lterNE. Qed.
(* x negative and y left *)
Lemma nmulr_lgt0 x y : x < 0 -> (0 < y * x) = (y < 0).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rgt0. Qed.
Lemma nmulr_lge0 x y : x < 0 -> (0 <= y * x) = (y <= 0).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rge0. Qed.
Lemma nmulr_llt0 x y : x < 0 -> (y * x < 0) = (0 < y).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rlt0. Qed.
Lemma nmulr_lle0 x y : x < 0 -> (y * x <= 0) = (0 <= y).
Proof. by move=> x_lt0; rewrite mulrC nmulr_rle0. Qed.
(* weak and symmetric lemmas *)
Lemma mulr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x * y.
Proof. by move=> x_ge0 y_ge0; rewrite -(mulr0 x) ler_wpM2l. Qed.
Lemma mulr_le0 x y : x <= 0 -> y <= 0 -> 0 <= x * y.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wnM2l. Qed.
Lemma mulr_ge0_le0 x y : 0 <= x -> y <= 0 -> x * y <= 0.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wpM2l. Qed.
Lemma mulr_le0_ge0 x y : x <= 0 -> 0 <= y -> x * y <= 0.
Proof. by move=> x_le0 y_le0; rewrite -(mulr0 x) ler_wnM2l. Qed.
(* mulr_gt0 with only one case *)
Lemma mulr_gt0 x y : 0 < x -> 0 < y -> 0 < x * y.
Proof. by move=> x_gt0 y_gt0; rewrite pmulr_rgt0. Qed.
(* and reverse direction *)
Lemma mulr_ge0_gt0 x y : 0 <= x -> 0 <= y -> (0 < x * y) = (0 < x) && (0 < y).
Proof.
rewrite le_eqVlt => /predU1P[<-|x0]; first by rewrite mul0r ltxx.
rewrite le_eqVlt => /predU1P[<-|y0]; first by rewrite mulr0 ltxx andbC.
by apply/idP/andP=> [|_]; rewrite pmulr_rgt0.
Qed.
(* Iterated products *)
Lemma prodr_ge0 I r (P : pred I) (E : I -> R) :
(forall i, P i -> 0 <= E i) -> 0 <= \prod_(i <- r | P i) E i.
Proof. by move=> Ege0; rewrite -nnegrE rpred_prod. Qed.
Lemma prodr_gt0 I r (P : pred I) (E : I -> R) :
(forall i, P i -> 0 < E i) -> 0 < \prod_(i <- r | P i) E i.
Proof. by move=> Ege0; rewrite -posrE rpred_prod. Qed.
Lemma ler_prod I r (P : pred I) (E1 E2 : I -> R) :
(forall i, P i -> 0 <= E1 i <= E2 i) ->
\prod_(i <- r | P i) E1 i <= \prod_(i <- r | P i) E2 i.
Proof.
move=> leE12; elim/(big_load (fun x => 0 <= x)): _.
elim/big_rec2: _ => // i x2 x1 /leE12/andP[le0Ei leEi12] [x1ge0 le_x12].
by rewrite mulr_ge0 // ler_pM.
Qed.
Lemma ltr_prod I r (P : pred I) (E1 E2 : I -> R) :
has P r -> (forall i, P i -> 0 <= E1 i < E2 i) ->
\prod_(i <- r | P i) E1 i < \prod_(i <- r | P i) E2 i.
Proof.
elim: r => //= i r IHr; rewrite !big_cons; case: ifP => {IHr}// Pi _ ltE12.
have /andP[le0E1i ltE12i] := ltE12 i Pi; set E2r := \prod_(j <- r | P j) E2 j.
apply: le_lt_trans (_ : E1 i * E2r < E2 i * E2r).
by rewrite ler_wpM2l ?ler_prod // => j /ltE12/andP[-> /ltW].
by rewrite ltr_pM2r ?prodr_gt0 // => j /ltE12/andP[le0E1j /le_lt_trans->].
Qed.
Lemma ltr_prod_nat (E1 E2 : nat -> R) (n m : nat) :
(m < n)%N -> (forall i, (m <= i < n)%N -> 0 <= E1 i < E2 i) ->
\prod_(m <= i < n) E1 i < \prod_(m <= i < n) E2 i.
Proof.
move=> lt_mn ltE12; rewrite !big_nat ltr_prod {ltE12}//.
by apply/hasP; exists m; rewrite ?mem_index_iota leqnn.
Qed.
(* real of mul *)
Lemma realMr x y : x != 0 -> x \is real -> (x * y \is real) = (y \is real).
Proof.
move=> x_neq0 xR; case: real_ltgtP x_neq0 => // hx _; rewrite !realE.
by rewrite nmulr_rge0 // nmulr_rle0 // orbC.
by rewrite pmulr_rge0 // pmulr_rle0 // orbC.
Qed.
Lemma realrM x y : y != 0 -> y \is real -> (x * y \is real) = (x \is real).
Proof. by move=> y_neq0 yR; rewrite mulrC realMr. Qed.
Lemma realM : {in real &, forall x y, x * y \is real}.
Proof. exact: rpredM. Qed.
Lemma realrMn x n : (n != 0)%N -> (x *+ n \is real) = (x \is real).
Proof. by move=> n_neq0; rewrite -mulr_natl realMr ?realn ?pnatr_eq0. Qed.
(* ler/ltr and multiplication between a positive/negative *)
Lemma ger_pMl x y : 0 < y -> (x * y <= y) = (x <= 1).
Proof. by move=> hy; rewrite -{2}[y]mul1r ler_pM2r. Qed.
Lemma gtr_pMl x y : 0 < y -> (x * y < y) = (x < 1).
Proof. by move=> hy; rewrite -{2}[y]mul1r ltr_pM2r. Qed.
Lemma ger_pMr x y : 0 < y -> (y * x <= y) = (x <= 1).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ler_pM2l. Qed.
Lemma gtr_pMr x y : 0 < y -> (y * x < y) = (x < 1).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ltr_pM2l. Qed.
Lemma ler_pMl x y : 0 < y -> (y <= x * y) = (1 <= x).
Proof. by move=> hy; rewrite -{1}[y]mul1r ler_pM2r. Qed.
Lemma ltr_pMl x y : 0 < y -> (y < x * y) = (1 < x).
Proof. by move=> hy; rewrite -{1}[y]mul1r ltr_pM2r. Qed.
Lemma ler_pMr x y : 0 < y -> (y <= y * x) = (1 <= x).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ler_pM2l. Qed.
Lemma ltr_pMr x y : 0 < y -> (y < y * x) = (1 < x).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ltr_pM2l. Qed.
Lemma ger_nMl x y : y < 0 -> (x * y <= y) = (1 <= x).
Proof. by move=> hy; rewrite -{2}[y]mul1r ler_nM2r. Qed.
Lemma gtr_nMl x y : y < 0 -> (x * y < y) = (1 < x).
Proof. by move=> hy; rewrite -{2}[y]mul1r ltr_nM2r. Qed.
Lemma ger_nMr x y : y < 0 -> (y * x <= y) = (1 <= x).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ler_nM2l. Qed.
Lemma gtr_nMr x y : y < 0 -> (y * x < y) = (1 < x).
Proof. by move=> hy; rewrite -{2}[y]mulr1 ltr_nM2l. Qed.
Lemma ler_nMl x y : y < 0 -> (y <= x * y) = (x <= 1).
Proof. by move=> hy; rewrite -{1}[y]mul1r ler_nM2r. Qed.
Lemma ltr_nMl x y : y < 0 -> (y < x * y) = (x < 1).
Proof. by move=> hy; rewrite -{1}[y]mul1r ltr_nM2r. Qed.
Lemma ler_nMr x y : y < 0 -> (y <= y * x) = (x <= 1).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ler_nM2l. Qed.
Lemma ltr_nMr x y : y < 0 -> (y < y * x) = (x < 1).
Proof. by move=> hy; rewrite -{1}[y]mulr1 ltr_nM2l. Qed.
(* ler/ltr and multiplication between a positive/negative
and a exterior (1 <= _) or interior (0 <= _ <= 1) *)
Lemma ler_peMl x y : 0 <= y -> 1 <= x -> y <= x * y.
Proof. by move=> hy hx; rewrite -{1}[y]mul1r ler_wpM2r. Qed.
Lemma ler_neMl x y : y <= 0 -> 1 <= x -> x * y <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mul1r ler_wnM2r. Qed.
Lemma ler_peMr x y : 0 <= y -> 1 <= x -> y <= y * x.
Proof. by move=> hy hx; rewrite -{1}[y]mulr1 ler_wpM2l. Qed.
Lemma ler_neMr x y : y <= 0 -> 1 <= x -> y * x <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mulr1 ler_wnM2l. Qed.
Lemma ler_piMl x y : 0 <= y -> x <= 1 -> x * y <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mul1r ler_wpM2r. Qed.
Lemma ler_niMl x y : y <= 0 -> x <= 1 -> y <= x * y.
Proof. by move=> hy hx; rewrite -{1}[y]mul1r ler_wnM2r. Qed.
Lemma ler_piMr x y : 0 <= y -> x <= 1 -> y * x <= y.
Proof. by move=> hy hx; rewrite -{2}[y]mulr1 ler_wpM2l. Qed.
Lemma ler_niMr x y : y <= 0 -> x <= 1 -> y <= y * x.
Proof. by move=> hx hy; rewrite -{1}[y]mulr1 ler_wnM2l. Qed.
Lemma mulr_ile1 x y : 0 <= x -> 0 <= y -> x <= 1 -> y <= 1 -> x * y <= 1.
Proof. by move=> *; rewrite (@le_trans _ _ y) ?ler_piMl. Qed.
Lemma prodr_ile1 {I : Type} (s : seq I) (P : pred I) (F : I -> R) :
(forall i, P i -> 0 <= F i <= 1) -> \prod_(j <- s | P j) F j <= 1.
Proof.
elim: s => [_ | y s ih xs01]; rewrite ?big_nil// big_cons.
case: ifPn => Py; last by rewrite ih.
have /andP[y0 y1] : 0 <= F y <= 1 by rewrite xs01// mem_head.
rewrite mulr_ile1 ?andbT//; last first.
by rewrite ih// => e xs; rewrite xs01// in_cons xs orbT.
by rewrite prodr_ge0// => x /xs01 /andP[].
Qed.
Lemma mulr_ilt1 x y : 0 <= x -> 0 <= y -> x < 1 -> y < 1 -> x * y < 1.
Proof. by move=> *; rewrite (@le_lt_trans _ _ y) ?ler_piMl // ltW. Qed.
Definition mulr_ilte1 := (mulr_ile1, mulr_ilt1).
Lemma mulr_ege1 x y : 1 <= x -> 1 <= y -> 1 <= x * y.
Proof.
by move=> le1x le1y; rewrite (@le_trans _ _ y) ?ler_peMl // (le_trans ler01).
Qed.
Lemma mulr_egt1 x y : 1 < x -> 1 < y -> 1 < x * y.
Proof.
by move=> le1x lt1y; rewrite (@lt_trans _ _ y) // ltr_pMl // (lt_trans ltr01).
Qed.
Definition mulr_egte1 := (mulr_ege1, mulr_egt1).
Definition mulr_cp1 := (mulr_ilte1, mulr_egte1).
(* ler and ^-1 *)
Lemma invr_gt0 x : (0 < x^-1) = (0 < x).
Proof.
have [ux | nux] := boolP (x \is a GRing.unit); last by rewrite invr_out.
by apply/idP/idP=> /ltr_pM2r <-; rewrite mul0r (mulrV, mulVr) ?ltr01.
Qed.
Lemma invr_ge0 x : (0 <= x^-1) = (0 <= x).
Proof. by rewrite !le0r invr_gt0 invr_eq0. Qed.
Lemma invr_lt0 x : (x^-1 < 0) = (x < 0).
Proof. by rewrite -oppr_cp0 -invrN invr_gt0 oppr_cp0. Qed.
Lemma invr_le0 x : (x^-1 <= 0) = (x <= 0).
Proof. by rewrite -oppr_cp0 -invrN invr_ge0 oppr_cp0. Qed.
Definition invr_gte0 := (invr_ge0, invr_gt0).
Definition invr_lte0 := (invr_le0, invr_lt0).
Lemma divr_ge0 x y : 0 <= x -> 0 <= y -> 0 <= x / y.
Proof. by move=> x_ge0 y_ge0; rewrite mulr_ge0 ?invr_ge0. Qed.
Lemma divr_gt0 x y : 0 < x -> 0 < y -> 0 < x / y.
Proof. by move=> x_gt0 y_gt0; rewrite pmulr_rgt0 ?invr_gt0. Qed.
Lemma realV : {mono (@GRing.inv R) : x / x \is real}.
Proof. exact: rpredV. Qed.
(* ler and exprn *)
Lemma exprn_ge0 n x : 0 <= x -> 0 <= x ^+ n.
Proof. by move=> xge0; rewrite -nnegrE rpredX. Qed.
Lemma realX n : {in real, forall x, x ^+ n \is real}.
Proof. exact: rpredX. Qed.
Lemma exprn_gt0 n x : 0 < x -> 0 < x ^+ n.
Proof.
by rewrite !lt0r expf_eq0 => /andP[/negPf-> /exprn_ge0->]; rewrite andbF.
Qed.
Definition exprn_gte0 := (exprn_ge0, exprn_gt0).
Lemma exprn_ile1 n x : 0 <= x -> x <= 1 -> x ^+ n <= 1.
Proof.
move=> xge0 xle1; elim: n=> [|*]; rewrite ?expr0 // exprS.
by rewrite mulr_ile1 ?exprn_ge0.
Qed.
Lemma exprn_ilt1 n x : 0 <= x -> x < 1 -> x ^+ n < 1 = (n != 0).
Proof.
move=> xge0 xlt1.
case: n; [by rewrite eqxx ltxx | elim=> [|n ihn]; first by rewrite expr1].
by rewrite exprS mulr_ilt1 // exprn_ge0.
Qed.
Definition exprn_ilte1 := (exprn_ile1, exprn_ilt1).
Lemma exprn_ege1 n x : 1 <= x -> 1 <= x ^+ n.
Proof.
by move=> x_ge1; elim: n=> [|n ihn]; rewrite ?expr0 // exprS mulr_ege1.
Qed.
Lemma exprn_egt1 n x : 1 < x -> 1 < x ^+ n = (n != 0).
Proof.
move=> xgt1; case: n; first by rewrite eqxx ltxx.
by elim=> [|n ihn]; rewrite ?expr1// exprS mulr_egt1 // exprn_ge0.
Qed.
Definition exprn_egte1 := (exprn_ege1, exprn_egt1).
Definition exprn_cp1 := (exprn_ilte1, exprn_egte1).
Lemma ler_iXnr x n : (0 < n)%N -> 0 <= x -> x <= 1 -> x ^+ n <= x.
Proof. by case: n => n // *; rewrite exprS ler_piMr // exprn_ile1. Qed.
Lemma ltr_iXnr x n : 0 < x -> x < 1 -> (x ^+ n < x) = (1 < n)%N.
Proof.
case: n=> [|[|n]] //; first by rewrite expr0 => _ /lt_gtF ->.
by move=> x0 x1; rewrite exprS gtr_pMr // ?exprn_ilt1 // ltW.
Qed.
Definition lter_iXnr := (ler_iXnr, ltr_iXnr).
Lemma ler_eXnr x n : (0 < n)%N -> 1 <= x -> x <= x ^+ n.
Proof.
case: n => // n _ x_ge1.
by rewrite exprS ler_peMr ?(le_trans _ x_ge1) // exprn_ege1.
Qed.
Lemma ltr_eXnr x n : 1 < x -> (x < x ^+ n) = (1 < n)%N.
Proof.
move=> x_ge1; case: n=> [|[|n]] //; first by rewrite expr0 lt_gtF.
by rewrite exprS ltr_pMr ?(lt_trans _ x_ge1) ?exprn_egt1.
Qed.
Definition lter_eXnr := (ler_eXnr, ltr_eXnr).
Definition lter_Xnr := (lter_iXnr, lter_eXnr).
Lemma ler_wiXn2l x :
0 <= x -> x <= 1 -> {homo GRing.exp x : m n / (n <= m)%N >-> m <= n}.
Proof.
move=> xge0 xle1 m n /= hmn.
by rewrite -(subnK hmn) exprD ler_piMl ?(exprn_ge0, exprn_ile1).
Qed.
Lemma ler_weXn2l x : 1 <= x -> {homo GRing.exp x : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> xge1 m n /= hmn; rewrite -(subnK hmn) exprD.
by rewrite ler_peMl ?(exprn_ge0, exprn_ege1) // (le_trans _ xge1) ?ler01.
Qed.
Lemma ieexprn_weq1 x n : 0 <= x -> (x ^+ n == 1) = ((n == 0) || (x == 1)).
Proof.
move=> xle0; case: n => [|n]; first by rewrite expr0 eqxx.
case: (@real_ltgtP x 1); do ?by rewrite ?ger0_real.
+ by move=> x_lt1; rewrite 1?lt_eqF // exprn_ilt1.
+ by move=> x_lt1; rewrite 1?gt_eqF // exprn_egt1.
by move->; rewrite expr1n eqxx.
Qed.
Lemma ieexprIn x : 0 < x -> x != 1 -> injective (GRing.exp x).
Proof.
move=> x_gt0 x_neq1 m n; without loss /subnK <-: m n / (n <= m)%N.
by move=> IH eq_xmn; case/orP: (leq_total m n) => /IH->.
case: {m}(m - n)%N => // m /eqP/idPn[]; rewrite -[x ^+ n]mul1r exprD.
by rewrite (inj_eq (mulIf _)) ?ieexprn_weq1 ?ltW // expf_neq0 ?gt_eqF.
Qed.
Lemma ler_iXn2l x :
0 < x -> x < 1 -> {mono GRing.exp x : m n / (n <= m)%N >-> m <= n}.
Proof.
move=> xgt0 xlt1; apply: (le_nmono (inj_nhomo_lt _ _)); last first.
by apply/ler_wiXn2l; exact/ltW.
by apply: ieexprIn; rewrite ?lt_eqF ?ltr_cpable.
Qed.
Lemma ltr_iXn2l x :
0 < x -> x < 1 -> {mono GRing.exp x : m n / (n < m)%N >-> m < n}.
Proof. by move=> xgt0 xlt1; apply: (leW_nmono (ler_iXn2l _ _)). Qed.
Definition lter_iXn2l := (ler_iXn2l, ltr_iXn2l).
Lemma ler_eXn2l x :
1 < x -> {mono GRing.exp x : m n / (m <= n)%N >-> m <= n}.
Proof.
move=> xgt1; apply: (le_mono (inj_homo_lt _ _)); last first.
by apply: ler_weXn2l; rewrite ltW.
by apply: ieexprIn; rewrite ?gt_eqF ?gtr_cpable //; apply: lt_trans xgt1.
Qed.
Lemma ltr_eXn2l x :
1 < x -> {mono (GRing.exp x) : m n / (m < n)%N >-> m < n}.
Proof. by move=> xgt1; apply: (leW_mono (ler_eXn2l _)). Qed.
Definition lter_eXn2l := (ler_eXn2l, ltr_eXn2l).
Lemma ltrXn2r n x y : 0 <= x -> x < y -> x ^+ n < y ^+ n = (n != 0).
Proof.
move=> xge0 xlty; case: n; first by rewrite ltxx.
elim=> [|n IHn]; rewrite ?[_ ^+ _.+2]exprS //.
rewrite (@le_lt_trans _ _ (x * y ^+ n.+1)) ?ler_wpM2l ?ltr_pM2r ?IHn //.
by rewrite ltW.
by rewrite exprn_gt0 // (le_lt_trans xge0).
Qed.
Lemma lerXn2r n : {in nneg & , {homo (@GRing.exp R)^~ n : x y / x <= y}}.
Proof.
move=> x y /= x0 y0 xy; elim: n => [|n IHn]; rewrite !(expr0, exprS) //.
by rewrite (@le_trans _ _ (x * y ^+ n)) ?ler_wpM2l ?ler_wpM2r ?exprn_ge0.
Qed.
Definition lterXn2r := (lerXn2r, ltrXn2r).
Lemma ltr_wpXn2r n :
(0 < n)%N -> {in nneg & , {homo (@GRing.exp R)^~ n : x y / x < y}}.
Proof. by move=> ngt0 x y /= x0 y0 hxy; rewrite ltrXn2r // -lt0n. Qed.
Lemma ler_pXn2r n :
(0 < n)%N -> {in nneg & , {mono (@GRing.exp R)^~ n : x y / x <= y}}.
Proof.
case: n => // n _ x y; rewrite !qualifE /= => x_ge0 y_ge0.
have [-> | nzx] := eqVneq x 0; first by rewrite exprS mul0r exprn_ge0.
rewrite -subr_ge0 subrXX pmulr_lge0 ?subr_ge0 //= big_ord_recr /=.
rewrite subnn expr0 mul1r /= ltr_pwDr // ?exprn_gt0 ?lt0r ?nzx //.
by rewrite sumr_ge0 // => i _; rewrite mulr_ge0 ?exprn_ge0.
Qed.
Lemma ltr_pXn2r n :
(0 < n)%N -> {in nneg & , {mono (@GRing.exp R)^~ n : x y / x < y}}.
Proof.
by move=> n_gt0 x y x_ge0 y_ge0; rewrite !lt_neqAle !eq_le !ler_pXn2r.
Qed.
Definition lter_pXn2r := (ler_pXn2r, ltr_pXn2r).
Lemma pexpIrn n : (0 < n)%N -> {in nneg &, injective ((@GRing.exp R)^~ n)}.
Proof. by move=> n_gt0; apply: inc_inj_in (ler_pXn2r _). Qed.
(* expr and ler/ltr *)
Lemma expr_le1 n x : (0 < n)%N -> 0 <= x -> (x ^+ n <= 1) = (x <= 1).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ler_pXn2r // [_ \in _]ler01.
Qed.
Lemma expr_lt1 n x : (0 < n)%N -> 0 <= x -> (x ^+ n < 1) = (x < 1).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ltr_pXn2r // [_ \in _]ler01.
Qed.
Definition expr_lte1 := (expr_le1, expr_lt1).
Lemma expr_ge1 n x : (0 < n)%N -> 0 <= x -> (1 <= x ^+ n) = (1 <= x).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ler_pXn2r // [_ \in _]ler01.
Qed.
Lemma expr_gt1 n x : (0 < n)%N -> 0 <= x -> (1 < x ^+ n) = (1 < x).
Proof.
by move=> ngt0 xge0; rewrite -{1}[1](expr1n _ n) ltr_pXn2r // [_ \in _]ler01.
Qed.
Definition expr_gte1 := (expr_ge1, expr_gt1).
Lemma pexpr_eq1 x n : (0 < n)%N -> 0 <= x -> (x ^+ n == 1) = (x == 1).
Proof. by move=> ngt0 xge0; rewrite !eq_le expr_le1 // expr_ge1. Qed.
Lemma pexprn_eq1 x n : 0 <= x -> (x ^+ n == 1) = (n == 0) || (x == 1).
Proof. by case: n => [|n] xge0; rewrite ?eqxx // pexpr_eq1 ?gtn_eqF. Qed.
Lemma eqrXn2 n x y :
(0 < n)%N -> 0 <= x -> 0 <= y -> (x ^+ n == y ^+ n) = (x == y).
Proof. by move=> ngt0 xge0 yge0; rewrite (inj_in_eq (pexpIrn _)). Qed.
Lemma sqrp_eq1 x : 0 <= x -> (x ^+ 2 == 1) = (x == 1).
Proof. by move/pexpr_eq1->. Qed.
Lemma sqrn_eq1 x : x <= 0 -> (x ^+ 2 == 1) = (x == -1).
Proof. by rewrite -sqrrN -oppr_ge0 -eqr_oppLR => /sqrp_eq1. Qed.
Lemma ler_sqr : {in nneg &, {mono (fun x => x ^+ 2) : x y / x <= y}}.
Proof. exact: ler_pXn2r. Qed.
Lemma ltr_sqr : {in nneg &, {mono (fun x => x ^+ 2) : x y / x < y}}.
Proof. exact: ltr_pXn2r. Qed.
Lemma ler_pV2 :
{in [pred x in GRing.unit | 0 < x] &, {mono (@GRing.inv R) : x y /~ x <= y}}.
Proof.
move=> x y /andP [ux hx] /andP [uy hy] /=.
by rewrite -(ler_pM2l hx) -(ler_pM2r hy) !(divrr, mulrVK) ?unitf_gt0 // mul1r.
Qed.
Lemma ler_nV2 :
{in [pred x in GRing.unit | x < 0] &, {mono (@GRing.inv R) : x y /~ x <= y}}.
Proof.
move=> x y /andP [ux hx] /andP [uy hy] /=.
by rewrite -(ler_nM2l hx) -(ler_nM2r hy) !(divrr, mulrVK) ?unitf_lt0 // mul1r.
Qed.
Lemma ltr_pV2 :
{in [pred x in GRing.unit | 0 < x] &, {mono (@GRing.inv R) : x y /~ x < y}}.
Proof. exact: leW_nmono_in ler_pV2. Qed.
Lemma ltr_nV2 :
{in [pred x in GRing.unit | x < 0] &, {mono (@GRing.inv R) : x y /~ x < y}}.
Proof. exact: leW_nmono_in ler_nV2. Qed.
Lemma invr_gt1 x : x \is a GRing.unit -> 0 < x -> (1 < x^-1) = (x < 1).
Proof.
by move=> Ux xgt0; rewrite -{1}[1]invr1 ltr_pV2 ?inE ?unitr1 ?ltr01 ?Ux.
Qed.
Lemma invr_ge1 x : x \is a GRing.unit -> 0 < x -> (1 <= x^-1) = (x <= 1).
Proof.
by move=> Ux xgt0; rewrite -{1}[1]invr1 ler_pV2 ?inE ?unitr1 ?ltr01 // Ux.
Qed.
Definition invr_gte1 := (invr_ge1, invr_gt1).
Lemma invr_le1 x (ux : x \is a GRing.unit) (hx : 0 < x) :
(x^-1 <= 1) = (1 <= x).
Proof. by rewrite -invr_ge1 ?invr_gt0 ?unitrV // invrK. Qed.
Lemma invr_lt1 x (ux : x \is a GRing.unit) (hx : 0 < x) : (x^-1 < 1) = (1 < x).
Proof. by rewrite -invr_gt1 ?invr_gt0 ?unitrV // invrK. Qed.
Definition invr_lte1 := (invr_le1, invr_lt1).
Definition invr_cp1 := (invr_gte1, invr_lte1).
(* max and min *)
Lemma natr_min (m n : nat) : (Order.min m n)%:R = Order.min m%:R n%:R :> R.
Proof. by rewrite !minElt ltr_nat /Order.lt/= -fun_if. Qed.
Lemma natr_max (m n : nat) : (Order.max m n)%:R = Order.max m%:R n%:R :> R.
Proof. by rewrite !maxElt ltr_nat /Order.lt/= -fun_if. Qed.
Lemma addr_min_max x y : min x y + max x y = x + y.
Proof. by rewrite /min /max; case: ifP => //; rewrite addrC. Qed.
Lemma addr_max_min x y : max x y + min x y = x + y.
Proof. by rewrite addrC addr_min_max. Qed.
Lemma minr_to_max x y : min x y = x + y - max x y.
Proof. by rewrite -[x + y]addr_min_max addrK. Qed.
Lemma maxr_to_min x y : max x y = x + y - min x y.
Proof. by rewrite -[x + y]addr_max_min addrK. Qed.
Lemma real_oppr_max : {in real &, {morph -%R : x y / max x y >-> min x y : R}}.
Proof.
by move=> x y xr yr; rewrite !(fun_if, if_arg) ltrN2; case: real_ltgtP => // ->.
Qed.
Lemma real_oppr_min : {in real &, {morph -%R : x y / min x y >-> max x y : R}}.
Proof.
by move=> x y xr yr; rewrite -[RHS]opprK real_oppr_max ?realN// !opprK.
Qed.
Lemma real_addr_minl : {in real & real & real, @left_distributive R R +%R min}.
Proof.
by move=> x y z xr yr zr; case: (@real_leP (_ + _)); rewrite ?realD//;
rewrite lterD2; case: real_leP.
Qed.
Lemma real_addr_minr : {in real & real & real, @right_distributive R R +%R min}.
Proof. by move=> x y z xr yr zr; rewrite !(addrC x) real_addr_minl. Qed.
Lemma real_addr_maxl : {in real & real & real, @left_distributive R R +%R max}.
Proof.
by move=> x y z xr yr zr; case: (@real_leP (_ + _)); rewrite ?realD//;
rewrite lterD2; case: real_leP.
Qed.
Lemma real_addr_maxr : {in real & real & real, @right_distributive R R +%R max}.
Proof. by move=> x y z xr yr zr; rewrite !(addrC x) real_addr_maxl. Qed.
Lemma minr_pMr x y z : 0 <= x -> x * min y z = min (x * y) (x * z).
Proof.
have [|x_gt0||->]// := comparableP x; last by rewrite !mul0r minxx.
by rewrite !(fun_if, if_arg) lter_pM2l//; case: (y < z).
Qed.
Lemma maxr_pMr x y z : 0 <= x -> x * max y z = max (x * y) (x * z).
Proof.
have [|x_gt0||->]// := comparableP x; last by rewrite !mul0r maxxx.
by rewrite !(fun_if, if_arg) lter_pM2l//; case: (y < z).
Qed.
Lemma real_maxr_nMr x y z : x <= 0 -> y \is real -> z \is real ->
x * max y z = min (x * y) (x * z).
Proof.
move=> x0 yr zr; rewrite -[_ * _]opprK -mulrN real_oppr_max// -mulNr.
by rewrite minr_pMr ?oppr_ge0// !(mulNr, mulrN, opprK).
Qed.
Lemma real_minr_nMr x y z : x <= 0 -> y \is real -> z \is real ->
x * min y z = max (x * y) (x * z).
Proof.
move=> x0 yr zr; rewrite -[_ * _]opprK -mulrN real_oppr_min// -mulNr.
by rewrite maxr_pMr ?oppr_ge0// !(mulNr, mulrN, opprK).
Qed.
Lemma minr_pMl x y z : 0 <= x -> min y z * x = min (y * x) (z * x).
Proof. by move=> *; rewrite mulrC minr_pMr // ![_ * x]mulrC. Qed.
Lemma maxr_pMl x y z : 0 <= x -> max y z * x = max (y * x) (z * x).
Proof. by move=> *; rewrite mulrC maxr_pMr // ![_ * x]mulrC. Qed.
Lemma real_minr_nMl x y z : x <= 0 -> y \is real -> z \is real ->
min y z * x = max (y * x) (z * x).
Proof. by move=> *; rewrite mulrC real_minr_nMr // ![_ * x]mulrC. Qed.
Lemma real_maxr_nMl x y z : x <= 0 -> y \is real -> z \is real ->
max y z * x = min (y * x) (z * x).
Proof. by move=> *; rewrite mulrC real_maxr_nMr // ![_ * x]mulrC. Qed.
Lemma real_maxrN x : x \is real -> max x (- x) = `|x|.
Proof.
move=> x_real; rewrite /max.
by case: real_ge0P => // [/ge0_cp [] | /lt0_cp []];
case: (@real_leP (- x) x); rewrite ?realN.
Qed.
Lemma real_maxNr x : x \is real -> max (- x) x = `|x|.
Proof.
by move=> x_real; rewrite comparable_maxC ?real_maxrN ?real_comparable ?realN.
Qed.
Lemma real_minrN x : x \is real -> min x (- x) = - `|x|.
Proof.
by move=> x_real; rewrite -[LHS]opprK real_oppr_min ?opprK ?real_maxNr ?realN.
Qed.
Lemma real_minNr x : x \is real -> min (- x) x = - `|x|.
Proof.
by move=> x_real; rewrite -[LHS]opprK real_oppr_min ?opprK ?real_maxrN ?realN.
Qed.
Section RealDomainArgExtremum.
Context {I : finType} (i0 : I).
Context (P : pred I) (F : I -> R) (Pi0 : P i0).
Hypothesis F_real : {in P, forall i, F i \is real}.
Lemma real_arg_minP : extremum_spec <=%R P F [arg min_(i < i0 | P i) F i].
Proof.
by apply: comparable_arg_minP => // i j iP jP; rewrite real_comparable ?F_real.
Qed.
Lemma real_arg_maxP : extremum_spec >=%R P F [arg max_(i > i0 | P i) F i].
Proof.
by apply: comparable_arg_maxP => // i j iP jP; rewrite real_comparable ?F_real.
Qed.
End RealDomainArgExtremum.
(* norm *)
Lemma real_ler_norm x : x \is real -> x <= `|x|.
Proof.
by case/real_ge0P=> hx //; rewrite (le_trans (ltW hx)) // oppr_ge0 ltW.
Qed.
(* norm + add *)
Section NormedZmoduleTheory.
Variable V : semiNormedZmodType R.
Implicit Types (u v w : V).
Lemma normr_real v : `|v| \is real. Proof. by apply/ger0_real. Qed.
Hint Resolve normr_real : core.
Lemma ler_norm_sum I r (G : I -> V) (P : pred I):
`|\sum_(i <- r | P i) G i| <= \sum_(i <- r | P i) `|G i|.
Proof.
elim/big_rec2: _ => [|i y x _]; first by rewrite normr0.
by rewrite -(lerD2l `|G i|); apply: le_trans; apply: ler_normD.
Qed.
Lemma ler_normB v w : `|v - w| <= `|v| + `|w|.
Proof. by rewrite (le_trans (ler_normD _ _)) ?normrN. Qed.
Lemma ler_distD u v w : `|v - w| <= `|v - u| + `|u - w|.
Proof. by rewrite (le_trans _ (ler_normD _ _)) // addrA addrNK. Qed.
Lemma lerB_normD v w : `|v| - `|w| <= `|v + w|.
Proof.
by rewrite -{1}[v](addrK w) lterBDl (le_trans (ler_normD _ _))// addrC normrN.
Qed.
Lemma lerB_dist v w : `|v| - `|w| <= `|v - w|.
Proof. by rewrite -[`|w|]normrN lerB_normD. Qed.
Lemma ler_dist_dist v w : `| `|v| - `|w| | <= `|v - w|.
Proof.
have [||_|_] // := @real_leP `|v| `|w|; last by rewrite lerB_dist.
by rewrite distrC lerB_dist.
Qed.
Lemma ler_dist_normD v w : `| `|v| - `|w| | <= `|v + w|.
Proof. by rewrite -[w]opprK normrN ler_dist_dist. Qed.
Lemma ler_nnorml v x : x < 0 -> `|v| <= x = false.
Proof. by move=> h; rewrite lt_geF //; apply/(lt_le_trans h). Qed.
Lemma ltr_nnorml v x : x <= 0 -> `|v| < x = false.
Proof. by move=> h; rewrite le_gtF //; apply/(le_trans h). Qed.
Definition lter_nnormr := (ler_nnorml, ltr_nnorml).
End NormedZmoduleTheory.
Hint Extern 0 (is_true (norm _ \is real)) => apply: normr_real : core.
Lemma real_ler_norml x y : x \is real -> (`|x| <= y) = (- y <= x <= y).
Proof.
move=> xR; wlog x_ge0 : x xR / 0 <= x => [hwlog|].
move: (xR) => /(@real_leVge 0) /orP [|/hwlog->|hx] //.
by rewrite -[x]opprK normrN lerN2 andbC lerNl hwlog ?realN ?oppr_ge0.
rewrite ger0_norm //; have [le_xy|] := boolP (x <= y); last by rewrite andbF.
by rewrite (le_trans _ x_ge0) // oppr_le0 (le_trans x_ge0).
Qed.
Lemma real_ler_normlP x y :
x \is real -> reflect ((-x <= y) * (x <= y)) (`|x| <= y).
Proof.
by move=> Rx; rewrite real_ler_norml // lerNl; apply: (iffP andP) => [] [].
Qed.
Arguments real_ler_normlP {x y}.
Lemma real_eqr_norml x y :
x \is real -> (`|x| == y) = ((x == y) || (x == -y)) && (0 <= y).
Proof.
move=> Rx.
apply/idP/idP=> [|/andP[/pred2P[]-> /ger0_norm/eqP]]; rewrite ?normrE //.
case: real_le0P => // hx; rewrite 1?eqr_oppLR => /eqP exy.
by move: hx; rewrite exy ?oppr_le0 eqxx orbT //.
by move: hx=> /ltW; rewrite exy eqxx.
Qed.
Lemma real_eqr_norm2 x y :
x \is real -> y \is real -> (`|x| == `|y|) = (x == y) || (x == -y).
Proof.
move=> Rx Ry; rewrite real_eqr_norml // normrE andbT.
by case: real_le0P; rewrite // opprK orbC.
Qed.
Lemma real_ltr_norml x y : x \is real -> (`|x| < y) = (- y < x < y).
Proof.
move=> Rx; wlog x_ge0 : x Rx / 0 <= x => [hwlog|].
move: (Rx) => /(@real_leVge 0) /orP [|/hwlog->|hx] //.
by rewrite -[x]opprK normrN ltrN2 andbC ltrNl hwlog ?realN ?oppr_ge0.
rewrite ger0_norm //; have [le_xy|] := boolP (x < y); last by rewrite andbF.
by rewrite (lt_le_trans _ x_ge0) // oppr_lt0 (le_lt_trans x_ge0).
Qed.
Definition real_lter_norml := (real_ler_norml, real_ltr_norml).
Lemma real_ltr_normlP x y :
x \is real -> reflect ((-x < y) * (x < y)) (`|x| < y).
Proof.
by move=> Rx; rewrite real_ltr_norml // ltrNl; apply: (iffP (@andP _ _)); case.
Qed.
Arguments real_ltr_normlP {x y}.
Lemma real_ler_normr x y : y \is real -> (x <= `|y|) = (x <= y) || (x <= - y).
Proof.
move=> Ry.
have [xR|xNR] := boolP (x \is real); last by rewrite ?Nreal_leF ?realN.
rewrite real_leNgt ?real_ltr_norml // negb_and -?real_leNgt ?realN //.
by rewrite orbC lerNr.
Qed.
Lemma real_ltr_normr x y : y \is real -> (x < `|y|) = (x < y) || (x < - y).
Proof.
move=> Ry.
have [xR|xNR] := boolP (x \is real); last by rewrite ?Nreal_ltF ?realN.
rewrite real_ltNge ?real_ler_norml // negb_and -?real_ltNge ?realN //.
by rewrite orbC ltrNr.
Qed.
Definition real_lter_normr := (real_ler_normr, real_ltr_normr).
Lemma real_ltr_normlW x y : x \is real -> `|x| < y -> x < y.
Proof. by move=> ?; case/real_ltr_normlP. Qed.
Lemma real_ltrNnormlW x y : x \is real -> `|x| < y -> - y < x.
Proof. by move=> ?; case/real_ltr_normlP => //; rewrite ltrNl. Qed.
Lemma real_ler_normlW x y : x \is real -> `|x| <= y -> x <= y.
Proof. by move=> ?; case/real_ler_normlP. Qed.
Lemma real_lerNnormlW x y : x \is real -> `|x| <= y -> - y <= x.
Proof. by move=> ?; case/real_ler_normlP => //; rewrite lerNl. Qed.
Lemma real_ler_distl x y e :
x - y \is real -> (`|x - y| <= e) = (y - e <= x <= y + e).
Proof. by move=> Rxy; rewrite real_lter_norml // !lterBDl. Qed.
Lemma real_ltr_distl x y e :
x - y \is real -> (`|x - y| < e) = (y - e < x < y + e).
Proof. by move=> Rxy; rewrite real_lter_norml // !lterBDl. Qed.
Definition real_lter_distl := (real_ler_distl, real_ltr_distl).
Lemma real_ltr_distlDr x y e : x - y \is real -> `|x - y| < e -> x < y + e.
Proof. by move=> ?; rewrite real_ltr_distl // => /andP[]. Qed.
Lemma real_ler_distlDr x y e : x - y \is real -> `|x - y| <= e -> x <= y + e.
Proof. by move=> ?; rewrite real_ler_distl // => /andP[]. Qed.
Lemma real_ltr_distlCDr x y e : x - y \is real -> `|x - y| < e -> y < x + e.
Proof. by rewrite realBC (distrC x) => ? /real_ltr_distlDr; apply. Qed.
Lemma real_ler_distlCDr x y e : x - y \is real -> `|x - y| <= e -> y <= x + e.
Proof. by rewrite realBC distrC => ? /real_ler_distlDr; apply. Qed.
Lemma real_ltr_distlBl x y e : x - y \is real -> `|x - y| < e -> x - e < y.
Proof. by move/real_ltr_distlDr; rewrite ltrBlDr; apply. Qed.
Lemma real_ler_distlBl x y e : x - y \is real -> `|x - y| <= e -> x - e <= y.
Proof. by move/real_ler_distlDr; rewrite lerBlDr; apply. Qed.
Lemma real_ltr_distlCBl x y e : x - y \is real -> `|x - y| < e -> y - e < x.
Proof. by rewrite realBC distrC => ? /real_ltr_distlBl; apply. Qed.
Lemma real_ler_distlCBl x y e : x - y \is real -> `|x - y| <= e -> y - e <= x.
Proof. by rewrite realBC distrC => ? /real_ler_distlBl; apply. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `ger0_def` instead")]
Lemma eqr_norm_id x : (`|x| == x) = (0 <= x). Proof. by rewrite ger0_def. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `ler0_def` instead")]
Lemma eqr_normN x : (`|x| == - x) = (x <= 0). Proof. by rewrite ler0_def. Qed.
Definition eqr_norm_idVN := =^~ (ger0_def, ler0_def).
Lemma real_exprn_even_ge0 n x : x \is real -> ~~ odd n -> 0 <= x ^+ n.
Proof.
move=> xR even_n; have [/exprn_ge0 -> //|x_lt0] := real_ge0P xR.
rewrite -[x]opprK -mulN1r exprMn -signr_odd (negPf even_n) expr0 mul1r.
by rewrite exprn_ge0 ?oppr_ge0 ?ltW.
Qed.
Lemma real_exprn_even_gt0 n x :
x \is real -> ~~ odd n -> (0 < x ^+ n) = (n == 0)%N || (x != 0).
Proof.
move=> xR n_even; rewrite lt0r real_exprn_even_ge0 ?expf_eq0 //.
by rewrite andbT negb_and lt0n negbK.
Qed.
Lemma real_exprn_even_le0 n x :
x \is real -> ~~ odd n -> (x ^+ n <= 0) = (n != 0) && (x == 0).
Proof.
move=> xR n_even; rewrite !real_leNgt ?rpred0 ?rpredX //.
by rewrite real_exprn_even_gt0 // negb_or negbK.
Qed.
Lemma real_exprn_even_lt0 n x :
x \is real -> ~~ odd n -> (x ^+ n < 0) = false.
Proof. by move=> xR n_even; rewrite le_gtF // real_exprn_even_ge0. Qed.
Lemma real_exprn_odd_ge0 n x :
x \is real -> odd n -> (0 <= x ^+ n) = (0 <= x).
Proof.
case/real_ge0P => [x_ge0|x_lt0] n_odd; first by rewrite exprn_ge0.
apply: negbTE; rewrite lt_geF //.
case: n n_odd => // n /= n_even; rewrite exprS pmulr_llt0 //.
by rewrite real_exprn_even_gt0 ?ler0_real ?ltW // (lt_eqF x_lt0) ?orbT.
Qed.
Lemma real_exprn_odd_gt0 n x : x \is real -> odd n -> (0 < x ^+ n) = (0 < x).
Proof.
by move=> xR n_odd; rewrite !lt0r expf_eq0 real_exprn_odd_ge0; case: n n_odd.
Qed.
Lemma real_exprn_odd_le0 n x : x \is real -> odd n -> (x ^+ n <= 0) = (x <= 0).
Proof.
by move=> xR n_odd; rewrite !real_leNgt ?rpred0 ?rpredX // real_exprn_odd_gt0.
Qed.
Lemma real_exprn_odd_lt0 n x : x \is real -> odd n -> (x ^+ n < 0) = (x < 0).
Proof.
by move=> xR n_odd; rewrite !real_ltNge ?rpred0 ?rpredX // real_exprn_odd_ge0.
Qed.
(* GG: Could this be a better definition of "real" ? *)
Lemma realEsqr x : (x \is real) = (0 <= x ^+ 2).
Proof. by rewrite ger0_def normrX eqf_sqr -ger0_def -ler0_def. Qed.
Lemma real_normK x : x \is real -> `|x| ^+ 2 = x ^+ 2.
Proof. by move=> Rx; rewrite -normrX ger0_norm -?realEsqr. Qed.
(* Binary sign ((-1) ^+ s). *)
Lemma normr_sign s : `|(-1) ^+ s : R| = 1.
Proof. by rewrite normrX normrN1 expr1n. Qed.
Lemma normrMsign s x : `|(-1) ^+ s * x| = `|x|.
Proof. by rewrite normrM normr_sign mul1r. Qed.
Lemma signr_gt0 (b : bool) : (0 < (-1) ^+ b :> R) = ~~ b.
Proof. by case: b; rewrite (ltr01, ltr0N1). Qed.
Lemma signr_lt0 (b : bool) : ((-1) ^+ b < 0 :> R) = b.
Proof. by case: b; rewrite // ?(ltrN10, ltr10). Qed.
Lemma signr_ge0 (b : bool) : (0 <= (-1) ^+ b :> R) = ~~ b.
Proof. by rewrite le0r signr_eq0 signr_gt0. Qed.
Lemma signr_le0 (b : bool) : ((-1) ^+ b <= 0 :> R) = b.
Proof. by rewrite le_eqVlt signr_eq0 signr_lt0. Qed.
(* This actually holds for char R != 2. *)
Lemma signr_inj : injective (fun b : bool => (-1) ^+ b : R).
Proof. exact: can_inj (fun x => 0 >= x) signr_le0. Qed.
(* Ternary sign (sg). *)
Lemma sgr_def x : sg x = (-1) ^+ (x < 0)%R *+ (x != 0).
Proof. by rewrite /sg; do 2!case: ifP => //. Qed.
Lemma neqr0_sign x : x != 0 -> (-1) ^+ (x < 0)%R = sgr x.
Proof. by rewrite sgr_def => ->. Qed.
Lemma gtr0_sg x : 0 < x -> sg x = 1.
Proof. by move=> x_gt0; rewrite /sg gt_eqF // lt_gtF. Qed.
Lemma ltr0_sg x : x < 0 -> sg x = -1.
Proof. by move=> x_lt0; rewrite /sg x_lt0 lt_eqF. Qed.
Lemma sgr0 : sg 0 = 0 :> R. Proof. by rewrite /sgr eqxx. Qed.
Lemma sgr1 : sg 1 = 1 :> R. Proof. by rewrite gtr0_sg // ltr01. Qed.
Lemma sgrN1 : sg (-1) = -1 :> R. Proof. by rewrite ltr0_sg // ltrN10. Qed.
Definition sgrE := (sgr0, sgr1, sgrN1).
Lemma sqr_sg x : sg x ^+ 2 = (x != 0)%:R.
Proof. by rewrite sgr_def exprMn_n sqrr_sign -mulnn mulnb andbb. Qed.
Lemma mulr_sg_eq1 x y : (sg x * y == 1) = (x != 0) && (sg x == y).
Proof.
rewrite /sg eq_sym; case: ifP => _; first by rewrite mul0r oner_eq0.
by case: ifP => _; rewrite ?mul1r // mulN1r eqr_oppLR.
Qed.
Lemma mulr_sg_eqN1 x y : (sg x * sg y == -1) = (x != 0) && (sg x == - sg y).
Proof.
move/sg: y => y; rewrite /sg eq_sym eqr_oppLR.
case: ifP => _; first by rewrite mul0r oppr0 oner_eq0.
by case: ifP => _; rewrite ?mul1r // mulN1r eqr_oppLR.
Qed.
Lemma sgr_eq0 x : (sg x == 0) = (x == 0).
Proof. by rewrite -sqrf_eq0 sqr_sg pnatr_eq0; case: (x == 0). Qed.
Lemma sgr_odd n x : x != 0 -> (sg x) ^+ n = (sg x) ^+ (odd n).
Proof. by rewrite /sg; do 2!case: ifP => // _; rewrite ?expr1n ?signr_odd. Qed.
Lemma sgrMn x n : sg (x *+ n) = (n != 0)%:R * sg x.
Proof.
case: n => [|n]; first by rewrite mulr0n sgr0 mul0r.
by rewrite !sgr_def mulrn_eq0 mul1r pmulrn_llt0.
Qed.
Lemma sgr_nat n : sg n%:R = (n != 0)%:R :> R.
Proof. by rewrite sgrMn sgr1 mulr1. Qed.
Lemma sgr_id x : sg (sg x) = sg x.
Proof. by rewrite !(fun_if sg) !sgrE. Qed.
Lemma sgr_lt0 x : (sg x < 0) = (x < 0).
Proof.
rewrite /sg; case: eqP => [-> // | _].
by case: ifP => _; rewrite ?ltrN10 // lt_gtF.
Qed.
Lemma sgr_le0 x : (sgr x <= 0) = (x <= 0).
Proof. by rewrite !le_eqVlt sgr_eq0 sgr_lt0. Qed.
(* sign and norm *)
Lemma realEsign x : x \is real -> x = (-1) ^+ (x < 0)%R * `|x|.
Proof. by case/real_ge0P; rewrite (mul1r, mulN1r) ?opprK. Qed.
Lemma realNEsign x : x \is real -> - x = (-1) ^+ (0 < x)%R * `|x|.
Proof. by move=> Rx; rewrite -normrN -oppr_lt0 -realEsign ?rpredN. Qed.
Lemma real_normrEsign (x : R) (xR : x \is real) : `|x| = (-1) ^+ (x < 0)%R * x.
Proof. by rewrite {3}[x]realEsign // signrMK. Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `realEsign` instead")]
Lemma real_mulr_sign_norm x : x \is real -> (-1) ^+ (x < 0)%R * `|x| = x.
Proof. by move/realEsign. Qed.
Lemma real_mulr_Nsign_norm x : x \is real -> (-1) ^+ (0 < x)%R * `|x| = - x.
Proof. by move/realNEsign. Qed.
Lemma realEsg x : x \is real -> x = sgr x * `|x|.
Proof.
move=> xR; have [-> | ] := eqVneq x 0; first by rewrite normr0 mulr0.
by move=> /neqr0_sign <-; rewrite -realEsign.
Qed.
Lemma normr_sg x : `|sg x| = (x != 0)%:R.
Proof. by rewrite sgr_def -mulr_natr normrMsign normr_nat. Qed.
Lemma sgr_norm x : sg `|x| = (x != 0)%:R.
Proof. by rewrite /sg le_gtF // normr_eq0 mulrb if_neg. Qed.
(* leif *)
Lemma leif_nat_r m n C : (m%:R <= n%:R ?= iff C :> R) = (m <= n ?= iff C)%N.
Proof. by rewrite /leif !ler_nat eqr_nat. Qed.
Lemma leifBLR x y z C : (x - y <= z ?= iff C) = (x <= z + y ?= iff C).
Proof. by rewrite /leif !eq_le lerBlDr lerBrDr. Qed.
Lemma leifBRL x y z C : (x <= y - z ?= iff C) = (x + z <= y ?= iff C).
Proof. by rewrite -leifBLR opprK. Qed.
Lemma leifD x1 y1 C1 x2 y2 C2 :
x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
x1 + x2 <= y1 + y2 ?= iff C1 && C2.
Proof.
rewrite -(mono_leif (C := C1) (lerD2r x2)).
rewrite -(mono_leif (C := C2) (lerD2l y1)).
exact: leif_trans.
Qed.
Lemma leif_sum (I : finType) (P C : pred I) (E1 E2 : I -> R) :
(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.
elim/big_rec3: _ => [|i Ci m2 m1 /leE12]; first by rewrite /leif lexx eqxx.
exact: leifD.
Qed.
Lemma leif_0_sum (I : finType) (P C : pred I) (E : I -> R) :
(forall i, P i -> 0 <= E i ?= iff C i) ->
0 <= \sum_(i | P i) E i ?= iff [forall (i | P i), C i].
Proof. by move/leif_sum; rewrite big1_eq. Qed.
Lemma real_leif_norm x : x \is real -> x <= `|x| ?= iff (0 <= x).
Proof.
by move=> xR; rewrite ger0_def eq_sym; apply: leif_eq; rewrite real_ler_norm.
Qed.
Lemma leif_pM x1 x2 y1 y2 C1 C2 :
0 <= x1 -> 0 <= x2 -> x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
x1 * x2 <= y1 * y2 ?= iff (y1 * y2 == 0) || C1 && C2.
Proof.
move=> x1_ge0 x2_ge0 le_xy1 le_xy2; have [y_0 | ] := eqVneq _ 0.
apply/leifP; rewrite y_0 /= mulf_eq0 !eq_le x1_ge0 x2_ge0 !andbT.
move/eqP: y_0; rewrite mulf_eq0.
by case/pred2P=> <-; rewrite (le_xy1, le_xy2) ?orbT.
rewrite /= mulf_eq0 => /norP[y1nz y2nz].
have y1_gt0: 0 < y1 by rewrite lt_def y1nz (le_trans _ le_xy1).
have [x2_0 | x2nz] := eqVneq x2 0.
apply/leifP; rewrite -le_xy2 x2_0 eq_sym (negPf y2nz) andbF mulr0.
by rewrite mulr_gt0 // lt_def y2nz -x2_0 le_xy2.
have:= le_xy2; rewrite -[X in X -> _](mono_leif (ler_pM2l y1_gt0)).
by apply: leif_trans; rewrite (mono_leif (ler_pM2r _)) // lt_def x2nz.
Qed.
Lemma leif_nM x1 x2 y1 y2 C1 C2 :
y1 <= 0 -> y2 <= 0 -> x1 <= y1 ?= iff C1 -> x2 <= y2 ?= iff C2 ->
y1 * y2 <= x1 * x2 ?= iff (x1 * x2 == 0) || C1 && C2.
Proof.
rewrite -!oppr_ge0 -mulrNN -[x1 * x2]mulrNN => y1le0 y2le0 le_xy1 le_xy2.
by apply: leif_pM => //; rewrite (nmono_leif lerN2).
Qed.
Lemma leif_pprod (I : finType) (P C : pred I) (E1 E2 : I -> R) :
(forall i, P i -> 0 <= E1 i) ->
(forall i, P i -> E1 i <= E2 i ?= iff C i) ->
let pi E := \prod_(i | P i) E i in
pi E1 <= pi E2 ?= iff (pi E2 == 0) || [forall (i | P i), C i].
Proof.
move=> E1_ge0 leE12 /=; rewrite -big_andE; elim/(big_load (fun x => 0 <= x)): _.
elim/big_rec3: _ => [|i Ci m2 m1 Pi [m1ge0 le_m12]].
by split=> //; apply/leifP; rewrite orbT.
have Ei_ge0 := E1_ge0 i Pi; split; first by rewrite mulr_ge0.
congr (leif _ _ _): (leif_pM Ei_ge0 m1ge0 (leE12 i Pi) le_m12).
by rewrite mulf_eq0 -!orbA; congr (_ || _); rewrite !orb_andr orbA orbb.
Qed.
(* lteif *)
Lemma subr_lteifr0 C x y : (y - x < 0 ?<= if C) = (y < x ?<= if C).
Proof. by case: C => /=; rewrite subr_lte0. Qed.
Lemma subr_lteif0r C x y : (0 < y - x ?<= if C) = (x < y ?<= if C).
Proof. by case: C => /=; rewrite subr_gte0. Qed.
Definition subr_lteif0 := (subr_lteifr0, subr_lteif0r).
Lemma lteif01 C : 0 < 1 ?<= if C :> R.
Proof. by case: C; rewrite /= lter01. Qed.
Lemma lteifNl C x y : - x < y ?<= if C = (- y < x ?<= if C).
Proof. by case: C; rewrite /= lterNl. Qed.
Lemma lteifNr C x y : x < - y ?<= if C = (y < - x ?<= if C).
Proof. by case: C; rewrite /= lterNr. Qed.
Lemma lteif0Nr C x : 0 < - x ?<= if C = (x < 0 ?<= if C).
Proof. by case: C; rewrite /= (oppr_ge0, oppr_gt0). Qed.
Lemma lteifNr0 C x : - x < 0 ?<= if C = (0 < x ?<= if C).
Proof. by case: C; rewrite /= (oppr_le0, oppr_lt0). Qed.
Lemma lteifN2 C : {mono -%R : x y /~ x < y ?<= if C :> R}.
Proof. by case: C => ? ?; rewrite /= lterN2. Qed.
Definition lteif_oppE := (lteif0Nr, lteifNr0, lteifN2).
Lemma lteifD2l C x : {mono +%R x : y z / y < z ?<= if C}.
Proof. by case: C => ? ?; rewrite /= lterD2. Qed.
Lemma lteifD2r C x : {mono +%R^~ x : y z / y < z ?<= if C}.
Proof. by case: C => ? ?; rewrite /= lterD2. Qed.
Definition lteifD2 := (lteifD2l, lteifD2r).
Lemma lteifBlDr C x y z : (x - y < z ?<= if C) = (x < z + y ?<= if C).
Proof. by case: C; rewrite /= lterBDr. Qed.
Lemma lteifBrDr C x y z : (x < y - z ?<= if C) = (x + z < y ?<= if C).
Proof. by case: C; rewrite /= lterBDr. Qed.
Definition lteifBDr := (lteifBlDr, lteifBrDr).
Lemma lteifBlDl C x y z : (x - y < z ?<= if C) = (x < y + z ?<= if C).
Proof. by case: C; rewrite /= lterBDl. Qed.
Lemma lteifBrDl C x y z : (x < y - z ?<= if C) = (z + x < y ?<= if C).
Proof. by case: C; rewrite /= lterBDl. Qed.
Definition lteifBDl := (lteifBlDl, lteifBrDl).
Lemma lteif_pM2l C x : 0 < x -> {mono *%R x : y z / y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_pM2l. Qed.
Lemma lteif_pM2r C x : 0 < x -> {mono *%R^~ x : y z / y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_pM2r. Qed.
Lemma lteif_nM2l C x : x < 0 -> {mono *%R x : y z /~ y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_nM2l. Qed.
Lemma lteif_nM2r C x : x < 0 -> {mono *%R^~ x : y z /~ y < z ?<= if C}.
Proof. by case: C => ? ? ?; rewrite /= lter_nM2r. Qed.
Lemma lteif_nnormr C x y : y < 0 ?<= if ~~ C -> (`|x| < y ?<= if C) = false.
Proof. by case: C => ?; rewrite /= lter_nnormr. Qed.
Lemma real_lteifNE x y C : x \is Num.real -> y \is Num.real ->
x < y ?<= if ~~ C = ~~ (y < x ?<= if C).
Proof. by move=> ? ?; rewrite comparable_lteifNE ?real_comparable. Qed.
Lemma real_lteif_norml C x y :
x \is Num.real ->
(`|x| < y ?<= if C) = ((- y < x ?<= if C) && (x < y ?<= if C)).
Proof. by case: C => ?; rewrite /= real_lter_norml. Qed.
Lemma real_lteif_normr C x y :
y \is Num.real ->
(x < `|y| ?<= if C) = ((x < y ?<= if C) || (x < - y ?<= if C)).
Proof. by case: C => ?; rewrite /= real_lter_normr. Qed.
Lemma real_lteif_distl C x y e :
x - y \is real ->
(`|x - y| < e ?<= if C) = (y - e < x ?<= if C) && (x < y + e ?<= if C).
Proof. by case: C => /= ?; rewrite real_lter_distl. Qed.
(* Mean inequalities. *)
Lemma real_leif_mean_square_scaled x y :
x \is real -> y \is real -> x * y *+ 2 <= x ^+ 2 + y ^+ 2 ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite -[_ *+ 2]add0r -leifBRL addrAC -sqrrB -subr_eq0.
by rewrite -sqrf_eq0 eq_sym; apply: leif_eq; rewrite -realEsqr rpredB.
Qed.
Lemma real_leif_AGM2_scaled x y :
x \is real -> y \is real -> x * y *+ 4 <= (x + y) ^+ 2 ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite sqrrD addrAC (mulrnDr _ 2) -leifBLR addrK.
exact: real_leif_mean_square_scaled.
Qed.
Lemma leif_AGM_scaled (I : finType) (A : {pred I}) (E : I -> R) (n := #|A|) :
{in A, forall i, 0 <= E i *+ n} ->
\prod_(i in A) (E i *+ n) <= (\sum_(i in A) E i) ^+ n
?= iff [forall i in A, forall j in A, E i == E j].
Proof.
have [m leAm] := ubnP #|A|; elim: m => // m IHm in A leAm E n * => Ege0.
apply/leifP; case: ifPn => [/forall_inP-Econstant | Enonconstant].
have [i /= Ai | A0] := pickP [in A]; last by rewrite [n]eq_card0 ?big_pred0.
have /eqfun_inP-E_i := Econstant i Ai; rewrite -(eq_bigr _ E_i) sumr_const.
by rewrite exprMn_n prodrMn_const -(eq_bigr _ E_i) prodr_const.
set mu := \sum_(i in A) E i; pose En i := E i *+ n.
pose cmp_mu s := [pred i | s * mu < s * En i].
have{Enonconstant} has_cmp_mu e (s := (-1) ^+ e): {i | i \in A & cmp_mu s i}.
apply/sig2W/exists_inP; apply: contraR Enonconstant => /exists_inPn-mu_s_A.
have n_gt0 i: i \in A -> (0 < n)%N by rewrite [n](cardD1 i) => ->.
have{} mu_s_A i: i \in A -> s * En i <= s * mu.
move=> Ai; rewrite real_leNgt ?mu_s_A ?rpredMsign ?ger0_real ?Ege0 //.
by rewrite -(pmulrn_lge0 _ (n_gt0 i Ai)) -sumrMnl sumr_ge0.
have [_ /esym/eqfun_inP] := leif_sum (fun i Ai => leif_eq (mu_s_A i Ai)).
rewrite sumr_const -/n -mulr_sumr sumrMnl -/mu mulrnAr eqxx => A_mu.
apply/forall_inP=> i Ai; apply/eqfun_inP=> j Aj.
by apply: (pmulrnI (n_gt0 i Ai)); apply: (can_inj (signrMK e)); rewrite !A_mu.
have [[i Ai Ei_lt_mu] [j Aj Ej_gt_mu]] := (has_cmp_mu 1, has_cmp_mu 0)%N.
rewrite {cmp_mu has_cmp_mu}/= !mul1r !mulN1r ltrN2 in Ei_lt_mu Ej_gt_mu.
pose A' := [predD1 A & i]; pose n' := #|A'|.
have [Dn n_gt0]: n = n'.+1 /\ (n > 0)%N by rewrite [n](cardD1 i) Ai.
have i'j: j != i by apply: contraTneq Ej_gt_mu => ->; rewrite lt_gtF.
have{i'j} A'j: j \in A' by rewrite !inE Aj i'j.
have mu_gt0: 0 < mu := le_lt_trans (Ege0 i Ai) Ei_lt_mu.
rewrite (bigD1 i) // big_andbC (bigD1 j) //= mulrA; set pi := \prod_(k | _) _.
have [-> | nz_pi] := eqVneq pi 0; first by rewrite !mulr0 exprn_gt0.
have{nz_pi} pi_gt0: 0 < pi.
by rewrite lt_def nz_pi prodr_ge0 // => k /andP[/andP[_ /Ege0]].
rewrite -/(En i) -/(En j); pose E' := [eta En with j |-> En i + En j - mu].
have E'ge0 k: k \in A' -> E' k *+ n' >= 0.
case/andP=> /= _ Ak; apply: mulrn_wge0; case: ifP => _; last exact: Ege0.
by rewrite subr_ge0 ler_wpDl ?Ege0 // ltW.
rewrite -/n Dn in leAm; have{leAm IHm E'ge0}: _ <= _ := IHm _ leAm _ E'ge0.
have ->: \sum_(k in A') E' k = mu *+ n'.
apply: (addrI mu); rewrite -mulrS -Dn -sumrMnl (bigD1 i Ai) big_andbC /=.
rewrite !(bigD1 j A'j) /= addrCA eqxx !addrA subrK; congr (_ + _).
by apply: eq_bigr => k /andP[_ /negPf->].
rewrite prodrMn_const exprMn_n -/n' ler_pMn2r ?expn_gt0; last by case: (n').
have ->: \prod_(k in A') E' k = E' j * pi.
by rewrite (bigD1 j) //=; congr *%R; apply: eq_bigr => k /andP[_ /negPf->].
rewrite -(ler_pM2l mu_gt0) -exprS -Dn mulrA; apply: lt_le_trans.
rewrite ltr_pM2r //= eqxx -addrA mulrDr mulrC -ltrBlDl -mulrBl.
by rewrite mulrC ltr_pM2r ?subr_gt0.
Qed.
(* Polynomial bound. *)
Implicit Type p : {poly R}.
Lemma poly_disk_bound p b : {ub | forall x, `|x| <= b -> `|p.[x]| <= ub}.
Proof.
exists (\sum_(j < size p) `|p`_j| * b ^+ j) => x le_x_b.
rewrite horner_coef (le_trans (ler_norm_sum _ _ _)) ?ler_sum // => j _.
rewrite normrM normrX ler_wpM2l ?lerXn2r ?unfold_in //=.
exact: le_trans (normr_ge0 x) le_x_b.
Qed.
End NumDomainOperationTheory.
#[global] Hint Resolve lerN2 ltrN2 normr_real : core.
#[global] Hint Extern 0 (is_true (_%:R \is real)) => apply: realn : core.
#[global] Hint Extern 0 (is_true (0 \is real)) => apply: real0 : core.
#[global] Hint Extern 0 (is_true (1 \is real)) => apply: real1 : core.
Arguments ler_sqr {R} [x y].
Arguments ltr_sqr {R} [x y].
Arguments signr_inj {R} [x1 x2].
Arguments real_ler_normlP {R x y}.
Arguments real_ltr_normlP {R x y}.
Section NumDomainMonotonyTheoryForReals.
Local Open Scope order_scope.
Variables (R R' : numDomainType) (D : pred R) (f : R -> R') (f' : R -> nat).
Implicit Types (m n p : nat) (x y z : R) (u v w : R').
Lemma real_mono :
{homo f : x y / x < y} -> {in real &, {mono f : x y / x <= y}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy | le_yx] := real_leP xR yR.
by rewrite ltW_homo.
by rewrite lt_geF ?mf.
Qed.
Lemma real_nmono :
{homo f : x y /~ x < y} -> {in real &, {mono f : x y /~ x <= y}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy|le_yx] := real_ltP xR yR.
by rewrite lt_geF ?mf.
by rewrite ltW_nhomo.
Qed.
Lemma real_mono_in :
{in D &, {homo f : x y / x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y / x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma real_nmono_in :
{in D &, {homo f : x y /~ x < y}} ->
{in [pred x in D | x \is real] &, {mono f : x y /~ x <= y}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_mono : {homo f' : x y / x < y >-> (x < y)} ->
{in real &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy | le_yx] := real_leP xR yR.
by rewrite ltW_homo.
by rewrite lt_geF ?mf.
Qed.
Lemma realn_nmono : {homo f' : x y / y < x >-> (x < y)} ->
{in real &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
move=> mf x y xR yR /=; have [lt_xy|le_yx] := real_ltP xR yR.
by rewrite lt_geF ?mf.
by rewrite ltW_nhomo.
Qed.
Lemma realn_mono_in : {in D &, {homo f' : x y / x < y >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / x <= y >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_leP xR yR; first by rewrite (ltW_homo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
Lemma realn_nmono_in : {in D &, {homo f' : x y / y < x >-> (x < y)}} ->
{in [pred x in D | x \is real] &, {mono f' : x y / y <= x >-> (x <= y)}}.
Proof.
move=> Dmf x y /andP[hx xR] /andP[hy yR] /=.
have [lt_xy|le_yx] := real_ltP xR yR; last by rewrite (ltW_nhomo_in Dmf).
by rewrite lt_geF ?Dmf.
Qed.
End NumDomainMonotonyTheoryForReals.
Section FinGroup.
Variables (R : numDomainType) (gT : finGroupType).
Implicit Types G : {group gT}.
Lemma natrG_gt0 G : #|G|%:R > 0 :> R.
Proof. by rewrite ltr0n cardG_gt0. Qed.
Lemma natrG_neq0 G : #|G|%:R != 0 :> R.
Proof. by rewrite gt_eqF // natrG_gt0. Qed.
Lemma natr_indexg_gt0 G B : #|G : B|%:R > 0 :> R.
Proof. by rewrite ltr0n indexg_gt0. Qed.
Lemma natr_indexg_neq0 G B : #|G : B|%:R != 0 :> R.
Proof. by rewrite gt_eqF // natr_indexg_gt0. Qed.
End FinGroup.
Section RealDomainTheory.
Variable R : realDomainType.
Implicit Types x y z t : R.
Lemma num_real x : x \is real. Proof. exact: num_real. Qed.
Hint Resolve num_real : core.
Lemma lerP x y : ler_xor_gt x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (x <= y) (y < x).
Proof. exact: real_leP. Qed.
Lemma ltrP x y : ltr_xor_ge x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y <= x) (x < y).
Proof. exact: real_ltP. Qed.
Lemma ltrgtP x y :
comparer x y (min y x) (min x y) (max y x) (max x y)
`|x - y| `|y - x| (y == x) (x == y)
(x >= y) (x <= y) (x > y) (x < y) .
Proof. exact: real_ltgtP. Qed.
Lemma ger0P x : ger0_xor_lt0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (x < 0) (0 <= x).
Proof. exact: real_ge0P. Qed.
Lemma ler0P x : ler0_xor_gt0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 < x) (x <= 0).
Proof. exact: real_le0P. Qed.
Lemma ltrgt0P x : comparer0 x (min 0 x) (min x 0) (max 0 x) (max x 0)
`|x| (0 == x) (x == 0) (x <= 0) (0 <= x) (x < 0) (x > 0).
Proof. exact: real_ltgt0P. Qed.
(* sign *)
Lemma mulr_lt0 x y :
(x * y < 0) = [&& x != 0, y != 0 & (x < 0) (+) (y < 0)].
Proof.
have [x_gt0|x_lt0|->] /= := ltrgt0P x; last by rewrite mul0r.
by rewrite pmulr_rlt0 //; case: ltrgt0P.
by rewrite nmulr_rlt0 //; case: ltrgt0P.
Qed.
Lemma neq0_mulr_lt0 x y :
x != 0 -> y != 0 -> (x * y < 0) = (x < 0) (+) (y < 0).
Proof. by move=> x_neq0 y_neq0; rewrite mulr_lt0 x_neq0 y_neq0. Qed.
Lemma mulr_sign_lt0 (b : bool) x :
((-1) ^+ b * x < 0) = (x != 0) && (b (+) (x < 0)%R).
Proof. by rewrite mulr_lt0 signr_lt0 signr_eq0. Qed.
(* sign & norm *)
Lemma mulr_sign_norm x : (-1) ^+ (x < 0)%R * `|x| = x.
Proof. by rewrite -realEsign. Qed.
Lemma mulr_Nsign_norm x : (-1) ^+ (0 < x)%R * `|x| = - x.
Proof. by rewrite real_mulr_Nsign_norm. Qed.
Lemma numEsign x : x = (-1) ^+ (x < 0)%R * `|x|.
Proof. by rewrite -realEsign. Qed.
Lemma numNEsign x : -x = (-1) ^+ (0 < x)%R * `|x|.
Proof. by rewrite -realNEsign. Qed.
Lemma normrEsign x : `|x| = (-1) ^+ (x < 0)%R * x.
Proof. by rewrite -real_normrEsign. Qed.
End RealDomainTheory.
#[global] Hint Resolve num_real : core.
Section RealDomainOperations.
Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" :=
(Order.arg_min (disp := ring_display) i0 (fun i => P%B) (fun i => F)) :
ring_scope.
Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" :=
[arg min_(i < i0 | i \in A) F] : ring_scope.
Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F] :
ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" :=
(Order.arg_max (disp := ring_display) i0 (fun i => P%B) (fun i => F)) :
ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" :=
[arg max_(i > i0 | i \in A) F] : ring_scope.
Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F] :
ring_scope.
(* sgr section *)
Variable R : realDomainType.
Implicit Types x y z t : R.
Let numR_real := @num_real R.
Hint Resolve numR_real : core.
Lemma sgr_cp0 x :
((sg x == 1) = (0 < x)) *
((sg x == -1) = (x < 0)) *
((sg x == 0) = (x == 0)).
Proof.
rewrite -[1]/((-1) ^+ false) -signrN lt0r leNgt sgr_def.
case: (x =P 0) => [-> | _]; first by rewrite !(eq_sym 0) !signr_eq0 ltxx eqxx.
by rewrite !(inj_eq signr_inj) eqb_id eqbF_neg signr_eq0 //.
Qed.
Variant sgr_val x : R -> bool -> bool -> bool -> bool -> bool -> bool
-> bool -> bool -> bool -> bool -> bool -> bool -> R -> Set :=
| SgrNull of x = 0 : sgr_val x 0 true true true true false false
true false false true false false 0
| SgrPos of x > 0 : sgr_val x x false false true false false true
false false true false false true 1
| SgrNeg of x < 0 : sgr_val x (- x) false true false false true false
false true false false true false (-1).
Lemma sgrP x :
sgr_val x `|x| (0 == x) (x <= 0) (0 <= x) (x == 0) (x < 0) (0 < x)
(0 == sg x) (-1 == sg x) (1 == sg x)
(sg x == 0) (sg x == -1) (sg x == 1) (sg x).
Proof.
by rewrite ![_ == sg _]eq_sym !sgr_cp0 /sg; case: ltrgt0P; constructor.
Qed.
Lemma normrEsg x : `|x| = sg x * x.
Proof. by case: sgrP; rewrite ?(mul0r, mul1r, mulN1r). Qed.
Lemma numEsg x : x = sg x * `|x|.
Proof. by case: sgrP; rewrite !(mul1r, mul0r, mulrNN). Qed.
#[deprecated(since="mathcomp 2.3.0", note="use `numEsg` instead")]
Lemma mulr_sg_norm x : sg x * `|x| = x. Proof. by rewrite -numEsg. Qed.
Lemma sgrM x y : sg (x * y) = sg x * sg y.
Proof.
rewrite !sgr_def mulr_lt0 andbA mulrnAr mulrnAl -mulrnA mulnb -negb_or mulf_eq0.
by case: (~~ _) => //; rewrite signr_addb.
Qed.
Lemma sgrN x : sg (- x) = - sg x.
Proof. by rewrite -mulrN1 sgrM sgrN1 mulrN1. Qed.
Lemma sgrX n x : sg (x ^+ n) = (sg x) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?sgr1 // !exprS sgrM IHn. Qed.
Lemma sgr_smul x y : sg (sg x * y) = sg x * sg y.
Proof. by rewrite sgrM sgr_id. Qed.
Lemma sgr_gt0 x : (sg x > 0) = (x > 0).
Proof. by rewrite -[LHS]sgr_cp0 sgr_id sgr_cp0. Qed.
Lemma sgr_ge0 x : (sgr x >= 0) = (x >= 0).
Proof. by rewrite !leNgt sgr_lt0. Qed.
(* norm section *)
Lemma ler_norm x : (x <= `|x|).
Proof. exact: real_ler_norm. Qed.
Lemma ler_norml x y : (`|x| <= y) = (- y <= x <= y).
Proof. exact: real_ler_norml. Qed.
Lemma ler_normlP x y : reflect ((- x <= y) * (x <= y)) (`|x| <= y).
Proof. exact: real_ler_normlP. Qed.
Arguments ler_normlP {x y}.
Lemma eqr_norml x y : (`|x| == y) = ((x == y) || (x == -y)) && (0 <= y).
Proof. exact: real_eqr_norml. Qed.
Lemma eqr_norm2 x y : (`|x| == `|y|) = (x == y) || (x == -y).
Proof. exact: real_eqr_norm2. Qed.
Lemma ltr_norml x y : (`|x| < y) = (- y < x < y).
Proof. exact: real_ltr_norml. Qed.
Definition lter_norml := (ler_norml, ltr_norml).
Lemma ltr_normlP x y : reflect ((-x < y) * (x < y)) (`|x| < y).
Proof. exact: real_ltr_normlP. Qed.
Arguments ltr_normlP {x y}.
Lemma ltr_normlW x y : `|x| < y -> x < y. Proof. exact: real_ltr_normlW. Qed.
Lemma ltrNnormlW x y : `|x| < y -> - y < x. Proof. exact: real_ltrNnormlW. Qed.
Lemma ler_normlW x y : `|x| <= y -> x <= y. Proof. exact: real_ler_normlW. Qed.
Lemma lerNnormlW x y : `|x| <= y -> - y <= x. Proof. exact: real_lerNnormlW. Qed.
Lemma ler_normr x y : (x <= `|y|) = (x <= y) || (x <= - y).
Proof. exact: real_ler_normr. Qed.
Lemma ltr_normr x y : (x < `|y|) = (x < y) || (x < - y).
Proof. exact: real_ltr_normr. Qed.
Definition lter_normr := (ler_normr, ltr_normr).
Lemma ler_distl x y e : (`|x - y| <= e) = (y - e <= x <= y + e).
Proof. exact: real_ler_distl. Qed.
Lemma ltr_distl x y e : (`|x - y| < e) = (y - e < x < y + e).
Proof. exact: real_ltr_distl. Qed.
Definition lter_distl := (ler_distl, ltr_distl).
Lemma ltr_distlC x y e : (`|x - y| < e) = (x - e < y < x + e).
Proof. by rewrite distrC ltr_distl. Qed.
Lemma ler_distlC x y e : (`|x - y| <= e) = (x - e <= y <= x + e).
Proof. by rewrite distrC ler_distl. Qed.
Definition lter_distlC := (ler_distlC, ltr_distlC).
Lemma ltr_distlDr x y e : `|x - y| < e -> x < y + e.
Proof. exact: real_ltr_distlDr. Qed.
Lemma ler_distlDr x y e : `|x - y| <= e -> x <= y + e.
Proof. exact: real_ler_distlDr. Qed.
Lemma ltr_distlCDr x y e : `|x - y| < e -> y < x + e.
Proof. exact: real_ltr_distlCDr. Qed.
Lemma ler_distlCDr x y e : `|x - y| <= e -> y <= x + e.
Proof. exact: real_ler_distlCDr. Qed.
Lemma ltr_distlBl x y e : `|x - y| < e -> x - e < y.
Proof. exact: real_ltr_distlBl. Qed.
Lemma ler_distlBl x y e : `|x - y| <= e -> x - e <= y.
Proof. exact: real_ler_distlBl. Qed.
Lemma ltr_distlCBl x y e : `|x - y| < e -> y - e < x.
Proof. exact: real_ltr_distlCBl. Qed.
Lemma ler_distlCBl x y e : `|x - y| <= e -> y - e <= x.
Proof. exact: real_ler_distlCBl. Qed.
Lemma exprn_even_ge0 n x : ~~ odd n -> 0 <= x ^+ n.
Proof. by move=> even_n; rewrite real_exprn_even_ge0 ?num_real. Qed.
Lemma exprn_even_gt0 n x : ~~ odd n -> (0 < x ^+ n) = (n == 0)%N || (x != 0).
Proof. by move=> even_n; rewrite real_exprn_even_gt0 ?num_real. Qed.
Lemma exprn_even_le0 n x : ~~ odd n -> (x ^+ n <= 0) = (n != 0) && (x == 0).
Proof. by move=> even_n; rewrite real_exprn_even_le0 ?num_real. Qed.
Lemma exprn_even_lt0 n x : ~~ odd n -> (x ^+ n < 0) = false.
Proof. by move=> even_n; rewrite real_exprn_even_lt0 ?num_real. Qed.
Lemma exprn_odd_ge0 n x : odd n -> (0 <= x ^+ n) = (0 <= x).
Proof. by move=> even_n; rewrite real_exprn_odd_ge0 ?num_real. Qed.
Lemma exprn_odd_gt0 n x : odd n -> (0 < x ^+ n) = (0 < x).
Proof. by move=> even_n; rewrite real_exprn_odd_gt0 ?num_real. Qed.
Lemma exprn_odd_le0 n x : odd n -> (x ^+ n <= 0) = (x <= 0).
Proof. by move=> even_n; rewrite real_exprn_odd_le0 ?num_real. Qed.
Lemma exprn_odd_lt0 n x : odd n -> (x ^+ n < 0) = (x < 0).
Proof. by move=> even_n; rewrite real_exprn_odd_lt0 ?num_real. Qed.
(* lteif *)
Lemma lteif_norml C x y :
(`|x| < y ?<= if C) = (- y < x ?<= if C) && (x < y ?<= if C).
Proof. by case: C; rewrite /= lter_norml. Qed.
Lemma lteif_normr C x y :
(x < `|y| ?<= if C) = (x < y ?<= if C) || (x < - y ?<= if C).
Proof. by case: C; rewrite /= lter_normr. Qed.
Lemma lteif_distl C x y e :
(`|x - y| < e ?<= if C) = (y - e < x ?<= if C) && (x < y + e ?<= if C).
Proof. by case: C; rewrite /= lter_distl. Qed.
(* Special lemmas for squares. *)
Lemma sqr_ge0 x : 0 <= x ^+ 2. Proof. by rewrite exprn_even_ge0. Qed.
Lemma sqr_norm_eq1 x : (x ^+ 2 == 1) = (`|x| == 1).
Proof. by rewrite sqrf_eq1 eqr_norml ler01 andbT. Qed.
Lemma leif_mean_square_scaled x y :
x * y *+ 2 <= x ^+ 2 + y ^+ 2 ?= iff (x == y).
Proof. exact: real_leif_mean_square_scaled. Qed.
Lemma leif_AGM2_scaled x y : x * y *+ 4 <= (x + y) ^+ 2 ?= iff (x == y).
Proof. exact: real_leif_AGM2_scaled. Qed.
Section MinMax.
Lemma oppr_max : {morph -%R : x y / max x y >-> min x y : R}.
Proof. by move=> x y; apply: real_oppr_max. Qed.
Lemma oppr_min : {morph -%R : x y / min x y >-> max x y : R}.
Proof. by move=> x y; apply: real_oppr_min. Qed.
Lemma addr_minl : @left_distributive R R +%R min.
Proof. by move=> x y z; apply: real_addr_minl. Qed.
Lemma addr_minr : @right_distributive R R +%R min.
Proof. by move=> x y z; apply: real_addr_minr. Qed.
Lemma addr_maxl : @left_distributive R R +%R max.
Proof. by move=> x y z; apply: real_addr_maxl. Qed.
Lemma addr_maxr : @right_distributive R R +%R max.
Proof. by move=> x y z; apply: real_addr_maxr. Qed.
Lemma minr_nMr x y z : x <= 0 -> x * min y z = max (x * y) (x * z).
Proof. by move=> x_le0; apply: real_minr_nMr. Qed.
Lemma maxr_nMr x y z : x <= 0 -> x * max y z = min (x * y) (x * z).
Proof. by move=> x_le0; apply: real_maxr_nMr. Qed.
Lemma minr_nMl x y z : x <= 0 -> min y z * x = max (y * x) (z * x).
Proof. by move=> x_le0; apply: real_minr_nMl. Qed.
Lemma maxr_nMl x y z : x <= 0 -> max y z * x = min (y * x) (z * x).
Proof. by move=> x_le0; apply: real_maxr_nMl. Qed.
Lemma maxrN x : max x (- x) = `|x|. Proof. exact: real_maxrN. Qed.
Lemma maxNr x : max (- x) x = `|x|. Proof. exact: real_maxNr. Qed.
Lemma minrN x : min x (- x) = - `|x|. Proof. exact: real_minrN. Qed.
Lemma minNr x : min (- x) x = - `|x|. Proof. exact: real_minNr. Qed.
End MinMax.
Section PolyBounds.
Variable p : {poly R}.
Lemma poly_itv_bound a b : {ub | forall x, a <= x <= b -> `|p.[x]| <= ub}.
Proof.
have [ub le_p_ub] := poly_disk_bound p (Num.max `|a| `|b|).
exists ub => x /andP[le_a_x le_x_b]; rewrite le_p_ub // le_max !ler_normr.
by have [_|_] := ler0P x; rewrite ?lerN2 ?le_a_x ?le_x_b orbT.
Qed.
Lemma monic_Cauchy_bound : p \is monic -> {b | forall x, x >= b -> p.[x] > 0}.
Proof.
move/monicP=> mon_p; pose n := (size p - 2)%N.
have [p_le1 | p_gt1] := leqP (size p) 1.
exists 0 => x _; rewrite (size1_polyC p_le1) hornerC.
by rewrite -[p`_0]lead_coefC -size1_polyC // mon_p ltr01.
pose lb := \sum_(j < n.+1) `|p`_j|; exists (lb + 1) => x le_ub_x.
have x_ge1: 1 <= x; last have x_gt0 := lt_le_trans ltr01 x_ge1.
by rewrite -(lerD2l lb) ler_wpDl ?sumr_ge0 // => j _.
rewrite horner_coef -(subnK p_gt1) -/n addnS big_ord_recr /= addn1.
rewrite [in p`__]subnSK // subn1 -lead_coefE mon_p mul1r -ltrBlDl sub0r.
apply: le_lt_trans (_ : lb * x ^+ n < _); last first.
by rewrite exprS ltr_pM2r ?exprn_gt0// -(ltrD2r 1) ltr_pwDr.
rewrite -sumrN mulr_suml ler_sum // => j _; apply: le_trans (ler_norm _) _.
rewrite normrN normrM ler_wpM2l // normrX.
by rewrite ger0_norm ?(ltW x_gt0) // ler_weXn2l ?leq_ord.
Qed.
End PolyBounds.
End RealDomainOperations.
End Theory.
HB.factory Record IntegralDomain_isNumRing R of GRing.IntegralDomain R := {
Rle : rel R;
Rlt : rel R;
norm : R -> R;
normD : forall x y, Rle (norm (x + y)) (norm x + norm y);
addr_gt0 : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x + y);
norm_eq0 : forall x, norm x = 0 -> x = 0;
ger_total : forall x y, Rle 0 x -> Rle 0 y -> Rle x y || Rle y x;
normM : {morph norm : x y / x * y};
le_def : forall x y, (Rle x y) = (norm (y - x) == y - x);
lt_def : forall x y, (Rlt x y) = (y != x) && (Rle x y)
}.
HB.builders Context R of IntegralDomain_isNumRing R.
Local Notation "x <= y" := (Rle x y) : ring_scope.
Local Notation "x < y" := (Rlt x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Lemma ltrr x : x < x = false. Proof. by rewrite lt_def eqxx. Qed.
Lemma ge0_def x : (0 <= x) = (`|x| == x).
Proof. by rewrite le_def subr0. Qed.
Lemma subr_ge0 x y : (0 <= x - y) = (y <= x).
Proof. by rewrite ge0_def -le_def. Qed.
Lemma subr_gt0 x y : (0 < y - x) = (x < y).
Proof. by rewrite !lt_def subr_eq0 subr_ge0. Qed.
Lemma lt_trans : transitive Rlt.
Proof.
move=> y x z le_xy le_yz.
by rewrite -subr_gt0 -(subrK y z) -addrA addr_gt0 // subr_gt0.
Qed.
Lemma le01 : 0 <= 1.
Proof.
have n1_nz: `|1| != 0 :> R by apply: contraNneq (@oner_neq0 R) => /norm_eq0->.
by rewrite ge0_def -(inj_eq (mulfI n1_nz)) -normM !mulr1.
Qed.
Lemma lt01 : 0 < 1.
Proof. by rewrite lt_def oner_neq0 le01. Qed.
Lemma ltW x y : x < y -> x <= y. Proof. by rewrite lt_def => /andP[]. Qed.
Lemma lerr x : x <= x.
Proof.
have n2: `|2| == 2 :> R by rewrite -ge0_def ltW ?addr_gt0 ?lt01.
rewrite le_def subrr -(inj_eq (addrI `|0|)) addr0 -mulr2n -mulr_natr.
by rewrite -(eqP n2) -normM mul0r.
Qed.
Lemma le_def' x y : (x <= y) = (x == y) || (x < y).
Proof. by rewrite lt_def; case: eqVneq => //= ->; rewrite lerr. Qed.
Lemma le_trans : transitive Rle.
by move=> y x z; rewrite !le_def' => /predU1P [->|hxy] // /predU1P [<-|hyz];
rewrite ?hxy ?(lt_trans hxy hyz) orbT.
Qed.
Lemma normrMn x n : `|x *+ n| = `|x| *+ n.
Proof.
rewrite -mulr_natr -[RHS]mulr_natr normM.
congr (_ * _); apply/eqP; rewrite -ge0_def.
elim: n => [|n ih]; [exact: lerr | apply: (le_trans ih)].
by rewrite le_def -natrB // subSnn -[_%:R]subr0 -le_def mulr1n le01.
Qed.
Lemma normrN1 : `|-1| = 1 :> R.
Proof.
have: `|-1| ^+ 2 == 1 :> R
by rewrite expr2 /= -normM mulrNN mul1r -[1]subr0 -le_def le01.
rewrite sqrf_eq1 => /predU1P [] //; rewrite -[-1]subr0 -le_def.
have ->: 0 <= -1 = (-1 == 0 :> R) || (0 < -1)
by rewrite lt_def; case: eqP => // ->; rewrite lerr.
by rewrite oppr_eq0 oner_eq0 => /(addr_gt0 lt01); rewrite subrr ltrr.
Qed.
Lemma normrN x : `|- x| = `|x|.
Proof. by rewrite -mulN1r normM -[RHS]mul1r normrN1. Qed.
HB.instance Definition _ :=
Order.LtLe_isPOrder.Build ring_display R le_def' ltrr lt_trans.
HB.instance Definition _ :=
Zmodule_isNormed.Build _ R normD norm_eq0 normrMn normrN.
HB.instance Definition _ :=
isNumRing.Build R addr_gt0 ger_total normM le_def.
HB.end.
HB.factory Record NumDomain_isReal R of NumDomain R := {
real : real_axiom R
}.
HB.builders Context R of NumDomain_isReal R.
Lemma le_total : Order.POrder_isTotal ring_display R.
Proof.
constructor=> x y; move: (real (x - y)).
by rewrite unfold_in /= !ler_def subr0 add0r opprB orbC.
Qed.
HB.instance Definition _ := le_total.
HB.end.
HB.factory Record IntegralDomain_isLeReal R of GRing.IntegralDomain R := {
Rle : rel R;
Rlt : rel R;
norm : R -> R;
le0_add : forall x y, Rle 0 x -> Rle 0 y -> Rle 0 (x + y);
le0_mul : forall x y, Rle 0 x -> Rle 0 y -> Rle 0 (x * y);
le0_anti : forall x, Rle 0 x -> Rle x 0 -> x = 0;
sub_ge0 : forall x y, Rle 0 (y - x) = Rle x y;
le0_total : forall x, Rle 0 x || Rle x 0;
normN : forall x, norm (- x) = norm x;
ge0_norm : forall x, Rle 0 x -> norm x = x;
lt_def : forall x y, Rlt x y = (y != x) && Rle x y;
}.
HB.builders Context R of IntegralDomain_isLeReal R.
Local Notation le := Rle.
Local Notation lt := Rlt.
Local Notation "x <= y" := (le x y) : ring_scope.
Local Notation "x < y" := (lt x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Let le0N x : (0 <= - x) = (x <= 0). Proof. by rewrite -sub0r sub_ge0. Qed.
Let leN_total x : 0 <= x \/ 0 <= - x.
Proof. by apply/orP; rewrite le0N le0_total. Qed.
Let le00 : 0 <= 0. Proof. by have:= le0_total 0; rewrite orbb. Qed.
Fact lt0_add x y : 0 < x -> 0 < y -> 0 < x + y.
Proof.
rewrite !lt_def => /andP [x_neq0 l0x] /andP [y_neq0 l0y]; rewrite le0_add //.
rewrite andbT addr_eq0; apply: contraNneq x_neq0 => hxy.
by rewrite [x](@le0_anti) // hxy -le0N opprK.
Qed.
Fact eq0_norm x : `|x| = 0 -> x = 0.
Proof.
case: (leN_total x) => /ge0_norm => [-> // | Dnx nx0].
by rewrite -[x]opprK -Dnx normN nx0 oppr0.
Qed.
Fact le_def x y : (x <= y) = (`|y - x| == y - x).
Proof.
wlog ->: x y / x = 0 by move/(_ 0 (y - x)); rewrite subr0 sub_ge0 => ->.
rewrite {x}subr0; apply/idP/eqP=> [/ge0_norm// | Dy].
by have [//| ny_ge0] := leN_total y; rewrite -Dy -normN ge0_norm.
Qed.
Fact normM : {morph norm : x y / x * y}.
Proof.
move=> x y /=; wlog x_ge0 : x / 0 <= x.
by move=> IHx; case: (leN_total x) => /IHx//; rewrite mulNr !normN.
wlog y_ge0 : y / 0 <= y; last by rewrite ?ge0_norm ?le0_mul.
by move=> IHy; case: (leN_total y) => /IHy//; rewrite mulrN !normN.
Qed.
Fact le_normD x y : `|x + y| <= `|x| + `|y|.
Proof.
wlog x_ge0 : x y / 0 <= x.
by move=> IH; case: (leN_total x) => /IH// /(_ (- y)); rewrite -opprD !normN.
rewrite -sub_ge0 ge0_norm //; have [y_ge0 | ny_ge0] := leN_total y.
by rewrite !ge0_norm ?subrr ?le0_add.
rewrite -normN ge0_norm //; have [hxy|hxy] := leN_total (x + y).
by rewrite ge0_norm // opprD addrCA -addrA addKr le0_add.
by rewrite -normN ge0_norm // opprK addrCA addrNK le0_add.
Qed.
Fact le_total : total le.
Proof. by move=> x y; rewrite -sub_ge0 -opprB le0N orbC -sub_ge0 le0_total. Qed.
HB.instance Definition _ := IntegralDomain_isNumRing.Build R
le_normD lt0_add eq0_norm (in2W le_total) normM le_def lt_def.
HB.instance Definition _ := Order.POrder_isTotal.Build ring_display R
le_total.
HB.end.
HB.factory Record IntegralDomain_isLtReal R of GRing.IntegralDomain R := {
Rlt : rel R;
Rle : rel R;
norm : R -> R;
lt0_add : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x + y);
lt0_mul : forall x y, Rlt 0 x -> Rlt 0 y -> Rlt 0 (x * y);
lt0_ngt0 : forall x, Rlt 0 x -> ~~ (Rlt x 0);
sub_gt0 : forall x y, Rlt 0 (y - x) = Rlt x y;
lt0_total : forall x, x != 0 -> Rlt 0 x || Rlt x 0;
normN : forall x, norm (- x) = norm x;
ge0_norm : forall x, Rle 0 x -> norm x = x;
le_def : forall x y, Rle x y = (x == y) || Rlt x y;
}.
HB.builders Context R of IntegralDomain_isLtReal R.
Local Notation le := Rle.
Local Notation lt := Rlt.
Local Notation "x < y" := (lt x y) : ring_scope.
Local Notation "x <= y" := (le x y) : ring_scope.
Local Notation "`| x |" := (norm x) : ring_scope.
Fact lt0N x : (- x < 0) = (0 < x).
Proof. by rewrite -sub_gt0 add0r opprK. Qed.
Let leN_total x : 0 <= x \/ 0 <= - x.
Proof.
rewrite !le_def [_ == - x]eq_sym oppr_eq0 -[0 < - x]lt0N opprK.
apply/orP; case: (eqVneq x) => //=; exact: lt0_total.
Qed.
Let le00 : (0 <= 0). Proof. by rewrite le_def eqxx. Qed.
Fact sub_ge0 x y : (0 <= y - x) = (x <= y).
Proof. by rewrite !le_def eq_sym subr_eq0 eq_sym sub_gt0. Qed.
Fact le0_add x y : 0 <= x -> 0 <= y -> 0 <= x + y.
Proof.
rewrite !le_def => /predU1P [<-|x_gt0]; first by rewrite add0r.
by case/predU1P=> [<-|y_gt0]; rewrite ?addr0 ?x_gt0 ?lt0_add // orbT.
Qed.
Fact le0_mul x y : 0 <= x -> 0 <= y -> 0 <= x * y.
Proof.
rewrite !le_def => /predU1P [<-|x_gt0]; first by rewrite mul0r eqxx.
by case/predU1P=> [<-|y_gt0]; rewrite ?mulr0 ?eqxx ?lt0_mul // orbT.
Qed.
Fact normM : {morph norm : x y / x * y}.
Proof.
move=> x y /=; wlog x_ge0 : x / 0 <= x.
by move=> IHx; case: (leN_total x) => /IHx//; rewrite mulNr !normN.
wlog y_ge0 : y / 0 <= y; last by rewrite ?ge0_norm ?le0_mul.
by move=> IHy; case: (leN_total y) => /IHy//; rewrite mulrN !normN.
Qed.
Fact le_normD x y : `|x + y| <= `|x| + `|y|.
Proof.
wlog x_ge0 : x y / 0 <= x.
by move=> IH; case: (leN_total x) => /IH// /(_ (- y)); rewrite -opprD !normN.
rewrite -sub_ge0 ge0_norm //; have [y_ge0 | ny_ge0] := leN_total y.
by rewrite !ge0_norm ?subrr ?le0_add.
rewrite -normN ge0_norm //; have [hxy|hxy] := leN_total (x + y).
by rewrite ge0_norm // opprD addrCA -addrA addKr le0_add.
by rewrite -normN ge0_norm // opprK addrCA addrNK le0_add.
Qed.
Fact eq0_norm x : `|x| = 0 -> x = 0.
Proof.
case: (leN_total x) => /ge0_norm => [-> // | Dnx nx0].
by rewrite -[x]opprK -Dnx normN nx0 oppr0.
Qed.
Fact le_def' x y : (x <= y) = (`|y - x| == y - x).
Proof.
wlog ->: x y / x = 0 by move/(_ 0 (y - x)); rewrite subr0 sub_ge0 => ->.
rewrite {x}subr0; apply/idP/eqP=> [/ge0_norm// | Dy].
by have [//| ny_ge0] := leN_total y; rewrite -Dy -normN ge0_norm.
Qed.
Fact lt_def x y : (x < y) = (y != x) && (x <= y).
Proof.
rewrite le_def; case: eqVneq => //= ->; rewrite -sub_gt0 subrr.
by apply/idP=> lt00; case/negP: (lt0_ngt0 lt00).
Qed.
Fact le_total : total le.
Proof.
move=> x y; rewrite !le_def; have [->|] //= := eqVneq; rewrite -subr_eq0.
by move/lt0_total; rewrite -(sub_gt0 (x - y)) sub0r opprB !sub_gt0 orbC.
Qed.
HB.instance Definition _ := IntegralDomain_isNumRing.Build R
le_normD lt0_add eq0_norm (in2W le_total) normM le_def' lt_def.
HB.instance Definition _ := Order.POrder_isTotal.Build ring_display R
le_total.
HB.end.
Module Exports. HB.reexport. End Exports.
End Num.
Export Num.Exports Num.Syntax Num.PredInstances.
|
Elementwise.lean
|
import Mathlib.Tactic.CategoryTheory.Elementwise
import Mathlib.Algebra.Category.MonCat.Basic
set_option autoImplicit true
namespace ElementwiseTest
open CategoryTheory
namespace HasForget
attribute [simp] Iso.hom_inv_id Iso.inv_hom_id IsIso.hom_inv_id IsIso.inv_hom_id
attribute [local instance] HasForget.instFunLike HasForget.hasCoeToSort
@[elementwise]
theorem ex1 [Category C] [HasForget C] (X : C) (f g h : X βΆ X) (h' : g β« h = h β« g) :
f β« g β« h = f β« h β« g := by rw [h']
-- If there is already a `HasForget` instance, do not add a new argument.
example : β C [Category C] [HasForget C] (X : C) (f g h : X βΆ X) (_ : g β« h = h β« g)
(x : X), h (g (f x)) = g (h (f x)) := @ex1_apply
@[elementwise]
theorem ex2 [Category C] (X : C) (f g h : X βΆ X) (h' : g β« h = h β« g) :
f β« g β« h = f β« h β« g := by rw [h']
-- If there is not already a `ConcreteCategory` instance, insert a new argument.
example : β C [Category C] (X : C) (f g h : X βΆ X) (_ : g β« h = h β« g)
{FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
[ConcreteCategory C FC]
(x : ToType X), h (g (f x)) = g (h (f x)) := @ex2_apply
-- Need nosimp on the following `elementwise` since the lemma can be proved by simp anyway.
@[elementwise nosimp]
theorem ex3 [Category C] {X Y : C} (f : X β
Y) : f.hom β« f.inv = π X :=
Iso.hom_inv_id _
example : β C [Category C] (X Y : C) (f : X β
Y)
{FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
[ConcreteCategory C FC]
(x : ToType X), f.inv (f.hom x) = x := @ex3_apply
-- Make sure there's no `id x` in there:
example : β C [Category C] (X Y : C) (f : X β
Y)
{FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
[ConcreteCategory C FC]
(x : ToType X), f.inv (f.hom x) = x := by intros; simp only [ex3_apply]
@[elementwise]
lemma foo [Category C]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) : f β« π N β« g = h := by
simp [w]
@[elementwise]
lemma foo' [Category C]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) : f β« π N β« g = h := by
simp [w]
lemma bar [Category C] {FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
[ConcreteCategory C FC]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) : g (f x) = h x := by
apply foo_apply w
example {M N K : Type} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by
have := elementwise_of% w
guard_hyp this : β (x : M), g (f x) = h x
exact this x
example {M N K : Type} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := (elementwise_of% w) x
example [Category C] [HasForget C]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by
have := elementwise_of% w
guard_hyp this : β (x : M), g (f x) = h x
exact this x
-- `elementwise_of%` allows a level metavariable for its `ConcreteCategory` instance.
-- Previously this example did not specify that the universe levels of `C` and `D` (inside `h`)
-- were the same, and this constraint was added post-hoc by the proof term.
-- After https://github.com/leanprover/lean4/pull/4493 this no longer works (happily!).
example {C : Type u} [Category.{v} C] {FC : C β C β Type _} {CC : C β Type w}
[β X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{w} C FC]
(h : β (D : Type u) [Category.{v} D] (X Y : D) (f : X βΆ Y) (g : Y βΆ X), f β« g = π X)
{M N : C} {f : M βΆ N} {g : N βΆ M} (x : M) : g (f x) = x := by
have := elementwise_of% h
guard_hyp this : β D [Category D] (X Y : D) (f : X βΆ Y) (g : Y βΆ X)
{FD : D β D β Type _} {CD : D β Type*}
[β X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory D FD] (x : ToType X), g (f x) = x
rw [this]
section Mon
lemma bar' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by exact foo_apply w x
lemma bar'' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by apply foo_apply w
lemma bar''' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by apply foo_apply w
example (M N K : MonCat) (f : M βΆ N) (g : N βΆ K) (h : M βΆ K) (w : f β« g = h) (m : M) :
g (f m) = h m := by rw [elementwise_of% w]
example (M N K : MonCat) (f : M βΆ N) (g : N βΆ K) (h : M βΆ K) (w : f β« g = h) (m : M) :
g (f m) = h m := by
replace w := elementwise_of% w
apply w
end Mon
example {Ξ± Ξ² : Type} (f g : Ξ± βΆ Ξ²) (w : f = g) (a : Ξ±) : f a = g a := by
replace w := elementwise_of% w
guard_hyp w : β (x : Ξ±), f x = g x
rw [w]
example {Ξ± Ξ² : Type} (f g : Ξ± βΆ Ξ²) (w : f β« π Ξ² = g) (a : Ξ±) : f a = g a := by
replace w := elementwise_of% w
guard_hyp w : β (x : Ξ±), f x = g x
rw [w]
variable {C : Type*} [Category C]
def f (X : C) : X βΆ X := π X
def g (X : C) : X βΆ X := π X
def h (X : C) : X βΆ X := π X
lemma gh (X : C) : g X = h X := rfl
@[elementwise]
theorem fh (X : C) : f X = h X := gh X
variable (X : C) {FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
variable [ConcreteCategory C FC] (x : X)
-- Prior to https://github.com/leanprover-community/mathlib4/pull/13413 this would produce
-- `fh_apply X x : (g X) x = (h X) x`.
/-- info: fh_apply X x : (ConcreteCategory.hom (f X)) x = (ConcreteCategory.hom (h X)) x -/
#guard_msgs in
#check fh_apply X x
end HasForget
namespace ConcreteCategory
attribute [simp] Iso.hom_inv_id Iso.inv_hom_id IsIso.hom_inv_id IsIso.inv_hom_id
attribute [simp] Iso.hom_inv_id Iso.inv_hom_id IsIso.hom_inv_id IsIso.inv_hom_id
variable {C : Type*} {FC : C β C β Type*} {CC : C β Type*}
variable [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
@[elementwise]
theorem ex1 [Category C] [ConcreteCategory C FC] (X : C) (f g h : X βΆ X) (h' : g β« h = h β« g) :
f β« g β« h = f β« h β« g := by rw [h']
-- If there is already a `ConcreteCategory` instance, do not add a new argument.
example : β C {FC : C β C β Type*} {CC : C β Type*} [β X Y, FunLike (FC X Y) (CC X) (CC Y)] [Category C] [ConcreteCategory C FC] (X : C) (f g h : X βΆ X) (_ : g β« h = h β« g)
(x : ToType X), h (g (f x)) = g (h (f x)) := @ex1_apply
@[elementwise]
lemma foo [Category C]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) : f β« π N β« g = h := by
simp [w]
@[elementwise]
lemma foo' [Category C]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) : f β« π N β« g = h := by
simp [w]
lemma bar [Category C]
{FC : C β C β Type _} {CC : C β Type _} [β X Y, FunLike (FC X Y) (CC X) (CC Y)]
[ConcreteCategory C FC]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : ToType M) : g (f x) = h x := by
apply foo_apply w
example {M N K : Type} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by
have := elementwise_of% w
guard_hyp this : β (x : M), g (f x) = h x
exact this x
example {M N K : Type} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := (elementwise_of% w) x
example [Category C] {FC : C β C β Type _} {CC : C β Type _}
[β X Y, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory C FC]
{M N K : C} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : ToType M) :
g (f x) = h x := by
have := elementwise_of% w
guard_hyp this : β (x : ToType M), g (f x) = h x
exact this x
section Mon
lemma bar' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by exact foo_apply w x
lemma bar'' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by apply foo_apply w
lemma bar''' {M N K : MonCat} {f : M βΆ N} {g : N βΆ K} {h : M βΆ K} (w : f β« g = h) (x : M) :
g (f x) = h x := by apply foo_apply w
example (M N K : MonCat) (f : M βΆ N) (g : N βΆ K) (h : M βΆ K) (w : f β« g = h) (m : M) :
g (f m) = h m := by rw [elementwise_of% w]
example (M N K : MonCat) (f : M βΆ N) (g : N βΆ K) (h : M βΆ K) (w : f β« g = h) (m : M) :
g (f m) = h m := by
replace w := elementwise_of% w
apply w
end Mon
example {Ξ± Ξ² : Type} (f g : Ξ± βΆ Ξ²) (w : f = g) (a : Ξ±) : f a = g a := by
replace w := elementwise_of% w
guard_hyp w : β (x : Ξ±), f x = g x
rw [w]
example {Ξ± Ξ² : Type} (f g : Ξ± βΆ Ξ²) (w : f β« π Ξ² = g) (a : Ξ±) : f a = g a := by
replace w := elementwise_of% w
guard_hyp w : β (x : Ξ±), f x = g x
rw [w]
end ConcreteCategory
end ElementwiseTest
|
Indicator.lean
|
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Hom.Defs
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Notation.Indicator
/-!
# Indicator function
In this file, we prove basic results about the indicator of a set.
- `Set.indicator (s : Set Ξ±) (f : Ξ± β Ξ²) (a : Ξ±)` is `f a` if `a β s` and is `0` otherwise.
- `Set.mulIndicator (s : Set Ξ±) (f : Ξ± β Ξ²) (a : Ξ±)` is `f a` if `a β s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `fun _ β¦ 1`.
The indicator function is implemented non-computably, to avoid having to pass around `Decidable`
arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`.
## Tags
indicator, characteristic
-/
assert_not_exists MonoidWithZero
open Function
variable {Ξ± Ξ² M N : Type*}
namespace Set
section Monoid
variable [MulOneClass M] {s t : Set Ξ±} {a : Ξ±}
@[to_additive]
theorem mulIndicator_union_mul_inter_apply (f : Ξ± β M) (s t : Set Ξ±) (a : Ξ±) :
mulIndicator (s βͺ t) f a * mulIndicator (s β© t) f a
= mulIndicator s f a * mulIndicator t f a := by
by_cases hs : a β s <;> by_cases ht : a β t <;> simp [*]
@[to_additive]
theorem mulIndicator_union_mul_inter (f : Ξ± β M) (s t : Set Ξ±) :
mulIndicator (s βͺ t) f * mulIndicator (s β© t) f = mulIndicator s f * mulIndicator t f :=
funext <| mulIndicator_union_mul_inter_apply f s t
@[to_additive]
theorem mulIndicator_union_of_notMem_inter (h : a β s β© t) (f : Ξ± β M) :
mulIndicator (s βͺ t) f a = mulIndicator s f a * mulIndicator t f a := by
rw [β mulIndicator_union_mul_inter_apply f s t, mulIndicator_of_notMem h, mul_one]
@[deprecated (since := "2025-05-23")]
alias indicator_union_of_not_mem_inter := indicator_union_of_notMem_inter
@[to_additive existing, deprecated (since := "2025-05-23")]
alias mulIndicator_union_of_not_mem_inter := mulIndicator_union_of_notMem_inter
@[to_additive]
theorem mulIndicator_union_of_disjoint (h : Disjoint s t) (f : Ξ± β M) :
mulIndicator (s βͺ t) f = fun a => mulIndicator s f a * mulIndicator t f a :=
funext fun _ => mulIndicator_union_of_notMem_inter (fun ha => h.le_bot ha) _
open scoped symmDiff in
@[to_additive]
theorem mulIndicator_symmDiff (s t : Set Ξ±) (f : Ξ± β M) :
mulIndicator (s β t) f = mulIndicator (s \ t) f * mulIndicator (t \ s) f :=
mulIndicator_union_of_disjoint (disjoint_sdiff_self_right.mono_left sdiff_le) _
@[to_additive]
theorem mulIndicator_mul (s : Set Ξ±) (f g : Ξ± β M) :
(mulIndicator s fun a => f a * g a) = fun a => mulIndicator s f a * mulIndicator s g a := by
funext
simp only [mulIndicator]
split_ifs
Β· rfl
rw [mul_one]
@[to_additive]
theorem mulIndicator_mul' (s : Set Ξ±) (f g : Ξ± β M) :
mulIndicator s (f * g) = mulIndicator s f * mulIndicator s g :=
mulIndicator_mul s f g
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self_apply (s : Set Ξ±) (f : Ξ± β M) (a : Ξ±) :
mulIndicator sαΆ f a * mulIndicator s f a = f a :=
by_cases (fun ha : a β s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_compl_mul_self (s : Set Ξ±) (f : Ξ± β M) :
mulIndicator sαΆ f * mulIndicator s f = f :=
funext <| mulIndicator_compl_mul_self_apply s f
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl_apply (s : Set Ξ±) (f : Ξ± β M) (a : Ξ±) :
mulIndicator s f a * mulIndicator sαΆ f a = f a :=
by_cases (fun ha : a β s => by simp [ha]) fun ha => by simp [ha]
@[to_additive (attr := simp)]
theorem mulIndicator_self_mul_compl (s : Set Ξ±) (f : Ξ± β M) :
mulIndicator s f * mulIndicator sαΆ f = f :=
funext <| mulIndicator_self_mul_compl_apply s f
@[to_additive]
theorem mulIndicator_mul_eq_left {f g : Ξ± β M} (h : Disjoint (mulSupport f) (mulSupport g)) :
(mulSupport f).mulIndicator (f * g) = f := by
refine (mulIndicator_congr fun x hx => ?_).trans mulIndicator_mulSupport
have : g x = 1 := notMem_mulSupport.1 (disjoint_left.1 h hx)
rw [Pi.mul_apply, this, mul_one]
@[to_additive]
theorem mulIndicator_mul_eq_right {f g : Ξ± β M} (h : Disjoint (mulSupport f) (mulSupport g)) :
(mulSupport g).mulIndicator (f * g) = g := by
refine (mulIndicator_congr fun x hx => ?_).trans mulIndicator_mulSupport
have : f x = 1 := notMem_mulSupport.1 (disjoint_right.1 h hx)
rw [Pi.mul_apply, this, one_mul]
@[to_additive]
theorem mulIndicator_mul_compl_eq_piecewise [DecidablePred (Β· β s)] (f g : Ξ± β M) :
s.mulIndicator f * sαΆ.mulIndicator g = s.piecewise f g := by
ext x
by_cases h : x β s
Β· rw [piecewise_eq_of_mem _ _ _ h, Pi.mul_apply, Set.mulIndicator_of_mem h,
Set.mulIndicator_of_notMem (Set.notMem_compl_iff.2 h), mul_one]
Β· rw [piecewise_eq_of_notMem _ _ _ h, Pi.mul_apply, Set.mulIndicator_of_notMem h,
Set.mulIndicator_of_mem (Set.mem_compl h), one_mul]
/-- `Set.mulIndicator` as a `monoidHom`. -/
@[to_additive /-- `Set.indicator` as an `addMonoidHom`. -/]
noncomputable def mulIndicatorHom {Ξ±} (M) [MulOneClass M] (s : Set Ξ±) : (Ξ± β M) β* Ξ± β M where
toFun := mulIndicator s
map_one' := mulIndicator_one M s
map_mul' := mulIndicator_mul s
end Monoid
section Group
variable {G : Type*} [Group G] {s t : Set Ξ±}
@[to_additive]
theorem mulIndicator_inv' (s : Set Ξ±) (f : Ξ± β G) : mulIndicator s fβ»ΒΉ = (mulIndicator s f)β»ΒΉ :=
(mulIndicatorHom G s).map_inv f
@[to_additive]
theorem mulIndicator_inv (s : Set Ξ±) (f : Ξ± β G) :
(mulIndicator s fun a => (f a)β»ΒΉ) = fun a => (mulIndicator s f a)β»ΒΉ :=
mulIndicator_inv' s f
@[to_additive]
theorem mulIndicator_div (s : Set Ξ±) (f g : Ξ± β G) :
(mulIndicator s fun a => f a / g a) = fun a => mulIndicator s f a / mulIndicator s g a :=
(mulIndicatorHom G s).map_div f g
@[to_additive]
theorem mulIndicator_div' (s : Set Ξ±) (f g : Ξ± β G) :
mulIndicator s (f / g) = mulIndicator s f / mulIndicator s g :=
mulIndicator_div s f g
@[to_additive indicator_compl']
theorem mulIndicator_compl (s : Set Ξ±) (f : Ξ± β G) :
mulIndicator sαΆ f = f * (mulIndicator s f)β»ΒΉ :=
eq_mul_inv_of_mul_eq <| s.mulIndicator_compl_mul_self f
@[to_additive indicator_compl]
theorem mulIndicator_compl' (s : Set Ξ±) (f : Ξ± β G) :
mulIndicator sαΆ f = f / mulIndicator s f := by rw [div_eq_mul_inv, mulIndicator_compl]
@[to_additive indicator_diff']
theorem mulIndicator_diff (h : s β t) (f : Ξ± β G) :
mulIndicator (t \ s) f = mulIndicator t f * (mulIndicator s f)β»ΒΉ :=
eq_mul_inv_of_mul_eq <| by
rw [Pi.mul_def, β mulIndicator_union_of_disjoint, diff_union_self,
union_eq_self_of_subset_right h]
exact disjoint_sdiff_self_left
@[to_additive indicator_diff]
theorem mulIndicator_diff' (h : s β t) (f : Ξ± β G) :
mulIndicator (t \ s) f = mulIndicator t f / mulIndicator s f := by
rw [mulIndicator_diff h, div_eq_mul_inv]
open scoped symmDiff in
@[to_additive]
theorem apply_mulIndicator_symmDiff {g : G β Ξ²} (hg : β x, g xβ»ΒΉ = g x)
(s t : Set Ξ±) (f : Ξ± β G) (x : Ξ±) :
g (mulIndicator (s β t) f x) = g (mulIndicator s f x / mulIndicator t f x) := by
by_cases hs : x β s <;> by_cases ht : x β t <;> simp [mem_symmDiff, *]
end Group
end Set
@[to_additive]
theorem MonoidHom.map_mulIndicator {M N : Type*} [MulOneClass M] [MulOneClass N] (f : M β* N)
(s : Set Ξ±) (g : Ξ± β M) (x : Ξ±) : f (s.mulIndicator g x) = s.mulIndicator (f β g) x := by
simp [Set.mulIndicator_comp_of_one]
|
ModularCharacter.lean
|
/-
Copyright (c) 2025 Noam Atar. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Noam Atar
-/
import Mathlib.MeasureTheory.Function.LocallyIntegrable
import Mathlib.MeasureTheory.Group.Integral
import Mathlib.MeasureTheory.Group.Measure
import Mathlib.Topology.Metrizable.Urysohn
import Mathlib.MeasureTheory.Measure.Haar.Unique
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-!
# Modular character of a locally compact group
On a locally compact group, there is a natural homomorphism `G β ββ₯0*`, which for `g : G` gives the
value `ΞΌ (Β· * gβ»ΒΉ) / ΞΌ`, where `ΞΌ` is an (inner regular) Haar measure. This file defines this
homomorphism, called the modular character, and shows that it is independent of the chosen Haar
measure.
TODO: Show that the character is continuous.
## Main Declarations
* `modularCharacterFun`: Define the modular character function. If `ΞΌ` is a left Haar measure on `G`
and `g : G`, the measure `A β¦ ΞΌ (A gβ»ΒΉ)` is also a left Haar measure, so by uniqueness is of the
form `Ξ(g) ΞΌ`, for `Ξ(g) β ββ₯0`. This `Ξ` is the modular character. The result that this does not
depend on the measure chosen is `modularCharacterFun_eq_haarScalarFactor`.
* `modularCharacter`: The homomorphism G β* ββ₯0 whose toFun is `modularCharacterFun`.
-/
open MeasureTheory
open scoped NNReal
namespace MeasureTheory
namespace Measure
variable {G : Type*} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [LocallyCompactSpace G]
/-- The modular character as a map is `g β¦ ΞΌ (Β· * gβ»ΒΉ) / ΞΌ`, where `ΞΌ` is a left Haar measure.
See also `modularCharacter` that defines the map as a homomorphism. -/
@[to_additive /-- The additive modular character as a map is `g β¦ ΞΌ (Β· - g) / ΞΌ`, where `ΞΌ` is an
left additive Haar measure. -/]
noncomputable def modularCharacterFun (g : G) : ββ₯0 :=
letI : MeasurableSpace G := borel G
haveI : BorelSpace G := β¨rflβ©
haarScalarFactor (map (Β· * g) MeasureTheory.Measure.haar) MeasureTheory.Measure.haar
/-- Independence of modularCharacterFun from the chosen Haar measure. -/
@[to_additive /-- Independence of addModularCharacterFun from the chosen Haar measure -/]
lemma modularCharacterFun_eq_haarScalarFactor [MeasurableSpace G] [BorelSpace G] (ΞΌ : Measure G)
[IsHaarMeasure ΞΌ] (g : G) : modularCharacterFun g = haarScalarFactor (map (Β· * g) ΞΌ) ΞΌ := by
let Ξ½ := MeasureTheory.Measure.haar (G := G)
obtain β¨β¨f, f_contβ©, f_comp, f_nonneg, f_oneβ© :
β f : C(G, β), HasCompactSupport f β§ 0 β€ f β§ f 1 β 0 := exists_continuous_nonneg_pos 1
have int_f_ne_zero (ΞΌβ : Measure G) [IsHaarMeasure ΞΌβ] : β« x, f x βΞΌβ β 0 :=
ne_of_gt (f_cont.integral_pos_of_hasCompactSupport_nonneg_nonzero f_comp f_nonneg f_one)
apply NNReal.coe_injective
have t : (β« x, f (x * g) βΞ½) = (β« x, f (x * g) β(haarScalarFactor Ξ½ ΞΌ β’ ΞΌ)) := by
refine integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport Ξ½ ΞΌ ?_ ?_
Β· exact Continuous.comp' f_cont (continuous_mul_right g)
Β· have j : (fun x β¦ f (x * g)) = (f β (Homeomorph.mulRight g)) := rfl
rw [j]
exact HasCompactSupport.comp_homeomorph f_comp _
have r : (haarScalarFactor Ξ½ ΞΌ : β) / (haarScalarFactor Ξ½ ΞΌ) = 1 := by
refine div_self ?_
rw [NNReal.coe_ne_zero]
apply (ne_of_lt (haarScalarFactor_pos_of_isHaarMeasure _ _)).symm
calc
β(modularCharacterFun g) = β(haarScalarFactor (map (Β· * g) Ξ½) Ξ½) := by borelize G; rfl
_ = (β« x, f x β(map (Β· * g) Ξ½)) / β« x, f x βΞ½ :=
haarScalarFactor_eq_integral_div _ _ f_cont f_comp (int_f_ne_zero Ξ½)
_ = (β« x, f (x * g) βΞ½) / β« x, f x βΞ½ := by
rw [integral_map (AEMeasurable.mul_const aemeasurable_id' _)
(Continuous.aestronglyMeasurable f_cont)]
_ = (β« x, f (x * g) β(haarScalarFactor Ξ½ ΞΌ β’ ΞΌ)) / β« x, f x βΞ½ := by rw [t]
_ = (β« x, f (x * g) β(haarScalarFactor Ξ½ ΞΌ β’ ΞΌ)) / β« x, f x β(haarScalarFactor Ξ½ ΞΌ β’ ΞΌ) := by
rw [integral_isMulLeftInvariant_eq_smul_of_hasCompactSupport Ξ½ ΞΌ f_cont f_comp]
_ = (haarScalarFactor Ξ½ ΞΌ β’ β« x, f (x * g) βΞΌ) / (haarScalarFactor Ξ½ ΞΌ β’ β« x, f x βΞΌ) := by
rw [integral_smul_nnreal_measure, integral_smul_nnreal_measure]
_ = (haarScalarFactor Ξ½ ΞΌ / haarScalarFactor Ξ½ ΞΌ) * ((β« x, f (x * g) βΞΌ) / β« x, f x βΞΌ) :=
mul_div_mul_comm _ _ _ _
_ = 1 * ((β« x, f (x * g) βΞΌ) / β« x, f x βΞΌ) := by rw [r]
_ = (β« x, f (x * g) βΞΌ) / β« x, f x βΞΌ := by rw [one_mul]
_ = (β« x, f x β(map (Β· * g) ΞΌ)) / β« x, f x βΞΌ := by
rw [integral_map (AEMeasurable.mul_const aemeasurable_id' _)
(Continuous.aestronglyMeasurable f_cont)]
_ = haarScalarFactor (map (Β· * g) ΞΌ) ΞΌ :=
(haarScalarFactor_eq_integral_div _ _ f_cont f_comp (int_f_ne_zero ΞΌ)).symm
@[to_additive]
lemma map_right_mul_eq_modularCharacterFun_smul [MeasurableSpace G] [BorelSpace G] (ΞΌ : Measure G)
[IsHaarMeasure ΞΌ] [InnerRegular ΞΌ] (g : G) : map (Β· * g) ΞΌ = modularCharacterFun g β’ ΞΌ := by
rw [modularCharacterFun_eq_haarScalarFactor ΞΌ _]
exact isMulLeftInvariant_eq_smul_of_innerRegular _ ΞΌ
@[to_additive]
lemma modularCharacterFun_pos (g : G) : 0 < modularCharacterFun g := by
borelize G
rw [modularCharacterFun_eq_haarScalarFactor MeasureTheory.Measure.haar g]
exact haarScalarFactor_pos_of_isHaarMeasure _ _
@[to_additive]
lemma modularCharacterFun_map_one : modularCharacterFun (1 : G) = 1 := by
simp [modularCharacterFun, haarScalarFactor_self]
@[to_additive]
lemma modularCharacterFun_map_mul (g h : G) : modularCharacterFun (g * h) =
modularCharacterFun g * modularCharacterFun h := by
borelize G
have mul_g_meas : Measurable (Β· * g) := Measurable.mul_const (fun β¦_β¦ a β¦ a) g
have mul_h_meas : Measurable (Β· * h) := Measurable.mul_const (fun β¦_β¦ a β¦ a) h
let Ξ½ := MeasureTheory.Measure.haar (G := G)
symm
calc
modularCharacterFun g * modularCharacterFun h =
modularCharacterFun h * modularCharacterFun g := mul_comm _ _
_ = haarScalarFactor (map (Β· * h) (map (Β· * g) Ξ½)) (map (Β· * g) Ξ½) *
modularCharacterFun g := by
rw [modularCharacterFun_eq_haarScalarFactor (map (Β· * g) Ξ½) _]
_ = haarScalarFactor (map (Β· * h) (map (Β· * g) Ξ½)) (map (Β· * g) Ξ½) *
haarScalarFactor (map (Β· * g) Ξ½) Ξ½ := rfl
_ = haarScalarFactor (map (Β· * (g * h)) Ξ½) Ξ½ := by simp only [map_map mul_h_meas mul_g_meas,
comp_mul_right, β haarScalarFactor_eq_mul]
/-- The modular character homomorphism. The underlying function is `modularCharacterFun`, which is
`g β¦ ΞΌ (Β· * gβ»ΒΉ) / ΞΌ`, where `ΞΌ` is a left Haar measure.
-/
noncomputable def modularCharacter : G β* ββ₯0 where
toFun := modularCharacterFun
map_one' := modularCharacterFun_map_one
map_mul' := modularCharacterFun_map_mul
end Measure
end MeasureTheory
|
PartialAdjoint.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.Adjunction.Basic
import Mathlib.CategoryTheory.Limits.HasLimits
import Mathlib.CategoryTheory.Yoneda
/-!
# Domain of definition of the partial left adjoint
Given a functor `F : D β₯€ C`, we define a functor
`F.partialLeftAdjoint : F.PartialLeftAdjointSource β₯€ D` which is
defined on the full subcategory of `C` consisting of those objects `X : C`
such that `F β coyoneda.obj (op X) : D β₯€ Type _` is corepresentable.
We have a natural bijection
`(F.partialLeftAdjoint.obj X βΆ Y) β (X.obj βΆ F.obj Y)`
that is similar to what we would expect for the image of the object `X`
by the left adjoint of `F`, if such an adjoint existed.
Indeed, if the predicate `F.LeftAdjointObjIsDefined` which defines
the `F.PartialLeftAdjointSource` holds for all
objects `X : C`, then `F` has a left adjoint.
When colimits indexed by a category `J` exist in `D`, we show that
the predicate `F.LeftAdjointObjIsDefined` is stable under colimits indexed by `J`.
## TODO
* consider dualizing the results to right adjoints
-/
universe vβ vβ uβ uβ
namespace CategoryTheory
namespace Functor
open Category Opposite Limits
section partialLeftAdjoint
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D] (F : D β₯€ C)
/-- Given a functor `F : D β₯€ C`, this is a predicate on objects `X : C` corresponding
to the domain of definition of the (partial) left adjoint of `F`. -/
def leftAdjointObjIsDefined : ObjectProperty C :=
fun X β¦ IsCorepresentable (F β coyoneda.obj (op X))
@[deprecated (since := "2025-03-05")] alias LeftAdjointObjIsDefined := leftAdjointObjIsDefined
lemma leftAdjointObjIsDefined_iff (X : C) :
F.leftAdjointObjIsDefined X β IsCorepresentable (F β coyoneda.obj (op X)) := by rfl
variable {F} in
lemma leftAdjointObjIsDefined_of_adjunction {G : C β₯€ D} (adj : G β£ F) (X : C) :
F.leftAdjointObjIsDefined X :=
(adj.corepresentableBy X).isCorepresentable
/-- The full subcategory where `F.partialLeftAdjoint` shall be defined. -/
abbrev PartialLeftAdjointSource := F.leftAdjointObjIsDefined.FullSubcategory
instance (X : F.PartialLeftAdjointSource) :
IsCorepresentable (F β coyoneda.obj (op X.obj)) := X.property
/-- Given `F : D β₯€ C`, this is `F.partialLeftAdjoint` on objects: it sends
`X : C` such that `F.leftAdjointObjIsDefined X` holds to an object of `D`
which represents the functor `F β coyoneda.obj (op X.obj)`. -/
noncomputable def partialLeftAdjointObj (X : F.PartialLeftAdjointSource) : D :=
(F β coyoneda.obj (op X.obj)).coreprX
/-- Given `F : D β₯€ C`, this is the canonical bijection
`(F.partialLeftAdjointObj X βΆ Y) β (X.obj βΆ F.obj Y)`
for all `X : F.PartialLeftAdjointSource` and `Y : D`. -/
noncomputable def partialLeftAdjointHomEquiv {X : F.PartialLeftAdjointSource} {Y : D} :
(F.partialLeftAdjointObj X βΆ Y) β (X.obj βΆ F.obj Y) :=
(F β coyoneda.obj (op X.obj)).corepresentableBy.homEquiv
lemma partialLeftAdjointHomEquiv_comp {X : F.PartialLeftAdjointSource} {Y Y' : D}
(f : F.partialLeftAdjointObj X βΆ Y) (g : Y βΆ Y') :
F.partialLeftAdjointHomEquiv (f β« g) =
F.partialLeftAdjointHomEquiv f β« F.map g := by
apply CorepresentableBy.homEquiv_comp
/-- Given `F : D β₯€ C`, this is `F.partialLeftAdjoint` on morphisms. -/
noncomputable def partialLeftAdjointMap {X Y : F.PartialLeftAdjointSource}
(f : X βΆ Y) : F.partialLeftAdjointObj X βΆ F.partialLeftAdjointObj Y :=
F.partialLeftAdjointHomEquiv.symm (f β« F.partialLeftAdjointHomEquiv (π _))
@[simp]
lemma partialLeftAdjointHomEquiv_map {X Y : F.PartialLeftAdjointSource}
(f : X βΆ Y) :
F.partialLeftAdjointHomEquiv (F.partialLeftAdjointMap f) =
by exact f β« F.partialLeftAdjointHomEquiv (π _) := by
simp [partialLeftAdjointMap]
lemma partialLeftAdjointHomEquiv_map_comp {X X' : F.PartialLeftAdjointSource} {Y : D}
(f : X βΆ X') (g : F.partialLeftAdjointObj X' βΆ Y) :
F.partialLeftAdjointHomEquiv (F.partialLeftAdjointMap f β« g) =
by exact f β« F.partialLeftAdjointHomEquiv g := by
rw [partialLeftAdjointHomEquiv_comp, partialLeftAdjointHomEquiv_map, assoc,
β partialLeftAdjointHomEquiv_comp, id_comp]
/-- Given `F : D β₯€ C`, this is the partial adjoint functor `F.PartialLeftAdjointSource β₯€ D`. -/
@[simps]
noncomputable def partialLeftAdjoint : F.PartialLeftAdjointSource β₯€ D where
obj := F.partialLeftAdjointObj
map := F.partialLeftAdjointMap
map_id X := by
apply F.partialLeftAdjointHomEquiv.injective
dsimp
rw [partialLeftAdjointHomEquiv_map]
erw [id_comp]
map_comp {X Y Z} f g := by
apply F.partialLeftAdjointHomEquiv.injective
dsimp
rw [partialLeftAdjointHomEquiv_map, partialLeftAdjointHomEquiv_comp,
partialLeftAdjointHomEquiv_map, assoc]
erw [assoc]
rw [β F.partialLeftAdjointHomEquiv_comp, id_comp,
partialLeftAdjointHomEquiv_map]
variable {F}
lemma isRightAdjoint_of_leftAdjointObjIsDefined_eq_top
(h : F.leftAdjointObjIsDefined = β€) : F.IsRightAdjoint := by
replace h : β X, IsCorepresentable (F β coyoneda.obj (op X)) := fun X β¦ by
simp only [β leftAdjointObjIsDefined_iff, h, Pi.top_apply, Prop.top_eq_true]
exact (Adjunction.adjunctionOfEquivLeft
(fun X Y β¦ (F β coyoneda.obj (op X)).corepresentableBy.homEquiv)
(fun X Y Y' g f β¦ by apply CorepresentableBy.homEquiv_comp)).isRightAdjoint
variable (F) in
lemma isRightAdjoint_iff_leftAdjointObjIsDefined_eq_top :
F.IsRightAdjoint β F.leftAdjointObjIsDefined = β€ := by
refine β¨fun h β¦ ?_, isRightAdjoint_of_leftAdjointObjIsDefined_eq_topβ©
ext X
simpa only [Pi.top_apply, Prop.top_eq_true, iff_true]
using leftAdjointObjIsDefined_of_adjunction (Adjunction.ofIsRightAdjoint F) X
/-- Auxiliary definition for `leftAdjointObjIsDefined_of_isColimit`. -/
noncomputable def corepresentableByCompCoyonedaObjOfIsColimit {J : Type*} [Category J]
{R : J β₯€ F.PartialLeftAdjointSource}
{c : Cocone (R β ObjectProperty.ΞΉ _)} (hc : IsColimit c)
{c' : Cocone (R β F.partialLeftAdjoint)} (hc' : IsColimit c') :
(F β coyoneda.obj (op c.pt)).CorepresentableBy c'.pt where
homEquiv {Y} :=
{ toFun := fun f β¦ hc.desc (Cocone.mk _
{ app := fun j β¦ F.partialLeftAdjointHomEquiv (c'.ΞΉ.app j β« f)
naturality := fun j j' Ο β¦ by
dsimp
rw [comp_id, β c'.w Ο, β partialLeftAdjointHomEquiv_map_comp, assoc]
dsimp })
invFun := fun g β¦ hc'.desc (Cocone.mk _
{ app := fun j β¦ F.partialLeftAdjointHomEquiv.symm (c.ΞΉ.app j β« g)
naturality := fun j j' Ο β¦ by
apply F.partialLeftAdjointHomEquiv.injective
have := c.w Ο
dsimp at this β’
rw [comp_id, Equiv.apply_symm_apply, partialLeftAdjointHomEquiv_map_comp,
Equiv.apply_symm_apply, reassoc_of% this] })
left_inv := fun f β¦ hc'.hom_ext (fun j β¦ by simp)
right_inv := fun g β¦ hc.hom_ext (fun j β¦ by simp) }
homEquiv_comp {Y Y'} g f := hc.hom_ext (fun j β¦ by
dsimp
simp only [IsColimit.fac, IsColimit.fac_assoc, partialLeftAdjointHomEquiv_comp,
F.map_comp, assoc] )
lemma leftAdjointObjIsDefined_of_isColimit {J : Type*} [Category J] {R : J β₯€ C} {c : Cocone R}
(hc : IsColimit c) [HasColimitsOfShape J D]
(h : β (j : J), F.leftAdjointObjIsDefined (R.obj j)) :
F.leftAdjointObjIsDefined c.pt :=
(corepresentableByCompCoyonedaObjOfIsColimit
(R := ObjectProperty.lift _ R h) hc (colimit.isColimit _)).isCorepresentable
lemma leftAdjointObjIsDefined_colimit {J : Type*} [Category J] (R : J β₯€ C)
[HasColimit R] [HasColimitsOfShape J D]
(h : β (j : J), F.leftAdjointObjIsDefined (R.obj j)) :
F.leftAdjointObjIsDefined (colimit R) :=
leftAdjointObjIsDefined_of_isColimit (colimit.isColimit R) h
end partialLeftAdjoint
section partialRightAdjoint
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D] (F : C β₯€ D)
/-- Given a functor `F : C β₯€ D`, this is a predicate on objects `X : D` corresponding
to the domain of definition of the (partial) right adjoint of `F`. -/
def rightAdjointObjIsDefined : ObjectProperty D :=
fun Y β¦ IsRepresentable (F.op β yoneda.obj Y)
lemma rightAdjointObjIsDefined_iff (Y : D) :
F.rightAdjointObjIsDefined Y β IsRepresentable (F.op β yoneda.obj Y) := by rfl
variable {F} in
lemma rightAdjointObjIsDefined_of_adjunction {G : D β₯€ C} (adj : F β£ G) (Y : D) :
F.rightAdjointObjIsDefined Y :=
(adj.representableBy Y).isRepresentable
/-- The full subcategory where `F.partialRightAdjoint` shall be defined. -/
abbrev PartialRightAdjointSource := F.rightAdjointObjIsDefined.FullSubcategory
instance (Y : F.PartialRightAdjointSource) :
IsRepresentable (F.op β yoneda.obj Y.obj) := Y.property
/-- Given `F : C β₯€ D`, this is `F.partialRightAdjoint` on objects: it sends
`X : D` such that `F.rightAdjointObjIsDefined X` holds to an object of `C`
which represents the functor `F β coyoneda.obj (op X.obj)`. -/
noncomputable def partialRightAdjointObj (Y : F.PartialRightAdjointSource) : C :=
(F.op β yoneda.obj Y.obj).reprX
/-- Given `F : C β₯€ D`, this is the canonical bijection
`(X βΆ F.partialRightAdjointObj Y) β (F.obj X βΆ Y.obj)`
for all `X : C` and `Y : F.PartialRightAdjointSource`. -/
noncomputable def partialRightAdjointHomEquiv {X : C} {Y : F.PartialRightAdjointSource} :
(X βΆ F.partialRightAdjointObj Y) β (F.obj X βΆ Y.obj) :=
(F.op β yoneda.obj Y.obj).representableBy.homEquiv
lemma partialRightAdjointHomEquiv_comp {X X' : C} {Y : F.PartialRightAdjointSource}
(f : X' βΆ F.partialRightAdjointObj Y) (g : X βΆ X') :
F.partialRightAdjointHomEquiv (g β« f) =
F.map g β« F.partialRightAdjointHomEquiv f :=
RepresentableBy.homEquiv_comp ..
/-- Given `F : C β₯€ D`, this is `F.partialRightAdjoint` on morphisms. -/
noncomputable def partialRightAdjointMap {X Y : F.PartialRightAdjointSource}
(f : X βΆ Y) : F.partialRightAdjointObj X βΆ F.partialRightAdjointObj Y :=
F.partialRightAdjointHomEquiv.symm (F.partialRightAdjointHomEquiv (π _) β« f)
@[simp]
lemma partialRightAdjointHomEquiv_map {X Y : F.PartialRightAdjointSource}
(f : X βΆ Y) :
F.partialRightAdjointHomEquiv (F.partialRightAdjointMap f) =
F.partialRightAdjointHomEquiv (π _) β« f := by
simp [partialRightAdjointMap]
lemma partialRightAdjointHomEquiv_map_comp {X : C} {Y Y' : F.PartialRightAdjointSource}
(f : X βΆ F.partialRightAdjointObj Y) (g : Y βΆ Y') :
F.partialRightAdjointHomEquiv (f β« F.partialRightAdjointMap g) =
F.partialRightAdjointHomEquiv f β« g := by
rw [partialRightAdjointHomEquiv_comp, partialRightAdjointHomEquiv_map,
β assoc, β partialRightAdjointHomEquiv_comp, comp_id]
/-- Given `F : C β₯€ D`, this is the partial adjoint functor `F.PartialLeftAdjointSource β₯€ C`. -/
@[simps]
noncomputable def partialRightAdjoint : F.PartialRightAdjointSource β₯€ C where
obj := F.partialRightAdjointObj
map := F.partialRightAdjointMap
map_id X := by
apply F.partialRightAdjointHomEquiv.injective
dsimp
rw [partialRightAdjointHomEquiv_map]
erw [comp_id]
map_comp {X Y Z} f g := by
apply F.partialRightAdjointHomEquiv.injective
dsimp
rw [partialRightAdjointHomEquiv_map, partialRightAdjointHomEquiv_comp,
partialRightAdjointHomEquiv_map, β assoc]
erw [β assoc]
rw [β F.partialRightAdjointHomEquiv_comp, comp_id,
partialRightAdjointHomEquiv_map]
variable {F}
lemma isLeftAdjoint_of_rightAdjointObjIsDefined_eq_top
(h : F.rightAdjointObjIsDefined = β€) : F.IsLeftAdjoint := by
replace h : β X, IsRepresentable (F.op β yoneda.obj X) := fun X β¦ by
simp only [β rightAdjointObjIsDefined_iff, h, Pi.top_apply, Prop.top_eq_true]
exact (Adjunction.adjunctionOfEquivRight
(fun X Y β¦ (F.op β yoneda.obj Y).representableBy.homEquiv.symm)
(fun X Y Y' g f β¦ (RepresentableBy.comp_homEquiv_symm ..).symm)).isLeftAdjoint
variable (F) in
lemma isLeftAdjoint_iff_rightAdjointObjIsDefined_eq_top :
F.IsLeftAdjoint β F.rightAdjointObjIsDefined = β€ := by
refine β¨fun h β¦ ?_, isLeftAdjoint_of_rightAdjointObjIsDefined_eq_topβ©
ext X
simpa only [Pi.top_apply, Prop.top_eq_true, iff_true]
using rightAdjointObjIsDefined_of_adjunction (Adjunction.ofIsLeftAdjoint F) X
/-- Auxiliary definition for `rightAdjointObjIsDefined_of_isLimit`. -/
noncomputable def representableByCompYonedaObjOfIsLimit {J : Type*} [Category J]
{R : J β₯€ F.PartialRightAdjointSource}
{c : Cone (R β ObjectProperty.ΞΉ _)} (hc : IsLimit c)
{c' : Cone (R β F.partialRightAdjoint)} (hc' : IsLimit c') :
(F.op β yoneda.obj c.pt).RepresentableBy c'.pt where
homEquiv {Y} :=
{ toFun := fun f β¦ hc.lift (Cone.mk _
{ app := fun j β¦ F.partialRightAdjointHomEquiv (f β« c'.Ο.app j)
naturality := fun j j' Ο β¦ by
dsimp
rw [id_comp, β c'.w Ο, β partialRightAdjointHomEquiv_map_comp,
β assoc]
dsimp })
invFun := fun g β¦ hc'.lift (Cone.mk _
{ app := fun j β¦ F.partialRightAdjointHomEquiv.symm (g β« c.Ο.app j)
naturality := fun j j' Ο β¦ by
apply F.partialRightAdjointHomEquiv.injective
have := c.w Ο
dsimp at this β’
rw [id_comp, Equiv.apply_symm_apply, partialRightAdjointHomEquiv_map_comp,
Equiv.apply_symm_apply, assoc, this] })
left_inv := fun f β¦ hc'.hom_ext (fun j β¦ by simp)
right_inv := fun g β¦ hc.hom_ext (fun j β¦ by simp) }
homEquiv_comp {Y Y'} g f := hc.hom_ext (fun j β¦ by
dsimp
simp only [IsLimit.fac, partialRightAdjointHomEquiv_comp, assoc] )
lemma rightAdjointObjIsDefined_of_isLimit {J : Type*} [Category J] {R : J β₯€ D} {c : Cone R}
(hc : IsLimit c) [HasLimitsOfShape J C]
(h : β (j : J), F.rightAdjointObjIsDefined (R.obj j)) :
F.rightAdjointObjIsDefined c.pt :=
(representableByCompYonedaObjOfIsLimit
(R := ObjectProperty.lift _ R h) hc (limit.isLimit _)).isRepresentable
lemma rightAdjointObjIsDefined_limit {J : Type*} [Category J] (R : J β₯€ D)
[HasLimit R] [HasLimitsOfShape J C]
(h : β (j : J), F.rightAdjointObjIsDefined (R.obj j)) :
F.rightAdjointObjIsDefined (limit R) :=
rightAdjointObjIsDefined_of_isLimit (limit.isLimit R) h
end partialRightAdjoint
end Functor
end CategoryTheory
|
Open.lean
|
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.AlgebraicGeometry.Cover.MorphismProperty
/-!
# Open covers of schemes
This file provides the basic API for open covers of schemes.
## Main definition
- `AlgebraicGeometry.Scheme.OpenCover`: The type of open covers of a scheme `X`,
consisting of a family of open immersions into `X`,
and for each `x : X` an open immersion (indexed by `f x`) that covers `x`.
- `AlgebraicGeometry.Scheme.affineCover`: `X.affineCover` is a choice of an affine cover of `X`.
- `AlgebraicGeometry.Scheme.AffineOpenCover`: The type of affine open covers of a scheme `X`.
-/
noncomputable section
open TopologicalSpace CategoryTheory Opposite CategoryTheory.Limits
universe v vβ vβ u
namespace AlgebraicGeometry
namespace Scheme
/-- An open cover of a scheme `X` is a cover where all component maps are open immersions. -/
abbrev OpenCover (X : Scheme.{u}) : Type _ := Cover.{v} @IsOpenImmersion X
variable {X Y Z : Scheme.{u}} (π° : OpenCover X) (f : X βΆ Z) (g : Y βΆ Z)
variable [β x, HasPullback (π°.map x β« f) g]
instance (i : π°.J) : IsOpenImmersion (π°.map i) := π°.map_prop i
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme.{u}) : OpenCover X where
J := X
obj x := Spec (X.local_affine x).choose_spec.choose
map x :=
β¨(X.local_affine x).choose_spec.choose_spec.some.inv β« X.toLocallyRingedSpace.ofRestrict _β©
f x := x
covers := by
intro x
simp only [LocallyRingedSpace.comp_toShHom, SheafedSpace.comp_base, TopCat.hom_comp,
ContinuousMap.coe_comp]
rw [Set.range_comp, Set.range_eq_univ.mpr, Set.image_univ]
Β· erw [Subtype.range_coe_subtype]
exact (X.local_affine x).choose.2
rw [β TopCat.epi_iff_surjective]
change Epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forgetToSheafedSpace.map _))
infer_instance
instance : Inhabited X.OpenCover :=
β¨X.affineCoverβ©
theorem OpenCover.iSup_opensRange {X : Scheme.{u}} (π° : X.OpenCover) :
β¨ i, (π°.map i).opensRange = β€ :=
Opens.ext <| by rw [Opens.coe_iSup]; exact π°.iUnion_range
/-- The ranges of the maps in a scheme-theoretic open cover are a topological open cover. -/
lemma OpenCover.isOpenCover_opensRange {X : Scheme.{u}} (π° : X.OpenCover) :
IsOpenCover fun i β¦ (π°.map i).opensRange :=
.mk π°.iSup_opensRange
/-- Every open cover of a quasi-compact scheme can be refined into a finite subcover.
-/
@[simps! obj map]
def OpenCover.finiteSubcover {X : Scheme.{u}} (π° : OpenCover X) [H : CompactSpace X] :
OpenCover X := by
have :=
@CompactSpace.elim_nhds_subcover _ _ H (fun x : X => Set.range (π°.map (π°.f x)).base)
fun x => (IsOpenImmersion.isOpen_range (π°.map (π°.f x))).mem_nhds (π°.covers x)
let t := this.choose
have h : β x : X, β y : t, x β Set.range (π°.map (π°.f y)).base := by
intro x
have h' : x β (β€ : Set X) := trivial
rw [β Classical.choose_spec this, Set.mem_iUnion] at h'
rcases h' with β¨y, _, β¨hy, rflβ©, hy'β©
exact β¨β¨y, hyβ©, hy'β©
exact
{ J := t
obj := fun x => π°.obj (π°.f x.1)
map := fun x => π°.map (π°.f x.1)
f := fun x => (h x).choose
covers := fun x => (h x).choose_spec }
instance [H : CompactSpace X] : Fintype π°.finiteSubcover.J := by
delta OpenCover.finiteSubcover; infer_instance
theorem OpenCover.compactSpace {X : Scheme.{u}} (π° : X.OpenCover) [Finite π°.J]
[H : β i, CompactSpace (π°.obj i)] : CompactSpace X := by
cases nonempty_fintype π°.J
rw [β isCompact_univ_iff, β π°.iUnion_range]
apply isCompact_iUnion
intro i
rw [isCompact_iff_compactSpace]
exact
@Homeomorph.compactSpace _ _ _ _ (H i)
(TopCat.homeoOfIso
(asIso
(IsOpenImmersion.isoOfRangeEq (π°.map i)
(X.ofRestrict (Opens.isOpenEmbedding β¨_, (π°.map_prop i).base_open.isOpen_rangeβ©))
Subtype.range_coe.symm).hom.base))
/--
An affine open cover of `X` consists of a family of open immersions into `X` from
spectra of rings.
-/
abbrev AffineOpenCover (X : Scheme.{u}) : Type _ :=
AffineCover.{v} @IsOpenImmersion X
namespace AffineOpenCover
instance {X : Scheme.{u}} (π° : X.AffineOpenCover) (j : π°.J) : IsOpenImmersion (π°.map j) :=
π°.map_prop j
/-- The open cover associated to an affine open cover. -/
@[simps! J obj map f]
def openCover {X : Scheme.{u}} (π° : X.AffineOpenCover) : X.OpenCover :=
AffineCover.cover π°
end AffineOpenCover
/-- A choice of an affine open cover of a scheme. -/
@[simps]
def affineOpenCover (X : Scheme.{u}) : X.AffineOpenCover where
obj := _
J := X.affineCover.J
map := X.affineCover.map
f := X.affineCover.f
covers := X.affineCover.covers
@[simp]
lemma openCover_affineOpenCover (X : Scheme.{u}) : X.affineOpenCover.openCover = X.affineCover :=
rfl
/-- Given any open cover `π€`, this is an affine open cover which refines it.
The morphism in the category of open covers which proves that this is indeed a refinement, see
`AlgebraicGeometry.Scheme.OpenCover.fromAffineRefinement`.
-/
def OpenCover.affineRefinement {X : Scheme.{u}} (π€ : X.OpenCover) : X.AffineOpenCover where
obj := _
J := (π€.bind fun j => (π€.obj j).affineCover).J
map := (π€.bind fun j => (π€.obj j).affineCover).map
f := (π€.bind fun j => (π€.obj j).affineCover).f
covers := (π€.bind fun j => (π€.obj j).affineCover).covers
/-- The pullback of the affine refinement is the pullback of the affine cover. -/
def OpenCover.pullbackCoverAffineRefinementObjIso (f : X βΆ Y) (π° : Y.OpenCover) (i) :
(π°.affineRefinement.openCover.pullbackCover f).obj i β
((π°.obj i.1).affineCover.pullbackCover (π°.pullbackHom f i.1)).obj i.2 :=
pullbackSymmetry _ _ βͺβ« (pullbackRightPullbackFstIso _ _ _).symm βͺβ«
pullbackSymmetry _ _ βͺβ« asIso (pullback.map _ _ _ _ (pullbackSymmetry _ _).hom (π _) (π _)
(by simp [Cover.pullbackHom]) (by simp))
@[reassoc]
lemma OpenCover.pullbackCoverAffineRefinementObjIso_inv_map (f : X βΆ Y) (π° : Y.OpenCover) (i) :
(π°.pullbackCoverAffineRefinementObjIso f i).inv β«
(π°.affineRefinement.openCover.pullbackCover f).map i =
((π°.obj i.1).affineCover.pullbackCover (π°.pullbackHom f i.1)).map i.2 β«
(π°.pullbackCover f).map i.1 := by
simp only [Cover.pullbackCover_obj,
pullbackCoverAffineRefinementObjIso, Iso.trans_inv, asIso_inv, Iso.symm_inv, Category.assoc,
Cover.pullbackCover_map, pullbackSymmetry_inv_comp_fst, IsIso.inv_comp_eq, limit.lift_Ο_assoc,
PullbackCone.mk_pt, cospan_left, PullbackCone.mk_Ο_app, pullbackSymmetry_hom_comp_fst]
convert pullbackSymmetry_inv_comp_snd_assoc
((π°.obj i.1).affineCover.map i.2) (pullback.fst _ _) _ using 2
exact pullbackRightPullbackFstIso_hom_snd _ _ _
@[reassoc]
lemma OpenCover.pullbackCoverAffineRefinementObjIso_inv_pullbackHom
(f : X βΆ Y) (π° : Y.OpenCover) (i) :
(π°.pullbackCoverAffineRefinementObjIso f i).inv β«
π°.affineRefinement.openCover.pullbackHom f i =
(π°.obj i.1).affineCover.pullbackHom (π°.pullbackHom f i.1) i.2 := by
simp only [Cover.pullbackCover_obj, Cover.pullbackHom,
AffineOpenCover.openCover_map, pullbackCoverAffineRefinementObjIso, Iso.trans_inv, asIso_inv,
Iso.symm_inv, Category.assoc, pullbackSymmetry_inv_comp_snd, IsIso.inv_comp_eq, limit.lift_Ο,
PullbackCone.mk_pt, PullbackCone.mk_Ο_app, Category.comp_id]
convert pullbackSymmetry_inv_comp_fst ((π°.obj i.1).affineCover.map i.2) (pullback.fst _ _)
exact pullbackRightPullbackFstIso_hom_fst _ _ _
/-- A family of elements spanning the unit ideal of `R` gives a affine open cover of `Spec R`. -/
@[simps]
noncomputable
def affineOpenCoverOfSpanRangeEqTop {R : CommRingCat} {ΞΉ : Type*} (s : ΞΉ β R)
(hs : Ideal.span (Set.range s) = β€) : (Spec R).AffineOpenCover where
J := ΞΉ
obj i := .of (Localization.Away (s i))
map i := Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away (s i))))
f x := by
have : β i, s i β x.asIdeal := by
by_contra! h; apply x.2.ne_top; rwa [β top_le_iff, β hs, Ideal.span_le, Set.range_subset_iff]
exact this.choose
covers x := by
generalize_proofs H
let i := H.choose
have := PrimeSpectrum.localization_away_comap_range (Localization.Away (s i)) (s i)
exact (eq_iff_iff.mp congr(x β $this)).mpr H.choose_spec
/-- Given any open cover `π€`, this is an affine open cover which refines it. -/
def OpenCover.fromAffineRefinement {X : Scheme.{u}} (π€ : X.OpenCover) :
π€.affineRefinement.openCover βΆ π€ where
idx j := j.fst
app j := (π€.obj j.fst).affineCover.map _
/-- If two global sections agree after restriction to each member of an open cover, then
they agree globally. -/
lemma OpenCover.ext_elem {X : Scheme.{u}} {U : X.Opens} (f g : Ξ(X, U)) (π° : X.OpenCover)
(h : β i : π°.J, (π°.map i).app U f = (π°.map i).app U g) : f = g := by
fapply TopCat.Sheaf.eq_of_locally_eq' X.sheaf
(fun i β¦ (π°.map (π°.f i)).opensRange β U) _ (fun _ β¦ homOfLE inf_le_right)
Β· intro x hx
simp only [Opens.iSup_mk, Opens.carrier_eq_coe, Opens.coe_inf, Hom.coe_opensRange, Opens.coe_mk,
Set.mem_iUnion, Set.mem_inter_iff, Set.mem_range, SetLike.mem_coe, exists_and_right]
refine β¨?_, hxβ©
simpa using β¨_, π°.covers xβ©
Β· intro x
replace h := h (π°.f x)
rw [β IsOpenImmersion.map_ΞIso_inv] at h
exact (IsOpenImmersion.ΞIso (π°.map (π°.f x)) U).commRingCatIsoToRingEquiv.symm.injective h
/-- If the restriction of a global section to each member of an open cover is zero, then it is
globally zero. -/
lemma zero_of_zero_cover {X : Scheme.{u}} {U : X.Opens} (s : Ξ(X, U)) (π° : X.OpenCover)
(h : β i : π°.J, (π°.map i).app U s = 0) : s = 0 :=
π°.ext_elem s 0 (fun i β¦ by rw [map_zero]; exact h i)
/-- If a global section is nilpotent on each member of a finite open cover, then `f` is
nilpotent. -/
lemma isNilpotent_of_isNilpotent_cover {X : Scheme.{u}} {U : X.Opens} (s : Ξ(X, U))
(π° : X.OpenCover) [Finite π°.J] (h : β i : π°.J, IsNilpotent ((π°.map i).app U s)) :
IsNilpotent s := by
choose fn hfn using h
have : Fintype π°.J := Fintype.ofFinite π°.J
/- the maximum of all `fn i` (exists, because `π°.J` is finite) -/
let N : β := Finset.sup Finset.univ fn
have hfnleN (i : π°.J) : fn i β€ N := Finset.le_sup (Finset.mem_univ i)
use N
apply zero_of_zero_cover (π° := π°)
on_goal 1 => intro i; simp only [map_pow]
-- This closes both remaining goals at once.
exact pow_eq_zero_of_le (hfnleN i) (hfn i)
section deprecated
/-- The basic open sets form an affine open cover of `Spec R`. -/
def affineBasisCoverOfAffine (R : CommRingCat.{u}) : OpenCover (Spec R) where
J := R
obj r := Spec(Localization.Away r)
map r := Spec.map (CommRingCat.ofHom (algebraMap R (Localization.Away r)))
f _ := 1
covers r := by
rw [Set.range_eq_univ.mpr ((TopCat.epi_iff_surjective _).mp _)]
Β· exact trivial
Β· infer_instance
map_prop x := AlgebraicGeometry.Scheme.basic_open_isOpenImmersion x
/-- We may bind the basic open sets of an open affine cover to form an affine cover that is also
a basis. -/
def affineBasisCover (X : Scheme.{u}) : OpenCover X :=
X.affineCover.bind fun _ => affineBasisCoverOfAffine _
/-- The coordinate ring of a component in the `affine_basis_cover`. -/
def affineBasisCoverRing (X : Scheme.{u}) (i : X.affineBasisCover.J) : CommRingCat :=
CommRingCat.of <| @Localization.Away (X.local_affine i.1).choose_spec.choose _ i.2
theorem affineBasisCover_obj (X : Scheme.{u}) (i : X.affineBasisCover.J) :
X.affineBasisCover.obj i = Spec (X.affineBasisCoverRing i) :=
rfl
theorem affineBasisCover_map_range (X : Scheme.{u}) (x : X)
(r : (X.local_affine x).choose_spec.choose) :
Set.range (X.affineBasisCover.map β¨x, rβ©).base =
(X.affineCover.map x).base '' (PrimeSpectrum.basicOpen r).1 := by
simp only [affineBasisCover, Cover.bind_map, comp_coeBase, TopCat.hom_comp,
ContinuousMap.coe_comp, Set.range_comp]
congr
exact (PrimeSpectrum.localization_away_comap_range (Localization.Away r) r :)
theorem affineBasisCover_is_basis (X : Scheme.{u}) :
TopologicalSpace.IsTopologicalBasis
{x : Set X |
β a : X.affineBasisCover.J, x = Set.range (X.affineBasisCover.map a).base} := by
apply TopologicalSpace.isTopologicalBasis_of_isOpen_of_nhds
Β· rintro _ β¨a, rflβ©
exact IsOpenImmersion.isOpen_range (X.affineBasisCover.map a)
Β· rintro a U haU hU
rcases X.affineCover.covers a with β¨x, eβ©
let U' := (X.affineCover.map (X.affineCover.f a)).base β»ΒΉ' U
have hxU' : x β U' := by rw [β e] at haU; exact haU
rcases PrimeSpectrum.isBasis_basic_opens.exists_subset_of_mem_open hxU'
((X.affineCover.map (X.affineCover.f a)).base.hom.continuous_toFun.isOpen_preimage _
hU) with
β¨_, β¨_, β¨s, rflβ©, rflβ©, hxV, hVUβ©
refine β¨_, β¨β¨_, sβ©, rflβ©, ?_, ?_β© <;> rw [affineBasisCover_map_range]
Β· exact β¨x, hxV, eβ©
Β· rw [Set.image_subset_iff]; exact hVU
end deprecated
end Scheme
end AlgebraicGeometry
|
Connected.lean
|
/-
Copyright (c) 2021 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Combinatorics.SimpleGraph.Connectivity.WalkDecomp
import Mathlib.Combinatorics.SimpleGraph.Paths
import Mathlib.Combinatorics.SimpleGraph.Subgraph
/-!
## Main definitions
* `SimpleGraph.Reachable` for the relation of whether there exists
a walk between a given pair of vertices
* `SimpleGraph.Preconnected` and `SimpleGraph.Connected` are predicates
on simple graphs for whether every vertex can be reached from every other,
and in the latter case, whether the vertex type is nonempty.
* `SimpleGraph.ConnectedComponent` is the type of connected components of
a given graph.
* `SimpleGraph.IsBridge` for whether an edge is a bridge edge
## Main statements
* `SimpleGraph.isBridge_iff_mem_and_forall_cycle_notMem` characterizes bridge edges in terms of
there being no cycle containing them.
## Tags
trails, paths, cycles, bridge edges
-/
open Function
universe u v w
namespace SimpleGraph
variable {V : Type u} {V' : Type v} {V'' : Type w}
variable (G : SimpleGraph V) (G' : SimpleGraph V') (G'' : SimpleGraph V'')
/-! ## `Reachable` and `Connected` -/
/-- Two vertices are *reachable* if there is a walk between them.
This is equivalent to `Relation.ReflTransGen` of `G.Adj`.
See `SimpleGraph.reachable_iff_reflTransGen`. -/
def Reachable (u v : V) : Prop := Nonempty (G.Walk u v)
variable {G}
theorem reachable_iff_nonempty_univ {u v : V} :
G.Reachable u v β (Set.univ : Set (G.Walk u v)).Nonempty :=
Set.nonempty_iff_univ_nonempty
lemma not_reachable_iff_isEmpty_walk {u v : V} : Β¬G.Reachable u v β IsEmpty (G.Walk u v) :=
not_nonempty_iff
protected theorem Reachable.elim {p : Prop} {u v : V} (h : G.Reachable u v)
(hp : G.Walk u v β p) : p :=
Nonempty.elim h hp
protected theorem Reachable.elim_path {p : Prop} {u v : V} (h : G.Reachable u v)
(hp : G.Path u v β p) : p := by classical exact h.elim fun q => hp q.toPath
protected theorem Walk.reachable {G : SimpleGraph V} {u v : V} (p : G.Walk u v) : G.Reachable u v :=
β¨pβ©
protected theorem Adj.reachable {u v : V} (h : G.Adj u v) : G.Reachable u v :=
h.toWalk.reachable
@[refl]
protected theorem Reachable.refl (u : V) : G.Reachable u u := β¨Walk.nilβ©
protected theorem Reachable.rfl {u : V} : G.Reachable u u := Reachable.refl _
@[symm]
protected theorem Reachable.symm {u v : V} (huv : G.Reachable u v) : G.Reachable v u :=
huv.elim fun p => β¨p.reverseβ©
theorem reachable_comm {u v : V} : G.Reachable u v β G.Reachable v u :=
β¨Reachable.symm, Reachable.symmβ©
@[trans]
protected theorem Reachable.trans {u v w : V} (huv : G.Reachable u v) (hvw : G.Reachable v w) :
G.Reachable u w :=
huv.elim fun puv => hvw.elim fun pvw => β¨puv.append pvwβ©
theorem reachable_iff_reflTransGen (u v : V) :
G.Reachable u v β Relation.ReflTransGen G.Adj u v := by
constructor
Β· rintro β¨hβ©
induction h with
| nil => rfl
| cons h' _ ih => exact (Relation.ReflTransGen.single h').trans ih
Β· intro h
induction h with
| refl => rfl
| tail _ ha hr => exact Reachable.trans hr β¨Walk.cons ha Walk.nilβ©
protected theorem Reachable.map {u v : V} {G : SimpleGraph V} {G' : SimpleGraph V'} (f : G βg G')
(h : G.Reachable u v) : G'.Reachable (f u) (f v) :=
h.elim fun p => β¨p.map fβ©
@[mono]
protected lemma Reachable.mono {u v : V} {G G' : SimpleGraph V}
(h : G β€ G') (Guv : G.Reachable u v) : G'.Reachable u v := Guv.map (.ofLE h)
theorem Reachable.exists_isPath {u v} (hr : G.Reachable u v) : β p : G.Walk u v, p.IsPath := by
classical
obtain β¨Wβ© := hr
exact β¨_, Path.isPath W.toPathβ©
theorem Iso.reachable_iff {G : SimpleGraph V} {G' : SimpleGraph V'} {Ο : G βg G'} {u v : V} :
G'.Reachable (Ο u) (Ο v) β G.Reachable u v :=
β¨fun r => Ο.left_inv u βΈ Ο.left_inv v βΈ r.map Ο.symm.toHom, Reachable.map Ο.toHomβ©
theorem Iso.symm_apply_reachable {G : SimpleGraph V} {G' : SimpleGraph V'} {Ο : G βg G'} {u : V}
{v : V'} : G.Reachable (Ο.symm v) u β G'.Reachable v (Ο u) := by
rw [β Iso.reachable_iff, RelIso.apply_symm_apply]
lemma Reachable.mem_subgraphVerts {u v} {H : G.Subgraph} (hr : G.Reachable u v)
(h : β v β H.verts, β w, G.Adj v w β H.Adj v w)
(hu : u β H.verts) : v β H.verts := by
let rec aux {v' : V} (hv' : v' β H.verts) (p : G.Walk v' v) : v β H.verts := by
by_cases hnp : p.Nil
Β· exact hnp.eq βΈ hv'
exact aux (H.edge_vert (h _ hv' _ (Walk.adj_snd hnp)).symm) p.tail
termination_by p.length
decreasing_by {
rw [β Walk.length_tail_add_one hnp]
omega
}
exact aux hu hr.some
variable (G)
theorem reachable_is_equivalence : Equivalence G.Reachable :=
Equivalence.mk (@Reachable.refl _ G) (@Reachable.symm _ G) (@Reachable.trans _ G)
/-- Distinct vertices are not reachable in the empty graph. -/
@[simp]
lemma reachable_bot {u v : V} : (β₯ : SimpleGraph V).Reachable u v β u = v :=
β¨fun h β¦ h.elim fun p β¦ match p with | .nil => rfl, fun h β¦ h βΈ .rflβ©
/-- The equivalence relation on vertices given by `SimpleGraph.Reachable`. -/
def reachableSetoid : Setoid V := Setoid.mk _ G.reachable_is_equivalence
/-- A graph is preconnected if every pair of vertices is reachable from one another. -/
def Preconnected : Prop := β u v : V, G.Reachable u v
theorem Preconnected.map {G : SimpleGraph V} {H : SimpleGraph V'} (f : G βg H) (hf : Surjective f)
(hG : G.Preconnected) : H.Preconnected :=
hf.forallβ.2 fun _ _ => Nonempty.map (Walk.map _) <| hG _ _
@[mono]
protected lemma Preconnected.mono {G G' : SimpleGraph V} (h : G β€ G') (hG : G.Preconnected) :
G'.Preconnected := fun u v => (hG u v).mono h
lemma bot_preconnected_iff_subsingleton : (β₯ : SimpleGraph V).Preconnected β Subsingleton V := by
refine β¨fun h β¦ ?_, fun h β¦ by simpa [subsingleton_iff, β reachable_bot] using hβ©
contrapose h
simp [nontrivial_iff.mp <| not_subsingleton_iff_nontrivial.mp h, Preconnected, reachable_bot]
lemma bot_preconnected [Subsingleton V] : (β₯ : SimpleGraph V).Preconnected :=
bot_preconnected_iff_subsingleton.mpr βΉ_βΊ
lemma bot_not_preconnected [Nontrivial V] : Β¬(β₯ : SimpleGraph V).Preconnected :=
bot_preconnected_iff_subsingleton.not.mpr <| not_subsingleton_iff_nontrivial.mpr βΉ_βΊ
lemma top_preconnected : (β€ : SimpleGraph V).Preconnected := fun x y => by
if h : x = y then rw [h] else exact Adj.reachable h
theorem Iso.preconnected_iff {G : SimpleGraph V} {H : SimpleGraph V'} (e : G βg H) :
G.Preconnected β H.Preconnected :=
β¨Preconnected.map e.toHom e.toEquiv.surjective,
Preconnected.map e.symm.toHom e.symm.toEquiv.surjectiveβ©
lemma Preconnected.support_eq_univ [Nontrivial V] {G : SimpleGraph V}
(h : G.Preconnected) : G.support = Set.univ := by
simp only [Set.eq_univ_iff_forall]
intro v
obtain β¨w, hwβ© := exists_ne v
obtain β¨pβ© := h v w
cases p with
| nil => contradiction
| @cons _ w => exact β¨w, βΉ_βΊβ©
lemma adj_of_mem_walk_support {G : SimpleGraph V} {u v : V} (p : G.Walk u v) (hp : Β¬p.Nil) {x : V}
(hx : x β p.support) : β y β p.support, G.Adj x y := by
induction p with
| nil =>
exact (hp Walk.Nil.nil).elim
| @cons u v w h p ih =>
cases List.mem_cons.mp hx with
| inl hxu =>
rw [hxu]
exact β¨v, β¨((Walk.cons h p).mem_support_iff).mpr (Or.inr p.start_mem_support), hβ©β©
| inr hxp =>
cases Decidable.em p.Nil with
| inl hnil =>
rw [Walk.nil_iff_support_eq.mp hnil] at hxp
rw [show (x = v) by simp_all]
exact β¨u, β¨(Walk.cons h p).start_mem_support, G.adj_symm hβ©β©
| inr hnotnil =>
obtain β¨y, hyβ© := ih hnotnil hxp
refine β¨y, β¨?_, hy.rightβ©β©
rw [Walk.mem_support_iff]
simp only [Walk.support_cons, List.tail_cons]
exact Or.inr hy.left
lemma mem_support_of_mem_walk_support {G : SimpleGraph V} {u v : V} (p : G.Walk u v) (hp : Β¬p.Nil)
{w : V} (hw : w β p.support) : w β G.support := by
obtain β¨y, hyβ© := adj_of_mem_walk_support p hp hw
exact (mem_support G).mpr β¨y, hy.rightβ©
lemma mem_support_of_reachable {G : SimpleGraph V} {u v : V} (huv : u β v) (h : G.Reachable u v) :
u β G.support := by
let p : G.Walk u v := Classical.choice h
have hp : Β¬p.Nil := Walk.not_nil_of_ne huv
exact mem_support_of_mem_walk_support p hp p.start_mem_support
theorem Preconnected.exists_isPath {G : SimpleGraph V} (h : G.Preconnected) (u v : V) :
β p : G.Walk u v, p.IsPath :=
(h u v).exists_isPath
/-- A graph is connected if it's preconnected and contains at least one vertex.
This follows the convention observed by mathlib that something is connected iff it has
exactly one connected component.
There is a `CoeFun` instance so that `h u v` can be used instead of `h.Preconnected u v`. -/
@[mk_iff]
structure Connected : Prop where
protected preconnected : G.Preconnected
protected [nonempty : Nonempty V]
lemma connected_iff_exists_forall_reachable : G.Connected β β v, β w, G.Reachable v w := by
rw [connected_iff]
constructor
Β· rintro β¨hp, β¨vβ©β©
exact β¨v, fun w => hp v wβ©
Β· rintro β¨v, hβ©
exact β¨fun u w => (h u).symm.trans (h w), β¨vβ©β©
instance : CoeFun G.Connected fun _ => β u v : V, G.Reachable u v := β¨fun h => h.preconnectedβ©
theorem Connected.map {G : SimpleGraph V} {H : SimpleGraph V'} (f : G βg H) (hf : Surjective f)
(hG : G.Connected) : H.Connected :=
haveI := hG.nonempty.map f
β¨hG.preconnected.map f hfβ©
@[mono]
protected lemma Connected.mono {G G' : SimpleGraph V} (h : G β€ G')
(hG : G.Connected) : G'.Connected where
preconnected := hG.preconnected.mono h
nonempty := hG.nonempty
theorem Connected.exists_isPath {G : SimpleGraph V} (h : G.Connected) (u v : V) :
β p : G.Walk u v, p.IsPath :=
(h u v).exists_isPath
lemma bot_not_connected [Nontrivial V] : Β¬(β₯ : SimpleGraph V).Connected := by
simp [bot_not_preconnected, connected_iff]
lemma top_connected [Nonempty V] : (β€ : SimpleGraph V).Connected where
preconnected := top_preconnected
theorem Iso.connected_iff {G : SimpleGraph V} {H : SimpleGraph V'} (e : G βg H) :
G.Connected β H.Connected :=
β¨Connected.map e.toHom e.toEquiv.surjective, Connected.map e.symm.toHom e.symm.toEquiv.surjectiveβ©
/-- The quotient of `V` by the `SimpleGraph.Reachable` relation gives the connected
components of a graph. -/
def ConnectedComponent := Quot G.Reachable
/-- Gives the connected component containing a particular vertex. -/
def connectedComponentMk (v : V) : G.ConnectedComponent := Quot.mk G.Reachable v
variable {G G' G''}
namespace ConnectedComponent
@[simps]
instance inhabited [Inhabited V] : Inhabited G.ConnectedComponent :=
β¨G.connectedComponentMk defaultβ©
instance isEmpty [IsEmpty V] : IsEmpty (ConnectedComponent G) := by
by_contra! hc
rw [@not_isEmpty_iff] at hc
obtain β¨v, _β© := (Classical.inhabited_of_nonempty hc).default.exists_rep
exact IsEmpty.false v
@[elab_as_elim]
protected theorem ind {Ξ² : G.ConnectedComponent β Prop}
(h : β v : V, Ξ² (G.connectedComponentMk v)) (c : G.ConnectedComponent) : Ξ² c :=
Quot.ind h c
@[elab_as_elim]
protected theorem indβ {Ξ² : G.ConnectedComponent β G.ConnectedComponent β Prop}
(h : β v w : V, Ξ² (G.connectedComponentMk v) (G.connectedComponentMk w))
(c d : G.ConnectedComponent) : Ξ² c d :=
Quot.induction_onβ c d h
protected theorem sound {v w : V} :
G.Reachable v w β G.connectedComponentMk v = G.connectedComponentMk w :=
Quot.sound
protected theorem exact {v w : V} :
G.connectedComponentMk v = G.connectedComponentMk w β G.Reachable v w :=
@Quotient.exact _ G.reachableSetoid _ _
@[simp]
protected theorem eq {v w : V} :
G.connectedComponentMk v = G.connectedComponentMk w β G.Reachable v w :=
@Quotient.eq' _ G.reachableSetoid _ _
theorem connectedComponentMk_eq_of_adj {v w : V} (a : G.Adj v w) :
G.connectedComponentMk v = G.connectedComponentMk w :=
ConnectedComponent.sound a.reachable
/-- The `ConnectedComponent` specialization of `Quot.lift`. Provides the stronger
assumption that the vertices are connected by a path. -/
protected def lift {Ξ² : Sort*} (f : V β Ξ²)
(h : β (v w : V) (p : G.Walk v w), p.IsPath β f v = f w) : G.ConnectedComponent β Ξ² :=
Quot.lift f fun v w (h' : G.Reachable v w) => h'.elim_path fun hp => h v w hp hp.2
@[simp]
protected theorem lift_mk {Ξ² : Sort*} {f : V β Ξ²}
{h : β (v w : V) (p : G.Walk v w), p.IsPath β f v = f w} {v : V} :
ConnectedComponent.lift f h (G.connectedComponentMk v) = f v :=
rfl
protected theorem Β«existsΒ» {p : G.ConnectedComponent β Prop} :
(β c : G.ConnectedComponent, p c) β β v, p (G.connectedComponentMk v) :=
Quot.mk_surjective.exists
protected theorem Β«forallΒ» {p : G.ConnectedComponent β Prop} :
(β c : G.ConnectedComponent, p c) β β v, p (G.connectedComponentMk v) :=
Quot.mk_surjective.forall
theorem _root_.SimpleGraph.Preconnected.subsingleton_connectedComponent (h : G.Preconnected) :
Subsingleton G.ConnectedComponent :=
β¨ConnectedComponent.indβ fun v w => ConnectedComponent.sound (h v w)β©
/-- This is `Quot.recOn` specialized to connected components.
For convenience, it strengthens the assumptions in the hypothesis
to provide a path between the vertices. -/
@[elab_as_elim]
def recOn
{motive : G.ConnectedComponent β Sort*}
(c : G.ConnectedComponent)
(f : (v : V) β motive (G.connectedComponentMk v))
(h : β (u v : V) (p : G.Walk u v) (_ : p.IsPath),
ConnectedComponent.sound p.reachable βΈ f u = f v) :
motive c :=
Quot.recOn c f fun u v r => r.elim_path fun p => h u v p p.2
/-- The map on connected components induced by a graph homomorphism. -/
def map (Ο : G βg G') (C : G.ConnectedComponent) : G'.ConnectedComponent :=
C.lift (fun v => G'.connectedComponentMk (Ο v)) fun _ _ p _ =>
ConnectedComponent.eq.mpr (p.map Ο).reachable
@[simp]
theorem map_mk (Ο : G βg G') (v : V) :
(G.connectedComponentMk v).map Ο = G'.connectedComponentMk (Ο v) :=
rfl
@[simp]
theorem map_id (C : ConnectedComponent G) : C.map Hom.id = C := C.ind (fun _ => rfl)
@[simp]
theorem map_comp (C : G.ConnectedComponent) (Ο : G βg G') (Ο : G' βg G'') :
(C.map Ο).map Ο = C.map (Ο.comp Ο) :=
C.ind (fun _ => rfl)
variable {Ο : G βg G'} {v : V} {v' : V'}
@[simp]
theorem iso_image_comp_eq_map_iff_eq_comp {C : G.ConnectedComponent} :
G'.connectedComponentMk (Ο v) = C.map β(βΟ : G βͺg G') β G.connectedComponentMk v = C := by
refine C.ind fun u => ?_
simp only [Iso.reachable_iff, ConnectedComponent.map_mk, RelEmbedding.coe_toRelHom,
RelIso.coe_toRelEmbedding, ConnectedComponent.eq]
@[simp]
theorem iso_inv_image_comp_eq_iff_eq_map {C : G.ConnectedComponent} :
G.connectedComponentMk (Ο.symm v') = C β G'.connectedComponentMk v' = C.map Ο := by
refine C.ind fun u => ?_
simp only [Iso.symm_apply_reachable, ConnectedComponent.eq, ConnectedComponent.map_mk,
RelEmbedding.coe_toRelHom, RelIso.coe_toRelEmbedding]
end ConnectedComponent
namespace Iso
/-- An isomorphism of graphs induces a bijection of connected components. -/
@[simps]
def connectedComponentEquiv (Ο : G βg G') : G.ConnectedComponent β G'.ConnectedComponent where
toFun := ConnectedComponent.map Ο
invFun := ConnectedComponent.map Ο.symm
left_inv C := C.ind (fun v => congr_arg G.connectedComponentMk (Equiv.left_inv Ο.toEquiv v))
right_inv C := C.ind (fun v => congr_arg G'.connectedComponentMk (Equiv.right_inv Ο.toEquiv v))
@[simp]
theorem connectedComponentEquiv_refl :
(Iso.refl : G βg G).connectedComponentEquiv = Equiv.refl _ := by
ext β¨vβ©
rfl
@[simp]
theorem connectedComponentEquiv_symm (Ο : G βg G') :
Ο.symm.connectedComponentEquiv = Ο.connectedComponentEquiv.symm := by
ext β¨_β©
rfl
@[simp]
theorem connectedComponentEquiv_trans (Ο : G βg G') (Ο' : G' βg G'') :
connectedComponentEquiv (Ο.trans Ο') =
Ο.connectedComponentEquiv.trans Ο'.connectedComponentEquiv := by
ext β¨_β©
rfl
end Iso
namespace ConnectedComponent
/-- The set of vertices in a connected component of a graph. -/
def supp (C : G.ConnectedComponent) :=
{ v | G.connectedComponentMk v = C }
@[ext]
theorem supp_injective :
Function.Injective (ConnectedComponent.supp : G.ConnectedComponent β Set V) := by
refine ConnectedComponent.indβ ?_
simp only [ConnectedComponent.supp, Set.ext_iff, ConnectedComponent.eq, Set.mem_setOf_eq]
intro v w h
rw [reachable_comm, h]
@[simp]
theorem supp_inj {C D : G.ConnectedComponent} : C.supp = D.supp β C = D :=
ConnectedComponent.supp_injective.eq_iff
instance : SetLike G.ConnectedComponent V where
coe := ConnectedComponent.supp
coe_injective' := ConnectedComponent.supp_injective
@[simp]
theorem mem_supp_iff (C : G.ConnectedComponent) (v : V) :
v β C.supp β G.connectedComponentMk v = C :=
Iff.rfl
lemma mem_supp_congr_adj {v w : V} (c : G.ConnectedComponent) (hadj : G.Adj v w) :
v β c.supp β w β c.supp := by
simp only [ConnectedComponent.mem_supp_iff] at *
constructor <;> intro h <;> simp only [β h] <;> apply connectedComponentMk_eq_of_adj
Β· exact hadj.symm
Β· exact hadj
theorem connectedComponentMk_mem {v : V} : v β G.connectedComponentMk v :=
rfl
theorem nonempty_supp (C : G.ConnectedComponent) : C.supp.Nonempty := C.exists_rep
/-- The equivalence between connected components, induced by an isomorphism of graphs,
itself defines an equivalence on the supports of each connected component.
-/
def isoEquivSupp (Ο : G βg G') (C : G.ConnectedComponent) :
C.supp β (Ο.connectedComponentEquiv C).supp where
toFun v := β¨Ο v, ConnectedComponent.iso_image_comp_eq_map_iff_eq_comp.mpr v.propβ©
invFun v' := β¨Ο.symm v', ConnectedComponent.iso_inv_image_comp_eq_iff_eq_map.mpr v'.propβ©
left_inv v := Subtype.ext_val (Ο.toEquiv.left_inv βv)
right_inv v := Subtype.ext_val (Ο.toEquiv.right_inv βv)
lemma mem_coe_supp_of_adj {v w : V} {H : Subgraph G} {c : ConnectedComponent H.coe}
(hv : v β (β) '' (c : Set H.verts)) (hw : w β H.verts)
(hadj : H.Adj v w) : w β (β) '' (c : Set H.verts) := by
obtain β¨_, hβ© := hv
use β¨w, hwβ©
rw [β (mem_supp_iff _ _).mp h.1]
exact β¨connectedComponentMk_eq_of_adj <| Subgraph.Adj.coe <| h.2 βΈ hadj.symm, rflβ©
lemma eq_of_common_vertex {v : V} {c c' : ConnectedComponent G} (hc : v β c.supp)
(hc' : v β c'.supp) : c = c' := by
simp only [mem_supp_iff] at *
rw [β hc, β hc']
lemma connectedComponentMk_supp_subset_supp {G'} {v : V} (h : G β€ G') (c' : G'.ConnectedComponent)
(hc' : v β c'.supp) : (G.connectedComponentMk v).supp β c'.supp := by
intro v' hv'
simp only [mem_supp_iff, ConnectedComponent.eq] at hv' β’
rw [ConnectedComponent.sound (hv'.mono h)]
exact hc'
lemma biUnion_supp_eq_supp {G G' : SimpleGraph V} (h : G β€ G') (c' : ConnectedComponent G') :
β (c : ConnectedComponent G) (_ : c.supp β c'.supp), c.supp = c'.supp := by
ext v
simp_rw [Set.mem_iUnion]
refine β¨fun β¨_, β¨hi, hi'β©β© β¦ hi hi', ?_β©
intro hv
use G.connectedComponentMk v
use c'.connectedComponentMk_supp_subset_supp h hv
simp only [mem_supp_iff]
lemma top_supp_eq_univ (c : ConnectedComponent (β€ : SimpleGraph V)) :
c.supp = (Set.univ : Set V) := by
have β¨w, hwβ© := c.exists_rep
ext v
simp only [Set.mem_univ, iff_true, mem_supp_iff, β hw]
apply ConnectedComponent.sound
exact (@top_connected V (Nonempty.intro v)).preconnected v w
lemma reachable_of_mem_supp {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
(hu : u β C.supp) (hv : v β C.supp) : G.Reachable u v := by
rw [mem_supp_iff] at hu hv
exact ConnectedComponent.exact (hv βΈ hu)
lemma mem_supp_of_adj_mem_supp {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
(hu : u β C.supp) (hadj : G.Adj u v) : v β C.supp := by
have hC : G.connectedComponentMk u = G.connectedComponentMk v :=
connectedComponentMk_eq_of_adj hadj
rw [hu] at hC
exact hC.symm
/--
Given a connected component `C` of a simple graph `G`, produce the induced graph on `C`.
The declaration `connected_toSimpleGraph` shows it is connected, and `toSimpleGraph_hom`
provides the homomorphism back to `G`.
-/
def toSimpleGraph {G : SimpleGraph V} (C : G.ConnectedComponent) : SimpleGraph C := G.induce C.supp
/-- Homomorphism from a connected component graph to the original graph. -/
def toSimpleGraph_hom {G : SimpleGraph V} (C : G.ConnectedComponent) : C.toSimpleGraph βg G where
toFun u := u.val
map_rel' := id
lemma toSimpleGraph_hom_apply {G : SimpleGraph V} (C : G.ConnectedComponent) (u : C) :
C.toSimpleGraph_hom u = u.val := rfl
lemma toSimpleGraph_adj {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V} (hu : u β C)
(hv : v β C) : C.toSimpleGraph.Adj β¨u, huβ© β¨v, hvβ© β G.Adj u v := by
simp [toSimpleGraph]
lemma adj_spanningCoe_toSimpleGraph {v w : V} (C : G.ConnectedComponent) :
C.toSimpleGraph.spanningCoe.Adj v w β v β C.supp β§ G.Adj v w := by
apply Iff.intro
Β· intro h
simp_all only [map_adj, SetLike.coe_sort_coe, Subtype.exists, mem_supp_iff]
obtain β¨_, a, _, _, hβ, hβ, hββ© := h
subst hβ hβ
exact β¨a, hββ©
Β· simp only [toSimpleGraph, map_adj, comap_adj, Embedding.subtype_apply, Subtype.exists,
exists_and_left, and_imp]
intro h hadj
exact β¨v, h, w, hadj, rfl, (C.mem_supp_congr_adj hadj).mp h, rflβ©
@[deprecated (since := "2025-05-08")]
alias adj_spanningCoe_induce_supp := adj_spanningCoe_toSimpleGraph
/-- Get the walk between two vertices in a connected component from a walk in the original graph. -/
private def walk_toSimpleGraph' {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
(hu : u β C) (hv : v β C) (p : G.Walk u v) : C.toSimpleGraph.Walk β¨u, huβ© β¨v, hvβ© := by
cases p with
| nil => exact Walk.nil
| @cons v w u h p =>
have hw : w β C := C.mem_supp_of_adj_mem_supp hu h
have h' : C.toSimpleGraph.Adj β¨u, huβ© β¨w, hwβ© := h
exact Walk.cons h' (C.walk_toSimpleGraph' hw hv p)
@[deprecated (since := "2025-05-08")] alias reachable_induce_supp := walk_toSimpleGraph'
/-- There is a walk between every pair of vertices in a connected component. -/
noncomputable def walk_toSimpleGraph {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
(hu : u β C) (hv : v β C) : C.toSimpleGraph.Walk β¨u, huβ© β¨v, hvβ© :=
C.walk_toSimpleGraph' hu hv (C.reachable_of_mem_supp hu hv).some
lemma reachable_toSimpleGraph {G : SimpleGraph V} (C : G.ConnectedComponent) {u v : V}
(hu : u β C) (hv : v β C) : C.toSimpleGraph.Reachable β¨u, huβ© β¨v, hvβ© :=
Walk.reachable (C.walk_toSimpleGraph hu hv)
lemma connected_toSimpleGraph (C : ConnectedComponent G) : (C.toSimpleGraph).Connected where
preconnected := by
intro β¨u, huβ© β¨v, hvβ©
exact C.reachable_toSimpleGraph hu hv
nonempty := β¨C.out, C.out_eqβ©
@[deprecated (since := "2025-05-08")] alias connected_induce_supp := connected_toSimpleGraph
end ConnectedComponent
-- TODO: Extract as lemma about general equivalence relation
lemma pairwise_disjoint_supp_connectedComponent (G : SimpleGraph V) :
Pairwise fun c c' : ConnectedComponent G β¦ Disjoint c.supp c'.supp := by
simp_rw [Set.disjoint_left]
intro _ _ h a hsx hsy
rw [ConnectedComponent.mem_supp_iff] at hsx hsy
rw [hsx] at hsy
exact h hsy
-- TODO: Extract as lemma about general equivalence relation
lemma iUnion_connectedComponentSupp (G : SimpleGraph V) :
β c : G.ConnectedComponent, c.supp = Set.univ := by
refine Set.eq_univ_of_forall fun v β¦ β¨G.connectedComponentMk v, ?_β©
simp only [Set.mem_range, SetLike.mem_coe]
exact β¨β¨G.connectedComponentMk v, rflβ©, rflβ©
theorem Preconnected.set_univ_walk_nonempty (hconn : G.Preconnected) (u v : V) :
(Set.univ : Set (G.Walk u v)).Nonempty := by
rw [β Set.nonempty_iff_univ_nonempty]
exact hconn u v
theorem Connected.set_univ_walk_nonempty (hconn : G.Connected) (u v : V) :
(Set.univ : Set (G.Walk u v)).Nonempty :=
hconn.preconnected.set_univ_walk_nonempty u v
/-! ### Bridge edges -/
section BridgeEdges
/-- An edge of a graph is a *bridge* if, after removing it, its incident vertices
are no longer reachable from one another. -/
def IsBridge (G : SimpleGraph V) (e : Sym2 V) : Prop :=
e β G.edgeSet β§
Sym2.lift β¨fun v w => Β¬(G \ fromEdgeSet {e}).Reachable v w, by simp [reachable_comm]β© e
theorem isBridge_iff {u v : V} :
G.IsBridge s(u, v) β G.Adj u v β§ Β¬(G \ fromEdgeSet {s(u, v)}).Reachable u v := Iff.rfl
theorem reachable_delete_edges_iff_exists_walk {v w v' w' : V} :
(G \ fromEdgeSet {s(v, w)}).Reachable v' w' β β p : G.Walk v' w', s(v, w) β p.edges := by
constructor
Β· rintro β¨pβ©
use p.map (.ofLE (by simp))
simp_rw [Walk.edges_map, List.mem_map, Hom.ofLE_apply, Sym2.map_id', id]
rintro β¨e, h, rflβ©
simpa using p.edges_subset_edgeSet h
Β· rintro β¨p, hβ©
refine β¨p.transfer _ fun e ep => ?_β©
simp only [edgeSet_sdiff, edgeSet_fromEdgeSet, edgeSet_sdiff_sdiff_isDiag]
exact β¨p.edges_subset_edgeSet ep, fun h' => h (h' βΈ ep)β©
theorem isBridge_iff_adj_and_forall_walk_mem_edges {v w : V} :
G.IsBridge s(v, w) β G.Adj v w β§ β p : G.Walk v w, s(v, w) β p.edges := by
rw [isBridge_iff, and_congr_right']
rw [reachable_delete_edges_iff_exists_walk, not_exists_not]
theorem reachable_deleteEdges_iff_exists_cycle.aux [DecidableEq V] {u v w : V}
(hb : β p : G.Walk v w, s(v, w) β p.edges) (c : G.Walk u u) (hc : c.IsTrail)
(he : s(v, w) β c.edges)
(hw : w β (c.takeUntil v (c.fst_mem_support_of_mem_edges he)).support) : False := by
have hv := c.fst_mem_support_of_mem_edges he
-- decompose c into
-- puw pwv pvu
-- u ----> w ----> v ----> u
let puw := (c.takeUntil v hv).takeUntil w hw
let pwv := (c.takeUntil v hv).dropUntil w hw
let pvu := c.dropUntil v hv
have : c = (puw.append pwv).append pvu := by simp [puw, pwv, pvu]
-- We have two walks from v to w
-- pvu puw
-- v ----> u ----> w
-- | ^
-- `-------------'
-- pwv.reverse
-- so they both contain the edge s(v, w), but that's a contradiction since c is a trail.
have hbq := hb (pvu.append puw)
have hpq' := hb pwv.reverse
rw [Walk.edges_reverse, List.mem_reverse] at hpq'
rw [Walk.isTrail_def, this, Walk.edges_append, Walk.edges_append, List.nodup_append_comm,
β List.append_assoc, β Walk.edges_append] at hc
exact List.disjoint_of_nodup_append hc hbq hpq'
theorem adj_and_reachable_delete_edges_iff_exists_cycle {v w : V} :
G.Adj v w β§ (G \ fromEdgeSet {s(v, w)}).Reachable v w β
β (u : V) (p : G.Walk u u), p.IsCycle β§ s(v, w) β p.edges := by
classical
rw [reachable_delete_edges_iff_exists_walk]
constructor
Β· rintro β¨h, p, hpβ©
refine β¨w, Walk.cons h.symm p.toPath, ?_, ?_β©
Β· apply Path.cons_isCycle
rw [Sym2.eq_swap]
intro h
cases hp (Walk.edges_toPath_subset p h)
Β· simp only [Sym2.eq_swap, Walk.edges_cons, List.mem_cons, true_or]
Β· rintro β¨u, c, hc, heβ©
refine β¨c.adj_of_mem_edges he, ?_β©
by_contra! hb
have hb' : β p : G.Walk w v, s(w, v) β p.edges := by
intro p
simpa [Sym2.eq_swap] using hb p.reverse
have hvc : v β c.support := Walk.fst_mem_support_of_mem_edges c he
refine reachable_deleteEdges_iff_exists_cycle.aux hb' (c.rotate hvc) (hc.isTrail.rotate hvc)
?_ (Walk.start_mem_support _)
rwa [(Walk.rotate_edges c hvc).mem_iff, Sym2.eq_swap]
theorem isBridge_iff_adj_and_forall_cycle_notMem {v w : V} : G.IsBridge s(v, w) β
G.Adj v w β§ β β¦u : Vβ¦ (p : G.Walk u u), p.IsCycle β s(v, w) β p.edges := by
rw [isBridge_iff, and_congr_right_iff]
intro h
rw [β not_iff_not]
push_neg
rw [β adj_and_reachable_delete_edges_iff_exists_cycle]
simp only [h, true_and]
@[deprecated (since := "2025-05-23")]
alias isBridge_iff_adj_and_forall_cycle_not_mem := isBridge_iff_adj_and_forall_cycle_notMem
theorem isBridge_iff_mem_and_forall_cycle_notMem {e : Sym2 V} :
G.IsBridge e β e β G.edgeSet β§ β β¦u : Vβ¦ (p : G.Walk u u), p.IsCycle β e β p.edges :=
Sym2.ind (fun _ _ => isBridge_iff_adj_and_forall_cycle_notMem) e
@[deprecated (since := "2025-05-23")]
alias isBridge_iff_mem_and_forall_cycle_not_mem := isBridge_iff_mem_and_forall_cycle_notMem
/-- Deleting a non-bridge edge from a connected graph preserves connectedness. -/
lemma Connected.connected_delete_edge_of_not_isBridge (hG : G.Connected) {x y : V}
(h : Β¬ G.IsBridge s(x, y)) : (G.deleteEdges {s(x, y)}).Connected := by
classical
simp only [isBridge_iff, not_and, not_not] at h
obtain hxy | hxy := em' <| G.Adj x y
Β· rwa [deleteEdges, Disjoint.sdiff_eq_left (by simpa)]
refine (connected_iff_exists_forall_reachable _).2 β¨x, fun w β¦ ?_β©
obtain β¨P, hPβ© := hG.exists_isPath w x
obtain heP | heP := em' <| s(x,y) β P.edges
Β· exact β¨(P.toDeleteEdges {s(x,y)} (by aesop)).reverseβ©
have hyP := P.snd_mem_support_of_mem_edges heP
let Pβ := P.takeUntil y hyP
have hxPβ := Walk.endpoint_notMem_support_takeUntil hP hyP hxy.ne
have hePβ : s(x,y) β Pβ.edges := fun h β¦ hxPβ <| Pβ.fst_mem_support_of_mem_edges h
exact (h hxy).trans (Reachable.symm β¨Pβ.toDeleteEdges {s(x,y)} (by aesop)β©)
end BridgeEdges
end SimpleGraph
|
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.
|
Basic.lean
|
/-
Copyright (c) 2021 Julian Kuelshammer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Julian Kuelshammer
-/
import Mathlib.Algebra.PEmptyInstances
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Functor.ReflectsIso.Basic
/-!
# Category instances for `Mul`, `Add`, `Semigroup` and `AddSemigroup`
We introduce the bundled categories:
* `MagmaCat`
* `AddMagmaCat`
* `Semigrp`
* `AddSemigrp`
along with the relevant forgetful functors between them.
This closely follows `Mathlib/Algebra/Category/MonCat/Basic.lean`.
## TODO
* Limits in these categories
* free/forgetful adjunctions
-/
universe u v
open CategoryTheory
/-- The category of additive magmas and additive magma morphisms. -/
structure AddMagmaCat : Type (u + 1) where
/-- The underlying additive magma. -/
(carrier : Type u)
[str : Add carrier]
/-- The category of magmas and magma morphisms. -/
@[to_additive]
structure MagmaCat : Type (u + 1) where
/-- The underlying magma. -/
(carrier : Type u)
[str : Mul carrier]
attribute [instance] AddMagmaCat.str MagmaCat.str
attribute [to_additive existing] MagmaCat.carrier MagmaCat.str
initialize_simps_projections AddMagmaCat (carrier β coe, -str)
initialize_simps_projections MagmaCat (carrier β coe, -str)
namespace MagmaCat
@[to_additive]
instance : CoeSort MagmaCat (Type u) :=
β¨MagmaCat.carrierβ©
attribute [coe] AddMagmaCat.carrier MagmaCat.carrier
/-- Construct a bundled `MagmaCat` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddMagmaCat` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Mul M] : MagmaCat := β¨Mβ©
end MagmaCat
/-- The type of morphisms in `AddMagmaCat R`. -/
@[ext]
structure AddMagmaCat.Hom (A B : AddMagmaCat.{u}) where
private mk ::
/-- The underlying `AddHom`. -/
hom' : A ββ+ B
/-- The type of morphisms in `MagmaCat R`. -/
@[to_additive, ext]
structure MagmaCat.Hom (A B : MagmaCat.{u}) where
private mk ::
/-- The underlying `MulHom`. -/
hom' : A ββ* B
attribute [to_additive existing AddMagmaCat.Hom.mk] MagmaCat.Hom.mk
namespace MagmaCat
@[to_additive]
instance : Category MagmaCat.{u} where
Hom X Y := Hom X Y
id X := β¨MulHom.id Xβ©
comp f g := β¨g.hom'.comp f.hom'β©
@[to_additive]
instance : ConcreteCategory MagmaCat (Β· ββ* Β·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `MagmaCat` back into a `MulHom`. -/
@[to_additive /-- Turn a morphism in `AddMagmaCat` back into an `AddHom`. -/]
abbrev Hom.hom {X Y : MagmaCat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := MagmaCat) f
/-- Typecheck a `MulHom` as a morphism in `MagmaCat`. -/
@[to_additive /-- Typecheck an `AddHom` as a morphism in `AddMagmaCat`. -/]
abbrev ofHom {X Y : Type u} [Mul X] [Mul Y] (f : X ββ* Y) : of X βΆ of Y :=
ConcreteCategory.ofHom (C := MagmaCat) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : MagmaCat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' β hom)
initialize_simps_projections AddMagmaCat.Hom (hom' β hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : MagmaCat} : (π X : X β X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : MagmaCat} {f : X βΆ Y} {g : Y βΆ Z} : (f β« g : X β Z) = g β f := rfl
@[to_additive (attr := simp)]
lemma forget_map {X Y : MagmaCat} (f : X βΆ Y) :
(forget MagmaCat).map f = f := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : MagmaCat} {f g : X βΆ Y} (w : β x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (M : Type u) [Mul M] : (MagmaCat.of M : Type u) = M := rfl
@[to_additive (attr := simp)]
lemma hom_id {M : MagmaCat} : (π M : M βΆ M).hom = MulHom.id M := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (M : MagmaCat) (x : M) :
(π M : M βΆ M) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {M N T : MagmaCat} (f : M βΆ N) (g : N βΆ T) :
(f β« g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {M N T : MagmaCat} (f : M βΆ N) (g : N βΆ T) (x : M) :
(f β« g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {M N : MagmaCat} {f g : M βΆ N} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {M N : Type u} [Mul M] [Mul N] (f : M ββ* N) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {M N : MagmaCat} (f : M βΆ N) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {M : Type u} [Mul M] : ofHom (MulHom.id M) = π (of M) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {M N P : Type u} [Mul M] [Mul N] [Mul P]
(f : M ββ* N) (g : N ββ* P) :
ofHom (g.comp f) = ofHom f β« ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Mul X] [Mul Y] (f : X ββ* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {M N : MagmaCat} (e : M β
N) (x : M) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {M N : MagmaCat} (e : M β
N) (s : N) : e.hom (e.inv s) = s := by
simp
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Mul X] [Mul Y] (e : X β* Y) :
(ofHom (e : X ββ* Y)).hom = βe :=
rfl
@[to_additive]
instance : Inhabited MagmaCat :=
β¨MagmaCat.of PEmptyβ©
end MagmaCat
/-- The category of additive semigroups and semigroup morphisms. -/
structure AddSemigrp : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : AddSemigroup carrier]
/-- The category of semigroups and semigroup morphisms. -/
@[to_additive]
structure Semigrp : Type (u + 1) where
/-- The underlying type. -/
(carrier : Type u)
[str : Semigroup carrier]
attribute [instance] AddSemigrp.str Semigrp.str
attribute [to_additive existing] Semigrp.carrier Semigrp.str
initialize_simps_projections AddSemigrp (carrier β coe, -str)
initialize_simps_projections Semigrp (carrier β coe, -str)
namespace Semigrp
@[to_additive]
instance : CoeSort Semigrp (Type u) :=
β¨Semigrp.carrierβ©
attribute [coe] AddSemigrp.carrier Semigrp.carrier
/-- Construct a bundled `Semigrp` from the underlying type and typeclass. -/
@[to_additive /-- Construct a bundled `AddSemigrp` from the underlying type and typeclass. -/]
abbrev of (M : Type u) [Semigroup M] : Semigrp := β¨Mβ©
end Semigrp
/-- The type of morphisms in `AddSemigrp R`. -/
@[ext]
structure AddSemigrp.Hom (A B : AddSemigrp.{u}) where
private mk ::
/-- The underlying `AddHom`. -/
hom' : A ββ+ B
/-- The type of morphisms in `Semigrp R`. -/
@[to_additive, ext]
structure Semigrp.Hom (A B : Semigrp.{u}) where
private mk ::
/-- The underlying `MulHom`. -/
hom' : A ββ* B
attribute [to_additive existing AddSemigrp.Hom.mk] Semigrp.Hom.mk
namespace Semigrp
@[to_additive]
instance : Category Semigrp.{u} where
Hom X Y := Hom X Y
id X := β¨MulHom.id Xβ©
comp f g := β¨g.hom'.comp f.hom'β©
@[to_additive]
instance : ConcreteCategory Semigrp (Β· ββ* Β·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `Semigrp` back into a `MulHom`. -/
@[to_additive /-- Turn a morphism in `AddSemigrp` back into an `AddHom`. -/]
abbrev Hom.hom {X Y : Semigrp.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := Semigrp) f
/-- Typecheck a `MulHom` as a morphism in `Semigrp`. -/
@[to_additive /-- Typecheck an `AddHom` as a morphism in `AddSemigrp`. -/]
abbrev ofHom {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X ββ* Y) : of X βΆ of Y :=
ConcreteCategory.ofHom (C := Semigrp) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : Semigrp.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' β hom)
initialize_simps_projections AddSemigrp.Hom (hom' β hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[to_additive (attr := simp)]
lemma coe_id {X : Semigrp} : (π X : X β X) = id := rfl
@[to_additive (attr := simp)]
lemma coe_comp {X Y Z : Semigrp} {f : X βΆ Y} {g : Y βΆ Z} : (f β« g : X β Z) = g β f := rfl
@[simp] lemma forget_map {X Y : Semigrp} (f : X βΆ Y) : (forget Semigrp).map f = (f : X β Y) := rfl
@[to_additive (attr := ext)]
lemma ext {X Y : Semigrp} {f g : X βΆ Y} (w : β x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[to_additive]
-- This is not `simp` to avoid rewriting in types of terms.
theorem coe_of (R : Type u) [Semigroup R] : β(Semigrp.of R) = R :=
rfl
@[to_additive (attr := simp)]
lemma hom_id {X : Semigrp} : (π X : X βΆ X).hom = MulHom.id X := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma id_apply (X : Semigrp) (x : X) :
(π X : X βΆ X) x = x := by simp
@[to_additive (attr := simp)]
lemma hom_comp {X Y T : Semigrp} (f : X βΆ Y) (g : Y βΆ T) :
(f β« g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
@[to_additive]
lemma comp_apply {X Y T : Semigrp} (f : X βΆ Y) (g : Y βΆ T) (x : X) :
(f β« g) x = g (f x) := by simp
@[to_additive (attr := ext)]
lemma hom_ext {X Y : Semigrp} {f g : X βΆ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[to_additive (attr := simp)]
lemma hom_ofHom {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X ββ* Y) : (ofHom f).hom = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_hom {X Y : Semigrp} (f : X βΆ Y) :
ofHom (Hom.hom f) = f := rfl
@[to_additive (attr := simp)]
lemma ofHom_id {X : Type u} [Semigroup X] : ofHom (MulHom.id X) = π (of X) := rfl
@[to_additive (attr := simp)]
lemma ofHom_comp {X Y Z : Type u} [Semigroup X] [Semigroup Y] [Semigroup Z]
(f : X ββ* Y) (g : Y ββ* Z) :
ofHom (g.comp f) = ofHom f β« ofHom g :=
rfl
@[to_additive]
lemma ofHom_apply {X Y : Type u} [Semigroup X] [Semigroup Y] (f : X ββ* Y) (x : X) :
(ofHom f) x = f x := rfl
@[to_additive]
lemma inv_hom_apply {X Y : Semigrp} (e : X β
Y) (x : X) : e.inv (e.hom x) = x := by
simp
@[to_additive]
lemma hom_inv_apply {X Y : Semigrp} (e : X β
Y) (s : Y) : e.hom (e.inv s) = s := by
simp
@[to_additive (attr := simp)]
lemma mulEquiv_coe_eq {X Y : Type _} [Semigroup X] [Semigroup Y] (e : X β* Y) :
(ofHom (e : X ββ* Y)).hom = βe :=
rfl
@[to_additive]
instance : Inhabited Semigrp :=
β¨Semigrp.of PEmptyβ©
@[to_additive]
instance hasForgetToMagmaCat : HasForgetβ Semigrp MagmaCat where
forgetβ :=
{ obj R := MagmaCat.of R
map f := MagmaCat.ofHom f.hom }
end Semigrp
variable {X Y : Type u}
section
variable [Mul X] [Mul Y]
/-- Build an isomorphism in the category `MagmaCat` from a `MulEquiv` between `Mul`s. -/
@[to_additive (attr := simps)
/-- Build an isomorphism in the category `AddMagmaCat` from an `AddEquiv` between `Add`s. -/]
def MulEquiv.toMagmaCatIso (e : X β* Y) : MagmaCat.of X β
MagmaCat.of Y where
hom := MagmaCat.ofHom e.toMulHom
inv := MagmaCat.ofHom e.symm.toMulHom
end
section
variable [Semigroup X] [Semigroup Y]
/-- Build an isomorphism in the category `Semigroup` from a `MulEquiv` between `Semigroup`s. -/
@[to_additive (attr := simps)
/-- Build an isomorphism in the category
`AddSemigroup` from an `AddEquiv` between `AddSemigroup`s. -/]
def MulEquiv.toSemigrpIso (e : X β* Y) : Semigrp.of X β
Semigrp.of Y where
hom := Semigrp.ofHom e.toMulHom
inv := Semigrp.ofHom e.symm.toMulHom
end
namespace CategoryTheory.Iso
/-- Build a `MulEquiv` from an isomorphism in the category `MagmaCat`. -/
@[to_additive
/-- Build an `AddEquiv` from an isomorphism in the category `AddMagmaCat`. -/]
def magmaCatIsoToMulEquiv {X Y : MagmaCat} (i : X β
Y) : X β* Y :=
MulHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
/-- Build a `MulEquiv` from an isomorphism in the category `Semigroup`. -/
@[to_additive
/-- Build an `AddEquiv` from an isomorphism in the category `AddSemigroup`. -/]
def semigrpIsoToMulEquiv {X Y : Semigrp} (i : X β
Y) : X β* Y :=
MulHom.toMulEquiv i.hom.hom i.inv.hom (by ext; simp) (by ext; simp)
end CategoryTheory.Iso
/-- multiplicative equivalences between `Mul`s are the same as (isomorphic to) isomorphisms
in `MagmaCat` -/
@[to_additive
/-- additive equivalences between `Add`s are the same
as (isomorphic to) isomorphisms in `AddMagmaCat` -/]
def mulEquivIsoMagmaIso {X Y : Type u} [Mul X] [Mul Y] :
X β* Y β
MagmaCat.of X β
MagmaCat.of Y where
hom e := e.toMagmaCatIso
inv i := i.magmaCatIsoToMulEquiv
/-- multiplicative equivalences between `Semigroup`s are the same as (isomorphic to) isomorphisms
in `Semigroup` -/
@[to_additive
/-- additive equivalences between `AddSemigroup`s are
the same as (isomorphic to) isomorphisms in `AddSemigroup` -/]
def mulEquivIsoSemigrpIso {X Y : Type u} [Semigroup X] [Semigroup Y] :
X β* Y β
Semigrp.of X β
Semigrp.of Y where
hom e := e.toSemigrpIso
inv i := i.semigrpIsoToMulEquiv
@[to_additive]
instance MagmaCat.forgetReflectsIsos : (forget MagmaCat.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget MagmaCat).map f)
let e : X β* Y := { f.hom, i.toEquiv with }
exact e.toMagmaCatIso.isIso_hom
@[to_additive]
instance Semigrp.forgetReflectsIsos : (forget Semigrp.{u}).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget Semigrp).map f)
let e : X β* Y := { f.hom, i.toEquiv with }
exact e.toSemigrpIso.isIso_hom
/--
Ensure that `forgetβ CommMonCat MonCat` automatically reflects isomorphisms.
We could have used `CategoryTheory.HasForget.ReflectsIso` alternatively.
-/
@[to_additive]
instance Semigrp.forgetβ_full : (forgetβ Semigrp MagmaCat).Full where
map_surjective f := β¨ofHom f.hom, rflβ©
/-!
Once we've shown that the forgetful functors to type reflect isomorphisms,
we automatically obtain that the `forgetβ` functors between our concrete categories
reflect isomorphisms.
-/
example : (forgetβ Semigrp MagmaCat).ReflectsIsomorphisms := inferInstance
|
Instances.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.ContinuousFunctionalCalculus.Restrict
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Unique
import Mathlib.Analysis.CStarAlgebra.Unitization
import Mathlib.Analysis.Normed.Algebra.Spectrum
/-! # Instances of the continuous functional calculus
## Main theorems
* `IsSelfAdjoint.instContinuousFunctionalCalculus`: the continuous functional calculus for
selfadjoint elements in a `β`-algebra with a continuous functional calculus for normal elements
and where every element has compact spectrum. In particular, this includes unital Cβ-algebras
over `β`.
* `Nonneg.instContinuousFunctionalCalculus`: the continuous functional calculus for nonnegative
elements in an `β`-algebra with a continuous functional calculus for selfadjoint elements,
where every element has compact spectrum, and where nonnegative elements have nonnegative
spectrum. In particular, this includes unital Cβ-algebras over `β`.
## Tags
continuous functional calculus, normal, selfadjoint
-/
open Topology
noncomputable section
local notation "Οβ" => quasispectrum
local notation "Ο" => spectrum
/-!
### Pull back a non-unital instance from a unital one on the unitization
-/
section RCLike
variable {π A : Type*} [RCLike π] [NonUnitalNormedRing A] [StarRing A]
variable [NormedSpace π A] [IsScalarTower π A A] [SMulCommClass π A A]
variable [StarModule π A] {p : A β Prop} {pβ : Unitization π A β Prop}
local postfix:max "βΊΒΉ" => Unitization π
variable (hpβ : β {x : A}, pβ x β p x) (a : A) (ha : p a)
variable [ContinuousFunctionalCalculus π (Unitization π A) pβ]
open scoped ContinuousMapZero
open Unitization in
/--
This is an auxiliary definition used for constructing an instance of the non-unital continuous
functional calculus given a instance of the unital one on the unitization.
This is the natural non-unital star homomorphism obtained from the chain
```lean
calc
C(Οβ π a, π)β ββββ[π] C(Οβ π a, π) := ContinuousMapZero.toContinuousMapHom
_ ββ[π] C(Ο π (βa : AβΊΒΉ), π) := Homeomorph.compStarAlgEquiv'
_ βββ[π] AβΊΒΉ := cfcHom
```
This range of this map is contained in the range of `(β) : A β AβΊΒΉ` (see `cfcβAux_mem_range_inr`),
and so we may restrict it to `A` to get the necessary homomorphism for the non-unital continuous
functional calculus.
-/
noncomputable def cfcβAux : C(Οβ π a, π)β ββββ[π] AβΊΒΉ :=
(cfcHom (R := π) (hpβ.mpr ha) : C(Ο π (a : AβΊΒΉ), π) ββββ[π] AβΊΒΉ) |>.comp
(Homeomorph.compStarAlgEquiv' π π <| .setCongr <| (quasispectrum_eq_spectrum_inr' π π a).symm)
|>.comp ContinuousMapZero.toContinuousMapHom
lemma cfcβAux_id : cfcβAux hpβ a ha (ContinuousMapZero.id rfl) = a := cfcHom_id (hpβ.mpr ha)
open Unitization in
lemma isClosedEmbedding_cfcβAux : IsClosedEmbedding (cfcβAux hpβ a ha) := by
simp only [cfcβAux, NonUnitalStarAlgHom.coe_comp]
refine ((cfcHom_isClosedEmbedding (hpβ.mpr ha)).comp ?_).comp
ContinuousMapZero.isClosedEmbedding_toContinuousMap
let e : C(Οβ π a, π) ββ C(Ο π (a : AβΊΒΉ), π) :=
(Homeomorph.setCongr (quasispectrum_eq_spectrum_inr' π π a)).arrowCongr (.refl _)
exact e.isClosedEmbedding
lemma spec_cfcβAux (f : C(Οβ π a, π)β) : Ο π (cfcβAux hpβ a ha f) = Set.range f := by
rw [cfcβAux, NonUnitalStarAlgHom.comp_assoc, NonUnitalStarAlgHom.comp_apply]
simp only [NonUnitalStarAlgHom.comp_apply, NonUnitalStarAlgHom.coe_coe]
rw [cfcHom_map_spectrum (hpβ.mpr ha) (R := π) _]
simp
variable [CompleteSpace A]
lemma cfcβAux_mem_range_inr (f : C(Οβ π a, π)β) :
cfcβAux hpβ a ha f β NonUnitalStarAlgHom.range (Unitization.inrNonUnitalStarAlgHom π A) := by
have hβ := (isClosedEmbedding_cfcβAux hpβ a ha).continuous.range_subset_closure_image_dense
(ContinuousMapZero.adjoin_id_dense (s := Οβ π a) rfl) β¨f, rflβ©
rw [β SetLike.mem_coe]
refine closure_minimal ?_ ?_ hβ
Β· rw [β NonUnitalStarSubalgebra.coe_map, SetLike.coe_subset_coe, NonUnitalStarSubalgebra.map_le]
apply NonUnitalStarAlgebra.adjoin_le
apply Set.singleton_subset_iff.mpr
rw [SetLike.mem_coe, NonUnitalStarSubalgebra.mem_comap, cfcβAux_id hpβ a ha]
exact β¨a, rflβ©
Β· have : Continuous (Unitization.fst (R := π) (A := A)) :=
Unitization.uniformEquivProd.continuous.fst
simp only [NonUnitalStarAlgHom.coe_range]
convert IsClosed.preimage this (isClosed_singleton (x := 0))
aesop
variable [CStarRing A]
include hpβ in
open Unitization NonUnitalStarAlgHom in
theorem RCLike.nonUnitalContinuousFunctionalCalculus :
NonUnitalContinuousFunctionalCalculus π A p where
predicate_zero := by
rw [β hpβ, Unitization.inr_zero π]
exact cfc_predicate_zero π
exists_cfc_of_predicate a ha := by
let Ο : C(Οβ π a, π)β ββββ[π] A := comp (inrRangeEquiv π A).symm <|
codRestrict (cfcβAux hpβ a ha) _ (cfcβAux_mem_range_inr hpβ a ha)
have coe_Ο (f : C(Οβ π a, π)β) : Ο f = cfcβAux hpβ a ha f :=
congr_arg Subtype.val <| (inrRangeEquiv π A).apply_symm_apply
β¨cfcβAux hpβ a ha f, cfcβAux_mem_range_inr hpβ a ha fβ©
refine β¨Ο, ?isClosedEmbedding, ?map_id, fun f β¦ ?map_spec, fun f β¦ ?isStarNormalβ©
case isClosedEmbedding =>
apply isometry_inr (π := π) (A := A) |>.isClosedEmbedding |>.of_comp_iff.mp
have : inr β Ο = cfcβAux hpβ a ha := by ext1; rw [Function.comp_apply, coe_Ο]
exact this βΈ isClosedEmbedding_cfcβAux hpβ a ha
case map_id => exact inr_injective (R := π) <| coe_Ο _ βΈ cfcβAux_id hpβ a ha
case map_spec =>
exact quasispectrum_eq_spectrum_inr' π π (Ο f) βΈ coe_Ο _ βΈ spec_cfcβAux hpβ a ha f
case isStarNormal => exact hpβ.mp <| coe_Ο _ βΈ cfcHom_predicate (R := π) (hpβ.mpr ha) _
end RCLike
/-!
### Continuous functional calculus for selfadjoint elements
-/
section SelfAdjointNonUnital
variable {A : Type*} [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [Module β A]
[IsScalarTower β A A] [SMulCommClass β A A]
[NonUnitalContinuousFunctionalCalculus β A IsStarNormal]
/-- An element in a non-unital Cβ-algebra is selfadjoint if and only if it is normal and its
quasispectrum is contained in `β`. -/
lemma isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts {a : A} :
IsSelfAdjoint a β IsStarNormal a β§ QuasispectrumRestricts a Complex.reCLM := by
refine β¨fun ha β¦ β¨ha.isStarNormal, β¨fun x hx β¦ ?_, Complex.ofReal_reβ©β©, ?_β©
Β· have := eqOn_of_cfcβ_eq_cfcβ <|
(cfcβ_star (id : β β β) a).symm βΈ (cfcβ_id β a).symm βΈ ha.star_eq
exact Complex.conj_eq_iff_re.mp (by simpa using this hx)
Β· rintro β¨haβ, haββ©
rw [isSelfAdjoint_iff]
nth_rw 2 [β cfcβ_id β a]
rw [β cfcβ_star_id a (R := β)]
refine cfcβ_congr fun x hx β¦ ?_
obtain β¨x, -, rflβ© := haβ.algebraMap_image.symm βΈ hx
exact Complex.conj_ofReal _
alias β¨IsSelfAdjoint.quasispectrumRestricts, _β© :=
isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts
/-- A normal element whose `β`-quasispectrum is contained in `β` is selfadjoint. -/
lemma QuasispectrumRestricts.isSelfAdjoint (a : A) (ha : QuasispectrumRestricts a Complex.reCLM)
[IsStarNormal a] : IsSelfAdjoint a :=
isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts.mpr β¨βΉ_βΊ, haβ©
instance IsSelfAdjoint.instNonUnitalContinuousFunctionalCalculus :
NonUnitalContinuousFunctionalCalculus β A IsSelfAdjoint :=
QuasispectrumRestricts.cfc (q := IsStarNormal) (p := IsSelfAdjoint) Complex.reCLM
Complex.isometry_ofReal.isUniformEmbedding (.zero _)
(fun _ β¦ isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts)
end SelfAdjointNonUnital
section SelfAdjointUnital
variable {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra β A]
[ContinuousFunctionalCalculus β A IsStarNormal]
/-
TODO: REMOVE
this is a duplicate of `isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts`, because of
`abbrev SpectrumRestricts := QuasispectrumRestricts` but we first need unital-to-non-unital
instance)
-/
/-- An element in a Cβ-algebra is selfadjoint if and only if it is normal and its spectrum is
contained in `β`. -/
lemma isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts {a : A} :
IsSelfAdjoint a β IsStarNormal a β§ SpectrumRestricts a Complex.reCLM :=
isSelfAdjoint_iff_isStarNormal_and_quasispectrumRestricts
-- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`)
lemma IsSelfAdjoint.spectrumRestricts {a : A} (ha : IsSelfAdjoint a) :
SpectrumRestricts a Complex.reCLM :=
isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts.mp ha |>.right
-- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`)
/-- A normal element whose `β`-spectrum is contained in `β` is selfadjoint. -/
lemma SpectrumRestricts.isSelfAdjoint (a : A) (ha : SpectrumRestricts a Complex.reCLM)
[IsStarNormal a] : IsSelfAdjoint a :=
isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts.mpr β¨βΉ_βΊ, haβ©
instance IsSelfAdjoint.instContinuousFunctionalCalculus :
ContinuousFunctionalCalculus β A IsSelfAdjoint :=
SpectrumRestricts.cfc (q := IsStarNormal) (p := IsSelfAdjoint) Complex.reCLM
Complex.isometry_ofReal.isUniformEmbedding (.zero _)
(fun _ β¦ isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts)
lemma IsSelfAdjoint.spectrum_nonempty {A : Type*} [Ring A] [StarRing A]
[TopologicalSpace A] [Algebra β A] [ContinuousFunctionalCalculus β A IsSelfAdjoint]
[Nontrivial A] {a : A} (ha : IsSelfAdjoint a) : (Ο β a).Nonempty :=
CFC.spectrum_nonempty β a ha
end SelfAdjointUnital
/-!
### Continuous functional calculus for nonnegative elements
-/
section Nonneg
lemma CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts {A : Type*} [NonUnitalRing A]
[StarRing A] [TopologicalSpace A] [Module β A] [IsScalarTower β A A] [SMulCommClass β A A]
[NonUnitalContinuousFunctionalCalculus β A IsSelfAdjoint]
{a : A} (haβ : IsSelfAdjoint a) (haβ : QuasispectrumRestricts a ContinuousMap.realToNNReal) :
β x : A, IsSelfAdjoint x β§ QuasispectrumRestricts x ContinuousMap.realToNNReal β§ x * x = a := by
use cfcβ (βΒ·) a, cfcβ_predicate (βΒ·) a
constructor
Β· simpa only [QuasispectrumRestricts.nnreal_iff, cfcβ_map_quasispectrum (βΒ·) a,
Set.mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ]
using fun x _ β¦ Real.sqrt_nonneg x
Β· rw [β cfcβ_mul ..]
nth_rw 2 [β cfcβ_id β a]
apply cfcβ_congr fun x hx β¦ ?_
rw [QuasispectrumRestricts.nnreal_iff] at haβ
apply haβ x at hx
simp [β sq, Real.sq_sqrt hx]
variable {A : Type*} [NonUnitalRing A] [PartialOrder A] [StarRing A] [StarOrderedRing A]
variable [TopologicalSpace A] [Module β A] [IsScalarTower β A A] [SMulCommClass β A A]
variable [NonUnitalContinuousFunctionalCalculus β A IsSelfAdjoint]
variable [NonnegSpectrumClass β A]
lemma nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts {a : A} :
0 β€ a β IsSelfAdjoint a β§ QuasispectrumRestricts a ContinuousMap.realToNNReal := by
refine β¨fun ha β¦ β¨.of_nonneg ha, .nnreal_of_nonneg haβ©, ?_β©
rintro β¨haβ, haββ©
obtain β¨x, hx, -, rflβ© := CFC.exists_sqrt_of_isSelfAdjoint_of_quasispectrumRestricts haβ haβ
simpa [sq, hx.star_eq] using star_mul_self_nonneg x
open NNReal in
instance Nonneg.instNonUnitalContinuousFunctionalCalculus :
NonUnitalContinuousFunctionalCalculus ββ₯0 A (0 β€ Β·) :=
QuasispectrumRestricts.cfc (q := IsSelfAdjoint) ContinuousMap.realToNNReal
isUniformEmbedding_subtype_val le_rfl
(fun _ β¦ nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts)
open NNReal in
lemma NNReal.spectrum_nonempty {A : Type*} [Ring A] [StarRing A] [LE A]
[TopologicalSpace A] [Algebra ββ₯0 A] [ContinuousFunctionalCalculus ββ₯0 A (0 β€ Β·)]
[Nontrivial A] {a : A} (ha : 0 β€ a) : (spectrum ββ₯0 a).Nonempty :=
CFC.spectrum_nonempty ββ₯0 a ha
end Nonneg
section Nonneg
-- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`)
lemma CFC.exists_sqrt_of_isSelfAdjoint_of_spectrumRestricts {A : Type*} [Ring A] [StarRing A]
[TopologicalSpace A] [Algebra β A] [ContinuousFunctionalCalculus β A IsSelfAdjoint]
{a : A} (haβ : IsSelfAdjoint a) (haβ : SpectrumRestricts a ContinuousMap.realToNNReal) :
β x : A, IsSelfAdjoint x β§ SpectrumRestricts x ContinuousMap.realToNNReal β§ x ^ 2 = a := by
use cfc (βΒ·) a, cfc_predicate (βΒ·) a
constructor
Β· simpa only [SpectrumRestricts.nnreal_iff, cfc_map_spectrum (βΒ·) a, Set.mem_image,
forall_exists_index, and_imp, forall_apply_eq_imp_iffβ] using fun x _ β¦ Real.sqrt_nonneg x
Β· rw [β cfc_pow ..]
nth_rw 2 [β cfc_id β a]
apply cfc_congr fun x hx β¦ ?_
rw [SpectrumRestricts.nnreal_iff] at haβ
apply haβ x at hx
simp [Real.sq_sqrt hx]
variable {A : Type*} [Ring A] [PartialOrder A] [StarRing A] [StarOrderedRing A] [TopologicalSpace A]
variable [Algebra β A] [ContinuousFunctionalCalculus β A IsSelfAdjoint]
variable [NonnegSpectrumClass β A]
-- TODO: REMOVE (duplicate; see comment on `isSelfAdjoint_iff_isStarNormal_and_spectrumRestricts`)
lemma nonneg_iff_isSelfAdjoint_and_spectrumRestricts {a : A} :
0 β€ a β IsSelfAdjoint a β§ SpectrumRestricts a ContinuousMap.realToNNReal := by
refine β¨fun ha β¦ β¨.of_nonneg ha, .nnreal_of_nonneg haβ©, ?_β©
rintro β¨haβ, haββ©
obtain β¨x, hx, -, rflβ© := CFC.exists_sqrt_of_isSelfAdjoint_of_spectrumRestricts haβ haβ
simpa [sq, hx.star_eq] using star_mul_self_nonneg x
open NNReal in
instance Nonneg.instContinuousFunctionalCalculus :
ContinuousFunctionalCalculus ββ₯0 A (0 β€ Β·) :=
SpectrumRestricts.cfc (q := IsSelfAdjoint) ContinuousMap.realToNNReal
isUniformEmbedding_subtype_val le_rfl (fun _ β¦ nonneg_iff_isSelfAdjoint_and_spectrumRestricts)
end Nonneg
/-!
### The restriction of a continuous functional calculus is equal to the original one
-/
section RealEqComplex
variable {A : Type*} [TopologicalSpace A] [Ring A] [StarRing A] [Algebra β A]
[ContinuousFunctionalCalculus β A IsStarNormal] [T2Space A]
lemma cfcHom_real_eq_restrict {a : A} (ha : IsSelfAdjoint a) :
cfcHom ha =
ha.spectrumRestricts.starAlgHom (R := β) (S := β)
(cfcHom ha.isStarNormal) (f := Complex.reCLM) :=
ha.spectrumRestricts.cfcHom_eq_restrict _ Complex.isometry_ofReal.isUniformEmbedding
ha ha.isStarNormal
lemma cfc_real_eq_complex {a : A} (f : β β β) (ha : IsSelfAdjoint a := by cfc_tac) :
cfc f a = cfc (fun x β¦ f x.re : β β β) a := by
replace ha : IsSelfAdjoint a := ha -- hack to avoid issues caused by autoParam
exact ha.spectrumRestricts.cfc_eq_restrict (f := Complex.reCLM)
Complex.isometry_ofReal.isUniformEmbedding ha ha.isStarNormal f
end RealEqComplex
section RealEqComplexNonUnital
variable {A : Type*} [TopologicalSpace A] [NonUnitalRing A] [StarRing A] [Module β A]
[IsScalarTower β A A] [SMulCommClass β A A] [T2Space A]
[NonUnitalContinuousFunctionalCalculus β A IsStarNormal]
lemma cfcβHom_real_eq_restrict {a : A} (ha : IsSelfAdjoint a) :
cfcβHom ha = (ha.quasispectrumRestricts.2).nonUnitalStarAlgHom (cfcβHom ha.isStarNormal)
(R := β) (S := β) (f := Complex.reCLM) :=
ha.quasispectrumRestricts.2.cfcβHom_eq_restrict _ Complex.isometry_ofReal.isUniformEmbedding
ha ha.isStarNormal
lemma cfcβ_real_eq_complex {a : A} (f : β β β) (ha : IsSelfAdjoint a := by cfc_tac) :
cfcβ f a = cfcβ (fun x β¦ f x.re : β β β) a := by
replace ha : IsSelfAdjoint a := ha -- hack to avoid issues caused by autoParam
exact ha.quasispectrumRestricts.2.cfcβ_eq_restrict (f := Complex.reCLM)
Complex.isometry_ofReal.isUniformEmbedding ha ha.isStarNormal f
end RealEqComplexNonUnital
section NNRealEqReal
open NNReal
variable {A : Type*} [TopologicalSpace A] [Ring A] [PartialOrder A] [StarRing A]
[StarOrderedRing A] [Algebra β A] [IsTopologicalRing A] [T2Space A]
[ContinuousFunctionalCalculus β A IsSelfAdjoint]
[NonnegSpectrumClass β A]
lemma cfcHom_nnreal_eq_restrict {a : A} (ha : 0 β€ a) :
cfcHom ha = (SpectrumRestricts.nnreal_of_nonneg ha).starAlgHom
(cfcHom (IsSelfAdjoint.of_nonneg ha)) := by
apply (SpectrumRestricts.nnreal_of_nonneg ha).cfcHom_eq_restrict _ isUniformEmbedding_subtype_val
lemma cfc_nnreal_eq_real {a : A} (f : ββ₯0 β ββ₯0) (ha : 0 β€ a := by cfc_tac) :
cfc f a = cfc (fun x β¦ f x.toNNReal : β β β) a := by
replace ha : 0 β€ a := ha -- hack to avoid issues caused by autoParam
apply (SpectrumRestricts.nnreal_of_nonneg ha).cfc_eq_restrict _
isUniformEmbedding_subtype_val ha (.of_nonneg ha)
end NNRealEqReal
section NNRealEqRealNonUnital
open NNReal
variable {A : Type*} [TopologicalSpace A] [NonUnitalRing A] [PartialOrder A] [StarRing A]
[StarOrderedRing A] [Module β A] [IsTopologicalRing A] [IsScalarTower β A A] [SMulCommClass β A A]
[T2Space A] [NonUnitalContinuousFunctionalCalculus β A IsSelfAdjoint]
[NonnegSpectrumClass β A]
lemma cfcβHom_nnreal_eq_restrict {a : A} (ha : 0 β€ a) :
cfcβHom ha = (QuasispectrumRestricts.nnreal_of_nonneg ha).nonUnitalStarAlgHom
(cfcβHom (IsSelfAdjoint.of_nonneg ha)) := by
apply (QuasispectrumRestricts.nnreal_of_nonneg ha).cfcβHom_eq_restrict _
isUniformEmbedding_subtype_val
lemma cfcβ_nnreal_eq_real {a : A} (f : ββ₯0 β ββ₯0) (ha : 0 β€ a := by cfc_tac) :
cfcβ f a = cfcβ (fun x β¦ f x.toNNReal : β β β) a := by
replace ha : 0 β€ a := ha -- hack to avoid issues caused by autoParam
apply (QuasispectrumRestricts.nnreal_of_nonneg ha).cfcβ_eq_restrict _
isUniformEmbedding_subtype_val ha (.of_nonneg ha)
end NNRealEqRealNonUnital
end
|
FormalMultilinearSeries.lean
|
/-
Copyright (c) 2019 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.NormedSpace.Multilinear.Curry
/-!
# Formal multilinear series
In this file we define `FormalMultilinearSeries π E F` to be a family of `n`-multilinear maps for
all `n`, designed to model the sequence of derivatives of a function. In other files we use this
notion to define `C^n` functions (called `contDiff` in `mathlib`) and analytic functions.
## Notations
We use the notation `E [Γn]βL[π] F` for the space of continuous multilinear maps on `E^n` with
values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives.
## Tags
multilinear, formal series
-/
noncomputable section
open Set Fin Topology
universe u u' v w x y
variable {π : Type u} {π' : Type u'} {E : Type v} {F : Type w} {G : Type x} {H : Type y}
section
variable [Semiring π]
[AddCommMonoid E] [Module π E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousConstSMul π E]
[AddCommMonoid F] [Module π F] [TopologicalSpace F] [ContinuousAdd F] [ContinuousConstSMul π F]
[AddCommMonoid G] [Module π G] [TopologicalSpace G] [ContinuousAdd G] [ContinuousConstSMul π G]
[AddCommMonoid H] [Module π H] [TopologicalSpace H] [ContinuousAdd H] [ContinuousConstSMul π H]
/-- A formal multilinear series over a field `π`, from `E` to `F`, is given by a family of
multilinear maps from `E^n` to `F` for all `n`. -/
@[nolint unusedArguments]
def FormalMultilinearSeries (π : Type*) (E : Type*) (F : Type*) [Semiring π] [AddCommMonoid E]
[Module π E] [TopologicalSpace E] [ContinuousAdd E] [ContinuousConstSMul π E]
[AddCommMonoid F] [Module π F] [TopologicalSpace F] [ContinuousAdd F]
[ContinuousConstSMul π F] :=
β n : β, E[Γn]βL[π] F
deriving AddCommMonoid, Inhabited
section Module
instance (π') [Semiring π'] [Module π' F] [ContinuousConstSMul π' F] [SMulCommClass π π' F] :
Module π' (FormalMultilinearSeries π E F) :=
inferInstanceAs <| Module π' <| β n : β, E[Γn]βL[π] F
end Module
namespace FormalMultilinearSeries
@[simp]
theorem zero_apply (n : β) : (0 : FormalMultilinearSeries π E F) n = 0 := rfl
@[simp]
theorem add_apply (p q : FormalMultilinearSeries π E F) (n : β) : (p + q) n = p n + q n := rfl
@[simp]
theorem smul_apply [Semiring π'] [Module π' F] [ContinuousConstSMul π' F] [SMulCommClass π π' F]
(f : FormalMultilinearSeries π E F) (n : β) (a : π') : (a β’ f) n = a β’ f n := rfl
@[ext]
protected theorem ext {p q : FormalMultilinearSeries π E F} (h : β n, p n = q n) : p = q :=
funext h
protected theorem ne_iff {p q : FormalMultilinearSeries π E F} : p β q β β n, p n β q n :=
Function.ne_iff
/-- Cartesian product of two formal multilinear series (with the same field `π` and the same source
space, but possibly different target spaces). -/
def prod (p : FormalMultilinearSeries π E F) (q : FormalMultilinearSeries π E G) :
FormalMultilinearSeries π E (F Γ G)
| n => (p n).prod (q n)
/-- Product of formal multilinear series (with the same field `π` and the same source
space, but possibly different target spaces). -/
@[simp] def pi {ΞΉ : Type*} {F : ΞΉ β Type*}
[β i, AddCommGroup (F i)] [β i, Module π (F i)] [β i, TopologicalSpace (F i)]
[β i, IsTopologicalAddGroup (F i)] [β i, ContinuousConstSMul π (F i)]
(p : Ξ i, FormalMultilinearSeries π E (F i)) :
FormalMultilinearSeries π E (Ξ i, F i)
| n => ContinuousMultilinearMap.pi (fun i β¦ p i n)
/-- Killing the zeroth coefficient in a formal multilinear series -/
def removeZero (p : FormalMultilinearSeries π E F) : FormalMultilinearSeries π E F
| 0 => 0
| n + 1 => p (n + 1)
@[simp]
theorem removeZero_coeff_zero (p : FormalMultilinearSeries π E F) : p.removeZero 0 = 0 :=
rfl
@[simp]
theorem removeZero_coeff_succ (p : FormalMultilinearSeries π E F) (n : β) :
p.removeZero (n + 1) = p (n + 1) :=
rfl
theorem removeZero_of_pos (p : FormalMultilinearSeries π E F) {n : β} (h : 0 < n) :
p.removeZero n = p n := by
rw [β Nat.succ_pred_eq_of_pos h]
rfl
/-- Convenience congruence lemma stating in a dependent setting that, if the arguments to a formal
multilinear series are equal, then the values are also equal. -/
theorem congr (p : FormalMultilinearSeries π E F) {m n : β} {v : Fin m β E} {w : Fin n β E}
(h1 : m = n) (h2 : β (i : β) (him : i < m) (hin : i < n), v β¨i, himβ© = w β¨i, hinβ©) :
p m v = p n w := by
subst n
congr with β¨i, hiβ©
exact h2 i hi hi
lemma congr_zero (p : FormalMultilinearSeries π E F) {k l : β} (h : k = l) (h' : p k = 0) :
p l = 0 := by
subst h; exact h'
/-- Composing each term `pβ` in a formal multilinear series with `(u, ..., u)` where `u` is a fixed
continuous linear map, gives a new formal multilinear series `p.compContinuousLinearMap u`. -/
def compContinuousLinearMap (p : FormalMultilinearSeries π F G) (u : E βL[π] F) :
FormalMultilinearSeries π E G := fun n => (p n).compContinuousLinearMap fun _ : Fin n => u
@[simp]
theorem compContinuousLinearMap_apply (p : FormalMultilinearSeries π F G) (u : E βL[π] F) (n : β)
(v : Fin n β E) : (p.compContinuousLinearMap u) n v = p n (u β v) :=
rfl
@[simp]
theorem compContinuousLinearMap_id (p : FormalMultilinearSeries π E F) :
p.compContinuousLinearMap (.id _ _) = p :=
rfl
theorem compContinuousLinearMap_comp (p : FormalMultilinearSeries π G H) (uβ : F βL[π] G)
(uβ : E βL[π] F) :
(p.compContinuousLinearMap uβ).compContinuousLinearMap uβ =
p.compContinuousLinearMap (uβ.comp uβ) :=
rfl
variable (π) [Semiring π'] [SMul π π']
variable [Module π' E] [ContinuousConstSMul π' E] [IsScalarTower π π' E]
variable [Module π' F] [ContinuousConstSMul π' F] [IsScalarTower π π' F]
/-- Reinterpret a formal `π'`-multilinear series as a formal `π`-multilinear series. -/
@[simp]
protected def restrictScalars (p : FormalMultilinearSeries π' E F) :
FormalMultilinearSeries π E F := fun n => (p n).restrictScalars π
end FormalMultilinearSeries
end
namespace FormalMultilinearSeries
variable [Ring π] [AddCommGroup E] [Module π E] [TopologicalSpace E] [IsTopologicalAddGroup E]
[ContinuousConstSMul π E] [AddCommGroup F] [Module π F] [TopologicalSpace F]
[IsTopologicalAddGroup F] [ContinuousConstSMul π F]
instance : AddCommGroup (FormalMultilinearSeries π E F) :=
inferInstanceAs <| AddCommGroup <| β n : β, E[Γn]βL[π] F
@[simp]
theorem neg_apply (f : FormalMultilinearSeries π E F) (n : β) : (-f) n = - f n := rfl
@[simp]
theorem sub_apply (f g : FormalMultilinearSeries π E F) (n : β) : (f - g) n = f n - g n := rfl
end FormalMultilinearSeries
namespace FormalMultilinearSeries
variable [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E] [NormedAddCommGroup F]
[NormedSpace π F]
variable (p : FormalMultilinearSeries π E F)
/-- Forgetting the zeroth term in a formal multilinear series, and interpreting the following terms
as multilinear maps into `E βL[π] F`. If `p` is the Taylor series (`HasFTaylorSeriesUpTo`) of a
function, then `p.shift` is the Taylor series of the derivative of the function. Note that the
`p.sum` of a Taylor series `p` does not give the original function; for a formal multilinear
series that sums to the derivative of `p.sum`, see `HasFPowerSeriesOnBall.fderiv`. -/
def shift : FormalMultilinearSeries π E (E βL[π] F) := fun n => (p n.succ).curryRight
/-- Adding a zeroth term to a formal multilinear series taking values in `E βL[π] F`. This
corresponds to starting from a Taylor series (`HasFTaylorSeriesUpTo`) for the derivative of a
function, and building a Taylor series for the function itself. -/
def unshift (q : FormalMultilinearSeries π E (E βL[π] F)) (z : F) : FormalMultilinearSeries π E F
| 0 => (continuousMultilinearCurryFin0 π E F).symm z
| n + 1 => (continuousMultilinearCurryRightEquiv' π n E F).symm (q n)
theorem unshift_shift {p : FormalMultilinearSeries π E (E βL[π] F)} {z : F} :
(p.unshift z).shift = p := by
ext1 n
simp [shift, unshift]
exact LinearIsometryEquiv.apply_symm_apply (continuousMultilinearCurryRightEquiv' π n E F) (p n)
end FormalMultilinearSeries
section
variable [Semiring π] [AddCommMonoid E] [Module π E] [TopologicalSpace E] [ContinuousAdd E]
[ContinuousConstSMul π E] [AddCommMonoid F] [Module π F] [TopologicalSpace F]
[ContinuousAdd F] [ContinuousConstSMul π F] [AddCommMonoid G] [Module π G]
[TopologicalSpace G] [ContinuousAdd G] [ContinuousConstSMul π G]
namespace ContinuousLinearMap
/-- Composing each term `pβ` in a formal multilinear series with a continuous linear map `f` on the
left gives a new formal multilinear series `f.compFormalMultilinearSeries p` whose general term
is `f β pβ`. -/
def compFormalMultilinearSeries (f : F βL[π] G) (p : FormalMultilinearSeries π E F) :
FormalMultilinearSeries π E G := fun n => f.compContinuousMultilinearMap (p n)
@[simp]
theorem compFormalMultilinearSeries_apply (f : F βL[π] G) (p : FormalMultilinearSeries π E F)
(n : β) : (f.compFormalMultilinearSeries p) n = f.compContinuousMultilinearMap (p n) :=
rfl
theorem compFormalMultilinearSeries_apply' (f : F βL[π] G) (p : FormalMultilinearSeries π E F)
(n : β) (v : Fin n β E) : (f.compFormalMultilinearSeries p) n v = f (p n v) :=
rfl
end ContinuousLinearMap
namespace ContinuousMultilinearMap
variable {ΞΉ : Type*} {E : ΞΉ β Type*} [β i, AddCommGroup (E i)] [β i, Module π (E i)]
[β i, TopologicalSpace (E i)] [β i, IsTopologicalAddGroup (E i)]
[β i, ContinuousConstSMul π (E i)] [Fintype ΞΉ] (f : ContinuousMultilinearMap π E F)
/-- Realize a ContinuousMultilinearMap on `β i : ΞΉ, E i` as the evaluation of a
FormalMultilinearSeries by choosing an arbitrary identification `ΞΉ β Fin (Fintype.card ΞΉ)`. -/
noncomputable def toFormalMultilinearSeries : FormalMultilinearSeries π (β i, E i) F :=
fun n β¦ if h : Fintype.card ΞΉ = n then
(f.compContinuousLinearMap .proj).domDomCongr (Fintype.equivFinOfCardEq h)
else 0
end ContinuousMultilinearMap
end
namespace FormalMultilinearSeries
section Order
variable [Semiring π] {n : β} [AddCommMonoid E] [Module π E] [TopologicalSpace E]
[ContinuousAdd E] [ContinuousConstSMul π E] [AddCommMonoid F] [Module π F]
[TopologicalSpace F] [ContinuousAdd F] [ContinuousConstSMul π F]
{p : FormalMultilinearSeries π E F}
/-- The index of the first non-zero coefficient in `p` (or `0` if all coefficients are zero). This
is the order of the isolated zero of an analytic function `f` at a point if `p` is the Taylor
series of `f` at that point. -/
noncomputable def order (p : FormalMultilinearSeries π E F) : β :=
sInf { n | p n β 0 }
@[simp]
theorem order_zero : (0 : FormalMultilinearSeries π E F).order = 0 := by simp [order]
theorem ne_zero_of_order_ne_zero (hp : p.order β 0) : p β 0 := fun h => by simp [h] at hp
theorem order_eq_find [DecidablePred fun n => p n β 0] (hp : β n, p n β 0) :
p.order = Nat.find hp := by convert Nat.sInf_def hp
theorem order_eq_find' [DecidablePred fun n => p n β 0] (hp : p β 0) :
p.order = Nat.find (FormalMultilinearSeries.ne_iff.mp hp) :=
order_eq_find _
theorem order_eq_zero_iff' : p.order = 0 β p = 0 β¨ p 0 β 0 := by
simpa [order, Nat.sInf_eq_zero, FormalMultilinearSeries.ext_iff, eq_empty_iff_forall_notMem]
using or_comm
theorem order_eq_zero_iff (hp : p β 0) : p.order = 0 β p 0 β 0 := by
simp [order_eq_zero_iff', hp]
theorem apply_order_ne_zero (hp : p β 0) : p p.order β 0 :=
Nat.sInf_mem (FormalMultilinearSeries.ne_iff.1 hp)
theorem apply_order_ne_zero' (hp : p.order β 0) : p p.order β 0 :=
apply_order_ne_zero (ne_zero_of_order_ne_zero hp)
theorem apply_eq_zero_of_lt_order (hp : n < p.order) : p n = 0 :=
by_contra <| Nat.notMem_of_lt_sInf hp
end Order
section Coef
variable [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E]
{p : FormalMultilinearSeries π π E} {f : π β E} {n : β} {z : π} {y : Fin n β π}
/-- The `n`th coefficient of `p` when seen as a power series. -/
def coeff (p : FormalMultilinearSeries π π E) (n : β) : E :=
p n 1
theorem mkPiRing_coeff_eq (p : FormalMultilinearSeries π π E) (n : β) :
ContinuousMultilinearMap.mkPiRing π (Fin n) (p.coeff n) = p n :=
(p n).mkPiRing_apply_one_eq_self
@[simp]
theorem apply_eq_prod_smul_coeff : p n y = (β i, y i) β’ p.coeff n := by
convert (p n).toMultilinearMap.map_smul_univ y 1
simp only [Pi.one_apply, Algebra.id.smul_eq_mul, mul_one]
theorem coeff_eq_zero : p.coeff n = 0 β p n = 0 := by
rw [β mkPiRing_coeff_eq p, ContinuousMultilinearMap.mkPiRing_eq_zero_iff]
theorem apply_eq_pow_smul_coeff : (p n fun _ => z) = z ^ n β’ p.coeff n := by simp
@[simp]
theorem norm_apply_eq_norm_coef : βp nβ = βcoeff p nβ := by
rw [β mkPiRing_coeff_eq p, ContinuousMultilinearMap.norm_mkPiRing]
end Coef
section Fslope
variable [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E]
{p : FormalMultilinearSeries π π E} {n : β}
/-- The formal counterpart of `dslope`, corresponding to the expansion of `(f z - f 0) / z`. If `f`
has `p` as a power series, then `dslope f` has `fslope p` as a power series. -/
noncomputable def fslope (p : FormalMultilinearSeries π π E) : FormalMultilinearSeries π π E :=
fun n => (p (n + 1)).curryLeft 1
@[simp]
theorem coeff_fslope : p.fslope.coeff n = p.coeff (n + 1) := by
simp only [fslope, coeff, ContinuousMultilinearMap.curryLeft_apply]
congr 1
exact Fin.cons_self_tail (fun _ => (1 : π))
@[simp]
theorem coeff_iterate_fslope (k n : β) : (fslope^[k] p).coeff n = p.coeff (n + k) := by
induction k generalizing p with
| zero => rfl
| succ k ih => simp [ih, add_assoc]
end Fslope
end FormalMultilinearSeries
section Const
/-- The formal multilinear series where all terms of positive degree are equal to zero, and the term
of degree zero is `c`. It is the power series expansion of the constant function equal to `c`
everywhere. -/
def constFormalMultilinearSeries (π : Type*) [NontriviallyNormedField π] (E : Type*)
[NormedAddCommGroup E] [NormedSpace π E] [ContinuousConstSMul π E] [IsTopologicalAddGroup E]
{F : Type*} [NormedAddCommGroup F] [IsTopologicalAddGroup F] [NormedSpace π F]
[ContinuousConstSMul π F] (c : F) : FormalMultilinearSeries π E F
| 0 => ContinuousMultilinearMap.uncurry0 _ _ c
| _ => 0
@[simp]
theorem constFormalMultilinearSeries_apply_zero [NontriviallyNormedField π] [NormedAddCommGroup E]
[NormedAddCommGroup F] [NormedSpace π E] [NormedSpace π F] {c : F} :
constFormalMultilinearSeries π E c 0 = ContinuousMultilinearMap.uncurry0 _ _ c :=
rfl
@[simp]
theorem constFormalMultilinearSeries_apply_succ [NontriviallyNormedField π] [NormedAddCommGroup E]
[NormedAddCommGroup F] [NormedSpace π E] [NormedSpace π F] {c : F} {n : β} :
constFormalMultilinearSeries π E c (n + 1) = 0 :=
rfl
theorem constFormalMultilinearSeries_apply_of_nonzero [NontriviallyNormedField π]
[NormedAddCommGroup E] [NormedAddCommGroup F] [NormedSpace π E] [NormedSpace π F] {c : F}
{n : β} (hn : n β 0) : constFormalMultilinearSeries π E c n = 0 :=
Nat.casesOn n (fun hn => (hn rfl).elim) (fun _ _ => rfl) hn
@[deprecated (since := "2025-06-23")]
alias constFormalMultilinearSeries_apply := constFormalMultilinearSeries_apply_of_nonzero
@[simp]
lemma constFormalMultilinearSeries_zero [NontriviallyNormedField π] [NormedAddCommGroup E]
[NormedAddCommGroup F] [NormedSpace π E] [NormedSpace π F] :
constFormalMultilinearSeries π E (0 : F) = 0 := by
ext n x
simp only [FormalMultilinearSeries.zero_apply, ContinuousMultilinearMap.zero_apply,
constFormalMultilinearSeries]
induction n
Β· simp only [ContinuousMultilinearMap.uncurry0_apply]
Β· simp only [constFormalMultilinearSeries.match_1.eq_2, ContinuousMultilinearMap.zero_apply]
@[simp]
lemma compContinuousLinearMap_zero [NontriviallyNormedField π]
[NormedAddCommGroup E] [NormedSpace π E]
[NormedAddCommGroup F] [NormedSpace π F]
[NormedAddCommGroup G] [NormedSpace π G]
(p : FormalMultilinearSeries π F G) :
p.compContinuousLinearMap (0 : E βL[π] F) = constFormalMultilinearSeries π E (p 0 0) := by
ext n v
cases n with
| zero =>
simp only [FormalMultilinearSeries.compContinuousLinearMap_apply, Matrix.zero_empty,
constFormalMultilinearSeries_apply_zero, ContinuousMultilinearMap.uncurry0_apply]
congr
apply Subsingleton.allEq
| succ =>
simp [ContinuousLinearMap.coe_zero']
end Const
section Linear
variable [NontriviallyNormedField π]
[NormedAddCommGroup E] [NormedSpace π E]
[NormedAddCommGroup F] [NormedSpace π F]
namespace ContinuousLinearMap
/-- Formal power series of a continuous linear map `f : E βL[π] F` at `x : E`:
`f y = f x + f (y - x)`. -/
def fpowerSeries (f : E βL[π] F) (x : E) : FormalMultilinearSeries π E F
| 0 => ContinuousMultilinearMap.uncurry0 π _ (f x)
| 1 => (continuousMultilinearCurryFin1 π E F).symm f
| _ => 0
@[simp]
theorem fpowerSeries_apply_zero (f : E βL[π] F) (x : E) :
f.fpowerSeries x 0 = ContinuousMultilinearMap.uncurry0 π _ (f x) :=
rfl
@[simp]
theorem fpowerSeries_apply_one (f : E βL[π] F) (x : E) :
f.fpowerSeries x 1 = (continuousMultilinearCurryFin1 π E F).symm f :=
rfl
@[simp]
theorem fpowerSeries_apply_add_two (f : E βL[π] F) (x : E) (n : β) : f.fpowerSeries x (n + 2) = 0 :=
rfl
end ContinuousLinearMap
end Linear
|
spectral.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat.
From mathcomp Require Import seq div fintype bigop ssralg finset fingroup zmodp.
From mathcomp Require Import poly polydiv order ssrnum matrix mxalgebra vector.
From mathcomp Require Import mxpoly mxred sesquilinear.
(******************************************************************************)
(* Spectral theory *)
(* *)
(* This file provides a formalization of Gram-Schmidt orthonormalization, *)
(* Schur decomposition, etc. *)
(* *)
(* M ^t* := M ^t conjC *)
(* Notation in scope sesquilinear_scope. *)
(* M \is unitarymx == M is a unitary matrix *)
(* M : 'M[C]_(m, n) with C : numClosedFieldType *)
(* M \is normalmx == M is a normal matrix *)
(* M : 'M[C]_n with C : numClosedFieldType *)
(* *)
(* dotmx u v == dot product *)
(* u and v are row vectors over a numClosedFieldType *)
(* Local notations: '[u, v] := dotmx u v, *)
(* '[u] := '[u, u] *)
(* proj_ortho Y := proj_mx <<U>>%MS U^!%MS *)
(* where U^! is a 1-orthogonal completement of U *)
(* schmidt A == Gram-Schmidt basis *)
(* A : 'M[C]_(m, n) *)
(* schmidt_complete V := col_mx (schmidt (row_base V)) *)
(* (schmidt (row_base V^!%MS)) *)
(* spectralmx A, spectral_diag A == (M,X) s.t. A = M^-1 *m diag_mx X *m M *)
(* A : 'M[C]_n *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory Order.Theory Num.Theory.
Local Open Scope ring_scope.
Local Open Scope sesquilinear_scope.
(* TODO: move? *)
Lemma eigenvalue_closed {C : numClosedFieldType} n (A : 'M[C]_n) : (n > 0)%N ->
exists a, eigenvalue A a.
Proof.
move=> n_gt0; have /closed_rootP [a rAa] : size (char_poly A) != 1%N.
by rewrite size_char_poly; case: (n) n_gt0.
by exists a; rewrite eigenvalue_root_char.
Qed.
(* TODO: move? *)
Lemma common_eigenvector {C : numClosedFieldType} n (As : seq 'M[C]_n) :
(n > 0)%N -> {in As &, forall A B, comm_mx A B} ->
exists2 v : 'rV_n, v != 0 & all (fun A => stablemx v A) As.
Proof.
move=> n_gt0 /all_comm_mxP; have [k sAsk] := ubnP (size As).
elim: k n n_gt0 As sAsk => [//|k IHk] n n_gt0 [|A As].
exists (const_mx 1) => //; apply/negP => /eqP/rowP/(_ (Ordinal n_gt0)).
by rewrite !mxE => /eqP; rewrite oner_eq0.
rewrite ltnS all_comm_mx_cons => sAsk /andP[].
move=> /allP/(_ _ _)/eqP/= A_comm /all_comm_mxP As_comm.
have [a a_eigen] := eigenvalue_closed A n_gt0.
have [] := IHk _ _ [seq restrictmx (eigenspace A a) B | B <- As].
- by rewrite lt0n mxrank_eq0.
- by rewrite size_map.
- apply/all_comm_mxP; move=> _ _ /= /mapP /= [B B_in ->] /mapP /= [B' B'_in ->].
rewrite -?conjmxM ?inE ?stablemx_row_base ?comm_mx_stable_eigenspace//;
by [rewrite As_comm | apply: As_comm | apply: A_comm].
move=> v vN0 /allP /= vP; exists (v *m (row_base (eigenspace A a))).
by rewrite mulmx_free_eq0 ?row_base_free.
apply/andP; split.
by apply/eigenvectorP; exists a; rewrite mulmx_sub // eq_row_base.
apply/allP => B B_in; rewrite -stablemx_restrict ?vP //.
by apply/mapP; exists B.
by rewrite comm_mx_stable_eigenspace //; exact: A_comm.
Qed.
(* TODO: move? *)
Lemma common_eigenvector2 {C : numClosedFieldType}n (A B : 'M[C]_n) :
(n > 0)%N -> A *m B = B *m A ->
exists2 v : 'rV_n, v != 0 & (stablemx v A) && (stablemx v B).
Proof.
move=> n_gt0 AB_comm; have [] := @common_eigenvector _ _ [:: A; B] n_gt0.
by move=> A' B'; rewrite !inE => /orP [] /eqP-> /orP [] /eqP->.
by move=> v v_neq0 /allP vP; exists v; rewrite ?vP ?(mem_head, in_cons, orbT).
Qed.
Notation "M ^t*" := (M ^t conjC) (at level 30) : sesquilinear_scope.
Notation realmx := (mxOver Num.real).
Lemma trmxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) : A ^t* ^t* = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
Section realmx.
Context {C : numClosedFieldType} {m n : nat}.
Implicit Types A B : 'M[C]_(m, n).
Lemma realmxC A : A \is a realmx -> A ^ conjC = A.
Proof.
by move=> ?; apply/matrixP => x y; rewrite mxE; exact/CrealP/mxOverP.
Qed.
Lemma realmxD A B : A \is a realmx -> B \is a realmx -> A + B \is a realmx.
Proof.
rewrite !qualifE/= => /'forall_forallP realA /'forall_forallP realB.
by apply/'forall_forallP => i j; rewrite mxE realD.
Qed.
Lemma Remx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Re _) = A}.
Proof.
move=> A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Re_rect // (mxOverP _ _).
Qed.
Lemma Immx_rect : {in realmx &, forall A B, (A + 'i *: B) ^ (@Im _) = B}.
Proof.
move=> /= A B Areal Breal; apply/matrixP=> i j; rewrite !mxE.
by rewrite Im_rect // (mxOverP _ _).
Qed.
Lemma eqmx_ReiIm A B A' B' :
A \is a realmx -> B \is a realmx -> A' \is a realmx -> B' \is a realmx ->
(A + 'i *: B) = (A' + 'i *: B') -> (A, B) = (A', B').
Proof.
move=> ARe BRe A'Im B'Im eqAB.
have /(congr1 (fun A => A ^ (@Im _))) := eqAB.
have /(congr1 (fun A => A ^ (@Re _))) := eqAB.
by rewrite !Remx_rect// !Immx_rect// => -> ->.
Qed.
End realmx.
Lemma realsym_hermsym {C : numClosedFieldType} {n} (A : 'M[C]_n) :
A \is symmetricmx -> A \is a realmx -> A \is hermsymmx.
Proof.
move=> Asym Areal; apply/is_hermitianmxP.
by rewrite (trmx_hermitian (HermitianMx Asym))/= !scale1r ?realmxC ?map_mx_id.
Qed.
Lemma real_similar {C : numClosedFieldType} {n} (A B : 'M[C]_n) :
similar_in unitmx A B ->
A \is a realmx -> B \is a realmx -> similar_in [predI realmx & unitmx] A B.
Proof.
case=> [P /=]; pose Pr := P ^ (@Re _); pose Pi := P ^ (@Im _).
have Pr_real : Pr \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Re.
have Pi_real : Pi \is a realmx by apply/mxOverP=> i j; rewrite !mxE Creal_Im.
pose Q x := P ^ (@Re _) + x *: P ^ (@Im _).
have -> : P = Q 'i by apply/matrixP=> i j; rewrite !mxE -Crect.
move=> Qi_unit eq_AP_PB Areal Breal.
pose p := \det (Pr ^ polyC + 'X *: Pi ^ polyC).
have horner_evaliC x : horner_eval (x : C) \o polyC =1 id := fun=> hornerC _ _.
have Qunit x : Q x \in unitmx = (p.[x] != 0).
rewrite /p -horner_evalE -det_map_mx map_mxD map_mxZ/= horner_evalE hornerX.
by rewrite -![(_ ^ polyC) ^ _]map_mx_comp !map_mx_id// unitmxE unitfE.
have p_neq0 : p != 0.
by move: Qi_unit; rewrite Qunit; apply: contra_neq => ->; rewrite hornerE.
have [a a_real rootNa] : exists2 a, a \is Num.real & ~~ root p a.
have rs_uniq : uniq [seq (i%:R : C) | i <- iota 0 (size p)].
by rewrite map_inj_uniq ?iota_uniq //; apply: mulrIn; rewrite oner_eq0.
have := contraNN (fun x => max_poly_roots p_neq0 x rs_uniq).
rewrite size_map size_iota ltnn => /(_ isT) /allPn[a a_in rootNpa].
by exists a => //; by move: a_in => /mapP [i _ ->]; rewrite realn.
exists (Q a).
rewrite inE Qunit rootNa andbT.
rewrite /Q/=.
by rewrite realmxD// mxOverZ.
apply/similarP; rewrite ?Qunit//; move: eq_AP_PB => /(similarP Qi_unit).
rewrite !mulmxDl !mulmxDr -!scalemxAr -!scalemxAl => /eqmx_ReiIm.
by rewrite !mxOverM// => /(_ isT isT isT isT) [-> ->].
Qed.
Section unitarymx.
Context {C : numClosedFieldType}.
Definition unitarymx {m n} := [qualify X : 'M[C]_(m, n) | X *m X ^t* == 1%:M].
Fact unitarymx_key m n : pred_key (@unitarymx m n). Proof. by []. Qed.
Canonical unitarymx_keyed m n := KeyedQualifier (unitarymx_key m n).
Lemma unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (M *m M^t* = 1%:M) (M \is unitarymx).
Proof. by apply: (iffP eqP). Qed.
Lemma mulmxtVK m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(n, m2)) :
B \is unitarymx -> A *m B *m B^t* = A.
Proof. by move=> B_unitary; rewrite -mulmxA (unitarymxP _) ?mulmx1. Qed.
Lemma unitarymx_unit n (M : 'M[C]_n) : M \is unitarymx -> M \in unitmx.
Proof. by move=> /unitarymxP /mulmx1_unit []. Qed.
Lemma invmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> invmx M = M^t*.
Proof.
move=> Munitary; apply: (@row_full_inj _ _ _ _ M).
by rewrite row_full_unit unitarymx_unit.
by rewrite mulmxV ?unitarymx_unit ?(unitarymxP _).
Qed.
Lemma mulmxKtV m1 m2 n (A : 'M[C]_(m1, n)) (B : 'M[C]_(m2, n)) :
B \is unitarymx -> m2 = n -> A *m B^t* *m B = A.
Proof.
move=> B_unitary m2E; case: _ / (esym m2E) in B B_unitary *.
by rewrite -invmx_unitary // mulmxKV //; exact: unitarymx_unit.
Qed.
Lemma mxrank_unitary m n (M : 'M[C]_(m, n)) : M \is unitarymx -> \rank M = m.
Proof.
rewrite qualifE => /eqP /(congr1 mxrank); rewrite mxrank1 => rkM.
apply/eqP; rewrite eqn_leq rank_leq_row /= -[X in (X <= _)%N]rkM.
by rewrite mxrankM_maxl.
Qed.
Lemma mul_unitarymx m n p (A : 'M[C]_(m, n)) (B : 'M[C]_(n, p)) :
A \is unitarymx -> B \is unitarymx -> A *m B \is unitarymx.
Proof.
move=> Aunitary Bunitary; apply/unitarymxP; rewrite trmx_mul map_mxM.
by rewrite mulmxA -[A *m _ *m _]mulmxA !(unitarymxP _, mulmx1).
Qed.
Lemma pinvmx_unitary n (M : 'M[C]_n) : M \is unitarymx -> pinvmx M = M^t*.
Proof. by move=> Munitary; rewrite pinvmxE ?unitarymx_unit// invmx_unitary. Qed.
Lemma conjymx n (P M : 'M[C]_n) : P \is unitarymx -> conjmx P M = P *m M *m P^t*.
Proof. by move=> Munitary; rewrite conjumx ?invmx_unitary ?unitarymx_unit. Qed.
Lemma trmx_unitary n (M : 'M[C]_n) : (M ^T \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_trmx -trmx_mul.
by rewrite -trmx1 => /trmx_inj /mulmx1C->; rewrite trmx1.
by move=> /mulmx1C->; rewrite trmx1.
Qed.
Lemma conjC_unitary m n (M : 'M[C]_(m, n)) :
(M ^ conjC \is unitarymx) = (M \is unitarymx).
Proof.
apply/unitarymxP/unitarymxP; rewrite -?map_mxM ?map_trmx; last first.
by move=> ->; rewrite map_mx1.
by rewrite -[1%:M](map_mx1 conjC) => /map_mx_inj ->; rewrite map_mx1.
Qed.
Lemma trmxC_unitary n (M : 'M[C]_n) : (M ^t* \is unitarymx) = (M \is unitarymx).
Proof. by rewrite conjC_unitary trmx_unitary. Qed.
End unitarymx.
Section normalmx.
Context {C : numClosedFieldType} {n : nat}.
Definition normalmx := [qualify M : 'M[C]_n | M *m M ^t* == M ^t* *m M].
Fact normalmx_key : pred_key normalmx. Proof. by []. Qed.
Canonical normalmx_keyed := KeyedQualifier normalmx_key.
Lemma normalmxP {M : 'M[C]_n} :
reflect (M *m M ^t* = M ^t* *m M) (M \is normalmx).
Proof. exact: eqP. Qed.
Lemma hermitian_normalmx (A : 'M[C]_n) : A \is hermsymmx -> A \is normalmx.
Proof.
move=> Ahermi; apply/normalmxP.
by rewrite (trmx_hermitian (HermitianMx Ahermi)) scale1r map_mxCK.
Qed.
Lemma symmetric_normalmx (A : 'M[C]_n) : A \is symmetricmx ->
A \is a realmx -> A \is normalmx.
Proof. by move=> Asym Areal; rewrite hermitian_normalmx// realsym_hermsym. Qed.
End normalmx.
Section Spectral.
Variable (C : numClosedFieldType).
Set Default Proof Using "C".
Local Notation dotmx_def := (form_of_matrix (@conjC _) 1%:M).
Definition dotmx n (u v : 'rV[C]_n) := dotmx_def u%R v%R.
(*
TODO: bug report
we were expecting
HB.instance Definition _ n := Bilinear.on (@dotmx n).
to be sufficient to equip dotmx with the bilinear structure
but needed to use .copy in the end as in:
*)
HB.instance Definition _ n := Bilinear.copy (@dotmx n) dotmx_def.
Local Notation "''[' u , v ]" := (dotmx u v) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
HB.instance Definition _ n := Hermitian.copy (@dotmx n) dotmx_def.
Lemma dotmxE n (u v : 'rV[C]_n) : '[u, v] = ( u *m v ^t* ) 0 0.
Proof. by rewrite /dotmx /form_of_matrix mulmx1 /= trace_mx11. Qed.
Lemma row_unitarymxP m n {M : 'M[C]_(m, n)} :
reflect (forall i j, '[row i M, row j M] = (i == j)%:R) (M \is unitarymx).
Proof.
apply: (iffP eqP) => [Mo i j|Mo].
have /matrixP/(_ i j) := Mo; rewrite !mxE => <-.
by rewrite dotmxE !mxE; apply: eq_bigr => /= k _; rewrite !mxE.
apply/matrixP=> i j; rewrite !mxE; have := Mo i j; rewrite dotmxE !mxE => <-.
by apply: eq_bigr => /= k _; rewrite !mxE.
Qed.
Fact dotmx_is_dotmx n (u : 'rV[C]_n) : u != 0 -> 0 < '[u].
Proof.
move=> u_neq0; rewrite dotmxE mxE.
suff /existsP[i ui_neq0] : [exists i, u 0 i != 0].
rewrite (bigD1 i) //= ltr_wpDr// ?sumr_ge0// ?mxE ?mul_conjC_gt0//.
by move=> j _; rewrite !mxE mul_conjC_ge0.
apply: contraNT u_neq0; rewrite negb_exists => /forallP uNN0.
by apply/eqP/rowP=> j; rewrite mxE; apply/eqP; rewrite -[_ == _]negbK uNN0.
Qed.
HB.instance Definition _ n := isDotProduct.Build _ _ (@dotmx n)
(@dotmx_is_dotmx n).
Local Notation "B ^!" :=
(orthomx (@conjC C) (mx_of_hermitian (hermitian1mx _)) B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B^!)%MS : bool_scope.
Lemma orthomx1E m n p (A : 'M[C]_(m, n)) (B : 'M_(p, n)) :
(A '_|_ B)%MS = (A *m B^t* == 0).
Proof. by apply/sub_kermxP/eqP; rewrite !mul1mx. Qed.
Lemma orthomx1P m n p {A : 'M[C]_(m, n)} {B : 'M_(p, n)} :
reflect (A *m B^t* = 0) (A '_|_ B).
Proof. by rewrite orthomx1E; exact/eqP. Qed.
Lemma orthomx_disj n p q (A : 'M[C]_(p, n)) (B :'M_(q, n)) :
A '_|_ B -> (A :&: B = 0)%MS.
Proof.
move=> nAB; apply/eqP/rowV0Pn => [[v]]; rewrite sub_capmx => /andP [vA vB].
apply/negP; rewrite negbK.
by rewrite -(dnorm_eq0 (@dotmx n)) -orthomxE (orthomxP _ _ _ nAB).
Qed.
Lemma orthomx_ortho_disj n p (A : 'M[C]_(p, n)) : (A :&: A^! = 0)%MS.
Proof. exact/orthomx_disj/ortho_mx_ortho. Qed.
Lemma rank_ortho p n (A : 'M[C]_(p, n)) : \rank A^! = (n - \rank A)%N.
Proof. by rewrite mxrank_ker mul1mx mxrank_map mxrank_tr. Qed.
Lemma add_rank_ortho p n (A : 'M[C]_(p, n)) : (\rank A + \rank A^!)%N = n.
Proof. by rewrite rank_ortho subnKC ?rank_leq_col. Qed.
Lemma addsmx_ortho p n (A : 'M[C]_(p, n)) : (A + A^! :=: 1%:M)%MS.
Proof.
apply/eqmxP/andP; rewrite submx1; split=> //.
rewrite -mxrank_leqif_sup ?submx1 ?mxrank1 ?(mxdirectP _) /= ?add_rank_ortho //.
by rewrite mxdirect_addsE /= ?mxdirectE ?orthomx_ortho_disj !eqxx.
Qed.
Lemma ortho_id p n (A : 'M[C]_(p, n)) : (A^!^! :=: A)%MS.
Proof.
apply/eqmx_sym/eqmxP.
by rewrite -mxrank_leqif_eq 1?orthomx_sym // !rank_ortho subKn // ?rank_leq_col.
Qed.
Lemma submx_ortho p m n (U : 'M[C]_(p, n)) (V : 'M_(m, n)) :
(U^! <= V^!)%MS = (V <= U)%MS.
Proof. by rewrite orthomx_sym ortho_id. Qed.
Definition proj_ortho p n (U : 'M[C]_(p, n)) := proj_mx <<U>>%MS U^!%MS.
Lemma sub_adds_genmx_ortho (p m n : nat) (U : 'M[C]_(p, n)) (W : 'M_(m, n)) :
(W <= <<U>> + U^!)%MS.
Proof.
by rewrite !(adds_eqmx (genmxE _) (eqmx_refl _)) addsmx_ortho submx1.
Qed.
Local Hint Resolve sub_adds_genmx_ortho : core.
Lemma cap_genmx_ortho p n (U : 'M[C]_(p, n)) : (<<U>> :&: U^!)%MS = 0.
Proof.
apply/eqmx0P; rewrite !(cap_eqmx (genmxE _) (eqmx_refl _)).
by rewrite orthomx_ortho_disj; exact/eqmx0P.
Qed.
Local Hint Resolve cap_genmx_ortho : core.
Lemma proj_ortho_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W *m proj_ortho U <= U)%MS.
Proof. by rewrite (submx_trans (proj_mx_sub _ _ _)) // genmxE. Qed.
Lemma proj_ortho_compl_sub p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W - W *m proj_ortho U <= U^!)%MS.
Proof. by rewrite proj_mx_compl_sub // addsmx_ortho submx1. Qed.
Lemma proj_ortho_id p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U)%MS -> W *m proj_ortho U = W.
Proof. by move=> WU; rewrite proj_mx_id ?genmxE. Qed.
Lemma proj_ortho_0 p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
(W <= U^!)%MS -> W *m proj_ortho U = 0.
Proof. by move=> WUo; rewrite proj_mx_0. Qed.
Lemma add_proj_ortho p m n (U : 'M_(p, n)) (W : 'M_(m, n)) :
W *m proj_ortho U + W *m proj_ortho U^!%MS = W.
Proof.
rewrite -[W in LHS](@add_proj_mx _ _ _ <<U>>%MS U^!%MS W)//.
rewrite !mulmxDl proj_ortho_id ?proj_ortho_sub //.
rewrite proj_ortho_0 ?proj_mx_sub // addr0.
rewrite proj_ortho_0 ?ortho_id ?proj_ortho_sub // add0r.
by rewrite proj_ortho_id ?proj_mx_sub// add_proj_mx.
Qed.
Lemma proj_ortho_proj m n (U : 'M_(m, n)) : let P := proj_ortho U in P *m P = P.
Proof. by rewrite /= proj_mx_proj. Qed.
Lemma proj_orthoE p n (U : 'M_(p, n)) : (proj_ortho U :=: U)%MS.
Proof.
apply/eqmxP/andP; split; first by rewrite -proj_ortho_proj proj_ortho_sub.
by rewrite -[X in (X <= _)%MS](proj_ortho_id (submx_refl U)) mulmx_sub.
Qed.
Lemma orthomx_proj_mx_ortho p p' m m' n
(A : 'M_(p, n)) (A' : 'M_(p', n))
(W : 'M_(m, n)) (W' : 'M_(m', n)) :
A '_|_ A' -> W *m proj_ortho A '_|_ W' *m proj_ortho A'.
Proof.
rewrite orthomx_sym => An.
rewrite mulmx_sub // orthomx_sym (eqmx_ortho _ (proj_orthoE _)).
by rewrite (submx_trans _ An) // proj_ortho_sub.
Qed.
Lemma schmidt_subproof m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
exists2 B : 'M_(m, n), B \is unitarymx & [forall i : 'I_m,
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k B>>))%MS
&& ('[row i A, row i B] >= 0) ].
Proof.
elim: m A => [|m IHm].
exists (pid_mx n); first by rewrite qualifE !thinmx0.
by apply/forallP=> -[].
rewrite -addn1 => A leq_Sm_n.
have lemSm : (m <= m + 1)%N by rewrite addn1.
have ltmSm : (m < m + 1)%N by rewrite addn1.
have lemn : (m <= n)%N by rewrite ltnW // -addn1.
have [B Bortho] := IHm (usubmx A) lemn.
move=> /forallP /= subAB.
have [v /and4P [vBn v_neq0 dAv_ge0 dAsub]] :
exists v, [&& B '_|_ v, v != 0, '[dsubmx A, v] >= 0 & (dsubmx A <= B + v)%MS].
have := add_proj_ortho B (dsubmx A).
set BoSn := (_ *m proj_ortho _^!%MS) => pBE.
have [BoSn_eq0|BoSn_neq0] := eqVneq BoSn 0.
rewrite BoSn_eq0 addr0 in pBE.
have /rowV0Pn [v vBn v_neq0] : B^!%MS != 0.
rewrite -mxrank_eq0 rank_ortho -lt0n subn_gt0.
by rewrite mxrank_unitary // -addn1.
rewrite orthomx_sym in vBn.
exists v; rewrite vBn v_neq0 -pBE.
rewrite ['[_, _]](hermmx_eq0P _ _) ?lexx //=.
rewrite (submx_trans (proj_ortho_sub _ _)) //.
by rewrite -{1}[B]addr0 addmx_sub_adds ?sub0mx.
by rewrite (submx_trans _ vBn) // proj_ortho_sub.
pose c := (sqrtC '[BoSn])^-1; have c_gt0 : c > 0.
by rewrite invr_gt0 sqrtC_gt0 lt_def ?dnorm_eq0 ?dnorm_ge0 BoSn_neq0.
exists BoSn; apply/and4P; split => //.
- by rewrite orthomx_sym ?proj_ortho_sub // /gtr_eqF.
- rewrite -pBE linearDl //.
rewrite [X in X + '[_]](hermmx_eq0P _ _) ?add0r ?dnorm_ge0 //.
by rewrite orthomx_proj_mx_ortho // orthomx_sym.
- by rewrite -pBE addmx_sub_adds // proj_ortho_sub.
wlog nv_eq1 : v vBn v_neq0 dAv_ge0 dAsub / '[v] = 1.
pose c := (sqrtC '[v])^-1.
have c_gt0 : c > 0 by rewrite invr_gt0 sqrtC_gt0 ?dnorm_gt0.
have [c_ge0 c_eq0F] := (ltW c_gt0, gt_eqF c_gt0).
move=> /(_ (c *: v)); apply.
- by rewrite orthomxZ ?c_eq0F.
- by rewrite scaler_eq0 c_eq0F.
- by rewrite linearZr mulr_ge0 // conjC_ge0.
- by rewrite (submx_trans dAsub) // addsmxS // eqmx_scale // c_eq0F.
- rewrite dnormZ normfV ger0_norm ?sqrtC_ge0 ?dnorm_ge0 //.
by rewrite exprVn rootCK ?mulVf // dnorm_eq0.
exists (col_mx B v).
apply/row_unitarymxP => i j.
case: (split_ordP i) (split_ordP j) => [] i' -> [] j' ->;
rewrite eq_shift ?(rowKu, rowKd, row_id, ord1) -?val_eqE /=
?(row_unitarymxP _) //= ?addn0.
by rewrite ['[_, _]](hermmx_eq0P _ _)//= (submx_trans _ vBn)// row_sub.
rewrite ['[_, _]](hermmx_eq0P _ _)//= orthomx_sym (submx_trans _ vBn) //.
exact: row_sub.
apply/forallP => i; case: (split_ordP i) => j -> /=.
have /andP [sABj dot_gt0] := subAB j.
rewrite rowKu -row_usubmx (submx_trans sABj) //=.
rewrite (eq_rect _ (submx _) (submx_refl _)) //.
rewrite [in RHS](reindex (lshift 1)) /=.
by apply: eq_bigr=> k k_le; rewrite rowKu.
exists (fun k => insubd j k) => k; rewrite inE /= => le_kj;
by apply/val_inj; rewrite /= insubdK // -topredE /= (leq_ltn_trans le_kj).
rewrite rowKd -row_dsubmx !row_id ord1 ?dAv_ge0 ?andbT {j} addn0.
rewrite (bigD1 (rshift _ ord0)) /= ?addn0 ?rowKd ?row_id // addsmxC.
rewrite (submx_trans dAsub) // addsmxS ?genmxE //.
apply/row_subP => j; apply/(sumsmx_sup (lshift _ j)) => //=.
by rewrite ltnW ?ltn_ord //= -val_eqE /= addn0 ltn_eqF.
by rewrite rowKu genmxE.
Qed.
Definition schmidt m n (A : 'M[C]_(m, n)) :=
if (m <= n)%N =P true is ReflectT le_mn
then projT1 (sig2_eqW (schmidt_subproof A le_mn))
else A.
Lemma schmidt_unitarymx m n (A : 'M[C]_(m, n)) : (m <= n)%N ->
schmidt A \is unitarymx.
Proof. by rewrite /schmidt; case: eqP => // ?; case: sig2_eqW. Qed.
Hint Resolve schmidt_unitarymx : core.
Lemma row_schmidt_sub m n (A : 'M[C]_(m, n)) i :
(row i A <= (\sum_(k < m | (k <= i)%N) <<row k (schmidt A)>>))%MS.
Proof.
rewrite /schmidt; case: eqP => // ?.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
by apply/(sumsmx_sup i) => //; rewrite genmxE.
Qed.
Lemma form1_row_schmidt m n (A : 'M[C]_(m, n)) i :
'[row i A, row i (schmidt A)] >= 0.
Proof.
rewrite /schmidt; case: eqP => // ?; rewrite ?dnorm_ge0 //.
by case: sig2_eqW => ? ? /= /forallP /(_ i) /andP[].
Qed.
Lemma schmidt_sub m n (A : 'M[C]_(m, n)) : (A <= schmidt A)%MS.
Proof.
apply/row_subP => i; rewrite (submx_trans (row_schmidt_sub _ _)) //.
by apply/sumsmx_subP => /= j le_ji; rewrite genmxE row_sub.
Qed.
Hint Resolve schmidt_sub : core.
Lemma eqmx_schmidt_full m n (A : 'M[C]_(m, n)) :
row_full A -> (schmidt A :=: A)%MS.
Proof.
move=> Afull; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans n) ?rank_leq_col ?col_leq_rank.
Qed.
Lemma eqmx_schmidt_free m n (A : 'M[C]_(m, n)) :
row_free A -> (schmidt A :=: A)%MS.
Proof.
move=> Afree; apply/eqmx_sym/eqmxP; rewrite -mxrank_leqif_eq //.
by rewrite eqn_leq mxrankS //= (@leq_trans m) ?rank_leq_row // ?row_leq_rank.
Qed.
Definition schmidt_complete m n (V : 'M[C]_(m, n)) :=
col_mx (schmidt (row_base V)) (schmidt (row_base V^!%MS)).
Lemma schmidt_complete_unitarymx m n (V : 'M[C]_(m, n)) :
schmidt_complete V \is unitarymx.
Proof.
apply/unitarymxP; rewrite tr_col_mx map_row_mx mul_col_row.
rewrite !(unitarymxP _) ?schmidt_unitarymx ?rank_leq_col //.
move=> [:nsV]; rewrite !(orthomx1P _) -?scalar_mx_block //;
[abstract: nsV|]; last by rewrite orthomx_sym.
by do 2!rewrite eqmx_schmidt_free ?eq_row_base ?row_base_free // orthomx_sym.
Qed.
Lemma cotrigonalization n (As : seq 'M[C]_n) :
{in As &, forall A B, comm_mx A B} ->
cotrigonalizable_in (@unitarymx C n n) As.
Proof.
elim: n {-2}n (leqnn n) As => [|N IHN] n.
rewrite leqn0 => /eqP n_eq0.
exists 1%:M; first by rewrite qualifE mul1mx trmx1 map_mx1.
apply/allP => ? ?; apply/is_trig_mxP => i j.
by suff: False by []; move: i; rewrite n_eq0 => -[].
rewrite leq_eqVlt => /predU1P [n_eqSN|/IHN//].
have /andP [n_gt0 n_small] : (n > 0)%N && (n - 1 <= N)%N.
by rewrite n_eqSN /= subn1.
move=> As As_comm;
have [v vN0 /allP /= vP] := common_eigenvector n_gt0 As_comm.
suff: exists2 P : 'M[C]_(\rank v + \rank v^!, n), P \is unitarymx &
all (fun A => is_trig_mx (P *m A *m ( P^t* ))) As.
rewrite add_rank_ortho // => -[P P_unitary] /=; rewrite -invmx_unitary//.
by under eq_all do rewrite -conjumx ?unitarymx_unit//; exists P.
pose S := schmidt_complete v.
pose r A := S *m A *m S^t*.
have vSvo X : stablemx v X ->
schmidt (row_base v) *m X *m schmidt (row_base v^!%MS) ^t* = 0.
move=> /eigenvectorP [a v_in].
rewrite (eigenspaceP (_ : (_ <= _ a))%MS); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
rewrite -scalemxAl (orthomx1P _) ?scaler0 //.
by do 2!rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base // orthomx_sym.
have drrE X : drsubmx (r X) =
schmidt (row_base v^!%MS) *m X *m schmidt (row_base v^!%MS) ^t*.
by rewrite /r mul_col_mx tr_col_mx map_row_mx mul_col_row block_mxKdr.
have vSv X a : (v <= eigenspace X a)%MS ->
schmidt (row_base v) *m X *m schmidt (row_base v) ^t* = a%:M.
move=> vXa; rewrite (eigenspaceP (_ : (_ <= _ a)%MS)); last first.
by rewrite eqmx_schmidt_free ?row_base_free ?eq_row_base.
by rewrite -scalemxAl (unitarymxP _) ?scalemx1 ?schmidt_unitarymx ?rank_leq_col.
have [] := IHN _ _ [seq drsubmx (r A) | A <- As].
- by rewrite rank_ortho rank_rV vN0.
- move=> _ _ /mapP[/= A A_in ->] /mapP[/= B B_in ->].
have : (r A) *m (r B) = (r B) *m (r A).
rewrite /r !mulmxA !mulmxKtV // ?schmidt_complete_unitarymx //;
by rewrite ?add_rank_ortho // -![S *m _ *m _]mulmxA As_comm.
rewrite -[r A in X in X -> _]submxK -[r B in X in X -> _]submxK.
rewrite 2!mulmx_block => /eq_block_mx [_ _ _].
suff urr_eq0 X : X \in As -> ursubmx (r X) = 0.
by rewrite !urr_eq0 ?mulmx0 ?add0r.
rewrite /r /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !block_mxKur.
by move=> X_in; rewrite vSvo // vP.
move=> P' P'_unitary /allP /= P'P.
exists ((block_mx 1%:M 0 0 P') *m S).
rewrite mul_unitarymx ?schmidt_complete_unitarymx //.
apply/unitarymxP; rewrite tr_block_mx map_block_mx mulmx_block.
rewrite !trmx0 !(@map_mx0 _ _ conjC) !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
by rewrite (unitarymxP _) -?scalar_mx_block //.
apply/allP => /= A A_in.
rewrite trmx_mul map_mxM tr_block_mx map_block_mx.
rewrite !trmx0 !map_mx0 !tr_scalar_mx !map_scalar_mx ?conjC1.
rewrite mulmxA -[_ *m S *m _]mulmxA -[_ *m _ *m S^t*]mulmxA.
rewrite /S ![schmidt_complete _ *m _]mul_col_mx.
rewrite !tr_col_mx !map_row_mx !mul_col_row !mulmx_block.
rewrite !(mulmx1, mul1mx, mulmx0, mul0mx, addr0, add0r).
apply/is_trig_mxP => /= i j lt_ij; rewrite mxE.
case: splitP => //= i' i_eq; rewrite !mxE;
case: splitP => //= j' j_eq.
- have /vP /eigenvectorP [a v_in] := A_in.
by rewrite (vSv _ _ v_in) mxE -val_eqE ltn_eqF //= -i_eq -j_eq.
- by rewrite vSvo ?mul0mx ?mxE // vP //.
- move: lt_ij; rewrite i_eq j_eq ltnNge -ltnS (leq_trans (ltn_ord j'))//.
by rewrite -addnS leq_addr.
- set A' := _ *m A *m _; rewrite -invmx_unitary // -conjumx ?unitarymx_unit//.
have /(_ _) /is_trig_mxP -> // := P'P A'; last first.
by move: lt_ij; rewrite i_eq j_eq ltn_add2l.
by apply/mapP; exists A; rewrite //= drrE.
Qed.
Theorem Schur n (A : 'M[C]_n) : (n > 0)%N ->
trigonalizable_in (@unitarymx C n n) A.
Proof.
case: n => [//|n] in A * => _; have [] := @cotrigonalization _ [:: A].
by move=> ? ? /=; rewrite !in_cons !orbF => /eqP-> /eqP->.
by move=> P P_unitary /=; rewrite andbT=> A_trigo; exists P.
Qed.
Lemma cotrigonalization2 n (A B : 'M[C]_n) : A *m B = B *m A ->
exists2 P : 'M[C]_n, P \is unitarymx &
similar_trig P A && similar_trig P B.
Proof.
move=> AB_comm; have [] := @cotrigonalization _ [:: A; B].
by move=> ??; rewrite !inE => /orP[]/eqP->/orP[]/eqP->.
move=> P Punitary /allP /= PP; exists P => //.
by rewrite !PP ?(mem_head, in_cons, orbT).
Qed.
Theorem orthomx_spectral_subproof n {A : 'M[C]_n} : reflect
(exists2 sp : 'M_n * 'rV_n,
sp.1 \is unitarymx &
A = invmx sp.1 *m diag_mx sp.2 *m sp.1)
(A \is normalmx).
Proof.
apply: (iffP normalmxP); last first.
move=> [[/= P D] P_unitary ->].
rewrite !trmx_mul !map_mxM !mulmxA invmx_unitary //.
rewrite !trmxCK ![_ *m P *m _]mulmxtVK //.
by rewrite -[X in X *m P]mulmxA tr_diag_mx map_diag_mx diag_mxC mulmxA.
move=> /cotrigonalization2 [P Punitary /andP[]] PA PATC.
have Punit := unitarymx_unit Punitary.
suff: similar_diag P A.
move=> /similar_diagPex[D] PAD; exists (P, D) => //=.
by rewrite -conjVmx//; exact/similarLR.
apply/similar_diagPp => // i j; case: ltngtP => // [lt_ij|lt_ji] _.
by have /is_trig_mxP-> := PA.
have /is_trig_mxP -/(_ j i lt_ji)/eqP := PATC.
rewrite !conjumx// invmx_unitary// -[P as X in X *m _]trmxCK.
by rewrite -!map_mxM -!trmx_mul mulmxA 2!mxE conjC_eq0 => /eqP.
Qed.
Definition spectralmx n (A : 'M[C]_n) : 'M[C]_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).1 else 1%:M.
Definition spectral_diag n (A : 'M[C]_n) : 'rV_n :=
if @orthomx_spectral_subproof _ A is ReflectT P
then (projT1 (sig2_eqW P)).2 else 0.
Lemma spectral_unitarymx n (A : 'M[C]_n) : spectralmx A \is unitarymx.
Proof.
rewrite /spectralmx; case: orthomx_spectral_subproof; last first.
by move=> _; apply/unitarymxP; rewrite trmx1 map_mx1 mulmx1.
by move=> ?; case: sig2_eqW.
Qed.
Lemma spectral_unit n (A : 'M[C]_n) : spectralmx A \in unitmx.
Proof. exact/unitarymx_unit/spectral_unitarymx. Qed.
Theorem orthomx_spectralP {n} {A : 'M[C]_n}
(P := spectralmx A) (sp := spectral_diag A) :
reflect (A = invmx P *m diag_mx sp *m P) (A \is normalmx).
Proof.
rewrite /P /sp /spectralmx /spectral_diag.
case: orthomx_spectral_subproof.
by move=> Psp; case: sig2_eqW => //=; constructor.
move=> /orthomx_spectral_subproof Ann; constructor; apply/eqP.
apply: contra Ann; rewrite invmx1 mul1mx mulmx1 => /eqP->.
suff -> : diag_mx 0 = 0 by rewrite qualifE trmx0 (map_mx0 conjC).
by move=> ? ?; apply/matrixP=> i j; rewrite !mxE mul0rn.
Qed.
Lemma hermitian_spectral_diag_real n (A : 'M[C]_n) : A \is hermsymmx ->
spectral_diag A \is a realmx.
Proof.
move=> Ahermi; have /hermitian_normalmx /orthomx_spectralP A_eq := Ahermi.
have /(congr1 ( fun X => X^t* )) := A_eq.
rewrite invmx_unitary ?spectral_unitarymx //.
rewrite !trmx_mul !map_mxM map_trmx trmxK -map_mx_comp.
rewrite tr_diag_mx map_diag_mx (map_mx_id (@conjCK _)).
rewrite -[in RHS]invmx_unitary ?spectral_unitarymx //.
have := is_hermitianmxP _ _ _ Ahermi; rewrite expr0 scale1r => <-.
rewrite {1}A_eq mulmxA => /(congr1 (mulmx^~ (invmx (spectralmx A)))).
rewrite !mulmxK ?spectral_unit//.
move=> /(congr1 (mulmx (spectralmx A))); rewrite !mulKVmx ?spectral_unit//.
move=> eq_A_conjA; apply/mxOverP => i j; rewrite ord1 {i}.
have /matrixP /(_ j j) := eq_A_conjA; rewrite !mxE eqxx !mulr1n.
by move=> /esym/CrealP.
Qed.
End Spectral.
|
Formula.lean
|
/-
Copyright (c) 2025 David Kurniadi Angdinata. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Kurniadi Angdinata
-/
import Mathlib.AlgebraicGeometry.EllipticCurve.Affine.Basic
/-!
# Negation and addition formulae for nonsingular points in affine coordinates
Let `W` be a Weierstrass curve over a field `F` with coefficients `aα΅’`. The nonsingular affine
points on `W` can be given negation and addition operations defined by a secant-and-tangent process.
* Given a nonsingular affine point `P`, its *negation* `-P` is defined to be the unique third
nonsingular point of intersection between `W` and the vertical line through `P`.
Explicitly, if `P` is `(x, y)`, then `-P` is `(x, -y - aβx - aβ)`.
* Given two nonsingular affine points `P` and `Q`, their *addition* `P + Q` is defined to be the
negation of the unique third nonsingular point of intersection between `W` and the line `L`
through `P` and `Q`. Explicitly, let `P` be `(xβ, yβ)` and let `Q` be `(xβ, yβ)`.
* If `xβ = xβ` and `yβ = -yβ - aβxβ - aβ`, then `L` is vertical.
* If `xβ = xβ` and `yβ β -yβ - aβxβ - aβ`, then `L` is the tangent of `W` at `P = Q`, and has
slope `β := (3xβΒ² + 2aβxβ + aβ - aβyβ) / (2yβ + aβxβ + aβ)`.
* Otherwise `xβ β xβ`, then `L` is the secant of `W` through `P` and `Q`, and has slope
`β := (yβ - yβ) / (xβ - xβ)`.
In the last two cases, the `X`-coordinate of `P + Q` is then the unique third solution of the
equation obtained by substituting the line `Y = β(X - xβ) + yβ` into the Weierstrass equation,
and can be written down explicitly as `x := βΒ² + aββ - aβ - xβ - xβ` by inspecting the
coefficients of `XΒ²`. The `Y`-coordinate of `P + Q`, after applying the final negation that maps
`Y` to `-Y - aβX - aβ`, is precisely `y := -(β(x - xβ) + yβ) - aβx - aβ`.
This file defines polynomials associated to negation and addition of nonsingular affine points,
including slopes of non-vertical lines. The actual group law on nonsingular points in affine
coordinates will be defined in `Mathlib/AlgebraicGeometry/EllipticCurve/Affine/Point.lean`.
## Main definitions
* `WeierstrassCurve.Affine.negY`: the `Y`-coordinate of `-P`.
* `WeierstrassCurve.Affine.addX`: the `X`-coordinate of `P + Q`.
* `WeierstrassCurve.Affine.negAddY`: the `Y`-coordinate of `-(P + Q)`.
* `WeierstrassCurve.Affine.addY`: the `Y`-coordinate of `P + Q`.
## Main statements
* `WeierstrassCurve.Affine.equation_neg`: negation preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.nonsingular_neg`: negation preserves the nonsingular condition.
* `WeierstrassCurve.Affine.equation_add`: addition preserves the Weierstrass equation.
* `WeierstrassCurve.Affine.nonsingular_add`: addition preserves the nonsingular condition.
## References
[J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009]
## Tags
elliptic curve, affine, negation, doubling, addition, group law
-/
open Polynomial
open scoped Polynomial.Bivariate
local macro "C_simp" : tactic =>
`(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow])
local macro "derivative_simp" : tactic =>
`(tactic| simp only [derivative_C, derivative_X, derivative_X_pow, derivative_neg, derivative_add,
derivative_sub, derivative_mul, derivative_sq])
local macro "eval_simp" : tactic =>
`(tactic| simp only [eval_C, eval_X, eval_neg, eval_add, eval_sub, eval_mul, eval_pow, evalEval])
local macro "map_simp" : tactic =>
`(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_divβ,
Polynomial.map_ofNat, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub,
Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom,
WeierstrassCurve.map])
universe r s u v w
namespace WeierstrassCurve
variable {R : Type r} {S : Type s} {A F : Type u} {B K : Type v} [CommRing R] [CommRing S]
[CommRing A] [CommRing B] [Field F] [Field K] {W' : Affine R} {W : Affine F}
namespace Affine
/-! ## Negation formulae in affine coordinates -/
variable (W') in
/-- The negation polynomial `-Y - aβX - aβ` associated to the negation of a nonsingular affine point
on a Weierstrass curve. -/
noncomputable def negPolynomial : R[X][Y] :=
-(Y : R[X][Y]) - C (C W'.aβ * X + C W'.aβ)
lemma Y_sub_polynomialY : Y - W'.polynomialY = W'.negPolynomial := by
rw [polynomialY, negPolynomial]
C_simp
ring1
lemma Y_sub_negPolynomial : Y - W'.negPolynomial = W'.polynomialY := by
rw [β Y_sub_polynomialY, sub_sub_cancel]
variable (W') in
/-- The `Y`-coordinate of `-(x, y)` for a nonsingular affine point `(x, y)` on a Weierstrass curve
`W`.
This depends on `W`, and has argument order: `x`, `y`. -/
@[simp]
def negY (x y : R) : R :=
-y - W'.aβ * x - W'.aβ
lemma negY_negY (x y : R) : W'.negY x (W'.negY x y) = y := by
simp only [negY]
ring1
lemma evalEval_negPolynomial (x y : R) : W'.negPolynomial.evalEval x y = W'.negY x y := by
rw [negY, sub_sub, negPolynomial]
eval_simp
@[deprecated (since := "2025-03-05")] alias eval_negPolynomial := evalEval_negPolynomial
lemma Y_eq_of_X_eq {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ)
(hx : xβ = xβ) : yβ = yβ β¨ yβ = W.negY xβ yβ := by
rw [equation_iff] at hβ hβ
rw [β sub_eq_zero, β sub_eq_zero (a := yβ), β mul_eq_zero, negY]
linear_combination (norm := (rw [hx]; ring1)) hβ - hβ
lemma Y_eq_of_Y_ne {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ) (hx : xβ = xβ)
(hy : yβ β W.negY xβ yβ) : yβ = yβ :=
(Y_eq_of_X_eq hβ hβ hx).resolve_right hy
lemma equation_neg (x y : R) : W'.Equation x (W'.negY x y) β W'.Equation x y := by
rw [equation_iff, equation_iff, negY]
congr! 1
ring1
@[deprecated (since := "2025-02-01")] alias equation_neg_of := equation_neg
@[deprecated (since := "2025-02-01")] alias equation_neg_iff := equation_neg
lemma nonsingular_neg (x y : R) : W'.Nonsingular x (W'.negY x y) β W'.Nonsingular x y := by
rw [nonsingular_iff, equation_neg, β negY, negY_negY, β @ne_comm _ y, nonsingular_iff]
exact and_congr_right' <| (iff_congr not_and_or.symm not_and_or.symm).mpr <|
not_congr <| and_congr_left fun h => by rw [β h]
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_of := nonsingular_neg
@[deprecated (since := "2025-02-01")] alias nonsingular_neg_iff := nonsingular_neg
/-! ## Slope formulae in affine coordinates -/
variable (W') in
/-- The line polynomial `β(X - x) + y` associated to the line `Y = β(X - x) + y` that passes through
a nonsingular affine point `(x, y)` on a Weierstrass curve `W` with a slope of `β`.
This does not depend on `W`, and has argument order: `x`, `y`, `β`. -/
noncomputable def linePolynomial (x y β : R) : R[X] :=
C β * (X - C x) + C y
section slope
variable [DecidableEq F]
variable (W) in
/-- The slope of the line through two nonsingular affine points `(xβ, yβ)` and `(xβ, yβ)` on a
Weierstrass curve `W`.
If `xβ β xβ`, then this line is the secant of `W` through `(xβ, yβ)` and `(xβ, yβ)`, and has slope
`(yβ - yβ) / (xβ - xβ)`. Otherwise, if `yβ β -yβ - aβxβ - aβ`, then this line is the tangent of `W`
at `(xβ, yβ) = (xβ, yβ)`, and has slope `(3xβΒ² + 2aβxβ + aβ - aβyβ) / (2yβ + aβxβ + aβ)`. Otherwise,
this line is vertical, in which case this returns the value `0`.
This depends on `W`, and has argument order: `xβ`, `xβ`, `yβ`, `yβ`. -/
def slope (xβ xβ yβ yβ : F) : F :=
if xβ = xβ then if yβ = W.negY xβ yβ then 0
else (3 * xβ ^ 2 + 2 * W.aβ * xβ + W.aβ - W.aβ * yβ) / (yβ - W.negY xβ yβ)
else (yβ - yβ) / (xβ - xβ)
@[simp]
lemma slope_of_Y_eq {xβ xβ yβ yβ : F} (hx : xβ = xβ) (hy : yβ = W.negY xβ yβ) :
W.slope xβ xβ yβ yβ = 0 := by
rw [slope, if_pos hx, if_pos hy]
@[simp]
lemma slope_of_Y_ne' {xβ yβ yβ : F} (hy : Β¬yβ = -yβ - W.aβ * xβ - W.aβ) :
W.slope xβ xβ yβ yβ =
(3 * xβ ^ 2 + 2 * W.aβ * xβ + W.aβ - W.aβ * yβ) / (yβ - (-yβ - W.aβ * xβ - W.aβ)) := by
simp [slope, hy]
lemma slope_of_Y_ne {xβ xβ yβ yβ : F} (hx : xβ = xβ) (hy : yβ β W.negY xβ yβ) :
W.slope xβ xβ yβ yβ =
(3 * xβ ^ 2 + 2 * W.aβ * xβ + W.aβ - W.aβ * yβ) / (yβ - W.negY xβ yβ) := by
simp_all
@[simp]
lemma slope_of_X_ne {xβ xβ yβ yβ : F} (hx : xβ β xβ) :
W.slope xβ xβ yβ yβ = (yβ - yβ) / (xβ - xβ) := by
rw [slope, if_neg hx]
lemma slope_of_Y_ne_eq_evalEval {xβ xβ yβ yβ : F} (hx : xβ = xβ) (hy : yβ β W.negY xβ yβ) :
W.slope xβ xβ yβ yβ = -W.polynomialX.evalEval xβ yβ / W.polynomialY.evalEval xβ yβ := by
rw [slope_of_Y_ne hx hy, evalEval_polynomialX, neg_sub]
congr 1
rw [negY, evalEval_polynomialY]
ring1
@[deprecated (since := "2025-03-05")] alias slope_of_Y_ne_eq_eval := slope_of_Y_ne_eq_evalEval
end slope
/-! ## Addition formulae in affine coordinates -/
variable (W') in
/-- The addition polynomial obtained by substituting the line `Y = β(X - x) + y` into the polynomial
`W(X, Y)` associated to a Weierstrass curve `W`. If such a line intersects `W` at another
nonsingular affine point `(x', y')` on `W`, then the roots of this polynomial are precisely `x`,
`x'`, and the `X`-coordinate of the addition of `(x, y)` and `(x', y')`.
This depends on `W`, and has argument order: `x`, `y`, `β`. -/
noncomputable def addPolynomial (x y β : R) : R[X] :=
W'.polynomial.eval <| linePolynomial x y β
lemma C_addPolynomial (x y β : R) : C (W'.addPolynomial x y β) =
(Y - C (linePolynomial x y β)) * (W'.negPolynomial - C (linePolynomial x y β)) +
W'.polynomial := by
rw [addPolynomial, linePolynomial, polynomial, negPolynomial]
eval_simp
C_simp
ring1
lemma addPolynomial_eq (x y β : R) : W'.addPolynomial x y β = -Cubic.toPoly
β¨1, -β ^ 2 - W'.aβ * β + W'.aβ,
2 * x * β ^ 2 + (W'.aβ * x - 2 * y - W'.aβ) * β + (-W'.aβ * y + W'.aβ),
-x ^ 2 * β ^ 2 + (2 * x * y + W'.aβ * x) * β - (y ^ 2 + W'.aβ * y - W'.aβ)β© := by
rw [addPolynomial, linePolynomial, polynomial, Cubic.toPoly]
eval_simp
C_simp
ring1
variable (W') in
/-- The `X`-coordinate of `(xβ, yβ) + (xβ, yβ)` for two nonsingular affine points `(xβ, yβ)` and
`(xβ, yβ)` on a Weierstrass curve `W`, where the line through them has a slope of `β`.
This depends on `W`, and has argument order: `xβ`, `xβ`, `β`. -/
@[simp]
def addX (xβ xβ β : R) : R :=
β ^ 2 + W'.aβ * β - W'.aβ - xβ - xβ
variable (W') in
/-- The `Y`-coordinate of `-((xβ, yβ) + (xβ, yβ))` for two nonsingular affine points `(xβ, yβ)` and
`(xβ, yβ)` on a Weierstrass curve `W`, where the line through them has a slope of `β`.
This depends on `W`, and has argument order: `xβ`, `xβ`, `yβ`, `β`. -/
@[simp]
def negAddY (xβ xβ yβ β : R) : R :=
β * (W'.addX xβ xβ β - xβ) + yβ
variable (W') in
/-- The `Y`-coordinate of `(xβ, yβ) + (xβ, yβ)` for two nonsingular affine points `(xβ, yβ)` and
`(xβ, yβ)` on a Weierstrass curve `W`, where the line through them has a slope of `β`.
This depends on `W`, and has argument order: `xβ`, `xβ`, `yβ`, `β`. -/
@[simp]
def addY (xβ xβ yβ β : R) : R :=
W'.negY (W'.addX xβ xβ β) (W'.negAddY xβ xβ yβ β)
section slope
variable [DecidableEq F]
lemma addPolynomial_slope {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) : W.addPolynomial xβ yβ (W.slope xβ xβ yβ yβ) =
-((X - C xβ) * (X - C xβ) * (X - C (W.addX xβ xβ <| W.slope xβ xβ yβ yβ))) := by
rw [addPolynomial_eq, neg_inj, Cubic.prod_X_sub_C_eq, Cubic.toPoly_injective]
by_cases hx : xβ = xβ
Β· have hy : yβ β W.negY xβ yβ := fun h => hxy β¨hx, hβ©
rcases hx, Y_eq_of_Y_ne hβ hβ hx hy with β¨rfl, rflβ©
rw [equation_iff] at hβ hβ
rw [slope_of_Y_ne rfl hy]
rw [negY, β sub_ne_zero] at hy
ext
Β· rfl
Β· simp only [addX]
ring1
Β· field_simp [hy]
ring1
Β· linear_combination (norm := (field_simp [hy]; ring1)) -hβ
Β· rw [equation_iff] at hβ hβ
rw [slope_of_X_ne hx]
rw [β sub_eq_zero] at hx
ext
Β· rfl
Β· simp only [addX]
ring1
Β· apply mul_right_injectiveβ hx
linear_combination (norm := (field_simp [hx]; ring1)) hβ - hβ
Β· apply mul_right_injectiveβ hx
linear_combination (norm := (field_simp [hx]; ring1)) xβ * hβ - xβ * hβ
lemma C_addPolynomial_slope {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) : C (W.addPolynomial xβ yβ <| W.slope xβ xβ yβ yβ) =
-(C (X - C xβ) * C (X - C xβ) * C (X - C (W.addX xβ xβ <| W.slope xβ xβ yβ yβ))) := by
rw [addPolynomial_slope hβ hβ hxy]
simp
lemma derivative_addPolynomial_slope {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ)
(hβ : W.Equation xβ yβ) (hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) :
derivative (W.addPolynomial xβ yβ <| W.slope xβ xβ yβ yβ) =
-((X - C xβ) * (X - C xβ) + (X - C xβ) * (X - C (W.addX xβ xβ <| W.slope xβ xβ yβ yβ)) +
(X - C xβ) * (X - C (W.addX xβ xβ <| W.slope xβ xβ yβ yβ))) := by
rw [addPolynomial_slope hβ hβ hxy]
derivative_simp
ring1
lemma nonsingular_negAdd_of_eval_derivative_ne_zero {xβ xβ yβ β : R}
(hx' : W'.Equation (W'.addX xβ xβ β) (W'.negAddY xβ xβ yβ β))
(hx : (W'.addPolynomial xβ yβ β).derivative.eval (W'.addX xβ xβ β) β 0) :
W'.Nonsingular (W'.addX xβ xβ β) (W'.negAddY xβ xβ yβ β) := by
rw [Nonsingular, and_iff_right hx', negAddY, polynomialX, polynomialY]
eval_simp
contrapose! hx
rw [addPolynomial, linePolynomial, polynomial]
eval_simp
derivative_simp
simp only [zero_add, add_zero, sub_zero, zero_mul, mul_one]
eval_simp
linear_combination (norm := (norm_num1; ring1)) hx.left + β * hx.right
lemma equation_add_iff (xβ xβ yβ β : R) : W'.Equation (W'.addX xβ xβ β) (W'.negAddY xβ xβ yβ β) β
(W'.addPolynomial xβ yβ β).eval (W'.addX xβ xβ β) = 0 := by
rw [Equation, negAddY, addPolynomial, linePolynomial, polynomial]
eval_simp
lemma equation_negAdd {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) : W.Equation
(W.addX xβ xβ <| W.slope xβ xβ yβ yβ) (W.negAddY xβ xβ yβ <| W.slope xβ xβ yβ yβ) := by
rw [equation_add_iff, addPolynomial_slope hβ hβ hxy]
eval_simp
rw [neg_eq_zero, sub_self, mul_zero]
lemma equation_add {xβ xβ yβ yβ : F} (hβ : W.Equation xβ yβ) (hβ : W.Equation xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) :
W.Equation (W.addX xβ xβ <| W.slope xβ xβ yβ yβ) (W.addY xβ xβ yβ <| W.slope xβ xβ yβ yβ) :=
(equation_neg ..).mpr <| equation_negAdd hβ hβ hxy
lemma nonsingular_negAdd {xβ xβ yβ yβ : F} (hβ : W.Nonsingular xβ yβ) (hβ : W.Nonsingular xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) : W.Nonsingular
(W.addX xβ xβ <| W.slope xβ xβ yβ yβ) (W.negAddY xβ xβ yβ <| W.slope xβ xβ yβ yβ) := by
by_cases hxβ : W.addX xβ xβ (W.slope xβ xβ yβ yβ) = xβ
Β· rwa [negAddY, hxβ, sub_self, mul_zero, zero_add]
Β· by_cases hxβ : W.addX xβ xβ (W.slope xβ xβ yβ yβ) = xβ
Β· by_cases hx : xβ = xβ
Β· subst hx
contradiction
Β· rwa [negAddY, β neg_sub, mul_neg, hxβ, slope_of_X_ne hx,
div_mul_cancelβ _ <| sub_ne_zero_of_ne hx, neg_sub, sub_add_cancel]
Β· apply nonsingular_negAdd_of_eval_derivative_ne_zero <| equation_negAdd hβ.left hβ.left hxy
rw [derivative_addPolynomial_slope hβ.left hβ.left hxy]
eval_simp
simp only [neg_ne_zero, sub_self, mul_zero, add_zero]
exact mul_ne_zero (sub_ne_zero_of_ne hxβ) (sub_ne_zero_of_ne hxβ)
lemma nonsingular_add {xβ xβ yβ yβ : F} (hβ : W.Nonsingular xβ yβ) (hβ : W.Nonsingular xβ yβ)
(hxy : Β¬(xβ = xβ β§ yβ = W.negY xβ yβ)) :
W.Nonsingular (W.addX xβ xβ <| W.slope xβ xβ yβ yβ) (W.addY xβ xβ yβ <| W.slope xβ xβ yβ yβ) :=
(nonsingular_neg ..).mpr <| nonsingular_negAdd hβ hβ hxy
/-- The formula `x(Pβ + Pβ) = x(Pβ - Pβ) - Ο(Pβ)Ο(Pβ) / (x(Pβ) - x(Pβ))Β²`,
where `Ο(x,y) = 2y + aβx + aβ`. -/
lemma addX_eq_addX_negY_sub {xβ xβ : F} (yβ yβ : F) (hx : xβ β xβ) :
W.addX xβ xβ (W.slope xβ xβ yβ yβ) = W.addX xβ xβ (W.slope xβ xβ yβ <| W.negY xβ yβ) -
(yβ - W.negY xβ yβ) * (yβ - W.negY xβ yβ) / (xβ - xβ) ^ 2 := by
simp_rw [slope_of_X_ne hx, addX, negY, β neg_sub xβ, neg_sq]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `y(Pβ)(x(Pβ) - x(Pβ)) + y(Pβ)(x(Pβ) - x(Pβ)) + y(Pβ)(x(Pβ) - x(Pβ)) = 0`,
assuming that `Pβ + Pβ + Pβ = O`. -/
lemma cyclic_sum_Y_mul_X_sub_X {xβ xβ : F} (yβ yβ : F) (hx : xβ β xβ) :
let xβ := W.addX xβ xβ (W.slope xβ xβ yβ yβ)
yβ * (xβ - xβ) + yβ * (xβ - xβ) + W.negAddY xβ xβ yβ (W.slope xβ xβ yβ yβ) * (xβ - xβ) = 0 := by
simp_rw [slope_of_X_ne hx, negAddY, addX]
field_simp [sub_ne_zero.mpr hx]
ring1
/-- The formula `Ο(Pβ + Pβ) = (Ο(Pβ)(x(Pβ) - x(Pβ)) - Ο(Pβ)(x(Pβ) - x(Pβ))) / (x(Pβ) - x(Pβ))`,
where `Ο(x,y) = 2y + aβx + aβ`. -/
lemma addY_sub_negY_addY {xβ xβ : F} (yβ yβ : F) (hx : xβ β xβ) :
let xβ := W.addX xβ xβ (W.slope xβ xβ yβ yβ)
let yβ := W.addY xβ xβ yβ (W.slope xβ xβ yβ yβ)
yβ - W.negY xβ yβ =
((yβ - W.negY xβ yβ) * (xβ - xβ) - (yβ - W.negY xβ yβ) * (xβ - xβ)) / (xβ - xβ) := by
simp_rw [addY, negY, eq_div_iff (sub_ne_zero.mpr hx.symm)]
linear_combination (norm := ring1) 2 * cyclic_sum_Y_mul_X_sub_X yβ yβ hx
end slope
/-! ## Maps and base changes -/
variable (f : R β+* S) (x y xβ yβ xβ yβ β : R)
lemma map_negPolynomial :
(W'.map f).toAffine.negPolynomial = W'.negPolynomial.map (mapRingHom f) := by
simp only [negPolynomial]
map_simp
lemma map_negY : (W'.map f).toAffine.negY (f x) (f y) = f (W'.negY x y) := by
simp only [negY]
map_simp
lemma map_linePolynomial : linePolynomial (f x) (f y) (f β) = (linePolynomial x y β).map f := by
simp only [linePolynomial]
map_simp
lemma map_addPolynomial :
(W'.map f).toAffine.addPolynomial (f x) (f y) (f β) = (W'.addPolynomial x y β).map f := by
rw [addPolynomial, map_polynomial, eval_map, linePolynomial, addPolynomial, β coe_mapRingHom,
β evalβ_hom, linePolynomial]
simp
lemma map_addX : (W'.map f).toAffine.addX (f xβ) (f xβ) (f β) = f (W'.addX xβ xβ β) := by
simp only [addX]
map_simp
lemma map_negAddY :
(W'.map f).toAffine.negAddY (f xβ) (f xβ) (f yβ) (f β) = f (W'.negAddY xβ xβ yβ β) := by
simp only [negAddY, map_addX]
map_simp
lemma map_addY :
(W'.map f).toAffine.addY (f xβ) (f xβ) (f yβ) (f β) = f (W'.toAffine.addY xβ xβ yβ β) := by
simp only [addY, map_negAddY, map_addX, map_negY]
lemma map_slope [DecidableEq F] [DecidableEq K] (f : F β+* K) (xβ xβ yβ yβ : F) :
(W.map f).toAffine.slope (f xβ) (f xβ) (f yβ) (f yβ) = f (W.slope xβ xβ yβ yβ) := by
by_cases hx : xβ = xβ
Β· by_cases hy : yβ = W.negY xβ yβ
Β· rw [slope_of_Y_eq (congr_arg f hx) <| by rw [hy, map_negY], slope_of_Y_eq hx hy, map_zero]
Β· rw [slope_of_Y_ne (congr_arg f hx) <| map_negY f xβ yβ βΈ fun h => hy <| f.injective h,
map_negY, slope_of_Y_ne hx hy]
map_simp
Β· rw [slope_of_X_ne fun h => hx <| f.injective h, slope_of_X_ne hx]
map_simp
variable [Algebra R S] [Algebra R A] [Algebra S A] [IsScalarTower R S A] [Algebra R B] [Algebra S B]
[IsScalarTower R S B] (f : A ββ[S] B) (x y xβ yβ xβ yβ β : A)
lemma baseChange_negPolynomial : (W'.baseChange B).toAffine.negPolynomial =
(W'.baseChange A).toAffine.negPolynomial.map (mapRingHom f) := by
rw [β map_negPolynomial, map_baseChange]
lemma baseChange_negY :
(W'.baseChange B).toAffine.negY (f x) (f y) = f ((W'.baseChange A).toAffine.negY x y) := by
rw [β RingHom.coe_coe, β map_negY, map_baseChange]
lemma baseChange_addPolynomial : (W'.baseChange B).toAffine.addPolynomial (f x) (f y) (f β) =
((W'.baseChange A).toAffine.addPolynomial x y β).map f := by
rw [β RingHom.coe_coe, β map_addPolynomial, map_baseChange]
lemma baseChange_addX : (W'.baseChange B).toAffine.addX (f xβ) (f xβ) (f β) =
f ((W'.baseChange A).toAffine.addX xβ xβ β) := by
rw [β RingHom.coe_coe, β map_addX, map_baseChange]
lemma baseChange_negAddY : (W'.baseChange B).toAffine.negAddY (f xβ) (f xβ) (f yβ) (f β) =
f ((W'.baseChange A).toAffine.negAddY xβ xβ yβ β) := by
rw [β RingHom.coe_coe, β map_negAddY, map_baseChange]
lemma baseChange_addY : (W'.baseChange B).toAffine.addY (f xβ) (f xβ) (f yβ) (f β) =
f ((W'.baseChange A).toAffine.addY xβ xβ yβ β) := by
rw [β RingHom.coe_coe, β map_addY, map_baseChange]
lemma baseChange_slope [DecidableEq F] [DecidableEq K]
[Algebra R F] [Algebra S F] [IsScalarTower R S F] [Algebra R K] [Algebra S K]
[IsScalarTower R S K] (f : F ββ[S] K) (xβ xβ yβ yβ : F) :
(W'.baseChange K).toAffine.slope (f xβ) (f xβ) (f yβ) (f yβ) =
f ((W'.baseChange F).toAffine.slope xβ xβ yβ yβ) := by
rw [β RingHom.coe_coe, β map_slope, map_baseChange]
end Affine
end WeierstrassCurve
|
DSlope.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.Calculus.Deriv.Slope
import Mathlib.Analysis.Calculus.Deriv.Comp
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Mul
/-!
# Slope of a differentiable function
Given a function `f : π β E` from a nontrivially normed field to a normed space over this field,
`dslope f a b` is defined as `slope f a b = (b - a)β»ΒΉ β’ (f b - f a)` for `a β b` and as `deriv f a`
for `a = b`.
In this file we define `dslope` and prove some basic lemmas about its continuity and
differentiability.
-/
open scoped Topology Filter
open Function Set Filter
variable {π E : Type*} [NontriviallyNormedField π] [NormedAddCommGroup E] [NormedSpace π E]
open Classical in
/-- `dslope f a b` is defined as `slope f a b = (b - a)β»ΒΉ β’ (f b - f a)` for `a β b` and
`deriv f a` for `a = b`. -/
noncomputable def dslope (f : π β E) (a : π) : π β E :=
update (slope f a) a (deriv f a)
@[simp]
theorem dslope_same (f : π β E) (a : π) : dslope f a a = deriv f a := by
classical
exact update_self ..
variable {f : π β E} {a b : π} {s : Set π}
theorem dslope_of_ne (f : π β E) (h : b β a) : dslope f a b = slope f a b := by
classical
exact update_of_ne h ..
theorem ContinuousLinearMap.dslope_comp {F : Type*} [NormedAddCommGroup F] [NormedSpace π F]
(f : E βL[π] F) (g : π β E) (a b : π) (H : a = b β DifferentiableAt π g a) :
dslope (f β g) a b = f (dslope g a b) := by
rcases eq_or_ne b a with (rfl | hne)
Β· simp only [dslope_same]
exact (f.hasFDerivAt.comp_hasDerivAt b (H rfl).hasDerivAt).deriv
Β· simpa only [dslope_of_ne _ hne] using f.toLinearMap.slope_comp g a b
theorem eqOn_dslope_slope (f : π β E) (a : π) : EqOn (dslope f a) (slope f a) {a}αΆ := fun _ =>
dslope_of_ne f
theorem dslope_eventuallyEq_slope_of_ne (f : π β E) (h : b β a) : dslope f a =αΆ [π b] slope f a :=
(eqOn_dslope_slope f a).eventuallyEq_of_mem (isOpen_ne.mem_nhds h)
theorem dslope_eventuallyEq_slope_nhdsNE (f : π β E) : dslope f a =αΆ [π[β ] a] slope f a :=
(eqOn_dslope_slope f a).eventuallyEq_of_mem self_mem_nhdsWithin
@[deprecated (since := "2025-03-02")]
alias dslope_eventuallyEq_slope_punctured_nhds := dslope_eventuallyEq_slope_nhdsNE
@[simp]
theorem sub_smul_dslope (f : π β E) (a b : π) : (b - a) β’ dslope f a b = f b - f a := by
rcases eq_or_ne b a with (rfl | hne) <;> simp [dslope_of_ne, *]
theorem dslope_sub_smul_of_ne (f : π β E) (h : b β a) :
dslope (fun x => (x - a) β’ f x) a b = f b := by
rw [dslope_of_ne _ h, slope_sub_smul _ h.symm]
theorem eqOn_dslope_sub_smul (f : π β E) (a : π) :
EqOn (dslope (fun x => (x - a) β’ f x) a) f {a}αΆ := fun _ => dslope_sub_smul_of_ne f
theorem dslope_sub_smul [DecidableEq π] (f : π β E) (a : π) :
dslope (fun x => (x - a) β’ f x) a = update f a (deriv (fun x => (x - a) β’ f x) a) :=
eq_update_iff.2 β¨dslope_same _ _, eqOn_dslope_sub_smul f aβ©
@[simp]
theorem continuousAt_dslope_same : ContinuousAt (dslope f a) a β DifferentiableAt π f a := by
simp only [dslope, continuousAt_update_same, β hasDerivAt_deriv_iff, hasDerivAt_iff_tendsto_slope]
theorem ContinuousWithinAt.of_dslope (h : ContinuousWithinAt (dslope f a) s b) :
ContinuousWithinAt f s b := by
have : ContinuousWithinAt (fun x => (x - a) β’ dslope f a x + f a) s b :=
((continuousWithinAt_id.sub continuousWithinAt_const).smul h).add continuousWithinAt_const
simpa only [sub_smul_dslope, sub_add_cancel] using this
theorem ContinuousAt.of_dslope (h : ContinuousAt (dslope f a) b) : ContinuousAt f b :=
(continuousWithinAt_univ _ _).1 h.continuousWithinAt.of_dslope
theorem ContinuousOn.of_dslope (h : ContinuousOn (dslope f a) s) : ContinuousOn f s := fun x hx =>
(h x hx).of_dslope
theorem continuousWithinAt_dslope_of_ne (h : b β a) :
ContinuousWithinAt (dslope f a) s b β ContinuousWithinAt f s b := by
refine β¨ContinuousWithinAt.of_dslope, fun hc => ?_β©
classical
simp only [dslope, continuousWithinAt_update_of_ne h]
exact ((continuousWithinAt_id.sub continuousWithinAt_const).invβ (sub_ne_zero.2 h)).smul
(hc.sub continuousWithinAt_const)
theorem continuousAt_dslope_of_ne (h : b β a) : ContinuousAt (dslope f a) b β ContinuousAt f b := by
simp only [β continuousWithinAt_univ, continuousWithinAt_dslope_of_ne h]
theorem continuousOn_dslope (h : s β π a) :
ContinuousOn (dslope f a) s β ContinuousOn f s β§ DifferentiableAt π f a := by
refine β¨fun hc => β¨hc.of_dslope, continuousAt_dslope_same.1 <| hc.continuousAt hβ©, ?_β©
rintro β¨hc, hdβ© x hx
rcases eq_or_ne x a with (rfl | hne)
exacts [(continuousAt_dslope_same.2 hd).continuousWithinAt,
(continuousWithinAt_dslope_of_ne hne).2 (hc x hx)]
theorem DifferentiableWithinAt.of_dslope (h : DifferentiableWithinAt π (dslope f a) s b) :
DifferentiableWithinAt π f s b := by
simpa only [id, sub_smul_dslope f a, sub_add_cancel] using
((differentiableWithinAt_id.sub_const a).fun_smul h).add_const (f a)
theorem DifferentiableAt.of_dslope (h : DifferentiableAt π (dslope f a) b) :
DifferentiableAt π f b :=
differentiableWithinAt_univ.1 h.differentiableWithinAt.of_dslope
theorem DifferentiableOn.of_dslope (h : DifferentiableOn π (dslope f a) s) :
DifferentiableOn π f s := fun x hx => (h x hx).of_dslope
theorem differentiableWithinAt_dslope_of_ne (h : b β a) :
DifferentiableWithinAt π (dslope f a) s b β DifferentiableWithinAt π f s b := by
refine β¨DifferentiableWithinAt.of_dslope, fun hd => ?_β©
refine (((differentiableWithinAt_id.sub_const a).inv (sub_ne_zero.2 h)).smul
(hd.sub_const (f a))).congr_of_eventuallyEq ?_ (dslope_of_ne _ h)
refine (eqOn_dslope_slope _ _).eventuallyEq_of_mem ?_
exact mem_nhdsWithin_of_mem_nhds (isOpen_ne.mem_nhds h)
theorem differentiableOn_dslope_of_notMem (h : a β s) :
DifferentiableOn π (dslope f a) s β DifferentiableOn π f s :=
forall_congr' fun _ =>
forall_congr' fun hx => differentiableWithinAt_dslope_of_ne <| ne_of_mem_of_not_mem hx h
@[deprecated (since := "2025-05-24")]
alias differentiableOn_dslope_of_nmem := differentiableOn_dslope_of_notMem
theorem differentiableAt_dslope_of_ne (h : b β a) :
DifferentiableAt π (dslope f a) b β DifferentiableAt π f b := by
simp only [β differentiableWithinAt_univ, differentiableWithinAt_dslope_of_ne h]
|
Disjoint.lean
|
/-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
import Mathlib.Data.Set.Basic
/-!
# Theorems about the `Disjoint` relation on `Set`.
-/
assert_not_exists HeytingAlgebra RelIso
/-! ### Set coercion to a type -/
open Function
universe u v
namespace Set
variable {Ξ± : Type u} {s t u sβ sβ tβ tβ : Set Ξ±}
/-! ### Disjointness -/
protected theorem disjoint_iff : Disjoint s t β s β© t β β
:=
disjoint_iff_inf_le
theorem disjoint_iff_inter_eq_empty : Disjoint s t β s β© t = β
:=
disjoint_iff
theorem _root_.Disjoint.inter_eq : Disjoint s t β s β© t = β
:=
Disjoint.eq_bot
theorem disjoint_left : Disjoint s t β β β¦aβ¦, a β s β a β t :=
disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and
alias β¨_root_.Disjoint.notMem_of_mem_left, _β© := disjoint_left
@[deprecated (since := "2025-05-23")]
alias _root_.Disjoint.not_mem_of_mem_left := Disjoint.notMem_of_mem_left
theorem disjoint_right : Disjoint s t β β β¦aβ¦, a β t β a β s := by rw [disjoint_comm, disjoint_left]
alias β¨_root_.Disjoint.notMem_of_mem_right, _β© := disjoint_right
@[deprecated (since := "2025-05-23")]
alias _root_.Disjoint.not_mem_of_mem_right := Disjoint.notMem_of_mem_right
lemma not_disjoint_iff : Β¬Disjoint s t β β x, x β s β§ x β t :=
Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ β¦ not_not
lemma not_disjoint_iff_nonempty_inter : Β¬ Disjoint s t β (s β© t).Nonempty := not_disjoint_iff
alias β¨_, Nonempty.not_disjointβ© := not_disjoint_iff_nonempty_inter
lemma disjoint_or_nonempty_inter (s t : Set Ξ±) : Disjoint s t β¨ (s β© t).Nonempty :=
(em _).imp_right not_disjoint_iff_nonempty_inter.1
lemma disjoint_iff_forall_ne : Disjoint s t β β β¦aβ¦, a β s β β β¦bβ¦, b β t β a β b := by
simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq']
alias β¨_root_.Disjoint.ne_of_mem, _β© := disjoint_iff_forall_ne
lemma disjoint_of_subset_left (h : s β u) (d : Disjoint u t) : Disjoint s t := d.mono_left h
lemma disjoint_of_subset_right (h : t β u) (d : Disjoint s u) : Disjoint s t := d.mono_right h
lemma disjoint_of_subset (hs : sβ β sβ) (ht : tβ β tβ) (h : Disjoint sβ tβ) : Disjoint sβ tβ :=
h.mono hs ht
@[simp]
lemma disjoint_union_left : Disjoint (s βͺ t) u β Disjoint s u β§ Disjoint t u := disjoint_sup_left
@[simp]
lemma disjoint_union_right : Disjoint s (t βͺ u) β Disjoint s t β§ Disjoint s u := disjoint_sup_right
@[simp] lemma disjoint_empty (s : Set Ξ±) : Disjoint s β
:= disjoint_bot_right
@[simp] lemma empty_disjoint (s : Set Ξ±) : Disjoint β
s := disjoint_bot_left
@[simp] lemma univ_disjoint : Disjoint univ s β s = β
:= top_disjoint
@[simp] lemma disjoint_univ : Disjoint s univ β s = β
:= disjoint_top
theorem disjoint_range_iff {Ξ² Ξ³ : Sort*} {x : Ξ² β Ξ±} {y : Ξ³ β Ξ±} :
Disjoint (range x) (range y) β β i j, x i β y j := by
simp [Set.disjoint_iff_forall_ne]
end Set
/-! ### Disjoint sets -/
variable {Ξ± : Type*} {s t u : Set Ξ±}
namespace Disjoint
theorem union_left (hs : Disjoint s u) (ht : Disjoint t u) : Disjoint (s βͺ t) u :=
hs.sup_left ht
theorem union_right (ht : Disjoint s t) (hu : Disjoint s u) : Disjoint s (t βͺ u) :=
ht.sup_right hu
theorem inter_left (u : Set Ξ±) (h : Disjoint s t) : Disjoint (s β© u) t :=
h.inf_left _
theorem inter_left' (u : Set Ξ±) (h : Disjoint s t) : Disjoint (u β© s) t :=
h.inf_left' _
theorem inter_right (u : Set Ξ±) (h : Disjoint s t) : Disjoint s (t β© u) :=
h.inf_right _
theorem inter_right' (u : Set Ξ±) (h : Disjoint s t) : Disjoint s (u β© t) :=
h.inf_right' _
theorem subset_left_of_subset_union (h : s β t βͺ u) (hac : Disjoint s u) : s β t :=
hac.left_le_of_le_sup_right h
theorem subset_right_of_subset_union (h : s β t βͺ u) (hab : Disjoint s t) : s β u :=
hab.left_le_of_le_sup_left h
end Disjoint
namespace Set
theorem mem_union_of_disjoint (h : Disjoint s t) {x : Ξ±} : x β s βͺ t β Xor' (x β s) (x β t) := by
grind [Xor', Set.disjoint_left]
end Set
|
Sym.lean
|
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Nat.Choose.Basic
import Mathlib.Data.Sym.Sym2
/-! # Unordered tuples of elements of a list
Defines `List.sym` and the specialized `List.sym2` for computing lists of all unordered n-tuples
from a given list. These are list versions of `Nat.multichoose`.
## Main declarations
* `List.sym`: `xs.sym n` is a list of all unordered n-tuples of elements from `xs`,
with multiplicity. The list's values are in `Sym Ξ± n`.
* `List.sym2`: `xs.sym2` is a list of all unordered pairs of elements from `xs`,
with multiplicity. The list's values are in `Sym2 Ξ±`.
## TODO
* Prove `protected theorem Perm.sym (n : β) {xs ys : List Ξ±} (h : xs ~ ys) : xs.sym n ~ ys.sym n`
and lift the result to `Multiset` and `Finset`.
-/
namespace List
variable {Ξ± Ξ² : Type*}
section Sym2
/-- `xs.sym2` is a list of all unordered pairs of elements from `xs`.
If `xs` has no duplicates then neither does `xs.sym2`. -/
protected def sym2 : List Ξ± β List (Sym2 Ξ±)
| [] => []
| x :: xs => (x :: xs).map (fun y => s(x, y)) ++ xs.sym2
theorem sym2_map (f : Ξ± β Ξ²) (xs : List Ξ±) :
(xs.map f).sym2 = xs.sym2.map (Sym2.map f) := by
induction xs with
| nil => simp [List.sym2]
| cons x xs ih => simp [List.sym2, ih, Function.comp]
theorem mem_sym2_cons_iff {x : Ξ±} {xs : List Ξ±} {z : Sym2 Ξ±} :
z β (x :: xs).sym2 β z = s(x, x) β¨ (β y, y β xs β§ z = s(x, y)) β¨ z β xs.sym2 := by
simp only [List.sym2, map_cons, cons_append, mem_cons, mem_append, mem_map]
simp only [eq_comm]
@[simp]
theorem sym2_eq_nil_iff {xs : List Ξ±} : xs.sym2 = [] β xs = [] := by
cases xs <;> simp [List.sym2]
theorem left_mem_of_mk_mem_sym2 {xs : List Ξ±} {a b : Ξ±}
(h : s(a, b) β xs.sym2) : a β xs := by
induction xs with
| nil => exact (not_mem_nil h).elim
| cons x xs ih =>
rw [mem_cons]
rw [mem_sym2_cons_iff] at h
obtain (h | β¨c, hc, hβ© | h) := h
Β· rw [Sym2.eq_iff, β and_or_left] at h
exact .inl h.1
Β· rw [Sym2.eq_iff] at h
obtain (β¨rfl, rflβ© | β¨rfl, rflβ©) := h <;> simp [hc]
Β· exact .inr <| ih h
theorem right_mem_of_mk_mem_sym2 {xs : List Ξ±} {a b : Ξ±}
(h : s(a, b) β xs.sym2) : b β xs := by
rw [Sym2.eq_swap] at h
exact left_mem_of_mk_mem_sym2 h
theorem mk_mem_sym2 {xs : List Ξ±} {a b : Ξ±} (ha : a β xs) (hb : b β xs) :
s(a, b) β xs.sym2 := by
induction xs with
| nil => simp at ha
| cons x xs ih =>
rw [mem_sym2_cons_iff]
rw [mem_cons] at ha hb
obtain (rfl | ha) := ha <;> obtain (rfl | hb) := hb
Β· left; rfl
Β· right; left; use b
Β· right; left; rw [Sym2.eq_swap]; use a
Β· right; right; exact ih ha hb
theorem mk_mem_sym2_iff {xs : List Ξ±} {a b : Ξ±} :
s(a, b) β xs.sym2 β a β xs β§ b β xs := by
constructor
Β· intro h
exact β¨left_mem_of_mk_mem_sym2 h, right_mem_of_mk_mem_sym2 hβ©
Β· rintro β¨ha, hbβ©
exact mk_mem_sym2 ha hb
theorem mem_sym2_iff {xs : List Ξ±} {z : Sym2 Ξ±} :
z β xs.sym2 β β y β z, y β xs := by
refine z.ind (fun a b => ?_)
simp [mk_mem_sym2_iff]
lemma setOf_mem_sym2 {xs : List Ξ±} :
{z : Sym2 Ξ± | z β xs.sym2} = {x : Ξ± | x β xs}.sym2 :=
Set.ext fun z β¦ z.ind fun a b => by simp [mk_mem_sym2_iff]
protected theorem Nodup.sym2 {xs : List Ξ±} (h : xs.Nodup) : xs.sym2.Nodup := by
induction xs with
| nil => simp only [List.sym2, nodup_nil]
| cons x xs ih =>
rw [List.sym2]
specialize ih h.of_cons
rw [nodup_cons] at h
refine Nodup.append (Nodup.cons ?notmem (h.2.map ?inj)) ih ?disj
case disj =>
intro z hz hz'
simp only [mem_cons, mem_map] at hz
obtain β¨_, (rfl | _), rflβ© := hz
<;> simp [left_mem_of_mk_mem_sym2 hz'] at h
case notmem =>
intro h'
simp only [h.1, mem_map, Sym2.eq_iff, true_and, or_self, exists_eq_right] at h'
case inj =>
intro a b
simp only [Sym2.eq_iff, true_and]
rintro (rfl | β¨rfl, rflβ©) <;> rfl
theorem map_mk_sublist_sym2 (x : Ξ±) (xs : List Ξ±) (h : x β xs) :
map (fun y β¦ s(x, y)) xs <+ xs.sym2 := by
induction xs with
| nil => simp
| cons x' xs ih =>
simp only [map_cons, List.sym2, cons_append]
cases h with
| head =>
exact (sublist_append_left _ _).consβ _
| tail _ h =>
refine .cons _ ?_
rw [β singleton_append]
refine .append ?_ (ih h)
rw [singleton_sublist, mem_map]
exact β¨_, h, Sym2.eq_swapβ©
theorem map_mk_disjoint_sym2 (x : Ξ±) (xs : List Ξ±) (h : x β xs) :
(map (fun y β¦ s(x, y)) xs).Disjoint xs.sym2 := by
induction xs with
| nil => simp
| cons x' xs ih =>
simp only [mem_cons, not_or] at h
rw [List.sym2, map_cons, map_cons, disjoint_cons_left, disjoint_append_right,
disjoint_cons_right]
refine β¨?_, β¨?_, ?_β©, ?_β©
Β· refine not_mem_cons_of_ne_of_not_mem ?_ (not_mem_append ?_ ?_)
Β· simp [h.1]
Β· simp_rw [mem_map, not_exists, not_and]
intro x'' hx
simp_rw [Sym2.mk_eq_mk_iff, Prod.swap_prod_mk, Prod.mk.injEq, true_and]
rintro (β¨rfl, rflβ© | rfl)
Β· exact h.2 hx
Β· exact h.2 hx
Β· simp [mk_mem_sym2_iff, h.2]
Β· simp [h.1]
Β· intro z hx hy
rw [List.mem_map] at hx hy
obtain β¨a, hx, rflβ© := hx
obtain β¨b, hy, hxβ© := hy
simp [Ne.symm h.1] at hx
obtain β¨rfl, rflβ© := hx
exact h.2 hy
Β· exact ih h.2
theorem dedup_sym2 [DecidableEq Ξ±] (xs : List Ξ±) : xs.sym2.dedup = xs.dedup.sym2 := by
induction xs with
| nil => simp only [List.sym2, dedup_nil]
| cons x xs ih =>
simp only [List.sym2, map_cons, cons_append]
obtain hm | hm := Decidable.em (x β xs)
Β· rw [dedup_cons_of_mem hm, β ih, dedup_cons_of_mem,
List.Subset.dedup_append_right (map_mk_sublist_sym2 _ _ hm).subset]
refine mem_append_left _ ?_
rw [mem_map]
exact β¨_, hm, Sym2.eq_swapβ©
Β· rw [dedup_cons_of_notMem hm, List.sym2, map_cons, β ih, dedup_cons_of_notMem, cons_append,
List.Disjoint.dedup_append, dedup_map_of_injective]
Β· exact (Sym2.mkEmbedding _).injective
Β· exact map_mk_disjoint_sym2 x xs hm
Β· simp [hm, mem_sym2_iff]
protected theorem Perm.sym2 {xs ys : List Ξ±} (h : xs ~ ys) :
xs.sym2 ~ ys.sym2 := by
induction h with
| nil => rfl
| cons x h ih =>
simp only [List.sym2, map_cons, cons_append, perm_cons]
exact (h.map _).append ih
| swap x y xs =>
simp only [List.sym2, map_cons, cons_append]
conv => enter [1,2,1]; rw [Sym2.eq_swap]
-- Explicit permutation to speed up simps that follow.
refine Perm.trans (Perm.swap ..) (Perm.trans (Perm.cons _ ?_) (Perm.swap ..))
simp only [β Multiset.coe_eq_coe, β Multiset.cons_coe,
β Multiset.coe_add, β Multiset.singleton_add]
simp only [add_left_comm]
| trans _ _ ih1 ih2 => exact ih1.trans ih2
protected theorem Sublist.sym2 {xs ys : List Ξ±} (h : xs <+ ys) : xs.sym2 <+ ys.sym2 := by
induction h with
| slnil => apply slnil
| cons a h ih =>
simp only [List.sym2]
exact Sublist.append (nil_sublist _) ih
| consβ a h ih =>
simp only [List.sym2, map_cons, cons_append]
exact consβ _ (append (Sublist.map _ h) ih)
protected theorem Subperm.sym2 {xs ys : List Ξ±} (h : xs <+~ ys) : xs.sym2 <+~ ys.sym2 := by
obtain β¨xs', hx, hβ© := h
exact hx.sym2.symm.subperm.trans h.sym2.subperm
theorem length_sym2 {xs : List Ξ±} : xs.sym2.length = Nat.choose (xs.length + 1) 2 := by
induction xs with
| nil => rfl
| cons x xs ih =>
rw [List.sym2, length_append, length_map, length_cons,
Nat.choose_succ_succ, β ih, Nat.choose_one_right]
end Sym2
section Sym
/-- `xs.sym n` is all unordered `n`-tuples from the list `xs` in some order. -/
protected def sym : (n : β) β List Ξ± β List (Sym Ξ± n)
| 0, _ => [.nil]
| _, [] => []
| n + 1, x :: xs => ((x :: xs).sym n |>.map fun p => x ::β p) ++ xs.sym (n + 1)
variable {xs ys : List Ξ±} {n : β}
theorem sym_one_eq : xs.sym 1 = xs.map (Β· ::β .nil) := by
induction xs with
| nil => simp only [List.sym, Nat.succ_eq_add_one, Nat.reduceAdd, map_nil]
| cons x xs ih =>
rw [map_cons, β ih, List.sym, List.sym, map_singleton, singleton_append]
theorem sym2_eq_sym_two : xs.sym2.map (Sym2.equivSym Ξ±) = xs.sym 2 := by
induction xs with
| nil => simp only [List.sym, map_eq_nil_iff, sym2_eq_nil_iff]
| cons x xs ih =>
rw [List.sym, β ih, sym_one_eq, map_map, List.sym2, map_append, map_map]
rfl
theorem sym_map {Ξ² : Type*} (f : Ξ± β Ξ²) (n : β) (xs : List Ξ±) :
(xs.map f).sym n = (xs.sym n).map (Sym.map f) :=
match n, xs with
| 0, _ => by simp only [List.sym]; rfl
| n + 1, [] => by simp [List.sym]
| n + 1, x :: xs => by
rw [map_cons, List.sym, β map_cons, sym_map f n (x :: xs), sym_map f (n + 1) xs]
simp only [map_map, List.sym, map_append, append_cancel_right_eq]
congr
ext s
simp only [Function.comp_apply, Sym.map_cons]
protected theorem Sublist.sym (n : β) {xs ys : List Ξ±} (h : xs <+ ys) : xs.sym n <+ ys.sym n :=
match n, h with
| 0, _ => by simp [List.sym]
| n + 1, .slnil => by simp only [refl]
| n + 1, .cons a h => by
rw [List.sym, β nil_append (List.sym (n + 1) xs)]
apply Sublist.append (nil_sublist _)
exact h.sym (n + 1)
| n + 1, .consβ a h => by
rw [List.sym, List.sym]
apply Sublist.append
Β· exact ((consβ a h).sym n).map _
Β· exact h.sym (n + 1)
theorem sym_sublist_sym_cons {a : Ξ±} : xs.sym n <+ (a :: xs).sym n :=
(sublist_cons_self a xs).sym n
theorem mem_of_mem_of_mem_sym {n : β} {xs : List Ξ±} {a : Ξ±} {z : Sym Ξ± n}
(ha : a β z) (hz : z β xs.sym n) : a β xs :=
match n, xs with
| 0, xs => by
cases Sym.eq_nil_of_card_zero z
simp at ha
| n + 1, [] => by simp [List.sym] at hz
| n + 1, x :: xs => by
rw [List.sym, mem_append, mem_map] at hz
obtain β¨z, hz, rflβ© | hz := hz
Β· rw [Sym.mem_cons] at ha
obtain rfl | ha := ha
Β· simp
Β· exact mem_of_mem_of_mem_sym ha hz
Β· rw [mem_cons]
right
exact mem_of_mem_of_mem_sym ha hz
theorem first_mem_of_cons_mem_sym {xs : List Ξ±} {n : β} {a : Ξ±} {z : Sym Ξ± n}
(h : a ::β z β xs.sym (n + 1)) : a β xs :=
mem_of_mem_of_mem_sym (Sym.mem_cons_self a z) h
protected theorem Nodup.sym (n : β) {xs : List Ξ±} (h : xs.Nodup) : (xs.sym n).Nodup :=
match n, xs with
| 0, _ => by simp [List.sym]
| n + 1, [] => by simp [List.sym]
| n + 1, x :: xs => by
rw [List.sym]
refine Nodup.append (Nodup.map ?inj (Nodup.sym n h)) (Nodup.sym (n + 1) h.of_cons) ?disj
case inj =>
intro z z'
simp
case disj =>
intro z hz hz'
rw [mem_map] at hz
obtain β¨z, _hz, rflβ© := hz
have := first_mem_of_cons_mem_sym hz'
simp only [nodup_cons, this, not_true_eq_false, false_and] at h
theorem length_sym {n : β} {xs : List Ξ±} :
(xs.sym n).length = Nat.multichoose xs.length n :=
match n, xs with
| 0, _ => by rw [List.sym, Nat.multichoose]; rfl
| n + 1, [] => by simp [List.sym]
| n + 1, x :: xs => by
rw [List.sym, length_append, length_map, length_cons]
rw [@length_sym n (x :: xs), @length_sym (n + 1) xs]
rw [Nat.multichoose_succ_succ, length_cons, add_comm]
end Sym
end List
|
Basic.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.Data.FunLike.Basic
import Mathlib.Logic.Embedding.Basic
import Mathlib.Order.RelClasses
/-!
# Relation homomorphisms, embeddings, isomorphisms
This file defines relation homomorphisms, embeddings, isomorphisms and order embeddings and
isomorphisms.
## Main declarations
* `RelHom`: Relation homomorphism. A `RelHom r s` is a function `f : Ξ± β Ξ²` such that
`r a b β s (f a) (f b)`.
* `RelEmbedding`: Relation embedding. A `RelEmbedding r s` is an embedding `f : Ξ± βͺ Ξ²` such that
`r a b β s (f a) (f b)`.
* `RelIso`: Relation isomorphism. A `RelIso r s` is an equivalence `f : Ξ± β Ξ²` such that
`r a b β s (f a) (f b)`.
* `sumLexCongr`, `prodLexCongr`: Creates a relation homomorphism between two `Sum.Lex` or two
`Prod.Lex` from relation homomorphisms between their arguments.
## Notation
* `βr`: `RelHom`
* `βͺr`: `RelEmbedding`
* `βr`: `RelIso`
-/
open Function
universe u v w
variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
{t : Ξ³ β Ξ³ β Prop} {u : Ξ΄ β Ξ΄ β Prop}
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : Ξ± β Ξ²` such that `r a b β s (f a) (f b)`. -/
structure RelHom {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) where
/-- The underlying function of a `RelHom` -/
toFun : Ξ± β Ξ²
/-- A `RelHom` sends related elements to related elements -/
map_rel' : β {a b}, r a b β s (toFun a) (toFun b)
/-- A relation homomorphism with respect to a given pair of relations `r` and `s`
is a function `f : Ξ± β Ξ²` such that `r a b β s (f a) (f b)`. -/
infixl:25 " βr " => RelHom
section
/-- `RelHomClass F r s` asserts that `F` is a type of functions such that all `f : F`
satisfy `r a b β s (f a) (f b)`.
The relations `r` and `s` are `outParam`s since figuring them out from a goal is a higher-order
matching problem that Lean usually can't do unaided.
-/
class RelHomClass (F : Type*) {Ξ± Ξ² : outParam Type*} (r : outParam <| Ξ± β Ξ± β Prop)
(s : outParam <| Ξ² β Ξ² β Prop) [FunLike F Ξ± Ξ²] : Prop where
/-- A `RelHomClass` sends related elements to related elements -/
map_rel : β (f : F) {a b}, r a b β s (f a) (f b)
export RelHomClass (map_rel)
end
namespace RelHomClass
variable {F : Type*} [FunLike F Ξ± Ξ²]
protected theorem isIrrefl [RelHomClass F r s] (f : F) : β [IsIrrefl Ξ² s], IsIrrefl Ξ± r
| β¨Hβ© => β¨fun _ h => H _ (map_rel f h)β©
protected theorem isAsymm [RelHomClass F r s] (f : F) : β [IsAsymm Ξ² s], IsAsymm Ξ± r
| β¨Hβ© => β¨fun _ _ hβ hβ => H _ _ (map_rel f hβ) (map_rel f hβ)β©
protected theorem acc [RelHomClass F r s] (f : F) (a : Ξ±) : Acc s (f a) β Acc r a := by
generalize h : f a = b
intro ac
induction ac generalizing a with | intro _ H IH => ?_
subst h
exact β¨_, fun a' h => IH (f a') (map_rel f h) _ rflβ©
protected theorem wellFounded [RelHomClass F r s] (f : F) : WellFounded s β WellFounded r
| β¨Hβ© => β¨fun _ => RelHomClass.acc f _ (H _)β©
protected theorem isWellFounded [RelHomClass F r s] (f : F) [IsWellFounded Ξ² s] :
IsWellFounded Ξ± r :=
β¨RelHomClass.wellFounded f IsWellFounded.wfβ©
end RelHomClass
namespace RelHom
instance : FunLike (r βr s) Ξ± Ξ² where
coe o := o.toFun
coe_injective' f g h := by
cases f
cases g
congr
instance : RelHomClass (r βr s) r s where
map_rel := map_rel'
initialize_simps_projections RelHom (toFun β apply)
protected theorem map_rel (f : r βr s) {a b} : r a b β s (f a) (f b) :=
f.map_rel'
@[simp]
theorem coe_fn_toFun (f : r βr s) : f.toFun = (f : Ξ± β Ξ²) :=
rfl
@[simp]
theorem coeFn_mk (f : Ξ± β Ξ²) (h : β {a b}, r a b β s (f a) (f b)) :
RelHom.mk f @h = f :=
rfl
/-- The map `coe_fn : (r βr s) β (Ξ± β Ξ²)` is injective. -/
theorem coe_fn_injective : Injective fun (f : r βr s) => (f : Ξ± β Ξ²) :=
DFunLike.coe_injective
@[ext]
theorem ext β¦f g : r βr sβ¦ (h : β x, f x = g x) : f = g :=
DFunLike.ext f g h
/-- Identity map is a relation homomorphism. -/
@[refl, simps]
protected def id (r : Ξ± β Ξ± β Prop) : r βr r :=
β¨fun x => x, fun x => xβ©
/-- Composition of two relation homomorphisms is a relation homomorphism. -/
@[simps]
protected def comp (g : s βr t) (f : r βr s) : r βr t :=
β¨fun x => g (f x), fun h => g.2 (f.2 h)β©
/-- A relation homomorphism is also a relation homomorphism between dual relations. -/
@[simps]
protected def swap (f : r βr s) : swap r βr swap s :=
β¨f, f.map_relβ©
/-- A function is a relation homomorphism from the preimage relation of `s` to `s`. -/
@[simps]
def preimage (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βr s :=
β¨f, idβ©
end RelHom
/-- An increasing function is injective -/
theorem injective_of_increasing (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsTrichotomous Ξ± r]
[IsIrrefl Ξ² s] (f : Ξ± β Ξ²) (hf : β {x y}, r x y β s (f x) (f y)) : Injective f := by
intro x y hxy
rcases trichotomous_of r x y with (h | h | h)
Β· have := hf h
rw [hxy] at this
exfalso
exact irrefl_of s (f y) this
Β· exact h
Β· have := hf h
rw [hxy] at this
exfalso
exact irrefl_of s (f y) this
/-- An increasing function is injective -/
theorem RelHom.injective_of_increasing [IsTrichotomous Ξ± r] [IsIrrefl Ξ² s] (f : r βr s) :
Injective f :=
_root_.injective_of_increasing r s f f.map_rel
theorem Function.Surjective.wellFounded_iff {f : Ξ± β Ξ²} (hf : Surjective f)
(o : β {a b}, r a b β s (f a) (f b)) :
WellFounded r β WellFounded s :=
Iff.intro
(RelHomClass.wellFounded (β¨surjInv hf,
fun h => by simpa only [o, surjInv_eq hf] using hβ© : s βr r))
(RelHomClass.wellFounded (β¨f, o.1β© : r βr s))
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : Ξ± βͺ Ξ²` such that `r a b β s (f a) (f b)`. -/
structure RelEmbedding {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) extends Ξ± βͺ Ξ² where
/-- Elements are related iff they are related after apply a `RelEmbedding` -/
map_rel_iff' : β {a b}, s (toEmbedding a) (toEmbedding b) β r a b
/-- A relation embedding with respect to a given pair of relations `r` and `s`
is an embedding `f : Ξ± βͺ Ξ²` such that `r a b β s (f a) (f b)`. -/
infixl:25 " βͺr " => RelEmbedding
theorem preimage_equivalence {Ξ± Ξ²} (f : Ξ± β Ξ²) {s : Ξ² β Ξ² β Prop} (hs : Equivalence s) :
Equivalence (f β»ΒΉ'o s) :=
β¨fun _ => hs.1 _, fun h => hs.2 h, fun hβ hβ => hs.3 hβ hββ©
namespace RelEmbedding
/-- A relation embedding is also a relation homomorphism -/
def toRelHom (f : r βͺr s) : r βr s where
toFun := f.toEmbedding.toFun
map_rel' := (map_rel_iff' f).mpr
instance : Coe (r βͺr s) (r βr s) :=
β¨toRelHomβ©
-- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined
instance : FunLike (r βͺr s) Ξ± Ξ² where
coe x := x.toFun
coe_injective' f g h := by
rcases f with β¨β¨β©β©
rcases g with β¨β¨β©β©
congr
-- TODO: define and instantiate a `RelEmbeddingClass` when `EmbeddingLike` is defined
instance : RelHomClass (r βͺr s) r s where
map_rel f _ _ := Iff.mpr (map_rel_iff' f)
initialize_simps_projections RelEmbedding (toFun β apply)
instance : EmbeddingLike (r βͺr s) Ξ± Ξ² where
injective' f := f.inj'
@[simp]
theorem coe_toEmbedding {f : r βͺr s} : ((f : r βͺr s).toEmbedding : Ξ± β Ξ²) = f :=
rfl
@[simp]
theorem coe_toRelHom {f : r βͺr s} : ((f : r βͺr s).toRelHom : Ξ± β Ξ²) = f :=
rfl
theorem toEmbedding_injective : Injective (toEmbedding : r βͺr s β (Ξ± βͺ Ξ²)) := by
rintro β¨f, -β© β¨g, -β©; simp
@[simp]
theorem toEmbedding_inj {f g : r βͺr s} : f.toEmbedding = g.toEmbedding β f = g :=
toEmbedding_injective.eq_iff
theorem injective (f : r βͺr s) : Injective f :=
f.inj'
theorem inj (f : r βͺr s) {a b} : f a = f b β a = b := f.injective.eq_iff
theorem map_rel_iff (f : r βͺr s) {a b} : s (f a) (f b) β r a b :=
f.map_rel_iff'
@[simp]
theorem coe_mk {f} {h} : β(β¨f, hβ© : r βͺr s) = f :=
rfl
/-- The map `coe_fn : (r βͺr s) β (Ξ± β Ξ²)` is injective. -/
theorem coe_fn_injective : Injective fun f : r βͺr s => (f : Ξ± β Ξ²) :=
DFunLike.coe_injective
@[ext]
theorem ext β¦f g : r βͺr sβ¦ (h : β x, f x = g x) : f = g :=
DFunLike.ext _ _ h
/-- Identity map is a relation embedding. -/
@[refl, simps!]
protected def refl (r : Ξ± β Ξ± β Prop) : r βͺr r :=
β¨Embedding.refl _, Iff.rflβ©
/-- Composition of two relation embeddings is a relation embedding. -/
protected def trans (f : r βͺr s) (g : s βͺr t) : r βͺr t :=
β¨f.1.trans g.1, by simp [f.map_rel_iff, g.map_rel_iff]β©
instance (r : Ξ± β Ξ± β Prop) : Inhabited (r βͺr r) :=
β¨RelEmbedding.refl _β©
theorem trans_apply (f : r βͺr s) (g : s βͺr t) (a : Ξ±) : (f.trans g) a = g (f a) :=
rfl
@[simp]
theorem coe_trans (f : r βͺr s) (g : s βͺr t) : (f.trans g) = g β f :=
rfl
/-- A relation embedding is also a relation embedding between dual relations. -/
protected def swap (f : r βͺr s) : swap r βͺr swap s :=
β¨f.toEmbedding, f.map_rel_iffβ©
@[simp]
theorem swap_apply (f : r βͺr s) (a : Ξ±) : f.swap a = f a := rfl
/-- If `f` is injective, then it is a relation embedding from the
preimage relation of `s` to `s`. -/
def preimage (f : Ξ± βͺ Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βͺr s :=
β¨f, Iff.rflβ©
@[simp]
theorem preimage_apply (f : Ξ± βͺ Ξ²) (s : Ξ² β Ξ² β Prop) (a : Ξ±) : preimage f s a = f a := rfl
theorem eq_preimage (f : r βͺr s) : r = f β»ΒΉ'o s := by
ext a b
exact f.map_rel_iff.symm
protected theorem isIrrefl (f : r βͺr s) [IsIrrefl Ξ² s] : IsIrrefl Ξ± r :=
β¨fun a => mt f.map_rel_iff.2 (irrefl (f a))β©
protected theorem isRefl (f : r βͺr s) [IsRefl Ξ² s] : IsRefl Ξ± r :=
β¨fun _ => f.map_rel_iff.1 <| refl _β©
protected theorem isSymm (f : r βͺr s) [IsSymm Ξ² s] : IsSymm Ξ± r :=
β¨fun _ _ => imp_imp_imp f.map_rel_iff.2 f.map_rel_iff.1 symmβ©
protected theorem isAsymm (f : r βͺr s) [IsAsymm Ξ² s] : IsAsymm Ξ± r :=
β¨fun _ _ hβ hβ => asymm (f.map_rel_iff.2 hβ) (f.map_rel_iff.2 hβ)β©
protected theorem isAntisymm : β (_ : r βͺr s) [IsAntisymm Ξ² s], IsAntisymm Ξ± r
| β¨f, oβ©, β¨Hβ© => β¨fun _ _ hβ hβ => f.inj' (H _ _ (o.2 hβ) (o.2 hβ))β©
protected theorem isTrans : β (_ : r βͺr s) [IsTrans Ξ² s], IsTrans Ξ± r
| β¨_, oβ©, β¨Hβ© => β¨fun _ _ _ hβ hβ => o.1 (H _ _ _ (o.2 hβ) (o.2 hβ))β©
protected theorem isTotal : β (_ : r βͺr s) [IsTotal Ξ² s], IsTotal Ξ± r
| β¨_, oβ©, β¨Hβ© => β¨fun _ _ => (or_congr o o).1 (H _ _)β©
protected theorem isPreorder : β (_ : r βͺr s) [IsPreorder Ξ² s], IsPreorder Ξ± r
| f, _ => { f.isRefl, f.isTrans with }
protected theorem isPartialOrder : β (_ : r βͺr s) [IsPartialOrder Ξ² s], IsPartialOrder Ξ± r
| f, _ => { f.isPreorder, f.isAntisymm with }
protected theorem isLinearOrder : β (_ : r βͺr s) [IsLinearOrder Ξ² s], IsLinearOrder Ξ± r
| f, _ => { f.isPartialOrder, f.isTotal with }
protected theorem isStrictOrder : β (_ : r βͺr s) [IsStrictOrder Ξ² s], IsStrictOrder Ξ± r
| f, _ => { f.isIrrefl, f.isTrans with }
protected theorem isTrichotomous : β (_ : r βͺr s) [IsTrichotomous Ξ² s], IsTrichotomous Ξ± r
| β¨f, oβ©, β¨Hβ© => β¨fun _ _ => (or_congr o (or_congr f.inj'.eq_iff o)).1 (H _ _)β©
protected theorem isStrictTotalOrder : β (_ : r βͺr s) [IsStrictTotalOrder Ξ² s],
IsStrictTotalOrder Ξ± r
| f, _ => { f.isTrichotomous, f.isStrictOrder with }
protected theorem acc (f : r βͺr s) (a : Ξ±) : Acc s (f a) β Acc r a := by
generalize h : f a = b
intro ac
induction ac generalizing a with | intro _ H IH => ?_
subst h
exact β¨_, fun a' h => IH (f a') (f.map_rel_iff.2 h) _ rflβ©
protected theorem wellFounded : β (_ : r βͺr s) (_ : WellFounded s), WellFounded r
| f, β¨Hβ© => β¨fun _ => f.acc _ (H _)β©
protected theorem isWellFounded (f : r βͺr s) [IsWellFounded Ξ² s] : IsWellFounded Ξ± r :=
β¨f.wellFounded IsWellFounded.wfβ©
protected theorem isWellOrder : β (_ : r βͺr s) [IsWellOrder Ξ² s], IsWellOrder Ξ± r
| f, H => { f.isStrictTotalOrder with wf := f.wellFounded H.wf }
end RelEmbedding
/-- The induced relation on a subtype is an embedding under the natural inclusion. -/
@[simps!]
def Subtype.relEmbedding {X : Type*} (r : X β X β Prop) (p : X β Prop) :
(Subtype.val : Subtype p β X) β»ΒΉ'o r βͺr r :=
β¨Embedding.subtype p, Iff.rflβ©
instance Subtype.wellFoundedLT [LT Ξ±] [WellFoundedLT Ξ±] (p : Ξ± β Prop) :
WellFoundedLT (Subtype p) :=
(Subtype.relEmbedding (Β· < Β·) p).isWellFounded
instance Subtype.wellFoundedGT [LT Ξ±] [WellFoundedGT Ξ±] (p : Ξ± β Prop) :
WellFoundedGT (Subtype p) :=
(Subtype.relEmbedding (Β· > Β·) p).isWellFounded
/-- `Quotient.mk` as a relation homomorphism between the relation and the lift of a relation. -/
@[simps]
def Quotient.mkRelHom {_ : Setoid Ξ±} {r : Ξ± β Ξ± β Prop}
(H : β (aβ bβ aβ bβ : Ξ±), aβ β aβ β bβ β bβ β r aβ bβ = r aβ bβ) : r βr Quotient.liftβ r H :=
β¨Quotient.mk _, idβ©
/-- `Quotient.out` as a relation embedding between the lift of a relation and the relation. -/
@[simps!]
noncomputable def Quotient.outRelEmbedding {_ : Setoid Ξ±} {r : Ξ± β Ξ± β Prop}
(H : β (aβ bβ aβ bβ : Ξ±), aβ β aβ β bβ β bβ β r aβ bβ = r aβ bβ) : Quotient.liftβ r H βͺr r :=
β¨Embedding.quotientOut Ξ±, by
refine @fun x y => Quotient.inductionOnβ x y fun a b => ?_
apply iff_iff_eq.2 (H _ _ _ _ _ _) <;> apply Quotient.mk_outβ©
@[simp]
theorem acc_liftβ_iff {_ : Setoid Ξ±} {r : Ξ± β Ξ± β Prop}
{H : β (aβ bβ aβ bβ : Ξ±), aβ β aβ β bβ β bβ β r aβ bβ = r aβ bβ} {a} :
Acc (Quotient.liftβ r H) β¦aβ§ β Acc r a := by
constructor
Β· exact RelHomClass.acc (Quotient.mkRelHom H) a
Β· intro ac
induction ac with | intro _ _ IH => ?_
refine β¨_, fun q h => ?_β©
obtain β¨a', rflβ© := q.exists_rep
exact IH a' h
@[simp]
theorem acc_liftOnβ'_iff {s : Setoid Ξ±} {r : Ξ± β Ξ± β Prop} {H} {a} :
Acc (fun x y => Quotient.liftOnβ' x y r H) (Quotient.mk'' a : Quotient s) β Acc r a :=
acc_liftβ_iff (H := H)
/-- A relation is well founded iff its lift to a quotient is. -/
@[simp]
theorem wellFounded_liftβ_iff {_ : Setoid Ξ±} {r : Ξ± β Ξ± β Prop}
{H : β (aβ bβ aβ bβ : Ξ±), aβ β aβ β bβ β bβ β r aβ bβ = r aβ bβ} :
WellFounded (Quotient.liftβ r H) β WellFounded r := by
constructor
Β· exact RelHomClass.wellFounded (Quotient.mkRelHom H)
Β· refine fun wf => β¨fun q => ?_β©
obtain β¨a, rflβ© := q.exists_rep
exact acc_liftβ_iff.2 (wf.apply a)
alias β¨WellFounded.of_quotient_liftβ, WellFounded.quotient_liftββ© := wellFounded_liftβ_iff
@[simp]
theorem wellFounded_liftOnβ'_iff {s : Setoid Ξ±} {r : Ξ± β Ξ± β Prop} {H} :
(WellFounded fun x y : Quotient s => Quotient.liftOnβ' x y r H) β WellFounded r :=
wellFounded_liftβ_iff (H := H)
alias β¨WellFounded.of_quotient_liftOnβ', WellFounded.quotient_liftOnβ'β© := wellFounded_liftOnβ'_iff
namespace RelEmbedding
/-- To define a relation embedding from an antisymmetric relation `r` to a reflexive relation `s`
it suffices to give a function together with a proof that it satisfies `s (f a) (f b) β r a b`.
-/
def ofMapRelIff (f : Ξ± β Ξ²) [IsAntisymm Ξ± r] [IsRefl Ξ² s] (hf : β a b, s (f a) (f b) β r a b) :
r βͺr s where
toFun := f
inj' _ _ h := antisymm ((hf _ _).1 (h βΈ refl _)) ((hf _ _).1 (h βΈ refl _))
map_rel_iff' := hf _ _
@[simp]
theorem ofMapRelIff_coe (f : Ξ± β Ξ²) [IsAntisymm Ξ± r] [IsRefl Ξ² s]
(hf : β a b, s (f a) (f b) β r a b) :
(ofMapRelIff f hf : r βͺr s) = f :=
rfl
/-- It suffices to prove `f` is monotone between strict relations
to show it is a relation embedding. -/
def ofMonotone [IsTrichotomous Ξ± r] [IsAsymm Ξ² s] (f : Ξ± β Ξ²) (H : β a b, r a b β s (f a) (f b)) :
r βͺr s := by
haveI := @IsAsymm.isIrrefl Ξ² s _
refine β¨β¨f, fun a b e => ?_β©, @fun a b => β¨fun h => ?_, H _ _β©β©
Β· refine ((@trichotomous _ r _ a b).resolve_left ?_).resolve_right ?_
Β· exact fun h => irrefl (r := s) (f a) (by simpa [e] using H _ _ h)
Β· exact fun h => irrefl (r := s) (f b) (by simpa [e] using H _ _ h)
Β· refine (@trichotomous _ r _ a b).resolve_right (Or.rec (fun e => ?_) fun h' => ?_)
Β· subst e
exact irrefl _ h
Β· exact asymm (H _ _ h') h
@[simp]
theorem ofMonotone_coe [IsTrichotomous Ξ± r] [IsAsymm Ξ² s] (f : Ξ± β Ξ²) (H) :
(@ofMonotone _ _ r s _ _ f H : Ξ± β Ξ²) = f :=
rfl
/-- A relation embedding from an empty type. -/
def ofIsEmpty (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsEmpty Ξ±] : r βͺr s :=
β¨Embedding.ofIsEmpty, @fun a => isEmptyElim aβ©
/-- `Sum.inl` as a relation embedding into `Sum.LiftRel r s`. -/
@[simps]
def sumLiftRelInl (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) : r βͺr Sum.LiftRel r s where
toFun := Sum.inl
inj' := Sum.inl_injective
map_rel_iff' := Sum.liftRel_inl_inl
/-- `Sum.inr` as a relation embedding into `Sum.LiftRel r s`. -/
@[simps]
def sumLiftRelInr (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) : s βͺr Sum.LiftRel r s where
toFun := Sum.inr
inj' := Sum.inr_injective
map_rel_iff' := Sum.liftRel_inr_inr
/-- `Sum.map` as a relation embedding between `Sum.LiftRel` relations. -/
@[simps]
def sumLiftRelMap (f : r βͺr s) (g : t βͺr u) : Sum.LiftRel r t βͺr Sum.LiftRel s u where
toFun := Sum.map f g
inj' := f.injective.sumMap g.injective
map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff]
/-- `Sum.inl` as a relation embedding into `Sum.Lex r s`. -/
@[simps]
def sumLexInl (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) : r βͺr Sum.Lex r s where
toFun := Sum.inl
inj' := Sum.inl_injective
map_rel_iff' := Sum.lex_inl_inl
/-- `Sum.inr` as a relation embedding into `Sum.Lex r s`. -/
@[simps]
def sumLexInr (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) : s βͺr Sum.Lex r s where
toFun := Sum.inr
inj' := Sum.inr_injective
map_rel_iff' := Sum.lex_inr_inr
/-- `Sum.map` as a relation embedding between `Sum.Lex` relations. -/
@[simps]
def sumLexMap (f : r βͺr s) (g : t βͺr u) : Sum.Lex r t βͺr Sum.Lex s u where
toFun := Sum.map f g
inj' := f.injective.sumMap g.injective
map_rel_iff' := by rintro (a | b) (c | d) <;> simp [f.map_rel_iff, g.map_rel_iff]
/-- `fun b β¦ Prod.mk a b` as a relation embedding. -/
@[simps]
def prodLexMkLeft (s : Ξ² β Ξ² β Prop) {a : Ξ±} (h : Β¬r a a) : s βͺr Prod.Lex r s where
toFun := Prod.mk a
inj' := Prod.mk_right_injective a
map_rel_iff' := by simp [Prod.lex_def, h]
/-- `fun a β¦ Prod.mk a b` as a relation embedding. -/
@[simps]
def prodLexMkRight (r : Ξ± β Ξ± β Prop) {b : Ξ²} (h : Β¬s b b) : r βͺr Prod.Lex r s where
toFun a := (a, b)
inj' := Prod.mk_left_injective b
map_rel_iff' := by simp [Prod.lex_def, h]
/-- `Prod.map` as a relation embedding. -/
@[simps]
def prodLexMap (f : r βͺr s) (g : t βͺr u) : Prod.Lex r t βͺr Prod.Lex s u where
toFun := Prod.map f g
inj' := f.injective.prodMap g.injective
map_rel_iff' := by simp [Prod.lex_def, f.map_rel_iff, g.map_rel_iff, f.inj]
end RelEmbedding
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
structure RelIso {Ξ± Ξ² : Type*} (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) extends Ξ± β Ξ² where
/-- Elements are related iff they are related after apply a `RelIso` -/
map_rel_iff' : β {a b}, s (toEquiv a) (toEquiv b) β r a b
/-- A relation isomorphism is an equivalence that is also a relation embedding. -/
infixl:25 " βr " => RelIso
namespace RelIso
/-- Convert a `RelIso` to a `RelEmbedding`. This function is also available as a coercion
but often it is easier to write `f.toRelEmbedding` than to write explicitly `r` and `s`
in the target type. -/
def toRelEmbedding (f : r βr s) : r βͺr s :=
β¨f.toEquiv.toEmbedding, f.map_rel_iff'β©
theorem toEquiv_injective : Injective (toEquiv : r βr s β Ξ± β Ξ²)
| β¨eβ, oββ©, β¨eβ, _β©, h => by congr
instance : CoeOut (r βr s) (r βͺr s) :=
β¨toRelEmbeddingβ©
-- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined
instance : FunLike (r βr s) Ξ± Ξ² where
coe x := x
coe_injective' := Equiv.coe_fn_injective.comp toEquiv_injective
-- TODO: define and instantiate a `RelIsoClass` when `EquivLike` is defined
instance : RelHomClass (r βr s) r s where
map_rel f _ _ := Iff.mpr (map_rel_iff' f)
instance : EquivLike (r βr s) Ξ± Ξ² where
coe f := f
inv f := f.toEquiv.symm
left_inv f := f.left_inv
right_inv f := f.right_inv
coe_injective' _ _ hf _ := DFunLike.ext' hf
@[simp]
theorem coe_toRelEmbedding (f : r βr s) : (f.toRelEmbedding : Ξ± β Ξ²) = f :=
rfl
@[simp]
theorem coe_toEmbedding (f : r βr s) : (f.toEmbedding : Ξ± β Ξ²) = f :=
rfl
theorem map_rel_iff (f : r βr s) {a b} : s (f a) (f b) β r a b :=
f.map_rel_iff'
@[simp]
theorem coe_fn_mk (f : Ξ± β Ξ²) (o : β β¦a bβ¦, s (f a) (f b) β r a b) :
(RelIso.mk f @o : Ξ± β Ξ²) = f :=
rfl
@[simp]
theorem coe_fn_toEquiv (f : r βr s) : (f.toEquiv : Ξ± β Ξ²) = f :=
rfl
/-- The map `DFunLike.coe : (r βr s) β (Ξ± β Ξ²)` is injective. -/
theorem coe_fn_injective : Injective fun f : r βr s => (f : Ξ± β Ξ²) :=
DFunLike.coe_injective
@[ext]
theorem ext β¦f g : r βr sβ¦ (h : β x, f x = g x) : f = g :=
DFunLike.ext f g h
/-- Inverse map of a relation isomorphism is a relation isomorphism. -/
protected def symm (f : r βr s) : s βr r :=
β¨f.toEquiv.symm, @fun a b => by erw [β f.map_rel_iff, f.1.apply_symm_apply, f.1.apply_symm_apply]β©
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because `RelIso` defines custom coercions other than the ones given by `DFunLike`. -/
def Simps.apply (h : r βr s) : Ξ± β Ξ² :=
h
/-- See Note [custom simps projection]. -/
def Simps.symm_apply (h : r βr s) : Ξ² β Ξ± :=
h.symm
initialize_simps_projections RelIso (toFun β apply, invFun β symm_apply)
/-- Identity map is a relation isomorphism. -/
@[refl, simps! apply]
protected def refl (r : Ξ± β Ξ± β Prop) : r βr r :=
β¨Equiv.refl _, Iff.rflβ©
/-- Composition of two relation isomorphisms is a relation isomorphism. -/
@[simps! apply]
protected def trans (fβ : r βr s) (fβ : s βr t) : r βr t :=
β¨fβ.toEquiv.trans fβ.toEquiv, fβ.map_rel_iff.trans fβ.map_rel_iffβ©
instance (r : Ξ± β Ξ± β Prop) : Inhabited (r βr r) :=
β¨RelIso.refl _β©
@[simp]
theorem default_def (r : Ξ± β Ξ± β Prop) : default = RelIso.refl r :=
rfl
@[simp] lemma apply_symm_apply (e : r βr s) (x : Ξ²) : e (e.symm x) = x := e.right_inv x
@[simp] lemma symm_apply_apply (e : r βr s) (x : Ξ±) : e.symm (e x) = x := e.left_inv x
@[simp] lemma symm_comp_self (e : r βr s) : e.symm β e = id := funext e.symm_apply_apply
@[simp] lemma self_comp_symm (e : r βr s) : e β e.symm = id := funext e.apply_symm_apply
@[simp] lemma symm_trans_apply (f : r βr s) (g : s βr t) (a : Ξ³) :
(f.trans g).symm a = f.symm (g.symm a) := rfl
lemma symm_symm_apply (f : r βr s) (b : Ξ±) : f.symm.symm b = f b := rfl
lemma apply_eq_iff_eq (f : r βr s) {x y : Ξ±} : f x = f y β x = y := EquivLike.apply_eq_iff_eq f
lemma apply_eq_iff_eq_symm_apply {x : Ξ±} {y : Ξ²} (f : r βr s) : f x = y β x = f.symm y := by
conv_lhs => rw [β apply_symm_apply f y]
rw [apply_eq_iff_eq]
lemma symm_apply_eq (e : r βr s) {x y} : e.symm x = y β x = e y := e.toEquiv.symm_apply_eq
lemma eq_symm_apply (e : r βr s) {x y} : y = e.symm x β e y = x := e.toEquiv.eq_symm_apply
@[simp] lemma symm_symm (e : r βr s) : e.symm.symm = e := rfl
lemma symm_bijective : Bijective (.symm : (r βr s) β s βr r) :=
bijective_iff_has_inverse.mpr β¨_, symm_symm, symm_symmβ©
@[simp] lemma refl_symm : (RelIso.refl r).symm = .refl _ := rfl
@[simp] lemma trans_refl (e : r βr s) : e.trans (.refl _) = e := rfl
@[simp] lemma refl_trans (e : r βr s) : .trans (.refl _) e = e := rfl
@[simp] lemma symm_trans_self (e : r βr s) : e.symm.trans e = .refl _ := ext <| by simp
@[simp] lemma self_trans_symm (e : r βr s) : e.trans e.symm = .refl _ := ext <| by simp
lemma trans_assoc {Ξ΄ : Type*} {u : Ξ΄ β Ξ΄ β Prop} (ab : r βr s) (bc : s βr t) (cd : t βr u) :
(ab.trans bc).trans cd = ab.trans (bc.trans cd) := rfl
/-- A relation isomorphism between equal relations on equal types. -/
@[simps! toEquiv apply]
protected def cast {Ξ± Ξ² : Type u} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (hβ : Ξ± = Ξ²)
(hβ : r β s) : r βr s :=
β¨Equiv.cast hβ, @fun a b => by
subst hβ
rw [eq_of_heq hβ]
rflβ©
@[simp]
protected theorem cast_symm {Ξ± Ξ² : Type u} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop} (hβ : Ξ± = Ξ²)
(hβ : r β s) : (RelIso.cast hβ hβ).symm = RelIso.cast hβ.symm hβ.symm :=
rfl
@[simp]
protected theorem cast_refl {Ξ± : Type u} {r : Ξ± β Ξ± β Prop} (hβ : Ξ± = Ξ± := rfl)
(hβ : r β r := HEq.rfl) : RelIso.cast hβ hβ = RelIso.refl r :=
rfl
@[simp]
protected theorem cast_trans {Ξ± Ξ² Ξ³ : Type u} {r : Ξ± β Ξ± β Prop} {s : Ξ² β Ξ² β Prop}
{t : Ξ³ β Ξ³ β Prop} (hβ : Ξ± = Ξ²) (hβ' : Ξ² = Ξ³) (hβ : r β s) (hβ' : s β t) :
(RelIso.cast hβ hβ).trans (RelIso.cast hβ' hβ') = RelIso.cast (hβ.trans hβ') (hβ.trans hβ') :=
ext fun x => by subst hβ; rfl
/-- A relation isomorphism is also a relation isomorphism between dual relations. -/
protected def swap (f : r βr s) : swap r βr swap s :=
β¨f, f.map_rel_iffβ©
/-- A relation isomorphism is also a relation isomorphism between complemented relations. -/
@[simps!]
protected def compl (f : r βr s) : rαΆ βr sαΆ :=
β¨f, f.map_rel_iff.notβ©
@[simp]
theorem coe_fn_symm_mk (f o) : ((@RelIso.mk _ _ r s f @o).symm : Ξ² β Ξ±) = f.symm :=
rfl
theorem rel_symm_apply (e : r βr s) {x y} : r x (e.symm y) β s (e x) y := by
rw [β e.map_rel_iff, e.apply_symm_apply]
theorem symm_apply_rel (e : r βr s) {x y} : r (e.symm x) y β s x (e y) := by
rw [β e.map_rel_iff, e.apply_symm_apply]
protected theorem bijective (e : r βr s) : Bijective e :=
e.toEquiv.bijective
protected theorem injective (e : r βr s) : Injective e :=
e.toEquiv.injective
protected theorem surjective (e : r βr s) : Surjective e :=
e.toEquiv.surjective
theorem eq_iff_eq (f : r βr s) {a b} : f a = f b β a = b :=
f.injective.eq_iff
/-- Copy of a `RelIso` with a new `toFun` and `invFun` equal to the old ones.
Useful to fix definitional equalities. -/
def copy (e : r βr s) (f : Ξ± β Ξ²) (g : Ξ² β Ξ±) (hf : f = e) (hg : g = e.symm) : r βr s where
toFun := f
invFun := g
left_inv _ := by simp [hf, hg]
right_inv _ := by simp [hf, hg]
map_rel_iff' := by simp [hf, e.map_rel_iff]
@[simp, norm_cast]
lemma coe_copy (e : r βr s) (f : Ξ± β Ξ²) (g : Ξ² β Ξ±) (hf hg) : e.copy f g hf hg = f := rfl
lemma copy_eq (e : r βr s) (f : Ξ± β Ξ²) (g : Ξ² β Ξ±) (hf hg) : e.copy f g hf hg = e :=
DFunLike.coe_injective hf
/-- Any equivalence lifts to a relation isomorphism between `s` and its preimage. -/
protected def preimage (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) : f β»ΒΉ'o s βr s :=
β¨f, Iff.rflβ©
-- `simps` crashes if asked to generate these
@[simp]
theorem preimage_apply (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) (a : Ξ±) : RelIso.preimage f s a = f a := rfl
@[simp]
theorem preimage_symm_apply (f : Ξ± β Ξ²) (s : Ξ² β Ξ² β Prop) (a : Ξ²) :
(RelIso.preimage f s).symm a = f.symm a := rfl
instance IsWellOrder.preimage {Ξ± : Type u} (r : Ξ± β Ξ± β Prop) [IsWellOrder Ξ± r] (f : Ξ² β Ξ±) :
IsWellOrder Ξ² (f β»ΒΉ'o r) :=
@RelEmbedding.isWellOrder _ _ (f β»ΒΉ'o r) r (RelIso.preimage f r) _
instance IsWellOrder.ulift {Ξ± : Type u} (r : Ξ± β Ξ± β Prop) [IsWellOrder Ξ± r] :
IsWellOrder (ULift Ξ±) (ULift.down β»ΒΉ'o r) :=
IsWellOrder.preimage r Equiv.ulift
/-- A surjective relation embedding is a relation isomorphism. -/
@[simps! apply]
noncomputable def ofSurjective (f : r βͺr s) (H : Surjective f) : r βr s :=
β¨Equiv.ofBijective f β¨f.injective, Hβ©, f.map_rel_iffβ©
/-- Transport a `RelHom` across a pair of `RelIso`s, by pre- and post-composition.
This is `Equiv.arrowCongr` for `RelHom`. -/
@[simps]
def relHomCongr {Ξ±β Ξ²β Ξ±β Ξ²β}
{rβ : Ξ±β β Ξ±β β Prop} {sβ : Ξ²β β Ξ²β β Prop} {rβ : Ξ±β β Ξ±β β Prop} {sβ : Ξ²β β Ξ²β β Prop}
(eβ : rβ βr rβ) (eβ : sβ βr sβ) :
(rβ βr sβ) β (rβ βr sβ) where
toFun fβ := eβ.toRelEmbedding.toRelHom.comp <| fβ.comp eβ.symm.toRelEmbedding.toRelHom
invFun fβ := eβ.symm.toRelEmbedding.toRelHom.comp <| fβ.comp eβ.toRelEmbedding.toRelHom
left_inv fβ := by ext; simp
right_inv fβ := by ext; simp
/-- Given relation isomorphisms `rβ βr sβ` and `rβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the sum.
-/
def sumLexCongr {Ξ±β Ξ±β Ξ²β Ξ²β rβ rβ sβ sβ} (eβ : @RelIso Ξ±β Ξ²β rβ sβ) (eβ : @RelIso Ξ±β Ξ²β rβ sβ) :
Sum.Lex rβ rβ βr Sum.Lex sβ sβ :=
β¨Equiv.sumCongr eβ.toEquiv eβ.toEquiv, @fun a b => by
obtain β¨f, hfβ© := eβ; obtain β¨g, hgβ© := eβ; cases a <;> cases b <;> simp [hf, hg]β©
/-- Given relation isomorphisms `rβ βr sβ` and `rβ βr sβ`, construct a relation isomorphism for the
lexicographic orders on the product.
-/
def prodLexCongr {Ξ±β Ξ±β Ξ²β Ξ²β rβ rβ sβ sβ} (eβ : @RelIso Ξ±β Ξ²β rβ sβ) (eβ : @RelIso Ξ±β Ξ²β rβ sβ) :
Prod.Lex rβ rβ βr Prod.Lex sβ sβ :=
β¨Equiv.prodCongr eβ.toEquiv eβ.toEquiv, by simp [Prod.lex_def, eβ.map_rel_iff, eβ.map_rel_iff,
eβ.injective.eq_iff]β©
/-- Two relations on empty types are isomorphic. -/
def relIsoOfIsEmpty (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsEmpty Ξ±] [IsEmpty Ξ²] : r βr s :=
β¨Equiv.equivOfIsEmpty Ξ± Ξ², @fun a => isEmptyElim aβ©
/-- The lexicographic sum of `r` plus an empty relation is isomorphic to `r`. -/
@[simps!]
def sumLexEmpty (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsEmpty Ξ²] : Sum.Lex r s βr r :=
β¨Equiv.sumEmpty _ _, by simpβ©
/-- The lexicographic sum of an empty relation plus `s` is isomorphic to `s`. -/
@[simps!]
def emptySumLex (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsEmpty Ξ±] : Sum.Lex r s βr s :=
β¨Equiv.emptySum _ _, by simpβ©
/-- Two irreflexive relations on a unique type are isomorphic. -/
def ofUniqueOfIrrefl (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsIrrefl Ξ± r]
[IsIrrefl Ξ² s] [Unique Ξ±] [Unique Ξ²] : r βr s :=
β¨Equiv.ofUnique Ξ± Ξ², iff_of_false (not_rel_of_subsingleton s _ _)
(not_rel_of_subsingleton r _ _) β©
/-- Two reflexive relations on a unique type are isomorphic. -/
def ofUniqueOfRefl (r : Ξ± β Ξ± β Prop) (s : Ξ² β Ξ² β Prop) [IsRefl Ξ± r] [IsRefl Ξ² s]
[Unique Ξ±] [Unique Ξ²] : r βr s :=
β¨Equiv.ofUnique Ξ± Ξ², iff_of_true (rel_of_subsingleton s _ _) (rel_of_subsingleton r _ _)β©
end RelIso
|
numfield.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 ssrAC div fintype path bigop order finset fingroup.
From mathcomp Require Import ssralg poly orderedzmod numdomain.
(******************************************************************************)
(* Number structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines some classes to manipulate number structures, i.e, *)
(* structures with an order and a norm. To use this file, insert *)
(* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *)
(* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *)
(* of Num.leif, etc.). *)
(* *)
(* This file defines the following number structures: *)
(* *)
(* numFieldType == Field with an order and a norm *)
(* The HB class is called NumField. *)
(* numClosedFieldType == Partially ordered Closed Field with conjugation *)
(* The HB class is called ClosedField. *)
(* realDomainType == Num domain where all elements are positive or negative *)
(* The HB class is called RealDomain. *)
(* realFieldType == Num Field where all elements are positive or negative *)
(* The HB class is called RealField. *)
(* rcfType == A Real Field with the real closed axiom *)
(* The HB class is called RealClosedField. *)
(* *)
(* Over these structures, we have the following operation: *)
(* Num.sqrt x == in a real-closed field, a positive square root of x if *)
(* x >= 0, or 0 otherwise *)
(* For numeric algebraically closed fields we provide the generic definitions *)
(* '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). *)
(* *)
(* - list of prefixes : *)
(* p : positive *)
(* n : negative *)
(* sp : strictly positive *)
(* sn : strictly negative *)
(* i : interior = in [0, 1] or ]0, 1[ *)
(* e : exterior = in [1, +oo[ or ]1; +oo[ *)
(* w : non strict (weak) monotony *)
(* *)
(* Pdeg2.NumClosed : theory of the degree 2 polynomials on NumClosedField. *)
(* Pdeg2.NumClosedMonic : theory of Pdeg2.NumClosed specialized to monic *)
(* polynomials. *)
(* Pdeg2.Real : theory of the degree 2 polynomials on RealField and rcfType. *)
(* Pdeg2.RealMonic : theory of Pdeg2.Real specialized to monic polynomials. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope order_scope.
Local Open Scope group_scope.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory.
Import orderedzmod.Num numdomain.Num.
Module Num.
#[short(type="numFieldType")]
HB.structure Definition NumField := { R of GRing.UnitRing_isField R &
GRing.IntegralDomain R &
POrderedZmodule R &
NormedZmodule (POrderedZmodule.clone R _) R &
isNumRing R }.
Module NumFieldExports.
Bind Scope ring_scope with NumField.sort.
End NumFieldExports.
HB.export NumFieldExports.
HB.mixin Record NumField_isImaginary R of NumField R := {
imaginary : R;
conj_op : {rmorphism R -> R};
sqrCi : imaginary ^+ 2 = - 1;
normCK : forall x, `|x| ^+ 2 = x * conj_op x;
}.
#[short(type="numClosedFieldType")]
HB.structure Definition ClosedField :=
{ R of NumField_isImaginary R & GRing.ClosedField R & NumField R }.
Module ClosedFieldExports.
Bind Scope ring_scope with ClosedField.sort.
End ClosedFieldExports.
HB.export ClosedFieldExports.
#[short(type="realFieldType")]
HB.structure Definition RealField :=
{ R of Order.Total ring_display R & NumField R }.
Module RealFieldExports.
Bind Scope ring_scope with RealField.sort.
End RealFieldExports.
HB.export RealFieldExports.
HB.mixin Record RealField_isClosed R of RealField R := {
poly_ivt_subproof : real_closed_axiom R
}.
#[short(type="rcfType")]
HB.structure Definition RealClosedField :=
{ R of RealField_isClosed R & RealField R }.
Module RealClosedFieldExports.
Bind Scope ring_scope with RealClosedField.sort.
End RealClosedFieldExports.
HB.export RealClosedFieldExports.
Section RealClosed.
Variable R : rcfType.
Lemma poly_ivt : real_closed_axiom R. Proof. exact: poly_ivt_subproof. Qed.
Fact sqrtr_subproof (x : R) :
exists2 y, 0 <= y & (if 0 <= x then y ^+ 2 == x else y == 0) : bool.
Proof.
case x_ge0: (0 <= x); last by exists 0.
have le0x1: 0 <= x + 1 by rewrite -nnegrE rpredD ?rpred1.
have [|y /andP[y_ge0 _]] := @poly_ivt ('X^2 - x%:P) _ _ le0x1.
rewrite !hornerE -subr_ge0 add0r expr0n sub0r opprK x_ge0 sqrrD mulr1.
by rewrite addrAC !addrA addrK -nnegrE !rpredD ?rpredX ?rpred1.
by rewrite rootE !hornerE subr_eq0; exists y.
Qed.
End RealClosed.
Module Import Def.
Definition sqrtr {R} x := s2val (sig2W (@sqrtr_subproof R x)).
End Def.
Notation sqrt := sqrtr.
Module Export Theory.
Section NumFieldTheory.
Variable F : numFieldType.
Implicit Types x y z t : F.
Lemma unitf_gt0 x : 0 < x -> x \is a GRing.unit.
Proof. by move=> hx; rewrite unitfE eq_sym lt_eqF. Qed.
Lemma unitf_lt0 x : x < 0 -> x \is a GRing.unit.
Proof. by move=> hx; rewrite unitfE lt_eqF. Qed.
Lemma lef_pV2 : {in pos &, {mono (@GRing.inv F) : x y /~ x <= y}}.
Proof. by move=> x y hx hy /=; rewrite ler_pV2 ?inE ?unitf_gt0. Qed.
Lemma lef_nV2 : {in neg &, {mono (@GRing.inv F) : x y /~ x <= y}}.
Proof. by move=> x y hx hy /=; rewrite ler_nV2 ?inE ?unitf_lt0. Qed.
Lemma ltf_pV2 : {in pos &, {mono (@GRing.inv F) : x y /~ x < y}}.
Proof. exact: leW_nmono_in lef_pV2. Qed.
Lemma ltf_nV2 : {in neg &, {mono (@GRing.inv F) : x y /~ x < y}}.
Proof. exact: leW_nmono_in lef_nV2. Qed.
Definition ltef_pV2 := (lef_pV2, ltf_pV2).
Definition ltef_nV2 := (lef_nV2, ltf_nV2).
Lemma invf_pgt : {in pos &, forall x y, (x < y^-1) = (y < x^-1)}.
Proof. by move=> x y *; rewrite -[x in LHS]invrK ltf_pV2// posrE invr_gt0. Qed.
Lemma invf_pge : {in pos &, forall x y, (x <= y^-1) = (y <= x^-1)}.
Proof. by move=> x y *; rewrite -[x in LHS]invrK lef_pV2// posrE invr_gt0. Qed.
Lemma invf_ngt : {in neg &, forall x y, (x < y^-1) = (y < x^-1)}.
Proof. by move=> x y *; rewrite -[x in LHS]invrK ltf_nV2// negrE invr_lt0. Qed.
Lemma invf_nge : {in neg &, forall x y, (x <= y^-1) = (y <= x^-1)}.
Proof. by move=> x y *; rewrite -[x in LHS]invrK lef_nV2// negrE invr_lt0. Qed.
Lemma invf_gt1 x : 0 < x -> (1 < x^-1) = (x < 1).
Proof. by move=> x0; rewrite invf_pgt ?invr1 ?posrE. Qed.
Lemma invf_ge1 x : 0 < x -> (1 <= x^-1) = (x <= 1).
Proof. by move=> x0; rewrite invf_pge ?invr1 ?posrE. Qed.
Definition invf_gte1 := (invf_ge1, invf_gt1).
Lemma invf_plt : {in pos &, forall x y, (x^-1 < y) = (y^-1 < x)}.
Proof. by move=> x y *; rewrite -[y in LHS]invrK ltf_pV2// posrE invr_gt0. Qed.
Lemma invf_ple : {in pos &, forall x y, (x^-1 <= y) = (y^-1 <= x)}.
Proof. by move=> x y *; rewrite -[y in LHS]invrK lef_pV2// posrE invr_gt0. Qed.
Lemma invf_nlt : {in neg &, forall x y, (x^-1 < y) = (y^-1 < x)}.
Proof. by move=> x y *; rewrite -[y in LHS]invrK ltf_nV2// negrE invr_lt0. Qed.
Lemma invf_nle : {in neg &, forall x y, (x^-1 <= y) = (y^-1 <= x)}.
Proof. by move=> x y *; rewrite -[y in LHS]invrK lef_nV2// negrE invr_lt0. Qed.
Lemma invf_le1 x : 0 < x -> (x^-1 <= 1) = (1 <= x).
Proof. by move=> x0; rewrite -invf_ple ?invr1 ?posrE. Qed.
Lemma invf_lt1 x : 0 < x -> (x^-1 < 1) = (1 < x).
Proof. by move=> x0; rewrite invf_plt ?invr1 ?posrE. Qed.
Definition invf_lte1 := (invf_le1, invf_lt1).
Definition invf_cp1 := (invf_gte1, invf_lte1).
(* These lemma are all combinations of mono(LR|RL) with ler_[pn]mul2[rl]. *)
Lemma ler_pdivlMr z x y : 0 < z -> (x <= y / z) = (x * z <= y).
Proof. by move=> z_gt0; rewrite -(@ler_pM2r _ z _ x) ?mulfVK ?gt_eqF. Qed.
Lemma ltr_pdivlMr z x y : 0 < z -> (x < y / z) = (x * z < y).
Proof. by move=> z_gt0; rewrite -(@ltr_pM2r _ z _ x) ?mulfVK ?gt_eqF. Qed.
Definition lter_pdivlMr := (ler_pdivlMr, ltr_pdivlMr).
Lemma ler_pdivrMr z x y : 0 < z -> (y / z <= x) = (y <= x * z).
Proof. by move=> z_gt0; rewrite -(@ler_pM2r _ z) ?mulfVK ?gt_eqF. Qed.
Lemma ltr_pdivrMr z x y : 0 < z -> (y / z < x) = (y < x * z).
Proof. by move=> z_gt0; rewrite -(@ltr_pM2r _ z) ?mulfVK ?gt_eqF. Qed.
Definition lter_pdivrMr := (ler_pdivrMr, ltr_pdivrMr).
Lemma ler_pdivlMl z x y : 0 < z -> (x <= z^-1 * y) = (z * x <= y).
Proof. by move=> z_gt0; rewrite mulrC ler_pdivlMr ?[z * _]mulrC. Qed.
Lemma ltr_pdivlMl z x y : 0 < z -> (x < z^-1 * y) = (z * x < y).
Proof. by move=> z_gt0; rewrite mulrC ltr_pdivlMr ?[z * _]mulrC. Qed.
Definition lter_pdivlMl := (ler_pdivlMl, ltr_pdivlMl).
Lemma ler_pdivrMl z x y : 0 < z -> (z^-1 * y <= x) = (y <= z * x).
Proof. by move=> z_gt0; rewrite mulrC ler_pdivrMr ?[z * _]mulrC. Qed.
Lemma ltr_pdivrMl z x y : 0 < z -> (z^-1 * y < x) = (y < z * x).
Proof. by move=> z_gt0; rewrite mulrC ltr_pdivrMr ?[z * _]mulrC. Qed.
Definition lter_pdivrMl := (ler_pdivrMl, ltr_pdivrMl).
Lemma ler_ndivlMr z x y : z < 0 -> (x <= y / z) = (y <= x * z).
Proof. by move=> z_lt0; rewrite -(@ler_nM2r _ z) ?mulfVK ?lt_eqF. Qed.
Lemma ltr_ndivlMr z x y : z < 0 -> (x < y / z) = (y < x * z).
Proof. by move=> z_lt0; rewrite -(@ltr_nM2r _ z) ?mulfVK ?lt_eqF. Qed.
Definition lter_ndivlMr := (ler_ndivlMr, ltr_ndivlMr).
Lemma ler_ndivrMr z x y : z < 0 -> (y / z <= x) = (x * z <= y).
Proof. by move=> z_lt0; rewrite -(@ler_nM2r _ z) ?mulfVK ?lt_eqF. Qed.
Lemma ltr_ndivrMr z x y : z < 0 -> (y / z < x) = (x * z < y).
Proof. by move=> z_lt0; rewrite -(@ltr_nM2r _ z) ?mulfVK ?lt_eqF. Qed.
Definition lter_ndivrMr := (ler_ndivrMr, ltr_ndivrMr).
Lemma ler_ndivlMl z x y : z < 0 -> (x <= z^-1 * y) = (y <= z * x).
Proof. by move=> z_lt0; rewrite mulrC ler_ndivlMr ?[z * _]mulrC. Qed.
Lemma ltr_ndivlMl z x y : z < 0 -> (x < z^-1 * y) = (y < z * x).
Proof. by move=> z_lt0; rewrite mulrC ltr_ndivlMr ?[z * _]mulrC. Qed.
Definition lter_ndivlMl := (ler_ndivlMl, ltr_ndivlMl).
Lemma ler_ndivrMl z x y : z < 0 -> (z^-1 * y <= x) = (z * x <= y).
Proof. by move=> z_lt0; rewrite mulrC ler_ndivrMr ?[z * _]mulrC. Qed.
Lemma ltr_ndivrMl z x y : z < 0 -> (z^-1 * y < x) = (z * x < y).
Proof. by move=> z_lt0; rewrite mulrC ltr_ndivrMr ?[z * _]mulrC. Qed.
Definition lter_ndivrMl := (ler_ndivrMl, ltr_ndivrMl).
Lemma natf_div m d : (d %| m)%N -> (m %/ d)%:R = m%:R / d%:R :> F.
Proof. by apply: pchar0_natf_div; apply: (@pchar_num F). Qed.
Lemma normfV : {morph (norm : F -> F) : x / x ^-1}.
Proof.
move=> x /=; have [/normrV //|Nux] := boolP (x \is a GRing.unit).
by rewrite !invr_out // unitfE normr_eq0 -unitfE.
Qed.
Lemma normf_div : {morph (norm : F -> F) : x y / x / y}.
Proof. by move=> x y /=; rewrite normrM normfV. Qed.
Lemma invr_sg x : (sg x)^-1 = sgr x.
Proof. by rewrite !(fun_if GRing.inv) !(invr0, invrN, invr1). Qed.
Lemma sgrV x : sgr x^-1 = sgr x.
Proof. by rewrite /sgr invr_eq0 invr_lt0. Qed.
Lemma splitr x : x = x / 2%:R + x / 2%:R.
Proof. by rewrite -mulr2n -[RHS]mulr_natr mulfVK //= pnatr_eq0. Qed.
(* lteif *)
Lemma lteif_pdivlMr C z x y :
0 < z -> x < y / z ?<= if C = (x * z < y ?<= if C).
Proof. by case: C => ? /=; rewrite lter_pdivlMr. Qed.
Lemma lteif_pdivrMr C z x y :
0 < z -> y / z < x ?<= if C = (y < x * z ?<= if C).
Proof. by case: C => ? /=; rewrite lter_pdivrMr. Qed.
Lemma lteif_pdivlMl C z x y :
0 < z -> x < z^-1 * y ?<= if C = (z * x < y ?<= if C).
Proof. by case: C => ? /=; rewrite lter_pdivlMl. Qed.
Lemma lteif_pdivrMl C z x y :
0 < z -> z^-1 * y < x ?<= if C = (y < z * x ?<= if C).
Proof. by case: C => ? /=; rewrite lter_pdivrMl. Qed.
Lemma lteif_ndivlMr C z x y :
z < 0 -> x < y / z ?<= if C = (y < x * z ?<= if C).
Proof. by case: C => ? /=; rewrite lter_ndivlMr. Qed.
Lemma lteif_ndivrMr C z x y :
z < 0 -> y / z < x ?<= if C = (x * z < y ?<= if C).
Proof. by case: C => ? /=; rewrite lter_ndivrMr. Qed.
Lemma lteif_ndivlMl C z x y :
z < 0 -> x < z^-1 * y ?<= if C = (y < z * x ?<= if C).
Proof. by case: C => ? /=; rewrite lter_ndivlMl. Qed.
Lemma lteif_ndivrMl C z x y :
z < 0 -> z^-1 * y < x ?<= if C = (z * x < y ?<= if C).
Proof. by case: C => ? /=; rewrite lter_ndivrMl. Qed.
(* Interval midpoint. *)
Local Notation mid x y := ((x + y) / 2).
Lemma midf_le x y : x <= y -> (x <= mid x y) * (mid x y <= y).
Proof.
move=> lexy; rewrite ler_pdivlMr ?ler_pdivrMr ?ltr0Sn //.
by rewrite !mulrDr !mulr1 !lerD2.
Qed.
Lemma midf_lt x y : x < y -> (x < mid x y) * (mid x y < y).
Proof.
move=> ltxy; rewrite ltr_pdivlMr ?ltr_pdivrMr ?ltr0Sn //.
by rewrite !mulrDr !mulr1 !ltrD2.
Qed.
Definition midf_lte := (midf_le, midf_lt).
Lemma ler_addgt0Pr x y : reflect (forall e, e > 0 -> x <= y + e) (x <= y).
Proof.
apply/(iffP idP)=> [lexy e e_gt0 | lexye]; first by rewrite ler_wpDr// ltW.
have [||ltyx]// := comparable_leP.
rewrite (@comparabler_trans _ (y + 1))// /Order.comparable ?lexye ?ltr01//.
by rewrite lerDl ler01 orbT.
have /midf_lt [_] := ltyx; rewrite le_gtF//.
rewrite -(@addrK _ y y) (addrAC _ _ x) -addrA 2!mulrDl -splitr lexye//.
by rewrite divr_gt0// ?ltr0n// subr_gt0.
Qed.
Lemma ler_addgt0Pl x y : reflect (forall e, e > 0 -> x <= e + y) (x <= y).
Proof.
by apply/(equivP (ler_addgt0Pr x y)); split=> lexy e /lexy; rewrite addrC.
Qed.
Lemma lt_le a b : (forall x, x < a -> x < b) -> a <= b.
Proof.
move=> ab; apply/ler_addgt0Pr => e e_gt0; rewrite -lerBDr ltW//.
by rewrite ab// ltrBlDr ltrDl.
Qed.
Lemma gt_ge a b : (forall x, b < x -> a < x) -> a <= b.
Proof.
by move=> ab; apply/ler_addgt0Pr => e e_gt0; rewrite ltW// ab// ltrDl.
Qed.
(* The AGM, unscaled but without the nth root. *)
Lemma real_leif_mean_square x y :
x \is real -> y \is real -> x * y <= mid (x ^+ 2) (y ^+ 2) ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite -(mono_leif (ler_pM2r (ltr_nat F 0 2))).
by rewrite divfK ?pnatr_eq0 // mulr_natr; apply: real_leif_mean_square_scaled.
Qed.
Lemma real_leif_AGM2 x y :
x \is real -> y \is real -> x * y <= mid x y ^+ 2 ?= iff (x == y).
Proof.
move=> Rx Ry; rewrite -(mono_leif (ler_pM2r (ltr_nat F 0 4))).
rewrite mulr_natr (natrX F 2 2) -exprMn divfK ?pnatr_eq0 //.
exact: real_leif_AGM2_scaled.
Qed.
Lemma leif_AGM (I : finType) (A : {pred I}) (E : I -> F) :
let n := #|A| in let mu := (\sum_(i in A) E i) / n%:R in
{in A, forall i, 0 <= E i} ->
\prod_(i in A) E i <= mu ^+ n
?= iff [forall i in A, forall j in A, E i == E j].
Proof.
move=> n mu Ege0; have [n0 | n_gt0] := posnP n.
by rewrite n0 -big_andE !(big_pred0 _ _ _ _ (card0_eq n0)); apply/leifP.
pose E' i := E i / n%:R.
have defE' i: E' i *+ n = E i by rewrite -mulr_natr divfK ?pnatr_eq0 -?lt0n.
have /leif_AGM_scaled (i): i \in A -> 0 <= E' i *+ n by rewrite defE' => /Ege0.
rewrite -/n -mulr_suml (eq_bigr _ (in1W defE')); congr (_ <= _ ?= iff _).
by do 2![apply: eq_forallb_in => ? _]; rewrite -(eqr_pMn2r n_gt0) !defE'.
Qed.
Implicit Type p : {poly F}.
Lemma Cauchy_root_bound p : p != 0 -> {b | forall x, root p x -> `|x| <= b}.
Proof.
move=> nz_p; set a := lead_coef p; set n := (size p).-1.
have [q Dp]: {q | forall x, x != 0 -> p.[x] = (a - q.[x^-1] / x) * x ^+ n}.
exists (- \poly_(i < n) p`_(n - i.+1)) => x nz_x.
rewrite hornerN mulNr opprK horner_poly mulrDl !mulr_suml addrC.
rewrite horner_coef polySpred // big_ord_recr (reindex_inj rev_ord_inj) /=.
rewrite -/n -lead_coefE; congr (_ + _); apply: eq_bigr=> i _.
by rewrite exprB ?unitfE // -exprVn mulrA mulrAC exprSr mulrA.
have [b ub_q] := poly_disk_bound q 1; exists (b / `|a| + 1) => x px0.
have b_ge0: 0 <= b by rewrite (le_trans (normr_ge0 q.[1])) ?ub_q ?normr1.
have{b_ge0} ba_ge0: 0 <= b / `|a| by rewrite divr_ge0.
rewrite real_leNgt ?rpredD ?rpred1 ?ger0_real //.
apply: contraL px0 => lb_x; rewrite rootE.
have x_ge1: 1 <= `|x| by rewrite (le_trans _ (ltW lb_x)) // ler_wpDl.
have nz_x: x != 0 by rewrite -normr_gt0 (lt_le_trans ltr01).
rewrite {}Dp // mulf_neq0 ?expf_neq0 // subr_eq0 eq_sym.
have: (b / `|a|) < `|x| by rewrite (lt_trans _ lb_x) // ltr_pwDr ?ltr01.
apply: contraTneq => /(canRL (divfK nz_x))Dax.
rewrite ltr_pdivrMr ?normr_gt0 ?lead_coef_eq0 // mulrC -normrM -{}Dax.
by rewrite le_gtF // ub_q // normfV invf_le1 ?normr_gt0.
Qed.
Lemma natf_indexg (gT : finGroupType) (G H : {group gT}) :
H \subset G -> #|G : H|%:R = (#|G|%:R / #|H|%:R)%R :> F.
Proof. by move=> sHG; rewrite -divgS // natf_div ?cardSg. Qed.
End NumFieldTheory.
Section RealField.
Variables F : realFieldType.
Implicit Type x y : F.
Lemma leif_mean_square x y : x * y <= (x ^+ 2 + y ^+ 2) / 2 ?= iff (x == y).
Proof. by apply: real_leif_mean_square; apply: num_real. Qed.
Lemma leif_AGM2 x y : x * y <= ((x + y) / 2)^+ 2 ?= iff (x == y).
Proof. by apply: real_leif_AGM2; apply: num_real. Qed.
Section MinMax.
Lemma maxr_absE x y : Num.max x y = (x + y + `|x - y|) / 2.
Proof.
apply: canRL (mulfK _) _ => //; rewrite ?pnatr_eq0//.
case: lerP => _; rewrite [2]mulr2n mulrDr mulr1.
by rewrite addrCA addrK.
by rewrite addrCA addrAC subrr add0r.
Qed.
Lemma minr_absE x y : Num.min x y = (x + y - `|x - y|) / 2.
Proof.
apply: (addrI (Num.max x y)); rewrite addr_max_min maxr_absE.
by rewrite -mulrDl addrCA addrK mulrDl -splitr.
Qed.
End MinMax.
End RealField.
Section RealClosedFieldTheory.
Variable R : rcfType.
Implicit Types a x y : R.
Lemma poly_ivt : real_closed_axiom R. Proof. exact: poly_ivt. Qed.
(* Square Root theory *)
Lemma sqrtr_ge0 a : 0 <= sqrt a.
Proof. by rewrite /sqrt; case: (sig2W _). Qed.
Hint Resolve sqrtr_ge0 : core.
Lemma sqr_sqrtr a : 0 <= a -> sqrt a ^+ 2 = a.
Proof.
by rewrite /sqrt => a_ge0; case: (sig2W _) => /= x _; rewrite a_ge0 => /eqP.
Qed.
Lemma ler0_sqrtr a : a <= 0 -> sqrt a = 0.
Proof.
rewrite /sqrtr; case: (sig2W _) => x /= _.
by have [//|_ /eqP//|->] := ltrgt0P a; rewrite mulf_eq0 orbb => /eqP.
Qed.
Lemma ltr0_sqrtr a : a < 0 -> sqrt a = 0.
Proof. by move=> /ltW; apply: ler0_sqrtr. Qed.
Variant sqrtr_spec a : R -> bool -> bool -> R -> Type :=
| IsNoSqrtr of a < 0 : sqrtr_spec a a false true 0
| IsSqrtr b of 0 <= b : sqrtr_spec a (b ^+ 2) true false b.
Lemma sqrtrP a : sqrtr_spec a a (0 <= a) (a < 0) (sqrt a).
Proof.
have [a_ge0|a_lt0] := ger0P a.
by rewrite -{1 2}[a]sqr_sqrtr //; constructor.
by rewrite ltr0_sqrtr //; constructor.
Qed.
Lemma sqrtr_sqr a : sqrt (a ^+ 2) = `|a|.
Proof.
have /eqP : sqrt (a ^+ 2) ^+ 2 = `|a| ^+ 2.
by rewrite -normrX ger0_norm ?sqr_sqrtr ?sqr_ge0.
rewrite eqf_sqr => /predU1P[-> //|ha].
have := sqrtr_ge0 (a ^+ 2); rewrite (eqP ha) oppr_ge0 normr_le0 => /eqP ->.
by rewrite normr0 oppr0.
Qed.
Lemma sqrtrM a b : 0 <= a -> sqrt (a * b) = sqrt a * sqrt b.
Proof.
case: (sqrtrP a) => // {}a a_ge0 _; case: (sqrtrP b) => [b_lt0 | {}b b_ge0].
by rewrite mulr0 ler0_sqrtr // nmulr_lle0 ?mulr_ge0.
by rewrite mulrACA sqrtr_sqr ger0_norm ?mulr_ge0.
Qed.
Lemma sqrtr0 : sqrt 0 = 0 :> R.
Proof. by move: (sqrtr_sqr 0); rewrite exprS mul0r => ->; rewrite normr0. Qed.
Lemma sqrtr1 : sqrt 1 = 1 :> R.
Proof. by move: (sqrtr_sqr 1); rewrite expr1n => ->; rewrite normr1. Qed.
Lemma sqrtr_eq0 a : (sqrt a == 0) = (a <= 0).
Proof.
case: sqrtrP => [/ltW ->|b]; first by rewrite eqxx.
case: ltrgt0P => [b_gt0|//|->]; last by rewrite exprS mul0r lexx.
by rewrite lt_geF ?pmulr_rgt0.
Qed.
Lemma sqrtr_gt0 a : (0 < sqrt a) = (0 < a).
Proof. by rewrite lt0r sqrtr_ge0 sqrtr_eq0 -ltNge andbT. Qed.
Lemma eqr_sqrt a b : 0 <= a -> 0 <= b -> (sqrt a == sqrt b) = (a == b).
Proof.
move=> a_ge0 b_ge0; apply/eqP/eqP=> [HS|->] //.
by move: (sqr_sqrtr a_ge0); rewrite HS (sqr_sqrtr b_ge0).
Qed.
Lemma ler_wsqrtr : {homo @sqrt R : a b / a <= b}.
Proof.
move=> a b /= le_ab; case: (boolP (0 <= a))=> [pa|]; last first.
by rewrite -ltNge; move/ltW; rewrite -sqrtr_eq0; move/eqP->.
rewrite -(@ler_pXn2r R 2) ?nnegrE ?sqrtr_ge0 //.
by rewrite !sqr_sqrtr // (le_trans pa).
Qed.
Lemma ler_psqrt : {in @nneg R &, {mono sqrt : a b / a <= b}}.
Proof.
apply: le_mono_in => x y x_gt0 y_gt0.
rewrite !lt_neqAle => /andP[neq_xy le_xy].
by rewrite ler_wsqrtr // eqr_sqrt // neq_xy.
Qed.
Lemma ler_sqrt a b : 0 <= b -> (sqrt a <= sqrt b) = (a <= b).
Proof.
move=> b_ge0; have [a_le0|a_gt0] := ler0P a; last first.
by rewrite ler_psqrt // nnegrE ltW.
by rewrite ler0_sqrtr // sqrtr_ge0 (le_trans a_le0).
Qed.
Lemma ltr_sqrt a b : 0 < b -> (sqrt a < sqrt b) = (a < b).
Proof.
move=> b_gt0; have [a_le0|a_gt0] := ler0P a; last first.
by rewrite (leW_mono_in ler_psqrt)//; apply: ltW.
by rewrite ler0_sqrtr // sqrtr_gt0 b_gt0 (le_lt_trans a_le0).
Qed.
Lemma sqrtrV x : 0 <= x -> sqrt (x^-1) = (sqrt x)^-1.
Proof.
case: ltrgt0P => // [x_gt0 _|->]; last by rewrite !(invr0, sqrtr0).
have sx_neq0 : sqrt x != 0 by rewrite sqrtr_eq0 -ltNge.
apply: (mulfI sx_neq0).
by rewrite -sqrtrM !(divff, ltW, sqrtr1) // lt0r_neq0.
Qed.
End RealClosedFieldTheory.
Notation "z ^*" := (conj_op z) : ring_scope.
Notation "'i" := imaginary : ring_scope.
Section ClosedFieldTheory.
Variable C : numClosedFieldType.
Implicit Types a x y z : C.
Definition normCK : forall x, `|x| ^+ 2 = x * x^* := normCK.
Definition sqrCi : 'i ^+ 2 = -1 :> C := sqrCi.
Lemma mulCii : 'i * 'i = -1 :> C. Proof. exact: sqrCi. Qed.
Lemma conjCK : involutive (@conj_op C).
Proof.
have JE x : x^* = `|x|^+2 / x.
have [->|x_neq0] := eqVneq x 0; first by rewrite rmorph0 invr0 mulr0.
by apply: (canRL (mulfK _)) => //; rewrite mulrC -normCK.
move=> x; have [->|x_neq0] := eqVneq x 0; first by rewrite !rmorph0.
rewrite !JE normrM normfV exprMn normrX normr_id.
rewrite invfM exprVn (AC (2*2) (1*(2*3)*4))/= -invfM -exprMn.
by rewrite divff ?mul1r ?invrK // !expf_eq0 normr_eq0 //.
Qed.
Let Re2 z := z + z^*.
Definition nnegIm z := (0 <= 'i * (z^* - z)).
Definition argCle y z := nnegIm z ==> nnegIm y && (Re2 z <= Re2 y).
Variant rootC_spec n (x : C) : Type :=
RootCspec (y : C) of if (n > 0)%N then y ^+ n = x else y = 0
& forall z, (n > 0)%N -> z ^+ n = x -> argCle y z.
Fact rootC_subproof n x : rootC_spec n x.
Proof.
have realRe2 u : Re2 u \is Num.real by
rewrite realEsqr expr2 {2}/Re2 -{2}[u]conjCK addrC -rmorphD -normCK exprn_ge0.
have argCle_total : total argCle.
move=> u v; rewrite /total /argCle.
by do 2!case: (nnegIm _) => //; rewrite ?orbT //= real_leVge.
have argCle_trans : transitive argCle.
move=> u v w /implyP geZuv /implyP geZvw; apply/implyP.
by case/geZvw/andP=> /geZuv/andP[-> geRuv] /le_trans->.
pose p := 'X^n - (x *+ (n > 0))%:P; have [r0 Dp] := closed_field_poly_normal p.
have sz_p : size p = n.+1.
rewrite size_polyDl ?size_polyXn // ltnS size_polyN size_polyC mulrn_eq0.
by case: posnP => //; case: negP.
pose r := sort argCle r0; have r_arg: sorted argCle r by apply: sort_sorted.
have{} Dp: p = \prod_(z <- r) ('X - z%:P).
rewrite Dp lead_coefE sz_p coefB coefXn coefC -mulrb -mulrnA mulnb lt0n andNb.
by rewrite subr0 eqxx scale1r; apply/esym/perm_big; rewrite perm_sort.
have mem_rP z: (n > 0)%N -> reflect (z ^+ n = x) (z \in r).
move=> n_gt0; rewrite -root_prod_XsubC -Dp rootE !hornerE n_gt0.
by rewrite subr_eq0; apply: eqP.
exists r`_0 => [|z n_gt0 /(mem_rP z n_gt0) r_z].
have sz_r: size r = n by apply: succn_inj; rewrite -sz_p Dp size_prod_XsubC.
case: posnP => [n0 | n_gt0]; first by rewrite nth_default // sz_r n0.
by apply/mem_rP=> //; rewrite mem_nth ?sz_r.
case: {Dp mem_rP}r r_z r_arg => // y r1 /[1!inE] /predU1P[-> _|r1z].
by apply/implyP=> ->; rewrite lexx.
by move/(order_path_min argCle_trans)/allP->.
Qed.
Definition nthroot n x := let: RootCspec y _ _ := rootC_subproof n x in y.
Notation "n .-root" := (nthroot n) : ring_scope.
Notation sqrtC := 2.-root.
Fact Re_lock : unit. Proof. exact: tt. Qed.
Fact Im_lock : unit. Proof. exact: tt. Qed.
Definition Re z := locked_with Re_lock ((z + z^*) / 2%:R).
Definition Im z := locked_with Im_lock ('i * (z^* - z) / 2%:R).
Notation "'Re z" := (Re z) : ring_scope.
Notation "'Im z" := (Im z) : ring_scope.
Lemma ReE z : 'Re z = (z + z^*) / 2%:R. Proof. by rewrite ['Re _]unlock. Qed.
Lemma ImE z : 'Im z = 'i * (z^* - z) / 2%:R.
Proof. by rewrite ['Im _]unlock. Qed.
Let nz2 : 2 != 0 :> C. Proof. by rewrite pnatr_eq0. Qed.
Lemma normCKC x : `|x| ^+ 2 = x^* * x. Proof. by rewrite normCK mulrC. Qed.
Lemma mul_conjC_ge0 x : 0 <= x * x^*.
Proof. by rewrite -normCK exprn_ge0. Qed.
Lemma mul_conjC_gt0 x : (0 < x * x^* ) = (x != 0).
Proof.
have [->|x_neq0] := eqVneq; first by rewrite rmorph0 mulr0.
by rewrite -normCK exprn_gt0 ?normr_gt0.
Qed.
Lemma mul_conjC_eq0 x : (x * x^* == 0) = (x == 0).
Proof. by rewrite -normCK expf_eq0 normr_eq0. Qed.
Lemma conjC_ge0 x : (0 <= x^* ) = (0 <= x).
Proof.
wlog suffices: x / 0 <= x -> 0 <= x^*.
by move=> IH; apply/idP/idP=> /IH; rewrite ?conjCK.
rewrite [in X in X -> _]le0r => /predU1P[-> | x_gt0]; first by rewrite rmorph0.
by rewrite -(pmulr_rge0 _ x_gt0) mul_conjC_ge0.
Qed.
Lemma conjC_nat n : (n%:R)^* = n%:R :> C. Proof. exact: rmorph_nat. Qed.
Lemma conjC0 : 0^* = 0 :> C. Proof. exact: rmorph0. Qed.
Lemma conjC1 : 1^* = 1 :> C. Proof. exact: rmorph1. Qed.
Lemma conjCN1 : (- 1)^* = - 1 :> C. Proof. exact: rmorphN1. Qed.
Lemma conjC_eq0 x : (x^* == 0) = (x == 0). Proof. exact: fmorph_eq0. Qed.
Lemma invC_norm x : x^-1 = `|x| ^- 2 * x^*.
Proof.
have [-> | nx_x] := eqVneq x 0; first by rewrite conjC0 mulr0 invr0.
by rewrite normCK invfM divfK ?conjC_eq0.
Qed.
(* Real number subset. *)
Lemma CrealE x : (x \is real) = (x^* == x).
Proof.
rewrite realEsqr ger0_def normrX normCK.
by have [-> | /mulfI/inj_eq-> //] := eqVneq x 0; rewrite rmorph0 !eqxx.
Qed.
Lemma CrealP {x} : reflect (x^* = x) (x \is real).
Proof. by rewrite CrealE; apply: eqP. Qed.
Lemma conj_Creal x : x \is real -> x^* = x.
Proof. by move/CrealP. Qed.
Lemma conj_normC z : `|z|^* = `|z|.
Proof. by rewrite conj_Creal ?normr_real. Qed.
Lemma CrealJ : {mono (@conj_op C) : x / x \is Num.real}.
Proof. by apply: (homo_mono1 conjCK) => x xreal; rewrite conj_Creal. Qed.
Lemma geC0_conj x : 0 <= x -> x^* = x.
Proof. by move=> /ger0_real/CrealP. Qed.
Lemma geC0_unit_exp x n : 0 <= x -> (x ^+ n.+1 == 1) = (x == 1).
Proof. by move=> x_ge0; rewrite pexpr_eq1. Qed.
(* Elementary properties of roots. *)
Ltac case_rootC := rewrite /nthroot; case: (rootC_subproof _ _).
Lemma root0C x : 0.-root x = 0. Proof. by case_rootC. Qed.
Lemma rootCK n : (n > 0)%N -> cancel n.-root (fun x => x ^+ n).
Proof. by case: n => //= n _ x; case_rootC. Qed.
Lemma root1C x : 1.-root x = x. Proof. exact: (@rootCK 1). Qed.
Lemma rootC0 n : n.-root 0 = 0.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite root0C.
by have /eqP := rootCK n_gt0 0; rewrite expf_eq0 n_gt0 /= => /eqP.
Qed.
Lemma rootC_inj n : (n > 0)%N -> injective n.-root.
Proof. by move/rootCK/can_inj. Qed.
Lemma eqr_rootC n : (n > 0)%N -> {mono n.-root : x y / x == y}.
Proof. by move/rootC_inj/inj_eq. Qed.
Lemma rootC_eq0 n x : (n > 0)%N -> (n.-root x == 0) = (x == 0).
Proof. by move=> n_gt0; rewrite -{1}(rootC0 n) eqr_rootC. Qed.
(* Rectangular coordinates. *)
Lemma nonRealCi : ('i : C) \isn't real.
Proof. by rewrite realEsqr sqrCi oppr_ge0 lt_geF ?ltr01. Qed.
Lemma neq0Ci : 'i != 0 :> C. Proof. by apply: contraNneq nonRealCi => ->. Qed.
Lemma normCi : `|'i| = 1 :> C.
Proof. by apply/eqP; rewrite -(@pexpr_eq1 _ _ 2) // -normrX sqrCi normrN1. Qed.
Lemma invCi : 'i^-1 = - 'i :> C.
Proof. by rewrite -div1r -[1]opprK -sqrCi mulNr mulfK ?neq0Ci. Qed.
Lemma conjCi : 'i^* = - 'i :> C.
Proof. by rewrite -invCi invC_norm normCi expr1n invr1 mul1r. Qed.
Lemma Crect x : x = 'Re x + 'i * 'Im x.
Proof.
rewrite !(ReE, ImE) 2!mulrA mulCii mulN1r opprB -mulrDl.
by rewrite addrACA subrr addr0 mulrDl -splitr.
Qed.
Lemma eqCP x y : x = y <-> ('Re x = 'Re y) /\ ('Im x = 'Im y).
Proof. by split=> [->//|[eqRe eqIm]]; rewrite [x]Crect [y]Crect eqRe eqIm. Qed.
Lemma eqC x y : (x == y) = ('Re x == 'Re y) && ('Im x == 'Im y).
Proof. by apply/eqP/(andPP eqP eqP) => /eqCP. Qed.
Lemma Creal_Re x : 'Re x \is real.
Proof. by rewrite ReE CrealE fmorph_div rmorph_nat rmorphD /= conjCK addrC. Qed.
Lemma Creal_Im x : 'Im x \is real.
Proof.
rewrite ImE CrealE fmorph_div rmorph_nat rmorphM /= rmorphB conjCK.
by rewrite conjCi -opprB mulrNN.
Qed.
Hint Resolve Creal_Re Creal_Im : core.
Fact Re_is_zmod_morphism : zmod_morphism Re.
Proof. by move=> x y; rewrite !ReE rmorphB addrACA -opprD mulrBl. Qed.
#[export]
HB.instance Definition _ := GRing.isZmodMorphism.Build C C Re Re_is_zmod_morphism.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `Re_is_zmod_morphism` instead")]
Definition Re_is_additive := Re_is_zmod_morphism.
Fact Im_is_zmod_morphism : zmod_morphism Im.
Proof.
by move=> x y; rewrite !ImE rmorphB opprD addrACA -opprD mulrBr mulrBl.
Qed.
#[export]
HB.instance Definition _ := GRing.isZmodMorphism.Build C C Im Im_is_zmod_morphism.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `Im_is_zmod_morphism` instead")]
Definition Im_is_additive := Im_is_zmod_morphism.
Lemma Creal_ImP z : reflect ('Im z = 0) (z \is real).
Proof.
rewrite ImE CrealE -subr_eq0 -(can_eq (mulKf neq0Ci)) mulr0.
by rewrite -(can_eq (divfK nz2)) mul0r; apply: eqP.
Qed.
Lemma Creal_ReP z : reflect ('Re z = z) (z \in real).
Proof.
rewrite (sameP (Creal_ImP z) eqP) -(can_eq (mulKf neq0Ci)) mulr0.
by rewrite -(inj_eq (addrI ('Re z))) addr0 -Crect eq_sym; apply: eqP.
Qed.
Lemma ReMl : {in real, forall x, {morph Re : z / x * z}}.
Proof.
by move=> x Rx z /=; rewrite !ReE rmorphM /= (conj_Creal Rx) -mulrDr -mulrA.
Qed.
Lemma ReMr : {in real, forall x, {morph Re : z / z * x}}.
Proof. by move=> x Rx z /=; rewrite mulrC ReMl // mulrC. Qed.
Lemma ImMl : {in real, forall x, {morph Im : z / x * z}}.
Proof.
by move=> x Rx z; rewrite !ImE rmorphM /= (conj_Creal Rx) -mulrBr mulrCA !mulrA.
Qed.
Lemma ImMr : {in real, forall x, {morph Im : z / z * x}}.
Proof. by move=> x Rx z /=; rewrite mulrC ImMl // mulrC. Qed.
Lemma Re_i : 'Re 'i = 0. Proof. by rewrite ReE conjCi subrr mul0r. Qed.
Lemma Im_i : 'Im 'i = 1.
Proof.
rewrite ImE conjCi -opprD mulrN -mulr2n mulrnAr mulCii.
by rewrite mulNrn opprK divff.
Qed.
Lemma Re_conj z : 'Re z^* = 'Re z.
Proof. by rewrite !ReE addrC conjCK. Qed.
Lemma Im_conj z : 'Im z^* = - 'Im z.
Proof. by rewrite !ImE -mulNr -mulrN opprB conjCK. Qed.
Lemma Re_rect : {in real &, forall x y, 'Re (x + 'i * y) = x}.
Proof.
move=> x y Rx Ry; rewrite /= raddfD /= (Creal_ReP x Rx).
by rewrite ReMr // Re_i mul0r addr0.
Qed.
Lemma Im_rect : {in real &, forall x y, 'Im (x + 'i * y) = y}.
Proof.
move=> x y Rx Ry; rewrite /= raddfD /= (Creal_ImP x Rx) add0r.
by rewrite ImMr // Im_i mul1r.
Qed.
Lemma conjC_rect : {in real &, forall x y, (x + 'i * y)^* = x - 'i * y}.
Proof.
by move=> x y Rx Ry; rewrite /= rmorphD rmorphM /= conjCi mulNr !conj_Creal.
Qed.
Lemma addC_rect x1 y1 x2 y2 :
(x1 + 'i * y1) + (x2 + 'i * y2) = x1 + x2 + 'i * (y1 + y2).
Proof. by rewrite addrACA -mulrDr. Qed.
Lemma oppC_rect x y : - (x + 'i * y) = - x + 'i * (- y).
Proof. by rewrite mulrN -opprD. Qed.
Lemma subC_rect x1 y1 x2 y2 :
(x1 + 'i * y1) - (x2 + 'i * y2) = x1 - x2 + 'i * (y1 - y2).
Proof. by rewrite oppC_rect addC_rect. Qed.
Lemma mulC_rect x1 y1 x2 y2 : (x1 + 'i * y1) * (x2 + 'i * y2) =
x1 * x2 - y1 * y2 + 'i * (x1 * y2 + x2 * y1).
Proof.
rewrite mulrDl !mulrDr (AC (2*2) (1*4*(2*3)))/= mulrACA.
by rewrite -expr2 sqrCi mulN1r -!mulrA [_ * ('i * _)]mulrCA [_ * y1]mulrC.
Qed.
Lemma ImM x y : 'Im (x * y) = 'Re x * 'Im y + 'Re y * 'Im x.
Proof.
rewrite [x in LHS]Crect [y in LHS]Crect mulC_rect.
by rewrite !(Im_rect, rpredB, rpredD, rpredM).
Qed.
Lemma ImMil x : 'Im ('i * x) = 'Re x.
Proof. by rewrite ImM Re_i Im_i mul0r mulr1 add0r. Qed.
Lemma ReMil x : 'Re ('i * x) = - 'Im x.
Proof. by rewrite -ImMil mulrA mulCii mulN1r raddfN. Qed.
Lemma ReMir x : 'Re (x * 'i) = - 'Im x. Proof. by rewrite mulrC ReMil. Qed.
Lemma ImMir x : 'Im (x * 'i) = 'Re x. Proof. by rewrite mulrC ImMil. Qed.
Lemma ReM x y : 'Re (x * y) = 'Re x * 'Re y - 'Im x * 'Im y.
Proof. by rewrite -ImMil mulrCA ImM ImMil ReMil mulNr ['Im _ * _]mulrC. Qed.
Lemma normC2_rect :
{in real &, forall x y, `|x + 'i * y| ^+ 2 = x ^+ 2 + y ^+ 2}.
Proof.
move=> x y Rx Ry; rewrite /= normCK rmorphD rmorphM /= conjCi !conj_Creal //.
by rewrite mulrC mulNr -subr_sqr exprMn sqrCi mulN1r opprK.
Qed.
Lemma normC2_Re_Im z : `|z| ^+ 2 = 'Re z ^+ 2 + 'Im z ^+ 2.
Proof. by rewrite -normC2_rect -?Crect. Qed.
Lemma invC_Crect x y : (x + 'i * y)^-1 = (x^* - 'i * y^*) / `|x + 'i * y| ^+ 2.
Proof. by rewrite /= invC_norm mulrC !rmorphE rmorphM /= conjCi mulNr. Qed.
Lemma invC_rect :
{in real &, forall x y, (x + 'i * y)^-1 = (x - 'i * y) / (x ^+ 2 + y ^+ 2)}.
Proof. by move=> x y Rx Ry; rewrite invC_Crect normC2_rect ?conj_Creal. Qed.
Lemma ImV x : 'Im x^-1 = - 'Im x / `|x| ^+ 2.
Proof.
rewrite [x in LHS]Crect invC_rect// ImMr ?(rpredV, rpredD, rpredX)//.
by rewrite -mulrN Im_rect ?rpredN// -normC2_rect// -Crect.
Qed.
Lemma ReV x : 'Re x^-1 = 'Re x / `|x| ^+ 2.
Proof.
rewrite [x in LHS]Crect invC_rect// ReMr ?(rpredV, rpredD, rpredX)//.
by rewrite -mulrN Re_rect ?rpredN// -normC2_rect// -Crect.
Qed.
Lemma rectC_mulr x y z : (x + 'i * y) * z = x * z + 'i * (y * z).
Proof. by rewrite mulrDl mulrA. Qed.
Lemma rectC_mull x y z : z * (x + 'i * y) = z * x + 'i * (z * y).
Proof. by rewrite mulrDr mulrCA. Qed.
Lemma divC_Crect x1 y1 x2 y2 :
(x1 + 'i * y1) / (x2 + 'i * y2) =
(x1 * x2^* + y1 * y2^* + 'i * (x2^* * y1 - x1 * y2^*)) /
`|x2 + 'i * y2| ^+ 2.
Proof.
rewrite invC_Crect// -mulrN [_ / _]rectC_mulr mulC_rect !mulrA -mulrBl.
rewrite [_ * _ * y1]mulrAC -mulrDl mulrA -mulrDl !(mulrN, mulNr) opprK.
by rewrite [- _ + _]addrC.
Qed.
Lemma divC_rect x1 y1 x2 y2 :
x1 \is real -> y1 \is real -> x2 \is real -> y2 \is real ->
(x1 + 'i * y1) / (x2 + 'i * y2) =
(x1 * x2 + y1 * y2 + 'i * (x2 * y1 - x1 * y2)) /
(x2 ^+ 2 + y2 ^+ 2).
Proof. by move=> *; rewrite divC_Crect normC2_rect ?conj_Creal. Qed.
Lemma Im_div x y : 'Im (x / y) = ('Re y * 'Im x - 'Re x * 'Im y) / `|y| ^+ 2.
Proof. by rewrite ImM ImV ReV mulrA [X in _ + X]mulrAC -mulrDl mulrN addrC. Qed.
Lemma Re_div x y : 'Re (x / y) = ('Re x * 'Re y + 'Im x * 'Im y) / `|y| ^+ 2.
Proof. by rewrite ReM ImV ReV !mulrA -mulrBl mulrN opprK. Qed.
Lemma leif_normC_Re_Creal z : `|'Re z| <= `|z| ?= iff (z \is real).
Proof.
rewrite -(mono_in_leif ler_sqr); try by rewrite qualifE /=.
rewrite [`|'Re _| ^+ 2]normCK conj_Creal // normC2_Re_Im -expr2.
rewrite addrC -leifBLR subrr (sameP (Creal_ImP _) eqP) -sqrf_eq0 eq_sym.
by apply: leif_eq; rewrite -realEsqr.
Qed.
Lemma leif_Re_Creal z : 'Re z <= `|z| ?= iff (0 <= z).
Proof.
have ubRe: 'Re z <= `|'Re z| ?= iff (0 <= 'Re z).
by rewrite ger0_def eq_sym; apply/leif_eq/real_ler_norm.
congr (_ <= _ ?= iff _): (leif_trans ubRe (leif_normC_Re_Creal z)).
apply/andP/idP=> [[zRge0 /Creal_ReP <- //] | z_ge0].
by have Rz := ger0_real z_ge0; rewrite (Creal_ReP _ _).
Qed.
(* Equality from polar coordinates, for the upper plane. *)
Lemma eqC_semipolar x y :
`|x| = `|y| -> 'Re x = 'Re y -> 0 <= 'Im x * 'Im y -> x = y.
Proof.
move=> eq_norm eq_Re sign_Im.
rewrite [x]Crect [y]Crect eq_Re; congr (_ + 'i * _).
have /eqP := congr1 (fun z => z ^+ 2) eq_norm.
rewrite !normC2_Re_Im eq_Re (can_eq (addKr _)) eqf_sqr => /pred2P[] // eq_Im.
rewrite eq_Im mulNr -expr2 oppr_ge0 real_exprn_even_le0 //= in sign_Im.
by rewrite eq_Im (eqP sign_Im) oppr0.
Qed.
(* Nth roots. *)
Let argCleP y z :
reflect (0 <= 'Im z -> 0 <= 'Im y /\ 'Re z <= 'Re y) (argCle y z).
Proof.
suffices dIm x: nnegIm x = (0 <= 'Im x).
rewrite /argCle !dIm !(ImE, ReE) ler_pM2r ?invr_gt0 ?ltr0n //.
by apply: (iffP implyP) => geZyz /geZyz/andP.
by rewrite (ImE x) pmulr_lge0 ?invr_gt0 ?ltr0n //; congr (0 <= _ * _).
Qed.
Lemma rootC_Re_max n x y :
(n > 0)%N -> y ^+ n = x -> 0 <= 'Im y -> 'Re y <= 'Re (n.-root x).
Proof.
by move=> n_gt0 yn_x leI0y; case_rootC=> z /= _ /(_ y n_gt0 yn_x)/argCleP[].
Qed.
Let neg_unity_root n : (n > 1)%N -> exists2 w : C, w ^+ n = 1 & 'Re w < 0.
Proof.
move=> n_gt1; have [|w /eqP pw_0] := closed_rootP (\poly_(i < n) (1 : C)) _.
by rewrite size_poly_eq ?oner_eq0 // -(subnKC n_gt1).
rewrite horner_poly (eq_bigr _ (fun _ _ => mul1r _)) in pw_0.
have wn1: w ^+ n = 1 by apply/eqP; rewrite -subr_eq0 subrX1 pw_0 mulr0.
suffices /existsP[i ltRwi0]: [exists i : 'I_n, 'Re (w ^+ i) < 0].
by exists (w ^+ i) => //; rewrite exprAC wn1 expr1n.
apply: contra_eqT (congr1 Re pw_0) => /existsPn geRw0.
rewrite raddf_sum raddf0 /= (bigD1 (Ordinal (ltnW n_gt1))) //=.
rewrite (Creal_ReP _ _) ?rpred1 // gt_eqF ?ltr_wpDr ?ltr01 //=.
by apply: sumr_ge0 => i _; rewrite real_leNgt ?rpred0.
Qed.
Lemma Im_rootC_ge0 n x : (n > 1)%N -> 0 <= 'Im (n.-root x).
Proof.
set y := n.-root x => n_gt1; have n_gt0 := ltnW n_gt1.
apply: wlog_neg; rewrite -real_ltNge ?rpred0 // => ltIy0.
suffices [z zn_x leI0z]: exists2 z, z ^+ n = x & 'Im z >= 0.
by rewrite /y; case_rootC => /= y1 _ /(_ z n_gt0 zn_x)/argCleP[].
have [w wn1 ltRw0] := neg_unity_root n_gt1.
wlog leRI0yw: w wn1 ltRw0 / 0 <= 'Re y * 'Im w.
move=> IHw; have: 'Re y * 'Im w \is real by rewrite rpredM.
case/real_ge0P=> [|/ltW leRIyw0]; first exact: IHw.
apply: (IHw w^* ); rewrite ?Re_conj ?Im_conj ?mulrN ?oppr_ge0 //.
by rewrite -rmorphXn wn1 rmorph1.
exists (w * y); first by rewrite exprMn wn1 mul1r rootCK.
rewrite [w]Crect [y]Crect mulC_rect.
by rewrite Im_rect ?rpredD ?rpredN 1?rpredM // addr_ge0 // ltW ?nmulr_rgt0.
Qed.
Lemma rootC_lt0 n x : (1 < n)%N -> (n.-root x < 0) = false.
Proof.
set y := n.-root x => n_gt1; have n_gt0 := ltnW n_gt1.
apply: negbTE; apply: wlog_neg => /negbNE lt0y; rewrite le_gtF //.
have Rx: x \is real by rewrite -[x](rootCK n_gt0) rpredX // ltr0_real.
have Re_y: 'Re y = y by apply/Creal_ReP; rewrite ltr0_real.
have [z zn_x leR0z]: exists2 z, z ^+ n = x & 'Re z >= 0.
have [w wn1 ltRw0] := neg_unity_root n_gt1.
exists (w * y); first by rewrite exprMn wn1 mul1r rootCK.
by rewrite ReMr ?ltr0_real // ltW // nmulr_lgt0.
without loss leI0z: z zn_x leR0z / 'Im z >= 0.
move=> IHz; have: 'Im z \is real by [].
case/real_ge0P=> [|/ltW leIz0]; first exact: IHz.
apply: (IHz z^* ); rewrite ?Re_conj ?Im_conj ?oppr_ge0 //.
by rewrite -rmorphXn /= zn_x conj_Creal.
by apply: le_trans leR0z _; rewrite -Re_y ?rootC_Re_max ?ltr0_real.
Qed.
Lemma rootC_ge0 n x : (n > 0)%N -> (0 <= n.-root x) = (0 <= x).
Proof.
set y := n.-root x => n_gt0.
apply/idP/idP=> [/(exprn_ge0 n) | x_ge0]; first by rewrite rootCK.
rewrite -(ge_leif (leif_Re_Creal y)).
have Ray: `|y| \is real by apply: normr_real.
rewrite -(Creal_ReP _ Ray) rootC_Re_max ?(Creal_ImP _ Ray) //.
by rewrite -normrX rootCK // ger0_norm.
Qed.
Lemma rootC_gt0 n x : (n > 0)%N -> (n.-root x > 0) = (x > 0).
Proof. by move=> n_gt0; rewrite !lt0r rootC_ge0 ?rootC_eq0. Qed.
Lemma rootC_le0 n x : (1 < n)%N -> (n.-root x <= 0) = (x == 0).
Proof.
by move=> n_gt1; rewrite le_eqVlt rootC_lt0 // orbF rootC_eq0 1?ltnW.
Qed.
Lemma ler_rootCl n : (n > 0)%N -> {in Num.nneg, {mono n.-root : x y / x <= y}}.
Proof.
move=> n_gt0 x x_ge0 y; have [y_ge0 | not_y_ge0] := boolP (0 <= y).
by rewrite -(ler_pXn2r n_gt0) ?qualifE /= ?rootC_ge0 ?rootCK.
rewrite (contraNF (@le_trans _ _ _ 0 _ _)) ?rootC_ge0 //.
by rewrite (contraNF (le_trans x_ge0)).
Qed.
Lemma ler_rootC n : (n > 0)%N -> {in Num.nneg &, {mono n.-root : x y / x <= y}}.
Proof. by move=> n_gt0 x y x_ge0 _; apply: ler_rootCl. Qed.
Lemma ltr_rootCl n : (n > 0)%N -> {in Num.nneg, {mono n.-root : x y / x < y}}.
Proof. by move=> n_gt0 x x_ge0 y; rewrite !lt_def ler_rootCl ?eqr_rootC. Qed.
Lemma ltr_rootC n : (n > 0)%N -> {in Num.nneg &, {mono n.-root : x y / x < y}}.
Proof. by move/ler_rootC/leW_mono_in. Qed.
Lemma exprCK n x : (0 < n)%N -> 0 <= x -> n.-root (x ^+ n) = x.
Proof.
move=> n_gt0 x_ge0; apply/eqP.
by rewrite -(eqrXn2 n_gt0) ?rootC_ge0 ?exprn_ge0 ?rootCK.
Qed.
Lemma norm_rootC n x : `|n.-root x| = n.-root `|x|.
Proof.
have [-> | n_gt0] := posnP n; first by rewrite !root0C normr0.
by apply/eqP; rewrite -(eqrXn2 n_gt0) ?rootC_ge0 // -normrX !rootCK.
Qed.
Lemma rootCX n x k : (n > 0)%N -> 0 <= x -> n.-root (x ^+ k) = n.-root x ^+ k.
Proof.
move=> n_gt0 x_ge0; apply/eqP.
by rewrite -(eqrXn2 n_gt0) ?(exprn_ge0, rootC_ge0) // 1?exprAC !rootCK.
Qed.
Lemma rootC1 n : (n > 0)%N -> n.-root 1 = 1.
Proof. by move/(rootCX 0)/(_ ler01). Qed.
Lemma rootCpX n x k : (k > 0)%N -> 0 <= x -> n.-root (x ^+ k) = n.-root x ^+ k.
Proof.
by case: n => [|n] k_gt0; [rewrite !root0C expr0n gtn_eqF | apply: rootCX].
Qed.
Lemma rootCV n x : 0 <= x -> n.-root x^-1 = (n.-root x)^-1.
Proof.
move=> x_ge0; have [->|n_gt0] := posnP n; first by rewrite !root0C invr0.
apply/eqP.
by rewrite -(eqrXn2 n_gt0) ?(invr_ge0, rootC_ge0) // !exprVn !rootCK.
Qed.
Lemma rootC_eq1 n x : (n > 0)%N -> (n.-root x == 1) = (x == 1).
Proof. by move=> n_gt0; rewrite -{1}(rootC1 n_gt0) eqr_rootC. Qed.
Lemma rootC_ge1 n x : (n > 0)%N -> (n.-root x >= 1) = (x >= 1).
Proof.
by move=> n_gt0; rewrite -{1}(rootC1 n_gt0) ler_rootCl // qualifE /= ler01.
Qed.
Lemma rootC_gt1 n x : (n > 0)%N -> (n.-root x > 1) = (x > 1).
Proof. by move=> n_gt0; rewrite !lt_def rootC_eq1 ?rootC_ge1. Qed.
Lemma rootC_le1 n x : (n > 0)%N -> 0 <= x -> (n.-root x <= 1) = (x <= 1).
Proof. by move=> n_gt0 x_ge0; rewrite -{1}(rootC1 n_gt0) ler_rootCl. Qed.
Lemma rootC_lt1 n x : (n > 0)%N -> 0 <= x -> (n.-root x < 1) = (x < 1).
Proof. by move=> n_gt0 x_ge0; rewrite !lt_neqAle rootC_eq1 ?rootC_le1. Qed.
Lemma rootCMl n x z : 0 <= x -> n.-root (x * z) = n.-root x * n.-root z.
Proof.
rewrite le0r => /predU1P[-> | x_gt0]; first by rewrite !(mul0r, rootC0).
have [| n_gt1 | ->] := ltngtP n 1; last by rewrite !root1C.
by case: n => //; rewrite !root0C mul0r.
have [x_ge0 n_gt0] := (ltW x_gt0, ltnW n_gt1).
have nx_gt0: 0 < n.-root x by rewrite rootC_gt0.
have Rnx: n.-root x \is real by rewrite ger0_real ?ltW.
apply: eqC_semipolar; last 1 first; try apply/eqP.
- by rewrite ImMl // !(Im_rootC_ge0, mulr_ge0, rootC_ge0).
- by rewrite -(eqrXn2 n_gt0) // -!normrX exprMn !rootCK.
rewrite eq_le; apply/andP; split; last first.
rewrite rootC_Re_max ?exprMn ?rootCK ?ImMl //.
by rewrite mulr_ge0 ?Im_rootC_ge0 ?ltW.
rewrite -[n.-root _](mulVKf (negbT (gt_eqF nx_gt0))) !(ReMl Rnx) //.
rewrite ler_pM2l // rootC_Re_max ?exprMn ?exprVn ?rootCK ?mulKf ?gt_eqF //.
by rewrite ImMl ?rpredV // mulr_ge0 ?invr_ge0 ?Im_rootC_ge0 ?ltW.
Qed.
Lemma rootCMr n x z : 0 <= x -> n.-root (z * x) = n.-root z * n.-root x.
Proof. by move=> x_ge0; rewrite mulrC rootCMl // mulrC. Qed.
Lemma imaginaryCE : 'i = sqrtC (-1).
Proof.
have : sqrtC (-1) ^+ 2 - 'i ^+ 2 == 0 by rewrite sqrCi rootCK // subrr.
rewrite subr_sqr mulf_eq0 subr_eq0 addr_eq0; have [//|_/= /eqP sCN1E] := eqP.
by have := @Im_rootC_ge0 2 (-1) isT; rewrite sCN1E raddfN /= Im_i ler0N1.
Qed.
(* More properties of n.-root will be established in cyclotomic.v. *)
(* The proper form of the Arithmetic - Geometric Mean inequality. *)
Lemma leif_rootC_AGM (I : finType) (A : {pred I}) (n := #|A|) E :
{in A, forall i, 0 <= E i} ->
n.-root (\prod_(i in A) E i) <= (\sum_(i in A) E i) / n%:R
?= iff [forall i in A, forall j in A, E i == E j].
Proof.
move=> Ege0; have [n0 | n_gt0] := posnP n.
rewrite n0 root0C invr0 mulr0; apply/leif_refl/forall_inP=> i.
by rewrite (card0_eq n0).
rewrite -(mono_in_leif (ler_pXn2r n_gt0)) ?rootCK //=; first 1 last.
- by rewrite qualifE /= rootC_ge0 // prodr_ge0.
- by rewrite rpred_div ?rpred_nat ?rpred_sum.
exact: leif_AGM.
Qed.
(* Square root. *)
Lemma sqrtC0 : sqrtC 0 = 0. Proof. exact: rootC0. Qed.
Lemma sqrtC1 : sqrtC 1 = 1. Proof. exact: rootC1. Qed.
Lemma sqrtCK x : sqrtC x ^+ 2 = x. Proof. exact: rootCK. Qed.
Lemma sqrCK x : 0 <= x -> sqrtC (x ^+ 2) = x. Proof. exact: exprCK. Qed.
Lemma sqrtC_ge0 x : (0 <= sqrtC x) = (0 <= x). Proof. exact: rootC_ge0. Qed.
Lemma sqrtC_eq0 x : (sqrtC x == 0) = (x == 0). Proof. exact: rootC_eq0. Qed.
Lemma sqrtC_gt0 x : (sqrtC x > 0) = (x > 0). Proof. exact: rootC_gt0. Qed.
Lemma sqrtC_lt0 x : (sqrtC x < 0) = false. Proof. exact: rootC_lt0. Qed.
Lemma sqrtC_le0 x : (sqrtC x <= 0) = (x == 0). Proof. exact: rootC_le0. Qed.
Lemma ler_sqrtC : {in Num.nneg &, {mono sqrtC : x y / x <= y}}.
Proof. exact: ler_rootC. Qed.
Lemma ltr_sqrtC : {in Num.nneg &, {mono sqrtC : x y / x < y}}.
Proof. exact: ltr_rootC. Qed.
Lemma eqr_sqrtC : {mono sqrtC : x y / x == y}.
Proof. exact: eqr_rootC. Qed.
Lemma sqrtC_inj : injective sqrtC.
Proof. exact: rootC_inj. Qed.
Lemma sqrtCM : {in Num.nneg &, {morph sqrtC : x y / x * y}}.
Proof. by move=> x y _; apply: rootCMr. Qed.
Lemma sqrtC_real x : 0 <= x -> sqrtC x \in Num.real.
Proof. by rewrite -sqrtC_ge0; apply: ger0_real. Qed.
Lemma sqrCK_P x : reflect (sqrtC (x ^+ 2) = x) ((0 <= 'Im x) && ~~ (x < 0)).
Proof.
apply: (iffP andP) => [[leI0x not_gt0x] | <-]; last first.
by rewrite sqrtC_lt0 Im_rootC_ge0.
have /eqP := sqrtCK (x ^+ 2); rewrite eqf_sqr => /pred2P[] // defNx.
apply: sqrCK; rewrite -real_leNgt ?rpred0 // in not_gt0x;
apply/Creal_ImP/le_anti;
by rewrite leI0x -oppr_ge0 -raddfN -defNx Im_rootC_ge0.
Qed.
Lemma normC_def x : `|x| = sqrtC (x * x^* ).
Proof. by rewrite -normCK sqrCK. Qed.
Lemma norm_conjC x : `|x^*| = `|x|.
Proof. by rewrite !normC_def conjCK mulrC. Qed.
Lemma normC_rect :
{in real &, forall x y, `|x + 'i * y| = sqrtC (x ^+ 2 + y ^+ 2)}.
Proof. by move=> x y Rx Ry; rewrite /= normC_def -normCK normC2_rect. Qed.
Lemma normC_Re_Im z : `|z| = sqrtC ('Re z ^+ 2 + 'Im z ^+ 2).
Proof. by rewrite normC_def -normCK normC2_Re_Im. Qed.
(* Norm sum (in)equalities. *)
Lemma normCDeq x y :
`|x + y| = `|x| + `|y| ->
{t : C | `|t| == 1 & (x, y) = (`|x| * t, `|y| * t)}.
Proof.
move=> lin_xy; apply: sig2_eqW; pose u z := if z == 0 then 1 else z / `|z|.
have uE z: (`|u z| = 1) * (`|z| * u z = z).
rewrite /u; have [->|nz_z] := eqVneq; first by rewrite normr0 normr1 mul0r.
by rewrite normf_div normr_id mulrCA divff ?mulr1 ?normr_eq0.
have [->|nz_x] := eqVneq x 0; first by exists (u y); rewrite uE ?normr0 ?mul0r.
exists (u x); rewrite uE // /u (negPf nz_x); congr (_ , _).
have{lin_xy} def2xy: `|x| * `|y| *+ 2 = x * y ^* + y * x ^*.
apply/(addrI (x * x^* ))/(addIr (y * y^* )); rewrite -2!{1}normCK -sqrrD.
by rewrite addrA -[RHS]addrA -!mulrDr -mulrDl -rmorphD -normCK lin_xy.
have def_xy: x * y^* = y * x^*.
apply/eqP; rewrite -subr_eq0 -[_ == 0](@expf_eq0 _ _ 2).
rewrite (canRL (subrK _) (subr_sqrDB _ _)) opprK -def2xy exprMn_n exprMn.
by rewrite mulrN (@GRing.mul C).[AC (2*2) (1*4*(3*2))] -!normCK mulNrn addNr.
have{def_xy def2xy} def_yx: `|y * x| = y * x^*.
by apply: (mulIf nz2); rewrite !mulr_natr mulrC normrM def2xy def_xy.
rewrite -{1}(divfK nz_x y) invC_norm mulrCA -{}def_yx !normrM invfM.
by rewrite mulrCA divfK ?normr_eq0 // mulrAC mulrA.
Qed.
Lemma normC_sum_eq (I : finType) (P : pred I) (F : I -> C) :
`|\sum_(i | P i) F i| = \sum_(i | P i) `|F i| ->
{t : C | `|t| == 1 & forall i, P i -> F i = `|F i| * t}.
Proof.
have [i /andP[Pi nzFi] | F0] := pickP [pred i | P i & F i != 0]; last first.
exists 1 => [|i Pi]; first by rewrite normr1.
by case/nandP: (F0 i) => [/negP[]// | /negbNE/eqP->]; rewrite normr0 mul0r.
rewrite !(bigD1 i Pi) /= => norm_sumF; pose Q j := P j && (j != i).
rewrite -normr_eq0 in nzFi; set c := F i / `|F i|; exists c => [|j Pj].
by rewrite normrM normfV normr_id divff.
have [Qj | /nandP[/negP[]// | /negbNE/eqP->]] := boolP (Q j); last first.
by rewrite mulrC divfK.
have: `|F i + F j| = `|F i| + `|F j|.
do [rewrite !(bigD1 j Qj) /=; set z := \sum_(k | _) `|_|] in norm_sumF.
apply/eqP; rewrite eq_le ler_normD -(lerD2r z) -addrA -norm_sumF addrA.
by rewrite (le_trans (ler_normD _ _)) // lerD2l ler_norm_sum.
by case/normCDeq=> k _ [/(canLR (mulKf nzFi)) <-]; rewrite -(mulrC (F i)).
Qed.
Lemma normC_sum_eq1 (I : finType) (P : pred I) (F : I -> C) :
`|\sum_(i | P i) F i| = (\sum_(i | P i) `|F i|) ->
(forall i, P i -> `|F i| = 1) ->
{t : C | `|t| == 1 & forall i, P i -> F i = t}.
Proof.
case/normC_sum_eq=> t t1 defF normF.
by exists t => // i Pi; rewrite defF // normF // mul1r.
Qed.
Lemma normC_sum_upper (I : finType) (P : pred I) (F G : I -> C) :
(forall i, P i -> `|F i| <= G i) ->
\sum_(i | P i) F i = \sum_(i | P i) G i ->
forall i, P i -> F i = G i.
Proof.
set sumF := \sum_(i | _) _; set sumG := \sum_(i | _) _ => leFG eq_sumFG.
have posG i: P i -> 0 <= G i by move/leFG; apply: le_trans.
have norm_sumG: `|sumG| = sumG by rewrite ger0_norm ?sumr_ge0.
have norm_sumF: `|sumF| = \sum_(i | P i) `|F i|.
apply/eqP; rewrite eq_le ler_norm_sum eq_sumFG norm_sumG -subr_ge0 -sumrB.
by rewrite sumr_ge0 // => i Pi; rewrite subr_ge0 ?leFG.
have [t _ defF] := normC_sum_eq norm_sumF.
have [/(psumr_eq0P posG) G0 i Pi | nz_sumG] := eqVneq sumG 0.
by apply/eqP; rewrite G0 // -normr_eq0 eq_le normr_ge0 -(G0 i Pi) leFG.
have t1: t = 1.
apply: (mulfI nz_sumG); rewrite mulr1 -{1}norm_sumG -eq_sumFG norm_sumF.
by rewrite mulr_suml -(eq_bigr _ defF).
have /psumr_eq0P eqFG i: P i -> 0 <= G i - F i.
by move=> Pi; rewrite subr_ge0 defF // t1 mulr1 leFG.
move=> i /eqFG/(canRL (subrK _))->; rewrite ?add0r //.
by rewrite sumrB -/sumF eq_sumFG subrr.
Qed.
Lemma normCBeq x y :
`|x - y| = `|x| - `|y| -> {t | `|t| == 1 & (x, y) = (`|x| * t, `|y| * t)}.
Proof.
set z := x - y; rewrite -(subrK y x) -/z => /(canLR (subrK _))/esym-Dx.
have [t t_1 [Dz Dy]] := normCDeq Dx.
by exists t; rewrite // Dx mulrDl -Dz -Dy.
Qed.
End ClosedFieldTheory.
Notation "n .-root" := (@nthroot _ n).
Notation sqrtC := 2.-root.
Notation "'i" := imaginary : ring_scope.
Notation "'Re z" := (Re z) : ring_scope.
Notation "'Im z" := (Im z) : ring_scope.
Arguments conjCK {C} x.
Arguments sqrCK {C} [x] le0x.
Arguments sqrCK_P {C x}.
#[global] Hint Extern 0 (is_true (in_mem ('Re _) _)) =>
solve [apply: Creal_Re] : core.
#[global] Hint Extern 0 (is_true (in_mem ('Im _) _)) =>
solve [apply: Creal_Im] : core.
Module Export Pdeg2.
Module NumClosed.
Section Pdeg2NumClosed.
Variables (F : numClosedFieldType) (p : {poly F}).
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Let r1 := (- b - sqrtC delta) / (2 * a).
Let r2 := (- b + sqrtC delta) / (2 * a).
Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P).
Proof. by apply: deg2_poly_factor; rewrite ?pnatr_eq0// sqrtCK. Qed.
Lemma deg2_poly_root1 : root p r1.
Proof. by apply: deg2_poly_root1; rewrite ?pnatr_eq0// sqrtCK. Qed.
Lemma deg2_poly_root2 : root p r2.
Proof. by apply: deg2_poly_root2; rewrite ?pnatr_eq0// sqrtCK. Qed.
End Pdeg2NumClosed.
End NumClosed.
Module NumClosedMonic.
Export FieldMonic.
Section Pdeg2NumClosedMonic.
Variables (F : numClosedFieldType) (p : {poly F}).
Hypothesis degp : size p = 3.
Hypothesis monicp : p \is monic.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * c.
Let r1 := (- b - sqrtC delta) / 2.
Let r2 := (- b + sqrtC delta) / 2.
Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P).
Proof. by apply: deg2_poly_factor; rewrite ?pnatr_eq0// sqrtCK. Qed.
Lemma deg2_poly_root1 : root p r1.
Proof. by apply: deg2_poly_root1; rewrite ?pnatr_eq0// sqrtCK. Qed.
Lemma deg2_poly_root2 : root p r2.
Proof. by apply: deg2_poly_root2; rewrite ?pnatr_eq0// sqrtCK. Qed.
End Pdeg2NumClosedMonic.
End NumClosedMonic.
Module Real.
Section Pdeg2Real.
Variable F : realFieldType.
Section Pdeg2RealConvex.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Hypothesis age0 : 0 <= a.
Let delta := b ^+ 2 - 4 * a * c.
Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed.
Let aneq0 : a != 0.
Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed.
Let agt0 : 0 < a. Proof. by rewrite lt_def aneq0. Qed.
Let a4gt0 : 0 < 4 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed.
Lemma deg2_poly_min x : p.[- b / (2 * a)] <= p.[x].
Proof.
rewrite [p]deg2_poly_canonical ?pnatr_eq0// -/a -/b -/c /delta !hornerE/=.
by rewrite ler_pM2l// lerD2r addrC mulNr subrr expr0n sqr_ge0.
Qed.
Lemma deg2_poly_minE : p.[- b / (2 * a)] = - delta / (4 * a).
Proof.
rewrite [p]deg2_poly_canonical ?pnatr_eq0// -/a -/b -/c -/delta !hornerE/=.
rewrite [X in X^+2]addrC [in LHS]mulNr subrr expr0n add0r mulNr.
by rewrite mulrC mulNr invfM mulrA mulfVK.
Qed.
Lemma deg2_poly_gt0 : reflect (forall x, 0 < p.[x]) (delta < 0).
Proof.
apply/(iffP idP) => [dlt0 x | /(_ (- b / (2 * a)))]; last first.
by rewrite deg2_poly_minE ltr_pdivlMr// mul0r oppr_gt0.
apply: lt_le_trans (deg2_poly_min _).
by rewrite deg2_poly_minE ltr_pdivlMr// mul0r oppr_gt0.
Qed.
Lemma deg2_poly_ge0 : reflect (forall x, 0 <= p.[x]) (delta <= 0).
Proof.
apply/(iffP idP) => [dlt0 x | /(_ (- b / (2 * a)))]; last first.
by rewrite deg2_poly_minE ler_pdivlMr// mul0r oppr_ge0.
apply: le_trans (deg2_poly_min _).
by rewrite deg2_poly_minE ler_pdivlMr// mul0r oppr_ge0.
Qed.
End Pdeg2RealConvex.
Section Pdeg2RealConcave.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Hypothesis ale0 : a <= 0.
Let delta := b ^+ 2 - 4 * a * c.
Let degpN : size (- p) = 3. Proof. by rewrite size_polyN. Qed.
Let b2a : - (- p)`_1 / (2 * (- p)`_2) = - b / (2 * a).
Proof. by rewrite !coefN mulrN divrNN. Qed.
Let deltaN : (- p)`_1 ^+ 2 - 4 * (- p)`_2 * (- p)`_0 = delta.
Proof. by rewrite !coefN sqrrN -mulrN opprK mulrN mulNr. Qed.
Lemma deg2_poly_max x : p.[x] <= p.[- b / (2 * a)].
Proof. by rewrite -lerN2 -!hornerN -b2a deg2_poly_min// coefN oppr_ge0. Qed.
Lemma deg2_poly_maxE : p.[- b / (2 * a)] = - delta / (4 * a).
Proof.
apply/eqP; rewrite [eqbRHS]mulNr -eqr_oppLR -hornerN -b2a.
by rewrite deg2_poly_minE// deltaN coefN mulrN divrNN.
Qed.
Lemma deg2_poly_lt0 : reflect (forall x, p.[x] < 0) (delta < 0).
Proof.
rewrite -deltaN; apply/(iffP (deg2_poly_gt0 _ _)); rewrite ?coefN ?oppr_ge0//.
- by move=> gt0 x; rewrite -oppr_gt0 -hornerN gt0.
- by move=> lt0 x; rewrite hornerN oppr_gt0 lt0.
Qed.
Lemma deg2_poly_le0 : reflect (forall x, p.[x] <= 0) (delta <= 0).
Proof.
rewrite -deltaN; apply/(iffP (deg2_poly_ge0 _ _)); rewrite ?coefN ?oppr_ge0//.
- by move=> ge0 x; rewrite -oppr_ge0 -hornerN ge0.
- by move=> le0 x; rewrite hornerN oppr_ge0 le0.
Qed.
End Pdeg2RealConcave.
End Pdeg2Real.
Section Pdeg2RealClosed.
Variable F : rcfType.
Section Pdeg2RealClosedConvex.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let pneq0 : p != 0. Proof. by rewrite -size_poly_gt0 degp. Qed.
Let aneq0 : a != 0.
Proof. by move: pneq0; rewrite -lead_coef_eq0 lead_coefE degp. Qed.
Let sqa2 : 4 * a ^+ 2 = (2 * a) ^+ 2. Proof. by rewrite exprMn -natrX. Qed.
Let nz2 : 2 != 0 :> F. Proof. by rewrite pnatr_eq0. Qed.
Let delta := b ^+ 2 - 4 * a * c.
Let r1 := (- b - sqrt delta) / (2 * a).
Let r2 := (- b + sqrt delta) / (2 * a).
Lemma deg2_poly_factor : 0 <= delta -> p = a *: ('X - r1%:P) * ('X - r2%:P).
Proof. by move=> dge0; apply: deg2_poly_factor; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_root1 : 0 <= delta -> root p r1.
Proof. by move=> dge0; apply: deg2_poly_root1; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_root2 : 0 <= delta -> root p r2.
Proof. by move=> dge0; apply: deg2_poly_root2; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_noroot : reflect (forall x, ~~ root p x) (delta < 0).
Proof.
apply/(iffP idP) => [dlt0 x | /(_ r1)].
case: ltgtP aneq0 => [agt0 _|alt0 _|//]; rewrite rootE; last first.
exact/lt0r_neq0/(deg2_poly_gt0 degp (ltW alt0)).
rewrite -oppr_eq0 -hornerN.
apply/lt0r_neq0/deg2_poly_gt0; rewrite ?size_polyN ?coefN ?oppr_ge0 ?ltW//.
by rewrite sqrrN -mulrA mulrNN mulrA.
by rewrite ltNge; apply: contraNN => ?; apply: deg2_poly_root1.
Qed.
Hypothesis age0 : 0 <= a.
Let agt0 : 0 < a. Proof. by rewrite lt_def aneq0. Qed.
Let a2gt0 : 0 < 2 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed.
Let a4gt0 : 0 < 4 * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed.
Let aa4gt0 : 0 < 4 * a * a. Proof. by rewrite mulr_gt0 ?ltr0n. Qed.
Let xb4 x : (x + b / (2 * a)) ^+ 2 * (4 * a * a) = (x * (2 * a) + b) ^+ 2.
Proof.
have -> : 4 * a * a = (2 * a) ^+ 2 by rewrite expr2 mulrACA -natrM mulrA.
by rewrite -exprMn mulrDl mulfVK ?mulf_neq0 ?pnatr_eq0.
Qed.
Lemma deg2_poly_gt0l x : x < r1 -> 0 < p.[x].
Proof.
move=> xltr1; have [? | dge0] := ltP delta 0; first exact: deg2_poly_gt0.
have {}xltr1 : sqrt delta < - (x * (2 * a) + b).
by rewrite ltrNr -ltrBrDr addrC -ltr_pdivlMr.
rewrite [p]deg2_poly_canonical// -/a -/b -/c -/delta !hornerE/=.
rewrite mulr_gt0// subr_gt0 ltr_pdivrMr// xb4 -sqrrN.
rewrite -ltr_sqrt ?sqrtr_sqr ?(lt_le_trans xltr1) ?ler_norm//.
by rewrite exprn_gt0 ?(le_lt_trans _ xltr1) ?sqrtr_ge0.
Qed.
Lemma deg2_poly_gt0r x : r2 < x -> 0 < p.[x].
Proof.
move=> xgtr2; have [? | dge0] := ltP delta 0; first exact: deg2_poly_gt0.
have {}xgtr2 : sqrt delta < x * (2 * a) + b.
by rewrite -ltrBlDr addrC -ltr_pdivrMr.
rewrite [p]deg2_poly_canonical// -/a -/b -/c -/delta !hornerE/=.
rewrite mulr_gt0// subr_gt0 ltr_pdivrMr// xb4.
rewrite -ltr_sqrt ?sqrtr_sqr ?(lt_le_trans xgtr2) ?ler_norm//.
by rewrite exprn_gt0 ?(le_lt_trans _ xgtr2) ?sqrtr_ge0.
Qed.
Lemma deg2_poly_lt0m x : r1 < x < r2 -> p.[x] < 0.
Proof.
move=> /andP[r1ltx xltr2].
have [dle0 | dgt0] := leP delta 0.
by move: (lt_trans r1ltx xltr2); rewrite /r1 /r2 ler0_sqrtr// oppr0 ltxx.
rewrite [p]deg2_poly_canonical// !hornerE/= -/a -/b -/c -/delta.
rewrite pmulr_rlt0// subr_lt0 ltr_pdivlMr// xb4 -ltr_sqrt// sqrtr_sqr ltr_norml.
by rewrite -ltrBlDr addrC -ltr_pdivrMr// r1ltx -ltrBrDr addrC -ltr_pdivlMr.
Qed.
Lemma deg2_poly_ge0l x : x <= r1 -> 0 <= p.[x].
Proof.
rewrite le_eqVlt => /orP[/eqP->|xltr1]; last exact/ltW/deg2_poly_gt0l.
have [dge0|dlt0] := leP 0 delta; last by apply: deg2_poly_ge0 => //; apply: ltW.
by rewrite le_eqVlt (rootP (deg2_poly_root1 dge0)) eqxx.
Qed.
Lemma deg2_poly_ge0r x : r2 <= x -> 0 <= p.[x].
Proof.
rewrite le_eqVlt => /orP[/eqP<-|xgtr2]; last exact/ltW/deg2_poly_gt0r.
have [dge0|dlt0] := leP 0 delta; last by apply: deg2_poly_ge0 => //; apply: ltW.
by rewrite le_eqVlt (rootP (deg2_poly_root2 dge0)) eqxx.
Qed.
Lemma deg2_poly_le0m x : 0 <= delta -> r1 <= x <= r2 -> p.[x] <= 0.
Proof.
move=> dge0; rewrite le_eqVlt andb_orl => /orP[/andP[/eqP<- _]|].
by rewrite le_eqVlt (rootP (deg2_poly_root1 dge0)) eqxx.
rewrite le_eqVlt andb_orr => /orP[/andP[_ /eqP->]|].
by rewrite le_eqVlt (rootP (deg2_poly_root2 dge0)) eqxx.
by move=> ?; apply/ltW/deg2_poly_lt0m.
Qed.
End Pdeg2RealClosedConvex.
Section Pdeg2RealClosedConcave.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Let r1 := (- b + sqrt delta) / (2 * a).
Let r2 := (- b - sqrt delta) / (2 * a).
Hypothesis ale0 : a <= 0.
Let degpN : size (- p) = 3. Proof. by rewrite size_polyN. Qed.
Let aNge0 : 0 <= (- p)`_2. Proof. by rewrite coefN oppr_ge0. Qed.
Let deltaN : (- p)`_1 ^+ 2 - 4 * (- p)`_2 * (- p)`_0 = delta.
Proof. by rewrite !coefN sqrrN -mulrN opprK mulrN mulNr. Qed.
Let r1N : (- (- p)`_1 - sqrt delta) / (2 * (- p)`_2) = r1.
Proof. by rewrite !coefN -opprD mulrN divrNN. Qed.
Let r2N : (- (- p)`_1 + sqrt delta) / (2 * (- p)`_2) = r2.
Proof. by rewrite !coefN mulrN divrN -mulNr opprK opprD. Qed.
Lemma deg2_poly_lt0l x : x < r1 -> p.[x] < 0.
Proof. by move=> ?; rewrite -oppr_gt0 -hornerN deg2_poly_gt0l// deltaN r1N. Qed.
Lemma deg2_poly_lt0r x : r2 < x -> p.[x] < 0.
Proof. by move=> ?; rewrite -oppr_gt0 -hornerN deg2_poly_gt0r// deltaN r2N. Qed.
Lemma deg2_poly_gt0m x : r1 < x < r2 -> 0 < p.[x].
Proof.
by move=> ?; rewrite -oppr_lt0 -hornerN deg2_poly_lt0m// deltaN r1N r2N.
Qed.
Lemma deg2_poly_le0l x : x <= r1 -> p.[x] <= 0.
Proof. by move=> ?; rewrite -oppr_ge0 -hornerN deg2_poly_ge0l// deltaN r1N. Qed.
Lemma deg2_poly_le0r x : r2 <= x -> p.[x] <= 0.
Proof. by move=> ?; rewrite -oppr_ge0 -hornerN deg2_poly_ge0r// deltaN r2N. Qed.
Lemma deg2_poly_ge0m x : 0 <= delta -> r1 <= x <= r2 -> 0 <= p.[x].
Proof.
by move=> ? ?; rewrite -oppr_le0 -hornerN deg2_poly_le0m ?deltaN// r1N r2N.
Qed.
End Pdeg2RealClosedConcave.
End Pdeg2RealClosed.
End Real.
Module RealMonic.
Import Real.
Export FieldMonic.
Section Pdeg2RealMonic.
Variable F : realFieldType.
Variable p : {poly F}.
Hypothesis degp : size p = 3.
Hypothesis monicp : p \is monic.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * c.
Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed.
Let a2 : 2 * a = 2. Proof. by rewrite a1 mulr1. Qed.
Let a4 : 4 * a = 4. Proof. by rewrite a1 mulr1. Qed.
Lemma deg2_poly_min x : p.[- b / 2] <= p.[x].
Proof. by rewrite -a2 deg2_poly_min -/a ?a1 ?ler01. Qed.
Let deltam : delta = b ^+ 2 - 4 * a * c. Proof. by rewrite a1 mulr1. Qed.
Lemma deg2_poly_minE : p.[- b / 2] = - delta / 4.
Proof. by rewrite -a2 -a4 deltam deg2_poly_minE. Qed.
Lemma deg2_poly_gt0 : reflect (forall x, 0 < p.[x]) (delta < 0).
Proof. by rewrite deltam; apply: deg2_poly_gt0; rewrite // -/a a1 ler01. Qed.
Lemma deg2_poly_ge0 : reflect (forall x, 0 <= p.[x]) (delta <= 0).
Proof. by rewrite deltam; apply: deg2_poly_ge0; rewrite // -/a a1 ler01. Qed.
End Pdeg2RealMonic.
Section Pdeg2RealClosedMonic.
Variables (F : rcfType) (p : {poly F}).
Hypothesis degp : size p = 3.
Hypothesis monicp : p \is monic.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed.
Let delta := b ^+ 2 - 4 * c.
Let deltam : delta = b ^+ 2 - 4 * a * c. Proof. by rewrite a1 mulr1. Qed.
Let r1 := (- b - sqrt delta) / 2.
Let r2 := (- b + sqrt delta) / 2.
Let nz2 : 2 != 0 :> F. Proof. by rewrite pnatr_eq0. Qed.
Lemma deg2_poly_factor : 0 <= delta -> p = ('X - r1%:P) * ('X - r2%:P).
Proof. by move=> dge0; apply: deg2_poly_factor; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_root1 : 0 <= delta -> root p r1.
Proof. by move=> dge0; apply: deg2_poly_root1; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_root2 : 0 <= delta -> root p r2.
Proof. by move=> dge0; apply: deg2_poly_root2; rewrite ?sqr_sqrtr. Qed.
Lemma deg2_poly_noroot : reflect (forall x, ~~ root p x) (delta < 0).
Proof. by rewrite deltam; apply: deg2_poly_noroot. Qed.
Lemma deg2_poly_gt0l x : x < r1 -> 0 < p.[x].
Proof.
by move=> ?; apply: deg2_poly_gt0l; rewrite // -/a ?a1 ?ler01 ?mulr1.
Qed.
Lemma deg2_poly_gt0r x : r2 < x -> 0 < p.[x].
Proof.
by move=> ?; apply: deg2_poly_gt0r; rewrite // -/a ?a1 ?ler01 ?mulr1.
Qed.
Lemma deg2_poly_lt0m x : r1 < x < r2 -> p.[x] < 0.
Proof.
by move=> ?; apply: deg2_poly_lt0m; rewrite // -/a ?a1 ?ler01 ?mulr1.
Qed.
Lemma deg2_poly_ge0l x : x <= r1 -> 0 <= p.[x].
Proof.
by move=> ?; apply: deg2_poly_ge0l; rewrite // -/a ?a1 ?ler01 ?mulr1.
Qed.
Lemma deg2_poly_ge0r x : r2 <= x -> 0 <= p.[x].
Proof.
by move=> ?; apply: deg2_poly_ge0r; rewrite // -/a ?a1 ?ler01 ?mulr1.
Qed.
Lemma deg2_poly_le0m x : 0 <= delta -> r1 <= x <= r2 -> p.[x] <= 0.
move=> dge0 xm.
by apply: deg2_poly_le0m; rewrite -/a -/b -/c ?a1 ?mulr1 -/delta ?ler01.
Qed.
End Pdeg2RealClosedMonic.
End RealMonic.
End Pdeg2.
Section Degle2PolyRealConvex.
Variable (F : realFieldType) (p : {poly F}).
Hypothesis degp : (size p <= 3)%N.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg_le2_poly_delta_ge0 : 0 <= a -> (forall x, 0 <= p.[x]) -> delta <= 0.
Proof.
move=> age0 pge0; move: degp; rewrite leq_eqVlt => /orP[/eqP|] degp'.
exact/(Real.deg2_poly_ge0 degp' age0).
have a0 : a = 0 by rewrite /a nth_default.
rewrite /delta a0 mulr0 mul0r subr0 exprn_even_le0//=.
have [//|/eqP nzb] := eqP; move: (pge0 ((- 1 - c) / b)).
have -> : p = b *: 'X + c%:P.
apply/polyP => + /[!coefE] => -[|[|i]] /=; rewrite !Monoid.simpm//.
by rewrite nth_default// -ltnS (leq_trans degp').
by rewrite !hornerE/= mulrAC mulfV// mul1r subrK ler0N1.
Qed.
End Degle2PolyRealConvex.
Section Degle2PolyRealConcave.
Variable (F : realFieldType) (p : {poly F}).
Hypothesis degp : (size p <= 3)%N.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg_le2_poly_delta_le0 : a <= 0 -> (forall x, p.[x] <= 0) -> delta <= 0.
Proof.
move=> ale0 ple0; rewrite /delta -sqrrN -[c]opprK mulrN -mulNr -[-(4 * a)]mulrN.
rewrite -!coefN deg_le2_poly_delta_ge0 ?size_polyN ?coefN ?oppr_ge0// => x.
by rewrite hornerN oppr_ge0.
Qed.
End Degle2PolyRealConcave.
Section Degle2PolyRealClosedConvex.
Variable (F : rcfType) (p : {poly F}).
Hypothesis degp : (size p <= 3)%N.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg_le2_poly_ge0 : (forall x, 0 <= p.[x]) -> delta <= 0.
Proof.
have [age0|alt0] := leP 0 a; first exact: deg_le2_poly_delta_ge0.
move=> pge0; move: degp; rewrite leq_eqVlt => /orP[/eqP|] degp'; last first.
by move: alt0; rewrite /a nth_default ?ltxx.
have [//|dge0] := leP delta 0.
pose r1 := (- b - sqrt delta) / (2 * a).
pose r2 := (- b + sqrt delta) / (2 * a).
pose x0 := Num.max (r1 + 1) (r2 + 1).
move: (pge0 x0); rewrite (Real.deg2_poly_factor degp' (ltW dge0)).
rewrite !hornerE/= -mulrA nmulr_rge0// leNgt => /negbTE<-.
by apply: mulr_gt0; rewrite subr_gt0 lt_max ltrDl ltr01 ?orbT.
Qed.
End Degle2PolyRealClosedConvex.
Section Degle2PolyRealClosedConcave.
Variable (F : rcfType) (p : {poly F}).
Hypothesis degp : (size p <= 3)%N.
Let a := p`_2.
Let b := p`_1.
Let c := p`_0.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg_le2_poly_le0 : (forall x, p.[x] <= 0) -> delta <= 0.
Proof.
move=> ple0; rewrite /delta -sqrrN -[c]opprK mulrN -mulNr -[-(4 * a)]mulrN.
by rewrite -!coefN deg_le2_poly_ge0 ?size_polyN// => x; rewrite hornerN oppr_ge0.
Qed.
End Degle2PolyRealClosedConcave.
End Theory.
Module Exports. HB.reexport. End Exports.
End Num.
Export Num.Exports.
|
Angle.lean
|
/-
Copyright (c) 2024 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Bounds
import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic
/-!
# Angle between complex numbers
This file relates the Euclidean geometric notion of angle between complex numbers to the argument of
their quotient.
It also shows that the arc and chord distances between two unit complex numbers are equivalent up to
a factor of `Ο / 2`.
## TODO
Prove the corresponding results for oriented angles.
## Tags
arc-length, arc-distance
-/
open InnerProductGeometry Set
open scoped Real
namespace Complex
variable {a x y : β}
/-- The angle between two non-zero complex numbers is the absolute value of the argument of their
quotient.
Note that this does not hold when `x` or `y` is `0` as the LHS is `Ο / 2` while the RHS is `0`. -/
lemma angle_eq_abs_arg (hx : x β 0) (hy : y β 0) : angle x y = |(x / y).arg| := by
refine Real.arccos_eq_of_eq_cos (abs_nonneg _) (abs_arg_le_pi _) ?_
rw [Real.cos_abs, Complex.cos_arg (div_ne_zero hx hy)]
simp [div_eq_mul_inv, Complex.normSq_eq_norm_sq]
field_simp
ring
lemma angle_one_left (hy : y β 0) : angle 1 y = |y.arg| := by simp [angle_eq_abs_arg, hy]
lemma angle_one_right (hx : x β 0) : angle x 1 = |x.arg| := by simp [angle_eq_abs_arg, hx]
@[simp] lemma angle_mul_left (ha : a β 0) (x y : β) : angle (a * x) (a * y) = angle x y := by
obtain rfl | hx := eq_or_ne x 0 <;> obtain rfl | hy := eq_or_ne y 0 <;>
simp [angle_eq_abs_arg, mul_div_mul_left, *]
@[simp] lemma angle_mul_right (ha : a β 0) (x y : β) : angle (x * a) (y * a) = angle x y := by
simp [mul_comm, angle_mul_left ha]
lemma angle_div_left_eq_angle_mul_right (a x y : β) : angle (x / a) y = angle x (y * a) := by
obtain rfl | ha := eq_or_ne a 0
Β· simp
Β· rw [β angle_mul_right ha, div_mul_cancelβ _ ha]
lemma angle_div_right_eq_angle_mul_left (a x y : β) : angle x (y / a) = angle (x * a) y := by
rw [angle_comm, angle_div_left_eq_angle_mul_right, angle_comm]
lemma angle_exp_exp (x y : β) :
angle (exp (x * I)) (exp (y * I)) = |toIocMod Real.two_pi_pos (-Ο) (x - y)| := by
simp_rw [angle_eq_abs_arg (exp_ne_zero _) (exp_ne_zero _), β exp_sub, β sub_mul, β ofReal_sub,
arg_exp_mul_I]
lemma angle_exp_one (x : β) : angle (exp (x * I)) 1 = |toIocMod Real.two_pi_pos (-Ο) x| := by
simpa using angle_exp_exp x 0
/-!
### Arc-length and chord-length are equivalent
This section shows that the arc and chord distances between two unit complex numbers are equivalent
up to a factor of `Ο / 2`.
-/
/-- Chord-length is a multiple of arc-length up to constants. -/
lemma norm_sub_mem_Icc_angle (hx : βxβ = 1) (hy : βyβ = 1) :
βx - yβ β Icc (2 / Ο * angle x y) (angle x y) := by
wlog h : y = 1
Β· have := @this (x / y) 1 (by simp only [norm_div, hx, hy, div_one]) norm_one rfl
rwa [angle_div_left_eq_angle_mul_right, div_sub_one, norm_div, hy, div_one, one_mul]
at this
rintro rfl
simp at hy
subst y
rw [norm_eq_one_iff'] at hx
obtain β¨ΞΈ, hΞΈ, rflβ© := hx
rw [angle_exp_one, exp_mul_I, add_sub_right_comm, (toIocMod_eq_self _).2]
Β· norm_cast
rw [norm_add_mul_I]
refine β¨Real.le_sqrt_of_sq_le ?_, ?_β©
Β· rw [mul_pow, β abs_pow, abs_sq]
calc
_ = 2 * (1 - (1 - 2 / Ο ^ 2 * ΞΈ ^ 2)) := by ring
_ β€ 2 * (1 - ΞΈ.cos) := by
gcongr; exact Real.cos_le_one_sub_mul_cos_sq <| abs_le.2 <| Ioc_subset_Icc_self hΞΈ
_ = _ := by linear_combination -ΞΈ.cos_sq_add_sin_sq
Β· rw [Real.sqrt_le_left (by positivity), β abs_pow, abs_sq]
calc
_ = 2 * (1 - ΞΈ.cos) := by linear_combination ΞΈ.cos_sq_add_sin_sq
_ β€ 2 * (1 - (1 - ΞΈ ^ 2 / 2)) := by gcongr; exact Real.one_sub_sq_div_two_le_cos
_ = _ := by ring
Β· convert hΞΈ
ring
/-- Chord-length is always less than arc-length. -/
lemma norm_sub_le_angle (hx : βxβ = 1) (hy : βyβ = 1) : βx - yβ β€ angle x y :=
(norm_sub_mem_Icc_angle hx hy).2
/-- Chord-length is always greater than a multiple of arc-length. -/
lemma mul_angle_le_norm_sub (hx : βxβ = 1) (hy : βyβ = 1) : 2 / Ο * angle x y β€ βx - yβ :=
(norm_sub_mem_Icc_angle hx hy).1
/-- Arc-length is always less than a multiple of chord-length. -/
lemma angle_le_mul_norm_sub (hx : βxβ = 1) (hy : βyβ = 1) : angle x y β€ Ο / 2 * βx - yβ := by
rw [β div_le_iffβ' <| by positivity, div_eq_inv_mul, inv_div]; exact mul_angle_le_norm_sub hx hy
end Complex
|
nilpotent.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 div bigop prime finset fingroup morphism.
From mathcomp Require Import automorphism quotient commutator gproduct.
From mathcomp Require Import perm gfunctor center gseries cyclic.
From mathcomp Require finfun.
(******************************************************************************)
(* This file defines nilpotent and solvable groups, and give some of their *)
(* elementary properties; more will be added later (e.g., the nilpotence of *)
(* p-groups in sylow.v, or the fact that minimal normal subgroups of solvable *)
(* groups are elementary abelian in maximal.v). This file defines: *)
(* nilpotent G == G is nilpotent, i.e., [~: H, G] is a proper subgroup of H *)
(* for all nontrivial H <| G. *)
(* solvable G == G is solvable, i.e., H^`(1) is a proper subgroup of H for *)
(* all nontrivial subgroups H of G. *)
(* 'L_n(G) == the nth term of the lower central series, namely *)
(* [~: G, ..., G] (n Gs) if n > 0, with 'L_0(G) = G. *)
(* G is nilpotent iff 'L_n(G) = 1 for some n. *)
(* 'Z_n(G) == the nth term of the upper central series, i.e., *)
(* with 'Z_0(G) = 1, 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)). *)
(* nil_class G == the nilpotence class of G, i.e., the least n such that *)
(* 'L_n.+1(G) = 1 (or, equivalently, 'Z_n(G) = G), if G is *)
(* nilpotent; we take nil_class G = #|G| when G is not *)
(* nilpotent, so nil_class G < #|G| iff G is nilpotent. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section SeriesDefs.
Variables (n : nat) (gT : finGroupType) (A : {set gT}).
(* By convention, the lower central series starts at 1 while the upper series *)
(* starts at 0 (sic). *)
Definition lower_central_at := iter n.-1 (fun B => [~: B, A]) A.
Definition upper_central_at := iter n (fun B => coset B @*^-1 'Z(A / B)) 1.
End SeriesDefs.
Arguments lower_central_at n%_N {gT} A%_g.
Arguments upper_central_at n%_N {gT} A%_g : simpl never.
Notation "''L_' n ( G )" := (lower_central_at n G)
(n at level 2, format "''L_' n ( G )") : group_scope.
Notation "''Z_' n ( G )" := (upper_central_at n G)
(n at level 2, format "''Z_' n ( G )") : group_scope.
Section PropertiesDefs.
Variables (gT : finGroupType) (A : {set gT}).
Definition nilpotent :=
[forall (G : {group gT} | G \subset A :&: [~: G, A]), G :==: 1].
Definition nil_class := index 1 (mkseq (fun n => 'L_n.+1(A)) #|A|).
Definition solvable :=
[forall (G : {group gT} | G \subset A :&: [~: G, G]), G :==: 1].
End PropertiesDefs.
Arguments nilpotent {gT} A%_g.
Arguments nil_class {gT} A%_g.
Arguments solvable {gT} A%_g.
Section NilpotentProps.
Variable gT: finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma nilpotent1 : nilpotent [1 gT].
Proof. by apply/forall_inP=> H; rewrite commG1 setIid -subG1. Qed.
Lemma nilpotentS A B : B \subset A -> nilpotent A -> nilpotent B.
Proof.
move=> sBA nilA; apply/forall_inP=> H sHR.
have:= forallP nilA H; rewrite (subset_trans sHR) //.
by apply: subset_trans (setIS _ _) (setSI _ _); rewrite ?commgS.
Qed.
Lemma nil_comm_properl G H A :
nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) ->
[~: H, A] \proper H.
Proof.
move=> nilG sHG ntH; rewrite subsetI properE; case/andP=> sAG nHA.
rewrite (subset_trans (commgS H (subset_gen A))) ?commg_subl ?gen_subG //.
apply: contra ntH => sHR; have:= forallP nilG H; rewrite subsetI sHG.
by rewrite (subset_trans sHR) ?commgS.
Qed.
Lemma nil_comm_properr G A H :
nilpotent G -> H \subset G -> H :!=: 1 -> A \subset 'N_G(H) ->
[~: A, H] \proper H.
Proof. by rewrite commGC; apply: nil_comm_properl. Qed.
Lemma centrals_nil (s : seq {group gT}) G :
G.-central.-series 1%G s -> last 1%G s = G -> nilpotent G.
Proof.
move=> cGs defG; apply/forall_inP=> H /subsetIP[sHG sHR].
move: sHG; rewrite -{}defG -subG1 -[1]/(gval 1%G).
elim: s 1%G cGs => //= L s IHs K /andP[/and3P[sRK sKL sLG] /IHs sHL] sHs.
exact: subset_trans sHR (subset_trans (commSg _ (sHL sHs)) sRK).
Qed.
End NilpotentProps.
Section LowerCentral.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma lcn0 A : 'L_0(A) = A. Proof. by []. Qed.
Lemma lcn1 A : 'L_1(A) = A. Proof. by []. Qed.
Lemma lcnSn n A : 'L_n.+2(A) = [~: 'L_n.+1(A), A]. Proof. by []. Qed.
Lemma lcnSnS n G : [~: 'L_n(G), G] \subset 'L_n.+1(G).
Proof. by case: n => //; apply: der1_subG. Qed.
Lemma lcnE n A : 'L_n.+1(A) = iter n (fun B => [~: B, A]) A.
Proof. by []. Qed.
Lemma lcn2 A : 'L_2(A) = A^`(1). Proof. by []. Qed.
Lemma lcn_group_set n G : group_set 'L_n(G).
Proof. by case: n => [|[|n]]; apply: groupP. Qed.
Canonical lower_central_at_group n G := Group (lcn_group_set n G).
Lemma lcn_char n G : 'L_n(G) \char G.
Proof. by case: n; last elim=> [|n IHn]; rewrite ?char_refl ?lcnSn ?charR. Qed.
Lemma lcn_normal n G : 'L_n(G) <| G.
Proof. exact/char_normal/lcn_char. Qed.
Lemma lcn_sub n G : 'L_n(G) \subset G.
Proof. exact/char_sub/lcn_char. Qed.
Lemma lcn_norm n G : G \subset 'N('L_n(G)).
Proof. exact/char_norm/lcn_char. Qed.
Lemma lcn_subS n G : 'L_n.+1(G) \subset 'L_n(G).
Proof.
case: n => // n; rewrite lcnSn commGC commg_subr.
by case/andP: (lcn_normal n.+1 G).
Qed.
Lemma lcn_normalS n G : 'L_n.+1(G) <| 'L_n(G).
Proof. by apply: normalS (lcn_normal _ _); rewrite (lcn_subS, lcn_sub). Qed.
Lemma lcn_central n G : 'L_n(G) / 'L_n.+1(G) \subset 'Z(G / 'L_n.+1(G)).
Proof.
case: n => [|n]; first by rewrite trivg_quotient sub1G.
by rewrite subsetI quotientS ?lcn_sub ?quotient_cents2r.
Qed.
Lemma lcn_sub_leq m n G : n <= m -> 'L_m(G) \subset 'L_n(G).
Proof.
by move/subnK <-; elim: {m}(m - n) => // m; apply: subset_trans (lcn_subS _ _).
Qed.
Lemma lcnS n A B : A \subset B -> 'L_n(A) \subset 'L_n(B).
Proof.
by case: n => // n sAB; elim: n => // n IHn; rewrite !lcnSn genS ?imset2S.
Qed.
Lemma lcn_cprod n A B G : A \* B = G -> 'L_n(A) \* 'L_n(B) = 'L_n(G).
Proof.
case: n => // n /cprodP[[H K -> ->{A B}] defG cHK].
have sL := subset_trans (lcn_sub _ _); rewrite cprodE ?(centSS _ _ cHK) ?sL //.
symmetry; elim: n => // n; rewrite lcnSn => ->; rewrite commMG /=; last first.
by apply: subset_trans (commg_normr _ _); rewrite sL // -defG mulG_subr.
rewrite -!(commGC G) -defG -{1}(centC cHK).
rewrite !commMG ?normsR ?lcn_norm ?cents_norm // 1?centsC //.
by rewrite -!(commGC 'L__(_)) -!lcnSn !(commG1P _) ?mul1g ?sL // centsC.
Qed.
Lemma lcn_dprod n A B G : A \x B = G -> 'L_n(A) \x 'L_n(B) = 'L_n(G).
Proof.
move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG.
rewrite !dprodEcp // in defG *; first exact: lcn_cprod.
by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?lcn_sub.
Qed.
Lemma der_cprod n A B G : A \* B = G -> A^`(n) \* B^`(n) = G^`(n).
Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_cprod 2). Qed.
Lemma der_dprod n A B G : A \x B = G -> A^`(n) \x B^`(n) = G^`(n).
Proof. by move=> defG; elim: n => {defG}// n; apply: (lcn_dprod 2). Qed.
Lemma lcn_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub.
by rewrite -(lcn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma lcn_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'L_n(F i) = 'L_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first exact/esym/trivgP/lcn_sub.
by rewrite -(lcn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma der_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(der_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma der_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) (F i)^`(n) = G^`(n).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(der_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma nilpotent_class G : nilpotent G = (nil_class G < #|G|).
Proof.
rewrite /nil_class; set s := mkseq _ _.
transitivity (1 \in s); last by rewrite -index_mem size_mkseq.
apply/idP/mapP=> {s}/= [nilG | [n _ Ln1]]; last first.
apply/forall_inP=> H /subsetIP[sHG sHR].
rewrite -subG1 {}Ln1; elim: n => // n IHn.
by rewrite (subset_trans sHR) ?commSg.
pose m := #|G|.-1; exists m; first by rewrite mem_iota /= prednK.
set n := m; rewrite ['L__(G)]card_le1_trivg //= -(subnn m) -[m in _ - m]/n.
elim: n => [|n]; [by rewrite subn0 prednK | rewrite lcnSn subnS].
case: (eqsVneq 'L_n.+1(G) 1) => [-> | ntLn]; first by rewrite comm1G cards1.
case: (m - n) => [|m' /= IHn]; first by rewrite leqNgt cardG_gt1 ntLn.
rewrite -ltnS (leq_trans (proper_card _) IHn) //.
by rewrite (nil_comm_properl nilG) ?lcn_sub // subsetI subxx lcn_norm.
Qed.
Lemma lcn_nil_classP n G :
nilpotent G -> reflect ('L_n.+1(G) = 1) (nil_class G <= n).
Proof.
rewrite nilpotent_class /nil_class; set s := mkseq _ _.
set c := index 1 s => lt_c_G; case: leqP => [le_c_n | lt_n_c].
have Lc1: nth 1 s c = 1 by rewrite nth_index // -index_mem size_mkseq.
by left; apply/trivgP; rewrite -Lc1 nth_mkseq ?lcn_sub_leq.
right; apply/eqP/negPf; rewrite -(before_find 1 lt_n_c) nth_mkseq //.
exact: ltn_trans lt_n_c lt_c_G.
Qed.
Lemma lcnP G : reflect (exists n, 'L_n.+1(G) = 1) (nilpotent G).
Proof.
apply: (iffP idP) => [nilG | [n Ln1]].
by exists (nil_class G); apply/lcn_nil_classP.
apply/forall_inP=> H /subsetIP[sHG sHR]; rewrite -subG1 -{}Ln1.
by elim: n => // n IHn; rewrite (subset_trans sHR) ?commSg.
Qed.
Lemma abelian_nil G : abelian G -> nilpotent G.
Proof. by move=> abG; apply/lcnP; exists 1%N; apply/commG1P. Qed.
Lemma nil_class0 G : (nil_class G == 0) = (G :==: 1).
Proof.
apply/idP/eqP=> [nilG | ->].
by apply/(lcn_nil_classP 0); rewrite ?nilpotent_class (eqP nilG) ?cardG_gt0.
by rewrite -leqn0; apply/(lcn_nil_classP 0); rewrite ?nilpotent1.
Qed.
Lemma nil_class1 G : (nil_class G <= 1) = abelian G.
Proof.
have [-> | ntG] := eqsVneq G 1.
by rewrite abelian1 leq_eqVlt ltnS leqn0 nil_class0 eqxx orbT.
apply/idP/idP=> cGG.
apply/commG1P; apply/(lcn_nil_classP 1); rewrite // nilpotent_class.
by rewrite (leq_ltn_trans cGG) // cardG_gt1.
by apply/(lcn_nil_classP 1); rewrite ?abelian_nil //; apply/commG1P.
Qed.
Lemma cprod_nil A B G : A \* B = G -> nilpotent G = nilpotent A && nilpotent B.
Proof.
move=> defG; case/cprodP: defG (defG) => [[H K -> ->{A B}] defG _] defGc.
apply/idP/andP=> [nilG | [/lcnP[m LmH1] /lcnP[n LnK1]]].
by rewrite !(nilpotentS _ nilG) // -defG (mulG_subr, mulG_subl).
apply/lcnP; exists (m + n.+1); apply/trivgP.
case/cprodP: (lcn_cprod (m.+1 + n.+1) defGc) => _ <- _.
by rewrite mulG_subG /= -{1}LmH1 -LnK1 !lcn_sub_leq ?leq_addl ?leq_addr.
Qed.
Lemma mulg_nil G H :
H \subset 'C(G) -> nilpotent (G * H) = nilpotent G && nilpotent H.
Proof. by move=> cGH; rewrite -(cprod_nil (cprodEY cGH)) /= cent_joinEr. Qed.
Lemma dprod_nil A B G : A \x B = G -> nilpotent G = nilpotent A && nilpotent B.
Proof. by case/dprodP=> [[H K -> ->] <- cHK _]; rewrite mulg_nil.
Qed.
Lemma bigdprod_nil I r (P : pred I) (A_ : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) A_ i = G
-> (forall i, P i -> nilpotent (A_ i)) -> nilpotent G.
Proof.
move=> defG nilA; elim/big_rec: _ => [|i B Pi nilB] in G defG *.
by rewrite -defG nilpotent1.
have [[_ H _ defB] _ _ _] := dprodP defG.
by rewrite (dprod_nil defG) nilA //= defB nilB.
Qed.
End LowerCentral.
Notation "''L_' n ( G )" := (lower_central_at_group n G) : Group_scope.
Lemma lcn_cont n : GFunctor.continuous (@lower_central_at n).
Proof.
case: n => //; elim=> // n IHn g0T h0T H phi.
by rewrite !lcnSn morphimR ?lcn_sub // commSg ?IHn.
Qed.
Canonical lcn_igFun n := [igFun by lcn_sub^~ n & lcn_cont n].
Canonical lcn_gFun n := [gFun by lcn_cont n].
Canonical lcn_mgFun n := [mgFun by fun _ G H => @lcnS _ n G H].
Section UpperCentralFunctor.
Variable n : nat.
Implicit Type gT : finGroupType.
Lemma ucn_pmap : exists hZ : GFunctor.pmap, @upper_central_at n = hZ.
Proof.
elim: n => [|n' [hZ defZ]]; first by exists trivGfun_pgFun.
by exists [pgFun of @center %% hZ]; rewrite /= -defZ.
Qed.
(* Now extract all the intermediate facts of the last proof. *)
Lemma ucn_group_set gT (G : {group gT}) : group_set 'Z_n(G).
Proof. by have [hZ ->] := ucn_pmap; apply: groupP. Qed.
Canonical upper_central_at_group gT G := Group (@ucn_group_set gT G).
Lemma ucn_sub gT (G : {group gT}) : 'Z_n(G) \subset G.
Proof. by have [hZ ->] := ucn_pmap; apply: gFsub. Qed.
Lemma morphim_ucn : GFunctor.pcontinuous (@upper_central_at n).
Proof. by have [hZ ->] := ucn_pmap; apply: pmorphimF. Qed.
Canonical ucn_igFun := [igFun by ucn_sub & morphim_ucn].
Canonical ucn_gFun := [gFun by morphim_ucn].
Canonical ucn_pgFun := [pgFun by morphim_ucn].
Variable (gT : finGroupType) (G : {group gT}).
Lemma ucn_char : 'Z_n(G) \char G. Proof. exact: gFchar. Qed.
Lemma ucn_norm : G \subset 'N('Z_n(G)). Proof. exact: gFnorm. Qed.
Lemma ucn_normal : 'Z_n(G) <| G. Proof. exact: gFnormal. Qed.
End UpperCentralFunctor.
Notation "''Z_' n ( G )" := (upper_central_at_group n G) : Group_scope.
Section UpperCentral.
Variable gT : finGroupType.
Implicit Types (A B : {set gT}) (G H : {group gT}).
Lemma ucn0 A : 'Z_0(A) = 1.
Proof. by []. Qed.
Lemma ucnSn n A : 'Z_n.+1(A) = coset 'Z_n(A) @*^-1 'Z(A / 'Z_n(A)).
Proof. by []. Qed.
Lemma ucnE n A : 'Z_n(A) = iter n (fun B => coset B @*^-1 'Z(A / B)) 1.
Proof. by []. Qed.
Lemma ucn_subS n G : 'Z_n(G) \subset 'Z_n.+1(G).
Proof. by rewrite -{1}['Z_n(G)]ker_coset morphpreS ?sub1G. Qed.
Lemma ucn_sub_geq m n G : n >= m -> 'Z_m(G) \subset 'Z_n(G).
Proof.
move/subnK <-; elim: {n}(n - m) => // n IHn.
exact: subset_trans (ucn_subS _ _).
Qed.
Lemma ucn_central n G : 'Z_n.+1(G) / 'Z_n(G) = 'Z(G / 'Z_n(G)).
Proof. by rewrite ucnSn cosetpreK. Qed.
Lemma ucn_normalS n G : 'Z_n(G) <| 'Z_n.+1(G).
Proof. by rewrite (normalS _ _ (ucn_normal n G)) ?ucn_subS ?ucn_sub. Qed.
Lemma ucn_comm n G : [~: 'Z_n.+1(G), G] \subset 'Z_n(G).
Proof.
rewrite -quotient_cents2 ?normal_norm ?ucn_normal ?ucn_normalS //.
by rewrite ucn_central subsetIr.
Qed.
Lemma ucn1 G : 'Z_1(G) = 'Z(G).
Proof.
apply: (quotient_inj (normal1 _) (normal1 _)).
by rewrite /= (ucn_central 0) -injmF ?norms1 ?coset1_injm.
Qed.
Lemma ucnSnR n G : 'Z_n.+1(G) = [set x in G | [~: [set x], G] \subset 'Z_n(G)].
Proof.
(* apply/setP=> x; rewrite inE -(setIidPr (ucn_sub n.+1 G)) inE ucnSn. *)
(* FIXME: before, we got a `rewrite inE` right after the apply/setP=> x. *
* However, this rewrite unfolds termes to strange internal HB names. *
* We fixed the issue by applying the inE more carefully, but the problem *
* needs to be investigated. *)
apply/setP=> x; rewrite -(setIidPr (ucn_sub n.+1 G)) [LHS]inE [RHS]inE ucnSn.
case Gx: (x \in G) => //=; have nZG := ucn_norm n G.
rewrite -sub1set -sub_quotient_pre -?quotient_cents2 ?sub1set ?(subsetP nZG) //.
by rewrite subsetI quotientS ?sub1set.
Qed.
Lemma ucn_cprod n A B G : A \* B = G -> 'Z_n(A) \* 'Z_n(B) = 'Z_n(G).
Proof.
case/cprodP=> [[H K -> ->{A B}] mulHK cHK].
elim: n => [|n /cprodP[_ /= defZ cZn]]; first exact: cprod1g.
set Z := 'Z_n(G) in defZ cZn; rewrite (ucnSn n G) /= -/Z.
have /mulGsubP[nZH nZK]: H * K \subset 'N(Z) by rewrite mulHK gFnorm.
have <-: 'Z(H / Z) * 'Z(K / Z) = 'Z(G / Z).
by rewrite -mulHK quotientMl // center_prod ?quotient_cents.
have ZquoZ (B A : {group gT}):
B \subset 'C(A) -> 'Z_n(A) * 'Z_n(B) = Z -> 'Z(A / Z) = 'Z_n.+1(A) / Z.
- move=> cAB {}defZ; have cAZnB: 'Z_n(B) \subset 'C(A) := gFsub_trans _ cAB.
have /second_isom[/=]: A \subset 'N(Z).
by rewrite -defZ normsM ?gFnorm ?cents_norm // centsC.
suffices ->: Z :&: A = 'Z_n(A).
by move=> f inj_f im_f; rewrite -!im_f ?gFsub // ucn_central injm_center.
rewrite -defZ -group_modl ?gFsub //; apply/mulGidPl.
have [-> | n_gt0] := posnP n; first exact: subsetIl.
by apply: subset_trans (ucn_sub_geq A n_gt0); rewrite /= setIC ucn1 setIS.
rewrite (ZquoZ H K) 1?centsC 1?(centC cZn) // {ZquoZ}(ZquoZ K H) //.
have cZn1: 'Z_n.+1(K) \subset 'C('Z_n.+1(H)) by apply: centSS cHK; apply: gFsub.
rewrite -quotientMl ?quotientK ?mul_subG ?gFsub_trans //=.
rewrite cprodE // -cent_joinEr ?mulSGid //= cent_joinEr //= -/Z.
by rewrite -defZ mulgSS ?ucn_subS.
Qed.
Lemma ucn_dprod n A B G : A \x B = G -> 'Z_n(A) \x 'Z_n(B) = 'Z_n(G).
Proof.
move=> defG; have [[K H defA defB] _ _ tiAB] := dprodP defG.
rewrite !dprodEcp // in defG *; first exact: ucn_cprod.
by rewrite defA defB; apply/trivgP; rewrite -tiAB defA defB setISS ?ucn_sub.
Qed.
Lemma ucn_bigcprod n I r P (F : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) F i = G ->
\big[cprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(ucn_cprod n dG); have [[_ H _ dH]] := cprodP dG; rewrite dH (IH H).
Qed.
Lemma ucn_bigdprod n I r P (F : I -> {set gT}) G :
\big[dprod/1]_(i <- r | P i) F i = G ->
\big[dprod/1]_(i <- r | P i) 'Z_n(F i) = 'Z_n(G).
Proof.
elim/big_rec2: _ G => [_ <- | i A Z _ IH G dG]; first by rewrite gF1.
by rewrite -(ucn_dprod n dG); have [[_ H _ dH]] := dprodP dG; rewrite dH (IH H).
Qed.
Lemma ucn_lcnP n G : ('L_n.+1(G) == 1) = ('Z_n(G) == G).
Proof.
rewrite !eqEsubset sub1G ucn_sub /= andbT -(ucn0 G); set i := (n in LHS).
have: i + 0 = n by [rewrite addn0]; elim: i 0 => [j <- //|i IHi j].
rewrite addSnnS => /IHi <- {IHi}; rewrite ucnSn lcnSn.
rewrite -sub_morphim_pre ?gFsub_trans ?gFnorm_trans // subsetI.
by rewrite morphimS ?gFsub // quotient_cents2 ?gFsub_trans ?gFnorm_trans.
Qed.
Lemma ucnP G : reflect (exists n, 'Z_n(G) = G) (nilpotent G).
Proof.
apply: (iffP (lcnP G)) => -[n /eqP-clGn];
by exists n; apply/eqP; rewrite ucn_lcnP in clGn *.
Qed.
Lemma ucn_nil_classP n G :
nilpotent G -> reflect ('Z_n(G) = G) (nil_class G <= n).
Proof.
move=> nilG; rewrite (sameP (lcn_nil_classP n nilG) eqP) ucn_lcnP; apply: eqP.
Qed.
Lemma ucn_id n G : 'Z_n('Z_n(G)) = 'Z_n(G).
Proof. exact: gFid. Qed.
Lemma ucn_nilpotent n G : nilpotent 'Z_n(G).
Proof. by apply/ucnP; exists n; rewrite ucn_id. Qed.
Lemma nil_class_ucn n G : nil_class 'Z_n(G) <= n.
Proof. by apply/ucn_nil_classP; rewrite ?ucn_nilpotent // ucn_id. Qed.
End UpperCentral.
Section MorphNil.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Type G : {group aT}.
Lemma morphim_lcn n G : G \subset D -> f @* 'L_n(G) = 'L_n(f @* G).
Proof.
move=> sHG; case: n => //; elim=> // n IHn.
by rewrite !lcnSn -IHn morphimR // (subset_trans _ sHG) // lcn_sub.
Qed.
Lemma injm_ucn n G : 'injm f -> G \subset D -> f @* 'Z_n(G) = 'Z_n(f @* G).
Proof. exact: injmF. Qed.
Lemma morphim_nil G : nilpotent G -> nilpotent (f @* G).
Proof.
case/ucnP=> n ZnG; apply/ucnP; exists n; apply/eqP.
by rewrite eqEsubset ucn_sub /= -{1}ZnG morphim_ucn.
Qed.
Lemma injm_nil G : 'injm f -> G \subset D -> nilpotent (f @* G) = nilpotent G.
Proof.
move=> injf sGD; apply/idP/idP; last exact: morphim_nil.
case/ucnP=> n; rewrite -injm_ucn // => /injm_morphim_inj defZ.
by apply/ucnP; exists n; rewrite defZ ?gFsub_trans.
Qed.
Lemma nil_class_morphim G : nilpotent G -> nil_class (f @* G) <= nil_class G.
Proof.
move=> nilG; rewrite (sameP (ucn_nil_classP _ (morphim_nil nilG)) eqP) /=.
by rewrite eqEsubset ucn_sub -{1}(ucn_nil_classP _ nilG (leqnn _)) morphim_ucn.
Qed.
Lemma nil_class_injm G :
'injm f -> G \subset D -> nil_class (f @* G) = nil_class G.
Proof.
move=> injf sGD; case nilG: (nilpotent G).
apply/eqP; rewrite eqn_leq nil_class_morphim //.
rewrite (sameP (lcn_nil_classP _ nilG) eqP) -subG1.
rewrite -(injmSK injf) ?gFsub_trans // morphim1.
by rewrite morphim_lcn // (lcn_nil_classP _ _ (leqnn _)) //= injm_nil.
transitivity #|G|; apply/eqP; rewrite eqn_leq.
rewrite -(card_injm injf sGD) (leq_trans (index_size _ _)) ?size_mkseq //.
by rewrite leqNgt -nilpotent_class injm_nil ?nilG.
rewrite (leq_trans (index_size _ _)) ?size_mkseq // leqNgt -nilpotent_class.
by rewrite nilG.
Qed.
End MorphNil.
Section QuotientNil.
Variables gT : finGroupType.
Implicit Types (rT : finGroupType) (G H : {group gT}).
Lemma quotient_ucn_add m n G : 'Z_(m + n)(G) / 'Z_n(G) = 'Z_m(G / 'Z_n(G)).
Proof.
elim: m => [|m IHm]; first exact: trivg_quotient.
apply/setP=> Zx; have [x Nx ->{Zx}] := cosetP Zx.
have [sZG nZG] := andP (ucn_normal n G).
rewrite (ucnSnR m) inE -!sub1set -morphim_set1 //= -quotientR ?sub1set // -IHm.
rewrite !quotientSGK ?(ucn_sub_geq, leq_addl, comm_subG _ nZG, sub1set) //=.
by rewrite addSn /= ucnSnR inE.
Qed.
Lemma isog_nil rT G (L : {group rT}) : G \isog L -> nilpotent G = nilpotent L.
Proof. by case/isogP=> f injf <-; rewrite injm_nil. Qed.
Lemma isog_nil_class rT G (L : {group rT}) :
G \isog L -> nil_class G = nil_class L.
Proof. by case/isogP=> f injf <-; rewrite nil_class_injm. Qed.
Lemma quotient_nil G H : nilpotent G -> nilpotent (G / H).
Proof. exact: morphim_nil. Qed.
Lemma quotient_center_nil G : nilpotent (G / 'Z(G)) = nilpotent G.
Proof.
rewrite -ucn1; apply/idP/idP; last exact: quotient_nil.
case/ucnP=> c nilGq; apply/ucnP; exists c.+1; have nsZ1G := ucn_normal 1 G.
apply: (quotient_inj _ nsZ1G); last by rewrite /= -(addn1 c) quotient_ucn_add.
by rewrite (normalS _ _ nsZ1G) ?ucn_sub ?ucn_sub_geq.
Qed.
Lemma nil_class_quotient_center G :
nilpotent (G) -> nil_class (G / 'Z(G)) = (nil_class G).-1.
Proof.
move=> nilG; have nsZ1G := ucn_normal 1 G.
apply/eqP; rewrite -ucn1 eqn_leq; apply/andP; split.
apply/ucn_nil_classP; rewrite ?quotient_nil //= -quotient_ucn_add ucn1.
by rewrite (ucn_nil_classP _ _ _) ?addn1 ?leqSpred.
rewrite -subn1 leq_subLR addnC; apply/ucn_nil_classP => //=.
apply: (quotient_inj _ nsZ1G) => /=.
by apply: normalS (ucn_sub _ _) nsZ1G; rewrite /= addnS ucn_sub_geq.
by rewrite quotient_ucn_add; apply/ucn_nil_classP; rewrite //= quotient_nil.
Qed.
Lemma nilpotent_sub_norm G H :
nilpotent G -> H \subset G -> 'N_G(H) \subset H -> G :=: H.
Proof.
move=> nilG sHG sNH; apply/eqP; rewrite eqEsubset sHG andbT; apply/negP=> nsGH.
have{nsGH} [i sZH []]: exists2 i, 'Z_i(G) \subset H & ~ 'Z_i.+1(G) \subset H.
case/ucnP: nilG => n ZnG; rewrite -{}ZnG in nsGH.
elim: n => [|i IHi] in nsGH *; first by rewrite sub1G in nsGH.
by case sZH: ('Z_i(G) \subset H); [exists i | apply: IHi; rewrite sZH].
apply: subset_trans sNH; rewrite subsetI ucn_sub -commg_subr.
by apply: subset_trans sZH; apply: subset_trans (ucn_comm i G); apply: commgS.
Qed.
Lemma nilpotent_proper_norm G H :
nilpotent G -> H \proper G -> H \proper 'N_G(H).
Proof.
move=> nilG; rewrite properEneq properE subsetI normG => /andP[neHG sHG].
by rewrite sHG; apply: contra neHG => /(nilpotent_sub_norm nilG)->.
Qed.
Lemma nilpotent_subnormal G H : nilpotent G -> H \subset G -> H <|<| G.
Proof.
move=> nilG; have [m] := ubnP (#|G| - #|H|).
elim: m H => // m IHm H /ltnSE-leGHm sHG.
have [->|] := eqVproper sHG; first exact: subnormal_refl.
move/(nilpotent_proper_norm nilG); set K := 'N_G(H) => prHK.
have snHK: H <|<| K by rewrite normal_subnormal ?normalSG.
have sKG: K \subset G by rewrite subsetIl.
apply: subnormal_trans snHK (IHm _ (leq_trans _ leGHm) sKG).
by rewrite ltn_sub2l ?proper_card ?(proper_sub_trans prHK).
Qed.
Lemma TI_center_nil G H : nilpotent G -> H <| G -> H :&: 'Z(G) = 1 -> H :=: 1.
Proof.
move=> nilG /andP[sHG nHG] tiHZ.
rewrite -{1}(setIidPl sHG); have{nilG} /ucnP[n <-] := nilG.
elim: n => [|n IHn]; apply/trivgP; rewrite ?subsetIr // -tiHZ.
rewrite [H :&: 'Z(G)]setIA subsetI setIS ?ucn_sub //= (sameP commG1P trivgP).
rewrite -commg_subr commGC in nHG.
rewrite -IHn subsetI (subset_trans _ nHG) ?commSg ?subsetIl //=.
by rewrite (subset_trans _ (ucn_comm n G)) ?commSg ?subsetIr.
Qed.
Lemma meet_center_nil G H :
nilpotent G -> H <| G -> H :!=: 1 -> H :&: 'Z(G) != 1.
Proof. by move=> nilG nsHG; apply: contraNneq => /TI_center_nil->. Qed.
Lemma center_nil_eq1 G : nilpotent G -> ('Z(G) == 1) = (G :==: 1).
Proof.
move=> nilG; apply/eqP/eqP=> [Z1 | ->]; last exact: center1.
by rewrite (TI_center_nil nilG) // (setIidPr (center_sub G)).
Qed.
Lemma cyclic_nilpotent_quo_der1_cyclic G :
nilpotent G -> cyclic (G / G^`(1)) -> cyclic G.
Proof.
move=> nG; rewrite (isog_cyclic (quotient1_isog G)).
have [-> // | ntG' cGG'] := (eqVneq G^`(1) 1)%g.
suffices: 'L_2(G) \subset G :&: 'L_3(G) by move/(eqfun_inP nG)=> <-.
rewrite subsetI lcn_sub /= -quotient_cents2 ?lcn_norm //.
apply: cyclic_factor_abelian (lcn_central 2 G) _.
by rewrite (isog_cyclic (third_isog _ _ _)) ?lcn_normal // lcn_subS.
Qed.
End QuotientNil.
Section Solvable.
Variable gT : finGroupType.
Implicit Types G H : {group gT}.
Lemma nilpotent_sol G : nilpotent G -> solvable G.
Proof.
move=> nilG; apply/forall_inP=> H /subsetIP[sHG sHH'].
by rewrite (forall_inP nilG) // subsetI sHG (subset_trans sHH') ?commgS.
Qed.
Lemma abelian_sol G : abelian G -> solvable G.
Proof. by move/abelian_nil/nilpotent_sol. Qed.
Lemma solvable1 : solvable [1 gT]. Proof. exact: abelian_sol (abelian1 gT). Qed.
Lemma solvableS G H : H \subset G -> solvable G -> solvable H.
Proof.
move=> sHG solG; apply/forall_inP=> K /subsetIP[sKH sKK'].
by rewrite (forall_inP solG) // subsetI (subset_trans sKH).
Qed.
Lemma sol_der1_proper G H :
solvable G -> H \subset G -> H :!=: 1 -> H^`(1) \proper H.
Proof.
move=> solG sHG ntH; rewrite properE comm_subG //; apply: implyP ntH.
by have:= forallP solG H; rewrite subsetI sHG implybNN.
Qed.
Lemma derivedP G : reflect (exists n, G^`(n) = 1) (solvable G).
Proof.
apply: (iffP idP) => [solG | [n solGn]]; last first.
apply/forall_inP=> H /subsetIP[sHG sHH'].
rewrite -subG1 -{}solGn; elim: n => // n IHn.
exact: subset_trans sHH' (commgSS _ _).
suffices IHn n: #|G^`(n)| <= (#|G|.-1 - n).+1.
by exists #|G|.-1; rewrite [G^`(_)]card_le1_trivg ?(leq_trans (IHn _)) ?subnn.
elim: n => [|n IHn]; first by rewrite subn0 prednK.
rewrite dergSn subnS -ltnS.
have [-> | ntGn] := eqVneq G^`(n) 1; first by rewrite commG1 cards1.
case: (_ - _) IHn => [|n']; first by rewrite leqNgt cardG_gt1 ntGn.
by apply: leq_trans (proper_card _); apply: sol_der1_proper (der_sub _ _) _.
Qed.
End Solvable.
Section MorphSol.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Variable G : {group gT}.
Lemma morphim_sol : solvable G -> solvable (f @* G).
Proof.
move/(solvableS (subsetIr D G)); case/derivedP=> n Gn1; apply/derivedP.
by exists n; rewrite /= -morphimIdom -morphim_der ?subsetIl // Gn1 morphim1.
Qed.
Lemma injm_sol : 'injm f -> G \subset D -> solvable (f @* G) = solvable G.
Proof.
move=> injf sGD; apply/idP/idP; last exact: morphim_sol.
case/derivedP=> n Gn1; apply/derivedP; exists n; apply/trivgP.
by rewrite -(injmSK injf) ?gFsub_trans ?morphim_der // Gn1 morphim1.
Qed.
End MorphSol.
Section QuotientSol.
Variables gT rT : finGroupType.
Implicit Types G H K : {group gT}.
Lemma isog_sol G (L : {group rT}) : G \isog L -> solvable G = solvable L.
Proof. by case/isogP=> f injf <-; rewrite injm_sol. Qed.
Lemma quotient_sol G H : solvable G -> solvable (G / H).
Proof. exact: morphim_sol. Qed.
Lemma series_sol G H : H <| G -> solvable G = solvable H && solvable (G / H).
Proof.
case/andP=> sHG nHG; apply/idP/andP=> [solG | [solH solGH]].
by rewrite quotient_sol // (solvableS sHG).
apply/forall_inP=> K /subsetIP[sKG sK'K].
suffices sKH: K \subset H by rewrite (forall_inP solH) // subsetI sKH.
have nHK := subset_trans sKG nHG.
rewrite -quotient_sub1 // subG1 (forall_inP solGH) //.
by rewrite subsetI -morphimR ?morphimS.
Qed.
Lemma metacyclic_sol G : metacyclic G -> solvable G.
Proof.
case/metacyclicP=> K [cycK nsKG cycGq].
by rewrite (series_sol nsKG) !abelian_sol ?cyclic_abelian.
Qed.
End QuotientSol.
Section setXn.
Import finfun.
Lemma setXn_sol n (gT : 'I_n -> finGroupType) (G : forall i, {group gT i}) :
(forall i, solvable (G i)) -> solvable (setXn G).
Proof.
elim: n => [|n IHn] in gT G * => solG; first by rewrite groupX0 solvable1.
pose gT' (i : 'I_n) := gT (lift ord0 i).
pose prod_group_gT := [the finGroupType of {dffun forall i, gT i}].
pose prod_group_gT' := [the finGroupType of {dffun forall i, gT' i}].
pose f (x : prod_group_gT) : prod_group_gT' := [ffun i => x (lift ord0 i)].
have fm : morphic (setXn G) f.
apply/'forall_implyP => -[a b]; rewrite !inE/=.
by move=> /andP[/forallP aG /forallP bG]; apply/eqP/ffunP => i; rewrite !ffunE.
rewrite (@series_sol _ [group of setXn G] ('ker (morphm fm))) ?ker_normal//=.
rewrite (isog_sol (first_isog _))/=.
have -> : (morphm fm @* setXn G)%g = setXn (fun i => G (lift ord0 i)).
apply/setP => v; rewrite !inE morphimEdom; apply/idP/forallP => /=.
move=> /imsetP[/=x]; rewrite inE => /forallP/= xG ->.
by move=> i; rewrite morphmE ffunE xG.
move=> vG; apply/imsetP.
pose w := [ffun i : 'I_n.+1 =>
match unliftP ord0 i return (gT i) : Type with
| UnliftSome j i_eq => ecast i (gT i) (esym i_eq) (v j)
| UnliftNone i0 => 1%g
end].
have wl i : w (lift ord0 i) = v i.
rewrite ffunE; case: unliftP => //= j elij.
have eij : i = j by case: elij; apply/val_inj.
by rewrite [elij](eq_irrelevance _ (congr1 _ eij)); case: _ / eij.
have w0 : w ord0 = 1%g by rewrite ffunE; case: unliftP.
exists w; last by apply/ffunP => i; rewrite morphmE ffunE/= wl.
apply/setXnP => i.
case: (unliftP ord0 i) => [j|]->; rewrite ?wl ?w0 ?vG//.
rewrite IHn ?andbT//; last by move=> i; apply: solG.
pose k (x : gT ord0) : prod_group_gT :=
[ffun i : 'I_n.+1 =>
match (ord0 =P i) return (gT i) : Type with
| ReflectT P => ecast i (gT i) P x
| _ => 1%g
end].
have km : morphic (G ord0) k.
apply/'forall_implyP => -[a b]; rewrite !inE/= => /andP[aG bG].
apply/eqP/ffunP => i; rewrite !ffunE; case: eqP => //; rewrite ?mulg1//.
by case: _ /.
suff -> : ('ker (morphm fm) = morphm km @* G ord0)%g by rewrite morphim_sol.
apply/setP => x; rewrite morphimEdom; apply/idP/imsetP => [xker|].
exists (x ord0).
by have := dom_ker xker; rewrite inE => /forallP/(_ ord0).
rewrite /= morphmE; apply/ffunP => i; rewrite ffunE; case: eqP => //=.
by case: _ /.
move/eqP; rewrite eq_sym; have /mker/= := xker; rewrite morphmE => /ffunP.
by case: (@unliftP _ ord0 i) => [j|] ->//= /(_ j); rewrite !ffunE.
move=> [x0 xG0 -> /=]; rewrite morphmE; apply/kerP; rewrite ?inE.
by apply/forallP => i; rewrite ffunE; case: eqP => //=; case: _ /.
by rewrite /= morphmE; apply/ffunP => i; rewrite !ffunE; case: eqP.
Qed.
End setXn.
|
Imo2006Q5.lean
|
/-
Copyright (c) 2022 Violeta HernΓ‘ndez Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta HernΓ‘ndez Palacios
-/
import Mathlib.Algebra.Polynomial.Roots
import Mathlib.Dynamics.PeriodicPts.Lemmas
/-!
# IMO 2006 Q5
Let $P(x)$ be a polynomial of degree $n>1$ with integer coefficients, and let $k$ be a positive
integer. Consider the polynomial $Q(x) = P(P(\ldots P(P(x))\ldots))$, where $P$ occurs $k$ times.
Prove that there are at most $n$ integers $t$ such that $Q(t)=t$.
## Sketch of solution
The following solution is adapted from
https://artofproblemsolving.com/wiki/index.php/2006_IMO_Problems/Problem_5.
Let $P^k$ denote the polynomial $P$ composed with itself $k$ times. We rely on a key observation: if
$P^k(t)=t$, then $P(P(t))=t$. We prove this by building the cyclic list
$(P(t)-t,P^2(t)-P(t),\ldots)$, and showing that each entry divides the next, which by transitivity
implies they all divide each other, and thus have the same absolute value.
If the entries in this list are all pairwise equal, then we can show inductively that for positive
$n$, $P^n(t)-t$ must always have the same sign as $P(t)-t$. Substituting $n=k$ gives us $P(t)=t$ and
in particular $P(P(t))=t$.
Otherwise, there must be two consecutive entries that are opposites of one another. This means
$P^{n+2}(t)-P^{n+1}(t)=P^n(t)-P^{n+1}(t)$, which implies $P^{n+2}(t)=P^n(t)$ and $P(P(t))=t$.
With this lemma, we can reduce the problem to the case $k=2$. If every root of $P(P(t))-t$ is also a
root of $P(t)-t$, then we're done. Otherwise, there exist $a$ and $b$ with $a\ne b$ and $P(a)=b$,
$P(b)=a$. For any root $t$ of $P(P(t))-t$, defining $u=P(t)$, we easily verify $a-t\mid b-u$,
$b-u\mid a-t$, $a-u\mid b-t$, $b-t\mid a-u$, which imply $|a-t|=|b-u|$ and $|a-u|=|b-t|$. By casing
on these equalities, we deduce $a+b=t+u$. This means that every root of $P(P(t))-t$ is a root of
$P(t)+t-a-b$, and we're again done.
-/
open Function Polynomial
namespace Imo2006Q5
/-- If every entry in a cyclic list of integers divides the next, then they all have the same
absolute value. -/
theorem Int.natAbs_eq_of_chain_dvd {l : Cycle β€} {x y : β€} (hl : l.Chain (Β· β£ Β·)) (hx : x β l)
(hy : y β l) : x.natAbs = y.natAbs := by
rw [Cycle.chain_iff_pairwise] at hl
exact Int.natAbs_eq_of_dvd_dvd (hl x hx y hy) (hl y hy x hx)
theorem Int.add_eq_add_of_natAbs_eq_of_natAbs_eq {a b c d : β€} (hne : a β b)
(hβ : (c - a).natAbs = (d - b).natAbs) (hβ : (c - b).natAbs = (d - a).natAbs) :
a + b = c + d := by
rcases Int.natAbs_eq_natAbs_iff.1 hβ with hβ | hβ
Β· rcases Int.natAbs_eq_natAbs_iff.1 hβ with hβ | hβ
Β· exact (hne <| by linarith).elim
Β· linarith
Β· linarith
/-- The main lemma in the proof: if $P^k(t)=t$, then $P(P(t))=t$. -/
theorem Polynomial.isPeriodicPt_eval_two {P : Polynomial β€} {t : β€}
(ht : t β periodicPts fun x => P.eval x) : IsPeriodicPt (fun x => P.eval x) 2 t := by
-- The cycle [P(t) - t, P(P(t)) - P(t), ...]
let C : Cycle β€ := (periodicOrbit (fun x => P.eval x) t).map fun x => P.eval x - x
have HC : β {n : β}, (fun x => P.eval x)^[n + 1] t - (fun x => P.eval x)^[n] t β C := by
intro n
rw [Cycle.mem_map, Function.iterate_succ_apply']
exact β¨_, iterate_mem_periodicOrbit ht n, rflβ©
-- Elements in C are all divisible by one another.
have Hdvd : C.Chain (Β· β£ Β·) := by
rw [Cycle.chain_map, periodicOrbit_chain' _ ht]
intro n
convert sub_dvd_eval_sub ((fun x => P.eval x)^[n + 1] t) ((fun x => P.eval x)^[n] t) P <;>
rw [Function.iterate_succ_apply']
-- Any two entries in C have the same absolute value.
have Habs :
β m n : β,
((fun x => P.eval x)^[m + 1] t - (fun x => P.eval x)^[m] t).natAbs =
((fun x => P.eval x)^[n + 1] t - (fun x => P.eval x)^[n] t).natAbs :=
fun m n => Int.natAbs_eq_of_chain_dvd Hdvd HC HC
-- We case on whether the elements on C are pairwise equal.
by_cases HC' : C.Chain (Β· = Β·)
Β· -- Any two entries in C are equal.
have Heq :
β m n : β,
(fun x => P.eval x)^[m + 1] t - (fun x => P.eval x)^[m] t =
(fun x => P.eval x)^[n + 1] t - (fun x => P.eval x)^[n] t :=
fun m n => Cycle.chain_iff_pairwise.1 HC' _ HC _ HC
-- The sign of P^n(t) - t is the same as P(t) - t for positive n. Proven by induction on n.
have IH (n : β) : ((fun x => P.eval x)^[n + 1] t - t).sign = (P.eval t - t).sign := by
induction n with
| zero => rfl
| succ n IH =>
apply Eq.trans _ (Int.sign_add_eq_of_sign_eq IH)
have H := Heq n.succ 0
dsimp at H β’
rw [β H, sub_add_sub_cancel']
-- This implies that the sign of P(t) - t is the same as the sign of P^k(t) - t, which is 0.
-- Hence P(t) = t and P(P(t)) = P(t).
rcases ht with β¨_ | k, hk, hk'β©
Β· exact (irrefl 0 hk).elim
Β· have H := IH k
rw [hk'.isFixedPt.eq, sub_self, Int.sign_zero, eq_comm, Int.sign_eq_zero_iff_zero,
sub_eq_zero] at H
simp [IsPeriodicPt, IsFixedPt, H]
Β· -- We take two nonequal consecutive entries.
rw [Cycle.chain_map, periodicOrbit_chain' _ ht] at HC'
push_neg at HC'
obtain β¨n, hnβ© := HC'
-- They must have opposite sign, so that P^{k + 1}(t) - P^k(t) = P^{k + 2}(t) - P^{k + 1}(t).
rcases Int.natAbs_eq_natAbs_iff.1 (Habs n n.succ) with hn' | hn'
Β· apply (hn _).elim
convert hn' <;> simp only [Function.iterate_succ_apply']
-- We deduce P^{k + 2}(t) = P^k(t) and hence P(P(t)) = t.
Β· rw [neg_sub, sub_right_inj] at hn'
simp only [Function.iterate_succ_apply'] at hn'
exact isPeriodicPt_of_mem_periodicPts_of_isPeriodicPt_iterate ht hn'.symm
theorem Polynomial.iterate_comp_sub_X_ne {P : Polynomial β€} (hP : 1 < P.natDegree) {k : β}
(hk : 0 < k) : P.comp^[k] X - X β 0 := by
rw [sub_ne_zero]
apply_fun natDegree
simpa using (one_lt_powβ hP hk.ne').ne'
/-- We solve the problem for the specific case k = 2 first. -/
theorem imo2006_q5' {P : Polynomial β€} (hP : 1 < P.natDegree) :
(P.comp P - X).roots.toFinset.card β€ P.natDegree := by
-- Auxiliary lemmas on degrees.
have hPX : (P - X).natDegree = P.natDegree := by
rw [natDegree_sub_eq_left_of_natDegree_lt]
simpa using hP
have hPX' : P - X β 0 := by
intro h
rw [h, natDegree_zero] at hPX
rw [β hPX] at hP
exact (zero_le_one.not_gt hP).elim
-- If every root of P(P(t)) - t is also a root of P(t) - t, then we're done.
by_cases H : (P.comp P - X).roots.toFinset β (P - X).roots.toFinset
Β· exact (Finset.card_le_card H).trans
((Multiset.toFinset_card_le _).trans ((card_roots' _).trans_eq hPX))
-- Otherwise, take a, b with P(a) = b, P(b) = a, a β b.
Β· rcases Finset.not_subset.1 H with β¨a, ha, habβ©
replace ha := isRoot_of_mem_roots (Multiset.mem_toFinset.1 ha)
rw [IsRoot.def, eval_sub, eval_comp, eval_X, sub_eq_zero] at ha
rw [Multiset.mem_toFinset, mem_roots hPX', IsRoot.def, eval_sub, eval_X, sub_eq_zero]
at hab
set b := P.eval a
-- More auxiliary lemmas on degrees.
have hPab : (P + (X : β€[X]) - a - b).natDegree = P.natDegree := by
rw [sub_sub, β Int.cast_add]
have hβ : (P + X).natDegree = P.natDegree := by
rw [natDegree_add_eq_left_of_natDegree_lt]
simpa using hP
rwa [natDegree_sub_eq_left_of_natDegree_lt]
rw [hβ, natDegree_intCast]
exact zero_lt_one.trans hP
have hPab' : P + (X : β€[X]) - a - b β 0 := by
intro h
rw [h, natDegree_zero] at hPab
rw [β hPab] at hP
exact (zero_le_one.not_gt hP).elim
-- We claim that every root of P(P(t)) - t is a root of P(t) + t - a - b. This allows us to
-- conclude the problem.
suffices H' : (P.comp P - X).roots.toFinset β (P + (X : β€[X]) - a - b).roots.toFinset from
(Finset.card_le_card H').trans
((Multiset.toFinset_card_le _).trans <| (card_roots' _).trans_eq hPab)
-- Let t be a root of P(P(t)) - t, define u = P(t).
intro t ht
replace ht := isRoot_of_mem_roots (Multiset.mem_toFinset.1 ht)
rw [IsRoot.def, eval_sub, eval_comp, eval_X, sub_eq_zero] at ht
simp only [mem_roots hPab', sub_eq_iff_eq_add, Multiset.mem_toFinset, IsRoot.def,
eval_sub, eval_add, eval_X, eval_intCast, Int.cast_id, zero_add]
-- An auxiliary lemma proved earlier implies we only need to show |t - a| = |u - b| and
-- |t - b| = |u - a|. We prove this by establishing that each side of either equation divides
-- the other.
apply (Int.add_eq_add_of_natAbs_eq_of_natAbs_eq hab _ _).symm <;>
apply Int.natAbs_eq_of_dvd_dvd <;> set u := P.eval t
Β· rw [β ha, β ht]; apply sub_dvd_eval_sub
Β· apply sub_dvd_eval_sub
Β· rw [β ht]; apply sub_dvd_eval_sub
Β· rw [β ha]; apply sub_dvd_eval_sub
end Imo2006Q5
open Imo2006Q5
/-- The general problem follows easily from the k = 2 case. -/
theorem imo2006_q5 {P : Polynomial β€} (hP : 1 < P.natDegree) {k : β} (hk : 0 < k) :
(P.comp^[k] X - X).roots.toFinset.card β€ P.natDegree := by
refine (Finset.card_le_card fun t ht => ?_).trans (imo2006_q5' hP)
have hP' : P.comp P - X β 0 := by
simpa [Nat.iterate] using Polynomial.iterate_comp_sub_X_ne hP zero_lt_two
replace ht := isRoot_of_mem_roots (Multiset.mem_toFinset.1 ht)
rw [IsRoot.def, eval_sub, iterate_comp_eval, eval_X, sub_eq_zero] at ht
rw [Multiset.mem_toFinset, mem_roots hP', IsRoot.def, eval_sub, eval_comp, eval_X,
sub_eq_zero]
exact Polynomial.isPeriodicPt_eval_two β¨k, hk, htβ©
|
all.v
|
From mathcomp Require Export all_boot.
From mathcomp Require Export all_order.
From mathcomp Require Export all_fingroup.
From mathcomp Require Export all_algebra.
From mathcomp Require Export all_solvable.
From mathcomp Require Export all_field.
From mathcomp Require Export all_character.
|
SuperFactorial.lean
|
/-
Copyright (c) 2023 Moritz Firsching. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moritz Firsching
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Algebra.Polynomial.Monic
import Mathlib.Data.Nat.Factorial.Basic
import Mathlib.LinearAlgebra.Vandermonde
import Mathlib.RingTheory.Polynomial.Pochhammer
/-!
# Superfactorial
This file defines the [superfactorial](https://en.wikipedia.org/wiki/Superfactorial)
`sf n = 1! * 2! * 3! * ... * n!`.
## Main declarations
* `Nat.superFactorial`: The superfactorial, denoted by `sf`.
-/
namespace Nat
/-- `Nat.superFactorial n` is the superfactorial of `n`. -/
def superFactorial : β β β
| 0 => 1
| succ n => factorial n.succ * superFactorial n
/-- `sf` notation for superfactorial -/
scoped notation "sf" n:60 => Nat.superFactorial n
section SuperFactorial
@[simp]
theorem superFactorial_zero : sf 0 = 1 :=
rfl
theorem superFactorial_succ (n : β) : (sf n.succ) = (n + 1)! * sf n :=
rfl
@[simp]
theorem superFactorial_one : sf 1 = 1 :=
rfl
@[simp]
theorem superFactorial_two : sf 2 = 2 :=
rfl
open Finset
@[simp]
theorem prod_Icc_factorial : β n : β, β x β Icc 1 n, x ! = sf n
| 0 => rfl
| n + 1 => by
rw [β Ico_add_one_right_eq_Icc 1, prod_Ico_succ_top le_add_self, Nat.factorial_succ,
Ico_add_one_right_eq_Icc 1 n, prod_Icc_factorial n, superFactorial, factorial, mul_comm]
@[simp]
theorem prod_range_factorial_succ (n : β) : β x β range n, (x + 1)! = sf n :=
(prod_Icc_factorial n) βΈ range_eq_Ico βΈ Finset.prod_Ico_add' _ _ _ _
@[simp]
theorem prod_range_succ_factorial : β n : β, β x β range (n + 1), x ! = sf n
| 0 => rfl
| n + 1 => by
rw [prod_range_succ, prod_range_succ_factorial n, mul_comm, superFactorial]
variable {R : Type*} [CommRing R]
theorem det_vandermonde_id_eq_superFactorial (n : β) :
(Matrix.vandermonde (fun (i : Fin (n + 1)) β¦ (i : R))).det = Nat.superFactorial n := by
induction' n with n hn
Β· simp
Β· rw [Nat.superFactorial, Matrix.det_vandermonde, Fin.prod_univ_succAbove _ 0]
push_cast
congr
Β· simp only [Fin.val_zero, Nat.cast_zero, sub_zero]
norm_cast
simp [Fin.prod_univ_eq_prod_range (fun i β¦ (βi + 1)) (n + 1)]
Β· rw [Matrix.det_vandermonde] at hn
simp [hn]
theorem superFactorial_two_mul : β n : β,
sf (2 * n) = (β i β range n, (2 * i + 1) !) ^ 2 * 2 ^ n * n !
| 0 => rfl
| (n + 1) => by
simp only [prod_range_succ, mul_pow, mul_add, mul_one, superFactorial_succ,
superFactorial_two_mul n, factorial_succ]
ring
theorem superFactorial_four_mul (n : β) :
sf (4 * n) = ((β i β range (2 * n), (2 * i + 1) !) * 2 ^ n) ^ 2 * (2 * n) ! :=
calc
sf (4 * n) = (β i β range (2 * n), (2 * i + 1) !) ^ 2 * 2 ^ (2 * n) * (2 * n) ! := by
rw [β superFactorial_two_mul, β mul_assoc, Nat.mul_two]
_ = ((β i β range (2 * n), (2 * i + 1) !) * 2 ^ n) ^ 2 * (2 * n) ! := by
rw [pow_mul', mul_pow]
private theorem matrixOf_eval_descPochhammer_eq_mul_matrixOf_choose {n : β} (v : Fin n β β) :
(Matrix.of (fun (i j : Fin n) => (descPochhammer β€ j).eval (v i : β€))).det =
(β i : Fin n, Nat.factorial i) *
(Matrix.of (fun (i j : Fin n) => (Nat.choose (v i) (j : β) : β€))).det := by
convert Matrix.det_mul_row (fun (i : Fin n) => ((Nat.factorial (i : β)) : β€)) _
Β· rw [Matrix.of_apply, descPochhammer_eval_eq_descFactorial β€ _ _]
congr
exact Nat.descFactorial_eq_factorial_mul_choose _ _
Β· rw [Nat.cast_prod]
theorem superFactorial_dvd_vandermonde_det {n : β} (v : Fin (n + 1) β β€) :
β(Nat.superFactorial n) β£ (Matrix.vandermonde v).det := by
let m := inf' univ β¨0, mem_univ _β© v
let w' := fun i β¦ (v i - m).toNat
have hw' : β i, (w' i : β€) = v i - m := fun i β¦ Int.toNat_sub_of_le (inf'_le _ (mem_univ _))
have h := Matrix.det_eval_matrixOfPolynomials_eq_det_vandermonde (fun i β¦ β(w' i))
(fun i => descPochhammer β€ i)
(fun i => descPochhammer_natDegree β€ i)
(fun i => monic_descPochhammer β€ i)
conv_lhs at h => simp only [hw', Matrix.det_vandermonde_sub]
use (Matrix.of (fun (i j : Fin (n + 1)) => (Nat.choose (w' i) (j : β) : β€))).det
simp [h, matrixOf_eval_descPochhammer_eq_mul_matrixOf_choose w', Fin.prod_univ_eq_prod_range]
end SuperFactorial
end Nat
|
Finmap.lean
|
/-
Copyright (c) 2018 Sean Leather. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sean Leather, Mario Carneiro
-/
import Mathlib.Data.List.AList
import Mathlib.Data.Finset.Sigma
import Mathlib.Data.Part
/-!
# Finite maps over `Multiset`
-/
universe u v w
open List
variable {Ξ± : Type u} {Ξ² : Ξ± β Type v}
/-! ### Multisets of sigma types -/
namespace Multiset
/-- Multiset of keys of an association multiset. -/
def keys (s : Multiset (Sigma Ξ²)) : Multiset Ξ± :=
s.map Sigma.fst
@[simp]
theorem coe_keys {l : List (Sigma Ξ²)} : keys (l : Multiset (Sigma Ξ²)) = (l.keys : Multiset Ξ±) :=
rfl
@[simp]
theorem keys_zero : keys (0 : Multiset (Sigma Ξ²)) = 0 := rfl
@[simp]
theorem keys_cons {a : Ξ±} {b : Ξ² a} {s : Multiset (Sigma Ξ²)} :
keys (β¨a, bβ© ::β s) = a ::β keys s := by
simp [keys]
@[simp]
theorem keys_singleton {a : Ξ±} {b : Ξ² a} : keys ({β¨a, bβ©} : Multiset (Sigma Ξ²)) = {a} := rfl
/-- `NodupKeys s` means that `s` has no duplicate keys. -/
def NodupKeys (s : Multiset (Sigma Ξ²)) : Prop :=
Quot.liftOn s List.NodupKeys fun _ _ p => propext <| perm_nodupKeys p
@[simp]
theorem coe_nodupKeys {l : List (Sigma Ξ²)} : @NodupKeys Ξ± Ξ² l β l.NodupKeys :=
Iff.rfl
lemma nodup_keys {m : Multiset (Ξ£ a, Ξ² a)} : m.keys.Nodup β m.NodupKeys := by
rcases m with β¨lβ©; rfl
alias β¨_, NodupKeys.nodup_keysβ© := nodup_keys
protected lemma NodupKeys.nodup {m : Multiset (Ξ£ a, Ξ² a)} (h : m.NodupKeys) : m.Nodup :=
h.nodup_keys.of_map _
end Multiset
/-! ### Finmap -/
/-- `Finmap Ξ²` is the type of finite maps over a multiset. It is effectively
a quotient of `AList Ξ²` by permutation of the underlying list. -/
structure Finmap (Ξ² : Ξ± β Type v) : Type max u v where
/-- The underlying `Multiset` of a `Finmap` -/
entries : Multiset (Sigma Ξ²)
/-- There are no duplicate keys in `entries` -/
nodupKeys : entries.NodupKeys
/-- The quotient map from `AList` to `Finmap`. -/
def AList.toFinmap (s : AList Ξ²) : Finmap Ξ² :=
β¨s.entries, s.nodupKeysβ©
local notation:arg "β¦" a "β§" => AList.toFinmap a
theorem AList.toFinmap_eq {sβ sβ : AList Ξ²} :
toFinmap sβ = toFinmap sβ β sβ.entries ~ sβ.entries := by
cases sβ
cases sβ
simp [AList.toFinmap]
@[simp]
theorem AList.toFinmap_entries (s : AList Ξ²) : β¦sβ§.entries = s.entries :=
rfl
/-- Given `l : List (Sigma Ξ²)`, create a term of type `Finmap Ξ²` by removing
entries with duplicate keys. -/
def List.toFinmap [DecidableEq Ξ±] (s : List (Sigma Ξ²)) : Finmap Ξ² :=
s.toAList.toFinmap
namespace Finmap
open AList
lemma nodup_entries (f : Finmap Ξ²) : f.entries.Nodup := f.nodupKeys.nodup
/-! ### Lifting from AList -/
/-- Lift a permutation-respecting function on `AList` to `Finmap`. -/
def liftOn {Ξ³} (s : Finmap Ξ²) (f : AList Ξ² β Ξ³)
(H : β a b : AList Ξ², a.entries ~ b.entries β f a = f b) : Ξ³ := by
refine
(Quotient.liftOn s.entries
(fun (l : List (Sigma Ξ²)) => (β¨_, fun nd => f β¨l, ndβ©β© : Part Ξ³))
(fun lβ lβ p => Part.ext' (perm_nodupKeys p) ?_) : Part Ξ³).get ?_
Β· exact fun h1 h2 => H _ _ p
Β· have := s.nodupKeys
revert this
rcases s.entries with β¨lβ©
exact id
@[simp]
theorem liftOn_toFinmap {Ξ³} (s : AList Ξ²) (f : AList Ξ² β Ξ³) (H) : liftOn β¦sβ§ f H = f s := by
cases s
rfl
/-- Lift a permutation-respecting function on 2 `AList`s to 2 `Finmap`s. -/
def liftOnβ {Ξ³} (sβ sβ : Finmap Ξ²) (f : AList Ξ² β AList Ξ² β Ξ³)
(H : β aβ bβ aβ bβ : AList Ξ²,
aβ.entries ~ aβ.entries β bβ.entries ~ bβ.entries β f aβ bβ = f aβ bβ) : Ξ³ :=
liftOn sβ (fun lβ => liftOn sβ (f lβ) fun _ _ p => H _ _ _ _ (Perm.refl _) p) fun aβ aβ p => by
have H' : f aβ = f aβ := funext fun _ => H _ _ _ _ p (Perm.refl _)
simp only [H']
@[simp]
theorem liftOnβ_toFinmap {Ξ³} (sβ sβ : AList Ξ²) (f : AList Ξ² β AList Ξ² β Ξ³) (H) :
liftOnβ β¦sββ§ β¦sββ§ f H = f sβ sβ := by
cases sβ; cases sβ; rfl
/-! ### Induction -/
@[elab_as_elim]
theorem induction_on {C : Finmap Ξ² β Prop} (s : Finmap Ξ²) (H : β a : AList Ξ², C β¦aβ§) : C s := by
rcases s with β¨β¨aβ©, hβ©; exact H β¨a, hβ©
@[elab_as_elim]
theorem induction_onβ {C : Finmap Ξ² β Finmap Ξ² β Prop} (sβ sβ : Finmap Ξ²)
(H : β aβ aβ : AList Ξ², C β¦aββ§ β¦aββ§) : C sβ sβ :=
induction_on sβ fun lβ => induction_on sβ fun lβ => H lβ lβ
@[elab_as_elim]
theorem induction_onβ {C : Finmap Ξ² β Finmap Ξ² β Finmap Ξ² β Prop} (sβ sβ sβ : Finmap Ξ²)
(H : β aβ aβ aβ : AList Ξ², C β¦aββ§ β¦aββ§ β¦aββ§) : C sβ sβ sβ :=
induction_onβ sβ sβ fun lβ lβ => induction_on sβ fun lβ => H lβ lβ lβ
/-! ### extensionality -/
@[ext]
theorem ext : β {s t : Finmap Ξ²}, s.entries = t.entries β s = t
| β¨lβ, hββ©, β¨lβ, _β©, H => by congr
@[simp]
theorem ext_iff' {s t : Finmap Ξ²} : s.entries = t.entries β s = t :=
Finmap.ext_iff.symm
/-! ### mem -/
/-- The predicate `a β s` means that `s` has a value associated to the key `a`. -/
instance : Membership Ξ± (Finmap Ξ²) :=
β¨fun s a => a β s.entries.keysβ©
theorem mem_def {a : Ξ±} {s : Finmap Ξ²} : a β s β a β s.entries.keys :=
Iff.rfl
@[simp]
theorem mem_toFinmap {a : Ξ±} {s : AList Ξ²} : a β toFinmap s β a β s :=
Iff.rfl
/-! ### keys -/
/-- The set of keys of a finite map. -/
def keys (s : Finmap Ξ²) : Finset Ξ± :=
β¨s.entries.keys, s.nodupKeys.nodup_keysβ©
@[simp]
theorem keys_val (s : AList Ξ²) : (keys β¦sβ§).val = s.keys :=
rfl
@[simp]
theorem keys_ext {sβ sβ : AList Ξ²} : keys β¦sββ§ = keys β¦sββ§ β sβ.keys ~ sβ.keys := by
simp [keys, AList.keys]
theorem mem_keys {a : Ξ±} {s : Finmap Ξ²} : a β s.keys β a β s :=
induction_on s fun _ => AList.mem_keys
/-! ### empty -/
/-- The empty map. -/
instance : EmptyCollection (Finmap Ξ²) :=
β¨β¨0, nodupKeys_nilβ©β©
instance : Inhabited (Finmap Ξ²) :=
β¨β
β©
@[simp]
theorem empty_toFinmap : (β¦β
β§ : Finmap Ξ²) = β
:=
rfl
@[simp]
theorem toFinmap_nil [DecidableEq Ξ±] : ([].toFinmap : Finmap Ξ²) = β
:=
rfl
theorem notMem_empty {a : Ξ±} : a β (β
: Finmap Ξ²) :=
Multiset.notMem_zero a
@[deprecated (since := "2025-05-23")] alias not_mem_empty := notMem_empty
@[simp]
theorem keys_empty : (β
: Finmap Ξ²).keys = β
:=
rfl
/-! ### singleton -/
/-- The singleton map. -/
def singleton (a : Ξ±) (b : Ξ² a) : Finmap Ξ² :=
β¦AList.singleton a bβ§
@[simp]
theorem keys_singleton (a : Ξ±) (b : Ξ² a) : (singleton a b).keys = {a} :=
rfl
@[simp]
theorem mem_singleton (x y : Ξ±) (b : Ξ² y) : x β singleton y b β x = y := by
simp [singleton, mem_def]
section
variable [DecidableEq Ξ±]
instance decidableEq [β a, DecidableEq (Ξ² a)] : DecidableEq (Finmap Ξ²)
| _, _ => decidable_of_iff _ Finmap.ext_iff.symm
/-! ### lookup -/
/-- Look up the value associated to a key in a map. -/
def lookup (a : Ξ±) (s : Finmap Ξ²) : Option (Ξ² a) :=
liftOn s (AList.lookup a) fun _ _ => perm_lookup
@[simp]
theorem lookup_toFinmap (a : Ξ±) (s : AList Ξ²) : lookup a β¦sβ§ = s.lookup a :=
rfl
@[simp]
theorem dlookup_list_toFinmap (a : Ξ±) (s : List (Sigma Ξ²)) : lookup a s.toFinmap = s.dlookup a := by
rw [List.toFinmap, lookup_toFinmap, lookup_to_alist]
@[simp]
theorem lookup_empty (a) : lookup a (β
: Finmap Ξ²) = none :=
rfl
theorem lookup_isSome {a : Ξ±} {s : Finmap Ξ²} : (s.lookup a).isSome β a β s :=
induction_on s fun _ => AList.lookup_isSome
theorem lookup_eq_none {a} {s : Finmap Ξ²} : lookup a s = none β a β s :=
induction_on s fun _ => AList.lookup_eq_none
lemma mem_lookup_iff {s : Finmap Ξ²} {a : Ξ±} {b : Ξ² a} :
b β s.lookup a β Sigma.mk a b β s.entries := by
rcases s with β¨β¨lβ©, hlβ©; exact List.mem_dlookup_iff hl
lemma lookup_eq_some_iff {s : Finmap Ξ²} {a : Ξ±} {b : Ξ² a} :
s.lookup a = b β Sigma.mk a b β s.entries := mem_lookup_iff
@[simp] lemma sigma_keys_lookup (s : Finmap Ξ²) :
s.keys.sigma (fun i => (s.lookup i).toFinset) = β¨s.entries, s.nodup_entriesβ© := by
ext x
have : x β s.entries β x.1 β s.keys := Multiset.mem_map_of_mem _
simpa [lookup_eq_some_iff]
@[simp]
theorem lookup_singleton_eq {a : Ξ±} {b : Ξ² a} : (singleton a b).lookup a = some b := by
rw [singleton, lookup_toFinmap, AList.singleton, AList.lookup, dlookup_cons_eq]
instance (a : Ξ±) (s : Finmap Ξ²) : Decidable (a β s) :=
decidable_of_iff _ lookup_isSome
theorem mem_iff {a : Ξ±} {s : Finmap Ξ²} : a β s β β b, s.lookup a = some b :=
induction_on s fun s =>
Iff.trans List.mem_keys <| exists_congr fun _ => (mem_dlookup_iff s.nodupKeys).symm
theorem mem_of_lookup_eq_some {a : Ξ±} {b : Ξ² a} {s : Finmap Ξ²} (h : s.lookup a = some b) : a β s :=
mem_iff.mpr β¨_, hβ©
theorem ext_lookup {sβ sβ : Finmap Ξ²} : (β x, sβ.lookup x = sβ.lookup x) β sβ = sβ :=
induction_onβ sβ sβ fun sβ sβ h => by
simp only [AList.lookup, lookup_toFinmap] at h
rw [AList.toFinmap_eq]
apply lookup_ext sβ.nodupKeys sβ.nodupKeys
intro x y
rw [h]
/-- An equivalence between `Finmap Ξ²` and pairs `(keys : Finset Ξ±, lookup : β a, Option (Ξ² a))` such
that `(lookup a).isSome β a β keys`. -/
@[simps apply_coe_fst apply_coe_snd]
def keysLookupEquiv :
Finmap Ξ² β { f : Finset Ξ± Γ (β a, Option (Ξ² a)) // β i, (f.2 i).isSome β i β f.1 } where
toFun s := β¨(s.keys, fun i => s.lookup i), fun _ => lookup_isSomeβ©
invFun f := mk (f.1.1.sigma fun i => (f.1.2 i).toFinset).val <| by
refine Multiset.nodup_keys.1 ((Finset.nodup _).map_on ?_)
simp only [Finset.mem_val, Finset.mem_sigma, Option.mem_toFinset, Option.mem_def]
rintro β¨i, xβ© β¨_, hxβ© β¨j, yβ© β¨_, hyβ© (rfl : i = j)
simpa using hx.symm.trans hy
left_inv f := ext <| by simp
right_inv := fun β¨(s, f), hfβ© => by
dsimp only at hf
ext
Β· simp [keys, Multiset.keys, β hf, Option.isSome_iff_exists]
Β· simp +contextual [lookup_eq_some_iff, β hf]
@[simp] lemma keysLookupEquiv_symm_apply_keys :
β f : {f : Finset Ξ± Γ (β a, Option (Ξ² a)) // β i, (f.2 i).isSome β i β f.1},
(keysLookupEquiv.symm f).keys = f.1.1 :=
keysLookupEquiv.surjective.forall.2 fun _ => by
simp only [Equiv.symm_apply_apply, keysLookupEquiv_apply_coe_fst]
@[simp] lemma keysLookupEquiv_symm_apply_lookup :
β (f : {f : Finset Ξ± Γ (β a, Option (Ξ² a)) // β i, (f.2 i).isSome β i β f.1}) a,
(keysLookupEquiv.symm f).lookup a = f.1.2 a :=
keysLookupEquiv.surjective.forall.2 fun _ _ => by
simp only [Equiv.symm_apply_apply, keysLookupEquiv_apply_coe_snd]
/-! ### replace -/
/-- Replace a key with a given value in a finite map.
If the key is not present it does nothing. -/
def replace (a : Ξ±) (b : Ξ² a) (s : Finmap Ξ²) : Finmap Ξ² :=
(liftOn s fun t => AList.toFinmap (AList.replace a b t))
fun _ _ p => toFinmap_eq.2 <| perm_replace p
@[simp]
theorem replace_toFinmap (a : Ξ±) (b : Ξ² a) (s : AList Ξ²) :
replace a b β¦sβ§ = (β¦s.replace a bβ§ : Finmap Ξ²) := by
simp [replace]
@[simp]
theorem keys_replace (a : Ξ±) (b : Ξ² a) (s : Finmap Ξ²) : (replace a b s).keys = s.keys :=
induction_on s fun s => by simp
@[simp]
theorem mem_replace {a a' : Ξ±} {b : Ξ² a} {s : Finmap Ξ²} : a' β replace a b s β a' β s :=
induction_on s fun s => by simp
end
/-! ### foldl -/
/-- Fold a commutative function over the key-value pairs in the map -/
def foldl {Ξ΄ : Type w} (f : Ξ΄ β β a, Ξ² a β Ξ΄)
(H : β d aβ bβ aβ bβ, f (f d aβ bβ) aβ bβ = f (f d aβ bβ) aβ bβ) (d : Ξ΄) (m : Finmap Ξ²) : Ξ΄ :=
letI : RightCommutative fun d (s : Sigma Ξ²) β¦ f d s.1 s.2 := β¨fun _ _ _ β¦ H _ _ _ _ _β©
m.entries.foldl (fun d s => f d s.1 s.2) d
/-- `any f s` returns `true` iff there exists a value `v` in `s` such that `f v = true`. -/
def any (f : β x, Ξ² x β Bool) (s : Finmap Ξ²) : Bool :=
s.foldl (fun x y z => x || f y z)
(fun _ _ _ _ => by simp_rw [Bool.or_assoc, Bool.or_comm, imp_true_iff]) false
/-- `all f s` returns `true` iff `f v = true` for all values `v` in `s`. -/
def all (f : β x, Ξ² x β Bool) (s : Finmap Ξ²) : Bool :=
s.foldl (fun x y z => x && f y z)
(fun _ _ _ _ => by simp_rw [Bool.and_assoc, Bool.and_comm, imp_true_iff]) true
/-! ### erase -/
section
variable [DecidableEq Ξ±]
/-- Erase a key from the map. If the key is not present it does nothing. -/
def erase (a : Ξ±) (s : Finmap Ξ²) : Finmap Ξ² :=
(liftOn s fun t => AList.toFinmap (AList.erase a t)) fun _ _ p => toFinmap_eq.2 <| perm_erase p
@[simp]
theorem erase_toFinmap (a : Ξ±) (s : AList Ξ²) : erase a β¦sβ§ = AList.toFinmap (s.erase a) := by
simp [erase]
@[simp]
theorem keys_erase_toFinset (a : Ξ±) (s : AList Ξ²) : keys β¦s.erase aβ§ = (keys β¦sβ§).erase a := by
simp [Finset.erase, keys, AList.erase, keys_kerase]
@[simp]
theorem keys_erase (a : Ξ±) (s : Finmap Ξ²) : (erase a s).keys = s.keys.erase a :=
induction_on s fun s => by simp
@[simp]
theorem mem_erase {a a' : Ξ±} {s : Finmap Ξ²} : a' β erase a s β a' β a β§ a' β s :=
induction_on s fun s => by simp
theorem notMem_erase_self {a : Ξ±} {s : Finmap Ξ²} : a β erase a s := by
rw [mem_erase, not_and_or, not_not]
left
rfl
@[deprecated (since := "2025-05-23")] alias not_mem_erase_self := notMem_erase_self
@[simp]
theorem lookup_erase (a) (s : Finmap Ξ²) : lookup a (erase a s) = none :=
induction_on s <| AList.lookup_erase a
@[simp]
theorem lookup_erase_ne {a a'} {s : Finmap Ξ²} (h : a β a') : lookup a (erase a' s) = lookup a s :=
induction_on s fun _ => AList.lookup_erase_ne h
theorem erase_erase {a a' : Ξ±} {s : Finmap Ξ²} : erase a (erase a' s) = erase a' (erase a s) :=
induction_on s fun s => ext (by simp only [AList.erase_erase, erase_toFinmap])
/-! ### sdiff -/
/-- `sdiff s s'` consists of all key-value pairs from `s` and `s'` where the keys are in `s` or
`s'` but not both. -/
def sdiff (s s' : Finmap Ξ²) : Finmap Ξ² :=
s'.foldl (fun s x _ => s.erase x) (fun _ _ _ _ _ => erase_erase) s
instance : SDiff (Finmap Ξ²) :=
β¨sdiffβ©
/-! ### insert -/
/-- Insert a key-value pair into a finite map, replacing any existing pair with
the same key. -/
def insert (a : Ξ±) (b : Ξ² a) (s : Finmap Ξ²) : Finmap Ξ² :=
(liftOn s fun t => AList.toFinmap (AList.insert a b t)) fun _ _ p =>
toFinmap_eq.2 <| perm_insert p
@[simp]
theorem insert_toFinmap (a : Ξ±) (b : Ξ² a) (s : AList Ξ²) :
insert a b (AList.toFinmap s) = AList.toFinmap (s.insert a b) := by
simp [insert]
theorem entries_insert_of_notMem {a : Ξ±} {b : Ξ² a} {s : Finmap Ξ²} :
a β s β (insert a b s).entries = β¨a, bβ© ::β s.entries :=
induction_on s fun s h => by
simp [AList.entries_insert_of_notMem (mt mem_toFinmap.1 h), -entries_insert]
@[deprecated (since := "2025-05-23")] alias entries_insert_of_not_mem := entries_insert_of_notMem
@[simp]
theorem mem_insert {a a' : Ξ±} {b' : Ξ² a'} {s : Finmap Ξ²} : a β insert a' b' s β a = a' β¨ a β s :=
induction_on s AList.mem_insert
@[simp]
theorem lookup_insert {a} {b : Ξ² a} (s : Finmap Ξ²) : lookup a (insert a b s) = some b :=
induction_on s fun s => by simp only [insert_toFinmap, lookup_toFinmap, AList.lookup_insert]
@[simp]
theorem lookup_insert_of_ne {a a'} {b : Ξ² a} (s : Finmap Ξ²) (h : a' β a) :
lookup a' (insert a b s) = lookup a' s :=
induction_on s fun s => by simp only [insert_toFinmap, lookup_toFinmap, lookup_insert_ne h]
@[simp]
theorem insert_insert {a} {b b' : Ξ² a} (s : Finmap Ξ²) :
(s.insert a b).insert a b' = s.insert a b' :=
induction_on s fun s => by simp only [insert_toFinmap, AList.insert_insert]
theorem insert_insert_of_ne {a a'} {b : Ξ² a} {b' : Ξ² a'} (s : Finmap Ξ²) (h : a β a') :
(s.insert a b).insert a' b' = (s.insert a' b').insert a b :=
induction_on s fun s => by
simp only [insert_toFinmap, AList.toFinmap_eq, AList.insert_insert_of_ne _ h]
theorem toFinmap_cons (a : Ξ±) (b : Ξ² a) (xs : List (Sigma Ξ²)) :
List.toFinmap (β¨a, bβ© :: xs) = insert a b xs.toFinmap :=
rfl
theorem mem_list_toFinmap (a : Ξ±) (xs : List (Sigma Ξ²)) :
a β xs.toFinmap β β b : Ξ² a, Sigma.mk a b β xs := by
induction' xs with x xs
Β· simp only [toFinmap_nil, notMem_empty, not_mem_nil, exists_false]
obtain β¨fst_i, snd_iβ© := x
simp only [toFinmap_cons, *, exists_or, mem_cons, mem_insert, exists_and_left, Sigma.mk.inj_iff]
refine (or_congr_left <| and_iff_left_of_imp ?_).symm
rintro rfl
simp only [exists_eq, heq_iff_eq]
@[simp]
theorem insert_singleton_eq {a : Ξ±} {b b' : Ξ² a} : insert a b (singleton a b') = singleton a b := by
simp only [singleton, Finmap.insert_toFinmap, AList.insert_singleton_eq]
/-! ### extract -/
/-- Erase a key from the map, and return the corresponding value, if found. -/
def extract (a : Ξ±) (s : Finmap Ξ²) : Option (Ξ² a) Γ Finmap Ξ² :=
(liftOn s fun t => Prod.map id AList.toFinmap (AList.extract a t)) fun sβ sβ p => by
simp [perm_lookup p, toFinmap_eq, perm_erase p]
@[simp]
theorem extract_eq_lookup_erase (a : Ξ±) (s : Finmap Ξ²) : extract a s = (lookup a s, erase a s) :=
induction_on s fun s => by simp [extract]
/-! ### union -/
/-- `sβ βͺ sβ` is the key-based union of two finite maps. It is left-biased: if
there exists an `a β sβ`, `lookup a (sβ βͺ sβ) = lookup a sβ`. -/
def union (sβ sβ : Finmap Ξ²) : Finmap Ξ² :=
(liftOnβ sβ sβ fun sβ sβ => (AList.toFinmap (sβ βͺ sβ))) fun _ _ _ _ pββ pββ =>
toFinmap_eq.mpr <| perm_union pββ pββ
instance : Union (Finmap Ξ²) :=
β¨unionβ©
@[simp]
theorem mem_union {a} {sβ sβ : Finmap Ξ²} : a β sβ βͺ sβ β a β sβ β¨ a β sβ :=
induction_onβ sβ sβ fun _ _ => AList.mem_union
@[simp]
theorem union_toFinmap (sβ sβ : AList Ξ²) : (toFinmap sβ) βͺ (toFinmap sβ) = toFinmap (sβ βͺ sβ) := by
simp [(Β· βͺ Β·), union]
theorem keys_union {sβ sβ : Finmap Ξ²} : (sβ βͺ sβ).keys = sβ.keys βͺ sβ.keys :=
induction_onβ sβ sβ fun sβ sβ => Finset.ext <| by simp [keys]
@[simp]
theorem lookup_union_left {a} {sβ sβ : Finmap Ξ²} : a β sβ β lookup a (sβ βͺ sβ) = lookup a sβ :=
induction_onβ sβ sβ fun _ _ => AList.lookup_union_left
@[simp]
theorem lookup_union_right {a} {sβ sβ : Finmap Ξ²} : a β sβ β lookup a (sβ βͺ sβ) = lookup a sβ :=
induction_onβ sβ sβ fun _ _ => AList.lookup_union_right
theorem lookup_union_left_of_not_in {a} {sβ sβ : Finmap Ξ²} (h : a β sβ) :
lookup a (sβ βͺ sβ) = lookup a sβ := by
by_cases h' : a β sβ
Β· rw [lookup_union_left h']
Β· rw [lookup_union_right h', lookup_eq_none.mpr h, lookup_eq_none.mpr h']
/-- `simp`-normal form of `mem_lookup_union` -/
@[simp]
theorem mem_lookup_union' {a} {b : Ξ² a} {sβ sβ : Finmap Ξ²} :
lookup a (sβ βͺ sβ) = some b β b β lookup a sβ β¨ a β sβ β§ b β lookup a sβ :=
induction_onβ sβ sβ fun _ _ => AList.mem_lookup_union
theorem mem_lookup_union {a} {b : Ξ² a} {sβ sβ : Finmap Ξ²} :
b β lookup a (sβ βͺ sβ) β b β lookup a sβ β¨ a β sβ β§ b β lookup a sβ :=
induction_onβ sβ sβ fun _ _ => AList.mem_lookup_union
theorem mem_lookup_union_middle {a} {b : Ξ² a} {sβ sβ sβ : Finmap Ξ²} :
b β lookup a (sβ βͺ sβ) β a β sβ β b β lookup a (sβ βͺ sβ βͺ sβ) :=
induction_onβ sβ sβ sβ fun _ _ _ => AList.mem_lookup_union_middle
theorem insert_union {a} {b : Ξ² a} {sβ sβ : Finmap Ξ²} : insert a b (sβ βͺ sβ) = insert a b sβ βͺ sβ :=
induction_onβ sβ sβ fun aβ aβ => by simp [AList.insert_union]
theorem union_assoc {sβ sβ sβ : Finmap Ξ²} : sβ βͺ sβ βͺ sβ = sβ βͺ (sβ βͺ sβ) :=
induction_onβ sβ sβ sβ fun sβ sβ sβ => by
simp only [AList.toFinmap_eq, union_toFinmap, AList.union_assoc]
@[simp]
theorem empty_union {sβ : Finmap Ξ²} : β
βͺ sβ = sβ :=
induction_on sβ fun sβ => by
rw [β empty_toFinmap]
simp [-empty_toFinmap, union_toFinmap]
@[simp]
theorem union_empty {sβ : Finmap Ξ²} : sβ βͺ β
= sβ :=
induction_on sβ fun sβ => by
rw [β empty_toFinmap]
simp [-empty_toFinmap, union_toFinmap]
theorem erase_union_singleton (a : Ξ±) (b : Ξ² a) (s : Finmap Ξ²) (h : s.lookup a = some b) :
s.erase a βͺ singleton a b = s :=
ext_lookup fun x => by
by_cases h' : x = a
Β· subst a
rw [lookup_union_right notMem_erase_self, lookup_singleton_eq, h]
Β· have : x β singleton a b := by rwa [mem_singleton]
rw [lookup_union_left_of_not_in this, lookup_erase_ne h']
end
/-! ### Disjoint -/
/-- `Disjoint sβ sβ` holds if `sβ` and `sβ` have no keys in common. -/
def Disjoint (sβ sβ : Finmap Ξ²) : Prop :=
β x β sβ, x β sβ
theorem disjoint_empty (x : Finmap Ξ²) : Disjoint β
x :=
nofun
@[symm]
theorem Disjoint.symm (x y : Finmap Ξ²) (h : Disjoint x y) : Disjoint y x := fun p hy hx => h p hx hy
theorem Disjoint.symm_iff (x y : Finmap Ξ²) : Disjoint x y β Disjoint y x :=
β¨Disjoint.symm x y, Disjoint.symm y xβ©
section
variable [DecidableEq Ξ±]
instance : DecidableRel (@Disjoint Ξ± Ξ²) := fun x y => by dsimp only [Disjoint]; infer_instance
theorem disjoint_union_left (x y z : Finmap Ξ²) :
Disjoint (x βͺ y) z β Disjoint x z β§ Disjoint y z := by
simp [Disjoint, Finmap.mem_union, or_imp, forall_and]
theorem disjoint_union_right (x y z : Finmap Ξ²) :
Disjoint x (y βͺ z) β Disjoint x y β§ Disjoint x z := by
rw [Disjoint.symm_iff, disjoint_union_left, Disjoint.symm_iff _ x, Disjoint.symm_iff _ x]
theorem union_comm_of_disjoint {sβ sβ : Finmap Ξ²} : Disjoint sβ sβ β sβ βͺ sβ = sβ βͺ sβ :=
induction_onβ sβ sβ fun sβ sβ => by
intro h
simp only [AList.toFinmap_eq, union_toFinmap, AList.union_comm_of_disjoint h]
theorem union_cancel {sβ sβ sβ : Finmap Ξ²} (h : Disjoint sβ sβ) (h' : Disjoint sβ sβ) :
sβ βͺ sβ = sβ βͺ sβ β sβ = sβ :=
β¨fun h'' => by
apply ext_lookup
intro x
have : (sβ βͺ sβ).lookup x = (sβ βͺ sβ).lookup x := h'' βΈ rfl
by_cases hsβ : x β sβ
Β· rwa [lookup_union_left hsβ, lookup_union_left_of_not_in (h _ hsβ)] at this
Β· by_cases hsβ : x β sβ
Β· rwa [lookup_union_left_of_not_in (h' _ hsβ), lookup_union_left hsβ] at this
Β· rw [lookup_eq_none.mpr hsβ, lookup_eq_none.mpr hsβ], fun h => h βΈ rflβ©
end
end Finmap
|
TransfiniteIteration.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.SmallObject.Iteration.Nonempty
import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition
import Mathlib.CategoryTheory.Limits.Shapes.Preorder.WellOrderContinuous
/-!
# The transfinite iteration of a successor structure
Given a successor structure `Ξ¦ : SuccStruct C` (see the file `SmallObject.Iteration.Basic`)
and a well-ordered type `J`, we define the iteration `Ξ¦.iteration J : C`. It is
defined as the colimit of a functor `Ξ¦.iterationFunctor J : J β₯€ C`.
-/
universe w v u
namespace CategoryTheory.SmallObject.SuccStruct
open Category Limits
variable {C : Type u} [Category.{v} C] (Ξ¦ : SuccStruct C)
(J : Type w) [LinearOrder J] [OrderBot J] [SuccOrder J] [WellFoundedLT J]
[HasIterationOfShape J C]
variable {J} in
/-- Given `Ξ¦ : SuccStruct C` and an element `j : J` in a well-ordered type,
this is the unique element in `Ξ¦.Iteration j`. -/
noncomputable def iter (j : J) : Ξ¦.Iteration j := Classical.arbitrary _
/-- Given `Ξ¦ : SuccStruct C` and a well-ordered type `J`, this
is the functor `J β₯€ C` which gives the iterations of `Ξ¦` indexed by `J`. -/
noncomputable def iterationFunctor : J β₯€ C where
obj j := (Ξ¦.iter j).F.obj β¨j, by simpβ©
map f := Iteration.mapObj _ _ (leOfHom f) _ _ (leOfHom f)
/-- Given `Ξ¦ : SuccStruct C` and a well-ordered type `J`,
this is an object of `C` which is the iteration of `Ξ¦` to the power `J`:
it is defined as the colimit of the functor `Ξ¦.iterationFunctor J : J β₯€ C`. -/
noncomputable def iteration : C := colimit (Ξ¦.iterationFunctor J)
/-- The colimit cocone expressing that `Ξ¦.iteration J` is the colimit
of `Ξ¦.iterationFunctor J`. -/
noncomputable def iterationCocone : Cocone (Ξ¦.iterationFunctor J) :=
colimit.cocone _
@[simp]
lemma iterationCocone_pt : (Ξ¦.iterationCocone J).pt = Ξ¦.iteration J := rfl
/-- `Ξ¦.iteration J` identifies to the colimit of `Ξ¦.iterationFunctor J`. -/
noncomputable def isColimitIterationCocone : IsColimit (Ξ¦.iterationCocone J) :=
colimit.isColimit _
variable {J}
lemma iterationFunctor_obj (i : J) {j : J} (iter : Ξ¦.Iteration j) (hi : i β€ j) :
(Ξ¦.iterationFunctor J).obj i = iter.F.obj β¨i, hiβ© :=
Iteration.congr_obj (Ξ¦.iter i) iter i (by simp) hi
lemma arrowMk_iterationFunctor_map (iβ iβ : J) (hββ : iβ β€ iβ)
{j : J} (iter : Ξ¦.Iteration j) (hj : iβ β€ j) :
Arrow.mk ((Ξ¦.iterationFunctor J).map (homOfLE hββ)) =
Arrow.mk (iter.F.map (homOfLE hββ : β¨iβ, hββ.trans hjβ© βΆ β¨iβ, hjβ©)) := by
dsimp [iterationFunctor]
rw [Iteration.arrow_mk_mapObj]
exact Arrow.ext (Iteration.congr_obj _ _ _ _ _)
(Iteration.congr_obj _ _ _ _ _) (Iteration.congr_map _ _ _ _ _)
variable (J)
instance : (Ξ¦.iterationFunctor J).IsWellOrderContinuous where
nonempty_isColimit i hi := β¨by
let e : (Set.principalSegIio i).monotone.functor β
(Ξ¦.iterationFunctor J) β
restrictionLT (Ξ¦.iter i).F (by simp) :=
NatIso.ofComponents (fun _ β¦ eqToIso (Ξ¦.iterationFunctor_obj _ _ _)) (by
rintro β¨kβ, hββ© β¨kβ, hββ© f
apply Arrow.mk_injective
simpa using Ξ¦.arrowMk_iterationFunctor_map kβ kβ (leOfHom f) (Ξ¦.iter i) hβ.le)
refine (IsColimit.precomposeInvEquiv e _).1 ?_
refine IsColimit.ofIsoColimit ((Ξ¦.iter i).isColimit i hi (by simp)) ?_
refine Cocones.ext (eqToIso (Ξ¦.iterationFunctor_obj i (Ξ¦.iter i) (by simp)).symm) ?_
rintro β¨k, hkβ©
apply Arrow.mk_injective
simp [Ξ¦.arrowMk_iterationFunctor_map k i hk.le (Ξ¦.iter i) (by simp), e]β©
/-- The isomorphism `(Ξ¦.iterationFunctor J).obj β₯ β
Ξ¦.Xβ`. -/
noncomputable def iterationFunctorObjBotIso : (Ξ¦.iterationFunctor J).obj β₯ β
Ξ¦.Xβ :=
eqToIso (Ξ¦.iter β₯).obj_bot
/-- The natural map `Ξ¦.Xβ βΆ (Ξ¦.iterationFunctor J).obj j`. -/
noncomputable def ΞΉIterationFunctor :
(Functor.const _).obj Ξ¦.Xβ βΆ Ξ¦.iterationFunctor J where
app j := (Ξ¦.iterationFunctorObjBotIso J).inv β«
(Ξ¦.iterationFunctor J).map (homOfLE bot_le : β₯ βΆ j)
naturality _ _ f := by
dsimp
rw [id_comp, assoc, β Functor.map_comp]
rfl
/-- The canonical map `Ξ¦.Xβ βΆ Ξ¦.iteration J` which is the `J`th-transfinite composition
of maps `Ξ¦.toSucc`. -/
noncomputable def ΞΉIteration : Ξ¦.Xβ βΆ Ξ¦.iteration J :=
(Ξ¦.iterationFunctorObjBotIso J).inv β« colimit.ΞΉ _ β₯
/-- The inclusion `Ξ¦.ΞΉIteration J` is a transfinite composition of
shape `J` of morphisms in `Ξ¦.prop`. -/
@[simps]
noncomputable def transfiniteCompositionOfShapeΞΉIteration :
Ξ¦.prop.TransfiniteCompositionOfShape J (Ξ¦.ΞΉIteration J) where
isoBot := Ξ¦.iterationFunctorObjBotIso J
map_mem j hj := by
have := (Ξ¦.iter (Order.succ j)).prop_map_succ j (Order.lt_succ_of_not_isMax hj)
rw [prop_iff] at this β’
simp only [Ξ¦.iterationFunctor_obj j (Ξ¦.iter (Order.succ j)) (Order.le_succ j),
Ξ¦.arrowMk_iterationFunctor_map _ _ (Order.le_succ j) (Ξ¦.iter (Order.succ j)) (by simp),
this]
F := Ξ¦.iterationFunctor J
incl := (Ξ¦.iterationCocone J).ΞΉ
isColimit := Ξ¦.isColimitIterationCocone J
variable {J}
lemma prop_iterationFunctor_map_succ (j : J) (hj : Β¬ IsMax j) :
Ξ¦.prop ((Ξ¦.iterationFunctor J).map (homOfLE (Order.le_succ j))) :=
(Ξ¦.transfiniteCompositionOfShapeΞΉIteration J).map_mem j hj
/-- When `j` is not a maximal element, then
`(Ξ¦.iterationFunctor J).obj (Order.succ j)` is isomorphic to
`Ξ¦.succ ((Ξ¦.iterationFunctor J).obj j)`. -/
noncomputable def iterationFunctorObjSuccIso (j : J) (hj : Β¬ IsMax j) :
(Ξ¦.iterationFunctor J).obj (Order.succ j) β
Ξ¦.succ ((Ξ¦.iterationFunctor J).obj j) :=
eqToIso ((Ξ¦.prop_iterationFunctor_map_succ j hj).succ_eq.symm)
@[reassoc]
lemma iterationFunctor_map_succ (j : J) (hj : Β¬ IsMax j) :
(Ξ¦.iterationFunctor J).map (homOfLE (Order.le_succ j)) =
Ξ¦.toSucc _ β« (Ξ¦.iterationFunctorObjSuccIso j hj).inv :=
(Ξ¦.prop_iterationFunctor_map_succ j hj).fac
end CategoryTheory.SmallObject.SuccStruct
|
Absorbs.lean
|
/-
Copyright (c) 2020 Jean Lo, Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo, Yury Kudryashov
-/
import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set
import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.Topology.Bornology.Basic
/-!
# Absorption of sets
Let `M` act on `Ξ±`, let `A` and `B` be sets in `Ξ±`.
We say that `A` *absorbs* `B` if for sufficiently large `a : M`, we have `B β a β’ A`.
Formally, "for sufficiently large `a : M`" means "for all but a bounded set of `a`".
Traditionally, this definition is formulated
for the action of a (semi)normed ring on a module over that ring.
We formulate it in a more general settings for two reasons:
- this way we don't have to depend on metric spaces, normed rings etc;
- some proofs look nicer with this definition than with something like
`β r : β, β a : R, r β€ βaβ β B β a β’ A`.
If `M` is a `GroupWithZero` (e.g., a division ring),
the sets absorbing a given set form a filter, see `Filter.absorbing`.
## Implementation notes
For now, all theorems assume that we deal with (a generalization of) a module over a division ring.
Some lemmas have multiplicative versions for `MulDistribMulAction`s.
They can be added later when someone needs them.
## Keywords
absorbs, absorbent
-/
assert_not_exists Real
open Set Bornology Filter
open scoped Pointwise
section Defs
variable (M : Type*) {Ξ± : Type*} [Bornology M] [SMul M Ξ±]
/-- A set `s` absorbs another set `t` if `t` is contained in all scalings of `s`
by all but a bounded set of elements. -/
def Absorbs (s t : Set Ξ±) : Prop :=
βαΆ a in cobounded M, t β a β’ s
/-- A set is *absorbent* if it absorbs every singleton. -/
def Absorbent (s : Set Ξ±) : Prop :=
β x, Absorbs M s {x}
end Defs
namespace Absorbs
section SMul
variable {M Ξ± : Type*} [Bornology M] [SMul M Ξ±] {s sβ sβ t tβ tβ : Set Ξ±} {S T : Set (Set Ξ±)}
protected lemma empty : Absorbs M s β
:= by simp [Absorbs]
protected lemma eventually (h : Absorbs M s t) : βαΆ a in cobounded M, t β a β’ s := h
@[simp] lemma of_boundedSpace [BoundedSpace M] : Absorbs M s t := by simp [Absorbs]
lemma mono_left (h : Absorbs M sβ t) (hs : sβ β sβ) : Absorbs M sβ t :=
h.mono fun _a ha β¦ ha.trans <| smul_set_mono hs
lemma mono_right (h : Absorbs M s tβ) (ht : tβ β tβ) : Absorbs M s tβ :=
h.mono fun _ β¦ ht.trans
lemma mono (h : Absorbs M sβ tβ) (hs : sβ β sβ) (ht : tβ β tβ) : Absorbs M sβ tβ :=
(h.mono_left hs).mono_right ht
@[simp]
lemma _root_.absorbs_union : Absorbs M s (tβ βͺ tβ) β Absorbs M s tβ β§ Absorbs M s tβ := by
simp [Absorbs]
protected lemma union (hβ : Absorbs M s tβ) (hβ : Absorbs M s tβ) : Absorbs M s (tβ βͺ tβ) :=
absorbs_union.2 β¨hβ, hββ©
lemma _root_.Set.Finite.absorbs_sUnion {T : Set (Set Ξ±)} (hT : T.Finite) :
Absorbs M s (ββ T) β β t β T, Absorbs M s t := by
simp [Absorbs, hT]
protected lemma sUnion (hT : T.Finite) (hs : β t β T, Absorbs M s t) :
Absorbs M s (ββ T) :=
hT.absorbs_sUnion.2 hs
@[simp]
lemma _root_.absorbs_iUnion {ΞΉ : Sort*} [Finite ΞΉ] {t : ΞΉ β Set Ξ±} :
Absorbs M s (β i, t i) β β i, Absorbs M s (t i) :=
(finite_range t).absorbs_sUnion.trans forall_mem_range
protected alias β¨_, iUnionβ© := absorbs_iUnion
lemma _root_.Set.Finite.absorbs_biUnion {ΞΉ : Type*} {t : ΞΉ β Set Ξ±} {I : Set ΞΉ} (hI : I.Finite) :
Absorbs M s (β i β I, t i) β β i β I, Absorbs M s (t i) := by
simp [Absorbs, hI]
protected alias β¨_, biUnionβ© := Set.Finite.absorbs_biUnion
@[simp]
lemma _root_.absorbs_biUnion_finset {ΞΉ : Type*} {t : ΞΉ β Set Ξ±} {I : Finset ΞΉ} :
Absorbs M s (β i β I, t i) β β i β I, Absorbs M s (t i) :=
I.finite_toSet.absorbs_biUnion
protected alias β¨_, biUnion_finsetβ© := absorbs_biUnion_finset
end SMul
section AddZero
variable {M E : Type*} [Bornology M] {sβ sβ tβ tβ : Set E}
protected lemma add [AddZeroClass E] [DistribSMul M E]
(hβ : Absorbs M sβ tβ) (hβ : Absorbs M sβ tβ) : Absorbs M (sβ + sβ) (tβ + tβ) :=
hβ.mp <| hβ.eventually.mono fun x hxβ hxβ β¦ by rw [smul_add]; exact add_subset_add hxβ hxβ
protected lemma zero [Zero E] [SMulZeroClass M E] {s : Set E} (hs : 0 β s) : Absorbs M s 0 :=
Eventually.of_forall fun _ β¦ zero_subset.2 <| zero_mem_smul_set hs
end AddZero
end Absorbs
section GroupWithZero
variable {Gβ Ξ± : Type*} [GroupWithZero Gβ] [Bornology Gβ] [MulAction Gβ Ξ±]
{s t u : Set Ξ±} {S : Set (Set Ξ±)}
@[simp]
protected lemma Absorbs.univ : Absorbs Gβ univ s :=
(eventually_ne_cobounded 0).mono fun a ha β¦ by rw [smul_set_univβ ha]; apply subset_univ
lemma absorbs_iff_eventually_cobounded_mapsTo :
Absorbs Gβ s t β βαΆ c in cobounded Gβ, MapsTo (cβ»ΒΉ β’ Β·) t s :=
eventually_congr <| (eventually_ne_cobounded 0).mono fun c hc β¦ by
rw [β preimage_smul_invβ hc]; rfl
alias β¨eventually_cobounded_mapsTo, _β© := absorbs_iff_eventually_cobounded_mapsTo
@[simp]
lemma absorbs_inter : Absorbs Gβ (s β© t) u β Absorbs Gβ s u β§ Absorbs Gβ t u := by
simp only [absorbs_iff_eventually_cobounded_mapsTo, mapsTo_inter, eventually_and]
protected lemma Absorbs.inter (hs : Absorbs Gβ s u) (ht : Absorbs Gβ t u) : Absorbs Gβ (s β© t) u :=
absorbs_inter.2 β¨hs, htβ©
variable (Gβ u) in
/-- The filter of sets that absorb `u`. -/
def Filter.absorbing : Filter Ξ± where
sets := {s | Absorbs Gβ s u}
univ_sets := .univ
sets_of_superset h := h.mono_left
inter_sets := .inter
@[simp]
lemma Filter.mem_absorbing : s β absorbing Gβ u β Absorbs Gβ s u := .rfl
lemma Set.Finite.absorbs_sInter (hS : S.Finite) :
Absorbs Gβ (ββ S) t β β s β S, Absorbs Gβ s t :=
sInter_mem (f := absorbing Gβ t) hS
protected alias β¨_, Absorbs.sInterβ© := Set.Finite.absorbs_sInter
@[simp]
lemma absorbs_iInter {ΞΉ : Sort*} [Finite ΞΉ] {s : ΞΉ β Set Ξ±} :
Absorbs Gβ (β i, s i) t β β i, Absorbs Gβ (s i) t :=
iInter_mem (f := absorbing Gβ t)
protected alias β¨_, Absorbs.iInterβ© := absorbs_iInter
lemma Set.Finite.absorbs_biInter {ΞΉ : Type*} {I : Set ΞΉ} (hI : I.Finite) {s : ΞΉ β Set Ξ±} :
Absorbs Gβ (β i β I, s i) t β β i β I, Absorbs Gβ (s i) t :=
biInter_mem (f := absorbing Gβ t) hI
protected alias β¨_, Absorbs.biInterβ© := Set.Finite.absorbs_biInter
@[simp]
lemma absorbs_zero_iff [NeBot (cobounded Gβ)]
{E : Type*} [AddMonoid E] [DistribMulAction Gβ E] {s : Set E} :
Absorbs Gβ s 0 β 0 β s := by
simp only [absorbs_iff_eventually_cobounded_mapsTo, β singleton_zero,
mapsTo_singleton, smul_zero, eventually_const]
end GroupWithZero
section AddGroup
variable {M E : Type*} [Monoid M] [AddGroup E] [DistribMulAction M E] [Bornology M]
@[simp]
lemma absorbs_neg_neg {s t : Set E} : Absorbs M (-s) (-t) β Absorbs M s t := by simp [Absorbs]
alias β¨Absorbs.of_neg_neg, Absorbs.neg_negβ© := absorbs_neg_neg
lemma Absorbs.sub {sβ sβ tβ tβ : Set E} (hβ : Absorbs M sβ tβ) (hβ : Absorbs M sβ tβ) :
Absorbs M (sβ - sβ) (tβ - tβ) := by
simpa only [sub_eq_add_neg] using hβ.add hβ.neg_neg
end AddGroup
namespace Absorbent
section SMul
variable {M Ξ± : Type*} [Bornology M] [SMul M Ξ±] {s t : Set Ξ±}
protected theorem mono (ht : Absorbent M s) (hsub : s β t) : Absorbent M t := fun x β¦
(ht x).mono_left hsub
theorem _root_.absorbent_iff_forall_absorbs_singleton : Absorbent M s β β x, Absorbs M s {x} := .rfl
protected theorem absorbs (hs : Absorbent M s) {x : Ξ±} : Absorbs M s {x} := hs x
theorem absorbs_finite (hs : Absorbent M s) (ht : t.Finite) : Absorbs M s t := by
rw [β Set.biUnion_of_singleton t]
exact .biUnion ht fun _ _ => hs.absorbs
end SMul
theorem vadd_absorbs {M E : Type*} [Bornology M] [AddZeroClass E] [DistribSMul M E]
{sβ sβ t : Set E} {x : E} (hβ : Absorbent M sβ) (hβ : Absorbs M sβ t) :
Absorbs M (sβ + sβ) (x +α΅₯ t) := by
rw [β singleton_vadd]; exact (hβ x).add hβ
end Absorbent
section GroupWithZero
variable {Gβ Ξ± E : Type*} [GroupWithZero Gβ] [Bornology Gβ] [MulAction Gβ Ξ±]
lemma absorbent_univ : Absorbent Gβ (univ : Set Ξ±) := fun _ β¦ .univ
lemma absorbent_iff_inv_smul {s : Set Ξ±} :
Absorbent Gβ s β β x, βαΆ c in cobounded Gβ, cβ»ΒΉ β’ x β s :=
forall_congr' fun x β¦ by simp only [absorbs_iff_eventually_cobounded_mapsTo, mapsTo_singleton]
lemma Absorbent.zero_mem [NeBot (cobounded Gβ)] [AddMonoid E] [DistribMulAction Gβ E]
{s : Set E} (hs : Absorbent Gβ s) : (0 : E) β s :=
absorbs_zero_iff.1 (hs 0)
end GroupWithZero
protected theorem Absorbs.restrict_scalars
{M N Ξ± : Type*} [Monoid N] [SMul M N] [SMul M Ξ±] [MulAction N Ξ±]
[IsScalarTower M N Ξ±] [Bornology M] [Bornology N] {s t : Set Ξ±} (h : Absorbs N s t)
(hbdd : Tendsto (Β· β’ 1 : M β N) (cobounded M) (cobounded N)) :
Absorbs M s t :=
(hbdd.eventually h).mono <| fun x hx β¦ by rwa [smul_one_smul N x s] at hx
|
abelian.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 choice div fintype finfun bigop finset prime.
From mathcomp Require Import binomial fingroup morphism perm automorphism.
From mathcomp Require Import action quotient gfunctor gproduct ssralg countalg.
From mathcomp Require Import finalg zmodp cyclic pgroup gseries nilpotent sylow.
(******************************************************************************)
(* Constructions based on abelian groups and their structure, with some *)
(* emphasis on elementary abelian p-groups. *)
(* 'Ldiv_n() == the set of all x that satisfy x ^+ n = 1, or, *)
(* equivalently the set of x whose order divides n. *)
(* 'Ldiv_n(G) == the set of x in G that satisfy x ^+ n = 1. *)
(* := G :&: 'Ldiv_n() (pure Notation) *)
(* exponent G == the exponent of G: the least e such that x ^+ e = 1 *)
(* for all x in G (the LCM of the orders of x \in G). *)
(* If G is nilpotent its exponent is reached. Note that *)
(* `exponent G %| m' reads as `G has exponent m'. *)
(* 'm(G) == the generator rank of G: the size of a smallest *)
(* generating set for G (this is a basis for G if G *)
(* abelian). *)
(* abelian_type G == the abelian type of G : if G is abelian, a lexico- *)
(* graphically maximal sequence of the orders of the *)
(* elements of a minimal basis of G (if G is a p-group *)
(* this is the sequence of orders for any basis of G, *)
(* sorted in descending order). *)
(* homocyclic G == G is the direct product of cycles of equal order, *)
(* i.e., G is abelian with constant abelian type. *)
(* p.-abelem G == G is an elementary abelian p-group, i.e., it is *)
(* an abelian p-group of exponent p, and thus of order *)
(* p ^ 'm(G) and rank (logn p #|G|). *)
(* is_abelem G == G is an elementary abelian p-group for some prime p. *)
(* 'E_p(G) == the set of elementary abelian p-subgroups of G. *)
(* := [set E : {group _} | p.-abelem E & E \subset G] *)
(* 'E_p^n(G) == the set of elementary abelian p-subgroups of G of *)
(* order p ^ n (or, equivalently, of rank n). *)
(* := [set E in 'E_p(G) | logn p #|E| == n] *)
(* := [set E in 'E_p(G) | #|E| == p ^ n]%N if p is prime *)
(* 'E*_p(G) == the set of maximal elementary abelian p-subgroups *)
(* of G. *)
(* := [set E | [max E | E \in 'E_p(G)]] *)
(* 'E^n(G) == the set of elementary abelian subgroups of G that *)
(* have gerank n (i.e., p-rank n for some prime p). *)
(* := \bigcup_(0 <= p < #|G|.+1) 'E_p^n(G) *)
(* 'r_p(G) == the p-rank of G: the maximal rank of an elementary *)
(* subgroup of G. *)
(* := \max_(E in 'E_p(G)) logn p #|E|. *)
(* 'r(G) == the rank of G. *)
(* := \max_(0 <= p < #|G|.+1) 'm_p(G). *)
(* Note that 'r(G) coincides with 'r_p(G) if G is a p-group, and with 'm(G) *)
(* if G is abelian, but is much more useful than 'm(G) in the proof of the *)
(* Odd Order Theorem. *)
(* 'Ohm_n(G) == the group generated by the x in G with order p ^ m *)
(* for some prime p and some m <= n. Usually, G will be *)
(* a p-group, so 'Ohm_n(G) will be generated by *)
(* 'Ldiv_(p ^ n)(G), set of elements of G of order at *)
(* most p ^ n. If G is also abelian then 'Ohm_n(G) *)
(* consists exactly of those element, and the abelian *)
(* type of G can be computed from the orders of the *)
(* 'Ohm_n(G) subgroups. *)
(* 'Mho^n(G) == the group generated by the x ^+ (p ^ n) for x a *)
(* p-element of G for some prime p. Usually G is a *)
(* p-group, and 'Mho^n(G) is generated by all such *)
(* x ^+ (p ^ n); it consists of exactly these if G is *)
(* also abelian. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section AbelianDefs.
(* We defer the definition of the functors ('Omh_n(G), 'Mho^n(G)) because *)
(* they must quantify over the finGroupType explicitly. *)
Variable gT : finGroupType.
Implicit Types (x : gT) (A B : {set gT}) (pi : nat_pred) (p n : nat).
Definition Ldiv n := [set x : gT | x ^+ n == 1].
Definition exponent A := \big[lcmn/1%N]_(x in A) #[x].
Definition abelem p A := [&& p.-group A, abelian A & exponent A %| p].
Definition is_abelem A := abelem (pdiv #|A|) A.
Definition pElem p A := [set E : {group gT} | E \subset A & abelem p E].
Definition pnElem p n A := [set E in pElem p A | logn p #|E| == n].
Definition nElem n A := \bigcup_(0 <= p < #|A|.+1) pnElem p n A.
Definition pmaxElem p A := [set E | [max E | E \in pElem p A]].
Definition p_rank p A := \max_(E in pElem p A) logn p #|E|.
Definition rank A := \max_(0 <= p < #|A|.+1) p_rank p A.
Definition gen_rank A := #|[arg min_(B < A | <<B>> == A) #|B|]|.
(* The definition of abelian_type depends on an existence lemma. *)
(* The definition of homocyclic depends on abelian_type. *)
End AbelianDefs.
Arguments exponent {gT} A%_g.
Arguments abelem {gT} p%_N A%_g.
Arguments is_abelem {gT} A%_g.
Arguments pElem {gT} p%_N A%_g.
Arguments pnElem {gT} p%_N n%_N A%_g.
Arguments nElem {gT} n%_N A%_g.
Arguments pmaxElem {gT} p%_N A%_g.
Arguments p_rank {gT} p%_N A%_g.
Arguments rank {gT} A%_g.
Arguments gen_rank {gT} A%_g.
Notation "''Ldiv_' n ()" := (Ldiv _ n)
(n at level 2, format "''Ldiv_' n ()") : group_scope.
Notation "''Ldiv_' n ( G )" := (G :&: 'Ldiv_n())
(format "''Ldiv_' n ( G )") : group_scope.
Prenex Implicits exponent.
Notation "p .-abelem" := (abelem p) (format "p .-abelem") : group_scope.
Notation "''E_' p ( G )" := (pElem p G)
(p at level 2, format "''E_' p ( G )") : group_scope.
Notation "''E_' p ^ n ( G )" := (pnElem p n G)
(n at level 2, format "''E_' p ^ n ( G )") : group_scope.
Notation "''E' ^ n ( G )" := (nElem n G)
(n at level 2, format "''E' ^ n ( G )") : group_scope.
Notation "''E*_' p ( G )" := (pmaxElem p G)
(p at level 2, format "''E*_' p ( G )") : group_scope.
Notation "''m' ( A )" := (gen_rank A)
(format "''m' ( A )") : group_scope.
Notation "''r' ( A )" := (rank A)
(format "''r' ( A )") : group_scope.
Notation "''r_' p ( A )" := (p_rank p A)
(p at level 2, format "''r_' p ( A )") : group_scope.
Section Functors.
(* A functor needs to quantify over the finGroupType just beore the set. *)
Variables (n : nat) (gT : finGroupType) (A : {set gT}).
Definition Ohm := <<[set x in A | x ^+ (pdiv #[x] ^ n) == 1]>>.
Definition Mho := <<[set x ^+ (pdiv #[x] ^ n) | x in A & (pdiv #[x]).-elt x]>>.
Canonical Ohm_group : {group gT} := Eval hnf in [group of Ohm].
Canonical Mho_group : {group gT} := Eval hnf in [group of Mho].
Lemma pdiv_p_elt (p : nat) (x : gT) : p.-elt x -> x != 1 -> pdiv #[x] = p.
Proof.
move=> p_x; rewrite /order -cycle_eq1.
by case/(pgroup_pdiv p_x)=> p_pr _ [k ->]; rewrite pdiv_pfactor.
Qed.
Lemma OhmPredP (x : gT) :
reflect (exists2 p, prime p & x ^+ (p ^ n) = 1) (x ^+ (pdiv #[x] ^ n) == 1).
Proof.
have [-> | nt_x] := eqVneq x 1.
by rewrite expg1n eqxx; left; exists 2; rewrite ?expg1n.
apply: (iffP idP) => [/eqP | [p p_pr /eqP x_pn]].
by exists (pdiv #[x]); rewrite ?pdiv_prime ?order_gt1.
rewrite (@pdiv_p_elt p) //; rewrite -order_dvdn in x_pn.
by rewrite [p_elt _ _](pnat_dvd x_pn) // pnatX pnat_id.
Qed.
Lemma Mho_p_elt (p : nat) x : x \in A -> p.-elt x -> x ^+ (p ^ n) \in Mho.
Proof.
move=> Ax p_x; have [-> | ntx] := eqVneq x 1; first by rewrite groupX.
by apply/mem_gen/imsetP; exists x; rewrite ?inE ?Ax (pdiv_p_elt p_x).
Qed.
End Functors.
Arguments Ohm n%_N {gT} A%_g.
Arguments Ohm_group n%_N {gT} A%_g.
Arguments Mho n%_N {gT} A%_g.
Arguments Mho_group n%_N {gT} A%_g.
Arguments OhmPredP {n gT x}.
Notation "''Ohm_' n ( G )" := (Ohm n G)
(n at level 2, format "''Ohm_' n ( G )") : group_scope.
Notation "''Ohm_' n ( G )" := (Ohm_group n G) : Group_scope.
Notation "''Mho^' n ( G )" := (Mho n G)
(n at level 2, format "''Mho^' n ( G )") : group_scope.
Notation "''Mho^' n ( G )" := (Mho_group n G) : Group_scope.
Section ExponentAbelem.
Variable gT : finGroupType.
Implicit Types (p n : nat) (pi : nat_pred) (x : gT) (A B C : {set gT}).
Implicit Types E G H K P X Y : {group gT}.
Lemma LdivP A n x : reflect (x \in A /\ x ^+ n = 1) (x \in 'Ldiv_n(A)).
Proof. by rewrite !inE; apply: (iffP andP) => [] [-> /eqP]. Qed.
Lemma dvdn_exponent x A : x \in A -> #[x] %| exponent A.
Proof. by move=> Ax; rewrite (biglcmn_sup x). Qed.
Lemma expg_exponent x A : x \in A -> x ^+ exponent A = 1.
Proof. by move=> Ax; apply/eqP; rewrite -order_dvdn dvdn_exponent. Qed.
Lemma exponentS A B : A \subset B -> exponent A %| exponent B.
Proof.
by move=> sAB; apply/dvdn_biglcmP=> x Ax; rewrite dvdn_exponent ?(subsetP sAB).
Qed.
Lemma exponentP A n :
reflect (forall x, x \in A -> x ^+ n = 1) (exponent A %| n).
Proof.
apply: (iffP (dvdn_biglcmP _ _ _)) => eAn x Ax.
by apply/eqP; rewrite -order_dvdn eAn.
by rewrite order_dvdn eAn.
Qed.
Arguments exponentP {A n}.
Lemma trivg_exponent G : (G :==: 1) = (exponent G %| 1).
Proof.
rewrite -subG1.
by apply/subsetP/exponentP=> trG x /trG; rewrite expg1 => /set1P.
Qed.
Lemma exponent1 : exponent [1 gT] = 1%N.
Proof. by apply/eqP; rewrite -dvdn1 -trivg_exponent eqxx. Qed.
Lemma exponent_dvdn G : exponent G %| #|G|.
Proof. by apply/dvdn_biglcmP=> x Gx; apply: order_dvdG. Qed.
Lemma exponent_gt0 G : 0 < exponent G.
Proof. exact: dvdn_gt0 (exponent_dvdn G). Qed.
Hint Resolve exponent_gt0 : core.
Lemma pnat_exponent pi G : pi.-nat (exponent G) = pi.-group G.
Proof.
congr (_ && _); first by rewrite cardG_gt0 exponent_gt0.
apply: eq_all_r => p; rewrite !mem_primes cardG_gt0 exponent_gt0 /=.
apply: andb_id2l => p_pr; apply/idP/idP=> pG.
exact: dvdn_trans pG (exponent_dvdn G).
by case/Cauchy: pG => // x Gx <-; apply: dvdn_exponent.
Qed.
Lemma exponentJ A x : exponent (A :^ x) = exponent A.
Proof.
rewrite /exponent (reindex_inj (conjg_inj x)).
by apply: eq_big => [y | y _]; rewrite ?orderJ ?memJ_conjg.
Qed.
Lemma exponent_witness G : nilpotent G -> {x | x \in G & exponent G = #[x]}.
Proof.
move=> nilG; have [//=| /= x Gx max_x] := @arg_maxnP _ 1 [in G] order.
exists x => //; apply/eqP; rewrite eqn_dvd dvdn_exponent // andbT.
apply/dvdn_biglcmP=> y Gy; apply/dvdn_partP=> //= p.
rewrite mem_primes => /andP[p_pr _]; have p_gt1: p > 1 := prime_gt1 p_pr.
rewrite p_part pfactor_dvdn // -(leq_exp2l _ _ p_gt1) -!p_part.
rewrite -(leq_pmul2r (part_gt0 p^' #[x])) partnC // -!order_constt.
rewrite -orderM ?order_constt ?coprime_partC // ?max_x ?groupM ?groupX //.
case/dprodP: (nilpotent_pcoreC p nilG) => _ _ cGpGp' _.
have inGp := mem_normal_Hall (nilpotent_pcore_Hall _ nilG) (pcore_normal _ _).
by red; rewrite -(centsP cGpGp') // inGp ?p_elt_constt ?groupX.
Qed.
Lemma exponent_cycle x : exponent <[x]> = #[x].
Proof. by apply/eqP; rewrite eqn_dvd exponent_dvdn dvdn_exponent ?cycle_id. Qed.
Lemma exponent_cyclic X : cyclic X -> exponent X = #|X|.
Proof. by case/cyclicP=> x ->; apply: exponent_cycle. Qed.
Lemma primes_exponent G : primes (exponent G) = primes (#|G|).
Proof.
apply/eq_primes => p; rewrite !mem_primes exponent_gt0 cardG_gt0 /=.
by apply: andb_id2l => p_pr; apply: negb_inj; rewrite -!p'natE // pnat_exponent.
Qed.
Lemma pi_of_exponent G : \pi(exponent G) = \pi(G).
Proof. by rewrite /pi_of primes_exponent. Qed.
Lemma partn_exponentS pi H G :
H \subset G -> #|G|`_pi %| #|H| -> (exponent H)`_pi = (exponent G)`_pi.
Proof.
move=> sHG Gpi_dvd_H; apply/eqP; rewrite eqn_dvd.
rewrite partn_dvd ?exponentS ?exponent_gt0 //=; apply/dvdn_partP=> // p.
rewrite pi_of_part ?exponent_gt0 // => /andP[_ /= pi_p].
have sppi: {subset (p : nat_pred) <= pi} by move=> q /eqnP->.
have [P sylP] := Sylow_exists p H; have sPH := pHall_sub sylP.
have{} sylP: p.-Sylow(G) P.
rewrite pHallE (subset_trans sPH) //= (card_Hall sylP) eqn_dvd andbC.
by rewrite -{1}(partn_part _ sppi) !partn_dvd ?cardSg ?cardG_gt0.
rewrite partn_part ?partn_biglcm //.
apply: (@big_ind _ (dvdn^~ _)) => [|m n|x Gx]; first exact: dvd1n.
by rewrite dvdn_lcm => ->.
rewrite -order_constt; have p_y := p_elt_constt p x; set y := x.`_p in p_y *.
have sYG: <[y]> \subset G by rewrite cycle_subG groupX.
have [z _ Pyz] := Sylow_Jsub sylP sYG p_y.
rewrite (bigD1 (y ^ z)) ?(subsetP sPH) -?cycle_subG ?cycleJ //=.
by rewrite orderJ part_pnat_id ?dvdn_lcml // (pi_pnat p_y).
Qed.
Lemma exponent_Hall pi G H : pi.-Hall(G) H -> exponent H = (exponent G)`_pi.
Proof.
move=> hallH; have [sHG piH _] := and3P hallH.
rewrite -(partn_exponentS sHG) -?(card_Hall hallH) ?part_pnat_id //.
by apply: pnat_dvd piH; apply: exponent_dvdn.
Qed.
Lemma exponent_Zgroup G : Zgroup G -> exponent G = #|G|.
Proof.
move/forall_inP=> ZgG; apply/eqP; rewrite eqn_dvd exponent_dvdn.
apply/(dvdn_partP _ (cardG_gt0 _)) => p _.
have [S sylS] := Sylow_exists p G; rewrite -(card_Hall sylS).
have /cyclicP[x defS]: cyclic S by rewrite ZgG ?(p_Sylow sylS).
by rewrite defS dvdn_exponent // -cycle_subG -defS (pHall_sub sylS).
Qed.
Lemma cprod_exponent A B G :
A \* B = G -> lcmn (exponent A) (exponent B) = (exponent G).
Proof.
case/cprodP=> [[K H -> ->{A B}] <- cKH].
apply/eqP; rewrite eqn_dvd dvdn_lcm !exponentS ?mulG_subl ?mulG_subr //=.
apply/exponentP=> _ /imset2P[x y Kx Hy ->].
rewrite -[1]mulg1 expgMn; last by red; rewrite -(centsP cKH).
congr (_ * _); apply/eqP; rewrite -order_dvdn.
by rewrite (dvdn_trans (dvdn_exponent Kx)) ?dvdn_lcml.
by rewrite (dvdn_trans (dvdn_exponent Hy)) ?dvdn_lcmr.
Qed.
Lemma dprod_exponent A B G :
A \x B = G -> lcmn (exponent A) (exponent B) = (exponent G).
Proof.
case/dprodP=> [[K H -> ->{A B}] defG cKH _].
by apply: cprod_exponent; rewrite cprodE.
Qed.
Lemma sub_LdivT A n : (A \subset 'Ldiv_n()) = (exponent A %| n).
Proof. by apply/subsetP/exponentP=> eAn x /eAn /[1!inE] /eqP. Qed.
Lemma LdivT_J n x : 'Ldiv_n() :^ x = 'Ldiv_n().
Proof.
apply/setP=> y; rewrite !inE mem_conjg inE -conjXg.
by rewrite (canF_eq (conjgKV x)) conj1g.
Qed.
Lemma LdivJ n A x : 'Ldiv_n(A :^ x) = 'Ldiv_n(A) :^ x.
Proof. by rewrite conjIg LdivT_J. Qed.
Lemma sub_Ldiv A n : (A \subset 'Ldiv_n(A)) = (exponent A %| n).
Proof. by rewrite subsetI subxx sub_LdivT. Qed.
Lemma group_Ldiv G n : abelian G -> group_set 'Ldiv_n(G).
Proof.
move=> cGG; apply/group_setP.
split=> [|x y]; rewrite !inE ?group1 ?expg1n //=.
case/andP=> Gx /eqP xn /andP[Gy /eqP yn].
by rewrite groupM //= expgMn ?xn ?yn ?mulg1 //; apply: (centsP cGG).
Qed.
Lemma abelian_exponent_gen A : abelian A -> exponent <<A>> = exponent A.
Proof.
rewrite -abelian_gen; set n := exponent A; set G := <<A>> => cGG.
apply/eqP; rewrite eqn_dvd andbC exponentS ?subset_gen //= -sub_Ldiv.
rewrite -(gen_set_id (group_Ldiv n cGG)) genS // subsetI subset_gen /=.
by rewrite sub_LdivT.
Qed.
Lemma abelem_pgroup p A : p.-abelem A -> p.-group A.
Proof. by case/andP. Qed.
Lemma abelem_abelian p A : p.-abelem A -> abelian A.
Proof. by case/and3P. Qed.
Lemma abelem1 p : p.-abelem [1 gT].
Proof. by rewrite /abelem pgroup1 abelian1 exponent1 dvd1n. Qed.
Lemma abelemE p G : prime p -> p.-abelem G = abelian G && (exponent G %| p).
Proof.
move=> p_pr; rewrite /abelem -pnat_exponent andbA -!(andbC (_ %| _)).
by case: (dvdn_pfactor _ 1 p_pr) => // [[k _ ->]]; rewrite pnatX pnat_id.
Qed.
Lemma abelemP p G :
prime p ->
reflect (abelian G /\ forall x, x \in G -> x ^+ p = 1) (p.-abelem G).
Proof.
by move=> p_pr; rewrite abelemE //; apply: (iffP andP) => [] [-> /exponentP].
Qed.
Lemma abelem_order_p p G x : p.-abelem G -> x \in G -> x != 1 -> #[x] = p.
Proof.
case/and3P=> pG _ eG Gx; rewrite -cycle_eq1 => ntX.
have{ntX} [p_pr p_x _] := pgroup_pdiv (mem_p_elt pG Gx) ntX.
by apply/eqP; rewrite eqn_dvd p_x andbT order_dvdn (exponentP eG).
Qed.
Lemma cyclic_abelem_prime p X : p.-abelem X -> cyclic X -> X :!=: 1 -> #|X| = p.
Proof.
move=> abelX cycX; case/cyclicP: cycX => x -> in abelX *.
by rewrite cycle_eq1; apply: abelem_order_p abelX (cycle_id x).
Qed.
Lemma cycle_abelem p x : p.-elt x || prime p -> p.-abelem <[x]> = (#[x] %| p).
Proof.
move=> p_xVpr; rewrite /abelem cycle_abelian /=.
apply/andP/idP=> [[_ xp1] | x_dvd_p].
by rewrite order_dvdn (exponentP xp1) ?cycle_id.
split; last exact: dvdn_trans (exponent_dvdn _) x_dvd_p.
by case/orP: p_xVpr => // /pnat_id; apply: pnat_dvd.
Qed.
Lemma exponent2_abelem G : exponent G %| 2 -> 2.-abelem G.
Proof.
move/exponentP=> expG; apply/abelemP=> //; split=> //.
apply/centsP=> x Gx y Gy; apply: (mulIg x); apply: (mulgI y).
by rewrite -!mulgA !(mulgA y) -!(expgS _ 1) !expG ?mulg1 ?groupM.
Qed.
Lemma prime_abelem p G : prime p -> #|G| = p -> p.-abelem G.
Proof.
move=> p_pr oG; rewrite /abelem -oG exponent_dvdn.
by rewrite /pgroup cyclic_abelian ?prime_cyclic ?oG ?pnat_id.
Qed.
Lemma abelem_cyclic p G : p.-abelem G -> cyclic G = (logn p #|G| <= 1).
Proof.
move=> abelG; have [pG _ expGp] := and3P abelG.
case: (eqsVneq G 1) => [-> | ntG]; first by rewrite cyclic1 cards1 logn1.
have [p_pr _ [e oG]] := pgroup_pdiv pG ntG; apply/idP/idP.
case/cyclicP=> x defG; rewrite -(pfactorK 1 p_pr) dvdn_leq_log ?prime_gt0 //.
by rewrite defG order_dvdn (exponentP expGp) // defG cycle_id.
by rewrite oG pfactorK // ltnS leqn0 => e0; rewrite prime_cyclic // oG (eqP e0).
Qed.
Lemma abelemS p H G : H \subset G -> p.-abelem G -> p.-abelem H.
Proof.
move=> sHG /and3P[cGG pG Gp1]; rewrite /abelem.
by rewrite (pgroupS sHG) // (abelianS sHG) // (dvdn_trans (exponentS sHG)).
Qed.
Lemma abelemJ p G x : p.-abelem (G :^ x) = p.-abelem G.
Proof. by rewrite /abelem pgroupJ abelianJ exponentJ. Qed.
Lemma cprod_abelem p A B G :
A \* B = G -> p.-abelem G = p.-abelem A && p.-abelem B.
Proof.
case/cprodP=> [[H K -> ->{A B}] defG cHK].
apply/idP/andP=> [abelG | []].
by rewrite !(abelemS _ abelG) // -defG (mulG_subl, mulG_subr).
case/and3P=> pH cHH expHp; case/and3P=> pK cKK expKp.
rewrite -defG /abelem pgroupM pH pK abelianM cHH cKK cHK /=.
apply/exponentP=> _ /imset2P[x y Hx Ky ->].
rewrite expgMn; last by red; rewrite -(centsP cHK).
by rewrite (exponentP expHp) // (exponentP expKp) // mul1g.
Qed.
Lemma dprod_abelem p A B G :
A \x B = G -> p.-abelem G = p.-abelem A && p.-abelem B.
Proof.
move=> defG; case/dprodP: (defG) => _ _ _ tiHK.
by apply: cprod_abelem; rewrite -dprodEcp.
Qed.
Lemma is_abelem_pgroup p G : p.-group G -> is_abelem G = p.-abelem G.
Proof.
rewrite /is_abelem => pG.
case: (eqsVneq G 1) => [-> | ntG]; first by rewrite !abelem1.
by have [p_pr _ [k ->]] := pgroup_pdiv pG ntG; rewrite pdiv_pfactor.
Qed.
Lemma is_abelemP G : reflect (exists2 p, prime p & p.-abelem G) (is_abelem G).
Proof.
apply: (iffP idP) => [abelG | [p p_pr abelG]].
case: (eqsVneq G 1) => [-> | ntG]; first by exists 2; rewrite ?abelem1.
by exists (pdiv #|G|); rewrite ?pdiv_prime // ltnNge -trivg_card_le1.
by rewrite (is_abelem_pgroup (abelem_pgroup abelG)).
Qed.
Lemma pElemP p A E : reflect (E \subset A /\ p.-abelem E) (E \in 'E_p(A)).
Proof. by rewrite inE; apply: andP. Qed.
Arguments pElemP {p A E}.
Lemma pElemS p A B : A \subset B -> 'E_p(A) \subset 'E_p(B).
Proof.
by move=> sAB; apply/subsetP=> E /[!inE] /andP[/subset_trans->].
Qed.
Lemma pElemI p A B : 'E_p(A :&: B) = 'E_p(A) :&: subgroups B.
Proof. by apply/setP=> E; rewrite !inE subsetI andbAC. Qed.
Lemma pElemJ x p A E : ((E :^ x)%G \in 'E_p(A :^ x)) = (E \in 'E_p(A)).
Proof. by rewrite !inE conjSg abelemJ. Qed.
Lemma pnElemP p n A E :
reflect [/\ E \subset A, p.-abelem E & logn p #|E| = n] (E \in 'E_p^n(A)).
Proof. by rewrite !inE -andbA; apply: (iffP and3P) => [] [-> -> /eqP]. Qed.
Arguments pnElemP {p n A E}.
Lemma pnElemPcard p n A E :
E \in 'E_p^n(A) -> [/\ E \subset A, p.-abelem E & #|E| = p ^ n]%N.
Proof.
by case/pnElemP=> -> abelE <-; rewrite -card_pgroup // abelem_pgroup.
Qed.
Lemma card_pnElem p n A E : E \in 'E_p^n(A) -> #|E| = (p ^ n)%N.
Proof. by case/pnElemPcard. Qed.
Lemma pnElem0 p G : 'E_p^0(G) = [set 1%G].
Proof.
apply/setP=> E; rewrite !inE -andbA; apply/and3P/idP=> [[_ pE] | /eqP->].
apply: contraLR; case/(pgroup_pdiv (abelem_pgroup pE)) => p_pr _ [k ->].
by rewrite pfactorK.
by rewrite sub1G abelem1 cards1 logn1.
Qed.
Lemma pnElem_prime p n A E : E \in 'E_p^n.+1(A) -> prime p.
Proof. by case/pnElemP=> _ _; rewrite lognE; case: prime. Qed.
Lemma pnElemE p n A :
prime p -> 'E_p^n(A) = [set E in 'E_p(A) | #|E| == (p ^ n)%N].
Proof.
move/pfactorK=> pnK; apply/setP=> E; rewrite 3!inE.
case: (@andP (E \subset A)) => //= [[_]] /andP[/p_natP[k ->] _].
by rewrite pnK (can_eq pnK).
Qed.
Lemma pnElemS p n A B : A \subset B -> 'E_p^n(A) \subset 'E_p^n(B).
Proof.
move=> sAB; apply/subsetP=> E.
by rewrite !inE -!andbA => /andP[/subset_trans->].
Qed.
Lemma pnElemI p n A B : 'E_p^n(A :&: B) = 'E_p^n(A) :&: subgroups B.
Proof. by apply/setP=> E; rewrite !inE subsetI -!andbA; do !bool_congr. Qed.
Lemma pnElemJ x p n A E : ((E :^ x)%G \in 'E_p^n(A :^ x)) = (E \in 'E_p^n(A)).
Proof. by rewrite inE pElemJ cardJg !inE. Qed.
Lemma abelem_pnElem p n G :
p.-abelem G -> n <= logn p #|G| -> exists E, E \in 'E_p^n(G).
Proof.
case: n => [|n] abelG lt_nG; first by exists 1%G; rewrite pnElem0 set11.
have p_pr: prime p by move: lt_nG; rewrite lognE; case: prime.
case/(normal_pgroup (abelem_pgroup abelG)): lt_nG => // E [sEG _ oE].
by exists E; rewrite pnElemE // !inE oE sEG (abelemS sEG) /=.
Qed.
Lemma card_p1Elem p A X : X \in 'E_p^1(A) -> #|X| = p.
Proof. exact: card_pnElem. Qed.
Lemma p1ElemE p A : prime p -> 'E_p^1(A) = [set X in subgroups A | #|X| == p].
Proof.
move=> p_pr; apply/setP=> X; rewrite pnElemE // !inE -andbA; congr (_ && _).
by apply: andb_idl => /eqP oX; rewrite prime_abelem ?oX.
Qed.
Lemma TIp1ElemP p A X Y :
X \in 'E_p^1(A) -> Y \in 'E_p^1(A) -> reflect (X :&: Y = 1) (X :!=: Y).
Proof.
move=> EpX EpY; have p_pr := pnElem_prime EpX.
have [oX oY] := (card_p1Elem EpX, card_p1Elem EpY).
have [<-|] := eqVneq.
by right=> X1; rewrite -oX -(setIid X) X1 cards1 in p_pr.
by rewrite eqEcard oX oY leqnn andbT; left; rewrite prime_TIg ?oX.
Qed.
Lemma card_p1Elem_pnElem p n A E :
E \in 'E_p^n(A) -> #|'E_p^1(E)| = (\sum_(i < n) p ^ i)%N.
Proof.
case/pnElemP=> _ {A} abelE dimE; have [pE cEE _] := and3P abelE.
have [E1 | ntE] := eqsVneq E 1.
rewrite -dimE E1 cards1 logn1 big_ord0 eq_card0 // => X.
by rewrite !inE subG1 trivg_card1; case: eqP => // ->; rewrite logn1 andbF.
have [p_pr _ _] := pgroup_pdiv pE ntE; have p_gt1 := prime_gt1 p_pr.
apply/eqP; rewrite -(@eqn_pmul2l (p - 1)) ?subn_gt0 // subn1 -predn_exp.
have groupD1_inj: injective (fun X => (gval X)^#).
apply: can_inj (@generated_group _) _ => X.
by apply: val_inj; rewrite /= genD1 ?group1 ?genGid.
rewrite -dimE -card_pgroup // (cardsD1 1 E) group1 /= mulnC.
rewrite -(card_imset _ groupD1_inj) eq_sym.
apply/eqP; apply: card_uniform_partition => [X'|].
case/imsetP=> X; rewrite pnElemE // expn1 => /setIdP[_ /eqP <-] ->.
by rewrite (cardsD1 1 X) group1.
apply/and3P; split; last 1 first.
- apply/imsetP=> [[X /card_p1Elem oX X'0]].
by rewrite -oX (cardsD1 1) -X'0 group1 cards0 in p_pr.
- rewrite eqEsubset; apply/andP; split.
by apply/bigcupsP=> _ /imsetP[X /pnElemP[sXE _ _] ->]; apply: setSD.
apply/subsetP=> x /setD1P[ntx Ex].
apply/bigcupP; exists <[x]>^#; last by rewrite !inE ntx cycle_id.
apply/imsetP; exists <[x]>%G; rewrite ?p1ElemE // !inE cycle_subG Ex /=.
by rewrite -orderE (abelem_order_p abelE).
apply/trivIsetP=> _ _ /imsetP[X EpX ->] /imsetP[Y EpY ->]; apply/implyP.
rewrite (inj_eq groupD1_inj) -setI_eq0 -setDIl setD_eq0 subG1.
by rewrite (sameP eqP (TIp1ElemP EpX EpY)) implybb.
Qed.
Lemma card_p1Elem_p2Elem p A E : E \in 'E_p^2(A) -> #|'E_p^1(E)| = p.+1.
Proof. by move/card_p1Elem_pnElem->; rewrite big_ord_recl big_ord1. Qed.
Lemma p2Elem_dprodP p A E X Y :
E \in 'E_p^2(A) -> X \in 'E_p^1(E) -> Y \in 'E_p^1(E) ->
reflect (X \x Y = E) (X :!=: Y).
Proof.
move=> Ep2E EpX EpY; have [_ abelE oE] := pnElemPcard Ep2E.
apply: (iffP (TIp1ElemP EpX EpY)) => [tiXY|]; last by case/dprodP.
have [[sXE _ oX] [sYE _ oY]] := (pnElemPcard EpX, pnElemPcard EpY).
rewrite dprodE ?(sub_abelian_cent2 (abelem_abelian abelE)) //.
by apply/eqP; rewrite eqEcard mul_subG //= TI_cardMg // oX oY oE.
Qed.
Lemma nElemP n G E : reflect (exists p, E \in 'E_p^n(G)) (E \in 'E^n(G)).
Proof.
rewrite ['E^n(G)]big_mkord.
apply: (iffP bigcupP) => [[[p /= _] _] | [p]]; first by exists p.
case: n => [|n EpnE]; first by rewrite pnElem0; exists ord0; rewrite ?pnElem0.
suffices lepG: p < #|G|.+1 by exists (Ordinal lepG).
have:= EpnE; rewrite pnElemE ?(pnElem_prime EpnE) // !inE -andbA ltnS.
case/and3P=> sEG _ oE; rewrite dvdn_leq // (dvdn_trans _ (cardSg sEG)) //.
by rewrite (eqP oE) dvdn_exp.
Qed.
Arguments nElemP {n G E}.
Lemma nElem0 G : 'E^0(G) = [set 1%G].
Proof.
apply/setP=> E; apply/nElemP/idP=> [[p] |]; first by rewrite pnElem0.
by exists 2; rewrite pnElem0.
Qed.
Lemma nElem1P G E :
reflect (E \subset G /\ exists2 p, prime p & #|E| = p) (E \in 'E^1(G)).
Proof.
apply: (iffP nElemP) => [[p pE] | [sEG [p p_pr oE]]].
have p_pr := pnElem_prime pE; rewrite pnElemE // !inE -andbA in pE.
by case/and3P: pE => -> _ /eqP; split; last exists p.
exists p; rewrite pnElemE // !inE sEG oE eqxx abelemE // -oE exponent_dvdn.
by rewrite cyclic_abelian // prime_cyclic // oE.
Qed.
Lemma nElemS n G H : G \subset H -> 'E^n(G) \subset 'E^n(H).
Proof.
move=> sGH; apply/subsetP=> E /nElemP[p EpnG_E].
by apply/nElemP; exists p; rewrite // (subsetP (pnElemS _ _ sGH)).
Qed.
Lemma nElemI n G H : 'E^n(G :&: H) = 'E^n(G) :&: subgroups H.
Proof.
apply/setP=> E; apply/nElemP/setIP=> [[p] | []].
by rewrite pnElemI; case/setIP; split=> //; apply/nElemP; exists p.
by case/nElemP=> p EpnG_E sHE; exists p; rewrite pnElemI inE EpnG_E.
Qed.
Lemma def_pnElem p n G : 'E_p^n(G) = 'E_p(G) :&: 'E^n(G).
Proof.
apply/setP=> E; rewrite inE in_setI; apply: andb_id2l => /pElemP[sEG abelE].
apply/idP/nElemP=> [|[q]]; first by exists p; rewrite !inE sEG abelE.
rewrite !inE -2!andbA => /and4P[_ /pgroupP qE _].
have [->|] := eqVneq E 1%G; first by rewrite cards1 !logn1.
case/(pgroup_pdiv (abelem_pgroup abelE)) => p_pr pE _.
by rewrite (eqnP (qE p p_pr pE)).
Qed.
Lemma pmaxElemP p A E :
reflect (E \in 'E_p(A) /\ forall H, H \in 'E_p(A) -> E \subset H -> H :=: E)
(E \in 'E*_p(A)).
Proof. by rewrite [E \in 'E*_p(A)]inE; apply: (iffP maxgroupP). Qed.
Lemma pmaxElem_exists p A D :
D \in 'E_p(A) -> {E | E \in 'E*_p(A) & D \subset E}.
Proof.
move=> EpD; have [E maxE sDE] := maxgroup_exists (EpD : mem 'E_p(A) D).
by exists E; rewrite // inE.
Qed.
Lemma pmaxElem_LdivP p G E :
prime p -> reflect ('Ldiv_p('C_G(E)) = E) (E \in 'E*_p(G)).
Proof.
move=> p_pr; apply: (iffP (pmaxElemP p G E)) => [[] | defE].
case/pElemP=> sEG abelE maxE; have [_ cEE eE] := and3P abelE.
apply/setP=> x; rewrite !inE -andbA; apply/and3P/idP=> [[Gx cEx xp] | Ex].
rewrite -(maxE (<[x]> <*> E)%G) ?joing_subr //.
by rewrite -cycle_subG joing_subl.
rewrite inE join_subG cycle_subG Gx sEG /=.
rewrite (cprod_abelem _ (cprodEY _)); last by rewrite centsC cycle_subG.
by rewrite cycle_abelem ?p_pr ?orbT // order_dvdn xp.
by rewrite (subsetP sEG) // (subsetP cEE) // (exponentP eE).
split=> [|H]; last first.
case/pElemP=> sHG /abelemP[// | cHH Hp1] sEH.
apply/eqP; rewrite eqEsubset sEH andbC /= -defE; apply/subsetP=> x Hx.
by rewrite 3!inE (subsetP sHG) // Hp1 ?(subsetP (centsS _ cHH)) /=.
apply/pElemP; split; first by rewrite -defE -setIA subsetIl.
apply/abelemP=> //; rewrite /abelian -{1 3}defE setIAC subsetIr.
by split=> //; apply/exponentP; rewrite -sub_LdivT setIAC subsetIr.
Qed.
Lemma pmaxElemS p A B :
A \subset B -> 'E*_p(B) :&: subgroups A \subset 'E*_p(A).
Proof.
move=> sAB; apply/subsetP=> E /[!inE].
case/andP=> /maxgroupP[/pElemP[_ abelE] maxE] sEA.
apply/maxgroupP; rewrite inE sEA; split=> // D EpD.
by apply: maxE; apply: subsetP EpD; apply: pElemS.
Qed.
Lemma pmaxElemJ p A E x : ((E :^ x)%G \in 'E*_p(A :^ x)) = (E \in 'E*_p(A)).
Proof.
apply/pmaxElemP/pmaxElemP=> [] [EpE maxE].
rewrite pElemJ in EpE; split=> //= H EpH sEH; apply: (act_inj 'Js x).
by apply: maxE; rewrite ?conjSg ?pElemJ.
rewrite pElemJ; split=> // H; rewrite -(actKV 'JG x H) pElemJ conjSg => EpHx'.
by move/maxE=> /= ->.
Qed.
Lemma grank_min B : 'm(<<B>>) <= #|B|.
Proof.
by rewrite /gen_rank; case: arg_minnP => [|_ _ -> //]; rewrite genGid.
Qed.
Lemma grank_witness G : {B | <<B>> = G & #|B| = 'm(G)}.
Proof.
rewrite /gen_rank; case: arg_minnP => [|B defG _]; first by rewrite genGid.
by exists B; first apply/eqP.
Qed.
Lemma p_rank_witness p G : {E | E \in 'E_p^('r_p(G))(G)}.
Proof.
have [E EG_E mE]: {E | E \in 'E_p(G) & 'r_p(G) = logn p #|E| }.
by apply: eq_bigmax_cond; rewrite (cardD1 1%G) inE sub1G abelem1.
by exists E; rewrite inE EG_E -mE /=.
Qed.
Lemma p_rank_geP p n G : reflect (exists E, E \in 'E_p^n(G)) (n <= 'r_p(G)).
Proof.
apply: (iffP idP) => [|[E]]; last first.
by rewrite inE => /andP[Ep_E /eqP <-]; rewrite (bigmax_sup E).
have [D /pnElemP[sDG abelD <-]] := p_rank_witness p G.
by case/abelem_pnElem=> // E; exists E; apply: (subsetP (pnElemS _ _ sDG)).
Qed.
Lemma p_rank_gt0 p H : ('r_p(H) > 0) = (p \in \pi(H)).
Proof.
rewrite mem_primes cardG_gt0 /=; apply/p_rank_geP/andP=> [[E] | [p_pr]].
case/pnElemP=> sEG _; rewrite lognE; case: and3P => // [[-> _ pE] _].
by rewrite (dvdn_trans _ (cardSg sEG)).
case/Cauchy=> // x Hx ox; exists <[x]>%G; rewrite 2!inE [#|_|]ox cycle_subG.
by rewrite Hx (pfactorK 1) ?abelemE // cycle_abelian -ox exponent_dvdn.
Qed.
Lemma p_rank1 p : 'r_p([1 gT]) = 0.
Proof. by apply/eqP; rewrite eqn0Ngt p_rank_gt0 /= cards1. Qed.
Lemma logn_le_p_rank p A E : E \in 'E_p(A) -> logn p #|E| <= 'r_p(A).
Proof. by move=> EpA_E; rewrite (bigmax_sup E). Qed.
Lemma p_rank_le_logn p G : 'r_p(G) <= logn p #|G|.
Proof.
have [E EpE] := p_rank_witness p G.
by have [sEG _ <-] := pnElemP EpE; apply: lognSg.
Qed.
Lemma p_rank_abelem p G : p.-abelem G -> 'r_p(G) = logn p #|G|.
Proof.
move=> abelG; apply/eqP; rewrite eqn_leq andbC (bigmax_sup G)//.
by apply/bigmax_leqP=> E /[1!inE] /andP[/lognSg->].
by rewrite inE subxx.
Qed.
Lemma p_rankS p A B : A \subset B -> 'r_p(A) <= 'r_p(B).
Proof.
move=> sAB; apply/bigmax_leqP=> E /(subsetP (pElemS p sAB)) EpB_E.
by rewrite (bigmax_sup E).
Qed.
Lemma p_rankElem_max p A : 'E_p^('r_p(A))(A) \subset 'E*_p(A).
Proof.
apply/subsetP=> E /setIdP[EpE dimE].
apply/pmaxElemP; split=> // F EpF sEF; apply/eqP.
have pF: p.-group F by case/pElemP: EpF => _ /and3P[].
have pE: p.-group E by case/pElemP: EpE => _ /and3P[].
rewrite eq_sym eqEcard sEF dvdn_leq // (card_pgroup pE) (card_pgroup pF).
by rewrite (eqP dimE) dvdn_exp2l // logn_le_p_rank.
Qed.
Lemma p_rankJ p A x : 'r_p(A :^ x) = 'r_p(A).
Proof.
rewrite /p_rank (reindex_inj (act_inj 'JG x)).
by apply: eq_big => [E | E _]; rewrite ?cardJg ?pElemJ.
Qed.
Lemma p_rank_Sylow p G H : p.-Sylow(G) H -> 'r_p(H) = 'r_p(G).
Proof.
move=> sylH; apply/eqP; rewrite eqn_leq (p_rankS _ (pHall_sub sylH)) /=.
apply/bigmax_leqP=> E /[1!inE] /andP[sEG abelE].
have [P sylP sEP] := Sylow_superset sEG (abelem_pgroup abelE).
have [x _ ->] := Sylow_trans sylP sylH.
by rewrite p_rankJ -(p_rank_abelem abelE) (p_rankS _ sEP).
Qed.
Lemma p_rank_Hall pi p G H : pi.-Hall(G) H -> p \in pi -> 'r_p(H) = 'r_p(G).
Proof.
move=> hallH pi_p; have [P sylP] := Sylow_exists p H.
by rewrite -(p_rank_Sylow sylP) (p_rank_Sylow (subHall_Sylow hallH pi_p sylP)).
Qed.
Lemma p_rank_pmaxElem_exists p r G :
'r_p(G) >= r -> exists2 E, E \in 'E*_p(G) & 'r_p(E) >= r.
Proof.
case/p_rank_geP=> D /setIdP[EpD /eqP <- {r}].
have [E EpE sDE] := pmaxElem_exists EpD; exists E => //.
case/pmaxElemP: EpE => /setIdP[_ abelE] _.
by rewrite (p_rank_abelem abelE) lognSg.
Qed.
Lemma rank1 : 'r([1 gT]) = 0.
Proof. by rewrite ['r(1)]big1_seq // => p _; rewrite p_rank1. Qed.
Lemma p_rank_le_rank p G : 'r_p(G) <= 'r(G).
Proof.
case: (posnP 'r_p(G)) => [-> //|]; rewrite p_rank_gt0 mem_primes.
case/and3P=> p_pr _ pG; have lepg: p < #|G|.+1 by rewrite ltnS dvdn_leq.
by rewrite ['r(G)]big_mkord (bigmax_sup (Ordinal lepg)).
Qed.
Lemma rank_gt0 G : ('r(G) > 0) = (G :!=: 1).
Proof.
case: (eqsVneq G 1) => [-> |]; first by rewrite rank1.
case: (trivgVpdiv G) => [/eqP->// | [p p_pr]].
case/Cauchy=> // x Gx oxp _; apply: leq_trans (p_rank_le_rank p G).
have EpGx: <[x]>%G \in 'E_p(G).
by rewrite inE cycle_subG Gx abelemE // cycle_abelian -oxp exponent_dvdn.
by apply: leq_trans (logn_le_p_rank EpGx); rewrite -orderE oxp logn_prime ?eqxx.
Qed.
Lemma rank_witness G : {p | prime p & 'r(G) = 'r_p(G)}.
Proof.
have [p _ defmG]: {p : 'I_(#|G|.+1) | true & 'r(G) = 'r_p(G)}.
by rewrite ['r(G)]big_mkord; apply: eq_bigmax_cond; rewrite card_ord.
case: (eqsVneq G 1) => [-> | ]; first by exists 2; rewrite // rank1 p_rank1.
by rewrite -rank_gt0 defmG p_rank_gt0 mem_primes; case/andP; exists p.
Qed.
Lemma rank_pgroup p G : p.-group G -> 'r(G) = 'r_p(G).
Proof.
move=> pG; apply/eqP; rewrite eqn_leq p_rank_le_rank andbT.
rewrite ['r(G)]big_mkord; apply/bigmax_leqP=> [[q /= _] _].
case: (posnP 'r_q(G)) => [-> // |]; rewrite p_rank_gt0 mem_primes.
by case/and3P=> q_pr _ qG; rewrite (eqnP (pgroupP pG q q_pr qG)).
Qed.
Lemma rank_Sylow p G P : p.-Sylow(G) P -> 'r(P) = 'r_p(G).
Proof.
move=> sylP; have pP := pHall_pgroup sylP.
by rewrite -(p_rank_Sylow sylP) -(rank_pgroup pP).
Qed.
Lemma rank_abelem p G : p.-abelem G -> 'r(G) = logn p #|G|.
Proof.
by move=> abelG; rewrite (rank_pgroup (abelem_pgroup abelG)) p_rank_abelem.
Qed.
Lemma nt_pnElem p n E A : E \in 'E_p^n(A) -> n > 0 -> E :!=: 1.
Proof. by case/pnElemP=> _ /rank_abelem <- <-; rewrite rank_gt0. Qed.
Lemma rankJ A x : 'r(A :^ x) = 'r(A).
Proof. by rewrite /rank cardJg; apply: eq_bigr => p _; rewrite p_rankJ. Qed.
Lemma rankS A B : A \subset B -> 'r(A) <= 'r(B).
Proof.
move=> sAB; rewrite /rank !big_mkord; apply/bigmax_leqP=> p _.
have leAB: #|A| < #|B|.+1 by rewrite ltnS subset_leq_card.
by rewrite (bigmax_sup (widen_ord leAB p)) ?p_rankS.
Qed.
Lemma rank_geP n G : reflect (exists E, E \in 'E^n(G)) (n <= 'r(G)).
Proof.
apply: (iffP idP) => [|[E]].
have [p _ ->] := rank_witness G; case/p_rank_geP=> E.
by rewrite def_pnElem; case/setIP; exists E.
case/nElemP=> p /[1!inE] /andP[EpG_E /eqP <-].
by rewrite (leq_trans (logn_le_p_rank EpG_E)) ?p_rank_le_rank.
Qed.
End ExponentAbelem.
Arguments LdivP {gT A n x}.
Arguments exponentP {gT A n}.
Arguments abelemP {gT p G}.
Arguments is_abelemP {gT G}.
Arguments pElemP {gT p A E}.
Arguments pnElemP {gT p n A E}.
Arguments nElemP {gT n G E}.
Arguments nElem1P {gT G E}.
Arguments pmaxElemP {gT p A E}.
Arguments pmaxElem_LdivP {gT p G E}.
Arguments p_rank_geP {gT p n G}.
Arguments rank_geP {gT n G}.
Section MorphAbelem.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Types (G H E : {group aT}) (A B : {set aT}).
Lemma exponent_morphim G : exponent (f @* G) %| exponent G.
Proof.
apply/exponentP=> _ /morphimP[x Dx Gx ->].
by rewrite -morphX // expg_exponent // morph1.
Qed.
Lemma morphim_LdivT n : f @* 'Ldiv_n() \subset 'Ldiv_n().
Proof.
apply/subsetP=> _ /morphimP[x Dx xn ->]; rewrite inE in xn.
by rewrite inE -morphX // (eqP xn) morph1.
Qed.
Lemma morphim_Ldiv n A : f @* 'Ldiv_n(A) \subset 'Ldiv_n(f @* A).
Proof.
by apply: subset_trans (morphimI f A _) (setIS _ _); apply: morphim_LdivT.
Qed.
Lemma morphim_abelem p G : p.-abelem G -> p.-abelem (f @* G).
Proof.
case: (eqsVneq G 1) => [-> | ntG] abelG; first by rewrite morphim1 abelem1.
have [p_pr _ _] := pgroup_pdiv (abelem_pgroup abelG) ntG.
case/abelemP: abelG => // abG elemG; apply/abelemP; rewrite ?morphim_abelian //.
by split=> // _ /morphimP[x Dx Gx ->]; rewrite -morphX // elemG ?morph1.
Qed.
Lemma morphim_pElem p G E : E \in 'E_p(G) -> (f @* E)%G \in 'E_p(f @* G).
Proof.
by rewrite !inE => /andP[sEG abelE]; rewrite morphimS // morphim_abelem.
Qed.
Lemma morphim_pnElem p n G E :
E \in 'E_p^n(G) -> {m | m <= n & (f @* E)%G \in 'E_p^m(f @* G)}.
Proof.
rewrite inE => /andP[EpE /eqP <-].
by exists (logn p #|f @* E|); rewrite ?logn_morphim // inE morphim_pElem /=.
Qed.
Lemma morphim_grank G : G \subset D -> 'm(f @* G) <= 'm(G).
Proof.
have [B defG <-] := grank_witness G; rewrite -defG gen_subG => sBD.
by rewrite morphim_gen ?morphimEsub ?(leq_trans (grank_min _)) ?leq_imset_card.
Qed.
(* There are no general morphism relations for the p-rank. We later prove *)
(* some relations for the p-rank of a quotient in the QuotientAbelem section. *)
End MorphAbelem.
Section InjmAbelem.
Variables (aT rT : finGroupType) (D G : {group aT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D).
Let defG : invm injf @* (f @* G) = G := morphim_invm injf sGD.
Lemma exponent_injm : exponent (f @* G) = exponent G.
Proof. by apply/eqP; rewrite eqn_dvd -{3}defG !exponent_morphim. Qed.
Lemma injm_Ldiv n A : f @* 'Ldiv_n(A) = 'Ldiv_n(f @* A).
Proof.
apply/eqP; rewrite eqEsubset morphim_Ldiv.
rewrite -[f @* 'Ldiv_n(A)](morphpre_invm injf).
rewrite -sub_morphim_pre; last by rewrite subIset ?morphim_sub.
rewrite injmI ?injm_invm // setISS ?morphim_LdivT //.
by rewrite sub_morphim_pre ?morphim_sub // morphpre_invm.
Qed.
Lemma injm_abelem p : p.-abelem (f @* G) = p.-abelem G.
Proof. by apply/idP/idP; first rewrite -{2}defG; apply: morphim_abelem. Qed.
Lemma injm_pElem p (E : {group aT}) :
E \subset D -> ((f @* E)%G \in 'E_p(f @* G)) = (E \in 'E_p(G)).
Proof.
move=> sED; apply/idP/idP=> EpE; last exact: morphim_pElem.
by rewrite -defG -(group_inj (morphim_invm injf sED)) morphim_pElem.
Qed.
Lemma injm_pnElem p n (E : {group aT}) :
E \subset D -> ((f @* E)%G \in 'E_p^n(f @* G)) = (E \in 'E_p^n(G)).
Proof. by move=> sED; rewrite inE injm_pElem // card_injm ?inE. Qed.
Lemma injm_nElem n (E : {group aT}) :
E \subset D -> ((f @* E)%G \in 'E^n(f @* G)) = (E \in 'E^n(G)).
Proof.
move=> sED; apply/nElemP/nElemP=> [] [p EpE];
by exists p; rewrite injm_pnElem in EpE *.
Qed.
Lemma injm_pmaxElem p (E : {group aT}) :
E \subset D -> ((f @* E)%G \in 'E*_p(f @* G)) = (E \in 'E*_p(G)).
Proof.
move=> sED; have defE := morphim_invm injf sED.
apply/pmaxElemP/pmaxElemP=> [] [EpE maxE].
split=> [|H EpH sEH]; first by rewrite injm_pElem in EpE.
have sHD: H \subset D by apply: subset_trans (sGD); case/pElemP: EpH.
by rewrite -(morphim_invm injf sHD) [f @* H]maxE ?morphimS ?injm_pElem.
rewrite injm_pElem //; split=> // fH Ep_fH sfEH; have [sfHG _] := pElemP Ep_fH.
have sfHD : fH \subset f @* D by rewrite (subset_trans sfHG) ?morphimS.
rewrite -(morphpreK sfHD); congr (f @* _).
rewrite [_ @*^-1 fH]maxE -?sub_morphim_pre //.
by rewrite -injm_pElem ?subsetIl // (group_inj (morphpreK sfHD)).
Qed.
Lemma injm_grank : 'm(f @* G) = 'm(G).
Proof. by apply/eqP; rewrite eqn_leq -{3}defG !morphim_grank ?morphimS. Qed.
Lemma injm_p_rank p : 'r_p(f @* G) = 'r_p(G).
Proof.
apply/eqP; rewrite eqn_leq; apply/andP; split.
have [fE] := p_rank_witness p (f @* G); move: 'r_p(_) => n Ep_fE.
apply/p_rank_geP; exists (f @*^-1 fE)%G.
rewrite -injm_pnElem ?subsetIl ?(group_inj (morphpreK _)) //.
by case/pnElemP: Ep_fE => sfEG _ _; rewrite (subset_trans sfEG) ?morphimS.
have [E] := p_rank_witness p G; move: 'r_p(_) => n EpE.
apply/p_rank_geP; exists (f @* E)%G; rewrite injm_pnElem //.
by case/pnElemP: EpE => sEG _ _; rewrite (subset_trans sEG).
Qed.
Lemma injm_rank : 'r(f @* G) = 'r(G).
Proof.
apply/eqP; rewrite eqn_leq; apply/andP; split.
by have [p _ ->] := rank_witness (f @* G); rewrite injm_p_rank p_rank_le_rank.
by have [p _ ->] := rank_witness G; rewrite -injm_p_rank p_rank_le_rank.
Qed.
End InjmAbelem.
Section IsogAbelem.
Variables (aT rT : finGroupType) (G : {group aT}) (H : {group rT}).
Hypothesis isoGH : G \isog H.
Lemma exponent_isog : exponent G = exponent H.
Proof. by case/isogP: isoGH => f injf <-; rewrite exponent_injm. Qed.
Lemma isog_abelem p : p.-abelem G = p.-abelem H.
Proof. by case/isogP: isoGH => f injf <-; rewrite injm_abelem. Qed.
Lemma isog_grank : 'm(G) = 'm(H).
Proof. by case/isogP: isoGH => f injf <-; rewrite [RHS]injm_grank. Qed.
Lemma isog_p_rank p : 'r_p(G) = 'r_p(H).
Proof. by case/isogP: isoGH => f injf <-; rewrite injm_p_rank. Qed.
Lemma isog_rank : 'r(G) = 'r(H).
Proof. by case/isogP: isoGH => f injf <-; rewrite injm_rank. Qed.
End IsogAbelem.
Section QuotientAbelem.
Variables (gT : finGroupType) (p : nat).
Implicit Types E G K H : {group gT}.
Lemma exponent_quotient G H : exponent (G / H) %| exponent G.
Proof. exact: exponent_morphim. Qed.
Lemma quotient_LdivT n H : 'Ldiv_n() / H \subset 'Ldiv_n().
Proof. exact: morphim_LdivT. Qed.
Lemma quotient_Ldiv n A H : 'Ldiv_n(A) / H \subset 'Ldiv_n(A / H).
Proof. exact: morphim_Ldiv. Qed.
Lemma quotient_abelem G H : p.-abelem G -> p.-abelem (G / H).
Proof. exact: morphim_abelem. Qed.
Lemma quotient_pElem G H E : E \in 'E_p(G) -> (E / H)%G \in 'E_p(G / H).
Proof. exact: morphim_pElem. Qed.
Lemma logn_quotient G H : logn p #|G / H| <= logn p #|G|.
Proof. exact: logn_morphim. Qed.
Lemma quotient_pnElem G H n E :
E \in 'E_p^n(G) -> {m | m <= n & (E / H)%G \in 'E_p^m(G / H)}.
Proof. exact: morphim_pnElem. Qed.
Lemma quotient_grank G H : G \subset 'N(H) -> 'm(G / H) <= 'm(G).
Proof. exact: morphim_grank. Qed.
Lemma p_rank_quotient G H : G \subset 'N(H) -> 'r_p(G) - 'r_p(H) <= 'r_p(G / H).
Proof.
move=> nHG; rewrite leq_subLR.
have [E EpE] := p_rank_witness p G; have{EpE} [sEG abelE <-] := pnElemP EpE.
rewrite -(LagrangeI E H) lognM ?cardG_gt0 //.
rewrite -card_quotient ?(subset_trans sEG) // leq_add ?logn_le_p_rank // !inE.
by rewrite subsetIr (abelemS (subsetIl E H)).
by rewrite quotientS ?quotient_abelem.
Qed.
Lemma p_rank_dprod K H G : K \x H = G -> 'r_p(K) + 'r_p(H) = 'r_p(G).
Proof.
move=> defG; apply/eqP; rewrite eqn_leq -leq_subLR andbC.
have [_ defKH cKH tiKH] := dprodP defG; have nKH := cents_norm cKH.
rewrite {1}(isog_p_rank (quotient_isog nKH tiKH)) /= -quotientMidl defKH.
rewrite p_rank_quotient; last by rewrite -defKH mul_subG ?normG.
have [[E EpE] [F EpF]] := (p_rank_witness p K, p_rank_witness p H).
have [[sEK abelE <-] [sFH abelF <-]] := (pnElemP EpE, pnElemP EpF).
have defEF: E \x F = E <*> F.
by rewrite dprodEY ?(centSS sFH sEK) //; apply/trivgP; rewrite -tiKH setISS.
apply/p_rank_geP; exists (E <*> F)%G; rewrite !inE (dprod_abelem p defEF).
rewrite -lognM ?cargG_gt0 // (dprod_card defEF) abelE abelF eqxx.
by rewrite -(genGid G) -defKH genM_join genS ?setUSS.
Qed.
Lemma p_rank_p'quotient G H :
(p : nat)^'.-group H -> G \subset 'N(H) -> 'r_p(G / H) = 'r_p(G).
Proof.
move=> p'H nHG; have [P sylP] := Sylow_exists p G.
have [sPG pP _] := and3P sylP; have nHP := subset_trans sPG nHG.
have tiHP: H :&: P = 1 := coprime_TIg (p'nat_coprime p'H pP).
rewrite -(p_rank_Sylow sylP) -(p_rank_Sylow (quotient_pHall nHP sylP)).
by rewrite (isog_p_rank (quotient_isog nHP tiHP)).
Qed.
End QuotientAbelem.
Section OhmProps.
Section Generic.
Variables (n : nat) (gT : finGroupType).
Implicit Types (p : nat) (x : gT) (rT : finGroupType).
Implicit Types (A B : {set gT}) (D G H : {group gT}).
Lemma Ohm_sub G : 'Ohm_n(G) \subset G.
Proof. by rewrite gen_subG; apply/subsetP=> x /setIdP[]. Qed.
Lemma Ohm1 : 'Ohm_n([1 gT]) = 1. Proof. exact: (trivgP (Ohm_sub _)). Qed.
Lemma Ohm_id G : 'Ohm_n('Ohm_n(G)) = 'Ohm_n(G).
Proof.
apply/eqP; rewrite eqEsubset Ohm_sub genS //.
by apply/subsetP=> x /setIdP[Gx oxn]; rewrite inE mem_gen // inE Gx.
Qed.
Lemma Ohm_cont rT G (f : {morphism G >-> rT}) :
f @* 'Ohm_n(G) \subset 'Ohm_n(f @* G).
Proof.
rewrite morphim_gen ?genS //; last by rewrite -gen_subG Ohm_sub.
apply/subsetP=> fx /morphimP[x Gx]; rewrite inE Gx /=.
case/OhmPredP=> p p_pr xpn_1 -> {fx}.
rewrite inE morphimEdom imset_f //=; apply/OhmPredP; exists p => //.
by rewrite -morphX // xpn_1 morph1.
Qed.
Lemma OhmS H G : H \subset G -> 'Ohm_n(H) \subset 'Ohm_n(G).
Proof.
move=> sHG; apply: genS; apply/subsetP=> x /[!inE] /andP[Hx ->].
by rewrite (subsetP sHG).
Qed.
Lemma OhmE p G : p.-group G -> 'Ohm_n(G) = <<'Ldiv_(p ^ n)(G)>>.
Proof.
move=> pG; congr <<_>>; apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
have [-> | ntx] := eqVneq x 1; first by rewrite !expg1n.
by rewrite (pdiv_p_elt (mem_p_elt pG Gx)).
Qed.
Lemma OhmEabelian p G :
p.-group G -> abelian 'Ohm_n(G) -> 'Ohm_n(G) = 'Ldiv_(p ^ n)(G).
Proof.
move=> pG; rewrite (OhmE pG) abelian_gen => cGGn; rewrite gen_set_id //.
rewrite -(setIidPr (subset_gen 'Ldiv_(p ^ n)(G))) setIA.
by rewrite [_ :&: G](setIidPl _) ?gen_subG ?subsetIl // group_Ldiv ?abelian_gen.
Qed.
Lemma Ohm_p_cycle p x :
p.-elt x -> 'Ohm_n(<[x]>) = <[x ^+ (p ^ (logn p #[x] - n))]>.
Proof.
move=> p_x; apply/eqP; rewrite (OhmE p_x) eqEsubset cycle_subG mem_gen.
rewrite gen_subG andbT; apply/subsetP=> y /LdivP[x_y ypn].
case: (leqP (logn p #[x]) n) => [|lt_n_x].
by rewrite -subn_eq0 => /eqP->.
have p_pr: prime p by move: lt_n_x; rewrite lognE; case: (prime p).
have def_y: <[y]> = <[x ^+ (#[x] %/ #[y])]>.
apply: congr_group; apply/set1P.
by rewrite -cycle_sub_group ?cardSg ?inE ?cycle_subG ?x_y /=.
rewrite -cycle_subG def_y cycle_subG -{1}(part_pnat_id p_x) p_part.
rewrite -{1}(subnK (ltnW lt_n_x)) expnD -muln_divA ?order_dvdn ?ypn //.
by rewrite expgM mem_cycle.
rewrite !inE mem_cycle -expgM -expnD addnC -maxnE -order_dvdn.
by rewrite -{1}(part_pnat_id p_x) p_part dvdn_exp2l ?leq_maxr.
Qed.
Lemma Ohm_dprod A B G : A \x B = G -> 'Ohm_n(A) \x 'Ohm_n(B) = 'Ohm_n(G).
Proof.
case/dprodP => [[H K -> ->{A B}]] <- cHK tiHK.
rewrite dprodEY //; last first.
- by apply/trivgP; rewrite -tiHK setISS ?Ohm_sub.
- by rewrite (subset_trans (subset_trans _ cHK)) ?centS ?Ohm_sub.
apply/eqP; rewrite -(cent_joinEr cHK) eqEsubset join_subG /=.
rewrite !OhmS ?joing_subl ?joing_subr //= cent_joinEr //= -genM_join genS //.
apply/subsetP=> _ /setIdP[/imset2P[x y Hx Ky ->] /OhmPredP[p p_pr /eqP]].
have cxy: commute x y by red; rewrite -(centsP cHK).
rewrite ?expgMn // -eq_invg_mul => /eqP def_x.
have ypn1: y ^+ (p ^ n) = 1.
by apply/set1P; rewrite -[[set 1]]tiHK inE -{1}def_x groupV !groupX.
have xpn1: x ^+ (p ^ n) = 1 by rewrite -[x ^+ _]invgK def_x ypn1 invg1.
by rewrite mem_mulg ?mem_gen // inE (Hx, Ky); apply/OhmPredP; exists p.
Qed.
Lemma Mho_sub G : 'Mho^n(G) \subset G.
Proof.
rewrite gen_subG; apply/subsetP=> _ /imsetP[x /setIdP[Gx _] ->].
exact: groupX.
Qed.
Lemma Mho1 : 'Mho^n([1 gT]) = 1. Proof. exact: (trivgP (Mho_sub _)). Qed.
Lemma morphim_Mho rT D G (f : {morphism D >-> rT}) :
G \subset D -> f @* 'Mho^n(G) = 'Mho^n(f @* G).
Proof.
move=> sGD; have sGnD := subset_trans (Mho_sub G) sGD.
apply/eqP; rewrite eqEsubset {1}morphim_gen -1?gen_subG // !gen_subG.
apply/andP; split; apply/subsetP=> y.
case/morphimP=> xpn _ /imsetP[x /setIdP[Gx]].
set p := pdiv _ => p_x -> -> {xpn y}; have Dx := subsetP sGD x Gx.
by rewrite morphX // Mho_p_elt ?morph_p_elt ?mem_morphim.
case/imsetP=> _ /setIdP[/morphimP[x Dx Gx ->]].
set p := pdiv _ => p_fx ->{y}; rewrite -(constt_p_elt p_fx) -morph_constt //.
by rewrite -morphX ?mem_morphim ?Mho_p_elt ?groupX ?p_elt_constt.
Qed.
Lemma Mho_cont rT G (f : {morphism G >-> rT}) :
f @* 'Mho^n(G) \subset 'Mho^n(f @* G).
Proof. by rewrite morphim_Mho. Qed.
Lemma MhoS H G : H \subset G -> 'Mho^n(H) \subset 'Mho^n(G).
Proof.
move=> sHG; apply: genS; apply: imsetS; apply/subsetP=> x.
by rewrite !inE => /andP[Hx]; rewrite (subsetP sHG).
Qed.
Lemma MhoE p G : p.-group G -> 'Mho^n(G) = <<[set x ^+ (p ^ n) | x in G]>>.
Proof.
move=> pG; apply/eqP; rewrite eqEsubset !gen_subG; apply/andP.
do [split; apply/subsetP=> xpn; case/imsetP=> x] => [|Gx ->]; last first.
by rewrite Mho_p_elt ?(mem_p_elt pG).
case/setIdP=> Gx _ ->; have [-> | ntx] := eqVneq x 1; first by rewrite expg1n.
by rewrite (pdiv_p_elt (mem_p_elt pG Gx) ntx) mem_gen //; apply: imset_f.
Qed.
Lemma MhoEabelian p G :
p.-group G -> abelian G -> 'Mho^n(G) = [set x ^+ (p ^ n) | x in G].
Proof.
move=> pG cGG; rewrite (MhoE pG); rewrite gen_set_id //; apply/group_setP.
split=> [|xn yn]; first by apply/imsetP; exists 1; rewrite ?expg1n.
case/imsetP=> x Gx ->; case/imsetP=> y Gy ->.
by rewrite -expgMn; [apply: imset_f; rewrite groupM | apply: (centsP cGG)].
Qed.
Lemma trivg_Mho G : 'Mho^n(G) == 1 -> 'Ohm_n(G) == G.
Proof.
rewrite -subG1 gen_subG eqEsubset Ohm_sub /= => Gp1.
rewrite -{1}(Sylow_gen G) genS //; apply/bigcupsP=> P.
case/SylowP=> p p_pr /and3P[sPG pP _]; apply/subsetP=> x Px.
have Gx := subsetP sPG x Px; rewrite inE Gx //=.
rewrite (sameP eqP set1P) (subsetP Gp1) ?mem_gen //; apply: imset_f.
by rewrite inE Gx; apply: pgroup_p (mem_p_elt pP Px).
Qed.
Lemma Mho_p_cycle p x : p.-elt x -> 'Mho^n(<[x]>) = <[x ^+ (p ^ n)]>.
Proof.
move=> p_x.
apply/eqP; rewrite (MhoE p_x) eqEsubset cycle_subG mem_gen; last first.
by apply: imset_f; apply: cycle_id.
rewrite gen_subG andbT; apply/subsetP=> _ /imsetP[_ /cycleP[k ->] ->].
by rewrite -expgM mulnC expgM mem_cycle.
Qed.
Lemma Mho_cprod A B G : A \* B = G -> 'Mho^n(A) \* 'Mho^n(B) = 'Mho^n(G).
Proof.
case/cprodP => [[H K -> ->{A B}]] <- cHK; rewrite cprodEY //; last first.
by rewrite (subset_trans (subset_trans _ cHK)) ?centS ?Mho_sub.
apply/eqP; rewrite -(cent_joinEr cHK) eqEsubset join_subG /=.
rewrite !MhoS ?joing_subl ?joing_subr //= cent_joinEr // -genM_join.
apply: genS; apply/subsetP=> xypn /imsetP[_ /setIdP[/imset2P[x y Hx Ky ->]]].
move/constt_p_elt; move: (pdiv _) => p <- ->.
have cxy: commute x y by red; rewrite -(centsP cHK).
rewrite consttM // expgMn; last exact: commuteX2.
by rewrite mem_mulg ?Mho_p_elt ?groupX ?p_elt_constt.
Qed.
Lemma Mho_dprod A B G : A \x B = G -> 'Mho^n(A) \x 'Mho^n(B) = 'Mho^n(G).
Proof.
case/dprodP => [[H K -> ->{A B}]] defG cHK tiHK.
rewrite dprodEcp; first by apply: Mho_cprod; rewrite cprodE.
by apply/trivgP; rewrite -tiHK setISS ?Mho_sub.
Qed.
End Generic.
Canonical Ohm_igFun i := [igFun by Ohm_sub i & Ohm_cont i].
Canonical Ohm_gFun i := [gFun by Ohm_cont i].
Canonical Ohm_mgFun i := [mgFun by OhmS i].
Canonical Mho_igFun i := [igFun by Mho_sub i & Mho_cont i].
Canonical Mho_gFun i := [gFun by Mho_cont i].
Canonical Mho_mgFun i := [mgFun by MhoS i].
Section char.
Variables (n : nat) (gT rT : finGroupType) (D G : {group gT}).
Lemma Ohm_char : 'Ohm_n(G) \char G. Proof. exact: gFchar. Qed.
Lemma Ohm_normal : 'Ohm_n(G) <| G. Proof. exact: gFnormal. Qed.
Lemma Mho_char : 'Mho^n(G) \char G. Proof. exact: gFchar. Qed.
Lemma Mho_normal : 'Mho^n(G) <| G. Proof. exact: gFnormal. Qed.
Lemma morphim_Ohm (f : {morphism D >-> rT}) :
G \subset D -> f @* 'Ohm_n(G) \subset 'Ohm_n(f @* G).
Proof. exact: morphimF. Qed.
Lemma injm_Ohm (f : {morphism D >-> rT}) :
'injm f -> G \subset D -> f @* 'Ohm_n(G) = 'Ohm_n(f @* G).
Proof. by move=> injf; apply: injmF. Qed.
Lemma isog_Ohm (H : {group rT}) : G \isog H -> 'Ohm_n(G) \isog 'Ohm_n(H).
Proof. exact: gFisog. Qed.
Lemma isog_Mho (H : {group rT}) : G \isog H -> 'Mho^n(G) \isog 'Mho^n(H).
Proof. exact: gFisog. Qed.
End char.
Variable gT : finGroupType.
Implicit Types (pi : nat_pred) (p : nat).
Implicit Types (A B C : {set gT}) (D G H E : {group gT}).
Lemma Ohm0 G : 'Ohm_0(G) = 1.
Proof.
by apply/trivgP; rewrite /= gen_subG; apply/subsetP=> x /setIdP[_] /[1!inE].
Qed.
Lemma Ohm_leq m n G : m <= n -> 'Ohm_m(G) \subset 'Ohm_n(G).
Proof.
move/subnKC <-; rewrite genS //; apply/subsetP=> y.
by rewrite !inE expnD expgM => /andP[-> /eqP->]; rewrite expg1n /=.
Qed.
Lemma OhmJ n G x : 'Ohm_n(G :^ x) = 'Ohm_n(G) :^ x.
Proof.
rewrite -{1}(setIid G) -(setIidPr (Ohm_sub n G)).
by rewrite -!morphim_conj injm_Ohm ?injm_conj.
Qed.
Lemma Mho0 G : 'Mho^0(G) = G.
Proof.
apply/eqP; rewrite eqEsubset Mho_sub /=.
apply/subsetP=> x Gx; rewrite -[x]prod_constt group_prod // => p _.
exact: Mho_p_elt (groupX _ Gx) (p_elt_constt _ _).
Qed.
Lemma Mho_leq m n G : m <= n -> 'Mho^n(G) \subset 'Mho^m(G).
Proof.
move/subnKC <-; rewrite gen_subG //.
apply/subsetP=> _ /imsetP[x /setIdP[Gx p_x] ->].
by rewrite expnD expgM groupX ?(Mho_p_elt _ _ p_x).
Qed.
Lemma MhoJ n G x : 'Mho^n(G :^ x) = 'Mho^n(G) :^ x.
Proof.
by rewrite -{1}(setIid G) -(setIidPr (Mho_sub n G)) -!morphim_conj morphim_Mho.
Qed.
Lemma extend_cyclic_Mho G p x :
p.-group G -> x \in G -> 'Mho^1(G) = <[x ^+ p]> ->
forall k, k > 0 -> 'Mho^k(G) = <[x ^+ (p ^ k)]>.
Proof.
move=> pG Gx defG1 [//|k _]; have pX := mem_p_elt pG Gx.
apply/eqP; rewrite eqEsubset cycle_subG (Mho_p_elt _ Gx pX) andbT.
rewrite (MhoE _ pG) gen_subG; apply/subsetP=> ypk; case/imsetP=> y Gy ->{ypk}.
have: y ^+ p \in <[x ^+ p]> by rewrite -defG1 (Mho_p_elt 1 _ (mem_p_elt pG Gy)).
rewrite !expnS /= !expgM => /cycleP[j ->].
by rewrite -!expgM mulnCA mulnC expgM mem_cycle.
Qed.
Lemma Ohm1Eprime G : 'Ohm_1(G) = <<[set x in G | prime #[x]]>>.
Proof.
rewrite -['Ohm_1(G)](genD1 (group1 _)); congr <<_>>.
apply/setP=> x; rewrite !inE andbCA -order_dvdn -order_gt1; congr (_ && _).
apply/andP/idP=> [[p_gt1] | p_pr]; last by rewrite prime_gt1 ?pdiv_id.
set p := pdiv _ => ox_p; have p_pr: prime p by rewrite pdiv_prime.
by have [_ dv_p] := primeP p_pr; case/pred2P: (dv_p _ ox_p) p_gt1 => ->.
Qed.
Lemma abelem_Ohm1 p G : p.-group G -> p.-abelem 'Ohm_1(G) = abelian 'Ohm_1(G).
Proof.
move=> pG; rewrite /abelem (pgroupS (Ohm_sub 1 G)) //.
case abG1: (abelian _) => //=; apply/exponentP=> x.
by rewrite (OhmEabelian pG abG1); case/LdivP.
Qed.
Lemma Ohm1_abelem p G : p.-group G -> abelian G -> p.-abelem ('Ohm_1(G)).
Proof. by move=> pG cGG; rewrite abelem_Ohm1 ?(abelianS (Ohm_sub 1 G)). Qed.
Lemma Ohm1_id p G : p.-abelem G -> 'Ohm_1(G) = G.
Proof.
case/and3P=> pG cGG /exponentP Gp.
apply/eqP; rewrite eqEsubset Ohm_sub (OhmE 1 pG) sub_gen //.
by apply/subsetP=> x Gx; rewrite !inE Gx Gp /=.
Qed.
Lemma abelem_Ohm1P p G :
abelian G -> p.-group G -> reflect ('Ohm_1(G) = G) (p.-abelem G).
Proof.
move=> cGG pG.
by apply: (iffP idP) => [| <-]; [apply: Ohm1_id | apply: Ohm1_abelem].
Qed.
Lemma TI_Ohm1 G H : H :&: 'Ohm_1(G) = 1 -> H :&: G = 1.
Proof.
move=> tiHG1; case: (trivgVpdiv (H :&: G)) => // [[p pr_p]].
case/Cauchy=> // x /setIP[Hx Gx] ox.
suffices x1: x \in [1] by rewrite -ox (set1P x1) order1 in pr_p.
by rewrite -{}tiHG1 inE Hx Ohm1Eprime mem_gen // inE Gx ox.
Qed.
Lemma Ohm1_eq1 G : ('Ohm_1(G) == 1) = (G :==: 1).
Proof.
apply/idP/idP => [/eqP G1_1 | /eqP->]; last by rewrite -subG1 Ohm_sub.
by rewrite -(setIid G) TI_Ohm1 // G1_1 setIg1.
Qed.
Lemma meet_Ohm1 G H : G :&: H != 1 -> G :&: 'Ohm_1(H) != 1.
Proof. by apply: contraNneq => /TI_Ohm1->. Qed.
Lemma Ohm1_cent_max G E p : E \in 'E*_p(G) -> p.-group G -> 'Ohm_1('C_G(E)) = E.
Proof.
move=> EpmE pG; have [G1 | ntG]:= eqsVneq G 1.
case/pmaxElemP: EpmE; case/pElemP; rewrite G1 => /trivgP-> _ _.
by apply/trivgP; rewrite cent1T setIT Ohm_sub.
have [p_pr _ _] := pgroup_pdiv pG ntG.
by rewrite (OhmE 1 (pgroupS (subsetIl G _) pG)) (pmaxElem_LdivP _ _) ?genGid.
Qed.
Lemma Ohm1_cyclic_pgroup_prime p G :
cyclic G -> p.-group G -> G :!=: 1 -> #|'Ohm_1(G)| = p.
Proof.
move=> cycG pG ntG; set K := 'Ohm_1(G).
have abelK: p.-abelem K by rewrite Ohm1_abelem ?cyclic_abelian.
have sKG: K \subset G := Ohm_sub 1 G.
case/cyclicP: (cyclicS sKG cycG) => x /=; rewrite -/K => defK.
rewrite defK -orderE (abelem_order_p abelK) //= -/K ?defK ?cycle_id //.
rewrite -cycle_eq1 -defK -(setIidPr sKG).
by apply: contraNneq ntG => /TI_Ohm1; rewrite setIid => ->.
Qed.
Lemma cyclic_pgroup_dprod_trivg p A B C :
p.-group C -> cyclic C -> A \x B = C ->
A = 1 /\ B = C \/ B = 1 /\ A = C.
Proof.
move=> pC cycC; case/cyclicP: cycC pC => x ->{C} pC defC.
case/dprodP: defC => [] [G H -> ->{A B}] defC _ tiGH; rewrite -defC.
have [/trivgP | ntC] := eqVneq <[x]> 1.
by rewrite -defC mulG_subG => /andP[/trivgP-> _]; rewrite mul1g; left.
have [pr_p _ _] := pgroup_pdiv pC ntC; pose K := 'Ohm_1(<[x]>).
have prK : prime #|K| by rewrite (Ohm1_cyclic_pgroup_prime _ pC) ?cycle_cyclic.
case: (prime_subgroupVti G prK) => [sKG |]; last first.
move/TI_Ohm1; rewrite -defC (setIidPl (mulG_subl _ _)) => ->.
by left; rewrite mul1g.
case: (prime_subgroupVti H prK) => [sKH |]; last first.
move/TI_Ohm1; rewrite -defC (setIidPl (mulG_subr _ _)) => ->.
by right; rewrite mulg1.
have K1: K :=: 1 by apply/trivgP; rewrite -tiGH subsetI sKG.
by rewrite K1 cards1 in prK.
Qed.
Lemma piOhm1 G : \pi('Ohm_1(G)) = \pi(G).
Proof.
apply/eq_piP => p; apply/idP/idP; first exact: (piSg (Ohm_sub 1 G)).
rewrite !mem_primes !cardG_gt0 => /andP[p_pr /Cauchy[] // x Gx oxp].
by rewrite p_pr -oxp order_dvdG //= Ohm1Eprime mem_gen // inE Gx oxp.
Qed.
Lemma Ohm1Eexponent p G :
prime p -> exponent 'Ohm_1(G) %| p -> 'Ohm_1(G) = 'Ldiv_p(G).
Proof.
move=> p_pr expG1p; have pG: p.-group G.
apply: sub_in_pnat (pnat_pi (cardG_gt0 G)) => q _.
rewrite -piOhm1 mem_primes; case/and3P=> q_pr _; apply: pgroupP q_pr.
by rewrite -pnat_exponent (pnat_dvd expG1p) ?pnat_id.
apply/eqP; rewrite eqEsubset {2}(OhmE 1 pG) subset_gen subsetI Ohm_sub.
by rewrite sub_LdivT expG1p.
Qed.
Lemma p_rank_Ohm1 p G : 'r_p('Ohm_1(G)) = 'r_p(G).
Proof.
apply/eqP; rewrite eqn_leq p_rankS ?Ohm_sub //.
apply/bigmax_leqP=> E /setIdP[sEG abelE].
by rewrite (bigmax_sup E) // inE -{1}(Ohm1_id abelE) OhmS.
Qed.
Lemma rank_Ohm1 G : 'r('Ohm_1(G)) = 'r(G).
Proof.
apply/eqP; rewrite eqn_leq rankS ?Ohm_sub //.
by have [p _ ->] := rank_witness G; rewrite -p_rank_Ohm1 p_rank_le_rank.
Qed.
Lemma p_rank_abelian p G : abelian G -> 'r_p(G) = logn p #|'Ohm_1(G)|.
Proof.
move=> cGG; have nilG := abelian_nil cGG; case p_pr: (prime p); last first.
by apply/eqP; rewrite lognE p_pr eqn0Ngt p_rank_gt0 mem_primes p_pr.
case/dprodP: (Ohm_dprod 1 (nilpotent_pcoreC p nilG)) => _ <- _ /TI_cardMg->.
rewrite mulnC logn_Gauss; last first.
rewrite prime_coprime // -p'natE // -/(pgroup _ _).
exact: pgroupS (Ohm_sub _ _) (pcore_pgroup _ _).
rewrite -(p_rank_Sylow (nilpotent_pcore_Hall p nilG)) -p_rank_Ohm1.
rewrite p_rank_abelem // Ohm1_abelem ?pcore_pgroup //.
exact: abelianS (pcore_sub _ _) cGG.
Qed.
Lemma rank_abelian_pgroup p G :
p.-group G -> abelian G -> 'r(G) = logn p #|'Ohm_1(G)|.
Proof. by move=> pG cGG; rewrite (rank_pgroup pG) p_rank_abelian. Qed.
End OhmProps.
Section AbelianStructure.
Variable gT : finGroupType.
Implicit Types (p : nat) (G H K E : {group gT}).
Lemma abelian_splits x G :
x \in G -> #[x] = exponent G -> abelian G -> [splits G, over <[x]>].
Proof.
move=> Gx ox cGG; apply/splitsP; have [n] := ubnP #|G|.
elim: n gT => // n IHn aT in x G Gx ox cGG * => /ltnSE-leGn.
have: <[x]> \subset G by [rewrite cycle_subG]; rewrite subEproper.
case/predU1P=> [<- | /properP[sxG [y]]].
by exists 1%G; rewrite inE -subG1 subsetIr mulg1 /=.
have [m] := ubnP #[y]; elim: m y => // m IHm y /ltnSE-leym Gy x'y.
case: (trivgVpdiv <[y]>) => [y1 | [p p_pr p_dv_y]].
by rewrite -cycle_subG y1 sub1G in x'y.
case x_yp: (y ^+ p \in <[x]>); last first.
apply: IHm (negbT x_yp); rewrite ?groupX ?(leq_trans _ leym) //.
by rewrite orderXdiv // ltn_Pdiv ?prime_gt1.
have{x_yp} xp_yp: (y ^+ p \in <[x ^+ p]>).
have: <[y ^+ p]>%G \in [set <[x ^+ (#[x] %/ #[y ^+ p])]>%G].
by rewrite -cycle_sub_group ?order_dvdG // inE cycle_subG x_yp eqxx.
rewrite inE -cycle_subG -val_eqE /=; move/eqP->.
rewrite cycle_subG orderXdiv // divnA // mulnC ox.
by rewrite -muln_divA ?dvdn_exponent ?expgM 1?groupX ?cycle_id.
have: p <= #[y] by rewrite dvdn_leq.
rewrite leq_eqVlt => /predU1P[{xp_yp m IHm leym}oy | ltpy]; last first.
case/cycleP: xp_yp => k; rewrite -expgM mulnC expgM => def_yp.
suffices: #[y * x ^- k] < m.
by move/IHm; apply; rewrite groupMr // groupV groupX ?cycle_id.
apply: leq_ltn_trans (leq_trans ltpy leym).
rewrite dvdn_leq ?prime_gt0 // order_dvdn expgMn.
by rewrite expgVn def_yp mulgV.
by apply: (centsP cGG); rewrite ?groupV ?groupX.
pose Y := <[y]>; have nsYG: Y <| G by rewrite -sub_abelian_normal ?cycle_subG.
have [sYG nYG] := andP nsYG; have nYx := subsetP nYG x Gx.
have GxY: coset Y x \in G / Y by rewrite mem_morphim.
have tiYx: Y :&: <[x]> = 1 by rewrite prime_TIg ?indexg1 -?[#|_|]oy ?cycle_subG.
have: #[coset Y x] = exponent (G / Y).
apply/eqP; rewrite eqn_dvd dvdn_exponent //.
apply/exponentP=> _ /morphimP[z Nz Gz ->].
rewrite -morphX // ((z ^+ _ =P 1) _) ?morph1 //.
rewrite orderE -quotient_cycle ?card_quotient ?cycle_subG // -indexgI /=.
by rewrite setIC tiYx indexg1 -orderE ox -order_dvdn dvdn_exponent.
case/IHn => // [||Hq]; first exact: quotient_abelian.
apply: leq_trans leGn; rewrite ltn_quotient // cycle_eq1.
by apply: contra x'y; move/eqP->; rewrite group1.
case/complP=> /= ti_x_Hq defGq.
have: Hq \subset G / Y by rewrite -defGq mulG_subr.
case/inv_quotientS=> // H defHq sYH sHG; exists H.
have nYX: <[x]> \subset 'N(Y) by rewrite cycle_subG.
rewrite inE -subG1 eqEsubset mul_subG //= -tiYx subsetI subsetIl andbT.
rewrite -{2}(mulSGid sYH) mulgA (normC nYX) -mulgA -quotientSK ?quotientMl //.
rewrite -quotient_sub1 ?(subset_trans (subsetIl _ _)) // quotientIG //= -/Y.
by rewrite -defHq quotient_cycle // ti_x_Hq defGq !subxx.
Qed.
Lemma abelem_splits p G H : p.-abelem G -> H \subset G -> [splits G, over H].
Proof.
have [m] := ubnP #|G|; elim: m G H => // m IHm G H /ltnSE-leGm abelG sHG.
have [-> | ] := eqsVneq H 1.
by apply/splitsP; exists G; rewrite inE mul1g -subG1 subsetIl /=.
case/trivgPn=> x Hx ntx; have Gx := subsetP sHG x Hx.
have [_ cGG eGp] := and3P abelG.
have ox: #[x] = exponent G.
by apply/eqP; rewrite eqn_dvd dvdn_exponent // (abelem_order_p abelG).
case/splitsP: (abelian_splits Gx ox cGG) => K; case/complP=> tixK defG.
have sKG: K \subset G by rewrite -defG mulG_subr.
have ltKm: #|K| < m.
rewrite (leq_trans _ leGm) ?proper_card //; apply/properP; split=> //.
exists x => //; apply: contra ntx => Kx; rewrite -cycle_eq1 -subG1 -tixK.
by rewrite subsetI subxx cycle_subG.
case/splitsP: (IHm _ _ ltKm (abelemS sKG abelG) (subsetIr H K)) => L.
case/complP=> tiHKL defK; apply/splitsP; exists L; rewrite inE.
rewrite -subG1 -tiHKL -setIA setIS; last by rewrite subsetI -defK mulG_subr /=.
by rewrite -(setIidPr sHG) -defG -group_modl ?cycle_subG //= setIC -mulgA defK.
Qed.
Fact abelian_type_subproof G :
{H : {group gT} & abelian G -> {x | #[x] = exponent G & <[x]> \x H = G}}.
Proof.
case cGG: (abelian G); last by exists G.
have [x Gx ox] := exponent_witness (abelian_nil cGG).
case/splitsP/ex_mingroup: (abelian_splits Gx (esym ox) cGG) => H.
case/mingroupp/complP=> tixH defG; exists H => _.
exists x; rewrite ?dprodE // (sub_abelian_cent2 cGG) ?cycle_subG //.
by rewrite -defG mulG_subr.
Qed.
Fixpoint abelian_type_rec n G :=
if n is n'.+1 then if abelian G && (G :!=: 1) then
exponent G :: abelian_type_rec n' (tag (abelian_type_subproof G))
else [::] else [::].
Definition abelian_type (A : {set gT}) := abelian_type_rec #|A| <<A>>.
Lemma abelian_type_dvdn_sorted A : sorted [rel m n | n %| m] (abelian_type A).
Proof.
set R := SimplRel _; pose G := <<A>>%G; pose M := G.
suffices: path R (exponent M) (abelian_type A) by case: (_ A) => // m t /andP[].
rewrite /abelian_type -/G; have: G \subset M by [].
elim: {A}#|A| G M => //= n IHn G M sGM.
case: andP => //= -[cGG ntG]; rewrite exponentS ?IHn //=.
case: (abelian_type_subproof G) => H /= [//| x _] /dprodP[_ /= <- _ _].
exact: mulG_subr.
Qed.
Lemma abelian_type_gt1 A : all [pred m | m > 1] (abelian_type A).
Proof.
rewrite /abelian_type; elim: {A}#|A| <<A>>%G => //= n IHn G.
case: ifP => //= /andP[_ ntG]; rewrite {n}IHn.
by rewrite ltn_neqAle exponent_gt0 eq_sym -dvdn1 -trivg_exponent ntG.
Qed.
Lemma abelian_type_sorted A : sorted geq (abelian_type A).
Proof.
have:= abelian_type_dvdn_sorted A; have:= abelian_type_gt1 A.
case: (abelian_type A) => //= m t; elim: t m => //= n t IHt m /andP[].
by move/ltnW=> m_gt0 t_gt1 /andP[n_dv_m /IHt->]; rewrite // dvdn_leq.
Qed.
Theorem abelian_structure G :
abelian G ->
{b | \big[dprod/1]_(x <- b) <[x]> = G & map order b = abelian_type G}.
Proof.
rewrite /abelian_type genGidG; have [n] := ubnPleq #|G|.
elim: n G => /= [|n IHn] G leGn cGG; first by rewrite leqNgt cardG_gt0 in leGn.
rewrite [in _ && _]cGG /=; case: ifP => [ntG|/eqP->]; last first.
by exists [::]; rewrite ?big_nil.
case: (abelian_type_subproof G) => H /= [//|x ox xdefG]; rewrite -ox.
have [_ defG cxH tixH] := dprodP xdefG.
have sHG: H \subset G by rewrite -defG mulG_subr.
case/IHn: (abelianS sHG cGG) => [|b defH <-].
rewrite -ltnS (leq_trans _ leGn) // -defG TI_cardMg // -orderE.
rewrite ltn_Pmull ?cardG_gt0 // ltn_neqAle order_gt0 eq_sym -dvdn1.
by rewrite ox -trivg_exponent ntG.
by exists (x :: b); rewrite // big_cons defH xdefG.
Qed.
Lemma count_logn_dprod_cycle p n b G :
\big[dprod/1]_(x <- b) <[x]> = G ->
count [pred x | logn p #[x] > n] b = logn p #|'Ohm_n.+1(G) : 'Ohm_n(G)|.
Proof.
have sOn1 H: 'Ohm_n(H) \subset 'Ohm_n.+1(H) by apply: Ohm_leq.
pose lnO i (A : {set gT}) := logn p #|'Ohm_i(A)|.
have lnO_le H: lnO n H <= lnO n.+1 H.
by rewrite dvdn_leq_log ?cardG_gt0 // cardSg ?sOn1.
have lnOx i A B H: A \x B = H -> lnO i A + lnO i B = lnO i H.
move=> defH; case/dprodP: defH (defH) => {A B}[[A B -> ->]] _ _ _ defH.
rewrite /lnO; case/dprodP: (Ohm_dprod i defH) => _ <- _ tiOAB.
by rewrite TI_cardMg ?lognM.
rewrite -divgS //= logn_div ?cardSg //= -/(lnO _ _) -/(lnO _ _).
elim: b G => [_ <-|x b IHb G] /=.
by rewrite big_nil /lnO !(trivgP (Ohm_sub _ _)) subnn.
rewrite /= big_cons => defG; rewrite -!(lnOx _ _ _ _ defG) subnDA.
case/dprodP: defG => [[_ H _ defH] _ _ _] {G}; rewrite defH (IHb _ defH).
symmetry; do 2!rewrite addnC -addnBA ?lnO_le //; congr (_ + _).
pose y := x.`_p; have p_y: p.-elt y by rewrite p_elt_constt.
have{lnOx} lnOy i: lnO i <[x]> = lnO i <[y]>.
have cXX := cycle_abelian x.
have co_yx': coprime #[y] #[x.`_p^'] by rewrite !order_constt coprime_partC.
have defX: <[y]> \x <[x.`_p^']> = <[x]>.
rewrite dprodE ?coprime_TIg //.
by rewrite -cycleM ?consttC //; apply: (centsP cXX); apply: mem_cycle.
by apply: (sub_abelian_cent2 cXX); rewrite cycle_subG mem_cycle.
rewrite -(lnOx i _ _ _ defX) addnC {1}/lnO lognE.
case: and3P => // [[p_pr _ /idPn[]]]; rewrite -p'natE //.
exact: pgroupS (Ohm_sub _ _) (p_elt_constt _ _).
rewrite -logn_part -order_constt -/y !{}lnOy /lnO !(Ohm_p_cycle _ p_y).
case: leqP => [| lt_n_y].
by rewrite -subn_eq0 -addn1 subnDA => /eqP->; rewrite subnn.
rewrite -!orderE -(subSS n) subSn // expnSr expgM.
have p_pr: prime p by move: lt_n_y; rewrite lognE; case: prime.
set m := (p ^ _)%N; have m_gt0: m > 0 by rewrite expn_gt0 prime_gt0.
suffices p_ym: p %| #[y ^+ m].
rewrite -logn_div ?orderXdvd // (orderXdiv p_ym) divnA // mulKn //.
by rewrite logn_prime ?eqxx.
rewrite orderXdiv ?pfactor_dvdn ?leq_subr // -(dvdn_pmul2r m_gt0).
by rewrite -expnS -subSn // subSS divnK pfactor_dvdn ?leq_subr.
Qed.
Lemma abelian_type_pgroup p b G :
p.-group G -> \big[dprod/1]_(x <- b) <[x]> = G -> 1 \notin b ->
perm_eq (abelian_type G) (map order b).
Proof.
rewrite perm_sym; move: b => b1 pG defG1 ntb1.
have cGG: abelian G.
elim: (b1) {pG}G defG1 => [_ <-|x b IHb G]; first by rewrite big_nil abelian1.
rewrite big_cons; case/dprodP=> [[_ H _ defH]] <-; rewrite defH => cxH _.
by rewrite abelianM cycle_abelian IHb.
have p_bG b: \big[dprod/1]_(x <- b) <[x]> = G -> all (p_elt p) b.
elim: b {defG1 cGG}G pG => //= x b IHb G pG; rewrite big_cons.
case/dprodP=> [[_ H _ defH]]; rewrite defH andbC => defG _ _.
by rewrite -defG pgroupM in pG; case/andP: pG => p_x /IHb->.
have [b2 defG2 def_t] := abelian_structure cGG.
have ntb2: 1 \notin b2.
apply: contraL (abelian_type_gt1 G) => b2_1.
rewrite -def_t -has_predC has_map.
by apply/hasP; exists 1; rewrite //= order1.
rewrite -{}def_t; apply/allP=> m; rewrite -map_cat => /mapP[x b_x def_m].
have{ntb1 ntb2} ntx: x != 1.
by apply: contraL b_x; move/eqP->; rewrite mem_cat negb_or ntb1 ntb2.
have p_x: p.-elt x by apply: allP (x) b_x; rewrite all_cat !p_bG.
rewrite -cycle_eq1 in ntx; have [p_pr _ [k ox]] := pgroup_pdiv p_x ntx.
apply/eqnP; rewrite {m}def_m orderE ox !count_map.
pose cnt_p k := count [pred x : gT | logn p #[x] > k].
have cnt_b b: \big[dprod/1]_(x <- b) <[x]> = G ->
count [pred x | #[x] == p ^ k.+1]%N b = cnt_p k b - cnt_p k.+1 b.
- move/p_bG; elim: b => //= _ b IHb /andP[/p_natP[j ->] /IHb-> {IHb}].
rewrite eqn_leq !leq_exp2l ?prime_gt1 // -eqn_leq pfactorK //.
case: (ltngtP k.+1) => // _ {j}; rewrite subSn // add0n.
by elim: b => //= y b IHb; rewrite leq_add // ltn_neqAle; case: (~~ _).
by rewrite !cnt_b // /cnt_p !(@count_logn_dprod_cycle _ _ _ G).
Qed.
Lemma size_abelian_type G : abelian G -> size (abelian_type G) = 'r(G).
Proof.
move=> cGG; have [b defG def_t] := abelian_structure cGG.
apply/eqP; rewrite -def_t size_map eqn_leq andbC; apply/andP; split.
have [p p_pr ->] := rank_witness G; rewrite p_rank_abelian //.
by rewrite -indexg1 -(Ohm0 G) -(count_logn_dprod_cycle _ _ defG) count_size.
case/lastP def_b: b => // [b' x]; pose p := pdiv #[x].
have p_pr: prime p.
have:= abelian_type_gt1 G; rewrite -def_t def_b map_rcons -cats1 all_cat.
by rewrite /= andbT => /andP[_]; apply: pdiv_prime.
suffices: all [pred y | logn p #[y] > 0] b.
rewrite all_count (count_logn_dprod_cycle _ _ defG) -def_b; move/eqP <-.
by rewrite Ohm0 indexg1 -p_rank_abelian ?p_rank_le_rank.
apply/allP=> y; rewrite def_b mem_rcons inE /= => b_y.
rewrite lognE p_pr order_gt0 (dvdn_trans (pdiv_dvd _)) //.
case/predU1P: b_y => [-> // | b'_y].
have:= abelian_type_dvdn_sorted G; rewrite -def_t def_b.
case/splitPr: b'_y => b1 b2; rewrite -cat_rcons rcons_cat map_cat !map_rcons.
rewrite headI /= cat_path -(last_cons 2) -headI last_rcons.
case/andP=> _ /order_path_min min_y.
apply: (allP (min_y _)) => [? ? ? ? dv|]; first exact: (dvdn_trans dv).
by rewrite mem_rcons mem_head.
Qed.
Lemma mul_card_Ohm_Mho_abelian n G :
abelian G -> (#|'Ohm_n(G)| * #|'Mho^n(G)|)%N = #|G|.
Proof.
case/abelian_structure => b defG _.
elim: b G defG => [_ <-|x b IHb G].
by rewrite !big_nil (trivgP (Ohm_sub _ _)) (trivgP (Mho_sub _ _)) !cards1.
rewrite big_cons => defG; rewrite -(dprod_card defG).
rewrite -(dprod_card (Ohm_dprod n defG)) -(dprod_card (Mho_dprod n defG)) /=.
rewrite mulnCA -!mulnA mulnCA mulnA; case/dprodP: defG => [[_ H _ defH] _ _ _].
rewrite defH {b G defH IHb}(IHb H defH); congr (_ * _)%N => {H}.
have [m] := ubnP #[x]; elim: m x => // m IHm x /ltnSE-lexm.
case p_x: (p_group <[x]>); last first.
case: (eqVneq x 1) p_x => [-> |]; first by rewrite cycle1 p_group1.
rewrite -order_gt1 /p_group -orderE; set p := pdiv _ => ntx p'x.
have def_x: <[x.`_p]> \x <[x.`_p^']> = <[x]>.
have ?: coprime #[x.`_p] #[x.`_p^'] by rewrite !order_constt coprime_partC.
have ?: commute x.`_p x.`_p^' by apply: commuteX2.
rewrite dprodE ?coprime_TIg -?cycleM ?consttC //.
by rewrite cent_cycle cycle_subG; apply/cent1P.
rewrite -(dprod_card (Ohm_dprod n def_x)) -(dprod_card (Mho_dprod n def_x)).
rewrite mulnCA -mulnA mulnCA mulnA.
rewrite !{}IHm ?(dprod_card def_x) ?(leq_trans _ lexm) {m lexm}//.
rewrite /order -(dprod_card def_x) -!orderE !order_constt ltn_Pmull //.
rewrite p_part -(expn0 p) ltn_exp2l 1?lognE ?prime_gt1 ?pdiv_prime //.
by rewrite order_gt0 pdiv_dvd.
rewrite proper_card // properEneq cycle_subG mem_cycle andbT.
by apply: contra (negbT p'x); move/eqP <-; apply: p_elt_constt.
case/p_groupP: p_x => p p_pr p_x.
rewrite (Ohm_p_cycle n p_x) (Mho_p_cycle n p_x) -!orderE.
set k := logn p #[x]; have ox: #[x] = (p ^ k)%N by rewrite -card_pgroup.
case: (leqP k n) => [le_k_n | lt_n_k].
rewrite -(subnKC le_k_n) subnDA subnn expg1 expnD expgM -ox.
by rewrite expg_order expg1n order1 muln1.
rewrite !orderXgcd ox -[in (p ^ k)%N](subnKC (ltnW lt_n_k)) expnD.
rewrite gcdnC gcdnMl gcdnC gcdnMr.
by rewrite mulnK ?mulKn ?expn_gt0 ?prime_gt0.
Qed.
Lemma grank_abelian G : abelian G -> 'm(G) = 'r(G).
Proof.
move=> cGG; apply/eqP; rewrite eqn_leq; apply/andP; split.
rewrite -size_abelian_type //; case/abelian_structure: cGG => b defG <-.
suffices <-: <<[set x in b]>> = G.
by rewrite (leq_trans (grank_min _)) // size_map cardsE card_size.
rewrite -{G defG}(bigdprodWY defG).
elim: b => [|x b IHb]; first by rewrite big_nil gen0.
by rewrite big_cons -joingE -joing_idr -IHb joing_idl joing_idr set_cons.
have [p p_pr ->] := rank_witness G; pose K := 'Mho^1(G).
have ->: 'r_p(G) = logn p #|G / K|.
rewrite p_rank_abelian // card_quotient /= ?gFnorm // -divgS ?Mho_sub //.
by rewrite -(mul_card_Ohm_Mho_abelian 1 cGG) mulnK ?cardG_gt0.
case: (grank_witness G) => B genB <-; rewrite -genB.
have{genB}: <<B>> \subset G by rewrite genB.
have [m] := ubnP #|B|; elim: m B => // m IHm B.
have [-> | [x Bx]] := set_0Vmem B; first by rewrite gen0 quotient1 cards1 logn1.
rewrite ltnS (cardsD1 x) Bx -[in <<B>>](setD1K Bx); set B' := B :\ x => ltB'm.
rewrite -joingE -joing_idl -joing_idr -/<[x]> join_subG => /andP[Gx sB'G].
rewrite cent_joinEl ?(sub_abelian_cent2 cGG) //.
have nKx: x \in 'N(K) by rewrite -cycle_subG (subset_trans Gx) ?gFnorm.
rewrite quotientMl ?cycle_subG // quotient_cycle //= -/K.
have le_Kxp_1: logn p #[coset K x] <= 1.
rewrite -(dvdn_Pexp2l _ _ (prime_gt1 p_pr)) -p_part -order_constt.
rewrite order_dvdn -morph_constt // -morphX ?groupX //= coset_id //.
by rewrite Mho_p_elt ?p_elt_constt ?groupX -?cycle_subG.
apply: leq_trans (leq_add le_Kxp_1 (IHm _ ltB'm sB'G)).
by rewrite -lognM ?dvdn_leq_log ?muln_gt0 ?cardG_gt0 // mul_cardG dvdn_mulr.
Qed.
Lemma rank_cycle (x : gT) : 'r(<[x]>) = (x != 1).
Proof.
have [->|ntx] := eqVneq x 1; first by rewrite cycle1 rank1.
apply/eqP; rewrite eqn_leq rank_gt0 cycle_eq1 ntx andbT.
by rewrite -grank_abelian ?cycle_abelian //= -(cards1 x) grank_min.
Qed.
Lemma abelian_rank1_cyclic G : abelian G -> cyclic G = ('r(G) <= 1).
Proof.
move=> cGG; have [b defG atypG] := abelian_structure cGG.
apply/idP/idP; first by case/cyclicP=> x ->; rewrite rank_cycle leq_b1.
rewrite -size_abelian_type // -{}atypG -{}defG unlock.
by case: b => [|x []] //= _; rewrite ?cyclic1 // dprodg1 cycle_cyclic.
Qed.
Definition homocyclic A := abelian A && constant (abelian_type A).
Lemma homocyclic_Ohm_Mho n p G :
p.-group G -> homocyclic G -> 'Ohm_n(G) = 'Mho^(logn p (exponent G) - n)(G).
Proof.
move=> pG /andP[cGG homoG]; set e := exponent G.
have{pG} p_e: p.-nat e by apply: pnat_dvd pG; apply: exponent_dvdn.
have{homoG}: all (pred1 e) (abelian_type G).
move: homoG; rewrite /abelian_type -(prednK (cardG_gt0 G)) /=.
by case: (_ && _) (tag _); rewrite //= genGid eqxx.
have{cGG} [b defG <-] := abelian_structure cGG.
move: e => e in p_e *; elim: b => /= [|x b IHb] in G defG *.
by rewrite -defG big_nil (trivgP (Ohm_sub _ _)) (trivgP (Mho_sub _ _)).
case/andP=> /eqP ox e_b; rewrite big_cons in defG.
rewrite -(Ohm_dprod _ defG) -(Mho_dprod _ defG).
case/dprodP: defG => [[_ H _ defH] _ _ _]; rewrite defH (IHb H) //; congr (_ \x _).
by rewrite -ox in p_e *; rewrite (Ohm_p_cycle _ p_e) (Mho_p_cycle _ p_e).
Qed.
Lemma Ohm_Mho_homocyclic (n p : nat) G :
abelian G -> p.-group G -> 0 < n < logn p (exponent G) ->
'Ohm_n(G) = 'Mho^(logn p (exponent G) - n)(G) -> homocyclic G.
Proof.
set e := exponent G => cGG pG /andP[n_gt0 n_lte] eq_Ohm_Mho.
suffices: all (pred1 e) (abelian_type G).
by rewrite /homocyclic cGG; apply: all_pred1_constant.
case/abelian_structure: cGG (abelian_type_gt1 G) => b defG <-.
set H := G in defG eq_Ohm_Mho *; have sHG: H \subset G by [].
elim: b H defG sHG eq_Ohm_Mho => //= x b IHb H.
rewrite big_cons => defG; case/dprodP: defG (defG) => [[_ K _ defK]].
rewrite defK => defHm cxK; rewrite setIC => /trivgP-tiKx defHd.
rewrite -{}[in H \subset G]defHm mulG_subG cycle_subG ltnNge -trivg_card_le1.
case/andP=> Gx sKG; rewrite -(Mho_dprod _ defHd) => /esym defMho /andP[ntx ntb].
have{defHd} defOhm := Ohm_dprod n defHd.
apply/andP; split; last first.
apply: (IHb K) => //; have:= dprod_modr defMho (Mho_sub _ _).
rewrite -(dprod_modr defOhm (Ohm_sub _ _)).
rewrite !(trivgP (subset_trans (setIS _ _) tiKx)) ?Ohm_sub ?Mho_sub //.
by rewrite !dprod1g.
have:= dprod_modl defMho (Mho_sub _ _).
rewrite -(dprod_modl defOhm (Ohm_sub _ _)) .
rewrite !(trivgP (subset_trans (setSI _ _) tiKx)) ?Ohm_sub ?Mho_sub //.
move/eqP; rewrite eqEcard => /andP[_].
have p_x: p.-elt x := mem_p_elt pG Gx.
have [p_pr p_dv_x _] := pgroup_pdiv p_x ntx.
rewrite !dprodg1 (Ohm_p_cycle _ p_x) (Mho_p_cycle _ p_x) -!orderE.
rewrite orderXdiv ?leq_divLR ?pfactor_dvdn ?leq_subr //.
rewrite orderXgcd divn_mulAC ?dvdn_gcdl // leq_divRL ?gcdn_gt0 ?order_gt0 //.
rewrite leq_pmul2l //; apply: contraLR.
rewrite eqn_dvd dvdn_exponent //= -ltnNge => lt_x_e.
rewrite (leq_trans (ltn_Pmull (prime_gt1 p_pr) _)) ?expn_gt0 ?prime_gt0 //.
rewrite -expnS dvdn_leq // ?gcdn_gt0 ?order_gt0 // dvdn_gcd.
rewrite pfactor_dvdn // dvdn_exp2l.
by rewrite -[ltnRHS]subn0 ltn_sub2l // lognE p_pr order_gt0 p_dv_x.
rewrite ltn_sub2r // ltnNge -(dvdn_Pexp2l _ _ (prime_gt1 p_pr)) -!p_part.
by rewrite !part_pnat_id // (pnat_dvd (exponent_dvdn G)).
Qed.
Lemma abelem_homocyclic p G : p.-abelem G -> homocyclic G.
Proof.
move=> abelG; have [_ cGG _] := and3P abelG.
rewrite /homocyclic cGG (@all_pred1_constant _ p) //.
case/abelian_structure: cGG (abelian_type_gt1 G) => b defG <- => b_gt1.
apply/allP=> _ /mapP[x b_x ->] /=; rewrite (abelem_order_p abelG) //.
rewrite -cycle_subG -(bigdprodWY defG) ?sub_gen //.
by rewrite bigcup_seq (bigcup_sup x).
by rewrite -order_gt1 [_ > 1](allP b_gt1) ?map_f.
Qed.
Lemma homocyclic1 : homocyclic [1 gT].
Proof. exact: abelem_homocyclic (abelem1 _ 2). Qed.
Lemma Ohm1_homocyclicP p G : p.-group G -> abelian G ->
reflect ('Ohm_1(G) = 'Mho^(logn p (exponent G)).-1(G)) (homocyclic G).
Proof.
move=> pG cGG; set e := logn p (exponent G); rewrite -subn1.
apply: (iffP idP) => [homoG | ]; first exact: homocyclic_Ohm_Mho.
case: (ltnP 1 e) => [lt1e | ]; first exact: Ohm_Mho_homocyclic.
rewrite -subn_eq0 => /eqP->; rewrite Mho0 => <-.
exact: abelem_homocyclic (Ohm1_abelem pG cGG).
Qed.
Lemma abelian_type_homocyclic G :
homocyclic G -> abelian_type G = nseq 'r(G) (exponent G).
Proof.
case/andP=> cGG; rewrite -size_abelian_type // /abelian_type.
rewrite -(prednK (cardG_gt0 G)) /=; case: andP => //= _; move: (tag _) => H.
by move/all_pred1P->; rewrite genGid size_nseq.
Qed.
Lemma abelian_type_abelem p G : p.-abelem G -> abelian_type G = nseq 'r(G) p.
Proof.
move=> abelG; rewrite (abelian_type_homocyclic (abelem_homocyclic abelG)).
have [-> | ntG] := eqVneq G 1%G; first by rewrite rank1.
congr nseq; apply/eqP; rewrite eqn_dvd; have [pG _ ->] := and3P abelG.
have [p_pr] := pgroup_pdiv pG ntG; case/Cauchy=> // x Gx <- _.
exact: dvdn_exponent.
Qed.
Lemma max_card_abelian G :
abelian G -> #|G| <= exponent G ^ 'r(G) ?= iff homocyclic G.
Proof.
move=> cGG; have [b defG def_tG] := abelian_structure cGG.
have Gb: all [in G] b.
apply/allP=> x b_x; rewrite -(bigdprodWY defG); have [b1 b2] := splitPr b_x.
by rewrite big_cat big_cons /= mem_gen // setUCA inE cycle_id.
have ->: homocyclic G = all (pred1 (exponent G)) (abelian_type G).
rewrite /homocyclic cGG /abelian_type; case: #|G| => //= n.
by move: (_ (tag _)) => t; case: ifP => //= _; rewrite genGid eqxx.
rewrite -size_abelian_type // -{}def_tG -{defG}(bigdprod_card defG) size_map.
rewrite unlock; elim: b Gb => //= x b IHb; case/andP=> Gx Gb.
have eGgt0: exponent G > 0 := exponent_gt0 G.
have le_x_G: #[x] <= exponent G by rewrite dvdn_leq ?dvdn_exponent.
have:= leqif_mul (leqif_eq le_x_G) (IHb Gb).
by rewrite -expnS expn_eq0 eqn0Ngt eGgt0.
Qed.
Lemma card_homocyclic G : homocyclic G -> #|G| = (exponent G ^ 'r(G))%N.
Proof.
by move=> homG; have [cGG _] := andP homG; apply/eqP; rewrite max_card_abelian.
Qed.
Lemma abelian_type_dprod_homocyclic p K H G :
K \x H = G -> p.-group G -> homocyclic G ->
abelian_type K = nseq 'r(K) (exponent G)
/\ abelian_type H = nseq 'r(H) (exponent G).
Proof.
move=> defG pG homG; have [cGG _] := andP homG.
have /mulG_sub[sKG sHG]: K * H = G by case/dprodP: defG.
have [cKK cHH] := (abelianS sKG cGG, abelianS sHG cGG).
suffices: all (pred1 (exponent G)) (abelian_type K ++ abelian_type H).
rewrite all_cat => /andP[/all_pred1P-> /all_pred1P->].
by rewrite !size_abelian_type.
suffices def_atG: abelian_type K ++ abelian_type H =i abelian_type G.
rewrite (eq_all_r def_atG); apply/all_pred1P.
by rewrite size_abelian_type // -abelian_type_homocyclic.
have [bK defK atK] := abelian_structure cKK.
have [bH defH atH] := abelian_structure cHH.
apply/perm_mem; rewrite perm_sym -atK -atH -map_cat.
apply: (abelian_type_pgroup pG); first by rewrite big_cat defK defH.
have: all [pred m | m > 1] (map order (bK ++ bH)).
by rewrite map_cat all_cat atK atH !abelian_type_gt1.
by rewrite all_map (eq_all (@order_gt1 _)) all_predC has_pred1.
Qed.
Lemma dprod_homocyclic p K H G :
K \x H = G -> p.-group G -> homocyclic G -> homocyclic K /\ homocyclic H.
Proof.
move=> defG pG homG; have [cGG _] := andP homG.
have /mulG_sub[sKG sHG]: K * H = G by case/dprodP: defG.
have [abtK abtH] := abelian_type_dprod_homocyclic defG pG homG.
by rewrite /homocyclic !(abelianS _ cGG) // abtK abtH !constant_nseq.
Qed.
Lemma exponent_dprod_homocyclic p K H G :
K \x H = G -> p.-group G -> homocyclic G -> K :!=: 1 ->
exponent K = exponent G.
Proof.
move=> defG pG homG ntK; have [homK _] := dprod_homocyclic defG pG homG.
have [] := abelian_type_dprod_homocyclic defG pG homG.
by rewrite abelian_type_homocyclic // -['r(K)]prednK ?rank_gt0 => [[]|].
Qed.
End AbelianStructure.
Arguments abelian_type {gT} A%_g.
Arguments homocyclic {gT} A%_g.
Section IsogAbelian.
Variables aT rT : finGroupType.
Implicit Type (gT : finGroupType) (D G : {group aT}) (H : {group rT}).
Lemma isog_abelian_type G H : isog G H -> abelian_type G = abelian_type H.
Proof.
pose lnO p n gT (A : {set gT}) := logn p #|'Ohm_n.+1(A) : 'Ohm_n(A)|.
pose lni i p gT (A : {set gT}) := \max_(e < logn p #|A| | i < lnO p e _ A) e.+1.
suffices{G} nth_abty gT (G : {group gT}) i:
abelian G -> i < size (abelian_type G) ->
nth 1%N (abelian_type G) i = (\prod_(p < #|G|.+1) p ^ lni i p _ G)%N.
- move=> isoGH; case cGG: (abelian G); last first.
rewrite /abelian_type -(prednK (cardG_gt0 G)) -(prednK (cardG_gt0 H)) /=.
by rewrite {1}(genGid G) {1}(genGid H) -(isog_abelian isoGH) cGG.
have cHH: abelian H by rewrite -(isog_abelian isoGH).
have eq_sz: size (abelian_type G) = size (abelian_type H).
by rewrite !size_abelian_type ?(isog_rank isoGH).
apply: (@eq_from_nth _ 1%N) => // i lt_i_G; rewrite !nth_abty // -?eq_sz //.
rewrite /lni (card_isog isoGH); apply: eq_bigr => p _; congr (p ^ _)%N.
apply: eq_bigl => e; rewrite /lnO -!divgS ?(Ohm_leq _ (leqnSn _)) //=.
by have:= card_isog (gFisog _ isoGH) => /= eqF; rewrite !eqF.
move=> cGG.
have (p): path leq 0 (map (logn p) (rev (abelian_type G))).
move: (abelian_type_gt1 G) (abelian_type_dvdn_sorted G).
case: abelian_type => //= m t; rewrite rev_cons map_rcons.
elim: t m => //= n t IHt m /andP[/ltnW m_gt0 nt_gt1].
rewrite -cats1 cat_path rev_cons map_rcons last_rcons /=.
by case/andP=> /dvdn_leq_log-> // /IHt->.
have{cGG} [b defG <- b_sorted] := abelian_structure cGG.
rewrite size_map => ltib; rewrite (nth_map 1 _ _ ltib); set x := nth 1 b i.
have Gx: x \in G.
have: x \in b by rewrite mem_nth.
rewrite -(bigdprodWY defG); case/splitPr=> bl br.
by rewrite mem_gen // big_cat big_cons !inE cycle_id orbT.
have lexG: #[x] <= #|G| by rewrite dvdn_leq ?order_dvdG.
rewrite -[#[x]]partn_pi // (widen_partn _ lexG) big_mkord big_mkcond.
apply: eq_bigr => p _; transitivity (p ^ logn p #[x])%N.
by rewrite -logn_gt0; case: posnP => // ->.
suffices lti_lnO e: (i < lnO p e _ G) = (e < logn p #[x]).
congr (p ^ _)%N; apply/eqP; rewrite eqn_leq andbC; apply/andP; split.
by apply/bigmax_leqP=> e; rewrite lti_lnO.
have [-> //|logx_gt0] := posnP (logn p #[x]).
have lexpG: (logn p #[x]).-1 < logn p #|G|.
by rewrite prednK // dvdn_leq_log ?order_dvdG.
by rewrite (bigmax_sup (Ordinal lexpG)) ?(prednK, lti_lnO).
rewrite /lnO -(count_logn_dprod_cycle _ _ defG).
case: (ltnP e) (b_sorted p) => [lt_e_x | le_x_e].
rewrite -(cat_take_drop i.+1 b) -map_rev rev_cat !map_cat cat_path.
case/andP=> _ ordb; rewrite count_cat ((count _ _ =P i.+1) _) ?leq_addr //.
rewrite -{2}(size_takel ltib) -all_count.
move: ordb; rewrite (take_nth 1 ltib) -/x rev_rcons all_rcons /= lt_e_x.
case/andP=> _ /=; move/(order_path_min leq_trans); apply: contraLR.
rewrite -!has_predC !has_map; case/hasP=> y b_y /= le_y_e; apply/hasP.
by exists y; rewrite ?mem_rev //=; apply: contra le_y_e; apply: leq_trans.
rewrite -(cat_take_drop i b) -map_rev rev_cat !map_cat cat_path.
case/andP=> ordb _; rewrite count_cat -{1}(size_takel (ltnW ltib)) ltnNge.
rewrite addnC ((count _ _ =P 0) _) ?count_size //.
rewrite eqn0Ngt -has_count; apply/hasPn=> y b_y /=; rewrite -leqNgt.
apply: leq_trans le_x_e; have ->: x = last x (rev (drop i b)).
by rewrite (drop_nth 1 ltib) rev_cons last_rcons.
rewrite -mem_rev in b_y; case/splitPr: (rev _) / b_y ordb => b1 b2.
rewrite !map_cat cat_path last_cat /=; case/and3P=> _ _.
move/(order_path_min leq_trans); case/lastP: b2 => // b3 x'.
by move/allP; apply; rewrite ?map_f ?last_rcons ?mem_rcons ?mem_head.
Qed.
Lemma eq_abelian_type_isog G H :
abelian G -> abelian H -> isog G H = (abelian_type G == abelian_type H).
Proof.
move=> cGG cHH; apply/idP/eqP; first exact: isog_abelian_type.
have{cGG} [bG defG <-] := abelian_structure cGG.
have{cHH} [bH defH <-] := abelian_structure cHH.
elim: bG bH G H defG defH => [|x bG IHb] [|y bH] // G H.
rewrite !big_nil => <- <- _.
by rewrite isog_cyclic_card ?cyclic1 ?cards1.
rewrite !big_cons => defG defH /= [eqxy eqb].
apply: (isog_dprod defG defH).
by rewrite isog_cyclic_card ?cycle_cyclic -?orderE ?eqxy /=.
case/dprodP: defG => [[_ G' _ defG]] _ _ _; rewrite defG.
case/dprodP: defH => [[_ H' _ defH]] _ _ _; rewrite defH.
exact: IHb eqb.
Qed.
Lemma isog_abelem_card p G H :
p.-abelem G -> isog G H = p.-abelem H && (#|H| == #|G|).
Proof.
move=> abelG; apply/idP/andP=> [isoGH | [abelH eqGH]].
by rewrite -(isog_abelem isoGH) (card_isog isoGH).
rewrite eq_abelian_type_isog ?(@abelem_abelian _ p) //.
by rewrite !(@abelian_type_abelem _ p) ?(@rank_abelem _ p) // (eqP eqGH).
Qed.
Variables (D : {group aT}) (f : {morphism D >-> rT}).
Lemma morphim_rank_abelian G : abelian G -> 'r(f @* G) <= 'r(G).
Proof.
move=> cGG; have sHG := subsetIr D G; apply: leq_trans (rankS sHG).
rewrite -!grank_abelian ?morphim_abelian ?(abelianS sHG) //=.
by rewrite -morphimIdom morphim_grank ?subsetIl.
Qed.
Lemma morphim_p_rank_abelian p G : abelian G -> 'r_p(f @* G) <= 'r_p(G).
Proof.
move=> cGG; have sHG := subsetIr D G; apply: leq_trans (p_rankS p sHG).
have cHH := abelianS sHG cGG; rewrite -morphimIdom /=; set H := D :&: G.
have sylP := nilpotent_pcore_Hall p (abelian_nil cHH).
have sPH := pHall_sub sylP.
have sPD: 'O_p(H) \subset D by rewrite (subset_trans sPH) ?subsetIl.
rewrite -(p_rank_Sylow (morphim_pHall f sPD sylP)) -(p_rank_Sylow sylP) //.
rewrite -!rank_pgroup ?morphim_pgroup ?pcore_pgroup //.
by rewrite morphim_rank_abelian ?(abelianS sPH).
Qed.
Lemma isog_homocyclic G H : G \isog H -> homocyclic G = homocyclic H.
Proof.
move=> isoGH.
by rewrite /homocyclic (isog_abelian isoGH) (isog_abelian_type isoGH).
Qed.
End IsogAbelian.
Section QuotientRank.
Variables (gT : finGroupType) (p : nat) (G H : {group gT}).
Hypothesis cGG : abelian G.
Lemma quotient_rank_abelian : 'r(G / H) <= 'r(G).
Proof. exact: morphim_rank_abelian. Qed.
Lemma quotient_p_rank_abelian : 'r_p(G / H) <= 'r_p(G).
Proof. exact: morphim_p_rank_abelian. Qed.
End QuotientRank.
Section FimModAbelem.
Import GRing.Theory FinRing.Theory.
Lemma fin_lmod_pchar_abelem p (R : nzRingType) (V : finLmodType R):
p \in [pchar R]%R -> p.-abelem [set: V].
Proof.
case/andP=> p_pr /eqP-pR0; apply/abelemP=> //.
by split=> [|v _]; rewrite ?zmod_abelian // zmodXgE -scaler_nat pR0 scale0r.
Qed.
Lemma fin_Fp_lmod_abelem p (V : finLmodType 'F_p) :
prime p -> p.-abelem [set: V].
Proof. by move/pchar_Fp/fin_lmod_pchar_abelem->. Qed.
Lemma fin_ring_pchar_abelem p (R : finNzRingType) :
p \in [pchar R]%R -> p.-abelem [set: R].
Proof. exact: fin_lmod_pchar_abelem R^o. Qed.
End FimModAbelem.
#[deprecated(since="mathcomp 2.4.0", note="Use fin_lmod_pchar_abelem instead.")]
Notation fin_lmod_char_abelem := (fin_lmod_pchar_abelem) (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use fin_ring_pchar_abelem instead.")]
Notation fin_ring_char_abelem := (fin_ring_pchar_abelem) (only parsing).
|
seq.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.
(******************************************************************************)
(* The seq type is the ssreflect type for sequences; it is an alias for the *)
(* standard Coq list type. The ssreflect library equips it with many *)
(* operations, as well as eqType and predType (and, later, choiceType) *)
(* structures. The operations are geared towards reflection: they generally *)
(* expect and provide boolean predicates, e.g., the membership predicate *)
(* expects an eqType. To avoid any confusion we do not Import the Coq List *)
(* module. *)
(* As there is no true subtyping in Coq, we don't use a type for non-empty *)
(* sequences; rather, we pass explicitly the head and tail of the sequence. *)
(* The empty sequence is especially bothersome for subscripting, since it *)
(* forces us to pass a default value. This default value can often be hidden *)
(* by a notation. *)
(* Here is the list of seq operations: *)
(* ** Constructors: *)
(* seq T == the type of sequences of items of type T. *)
(* bitseq == seq bool. *)
(* [::], nil, Nil T == the empty sequence (of type T). *)
(* x :: s, cons x s, Cons T x s == the sequence x followed by s (of type T). *)
(* [:: x] == the singleton sequence. *)
(* [:: x_0; ...; x_n] == the explicit sequence of the x_i. *)
(* [:: x_0, ..., x_n & s] == the sequence of the x_i, followed by s. *)
(* rcons s x == the sequence s, followed by x. *)
(* All of the above, except rcons, can be used in patterns. We define a view *)
(* lastP and an induction principle last_ind that can be used to decompose *)
(* or traverse a sequence in a right to left order. The view lemma lastP has *)
(* a dependent family type, so the ssreflect tactic case/lastP: p => [|p' x] *)
(* will generate two subgoals in which p has been replaced by [::] and by *)
(* rcons p' x, respectively. *)
(* ** Factories: *)
(* nseq n x == a sequence of n x's. *)
(* ncons n x s == a sequence of n x's, followed by s. *)
(* seqn n x_0 ... x_n-1 == the sequence of the x_i; can be partially applied. *)
(* iota m n == the sequence m, m + 1, ..., m + n - 1. *)
(* mkseq f n == the sequence f 0, f 1, ..., f (n - 1). *)
(* ** Sequential access: *)
(* head x0 s == the head (zero'th item) of s if s is non-empty, else x0. *)
(* ohead s == None if s is empty, else Some x when the head of s is x. *)
(* behead s == s minus its head, i.e., s' if s = x :: s', else [::]. *)
(* last x s == the last element of x :: s (which is non-empty). *)
(* belast x s == x :: s minus its last item. *)
(* ** Dimensions: *)
(* size s == the number of items (length) in s. *)
(* shape ss == the sequence of sizes of the items of the sequence of *)
(* sequences ss. *)
(* ** Random access: *)
(* nth x0 s i == the item i of s (numbered from 0), or x0 if s does *)
(* not have at least i+1 items (i.e., size x <= i) *)
(* s`_i == standard notation for nth x0 s i for a default x0, *)
(* e.g., 0 for rings. *)
(* onth s i == Some x if x is the i^th idem of s (numbered from 0), *)
(* or None if size s <= i) *)
(* set_nth x0 s i y == s where item i has been changed to y; if s does not *)
(* have an item i, it is first padded with copies of x0 *)
(* to size i+1. *)
(* incr_nth s i == the nat sequence s with item i incremented (s is *)
(* first padded with 0's to size i+1, if needed). *)
(* ** Predicates: *)
(* nilp s <=> s is [::]. *)
(* := (size s == 0). *)
(* x \in s == x appears in s (this requires an eqType for T). *)
(* index x s == the first index at which x appears in s, or size s if *)
(* x \notin s. *)
(* has a s <=> a holds for some item in s, where a is an applicative *)
(* bool predicate. *)
(* all a s <=> a holds for all items in s. *)
(* 'has_aP <-> the view reflect (exists2 x, x \in s & A x) (has a s), *)
(* where aP x : reflect (A x) (a x). *)
(* 'all_aP <=> the view for reflect {in s, forall x, A x} (all a s). *)
(* all2 r s t <=> the (bool) relation r holds for all _respective_ items *)
(* in s and t, which must also have the same size, i.e., *)
(* for s := [:: x1; ...; x_m] and t := [:: y1; ...; y_n], *)
(* the condition [&& r x_1 y_1, ..., r x_n y_n & m == n]. *)
(* find p s == the index of the first item in s for which p holds, *)
(* or size s if no such item is found. *)
(* count p s == the number of items of s for which p holds. *)
(* count_mem x s == the multiplicity of x in s, i.e., count (pred1 x) s. *)
(* tally s == a tally of s, i.e., a sequence of (item, multiplicity) *)
(* pairs for all items in sequence s (without duplicates). *)
(* incr_tally bs x == increment the multiplicity of x in the tally bs, or add *)
(* x with multiplicity 1 at then end if x is not in bs. *)
(* bs \is a wf_tally <=> bs is well-formed tally, with no duplicate items or *)
(* null multiplicities. *)
(* tally_seq bs == the expansion of a tally bs into a sequence where each *)
(* (x, n) pair expands into a sequence of n x's. *)
(* constant s <=> all items in s are identical (trivial if s = [::]). *)
(* uniq s <=> all the items in s are pairwise different. *)
(* subseq s1 s2 <=> s1 is a subsequence of s2, i.e., s1 = mask m s2 for *)
(* some m : bitseq (see below). *)
(* infix s1 s2 <=> s1 is a contiguous subsequence of s2, i.e., *)
(* s ++ s1 ++ s' = s2 for some sequences s, s'. *)
(* prefix s1 s2 <=> s1 is a subchain of s2 appearing at the beginning *)
(* of s2. *)
(* suffix s1 s2 <=> s1 is a subchain of s2 appearing at the end of s2. *)
(* infix_index s1 s2 <=> the first index at which s1 appears in s2, *)
(* or (size s2).+1 if infix s1 s2 is false. *)
(* perm_eq s1 s2 <=> s2 is a permutation of s1, i.e., s1 and s2 have the *)
(* items (with the same repetitions), but possibly in a *)
(* different order. *)
(* perm_eql s1 s2 <-> s1 and s2 behave identically on the left of perm_eq. *)
(* perm_eqr s1 s2 <-> s1 and s2 behave identically on the right of perm_eq. *)
(* --> These left/right transitive versions of perm_eq make it easier to *)
(* chain a sequence of equivalences. *)
(* permutations s == a duplicate-free list of all permutations of s. *)
(* ** Filtering: *)
(* filter p s == the subsequence of s consisting of all the items *)
(* for which the (boolean) predicate p holds. *)
(* rem x s == the subsequence of s, where the first occurrence *)
(* of x has been removed (compare filter (predC1 x) s *)
(* where ALL occurrences of x are removed). *)
(* undup s == the subsequence of s containing only the first *)
(* occurrence of each item in s, i.e., s with all *)
(* duplicates removed. *)
(* mask m s == the subsequence of s selected by m : bitseq, with *)
(* item i of s selected by bit i in m (extra items or *)
(* bits are ignored. *)
(* ** Surgery: *)
(* s1 ++ s2, cat s1 s2 == the concatenation of s1 and s2. *)
(* take n s == the sequence containing only the first n items of s *)
(* (or all of s if size s <= n). *)
(* drop n s == s minus its first n items ([::] if size s <= n) *)
(* rot n s == s rotated left n times (or s if size s <= n). *)
(* := drop n s ++ take n s *)
(* rotr n s == s rotated right n times (or s if size s <= n). *)
(* rev s == the (linear time) reversal of s. *)
(* catrev s1 s2 == the reversal of s1 followed by s2 (this is the *)
(* recursive form of rev). *)
(* ** Dependent iterator: for s : seq S and t : S -> seq T *)
(* [seq E | x <- s, y <- t] := flatten [seq [seq E | x <- t] | y <- s] *)
(* == the sequence of all the f x y, with x and y drawn from *)
(* s and t, respectively, in row-major order, *)
(* and where t is possibly dependent in elements of s *)
(* allpairs_dep f s t := self expanding definition for *)
(* [seq f x y | x <- s, y <- t y] *)
(* ** Iterators: for s == [:: x_1, ..., x_n], t == [:: y_1, ..., y_m], *)
(* allpairs f s t := same as allpairs_dep but where t is non dependent, *)
(* i.e. self expanding definition for *)
(* [seq f x y | x <- s, y <- t] *)
(* := [:: f x_1 y_1; ...; f x_1 y_m; f x_2 y_1; ...; f x_n y_m] *)
(* allrel r xs ys := all [pred x | all (r x) ys] xs *)
(* <=> r x y holds whenever x is in xs and y is in ys *)
(* all2rel r xs := allrel r xs xs *)
(* <=> the proposition r x y holds for all possible x, y in xs.*)
(* pairwise r xs <=> the relation r holds for any i-th and j-th element of *)
(* xs such that i < j. *)
(* map f s == the sequence [:: f x_1, ..., f x_n]. *)
(* pmap pf s == the sequence [:: y_i1, ..., y_ik] where i1 < ... < ik, *)
(* pf x_i = Some y_i, and pf x_j = None iff j is not in *)
(* {i1, ..., ik}. *)
(* foldr f a s == the right fold of s by f (i.e., the natural iterator). *)
(* := f x_1 (f x_2 ... (f x_n a)) *)
(* sumn s == x_1 + (x_2 + ... + (x_n + 0)) (when s : seq nat). *)
(* foldl f a s == the left fold of s by f. *)
(* := f (f ... (f a x_1) ... x_n-1) x_n *)
(* scanl f a s == the sequence of partial accumulators of foldl f a s. *)
(* := [:: f a x_1; ...; foldl f a s] *)
(* pairmap f a s == the sequence of f applied to consecutive items in a :: s. *)
(* := [:: f a x_1; f x_1 x_2; ...; f x_n-1 x_n] *)
(* zip s t == itemwise pairing of s and t (dropping any extra items). *)
(* := [:: (x_1, y_1); ...; (x_mn, y_mn)] with mn = minn n m. *)
(* unzip1 s == [:: (x_1).1; ...; (x_n).1] when s : seq (S * T). *)
(* unzip2 s == [:: (x_1).2; ...; (x_n).2] when s : seq (S * T). *)
(* flatten s == x_1 ++ ... ++ x_n ++ [::] when s : seq (seq T). *)
(* reshape r s == s reshaped into a sequence of sequences whose sizes are *)
(* given by r (truncating if s is too long or too short). *)
(* := [:: [:: x_1; ...; x_r1]; *)
(* [:: x_(r1 + 1); ...; x_(r0 + r1)]; *)
(* ...; *)
(* [:: x_(r1 + ... + r(k-1) + 1); ...; x_(r0 + ... rk)]] *)
(* flatten_index sh r c == the index, in flatten ss, of the item of indexes *)
(* (r, c) in any sequence of sequences ss of shape sh *)
(* := sh_1 + sh_2 + ... + sh_r + c *)
(* reshape_index sh i == the index, in reshape sh s, of the sequence *)
(* containing the i-th item of s. *)
(* reshape_offset sh i == the offset, in the (reshape_index sh i)-th *)
(* sequence of reshape sh s of the i-th item of s *)
(* ** Notation for manifest comprehensions: *)
(* [seq x <- s | C] := filter (fun x => C) s. *)
(* [seq E | x <- s] := map (fun x => E) s. *)
(* [seq x <- s | C1 & C2] := [seq x <- s | C1 && C2]. *)
(* [seq E | x <- s & C] := [seq E | x <- [seq x | C]]. *)
(* --> The above allow optional type casts on the eigenvariables, as in *)
(* [seq x : T <- s | C] or [seq E | x : T <- s, y : U <- t]. The cast may be *)
(* needed as type inference considers E or C before s. *)
(* We are quite systematic in providing lemmas to rewrite any composition *)
(* of two operations. "rev", whose simplifications are not natural, is *)
(* protected with simpl never. *)
(* ** The following are equivalent: *)
(* [<-> P0; P1; ..; Pn] <-> P0, P1, ..., Pn are all equivalent. *)
(* := P0 -> P1 -> ... -> Pn -> P0 *)
(* if T : [<-> P0; P1; ..; Pn] is such an equivalence, and i, j are in nat *)
(* then T i j is a proof of the equivalence Pi <-> Pj between Pi and Pj; *)
(* when i (resp. j) is out of bounds, Pi (resp. Pj) defaults to P0. *)
(* The tactic tfae splits the goal into n+1 implications to prove. *)
(* An example of use can be found in fingraph theorem orbitPcycle. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope seq_scope.
Reserved Notation "[ '<->' P0 ; P1 ; .. ; Pn ]"
(format "[ '<->' '[' P0 ; '/' P1 ; '/' .. ; '/' Pn ']' ]").
Delimit Scope seq_scope with SEQ.
Open Scope seq_scope.
(* Inductive seq (T : Type) : Type := Nil | Cons of T & seq T. *)
Notation seq := list.
Bind Scope seq_scope with list.
Arguments cons {T%_type} x s%_SEQ : rename.
Arguments nil {T%_type} : rename.
Notation Cons T := (@cons T) (only parsing).
Notation Nil T := (@nil T) (only parsing).
(* As :: and ++ are (improperly) declared in Init.datatypes, we only rebind *)
(* them here. *)
Infix "::" := cons : seq_scope.
Notation "[ :: ]" := nil (format "[ :: ]") : seq_scope.
Notation "[ :: x1 ]" := (x1 :: [::]) (format "[ :: x1 ]") : seq_scope.
Notation "[ :: x & s ]" := (x :: s) (only parsing) : seq_scope.
Notation "[ :: x1 , x2 , .. , xn & s ]" := (x1 :: x2 :: .. (xn :: s) ..)
(format
"'[hv' [ :: '[' x1 , '/' x2 , '/' .. , '/' xn ']' '/ ' & s ] ']'"
) : seq_scope.
Notation "[ :: x1 ; x2 ; .. ; xn ]" := (x1 :: x2 :: .. [:: xn] ..)
(format "[ :: '[' x1 ; '/' x2 ; '/' .. ; '/' xn ']' ]"
) : seq_scope.
Section Sequences.
Variable n0 : nat. (* numerical parameter for take, drop et al *)
Variable T : Type. (* must come before the implicit Type *)
Variable x0 : T. (* default for head/nth *)
Implicit Types x y z : T.
Implicit Types m n : nat.
Implicit Type s : seq T.
Fixpoint size s := if s is _ :: s' then (size s').+1 else 0.
Lemma size0nil s : size s = 0 -> s = [::]. Proof. by case: s. Qed.
Definition nilp s := size s == 0.
Lemma nilP s : reflect (s = [::]) (nilp s).
Proof. by case: s => [|x s]; constructor. Qed.
Definition ohead s := if s is x :: _ then Some x else None.
Definition head s := if s is x :: _ then x else x0.
Definition behead s := if s is _ :: s' then s' else [::].
Lemma size_behead s : size (behead s) = (size s).-1.
Proof. by case: s. Qed.
(* Factories *)
Definition ncons n x := iter n (cons x).
Definition nseq n x := ncons n x [::].
Lemma size_ncons n x s : size (ncons n x s) = n + size s.
Proof. by elim: n => //= n ->. Qed.
Lemma size_nseq n x : size (nseq n x) = n.
Proof. by rewrite size_ncons addn0. Qed.
(* n-ary, dependently typed constructor. *)
Fixpoint seqn_type n := if n is n'.+1 then T -> seqn_type n' else seq T.
Fixpoint seqn_rec f n : seqn_type n :=
if n is n'.+1 return seqn_type n then
fun x => seqn_rec (fun s => f (x :: s)) n'
else f [::].
Definition seqn := seqn_rec id.
(* Sequence catenation "cat". *)
Fixpoint cat s1 s2 := if s1 is x :: s1' then x :: s1' ++ s2 else s2
where "s1 ++ s2" := (cat s1 s2) : seq_scope.
Lemma cat0s s : [::] ++ s = s. Proof. by []. Qed.
Lemma cat1s x s : [:: x] ++ s = x :: s. Proof. by []. Qed.
Lemma cat_cons x s1 s2 : (x :: s1) ++ s2 = x :: s1 ++ s2. Proof. by []. Qed.
Lemma cat_nseq n x s : nseq n x ++ s = ncons n x s.
Proof. by elim: n => //= n ->. Qed.
Lemma nseqD n1 n2 x : nseq (n1 + n2) x = nseq n1 x ++ nseq n2 x.
Proof. by rewrite cat_nseq /nseq /ncons iterD. Qed.
Lemma cats0 s : s ++ [::] = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma catA s1 s2 s3 : s1 ++ s2 ++ s3 = (s1 ++ s2) ++ s3.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma size_cat s1 s2 : size (s1 ++ s2) = size s1 + size s2.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma cat_nilp s1 s2 : nilp (s1 ++ s2) = nilp s1 && nilp s2.
Proof. by case: s1. Qed.
(* last, belast, rcons, and last induction. *)
Fixpoint rcons s z := if s is x :: s' then x :: rcons s' z else [:: z].
Lemma rcons_cons x s z : rcons (x :: s) z = x :: rcons s z.
Proof. by []. Qed.
Lemma cats1 s z : s ++ [:: z] = rcons s z.
Proof. by elim: s => //= x s ->. Qed.
Fixpoint last x s := if s is x' :: s' then last x' s' else x.
Fixpoint belast x s := if s is x' :: s' then x :: (belast x' s') else [::].
Lemma lastI x s : x :: s = rcons (belast x s) (last x s).
Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed.
Lemma last_cons x y s : last x (y :: s) = last y s.
Proof. by []. Qed.
Lemma size_rcons s x : size (rcons s x) = (size s).+1.
Proof. by rewrite -cats1 size_cat addnC. Qed.
Lemma size_belast x s : size (belast x s) = size s.
Proof. by elim: s x => [|y s IHs] x //=; rewrite IHs. Qed.
Lemma last_cat x s1 s2 : last x (s1 ++ s2) = last (last x s1) s2.
Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed.
Lemma last_rcons x s z : last x (rcons s z) = z.
Proof. by rewrite -cats1 last_cat. Qed.
Lemma belast_cat x s1 s2 :
belast x (s1 ++ s2) = belast x s1 ++ belast (last x s1) s2.
Proof. by elim: s1 x => [|y s1 IHs] x //=; rewrite IHs. Qed.
Lemma belast_rcons x s z : belast x (rcons s z) = x :: s.
Proof. by rewrite lastI -!cats1 belast_cat. Qed.
Lemma cat_rcons x s1 s2 : rcons s1 x ++ s2 = s1 ++ x :: s2.
Proof. by rewrite -cats1 -catA. Qed.
Lemma rcons_cat x s1 s2 : rcons (s1 ++ s2) x = s1 ++ rcons s2 x.
Proof. by rewrite -!cats1 catA. Qed.
Variant last_spec : seq T -> Type :=
| LastNil : last_spec [::]
| LastRcons s x : last_spec (rcons s x).
Lemma lastP s : last_spec s.
Proof. case: s => [|x s]; [left | rewrite lastI; right]. Qed.
Lemma last_ind P :
P [::] -> (forall s x, P s -> P (rcons s x)) -> forall s, P s.
Proof.
move=> Hnil Hlast s; rewrite -(cat0s s).
elim: s [::] Hnil => [|x s2 IHs] s1 Hs1; first by rewrite cats0.
by rewrite -cat_rcons; apply/IHs/Hlast.
Qed.
(* Sequence indexing. *)
Fixpoint nth s n {struct n} :=
if s is x :: s' then if n is n'.+1 then @nth s' n' else x else x0.
Fixpoint set_nth s n y {struct n} :=
if s is x :: s' then if n is n'.+1 then x :: @set_nth s' n' y else y :: s'
else ncons n x0 [:: y].
Lemma nth0 s : nth s 0 = head s. Proof. by []. Qed.
Lemma nth_default s n : size s <= n -> nth s n = x0.
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma if_nth s b n : b || (size s <= n) ->
(if b then nth s n else x0) = nth s n.
Proof. by case: leqP; case: ifP => //= *; rewrite nth_default. Qed.
Lemma nth_nil n : nth [::] n = x0.
Proof. by case: n. Qed.
Lemma nth_seq1 n x : nth [:: x] n = if n == 0 then x else x0.
Proof. by case: n => [|[]]. Qed.
Lemma last_nth x s : last x s = nth (x :: s) (size s).
Proof. by elim: s x => [|y s IHs] x /=. Qed.
Lemma nth_last s : nth s (size s).-1 = last x0 s.
Proof. by case: s => //= x s; rewrite last_nth. Qed.
Lemma nth_behead s n : nth (behead s) n = nth s n.+1.
Proof. by case: s n => [|x s] [|n]. Qed.
Lemma nth_cat s1 s2 n :
nth (s1 ++ s2) n = if n < size s1 then nth s1 n else nth s2 (n - size s1).
Proof. by elim: s1 n => [|x s1 IHs] []. Qed.
Lemma nth_rcons s x n :
nth (rcons s x) n =
if n < size s then nth s n else if n == size s then x else x0.
Proof. by elim: s n => [|y s IHs] [] //=; apply: nth_nil. Qed.
Lemma nth_rcons_default s i : nth (rcons s x0) i = nth s i.
Proof.
by rewrite nth_rcons; case: ltngtP => //[/ltnW ?|->]; rewrite nth_default.
Qed.
Lemma nth_ncons m x s n :
nth (ncons m x s) n = if n < m then x else nth s (n - m).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma nth_nseq m x n : nth (nseq m x) n = (if n < m then x else x0).
Proof. by elim: m n => [|m IHm] []. Qed.
Lemma eq_from_nth s1 s2 :
size s1 = size s2 -> (forall i, i < size s1 -> nth s1 i = nth s2 i) ->
s1 = s2.
Proof.
elim: s1 s2 => [|x1 s1 IHs1] [|x2 s2] //= [eq_sz] eq_s12.
by rewrite [x1](eq_s12 0) // (IHs1 s2) // => i; apply: (eq_s12 i.+1).
Qed.
Lemma size_set_nth s n y : size (set_nth s n y) = maxn n.+1 (size s).
Proof.
rewrite maxnC; elim: s n => [|x s IHs] [|n] //=.
- by rewrite size_ncons addn1.
- by rewrite IHs maxnSS.
Qed.
Lemma set_nth_nil n y : set_nth [::] n y = ncons n x0 [:: y].
Proof. by case: n. Qed.
Lemma nth_set_nth s n y : nth (set_nth s n y) =1 [eta nth s with n |-> y].
Proof.
elim: s n => [|x s IHs] [|n] [|m] //=; rewrite ?nth_nil ?IHs // nth_ncons eqSS.
case: ltngtP => // [lt_nm | ->]; last by rewrite subnn.
by rewrite nth_default // subn_gt0.
Qed.
Lemma set_set_nth s n1 y1 n2 y2 (s2 := set_nth s n2 y2) :
set_nth (set_nth s n1 y1) n2 y2 = if n1 == n2 then s2 else set_nth s2 n1 y1.
Proof.
have [-> | ne_n12] := eqVneq.
apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnA maxnn.
by do 2!rewrite !nth_set_nth /=; case: eqP.
apply: eq_from_nth => [|i _]; first by rewrite !size_set_nth maxnCA.
by do 2!rewrite !nth_set_nth /=; case: eqP => // ->; case: eqVneq ne_n12.
Qed.
(* find, count, has, all. *)
Section SeqFind.
Variable a : pred T.
Fixpoint find s := if s is x :: s' then if a x then 0 else (find s').+1 else 0.
Fixpoint filter s :=
if s is x :: s' then if a x then x :: filter s' else filter s' else [::].
Fixpoint count s := if s is x :: s' then a x + count s' else 0.
Fixpoint has s := if s is x :: s' then a x || has s' else false.
Fixpoint all s := if s is x :: s' then a x && all s' else true.
Lemma size_filter s : size (filter s) = count s.
Proof. by elim: s => //= x s <-; case (a x). Qed.
Lemma has_count s : has s = (0 < count s).
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma size_filter_gt0 s : (size (filter s) > 0) = (has s).
Proof. by rewrite size_filter -has_count. Qed.
Lemma count_size s : count s <= size s.
Proof. by elim: s => //= x s; case: (a x); last apply: leqW. Qed.
Lemma all_count s : all s = (count s == size s).
Proof.
elim: s => //= x s; case: (a x) => _ //=.
by rewrite add0n eqn_leq andbC ltnNge count_size.
Qed.
Lemma filter_all s : all (filter s).
Proof. by elim: s => //= x s IHs; case: ifP => //= ->. Qed.
Lemma all_filterP s : reflect (filter s = s) (all s).
Proof.
apply: (iffP idP) => [| <-]; last exact: filter_all.
by elim: s => //= x s IHs /andP[-> Hs]; rewrite IHs.
Qed.
Lemma filter_id s : filter (filter s) = filter s.
Proof. by apply/all_filterP; apply: filter_all. Qed.
Lemma has_find s : has s = (find s < size s).
Proof. by elim: s => //= x s IHs; case (a x); rewrite ?leqnn. Qed.
Lemma find_size s : find s <= size s.
Proof. by elim: s => //= x s IHs; case (a x). Qed.
Lemma find_cat s1 s2 :
find (s1 ++ s2) = if has s1 then find s1 else size s1 + find s2.
Proof.
by elim: s1 => //= x s1 IHs; case: (a x) => //; rewrite IHs (fun_if succn).
Qed.
Lemma has_nil : has [::] = false. Proof. by []. Qed.
Lemma has_seq1 x : has [:: x] = a x.
Proof. exact: orbF. Qed.
Lemma has_nseq n x : has (nseq n x) = (0 < n) && a x.
Proof. by elim: n => //= n ->; apply: andKb. Qed.
Lemma has_seqb (b : bool) x : has (nseq b x) = b && a x.
Proof. by rewrite has_nseq lt0b. Qed.
Lemma all_nil : all [::] = true. Proof. by []. Qed.
Lemma all_seq1 x : all [:: x] = a x.
Proof. exact: andbT. Qed.
Lemma all_nseq n x : all (nseq n x) = (n == 0) || a x.
Proof. by elim: n => //= n ->; apply: orKb. Qed.
Lemma all_nseqb (b : bool) x : all (nseq b x) = b ==> a x.
Proof. by rewrite all_nseq eqb0 implybE. Qed.
Lemma filter_nseq n x : filter (nseq n x) = nseq (a x * n) x.
Proof. by elim: n => /= [|n ->]; case: (a x). Qed.
Lemma count_nseq n x : count (nseq n x) = a x * n.
Proof. by rewrite -size_filter filter_nseq size_nseq. Qed.
Lemma find_nseq n x : find (nseq n x) = ~~ a x * n.
Proof. by elim: n => /= [|n ->]; case: (a x). Qed.
Lemma nth_find s : has s -> a (nth s (find s)).
Proof. by elim: s => //= x s IHs; case a_x: (a x). Qed.
Lemma before_find s i : i < find s -> a (nth s i) = false.
Proof. by elim: s i => //= x s IHs; case: ifP => // a'x [|i] // /(IHs i). Qed.
Lemma hasNfind s : ~~ has s -> find s = size s.
Proof. by rewrite has_find; case: ltngtP (find_size s). Qed.
Lemma filter_cat s1 s2 : filter (s1 ++ s2) = filter s1 ++ filter s2.
Proof. by elim: s1 => //= x s1 ->; case (a x). Qed.
Lemma filter_rcons s x :
filter (rcons s x) = if a x then rcons (filter s) x else filter s.
Proof. by rewrite -!cats1 filter_cat /=; case (a x); rewrite /= ?cats0. Qed.
Lemma count_cat s1 s2 : count (s1 ++ s2) = count s1 + count s2.
Proof. by rewrite -!size_filter filter_cat size_cat. Qed.
Lemma has_cat s1 s2 : has (s1 ++ s2) = has s1 || has s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs orbA. Qed.
Lemma has_rcons s x : has (rcons s x) = a x || has s.
Proof. by rewrite -cats1 has_cat has_seq1 orbC. Qed.
Lemma all_cat s1 s2 : all (s1 ++ s2) = all s1 && all s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs andbA. Qed.
Lemma all_rcons s x : all (rcons s x) = a x && all s.
Proof. by rewrite -cats1 all_cat all_seq1 andbC. Qed.
End SeqFind.
Lemma find_pred0 s : find pred0 s = size s. Proof. by []. Qed.
Lemma find_predT s : find predT s = 0.
Proof. by case: s. Qed.
Lemma eq_find a1 a2 : a1 =1 a2 -> find a1 =1 find a2.
Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed.
Lemma eq_filter a1 a2 : a1 =1 a2 -> filter a1 =1 filter a2.
Proof. by move=> Ea; elim=> //= x s IHs; rewrite Ea IHs. Qed.
Lemma eq_count a1 a2 : a1 =1 a2 -> count a1 =1 count a2.
Proof. by move=> Ea s; rewrite -!size_filter (eq_filter Ea). Qed.
Lemma eq_has a1 a2 : a1 =1 a2 -> has a1 =1 has a2.
Proof. by move=> Ea s; rewrite !has_count (eq_count Ea). Qed.
Lemma eq_all a1 a2 : a1 =1 a2 -> all a1 =1 all a2.
Proof. by move=> Ea s; rewrite !all_count (eq_count Ea). Qed.
Lemma all_filter (p q : pred T) xs :
all p (filter q xs) = all [pred i | q i ==> p i] xs.
Proof. by elim: xs => //= x xs <-; case: (q x). Qed.
Section SubPred.
Variable (a1 a2 : pred T).
Hypothesis s12 : subpred a1 a2.
Lemma sub_find s : find a2 s <= find a1 s.
Proof. by elim: s => //= x s IHs; case: ifP => // /(contraFF (@s12 x))->. Qed.
Lemma sub_has s : has a1 s -> has a2 s.
Proof. by rewrite !has_find; apply: leq_ltn_trans (sub_find s). Qed.
Lemma sub_count s : count a1 s <= count a2 s.
Proof.
by elim: s => //= x s; apply: leq_add; case a1x: (a1 x); rewrite // s12.
Qed.
Lemma sub_all s : all a1 s -> all a2 s.
Proof.
by rewrite !all_count !eqn_leq !count_size => /leq_trans-> //; apply: sub_count.
Qed.
End SubPred.
Lemma filter_pred0 s : filter pred0 s = [::]. Proof. by elim: s. Qed.
Lemma filter_predT s : filter predT s = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma filter_predI a1 a2 s : filter (predI a1 a2) s = filter a1 (filter a2 s).
Proof. by elim: s => //= x s ->; rewrite andbC; case: (a2 x). Qed.
Lemma count_pred0 s : count pred0 s = 0.
Proof. by rewrite -size_filter filter_pred0. Qed.
Lemma count_predT s : count predT s = size s.
Proof. by rewrite -size_filter filter_predT. Qed.
Lemma count_predUI a1 a2 s :
count (predU a1 a2) s + count (predI a1 a2) s = count a1 s + count a2 s.
Proof.
elim: s => //= x s IHs; rewrite /= addnACA [RHS]addnACA IHs.
by case: (a1 x) => //; rewrite addn0.
Qed.
Lemma count_predC a s : count a s + count (predC a) s = size s.
Proof. by elim: s => //= x s IHs; rewrite addnACA IHs; case: (a _). Qed.
Lemma count_filter a1 a2 s : count a1 (filter a2 s) = count (predI a1 a2) s.
Proof. by rewrite -!size_filter filter_predI. Qed.
Lemma has_pred0 s : has pred0 s = false.
Proof. by rewrite has_count count_pred0. Qed.
Lemma has_predT s : has predT s = (0 < size s).
Proof. by rewrite has_count count_predT. Qed.
Lemma has_predC a s : has (predC a) s = ~~ all a s.
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma has_predU a1 a2 s : has (predU a1 a2) s = has a1 s || has a2 s.
Proof. by elim: s => //= x s ->; rewrite -!orbA; do !bool_congr. Qed.
Lemma all_pred0 s : all pred0 s = (size s == 0).
Proof. by rewrite all_count count_pred0 eq_sym. Qed.
Lemma all_predT s : all predT s.
Proof. by rewrite all_count count_predT. Qed.
Lemma allT (a : pred T) s : (forall x, a x) -> all a s.
Proof. by move/eq_all->; apply/all_predT. Qed.
Lemma all_predC a s : all (predC a) s = ~~ has a s.
Proof. by elim: s => //= x s ->; case (a x). Qed.
Lemma all_predI a1 a2 s : all (predI a1 a2) s = all a1 s && all a2 s.
Proof.
apply: (can_inj negbK); rewrite negb_and -!has_predC -has_predU.
by apply: eq_has => x; rewrite /= negb_and.
Qed.
(* Surgery: drop, take, rot, rotr. *)
Fixpoint drop n s {struct s} :=
match s, n with
| _ :: s', n'.+1 => drop n' s'
| _, _ => s
end.
Lemma drop_behead : drop n0 =1 iter n0 behead.
Proof. by elim: n0 => [|n IHn] [|x s] //; rewrite iterSr -IHn. Qed.
Lemma drop0 s : drop 0 s = s. Proof. by case: s. Qed.
Lemma drop1 : drop 1 =1 behead. Proof. by case=> [|x [|y s]]. Qed.
Lemma drop_oversize n s : size s <= n -> drop n s = [::].
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma drop_size s : drop (size s) s = [::].
Proof. by rewrite drop_oversize // leqnn. Qed.
Lemma drop_cons x s :
drop n0 (x :: s) = if n0 is n.+1 then drop n s else x :: s.
Proof. by []. Qed.
Lemma size_drop s : size (drop n0 s) = size s - n0.
Proof. by elim: s n0 => [|x s IHs] []. Qed.
Lemma drop_cat s1 s2 :
drop n0 (s1 ++ s2) =
if n0 < size s1 then drop n0 s1 ++ s2 else drop (n0 - size s1) s2.
Proof. by elim: s1 n0 => [|x s1 IHs] []. Qed.
Lemma drop_size_cat n s1 s2 : size s1 = n -> drop n (s1 ++ s2) = s2.
Proof. by move <-; elim: s1 => //=; rewrite drop0. Qed.
Lemma nconsK n x : cancel (ncons n x) (drop n).
Proof. by elim: n => // -[]. Qed.
Lemma drop_drop s n1 n2 : drop n1 (drop n2 s) = drop (n1 + n2) s.
Proof. by elim: s n2 => // x s ihs [|n2]; rewrite ?drop0 ?addn0 ?addnS /=. Qed.
Fixpoint take n s {struct s} :=
match s, n with
| x :: s', n'.+1 => x :: take n' s'
| _, _ => [::]
end.
Lemma take0 s : take 0 s = [::]. Proof. by case: s. Qed.
Lemma take_oversize n s : size s <= n -> take n s = s.
Proof. by elim: s n => [|x s IHs] [|n] //= /IHs->. Qed.
Lemma take_size s : take (size s) s = s.
Proof. exact: take_oversize. Qed.
Lemma take_cons x s :
take n0 (x :: s) = if n0 is n.+1 then x :: (take n s) else [::].
Proof. by []. Qed.
Lemma drop_rcons s : n0 <= size s ->
forall x, drop n0 (rcons s x) = rcons (drop n0 s) x.
Proof. by elim: s n0 => [|y s IHs] []. Qed.
Lemma cat_take_drop s : take n0 s ++ drop n0 s = s.
Proof. by elim: s n0 => [|x s IHs] [|n] //=; rewrite IHs. Qed.
Lemma size_takel s : n0 <= size s -> size (take n0 s) = n0.
Proof.
by move/subKn; rewrite -size_drop -[in size s](cat_take_drop s) size_cat addnK.
Qed.
Lemma size_take s : size (take n0 s) = if n0 < size s then n0 else size s.
Proof.
have [le_sn | lt_ns] := leqP (size s) n0; first by rewrite take_oversize.
by rewrite size_takel // ltnW.
Qed.
Lemma size_take_min s : size (take n0 s) = minn n0 (size s).
Proof. exact: size_take. Qed.
Lemma take_cat s1 s2 :
take n0 (s1 ++ s2) =
if n0 < size s1 then take n0 s1 else s1 ++ take (n0 - size s1) s2.
Proof.
elim: s1 n0 => [|x s1 IHs] [|n] //=.
by rewrite ltnS subSS -(fun_if (cons x)) -IHs.
Qed.
Lemma take_size_cat n s1 s2 : size s1 = n -> take n (s1 ++ s2) = s1.
Proof. by move <-; elim: s1 => [|x s1 IHs]; rewrite ?take0 //= IHs. Qed.
Lemma takel_cat s1 s2 : n0 <= size s1 -> take n0 (s1 ++ s2) = take n0 s1.
Proof.
by rewrite take_cat; case: ltngtP => // ->; rewrite subnn take0 take_size cats0.
Qed.
Lemma nth_drop s i : nth (drop n0 s) i = nth s (n0 + i).
Proof.
rewrite -[s in RHS]cat_take_drop nth_cat size_take ltnNge.
case: ltnP => [?|le_s_n0]; rewrite ?(leq_trans le_s_n0) ?leq_addr ?addKn //=.
by rewrite drop_oversize // !nth_default.
Qed.
Lemma find_ltn p s i : has p (take i s) -> find p s < i.
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs. Qed.
Lemma has_take p s i : has p s -> has p (take i s) = (find p s < i).
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed.
Lemma has_take_leq (p : pred T) (s : seq T) i : i <= size s ->
has p (take i s) = (find p s < i).
Proof. by elim: s i => [|y s ihs] [|i]//=; case: (p _) => //= /ihs ->. Qed.
Lemma nth_take i : i < n0 -> forall s, nth (take n0 s) i = nth s i.
Proof.
move=> lt_i_n0 s; case lt_n0_s: (n0 < size s).
by rewrite -[s in RHS]cat_take_drop nth_cat size_take lt_n0_s /= lt_i_n0.
by rewrite -[s in LHS]cats0 take_cat lt_n0_s /= cats0.
Qed.
Lemma take_min i j s : take (minn i j) s = take i (take j s).
Proof. by elim: s i j => //= a l IH [|i] [|j] //=; rewrite minnSS IH. Qed.
Lemma take_takel i j s : i <= j -> take i (take j s) = take i s.
Proof. by move=> ?; rewrite -take_min (minn_idPl _). Qed.
Lemma take_taker i j s : j <= i -> take i (take j s) = take j s.
Proof. by move=> ?; rewrite -take_min (minn_idPr _). Qed.
Lemma take_drop i j s : take i (drop j s) = drop j (take (i + j) s).
Proof. by rewrite addnC; elim: s i j => // x s IHs [|i] [|j] /=. Qed.
Lemma takeD i j s : take (i + j) s = take i s ++ take j (drop i s).
Proof.
elim: i j s => [|i IHi] [|j] [|a s] //; first by rewrite take0 addn0 cats0.
by rewrite addSn /= IHi.
Qed.
Lemma takeC i j s : take i (take j s) = take j (take i s).
Proof. by rewrite -!take_min minnC. Qed.
Lemma take_nseq i j x : i <= j -> take i (nseq j x) = nseq i x.
Proof. by move=>/subnKC <-; rewrite nseqD take_size_cat // size_nseq. Qed.
Lemma drop_nseq i j x : drop i (nseq j x) = nseq (j - i) x.
Proof.
case: (leqP i j) => [/subnKC {1}<-|/ltnW j_le_i].
by rewrite nseqD drop_size_cat // size_nseq.
by rewrite drop_oversize ?size_nseq // (eqP j_le_i).
Qed.
(* drop_nth and take_nth below do NOT use the default n0, because the "n" *)
(* can be inferred from the condition, whereas the nth default value x0 *)
(* will have to be given explicitly (and this will provide "d" as well). *)
Lemma drop_nth n s : n < size s -> drop n s = nth s n :: drop n.+1 s.
Proof. by elim: s n => [|x s IHs] [|n] Hn //=; rewrite ?drop0 1?IHs. Qed.
Lemma take_nth n s : n < size s -> take n.+1 s = rcons (take n s) (nth s n).
Proof. by elim: s n => [|x s IHs] //= [|n] Hn /=; rewrite ?take0 -?IHs. Qed.
(* Rotation *)
Definition rot n s := drop n s ++ take n s.
Lemma rot0 s : rot 0 s = s.
Proof. by rewrite /rot drop0 take0 cats0. Qed.
Lemma size_rot s : size (rot n0 s) = size s.
Proof. by rewrite -[s in RHS]cat_take_drop /rot !size_cat addnC. Qed.
Lemma rot_oversize n s : size s <= n -> rot n s = s.
Proof. by move=> le_s_n; rewrite /rot take_oversize ?drop_oversize. Qed.
Lemma rot_size s : rot (size s) s = s.
Proof. exact: rot_oversize. Qed.
Lemma has_rot s a : has a (rot n0 s) = has a s.
Proof. by rewrite has_cat orbC -has_cat cat_take_drop. Qed.
Lemma rot_size_cat s1 s2 : rot (size s1) (s1 ++ s2) = s2 ++ s1.
Proof. by rewrite /rot take_size_cat ?drop_size_cat. Qed.
Definition rotr n s := rot (size s - n) s.
Lemma rotK : cancel (rot n0) (rotr n0).
Proof.
move=> s; rewrite /rotr size_rot -size_drop {2}/rot.
by rewrite rot_size_cat cat_take_drop.
Qed.
Lemma rot_inj : injective (rot n0). Proof. exact (can_inj rotK). Qed.
(* (efficient) reversal *)
Fixpoint catrev s1 s2 := if s1 is x :: s1' then catrev s1' (x :: s2) else s2.
Definition rev s := catrev s [::].
Lemma catrev_catl s t u : catrev (s ++ t) u = catrev t (catrev s u).
Proof. by elim: s u => /=. Qed.
Lemma catrev_catr s t u : catrev s (t ++ u) = catrev s t ++ u.
Proof. by elim: s t => //= x s IHs t; rewrite -IHs. Qed.
Lemma catrevE s t : catrev s t = rev s ++ t.
Proof. by rewrite -catrev_catr. Qed.
Lemma rev_cons x s : rev (x :: s) = rcons (rev s) x.
Proof. by rewrite -cats1 -catrevE. Qed.
Lemma size_rev s : size (rev s) = size s.
Proof. by elim: s => // x s IHs; rewrite rev_cons size_rcons IHs. Qed.
Lemma rev_nilp s : nilp (rev s) = nilp s.
Proof. by rewrite /nilp size_rev. Qed.
Lemma rev_cat s t : rev (s ++ t) = rev t ++ rev s.
Proof. by rewrite -catrev_catr -catrev_catl. Qed.
Lemma rev_rcons s x : rev (rcons s x) = x :: rev s.
Proof. by rewrite -cats1 rev_cat. Qed.
Lemma revK : involutive rev.
Proof. by elim=> //= x s IHs; rewrite rev_cons rev_rcons IHs. Qed.
Lemma nth_rev n s : n < size s -> nth (rev s) n = nth s (size s - n.+1).
Proof.
elim/last_ind: s => // s x IHs in n *.
rewrite rev_rcons size_rcons ltnS subSS -cats1 nth_cat /=.
case: n => [|n] lt_n_s; first by rewrite subn0 ltnn subnn.
by rewrite subnSK //= leq_subr IHs.
Qed.
Lemma filter_rev a s : filter a (rev s) = rev (filter a s).
Proof. by elim: s => //= x s IH; rewrite fun_if !rev_cons filter_rcons IH. Qed.
Lemma count_rev a s : count a (rev s) = count a s.
Proof. by rewrite -!size_filter filter_rev size_rev. Qed.
Lemma has_rev a s : has a (rev s) = has a s.
Proof. by rewrite !has_count count_rev. Qed.
Lemma all_rev a s : all a (rev s) = all a s.
Proof. by rewrite !all_count count_rev size_rev. Qed.
Lemma rev_nseq n x : rev (nseq n x) = nseq n x.
Proof. by elim: n => // n IHn; rewrite -[in LHS]addn1 nseqD rev_cat IHn. Qed.
End Sequences.
Prenex Implicits size ncons nseq head ohead behead last rcons belast.
Arguments seqn {T} n.
Prenex Implicits cat take drop rot rotr catrev.
Prenex Implicits find count nth all has filter.
Arguments rev {T} s : simpl never.
Arguments nth : simpl nomatch.
Arguments set_nth : simpl nomatch.
Arguments take : simpl nomatch.
Arguments drop : simpl nomatch.
Arguments nilP {T s}.
Arguments all_filterP {T a s}.
Arguments rotK n0 {T} s : rename.
Arguments rot_inj {n0 T} [s1 s2] eq_rot_s12 : rename.
Arguments revK {T} s : rename.
Notation count_mem x := (count (pred_of_simpl (pred1 x))).
Infix "++" := cat : seq_scope.
Notation "[ 'seq' x <- s | C ]" := (filter (fun x => C%B) s)
(x at level 99,
format "[ '[hv' 'seq' x <- s '/ ' | C ] ']'") : seq_scope.
Notation "[ 'seq' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2]
(format "[ '[hv' 'seq' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope.
Notation "[ 'seq' ' x <- s | C ]" := (filter (fun x => C%B) s)
(x strict pattern,
format "[ '[hv' 'seq' ' x <- s '/ ' | C ] ']'") : seq_scope.
Notation "[ 'seq' ' x <- s | C1 & C2 ]" := [seq x <- s | C1 && C2]
(x strict pattern,
format "[ '[hv' 'seq' ' x <- s '/ ' | C1 '/ ' & C2 ] ']'") : seq_scope.
Notation "[ 'seq' x : T <- s | C ]" := (filter (fun x : T => C%B) s)
(only parsing).
Notation "[ 'seq' x : T <- s | C1 & C2 ]" := [seq x : T <- s | C1 && C2]
(only parsing).
(* Double induction/recursion. *)
Lemma seq_ind2 {S T} (P : seq S -> seq T -> Type) :
P [::] [::] ->
(forall x y s t, size s = size t -> P s t -> P (x :: s) (y :: t)) ->
forall s t, size s = size t -> P s t.
Proof.
by move=> Pnil Pcons; elim=> [|x s IHs] [|y t] //= [eq_sz]; apply/Pcons/IHs.
Qed.
Section AllIff.
(* The Following Are Equivalent *)
(* We introduce a specific conjunction, used to chain the consecutive *)
(* items in a circular list of implications *)
Inductive all_iff_and (P Q : Prop) : Prop := AllIffConj of P & Q.
Definition all_iff (P0 : Prop) (Ps : seq Prop) : Prop :=
let fix loop (P : Prop) (Qs : seq Prop) : Prop :=
if Qs is Q :: Qs then all_iff_and (P -> Q) (loop Q Qs) else P -> P0 in
loop P0 Ps.
Lemma all_iffLR P0 Ps : all_iff P0 Ps ->
forall m n, nth P0 (P0 :: Ps) m -> nth P0 (P0 :: Ps) n.
Proof.
move=> iffPs; have PsS n: nth P0 Ps n -> nth P0 Ps n.+1.
elim: n P0 Ps iffPs => [|n IHn] P0 [|P [|Q Ps]] //= [iP0P] //; first by case.
by rewrite nth_nil.
by case=> iPQ iffPs; apply: IHn; split=> // /iP0P.
have{PsS} lePs: {homo nth P0 Ps : m n / m <= n >-> (m -> n)}.
by move=> m n /subnK<-; elim: {n}(n - m) => // n IHn /IHn; apply: PsS.
move=> m n P_m; have{m P_m} hP0: P0.
case: m P_m => //= m /(lePs m _ (leq_maxl m (size Ps))).
by rewrite nth_default ?leq_maxr.
case: n =>// n; apply: lePs 0 n (leq0n n) _.
by case: Ps iffPs hP0 => // P Ps [].
Qed.
Lemma all_iffP P0 Ps :
all_iff P0 Ps -> forall m n, nth P0 (P0 :: Ps) m <-> nth P0 (P0 :: Ps) n.
Proof. by move=> /all_iffLR-iffPs m n; split => /iffPs. Qed.
End AllIff.
Arguments all_iffLR {P0 Ps}.
Arguments all_iffP {P0 Ps}.
Coercion all_iffP : all_iff >-> Funclass.
(* This means "the following are all equivalent: P0, ... Pn" *)
Notation "[ '<->' P0 ; P1 ; .. ; Pn ]" :=
(all_iff P0 (@cons Prop P1 (.. (@cons Prop Pn nil) ..))) : form_scope.
Ltac tfae := do !apply: AllIffConj.
Section FindSpec.
Variable (T : Type) (a : {pred T}) (s : seq T).
Variant find_spec : bool -> nat -> Type :=
| NotFound of ~~ has a s : find_spec false (size s)
| Found (i : nat) of i < size s & (forall x0, a (nth x0 s i)) &
(forall x0 j, j < i -> a (nth x0 s j) = false) : find_spec true i.
Lemma findP : find_spec (has a s) (find a s).
Proof.
have [a_s|aNs] := boolP (has a s); last by rewrite hasNfind//; constructor.
by constructor=> [|x0|x0]; rewrite -?has_find ?nth_find//; apply: before_find.
Qed.
End FindSpec.
Arguments findP {T}.
Section RotRcons.
Variable T : Type.
Implicit Types (x : T) (s : seq T).
Lemma rot1_cons x s : rot 1 (x :: s) = rcons s x.
Proof. by rewrite /rot /= take0 drop0 -cats1. Qed.
Lemma rcons_inj s1 s2 x1 x2 :
rcons s1 x1 = rcons s2 x2 :> seq T -> (s1, x1) = (s2, x2).
Proof. by rewrite -!rot1_cons => /rot_inj[-> ->]. Qed.
Lemma rcons_injl x : injective (rcons^~ x).
Proof. by move=> s1 s2 /rcons_inj[]. Qed.
Lemma rcons_injr s : injective (rcons s).
Proof. by move=> x1 x2 /rcons_inj[]. Qed.
End RotRcons.
Arguments rcons_inj {T s1 x1 s2 x2} eq_rcons : rename.
Arguments rcons_injl {T} x [s1 s2] eq_rcons : rename.
Arguments rcons_injr {T} s [x1 x2] eq_rcons : rename.
(* Equality and eqType for seq. *)
Section EqSeq.
Variables (n0 : nat) (T : eqType) (x0 : T).
Local Notation nth := (nth x0).
Implicit Types (x y z : T) (s : seq T).
Fixpoint eqseq s1 s2 {struct s2} :=
match s1, s2 with
| [::], [::] => true
| x1 :: s1', x2 :: s2' => (x1 == x2) && eqseq s1' s2'
| _, _ => false
end.
Lemma eqseqP : Equality.axiom eqseq.
Proof.
move; elim=> [|x1 s1 IHs] [|x2 s2]; do [by constructor | simpl].
have [<-|neqx] := x1 =P x2; last by right; case.
by apply: (iffP (IHs s2)) => [<-|[]].
Qed.
HB.instance Definition _ := hasDecEq.Build (seq T) eqseqP.
Lemma eqseqE : eqseq = eq_op. Proof. by []. Qed.
Lemma eqseq_cons x1 x2 s1 s2 :
(x1 :: s1 == x2 :: s2) = (x1 == x2) && (s1 == s2).
Proof. by []. Qed.
Lemma eqseq_cat s1 s2 s3 s4 :
size s1 = size s2 -> (s1 ++ s3 == s2 ++ s4) = (s1 == s2) && (s3 == s4).
Proof.
elim: s1 s2 => [|x1 s1 IHs] [|x2 s2] //= [sz12].
by rewrite !eqseq_cons -andbA IHs.
Qed.
Lemma eqseq_rcons s1 s2 x1 x2 :
(rcons s1 x1 == rcons s2 x2) = (s1 == s2) && (x1 == x2).
Proof. by rewrite -(can_eq revK) !rev_rcons eqseq_cons andbC (can_eq revK). Qed.
Lemma size_eq0 s : (size s == 0) = (s == [::]).
Proof. exact: (sameP nilP eqP). Qed.
Lemma nilpE s : nilp s = (s == [::]). Proof. by case: s. Qed.
Lemma has_filter a s : has a s = (filter a s != [::]).
Proof. by rewrite -size_eq0 size_filter has_count lt0n. Qed.
(* mem_seq and index. *)
(* mem_seq defines a predType for seq. *)
Fixpoint mem_seq (s : seq T) :=
if s is y :: s' then xpredU1 y (mem_seq s') else xpred0.
Definition seq_eqclass := seq T.
Identity Coercion seq_of_eqclass : seq_eqclass >-> seq.
Coercion pred_of_seq (s : seq_eqclass) : {pred T} := mem_seq s.
Canonical seq_predType := PredType (pred_of_seq : seq T -> pred T).
(* The line below makes mem_seq a canonical instance of topred. *)
Canonical mem_seq_predType := PredType mem_seq.
Lemma in_cons y s x : (x \in y :: s) = (x == y) || (x \in s).
Proof. by []. Qed.
Lemma in_nil x : (x \in [::]) = false.
Proof. by []. Qed.
Lemma mem_seq1 x y : (x \in [:: y]) = (x == y).
Proof. by rewrite in_cons orbF. Qed.
(* to be repeated after the Section discharge. *)
Let inE := (mem_seq1, in_cons, inE).
Lemma forall_cons {P : T -> Prop} {a s} :
{in a::s, forall x, P x} <-> P a /\ {in s, forall x, P x}.
Proof.
split=> [A|[A B]]; last by move => x /predU1P [-> //|]; apply: B.
by split=> [|b Hb]; apply: A; rewrite !inE ?eqxx ?Hb ?orbT.
Qed.
Lemma exists_cons {P : T -> Prop} {a s} :
(exists2 x, x \in a::s & P x) <-> P a \/ exists2 x, x \in s & P x.
Proof.
split=> [[x /predU1P[->|x_s] Px]|]; [by left| by right; exists x|].
by move=> [?|[x x_s ?]]; [exists a|exists x]; rewrite ?inE ?eqxx ?x_s ?orbT.
Qed.
Lemma mem_seq2 x y z : (x \in [:: y; z]) = xpred2 y z x.
Proof. by rewrite !inE. Qed.
Lemma mem_seq3 x y z t : (x \in [:: y; z; t]) = xpred3 y z t x.
Proof. by rewrite !inE. Qed.
Lemma mem_seq4 x y z t u : (x \in [:: y; z; t; u]) = xpred4 y z t u x.
Proof. by rewrite !inE. Qed.
Lemma mem_cat x s1 s2 : (x \in s1 ++ s2) = (x \in s1) || (x \in s2).
Proof. by elim: s1 => //= y s1 IHs; rewrite !inE /= -orbA -IHs. Qed.
Lemma mem_rcons s y : rcons s y =i y :: s.
Proof. by move=> x; rewrite -cats1 /= mem_cat mem_seq1 orbC in_cons. Qed.
Lemma mem_head x s : x \in x :: s.
Proof. exact: predU1l. Qed.
Lemma mem_last x s : last x s \in x :: s.
Proof. by rewrite lastI mem_rcons mem_head. Qed.
Lemma mem_behead s : {subset behead s <= s}.
Proof. by case: s => // y s x; apply: predU1r. Qed.
Lemma mem_belast s y : {subset belast y s <= y :: s}.
Proof. by move=> x ys'x; rewrite lastI mem_rcons mem_behead. Qed.
Lemma mem_nth s n : n < size s -> nth s n \in s.
Proof.
by elim: s n => // x s IHs [_|n sz_s]; rewrite ?mem_head // mem_behead ?IHs.
Qed.
Lemma mem_take s x : x \in take n0 s -> x \in s.
Proof. by move=> s0x; rewrite -(cat_take_drop n0 s) mem_cat /= s0x. Qed.
Lemma mem_drop s x : x \in drop n0 s -> x \in s.
Proof. by move=> s0'x; rewrite -(cat_take_drop n0 s) mem_cat /= s0'x orbT. Qed.
Lemma last_eq s z x y : x != y -> z != y -> (last x s == y) = (last z s == y).
Proof. by move=> /negPf xz /negPf yz; case: s => [|t s]//; rewrite xz yz. Qed.
Section Filters.
Implicit Type a : pred T.
Lemma hasP {a s} : reflect (exists2 x, x \in s & a x) (has a s).
Proof.
elim: s => [|y s IHs] /=; first by right; case.
exact: equivP (orPP idP IHs) (iff_sym exists_cons).
Qed.
Lemma allP {a s} : reflect {in s, forall x, a x} (all a s).
Proof.
elim: s => [|/= y s IHs]; first by left.
exact: equivP (andPP idP IHs) (iff_sym forall_cons).
Qed.
Lemma hasPn a s : reflect {in s, forall x, ~~ a x} (~~ has a s).
Proof. by rewrite -all_predC; apply: allP. Qed.
Lemma allPn a s : reflect (exists2 x, x \in s & ~~ a x) (~~ all a s).
Proof. by rewrite -has_predC; apply: hasP. Qed.
Lemma allss s : all [in s] s. Proof. exact/allP. Qed.
Lemma mem_filter a x s : (x \in filter a s) = a x && (x \in s).
Proof.
rewrite andbC; elim: s => //= y s IHs.
rewrite (fun_if (fun s' : seq T => x \in s')) !in_cons {}IHs.
by case: eqP => [->|_]; case (a y); rewrite /= ?andbF.
Qed.
Variables (a : pred T) (s : seq T) (A : T -> Prop).
Hypothesis aP : forall x, reflect (A x) (a x).
Lemma hasPP : reflect (exists2 x, x \in s & A x) (has a s).
Proof. by apply: (iffP hasP) => -[x ? /aP]; exists x. Qed.
Lemma allPP : reflect {in s, forall x, A x} (all a s).
Proof. by apply: (iffP allP) => a_s x /a_s/aP. Qed.
End Filters.
Section EqIn.
Variables a1 a2 : pred T.
Lemma eq_in_filter s : {in s, a1 =1 a2} -> filter a1 s = filter a2 s.
Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_in_find s : {in s, a1 =1 a2} -> find a1 s = find a2 s.
Proof. by elim: s => //= x s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_in_count s : {in s, a1 =1 a2} -> count a1 s = count a2 s.
Proof. by move/eq_in_filter=> eq_a12; rewrite -!size_filter eq_a12. Qed.
Lemma eq_in_all s : {in s, a1 =1 a2} -> all a1 s = all a2 s.
Proof. by move=> eq_a12; rewrite !all_count eq_in_count. Qed.
Lemma eq_in_has s : {in s, a1 =1 a2} -> has a1 s = has a2 s.
Proof. by move/eq_in_filter=> eq_a12; rewrite !has_filter eq_a12. Qed.
End EqIn.
Lemma eq_has_r s1 s2 : s1 =i s2 -> has^~ s1 =1 has^~ s2.
Proof.
by move=> Es a; apply/hasP/hasP=> -[x sx ax]; exists x; rewrite ?Es in sx *.
Qed.
Lemma eq_all_r s1 s2 : s1 =i s2 -> all^~ s1 =1 all^~ s2.
Proof. by move=> Es a; apply/negb_inj; rewrite -!has_predC (eq_has_r Es). Qed.
Lemma has_sym s1 s2 : has [in s1] s2 = has [in s2] s1.
Proof. by apply/hasP/hasP=> -[x]; exists x. Qed.
Lemma has_pred1 x s : has (pred1 x) s = (x \in s).
Proof. by rewrite -(eq_has (mem_seq1^~ x)) (has_sym [:: x]) /= orbF. Qed.
Lemma mem_rev s : rev s =i s.
Proof. by move=> a; rewrite -!has_pred1 has_rev. Qed.
(* Constant sequences, i.e., the image of nseq. *)
Definition constant s := if s is x :: s' then all (pred1 x) s' else true.
Lemma all_pred1P x s : reflect (s = nseq (size s) x) (all (pred1 x) s).
Proof.
elim: s => [|y s IHs] /=; first by left.
case: eqP => [->{y} | ne_xy]; last by right=> [] [? _]; case ne_xy.
by apply: (iffP IHs) => [<- //| []].
Qed.
Lemma all_pred1_constant x s : all (pred1 x) s -> constant s.
Proof. by case: s => //= y s /andP[/eqP->]. Qed.
Lemma all_pred1_nseq x n : all (pred1 x) (nseq n x).
Proof. by rewrite all_nseq /= eqxx orbT. Qed.
Lemma mem_nseq n x y : (y \in nseq n x) = (0 < n) && (y == x).
Proof. by rewrite -has_pred1 has_nseq eq_sym. Qed.
Lemma nseqP n x y : reflect (y = x /\ n > 0) (y \in nseq n x).
Proof. by rewrite mem_nseq andbC; apply: (iffP andP) => -[/eqP]. Qed.
Lemma constant_nseq n x : constant (nseq n x).
Proof. exact: all_pred1_constant (all_pred1_nseq x n). Qed.
(* Uses x0 *)
Lemma constantP s : reflect (exists x, s = nseq (size s) x) (constant s).
Proof.
apply: (iffP idP) => [| [x ->]]; last exact: constant_nseq.
case: s => [|x s] /=; first by exists x0.
by move/all_pred1P=> def_s; exists x; rewrite -def_s.
Qed.
(* Duplicate-freenes. *)
Fixpoint uniq s := if s is x :: s' then (x \notin s') && uniq s' else true.
Lemma cons_uniq x s : uniq (x :: s) = (x \notin s) && uniq s.
Proof. by []. Qed.
Lemma cat_uniq s1 s2 :
uniq (s1 ++ s2) = [&& uniq s1, ~~ has [in s1] s2 & uniq s2].
Proof.
elim: s1 => [|x s1 IHs]; first by rewrite /= has_pred0.
by rewrite has_sym /= mem_cat !negb_or has_sym IHs -!andbA; do !bool_congr.
Qed.
Lemma uniq_catC s1 s2 : uniq (s1 ++ s2) = uniq (s2 ++ s1).
Proof. by rewrite !cat_uniq has_sym andbCA andbA andbC. Qed.
Lemma uniq_catCA s1 s2 s3 : uniq (s1 ++ s2 ++ s3) = uniq (s2 ++ s1 ++ s3).
Proof.
by rewrite !catA -!(uniq_catC s3) !(cat_uniq s3) uniq_catC !has_cat orbC.
Qed.
Lemma rcons_uniq s x : uniq (rcons s x) = (x \notin s) && uniq s.
Proof. by rewrite -cats1 uniq_catC. Qed.
Lemma filter_uniq s a : uniq s -> uniq (filter a s).
Proof.
elim: s => //= x s IHs /andP[s'x]; case: ifP => //= a_x /IHs->.
by rewrite mem_filter a_x s'x.
Qed.
Lemma rot_uniq s : uniq (rot n0 s) = uniq s.
Proof. by rewrite /rot uniq_catC cat_take_drop. Qed.
Lemma rev_uniq s : uniq (rev s) = uniq s.
Proof.
elim: s => // x s IHs.
by rewrite rev_cons -cats1 cat_uniq /= andbT andbC mem_rev orbF IHs.
Qed.
Lemma count_memPn x s : reflect (count_mem x s = 0) (x \notin s).
Proof. by rewrite -has_pred1 has_count -eqn0Ngt; apply: eqP. Qed.
Lemma count_uniq_mem s x : uniq s -> count_mem x s = (x \in s).
Proof.
elim: s => //= y s IHs /andP[/negbTE s'y /IHs-> {IHs}].
by rewrite in_cons; case: (eqVneq y x) => // <-; rewrite s'y.
Qed.
Lemma leq_uniq_countP x s1 s2 : uniq s1 ->
reflect (x \in s1 -> x \in s2) (count_mem x s1 <= count_mem x s2).
Proof.
move/count_uniq_mem->; case: (boolP (_ \in _)) => //= _; last by constructor.
by rewrite -has_pred1 has_count; apply: (iffP idP) => //; apply.
Qed.
Lemma leq_uniq_count s1 s2 : uniq s1 -> {subset s1 <= s2} ->
(forall x, count_mem x s1 <= count_mem x s2).
Proof. by move=> s1_uniq s1_s2 x; apply/leq_uniq_countP/s1_s2. Qed.
Lemma filter_pred1_uniq s x : uniq s -> x \in s -> filter (pred1 x) s = [:: x].
Proof.
move=> uniq_s s_x; rewrite (all_pred1P _ _ (filter_all _ _)).
by rewrite size_filter count_uniq_mem ?s_x.
Qed.
(* Removing duplicates *)
Fixpoint undup s :=
if s is x :: s' then if x \in s' then undup s' else x :: undup s' else [::].
Lemma size_undup s : size (undup s) <= size s.
Proof. by elim: s => //= x s IHs; case: (x \in s) => //=; apply: ltnW. Qed.
Lemma mem_undup s : undup s =i s.
Proof.
move=> x; elim: s => //= y s IHs.
by case s_y: (y \in s); rewrite !inE IHs //; case: eqP => [->|].
Qed.
Lemma undup_uniq s : uniq (undup s).
Proof.
by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= mem_undup s_x.
Qed.
Lemma undup_id s : uniq s -> undup s = s.
Proof. by elim: s => //= x s IHs /andP[/negbTE-> /IHs->]. Qed.
Lemma ltn_size_undup s : (size (undup s) < size s) = ~~ uniq s.
Proof.
by elim: s => //= x s IHs; case s_x: (x \in s); rewrite //= ltnS size_undup.
Qed.
Lemma filter_undup p s : filter p (undup s) = undup (filter p s).
Proof.
elim: s => //= x s IHs; rewrite (fun_if undup) [_ = _]fun_if /= mem_filter /=.
by rewrite (fun_if (filter p)) /= IHs; case: ifP => -> //=; apply: if_same.
Qed.
Lemma undup_nil s : undup s = [::] -> s = [::].
Proof. by case: s => //= x s; rewrite -mem_undup; case: ifP; case: undup. Qed.
Lemma undup_cat s t :
undup (s ++ t) = [seq x <- undup s | x \notin t] ++ undup t.
Proof. by elim: s => //= x s ->; rewrite mem_cat; do 2 case: in_mem => //=. Qed.
Lemma undup_rcons s x : undup (rcons s x) = rcons [seq y <- undup s | y != x] x.
Proof.
by rewrite -!cats1 undup_cat; congr cat; apply: eq_filter => y; rewrite inE.
Qed.
Lemma count_undup s p : count p (undup s) <= count p s.
Proof. by rewrite -!size_filter filter_undup size_undup. Qed.
Lemma has_undup p s : has p (undup s) = has p s.
Proof. by apply: eq_has_r => x; rewrite mem_undup. Qed.
Lemma all_undup p s : all p (undup s) = all p s.
Proof. by apply: eq_all_r => x; rewrite mem_undup. Qed.
(* Lookup *)
Definition index x := find (pred1 x).
Lemma index_size x s : index x s <= size s.
Proof. by rewrite /index find_size. Qed.
Lemma index_mem x s : (index x s < size s) = (x \in s).
Proof. by rewrite -has_pred1 has_find. Qed.
Lemma memNindex x s : x \notin s -> index x s = size s.
Proof. by rewrite -has_pred1 => /hasNfind. Qed.
Lemma nth_index x s : x \in s -> nth s (index x s) = x.
Proof. by rewrite -has_pred1 => /(nth_find x0)/eqP. Qed.
Lemma index_inj s : {in s &, injective (index ^~ s)}.
Proof.
by move=> x y x_s y_s eidx; rewrite -(nth_index x_s) eidx nth_index.
Qed.
Lemma index_cat x s1 s2 :
index x (s1 ++ s2) = if x \in s1 then index x s1 else size s1 + index x s2.
Proof. by rewrite /index find_cat has_pred1. Qed.
Lemma index_ltn x s i : x \in take i s -> index x s < i.
Proof. by rewrite -has_pred1; apply: find_ltn. Qed.
Lemma in_take x s i : x \in s -> (x \in take i s) = (index x s < i).
Proof. by rewrite -?has_pred1; apply: has_take. Qed.
Lemma in_take_leq x s i : i <= size s -> (x \in take i s) = (index x s < i).
Proof. by rewrite -?has_pred1; apply: has_take_leq. Qed.
Lemma index_nth i s : i < size s -> index (nth s i) s <= i.
Proof.
move=> lti; rewrite -ltnS index_ltn// -(@nth_take i.+1)// mem_nth // size_take.
by case: ifP.
Qed.
Lemma nthK s: uniq s -> {in gtn (size s), cancel (nth s) (index^~ s)}.
Proof.
elim: s => //= x s IHs /andP[s'x Us] i; rewrite inE ltnS eq_sym -if_neg.
by case: i => /= [_|i lt_i_s]; rewrite ?eqxx ?IHs ?(memPn s'x) ?mem_nth.
Qed.
Lemma index_uniq i s : i < size s -> uniq s -> index (nth s i) s = i.
Proof. by move/nthK. Qed.
Lemma index_head x s : index x (x :: s) = 0.
Proof. by rewrite /= eqxx. Qed.
Lemma index_last x s : uniq (x :: s) -> index (last x s) (x :: s) = size s.
Proof.
rewrite lastI rcons_uniq -cats1 index_cat size_belast.
by case: ifP => //=; rewrite eqxx addn0.
Qed.
Lemma nth_uniq s i j :
i < size s -> j < size s -> uniq s -> (nth s i == nth s j) = (i == j).
Proof. by move=> lti ltj /nthK/can_in_eq->. Qed.
Lemma uniqPn s :
reflect (exists i j, [/\ i < j, j < size s & nth s i = nth s j]) (~~ uniq s).
Proof.
apply: (iffP idP) => [|[i [j [ltij ltjs]]]]; last first.
by apply: contra_eqN => Us; rewrite nth_uniq ?ltn_eqF // (ltn_trans ltij).
elim: s => // x s IHs /nandP[/negbNE | /IHs[i [j]]]; last by exists i.+1, j.+1.
by exists 0, (index x s).+1; rewrite !ltnS index_mem /= nth_index.
Qed.
Lemma uniqP s : reflect {in gtn (size s) &, injective (nth s)} (uniq s).
Proof.
apply: (iffP idP) => [/nthK/can_in_inj// | nth_inj].
apply/uniqPn => -[i [j [ltij ltjs /nth_inj/eqP/idPn]]].
by rewrite !inE (ltn_trans ltij ltjs) ltn_eqF //=; case.
Qed.
Lemma mem_rot s : rot n0 s =i s.
Proof. by move=> x; rewrite -[s in RHS](cat_take_drop n0) !mem_cat /= orbC. Qed.
Lemma eqseq_rot s1 s2 : (rot n0 s1 == rot n0 s2) = (s1 == s2).
Proof. exact/inj_eq/rot_inj. Qed.
Lemma drop_index s (n := index x0 s) : x0 \in s -> drop n s = x0 :: drop n.+1 s.
Proof. by move=> xs; rewrite (drop_nth x0) ?index_mem ?nth_index. Qed.
(* lemmas about the pivot pattern [_ ++ _ :: _] *)
Lemma index_pivot x s1 s2 (s := s1 ++ x :: s2) : x \notin s1 ->
index x s = size s1.
Proof. by rewrite index_cat/= eqxx addn0; case: ifPn. Qed.
Lemma take_pivot x s2 s1 (s := s1 ++ x :: s2) : x \notin s1 ->
take (index x s) s = s1.
Proof. by move=> /index_pivot->; rewrite take_size_cat. Qed.
Lemma rev_pivot x s1 s2 : rev (s1 ++ x :: s2) = rev s2 ++ x :: rev s1.
Proof. by rewrite rev_cat rev_cons cat_rcons. Qed.
Lemma eqseq_pivot2l x s1 s2 s3 s4 : x \notin s1 -> x \notin s3 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs1 xNs3; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//].
suff S : size s1 = size s3 by rewrite eqseq_cat// eqseq_cons eqxx in E.
by rewrite -(index_pivot s2 xNs1) (eqP E) index_pivot.
Qed.
Lemma eqseq_pivot2r x s1 s2 s3 s4 : x \notin s2 -> x \notin s4 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs2 xNs4; rewrite -(can_eq revK) !rev_pivot.
by rewrite eqseq_pivot2l ?mem_rev // !(can_eq revK) andbC.
Qed.
Lemma eqseq_pivotl x s1 s2 s3 s4 : x \notin s1 -> x \notin s2 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
move=> xNs1 xNs2; apply/idP/idP => [E|/andP[/eqP-> /eqP->]//].
rewrite -(@eqseq_pivot2l x)//; have /eqP/(congr1 (count_mem x)) := E.
rewrite !count_cat/= eqxx !addnS (count_memPn _ _ xNs1) (count_memPn _ _ xNs2).
by move=> -[/esym/eqP]; rewrite addn_eq0 => /andP[/eqP/count_memPn].
Qed.
Lemma eqseq_pivotr x s1 s2 s3 s4 : x \notin s3 -> x \notin s4 ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof. by move=> *; rewrite eq_sym eqseq_pivotl//; case: eqVneq => /=. Qed.
Lemma uniq_eqseq_pivotl x s1 s2 s3 s4 : uniq (s1 ++ x :: s2) ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof.
by rewrite uniq_catC/= mem_cat => /andP[/norP[? ?] _]; rewrite eqseq_pivotl.
Qed.
Lemma uniq_eqseq_pivotr x s1 s2 s3 s4 : uniq (s3 ++ x :: s4) ->
(s1 ++ x :: s2 == s3 ++ x :: s4) = (s1 == s3) && (s2 == s4).
Proof. by move=> ?; rewrite eq_sym uniq_eqseq_pivotl//; case: eqVneq => /=. Qed.
End EqSeq.
Arguments eqseq : simpl nomatch.
Notation "'has_ view" := (hasPP _ (fun _ => view))
(at level 4, right associativity, format "''has_' view").
Notation "'all_ view" := (allPP _ (fun _ => view))
(at level 4, right associativity, format "''all_' view").
Section RotIndex.
Variables (T : eqType).
Implicit Types x y z : T.
Lemma rot_index s x (i := index x s) : x \in s ->
rot i s = x :: (drop i.+1 s ++ take i s).
Proof. by move=> x_s; rewrite /rot drop_index. Qed.
Variant rot_to_spec s x := RotToSpec i s' of rot i s = x :: s'.
Lemma rot_to s x : x \in s -> rot_to_spec s x.
Proof. by move=> /rot_index /RotToSpec. Qed.
End RotIndex.
Definition inE := (mem_seq1, in_cons, inE).
Prenex Implicits mem_seq1 constant uniq undup index.
Arguments eqseq {T} !_ !_.
Arguments pred_of_seq {T} s x /.
Arguments eqseqP {T x y}.
Arguments hasP {T a s}.
Arguments hasPn {T a s}.
Arguments allP {T a s}.
Arguments allPn {T a s}.
Arguments nseqP {T n x y}.
Arguments count_memPn {T x s}.
Arguments uniqPn {T} x0 {s}.
Arguments uniqP {T} x0 {s}.
Arguments forall_cons {T P a s}.
Arguments exists_cons {T P a s}.
(* Since both `all [in s] s`, `all (mem s) s`, and `all (pred_of_seq s) s` *)
(* may appear in goals, the following hint has to be declared using the *)
(* `Hint Extern` command. Additionally, `mem` and `pred_of_seq` in the above *)
(* terms do not reduce to each other; thus, stating `allss` in the form of *)
(* one of them makes `apply: allss` fail for the other case. Since both `mem` *)
(* and `pred_of_seq` reduce to `mem_seq`, the following explicit type *)
(* annotation for `allss` makes it work for both cases. *)
#[export] Hint Extern 0 (is_true (all _ _)) =>
apply: (allss : forall T s, all (mem_seq s) s) : core.
Section NthTheory.
Lemma nthP (T : eqType) (s : seq T) x x0 :
reflect (exists2 i, i < size s & nth x0 s i = x) (x \in s).
Proof.
apply: (iffP idP) => [|[n Hn <-]]; last exact: mem_nth.
by exists (index x s); [rewrite index_mem | apply nth_index].
Qed.
Variable T : Type.
Implicit Types (a : pred T) (x : T).
Lemma has_nthP a s x0 :
reflect (exists2 i, i < size s & a (nth x0 s i)) (has a s).
Proof.
elim: s => [|x s IHs] /=; first by right; case.
case nax: (a x); first by left; exists 0.
by apply: (iffP IHs) => [[i]|[[|i]]]; [exists i.+1 | rewrite nax | exists i].
Qed.
Lemma all_nthP a s x0 :
reflect (forall i, i < size s -> a (nth x0 s i)) (all a s).
Proof.
rewrite -(eq_all (fun x => negbK (a x))) all_predC.
case: (has_nthP _ _ x0) => [na_s | a_s]; [right=> a_s | left=> i lti].
by case: na_s => i lti; rewrite a_s.
by apply/idPn=> na_si; case: a_s; exists i.
Qed.
Lemma set_nthE s x0 n x :
set_nth x0 s n x = if n < size s
then take n s ++ x :: drop n.+1 s
else s ++ ncons (n - size s) x0 [:: x].
Proof.
elim: s n => [|a s IH] n /=; first by rewrite subn0 set_nth_nil.
case: n => [|n]; first by rewrite drop0.
by rewrite ltnS /=; case: ltnP (IH n) => _ ->.
Qed.
Lemma count_set_nth a s x0 n x :
count a (set_nth x0 s n x) =
count a s + a x - a (nth x0 s n) * (n < size s) + (a x0) * (n - size s).
Proof.
rewrite set_nthE; case: ltnP => [nlts|nges]; last first.
rewrite -cat_nseq !count_cat count_nseq /=.
by rewrite muln0 addn0 subn0 addnAC addnA.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
rewrite -[in count a s](cat_take_drop n s) [drop n s](drop_nth x0)//.
by rewrite !count_cat/= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK.
Qed.
Lemma count_set_nth_ltn a s x0 n x : n < size s ->
count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n).
Proof.
move=> nlts; rewrite count_set_nth nlts muln1.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
by rewrite muln0 addn0.
Qed.
Lemma count_set_nthF a s x0 n x : ~~ a x0 ->
count a (set_nth x0 s n x) = count a s + a x - a (nth x0 s n).
Proof.
move=> /negbTE ax0; rewrite count_set_nth ax0 mul0n addn0.
case: ltnP => [_|nges]; first by rewrite muln1.
by rewrite nth_default// ax0 subn0.
Qed.
End NthTheory.
Lemma set_nth_default T s (y0 x0 : T) n : n < size s -> nth x0 s n = nth y0 s n.
Proof. by elim: s n => [|y s' IHs] [|n] //= /IHs. Qed.
Lemma headI T s (x : T) : rcons s x = head x s :: behead (rcons s x).
Proof. by case: s. Qed.
Arguments nthP {T s x}.
Arguments has_nthP {T a s}.
Arguments all_nthP {T a s}.
Definition bitseq := seq bool.
#[hnf] HB.instance Definition _ := Equality.on bitseq.
Canonical bitseq_predType := Eval hnf in [predType of bitseq].
(* Generalizations of splitP (from path.v): split_find_nth and split_find *)
Section FindNth.
Variables (T : Type).
Implicit Types (x : T) (p : pred T) (s : seq T).
Variant split_find_nth_spec p : seq T -> seq T -> seq T -> T -> Type :=
FindNth x s1 s2 of p x & ~~ has p s1 :
split_find_nth_spec p (rcons s1 x ++ s2) s1 s2 x.
Lemma split_find_nth x0 p s (i := find p s) :
has p s -> split_find_nth_spec p s (take i s) (drop i.+1 s) (nth x0 s i).
Proof.
move=> p_s; rewrite -[X in split_find_nth_spec _ X](cat_take_drop i s).
rewrite (drop_nth x0 _) -?has_find// -cat_rcons.
by constructor; [apply: nth_find | rewrite has_take -?leqNgt].
Qed.
Variant split_find_spec p : seq T -> seq T -> seq T -> Type :=
FindSplit x s1 s2 of p x & ~~ has p s1 :
split_find_spec p (rcons s1 x ++ s2) s1 s2.
Lemma split_find p s (i := find p s) :
has p s -> split_find_spec p s (take i s) (drop i.+1 s).
Proof.
by case: s => // x ? in i * => ?; case: split_find_nth => //; constructor.
Qed.
Lemma nth_rcons_cat_find x0 p s1 s2 x (s := rcons s1 x ++ s2) :
p x -> ~~ has p s1 -> nth x0 s (find p s) = x.
Proof.
move=> pz pNs1; rewrite /s cat_rcons find_cat (negPf pNs1).
by rewrite nth_cat/= pz addn0 subnn ltnn.
Qed.
End FindNth.
(* Incrementing the ith nat in a seq nat, padding with 0's if needed. This *)
(* allows us to use nat seqs as bags of nats. *)
Fixpoint incr_nth v i {struct i} :=
if v is n :: v' then if i is i'.+1 then n :: incr_nth v' i' else n.+1 :: v'
else ncons i 0 [:: 1].
Arguments incr_nth : simpl nomatch.
Lemma nth_incr_nth v i j : nth 0 (incr_nth v i) j = (i == j) + nth 0 v j.
Proof.
elim: v i j => [|n v IHv] [|i] [|j] //=; rewrite ?eqSS ?addn0 //; try by case j.
elim: i j => [|i IHv] [|j] //=; rewrite ?eqSS //; by case j.
Qed.
Lemma size_incr_nth v i :
size (incr_nth v i) = if i < size v then size v else i.+1.
Proof.
elim: v i => [|n v IHv] [|i] //=; first by rewrite size_ncons /= addn1.
by rewrite IHv; apply: fun_if.
Qed.
Lemma incr_nth_inj v : injective (incr_nth v).
Proof.
move=> i j /(congr1 (nth 0 ^~ i)); apply: contra_eq => neq_ij.
by rewrite !nth_incr_nth eqn_add2r eqxx /nat_of_bool ifN_eqC.
Qed.
Lemma incr_nthC v i j :
incr_nth (incr_nth v i) j = incr_nth (incr_nth v j) i.
Proof.
apply: (@eq_from_nth _ 0) => [|k _]; last by rewrite !nth_incr_nth addnCA.
by do !rewrite size_incr_nth leqNgt if_neg -/(maxn _ _); apply: maxnAC.
Qed.
(* Equality up to permutation *)
Section PermSeq.
Variable T : eqType.
Implicit Type s : seq T.
Definition perm_eq s1 s2 :=
all [pred x | count_mem x s1 == count_mem x s2] (s1 ++ s2).
Lemma permP s1 s2 : reflect (count^~ s1 =1 count^~ s2) (perm_eq s1 s2).
Proof.
apply: (iffP allP) => /= [eq_cnt1 a | eq_cnt x _]; last exact/eqP.
have [n le_an] := ubnP (count a (s1 ++ s2)); elim: n => // n IHn in a le_an *.
have [/eqP|] := posnP (count a (s1 ++ s2)).
by rewrite count_cat addn_eq0; do 2!case: eqP => // ->.
rewrite -has_count => /hasP[x s12x a_x]; pose a' := predD1 a x.
have cnt_a' s: count a s = count_mem x s + count a' s.
rewrite -count_predUI -[LHS]addn0 -(count_pred0 s).
by congr (_ + _); apply: eq_count => y /=; case: eqP => // ->.
rewrite !cnt_a' (eqnP (eq_cnt1 _ s12x)) (IHn a') // -ltnS.
apply: leq_trans le_an.
by rewrite ltnS cnt_a' -add1n leq_add2r -has_count has_pred1.
Qed.
Lemma perm_refl s : perm_eq s s.
Proof. exact/permP. Qed.
Hint Resolve perm_refl : core.
Lemma perm_sym : symmetric perm_eq.
Proof. by move=> s1 s2; apply/permP/permP=> eq_s12 a. Qed.
Lemma perm_trans : transitive perm_eq.
Proof. by move=> s2 s1 s3 /permP-eq12 /permP/(ftrans eq12)/permP. Qed.
Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2).
Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2).
Lemma permEl s1 s2 : perm_eql s1 s2 -> perm_eq s1 s2. Proof. by move->. Qed.
Lemma permPl s1 s2 : reflect (perm_eql s1 s2) (perm_eq s1 s2).
Proof.
apply: (iffP idP) => [eq12 s3 | -> //]; apply/idP/idP; last exact: perm_trans.
by rewrite -!(perm_sym s3) => /perm_trans; apply.
Qed.
Lemma permPr s1 s2 : reflect (perm_eqr s1 s2) (perm_eq s1 s2).
Proof.
by apply/(iffP idP) => [/permPl eq12 s3| <- //]; rewrite !(perm_sym s3) eq12.
Qed.
Lemma perm_catC s1 s2 : perm_eql (s1 ++ s2) (s2 ++ s1).
Proof. by apply/permPl/permP=> a; rewrite !count_cat addnC. Qed.
Lemma perm_cat2l s1 s2 s3 : perm_eq (s1 ++ s2) (s1 ++ s3) = perm_eq s2 s3.
Proof.
apply/permP/permP=> eq23 a; apply/eqP;
by move/(_ a)/eqP: eq23; rewrite !count_cat eqn_add2l.
Qed.
Lemma perm_catl s t1 t2 : perm_eq t1 t2 -> perm_eql (s ++ t1) (s ++ t2).
Proof. by move=> eq_t12; apply/permPl; rewrite perm_cat2l. Qed.
Lemma perm_cons x s1 s2 : perm_eq (x :: s1) (x :: s2) = perm_eq s1 s2.
Proof. exact: (perm_cat2l [::x]). Qed.
Lemma perm_cat2r s1 s2 s3 : perm_eq (s2 ++ s1) (s3 ++ s1) = perm_eq s2 s3.
Proof. by do 2!rewrite perm_sym perm_catC; apply: perm_cat2l. Qed.
Lemma perm_catr s1 s2 t : perm_eq s1 s2 -> perm_eql (s1 ++ t) (s2 ++ t).
Proof. by move=> eq_s12; apply/permPl; rewrite perm_cat2r. Qed.
Lemma perm_cat s1 s2 t1 t2 :
perm_eq s1 s2 -> perm_eq t1 t2 -> perm_eq (s1 ++ t1) (s2 ++ t2).
Proof. by move=> /perm_catr-> /perm_catl->. Qed.
Lemma perm_catAC s1 s2 s3 : perm_eql ((s1 ++ s2) ++ s3) ((s1 ++ s3) ++ s2).
Proof. by apply/permPl; rewrite -!catA perm_cat2l perm_catC. Qed.
Lemma perm_catCA s1 s2 s3 : perm_eql (s1 ++ s2 ++ s3) (s2 ++ s1 ++ s3).
Proof. by apply/permPl; rewrite !catA perm_cat2r perm_catC. Qed.
Lemma perm_catACA s1 s2 s3 s4 :
perm_eql ((s1 ++ s2) ++ (s3 ++ s4)) ((s1 ++ s3) ++ (s2 ++ s4)).
Proof. by apply/permPl; rewrite perm_catAC !catA perm_catAC. Qed.
Lemma perm_rcons x s : perm_eql (rcons s x) (x :: s).
Proof. by move=> /= s2; rewrite -cats1 perm_catC. Qed.
Lemma perm_rot n s : perm_eql (rot n s) s.
Proof. by move=> /= s2; rewrite perm_catC cat_take_drop. Qed.
Lemma perm_rotr n s : perm_eql (rotr n s) s.
Proof. exact: perm_rot. Qed.
Lemma perm_rev s : perm_eql (rev s) s.
Proof. by apply/permPl/permP=> i; rewrite count_rev. Qed.
Lemma perm_filter s1 s2 a :
perm_eq s1 s2 -> perm_eq (filter a s1) (filter a s2).
Proof. by move/permP=> s12_count; apply/permP=> Q; rewrite !count_filter. Qed.
Lemma perm_filterC a s : perm_eql (filter a s ++ filter (predC a) s) s.
Proof.
apply/permPl; elim: s => //= x s IHs.
by case: (a x); last rewrite /= -cat1s perm_catCA; rewrite perm_cons.
Qed.
Lemma perm_size s1 s2 : perm_eq s1 s2 -> size s1 = size s2.
Proof. by move/permP=> eq12; rewrite -!count_predT eq12. Qed.
Lemma perm_mem s1 s2 : perm_eq s1 s2 -> s1 =i s2.
Proof. by move/permP=> eq12 x; rewrite -!has_pred1 !has_count eq12. Qed.
Lemma perm_nilP s : reflect (s = [::]) (perm_eq s [::]).
Proof. by apply: (iffP idP) => [/perm_size/eqP/nilP | ->]. Qed.
Lemma perm_consP x s t :
reflect (exists i u, rot i t = x :: u /\ perm_eq u s)
(perm_eq t (x :: s)).
Proof.
apply: (iffP idP) => [eq_txs | [i [u [Dt eq_us]]]].
have /rot_to[i u Dt]: x \in t by rewrite (perm_mem eq_txs) mem_head.
by exists i, u; rewrite -(perm_cons x) -Dt perm_rot.
by rewrite -(perm_rot i) Dt perm_cons.
Qed.
Lemma perm_has s1 s2 a : perm_eq s1 s2 -> has a s1 = has a s2.
Proof. by move/perm_mem/eq_has_r. Qed.
Lemma perm_all s1 s2 a : perm_eq s1 s2 -> all a s1 = all a s2.
Proof. by move/perm_mem/eq_all_r. Qed.
Lemma perm_small_eq s1 s2 : size s2 <= 1 -> perm_eq s1 s2 -> s1 = s2.
Proof.
move=> s2_le1 eqs12; move/perm_size: eqs12 s2_le1 (perm_mem eqs12).
by case: s2 s1 => [|x []] // [|y []] // _ _ /(_ x) /[!(inE, eqxx)] /eqP->.
Qed.
Lemma uniq_leq_size s1 s2 : uniq s1 -> {subset s1 <= s2} -> size s1 <= size s2.
Proof.
elim: s1 s2 => //= x s1 IHs s2 /andP[not_s1x Us1] /forall_cons[s2x ss12].
have [i s3 def_s2] := rot_to s2x; rewrite -(size_rot i s2) def_s2.
apply: IHs => // y s1y; have:= ss12 y s1y.
by rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)).
Qed.
Lemma leq_size_uniq s1 s2 :
uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 -> uniq s2.
Proof.
elim: s1 s2 => [[] | x s1 IHs s2] // Us1x; have /andP[not_s1x Us1] := Us1x.
case/forall_cons => /rot_to[i s3 def_s2] ss12 le_s21.
rewrite -(rot_uniq i) -(size_rot i) def_s2 /= in le_s21 *.
have ss13 y (s1y : y \in s1): y \in s3.
by have:= ss12 y s1y; rewrite -(mem_rot i) def_s2 inE (negPf (memPn _ y s1y)).
rewrite IHs // andbT; apply: contraL _ le_s21 => s3x; rewrite -leqNgt.
by apply/(uniq_leq_size Us1x)/allP; rewrite /= s3x; apply/allP.
Qed.
Lemma uniq_size_uniq s1 s2 :
uniq s1 -> s1 =i s2 -> uniq s2 = (size s2 == size s1).
Proof.
move=> Us1 eqs12; apply/idP/idP=> [Us2 | /eqP eq_sz12].
by rewrite eqn_leq !uniq_leq_size // => y; rewrite eqs12.
by apply: (leq_size_uniq Us1) => [y|]; rewrite (eqs12, eq_sz12).
Qed.
Lemma uniq_min_size s1 s2 :
uniq s1 -> {subset s1 <= s2} -> size s2 <= size s1 ->
(size s1 = size s2) * (s1 =i s2).
Proof.
move=> Us1 ss12 le_s21; have Us2: uniq s2 := leq_size_uniq Us1 ss12 le_s21.
suffices: s1 =i s2 by split; first by apply/eqP; rewrite -uniq_size_uniq.
move=> x; apply/idP/idP=> [/ss12// | s2x]; apply: contraLR le_s21 => not_s1x.
rewrite -ltnNge (@uniq_leq_size (x :: s1)) /= ?not_s1x //.
by apply/allP; rewrite /= s2x; apply/allP.
Qed.
Lemma eq_uniq s1 s2 : size s1 = size s2 -> s1 =i s2 -> uniq s1 = uniq s2.
Proof.
move=> eq_sz12 eq_s12.
by apply/idP/idP=> Us; rewrite (uniq_size_uniq Us) ?eq_sz12 ?eqxx.
Qed.
Lemma perm_uniq s1 s2 : perm_eq s1 s2 -> uniq s1 = uniq s2.
Proof. by move=> eq_s12; apply/eq_uniq; [apply/perm_size | apply/perm_mem]. Qed.
Lemma uniq_perm s1 s2 : uniq s1 -> uniq s2 -> s1 =i s2 -> perm_eq s1 s2.
Proof.
move=> Us1 Us2 eq12; apply/allP=> x _; apply/eqP.
by rewrite !count_uniq_mem ?eq12.
Qed.
Lemma perm_undup s1 s2 : s1 =i s2 -> perm_eq (undup s1) (undup s2).
Proof.
by move=> Es12; rewrite uniq_perm ?undup_uniq // => s; rewrite !mem_undup.
Qed.
Lemma count_mem_uniq s : (forall x, count_mem x s = (x \in s)) -> uniq s.
Proof.
move=> count1_s; have Uus := undup_uniq s.
suffices: perm_eq s (undup s) by move/perm_uniq->.
by apply/allP=> x _; apply/eqP; rewrite (count_uniq_mem x Uus) mem_undup.
Qed.
Lemma eq_count_undup a s1 s2 :
{in a, s1 =i s2} -> count a (undup s1) = count a (undup s2).
Proof.
move=> s1_eq_s2; rewrite -!size_filter !filter_undup.
apply/perm_size/perm_undup => x.
by rewrite !mem_filter; case: (boolP (a x)) => //= /s1_eq_s2.
Qed.
Lemma catCA_perm_ind P :
(forall s1 s2 s3, P (s1 ++ s2 ++ s3) -> P (s2 ++ s1 ++ s3)) ->
(forall s1 s2, perm_eq s1 s2 -> P s1 -> P s2).
Proof.
move=> PcatCA s1 s2 eq_s12; rewrite -[s1]cats0 -[s2]cats0.
elim: s2 nil => [|x s2 IHs] s3 in s1 eq_s12 *.
by case: s1 {eq_s12}(perm_size eq_s12).
have /rot_to[i s' def_s1]: x \in s1 by rewrite (perm_mem eq_s12) mem_head.
rewrite -(cat_take_drop i s1) -catA => /PcatCA.
rewrite catA -/(rot i s1) def_s1 /= -cat1s => /PcatCA/IHs/PcatCA; apply.
by rewrite -(perm_cons x) -def_s1 perm_rot.
Qed.
Lemma catCA_perm_subst R F :
(forall s1 s2 s3, F (s1 ++ s2 ++ s3) = F (s2 ++ s1 ++ s3) :> R) ->
(forall s1 s2, perm_eq s1 s2 -> F s1 = F s2).
Proof.
move=> FcatCA s1 s2 /catCA_perm_ind => ind_s12.
by apply: (ind_s12 (eq _ \o F)) => //= *; rewrite FcatCA.
Qed.
End PermSeq.
Notation perm_eql s1 s2 := (perm_eq s1 =1 perm_eq s2).
Notation perm_eqr s1 s2 := (perm_eq^~ s1 =1 perm_eq^~ s2).
Arguments permP {T s1 s2}.
Arguments permPl {T s1 s2}.
Arguments permPr {T s1 s2}.
Prenex Implicits perm_eq.
#[global] Hint Resolve perm_refl : core.
Section RotrLemmas.
Variables (n0 : nat) (T : Type) (T' : eqType).
Implicit Types (x : T) (s : seq T).
Lemma size_rotr s : size (rotr n0 s) = size s.
Proof. by rewrite size_rot. Qed.
Lemma mem_rotr (s : seq T') : rotr n0 s =i s.
Proof. by move=> x; rewrite mem_rot. Qed.
Lemma rotr_size_cat s1 s2 : rotr (size s2) (s1 ++ s2) = s2 ++ s1.
Proof. by rewrite /rotr size_cat addnK rot_size_cat. Qed.
Lemma rotr1_rcons x s : rotr 1 (rcons s x) = x :: s.
Proof. by rewrite -rot1_cons rotK. Qed.
Lemma has_rotr a s : has a (rotr n0 s) = has a s.
Proof. by rewrite has_rot. Qed.
Lemma rotr_uniq (s : seq T') : uniq (rotr n0 s) = uniq s.
Proof. by rewrite rot_uniq. Qed.
Lemma rotrK : cancel (@rotr T n0) (rot n0).
Proof.
move=> s; have [lt_n0s | ge_n0s] := ltnP n0 (size s).
by rewrite -{1}(subKn (ltnW lt_n0s)) -{1}[size s]size_rotr; apply: rotK.
by rewrite -[in RHS](rot_oversize ge_n0s) /rotr (eqnP ge_n0s) rot0.
Qed.
Lemma rotr_inj : injective (@rotr T n0).
Proof. exact (can_inj rotrK). Qed.
Lemma take_rev s : take n0 (rev s) = rev (drop (size s - n0) s).
Proof.
set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat take_cat.
rewrite size_rev size_drop -minnE minnC leq_min ltnn /m.
by have [_|/eqnP->] := ltnP; rewrite ?subnn take0 cats0.
Qed.
Lemma rev_take s : rev (take n0 s) = drop (size s - n0) (rev s).
Proof. by rewrite -[s in take _ s]revK take_rev revK size_rev. Qed.
Lemma drop_rev s : drop n0 (rev s) = rev (take (size s - n0) s).
Proof.
set m := _ - n0; rewrite -[s in LHS](cat_take_drop m) rev_cat drop_cat.
rewrite size_rev size_drop -minnE minnC leq_min ltnn /m.
by have [_|/eqnP->] := ltnP; rewrite ?take0 // subnn drop0.
Qed.
Lemma rev_drop s : rev (drop n0 s) = take (size s - n0) (rev s).
Proof. by rewrite -[s in drop _ s]revK drop_rev revK size_rev. Qed.
Lemma rev_rotr s : rev (rotr n0 s) = rot n0 (rev s).
Proof. by rewrite rev_cat -take_rev -drop_rev. Qed.
Lemma rev_rot s : rev (rot n0 s) = rotr n0 (rev s).
Proof. by apply: canLR revK _; rewrite rev_rotr revK. Qed.
End RotrLemmas.
Arguments rotrK n0 {T} s : rename.
Arguments rotr_inj {n0 T} [s1 s2] eq_rotr_s12 : rename.
Section RotCompLemmas.
Variable T : Type.
Implicit Type s : seq T.
Lemma rotD m n s : m + n <= size s -> rot (m + n) s = rot m (rot n s).
Proof.
move=> sz_s; rewrite [LHS]/rot -[take _ s](cat_take_drop n).
rewrite 5!(catA, =^~ rot_size_cat) !cat_take_drop.
by rewrite size_drop !size_takel ?leq_addl ?addnK.
Qed.
Lemma rotS n s : n < size s -> rot n.+1 s = rot 1 (rot n s).
Proof. exact: (@rotD 1). Qed.
Lemma rot_add_mod m n s : n <= size s -> m <= size s ->
rot m (rot n s) = rot (if m + n <= size s then m + n else m + n - size s) s.
Proof.
move=> Hn Hm; case: leqP => [/rotD // | /ltnW Hmn]; symmetry.
by rewrite -{2}(rotK n s) /rotr -rotD size_rot addnBA ?subnK ?addnK.
Qed.
Lemma rot_minn n s : rot n s = rot (minn n (size s)) s.
Proof.
by case: (leqP n (size s)) => // /leqW ?; rewrite rot_size rot_oversize.
Qed.
Definition rot_add s n m (k := size s) (p := minn m k + minn n k) :=
locked (if p <= k then p else p - k).
Lemma leq_rot_add n m s : rot_add s n m <= size s.
Proof.
by unlock rot_add; case: ifP; rewrite // leq_subLR leq_add // geq_minr.
Qed.
Lemma rot_addC n m s : rot_add s n m = rot_add s m n.
Proof. by unlock rot_add; rewrite ![minn n _ + _]addnC. Qed.
Lemma rot_rot_add n m s : rot m (rot n s) = rot (rot_add s n m) s.
Proof.
unlock rot_add.
by rewrite (rot_minn n) (rot_minn m) rot_add_mod ?size_rot ?geq_minr.
Qed.
Lemma rot_rot m n s : rot m (rot n s) = rot n (rot m s).
Proof. by rewrite rot_rot_add rot_addC -rot_rot_add. Qed.
Lemma rot_rotr m n s : rot m (rotr n s) = rotr n (rot m s).
Proof. by rewrite [RHS]/rotr size_rot rot_rot. Qed.
Lemma rotr_rotr m n s : rotr m (rotr n s) = rotr n (rotr m s).
Proof. by rewrite /rotr !size_rot rot_rot. Qed.
End RotCompLemmas.
Section Mask.
Variables (n0 : nat) (T : Type).
Implicit Types (m : bitseq) (s : seq T).
Fixpoint mask m s {struct m} :=
match m, s with
| b :: m', x :: s' => if b then x :: mask m' s' else mask m' s'
| _, _ => [::]
end.
Lemma mask_false s n : mask (nseq n false) s = [::].
Proof. by elim: s n => [|x s IHs] [|n] /=. Qed.
Lemma mask_true s n : size s <= n -> mask (nseq n true) s = s.
Proof. by elim: s n => [|x s IHs] [|n] //= Hn; congr (_ :: _); apply: IHs. Qed.
Lemma mask0 m : mask m [::] = [::].
Proof. by case: m. Qed.
Lemma mask0s s : mask [::] s = [::]. Proof. by []. Qed.
Lemma mask1 b x : mask [:: b] [:: x] = nseq b x.
Proof. by case: b. Qed.
Lemma mask_cons b m x s : mask (b :: m) (x :: s) = nseq b x ++ mask m s.
Proof. by case: b. Qed.
Lemma size_mask m s : size m = size s -> size (mask m s) = count id m.
Proof. by move: m s; apply: seq_ind2 => // -[] x m s /= _ ->. Qed.
Lemma mask_cat m1 m2 s1 s2 :
size m1 = size s1 -> mask (m1 ++ m2) (s1 ++ s2) = mask m1 s1 ++ mask m2 s2.
Proof. by move: m1 s1; apply: seq_ind2 => // -[] m1 x1 s1 /= _ ->. Qed.
Lemma mask_rcons b m x s : size m = size s ->
mask (rcons m b) (rcons s x) = mask m s ++ nseq b x.
Proof. by move=> ms; rewrite -!cats1 mask_cat//; case: b. Qed.
Lemma all_mask a m s : all a s -> all a (mask m s).
Proof. by elim: s m => [|x s IHs] [|[] m]//= /andP[ax /IHs->]; rewrite ?ax. Qed.
Lemma has_mask_cons a b m x s :
has a (mask (b :: m) (x :: s)) = b && a x || has a (mask m s).
Proof. by case: b. Qed.
Lemma has_mask a m s : has a (mask m s) -> has a s.
Proof. by apply/contraTT; rewrite -!all_predC; apply: all_mask. Qed.
Lemma rev_mask m s : size m = size s -> rev (mask m s) = mask (rev m) (rev s).
Proof.
move: m s; apply: seq_ind2 => //= b x m s eq_size_sm IH.
by case: b; rewrite !rev_cons mask_rcons ?IH ?size_rev// (cats1, cats0).
Qed.
Lemma mask_rot m s : size m = size s ->
mask (rot n0 m) (rot n0 s) = rot (count id (take n0 m)) (mask m s).
Proof.
move=> Ems; rewrite mask_cat ?size_drop ?Ems // -rot_size_cat.
by rewrite size_mask -?mask_cat ?size_take ?Ems // !cat_take_drop.
Qed.
Lemma resize_mask m s : {m1 | size m1 = size s & mask m s = mask m1 s}.
Proof.
exists (take (size s) m ++ nseq (size s - size m) false).
by elim: s m => [|x s IHs] [|b m] //=; rewrite (size_nseq, IHs).
by elim: s m => [|x s IHs] [|b m] //=; rewrite (mask_false, IHs).
Qed.
Lemma takeEmask i s : take i s = mask (nseq i true) s.
Proof. by elim: i s => [s|i IHi []// ? ?]; rewrite ?take0 //= IHi. Qed.
Lemma dropEmask i s :
drop i s = mask (nseq i false ++ nseq (size s - i) true) s.
Proof. by elim: i s => [s|? ? []//]; rewrite drop0/= mask_true// subn0. Qed.
End Mask.
Arguments mask _ !_ !_.
Section EqMask.
Variables (n0 : nat) (T : eqType).
Implicit Types (s : seq T) (m : bitseq).
Lemma mem_mask_cons x b m y s :
(x \in mask (b :: m) (y :: s)) = b && (x == y) || (x \in mask m s).
Proof. by case: b. Qed.
Lemma mem_mask x m s : x \in mask m s -> x \in s.
Proof. by rewrite -!has_pred1 => /has_mask. Qed.
Lemma in_mask x m s :
uniq s -> x \in mask m s = (x \in s) && nth false m (index x s).
Proof.
elim: s m => [|y s IHs] [|[] m]//= /andP[yNs ?]; rewrite ?in_cons ?IHs //=;
by have [->|neq_xy] //= := eqVneq; rewrite ?andbF // (negPf yNs).
Qed.
Lemma mask_uniq s : uniq s -> forall m, uniq (mask m s).
Proof.
elim: s => [|x s IHs] Uxs [|b m] //=.
case: b Uxs => //= /andP[s'x Us]; rewrite {}IHs // andbT.
by apply: contra s'x; apply: mem_mask.
Qed.
Lemma mem_mask_rot m s :
size m = size s -> mask (rot n0 m) (rot n0 s) =i mask m s.
Proof. by move=> Ems x; rewrite mask_rot // mem_rot. Qed.
End EqMask.
Section Subseq.
Variable T : eqType.
Implicit Type s : seq T.
Fixpoint subseq s1 s2 :=
if s2 is y :: s2' then
if s1 is x :: s1' then subseq (if x == y then s1' else s1) s2' else true
else s1 == [::].
Lemma sub0seq s : subseq [::] s. Proof. by case: s. Qed.
Lemma subseq0 s : subseq s [::] = (s == [::]). Proof. by []. Qed.
Lemma subseq_refl s : subseq s s.
Proof. by elim: s => //= x s IHs; rewrite eqxx. Qed.
Hint Resolve subseq_refl : core.
Lemma subseqP s1 s2 :
reflect (exists2 m, size m = size s2 & s1 = mask m s2) (subseq s1 s2).
Proof.
elim: s2 s1 => [|y s2 IHs2] [|x s1].
- by left; exists [::].
- by right=> -[m /eqP/nilP->].
- by left; exists (nseq (size s2).+1 false); rewrite ?size_nseq //= mask_false.
apply: {IHs2}(iffP (IHs2 _)) => [] [m sz_m def_s1].
by exists ((x == y) :: m); rewrite /= ?sz_m // -def_s1; case: eqP => // ->.
case: eqP => [_ | ne_xy]; last first.
by case: m def_s1 sz_m => [|[] m] //; [case | move=> -> [<-]; exists m].
pose i := index true m; have def_m_i: take i m = nseq (size (take i m)) false.
apply/all_pred1P; apply/(all_nthP true) => j.
rewrite size_take ltnNge geq_min negb_or -ltnNge => /andP[lt_j_i _].
rewrite nth_take //= -negb_add addbF -addbT -negb_eqb.
by rewrite [_ == _](before_find _ lt_j_i).
have lt_i_m: i < size m.
rewrite ltnNge; apply/negP=> le_m_i; rewrite take_oversize // in def_m_i.
by rewrite def_m_i mask_false in def_s1.
rewrite size_take lt_i_m in def_m_i.
exists (take i m ++ drop i.+1 m).
rewrite size_cat size_take size_drop lt_i_m.
by rewrite sz_m in lt_i_m *; rewrite subnKC.
rewrite {s1 def_s1}[s1](congr1 behead def_s1).
rewrite -[s2](cat_take_drop i) -[m in LHS](cat_take_drop i) {}def_m_i -cat_cons.
have sz_i_s2: size (take i s2) = i by apply: size_takel; rewrite sz_m in lt_i_m.
rewrite lastI cat_rcons !mask_cat ?size_nseq ?size_belast ?mask_false //=.
by rewrite (drop_nth true) // nth_index -?index_mem.
Qed.
Lemma mask_subseq m s : subseq (mask m s) s.
Proof. by apply/subseqP; have [m1] := resize_mask m s; exists m1. Qed.
Lemma subseq_trans : transitive subseq.
Proof.
move=> _ _ s /subseqP[m2 _ ->] /subseqP[m1 _ ->].
elim: s => [|x s IHs] in m2 m1 *; first by rewrite !mask0.
case: m1 => [|[] m1]; first by rewrite mask0.
case: m2 => [|[] m2] //; first by rewrite /= eqxx IHs.
case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP.
by exists (false :: m); rewrite //= sz_m.
case/subseqP: (IHs m2 m1) => m sz_m def_s; apply/subseqP.
by exists (false :: m); rewrite //= sz_m.
Qed.
Lemma cat_subseq s1 s2 s3 s4 :
subseq s1 s3 -> subseq s2 s4 -> subseq (s1 ++ s2) (s3 ++ s4).
Proof.
case/subseqP=> m1 sz_m1 -> /subseqP [m2 sz_m2 ->]; apply/subseqP.
by exists (m1 ++ m2); rewrite ?size_cat ?mask_cat ?sz_m1 ?sz_m2.
Qed.
Lemma prefix_subseq s1 s2 : subseq s1 (s1 ++ s2).
Proof. by rewrite -[s1 in subseq s1]cats0 cat_subseq ?sub0seq. Qed.
Lemma suffix_subseq s1 s2 : subseq s2 (s1 ++ s2).
Proof. exact: cat_subseq (sub0seq s1) _. Qed.
Lemma take_subseq s i : subseq (take i s) s.
Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) prefix_subseq. Qed.
Lemma drop_subseq s i : subseq (drop i s) s.
Proof. by rewrite -[s in X in subseq _ X](cat_take_drop i) suffix_subseq. Qed.
Lemma mem_subseq s1 s2 : subseq s1 s2 -> {subset s1 <= s2}.
Proof. by case/subseqP=> m _ -> x; apply: mem_mask. Qed.
Lemma sub1seq x s : subseq [:: x] s = (x \in s).
Proof. by elim: s => //= y s /[1!inE]; case: ifP; rewrite ?sub0seq. Qed.
Lemma size_subseq s1 s2 : subseq s1 s2 -> size s1 <= size s2.
Proof. by case/subseqP=> m sz_m ->; rewrite size_mask -sz_m ?count_size. Qed.
Lemma size_subseq_leqif s1 s2 :
subseq s1 s2 -> size s1 <= size s2 ?= iff (s1 == s2).
Proof.
move=> sub12; split; first exact: size_subseq.
apply/idP/eqP=> [|-> //]; case/subseqP: sub12 => m sz_m ->{s1}.
rewrite size_mask -sz_m // -all_count -(eq_all eqb_id).
by move/(@all_pred1P _ true)->; rewrite sz_m mask_true.
Qed.
Lemma subseq_anti : antisymmetric subseq.
Proof.
move=> s1 s2 /andP[] /size_subseq_leqif /leqifP.
by case: eqP => [//|_] + /size_subseq; rewrite ltnNge => /negP.
Qed.
Lemma subseq_cons s x : subseq s (x :: s).
Proof. exact: suffix_subseq [:: x] s. Qed.
Lemma cons_subseq s1 s2 x : subseq (x :: s1) s2 -> subseq s1 s2.
Proof. exact/subseq_trans/subseq_cons. Qed.
Lemma subseq_rcons s x : subseq s (rcons s x).
Proof. by rewrite -cats1 prefix_subseq. Qed.
Lemma subseq_uniq s1 s2 : subseq s1 s2 -> uniq s2 -> uniq s1.
Proof. by case/subseqP=> m _ -> Us2; apply: mask_uniq. Qed.
Lemma take_uniq s n : uniq s -> uniq (take n s).
Proof. exact/subseq_uniq/take_subseq. Qed.
Lemma drop_uniq s n : uniq s -> uniq (drop n s).
Proof. exact/subseq_uniq/drop_subseq. Qed.
Lemma undup_subseq s : subseq (undup s) s.
Proof.
elim: s => //= x s; case: (_ \in _); last by rewrite eqxx.
by case: (undup s) => //= y u; case: (_ == _) => //=; apply: cons_subseq.
Qed.
Lemma subseq_rev s1 s2 : subseq (rev s1) (rev s2) = subseq s1 s2.
Proof.
wlog suff W : s1 s2 / subseq s1 s2 -> subseq (rev s1) (rev s2).
by apply/idP/idP => /W //; rewrite !revK.
by case/subseqP => m size_m ->; rewrite rev_mask // mask_subseq.
Qed.
Lemma subseq_cat2l s s1 s2 : subseq (s ++ s1) (s ++ s2) = subseq s1 s2.
Proof. by elim: s => // x s IHs; rewrite !cat_cons /= eqxx. Qed.
Lemma subseq_cat2r s s1 s2 : subseq (s1 ++ s) (s2 ++ s) = subseq s1 s2.
Proof. by rewrite -subseq_rev !rev_cat subseq_cat2l subseq_rev. Qed.
Lemma subseq_rot p s n :
subseq p s -> exists2 k, k <= n & subseq (rot k p) (rot n s).
Proof.
move=> /subseqP[m size_m ->].
exists (count id (take n m)); last by rewrite -mask_rot // mask_subseq.
by rewrite (leq_trans (count_size _ _))// size_take_min geq_minl.
Qed.
End Subseq.
Prenex Implicits subseq.
Arguments subseqP {T s1 s2}.
#[global] Hint Resolve subseq_refl : core.
Section Rem.
Variables (T : eqType) (x : T).
Fixpoint rem s := if s is y :: t then (if y == x then t else y :: rem t) else s.
Lemma rem_cons y s : rem (y :: s) = if y == x then s else y :: rem s.
Proof. by []. Qed.
Lemma remE s : rem s = take (index x s) s ++ drop (index x s).+1 s.
Proof. by elim: s => //= y s ->; case: eqVneq; rewrite ?drop0. Qed.
Lemma rem_id s : x \notin s -> rem s = s.
Proof. by elim: s => //= y s IHs /norP[neq_yx /IHs->]; case: eqVneq neq_yx. Qed.
Lemma perm_to_rem s : x \in s -> perm_eq s (x :: rem s).
Proof.
move=> xs; rewrite remE -[X in perm_eq X](cat_take_drop (index x s)).
by rewrite drop_index// -cat1s perm_catCA cat1s.
Qed.
Lemma size_rem s : x \in s -> size (rem s) = (size s).-1.
Proof. by move/perm_to_rem/perm_size->. Qed.
Lemma rem_subseq s : subseq (rem s) s.
Proof.
elim: s => //= y s IHs; rewrite eq_sym.
by case: ifP => _; [apply: subseq_cons | rewrite eqxx].
Qed.
Lemma rem_uniq s : uniq s -> uniq (rem s).
Proof. by apply: subseq_uniq; apply: rem_subseq. Qed.
Lemma mem_rem s : {subset rem s <= s}.
Proof. exact: mem_subseq (rem_subseq s). Qed.
Lemma rem_mem y s : y != x -> y \in s -> y \in rem s.
Proof.
move=> yx; elim: s => [//|z s IHs] /=.
rewrite inE => /orP[/eqP<-|ys]; first by rewrite (negbTE yx) inE eqxx.
by case: ifP => _ //; rewrite inE IHs ?orbT.
Qed.
Lemma rem_filter s : uniq s -> rem s = filter (predC1 x) s.
Proof.
elim: s => //= y s IHs /andP[not_s_y /IHs->].
by case: eqP => //= <-; apply/esym/all_filterP; rewrite all_predC has_pred1.
Qed.
Lemma mem_rem_uniq s : uniq s -> rem s =i [predD1 s & x].
Proof. by move/rem_filter=> -> y; rewrite mem_filter. Qed.
Lemma mem_rem_uniqF s : uniq s -> x \in rem s = false.
Proof. by move/mem_rem_uniq->; rewrite inE eqxx. Qed.
Lemma count_rem P s : count P (rem s) = count P s - (x \in s) && P x.
Proof.
have [/perm_to_rem/permP->|xNs]/= := boolP (x \in s); first by rewrite addKn.
by rewrite subn0 rem_id.
Qed.
Lemma count_mem_rem y s : count_mem y (rem s) = count_mem y s - (x == y).
Proof.
rewrite count_rem; have []//= := boolP (x \in s).
by case: eqP => // <- /count_memPn->.
Qed.
End Rem.
Section Map.
Variables (n0 : nat) (T1 : Type) (x1 : T1).
Variables (T2 : Type) (x2 : T2) (f : T1 -> T2).
Fixpoint map s := if s is x :: s' then f x :: map s' else [::].
Lemma map_cons x s : map (x :: s) = f x :: map s.
Proof. by []. Qed.
Lemma map_nseq x : map (nseq n0 x) = nseq n0 (f x).
Proof. by elim: n0 => // *; congr (_ :: _). Qed.
Lemma map_cat s1 s2 : map (s1 ++ s2) = map s1 ++ map s2.
Proof. by elim: s1 => [|x s1 IHs] //=; rewrite IHs. Qed.
Lemma size_map s : size (map s) = size s.
Proof. by elim: s => //= x s ->. Qed.
Lemma behead_map s : behead (map s) = map (behead s).
Proof. by case: s. Qed.
Lemma nth_map n s : n < size s -> nth x2 (map s) n = f (nth x1 s n).
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma map_rcons s x : map (rcons s x) = rcons (map s) (f x).
Proof. by rewrite -!cats1 map_cat. Qed.
Lemma last_map s x : last (f x) (map s) = f (last x s).
Proof. by elim: s x => /=. Qed.
Lemma belast_map s x : belast (f x) (map s) = map (belast x s).
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma filter_map a s : filter a (map s) = map (filter (preim f a) s).
Proof. by elim: s => //= x s IHs; rewrite (fun_if map) /= IHs. Qed.
Lemma find_map a s : find a (map s) = find (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma has_map a s : has a (map s) = has (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma all_map a s : all a (map s) = all (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma all_mapT (a : pred T2) s : (forall x, a (f x)) -> all a (map s).
Proof. by rewrite all_map => /allT->. Qed.
Lemma count_map a s : count a (map s) = count (preim f a) s.
Proof. by elim: s => //= x s ->. Qed.
Lemma map_take s : map (take n0 s) = take n0 (map s).
Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed.
Lemma map_drop s : map (drop n0 s) = drop n0 (map s).
Proof. by elim: n0 s => [|n IHn] [|x s] //=; rewrite IHn. Qed.
Lemma map_rot s : map (rot n0 s) = rot n0 (map s).
Proof. by rewrite /rot map_cat map_take map_drop. Qed.
Lemma map_rotr s : map (rotr n0 s) = rotr n0 (map s).
Proof. by apply: canRL (rotK n0) _; rewrite -map_rot rotrK. Qed.
Lemma map_rev s : map (rev s) = rev (map s).
Proof. by elim: s => //= x s IHs; rewrite !rev_cons -!cats1 map_cat IHs. Qed.
Lemma map_mask m s : map (mask m s) = mask m (map s).
Proof. by elim: m s => [|[|] m IHm] [|x p] //=; rewrite IHm. Qed.
Lemma inj_map : injective f -> injective map.
Proof. by move=> injf; elim=> [|x s IHs] [|y t] //= [/injf-> /IHs->]. Qed.
Lemma inj_in_map (A : {pred T1}) :
{in A &, injective f} -> {in [pred s | all [in A] s] &, injective map}.
Proof.
move=> injf; elim=> [|x s IHs] [|y t] //= /andP[Ax As] /andP[Ay At].
by case=> /injf-> // /IHs->.
Qed.
End Map.
(* Sequence indexing with error. *)
Section onth.
Variable T : Type.
Implicit Types x y z : T.
Implicit Types m n : nat.
Implicit Type s : seq T.
Fixpoint onth s n {struct n} : option T :=
if s isn't x :: s then None else
if n isn't n.+1 then Some x else onth s n.
Lemma odflt_onth x0 s n : odflt x0 (onth s n) = nth x0 s n.
Proof. by elim: n s => [|? ?] []. Qed.
Lemma onthE s : onth s =1 nth None (map Some s).
Proof. by move=> n; elim: n s => [|? ?] []. Qed.
Lemma onth_nth x0 x t n : onth t n = Some x -> nth x0 t n = x.
Proof. by move=> tn; rewrite -odflt_onth tn. Qed.
Lemma onth0n n : onth [::] n = None. Proof. by case: n. Qed.
Lemma onth1P x y n : onth [:: x] n = Some y <-> n = 0 /\ x = y.
Proof. by case: n => [|[]]; split=> // -[] // _ ->. Qed.
Lemma onthTE s n : onth s n = (n < size s) :> bool.
Proof. by elim: n s => [|? ?] []. Qed.
Lemma onthNE s n: ~~ onth s n = (size s <= n).
Proof. by rewrite onthTE -leqNgt. Qed.
Lemma onth_default n s : size s <= n -> onth s n = None.
Proof. by rewrite -onthNE; case: onth. Qed.
Lemma onth_cat s1 s2 n :
onth (s1 ++ s2) n = if n < size s1 then onth s1 n else onth s2 (n - size s1).
Proof. by elim: n s1 => [|? ?] []. Qed.
Lemma onth_nseq x n m : onth (nseq n x) m = if m < n then Some x else None.
Proof. by rewrite onthE/= -nth_nseq map_nseq. Qed.
Lemma eq_onthP {s1 s2} :
[<-> s1 = s2;
forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i;
forall i : nat, onth s1 i = onth s2 i].
Proof.
tfae=> [->//|eqs12 i|eqs12].
have := eqs12 i; case: ltnP => [_ ->//|].
by rewrite geq_max => /andP[is1 is2] _; rewrite !onth_default.
have /eqP eq_size_12 : size s1 == size s2.
by rewrite eqn_leq -!onthNE eqs12 onthNE -eqs12 onthNE !leqnn.
apply/(inj_map Some_inj)/(@eq_from_nth _ None); rewrite !size_map//.
by move=> i _; rewrite -!onthE eqs12.
Qed.
Lemma eq_from_onth [s1 s2 : seq T] :
(forall i : nat, onth s1 i = onth s2 i) -> s1 = s2.
Proof. by move/(eq_onthP 0 2). Qed.
Lemma eq_from_onth_le [s1 s2 : seq T] :
(forall i : nat, i < maxn (size s1) (size s2) -> onth s1 i = onth s2 i) ->
s1 = s2.
Proof. by move/(eq_onthP 0 1). Qed.
End onth.
Lemma onth_map {T S} n (s : seq T) (f : T -> S) :
onth (map f s) n = omap f (onth s n).
Proof. by elim: s n => [|x s IHs] []. Qed.
Lemma inj_onth_map {T S} n (s : seq T) (f : T -> S) x :
injective f -> onth (map f s) n = Some (f x) -> onth s n = Some x.
Proof. by rewrite onth_map => /inj_omap + fs; apply. Qed.
Section onthEqType.
Variables T : eqType.
Implicit Types x y z : T.
Implicit Types i m n : nat.
Implicit Type s : seq T.
Lemma onthP s x : reflect (exists i, onth s i = Some x) (x \in s).
Proof.
elim: s => [|y s IHs]; first by constructor=> -[] [].
rewrite in_cons; case: eqVneq => [->|/= Nxy]; first by constructor; exists 0.
apply: (iffP idP) => [/IHs[i <-]|[[|i]//=]]; first by exists i.+1.
by move=> [eq_xy]; rewrite eq_xy eqxx in Nxy.
by move=> six; apply/IHs; exists i.
Qed.
Lemma onthPn s x : reflect (forall i, onth s i != Some x) (x \notin s).
Proof.
apply: (iffP idP); first by move=> /onthP + i; apply: contra_not_neq; exists i.
by move=> nsix; apply/onthP => -[n /eqP/negPn]; rewrite nsix.
Qed.
Lemma onth_inj s n m : uniq s -> minn m n < size s ->
onth s n = onth s m -> n = m.
Proof.
elim: s m n => [|x s IHs]//= [|m] [|n]//=; rewrite ?minnSS !ltnS.
- by move=> /andP[+ _] _ /eqP => /onthPn/(_ _)/negPf->.
- by move=> /andP[+ _] _ /esym /eqP => /onthPn/(_ _)/negPf->.
by move=> /andP[xNs /IHs]/[apply]/[apply]->.
Qed.
End onthEqType.
Arguments onthP {T s x}.
Arguments onthPn {T s x}.
Arguments onth_nth {T}.
Arguments onth_inj {T}.
Notation "[ 'seq' E | i <- s ]" := (map (fun i => E) s)
(i binder, format "[ '[hv' 'seq' E '/ ' | i <- s ] ']'") : seq_scope.
Notation "[ 'seq' E | i <- s & C ]" := [seq E | i <- [seq i <- s | C]]
(i binder,
format "[ '[hv' 'seq' E '/ ' | i <- s '/ ' & C ] ']'") : seq_scope.
Notation "[ 'seq' E : R | i <- s ]" := (@map _ R (fun i => E) s)
(i binder, only parsing) : seq_scope.
Notation "[ 'seq' E : R | i <- s & C ]" := [seq E : R | i <- [seq i <- s | C]]
(i binder, only parsing) : seq_scope.
Lemma filter_mask T a (s : seq T) : filter a s = mask (map a s) s.
Proof. by elim: s => //= x s <-; case: (a x). Qed.
Lemma all_sigP T a (s : seq T) : all a s -> {s' : seq (sig a) | s = map sval s'}.
Proof.
elim: s => /= [_|x s ihs /andP [ax /ihs [s' ->]]]; first by exists [::].
by exists (exist a x ax :: s').
Qed.
Section MiscMask.
Lemma leq_count_mask T (P : {pred T}) m s : count P (mask m s) <= count P s.
Proof.
by elim: s m => [|x s IHs] [|[] m]//=;
rewrite ?leq_add2l (leq_trans (IHs _)) ?leq_addl.
Qed.
Variable (T : eqType).
Implicit Types (s : seq T) (m : bitseq).
Lemma mask_filter s m : uniq s -> mask m s = [seq i <- s | i \in mask m s].
Proof.
elim: m s => [|[] m IH] [|x s /= /andP[/negP xS uS]]; rewrite ?filter_pred0 //.
rewrite inE eqxx /=; congr cons; rewrite [LHS]IH//.
by apply/eq_in_filter => ? /[1!inE]; case: eqP => [->|].
by case: ifP => [/mem_mask //|_]; apply: IH.
Qed.
Lemma leq_count_subseq P s1 s2 : subseq s1 s2 -> count P s1 <= count P s2.
Proof. by move=> /subseqP[m _ ->]; rewrite leq_count_mask. Qed.
Lemma count_maskP s1 s2 :
(forall x, count_mem x s1 <= count_mem x s2) <->
exists2 m : bitseq, size m = size s2 & perm_eq s1 (mask m s2).
Proof.
split=> [s1_le|[m _ /permP s1ms2 x]]; last by rewrite s1ms2 leq_count_mask.
suff [m mP]: exists m, perm_eq s1 (mask m s2).
by have [m' sm' eqm] := resize_mask m s2; exists m'; rewrite -?eqm.
elim: s2 => [|x s2 IHs]//= in s1 s1_le *.
by exists [::]; apply/allP => x _/=; rewrite eqn_leq s1_le.
have [y|m s1s2] := IHs (rem x s1); first by rewrite count_mem_rem leq_subLR.
exists ((x \in s1) :: m); have [|/rem_id<-//] := boolP (x \in s1).
by move/perm_to_rem/permPl->; rewrite perm_cons.
Qed.
Lemma count_subseqP s1 s2 :
(forall x, count_mem x s1 <= count_mem x s2) <->
exists2 s, subseq s s2 & perm_eq s1 s.
Proof.
split=> [/count_maskP[m _]|]; first by exists (mask m s2); rewrite ?mask_subseq.
by move=> -[_/subseqP[m sm ->] ?]; apply/count_maskP; exists m.
Qed.
End MiscMask.
Section FilterSubseq.
Variable T : eqType.
Implicit Types (s : seq T) (a : pred T).
Lemma filter_subseq a s : subseq (filter a s) s.
Proof. by apply/subseqP; exists (map a s); rewrite ?size_map ?filter_mask. Qed.
Lemma subseq_filter s1 s2 a :
subseq s1 (filter a s2) = all a s1 && subseq s1 s2.
Proof.
elim: s2 s1 => [|x s2 IHs] [|y s1] //=; rewrite ?andbF ?sub0seq //.
by case a_x: (a x); rewrite /= !IHs /=; case: eqP => // ->; rewrite a_x.
Qed.
Lemma subseq_uniqP s1 s2 :
uniq s2 -> reflect (s1 = filter [in s1] s2) (subseq s1 s2).
Proof.
move=> uniq_s2; apply: (iffP idP) => [ss12 | ->]; last exact: filter_subseq.
apply/eqP; rewrite -size_subseq_leqif ?subseq_filter ?(introT allP) //.
apply/eqP/esym/perm_size.
rewrite uniq_perm ?filter_uniq ?(subseq_uniq ss12) // => x.
by rewrite mem_filter; apply: andb_idr; apply: (mem_subseq ss12).
Qed.
Lemma uniq_subseq_pivot x (s1 s2 s3 s4 : seq T) (s := s3 ++ x :: s4) :
uniq s -> subseq (s1 ++ x :: s2) s = (subseq s1 s3 && subseq s2 s4).
Proof.
move=> uniq_s; apply/idP/idP => [sub_s'_s|/andP[? ?]]; last first.
by rewrite cat_subseq //= eqxx.
have uniq_s' := subseq_uniq sub_s'_s uniq_s.
have/eqP {sub_s'_s uniq_s} := subseq_uniqP _ uniq_s sub_s'_s.
rewrite !filter_cat /= mem_cat inE eqxx orbT /=.
rewrite uniq_eqseq_pivotl // => /andP [/eqP -> /eqP ->].
by rewrite !filter_subseq.
Qed.
Lemma perm_to_subseq s1 s2 :
subseq s1 s2 -> {s3 | perm_eq s2 (s1 ++ s3)}.
Proof.
elim Ds2: s2 s1 => [|y s2' IHs] [|x s1] //=; try by exists s2; rewrite Ds2.
case: eqP => [-> | _] /IHs[s3 perm_s2] {IHs}.
by exists s3; rewrite perm_cons.
by exists (rcons s3 y); rewrite -cat_cons -perm_rcons -!cats1 catA perm_cat2r.
Qed.
Lemma subseq_rem x : {homo rem x : s1 s2 / @subseq T s1 s2}.
Proof.
move=> s1 s2; elim: s2 s1 => [|x2 s2 IHs2] [|x1 s1]; rewrite ?sub0seq //=.
have [->|_] := eqVneq x1 x2; first by case: eqP => //= _ /IHs2; rewrite eqxx.
move=> /IHs2/subseq_trans->//.
by have [->|_] := eqVneq x x2; [apply: rem_subseq|apply: subseq_cons].
Qed.
End FilterSubseq.
Arguments subseq_uniqP [T s1 s2].
Section EqMap.
Variables (n0 : nat) (T1 : eqType) (x1 : T1).
Variables (T2 : eqType) (x2 : T2) (f : T1 -> T2).
Implicit Type s : seq T1.
Lemma map_f s x : x \in s -> f x \in map f s.
Proof.
by elim: s => //= y s IHs /predU1P[->|/IHs]; [apply: predU1l | apply: predU1r].
Qed.
Lemma mapP s y : reflect (exists2 x, x \in s & y = f x) (y \in map f s).
Proof.
elim: s => [|x s IHs]; [by right; case|rewrite /= inE].
exact: equivP (orPP eqP IHs) (iff_sym exists_cons).
Qed.
Lemma subset_mapP (s : seq T1) (s' : seq T2) :
{subset s' <= map f s} <-> exists2 t, all (mem s) t & s' = map f t.
Proof.
split => [|[r /allP/= rE ->] _ /mapP[x xr ->]]; last by rewrite map_f ?rE.
elim: s' => [|x s' IHs'] subss'; first by exists [::].
have /mapP[y ys ->] := subss' _ (mem_head _ _).
have [x' x's'|t st ->] := IHs'; first by rewrite subss'// inE x's' orbT.
by exists (y :: t); rewrite //= ys st.
Qed.
Lemma map_uniq s : uniq (map f s) -> uniq s.
Proof.
elim: s => //= x s IHs /andP[not_sfx /IHs->]; rewrite andbT.
by apply: contra not_sfx => sx; apply/mapP; exists x.
Qed.
Lemma map_inj_in_uniq s : {in s &, injective f} -> uniq (map f s) = uniq s.
Proof.
elim: s => //= x s IHs //= injf; congr (~~ _ && _).
apply/mapP/idP=> [[y sy /injf] | ]; last by exists x.
by rewrite mem_head mem_behead // => ->.
by apply: IHs => y z sy sz; apply: injf => //; apply: predU1r.
Qed.
Lemma map_subseq s1 s2 : subseq s1 s2 -> subseq (map f s1) (map f s2).
Proof.
case/subseqP=> m sz_m ->; apply/subseqP.
by exists m; rewrite ?size_map ?map_mask.
Qed.
Lemma nth_index_map s x0 x :
{in s &, injective f} -> x \in s -> nth x0 s (index (f x) (map f s)) = x.
Proof.
elim: s => //= y s IHs inj_f s_x; rewrite (inj_in_eq inj_f) ?mem_head //.
move: s_x; rewrite inE; have [-> // | _] := eqVneq; apply: IHs.
by apply: sub_in2 inj_f => z; apply: predU1r.
Qed.
Lemma perm_map s t : perm_eq s t -> perm_eq (map f s) (map f t).
Proof. by move/permP=> Est; apply/permP=> a; rewrite !count_map Est. Qed.
Lemma sub_map s1 s2 : {subset s1 <= s2} -> {subset map f s1 <= map f s2}.
Proof. by move=> sub_s ? /mapP[x x_s ->]; rewrite map_f ?sub_s. Qed.
Lemma eq_mem_map s1 s2 : s1 =i s2 -> map f s1 =i map f s2.
Proof. by move=> Es x; apply/idP/idP; apply: sub_map => ?; rewrite Es. Qed.
Hypothesis Hf : injective f.
Lemma mem_map s x : (f x \in map f s) = (x \in s).
Proof. by apply/mapP/idP=> [[y Hy /Hf->] //|]; exists x. Qed.
Lemma index_map s x : index (f x) (map f s) = index x s.
Proof. by rewrite /index; elim: s => //= y s IHs; rewrite (inj_eq Hf) IHs. Qed.
Lemma map_inj_uniq s : uniq (map f s) = uniq s.
Proof. by apply: map_inj_in_uniq; apply: in2W. Qed.
Lemma undup_map_inj s : undup (map f s) = map f (undup s).
Proof. by elim: s => //= s0 s ->; rewrite mem_map //; case: (_ \in _). Qed.
Lemma perm_map_inj s t : perm_eq (map f s) (map f t) -> perm_eq s t.
Proof.
move/permP=> Est; apply/allP=> x _ /=.
have Dx: pred1 x =1 preim f (pred1 (f x)) by move=> y /=; rewrite inj_eq.
by rewrite !(eq_count Dx) -!count_map Est.
Qed.
End EqMap.
Arguments mapP {T1 T2 f s y}.
Arguments subset_mapP {T1 T2}.
Lemma map_of_seq (T1 : eqType) T2 (s : seq T1) (fs : seq T2) (y0 : T2) :
{f | uniq s -> size fs = size s -> map f s = fs}.
Proof.
exists (fun x => nth y0 fs (index x s)) => uAs eq_sz.
apply/esym/(@eq_from_nth _ y0); rewrite ?size_map eq_sz // => i ltis.
by have x0 : T1 by [case: (s) ltis]; rewrite (nth_map x0) // index_uniq.
Qed.
Section MapComp.
Variable S T U : Type.
Lemma map_id (s : seq T) : map id s = s.
Proof. by elim: s => //= x s ->. Qed.
Lemma eq_map (f g : S -> T) : f =1 g -> map f =1 map g.
Proof. by move=> Ef; elim=> //= x s ->; rewrite Ef. Qed.
Lemma map_comp (f : T -> U) (g : S -> T) s : map (f \o g) s = map f (map g s).
Proof. by elim: s => //= x s ->. Qed.
Lemma mapK (f : S -> T) (g : T -> S) : cancel f g -> cancel (map f) (map g).
Proof. by move=> fK; elim=> //= x s ->; rewrite fK. Qed.
Lemma mapK_in (A : {pred S}) (f : S -> T) (g : T -> S) :
{in A, cancel f g} -> {in [pred s | all [in A] s], cancel (map f) (map g)}.
Proof. by move=> fK; elim=> //= x s IHs /andP[/fK-> /IHs->]. Qed.
End MapComp.
Lemma eq_in_map (S : eqType) T (f g : S -> T) (s : seq S) :
{in s, f =1 g} <-> map f s = map g s.
Proof.
elim: s => //= x s IHs; split=> [/forall_cons[-> ?]|]; first by rewrite IHs.1.
by move=> -[? ?]; apply/forall_cons; split=> [//|]; apply: IHs.2.
Qed.
Lemma map_id_in (T : eqType) f (s : seq T) : {in s, f =1 id} -> map f s = s.
Proof. by move/eq_in_map->; apply: map_id. Qed.
(* Map a partial function *)
Section Pmap.
Variables (aT rT : Type) (f : aT -> option rT) (g : rT -> aT).
Fixpoint pmap s :=
if s is x :: s' then let r := pmap s' in oapp (cons^~ r) r (f x) else [::].
Lemma map_pK : pcancel g f -> cancel (map g) pmap.
Proof. by move=> gK; elim=> //= x s ->; rewrite gK. Qed.
Lemma size_pmap s : size (pmap s) = count [eta f] s.
Proof. by elim: s => //= x s <-; case: (f _). Qed.
Lemma pmapS_filter s : map some (pmap s) = map f (filter [eta f] s).
Proof. by elim: s => //= x s; case fx: (f x) => //= [u] <-; congr (_ :: _). Qed.
Hypothesis fK : ocancel f g.
Lemma pmap_filter s : map g (pmap s) = filter [eta f] s.
Proof. by elim: s => //= x s <-; rewrite -{3}(fK x); case: (f _). Qed.
Lemma pmap_cat s t : pmap (s ++ t) = pmap s ++ pmap t.
Proof. by elim: s => //= x s ->; case/f: x. Qed.
Lemma all_pmap (p : pred rT) s :
all p (pmap s) = all [pred i | oapp p true (f i)] s.
Proof. by elim: s => //= x s <-; case: f. Qed.
End Pmap.
Lemma eq_in_pmap (aT : eqType) rT (f1 f2 : aT -> option rT) s :
{in s, f1 =1 f2} -> pmap f1 s = pmap f2 s.
Proof. by elim: s => //= a s IHs /forall_cons [-> /IHs ->]. Qed.
Lemma eq_pmap aT rT (f1 f2 : aT -> option rT) :
f1 =1 f2 -> pmap f1 =1 pmap f2.
Proof. by move=> Ef; elim => //= a s ->; rewrite Ef. Qed.
Section EqPmap.
Variables (aT rT : eqType) (f : aT -> option rT) (g : rT -> aT).
Lemma mem_pmap s u : (u \in pmap f s) = (Some u \in map f s).
Proof. by elim: s => //= x s IHs; rewrite in_cons -IHs; case: (f x). Qed.
Hypothesis fK : ocancel f g.
Lemma can2_mem_pmap : pcancel g f -> forall s u, (u \in pmap f s) = (g u \in s).
Proof.
by move=> gK s u; rewrite -(mem_map (pcan_inj gK)) pmap_filter // mem_filter gK.
Qed.
Lemma pmap_uniq s : uniq s -> uniq (pmap f s).
Proof. move/(filter_uniq f); rewrite -(pmap_filter fK); exact: map_uniq. Qed.
Lemma perm_pmap s t : perm_eq s t -> perm_eq (pmap f s) (pmap f t).
Proof.
move=> eq_st; apply/(perm_map_inj Some_inj); rewrite !pmapS_filter.
exact/perm_map/perm_filter.
Qed.
End EqPmap.
Section PmapSub.
Variables (T : Type) (p : pred T) (sT : subType p).
Lemma size_pmap_sub s : size (pmap (insub : T -> option sT) s) = count p s.
Proof. by rewrite size_pmap (eq_count (isSome_insub _)). Qed.
End PmapSub.
Section EqPmapSub.
Variables (T : eqType) (p : pred T) (sT : subEqType p).
Let insT : T -> option sT := insub.
Lemma mem_pmap_sub s u : (u \in pmap insT s) = (val u \in s).
Proof. exact/(can2_mem_pmap (insubK _))/valK. Qed.
Lemma pmap_sub_uniq s : uniq s -> uniq (pmap insT s).
Proof. exact: (pmap_uniq (insubK _)). Qed.
End EqPmapSub.
(* Index sequence *)
Fixpoint iota m n := if n is n'.+1 then m :: iota m.+1 n' else [::].
Lemma size_iota m n : size (iota m n) = n.
Proof. by elim: n m => //= n IHn m; rewrite IHn. Qed.
Lemma iotaD m n1 n2 : iota m (n1 + n2) = iota m n1 ++ iota (m + n1) n2.
Proof. by elim: n1 m => [|n1 IHn1] m; rewrite ?addn0 // -addSnnS /= -IHn1. Qed.
Lemma iotaDl m1 m2 n : iota (m1 + m2) n = map (addn m1) (iota m2 n).
Proof. by elim: n m2 => //= n IHn m2; rewrite -addnS IHn. Qed.
Lemma nth_iota p m n i : i < n -> nth p (iota m n) i = m + i.
Proof.
by move/subnKC <-; rewrite addSnnS iotaD nth_cat size_iota ltnn subnn.
Qed.
Lemma mem_iota m n i : (i \in iota m n) = (m <= i < m + n).
Proof.
elim: n m => [|n IHn] /= m; first by rewrite addn0 ltnNge andbN.
by rewrite in_cons IHn addnS ltnS; case: ltngtP => // ->; rewrite leq_addr.
Qed.
Lemma iota_uniq m n : uniq (iota m n).
Proof. by elim: n m => //= n IHn m; rewrite mem_iota ltnn /=. Qed.
Lemma take_iota k m n : take k (iota m n) = iota m (minn k n).
Proof.
have [lt_k_n|le_n_k] := ltnP.
by elim: k n lt_k_n m => [|k IHk] [|n] //= H m; rewrite IHk.
by apply: take_oversize; rewrite size_iota.
Qed.
Lemma drop_iota k m n : drop k (iota m n) = iota (m + k) (n - k).
Proof.
by elim: k m n => [|k IHk] m [|n] //=; rewrite ?addn0 // IHk addnS subSS.
Qed.
Lemma filter_iota_ltn m n j : j <= n ->
[seq i <- iota m n | i < m + j] = iota m j.
Proof.
elim: n m j => [m j|n IHn m [|j] jlen]; first by rewrite leqn0 => /eqP ->.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i.
by rewrite addn0 ltnNge mem_iota => /andP[->].
by rewrite /= addnS leq_addr -addSn IHn.
Qed.
Lemma filter_iota_leq n m j : j < n ->
[seq i <- iota m n | i <= m + j] = iota m j.+1.
Proof.
elim: n m j => [//|n IHn] m [|j] jlen /=; rewrite leq_addr.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => i.
by rewrite addn0 leqNgt mem_iota => /andP[->].
by rewrite addnS -addSn IHn -1?ltnS.
Qed.
(* Making a sequence of a specific length, using indexes to compute items. *)
Section MakeSeq.
Variables (T : Type) (x0 : T).
Definition mkseq f n : seq T := map f (iota 0 n).
Lemma size_mkseq f n : size (mkseq f n) = n.
Proof. by rewrite size_map size_iota. Qed.
Lemma mkseqS f n :
mkseq f n.+1 = rcons (mkseq f n) (f n).
Proof. by rewrite /mkseq -addn1 iotaD add0n map_cat cats1. Qed.
Lemma eq_mkseq f g : f =1 g -> mkseq f =1 mkseq g.
Proof. by move=> Efg n; apply: eq_map Efg _. Qed.
Lemma nth_mkseq f n i : i < n -> nth x0 (mkseq f n) i = f i.
Proof. by move=> Hi; rewrite (nth_map 0) ?nth_iota ?size_iota. Qed.
Lemma mkseq_nth s : mkseq (nth x0 s) (size s) = s.
Proof.
by apply: (@eq_from_nth _ x0); rewrite size_mkseq // => i Hi; rewrite nth_mkseq.
Qed.
Variant mkseq_spec s : seq T -> Type :=
| MapIota n f : s = mkseq f n -> mkseq_spec s (mkseq f n).
Lemma mkseqP s : mkseq_spec s s.
Proof. by rewrite -[s]mkseq_nth; constructor. Qed.
Lemma map_nth_iota0 s i :
i <= size s -> [seq nth x0 s j | j <- iota 0 i] = take i s.
Proof.
by move=> ile; rewrite -[s in RHS]mkseq_nth -map_take take_iota (minn_idPl _).
Qed.
Lemma map_nth_iota s i j : j <= size s - i ->
[seq nth x0 s k | k <- iota i j] = take j (drop i s).
Proof.
elim: i => [|i IH] in s j *; first by rewrite subn0 drop0 => /map_nth_iota0->.
case: s => [|x s /IH<-]; first by rewrite leqn0 => /eqP->.
by rewrite -add1n iotaDl -map_comp.
Qed.
End MakeSeq.
Section MakeEqSeq.
Variable T : eqType.
Lemma mkseq_uniqP (f : nat -> T) n :
reflect {in gtn n &, injective f} (uniq (mkseq f n)).
Proof.
apply: (equivP (uniqP (f 0))); rewrite size_mkseq.
by split=> injf i j lti ltj; have:= injf i j lti ltj; rewrite !nth_mkseq.
Qed.
Lemma mkseq_uniq (f : nat -> T) n : injective f -> uniq (mkseq f n).
Proof. by move/map_inj_uniq->; apply: iota_uniq. Qed.
Lemma perm_iotaP {s t : seq T} x0 (It := iota 0 (size t)) :
reflect (exists2 Is, perm_eq Is It & s = map (nth x0 t) Is) (perm_eq s t).
Proof.
apply: (iffP idP) => [Est | [Is eqIst ->]]; last first.
by rewrite -{2}[t](mkseq_nth x0) perm_map.
elim: t => [|x t IHt] in s It Est *.
by rewrite (perm_small_eq _ Est) //; exists [::].
have /rot_to[k s1 Ds]: x \in s by rewrite (perm_mem Est) mem_head.
have [|Is1 eqIst1 Ds1] := IHt s1; first by rewrite -(perm_cons x) -Ds perm_rot.
exists (rotr k (0 :: map succn Is1)).
by rewrite perm_rot /It /= perm_cons (iotaDl 1) perm_map.
by rewrite map_rotr /= -map_comp -(@eq_map _ _ (nth x0 t)) // -Ds1 -Ds rotK.
Qed.
End MakeEqSeq.
Arguments perm_iotaP {T s t}.
Section FoldRight.
Variables (T : Type) (R : Type) (f : T -> R -> R) (z0 : R).
Fixpoint foldr s := if s is x :: s' then f x (foldr s') else z0.
End FoldRight.
Section FoldRightComp.
Variables (T1 T2 : Type) (h : T1 -> T2).
Variables (R : Type) (f : T2 -> R -> R) (z0 : R).
Lemma foldr_cat s1 s2 : foldr f z0 (s1 ++ s2) = foldr f (foldr f z0 s2) s1.
Proof. by elim: s1 => //= x s1 ->. Qed.
Lemma foldr_rcons s x : foldr f z0 (rcons s x) = foldr f (f x z0) s.
Proof. by rewrite -cats1 foldr_cat. Qed.
Lemma foldr_map s : foldr f z0 (map h s) = foldr (fun x z => f (h x) z) z0 s.
Proof. by elim: s => //= x s ->. Qed.
End FoldRightComp.
(* Quick characterization of the null sequence. *)
Definition sumn := foldr addn 0.
Lemma sumn_ncons x n s : sumn (ncons n x s) = x * n + sumn s.
Proof. by rewrite mulnC; elim: n => //= n ->; rewrite addnA. Qed.
Lemma sumn_nseq x n : sumn (nseq n x) = x * n.
Proof. by rewrite sumn_ncons addn0. Qed.
Lemma sumn_cat s1 s2 : sumn (s1 ++ s2) = sumn s1 + sumn s2.
Proof. by elim: s1 => //= x s1 ->; rewrite addnA. Qed.
Lemma sumn_count T (a : pred T) s : sumn [seq a i : nat | i <- s] = count a s.
Proof. by elim: s => //= s0 s /= ->. Qed.
Lemma sumn_rcons s n : sumn (rcons s n) = sumn s + n.
Proof. by rewrite -cats1 sumn_cat /= addn0. Qed.
Lemma perm_sumn s1 s2 : perm_eq s1 s2 -> sumn s1 = sumn s2.
Proof.
by apply/catCA_perm_subst: s1 s2 => s1 s2 s3; rewrite !sumn_cat addnCA.
Qed.
Lemma sumn_rot s n : sumn (rot n s) = sumn s.
Proof. by apply/perm_sumn; rewrite perm_rot. Qed.
Lemma sumn_rev s : sumn (rev s) = sumn s.
Proof. by apply/perm_sumn; rewrite perm_rev. Qed.
Lemma natnseq0P s : reflect (s = nseq (size s) 0) (sumn s == 0).
Proof.
apply: (iffP idP) => [|->]; last by rewrite sumn_nseq.
by elim: s => //= x s IHs; rewrite addn_eq0 => /andP[/eqP-> /IHs <-].
Qed.
Lemma sumn_set_nth s x0 n x :
sumn (set_nth x0 s n x) =
sumn s + x - (nth x0 s n) * (n < size s) + x0 * (n - size s).
Proof.
rewrite set_nthE; case: ltnP => [nlts|nges]; last first.
by rewrite sumn_cat sumn_ncons /= addn0 muln0 subn0 addnAC addnA.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
rewrite -[in sumn s](cat_take_drop n s) [drop n s](drop_nth x0)//.
by rewrite !sumn_cat /= muln1 muln0 addn0 addnAC !addnA [in RHS]addnAC addnK.
Qed.
Lemma sumn_set_nth_ltn s x0 n x : n < size s ->
sumn (set_nth x0 s n x) = sumn s + x - nth x0 s n.
Proof.
move=> nlts; rewrite sumn_set_nth nlts muln1.
have -> : n - size s = 0 by apply/eqP; rewrite subn_eq0 ltnW.
by rewrite muln0 addn0.
Qed.
Lemma sumn_set_nth0 s n x : sumn (set_nth 0 s n x) = sumn s + x - nth 0 s n.
Proof.
rewrite sumn_set_nth mul0n addn0.
by case: ltnP => [_|nges]; rewrite ?muln1// nth_default.
Qed.
Section FoldLeft.
Variables (T R : Type) (f : R -> T -> R).
Fixpoint foldl z s := if s is x :: s' then foldl (f z x) s' else z.
Lemma foldl_rev z s : foldl z (rev s) = foldr (fun x z => f z x) z s.
Proof.
by elim/last_ind: s z => // s x IHs z; rewrite rev_rcons -cats1 foldr_cat -IHs.
Qed.
Lemma foldl_cat z s1 s2 : foldl z (s1 ++ s2) = foldl (foldl z s1) s2.
Proof.
by rewrite -(revK (s1 ++ s2)) foldl_rev rev_cat foldr_cat -!foldl_rev !revK.
Qed.
Lemma foldl_rcons z s x : foldl z (rcons s x) = f (foldl z s) x.
Proof. by rewrite -cats1 foldl_cat. Qed.
End FoldLeft.
Section Folds.
Variables (T : Type) (f : T -> T -> T).
Hypotheses (fA : associative f) (fC : commutative f).
Lemma foldl_foldr x0 l : foldl f x0 l = foldr f x0 l.
Proof.
elim: l x0 => [//|x1 l IHl] x0 /=; rewrite {}IHl.
by elim: l x0 x1 => [//|x2 l IHl] x0 x1 /=; rewrite IHl !fA [f x2 x1]fC.
Qed.
End Folds.
Section Scan.
Variables (T1 : Type) (x1 : T1) (T2 : Type) (x2 : T2).
Variables (f : T1 -> T1 -> T2) (g : T1 -> T2 -> T1).
Fixpoint pairmap x s := if s is y :: s' then f x y :: pairmap y s' else [::].
Lemma size_pairmap x s : size (pairmap x s) = size s.
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma pairmap_cat x s1 s2 :
pairmap x (s1 ++ s2) = pairmap x s1 ++ pairmap (last x s1) s2.
Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed.
Lemma nth_pairmap s n : n < size s ->
forall x, nth x2 (pairmap x s) n = f (nth x1 (x :: s) n) (nth x1 s n).
Proof. by elim: s n => [|y s IHs] [|n] //= Hn x; apply: IHs. Qed.
Fixpoint scanl x s :=
if s is y :: s' then let x' := g x y in x' :: scanl x' s' else [::].
Lemma size_scanl x s : size (scanl x s) = size s.
Proof. by elim: s x => //= y s IHs x; rewrite IHs. Qed.
Lemma scanl_cat x s1 s2 :
scanl x (s1 ++ s2) = scanl x s1 ++ scanl (foldl g x s1) s2.
Proof. by elim: s1 x => //= y s1 IHs1 x; rewrite IHs1. Qed.
Lemma scanl_rcons x s1 y :
scanl x (rcons s1 y) = rcons (scanl x s1) (foldl g x (rcons s1 y)).
Proof. by rewrite -!cats1 scanl_cat foldl_cat. Qed.
Lemma nth_cons_scanl s n : n <= size s ->
forall x, nth x1 (x :: scanl x s) n = foldl g x (take n s).
Proof. by elim: s n => [|y s IHs] [|n] Hn x //=; rewrite IHs. Qed.
Lemma nth_scanl s n : n < size s ->
forall x, nth x1 (scanl x s) n = foldl g x (take n.+1 s).
Proof. by move=> n_lt x; rewrite -nth_cons_scanl. Qed.
Lemma scanlK :
(forall x, cancel (g x) (f x)) -> forall x, cancel (scanl x) (pairmap x).
Proof. by move=> Hfg x s; elim: s x => //= y s IHs x; rewrite Hfg IHs. Qed.
Lemma pairmapK :
(forall x, cancel (f x) (g x)) -> forall x, cancel (pairmap x) (scanl x).
Proof. by move=> Hgf x s; elim: s x => //= y s IHs x; rewrite Hgf IHs. Qed.
End Scan.
Prenex Implicits mask map pmap foldr foldl scanl pairmap.
Section Zip.
Variables (S T : Type) (r : S -> T -> bool).
Fixpoint zip (s : seq S) (t : seq T) {struct t} :=
match s, t with
| x :: s', y :: t' => (x, y) :: zip s' t'
| _, _ => [::]
end.
Definition unzip1 := map (@fst S T).
Definition unzip2 := map (@snd S T).
Fixpoint all2 s t :=
match s, t with
| [::], [::] => true
| x :: s, y :: t => r x y && all2 s t
| _, _ => false
end.
Lemma zip_unzip s : zip (unzip1 s) (unzip2 s) = s.
Proof. by elim: s => [|[x y] s /= ->]. Qed.
Lemma unzip1_zip s t : size s <= size t -> unzip1 (zip s t) = s.
Proof. by elim: s t => [|x s IHs] [|y t] //= le_s_t; rewrite IHs. Qed.
Lemma unzip2_zip s t : size t <= size s -> unzip2 (zip s t) = t.
Proof. by elim: s t => [|x s IHs] [|y t] //= le_t_s; rewrite IHs. Qed.
Lemma size1_zip s t : size s <= size t -> size (zip s t) = size s.
Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed.
Lemma size2_zip s t : size t <= size s -> size (zip s t) = size t.
Proof. by elim: s t => [|x s IHs] [|y t] //= Hs; rewrite IHs. Qed.
Lemma size_zip s t : size (zip s t) = minn (size s) (size t).
Proof. by elim: s t => [|x s IHs] [|t2 t] //=; rewrite IHs minnSS. Qed.
Lemma zip_cat s1 s2 t1 t2 :
size s1 = size t1 -> zip (s1 ++ s2) (t1 ++ t2) = zip s1 t1 ++ zip s2 t2.
Proof. by move: s1 t1; apply: seq_ind2 => //= x y s1 t1 _ ->. Qed.
Lemma nth_zip x y s t i :
size s = size t -> nth (x, y) (zip s t) i = (nth x s i, nth y t i).
Proof. by elim: i s t => [|i IHi] [|y1 s1] [|y2 t] //= [/IHi->]. Qed.
Lemma nth_zip_cond p s t i :
nth p (zip s t) i
= (if i < size (zip s t) then (nth p.1 s i, nth p.2 t i) else p).
Proof.
rewrite size_zip ltnNge geq_min.
by elim: s t i => [|x s IHs] [|y t] [|i] //=; rewrite ?orbT -?IHs.
Qed.
Lemma zip_rcons s t x y :
size s = size t -> zip (rcons s x) (rcons t y) = rcons (zip s t) (x, y).
Proof. by move=> eq_sz; rewrite -!cats1 zip_cat //= eq_sz. Qed.
Lemma rev_zip s t : size s = size t -> rev (zip s t) = zip (rev s) (rev t).
Proof.
move: s t; apply: seq_ind2 => //= x y s t eq_sz IHs.
by rewrite !rev_cons IHs zip_rcons ?size_rev.
Qed.
Lemma all2E s t :
all2 s t = (size s == size t) && all [pred xy | r xy.1 xy.2] (zip s t).
Proof. by elim: s t => [|x s IHs] [|y t] //=; rewrite IHs andbCA. Qed.
Lemma zip_map I f g (s : seq I) :
zip (map f s) (map g s) = [seq (f i, g i) | i <- s].
Proof. by elim: s => //= i s ->. Qed.
Lemma unzip1_map_nth_zip x y s t l :
size s = size t ->
unzip1 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth x s i | i <- l].
Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed.
Lemma unzip2_map_nth_zip x y s t l :
size s = size t ->
unzip2 [seq nth (x, y) (zip s t) i | i <- l] = [seq nth y t i | i <- l].
Proof. by move=> st; elim: l => [//=|n l IH /=]; rewrite nth_zip ?IH ?st. Qed.
End Zip.
Lemma zip_uniql (S T : eqType) (s : seq S) (t : seq T) :
uniq s -> uniq (zip s t).
Proof.
case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]].
case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[n _].
by apply/(uniqPn s0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minl.
Qed.
Lemma zip_uniqr (S T : eqType) (s : seq S) (t : seq T) :
uniq t -> uniq (zip s t).
Proof.
case: s t => [|s0 s] [|t0 t] //; apply: contraTT => /(uniqPn (s0, t0)) [i [j]].
case=> o z; rewrite !nth_zip_cond !ifT ?js ?(ltn_trans o)// => -[_ n].
by apply/(uniqPn t0); exists i, j; rewrite o n (leq_trans z) ?size_zip?geq_minr.
Qed.
Lemma perm_zip_sym (S T : eqType) (s1 s2 : seq S) (t1 t2 : seq T) :
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq (zip t1 s1) (zip t2 s2).
Proof.
have swap t s : zip t s = map (fun u => (u.2, u.1)) (zip s t).
by elim: s t => [|x s +] [|y t]//= => ->.
by rewrite [zip t1 s1]swap [zip t2 s2]swap; apply: perm_map.
Qed.
Lemma perm_zip1 {S T : eqType} (t1 t2 : seq T) (s1 s2 : seq S):
size s1 = size t1 -> size s2 = size t2 ->
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq s1 s2.
Proof.
wlog [x y] : s1 s2 t1 t2 / (S * T)%type => [hwlog|].
case: s2 t2 => [|x s2] [|y t2] //; last exact: hwlog.
by case: s1 t1 => [|u s1] [|v t1]//= _ _ /perm_nilP.
move=> eq1 eq2 /(perm_iotaP (x, y))[ns nsP /(congr1 (@unzip1 _ _))].
rewrite unzip1_zip ?unzip1_map_nth_zip -?eq1// => ->.
by apply/(perm_iotaP x); exists ns; rewrite // size_zip -eq2 minnn in nsP.
Qed.
Lemma perm_zip2 {S T : eqType} (s1 s2 : seq S) (t1 t2 : seq T) :
size s1 = size t1 -> size s2 = size t2 ->
perm_eq (zip s1 t1) (zip s2 t2) -> perm_eq t1 t2.
Proof. by move=> ? ? ?; rewrite (@perm_zip1 _ _ s1 s2) 1?perm_zip_sym. Qed.
Prenex Implicits zip unzip1 unzip2 all2.
Lemma eqseq_all (T : eqType) (s t : seq T) : (s == t) = all2 eq_op s t.
Proof. by elim: s t => [|x s +] [|y t]//= => <-. Qed.
Lemma eq_map_all I (T : eqType) (f g : I -> T) (s : seq I) :
(map f s == map g s) = all [pred xy | xy.1 == xy.2] [seq (f i, g i) | i <- s].
Proof. by rewrite eqseq_all all2E !size_map eqxx zip_map. Qed.
Section Flatten.
Variable T : Type.
Implicit Types (s : seq T) (ss : seq (seq T)).
Definition flatten := foldr cat (Nil T).
Definition shape := map (@size T).
Fixpoint reshape sh s :=
if sh is n :: sh' then take n s :: reshape sh' (drop n s) else [::].
Definition flatten_index sh r c := sumn (take r sh) + c.
Definition reshape_index sh i := find (pred1 0) (scanl subn i.+1 sh).
Definition reshape_offset sh i := i - sumn (take (reshape_index sh i) sh).
Lemma size_flatten ss : size (flatten ss) = sumn (shape ss).
Proof. by elim: ss => //= s ss <-; rewrite size_cat. Qed.
Lemma flatten_cat ss1 ss2 : flatten (ss1 ++ ss2) = flatten ss1 ++ flatten ss2.
Proof. by elim: ss1 => //= s ss1 ->; rewrite catA. Qed.
Lemma size_reshape sh s : size (reshape sh s) = size sh.
Proof. by elim: sh s => //= s0 sh IHsh s; rewrite IHsh. Qed.
Lemma nth_reshape (sh : seq nat) l n :
nth [::] (reshape sh l) n = take (nth 0 sh n) (drop (sumn (take n sh)) l).
Proof.
elim: n sh l => [| n IHn] [| sh0 sh] l; rewrite ?take0 ?drop0 //=.
by rewrite addnC -drop_drop; apply: IHn.
Qed.
Lemma flattenK ss : reshape (shape ss) (flatten ss) = ss.
Proof.
by elim: ss => //= s ss IHss; rewrite take_size_cat ?drop_size_cat ?IHss.
Qed.
Lemma reshapeKr sh s : size s <= sumn sh -> flatten (reshape sh s) = s.
Proof.
elim: sh s => [[]|n sh IHsh] //= s sz_s; rewrite IHsh ?cat_take_drop //.
by rewrite size_drop leq_subLR.
Qed.
Lemma reshapeKl sh s : size s >= sumn sh -> shape (reshape sh s) = sh.
Proof.
elim: sh s => [[]|n sh IHsh] //= s sz_s.
rewrite size_takel; last exact: leq_trans (leq_addr _ _) sz_s.
by rewrite IHsh // -(leq_add2l n) size_drop -maxnE leq_max sz_s orbT.
Qed.
Lemma flatten_rcons ss s : flatten (rcons ss s) = flatten ss ++ s.
Proof. by rewrite -cats1 flatten_cat /= cats0. Qed.
Lemma flatten_seq1 s : flatten [seq [:: x] | x <- s] = s.
Proof. by elim: s => //= s0 s ->. Qed.
Lemma count_flatten ss P :
count P (flatten ss) = sumn [seq count P x | x <- ss].
Proof. by elim: ss => //= s ss IHss; rewrite count_cat IHss. Qed.
Lemma filter_flatten ss (P : pred T) :
filter P (flatten ss) = flatten [seq filter P i | i <- ss].
Proof. by elim: ss => // s ss /= <-; apply: filter_cat. Qed.
Lemma rev_flatten ss :
rev (flatten ss) = flatten (rev (map rev ss)).
Proof.
by elim: ss => //= s ss IHss; rewrite rev_cons flatten_rcons -IHss rev_cat.
Qed.
Lemma nth_shape ss i : nth 0 (shape ss) i = size (nth [::] ss i).
Proof.
rewrite /shape; case: (ltnP i (size ss)) => Hi; first exact: nth_map.
by rewrite !nth_default // size_map.
Qed.
Lemma shape_rev ss : shape (rev ss) = rev (shape ss).
Proof. exact: map_rev. Qed.
Lemma eq_from_flatten_shape ss1 ss2 :
flatten ss1 = flatten ss2 -> shape ss1 = shape ss2 -> ss1 = ss2.
Proof. by move=> Eflat Esh; rewrite -[LHS]flattenK Eflat Esh flattenK. Qed.
Lemma rev_reshape sh s :
size s = sumn sh -> rev (reshape sh s) = map rev (reshape (rev sh) (rev s)).
Proof.
move=> sz_s; apply/(canLR revK)/eq_from_flatten_shape.
rewrite reshapeKr ?sz_s // -rev_flatten reshapeKr ?revK //.
by rewrite size_rev sumn_rev sz_s.
transitivity (rev (shape (reshape (rev sh) (rev s)))).
by rewrite !reshapeKl ?revK ?size_rev ?sz_s ?sumn_rev.
rewrite shape_rev; congr (rev _); rewrite -[RHS]map_comp.
by under eq_map do rewrite /= size_rev.
Qed.
Lemma reshape_rcons s sh n (m := sumn sh) :
m + n = size s ->
reshape (rcons sh n) s = rcons (reshape sh (take m s)) (drop m s).
Proof.
move=> Dmn; apply/(can_inj revK); rewrite rev_reshape ?rev_rcons ?sumn_rcons //.
rewrite /= take_rev drop_rev -Dmn addnK revK -rev_reshape //.
by rewrite size_takel // -Dmn leq_addr.
Qed.
Lemma flatten_indexP sh r c :
c < nth 0 sh r -> flatten_index sh r c < sumn sh.
Proof.
move=> lt_c_sh; rewrite -[sh in sumn sh](cat_take_drop r) sumn_cat ltn_add2l.
suffices lt_r_sh: r < size sh by rewrite (drop_nth 0 lt_r_sh) ltn_addr.
by case: ltnP => // le_sh_r; rewrite nth_default in lt_c_sh.
Qed.
Lemma reshape_indexP sh i : i < sumn sh -> reshape_index sh i < size sh.
Proof.
rewrite /reshape_index; elim: sh => //= n sh IHsh in i *; rewrite subn_eq0.
by have [// | le_n_i] := ltnP i n; rewrite -leq_subLR subSn // => /IHsh.
Qed.
Lemma reshape_offsetP sh i :
i < sumn sh -> reshape_offset sh i < nth 0 sh (reshape_index sh i).
Proof.
rewrite /reshape_offset /reshape_index; elim: sh => //= n sh IHsh in i *.
rewrite subn_eq0; have [| le_n_i] := ltnP i n; first by rewrite subn0.
by rewrite -leq_subLR /= subnDA subSn // => /IHsh.
Qed.
Lemma reshape_indexK sh i :
flatten_index sh (reshape_index sh i) (reshape_offset sh i) = i.
Proof.
rewrite /reshape_offset /reshape_index /flatten_index -subSKn.
elim: sh => //= n sh IHsh in i *; rewrite subn_eq0; have [//|le_n_i] := ltnP.
by rewrite /= subnDA subSn // -addnA IHsh subnKC.
Qed.
Lemma flatten_indexKl sh r c :
c < nth 0 sh r -> reshape_index sh (flatten_index sh r c) = r.
Proof.
rewrite /reshape_index /flatten_index.
elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT.
by rewrite -addnA -addnS addKn IHsh.
Qed.
Lemma flatten_indexKr sh r c :
c < nth 0 sh r -> reshape_offset sh (flatten_index sh r c) = c.
Proof.
rewrite /reshape_offset /reshape_index /flatten_index.
elim: sh r => [|n sh IHsh] [|r] //= lt_c_sh; first by rewrite ifT ?subn0.
by rewrite -addnA -addnS addKn /= subnDl IHsh.
Qed.
Lemma nth_flatten x0 ss i (r := reshape_index (shape ss) i) :
nth x0 (flatten ss) i = nth x0 (nth [::] ss r) (reshape_offset (shape ss) i).
Proof.
rewrite /reshape_offset -subSKn {}/r /reshape_index.
elim: ss => //= s ss IHss in i *; rewrite subn_eq0 nth_cat.
by have [//|le_s_i] := ltnP; rewrite subnDA subSn /=.
Qed.
Lemma reshape_leq sh i1 i2
(r1 := reshape_index sh i1) (c1 := reshape_offset sh i1)
(r2 := reshape_index sh i2) (c2 := reshape_offset sh i2) :
(i1 <= i2) = ((r1 < r2) || ((r1 == r2) && (c1 <= c2))).
Proof.
rewrite {}/r1 {}/c1 {}/r2 {}/c2 /reshape_offset /reshape_index.
elim: sh => [|s0 s IHs] /= in i1 i2 *; rewrite ?subn0 ?subn_eq0 //.
have [[] i1s0 [] i2s0] := (ltnP i1 s0, ltnP i2 s0); first by rewrite !subn0.
- by apply: leq_trans i2s0; apply/ltnW.
- by apply/negP => /(leq_trans i1s0); rewrite leqNgt i2s0.
by rewrite !subSn // !eqSS !ltnS !subnDA -IHs leq_subLR subnKC.
Qed.
End Flatten.
Prenex Implicits flatten shape reshape.
Lemma map_flatten S T (f : T -> S) ss :
map f (flatten ss) = flatten (map (map f) ss).
Proof. by elim: ss => // s ss /= <-; apply: map_cat. Qed.
Lemma flatten_map1 (S T : Type) (f : S -> T) s :
flatten [seq [:: f x] | x <- s] = map f s.
Proof. by elim: s => //= s0 s ->. Qed.
Lemma undup_flatten_nseq n (T : eqType) (s : seq T) : 0 < n ->
undup (flatten (nseq n s)) = undup s.
Proof.
elim: n => [|[|n]/= IHn]//= _; rewrite ?cats0// undup_cat {}IHn//.
rewrite (@eq_in_filter _ _ pred0) ?filter_pred0// => x.
by rewrite mem_undup mem_cat => ->.
Qed.
Lemma sumn_flatten (ss : seq (seq nat)) :
sumn (flatten ss) = sumn (map sumn ss).
Proof. by elim: ss => // s ss /= <-; apply: sumn_cat. Qed.
Lemma map_reshape T S (f : T -> S) sh s :
map (map f) (reshape sh s) = reshape sh (map f s).
Proof. by elim: sh s => //= sh0 sh IHsh s; rewrite map_take IHsh map_drop. Qed.
Section EqFlatten.
Variables S T : eqType.
Lemma flattenP (A : seq (seq T)) x :
reflect (exists2 s, s \in A & x \in s) (x \in flatten A).
Proof.
elim: A => /= [|s A IH_A]; [by right; case | rewrite mem_cat].
by apply: equivP (iff_sym exists_cons); apply: (orPP idP IH_A).
Qed.
Arguments flattenP {A x}.
Lemma flatten_mapP (A : S -> seq T) s y :
reflect (exists2 x, x \in s & y \in A x) (y \in flatten (map A s)).
Proof.
apply: (iffP flattenP) => [[_ /mapP[x sx ->]] | [x sx]] Axy; first by exists x.
by exists (A x); rewrite ?map_f.
Qed.
Lemma perm_flatten (ss1 ss2 : seq (seq T)) :
perm_eq ss1 ss2 -> perm_eq (flatten ss1) (flatten ss2).
Proof.
move=> eq_ss; apply/permP=> a; apply/catCA_perm_subst: ss1 ss2 eq_ss.
by move=> ss1 ss2 ss3; rewrite !flatten_cat !count_cat addnCA.
Qed.
End EqFlatten.
Arguments flattenP {T A x}.
Arguments flatten_mapP {S T A s y}.
Notation "[ 'seq' E | x <- s , y <- t ]" :=
(flatten [seq [seq E | y <- t] | x <- s])
(x binder, y binder,
format "[ '[hv' 'seq' E '/ ' | x <- s , '/ ' y <- t ] ']'")
: seq_scope.
Notation "[ 'seq' E : R | x <- s , y <- t ]" :=
(flatten [seq [seq E : R | y <- t] | x <- s])
(x binder, y binder, only parsing) : seq_scope.
Section PrefixSuffixInfix.
Variables T : eqType.
Implicit Type s : seq T.
Fixpoint prefix s1 s2 {struct s2} :=
if s1 isn't x :: s1' then true else
if s2 isn't y :: s2' then false else
(x == y) && prefix s1' s2'.
Lemma prefixE s1 s2 : prefix s1 s2 = (take (size s1) s2 == s1).
Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => ->; rewrite eq_sym. Qed.
Lemma prefix_refl s : prefix s s. Proof. by rewrite prefixE take_size. Qed.
Lemma prefixs0 s : prefix s [::] = (s == [::]). Proof. by case: s. Qed.
Lemma prefix0s s : prefix [::] s. Proof. by case: s. Qed.
Lemma prefix_cons s1 s2 x y :
prefix (x :: s1) (y :: s2) = (x == y) && prefix s1 s2.
Proof. by []. Qed.
Lemma prefix_catr s1 s2 s1' s3 : size s1 = size s1' ->
prefix (s1 ++ s2) (s1' ++ s3) = (s1 == s1') && prefix s2 s3.
Proof.
elim: s1 s1' => [|x s1 IHs1] [|y s1']//= [eqs1].
by rewrite IHs1// eqseq_cons andbA.
Qed.
Lemma prefix_prefix s1 s2 : prefix s1 (s1 ++ s2).
Proof. by rewrite prefixE take_cat ltnn subnn take0 cats0. Qed.
Hint Resolve prefix_prefix : core.
Lemma prefixP {s1 s2} :
reflect (exists s2' : seq T, s2 = s1 ++ s2') (prefix s1 s2).
Proof.
apply: (iffP idP) => [|[{}s2 ->]]; last exact: prefix_prefix.
by rewrite prefixE => /eqP<-; exists (drop (size s1) s2); rewrite cat_take_drop.
Qed.
Lemma prefix_trans : transitive prefix.
Proof. by move=> _ s2 _ /prefixP[s1 ->] /prefixP[s3 ->]; rewrite -catA. Qed.
Lemma prefixs1 s x : prefix s [:: x] = (s == [::]) || (s == [:: x]).
Proof. by case: s => //= y s; rewrite prefixs0 eqseq_cons. Qed.
Lemma catl_prefix s1 s2 s3 : prefix (s1 ++ s3) s2 -> prefix s1 s2.
Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed.
Lemma prefix_catl s1 s2 s3 : prefix s1 s2 -> prefix s1 (s2 ++ s3).
Proof. by move=> /prefixP [s2'] ->; rewrite -catA. Qed.
Lemma prefix_rcons s x : prefix s (rcons s x).
Proof. by rewrite -cats1 prefix_prefix. Qed.
Definition suffix s1 s2 := prefix (rev s1) (rev s2).
Lemma suffixE s1 s2 : suffix s1 s2 = (drop (size s2 - size s1) s2 == s1).
Proof. by rewrite /suffix prefixE take_rev (can_eq revK) size_rev. Qed.
Lemma suffix_refl s : suffix s s.
Proof. exact: prefix_refl. Qed.
Lemma suffixs0 s : suffix s [::] = (s == [::]).
Proof. by rewrite /suffix prefixs0 -!nilpE rev_nilp. Qed.
Lemma suffix0s s : suffix [::] s.
Proof. exact: prefix0s. Qed.
Lemma prefix_rev s1 s2 : prefix (rev s1) (rev s2) = suffix s1 s2.
Proof. by []. Qed.
Lemma prefix_revLR s1 s2 : prefix (rev s1) s2 = suffix s1 (rev s2).
Proof. by rewrite -prefix_rev revK. Qed.
Lemma suffix_rev s1 s2 : suffix (rev s1) (rev s2) = prefix s1 s2.
Proof. by rewrite -prefix_rev !revK. Qed.
Lemma suffix_revLR s1 s2 : suffix (rev s1) s2 = prefix s1 (rev s2).
Proof. by rewrite -prefix_rev revK. Qed.
Lemma suffix_suffix s1 s2 : suffix s2 (s1 ++ s2).
Proof. by rewrite /suffix rev_cat prefix_prefix. Qed.
Hint Resolve suffix_suffix : core.
Lemma suffixP {s1 s2} :
reflect (exists s2' : seq T, s2 = s2' ++ s1) (suffix s1 s2).
Proof.
apply: (iffP prefixP) => [[s2' rev_s2]|[s2' ->]]; exists (rev s2'); last first.
by rewrite rev_cat.
by rewrite -[s2]revK rev_s2 rev_cat revK.
Qed.
Lemma suffix_trans : transitive suffix.
Proof. by move=> _ s2 _ /suffixP[s1 ->] /suffixP[s3 ->]; rewrite catA. Qed.
Lemma suffix_rcons s1 s2 x y :
suffix (rcons s1 x) (rcons s2 y) = (x == y) && suffix s1 s2.
Proof. by rewrite /suffix 2!rev_rcons prefix_cons. Qed.
Lemma suffix_catl s1 s2 s3 s3' : size s3 = size s3' ->
suffix (s1 ++ s3) (s2 ++ s3') = (s3 == s3') && suffix s1 s2.
Proof.
by move=> eqs3; rewrite /suffix !rev_cat prefix_catr ?size_rev// (can_eq revK).
Qed.
Lemma suffix_catr s1 s2 s3 : suffix s1 s2 -> suffix s1 (s3 ++ s2).
Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed.
Lemma catl_suffix s s1 s2 : suffix (s ++ s1) s2 -> suffix s1 s2.
Proof. by move=> /suffixP [s2'] ->; rewrite catA suffix_suffix. Qed.
Lemma suffix_cons s x : suffix s (x :: s).
Proof. by rewrite /suffix rev_cons prefix_rcons. Qed.
Fixpoint infix s1 s2 :=
if s2 is y :: s2' then prefix s1 s2 || infix s1 s2' else s1 == [::].
Fixpoint infix_index s1 s2 :=
if prefix s1 s2 then 0
else if s2 is y :: s2' then (infix_index s1 s2').+1 else 1.
Lemma infix0s s : infix [::] s. Proof. by case: s. Qed.
Lemma infixs0 s : infix s [::] = (s == [::]). Proof. by case: s. Qed.
Lemma infix_consl s1 y s2 :
infix s1 (y :: s2) = prefix s1 (y :: s2) || infix s1 s2.
Proof. by []. Qed.
Lemma infix_indexss s : infix_index s s = 0.
Proof. by case: s => //= x s; rewrite eqxx prefix_refl. Qed.
Lemma infix_index_le s1 s2 : infix_index s1 s2 <= (size s2).+1.
Proof. by elim: s2 => [|x s2'] /=; case: ifP. Qed.
Lemma infixTindex s1 s2 : (infix_index s1 s2 <= size s2) = infix s1 s2.
Proof. by elim: s2 s1 => [|y s2 +] [|x s1]//= => <-; case: ifP. Qed.
Lemma infixPn s1 s2 :
reflect (infix_index s1 s2 = (size s2).+1) (~~ infix s1 s2).
Proof.
rewrite -infixTindex -ltnNge; apply: (iffP idP) => [s2lt|->//].
by apply/eqP; rewrite eqn_leq s2lt infix_index_le.
Qed.
Lemma infix_index0s s : infix_index [::] s = 0.
Proof. by case: s. Qed.
Lemma infix_indexs0 s : infix_index s [::] = (s != [::]).
Proof. by case: s. Qed.
Lemma infixE s1 s2 : infix s1 s2 =
(take (size s1) (drop (infix_index s1 s2) s2) == s1).
Proof.
elim: s2 s1 => [|y s2 +] [|x s1]//= => -> /=.
by case: ifP => // /andP[/eqP-> ps1s2/=]; rewrite eqseq_cons -prefixE eqxx.
Qed.
Lemma infix_refl s : infix s s.
Proof. by rewrite infixE infix_indexss// drop0 take_size. Qed.
Lemma prefixW s1 s2 : prefix s1 s2 -> infix s1 s2.
Proof. by elim: s2 s1 => [|y s2 IHs2] [|x s1]//=->. Qed.
Lemma prefix_infix s1 s2 : infix s1 (s1 ++ s2).
Proof. exact: prefixW. Qed.
Hint Resolve prefix_infix : core.
Lemma infix_infix s1 s2 s3 : infix s2 (s1 ++ s2 ++ s3).
Proof. by elim: s1 => //= x s1 ->; rewrite orbT. Qed.
Hint Resolve infix_infix : core.
Lemma suffix_infix s1 s2 : infix s2 (s1 ++ s2).
Proof. by rewrite -[X in s1 ++ X]cats0. Qed.
Hint Resolve suffix_infix : core.
Lemma infixP {s1 s2} :
reflect (exists s s' : seq T, s2 = s ++ s1 ++ s') (infix s1 s2).
Proof.
apply: (iffP idP) => [|[p [s {s2}->]]]//=; rewrite infixE => /eqP<-.
set k := infix_index _ _; exists (take k s2), (drop (size s1 + k) s2).
by rewrite -drop_drop !cat_take_drop.
Qed.
Lemma infix_rev s1 s2 : infix (rev s1) (rev s2) = infix s1 s2.
Proof.
gen have sr : s1 s2 / infix s1 s2 -> infix (rev s1) (rev s2); last first.
by apply/idP/idP => /sr; rewrite ?revK.
by move=> /infixP[s [p ->]]; rewrite !rev_cat -catA.
Qed.
Lemma suffixW s1 s2 : suffix s1 s2 -> infix s1 s2.
Proof. by rewrite -infix_rev; apply: prefixW. Qed.
Lemma infix_trans : transitive infix.
Proof.
move=> s s1 s2 /infixP[s1p [s1s def_s]] /infixP[sp [ss def_s2]].
by apply/infixP; exists (sp ++ s1p),(s1s ++ ss); rewrite def_s2 def_s -!catA.
Qed.
Lemma infix_revLR s1 s2 : infix (rev s1) s2 = infix s1 (rev s2).
Proof. by rewrite -infix_rev revK. Qed.
Lemma infix_rconsl s1 s2 y :
infix s1 (rcons s2 y) = suffix s1 (rcons s2 y) || infix s1 s2.
Proof.
rewrite -infix_rev rev_rcons infix_consl.
by rewrite -rev_rcons prefix_rev infix_rev.
Qed.
Lemma infix_cons s x : infix s (x :: s).
Proof. by rewrite -cat1s suffix_infix. Qed.
Lemma infixs1 s x : infix s [:: x] = (s == [::]) || (s == [:: x]).
Proof. by rewrite infix_consl prefixs1 orbC orbA orbb. Qed.
Lemma catl_infix s s1 s2 : infix (s ++ s1) s2 -> infix s1 s2.
Proof. apply: infix_trans; exact/suffixW/suffix_suffix. Qed.
Lemma catr_infix s s1 s2 : infix (s1 ++ s) s2 -> infix s1 s2.
Proof.
by rewrite -infix_rev rev_cat => /catl_infix; rewrite infix_rev.
Qed.
Lemma cons2_infix s1 s2 x : infix (x :: s1) (x :: s2) -> infix s1 s2.
Proof.
by rewrite /= eqxx /= -cat1s => /orP[/prefixW//|]; exact: catl_infix.
Qed.
Lemma rcons2_infix s1 s2 x : infix (rcons s1 x) (rcons s2 x) -> infix s1 s2.
Proof. by rewrite -infix_rev !rev_rcons => /cons2_infix; rewrite infix_rev. Qed.
Lemma catr2_infix s s1 s2 : infix (s ++ s1) (s ++ s2) -> infix s1 s2.
Proof. by elim: s => //= x s IHs /cons2_infix. Qed.
Lemma catl2_infix s s1 s2 : infix (s1 ++ s) (s2 ++ s) -> infix s1 s2.
Proof. by rewrite -infix_rev !rev_cat => /catr2_infix; rewrite infix_rev. Qed.
Lemma infix_catl s1 s2 s3 : infix s1 s2 -> infix s1 (s3 ++ s2).
Proof. by move=> is12; apply: infix_trans is12 (suffix_infix _ _). Qed.
Lemma infix_catr s1 s2 s3 : infix s1 s2 -> infix s1 (s2 ++ s3).
Proof.
case: s3 => [|x s /infixP [p [sf]] ->]; first by rewrite cats0.
by rewrite -catA; apply: infix_catl; rewrite -catA prefix_infix.
Qed.
Lemma prefix_infix_trans s2 s1 s3 :
prefix s1 s2 -> infix s2 s3 -> infix s1 s3.
Proof. by move=> /prefixW/infix_trans; apply. Qed.
Lemma suffix_infix_trans s2 s1 s3 :
suffix s1 s2 -> infix s2 s3 -> infix s1 s3.
Proof. by move=> /suffixW/infix_trans; apply. Qed.
Lemma infix_prefix_trans s2 s1 s3 :
infix s1 s2 -> prefix s2 s3 -> infix s1 s3.
Proof. by move=> + /prefixW; apply: infix_trans. Qed.
Lemma infix_suffix_trans s2 s1 s3 :
infix s1 s2 -> suffix s2 s3 -> infix s1 s3.
Proof. by move=> + /suffixW; apply: infix_trans. Qed.
Lemma prefix_suffix_trans s2 s1 s3 :
prefix s1 s2 -> suffix s2 s3 -> infix s1 s3.
Proof. by move=> /prefixW + /suffixW +; apply: infix_trans. Qed.
Lemma suffix_prefix_trans s2 s1 s3 :
suffix s1 s2 -> prefix s2 s3 -> infix s1 s3.
Proof. by move=> /suffixW + /prefixW +; apply: infix_trans. Qed.
Lemma infixW s1 s2 : infix s1 s2 -> subseq s1 s2.
Proof.
move=> /infixP[sp [ss ->]].
exact: subseq_trans (prefix_subseq _ _) (suffix_subseq _ _).
Qed.
Lemma mem_infix s1 s2 : infix s1 s2 -> {subset s1 <= s2}.
Proof. by move=> /infixW subH; apply: mem_subseq. Qed.
Lemma infix1s s x : infix [:: x] s = (x \in s).
Proof. by elim: s => // x' s /= ->; rewrite in_cons prefix0s andbT. Qed.
Lemma prefix1s s x : prefix [:: x] s -> x \in s.
Proof. by rewrite -infix1s => /prefixW. Qed.
Lemma suffix1s s x : suffix [:: x] s -> x \in s.
Proof. by rewrite -infix1s => /suffixW. Qed.
Lemma infix_rcons s x : infix s (rcons s x).
Proof. by rewrite -cats1 prefix_infix. Qed.
Lemma infix_uniq s1 s2 : infix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /infixW /subseq_uniq subH. Qed.
Lemma prefix_uniq s1 s2 : prefix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /prefixW /infix_uniq preH. Qed.
Lemma suffix_uniq s1 s2 : suffix s1 s2 -> uniq s2 -> uniq s1.
Proof. by move=> /suffixW /infix_uniq preH. Qed.
Lemma prefix_take s i : prefix (take i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma suffix_drop s i : suffix (drop i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma infix_take s i : infix (take i s) s.
Proof. by rewrite prefixW // prefix_take. Qed.
Lemma prefix_drop_gt0 s i : ~~ prefix (drop i s) s -> i > 0.
Proof. by case: i => //=; rewrite drop0 ltnn prefix_refl. Qed.
Lemma infix_drop s i : infix (drop i s) s.
Proof. by rewrite -{2}[s](cat_take_drop i). Qed.
Lemma consr_infix s1 s2 x : infix (x :: s1) s2 -> infix [:: x] s2.
Proof. by rewrite -cat1s => /catr_infix. Qed.
Lemma consl_infix s1 s2 x : infix (x :: s1) s2 -> infix s1 s2.
Proof. by rewrite -cat1s => /catl_infix. Qed.
Lemma prefix_index s1 s2 : prefix s1 s2 -> infix_index s1 s2 = 0.
Proof. by case: s1 s2 => [|x s1] [|y s2] //= ->. Qed.
Lemma size_infix s1 s2 : infix s1 s2 -> size s1 <= size s2.
Proof. by move=> /infixW; apply: size_subseq. Qed.
Lemma size_prefix s1 s2 : prefix s1 s2 -> size s1 <= size s2.
Proof. by move=> /prefixW; apply: size_infix. Qed.
Lemma size_suffix s1 s2 : suffix s1 s2 -> size s1 <= size s2.
Proof. by move=> /suffixW; apply: size_infix. Qed.
End PrefixSuffixInfix.
Section AllPairsDep.
Variables (S S' : Type) (T T' : S -> Type) (R : Type).
Implicit Type f : forall x, T x -> R.
Definition allpairs_dep f s t := [seq f x y | x <- s, y <- t x].
Lemma size_allpairs_dep f s t :
size [seq f x y | x <- s, y <- t x] = sumn [seq size (t x) | x <- s].
Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed.
Lemma allpairs0l f t : [seq f x y | x <- [::], y <- t x] = [::].
Proof. by []. Qed.
Lemma allpairs0r f s : [seq f x y | x <- s, y <- [::]] = [::].
Proof. by elim: s. Qed.
Lemma allpairs1l f x t :
[seq f x y | x <- [:: x], y <- t x] = [seq f x y | y <- t x].
Proof. exact: cats0. Qed.
Lemma allpairs1r f s y :
[seq f x y | x <- s, y <- [:: y x]] = [seq f x (y x) | x <- s].
Proof. exact: flatten_map1. Qed.
Lemma allpairs_cons f x s t :
[seq f x y | x <- x :: s, y <- t x] =
[seq f x y | y <- t x] ++ [seq f x y | x <- s, y <- t x].
Proof. by []. Qed.
Lemma eq_allpairs (f1 f2 : forall x, T x -> R) s t :
(forall x, f1 x =1 f2 x) ->
[seq f1 x y | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x].
Proof. by move=> eq_f; under eq_map do under eq_map do rewrite eq_f. Qed.
Lemma eq_allpairsr (f : forall x, T x -> R) s t1 t2 : (forall x, t1 x = t2 x) ->
[seq f x y | x <- s, y <- t1 x] = [seq f x y | x <- s, y <- t2 x].
Proof. by move=> eq_t; under eq_map do rewrite eq_t. Qed.
Lemma allpairs_cat f s1 s2 t :
[seq f x y | x <- s1 ++ s2, y <- t x] =
[seq f x y | x <- s1, y <- t x] ++ [seq f x y | x <- s2, y <- t x].
Proof. by rewrite map_cat flatten_cat. Qed.
Lemma allpairs_rcons f x s t :
[seq f x y | x <- rcons s x, y <- t x] =
[seq f x y | x <- s, y <- t x] ++ [seq f x y | y <- t x].
Proof. by rewrite -cats1 allpairs_cat allpairs1l. Qed.
Lemma allpairs_mapl f (g : S' -> S) s t :
[seq f x y | x <- map g s, y <- t x] = [seq f (g x) y | x <- s, y <- t (g x)].
Proof. by rewrite -map_comp. Qed.
Lemma allpairs_mapr f (g : forall x, T' x -> T x) s t :
[seq f x y | x <- s, y <- map (g x) (t x)] =
[seq f x (g x y) | x <- s, y <- t x].
Proof. by under eq_map do rewrite -map_comp. Qed.
End AllPairsDep.
Arguments allpairs_dep {S T R} f s t /.
Lemma map_allpairs S T R R' (g : R' -> R) f s t :
map g [seq f x y | x : S <- s, y : T x <- t x] =
[seq g (f x y) | x <- s, y <- t x].
Proof. by rewrite map_flatten allpairs_mapl allpairs_mapr. Qed.
Section AllPairsNonDep.
Variables (S T R : Type) (f : S -> T -> R).
Implicit Types (s : seq S) (t : seq T).
Definition allpairs s t := [seq f x y | x <- s, y <- t].
Lemma size_allpairs s t : size [seq f x y | x <- s, y <- t] = size s * size t.
Proof. by elim: s => //= x s IHs; rewrite size_cat size_map IHs. Qed.
End AllPairsNonDep.
Arguments allpairs {S T R} f s t /.
Section EqAllPairsDep.
Variables (S : eqType) (T : S -> eqType).
Implicit Types (R : eqType) (s : seq S) (t : forall x, seq (T x)).
Lemma allpairsPdep R (f : forall x, T x -> R) s t (z : R) :
reflect (exists x y, [/\ x \in s, y \in t x & z = f x y])
(z \in [seq f x y | x <- s, y <- t x]).
Proof.
apply: (iffP flatten_mapP); first by case=> x sx /mapP[y ty ->]; exists x, y.
by case=> x [y [sx ty ->]]; exists x; last apply: map_f.
Qed.
Variable R : eqType.
Implicit Type f : forall x, T x -> R.
Lemma allpairs_f_dep f s t x y :
x \in s -> y \in t x -> f x y \in [seq f x y | x <- s, y <- t x].
Proof. by move=> sx ty; apply/allpairsPdep; exists x, y. Qed.
Lemma eq_in_allpairs_dep f1 f2 s t :
{in s, forall x, {in t x, f1 x =1 f2 x}} <->
[seq f1 x y : R | x <- s, y <- t x] = [seq f2 x y | x <- s, y <- t x].
Proof.
split=> [eq_f | eq_fst x s_x].
by congr flatten; apply/eq_in_map=> x s_x; apply/eq_in_map/eq_f.
apply/eq_in_map; apply/eq_in_map: x s_x; apply/eq_from_flatten_shape => //.
by rewrite /shape -!map_comp; apply/eq_map=> x /=; rewrite !size_map.
Qed.
Lemma perm_allpairs_dep f s1 t1 s2 t2 :
perm_eq s1 s2 -> {in s1, forall x, perm_eq (t1 x) (t2 x)} ->
perm_eq [seq f x y | x <- s1, y <- t1 x] [seq f x y | x <- s2, y <- t2 x].
Proof.
elim: s1 s2 t1 t2 => [s2 t1 t2 |a s1 IH s2 t1 t2 perm_s2 perm_t1].
by rewrite perm_sym => /perm_nilP->.
have mem_a : a \in s2 by rewrite -(perm_mem perm_s2) inE eqxx.
rewrite -[s2](cat_take_drop (index a s2)).
rewrite allpairs_cat (drop_nth a) ?index_mem //= nth_index //=.
rewrite perm_sym perm_catC -catA perm_cat //; last first.
rewrite perm_catC -allpairs_cat.
rewrite -remE perm_sym IH // => [|x xI]; last first.
by apply: perm_t1; rewrite inE xI orbT.
by rewrite -(perm_cons a) (perm_trans perm_s2 (perm_to_rem _)).
have /perm_t1 : a \in a :: s1 by rewrite inE eqxx.
rewrite perm_sym; elim: (t2 a) (t1 a) => /= [s4|b s3 IH1 s4 perm_s4].
by rewrite perm_sym => /perm_nilP->.
have mem_b : b \in s4 by rewrite -(perm_mem perm_s4) inE eqxx.
rewrite -[s4](cat_take_drop (index b s4)).
rewrite map_cat /= (drop_nth b) ?index_mem //= nth_index //=.
rewrite perm_sym perm_catC /= perm_cons // perm_catC -map_cat.
rewrite -remE perm_sym IH1 // -(perm_cons b).
by apply: perm_trans perm_s4 (perm_to_rem _).
Qed.
Lemma mem_allpairs_dep f s1 t1 s2 t2 :
s1 =i s2 -> {in s1, forall x, t1 x =i t2 x} ->
[seq f x y | x <- s1, y <- t1 x] =i [seq f x y | x <- s2, y <- t2 x].
Proof.
move=> eq_s eq_t z; apply/allpairsPdep/allpairsPdep=> -[x [y [sx ty ->]]];
by exists x, y; rewrite -eq_s in sx *; rewrite eq_t in ty *.
Qed.
Lemma allpairs_uniq_dep f s t (st := [seq Tagged T y | x <- s, y <- t x]) :
let g (p : {x : S & T x}) : R := f (tag p) (tagged p) in
uniq s -> {in s, forall x, uniq (t x)} -> {in st &, injective g} ->
uniq [seq f x y | x <- s, y <- t x].
Proof.
move=> g Us Ut; rewrite -(map_allpairs g (existT T)) => /map_inj_in_uniq->{f g}.
elim: s Us => //= x s IHs /andP[s'x Us] in st Ut *; rewrite {st}cat_uniq.
rewrite {}IHs {Us}// ?andbT => [|x1 s_s1]; last exact/Ut/mem_behead.
have injT: injective (existT T x) by move=> y z /eqP; rewrite eq_Tagged => /eqP.
rewrite (map_inj_in_uniq (in2W injT)) {injT}Ut ?mem_head // has_sym has_map.
by apply: contra s'x => /hasP[y _ /allpairsPdep[z [_ [? _ /(congr1 tag)/=->]]]].
Qed.
End EqAllPairsDep.
Arguments allpairsPdep {S T R f s t z}.
Section MemAllPairs.
Variables (S : Type) (T : S -> Type) (R : eqType).
Implicit Types (f : forall x, T x -> R) (s : seq S).
Lemma perm_allpairs_catr f s t1 t2 :
perm_eql [seq f x y | x <- s, y <- t1 x ++ t2 x]
([seq f x y | x <- s, y <- t1 x] ++ [seq f x y | x <- s, y <- t2 x]).
Proof.
apply/permPl; rewrite perm_sym; elim: s => //= x s ihs.
by rewrite perm_catACA perm_cat ?map_cat.
Qed.
Lemma mem_allpairs_catr f s y0 t :
[seq f x y | x <- s, y <- y0 x ++ t x] =i
[seq f x y | x <- s, y <- y0 x] ++ [seq f x y | x <- s, y <- t x].
Proof. exact/perm_mem/permPl/perm_allpairs_catr. Qed.
Lemma perm_allpairs_consr f s y0 t :
perm_eql [seq f x y | x <- s, y <- y0 x :: t x]
([seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x]).
Proof.
by apply/permPl; rewrite (perm_allpairs_catr _ _ (fun=> [:: _])) allpairs1r.
Qed.
Lemma mem_allpairs_consr f s t y0 :
[seq f x y | x <- s, y <- y0 x :: t x] =i
[seq f x (y0 x) | x <- s] ++ [seq f x y | x <- s, y <- t x].
Proof. exact/perm_mem/permPl/perm_allpairs_consr. Qed.
Lemma allpairs_rconsr f s y0 t :
perm_eql [seq f x y | x <- s, y <- rcons (t x) (y0 x)]
([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]).
Proof.
apply/permPl; rewrite -(eq_allpairsr _ _ (fun=> cats1 _ _)).
by rewrite perm_allpairs_catr allpairs1r.
Qed.
Lemma mem_allpairs_rconsr f s t y0 :
[seq f x y | x <- s, y <- rcons (t x) (y0 x)] =i
([seq f x y | x <- s, y <- t x] ++ [seq f x (y0 x) | x <- s]).
Proof. exact/perm_mem/permPl/allpairs_rconsr. Qed.
End MemAllPairs.
Lemma all_allpairsP
(S : eqType) (T : S -> eqType) (R : Type)
(p : pred R) (f : forall x : S, T x -> R)
(s : seq S) (t : forall x : S, seq (T x)) :
reflect (forall (x : S) (y : T x), x \in s -> y \in t x -> p (f x y))
(all p [seq f x y | x <- s, y <- t x]).
Proof.
elim: s => [|x s IHs]; first by constructor.
rewrite /= all_cat all_map /preim.
apply/(iffP andP)=> [[/allP /= ? ? x' y x'_in_xs]|p_xs_t].
by move: x'_in_xs y => /[1!inE] /predU1P [-> //|? ?]; exact: IHs.
split; first by apply/allP => ?; exact/p_xs_t/mem_head.
by apply/IHs => x' y x'_in_s; apply: p_xs_t; rewrite inE x'_in_s orbT.
Qed.
Arguments all_allpairsP {S T R p f s t}.
Section EqAllPairs.
Variables S T R : eqType.
Implicit Types (f : S -> T -> R) (s : seq S) (t : seq T).
Lemma allpairsP f s t (z : R) :
reflect (exists p, [/\ p.1 \in s, p.2 \in t & z = f p.1 p.2])
(z \in [seq f x y | x <- s, y <- t]).
Proof.
by apply: (iffP allpairsPdep) => [[x[y]]|[[x y]]]; [exists (x, y)|exists x, y].
Qed.
Lemma allpairs_f f s t x y :
x \in s -> y \in t -> f x y \in [seq f x y | x <- s, y <- t].
Proof. exact: allpairs_f_dep. Qed.
Lemma eq_in_allpairs f1 f2 s t :
{in s & t, f1 =2 f2} <->
[seq f1 x y : R | x <- s, y <- t] = [seq f2 x y | x <- s, y <- t].
Proof.
split=> [eq_f | /eq_in_allpairs_dep-eq_f x y /eq_f/(_ y)//].
by apply/eq_in_allpairs_dep=> x /eq_f.
Qed.
Lemma perm_allpairs f s1 t1 s2 t2 :
perm_eq s1 s2 -> perm_eq t1 t2 ->
perm_eq [seq f x y | x <- s1, y <- t1] [seq f x y | x <- s2, y <- t2].
Proof. by move=> perm_s perm_t; apply: perm_allpairs_dep. Qed.
Lemma mem_allpairs f s1 t1 s2 t2 :
s1 =i s2 -> t1 =i t2 ->
[seq f x y | x <- s1, y <- t1] =i [seq f x y | x <- s2, y <- t2].
Proof. by move=> eq_s eq_t; apply: mem_allpairs_dep. Qed.
Lemma allpairs_uniq f s t (st := [seq (x, y) | x <- s, y <- t]) :
uniq s -> uniq t -> {in st &, injective (uncurry f)} ->
uniq [seq f x y | x <- s, y <- t].
Proof.
move=> Us Ut inj_f; rewrite -(map_allpairs (uncurry f) (@pair S T)) -/st.
rewrite map_inj_in_uniq // allpairs_uniq_dep {Us Ut st inj_f}//.
by apply: in2W => -[x1 y1] [x2 y2] /= [-> ->].
Qed.
End EqAllPairs.
Arguments allpairsP {S T R f s t z}.
Arguments perm_nilP {T s}.
Arguments perm_consP {T x s t}.
Section AllRel.
Variables (T S : Type) (r : T -> S -> bool).
Implicit Types (x : T) (y : S) (xs : seq T) (ys : seq S).
Definition allrel xs ys := all [pred x | all (r x) ys] xs.
Lemma allrel0l ys : allrel [::] ys. Proof. by []. Qed.
Lemma allrel0r xs : allrel xs [::]. Proof. by elim: xs. Qed.
Lemma allrel_consl x xs ys : allrel (x :: xs) ys = all (r x) ys && allrel xs ys.
Proof. by []. Qed.
Lemma allrel_consr xs y ys :
allrel xs (y :: ys) = all (r^~ y) xs && allrel xs ys.
Proof. exact: all_predI. Qed.
Lemma allrel_cons2 x y xs ys :
allrel (x :: xs) (y :: ys) =
[&& r x y, all (r x) ys, all (r^~ y) xs & allrel xs ys].
Proof. by rewrite /= allrel_consr -andbA. Qed.
Lemma allrel1l x ys : allrel [:: x] ys = all (r x) ys. Proof. exact: andbT. Qed.
Lemma allrel1r xs y : allrel xs [:: y] = all (r^~ y) xs.
Proof. by rewrite allrel_consr allrel0r andbT. Qed.
Lemma allrel_catl xs xs' ys :
allrel (xs ++ xs') ys = allrel xs ys && allrel xs' ys.
Proof. exact: all_cat. Qed.
Lemma allrel_catr xs ys ys' :
allrel xs (ys ++ ys') = allrel xs ys && allrel xs ys'.
Proof.
elim: ys => /= [|y ys ihys]; first by rewrite allrel0r.
by rewrite !allrel_consr ihys andbA.
Qed.
Lemma allrel_maskl m xs ys : allrel xs ys -> allrel (mask m xs) ys.
Proof.
by elim: m xs => [|[] m IHm] [|x xs] //= /andP [xys /IHm->]; rewrite ?xys.
Qed.
Lemma allrel_maskr m xs ys : allrel xs ys -> allrel xs (mask m ys).
Proof. by elim: xs => //= x xs IHxs /andP [/all_mask->]. Qed.
Lemma allrel_filterl a xs ys : allrel xs ys -> allrel (filter a xs) ys.
Proof. by rewrite filter_mask; apply: allrel_maskl. Qed.
Lemma allrel_filterr a xs ys : allrel xs ys -> allrel xs (filter a ys).
Proof. by rewrite filter_mask; apply: allrel_maskr. Qed.
Lemma allrel_allpairsE xs ys :
allrel xs ys = all id [seq r x y | x <- xs, y <- ys].
Proof. by elim: xs => //= x xs ->; rewrite all_cat all_map. Qed.
End AllRel.
Arguments allrel {T S} r xs ys : simpl never.
Arguments allrel0l {T S} r ys.
Arguments allrel0r {T S} r xs.
Arguments allrel_consl {T S} r x xs ys.
Arguments allrel_consr {T S} r xs y ys.
Arguments allrel1l {T S} r x ys.
Arguments allrel1r {T S} r xs y.
Arguments allrel_catl {T S} r xs xs' ys.
Arguments allrel_catr {T S} r xs ys ys'.
Arguments allrel_maskl {T S} r m xs ys.
Arguments allrel_maskr {T S} r m xs ys.
Arguments allrel_filterl {T S} r a xs ys.
Arguments allrel_filterr {T S} r a xs ys.
Arguments allrel_allpairsE {T S} r xs ys.
Notation all2rel r xs := (allrel r xs xs).
Lemma sub_in_allrel
{T S : Type} (P : {pred T}) (Q : {pred S}) (r r' : T -> S -> bool) :
{in P & Q, forall x y, r x y -> r' x y} ->
forall xs ys, all P xs -> all Q ys -> allrel r xs ys -> allrel r' xs ys.
Proof.
move=> rr' + ys; elim=> //= x xs IHxs /andP [Px Pxs] Qys.
rewrite !allrel_consl => /andP [+ {}/IHxs-> //]; rewrite andbT.
by elim: ys Qys => //= y ys IHys /andP [Qy Qys] /andP [/rr'-> // /IHys->].
Qed.
Lemma sub_allrel {T S : Type} (r r' : T -> S -> bool) :
(forall x y, r x y -> r' x y) ->
forall xs ys, allrel r xs ys -> allrel r' xs ys.
Proof.
by move=> rr' xs ys; apply/sub_in_allrel/all_predT/all_predT; apply: in2W.
Qed.
Lemma eq_in_allrel {T S : Type} (P : {pred T}) (Q : {pred S}) r r' :
{in P & Q, r =2 r'} ->
forall xs ys, all P xs -> all Q ys -> allrel r xs ys = allrel r' xs ys.
Proof.
move=> rr' xs ys Pxs Qys.
by apply/idP/idP; apply/sub_in_allrel/Qys/Pxs => ? ? ? ?; rewrite rr'.
Qed.
Lemma eq_allrel {T S : Type} (r r' : T -> S -> bool) :
r =2 r' -> allrel r =2 allrel r'.
Proof. by move=> rr' xs ys; apply/eq_in_allrel/all_predT/all_predT. Qed.
Lemma allrelC {T S : Type} (r : T -> S -> bool) xs ys :
allrel r xs ys = allrel (fun y => r^~ y) ys xs.
Proof. by elim: xs => [|x xs ih]; [elim: ys | rewrite allrel_consr -ih]. Qed.
Lemma allrel_mapl {T T' S : Type} (f : T' -> T) (r : T -> S -> bool) xs ys :
allrel r (map f xs) ys = allrel (fun x => r (f x)) xs ys.
Proof. exact: all_map. Qed.
Lemma allrel_mapr {T S S' : Type} (f : S' -> S) (r : T -> S -> bool) xs ys :
allrel r xs (map f ys) = allrel (fun x y => r x (f y)) xs ys.
Proof. by rewrite allrelC allrel_mapl allrelC. Qed.
Lemma allrelP {T S : eqType} {r : T -> S -> bool} {xs ys} :
reflect {in xs & ys, forall x y, r x y} (allrel r xs ys).
Proof. by rewrite allrel_allpairsE; exact: all_allpairsP. Qed.
Lemma allrelT {T S : Type} (xs : seq T) (ys : seq S) :
allrel (fun _ _ => true) xs ys = true.
Proof. by elim: xs => //= ? ?; rewrite allrel_consl all_predT. Qed.
Lemma allrel_relI {T S : Type} (r r' : T -> S -> bool) xs ys :
allrel (fun x y => r x y && r' x y) xs ys = allrel r xs ys && allrel r' xs ys.
Proof. by rewrite -all_predI; apply: eq_all => ?; rewrite /= -all_predI. Qed.
Lemma allrel_revl {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r (rev s1) s2 = allrel r s1 s2.
Proof. exact: all_rev. Qed.
Lemma allrel_revr {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r s1 (rev s2) = allrel r s1 s2.
Proof. by rewrite allrelC allrel_revl allrelC. Qed.
Lemma allrel_rev2 {T S : Type} (r : T -> S -> bool) (s1 : seq T) (s2 : seq S) :
allrel r (rev s1) (rev s2) = allrel r s1 s2.
Proof. by rewrite allrel_revr allrel_revl. Qed.
Lemma eq_allrel_meml {T : eqType} {S} (r : T -> S -> bool) (s1 s1' : seq T) s2 :
s1 =i s1' -> allrel r s1 s2 = allrel r s1' s2.
Proof. by move=> eqs1; apply: eq_all_r. Qed.
Lemma eq_allrel_memr {T} {S : eqType} (r : T -> S -> bool) s1 (s2 s2' : seq S) :
s2 =i s2' -> allrel r s1 s2 = allrel r s1 s2'.
Proof. by rewrite ![allrel _ s1 _]allrelC; apply: eq_allrel_meml. Qed.
Lemma eq_allrel_mem2 {T S : eqType} (r : T -> S -> bool)
(s1 s1' : seq T) (s2 s2' : seq S) :
s1 =i s1' -> s2 =i s2' -> allrel r s1 s2 = allrel r s1' s2'.
Proof. by move=> /eq_allrel_meml -> /eq_allrel_memr ->. Qed.
Section All2Rel.
Variable (T : nonPropType) (r : rel T).
Implicit Types (x y z : T) (xs : seq T).
Hypothesis (rsym : symmetric r).
Lemma all2rel1 x : all2rel r [:: x] = r x x.
Proof. by rewrite /allrel /= !andbT. Qed.
Lemma all2rel2 x y : all2rel r [:: x; y] = r x x && r y y && r x y.
Proof. by rewrite /allrel /= rsym; do 3 case: r. Qed.
Lemma all2rel_cons x xs :
all2rel r (x :: xs) = [&& r x x, all (r x) xs & all2rel r xs].
Proof.
rewrite allrel_cons2; congr andb; rewrite andbA -all_predI; congr andb.
by elim: xs => //= y xs ->; rewrite rsym andbb.
Qed.
End All2Rel.
Section Pairwise.
Variables (T : Type) (r : T -> T -> bool).
Implicit Types (x y : T) (xs ys : seq T).
Fixpoint pairwise xs : bool :=
if xs is x :: xs then all (r x) xs && pairwise xs else true.
Lemma pairwise_cons x xs : pairwise (x :: xs) = all (r x) xs && pairwise xs.
Proof. by []. Qed.
Lemma pairwise_cat xs ys :
pairwise (xs ++ ys) = [&& allrel r xs ys, pairwise xs & pairwise ys].
Proof. by elim: xs => //= x xs ->; rewrite all_cat -!andbA; bool_congr. Qed.
Lemma pairwise_rcons xs x :
pairwise (rcons xs x) = all (r^~ x) xs && pairwise xs.
Proof. by rewrite -cats1 pairwise_cat allrel1r andbT. Qed.
Lemma pairwise2 x y : pairwise [:: x; y] = r x y.
Proof. by rewrite /= !andbT. Qed.
Lemma pairwise_mask m xs : pairwise xs -> pairwise (mask m xs).
Proof.
by elim: m xs => [|[] m IHm] [|x xs] //= /andP [? ?]; rewrite ?IHm // all_mask.
Qed.
Lemma pairwise_filter a xs : pairwise xs -> pairwise (filter a xs).
Proof. by rewrite filter_mask; apply: pairwise_mask. Qed.
Lemma pairwiseP x0 xs :
reflect {in gtn (size xs) &, {homo nth x0 xs : i j / i < j >-> r i j}}
(pairwise xs).
Proof.
elim: xs => /= [|x xs IHxs]; first exact: (iffP idP).
apply: (iffP andP) => [[r_x_xs pxs] i j|Hnth]; rewrite -?topredE /= ?ltnS.
by case: i j => [|i] [|j] //= gti gtj ij; [exact/all_nthP | exact/IHxs].
split; last by apply/IHxs => // i j; apply/(Hnth i.+1 j.+1).
by apply/(all_nthP x0) => i gti; apply/(Hnth 0 i.+1).
Qed.
Lemma pairwise_all2rel :
reflexive r -> symmetric r -> forall xs, pairwise xs = all2rel r xs.
Proof.
by move=> r_refl r_sym; elim => //= x xs ->; rewrite all2rel_cons // r_refl.
Qed.
End Pairwise.
Arguments pairwise {T} r xs.
Arguments pairwise_cons {T} r x xs.
Arguments pairwise_cat {T} r xs ys.
Arguments pairwise_rcons {T} r xs x.
Arguments pairwise2 {T} r x y.
Arguments pairwise_mask {T r} m {xs}.
Arguments pairwise_filter {T r} a {xs}.
Arguments pairwiseP {T r} x0 {xs}.
Arguments pairwise_all2rel {T r} r_refl r_sym xs.
Lemma sub_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) :
{in P &, subrel r r'} ->
forall xs, all P xs -> pairwise r xs -> pairwise r' xs.
Proof.
move=> rr'; elim=> //= x xs IHxs /andP [Px Pxs] /andP [+ {}/IHxs->] //.
rewrite andbT; elim: xs Pxs => //= x' xs IHxs /andP [? ?] /andP [+ /IHxs->] //.
by rewrite andbT; apply: rr'.
Qed.
Lemma sub_pairwise {T : Type} (r r' : rel T) xs :
subrel r r' -> pairwise r xs -> pairwise r' xs.
Proof. by move=> rr'; apply/sub_in_pairwise/all_predT; apply: in2W. Qed.
Lemma eq_in_pairwise {T : Type} (P : {pred T}) (r r' : rel T) :
{in P &, r =2 r'} -> forall xs, all P xs -> pairwise r xs = pairwise r' xs.
Proof.
move=> rr' xs Pxs.
by apply/idP/idP; apply/sub_in_pairwise/Pxs => ? ? ? ?; rewrite rr'.
Qed.
Lemma eq_pairwise {T : Type} (r r' : rel T) :
r =2 r' -> pairwise r =i pairwise r'.
Proof. by move=> rr' xs; apply/eq_in_pairwise/all_predT. Qed.
Lemma pairwise_map {T T' : Type} (f : T' -> T) (r : rel T) xs :
pairwise r (map f xs) = pairwise (relpre f r) xs.
Proof. by elim: xs => //= x xs ->; rewrite all_map. Qed.
Lemma pairwise_relI {T : Type} (r r' : rel T) (s : seq T) :
pairwise [rel x y | r x y && r' x y] s = pairwise r s && pairwise r' s.
Proof. by elim: s => //= x s ->; rewrite andbACA all_predI. Qed.
Section EqPairwise.
Variables (T : eqType) (r : T -> T -> bool).
Implicit Types (xs ys : seq T).
Lemma subseq_pairwise xs ys : subseq xs ys -> pairwise r ys -> pairwise r xs.
Proof. by case/subseqP => m _ ->; apply: pairwise_mask. Qed.
Lemma uniq_pairwise xs : uniq xs = pairwise [rel x y | x != y] xs.
Proof.
elim: xs => //= x xs ->; congr andb; rewrite -has_pred1 -all_predC.
by elim: xs => //= x' xs ->; case: eqVneq.
Qed.
Lemma pairwise_uniq xs : irreflexive r -> pairwise r xs -> uniq xs.
Proof.
move=> r_irr; rewrite uniq_pairwise; apply/sub_pairwise => x y.
by apply: contraTneq => ->; rewrite r_irr.
Qed.
Lemma pairwise_eq : antisymmetric r ->
forall xs ys, pairwise r xs -> pairwise r ys -> perm_eq xs ys -> xs = ys.
Proof.
move=> r_asym; elim=> [|x xs IHxs] [|y ys] //=; try by move=> ? ? /perm_size.
move=> /andP [r_x_xs pxs] /andP [r_y_ys pys] eq_xs_ys.
move: (mem_head y ys) (mem_head x xs).
rewrite -(perm_mem eq_xs_ys) [x \in _](perm_mem eq_xs_ys) !inE.
case: eqVneq eq_xs_ys => /= [->|ne_xy] eq_xs_ys ys_x xs_y.
by rewrite (IHxs ys) // -(perm_cons x).
by case/eqP: ne_xy; apply: r_asym; rewrite (allP r_x_xs) ?(allP r_y_ys).
Qed.
Lemma pairwise_trans s : antisymmetric r ->
pairwise r s -> {in s & &, transitive r}.
Proof.
move=> /(_ _ _ _)/eqP r_anti + y x z => /pairwiseP-/(_ y) ltP ys xs zs.
have [-> //|neqxy] := eqVneq x y; have [-> //|neqzy] := eqVneq z y.
move=> lxy lyz; move: ys xs zs lxy neqxy lyz neqzy.
move=> /(nthP y)[j jlt <-] /(nthP y)[i ilt <-] /(nthP y)[k klt <-].
have [ltij|ltji|->] := ltngtP i j; last 2 first.
- by move=> leij; rewrite r_anti// leij ltP.
- by move=> lejj; rewrite r_anti// lejj.
move=> _ _; have [ltjk|ltkj|->] := ltngtP j k; last 2 first.
- by move=> lejk; rewrite r_anti// lejk ltP.
- by move=> lekk; rewrite r_anti// lekk.
by move=> _ _; apply: (ltP) => //; apply: ltn_trans ltjk.
Qed.
End EqPairwise.
Arguments subseq_pairwise {T r xs ys}.
Arguments uniq_pairwise {T} xs.
Arguments pairwise_uniq {T r xs}.
Arguments pairwise_eq {T r} r_asym {xs ys}.
Section Permutations.
Variable T : eqType.
Implicit Types (x : T) (s t : seq T) (bs : seq (T * nat)) (acc : seq (seq T)).
Fixpoint incr_tally bs x :=
if bs isn't b :: bs then [:: (x, 1)] else
if x == b.1 then (x, b.2.+1) :: bs else b :: incr_tally bs x.
Definition tally s := foldl incr_tally [::] s.
Definition wf_tally :=
[qualify a bs : seq (T * nat) | uniq (unzip1 bs) && (0 \notin unzip2 bs)].
Definition tally_seq bs := flatten [seq nseq b.2 b.1 | b <- bs].
Local Notation tseq := tally_seq.
Lemma size_tally_seq bs : size (tally_seq bs) = sumn (unzip2 bs).
Proof.
by rewrite size_flatten /shape -map_comp; under eq_map do rewrite /= size_nseq.
Qed.
Lemma tally_seqK : {in wf_tally, cancel tally_seq tally}.
Proof.
move=> bs /andP[]; elim: bs => [|[x [|n]] bs IHbs] //= /andP[bs'x Ubs] bs'0.
rewrite inE /tseq /tally /= -[n.+1]addn1 in bs'0 *.
elim: n 1 => /= [|n IHn] m; last by rewrite eqxx IHn addnS.
rewrite -{}[in RHS]IHbs {Ubs bs'0}// /tally /tally_seq add0n.
elim: bs bs'x [::] => [|[y n] bs IHbs] //= /[1!inE] /norP[y'x bs'x].
by elim: n => [|n IHn] bs1 /=; [rewrite IHbs | rewrite eq_sym ifN // IHn].
Qed.
Lemma incr_tallyP x : {homo incr_tally^~ x : bs / bs \in wf_tally}.
Proof.
move=> bs /andP[]; rewrite unfold_in.
elim: bs => [|[y [|n]] bs IHbs] //= /andP[bs'y Ubs] /[1!inE] /= bs'0.
have [<- | y'x] /= := eqVneq y; first by rewrite bs'y Ubs.
rewrite -andbA {}IHbs {Ubs bs'0}// andbT.
elim: bs bs'y => [|b bs IHbs] /=; rewrite inE ?y'x // => /norP[b'y bs'y].
by case: ifP => _; rewrite /= inE negb_or ?y'x // b'y IHbs.
Qed.
Lemma tallyP s : tally s \is a wf_tally.
Proof.
rewrite /tally; set bs := [::]; have: bs \in wf_tally by [].
by elim: s bs => //= x s IHs bs /(incr_tallyP x)/IHs.
Qed.
Lemma tallyK s : perm_eq (tally_seq (tally s)) s.
Proof.
rewrite -[s in perm_eq _ s]cats0 -[nil]/(tseq [::]) /tally.
elim: s [::] => //= x s IHs bs; rewrite {IHs}(permPl (IHs _)).
rewrite perm_sym -cat1s perm_catCA {s}perm_cat2l.
elim: bs => //= b bs IHbs; case: eqP => [-> | _] //=.
by rewrite -cat1s perm_catCA perm_cat2l.
Qed.
Lemma tallyEl s : perm_eq (unzip1 (tally s)) (undup s).
Proof.
have /andP[Ubs bs'0] := tallyP s; set bs := tally s in Ubs bs'0 *.
rewrite uniq_perm ?undup_uniq {Ubs}// => x.
rewrite mem_undup -(perm_mem (tallyK s)) -/bs.
elim: bs => [|[y [|m]] bs IHbs] //= in bs'0 *.
by rewrite inE IHbs // mem_cat mem_nseq.
Qed.
Lemma tallyE s : perm_eq (tally s) [seq (x, count_mem x s) | x <- undup s].
Proof.
have /andP[Ubs _] := tallyP s; pose b := [fun s x => (x, count_mem x (tseq s))].
suffices /permPl->: perm_eq (tally s) (map (b (tally s)) (unzip1 (tally s))).
congr perm_eq: (perm_map (b (tally s)) (tallyEl s)).
by under eq_map do rewrite /= (permP (tallyK s)).
elim: (tally s) Ubs => [|[x m] bs IH] //= /andP[bs'x /IH-IHbs {IH}].
rewrite /tseq /= -/(tseq _) count_cat count_nseq /= eqxx mul1n.
rewrite (count_memPn _) ?addn0 ?perm_cons; last first.
apply: contra bs'x; elim: {b IHbs}bs => //= b bs IHbs.
by rewrite mem_cat mem_nseq inE andbC; case: (_ == _).
congr perm_eq: IHbs; apply/eq_in_map=> y bs_y; congr (y, _).
by rewrite count_cat count_nseq /= (negPf (memPnC bs'x y bs_y)).
Qed.
Lemma perm_tally s1 s2 : perm_eq s1 s2 -> perm_eq (tally s1) (tally s2).
Proof.
move=> eq_s12; apply: (@perm_trans _ [seq (x, count_mem x s2) | x <- undup s1]).
by congr perm_eq: (tallyE s1); under eq_map do rewrite (permP eq_s12).
by rewrite (permPr (tallyE s2)); apply/perm_map/perm_undup/(perm_mem eq_s12).
Qed.
Lemma perm_tally_seq bs1 bs2 :
perm_eq bs1 bs2 -> perm_eq (tally_seq bs1) (tally_seq bs2).
Proof. by move=> Ebs12; rewrite perm_flatten ?perm_map. Qed.
Local Notation perm_tseq := perm_tally_seq.
Lemma perm_count_undup s :
perm_eq (flatten [seq nseq (count_mem x s) x | x <- undup s]) s.
Proof.
by rewrite -(permPr (tallyK s)) (permPr (perm_tseq (tallyE s))) /tseq -map_comp.
Qed.
Local Fixpoint cons_perms_ perms_rec (s : seq T) bs bs2 acc :=
if bs isn't b :: bs1 then acc else
if b isn't (x, m.+1) then cons_perms_ perms_rec s bs1 bs2 acc else
let acc_xs := perms_rec (x :: s) ((x, m) :: bs1 ++ bs2) acc in
cons_perms_ perms_rec s bs1 (b :: bs2) acc_xs.
Local Fixpoint perms_rec n s bs acc :=
if n isn't n.+1 then s :: acc else cons_perms_ (perms_rec n) s bs [::] acc.
Local Notation cons_perms n := (cons_perms_ (perms_rec n) [::]).
Definition permutations s := perms_rec (size s) [::] (tally s) [::].
Let permsP s : exists n bs,
[/\ permutations s = perms_rec n [::] bs [::],
size (tseq bs) == n, perm_eq (tseq bs) s & uniq (unzip1 bs)].
Proof.
have /andP[Ubs _] := tallyP s; exists (size s), (tally s).
by rewrite (perm_size (tallyK s)) tallyK.
Qed.
Local Notation bsCA := (permEl (perm_catCA _ [:: _] _)).
Let cons_permsE : forall n x bs bs1 bs2,
let cp := cons_perms n bs bs2 in let perms s := perms_rec n s bs1 [::] in
cp (perms [:: x]) = cp [::] ++ [seq rcons t x | t <- perms [::]].
Proof.
pose is_acc f := forall acc, f acc = f [::] ++ acc. (* f is accumulating. *)
have cpE: forall f & forall s bs, is_acc (f s bs), is_acc (cons_perms_ f _ _ _).
move=> s bs bs2 f fE acc; elim: bs => [|[x [|m]] bs IHbs] //= in s bs2 acc *.
by rewrite fE IHbs catA -IHbs.
have prE: is_acc (perms_rec _ _ _) by elim=> //= n IHn s bs; apply: cpE.
pose has_suffix f := forall s : seq T, f s = [seq t ++ s | t <- f [::]].
suffices prEs n bs: has_suffix (fun s => perms_rec n s bs [::]).
move=> n x bs bs1 bs2 /=; rewrite cpE // prEs.
by under eq_map do rewrite cats1.
elim: n bs => //= n IHn bs s; elim: bs [::] => [|[x [|m]] bs IHbs] //= bs1.
rewrite cpE // IHbs IHn [in RHS]cpE // [in RHS]IHn map_cat -map_comp.
by congr (_ ++ _); apply: eq_map => t /=; rewrite -catA.
Qed.
Lemma mem_permutations s t : (t \in permutations s) = perm_eq t s.
Proof.
have{s} [n [bs [-> Dn /permPr<- _]]] := permsP s.
elim: n => [|n IHn] /= in t bs Dn *.
by rewrite inE (nilP Dn); apply/eqP/perm_nilP.
rewrite -[bs in tseq bs]cats0 in Dn *; have x0 : T by case: (tseq _) Dn.
rewrite -[RHS](@andb_idl (last x0 t \in tseq bs)); last first.
case/lastP: t {IHn} => [|t x] Dt; first by rewrite -(perm_size Dt) in Dn.
by rewrite -[bs]cats0 -(perm_mem Dt) last_rcons mem_rcons mem_head.
elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn *.
rewrite cons_permsE -!cat_cons !mem_cat (mem_nseq m.+1) orbC andb_orl.
rewrite {}IHbs ?(perm_size (perm_tseq bsCA)) //= (permPr (perm_tseq bsCA)).
congr (_ || _); apply/mapP/andP=> [[t1 Dt1 ->] | [/eqP]].
by rewrite last_rcons perm_rcons perm_cons IHn in Dt1 *.
case/lastP: t => [_ /perm_size//|t y]; rewrite last_rcons perm_rcons => ->.
by rewrite perm_cons; exists t; rewrite ?IHn.
Qed.
Lemma permutations_uniq s : uniq (permutations s).
Proof.
have{s} [n [bs [-> Dn _ Ubs]]] := permsP s.
elim: n => //= n IHn in bs Dn Ubs *; rewrite -[bs]cats0 /unzip1 in Dn Ubs.
elim: bs [::] => [|[x [|m]] bs IHbs] //= bs2 in Dn Ubs *.
by case/andP: Ubs => _ /IHbs->.
rewrite /= cons_permsE cat_uniq has_sym andbCA andbC.
rewrite {}IHbs; first 1 last; first by rewrite (perm_size (perm_tseq bsCA)).
by rewrite (perm_uniq (perm_map _ bsCA)).
rewrite (map_inj_uniq (rcons_injl x)) {}IHn {Dn}//=.
have: x \notin unzip1 bs by apply: contraL Ubs; rewrite map_cat mem_cat => ->.
move: {bs2 m Ubs}(perms_rec n _ _ _) (_ :: bs2) => ts.
elim: bs => [|[y [|m]] bs IHbs] //= /[1!inE] bs2 /norP[x'y /IHbs//].
rewrite cons_permsE has_cat negb_or has_map => ->.
by apply/hasPn=> t _; apply: contra x'y => /mapP[t1 _ /rcons_inj[_ ->]].
Qed.
Notation perms := permutations.
Lemma permutationsE s :
0 < size s ->
perm_eq (perms s) [seq x :: t | x <- undup s, t <- perms (rem x s)].
Proof.
move=> nt_s; apply/uniq_perm=> [||t]; first exact: permutations_uniq.
apply/allpairs_uniq_dep=> [|x _|]; rewrite ?undup_uniq ?permutations_uniq //.
by case=> [_ _] [x t] _ _ [-> ->].
rewrite mem_permutations; apply/idP/allpairsPdep=> [Dt | [x [t1 []]]].
rewrite -(perm_size Dt) in nt_s; case: t nt_s => // x t _ in Dt *.
have s_x: x \in s by rewrite -(perm_mem Dt) mem_head.
exists x, t; rewrite mem_undup mem_permutations; split=> //.
by rewrite -(perm_cons x) (permPl Dt) perm_to_rem.
rewrite mem_undup mem_permutations -(perm_cons x) => s_x Dt1 ->.
by rewrite (permPl Dt1) perm_sym perm_to_rem.
Qed.
Lemma permutationsErot x s (le_x := fun t => iota 0 (index x t + 1)) :
perm_eq (perms (x :: s)) [seq rot i (x :: t) | t <- perms s, i <- le_x t].
Proof.
have take'x t i: i <= index x t -> i <= size t /\ x \notin take i t.
move=> le_i_x; have le_i_t: i <= size t := leq_trans le_i_x (index_size x t).
case: (nthP x) => // -[j lt_j_i /eqP]; rewrite size_takel // in lt_j_i.
by rewrite nth_take // [_ == _](before_find x (leq_trans lt_j_i le_i_x)).
pose xrot t i := rot i (x :: t); pose xrotV t := index x (rev (rot 1 t)).
have xrotK t: {in le_x t, cancel (xrot t) xrotV}.
move=> i; rewrite mem_iota addn1 /xrotV => /take'x[le_i_t ti'x].
rewrite -rotD ?rev_cat //= rev_cons cat_rcons index_cat mem_rev size_rev.
by rewrite ifN // size_takel //= eqxx addn0.
apply/uniq_perm=> [||t]; first exact: permutations_uniq.
apply/allpairs_uniq_dep=> [|t _|]; rewrite ?permutations_uniq ?iota_uniq //.
move=> _ _ /allpairsPdep[t [i [_ ? ->]]] /allpairsPdep[u [j [_ ? ->]]] Etu.
have Eij: i = j by rewrite -(xrotK t i) // /xrot Etu xrotK.
by move: Etu; rewrite Eij => /rot_inj[->].
rewrite mem_permutations; apply/esym; apply/allpairsPdep/idP=> [[u [i]] | Dt].
rewrite mem_permutations => -[Du _ /(canLR (rotK i))]; rewrite /rotr.
by set j := (j in rot j _) => Dt; apply/perm_consP; exists j, u.
pose r := rev (rot 1 t); pose i := index x r; pose u := rev (take i r).
have r_x: x \in r by rewrite mem_rev mem_rot (perm_mem Dt) mem_head.
have [v Duv]: {v | rot i (x :: u ++ v) = t}; first exists (rev (drop i.+1 r)).
rewrite -rev_cat -rev_rcons -rot1_cons -cat_cons -(nth_index x r_x).
by rewrite -drop_nth ?index_mem // rot_rot !rev_rot revK rotK rotrK.
exists (u ++ v), i; rewrite mem_permutations -(perm_cons x) -(perm_rot i) Duv.
rewrite mem_iota addn1 ltnS /= index_cat mem_rev size_rev.
by have /take'x[le_i_t ti'x] := leqnn i; rewrite ifN ?size_takel ?leq_addr.
Qed.
Lemma size_permutations s : uniq s -> size (permutations s) = (size s)`!.
Proof.
move Dn: (size s) => n Us; elim: n s => [[]|n IHn s] //= in Dn Us *.
rewrite (perm_size (permutationsE _)) ?Dn // undup_id // factS -Dn.
rewrite -(size_iota 0 n`!) -(size_allpairs (fun=>id)) !size_allpairs_dep.
by apply/congr1/eq_in_map=> x sx; rewrite size_iota IHn ?size_rem ?Dn ?rem_uniq.
Qed.
Lemma permutations_all_uniq s : uniq s -> all uniq (permutations s).
Proof.
by move=> Us; apply/allP=> t; rewrite mem_permutations => /perm_uniq->.
Qed.
Lemma perm_permutations s t :
perm_eq s t -> perm_eq (permutations s) (permutations t).
Proof.
move=> Est; apply/uniq_perm; try exact: permutations_uniq.
by move=> u; rewrite !mem_permutations (permPr Est).
Qed.
End Permutations.
|
FinBddDistLat.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.Data.Fintype.Order
import Mathlib.Order.Category.BddDistLat
import Mathlib.Order.Category.FinPartOrd
/-!
# The category of finite bounded distributive lattices
This file defines `FinBddDistLat`, the category of finite distributive lattices with
bounded lattice homomorphisms.
-/
universe u
open CategoryTheory
/-- The category of finite distributive lattices with bounded lattice morphisms. -/
structure FinBddDistLat extends BddDistLat where
[isFintype : Fintype carrier]
namespace FinBddDistLat
instance : CoeSort FinBddDistLat Type* :=
β¨fun X => X.carrierβ©
instance (X : FinBddDistLat) : DistribLattice X :=
X.str
instance (X : FinBddDistLat) : BoundedOrder X :=
X.isBoundedOrder
attribute [instance] FinBddDistLat.isFintype
/-- Construct a bundled `FinBddDistLat` from a `Fintype` `BoundedOrder` `DistribLattice`. -/
abbrev of (Ξ± : Type*) [DistribLattice Ξ±] [BoundedOrder Ξ±] [Fintype Ξ±] : FinBddDistLat where
carrier := Ξ±
/-- Construct a bundled `FinBddDistLat` from a `Nonempty` `Fintype` `DistribLattice`. -/
abbrev of' (Ξ± : Type*) [DistribLattice Ξ±] [Fintype Ξ±] [Nonempty Ξ±] : FinBddDistLat where
carrier := Ξ±
isBoundedOrder := Fintype.toBoundedOrder Ξ±
/-- The type of morphisms in `FinBddDistLat R`. -/
@[ext]
structure Hom (X Y : FinBddDistLat.{u}) where
private mk ::
/-- The underlying `BoundedLatticeHom`. -/
hom' : BoundedLatticeHom X Y
instance : Category FinBddDistLat.{u} where
Hom X Y := Hom X Y
id X := β¨BoundedLatticeHom.id Xβ©
comp f g := β¨g.hom'.comp f.hom'β©
instance : ConcreteCategory FinBddDistLat (BoundedLatticeHom Β· Β·) where
hom := Hom.hom'
ofHom := Hom.mk
/-- Turn a morphism in `FinBddDistLat` back into a `BoundedLatticeHom`. -/
abbrev Hom.hom {X Y : FinBddDistLat.{u}} (f : Hom X Y) :=
ConcreteCategory.hom (C := FinBddDistLat) f
/-- Typecheck a `BoundedLatticeHom` as a morphism in `FinBddDistLat`. -/
abbrev ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y]
[BoundedOrder Y] [Fintype Y]
(f : BoundedLatticeHom X Y) :
of X βΆ of Y :=
ConcreteCategory.ofHom (C := FinBddDistLat) f
variable {R} in
/-- Use the `ConcreteCategory.hom` projection for `@[simps]` lemmas. -/
def Hom.Simps.hom (X Y : FinBddDistLat.{u}) (f : Hom X Y) :=
f.hom
initialize_simps_projections Hom (hom' β hom)
/-!
The results below duplicate the `ConcreteCategory` simp lemmas, but we can keep them for `dsimp`.
-/
@[simp]
lemma coe_id {X : FinBddDistLat} : (π X : X β X) = id := rfl
@[simp]
lemma coe_comp {X Y Z : FinBddDistLat} {f : X βΆ Y} {g : Y βΆ Z} : (f β« g : X β Z) = g β f := rfl
@[simp]
lemma forget_map {X Y : FinBddDistLat} (f : X βΆ Y) :
(forget FinBddDistLat).map f = f := rfl
@[ext]
lemma ext {X Y : FinBddDistLat} {f g : X βΆ Y} (w : β x : X, f x = g x) : f = g :=
ConcreteCategory.hom_ext _ _ w
@[simp]
lemma hom_id {X : FinBddDistLat} : (π X : X βΆ X).hom = BoundedLatticeHom.id _ := rfl
/- Provided for rewriting. -/
lemma id_apply (X : FinBddDistLat) (x : X) :
(π X : X βΆ X) x = x := by simp
@[simp]
lemma hom_comp {X Y Z : FinBddDistLat} (f : X βΆ Y) (g : Y βΆ Z) :
(f β« g).hom = g.hom.comp f.hom := rfl
/- Provided for rewriting. -/
lemma comp_apply {X Y Z : FinBddDistLat} (f : X βΆ Y) (g : Y βΆ Z) (x : X) :
(f β« g) x = g (f x) := by simp
@[ext]
lemma hom_ext {X Y : FinBddDistLat} {f g : X βΆ Y} (hf : f.hom = g.hom) : f = g :=
Hom.ext hf
@[simp]
lemma hom_ofHom {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y]
[BoundedOrder Y] [Fintype Y] (f : BoundedLatticeHom X Y) : (ofHom f).hom = f := rfl
@[simp]
lemma ofHom_hom {X Y : FinBddDistLat} (f : X βΆ Y) :
ofHom (Hom.hom f) = f := rfl
@[simp]
lemma ofHom_id {X : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] :
ofHom (BoundedLatticeHom.id _) = π (of X) := rfl
@[simp]
lemma ofHom_comp {X Y Z : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y]
[BoundedOrder Y] [Fintype Y] [DistribLattice Z] [BoundedOrder Z] [Fintype Z]
(f : BoundedLatticeHom X Y) (g : BoundedLatticeHom Y Z) :
ofHom (g.comp f) = ofHom f β« ofHom g :=
rfl
lemma ofHom_apply {X Y : Type u} [DistribLattice X] [BoundedOrder X] [Fintype X] [DistribLattice Y]
[BoundedOrder Y] [Fintype Y]
(f : BoundedLatticeHom X Y) (x : X) :
(ofHom f) x = f x := rfl
lemma inv_hom_apply {X Y : FinBddDistLat} (e : X β
Y) (x : X) : e.inv (e.hom x) = x := by
simp
lemma hom_inv_apply {X Y : FinBddDistLat} (e : X β
Y) (s : Y) : e.hom (e.inv s) = s := by
simp
instance : Inhabited FinBddDistLat :=
β¨of PUnitβ©
instance hasForgetToBddDistLat : HasForgetβ FinBddDistLat BddDistLat where
forgetβ.obj X := .of X
forgetβ.map f := BddDistLat.ofHom f.hom
instance hasForgetToFinPartOrd : HasForgetβ FinBddDistLat FinPartOrd where
forgetβ.obj X := .of X
forgetβ.map f := PartOrd.ofHom (OrderHomClass.toOrderHom f.hom)
/-- Constructs an equivalence between finite distributive lattices from an order isomorphism
between them. -/
@[simps]
def Iso.mk {Ξ± Ξ² : FinBddDistLat.{u}} (e : Ξ±.carrier βo Ξ².carrier) : Ξ± β
Ξ² where
hom := ofHom e
inv := ofHom e.symm
hom_inv_id := by ext; exact e.symm_apply_apply _
inv_hom_id := by ext; exact e.apply_symm_apply _
/-- `OrderDual` as a functor. -/
@[simps map]
def dual : FinBddDistLat β₯€ FinBddDistLat where
obj X := of Xα΅α΅
map f := ofHom f.hom.dual
/-- The equivalence between `FinBddDistLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : FinBddDistLat β FinBddDistLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents (fun X => Iso.mk (Ξ± := X) <| OrderIso.dualDual X)
counitIso := NatIso.ofComponents (fun X => Iso.mk <| OrderIso.dualDual X)
end FinBddDistLat
theorem finBddDistLat_dual_comp_forget_to_bddDistLat :
FinBddDistLat.dual β forgetβ FinBddDistLat BddDistLat =
forgetβ FinBddDistLat BddDistLat β BddDistLat.dual :=
rfl
|
Filter.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.Order.Filter.Lift
import Mathlib.Order.Interval.Set.Monotone
import Mathlib.Topology.Separation.Basic
/-!
# Topology on the set of filters on a type
This file introduces a topology on `Filter Ξ±`. It is generated by the sets
`Set.Iic (π s) = {l : Filter Ξ± | s β l}`, `s : Set Ξ±`. A set `s : Set (Filter Ξ±)` is open if and
only if it is a union of a family of these basic open sets, see `Filter.isOpen_iff`.
This topology has the following important properties.
* If `X` is a topological space, then the map `π : X β Filter X` is a topology inducing map.
* In particular, it is a continuous map, so `π β f` tends to `π (π a)` whenever `f` tends to `π a`.
* If `X` is an ordered topological space with order topology and no max element, then `π β f` tends
to `π Filter.atTop` whenever `f` tends to `Filter.atTop`.
* It turns `Filter X` into a Tβ space and the order on `Filter X` is the dual of the
`specializationOrder (Filter X)`.
## Tags
filter, topological space
-/
open Set Filter TopologicalSpace
open Filter Topology
variable {ΞΉ : Sort*} {Ξ± Ξ² X Y : Type*}
namespace Filter
/-- The topology on `Filter Ξ±` is generated by the sets `Set.Iic (π s) = {l : Filter Ξ± | s β l}`,
`s : Set Ξ±`. A set `s : Set (Filter Ξ±)` is open if and only if it is a union of a family of these
basic open sets, see `Filter.isOpen_iff`. -/
instance : TopologicalSpace (Filter Ξ±) :=
generateFrom <| range <| Iic β π
theorem isOpen_Iic_principal {s : Set Ξ±} : IsOpen (Iic (π s)) :=
GenerateOpen.basic _ (mem_range_self _)
theorem isOpen_setOf_mem {s : Set Ξ±} : IsOpen { l : Filter Ξ± | s β l } := by
simpa only [Iic_principal] using isOpen_Iic_principal
theorem isTopologicalBasis_Iic_principal :
IsTopologicalBasis (range (Iic β π : Set Ξ± β Set (Filter Ξ±))) :=
{ exists_subset_inter := by
rintro _ β¨s, rflβ© _ β¨t, rflβ© l hl
exact β¨Iic (π s) β© Iic (π t), β¨s β© t, by simpβ©, hl, Subset.rflβ©
sUnion_eq := sUnion_eq_univ_iff.2 fun _ => β¨Iic β€, β¨univ, congr_arg Iic principal_univβ©,
mem_Iic.2 le_topβ©
eq_generateFrom := rfl }
theorem isOpen_iff {s : Set (Filter Ξ±)} : IsOpen s β β T : Set (Set Ξ±), s = β t β T, Iic (π t) :=
isTopologicalBasis_Iic_principal.open_iff_eq_sUnion.trans <| by
simp only [exists_subset_range_and_iff, sUnion_image, (Β· β Β·)]
theorem nhds_eq (l : Filter Ξ±) : π l = l.lift' (Iic β π) :=
nhds_generateFrom.trans <| by
simp only [mem_setOf_eq, @and_comm (l β _), iInf_and, iInf_range, Filter.lift', Filter.lift,
(Β· β Β·), mem_Iic, le_principal_iff]
theorem nhds_eq' (l : Filter Ξ±) : π l = l.lift' fun s => { l' | s β l' } := by
simpa only [Function.comp_def, Iic_principal] using nhds_eq l
protected theorem tendsto_nhds {la : Filter Ξ±} {lb : Filter Ξ²} {f : Ξ± β Filter Ξ²} :
Tendsto f la (π lb) β β s β lb, βαΆ a in la, s β f a := by
simp only [nhds_eq', tendsto_lift', mem_setOf_eq]
protected theorem HasBasis.nhds {l : Filter Ξ±} {p : ΞΉ β Prop} {s : ΞΉ β Set Ξ±} (h : HasBasis l p s) :
HasBasis (π l) p fun i => Iic (π (s i)) := by
rw [nhds_eq]
exact h.lift' monotone_principal.Iic
protected theorem tendsto_pure_self (l : Filter X) :
Tendsto (pure : X β Filter X) l (π l) := by
rw [Filter.tendsto_nhds]
exact fun s hs β¦ Eventually.mono hs fun x β¦ id
/-- Neighborhoods of a countably generated filter is a countably generated filter. -/
instance {l : Filter Ξ±} [IsCountablyGenerated l] : IsCountablyGenerated (π l) :=
let β¨_b, hbβ© := l.exists_antitone_basis
HasCountableBasis.isCountablyGenerated <| β¨hb.nhds, Set.to_countable _β©
theorem HasBasis.nhds' {l : Filter Ξ±} {p : ΞΉ β Prop} {s : ΞΉ β Set Ξ±} (h : HasBasis l p s) :
HasBasis (π l) p fun i => { l' | s i β l' } := by simpa only [Iic_principal] using h.nhds
protected theorem mem_nhds_iff {l : Filter Ξ±} {S : Set (Filter Ξ±)} :
S β π l β β t β l, Iic (π t) β S :=
l.basis_sets.nhds.mem_iff
theorem mem_nhds_iff' {l : Filter Ξ±} {S : Set (Filter Ξ±)} :
S β π l β β t β l, β β¦l' : Filter Ξ±β¦, t β l' β l' β S :=
l.basis_sets.nhds'.mem_iff
@[simp]
theorem nhds_bot : π (β₯ : Filter Ξ±) = pure β₯ := by
simp [nhds_eq, Function.comp_def, lift'_bot monotone_principal.Iic]
@[simp]
theorem nhds_top : π (β€ : Filter Ξ±) = β€ := by simp [nhds_eq]
@[simp]
theorem nhds_principal (s : Set Ξ±) : π (π s) = π (Iic (π s)) :=
(hasBasis_principal s).nhds.eq_of_same_basis (hasBasis_principal _)
@[simp]
theorem nhds_pure (x : Ξ±) : π (pure x : Filter Ξ±) = π {β₯, pure x} := by
rw [β principal_singleton, nhds_principal, principal_singleton, Iic_pure]
@[simp]
protected theorem nhds_iInf (f : ΞΉ β Filter Ξ±) : π (β¨
i, f i) = β¨
i, π (f i) := by
simp only [nhds_eq]
apply lift'_iInf_of_map_univ <;> simp
@[simp]
protected theorem nhds_inf (lβ lβ : Filter Ξ±) : π (lβ β lβ) = π lβ β π lβ := by
simpa only [iInf_bool_eq] using Filter.nhds_iInf fun b => cond b lβ lβ
theorem monotone_nhds : Monotone (π : Filter Ξ± β Filter (Filter Ξ±)) :=
Monotone.of_map_inf Filter.nhds_inf
theorem sInter_nhds (l : Filter Ξ±) : ββ { s | s β π l } = Iic l := by
simp_rw [nhds_eq, Function.comp_def, sInter_lift'_sets monotone_principal.Iic, Iic,
le_principal_iff, β setOf_forall, β Filter.le_def]
@[simp]
theorem nhds_mono {lβ lβ : Filter Ξ±} : π lβ β€ π lβ β lβ β€ lβ := by
refine β¨fun h => ?_, fun h => monotone_nhds hβ©
rw [β Iic_subset_Iic, β sInter_nhds, β sInter_nhds]
exact sInter_subset_sInter h
protected theorem mem_interior {s : Set (Filter Ξ±)} {l : Filter Ξ±} :
l β interior s β β t β l, Iic (π t) β s := by
rw [mem_interior_iff_mem_nhds, Filter.mem_nhds_iff]
protected theorem mem_closure {s : Set (Filter Ξ±)} {l : Filter Ξ±} :
l β closure s β β t β l, β l' β s, t β l' := by
simp only [closure_eq_compl_interior_compl, Filter.mem_interior, mem_compl_iff, not_exists,
not_forall, Classical.not_not, exists_prop, not_and, and_comm, subset_def, mem_Iic,
le_principal_iff]
@[simp]
protected theorem closure_singleton (l : Filter Ξ±) : closure {l} = Ici l := by
ext l'
simp [Filter.mem_closure, Filter.le_def]
@[simp]
theorem specializes_iff_le {lβ lβ : Filter Ξ±} : lβ β€³ lβ β lβ β€ lβ := by
simp only [specializes_iff_closure_subset, Filter.closure_singleton, Ici_subset_Ici]
instance : T0Space (Filter Ξ±) :=
β¨fun _ _ h => (specializes_iff_le.1 h.specializes).antisymm
(specializes_iff_le.1 h.symm.specializes)β©
theorem nhds_atTop [Preorder Ξ±] : π atTop = β¨
x : Ξ±, π (Iic (π (Ici x))) := by
simp only [atTop, Filter.nhds_iInf, nhds_principal]
protected theorem tendsto_nhds_atTop_iff [Preorder Ξ²] {l : Filter Ξ±} {f : Ξ± β Filter Ξ²} :
Tendsto f l (π atTop) β β y, βαΆ a in l, Ici y β f a := by
simp only [nhds_atTop, tendsto_iInf, tendsto_principal, mem_Iic, le_principal_iff]
theorem nhds_atBot [Preorder Ξ±] : π atBot = β¨
x : Ξ±, π (Iic (π (Iic x))) :=
@nhds_atTop Ξ±α΅α΅ _
protected theorem tendsto_nhds_atBot_iff [Preorder Ξ²] {l : Filter Ξ±} {f : Ξ± β Filter Ξ²} :
Tendsto f l (π atBot) β β y, βαΆ a in l, Iic y β f a :=
@Filter.tendsto_nhds_atTop_iff Ξ± Ξ²α΅α΅ _ _ _
variable [TopologicalSpace X]
theorem nhds_nhds (x : X) :
π (π x) = β¨
(s : Set X) (_ : IsOpen s) (_ : x β s), π (Iic (π s)) := by
simp only [(nhds_basis_opens x).nhds.eq_biInf, iInf_and, @iInf_comm _ (_ β _)]
theorem isInducing_nhds : IsInducing (π : X β Filter X) :=
isInducing_iff_nhds.2 fun x =>
(nhds_def' _).trans <| by
simp +contextual only [nhds_nhds, comap_iInf, comap_principal,
Iic_principal, preimage_setOf_eq, β mem_interior_iff_mem_nhds, setOf_mem_eq,
IsOpen.interior_eq]
@[continuity]
theorem continuous_nhds : Continuous (π : X β Filter X) :=
isInducing_nhds.continuous
protected theorem Tendsto.nhds {f : Ξ± β X} {l : Filter Ξ±} {x : X} (h : Tendsto f l (π x)) :
Tendsto (π β f) l (π (π x)) :=
(continuous_nhds.tendsto _).comp h
end Filter
variable [TopologicalSpace X] [TopologicalSpace Y] {f : X β Y} {x : X} {s : Set X}
protected nonrec theorem ContinuousWithinAt.nhds (h : ContinuousWithinAt f s x) :
ContinuousWithinAt (π β f) s x :=
h.nhds
protected nonrec theorem ContinuousAt.nhds (h : ContinuousAt f x) : ContinuousAt (π β f) x :=
h.nhds
protected nonrec theorem ContinuousOn.nhds (h : ContinuousOn f s) : ContinuousOn (π β f) s :=
fun x hx => (h x hx).nhds
protected nonrec theorem Continuous.nhds (h : Continuous f) : Continuous (π β f) :=
Filter.continuous_nhds.comp h
|
Wronskian.lean
|
/-
Copyright (c) 2024 Jineon Baek and Seewoo Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jineon Baek, Seewoo Lee
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Algebra.Polynomial.Derivative
import Mathlib.LinearAlgebra.SesquilinearForm
import Mathlib.RingTheory.Coprime.Basic
/-!
# Wronskian of a pair of polynomial
This file defines Wronskian of a pair of polynomials, which is `W(a, b) = ab' - a'b`.
We also prove basic properties of it.
## Main declarations
- `Polynomial.wronskian_eq_of_sum_zero`: We have `W(a, b) = W(b, c)` when `a + b + c = 0`.
- `Polynomial.degree_wronskian_lt_add`: Degree of Wronskian `W(a, b)` is strictly smaller than
the sum of degrees of `a` and `b`
- `Polynomial.natDegree_wronskian_lt_add`: `natDegree` version of the above theorem.
We need to assume that the Wronskian is nonzero. (Otherwise, `a = b = 1` gives a counterexample.)
## TODO
- Define Wronskian for n-tuple of polynomials, not necessarily two.
-/
noncomputable section
open scoped Polynomial
namespace Polynomial
variable {R : Type*} [CommRing R]
/-- Wronskian of a pair of polynomials, `W(a, b) = ab' - a'b`. -/
def wronskian (a b : R[X]) : R[X] :=
a * (derivative b) - (derivative a) * b
variable (R) in
/-- `Polynomial.wronskian` as a bilinear map. -/
def wronskianBilin : R[X] ββ[R] R[X] ββ[R] R[X] :=
(LinearMap.mul R R[X]).complβ derivative - (LinearMap.mul R R[X]).comp derivative
@[simp]
theorem wronskianBilin_apply (a b : R[X]) : wronskianBilin R a b = wronskian a b := rfl
@[simp]
theorem wronskian_zero_left (a : R[X]) : wronskian 0 a = 0 := by
rw [β wronskianBilin_apply 0 a, map_zero]; rfl
@[simp]
theorem wronskian_zero_right (a : R[X]) : wronskian a 0 = 0 := (wronskianBilin R a).map_zero
theorem wronskian_neg_left (a b : R[X]) : wronskian (-a) b = -wronskian a b :=
LinearMap.map_negβ (wronskianBilin R) a b
theorem wronskian_neg_right (a b : R[X]) : wronskian a (-b) = -wronskian a b :=
(wronskianBilin R a).map_neg b
theorem wronskian_add_right (a b c : R[X]) : wronskian a (b + c) = wronskian a b + wronskian a c :=
(wronskianBilin R a).map_add b c
theorem wronskian_add_left (a b c : R[X]) : wronskian (a + b) c = wronskian a c + wronskian b c :=
(wronskianBilin R).map_addβ a b c
theorem wronskian_self_eq_zero (a : R[X]) : wronskian a a = 0 := by
rw [wronskian, mul_comm, sub_self]
theorem isAlt_wronskianBilin : (wronskianBilin R).IsAlt := wronskian_self_eq_zero
theorem wronskian_neg_eq (a b : R[X]) : -wronskian a b = wronskian b a :=
LinearMap.IsAlt.neg isAlt_wronskianBilin a b
theorem wronskian_eq_of_sum_zero {a b c : R[X]} (hAdd : a + b + c = 0) :
wronskian a b = wronskian b c := isAlt_wronskianBilin.eq_of_add_add_eq_zero hAdd
/-- Degree of `W(a,b)` is strictly less than the sum of degrees of `a` and `b` (both nonzero). -/
theorem degree_wronskian_lt_add {a b : R[X]} (ha : a β 0) (hb : b β 0) :
(wronskian a b).degree < a.degree + b.degree := by
calc
(wronskian a b).degree β€ max (a * derivative b).degree (derivative a * b).degree :=
Polynomial.degree_sub_le _ _
_ < a.degree + b.degree := by
rw [max_lt_iff]
constructor
case left =>
apply lt_of_le_of_lt
Β· exact degree_mul_le a (derivative b)
Β· rw [β Polynomial.degree_ne_bot] at ha
rw [WithBot.add_lt_add_iff_left ha]
exact Polynomial.degree_derivative_lt hb
case right =>
apply lt_of_le_of_lt
Β· exact degree_mul_le (derivative a) b
Β· rw [β Polynomial.degree_ne_bot] at hb
rw [WithBot.add_lt_add_iff_right hb]
exact Polynomial.degree_derivative_lt ha
/--
`natDegree` version of the above theorem.
Note this would be false with just `(ha : a β 0) (hb : b β 0),
as when `a = b = 1` we have `(wronskian a b).natDegree = a.natDegree = b.natDegree = 0`.
-/
theorem natDegree_wronskian_lt_add {a b : R[X]} (hw : wronskian a b β 0) :
(wronskian a b).natDegree < a.natDegree + b.natDegree := by
have ha : a β 0 := by intro h; subst h; rw [wronskian_zero_left] at hw; exact hw rfl
have hb : b β 0 := by intro h; subst h; rw [wronskian_zero_right] at hw; exact hw rfl
rw [β WithBot.coe_lt_coe, WithBot.coe_add]
convert β degree_wronskian_lt_add ha hb
Β· exact Polynomial.degree_eq_natDegree hw
Β· exact Polynomial.degree_eq_natDegree ha
Β· exact Polynomial.degree_eq_natDegree hb
/--
For coprime polynomials `a` and `b`, their Wronskian is zero
if and only if their derivatives are zeros.
-/
theorem _root_.IsCoprime.wronskian_eq_zero_iff
[NoZeroDivisors R] {a b : R[X]} (hc : IsCoprime a b) :
wronskian a b = 0 β derivative a = 0 β§ derivative b = 0 where
mp hw := by
rw [wronskian, sub_eq_iff_eq_add, zero_add] at hw
constructor
Β· rw [β dvd_derivative_iff]
apply hc.dvd_of_dvd_mul_right
rw [β hw]; exact dvd_mul_right _ _
Β· rw [β dvd_derivative_iff]
apply hc.symm.dvd_of_dvd_mul_left
rw [hw]; exact dvd_mul_left _ _
mpr hdab := by
obtain β¨hda, hdbβ© := hdab
rw [wronskian]
rw [hda, hdb]; simp only [MulZeroClass.mul_zero, MulZeroClass.zero_mul, sub_self]
end Polynomial
|
Projection.lean
|
import Mathlib.Analysis.InnerProductSpace.Projection.Basic
import Mathlib.Analysis.InnerProductSpace.Projection.FiniteDimensional
import Mathlib.Analysis.InnerProductSpace.Projection.Minimal
import Mathlib.Analysis.InnerProductSpace.Projection.Reflection
import Mathlib.Analysis.InnerProductSpace.Projection.Submodule
deprecated_module (since := "2025-08-08")
|
orderedzmod.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 ssrAC div fintype path bigop order finset fingroup.
From mathcomp Require Import ssralg poly.
(******************************************************************************)
(* Number structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines some classes to manipulate number structures, i.e, *)
(* structures with an order and a norm. To use this file, insert *)
(* "Import Num.Theory." before your scripts. You can also "Import Num.Def." *)
(* to enjoy shorter notations (e.g., minr instead of Num.min, lerif instead *)
(* of Num.leif, etc.). *)
(* *)
(* This file defines the following number structures: *)
(* *)
(* porderZmodType == join of Order.POrder and GRing.Zmodule *)
(* The HB class is called POrderedZmodule. *)
(* *)
(* The ordering symbols and notations (<, <=, >, >=, _ <= _ ?= iff _, *)
(* _ < _ ?<= if _, >=<, and ><) and lattice operations (meet and join) *)
(* defined in order.v are redefined for the ring_display in the ring_scope *)
(* (%R). 0-ary ordering symbols for the ring_display have the suffix "%R", *)
(* e.g., <%R. All the other ordering notations are the same as order.v. *)
(* *)
(* Over these structures, we have the following operations: *)
(* x \is a Num.pos <=> x is positive (:= x > 0) *)
(* x \is a Num.neg <=> x is negative (:= x < 0) *)
(* x \is a Num.nneg <=> x is positive or 0 (:= x >= 0) *)
(* x \is a Num.npos <=> x is negative or 0 (:= x <= 0) *)
(* x \is a Num.real <=> x is real (:= x >= 0 or x < 0) *)
(* *)
(* - list of prefixes : *)
(* p : positive *)
(* n : negative *)
(* sp : strictly positive *)
(* sn : strictly negative *)
(* i : interior = in [0, 1] or ]0, 1[ *)
(* e : exterior = in [1, +oo[ or ]1; +oo[ *)
(* w : non strict (weak) monotony *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "n .-root" (format "n .-root").
Reserved Notation "'i".
Reserved Notation "'Re z" (at level 10, z at level 8).
Reserved Notation "'Im z" (at level 10, z at level 8).
Local Open Scope order_scope.
Local Open Scope group_scope.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory.
Fact ring_display : Order.disp_t. Proof. exact. Qed.
Module Num.
#[short(type="porderZmodType")]
HB.structure Definition POrderedZmodule :=
{ R of Order.isPOrder ring_display R & GRing.Zmodule R }.
Module Export Def.
Notation ler := (@Order.le ring_display _) (only parsing).
Notation "@ 'ler' R" := (@Order.le ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation ltr := (@Order.lt ring_display _) (only parsing).
Notation "@ 'ltr' R" := (@Order.lt ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation ger := (@Order.ge ring_display _) (only parsing).
Notation "@ 'ger' R" := (@Order.ge ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation gtr := (@Order.gt ring_display _) (only parsing).
Notation "@ 'gtr' R" := (@Order.gt ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation lerif := (@Order.leif ring_display _) (only parsing).
Notation "@ 'lerif' R" := (@Order.leif ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation lterif := (@Order.lteif ring_display _) (only parsing).
Notation "@ 'lteif' R" := (@Order.lteif ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation comparabler := (@Order.comparable ring_display _) (only parsing).
Notation "@ 'comparabler' R" := (@Order.comparable ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation maxr := (@Order.max ring_display _).
Notation "@ 'maxr' R" := (@Order.max ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Notation minr := (@Order.min ring_display _).
Notation "@ 'minr' R" := (@Order.min ring_display R)
(at level 10, R at level 8, only parsing) : function_scope.
Section Def.
Context {R : porderZmodType}.
Definition Rpos_pred := fun x : R => 0 < x.
Definition Rpos : qualifier 0 R := [qualify x | Rpos_pred x].
Definition Rneg_pred := fun x : R => x < 0.
Definition Rneg : qualifier 0 R := [qualify x : R | Rneg_pred x].
Definition Rnneg_pred := fun x : R => 0 <= x.
Definition Rnneg : qualifier 0 R := [qualify x : R | Rnneg_pred x].
Definition Rnpos_pred := fun x : R => x <= 0.
Definition Rnpos : qualifier 0 R := [qualify x : R | Rnpos_pred x].
Definition Rreal_pred := fun x : R => (0 <= x) || (x <= 0).
Definition Rreal : qualifier 0 R := [qualify x : R | Rreal_pred x].
End Def.
Arguments Rpos_pred _ _ /.
Arguments Rneg_pred _ _ /.
Arguments Rnneg_pred _ _ /.
Arguments Rreal_pred _ _ /.
End Def.
(* Shorter qualified names, when Num.Def is not imported. *)
Notation le := ler (only parsing).
Notation lt := ltr (only parsing).
Notation ge := ger (only parsing).
Notation gt := gtr (only parsing).
Notation leif := lerif (only parsing).
Notation lteif := lterif (only parsing).
Notation comparable := comparabler (only parsing).
Notation max := maxr.
Notation min := minr.
Notation pos := Rpos.
Notation neg := Rneg.
Notation nneg := Rnneg.
Notation npos := Rnpos.
Notation real := Rreal.
(* (Exported) symbolic syntax. *)
Module Import Syntax.
Notation "<=%R" := le : function_scope.
Notation ">=%R" := ge : function_scope.
Notation "<%R" := lt : function_scope.
Notation ">%R" := gt : function_scope.
Notation "<?=%R" := leif : function_scope.
Notation "<?<=%R" := lteif : function_scope.
Notation ">=<%R" := comparable : function_scope.
Notation "><%R" := (fun x y => ~~ (comparable x y)) : function_scope.
Notation "<= y" := (ge y) : ring_scope.
Notation "<= y :> T" := (<= (y : T)) (only parsing) : ring_scope.
Notation ">= y" := (le y) : ring_scope.
Notation ">= y :> T" := (>= (y : T)) (only parsing) : ring_scope.
Notation "< y" := (gt y) : ring_scope.
Notation "< y :> T" := (< (y : T)) (only parsing) : ring_scope.
Notation "> y" := (lt y) : ring_scope.
Notation "> y :> T" := (> (y : T)) (only parsing) : ring_scope.
Notation "x <= y" := (le x y) : ring_scope.
Notation "x <= y :> T" := ((x : T) <= (y : T)) (only parsing) : ring_scope.
Notation "x >= y" := (y <= x) (only parsing) : ring_scope.
Notation "x >= y :> T" := ((x : T) >= (y : T)) (only parsing) : ring_scope.
Notation "x < y" := (lt x y) : ring_scope.
Notation "x < y :> T" := ((x : T) < (y : T)) (only parsing) : ring_scope.
Notation "x > y" := (y < x) (only parsing) : ring_scope.
Notation "x > y :> T" := ((x : T) > (y : T)) (only parsing) : ring_scope.
Notation "x <= y <= z" := ((x <= y) && (y <= z)) : ring_scope.
Notation "x < y <= z" := ((x < y) && (y <= z)) : ring_scope.
Notation "x <= y < z" := ((x <= y) && (y < z)) : ring_scope.
Notation "x < y < z" := ((x < y) && (y < z)) : ring_scope.
Notation "x <= y ?= 'iff' C" := (lerif x y C) : ring_scope.
Notation "x <= y ?= 'iff' C :> R" := ((x : R) <= (y : R) ?= iff C)
(only parsing) : ring_scope.
Notation "x < y ?<= 'if' C" := (lterif x y C) : ring_scope.
Notation "x < y ?<= 'if' C :> R" := ((x : R) < (y : R) ?<= if C)
(only parsing) : ring_scope.
Notation ">=< y" := [pred x | comparable x y] : ring_scope.
Notation ">=< y :> T" := (>=< (y : T)) (only parsing) : ring_scope.
Notation "x >=< y" := (comparable x y) : ring_scope.
Notation ">< y" := [pred x | ~~ comparable x y] : ring_scope.
Notation ">< y :> T" := (>< (y : T)) (only parsing) : ring_scope.
Notation "x >< y" := (~~ (comparable x y)) : ring_scope.
Export Order.PreOCoercions.
End Syntax.
Module Export Theory.
End Theory.
Module Exports. HB.reexport. End Exports.
End Num.
Export Num.Syntax Num.Exports.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.