filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
falgebra.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 path.
From mathcomp Require Import choice fintype div tuple finfun bigop ssralg.
From mathcomp Require Import finalg zmodp matrix vector poly.
(******************************************************************************)
(* Finite dimensional free algebras, usually known as F-algebras *)
(* *)
(* falgType K == the interface type for F-algebras over K; it simply *)
(* joins the unitAlgType K and vectType K interfaces *)
(* The HB class is called Falgebra. *)
(* Any aT with an falgType structure inherits all the Vector, NzRing and *)
(* Algebra operations, and supports the following additional operations: *)
(* \dim_A M == (\dim M %/ dim A)%N -- free module dimension *)
(* amull u == the linear function v |-> u * v, for u, v : aT *)
(* amulr u == the linear function v |-> v * u, for u, v : aT *)
(* 1, f * g, f ^+ n == the identity function, the composite g \o f, the nth *)
(* iterate of f, for 1, f, g in 'End(aT) *)
(* This is just the usual F-algebra structure on *)
(* 'End(aT). It is NOT canonical by default, but can be *)
(* activated by the line Import FalgLfun. Beware also *)
(* that (f^-1)%VF is the linear function inverse, not *)
(* the ring inverse of f (though they do coincide when *)
(* f is injective). *)
(* 1%VS == the line generated by 1 : aT *)
(* (U * V)%VS == the smallest subspace of aT that contains all *)
(* products u * v for u in U, v in V *)
(* (U ^+ n)%VS == (U * U * ... * U), n-times. U ^+ 0 = 1%VS *)
(* 'C[u]%VS == the centraliser subspace of the vector u *)
(* 'C_U[v]%VS := (U :&: 'C[v])%VS *)
(* 'C(V)%VS == the centraliser subspace of the subspace V *)
(* 'C_U(V)%VS := (U :&: 'C(V))%VS *)
(* 'Z(V)%VS == the center subspace of the subspace V *)
(* agenv U == the smallest subalgebra containing U ^+ n for all n *)
(* <<U; v>>%VS == agenv (U + <[v]>) (adjoin v to U) *)
(* <<U & vs>>%VS == agenv (U + <<vs>>) (adjoin vs to U) *)
(* {aspace aT} == a subType of {vspace aT} consisting of sub-algebras *)
(* of aT (see below); for A : {aspace aT}, subvs_of A *)
(* has a canonical falgType K structure *)
(* is_aspace U <=> the characteristic predicate of {aspace aT} stating *)
(* that U is closed under product and contains an *)
(* identity element, := has_algid U && (U * U <= U)%VS *)
(* algid A == the identity element of A : {aspace aT}, which need *)
(* not be equal to 1 (indeed, in a Wedderburn *)
(* decomposition it is not even a unit in aT) *)
(* is_algid U e <-> e : aT is an identity element for the subspace U: *)
(* e in U, e != 0 & e * u = u * e = u for all u in U *)
(* has_algid U <=> there is an e such that is_algid U e *)
(* [aspace of U] == a clone of an existing {aspace aT} structure on *)
(* U : {vspace aT} (more instances of {aspace aT} will *)
(* be defined in extFieldType) *)
(* [aspace of U for A] == a clone of A : {aspace aT} for U : {vspace aT} *)
(* 1%AS == the canonical sub-algebra 1%VS *)
(* {:aT}%AS == the canonical full algebra *)
(* <<U>>%AS == the canonical algebra for agenv U; note that this is *)
(* unrelated to <<vs>>%VS, the subspace spanned by vs *)
(* <<U; v>>%AS == the canonical algebra for <<U; v>>%VS *)
(* <<U & vs>>%AS == the canonical algebra for <<U & vs>>%VS *)
(* ahom_in U f <=> f : 'Hom(aT, rT) is a multiplicative homomorphism *)
(* inside U, and in addition f 1 = 1 (even if U doesn't *)
(* contain 1) *)
(* Note that f @: U need not be a subalgebra when U is, *)
(* as f could annilate U. *)
(* 'AHom(aT, rT) == the type of algebra homomorphisms from aT to rT, *)
(* where aT and rT ARE falgType structures. Elements of *)
(* 'AHom(aT, rT) coerce to 'End(aT, rT) and aT -> rT *)
(* 'AEnd(aT) == algebra endomorphisms of aT (:= 'AHom(aT, aT)) *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope aspace_scope.
Declare Scope lrfun_scope.
Local Open Scope ring_scope.
Reserved Notation "{ 'aspace' T }" (format "{ 'aspace' T }").
Reserved Notation "<< U & vs >>" (format "<< U & vs >>").
Reserved Notation "<< U ; x >>" (format "<< U ; x >>").
Reserved Notation "''AHom' ( T , rT )" (format "''AHom' ( T , rT )").
Reserved Notation "''AEnd' ( T )" (format "''AEnd' ( T )").
Notation "\dim_ E V" := (divn (\dim V) (\dim E))
(at level 10, E at level 2, V at level 8, format "\dim_ E V") : nat_scope.
Import GRing.Theory.
(* Finite dimensional algebra *)
#[short(type="falgType")]
HB.structure Definition Falgebra (R : nzRingType) :=
{ A of Vector R A & GRing.UnitAlgebra R A }.
#[deprecated(since="mathcomp 2.0.0", note="Use falgType instead.")]
Notation FalgType := falgType.
(* Supply a default unitRing mixin for the default unitAlgType base type. *)
HB.factory Record Algebra_isFalgebra (K : fieldType) A
of Vector K A & GRing.Algebra K A := {}.
HB.builders Context K A of Algebra_isFalgebra K A.
Let vA : Vector.type K := A.
Let am u := linfun (u \o* idfun : vA -> vA).
Let uam := [pred u | lker (am u) == 0%VS].
Let vam := [fun u => if u \in uam then (am u)^-1%VF 1 else u].
Lemma amE u v : am u v = v * u. Proof. by rewrite lfunE. Qed.
Lemma mulVr : {in uam, left_inverse 1 vam *%R}.
Proof. by move=> u Uu; rewrite /= Uu -amE lker0_lfunVK. Qed.
Lemma divrr : {in uam, right_inverse 1 vam *%R}.
Proof.
by move=> u Uu; apply/(lker0P Uu); rewrite !amE -mulrA mulVr // mul1r mulr1.
Qed.
Lemma unitrP : forall x y, y * x = 1 /\ x * y = 1 -> uam x.
Proof.
move=> u v [_ uv1].
by apply/lker0P=> w1 w2 /(congr1 (am v)); rewrite !amE -!mulrA uv1 !mulr1.
Qed.
Lemma invr_out : {in [predC uam], vam =1 id}.
Proof. by move=> u /negbTE/= ->. Qed.
HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build A
mulVr divrr unitrP invr_out.
HB.end.
Module FalgebraExports.
Bind Scope ring_scope with sort.
End FalgebraExports.
HB.export FalgebraExports.
Notation "1" := (vline 1) : vspace_scope.
HB.instance Definition _ (K : fieldType) n :=
Algebra_isFalgebra.Build K 'M[K]_n.+1.
HB.instance Definition _ (R : comUnitRingType) := GRing.UnitAlgebra.on R^o.
(* FIXME: remove once https://github.com/math-comp/hierarchy-builder/issues/197
is fixed *)
Lemma regular_fullv (K : fieldType) : (fullv = 1 :> {vspace K^o})%VS.
Proof. by apply/esym/eqP; rewrite eqEdim subvf dim_vline oner_eq0 dimvf. Qed.
Section Proper.
Variables (R : nzRingType) (aT : falgType R).
Import VectorInternalTheory.
Lemma FalgType_proper : dim aT > 0.
Proof.
rewrite lt0n; apply: contraNneq (oner_neq0 aT) => aT0.
by apply/eqP/v2r_inj; do 2!move: (v2r _); rewrite aT0 => u v; rewrite !thinmx0.
Qed.
End Proper.
Module FalgLfun.
Section FalgLfun.
Variable (R : comNzRingType) (aT : falgType R).
Implicit Types f g : 'End(aT).
HB.instance Definition _ := GRing.Algebra.copy 'End(aT)
(lfun_algType (FalgType_proper aT)).
Lemma lfun_mulE f g u : (f * g) u = g (f u). Proof. exact: lfunE. Qed.
Lemma lfun_compE f g : (g \o f)%VF = f * g. Proof. by []. Qed.
End FalgLfun.
Section InvLfun.
Variable (K : fieldType) (aT : falgType K).
Implicit Types f g : 'End(aT).
Definition lfun_invr f := if lker f == 0%VS then f^-1%VF else f.
Lemma lfun_mulVr f : lker f == 0%VS -> f^-1%VF * f = 1.
Proof. exact: lker0_compfV. Qed.
Lemma lfun_mulrV f : lker f == 0%VS -> f * f^-1%VF = 1.
Proof. exact: lker0_compVf. Qed.
Fact lfun_mulRVr f : lker f == 0%VS -> lfun_invr f * f = 1.
Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulVr. Qed.
Fact lfun_mulrRV f : lker f == 0%VS -> f * lfun_invr f = 1.
Proof. by move=> Uf; rewrite /lfun_invr Uf lfun_mulrV. Qed.
Fact lfun_unitrP f g : g * f = 1 /\ f * g = 1 -> lker f == 0%VS.
Proof.
case=> _ fK; apply/lker0P; apply: can_inj (g) _ => u.
by rewrite -lfun_mulE fK lfunE.
Qed.
Lemma lfun_invr_out f : lker f != 0%VS -> lfun_invr f = f.
Proof. by rewrite /lfun_invr => /negPf->. Qed.
HB.instance Definition _ := GRing.NzRing_hasMulInverse.Build 'End(aT)
lfun_mulRVr lfun_mulrRV lfun_unitrP lfun_invr_out.
Lemma lfun_invE f : lker f == 0%VS -> f^-1%VF = f^-1.
Proof. by rewrite /f^-1 /= /lfun_invr => ->. Qed.
End InvLfun.
End FalgLfun.
Section FalgebraTheory.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v : aT) (U V W : {vspace aT}).
Import FalgLfun.
Definition amull u : 'End(aT) := linfun (u \*o @idfun aT).
Definition amulr u : 'End(aT) := linfun (u \o* @idfun aT).
Lemma amull_inj : injective amull.
Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mulr1. Qed.
Lemma amulr_inj : injective amulr.
Proof. by move=> u v /lfunP/(_ 1); rewrite !lfunE /= !mul1r. Qed.
Fact amull_is_linear : linear amull.
Proof.
move=> a u v; apply/lfunP => w.
by rewrite !lfunE /= scale_lfunE !lfunE /= mulrDl scalerAl.
Qed.
#[hnf]
HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amull
(GRing.semilinear_linear amull_is_linear).
(* amull is a converse ring morphism *)
Lemma amull1 : amull 1 = \1%VF.
Proof. by apply/lfunP => z; rewrite id_lfunE lfunE /= mul1r. Qed.
Lemma amullM u v : (amull (u * v) = amull v * amull u)%VF.
Proof. by apply/lfunP => w; rewrite comp_lfunE !lfunE /= mulrA. Qed.
Lemma amulr_is_linear : linear amulr.
Proof.
move=> a u v; apply/lfunP => w.
by rewrite !lfunE /= !lfunE /= lfunE mulrDr /= scalerAr.
Qed.
Lemma amulr_is_monoid_morphism : monoid_morphism amulr.
Proof.
split=> [|x y]; first by apply/lfunP => w; rewrite id_lfunE !lfunE /= mulr1.
by apply/lfunP=> w; rewrite comp_lfunE !lfunE /= mulrA.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `amulr_is_monoid_morphism` instead")]
Definition amulr_is_multiplicative :=
(fun p => (p.2, p.1)) amulr_is_monoid_morphism.
#[hnf]
HB.instance Definition _ := GRing.isSemilinear.Build K aT (hom aT aT) _ amulr
(GRing.semilinear_linear amulr_is_linear).
#[hnf]
HB.instance Definition _ := GRing.isMonoidMorphism.Build aT (hom aT aT) amulr
amulr_is_monoid_morphism.
Lemma lker0_amull u : u \is a GRing.unit -> lker (amull u) == 0%VS.
Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulrI. Qed.
Lemma lker0_amulr u : u \is a GRing.unit -> lker (amulr u) == 0%VS.
Proof. by move=> Uu; apply/lker0P=> v w; rewrite !lfunE; apply: mulIr. Qed.
Lemma lfun1_poly (p : {poly aT}) : map_poly \1%VF p = p.
Proof. by apply: map_poly_id => u _; apply: id_lfunE. Qed.
Fact prodv_key : unit. Proof. by []. Qed.
Definition prodv :=
locked_with prodv_key (fun U V => <<allpairs *%R (vbasis U) (vbasis V)>>%VS).
Canonical prodv_unlockable := [unlockable fun prodv].
Local Notation "A * B" := (prodv A B) : vspace_scope.
Lemma memv_mul U V : {in U & V, forall u v, u * v \in (U * V)%VS}.
Proof.
move=> u v /coord_vbasis-> /coord_vbasis->.
rewrite mulr_suml; apply: memv_suml => i _.
rewrite mulr_sumr; apply: memv_suml => j _.
rewrite -scalerAl -scalerAr !memvZ // [prodv]unlock memv_span //.
by apply/allpairsP; exists ((vbasis U)`_i, (vbasis V)`_j); rewrite !memt_nth.
Qed.
Lemma prodvP {U V W} :
reflect {in U & V, forall u v, u * v \in W} (U * V <= W)%VS.
Proof.
apply: (iffP idP) => [sUVW u v Uu Vv | sUVW].
by rewrite (subvP sUVW) ?memv_mul.
rewrite [prodv]unlock; apply/span_subvP=> _ /allpairsP[[u v] /= [Uu Vv ->]].
by rewrite sUVW ?vbasis_mem.
Qed.
Lemma prodv_line u v : (<[u]> * <[v]> = <[u * v]>)%VS.
Proof.
apply: subv_anti; rewrite -memvE memv_mul ?memv_line // andbT.
apply/prodvP=> _ _ /vlineP[a ->] /vlineP[b ->].
by rewrite -scalerAr -scalerAl !memvZ ?memv_line.
Qed.
Lemma dimv1: \dim (1%VS : {vspace aT}) = 1.
Proof. by rewrite dim_vline oner_neq0. Qed.
Lemma dim_prodv U V : \dim (U * V) <= \dim U * \dim V.
Proof. by rewrite unlock (leq_trans (dim_span _)) ?size_tuple. Qed.
Lemma vspace1_neq0 : (1 != 0 :> {vspace aT})%VS.
Proof. by rewrite -dimv_eq0 dimv1. Qed.
Lemma vbasis1 : exists2 k, k != 0 & vbasis 1 = [:: k%:A] :> seq aT.
Proof.
move: (vbasis 1) (@vbasisP K aT 1); rewrite dim_vline oner_neq0.
case/tupleP=> x X0; rewrite {X0}tuple0 => defX; have Xx := mem_head x nil.
have /vlineP[k def_x] := basis_mem defX Xx; exists k; last by rewrite def_x.
by have:= basis_not0 defX Xx; rewrite def_x scaler_eq0 oner_eq0 orbF.
Qed.
Lemma prod0v : left_zero 0%VS prodv.
Proof.
move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv 0 U)) //.
by rewrite dimv0.
Qed.
Lemma prodv0 : right_zero 0%VS prodv.
Proof.
move=> U; apply/eqP; rewrite -dimv_eq0 -leqn0 (leq_trans (dim_prodv U 0)) //.
by rewrite dimv0 muln0.
Qed.
HB.instance Definition _ := Monoid.isMulLaw.Build {vspace aT} 0%VS prodv
prod0v prodv0.
Lemma prod1v : left_id 1%VS prodv.
Proof.
move=> U; apply/subv_anti/andP; split.
by apply/prodvP=> _ u /vlineP[a ->] Uu; rewrite mulr_algl memvZ.
by apply/subvP=> u Uu; rewrite -[u]mul1r memv_mul ?memv_line.
Qed.
Lemma prodv1 : right_id 1%VS prodv.
Proof.
move=> U; apply/subv_anti/andP; split.
by apply/prodvP=> u _ Uu /vlineP[a ->]; rewrite mulr_algr memvZ.
by apply/subvP=> u Uu; rewrite -[u]mulr1 memv_mul ?memv_line.
Qed.
Lemma prodvS U1 U2 V1 V2 : (U1 <= U2 -> V1 <= V2 -> U1 * V1 <= U2 * V2)%VS.
Proof.
move/subvP=> sU12 /subvP sV12; apply/prodvP=> u v Uu Vv.
by rewrite memv_mul ?sU12 ?sV12.
Qed.
Lemma prodvSl U1 U2 V : (U1 <= U2 -> U1 * V <= U2 * V)%VS.
Proof. by move/prodvS->. Qed.
Lemma prodvSr U V1 V2 : (V1 <= V2 -> U * V1 <= U * V2)%VS.
Proof. exact: prodvS. Qed.
Lemma prodvDl : left_distributive prodv addv.
Proof.
move=> U1 U2 V; apply/esym/subv_anti/andP; split.
by rewrite subv_add 2?prodvS ?addvSl ?addvSr.
apply/prodvP=> _ v /memv_addP[u1 Uu1 [u2 Uu2 ->]] Vv.
by rewrite mulrDl memv_add ?memv_mul.
Qed.
Lemma prodvDr : right_distributive prodv addv.
Proof.
move=> U V1 V2; apply/esym/subv_anti/andP; split.
by rewrite subv_add 2?prodvS ?addvSl ?addvSr.
apply/prodvP=> u _ Uu /memv_addP[v1 Vv1 [v2 Vv2 ->]].
by rewrite mulrDr memv_add ?memv_mul.
Qed.
HB.instance Definition _ := Monoid.isAddLaw.Build {vspace aT} prodv addv
prodvDl prodvDr.
Lemma prodvA : associative prodv.
Proof.
move=> U V W; rewrite -(span_basis (vbasisP U)) span_def !big_distrl /=.
apply: eq_bigr => u _; rewrite -(span_basis (vbasisP W)) span_def !big_distrr.
apply: eq_bigr => w _; rewrite -(span_basis (vbasisP V)) span_def /=.
rewrite !(big_distrl, big_distrr) /=; apply: eq_bigr => v _.
by rewrite !prodv_line mulrA.
Qed.
HB.instance Definition _ := Monoid.isLaw.Build {vspace aT} 1%VS prodv
prodvA prod1v prodv1.
Definition expv U n := iterop n.+1.-1 prodv U 1%VS.
Local Notation "A ^+ n" := (expv A n) : vspace_scope.
Lemma expv0 U : (U ^+ 0 = 1)%VS. Proof. by []. Qed.
Lemma expv1 U : (U ^+ 1 = U)%VS. Proof. by []. Qed.
Lemma expv2 U : (U ^+ 2 = U * U)%VS. Proof. by []. Qed.
Lemma expvSl U n : (U ^+ n.+1 = U * U ^+ n)%VS.
Proof. by case: n => //; rewrite prodv1. Qed.
Lemma expv0n n : (0 ^+ n = if n is _.+1 then 0 else 1)%VS.
Proof. by case: n => // n; rewrite expvSl prod0v. Qed.
Lemma expv1n n : (1 ^+ n = 1)%VS.
Proof. by elim: n => // n IHn; rewrite expvSl IHn prodv1. Qed.
Lemma expvD U m n : (U ^+ (m + n) = U ^+ m * U ^+ n)%VS.
Proof. by elim: m => [|m IHm]; rewrite ?prod1v // !expvSl IHm prodvA. Qed.
Lemma expvSr U n : (U ^+ n.+1 = U ^+ n * U)%VS.
Proof. by rewrite -addn1 expvD. Qed.
Lemma expvM U m n : (U ^+ (m * n) = U ^+ m ^+ n)%VS.
Proof. by elim: n => [|n IHn]; rewrite ?muln0 // mulnS expvD IHn expvSl. Qed.
Lemma expvS U V n : (U <= V -> U ^+ n <= V ^+ n)%VS.
Proof.
move=> sUV; elim: n => [|n IHn]; first by rewrite !expv0 subvv.
by rewrite !expvSl prodvS.
Qed.
Lemma expv_line u n : (<[u]> ^+ n = <[u ^+ n]>)%VS.
Proof.
elim: n => [|n IH]; first by rewrite expr0 expv0.
by rewrite exprS expvSl IH prodv_line.
Qed.
(* Centralisers and centers. *)
Definition centraliser1_vspace u := lker (amulr u - amull u).
Local Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope.
Definition centraliser_vspace V := (\bigcap_i 'C[tnth (vbasis V) i])%VS.
Local Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope.
Definition center_vspace V := (V :&: 'C(V))%VS.
Local Notation "'Z ( V )" := (center_vspace V) : vspace_scope.
Lemma cent1vP u v : reflect (u * v = v * u) (u \in 'C[v]%VS).
Proof. by rewrite (sameP eqlfunP eqP) !lfunE /=; apply: eqP. Qed.
Lemma cent1v1 u : 1 \in 'C[u]%VS. Proof. by apply/cent1vP; rewrite commr1. Qed.
Lemma cent1v_id u : u \in 'C[u]%VS. Proof. exact/cent1vP. Qed.
Lemma cent1vX u n : u ^+ n \in 'C[u]%VS. Proof. exact/cent1vP/esym/commrX. Qed.
Lemma cent1vC u v : (u \in 'C[v])%VS = (v \in 'C[u])%VS.
Proof. exact/cent1vP/cent1vP. Qed.
Lemma centvP u V : reflect {in V, forall v, u * v = v * u} (u \in 'C(V))%VS.
Proof.
apply: (iffP subv_bigcapP) => [cVu y /coord_vbasis-> | cVu i _].
apply/esym/cent1vP/rpred_sum=> i _; apply: rpredZ.
by rewrite -tnth_nth cent1vC memvE cVu.
exact/cent1vP/cVu/vbasis_mem/mem_tnth.
Qed.
Lemma centvsP U V : reflect {in U & V, commutative *%R} (U <= 'C(V))%VS.
Proof. by apply: (iffP subvP) => [cUV u v | cUV u] /cUV-/centvP; apply. Qed.
Lemma subv_cent1 U v : (U <= 'C[v])%VS = (v \in 'C(U)%VS).
Proof.
by apply/subvP/centvP=> cUv u Uu; apply/cent1vP; rewrite 1?cent1vC cUv.
Qed.
Lemma centv1 V : 1 \in 'C(V)%VS.
Proof. by apply/centvP=> v _; rewrite commr1. Qed.
Lemma centvX V u n : u \in 'C(V)%VS -> u ^+ n \in 'C(V)%VS.
Proof. by move/centvP=> cVu; apply/centvP=> v /cVu/esym/commrX->. Qed.
Lemma centvC U V : (U <= 'C(V))%VS = (V <= 'C(U))%VS.
Proof. by apply/centvsP/centvsP=> cUV u v UVu /cUV->. Qed.
Lemma centerv_sub V : ('Z(V) <= V)%VS. Proof. exact: capvSl. Qed.
Lemma cent_centerv V : (V <= 'C('Z(V)))%VS.
Proof. by rewrite centvC capvSr. Qed.
(* Building the predicate that checks is a vspace has a unit *)
Definition is_algid e U :=
[/\ e \in U, e != 0 & {in U, forall u, e * u = u /\ u * e = u}].
Fact algid_decidable U : decidable (exists e, is_algid e U).
Proof.
have [-> | nzU] := eqVneq U 0%VS.
by right=> [[e []]]; rewrite memv0 => ->.
pose X := vbasis U; pose feq f1 f2 := [tuple of map f1 X ++ map f2 X].
have feqL f i: tnth (feq _ f _) (lshift _ i) = f X`_i.
set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple.
by rewrite ltn_ord (nth_map 0) ?size_tuple.
have feqR f i: tnth (feq _ _ f) (rshift _ i) = f X`_i.
set v := f _; rewrite (tnth_nth v) /= nth_cat size_map size_tuple.
by rewrite ltnNge leq_addr addKn /= (nth_map 0) ?size_tuple.
apply: decP (vsolve_eq (feq _ amulr amull) (feq _ id id) U) _.
apply: (iffP (vsolve_eqP _ _ _)) => [[e Ue id_e] | [e [Ue _ id_e]]].
suffices idUe: {in U, forall u, e * u = u /\ u * e = u}.
exists e; split=> //; apply: contraNneq nzU => e0; rewrite -subv0.
by apply/subvP=> u /idUe[<- _]; rewrite e0 mul0r mem0v.
move=> u /coord_vbasis->; rewrite mulr_sumr mulr_suml.
split; apply/eq_bigr=> i _; rewrite -(scalerAr, scalerAl); congr (_ *: _).
by have:= id_e (lshift _ i); rewrite !feqL lfunE.
by have:= id_e (rshift _ i); rewrite !feqR lfunE.
have{id_e} /all_and2[ideX idXe]:= id_e _ (vbasis_mem (mem_tnth _ X)).
exists e => // k; rewrite -[k]splitK.
by case: (split k) => i; rewrite !(feqL, feqR) lfunE /= -tnth_nth.
Qed.
Definition has_algid : pred {vspace aT} := algid_decidable.
Lemma has_algidP {U} : reflect (exists e, is_algid e U) (has_algid U).
Proof. exact: sumboolP. Qed.
Lemma has_algid1 U : 1 \in U -> has_algid U.
Proof.
move=> U1; apply/has_algidP; exists 1; split; rewrite ?oner_eq0 // => u _.
by rewrite mulr1 mul1r.
Qed.
Definition is_aspace U := has_algid U && (U * U <= U)%VS.
Structure aspace := ASpace {asval :> {vspace aT}; _ : is_aspace asval}.
HB.instance Definition _ := [isSub for asval].
HB.instance Definition _ := [Choice of aspace by <:].
Definition clone_aspace U (A : aspace) :=
fun algU & phant_id algU (valP A) => @ASpace U algU : aspace.
Fact aspace1_subproof : is_aspace 1.
Proof. by rewrite /is_aspace prod1v -memvE has_algid1 memv_line. Qed.
Canonical aspace1 : aspace := ASpace aspace1_subproof.
Lemma aspacef_subproof : is_aspace fullv.
Proof. by rewrite /is_aspace subvf has_algid1 ?memvf. Qed.
Canonical aspacef : aspace := ASpace aspacef_subproof.
Lemma polyOver1P p :
reflect (exists q, p = map_poly (in_alg aT) q) (p \is a polyOver 1%VS).
Proof.
apply: (iffP idP) => [/allP/=Qp | [q ->]]; last first.
by apply/polyOverP=> j; rewrite coef_map rpredZ ?memv_line.
exists (map_poly (coord [tuple 1] 0) p).
rewrite -map_poly_comp map_poly_id // => _ /Qp/vlineP[a ->] /=.
by rewrite linearZ /= (coord_free 0) ?mulr1 // seq1_free ?oner_eq0.
Qed.
End FalgebraTheory.
Delimit Scope aspace_scope with AS.
Bind Scope aspace_scope with aspace.
Arguments asval {K aT} a%_AS.
Arguments aspace [K]%_type aT%_type.
Arguments clone_aspace [K aT U%_VS A%_AS algU] _.
Notation "{ 'aspace' T }" := (aspace T) : type_scope.
Notation "A * B" := (prodv A B) : vspace_scope.
Notation "A ^+ n" := (expv A n) : vspace_scope.
Notation "'C [ u ]" := (centraliser1_vspace u) : vspace_scope.
Notation "'C_ U [ v ]" := (capv U 'C[v]) : vspace_scope.
Notation "'C_ ( U ) [ v ]" := (capv U 'C[v]) (only parsing) : vspace_scope.
Notation "'C ( V )" := (centraliser_vspace V) : vspace_scope.
Notation "'C_ U ( V )" := (capv U 'C(V)) : vspace_scope.
Notation "'C_ ( U ) ( V )" := (capv U 'C(V)) (only parsing) : vspace_scope.
Notation "'Z ( V )" := (center_vspace V) : vspace_scope.
Notation "1" := (aspace1 _) : aspace_scope.
Notation "{ : aT }" := (aspacef aT) : aspace_scope.
Notation "[ 'aspace' 'of' U ]" := (@clone_aspace _ _ U _ _ id)
(format "[ 'aspace' 'of' U ]") : form_scope.
Notation "[ 'aspace' 'of' U 'for' A ]" := (@clone_aspace _ _ U A _ idfun)
(format "[ 'aspace' 'of' U 'for' A ]") : form_scope.
Arguments prodvP {K aT U V W}.
Arguments cent1vP {K aT u v}.
Arguments centvP {K aT u V}.
Arguments centvsP {K aT U V}.
Arguments has_algidP {K aT U}.
Arguments polyOver1P {K aT p}.
Section AspaceTheory.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v e : aT) (U V : {vspace aT}) (A B : {aspace aT}).
Import FalgLfun.
Lemma algid_subproof U :
{e | e \in U
& has_algid U ==> (U <= lker (amull e - 1) :&: lker (amulr e - 1))%VS}.
Proof.
apply: sig2W; case: has_algidP => [[e]|]; last by exists 0; rewrite ?mem0v.
case=> Ae _ idAe; exists e => //; apply/subvP=> u /idAe[eu_u ue_u].
by rewrite memv_cap !memv_ker !lfun_simp /= eu_u ue_u subrr eqxx.
Qed.
Definition algid U := s2val (algid_subproof U).
Lemma memv_algid U : algid U \in U.
Proof. by rewrite /algid; case: algid_subproof. Qed.
Lemma algidl A : {in A, left_id (algid A) *%R}.
Proof.
rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A.
move/subvP=> idAe u /idAe/memv_capP[].
by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP.
Qed.
Lemma algidr A : {in A, right_id (algid A) *%R}.
Proof.
rewrite /algid; case: algid_subproof => e _ /=; have /andP[-> _] := valP A.
move/subvP=> idAe u /idAe/memv_capP[_].
by rewrite memv_ker !lfun_simp /= subr_eq0 => /eqP.
Qed.
Lemma unitr_algid1 A u : u \in A -> u \is a GRing.unit -> algid A = 1.
Proof. by move=> Eu /mulrI; apply; rewrite mulr1 algidr. Qed.
Lemma algid_eq1 A : (algid A == 1) = (1 \in A).
Proof. by apply/eqP/idP=> [<- | /algidr <-]; rewrite ?memv_algid ?mul1r. Qed.
Lemma algid_neq0 A : algid A != 0.
Proof.
have /andP[/has_algidP[u [Au nz_u _]] _] := valP A.
by apply: contraNneq nz_u => e0; rewrite -(algidr Au) e0 mulr0.
Qed.
Lemma dim_algid A : \dim <[algid A]> = 1%N.
Proof. by rewrite dim_vline algid_neq0. Qed.
Lemma adim_gt0 A : (0 < \dim A)%N.
Proof. by rewrite -(dim_algid A) dimvS // -memvE ?memv_algid. Qed.
Lemma not_asubv0 A : ~~ (A <= 0)%VS.
Proof. by rewrite subv0 -dimv_eq0 -lt0n adim_gt0. Qed.
Lemma adim1P {A} : reflect (A = <[algid A]>%VS :> {vspace aT}) (\dim A == 1%N).
Proof.
rewrite eqn_leq adim_gt0 -(memv_algid A) andbC -(dim_algid A) -eqEdim eq_sym.
exact: eqP.
Qed.
Lemma asubv A : (A * A <= A)%VS.
Proof. by have /andP[] := valP A. Qed.
Lemma memvM A : {in A &, forall u v, u * v \in A}.
Proof. exact/prodvP/asubv. Qed.
Lemma prodv_id A : (A * A)%VS = A.
Proof.
apply/eqP; rewrite eqEsubv asubv; apply/subvP=> u Au.
by rewrite -(algidl Au) memv_mul // memv_algid.
Qed.
Lemma prodv_sub U V A : (U <= A -> V <= A -> U * V <= A)%VS.
Proof. by move=> sUA sVA; rewrite -prodv_id prodvS. Qed.
Lemma expv_id A n : (A ^+ n.+1)%VS = A.
Proof. by elim: n => // n IHn; rewrite !expvSl prodvA prodv_id -expvSl. Qed.
Lemma limg_amulr U v : (amulr v @: U = U * <[v]>)%VS.
Proof.
rewrite -(span_basis (vbasisP U)) limg_span !span_def big_distrl /= big_map.
by apply: eq_bigr => u; rewrite prodv_line lfunE.
Qed.
Lemma memv_cosetP {U v w} :
reflect (exists2 u, u\in U & w = u * v) (w \in U * <[v]>)%VS.
Proof.
rewrite -limg_amulr.
by apply: (iffP memv_imgP) => [] [u] Uu ->; exists u; rewrite ?lfunE.
Qed.
Lemma dim_cosetv_unit V u : u \is a GRing.unit -> \dim (V * <[u]>) = \dim V.
Proof.
by move/lker0_amulr/eqP=> Uu; rewrite -limg_amulr limg_dim_eq // Uu capv0.
Qed.
Lemma memvV A u : (u^-1 \in A) = (u \in A).
Proof.
suffices{u} invA: invr_closed A by apply/idP/idP=> /invA; rewrite ?invrK.
move=> u Au; have [Uu | /invr_out-> //] := boolP (u \is a GRing.unit).
rewrite memvE -(limg_ker0 _ _ (lker0_amulr Uu)) limg_line lfunE /= mulVr //.
suff ->: (amulr u @: A)%VS = A by rewrite -memvE -algid_eq1 (unitr_algid1 Au).
by apply/eqP; rewrite limg_amulr -dimv_leqif_eq ?prodv_sub ?dim_cosetv_unit.
Qed.
Fact aspace_cap_subproof A B : algid A \in B -> is_aspace (A :&: B).
Proof.
move=> BeA; apply/andP.
split; [apply/has_algidP | by rewrite subv_cap !prodv_sub ?capvSl ?capvSr].
exists (algid A); rewrite /is_algid algid_neq0 memv_cap memv_algid.
by split=> // u /memv_capP[Au _]; rewrite ?algidl ?algidr.
Qed.
Definition aspace_cap A B BeA := ASpace (@aspace_cap_subproof A B BeA).
Fact centraliser1_is_aspace u : is_aspace 'C[u].
Proof.
rewrite /is_aspace has_algid1 ?cent1v1 //=.
apply/prodvP=> v w /cent1vP-cuv /cent1vP-cuw.
by apply/cent1vP; rewrite -mulrA cuw !mulrA cuv.
Qed.
Canonical centraliser1_aspace u := ASpace (centraliser1_is_aspace u).
Fact centraliser_is_aspace V : is_aspace 'C(V).
Proof.
rewrite /is_aspace has_algid1 ?centv1 //=.
apply/prodvP=> u w /centvP-cVu /centvP-cVw.
by apply/centvP=> v Vv; rewrite /= -mulrA cVw // !mulrA cVu.
Qed.
Canonical centraliser_aspace V := ASpace (centraliser_is_aspace V).
Lemma centv_algid A : algid A \in 'C(A)%VS.
Proof. by apply/centvP=> u Au; rewrite algidl ?algidr. Qed.
Canonical center_aspace A := [aspace of 'Z(A) for aspace_cap (centv_algid A)].
Lemma algid_center A : algid 'Z(A) = algid A.
Proof.
rewrite -(algidl (subvP (centerv_sub A) _ (memv_algid _))) algidr //=.
by rewrite memv_cap memv_algid centv_algid.
Qed.
Lemma Falgebra_FieldMixin :
GRing.integral_domain_axiom aT -> GRing.field_axiom aT.
Proof.
move=> domT u nz_u; apply/unitrP.
have kerMu: lker (amulr u) == 0%VS.
rewrite eqEsubv sub0v andbT; apply/subvP=> v; rewrite memv_ker lfunE /=.
by move/eqP/domT; rewrite (negPf nz_u) orbF memv0.
have /memv_imgP[v _ vu1]: 1 \in limg (amulr u); last rewrite lfunE /= in vu1.
suffices /eqP->: limg (amulr u) == fullv by rewrite memvf.
by rewrite -dimv_leqif_eq ?subvf ?limg_dim_eq // (eqP kerMu) capv0.
exists v; split=> //; apply: (lker0P kerMu).
by rewrite !lfunE /= -mulrA -vu1 mulr1 mul1r.
Qed.
Section SkewField.
Hypothesis fieldT : GRing.field_axiom aT.
Lemma skew_field_algid1 A : algid A = 1.
Proof. by rewrite (unitr_algid1 (memv_algid A)) ?fieldT ?algid_neq0. Qed.
Lemma skew_field_module_semisimple A M :
let sumA X := (\sum_(x <- X) A * <[x]>)%VS in
(A * M <= M)%VS -> {X | [/\ sumA X = M, directv (sumA X) & 0 \notin X]}.
Proof.
move=> sumA sAM_M; pose X := Nil aT; pose k := (\dim (A * M) - \dim (sumA X))%N.
have: (\dim (A * M) - \dim (sumA X) < k.+1)%N by [].
have: [/\ (sumA X <= A * M)%VS, directv (sumA X) & 0 \notin X].
by rewrite /sumA directvE /= !big_nil sub0v dimv0.
elim: {X k}k.+1 (X) => // k IHk X [sAX_AM dxAX nzX]; rewrite ltnS => leAXk.
have [sM_AX | /subvPn/sig2W[y My notAXy]] := boolP (M <= sumA X)%VS.
by exists X; split=> //; apply/eqP; rewrite eqEsubv (subv_trans sAX_AM).
have nz_y: y != 0 by rewrite (memPnC notAXy) ?mem0v.
pose AY := sumA (y :: X).
have sAY_AM: (AY <= A * M)%VS by rewrite [AY]big_cons subv_add ?prodvSr.
have dxAY: directv AY.
rewrite directvE /= !big_cons [_ == _]directv_addE dxAX directvE eqxx /=.
rewrite -/(sumA X) eqEsubv sub0v andbT -limg_amulr.
apply/subvP=> _ /memv_capP[/memv_imgP[a Aa ->]]/[!lfunE]/= AXay.
rewrite memv0 (mulIr_eq0 a (mulIr _)) ?fieldT //.
apply: contraR notAXy => /fieldT-Ua; rewrite -[y](mulKr Ua) /sumA.
by rewrite -big_distrr -(prodv_id A) /= -prodvA big_distrr memv_mul ?memvV.
apply: (IHk (y :: X)); first by rewrite !inE eq_sym negb_or nz_y.
rewrite -subSn ?dimvS // (directvP dxAY) /= big_cons -(directvP dxAX) /=.
rewrite subnDA (leq_trans _ leAXk) ?leq_sub2r // leq_subLR -add1n leq_add2r.
by rewrite dim_cosetv_unit ?fieldT ?adim_gt0.
Qed.
Lemma skew_field_module_dimS A M : (A * M <= M)%VS -> \dim A %| \dim M.
Proof.
case/skew_field_module_semisimple=> X [<- /directvP-> nzX] /=.
rewrite big_seq prime.dvdn_sum // => x /(memPn nzX)nz_x.
by rewrite dim_cosetv_unit ?fieldT.
Qed.
Lemma skew_field_dimS A B : (A <= B)%VS -> \dim A %| \dim B.
Proof. by move=> sAB; rewrite skew_field_module_dimS ?prodv_sub. Qed.
End SkewField.
End AspaceTheory.
(* Note that local centraliser might not be proper sub-algebras. *)
Notation "'C [ u ]" := (centraliser1_aspace u) : aspace_scope.
Notation "'C ( V )" := (centraliser_aspace V) : aspace_scope.
Notation "'Z ( A )" := (center_aspace A) : aspace_scope.
Arguments adim1P {K aT A}.
Arguments memv_cosetP {K aT U v w}.
Section Closure.
Variables (K : fieldType) (aT : falgType K).
Implicit Types (u v : aT) (U V W : {vspace aT}).
(* Subspaces of an F-algebra form a Kleene algebra *)
Definition agenv U := (\sum_(i < \dim {:aT}) U ^+ i)%VS.
Local Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope.
Local Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope.
Lemma agenvEl U : agenv U = (1 + U * agenv U)%VS.
Proof.
pose f V := (1 + U * V)%VS; rewrite -/(f _); pose n := \dim {:aT}.
have ->: agenv U = iter n f 0%VS.
rewrite /agenv -/n; elim: n => [|n IHn]; first by rewrite big_ord0.
rewrite big_ord_recl /= -{}IHn; congr (1 + _)%VS; rewrite big_distrr /=.
by apply: eq_bigr => i; rewrite expvSl.
have fS i j: i <= j -> (iter i f 0 <= iter j f 0)%VS.
by elim: i j => [|i IHi] [|j] leij; rewrite ?sub0v //= addvS ?prodvSr ?IHi.
suffices /(@trajectP _ f _ n.+1)[i le_i_n Dfi]: looping f 0%VS n.+1.
by apply/eqP; rewrite eqEsubv -iterS fS // Dfi fS.
apply: contraLR (dimvS (subvf (iter n.+1 f 0%VS))); rewrite -/n -ltnNge.
rewrite -looping_uniq; elim: n.+1 => // i IHi; rewrite trajectSr rcons_uniq.
rewrite {1}trajectSr mem_rcons inE negb_or eq_sym eqEdim fS ?leqW // -ltnNge.
by rewrite -andbA => /and3P[lt_fi _ /IHi/leq_ltn_trans->].
Qed.
Lemma agenvEr U : agenv U = (1 + agenv U * U)%VS.
Proof.
rewrite [lhs in lhs = _]agenvEl big_distrr big_distrl /=; congr (_ + _)%VS.
by apply: eq_bigr => i _ /=; rewrite -expvSr -expvSl.
Qed.
Lemma agenv_modl U V : (U * V <= V -> agenv U * V <= V)%VS.
Proof.
rewrite big_distrl /= => idlU_V; apply/subv_sumP=> [[i _] /= _].
elim: i => [|i]; first by rewrite expv0 prod1v.
by apply: subv_trans; rewrite expvSr -prodvA prodvSr.
Qed.
Lemma agenv_modr U V : (V * U <= V -> V * agenv U <= V)%VS.
Proof.
rewrite big_distrr /= => idrU_V; apply/subv_sumP=> [[i _] /= _].
elim: i => [|i]; first by rewrite expv0 prodv1.
by apply: subv_trans; rewrite expvSl prodvA prodvSl.
Qed.
Fact agenv_is_aspace U : is_aspace (agenv U).
Proof.
rewrite /is_aspace has_algid1; last by rewrite memvE agenvEl addvSl.
by rewrite agenv_modl // [V in (_ <= V)%VS]agenvEl addvSr.
Qed.
Canonical agenv_aspace U : {aspace aT} := ASpace (agenv_is_aspace U).
Lemma agenvE U : agenv U = agenv_aspace U. Proof. by []. Qed.
(* Kleene algebra properties *)
Lemma agenvM U : (agenv U * agenv U)%VS = agenv U. Proof. exact: prodv_id. Qed.
Lemma agenvX n U : (agenv U ^+ n.+1)%VS = agenv U. Proof. exact: expv_id. Qed.
Lemma sub1_agenv U : (1 <= agenv U)%VS. Proof. by rewrite agenvEl addvSl. Qed.
Lemma sub_agenv U : (U <= agenv U)%VS.
Proof. by rewrite 2!agenvEl addvC prodvDr prodv1 -addvA addvSl. Qed.
Lemma subX_agenv U n : (U ^+ n <= agenv U)%VS.
Proof.
by case: n => [|n]; rewrite ?sub1_agenv // -(agenvX n) expvS // sub_agenv.
Qed.
Lemma agenv_sub_modl U V : (1 <= V -> U * V <= V -> agenv U <= V)%VS.
Proof.
move=> s1V /agenv_modl; apply: subv_trans.
by rewrite -[Us in (Us <= _)%VS]prodv1 prodvSr.
Qed.
Lemma agenv_sub_modr U V : (1 <= V -> V * U <= V -> agenv U <= V)%VS.
Proof.
move=> s1V /agenv_modr; apply: subv_trans.
by rewrite -[Us in (Us <= _)%VS]prod1v prodvSl.
Qed.
Lemma agenv_id U : agenv (agenv U) = agenv U.
Proof.
apply/eqP; rewrite eqEsubv sub_agenv andbT.
by rewrite agenv_sub_modl ?sub1_agenv ?agenvM.
Qed.
Lemma agenvS U V : (U <= V -> agenv U <= agenv V)%VS.
Proof.
move=> sUV; rewrite agenv_sub_modl ?sub1_agenv //.
by rewrite -[Vs in (_ <= Vs)%VS]agenvM prodvSl ?(subv_trans sUV) ?sub_agenv.
Qed.
Lemma agenv_add_id U V : agenv (agenv U + V) = agenv (U + V).
Proof.
apply/eqP; rewrite eqEsubv andbC agenvS ?addvS ?sub_agenv //=.
rewrite agenv_sub_modl ?sub1_agenv //.
rewrite -[rhs in (_ <= rhs)%VS]agenvM prodvSl // subv_add agenvS ?addvSl //=.
exact: subv_trans (addvSr U V) (sub_agenv _).
Qed.
Lemma subv_adjoin U x : (U <= <<U; x>>)%VS.
Proof. by rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSl. Qed.
Lemma subv_adjoin_seq U xs : (U <= <<U & xs>>)%VS.
Proof. by rewrite (subv_trans (sub_agenv _)) // ?agenvS ?addvSl. Qed.
Lemma memv_adjoin U x : x \in <<U; x>>%VS.
Proof. by rewrite memvE (subv_trans (sub_agenv _)) ?agenvS ?addvSr. Qed.
Lemma seqv_sub_adjoin U xs : {subset xs <= <<U & xs>>%VS}.
Proof.
by apply/span_subvP; rewrite (subv_trans (sub_agenv _)) ?agenvS ?addvSr.
Qed.
Lemma subvP_adjoin U x y : y \in U -> y \in <<U; x>>%VS.
Proof. exact/subvP/subv_adjoin. Qed.
Lemma adjoin_nil V : <<V & [::]>>%VS = agenv V.
Proof. by rewrite span_nil addv0. Qed.
Lemma adjoin_cons V x rs : <<V & x :: rs>>%VS = << <<V; x>> & rs>>%VS.
Proof. by rewrite span_cons addvA agenv_add_id. Qed.
Lemma adjoin_rcons V rs x : <<V & rcons rs x>>%VS = << <<V & rs>>%VS; x>>%VS.
Proof. by rewrite -cats1 span_cat addvA span_seq1 agenv_add_id. Qed.
Lemma adjoin_seq1 V x : <<V & [:: x]>>%VS = <<V; x>>%VS.
Proof. by rewrite adjoin_cons adjoin_nil agenv_id. Qed.
Lemma adjoinC V x y : << <<V; x>>; y>>%VS = << <<V; y>>; x>>%VS.
Proof. by rewrite !agenv_add_id -!addvA (addvC <[x]>%VS). Qed.
Lemma adjoinSl U V x : (U <= V -> <<U; x>> <= <<V; x>>)%VS.
Proof. by move=> sUV; rewrite agenvS ?addvS. Qed.
Lemma adjoin_seqSl U V rs : (U <= V -> <<U & rs>> <= <<V & rs>>)%VS.
Proof. by move=> sUV; rewrite agenvS ?addvS. Qed.
Lemma adjoin_seqSr U rs1 rs2 :
{subset rs1 <= rs2} -> (<<U & rs1>> <= <<U & rs2>>)%VS.
Proof. by move/sub_span=> s_rs12; rewrite agenvS ?addvS. Qed.
End Closure.
Notation "<< U >>" := (agenv_aspace U) : aspace_scope.
Notation "<< U & vs >>" := (agenv (U + <<vs>>)) : vspace_scope.
Notation "<< U ; x >>" := (agenv (U + <[x]>)) : vspace_scope.
Notation "<< U & vs >>" := << U + <<vs>> >>%AS : aspace_scope.
Notation "<< U ; x >>" := << U + <[x]> >>%AS : aspace_scope.
Section SubFalgType.
(* The falgType structure of subvs_of A for A : {aspace aT}. *)
(* We can't use the rpred-based mixin, because A need not contain 1. *)
Variable (K : fieldType) (aT : falgType K) (A : {aspace aT}).
Definition subvs_one := Subvs (memv_algid A).
Definition subvs_mul (u v : subvs_of A) :=
Subvs (subv_trans (memv_mul (subvsP u) (subvsP v)) (asubv _)).
Fact subvs_mulA : associative subvs_mul.
Proof. by move=> x y z; apply/val_inj/mulrA. Qed.
Fact subvs_mu1l : left_id subvs_one subvs_mul.
Proof. by move=> x; apply/val_inj/algidl/(valP x). Qed.
Fact subvs_mul1 : right_id subvs_one subvs_mul.
Proof. by move=> x; apply/val_inj/algidr/(valP x). Qed.
Fact subvs_mulDl : left_distributive subvs_mul +%R.
Proof. move=> x y z; apply/val_inj/mulrDl. Qed.
Fact subvs_mulDr : right_distributive subvs_mul +%R.
Proof. move=> x y z; apply/val_inj/mulrDr. Qed.
HB.instance Definition _ := GRing.Zmodule_isNzRing.Build (subvs_of A)
subvs_mulA subvs_mu1l subvs_mul1 subvs_mulDl subvs_mulDr (algid_neq0 _).
Lemma subvs_scaleAl k (x y : subvs_of A) : k *: (x * y) = (k *: x) * y.
Proof. exact/val_inj/scalerAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build K (subvs_of A)
subvs_scaleAl.
Lemma subvs_scaleAr k (x y : subvs_of A) : k *: (x * y) = x * (k *: y).
Proof. exact/val_inj/scalerAr. Qed.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build K (subvs_of A)
subvs_scaleAr.
HB.instance Definition _ := Algebra_isFalgebra.Build K (subvs_of A).
Implicit Type w : subvs_of A.
Lemma vsval_unitr w : vsval w \is a GRing.unit -> w \is a GRing.unit.
Proof.
case: w => /= u Au Uu; have Au1: u^-1 \in A by rewrite memvV.
apply/unitrP; exists (Subvs Au1).
by split; apply: val_inj; rewrite /= ?mulrV ?mulVr ?(unitr_algid1 Au).
Qed.
Lemma vsval_invr w : vsval w \is a GRing.unit -> val w^-1 = (val w)^-1.
Proof.
move=> Uu; have def_w: w / w * w = w by rewrite divrK ?vsval_unitr.
by apply: (mulrI Uu); rewrite -[in u in u / _]def_w ?mulrK.
Qed.
End SubFalgType.
Section AHom.
Variable K : fieldType.
Section Class_Def.
Variables aT rT : falgType K.
Definition ahom_in (U : {vspace aT}) (f : 'Hom(aT, rT)) :=
all2rel (fun x y : aT => f (x * y) == f x * f y) (vbasis U) && (f 1 == 1).
Lemma ahom_inP {f : 'Hom(aT, rT)} {U : {vspace aT}} :
reflect ({in U &, {morph f : x y / x * y >-> x * y}} * (f 1 = 1))
(ahom_in U f).
Proof.
apply: (iffP andP) => [[/allrelP fM /eqP f1] | [fM f1]]; last first.
rewrite f1; split=> //; apply/allrelP => x y Ax Ay.
by rewrite fM // vbasis_mem.
split=> // x y /coord_vbasis -> /coord_vbasis ->.
rewrite !mulr_suml ![f _]linear_sum mulr_suml; apply: eq_bigr => i _ /=.
rewrite !mulr_sumr linear_sum; apply: eq_bigr => j _ /=.
rewrite !linearZ -!scalerAr -!scalerAl 2!linearZ /=; congr (_ *: (_ *: _)).
by apply/eqP/fM; apply: memt_nth.
Qed.
Lemma ahomP_tmp {f : 'Hom(aT, rT)} : reflect (monoid_morphism f) (ahom_in {:aT} f).
Proof.
apply: (iffP ahom_inP) => [[fM f1] | fRM_P]; last first.
by split=> [x y|]; [rewrite fRM_P.2|rewrite fRM_P.1].
by split=> // x y; rewrite fM ?memvf.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ahomP_tmp` instead")]
Lemma ahomP {f : 'Hom(aT, rT)} : reflect (multiplicative f) (ahom_in {:aT} f).
Proof. by apply: (iffP ahomP_tmp) => [][]. Qed.
Structure ahom := AHom {ahval :> 'Hom(aT, rT); _ : ahom_in {:aT} ahval}.
HB.instance Definition _ := [isSub for ahval].
HB.instance Definition _ := [Equality of ahom by <:].
HB.instance Definition _ := [Choice of ahom by <:].
Fact linfun_is_ahom (f : {lrmorphism aT -> rT}) : ahom_in {:aT} (linfun f).
Proof. by apply/ahom_inP; split=> [x y|]; rewrite !lfunE ?rmorphM ?rmorph1. Qed.
Canonical linfun_ahom f := AHom (linfun_is_ahom f).
End Class_Def.
Arguments ahom_in [aT rT].
Arguments ahom_inP {aT rT f U}.
#[warning="-deprecated-since-mathcomp-2.5.0"]
Arguments ahomP {aT rT f}.
Arguments ahomP_tmp {aT rT f}.
Section LRMorphism.
Variables aT rT sT : falgType K.
Fact ahom_is_monoid_morphism (f : ahom aT rT) : monoid_morphism f.
Proof. by apply/ahomP_tmp; case: f. Qed.
#[hnf]
HB.instance Definition _ (f : ahom aT rT) :=
GRing.isMonoidMorphism.Build aT rT f (ahom_is_monoid_morphism f).
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `ahom_is_monoid_morphism` instead")]
Definition ahom_is_multiplicative (f : ahom aT rT) : multiplicative f :=
(fun p => (p.2, p.1)) (ahom_is_monoid_morphism f).
Lemma ahomWin (f : ahom aT rT) U : ahom_in U f.
Proof.
by apply/ahom_inP; split; [apply: in2W (rmorphM _) | apply: rmorph1].
Qed.
Lemma id_is_ahom (V : {vspace aT}) : ahom_in V \1.
Proof. by apply/ahom_inP; split=> [x y|] /=; rewrite !id_lfunE. Qed.
Canonical id_ahom := AHom (id_is_ahom (aspacef aT)).
Lemma comp_is_ahom (V : {vspace aT}) (f : 'Hom(rT, sT)) (g : 'Hom(aT, rT)) :
ahom_in {:rT} f -> ahom_in V g -> ahom_in V (f \o g).
Proof.
move=> /ahom_inP fM /ahom_inP gM; apply/ahom_inP.
by split=> [x y Vx Vy|] /=; rewrite !comp_lfunE gM // fM ?memvf.
Qed.
Canonical comp_ahom (f : ahom rT sT) (g : ahom aT rT) :=
AHom (comp_is_ahom (valP f) (valP g)).
Lemma aimgM (f : ahom aT rT) U V : (f @: (U * V) = f @: U * f @: V)%VS.
Proof.
apply/eqP; rewrite eqEsubv; apply/andP; split; last first.
apply/prodvP=> _ _ /memv_imgP[u Hu ->] /memv_imgP[v Hv ->].
by rewrite -rmorphM memv_img // memv_mul.
apply/subvP=> _ /memv_imgP[w UVw ->]; rewrite memv_preim (subvP _ w UVw) //.
by apply/prodvP=> u v Uu Vv; rewrite -memv_preim rmorphM memv_mul // memv_img.
Qed.
Lemma aimg1 (f : ahom aT rT) : (f @: 1 = 1)%VS.
Proof. by rewrite limg_line rmorph1. Qed.
Lemma aimgX (f : ahom aT rT) U n : (f @: (U ^+ n) = f @: U ^+ n)%VS.
Proof.
elim: n => [|n IH]; first by rewrite !expv0 aimg1.
by rewrite !expvSl aimgM IH.
Qed.
Lemma aimg_agen (f : ahom aT rT) U : (f @: agenv U)%VS = agenv (f @: U).
Proof.
apply/eqP; rewrite eqEsubv; apply/andP; split.
by rewrite limg_sum; apply/subv_sumP => i _; rewrite aimgX subX_agenv.
apply: agenv_sub_modl; first by rewrite -(aimg1 f) limgS // sub1_agenv.
by rewrite -aimgM limgS // [rhs in (_ <= rhs)%VS]agenvEl addvSr.
Qed.
Lemma aimg_adjoin (f : ahom aT rT) U x : (f @: <<U; x>> = <<f @: U; f x>>)%VS.
Proof. by rewrite aimg_agen limgD limg_line. Qed.
Lemma aimg_adjoin_seq (f : ahom aT rT) U xs :
(f @: <<U & xs>> = <<f @: U & map f xs>>)%VS.
Proof. by rewrite aimg_agen limgD limg_span. Qed.
Fact ker_sub_ahom_is_aspace (f g : ahom aT rT) :
is_aspace (lker (ahval f - ahval g)).
Proof.
rewrite /is_aspace has_algid1; last by apply/eqlfunP; rewrite !rmorph1.
apply/prodvP=> a b /eqlfunP Dfa /eqlfunP Dfb.
by apply/eqlfunP; rewrite !rmorphM /= Dfa Dfb.
Qed.
Canonical ker_sub_ahom_aspace f g := ASpace (ker_sub_ahom_is_aspace f g).
End LRMorphism.
Canonical fixedSpace_aspace aT (f : ahom aT aT) := [aspace of fixedSpace f].
End AHom.
Arguments ahom_in [K aT rT].
Notation "''AHom' ( aT , rT )" := (ahom aT rT) : type_scope.
Notation "''AEnd' ( aT )" := (ahom aT aT) : type_scope.
Delimit Scope lrfun_scope with AF.
Bind Scope lrfun_scope with ahom.
Notation "\1" := (@id_ahom _ _) : lrfun_scope.
Notation "f \o g" := (comp_ahom f g) : lrfun_scope.
|
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.
|
monoid.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype choice ssrnat seq.
From mathcomp Require Import bigop fintype finfun.
(******************************************************************************)
(* Group-like structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines the following algebraic structures: *)
(* *)
(* magmaType == magma *)
(* The HB class is called Magma. *)
(* ChoiceMagma.type == join of magmaType and choiceType *)
(* The HB class is called ChoiceMagma. *)
(* semigroupType == associative magma *)
(* The HB class is called Semigroup. *)
(* baseUMagmaType == pointed magma *)
(* The HB class is called BaseUMagma. *)
(* ChoiceBaseUMagma.type == join of baseUMagmaType and choiceType *)
(* The HB class is called ChoiceBaseUMagma. *)
(* umagmaType == unitary magma *)
(* The HB class is called UMagma. *)
(* monoidType == monoid *)
(* The HB class is called Monoid. *)
(* baseGroupType == pointed magma with an inversion operator *)
(* The HB class is called BaseGroup. *)
(* groupType == group *)
(* The HB class is called Group. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subMagmaType V P == join of magmaType and subType (P : pred V) such *)
(* that val is multiplicative *)
(* The HB class is called SubMagma. *)
(* subSemigroupType V P == join of semigroupType and subType (P : pred V) *)
(* such that val is multiplicative *)
(* The HB class is called SubSemigroup. *)
(* subBaseUMagmaType V P == join of baseUMagmaType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubBaseUMagma. *)
(* subUMagmaType V P == join of UMagmaType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubUMagma. *)
(* subMonoidType V P == join of monoidType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubMonoid. *)
(* subGroupType V P == join of groupType and subType (P : pred V) *)
(* such that val is multiplicative and preserves 1 *)
(* The HB class is called SubGroup. *)
(* *)
(* Morphisms between the above structures: *)
(* *)
(* Multiplicative.type G H == multiplicative functions between magmaType *)
(* instances G and H *)
(* UMagmaMorphism.type G H == multiplicative functions preserving 1 between *)
(* baseUMagmaType instances G and H *)
(* *)
(* Closedness predicates for the algebraic structures: *)
(* *)
(* mulgClosed V == predicate closed under multiplication on G : magmaType *)
(* The HB class is called MulClosed. *)
(* umagmaClosed V == predicate closed under multiplication and containing 1 *)
(* on G : baseUMagmaType *)
(* The HB class is called UMagmaClosed. *)
(* invgClosed V == predicate closed under inversion on G : baseGroupType *)
(* The HB class is called InvClosed. *)
(* groupClosed V == predicate closed under multiplication and inversion and *)
(* containing 1 on G : baseGroupType *)
(* The HB class is called InvClosed. *)
(* *)
(* Canonical properties of the algebraic structures: *)
(* * magmaType (magmas): *)
(* x * y == the product of x and y *)
(* commute x y <-> x and y commute (i.e. x * y = y * x) *)
(* mulg_closed S <-> collective predicate S is closed under *)
(* multiplication *)
(* *)
(* * baseUMagmaType (pointed magmas): *)
(* 1 == the unit of a unitary magma *)
(* x ^+ n == x to the power n, with n in nat (non-negative), *)
(* i.e. x * (x * .. (x * x)..) (n terms); x ^+ 1 is *)
(* thus convertible to x, and x ^+ 2 to x * x *)
(* \prod<range> e == iterated product for a baseUMagmaType (cf bigop.v)*)
(* umagma_closed S <-> collective predicate S is closed under *)
(* multiplication and contains 1 *)
(* *)
(* * monoidType (monoids): *)
(* monoid_closed S := umagma_closed S *)
(* *)
(* * baseGroupType (pointed magmas with an inversion operator): *)
(* x ^-1 == the inverse of x *)
(* x / y == x * (y ^- 1) *)
(* x ^- n == (x ^+ n)^-1 *)
(* x ^ y := y^-1 * (x * y) *)
(* == the conjugate of x by y *)
(* [~ x, y] := x^-1 * (y^-1 * (x * y) *)
(* == the commutator of x and y *)
(* invg_closed S <-> collective predicate S is closed under inversion *)
(* divg_closed S <-> collective predicate S is closed under division *)
(* group_closed S <-> collective predicate S is closed under division *)
(* and contains 1 *)
(* *)
(* In addition to this structure hierarchy, we also develop a separate, *)
(* *)
(* * Multiplicative (magma morphisms): *)
(* {multiplicative U -> V} == the interface type for magma morphisms, i.e. *)
(* functions from U to V which maps * in U to * in *)
(* V; both U and V must have magmaType instances *)
(* := GRing.RMorphism.type R S *)
(* *)
(* * UMagmaMorphism (unitary magma morphisms): *)
(* monoid_morphism f <-> f of type U -> V is a multiplicative monoid *)
(* morphism, i.e., f maps 1 and * in U to 1 and *)
(* * in V, respectively. U and V must have *)
(* canonical baseUMagmaType instances. *)
(*Algebra.UMagmaMorphism.type == the interface type for unitary magma *)
(* morphisms; both U and V must have magmaType *)
(* instances *)
(* *)
(* Notations are defined in scope group_scope (delimiter %g) *)
(* This library also extends the conventional suffixes described in library *)
(* ssrbool.v with the following: *)
(* 1 -- unitary magma 1, as in mulg1 : x * 1 = x *)
(* M -- magma multiplication, as in conjgM : x ^ (y * z) = (x ^ y) ^ z *)
(* Mn -- ring by nat multiplication, as in expgMn : *)
(* (x * y) ^+ n = x ^+ n * y ^+ n *)
(* V -- group inverse, as in expVgn : (x^-1) ^+ n = x ^- n *)
(* F -- group division, as in invgF : (x / y)^-1 = y / x *)
(* X -- unitary magma exponentiation, as in conjXg : *)
(* (x ^+ n) ^ y = (x ^ y) ^+ n *)
(* J -- group conjugation, as in conjJg : (x ^ y) ^ z = (x ^ z) ^ y ^ z *)
(* R -- group commutator, as in conjRg : [~ x, y] ^ z = [~ x ^ z, y ^ z] *)
(* The operator suffixes D, B, M and X are also used for the corresponding *)
(* operations on nat, as in expgnDr : x ^+ (m + n) = x ^+ m * x ^+ n. For the *)
(* binary power operator, a trailing "n" suffix is used to indicate the *)
(* operator suffix applies to the left-hand group argument, as in *)
(* expg1n : 1 ^+ n = 1 vs. expg1 : x ^+ 1 = x. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "*%g" (at level 0).
Reserved Notation "\1" (at level 0).
Reserved Notation "f \* g" (at level 40, left associativity).
Reserved Notation "'{' 'multiplicative' G '->' H '}'"
(at level 0, G at level 98, H at level 99,
format "{ 'multiplicative' G -> H }").
Declare Scope group_scope.
Delimit Scope group_scope with g.
Local Open Scope group_scope.
HB.mixin Record hasMul G := {
mul : G -> G -> G
}.
#[short(type="magmaType")]
HB.structure Definition Magma := {G of hasMul G}.
Bind Scope group_scope with Magma.sort.
HB.structure Definition ChoiceMagma := {G of Magma G & Choice G}.
Bind Scope group_scope with ChoiceMagma.sort.
Local Notation "*%g" := (@mul _) : function_scope.
Local Notation "x * y" := (mul x y) : group_scope.
Section MagmaTheory.
Variable G : magmaType.
Implicit Types x y : G.
Definition commute x y := x * y = y * x.
Lemma commute_refl x : commute x x.
Proof. by []. Qed.
Lemma commute_sym x y : commute x y -> commute y x.
Proof. by []. Qed.
Section ClosedPredicates.
Variable S : {pred G}.
Definition mulg_closed := {in S &, forall u v, u * v \in S}.
End ClosedPredicates.
End MagmaTheory.
HB.mixin Record Magma_isSemigroup G of Magma G := {
mulgA : associative (@mul G)
}.
#[short(type="semigroupType")]
HB.structure Definition Semigroup := {G of Magma_isSemigroup G & ChoiceMagma G}.
HB.factory Record isSemigroup G of Choice G := {
mul : G -> G -> G;
mulgA : associative mul
}.
HB.builders Context G of isSemigroup G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.end.
Bind Scope group_scope with Semigroup.sort.
Section SemigroupTheory.
Variable G : semigroupType.
Implicit Types x y : G.
Lemma commuteM x y z : commute x y -> commute x z -> commute x (y * z).
Proof. by move=> cxy cxz; rewrite /commute -mulgA -cxz !mulgA cxy. Qed.
End SemigroupTheory.
HB.mixin Record hasOne G := {
one : G
}.
#[short(type="baseUMagmaType")]
HB.structure Definition BaseUMagma := {G of hasOne G & Magma G}.
Bind Scope group_scope with BaseUMagma.sort.
HB.structure Definition ChoiceBaseUMagma := {G of BaseUMagma G & Choice G}.
Bind Scope group_scope with ChoiceBaseUMagma.sort.
Local Notation "1" := (@one _) : group_scope.
Local Notation "s `_ i" := (nth 1 s i) : group_scope.
Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%g/1]_(i <- r | P) F).
Local Notation "\prod_ ( i | P ) F" := (\big[*%g/1]_(i | P) F).
Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%g/1]_(i in A) F).
Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%g/1%g]_(m <= i < n) F%g).
Definition natexp (G : baseUMagmaType) (x : G) n : G := iterop n *%g x 1.
Arguments natexp : simpl never.
Local Notation "x ^+ n" := (natexp x n) : group_scope.
Section baseUMagmaTheory.
Variable G : baseUMagmaType.
Implicit Types x : G.
Lemma expg0 x : x ^+ 0 = 1. Proof. by []. Qed.
Lemma expg1 x : x ^+ 1 = x. Proof. by []. Qed.
Lemma expg2 x : x ^+ 2 = x * x. Proof. by []. Qed.
Lemma expgSS x n : x ^+ n.+2 = x * x ^+ n.+1.
Proof. by []. Qed.
Lemma expgb x (b : bool) : x ^+ b = (if b then x else 1).
Proof. by case: b. Qed.
Section ClosedPredicates.
Variable S : {pred G}.
Definition umagma_closed := 1 \in S /\ mulg_closed S.
End ClosedPredicates.
End baseUMagmaTheory.
HB.mixin Record BaseUMagma_isUMagma G of BaseUMagma G := {
mul1g : left_id one (@mul G);
mulg1 : right_id one (@mul G)
}.
HB.factory Record Magma_isUMagma G of Magma G := {
one : G;
mul1g : left_id one (@mul G);
mulg1 : right_id one (@mul G)
}.
HB.builders Context G of Magma_isUMagma G.
HB.instance Definition _ := hasOne.Build G one.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := BaseUMagma_isUMagma.Build G mul1g mulg1.
HB.end.
#[short(type="umagmaType")]
HB.structure Definition UMagma := {G of Magma_isUMagma G & ChoiceMagma G}.
Bind Scope group_scope with UMagma.sort.
Section UMagmaTheory.
Variable G : umagmaType.
Implicit Types x y : G.
Lemma expgS x n : x ^+ n.+1 = x * x ^+ n.
Proof. by case: n => //=; rewrite mulg1. Qed.
Lemma expg1n n : 1 ^+ n = 1 :> G.
Proof. by elim: n => // n IHn; rewrite expgS mul1g. Qed.
Lemma commute1 x : commute x 1.
Proof. by rewrite /commute mulg1 mul1g. Qed.
End UMagmaTheory.
#[short(type="monoidType")]
HB.structure Definition Monoid := {G of Magma_isUMagma G & Semigroup G}.
HB.factory Record Semigroup_isMonoid G of Semigroup G := {
one : G;
mul1g : left_id one mul;
mulg1 : right_id one mul
}.
HB.builders Context G of Semigroup_isMonoid G.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.end.
HB.factory Record UMagma_isMonoid G of UMagma G := {
mulgA : associative (@mul G)
}.
HB.builders Context G of UMagma_isMonoid G.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.end.
HB.factory Record isMonoid G of Choice G := {
mul : G -> G -> G;
one : G;
mulgA : associative mul;
mul1g : left_id one mul;
mulg1 : right_id one mul
}.
HB.builders Context G of isMonoid G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.end.
#[export]
HB.instance Definition _ (G : monoidType) := Monoid.isLaw.Build G 1 *%g mulgA mul1g mulg1.
Bind Scope group_scope with Monoid.sort.
Section MonoidTheory.
Variable G : monoidType.
Implicit Types x y : G.
Lemma expgSr x n : x ^+ n.+1 = x ^+ n * x.
Proof.
elim: n => [|n IHn]; first by rewrite mul1g.
by rewrite expgS [in LHS]IHn expgS mulgA.
Qed.
Lemma expgnDr x m n : x ^+ (m + n) = x ^+ m * x ^+ n.
Proof.
elim: m => [|m IHm]; first by rewrite mul1g.
by rewrite 2!expgS IHm mulgA.
Qed.
Lemma expgnA x m n : x ^+ (m * n) = x ^+ m ^+ n.
Proof. by rewrite mulnC; elim: n => //= n IHn; rewrite expgS expgnDr IHn. Qed.
Lemma expgnAC x m n : x ^+ m ^+ n = x ^+ n ^+ m.
Proof. by rewrite -2!expgnA mulnC. Qed.
Lemma iter_mulg n x y : iter n ( *%g x) y = x ^+ n * y.
Proof. by elim: n => [|n IHn]; rewrite ?mul1g //= IHn expgS mulgA. Qed.
Lemma iter_mulg_1 n x : iter n ( *%g x) 1 = x ^+ n.
Proof. by rewrite iter_mulg mulg1. Qed.
Lemma prodg_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|.
Proof. by rewrite big_const -Monoid.iteropE. Qed.
Lemma prodg_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n).
Proof. by rewrite big_const_nat -Monoid.iteropE. Qed.
Lemma prodgXr x I r P (F : I -> nat) :
\prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i).
Proof. by rewrite (big_morph _ (expgnDr _) (erefl _)). Qed.
Lemma commute_prod (I : Type) (s : seq I) (P : pred I) (F : I -> G) x :
(forall i, P i -> commute x (F i)) -> commute x (\prod_(i <- s | P i) F i).
Proof. exact: (big_ind _ (commute1 x) (@commuteM _ x)). Qed.
Lemma prodgM_commute {I : eqType} r (P : pred I) (F H : I -> G) :
(forall i j, P i -> P j -> commute (F i) (H j)) ->
\prod_(i <- r | P i) (F i * H i) =
\prod_(i <- r | P i) F i * \prod_(i <- r | P i) H i.
Proof.
move=> FH; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulg1//.
case: ifPn => // Pi; rewrite IHr !mulgA; congr (_ * _); rewrite -!mulgA.
by rewrite commute_prod // => j Pj; apply/commute_sym/FH.
Qed.
Lemma prodgMl_commute {I : finType} (A : pred I) (x : G) F :
(forall i, A i -> commute x (F i)) ->
\prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i.
Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j _ /xF. Qed.
Lemma prodgMr_commute {I : finType} (A : pred I) (x : G) F :
(forall i, A i -> commute x (F i)) ->
\prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|.
Proof. by move=> xF; rewrite prodgM_commute ?prodg_const// => i j /xF. Qed.
Lemma commuteX x y n : commute x y -> commute x (y ^+ n).
Proof.
by move=> cxy; case: n; [apply: commute1 | elim=> // n; apply: commuteM].
Qed.
Lemma commuteX2 x y m n : commute x y -> commute (x ^+ m) (y ^+ n).
Proof. by move=> cxy; apply/commuteX/commute_sym/commuteX. Qed.
Lemma expgMn x y n : commute x y -> (x * y) ^+ n = x ^+ n * y ^+ n.
Proof.
move=> cxy; elim: n => [|n IHn]; first by rewrite mulg1.
by rewrite !expgS IHn -mulgA (mulgA y) (commuteX _ (commute_sym cxy)) !mulgA.
Qed.
End MonoidTheory.
Notation monoid_closed := umagma_closed.
HB.mixin Record hasInv G := {
inv : G -> G
}.
#[short(type="baseGroupType")]
HB.structure Definition BaseGroup := {G of hasInv G & BaseUMagma G}.
Bind Scope group_scope with BaseGroup.sort.
HB.mixin Record Monoid_isGroup G of BaseGroup G := {
mulVg : left_inverse one inv (@mul G);
mulgV : right_inverse one inv (@mul G)
}.
#[short(type="groupType")]
HB.structure Definition Group :=
{G of Monoid_isGroup G & BaseGroup G & Monoid G}.
HB.factory Record isGroup G of Choice G := {
one : G;
inv : G -> G;
mul : G -> G -> G;
mulgA : associative mul;
mul1g : left_id one mul;
mulg1 : right_id one mul;
mulVg : left_inverse one inv mul;
mulgV : right_inverse one inv mul
}.
HB.builders Context G of isGroup G.
HB.instance Definition _ := hasMul.Build G mul.
HB.instance Definition _ := Magma_isSemigroup.Build G mulgA.
HB.instance Definition _ := Magma_isUMagma.Build G mul1g mulg1.
HB.instance Definition _ := hasInv.Build G inv.
HB.instance Definition _ := Monoid_isGroup.Build G mulVg mulgV.
HB.end.
Bind Scope group_scope with Group.sort.
Local Notation "x ^-1" := (inv x) : group_scope.
Local Notation "x / y" := (x * y^-1) : group_scope.
Local Notation "x ^- n" := ((x ^+ n)^-1) : group_scope.
Definition conjg (G : groupType) (x y : G) := y^-1 * (x * y).
Local Notation "x ^ y" := (conjg x y) : group_scope.
Definition commg (G : groupType) (x y : G) := x^-1 * (conjg x y).
Local Notation "[~ x , y ]" := (commg x y) : group_scope.
Section GroupTheory.
Variable G : groupType.
Implicit Types x y : G.
Definition divgg := @mulgV G.
Lemma mulKg : @left_loop G G (@inv G) *%g.
Proof. by move=> x y; rewrite mulgA mulVg mul1g. Qed.
Lemma mulVKg : @rev_left_loop G G (@inv G) *%g.
Proof. by move=> x y ; rewrite mulgA mulgV mul1g. Qed.
Lemma mulgK : @right_loop G G (@inv G) *%g.
Proof. by move=> x y; rewrite -mulgA mulgV mulg1. Qed.
Lemma mulgVK : @rev_right_loop G G (@inv G) *%g.
Proof. by move=> x y ; rewrite -mulgA mulVg mulg1. Qed.
Definition divgK := mulgVK.
Lemma mulgI : @right_injective G G G *%g.
Proof. by move=> x; apply: can_inj (mulKg x). Qed.
Lemma mulIg : @left_injective G G G *%g.
Proof. by move=> x; apply: can_inj (mulgK x). Qed.
Lemma invgK : @involutive G (@inv G).
Proof. by move=> x; rewrite -[LHS](mulVKg x) divgg mulg1. Qed.
Lemma invg_inj : @injective G G (@inv G).
Proof. exact: inv_inj invgK. Qed.
Lemma divgI : @right_injective G G G (fun x y => x / y).
Proof. by move=> x y z /mulgI/invg_inj. Qed.
Lemma divIg : @left_injective G G G (fun x y => x / y).
Proof. by move=> x y z /mulIg. Qed.
Lemma invg1 : 1 ^-1 = 1 :> G.
Proof. by rewrite -[LHS]mul1g divgg. Qed.
Lemma invg_eq1 x : (x ^-1 == 1) = (x == 1).
Proof. by rewrite (inv_eq invgK) invg1. Qed.
Lemma divg1 x : x / 1 = x. Proof. by rewrite invg1 mulg1. Qed.
Lemma div1g x : 1 / x = x^-1. Proof. by rewrite mul1g. Qed.
Lemma invgF x y : (x / y)^-1 = y / x.
Proof. by apply/(canRL (mulgK x))/(@divIg y); rewrite -mulgA mulVg divgg. Qed.
Lemma invgM : {morph (@inv G): x y / x * y >-> y * x : G}.
Proof. by move=> x y; rewrite -[y in LHS]invgK invgF. Qed.
Lemma prodgV I r (P : pred I) (E : I -> G) :
\prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- rev r | P i) E i)^-1.
Proof.
elim: r => [|x r IHr]; first by rewrite !big_nil invg1.
rewrite big_cons rev_cons big_rcons/= IHr.
by case: ifP => _; rewrite ?mulg1// invgM.
Qed.
Lemma divKg x y : commute x y -> x / (x / y) = y.
Proof. by move=> xyC; rewrite invgF mulgA xyC mulgK. Qed.
(* TOTHINK : This does not have the same form as addrKA in ssralg.v *)
Lemma mulgKA z x y : (x * z) / (y * z) = x / y.
Proof. by rewrite invgM mulgA mulgK. Qed.
Lemma divgKA z x y : (x / z) * (z * y) = x * y.
Proof. by rewrite mulgA mulgVK. Qed.
Lemma mulg1_eq x y : x * y = 1 -> x^-1 = y.
Proof. by rewrite -[x^-1]mulg1 => <-; rewrite mulKg. Qed.
Lemma divg1_eq x y : x / y = 1 -> x = y.
Proof. by move/mulg1_eq/invg_inj. Qed.
Lemma divg_eq x y z : (x / z == y) = (x == y * z).
Proof. exact: can2_eq (divgK z) (mulgK z) x y. Qed.
Lemma divg_eq1 x y : (x / y == 1) = (x == y).
Proof. by rewrite divg_eq mul1g. Qed.
Lemma mulg_eq1 x y : (x * y == 1) = (x == y^-1).
Proof. by rewrite -[y in LHS]invgK divg_eq1. Qed.
Lemma eqg_inv x y : (x^-1 == y^-1) = (x == y).
Proof. exact: can_eq invgK x y. Qed.
Lemma eqg_invLR x y : (x^-1 == y) = (x == y^-1).
Proof. exact: inv_eq invgK x y. Qed.
Lemma commuteV x y : commute x y -> commute x y^-1.
Proof. by move=> cxy; apply: (@mulIg y); rewrite mulgVK -mulgA cxy mulKg. Qed.
Lemma expVgn x n : (x^-1) ^+ n = x ^- n.
Proof.
apply/esym/mulg1_eq; rewrite -expgMn; first by rewrite divgg expg1n.
exact/commuteV.
Qed.
Lemma expgnFr x m n : n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n.
Proof. by move=> lenm; rewrite -[in RHS](subnK lenm) expgnDr mulgK. Qed.
Lemma expgnFl x y n : commute x y -> (x / y) ^+ n = x ^+ n / y ^+ n.
Proof. by move=> xyC; rewrite expgMn 1?expVgn; last exact/commuteV. Qed.
Lemma conjgE x y : x ^ y = y^-1 * (x * y). Proof. by []. Qed.
Lemma conjgC x y : x * y = y * x ^ y.
Proof. by rewrite mulVKg. Qed.
Lemma conjgCV x y : x * y = y ^ x^-1 * x.
Proof. by rewrite -mulgA mulgVK invgK. Qed.
Lemma conjg1 x : x ^ 1 = x.
Proof. by rewrite conjgE commute1 mulKg. Qed.
Lemma conj1g x : 1 ^ x = 1.
Proof. by rewrite conjgE mul1g mulVg. Qed.
Lemma conjMg x y z : (x * y) ^ z = x ^ z * y ^ z.
Proof. by rewrite !conjgE !mulgA mulgK. Qed.
Lemma conjgM x y z : x ^ (y * z) = (x ^ y) ^ z.
Proof. by rewrite !conjgE invgM !mulgA. Qed.
Lemma conjVg x y : x^-1 ^ y = (x ^ y)^-1.
Proof. by rewrite !conjgE !invgM invgK mulgA. Qed.
Lemma conjJg x y z : (x ^ y) ^ z = (x ^ z) ^ y ^ z.
Proof. by rewrite 2!conjMg conjVg. Qed.
Lemma conjXg x y n : (x ^+ n) ^ y = (x ^ y) ^+ n.
Proof. by elim: n => [|n IHn]; rewrite ?conj1g // !expgS conjMg IHn. Qed.
Lemma conjgK : @right_loop G G (@inv G) (@conjg G).
Proof. by move=> y x; rewrite -conjgM mulgV conjg1. Qed.
Lemma conjgKV : @rev_right_loop G G (@inv G) (@conjg G).
Proof. by move=> y x; rewrite -conjgM mulVg conjg1. Qed.
Lemma conjg_inj : @left_injective G G G (@conjg G).
Proof. by move=> y; apply: can_inj (conjgK y). Qed.
Lemma conjg_eq1 x y : (x ^ y == 1) = (x == 1).
Proof. by rewrite (can2_eq (conjgK _) (conjgKV _)) conj1g. Qed.
Lemma commgEl x y : [~ x, y] = x^-1 * x ^ y. Proof. by []. Qed.
Lemma commgEr x y : [~ x, y] = y^-1 ^ x * y.
Proof. by rewrite -!mulgA. Qed.
Lemma commgC x y : x * y = y * x * [~ x, y].
Proof. by rewrite -mulgA !mulVKg. Qed.
Lemma commgCV x y : x * y = [~ x^-1, y^-1] * (y * x).
Proof. by rewrite commgEl !mulgA !invgK !mulgVK. Qed.
Lemma conjRg x y z : [~ x, y] ^ z = [~ x ^ z, y ^ z].
Proof. by rewrite !conjMg !conjVg. Qed.
Lemma invgR x y : [~ x, y]^-1 = [~ y, x].
Proof. by rewrite commgEr conjVg invgM invgK. Qed.
Lemma commgP x y : reflect (commute x y) ([~ x, y] == 1).
Proof. rewrite [[~ x, y]]mulgA -invgM mulg_eq1 eqg_inv eq_sym; apply: eqP. Qed.
Lemma conjg_fix x y : x ^ y == x = ([~ x, y] == 1).
Proof. by rewrite mulg_eq1 eqg_inv. Qed.
Lemma conjg_fixP x y : reflect (x ^ y = x) ([~ x, y] == 1).
Proof. by rewrite -conjg_fix; apply: eqP. Qed.
Lemma commg1_sym x y : ([~ x, y] == 1) = ([~ y, x] == 1).
Proof. by rewrite -invgR (inv_eq invgK) invg1. Qed.
Lemma commg1 x : [~ x, 1] = 1.
Proof. exact/eqP/commgP/commute1. Qed.
Lemma comm1g x : [~ 1, x] = 1.
Proof. by rewrite -invgR commg1 invg1. Qed.
Lemma commgg x : [~ x, x] = 1.
Proof. exact/eqP/commgP. Qed.
Lemma commgXg x n : [~ x, x ^+ n] = 1.
Proof. exact/eqP/commgP/commuteX. Qed.
Lemma commgVg x : [~ x, x^-1] = 1.
Proof. exact/eqP/commgP/commuteV. Qed.
Lemma commgXVg x n : [~ x, x ^- n] = 1.
Proof. exact/eqP/commgP/commuteV/commuteX. Qed.
Section ClosedPredicates.
Variable S : {pred G}.
Definition invg_closed := {in S, forall u, u^-1 \in S}.
Definition divg_closed := {in S &, forall u v, u / v \in S}.
Definition group_closed := 1 \in S /\ divg_closed.
Lemma group_closedV : group_closed -> invg_closed.
Proof. by move=> [S1 SB] x /(SB 1)-/(_ S1); rewrite div1g. Qed.
Lemma group_closedM : group_closed -> mulg_closed S.
Proof.
move=> /[dup]-[S1 SB] /group_closedV SV x y xS /SV yS.
rewrite -[y]invgK; exact: SB.
Qed.
End ClosedPredicates.
End GroupTheory.
(* Morphism hierarchy. *)
HB.mixin Record isMultiplicative (G H : magmaType) (apply : G -> H) := {
gmulfM : {morph apply : x y / x * y}
}.
HB.structure Definition Multiplicative (G H : magmaType) :=
{f of isMultiplicative G H f}.
(* TODO: define pointedTypes and generalize this to pointedTypes. *)
HB.mixin Record Multiplicative_isUMagmaMorphism (G H : baseUMagmaType)
(f : G -> H) := {
gmulf1 : f 1 = 1
}.
HB.structure Definition UMagmaMorphism (G H : baseUMagmaType) :=
{f of Multiplicative_isUMagmaMorphism G H f & isMultiplicative G H f}.
Definition monoid_morphism (G H : baseUMagmaType) (f : G -> H) : Prop :=
(f 1 = 1) * {morph f : x y / x * y}.
HB.factory Record isUMagmaMorphism (G H : baseUMagmaType) (f : G -> H) := {
monoid_morphism_subproof : monoid_morphism f
}.
HB.builders Context G H apply of isUMagmaMorphism G H apply.
HB.instance Definition _ :=
isMultiplicative.Build G H apply monoid_morphism_subproof.2.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H apply monoid_morphism_subproof.1.
HB.end.
HB.factory Record isGroupMorphism (G H : groupType) (f : G -> H) := {
gmulfF : {morph f : x y / x / y}
}.
HB.builders Context G H apply of isGroupMorphism G H apply.
Local Lemma gmulf1 : apply 1 = 1.
Proof. by rewrite -[1]divg1 gmulfF divgg. Qed.
Local Lemma gmulfM : {morph apply : x y / x * y}.
Proof.
move=> x y; rewrite -[y in LHS] invgK -[y^-1]mul1g.
by rewrite !gmulfF gmulf1 div1g invgK.
Qed.
HB.instance Definition _ := isMultiplicative.Build G H apply gmulfM.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H apply gmulf1.
HB.end.
Module MultiplicativeExports.
Notation "{ 'multiplicative' U -> V }" :=
(Multiplicative.type U%type V%type) : type_scope.
End MultiplicativeExports.
HB.export MultiplicativeExports.
(* FIXME: The instance below makes sure that the join instance between *)
(* Multiplicative.type and UMagmaMorphism.type is declared in both directions.*)
(* HB should do this automatically. *)
#[non_forgetful_inheritance]
HB.instance Definition _ G H (f : UMagmaMorphism.type G H) :=
UMagmaMorphism.on (Multiplicative.sort f).
Section LiftedMagma.
Variables (T : Type) (G : magmaType).
Definition mul_fun (f g : T -> G) x := f x * g x.
End LiftedMagma.
Section LiftedBaseUMagma.
Variables (T : Type) (G : baseUMagmaType).
Definition one_fun : T -> G := fun=> 1.
End LiftedBaseUMagma.
Local Notation "\1" := (one_fun _) : function_scope.
Local Notation "f \* g" := (mul_fun f g) : function_scope.
Arguments one_fun {_} G _ /.
Arguments mul_fun {_ _} f g _ /.
Section MorphismTheory.
Section Magma.
Variables (G H : magmaType) (f : {multiplicative G -> H}).
Lemma can2_gmulfM f' : cancel f f' -> cancel f' f -> {morph f' : x y / x * y}.
Proof. by move=> fK f'K x y; apply: (canLR fK); rewrite gmulfM !f'K. Qed.
Lemma gmulf_commute x y : commute x y -> commute (f x) (f y).
Proof. by move=> xy; rewrite /commute -!gmulfM xy. Qed.
End Magma.
Section UMagma.
Variables (G H : umagmaType) (f : UMagmaMorphism.type G H).
Lemma gmulf_eq1 x : injective f -> (f x == 1) = (x == 1).
Proof. by move=> /inj_eq <-; rewrite gmulf1. Qed.
Lemma can2_gmulf1 f' : cancel f f' -> cancel f' f -> f' 1 = 1.
Proof. by move=> fK f'K; apply: (canLR fK); rewrite gmulf1. Qed.
Lemma gmulfXn n : {morph f : x / x ^+ n}.
Proof. by elim: n => [|[|n] IHn] x /=; rewrite ?(gmulf1, gmulfM) // IHn. Qed.
Lemma gmulf_prod I r (P : pred I) E :
f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i).
Proof. exact: (big_morph f gmulfM gmulf1). Qed.
End UMagma.
Section Group.
Variables (G H : groupType) (f : UMagmaMorphism.type G H).
Lemma gmulfV : {morph f : x / x^-1}.
Proof. by move=> x; apply/divg1_eq; rewrite invgK -gmulfM mulVg gmulf1. Qed.
Lemma gmulfF : {morph f : x y / x / y}.
Proof. by move=> x y; rewrite gmulfM gmulfV. Qed.
Lemma gmulf_inj : (forall x, f x = 1 -> x = 1) -> injective f.
Proof. by move=> fI x y xy; apply/divg1_eq/fI; rewrite gmulfF xy divgg. Qed.
Lemma gmulfXVn n : {morph f : x / x ^- n}.
Proof. by move=> x /=; rewrite gmulfV gmulfXn. Qed.
Lemma gmulfJ : {morph f : x y / x ^ y}.
Proof. by move=> x y; rewrite !gmulfM/= gmulfV. Qed.
Lemma gmulfR : {morph f : x y / [~ x, y]}.
Proof. by move=> x y; rewrite !gmulfM/= !gmulfV. Qed.
End Group.
Section MulFun.
Variables (G H K : magmaType).
Variables (f g : {multiplicative H -> K}) (h : {multiplicative G -> H}).
Fact idfun_gmulfM : {morph @idfun G : x y / x * y}.
Proof. by []. Qed.
HB.instance Definition _ := isMultiplicative.Build G G idfun idfun_gmulfM.
Fact comp_gmulfM : {morph f \o h : x y / x * y}.
Proof. by move=> x y /=; rewrite !gmulfM. Qed.
HB.instance Definition _ := isMultiplicative.Build G K (f \o h) comp_gmulfM.
End MulFun.
Section Mul1Fun.
Variables (G : magmaType) (H : umagmaType).
Fact idfun_gmulf1 : idfun 1 = 1 :> H.
Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build H H idfun idfun_gmulf1.
Fact one_fun_gmulfM : {morph @one_fun G H : x y / x * y}.
Proof. by move=> x y; rewrite mulg1. Qed.
HB.instance Definition _ :=
isMultiplicative.Build G H (@one_fun G H) one_fun_gmulfM.
End Mul1Fun.
Section Mul11Fun.
Variables (G H K : umagmaType).
Variables (f g : UMagmaMorphism.type H K) (h : UMagmaMorphism.type G H).
Fact comp_gmulf1 : (f \o h) 1 = 1.
Proof. by rewrite /= !gmulf1. Qed.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G K (f \o h) comp_gmulf1.
Fact one_fun_gmulf1 : @one_fun G H 1 = 1.
Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build G H (@one_fun G H) one_fun_gmulf1.
Fact mul_fun_gmulf1 : (f \* g) 1 = 1.
Proof. by rewrite /= !gmulf1 mulg1. Qed.
End Mul11Fun.
End MorphismTheory.
(* Mixins for stability properties *)
HB.mixin Record isMulClosed (G : magmaType) (S : {pred G}) := {
gpredM : mulg_closed S
}.
HB.mixin Record isMul1Closed (G : baseUMagmaType) (S : {pred G}) := {
gpred1 : 1 \in S
}.
HB.mixin Record isInvClosed (G : groupType) (S : {pred G}) := {
gpredVr : invg_closed S
}.
(* Structures for stability properties *)
#[short(type="mulgClosed")]
HB.structure Definition MulClosed G := {S of isMulClosed G S}.
#[short(type="umagmaClosed")]
HB.structure Definition UMagmaClosed G :=
{S of isMul1Closed G S & isMulClosed G S}.
#[short(type="invgClosed")]
HB.structure Definition InvClosed G := {S of isInvClosed G S}.
#[short(type="groupClosed")]
HB.structure Definition GroupClosed G :=
{S of isInvClosed G S & isMul1Closed G S & isMulClosed G S}.
Section UMagmaPred.
Variables (G : baseUMagmaType).
Section UMagma.
Variables S : umagmaClosed G.
Lemma gpred_prod I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S.
Proof. by move=> IH; elim/big_ind: _; [apply: gpred1 | apply: gpredM |]. Qed.
Lemma gpredXn n : {in S, forall u, u ^+ n \in S}.
Proof.
by move=> x xS; elim: n => [|[//|n] IHn]; [exact: gpred1 | exact: gpredM].
Qed.
End UMagma.
End UMagmaPred.
Section GroupPred.
Variables (G : groupType).
Lemma gpredV (S : invgClosed G) : {mono (@inv G): u / u \in S}.
Proof. by move=> u; apply/idP/idP=> /gpredVr; rewrite ?invgK; apply. Qed.
Section Group.
Variables S : groupClosed G.
Lemma gpredF : {in S &, forall u v, u / v \in S}.
Proof. by move=> x y xS yS; rewrite gpredM// gpredV. Qed.
Lemma gpredFC u v : u / v \in S = (v / u \in S).
Proof. by rewrite -gpredV invgF. Qed.
Lemma gpredXNn n: {in S, forall u, u ^- n \in S}.
Proof. by move=> x xS; apply/gpredVr/gpredXn. Qed.
Lemma gpredMr x y : x \in S -> (y * x \in S) = (y \in S).
Proof.
move=> Sx; apply/idP/idP => [Sxy|/gpredM-> //].
by rewrite -(mulgK x y) gpredF.
Qed.
Lemma gpredMl x y : x \in S -> (x * y \in S) = (y \in S).
Proof.
move=> Sx; apply/idP/idP => [Sxy|/(gpredM x y Sx)//].
by rewrite -(mulKg x y) gpredM// gpredV.
Qed.
Lemma gpredFr x y : x \in S -> (y / x \in S) = (y \in S).
Proof. by rewrite -gpredV; apply: gpredMr. Qed.
Lemma gpredFl x y : x \in S -> (x / y \in S) = (y \in S).
Proof. by rewrite -(gpredV S y); apply: gpredMl. Qed.
Lemma gpredJ x y : x \in S -> y \in S -> x ^ y \in S.
Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredM]. Qed.
Lemma gpredR x y : x \in S -> y \in S -> [~ x, y] \in S.
Proof. by move=> xS yS; apply/gpredM; [apply/gpredVr|apply/gpredJ]. Qed.
End Group.
End GroupPred.
HB.mixin Record isSubMagma (G : magmaType) (S : pred G) H
of SubType G S H & Magma H := {
valM_subproof : {morph (val : H -> G) : x y / x * y}
}.
#[short(type="subMagmaType")]
HB.structure Definition SubMagma (G : magmaType) S :=
{ H of SubChoice G S H & Magma H & isSubMagma G S H }.
Section subMagma.
Context (G : magmaType) (S : pred G) (H : subMagmaType S).
Notation val := (val : H -> G).
HB.instance Definition _ := isMultiplicative.Build H G val valM_subproof.
Lemma valM : {morph val : x y / x * y}. Proof. exact: gmulfM. Qed.
End subMagma.
HB.factory Record SubChoice_isSubMagma (G : magmaType) S H
of SubChoice G S H := {
mulg_closed_subproof : mulg_closed S
}.
HB.builders Context G S H of SubChoice_isSubMagma G S H.
HB.instance Definition _ := isMulClosed.Build G S mulg_closed_subproof.
Let inH v Sv : H := Sub v Sv.
Let mulH (u1 u2 : H) := inH (gpredM _ _ (valP u1) (valP u2)).
HB.instance Definition _ := hasMul.Build H mulH.
Lemma valM : {morph (val : H -> G) : x y / x * y}.
Proof. by move=> x y; rewrite SubK. Qed.
HB.instance Definition _ := isSubMagma.Build G S H valM.
HB.end.
#[short(type="subSemigroupType")]
HB.structure Definition SubSemigroup (G : semigroupType) S :=
{ H of SubMagma G S H & Semigroup H}.
HB.factory Record SubChoice_isSubSemigroup (G : semigroupType) S H
of SubChoice G S H := {
mulg_closed_subproof : mulg_closed S
}.
HB.builders Context G S H of SubChoice_isSubSemigroup G S H.
HB.instance Definition _ :=
SubChoice_isSubMagma.Build G S H mulg_closed_subproof.
Lemma mulgA : associative (@mul H).
Proof. by move=> x y z; apply/val_inj; rewrite !valM mulgA. Qed.
HB.instance Definition _ := isSemigroup.Build H mulgA.
HB.end.
HB.mixin Record isSubBaseUMagma (G : baseUMagmaType) (S : pred G) H
of SubMagma G S H & BaseUMagma H := {
val1_subproof : (val : H -> G) 1 = 1
}.
#[short(type="subBaseUMagmaType")]
HB.structure Definition SubBaseUMagma (G : umagmaType) S :=
{ H of SubMagma G S H & BaseUMagma H & isSubBaseUMagma G S H}.
#[short(type="subUMagmaType")]
HB.structure Definition SubUMagma (G : umagmaType) S :=
{ H of SubMagma G S H & UMagma H & isSubBaseUMagma G S H}.
Section subUMagma.
Context (G : umagmaType) (S : pred G) (H : subUMagmaType S).
Notation val := (val : H -> G).
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build H G val val1_subproof.
Lemma val1 : val 1 = 1. Proof. exact: gmulf1. Qed.
End subUMagma.
HB.factory Record SubChoice_isSubUMagma (G : umagmaType) S H
of SubChoice G S H := {
umagma_closed_subproof : umagma_closed S
}.
HB.builders Context G S H of SubChoice_isSubUMagma G S H.
HB.instance Definition _ :=
SubChoice_isSubMagma.Build G S H (snd umagma_closed_subproof).
Let inH v Sv : H := Sub v Sv.
Let oneH := inH (fst umagma_closed_subproof).
HB.instance Definition _ := hasOne.Build H oneH.
Lemma val1 : (val : H -> G) 1 = 1.
Proof. exact/SubK. Qed.
HB.instance Definition _ := isSubBaseUMagma.Build G S H val1.
Lemma mul1g : left_id 1 (@mul H).
Proof. by move=> x; apply/val_inj; rewrite valM val1 mul1g. Qed.
Lemma mulg1 : right_id 1 (@mul H).
Proof. by move=> x; apply/val_inj; rewrite valM val1 mulg1. Qed.
HB.instance Definition _ := BaseUMagma_isUMagma.Build H mul1g mulg1.
HB.end.
#[short(type="subMonoidType")]
HB.structure Definition SubMonoid (G : monoidType) S :=
{ H of SubUMagma G S H & Monoid H}.
HB.factory Record SubChoice_isSubMonoid (G : monoidType) S H
of SubChoice G S H := {
monoid_closed_subproof : monoid_closed S
}.
HB.builders Context G S H of SubChoice_isSubMonoid G S H.
HB.instance Definition _ :=
SubChoice_isSubUMagma.Build G S H monoid_closed_subproof.
HB.instance Definition _ :=
SubChoice_isSubSemigroup.Build G S H (snd monoid_closed_subproof).
HB.end.
#[short(type="subGroupType")]
HB.structure Definition SubGroup (G : groupType) S :=
{ H of SubUMagma G S H & Group H}.
HB.factory Record SubChoice_isSubGroup (G : groupType) S H
of SubChoice G S H := {
group_closed_subproof : group_closed S
}.
HB.builders Context G S H of SubChoice_isSubGroup G S H.
Lemma umagma_closed : umagma_closed S.
Proof.
split; first exact/(fst group_closed_subproof).
exact/group_closedM/group_closed_subproof.
Qed.
HB.instance Definition _ := SubChoice_isSubMonoid.Build G S H umagma_closed.
HB.instance Definition _ :=
isInvClosed.Build G S (group_closedV group_closed_subproof).
Let inH v Sv : H := Sub v Sv.
Let invH (u : H) := inH (gpredVr _ (valP u)).
HB.instance Definition _ := hasInv.Build H invH.
Lemma mulVg : left_inverse 1%g invH *%g.
Proof. by move=> x; apply/val_inj; rewrite valM SubK mulVg val1. Qed.
Lemma mulgV : right_inverse 1%g invH *%g.
Proof. by move=> x; apply/val_inj; rewrite valM SubK mulgV val1. Qed.
HB.instance Definition _ := Monoid_isGroup.Build H mulVg mulgV.
HB.end.
(* Lifting Structure from the codomain of finfuns. *)
Section FinFunMagma.
Variable (aT : finType) (rT : magmaType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_mul f g := [ffun a => f a * g a].
HB.instance Definition _ := hasMul.Build {ffun aT -> rT} ffun_mul.
End FinFunMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : ChoiceMagma.type) :=
Magma.on {ffun aT -> rT}.
Section FinFunSemigroup.
Variable (aT : finType) (rT : semigroupType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mulgA : associative (@ffun_mul aT rT).
Proof. by move=> f1 f2 f3; apply/ffunP=> a; rewrite !ffunE mulgA. Qed.
HB.instance Definition _ := isSemigroup.Build {ffun aT -> rT} ffun_mulgA.
End FinFunSemigroup.
Section FinFunBaseUMagma.
Variable (aT : finType) (rT : baseUMagmaType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_one := [ffun a : aT => (1 : rT)].
HB.instance Definition _ :=
hasOne.Build {ffun aT -> rT} ffun_one.
End FinFunBaseUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : ChoiceBaseUMagma.type) :=
BaseUMagma.on {ffun aT -> rT}.
Section FinFunUMagma.
Variable (aT : finType) (rT : umagmaType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mul1g : left_id (@ffun_one aT rT) *%g.
Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mul1g. Qed.
Fact ffun_mulg1 : right_id (@ffun_one aT rT) *%g.
Proof. by move=> f; apply/ffunP => a; rewrite !ffunE mulg1. Qed.
HB.instance Definition _ :=
Magma_isUMagma.Build {ffun aT -> rT} ffun_mul1g ffun_mulg1.
End FinFunUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (aT : finType) (rT : monoidType) :=
UMagma.on {ffun aT -> rT}.
Section FinFunBaseGroup.
Variable (aT : finType) (rT : baseGroupType).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_inv f := [ffun a => (f a)^-1].
HB.instance Definition _ := hasInv.Build {ffun aT -> rT} ffun_inv.
End FinFunBaseGroup.
Section FinFunGroup.
Variable (aT : finType) (rT : groupType).
Implicit Types f g : {ffun aT -> rT}.
Fact ffun_mulVg :
left_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _).
Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulVg. Qed.
Fact ffun_mulgV :
right_inverse (@ffun_one aT rT) (@ffun_inv _ _) (@ffun_mul _ _).
Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE mulgV. Qed.
HB.instance Definition _ := Monoid_isGroup.Build {ffun aT -> rT}
ffun_mulVg ffun_mulgV.
End FinFunGroup.
(* External direct product *)
Section PairMagma.
Variables G H : magmaType.
Definition mul_pair (x y : G * H) := (x.1 * y.1, x.2 * y.2).
HB.instance Definition _ := hasMul.Build (G * H)%type mul_pair.
Fact fst_is_multiplicative : {morph fst : x y / x * y}. Proof. by []. Qed.
HB.instance Definition _ :=
isMultiplicative.Build _ _ fst fst_is_multiplicative.
Fact snd_is_multiplicative : {morph snd : x y / x * y}. Proof. by []. Qed.
HB.instance Definition _ :=
isMultiplicative.Build _ _ snd snd_is_multiplicative.
End PairMagma.
Section PairSemigroup.
Variables G H : semigroupType.
Lemma pair_mulgA : associative (@mul (G * H)%type).
Proof. by move=> x y z; congr (_, _); apply/mulgA. Qed.
HB.instance Definition _ := Magma_isSemigroup.Build (G * H)%type pair_mulgA.
End PairSemigroup.
Section PairBaseUMagma.
Variables G H : baseUMagmaType.
Definition one_pair : G * H := (1, 1).
HB.instance Definition _ := hasOne.Build (G * H)%type one_pair.
Fact fst_is_umagma_morphism : fst (1 : G * H) = 1. Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build _ _ fst fst_is_umagma_morphism.
Fact snd_is_umagma_morphism : snd (1 : G * H) = 1. Proof. by []. Qed.
HB.instance Definition _ :=
Multiplicative_isUMagmaMorphism.Build _ _ snd snd_is_umagma_morphism.
End PairBaseUMagma.
Section PairUMagma.
Variables G H : umagmaType.
Lemma pair_mul1g : left_id (@one_pair G H) *%g.
Proof. by move=> [x y]; congr (_, _); rewrite mul1g. Qed.
Lemma pair_mulg1 : right_id (@one_pair G H) *%g.
Proof. by move=> [x y]; congr (_, _); rewrite mulg1. Qed.
HB.instance Definition _ :=
BaseUMagma_isUMagma.Build (G * H)%type pair_mul1g pair_mulg1.
End PairUMagma.
(* FIXME: HB.saturate *)
HB.instance Definition _ (G H : ChoiceMagma.type) := Magma.on (G * H)%type.
HB.instance Definition _ (G H : ChoiceBaseUMagma.type) :=
BaseUMagma.on (G * H)%type.
HB.instance Definition _ (G H : monoidType) := Semigroup.on (G * H)%type.
(* /FIXME *)
Section PairBaseGroup.
Variables G H : baseGroupType.
Definition inv_pair (u : G * H) := (u.1 ^-1, u.2 ^-1).
HB.instance Definition _ := hasInv.Build (G * H)%type inv_pair.
End PairBaseGroup.
Section PairGroup.
Variables G H : groupType.
Lemma pair_mulVg : left_inverse one (@inv_pair G H) mul.
Proof. by move=> x; congr (_, _); apply/mulVg. Qed.
Lemma pair_mulgV : right_inverse one (@inv_pair G H) mul.
Proof. by move=> x; congr (_, _); apply/mulgV. Qed.
HB.instance Definition _ :=
Monoid_isGroup.Build (G * H)%type pair_mulVg pair_mulgV.
End PairGroup.
|
Sigma.lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import Mathlib.Data.PFunctor.Multivariate.Basic
import Mathlib.Data.QPF.Multivariate.Basic
/-!
# Dependent product and sum of QPFs are QPFs
-/
universe u
namespace MvQPF
open MvFunctor
variable {n : ℕ} {A : Type u}
variable (F : A → TypeVec.{u} n → Type u)
/-- Dependent sum of an `n`-ary functor. The sum can range over
data types like `ℕ` or over `Type.{u-1}` -/
def Sigma (v : TypeVec.{u} n) : Type u :=
Σ α : A, F α v
/-- Dependent product of an `n`-ary functor. The sum can range over
data types like `ℕ` or over `Type.{u-1}` -/
def Pi (v : TypeVec.{u} n) : Type u :=
∀ α : A, F α v
instance Sigma.inhabited {α} [Inhabited A] [Inhabited (F default α)] : Inhabited (Sigma F α) :=
⟨⟨default, default⟩⟩
instance Pi.inhabited {α} [∀ a, Inhabited (F a α)] : Inhabited (Pi F α) :=
⟨fun _a => default⟩
namespace Sigma
instance [∀ α, MvFunctor <| F α] : MvFunctor (Sigma F) where
map := fun f ⟨a, x⟩ => ⟨a, f <$$> x⟩
variable [∀ α, MvQPF <| F α]
/-- polynomial functor representation of a dependent sum -/
protected def P : MvPFunctor n :=
⟨Σ a, (P (F a)).A, fun x => (P (F x.1)).B x.2⟩
/-- abstraction function for dependent sums -/
protected def abs ⦃α⦄ : Sigma.P F α → Sigma F α
| ⟨a, f⟩ => ⟨a.1, MvQPF.abs ⟨a.2, f⟩⟩
/-- representation function for dependent sums -/
protected def repr ⦃α⦄ : Sigma F α → Sigma.P F α
| ⟨a, f⟩ =>
let x := MvQPF.repr f
⟨⟨a, x.1⟩, x.2⟩
instance : MvQPF (Sigma F) where
P := Sigma.P F
abs {α} := @Sigma.abs _ _ F _ α
repr {α} := @Sigma.repr _ _ F _ α
abs_repr := by rintro α ⟨x, f⟩; simp only [Sigma.abs, Sigma.repr, Sigma.eta, abs_repr]
abs_map := by rintro α β f ⟨x, g⟩; simp only [Sigma.abs, MvPFunctor.map_eq]
simp only [(· <$$> ·), ← abs_map, ← MvPFunctor.map_eq]
end Sigma
namespace Pi
instance [∀ α, MvFunctor <| F α] : MvFunctor (Pi F) where map f x a := f <$$> x a
variable [∀ α, MvQPF <| F α]
/-- polynomial functor representation of a dependent product -/
protected def P : MvPFunctor n :=
⟨∀ a, (P (F a)).A, fun x i => Σ a, (P (F a)).B (x a) i⟩
/-- abstraction function for dependent products -/
protected def abs ⦃α⦄ : Pi.P F α → Pi F α
| ⟨a, f⟩ => fun x => MvQPF.abs ⟨a x, fun i y => f i ⟨_, y⟩⟩
/-- representation function for dependent products -/
protected def repr ⦃α⦄ : Pi F α → Pi.P F α
| f => ⟨fun a => (MvQPF.repr (f a)).1, fun _i a => (MvQPF.repr (f _)).2 _ a.2⟩
instance : MvQPF (Pi F) where
P := Pi.P F
abs := @Pi.abs _ _ F _
repr := @Pi.repr _ _ F _
abs_repr := by rintro α f; simp only [Pi.abs, Pi.repr, Sigma.eta, abs_repr]
abs_map := by rintro α β f ⟨x, g⟩; simp only [Pi.abs, (· <$$> ·), ← abs_map]; rfl
end Pi
end MvQPF
|
FixedPoint.lean
|
/-
Copyright (c) 2018 Violeta Hernández Palacios, Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios, Mario Carneiro
-/
import Mathlib.Logic.Small.List
import Mathlib.SetTheory.Ordinal.Enum
import Mathlib.SetTheory.Ordinal.Exponential
/-!
# Fixed points of normal functions
We prove various statements about the fixed points of normal ordinal functions. We state them in
three forms: as statements about type-indexed families of normal functions, as statements about
ordinal-indexed families of normal functions, and as statements about a single normal function. For
the most part, the first case encompasses the others.
Moreover, we prove some lemmas about the fixed points of specific normal functions.
## Main definitions and results
* `nfpFamily`, `nfp`: the next fixed point of a (family of) normal function(s).
* `not_bddAbove_fp_family`, `not_bddAbove_fp`: the (common) fixed points of a (family of) normal
function(s) are unbounded in the ordinals.
* `deriv_add_eq_mul_omega0_add`: a characterization of the derivative of addition.
* `deriv_mul_eq_opow_omega0_mul`: a characterization of the derivative of multiplication.
-/
noncomputable section
universe u v
open Function Order
namespace Ordinal
/-! ### Fixed points of type-indexed families of ordinals -/
section
variable {ι : Type*} {f : ι → Ordinal.{u} → Ordinal.{u}}
/-- The next common fixed point, at least `a`, for a family of normal functions.
This is defined for any family of functions, as the supremum of all values reachable by applying
finitely many functions in the family to `a`.
`Ordinal.nfpFamily_fp` shows this is a fixed point, `Ordinal.le_nfpFamily` shows it's at
least `a`, and `Ordinal.nfpFamily_le_fp` shows this is the least ordinal with these properties. -/
def nfpFamily (f : ι → Ordinal.{u} → Ordinal.{u}) (a : Ordinal.{u}) : Ordinal :=
⨆ i, List.foldr f a i
theorem foldr_le_nfpFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) (a l) :
List.foldr f a l ≤ nfpFamily f a :=
Ordinal.le_iSup _ _
theorem le_nfpFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) (a) : a ≤ nfpFamily f a :=
foldr_le_nfpFamily f a []
theorem lt_nfpFamily_iff [Small.{u} ι] {a b} : a < nfpFamily f b ↔ ∃ l, a < List.foldr f b l :=
Ordinal.lt_iSup_iff
@[deprecated (since := "2025-02-16")]
alias lt_nfpFamily := lt_nfpFamily_iff
theorem nfpFamily_le_iff [Small.{u} ι] {a b} : nfpFamily f a ≤ b ↔ ∀ l, List.foldr f a l ≤ b :=
Ordinal.iSup_le_iff
theorem nfpFamily_le {a b} : (∀ l, List.foldr f a l ≤ b) → nfpFamily f a ≤ b :=
Ordinal.iSup_le
theorem nfpFamily_monotone [Small.{u} ι] (hf : ∀ i, Monotone (f i)) : Monotone (nfpFamily f) :=
fun _ _ h ↦ nfpFamily_le <| fun l ↦ (List.foldr_monotone hf l h).trans (foldr_le_nfpFamily _ _ l)
theorem apply_lt_nfpFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b}
(hb : b < nfpFamily f a) (i) : f i b < nfpFamily f a :=
let ⟨l, hl⟩ := lt_nfpFamily_iff.1 hb
lt_nfpFamily_iff.2 ⟨i::l, (H i).strictMono hl⟩
theorem apply_lt_nfpFamily_iff [Nonempty ι] [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b < nfpFamily f a) ↔ b < nfpFamily f a := by
refine ⟨fun h ↦ ?_, apply_lt_nfpFamily H⟩
let ⟨l, hl⟩ := lt_nfpFamily_iff.1 (h (Classical.arbitrary ι))
exact lt_nfpFamily_iff.2 <| ⟨l, (H _).le_apply.trans_lt hl⟩
theorem nfpFamily_le_apply [Nonempty ι] [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∃ i, nfpFamily f a ≤ f i b) ↔ nfpFamily f a ≤ b := by
rw [← not_iff_not]
push_neg
exact apply_lt_nfpFamily_iff H
theorem nfpFamily_le_fp (H : ∀ i, Monotone (f i)) {a b} (ab : a ≤ b) (h : ∀ i, f i b ≤ b) :
nfpFamily f a ≤ b := by
apply Ordinal.iSup_le fun l ↦ ?_
induction l generalizing a with
| nil => exact ab
| cons i l IH => exact (H i (IH ab)).trans (h i)
theorem nfpFamily_fp [Small.{u} ι] {i} (H : IsNormal (f i)) (a) :
f i (nfpFamily f a) = nfpFamily f a := by
rw [nfpFamily, H.map_iSup]
apply le_antisymm <;> refine Ordinal.iSup_le fun l => ?_
· exact Ordinal.le_iSup _ (i::l)
· exact H.le_apply.trans (Ordinal.le_iSup _ _)
theorem apply_le_nfpFamily [Small.{u} ι] [hι : Nonempty ι] (H : ∀ i, IsNormal (f i)) {a b} :
(∀ i, f i b ≤ nfpFamily f a) ↔ b ≤ nfpFamily f a := by
refine ⟨fun h => ?_, fun h i => ?_⟩
· obtain ⟨i⟩ := hι
exact (H i).le_apply.trans (h i)
· rw [← nfpFamily_fp (H i)]
exact (H i).monotone h
theorem nfpFamily_eq_self [Small.{u} ι] {a} (h : ∀ i, f i a = a) : nfpFamily f a = a := by
apply (Ordinal.iSup_le ?_).antisymm (le_nfpFamily f a)
intro l
rw [List.foldr_fixed' h l]
-- Todo: This is actually a special case of the fact the intersection of club sets is a club set.
/-- A generalization of the fixed point lemma for normal functions: any family of normal functions
has an unbounded set of common fixed points. -/
theorem not_bddAbove_fp_family [Small.{u} ι] (H : ∀ i, IsNormal (f i)) :
¬ BddAbove (⋂ i, Function.fixedPoints (f i)) := by
rw [not_bddAbove_iff]
refine fun a ↦ ⟨nfpFamily f (succ a), ?_, (lt_succ a).trans_le (le_nfpFamily f _)⟩
rintro _ ⟨i, rfl⟩
exact nfpFamily_fp (H i) _
/-- The derivative of a family of normal functions is the sequence of their common fixed points.
This is defined for all functions such that `Ordinal.derivFamily_zero`,
`Ordinal.derivFamily_succ`, and `Ordinal.derivFamily_limit` are satisfied. -/
def derivFamily (f : ι → Ordinal.{u} → Ordinal.{u}) (o : Ordinal.{u}) : Ordinal.{u} :=
limitRecOn o (nfpFamily f 0) (fun _ IH => nfpFamily f (succ IH))
fun a _ g => ⨆ b : Set.Iio a, g _ b.2
@[simp]
theorem derivFamily_zero (f : ι → Ordinal → Ordinal) :
derivFamily f 0 = nfpFamily f 0 :=
limitRecOn_zero ..
@[simp]
theorem derivFamily_succ (f : ι → Ordinal → Ordinal) (o) :
derivFamily f (succ o) = nfpFamily f (succ (derivFamily f o)) :=
limitRecOn_succ ..
theorem derivFamily_limit (f : ι → Ordinal → Ordinal) {o} :
IsSuccLimit o → derivFamily f o = ⨆ b : Set.Iio o, derivFamily f b :=
limitRecOn_limit _ _ _ _
theorem isNormal_derivFamily [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) :
IsNormal (derivFamily f) := by
refine IsNormal.of_succ_lt (fun o ↦ ?_) @fun o h ↦ ?_
· rw [derivFamily_succ, ← succ_le_iff]
exact le_nfpFamily _ _
· rw [derivFamily_limit _ h, Set.image_eq_range]
have : Nonempty (Set.Iio o) := ⟨0, h.bot_lt⟩
exact isLUB_ciSup (bddAbove_of_small _)
theorem derivFamily_strictMono [Small.{u} ι] (f : ι → Ordinal.{u} → Ordinal.{u}) :
StrictMono (derivFamily f) :=
(isNormal_derivFamily f).strictMono
theorem derivFamily_fp [Small.{u} ι] {i} (H : IsNormal (f i)) (o : Ordinal) :
f i (derivFamily f o) = derivFamily f o := by
induction o using limitRecOn with
| zero =>
rw [derivFamily_zero]
exact nfpFamily_fp H 0
| succ =>
rw [derivFamily_succ]
exact nfpFamily_fp H _
| limit o l IH =>
have : Nonempty (Set.Iio o) := ⟨0, l.bot_lt⟩
rw [derivFamily_limit _ l, H.map_iSup]
refine eq_of_forall_ge_iff fun c => ?_
rw [Ordinal.iSup_le_iff, Ordinal.iSup_le_iff]
refine forall_congr' fun a ↦ ?_
rw [IH _ a.2]
theorem le_iff_derivFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a ≤ a) ↔ ∃ o, derivFamily f o = a :=
⟨fun ha => by
suffices ∀ (o), a ≤ derivFamily f o → ∃ o, derivFamily f o = a from
this a (isNormal_derivFamily _).le_apply
intro o
induction o using limitRecOn with
| zero =>
intro h₁
refine ⟨0, le_antisymm ?_ h₁⟩
rw [derivFamily_zero]
exact nfpFamily_le_fp (fun i => (H i).monotone) (Ordinal.zero_le _) ha
| succ o IH =>
intro h₁
rcases le_or_gt a (derivFamily f o) with h | h
· exact IH h
refine ⟨succ o, le_antisymm ?_ h₁⟩
rw [derivFamily_succ]
exact nfpFamily_le_fp (fun i => (H i).monotone) (succ_le_of_lt h) ha
| limit o l IH =>
intro h₁
rcases eq_or_lt_of_le h₁ with h | h
· exact ⟨_, h.symm⟩
rw [derivFamily_limit _ l, ← not_le, Ordinal.iSup_le_iff, not_forall] at h
obtain ⟨o', h⟩ := h
exact IH o' o'.2 (le_of_not_ge h),
fun ⟨_, e⟩ i => e ▸ (derivFamily_fp (H i) _).le⟩
theorem fp_iff_derivFamily [Small.{u} ι] (H : ∀ i, IsNormal (f i)) {a} :
(∀ i, f i a = a) ↔ ∃ o, derivFamily f o = a :=
Iff.trans ⟨fun h i => le_of_eq (h i), fun h i => (H i).le_iff_eq.1 (h i)⟩ (le_iff_derivFamily H)
/-- For a family of normal functions, `Ordinal.derivFamily` enumerates the common fixed points. -/
theorem derivFamily_eq_enumOrd [Small.{u} ι] (H : ∀ i, IsNormal (f i)) :
derivFamily f = enumOrd (⋂ i, Function.fixedPoints (f i)) := by
rw [eq_comm, eq_enumOrd _ (not_bddAbove_fp_family H)]
use (isNormal_derivFamily f).strictMono
rw [Set.range_eq_iff]
refine ⟨?_, fun a ha => ?_⟩
· rintro a S ⟨i, hi⟩
rw [← hi]
exact derivFamily_fp (H i) a
rw [Set.mem_iInter] at ha
rwa [← fp_iff_derivFamily H]
end
/-! ### Fixed points of a single function -/
section
variable {f : Ordinal.{u} → Ordinal.{u}}
/-- The next fixed point function, the least fixed point of the normal function `f`, at least `a`.
This is defined as `nfpFamily` applied to a family consisting only of `f`. -/
def nfp (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
nfpFamily fun _ : Unit => f
theorem nfp_eq_nfpFamily (f : Ordinal → Ordinal) : nfp f = nfpFamily fun _ : Unit => f :=
rfl
theorem iSup_iterate_eq_nfp (f : Ordinal.{u} → Ordinal.{u}) (a : Ordinal.{u}) :
⨆ n : ℕ, f^[n] a = nfp f a := by
apply le_antisymm
· rw [Ordinal.iSup_le_iff]
intro n
rw [← List.length_replicate (n := n) (a := Unit.unit), ← List.foldr_const f a]
exact Ordinal.le_iSup _ _
· apply Ordinal.iSup_le
intro l
rw [List.foldr_const f a l]
exact Ordinal.le_iSup _ _
theorem iterate_le_nfp (f a n) : f^[n] a ≤ nfp f a := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.le_iSup (fun n ↦ f^[n] a) n
theorem le_nfp (f a) : a ≤ nfp f a :=
iterate_le_nfp f a 0
theorem lt_nfp_iff {a b} : a < nfp f b ↔ ∃ n, a < f^[n] b := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.lt_iSup_iff
theorem nfp_le_iff {a b} : nfp f a ≤ b ↔ ∀ n, f^[n] a ≤ b := by
rw [← iSup_iterate_eq_nfp]
exact Ordinal.iSup_le_iff
theorem nfp_le {a b} : (∀ n, f^[n] a ≤ b) → nfp f a ≤ b :=
nfp_le_iff.2
@[simp]
theorem nfp_id : nfp id = id := by
ext
simp_rw [← iSup_iterate_eq_nfp, iterate_id]
exact ciSup_const
theorem nfp_monotone (hf : Monotone f) : Monotone (nfp f) :=
nfpFamily_monotone fun _ => hf
theorem iterate_lt_nfp (hf : StrictMono f) {a} (h : a < f a) (n : ℕ) : f^[n] a < nfp f a := by
apply (hf.iterate n h).trans_le
rw [← iterate_succ_apply]
exact iterate_le_nfp ..
theorem IsNormal.apply_lt_nfp (H : IsNormal f) {a b} : f b < nfp f a ↔ b < nfp f a := by
unfold nfp
rw [← @apply_lt_nfpFamily_iff Unit (fun _ => f) _ _ (fun _ => H) a b]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.nfp_le_apply (H : IsNormal f) {a b} : nfp f a ≤ f b ↔ nfp f a ≤ b :=
le_iff_le_iff_lt_iff_lt.2 H.apply_lt_nfp
theorem nfp_le_fp (H : Monotone f) {a b} (ab : a ≤ b) (h : f b ≤ b) : nfp f a ≤ b :=
nfpFamily_le_fp (fun _ => H) ab fun _ => h
theorem IsNormal.nfp_fp (H : IsNormal f) : ∀ a, f (nfp f a) = nfp f a :=
@nfpFamily_fp Unit (fun _ => f) _ () H
theorem IsNormal.apply_le_nfp (H : IsNormal f) {a b} : f b ≤ nfp f a ↔ b ≤ nfp f a :=
⟨H.le_apply.trans, fun h => by simpa only [H.nfp_fp] using H.le_iff.2 h⟩
theorem nfp_eq_self {a} (h : f a = a) : nfp f a = a :=
nfpFamily_eq_self fun _ => h
/-- The fixed point lemma for normal functions: any normal function has an unbounded set of
fixed points. -/
theorem not_bddAbove_fp (H : IsNormal f) : ¬ BddAbove (Function.fixedPoints f) := by
convert not_bddAbove_fp_family fun _ : Unit => H
exact (Set.iInter_const _).symm
/-- The derivative of a normal function `f` is the sequence of fixed points of `f`.
This is defined as `Ordinal.derivFamily` applied to a trivial family consisting only of `f`. -/
def deriv (f : Ordinal → Ordinal) : Ordinal → Ordinal :=
derivFamily fun _ : Unit => f
theorem deriv_eq_derivFamily (f : Ordinal → Ordinal) : deriv f = derivFamily fun _ : Unit => f :=
rfl
@[simp]
theorem deriv_zero_right (f) : deriv f 0 = nfp f 0 :=
derivFamily_zero _
@[simp]
theorem deriv_succ (f o) : deriv f (succ o) = nfp f (succ (deriv f o)) :=
derivFamily_succ _ _
theorem deriv_limit (f) {o} : IsSuccLimit o → deriv f o = ⨆ a : {a // a < o}, deriv f a :=
derivFamily_limit _
theorem isNormal_deriv (f) : IsNormal (deriv f) :=
isNormal_derivFamily _
theorem deriv_strictMono (f) : StrictMono (deriv f) :=
derivFamily_strictMono _
theorem deriv_id_of_nfp_id (h : nfp f = id) : deriv f = id :=
((isNormal_deriv _).eq_iff_zero_and_succ IsNormal.refl).2 (by simp [h])
theorem IsNormal.deriv_fp (H : IsNormal f) : ∀ o, f (deriv f o) = deriv f o :=
derivFamily_fp (i := ⟨⟩) H
theorem IsNormal.le_iff_deriv (H : IsNormal f) {a} : f a ≤ a ↔ ∃ o, deriv f o = a := by
unfold deriv
rw [← le_iff_derivFamily fun _ : Unit => H]
exact ⟨fun h _ => h, fun h => h Unit.unit⟩
theorem IsNormal.fp_iff_deriv (H : IsNormal f) {a} : f a = a ↔ ∃ o, deriv f o = a := by
rw [← H.le_iff_eq, H.le_iff_deriv]
/-- `Ordinal.deriv` enumerates the fixed points of a normal function. -/
theorem deriv_eq_enumOrd (H : IsNormal f) : deriv f = enumOrd (Function.fixedPoints f) := by
convert derivFamily_eq_enumOrd fun _ : Unit => H
exact (Set.iInter_const _).symm
theorem deriv_eq_id_of_nfp_eq_id (h : nfp f = id) : deriv f = id :=
(IsNormal.eq_iff_zero_and_succ (isNormal_deriv _) IsNormal.refl).2 <| by simp [h]
theorem nfp_zero_left (a) : nfp 0 a = a := by
rw [← iSup_iterate_eq_nfp]
apply (Ordinal.iSup_le ?_).antisymm (Ordinal.le_iSup _ 0)
intro n
cases n
· rfl
· rw [Function.iterate_succ']
simp
@[simp]
theorem nfp_zero : nfp 0 = id := by
ext
exact nfp_zero_left _
@[simp]
theorem deriv_zero : deriv 0 = id :=
deriv_eq_id_of_nfp_eq_id nfp_zero
theorem deriv_zero_left (a) : deriv 0 a = a := by
rw [deriv_zero, id_eq]
end
/-! ### Fixed points of addition -/
@[simp]
theorem nfp_add_zero (a) : nfp (a + ·) 0 = a * ω := by
simp_rw [← iSup_iterate_eq_nfp, ← iSup_mul_nat]
congr; funext n
induction n with
| zero => rw [Nat.cast_zero, mul_zero, iterate_zero_apply]
| succ n hn => rw [iterate_succ_apply', Nat.add_comm, Nat.cast_add, Nat.cast_one, mul_one_add, hn]
theorem nfp_add_eq_mul_omega0 {a b} (hba : b ≤ a * ω) : nfp (a + ·) b = a * ω := by
apply le_antisymm (nfp_le_fp (isNormal_add_right a).monotone hba _)
· rw [← nfp_add_zero]
exact nfp_monotone (isNormal_add_right a).monotone (Ordinal.zero_le b)
· dsimp; rw [← mul_one_add, one_add_omega0]
theorem add_eq_right_iff_mul_omega0_le {a b : Ordinal} : a + b = b ↔ a * ω ≤ b := by
refine ⟨fun h => ?_, fun h => ?_⟩
· rw [← nfp_add_zero a, ← deriv_zero_right]
obtain ⟨c, hc⟩ := (isNormal_add_right a).fp_iff_deriv.1 h
rw [← hc]
exact (isNormal_deriv _).monotone (Ordinal.zero_le _)
· have := Ordinal.add_sub_cancel_of_le h
nth_rw 1 [← this]
rwa [← add_assoc, ← mul_one_add, one_add_omega0]
theorem add_le_right_iff_mul_omega0_le {a b : Ordinal} : a + b ≤ b ↔ a * ω ≤ b := by
rw [← add_eq_right_iff_mul_omega0_le]
exact (isNormal_add_right a).le_iff_eq
theorem deriv_add_eq_mul_omega0_add (a b : Ordinal.{u}) : deriv (a + ·) b = a * ω + b := by
revert b
rw [← funext_iff, IsNormal.eq_iff_zero_and_succ (isNormal_deriv _) (isNormal_add_right _)]
refine ⟨?_, fun a h => ?_⟩
· rw [deriv_zero_right, add_zero]
exact nfp_add_zero a
· rw [deriv_succ, h, add_succ]
exact nfp_eq_self (add_eq_right_iff_mul_omega0_le.2 ((le_add_right _ _).trans (le_succ _)))
/-! ### Fixed points of multiplication -/
@[simp]
theorem nfp_mul_one {a : Ordinal} (ha : 0 < a) : nfp (a * ·) 1 = a ^ ω := by
rw [← iSup_iterate_eq_nfp, ← iSup_pow ha]
congr
funext n
induction n with
| zero => rw [pow_zero, iterate_zero_apply]
| succ n hn => rw [iterate_succ_apply', Nat.add_comm, pow_add, pow_one, hn]
@[simp]
theorem nfp_mul_zero (a : Ordinal) : nfp (a * ·) 0 = 0 := by
rw [← Ordinal.le_zero, nfp_le_iff]
intro n
induction n with
| zero => rfl
| succ n hn => dsimp only; rwa [iterate_succ_apply, mul_zero]
theorem nfp_mul_eq_opow_omega0 {a b : Ordinal} (hb : 0 < b) (hba : b ≤ a ^ ω) :
nfp (a * ·) b = a ^ ω := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_opow omega0_ne_zero] at hba ⊢
simp_rw [Ordinal.le_zero.1 hba, zero_mul]
exact nfp_zero_left 0
apply le_antisymm
· apply nfp_le_fp (isNormal_mul_right ha).monotone hba
rw [← opow_one_add, one_add_omega0]
rw [← nfp_mul_one ha]
exact nfp_monotone (isNormal_mul_right ha).monotone (one_le_iff_pos.2 hb)
theorem eq_zero_or_opow_omega0_le_of_mul_eq_right {a b : Ordinal} (hab : a * b = b) :
b = 0 ∨ a ^ ω ≤ b := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_opow omega0_ne_zero]
exact Or.inr (Ordinal.zero_le b)
rw [or_iff_not_imp_left]
intro hb
rw [← nfp_mul_one ha]
rw [← Ne, ← one_le_iff_ne_zero] at hb
exact nfp_le_fp (isNormal_mul_right ha).monotone hb (le_of_eq hab)
theorem mul_eq_right_iff_opow_omega0_dvd {a b : Ordinal} : a * b = b ↔ a ^ ω ∣ b := by
rcases eq_zero_or_pos a with ha | ha
· rw [ha, zero_mul, zero_opow omega0_ne_zero, zero_dvd_iff]
exact eq_comm
refine ⟨fun hab => ?_, fun h => ?_⟩
· rw [dvd_iff_mod_eq_zero]
rw [← div_add_mod b (a ^ ω), mul_add, ← mul_assoc, ← opow_one_add, one_add_omega0,
add_left_cancel_iff] at hab
rcases eq_zero_or_opow_omega0_le_of_mul_eq_right hab with hab | hab
· exact hab
refine (not_lt_of_ge hab (mod_lt b (opow_ne_zero ω ?_))).elim
rwa [← Ordinal.pos_iff_ne_zero]
obtain ⟨c, hc⟩ := h
rw [hc, ← mul_assoc, ← opow_one_add, one_add_omega0]
theorem mul_le_right_iff_opow_omega0_dvd {a b : Ordinal} (ha : 0 < a) :
a * b ≤ b ↔ (a ^ ω) ∣ b := by
rw [← mul_eq_right_iff_opow_omega0_dvd]
exact (isNormal_mul_right ha).le_iff_eq
theorem nfp_mul_opow_omega0_add {a c : Ordinal} (b) (ha : 0 < a) (hc : 0 < c)
(hca : c ≤ a ^ ω) : nfp (a * ·) (a ^ ω * b + c) = a ^ ω * succ b := by
apply le_antisymm
· apply nfp_le_fp (isNormal_mul_right ha).monotone
· rw [mul_succ]
apply add_le_add_left hca
· dsimp only; rw [← mul_assoc, ← opow_one_add, one_add_omega0]
· obtain ⟨d, hd⟩ :=
mul_eq_right_iff_opow_omega0_dvd.1 ((isNormal_mul_right ha).nfp_fp ((a ^ ω) * b + c))
rw [hd]
apply mul_le_mul_left'
have := le_nfp (a * ·) (a ^ ω * b + c)
rw [hd] at this
have := (add_lt_add_left hc (a ^ ω * b)).trans_le this
rw [add_zero, mul_lt_mul_iff_left (opow_pos ω ha)] at this
rwa [succ_le_iff]
theorem deriv_mul_eq_opow_omega0_mul {a : Ordinal.{u}} (ha : 0 < a) (b) :
deriv (a * ·) b = a ^ ω * b := by
revert b
rw [← funext_iff,
IsNormal.eq_iff_zero_and_succ (isNormal_deriv _) (isNormal_mul_right (opow_pos ω ha))]
refine ⟨?_, fun c h => ?_⟩
· dsimp only; rw [deriv_zero_right, nfp_mul_zero, mul_zero]
· rw [deriv_succ, h]
exact nfp_mul_opow_omega0_add c ha zero_lt_one (one_le_iff_pos.2 (opow_pos _ ha))
end Ordinal
|
UnitsCyclic.lean
|
/-
Copyright (c) 2025 Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, Junyan Xu
-/
import Mathlib.Algebra.Order.Star.Basic
import Mathlib.Analysis.Normed.Ring.Lemmas
import Mathlib.Data.Nat.Choose.Dvd
import Mathlib.Data.ZMod.Units
import Mathlib.FieldTheory.Finite.Basic
/-! # Cyclicity of the units of `ZMod n`
`ZMod.isCyclic_units_iff` : `(ZMod n)ˣ` is cyclic iff
one of the following mutually exclusive cases happens:
- `n = 0` (then `ZMod 0 ≃+* ℤ` and the group of units is cyclic of order 2);
- `n = 1`, `2` or `4`
- `n` is a power `p ^ e` of an odd prime number, or twice such a power
(with `1 ≤ e`).
The individual cases are proved by `inferInstance` and are
also directly provided by :
* `ZMod.isCyclic_units_zero`
* `ZMod.isCyclic_units_one`
* `ZMod.isCyclic_units_two`
* `ZMod.isCyclic_units_four`
The case of prime numbers is also an instance:
* `ZMod.isCyclic_units_prime`
* `ZMod.not_isCyclic_units_eight`: `(ZMod 8)ˣ` is not cyclic
* `ZMod.orderOf_one_add_mul_prime`: the order of `1 + a * p`
modulo `p ^ (n + 1)` is `p ^ n` when `p` does not divide `a`.
* `ZMod.orderOf_five` : the order of `5` modulo `2 ^ (n + 3)` is `2 ^ (n + 1)`.
* `ZMod.isCyclic_units_of_prime_pow` : the case of odd prime powers
* `ZMod.isCyclic_units_two_pow_iff` : `(ZMod (2 ^ n))ˣ` is cyclic iff `n ≤ 2`.
The proofs mostly follow [Ireland and Rosen,
*A classical introduction to modern number theory*, chapter 4]
[IrelandRosen1990].
-/
open scoped Nat
namespace ZMod
section EasyCases
theorem isCyclic_units_zero :
IsCyclic (ZMod 0)ˣ := inferInstance
theorem isCyclic_units_one :
IsCyclic (ZMod 1)ˣ := inferInstance
theorem isCyclic_units_two :
IsCyclic (ZMod 2)ˣ := inferInstance
theorem isCyclic_units_four :
IsCyclic (ZMod 4)ˣ := by
apply isCyclic_of_prime_card (p := 2)
simp only [Nat.card_eq_fintype_card, card_units_eq_totient]
decide
/- The multiplicative group of `ZMod p` is cyclic. -/
theorem isCyclic_units_prime {p : ℕ} (hp : p.Prime) :
IsCyclic (ZMod p)ˣ :=
have : Fact (p.Prime) := ⟨hp⟩
inferInstance
theorem not_isCyclic_units_eight :
¬ IsCyclic (ZMod 8)ˣ := by
rw [IsCyclic.iff_exponent_eq_card, Nat.card_eq_fintype_card, card_units_eq_totient]
have h : Monoid.exponent (ZMod 8)ˣ ∣ 2 := Monoid.exponent_dvd_of_forall_pow_eq_one (by decide)
intro (h' : Monoid.exponent (ZMod 8)ˣ = 4)
simp [h'] at h
end EasyCases
section Divisibility
variable {R : Type*} [CommSemiring R] {u v : R} {p : ℕ}
lemma exists_one_add_mul_pow_prime_eq
(hp : p.Prime) (hvu : v ∣ u) (hpuv : p * u * v ∣ u ^ p) (x : R) :
∃ y, (1 + u * x) ^ p = 1 + p * u * (x + v * y) := by
rw [add_comm, add_pow]
rw [← Finset.add_sum_erase (a := 0) _ _ (by simp)]
simp_rw [one_pow, pow_zero, Nat.choose_zero_right, Nat.cast_one, mul_one]
rw [← Finset.add_sum_erase (a := 1) _ _ (by simp [hp.pos])]
rw [← Finset.sum_erase_add (a := p) _ _ (by -- aesop works but is slow
simp only [Finset.mem_erase]
rw [← and_assoc, and_comm (a := ¬ _), ← Nat.two_le_iff]
simp [hp.two_le])]
obtain ⟨a, ha⟩ := hvu
obtain ⟨b, hb⟩ := hpuv
use a * x ^ 2 * ∑ i ∈ (((Finset.range (p + 1)).erase 0).erase 1).erase p,
(u * x) ^ (i - 2) * (p.choose i / p : ℕ) + b * x ^ p
rw [mul_add]
congr 2
· rw [Nat.choose_one_right]; ring
simp only [mul_add, Finset.mul_sum]
congr 1
· congr! 1 with i hi
simp only [Finset.mem_erase, ne_eq, Finset.mem_range] at hi
have hi' : 2 ≤ i := by omega
calc
(u * x) ^ i * p.choose i =
(u * x) ^ (2 + (i - 2)) * p.choose i := by rw [Nat.add_sub_of_le hi']
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * p.choose i := by ring_nf
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * (p * (p.choose i / p) : ℕ) := by
rw [Nat.mul_div_cancel' (hp.dvd_choose_self hi.2.2.1 <| by omega)]
_ = u ^ 2 * x ^ 2 * (u * x) ^ (i - 2) * p * (p.choose i / p : ℕ) := by
simp only [Nat.cast_mul]; ring_nf
_ = p * u * (v * (a * x ^ 2 * ((u * x) ^ (i - 2) * (p.choose i / p : ℕ)))) := by
rw [ha]; ring
· calc
(u * x) ^ p * (p.choose p) = u ^ p * x ^ p := by simp [Nat.choose_self, mul_pow]
_ = p * u * v * b * x ^ p := by rw [hb]
_ = p * u * (v * (b * x ^ p)) := by ring_nf
lemma exists_one_add_mul_pow_prime_pow_eq {u v : R}
(hp : p.Prime) (hvu : v ∣ u) (hpuv : p * u * v ∣ u ^ p) (x : R) (m : ℕ) :
∃ y, (1 + u * x) ^ (p ^ m) = 1 + p ^ m * u * (x + v * y) :=
match m with
| 0 => ⟨0, by simp⟩
| m + 1 => by
rw [pow_succ', pow_mul]
obtain ⟨y, hy⟩ := exists_one_add_mul_pow_prime_eq hp hvu hpuv x
rw [hy]
obtain ⟨z, hz⟩ :=
exists_one_add_mul_pow_prime_pow_eq (u := p * u) (v := p * v) hp
(mul_dvd_mul_left _ hvu)
(by
rw [mul_pow]
simp only [← mul_assoc]
rw [mul_assoc, mul_assoc, ← mul_assoc u, mul_comm u]
apply mul_dvd_mul _ hpuv
rw [← pow_two]
exact pow_dvd_pow _ hp.two_le)
(x + v * y) m
use y + p * z
rw [hz]
ring
end Divisibility
section PrimePow
theorem orderOf_one_add_mul_prime_pow {p : ℕ} (hp : p.Prime) (m : ℕ) (hm0 : m ≠ 0)
(hpm : m + 2 ≤ p * m) (a : ℤ) (ha : ¬ (p : ℤ) ∣ a) (n : ℕ) :
orderOf (1 + p ^ m * a : ZMod (p ^ (n + m))) = p ^ n := by
match n with
| 0 => rw [← Nat.cast_pow, zero_add m, ZMod.natCast_self]; simp
| n + 1 =>
have := Fact.mk hp
have := exists_one_add_mul_pow_prime_pow_eq
(R := ZMod (p ^ (n + 1 + m))) (u := p ^ m) (v := p) hp (dvd_pow_self _ hm0) ?_ a
· apply orderOf_eq_prime_pow
· obtain ⟨y, hy⟩ := this n
rw [hy, ← pow_add, add_eq_left, mul_add, ← mul_assoc, ← pow_succ]
simp_rw [add_right_comm n _ 1, ← Nat.cast_pow, ZMod.natCast_self, zero_mul, add_zero]
rwa [← Int.cast_natCast, ← Int.cast_mul, ZMod.intCast_zmod_eq_zero_iff_dvd, add_right_comm,
pow_succ, Nat.cast_mul, Int.mul_dvd_mul_iff_left (by simp [hp.ne_zero])]
· obtain ⟨y, hy⟩ := this (n + 1)
rw [hy, ← pow_add, ← Nat.cast_pow]
simp
· rw [← pow_succ', ← pow_succ, ← pow_mul, mul_comm]
exact pow_dvd_pow _ hpm
theorem orderOf_one_add_mul_prime {p : ℕ} (hp : p.Prime) (hp2 : p ≠ 2) (a : ℤ)
(ha : ¬ (p : ℤ) ∣ a) (n : ℕ) :
orderOf (1 + p * a : ZMod (p ^ (n + 1))) = p ^ n := by
convert orderOf_one_add_mul_prime_pow hp 1 one_ne_zero _ a ha n using 1
· rw [pow_one]
· have := hp.two_le; omega
theorem orderOf_one_add_prime {p : ℕ} (hp : p.Prime) (hp2 : p ≠ 2) (n : ℕ) :
orderOf (1 + p : ZMod (p ^ (n + 1))) = p ^ n := by
convert orderOf_one_add_mul_prime hp hp2 1 _ n
· simp
· intro H
apply hp.ne_one
simpa using Int.eq_one_of_dvd_one (Int.natCast_nonneg p) H
/-- If `p` is an odd prime, then `(ZMod (p ^ n))ˣ` is cyclic for all n -/
theorem isCyclic_units_of_prime_pow (p : ℕ) (hp : p.Prime) (hp2 : p ≠ 2) (n : ℕ) :
IsCyclic (ZMod (p ^ n))ˣ := by
have _ : NeZero (p ^ n) := ⟨pow_ne_zero n hp.ne_zero⟩
have := Fact.mk hp
rcases n with _ | n
· rw [pow_zero]; infer_instance
-- We first consider the element `1 + p` of order `p ^ n`
set a := (1 + p : ZMod (p ^ (n + 1))) with ha_def
have ha : IsUnit a := by
rw [ha_def, ← Nat.cast_one (R := ZMod _), ← Nat.cast_add, ZMod.isUnit_iff_coprime]
apply Nat.Coprime.pow_right
simp only [Nat.coprime_add_self_left, Nat.coprime_one_left_eq_true]
have ha' : orderOf ha.unit = p ^ n := by
rw [← orderOf_injective _ Units.coeHom_injective ha.unit, Units.coeHom_apply, IsUnit.unit_spec]
exact orderOf_one_add_prime hp hp2 n
-- We lift a primitive root of unity mod `p`, an adequate power of which has order `p - 1`.
obtain ⟨c, hc⟩ := isCyclic_iff_exists_orderOf_eq_natCard.mp (isCyclic_units_prime hp)
rw [Nat.card_eq_fintype_card, ZMod.card_units] at hc
obtain ⟨(b : (ZMod (p ^ (n + 1)))ˣ), rfl⟩ :=
ZMod.unitsMap_surjective (Dvd.intro_left (p ^ n) rfl) c
have : p - 1 ∣ orderOf b := hc ▸ orderOf_map_dvd _ b
let k := orderOf b / (p - 1)
have : orderOf (b ^ k) = p - 1 := orderOf_pow_orderOf_div (orderOf_pos b).ne' this
rw [isCyclic_iff_exists_orderOf_eq_natCard]
-- The product of `ha.unit` and `b ^ k` has the required order
use ha.unit * b ^ k
rw [(Commute.all _ _).orderOf_mul_eq_mul_orderOf_of_coprime, this, Nat.card_eq_fintype_card,
ZMod.card_units_eq_totient, Nat.totient_prime_pow_succ hp, ← ha']
rw [ha', this]
apply Nat.Coprime.pow_left
rw [Nat.coprime_self_sub_right hp.pos]
simp
theorem isCyclic_units_two_pow_iff (n : ℕ) :
IsCyclic (ZMod (2 ^ n))ˣ ↔ n ≤ 2 := by
match n with
| 0 => simp [isCyclic_units_one]
| 1 => simp [isCyclic_units_prime Nat.prime_two]
| 2 => simp [isCyclic_units_four]
| n + 3 =>
simp only [Nat.reduceLeDiff, iff_false]
intro H
apply not_isCyclic_units_eight
have h : 2 ^ 3 ∣ 2 ^ (n + 3) := pow_dvd_pow _ (by omega)
exact isCyclic_of_surjective _ (unitsMap_surjective h)
lemma orderOf_one_add_four_mul (a : ℤ) (ha : Odd a) (n : ℕ) :
orderOf (1 + 4 * a : ZMod (2 ^ (n + 2))) = 2 ^ n := by
convert orderOf_one_add_mul_prime_pow Nat.prime_two 2 two_ne_zero le_rfl a ?_ n using 1
· norm_num
· rwa [← Int.not_even_iff_odd, even_iff_two_dvd] at ha
theorem orderOf_five (n : ℕ) :
orderOf (5 : ZMod (2 ^ (n + 2))) = 2 ^ n := by
convert orderOf_one_add_four_mul 1 (by norm_num) n
norm_num
end PrimePow
section Products
theorem isCyclic_units_four_mul_iff (n : ℕ) :
IsCyclic (ZMod (4 * n))ˣ ↔ n = 0 ∨ n = 1 := by
obtain rfl | hn0 := eq_or_ne n 0
· simp [isCyclic_units_zero]
obtain rfl | hn1 := eq_or_ne n 1
· simp [isCyclic_units_four]
refine iff_of_false ?_ (by simp [hn0, hn1])
obtain ⟨n, rfl⟩ | h2n := em (2 ∣ n)
· rw [← mul_assoc]
have : NeZero n := ⟨by simpa using hn0⟩
refine mt (fun _ ↦ ?_) not_isCyclic_units_eight
exact isCyclic_of_surjective _ (ZMod.unitsMap_surjective (m := 4 * 2 * n) (dvd_mul_right 8 _))
have : Nat.Coprime 4 n := (Nat.prime_two.coprime_iff_not_dvd.mpr h2n).pow_left 2
rw [((Units.mapEquiv (chineseRemainder this).toMulEquiv).trans .prodUnits).isCyclic,
Group.isCyclic_prod_iff]
rintro ⟨-, -, h⟩
have : NeZero n := ⟨hn0⟩
have : Odd (φ n) := by simpa [show φ 4 = 2 from rfl] using h
rw [Nat.odd_totient_iff] at this
omega
theorem isCyclic_units_two_mul_iff_of_odd (n : ℕ) (hn : Odd n) :
IsCyclic (ZMod (2 * n))ˣ ↔ IsCyclic (ZMod n)ˣ := by
simp [((Units.mapEquiv (chineseRemainder <| Nat.coprime_two_left.mpr hn).toMulEquiv).trans
.prodUnits).isCyclic, Group.isCyclic_prod_iff, isCyclic_units_two]
theorem not_isCyclic_units_of_mul_coprime (m n : ℕ)
(hm : Odd m) (hm1 : m ≠ 1) (hn : Odd n) (hn1 : n ≠ 1) (hmn : m.Coprime n) :
¬ IsCyclic (ZMod (m * n))ˣ := by
classical
have _ : NeZero m := ⟨Nat.ne_of_odd_add hm⟩
have _ : NeZero n := ⟨Nat.ne_of_odd_add hn⟩
let e := (Units.mapEquiv (chineseRemainder hmn).toMulEquiv).trans .prodUnits
rw [e.isCyclic, Group.isCyclic_prod_iff]
rintro ⟨-, -, h⟩
simp_rw [Nat.card_eq_fintype_card, card_units_eq_totient,
Nat.totient_coprime_totient_iff, hm1, hn1, false_or] at h
rcases h with (rfl | rfl)
· simp [← Nat.not_even_iff_odd] at hm
· simp [← Nat.not_even_iff_odd] at hn
theorem isCyclic_units_iff_of_odd {n : ℕ} (hn : Odd n) :
IsCyclic (ZMod n)ˣ ↔ ∃ (p m : ℕ), p.Prime ∧ Odd p ∧ n = p ^ m := by
have hn0 : n ≠ 0 := by rintro rfl; exact Nat.not_odd_zero hn
obtain rfl | h1 := eq_or_ne n 1
· simp_rw [isCyclic_units_one, true_iff]
exact ⟨3, 0, Nat.prime_three, by simp [Nat.odd_iff], by rw [pow_zero]⟩
have ⟨p, hp, dvd⟩ := n.exists_prime_and_dvd h1
have odd := hn.of_dvd_nat dvd
by_cases hnp : n = p ^ n.factorization p
· exact hnp ▸ iff_of_true (isCyclic_units_of_prime_pow p hp (odd.ne_two_of_dvd_nat dvd_rfl) _)
⟨p, _, hp, odd, rfl⟩
refine iff_of_false ?_ (mt ?_ hnp)
· have := n.ordProj_dvd p
rw [← Nat.mul_div_cancel' this]
refine not_isCyclic_units_of_mul_coprime _ _ (hn.of_dvd_nat this) ?_
(hn.of_dvd_nat (Nat.div_dvd_of_dvd this)) ?_ ((Nat.coprime_ordCompl hp hn0).pow_left ..)
· simpa only [Ne, pow_eq_one_iff (hp.factorization_pos_of_dvd hn0 dvd).ne'] using hp.ne_one
· contrapose! hnp
conv_lhs => rw [← Nat.div_mul_cancel this, hnp, one_mul]
rintro ⟨q, m, hq, -, rfl⟩
cases (Nat.prime_dvd_prime_iff_eq hp hq).mp (hp.dvd_of_dvd_pow dvd)
simp [hp.factorization_self] at hnp
end Products
/-- `(ZMod n)ˣ` is cyclic iff `n` is of the form
`0`, `1`, `2`, `4`, `p ^ m`, or `2 * p ^ m`,
where `p` is an odd prime and `1 ≤ m`. -/
theorem isCyclic_units_iff (n : ℕ) :
IsCyclic (ZMod n)ˣ ↔ n = 0 ∨ n = 1 ∨ n = 2 ∨ n = 4 ∨
∃ (p m : ℕ), p.Prime ∧ Odd p ∧ 1 ≤ m ∧ (n = p ^ m ∨ n = 2 * p ^ m) := by
by_cases h0 : n = 0
· rw [h0]; simp [isCyclic_units_zero]
by_cases h1 : n = 1
· rw [h1]; simp [isCyclic_units_one]
by_cases h2 : n = 2
· rw [h2]; simp [isCyclic_units_two]
by_cases h4 : n = 4
· rw [h4]; simp [isCyclic_units_four]
simp only [h0, h1, h2, h4, false_or, and_or_left, exists_or]
rcases (n.even_or_odd).symm with hn | hn
· rw [isCyclic_units_iff_of_odd hn, or_iff_left]
· congr! with p m
rw [and_iff_right_of_imp]
rintro rfl
contrapose! h1
cases Nat.lt_one_iff.mp h1
apply pow_zero
· rintro ⟨p, m, -, -, -, rfl⟩
simp [← Nat.not_even_iff_odd] at hn
obtain ⟨n, rfl⟩ := hn.two_dvd
rcases (n.even_or_odd).symm with hn | hn
· rw [isCyclic_units_two_mul_iff_of_odd _ hn, isCyclic_units_iff_of_odd hn, or_iff_right]
· congr! with p m
rw [Nat.mul_left_cancel_iff zero_lt_two, and_iff_right_of_imp]
rintro rfl
contrapose! h2
cases Nat.lt_one_iff.mp h2
rw [pow_zero, mul_one]
· rintro ⟨p, m, -, odd, -, eq⟩
have := eq ▸ odd.pow
simp [← Nat.not_even_iff_odd] at this
obtain ⟨n, rfl⟩ := hn.two_dvd
apply iff_of_false
· rw [← mul_assoc, show 2 * 2 = 4 from rfl, isCyclic_units_four_mul_iff]
omega
rintro (⟨p, m, -, odd, -, eq⟩ | ⟨p, m, -, odd, -, eq⟩)
on_goal 1 => have := eq ▸ odd.pow
on_goal 2 => have := (Nat.mul_left_cancel_iff zero_lt_two).mp eq ▸ odd.pow
all_goals simp [← Nat.not_even_iff_odd] at this
end ZMod
|
Limits.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Kim Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
/-!
# Specific subobjects
We define `equalizerSubobject`, `kernelSubobject` and `imageSubobject`, which are the subobjects
represented by the equalizer, kernel and image of (a pair of) morphism(s) and provide conditions
for `P.factors f`, where `P` is one of these special subobjects.
TODO: Add conditions for when `P` is a pullback subobject.
TODO: an iff characterisation of `(imageSubobject f).Factors h`
-/
universe v u
noncomputable section
open CategoryTheory CategoryTheory.Category CategoryTheory.Limits CategoryTheory.Subobject Opposite
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace CategoryTheory
namespace Limits
section Equalizer
variable (f g : X ⟶ Y) [HasEqualizer f g]
/-- The equalizer of morphisms `f g : X ⟶ Y` as a `Subobject X`. -/
abbrev equalizerSubobject : Subobject X :=
Subobject.mk (equalizer.ι f g)
/-- The underlying object of `equalizerSubobject f g` is (up to isomorphism!)
the same as the chosen object `equalizer f g`. -/
def equalizerSubobjectIso : (equalizerSubobject f g : C) ≅ equalizer f g :=
Subobject.underlyingIso (equalizer.ι f g)
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow :
(equalizerSubobjectIso f g).hom ≫ equalizer.ι f g = (equalizerSubobject f g).arrow := by
simp [equalizerSubobjectIso]
@[reassoc (attr := simp)]
theorem equalizerSubobject_arrow' :
(equalizerSubobjectIso f g).inv ≫ (equalizerSubobject f g).arrow = equalizer.ι f g := by
simp [equalizerSubobjectIso]
@[reassoc]
theorem equalizerSubobject_arrow_comp :
(equalizerSubobject f g).arrow ≫ f = (equalizerSubobject f g).arrow ≫ g := by
rw [← equalizerSubobject_arrow, Category.assoc, Category.assoc, equalizer.condition]
theorem equalizerSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = h ≫ g) :
(equalizerSubobject f g).Factors h :=
⟨equalizer.lift h w, by simp⟩
theorem equalizerSubobject_factors_iff {W : C} (h : W ⟶ X) :
(equalizerSubobject f g).Factors h ↔ h ≫ f = h ≫ g :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, equalizerSubobject_arrow_comp,
Category.assoc],
equalizerSubobject_factors f g h⟩
end Equalizer
section Kernel
variable [HasZeroMorphisms C] (f : X ⟶ Y) [HasKernel f]
/-- The kernel of a morphism `f : X ⟶ Y` as a `Subobject X`. -/
abbrev kernelSubobject : Subobject X :=
Subobject.mk (kernel.ι f)
/-- The underlying object of `kernelSubobject f` is (up to isomorphism!)
the same as the chosen object `kernel f`. -/
def kernelSubobjectIso : (kernelSubobject f : C) ≅ kernel f :=
Subobject.underlyingIso (kernel.ι f)
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow :
(kernelSubobjectIso f).hom ≫ kernel.ι f = (kernelSubobject f).arrow := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow' :
(kernelSubobjectIso f).inv ≫ (kernelSubobject f).arrow = kernel.ι f := by
simp [kernelSubobjectIso]
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobject_arrow_comp : (kernelSubobject f).arrow ≫ f = 0 := by
rw [← kernelSubobject_arrow]
simp only [Category.assoc, kernel.condition, comp_zero]
theorem kernelSubobject_factors {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
(kernelSubobject f).Factors h :=
⟨kernel.lift _ h w, by simp⟩
theorem kernelSubobject_factors_iff {W : C} (h : W ⟶ X) :
(kernelSubobject f).Factors h ↔ h ≫ f = 0 :=
⟨fun w => by
rw [← Subobject.factorThru_arrow _ _ w, Category.assoc, kernelSubobject_arrow_comp,
comp_zero],
kernelSubobject_factors f h⟩
/-- A factorisation of `h : W ⟶ X` through `kernelSubobject f`, assuming `h ≫ f = 0`. -/
def factorThruKernelSubobject {W : C} (h : W ⟶ X) (w : h ≫ f = 0) : W ⟶ kernelSubobject f :=
(kernelSubobject f).factorThru h (kernelSubobject_factors f h w)
@[simp]
theorem factorThruKernelSubobject_comp_arrow {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobject f).arrow = h := by
dsimp [factorThruKernelSubobject]
simp
@[simp]
theorem factorThruKernelSubobject_comp_kernelSubobjectIso {W : C} (h : W ⟶ X) (w : h ≫ f = 0) :
factorThruKernelSubobject f h w ≫ (kernelSubobjectIso f).hom = kernel.lift f h w :=
(cancel_mono (kernel.ι f)).1 <| by simp
section
variable {f} {X' Y' : C} {f' : X' ⟶ Y'} [HasKernel f']
/-- A commuting square induces a morphism between the kernel subobjects. -/
def kernelSubobjectMap (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobject f : C) ⟶ (kernelSubobject f' : C) :=
Subobject.factorThru _ ((kernelSubobject f).arrow ≫ sq.left)
(kernelSubobject_factors _ _ (by simp))
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem kernelSubobjectMap_arrow (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernelSubobjectMap sq ≫ (kernelSubobject f').arrow = (kernelSubobject f).arrow ≫ sq.left := by
simp [kernelSubobjectMap]
@[simp]
theorem kernelSubobjectMap_id : kernelSubobjectMap (𝟙 (Arrow.mk f)) = 𝟙 _ := by cat_disch
@[simp]
theorem kernelSubobjectMap_comp {X'' Y'' : C} {f'' : X'' ⟶ Y''} [HasKernel f'']
(sq : Arrow.mk f ⟶ Arrow.mk f') (sq' : Arrow.mk f' ⟶ Arrow.mk f'') :
kernelSubobjectMap (sq ≫ sq') = kernelSubobjectMap sq ≫ kernelSubobjectMap sq' := by
cat_disch
@[reassoc]
theorem kernel_map_comp_kernelSubobjectIso_inv (sq : Arrow.mk f ⟶ Arrow.mk f') :
kernel.map f f' sq.1 sq.2 sq.3.symm ≫ (kernelSubobjectIso _).inv =
(kernelSubobjectIso _).inv ≫ kernelSubobjectMap sq := by cat_disch
@[reassoc]
theorem kernelSubobjectIso_comp_kernel_map (sq : Arrow.mk f ⟶ Arrow.mk f') :
(kernelSubobjectIso _).hom ≫ kernel.map f f' sq.1 sq.2 sq.3.symm =
kernelSubobjectMap sq ≫ (kernelSubobjectIso _).hom := by
simp [← Iso.comp_inv_eq, kernel_map_comp_kernelSubobjectIso_inv]
end
@[simp]
theorem kernelSubobject_zero {A B : C} : kernelSubobject (0 : A ⟶ B) = ⊤ :=
(isIso_iff_mk_eq_top _).mp (by infer_instance)
instance isIso_kernelSubobject_zero_arrow : IsIso (kernelSubobject (0 : X ⟶ Y)).arrow :=
(isIso_arrow_iff_eq_top _).mpr kernelSubobject_zero
theorem le_kernelSubobject (A : Subobject X) (h : A.arrow ≫ f = 0) : A ≤ kernelSubobject f :=
Subobject.le_mk_of_comm (kernel.lift f A.arrow h) (by simp)
/-- The isomorphism between the kernel of `f ≫ g` and the kernel of `g`,
when `f` is an isomorphism.
-/
def kernelSubobjectIsoComp {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobject (f ≫ g) : C) ≅ (kernelSubobject g : C) :=
kernelSubobjectIso _ ≪≫ kernelIsIsoComp f g ≪≫ (kernelSubobjectIso _).symm
@[simp]
theorem kernelSubobjectIsoComp_hom_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).hom ≫ (kernelSubobject g).arrow =
(kernelSubobject (f ≫ g)).arrow ≫ f := by
simp [kernelSubobjectIsoComp]
@[simp]
theorem kernelSubobjectIsoComp_inv_arrow {X' : C} (f : X' ⟶ X) [IsIso f] (g : X ⟶ Y) [HasKernel g] :
(kernelSubobjectIsoComp f g).inv ≫ (kernelSubobject (f ≫ g)).arrow =
(kernelSubobject g).arrow ≫ inv f := by
simp [kernelSubobjectIsoComp]
/-- The kernel of `f` is always a smaller subobject than the kernel of `f ≫ h`. -/
theorem kernelSubobject_comp_le (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [HasKernel (f ≫ h)] :
kernelSubobject f ≤ kernelSubobject (f ≫ h) :=
le_kernelSubobject _ _ (by simp)
/-- Postcomposing by a monomorphism does not change the kernel subobject. -/
@[simp]
theorem kernelSubobject_comp_mono (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
kernelSubobject (f ≫ h) = kernelSubobject f :=
le_antisymm (le_kernelSubobject _ _ ((cancel_mono h).mp (by simp))) (kernelSubobject_comp_le f h)
instance kernelSubobject_comp_mono_isIso (f : X ⟶ Y) [HasKernel f] {Z : C} (h : Y ⟶ Z) [Mono h] :
IsIso (Subobject.ofLE _ _ (kernelSubobject_comp_le f h)) := by
rw [ofLE_mk_le_mk_of_comm (kernelCompMono f h).inv]
· infer_instance
· simp
/-- Taking cokernels is an order-reversing map from the subobjects of `X` to the quotient objects
of `X`. -/
@[simps]
def cokernelOrderHom [HasCokernels C] (X : C) : Subobject X →o (Subobject (op X))ᵒᵈ where
toFun :=
Subobject.lift (fun _ f _ => Subobject.mk (cokernel.π f).op)
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ (Iso.op ?_) (Quiver.Hom.unop_inj ?_)
· exact (IsColimit.coconePointUniqueUpToIso (colimit.isColimit _)
(isCokernelEpiComp (colimit.isColimit _) i.hom rfl)).symm
· simp only [Iso.comp_inv_eq, Iso.op_hom, Iso.symm_hom, unop_comp, Quiver.Hom.unop_op,
colimit.comp_coconePointUniqueUpToIso_hom, Cofork.ofπ_ι_app,
coequalizer.cofork_π])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (cokernel.desc f (cokernel.π g) ?_).op ?_
· rw [← Subobject.ofMkLEMk_comp h, Category.assoc, cokernel.condition, comp_zero]
· exact Quiver.Hom.unop_inj (cokernel.π_desc _ _ _)
/-- Taking kernels is an order-reversing map from the quotient objects of `X` to the subobjects of
`X`. -/
@[simps]
def kernelOrderHom [HasKernels C] (X : C) : (Subobject (op X))ᵒᵈ →o Subobject X where
toFun :=
Subobject.lift (fun _ f _ => Subobject.mk (kernel.ι f.unop))
(by
rintro A B f g hf hg i rfl
refine Subobject.mk_eq_mk_of_comm _ _ ?_ ?_
· exact
IsLimit.conePointUniqueUpToIso (limit.isLimit _)
(isKernelCompMono (limit.isLimit (parallelPair g.unop 0)) i.unop.hom rfl)
· dsimp
simp only [← Iso.eq_inv_comp, limit.conePointUniqueUpToIso_inv_comp,
Fork.ofι_π_app])
monotone' :=
Subobject.ind₂ _ <| by
intro A B f g hf hg h
dsimp only [Subobject.lift_mk]
refine Subobject.mk_le_mk_of_comm (kernel.lift g.unop (kernel.ι f.unop) ?_) ?_
· rw [← Subobject.ofMkLEMk_comp h, unop_comp, kernel.condition_assoc, zero_comp]
· exact Quiver.Hom.op_inj (by simp)
end Kernel
section Image
variable (f : X ⟶ Y) [HasImage f]
/-- The image of a morphism `f g : X ⟶ Y` as a `Subobject Y`. -/
abbrev imageSubobject : Subobject Y :=
Subobject.mk (image.ι f)
/-- The underlying object of `imageSubobject f` is (up to isomorphism!)
the same as the chosen object `image f`. -/
def imageSubobjectIso : (imageSubobject f : C) ≅ image f :=
Subobject.underlyingIso (image.ι f)
@[reassoc (attr := simp)]
theorem imageSubobject_arrow :
(imageSubobjectIso f).hom ≫ image.ι f = (imageSubobject f).arrow := by simp [imageSubobjectIso]
@[reassoc (attr := simp)]
theorem imageSubobject_arrow' :
(imageSubobjectIso f).inv ≫ (imageSubobject f).arrow = image.ι f := by simp [imageSubobjectIso]
/-- A factorisation of `f : X ⟶ Y` through `imageSubobject f`. -/
def factorThruImageSubobject : X ⟶ imageSubobject f :=
factorThruImage f ≫ (imageSubobjectIso f).inv
instance [HasEqualizers C] : Epi (factorThruImageSubobject f) := by
dsimp [factorThruImageSubobject]
apply epi_comp
@[reassoc (attr := simp), elementwise (attr := simp)]
theorem imageSubobject_arrow_comp : factorThruImageSubobject f ≫ (imageSubobject f).arrow = f := by
simp [factorThruImageSubobject]
theorem imageSubobject_arrow_comp_eq_zero [HasZeroMorphisms C] {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
[HasImage f] [Epi (factorThruImageSubobject f)] (h : f ≫ g = 0) :
(imageSubobject f).arrow ≫ g = 0 :=
zero_of_epi_comp (factorThruImageSubobject f) <| by simp [h]
theorem imageSubobject_factors_comp_self {W : C} (k : W ⟶ X) : (imageSubobject f).Factors (k ≫ f) :=
⟨k ≫ factorThruImage f, by simp⟩
@[simp]
theorem factorThruImageSubobject_comp_self {W : C} (k : W ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ f) h = k ≫ factorThruImageSubobject f := by
ext
simp
@[simp]
theorem factorThruImageSubobject_comp_self_assoc {W W' : C} (k : W ⟶ W') (k' : W' ⟶ X) (h) :
(imageSubobject f).factorThru (k ≫ k' ≫ f) h = k ≫ k' ≫ factorThruImageSubobject f := by
ext
simp
/-- The image of `h ≫ f` is always a smaller subobject than the image of `f`. -/
theorem imageSubobject_comp_le {X' : C} (h : X' ⟶ X) (f : X ⟶ Y) [HasImage f] [HasImage (h ≫ f)] :
imageSubobject (h ≫ f) ≤ imageSubobject f :=
Subobject.mk_le_mk_of_comm (image.preComp h f) (by simp)
section
open ZeroObject
variable [HasZeroMorphisms C] [HasZeroObject C]
@[simp]
theorem imageSubobject_zero_arrow : (imageSubobject (0 : X ⟶ Y)).arrow = 0 := by
rw [← imageSubobject_arrow]
simp
@[simp]
theorem imageSubobject_zero {A B : C} : imageSubobject (0 : A ⟶ B) = ⊥ :=
Subobject.eq_of_comm (imageSubobjectIso _ ≪≫ imageZero ≪≫ Subobject.botCoeIsoZero.symm) (by simp)
end
section
variable [HasEqualizers C]
/-- The morphism `imageSubobject (h ≫ f) ⟶ imageSubobject f`
is an epimorphism when `h` is an epimorphism.
In general this does not imply that `imageSubobject (h ≫ f) = imageSubobject f`,
although it will when the ambient category is abelian.
-/
instance imageSubobject_comp_le_epi_of_epi {X' : C} (h : X' ⟶ X) [Epi h] (f : X ⟶ Y) [HasImage f]
[HasImage (h ≫ f)] : Epi (Subobject.ofLE _ _ (imageSubobject_comp_le h f)) := by
rw [ofLE_mk_le_mk_of_comm (image.preComp h f)]
· infer_instance
· simp
end
section
variable [HasEqualizers C]
/-- Postcomposing by an isomorphism gives an isomorphism between image subobjects. -/
def imageSubobjectCompIso (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] :
(imageSubobject (f ≫ h) : C) ≅ (imageSubobject f : C) :=
imageSubobjectIso _ ≪≫ (image.compIso _ _).symm ≪≫ (imageSubobjectIso _).symm
@[reassoc (attr := simp)]
theorem imageSubobjectCompIso_hom_arrow (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] :
(imageSubobjectCompIso f h).hom ≫ (imageSubobject f).arrow =
(imageSubobject (f ≫ h)).arrow ≫ inv h := by
simp [imageSubobjectCompIso]
@[reassoc (attr := simp)]
theorem imageSubobjectCompIso_inv_arrow (f : X ⟶ Y) [HasImage f] {Y' : C} (h : Y ⟶ Y') [IsIso h] :
(imageSubobjectCompIso f h).inv ≫ (imageSubobject (f ≫ h)).arrow =
(imageSubobject f).arrow ≫ h := by
simp [imageSubobjectCompIso]
end
theorem imageSubobject_mono (f : X ⟶ Y) [Mono f] : imageSubobject f = Subobject.mk f :=
eq_of_comm (imageSubobjectIso f ≪≫ imageMonoIsoSource f ≪≫ (underlyingIso f).symm) (by simp)
/-- Precomposing by an isomorphism does not change the image subobject. -/
theorem imageSubobject_iso_comp [HasEqualizers C] {X' : C} (h : X' ⟶ X) [IsIso h] (f : X ⟶ Y)
[HasImage f] : imageSubobject (h ≫ f) = imageSubobject f :=
le_antisymm (imageSubobject_comp_le h f)
(Subobject.mk_le_mk_of_comm (inv (image.preComp h f)) (by simp))
theorem imageSubobject_le {A B : C} {X : Subobject B} (f : A ⟶ B) [HasImage f] (h : A ⟶ X)
(w : h ≫ X.arrow = f) : imageSubobject f ≤ X :=
Subobject.le_of_comm
((imageSubobjectIso f).hom ≫
image.lift
{ I := (X : C)
e := h
m := X.arrow })
(by rw [assoc, image.lift_fac, imageSubobject_arrow])
theorem imageSubobject_le_mk {A B : C} {X : C} (g : X ⟶ B) [Mono g] (f : A ⟶ B) [HasImage f]
(h : A ⟶ X) (w : h ≫ g = f) : imageSubobject f ≤ Subobject.mk g :=
imageSubobject_le f (h ≫ (Subobject.underlyingIso g).inv) (by simp [w])
/-- Given a commutative square between morphisms `f` and `g`,
we have a morphism in the category from `imageSubobject f` to `imageSubobject g`. -/
def imageSubobjectMap {W X Y Z : C} {f : W ⟶ X} [HasImage f] {g : Y ⟶ Z} [HasImage g]
(sq : Arrow.mk f ⟶ Arrow.mk g) [HasImageMap sq] :
(imageSubobject f : C) ⟶ (imageSubobject g : C) :=
(imageSubobjectIso f).hom ≫ image.map sq ≫ (imageSubobjectIso g).inv
@[reassoc (attr := simp)]
theorem imageSubobjectMap_arrow {W X Y Z : C} {f : W ⟶ X} [HasImage f] {g : Y ⟶ Z} [HasImage g]
(sq : Arrow.mk f ⟶ Arrow.mk g) [HasImageMap sq] :
imageSubobjectMap sq ≫ (imageSubobject g).arrow = (imageSubobject f).arrow ≫ sq.right := by
simp only [imageSubobjectMap, Category.assoc, imageSubobject_arrow']
erw [image.map_ι, ← Category.assoc, imageSubobject_arrow]
theorem image_map_comp_imageSubobjectIso_inv {W X Y Z : C} {f : W ⟶ X} [HasImage f] {g : Y ⟶ Z}
[HasImage g] (sq : Arrow.mk f ⟶ Arrow.mk g) [HasImageMap sq] :
image.map sq ≫ (imageSubobjectIso _).inv =
(imageSubobjectIso _).inv ≫ imageSubobjectMap sq := by
ext
simpa using image.map_ι sq
theorem imageSubobjectIso_comp_image_map {W X Y Z : C} {f : W ⟶ X} [HasImage f] {g : Y ⟶ Z}
[HasImage g] (sq : Arrow.mk f ⟶ Arrow.mk g) [HasImageMap sq] :
(imageSubobjectIso _).hom ≫ image.map sq =
imageSubobjectMap sq ≫ (imageSubobjectIso _).hom := by
erw [← Iso.comp_inv_eq, Category.assoc, ← (imageSubobjectIso f).eq_inv_comp,
image_map_comp_imageSubobjectIso_inv sq]
end Image
end Limits
end CategoryTheory
|
Length.lean
|
/-
Copyright (c) 2025 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Algebra.Exact
import Mathlib.LinearAlgebra.Basis.VectorSpace
import Mathlib.LinearAlgebra.Dimension.Finite
import Mathlib.Order.KrullDimension
import Mathlib.RingTheory.FiniteLength
/-!
# Length of modules
## Main results
- `Module.length`: `Module.length R M` is the length of `M` as an `R`-module.
- `Module.length_pos`: The length of a nontrivial module is positive
- `Module.length_ne_top`: The length of an artinian and noetherian module is finite.
- `Module.length_eq_add_of_exact`: Length is additive in exact sequences.
-/
variable (R M : Type*) [Ring R] [AddCommGroup M] [Module R M]
/-- The length of a module, defined as the krull dimension of its submodule lattice. -/
noncomputable
def Module.length : ℕ∞ :=
(Order.krullDim (Submodule R M)).unbot (by simp [Order.krullDim_eq_bot_iff])
lemma Module.coe_length :
(Module.length R M : WithBot ℕ∞) = Order.krullDim (Submodule R M) :=
WithBot.coe_unbot _ _
lemma Module.length_eq_height : Module.length R M = Order.height (⊤ : Submodule R M) := by
apply WithBot.coe_injective
rw [Module.coe_length, Order.height_top_eq_krullDim]
lemma Module.length_eq_coheight : Module.length R M = Order.coheight (⊥ : Submodule R M) := by
apply WithBot.coe_injective
rw [Module.coe_length, Order.coheight_bot_eq_krullDim]
variable {R M}
lemma Module.length_eq_zero_iff : Module.length R M = 0 ↔ Subsingleton M := by
rw [← WithBot.coe_inj, Module.coe_length, WithBot.coe_zero,
Order.krullDim_eq_zero_iff_of_orderTop, Submodule.subsingleton_iff]
@[simp, nontriviality]
lemma Module.length_eq_zero [Subsingleton M] : Module.length R M = 0 :=
Module.length_eq_zero_iff.mpr ‹_›
@[simp, nontriviality]
lemma Module.length_eq_zero_of_subsingleton_ring [Subsingleton R] : Module.length R M = 0 :=
have := Module.subsingleton R M
Module.length_eq_zero
lemma Module.length_pos_iff : 0 < Module.length R M ↔ Nontrivial M := by
rw [pos_iff_ne_zero, ne_eq, Module.length_eq_zero_iff, not_subsingleton_iff_nontrivial]
lemma Module.length_pos [Nontrivial M] : 0 < Module.length R M :=
Module.length_pos_iff.mpr ‹_›
lemma Module.length_compositionSeries (s : CompositionSeries (Submodule R M)) (h₁ : s.head = ⊥)
(h₂ : s.last = ⊤) : s.length = Module.length R M := by
have H := isFiniteLength_of_exists_compositionSeries ⟨s, h₁, h₂⟩
have := (isFiniteLength_iff_isNoetherian_isArtinian.mp H).1
have := (isFiniteLength_iff_isNoetherian_isArtinian.mp H).2
rw [← WithBot.coe_inj, Module.coe_length]
apply le_antisymm
· exact (Order.LTSeries.length_le_krullDim <| s.map ⟨id, fun h ↦ h.1⟩)
· rw [Order.krullDim, iSup_le_iff]
intro t
refine WithBot.coe_le_coe.mpr ?_
obtain ⟨t', i, hi, ht₁, ht₂⟩ := t.exists_relSeries_covBy_and_head_eq_bot_and_last_eq_bot
have := (s.jordan_holder t' (h₁.trans ht₁.symm) (h₂.trans ht₂.symm)).choose
have h : t.length ≤ t'.length := by simpa using Fintype.card_le_of_embedding i
have h' : t'.length = s.length := by simpa using Fintype.card_congr this.symm
simpa using h.trans h'.le
lemma Module.length_eq_top_iff_infiniteDimensionalOrder :
length R M = ⊤ ↔ InfiniteDimensionalOrder (Submodule R M) := by
rw [← WithBot.coe_inj, WithBot.coe_top, coe_length, Order.krullDim_eq_top_iff,
← not_finiteDimensionalOrder_iff]
lemma Module.length_ne_top_iff_finiteDimensionalOrder :
length R M ≠ ⊤ ↔ FiniteDimensionalOrder (Submodule R M) := by
rw [Ne, length_eq_top_iff_infiniteDimensionalOrder, ← not_finiteDimensionalOrder_iff, not_not]
lemma Module.length_ne_top_iff : Module.length R M ≠ ⊤ ↔ IsFiniteLength R M := by
refine ⟨fun h ↦ ?_, fun H ↦ ?_⟩
· rw [length_ne_top_iff_finiteDimensionalOrder] at h
rw [isFiniteLength_iff_isNoetherian_isArtinian, isNoetherian_iff, isArtinian_iff]
let R : SetRel (Submodule R M) (Submodule R M) :=
{(N₁, N₂) : Submodule R M × Submodule R M | N₁ < N₂}
change R.inv.IsWellFounded ∧ R.IsWellFounded
exact ⟨.of_finiteDimensional R.inv, .of_finiteDimensional R⟩
· obtain ⟨s, hs₁, hs₂⟩ := isFiniteLength_iff_exists_compositionSeries.mp H
rw [← length_compositionSeries s hs₁ hs₂]
simp
lemma Module.length_ne_top [IsArtinian R M] [IsNoetherian R M] : Module.length R M ≠ ⊤ := by
rw [length_ne_top_iff, isFiniteLength_iff_isNoetherian_isArtinian]
exact ⟨‹_›, ‹_›⟩
lemma Module.length_submodule {N : Submodule R M} :
Module.length R N = Order.height N := by
apply WithBot.coe_injective
rw [Order.height_eq_krullDim_Iic, coe_length, Order.krullDim_eq_of_orderIso (Submodule.mapIic _)]
lemma Module.length_quotient {N : Submodule R M} :
Module.length R (M ⧸ N) = Order.coheight N := by
apply WithBot.coe_injective
rw [Order.coheight_eq_krullDim_Ici, coe_length,
Order.krullDim_eq_of_orderIso (Submodule.comapMkQRelIso N)]
lemma LinearEquiv.length_eq {N : Type*} [AddCommGroup N] [Module R N] (e : M ≃ₗ[R] N) :
Module.length R M = Module.length R N := by
apply WithBot.coe_injective
rw [Module.coe_length, Module.coe_length,
Order.krullDim_eq_of_orderIso (Submodule.orderIsoMapComap e)]
lemma Module.length_bot :
Module.length R (⊥ : Submodule R M) = 0 :=
Module.length_eq_zero
@[simp] lemma Module.length_top :
Module.length R (⊤ : Submodule R M) = Module.length R M := by
rw [Module.length_submodule, Module.length_eq_height]
lemma Submodule.height_lt_top [IsArtinian R M] [IsNoetherian R M] (N : Submodule R M) :
Order.height N < ⊤ := by
simpa only [← Module.length_submodule] using Module.length_ne_top.lt_top
lemma Submodule.height_strictMono [IsArtinian R M] [IsNoetherian R M] :
StrictMono (Order.height : Submodule R M → ℕ∞) :=
fun N _ h ↦ Order.height_strictMono h N.height_lt_top
lemma Submodule.length_lt [IsArtinian R M] [IsNoetherian R M] {N : Submodule R M} (h : N ≠ ⊤) :
Module.length R N < Module.length R M := by
simpa [← Module.length_top (M := M), Module.length_submodule] using height_strictMono h.lt_top
variable {N P : Type*} [AddCommGroup N] [AddCommGroup P] [Module R N] [Module R P]
variable (f : N →ₗ[R] M) (g : M →ₗ[R] P) (hf : Function.Injective f) (hg : Function.Surjective g)
variable (H : Function.Exact f g)
include hf hg H in
/-- Length is additive in exact sequences. -/
lemma Module.length_eq_add_of_exact :
Module.length R M = Module.length R N + Module.length R P := by
by_cases hP : IsFiniteLength R P
· by_cases hN : IsFiniteLength R N
· obtain ⟨s, hs₁, hs₂⟩ := isFiniteLength_iff_exists_compositionSeries.mp hP
obtain ⟨t, ht₁, ht₂⟩ := isFiniteLength_iff_exists_compositionSeries.mp hN
let s' : CompositionSeries (Submodule R M) :=
s.map ⟨Submodule.comap g, Submodule.comap_covBy_of_surjective hg⟩
let t' : CompositionSeries (Submodule R M) :=
t.map ⟨Submodule.map f, Submodule.map_covBy_of_injective hf⟩
have hfg : Submodule.map f ⊤ = Submodule.comap g ⊥ := by
rw [Submodule.map_top, Submodule.comap_bot, LinearMap.exact_iff.mp H]
let r := t'.smash s' (by simpa [s', t', hs₁, ht₂] using hfg)
rw [← Module.length_compositionSeries s hs₁ hs₂,
← Module.length_compositionSeries t ht₁ ht₂,
← Module.length_compositionSeries r
(by simpa [r, t', ht₁, -Submodule.map_bot] using Submodule.map_bot f)
(by simpa [r, s', hs₂, -Submodule.comap_top] using Submodule.comap_top g)]
simp_rw [r, RelSeries.smash_length, Nat.cast_add, s', t', RelSeries.map_length]
· have := mt (IsFiniteLength.of_injective · hf) hN
rw [← Module.length_ne_top_iff, ne_eq, not_not] at hN this
rw [hN, this, top_add]
· have := mt (IsFiniteLength.of_surjective · hg) hP
rw [← Module.length_ne_top_iff, ne_eq, not_not] at hP this
rw [hP, this, add_top]
include hf in
lemma Module.length_le_of_injective : Module.length R N ≤ Module.length R M := by
rw [Module.length_eq_add_of_exact f (LinearMap.range f).mkQ hf
(Submodule.mkQ_surjective _) (LinearMap.exact_map_mkQ_range f)]
exact le_self_add
include hg in
lemma Module.length_le_of_surjective : Module.length R P ≤ Module.length R M := by
rw [Module.length_eq_add_of_exact (LinearMap.ker g).subtype g (Submodule.subtype_injective _) hg
(LinearMap.exact_subtype_ker_map g)]
exact le_add_self
variable (R M N) in
@[simp]
lemma Module.length_prod :
Module.length R (M × N) = Module.length R M + Module.length R N :=
Module.length_eq_add_of_exact _ _ LinearMap.inl_injective LinearMap.snd_surjective .inl_snd
variable (R) in
@[simp]
lemma Module.length_pi_of_fintype : ∀ {ι : Type*} [Fintype ι]
(M : ι → Type*) [∀ i, AddCommGroup (M i)] [∀ i, Module R (M i)],
Module.length R (Π i, M i) = ∑ i, Module.length R (M i) := by
apply Fintype.induction_empty_option
· intro α β _ e IH M _ _
let _ : Fintype α := .ofEquiv β e.symm
rw [← (LinearEquiv.piCongrLeft R M e).length_eq, IH, e.sum_comp (length R <| M ·)]
· intro M _ _
simp [Module.length_eq_zero]
· intro ι _ IH M _ _
rw [(LinearEquiv.piOptionEquivProd _).length_eq, Module.length_prod, IH, add_comm,
Fintype.sum_option, add_comm]
@[simp]
lemma Module.length_finsupp {ι : Type*} :
Module.length R (ι →₀ M) = ENat.card ι * Module.length R M := by
cases finite_or_infinite ι
· cases nonempty_fintype ι
simp [(Finsupp.linearEquivFunOnFinite R M ι).length_eq]
nontriviality M
rw [ENat.card_eq_top_of_infinite, ENat.top_mul length_pos.ne', ENat.eq_top_iff_forall_ge]
intro m
obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq ι m
have : length R (s →₀ M) = ↑m * length R M := by
simp [(Finsupp.linearEquivFunOnFinite R M _).length_eq, hs]
refine le_trans ?_ (Module.length_le_of_injective (Finsupp.lmapDomain M R ((↑) : s → ι))
(Finsupp.mapDomain_injective Subtype.val_injective))
rw [this]
exact ENat.self_le_mul_right _ length_pos.ne'
@[simp]
lemma Module.length_pi {ι : Type*} :
Module.length R (ι → M) = ENat.card ι * Module.length R M := by
cases finite_or_infinite ι
· cases nonempty_fintype ι
simp
nontriviality M
rw [ENat.card_eq_top_of_infinite, ENat.top_mul length_pos.ne', ← top_le_iff]
refine le_trans ?_ (Module.length_le_of_injective Finsupp.lcoeFun DFunLike.coe_injective)
simp [ENat.top_mul length_pos.ne']
attribute [nontriviality] rank_subsingleton'
variable (R M) in
lemma Module.length_of_free [Module.Free R M] :
Module.length R M = (Module.rank R M).toENat * Module.length R R := by
let b := Module.Free.chooseBasis R M
nontriviality R
nontriviality M
by_cases H : Module.length R R = ⊤
· rw [b.repr.length_eq, Module.length_finsupp, H, ENat.mul_top', ENat.mul_top']
congr 1
simp [ENat.card_eq_zero_iff_empty, rank_pos_of_free.ne']
rw [← ne_eq, Module.length_ne_top_iff, isFiniteLength_iff_isNoetherian_isArtinian] at H
cases H
let b := Module.Free.chooseBasis R M
rw [b.repr.length_eq, Module.length_finsupp, Free.rank_eq_card_chooseBasisIndex, ENat.card]
variable (R M) in
lemma Module.length_of_free_of_finite
[StrongRankCondition R] [Module.Free R M] [Module.Finite R M] :
Module.length R M = Module.finrank R M * Module.length R R := by
rw [length_of_free, Cardinal.toENat_eq_nat.mpr (finrank_eq_rank _ _).symm]
lemma Module.length_eq_one_iff :
Module.length R M = 1 ↔ IsSimpleModule R M := by
rw [← WithBot.coe_inj, Module.coe_length, WithBot.coe_one,
Order.krullDim_eq_one_iff_of_boundedOrder, isSimpleModule_iff]
variable (R M) in
@[simp]
lemma Module.length_eq_one [IsSimpleModule R M] :
Module.length R M = 1 :=
Module.length_eq_one_iff.mpr ‹_›
lemma Module.length_eq_rank
(K M : Type*) [DivisionRing K] [AddCommGroup M] [Module K M] :
Module.length K M = (Module.rank K M).toENat := by
simp [Module.length_of_free]
lemma Module.length_eq_finrank
(K M : Type*) [DivisionRing K] [AddCommGroup M] [Module K M] [Module.Finite K M] :
Module.length K M = Module.finrank K M := by
simp [Module.length_of_free]
|
ExpDeriv.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne
-/
import Mathlib.Analysis.Calculus.ContDiff.RCLike
import Mathlib.Analysis.Calculus.IteratedDeriv.Lemmas
import Mathlib.Analysis.Complex.RealDeriv
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Analysis.SpecialFunctions.Exponential
/-!
# Complex and real exponential
In this file we prove that `Complex.exp` and `Real.exp` are analytic functions.
## Tags
exp, derivative
-/
assert_not_exists IsConformalMap Conformal
noncomputable section
open Filter Asymptotics Set Function
open scoped Topology
/-! ## `Complex.exp` -/
section
open Complex
variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℂ E]
variable {f g : E → ℂ} {z : ℂ} {x : E} {s : Set E}
/-- The function `Complex.exp` is complex analytic. -/
theorem analyticOnNhd_cexp : AnalyticOnNhd ℂ exp univ := by
rw [Complex.exp_eq_exp_ℂ]
exact fun x _ ↦ NormedSpace.exp_analytic x
/-- The function `Complex.exp` is complex analytic. -/
theorem analyticOn_cexp : AnalyticOn ℂ exp univ := analyticOnNhd_cexp.analyticOn
/-- The function `Complex.exp` is complex analytic. -/
@[fun_prop]
theorem analyticAt_cexp : AnalyticAt ℂ exp z :=
analyticOnNhd_cexp z (mem_univ _)
/-- The function `Complex.exp` is complex analytic. -/
lemma analyticWithinAt_cexp {s : Set ℂ} {x : ℂ} :
AnalyticWithinAt ℂ Complex.exp s x := by
exact analyticAt_cexp.analyticWithinAt
/-- `exp ∘ f` is analytic -/
@[fun_prop]
theorem AnalyticAt.cexp (fa : AnalyticAt ℂ f x) : AnalyticAt ℂ (exp ∘ f) x :=
analyticAt_cexp.comp fa
/-- `exp ∘ f` is analytic -/
@[fun_prop]
theorem AnalyticAt.cexp' (fa : AnalyticAt ℂ f x) : AnalyticAt ℂ (fun z ↦ exp (f z)) x :=
fa.cexp
theorem AnalyticWithinAt.cexp (fa : AnalyticWithinAt ℂ f s x) :
AnalyticWithinAt ℂ (fun z ↦ exp (f z)) s x :=
analyticAt_cexp.comp_analyticWithinAt fa
/-- `exp ∘ f` is analytic -/
theorem AnalyticOnNhd.cexp (fs : AnalyticOnNhd ℂ f s) : AnalyticOnNhd ℂ (fun z ↦ exp (f z)) s :=
fun z n ↦ analyticAt_cexp.comp (fs z n)
theorem AnalyticOn.cexp (fs : AnalyticOn ℂ f s) : AnalyticOn ℂ (fun z ↦ exp (f z)) s :=
analyticOnNhd_cexp.comp_analyticOn fs (mapsTo_univ _ _)
end
namespace Complex
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedAlgebra 𝕜 ℂ]
/-- The complex exponential is everywhere differentiable, with the derivative `exp x`. -/
theorem hasDerivAt_exp (x : ℂ) : HasDerivAt exp (exp x) x := by
rw [hasDerivAt_iff_isLittleO_nhds_zero]
have : (1 : ℕ) < 2 := by simp
refine (IsBigO.of_bound ‖exp x‖ ?_).trans_isLittleO (isLittleO_pow_id this)
filter_upwards [Metric.ball_mem_nhds (0 : ℂ) zero_lt_one]
simp only [Metric.mem_ball, dist_zero_right, norm_pow]
exact fun z hz => exp_bound_sq x z hz.le
@[simp]
theorem differentiable_exp : Differentiable 𝕜 exp := fun x =>
(hasDerivAt_exp x).differentiableAt.restrictScalars 𝕜
@[simp]
theorem differentiableAt_exp {x : ℂ} : DifferentiableAt 𝕜 exp x :=
differentiable_exp x
@[simp]
theorem deriv_exp : deriv exp = exp :=
funext fun x => (hasDerivAt_exp x).deriv
@[simp]
theorem iter_deriv_exp : ∀ n : ℕ, deriv^[n] exp = exp
| 0 => rfl
| n + 1 => by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
@[fun_prop]
theorem contDiff_exp {n : WithTop ℕ∞} : ContDiff 𝕜 n exp :=
analyticOnNhd_cexp.restrictScalars.contDiff
theorem hasStrictDerivAt_exp (x : ℂ) : HasStrictDerivAt exp (exp x) x :=
contDiff_exp.contDiffAt.hasStrictDerivAt' (hasDerivAt_exp x) le_rfl
theorem hasStrictFDerivAt_exp_real (x : ℂ) : HasStrictFDerivAt exp (exp x • (1 : ℂ →L[ℝ] ℂ)) x :=
(hasStrictDerivAt_exp x).complexToReal_fderiv
end Complex
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedAlgebra 𝕜 ℂ] {f : 𝕜 → ℂ} {f' : ℂ} {x : 𝕜}
{s : Set 𝕜}
theorem HasStrictDerivAt.cexp (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') x :=
(Complex.hasStrictDerivAt_exp (f x)).comp x hf
theorem HasDerivAt.cexp (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') x :=
(Complex.hasDerivAt_exp (f x)).comp x hf
theorem HasDerivWithinAt.cexp (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.exp (f x)) (Complex.exp (f x) * f') s x :=
(Complex.hasDerivAt_exp (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_cexp (hf : DifferentiableWithinAt 𝕜 f s x) (hxs : UniqueDiffWithinAt 𝕜 s x) :
derivWithin (fun x => Complex.exp (f x)) s x = Complex.exp (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.cexp.derivWithin hxs
@[simp]
theorem deriv_cexp (hc : DifferentiableAt 𝕜 f x) :
deriv (fun x => Complex.exp (f x)) x = Complex.exp (f x) * deriv f x :=
hc.hasDerivAt.cexp.deriv
end
section
variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] [NormedAlgebra 𝕜 ℂ] {E : Type*}
[NormedAddCommGroup E] [NormedSpace 𝕜 E] {f : E → ℂ} {f' : E →L[𝕜] ℂ} {x : E} {s : Set E}
theorem HasStrictFDerivAt.cexp (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) • f') x :=
(Complex.hasStrictDerivAt_exp (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivWithinAt.cexp (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.exp (f x)) (Complex.exp (f x) • f') s x :=
(Complex.hasDerivAt_exp (f x)).comp_hasFDerivWithinAt x hf
theorem HasFDerivAt.cexp (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.exp (f x)) (Complex.exp (f x) • f') x :=
hasFDerivWithinAt_univ.1 <| hf.hasFDerivWithinAt.cexp
theorem DifferentiableWithinAt.cexp (hf : DifferentiableWithinAt 𝕜 f s x) :
DifferentiableWithinAt 𝕜 (fun x => Complex.exp (f x)) s x :=
hf.hasFDerivWithinAt.cexp.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.cexp (hc : DifferentiableAt 𝕜 f x) :
DifferentiableAt 𝕜 (fun x => Complex.exp (f x)) x :=
hc.hasFDerivAt.cexp.differentiableAt
theorem DifferentiableOn.cexp (hc : DifferentiableOn 𝕜 f s) :
DifferentiableOn 𝕜 (fun x => Complex.exp (f x)) s := fun x h => (hc x h).cexp
@[simp, fun_prop]
theorem Differentiable.cexp (hc : Differentiable 𝕜 f) :
Differentiable 𝕜 fun x => Complex.exp (f x) := fun x => (hc x).cexp
@[fun_prop]
theorem ContDiff.cexp {n} (h : ContDiff 𝕜 n f) : ContDiff 𝕜 n fun x => Complex.exp (f x) :=
Complex.contDiff_exp.comp h
@[fun_prop]
theorem ContDiffAt.cexp {n} (hf : ContDiffAt 𝕜 n f x) :
ContDiffAt 𝕜 n (fun x => Complex.exp (f x)) x :=
Complex.contDiff_exp.contDiffAt.comp x hf
@[fun_prop]
theorem ContDiffOn.cexp {n} (hf : ContDiffOn 𝕜 n f s) :
ContDiffOn 𝕜 n (fun x => Complex.exp (f x)) s :=
Complex.contDiff_exp.comp_contDiffOn hf
@[fun_prop]
theorem ContDiffWithinAt.cexp {n} (hf : ContDiffWithinAt 𝕜 n f s x) :
ContDiffWithinAt 𝕜 n (fun x => Complex.exp (f x)) s x :=
Complex.contDiff_exp.contDiffAt.comp_contDiffWithinAt x hf
end
open Complex in
@[simp]
theorem iteratedDeriv_cexp_const_mul (n : ℕ) (c : ℂ) :
(iteratedDeriv n fun s : ℂ => exp (c * s)) = fun s => c ^ n * exp (c * s) := by
rw [iteratedDeriv_comp_const_mul contDiff_exp, iteratedDeriv_eq_iterate, iter_deriv_exp]
/-! ## `Real.exp` -/
section
open Real
variable {x : ℝ} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {s : Set E}
/-- The function `Real.exp` is real analytic. -/
theorem analyticOnNhd_rexp : AnalyticOnNhd ℝ exp univ := by
rw [Real.exp_eq_exp_ℝ]
exact fun x _ ↦ NormedSpace.exp_analytic x
/-- The function `Real.exp` is real analytic. -/
theorem analyticOn_rexp : AnalyticOn ℝ exp univ := analyticOnNhd_rexp.analyticOn
/-- The function `Real.exp` is real analytic. -/
@[fun_prop]
theorem analyticAt_rexp : AnalyticAt ℝ exp x :=
analyticOnNhd_rexp x (mem_univ _)
/-- The function `Real.exp` is real analytic. -/
lemma analyticWithinAt_rexp {s : Set ℝ} : AnalyticWithinAt ℝ Real.exp s x :=
analyticAt_rexp.analyticWithinAt
/-- `exp ∘ f` is analytic -/
@[fun_prop]
theorem AnalyticAt.rexp {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (exp ∘ f) x :=
analyticAt_rexp.comp fa
/-- `exp ∘ f` is analytic -/
@[fun_prop]
theorem AnalyticAt.rexp' {x : E} (fa : AnalyticAt ℝ f x) : AnalyticAt ℝ (fun z ↦ exp (f z)) x :=
fa.rexp
theorem AnalyticWithinAt.rexp {x : E} (fa : AnalyticWithinAt ℝ f s x) :
AnalyticWithinAt ℝ (fun z ↦ exp (f z)) s x :=
analyticAt_rexp.comp_analyticWithinAt fa
/-- `exp ∘ f` is analytic -/
theorem AnalyticOnNhd.rexp {s : Set E} (fs : AnalyticOnNhd ℝ f s) :
AnalyticOnNhd ℝ (fun z ↦ exp (f z)) s :=
fun z n ↦ analyticAt_rexp.comp (fs z n)
theorem AnalyticOn.rexp (fs : AnalyticOn ℝ f s) : AnalyticOn ℝ (fun z ↦ exp (f z)) s :=
analyticOnNhd_rexp.comp_analyticOn fs (mapsTo_univ _ _)
end
namespace Real
theorem hasStrictDerivAt_exp (x : ℝ) : HasStrictDerivAt exp (exp x) x :=
(Complex.hasStrictDerivAt_exp x).real_of_complex
theorem hasDerivAt_exp (x : ℝ) : HasDerivAt exp (exp x) x :=
(Complex.hasDerivAt_exp x).real_of_complex
@[fun_prop]
theorem contDiff_exp {n : WithTop ℕ∞} : ContDiff ℝ n exp :=
Complex.contDiff_exp.real_of_complex
@[simp]
theorem differentiable_exp : Differentiable ℝ exp := fun x => (hasDerivAt_exp x).differentiableAt
@[simp]
theorem differentiableAt_exp {x : ℝ} : DifferentiableAt ℝ exp x :=
differentiable_exp x
@[simp]
theorem deriv_exp : deriv exp = exp :=
funext fun x => (hasDerivAt_exp x).deriv
@[simp]
theorem iter_deriv_exp : ∀ n : ℕ, deriv^[n] exp = exp
| 0 => rfl
| n + 1 => by rw [iterate_succ_apply, deriv_exp, iter_deriv_exp n]
end Real
section
/-! Register lemmas for the derivatives of the composition of `Real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variable {f : ℝ → ℝ} {f' x : ℝ} {s : Set ℝ}
theorem HasStrictDerivAt.exp (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') x :=
(Real.hasStrictDerivAt_exp (f x)).comp x hf
theorem HasDerivAt.exp (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') x :=
(Real.hasDerivAt_exp (f x)).comp x hf
theorem HasDerivWithinAt.exp (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.exp (f x)) (Real.exp (f x) * f') s x :=
(Real.hasDerivAt_exp (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_exp (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.exp (f x)) s x = Real.exp (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.exp.derivWithin hxs
@[simp]
theorem deriv_exp (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.exp (f x)) x = Real.exp (f x) * deriv f x :=
hc.hasDerivAt.exp.deriv
end
section
/-! Register lemmas for the derivatives of the composition of `Real.exp` with a differentiable
function, for standalone use and use with `simp`. -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : Set E}
@[fun_prop]
theorem ContDiff.exp {n} (hf : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.exp (f x) :=
Real.contDiff_exp.comp hf
@[fun_prop]
theorem ContDiffAt.exp {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.exp (f x)) x :=
Real.contDiff_exp.contDiffAt.comp x hf
@[fun_prop]
theorem ContDiffOn.exp {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.exp (f x)) s :=
Real.contDiff_exp.comp_contDiffOn hf
@[fun_prop]
theorem ContDiffWithinAt.exp {n} (hf : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => Real.exp (f x)) s x :=
Real.contDiff_exp.contDiffAt.comp_contDiffWithinAt x hf
theorem HasFDerivWithinAt.exp (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Real.exp (f x)) (Real.exp (f x) • f') s x :=
(Real.hasDerivAt_exp (f x)).comp_hasFDerivWithinAt x hf
theorem HasFDerivAt.exp (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) • f') x :=
(Real.hasDerivAt_exp (f x)).comp_hasFDerivAt x hf
theorem HasStrictFDerivAt.exp (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Real.exp (f x)) (Real.exp (f x) • f') x :=
(Real.hasStrictDerivAt_exp (f x)).comp_hasStrictFDerivAt x hf
theorem DifferentiableWithinAt.exp (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.exp (f x)) s x :=
hf.hasFDerivWithinAt.exp.differentiableWithinAt
@[simp, fun_prop]
theorem DifferentiableAt.exp (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => Real.exp (f x)) x :=
hc.hasFDerivAt.exp.differentiableAt
@[fun_prop]
theorem DifferentiableOn.exp (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => Real.exp (f x)) s := fun x h => (hc x h).exp
@[simp, fun_prop]
theorem Differentiable.exp (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.exp (f x) :=
fun x => (hc x).exp
theorem fderivWithin_exp (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => Real.exp (f x)) s x = Real.exp (f x) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.exp.fderivWithin hxs
@[simp]
theorem fderiv_exp (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => Real.exp (f x)) x = Real.exp (f x) • fderiv ℝ f x :=
hc.hasFDerivAt.exp.fderiv
end
open Real in
@[simp]
theorem iteratedDeriv_exp_const_mul (n : ℕ) (c : ℝ) :
(iteratedDeriv n fun s => exp (c * s)) = fun s => c ^ n * exp (c * s) := by
rw [iteratedDeriv_comp_const_mul contDiff_exp, iteratedDeriv_eq_iterate, iter_deriv_exp]
|
Basic.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 Batteries.Tactic.Alias
import Mathlib.Tactic.Lemma
import Mathlib.Tactic.TypeStar
/-!
# Helper definitions and instances for `Ordering`
-/
universe u
namespace Ordering
variable {α : Type*}
/-- `Compares o a b` means that `a` and `b` have the ordering relation `o` between them, assuming
that the relation `a < b` is defined. -/
def Compares [LT α] : Ordering → α → α → Prop
| lt, a, b => a < b
| eq, a, b => a = b
| gt, a, b => a > b
@[simp] lemma compares_lt [LT α] (a b : α) : Compares lt a b = (a < b) := rfl
@[simp] lemma compares_eq [LT α] (a b : α) : Compares eq a b = (a = b) := rfl
@[simp] lemma compares_gt [LT α] (a b : α) : Compares gt a b = (a > b) := rfl
/-- `o₁.dthen fun h => o₂(h)` is like `o₁.then o₂` but `o₂` is allowed to depend on
`h : o₁ = .eq`. -/
@[macro_inline] def dthen :
(o : Ordering) → (o = .eq → Ordering) → Ordering
| .eq, f => f rfl
| o, _ => o
end Ordering
/--
Lift a decidable relation to an `Ordering`,
assuming that incomparable terms are `Ordering.eq`.
-/
def cmpUsing {α : Type u} (lt : α → α → Prop) [DecidableRel lt] (a b : α) : Ordering :=
if lt a b then Ordering.lt else if lt b a then Ordering.gt else Ordering.eq
/--
Construct an `Ordering` from a type with a decidable `LT` instance,
assuming that incomparable terms are `Ordering.eq`.
-/
def cmp {α : Type u} [LT α] [DecidableLT α] (a b : α) : Ordering :=
cmpUsing (· < ·) a b
|
ChainOfFn.lean
|
/-
Copyright (c) 2024 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import Mathlib.Data.List.Chain
import Mathlib.Data.List.OfFn
/-!
# Lemmas about `Chain'` and `OfFn`
This file provides lemmas involving both `List.Chain'` and `List.OfFn`.
-/
open Nat
namespace List
lemma chain'_ofFn {α : Type*} {n : ℕ} {f : Fin n → α} {r : α → α → Prop} :
(ofFn f).Chain' r ↔ ∀ (i) (hi : i + 1 < n), r (f ⟨i, lt_of_succ_lt hi⟩) (f ⟨i + 1, hi⟩) := by
simp_rw [chain'_iff_get, get_ofFn, length_ofFn]
exact ⟨fun h i hi ↦ h i (by omega), fun h i hi ↦ h i (by omega)⟩
end List
|
TensorProduct.lean
|
/-
Copyright (c) 2024 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, Andrew Yang
-/
import Mathlib.LinearAlgebra.TensorProduct.Tower
import Mathlib.RingTheory.Coalgebra.Equiv
/-!
# Tensor products of coalgebras
Suppose `S` is an `R`-algebra. Given an `S`-coalgebra `A` and `R`-coalgebra `B`, we can define
a natural comultiplication map `Δ : A ⊗[R] B → (A ⊗[R] B) ⊗[S] (A ⊗[R] B)`
and counit map `ε : A ⊗[R] B → S` induced by the comultiplication and counit maps of `A` and `B`.
In this file we show that `Δ, ε` satisfy the axioms of a coalgebra, and also define other data
in the monoidal structure on `R`-coalgebras, like the tensor product of two coalgebra morphisms
as a coalgebra morphism.
In particular, when `R = S` we get tensor products of coalgebras, and when `A = S` we get
the base change `S ⊗[R] B` as an `S`-coalgebra.
-/
open TensorProduct
variable {R S A B : Type*} [CommSemiring R] [CommSemiring S] [AddCommMonoid A] [AddCommMonoid B]
[Algebra R S] [Module R A] [Module S A] [Module R B] [Coalgebra R B]
[Coalgebra S A] [IsScalarTower R S A]
namespace TensorProduct
open Coalgebra
noncomputable
instance instCoalgebraStruct : CoalgebraStruct S (A ⊗[R] B) where
comul :=
AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B ∘ₗ
AlgebraTensorModule.map comul comul
counit := AlgebraTensorModule.rid R S S ∘ₗ AlgebraTensorModule.map counit counit
lemma comul_def :
Coalgebra.comul (R := S) (A := A ⊗[R] B) =
AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B ∘ₗ
AlgebraTensorModule.map Coalgebra.comul Coalgebra.comul :=
rfl
@[deprecated (since := "2025-04-09")] alias instCoalgebraStruct_comul := comul_def
lemma counit_def :
Coalgebra.counit (R := S) (A := A ⊗[R] B) =
AlgebraTensorModule.rid R S S ∘ₗ AlgebraTensorModule.map counit counit :=
rfl
@[deprecated (since := "2025-04-09")] alias instCoalgebraStruct_counit := counit_def
@[simp]
lemma comul_tmul (x : A) (y : B) :
comul (x ⊗ₜ y) =
AlgebraTensorModule.tensorTensorTensorComm R S R S A A B B (comul x ⊗ₜ comul y) := rfl
@[simp]
lemma counit_tmul (x : A) (y : B) :
counit (R := S) (x ⊗ₜ[R] y) = counit (R := R) y • counit (R := S) x := rfl
open Lean.Parser.Tactic in
/-- `hopf_tensor_induction x with x₁ x₂` attempts to replace `x` by
`x₁ ⊗ₜ x₂` via linearity. This is an implementation detail that is used to set up tensor products
of coalgebras, bialgebras, and hopf algebras, and shouldn't be relied on downstream. -/
scoped macro "hopf_tensor_induction " var:elimTarget "with " var₁:ident var₂:ident : tactic =>
`(tactic|
(induction $var with
| zero => simp only [tmul_zero, LinearEquiv.map_zero, LinearMap.map_zero,
zero_tmul, zero_mul, mul_zero]
| add _ _ h₁ h₂ =>
-- avoid the more general `map_add` for performance reasons
simp only [LinearEquiv.map_add, LinearMap.map_add,
tmul_add, add_tmul, add_mul, mul_add, h₁, h₂]
| tmul $var₁ $var₂ => ?_))
private lemma coassoc :
TensorProduct.assoc S (A ⊗[R] B) (A ⊗[R] B) (A ⊗[R] B) ∘ₗ
(comul (R := S) (A := (A ⊗[R] B))).rTensor (A ⊗[R] B) ∘ₗ
(comul (R := S) (A := (A ⊗[R] B))) =
(comul (R := S) (A := (A ⊗[R] B))).lTensor (A ⊗[R] B) ∘ₗ
(comul (R := S) (A := (A ⊗[R] B))) := by
ext x y
let F : A ⊗[S] (A ⊗[S] A) ⊗[R] (B ⊗[R] (B ⊗[R] B)) ≃ₗ[S]
A ⊗[R] B ⊗[S] (A ⊗[R] B ⊗[S] (A ⊗[R] B)) :=
AlgebraTensorModule.tensorTensorTensorComm _ _ _ _ _ _ _ _ ≪≫ₗ
AlgebraTensorModule.congr (.refl _ _)
(AlgebraTensorModule.tensorTensorTensorComm _ _ _ _ _ _ _ _)
let F' : A ⊗[S] (A ⊗[S] A) ⊗[R] (B ⊗[R] (B ⊗[R] B)) →ₗ[S]
A ⊗[R] B ⊗[S] (A ⊗[R] B ⊗[S] (A ⊗[R] B)) :=
TensorProduct.mapOfCompatibleSMul _ _ _ _ ∘ₗ
TensorProduct.map .id (TensorProduct.mapOfCompatibleSMul _ _ _ _) ∘ₗ F.toLinearMap
convert congr(F ($(Coalgebra.coassoc_apply x) ⊗ₜ[R] $(Coalgebra.coassoc_apply y))) using 1
· dsimp
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
dsimp
hopf_tensor_induction comul (R := S) x₁ with x₁₁ x₁₂
hopf_tensor_induction comul (R := R) y₁ with y₁₁ y₁₂
rfl
· dsimp
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
dsimp
hopf_tensor_induction comul (R := S) x₂ with x₂₁ x₂₂
hopf_tensor_induction comul (R := R) y₂ with y₂₁ y₂₂
rfl
noncomputable
instance instCoalgebra : Coalgebra S (A ⊗[R] B) where
coassoc := coassoc (R := R)
rTensor_counit_comp_comul := by
ext x y
convert congr((TensorProduct.lid S _).symm
(TensorProduct.lid _ _ $(rTensor_counit_comul (R := S) x) ⊗ₜ[R]
TensorProduct.lid _ _ $(rTensor_counit_comul (R := R) y)))
· dsimp
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
apply (TensorProduct.lid S _).injective
dsimp
rw [tmul_smul, smul_assoc, one_smul, smul_tmul']
· dsimp
simp only [one_smul]
lTensor_counit_comp_comul := by
ext x y
convert congr((TensorProduct.rid S _).symm
(TensorProduct.rid _ _ $(lTensor_counit_comul (R := S) x) ⊗ₜ[R]
TensorProduct.rid _ _ $(lTensor_counit_comul (R := R) y)))
· dsimp
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
apply (TensorProduct.rid S _).injective
dsimp
rw [tmul_smul, smul_assoc, one_smul, smul_tmul']
· dsimp
simp only [one_smul]
instance [IsCocomm S A] [IsCocomm R B] : IsCocomm S (A ⊗[R] B) where
comm_comp_comul := by
ext x y
dsimp
conv_rhs => rw [← comm_comul _ x, ← comm_comul _ y]
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
simp
end TensorProduct
namespace Coalgebra
namespace TensorProduct
variable {R S M N P Q : Type*} [CommSemiring R] [CommSemiring S] [Algebra R S]
[AddCommMonoid M] [AddCommMonoid N] [AddCommMonoid P] [AddCommMonoid Q] [Module R M] [Module R N]
[Module R P] [Module R Q] [Module S M] [IsScalarTower R S M] [Coalgebra S M] [Module S N]
[IsScalarTower R S N] [Coalgebra S N] [Coalgebra R P] [Coalgebra R Q]
section
/-- The tensor product of two coalgebra morphisms as a coalgebra morphism. -/
noncomputable def map (f : M →ₗc[S] N) (g : P →ₗc[R] Q) :
M ⊗[R] P →ₗc[S] N ⊗[R] Q where
toLinearMap := AlgebraTensorModule.map f.toLinearMap g.toLinearMap
counit_comp := by ext; simp
map_comp_comul := by
ext x y
dsimp
simp only [← CoalgHomClass.map_comp_comul_apply]
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := R) y with y₁ y₂
simp
@[simp]
theorem map_tmul (f : M →ₗc[S] N) (g : P →ₗc[R] Q) (x : M) (y : P) :
map f g (x ⊗ₜ y) = f x ⊗ₜ g y :=
rfl
@[simp]
theorem map_toLinearMap (f : M →ₗc[S] N) (g : P →ₗc[R] Q) :
map f g = AlgebraTensorModule.map (f : M →ₗ[S] N) (g : P →ₗ[R] Q) := rfl
variable (R S M N P)
/-- The associator for tensor products of R-coalgebras, as a coalgebra equivalence. -/
protected noncomputable def assoc :
(M ⊗[S] N) ⊗[R] P ≃ₗc[S] M ⊗[S] (N ⊗[R] P) :=
{ AlgebraTensorModule.assoc R S S M N P with
counit_comp := by ext; simp
map_comp_comul := by
ext x y z
dsimp
hopf_tensor_induction comul (R := S) x with x₁ x₂
hopf_tensor_induction comul (R := S) y with y₁ y₂
hopf_tensor_induction comul (R := R) z with z₁ z₂
simp }
variable {R S M N P}
@[simp]
theorem assoc_tmul (x : M) (y : N) (z : P) :
Coalgebra.TensorProduct.assoc R S M N P ((x ⊗ₜ y) ⊗ₜ z) = x ⊗ₜ (y ⊗ₜ z) :=
rfl
@[simp]
theorem assoc_symm_tmul (x : M) (y : N) (z : P) :
(Coalgebra.TensorProduct.assoc R S M N P).symm (x ⊗ₜ (y ⊗ₜ z)) = (x ⊗ₜ y) ⊗ₜ z :=
rfl
@[simp]
theorem assoc_toLinearEquiv :
Coalgebra.TensorProduct.assoc R S M N P = AlgebraTensorModule.assoc R S S M N P := rfl
variable (R P)
/-- The base ring is a left identity for the tensor product of coalgebras, up to
coalgebra equivalence. -/
protected noncomputable def lid : R ⊗[R] P ≃ₗc[R] P :=
{ _root_.TensorProduct.lid R P with
counit_comp := by ext; simp
map_comp_comul := by
ext x
dsimp
simp only [one_smul]
hopf_tensor_induction comul (R := R) x with x₁ x₂
simp }
variable {R P}
@[simp]
theorem lid_toLinearEquiv :
(Coalgebra.TensorProduct.lid R P) = _root_.TensorProduct.lid R P := rfl
@[simp]
theorem lid_tmul (r : R) (a : P) : Coalgebra.TensorProduct.lid R P (r ⊗ₜ a) = r • a := rfl
@[simp]
theorem lid_symm_apply (a : P) : (Coalgebra.TensorProduct.lid R P).symm a = 1 ⊗ₜ a := rfl
variable (R S M) in
/-- The base ring is a right identity for the tensor product of coalgebras, up to
coalgebra equivalence. -/
protected noncomputable def rid : M ⊗[R] R ≃ₗc[S] M :=
{ AlgebraTensorModule.rid R S M with
counit_comp := by ext; simp
map_comp_comul := by
ext x
dsimp
simp only [one_smul]
hopf_tensor_induction comul (R := S) x with x₁ x₂
simp }
@[simp]
theorem rid_toLinearEquiv :
(Coalgebra.TensorProduct.rid R S M) = AlgebraTensorModule.rid R S M := rfl
@[simp]
theorem rid_tmul (r : R) (a : M) : Coalgebra.TensorProduct.rid R S M (a ⊗ₜ r) = r • a := rfl
@[simp]
theorem rid_symm_apply (a : M) : (Coalgebra.TensorProduct.rid R S M).symm a = a ⊗ₜ 1 := rfl
end
end TensorProduct
end Coalgebra
namespace CoalgHom
variable {R M N P : Type*} [CommRing R]
[AddCommGroup M] [AddCommGroup N] [AddCommGroup P] [Module R M] [Module R N]
[Module R P] [Coalgebra R M] [Coalgebra R N] [Coalgebra R P]
variable (M)
/-- `lTensor M f : M ⊗ N →ₗc M ⊗ P` is the natural coalgebra morphism induced by `f : N →ₗc P`. -/
noncomputable abbrev lTensor (f : N →ₗc[R] P) : M ⊗[R] N →ₗc[R] M ⊗[R] P :=
Coalgebra.TensorProduct.map (CoalgHom.id R M) f
/-- `rTensor M f : N ⊗ M →ₗc P ⊗ M` is the natural coalgebra morphism induced by `f : N →ₗc P`. -/
noncomputable abbrev rTensor (f : N →ₗc[R] P) : N ⊗[R] M →ₗc[R] P ⊗[R] M :=
Coalgebra.TensorProduct.map f (CoalgHom.id R M)
end CoalgHom
|
Nodup.lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kenny Lau
-/
import Mathlib.Data.List.Forall2
/-!
# Lists with no duplicates
`List.Nodup` is defined in `Data/List/Basic`. In this file we prove various properties of this
predicate.
-/
universe u v
open Function
variable {α : Type u} {β : Type v} {l l₁ l₂ : List α} {r : α → α → Prop} {a : α}
namespace List
protected theorem Pairwise.nodup {l : List α} {r : α → α → Prop} [IsIrrefl α r] (h : Pairwise r l) :
Nodup l :=
h.imp ne_of_irrefl
open scoped Relator in
theorem rel_nodup {r : α → β → Prop} (hr : Relator.BiUnique r) : (Forall₂ r ⇒ (· ↔ ·)) Nodup Nodup
| _, _, Forall₂.nil => by simp only [nodup_nil]
| _, _, Forall₂.cons hab h => by
simpa only [nodup_cons] using
Relator.rel_and (Relator.rel_not (rel_mem hr hab h)) (rel_nodup hr h)
protected theorem Nodup.cons (ha : a ∉ l) (hl : Nodup l) : Nodup (a :: l) :=
nodup_cons.2 ⟨ha, hl⟩
theorem nodup_singleton (a : α) : Nodup [a] :=
pairwise_singleton _ _
theorem Nodup.of_cons (h : Nodup (a :: l)) : Nodup l :=
(nodup_cons.1 h).2
theorem Nodup.notMem (h : (a :: l).Nodup) : a ∉ l :=
(nodup_cons.1 h).1
@[deprecated (since := "2025-05-23")] alias Nodup.not_mem := Nodup.notMem
theorem not_nodup_cons_of_mem : a ∈ l → ¬Nodup (a :: l) :=
imp_not_comm.1 Nodup.notMem
theorem not_nodup_pair (a : α) : ¬Nodup [a, a] :=
not_nodup_cons_of_mem <| mem_singleton_self _
theorem nodup_iff_sublist {l : List α} : Nodup l ↔ ∀ a, ¬[a, a] <+ l :=
⟨fun d a h => not_nodup_pair a (d.sublist h),
by
induction l <;> intro h; · exact nodup_nil
case cons a l IH =>
exact (IH fun a s => h a <| sublist_cons_of_sublist _ s).cons
fun al => h a <| (singleton_sublist.2 al).cons_cons _⟩
@[simp]
theorem nodup_mergeSort {l : List α} {le : α → α → Bool} : (l.mergeSort le).Nodup ↔ l.Nodup :=
(mergeSort_perm l le).nodup_iff
protected alias ⟨_, Nodup.mergeSort⟩ := nodup_mergeSort
theorem nodup_iff_injective_getElem {l : List α} :
Nodup l ↔ Function.Injective (fun i : Fin l.length => l[i.1]) :=
pairwise_iff_getElem.trans
⟨fun h i j hg => by
obtain ⟨i, hi⟩ := i; obtain ⟨j, hj⟩ := j
rcases lt_trichotomy i j with (hij | rfl | hji)
· exact (h i j hi hj hij hg).elim
· rfl
· exact (h j i hj hi hji hg.symm).elim,
fun hinj i j hi hj hij h => Nat.ne_of_lt hij (Fin.val_eq_of_eq (@hinj ⟨i, hi⟩ ⟨j, hj⟩ h))⟩
theorem nodup_iff_injective_get {l : List α} :
Nodup l ↔ Function.Injective l.get := by
rw [nodup_iff_injective_getElem]
change _ ↔ Injective (fun i => l.get i)
simp
theorem Nodup.get_inj_iff {l : List α} (h : Nodup l) {i j : Fin l.length} :
l.get i = l.get j ↔ i = j :=
(nodup_iff_injective_get.1 h).eq_iff
theorem Nodup.getElem_inj_iff {l : List α} (h : Nodup l)
{i : Nat} {hi : i < l.length} {j : Nat} {hj : j < l.length} :
l[i] = l[j] ↔ i = j := by
have := @Nodup.get_inj_iff _ _ h ⟨i, hi⟩ ⟨j, hj⟩
simpa
theorem nodup_iff_getElem?_ne_getElem? {l : List α} :
l.Nodup ↔ ∀ i j : ℕ, i < j → j < l.length → l[i]? ≠ l[j]? := by
rw [Nodup, pairwise_iff_getElem]
constructor
· intro h i j hij hj
rw [getElem?_eq_getElem (lt_trans hij hj), getElem?_eq_getElem hj, Ne, Option.some_inj]
exact h _ _ (by omega) hj hij
· intro h i j hi hj hij
rw [Ne, ← Option.some_inj, ← getElem?_eq_getElem, ← getElem?_eq_getElem]
exact h i j hij hj
set_option linter.deprecated false in
@[deprecated nodup_iff_getElem?_ne_getElem? (since := "2025-02-17")]
theorem nodup_iff_get?_ne_get? {l : List α} :
l.Nodup ↔ ∀ i j : ℕ, i < j → j < l.length → l.get? i ≠ l.get? j := by
simp [nodup_iff_getElem?_ne_getElem?]
theorem Nodup.ne_singleton_iff {l : List α} (h : Nodup l) (x : α) :
l ≠ [x] ↔ l = [] ∨ ∃ y ∈ l, y ≠ x := by
induction l with
| nil => simp
| cons hd tl hl =>
specialize hl h.of_cons
by_cases hx : tl = [x]
· simpa [hx, and_comm, and_or_left] using h
· rw [← Ne, hl] at hx
rcases hx with (rfl | ⟨y, hy, hx⟩)
· simp
· suffices ∃ y ∈ hd :: tl, y ≠ x by simpa [ne_nil_of_mem hy]
exact ⟨y, mem_cons_of_mem _ hy, hx⟩
theorem not_nodup_of_get_eq_of_ne (xs : List α) (n m : Fin xs.length)
(h : xs.get n = xs.get m) (hne : n ≠ m) : ¬Nodup xs := by
rw [nodup_iff_injective_get]
exact fun hinj => hne (hinj h)
theorem idxOf_getElem [DecidableEq α] {l : List α} (H : Nodup l) (i : Nat) (h : i < l.length) :
idxOf l[i] l = i :=
suffices (⟨idxOf l[i] l, idxOf_lt_length_iff.2 (getElem_mem _)⟩ : Fin l.length) = ⟨i, h⟩
from Fin.val_eq_of_eq this
nodup_iff_injective_get.1 H (by simp)
-- This is incorrectly named and should be `idxOf_get`;
-- this already exists, so will require a deprecation dance.
theorem get_idxOf [DecidableEq α] {l : List α} (H : Nodup l) (i : Fin l.length) :
idxOf (get l i) l = i := by
simp [idxOf_getElem, H]
theorem nodup_iff_count_le_one [DecidableEq α] {l : List α} : Nodup l ↔ ∀ a, count a l ≤ 1 :=
nodup_iff_sublist.trans <|
forall_congr' fun a =>
have : replicate 2 a <+ l ↔ 1 < count a l := replicate_sublist_iff ..
(not_congr this).trans not_lt
theorem nodup_iff_count_eq_one [DecidableEq α] : Nodup l ↔ ∀ a ∈ l, count a l = 1 :=
nodup_iff_count_le_one.trans <| forall_congr' fun _ =>
⟨fun H h => H.antisymm (count_pos_iff.mpr h),
fun H => if h : _ then (H h).le else (count_eq_zero.mpr h).trans_le (Nat.zero_le 1)⟩
@[simp]
theorem count_eq_one_of_mem [DecidableEq α] {a : α} {l : List α} (d : Nodup l) (h : a ∈ l) :
count a l = 1 :=
_root_.le_antisymm (nodup_iff_count_le_one.1 d a) (Nat.succ_le_of_lt (count_pos_iff.2 h))
theorem count_eq_of_nodup [DecidableEq α] {a : α} {l : List α} (d : Nodup l) :
count a l = if a ∈ l then 1 else 0 := by
split_ifs with h
· exact count_eq_one_of_mem d h
· exact count_eq_zero_of_not_mem h
theorem Nodup.of_append_left : Nodup (l₁ ++ l₂) → Nodup l₁ :=
Nodup.sublist (sublist_append_left l₁ l₂)
theorem Nodup.of_append_right : Nodup (l₁ ++ l₂) → Nodup l₂ :=
Nodup.sublist (sublist_append_right l₁ l₂)
/-- This is a variant of the `nodup_append` from the standard library,
which does not use `Disjoint`. -/
theorem nodup_append' {l₁ l₂ : List α} :
Nodup (l₁ ++ l₂) ↔ Nodup l₁ ∧ Nodup l₂ ∧ Disjoint l₁ l₂ := by
simp only [Nodup, pairwise_append, disjoint_iff_ne]
theorem disjoint_of_nodup_append {l₁ l₂ : List α} (d : Nodup (l₁ ++ l₂)) : Disjoint l₁ l₂ :=
(nodup_append'.1 d).2.2
theorem Nodup.append (d₁ : Nodup l₁) (d₂ : Nodup l₂) (dj : Disjoint l₁ l₂) : Nodup (l₁ ++ l₂) :=
nodup_append'.2 ⟨d₁, d₂, dj⟩
theorem nodup_append_comm {l₁ l₂ : List α} : Nodup (l₁ ++ l₂) ↔ Nodup (l₂ ++ l₁) := by
simp only [nodup_append', and_left_comm, disjoint_comm]
theorem nodup_middle {a : α} {l₁ l₂ : List α} :
Nodup (l₁ ++ a :: l₂) ↔ Nodup (a :: (l₁ ++ l₂)) := by
simp only [nodup_append', not_or, and_left_comm, and_assoc, nodup_cons, mem_append,
disjoint_cons_right]
theorem Nodup.of_map (f : α → β) {l : List α} : Nodup (map f l) → Nodup l :=
(Pairwise.of_map f) fun _ _ => mt <| congr_arg f
theorem Nodup.map_on {f : α → β} (H : ∀ x ∈ l, ∀ y ∈ l, f x = f y → x = y) (d : Nodup l) :
(map f l).Nodup :=
Pairwise.map _ (fun a b ⟨ma, mb, n⟩ e => n (H a ma b mb e)) (Pairwise.and_mem.1 d)
theorem inj_on_of_nodup_map {f : α → β} {l : List α} (d : Nodup (map f l)) :
∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → f x = f y → x = y := by
induction l with
| nil => simp
| cons hd tl ih =>
simp only [map, nodup_cons, mem_map, not_exists, not_and, ← Ne.eq_def] at d
simp only [mem_cons]
rintro _ (rfl | h₁) _ (rfl | h₂) h₃
· rfl
· apply (d.1 _ h₂ h₃.symm).elim
· apply (d.1 _ h₁ h₃).elim
· apply ih d.2 h₁ h₂ h₃
theorem nodup_map_iff_inj_on {f : α → β} {l : List α} (d : Nodup l) :
Nodup (map f l) ↔ ∀ x ∈ l, ∀ y ∈ l, f x = f y → x = y :=
⟨inj_on_of_nodup_map, fun h => d.map_on h⟩
protected theorem Nodup.map {f : α → β} (hf : Injective f) : Nodup l → Nodup (map f l) :=
Nodup.map_on fun _ _ _ _ h => hf h
theorem nodup_map_iff {f : α → β} {l : List α} (hf : Injective f) : Nodup (map f l) ↔ Nodup l :=
⟨Nodup.of_map _, Nodup.map hf⟩
@[simp]
theorem nodup_attach {l : List α} : Nodup (attach l) ↔ Nodup l :=
⟨fun h => attach_map_subtype_val l ▸ h.map fun _ _ => Subtype.eq, fun h =>
Nodup.of_map Subtype.val ((attach_map_subtype_val l).symm ▸ h)⟩
protected alias ⟨Nodup.of_attach, Nodup.attach⟩ := nodup_attach
theorem Nodup.pmap {p : α → Prop} {f : ∀ a, p a → β} {l : List α} {H}
(hf : ∀ a ha b hb, f a ha = f b hb → a = b) (h : Nodup l) : Nodup (pmap f l H) := by
rw [pmap_eq_map_attach]
exact h.attach.map fun ⟨a, ha⟩ ⟨b, hb⟩ h => by congr; exact hf a (H _ ha) b (H _ hb) h
theorem Nodup.filter (p : α → Bool) {l} : Nodup l → Nodup (filter p l) := by
simpa using Pairwise.filter p
@[simp]
theorem nodup_reverse {l : List α} : Nodup (reverse l) ↔ Nodup l :=
pairwise_reverse.trans <| by simp only [Nodup, Ne, eq_comm]
theorem nodup_concat (l : List α) (u : α) : (l.concat u).Nodup ↔ u ∉ l ∧ l.Nodup := by
rw [← nodup_reverse]
simp
lemma nodup_tail_reverse (l : List α) (h : l[0]? = l.getLast?) :
Nodup l.reverse.tail ↔ Nodup l.tail := by
induction l with
| nil => simp
| cons a l ih =>
by_cases hl : l = []
· aesop
· simp_all only [List.tail_reverse, List.nodup_reverse,
List.dropLast_cons_of_ne_nil hl, List.tail_cons]
simp only [length_cons, Nat.zero_lt_succ, getElem?_eq_getElem,
Nat.add_one_sub_one, Nat.lt_add_one, Option.some.injEq, List.getElem_cons,
show l.length ≠ 0 by aesop, ↓reduceDIte, getLast?_eq_getElem?] at h
rw [h,
show l.Nodup = (l.dropLast ++ [l.getLast hl]).Nodup by
simp [List.dropLast_eq_take],
List.nodup_append_comm]
simp [List.getLast_eq_getElem]
theorem Nodup.erase_getElem [DecidableEq α] {l : List α} (hl : l.Nodup)
(i : Nat) (h : i < l.length) : l.erase l[i] = l.eraseIdx ↑i := by
induction l generalizing i with
| nil => simp
| cons a l IH =>
cases i with
| zero => simp
| succ i =>
rw [nodup_cons] at hl
rw [erase_cons_tail]
· simp [IH hl.2]
· rw [beq_iff_eq]
simp only [getElem_cons_succ]
simp only [length_cons, Nat.add_lt_add_iff_right] at h
exact mt (· ▸ getElem_mem h) hl.1
theorem Nodup.erase_get [DecidableEq α] {l : List α} (hl : l.Nodup) (i : Fin l.length) :
l.erase (l.get i) = l.eraseIdx ↑i := by
simp [erase_getElem, hl]
theorem Nodup.diff [DecidableEq α] : l₁.Nodup → (l₁.diff l₂).Nodup :=
Nodup.sublist <| diff_sublist _ _
theorem nodup_flatten {L : List (List α)} :
Nodup (flatten L) ↔ (∀ l ∈ L, Nodup l) ∧ Pairwise Disjoint L := by
simp only [Nodup, pairwise_flatten, disjoint_left.symm, forall_mem_ne]
theorem nodup_flatMap {l₁ : List α} {f : α → List β} :
Nodup (l₁.flatMap f) ↔
(∀ x ∈ l₁, Nodup (f x)) ∧ Pairwise (Disjoint on f) l₁ := by
simp only [List.flatMap, nodup_flatten, pairwise_map, and_comm, mem_map,
exists_imp, and_imp]
rw [show (∀ (l : List β) (x : α), f x = l → x ∈ l₁ → Nodup l) ↔ ∀ x : α, x ∈ l₁ → Nodup (f x)
from forall_swap.trans <| forall_congr' fun _ => forall_eq']
protected theorem Nodup.product {l₂ : List β} (d₁ : l₁.Nodup) (d₂ : l₂.Nodup) :
(l₁ ×ˢ l₂).Nodup :=
nodup_flatMap.2
⟨fun a _ => d₂.map <| LeftInverse.injective fun b => (rfl : (a, b).2 = b),
d₁.imp fun {a₁ a₂} n x h₁ h₂ => by
rcases mem_map.1 h₁ with ⟨b₁, _, rfl⟩
rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩
exact n rfl⟩
theorem Nodup.sigma {σ : α → Type*} {l₂ : ∀ a, List (σ a)} (d₁ : Nodup l₁)
(d₂ : ∀ a, Nodup (l₂ a)) : (l₁.sigma l₂).Nodup :=
nodup_flatMap.2
⟨fun a _ => (d₂ a).map fun b b' h => by injection h with _ h,
d₁.imp fun {a₁ a₂} n x h₁ h₂ => by
rcases mem_map.1 h₁ with ⟨b₁, _, rfl⟩
rcases mem_map.1 h₂ with ⟨b₂, mb₂, ⟨⟩⟩
exact n rfl⟩
protected theorem Nodup.filterMap {f : α → Option β} (h : ∀ a a' b, b ∈ f a → b ∈ f a' → a = a') :
Nodup l → Nodup (filterMap f l) :=
(Pairwise.filterMap f) @fun a a' n b bm b' bm' e => n <| h a a' b' (by rw [← e]; exact bm) bm'
protected theorem Nodup.concat (h : a ∉ l) (h' : l.Nodup) : (l.concat a).Nodup := by
rw [concat_eq_append]; exact h'.append (nodup_singleton _) (disjoint_singleton.2 h)
protected theorem Nodup.insert [DecidableEq α] (h : l.Nodup) : (l.insert a).Nodup :=
if h' : a ∈ l then by rw [insert_of_mem h']; exact h
else by rw [insert_of_not_mem h', nodup_cons]; constructor <;> assumption
theorem Nodup.union [DecidableEq α] (l₁ : List α) (h : Nodup l₂) : (l₁ ∪ l₂).Nodup := by
induction l₁ generalizing l₂ with
| nil => exact h
| cons a l₁ ih => exact (ih h).insert
theorem Nodup.inter [DecidableEq α] (l₂ : List α) : Nodup l₁ → Nodup (l₁ ∩ l₂) :=
Nodup.filter _
theorem Nodup.diff_eq_filter [BEq α] [LawfulBEq α] :
∀ {l₁ l₂ : List α} (_ : l₁.Nodup), l₁.diff l₂ = l₁.filter (· ∉ l₂)
| l₁, [], _ => by simp
| l₁, a :: l₂, hl₁ => by
rw [diff_cons, (hl₁.erase _).diff_eq_filter, hl₁.erase_eq_filter, filter_filter]
simp only [decide_not, bne, Bool.and_comm, decide_mem_cons, Bool.not_or]
theorem Nodup.mem_diff_iff [DecidableEq α] (hl₁ : l₁.Nodup) : a ∈ l₁.diff l₂ ↔ a ∈ l₁ ∧ a ∉ l₂ := by
rw [hl₁.diff_eq_filter, mem_filter, decide_eq_true_iff]
protected theorem Nodup.set :
∀ {l : List α} {n : ℕ} {a : α} (_ : l.Nodup) (_ : a ∉ l), (l.set n a).Nodup
| [], _, _, _, _ => nodup_nil
| _ :: _, 0, _, hl, ha => nodup_cons.2 ⟨mt (mem_cons_of_mem _) ha, (nodup_cons.1 hl).2⟩
| _ :: _, _ + 1, _, hl, ha =>
nodup_cons.2
⟨fun h =>
(mem_or_eq_of_mem_set h).elim (nodup_cons.1 hl).1 fun hba => ha (hba ▸ mem_cons_self),
hl.of_cons.set (mt (mem_cons_of_mem _) ha)⟩
theorem Nodup.map_update [DecidableEq α] {l : List α} (hl : l.Nodup) (f : α → β) (x : α) (y : β) :
l.map (Function.update f x y) =
if x ∈ l then (l.map f).set (l.idxOf x) y else l.map f := by
induction l with | nil => simp | cons hd tl ihl => ?_
rw [nodup_cons] at hl
simp only [mem_cons, map, ihl hl.2]
by_cases H : hd = x
· subst hd
simp [hl.1]
· simp [Ne.symm H, H, ← apply_ite (cons (f hd))]
theorem Nodup.pairwise_of_forall_ne {l : List α} {r : α → α → Prop} (hl : l.Nodup)
(h : ∀ a ∈ l, ∀ b ∈ l, a ≠ b → r a b) : l.Pairwise r := by
grind [List.pairwise_iff_forall_sublist]
theorem Nodup.take_eq_filter_mem [DecidableEq α] :
∀ {l : List α} {n : ℕ} (_ : l.Nodup), l.take n = l.filter (l.take n).elem
| [], n, _ => by simp
| b::l, 0, _ => by simp
| b::l, n+1, hl => by
rw [take_succ_cons, Nodup.take_eq_filter_mem (Nodup.of_cons hl), filter_cons_of_pos (by simp)]
congr 1
refine List.filter_congr ?_
intro x hx
have : x ≠ b := fun h => (nodup_cons.1 hl).1 (h ▸ hx)
simp +contextual [List.mem_filter, this, hx]
end List
theorem Option.toList_nodup : ∀ o : Option α, o.toList.Nodup
| none => List.nodup_nil
| some x => List.nodup_singleton x
|
Order.lean
|
/-
Copyright (c) 2019 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Order.Monoid.Defs
import Mathlib.GroupTheory.MonoidLocalization.Basic
/-!
# Ordered structures on localizations of commutative monoids
-/
open Function
namespace Localization
variable {α : Type*}
section OrderedCancelCommMonoid
variable [CommMonoid α] [PartialOrder α] [IsOrderedCancelMonoid α] {s : Submonoid α}
{a₁ b₁ : α} {a₂ b₂ : s}
@[to_additive]
instance le : LE (Localization s) :=
⟨fun a b =>
Localization.liftOn₂ a b (fun a₁ a₂ b₁ b₂ => ↑b₂ * a₁ ≤ a₂ * b₁)
fun {a₁ b₁ a₂ b₂ c₁ d₁ c₂ d₂} hab hcd => propext <| by
obtain ⟨e, he⟩ := r_iff_exists.1 hab
obtain ⟨f, hf⟩ := r_iff_exists.1 hcd
simp only [mul_right_inj] at he hf
dsimp
rw [← mul_le_mul_iff_right, mul_right_comm, ← hf, mul_right_comm, mul_right_comm (a₂ : α),
mul_le_mul_iff_right, ← mul_le_mul_iff_left, mul_left_comm, he, mul_left_comm,
mul_left_comm (b₂ : α), mul_le_mul_iff_left]⟩
@[to_additive]
instance lt : LT (Localization s) :=
⟨fun a b =>
Localization.liftOn₂ a b (fun a₁ a₂ b₁ b₂ => ↑b₂ * a₁ < a₂ * b₁)
fun {a₁ b₁ a₂ b₂ c₁ d₁ c₂ d₂} hab hcd => propext <| by
obtain ⟨e, he⟩ := r_iff_exists.1 hab
obtain ⟨f, hf⟩ := r_iff_exists.1 hcd
simp only [mul_right_inj] at he hf
dsimp
rw [← mul_lt_mul_iff_right, mul_right_comm, ← hf, mul_right_comm, mul_right_comm (a₂ : α),
mul_lt_mul_iff_right, ← mul_lt_mul_iff_left, mul_left_comm, he, mul_left_comm,
mul_left_comm (b₂ : α), mul_lt_mul_iff_left]⟩
@[to_additive]
theorem mk_le_mk : mk a₁ a₂ ≤ mk b₁ b₂ ↔ ↑b₂ * a₁ ≤ a₂ * b₁ :=
Iff.rfl
@[to_additive]
theorem mk_lt_mk : mk a₁ a₂ < mk b₁ b₂ ↔ ↑b₂ * a₁ < a₂ * b₁ :=
Iff.rfl
-- declaring this separately to the instance below makes things faster
@[to_additive]
instance partialOrder : PartialOrder (Localization s) where
le := (· ≤ ·)
lt := (· < ·)
le_refl a := Localization.induction_on a fun _ => le_rfl
le_trans a b c :=
Localization.induction_on₃ a b c fun a b c hab hbc => by
simp only [mk_le_mk] at hab hbc ⊢
apply le_of_mul_le_mul_left' _
· exact ↑b.2
rw [mul_left_comm]
refine (mul_le_mul_left' hab _).trans ?_
rwa [mul_left_comm, mul_left_comm (b.2 : α), mul_le_mul_iff_left]
le_antisymm a b := by
induction a using Localization.rec
on_goal 1 =>
induction b using Localization.rec
· simp_rw [mk_le_mk, mk_eq_mk_iff, r_iff_exists]
exact fun hab hba => ⟨1, by rw [hab.antisymm hba]⟩
all_goals rfl
lt_iff_le_not_ge a b := Localization.induction_on₂ a b fun _ _ => lt_iff_le_not_ge
@[to_additive]
instance isOrderedCancelMonoid : IsOrderedCancelMonoid (Localization s) where
mul_le_mul_left := fun a b =>
Localization.induction_on₂ a b fun a b hab c =>
Localization.induction_on c fun c => by
simp only [mk_mul, mk_le_mk, Submonoid.coe_mul, mul_mul_mul_comm _ _ c.1] at hab ⊢
exact mul_le_mul_left' hab _
le_of_mul_le_mul_left := fun a b c =>
Localization.induction_on₃ a b c fun a b c hab => by
simp only [mk_mul, mk_le_mk, Submonoid.coe_mul, mul_mul_mul_comm _ _ a.1] at hab ⊢
exact le_of_mul_le_mul_left' hab
@[to_additive]
instance decidableLE [DecidableLE α] : DecidableLE (Localization s) := fun a b =>
Localization.recOnSubsingleton₂ a b fun _ _ _ _ => decidable_of_iff' _ mk_le_mk
@[to_additive]
instance decidableLT [DecidableLT α] : DecidableLT (Localization s) := fun a b =>
Localization.recOnSubsingleton₂ a b fun _ _ _ _ => decidable_of_iff' _ mk_lt_mk
/-- An ordered cancellative monoid injects into its localization by sending `a` to `a / b`. -/
@[to_additive (attr := simps!) /-- An ordered cancellative monoid injects into its localization by
sending `a` to `a - b`. -/]
def mkOrderEmbedding (b : s) : α ↪o Localization s where
toFun a := mk a b
inj' := mk_left_injective _
map_rel_iff' {a b} := by simp [mk_le_mk]
end OrderedCancelCommMonoid
@[to_additive]
instance [CommMonoid α] [LinearOrder α] [IsOrderedCancelMonoid α] {s : Submonoid α} :
LinearOrder (Localization s) :=
{ le_total := fun a b =>
Localization.induction_on₂ a b fun _ _ => by
simp_rw [mk_le_mk]
exact le_total _ _
toDecidableLE := Localization.decidableLE
toDecidableLT := Localization.decidableLT
toDecidableEq := Localization.decidableEq }
end Localization
|
KreinMilman.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.Analysis.Convex.Exposed
import Mathlib.Analysis.NormedSpace.HahnBanach.Separation
import Mathlib.Topology.Algebra.ContinuousAffineMap
/-!
# The Krein-Milman theorem
This file proves the Krein-Milman lemma and the Krein-Milman theorem.
## The lemma
The lemma states that a nonempty compact set `s` has an extreme point. The proof goes:
1. Using Zorn's lemma, find a minimal nonempty closed `t` that is an extreme subset of `s`. We will
show that `t` is a singleton, thus corresponding to an extreme point.
2. By contradiction, `t` contains two distinct points `x` and `y`.
3. With the (geometric) Hahn-Banach theorem, find a hyperplane that separates `x` and `y`.
4. Look at the extreme (actually exposed) subset of `t` obtained by going the furthest away from
the separating hyperplane in the direction of `x`. It is nonempty, closed and an extreme subset
of `s`.
5. It is a strict subset of `t` (`y` isn't in it), so `t` isn't minimal. Absurd.
## The theorem
The theorem states that a compact convex set `s` is the closure of the convex hull of its extreme
points. It is an almost immediate strengthening of the lemma. The proof goes:
1. By contradiction, `s \ closure (convexHull ℝ (extremePoints ℝ s))` is nonempty, say with `x`.
2. With the (geometric) Hahn-Banach theorem, find a hyperplane that separates `x` from
`closure (convexHull ℝ (extremePoints ℝ s))`.
3. Look at the extreme (actually exposed) subset of
`s \ closure (convexHull ℝ (extremePoints ℝ s))` obtained by going the furthest away from the
separating hyperplane. It is nonempty by assumption of nonemptiness and compactness, so by the
lemma it has an extreme point.
4. This point is also an extreme point of `s`. Absurd.
## Related theorems
When the space is finite dimensional, the `closure` can be dropped to strengthen the result of the
Krein-Milman theorem. This leads to the Minkowski-Carathéodory theorem (currently not in mathlib).
Birkhoff's theorem is the Minkowski-Carathéodory theorem applied to the set of bistochastic
matrices, permutation matrices being the extreme points.
## References
See chapter 8 of [Barry Simon, *Convexity*][simon2011]
-/
open Set
variable {E F : Type*} [AddCommGroup E] [Module ℝ E] [TopologicalSpace E] [T2Space E]
[IsTopologicalAddGroup E] [ContinuousSMul ℝ E] [LocallyConvexSpace ℝ E] {s : Set E}
[AddCommGroup F] [Module ℝ F] [TopologicalSpace F] [T1Space F]
/-- **Krein-Milman lemma**: In a LCTVS, any nonempty compact set has an extreme point. -/
theorem IsCompact.extremePoints_nonempty (hscomp : IsCompact s) (hsnemp : s.Nonempty) :
(s.extremePoints ℝ).Nonempty := by
let S : Set (Set E) := { t | t.Nonempty ∧ IsClosed t ∧ IsExtreme ℝ s t }
rsuffices ⟨t, ht⟩ : ∃ t, Minimal (· ∈ S) t
· obtain ⟨⟨x,hxt⟩, htclos, hst⟩ := ht.prop
refine ⟨x, IsExtreme.mem_extremePoints ?_⟩
rwa [← eq_singleton_iff_unique_mem.2 ⟨hxt, fun y hyB => ?_⟩]
by_contra hyx
obtain ⟨l, hl⟩ := geometric_hahn_banach_point_point hyx
obtain ⟨z, hzt, hz⟩ :=
(hscomp.of_isClosed_subset htclos hst.1).exists_isMaxOn ⟨x, hxt⟩
l.continuous.continuousOn
have h : IsExposed ℝ t ({ z ∈ t | ∀ w ∈ t, l w ≤ l z }) := fun _ => ⟨l, rfl⟩
rw [ht.eq_of_ge (y := ({ z ∈ t | ∀ w ∈ t, l w ≤ l z }))
⟨⟨z, hzt, hz⟩, h.isClosed htclos, hst.trans h.isExtreme⟩ (t.sep_subset _)] at hyB
exact hl.not_ge (hyB.2 x hxt)
refine zorn_superset _ fun F hFS hF => ?_
obtain rfl | hFnemp := F.eq_empty_or_nonempty
· exact ⟨s, ⟨hsnemp, hscomp.isClosed, IsExtreme.rfl⟩, fun _ => False.elim⟩
refine ⟨⋂₀ F, ⟨?_, isClosed_sInter fun t ht => (hFS ht).2.1,
isExtreme_sInter hFnemp fun t ht => (hFS ht).2.2⟩, fun t ht => sInter_subset_of_mem ht⟩
haveI : Nonempty (↥F) := hFnemp.to_subtype
rw [sInter_eq_iInter]
refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun t u => ?_)
(fun t => (hFS t.mem).1)
(fun t => hscomp.of_isClosed_subset (hFS t.mem).2.1 (hFS t.mem).2.2.1) fun t =>
(hFS t.mem).2.1
obtain htu | hut := hF.total t.mem u.mem
exacts [⟨t, Subset.rfl, htu⟩, ⟨u, hut, Subset.rfl⟩]
/-- **Krein-Milman theorem**: In a LCTVS, any compact convex set is the closure of the convex hull
of its extreme points. -/
theorem closure_convexHull_extremePoints (hscomp : IsCompact s) (hAconv : Convex ℝ s) :
closure (convexHull ℝ <| s.extremePoints ℝ) = s := by
apply (closure_minimal (convexHull_min extremePoints_subset hAconv) hscomp.isClosed).antisymm
by_contra hs
obtain ⟨x, hxA, hxt⟩ := not_subset.1 hs
obtain ⟨l, r, hlr, hrx⟩ :=
geometric_hahn_banach_closed_point (convex_convexHull _ _).closure isClosed_closure hxt
have h : IsExposed ℝ s ({ y ∈ s | ∀ z ∈ s, l z ≤ l y }) := fun _ => ⟨l, rfl⟩
obtain ⟨z, hzA, hz⟩ := hscomp.exists_isMaxOn ⟨x, hxA⟩ l.continuous.continuousOn
obtain ⟨y, hy⟩ := (h.isCompact hscomp).extremePoints_nonempty ⟨z, hzA, hz⟩
linarith [hlr _ (subset_closure <| subset_convexHull _ _ <|
h.isExtreme.extremePoints_subset_extremePoints hy), hy.1.2 x hxA]
/-- A continuous affine map is surjective from the extreme points of a compact set to the extreme
points of the image of that set. This inclusion is in general strict. -/
lemma surjOn_extremePoints_image (f : E →ᴬ[ℝ] F) (hs : IsCompact s) :
SurjOn f (extremePoints ℝ s) (extremePoints ℝ (f '' s)) := by
rintro w hw
-- The fiber of `w` is nonempty and compact
have ht : IsCompact {x ∈ s | f x = w} :=
hs.inter_right <| isClosed_singleton.preimage f.continuous
have ht₀ : {x ∈ s | f x = w}.Nonempty := by simpa using extremePoints_subset hw
-- Hence by the Krein-Milman lemma it has an extreme point `x`
obtain ⟨x, ⟨hx, rfl⟩, hyt⟩ := ht.extremePoints_nonempty ht₀
-- `f x = w` and `x` is an extreme point of `s`, so we're done
refine mem_image_of_mem _ ⟨hx, fun y hy z hz hxyz ↦ ?_⟩
have := by simpa using image_openSegment _ f.toAffineMap y z
have := hw.2 (mem_image_of_mem _ hy) (mem_image_of_mem _ hz) <| by
rw [← this]; exact mem_image_of_mem _ hxyz
exact hyt ⟨hy, this.1⟩ ⟨hz, this.2⟩ hxyz
|
Finset.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.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.AbsoluteValue.Basic
import Mathlib.Algebra.Order.BigOperators.Group.Finset
import Mathlib.Algebra.Order.BigOperators.Ring.Multiset
import Mathlib.Tactic.Ring
/-!
# Big operators on a finset in ordered rings
This file contains the results concerning the interaction of finset big operators with ordered
rings.
In particular, this file contains the standard form of the Cauchy-Schwarz inequality, as well as
some of its immediate consequences.
-/
variable {ι R S : Type*}
namespace Finset
section CommMonoidWithZero
variable [CommMonoidWithZero R] [PartialOrder R] [ZeroLEOneClass R]
section PosMulMono
variable [PosMulMono R] {f g : ι → R} {s t : Finset ι}
lemma prod_nonneg (h0 : ∀ i ∈ s, 0 ≤ f i) : 0 ≤ ∏ i ∈ s, f i :=
prod_induction f (fun i ↦ 0 ≤ i) (fun _ _ ha hb ↦ mul_nonneg ha hb) zero_le_one h0
/-- If all `f i`, `i ∈ s`, are nonnegative and each `f i` is less than or equal to `g i`, then the
product of `f i` is less than or equal to the product of `g i`. See also `Finset.prod_le_prod'` for
the case of an ordered commutative multiplicative monoid. -/
@[gcongr]
lemma prod_le_prod (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ g i) :
∏ i ∈ s, f i ≤ ∏ i ∈ s, g i := by
induction s using Finset.cons_induction with
| empty => simp
| cons a s has ih =>
simp only [prod_cons, forall_mem_cons] at h0 h1 ⊢
have := posMulMono_iff_mulPosMono.1 ‹PosMulMono R›
gcongr
exacts [prod_nonneg h0.2, h0.1.trans h1.1, h1.1, ih h0.2 h1.2]
/-- If each `f i`, `i ∈ s` belongs to `[0, 1]`, then their product is less than or equal to one.
See also `Finset.prod_le_one'` for the case of an ordered commutative multiplicative monoid. -/
lemma prod_le_one (h0 : ∀ i ∈ s, 0 ≤ f i) (h1 : ∀ i ∈ s, f i ≤ 1) : ∏ i ∈ s, f i ≤ 1 := by
convert ← prod_le_prod h0 h1
exact Finset.prod_const_one
end PosMulMono
section PosMulStrictMono
variable [PosMulStrictMono R] [Nontrivial R] {f g : ι → R} {s t : Finset ι}
lemma prod_pos (h0 : ∀ i ∈ s, 0 < f i) : 0 < ∏ i ∈ s, f i :=
prod_induction f (fun x ↦ 0 < x) (fun _ _ ha hb ↦ mul_pos ha hb) zero_lt_one h0
lemma prod_lt_prod (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i ≤ g i)
(hlt : ∃ i ∈ s, f i < g i) :
∏ i ∈ s, f i < ∏ i ∈ s, g i := by
classical
obtain ⟨i, hi, hilt⟩ := hlt
rw [← insert_erase hi, prod_insert (notMem_erase _ _), prod_insert (notMem_erase _ _)]
have := posMulStrictMono_iff_mulPosStrictMono.1 ‹PosMulStrictMono R›
refine mul_lt_mul_of_pos_of_nonneg' hilt ?_ ?_ ?_
· exact prod_le_prod (fun j hj => le_of_lt (hf j (mem_of_mem_erase hj)))
(fun _ hj ↦ hfg _ <| mem_of_mem_erase hj)
· exact prod_pos fun j hj => hf j (mem_of_mem_erase hj)
· exact (hf i hi).le.trans hilt.le
lemma prod_lt_prod_of_nonempty (hf : ∀ i ∈ s, 0 < f i) (hfg : ∀ i ∈ s, f i < g i)
(h_ne : s.Nonempty) :
∏ i ∈ s, f i < ∏ i ∈ s, g i := by
apply prod_lt_prod hf fun i hi => le_of_lt (hfg i hi)
obtain ⟨i, hi⟩ := h_ne
exact ⟨i, hi, hfg i hi⟩
end PosMulStrictMono
end CommMonoidWithZero
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {f : ι → R} {s : Finset ι}
lemma sum_sq_le_sq_sum_of_nonneg (hf : ∀ i ∈ s, 0 ≤ f i) :
∑ i ∈ s, f i ^ 2 ≤ (∑ i ∈ s, f i) ^ 2 := by
simp only [sq, sum_mul_sum]
refine sum_le_sum fun i hi ↦ ?_
rw [← mul_sum]
gcongr
· exact hf i hi
· exact single_le_sum hf hi
end OrderedSemiring
section OrderedCommSemiring
variable [CommSemiring R] [PartialOrder R] [IsOrderedRing R] {f g : ι → R} {s t : Finset ι}
/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the
sum of the products of `g` and `h`. This is the version for `OrderedCommSemiring`. -/
lemma prod_add_prod_le {i : ι} {f g h : ι → R} (hi : i ∈ s) (h2i : g i + h i ≤ f i)
(hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j) (hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) (hg : ∀ i ∈ s, 0 ≤ g i)
(hh : ∀ i ∈ s, 0 ≤ h i) : ((∏ i ∈ s, g i) + ∏ i ∈ s, h i) ≤ ∏ i ∈ s, f i := by
classical
simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine le_trans ?_ (mul_le_mul_of_nonneg_right h2i ?_)
· rw [right_distrib]
gcongr with j hj <;> aesop
· apply prod_nonneg
simp only [and_imp, mem_sdiff, mem_singleton]
exact fun j hj hji ↦ le_trans (hg j hj) (hgf j hj hji)
theorem le_prod_of_submultiplicative_on_pred_of_nonneg {M : Type*} [CommMonoid M] (f : M → R)
(p : M → Prop) (h_nonneg : ∀ a, 0 ≤ f a) (h_one : f 1 ≤ 1)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b) (hp_mul : ∀ a b, p a → p b → p (a * b))
(s : Finset ι) (g : ι → M) (hps : ∀ a, a ∈ s → p (g a)) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) := by
apply le_trans (Multiset.le_prod_of_submultiplicative_on_pred_of_nonneg f p h_nonneg h_one
h_mul hp_mul _ ?_) (by simp [Multiset.map_map])
intro _ ha
obtain ⟨i, hi, rfl⟩ := Multiset.mem_map.mp ha
exact hps i hi
theorem le_prod_of_submultiplicative_of_nonneg {M : Type*} [CommMonoid M]
(f : M → R) (h_nonneg : ∀ a, 0 ≤ f a) (h_one : f 1 ≤ 1)
(h_mul : ∀ x y : M, f (x * y) ≤ f x * f y) (s : Finset ι) (g : ι → M) :
f (∏ i ∈ s, g i) ≤ ∏ i ∈ s, f (g i) :=
le_trans (Multiset.le_prod_of_submultiplicative_of_nonneg f h_nonneg h_one h_mul _)
(by simp [Multiset.map_map])
end OrderedCommSemiring
theorem sum_mul_self_eq_zero_iff [Semiring R] [LinearOrder R] [IsStrictOrderedRing R]
[ExistsAddOfLE R] (s : Finset ι)
(f : ι → R) : ∑ i ∈ s, f i * f i = 0 ↔ ∀ i ∈ s, f i = 0 := by
rw [sum_eq_zero_iff_of_nonneg fun _ _ ↦ mul_self_nonneg _]
simp
lemma abs_prod [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] (s : Finset ι) (f : ι → R) :
|∏ x ∈ s, f x| = ∏ x ∈ s, |f x| :=
map_prod absHom _ _
@[simp, norm_cast]
theorem PNat.coe_prod {ι : Type*} (f : ι → ℕ+) (s : Finset ι) :
↑(∏ i ∈ s, f i) = (∏ i ∈ s, f i : ℕ) :=
map_prod PNat.coeMonoidHom _ _
section CanonicallyOrderedAdd
variable [CommSemiring R] [PartialOrder R] [CanonicallyOrderedAdd R]
{f g h : ι → R} {s : Finset ι} {i : ι}
/-- Note that the name is to match `CanonicallyOrderedAdd.mul_pos`. -/
@[simp] lemma _root_.CanonicallyOrderedAdd.prod_pos [NoZeroDivisors R] [Nontrivial R] :
0 < ∏ i ∈ s, f i ↔ (∀ i ∈ s, (0 : R) < f i) :=
CanonicallyOrderedAdd.multiset_prod_pos.trans Multiset.forall_mem_map_iff
/-- If `g, h ≤ f` and `g i + h i ≤ f i`, then the product of `f` over `s` is at least the
sum of the products of `g` and `h`. This is the version for `CanonicallyOrderedAdd`.
-/
lemma prod_add_prod_le' (hi : i ∈ s) (h2i : g i + h i ≤ f i) (hgf : ∀ j ∈ s, j ≠ i → g j ≤ f j)
(hhf : ∀ j ∈ s, j ≠ i → h j ≤ f j) : ((∏ i ∈ s, g i) + ∏ i ∈ s, h i) ≤ ∏ i ∈ s, f i := by
classical
simp_rw [prod_eq_mul_prod_diff_singleton hi]
refine le_trans ?_ (mul_le_mul_right' h2i _)
rw [right_distrib]
gcongr with j hj j hj <;> simp_all
end CanonicallyOrderedAdd
/-! ### Named inequalities -/
/-- **Cauchy-Schwarz inequality** for finsets.
This is written in terms of sequences `f`, `g`, and `r`, where `r` is a stand-in for
`√(f i * g i)`. See `sum_mul_sq_le_sq_mul_sq` for the more usual form in terms of squared
sequences. -/
lemma sum_sq_le_sum_mul_sum_of_sq_eq_mul [CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]
[ExistsAddOfLE R]
(s : Finset ι) {r f g : ι → R} (hf : ∀ i ∈ s, 0 ≤ f i) (hg : ∀ i ∈ s, 0 ≤ g i)
(ht : ∀ i ∈ s, r i ^ 2 = f i * g i) : (∑ i ∈ s, r i) ^ 2 ≤ (∑ i ∈ s, f i) * ∑ i ∈ s, g i := by
obtain h | h := (sum_nonneg hg).eq_or_lt'
· have ht' : ∑ i ∈ s, r i = 0 := sum_eq_zero fun i hi ↦ by
simpa [(sum_eq_zero_iff_of_nonneg hg).1 h i hi] using ht i hi
rw [h, ht']
simp
· refine le_of_mul_le_mul_of_pos_left
(le_of_add_le_add_left (a := (∑ i ∈ s, g i) * (∑ i ∈ s, r i) ^ 2) ?_) h
calc
_ = ∑ i ∈ s, 2 * r i * (∑ j ∈ s, g j) * (∑ j ∈ s, r j) := by
simp_rw [mul_assoc, ← mul_sum, ← sum_mul]; ring
_ ≤ ∑ i ∈ s, (f i * (∑ j ∈ s, g j) ^ 2 + g i * (∑ j ∈ s, r j) ^ 2) := by
gcongr with i hi
have ht : (r i * (∑ j ∈ s, g j) * (∑ j ∈ s, r j)) ^ 2 =
(f i * (∑ j ∈ s, g j) ^ 2) * (g i * (∑ j ∈ s, r j) ^ 2) := by grind
refine le_of_eq_of_le ?_ (two_mul_le_add_of_sq_eq_mul
(mul_nonneg (hf i hi) (sq_nonneg _)) (mul_nonneg (hg i hi) (sq_nonneg _)) ht)
repeat rw [mul_assoc]
_ = _ := by simp_rw [sum_add_distrib, ← sum_mul]; ring
/-- **Cauchy-Schwarz inequality** for finsets, squared version. -/
lemma sum_mul_sq_le_sq_mul_sq [CommSemiring R] [LinearOrder R] [IsStrictOrderedRing R]
[ExistsAddOfLE R] (s : Finset ι)
(f g : ι → R) : (∑ i ∈ s, f i * g i) ^ 2 ≤ (∑ i ∈ s, f i ^ 2) * ∑ i ∈ s, g i ^ 2 :=
sum_sq_le_sum_mul_sum_of_sq_eq_mul s
(fun _ _ ↦ sq_nonneg _) (fun _ _ ↦ sq_nonneg _) (fun _ _ ↦ mul_pow ..)
/-- **Sedrakyan's lemma**, aka **Titu's lemma** or **Engel's form**.
This is a specialization of the Cauchy-Schwarz inequality with the sequences `f n / √(g n)` and
`√(g n)`, though here it is proven without relying on square roots. -/
theorem sq_sum_div_le_sum_sq_div [Semifield R] [LinearOrder R] [IsStrictOrderedRing R]
[ExistsAddOfLE R] (s : Finset ι)
(f : ι → R) {g : ι → R} (hg : ∀ i ∈ s, 0 < g i) :
(∑ i ∈ s, f i) ^ 2 / ∑ i ∈ s, g i ≤ ∑ i ∈ s, f i ^ 2 / g i := by
have hg' : ∀ i ∈ s, 0 ≤ g i := fun i hi ↦ (hg i hi).le
have H : ∀ i ∈ s, 0 ≤ f i ^ 2 / g i := fun i hi ↦ div_nonneg (sq_nonneg _) (hg' i hi)
refine div_le_of_le_mul₀ (sum_nonneg hg') (sum_nonneg H)
(sum_sq_le_sum_mul_sum_of_sq_eq_mul _ H hg' fun i hi ↦ ?_)
rw [div_mul_cancel₀]
exact (hg i hi).ne'
end Finset
/-! ### Absolute values -/
section AbsoluteValue
lemma AbsoluteValue.sum_le [Semiring R] [Semiring S] [PartialOrder S] [IsOrderedRing S]
(abv : AbsoluteValue R S)
(s : Finset ι) (f : ι → R) : abv (∑ i ∈ s, f i) ≤ ∑ i ∈ s, abv (f i) :=
Finset.le_sum_of_subadditive abv (map_zero _) abv.add_le _ _
lemma IsAbsoluteValue.abv_sum [Semiring R] [Semiring S] [PartialOrder S] [IsOrderedRing S]
(abv : R → S) [IsAbsoluteValue abv]
(f : ι → R) (s : Finset ι) : abv (∑ i ∈ s, f i) ≤ ∑ i ∈ s, abv (f i) :=
(IsAbsoluteValue.toAbsoluteValue abv).sum_le _ _
nonrec lemma AbsoluteValue.map_prod [CommSemiring R] [Nontrivial R]
[CommRing S] [LinearOrder S] [IsStrictOrderedRing S]
(abv : AbsoluteValue R S) (f : ι → R) (s : Finset ι) :
abv (∏ i ∈ s, f i) = ∏ i ∈ s, abv (f i) :=
map_prod abv f s
lemma IsAbsoluteValue.map_prod [CommSemiring R] [Nontrivial R]
[CommRing S] [LinearOrder S] [IsStrictOrderedRing S]
(abv : R → S) [IsAbsoluteValue abv] (f : ι → R) (s : Finset ι) :
abv (∏ i ∈ s, f i) = ∏ i ∈ s, abv (f i) :=
(IsAbsoluteValue.toAbsoluteValue abv).map_prod _ _
end AbsoluteValue
/-! ### Positivity extension -/
namespace Mathlib.Meta.Positivity
open Qq Lean Meta Finset
private alias ⟨_, prod_ne_zero⟩ := prod_ne_zero_iff
attribute [local instance] monadLiftOptionMetaM in
/-- The `positivity` extension which proves that `∏ i ∈ s, f i` is nonnegative if `f` is, and
positive if each `f i` is.
TODO: The following example does not work
```
example (s : Finset ℕ) (f : ℕ → ℤ) (hf : ∀ n, 0 ≤ f n) : 0 ≤ s.prod f := by positivity
```
because `compareHyp` can't look for assumptions behind binders.
-/
@[positivity Finset.prod _ _]
def evalFinsetProd : PositivityExt where eval {u α} zα pα e := do
match e with
| ~q(@Finset.prod $ι _ $instα $s $f) =>
let i : Q($ι) ← mkFreshExprMVarQ q($ι) .syntheticOpaque
have body : Q($α) := Expr.betaRev f #[i]
let rbody ← core zα pα body
let _instαmon ← synthInstanceQ q(CommMonoidWithZero $α)
-- Try to show that the product is positive
let p_pos : Option Q(0 < $e) := ← do
let .positive pbody := rbody | pure none -- Fail if the body is not provably positive
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let .some _instαzeroone ← trySynthInstanceQ q(ZeroLEOneClass $α) | pure none
let .some _instαposmul ← trySynthInstanceQ q(PosMulStrictMono $α) | pure none
let .some _instαnontriv ← trySynthInstanceQ q(Nontrivial $α) | pure none
assertInstancesCommute
let pr : Q(∀ i, 0 < $f i) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
return some q(prod_pos fun i _ ↦ $pr i)
if let some p_pos := p_pos then return .positive p_pos
-- Try to show that the product is nonnegative
let p_nonneg : Option Q(0 ≤ $e) := ← do
let .some pbody := rbody.toNonneg
| return none -- Fail if the body is not provably nonnegative
let pr : Q(∀ i, 0 ≤ $f i) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let .some _instαzeroone ← trySynthInstanceQ q(ZeroLEOneClass $α) | pure none
let .some _instαposmul ← trySynthInstanceQ q(PosMulMono $α) | pure none
assertInstancesCommute
return some q(prod_nonneg fun i _ ↦ $pr i)
if let some p_nonneg := p_nonneg then return .nonnegative p_nonneg
-- Fall back to showing that the product is nonzero
let pbody ← rbody.toNonzero
let pr : Q(∀ i, $f i ≠ 0) ← mkLambdaFVars #[i] pbody (binderInfoForMVars := .default)
-- TODO(quote4#38): We must name the following, else `assertInstancesCommute` loops.
let _instαnontriv ← synthInstanceQ q(Nontrivial $α)
let _instαnozerodiv ← synthInstanceQ q(NoZeroDivisors $α)
assertInstancesCommute
return .nonzero q(prod_ne_zero fun i _ ↦ $pr i)
end Mathlib.Meta.Positivity
|
Bases.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Data.Set.Constructions
import Mathlib.Order.Filter.AtTopBot.CountablyGenerated
import Mathlib.Topology.Constructions
import Mathlib.Topology.ContinuousOn
/-!
# Bases of topologies. Countability axioms.
A topological basis on a topological space `t` is a collection of sets,
such that all open sets can be generated as unions of these sets, without the need to take
finite intersections of them. This file introduces a framework for dealing with these collections,
and also what more we can say under certain countability conditions on bases,
which are referred to as first- and second-countable.
We also briefly cover the theory of separable spaces, which are those with a countable, dense
subset. If a space is second-countable, and also has a countably generated uniformity filter
(for example, if `t` is a metric space), it will automatically be separable (and indeed, these
conditions are equivalent in this case).
## Main definitions
* `TopologicalSpace.IsTopologicalBasis s`: The topological space `t` has basis `s`.
* `TopologicalSpace.SeparableSpace α`: The topological space `t` has a countable, dense subset.
* `TopologicalSpace.IsSeparable s`: The set `s` is contained in the closure of a countable set.
* `FirstCountableTopology α`: A topology in which `𝓝 x` is countably generated for
every `x`.
* `SecondCountableTopology α`: A topology which has a topological basis which is
countable.
## Main results
* `TopologicalSpace.FirstCountableTopology.tendsto_subseq`: In a first-countable space,
cluster points are limits of subsequences.
* `TopologicalSpace.SecondCountableTopology.isOpen_iUnion_countable`: In a second-countable space,
the union of arbitrarily-many open sets is equal to a sub-union of only countably many of these
sets.
* `TopologicalSpace.SecondCountableTopology.countable_cover_nhds`: Consider `f : α → Set α` with the
property that `f x ∈ 𝓝 x` for all `x`. Then there is some countable set `s` whose image covers
the space.
## Implementation Notes
For our applications we are interested that there exists a countable basis, but we do not need the
concrete basis itself. This allows us to declare these type classes as `Prop` to use them as mixins.
## TODO
More fine grained instances for `FirstCountableTopology`,
`TopologicalSpace.SeparableSpace`, and more.
-/
open Set Filter Function Topology
noncomputable section
namespace TopologicalSpace
universe u
variable {α : Type u} {β : Type*} [t : TopologicalSpace α] {B : Set (Set α)} {s : Set α}
/-- A topological basis is one that satisfies the necessary conditions so that
it suffices to take unions of the basis sets to get a topology (without taking
finite intersections as well). -/
structure IsTopologicalBasis (s : Set (Set α)) : Prop where
/-- For every point `x`, the set of `t ∈ s` such that `x ∈ t` is directed downwards. -/
exists_subset_inter : ∀ t₁ ∈ s, ∀ t₂ ∈ s, ∀ x ∈ t₁ ∩ t₂, ∃ t₃ ∈ s, x ∈ t₃ ∧ t₃ ⊆ t₁ ∩ t₂
/-- The sets from `s` cover the whole space. -/
sUnion_eq : ⋃₀ s = univ
/-- The topology is generated by sets from `s`. -/
eq_generateFrom : t = generateFrom s
/-- If a family of sets `s` generates the topology, then intersections of finite
subcollections of `s` form a topological basis. -/
theorem isTopologicalBasis_of_subbasis {s : Set (Set α)} (hs : t = generateFrom s) :
IsTopologicalBasis ((fun f => ⋂₀ f) '' { f : Set (Set α) | f.Finite ∧ f ⊆ s }) := by
subst t; letI := generateFrom s
refine ⟨?_, ?_, le_antisymm (le_generateFrom ?_) <| generateFrom_anti fun t ht => ?_⟩
· rintro _ ⟨t₁, ⟨hft₁, ht₁b⟩, rfl⟩ _ ⟨t₂, ⟨hft₂, ht₂b⟩, rfl⟩ x h
exact ⟨_, ⟨_, ⟨hft₁.union hft₂, union_subset ht₁b ht₂b⟩, sInter_union t₁ t₂⟩, h, Subset.rfl⟩
· rw [sUnion_image, iUnion₂_eq_univ_iff]
exact fun x => ⟨∅, ⟨finite_empty, empty_subset _⟩, sInter_empty.substr <| mem_univ x⟩
· rintro _ ⟨t, ⟨hft, htb⟩, rfl⟩
exact hft.isOpen_sInter fun s hs ↦ GenerateOpen.basic _ <| htb hs
· rw [← sInter_singleton t]
exact ⟨{t}, ⟨finite_singleton t, singleton_subset_iff.2 ht⟩, rfl⟩
theorem isTopologicalBasis_of_subbasis_of_finiteInter {s : Set (Set α)} (hsg : t = generateFrom s)
(hsi : FiniteInter s) : IsTopologicalBasis s := by
convert isTopologicalBasis_of_subbasis hsg
refine le_antisymm (fun t ht ↦ ⟨{t}, by simpa using ht⟩) ?_
rintro _ ⟨g, ⟨hg, hgs⟩, rfl⟩
lift g to Finset (Set α) using hg
exact hsi.finiteInter_mem g hgs
theorem isTopologicalBasis_of_subbasis_of_inter {r : Set (Set α)} (hsg : t = generateFrom r)
(hsi : ∀ ⦃s⦄, s ∈ r → ∀ ⦃t⦄, t ∈ r → s ∩ t ∈ r) : IsTopologicalBasis (insert univ r) :=
isTopologicalBasis_of_subbasis_of_finiteInter (by simpa using hsg) (FiniteInter.mk₂ hsi)
theorem IsTopologicalBasis.of_hasBasis_nhds {s : Set (Set α)}
(h_nhds : ∀ a, (𝓝 a).HasBasis (fun t ↦ t ∈ s ∧ a ∈ t) id) : IsTopologicalBasis s where
exists_subset_inter t₁ ht₁ t₂ ht₂ x hx := by
simpa only [and_assoc, (h_nhds x).mem_iff]
using (inter_mem ((h_nhds _).mem_of_mem ⟨ht₁, hx.1⟩) ((h_nhds _).mem_of_mem ⟨ht₂, hx.2⟩))
sUnion_eq := sUnion_eq_univ_iff.2 fun x ↦ (h_nhds x).ex_mem
eq_generateFrom := ext_nhds fun x ↦ by
simpa only [nhds_generateFrom, and_comm] using (h_nhds x).eq_biInf
/-- If a family of open sets `s` is such that every open neighbourhood contains some
member of `s`, then `s` is a topological basis. -/
theorem isTopologicalBasis_of_isOpen_of_nhds {s : Set (Set α)} (h_open : ∀ u ∈ s, IsOpen u)
(h_nhds : ∀ (a : α) (u : Set α), a ∈ u → IsOpen u → ∃ v ∈ s, a ∈ v ∧ v ⊆ u) :
IsTopologicalBasis s :=
.of_hasBasis_nhds <| fun a ↦
(nhds_basis_opens a).to_hasBasis' (by simpa [and_assoc] using h_nhds a)
fun _ ⟨hts, hat⟩ ↦ (h_open _ hts).mem_nhds hat
/-- A set `s` is in the neighbourhood of `a` iff there is some basis set `t`, which
contains `a` and is itself contained in `s`. -/
theorem IsTopologicalBasis.mem_nhds_iff {a : α} {s : Set α} {b : Set (Set α)}
(hb : IsTopologicalBasis b) : s ∈ 𝓝 a ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by
change s ∈ (𝓝 a).sets ↔ ∃ t ∈ b, a ∈ t ∧ t ⊆ s
rw [hb.eq_generateFrom, nhds_generateFrom, biInf_sets_eq]
· simp [and_assoc, and_left_comm]
· rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩
let ⟨u, hu₁, hu₂, hu₃⟩ := hb.1 _ hs₂ _ ht₂ _ ⟨hs₁, ht₁⟩
exact ⟨u, ⟨hu₂, hu₁⟩, le_principal_iff.2 (hu₃.trans inter_subset_left),
le_principal_iff.2 (hu₃.trans inter_subset_right)⟩
· rcases eq_univ_iff_forall.1 hb.sUnion_eq a with ⟨i, h1, h2⟩
exact ⟨i, h2, h1⟩
theorem IsTopologicalBasis.isOpen_iff {s : Set α} {b : Set (Set α)} (hb : IsTopologicalBasis b) :
IsOpen s ↔ ∀ a ∈ s, ∃ t ∈ b, a ∈ t ∧ t ⊆ s := by simp [isOpen_iff_mem_nhds, hb.mem_nhds_iff]
theorem IsTopologicalBasis.of_isOpen_of_subset {s s' : Set (Set α)} (h_open : ∀ u ∈ s', IsOpen u)
(hs : IsTopologicalBasis s) (hss' : s ⊆ s') : IsTopologicalBasis s' :=
isTopologicalBasis_of_isOpen_of_nhds h_open fun a _ ha u_open ↦
have ⟨t, hts, ht⟩ := hs.isOpen_iff.mp u_open a ha; ⟨t, hss' hts, ht⟩
theorem IsTopologicalBasis.nhds_hasBasis {b : Set (Set α)} (hb : IsTopologicalBasis b) {a : α} :
(𝓝 a).HasBasis (fun t : Set α => t ∈ b ∧ a ∈ t) fun t => t :=
⟨fun s => hb.mem_nhds_iff.trans <| by simp only [and_assoc]⟩
protected theorem IsTopologicalBasis.isOpen {s : Set α} {b : Set (Set α)}
(hb : IsTopologicalBasis b) (hs : s ∈ b) : IsOpen s := by
rw [hb.eq_generateFrom]
exact .basic s hs
theorem IsTopologicalBasis.insert_empty {s : Set (Set α)} (h : IsTopologicalBasis s) :
IsTopologicalBasis (insert ∅ s) :=
h.of_isOpen_of_subset (by rintro _ (rfl | hu); exacts [isOpen_empty, h.isOpen hu])
(subset_insert ..)
theorem IsTopologicalBasis.diff_empty {s : Set (Set α)} (h : IsTopologicalBasis s) :
IsTopologicalBasis (s \ {∅}) :=
isTopologicalBasis_of_isOpen_of_nhds (fun _ hu ↦ h.isOpen hu.1) fun a _ ha hu ↦
have ⟨t, hts, ht⟩ := h.isOpen_iff.mp hu a ha
⟨t, ⟨hts, ne_of_mem_of_not_mem' ht.1 <| notMem_empty _⟩, ht⟩
protected theorem IsTopologicalBasis.mem_nhds {a : α} {s : Set α} {b : Set (Set α)}
(hb : IsTopologicalBasis b) (hs : s ∈ b) (ha : a ∈ s) : s ∈ 𝓝 a :=
(hb.isOpen hs).mem_nhds ha
theorem IsTopologicalBasis.exists_subset_of_mem_open {b : Set (Set α)} (hb : IsTopologicalBasis b)
{a : α} {u : Set α} (au : a ∈ u) (ou : IsOpen u) : ∃ v ∈ b, a ∈ v ∧ v ⊆ u :=
hb.mem_nhds_iff.1 <| IsOpen.mem_nhds ou au
/-- Any open set is the union of the basis sets contained in it. -/
theorem IsTopologicalBasis.open_eq_sUnion' {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α}
(ou : IsOpen u) : u = ⋃₀ { s ∈ B | s ⊆ u } :=
ext fun _a =>
⟨fun ha =>
let ⟨b, hb, ab, bu⟩ := hB.exists_subset_of_mem_open ha ou
⟨b, ⟨hb, bu⟩, ab⟩,
fun ⟨_b, ⟨_, bu⟩, ab⟩ => bu ab⟩
theorem IsTopologicalBasis.open_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α}
(ou : IsOpen u) : ∃ S ⊆ B, u = ⋃₀ S :=
⟨{ s ∈ B | s ⊆ u }, fun _ h => h.1, hB.open_eq_sUnion' ou⟩
theorem IsTopologicalBasis.open_iff_eq_sUnion {B : Set (Set α)} (hB : IsTopologicalBasis B)
{u : Set α} : IsOpen u ↔ ∃ S ⊆ B, u = ⋃₀ S :=
⟨hB.open_eq_sUnion, fun ⟨_S, hSB, hu⟩ => hu.symm ▸ isOpen_sUnion fun _s hs => hB.isOpen (hSB hs)⟩
theorem IsTopologicalBasis.open_eq_iUnion {B : Set (Set α)} (hB : IsTopologicalBasis B) {u : Set α}
(ou : IsOpen u) : ∃ (β : Type u) (f : β → Set α), (u = ⋃ i, f i) ∧ ∀ i, f i ∈ B :=
⟨↥({ s ∈ B | s ⊆ u }), (↑), by
rw [← sUnion_eq_iUnion]
apply hB.open_eq_sUnion' ou, fun s => And.left s.2⟩
@[elab_as_elim]
lemma IsTopologicalBasis.isOpen_induction {P : Set α → Prop} (hB : IsTopologicalBasis B)
(basis : ∀ b ∈ B, P b) (sUnion : ∀ S, (∀ s ∈ S, P s) → P (⋃₀ S)) {s : Set α} (hs : IsOpen s) :
P s := by
obtain ⟨S, hS, rfl⟩ := hB.open_eq_sUnion hs; exact sUnion _ fun b hb ↦ basis _ <| hS hb
lemma IsTopologicalBasis.subset_of_forall_subset {t : Set α} (hB : IsTopologicalBasis B)
(hs : IsOpen s) (h : ∀ U ∈ B, U ⊆ s → U ⊆ t) : s ⊆ t := by
rw [hB.open_eq_sUnion' hs]; simpa [sUnion_subset_iff]
lemma IsTopologicalBasis.eq_of_forall_subset_iff {t : Set α} (hB : IsTopologicalBasis B)
(hs : IsOpen s) (ht : IsOpen t) (h : ∀ U ∈ B, U ⊆ s ↔ U ⊆ t) : s = t := by
rw [hB.open_eq_sUnion' hs, hB.open_eq_sUnion' ht]
exact congr_arg _ (Set.ext fun U ↦ and_congr_right <| h _)
/-- A point `a` is in the closure of `s` iff all basis sets containing `a` intersect `s`. -/
theorem IsTopologicalBasis.mem_closure_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α}
{a : α} : a ∈ closure s ↔ ∀ o ∈ b, a ∈ o → (o ∩ s).Nonempty :=
(mem_closure_iff_nhds_basis' hb.nhds_hasBasis).trans <| by simp only [and_imp]
/-- A set is dense iff it has non-trivial intersection with all basis sets. -/
theorem IsTopologicalBasis.dense_iff {b : Set (Set α)} (hb : IsTopologicalBasis b) {s : Set α} :
Dense s ↔ ∀ o ∈ b, Set.Nonempty o → (o ∩ s).Nonempty := by
simp only [Dense, hb.mem_closure_iff]
exact ⟨fun h o hb ⟨a, ha⟩ => h a o hb ha, fun h a o hb ha => h o hb ⟨a, ha⟩⟩
theorem IsTopologicalBasis.isOpenMap_iff {β} [TopologicalSpace β] {B : Set (Set α)}
(hB : IsTopologicalBasis B) {f : α → β} : IsOpenMap f ↔ ∀ s ∈ B, IsOpen (f '' s) := by
refine ⟨fun H o ho => H _ (hB.isOpen ho), fun hf o ho => ?_⟩
rw [hB.open_eq_sUnion' ho, sUnion_eq_iUnion, image_iUnion]
exact isOpen_iUnion fun s => hf s s.2.1
theorem IsTopologicalBasis.exists_nonempty_subset {B : Set (Set α)} (hb : IsTopologicalBasis B)
{u : Set α} (hu : u.Nonempty) (ou : IsOpen u) : ∃ v ∈ B, Set.Nonempty v ∧ v ⊆ u :=
let ⟨x, hx⟩ := hu
let ⟨v, vB, xv, vu⟩ := hb.exists_subset_of_mem_open hx ou
⟨v, vB, ⟨x, xv⟩, vu⟩
theorem isTopologicalBasis_opens : IsTopologicalBasis { U : Set α | IsOpen U } :=
isTopologicalBasis_of_isOpen_of_nhds (by tauto) (by tauto)
protected lemma IsTopologicalBasis.isInducing {β} [TopologicalSpace β] {f : α → β} {T : Set (Set β)}
(hf : IsInducing f) (h : IsTopologicalBasis T) : IsTopologicalBasis ((preimage f) '' T) :=
.of_hasBasis_nhds fun a ↦ by
convert (hf.basis_nhds (h.nhds_hasBasis (a := f a))).to_image_id with s
aesop
protected theorem IsTopologicalBasis.induced {α} [s : TopologicalSpace β] (f : α → β)
{T : Set (Set β)} (h : IsTopologicalBasis T) :
IsTopologicalBasis (t := induced f s) ((preimage f) '' T) :=
h.isInducing (t := induced f s) (.induced f)
protected theorem IsTopologicalBasis.inf {t₁ t₂ : TopologicalSpace β} {B₁ B₂ : Set (Set β)}
(h₁ : IsTopologicalBasis (t := t₁) B₁) (h₂ : IsTopologicalBasis (t := t₂) B₂) :
IsTopologicalBasis (t := t₁ ⊓ t₂) (image2 (· ∩ ·) B₁ B₂) := by
refine .of_hasBasis_nhds (t := ?_) fun a ↦ ?_
rw [nhds_inf (t₁ := t₁)]
convert ((h₁.nhds_hasBasis (t := t₁)).inf (h₂.nhds_hasBasis (t := t₂))).to_image_id
aesop
theorem IsTopologicalBasis.inf_induced {γ} [s : TopologicalSpace β] {B₁ : Set (Set α)}
{B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) (f₁ : γ → α)
(f₂ : γ → β) :
IsTopologicalBasis (t := induced f₁ t ⊓ induced f₂ s) (image2 (f₁ ⁻¹' · ∩ f₂ ⁻¹' ·) B₁ B₂) := by
simpa only [image2_image_left, image2_image_right] using (h₁.induced f₁).inf (h₂.induced f₂)
protected theorem IsTopologicalBasis.prod {β} [TopologicalSpace β] {B₁ : Set (Set α)}
{B₂ : Set (Set β)} (h₁ : IsTopologicalBasis B₁) (h₂ : IsTopologicalBasis B₂) :
IsTopologicalBasis (image2 (· ×ˢ ·) B₁ B₂) :=
h₁.inf_induced h₂ Prod.fst Prod.snd
theorem isTopologicalBasis_of_cover {ι} {U : ι → Set α} (Uo : ∀ i, IsOpen (U i))
(Uc : ⋃ i, U i = univ) {b : ∀ i, Set (Set (U i))} (hb : ∀ i, IsTopologicalBasis (b i)) :
IsTopologicalBasis (⋃ i : ι, image ((↑) : U i → α) '' b i) := by
refine isTopologicalBasis_of_isOpen_of_nhds (fun u hu => ?_) ?_
· simp only [mem_iUnion, mem_image] at hu
rcases hu with ⟨i, s, sb, rfl⟩
exact (Uo i).isOpenMap_subtype_val _ ((hb i).isOpen sb)
· intro a u ha uo
rcases iUnion_eq_univ_iff.1 Uc a with ⟨i, hi⟩
lift a to ↥(U i) using hi
rcases (hb i).exists_subset_of_mem_open ha (uo.preimage continuous_subtype_val) with
⟨v, hvb, hav, hvu⟩
exact ⟨(↑) '' v, mem_iUnion.2 ⟨i, mem_image_of_mem _ hvb⟩, mem_image_of_mem _ hav,
image_subset_iff.2 hvu⟩
protected theorem IsTopologicalBasis.continuous_iff {β : Type*} [TopologicalSpace β]
{B : Set (Set β)} (hB : IsTopologicalBasis B) {f : α → β} :
Continuous f ↔ ∀ s ∈ B, IsOpen (f ⁻¹' s) := by
rw [hB.eq_generateFrom, continuous_generateFrom_iff]
@[simp] lemma isTopologicalBasis_empty : IsTopologicalBasis (∅ : Set (Set α)) ↔ IsEmpty α where
mp h := by simpa using h.sUnion_eq.symm
mpr h := ⟨by simp, by simp [Set.univ_eq_empty_iff.2], Subsingleton.elim ..⟩
variable (α)
/-- A separable space is one with a countable dense subset, available through
`TopologicalSpace.exists_countable_dense`. If `α` is also known to be nonempty, then
`TopologicalSpace.denseSeq` provides a sequence `ℕ → α` with dense range, see
`TopologicalSpace.denseRange_denseSeq`.
If `α` is a uniform space with countably generated uniformity filter (e.g., an `EMetricSpace`), then
this condition is equivalent to `SecondCountableTopology α`. In this case the
latter should be used as a typeclass argument in theorems because Lean can automatically deduce
`TopologicalSpace.SeparableSpace` from `SecondCountableTopology` but it can't
deduce `SecondCountableTopology` from `TopologicalSpace.SeparableSpace`.
Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: the previous paragraph describes the state of the art in Lean 3.
We can have instance cycles in Lean 4 but we might want to
postpone adding them till after the port. -/
@[mk_iff] class SeparableSpace : Prop where
/-- There exists a countable dense set. -/
exists_countable_dense : ∃ s : Set α, s.Countable ∧ Dense s
theorem exists_countable_dense [SeparableSpace α] : ∃ s : Set α, s.Countable ∧ Dense s :=
SeparableSpace.exists_countable_dense
/-- A nonempty separable space admits a sequence with dense range. Instead of running `cases` on the
conclusion of this lemma, you might want to use `TopologicalSpace.denseSeq` and
`TopologicalSpace.denseRange_denseSeq`.
If `α` might be empty, then `TopologicalSpace.exists_countable_dense` is the main way to use
separability of `α`. -/
theorem exists_dense_seq [SeparableSpace α] [Nonempty α] : ∃ u : ℕ → α, DenseRange u := by
obtain ⟨s : Set α, hs, s_dense⟩ := exists_countable_dense α
obtain ⟨u, hu⟩ := Set.countable_iff_exists_subset_range.mp hs
exact ⟨u, s_dense.mono hu⟩
/-- A dense sequence in a non-empty separable topological space.
If `α` might be empty, then `TopologicalSpace.exists_countable_dense` is the main way to use
separability of `α`. -/
def denseSeq [SeparableSpace α] [Nonempty α] : ℕ → α :=
Classical.choose (exists_dense_seq α)
/-- The sequence `TopologicalSpace.denseSeq α` has dense range. -/
@[simp]
theorem denseRange_denseSeq [SeparableSpace α] [Nonempty α] : DenseRange (denseSeq α) :=
Classical.choose_spec (exists_dense_seq α)
variable {α}
instance (priority := 100) Countable.to_separableSpace [Countable α] : SeparableSpace α where
exists_countable_dense := ⟨Set.univ, Set.countable_univ, dense_univ⟩
/-- If `f` has a dense range and its domain is countable, then its codomain is a separable space.
See also `DenseRange.separableSpace`. -/
theorem SeparableSpace.of_denseRange {ι : Sort _} [Countable ι] (u : ι → α) (hu : DenseRange u) :
SeparableSpace α :=
⟨⟨range u, countable_range u, hu⟩⟩
alias _root_.DenseRange.separableSpace' := SeparableSpace.of_denseRange
/-- If `α` is a separable space and `f : α → β` is a continuous map with dense range, then `β` is
a separable space as well. E.g., the completion of a separable uniform space is separable. -/
protected theorem _root_.DenseRange.separableSpace [SeparableSpace α] [TopologicalSpace β]
{f : α → β} (h : DenseRange f) (h' : Continuous f) : SeparableSpace β :=
let ⟨s, s_cnt, s_dense⟩ := exists_countable_dense α
⟨⟨f '' s, Countable.image s_cnt f, h.dense_image h' s_dense⟩⟩
theorem _root_.Topology.IsQuotientMap.separableSpace [SeparableSpace α] [TopologicalSpace β]
{f : α → β} (hf : IsQuotientMap f) : SeparableSpace β :=
hf.surjective.denseRange.separableSpace hf.continuous
/-- The product of two separable spaces is a separable space. -/
instance [TopologicalSpace β] [SeparableSpace α] [SeparableSpace β] : SeparableSpace (α × β) := by
rcases exists_countable_dense α with ⟨s, hsc, hsd⟩
rcases exists_countable_dense β with ⟨t, htc, htd⟩
exact ⟨⟨s ×ˢ t, hsc.prod htc, hsd.prod htd⟩⟩
/-- The product of a countable family of separable spaces is a separable space. -/
instance {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)] [∀ i, SeparableSpace (X i)]
[Countable ι] : SeparableSpace (∀ i, X i) := by
choose t htc htd using (exists_countable_dense <| X ·)
haveI := fun i ↦ (htc i).to_subtype
nontriviality ∀ i, X i; inhabit ∀ i, X i
classical
set f : (Σ I : Finset ι, ∀ i : I, t i) → ∀ i, X i := fun ⟨I, g⟩ i ↦
if hi : i ∈ I then g ⟨i, hi⟩ else (default : ∀ i, X i) i
refine ⟨⟨range f, countable_range f, dense_iff_inter_open.2 fun U hU ⟨g, hg⟩ ↦ ?_⟩⟩
rcases isOpen_pi_iff.1 hU g hg with ⟨I, u, huo, huU⟩
have : ∀ i : I, ∃ y ∈ t i, y ∈ u i := fun i ↦
(htd i).exists_mem_open (huo i i.2).1 ⟨_, (huo i i.2).2⟩
choose y hyt hyu using this
lift y to ∀ i : I, t i using hyt
refine ⟨f ⟨I, y⟩, huU fun i (hi : i ∈ I) ↦ ?_, mem_range_self (f := f) ⟨I, y⟩⟩
simp only [f, dif_pos hi]
exact hyu ⟨i, _⟩
instance [SeparableSpace α] {r : α → α → Prop} : SeparableSpace (Quot r) :=
isQuotientMap_quot_mk.separableSpace
instance [SeparableSpace α] {s : Setoid α} : SeparableSpace (Quotient s) :=
isQuotientMap_quot_mk.separableSpace
/-- A topological space with discrete topology is separable iff it is countable. -/
theorem separableSpace_iff_countable [DiscreteTopology α] : SeparableSpace α ↔ Countable α := by
simp [separableSpace_iff, countable_univ_iff]
/-- In a separable space, a family of nonempty disjoint open sets is countable. -/
theorem _root_.Pairwise.countable_of_isOpen_disjoint [SeparableSpace α] {ι : Type*}
{s : ι → Set α} (hd : Pairwise (Disjoint on s)) (ho : ∀ i, IsOpen (s i))
(hne : ∀ i, (s i).Nonempty) : Countable ι := by
rcases exists_countable_dense α with ⟨u, u_countable, u_dense⟩
choose f hfu hfs using fun i ↦ u_dense.exists_mem_open (ho i) (hne i)
have f_inj : Injective f := fun i j hij ↦
hd.eq <| not_disjoint_iff.2 ⟨f i, hfs i, hij.symm ▸ hfs j⟩
have := u_countable.to_subtype
exact (f_inj.codRestrict hfu).countable
/-- In a separable space, a family of nonempty disjoint open sets is countable. -/
theorem _root_.Set.PairwiseDisjoint.countable_of_isOpen [SeparableSpace α] {ι : Type*}
{s : ι → Set α} {a : Set ι} (h : a.PairwiseDisjoint s) (ho : ∀ i ∈ a, IsOpen (s i))
(hne : ∀ i ∈ a, (s i).Nonempty) : a.Countable :=
(h.subtype _ _).countable_of_isOpen_disjoint (Subtype.forall.2 ho) (Subtype.forall.2 hne)
/-- In a separable space, a family of disjoint sets with nonempty interiors is countable. -/
theorem _root_.Set.PairwiseDisjoint.countable_of_nonempty_interior [SeparableSpace α] {ι : Type*}
{s : ι → Set α} {a : Set ι} (h : a.PairwiseDisjoint s)
(ha : ∀ i ∈ a, (interior (s i)).Nonempty) : a.Countable :=
(h.mono fun _ => interior_subset).countable_of_isOpen (fun _ _ => isOpen_interior) ha
/-- A set `s` in a topological space is separable if it is contained in the closure of a countable
set `c`. Beware that this definition does not require that `c` is contained in `s` (to express the
latter, use `TopologicalSpace.SeparableSpace s` or
`TopologicalSpace.IsSeparable (univ : Set s))`. In metric spaces, the two definitions are
equivalent, see `TopologicalSpace.IsSeparable.separableSpace`. -/
def IsSeparable (s : Set α) :=
∃ c : Set α, c.Countable ∧ s ⊆ closure c
theorem IsSeparable.mono {s u : Set α} (hs : IsSeparable s) (hu : u ⊆ s) : IsSeparable u := by
rcases hs with ⟨c, c_count, hs⟩
exact ⟨c, c_count, hu.trans hs⟩
theorem IsSeparable.iUnion {ι : Sort*} [Countable ι] {s : ι → Set α}
(hs : ∀ i, IsSeparable (s i)) : IsSeparable (⋃ i, s i) := by
choose c hc h'c using hs
refine ⟨⋃ i, c i, countable_iUnion hc, iUnion_subset_iff.2 fun i => ?_⟩
exact (h'c i).trans (closure_mono (subset_iUnion _ i))
@[simp]
theorem isSeparable_iUnion {ι : Sort*} [Countable ι] {s : ι → Set α} :
IsSeparable (⋃ i, s i) ↔ ∀ i, IsSeparable (s i) :=
⟨fun h i ↦ h.mono <| subset_iUnion s i, .iUnion⟩
@[simp]
theorem isSeparable_union {s t : Set α} : IsSeparable (s ∪ t) ↔ IsSeparable s ∧ IsSeparable t := by
simp [union_eq_iUnion, and_comm]
theorem IsSeparable.union {s u : Set α} (hs : IsSeparable s) (hu : IsSeparable u) :
IsSeparable (s ∪ u) :=
isSeparable_union.2 ⟨hs, hu⟩
@[simp]
theorem isSeparable_closure : IsSeparable (closure s) ↔ IsSeparable s := by
simp only [IsSeparable, isClosed_closure.closure_subset_iff]
protected alias ⟨_, IsSeparable.closure⟩ := isSeparable_closure
theorem _root_.Set.Countable.isSeparable {s : Set α} (hs : s.Countable) : IsSeparable s :=
⟨s, hs, subset_closure⟩
theorem _root_.Set.Finite.isSeparable {s : Set α} (hs : s.Finite) : IsSeparable s :=
hs.countable.isSeparable
theorem IsSeparable.univ_pi {ι : Type*} [Countable ι] {X : ι → Type*} {s : ∀ i, Set (X i)}
[∀ i, TopologicalSpace (X i)] (h : ∀ i, IsSeparable (s i)) :
IsSeparable (univ.pi s) := by
classical
rcases eq_empty_or_nonempty (univ.pi s) with he | ⟨f₀, -⟩
· rw [he]
exact countable_empty.isSeparable
· choose c c_count hc using h
haveI := fun i ↦ (c_count i).to_subtype
set g : (I : Finset ι) × ((i : I) → c i) → (i : ι) → X i := fun ⟨I, f⟩ i ↦
if hi : i ∈ I then f ⟨i, hi⟩ else f₀ i
refine ⟨range g, countable_range g, fun f hf ↦ mem_closure_iff.2 fun o ho hfo ↦ ?_⟩
rcases isOpen_pi_iff.1 ho f hfo with ⟨I, u, huo, hI⟩
rsuffices ⟨f, hf⟩ : ∃ f : (i : I) → c i, g ⟨I, f⟩ ∈ Set.pi I u
· exact ⟨g ⟨I, f⟩, hI hf, mem_range_self (f := g) ⟨I, f⟩⟩
suffices H : ∀ i ∈ I, (u i ∩ c i).Nonempty by
choose f hfu hfc using H
refine ⟨fun i ↦ ⟨f i i.2, hfc i i.2⟩, fun i (hi : i ∈ I) ↦ ?_⟩
simpa only [g, dif_pos hi] using hfu i hi
intro i hi
exact mem_closure_iff.1 (hc i <| hf _ trivial) _ (huo i hi).1 (huo i hi).2
lemma isSeparable_pi {ι : Type*} [Countable ι] {α : ι → Type*} {s : ∀ i, Set (α i)}
[∀ i, TopologicalSpace (α i)] (h : ∀ i, IsSeparable (s i)) :
IsSeparable {f : ∀ i, α i | ∀ i, f i ∈ s i} := by
simpa only [← mem_univ_pi] using IsSeparable.univ_pi h
lemma IsSeparable.prod {β : Type*} [TopologicalSpace β]
{s : Set α} {t : Set β} (hs : IsSeparable s) (ht : IsSeparable t) :
IsSeparable (s ×ˢ t) := by
rcases hs with ⟨cs, cs_count, hcs⟩
rcases ht with ⟨ct, ct_count, hct⟩
refine ⟨cs ×ˢ ct, cs_count.prod ct_count, ?_⟩
rw [closure_prod_eq]
gcongr
theorem IsSeparable.image {β : Type*} [TopologicalSpace β] {s : Set α} (hs : IsSeparable s)
{f : α → β} (hf : Continuous f) : IsSeparable (f '' s) := by
rcases hs with ⟨c, c_count, hc⟩
refine ⟨f '' c, c_count.image _, ?_⟩
rw [image_subset_iff]
exact hc.trans (closure_subset_preimage_closure_image hf)
theorem _root_.Dense.isSeparable_iff (hs : Dense s) :
IsSeparable s ↔ SeparableSpace α := by
simp_rw [IsSeparable, separableSpace_iff, dense_iff_closure_eq, ← univ_subset_iff,
← hs.closure_eq, isClosed_closure.closure_subset_iff]
theorem isSeparable_univ_iff : IsSeparable (univ : Set α) ↔ SeparableSpace α :=
dense_univ.isSeparable_iff
theorem isSeparable_range [TopologicalSpace β] [SeparableSpace α] {f : α → β} (hf : Continuous f) :
IsSeparable (range f) :=
image_univ (f := f) ▸ (isSeparable_univ_iff.2 ‹_›).image hf
theorem IsSeparable.of_subtype (s : Set α) [SeparableSpace s] : IsSeparable s := by
simpa using isSeparable_range (continuous_subtype_val (p := (· ∈ s)))
theorem IsSeparable.of_separableSpace [h : SeparableSpace α] (s : Set α) : IsSeparable s :=
IsSeparable.mono (isSeparable_univ_iff.2 h) (subset_univ _)
end TopologicalSpace
open TopologicalSpace
protected theorem IsTopologicalBasis.iInf {β : Type*} {ι : Type*} {t : ι → TopologicalSpace β}
{T : ι → Set (Set β)} (h_basis : ∀ i, IsTopologicalBasis (t := t i) (T i)) :
IsTopologicalBasis (t := ⨅ i, t i)
{ S | ∃ (U : ι → Set β) (F : Finset ι), (∀ i, i ∈ F → U i ∈ T i) ∧ S = ⋂ i ∈ F, U i } := by
let _ := ⨅ i, t i
refine isTopologicalBasis_of_isOpen_of_nhds ?_ ?_
· rintro - ⟨U, F, hU, rfl⟩
refine isOpen_biInter_finset fun i hi ↦
(h_basis i).isOpen (t := t i) (hU i hi) |>.mono (iInf_le _ _)
· intro a u ha hu
rcases (nhds_iInf (t := t) (a := a)).symm ▸ HasBasis.iInf'
(fun i ↦ (h_basis i).nhds_hasBasis (t := t i)) |>.mem_iff.1 (hu.mem_nhds ha)
with ⟨⟨F, U⟩, ⟨hF, hU⟩, hUu⟩
refine ⟨_, ⟨U, hF.toFinset, ?_, rfl⟩, ?_, ?_⟩ <;> simp only [Finite.mem_toFinset, mem_iInter]
· exact fun i hi ↦ (hU i hi).1
· exact fun i hi ↦ (hU i hi).2
· exact hUu
theorem IsTopologicalBasis.iInf_induced {β : Type*} {ι : Type*} {X : ι → Type*}
[t : Π i, TopologicalSpace (X i)] {T : Π i, Set (Set (X i))}
(cond : ∀ i, IsTopologicalBasis (T i)) (f : Π i, β → X i) :
IsTopologicalBasis (t := ⨅ i, induced (f i) (t i))
{ S | ∃ (U : ∀ i, Set (X i)) (F : Finset ι),
(∀ i, i ∈ F → U i ∈ T i) ∧ S = ⋂ (i) (_ : i ∈ F), f i ⁻¹' U i } := by
convert IsTopologicalBasis.iInf (fun i ↦ (cond i).induced (f i)) with S
constructor <;> rintro ⟨U, F, hUT, hSU⟩
· exact ⟨fun i ↦ (f i) ⁻¹' (U i), F, fun i hi ↦ mem_image_of_mem _ (hUT i hi), hSU⟩
· choose! U' hU' hUU' using hUT
exact ⟨U', F, hU', hSU ▸ (.symm <| iInter₂_congr hUU')⟩
theorem isTopologicalBasis_pi {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
{T : ∀ i, Set (Set (X i))} (cond : ∀ i, IsTopologicalBasis (T i)) :
IsTopologicalBasis { S | ∃ (U : ∀ i, Set (X i)) (F : Finset ι),
(∀ i, i ∈ F → U i ∈ T i) ∧ S = (F : Set ι).pi U } := by
simpa only [Set.pi_def] using IsTopologicalBasis.iInf_induced cond eval
theorem isTopologicalBasis_singletons (α : Type*) [TopologicalSpace α] [DiscreteTopology α] :
IsTopologicalBasis { s | ∃ x : α, (s : Set α) = {x} } :=
isTopologicalBasis_of_isOpen_of_nhds (fun _ _ => isOpen_discrete _) fun x _ hx _ =>
⟨{x}, ⟨x, rfl⟩, mem_singleton x, singleton_subset_iff.2 hx⟩
theorem isTopologicalBasis_subtype
{α : Type*} [TopologicalSpace α] {B : Set (Set α)}
(h : TopologicalSpace.IsTopologicalBasis B) (p : α → Prop) :
IsTopologicalBasis (Set.preimage (Subtype.val (p := p)) '' B) :=
h.isInducing ⟨rfl⟩
section
variable {ι : Type*} {X : ι → Type*} [∀ i, TopologicalSpace (X i)]
lemma isOpenMap_eval (i : ι) : IsOpenMap (Function.eval i : (∀ i, X i) → X i) := by
classical
refine (isTopologicalBasis_pi fun _ ↦ isTopologicalBasis_opens).isOpenMap_iff.2 ?_
rintro _ ⟨U, s, hU, rfl⟩
obtain h | h := ((s : Set ι).pi U).eq_empty_or_nonempty
· simp [h]
by_cases hi : i ∈ s
· rw [eval_image_pi (mod_cast hi) h]
exact hU _ hi
· rw [eval_image_pi_of_notMem (mod_cast hi), if_pos h]
exact isOpen_univ
end
theorem Dense.exists_countable_dense_subset {α : Type*} [TopologicalSpace α] {s : Set α}
[SeparableSpace s] (hs : Dense s) : ∃ t ⊆ s, t.Countable ∧ Dense t :=
let ⟨t, htc, htd⟩ := exists_countable_dense s
⟨(↑) '' t, Subtype.coe_image_subset s t, htc.image Subtype.val,
hs.denseRange_val.dense_image continuous_subtype_val htd⟩
/-- Let `s` be a dense set in a topological space `α` with partial order structure. If `s` is a
separable space (e.g., if `α` has a second countable topology), then there exists a countable
dense subset `t ⊆ s` such that `t` contains bottom/top element of `α` when they exist and belong
to `s`. For a dense subset containing neither bot nor top elements, see
`Dense.exists_countable_dense_subset_no_bot_top`. -/
theorem Dense.exists_countable_dense_subset_bot_top {α : Type*} [TopologicalSpace α]
[PartialOrder α] {s : Set α} [SeparableSpace s] (hs : Dense s) :
∃ t ⊆ s, t.Countable ∧ Dense t ∧ (∀ x, IsBot x → x ∈ s → x ∈ t) ∧
∀ x, IsTop x → x ∈ s → x ∈ t := by
rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, htd⟩
refine ⟨(t ∪ ({ x | IsBot x } ∪ { x | IsTop x })) ∩ s, ?_, ?_, ?_, ?_, ?_⟩
exacts [inter_subset_right,
(htc.union ((countable_isBot α).union (countable_isTop α))).mono inter_subset_left,
htd.mono (subset_inter subset_union_left hts), fun x hx hxs => ⟨Or.inr <| Or.inl hx, hxs⟩,
fun x hx hxs => ⟨Or.inr <| Or.inr hx, hxs⟩]
instance separableSpace_univ {α : Type*} [TopologicalSpace α] [SeparableSpace α] :
SeparableSpace (univ : Set α) :=
(Equiv.Set.univ α).symm.surjective.denseRange.separableSpace (continuous_id.subtype_mk _)
/-- If `α` is a separable topological space with a partial order, then there exists a countable
dense set `s : Set α` that contains those of both bottom and top elements of `α` that actually
exist. For a dense set containing neither bot nor top elements, see
`exists_countable_dense_no_bot_top`. -/
theorem exists_countable_dense_bot_top (α : Type*) [TopologicalSpace α] [SeparableSpace α]
[PartialOrder α] :
∃ s : Set α, s.Countable ∧ Dense s ∧ (∀ x, IsBot x → x ∈ s) ∧ ∀ x, IsTop x → x ∈ s := by
simpa using dense_univ.exists_countable_dense_subset_bot_top
namespace TopologicalSpace
universe u
variable (α : Type u) [t : TopologicalSpace α]
/-- A first-countable space is one in which every point has a
countable neighborhood basis. -/
class _root_.FirstCountableTopology : Prop where
/-- The filter `𝓝 a` is countably generated for all points `a`. -/
nhds_generated_countable : ∀ a : α, (𝓝 a).IsCountablyGenerated
attribute [instance] FirstCountableTopology.nhds_generated_countable
/-- If `β` is a first-countable space, then its induced topology via `f` on `α` is also
first-countable. -/
theorem firstCountableTopology_induced (α β : Type*) [t : TopologicalSpace β]
[FirstCountableTopology β] (f : α → β) : @FirstCountableTopology α (t.induced f) :=
let _ := t.induced f
⟨fun x ↦ nhds_induced f x ▸ inferInstance⟩
variable {α}
instance Subtype.firstCountableTopology (s : Set α) [FirstCountableTopology α] :
FirstCountableTopology s :=
firstCountableTopology_induced s α (↑)
protected theorem _root_.Topology.IsInducing.firstCountableTopology {β : Type*}
[TopologicalSpace β] [FirstCountableTopology β] {f : α → β} (hf : IsInducing f) :
FirstCountableTopology α := by
rw [hf.1]
exact firstCountableTopology_induced α β f
protected theorem _root_.Topology.IsEmbedding.firstCountableTopology {β : Type*}
[TopologicalSpace β] [FirstCountableTopology β] {f : α → β} (hf : IsEmbedding f) :
FirstCountableTopology α :=
hf.1.firstCountableTopology
namespace FirstCountableTopology
/-- In a first-countable space, a cluster point `x` of a sequence
is the limit of some subsequence. -/
theorem tendsto_subseq [FirstCountableTopology α] {u : ℕ → α} {x : α}
(hx : MapClusterPt x atTop u) : ∃ ψ : ℕ → ℕ, StrictMono ψ ∧ Tendsto (u ∘ ψ) atTop (𝓝 x) :=
subseq_tendsto_of_neBot hx
end FirstCountableTopology
instance {β} [TopologicalSpace β] [FirstCountableTopology α] [FirstCountableTopology β] :
FirstCountableTopology (α × β) :=
⟨fun ⟨x, y⟩ => by rw [nhds_prod_eq]; infer_instance⟩
section Pi
instance {ι : Type*} {X : ι → Type*} [Countable ι] [∀ i, TopologicalSpace (X i)]
[∀ i, FirstCountableTopology (X i)] : FirstCountableTopology (∀ i, X i) :=
⟨fun f => by rw [nhds_pi]; infer_instance⟩
end Pi
instance isCountablyGenerated_nhdsWithin (x : α) [IsCountablyGenerated (𝓝 x)] (s : Set α) :
IsCountablyGenerated (𝓝[s] x) :=
Inf.isCountablyGenerated _ _
variable (α) in
/-- A second-countable space is one with a countable basis. -/
class _root_.SecondCountableTopology : Prop where
/-- There exists a countable set of sets that generates the topology. -/
is_open_generated_countable : ∃ b : Set (Set α), b.Countable ∧ t = TopologicalSpace.generateFrom b
protected theorem IsTopologicalBasis.secondCountableTopology {b : Set (Set α)}
(hb : IsTopologicalBasis b) (hc : b.Countable) : SecondCountableTopology α :=
⟨⟨b, hc, hb.eq_generateFrom⟩⟩
lemma SecondCountableTopology.mk' {α} {b : Set (Set α)} (hc : b.Countable) :
@SecondCountableTopology α (generateFrom b) :=
@SecondCountableTopology.mk α (generateFrom b) ⟨b, hc, rfl⟩
instance _root_.Finite.toSecondCountableTopology [Finite α] : SecondCountableTopology α where
is_open_generated_countable :=
⟨_, {U | IsOpen U}.to_countable, TopologicalSpace.isTopologicalBasis_opens.eq_generateFrom⟩
variable (α)
theorem exists_countable_basis [SecondCountableTopology α] :
∃ b : Set (Set α), b.Countable ∧ ∅ ∉ b ∧ IsTopologicalBasis b := by
obtain ⟨b, hb₁, hb₂⟩ := @SecondCountableTopology.is_open_generated_countable α _ _
refine ⟨_, ?_, notMem_diff_of_mem ?_, (isTopologicalBasis_of_subbasis hb₂).diff_empty⟩
exacts [((countable_setOf_finite_subset hb₁).image _).mono diff_subset, rfl]
/-- A countable topological basis of `α`. -/
def countableBasis [SecondCountableTopology α] : Set (Set α) :=
(exists_countable_basis α).choose
theorem countable_countableBasis [SecondCountableTopology α] : (countableBasis α).Countable :=
(exists_countable_basis α).choose_spec.1
instance encodableCountableBasis [SecondCountableTopology α] : Encodable (countableBasis α) :=
(countable_countableBasis α).toEncodable
theorem empty_notMem_countableBasis [SecondCountableTopology α] : ∅ ∉ countableBasis α :=
(exists_countable_basis α).choose_spec.2.1
@[deprecated (since := "2025-05-24")] alias empty_nmem_countableBasis := empty_notMem_countableBasis
theorem isBasis_countableBasis [SecondCountableTopology α] :
IsTopologicalBasis (countableBasis α) :=
(exists_countable_basis α).choose_spec.2.2
theorem eq_generateFrom_countableBasis [SecondCountableTopology α] :
‹TopologicalSpace α› = generateFrom (countableBasis α) :=
(isBasis_countableBasis α).eq_generateFrom
variable {α}
theorem isOpen_of_mem_countableBasis [SecondCountableTopology α] {s : Set α}
(hs : s ∈ countableBasis α) : IsOpen s :=
(isBasis_countableBasis α).isOpen hs
theorem nonempty_of_mem_countableBasis [SecondCountableTopology α] {s : Set α}
(hs : s ∈ countableBasis α) : s.Nonempty :=
nonempty_iff_ne_empty.2 <| ne_of_mem_of_not_mem hs <| empty_notMem_countableBasis α
variable (α)
-- see Note [lower instance priority]
instance (priority := 100) SecondCountableTopology.to_firstCountableTopology
[SecondCountableTopology α] : FirstCountableTopology α :=
⟨fun _ => HasCountableBasis.isCountablyGenerated <|
⟨(isBasis_countableBasis α).nhds_hasBasis,
(countable_countableBasis α).mono inter_subset_left⟩⟩
-- see Note [lower instance priority]
instance (priority := 100) [Countable α] [FirstCountableTopology α] :
SecondCountableTopology α where
is_open_generated_countable := by
-- The countable union of the countable neighborhood bases at each point is a countable basis.
choose b hxb hbb using fun x : α => (nhds_basis_opens x).exists_antitone_subbasis
use range b.uncurry, countable_range b.uncurry
apply le_antisymm
· rw [le_generateFrom_iff_subset_isOpen]
rintro _ ⟨⟨x, n⟩, rfl⟩
exact (hxb x n).right
· rw [le_iff_nhds]
intro x
rw [(hbb x).ge_iff]
intro n _
refine @IsOpen.mem_nhds α (generateFrom (range b.uncurry)) x (b x n) ?_ (hxb x n).left
exact isOpen_generateFrom_of_mem ⟨⟨x, n⟩, rfl⟩
/-- If `β` is a second-countable space, then its induced topology via
`f` on `α` is also second-countable. -/
theorem secondCountableTopology_induced (α β) [t : TopologicalSpace β] [SecondCountableTopology β]
(f : α → β) : @SecondCountableTopology α (t.induced f) := by
rcases @SecondCountableTopology.is_open_generated_countable β _ _ with ⟨b, hb, eq⟩
letI := t.induced f
refine { is_open_generated_countable := ⟨preimage f '' b, hb.image _, ?_⟩ }
rw [eq, induced_generateFrom_eq]
variable {α}
instance Subtype.secondCountableTopology (s : Set α) [SecondCountableTopology α] :
SecondCountableTopology s :=
secondCountableTopology_induced s α (↑)
lemma secondCountableTopology_iInf {α ι} [Countable ι] {t : ι → TopologicalSpace α}
(ht : ∀ i, @SecondCountableTopology α (t i)) : @SecondCountableTopology α (⨅ i, t i) := by
rw [funext fun i => @eq_generateFrom_countableBasis α (t i) (ht i), ← generateFrom_iUnion]
exact SecondCountableTopology.mk' <|
countable_iUnion fun i => @countable_countableBasis _ (t i) (ht i)
-- TODO: more fine grained instances for `FirstCountableTopology`, `SeparableSpace`, `T2Space`, ...
instance {β : Type*} [TopologicalSpace β] [SecondCountableTopology α] [SecondCountableTopology β] :
SecondCountableTopology (α × β) :=
((isBasis_countableBasis α).prod (isBasis_countableBasis β)).secondCountableTopology <|
(countable_countableBasis α).image2 (countable_countableBasis β) _
instance {ι : Type*} {X : ι → Type*} [Countable ι] [∀ a, TopologicalSpace (X a)]
[∀ a, SecondCountableTopology (X a)] : SecondCountableTopology (∀ a, X a) :=
secondCountableTopology_iInf fun _ => secondCountableTopology_induced _ _ _
-- see Note [lower instance priority]
instance (priority := 100) SecondCountableTopology.to_separableSpace [SecondCountableTopology α] :
SeparableSpace α := by
choose p hp using fun s : countableBasis α => nonempty_of_mem_countableBasis s.2
exact ⟨⟨range p, countable_range _, (isBasis_countableBasis α).dense_iff.2 fun o ho _ =>
⟨p ⟨o, ho⟩, hp ⟨o, _⟩, mem_range_self _⟩⟩⟩
/-- A countable open cover induces a second-countable topology if all open covers
are themselves second countable. -/
theorem secondCountableTopology_of_countable_cover {ι} [Countable ι] {U : ι → Set α}
[∀ i, SecondCountableTopology (U i)] (Uo : ∀ i, IsOpen (U i)) (hc : ⋃ i, U i = univ) :
SecondCountableTopology α :=
haveI : IsTopologicalBasis (⋃ i, image ((↑) : U i → α) '' countableBasis (U i)) :=
isTopologicalBasis_of_cover Uo hc fun i => isBasis_countableBasis (U i)
this.secondCountableTopology (countable_iUnion fun _ => (countable_countableBasis _).image _)
/-- In a second-countable space, an open set, given as a union of open sets,
is equal to the union of countably many of those sets.
In particular, any open covering of `α` has a countable subcover: α is a Lindelöf space. -/
theorem isOpen_iUnion_countable [SecondCountableTopology α] {ι} (s : ι → Set α)
(H : ∀ i, IsOpen (s i)) : ∃ T : Set ι, T.Countable ∧ ⋃ i ∈ T, s i = ⋃ i, s i := by
let B := { b ∈ countableBasis α | ∃ i, b ⊆ s i }
choose f hf using fun b : B => b.2.2
haveI : Countable B := ((countable_countableBasis α).mono (sep_subset _ _)).to_subtype
refine ⟨_, countable_range f, (iUnion₂_subset_iUnion _ _).antisymm (sUnion_subset ?_)⟩
rintro _ ⟨i, rfl⟩ x xs
rcases (isBasis_countableBasis α).exists_subset_of_mem_open xs (H _) with ⟨b, hb, xb, bs⟩
exact ⟨_, ⟨_, rfl⟩, _, ⟨⟨⟨_, hb, _, bs⟩, rfl⟩, rfl⟩, hf _ xb⟩
theorem isOpen_biUnion_countable [SecondCountableTopology α] {ι : Type*} (I : Set ι) (s : ι → Set α)
(H : ∀ i ∈ I, IsOpen (s i)) : ∃ T ⊆ I, T.Countable ∧ ⋃ i ∈ T, s i = ⋃ i ∈ I, s i := by
simp_rw [← Subtype.exists_set_subtype, biUnion_image]
rcases isOpen_iUnion_countable (fun i : I ↦ s i) fun i ↦ H i i.2 with ⟨T, hTc, hU⟩
exact ⟨T, hTc.image _, hU.trans <| iUnion_subtype ..⟩
theorem isOpen_sUnion_countable [SecondCountableTopology α] (S : Set (Set α))
(H : ∀ s ∈ S, IsOpen s) : ∃ T : Set (Set α), T.Countable ∧ T ⊆ S ∧ ⋃₀ T = ⋃₀ S := by
simpa only [and_left_comm, sUnion_eq_biUnion] using isOpen_biUnion_countable S id H
/-- In a topological space with second countable topology, if `f` is a function that sends each
point `x` to a neighborhood of `x`, then for some countable set `s`, the neighborhoods `f x`,
`x ∈ s`, cover the whole space. -/
theorem countable_cover_nhds [SecondCountableTopology α] {f : α → Set α} (hf : ∀ x, f x ∈ 𝓝 x) :
∃ s : Set α, s.Countable ∧ ⋃ x ∈ s, f x = univ := by
rcases isOpen_iUnion_countable (fun x => interior (f x)) fun x => isOpen_interior with
⟨s, hsc, hsU⟩
suffices ⋃ x ∈ s, interior (f x) = univ from
⟨s, hsc, flip eq_univ_of_subset this <| iUnion₂_mono fun _ _ => interior_subset⟩
simp only [hsU, eq_univ_iff_forall, mem_iUnion]
exact fun x => ⟨x, mem_interior_iff_mem_nhds.2 (hf x)⟩
theorem countable_cover_nhdsWithin [SecondCountableTopology α] {f : α → Set α} {s : Set α}
(hf : ∀ x ∈ s, f x ∈ 𝓝[s] x) : ∃ t ⊆ s, t.Countable ∧ s ⊆ ⋃ x ∈ t, f x := by
have : ∀ x : s, (↑) ⁻¹' f x ∈ 𝓝 x := fun x => preimage_coe_mem_nhds_subtype.2 (hf x x.2)
rcases countable_cover_nhds this with ⟨t, htc, htU⟩
refine ⟨(↑) '' t, Subtype.coe_image_subset _ _, htc.image _, fun x hx => ?_⟩
simp only [biUnion_image, eq_univ_iff_forall, ← preimage_iUnion, mem_preimage] at htU ⊢
exact htU ⟨x, hx⟩
section Sigma
variable {ι : Type*} {E : ι → Type*} [∀ i, TopologicalSpace (E i)]
/-- In a disjoint union space `Σ i, E i`, one can form a topological basis by taking the union of
topological bases on each of the parts of the space. -/
theorem IsTopologicalBasis.sigma {s : ∀ i : ι, Set (Set (E i))}
(hs : ∀ i, IsTopologicalBasis (s i)) :
IsTopologicalBasis (⋃ i : ι, (fun u => (Sigma.mk i '' u : Set (Σ i, E i))) '' s i) := by
refine .of_hasBasis_nhds fun a ↦ ?_
rw [Sigma.nhds_eq]
convert (((hs a.1).nhds_hasBasis).map _).to_image_id
aesop
/-- A countable disjoint union of second countable spaces is second countable. -/
instance [Countable ι] [∀ i, SecondCountableTopology (E i)] :
SecondCountableTopology (Σ i, E i) := by
let b := ⋃ i : ι, (fun u => (Sigma.mk i '' u : Set (Σ i, E i))) '' countableBasis (E i)
have A : IsTopologicalBasis b := IsTopologicalBasis.sigma fun i => isBasis_countableBasis _
have B : b.Countable := countable_iUnion fun i => (countable_countableBasis _).image _
exact A.secondCountableTopology B
end Sigma
section Sum
variable {β : Type*} [TopologicalSpace β]
/-- In a sum space `α ⊕ β`, one can form a topological basis by taking the union of
topological bases on each of the two components. -/
theorem IsTopologicalBasis.sum {s : Set (Set α)} (hs : IsTopologicalBasis s) {t : Set (Set β)}
(ht : IsTopologicalBasis t) :
IsTopologicalBasis ((fun u => Sum.inl '' u) '' s ∪ (fun u => Sum.inr '' u) '' t) := by
apply isTopologicalBasis_of_isOpen_of_nhds
· rintro u (⟨w, hw, rfl⟩ | ⟨w, hw, rfl⟩)
· exact IsOpenEmbedding.inl.isOpenMap w (hs.isOpen hw)
· exact IsOpenEmbedding.inr.isOpenMap w (ht.isOpen hw)
· rintro (x | x) u hxu u_open
· obtain ⟨v, vs, xv, vu⟩ : ∃ v ∈ s, x ∈ v ∧ v ⊆ Sum.inl ⁻¹' u :=
hs.exists_subset_of_mem_open hxu (isOpen_sum_iff.1 u_open).1
exact ⟨Sum.inl '' v, mem_union_left _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv,
image_subset_iff.2 vu⟩
· obtain ⟨v, vs, xv, vu⟩ : ∃ v ∈ t, x ∈ v ∧ v ⊆ Sum.inr ⁻¹' u :=
ht.exists_subset_of_mem_open hxu (isOpen_sum_iff.1 u_open).2
exact ⟨Sum.inr '' v, mem_union_right _ (mem_image_of_mem _ vs), mem_image_of_mem _ xv,
image_subset_iff.2 vu⟩
/-- A sum type of two second countable spaces is second countable. -/
instance [SecondCountableTopology α] [SecondCountableTopology β] :
SecondCountableTopology (α ⊕ β) := by
let b :=
(fun u => Sum.inl '' u) '' countableBasis α ∪ (fun u => Sum.inr '' u) '' countableBasis β
have A : IsTopologicalBasis b := (isBasis_countableBasis α).sum (isBasis_countableBasis β)
have B : b.Countable :=
(Countable.image (countable_countableBasis _) _).union
(Countable.image (countable_countableBasis _) _)
exact A.secondCountableTopology B
end Sum
section Quotient
variable {X : Type*} [TopologicalSpace X] {Y : Type*} [TopologicalSpace Y] {π : X → Y}
/-- The image of a topological basis under an open quotient map is a topological basis. -/
theorem IsTopologicalBasis.isQuotientMap {V : Set (Set X)} (hV : IsTopologicalBasis V)
(h' : IsQuotientMap π) (h : IsOpenMap π) : IsTopologicalBasis (Set.image π '' V) := by
apply isTopologicalBasis_of_isOpen_of_nhds
· rintro - ⟨U, U_in_V, rfl⟩
apply h U (hV.isOpen U_in_V)
· intro y U y_in_U U_open
obtain ⟨x, rfl⟩ := h'.surjective y
let W := π ⁻¹' U
have x_in_W : x ∈ W := y_in_U
have W_open : IsOpen W := U_open.preimage h'.continuous
obtain ⟨Z, Z_in_V, x_in_Z, Z_in_W⟩ := hV.exists_subset_of_mem_open x_in_W W_open
have XZ_in_U : π '' Z ⊆ U := (Set.image_mono Z_in_W).trans (image_preimage_subset π U)
exact ⟨π '' Z, ⟨Z, Z_in_V, rfl⟩, ⟨x, x_in_Z, rfl⟩, XZ_in_U⟩
/-- A second countable space is mapped by an open quotient map to a second countable space. -/
theorem _root_.Topology.IsQuotientMap.secondCountableTopology [SecondCountableTopology X]
(h' : IsQuotientMap π) (h : IsOpenMap π) : SecondCountableTopology Y where
is_open_generated_countable := by
obtain ⟨V, V_countable, -, V_generates⟩ := exists_countable_basis X
exact ⟨Set.image π '' V, V_countable.image (Set.image π),
(V_generates.isQuotientMap h' h).eq_generateFrom⟩
variable {S : Setoid X}
/-- The image of a topological basis "downstairs" in an open quotient is a topological basis. -/
theorem IsTopologicalBasis.quotient {V : Set (Set X)} (hV : IsTopologicalBasis V)
(h : IsOpenMap (Quotient.mk' : X → Quotient S)) :
IsTopologicalBasis (Set.image (Quotient.mk' : X → Quotient S) '' V) :=
hV.isQuotientMap isQuotientMap_quotient_mk' h
/-- An open quotient of a second countable space is second countable. -/
theorem Quotient.secondCountableTopology [SecondCountableTopology X]
(h : IsOpenMap (Quotient.mk' : X → Quotient S)) : SecondCountableTopology (Quotient S) :=
isQuotientMap_quotient_mk'.secondCountableTopology h
end Quotient
end TopologicalSpace
open TopologicalSpace
variable {α β : Type*} [TopologicalSpace α] {f : α → β}
protected theorem Topology.IsInducing.secondCountableTopology [TopologicalSpace β]
[SecondCountableTopology β] (hf : IsInducing f) : SecondCountableTopology α := by
rw [hf.1]
exact secondCountableTopology_induced α β f
protected theorem Topology.IsEmbedding.secondCountableTopology
[TopologicalSpace β] [SecondCountableTopology β]
(hf : IsEmbedding f) : SecondCountableTopology α :=
hf.1.secondCountableTopology
protected theorem Topology.IsEmbedding.separableSpace
[TopologicalSpace β] [SecondCountableTopology β] {f : α → β} (hf : IsEmbedding f) :
TopologicalSpace.SeparableSpace α := by
have := hf.secondCountableTopology
exact SecondCountableTopology.to_separableSpace
|
PartrecCode.lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathlib.Computability.Partrec
import Mathlib.Data.Option.Basic
/-!
# Gödel Numbering for Partial Recursive Functions.
This file defines `Nat.Partrec.Code`, an inductive datatype describing code for partial
recursive functions on ℕ. It defines an encoding for these codes, and proves that the constructors
are primitive recursive with respect to the encoding.
It also defines the evaluation of these codes as partial functions using `PFun`, and proves that a
function is partially recursive (as defined by `Nat.Partrec`) if and only if it is the evaluation
of some code.
## Main Definitions
* `Nat.Partrec.Code`: Inductive datatype for partial recursive codes.
* `Nat.Partrec.Code.encodeCode`: A (computable) encoding of codes as natural numbers.
* `Nat.Partrec.Code.ofNatCode`: The inverse of this encoding.
* `Nat.Partrec.Code.eval`: The interpretation of a `Nat.Partrec.Code` as a partial function.
## Main Results
* `Nat.Partrec.Code.rec_prim`: Recursion on `Nat.Partrec.Code` is primitive recursive.
* `Nat.Partrec.Code.rec_computable`: Recursion on `Nat.Partrec.Code` is computable.
* `Nat.Partrec.Code.smn`: The $S_n^m$ theorem.
* `Nat.Partrec.Code.exists_code`: Partial recursiveness is equivalent to being the eval of a code.
* `Nat.Partrec.Code.evaln_prim`: `evaln` is primitive recursive.
* `Nat.Partrec.Code.fixed_point`: Roger's fixed point theorem.
* `Nat.Partrec.Code.fixed_point₂`: Kleene's second recursion theorem.
## References
* [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019]
-/
open Encodable Denumerable
namespace Nat.Partrec
theorem rfind' {f} (hf : Nat.Partrec f) :
Nat.Partrec
(Nat.unpaired fun a m =>
(Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a (n + m))).map (· + m)) :=
Partrec₂.unpaired'.2 <| by
refine
Partrec.map
((@Partrec₂.unpaired' fun a b : ℕ =>
Nat.rfind fun n => (fun m => m = 0) <$> f (Nat.pair a (n + b))).1
?_)
(Primrec.nat_add.comp Primrec.snd <| Primrec.snd.comp Primrec.fst).to_comp.to₂
have : Nat.Partrec (fun a => Nat.rfind (fun n => (fun m => decide (m = 0)) <$>
Nat.unpaired (fun a b => f (Nat.pair (Nat.unpair a).1 (b + (Nat.unpair a).2)))
(Nat.pair a n))) :=
rfind
(Partrec₂.unpaired'.2
((Partrec.nat_iff.2 hf).comp
(Primrec₂.pair.comp (Primrec.fst.comp <| Primrec.unpair.comp Primrec.fst)
(Primrec.nat_add.comp Primrec.snd
(Primrec.snd.comp <| Primrec.unpair.comp Primrec.fst))).to_comp))
simpa
/-- Code for partial recursive functions from ℕ to ℕ.
See `Nat.Partrec.Code.eval` for the interpretation of these constructors.
-/
inductive Code : Type
| zero : Code
| succ : Code
| left : Code
| right : Code
| pair : Code → Code → Code
| comp : Code → Code → Code
| prec : Code → Code → Code
| rfind' : Code → Code
compile_inductive% Code
end Nat.Partrec
namespace Nat.Partrec.Code
instance instInhabited : Inhabited Code :=
⟨zero⟩
/-- Returns a code for the constant function outputting a particular natural. -/
protected def const : ℕ → Code
| 0 => zero
| n + 1 => comp succ (Code.const n)
theorem const_inj : ∀ {n₁ n₂}, Nat.Partrec.Code.const n₁ = Nat.Partrec.Code.const n₂ → n₁ = n₂
| 0, 0, _ => by simp
| n₁ + 1, n₂ + 1, h => by
dsimp [Nat.Partrec.Code.const] at h
injection h with h₁ h₂
simp only [const_inj h₂]
/-- A code for the identity function. -/
protected def id : Code :=
pair left right
/-- Given a code `c` taking a pair as input, returns a code using `n` as the first argument to `c`.
-/
def curry (c : Code) (n : ℕ) : Code :=
comp c (pair (Code.const n) Code.id)
/-- An encoding of a `Nat.Partrec.Code` as a ℕ. -/
def encodeCode : Code → ℕ
| zero => 0
| succ => 1
| left => 2
| right => 3
| pair cf cg => 2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg)) + 4
| comp cf cg => 2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg) + 1) + 4
| prec cf cg => (2 * (2 * Nat.pair (encodeCode cf) (encodeCode cg)) + 1) + 4
| rfind' cf => (2 * (2 * encodeCode cf + 1) + 1) + 4
/--
A decoder for `Nat.Partrec.Code.encodeCode`, taking any ℕ to the `Nat.Partrec.Code` it represents.
-/
def ofNatCode : ℕ → Code
| 0 => zero
| 1 => succ
| 2 => left
| 3 => right
| n + 4 =>
let m := n.div2.div2
have hm : m < n + 4 := by
simp only [m, div2_val]
exact
lt_of_le_of_lt (le_trans (Nat.div_le_self _ _) (Nat.div_le_self _ _))
(Nat.succ_le_succ (Nat.le_add_right _ _))
have _m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm
have _m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm
match n.bodd, n.div2.bodd with
| false, false => pair (ofNatCode m.unpair.1) (ofNatCode m.unpair.2)
| false, true => comp (ofNatCode m.unpair.1) (ofNatCode m.unpair.2)
| true , false => prec (ofNatCode m.unpair.1) (ofNatCode m.unpair.2)
| true , true => rfind' (ofNatCode m)
/-- Proof that `Nat.Partrec.Code.ofNatCode` is the inverse of `Nat.Partrec.Code.encodeCode` -/
private theorem encode_ofNatCode : ∀ n, encodeCode (ofNatCode n) = n
| 0 => by simp [ofNatCode, encodeCode]
| 1 => by simp [ofNatCode, encodeCode]
| 2 => by simp [ofNatCode, encodeCode]
| 3 => by simp [ofNatCode, encodeCode]
| n + 4 => by
let m := n.div2.div2
have hm : m < n + 4 := by
simp only [m, div2_val]
exact
lt_of_le_of_lt (le_trans (Nat.div_le_self _ _) (Nat.div_le_self _ _))
(Nat.succ_le_succ (Nat.le_add_right _ _))
have _m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm
have _m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm
have IH := encode_ofNatCode m
have IH1 := encode_ofNatCode m.unpair.1
have IH2 := encode_ofNatCode m.unpair.2
conv_rhs => rw [← Nat.bit_decomp n, ← Nat.bit_decomp n.div2]
simp only [ofNatCode.eq_5]
cases n.bodd <;> cases n.div2.bodd <;>
simp [m, encodeCode, IH, IH1, IH2, Nat.bit_val]
instance instDenumerable : Denumerable Code :=
mk'
⟨encodeCode, ofNatCode, fun c => by
induction c <;> simp [encodeCode, ofNatCode, Nat.div2_val, *],
encode_ofNatCode⟩
theorem encodeCode_eq : encode = encodeCode :=
rfl
theorem ofNatCode_eq : ofNat Code = ofNatCode :=
rfl
theorem encode_lt_pair (cf cg) :
encode cf < encode (pair cf cg) ∧ encode cg < encode (pair cf cg) := by
simp only [encodeCode_eq, encodeCode]
have := Nat.mul_le_mul_right (Nat.pair cf.encodeCode cg.encodeCode) (by decide : 1 ≤ 2 * 2)
rw [one_mul, mul_assoc] at this
have := lt_of_le_of_lt this (lt_add_of_pos_right _ (by decide : 0 < 4))
exact ⟨lt_of_le_of_lt (Nat.left_le_pair _ _) this, lt_of_le_of_lt (Nat.right_le_pair _ _) this⟩
theorem encode_lt_comp (cf cg) :
encode cf < encode (comp cf cg) ∧ encode cg < encode (comp cf cg) := by
have : encode (pair cf cg) < encode (comp cf cg) := by simp [encodeCode_eq, encodeCode]
exact (encode_lt_pair cf cg).imp (fun h => lt_trans h this) fun h => lt_trans h this
theorem encode_lt_prec (cf cg) :
encode cf < encode (prec cf cg) ∧ encode cg < encode (prec cf cg) := by
have : encode (pair cf cg) < encode (prec cf cg) := by simp [encodeCode_eq, encodeCode]
exact (encode_lt_pair cf cg).imp (fun h => lt_trans h this) fun h => lt_trans h this
theorem encode_lt_rfind' (cf) : encode cf < encode (rfind' cf) := by
simp only [encodeCode_eq, encodeCode]
omega
end Nat.Partrec.Code
section
open Primrec
namespace Nat.Partrec.Code
theorem primrec₂_pair : Primrec₂ pair :=
Primrec₂.ofNat_iff.2 <|
Primrec₂.encode_iff.1 <|
nat_add.comp
(nat_double.comp <|
nat_double.comp <|
Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst)
(encode_iff.2 <| (Primrec.ofNat Code).comp snd))
(Primrec₂.const 4)
@[deprecated (since := "2025-05-12")] alias pair_prim := primrec₂_pair
theorem primrec₂_comp : Primrec₂ comp :=
Primrec₂.ofNat_iff.2 <|
Primrec₂.encode_iff.1 <|
nat_add.comp
(nat_double.comp <|
nat_double_succ.comp <|
Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst)
(encode_iff.2 <| (Primrec.ofNat Code).comp snd))
(Primrec₂.const 4)
@[deprecated (since := "2025-05-12")] alias comp_prim := primrec₂_comp
theorem primrec₂_prec : Primrec₂ prec :=
Primrec₂.ofNat_iff.2 <|
Primrec₂.encode_iff.1 <|
nat_add.comp
(nat_double_succ.comp <|
nat_double.comp <|
Primrec₂.natPair.comp (encode_iff.2 <| (Primrec.ofNat Code).comp fst)
(encode_iff.2 <| (Primrec.ofNat Code).comp snd))
(Primrec₂.const 4)
@[deprecated (since := "2025-05-12")] alias prec_prim := primrec₂_prec
theorem primrec_rfind' : Primrec rfind' :=
ofNat_iff.2 <|
encode_iff.1 <|
nat_add.comp
(nat_double_succ.comp <| nat_double_succ.comp <|
encode_iff.2 <| Primrec.ofNat Code)
(const 4)
@[deprecated (since := "2025-05-12")] alias rfind_prim := primrec_rfind'
theorem primrec_recOn' {α σ}
[Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ}
(hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ}
(hr : Primrec r) {pr : α → Code × Code × σ × σ → σ} (hpr : Primrec₂ pr)
{co : α → Code × Code × σ × σ → σ} (hco : Primrec₂ co) {pc : α → Code × Code × σ × σ → σ}
(hpc : Primrec₂ pc) {rf : α → Code × σ → σ} (hrf : Primrec₂ rf) :
let PR (a) cf cg hf hg := pr a (cf, cg, hf, hg)
let CO (a) cf cg hf hg := co a (cf, cg, hf, hg)
let PC (a) cf cg hf hg := pc a (cf, cg, hf, hg)
let RF (a) cf hf := rf a (cf, hf)
let F (a : α) (c : Code) : σ :=
Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a)
Primrec (fun a => F a (c a) : α → σ) := by
intros _ _ _ _ F
let G₁ : (α × List σ) × ℕ × ℕ → Option σ := fun p =>
letI a := p.1.1; letI IH := p.1.2; letI n := p.2.1; letI m := p.2.2
IH[m]?.bind fun s =>
IH[m.unpair.1]?.bind fun s₁ =>
IH[m.unpair.2]?.map fun s₂ =>
cond n.bodd
(cond n.div2.bodd (rf a (ofNat Code m, s))
(pc a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)))
(cond n.div2.bodd (co a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))
(pr a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)))
have : Primrec G₁ :=
option_bind (list_getElem?.comp (snd.comp fst) (snd.comp snd)) <| .mk <|
option_bind ((list_getElem?.comp (snd.comp fst)
(fst.comp <| Primrec.unpair.comp (snd.comp snd))).comp fst) <| .mk <|
option_map ((list_getElem?.comp (snd.comp fst)
(snd.comp <| Primrec.unpair.comp (snd.comp snd))).comp <| fst.comp fst) <| .mk <|
have a := fst.comp (fst.comp <| fst.comp <| fst.comp fst)
have n := fst.comp (snd.comp <| fst.comp <| fst.comp fst)
have m := snd.comp (snd.comp <| fst.comp <| fst.comp fst)
have m₁ := fst.comp (Primrec.unpair.comp m)
have m₂ := snd.comp (Primrec.unpair.comp m)
have s := snd.comp (fst.comp fst)
have s₁ := snd.comp fst
have s₂ := snd
(nat_bodd.comp n).cond
((nat_bodd.comp <| nat_div2.comp n).cond
(hrf.comp a (((Primrec.ofNat Code).comp m).pair s))
(hpc.comp a (((Primrec.ofNat Code).comp m₁).pair <|
((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂)))
(Primrec.cond (nat_bodd.comp <| nat_div2.comp n)
(hco.comp a (((Primrec.ofNat Code).comp m₁).pair <|
((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂))
(hpr.comp a (((Primrec.ofNat Code).comp m₁).pair <|
((Primrec.ofNat Code).comp m₂).pair <| s₁.pair s₂)))
let G : α → List σ → Option σ := fun a IH =>
IH.length.casesOn (some (z a)) fun n =>
n.casesOn (some (s a)) fun n =>
n.casesOn (some (l a)) fun n =>
n.casesOn (some (r a)) fun n =>
G₁ ((a, IH), n, n.div2.div2)
have : Primrec₂ G := .mk <|
nat_casesOn (list_length.comp snd) (option_some_iff.2 (hz.comp fst)) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hs.comp (fst.comp fst))) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hl.comp (fst.comp <| fst.comp fst))) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hr.comp (fst.comp <| fst.comp <| fst.comp fst))) <| .mk <|
this.comp <|
((fst.pair snd).comp <| fst.comp <| fst.comp <| fst.comp <| fst).pair <|
snd.pair <| nat_div2.comp <| nat_div2.comp snd
refine (nat_strong_rec (fun a n => F a (ofNat Code n)) this.to₂ fun a n => ?_)
|>.comp .id (encode_iff.2 hc) |>.of_eq fun a => by simp
iterate 4 rcases n with - | n; · simp [ofNatCode_eq, ofNatCode]; rfl
simp only [G]; rw [List.length_map, List.length_range]
let m := n.div2.div2
change G₁ ((a, (List.range (n + 4)).map fun n => F a (ofNat Code n)), n, m)
= some (F a (ofNat Code (n + 4)))
have hm : m < n + 4 := by
simp only [m, div2_val]
exact lt_of_le_of_lt
(le_trans (Nat.div_le_self ..) (Nat.div_le_self ..))
(Nat.succ_le_succ (Nat.le_add_right ..))
have m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm
have m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm
simp [G₁, m, hm, m1, m2]
rw [show ofNat Code (n + 4) = ofNatCode (n + 4) from rfl]
simp [ofNatCode]
cases n.bodd <;> cases n.div2.bodd <;> rfl
@[deprecated (since := "2025-05-12")] alias rec_prim' := primrec_recOn'
/-- Recursion on `Nat.Partrec.Code` is primitive recursive. -/
theorem primrec_recOn {α σ}
[Primcodable α] [Primcodable σ] {c : α → Code} (hc : Primrec c) {z : α → σ}
(hz : Primrec z) {s : α → σ} (hs : Primrec s) {l : α → σ} (hl : Primrec l) {r : α → σ}
(hr : Primrec r) {pr : α → Code → Code → σ → σ → σ}
(hpr : Primrec fun a : α × Code × Code × σ × σ => pr a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2)
{co : α → Code → Code → σ → σ → σ}
(hco : Primrec fun a : α × Code × Code × σ × σ => co a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2)
{pc : α → Code → Code → σ → σ → σ}
(hpc : Primrec fun a : α × Code × Code × σ × σ => pc a.1 a.2.1 a.2.2.1 a.2.2.2.1 a.2.2.2.2)
{rf : α → Code → σ → σ} (hrf : Primrec fun a : α × Code × σ => rf a.1 a.2.1 a.2.2) :
let F (a : α) (c : Code) : σ :=
Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (pr a) (co a) (pc a) (rf a)
Primrec fun a => F a (c a) :=
primrec_recOn' hc hz hs hl hr
(pr := fun a b => pr a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hpr)
(co := fun a b => co a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hco)
(pc := fun a b => pc a b.1 b.2.1 b.2.2.1 b.2.2.2) (.mk hpc)
(rf := fun a b => rf a b.1 b.2) (.mk hrf)
@[deprecated (since := "2025-05-12")] alias rec_prim := primrec_recOn
end Nat.Partrec.Code
end
namespace Nat.Partrec.Code
section
open Computable
/-- Recursion on `Nat.Partrec.Code` is computable. -/
theorem computable_recOn {α σ} [Primcodable α] [Primcodable σ] {c : α → Code} (hc : Computable c)
{z : α → σ} (hz : Computable z) {s : α → σ} (hs : Computable s) {l : α → σ} (hl : Computable l)
{r : α → σ} (hr : Computable r) {pr : α → Code × Code × σ × σ → σ} (hpr : Computable₂ pr)
{co : α → Code × Code × σ × σ → σ} (hco : Computable₂ co) {pc : α → Code × Code × σ × σ → σ}
(hpc : Computable₂ pc) {rf : α → Code × σ → σ} (hrf : Computable₂ rf) :
let PR (a) cf cg hf hg := pr a (cf, cg, hf, hg)
let CO (a) cf cg hf hg := co a (cf, cg, hf, hg)
let PC (a) cf cg hf hg := pc a (cf, cg, hf, hg)
let RF (a) cf hf := rf a (cf, hf)
let F (a : α) (c : Code) : σ :=
Nat.Partrec.Code.recOn c (z a) (s a) (l a) (r a) (PR a) (CO a) (PC a) (RF a)
Computable fun a => F a (c a) := by
-- TODO(Mario): less copy-paste from previous proof
intros _ _ _ _ F
let G₁ : (α × List σ) × ℕ × ℕ → Option σ := fun p =>
letI a := p.1.1; letI IH := p.1.2; letI n := p.2.1; letI m := p.2.2
IH[m]?.bind fun s =>
IH[m.unpair.1]?.bind fun s₁ =>
IH[m.unpair.2]?.map fun s₂ =>
cond n.bodd
(cond n.div2.bodd (rf a (ofNat Code m, s))
(pc a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)))
(cond n.div2.bodd (co a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂))
(pr a (ofNat Code m.unpair.1, ofNat Code m.unpair.2, s₁, s₂)))
have : Computable G₁ := by
refine option_bind (list_getElem?.comp (snd.comp fst) (snd.comp snd)) <| .mk ?_
refine option_bind ((list_getElem?.comp (snd.comp fst)
(fst.comp <| Computable.unpair.comp (snd.comp snd))).comp fst) <| .mk ?_
refine option_map ((list_getElem?.comp (snd.comp fst)
(snd.comp <| Computable.unpair.comp (snd.comp snd))).comp <| fst.comp fst) <| .mk ?_
exact
have a := fst.comp (fst.comp <| fst.comp <| fst.comp fst)
have n := fst.comp (snd.comp <| fst.comp <| fst.comp fst)
have m := snd.comp (snd.comp <| fst.comp <| fst.comp fst)
have m₁ := fst.comp (Computable.unpair.comp m)
have m₂ := snd.comp (Computable.unpair.comp m)
have s := snd.comp (fst.comp fst)
have s₁ := snd.comp fst
have s₂ := snd
(nat_bodd.comp n).cond
((nat_bodd.comp <| nat_div2.comp n).cond
(hrf.comp a (((Computable.ofNat Code).comp m).pair s))
(hpc.comp a (((Computable.ofNat Code).comp m₁).pair <|
((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂)))
(Computable.cond (nat_bodd.comp <| nat_div2.comp n)
(hco.comp a (((Computable.ofNat Code).comp m₁).pair <|
((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂))
(hpr.comp a (((Computable.ofNat Code).comp m₁).pair <|
((Computable.ofNat Code).comp m₂).pair <| s₁.pair s₂)))
let G : α → List σ → Option σ := fun a IH =>
IH.length.casesOn (some (z a)) fun n =>
n.casesOn (some (s a)) fun n =>
n.casesOn (some (l a)) fun n =>
n.casesOn (some (r a)) fun n =>
G₁ ((a, IH), n, n.div2.div2)
have : Computable₂ G := .mk <|
nat_casesOn (list_length.comp snd) (option_some_iff.2 (hz.comp fst)) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hs.comp (fst.comp fst))) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hl.comp (fst.comp <| fst.comp fst))) <| .mk <|
nat_casesOn snd (option_some_iff.2 (hr.comp (fst.comp <| fst.comp <| fst.comp fst))) <| .mk <|
this.comp <|
((fst.pair snd).comp <| fst.comp <| fst.comp <| fst.comp <| fst).pair <|
snd.pair <| nat_div2.comp <| nat_div2.comp snd
refine (nat_strong_rec (fun a n => F a (ofNat Code n)) this.to₂ fun a n => ?_)
|>.comp .id (encode_iff.2 hc) |>.of_eq fun a => by simp
iterate 4 rcases n with - | n; · simp [ofNatCode_eq, ofNatCode]; rfl
simp only [G]; rw [List.length_map, List.length_range]
let m := n.div2.div2
change G₁ ((a, (List.range (n + 4)).map fun n => F a (ofNat Code n)), n, m)
= some (F a (ofNat Code (n + 4)))
have hm : m < n + 4 := by
simp only [m, div2_val]
exact lt_of_le_of_lt
(le_trans (Nat.div_le_self ..) (Nat.div_le_self ..))
(Nat.succ_le_succ (Nat.le_add_right ..))
have m1 : m.unpair.1 < n + 4 := lt_of_le_of_lt m.unpair_left_le hm
have m2 : m.unpair.2 < n + 4 := lt_of_le_of_lt m.unpair_right_le hm
simp [G₁, m, hm, m1, m2]
rw [show ofNat Code (n + 4) = ofNatCode (n + 4) from rfl]
simp [ofNatCode]
cases n.bodd <;> cases n.div2.bodd <;> rfl
@[deprecated (since := "2025-05-12")] alias rec_computable := computable_recOn
end
/-- The interpretation of a `Nat.Partrec.Code` as a partial function.
* `Nat.Partrec.Code.zero`: The constant zero function.
* `Nat.Partrec.Code.succ`: The successor function.
* `Nat.Partrec.Code.left`: Left unpairing of a pair of ℕ (encoded by `Nat.pair`)
* `Nat.Partrec.Code.right`: Right unpairing of a pair of ℕ (encoded by `Nat.pair`)
* `Nat.Partrec.Code.pair`: Pairs the outputs of argument codes using `Nat.pair`.
* `Nat.Partrec.Code.comp`: Composition of two argument codes.
* `Nat.Partrec.Code.prec`: Primitive recursion. Given an argument of the form `Nat.pair a n`:
* If `n = 0`, returns `eval cf a`.
* If `n = succ k`, returns `eval cg (pair a (pair k (eval (prec cf cg) (pair a k))))`
* `Nat.Partrec.Code.rfind'`: Minimization. For `f` an argument of the form `Nat.pair a m`,
`rfind' f m` returns the least `a` such that `f a m = 0`, if one exists and `f b m` terminates
for `b < a`
-/
def eval : Code → ℕ →. ℕ
| zero => pure 0
| succ => Nat.succ
| left => ↑fun n : ℕ => n.unpair.1
| right => ↑fun n : ℕ => n.unpair.2
| pair cf cg => fun n => Nat.pair <$> eval cf n <*> eval cg n
| comp cf cg => fun n => eval cg n >>= eval cf
| prec cf cg =>
Nat.unpaired fun a n =>
n.rec (eval cf a) fun y IH => do
let i ← IH
eval cg (Nat.pair a (Nat.pair y i))
| rfind' cf =>
Nat.unpaired fun a m =>
(Nat.rfind fun n => (fun m => m = 0) <$> eval cf (Nat.pair a (n + m))).map (· + m)
/-- Helper lemma for the evaluation of `prec` in the base case. -/
@[simp]
theorem eval_prec_zero (cf cg : Code) (a : ℕ) : eval (prec cf cg) (Nat.pair a 0) = eval cf a := by
rw [eval, Nat.unpaired, Nat.unpair_pair]
simp (config := { Lean.Meta.Simp.neutralConfig with proj := true }) only []
rw [Nat.rec_zero]
/-- Helper lemma for the evaluation of `prec` in the recursive case. -/
theorem eval_prec_succ (cf cg : Code) (a k : ℕ) :
eval (prec cf cg) (Nat.pair a (Nat.succ k)) =
do {let ih ← eval (prec cf cg) (Nat.pair a k); eval cg (Nat.pair a (Nat.pair k ih))} := by
rw [eval, Nat.unpaired, Part.bind_eq_bind, Nat.unpair_pair]
simp
instance : Membership (ℕ →. ℕ) Code :=
⟨fun c f => eval c = f⟩
@[simp]
theorem eval_const : ∀ n m, eval (Code.const n) m = Part.some n
| 0, _ => rfl
| n + 1, m => by simp! [eval_const n m]
@[simp]
theorem eval_id (n) : eval Code.id n = Part.some n := by simp! [Seq.seq, Code.id]
@[simp]
theorem eval_curry (c n x) : eval (curry c n) x = eval c (Nat.pair n x) := by simp! [Seq.seq, curry]
theorem primrec_const : Primrec Code.const :=
(_root_.Primrec.id.nat_iterate (_root_.Primrec.const zero)
(primrec₂_comp.comp (_root_.Primrec.const succ) Primrec.snd).to₂).of_eq
fun n => by simp; induction n <;>
simp [*, Code.const, Function.iterate_succ', -Function.iterate_succ]
@[deprecated (since := "2025-05-12")] alias const_prim := primrec_const
theorem primrec₂_curry : Primrec₂ curry :=
primrec₂_comp.comp Primrec.fst <| primrec₂_pair.comp (primrec_const.comp Primrec.snd)
(_root_.Primrec.const Code.id)
@[deprecated (since := "2025-05-12")] alias curry_prim := primrec₂_curry
theorem curry_inj {c₁ c₂ n₁ n₂} (h : curry c₁ n₁ = curry c₂ n₂) : c₁ = c₂ ∧ n₁ = n₂ :=
⟨by injection h, by
injection h with h₁ h₂
injection h₂ with h₃ h₄
exact const_inj h₃⟩
/--
The $S_n^m$ theorem: There is a computable function, namely `Nat.Partrec.Code.curry`, that takes a
program and a ℕ `n`, and returns a new program using `n` as the first argument.
-/
theorem smn :
∃ f : Code → ℕ → Code, Computable₂ f ∧ ∀ c n x, eval (f c n) x = eval c (Nat.pair n x) :=
⟨curry, Primrec₂.to_comp primrec₂_curry, eval_curry⟩
/-- A function is partial recursive if and only if there is a code implementing it. Therefore,
`eval` is a **universal partial recursive function**. -/
theorem exists_code {f : ℕ →. ℕ} : Nat.Partrec f ↔ ∃ c : Code, eval c = f := by
refine ⟨fun h => ?_, ?_⟩
· induction h with
| zero => exact ⟨zero, rfl⟩
| succ => exact ⟨succ, rfl⟩
| left => exact ⟨left, rfl⟩
| right => exact ⟨right, rfl⟩
| pair pf pg hf hg =>
rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩
exact ⟨pair cf cg, rfl⟩
| comp pf pg hf hg =>
rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩
exact ⟨comp cf cg, rfl⟩
| prec pf pg hf hg =>
rcases hf with ⟨cf, rfl⟩; rcases hg with ⟨cg, rfl⟩
exact ⟨prec cf cg, rfl⟩
| rfind pf hf =>
rcases hf with ⟨cf, rfl⟩
refine ⟨comp (rfind' cf) (pair Code.id zero), ?_⟩
simp [eval, Seq.seq, pure, PFun.pure, Part.map_id']
· rintro ⟨c, rfl⟩
induction c with
| zero => exact Nat.Partrec.zero
| succ => exact Nat.Partrec.succ
| left => exact Nat.Partrec.left
| right => exact Nat.Partrec.right
| pair cf cg pf pg => exact pf.pair pg
| comp cf cg pf pg => exact pf.comp pg
| prec cf cg pf pg => exact pf.prec pg
| rfind' cf pf => exact pf.rfind'
/-- A modified evaluation for the code which returns an `Option ℕ` instead of a `Part ℕ`. To avoid
undecidability, `evaln` takes a parameter `k` and fails if it encounters a number ≥ k in the course
of its execution. Other than this, the semantics are the same as in `Nat.Partrec.Code.eval`.
-/
def evaln : ℕ → Code → ℕ → Option ℕ
| 0, _ => fun _ => Option.none
| k + 1, zero => fun n => do
guard (n ≤ k)
return 0
| k + 1, succ => fun n => do
guard (n ≤ k)
return (Nat.succ n)
| k + 1, left => fun n => do
guard (n ≤ k)
return n.unpair.1
| k + 1, right => fun n => do
guard (n ≤ k)
pure n.unpair.2
| k + 1, pair cf cg => fun n => do
guard (n ≤ k)
Nat.pair <$> evaln (k + 1) cf n <*> evaln (k + 1) cg n
| k + 1, comp cf cg => fun n => do
guard (n ≤ k)
let x ← evaln (k + 1) cg n
evaln (k + 1) cf x
| k + 1, prec cf cg => fun n => do
guard (n ≤ k)
n.unpaired fun a n =>
n.casesOn (evaln (k + 1) cf a) fun y => do
let i ← evaln k (prec cf cg) (Nat.pair a y)
evaln (k + 1) cg (Nat.pair a (Nat.pair y i))
| k + 1, rfind' cf => fun n => do
guard (n ≤ k)
n.unpaired fun a m => do
let x ← evaln (k + 1) cf (Nat.pair a m)
if x = 0 then
pure m
else
evaln k (rfind' cf) (Nat.pair a (m + 1))
theorem evaln_bound : ∀ {k c n x}, x ∈ evaln k c n → n < k
| 0, c, n, x, h => by simp [evaln] at h
| k + 1, c, n, x, h => by
suffices ∀ {o : Option ℕ}, x ∈ do { guard (n ≤ k); o } → n < k + 1 by
cases c <;> rw [evaln] at h <;> exact this h
simpa [Option.bind_eq_some_iff] using Nat.lt_succ_of_le
theorem evaln_mono : ∀ {k₁ k₂ c n x}, k₁ ≤ k₂ → x ∈ evaln k₁ c n → x ∈ evaln k₂ c n
| 0, k₂, c, n, x, _, h => by simp [evaln] at h
| k + 1, k₂ + 1, c, n, x, hl, h => by
have hl' := Nat.le_of_succ_le_succ hl
have :
∀ {k k₂ n x : ℕ} {o₁ o₂ : Option ℕ},
k ≤ k₂ → (x ∈ o₁ → x ∈ o₂) →
x ∈ do { guard (n ≤ k); o₁ } → x ∈ do { guard (n ≤ k₂); o₂ } := by
simp only [Option.mem_def, bind, Option.bind_eq_some_iff, Option.guard_eq_some',
exists_and_left, exists_const, and_imp]
introv h h₁ h₂ h₃
exact ⟨le_trans h₂ h, h₁ h₃⟩
simp? at h ⊢ says simp only [Option.mem_def] at h ⊢
induction c generalizing x n <;> rw [evaln] at h ⊢ <;> refine this hl' (fun h => ?_) h
iterate 4 exact h
case pair cf cg hf hg _ =>
simp? [Seq.seq, Option.bind_eq_some_iff] at h ⊢ says
simp only [Seq.seq, Option.map_eq_map, Option.mem_def, Option.bind_eq_some_iff,
Option.map_eq_some_iff, exists_exists_and_eq_and] at h ⊢
exact h.imp fun a => And.imp (hf _ _) <| Exists.imp fun b => And.imp_left (hg _ _)
case comp cf cg hf hg _ =>
simp? [Bind.bind, Option.bind_eq_some_iff] at h ⊢ says
simp only [bind, Option.mem_def, Option.bind_eq_some_iff] at h ⊢
exact h.imp fun a => And.imp (hg _ _) (hf _ _)
case prec cf cg hf hg _ =>
revert h
simp only [unpaired, bind, Option.mem_def]
induction n.unpair.2 <;> simp [Option.bind_eq_some_iff]
· apply hf
· exact fun y h₁ h₂ => ⟨y, evaln_mono hl' h₁, hg _ _ h₂⟩
case rfind' cf hf _ =>
simp? [Bind.bind, Option.bind_eq_some_iff] at h ⊢ says
simp only [unpaired, bind, pair_unpair, Option.pure_def, Option.mem_def,
Option.bind_eq_some_iff] at h ⊢
refine h.imp fun x => And.imp (hf _ _) ?_
by_cases x0 : x = 0 <;> simp [x0]
exact evaln_mono hl'
theorem evaln_sound : ∀ {k c n x}, x ∈ evaln k c n → x ∈ eval c n
| 0, _, n, x, h => by simp [evaln] at h
| k + 1, c, n, x, h => by
induction c generalizing x n <;> simp [eval, evaln, Option.bind_eq_some_iff, Seq.seq] at h ⊢ <;>
obtain ⟨_, h⟩ := h
iterate 4 simpa [pure, PFun.pure, eq_comm] using h
case pair cf cg hf hg _ =>
rcases h with ⟨y, ef, z, eg, rfl⟩
exact ⟨_, hf _ _ ef, _, hg _ _ eg, rfl⟩
case comp cf cg hf hg _ =>
rcases h with ⟨y, eg, ef⟩
exact ⟨_, hg _ _ eg, hf _ _ ef⟩
case prec cf cg hf hg _ =>
revert h
induction n.unpair.2 generalizing x with simp [Option.bind_eq_some_iff]
| zero => apply hf
| succ m IH =>
refine fun y h₁ h₂ => ⟨y, IH _ ?_, ?_⟩
· have := evaln_mono k.le_succ h₁
simp [evaln, Option.bind_eq_some_iff] at this
exact this.2
· exact hg _ _ h₂
case rfind' cf hf _ =>
rcases h with ⟨m, h₁, h₂⟩
by_cases m0 : m = 0 <;> simp [m0] at h₂
· exact
⟨0, ⟨by simpa [m0] using hf _ _ h₁, fun {m} => (Nat.not_lt_zero _).elim⟩, by simp [h₂]⟩
· have := evaln_sound h₂
simp [eval] at this
rcases this with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩
refine
⟨y + 1, ⟨by simpa [add_comm, add_left_comm] using hy₁, fun {i} im => ?_⟩, by
simp [add_comm, add_left_comm]⟩
rcases i with - | i
· exact ⟨m, by simpa using hf _ _ h₁, m0⟩
· rcases hy₂ (Nat.lt_of_succ_lt_succ im) with ⟨z, hz, z0⟩
exact ⟨z, by simpa [add_comm, add_left_comm] using hz, z0⟩
theorem evaln_complete {c n x} : x ∈ eval c n ↔ ∃ k, x ∈ evaln k c n := by
refine ⟨fun h => ?_, fun ⟨k, h⟩ => evaln_sound h⟩
rsuffices ⟨k, h⟩ : ∃ k, x ∈ evaln (k + 1) c n
· exact ⟨k + 1, h⟩
induction c generalizing n x with
simp [eval, evaln, pure, PFun.pure, Seq.seq, Option.bind_eq_some_iff] at h ⊢
| pair cf cg hf hg =>
rcases h with ⟨x, hx, y, hy, rfl⟩
rcases hf hx with ⟨k₁, hk₁⟩; rcases hg hy with ⟨k₂, hk₂⟩
refine ⟨max k₁ k₂, ?_⟩
refine
⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _,
evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁, _,
evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂, rfl⟩
| comp cf cg hf hg =>
rcases h with ⟨y, hy, hx⟩
rcases hg hy with ⟨k₁, hk₁⟩; rcases hf hx with ⟨k₂, hk₂⟩
refine ⟨max k₁ k₂, ?_⟩
exact
⟨le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁, _,
evaln_mono (Nat.succ_le_succ <| le_max_left _ _) hk₁,
evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂⟩
| prec cf cg hf hg =>
revert h
generalize n.unpair.1 = n₁; generalize n.unpair.2 = n₂
induction n₂ generalizing x n with simp [Option.bind_eq_some_iff]
| zero =>
intro h
rcases hf h with ⟨k, hk⟩
exact ⟨_, le_max_left _ _, evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk⟩
| succ m IH =>
intro y hy hx
rcases IH hy with ⟨k₁, nk₁, hk₁⟩
rcases hg hx with ⟨k₂, hk₂⟩
refine
⟨(max k₁ k₂).succ,
Nat.le_succ_of_le <| le_max_of_le_left <|
le_trans (le_max_left _ (Nat.pair n₁ m)) nk₁, y,
evaln_mono (Nat.succ_le_succ <| le_max_left _ _) ?_,
evaln_mono (Nat.succ_le_succ <| Nat.le_succ_of_le <| le_max_right _ _) hk₂⟩
simp only [evaln.eq_8, bind, unpaired, unpair_pair, Option.mem_def, Option.bind_eq_some_iff,
Option.guard_eq_some', exists_and_left, exists_const]
exact ⟨le_trans (le_max_right _ _) nk₁, hk₁⟩
| rfind' cf hf =>
rcases h with ⟨y, ⟨hy₁, hy₂⟩, rfl⟩
suffices ∃ k, y + n.unpair.2 ∈ evaln (k + 1) (rfind' cf) (Nat.pair n.unpair.1 n.unpair.2) by
simpa [evaln, Option.bind_eq_some_iff]
revert hy₁ hy₂
generalize n.unpair.2 = m
intro hy₁ hy₂
induction y generalizing m with simp [evaln, Option.bind_eq_some_iff]
| zero =>
simp at hy₁
rcases hf hy₁ with ⟨k, hk⟩
exact ⟨_, Nat.le_of_lt_succ <| evaln_bound hk, _, hk, by simp⟩
| succ y IH =>
rcases hy₂ (Nat.succ_pos _) with ⟨a, ha, a0⟩
rcases hf ha with ⟨k₁, hk₁⟩
rcases IH m.succ (by simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using hy₁)
fun {i} hi => by
simpa [Nat.succ_eq_add_one, add_comm, add_left_comm] using
hy₂ (Nat.succ_lt_succ hi) with
⟨k₂, hk₂⟩
use (max k₁ k₂).succ
rw [zero_add] at hk₁
use Nat.le_succ_of_le <| le_max_of_le_left <| Nat.le_of_lt_succ <| evaln_bound hk₁
use a
use evaln_mono (Nat.succ_le_succ <| Nat.le_succ_of_le <| le_max_left _ _) hk₁
simpa [a0, add_comm, add_left_comm] using
evaln_mono (Nat.succ_le_succ <| le_max_right _ _) hk₂
| _ => exact ⟨⟨_, le_rfl⟩, h.symm⟩
section
open Primrec
private def lup (L : List (List (Option ℕ))) (p : ℕ × Code) (n : ℕ) := do
let l ← L[encode p]?
let o ← l[n]?
o
private theorem hlup : Primrec fun p : _ × (_ × _) × _ => lup p.1 p.2.1 p.2.2 :=
Primrec.option_bind
(Primrec.list_getElem?.comp Primrec.fst (Primrec.encode.comp <| Primrec.fst.comp Primrec.snd))
(Primrec.option_bind (Primrec.list_getElem?.comp Primrec.snd <| Primrec.snd.comp <|
Primrec.snd.comp Primrec.fst) Primrec.snd)
private def G (L : List (List (Option ℕ))) : Option (List (Option ℕ)) :=
Option.some <|
let a := ofNat (ℕ × Code) L.length
let k := a.1
let c := a.2
(List.range k).map fun n =>
k.casesOn Option.none fun k' =>
Nat.Partrec.Code.recOn c
(some 0) -- zero
(some (Nat.succ n))
(some n.unpair.1)
(some n.unpair.2)
(fun cf cg _ _ => do
let x ← lup L (k, cf) n
let y ← lup L (k, cg) n
some (Nat.pair x y))
(fun cf cg _ _ => do
let x ← lup L (k, cg) n
lup L (k, cf) x)
(fun cf cg _ _ =>
let z := n.unpair.1
n.unpair.2.casesOn (lup L (k, cf) z) fun y => do
let i ← lup L (k', c) (Nat.pair z y)
lup L (k, cg) (Nat.pair z (Nat.pair y i)))
(fun cf _ =>
let z := n.unpair.1
let m := n.unpair.2
do
let x ← lup L (k, cf) (Nat.pair z m)
x.casesOn (some m) fun _ => lup L (k', c) (Nat.pair z (m + 1)))
private theorem hG : Primrec G := by
have a := (Primrec.ofNat (ℕ × Code)).comp (Primrec.list_length (α := List (Option ℕ)))
have k := Primrec.fst.comp a
refine Primrec.option_some.comp (Primrec.list_map (Primrec.list_range.comp k) (?_ : Primrec _))
replace k := k.comp (Primrec.fst (β := ℕ))
have n := Primrec.snd (α := List (List (Option ℕ))) (β := ℕ)
refine Primrec.nat_casesOn k (_root_.Primrec.const Option.none) (?_ : Primrec _)
have k := k.comp (Primrec.fst (β := ℕ))
have n := n.comp (Primrec.fst (β := ℕ))
have k' := Primrec.snd (α := List (List (Option ℕ)) × ℕ) (β := ℕ)
have c := Primrec.snd.comp (a.comp <| (Primrec.fst (β := ℕ)).comp (Primrec.fst (β := ℕ)))
apply
Nat.Partrec.Code.primrec_recOn c
(_root_.Primrec.const (some 0))
(Primrec.option_some.comp (_root_.Primrec.succ.comp n))
(Primrec.option_some.comp (Primrec.fst.comp <| Primrec.unpair.comp n))
(Primrec.option_some.comp (Primrec.snd.comp <| Primrec.unpair.comp n))
· have L := (Primrec.fst.comp Primrec.fst).comp
(Primrec.fst (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have k := k.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have n := n.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have cf := Primrec.fst.comp (Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have cg := (Primrec.fst.comp Primrec.snd).comp
(Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
refine Primrec.option_bind (hlup.comp <| L.pair <| (k.pair cf).pair n) ?_
unfold Primrec₂
conv =>
congr
· ext p
dsimp only []
erw [Option.bind_eq_bind, ← Option.map_eq_bind]
refine Primrec.option_map ((hlup.comp <| L.pair <| (k.pair cg).pair n).comp Primrec.fst) ?_
unfold Primrec₂
exact Primrec₂.natPair.comp (Primrec.snd.comp Primrec.fst) Primrec.snd
· have L := (Primrec.fst.comp Primrec.fst).comp
(Primrec.fst (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have k := k.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have n := n.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have cf := Primrec.fst.comp (Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have cg := (Primrec.fst.comp Primrec.snd).comp
(Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
refine Primrec.option_bind (hlup.comp <| L.pair <| (k.pair cg).pair n) ?_
unfold Primrec₂
have h :=
hlup.comp ((L.comp Primrec.fst).pair <| ((k.pair cf).comp Primrec.fst).pair Primrec.snd)
exact h
· have L := (Primrec.fst.comp Primrec.fst).comp
(Primrec.fst (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have k := k.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have n := n.comp (Primrec.fst (β := Code × Code × Option ℕ × Option ℕ))
have cf := Primrec.fst.comp (Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have cg := (Primrec.fst.comp Primrec.snd).comp
(Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Code × Option ℕ × Option ℕ))
have z := Primrec.fst.comp (Primrec.unpair.comp n)
refine
Primrec.nat_casesOn (Primrec.snd.comp (Primrec.unpair.comp n))
(hlup.comp <| L.pair <| (k.pair cf).pair z)
(?_ : Primrec _)
have L := L.comp (Primrec.fst (β := ℕ))
have z := z.comp (Primrec.fst (β := ℕ))
have y := Primrec.snd
(α := ((List (List (Option ℕ)) × ℕ) × ℕ) × Code × Code × Option ℕ × Option ℕ) (β := ℕ)
have h₁ := hlup.comp <| L.pair <| (((k'.pair c).comp Primrec.fst).comp Primrec.fst).pair
(Primrec₂.natPair.comp z y)
refine Primrec.option_bind h₁ (?_ : Primrec _)
have z := z.comp (Primrec.fst (β := ℕ))
have y := y.comp (Primrec.fst (β := ℕ))
have i := Primrec.snd
(α := (((List (List (Option ℕ)) × ℕ) × ℕ) × Code × Code × Option ℕ × Option ℕ) × ℕ)
(β := ℕ)
have h₂ := hlup.comp ((L.comp Primrec.fst).pair <|
((k.pair cg).comp <| Primrec.fst.comp Primrec.fst).pair <|
Primrec₂.natPair.comp z <| Primrec₂.natPair.comp y i)
exact h₂
· have L := (Primrec.fst.comp Primrec.fst).comp
(Primrec.fst (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Option ℕ))
have k := k.comp (Primrec.fst (β := Code × Option ℕ))
have n := n.comp (Primrec.fst (β := Code × Option ℕ))
have cf := Primrec.fst.comp (Primrec.snd (α := (List (List (Option ℕ)) × ℕ) × ℕ)
(β := Code × Option ℕ))
have z := Primrec.fst.comp (Primrec.unpair.comp n)
have m := Primrec.snd.comp (Primrec.unpair.comp n)
have h₁ := hlup.comp <| L.pair <| (k.pair cf).pair (Primrec₂.natPair.comp z m)
refine Primrec.option_bind h₁ (?_ : Primrec _)
have m := m.comp (Primrec.fst (β := ℕ))
refine Primrec.nat_casesOn Primrec.snd (Primrec.option_some.comp m) ?_
unfold Primrec₂
exact (hlup.comp ((L.comp Primrec.fst).pair <|
((k'.pair c).comp <| Primrec.fst.comp Primrec.fst).pair
(Primrec₂.natPair.comp (z.comp Primrec.fst) (_root_.Primrec.succ.comp m)))).comp
Primrec.fst
private theorem evaln_map (k c n) :
((List.range k)[n]?.bind fun a ↦ evaln k c a) = evaln k c n := by
by_cases kn : n < k
· simp [List.getElem?_range kn]
· rw [List.getElem?_eq_none]
· cases e : evaln k c n
· rfl
exact kn.elim (evaln_bound e)
simpa using kn
/-- The `Nat.Partrec.Code.evaln` function is primitive recursive. -/
theorem primrec_evaln : Primrec fun a : (ℕ × Code) × ℕ => evaln a.1.1 a.1.2 a.2 :=
have :
Primrec₂ fun (_ : Unit) (n : ℕ) =>
let a := ofNat (ℕ × Code) n
(List.range a.1).map (evaln a.1 a.2) :=
Primrec.nat_strong_rec _ (hG.comp Primrec.snd).to₂ fun _ p => by
simp only [G, prod_ofNat_val, ofNat_nat, List.length_map, List.length_range,
Nat.pair_unpair, Option.some_inj]
refine List.map_congr_left fun n => ?_
have : List.range p = List.range (Nat.pair p.unpair.1 (encode (ofNat Code p.unpair.2))) := by
simp
rw [this]
generalize p.unpair.1 = k
generalize ofNat Code p.unpair.2 = c
intro nk
rcases k with - | k'
· simp [evaln]
let k := k' + 1
simp only
simp? [Nat.lt_succ_iff] at nk says simp only [List.mem_range, Nat.lt_succ_iff] at nk
have hg :
∀ {k' c' n},
Nat.pair k' (encode c') < Nat.pair k (encode c) →
lup ((List.range (Nat.pair k (encode c))).map fun n =>
(List.range n.unpair.1).map (evaln n.unpair.1 (ofNat Code n.unpair.2))) (k', c') n =
evaln k' c' n := by
intro k₁ c₁ n₁ hl
simp [lup, List.getElem?_range hl, evaln_map, Bind.bind, Option.bind_map]
obtain - | - | - | - | ⟨cf, cg⟩ | ⟨cf, cg⟩ | ⟨cf, cg⟩ | cf := c <;>
simp [evaln, nk, Bind.bind, Functor.map, Seq.seq, pure]
· obtain ⟨lf, lg⟩ := encode_lt_pair cf cg
rw [hg (Nat.pair_lt_pair_right _ lf), hg (Nat.pair_lt_pair_right _ lg)]
cases evaln k cf n
· rfl
cases evaln k cg n <;> rfl
· obtain ⟨lf, lg⟩ := encode_lt_comp cf cg
rw [hg (Nat.pair_lt_pair_right _ lg)]
cases evaln k cg n
· rfl
simp [k, hg (Nat.pair_lt_pair_right _ lf)]
· obtain ⟨lf, lg⟩ := encode_lt_prec cf cg
rw [hg (Nat.pair_lt_pair_right _ lf)]
cases n.unpair.2
· rfl
simp only
rw [hg (Nat.pair_lt_pair_left _ k'.lt_succ_self)]
cases evaln k' _ _
· rfl
simp [k, hg (Nat.pair_lt_pair_right _ lg)]
· have lf := encode_lt_rfind' cf
rw [hg (Nat.pair_lt_pair_right _ lf)]
rcases evaln k cf n with - | x
· rfl
simp only [Option.bind_some]
cases x <;> simp
rw [hg (Nat.pair_lt_pair_left _ k'.lt_succ_self)]
(Primrec.option_bind
(Primrec.list_getElem?.comp (this.comp (_root_.Primrec.const ())
(Primrec.encode_iff.2 Primrec.fst)) Primrec.snd) Primrec.snd.to₂).of_eq
fun ⟨⟨k, c⟩, n⟩ => by simp [evaln_map, Option.bind_map]
@[deprecated (since := "2025-05-12")] alias evaln_prim := primrec_evaln
end
section
open Partrec Computable
theorem eval_eq_rfindOpt (c n) : eval c n = Nat.rfindOpt fun k => evaln k c n :=
Part.ext fun x => by
refine evaln_complete.trans (Nat.rfindOpt_mono ?_).symm
intro a m n hl; apply evaln_mono hl
theorem eval_part : Partrec₂ eval :=
(Partrec.rfindOpt
(primrec_evaln.to_comp.comp
((Computable.snd.pair (fst.comp fst)).pair (snd.comp fst))).to₂).of_eq
fun a => by simp [eval_eq_rfindOpt]
/-- **Roger's fixed-point theorem**: any total, computable `f` has a fixed point.
That is, under the interpretation given by `Nat.Partrec.Code.eval`, there is a code `c`
such that `c` and `f c` have the same evaluation.
-/
theorem fixed_point {f : Code → Code} (hf : Computable f) : ∃ c : Code, eval (f c) = eval c :=
let g (x y : ℕ) : Part ℕ := eval (ofNat Code x) x >>= fun b => eval (ofNat Code b) y
have : Partrec₂ g :=
(eval_part.comp ((Computable.ofNat _).comp fst) fst).bind
(eval_part.comp ((Computable.ofNat _).comp snd) (snd.comp fst)).to₂
let ⟨cg, eg⟩ := exists_code.1 this
have eg' : ∀ a n, eval cg (Nat.pair a n) = Part.map encode (g a n) := by simp [eg]
let F (x : ℕ) : Code := f (curry cg x)
have : Computable F :=
hf.comp (primrec₂_curry.comp (_root_.Primrec.const cg) _root_.Primrec.id).to_comp
let ⟨cF, eF⟩ := exists_code.1 this
have eF' : eval cF (encode cF) = Part.some (encode (F (encode cF))) := by simp [eF]
⟨curry cg (encode cF),
funext fun n =>
show eval (f (curry cg (encode cF))) n = eval (curry cg (encode cF)) n by
simp [F, g, eg', eF', Part.map_id']⟩
/-- **Kleene's second recursion theorem** -/
theorem fixed_point₂ {f : Code → ℕ →. ℕ} (hf : Partrec₂ f) : ∃ c : Code, eval c = f c :=
let ⟨cf, ef⟩ := exists_code.1 hf
(fixed_point (primrec₂_curry.comp (_root_.Primrec.const cf) Primrec.encode).to_comp).imp
fun c e => funext fun n => by simp [e.symm, ef, Part.map_id']
end
/-- There are only countably many partial recursive partial functions `ℕ →. ℕ`. -/
instance : Countable {f : ℕ →. ℕ // _root_.Partrec f} := by
apply Function.Surjective.countable (f := fun c => ⟨eval c, eval_part.comp (.const c) .id⟩)
intro ⟨f, hf⟩; simpa using exists_code.1 hf
/-- There are only countably many computable functions `ℕ → ℕ`. -/
instance : Countable {f : ℕ → ℕ // Computable f} :=
@Function.Injective.countable {f : ℕ → ℕ // Computable f} {f : ℕ →. ℕ // _root_.Partrec f} _
(fun f => ⟨f.val, f.2⟩)
(fun _ _ h => Subtype.val_inj.1 (PFun.lift_injective (by simpa using h)))
end Nat.Partrec.Code
|
Parity.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Iván Renison
-/
import Mathlib.Algebra.Ring.Parity
import Mathlib.Data.Fin.Basic
import Mathlib.Data.ZMod.Defs
/-!
# Parity in `Fin n`
In this file we prove that an element `k : Fin n` is even in `Fin n`
iff `n` is odd or `Fin.val k` is even.
We also prove a lemma about parity of `Fin.succAbove i j + Fin.predAbove j i`
which can be used to prove `d ∘ d = 0` for de Rham cohomologies.
-/
open Fin
namespace Fin
open Fin.CommRing
variable {n : ℕ} {k : Fin n}
theorem even_succAbove_add_predAbove (i : Fin (n + 1)) (j : Fin n) :
Even (i.succAbove j + j.predAbove i : ℕ) ↔ Odd (i + j : ℕ) := by
rcases lt_or_ge j.castSucc i with hji | hij
· have : 1 ≤ (i : ℕ) := (Nat.zero_le j).trans_lt hji
simp [succAbove_of_castSucc_lt _ _ hji, predAbove_of_castSucc_lt _ _ hji, this, iff_comm,
parity_simps]
· simp [succAbove_of_le_castSucc _ _ hij, predAbove_of_le_castSucc _ _ hij,
← Nat.not_even_iff_odd, not_iff, not_iff_comm, parity_simps]
lemma neg_one_pow_succAbove_add_predAbove {R : Type*} [Monoid R] [HasDistribNeg R]
(i : Fin (n + 1)) (j : Fin n) :
(-1 : R) ^ (i.succAbove j + j.predAbove i : ℕ) = -(-1) ^ (i + j : ℕ) := by
rw [← neg_one_mul (_ ^ _), ← pow_succ', neg_one_pow_congr]
rw [even_succAbove_add_predAbove, Nat.even_add_one, Nat.not_even_iff_odd]
lemma even_of_val (h : Even k.val) : Even k := by
have : NeZero n := ⟨k.pos.ne'⟩
rw [← Fin.cast_val_eq_self k]
exact h.natCast
lemma odd_of_val [NeZero n] (h : Odd k.val) : Odd k := by
rw [← Fin.cast_val_eq_self k]
exact h.natCast
lemma even_of_odd (hn : Odd n) (k : Fin n) : Even k := by
have : NeZero n := ⟨k.pos.ne'⟩
rcases k.val.even_or_odd with hk | hk
· exact even_of_val hk
· simpa using (hk.add_odd hn).natCast (α := Fin n)
lemma odd_of_odd [NeZero n] (hn : Odd n) (k : Fin n) : Odd k := by
rcases k.val.even_or_odd with hk | hk
· simpa using (Even.add_odd hk hn).natCast (R := Fin n)
· exact odd_of_val hk
lemma even_iff_of_even (hn : Even n) : Even k ↔ Even k.val := by
rcases hn with ⟨n, rfl⟩
refine ⟨?_, even_of_val⟩
rintro ⟨l, rfl⟩
rw [val_add_eq_ite]
split_ifs with h <;> simp [Nat.even_sub, *]
lemma odd_iff_of_even [NeZero n] (hn : Even n) : Odd k ↔ Odd k.val := by
rcases hn with ⟨n, rfl⟩
refine ⟨?_, odd_of_val⟩
rintro ⟨l, rfl⟩
rw [val_add, val_mul, coe_ofNat_eq_mod, coe_ofNat_eq_mod]
simp only [Nat.mod_mul_mod, Nat.add_mod_mod, Nat.mod_add_mod, Nat.odd_iff]
rw [Nat.mod_mod_of_dvd _ ⟨n, (two_mul n).symm⟩, ← Nat.odd_iff, Nat.odd_add_one,
Nat.not_odd_iff_even]
simp
/-- In `Fin n`, all elements are even for odd `n`,
otherwise an element is even iff its `Fin.val` value is even. -/
lemma even_iff : Even k ↔ (Odd n ∨ Even k.val) := by
refine ⟨fun hk ↦ ?_, or_imp.mpr ⟨(even_of_odd · k), even_of_val⟩⟩
rw [← Nat.not_even_iff_odd, ← imp_iff_not_or]
exact fun hn ↦ (even_iff_of_even hn).mp hk
lemma even_iff_imp : Even k ↔ (Even n → Even k.val) := by
rw [imp_iff_not_or, Nat.not_even_iff_odd]
exact even_iff
/-- In `Fin n`, all elements are odd for odd `n`,
otherwise an element is odd iff its `Fin.val` value is odd. -/
lemma odd_iff [NeZero n] : Odd k ↔ Odd n ∨ Odd k.val := by
refine ⟨fun hk ↦ ?_, or_imp.mpr ⟨(odd_of_odd · k), odd_of_val⟩⟩
rw [← Nat.not_even_iff_odd, ← imp_iff_not_or]
exact fun hn ↦ (odd_iff_of_even hn).mp hk
lemma odd_iff_imp [NeZero n] : Odd k ↔ (Even n → Odd k.val) := by
rw [imp_iff_not_or, Nat.not_even_iff_odd]
exact odd_iff
lemma even_iff_mod_of_even (hn : Even n) : Even k ↔ k.val % 2 = 0 := by
rw [even_iff_of_even hn]
exact Nat.even_iff
lemma odd_iff_mod_of_even [NeZero n] (hn : Even n) : Odd k ↔ k.val % 2 = 1 := by
rw [odd_iff_of_even hn]
exact Nat.odd_iff
lemma not_odd_iff_even_of_even [NeZero n] (hn : Even n) : ¬Odd k ↔ Even k := by
rw [even_iff_of_even hn, odd_iff_of_even hn]
exact Nat.not_odd_iff_even
lemma not_even_iff_odd_of_even [NeZero n] (hn : Even n) : ¬Even k ↔ Odd k := by
rw [even_iff_of_even hn, odd_iff_of_even hn]
exact Nat.not_even_iff_odd
lemma odd_add_one_iff_even [NeZero n] : Odd (k + 1) ↔ Even k :=
⟨fun ⟨k, hk⟩ ↦ add_right_cancel hk ▸ even_two_mul k, Even.add_one⟩
lemma even_add_one_iff_odd [NeZero n] : Even (k + 1) ↔ Odd k :=
⟨fun ⟨k, hk⟩ ↦ eq_sub_iff_add_eq.mpr hk ▸ (Even.add_self k).sub_odd odd_one, Odd.add_one⟩
end Fin
|
Limits.lean
|
/-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Sites.Sheafification
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
/-!
# Limits and colimits of sheaves
## Limits
We prove that the forgetful functor from `Sheaf J D` to presheaves creates limits.
If the target category `D` has limits (of a certain shape),
this then implies that `Sheaf J D` has limits of the same shape and that the forgetful
functor preserves these limits.
## Colimits
Given a diagram `F : K ⥤ Sheaf J D` of sheaves, and a colimit cocone on the level of presheaves,
we show that the cocone obtained by sheafifying the cocone point is a colimit cocone of sheaves.
This allows us to show that `Sheaf J D` has colimits (of a certain shape) as soon as `D` does.
-/
namespace CategoryTheory
namespace Sheaf
open CategoryTheory.Limits
open Opposite
universe w w' v u z z' u₁ u₂
variable {C : Type u} [Category.{v} C] {J : GrothendieckTopology C}
variable {D : Type w} [Category.{w'} D]
variable {K : Type z} [Category.{z'} K]
section Limits
noncomputable section
section
/-- An auxiliary definition to be used below.
Whenever `E` is a cone of shape `K` of sheaves, and `S` is the multifork associated to a
covering `W` of an object `X`, with respect to the cone point `E.X`, this provides a cone of
shape `K` of objects in `D`, with cone point `S.X`.
See `isLimitMultiforkOfIsLimit` for more on how this definition is used.
-/
def multiforkEvaluationCone (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D)) (X : C)
(W : J.Cover X) (S : Multifork (W.index E.pt)) :
Cone (F ⋙ sheafToPresheaf J D ⋙ (evaluation Cᵒᵖ D).obj (op X)) where
pt := S.pt
π :=
{ app := fun k => (Presheaf.isLimitOfIsSheaf J (F.obj k).1 W (F.obj k).2).lift <|
Multifork.ofι _ S.pt (fun i => S.ι i ≫ (E.π.app k).app (op i.Y))
(by
intro i
simp only [Category.assoc]
erw [← (E.π.app k).naturality, ← (E.π.app k).naturality]
dsimp
simp only [← Category.assoc]
congr 1
apply S.condition)
naturality := by
intro i j f
dsimp [Presheaf.isLimitOfIsSheaf]
rw [Category.id_comp]
apply Presheaf.IsSheaf.hom_ext (F.obj j).2 W
intro ii
rw [Presheaf.IsSheaf.amalgamate_map, Category.assoc, ← (F.map f).val.naturality, ←
Category.assoc, Presheaf.IsSheaf.amalgamate_map]
dsimp [Multifork.ofι]
erw [Category.assoc, ← E.w f]
cat_disch }
variable [HasLimitsOfShape K D]
/-- If `E` is a cone of shape `K` of sheaves, which is a limit on the level of presheaves,
this definition shows that the limit presheaf satisfies the multifork variant of the sheaf
condition, at a given covering `W`.
This is used below in `isSheaf_of_isLimit` to show that the limit presheaf is indeed a sheaf.
-/
def isLimitMultiforkOfIsLimit (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D))
(hE : IsLimit E) (X : C) (W : J.Cover X) : IsLimit (W.multifork E.pt) :=
Multifork.IsLimit.mk _
(fun S => (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).lift <|
multiforkEvaluationCone F E X W S)
(by
intro S i
apply (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op i.Y)) hE).hom_ext
intro k
dsimp [Multifork.ofι]
erw [Category.assoc, (E.π.app k).naturality]
dsimp
rw [← Category.assoc]
erw [(isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).fac
(multiforkEvaluationCone F E X W S)]
dsimp [multiforkEvaluationCone, Presheaf.isLimitOfIsSheaf]
rw [Presheaf.IsSheaf.amalgamate_map]
rfl)
(by
intro S m hm
apply (isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).hom_ext
intro k
dsimp
erw [(isLimitOfPreserves ((evaluation Cᵒᵖ D).obj (op X)) hE).fac]
apply Presheaf.IsSheaf.hom_ext (F.obj k).2 W
intro i
dsimp only [multiforkEvaluationCone, Presheaf.isLimitOfIsSheaf]
rw [(F.obj k).cond.amalgamate_map]
dsimp [Multifork.ofι]
change _ = S.ι i ≫ _
erw [← hm, Category.assoc, ← (E.π.app k).naturality, Category.assoc]
rfl)
/-- If `E` is a cone which is a limit on the level of presheaves,
then the limit presheaf is again a sheaf.
This is used to show that the forgetful functor from sheaves to presheaves creates limits.
-/
theorem isSheaf_of_isLimit (F : K ⥤ Sheaf J D) (E : Cone (F ⋙ sheafToPresheaf J D))
(hE : IsLimit E) : Presheaf.IsSheaf J E.pt := by
rw [Presheaf.isSheaf_iff_multifork]
intro X S
exact ⟨isLimitMultiforkOfIsLimit _ _ hE _ _⟩
instance (F : K ⥤ Sheaf J D) : CreatesLimit F (sheafToPresheaf J D) :=
createsLimitOfReflectsIso fun E hE =>
{ liftedCone := ⟨⟨E.pt, isSheaf_of_isLimit _ _ hE⟩,
⟨fun _ => ⟨E.π.app _⟩, fun _ _ _ => Sheaf.Hom.ext <| E.π.naturality _⟩⟩
validLift := Cones.ext (eqToIso rfl) fun j => by simp
makesLimit :=
{ lift := fun S => ⟨hE.lift ((sheafToPresheaf J D).mapCone S)⟩
fac := fun S j => by
ext1
apply hE.fac ((sheafToPresheaf J D).mapCone S) j
uniq := fun S m hm => by
ext1
exact hE.uniq ((sheafToPresheaf J D).mapCone S) m.val fun j =>
congr_arg Hom.val (hm j) } }
instance createsLimitsOfShape : CreatesLimitsOfShape K (sheafToPresheaf J D) where
instance : HasLimitsOfShape K (Sheaf J D) :=
hasLimitsOfShape_of_hasLimitsOfShape_createsLimitsOfShape (sheafToPresheaf J D)
instance [HasFiniteProducts D] : HasFiniteProducts (Sheaf J D) :=
⟨inferInstance⟩
instance [HasFiniteLimits D] : HasFiniteLimits (Sheaf J D) :=
⟨fun _ ↦ inferInstance⟩
end
instance createsLimits [HasLimitsOfSize.{u₁, u₂} D] :
CreatesLimitsOfSize.{u₁, u₂} (sheafToPresheaf J D) :=
⟨createsLimitsOfShape⟩
instance hasLimitsOfSize [HasLimitsOfSize.{u₁, u₂} D] : HasLimitsOfSize.{u₁, u₂} (Sheaf J D) :=
hasLimits_of_hasLimits_createsLimits (sheafToPresheaf J D)
variable {D : Type w} [Category.{max v u} D]
example [HasLimits D] : HasLimits (Sheaf J D) := inferInstance
end
end Limits
section Colimits
variable [HasWeakSheafify J D]
/-- Construct a cocone by sheafifying a cocone point of a cocone `E` of presheaves
over a functor which factors through sheaves.
In `isColimitSheafifyCocone`, we show that this is a colimit cocone when `E` is a colimit. -/
noncomputable def sheafifyCocone {F : K ⥤ Sheaf J D}
(E : Cocone (F ⋙ sheafToPresheaf J D)) : Cocone F :=
(Cocones.precompose
(Functor.isoWhiskerLeft F (asIso (sheafificationAdjunction J D).counit).symm).hom).obj
((presheafToSheaf J D).mapCocone E)
/-- If `E` is a colimit cocone of presheaves, over a diagram factoring through sheaves,
then `sheafifyCocone E` is a colimit cocone. -/
noncomputable def isColimitSheafifyCocone {F : K ⥤ Sheaf J D}
(E : Cocone (F ⋙ sheafToPresheaf J D)) (hE : IsColimit E) : IsColimit (sheafifyCocone E) :=
(IsColimit.precomposeHomEquiv _ ((presheafToSheaf J D).mapCocone E)).symm
(isColimitOfPreserves _ hE)
instance [HasColimitsOfShape K D] : HasColimitsOfShape K (Sheaf J D) :=
⟨fun _ => HasColimit.mk
⟨sheafifyCocone (colimit.cocone _), isColimitSheafifyCocone _ (colimit.isColimit _)⟩⟩
instance [HasFiniteCoproducts D] : HasFiniteCoproducts (Sheaf J D) :=
⟨inferInstance⟩
instance [HasFiniteColimits D] : HasFiniteColimits (Sheaf J D) :=
⟨fun _ ↦ inferInstance⟩
instance [HasColimitsOfSize.{u₁, u₂} D] : HasColimitsOfSize.{u₁, u₂} (Sheaf J D) :=
⟨inferInstance⟩
/--
If every cocone on a diagram of sheaves which is a colimit on the level of presheaves satisfies
the condition that the cocone point is a sheaf, then the functor from sheaves to presheaves
creates colimits of the diagram.
Note: this almost never holds in sheaf categories in general, but it does for the extensive
topology (see `Mathlib/CategoryTheory/Sites/Coherent/ExtensiveColimits.lean`).
-/
def createsColimitOfIsSheaf (F : K ⥤ Sheaf J D)
(h : ∀ (c : Cocone (F ⋙ sheafToPresheaf J D)) (_ : IsColimit c), Presheaf.IsSheaf J c.pt) :
CreatesColimit F (sheafToPresheaf J D) :=
createsColimitOfReflectsIso fun E hE =>
{ liftedCocone := ⟨⟨E.pt, h _ hE⟩,
⟨fun _ => ⟨E.ι.app _⟩, fun _ _ _ => Sheaf.Hom.ext <| E.ι.naturality _⟩⟩
validLift := Cocones.ext (eqToIso rfl) fun j => by simp
makesColimit :=
{ desc := fun S => ⟨hE.desc ((sheafToPresheaf J D).mapCocone S)⟩
fac := fun S j => by ext1; dsimp; rw [hE.fac]; rfl
uniq := fun S m hm => by
ext1
exact hE.uniq ((sheafToPresheaf J D).mapCocone S) m.val fun j =>
congr_arg Hom.val (hm j) } }
variable {D : Type w} [Category.{max v u} D]
example [HasLimits D] : HasLimits (Sheaf J D) := inferInstance
end Colimits
end Sheaf
end CategoryTheory
|
ssralg.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 div seq.
From mathcomp Require Import choice fintype finfun bigop prime binomial.
From mathcomp Require Export nmodule.
(******************************************************************************)
(* Ring-like structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* Reference: Francois Garillot, Georges Gonthier, Assia Mahboubi, Laurence *)
(* Rideau, Packaging mathematical structures, TPHOLs 2009 *)
(* *)
(* This file defines the following algebraic structures: *)
(* *)
(* semiPzRingType == non-commutative semi rings *)
(* (NModule with a multiplication) *)
(* The HB class is called PzSemiRing. *)
(* nzSemiRingType == non-commutative non-trivial semi rings *)
(* (NModule with a multiplication) *)
(* The HB class is called NzSemiRing. *)
(* comPzSemiRingType == commutative semi rings *)
(* The HB class is called ComPzSemiRing. *)
(* comNzSemiRingType == commutative non-trivial semi rings *)
(* The HB class is called ComNzSemiRing. *)
(* pzRingType == non-commutative rings *)
(* (semi rings with an opposite) *)
(* The HB class is called PzRing. *)
(* nzRingType == non-commutative non-trivial rings *)
(* (semi rings with an opposite) *)
(* The HB class is called NzRing. *)
(* comPzRingType == commutative rings *)
(* The HB class is called ComPzRing. *)
(* comNzRingType == commutative non-trivial rings *)
(* The HB class is called ComNzRing. *)
(* lSemiModType R == semimodule with left multiplication by external scalars *)
(* in the semiring R *)
(* The HB class is called LSemiModule. *)
(* lmodType R == module with left multiplication by external scalars *)
(* in the pzRing R *)
(* The HB class is called Lmodule. *)
(* lSemiAlgType R == left semialgebra, semiring with scaling that associates *)
(* on the left *)
(* The HB class is called LSemiAlgebra. *)
(* lalgType R == left algebra, ring with scaling that associates on the *)
(* left *)
(* The HB class is called Lalgebra. *)
(* semiAlgType R == semialgebra, semiring with scaling that associates both *)
(* left and right *)
(* The HB class is called SemiAlgebra. *)
(* algType R == algebra, ring with scaling that associates both left *)
(* and right *)
(* The HB class is called Algebra. *)
(*comSemiAlgType R == commutative semiAlgType *)
(* The HB class is called ComSemiAlgebra. *)
(* comAlgType R == commutative algType *)
(* The HB class is called ComAlgebra. *)
(* unitRingType == Rings whose units have computable inverses *)
(* The HB class is called UnitRing. *)
(* comUnitRingType == commutative UnitRing *)
(* The HB class is called ComUnitRing. *)
(* unitAlgType R == algebra with computable inverses *)
(* The HB class is called UnitAlgebra. *)
(*comUnitAlgType R == commutative UnitAlgebra *)
(* The HB class is called ComUnitAlgebra. *)
(* idomainType == integral, commutative, ring with partial inverses *)
(* The HB class is called IntegralDomain. *)
(* fieldType == commutative fields *)
(* The HB class is called Field. *)
(* decFieldType == fields with a decidable first order theory *)
(* The HB class is called DecidableField. *)
(* closedFieldType == algebraically closed fields *)
(* The HB class is called ClosedField. *)
(* *)
(* and their joins with subType: *)
(* *)
(* subPzSemiRingType R P == join of pzSemiRingType and *)
(* subType (P : pred R) such that val is a *)
(* semiring morphism *)
(* The HB class is called SubPzSemiRing. *)
(* subNzSemiRingType R P == join of nzSemiRingType and *)
(* subType (P : pred R) such that val is a *)
(* semiring morphism *)
(* The HB class is called SubNzSemiRing. *)
(*subComPzSemiRingType R P == join of comPzSemiRingType and *)
(* subType (P : pred R) such that val is a morphism*)
(* The HB class is called SubComPzSemiRing. *)
(*subComNzSemiRingType R P == join of comNzSemiRingType and *)
(* subType (P : pred R) such that val is a morphism*)
(* The HB class is called SubComNzSemiRing. *)
(* subPzRingType R P == join of pzRingType and subType (P : pred R) *)
(* such that val is a morphism *)
(* The HB class is called SubPzRing. *)
(* subComPzRingType R P == join of comPzRingType and subType (P : pred R) *)
(* such that val is a morphism *)
(* The HB class is called SubComPzRing. *)
(* subNzRingType R P == join of nzRingType and subType (P : pred R) *)
(* such that val is a morphism *)
(* The HB class is called SubNzRing. *)
(* subComNzRingType R P == join of comNzRingType and subType (P : pred R) *)
(* such that val is a morphism *)
(* The HB class is called SubComNzRing. *)
(* subLSemiModType R V P == join of lSemiModType and subType (P : pred V) *)
(* such that val is scalable *)
(* The HB class is called SubLSemiModule. *)
(* subLmodType R V P == join of lmodType and subType (P : pred V) *)
(* such that val is scalable *)
(* The HB class is called SubLmodule. *)
(* subLSemiAlgType R V P == join of lSemiAlgType and subType (P : pred V) *)
(* such that val is linear *)
(* The HB class is called SubLSemiAlgebra. *)
(* subLalgType R V P == join of lalgType and subType (P : pred V) *)
(* such that val is linear *)
(* The HB class is called SubLalgebra. *)
(* subSemiAlgType R V P == join of semiAlgType and subType (P : pred V) *)
(* such that val is linear *)
(* The HB class is called SubSemiAlgebra. *)
(* subAlgType R V P == join of algType and subType (P : pred V) *)
(* such that val is linear *)
(* The HB class is called SubAlgebra. *)
(* subUnitRingType R P == join of unitRingType and subType (P : pred R) *)
(* such that val is a ring morphism *)
(* The HB class is called SubUnitRing. *)
(* subComUnitRingType R P == join of comUnitRingType and subType (P : pred R)*)
(* such that val is a ring morphism *)
(* The HB class is called SubComUnitRing. *)
(* subIdomainType R P == join of idomainType and subType (P : pred R) *)
(* such that val is a ring morphism *)
(* The HB class is called SubIntegralDomain. *)
(* subField R P == join of fieldType and subType (P : pred R) *)
(* such that val is a ring morphism *)
(* The HB class is called SubField. *)
(* *)
(* Morphisms between the above structures (see below for details): *)
(* *)
(* {rmorphism R -> S} == semi ring (resp. ring) morphism between *)
(* semiPzRingType (resp. pzRingType) instances *)
(* R and S. *)
(* The HB class is called RMorphism. *)
(* {linear U -> V | s} == semilinear (resp. linear) functions of type *)
(* U -> V, where U is a left semimodule (resp. *)
(* left module) over semiring (resp. ring) R, V is *)
(* an N-module (resp. Z-module), and s is a scaling*)
(* operator (detailed below) of type R -> V -> V. *)
(* The HB class is called Linear. *)
(* {lrmorphism A -> B | s} == semialgebra (resp. algebra) morphisms of type *)
(* A -> B, where A is a left semialgebra *)
(* (resp. left algebra) over semiring (resp. ring) *)
(* R, B is an semiring (resp. ring), and s is a *)
(* scaling operator (detailed below) of type *)
(* R -> B -> B. *)
(* The HB class is called LRMorphism. *)
(* *)
(* -> The scaling operator s above should be one of *:%R, *%R, or a *)
(* combination nu \; *:%R or nu \; *%R with a semiring morphism nu; *)
(* otherwise some of the theory (e.g., the linearZ rule) will not apply. *)
(* To enable the overloading of the scaling operator, we use the following *)
(* structures: *)
(* *)
(* GRing.Scale.preLaw R V == scaling morphisms of type R -> V -> V *)
(* The HB class is called Scale.PreLaw. *)
(* GRing.Scale.semiLaw R V == scaling morphisms of type R -> V -> V *)
(* The HB class is called Scale.SemiLaw. *)
(* GRing.Scale.law R V == scaling morphisms of type R -> V -> V *)
(* The HB class is called Scale.Law. *)
(* *)
(* Closedness predicates for the algebraic structures: *)
(* *)
(* addrClosed V == predicate closed under addition on V : nmodType *)
(* The HB class is called AddClosed. *)
(* opprClosed V == predicate closed under opposite on V : zmodType *)
(* The HB class is called OppClosed. *)
(* zmodClosed V == predicate closed under opposite and addition on V *)
(* The HB class is called ZmodClosed. *)
(* mulr2Closed R == predicate closed under multiplication on *)
(* R : semiPzRingType *)
(* The HB class is called Mul2Closed. *)
(* mulrClosed R == predicate closed under multiplication and for 1 *)
(* The HB class is called MulClosed. *)
(* semiring2Closed R == predicate closed under addition and multiplication *)
(* The HB class is called Semiring2Closed. *)
(* semiringClosed R == predicate closed under semiring operations *)
(* The HB class is called SemiringClosed. *)
(* smulClosed R == predicate closed under multiplication and for -1 *)
(* The HB class is called SmulClosed. *)
(* subringClosed R == predicate closed under ring operations *)
(* The HB class is called SubringClosed. *)
(* divClosed R == predicate closed under division *)
(* The HB class is called DivClosed. *)
(* sdivClosed R == predicate closed under division and opposite *)
(* The HB class is called SdivClosed. *)
(* submodClosed R == predicate closed under lSemiModType operations *)
(* The HB class is called SubmodClosed. *)
(* subalgClosed R == predicate closed under lSemiAlgType operations *)
(* The HB class is called SubalgClosed. *)
(* divringClosed R == predicate closed under unitRing operations *)
(* The HB class is called DivringClosed. *)
(* divalgClosed R S == predicate closed under (S : unitAlg R) operations *)
(* The HB class is called DivalgClosed. *)
(* *)
(* The rpred* lemmas ensure that the set S remains stable under the specified *)
(* operations, provided the corresponding closedness predicate is satisfied. *)
(* This stability is crucial for constructing and reasoning about *)
(* substructures within algebraic hierarchies. For example: *)
(* *)
(* - rpred0: Concludes 0 \in S if S is addrClosed. *)
(* - rpredD: Concludes x + y \in S if x \in S and y \in S and S is addrClosed.*)
(* - rpredN: Concludes -x \in S if x \in S and S is opprClosed. *)
(* - rpredZ: Concludes a *: v \in S if v \in S and S is scalerClosed. *)
(* *)
(* Canonical properties of the algebraic structures: *)
(* * Nmodule (additive abelian monoids): *)
(* 0 == the zero (additive identity) of a Nmodule *)
(* x + y == the sum of x and y (in a Nmodule) *)
(* x *+ n == n times x, with n in nat (non-negative), i.e., *)
(* x + (x + .. (x + x)..) (n terms); x *+ 1 is thus *)
(* convertible to x, and x *+ 2 to x + x *)
(* \sum_<range> e == iterated sum for a Nmodule (cf bigop.v) *)
(* e`_i == nth 0 e i, when e : seq M and M has a nmodType *)
(* structure *)
(* support f == 0.-support f, i.e., [pred x | f x != 0] *)
(* addr_closed S <-> collective predicate S is closed under finite *)
(* sums (0 and x + y in S, for x, y in S) *)
(* [SubChoice_isSubNmodule of U by <:] == nmodType mixin for a subType whose *)
(* base type is a nmodType and whose predicate's is *)
(* an addrClosed *)
(* *)
(* * Zmodule (additive abelian groups): *)
(* - x == the opposite (additive inverse) of x *)
(* x - y == the difference of x and y; this is only notation *)
(* for x + (- y) *)
(* x *- n == notation for - (x *+ n), the opposite of x *+ n *)
(* oppr_closed S <-> collective predicate S is closed under opposite *)
(* zmod_closed S <-> collective predicate S is closed under zmodType *)
(* operations (0 and x - y in S, for x, y in S) *)
(* This property coerces to oppr_pred and addr_pred. *)
(* [SubChoice_isSubZmodule of U by <:] == zmodType mixin for a subType whose *)
(* base type is a zmodType and whose predicate's *)
(* is a zmodClosed *)
(* *)
(* * PzSemiRing (non-commutative semirings): *)
(* R^c == the converse (semi)ring for R: R^c is convertible*)
(* to R but when R has a canonical (semi)ring *)
(* structure R^c has the converse one: *)
(* if x y : R^c, then x * y = (y : R) * (x : R) *)
(* 1 == the multiplicative identity element of a semiring*)
(* n%:R == the semiring image of an n in nat; this is just *)
(* notation for 1 *+ n, so 1%:R is convertible to 1 *)
(* and 2%:R to 1 + 1 *)
(* <number> == <number>%:R with <number> a sequence of digits *)
(* x * y == the semiring product of x and y *)
(* \prod_<range> e == iterated product for a semiring (cf bigop.v) *)
(* x ^+ n == x to the nth power with n in nat (non-negative), *)
(* i.e., x * (x * .. (x * x)..) (n factors); x ^+ 1 *)
(* is thus convertible to x, and x ^+ 2 to x * x *)
(* GRing.comm x y <-> x and y commute, i.e., x * y = y * x *)
(* GRing.lreg x <-> x if left-regular, i.e., *%R x is injective *)
(* GRing.rreg x <-> x if right-regular, i.e., *%R^~ x is injective *)
(* [pchar R] == the characteristic of R, defined as the set of *)
(* prime numbers p such that p%:R = 0 in R *)
(* The set [pchar R] has at most one element, and is*)
(* implemented as a pred_nat collective predicate *)
(* (see prime.v); thus the statement p \in [pchar R]*)
(* can be read as `R has characteristic p', while *)
(* [pchar R] =i pred0 means `R has characteristic 0'*)
(* when R is a field. *)
(* pFrobenius_aut chRp == the Frobenius automorphism mapping x in R to *)
(* x ^+ p, where chRp : p \in [pchar R] is a proof *)
(* that R has (non-zero) characteristic p *)
(* mulr_closed S <-> collective predicate S is closed under finite *)
(* products (1 and x * y in S for x, y in S) *)
(* semiring_closed S <-> collective predicate S is closed under semiring *)
(* operations (0, 1, x + y and x * y in S) *)
(* [SubNmodule_isSubPzSemiRing of R by <:] == *)
(* [SubChoice_isSubPzSemiRing of R by <:] == semiPzRingType mixin for a *)
(* subType whose base type is a pzSemiRingType and *)
(* whose predicate's is a semiringClosed *)
(* *)
(* * NzSemiRing (non-commutative non-trivial semirings): *)
(* [SubNmodule_isSubNzSemiRing of R by <:] == *)
(* [SubChoice_isSubNzSemiRing of R by <:] == semiNzRingType mixin for a *)
(* subType whose base type is a nzSemiRingType and *)
(* whose predicate's is a semiringClosed *)
(* *)
(* * PzRing (non-commutative rings): *)
(* GRing.sign R b := (-1) ^+ b in R : pzRingType, with b : bool *)
(* This is a parsing-only helper notation, to be *)
(* used for defining more specific instances. *)
(* smulr_closed S <-> collective predicate S is closed under products *)
(* and opposite (-1 and x * y in S for x, y in S) *)
(* subring_closed S <-> collective predicate S is closed under ring *)
(* operations (1, x - y and x * y in S) *)
(* [SubZmodule_isSubPzRing of R by <:] == *)
(* [SubChoice_isSubPzRing of R by <:] == pzRingType mixin for a subType whose *)
(* base *)
(* type is a pzRingType and whose predicate's is a *)
(* subringClosed *)
(* *)
(* * NzRing (non-commutative non-trivial rings): *)
(* [SubZmodule_isSubNzRing of R by <:] == *)
(* [SubChoice_isSubNzRing of R by <:] == nzRingType mixin for a subType whose *)
(* base *)
(* type is a nzRingType and whose predicate's is a *)
(* subringClosed *)
(* *)
(* * ComPzSemiRing (commutative PzSemiRings): *)
(* [SubNmodule_isSubComPzSemiRing of R by <:] == *)
(* [SubChoice_isSubComPzSemiRing of R by <:] == comPzSemiRingType mixin for a *)
(* subType whose base type is a comPzSemiRingType *)
(* and whose predicate's is a semiringClosed *)
(* *)
(* * ComNzSemiRing (commutative NzSemiRings): *)
(* [SubNmodule_isSubComNzSemiRing of R by <:] == *)
(* [SubChoice_isSubComNzSemiRing of R by <:] == comNzSemiRingType mixin for a *)
(* subType whose base type is a comNzSemiRingType *)
(* and whose predicate's is a semiringClosed *)
(* *)
(* * ComPzRing (commutative PzRings): *)
(* [SubZmodule_isSubComPzRing of R by <:] == *)
(* [SubChoice_isSubComPzRing of R by <:] == comPzRingType mixin for a *)
(* subType whose base type is a comPzRingType and *)
(* whose predicate's is a subringClosed *)
(* *)
(* * ComNzRing (commutative NzRings): *)
(* [SubZmodule_isSubComNzRing of R by <:] == *)
(* [SubChoice_isSubComNzRing of R by <:] == comNzRingType mixin for a *)
(* subType whose base type is a comNzRingType and *)
(* whose predicate's is a subringClosed *)
(* *)
(* * UnitRing (NzRings whose units have computable inverses): *)
(* x \is a GRing.unit <=> x is a unit (i.e., has an inverse) *)
(* x^-1 == the ring inverse of x, if x is a unit, else x *)
(* x / y == x divided by y (notation for x * y^-1) *)
(* x ^- n := notation for (x ^+ n)^-1, the inverse of x ^+ n *)
(* invr_closed S <-> collective predicate S is closed under inverse *)
(* divr_closed S <-> collective predicate S is closed under division *)
(* (1 and x / y in S) *)
(* sdivr_closed S <-> collective predicate S is closed under division *)
(* and opposite (-1 and x / y in S, for x, y in S) *)
(* divring_closed S <-> collective predicate S is closed under unitRing *)
(* operations (1, x - y and x / y in S) *)
(* [SubNzRing_isSubUnitRing of R by <:] == *)
(* [SubChoice_isSubUnitRing of R by <:] == unitRingType mixin for a subType *)
(* whose base type is a unitRingType and whose *)
(* predicate's is a divringClosed and whose ring *)
(* structure is compatible with the base type's *)
(* *)
(* * ComUnitRing (commutative rings with computable inverses): *)
(* [SubChoice_isSubComUnitRing of R by <:] == comUnitRingType mixin for a *)
(* subType whose base type is a comUnitRingType and *)
(* whose predicate's is a divringClosed and whose *)
(* ring structure is compatible with the base *)
(* type's *)
(* *)
(* * IntegralDomain (integral, commutative, ring with partial inverses): *)
(* [SubComUnitRing_isSubIntegralDomain R by <:] == *)
(* [SubChoice_isSubIntegralDomain R by <:] == mixin axiom for a idomain *)
(* subType *)
(* *)
(* * Field (commutative fields): *)
(* GRing.Field.axiom inv == field axiom: x != 0 -> inv x * x = 1 for all x *)
(* This is equivalent to the property above, but *)
(* does not require a unitRingType as inv is an *)
(* explicit argument. *)
(* [SubIntegralDomain_isSubField of R by <:] == mixin axiom for a field *)
(* subType *)
(* *)
(* * DecidableField (fields with a decidable first order theory): *)
(* GRing.term R == the type of formal expressions in a unit ring R *)
(* with formal variables 'X_k, k : nat, and *)
(* manifest constants x%:T, x : R *)
(* The notation of all the ring operations is *)
(* redefined for terms, in scope %T. *)
(* GRing.formula R == the type of first order formulas over R; the %T *)
(* scope binds the logical connectives /\, \/, ~, *)
(* ==>, ==, and != to formulae; GRing.True/False *)
(* and GRing.Bool b denote constant formulae, and *)
(* quantifiers are written 'forall/'exists 'X_k, f *)
(* GRing.Unit x tests for ring units *)
(* GRing.If p_f t_f e_f emulates if-then-else *)
(* GRing.Pick p_f t_f e_f emulates fintype.pick *)
(* foldr GRing.Exists/Forall q_f xs can be used *)
(* to write iterated quantifiers *)
(* GRing.eval e t == the value of term t with valuation e : seq R *)
(* (e maps 'X_i to e`_i) *)
(* GRing.same_env e1 e2 <-> environments e1 and e2 are extensionally equal *)
(* GRing.qf_form f == f is quantifier-free *)
(* GRing.holds e f == the intuitionistic CiC interpretation of the *)
(* formula f holds with valuation e *)
(* GRing.qf_eval e f == the value (in bool) of a quantifier-free f *)
(* GRing.sat e f == valuation e satisfies f (only in a decField) *)
(* GRing.sol n f == a sequence e of size n such that e satisfies f, *)
(* if one exists, or [::] if there is no such e *)
(* 'exists 'X_i, u1 == 0 /\ ... /\ u_m == 0 /\ v1 != 0 ... /\ v_n != 0 *)
(* *)
(* * LSemiModule (semimodule with left multiplication by external scalars). *)
(* a *: v == v scaled by a, when v is in an LSemiModule V and *)
(* a is in the scalar semiring of V *)
(* scaler_closed S <-> collective predicate S is closed under scaling *)
(* subsemimod_closed S <-> collective predicate S is closed under *)
(* lSemiModType operations (0, +%R, and *:%R) *)
(* [SubNmodule_isSubLSemiModule of V by <:] == *)
(* [SubChoice_isSubLSemiModule of V by <:] == mixin axiom for a subType of an *)
(* lSemiModType *)
(* *)
(* * Lmodule (module with left multiplication by external scalars). *)
(* linear_closed S <-> collective predicate S is closed under linear *)
(* combinations (a *: u + v in S when u, v in S) *)
(* submod_closed S <-> collective predicate S is closed under lmodType *)
(* operations (0 and a *: u + v in S) *)
(* [SubZmodule_isSubLmodule of V by <:] == *)
(* [SubChoice_isSubLmodule of V by <:] == mixin axiom for a subType of an *)
(* lmodType *)
(* *)
(* * LSemiAlgebra *)
(* (left semialgebra, semiring with scaling that associates on the left): *)
(* R^o == the regular (semi)algebra of R: R^o is *)
(* convertible to R, but when R has a *)
(* nz(Semi)RingType structure then R^o extends it *)
(* to an l(Semi)AlgType structure by letting R act *)
(* on itself: if x : R and y : R^o then *)
(* x *: y = x * (y : R) *)
(* k%:A == the image of the scalar k in a left semialgebra; *)
(* this is simply notation for k *: 1 *)
(* [SubSemiRing_SubLSemiModule_isSubLSemiAlgebra of V by <:] *)
(* == mixin axiom for a subType of an lSemiAlgType *)
(* *)
(* * Lalgebra (left algebra, ring with scaling that associates on the left): *)
(* subalg_closed S <-> collective predicate S is closed under lalgType *)
(* operations (1, a *: u + v and u * v in S) *)
(* [SubNzRing_SubLmodule_isSubLalgebra of V by <:] == *)
(* [SubChoice_isSubLalgebra of V by <:] == mixin axiom for a subType of an *)
(* lalgType *)
(* *)
(* * SemiAlgebra (semiring with scaling that associates both left and right):*)
(* [SubLSemiAlgebra_isSubSemiAlgebra of V by <:] == *)
(* == mixin axiom for a subType of an semiAlgType *)
(* *)
(* * Algebra (ring with scaling that associates both left and right): *)
(* [SubLalgebra_isSubAlgebra of V by <:] == *)
(* [SubChoice_isSubAlgebra of V by <:] == mixin axiom for a subType of an *)
(* algType *)
(* *)
(* * UnitAlgebra (algebra with computable inverses): *)
(* divalg_closed S <-> collective predicate S is closed under all *)
(* unitAlgType operations (1, a *: u + v and u / v *)
(* are in S fo u, v in S) *)
(* *)
(* In addition to this structure hierarchy, we also develop a separate, *)
(* parallel hierarchy for morphisms linking these structures: *)
(* *)
(* * RMorphism (semiring or ring morphisms): *)
(* monoid_morphism f <-> f of type R -> S is a multiplicative monoid *)
(* morphism, i.e., f maps 1 and * in R to 1 and * *)
(* in S, respectively. R and S must have canonical *)
(* pzSemiRingType instances. *)
(* {rmorphism R -> S} == the interface type for semiring morphisms; both *)
(* R and S must have pzSemiRingType instances *)
(* When both R and S have pzRingType instances, it *)
(* is a ring morphism. *)
(* := GRing.RMorphism.type R S *)
(* *)
(* -> If R and S are UnitRings the f also maps units to units and inverses *)
(* of units to inverses; if R is a field then f is a field isomorphism *)
(* between R and its image. *)
(* -> Additive properties (raddf_suffix, see below) are duplicated and *)
(* specialised for RMorphism (as rmorph_suffix). This allows more *)
(* precise rewriting and cleaner chaining: although raddf lemmas will *)
(* recognize RMorphism functions, the converse will not hold (we cannot *)
(* add reverse inheritance rules because of incomplete backtracking in *)
(* the Canonical Projection unification), so one would have to insert a *)
(* /= every time one switched from additive to multiplicative rules. *)
(* *)
(* * Linear (semilinear or linear functions): *)
(* scalable_for s f <-> f of type U -> V is scalable for the scaling *)
(* operator s of type R -> V -> V, i.e., *)
(* f morphs a *: _ to s a _; R, U, and V must be a *)
(* pzSemiRingType, an lSemiModType R, and an *)
(* nmodType, respectively. *)
(* := forall a, {morph f : u / a *: u >-> s a u} *)
(* scalable f <-> f of type U -> V is scalable, i.e., f morphs *)
(* scaling on U to scaling on V, a *: _ to a *: _; *)
(* U and V must be lSemiModType R for the same *)
(* pzSemiRingType R. *)
(* := scalable_for *:%R f *)
(* semilinear_for s f <-> f of type U -> V is semilinear for s of type *)
(* R -> V -> V , i.e., f morphs a *: _ and addition *)
(* on U to s a _ and addition on V, respectively; *)
(* R, U, and V must be a pzSemiRingType, an *)
(* lSemiModType R and an nmodType, respectively. *)
(* := scalable_for s f * {morph f : x y / x + y} *)
(* semilinear f <-> f of type U -> V is semilinear, i.e., f morphs *)
(* scaling and addition on U to scaling and *)
(* addition on V, respectively; U and V must be *)
(* lSemiModType R for the same pzSemiRingType R. *)
(* := semilinear_for *:% f *)
(* semiscalar f <-> f of type U -> R is a semiscalar function, *)
(* i.e., f morphs scaling and addition on U to *)
(* multiplication and addition on R; R and U must *)
(* be a pzSemiRingType and an lSemiModType R, *)
(* respectively. *)
(* := semilinear_for *%R f *)
(* linear_for s f <-> f of type U -> V is linear for s of type *)
(* R -> V -> V, i.e., *)
(* f (a *: u + v) = s a (f u) + f v; *)
(* R, U, and V must be a pzRingType, an lmodType R, *)
(* and a zmodType, respectively. *)
(* linear f <-> f of type U -> V is linear, i.e., *)
(* f (f *: u + v) = a *: f u + f v; *)
(* U and V must be lmodType R for the same *)
(* pzRingType R. *)
(* := linear_for *:%R f *)
(* scalar f <-> f of type U -> R is a scalar function, i.e., *)
(* f (a *: u + v) = a * f u + f v; *)
(* R and U must be a pzRingType and an lmodType R, *)
(* respectively. *)
(* := linear_for *%R f *)
(* {linear U -> V | s} == the interface type for functions (semi)linear *)
(* for the scaling operator s of type R -> V -> V, *)
(* i.e., a structure that encapsulates two *)
(* properties semi_additive f and scalable_for s f *)
(* for functions f : U -> V; R, U, and V must be a *)
(* pzSemiRingType, an lSemiModType R, and an *)
(* nmodType, respectively. *)
(* {linear U -> V} == the interface type for (semi)linear functions, *)
(* of type U -> V where both U and V must be *)
(* lSemiModType R for the same pzSemiRingType R *)
(* := {linear U -> V | *:%R} *)
(* {scalar U} == the interface type for (semi)scalar functions, *)
(* of type U -> R where U must be an lSemiModType R *)
(* := {linear U -> R | *%R} *)
(* (a *: u)%Rlin == transient forms that simplify to a *: u, a * u, *)
(* (a * u)%Rlin nu a *: u, and nu a * u, respectively, and are *)
(* (a *:^nu u)%Rlin created by rewriting with the linearZ lemma *)
(* (a *^nu u)%Rlin The forms allows the RHS of linearZ to be matched*)
(* reliably, using the GRing.Scale.law structure. *)
(* -> Similarly to semiring morphisms, semiadditive properties are *)
(* specialized for semilinear functions. *)
(* -> Although {scalar U} is convertible to {linear U -> R^o}, it does not *)
(* actually use R^o, so that rewriting preserves the canonical structure *)
(* of the range of scalar functions. *)
(* -> The generic linearZ lemma uses a set of bespoke interface structures to *)
(* ensure that both left-to-right and right-to-left rewriting work even in *)
(* the presence of scaling functions that simplify non-trivially (e.g., *)
(* idfun \; *%R). Because most of the canonical instances and projections *)
(* are coercions the machinery will be mostly invisible (with only the *)
(* {linear ...} structure and %Rlin notations showing), but users should *)
(* beware that in (a *: f u)%Rlin, a actually occurs in the f u subterm. *)
(* -> The simpler linear_LR, or more specialized linearZZ and scalarZ rules *)
(* should be used instead of linearZ if there are complexity issues, as *)
(* well as for explicit forward and backward application, as the main *)
(* parameter of linearZ is a proper sub-interface of {linear U -> V | s}. *)
(* *)
(* * LRMorphism (semialgebra or algebra morphisms): *)
(* {lrmorphism A -> B | s} == the interface type for semiring (resp. ring) *)
(* morphisms semilinear (resp. linear) for the *)
(* scaling operator s of type R -> B -> B, i.e., *)
(* the join of semiring (resp. ring) morphisms *)
(* {rmorphism A -> B} and semilinear (resp. linear) *)
(* functions {linear A -> B | s}; R, A, and B must *)
(* be a pzSemiRingType (resp. pzRingType), an *)
(* lSemiAlgType R (resp. lalgType R), and a *)
(* pzSemiRingType (resp. pzRingType), respectively *)
(* {lrmorphism A -> B} == the interface type for semialgebra (resp. *)
(* algebra) morphisms, where A and B must be *)
(* lSemiAlgType R (resp. lalgType R) for the same *)
(* pzSemiRingType (resp. pzRingType) R *)
(* := {lrmorphism A -> B | *:%R} *)
(* -> Linear and rmorphism properties do not need to be specialized for *)
(* as we supply inheritance join instances in both directions. *)
(* Finally we supply some helper notation for morphisms: *)
(* x^f == the image of x under some morphism *)
(* This notation is only reserved (not defined) *)
(* here; it is bound locally in sections where some *)
(* morphism is used heavily (e.g., the container *)
(* morphism in the parametricity sections of poly *)
(* and matrix, or the Frobenius section here) *)
(* \0 == the constant null function, which has a *)
(* canonical linear structure, and simplifies on *)
(* application (see ssrfun.v) *)
(* f \+ g == the additive composition of f and g, i.e., the *)
(* function x |-> f x + g x; f \+ g is canonically *)
(* linear when f and g are, and simplifies on *)
(* application (see ssrfun.v) *)
(* f \- g == the function x |-> f x - g x, canonically *)
(* linear when f and g are, and simplifies on *)
(* application *)
(* \- g == the function x |-> - f x, canonically linear *)
(* when f is, and simplifies on application *)
(* k \*: f == the function x |-> k *: f x, which is *)
(* canonically linear when f is and simplifies on *)
(* application (this is a shorter alternative to *)
(* *:%R k \o f) *)
(* GRing.in_alg A == the ring morphism that injects R into A, where A *)
(* has an lalgType R structure; GRing.in_alg A k *)
(* simplifies to k%:A *)
(* a \*o f == the function x |-> a * f x, canonically linear *)
(* when f is and its codomain is an algType *)
(* and which simplifies on application *)
(* a \o* f == the function x |-> f x * a, canonically linear *)
(* when f is and its codomain is an lalgType *)
(* and which simplifies on application *)
(* f \* g == the function x |-> f x * g x; f \* g *)
(* simplifies on application *)
(* The Lemmas about these structures are contained in both the GRing module *)
(* and in the submodule GRing.Theory, which can be imported when unqualified *)
(* access to the theory is needed (GRing.Theory also allows the unqualified *)
(* use of additive, linear, Linear, etc). The main GRing module should NOT be *)
(* imported. *)
(* Notations are defined in scope ring_scope (delimiter %R), except term *)
(* and formula notations, which are in term_scope (delimiter %T). *)
(* This library also extends the conventional suffixes described in library *)
(* ssrbool.v with the following: *)
(* 0 -- ring 0, as in addr0 : x + 0 = x *)
(* 1 -- ring 1, as in mulr1 : x * 1 = x *)
(* D -- ring addition, as in linearD : f (u + v) = f u + f v *)
(* B -- ring subtraction, as in opprB : - (x - y) = y - x *)
(* M -- ring multiplication, as in invfM : (x * y)^-1 = x^-1 * y^-1 *)
(* Mn -- ring by nat multiplication, as in raddfMn : f (x *+ n) = f x *+ n *)
(* N -- ring opposite, as in mulNr : (- x) * y = - (x * y) *)
(* V -- ring inverse, as in mulVr : x^-1 * x = 1 *)
(* X -- ring exponentiation, as in rmorphXn : f (x ^+ n) = f x ^+ n *)
(* Z -- (left) module scaling, as in linearZ : f (a *: v) = s *: f v *)
(* The operator suffixes D, B, M and X are also used for the corresponding *)
(* operations on nat, as in natrX : (m ^ n)%:R = m%:R ^+ n. For the binary *)
(* power operator, a trailing "n" suffix is used to indicate the operator *)
(* suffix applies to the left-hand ring argument, as in *)
(* expr1n : 1 ^+ n = 1 vs. expr1 : x ^+ 1 = x. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope ring_scope.
Declare Scope term_scope.
Declare Scope linear_ring_scope.
Reserved Notation "+%R".
Reserved Notation "-%R".
Reserved Notation "*%R" (format " *%R").
Reserved Notation "*:%R" (format " *:%R").
Reserved Notation "n %:R" (left associativity, format "n %:R").
Reserved Notation "k %:A" (left associativity, format "k %:A").
Reserved Notation "[ 'pchar' F ]" (format "[ 'pchar' F ]").
Reserved Notation "[ 'char' F ]" (format "[ 'char' F ]").
Reserved Notation "x %:T" (left associativity, format "x %:T").
Reserved Notation "''X_' i" (at level 8, i at level 2, format "''X_' i").
(* Patch for recurring Coq parser bug: Coq seg faults when a level 200 *)
(* notation is used as a pattern. *)
Reserved Notation "''exists' ''X_' i , f"
(at level 199, i at level 2, right associativity,
format "'[hv' ''exists' ''X_' i , '/ ' f ']'").
Reserved Notation "''forall' ''X_' i , f"
(at level 199, i at level 2, right associativity,
format "'[hv' ''forall' ''X_' i , '/ ' f ']'").
Reserved Notation "x ^f" (left associativity, format "x ^f").
Reserved Notation "\0".
Reserved Notation "f \+ g" (at level 50, left associativity).
Reserved Notation "f \- g" (at level 50, left associativity).
Reserved Notation "\- f" (at level 35, f at level 35).
Reserved Notation "a \*o f" (at level 40).
Reserved Notation "a \o* f" (at level 40).
Reserved Notation "a \*: f" (at level 40).
Reserved Notation "f \* g" (at level 40, left associativity).
Reserved Notation "'{' 'additive' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'additive' U -> V }").
Reserved Notation "'{' 'rmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'rmorphism' U -> V }").
Reserved Notation "'{' 'lrmorphism' U '->' V '|' s '}'"
(U at level 98, V at level 99, format "{ 'lrmorphism' U -> V | s }").
Reserved Notation "'{' 'lrmorphism' U '->' V '}'"
(U at level 98, V at level 99, format "{ 'lrmorphism' U -> V }").
Reserved Notation "'{' 'linear' U '->' V '|' s '}'"
(U at level 98, V at level 99, format "{ 'linear' U -> V | s }").
Reserved Notation "'{' 'linear' U '->' V '}'"
(U at level 98, V at level 99,
format "{ 'linear' U -> V }").
Reserved Notation "'{' 'scalar' U '}'" (format "{ 'scalar' U }").
Reserved Notation "R ^c" (format "R ^c").
Reserved Notation "R ^o" (format "R ^o").
Declare Scope ring_scope.
Delimit Scope ring_scope with R.
Declare Scope term_scope.
Delimit Scope term_scope with T.
Local Open Scope ring_scope.
Module Export Dummy.
Module GRing := Algebra.
End Dummy.
Module Import GRing.
Export Algebra.
Import Monoid.Theory.
Local Notation "0" := (@zero _) : ring_scope.
Local Notation "+%R" := (@add _) : function_scope.
Local Notation "x + y" := (add x y) : ring_scope.
Local Notation "x *+ n" := (natmul x n) : ring_scope.
Local Notation "\sum_ ( i <- r | P ) F" := (\big[+%R/0]_(i <- r | P) F).
Local Notation "\sum_ ( m <= i < n ) F" := (\big[+%R/0]_(m <= i < n) F).
Local Notation "\sum_ ( i < n ) F" := (\big[+%R/0]_(i < n) F).
Local Notation "\sum_ ( i 'in' A ) F" := (\big[+%R/0]_(i in A) F).
Local Notation "s `_ i" := (nth 0 s i) : ring_scope.
Section NmoduleTheory.
Variable V : nmodType.
Implicit Types x y : V.
Lemma addrA : associative (@add V).
Proof. exact: addrA. Qed.
Lemma addrC : commutative (@add V).
Proof. exact: addrC. Qed.
Lemma add0r : left_id (@zero V) add.
Proof. exact: add0r. Qed.
Lemma addr0 : right_id (@zero V) add.
Proof. exact: addr0. Qed.
Lemma addrCA : @left_commutative V V +%R. Proof. exact: addrCA. Qed.
Lemma addrAC : @right_commutative V V +%R. Proof. exact: addrAC. Qed.
Lemma addrACA : @interchange V +%R +%R. Proof. exact: addrACA. Qed.
Lemma mulr0n x : x *+ 0 = 0. Proof. exact: mulr0n. Qed.
Lemma mulr1n x : x *+ 1 = x. Proof. exact: mulr1n. Qed.
Lemma mulr2n x : x *+ 2 = x + x. Proof. exact: mulr2n. Qed.
Lemma mulrS x n : x *+ n.+1 = x + (x *+ n). Proof. exact: mulrS. Qed.
Lemma mulrSr x n : x *+ n.+1 = x *+ n + x. Proof. exact: mulrSr. Qed.
Lemma mulrb x (b : bool) : x *+ b = (if b then x else 0).
Proof. exact: mulrb. Qed.
Lemma mul0rn n : 0 *+ n = 0 :> V. Proof. exact: mul0rn. Qed.
Lemma mulrnDl n : {morph (fun x => x *+ n) : x y / x + y}.
Proof. exact: mulrnDl. Qed.
Lemma mulrnDr x m n : x *+ (m + n) = x *+ m + x *+ n.
Proof. exact: mulrnDr. Qed.
Lemma mulrnA x m n : x *+ (m * n) = x *+ m *+ n. Proof. exact: mulrnA. Qed.
Lemma mulrnAC x m n : x *+ m *+ n = x *+ n *+ m. Proof. exact: mulrnAC. Qed.
Lemma iter_addr n x y : iter n (+%R x) y = x *+ n + y.
Proof. exact: iter_addr. Qed.
Lemma iter_addr_0 n x : iter n (+%R x) 0 = x *+ n.
Proof. exact: iter_addr_0. Qed.
Lemma sumrMnl I r P (F : I -> V) n :
\sum_(i <- r | P i) F i *+ n = (\sum_(i <- r | P i) F i) *+ n.
Proof. exact: sumrMnl. Qed.
Lemma sumrMnr x I r P (F : I -> nat) :
\sum_(i <- r | P i) x *+ F i = x *+ (\sum_(i <- r | P i) F i).
Proof. exact: sumrMnr. Qed.
Lemma sumr_const (I : finType) (A : pred I) x : \sum_(i in A) x = x *+ #|A|.
Proof. exact: sumr_const. Qed.
Lemma sumr_const_nat m n x : \sum_(n <= i < m) x = x *+ (m - n).
Proof. exact: sumr_const_nat. Qed.
#[deprecated(since="mathcomp 2.4.0",
note="Use Algebra.nmod_closed instead.")]
Definition addr_closed := nmod_closed.
End NmoduleTheory.
Local Notation "-%R" := (@opp _) : ring_scope.
Local Notation "- x" := (opp x) : ring_scope.
Local Notation "x - y" := (x + - y) : ring_scope.
Local Notation "x *- n" := (- (x *+ n)) : ring_scope.
Section ZmoduleTheory.
Variable V : zmodType.
Implicit Types x y : V.
Lemma addNr : @left_inverse V V V 0 -%R +%R. Proof. exact: addNr. Qed.
Lemma addrN : @right_inverse V V V 0 -%R +%R. Proof. exact: addrN. Qed.
Definition subrr := addrN.
Lemma addKr : @left_loop V V -%R +%R. Proof. exact: addKr. Qed.
Lemma addNKr : @rev_left_loop V V -%R +%R. Proof. exact: addNKr. Qed.
Lemma addrK : @right_loop V V -%R +%R. Proof. exact: addrK. Qed.
Lemma addrNK : @rev_right_loop V V -%R +%R. Proof. exact: addrNK. Qed.
Definition subrK := addrNK.
Lemma subrKC x y : x + (y - x) = y. Proof. by rewrite addrC subrK. Qed.
Lemma subKr x : involutive (fun y => x - y). Proof. exact: subKr. Qed.
Lemma addrI : @right_injective V V V +%R. Proof. exact: addrI. Qed.
Lemma addIr : @left_injective V V V +%R. Proof. exact: addIr. Qed.
Lemma subrI : right_injective (fun x y => x - y). Proof. exact: subrI. Qed.
Lemma subIr : left_injective (fun x y => x - y). Proof. exact: subIr. Qed.
Lemma opprK : @involutive V -%R. Proof. exact: opprK. Qed.
Lemma oppr_inj : @injective V V -%R. Proof. exact: oppr_inj. Qed.
Lemma oppr0 : -0 = 0 :> V. Proof. exact: oppr0. Qed.
Lemma oppr_eq0 x : (- x == 0) = (x == 0). Proof. exact: oppr_eq0. Qed.
Lemma subr0 x : x - 0 = x. Proof. exact: subr0. Qed.
Lemma sub0r x : 0 - x = - x. Proof. exact: sub0r. Qed.
Lemma opprB x y : - (x - y) = y - x. Proof. exact: opprB. Qed.
Lemma opprD : {morph -%R: x y / x + y : V}. Proof. exact: opprD. Qed.
Lemma addrKA z x y : (x + z) - (z + y) = x - y. Proof. exact: addrKA. Qed.
Lemma subrKA z x y : (x - z) + (z + y) = x + y. Proof. exact: subrKA. Qed.
Lemma addr0_eq x y : x + y = 0 -> - x = y. Proof. exact: addr0_eq. Qed.
Lemma subr0_eq x y : x - y = 0 -> x = y. Proof. exact: subr0_eq. Qed.
Lemma subr_eq x y z : (x - z == y) = (x == y + z). Proof. exact: subr_eq. Qed.
Lemma subr_eq0 x y : (x - y == 0) = (x == y). Proof. exact: subr_eq0. Qed.
Lemma addr_eq0 x y : (x + y == 0) = (x == - y). Proof. exact: addr_eq0. Qed.
Lemma eqr_opp x y : (- x == - y) = (x == y). Proof. exact: eqr_opp. Qed.
Lemma eqr_oppLR x y : (- x == y) = (x == - y). Proof. exact: eqr_oppLR. Qed.
Lemma mulNrn x n : (- x) *+ n = x *- n. Proof. exact: mulNrn. Qed.
Lemma mulrnBl n : {morph (fun x => x *+ n) : x y / x - y}.
Proof. exact: mulrnBl. Qed.
Lemma mulrnBr x m n : n <= m -> x *+ (m - n) = x *+ m - x *+ n.
Proof. exact: mulrnBr. Qed.
Lemma sumrN I r P (F : I -> V) :
(\sum_(i <- r | P i) - F i = - (\sum_(i <- r | P i) F i)).
Proof. exact: sumrN. Qed.
Lemma sumrB I r (P : pred I) (F1 F2 : I -> V) :
\sum_(i <- r | P i) (F1 i - F2 i)
= \sum_(i <- r | P i) F1 i - \sum_(i <- r | P i) F2 i.
Proof. exact: sumrB. Qed.
Lemma telescope_sumr n m (f : nat -> V) : n <= m ->
\sum_(n <= k < m) (f k.+1 - f k) = f m - f n.
Proof. exact: telescope_sumr. Qed.
Lemma telescope_sumr_eq n m (f u : nat -> V) : n <= m ->
(forall k, (n <= k < m)%N -> u k = f k.+1 - f k) ->
\sum_(n <= k < m) u k = f m - f n.
Proof. exact: telescope_sumr_eq. Qed.
Section ClosedPredicates.
Variable S : {pred V}.
Definition oppr_closed := oppr_closed S.
Definition subr_2closed := subr_closed S.
Definition zmod_closed := zmod_closed S.
Lemma zmod_closedN : zmod_closed -> oppr_closed.
Proof. exact: zmod_closedN. Qed.
Lemma zmod_closedD : zmod_closed -> nmod_closed S.
Proof. by move=> z; split; [case: z|apply/zmod_closedD]. Qed.
End ClosedPredicates.
End ZmoduleTheory.
Arguments addrI {V} y [x1 x2].
Arguments addIr {V} x [x1 x2].
Arguments opprK {V}.
Arguments oppr_inj {V} [x1 x2].
Arguments telescope_sumr_eq {V n m} f u.
HB.mixin Record Nmodule_isPzSemiRing R of Nmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul +%R;
mulrDr : right_distributive mul +%R;
mul0r : left_zero zero mul;
mulr0 : right_zero zero mul;
}.
#[short(type="pzSemiRingType")]
HB.structure Definition PzSemiRing :=
{ R of Nmodule_isPzSemiRing R & Nmodule R }.
HB.factory Record isPzSemiRing R of Choice R := {
zero : R;
add : R -> R -> R;
one : R;
mul : R -> R -> R;
addrA : associative add;
addrC : commutative add;
add0r : left_id zero add;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul add;
mulrDr : right_distributive mul add;
mul0r : left_zero zero mul;
mulr0 : right_zero zero mul;
}.
HB.builders Context R of isPzSemiRing R.
HB.instance Definition _ := @isNmodule.Build R
zero add addrA addrC add0r.
HB.instance Definition _ := @Nmodule_isPzSemiRing.Build R
one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0.
HB.end.
Module PzSemiRingExports.
Bind Scope ring_scope with PzSemiRing.sort.
End PzSemiRingExports.
HB.export PzSemiRingExports.
HB.mixin Record PzSemiRing_isNonZero R of PzSemiRing R := {
oner_neq0 : @one R != 0
}.
#[short(type="nzSemiRingType")]
HB.structure Definition NzSemiRing :=
{ R of PzSemiRing_isNonZero R & PzSemiRing R }.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzSemiRing instead.")]
Notation SemiRing R := (NzSemiRing R) (only parsing).
Module SemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzSemiRing.sort instead.")]
Notation sort := (NzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use NzSemiRing.on instead.")]
Notation on R := (NzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use NzSemiRing.copy instead.")]
Notation copy T U := (NzSemiRing.copy T U) (only parsing).
End SemiRing.
HB.factory Record Nmodule_isNzSemiRing R of Nmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul +%R;
mulrDr : right_distributive mul +%R;
mul0r : left_zero zero mul;
mulr0 : right_zero zero mul;
oner_neq0 : one != 0
}.
HB.builders Context R of Nmodule_isNzSemiRing R.
HB.instance Definition _ :=
Nmodule_isPzSemiRing.Build R mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0.
HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0.
HB.end.
Module Nmodule_isSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Nmodule_isNzSemiRing.Build instead.")]
Notation Build R := (Nmodule_isNzSemiRing.Build R) (only parsing).
End Nmodule_isSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Nmodule_isNzSemiRing instead.")]
Notation Nmodule_isSemiRing R := (Nmodule_isNzSemiRing R) (only parsing).
HB.factory Record isNzSemiRing R of Choice R := {
zero : R;
add : R -> R -> R;
one : R;
mul : R -> R -> R;
addrA : associative add;
addrC : commutative add;
add0r : left_id zero add;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul add;
mulrDr : right_distributive mul add;
mul0r : left_zero zero mul;
mulr0 : right_zero zero mul;
oner_neq0 : one != zero
}.
Module isSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzSemiRing.Build instead.")]
Notation Build R := (isNzSemiRing.Build R) (only parsing).
End isSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzSemiRing instead.")]
Notation isSemiRing R := (isNzSemiRing R) (only parsing).
HB.builders Context R of isNzSemiRing R.
HB.instance Definition _ := @isNmodule.Build R
zero add addrA addrC add0r.
HB.instance Definition _ := @Nmodule_isNzSemiRing.Build R
one mul mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0.
HB.end.
Module NzSemiRingExports.
Bind Scope ring_scope with NzSemiRing.sort.
End NzSemiRingExports.
HB.export NzSemiRingExports.
Definition exp R x n := iterop n (@mul R) x (@one R).
Arguments exp : simpl never.
Definition comm R x y := @mul R x y = mul y x.
Definition lreg R x := injective (@mul R x).
Definition rreg R x := injective ((@mul R)^~ x).
Local Notation "1" := (@one _) : ring_scope.
Local Notation "n %:R" := (1 *+ n) : ring_scope.
Local Notation "*%R" := (@mul _) : function_scope.
Local Notation "x * y" := (mul x y) : ring_scope.
Local Notation "x ^+ n" := (exp x n) : ring_scope.
Local Notation "\prod_ ( i <- r | P ) F" := (\big[*%R/1]_(i <- r | P) F).
Local Notation "\prod_ ( i | P ) F" := (\big[*%R/1]_(i | P) F).
Local Notation "\prod_ ( i 'in' A ) F" := (\big[*%R/1]_(i in A) F).
Local Notation "\prod_ ( m <= i < n ) F" := (\big[*%R/1%R]_(m <= i < n) F%R).
(* The ``field'' characteristic; the definition, and many of the theorems, *)
(* has to apply to rings as well; indeed, we need the Frobenius automorphism *)
(* results for a non commutative ring in the proof of Gorenstein 2.6.3. *)
Definition pchar (R : nzSemiRingType) : nat_pred :=
[pred p | prime p & p%:R == 0 :> R].
#[deprecated(since="mathcomp 2.4.0", note="Use pchar instead.")]
Notation char := pchar (only parsing).
Local Notation has_pchar0 L := (pchar L =i pred0).
#[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")]
Notation has_char0 L := (has_pchar0 L) (only parsing).
(* Converse ring tag. *)
Definition converse R : Type := R.
Local Notation "R ^c" := (converse R) : type_scope.
Section PzSemiRingTheory.
Variable R : pzSemiRingType.
Implicit Types x y : R.
#[export]
HB.instance Definition _ := Monoid.isLaw.Build R 1 *%R mulrA mul1r mulr1.
#[export]
HB.instance Definition _ := Monoid.isMulLaw.Build R 0 *%R mul0r mulr0.
#[export]
HB.instance Definition _ := Monoid.isAddLaw.Build R *%R +%R mulrDl mulrDr.
Lemma mulr_suml I r P (F : I -> R) x :
(\sum_(i <- r | P i) F i) * x = \sum_(i <- r | P i) F i * x.
Proof. exact: big_distrl. Qed.
Lemma mulr_sumr I r P (F : I -> R) x :
x * (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) x * F i.
Proof. exact: big_distrr. Qed.
Lemma mulrnAl x y n : (x *+ n) * y = (x * y) *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mul0r // !mulrS mulrDl IHn. Qed.
Lemma mulrnAr x y n : x * (y *+ n) = (x * y) *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mulr0 // !mulrS mulrDr IHn. Qed.
Lemma mulr_natl x n : n%:R * x = x *+ n.
Proof. by rewrite mulrnAl mul1r. Qed.
Lemma mulr_natr x n : x * n%:R = x *+ n.
Proof. by rewrite mulrnAr mulr1. Qed.
Lemma natrD m n : (m + n)%:R = m%:R + n%:R :> R. Proof. exact: mulrnDr. Qed.
Lemma natr1 n : n%:R + 1 = n.+1%:R :> R. Proof. by rewrite mulrSr. Qed.
Lemma nat1r n : 1 + n%:R = n.+1%:R :> R. Proof. by rewrite mulrS. Qed.
Definition natr_sum := big_morph (natmul 1) natrD (mulr0n 1).
Lemma natrM m n : (m * n)%:R = m%:R * n%:R :> R.
Proof. by rewrite mulrnA mulr_natr. Qed.
Lemma expr0 x : x ^+ 0 = 1. Proof. by []. Qed.
Lemma expr1 x : x ^+ 1 = x. Proof. by []. Qed.
Lemma expr2 x : x ^+ 2 = x * x. Proof. by []. Qed.
Lemma exprS x n : x ^+ n.+1 = x * x ^+ n.
Proof. by case: n => //; rewrite mulr1. Qed.
Lemma expr0n n : 0 ^+ n = (n == 0%N)%:R :> R.
Proof. by case: n => // n; rewrite exprS mul0r. Qed.
Lemma expr1n n : 1 ^+ n = 1 :> R.
Proof. by elim: n => // n IHn; rewrite exprS mul1r. Qed.
Lemma exprD x m n : x ^+ (m + n) = x ^+ m * x ^+ n.
Proof. by elim: m => [|m IHm]; rewrite ?mul1r // !exprS -mulrA -IHm. Qed.
Lemma exprSr x n : x ^+ n.+1 = x ^+ n * x.
Proof. by rewrite -addn1 exprD expr1. Qed.
Lemma expr_sum x (I : Type) (s : seq I) (P : pred I) F :
x ^+ (\sum_(i <- s | P i) F i) = \prod_(i <- s | P i) x ^+ F i :> R.
Proof. exact: (big_morph _ (exprD _)). Qed.
Lemma commr_sym x y : comm x y -> comm y x. Proof. by []. Qed.
Lemma commr_refl x : comm x x. Proof. by []. Qed.
Lemma commr0 x : comm x 0.
Proof. by rewrite /comm mulr0 mul0r. Qed.
Lemma commr1 x : comm x 1.
Proof. by rewrite /comm mulr1 mul1r. Qed.
Lemma commrD x y z : comm x y -> comm x z -> comm x (y + z).
Proof. by rewrite /comm mulrDl mulrDr => -> ->. Qed.
Lemma commr_sum (I : Type) (s : seq I) (P : pred I) (F : I -> R) x :
(forall i, P i -> comm x (F i)) -> comm x (\sum_(i <- s | P i) F i).
Proof.
move=> comm_x_F; rewrite /comm mulr_suml mulr_sumr.
by apply: eq_bigr => i /comm_x_F.
Qed.
Lemma commrMn x y n : comm x y -> comm x (y *+ n).
Proof.
rewrite /comm => com_xy.
by elim: n => [|n IHn]; rewrite ?commr0 // mulrS commrD.
Qed.
Lemma commrM x y z : comm x y -> comm x z -> comm x (y * z).
Proof. by move=> com_xy; rewrite /comm mulrA com_xy -!mulrA => ->. Qed.
Lemma commr_prod (I : Type) (s : seq I) (P : pred I) (F : I -> R) x :
(forall i, P i -> comm x (F i)) -> comm x (\prod_(i <- s | P i) F i).
Proof. exact: (big_ind _ (commr1 x) (@commrM x)). Qed.
Lemma commr_nat x n : comm x n%:R. Proof. exact/commrMn/commr1. Qed.
Lemma commrX x y n : comm x y -> comm x (y ^+ n).
Proof.
rewrite /comm => com_xy.
by elim: n => [|n IHn]; rewrite ?commr1 // exprS commrM.
Qed.
Lemma exprMn_comm x y n : comm x y -> (x * y) ^+ n = x ^+ n * y ^+ n.
Proof.
move=> com_xy; elim: n => /= [|n IHn]; first by rewrite mulr1.
by rewrite !exprS IHn !mulrA; congr (_ * _); rewrite -!mulrA -commrX.
Qed.
Lemma exprMn_n x m n : (x *+ m) ^+ n = x ^+ n *+ (m ^ n) :> R.
Proof.
elim: n => [|n IHn]; first by rewrite mulr1n.
by rewrite exprS IHn mulrnAl mulrnAr -mulrnA exprS -expnSr.
Qed.
Lemma exprM x m n : x ^+ (m * n) = x ^+ m ^+ n.
Proof.
elim: m => [|m IHm]; first by rewrite expr1n.
by rewrite mulSn exprD IHm exprS exprMn_comm //; apply: commrX.
Qed.
Lemma exprAC x m n : (x ^+ m) ^+ n = (x ^+ n) ^+ m.
Proof. by rewrite -!exprM mulnC. Qed.
Lemma expr_mod n x i : x ^+ n = 1 -> x ^+ (i %% n) = x ^+ i.
Proof.
move=> xn1; rewrite {2}(divn_eq i n) exprD mulnC exprM xn1.
by rewrite expr1n mul1r.
Qed.
Lemma expr_dvd n x i : x ^+ n = 1 -> n %| i -> x ^+ i = 1.
Proof.
by move=> xn1 dvd_n_i; rewrite -(expr_mod i xn1) (eqnP dvd_n_i).
Qed.
Lemma natrX n k : (n ^ k)%:R = n%:R ^+ k :> R.
Proof. by rewrite exprMn_n expr1n. Qed.
Lemma mulrI_eq0 x y : lreg x -> (x * y == 0) = (y == 0).
Proof. by move=> reg_x; rewrite -{1}(mulr0 x) (inj_eq reg_x). Qed.
Lemma lreg1 : lreg (1 : R).
Proof. by move=> x y; rewrite !mul1r. Qed.
Lemma lregM x y : lreg x -> lreg y -> lreg (x * y).
Proof. by move=> reg_x reg_y z t; rewrite -!mulrA => /reg_x/reg_y. Qed.
Lemma lregMl (a b: R) : lreg (a * b) -> lreg b.
Proof. by move=> rab c c' eq_bc; apply/rab; rewrite -!mulrA eq_bc. Qed.
Lemma rregMr (a b: R) : rreg (a * b) -> rreg a.
Proof. by move=> rab c c' eq_ca; apply/rab; rewrite !mulrA eq_ca. Qed.
Lemma lregX x n : lreg x -> lreg (x ^+ n).
Proof.
by move=> reg_x; elim: n => [|n]; [apply: lreg1 | rewrite exprS; apply: lregM].
Qed.
Lemma iter_mulr n x y : iter n ( *%R x) y = x ^+ n * y.
Proof. by elim: n => [|n ih]; rewrite ?expr0 ?mul1r //= ih exprS -mulrA. Qed.
Lemma iter_mulr_1 n x : iter n ( *%R x) 1 = x ^+ n.
Proof. by rewrite iter_mulr mulr1. Qed.
Lemma prodr_const (I : finType) (A : pred I) x : \prod_(i in A) x = x ^+ #|A|.
Proof. by rewrite big_const -iteropE. Qed.
Lemma prodr_const_nat n m x : \prod_(n <= i < m) x = x ^+ (m - n).
Proof. by rewrite big_const_nat -iteropE. Qed.
Lemma prodrXr x I r P (F : I -> nat) :
\prod_(i <- r | P i) x ^+ F i = x ^+ (\sum_(i <- r | P i) F i).
Proof. by rewrite (big_morph _ (exprD _) (erefl _)). Qed.
Lemma prodrM_comm {I : eqType} r (P : pred I) (F G : I -> R) :
(forall i j, P i -> P j -> comm (F i) (G j)) ->
\prod_(i <- r | P i) (F i * G i) =
\prod_(i <- r | P i) F i * \prod_(i <- r | P i) G i.
Proof.
move=> FG; elim: r => [|i r IHr]; rewrite !(big_nil, big_cons) ?mulr1//.
case: ifPn => // Pi; rewrite IHr !mulrA; congr (_ * _); rewrite -!mulrA.
by rewrite commr_prod // => j Pj; apply/commr_sym/FG.
Qed.
Lemma prodrMl_comm {I : finType} (A : pred I) (x : R) F :
(forall i, A i -> comm x (F i)) ->
\prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i.
Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j _ /xF. Qed.
Lemma prodrMr_comm {I : finType} (A : pred I) (x : R) F :
(forall i, A i -> comm x (F i)) ->
\prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|.
Proof. by move=> xF; rewrite prodrM_comm ?prodr_const// => i j /xF. Qed.
Lemma prodrMn (I : Type) (s : seq I) (P : pred I) (F : I -> R) (g : I -> nat) :
\prod_(i <- s | P i) (F i *+ g i) =
\prod_(i <- s | P i) (F i) *+ \prod_(i <- s | P i) g i.
Proof.
by elim/big_rec3: _ => // i y1 y2 y3 _ ->; rewrite mulrnAr mulrnAl -mulrnA.
Qed.
Lemma prodrMn_const n (I : finType) (A : pred I) (F : I -> R) :
\prod_(i in A) (F i *+ n) = \prod_(i in A) F i *+ n ^ #|A|.
Proof. by rewrite prodrMn prod_nat_const. Qed.
Lemma natr_prod I r P (F : I -> nat) :
(\prod_(i <- r | P i) F i)%:R = \prod_(i <- r | P i) (F i)%:R :> R.
Proof. exact: (big_morph _ natrM). Qed.
Lemma exprDn_comm x y n (cxy : comm x y) :
(x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i).
Proof.
elim: n => [|n IHn]; rewrite big_ord_recl mulr1 ?big_ord0 ?addr0 //=.
rewrite exprS {}IHn /= mulrDl !big_distrr /= big_ord_recl mulr1 subn0.
rewrite !big_ord_recr /= !binn !subnn !mul1r !subn0 bin0 !exprS -addrA.
congr (_ + _); rewrite addrA -big_split /=; congr (_ + _).
apply: eq_bigr => i _; rewrite !mulrnAr !mulrA -exprS -subSn ?(valP i) //.
by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS -mulrnDr.
Qed.
Lemma exprD1n x n : (x + 1) ^+ n = \sum_(i < n.+1) x ^+ i *+ 'C(n, i).
Proof.
rewrite addrC (exprDn_comm n (commr_sym (commr1 x))).
by apply: eq_bigr => i _; rewrite expr1n mul1r.
Qed.
Lemma sqrrD1 x : (x + 1) ^+ 2 = x ^+ 2 + x *+ 2 + 1.
Proof.
rewrite exprD1n !big_ord_recr big_ord0 /= add0r.
by rewrite addrC addrA addrAC.
Qed.
Section ClosedPredicates.
Variable S : {pred R}.
Definition mulr_2closed := {in S &, forall u v, u * v \in S}.
Definition mulr_closed := 1 \in S /\ mulr_2closed.
Definition semiring_closed := nmod_closed S /\ mulr_closed.
Lemma semiring_closedD : semiring_closed -> nmod_closed S. Proof. by case. Qed.
Lemma semiring_closedM : semiring_closed -> mulr_closed. Proof. by case. Qed.
End ClosedPredicates.
End PzSemiRingTheory.
Section NzSemiRingTheory.
Variable R : nzSemiRingType.
Implicit Types x y : R.
Lemma oner_eq0 : (1 == 0 :> R) = false. Proof. exact: negbTE oner_neq0. Qed.
Lemma lastr_eq0 (s : seq R) x : x != 0 -> (last x s == 0) = (last 1 s == 0).
Proof. by case: s => [|y s] /negPf // ->; rewrite oner_eq0. Qed.
Lemma lreg_neq0 x : lreg x -> x != 0.
Proof. by move=> reg_x; rewrite -[x]mulr1 mulrI_eq0 ?oner_eq0. Qed.
Definition pFrobenius_aut p of p \in pchar R := fun x => x ^+ p.
(* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible
definition. *)
Section FrobeniusAutomorphism.
Variable p : nat.
Hypothesis pcharFp : p \in pchar R.
Lemma pcharf0 : p%:R = 0 :> R. Proof. by apply/eqP; case/andP: pcharFp. Qed.
Lemma pcharf_prime : prime p. Proof. by case/andP: pcharFp. Qed.
Hint Resolve pcharf_prime : core.
Lemma mulrn_pchar x : x *+ p = 0. Proof. by rewrite -mulr_natl pcharf0 mul0r. Qed.
Lemma natr_mod_pchar n : (n %% p)%:R = n%:R :> R.
Proof. by rewrite {2}(divn_eq n p) natrD mulrnA mulrn_pchar add0r. Qed.
Lemma dvdn_pcharf n : (p %| n)%N = (n%:R == 0 :> R).
Proof.
apply/idP/eqP=> [/dvdnP[n' ->]|n0]; first by rewrite natrM pcharf0 mulr0.
apply/idPn; rewrite -prime_coprime // => /eqnP pn1.
have [a _ /dvdnP[b]] := Bezoutl n (prime_gt0 pcharf_prime).
move/(congr1 (fun m => m%:R : R))/eqP.
by rewrite natrD !natrM pcharf0 n0 !mulr0 pn1 addr0 oner_eq0.
Qed.
Lemma pcharf_eq : pchar R =i (p : nat_pred).
Proof.
move=> q; apply/andP/eqP=> [[q_pr q0] | ->]; last by rewrite pcharf0.
by apply/eqP; rewrite eq_sym -dvdn_prime2 // dvdn_pcharf.
Qed.
Lemma bin_lt_pcharf_0 k : 0 < k < p -> 'C(p, k)%:R = 0 :> R.
Proof. by move=> lt0kp; apply/eqP; rewrite -dvdn_pcharf prime_dvd_bin. Qed.
Local Notation "x ^f" := (pFrobenius_aut pcharFp x).
Lemma pFrobenius_autE x : x^f = x ^+ p. Proof. by []. Qed.
Local Notation f'E := pFrobenius_autE.
Lemma pFrobenius_aut0 : 0^f = 0.
Proof. by rewrite f'E -(prednK (prime_gt0 pcharf_prime)) exprS mul0r. Qed.
Lemma pFrobenius_aut1 : 1^f = 1.
Proof. by rewrite f'E expr1n. Qed.
Lemma pFrobenius_autD_comm x y (cxy : comm x y) : (x + y)^f = x^f + y^f.
Proof.
have defp := prednK (prime_gt0 pcharf_prime).
rewrite !f'E exprDn_comm // big_ord_recr subnn -defp big_ord_recl /= defp.
rewrite subn0 mulr1 mul1r bin0 binn big1 ?addr0 // => i _.
by rewrite -mulr_natl bin_lt_pcharf_0 ?mul0r //= -{2}defp ltnS (valP i).
Qed.
Lemma pFrobenius_autMn x n : (x *+ n)^f = x^f *+ n.
Proof.
elim: n => [|n IHn]; first exact: pFrobenius_aut0.
by rewrite !mulrS pFrobenius_autD_comm ?IHn //; apply: commrMn.
Qed.
Lemma pFrobenius_aut_nat n : (n%:R)^f = n%:R.
Proof. by rewrite pFrobenius_autMn pFrobenius_aut1. Qed.
Lemma pFrobenius_autM_comm x y : comm x y -> (x * y)^f = x^f * y^f.
Proof. exact: exprMn_comm. Qed.
Lemma pFrobenius_autX x n : (x ^+ n)^f = x^f ^+ n.
Proof. by rewrite !f'E -!exprM mulnC. Qed.
End FrobeniusAutomorphism.
Section Char2.
Hypothesis pcharR2 : 2 \in pchar R.
Lemma addrr_pchar2 x : x + x = 0. Proof. by rewrite -mulr2n mulrn_pchar. Qed.
End Char2.
End NzSemiRingTheory.
#[short(type="pzRingType")]
HB.structure Definition PzRing := { R of PzSemiRing R & Zmodule R }.
HB.factory Record Zmodule_isPzRing R of Zmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul +%R;
mulrDr : right_distributive mul +%R;
}.
HB.builders Context R of Zmodule_isPzRing R.
Local Notation "1" := one.
Local Notation "x * y" := (mul x y).
Lemma mul0r : @left_zero R R 0 mul.
Proof. by move=> x; apply: (addIr (1 * x)); rewrite -mulrDl !add0r mul1r. Qed.
Lemma mulr0 : @right_zero R R 0 mul.
Proof. by move=> x; apply: (addIr (x * 1)); rewrite -mulrDr !add0r mulr1. Qed.
HB.instance Definition _ := Nmodule_isPzSemiRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0.
HB.end.
HB.factory Record isPzRing R of Choice R := {
zero : R;
opp : R -> R;
add : R -> R -> R;
one : R;
mul : R -> R -> R;
addrA : associative add;
addrC : commutative add;
add0r : left_id zero add;
addNr : left_inverse zero opp add;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul add;
mulrDr : right_distributive mul add;
}.
HB.builders Context R of isPzRing R.
HB.instance Definition _ := @isZmodule.Build R
zero opp add addrA addrC add0r addNr.
HB.instance Definition _ := @Zmodule_isPzRing.Build R
one mul mulrA mul1r mulr1 mulrDl mulrDr.
HB.end.
Module PzRingExports.
Bind Scope ring_scope with PzRing.sort.
End PzRingExports.
HB.export PzRingExports.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")]
Notation Frobenius_aut := pFrobenius_aut (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")]
Notation charf0 := pcharf0 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")]
Notation charf_prime := pcharf_prime (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")]
Notation mulrn_char := mulrn_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use natr_mod_pchar instead.")]
Notation natr_mod_char := natr_mod_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")]
Notation dvdn_charf := dvdn_pcharf (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")]
Notation charf_eq := pcharf_eq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")]
Notation bin_lt_charf_0 := bin_lt_pcharf_0 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")]
Notation Frobenius_autE := pFrobenius_autE (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")]
Notation Frobenius_aut0 := pFrobenius_aut0 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")]
Notation Frobenius_aut1 := pFrobenius_aut1 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")]
Notation Frobenius_autD_comm := pFrobenius_autD_comm (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")]
Notation Frobenius_autMn := pFrobenius_autMn (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")]
Notation Frobenius_aut_nat := pFrobenius_aut_nat (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")]
Notation Frobenius_autM_comm := pFrobenius_autM_comm (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")]
Notation Frobenius_autX := pFrobenius_autX (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")]
Notation addrr_char2 := addrr_pchar2 (only parsing).
#[short(type="nzRingType")]
HB.structure Definition NzRing := { R of NzSemiRing R & Zmodule R }.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing instead.")]
Notation Ring R := (NzRing R) (only parsing).
Module Ring.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing.sort instead.")]
Notation sort := (NzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing.on instead.")]
Notation on R := (NzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing.copy instead.")]
Notation copy T U := (NzRing.copy T U) (only parsing).
End Ring.
HB.factory Record Zmodule_isNzRing R of Zmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul +%R;
mulrDr : right_distributive mul +%R;
oner_neq0 : one != 0
}.
Module Zmodule_isRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Zmodule_isNzRing.Build instead.")]
Notation Build R := (Zmodule_isNzRing.Build R) (only parsing).
End Zmodule_isRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Zmodule_isNzRing instead.")]
Notation Zmodule_isRing R := (Zmodule_isNzRing R) (only parsing).
HB.builders Context R of Zmodule_isNzRing R.
HB.instance Definition _ := Zmodule_isPzRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr.
HB.instance Definition _ := PzSemiRing_isNonZero.Build R oner_neq0.
HB.end.
HB.factory Record isNzRing R of Choice R := {
zero : R;
opp : R -> R;
add : R -> R -> R;
one : R;
mul : R -> R -> R;
addrA : associative add;
addrC : commutative add;
add0r : left_id zero add;
addNr : left_inverse zero opp add;
mulrA : associative mul;
mul1r : left_id one mul;
mulr1 : right_id one mul;
mulrDl : left_distributive mul add;
mulrDr : right_distributive mul add;
oner_neq0 : one != zero
}.
Module isRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzRing.Build instead.")]
Notation Build R := (isNzRing.Build R) (only parsing).
End isRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isNzRing instead.")]
Notation isRing R := (isNzRing R) (only parsing).
HB.builders Context R of isNzRing R.
HB.instance Definition _ := @isZmodule.Build R
zero opp add addrA addrC add0r addNr.
HB.instance Definition _ := @Zmodule_isNzRing.Build R
one mul mulrA mul1r mulr1 mulrDl mulrDr oner_neq0.
HB.end.
Module NzRingExports.
Bind Scope ring_scope with NzRing.sort.
End NzRingExports.
HB.export NzRingExports.
Notation sign R b := (exp (- @one R) (nat_of_bool b)) (only parsing).
Local Notation "- 1" := (- (1)) : ring_scope.
Section PzRingTheory.
Variable R : pzRingType.
Implicit Types x y : R.
Lemma mulrN x y : x * (- y) = - (x * y).
Proof. by apply: (addrI (x * y)); rewrite -mulrDr !subrr mulr0. Qed.
Lemma mulNr x y : (- x) * y = - (x * y).
Proof. by apply: (addrI (x * y)); rewrite -mulrDl !subrr mul0r. Qed.
Lemma mulrNN x y : (- x) * (- y) = x * y.
Proof. by rewrite mulrN mulNr opprK. Qed.
Lemma mulN1r x : -1 * x = - x.
Proof. by rewrite mulNr mul1r. Qed.
Lemma mulrN1 x : x * -1 = - x.
Proof. by rewrite mulrN mulr1. Qed.
Lemma mulrBl x y z : (y - z) * x = y * x - z * x.
Proof. by rewrite mulrDl mulNr. Qed.
Lemma mulrBr x y z : x * (y - z) = x * y - x * z.
Proof. by rewrite mulrDr mulrN. Qed.
Lemma natrB m n : n <= m -> (m - n)%:R = m%:R - n%:R :> R.
Proof. exact: mulrnBr. Qed.
Lemma commrN x y : comm x y -> comm x (- y).
Proof. by move=> com_xy; rewrite /comm mulrN com_xy mulNr. Qed.
Lemma commrN1 x : comm x (-1). Proof. exact/commrN/commr1. Qed.
Lemma commrB x y z : comm x y -> comm x z -> comm x (y - z).
Proof. by move=> com_xy com_xz; apply: commrD => //; apply: commrN. Qed.
Lemma commr_sign x n : comm x ((-1) ^+ n).
Proof. exact: (commrX n (commrN1 x)). Qed.
Lemma signr_odd n : (-1) ^+ (odd n) = (-1) ^+ n :> R.
Proof.
elim: n => //= n IHn; rewrite exprS -{}IHn.
by case/odd: n; rewrite !mulN1r ?opprK.
Qed.
Lemma mulr_sign (b : bool) x : (-1) ^+ b * x = (if b then - x else x).
Proof. by case: b; rewrite ?mulNr mul1r. Qed.
Lemma signr_addb b1 b2 : (-1) ^+ (b1 (+) b2) = (-1) ^+ b1 * (-1) ^+ b2 :> R.
Proof. by rewrite mulr_sign; case: b1 b2 => [] []; rewrite ?opprK. Qed.
Lemma signrE (b : bool) : (-1) ^+ b = 1 - b.*2%:R :> R.
Proof. by case: b; rewrite ?subr0 // opprD addNKr. Qed.
Lemma signrN b : (-1) ^+ (~~ b) = - (-1) ^+ b :> R.
Proof. by case: b; rewrite ?opprK. Qed.
Lemma mulr_signM (b1 b2 : bool) x1 x2 :
((-1) ^+ b1 * x1) * ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 * x2).
Proof.
by rewrite signr_addb -!mulrA; congr (_ * _); rewrite !mulrA commr_sign.
Qed.
Lemma exprNn x n : (- x) ^+ n = (-1) ^+ n * x ^+ n :> R.
Proof. by rewrite -mulN1r exprMn_comm // /comm mulN1r mulrN mulr1. Qed.
Lemma sqrrN x : (- x) ^+ 2 = x ^+ 2. Proof. exact: mulrNN. Qed.
Lemma sqrr_sign n : ((-1) ^+ n) ^+ 2 = 1 :> R.
Proof. by rewrite exprAC sqrrN !expr1n. Qed.
Lemma signrMK n : @involutive R ( *%R ((-1) ^+ n)).
Proof. by move=> x; rewrite mulrA -expr2 sqrr_sign mul1r. Qed.
Lemma mulrI0_lreg x : (forall y, x * y = 0 -> y = 0) -> lreg x.
Proof.
move=> reg_x y z eq_xy_xz; apply/eqP; rewrite -subr_eq0 [y - z]reg_x //.
by rewrite mulrBr eq_xy_xz subrr.
Qed.
Lemma lregN x : lreg x -> lreg (- x).
Proof. by move=> reg_x y z; rewrite !mulNr => /oppr_inj/reg_x. Qed.
Lemma lreg_sign n : lreg ((-1) ^+ n : R). Proof. exact/lregX/lregN/lreg1. Qed.
Lemma prodrN (I : finType) (A : pred I) (F : I -> R) :
\prod_(i in A) - F i = (- 1) ^+ #|A| * \prod_(i in A) F i.
Proof.
rewrite -sum1_card; elim/big_rec3: _ => [|i x n _ _ ->]; first by rewrite mulr1.
by rewrite exprS !mulrA mulN1r !mulNr commrX //; apply: commrN1.
Qed.
Lemma exprBn_comm x y n (cxy : comm x y) :
(x - y) ^+ n =
\sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i).
Proof.
rewrite exprDn_comm; last exact: commrN.
by apply: eq_bigr => i _; congr (_ *+ _); rewrite -commr_sign -mulrA -exprNn.
Qed.
Lemma subrXX_comm x y n (cxy : comm x y) :
x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i).
Proof.
case: n => [|n]; first by rewrite big_ord0 mulr0 subrr.
rewrite mulrBl !big_distrr big_ord_recl big_ord_recr /= subnn mulr1 mul1r.
rewrite subn0 -!exprS opprD -!addrA; congr (_ + _); rewrite addrA -sumrB.
rewrite big1 ?add0r // => i _; rewrite !mulrA -exprS -subSn ?(valP i) //.
by rewrite subSS (commrX _ (commr_sym cxy)) -mulrA -exprS subrr.
Qed.
Lemma subrX1 x n : x ^+ n - 1 = (x - 1) * (\sum_(i < n) x ^+ i).
Proof.
rewrite -!(opprB 1) mulNr -{1}(expr1n _ n).
rewrite (subrXX_comm _ (commr_sym (commr1 x))); congr (- (_ * _)).
by apply: eq_bigr => i _; rewrite expr1n mul1r.
Qed.
Lemma sqrrB1 x : (x - 1) ^+ 2 = x ^+ 2 - x *+ 2 + 1.
Proof. by rewrite -sqrrN opprB addrC sqrrD1 sqrrN mulNrn. Qed.
Lemma subr_sqr_1 x : x ^+ 2 - 1 = (x - 1) * (x + 1).
Proof. by rewrite subrX1 !big_ord_recr big_ord0 /= addrAC add0r. Qed.
Section ClosedPredicates.
Variable S : {pred R}.
Definition smulr_closed := -1 \in S /\ mulr_2closed S.
Definition subring_closed := [/\ 1 \in S, subr_2closed S & mulr_2closed S].
Lemma smulr_closedM : smulr_closed -> mulr_closed S.
Proof. by case=> SN1 SM; split=> //; rewrite -[1]mulr1 -mulrNN SM. Qed.
Lemma smulr_closedN : smulr_closed -> oppr_closed S.
Proof. by case=> SN1 SM x Sx; rewrite -mulN1r SM. Qed.
Lemma subring_closedB : subring_closed -> zmod_closed S.
Proof. by case=> S1 SB _; split; rewrite // -(subrr 1) SB. Qed.
Lemma subring_closedM : subring_closed -> smulr_closed.
Proof.
by case=> S1 SB SM; split; rewrite ?(zmod_closedN (subring_closedB _)).
Qed.
Lemma subring_closed_semi : subring_closed -> semiring_closed S.
Proof.
by move=> ringS; split; [apply/zmod_closedD/subring_closedB | case: ringS].
Qed.
End ClosedPredicates.
End PzRingTheory.
Section NzRingTheory.
Variable R : nzRingType.
Implicit Types x y : R.
Lemma signr_eq0 n : ((-1) ^+ n == 0 :> R) = false.
Proof. by rewrite -signr_odd; case: odd; rewrite ?oppr_eq0 oner_eq0. Qed.
(* FIXME: Generalize to `pzSemiRingType` once `char` has a sensible
definition. *)
Section FrobeniusAutomorphism.
Variable p : nat.
Hypothesis pcharFp : p \in pchar R.
Hint Resolve pcharf_prime : core.
Local Notation "x ^f" := (pFrobenius_aut pcharFp x).
Lemma pFrobenius_autN x : (- x)^f = - x^f.
Proof.
apply/eqP; rewrite -subr_eq0 opprK addrC.
by rewrite -(pFrobenius_autD_comm _ (commrN _)) // subrr pFrobenius_aut0.
Qed.
Lemma pFrobenius_autB_comm x y : comm x y -> (x - y)^f = x^f - y^f.
Proof.
by move/commrN/pFrobenius_autD_comm->; rewrite pFrobenius_autN.
Qed.
End FrobeniusAutomorphism.
Lemma exprNn_pchar x n : (pchar R).-nat n -> (- x) ^+ n = - (x ^+ n).
Proof.
pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]].
have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) // pi_pdiv.
have /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)).
elim: e => // e IHe; rewrite expnSr !exprM {}IHe.
by rewrite -pFrobenius_autE pFrobenius_autN.
Qed.
Section Char2.
Hypothesis pcharR2 : 2 \in pchar R.
Lemma oppr_pchar2 x : - x = x.
Proof. by apply/esym/eqP; rewrite -addr_eq0 addrr_pchar2. Qed.
Lemma subr_pchar2 x y : x - y = x + y. Proof. by rewrite oppr_pchar2. Qed.
Lemma addrK_pchar2 x : involutive (+%R^~ x).
Proof. by move=> y; rewrite /= -subr_pchar2 addrK. Qed.
Lemma addKr_pchar2 x : involutive (+%R x).
Proof. by move=> y; rewrite -{1}[x]oppr_pchar2 addKr. Qed.
End Char2.
End NzRingTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")]
Notation Frobenius_autN := pFrobenius_autN (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")]
Notation Frobenius_autB_comm := pFrobenius_autB_comm (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")]
Notation exprNn_char := exprNn_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")]
Notation oppr_char2 := oppr_pchar2 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use subr_pchar2 instead.")]
Notation subr_char2 := subr_pchar2 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")]
Notation addrK_char2 := addrK_pchar2 (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")]
Notation addKr_char2 := addKr_pchar2 (only parsing).
Section ConverseRing.
#[export]
HB.instance Definition _ (T : eqType) := Equality.on T^c.
#[export]
HB.instance Definition _ (T : choiceType) := Choice.on T^c.
#[export]
HB.instance Definition _ (U : nmodType) := Nmodule.on U^c.
#[export]
HB.instance Definition _ (U : zmodType) := Zmodule.on U^c.
#[export]
HB.instance Definition _ (R : pzSemiRingType) :=
let mul' (x y : R) := y * x in
let mulrA' x y z := esym (mulrA z y x) in
let mulrDl' x y z := mulrDr z x y in
let mulrDr' x y z := mulrDl y z x in
Nmodule_isPzSemiRing.Build R^c
mulrA' mulr1 mul1r mulrDl' mulrDr' mulr0 mul0r.
#[export]
HB.instance Definition _ (R : pzRingType) := PzSemiRing.on R^c.
#[export]
HB.instance Definition _ (R : nzSemiRingType) :=
PzSemiRing_isNonZero.Build R^c oner_neq0.
#[export]
HB.instance Definition _ (R : nzRingType) := NzSemiRing.on R^c.
End ConverseRing.
Lemma rev_prodr (R : pzSemiRingType)
(I : Type) (r : seq I) (P : pred I) (E : I -> R) :
\prod_(i <- r | P i) (E i : R^c) = \prod_(i <- rev r | P i) E i.
Proof. by rewrite rev_big_rev. Qed.
Section SemiRightRegular.
Variable R : pzSemiRingType.
Implicit Types x y : R.
Lemma mulIr_eq0 x y : rreg x -> (y * x == 0) = (y == 0).
Proof. exact: (@mulrI_eq0 R^c). Qed.
Lemma rreg1 : rreg (1 : R).
Proof. exact: (@lreg1 R^c). Qed.
Lemma rregM x y : rreg x -> rreg y -> rreg (x * y).
Proof. by move=> reg_x reg_y; apply: (@lregM R^c). Qed.
Lemma revrX x n : (x : R^c) ^+ n = (x : R) ^+ n.
Proof. by elim: n => // n IHn; rewrite exprS exprSr IHn. Qed.
Lemma rregX x n : rreg x -> rreg (x ^+ n).
Proof. by move/(@lregX R^c x n); rewrite revrX. Qed.
End SemiRightRegular.
Lemma rreg_neq0 (R : nzSemiRingType) (x : R) : rreg x -> x != 0.
Proof. exact: (@lreg_neq0 R^c). Qed.
Section RightRegular.
Variable R : pzRingType.
Implicit Types x y : R.
Lemma mulIr0_rreg x : (forall y, y * x = 0 -> y = 0) -> rreg x.
Proof. exact: (@mulrI0_lreg R^c). Qed.
Lemma rregN x : rreg x -> rreg (- x). Proof. exact: (@lregN R^c). Qed.
End RightRegular.
HB.mixin Record Nmodule_isLSemiModule (R : pzSemiRingType) V of Nmodule V := {
scale : R -> V -> V;
scalerA : forall a b v, scale a (scale b v) = scale (a * b) v;
scale0r : forall v, scale 0 v = 0;
scale1r : left_id 1 scale;
scalerDr : right_distributive scale +%R;
scalerDl : forall v, {morph scale^~ v: a b / a + b}
}.
#[short(type="lSemiModType")]
HB.structure Definition LSemiModule (R : pzSemiRingType) :=
{M of Nmodule M & Nmodule_isLSemiModule R M}.
Module LSemiModExports.
Bind Scope ring_scope with LSemiModule.sort.
End LSemiModExports.
HB.export LSemiModExports.
Local Notation "*:%R" := (@scale _ _) : function_scope.
Local Notation "a *: v" := (scale a v) : ring_scope.
#[short(type="lmodType")]
HB.structure Definition Lmodule (R : pzRingType) :=
{M of Zmodule M & Nmodule_isLSemiModule R M}.
(* FIXME: see #1126 and #1127 *)
Arguments scalerA [R s] (a b)%_ring_scope v.
Module LmodExports.
Bind Scope ring_scope with Lmodule.sort.
End LmodExports.
HB.export LmodExports.
HB.factory Record Zmodule_isLmodule (R : pzRingType) V of Zmodule V := {
scale : R -> V -> V;
scalerA : forall a b v, scale a (scale b v) = scale (a * b) v;
scale1r : left_id 1 scale;
scalerDr : right_distributive scale +%R;
scalerDl : forall v, {morph scale^~ v: a b / a + b}
}.
HB.builders Context R V of Zmodule_isLmodule R V.
Lemma scale0r v : scale 0 v = 0.
Proof. by apply: (addIr (scale 1 v)); rewrite -scalerDl !add0r. Qed.
HB.instance Definition _ :=
Nmodule_isLSemiModule.Build R V scalerA scale0r scale1r scalerDr scalerDl.
HB.end.
HB.factory Record LSemiModule_isLmodule (R : pzRingType) V
of LSemiModule R V := {}.
HB.builders Context R V of LSemiModule_isLmodule R V.
Definition opp : V -> V := scale (- 1).
Lemma addNr : left_inverse 0 opp +%R.
Proof.
move=> v; suff : scale (-1 + 1) v = 0 by rewrite scalerDl scale1r.
by rewrite addNr scale0r.
Qed.
HB.instance Definition _ := Nmodule_isZmodule.Build V addNr.
HB.end.
Section LSemiModuleTheory.
Variables (R : pzSemiRingType) (V : lSemiModType R).
Implicit Types (a b c : R) (u v : V).
Lemma scaler0 a : a *: 0 = 0 :> V.
Proof. by rewrite -[0 in LHS](scale0r 0) scalerA mulr0 scale0r. Qed.
Lemma scaler_nat n v : n%:R *: v = v *+ n.
Proof.
elim: n => /= [|n]; first by rewrite scale0r.
by rewrite !mulrS scalerDl ?scale1r => ->.
Qed.
Lemma scalerMnl a v n : a *: v *+ n = (a *+ n) *: v.
Proof.
elim: n => [|n IHn]; first by rewrite !mulr0n scale0r.
by rewrite !mulrSr IHn scalerDl.
Qed.
Lemma scalerMnr a v n : a *: v *+ n = a *: (v *+ n).
Proof.
elim: n => [|n IHn]; first by rewrite !mulr0n scaler0.
by rewrite !mulrSr IHn scalerDr.
Qed.
Lemma scaler_suml v I r (P : pred I) F :
(\sum_(i <- r | P i) F i) *: v = \sum_(i <- r | P i) F i *: v.
Proof. exact: (big_morph _ (scalerDl v) (scale0r v)). Qed.
Lemma scaler_sumr a I r (P : pred I) (F : I -> V) :
a *: (\sum_(i <- r | P i) F i) = \sum_(i <- r | P i) a *: F i.
Proof. exact: big_endo (scalerDr a) (scaler0 a) I r P F. Qed.
Section ClosedPredicates.
Variable S : {pred V}.
Definition scaler_closed := forall a, {in S, forall v, a *: v \in S}.
Definition subsemimod_closed := nmod_closed S /\ scaler_closed.
Lemma subsemimod_closedD : subsemimod_closed -> nmod_closed S.
Proof. by case. Qed.
Lemma subsemimod_closedZ : subsemimod_closed -> scaler_closed.
Proof. by case. Qed.
End ClosedPredicates.
End LSemiModuleTheory.
Section LmoduleTheory.
Variables (R : pzRingType) (V : lmodType R).
Implicit Types (a b c : R) (u v : V).
Lemma scaleNr a v : - a *: v = - (a *: v).
Proof. by apply: (addIr (a *: v)); rewrite -scalerDl !addNr scale0r. Qed.
Lemma scaleN1r v : - 1 *: v = - v.
Proof. by rewrite scaleNr scale1r. Qed.
Lemma scalerN a v : a *: - v = - (a *: v).
Proof. by apply: (addIr (a *: v)); rewrite -scalerDr !addNr scaler0. Qed.
Lemma scalerBl a b v : (a - b) *: v = a *: v - b *: v.
Proof. by rewrite scalerDl scaleNr. Qed.
Lemma scalerBr a u v : a *: (u - v) = a *: u - a *: v.
Proof. by rewrite scalerDr scalerN. Qed.
Lemma scaler_sign (b : bool) v : (-1) ^+ b *: v = (if b then - v else v).
Proof. by case: b; rewrite ?scaleNr scale1r. Qed.
Lemma signrZK n : @involutive V ( *:%R ((-1) ^+ n)).
Proof. by move=> u; rewrite scalerA -expr2 sqrr_sign scale1r. Qed.
Section ClosedPredicates.
Variable S : {pred V}.
Definition linear_closed := forall a, {in S &, forall u v, a *: u + v \in S}.
Definition submod_closed := 0 \in S /\ linear_closed.
Lemma linear_closedB : linear_closed -> subr_2closed S.
Proof. by move=> Slin u v Su Sv; rewrite addrC -scaleN1r Slin. Qed.
Lemma submod_closedB : submod_closed -> zmod_closed S.
Proof. by case=> S0 /linear_closedB. Qed.
Lemma submod_closed_semi : submod_closed -> subsemimod_closed S.
Proof.
move=> /[dup] /submod_closedB /zmod_closedD SD [S0 Slin]; split => // a v Sv.
by rewrite -[a *: v]addr0 Slin.
Qed.
End ClosedPredicates.
End LmoduleTheory.
(* TOTHINK: Can I change `NzSemiRing` to `PzSemiRing`? *)
HB.mixin Record LSemiModule_isLSemiAlgebra R V
of NzSemiRing V & LSemiModule R V := {
scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v
}.
#[short(type="lSemiAlgType")]
HB.structure Definition LSemiAlgebra R :=
{A of LSemiModule R A & NzSemiRing A & LSemiModule_isLSemiAlgebra R A}.
Module LSemiAlgExports.
Bind Scope ring_scope with LSemiAlgebra.sort.
End LSemiAlgExports.
HB.export LSemiAlgExports.
(* Scalar injection (see the definition of in_alg A below). *)
Local Notation "k %:A" := (k *: 1) : ring_scope.
#[short(type="lalgType")]
HB.structure Definition Lalgebra R :=
{A of Lmodule R A & NzRing A & LSemiModule_isLSemiAlgebra R A}.
Module LalgExports.
Bind Scope ring_scope with Lalgebra.sort.
End LalgExports.
HB.export LalgExports.
HB.factory Record Lmodule_isLalgebra R V of NzRing V & Lmodule R V := {
scalerAl : forall (a : R) (u v : V), a *: (u * v) = (a *: u) * v
}.
HB.builders Context R V of Lmodule_isLalgebra R V.
HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R V scalerAl.
HB.end.
(* Regular ring algebra tag. *)
Definition regular R : Type := R.
Local Notation "R ^o" := (regular R) : type_scope.
Section RegularAlgebra.
#[export]
HB.instance Definition _ (V : nmodType) := Nmodule.on V^o.
#[export]
HB.instance Definition _ (V : zmodType) := Zmodule.on V^o.
#[export]
HB.instance Definition _ (R : pzSemiRingType) := PzSemiRing.on R^o.
#[export]
HB.instance Definition _ (R : nzSemiRingType) := NzSemiRing.on R^o.
#[export]
HB.instance Definition _ (R : pzSemiRingType) :=
@Nmodule_isLSemiModule.Build R R^o
mul mulrA mul0r mul1r mulrDr (fun v a b => mulrDl a b v).
#[export]
HB.instance Definition _ (R : nzSemiRingType) :=
LSemiModule_isLSemiAlgebra.Build R R^o mulrA.
#[export]
HB.instance Definition _ (R : pzRingType) := PzRing.on R^o.
#[export]
HB.instance Definition _ (R : nzRingType) := NzRing.on R^o.
End RegularAlgebra.
Section LSemiAlgebraTheory.
Variables (R : pzSemiRingType) (A : lSemiAlgType R).
Lemma mulr_algl (a : R) (x : A) : (a *: 1) * x = a *: x.
Proof. by rewrite -scalerAl mul1r. Qed.
End LSemiAlgebraTheory.
Section LalgebraTheory.
Variables (R : pzRingType) (A : lalgType R).
Section ClosedPredicates.
Variable S : {pred A}.
Definition subalg_closed := [/\ 1 \in S, linear_closed S & mulr_2closed S].
Lemma subalg_closedZ : subalg_closed -> submod_closed S.
Proof. by case=> S1 Slin _; split; rewrite // -(subrr 1) linear_closedB. Qed.
Lemma subalg_closedBM : subalg_closed -> subring_closed S.
Proof. by case=> S1 Slin SM; split=> //; apply: linear_closedB. Qed.
End ClosedPredicates.
End LalgebraTheory.
(* Morphism hierarchy. *)
(* Lifted multiplication. *)
Section LiftedSemiRing.
Variables (R : pzSemiRingType) (T : Type).
Implicit Type f : T -> R.
Definition mull_fun a f x := a * f x.
Definition mulr_fun a f x := f x * a.
Definition mul_fun f g x := f x * g x.
End LiftedSemiRing.
(* Lifted linear operations. *)
Section LiftedScale.
Variables (R : pzSemiRingType) (U : Type).
Variables (V : lSemiModType R) (A : lSemiAlgType R).
Definition scale_fun a (f : U -> V) x := a *: f x.
Definition in_alg k : A := k%:A.
End LiftedScale.
Local Notation "\0" := (null_fun _) : function_scope.
Local Notation "f \+ g" := (add_fun f g) : function_scope.
Local Notation "f \- g" := (sub_fun f g) : function_scope.
Local Notation "\- f" := (opp_fun f) : function_scope.
Local Notation "a \*: f" := (scale_fun a f) : function_scope.
Local Notation "x \*o f" := (mull_fun x f) : function_scope.
Local Notation "x \o* f" := (mulr_fun x f) : function_scope.
Local Notation "f \* g" := (mul_fun f g) : function_scope.
Arguments in_alg {_} A _ /.
Arguments mull_fun {_ _} a f _ /.
Arguments mulr_fun {_ _} a f _ /.
Arguments scale_fun {_ _ _} a f _ /.
Arguments mul_fun {_ _} f g _ /.
Section AdditiveTheory.
Section SemiRingProperties.
Variables (R S : pzSemiRingType) (f : {additive R -> S}).
Lemma raddfMnat n x : f (n%:R * x) = n%:R * f x.
Proof. by rewrite !mulr_natl raddfMn. Qed.
Variables (U : lSemiModType R) (V : lSemiModType S) (h : {additive U -> V}).
Lemma raddfZnat n u : h (n%:R *: u) = n%:R *: h u.
Proof. by rewrite !scaler_nat raddfMn. Qed.
End SemiRingProperties.
Section MulFun.
Variables (R : pzSemiRingType) (U : nmodType) (a : R) (f : {additive U -> R}).
Fact mull_fun_is_nmod_morphism : nmod_morphism (a \*o f).
Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mulr0// raddfD mulrDr. Qed.
#[export]
HB.instance Definition _ := isNmodMorphism.Build U R (a \*o f)
mull_fun_is_nmod_morphism.
Fact mulr_fun_is_nmod_morphism : nmod_morphism (a \o* f).
Proof. by split=> [|x y]; rewrite /= ?raddf0 ?mul0r// raddfD mulrDl. Qed.
#[export]
HB.instance Definition _ := isNmodMorphism.Build U R (a \o* f)
mulr_fun_is_nmod_morphism.
End MulFun.
Section Properties.
Variables (U V : zmodType) (f : {additive U -> V}).
Lemma raddfN : {morph f : x / - x}. Proof. exact: raddfN. Qed.
Lemma raddfB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed.
Lemma raddf_inj : (forall x, f x = 0 -> x = 0) -> injective f.
Proof. exact: raddf_inj. Qed.
Lemma raddfMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed.
End Properties.
Section RingProperties.
Variables (R S : pzRingType) (f : {additive R -> S}).
Lemma raddfMsign n x : f ((-1) ^+ n * x) = (-1) ^+ n * f x.
Proof. by rewrite !(mulr_sign, =^~ signr_odd) (fun_if f) raddfN. Qed.
Variables (U : lmodType R) (V : lmodType S) (h : {additive U -> V}).
Lemma raddfZsign n u : h ((-1) ^+ n *: u) = (-1) ^+ n *: h u.
Proof. by rewrite !(scaler_sign, =^~ signr_odd) (fun_if h) raddfN. Qed.
End RingProperties.
Section ScaleFun.
Variables (R : pzSemiRingType) (U : nmodType) (V : lSemiModType R).
Variables (a : R) (f : {additive U -> V}).
#[export]
HB.instance Definition _ :=
isNmodMorphism.Build V V ( *:%R a) (conj (scaler0 _ a) (scalerDr a)).
#[export]
HB.instance Definition _ := Additive.copy (a \*: f) (f \; *:%R a).
End ScaleFun.
End AdditiveTheory.
#[deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")]
Definition multiplicative (R S : pzSemiRingType) (f : R -> S) : Prop :=
{morph f : x y / x * y}%R * (f 1 = 1).
(* FIXME: remove once PzSemiRing extends Monoid. *)
Definition monoid_morphism (R S : pzSemiRingType) (f : R -> S) : Prop :=
(f 1 = 1) * {morph f : x y / x * y}%R.
HB.mixin Record isMonoidMorphism (R S : pzSemiRingType) (f : R -> S) := {
monoid_morphism_subproof : monoid_morphism f
}.
HB.structure Definition RMorphism (R S : pzSemiRingType) :=
{f of @isNmodMorphism R S f & isMonoidMorphism R S f}.
(* FIXME: remove the @ once
https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *)
#[warning="-deprecated-since-mathcomp-2.5.0"]
HB.factory Record isMultiplicative (R S : pzSemiRingType) (f : R -> S) := {
rmorphism_subproof : multiplicative f
}.
HB.builders Context R S f of isMultiplicative R S f.
#[warning="-HB.no-new-instance"]
HB.instance Definition _ := isMonoidMorphism.Build R S f
(rmorphism_subproof.2, rmorphism_subproof.1).
HB.end.
Module RMorphismExports.
Notation "{ 'rmorphism' U -> V }" := (RMorphism.type U%type V%type)
: type_scope.
End RMorphismExports.
HB.export RMorphismExports.
Section RmorphismTheory.
Section Properties.
Variables (R S : pzSemiRingType) (f : {rmorphism R -> S}).
Lemma rmorph0 : f 0 = 0. Proof. exact: raddf0. Qed.
Lemma rmorphD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed.
Lemma rmorphMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed.
Lemma rmorph_sum I r (P : pred I) E :
f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i).
Proof. exact: raddf_sum. Qed.
Lemma rmorphism_monoidP : monoid_morphism f.
Proof. exact: monoid_morphism_subproof. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `rmorphism_monoidP` instead")]
Definition rmorphismMP : multiplicative f :=
(fun p => (p.2, p.1)) rmorphism_monoidP.
Lemma rmorph1 : f 1 = 1. Proof. by case: rmorphism_monoidP. Qed.
Lemma rmorphM : {morph f: x y / x * y}. Proof. by case: rmorphism_monoidP. Qed.
Lemma rmorph_prod I r (P : pred I) E :
f (\prod_(i <- r | P i) E i) = \prod_(i <- r | P i) f (E i).
Proof. exact: (big_morph f rmorphM rmorph1). Qed.
Lemma rmorphXn n : {morph f : x / x ^+ n}.
Proof. by elim: n => [|n IHn] x; rewrite ?rmorph1 // !exprS rmorphM IHn. Qed.
Lemma rmorph_nat n : f n%:R = n%:R. Proof. by rewrite rmorphMn rmorph1. Qed.
Lemma rmorph_eq_nat x n : injective f -> (f x == n%:R) = (x == n%:R).
Proof. by move/inj_eq <-; rewrite rmorph_nat. Qed.
Lemma rmorph_eq1 x : injective f -> (f x == 1) = (x == 1).
Proof. exact: rmorph_eq_nat 1%N. Qed.
Lemma can2_monoid_morphism f' : cancel f f' -> cancel f' f -> monoid_morphism f'.
Proof.
move=> fK f'K.
by split=> [|x y]; apply: (canLR fK); rewrite /= (rmorph1, rmorphM) ?f'K.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `can2_monoid_morphism` instead")]
Definition can2_rmorphism f' (cff' : cancel f f') :=
(fun p => (p.2, p.1)) \o (can2_monoid_morphism cff').
End Properties.
Lemma rmorph_pchar (R S : nzSemiRingType) (f : {rmorphism R -> S}) p :
p \in pchar R -> p \in pchar S.
Proof.
by rewrite !inE -(rmorph_nat f) => /andP[-> /= /eqP->]; rewrite rmorph0.
Qed.
Section Projections.
Variables (R S T : pzSemiRingType).
Variables (f : {rmorphism S -> T}) (g : {rmorphism R -> S}).
Fact idfun_is_monoid_morphism : monoid_morphism (@idfun R).
Proof. by []. Qed.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build R R idfun
idfun_is_monoid_morphism.
Fact comp_is_monoid_morphism : monoid_morphism (f \o g).
Proof. by split=> [|x y] /=; rewrite ?rmorph1 ?rmorphM. Qed.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build R T (f \o g)
comp_is_monoid_morphism.
End Projections.
Section Properties.
Variables (R S : pzRingType) (f : {rmorphism R -> S}).
Lemma rmorphN : {morph f : x / - x}. Proof. exact: raddfN. Qed.
Lemma rmorphB : {morph f: x y / x - y}. Proof. exact: raddfB. Qed.
Lemma rmorphMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed.
Lemma rmorphMsign n : {morph f : x / (- 1) ^+ n * x}.
Proof. exact: raddfMsign. Qed.
Lemma rmorphN1 : f (- 1) = (- 1). Proof. by rewrite rmorphN rmorph1. Qed.
Lemma rmorph_sign n : f ((- 1) ^+ n) = (- 1) ^+ n.
Proof. by rewrite rmorphXn /= rmorphN1. Qed.
End Properties.
Section InSemiAlgebra.
Variables (R : pzSemiRingType) (A : lSemiAlgType R).
Fact in_alg_is_nmod_morphism : nmod_morphism (in_alg A).
Proof. by split; [exact: scale0r | exact: scalerDl]. Qed.
#[export]
HB.instance Definition _ :=
isNmodMorphism.Build R A (in_alg A) in_alg_is_nmod_morphism.
Fact in_alg_is_monoid_morphism : monoid_morphism (in_alg A).
Proof. by split=> [|x y]; rewrite /= ?scale1r // mulr_algl scalerA. Qed.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build R A (in_alg A)
in_alg_is_monoid_morphism.
Lemma in_algE a : in_alg A a = a%:A. Proof. by []. Qed.
End InSemiAlgebra.
End RmorphismTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")]
Notation rmorph_char := rmorph_pchar (only parsing).
Module Scale.
HB.mixin Record isPreLaw
(R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := {
op_nmod_morphism : forall a, nmod_morphism (op a);
}.
#[export]
HB.structure Definition PreLaw R V := {op of isPreLaw R V op}.
Definition preLaw := PreLaw.type.
HB.mixin Record isSemiLaw
(R : pzSemiRingType) (V : nmodType) (op : R -> V -> V) := {
op0v : forall v, op 0 v = 0;
op1v : op 1 =1 id;
opA : forall a b v, op a (op b v) = op (a * b) v;
}.
#[export]
HB.structure Definition SemiLaw R V :=
{op of isPreLaw R V op & isSemiLaw R V op}.
Definition semiLaw := SemiLaw.type.
HB.mixin Record isLaw (R : pzRingType) (V : zmodType) (op : R -> V -> V) :=
{ N1op : op (-1) =1 -%R }.
#[export]
HB.structure Definition Law (R : pzRingType) (V : zmodType) :=
{op of isPreLaw R V op & isLaw R V op}.
Definition law := Law.type.
Section CompSemiLaw.
Context (R : pzSemiRingType) (V : nmodType) (s : semiLaw R V).
Context (aR : pzSemiRingType) (nu : {rmorphism aR -> R}).
Fact comp_op0v v : (nu \; s) 0 v = 0.
Proof. by rewrite /= rmorph0 op0v. Qed.
Fact comp_op1v : (nu \; s) 1 =1 id.
Proof. by move=> v; rewrite /= rmorph1 op1v. Qed.
Fact comp_opA a b v : (nu \; s) a ((nu \; s) b v) = (nu \; s) (a * b) v.
Proof. by rewrite /= opA rmorphM. Qed.
End CompSemiLaw.
Fact compN1op
(R : pzRingType) (V : zmodType) (s : law R V)
(aR : pzRingType) (nu : {rmorphism aR -> R}) : (nu \; s) (-1) =1 -%R.
Proof. by move=> v; rewrite /= rmorphN1 N1op. Qed.
Module Exports. HB.reexport. End Exports.
End Scale.
Export Scale.Exports.
#[export]
HB.instance Definition _ (R : pzSemiRingType) :=
Scale.isPreLaw.Build R R *%R (fun => mull_fun_is_nmod_morphism _ idfun).
#[export]
HB.instance Definition _ (R : pzSemiRingType) :=
Scale.isSemiLaw.Build R R *%R mul0r mul1r mulrA.
#[export]
HB.instance Definition _ (R : pzRingType) :=
Scale.isLaw.Build R R *%R (@mulN1r R).
#[export]
HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) :=
Scale.isPreLaw.Build R V *:%R (fun => (scaler0 _ _, scalerDr _)).
#[export]
HB.instance Definition _ (R : pzSemiRingType) (V : lSemiModType R) :=
Scale.isSemiLaw.Build R V *:%R scale0r scale1r (@scalerA _ _).
#[export]
HB.instance Definition _ (R : pzRingType) (U : lmodType R) :=
Scale.isLaw.Build R U *:%R (@scaleN1r R U).
#[export]
HB.instance Definition _
(R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V)
(aR : pzSemiRingType) (nu : {rmorphism aR -> R}) :=
Scale.isPreLaw.Build aR V (nu \; s) (fun => Scale.op_nmod_morphism _).
#[export]
HB.instance Definition _
(R : pzSemiRingType) (V : nmodType) (s : Scale.semiLaw R V)
(aR : pzSemiRingType) (nu : {rmorphism aR -> R}) :=
Scale.isSemiLaw.Build aR V (nu \; s)
(Scale.comp_op0v s nu) (Scale.comp_op1v s nu) (Scale.comp_opA s nu).
#[export]
HB.instance Definition _
(R : pzRingType) (V : zmodType) (s : Scale.law R V)
(aR : pzRingType) (nu : {rmorphism aR -> R}) :=
Scale.isLaw.Build aR V (nu \; s) (Scale.compN1op s nu).
#[export, non_forgetful_inheritance]
HB.instance Definition _
(R : pzSemiRingType) (V : nmodType) (s : Scale.preLaw R V) a :=
isNmodMorphism.Build V V (s a) (Scale.op_nmod_morphism a).
Definition scalable_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType)
(s : R -> V -> V) (f : U -> V) :=
forall a, {morph f : u / a *: u >-> s a u}.
HB.mixin Record isScalable (R : pzSemiRingType) (U : lSemiModType R)
(V : nmodType) (s : R -> V -> V) (f : U -> V) := {
semi_linear_subproof : scalable_for s f;
}.
HB.structure Definition Linear (R : pzSemiRingType)
(U : lSemiModType R) (V : nmodType) (s : R -> V -> V) :=
{f of @isNmodMorphism U V f & isScalable R U V s f}.
Definition semilinear_for (R : pzSemiRingType)
(U : lSemiModType R) (V : nmodType) (s : R -> V -> V) (f : U -> V) : Type :=
scalable_for s f * {morph f : x y / x + y}.
Lemma nmod_morphism_semilinear (R : pzSemiRingType)
(U : lSemiModType R) (V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) :
semilinear_for s f -> nmod_morphism f.
Proof.
by case=> sf Df; split => //; rewrite -[0 in LHS](scale0r 0) sf Scale.op0v.
Qed.
Definition additive_semilinear := nmod_morphism_semilinear.
Lemma scalable_semilinear (R : pzSemiRingType)
(U : lSemiModType R) (V : nmodType) (s : Scale.preLaw R V) (f : U -> V) :
semilinear_for s f -> scalable_for s f.
Proof. by case. Qed.
HB.factory Record isSemilinear (R : pzSemiRingType) (U : lSemiModType R)
(V : nmodType) (s : Scale.semiLaw R V) (f : U -> V) := {
linear_subproof : semilinear_for s f;
}.
HB.builders Context R U V s f of isSemilinear R U V s f.
HB.instance Definition _ := isNmodMorphism.Build U V f
(additive_semilinear linear_subproof).
HB.instance Definition _ :=
isScalable.Build R U V s f (scalable_semilinear linear_subproof).
HB.end.
Definition linear_for (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType)
(s : R -> V -> V) (f : U -> V) :=
forall a, {morph f : u v / a *: u + v >-> s a u + v}.
Lemma zmod_morphism_linear (R : pzRingType) (U : lmodType R) V
(s : Scale.law R V) (f : U -> V) : linear_for s f -> zmod_morphism f.
Proof. by move=> Lsf x y; rewrite -scaleN1r addrC Lsf Scale.N1op addrC. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `zmod_morphism_linear` instead")]
Definition additive_linear := zmod_morphism_linear.
Lemma scalable_linear (R : pzRingType) (U : lmodType R) V
(s : Scale.law R V) (f : U -> V) : linear_for s f -> scalable_for s f.
Proof.
by move=> Lsf a v; rewrite -[a *:v](addrK v) (zmod_morphism_linear Lsf) Lsf addrK.
Qed.
Lemma semilinear_linear (R : pzRingType) (U : lmodType R) V
(s : Scale.law R V) (f : U -> V) : linear_for s f -> semilinear_for s f.
Proof.
move=> Lsf; split=> [a x|x y]; first exact: (scalable_linear Lsf).
have f0: f 0 = 0 by rewrite -[0 in LHS]subr0 (zmod_morphism_linear Lsf) subrr.
by rewrite -[y in LHS]opprK -[- y]add0r !(zmod_morphism_linear Lsf) f0 sub0r opprK.
Qed.
HB.factory Record isLinear (R : pzRingType) (U : lmodType R) (V : zmodType)
(s : Scale.law R V) (f : U -> V) := {
linear_subproof : linear_for s f;
}.
HB.builders Context R U V s f of isLinear R U V s f.
HB.instance Definition _ := isZmodMorphism.Build U V f
(zmod_morphism_linear linear_subproof).
HB.instance Definition _ := isScalable.Build R U V s f
(scalable_linear linear_subproof).
HB.end.
Module LinearExports.
Notation scalable f := (scalable_for *:%R f).
Notation semilinear f := (semilinear_for *:%R f).
Notation semiscalar f := (semilinear_for *%R f).
Notation linear f := (linear_for *:%R f).
Notation scalar f := (linear_for *%R f).
Module Linear.
Section Linear.
Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType).
Variables (s : R -> V -> V).
(* Support for right-to-left rewriting with the generic linearZ rule. *)
Local Notation mapUV := (@Linear.type R U V s).
Definition map_class := mapUV.
Definition map_at (a : R) := mapUV.
Structure map_for a s_a := MapFor {map_for_map : mapUV; _ : s a = s_a}.
Definition unify_map_at a (g : map_at a) := MapFor g (erefl (s a)).
Structure wrapped := Wrap {unwrap : mapUV}.
Definition wrap (f : map_class) := Wrap f.
End Linear.
End Linear.
Notation "{ 'linear' U -> V | s }" := (@Linear.type _ U V s) : type_scope.
Notation "{ 'linear' U -> V }" := {linear U -> V | *:%R} : type_scope.
Notation "{ 'scalar' U }" := {linear U -> _ | *%R}
(format "{ 'scalar' U }") : type_scope.
(* Support for right-to-left rewriting with the generic linearZ rule. *)
Coercion Linear.map_for_map : Linear.map_for >-> Linear.type.
Coercion Linear.unify_map_at : Linear.map_at >-> Linear.map_for.
Canonical Linear.unify_map_at.
Coercion Linear.unwrap : Linear.wrapped >-> Linear.type.
Coercion Linear.wrap : Linear.map_class >-> Linear.wrapped.
Canonical Linear.wrap.
End LinearExports.
HB.export LinearExports.
Section LinearTheory.
Section GenericProperties.
Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType).
Variables (s : R -> V -> V) (f : {linear U -> V | s}).
Lemma linear0 : f 0 = 0. Proof. exact: raddf0. Qed.
Lemma linearD : {morph f : x y / x + y}. Proof. exact: raddfD. Qed.
Lemma linearMn n : {morph f : x / x *+ n}. Proof. exact: raddfMn. Qed.
Lemma linear_sum I r (P : pred I) E :
f (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f (E i).
Proof. exact: raddf_sum. Qed.
Lemma linearZ_LR : scalable_for s f. Proof. exact: semi_linear_subproof. Qed.
Lemma semilinearP : semilinear_for s f.
Proof. split; [exact: linearZ_LR | exact: linearD]. Qed.
Lemma linearP : linear_for s f.
Proof. by move=> a u v /=; rewrite !semilinearP. Qed.
End GenericProperties.
Section GenericProperties.
Variables (R : pzRingType) (U : lmodType R) (V : zmodType) (s : R -> V -> V).
Variables (f : {linear U -> V | s}).
Lemma linearN : {morph f : x / - x}. Proof. exact: raddfN. Qed.
Lemma linearB : {morph f : x y / x - y}. Proof. exact: raddfB. Qed.
Lemma linearMNn n : {morph f : x / x *- n}. Proof. exact: raddfMNn. Qed.
End GenericProperties.
Section BidirectionalLinearZ.
(* The general form of the linearZ lemma uses some bespoke interfaces to *)
(* allow right-to-left rewriting when a composite scaling operation such as *)
(* conjC \; *%R has been expanded, say in a^* * f u. This redex is matched *)
(* by using the Scale.law interface to recognize a "head" scaling operation *)
(* h (here *%R), stow away its "scalar" c, then reconcile h c and s a, once *)
(* s is known, that is, once the Linear.map structure for f has been found. *)
(* In general, s and a need not be equal to h and c; indeed they need not *)
(* have the same type! The unification is performed by the unify_map_at *)
(* default instance for the Linear.map_for U s a h_c sub-interface of *)
(* Linear.map; the h_c pattern uses the Scale.law structure to insure it is *)
(* inferred when rewriting right-to-left. *)
(* The wrap on the rhs allows rewriting f (a *: b *: u) into a *: b *: f u *)
(* with rewrite !linearZ /= instead of rewrite linearZ /= linearZ /=. *)
(* Without it, the first rewrite linearZ would produce *)
(* (a *: apply (map_for_map (@check_map_at .. a f)) (b *: u)%R)%Rlin *)
(* and matching the second rewrite LHS would bypass the unify_map_at default *)
(* instance for b, reuse the one for a, and subsequently fail to match the *)
(* b *: u argument. The extra wrap / unwrap ensures that this can't happen. *)
(* In the RL direction, the wrap / unwrap will be inserted on the redex side *)
(* as needed, without causing unnecessary delta-expansion: using an explicit *)
(* identity function would have Coq normalize the redex to head normal, then *)
(* reduce the identity to expose the map_for_map projection, and the *)
(* expanded Linear.map structure would then be exposed in the result. *)
(* Most of this machinery will be invisible to a casual user, because all *)
(* the projections and default instances involved are declared as coercions. *)
Lemma linearZ (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType)
(s : R -> V -> V) (S : pzSemiRingType) (h : Scale.preLaw S V)
(c : S) (a : R) (h_c := h c) (f : Linear.map_for U s a h_c) (u : U) :
f (a *: u) = h_c (Linear.wrap f u).
Proof. by rewrite linearZ_LR; case: f => f /= ->. Qed.
End BidirectionalLinearZ.
Section LmodProperties.
Variables (R : pzSemiRingType) (U V : lSemiModType R) (f : {linear U -> V}).
Lemma linearZZ : scalable f. Proof. exact: linearZ_LR. Qed.
Lemma semilinearPZ : semilinear f. Proof. exact: semilinearP. Qed.
Lemma linearPZ : linear f. Proof. exact: linearP. Qed.
Lemma can2_scalable f' : cancel f f' -> cancel f' f -> scalable f'.
Proof. by move=> fK f'K a x; apply: (canLR fK); rewrite linearZZ f'K. Qed.
Lemma can2_semilinear f' : cancel f f' -> cancel f' f -> semilinear f'.
Proof.
by move=> fK f'K; split=> ? ?; apply: (canLR fK); rewrite semilinearPZ !f'K.
Qed.
Lemma can2_linear f' : cancel f f' -> cancel f' f -> linear f'.
Proof. by move=> fK f'K a x y /=; apply: (canLR fK); rewrite linearP !f'K. Qed.
End LmodProperties.
Section ScalarProperties.
Variable (R : pzSemiRingType) (U : lSemiModType R) (f : {scalar U}).
Lemma scalarZ : scalable_for *%R f. Proof. exact: linearZ_LR. Qed.
Lemma semiscalarP : semiscalar f. Proof. exact: semilinearP. Qed.
Lemma scalarP : scalar f. Proof. exact: linearP. Qed.
End ScalarProperties.
Section LinearLSemiMod.
Section Idfun.
Variables (R : pzSemiRingType) (U : lSemiModType R).
Lemma idfun_is_scalable : scalable (@idfun U). Proof. by []. Qed.
#[export]
HB.instance Definition _ := isScalable.Build R U U *:%R idfun idfun_is_scalable.
End Idfun.
Section Plain.
Variables (R : pzSemiRingType) (W U : lSemiModType R) (V : nmodType).
Variables (s : R -> V -> V) (f : {linear U -> V | s}) (g : {linear W -> U}).
Lemma comp_is_scalable : scalable_for s (f \o g).
Proof. by move=> a v /=; rewrite !linearZ_LR. Qed.
#[export]
HB.instance Definition _ := isScalable.Build R W V s (f \o g) comp_is_scalable.
End Plain.
Section SemiScale.
Variables (R : pzSemiRingType) (U : lSemiModType R) (V : nmodType).
Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}).
Lemma null_fun_is_scalable : scalable_for s (\0 : U -> V).
Proof. by move=> a v /=; rewrite raddf0. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R U V s \0 null_fun_is_scalable.
Lemma add_fun_is_scalable : scalable_for s (add_fun f g).
Proof. by move=> a u; rewrite /= !linearZ_LR raddfD. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R U V s (f \+ g) add_fun_is_scalable.
End SemiScale.
End LinearLSemiMod.
Section LinearLmod.
Variables (R : pzRingType) (U : lmodType R).
Lemma opp_is_scalable : scalable (-%R : U -> U).
Proof. by move=> a v /=; rewrite scalerN. Qed.
#[export]
HB.instance Definition _ := isScalable.Build R U U *:%R -%R opp_is_scalable.
End LinearLmod.
Section Scale.
Variables (R : pzRingType) (U : lmodType R) (V : zmodType).
Variables (s : Scale.preLaw R V) (f g : {linear U -> V | s}).
Lemma sub_fun_is_scalable : scalable_for s (f \- g).
Proof. by move=> a u; rewrite /= !linearZ_LR raddfB. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R U V s (f \- g) sub_fun_is_scalable.
Lemma opp_fun_is_scalable : scalable_for s (\- f).
Proof. by move=> a u; rewrite /= linearZ_LR raddfN. Qed.
#[export]
HB.instance Definition _ := isScalable.Build R U V s (\- f) opp_fun_is_scalable.
End Scale.
Section LinearLSemiAlg.
Variables (R : pzSemiRingType) (A : lSemiAlgType R) (U : lSemiModType R).
Variables (a : A) (f : {linear U -> A}).
Fact mulr_fun_is_scalable : scalable (a \o* f).
Proof. by move=> k x /=; rewrite linearZ scalerAl. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R U A *:%R (a \o* f) mulr_fun_is_scalable.
End LinearLSemiAlg.
End LinearTheory.
HB.structure Definition LRMorphism (R : pzSemiRingType) (A : lSemiAlgType R)
(B : pzSemiRingType) (s : R -> B -> B) :=
{f of @RMorphism A B f & isScalable R A B s f}.
(* FIXME: remove the @ once
https://github.com/math-comp/hierarchy-builder/issues/319 is fixed *)
Module LRMorphismExports.
Notation "{ 'lrmorphism' A -> B | s }" := (@LRMorphism.type _ A%type B%type s)
: type_scope.
Notation "{ 'lrmorphism' A -> B }" := {lrmorphism A%type -> B%type | *:%R}
: type_scope.
End LRMorphismExports.
HB.export LRMorphismExports.
Section LRMorphismTheory.
Variables (R : pzSemiRingType) (A B : lSemiAlgType R) (C : pzSemiRingType).
Variables (s : R -> C -> C).
Variables (f : {lrmorphism A -> B}) (g : {lrmorphism B -> C | s}).
#[export] HB.instance Definition _ := RMorphism.on (@idfun A).
#[export] HB.instance Definition _ := RMorphism.on (g \o f).
Lemma rmorph_alg a : f a%:A = a%:A.
Proof. by rewrite linearZ /= rmorph1. Qed.
End LRMorphismTheory.
HB.mixin Record PzSemiRing_hasCommutativeMul R of PzSemiRing R := {
mulrC : commutative (@mul R)
}.
Module SemiRing_hasCommutativeMul.
#[deprecated(since="mathcomp 2.4.0",
note="Use PzSemiRing_hasCommutativeMul.Build instead.")]
Notation Build R := (PzSemiRing_hasCommutativeMul.Build R) (only parsing).
End SemiRing_hasCommutativeMul.
#[deprecated(since="mathcomp 2.4.0",
note="Use PzSemiRing_hasCommutativeMul instead.")]
Notation SemiRing_hasCommutativeMul R :=
(PzSemiRing_hasCommutativeMul R) (only parsing).
#[short(type="comPzSemiRingType")]
HB.structure Definition ComPzSemiRing :=
{R of PzSemiRing R & PzSemiRing_hasCommutativeMul R}.
Module ComPzSemiRingExports.
Bind Scope ring_scope with ComPzSemiRing.sort.
End ComPzSemiRingExports.
HB.export ComPzSemiRingExports.
HB.factory Record Nmodule_isComPzSemiRing R of Nmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mulrC : commutative mul;
mul1r : left_id one mul;
mulrDl : left_distributive mul add;
mul0r : left_zero zero mul;
}.
HB.builders Context R of Nmodule_isComPzSemiRing R.
Definition mulr1 := Monoid.mulC_id mulrC mul1r.
Definition mulrDr := Monoid.mulC_dist mulrC mulrDl.
Lemma mulr0 : right_zero zero mul.
Proof. by move=> x; rewrite mulrC mul0r. Qed.
HB.instance Definition _ := Nmodule_isPzSemiRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0.
HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC.
HB.end.
#[short(type="comNzSemiRingType")]
HB.structure Definition ComNzSemiRing :=
{R of NzSemiRing R & PzSemiRing_hasCommutativeMul R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzSemiRing instead.")]
Notation ComSemiRing R := (ComNzSemiRing R) (only parsing).
Module ComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzSemiRing.sort instead.")]
Notation sort := (ComNzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzSemiRing.on instead.")]
Notation on R := (ComNzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzSemiRing.copy instead.")]
Notation copy T U := (ComNzSemiRing.copy T U) (only parsing).
End ComSemiRing.
Module ComNzSemiRingExports.
Bind Scope ring_scope with ComNzSemiRing.sort.
End ComNzSemiRingExports.
HB.export ComNzSemiRingExports.
HB.factory Record Nmodule_isComNzSemiRing R of Nmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mulrC : commutative mul;
mul1r : left_id one mul;
mulrDl : left_distributive mul add;
mul0r : left_zero zero mul;
oner_neq0 : one != zero
}.
Module Nmodule_isComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Nmodule_isComNzSemiRing.Build instead.")]
Notation Build R := (Nmodule_isComNzSemiRing.Build R) (only parsing).
End Nmodule_isComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Nmodule_isComNzSemiRing instead.")]
Notation Nmodule_isComSemiRing R := (Nmodule_isComNzSemiRing R) (only parsing).
HB.builders Context R of Nmodule_isComNzSemiRing R.
Definition mulr1 := Monoid.mulC_id mulrC mul1r.
Definition mulrDr := Monoid.mulC_dist mulrC mulrDl.
Lemma mulr0 : right_zero zero mul.
Proof. by move=> x; rewrite mulrC mul0r. Qed.
HB.instance Definition _ := Nmodule_isNzSemiRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0 oner_neq0.
HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC.
HB.end.
Section ComSemiRingTheory.
Variable R : comPzSemiRingType.
Implicit Types x y : R.
#[export]
HB.instance Definition _ := SemiGroup.isCommutativeLaw.Build R *%R mulrC.
Lemma mulrCA : @left_commutative R R *%R. Proof. exact: mulmCA. Qed.
Lemma mulrAC : @right_commutative R R *%R. Proof. exact: mulmAC. Qed.
Lemma mulrACA : @interchange R *%R *%R. Proof. exact: mulmACA. Qed.
Lemma exprMn n : {morph (fun x => x ^+ n) : x y / x * y}.
Proof. by move=> x y; exact/exprMn_comm/mulrC. Qed.
Lemma prodrXl n I r (P : pred I) (F : I -> R) :
\prod_(i <- r | P i) F i ^+ n = (\prod_(i <- r | P i) F i) ^+ n.
Proof. by rewrite (big_morph _ (exprMn n) (expr1n _ n)). Qed.
Lemma prodr_undup_exp_count (I : eqType) r (P : pred I) (F : I -> R) :
\prod_(i <- undup r | P i) F i ^+ count_mem i r = \prod_(i <- r | P i) F i.
Proof. exact: big_undup_iterop_count. Qed.
Lemma prodrMl {I : finType} (A : pred I) (x : R) F :
\prod_(i in A) (x * F i) = x ^+ #|A| * \prod_(i in A) F i.
Proof. by rewrite big_split ?prodr_const. Qed.
Lemma prodrMr {I : finType} (A : pred I) (x : R) F :
\prod_(i in A) (F i * x) = \prod_(i in A) F i * x ^+ #|A|.
Proof. by rewrite big_split ?prodr_const. Qed.
Lemma exprDn x y n :
(x + y) ^+ n = \sum_(i < n.+1) (x ^+ (n - i) * y ^+ i) *+ 'C(n, i).
Proof. by rewrite exprDn_comm //; apply: mulrC. Qed.
Lemma sqrrD x y : (x + y) ^+ 2 = x ^+ 2 + x * y *+ 2 + y ^+ 2.
Proof. by rewrite exprDn !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed.
End ComSemiRingTheory.
(* FIXME: Generalize to `comPzSemiRingType` ? *)
Section ComNzSemiRingTheory.
Variable R : comNzSemiRingType.
Implicit Types x y : R.
Section FrobeniusAutomorphism.
Variables (p : nat) (pcharRp : p \in pchar R).
Lemma pFrobenius_aut_is_nmod_morphism : nmod_morphism (pFrobenius_aut pcharRp).
Proof.
by split=> [|x y]; [exact: pFrobenius_aut0 | exact/pFrobenius_autD_comm/mulrC].
Qed.
Lemma pFrobenius_aut_is_monoid_morphism : monoid_morphism (pFrobenius_aut pcharRp).
Proof.
by split=> [|x y]; [exact: pFrobenius_aut1 | exact/pFrobenius_autM_comm/mulrC].
Qed.
#[export]
HB.instance Definition _ := isNmodMorphism.Build R R (pFrobenius_aut pcharRp)
pFrobenius_aut_is_nmod_morphism.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build R R (pFrobenius_aut pcharRp)
pFrobenius_aut_is_monoid_morphism.
End FrobeniusAutomorphism.
Lemma exprDn_pchar x y n : (pchar R).-nat n -> (x + y) ^+ n = x ^+ n + y ^+ n.
Proof.
pose p := pdiv n; have [|n_gt1 pcharRn] := leqP n 1; first by case: (n) => [|[]].
have pcharRp: p \in pchar R by rewrite (pnatPpi pcharRn) ?pi_pdiv.
have{pcharRn} /p_natP[e ->]: p.-nat n by rewrite -(eq_pnat _ (pcharf_eq pcharRp)).
by elim: e => // e IHe; rewrite !expnSr !exprM IHe -pFrobenius_autE rmorphD.
Qed.
(* FIXME: Generalize to `comPzSemiRingType` ? *)
Lemma rmorph_comm (S : nzSemiRingType) (f : {rmorphism R -> S}) x y :
comm (f x) (f y).
Proof. by red; rewrite -!rmorphM mulrC. Qed.
Section ScaleLinear.
Variables (U V : lSemiModType R) (b : R) (f : {linear U -> V}).
Lemma scale_is_scalable : scalable ( *:%R b : V -> V).
Proof. by move=> a v /=; rewrite !scalerA mulrC. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R V V *:%R ( *:%R b) scale_is_scalable.
Lemma scale_fun_is_scalable : scalable (b \*: f).
Proof. by move=> a v /=; rewrite !linearZ. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R U V *:%R (b \*: f) scale_fun_is_scalable.
End ScaleLinear.
End ComNzSemiRingTheory.
#[short(type="comPzRingType")]
HB.structure Definition ComPzRing := {R of PzRing R & ComPzSemiRing R}.
HB.factory Record PzRing_hasCommutativeMul R of PzRing R := {
mulrC : commutative (@mul R)
}.
Module Ring_hasCommutativeMul.
#[deprecated(since="mathcomp 2.4.0",
note="Use PzRing_hasCommutativeMul.Build instead.")]
Notation Build R := (PzRing_hasCommutativeMul.Build R) (only parsing).
End Ring_hasCommutativeMul.
#[deprecated(since="mathcomp 2.4.0",
note="Use PzRing_hasCommutativeMul instead.")]
Notation Ring_hasCommutativeMul R :=
(PzRing_hasCommutativeMul R) (only parsing).
HB.builders Context R of PzRing_hasCommutativeMul R.
HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build R mulrC.
HB.end.
HB.factory Record Zmodule_isComPzRing R of Zmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mulrC : commutative mul;
mul1r : left_id one mul;
mulrDl : left_distributive mul add;
}.
HB.builders Context R of Zmodule_isComPzRing R.
Definition mulr1 := Monoid.mulC_id mulrC mul1r.
Definition mulrDr := Monoid.mulC_dist mulrC mulrDl.
HB.instance Definition _ := Zmodule_isPzRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr.
HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC.
HB.end.
Module ComPzRingExports.
Bind Scope ring_scope with ComPzRing.sort.
End ComPzRingExports.
HB.export ComPzRingExports.
#[deprecated(since="mathcomp 2.5.0",
note="Use pFrobenius_aut_is_monoid_morphism instead.")]
Notation pFrobenius_aut_is_multiplicative :=
(fun p => (p.2, p.1) \o pFrobenius_aut_is_monoid_morphism) (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")]
Notation exprDn_char := exprDn_pchar (only parsing).
#[short(type="comNzRingType")]
HB.structure Definition ComNzRing := {R of NzRing R & ComNzSemiRing R}.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing instead.")]
Notation ComRing R := (ComNzRing R) (only parsing).
Module ComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing.sort instead.")]
Notation sort := (ComNzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing.on instead.")]
Notation on R := (ComNzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing.copy instead.")]
Notation copy T U := (ComNzRing.copy T U) (only parsing).
End ComRing.
HB.factory Record Zmodule_isComNzRing R of Zmodule R := {
one : R;
mul : R -> R -> R;
mulrA : associative mul;
mulrC : commutative mul;
mul1r : left_id one mul;
mulrDl : left_distributive mul add;
oner_neq0 : one != zero
}.
Module Zmodule_isComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Zmodule_isComNzRing.Build instead.")]
Notation Build R := (Zmodule_isComNzRing.Build R) (only parsing).
End Zmodule_isComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use Zmodule_isComNzRing instead.")]
Notation Zmodule_isComRing R := (Zmodule_isComNzRing R) (only parsing).
HB.builders Context R of Zmodule_isComNzRing R.
Definition mulr1 := Monoid.mulC_id mulrC mul1r.
Definition mulrDr := Monoid.mulC_dist mulrC mulrDl.
HB.instance Definition _ := Zmodule_isNzRing.Build R
mulrA mul1r mulr1 mulrDl mulrDr oner_neq0.
HB.instance Definition _ := PzRing_hasCommutativeMul.Build R mulrC.
HB.end.
Module ComNzRingExports.
Bind Scope ring_scope with ComNzRing.sort.
End ComNzRingExports.
HB.export ComNzRingExports.
Section ComPzRingTheory.
Variable R : comPzRingType.
Implicit Types x y : R.
Lemma exprBn x y n :
(x - y) ^+ n =
\sum_(i < n.+1) ((-1) ^+ i * x ^+ (n - i) * y ^+ i) *+ 'C(n, i).
Proof. by rewrite exprBn_comm //; apply: mulrC. Qed.
Lemma subrXX x y n :
x ^+ n - y ^+ n = (x - y) * (\sum_(i < n) x ^+ (n.-1 - i) * y ^+ i).
Proof. by rewrite -subrXX_comm //; apply: mulrC. Qed.
Lemma sqrrB x y : (x - y) ^+ 2 = x ^+ 2 - x * y *+ 2 + y ^+ 2.
Proof. by rewrite sqrrD mulrN mulNrn sqrrN. Qed.
Lemma subr_sqr x y : x ^+ 2 - y ^+ 2 = (x - y) * (x + y).
Proof. by rewrite subrXX !big_ord_recr big_ord0 /= add0r mulr1 mul1r. Qed.
Lemma subr_sqrDB x y : (x + y) ^+ 2 - (x - y) ^+ 2 = x * y *+ 4.
Proof.
rewrite sqrrD sqrrB -!(addrAC _ (y ^+ 2)) opprB.
by rewrite [LHS]addrC addrA subrK -mulrnDr.
Qed.
End ComPzRingTheory.
HB.mixin Record LSemiAlgebra_isSemiAlgebra R V of LSemiAlgebra R V := {
scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y);
}.
#[short(type="semiAlgType")]
HB.structure Definition SemiAlgebra (R : pzSemiRingType) :=
{A of LSemiAlgebra_isSemiAlgebra R A & LSemiAlgebra R A}.
Module SemiAlgExports.
Bind Scope ring_scope with SemiAlgebra.sort.
End SemiAlgExports.
HB.factory Record LSemiAlgebra_isComSemiAlgebra R V
of ComPzSemiRing V & LSemiAlgebra R V := {}.
HB.builders Context (R : pzSemiRingType) V of LSemiAlgebra_isComSemiAlgebra R V.
Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y).
Proof. by rewrite mulrC scalerAl mulrC. Qed.
HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalarAr.
HB.end.
#[short(type="algType")]
HB.structure Definition Algebra (R : pzRingType) :=
{A of LSemiAlgebra_isSemiAlgebra R A & Lalgebra R A}.
Module AlgExports.
Bind Scope ring_scope with Algebra.sort.
End AlgExports.
HB.export AlgExports.
HB.factory Record Lalgebra_isAlgebra (R : pzRingType) V of Lalgebra R V := {
scalerAr : forall k (x y : V), k *: (x * y) = x * (k *: y);
}.
HB.builders Context (R : pzRingType) V of Lalgebra_isAlgebra R V.
HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R V scalerAr.
HB.end.
HB.factory Record Lalgebra_isComAlgebra R V of ComPzRing V & Lalgebra R V := {}.
HB.builders Context (R : pzRingType) V of Lalgebra_isComAlgebra R V.
Lemma scalarAr k (x y : V) : k *: (x * y) = x * (k *: y).
Proof. by rewrite mulrC scalerAl mulrC. Qed.
HB.instance Definition lalgebra_is_algebra : Lalgebra_isAlgebra R V :=
Lalgebra_isAlgebra.Build R V scalarAr.
HB.end.
#[short(type="comSemiAlgType")]
HB.structure Definition ComSemiAlgebra R :=
{V of ComNzSemiRing V & SemiAlgebra R V}.
Module ComSemiAlgExports.
Bind Scope ring_scope with ComSemiAlgebra.sort.
End ComSemiAlgExports.
HB.export ComSemiAlgExports.
Section SemiAlgebraTheory.
#[export]
HB.instance Definition _ (R : comPzSemiRingType) :=
PzSemiRing_hasCommutativeMul.Build R^c (fun _ _ => mulrC _ _).
#[export]
HB.instance Definition _ (R : comPzSemiRingType) := ComPzSemiRing.on R^o.
#[export]
HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^c.
#[export]
HB.instance Definition _ (R : comNzSemiRingType) := ComNzSemiRing.on R^o.
#[export]
HB.instance Definition _ (R : comNzSemiRingType) :=
LSemiAlgebra_isComSemiAlgebra.Build R R^o.
End SemiAlgebraTheory.
#[short(type="comAlgType")]
HB.structure Definition ComAlgebra R := {V of ComNzRing V & Algebra R V}.
Module ComAlgExports.
Bind Scope ring_scope with ComAlgebra.sort.
End ComAlgExports.
HB.export ComAlgExports.
Section AlgebraTheory.
#[export]
HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^c.
#[export]
HB.instance Definition _ (R : comPzRingType) := ComPzRing.on R^o.
#[export]
HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^c.
#[export]
HB.instance Definition _ (R : comNzRingType) := ComNzRing.on R^o.
End AlgebraTheory.
Section SemiAlgebraTheory.
Variables (R : pzSemiRingType) (A : semiAlgType R).
Implicit Types (k : R) (x y : A).
Lemma scalerCA k x y : k *: x * y = x * (k *: y).
Proof. by rewrite -scalerAl scalerAr. Qed.
Lemma mulr_algr a x : x * a%:A = a *: x.
Proof. by rewrite -scalerAr mulr1. Qed.
Lemma comm_alg a x : comm a%:A x.
Proof. by rewrite /comm mulr_algr mulr_algl. Qed.
Lemma exprZn k x n : (k *: x) ^+ n = k ^+ n *: x ^+ n.
Proof.
elim: n => [|n IHn]; first by rewrite !expr0 scale1r.
by rewrite !exprS IHn -scalerA scalerAr scalerAl.
Qed.
Lemma scaler_prod I r (P : pred I) (F : I -> R) (G : I -> A) :
\prod_(i <- r | P i) (F i *: G i) =
\prod_(i <- r | P i) F i *: \prod_(i <- r | P i) G i.
Proof.
elim/big_rec3: _ => [|i x a _ _ ->]; first by rewrite scale1r.
by rewrite -scalerAl -scalerAr scalerA.
Qed.
Lemma scaler_prodl (I : finType) (S : pred I) (F : I -> A) k :
\prod_(i in S) (k *: F i) = k ^+ #|S| *: \prod_(i in S) F i.
Proof. by rewrite scaler_prod prodr_const. Qed.
Lemma scaler_prodr (I : finType) (S : pred I) (F : I -> R) x :
\prod_(i in S) (F i *: x) = \prod_(i in S) F i *: x ^+ #|S|.
Proof. by rewrite scaler_prod prodr_const. Qed.
End SemiAlgebraTheory.
Section AlgebraTheory.
Variables (R : pzSemiRingType) (A : semiAlgType R).
Variables (U : lSemiModType R) (a : A) (f : {linear U -> A}).
Lemma mull_fun_is_scalable : scalable (a \*o f).
Proof. by move=> k x /=; rewrite linearZ scalerAr. Qed.
#[export]
HB.instance Definition _ := isScalable.Build R U A *:%R (a \*o f)
mull_fun_is_scalable.
End AlgebraTheory.
HB.mixin Record NzRing_hasMulInverse R of NzRing R := {
unit_subdef : pred R;
inv : R -> R;
mulVr_subproof : {in unit_subdef, left_inverse 1 inv *%R};
divrr_subproof : {in unit_subdef, right_inverse 1 inv *%R};
unitrP_subproof : forall x y, y * x = 1 /\ x * y = 1 -> unit_subdef x;
invr_out_subproof : {in [predC unit_subdef], inv =1 id}
}.
Module Ring_hasMulInverse.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing_hasMulInverse.Build instead.")]
Notation Build R := (NzRing_hasMulInverse.Build R) (only parsing).
End Ring_hasMulInverse.
#[deprecated(since="mathcomp 2.4.0",
note="Use NzRing_hasMulInverse instead.")]
Notation Ring_hasMulInverse R := (NzRing_hasMulInverse R) (only parsing).
#[short(type="unitRingType")]
HB.structure Definition UnitRing := {R of NzRing_hasMulInverse R & NzRing R}.
Module UnitRingExports.
Bind Scope ring_scope with UnitRing.sort.
End UnitRingExports.
HB.export UnitRingExports.
Definition unit_pred {R : unitRingType} :=
Eval cbv [ unit_subdef NzRing_hasMulInverse.unit_subdef ] in
(fun u : R => unit_subdef u).
Arguments unit_pred _ _ /.
Definition unit {R : unitRingType} := [qualify a u : R | unit_pred u].
Local Notation "x ^-1" := (inv x).
Local Notation "x / y" := (x * y^-1).
Local Notation "x ^- n" := ((x ^+ n)^-1).
Section UnitRingTheory.
Variable R : unitRingType.
Implicit Types x y : R.
Lemma divrr : {in unit, right_inverse 1 (@inv R) *%R}.
Proof. exact: divrr_subproof. Qed.
Definition mulrV := divrr.
Lemma mulVr : {in unit, left_inverse 1 (@inv R) *%R}.
Proof. exact: mulVr_subproof. Qed.
Lemma invr_out x : x \isn't a unit -> x^-1 = x.
Proof. exact: invr_out_subproof. Qed.
Lemma unitrP x : reflect (exists y, y * x = 1 /\ x * y = 1) (x \is a unit).
Proof.
apply: (iffP idP) => [Ux | []]; last exact: unitrP_subproof.
by exists x^-1; rewrite divrr ?mulVr.
Qed.
Lemma mulKr : {in unit, left_loop (@inv R) *%R}.
Proof. by move=> x Ux y; rewrite mulrA mulVr ?mul1r. Qed.
Lemma mulVKr : {in unit, rev_left_loop (@inv R) *%R}.
Proof. by move=> x Ux y; rewrite mulrA mulrV ?mul1r. Qed.
Lemma mulrK : {in unit, right_loop (@inv R) *%R}.
Proof. by move=> x Ux y; rewrite -mulrA divrr ?mulr1. Qed.
Lemma mulrVK : {in unit, rev_right_loop (@inv R) *%R}.
Proof. by move=> x Ux y; rewrite -mulrA mulVr ?mulr1. Qed.
Definition divrK := mulrVK.
Lemma mulrI : {in @unit R, right_injective *%R}.
Proof. by move=> x Ux; apply: can_inj (mulKr Ux). Qed.
Lemma mulIr : {in @unit R, left_injective *%R}.
Proof. by move=> x Ux; apply: can_inj (mulrK Ux). Qed.
(* Due to noncommutativity, fractions are inverted. *)
Lemma telescope_prodr n m (f : nat -> R) :
(forall k, n < k < m -> f k \is a unit) -> n < m ->
\prod_(n <= k < m) (f k / f k.+1) = f n / f m.
Proof.
move=> Uf ltnm; rewrite (telescope_big (fun i j => f i / f j)) ?ltnm//.
by move=> k ltnkm /=; rewrite mulrA divrK// Uf.
Qed.
Lemma telescope_prodr_eq n m (f u : nat -> R) : n < m ->
(forall k, n < k < m -> f k \is a unit) ->
(forall k, (n <= k < m)%N -> u k = f k / f k.+1) ->
\prod_(n <= k < m) u k = f n / f m.
Proof.
by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodr.
Qed.
Lemma commrV x y : comm x y -> comm x y^-1.
Proof.
have [Uy cxy | /invr_out-> //] := boolP (y \in unit).
by apply: (canLR (mulrK Uy)); rewrite -mulrA cxy mulKr.
Qed.
Lemma unitrE x : (x \is a unit) = (x / x == 1).
Proof.
apply/idP/eqP=> [Ux | xx1]; first exact: divrr.
by apply/unitrP; exists x^-1; rewrite -commrV.
Qed.
Lemma invrK : involutive (@inv R).
Proof.
move=> x; case Ux: (x \in unit); last by rewrite !invr_out ?Ux.
rewrite -(mulrK Ux _^-1) -mulrA commrV ?mulKr //.
by apply/unitrP; exists x; rewrite divrr ?mulVr.
Qed.
Lemma invr_inj : injective (@inv R). Proof. exact: inv_inj invrK. Qed.
Lemma unitrV x : (x^-1 \in unit) = (x \in unit).
Proof. by rewrite !unitrE invrK commrV. Qed.
Lemma unitr1 : 1 \in @unit R.
Proof. by apply/unitrP; exists 1; rewrite mulr1. Qed.
Lemma invr1 : 1^-1 = 1 :> R.
Proof. by rewrite -{2}(mulVr unitr1) mulr1. Qed.
Lemma div1r x : 1 / x = x^-1. Proof. by rewrite mul1r. Qed.
Lemma divr1 x : x / 1 = x. Proof. by rewrite invr1 mulr1. Qed.
Lemma natr_div m d :
d %| m -> d%:R \is a @unit R -> (m %/ d)%:R = m%:R / d%:R :> R.
Proof.
by rewrite dvdn_eq => /eqP def_m unit_d; rewrite -{2}def_m natrM mulrK.
Qed.
Lemma divrI : {in unit, right_injective (fun x y => x / y)}.
Proof. by move=> x /mulrI/inj_comp; apply; apply: invr_inj. Qed.
Lemma divIr : {in unit, left_injective (fun x y => x / y)}.
Proof. by move=> x; rewrite -unitrV => /mulIr. Qed.
Lemma unitr0 : (0 \is a @unit R) = false.
Proof. by apply/unitrP=> [[x [_ /esym/eqP]]]; rewrite mul0r oner_eq0. Qed.
Lemma invr0 : 0^-1 = 0 :> R.
Proof. by rewrite invr_out ?unitr0. Qed.
Lemma unitrN1 : -1 \is a @unit R.
Proof. by apply/unitrP; exists (-1); rewrite mulrNN mulr1. Qed.
Lemma invrN1 : (-1)^-1 = -1 :> R.
Proof. by rewrite -{2}(divrr unitrN1) mulN1r opprK. Qed.
Lemma invr_sign n : ((-1) ^- n) = (-1) ^+ n :> R.
Proof. by rewrite -signr_odd; case: (odd n); rewrite (invr1, invrN1). Qed.
Lemma unitrMl x y : y \is a unit -> (x * y \is a unit) = (x \is a unit).
Proof.
move=> Uy; wlog Ux: x y Uy / x \is a unit => [WHxy|].
by apply/idP/idP=> Ux; first rewrite -(mulrK Uy x); rewrite WHxy ?unitrV.
rewrite Ux; apply/unitrP; exists (y^-1 * x^-1).
by rewrite -!mulrA mulKr ?mulrA ?mulrK ?divrr ?mulVr.
Qed.
Lemma unitrMr x y : x \is a unit -> (x * y \is a unit) = (y \is a unit).
Proof.
move=> Ux; apply/idP/idP=> [Uxy | Uy]; last by rewrite unitrMl.
by rewrite -(mulKr Ux y) unitrMl ?unitrV.
Qed.
Lemma unitr_prod {I : Type} (P : pred I) (E : I -> R) (r : seq I) :
(forall i, P i -> E i \is a GRing.unit) ->
(\prod_(i <- r | P i) E i \is a GRing.unit).
Proof.
by move=> Eunit; elim/big_rec: _ => [/[!unitr1] |i x /Eunit/unitrMr->].
Qed.
Lemma unitr_prod_in {I : eqType} (P : pred I) (E : I -> R) (r : seq I) :
{in r, forall i, P i -> E i \is a GRing.unit} ->
(\prod_(i <- r | P i) E i \is a GRing.unit).
Proof.
by rewrite big_seq_cond => H; apply: unitr_prod => i /andP[]; exact: H.
Qed.
Lemma invrM : {in unit &, forall x y, (x * y)^-1 = y^-1 * x^-1}.
Proof.
move=> x y Ux Uy; have Uxy: (x * y \in unit) by rewrite unitrMl.
by apply: (mulrI Uxy); rewrite divrr ?mulrA ?mulrK ?divrr.
Qed.
Lemma unitrM_comm x y :
comm x y -> (x * y \is a unit) = (x \is a unit) && (y \is a unit).
Proof.
move=> cxy; apply/idP/andP=> [Uxy | [Ux Uy]]; last by rewrite unitrMl.
suffices Ux: x \in unit by rewrite unitrMr in Uxy.
apply/unitrP; case/unitrP: Uxy => z [zxy xyz]; exists (y * z).
rewrite mulrA xyz -{1}[y]mul1r -{1}zxy cxy -!mulrA (mulrA x) (mulrA _ z) xyz.
by rewrite mul1r -cxy.
Qed.
Lemma unitrX x n : x \is a unit -> x ^+ n \is a unit.
Proof.
by move=> Ux; elim: n => [|n IHn]; rewrite ?unitr1 // exprS unitrMl.
Qed.
Lemma unitrX_pos x n : n > 0 -> (x ^+ n \in unit) = (x \in unit).
Proof.
case: n => // n _; rewrite exprS unitrM_comm; last exact: commrX.
by case Ux: (x \is a unit); rewrite // unitrX.
Qed.
Lemma exprVn x n : x^-1 ^+ n = x ^- n.
Proof.
elim: n => [|n IHn]; first by rewrite !expr0 ?invr1.
case Ux: (x \is a unit); first by rewrite exprSr exprS IHn -invrM // unitrX.
by rewrite !invr_out ?unitrX_pos ?Ux.
Qed.
Lemma exprB m n x : n <= m -> x \is a unit -> x ^+ (m - n) = x ^+ m / x ^+ n.
Proof. by move/subnK=> {2}<- Ux; rewrite exprD mulrK ?unitrX. Qed.
Lemma invr_neq0 x : x != 0 -> x^-1 != 0.
Proof.
move=> nx0; case Ux: (x \is a unit); last by rewrite invr_out ?Ux.
by apply/eqP=> x'0; rewrite -unitrV x'0 unitr0 in Ux.
Qed.
Lemma invr_eq0 x : (x^-1 == 0) = (x == 0).
Proof. by apply: negb_inj; apply/idP/idP; move/invr_neq0; rewrite ?invrK. Qed.
Lemma invr_eq1 x : (x^-1 == 1) = (x == 1).
Proof. by rewrite (inv_eq invrK) invr1. Qed.
Lemma rev_unitrP (x y : R^c) : y * x = 1 /\ x * y = 1 -> x \is a unit.
Proof. by case=> [yx1 xy1]; apply/unitrP; exists y. Qed.
#[export]
HB.instance Definition _ :=
NzRing_hasMulInverse.Build R^c mulrV mulVr rev_unitrP invr_out.
#[export]
HB.instance Definition _ := UnitRing.on R^o.
End UnitRingTheory.
Arguments invrK {R}.
Arguments invr_inj {R} [x1 x2].
Arguments telescope_prodr_eq {R n m} f u.
Lemma rev_prodrV (R : unitRingType)
(I : Type) (r : seq I) (P : pred I) (E : I -> R) :
(forall i, P i -> E i \is a GRing.unit) ->
\prod_(i <- r | P i) (E i)^-1 = ((\prod_(i <- r | P i) (E i : R^c))^-1).
Proof.
move=> Eunit; symmetry.
apply: (big_morph_in GRing.unit _ _ (unitr1 R^c) (@invrM _) (invr1 _)) Eunit.
by move=> x y xunit; rewrite unitrMr.
Qed.
Section UnitRingClosedPredicates.
Variables (R : unitRingType) (S : {pred R}).
Definition invr_closed := {in S, forall x, x^-1 \in S}.
Definition divr_2closed := {in S &, forall x y, x / y \in S}.
Definition divr_closed := 1 \in S /\ divr_2closed.
Definition sdivr_closed := -1 \in S /\ divr_2closed.
Definition divring_closed := [/\ 1 \in S, subr_2closed S & divr_2closed].
Lemma divr_closedV : divr_closed -> invr_closed.
Proof. by case=> S1 Sdiv x Sx; rewrite -[x^-1]mul1r Sdiv. Qed.
Lemma divr_closedM : divr_closed -> mulr_closed S.
Proof.
by case=> S1 Sdiv; split=> // x y Sx Sy; rewrite -[y]invrK -[y^-1]mul1r !Sdiv.
Qed.
Lemma sdivr_closed_div : sdivr_closed -> divr_closed.
Proof. by case=> SN1 Sdiv; split; rewrite // -(divrr (@unitrN1 _)) Sdiv. Qed.
Lemma sdivr_closedM : sdivr_closed -> smulr_closed S.
Proof.
by move=> Sdiv; have [_ SM] := divr_closedM (sdivr_closed_div Sdiv); case: Sdiv.
Qed.
Lemma divring_closedBM : divring_closed -> subring_closed S.
Proof. by case=> S1 SB Sdiv; split=> //; case: divr_closedM. Qed.
Lemma divring_closed_div : divring_closed -> sdivr_closed.
Proof.
case=> S1 SB Sdiv; split; rewrite ?zmod_closedN //.
exact/subring_closedB/divring_closedBM.
Qed.
End UnitRingClosedPredicates.
Section UnitRingMorphism.
Variables (R S : unitRingType) (f : {rmorphism R -> S}).
Lemma rmorph_unit x : x \in unit -> f x \in unit.
Proof.
case/unitrP=> y [yx1 xy1]; apply/unitrP.
by exists (f y); rewrite -!rmorphM // yx1 xy1 rmorph1.
Qed.
Lemma rmorphV : {in unit, {morph f: x / x^-1}}.
Proof.
move=> x Ux; rewrite /= -[(f x)^-1]mul1r.
by apply: (canRL (mulrK (rmorph_unit Ux))); rewrite -rmorphM mulVr ?rmorph1.
Qed.
Lemma rmorph_div x y : y \in unit -> f (x / y) = f x / f y.
Proof. by move=> Uy; rewrite rmorphM /= rmorphV. Qed.
End UnitRingMorphism.
#[short(type="comUnitRingType")]
HB.structure Definition ComUnitRing := {R of ComNzRing R & UnitRing R}.
Module ComUnitRingExports.
Bind Scope ring_scope with ComUnitRing.sort.
End ComUnitRingExports.
HB.export ComUnitRingExports.
(* TODO_HB: fix the name (was ComUnitRingMixin) *)
HB.factory Record ComNzRing_hasMulInverse R of ComNzRing R := {
unit : {pred R};
inv : R -> R;
mulVx : {in unit, left_inverse 1 inv *%R};
unitPl : forall x y, y * x = 1 -> unit x;
invr_out : {in [predC unit], inv =1 id}
}.
Module ComRing_hasMulInverse.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing_hasMulInverse.Build instead.")]
Notation Build R := (ComNzRing_hasMulInverse.Build R) (only parsing).
End ComRing_hasMulInverse.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing_hasMulInverse instead.")]
Notation ComRing_hasMulInverse R := (ComNzRing_hasMulInverse R) (only parsing).
HB.builders Context R of ComNzRing_hasMulInverse R.
Fact mulC_mulrV : {in unit, right_inverse 1 inv *%R}.
Proof. by move=> x Ux /=; rewrite mulrC mulVx. Qed.
Fact mulC_unitP x y : y * x = 1 /\ x * y = 1 -> unit x.
Proof. by case=> yx _; apply: unitPl yx. Qed.
HB.instance Definition _ :=
NzRing_hasMulInverse.Build R mulVx mulC_mulrV mulC_unitP invr_out.
HB.end.
#[short(type="unitAlgType")]
HB.structure Definition UnitAlgebra R := {V of Algebra R V & UnitRing V}.
Module UnitAlgebraExports.
Bind Scope ring_scope with UnitAlgebra.sort.
End UnitAlgebraExports.
HB.export UnitAlgebraExports.
#[short(type="comUnitAlgType")]
HB.structure Definition ComUnitAlgebra R := {V of ComAlgebra R V & UnitRing V}.
Module ComUnitAlgebraExports.
Bind Scope ring_scope with UnitAlgebra.sort.
End ComUnitAlgebraExports.
HB.export ComUnitAlgebraExports.
Section ComUnitRingTheory.
Variable R : comUnitRingType.
Implicit Types x y : R.
Lemma unitrM x y : (x * y \in unit) = (x \in unit) && (y \in unit).
Proof. exact/unitrM_comm/mulrC. Qed.
Lemma unitrPr x : reflect (exists y, x * y = 1) (x \in unit).
Proof.
by apply: (iffP (unitrP x)) => [[y []] | [y]]; exists y; rewrite // mulrC.
Qed.
Lemma mulr1_eq x y : x * y = 1 -> x^-1 = y.
Proof.
by move=> xy_eq1; rewrite -[LHS]mulr1 -xy_eq1; apply/mulKr/unitrPr; exists y.
Qed.
Lemma divr1_eq x y : x / y = 1 -> x = y. Proof. by move/mulr1_eq/invr_inj. Qed.
Lemma divKr x : x \is a unit -> {in unit, involutive (fun y => x / y)}.
Proof. by move=> Ux y Uy; rewrite /= invrM ?unitrV // invrK mulrC divrK. Qed.
Lemma expr_div_n x y n : (x / y) ^+ n = x ^+ n / y ^+ n.
Proof. by rewrite exprMn exprVn. Qed.
Lemma unitr_prodP (I : eqType) (r : seq I) (P : pred I) (E : I -> R) :
reflect {in r, forall i, P i -> E i \is a GRing.unit}
(\prod_(i <- r | P i) E i \is a GRing.unit).
Proof.
rewrite (big_morph [in unit] unitrM (@unitr1 _) ) big_all_cond.
exact: 'all_implyP.
Qed.
Lemma prodrV (I : eqType) (r : seq I) (P : pred I) (E : I -> R) :
(forall i, P i -> E i \is a GRing.unit) ->
\prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1.
Proof.
by move=> /rev_prodrV->; rewrite rev_prodr (perm_big r)// perm_rev.
Qed.
(* TODO: HB.saturate *)
#[export] HB.instance Definition _ := ComUnitRing.on R^c.
#[export] HB.instance Definition _ := ComUnitRing.on R^o.
(* /TODO *)
End ComUnitRingTheory.
Section UnitAlgebraTheory.
Variable (R : comUnitRingType) (A : unitAlgType R).
Implicit Types (k : R) (x y : A).
Lemma scaler_injl : {in unit, @right_injective R A A *:%R}.
Proof.
move=> k Uk x1 x2 Hx1x2.
by rewrite -[x1]scale1r -(mulVr Uk) -scalerA Hx1x2 scalerA mulVr // scale1r.
Qed.
Lemma scaler_unit k x : k \in unit -> (k *: x \in unit) = (x \in unit).
Proof.
move=> Uk; apply/idP/idP=> [Ukx | Ux]; apply/unitrP; last first.
exists (k^-1 *: x^-1).
by rewrite -!scalerAl -!scalerAr !scalerA !mulVr // !mulrV // scale1r.
exists (k *: (k *: x)^-1); split.
apply: (mulrI Ukx).
by rewrite mulr1 mulrA -scalerAr mulrV // -scalerAl mul1r.
apply: (mulIr Ukx).
by rewrite mul1r -mulrA -scalerAl mulVr // -scalerAr mulr1.
Qed.
Lemma invrZ k x : k \in unit -> x \in unit -> (k *: x)^-1 = k^-1 *: x^-1.
Proof.
move=> Uk Ux; have Ukx: (k *: x \in unit) by rewrite scaler_unit.
apply: (mulIr Ukx).
by rewrite mulVr // -scalerAl -scalerAr scalerA !mulVr // scale1r.
Qed.
Section ClosedPredicates.
Variables S : {pred A}.
Definition divalg_closed := [/\ 1 \in S, linear_closed S & divr_2closed S].
Lemma divalg_closedBdiv : divalg_closed -> divring_closed S.
Proof. by case=> S1 /linear_closedB. Qed.
Lemma divalg_closedZ : divalg_closed -> subalg_closed S.
Proof. by case=> S1 Slin Sdiv; split=> //; have [] := @divr_closedM A S. Qed.
End ClosedPredicates.
End UnitAlgebraTheory.
Module ClosedExports.
Notation addr_closed := nmod_closed.
Notation oppr_closed := oppr_closed.
Notation zmod_closed := zmod_closed.
Notation mulr_closed := mulr_closed.
Notation semiring_closed := semiring_closed.
Notation smulr_closed := smulr_closed.
Notation subring_closed := subring_closed.
Notation scaler_closed := scaler_closed.
Notation subsemimod_closed := subsemimod_closed.
Notation linear_closed := linear_closed.
Notation submod_closed := submod_closed.
Notation subalg_closed := subalg_closed.
Notation invr_closed := invr_closed.
Notation divr_2closed := divr_2closed.
Notation divr_closed := divr_closed.
Notation sdivr_closed := sdivr_closed.
Notation divring_closed := divring_closed.
Notation divalg_closed := divalg_closed.
Coercion zmod_closedD : zmod_closed >-> nmod_closed.
Coercion zmod_closedN : zmod_closed >-> oppr_closed.
Coercion semiring_closedD : semiring_closed >-> addr_closed.
Coercion semiring_closedM : semiring_closed >-> mulr_closed.
Coercion smulr_closedM : smulr_closed >-> mulr_closed.
Coercion smulr_closedN : smulr_closed >-> oppr_closed.
Coercion subring_closedB : subring_closed >-> zmod_closed.
Coercion subring_closedM : subring_closed >-> smulr_closed.
Coercion subring_closed_semi : subring_closed >-> semiring_closed.
Coercion subsemimod_closedD : subsemimod_closed >-> addr_closed.
Coercion subsemimod_closedZ : subsemimod_closed >-> scaler_closed.
Coercion linear_closedB : linear_closed >-> subr_2closed.
Coercion submod_closedB : submod_closed >-> zmod_closed.
Coercion submod_closed_semi : submod_closed >-> subsemimod_closed.
Coercion subalg_closedZ : subalg_closed >-> submod_closed.
Coercion subalg_closedBM : subalg_closed >-> subring_closed.
Coercion divr_closedV : divr_closed >-> invr_closed.
Coercion divr_closedM : divr_closed >-> mulr_closed.
Coercion sdivr_closed_div : sdivr_closed >-> divr_closed.
Coercion sdivr_closedM : sdivr_closed >-> smulr_closed.
Coercion divring_closedBM : divring_closed >-> subring_closed.
Coercion divring_closed_div : divring_closed >-> sdivr_closed.
Coercion divalg_closedBdiv : divalg_closed >-> divring_closed.
Coercion divalg_closedZ : divalg_closed >-> subalg_closed.
End ClosedExports.
(* Reification of the theory of rings with units, in named style *)
Section TermDef.
Variable R : Type.
Inductive term : Type :=
| Var of nat
| Const of R
| NatConst of nat
| Add of term & term
| Opp of term
| NatMul of term & nat
| Mul of term & term
| Inv of term
| Exp of term & nat.
Inductive formula : Type :=
| Bool of bool
| Equal of term & term
| Unit of term
| And of formula & formula
| Or of formula & formula
| Implies of formula & formula
| Not of formula
| Exists of nat & formula
| Forall of nat & formula.
End TermDef.
Bind Scope term_scope with term.
Bind Scope term_scope with formula.
Arguments Add {R} t1%_T t2%_T.
Arguments Opp {R} t1%_T.
Arguments NatMul {R} t1%_T n%_N.
Arguments Mul {R} t1%_T t2%_T.
Arguments Inv {R} t1%_T.
Arguments Exp {R} t1%_T n%_N.
Arguments Equal {R} t1%_T t2%_T.
Arguments Unit {R} t1%_T.
Arguments And {R} f1%_T f2%_T.
Arguments Or {R} f1%_T f2%_T.
Arguments Implies {R} f1%_T f2%_T.
Arguments Not {R} f1%_T.
Arguments Exists {R} i%_N f1%_T.
Arguments Forall {R} i%_N f1%_T.
Arguments Bool {R} b.
Arguments Const {R} x.
Notation True := (Bool true).
Notation False := (Bool false).
Local Notation "''X_' i" := (Var _ i) : term_scope.
Local Notation "n %:R" := (NatConst _ n) : term_scope.
Local Notation "x %:T" := (Const x) : term_scope.
Local Notation "0" := 0%:R%T : term_scope.
Local Notation "1" := 1%:R%T : term_scope.
Local Infix "+" := Add : term_scope.
Local Notation "- t" := (Opp t) : term_scope.
Local Notation "t - u" := (Add t (- u)) : term_scope.
Local Infix "*" := Mul : term_scope.
Local Infix "*+" := NatMul : term_scope.
Local Notation "t ^-1" := (Inv t) : term_scope.
Local Notation "t / u" := (Mul t u^-1) : term_scope.
Local Infix "^+" := Exp : term_scope.
Local Infix "==" := Equal : term_scope.
Local Infix "/\" := And : term_scope.
Local Infix "\/" := Or : term_scope.
Local Infix "==>" := Implies : term_scope.
Local Notation "~ f" := (Not f) : term_scope.
Local Notation "x != y" := (Not (x == y)) : term_scope.
Local Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope.
Local Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope.
Section Substitution.
Variable R : Type.
Fixpoint tsubst (t : term R) (s : nat * term R) :=
match t with
| 'X_i => if i == s.1 then s.2 else t
| _%:T | _%:R => t
| t1 + t2 => tsubst t1 s + tsubst t2 s
| - t1 => - tsubst t1 s
| t1 *+ n => tsubst t1 s *+ n
| t1 * t2 => tsubst t1 s * tsubst t2 s
| t1^-1 => (tsubst t1 s)^-1
| t1 ^+ n => tsubst t1 s ^+ n
end%T.
Fixpoint fsubst (f : formula R) (s : nat * term R) :=
match f with
| Bool _ => f
| t1 == t2 => tsubst t1 s == tsubst t2 s
| Unit t1 => Unit (tsubst t1 s)
| f1 /\ f2 => fsubst f1 s /\ fsubst f2 s
| f1 \/ f2 => fsubst f1 s \/ fsubst f2 s
| f1 ==> f2 => fsubst f1 s ==> fsubst f2 s
| ~ f1 => ~ fsubst f1 s
| ('exists 'X_i, f1) => 'exists 'X_i, if i == s.1 then f1 else fsubst f1 s
| ('forall 'X_i, f1) => 'forall 'X_i, if i == s.1 then f1 else fsubst f1 s
end%T.
End Substitution.
Section EvalTerm.
Variable R : unitRingType.
(* Evaluation of a reified term into R a ring with units *)
Fixpoint eval (e : seq R) (t : term R) {struct t} : R :=
match t with
| ('X_i)%T => e`_i
| (x%:T)%T => x
| (n%:R)%T => n%:R
| (t1 + t2)%T => eval e t1 + eval e t2
| (- t1)%T => - eval e t1
| (t1 *+ n)%T => eval e t1 *+ n
| (t1 * t2)%T => eval e t1 * eval e t2
| t1^-1%T => (eval e t1)^-1
| (t1 ^+ n)%T => eval e t1 ^+ n
end.
Definition same_env (e e' : seq R) := nth 0 e =1 nth 0 e'.
Lemma eq_eval e e' t : same_env e e' -> eval e t = eval e' t.
Proof. by move=> eq_e; elim: t => //= t1 -> // t2 ->. Qed.
Lemma eval_tsubst e t s :
eval e (tsubst t s) = eval (set_nth 0 e s.1 (eval e s.2)) t.
Proof.
case: s => i u; elim: t => //=; do 2?[move=> ? -> //] => j.
by rewrite nth_set_nth /=; case: (_ == _).
Qed.
(* Evaluation of a reified formula *)
Fixpoint holds (e : seq R) (f : formula R) {struct f} : Prop :=
match f with
| Bool b => b
| (t1 == t2)%T => eval e t1 = eval e t2
| Unit t1 => eval e t1 \in unit
| (f1 /\ f2)%T => holds e f1 /\ holds e f2
| (f1 \/ f2)%T => holds e f1 \/ holds e f2
| (f1 ==> f2)%T => holds e f1 -> holds e f2
| (~ f1)%T => ~ holds e f1
| ('exists 'X_i, f1)%T => exists x, holds (set_nth 0 e i x) f1
| ('forall 'X_i, f1)%T => forall x, holds (set_nth 0 e i x) f1
end.
Lemma same_env_sym e e' : same_env e e' -> same_env e' e.
Proof. exact: fsym. Qed.
(* Extensionality of formula evaluation *)
Lemma eq_holds e e' f : same_env e e' -> holds e f -> holds e' f.
Proof.
pose sv := set_nth (0 : R).
have eq_i i v e1 e2: same_env e1 e2 -> same_env (sv e1 i v) (sv e2 i v).
by move=> eq_e j; rewrite !nth_set_nth /= eq_e.
elim: f e e' => //=.
- by move=> t1 t2 e e' eq_e; rewrite !(eq_eval _ eq_e).
- by move=> t e e' eq_e; rewrite (eq_eval _ eq_e).
- by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto.
- by move=> f1 IH1 f2 IH2 e e' eq_e; move/IH2: (eq_e); move/IH1: eq_e; tauto.
- by move=> f1 IH1 f2 IH2 e e' eq_e f12; move/IH1: (same_env_sym eq_e); eauto.
- by move=> f1 IH1 e e'; move/same_env_sym; move/IH1; tauto.
- by move=> i f1 IH1 e e'; move/(eq_i i)=> eq_e [x f_ex]; exists x; eauto.
by move=> i f1 IH1 e e'; move/(eq_i i); eauto.
Qed.
(* Evaluation and substitution by a constant *)
Lemma holds_fsubst e f i v :
holds e (fsubst f (i, v%:T)%T) <-> holds (set_nth 0 e i v) f.
Proof.
elim: f e => //=; do [
by move=> *; rewrite !eval_tsubst
| move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto
| move=> f IHf e; move: (IHf e); tauto
| move=> j f IHf e].
- case eq_ji: (j == i); first rewrite (eqP eq_ji).
by split=> [] [x f_x]; exists x; rewrite set_set_nth eqxx in f_x *.
split=> [] [x f_x]; exists x; move: f_x; rewrite set_set_nth eq_sym eq_ji;
have:= IHf (set_nth 0 e j x); tauto.
case eq_ji: (j == i); first rewrite (eqP eq_ji).
by split=> [] f_ x; move: (f_ x); rewrite set_set_nth eqxx.
split=> [] f_ x; move: (IHf (set_nth 0 e j x)) (f_ x);
by rewrite set_set_nth 1?[i == j]eq_sym eq_ji; tauto.
Qed.
(* Boolean test selecting terms in the language of rings *)
Fixpoint rterm (t : term R) :=
match t with
| _^-1 => false
| t1 + t2 | t1 * t2 => rterm t1 && rterm t2
| - t1 | t1 *+ _ | t1 ^+ _ => rterm t1
| _ => true
end%T.
(* Boolean test selecting formulas in the theory of rings *)
Fixpoint rformula (f : formula R) :=
match f with
| Bool _ => true
| t1 == t2 => rterm t1 && rterm t2
| Unit t1 => false
| f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => rformula f1 && rformula f2
| ~ f1 | ('exists 'X__, f1) | ('forall 'X__, f1) => rformula f1
end%T.
(* Upper bound of the names used in a term *)
Fixpoint ub_var (t : term R) :=
match t with
| 'X_i => i.+1
| t1 + t2 | t1 * t2 => maxn (ub_var t1) (ub_var t2)
| - t1 | t1 *+ _ | t1 ^+ _ | t1^-1 => ub_var t1
| _ => 0%N
end%T.
(* Replaces inverses in the term t by fresh variables, accumulating the *)
(* substitution. *)
Fixpoint to_rterm (t : term R) (r : seq (term R)) (n : nat) {struct t} :=
match t with
| t1^-1 =>
let: (t1', r1) := to_rterm t1 r n in
('X_(n + size r1), rcons r1 t1')
| t1 + t2 =>
let: (t1', r1) := to_rterm t1 r n in
let: (t2', r2) := to_rterm t2 r1 n in
(t1' + t2', r2)
| - t1 =>
let: (t1', r1) := to_rterm t1 r n in
(- t1', r1)
| t1 *+ m =>
let: (t1', r1) := to_rterm t1 r n in
(t1' *+ m, r1)
| t1 * t2 =>
let: (t1', r1) := to_rterm t1 r n in
let: (t2', r2) := to_rterm t2 r1 n in
(Mul t1' t2', r2)
| t1 ^+ m =>
let: (t1', r1) := to_rterm t1 r n in
(t1' ^+ m, r1)
| _ => (t, r)
end%T.
Lemma to_rterm_id t r n : rterm t -> to_rterm t r n = (t, r).
Proof.
elim: t r n => //.
- by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2.
- by move=> t IHt r n /= rt; rewrite {}IHt.
- by move=> t IHt r n m /= rt; rewrite {}IHt.
- by move=> t1 IHt1 t2 IHt2 r n /= /andP[rt1 rt2]; rewrite {}IHt1 // IHt2.
- by move=> t IHt r n m /= rt; rewrite {}IHt.
Qed.
(* A ring formula stating that t1 is equal to 0 in the ring theory. *)
(* Also applies to non commutative rings. *)
Definition eq0_rform t1 :=
let m := ub_var t1 in
let: (t1', r1) := to_rterm t1 [::] m in
let fix loop r i := match r with
| [::] => t1' == 0
| t :: r' =>
let f := 'X_i * t == 1 /\ t * 'X_i == 1 in
'forall 'X_i, (f \/ 'X_i == t /\ ~ ('exists 'X_i, f)) ==> loop r' i.+1
end%T
in loop r1 m.
(* Transformation of a formula in the theory of rings with units into an *)
(* equivalent formula in the sub-theory of rings. *)
Fixpoint to_rform f :=
match f with
| Bool b => f
| t1 == t2 => eq0_rform (t1 - t2)
| Unit t1 => eq0_rform (t1 * t1^-1 - 1)
| f1 /\ f2 => to_rform f1 /\ to_rform f2
| f1 \/ f2 => to_rform f1 \/ to_rform f2
| f1 ==> f2 => to_rform f1 ==> to_rform f2
| ~ f1 => ~ to_rform f1
| ('exists 'X_i, f1) => 'exists 'X_i, to_rform f1
| ('forall 'X_i, f1) => 'forall 'X_i, to_rform f1
end%T.
(* The transformation gives a ring formula. *)
Lemma to_rform_rformula f : rformula (to_rform f).
Proof.
suffices eq0_ring t1: rformula (eq0_rform t1) by elim: f => //= => f1 ->.
rewrite /eq0_rform; move: (ub_var t1) => m; set tr := _ m.
suffices: all rterm (tr.1 :: tr.2).
case: tr => {}t1 r /= /andP[t1_r].
by elim: r m => [|t r IHr] m; rewrite /= ?andbT // => /andP[->]; apply: IHr.
have: all rterm [::] by [].
rewrite {}/tr; elim: t1 [::] => //=.
- move=> t1 IHt1 t2 IHt2 r.
move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r].
move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r].
by rewrite t1_r t2_r.
- by move=> t1 IHt1 r /IHt1; case: to_rterm.
- by move=> t1 IHt1 n r /IHt1; case: to_rterm.
- move=> t1 IHt1 t2 IHt2 r.
move/IHt1; case: to_rterm => {r IHt1}t1 r /= /andP[t1_r].
move/IHt2; case: to_rterm => {r IHt2}t2 r /= /andP[t2_r].
by rewrite t1_r t2_r.
- move=> t1 IHt1 r.
by move/IHt1; case: to_rterm => {r IHt1}t1 r /=; rewrite all_rcons.
- by move=> t1 IHt1 n r /IHt1; case: to_rterm.
Qed.
(* Correctness of the transformation. *)
Lemma to_rformP e f : holds e (to_rform f) <-> holds e f.
Proof.
suffices{e f} equal0_equiv e t1 t2:
holds e (eq0_rform (t1 - t2)) <-> (eval e t1 == eval e t2).
- elim: f e => /=; try tauto.
+ move=> t1 t2 e.
by split; [move/equal0_equiv/eqP | move/eqP/equal0_equiv].
+ by move=> t1 e; rewrite unitrE; apply: equal0_equiv.
+ by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto.
+ by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto.
+ by move=> f1 IHf1 f2 IHf2 e; move: (IHf1 e) (IHf2 e); tauto.
+ by move=> f1 IHf1 e; move: (IHf1 e); tauto.
+ by move=> n f1 IHf1 e; split=> [] [x] /IHf1; exists x.
+ by move=> n f1 IHf1 e; split=> Hx x; apply/IHf1.
rewrite -(add0r (eval e t2)) -(can2_eq (subrK _) (addrK _)).
rewrite -/(eval e (t1 - t2)); move: (t1 - t2)%T => {t1 t2} t.
have sub_var_tsubst s t0: s.1 >= ub_var t0 -> tsubst t0 s = t0.
elim: t0 {t} => //=.
- by move=> n; case: ltngtP.
- by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->].
- by move=> t1 IHt1 /IHt1->.
- by move=> t1 IHt1 n /IHt1->.
- by move=> t1 IHt1 t2 IHt2; rewrite geq_max => /andP[/IHt1-> /IHt2->].
- by move=> t1 IHt1 /IHt1->.
- by move=> t1 IHt1 n /IHt1->.
pose fix rsub t' m r : term R :=
if r is u :: r' then tsubst (rsub t' m.+1 r') (m, u^-1)%T else t'.
pose fix ub_sub m r : Prop :=
if r is u :: r' then ub_var u <= m /\ ub_sub m.+1 r' else true.
suffices{t} rsub_to_r t r0 m: m >= ub_var t -> ub_sub m r0 ->
let: (t', r) := to_rterm t r0 m in
[/\ take (size r0) r = r0,
ub_var t' <= m + size r, ub_sub m r & rsub t' m r = t].
- have:= rsub_to_r t [::] _ (leqnn _); rewrite /eq0_rform.
case: (to_rterm _ _ _) => [t1' r1] [//|_ _ ub_r1 def_t].
rewrite -{2}def_t {def_t}.
elim: r1 (ub_var t) e ub_r1 => [|u r1 IHr1] m e /= => [_|[ub_u ub_r1]].
by split=> /eqP.
rewrite eval_tsubst /=; set y := eval e u; split=> t_eq0.
apply/IHr1=> //; apply: t_eq0.
rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)).
rewrite sub_var_tsubst //= -/y.
case Uy: (y \in unit); [left | right]; first by rewrite mulVr ?divrr.
split=> [|[z]]; first by rewrite invr_out ?Uy.
rewrite nth_set_nth /= eqxx.
rewrite -!(eval_tsubst _ _ (m, Const _)) !sub_var_tsubst // -/y => yz1.
by case/unitrP: Uy; exists z.
move=> x def_x; apply/IHr1=> //; suff ->: x = y^-1 by []; move: def_x.
rewrite nth_set_nth /= eqxx -(eval_tsubst e u (m, Const _)).
rewrite sub_var_tsubst //= -/y; case=> [[xy1 yx1] | [xy nUy]].
by rewrite -[y^-1]mul1r -[1]xy1 mulrK //; apply/unitrP; exists x.
rewrite invr_out //; apply/unitrP=> [[z yz1]]; case: nUy; exists z.
rewrite nth_set_nth /= eqxx -!(eval_tsubst _ _ (m, _%:T)%T).
by rewrite !sub_var_tsubst.
have rsub_id r t0 n: ub_var t0 <= n -> rsub t0 n r = t0.
by elim: r n => //= t1 r IHr n let0n; rewrite IHr ?sub_var_tsubst ?leqW.
have rsub_acc r s t1 m1:
ub_var t1 <= m1 + size r -> rsub t1 m1 (r ++ s) = rsub t1 m1 r.
elim: r t1 m1 => [|t1 r IHr] t2 m1 /=; first by rewrite addn0; apply: rsub_id.
by move=> letmr; rewrite IHr ?addSnnS.
elim: t r0 m => /=; try do [
by move=> n r m hlt hub; rewrite take_size (ltn_addr _ hlt) rsub_id
| by move=> n r m hlt hub; rewrite leq0n take_size rsub_id
| move=> t1 IHt1 t2 IHt2 r m; rewrite geq_max; case/andP=> hub1 hub2 hmr;
case: to_rterm {hub1 hmr}(IHt1 r m hub1 hmr) => t1' r1;
case=> htake1 hub1' hsub1 <-;
case: to_rterm {IHt2 hub2 hsub1}(IHt2 r1 m hub2 hsub1) => t2' r2 /=;
rewrite geq_max; case=> htake2 -> hsub2 /= <-;
rewrite -{1 2}(cat_take_drop (size r1) r2) htake2; set r3 := drop _ _;
rewrite size_cat addnA (leq_trans _ (leq_addr _ _)) //;
split=> {hsub2}//;
first by [rewrite takel_cat // -htake1 size_take geq_min leqnn orbT];
rewrite -(rsub_acc r1 r3 t1') {hub1'}// -{htake1}htake2 {r3}cat_take_drop;
by elim: r2 m => //= u r2 IHr2 m; rewrite IHr2
| do [ move=> t1 IHt1 r m; do 2!move=> /IHt1{}IHt1
| move=> t1 IHt1 n r m; do 2!move=> /IHt1{}IHt1];
case: to_rterm IHt1 => t1' r1 [-> -> hsub1 <-]; split=> {hsub1}//;
by elim: r1 m => //= u r1 IHr1 m; rewrite IHr1].
move=> t1 IH r m letm /IH {IH} /(_ letm) {letm}.
case: to_rterm => t1' r1 /= [def_r ub_t1' ub_r1 <-].
rewrite size_rcons addnS leqnn -{1}cats1 takel_cat ?def_r; last first.
by rewrite -def_r size_take geq_min leqnn orbT.
elim: r1 m ub_r1 ub_t1' {def_r} => /= [|u r1 IHr1] m => [_|[->]].
by rewrite addn0 eqxx.
by rewrite -addSnnS => /IHr1 IH /IH[_ _ ub_r1 ->].
Qed.
(* Boolean test selecting formulas which describe a constructible set, *)
(* i.e. formulas without quantifiers. *)
(* The quantifier elimination check. *)
Fixpoint qf_form (f : formula R) :=
match f with
| Bool _ | _ == _ | Unit _ => true
| f1 /\ f2 | f1 \/ f2 | f1 ==> f2 => qf_form f1 && qf_form f2
| ~ f1 => qf_form f1
| _ => false
end%T.
(* Boolean holds predicate for quantifier free formulas *)
Definition qf_eval e := fix loop (f : formula R) : bool :=
match f with
| Bool b => b
| t1 == t2 => (eval e t1 == eval e t2)%bool
| Unit t1 => eval e t1 \in unit
| f1 /\ f2 => loop f1 && loop f2
| f1 \/ f2 => loop f1 || loop f2
| f1 ==> f2 => (loop f1 ==> loop f2)%bool
| ~ f1 => ~~ loop f1
|_ => false
end%T.
(* qf_eval is equivalent to holds *)
Lemma qf_evalP e f : qf_form f -> reflect (holds e f) (qf_eval e f).
Proof.
elim: f => //=; try by move=> *; apply: idP.
- by move=> t1 t2 _; apply: eqP.
- move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by right; case.
by case/IHf2; [left | right; case].
- move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1F]; first by do 2 left.
by case/IHf2; [left; right | right; case].
- move=> f1 IHf1 f2 IHf2 /= /andP[/IHf1[] f1T]; last by left.
by case/IHf2; [left | right; move/(_ f1T)].
by move=> f1 IHf1 /IHf1[]; [right | left].
Qed.
Implicit Type bc : seq (term R) * seq (term R).
(* Quantifier-free formula are normalized into DNF. A DNF is *)
(* represented by the type seq (seq (term R) * seq (term R)), where we *)
(* separate positive and negative literals *)
(* DNF preserving conjunction *)
Definition and_dnf bcs1 bcs2 :=
\big[cat/nil]_(bc1 <- bcs1)
map (fun bc2 => (bc1.1 ++ bc2.1, bc1.2 ++ bc2.2)) bcs2.
(* Computes a DNF from a qf ring formula *)
Fixpoint qf_to_dnf (f : formula R) (neg : bool) {struct f} :=
match f with
| Bool b => if b (+) neg then [:: ([::], [::])] else [::]
| t1 == t2 => [:: if neg then ([::], [:: t1 - t2]) else ([:: t1 - t2], [::])]
| f1 /\ f2 => (if neg then cat else and_dnf) [rec f1, neg] [rec f2, neg]
| f1 \/ f2 => (if neg then and_dnf else cat) [rec f1, neg] [rec f2, neg]
| f1 ==> f2 => (if neg then and_dnf else cat) [rec f1, ~~ neg] [rec f2, neg]
| ~ f1 => [rec f1, ~~ neg]
| _ => if neg then [:: ([::], [::])] else [::]
end%T where "[ 'rec' f , neg ]" := (qf_to_dnf f neg).
(* Conversely, transforms a DNF into a formula *)
Definition dnf_to_form :=
let pos_lit t := And (t == 0) in let neg_lit t := And (t != 0) in
let cls bc := Or (foldr pos_lit True bc.1 /\ foldr neg_lit True bc.2) in
foldr cls False.
(* Catenation of dnf is the Or of formulas *)
Lemma cat_dnfP e bcs1 bcs2 :
qf_eval e (dnf_to_form (bcs1 ++ bcs2))
= qf_eval e (dnf_to_form bcs1 \/ dnf_to_form bcs2).
Proof.
by elim: bcs1 => //= bc1 bcs1 IH1; rewrite -orbA; congr orb; rewrite IH1.
Qed.
(* and_dnf is the And of formulas *)
Lemma and_dnfP e bcs1 bcs2 :
qf_eval e (dnf_to_form (and_dnf bcs1 bcs2))
= qf_eval e (dnf_to_form bcs1 /\ dnf_to_form bcs2).
Proof.
elim: bcs1 => [|bc1 bcs1 IH1] /=; first by rewrite /and_dnf big_nil.
rewrite /and_dnf big_cons -/(and_dnf bcs1 bcs2) cat_dnfP /=.
rewrite {}IH1 /= andb_orl; congr orb.
elim: bcs2 bc1 {bcs1} => [|bc2 bcs2 IH] bc1 /=; first by rewrite andbF.
rewrite {}IH /= andb_orr; congr orb => {bcs2}.
suffices aux (l1 l2 : seq (term R)) g : let redg := foldr (And \o g) True in
qf_eval e (redg (l1 ++ l2)) = qf_eval e (redg l1 /\ redg l2)%T.
+ by rewrite 2!aux /= 2!andbA -andbA -andbCA andbA andbCA andbA.
by elim: l1 => [| t1 l1 IHl1] //=; rewrite -andbA IHl1.
Qed.
Lemma qf_to_dnfP e :
let qev f b := qf_eval e (dnf_to_form (qf_to_dnf f b)) in
forall f, qf_form f && rformula f -> qev f false = qf_eval e f.
Proof.
move=> qev; have qevT f: qev f true = ~~ qev f false.
rewrite {}/qev; elim: f => //=; do [by case | move=> f1 IH1 f2 IH2 | ].
- by move=> t1 t2; rewrite !andbT !orbF.
- by rewrite and_dnfP cat_dnfP negb_and -IH1 -IH2.
- by rewrite and_dnfP cat_dnfP negb_or -IH1 -IH2.
- by rewrite and_dnfP cat_dnfP /= negb_or IH1 -IH2 negbK.
by move=> t1 ->; rewrite negbK.
rewrite /qev; elim=> //=; first by case.
- by move=> t1 t2 _; rewrite subr_eq0 !andbT orbF.
- move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP.
by rewrite and_dnfP /= => /IH1-> /IH2->.
- move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP.
by rewrite cat_dnfP /= => /IH1-> => /IH2->.
- move=> f1 IH1 f2 IH2; rewrite andbCA -andbA andbCA andbA; case/andP.
by rewrite cat_dnfP /= [qf_eval _ _]qevT -implybE => /IH1 <- /IH2->.
by move=> f1 IH1 /IH1 <-; rewrite -qevT.
Qed.
Lemma dnf_to_form_qf bcs : qf_form (dnf_to_form bcs).
Proof.
by elim: bcs => //= [[clT clF] _ ->] /=; elim: clT => //=; elim: clF.
Qed.
Definition dnf_rterm cl := all rterm cl.1 && all rterm cl.2.
Lemma qf_to_dnf_rterm f b : rformula f -> all dnf_rterm (qf_to_dnf f b).
Proof.
set ok := all dnf_rterm.
have cat_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (bcs1 ++ bcs2).
by move=> ok1 ok2; rewrite [ok _]all_cat; apply/andP.
have and_ok bcs1 bcs2: ok bcs1 -> ok bcs2 -> ok (and_dnf bcs1 bcs2).
rewrite /and_dnf unlock; elim: bcs1 => //= cl1 bcs1 IH1; rewrite -andbA.
case/and3P=> ok11 ok12 ok1 ok2; rewrite cat_ok ?{}IH1 {bcs1 ok1}//.
elim: bcs2 ok2 => //= cl2 bcs2 IH2 /andP[ok2 /IH2->].
by rewrite /dnf_rterm !all_cat ok11 ok12 /= !andbT.
elim: f b => //=; [ by do 2!case | | | | | by auto | | ];
try by repeat case/andP || intro; case: ifP; auto.
by rewrite /dnf_rterm => ?? [] /= ->.
Qed.
Lemma dnf_to_rform bcs : rformula (dnf_to_form bcs) = all dnf_rterm bcs.
Proof.
elim: bcs => //= [[cl1 cl2] bcs ->]; rewrite {2}/dnf_rterm /=; congr (_ && _).
by (congr andb; [elim: cl1 | elim: cl2]) => //= t cl ->; rewrite andbT.
Qed.
Section If.
Variables (pred_f then_f else_f : formula R).
Definition If := (pred_f /\ then_f \/ ~ pred_f /\ else_f)%T.
Lemma If_form_qf :
qf_form pred_f -> qf_form then_f -> qf_form else_f -> qf_form If.
Proof. by move=> /= -> -> ->. Qed.
Lemma If_form_rf :
rformula pred_f -> rformula then_f -> rformula else_f -> rformula If.
Proof. by move=> /= -> -> ->. Qed.
Lemma eval_If e :
let ev := qf_eval e in ev If = (if ev pred_f then ev then_f else ev else_f).
Proof. by rewrite /=; case: ifP => _; rewrite ?orbF. Qed.
End If.
Section Pick.
Variables (I : finType) (pred_f then_f : I -> formula R) (else_f : formula R).
Definition Pick :=
\big[Or/False]_(p : {ffun pred I})
((\big[And/True]_i (if p i then pred_f i else ~ pred_f i))
/\ (if pick p is Some i then then_f i else else_f))%T.
Lemma Pick_form_qf :
(forall i, qf_form (pred_f i)) ->
(forall i, qf_form (then_f i)) ->
qf_form else_f ->
qf_form Pick.
Proof.
move=> qfp qft qfe; have mA := (big_morph qf_form) true andb.
rewrite mA // big1 //= => p _.
rewrite mA // big1 => [|i _]; first by case: pick.
by rewrite fun_if if_same /= qfp.
Qed.
Lemma eval_Pick e (qev := qf_eval e) :
let P i := qev (pred_f i) in
qev Pick = (if pick P is Some i then qev (then_f i) else qev else_f).
Proof.
move=> P; rewrite ((big_morph qev) false orb) //= big_orE /=.
apply/existsP/idP=> [[p] | true_at_P].
rewrite ((big_morph qev) true andb) //= big_andE /=.
case/andP=> /forallP-eq_p_P.
rewrite (@eq_pick _ _ P) => [|i]; first by case: pick.
by move/(_ i): eq_p_P => /=; case: (p i) => //= /negPf.
exists [ffun i => P i] => /=; apply/andP; split.
rewrite ((big_morph qev) true andb) //= big_andE /=.
by apply/forallP=> i; rewrite /= ffunE; case Pi: (P i) => //=; apply: negbT.
rewrite (@eq_pick _ _ P) => [|i]; first by case: pick true_at_P.
by rewrite ffunE.
Qed.
End Pick.
Section MultiQuant.
Variable f : formula R.
Implicit Types (I : seq nat) (e : seq R).
Lemma foldExistsP I e :
(exists2 e', {in [predC I], same_env e e'} & holds e' f)
<-> holds e (foldr Exists f I).
Proof.
elim: I e => /= [|i I IHi] e.
by split=> [[e' eq_e] |]; [apply: eq_holds => i; rewrite eq_e | exists e].
split=> [[e' eq_e f_e'] | [x]]; last set e_x := set_nth 0 e i x.
exists e'`_i; apply/IHi; exists e' => // j.
by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->.
case/IHi=> e' eq_e f_e'; exists e' => // j.
by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP.
Qed.
Lemma foldForallP I e :
(forall e', {in [predC I], same_env e e'} -> holds e' f)
<-> holds e (foldr Forall f I).
Proof.
elim: I e => /= [|i I IHi] e.
by split=> [|f_e e' eq_e]; [apply | apply: eq_holds f_e => i; rewrite eq_e].
split=> [f_e' x | f_e e' eq_e]; first set e_x := set_nth 0 e i x.
apply/IHi=> e' eq_e; apply: f_e' => j.
by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP.
move/IHi: (f_e e'`_i); apply=> j.
by have:= eq_e j; rewrite nth_set_nth /= !inE; case: eqP => // ->.
Qed.
End MultiQuant.
End EvalTerm.
Prenex Implicits dnf_rterm.
Definition integral_domain_axiom (R : pzRingType) :=
forall x y : R, x * y = 0 -> (x == 0) || (y == 0).
HB.mixin Record ComUnitRing_isIntegral R of ComUnitRing R := {
mulf_eq0_subproof : integral_domain_axiom R;
}.
#[mathcomp(axiom="integral_domain_axiom"), short(type="idomainType")]
HB.structure Definition IntegralDomain :=
{R of ComUnitRing_isIntegral R & ComUnitRing R}.
Module IntegralDomainExports.
Bind Scope ring_scope with IntegralDomain.sort.
End IntegralDomainExports.
HB.export IntegralDomainExports.
Section IntegralDomainTheory.
Variable R : idomainType.
Implicit Types x y : R.
Lemma mulf_eq0 x y : (x * y == 0) = (x == 0) || (y == 0).
Proof.
apply/eqP/idP; first exact: mulf_eq0_subproof.
by case/pred2P=> ->; rewrite (mulr0, mul0r).
Qed.
Lemma prodf_eq0 (I : finType) (P : pred I) (F : I -> R) :
reflect (exists2 i, P i & (F i == 0)) (\prod_(i | P i) F i == 0).
Proof.
apply: (iffP idP) => [|[i Pi /eqP Fi0]]; last first.
by rewrite (bigD1 i) //= Fi0 mul0r.
elim: (index_enum _) => [|i r IHr]; first by rewrite big_nil oner_eq0.
rewrite big_cons /=; have [Pi | _] := ifP; last exact: IHr.
by rewrite mulf_eq0; case/orP=> // Fi0; exists i.
Qed.
Lemma prodf_seq_eq0 I r (P : pred I) (F : I -> R) :
(\prod_(i <- r | P i) F i == 0) = has (fun i => P i && (F i == 0)) r.
Proof. by rewrite (big_morph _ mulf_eq0 (oner_eq0 _)) big_has_cond. Qed.
Lemma mulf_neq0 x y : x != 0 -> y != 0 -> x * y != 0.
Proof. by move=> x0 y0; rewrite mulf_eq0; apply/norP. Qed.
Lemma prodf_neq0 (I : finType) (P : pred I) (F : I -> R) :
reflect (forall i, P i -> (F i != 0)) (\prod_(i | P i) F i != 0).
Proof. by rewrite (sameP (prodf_eq0 _ _) exists_inP); apply: exists_inPn. Qed.
Lemma prodf_seq_neq0 I r (P : pred I) (F : I -> R) :
(\prod_(i <- r | P i) F i != 0) = all (fun i => P i ==> (F i != 0)) r.
Proof.
rewrite prodf_seq_eq0 -all_predC; apply: eq_all => i /=.
by rewrite implybE negb_and.
Qed.
Lemma expf_eq0 x n : (x ^+ n == 0) = (n > 0) && (x == 0).
Proof.
elim: n => [|n IHn]; first by rewrite oner_eq0.
by rewrite exprS mulf_eq0 IHn andKb.
Qed.
Lemma sqrf_eq0 x : (x ^+ 2 == 0) = (x == 0). Proof. exact: expf_eq0. Qed.
Lemma expf_neq0 x m : x != 0 -> x ^+ m != 0.
Proof. by move=> x_nz; rewrite expf_eq0; apply/nandP; right. Qed.
Lemma natf_neq0_pchar n : (n%:R != 0 :> R) = (pchar R)^'.-nat n.
Proof.
have [-> | /prod_prime_decomp->] := posnP n; first by rewrite eqxx.
rewrite !big_seq; elim/big_rec: _ => [|[p e] s /=]; first by rewrite oner_eq0.
case/mem_prime_decomp=> p_pr _ _; rewrite pnatM pnatX eqn0Ngt orbC => <-.
by rewrite natrM natrX mulf_eq0 expf_eq0 negb_or negb_and pnatE ?inE p_pr.
Qed.
Lemma natf0_pchar n : n > 0 -> n%:R == 0 :> R -> exists p, p \in pchar R.
Proof.
move=> n_gt0 nR_0; exists (pdiv n`_(pchar R)).
apply: pnatP (pdiv_dvd _); rewrite ?part_pnat // ?pdiv_prime //.
by rewrite ltn_neqAle eq_sym partn_eq1 // -natf_neq0_pchar nR_0 /=.
Qed.
Lemma pcharf'_nat n : (pchar R)^'.-nat n = (n%:R != 0 :> R).
Proof.
have [-> | n_gt0] := posnP n; first by rewrite eqxx.
apply/idP/idP => [|nz_n]; last first.
by apply/pnatP=> // p p_pr p_dvd_n; apply: contra nz_n => /dvdn_pcharf <-.
apply: contraL => n0; have [// | p pcharRp] := natf0_pchar _ n0.
have [p_pr _] := andP pcharRp; rewrite (eq_pnat _ (eq_negn (pcharf_eq pcharRp))).
by rewrite p'natE // (dvdn_pcharf pcharRp) n0.
Qed.
Lemma pcharf0P : pchar R =i pred0 <-> (forall n, (n%:R == 0 :> R) = (n == 0)%N).
Proof.
split=> pcharF0 n; last by rewrite !inE pcharF0 andbC; case: eqP => // ->.
have [-> | n_gt0] := posnP; first exact: eqxx.
by apply/negP; case/natf0_pchar=> // p; rewrite pcharF0.
Qed.
Lemma eqf_sqr x y : (x ^+ 2 == y ^+ 2) = (x == y) || (x == - y).
Proof. by rewrite -subr_eq0 subr_sqr mulf_eq0 subr_eq0 addr_eq0. Qed.
Lemma mulfI x : x != 0 -> injective ( *%R x).
Proof.
move=> nz_x y z; apply: contra_eq => neq_yz.
by rewrite -subr_eq0 -mulrBr mulf_neq0 ?subr_eq0.
Qed.
Lemma mulIf x : x != 0 -> injective ( *%R^~ x).
Proof. by move=> nz_x y z; rewrite -!(mulrC x); apply: mulfI. Qed.
Lemma divfI x : x != 0 -> injective (fun y => x / y).
Proof. by move/mulfI/inj_comp; apply; apply: invr_inj. Qed.
Lemma divIf y : y != 0 -> injective (fun x => x / y).
Proof. by rewrite -invr_eq0; apply: mulIf. Qed.
Lemma sqrf_eq1 x : (x ^+ 2 == 1) = (x == 1) || (x == -1).
Proof. by rewrite -subr_eq0 subr_sqr_1 mulf_eq0 subr_eq0 addr_eq0. Qed.
Lemma expfS_eq1 x n :
(x ^+ n.+1 == 1) = (x == 1) || (\sum_(i < n.+1) x ^+ i == 0).
Proof. by rewrite -![_ == 1]subr_eq0 subrX1 mulf_eq0. Qed.
Lemma lregP x : reflect (lreg x) (x != 0).
Proof. by apply: (iffP idP) => [/mulfI | /lreg_neq0]. Qed.
Lemma rregP x : reflect (rreg x) (x != 0).
Proof. by apply: (iffP idP) => [/mulIf | /rreg_neq0]. Qed.
#[export]
HB.instance Definition _ := IntegralDomain.on R^o.
End IntegralDomainTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")]
Notation natf_neq0 := natf_neq0_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")]
Notation natf0_char := natf0_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")]
Notation charf'_nat := pcharf'_nat (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")]
Notation charf0P := pcharf0P (only parsing).
Arguments lregP {R x}.
Arguments rregP {R x}.
Definition field_axiom (R : unitRingType) := forall x : R, x != 0 -> x \in unit.
HB.mixin Record UnitRing_isField R of UnitRing R := {
fieldP : field_axiom R;
}.
#[mathcomp(axiom="field_axiom"), short(type="fieldType")]
HB.structure Definition Field := { R of IntegralDomain R & UnitRing_isField R }.
Module FieldExports.
Bind Scope ring_scope with Field.sort.
End FieldExports.
HB.export FieldExports.
#[export] HB.instance Definition regular_field (F : fieldType) := Field.on F^o.
Lemma IdomainMixin (R : unitRingType): Field.axiom R -> IntegralDomain.axiom R.
Proof.
move=> m x y xy0; apply/norP=> [[]] /m Ux /m.
by rewrite -(unitrMr _ Ux) xy0 unitr0.
Qed.
HB.factory Record ComUnitRing_isField R of ComUnitRing R := {
fieldP : field_axiom R;
}.
HB.builders Context R of ComUnitRing_isField R.
HB.instance Definition _ :=
ComUnitRing_isIntegral.Build R (IdomainMixin fieldP).
HB.instance Definition _ := UnitRing_isField.Build R fieldP.
HB.end.
HB.factory Record ComNzRing_isField R of ComNzRing R := {
inv : R -> R;
mulVf : forall x, x != 0 -> inv x * x = 1;
invr0 : inv 0 = 0;
}.
Module ComRing_isField.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing_isField.Build instead.")]
Notation Build R := (ComNzRing_isField.Build R) (only parsing).
End ComRing_isField.
#[deprecated(since="mathcomp 2.4.0",
note="Use ComNzRing_isField instead.")]
Notation ComRing_isField R := (ComNzRing_isField R) (only parsing).
HB.builders Context R of ComNzRing_isField R.
Fact intro_unit (x y : R) : y * x = 1 -> x != 0.
Proof.
move=> yx1; apply: contraNneq (@oner_neq0 R) => x0.
by rewrite -yx1 x0 mulr0.
Qed.
Fact inv_out : {in predC (predC1 0), inv =1 id}.
Proof. by move=> x /negbNE/eqP->; exact: invr0. Qed.
HB.instance Definition _ : ComNzRing_hasMulInverse R :=
ComNzRing_hasMulInverse.Build R mulVf intro_unit inv_out.
HB.instance Definition _ : ComUnitRing_isField R :=
ComUnitRing_isField.Build R (fun x x_neq_0 => x_neq_0).
HB.end.
Section FieldTheory.
Variable F : fieldType.
Implicit Types x y : F.
Lemma unitfE x : (x \in unit) = (x != 0).
Proof. by apply/idP/idP=> [/(memPn _)-> | /fieldP]; rewrite ?unitr0. Qed.
Lemma mulVf x : x != 0 -> x^-1 * x = 1.
Proof. by rewrite -unitfE; apply: mulVr. Qed.
Lemma divff x : x != 0 -> x / x = 1.
Proof. by rewrite -unitfE; apply: divrr. Qed.
Definition mulfV := divff.
Lemma mulKf x : x != 0 -> cancel ( *%R x) ( *%R x^-1).
Proof. by rewrite -unitfE; apply: mulKr. Qed.
Lemma mulVKf x : x != 0 -> cancel ( *%R x^-1) ( *%R x).
Proof. by rewrite -unitfE; apply: mulVKr. Qed.
Lemma mulfK x : x != 0 -> cancel ( *%R^~ x) ( *%R^~ x^-1).
Proof. by rewrite -unitfE; apply: mulrK. Qed.
Lemma mulfVK x : x != 0 -> cancel ( *%R^~ x^-1) ( *%R^~ x).
Proof. by rewrite -unitfE; apply: divrK. Qed.
Definition divfK := mulfVK.
Lemma invfM : {morph @inv F : x y / x * y}.
Proof.
move=> x y; have [->|nzx] := eqVneq x 0; first by rewrite !(mul0r, invr0).
have [->|nzy] := eqVneq y 0; first by rewrite !(mulr0, invr0).
by rewrite mulrC invrM ?unitfE.
Qed.
Lemma invf_div x y : (x / y)^-1 = y / x.
Proof. by rewrite invfM invrK mulrC. Qed.
Lemma divKf x : x != 0 -> involutive (fun y => x / y).
Proof. by move=> nz_x y; rewrite invf_div mulrC divfK. Qed.
Lemma expfB_cond m n x : (x == 0) + n <= m -> x ^+ (m - n) = x ^+ m / x ^+ n.
Proof.
move/subnK=> <-; rewrite addnA addnK !exprD.
have [-> | nz_x] := eqVneq; first by rewrite !mulr0 !mul0r.
by rewrite mulfK ?expf_neq0.
Qed.
Lemma expfB m n x : n < m -> x ^+ (m - n) = x ^+ m / x ^+ n.
Proof. by move=> lt_n_m; apply: expfB_cond; case: eqP => // _; apply: ltnW. Qed.
Lemma prodfV I r (P : pred I) (E : I -> F) :
\prod_(i <- r | P i) (E i)^-1 = (\prod_(i <- r | P i) E i)^-1.
Proof. by rewrite (big_morph _ invfM (invr1 F)). Qed.
Lemma prodf_div I r (P : pred I) (E D : I -> F) :
\prod_(i <- r | P i) (E i / D i) =
\prod_(i <- r | P i) E i / \prod_(i <- r | P i) D i.
Proof. by rewrite big_split prodfV. Qed.
Lemma telescope_prodf n m (f : nat -> F) :
(forall k, n < k < m -> f k != 0) -> n < m ->
\prod_(n <= k < m) (f k.+1 / f k) = f m / f n.
Proof.
move=> nz_f ltnm; apply: invr_inj; rewrite prodf_div !invf_div -prodf_div.
by apply: telescope_prodr => // k /nz_f; rewrite unitfE.
Qed.
Lemma telescope_prodf_eq n m (f u : nat -> F) :
(forall k, n < k < m -> f k != 0) -> n < m ->
(forall k, n <= k < m -> u k = f k.+1 / f k) ->
\prod_(n <= k < m) u k = f m / f n.
Proof.
by move=> ? ? uE; under eq_big_nat do rewrite uE //=; exact: telescope_prodf.
Qed.
Lemma addf_div x1 y1 x2 y2 :
y1 != 0 -> y2 != 0 -> x1 / y1 + x2 / y2 = (x1 * y2 + x2 * y1) / (y1 * y2).
Proof. by move=> nzy1 nzy2; rewrite invfM mulrDl !mulrA mulrAC !mulfK. Qed.
Lemma mulf_div x1 y1 x2 y2 : (x1 / y1) * (x2 / y2) = (x1 * x2) / (y1 * y2).
Proof. by rewrite mulrACA -invfM. Qed.
Lemma eqr_div x y z t : y != 0 -> t != 0 -> (x / y == z / t) = (x * t == z * y).
Proof.
move=> yD0 tD0; rewrite -[x in RHS](divfK yD0) -[z in RHS](divfK tD0) mulrAC.
by apply/eqP/eqP => [->|/(mulIf yD0)/(mulIf tD0)].
Qed.
Lemma eqr_sum_div I r P (f : I -> F) c a : c != 0 ->
\big[+%R/0]_(x <- r | P x) (f x / c) == a
= (\big[+%R/0]_(x <- r | P x) f x == a * c).
Proof.
by move=> ?; rewrite -mulr_suml -(divr1 a) eqr_div ?oner_eq0// mulr1 divr1.
Qed.
Lemma pchar0_natf_div :
pchar F =i pred0 -> forall m d, d %| m -> (m %/ d)%:R = m%:R / d%:R :> F.
Proof.
move/pcharf0P=> pchar0F m [|d] d_dv_m; first by rewrite divn0 invr0 mulr0.
by rewrite natr_div // unitfE pchar0F.
Qed.
Section FieldMorphismInj.
Variables (R : nzRingType) (f : {rmorphism F -> R}).
Lemma fmorph_eq0 x : (f x == 0) = (x == 0).
Proof.
have [-> | nz_x] := eqVneq x; first by rewrite rmorph0 eqxx.
apply/eqP; move/(congr1 ( *%R (f x^-1)))/eqP.
by rewrite -rmorphM mulVf // mulr0 rmorph1 ?oner_eq0.
Qed.
Lemma fmorph_inj : injective f.
Proof. by apply/raddf_inj => x /eqP; rewrite fmorph_eq0 => /eqP. Qed.
Lemma fmorph_eq : {mono f : x y / x == y}.
Proof. exact: inj_eq fmorph_inj. Qed.
Lemma fmorph_eq1 x : (f x == 1) = (x == 1).
Proof. by rewrite -(inj_eq fmorph_inj) rmorph1. Qed.
Lemma fmorph_pchar : pchar R =i pchar F.
Proof. by move=> p; rewrite !inE -fmorph_eq0 rmorph_nat. Qed.
End FieldMorphismInj.
Section FieldMorphismInv.
Variables (R : unitRingType) (f : {rmorphism F -> R}).
Lemma fmorph_unit x : (f x \in unit) = (x != 0).
Proof.
have [-> |] := eqVneq x; first by rewrite rmorph0 unitr0.
by rewrite -unitfE; apply: rmorph_unit.
Qed.
Lemma fmorphV : {morph f: x / x^-1}.
Proof.
move=> x; have [-> | nz_x] := eqVneq x 0; first by rewrite !(invr0, rmorph0).
by rewrite rmorphV ?unitfE.
Qed.
Lemma fmorph_div : {morph f : x y / x / y}.
Proof. by move=> x y; rewrite rmorphM /= fmorphV. Qed.
End FieldMorphismInv.
Section ModuleTheory.
Variable V : lmodType F.
Implicit Types (a : F) (v : V).
Lemma scalerK a : a != 0 -> cancel ( *:%R a : V -> V) ( *:%R a^-1).
Proof. by move=> nz_a v; rewrite scalerA mulVf // scale1r. Qed.
Lemma scalerKV a : a != 0 -> cancel ( *:%R a^-1 : V -> V) ( *:%R a).
Proof. by rewrite -invr_eq0 -{3}[a]invrK; apply: scalerK. Qed.
Lemma scalerI a : a != 0 -> injective ( *:%R a : V -> V).
Proof. by move=> nz_a; apply: can_inj (scalerK nz_a). Qed.
Lemma scaler_eq0 a v : (a *: v == 0) = (a == 0) || (v == 0).
Proof.
have [-> | nz_a] := eqVneq a; first by rewrite scale0r eqxx.
by rewrite (can2_eq (scalerK nz_a) (scalerKV nz_a)) scaler0.
Qed.
End ModuleTheory.
Lemma pchar_lalg (A : lalgType F) : pchar A =i pchar F.
Proof. by move=> p; rewrite inE -scaler_nat scaler_eq0 oner_eq0 orbF. Qed.
End FieldTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")]
Notation char0_natf_div := pchar0_natf_div (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")]
Notation fmorph_char := fmorph_pchar (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")]
Notation char_lalg := pchar_lalg (only parsing).
Arguments fmorph_inj {F R} f [x1 x2].
Arguments telescope_prodf_eq {F n m} f u.
Definition decidable_field_axiom (R : unitRingType)
(s : seq R -> pred (formula R)) :=
forall e f, reflect (holds e f) (s e f).
HB.mixin Record Field_isDecField R of UnitRing R := {
sat : seq R -> pred (formula R);
satP : decidable_field_axiom sat;
}.
#[mathcomp(axiom="decidable_field_axiom"), short(type="decFieldType")]
HB.structure Definition DecidableField := { F of Field F & Field_isDecField F }.
Module DecFieldExports.
Bind Scope ring_scope with DecidableField.sort.
End DecFieldExports.
HB.export DecFieldExports.
#[export] HB.instance Definition _ (F : decFieldType) := DecidableField.on F^o.
Section DecidableFieldTheory.
Variable F : decFieldType.
Implicit Type f : formula F.
Fact sol_subproof n f :
reflect (exists s, (size s == n) && sat s f)
(sat [::] (foldr Exists f (iota 0 n))).
Proof.
apply: (iffP (satP _ _)) => [|[s]]; last first.
case/andP=> /eqP sz_s /satP f_s; apply/foldExistsP.
exists s => // i; rewrite !inE mem_iota -leqNgt add0n => le_n_i.
by rewrite !nth_default ?sz_s.
case/foldExistsP=> e e0 f_e; set s := take n (set_nth 0 e n 0).
have sz_s: size s = n by rewrite size_take size_set_nth leq_max leqnn.
exists s; rewrite sz_s eqxx; apply/satP; apply: eq_holds f_e => i.
case: (leqP n i) => [le_n_i | lt_i_n].
by rewrite -e0 ?nth_default ?sz_s // !inE mem_iota -leqNgt.
by rewrite nth_take // nth_set_nth /= eq_sym eqn_leq leqNgt lt_i_n.
Qed.
Definition sol n f :=
if sol_subproof n f is ReflectT sP then xchoose sP else nseq n 0.
Lemma size_sol n f : size (sol n f) = n.
Proof.
rewrite /sol; case: sol_subproof => [sP | _]; last exact: size_nseq.
by case/andP: (xchooseP sP) => /eqP.
Qed.
Lemma solP n f : reflect (exists2 s, size s = n & holds s f) (sat (sol n f) f).
Proof.
rewrite /sol; case: sol_subproof => [sP | sPn].
case/andP: (xchooseP sP) => _ ->; left.
by case: sP => s; case/andP; move/eqP=> <-; move/satP; exists s.
apply: (iffP (satP _ _)); first by exists (nseq n 0); rewrite ?size_nseq.
by case=> s sz_s; move/satP=> f_s; case: sPn; exists s; rewrite sz_s eqxx.
Qed.
Lemma eq_sat f1 f2 :
(forall e, holds e f1 <-> holds e f2) -> sat^~ f1 =1 sat^~ f2.
Proof. by move=> eqf12 e; apply/satP/satP; case: (eqf12 e). Qed.
Lemma eq_sol f1 f2 :
(forall e, holds e f1 <-> holds e f2) -> sol^~ f1 =1 sol^~ f2.
Proof.
rewrite /sol => /eq_sat eqf12 n.
do 2![case: sol_subproof] => //= [f1s f2s | ns1 [s f2s] | [s f1s] []].
- by apply: eq_xchoose => s; rewrite eqf12.
- by case: ns1; exists s; rewrite -eqf12.
by exists s; rewrite eqf12.
Qed.
End DecidableFieldTheory.
Arguments satP {F e f} : rename.
Arguments solP {F n f} : rename.
Section QE_Mixin.
Variable F : Field.type.
Implicit Type f : formula F.
Variable proj : nat -> seq (term F) * seq (term F) -> formula F.
(* proj is the elimination of a single existential quantifier *)
(* The elimination projector is well_formed. *)
Definition wf_QE_proj :=
forall i bc (bc_i := proj i bc),
dnf_rterm bc -> qf_form bc_i && rformula bc_i.
(* The elimination projector is valid *)
Definition valid_QE_proj :=
forall i bc (ex_i_bc := ('exists 'X_i, dnf_to_form [:: bc])%T) e,
dnf_rterm bc -> reflect (holds e ex_i_bc) (qf_eval e (proj i bc)).
Hypotheses (wf_proj : wf_QE_proj) (ok_proj : valid_QE_proj).
Let elim_aux f n := foldr Or False (map (proj n) (qf_to_dnf f false)).
Fixpoint quantifier_elim f :=
match f with
| f1 /\ f2 => (quantifier_elim f1) /\ (quantifier_elim f2)
| f1 \/ f2 => (quantifier_elim f1) \/ (quantifier_elim f2)
| f1 ==> f2 => (~ quantifier_elim f1) \/ (quantifier_elim f2)
| ~ f => ~ quantifier_elim f
| ('exists 'X_n, f) => elim_aux (quantifier_elim f) n
| ('forall 'X_n, f) => ~ elim_aux (~ quantifier_elim f) n
| _ => f
end%T.
Lemma quantifier_elim_wf f :
let qf := quantifier_elim f in rformula f -> qf_form qf && rformula qf.
Proof.
suffices aux_wf f0 n : let qf := elim_aux f0 n in
rformula f0 -> qf_form qf && rformula qf.
- by elim: f => //=; do ?[ move=> f1 IH1 f2 IH2;
case/andP=> rf1 rf2;
case/andP:(IH1 rf1)=> -> ->;
case/andP:(IH2 rf2)=> -> -> //
| move=> n f1 IH rf1;
case/andP: (IH rf1)=> qff rf;
rewrite aux_wf ].
rewrite /elim_aux => rf.
suffices or_wf fs : let ofs := foldr Or False fs in
all (@qf_form F) fs && all (@rformula F) fs -> qf_form ofs && rformula ofs.
- apply: or_wf.
suffices map_proj_wf bcs: let mbcs := map (proj n) bcs in
all dnf_rterm bcs -> all (@qf_form _) mbcs && all (@rformula _) mbcs.
by apply/map_proj_wf/qf_to_dnf_rterm.
elim: bcs => [|bc bcs ihb] bcsr //= /andP[rbc rbcs].
by rewrite andbAC andbA wf_proj //= andbC ihb.
elim: fs => //= g gs ihg; rewrite -andbA => /and4P[-> qgs -> rgs] /=.
by apply: ihg; rewrite qgs rgs.
Qed.
Lemma quantifier_elim_rformP e f :
rformula f -> reflect (holds e f) (qf_eval e (quantifier_elim f)).
Proof.
pose rc e n f := exists x, qf_eval (set_nth 0 e n x) f.
have auxP f0 e0 n0: qf_form f0 && rformula f0 ->
reflect (rc e0 n0 f0) (qf_eval e0 (elim_aux f0 n0)).
+ rewrite /elim_aux => cf; set bcs := qf_to_dnf f0 false.
apply: (@iffP (rc e0 n0 (dnf_to_form bcs))); last first.
- by case=> x; rewrite -qf_to_dnfP //; exists x.
- by case=> x; rewrite qf_to_dnfP //; exists x.
have: all dnf_rterm bcs by case/andP: cf => _; apply: qf_to_dnf_rterm.
elim: {f0 cf}bcs => [|bc bcs IHbcs] /=; first by right; case.
case/andP=> r_bc /IHbcs {IHbcs}bcsP.
have f_qf := dnf_to_form_qf [:: bc].
case: ok_proj => //= [ex_x|no_x].
left; case: ex_x => x /(qf_evalP _ f_qf); rewrite /= orbF => bc_x.
by exists x; rewrite /= bc_x.
apply: (iffP bcsP) => [[x bcs_x] | [x]] /=.
by exists x; rewrite /= bcs_x orbT.
case/orP => [bc_x|]; last by exists x.
by case: no_x; exists x; apply/(qf_evalP _ f_qf); rewrite /= bc_x.
elim: f e => //.
- by move=> b e _; apply: idP.
- by move=> t1 t2 e _; apply: eqP.
- move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by right; case.
by case/IH2; [left | right; case].
- move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; first by do 2!left.
by case/IH2; [left; right | right; case].
- move=> f1 IH1 f2 IH2 e /= /andP[/IH1[] f1e]; last by left.
by case/IH2; [left | right; move/(_ f1e)].
- by move=> f IHf e /= /IHf[]; [right | left].
- move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf.
by apply: (iffP (auxP _ _ _ rqf)) => [] [x]; exists x; apply/IHf.
move=> n f IHf e /= rf; have rqf := quantifier_elim_wf rf.
case: auxP => // [f_x|no_x]; first by right=> no_x; case: f_x => x /IHf[].
by left=> x; apply/IHf=> //; apply/idPn=> f_x; case: no_x; exists x.
Qed.
Definition proj_sat e f := qf_eval e (quantifier_elim (to_rform f)).
Lemma proj_satP : DecidableField.axiom proj_sat.
Proof.
move=> e f; have fP := quantifier_elim_rformP e (to_rform_rformula f).
by apply: (iffP fP); move/to_rformP.
Qed.
End QE_Mixin.
HB.factory Record Field_QE_isDecField F of Field F := {
proj : nat -> seq (term F) * seq (term F) -> formula F;
wf_proj : wf_QE_proj proj;
ok_proj : valid_QE_proj proj;
}.
HB.builders Context F of Field_QE_isDecField F.
HB.instance Definition qe_is_def_field : Field_isDecField F :=
Field_isDecField.Build F (proj_satP wf_proj ok_proj).
HB.end.
(* Axiom == all non-constant monic polynomials have a root *)
Definition closed_field_axiom (R : pzRingType) :=
forall n (P : nat -> R), n > 0 ->
exists x : R, x ^+ n = \sum_(i < n) P i * (x ^+ i).
HB.mixin Record DecField_isAlgClosed F of DecidableField F := {
solve_monicpoly : closed_field_axiom F;
}.
#[mathcomp(axiom="closed_field_axiom"), short(type="closedFieldType")]
HB.structure Definition ClosedField :=
{ F of DecidableField F & DecField_isAlgClosed F }.
Module ClosedFieldExports.
Bind Scope ring_scope with ClosedField.sort.
End ClosedFieldExports.
HB.export ClosedFieldExports.
#[export] HB.instance Definition _ (F : closedFieldType) := ClosedField.on F^o.
Section ClosedFieldTheory.
Variable F : closedFieldType.
Lemma imaginary_exists : {i : F | i ^+ 2 = -1}.
Proof.
have /sig_eqW[i Di2] := @solve_monicpoly F 2 (nth 0 [:: -1]) isT.
by exists i; rewrite Di2 !big_ord_recl big_ord0 mul0r mulr1 !addr0.
Qed.
End ClosedFieldTheory.
Lemma lalgMixin (R : pzRingType) (A : lalgType R) (B : lmodType R) (f : B -> A) :
phant B -> injective f -> scalable f ->
forall mulB, {morph f : x y / mulB x y >-> x * y} ->
forall a u v, a *: (mulB u v) = mulB (a *: u) v.
Proof.
by move=> _ injf fZ mulB fM a x y; apply: injf; rewrite !(fZ, fM) scalerAl.
Qed.
Lemma comRingMixin (R : comPzRingType) (T : pzRingType) (f : T -> R) :
phant T -> injective f -> {morph f : x y / x * y} -> commutative (@mul T).
Proof. by move=> _ inj_f fM x y; apply: inj_f; rewrite !fM mulrC. Qed.
Lemma algMixin (R : pzRingType) (A : algType R) (B : lalgType R) (f : B -> A) :
phant B -> injective f -> {morph f : x y / x * y} -> scalable f ->
forall k (x y : B), k *: (x * y) = x * (k *: y).
Proof.
by move=> _ inj_f fM fZ a x y; apply: inj_f; rewrite !(fM, fZ) scalerAr.
Qed.
(* Mixins for stability properties *)
HB.mixin Record isMul2Closed (R : pzSemiRingType) (S : {pred R}) := {
rpredM : mulr_2closed S
}.
HB.mixin Record isMul1Closed (R : pzSemiRingType) (S : {pred R}) := {
rpred1 : 1 \in S
}.
HB.mixin Record isInvClosed (R : unitRingType) (S : {pred R}) := {
rpredVr : invr_closed S
}.
HB.mixin Record isScaleClosed (R : pzSemiRingType) (V : lSemiModType R)
(S : {pred V}) := {
rpredZ : scaler_closed S
}.
(* Structures for stability properties *)
Local Notation addrClosed := addrClosed.
Local Notation opprClosed := opprClosed.
#[short(type="mulr2Closed")]
HB.structure Definition Mul2Closed (R : pzSemiRingType) :=
{S of isMul2Closed R S}.
#[short(type="mulrClosed")]
HB.structure Definition MulClosed (R : pzSemiRingType) :=
{S of Mul2Closed R S & isMul1Closed R S}.
#[short(type="semiring2Closed")]
HB.structure Definition Semiring2Closed (R : pzSemiRingType) :=
{S of AddClosed R S & Mul2Closed R S}.
#[short(type="semiringClosed")]
HB.structure Definition SemiringClosed (R : pzSemiRingType) :=
{S of AddClosed R S & MulClosed R S}.
#[short(type="smulClosed")]
HB.structure Definition SmulClosed (R : pzRingType) :=
{S of OppClosed R S & MulClosed R S}.
#[short(type="subringClosed")]
HB.structure Definition SubringClosed (R : pzRingType) :=
{S of ZmodClosed R S & MulClosed R S}.
#[short(type="divClosed")]
HB.structure Definition DivClosed (R : unitRingType) :=
{S of MulClosed R S & isInvClosed R S}.
#[short(type="sdivClosed")]
HB.structure Definition SdivClosed (R : unitRingType) :=
{S of SmulClosed R S & isInvClosed R S}.
#[short(type="submodClosed")]
HB.structure Definition SubmodClosed (R : pzSemiRingType) (V : lSemiModType R)
:= {S of AddClosed V S & isScaleClosed R V S}.
#[short(type="subalgClosed")]
HB.structure Definition SubalgClosed (R : pzSemiRingType) (A : lSemiAlgType R)
:= {S of SemiringClosed A S & isScaleClosed R A S}.
#[short(type="divringClosed")]
HB.structure Definition DivringClosed (R : unitRingType) :=
{S of SubringClosed R S & isInvClosed R S}.
#[short(type="divalgClosed")]
HB.structure Definition DivalgClosed (R : pzRingType) (A : unitAlgType R) :=
{S of DivringClosed A S & isScaleClosed R A S}.
(* Factories for stability properties *)
HB.factory Record isMulClosed (R : pzSemiRingType) (S : {pred R}) := {
rpred1M : mulr_closed S
}.
HB.builders Context R S of isMulClosed R S.
HB.instance Definition _ := isMul2Closed.Build R S (proj2 rpred1M).
HB.instance Definition _ := isMul1Closed.Build R S (proj1 rpred1M).
HB.end.
HB.factory Record isSmulClosed (R : pzRingType) (S : R -> bool) := {
smulr_closed_subproof : smulr_closed S
}.
HB.builders Context R S of isSmulClosed R S.
HB.instance Definition _ := isMulClosed.Build R S
(smulr_closedM smulr_closed_subproof).
HB.instance Definition _ := isOppClosed.Build R S
(smulr_closedN smulr_closed_subproof).
HB.end.
HB.factory Record isSemiringClosed (R : pzSemiRingType) (S : R -> bool) := {
semiring_closed_subproof : semiring_closed S
}.
HB.builders Context R S of isSemiringClosed R S.
HB.instance Definition _ := isAddClosed.Build R S
(semiring_closedD semiring_closed_subproof).
HB.instance Definition _ := isMulClosed.Build R S
(semiring_closedM semiring_closed_subproof).
HB.end.
HB.factory Record isSubringClosed (R : pzRingType) (S : R -> bool) := {
subring_closed_subproof : subring_closed S
}.
HB.builders Context R S of isSubringClosed R S.
HB.instance Definition _ := isZmodClosed.Build R S
(subring_closedB subring_closed_subproof).
HB.instance Definition _ := isSmulClosed.Build R S
(subring_closedM subring_closed_subproof).
HB.end.
HB.factory Record isDivClosed (R : unitRingType) (S : R -> bool) := {
divr_closed_subproof : divr_closed S
}.
HB.builders Context R S of isDivClosed R S.
HB.instance Definition _ := isMulClosed.Build R S
(divr_closedM divr_closed_subproof).
HB.instance Definition _ := isInvClosed.Build R S
(divr_closedV divr_closed_subproof).
HB.end.
HB.factory Record isSdivClosed (R : unitRingType) (S : R -> bool) := {
sdivr_closed_subproof : sdivr_closed S
}.
HB.builders Context R S of isSdivClosed R S.
HB.instance Definition _ := isDivClosed.Build R S
(sdivr_closed_div sdivr_closed_subproof).
HB.instance Definition _ := isSmulClosed.Build R S
(sdivr_closedM sdivr_closed_subproof).
HB.end.
HB.factory Record isSubSemiModClosed (R : pzSemiRingType) (V : lSemiModType R)
(S : V -> bool) := {
subsemimod_closed_subproof : subsemimod_closed S
}.
HB.builders Context R V S of isSubSemiModClosed R V S.
HB.instance Definition _ := isAddClosed.Build V S
(subsemimod_closedD subsemimod_closed_subproof).
HB.instance Definition _ := isScaleClosed.Build R V S
(subsemimod_closedZ subsemimod_closed_subproof).
HB.end.
HB.factory Record isSubmodClosed (R : pzRingType) (V : lmodType R)
(S : V -> bool) := {
submod_closed_subproof : submod_closed S
}.
HB.builders Context R V S of isSubmodClosed R V S.
HB.instance Definition _ := isZmodClosed.Build V S
(submod_closedB submod_closed_subproof).
HB.instance Definition _ := isScaleClosed.Build R V S
(subsemimod_closedZ (submod_closed_semi submod_closed_subproof)).
HB.end.
HB.factory Record isSubalgClosed (R : pzRingType) (A : lalgType R)
(S : A -> bool) := {
subalg_closed_subproof : subalg_closed S
}.
HB.builders Context R A S of isSubalgClosed R A S.
HB.instance Definition _ := isSubmodClosed.Build R A S
(subalg_closedZ subalg_closed_subproof).
HB.instance Definition _ := isSubringClosed.Build A S
(subalg_closedBM subalg_closed_subproof).
HB.end.
HB.factory Record isDivringClosed (R : unitRingType) (S : R -> bool) := {
divring_closed_subproof : divring_closed S
}.
HB.builders Context R S of isDivringClosed R S.
HB.instance Definition _ := isSubringClosed.Build R S
(divring_closedBM divring_closed_subproof).
HB.instance Definition _ := isSdivClosed.Build R S
(divring_closed_div divring_closed_subproof).
HB.end.
HB.factory Record isDivalgClosed (R : comUnitRingType) (A : unitAlgType R)
(S : A -> bool) := {
divalg_closed_subproof : divalg_closed S
}.
HB.builders Context R A S of isDivalgClosed R A S.
HB.instance Definition _ := isDivringClosed.Build A S
(divalg_closedBdiv divalg_closed_subproof).
HB.instance Definition _ := isSubalgClosed.Build R A S
(divalg_closedZ divalg_closed_subproof).
HB.end.
Section NmodulePred.
Variables (V : nmodType).
Section Add.
Variable S : addrClosed V.
Lemma rpred0D : nmod_closed S. Proof. exact: nmod_closed_subproof. Qed.
End Add.
End NmodulePred.
Section ZmodulePred.
Variables (V : zmodType).
Section Opp.
Variable S : opprClosed V.
End Opp.
Section Sub.
Variable S : zmodClosed V.
Lemma zmodClosedP : zmod_closed S.
Proof. split; [ exact: (@rpred0D V S).1 | exact: rpredB ]. Qed.
End Sub.
End ZmodulePred.
Section SemiRingPred.
Variables (R : pzSemiRingType).
Section Mul.
Variable S : mulrClosed R.
Lemma rpred1M : mulr_closed S.
Proof. exact: (conj rpred1 rpredM). Qed.
Lemma rpred_prod I r (P : pred I) F :
(forall i, P i -> F i \in S) -> \prod_(i <- r | P i) F i \in S.
Proof. by move=> IH; elim/big_ind: _; [apply: rpred1 | apply: rpredM |]. Qed.
Lemma rpredX n : {in S, forall u, u ^+ n \in S}.
Proof. by move=> u Su; rewrite -(card_ord n) -prodr_const rpred_prod. Qed.
End Mul.
Lemma rpred_nat (S : semiringClosed R) n : n%:R \in S.
Proof. by rewrite rpredMn ?rpred1. Qed.
Lemma semiringClosedP (rngS : semiringClosed R) : semiring_closed rngS.
Proof. split; [ exact: rpred0D | exact: rpred1M ]. Qed.
End SemiRingPred.
Section RingPred.
Variables (R : pzRingType).
Lemma rpredMsign (S : opprClosed R) n x : ((-1) ^+ n * x \in S) = (x \in S).
Proof. by rewrite -signr_odd mulr_sign; case: ifP => // _; rewrite rpredN. Qed.
Lemma rpredN1 (S : smulClosed R) : -1 \in S.
Proof. by rewrite rpredN rpred1. Qed.
Lemma rpred_sign (S : smulClosed R) n : (-1) ^+ n \in S.
Proof. by rewrite rpredX ?rpredN1. Qed.
Lemma subringClosedP (rngS : subringClosed R) : subring_closed rngS.
Proof.
split; [ exact: rpred1 | exact: (zmodClosedP rngS).2 | exact: rpredM ].
Qed.
End RingPred.
Section LmodPred.
Variables (R : pzSemiRingType) (V : lSemiModType R).
Lemma rpredZnat (S : addrClosed V) n : {in S, forall u, n%:R *: u \in S}.
Proof. by move=> u Su; rewrite /= scaler_nat rpredMn. Qed.
Lemma subsemimodClosedP (modS : submodClosed V) : subsemimod_closed modS.
Proof. by split; [exact: rpred0D | exact: rpredZ]. Qed.
End LmodPred.
Section LmodPred.
Variables (R : pzRingType) (V : lmodType R).
Lemma rpredZsign (S : opprClosed V) n u : ((-1) ^+ n *: u \in S) = (u \in S).
Proof. by rewrite -signr_odd scaler_sign fun_if if_arg rpredN if_same. Qed.
Lemma submodClosedP (modS : submodClosed V) : submod_closed modS.
Proof.
split; first exact (@rpred0D V modS).1.
by move=> a u v uS vS; apply: rpredD; first exact: rpredZ.
Qed.
End LmodPred.
Section LalgPred.
Variables (R : pzRingType) (A : lalgType R).
Lemma subalgClosedP (algS : subalgClosed A) : subalg_closed algS.
Proof.
split; [ exact: rpred1 | | exact: rpredM ].
by move=> a u v uS vS; apply: rpredD; first exact: rpredZ.
Qed.
End LalgPred.
Section UnitRingPred.
Variable R : unitRingType.
Section Div.
Variable S : divClosed R.
Lemma rpredV x : (x^-1 \in S) = (x \in S).
Proof. by apply/idP/idP=> /rpredVr; rewrite ?invrK. Qed.
Lemma rpred_div : {in S &, forall x y, x / y \in S}.
Proof. by move=> x y Sx Sy; rewrite /= rpredM ?rpredV. Qed.
Lemma rpredXN n : {in S, forall x, x ^- n \in S}.
Proof. by move=> x Sx; rewrite /= rpredV rpredX. Qed.
Lemma rpredMl x y : x \in S -> x \is a unit-> (x * y \in S) = (y \in S).
Proof.
move=> Sx Ux; apply/idP/idP=> [Sxy | /(rpredM _ _ Sx)-> //].
by rewrite -(mulKr Ux y); rewrite rpredM ?rpredV.
Qed.
Lemma rpredMr x y : x \in S -> x \is a unit -> (y * x \in S) = (y \in S).
Proof.
move=> Sx Ux; apply/idP/idP=> [Sxy | /rpredM-> //].
by rewrite -(mulrK Ux y); rewrite rpred_div.
Qed.
Lemma rpred_divr x y : x \in S -> x \is a unit -> (y / x \in S) = (y \in S).
Proof. by rewrite -rpredV -unitrV; apply: rpredMr. Qed.
Lemma rpred_divl x y : x \in S -> x \is a unit -> (x / y \in S) = (y \in S).
Proof. by rewrite -(rpredV y); apply: rpredMl. Qed.
End Div.
Lemma divringClosedP (divS : divringClosed R) : divring_closed divS.
Proof. split; [ exact: rpred1 | exact: rpredB | exact: rpred_div ]. Qed.
Fact unitr_sdivr_closed : @sdivr_closed R unit.
Proof. by split=> [|x y Ux Uy]; rewrite ?unitrN1 // unitrMl ?unitrV. Qed.
#[export]
HB.instance Definition _ := isSdivClosed.Build R unit_pred unitr_sdivr_closed.
Implicit Type x : R.
Lemma unitrN x : (- x \is a unit) = (x \is a unit). Proof. exact: rpredN. Qed.
Lemma invrN x : (- x)^-1 = - x^-1.
Proof.
have [Ux | U'x] := boolP (x \is a unit); last by rewrite !invr_out ?unitrN.
by rewrite -mulN1r invrM ?unitrN1 // invrN1 mulrN1.
Qed.
Lemma divrNN x y : (- x) / (- y) = x / y.
Proof. by rewrite invrN mulrNN. Qed.
Lemma divrN x y : x / (- y) = - (x / y).
Proof. by rewrite invrN mulrN. Qed.
Lemma invr_signM n x : ((-1) ^+ n * x)^-1 = (-1) ^+ n * x^-1.
Proof. by rewrite -signr_odd !mulr_sign; case: ifP => // _; rewrite invrN. Qed.
Lemma divr_signM (b1 b2 : bool) x1 x2:
((-1) ^+ b1 * x1) / ((-1) ^+ b2 * x2) = (-1) ^+ (b1 (+) b2) * (x1 / x2).
Proof. by rewrite invr_signM mulr_signM. Qed.
End UnitRingPred.
Section FieldPred.
Variable F : fieldType.
Implicit Types x y : F.
Section ModuleTheory.
Variable V : lmodType F.
Implicit Types (a : F) (v : V).
Lemma rpredZeq (S : submodClosed V) a v :
(a *: v \in S) = (a == 0) || (v \in S).
Proof.
have [-> | nz_a] := eqVneq; first by rewrite scale0r rpred0.
by apply/idP/idP; first rewrite -{2}(scalerK nz_a v); apply: rpredZ.
Qed.
End ModuleTheory.
Section Predicates.
Context (S : divClosed F).
Lemma fpredMl x y : x \in S -> x != 0 -> (x * y \in S) = (y \in S).
Proof. by rewrite -!unitfE; apply: rpredMl. Qed.
Lemma fpredMr x y : x \in S -> x != 0 -> (y * x \in S) = (y \in S).
Proof. by rewrite -!unitfE; apply: rpredMr. Qed.
Lemma fpred_divl x y : x \in S -> x != 0 -> (x / y \in S) = (y \in S).
Proof. by rewrite -!unitfE; apply: rpred_divl. Qed.
Lemma fpred_divr x y : x \in S -> x != 0 -> (y / x \in S) = (y \in S).
Proof. by rewrite -!unitfE; apply: rpred_divr. Qed.
End Predicates.
End FieldPred.
HB.mixin Record isSubPzSemiRing (R : pzSemiRingType) (S : pred R) U
of SubNmodule R S U & PzSemiRing U := {
valM_subproof : monoid_morphism (val : U -> R);
}.
Module isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isSubPzSemiRing.Build instead.")]
Notation Build R S U := (isSubPzSemiRing.Build R S U) (only parsing).
End isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use isSubPzSemiRing instead.")]
Notation isSubSemiRing R S U := (isSubPzSemiRing R S U) (only parsing).
#[short(type="subPzSemiRingType")]
HB.structure Definition SubPzSemiRing (R : pzSemiRingType) (S : pred R) :=
{ U of SubNmodule R S U & PzSemiRing U & isSubPzSemiRing R S U }.
#[short(type="subNzSemiRingType")]
HB.structure Definition SubNzSemiRing (R : nzSemiRingType) (S : pred R) :=
{ U of SubNmodule R S U & NzSemiRing U & isSubPzSemiRing R S U }.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing instead.")]
Notation SubSemiRing R := (SubNzSemiRing R) (only parsing).
Module SubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing.sort instead.")]
Notation sort := (SubNzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing.on instead.")]
Notation on R := (SubNzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing.copy instead.")]
Notation copy T U := (SubNzSemiRing.copy T U) (only parsing).
End SubSemiRing.
Section multiplicative.
Context (R : pzSemiRingType) (S : pred R) (U : SubPzSemiRing.type S).
Notation val := (val : U -> R).
#[export]
HB.instance Definition _ := isMonoidMorphism.Build U R val valM_subproof.
Lemma val1 : val 1 = 1. Proof. exact: rmorph1. Qed.
Lemma valM : {morph val : x y / x * y}. Proof. exact: rmorphM. Qed.
Lemma valM1 : monoid_morphism val. Proof. exact: valM_subproof. Qed.
End multiplicative.
HB.factory Record SubNmodule_isSubPzSemiRing (R : pzSemiRingType) S U
of SubNmodule R S U := {
mulr_closed_subproof : mulr_closed S
}.
HB.builders Context R S U of SubNmodule_isSubPzSemiRing R S U.
HB.instance Definition _ := isMulClosed.Build R S mulr_closed_subproof.
Let inU v Sv : U := Sub v Sv.
Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)).
Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)).
Lemma mulrA : associative mulU.
Proof. by move=> x y z; apply: val_inj; rewrite !SubK mulrA. Qed.
Lemma mul1r : left_id oneU mulU.
Proof. by move=> x; apply: val_inj; rewrite !SubK mul1r. Qed.
Lemma mulr1 : right_id oneU mulU.
Proof. by move=> x; apply: val_inj; rewrite !SubK mulr1. Qed.
Lemma mulrDl : left_distributive mulU +%R.
Proof.
by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDl.
Qed.
Lemma mulrDr : right_distributive mulU +%R.
Proof.
by move=> x y z; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK mulrDr.
Qed.
Lemma mul0r : left_zero 0%R mulU.
Proof. by move=> x; apply: val_inj; rewrite SubK val0 mul0r. Qed.
Lemma mulr0 : right_zero 0%R mulU.
Proof. by move=> x; apply: val_inj; rewrite SubK val0 mulr0. Qed.
HB.instance Definition _ := Nmodule_isPzSemiRing.Build U
mulrA mul1r mulr1 mulrDl mulrDr mul0r mulr0.
Lemma valM : monoid_morphism (val : U -> R).
Proof. by split=> [|x y] /=; rewrite !SubK. Qed.
HB.instance Definition _ := isSubPzSemiRing.Build R S U valM.
HB.end.
HB.factory Record SubNmodule_isSubNzSemiRing (R : nzSemiRingType) S U
of SubNmodule R S U := {
mulr_closed_subproof : mulr_closed S
}.
Module SubNmodule_isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNmodule_isSubNzSemiRing.Build instead.")]
Notation Build R S U := (SubNmodule_isSubNzSemiRing.Build R S U) (only parsing).
End SubNmodule_isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNmodule_isSubNzSemiRing instead.")]
Notation SubNmodule_isSubSemiRing R S U :=
(SubNmodule_isSubNzSemiRing R S U) (only parsing).
HB.builders Context R S U of SubNmodule_isSubNzSemiRing R S U.
HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U
mulr_closed_subproof.
Lemma oner_neq0 : (1 : U) != 0.
Proof. by rewrite -(inj_eq val_inj) SubK raddf0 oner_neq0. Qed.
HB.instance Definition _ := PzSemiRing_isNonZero.Build U oner_neq0.
HB.end.
#[short(type="subComPzSemiRingType")]
HB.structure Definition SubComPzSemiRing (R : pzSemiRingType) S :=
{U of SubPzSemiRing R S U & ComPzSemiRing U}.
HB.factory Record SubPzSemiRing_isSubComPzSemiRing (R : comPzSemiRingType) S U
of SubPzSemiRing R S U := {}.
HB.builders Context R S U of SubPzSemiRing_isSubComPzSemiRing R S U.
Lemma mulrC : @commutative U U *%R.
Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed.
HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build U mulrC.
HB.end.
#[short(type="subComNzSemiRingType")]
HB.structure Definition SubComNzSemiRing (R : nzSemiRingType) S :=
{U of SubNzSemiRing R S U & ComNzSemiRing U}.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzSemiRing instead.")]
Notation SubComSemiRing R := (SubComNzSemiRing R) (only parsing).
Module SubComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzSemiRing.sort instead.")]
Notation sort := (SubComNzSemiRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzSemiRing.on instead.")]
Notation on R := (SubComNzSemiRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzSemiRing.copy instead.")]
Notation copy T U := (SubComNzSemiRing.copy T U) (only parsing).
End SubComSemiRing.
HB.factory Record SubNzSemiRing_isSubComNzSemiRing (R : comNzSemiRingType) S U
of SubNzSemiRing R S U := {}.
Module SubSemiRing_isSubComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing_isSubComNzSemiRing.Build instead.")]
Notation Build R S U :=
(SubNzSemiRing_isSubComNzSemiRing.Build R S U) (only parsing).
End SubSemiRing_isSubComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzSemiRing_isSubComNzSemiRing instead.")]
Notation SubSemiRing_isSubComSemiRing R S U :=
(SubNzSemiRing_isSubComNzSemiRing R S U) (only parsing).
HB.builders Context R S U of SubNzSemiRing_isSubComNzSemiRing R S U.
HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U.
HB.end.
#[short(type="subPzRingType")]
HB.structure Definition SubPzRing (R : pzRingType) (S : pred R) :=
{ U of SubPzSemiRing R S U & PzRing U & isSubZmodule R S U }.
HB.factory Record SubZmodule_isSubPzRing (R : pzRingType) S U
of SubZmodule R S U := {
subring_closed_subproof : subring_closed S
}.
HB.builders Context R S U of SubZmodule_isSubPzRing R S U.
HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof.
Let inU v Sv : U := Sub v Sv.
Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)).
Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)).
HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U
(smulr_closedM (subring_closedM subring_closed_subproof)).
HB.end.
#[short(type="subNzRingType")]
HB.structure Definition SubNzRing (R : nzRingType) (S : pred R) :=
{ U of SubNzSemiRing R S U & NzRing U & isSubBaseAddUMagma R S U }.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing instead.")]
Notation SubRing R := (SubNzRing R) (only parsing).
Module SubRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing.sort instead.")]
Notation sort := (SubNzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing.on instead.")]
Notation on R := (SubNzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing.copy instead.")]
Notation copy T U := (SubNzRing.copy T U) (only parsing).
End SubRing.
HB.factory Record SubZmodule_isSubNzRing (R : nzRingType) S U
of SubZmodule R S U := {
subring_closed_subproof : subring_closed S
}.
Module SubZmodule_isSubRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubZmodule_isSubNzRing.Build instead.")]
Notation Build R S U := (SubZmodule_isSubNzRing.Build R S U) (only parsing).
End SubZmodule_isSubRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubZmodule_isSubNzRing instead.")]
Notation SubZmodule_isSubRing R S U :=
(SubZmodule_isSubNzRing R S U) (only parsing).
HB.builders Context R S U of SubZmodule_isSubNzRing R S U.
HB.instance Definition _ := isSubringClosed.Build R S subring_closed_subproof.
Let inU v Sv : U := Sub v Sv.
Let oneU : U := inU (@rpred1 _ (MulClosed.clone R S _)).
Let mulU (u1 u2 : U) := inU (rpredM _ _ (valP u1) (valP u2)).
HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U
(smulr_closedM (subring_closedM subring_closed_subproof)).
HB.end.
#[short(type="subComPzRingType")]
HB.structure Definition SubComPzRing (R : pzRingType) S :=
{U of SubPzRing R S U & ComPzRing U}.
HB.factory Record SubPzRing_isSubComPzRing (R : comPzRingType) S U
of SubPzRing R S U := {}.
HB.builders Context R S U of SubPzRing_isSubComPzRing R S U.
Lemma mulrC : @commutative U U *%R.
Proof. by move=> x y; apply: val_inj; rewrite !rmorphM mulrC. Qed.
HB.instance Definition _ := PzRing_hasCommutativeMul.Build U mulrC.
HB.end.
#[short(type="subComNzRingType")]
HB.structure Definition SubComNzRing (R : nzRingType) S :=
{U of SubNzRing R S U & ComNzRing U}.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzRing instead.")]
Notation SubComRing R := (SubComNzRing R) (only parsing).
Module SubComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzRing.sort instead.")]
Notation sort := (SubComNzRing.sort) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzRing.on instead.")]
Notation on R := (SubComNzRing.on R) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Use SubComNzRing.copy instead.")]
Notation copy T U := (SubComNzRing.copy T U) (only parsing).
End SubComRing.
HB.factory Record SubNzRing_isSubComNzRing (R : comNzRingType) S U
of SubNzRing R S U := {}.
Module SubRing_isSubComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing_isSubComNzRing.Build instead.")]
Notation Build R S U := (SubNzRing_isSubComNzRing.Build R S U) (only parsing).
End SubRing_isSubComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing_isSubComNzRing instead.")]
Notation SubRing_isSubComRing R S U :=
(SubNzRing_isSubComNzRing R S U) (only parsing).
HB.builders Context R S U of SubNzRing_isSubComNzRing R S U.
HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U.
HB.end.
HB.mixin Record isSubLSemiModule (R : pzSemiRingType) (V : lSemiModType R)
(S : pred V) W of SubNmodule V S W & LSemiModule R W := {
valZ : scalable (val : W -> V);
}.
#[short(type="subLSemiModType")]
HB.structure Definition SubLSemiModule (R : pzSemiRingType) (V : lSemiModType R)
(S : pred V) :=
{ W of SubNmodule V S W &
Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}.
#[short(type="subLmodType")]
HB.structure Definition SubLmodule (R : pzRingType) (V : lmodType R)
(S : pred V) :=
{ W of SubZmodule V S W &
Nmodule_isLSemiModule R W & isSubLSemiModule R V S W}.
Section linear.
Context (R : pzSemiRingType) (V : lSemiModType R).
Context (S : pred V) (W : subLSemiModType S).
Notation val := (val : W -> V).
#[export]
HB.instance Definition _ := isScalable.Build R W V *:%R val valZ.
End linear.
HB.factory Record isSubLmodule (R : pzRingType) (V : lmodType R) (S : pred V)
W of SubZmodule V S W & Lmodule R W := {
valZ : scalable (val : W -> V);
}.
HB.builders Context (R : pzRingType) (V : lmodType R) S W of
isSubLmodule R V S W.
HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ.
HB.end.
HB.factory Record SubNmodule_isSubLSemiModule
(R : pzSemiRingType) (V : lSemiModType R) S W of SubNmodule V S W := {
submod_closed_subproof : subsemimod_closed S
}.
HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W
of SubNmodule_isSubLSemiModule R V S W.
HB.instance Definition _ :=
isSubSemiModClosed.Build R V S submod_closed_subproof.
Let inW v Sv : W := Sub v Sv.
Let scaleW a (w : W) := inW (rpredZ a _ (valP w)).
Lemma scalerA' a b v : scaleW a (scaleW b v) = scaleW (a * b) v.
Proof. by apply: val_inj; rewrite !SubK scalerA. Qed.
Lemma scale0r v : scaleW 0 v = 0.
Proof. by apply: val_inj; rewrite SubK scale0r raddf0. Qed.
Lemma scale1r : left_id 1 scaleW.
Proof. by move=> x; apply: val_inj; rewrite SubK scale1r. Qed.
Lemma scalerDr : right_distributive scaleW +%R.
Proof.
by move=> a u v; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK.
Qed.
Lemma scalerDl v : {morph scaleW^~ v : a b / a + b}.
Proof.
by move=> a b; apply: val_inj; rewrite !(SubK, raddfD)/= !SubK scalerDl.
Qed.
HB.instance Definition _ := Nmodule_isLSemiModule.Build R W
scalerA' scale0r scale1r scalerDr scalerDl.
Fact valZ : scalable (val : W -> _). Proof. by move=> k w; rewrite SubK. Qed.
HB.instance Definition _ := isSubLSemiModule.Build R V S W valZ.
HB.end.
HB.factory Record SubZmodule_isSubLmodule (R : pzRingType) (V : lmodType R) S W
of SubZmodule V S W := {
submod_closed_subproof : submod_closed S
}.
HB.builders Context (R : pzRingType) (V : lmodType R) S W
of SubZmodule_isSubLmodule R V S W.
HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W
(submod_closed_semi submod_closed_subproof).
HB.end.
#[short(type="subLSemiAlgType")]
HB.structure Definition SubLSemiAlgebra
(R : pzSemiRingType) (V : lSemiAlgType R) S :=
{W of SubNzSemiRing V S W & @SubLSemiModule R V S W & LSemiAlgebra R W}.
#[short(type="subLalgType")]
HB.structure Definition SubLalgebra (R : pzRingType) (V : lalgType R) S :=
{W of SubNzRing V S W & @SubLmodule R V S W & Lalgebra R W}.
HB.factory Record SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra
(R : pzSemiRingType) (V : lSemiAlgType R) S W
of SubNzSemiRing V S W & @SubLSemiModule R V S W := {}.
HB.builders Context (R : pzSemiRingType) (V : lSemiAlgType R) S W
of SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra R V S W.
Lemma scalerAl (a : R) (u v : W) : a *: (u * v) = a *: u * v.
Proof. by apply: val_inj; rewrite !(linearZ, rmorphM) /= linearZ scalerAl. Qed.
HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R W scalerAl.
HB.end.
HB.factory Record SubNzRing_SubLmodule_isSubLalgebra (R : pzRingType)
(V : lalgType R) S W of SubNzRing V S W & @SubLmodule R V S W := {}.
Module SubRing_SubLmodule_isSubLalgebra.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing_SubLmodule_isSubLalgebra.Build instead.")]
Notation Build R V S U :=
(SubNzRing_SubLmodule_isSubLalgebra.Build R V S U) (only parsing).
End SubRing_SubLmodule_isSubLalgebra.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubNzRing_SubLmodule_isSubLalgebra instead.")]
Notation SubRing_SubLmodule_isSubLalgebra R V S U :=
(SubNzRing_SubLmodule_isSubLalgebra R V S U) (only parsing).
HB.builders Context (R : pzRingType) (V : lalgType R) S W
of SubNzRing_SubLmodule_isSubLalgebra R V S W.
HB.instance Definition _ :=
SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build R V S W.
HB.end.
#[short(type="subSemiAlgType")]
HB.structure Definition SubSemiAlgebra (R : pzSemiRingType) (V : semiAlgType R)
S :=
{W of @SubLSemiAlgebra R V S W & SemiAlgebra R W}.
#[short(type="subAlgType")]
HB.structure Definition SubAlgebra (R : pzRingType) (V : algType R) S :=
{W of @SubLalgebra R V S W & Algebra R W}.
HB.factory Record SubLSemiAlgebra_isSubSemiAlgebra (R : pzSemiRingType)
(V : semiAlgType R) S W of @SubLSemiAlgebra R V S W := {}.
HB.builders Context (R : pzSemiRingType) (V : semiAlgType R) S W
of SubLSemiAlgebra_isSubSemiAlgebra R V S W.
Lemma scalerAr (k : R) (x y : W) : k *: (x * y) = x * (k *: y).
Proof. by apply: val_inj; rewrite !(linearZ, rmorphM)/= linearZ scalerAr. Qed.
HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R W scalerAr.
HB.end.
HB.factory Record SubLalgebra_isSubAlgebra (R : pzRingType)
(V : algType R) S W of @SubLalgebra R V S W := {}.
HB.builders Context (R : pzRingType) (V : algType R) S W
of SubLalgebra_isSubAlgebra R V S W.
HB.instance Definition _ := SubLSemiAlgebra_isSubSemiAlgebra.Build R V S W.
HB.end.
#[short(type="subUnitRingType")]
HB.structure Definition SubUnitRing (R : nzRingType) (S : pred R) :=
{U of SubNzRing R S U & UnitRing U}.
HB.factory Record SubNzRing_isSubUnitRing (R : unitRingType) S U
of SubNzRing R S U := {
divring_closed_subproof : divring_closed S
}.
HB.builders Context (R : unitRingType) S U of SubNzRing_isSubUnitRing R S U.
HB.instance Definition _ := isDivringClosed.Build R S divring_closed_subproof.
Let inU v Sv : U := Sub v Sv.
Let invU (u : U) := inU (rpredVr _ (valP u)).
Lemma mulVr : {in [pred x | val x \is a unit], left_inverse 1 invU *%R}.
Proof.
by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulVr.
Qed.
Lemma divrr : {in [pred x | val x \is a unit], right_inverse 1 invU *%R}.
by move=> x /[!inE] xu; apply: val_inj; rewrite rmorphM rmorph1 /= SubK mulrV.
Qed.
Lemma unitrP (x y : U) : y * x = 1 /\ x * y = 1 -> val x \is a unit.
Proof.
move=> -[/(congr1 val) yx1 /(congr1 val) xy1].
by apply: rev_unitrP (val y) _; rewrite !rmorphM rmorph1 /= in yx1 xy1.
Qed.
Lemma invr_out : {in [pred x | val x \isn't a unit], invU =1 id}.
Proof.
by move=> x /[!inE] xNU; apply: val_inj; rewrite SubK invr_out.
Qed.
HB.instance Definition _ := NzRing_hasMulInverse.Build U
mulVr divrr unitrP invr_out.
HB.end.
#[short(type="subComUnitRingType")]
HB.structure Definition SubComUnitRing (R : comUnitRingType) (S : pred R) :=
{U of SubComNzRing R S U & SubUnitRing R S U}.
#[short(type="subIdomainType")]
HB.structure Definition SubIntegralDomain (R : idomainType) (S : pred R) :=
{U of SubComNzRing R S U & IntegralDomain U}.
HB.factory Record SubComUnitRing_isSubIntegralDomain (R : idomainType) S U
of SubComUnitRing R S U := {}.
HB.builders Context (R : idomainType) S U
of SubComUnitRing_isSubIntegralDomain R S U.
Lemma id : IntegralDomain.axiom U.
Proof.
move=> x y /(congr1 val)/eqP; rewrite rmorphM /=.
by rewrite -!(inj_eq val_inj) rmorph0 -mulf_eq0.
Qed.
HB.instance Definition _ := ComUnitRing_isIntegral.Build U id.
HB.end.
#[short(type="subFieldType")]
HB.structure Definition SubField (F : fieldType) (S : pred F) :=
{U of SubIntegralDomain F S U & Field U}.
HB.factory Record SubIntegralDomain_isSubField (F : fieldType) S U
of SubIntegralDomain F S U := {
subfield_subproof : {mono (val : U -> F) : u / u \in unit}
}.
HB.builders Context (F : fieldType) S U of SubIntegralDomain_isSubField F S U.
Lemma fieldP : Field.axiom U.
Proof.
by move=> u; rewrite -(inj_eq val_inj) rmorph0 -unitfE subfield_subproof.
Qed.
HB.instance Definition _ := UnitRing_isField.Build U fieldP.
HB.end.
HB.factory Record SubChoice_isSubPzSemiRing (R : pzSemiRingType) S U
of SubChoice R S U := {
semiring_closed_subproof : semiring_closed S
}.
HB.builders Context (R : pzSemiRingType) S U of SubChoice_isSubPzSemiRing R S U.
HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U
(semiring_closedD semiring_closed_subproof).
HB.instance Definition _ := SubNmodule_isSubPzSemiRing.Build R S U
(semiring_closedM semiring_closed_subproof).
HB.end.
HB.factory Record SubChoice_isSubNzSemiRing (R : nzSemiRingType) S U
of SubChoice R S U := {
semiring_closed_subproof : semiring_closed S
}.
Module SubChoice_isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubNzSemiRing.Build instead.")]
Notation Build R S U := (SubChoice_isSubNzSemiRing.Build R S U) (only parsing).
End SubChoice_isSubSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubNzSemiRing instead.")]
Notation SubChoice_isSubSemiRing R S U :=
(SubChoice_isSubNzSemiRing R S U) (only parsing).
HB.builders Context (R : nzSemiRingType) S U of SubChoice_isSubNzSemiRing R S U.
HB.instance Definition _ := SubChoice_isSubNmodule.Build R S U
(semiring_closedD semiring_closed_subproof).
HB.instance Definition _ := SubNmodule_isSubNzSemiRing.Build R S U
(semiring_closedM semiring_closed_subproof).
HB.end.
HB.factory Record SubChoice_isSubComPzSemiRing (R : comPzSemiRingType) S U
of SubChoice R S U := {
semiring_closed_subproof : semiring_closed S
}.
HB.builders Context (R : comPzSemiRingType) S U
of SubChoice_isSubComPzSemiRing R S U.
HB.instance Definition _ := SubChoice_isSubPzSemiRing.Build R S U
semiring_closed_subproof.
HB.instance Definition _ := SubPzSemiRing_isSubComPzSemiRing.Build R S U.
HB.end.
HB.factory Record SubChoice_isSubComNzSemiRing (R : comNzSemiRingType) S U
of SubChoice R S U := {
semiring_closed_subproof : semiring_closed S
}.
Module SubChoice_isSubComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubComNzSemiRing.Build instead.")]
Notation Build R S U :=
(SubChoice_isSubComNzSemiRing.Build R S U) (only parsing).
End SubChoice_isSubComSemiRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubComNzSemiRing instead.")]
Notation SubChoice_isSubComSemiRing R S U :=
(SubChoice_isSubComNzSemiRing R S U) (only parsing).
HB.builders Context (R : comNzSemiRingType) S U
of SubChoice_isSubComNzSemiRing R S U.
HB.instance Definition _ := SubChoice_isSubNzSemiRing.Build R S U
semiring_closed_subproof.
HB.instance Definition _ := SubNzSemiRing_isSubComNzSemiRing.Build R S U.
HB.end.
HB.factory Record SubChoice_isSubPzRing (R : pzRingType) S U of SubChoice R S U := {
subring_closed_subproof : subring_closed S
}.
HB.builders Context (R : pzRingType) S U of SubChoice_isSubPzRing R S U.
HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U
(subring_closedB subring_closed_subproof).
HB.instance Definition _ := SubZmodule_isSubPzRing.Build R S U
subring_closed_subproof.
HB.end.
HB.factory Record SubChoice_isSubNzRing (R : nzRingType) S U of SubChoice R S U := {
subring_closed_subproof : subring_closed S
}.
Module SubChoice_isSubRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubNzRing.Build instead.")]
Notation Build R S U := (SubChoice_isSubNzRing.Build R S U) (only parsing).
End SubChoice_isSubRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubNzRing instead.")]
Notation SubChoice_isSubRing R S U :=
(SubChoice_isSubNzRing R S U) (only parsing).
HB.builders Context (R : nzRingType) S U of SubChoice_isSubNzRing R S U.
HB.instance Definition _ := SubChoice_isSubZmodule.Build R S U
(subring_closedB subring_closed_subproof).
HB.instance Definition _ := SubZmodule_isSubNzRing.Build R S U
subring_closed_subproof.
HB.end.
HB.factory Record SubChoice_isSubComPzRing (R : comPzRingType) S U
of SubChoice R S U := {
subring_closed_subproof : subring_closed S
}.
HB.builders Context (R : comPzRingType) S U of SubChoice_isSubComPzRing R S U.
HB.instance Definition _ := SubChoice_isSubPzRing.Build R S U
subring_closed_subproof.
HB.instance Definition _ := SubPzRing_isSubComPzRing.Build R S U.
HB.end.
HB.factory Record SubChoice_isSubComNzRing (R : comNzRingType) S U
of SubChoice R S U := {
subring_closed_subproof : subring_closed S
}.
Module SubChoice_isSubComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubComNzRing.Build instead.")]
Notation Build R S U := (SubChoice_isSubComNzRing.Build R S U) (only parsing).
End SubChoice_isSubComRing.
#[deprecated(since="mathcomp 2.4.0",
note="Use SubChoice_isSubComNzRing instead.")]
Notation SubChoice_isSubComRing R S U :=
(SubChoice_isSubComNzRing R S U) (only parsing).
HB.builders Context (R : comNzRingType) S U of SubChoice_isSubComNzRing R S U.
HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U
subring_closed_subproof.
HB.instance Definition _ := SubNzRing_isSubComNzRing.Build R S U.
HB.end.
HB.factory Record SubChoice_isSubLSemiModule
(R : pzSemiRingType) (V : lSemiModType R) S W of SubChoice V S W := {
subsemimod_closed_subproof : subsemimod_closed S
}.
HB.builders Context (R : pzSemiRingType) (V : lSemiModType R) S W
of SubChoice_isSubLSemiModule R V S W.
HB.instance Definition _ := SubChoice_isSubNmodule.Build V S W
(subsemimod_closedD subsemimod_closed_subproof).
HB.instance Definition _ := SubNmodule_isSubLSemiModule.Build R V S W
subsemimod_closed_subproof.
HB.end.
HB.factory Record SubChoice_isSubLmodule (R : pzRingType) (V : lmodType R) S W
of SubChoice V S W := {
submod_closed_subproof : submod_closed S
}.
HB.builders Context (R : pzRingType) (V : lmodType R) S W
of SubChoice_isSubLmodule R V S W.
HB.instance Definition _ := SubChoice_isSubZmodule.Build V S W
(submod_closedB submod_closed_subproof).
HB.instance Definition _ := SubZmodule_isSubLmodule.Build R V S W
submod_closed_subproof.
HB.end.
(* TODO: SubChoice_isSubLSemiAlgebra? *)
HB.factory Record SubChoice_isSubLalgebra (R : pzRingType) (A : lalgType R) S W
of SubChoice A S W := {
subalg_closed_subproof : subalg_closed S
}.
HB.builders Context (R : pzRingType) (A : lalgType R) S W
of SubChoice_isSubLalgebra R A S W.
HB.instance Definition _ := SubChoice_isSubNzRing.Build A S W
(subalg_closedBM subalg_closed_subproof).
HB.instance Definition _ := SubZmodule_isSubLmodule.Build R A S W
(subalg_closedZ subalg_closed_subproof).
HB.instance Definition _ := SubNzRing_SubLmodule_isSubLalgebra.Build R A S W.
HB.end.
(* TODO: SubChoice_isSubSemiAlgebra? *)
HB.factory Record SubChoice_isSubAlgebra (R : pzRingType) (A : algType R) S W
of SubChoice A S W := {
subalg_closed_subproof : subalg_closed S
}.
HB.builders Context (R : pzRingType) (A : algType R) S W
of SubChoice_isSubAlgebra R A S W.
HB.instance Definition _ := SubChoice_isSubLalgebra.Build R A S W
subalg_closed_subproof.
HB.instance Definition _ := SubLalgebra_isSubAlgebra.Build R A S W.
HB.end.
HB.factory Record SubChoice_isSubUnitRing (R : unitRingType) S U
of SubChoice R S U := {
divring_closed_subproof : divring_closed S
}.
HB.builders Context (R : unitRingType) S U of SubChoice_isSubUnitRing R S U.
HB.instance Definition _ := SubChoice_isSubNzRing.Build R S U
(divring_closedBM divring_closed_subproof).
HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U
divring_closed_subproof.
HB.end.
HB.factory Record SubChoice_isSubComUnitRing (R : comUnitRingType) S U
of SubChoice R S U := {
divring_closed_subproof : divring_closed S
}.
HB.builders Context (R : comUnitRingType) S U
of SubChoice_isSubComUnitRing R S U.
HB.instance Definition _ := SubChoice_isSubComNzRing.Build R S U
(divring_closedBM divring_closed_subproof).
HB.instance Definition _ := SubNzRing_isSubUnitRing.Build R S U
divring_closed_subproof.
HB.end.
HB.factory Record SubChoice_isSubIntegralDomain (R : idomainType) S U
of SubChoice R S U := {
divring_closed_subproof : divring_closed S
}.
HB.builders Context (R : idomainType) S U
of SubChoice_isSubIntegralDomain R S U.
HB.instance Definition _ := SubChoice_isSubComUnitRing.Build R S U
divring_closed_subproof.
HB.instance Definition _ := SubComUnitRing_isSubIntegralDomain.Build R S U.
HB.end.
Module SubExports.
Notation "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]" :=
(SubChoice_isSubNmodule.Build _ _ U rpred0D)
(format "[ 'SubChoice_isSubNmodule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]" :=
(SubChoice_isSubZmodule.Build _ _ U (zmodClosedP _))
(format "[ 'SubChoice_isSubZmodule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]" :=
(SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _))
(format "[ 'SubNmodule_isSubNzSemiRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ SubNmodule_isSubNzSemiRing of U by <: ] instead.")]
Notation "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]" :=
(SubNmodule_isSubNzSemiRing.Build _ _ U (@rpred1M _ _))
(format "[ 'SubNmodule_isSubSemiRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _))
(format "[ 'SubChoice_isSubNzSemiRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubChoice_isSubNzSemiRing' of U by <: ] instead.")]
Notation "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubNzSemiRing.Build _ _ U (semiringClosedP _))
(format "[ 'SubChoice_isSubSemiRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]" :=
(SubNzSemiRing_isSubComNzSemiRing.Build _ _ U)
(format "[ 'SubNzSemiRing_isSubComNzSemiRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubNzSemiRing_isSubComNzSemiRing' of U by <: ] instead.")]
Notation "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]" :=
(SubNzSemiRing_isSubComNzSemiRing.Build _ _ U)
(format "[ 'SubSemiRing_isSubComSemiRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _))
(format "[ 'SubChoice_isSubComNzSemiRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubChoice_isSubComNzSemiRing' of U by <: ] instead.")]
Notation "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubComNzSemiRing.Build _ _ U (semiringClosedP _))
(format "[ 'SubChoice_isSubComSemiRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]" :=
(SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubZmodule_isSubNzRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubZmodule_isSubNzRing' of U by <: ] instead.")]
Notation "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]" :=
(SubZmodule_isSubNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubZmodule_isSubRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubChoice_isSubNzRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubChoice_isSubNzRing' of U by <: ] instead.")]
Notation "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubChoice_isSubRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]" :=
(SubNzRing_isSubComNzRing.Build _ _ U)
(format "[ 'SubNzRing_isSubComNzRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubNzRing_isSubComNzRing' of U by <: ] instead.")]
Notation "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]" :=
(SubNzRing_isSubComNzRing.Build _ _ U)
(format "[ 'SubRing_isSubComRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubChoice_isSubComNzRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubChoice_isSubComNzRing' of U by <: ] instead.")]
Notation "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubComNzRing.Build _ _ U (subringClosedP _))
(format "[ 'SubChoice_isSubComRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]" :=
(SubNmodule_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _))
(format "[ 'SubNmodule_isSubLSemiModule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]" :=
(SubChoice_isSubLSemiModule.Build _ _ _ U (subsemimodClosedP _))
(format "[ 'SubChoice_isSubLSemiModule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]" :=
(SubZmodule_isSubLmodule.Build _ _ _ U (submodClosedP _))
(format "[ 'SubZmodule_isSubLmodule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]" :=
(SubChoice_isSubLmodule.Build _ _ _ U (submodClosedP _))
(format "[ 'SubChoice_isSubLmodule' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]" :=
(SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra.Build _ _ _ U)
(format "[ 'SubNzSemiRing_SubLSemiModule_isSubLSemiAlgebra' 'of' U 'by' <: ]")
: form_scope.
(* TODO: SubChoice_isSubLSemiAlgebra? *)
Notation "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" :=
(SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U)
(format "[ 'SubNzRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubNzRing_SubLmodule_isSubLalgebra' of U by <: ] instead.")]
Notation "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]" :=
(SubNzRing_SubLmodule_isSubLalgebra.Build _ _ _ U)
(format "[ 'SubRing_SubLmodule_isSubLalgebra' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]" :=
(SubChoice_isSubLalgebra.Build _ _ _ U (subalgClosedP _))
(format "[ 'SubChoice_isSubLalgebra' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]" :=
(SubLSemiAlgebra_isSubSemiAlgebra.Build _ _ _ U)
(format "[ 'SubLSemiAlgebra_isSubSemiAlgebra' 'of' U 'by' <: ]")
: form_scope.
(* TODO: SubChoice_isSubSemiAlgebra? *)
Notation "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]" :=
(SubLalgebra_isSubAlgebra.Build _ _ _ U)
(format "[ 'SubLalgebra_isSubAlgebra' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]" :=
(SubChoice_isSubAlgebra.Build _ _ _ U (subalgClosedP _))
(format "[ 'SubChoice_isSubAlgebra' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]" :=
(SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _))
(format "[ 'SubNzRing_isSubUnitRing' 'of' U 'by' <: ]")
: form_scope.
#[deprecated(since="mathcomp 2.4.0",
note="Use [ 'SubNzRing_isSubUnitRing' of U by <: ] instead.")]
Notation "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]" :=
(SubNzRing_isSubUnitRing.Build _ _ U (divringClosedP _))
(format "[ 'SubRing_isSubUnitRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubUnitRing.Build _ _ U (divringClosedP _))
(format "[ 'SubChoice_isSubUnitRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]" :=
(SubChoice_isSubComUnitRing.Build _ _ U (divringClosedP _))
(format "[ 'SubChoice_isSubComUnitRing' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]" :=
(SubComUnitRing_isSubIntegralDomain.Build _ _ U)
(format "[ 'SubComUnitRing_isSubIntegralDomain' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]" :=
(SubChoice_isSubIntegralDomain.Build _ _ U (divringClosedP _))
(format "[ 'SubChoice_isSubIntegralDomain' 'of' U 'by' <: ]")
: form_scope.
Notation "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]" :=
(SubIntegralDomain_isSubField.Build _ _ U (frefl _))
(format "[ 'SubIntegralDomain_isSubField' 'of' U 'by' <: ]")
: form_scope.
End SubExports.
HB.export SubExports.
Module Theory.
Definition addrA := @addrA.
Definition addrC := @addrC.
Definition add0r := @add0r.
Definition addNr := @addNr.
Definition addr0 := addr0.
Definition addrN := addrN.
Definition subrr := subrr.
Definition addrCA := addrCA.
Definition addrAC := addrAC.
Definition addrACA := addrACA.
Definition addKr := addKr.
Definition addNKr := addNKr.
Definition addrK := addrK.
Definition addrNK := addrNK.
Definition subrK := subrK.
Definition subKr := subKr.
Definition addrI := @addrI.
Definition addIr := @addIr.
Definition subrI := @subrI.
Definition subIr := @subIr.
Arguments addrI {V} y [x1 x2].
Arguments addIr {V} x [x1 x2].
Arguments subrI {V} y [x1 x2].
Arguments subIr {V} x [x1 x2].
Definition opprK := @opprK.
Arguments opprK {V}.
Definition oppr_inj := @oppr_inj.
Arguments oppr_inj {V} [x1 x2].
Definition oppr0 := oppr0.
Definition oppr_eq0 := oppr_eq0.
Definition opprD := opprD.
Definition opprB := opprB.
Definition addrKA := addrKA.
Definition subrKA := subrKA.
Definition subr0 := subr0.
Definition sub0r := sub0r.
Definition subr_eq := subr_eq.
Definition addr0_eq := addr0_eq.
Definition subr0_eq := subr0_eq.
Definition subr_eq0 := subr_eq0.
Definition addr_eq0 := addr_eq0.
Definition eqr_opp := eqr_opp.
Definition eqr_oppLR := eqr_oppLR.
Definition sumrN := sumrN.
Definition sumrB := sumrB.
Definition sumrMnl := sumrMnl.
Definition sumrMnr := sumrMnr.
Definition sumr_const := sumr_const.
Definition sumr_const_nat := sumr_const_nat.
Definition telescope_sumr := telescope_sumr.
Definition telescope_sumr_eq := @telescope_sumr_eq.
Arguments telescope_sumr_eq {V n m} f u.
Definition mulr0n := mulr0n.
Definition mulr1n := mulr1n.
Definition mulr2n := mulr2n.
Definition mulrS := mulrS.
Definition mulrSr := mulrSr.
Definition mulrb := mulrb.
Definition mul0rn := mul0rn.
Definition mulNrn := mulNrn.
Definition mulrnDl := mulrnDl.
Definition mulrnDr := mulrnDr.
Definition mulrnBl := mulrnBl.
Definition mulrnBr := mulrnBr.
Definition mulrnA := mulrnA.
Definition mulrnAC := mulrnAC.
Definition iter_addr := iter_addr.
Definition iter_addr_0 := iter_addr_0.
Definition mulrA := @mulrA.
Definition mul1r := @mul1r.
Definition mulr1 := @mulr1.
Definition mulrDl := @mulrDl.
Definition mulrDr := @mulrDr.
Definition oner_neq0 := @oner_neq0.
Definition oner_eq0 := oner_eq0.
Definition mul0r := @mul0r.
Definition mulr0 := @mulr0.
Definition mulrN := mulrN.
Definition mulNr := mulNr.
Definition mulrNN := mulrNN.
Definition mulN1r := mulN1r.
Definition mulrN1 := mulrN1.
Definition mulr_suml := mulr_suml.
Definition mulr_sumr := mulr_sumr.
Definition mulrBl := mulrBl.
Definition mulrBr := mulrBr.
Definition mulrnAl := mulrnAl.
Definition mulrnAr := mulrnAr.
Definition mulr_natl := mulr_natl.
Definition mulr_natr := mulr_natr.
Definition natrD := natrD.
Definition nat1r := nat1r.
Definition natr1 := natr1.
Arguments natr1 {R} n.
Arguments nat1r {R} n.
Definition natrB := natrB.
Definition natr_sum := natr_sum.
Definition natrM := natrM.
Definition natrX := natrX.
Definition expr0 := expr0.
Definition exprS := exprS.
Definition expr1 := expr1.
Definition expr2 := expr2.
Definition expr0n := expr0n.
Definition expr1n := expr1n.
Definition exprD := exprD.
Definition exprSr := exprSr.
Definition expr_sum := expr_sum.
Definition commr_sym := commr_sym.
Definition commr_refl := commr_refl.
Definition commr0 := commr0.
Definition commr1 := commr1.
Definition commrN := commrN.
Definition commrN1 := commrN1.
Definition commrD := commrD.
Definition commrB := commrB.
Definition commr_sum := commr_sum.
Definition commr_prod := commr_prod.
Definition commrMn := commrMn.
Definition commrM := commrM.
Definition commr_nat := commr_nat.
Definition commrX := commrX.
Definition exprMn_comm := exprMn_comm.
Definition commr_sign := commr_sign.
Definition exprMn_n := exprMn_n.
Definition exprM := exprM.
Definition exprAC := exprAC.
Definition expr_mod := expr_mod.
Definition expr_dvd := expr_dvd.
Definition signr_odd := signr_odd.
Definition signr_eq0 := signr_eq0.
Definition mulr_sign := mulr_sign.
Definition signr_addb := signr_addb.
Definition signrN := signrN.
Definition signrE := signrE.
Definition mulr_signM := mulr_signM.
Definition exprNn := exprNn.
Definition sqrrN := sqrrN.
Definition sqrr_sign := sqrr_sign.
Definition signrMK := signrMK.
Definition mulrI_eq0 := mulrI_eq0.
Definition lreg_neq0 := lreg_neq0.
Definition mulrI0_lreg := mulrI0_lreg.
Definition lregN := lregN.
Definition lreg1 := lreg1.
Definition lregM := lregM.
Definition lregX := lregX.
Definition lreg_sign := lreg_sign.
Definition lregP {R x} := @lregP R x.
Definition mulIr_eq0 := mulIr_eq0.
Definition mulIr0_rreg := mulIr0_rreg.
Definition rreg_neq0 := rreg_neq0.
Definition rregN := rregN.
Definition rreg1 := rreg1.
Definition rregM := rregM.
Definition revrX := revrX.
Definition rregX := rregX.
Definition rregP {R x} := @rregP R x.
Definition exprDn_comm := exprDn_comm.
Definition exprBn_comm := exprBn_comm.
Definition subrXX_comm := subrXX_comm.
Definition exprD1n := exprD1n.
Definition subrX1 := subrX1.
Definition sqrrD1 := sqrrD1.
Definition sqrrB1 := sqrrB1.
Definition subr_sqr_1 := subr_sqr_1.
Definition pcharf0 := pcharf0.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0 instead.")]
Definition charf0 := pcharf0.
Definition pcharf_prime := pcharf_prime.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_prime instead.")]
Definition charf_prime := pcharf_prime.
Definition mulrn_pchar := mulrn_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use mulrn_pchar instead.")]
Definition mulrn_char := mulrn_pchar.
Definition dvdn_pcharf := dvdn_pcharf.
#[deprecated(since="mathcomp 2.4.0", note="Use dvdn_pcharf instead.")]
Definition dvdn_charf := dvdn_pcharf.
Definition pcharf_eq := pcharf_eq.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf_eq instead.")]
Definition charf_eq := pcharf_eq.
Definition bin_lt_pcharf_0 := bin_lt_pcharf_0.
#[deprecated(since="mathcomp 2.4.0", note="Use bin_lt_pcharf_0 instead.")]
Definition bin_lt_charf_0 := bin_lt_pcharf_0.
Definition pFrobenius_autE := pFrobenius_autE.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autE instead.")]
Definition Frobenius_autE := pFrobenius_autE.
Definition pFrobenius_aut0 := pFrobenius_aut0.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut0 instead.")]
Definition Frobenius_aut0 := pFrobenius_aut0.
Definition pFrobenius_aut1 := pFrobenius_aut1.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut1 instead.")]
Definition Frobenius_aut1 := pFrobenius_aut1.
Definition pFrobenius_autD_comm := pFrobenius_autD_comm.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autD_comm instead.")]
Definition Frobenius_autD_comm := pFrobenius_autD_comm.
Definition pFrobenius_autMn := pFrobenius_autMn.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autMn instead.")]
Definition Frobenius_autMn := pFrobenius_autMn.
Definition pFrobenius_aut_nat := pFrobenius_aut_nat.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut_nat instead.")]
Definition Frobenius_aut_nat := pFrobenius_aut_nat.
Definition pFrobenius_autM_comm := pFrobenius_autM_comm.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autM_comm instead.")]
Definition Frobenius_autM_comm := pFrobenius_autM_comm.
Definition pFrobenius_autX := pFrobenius_autX.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autX instead.")]
Definition Frobenius_autX := pFrobenius_autX.
Definition pFrobenius_autN := pFrobenius_autN.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autN instead.")]
Definition Frobenius_autN := pFrobenius_autN.
Definition pFrobenius_autB_comm := pFrobenius_autB_comm.
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_autB_comm instead.")]
Definition Frobenius_autB_comm := pFrobenius_autB_comm.
Definition exprNn_pchar := exprNn_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use exprNn_pchar instead.")]
Definition exprNn_char := exprNn_pchar.
Definition addrr_pchar2 := addrr_pchar2.
#[deprecated(since="mathcomp 2.4.0", note="Use addrr_pchar2 instead.")]
Definition addrr_char2 := addrr_pchar2.
Definition oppr_pchar2 := oppr_pchar2.
#[deprecated(since="mathcomp 2.4.0", note="Use oppr_pchar2 instead.")]
Definition oppr_char2 := oppr_pchar2.
Definition addrK_pchar2 := addrK_pchar2.
#[deprecated(since="mathcomp 2.4.0", note="Use addrK_pchar2 instead.")]
Definition addrK_char2 := addrK_pchar2.
Definition addKr_pchar2 := addKr_pchar2.
#[deprecated(since="mathcomp 2.4.0", note="Use addKr_pchar2 instead.")]
Definition addKr_char2 := addKr_pchar2.
Definition iter_mulr := iter_mulr.
Definition iter_mulr_1 := iter_mulr_1.
Definition prodr_const := prodr_const.
Definition prodr_const_nat := prodr_const_nat.
Definition mulrC := @mulrC.
Definition mulrCA := mulrCA.
Definition mulrAC := mulrAC.
Definition mulrACA := mulrACA.
Definition exprMn := exprMn.
Definition prodrXl := prodrXl.
Definition prodrXr := prodrXr.
Definition prodrN := prodrN.
Definition prodrMn_const := prodrMn_const.
Definition prodrM_comm := prodrM_comm.
Definition prodrMl_comm := prodrMl_comm.
Definition prodrMr_comm := prodrMr_comm.
Definition prodrMl := prodrMl.
Definition prodrMr := prodrMr.
Definition prodrMn := prodrMn.
Definition rev_prodr := rev_prodr.
Definition natr_prod := natr_prod.
Definition prodr_undup_exp_count := prodr_undup_exp_count.
Definition exprDn := exprDn.
Definition exprBn := exprBn.
Definition subrXX := subrXX.
Definition sqrrD := sqrrD.
Definition sqrrB := sqrrB.
Definition subr_sqr := subr_sqr.
Definition subr_sqrDB := subr_sqrDB.
Definition exprDn_pchar := exprDn_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use exprDn_pchar instead.")]
Definition exprDn_char := exprDn_pchar.
Definition mulrV := mulrV.
Definition divrr := divrr.
Definition mulVr := mulVr.
Definition invr_out := invr_out.
Definition unitrP {R x} := @unitrP R x.
Definition mulKr := mulKr.
Definition mulVKr := mulVKr.
Definition mulrK := mulrK.
Definition mulrVK := mulrVK.
Definition divrK := divrK.
Definition mulrI := mulrI.
Definition mulIr := mulIr.
Definition divrI := divrI.
Definition divIr := divIr.
Definition telescope_prodr := telescope_prodr.
Definition telescope_prodr_eq := @telescope_prodr_eq.
Arguments telescope_prodr_eq {R n m} f u.
Definition commrV := commrV.
Definition unitrE := unitrE.
Definition invrK := @invrK.
Arguments invrK {R}.
Definition invr_inj := @invr_inj.
Arguments invr_inj {R} [x1 x2].
Definition unitrV := unitrV.
Definition unitr1 := unitr1.
Definition invr1 := invr1.
Definition divr1 := divr1.
Definition div1r := div1r.
Definition natr_div := natr_div.
Definition unitr0 := unitr0.
Definition invr0 := invr0.
Definition unitrN1 := unitrN1.
Definition unitrN := unitrN.
Definition invrN1 := invrN1.
Definition invrN := invrN.
Definition divrNN := divrNN.
Definition divrN := divrN.
Definition invr_sign := invr_sign.
Definition unitrMl := unitrMl.
Definition unitrMr := unitrMr.
Definition invrM := invrM.
Definition unitr_prod := unitr_prod.
Definition unitr_prod_in := unitr_prod_in.
Definition invr_eq0 := invr_eq0.
Definition invr_eq1 := invr_eq1.
Definition invr_neq0 := invr_neq0.
Definition rev_unitrP := rev_unitrP.
Definition rev_prodrV := rev_prodrV.
Definition unitrM_comm := unitrM_comm.
Definition unitrX := unitrX.
Definition unitrX_pos := unitrX_pos.
Definition exprVn := exprVn.
Definition exprB := exprB.
Definition invr_signM := invr_signM.
Definition divr_signM := divr_signM.
Definition rpred0D := @rpred0D.
Definition rpred0 := rpred0.
Definition rpredD := rpredD.
Definition rpredNr := @rpredNr.
Definition rpred_sum := rpred_sum.
Definition rpredMn := rpredMn.
Definition rpredN := rpredN.
Definition rpredB := rpredB.
Definition rpredBC := rpredBC.
Definition rpredMNn := rpredMNn.
Definition rpredDr := rpredDr.
Definition rpredDl := rpredDl.
Definition rpredBr := rpredBr.
Definition rpredBl := rpredBl.
Definition zmodClosedP := zmodClosedP.
Definition rpredMsign := rpredMsign.
Definition rpred1M := @rpred1M.
Definition rpred1 := @rpred1.
Definition rpredM := @rpredM.
Definition rpred_prod := rpred_prod.
Definition rpredX := rpredX.
Definition rpred_nat := rpred_nat.
Definition rpredN1 := rpredN1.
Definition rpred_sign := rpred_sign.
Definition semiringClosedP := semiringClosedP.
Definition subringClosedP := subringClosedP.
Definition rpredZsign := rpredZsign.
Definition rpredZnat := rpredZnat.
Definition submodClosedP := submodClosedP.
Definition subalgClosedP := subalgClosedP.
Definition rpredZ := @rpredZ.
Definition rpredVr := @rpredVr.
Definition rpredV := rpredV.
Definition rpred_div := rpred_div.
Definition rpredXN := rpredXN.
Definition rpredZeq := rpredZeq.
Definition pchar_lalg := pchar_lalg.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_lalg instead.")]
Definition char_lalg := pchar_lalg.
Definition rpredMr := rpredMr.
Definition rpredMl := rpredMl.
Definition rpred_divr := rpred_divr.
Definition rpred_divl := rpred_divl.
Definition divringClosedP := divringClosedP.
Definition eq_eval := eq_eval.
Definition eval_tsubst := eval_tsubst.
Definition eq_holds := eq_holds.
Definition holds_fsubst := holds_fsubst.
Definition unitrM := unitrM.
Definition unitr_prodP := unitr_prodP.
Definition prodrV := prodrV.
Definition unitrPr {R x} := @unitrPr R x.
Definition expr_div_n := expr_div_n.
Definition mulr1_eq := mulr1_eq.
Definition divr1_eq := divr1_eq.
Definition divKr := divKr.
Definition mulf_eq0 := mulf_eq0.
Definition prodf_eq0 := prodf_eq0.
Definition prodf_seq_eq0 := prodf_seq_eq0.
Definition mulf_neq0 := mulf_neq0.
Definition prodf_neq0 := prodf_neq0.
Definition prodf_seq_neq0 := prodf_seq_neq0.
Definition expf_eq0 := expf_eq0.
Definition sqrf_eq0 := sqrf_eq0.
Definition expf_neq0 := expf_neq0.
Definition natf_neq0_pchar := natf_neq0_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use natf_neq0_pchar instead.")]
Definition natf_neq0 := natf_neq0_pchar.
Definition natf0_pchar := natf0_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use natf0_pchar instead.")]
Definition natf0_char := natf0_pchar.
Definition pcharf'_nat := pcharf'_nat.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf'_nat instead.")]
Definition charf'_nat := pcharf'_nat.
Definition pcharf0P := pcharf0P.
#[deprecated(since="mathcomp 2.4.0", note="Use pcharf0P instead.")]
Definition charf0P := pcharf0P.
Definition eqf_sqr := eqf_sqr.
Definition mulfI := mulfI.
Definition mulIf := mulIf.
Definition divfI := divfI.
Definition divIf := divIf.
Definition sqrf_eq1 := sqrf_eq1.
Definition expfS_eq1 := expfS_eq1.
Definition fieldP := @fieldP.
Definition unitfE := unitfE.
Definition mulVf := mulVf.
Definition mulfV := mulfV.
Definition divff := divff.
Definition mulKf := mulKf.
Definition mulVKf := mulVKf.
Definition mulfK := mulfK.
Definition mulfVK := mulfVK.
Definition divfK := divfK.
Definition divKf := divKf.
Definition invfM := invfM.
Definition invf_div := invf_div.
Definition expfB_cond := expfB_cond.
Definition expfB := expfB.
Definition prodfV := prodfV.
Definition prodf_div := prodf_div.
Definition telescope_prodf := telescope_prodf.
Definition telescope_prodf_eq := @telescope_prodf_eq.
Arguments telescope_prodf_eq {F n m} f u.
Definition addf_div := addf_div.
Definition mulf_div := mulf_div.
Definition eqr_div := eqr_div.
Definition eqr_sum_div := eqr_sum_div.
Definition pchar0_natf_div := pchar0_natf_div.
#[deprecated(since="mathcomp 2.4.0", note="Use pchar0_natf_div instead.")]
Definition char0_natf_div := pchar0_natf_div.
Definition fpredMr := fpredMr.
Definition fpredMl := fpredMl.
Definition fpred_divr := fpred_divr.
Definition fpred_divl := fpred_divl.
Definition satP {F e f} := @satP F e f.
Definition eq_sat := eq_sat.
Definition solP {F n f} := @solP F n f.
Definition eq_sol := eq_sol.
Definition size_sol := size_sol.
Definition solve_monicpoly := @solve_monicpoly.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `nmod_morphism` instead")]
Definition semi_additive := semi_additive.
Definition nmod_morphism := nmod_morphism.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `zmod_morphism` instead")]
Definition additive := additive.
Definition zmod_morphism := zmod_morphism.
Definition raddf0 := raddf0.
Definition raddf_eq0 := raddf_eq0.
Definition raddf_inj := raddf_inj.
Definition raddfN := raddfN.
Definition raddfD := raddfD.
Definition raddfB := raddfB.
Definition raddf_sum := raddf_sum.
Definition raddfMn := raddfMn.
Definition raddfMNn := raddfMNn.
Definition raddfMnat := raddfMnat.
Definition raddfMsign := raddfMsign.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `can2_nmod_morphism` instead")]
Definition can2_semi_additive := can2_semi_additive.
Definition can2_nmod_morphism := can2_nmod_morphism.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `can2_zmod_morphism` instead")]
Definition can2_additive := can2_additive.
Definition can2_zmod_morphism := can2_zmod_morphism.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `monoid_morphism` instead")]
Definition multiplicative := multiplicative.
Definition monoid_morphism := monoid_morphism.
Definition rmorph0 := rmorph0.
Definition rmorphN := rmorphN.
Definition rmorphD := rmorphD.
Definition rmorphB := rmorphB.
Definition rmorph_sum := rmorph_sum.
Definition rmorphMn := rmorphMn.
Definition rmorphMNn := rmorphMNn.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `rmorphism_monoidP` instead")]
Definition rmorphismMP := rmorphismMP.
Definition rmorphism_monoidP := rmorphism_monoidP.
Definition rmorph1 := rmorph1.
Definition rmorph_eq1 := rmorph_eq1.
Definition rmorphM := rmorphM.
Definition rmorphMsign := rmorphMsign.
Definition rmorph_nat := rmorph_nat.
Definition rmorph_eq_nat := rmorph_eq_nat.
Definition rmorph_prod := rmorph_prod.
Definition rmorphXn := rmorphXn.
Definition rmorphN1 := rmorphN1.
Definition rmorph_sign := rmorph_sign.
Definition rmorph_pchar := rmorph_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use rmorph_pchar instead.")]
Definition rmorph_char := rmorph_pchar.
#[warning="-deprecated-since-mathcomp-2.5.0",
deprecated(since="mathcomp 2.5.0", note="use `can2_monoid_morphism` instead")]
Definition can2_rmorphism := can2_rmorphism.
Definition can2_monoid_morphism := can2_monoid_morphism.
Definition rmorph_comm := rmorph_comm.
Definition rmorph_unit := rmorph_unit.
Definition rmorphV := rmorphV.
Definition rmorph_div := rmorph_div.
Definition fmorph_eq0 := fmorph_eq0.
Definition fmorph_inj := @fmorph_inj.
Arguments fmorph_inj {F R} f [x1 x2].
Definition fmorph_eq := fmorph_eq.
Definition fmorph_eq1 := fmorph_eq1.
Definition fmorph_pchar := fmorph_pchar.
#[deprecated(since="mathcomp 2.4.0", note="Use fmorph_pchar instead.")]
Definition fmorph_char := fmorph_pchar.
Definition fmorph_unit := fmorph_unit.
Definition fmorphV := fmorphV.
Definition fmorph_div := fmorph_div.
Definition scalerA := scalerA.
Definition scale1r := @scale1r.
Definition scalerDr := @scalerDr.
Definition scalerDl := @scalerDl.
Definition scaler0 := scaler0.
Definition scale0r := @scale0r.
Definition scaleNr := scaleNr.
Definition scaleN1r := scaleN1r.
Definition scalerN := scalerN.
Definition scalerBl := scalerBl.
Definition scalerBr := scalerBr.
Definition scaler_nat := scaler_nat.
Definition scalerMnl := scalerMnl.
Definition scalerMnr := scalerMnr.
Definition scaler_suml := scaler_suml.
Definition scaler_sumr := scaler_sumr.
Definition scaler_eq0 := scaler_eq0.
Definition scalerK := scalerK.
Definition scalerKV := scalerKV.
Definition scalerI := scalerI.
Definition scalerAl := @scalerAl.
Definition mulr_algl := mulr_algl.
Definition scaler_sign := scaler_sign.
Definition signrZK := signrZK.
Definition scalerCA := scalerCA.
Definition scalerAr := @scalerAr.
Definition mulr_algr := mulr_algr.
Definition comm_alg := comm_alg.
Definition exprZn := exprZn.
Definition scaler_prodl := scaler_prodl.
Definition scaler_prodr := scaler_prodr.
Definition scaler_prod := scaler_prod.
Definition scaler_injl := scaler_injl.
Definition scaler_unit := scaler_unit.
Definition invrZ := invrZ.
Definition raddfZnat := raddfZnat.
Definition raddfZsign := raddfZsign.
Definition in_algE := in_algE.
Definition scalable_for := scalable_for.
Definition semilinear_for := semilinear_for.
Definition linear_for := linear_for.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `nmod_morphism_semilinear` instead")]
Definition additive_semilinear := additive_semilinear.
Definition nmod_morphism_semilinear := nmod_morphism_semilinear.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `zmod_morphism_linear` instead")]
Definition additive_linear := additive_linear.
Definition zmod_morphism_linear := zmod_morphism_linear.
Definition scalable_semilinear := scalable_semilinear.
Definition scalable_linear := scalable_linear.
Definition linear0 := linear0.
Definition linearN := linearN.
Definition linearD := linearD.
Definition linearB := linearB.
Definition linear_sum := linear_sum.
Definition linearMn := linearMn.
Definition linearMNn := linearMNn.
Definition semilinearP := semilinearP.
Definition linearP := linearP.
Definition linearZ_LR := linearZ_LR.
Definition linearZ := linearZ.
Definition semilinearPZ := semilinearPZ.
Definition linearPZ := linearPZ.
Definition linearZZ := linearZZ.
Definition semiscalarP := semiscalarP.
Definition scalarP := scalarP.
Definition scalarZ := scalarZ.
Definition can2_scalable := can2_scalable.
Definition can2_linear := can2_linear.
Definition can2_semilinear := can2_semilinear.
Definition rmorph_alg := rmorph_alg.
Definition imaginary_exists := imaginary_exists.
Definition raddf := (raddf0, raddfN, raddfD, raddfMn).
Definition rmorphE :=
(rmorphD, rmorph0, rmorphB, rmorphN, rmorphMNn, rmorphMn, rmorph1, rmorphXn).
Definition linearE :=
(linearD, linear0, linearB, linearMNn, linearMn, linearZ).
Notation null_fun V := (null_fun V) (only parsing).
Notation in_alg A := (in_alg A) (only parsing).
End Theory.
Module AllExports. HB.reexport. End AllExports.
End GRing.
Export AllExports.
Export Scale.Exports.
Export ClosedExports.
#[deprecated(since="mathcomp 2.4.0",
note="Try pzSemiRingType (the potentially-zero counterpart) first, or use nzSemiRingType instead.")]
Notation semiRingType := (nzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try pzRingType (the potentially-zero counterpart) first, or use nzRingType instead.")]
Notation ringType := (nzRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try comPzSemiRingType (the potentially-zero counterpart) first, or use comNzSemiRingType instead.")]
Notation comSemiRingType := (comNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try comPzRingType (the potentially-zero counterpart) first, or use comNzRingType instead.")]
Notation comRingType := (comNzRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try subPzSemiRingType (the potentially-zero counterpart) first, or use subNzSemiRingType instead.")]
Notation subSemiRingType := (subNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try subComPzSemiRingType (the potentially-zero counterpart) first, or use subComNzSemiRingType instead.")]
Notation subComSemiRingType := (subComNzSemiRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try subPzRingType (the potentially-zero counterpart) first, or use subNzRingType instead.")]
Notation subRingType := (subNzRingType) (only parsing).
#[deprecated(since="mathcomp 2.4.0",
note="Try subComPzRingType (the potentially-zero counterpart) first, or use subComNzRingType instead.")]
Notation subComNzRingType := (subComNzRingType) (only parsing).
Notation addrClosed := addrClosed.
Notation opprClosed := opprClosed.
Variant Ione := IOne : Ione.
Inductive Inatmul :=
| INatmul : Ione -> nat -> Inatmul
| IOpp : Inatmul -> Inatmul.
Variant Idummy_placeholder :=.
Definition parse (x : Number.int) : Inatmul :=
match x with
| Number.IntDecimal (Decimal.Pos u) => INatmul IOne (Nat.of_uint u)
| Number.IntDecimal (Decimal.Neg u) => IOpp (INatmul IOne (Nat.of_uint u))
| Number.IntHexadecimal (Hexadecimal.Pos u) =>
INatmul IOne (Nat.of_hex_uint u)
| Number.IntHexadecimal (Hexadecimal.Neg u) =>
IOpp (INatmul IOne (Nat.of_hex_uint u))
end.
Definition print (x : Inatmul) : option Number.int :=
match x with
| INatmul IOne n =>
Some (Number.IntDecimal (Decimal.Pos (Nat.to_uint n)))
| IOpp (INatmul IOne n) =>
Some (Number.IntDecimal (Decimal.Neg (Nat.to_uint n)))
| _ => None
end.
Arguments GRing.one {_}.
Set Warnings "-via-type-remapping,-via-type-mismatch".
Number Notation Idummy_placeholder parse print (via Inatmul
mapping [[natmul] => INatmul, [opp] => IOpp, [one] => IOne])
: ring_scope.
Set Warnings "via-type-remapping,via-type-mismatch".
Arguments GRing.one : clear implicits.
Notation "0" := (@zero _) : ring_scope.
Notation "-%R" := (@opp _) : ring_scope.
Notation "- x" := (opp x) : ring_scope.
Notation "+%R" := (@add _) : function_scope.
Notation "x + y" := (add x y) : ring_scope.
Notation "x - y" := (add x (- y)) : ring_scope.
Arguments natmul : simpl never.
Notation "x *+ n" := (natmul x n) : ring_scope.
Notation "x *- n" := (opp (x *+ n)) : ring_scope.
Notation "s `_ i" := (seq.nth 0%R s%R i) : ring_scope.
Notation support := 0.-support.
Notation "1" := (@one _) : ring_scope.
Notation "- 1" := (opp 1) : ring_scope.
Notation "n %:R" := (natmul 1 n) : ring_scope.
Arguments GRing.pchar R%_type.
Notation "[ 'pchar' R ]" := (GRing.pchar R) : ring_scope.
#[deprecated(since="mathcomp 2.4.0", note="Use [pchar R] instead.")]
Notation "[ 'char' R ]" := (GRing.pchar R) : ring_scope.
Notation has_pchar0 R := (GRing.pchar R =i pred0).
#[deprecated(since="mathcomp 2.4.0", note="Use has_pchar0 instead.")]
Notation has_char0 R := (GRing.pchar R =i pred0).
Notation pFrobenius_aut chRp := (pFrobenius_aut chRp).
#[deprecated(since="mathcomp 2.4.0", note="Use pFrobenius_aut instead.")]
Notation Frobenius_aut chRp := (pFrobenius_aut chRp).
Notation "*%R" := (@mul _) : function_scope.
Notation "x * y" := (mul x y) : ring_scope.
Arguments exp : simpl never.
Notation "x ^+ n" := (exp x n) : ring_scope.
Notation "x ^-1" := (inv x) : ring_scope.
Notation "x ^- n" := (inv (x ^+ n)) : ring_scope.
Notation "x / y" := (mul x y^-1) : ring_scope.
Notation "*:%R" := (@scale _ _) : function_scope.
Notation "a *: m" := (scale a m) : ring_scope.
Notation "k %:A" := (scale k 1) : ring_scope.
Notation "\0" := (null_fun _) : ring_scope.
Notation "f \+ g" := (add_fun f g) : ring_scope.
Notation "f \- g" := (sub_fun f g) : ring_scope.
Notation "\- f" := (opp_fun f) : ring_scope.
Notation "a \*: f" := (scale_fun a f) : ring_scope.
Notation "x \*o f" := (mull_fun x f) : ring_scope.
Notation "x \o* f" := (mulr_fun x f) : ring_scope.
Notation "f \* g" := (mul_fun f g) : ring_scope.
Arguments mull_fun {_ _} a f _ /.
Arguments mulr_fun {_ _} a f _ /.
Arguments scale_fun {_ _ _} a f _ /.
Arguments mul_fun {_ _} f g _ /.
Notation "\sum_ ( i <- r | P ) F" :=
(\big[+%R/0%R]_(i <- r | P%B) F%R) : ring_scope.
Notation "\sum_ ( i <- r ) F" :=
(\big[+%R/0%R]_(i <- r) F%R) : ring_scope.
Notation "\sum_ ( m <= i < n | P ) F" :=
(\big[+%R/0%R]_(m <= i < n | P%B) F%R) : ring_scope.
Notation "\sum_ ( m <= i < n ) F" :=
(\big[+%R/0%R]_(m <= i < n) F%R) : ring_scope.
Notation "\sum_ ( i | P ) F" :=
(\big[+%R/0%R]_(i | P%B) F%R) : ring_scope.
Notation "\sum_ i F" :=
(\big[+%R/0%R]_i F%R) : ring_scope.
Notation "\sum_ ( i : t | P ) F" :=
(\big[+%R/0%R]_(i : t | P%B) F%R) (only parsing) : ring_scope.
Notation "\sum_ ( i : t ) F" :=
(\big[+%R/0%R]_(i : t) F%R) (only parsing) : ring_scope.
Notation "\sum_ ( i < n | P ) F" :=
(\big[+%R/0%R]_(i < n | P%B) F%R) : ring_scope.
Notation "\sum_ ( i < n ) F" :=
(\big[+%R/0%R]_(i < n) F%R) : ring_scope.
Notation "\sum_ ( i 'in' A | P ) F" :=
(\big[+%R/0%R]_(i in A | P%B) F%R) : ring_scope.
Notation "\sum_ ( i 'in' A ) F" :=
(\big[+%R/0%R]_(i in A) F%R) : ring_scope.
Notation "\prod_ ( i <- r | P ) F" :=
(\big[*%R/1%R]_(i <- r | P%B) F%R) : ring_scope.
Notation "\prod_ ( i <- r ) F" :=
(\big[*%R/1%R]_(i <- r) F%R) : ring_scope.
Notation "\prod_ ( m <= i < n | P ) F" :=
(\big[*%R/1%R]_(m <= i < n | P%B) F%R) : ring_scope.
Notation "\prod_ ( m <= i < n ) F" :=
(\big[*%R/1%R]_(m <= i < n) F%R) : ring_scope.
Notation "\prod_ ( i | P ) F" :=
(\big[*%R/1%R]_(i | P%B) F%R) : ring_scope.
Notation "\prod_ i F" :=
(\big[*%R/1%R]_i F%R) : ring_scope.
Notation "\prod_ ( i : t | P ) F" :=
(\big[*%R/1%R]_(i : t | P%B) F%R) (only parsing) : ring_scope.
Notation "\prod_ ( i : t ) F" :=
(\big[*%R/1%R]_(i : t) F%R) (only parsing) : ring_scope.
Notation "\prod_ ( i < n | P ) F" :=
(\big[*%R/1%R]_(i < n | P%B) F%R) : ring_scope.
Notation "\prod_ ( i < n ) F" :=
(\big[*%R/1%R]_(i < n) F%R) : ring_scope.
Notation "\prod_ ( i 'in' A | P ) F" :=
(\big[*%R/1%R]_(i in A | P%B) F%R) : ring_scope.
Notation "\prod_ ( i 'in' A ) F" :=
(\big[*%R/1%R]_(i in A) F%R) : ring_scope.
Notation "R ^c" := (converse R) : type_scope.
Notation "R ^o" := (regular R) : type_scope.
Bind Scope term_scope with term.
Bind Scope term_scope with formula.
Notation "''X_' i" := (Var _ i) : term_scope.
Notation "n %:R" := (NatConst _ n) : term_scope.
Notation "0" := 0%:R%T : term_scope.
Notation "1" := 1%:R%T : term_scope.
Notation "x %:T" := (Const x) : term_scope.
Infix "+" := Add : term_scope.
Notation "- t" := (Opp t) : term_scope.
Notation "t - u" := (Add t (- u)) : term_scope.
Infix "*" := Mul : term_scope.
Infix "*+" := NatMul : term_scope.
Notation "t ^-1" := (Inv t) : term_scope.
Notation "t / u" := (Mul t u^-1) : term_scope.
Infix "^+" := Exp : term_scope.
Infix "==" := Equal : term_scope.
Notation "x != y" := (GRing.Not (x == y)) : term_scope.
Infix "/\" := And : term_scope.
Infix "\/" := Or : term_scope.
Infix "==>" := Implies : term_scope.
Notation "~ f" := (Not f) : term_scope.
Notation "''exists' ''X_' i , f" := (Exists i f) : term_scope.
Notation "''forall' ''X_' i , f" := (Forall i f) : term_scope.
(* Lifting Structure from the codomain of finfuns. *)
Section Sum.
Variables (aT : finType) (rT : nmodType).
Variables (I : Type) (r : seq I) (P : pred I) (F : I -> {ffun aT -> rT}).
Lemma sum_ffunE x : (\sum_(i <- r | P i) F i) x = \sum_(i <- r | P i) F i x.
Proof. by elim/big_rec2: _ => // [|i _ y _ <-]; rewrite !ffunE. Qed.
Lemma sum_ffun :
\sum_(i <- r | P i) F i = [ffun x => \sum_(i <- r | P i) F i x].
Proof. by apply/ffunP=> i; rewrite sum_ffunE ffunE. Qed.
End Sum.
Section FinFunSemiRing.
(* As rings require 1 != 0 in order to lift a ring structure over finfuns *)
(* we need evidence that the domain is non-empty. *)
Variable (aT : finType) (R : pzSemiRingType).
Definition ffun_one : {ffun aT -> R} := [ffun => 1].
Definition ffun_mul (f g : {ffun aT -> R}) := [ffun x => f x * g x].
Fact ffun_mulA : associative ffun_mul.
Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrA. Qed.
Fact ffun_mul_1l : left_id ffun_one ffun_mul.
Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul1r. Qed.
Fact ffun_mul_1r : right_id ffun_one ffun_mul.
Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr1. Qed.
Fact ffun_mul_addl : left_distributive ffun_mul (@ffun_add _ _).
Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDl. Qed.
Fact ffun_mul_addr : right_distributive ffun_mul (@ffun_add _ _).
Proof. by move=> f1 f2 f3; apply/ffunP=> i; rewrite !ffunE mulrDr. Qed.
Fact ffun_mul_0l : left_zero (@ffun_zero _ _) ffun_mul.
Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mul0r. Qed.
Fact ffun_mul_0r : right_zero (@ffun_zero _ _) ffun_mul.
Proof. by move=> f; apply/ffunP=> i; rewrite !ffunE mulr0. Qed.
#[export]
HB.instance Definition _ := Nmodule_isPzSemiRing.Build {ffun aT -> R}
ffun_mulA ffun_mul_1l ffun_mul_1r ffun_mul_addl ffun_mul_addr
ffun_mul_0l ffun_mul_0r.
Definition ffun_semiring : pzSemiRingType := {ffun aT -> R}.
End FinFunSemiRing.
Section FinFunSemiRing.
Variable (aT : finType) (R : nzSemiRingType) (a : aT).
Fact ffun1_nonzero : ffun_one aT R != 0.
Proof. by apply/eqP => /ffunP/(_ a)/eqP; rewrite !ffunE oner_eq0. Qed.
(* TODO_HB uncomment once ffun_ring below is fixed
#[export]
HB.instance Definition _ := PzSemiRing_isNonZero.Build {ffun aT -> R}
ffun1_nonzero.
*)
End FinFunSemiRing.
HB.instance Definition _ (aT : finType) (R : pzRingType) :=
Zmodule_isPzRing.Build {ffun aT -> R}
(@ffun_mulA _ _) (@ffun_mul_1l _ _) (@ffun_mul_1r _ _)
(@ffun_mul_addl _ _) (@ffun_mul_addr _ _).
(* As nzRings require 1 != 0 in order to lift a ring structure over finfuns *)
(* we need evidence that the domain is non-empty. *)
Section FinFunRing.
Variable (aT : finType) (R : nzRingType) (a : aT).
(* TODO_HB: doesn't work in combination with ffun_semiring above *)
HB.instance Definition _ :=
PzSemiRing_isNonZero.Build {ffun aT -> R} (@ffun1_nonzero _ _ a).
Definition ffun_ring : nzRingType := {ffun aT -> R}.
End FinFunRing.
(* TODO_HB do FinFunComSemiRing once above is fixed *)
Section FinFunComRing.
Variable (aT : finType) (R : comPzRingType) (a : aT).
Fact ffun_mulC : commutative (@ffun_mul aT R).
Proof. by move=> f1 f2; apply/ffunP=> i; rewrite !ffunE mulrC. Qed.
(* TODO_HB
#[export]
HB.instance Definition _ :=
Ring_hasCommutativeMul.Build (ffun_ring _ a) ffun_mulC.
*)
End FinFunComRing.
Section FinFunLSemiMod.
Variable (R : pzSemiRingType) (aT : finType) (rT : lSemiModType R).
Implicit Types f g : {ffun aT -> rT}.
Definition ffun_scale k f := [ffun a => k *: f a].
Fact ffun_scaleA k1 k2 f :
ffun_scale k1 (ffun_scale k2 f) = ffun_scale (k1 * k2) f.
Proof. by apply/ffunP=> a; rewrite !ffunE scalerA. Qed.
Fact ffun_scale0r f : ffun_scale 0 f = 0.
Proof. by apply/ffunP=> a; rewrite !ffunE scale0r. Qed.
Fact ffun_scale1 : left_id 1 ffun_scale.
Proof. by move=> f; apply/ffunP=> a; rewrite !ffunE scale1r. Qed.
Fact ffun_scale_addr k : {morph (ffun_scale k) : x y / x + y}.
Proof. by move=> f g; apply/ffunP=> a; rewrite !ffunE scalerDr. Qed.
Fact ffun_scale_addl u : {morph (ffun_scale)^~ u : k1 k2 / k1 + k2}.
Proof. by move=> k1 k2; apply/ffunP=> a; rewrite !ffunE scalerDl. Qed.
#[export]
HB.instance Definition _ := Nmodule_isLSemiModule.Build R {ffun aT -> rT}
ffun_scaleA ffun_scale0r ffun_scale1 ffun_scale_addr ffun_scale_addl.
End FinFunLSemiMod.
#[export]
HB.instance Definition _ (R : pzRingType) (aT : finType) (rT : lmodType R) :=
LSemiModule.on {ffun aT -> rT}.
(* External direct product. *)
Section PairSemiRing.
Variables R1 R2 : pzSemiRingType.
Definition mul_pair (x y : R1 * R2) := (x.1 * y.1, x.2 * y.2).
Fact pair_mulA : associative mul_pair.
Proof. by move=> x y z; congr (_, _); apply: mulrA. Qed.
Fact pair_mul1l : left_id (1, 1) mul_pair.
Proof. by case=> x1 x2; congr (_, _); apply: mul1r. Qed.
Fact pair_mul1r : right_id (1, 1) mul_pair.
Proof. by case=> x1 x2; congr (_, _); apply: mulr1. Qed.
Fact pair_mulDl : left_distributive mul_pair +%R.
Proof. by move=> x y z; congr (_, _); apply: mulrDl. Qed.
Fact pair_mulDr : right_distributive mul_pair +%R.
Proof. by move=> x y z; congr (_, _); apply: mulrDr. Qed.
Fact pair_mul0r : left_zero 0 mul_pair.
Proof. by move=> x; congr (_, _); apply: mul0r. Qed.
Fact pair_mulr0 : right_zero 0 mul_pair.
Proof. by move=> x; congr (_, _); apply: mulr0. Qed.
#[export]
HB.instance Definition _ := Nmodule_isPzSemiRing.Build (R1 * R2)%type
pair_mulA pair_mul1l pair_mul1r pair_mulDl pair_mulDr pair_mul0r pair_mulr0.
Fact fst_is_monoid_morphism : monoid_morphism fst. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R1 fst
fst_is_monoid_morphism.
Fact snd_is_monoid_morphism : monoid_morphism snd. Proof. by []. Qed.
#[export]
HB.instance Definition _ := isMonoidMorphism.Build (R1 * R2)%type R2 snd
snd_is_monoid_morphism.
End PairSemiRing.
Section PairSemiRing.
Variables R1 R2 : nzSemiRingType.
Fact pair_one_neq0 : 1 != 0 :> R1 * R2.
Proof. by rewrite xpair_eqE oner_eq0. Qed.
#[export]
HB.instance Definition _ := PzSemiRing_isNonZero.Build (R1 * R2)%type
pair_one_neq0.
End PairSemiRing.
Section PairComSemiRing.
Variables R1 R2 : comPzSemiRingType.
Fact pair_mulC : commutative (@mul_pair R1 R2).
Proof. by move=> x y; congr (_, _); apply: mulrC. Qed.
#[export]
HB.instance Definition _ := PzSemiRing_hasCommutativeMul.Build (R1 * R2)%type
pair_mulC.
End PairComSemiRing.
(* TODO: HB.saturate *)
#[export]
HB.instance Definition _ (R1 R2 : comNzSemiRingType) :=
NzSemiRing.on (R1 * R2)%type.
#[export]
HB.instance Definition _ (R1 R2 : pzRingType) := PzSemiRing.on (R1 * R2)%type.
#[export]
HB.instance Definition _ (R1 R2 : nzRingType) := NzSemiRing.on (R1 * R2)%type.
#[export]
HB.instance Definition _ (R1 R2 : comPzRingType) := PzRing.on (R1 * R2)%type.
#[export]
HB.instance Definition _ (R1 R2 : comNzRingType) := NzRing.on (R1 * R2)%type.
(* /TODO *)
Section PairLSemiMod.
Variables (R : pzSemiRingType) (V1 V2 : lSemiModType R).
Definition scale_pair a (v : V1 * V2) : V1 * V2 := (a *: v.1, a *: v.2).
Fact pair_scaleA a b u : scale_pair a (scale_pair b u) = scale_pair (a * b) u.
Proof. by congr (_, _); apply: scalerA. Qed.
Fact pair_scale0 u : scale_pair 0 u = 0.
Proof. by case: u => u1 u2; congr (_, _); apply: scale0r. Qed.
Fact pair_scale1 u : scale_pair 1 u = u.
Proof. by case: u => u1 u2; congr (_, _); apply: scale1r. Qed.
Fact pair_scaleDr : right_distributive scale_pair +%R.
Proof. by move=> a u v; congr (_, _); apply: scalerDr. Qed.
Fact pair_scaleDl u : {morph scale_pair^~ u: a b / a + b}.
Proof. by move=> a b; congr (_, _); apply: scalerDl. Qed.
#[export]
HB.instance Definition _ := Nmodule_isLSemiModule.Build R (V1 * V2)%type
pair_scaleA pair_scale0 pair_scale1 pair_scaleDr pair_scaleDl.
Fact fst_is_scalable : scalable fst. Proof. by []. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R (V1 * V2)%type V1 *:%R fst fst_is_scalable.
Fact snd_is_scalable : scalable snd. Proof. by []. Qed.
#[export]
HB.instance Definition _ :=
isScalable.Build R (V1 * V2)%type V2 *:%R snd snd_is_scalable.
End PairLSemiMod.
Section PairLSemiAlg.
Variables (R : pzSemiRingType) (A1 A2 : lSemiAlgType R).
Fact pair_scaleAl a (u v : A1 * A2) : a *: (u * v) = (a *: u) * v.
Proof. by congr (_, _); apply: scalerAl. Qed.
#[export]
HB.instance Definition _ := LSemiModule_isLSemiAlgebra.Build R (A1 * A2)%type
pair_scaleAl.
(* TODO: HB.saturate *)
#[export]
HB.instance Definition _ := RMorphism.on (@fst A1 A2).
#[export]
HB.instance Definition _ := RMorphism.on (@snd A1 A2).
(* /TODO *)
End PairLSemiAlg.
Section PairSemiAlg.
Variables (R : pzSemiRingType) (A1 A2 : semiAlgType R).
Fact pair_scaleAr a (u v : A1 * A2) : a *: (u * v) = u * (a *: v).
Proof. by congr (_, _); apply: scalerAr. Qed.
#[export]
HB.instance Definition _ := LSemiAlgebra_isSemiAlgebra.Build R (A1 * A2)%type
pair_scaleAr.
End PairSemiAlg.
Section PairUnitRing.
Variables R1 R2 : unitRingType.
Definition pair_unitr :=
[qualify a x : R1 * R2 | (x.1 \is a GRing.unit) && (x.2 \is a GRing.unit)].
Definition pair_invr x :=
if x \is a pair_unitr then (x.1^-1, x.2^-1) else x.
Lemma pair_mulVl : {in pair_unitr, left_inverse 1 pair_invr *%R}.
Proof.
rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _.
by congr (_, _); apply: mulVr.
Qed.
Lemma pair_mulVr : {in pair_unitr, right_inverse 1 pair_invr *%R}.
Proof.
rewrite /pair_invr=> x; case: ifP => // /andP[Ux1 Ux2] _.
by congr (_, _); apply: mulrV.
Qed.
Lemma pair_unitP x y : y * x = 1 /\ x * y = 1 -> x \is a pair_unitr.
Proof.
case=> [[y1x y2x] [x1y x2y]]; apply/andP.
by split; apply/unitrP; [exists y.1 | exists y.2].
Qed.
Lemma pair_invr_out : {in [predC pair_unitr], pair_invr =1 id}.
Proof. by rewrite /pair_invr => x /negPf/= ->. Qed.
#[export]
HB.instance Definition _ := NzRing_hasMulInverse.Build (R1 * R2)%type
pair_mulVl pair_mulVr pair_unitP pair_invr_out.
End PairUnitRing.
(* TODO: HB.saturate *)
#[export]
HB.instance Definition _ (R1 R2 : comUnitRingType) :=
UnitRing.on (R1 * R2)%type.
#[export]
HB.instance Definition _ (R : pzSemiRingType) (A1 A2 : comSemiAlgType R) :=
SemiAlgebra.on (A1 * A2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (V1 V2 : lmodType R) :=
LSemiModule.on (V1 * V2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (A1 A2 : lalgType R) :=
LSemiAlgebra.on (A1 * A2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (A1 A2 : algType R) :=
SemiAlgebra.on (A1 * A2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (A1 A2 : comAlgType R) :=
Algebra.on (A1 * A2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (A1 A2 : unitAlgType R) :=
Algebra.on (A1 * A2)%type.
#[export]
HB.instance Definition _ (R : pzRingType) (A1 A2 : comUnitAlgType R) :=
Algebra.on (A1 * A2)%type.
(* /TODO *)
Lemma pairMnE (M1 M2 : zmodType) (x : M1 * M2) n :
x *+ n = (x.1 *+ n, x.2 *+ n).
Proof. by case: x => x y; elim: n => //= n; rewrite !mulrS => ->. Qed.
(* begin hide *)
(* Testing subtype hierarchy
Section Test0.
Variables (T : choiceType) (S : {pred T}).
Inductive B := mkB x & x \in S.
Definition vB u := let: mkB x _ := u in x.
HB.instance Definition _ := [isSub for vB].
HB.instance Definition _ := [Choice of B by <:].
End Test0.
Section Test1.
Variables (R : unitRingType) (S : divringClosed R).
HB.instance Definition _ := [SubChoice_isSubUnitRing of B S by <:].
End Test1.
Section Test2.
Variables (R : comUnitRingType) (A : unitAlgType R) (S : divalgClosed A).
HB.instance Definition _ := [SubZmodule_isSubLmodule of B S by <:].
HB.instance Definition _ := [SubNzRing_SubLmodule_isSubLalgebra of B S by <:].
HB.instance Definition _ := [SubLalgebra_isSubAlgebra of B S by <:].
End Test2.
Section Test3.
Variables (F : fieldType) (S : divringClosed F).
HB.instance Definition _ := [SubRing_isSubComNzRing of B S by <:].
HB.instance Definition _ := [SubComUnitRing_isSubIntegralDomain of B S by <:].
HB.instance Definition _ := [SubIntegralDomain_isSubField of B S by <:].
End Test3.
*)
(* end hide *)
(* Algebraic structure of bool *)
HB.instance Definition _ := Zmodule_isComNzRing.Build bool
andbA andbC andTb andb_addl isT.
Fact mulVb (b : bool) : b != 0 -> b * b = 1.
Proof. by case: b. Qed.
Fact invb_out (x y : bool) : y * x = 1 -> x != 0.
Proof. by case: x; case: y. Qed.
HB.instance Definition _ := ComNzRing_hasMulInverse.Build bool
mulVb invb_out (fun x => fun => erefl x).
Lemma bool_fieldP : Field.axiom bool. Proof. by []. Qed.
HB.instance Definition _ := ComUnitRing_isField.Build bool bool_fieldP.
(* Algebraic structure of nat *)
HB.instance Definition _ := Nmodule_isComNzSemiRing.Build nat
mulnA mulnC mul1n mulnDl mul0n erefl.
HB.instance Definition _ (R : pzSemiRingType) :=
isMonoidMorphism.Build nat R (natmul 1) (mulr1n 1, natrM R).
Lemma natr0E : 0 = 0%N. Proof. by []. Qed.
Lemma natr1E : 1 = 1%N. Proof. by []. Qed.
Lemma natn n : n%:R = n.
Proof. by elim: n => [//|n IHn]; rewrite -nat1r IHn. Qed.
Lemma natrDE n m : n + m = (n + m)%N. Proof. by []. Qed.
Lemma natrME n m : n * m = (n * m)%N. Proof. by []. Qed.
Lemma natrXE n m : n ^+ m = (n ^ m)%N. Proof. by []. Qed.
Definition natrE := (natr0E, natr1E, natn, natrDE, natrME, natrXE).
|
Imo2011Q3.lean
|
/-
Copyright (c) 2021 David Renshaw. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Renshaw
-/
import Mathlib.Data.Real.Basic
import Mathlib.Tactic.Linarith
/-!
# IMO 2011 Q3
Let f : ℝ → ℝ be a function that satisfies
f(x + y) ≤ y * f(x) + f(f(x))
for all x and y. Prove that f(x) = 0 for all x ≤ 0.
# Solution
Direct translation of the solution found in https://www.imo-official.org/problems/IMO2011SL.pdf
-/
theorem imo2011_q3 (f : ℝ → ℝ) (hf : ∀ x y, f (x + y) ≤ y * f x + f (f x)) : ∀ x ≤ 0, f x = 0 := by
-- reparameterize
have hxt : ∀ x t, f t ≤ t * f x - x * f x + f (f x) := fun x t =>
calc
f t = f (x + (t - x)) := by rw [add_eq_of_eq_sub' rfl]
_ ≤ (t - x) * f x + f (f x) := hf x (t - x)
_ = t * f x - x * f x + f (f x) := by rw [sub_mul]
have h_ab_combined : ∀ a b, a * f a + b * f b ≤ 2 * f a * f b := fun a b => by
linarith [hxt b (f a), hxt a (f b)]
have h_f_nonneg_of_pos : ∀ a < 0, 0 ≤ f a := fun a han =>
suffices a * f a ≤ 0 from nonneg_of_mul_nonpos_right this han
add_le_iff_nonpos_left.mp (h_ab_combined a (2 * f a))
have h_f_nonpos : ∀ x, f x ≤ 0 := fun x => by
by_contra h_suppose_not
-- If we choose a small enough argument for f, then we get a contradiction.
let s := (x * f x - f (f x)) / f x
have hm : min 0 s - 1 < s := (sub_one_lt _).trans_le (min_le_right 0 s)
have hml : min 0 s - 1 < 0 := (sub_one_lt _).trans_le (min_le_left 0 s)
suffices f (min 0 s - 1) < 0 from not_le.mpr this (h_f_nonneg_of_pos (min 0 s - 1) hml)
have hp : 0 < f x := not_le.mp h_suppose_not
calc
f (min 0 s - 1) ≤ (min 0 s - 1) * f x - x * f x + f (f x) := hxt x (min 0 s - 1)
_ < s * f x - x * f x + f (f x) := by linarith [(mul_lt_mul_right hp).mpr hm]
_ = 0 := by rw [(eq_div_iff hp.ne.symm).mp rfl]; linarith
have h_fx_zero_of_neg : ∀ x < 0, f x = 0 := fun x hxz =>
(h_f_nonpos x).antisymm (h_f_nonneg_of_pos x hxz)
intro x hx
obtain (h_x_neg : x < 0) | (rfl : x = 0) := hx.lt_or_eq
· exact h_fx_zero_of_neg _ h_x_neg
· suffices 0 ≤ f 0 from le_antisymm (h_f_nonpos 0) this
have hno : f (-1) = 0 := h_fx_zero_of_neg (-1) neg_one_lt_zero
have hp := hxt (-1) (-1)
rw [hno] at hp
linarith
|
OpenSubgroup.lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Nailin Guan, Yi Song, Xuchun Li
-/
import Mathlib.Algebra.Module.Submodule.Lattice
import Mathlib.RingTheory.Ideal.Defs
import Mathlib.Topology.Algebra.Group.Quotient
import Mathlib.Topology.Algebra.Ring.Basic
import Mathlib.Topology.Sets.Opens
/-!
# Open subgroups of a topological group
This files builds the lattice `OpenSubgroup G` of open subgroups in a topological group `G`,
and its additive version `OpenAddSubgroup`. This lattice has a top element, the subgroup of all
elements, but no bottom element in general. The trivial subgroup which is the natural candidate
bottom has no reason to be open (this happens only in discrete groups).
Note that this notion is especially relevant in a non-archimedean context, for instance for
`p`-adic groups.
## Main declarations
* `OpenSubgroup.isClosed`: An open subgroup is automatically closed.
* `Subgroup.isOpen_mono`: A subgroup containing an open subgroup is open.
There are also versions for additive groups, submodules and ideals.
* `OpenSubgroup.comap`: Open subgroups can be pulled back by a continuous group morphism.
## TODO
* Prove that the identity component of a locally path connected group is an open subgroup.
Up to now this file is really geared towards non-archimedean algebra, not Lie groups.
-/
open TopologicalSpace Topology Function
/-- The type of open subgroups of a topological additive group. -/
structure OpenAddSubgroup (G : Type*) [AddGroup G] [TopologicalSpace G] extends AddSubgroup G where
isOpen' : IsOpen carrier
/-- The type of open subgroups of a topological group. -/
@[to_additive]
structure OpenSubgroup (G : Type*) [Group G] [TopologicalSpace G] extends Subgroup G where
isOpen' : IsOpen carrier
/-- Reinterpret an `OpenSubgroup` as a `Subgroup`. -/
add_decl_doc OpenSubgroup.toSubgroup
/-- Reinterpret an `OpenAddSubgroup` as an `AddSubgroup`. -/
add_decl_doc OpenAddSubgroup.toAddSubgroup
attribute [coe] OpenSubgroup.toSubgroup OpenAddSubgroup.toAddSubgroup
namespace OpenSubgroup
variable {G : Type*} [Group G] [TopologicalSpace G]
variable {U V : OpenSubgroup G} {g : G}
@[to_additive]
instance hasCoeSubgroup : CoeTC (OpenSubgroup G) (Subgroup G) :=
⟨toSubgroup⟩
@[to_additive]
theorem toSubgroup_injective : Injective ((↑) : OpenSubgroup G → Subgroup G)
| ⟨_, _⟩, ⟨_, _⟩, rfl => rfl
@[to_additive]
instance : SetLike (OpenSubgroup G) G where
coe U := U.1
coe_injective' _ _ h := toSubgroup_injective <| SetLike.ext' h
@[to_additive]
instance : SubgroupClass (OpenSubgroup G) G where
mul_mem := Subsemigroup.mul_mem' _
one_mem U := U.one_mem'
inv_mem := Subgroup.inv_mem' _
/-- Coercion from `OpenSubgroup G` to `Opens G`. -/
@[to_additive (attr := coe) /-- Coercion from `OpenAddSubgroup G` to `Opens G`. -/]
def toOpens (U : OpenSubgroup G) : Opens G := ⟨U, U.isOpen'⟩
@[to_additive]
instance hasCoeOpens : CoeTC (OpenSubgroup G) (Opens G) := ⟨toOpens⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_toOpens : ((U : Opens G) : Set G) = U :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_toSubgroup : ((U : Subgroup G) : Set G) = U := rfl
@[to_additive (attr := simp, norm_cast)]
theorem mem_toOpens : g ∈ (U : Opens G) ↔ g ∈ U := Iff.rfl
@[to_additive (attr := simp, norm_cast)]
theorem mem_toSubgroup : g ∈ (U : Subgroup G) ↔ g ∈ U := Iff.rfl
@[to_additive (attr := ext)]
theorem ext (h : ∀ x, x ∈ U ↔ x ∈ V) : U = V :=
SetLike.ext h
variable (U)
@[to_additive]
protected theorem isOpen : IsOpen (U : Set G) :=
U.isOpen'
@[to_additive]
theorem mem_nhds_one : (U : Set G) ∈ 𝓝 (1 : G) :=
U.isOpen.mem_nhds U.one_mem
variable {U}
@[to_additive] instance : Top (OpenSubgroup G) := ⟨⟨⊤, isOpen_univ⟩⟩
@[to_additive (attr := simp)]
theorem mem_top (x : G) : x ∈ (⊤ : OpenSubgroup G) :=
trivial
@[to_additive (attr := simp, norm_cast)]
theorem coe_top : ((⊤ : OpenSubgroup G) : Set G) = Set.univ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem toSubgroup_top : ((⊤ : OpenSubgroup G) : Subgroup G) = ⊤ :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem toOpens_top : ((⊤ : OpenSubgroup G) : Opens G) = ⊤ :=
rfl
@[to_additive]
instance : Inhabited (OpenSubgroup G) :=
⟨⊤⟩
@[to_additive]
theorem isClosed [ContinuousMul G] (U : OpenSubgroup G) : IsClosed (U : Set G) := by
apply isOpen_compl_iff.1
refine isOpen_iff_forall_mem_open.2 fun x hx ↦ ⟨(fun y ↦ y * x⁻¹) ⁻¹' U, ?_, ?_, ?_⟩
· refine fun u hux hu ↦ hx ?_
simp only [Set.mem_preimage, SetLike.mem_coe] at hux hu ⊢
convert U.mul_mem (U.inv_mem hux) hu
simp
· exact U.isOpen.preimage (continuous_mul_right _)
· simp [one_mem]
@[to_additive]
theorem isClopen [ContinuousMul G] (U : OpenSubgroup G) : IsClopen (U : Set G) :=
⟨U.isClosed, U.isOpen⟩
section
variable {H : Type*} [Group H] [TopologicalSpace H]
/-- The product of two open subgroups as an open subgroup of the product group. -/
@[to_additive prod
/-- The product of two open subgroups as an open subgroup of the product group. -/]
def prod (U : OpenSubgroup G) (V : OpenSubgroup H) : OpenSubgroup (G × H) :=
⟨.prod U V, U.isOpen.prod V.isOpen⟩
@[deprecated (since := "2025-03-11")]
alias _root_.OpenAddSubgroup.sum := OpenAddSubgroup.prod
@[to_additive (attr := simp, norm_cast) coe_prod]
theorem coe_prod (U : OpenSubgroup G) (V : OpenSubgroup H) :
(U.prod V : Set (G × H)) = (U : Set G) ×ˢ (V : Set H) :=
rfl
@[deprecated (since := "2025-03-11")]
alias _root_.OpenAddSubgroup.coe_sum := OpenAddSubgroup.coe_prod
@[to_additive (attr := simp, norm_cast) toAddSubgroup_prod]
theorem toSubgroup_prod (U : OpenSubgroup G) (V : OpenSubgroup H) :
(U.prod V : Subgroup (G × H)) = (U : Subgroup G).prod V :=
rfl
@[deprecated (since := "2025-03-11")]
alias _root_.OpenAddSubgroup.toAddSubgroup_sum := OpenAddSubgroup.toAddSubgroup_prod
end
@[to_additive]
instance instInfOpenSubgroup : Min (OpenSubgroup G) :=
⟨fun U V ↦ ⟨U ⊓ V, U.isOpen.inter V.isOpen⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inf : (↑(U ⊓ V) : Set G) = (U : Set G) ∩ V :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem toSubgroup_inf : (↑(U ⊓ V) : Subgroup G) = ↑U ⊓ ↑V :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem toOpens_inf : (↑(U ⊓ V) : Opens G) = ↑U ⊓ ↑V :=
rfl
@[to_additive (attr := simp)]
theorem mem_inf {x} : x ∈ U ⊓ V ↔ x ∈ U ∧ x ∈ V :=
Iff.rfl
@[to_additive]
instance instPartialOrderOpenSubgroup : PartialOrder (OpenSubgroup G) := inferInstance
-- We override `toPartialorder` to get better `le`
@[to_additive]
instance instSemilatticeInfOpenSubgroup : SemilatticeInf (OpenSubgroup G) :=
{ SetLike.coe_injective.semilatticeInf ((↑) : OpenSubgroup G → Set G) fun _ _ ↦ rfl with
toPartialOrder := instPartialOrderOpenSubgroup }
@[to_additive]
instance : OrderTop (OpenSubgroup G) where
top := ⊤
le_top _ := Set.subset_univ _
@[to_additive (attr := simp, norm_cast)]
theorem toSubgroup_le : (U : Subgroup G) ≤ (V : Subgroup G) ↔ U ≤ V :=
Iff.rfl
variable {N : Type*} [Group N] [TopologicalSpace N]
/-- The preimage of an `OpenSubgroup` along a continuous `Monoid` homomorphism
is an `OpenSubgroup`. -/
@[to_additive /-- The preimage of an `OpenAddSubgroup` along a continuous `AddMonoid` homomorphism
is an `OpenAddSubgroup`. -/]
def comap (f : G →* N) (hf : Continuous f) (H : OpenSubgroup N) : OpenSubgroup G :=
⟨.comap f H, H.isOpen.preimage hf⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_comap (H : OpenSubgroup N) (f : G →* N) (hf : Continuous f) :
(H.comap f hf : Set G) = f ⁻¹' H :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem toSubgroup_comap (H : OpenSubgroup N) (f : G →* N) (hf : Continuous f) :
(H.comap f hf : Subgroup G) = (H : Subgroup N).comap f :=
rfl
@[to_additive (attr := simp)]
theorem mem_comap {H : OpenSubgroup N} {f : G →* N} {hf : Continuous f} {x : G} :
x ∈ H.comap f hf ↔ f x ∈ H :=
Iff.rfl
@[to_additive]
theorem comap_comap {P : Type*} [Group P] [TopologicalSpace P] (K : OpenSubgroup P) (f₂ : N →* P)
(hf₂ : Continuous f₂) (f₁ : G →* N) (hf₁ : Continuous f₁) :
(K.comap f₂ hf₂).comap f₁ hf₁ = K.comap (f₂.comp f₁) (hf₂.comp hf₁) :=
rfl
end OpenSubgroup
namespace Subgroup
variable {G : Type*} [Group G] [TopologicalSpace G]
@[to_additive]
theorem isOpen_of_mem_nhds [ContinuousMul G] (H : Subgroup G) {g : G} (hg : (H : Set G) ∈ 𝓝 g) :
IsOpen (H : Set G) := by
refine isOpen_iff_mem_nhds.2 fun x hx ↦ ?_
have hg' : g ∈ H := SetLike.mem_coe.1 (mem_of_mem_nhds hg)
have : Filter.Tendsto (fun y ↦ y * (x⁻¹ * g)) (𝓝 x) (𝓝 g) :=
(continuous_id.mul continuous_const).tendsto' _ _ (mul_inv_cancel_left _ _)
simpa only [SetLike.mem_coe, Filter.mem_map',
H.mul_mem_cancel_right (H.mul_mem (H.inv_mem hx) hg')] using this hg
@[to_additive]
theorem isOpen_mono [ContinuousMul G] {H₁ H₂ : Subgroup G} (h : H₁ ≤ H₂)
(h₁ : IsOpen (H₁ : Set G)) : IsOpen (H₂ : Set G) :=
isOpen_of_mem_nhds _ <| Filter.mem_of_superset (h₁.mem_nhds <| one_mem H₁) h
@[to_additive]
theorem isOpen_of_openSubgroup
[ContinuousMul G] (H : Subgroup G) {U : OpenSubgroup G} (h : ↑U ≤ H) :
IsOpen (H : Set G) :=
isOpen_mono h U.isOpen
/-- If a subgroup of a topological group has `1` in its interior, then it is open. -/
@[to_additive /-- If a subgroup of an additive topological group has `0` in its interior, then it is
open. -/]
theorem isOpen_of_one_mem_interior [ContinuousMul G] (H : Subgroup G)
(h_1_int : (1 : G) ∈ interior (H : Set G)) : IsOpen (H : Set G) :=
isOpen_of_mem_nhds H <| mem_interior_iff_mem_nhds.1 h_1_int
@[to_additive]
lemma isClosed_of_isOpen [ContinuousMul G] (U : Subgroup G) (h : IsOpen (U : Set G)) :
IsClosed (U : Set G) :=
OpenSubgroup.isClosed ⟨U, h⟩
@[to_additive]
lemma subgroupOf_isOpen (U K : Subgroup G) (h : IsOpen (K : Set G)) :
IsOpen (K.subgroupOf U : Set U) :=
Continuous.isOpen_preimage (continuous_iff_le_induced.mpr fun _ ↦ id) _ h
@[to_additive]
lemma discreteTopology [ContinuousMul G] (U : Subgroup G) (h : IsOpen (U : Set G)) :
DiscreteTopology (G ⧸ U) := by
refine singletons_open_iff_discrete.mp (fun g ↦ ?_)
induction g using Quotient.inductionOn with | h g =>
change IsOpen (QuotientGroup.mk ⁻¹' {QuotientGroup.mk g})
convert_to IsOpen ((g * ·) '' U)
· ext g'
simp only [Set.mem_preimage, Set.mem_singleton_iff, QuotientGroup.eq, Set.image_mul_left]
rw [← U.inv_mem_iff]
simp
· exact Homeomorph.mulLeft g |>.isOpen_image |>.mpr h
@[to_additive]
instance [ContinuousMul G] (U : OpenSubgroup G) : DiscreteTopology (G ⧸ U.toSubgroup) :=
discreteTopology U.toSubgroup U.isOpen
@[to_additive]
lemma quotient_finite_of_isOpen [ContinuousMul G] [CompactSpace G] (U : Subgroup G)
(h : IsOpen (U : Set G)) : Finite (G ⧸ U) :=
have : DiscreteTopology (G ⧸ U) := U.discreteTopology h
finite_of_compact_of_discrete
@[to_additive]
instance [ContinuousMul G] [CompactSpace G] (U : OpenSubgroup G) : Finite (G ⧸ U.toSubgroup) :=
quotient_finite_of_isOpen U.toSubgroup U.isOpen
@[to_additive]
lemma quotient_finite_of_isOpen' [IsTopologicalGroup G] [CompactSpace G] (U : Subgroup G)
(K : Subgroup U) (hUopen : IsOpen (U : Set G)) (hKopen : IsOpen (K : Set U)) :
Finite (U ⧸ K) :=
have : CompactSpace U := isCompact_iff_compactSpace.mp <| IsClosed.isCompact <|
U.isClosed_of_isOpen hUopen
K.quotient_finite_of_isOpen hKopen
@[to_additive]
instance [IsTopologicalGroup G] [CompactSpace G] (U : OpenSubgroup G) (K : OpenSubgroup U) :
Finite (U ⧸ K.toSubgroup) :=
quotient_finite_of_isOpen' U.toSubgroup K.toSubgroup U.isOpen K.isOpen
end Subgroup
namespace OpenSubgroup
variable {G : Type*} [Group G] [TopologicalSpace G] [ContinuousMul G]
@[to_additive]
instance : Max (OpenSubgroup G) :=
⟨fun U V ↦ ⟨U ⊔ V, Subgroup.isOpen_mono (le_sup_left : U.1 ≤ U.1 ⊔ V.1) U.isOpen⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem toSubgroup_sup (U V : OpenSubgroup G) : (↑(U ⊔ V) : Subgroup G) = ↑U ⊔ ↑V := rfl
-- We override `toPartialorder` to get better `le`
@[to_additive]
instance : Lattice (OpenSubgroup G) :=
{ instSemilatticeInfOpenSubgroup,
toSubgroup_injective.semilatticeSup ((↑) : OpenSubgroup G → Subgroup G) fun _ _ ↦ rfl with
toPartialOrder := instPartialOrderOpenSubgroup }
end OpenSubgroup
namespace Submodule
open OpenAddSubgroup
variable {R : Type*} {M : Type*} [CommRing R]
variable [AddCommGroup M] [TopologicalSpace M] [IsTopologicalAddGroup M] [Module R M]
theorem isOpen_mono {U P : Submodule R M} (h : U ≤ P) (hU : IsOpen (U : Set M)) :
IsOpen (P : Set M) :=
@AddSubgroup.isOpen_mono M _ _ _ U.toAddSubgroup P.toAddSubgroup h hU
end Submodule
namespace Ideal
variable {R : Type*} [CommRing R]
variable [TopologicalSpace R] [IsTopologicalRing R]
theorem isOpen_of_isOpen_subideal {U I : Ideal R} (h : U ≤ I) (hU : IsOpen (U : Set R)) :
IsOpen (I : Set R) :=
@Submodule.isOpen_mono R R _ _ _ _ Semiring.toModule _ _ h hU
end Ideal
/-!
# Open normal subgroups of a topological group
This section builds the lattice `OpenNormalSubgroup G` of open subgroups in a topological group `G`,
and its additive version `OpenNormalAddSubgroup`.
-/
section
universe u
/-- The type of open normal subgroups of a topological group. -/
@[ext]
structure OpenNormalSubgroup (G : Type u) [Group G] [TopologicalSpace G]
extends OpenSubgroup G where
isNormal' : toSubgroup.Normal := by infer_instance
/-- The type of open normal subgroups of a topological additive group. -/
@[ext]
structure OpenNormalAddSubgroup (G : Type u) [AddGroup G] [TopologicalSpace G]
extends OpenAddSubgroup G where
isNormal' : toAddSubgroup.Normal := by infer_instance
attribute [to_additive] OpenNormalSubgroup
namespace OpenNormalSubgroup
variable {G : Type u} [Group G] [TopologicalSpace G]
@[to_additive]
instance (H : OpenNormalSubgroup G) : H.toSubgroup.Normal := H.isNormal'
@[to_additive]
theorem toSubgroup_injective : Function.Injective
(fun H ↦ H.toOpenSubgroup.toSubgroup : OpenNormalSubgroup G → Subgroup G) :=
fun A B h ↦ by
ext
dsimp at h
rw [h]
@[to_additive]
instance : SetLike (OpenNormalSubgroup G) G where
coe U := U.1
coe_injective' _ _ h := toSubgroup_injective <| SetLike.ext' h
@[to_additive]
instance : SubgroupClass (OpenNormalSubgroup G) G where
mul_mem := Subsemigroup.mul_mem' _
one_mem U := U.one_mem'
inv_mem := Subgroup.inv_mem' _
@[to_additive]
instance : Coe (OpenNormalSubgroup G) (Subgroup G) where
coe H := H.toOpenSubgroup.toSubgroup
@[to_additive]
instance instPartialOrderOpenNormalSubgroup : PartialOrder (OpenNormalSubgroup G) := inferInstance
@[to_additive]
instance instInfOpenNormalSubgroup : Min (OpenNormalSubgroup G) :=
⟨fun U V ↦ ⟨U.toOpenSubgroup ⊓ V.toOpenSubgroup,
Subgroup.normal_inf_normal U.toSubgroup V.toSubgroup⟩⟩
@[to_additive]
instance instSemilatticeInfOpenNormalSubgroup : SemilatticeInf (OpenNormalSubgroup G) :=
SetLike.coe_injective.semilatticeInf ((↑) : OpenNormalSubgroup G → Set G) fun _ _ ↦ rfl
@[to_additive]
instance [ContinuousMul G] : Max (OpenNormalSubgroup G) :=
⟨fun U V ↦ ⟨U.toOpenSubgroup ⊔ V.toOpenSubgroup,
Subgroup.sup_normal U.toOpenSubgroup.1 V.toOpenSubgroup.1⟩⟩
@[to_additive]
instance instSemilatticeSupOpenNormalSubgroup [ContinuousMul G] :
SemilatticeSup (OpenNormalSubgroup G) :=
toSubgroup_injective.semilatticeSup _ (fun _ _ ↦ rfl)
@[to_additive]
instance [ContinuousMul G] : Lattice (OpenNormalSubgroup G) :=
{ instSemilatticeInfOpenNormalSubgroup,
instSemilatticeSupOpenNormalSubgroup with
toPartialOrder := instPartialOrderOpenNormalSubgroup}
end OpenNormalSubgroup
end
/-!
# Existence of an open subgroup in any clopen neighborhood of the neutral element
This section proves the lemma `IsTopologicalGroup.exist_openSubgroup_sub_clopen_nhds_of_one`, which
states that in a compact topological group, for any clopen neighborhood of 1,
there exists an open subgroup contained within it.
-/
open scoped Pointwise
variable {G : Type*} [TopologicalSpace G]
structure IsTopologicalAddGroup.addNegClosureNhd (T W : Set G) [AddGroup G] : Prop where
nhds : T ∈ 𝓝 0
neg : -T = T
isOpen : IsOpen T
add : W + T ⊆ W
/-- For a set `W`, `T` is a neighborhood of `1` which is open, stable under inverse and satisfies
`T * W ⊆ W`. -/
@[to_additive
/-- For a set `W`, `T` is a neighborhood of `0` which is open, stable under negation and satisfies
`T + W ⊆ W`. -/]
structure IsTopologicalGroup.mulInvClosureNhd (T W : Set G) [Group G] : Prop where
nhds : T ∈ 𝓝 1
inv : T⁻¹ = T
isOpen : IsOpen T
mul : W * T ⊆ W
namespace IsTopologicalGroup
variable [Group G] [IsTopologicalGroup G] [CompactSpace G]
open Set Filter
@[to_additive]
lemma exist_mul_closure_nhds {W : Set G} (WClopen : IsClopen W) : ∃ T ∈ 𝓝 (1 : G), W * T ⊆ W := by
apply WClopen.isClosed.isCompact.induction_on (p := fun S ↦ ∃ T ∈ 𝓝 (1 : G), S * T ⊆ W)
⟨Set.univ ,by simp only [univ_mem, empty_mul, empty_subset, and_self]⟩
(fun _ _ huv ⟨T, hT, mem⟩ ↦ ⟨T, hT, (mul_subset_mul_right huv).trans mem⟩)
fun U V ⟨T₁, hT₁, mem1⟩ ⟨T₂, hT₂, mem2⟩ ↦ ⟨T₁ ∩ T₂, inter_mem hT₁ hT₂, by
rw [union_mul]
exact union_subset (mul_subset_mul_left inter_subset_left |>.trans mem1)
(mul_subset_mul_left inter_subset_right |>.trans mem2) ⟩
intro x memW
have : (x, 1) ∈ (fun p ↦ p.1 * p.2) ⁻¹' W := by simp [memW]
rcases isOpen_prod_iff.mp (continuous_mul.isOpen_preimage W <| WClopen.2) x 1 this with
⟨U, V, Uopen, Vopen, xmemU, onememV, prodsub⟩
have h6 : U * V ⊆ W := mul_subset_iff.mpr (fun _ hx _ hy ↦ prodsub (mk_mem_prod hx hy))
exact ⟨U ∩ W, ⟨U, Uopen.mem_nhds xmemU, W, fun _ a ↦ a, rfl⟩,
V, IsOpen.mem_nhds Vopen onememV, fun _ a ↦ h6 ((mul_subset_mul_right inter_subset_left) a)⟩
@[deprecated (since := "2025-05-22")] alias exist_mul_closure_nhd := exist_mul_closure_nhds
@[deprecated (since := "2025-05-22")] alias _root_.IsTopologicalAddGroup.exist_add_closure_nhd :=
IsTopologicalAddGroup.exist_add_closure_nhds
@[to_additive]
lemma exists_mulInvClosureNhd {W : Set G} (WClopen : IsClopen W) :
∃ T, mulInvClosureNhd T W := by
rcases exist_mul_closure_nhds WClopen with ⟨S, Smemnhds, mulclose⟩
rcases mem_nhds_iff.mp Smemnhds with ⟨U, UsubS, Uopen, onememU⟩
use U ∩ U⁻¹
constructor
· simp [Uopen.mem_nhds onememU, inv_mem_nhds_one]
· simp [inter_comm]
· exact Uopen.inter Uopen.inv
· exact fun a ha ↦ mulclose (mul_subset_mul_left UsubS (mul_subset_mul_left inter_subset_left ha))
@[to_additive]
theorem exist_openSubgroup_sub_clopen_nhds_of_one {G : Type*} [Group G] [TopologicalSpace G]
[IsTopologicalGroup G] [CompactSpace G] {W : Set G} (WClopen : IsClopen W) (einW : 1 ∈ W) :
∃ H : OpenSubgroup G, (H : Set G) ⊆ W := by
rcases exists_mulInvClosureNhd WClopen with ⟨V, hV⟩
let S : Subgroup G := {
carrier := ⋃ n , V ^ (n + 1)
mul_mem' := fun ha hb ↦ by
rcases mem_iUnion.mp ha with ⟨k, hk⟩
rcases mem_iUnion.mp hb with ⟨l, hl⟩
apply mem_iUnion.mpr
use k + 1 + l
rw [add_assoc, pow_add]
exact Set.mul_mem_mul hk hl
one_mem' := by
apply mem_iUnion.mpr
use 0
simp [mem_of_mem_nhds hV.nhds]
inv_mem' := fun ha ↦ by
rcases mem_iUnion.mp ha with ⟨k, hk⟩
apply mem_iUnion.mpr
use k
rw [← hV.inv]
simpa only [inv_pow, Set.mem_inv, inv_inv] using hk }
have : IsOpen (⋃ n , V ^ (n + 1)) := by
refine isOpen_iUnion (fun n ↦ ?_)
rw [pow_succ]
exact hV.isOpen.mul_left
use ⟨S, this⟩
have mulVpow (n : ℕ) : W * V ^ (n + 1) ⊆ W := by
induction n with
| zero => simp [hV.mul]
| succ n ih =>
rw [pow_succ, ← mul_assoc]
exact (Set.mul_subset_mul_right ih).trans hV.mul
have (n : ℕ) : V ^ (n + 1) ⊆ W * V ^ (n + 1) := by
intro x xin
rw [Set.mem_mul]
use 1, einW, x, xin
rw [one_mul]
apply iUnion_subset fun i _ a ↦ mulVpow i (this i a)
@[deprecated (since := "2025-05-22")]
alias exist_openSubgroup_sub_clopen_nhd_of_one := exist_openSubgroup_sub_clopen_nhds_of_one
@[deprecated (since := "2025-05-22")]
alias _root_.IsTopologicalAddGroup.exist_openAddSubgroup_sub_clopen_nhd_of_zero :=
IsTopologicalAddGroup.exist_openAddSubgroup_sub_clopen_nhds_of_zero
end IsTopologicalGroup
|
Fin.lean
|
/-
Copyright (c) 2020 Yury Kudryashov, Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Anne Baanen
-/
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Group.Action.Pi
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Data.Fintype.Fin
import Mathlib.Logic.Equiv.Fin.Basic
/-!
# Big operators and `Fin`
Some results about products and sums over the type `Fin`.
The most important results are the induction formulas `Fin.prod_univ_castSucc`
and `Fin.prod_univ_succ`, and the formula `Fin.prod_const` for the product of a
constant function. These results have variants for sums instead of products.
## Main declarations
* `finFunctionFinEquiv`: An explicit equivalence between `Fin n → Fin m` and `Fin (m ^ n)`.
-/
assert_not_exists Field
open Finset
variable {ι M : Type*}
namespace Finset
@[to_additive]
theorem prod_range [CommMonoid M] {n : ℕ} (f : ℕ → M) :
∏ i ∈ Finset.range n, f i = ∏ i : Fin n, f i :=
(Fin.prod_univ_eq_prod_range _ _).symm
end Finset
namespace Fin
section CommMonoid
variable [CommMonoid M] {n : ℕ}
@[to_additive]
theorem prod_ofFn (f : Fin n → M) : (List.ofFn f).prod = ∏ i, f i := by
simp [prod_eq_multiset_prod]
@[to_additive]
theorem prod_univ_def (f : Fin n → M) : ∏ i, f i = ((List.finRange n).map f).prod := by
rw [← List.ofFn_eq_map, prod_ofFn]
/-- A product of a function `f : Fin 0 → M` is `1` because `Fin 0` is empty -/
@[to_additive /-- A sum of a function `f : Fin 0 → M` is `0` because `Fin 0` is empty -/]
theorem prod_univ_zero (f : Fin 0 → M) : ∏ i, f i = 1 :=
rfl
/-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)`
is the product of `f x`, for some `x : Fin (n + 1)` times the remaining product -/
@[to_additive /-- A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of
`f x`, for some `x : Fin (n + 1)` plus the remaining sum -/]
theorem prod_univ_succAbove (f : Fin (n + 1) → M) (x : Fin (n + 1)) :
∏ i, f i = f x * ∏ i : Fin n, f (x.succAbove i) := by
rw [univ_succAbove n x, prod_cons, Finset.prod_map, coe_succAboveEmb]
/-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)`
is the product of `f 0` times the remaining product -/
@[to_additive /-- A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of
`f 0` plus the remaining sum -/]
theorem prod_univ_succ (f : Fin (n + 1) → M) :
∏ i, f i = f 0 * ∏ i : Fin n, f i.succ :=
prod_univ_succAbove f 0
/-- A product of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)`
is the product of `f (Fin.last n)` times the remaining product -/
@[to_additive /-- A sum of a function `f : Fin (n + 1) → M` over all `Fin (n + 1)` is the sum of
`f (Fin.last n)` plus the remaining sum -/]
theorem prod_univ_castSucc (f : Fin (n + 1) → M) :
∏ i, f i = (∏ i : Fin n, f (Fin.castSucc i)) * f (last n) := by
simpa [mul_comm] using prod_univ_succAbove f (last n)
@[to_additive (attr := simp)]
theorem prod_univ_getElem (l : List M) : ∏ i : Fin l.length, l[i.1] = l.prod := by
simp [Finset.prod_eq_multiset_prod]
@[deprecated (since := "2025-04-19")]
alias sum_univ_get := sum_univ_getElem
@[to_additive existing, deprecated (since := "2025-04-19")]
alias prod_univ_get := prod_univ_getElem
@[to_additive (attr := simp)]
theorem prod_univ_fun_getElem (l : List ι) (f : ι → M) :
∏ i : Fin l.length, f l[i.1] = (l.map f).prod := by
simp [Finset.prod_eq_multiset_prod]
@[deprecated (since := "2025-04-19")]
alias sum_univ_get' := sum_univ_fun_getElem
@[to_additive existing, deprecated (since := "2025-04-19")]
alias prod_univ_get' := prod_univ_fun_getElem
@[to_additive (attr := simp)]
theorem prod_cons (x : M) (f : Fin n → M) :
(∏ i : Fin n.succ, (cons x f : Fin n.succ → M) i) = x * ∏ i : Fin n, f i := by
simp_rw [prod_univ_succ, cons_zero, cons_succ]
@[to_additive (attr := simp)]
theorem prod_snoc (x : M) (f : Fin n → M) :
(∏ i : Fin n.succ, (snoc f x : Fin n.succ → M) i) = (∏ i : Fin n, f i) * x := by
simp [prod_univ_castSucc]
@[to_additive sum_univ_one]
theorem prod_univ_one (f : Fin 1 → M) : ∏ i, f i = f 0 := by simp
@[to_additive (attr := simp)]
theorem prod_univ_two (f : Fin 2 → M) : ∏ i, f i = f 0 * f 1 := by
simp [prod_univ_succ]
@[to_additive]
theorem prod_univ_two' (f : ι → M) (a b : ι) : ∏ i, f (![a, b] i) = f a * f b :=
prod_univ_two _
@[to_additive]
theorem prod_univ_three (f : Fin 3 → M) : ∏ i, f i = f 0 * f 1 * f 2 := by
rw [prod_univ_castSucc, prod_univ_two]
rfl
@[to_additive]
theorem prod_univ_four (f : Fin 4 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 := by
rw [prod_univ_castSucc, prod_univ_three]
rfl
@[to_additive]
theorem prod_univ_five (f : Fin 5 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 := by
rw [prod_univ_castSucc, prod_univ_four]
rfl
@[to_additive]
theorem prod_univ_six (f : Fin 6 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 := by
rw [prod_univ_castSucc, prod_univ_five]
rfl
@[to_additive]
theorem prod_univ_seven (f : Fin 7 → M) : ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 := by
rw [prod_univ_castSucc, prod_univ_six]
rfl
@[to_additive]
theorem prod_univ_eight (f : Fin 8 → M) :
∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 * f 7 := by
rw [prod_univ_castSucc, prod_univ_seven]
rfl
@[to_additive]
theorem prod_const (n : ℕ) (x : M) : ∏ _i : Fin n, x = x ^ n := by simp
@[to_additive]
theorem prod_congr' {a b : ℕ} (f : Fin b → M) (h : a = b) :
(∏ i : Fin a, f (i.cast h)) = ∏ i : Fin b, f i := by
subst h
congr
@[to_additive]
theorem prod_univ_add {a b : ℕ} (f : Fin (a + b) → M) :
(∏ i : Fin (a + b), f i) = (∏ i : Fin a, f (castAdd b i)) * ∏ i : Fin b, f (natAdd a i) := by
rw [Fintype.prod_equiv finSumFinEquiv.symm f fun i => f (finSumFinEquiv.toFun i)]
· apply Fintype.prod_sum_type
· intro x
simp only [Equiv.toFun_as_coe, Equiv.apply_symm_apply]
@[to_additive]
theorem prod_trunc {a b : ℕ} (f : Fin (a + b) → M) (hf : ∀ j : Fin b, f (natAdd a j) = 1) :
(∏ i : Fin (a + b), f i) = ∏ i : Fin a, f (castAdd b i) := by
rw [prod_univ_add, Fintype.prod_eq_one _ hf, mul_one]
/-!
### Products over intervals: `Fin.cast`
-/
section cast
variable {m : ℕ}
@[to_additive]
theorem prod_Icc_cast (h : n = m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Icc (a.cast h) (b.cast h), f i = ∏ i ∈ Icc a b, f (i.cast h) := by
simp [← map_finCongr_Icc]
@[to_additive]
theorem prod_Ico_cast (h : n = m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ico (a.cast h) (b.cast h), f i = ∏ i ∈ Ico a b, f (i.cast h) := by
simp [← map_finCongr_Ico]
@[to_additive]
theorem prod_Ioc_cast (h : n = m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ioc (a.cast h) (b.cast h), f i = ∏ i ∈ Ioc a b, f (i.cast h) := by
simp [← map_finCongr_Ioc]
@[to_additive]
theorem prod_Ioo_cast (h : n = m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ioo (a.cast h) (b.cast h), f i = ∏ i ∈ Ioo a b, f (i.cast h) := by
simp [← map_finCongr_Ioo]
@[to_additive]
theorem prod_uIcc_cast (h : n = m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ uIcc (a.cast h) (b.cast h), f i = ∏ i ∈ uIcc a b, f (i.cast h) := by
simp [← map_finCongr_uIcc]
@[to_additive]
theorem prod_Ici_cast (h : n = m) (f : Fin m → M) (a : Fin n) :
∏ i ≥ a.cast h, f i = ∏ i ≥ a, f (i.cast h) := by
simp [← map_finCongr_Ici]
@[to_additive]
theorem prod_Ioi_cast (h : n = m) (f : Fin m → M) (a : Fin n) :
∏ i > a.cast h, f i = ∏ i > a, f (i.cast h) := by
simp [← map_finCongr_Ioi]
@[to_additive]
theorem prod_Iic_cast (h : n = m) (f : Fin m → M) (a : Fin n) :
∏ i ≤ a.cast h, f i = ∏ i ≤ a, f (i.cast h) := by
simp [← map_finCongr_Iic]
@[to_additive]
theorem prod_Iio_cast (h : n = m) (f : Fin m → M) (a : Fin n) :
∏ i < a.cast h, f i = ∏ i < a, f (i.cast h) := by
simp [← map_finCongr_Iio]
end cast
/-!
### Products over intervals: `Fin.castLE`
-/
section castLE
variable {m : ℕ}
@[to_additive]
theorem prod_Icc_castLE (h : n ≤ m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Icc (a.castLE h) (b.castLE h), f i = ∏ i ∈ Icc a b, f (i.castLE h) := by
simp [← map_castLEEmb_Icc]
@[to_additive]
theorem prod_Ico_castLE (h : n ≤ m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ico (a.castLE h) (b.castLE h), f i = ∏ i ∈ Ico a b, f (i.castLE h) := by
simp [← map_castLEEmb_Ico]
@[to_additive]
theorem prod_Ioc_castLE (h : n ≤ m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ioc (a.castLE h) (b.castLE h), f i = ∏ i ∈ Ioc a b, f (i.castLE h) := by
simp [← map_castLEEmb_Ioc]
@[to_additive]
theorem prod_Ioo_castLE (h : n ≤ m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ Ioo (a.castLE h) (b.castLE h), f i = ∏ i ∈ Ioo a b, f (i.castLE h) := by
simp [← map_castLEEmb_Ioo]
@[to_additive]
theorem prod_uIcc_castLE (h : n ≤ m) (f : Fin m → M) (a b : Fin n) :
∏ i ∈ uIcc (a.castLE h) (b.castLE h), f i = ∏ i ∈ uIcc a b, f (i.castLE h) := by
simp [← map_castLEEmb_uIcc]
@[to_additive]
theorem prod_Iic_castLE (h : n ≤ m) (f : Fin m → M) (a : Fin n) :
∏ i ≤ a.castLE h, f i = ∏ i ≤ a, f (i.castLE h) := by
simp [← map_castLEEmb_Iic]
@[to_additive]
theorem prod_Iio_castLE (h : n ≤ m) (f : Fin m → M) (a : Fin n) :
∏ i < a.castLE h, f i = ∏ i < a, f (i.castLE h) := by
simp [← map_castLEEmb_Iio]
end castLE
/-!
### Products over intervals: `Fin.castAdd`
-/
section castAdd
@[to_additive]
theorem prod_Icc_castAdd (m : ℕ) (f : Fin (n + m) → M) (a b : Fin n) :
∏ i ∈ Icc (a.castAdd m) (b.castAdd m), f i = ∏ i ∈ Icc a b, f (i.castAdd m) := by
simp [← map_castAddEmb_Icc]
@[to_additive]
theorem prod_Ico_castAdd (m : ℕ) (f : Fin (n + m) → M) (a b : Fin n) :
∏ i ∈ Ico (a.castAdd m) (b.castAdd m), f i = ∏ i ∈ Ico a b, f (i.castAdd m) := by
simp [← map_castAddEmb_Ico]
@[to_additive]
theorem prod_Ioc_castAdd (m : ℕ) (f : Fin (n + m) → M) (a b : Fin n) :
∏ i ∈ Ioc (a.castAdd m) (b.castAdd m), f i = ∏ i ∈ Ioc a b, f (i.castAdd m) := by
simp [← map_castAddEmb_Ioc]
@[to_additive]
theorem prod_Ioo_castAdd (m : ℕ) (f : Fin (n + m) → M) (a b : Fin n) :
∏ i ∈ Ioo (a.castAdd m) (b.castAdd m), f i = ∏ i ∈ Ioo a b, f (i.castAdd m) := by
simp [← map_castAddEmb_Ioo]
@[to_additive]
theorem prod_uIcc_castAdd (m : ℕ) (f : Fin (n + m) → M) (a b : Fin n) :
∏ i ∈ uIcc (a.castAdd m) (b.castAdd m), f i = ∏ i ∈ uIcc a b, f (i.castAdd m) := by
simp [← map_castAddEmb_uIcc]
@[to_additive]
theorem prod_Iic_castAdd (m : ℕ) (f : Fin (n + m) → M) (a : Fin n) :
∏ i ≤ a.castAdd m, f i = ∏ i ≤ a, f (i.castAdd m) := by
simp [← map_castAddEmb_Iic]
@[to_additive]
theorem prod_Iio_castAdd (m : ℕ) (f : Fin (n + m) → M) (a : Fin n) :
∏ i < a.castAdd m, f i = ∏ i < a, f (i.castAdd m) := by
simp [← map_castAddEmb_Iio]
end castAdd
/-!
### Products over intervals: `Fin.castSucc`
-/
section castSucc
@[to_additive]
theorem prod_Icc_castSucc (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Icc a.castSucc b.castSucc, f i = ∏ i ∈ Icc a b, f i.castSucc := by
simp [← map_castSuccEmb_Icc]
@[to_additive]
theorem prod_Ico_castSucc (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ico a.castSucc b.castSucc, f i = ∏ i ∈ Ico a b, f i.castSucc := by
simp [← map_castSuccEmb_Ico]
@[to_additive]
theorem prod_Ioc_castSucc (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ioc a.castSucc b.castSucc, f i = ∏ i ∈ Ioc a b, f i.castSucc := by
simp [← map_castSuccEmb_Ioc]
@[to_additive]
theorem prod_Ioo_castSucc (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ioo a.castSucc b.castSucc, f i = ∏ i ∈ Ioo a b, f i.castSucc := by
simp [← map_castSuccEmb_Ioo]
@[to_additive]
theorem prod_uIcc_castSucc (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ uIcc a.castSucc b.castSucc, f i = ∏ i ∈ uIcc a b, f i.castSucc := by
simp [← map_castSuccEmb_uIcc]
@[to_additive]
theorem prod_Iic_castSucc (f : Fin (n + 1) → M) (a : Fin n) :
∏ i ≤ a.castSucc, f i = ∏ i ≤ a, f i.castSucc := by
simp [← map_castSuccEmb_Iic]
@[to_additive]
theorem prod_Iio_castSucc (f : Fin (n + 1) → M) (a : Fin n) :
∏ i < a.castSucc, f i = ∏ i < a, f i.castSucc := by
simp [← map_castSuccEmb_Iio]
end castSucc
/-!
### Products over intervals: `Fin.succ`
-/
section succ
@[to_additive]
theorem prod_Icc_succ (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Icc a.succ b.succ, f i = ∏ i ∈ Icc a b, f i.succ := by
simp [← map_succEmb_Icc]
@[to_additive]
theorem prod_Ico_succ (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ico a.succ b.succ, f i = ∏ i ∈ Ico a b, f i.succ := by
simp [← map_succEmb_Ico]
@[to_additive]
theorem prod_Ioc_succ (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ioc a.succ b.succ, f i = ∏ i ∈ Ioc a b, f i.succ := by
simp [← map_succEmb_Ioc]
@[to_additive]
theorem prod_Ioo_succ (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ Ioo a.succ b.succ, f i = ∏ i ∈ Ioo a b, f i.succ := by
simp [← map_succEmb_Ioo]
@[to_additive]
theorem prod_uIcc_succ (f : Fin (n + 1) → M) (a b : Fin n) :
∏ i ∈ uIcc a.succ b.succ, f i = ∏ i ∈ uIcc a b, f i.succ := by
simp [← map_succEmb_uIcc]
@[to_additive]
theorem prod_Ici_succ (f : Fin (n + 1) → M) (a : Fin n) :
∏ i ≥ a.succ, f i = ∏ i ≥ a, f i.succ := by
simp [← map_succEmb_Ici]
@[to_additive (attr := simp)]
theorem prod_Ioi_succ (f : Fin (n + 1) → M) (a : Fin n) :
∏ i > a.succ, f i = ∏ i > a, f i.succ := by
simp [← map_succEmb_Ioi]
@[to_additive]
theorem prod_Ioi_zero (f : Fin (n + 1) → M) :
∏ i > 0, f i = ∏ j : Fin n, f j.succ := by
simp [Ioi_zero_eq_map]
end succ
end CommMonoid
theorem sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [CommSemiring R] (a b : R) :
(∑ s : Finset (Fin n), a ^ s.card * b ^ (n - s.card)) = (a + b) ^ n := by
simpa using Fintype.sum_pow_mul_eq_add_pow (Fin n) a b
lemma sum_neg_one_pow (R : Type*) [Ring R] (m : ℕ) :
(∑ n : Fin m, (-1) ^ n.1 : R) = if Even m then 0 else 1 := by
induction m with
| zero => simp
| succ n IH =>
simp only [Fin.sum_univ_castSucc, Fin.coe_castSucc, IH, Fin.val_last, Nat.even_add_one, ite_not]
split_ifs with h
· simp [*]
· simp [(Nat.not_even_iff_odd.mp h).neg_pow]
section PartialProd
variable [Monoid M] {n : ℕ}
/-- For `f = (a₁, ..., aₙ)` in `αⁿ`, `partialProd f` is `(1, a₁, a₁a₂, ..., a₁...aₙ)` in `αⁿ⁺¹`. -/
@[to_additive /-- For `f = (a₁, ..., aₙ)` in `αⁿ`, `partialSum f` is
`(0, a₁, a₁ + a₂, ..., a₁ + ... + aₙ)` in `αⁿ⁺¹`. -/]
def partialProd (f : Fin n → M) (i : Fin (n + 1)) : M :=
((List.ofFn f).take i).prod
@[to_additive (attr := simp)]
theorem partialProd_zero (f : Fin n → M) : partialProd f 0 = 1 := by simp [partialProd]
@[to_additive]
theorem partialProd_succ (f : Fin n → M) (j : Fin n) :
partialProd f j.succ = partialProd f (Fin.castSucc j) * f j := by
simp [partialProd, List.take_succ]
@[to_additive]
theorem partialProd_succ' (f : Fin (n + 1) → M) (j : Fin (n + 1)) :
partialProd f j.succ = f 0 * partialProd (Fin.tail f) j := by
simp [partialProd]
rfl
@[to_additive]
lemma partialProd_init {f : Fin (n + 1) → M} (i : Fin (n + 1)) :
partialProd (init f) i = partialProd f i.castSucc :=
i.inductionOn (by simp) fun i hi => by simp_all [init, partialProd_succ]
@[to_additive]
theorem partialProd_left_inv {G : Type*} [Group G] (f : Fin (n + 1) → G) :
(f 0 • partialProd fun i : Fin n => (f i.castSucc)⁻¹ * f i.succ) = f :=
funext fun x => Fin.inductionOn x (by simp) fun x hx => by
simp only [Pi.smul_apply, smul_eq_mul] at hx ⊢
rw [partialProd_succ, ← mul_assoc, hx, mul_inv_cancel_left]
@[to_additive]
theorem partialProd_right_inv {G : Type*} [Group G] (f : Fin n → G) (i : Fin n) :
(partialProd f (Fin.castSucc i))⁻¹ * partialProd f i.succ = f i := by
rw [partialProd_succ, inv_mul_cancel_left]
@[to_additive]
lemma partialProd_contractNth {G : Type*} [Monoid G] {n : ℕ}
(g : Fin (n + 1) → G) (a : Fin (n + 1)) :
partialProd (contractNth a (· * ·) g) = partialProd g ∘ a.succ.succAbove := by
ext i
refine inductionOn i ?_ ?_
· simp only [partialProd_zero, Function.comp_apply, succ_succAbove_zero]
· intro i hi
simp only [Function.comp_apply, succ_succAbove_succ] at *
rw [partialProd_succ, partialProd_succ, hi]
rcases lt_trichotomy (i : ℕ) a with (h | h | h)
· rw [succAbove_of_castSucc_lt, contractNth_apply_of_lt _ _ _ _ h,
succAbove_of_castSucc_lt] <;>
simp only [lt_def, coe_castSucc, val_succ] <;>
omega
· rw [succAbove_of_castSucc_lt, contractNth_apply_of_eq _ _ _ _ h,
succAbove_of_le_castSucc, castSucc_fin_succ, partialProd_succ, mul_assoc] <;>
simp only [castSucc_lt_succ_iff, le_def, coe_castSucc] <;>
omega
· rw [succAbove_of_le_castSucc, succAbove_of_le_castSucc, contractNth_apply_of_gt _ _ _ _ h,
castSucc_fin_succ] <;>
simp only [le_def, val_succ, coe_castSucc] <;>
omega
/-- Let `(g₀, g₁, ..., gₙ)` be a tuple of elements in `Gⁿ⁺¹`.
Then if `k < j`, this says `(g₀g₁...gₖ₋₁)⁻¹ * g₀g₁...gₖ = gₖ`.
If `k = j`, it says `(g₀g₁...gₖ₋₁)⁻¹ * g₀g₁...gₖ₊₁ = gₖgₖ₊₁`.
If `k > j`, it says `(g₀g₁...gₖ)⁻¹ * g₀g₁...gₖ₊₁ = gₖ₊₁.`
Useful for defining group cohomology. -/
@[to_additive
/-- Let `(g₀, g₁, ..., gₙ)` be a tuple of elements in `Gⁿ⁺¹`.
Then if `k < j`, this says `-(g₀ + g₁ + ... + gₖ₋₁) + (g₀ + g₁ + ... + gₖ) = gₖ`.
If `k = j`, it says `-(g₀ + g₁ + ... + gₖ₋₁) + (g₀ + g₁ + ... + gₖ₊₁) = gₖ + gₖ₊₁`.
If `k > j`, it says `-(g₀ + g₁ + ... + gₖ) + (g₀ + g₁ + ... + gₖ₊₁) = gₖ₊₁.`
Useful for defining group cohomology. -/]
theorem inv_partialProd_mul_eq_contractNth {G : Type*} [Group G] (g : Fin (n + 1) → G)
(j : Fin (n + 1)) (k : Fin n) :
(partialProd g (j.succ.succAbove (Fin.castSucc k)))⁻¹ * partialProd g (j.succAbove k).succ =
j.contractNth (· * ·) g k := by
rcases lt_trichotomy (k : ℕ) j with (h | h | h)
· rwa [succAbove_of_castSucc_lt, succAbove_of_castSucc_lt, partialProd_right_inv,
contractNth_apply_of_lt]
· assumption
· rw [castSucc_lt_iff_succ_le, succ_le_succ_iff, le_iff_val_le_val]
exact le_of_lt h
· rwa [succAbove_of_castSucc_lt, succAbove_of_le_castSucc, partialProd_succ,
castSucc_fin_succ, ← mul_assoc,
partialProd_right_inv, contractNth_apply_of_eq]
· simp [le_iff_val_le_val, ← h]
· rw [castSucc_lt_iff_succ_le, succ_le_succ_iff, le_iff_val_le_val]
exact le_of_eq h
· rwa [succAbove_of_le_castSucc, succAbove_of_le_castSucc, partialProd_succ, partialProd_succ,
castSucc_fin_succ, partialProd_succ, inv_mul_cancel_left, contractNth_apply_of_gt]
· exact le_iff_val_le_val.2 (le_of_lt h)
· rw [le_iff_val_le_val, val_succ]
exact Nat.succ_le_of_lt h
end PartialProd
end Fin
/-- Equivalence between `Fin n → Fin m` and `Fin (m ^ n)`. -/
@[simps!]
def finFunctionFinEquiv {m n : ℕ} : (Fin n → Fin m) ≃ Fin (m ^ n) :=
Equiv.ofRightInverseOfCardLE (le_of_eq <| by simp_rw [Fintype.card_fun, Fintype.card_fin])
(fun f => ⟨∑ i, f i * m ^ (i : ℕ), by
induction n with
| zero => simp
| succ n ih =>
cases m
· exact isEmptyElim (f <| Fin.last _)
simp_rw [Fin.sum_univ_castSucc, Fin.coe_castSucc, Fin.val_last]
refine (Nat.add_lt_add_of_lt_of_le (ih _) <| Nat.mul_le_mul_right _
(Fin.is_le _)).trans_eq ?_
rw [← one_add_mul (_ : ℕ), add_comm, pow_succ']⟩)
(fun a b => ⟨a / m ^ (b : ℕ) % m, by
rcases n with - | n
· exact b.elim0
rcases m with - | m
· rw [zero_pow n.succ_ne_zero] at a
exact a.elim0
· exact Nat.mod_lt _ m.succ_pos⟩)
fun a => by
dsimp
induction n with
| zero => subsingleton [(finCongr <| pow_zero _).subsingleton]
| succ n ih =>
simp_rw [Fin.forall_iff, Fin.ext_iff] at ih
ext
simp_rw [Fin.sum_univ_succ, Fin.val_zero, Fin.val_succ, pow_zero, Nat.div_one,
mul_one, pow_succ', ← Nat.div_div_eq_div_mul, mul_left_comm _ m, ← mul_sum]
rw [ih _ (Nat.div_lt_of_lt_mul (a.is_lt.trans_eq (pow_succ' _ _))), Nat.mod_add_div]
theorem finFunctionFinEquiv_apply {m n : ℕ} (f : Fin n → Fin m) :
(finFunctionFinEquiv f : ℕ) = ∑ i : Fin n, ↑(f i) * m ^ (i : ℕ) :=
rfl
theorem finFunctionFinEquiv_single {m n : ℕ} [NeZero m] (i : Fin n) (j : Fin m) :
(finFunctionFinEquiv (Pi.single i j) : ℕ) = j * m ^ (i : ℕ) := by
rw [finFunctionFinEquiv_apply, Fintype.sum_eq_single i, Pi.single_eq_same]
rintro x hx
rw [Pi.single_eq_of_ne hx, Fin.val_zero, zero_mul]
/-- Equivalence between `∀ i : Fin m, Fin (n i)` and `Fin (∏ i : Fin m, n i)`. -/
def finPiFinEquiv {m : ℕ} {n : Fin m → ℕ} : (∀ i : Fin m, Fin (n i)) ≃ Fin (∏ i : Fin m, n i) :=
Equiv.ofRightInverseOfCardLE (le_of_eq <| by simp_rw [Fintype.card_pi, Fintype.card_fin])
(fun f => ⟨∑ i, f i * ∏ j, n (Fin.castLE i.is_lt.le j), by
induction m with
| zero => simp
| succ m ih =>
rw [Fin.prod_univ_castSucc, Fin.sum_univ_castSucc]
suffices
∀ (n : Fin m → ℕ) (nn : ℕ) (f : ∀ i : Fin m, Fin (n i)) (fn : Fin nn),
((∑ i : Fin m, ↑(f i) * ∏ j : Fin i, n (Fin.castLE i.prop.le j)) + ↑fn * ∏ j, n j) <
(∏ i : Fin m, n i) * nn by
solve_by_elim
intro n nn f fn
cases nn
· exact isEmptyElim fn
refine (Nat.add_lt_add_of_lt_of_le (ih _) <| Nat.mul_le_mul_right _ (Fin.is_le _)).trans_eq ?_
rw [← one_add_mul (_ : ℕ), mul_comm, add_comm]⟩)
(fun a b => ⟨(a / ∏ j : Fin b, n (Fin.castLE b.is_lt.le j)) % n b, by
cases m
· exact b.elim0
rcases h : n b with nb | nb
· rw [prod_eq_zero (Finset.mem_univ _) h] at a
exact isEmptyElim a
exact Nat.mod_lt _ nb.succ_pos⟩)
(by
intro a; revert a; dsimp only [Fin.val_mk]
refine Fin.consInduction ?_ ?_ n
· intro a
have : Subsingleton (Fin (∏ i : Fin 0, i.elim0)) :=
(finCongr <| prod_empty).subsingleton
subsingleton
· intro n x xs ih a
simp_rw [Fin.forall_iff, Fin.ext_iff] at ih
ext
simp_rw [Fin.sum_univ_succ, Fin.cons_succ]
have := fun i : Fin n =>
Fintype.prod_equiv (finCongr <| Fin.val_succ i)
(fun j => (Fin.cons x xs : _ → ℕ) (Fin.castLE (Fin.is_lt _).le j))
(fun j => (Fin.cons x xs : _ → ℕ) (Fin.castLE (Nat.succ_le_succ (Fin.is_lt _).le) j))
fun j => rfl
simp_rw [this]
clear this
simp_rw [Fin.val_zero, Fintype.prod_empty, Nat.div_one, mul_one, Fin.cons_zero,
Fin.prod_univ_succ, Fin.castLE_zero, Fin.cons_zero, ← Nat.div_div_eq_div_mul,
mul_left_comm (_ % _ : ℕ), ← mul_sum]
convert Nat.mod_add_div _ _
exact ih (a / x) (Nat.div_lt_of_lt_mul <| a.is_lt.trans_eq (Fin.prod_univ_succ _)))
theorem finPiFinEquiv_apply {m : ℕ} {n : Fin m → ℕ} (f : ∀ i : Fin m, Fin (n i)) :
(finPiFinEquiv f : ℕ) = ∑ i, f i * ∏ j, n (Fin.castLE i.is_lt.le j) := rfl
theorem finPiFinEquiv_single {m : ℕ} {n : Fin m → ℕ} [∀ i, NeZero (n i)] (i : Fin m)
(j : Fin (n i)) :
(finPiFinEquiv (Pi.single i j : ∀ i : Fin m, Fin (n i)) : ℕ) =
j * ∏ j, n (Fin.castLE i.is_lt.le j) := by
rw [finPiFinEquiv_apply, Fintype.sum_eq_single i, Pi.single_eq_same]
rintro x hx
rw [Pi.single_eq_of_ne hx, Fin.val_zero, zero_mul]
/-- Equivalence between the Sigma type `(i : Fin m) × Fin (n i)` and `Fin (∑ i : Fin m, n i)`. -/
def finSigmaFinEquiv {m : ℕ} {n : Fin m → ℕ} : (i : Fin m) × Fin (n i) ≃ Fin (∑ i : Fin m, n i) :=
match m with
| 0 => @Equiv.equivOfIsEmpty _ _ _ (by simp; exact Fin.isEmpty')
| Nat.succ m =>
calc _ ≃ _ := (@finSumFinEquiv m 1).sigmaCongrLeft.symm
_ ≃ _ := Equiv.sumSigmaDistrib _
_ ≃ _ := finSigmaFinEquiv.sumCongr (Equiv.uniqueSigma _)
_ ≃ _ := finSumFinEquiv
_ ≃ _ := finCongr (Fin.sum_univ_castSucc n).symm
@[simp]
theorem finSigmaFinEquiv_apply {m : ℕ} {n : Fin m → ℕ} (k : (i : Fin m) × Fin (n i)) :
(finSigmaFinEquiv k : ℕ) = ∑ i : Fin k.1, n (Fin.castLE k.1.2.le i) + k.2 := by
induction m with
| zero => exact k.fst.elim0
| succ m ih =>
rcases k with ⟨⟨iv, hi⟩, j⟩
rw [finSigmaFinEquiv]
unfold finSumFinEquiv
simp only [Equiv.coe_fn_mk, Equiv.sigmaCongrLeft, Equiv.coe_fn_symm_mk, Equiv.trans_def,
Equiv.trans_apply, finCongr_apply, Fin.coe_cast]
conv =>
enter [1,1,3]
apply Equiv.sumCongr_apply
by_cases him : iv < m
· conv in Sigma.mk _ _ =>
equals ⟨Sum.inl ⟨iv, him⟩, j⟩ => simp [Fin.addCases, him]
simpa using ih _
· replace him := Nat.eq_of_lt_succ_of_not_lt hi him
subst him
conv in Sigma.mk _ _ =>
equals ⟨Sum.inr 0, j⟩ => simp [Fin.addCases, Fin.natAdd]
simp
rfl
/-- `finSigmaFinEquiv` on `Fin 1 × f` is just `f` -/
theorem finSigmaFinEquiv_one {n : Fin 1 → ℕ} (ij : (i : Fin 1) × Fin (n i)) :
(finSigmaFinEquiv ij : ℕ) = ij.2 := by
rw [finSigmaFinEquiv_apply, add_eq_right]
apply @Finset.sum_of_isEmpty _ _ _ _ (by simpa using Fin.isEmpty')
namespace List
section CommMonoid
variable [CommMonoid M]
@[to_additive]
theorem prod_take_ofFn {n : ℕ} (f : Fin n → M) (i : ℕ) :
((ofFn f).take i).prod = ∏ j with j.val < i, f j := by
induction i with
| zero =>
simp
| succ i IH =>
by_cases h : i < n
· have : i < length (ofFn f) := by rwa [length_ofFn]
rw [prod_take_succ _ _ this]
have A : ({j | j.val < i + 1} : Finset (Fin n)) =
insert ⟨i, h⟩ ({j | Fin.val j < i} : Finset (Fin n)) := by
ext ⟨_, _⟩
simp [Nat.lt_succ_iff_lt_or_eq, or_comm]
rw [A, prod_insert (by simp), IH, mul_comm]
simp
· have A : (ofFn f).take i = (ofFn f).take i.succ := by
rw [← length_ofFn (f := f)] at h
have : length (ofFn f) ≤ i := not_lt.mp h
rw [take_of_length_le this, take_of_length_le (le_trans this (Nat.le_succ _))]
have B : ∀ j : Fin n, ((j : ℕ) < i.succ) = ((j : ℕ) < i) := by
intro j
have : (j : ℕ) < i := lt_of_lt_of_le j.2 (not_lt.mp h)
simp [this, lt_trans this (Nat.lt_succ_self _)]
simp [← A, B, IH]
@[to_additive]
theorem prod_ofFn {n : ℕ} {f : Fin n → M} : (ofFn f).prod = ∏ i, f i :=
Fin.prod_ofFn f
end CommMonoid
@[to_additive]
theorem alternatingProd_eq_finset_prod {G : Type*} [DivisionCommMonoid G] :
∀ (L : List G), alternatingProd L = ∏ i : Fin L.length, L[i] ^ (-1 : ℤ) ^ (i : ℕ)
| [] => by
rw [alternatingProd, Finset.prod_eq_one]
rintro ⟨i, ⟨⟩⟩
| g::[] => by
change g = ∏ i : Fin 1, [g][i] ^ (-1 : ℤ) ^ (i : ℕ)
rw [Fin.prod_univ_succ]; simp
| g::h::L =>
calc g * h⁻¹ * L.alternatingProd
= g * h⁻¹ * ∏ i : Fin L.length, L[i] ^ (-1 : ℤ) ^ (i : ℕ) :=
congr_arg _ (alternatingProd_eq_finset_prod _)
_ = ∏ i : Fin (L.length + 2), (g::h::L)[i] ^ (-1 : ℤ) ^ (i : ℕ) := by
{ rw [Fin.prod_univ_succ, Fin.prod_univ_succ, mul_assoc]
simp [pow_add]}
end List
|
GDelta.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import Mathlib.Topology.Compactness.Lindelof
import Mathlib.Topology.Compactness.SigmaCompact
import Mathlib.Topology.Connected.TotallyDisconnected
import Mathlib.Topology.Inseparable
import Mathlib.Topology.Separation.Regular
import Mathlib.Topology.GDelta.Basic
/-!
# Separation properties of topological spaces.
## Main definitions
* `PerfectlyNormalSpace`: A perfectly normal space is a normal space such that
closed sets are Gδ.
* `T6Space`: A T₆ space is a perfectly normal T₀ space. T₆ implies T₅.
Note that `mathlib` adopts the modern convention that `m ≤ n` if and only if `T_m → T_n`, but
occasionally the literature swaps definitions for e.g. T₃ and regular.
-/
open Function Set Filter Topology TopologicalSpace
universe u
variable {X : Type*} [TopologicalSpace X]
section Separation
theorem IsGδ.compl_singleton (x : X) [T1Space X] : IsGδ ({x}ᶜ : Set X) :=
isOpen_compl_singleton.isGδ
theorem Set.Countable.isGδ_compl {s : Set X} [T1Space X] (hs : s.Countable) : IsGδ sᶜ := by
rw [← biUnion_of_singleton s, compl_iUnion₂]
exact .biInter hs fun x _ => .compl_singleton x
theorem Set.Finite.isGδ_compl {s : Set X} [T1Space X] (hs : s.Finite) : IsGδ sᶜ :=
hs.countable.isGδ_compl
theorem Set.Subsingleton.isGδ_compl {s : Set X} [T1Space X] (hs : s.Subsingleton) : IsGδ sᶜ :=
hs.finite.isGδ_compl
theorem Finset.isGδ_compl [T1Space X] (s : Finset X) : IsGδ (sᶜ : Set X) :=
s.finite_toSet.isGδ_compl
protected theorem IsGδ.singleton [FirstCountableTopology X] [T1Space X] (x : X) :
IsGδ ({x} : Set X) := by
rcases (nhds_basis_opens x).exists_antitone_subbasis with ⟨U, hU, h_basis⟩
rw [← biInter_basis_nhds h_basis.toHasBasis]
exact .biInter (to_countable _) fun n _ => (hU n).2.isGδ
theorem Set.Finite.isGδ [FirstCountableTopology X] {s : Set X} [T1Space X] (hs : s.Finite) :
IsGδ s :=
Finite.induction_on _ hs .empty fun _ _ ↦ .union (.singleton _)
section PerfectlyNormal
/-- A topological space `X` is a *perfectly normal space* provided it is normal and
closed sets are Gδ. -/
class PerfectlyNormalSpace (X : Type u) [TopologicalSpace X] : Prop extends NormalSpace X where
closed_gdelta : ∀ ⦃h : Set X⦄, IsClosed h → IsGδ h
/-- Lemma that allows the easy conclusion that perfectly normal spaces are completely normal. -/
theorem Disjoint.hasSeparatingCover_closed_gdelta_right {s t : Set X} [NormalSpace X]
(st_dis : Disjoint s t) (t_cl : IsClosed t) (t_gd : IsGδ t) : HasSeparatingCover s t := by
obtain ⟨T, T_open, T_count, T_int⟩ := t_gd
rcases T.eq_empty_or_nonempty with rfl | T_nonempty
· rw [T_int, sInter_empty] at st_dis
rw [(s.disjoint_univ).mp st_dis]
exact t.hasSeparatingCover_empty_left
obtain ⟨g, g_surj⟩ := T_count.exists_surjective T_nonempty
choose g' g'_open clt_sub_g' clg'_sub_g using fun n ↦ by
apply normal_exists_closure_subset t_cl (T_open (g n).1 (g n).2)
rw [T_int]
exact sInter_subset_of_mem (g n).2
have clg'_int : t = ⋂ i, closure (g' i) := by
apply (subset_iInter fun n ↦ (clt_sub_g' n).trans subset_closure).antisymm
rw [T_int]
refine subset_sInter fun t tinT ↦ ?_
obtain ⟨n, gn⟩ := g_surj ⟨t, tinT⟩
refine iInter_subset_of_subset n <| (clg'_sub_g n).trans ?_
rw [gn]
use fun n ↦ (closure (g' n))ᶜ
constructor
· rw [← compl_iInter, subset_compl_comm, ← clg'_int]
exact st_dis.subset_compl_left
· refine fun n ↦ ⟨isOpen_compl_iff.mpr isClosed_closure, ?_⟩
simp only [closure_compl, disjoint_compl_left_iff_subset]
rw [← closure_eq_iff_isClosed.mpr t_cl] at clt_sub_g'
exact subset_closure.trans <| (clt_sub_g' n).trans <| (g'_open n).subset_interior_closure
instance (priority := 100) PerfectlyNormalSpace.toCompletelyNormalSpace
[PerfectlyNormalSpace X] : CompletelyNormalSpace X where
completely_normal _ _ hd₁ hd₂ := separatedNhds_iff_disjoint.mp <|
hasSeparatingCovers_iff_separatedNhds.mp
⟨(hd₂.hasSeparatingCover_closed_gdelta_right isClosed_closure <|
closed_gdelta isClosed_closure).mono (fun ⦃_⦄ a ↦ a) subset_closure,
((Disjoint.symm hd₁).hasSeparatingCover_closed_gdelta_right isClosed_closure <|
closed_gdelta isClosed_closure).mono (fun ⦃_⦄ a ↦ a) subset_closure⟩
/-- In a perfectly normal space, all closed sets are Gδ. -/
theorem IsClosed.isGδ [PerfectlyNormalSpace X] {s : Set X} (hs : IsClosed s) : IsGδ s :=
PerfectlyNormalSpace.closed_gdelta hs
instance (priority := 100) [PerfectlyNormalSpace X] : R0Space X where
specializes_symmetric x y hxy := by
rw [specializes_iff_forall_closed]
intro K hK hyK
apply IsClosed.isGδ at hK
obtain ⟨Ts, hoTs, -, rfl⟩ := hK
rw [mem_sInter] at hyK ⊢
intros
solve_by_elim [hxy.mem_open]
/-- A T₆ space is a perfectly normal T₀ space. -/
class T6Space (X : Type u) [TopologicalSpace X] : Prop extends T0Space X, PerfectlyNormalSpace X
-- see Note [lower instance priority]
/-- A `T₆` space is a `T₅` space. -/
instance (priority := 100) T6Space.toT5Space [T6Space X] : T5Space X where
end PerfectlyNormal
end Separation
|
Basic.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Logic.Function.Defs
import Mathlib.Logic.Function.Basic
/-!
# Sigma types
This file proves basic results about sigma types.
A sigma type is a dependent pair type. Like `α × β` but where the type of the second component
depends on the first component. More precisely, given `β : ι → Type*`, `Sigma β` is made of stuff
which is of type `β i` for some `i : ι`, so the sigma type is a disjoint union of types.
For example, the sum type `X ⊕ Y` can be emulated using a sigma type, by taking `ι` with
exactly two elements (see `Equiv.sumEquivSigmaBool`).
`Σ x, A x` is notation for `Sigma A` (note that this is `\Sigma`, not the sum operator `∑`).
`Σ x y z ..., A x y z ...` is notation for `Σ x, Σ y, Σ z, ..., A x y z ...`. Here we have
`α : Type*`, `β : α → Type*`, `γ : Π a : α, β a → Type*`, ...,
`A : Π (a : α) (b : β a) (c : γ a b) ..., Type*` with `x : α` `y : β x`, `z : γ x y`, ...
## Notes
The definition of `Sigma` takes values in `Type*`. This effectively forbids `Prop`- valued sigma
types. To that effect, we have `PSigma`, which takes value in `Sort*` and carries a more
complicated universe signature as a consequence.
-/
open Function
section Sigma
variable {α α₁ α₂ : Type*} {β : α → Type*} {β₁ : α₁ → Type*} {β₂ : α₂ → Type*}
namespace Sigma
instance instInhabitedSigma [Inhabited α] [Inhabited (β default)] : Inhabited (Sigma β) :=
⟨⟨default, default⟩⟩
instance instDecidableEqSigma [h₁ : DecidableEq α] [h₂ : ∀ a, DecidableEq (β a)] :
DecidableEq (Sigma β)
| ⟨a₁, b₁⟩, ⟨a₂, b₂⟩ =>
match a₁, b₁, a₂, b₂, h₁ a₁ a₂ with
| _, b₁, _, b₂, isTrue (Eq.refl _) =>
match b₁, b₂, h₂ _ b₁ b₂ with
| _, _, isTrue (Eq.refl _) => isTrue rfl
| _, _, isFalse n => isFalse fun h ↦ Sigma.noConfusion h fun _ e₂ ↦ n <| eq_of_heq e₂
| _, _, _, _, isFalse n => isFalse fun h ↦ Sigma.noConfusion h fun e₁ _ ↦ n e₁
theorem mk.inj_iff {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂} :
Sigma.mk a₁ b₁ = ⟨a₂, b₂⟩ ↔ a₁ = a₂ ∧ b₁ ≍ b₂ := by simp
@[simp]
theorem eta : ∀ x : Σ a, β a, Sigma.mk x.1 x.2 = x
| ⟨_, _⟩ => rfl
protected theorem eq {α : Type*} {β : α → Type*} : ∀ {p₁ p₂ : Σ a, β a} (h₁ : p₁.1 = p₂.1),
(Eq.recOn h₁ p₁.2 : β p₂.1) = p₂.2 → p₁ = p₂
| ⟨_, _⟩, _, rfl, rfl => rfl
/-- A version of `Iff.mp Sigma.ext_iff` for functions from a nonempty type to a sigma type. -/
theorem _root_.Function.eq_of_sigmaMk_comp {γ : Type*} [Nonempty γ]
{a b : α} {f : γ → β a} {g : γ → β b} (h : Sigma.mk a ∘ f = Sigma.mk b ∘ g) :
a = b ∧ f ≍ g := by
rcases ‹Nonempty γ› with ⟨i⟩
obtain rfl : a = b := congr_arg Sigma.fst (congr_fun h i)
simpa [funext_iff] using h
/-- A specialized ext lemma for equality of sigma types over an indexed subtype. -/
@[ext]
theorem subtype_ext {β : Type*} {p : α → β → Prop} :
∀ {x₀ x₁ : Σ a, Subtype (p a)}, x₀.fst = x₁.fst → (x₀.snd : β) = x₁.snd → x₀ = x₁
| ⟨_, _, _⟩, ⟨_, _, _⟩, rfl, rfl => rfl
-- This is not a good simp lemma, as its discrimination tree key is just an arrow.
theorem «forall» {p : (Σ a, β a) → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ :=
⟨fun h a b ↦ h ⟨a, b⟩, fun h ⟨a, b⟩ ↦ h a b⟩
@[simp]
theorem «exists» {p : (Σ a, β a) → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ :=
⟨fun ⟨⟨a, b⟩, h⟩ ↦ ⟨a, b, h⟩, fun ⟨a, b, h⟩ ↦ ⟨⟨a, b⟩, h⟩⟩
lemma exists' {p : ∀ a, β a → Prop} : (∃ a b, p a b) ↔ ∃ x : Σ a, β a, p x.1 x.2 :=
(Sigma.exists (p := fun x ↦ p x.1 x.2)).symm
lemma forall' {p : ∀ a, β a → Prop} : (∀ a b, p a b) ↔ ∀ x : Σ a, β a, p x.1 x.2 :=
(Sigma.forall (p := fun x ↦ p x.1 x.2)).symm
theorem _root_.sigma_mk_injective {i : α} : Injective (@Sigma.mk α β i)
| _, _, rfl => rfl
theorem fst_surjective [h : ∀ a, Nonempty (β a)] : Surjective (fst : (Σ a, β a) → α) := fun a ↦
let ⟨b⟩ := h a; ⟨⟨a, b⟩, rfl⟩
theorem fst_surjective_iff : Surjective (fst : (Σ a, β a) → α) ↔ ∀ a, Nonempty (β a) :=
⟨fun h a ↦ let ⟨x, hx⟩ := h a; hx ▸ ⟨x.2⟩, @fst_surjective _ _⟩
theorem fst_injective [h : ∀ a, Subsingleton (β a)] : Injective (fst : (Σ a, β a) → α) := by
rintro ⟨a₁, b₁⟩ ⟨a₂, b₂⟩ (rfl : a₁ = a₂)
exact congr_arg (mk a₁) <| Subsingleton.elim _ _
theorem fst_injective_iff : Injective (fst : (Σ a, β a) → α) ↔ ∀ a, Subsingleton (β a) :=
⟨fun h _ ↦ ⟨fun _ _ ↦ sigma_mk_injective <| h rfl⟩, @fst_injective _ _⟩
/-- Map the left and right components of a sigma -/
def map (f₁ : α₁ → α₂) (f₂ : ∀ a, β₁ a → β₂ (f₁ a)) (x : Sigma β₁) : Sigma β₂ :=
⟨f₁ x.1, f₂ x.1 x.2⟩
lemma map_mk (f₁ : α₁ → α₂) (f₂ : ∀ a, β₁ a → β₂ (f₁ a)) (x : α₁) (y : β₁ x) :
map f₁ f₂ ⟨x, y⟩ = ⟨f₁ x, f₂ x y⟩ := rfl
end Sigma
theorem Function.Injective.sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Injective f₁) (h₂ : ∀ a, Injective (f₂ a)) : Injective (Sigma.map f₁ f₂)
| ⟨i, x⟩, ⟨j, y⟩, h => by
obtain rfl : i = j := h₁ (Sigma.mk.inj_iff.mp h).1
obtain rfl : x = y := h₂ i (sigma_mk_injective h)
rfl
theorem Function.Injective.of_sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h : Injective (Sigma.map f₁ f₂)) (a : α₁) : Injective (f₂ a) := fun x y hxy ↦
sigma_mk_injective <| @h ⟨a, x⟩ ⟨a, y⟩ (Sigma.ext rfl (heq_of_eq hxy))
theorem Function.Injective.sigma_map_iff {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Injective f₁) : Injective (Sigma.map f₁ f₂) ↔ ∀ a, Injective (f₂ a) :=
⟨fun h ↦ h.of_sigma_map, h₁.sigma_map⟩
theorem Function.Surjective.sigma_map {f₁ : α₁ → α₂} {f₂ : ∀ a, β₁ a → β₂ (f₁ a)}
(h₁ : Surjective f₁) (h₂ : ∀ a, Surjective (f₂ a)) : Surjective (Sigma.map f₁ f₂) := by
simp only [Surjective, Sigma.forall, h₁.forall]
exact fun i ↦ (h₂ _).forall.2 fun x ↦ ⟨⟨i, x⟩, rfl⟩
/-- Interpret a function on `Σ x : α, β x` as a dependent function with two arguments.
This also exists as an `Equiv` as `Equiv.piCurry γ`. -/
def Sigma.curry {γ : ∀ a, β a → Type*} (f : ∀ x : Sigma β, γ x.1 x.2) (x : α) (y : β x) : γ x y :=
f ⟨x, y⟩
/-- Interpret a dependent function with two arguments as a function on `Σ x : α, β x`.
This also exists as an `Equiv` as `(Equiv.piCurry γ).symm`. -/
def Sigma.uncurry {γ : ∀ a, β a → Type*} (f : ∀ (x) (y : β x), γ x y) (x : Sigma β) : γ x.1 x.2 :=
f x.1 x.2
@[simp]
theorem Sigma.uncurry_curry {γ : ∀ a, β a → Type*} (f : ∀ x : Sigma β, γ x.1 x.2) :
Sigma.uncurry (Sigma.curry f) = f :=
funext fun ⟨_, _⟩ ↦ rfl
@[simp]
theorem Sigma.curry_uncurry {γ : ∀ a, β a → Type*} (f : ∀ (x) (y : β x), γ x y) :
Sigma.curry (Sigma.uncurry f) = f :=
rfl
theorem Sigma.curry_update {γ : ∀ a, β a → Type*} [DecidableEq α] [∀ a, DecidableEq (β a)]
(i : Σ a, β a) (f : (i : Σ a, β a) → γ i.1 i.2) (x : γ i.1 i.2) :
Sigma.curry (Function.update f i x) =
Function.update (Sigma.curry f) i.1 (Function.update (Sigma.curry f i.1) i.2 x) := by
obtain ⟨ia, ib⟩ := i
ext ja jb
unfold Sigma.curry
obtain rfl | ha := eq_or_ne ia ja
· obtain rfl | hb := eq_or_ne ib jb
· simp
· simp only [update_self]
rw [Function.update_of_ne (mt _ hb.symm), Function.update_of_ne hb.symm]
rintro h
injection h
· rw [Function.update_of_ne (ne_of_apply_ne Sigma.fst _), Function.update_of_ne]
· exact ha.symm
· exact ha.symm
/-- Convert a product type to a Σ-type. -/
def Prod.toSigma {α β} (p : α × β) : Σ _ : α, β :=
⟨p.1, p.2⟩
@[simp]
theorem Prod.fst_comp_toSigma {α β} : Sigma.fst ∘ @Prod.toSigma α β = Prod.fst :=
rfl
@[simp]
theorem Prod.fst_toSigma {α β} (x : α × β) : (Prod.toSigma x).fst = x.fst :=
rfl
@[simp]
theorem Prod.snd_toSigma {α β} (x : α × β) : (Prod.toSigma x).snd = x.snd :=
rfl
@[simp]
theorem Prod.toSigma_mk {α β} (x : α) (y : β) : (x, y).toSigma = ⟨x, y⟩ :=
rfl
end Sigma
namespace PSigma
variable {α : Sort*} {β : α → Sort*}
/-- Nondependent eliminator for `PSigma`. -/
def elim {γ} (f : ∀ a, β a → γ) (a : PSigma β) : γ :=
PSigma.casesOn a f
@[simp]
theorem elim_val {γ} (f : ∀ a, β a → γ) (a b) : PSigma.elim f ⟨a, b⟩ = f a b :=
rfl
instance [Inhabited α] [Inhabited (β default)] : Inhabited (PSigma β) :=
⟨⟨default, default⟩⟩
instance decidableEq [h₁ : DecidableEq α] [h₂ : ∀ a, DecidableEq (β a)] : DecidableEq (PSigma β)
| ⟨a₁, b₁⟩, ⟨a₂, b₂⟩ =>
match a₁, b₁, a₂, b₂, h₁ a₁ a₂ with
| _, b₁, _, b₂, isTrue (Eq.refl _) =>
match b₁, b₂, h₂ _ b₁ b₂ with
| _, _, isTrue (Eq.refl _) => isTrue rfl
| _, _, isFalse n => isFalse fun h ↦ PSigma.noConfusion h fun _ e₂ ↦ n <| eq_of_heq e₂
| _, _, _, _, isFalse n => isFalse fun h ↦ PSigma.noConfusion h fun e₁ _ ↦ n e₁
theorem mk.inj_iff {a₁ a₂ : α} {b₁ : β a₁} {b₂ : β a₂} :
@PSigma.mk α β a₁ b₁ = @PSigma.mk α β a₂ b₂ ↔ a₁ = a₂ ∧ b₁ ≍ b₂ :=
(Iff.intro PSigma.mk.inj) fun ⟨h₁, h₂⟩ ↦
match a₁, a₂, b₁, b₂, h₁, h₂ with
| _, _, _, _, Eq.refl _, HEq.refl _ => rfl
-- This should not be a simp lemma, since its discrimination tree key would just be `→`.
theorem «forall» {p : (Σ' a, β a) → Prop} : (∀ x, p x) ↔ ∀ a b, p ⟨a, b⟩ :=
⟨fun h a b ↦ h ⟨a, b⟩, fun h ⟨a, b⟩ ↦ h a b⟩
@[simp] lemma «exists» {p : (Σ' a, β a) → Prop} : (∃ x, p x) ↔ ∃ a b, p ⟨a, b⟩ :=
⟨fun ⟨⟨a, b⟩, h⟩ ↦ ⟨a, b, h⟩, fun ⟨a, b, h⟩ ↦ ⟨⟨a, b⟩, h⟩⟩
/-- A specialized ext lemma for equality of `PSigma` types over an indexed subtype. -/
@[ext]
theorem subtype_ext {β : Sort*} {p : α → β → Prop} :
∀ {x₀ x₁ : Σ' a, Subtype (p a)}, x₀.fst = x₁.fst → (x₀.snd : β) = x₁.snd → x₀ = x₁
| ⟨_, _, _⟩, ⟨_, _, _⟩, rfl, rfl => rfl
variable {α₁ : Sort*} {α₂ : Sort*} {β₁ : α₁ → Sort*} {β₂ : α₂ → Sort*}
/-- Map the left and right components of a sigma -/
def map (f₁ : α₁ → α₂) (f₂ : ∀ a, β₁ a → β₂ (f₁ a)) : PSigma β₁ → PSigma β₂
| ⟨a, b⟩ => ⟨f₁ a, f₂ a b⟩
end PSigma
|
Types.lean
|
/-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.CategoryTheory.Sites.Canonical
/-!
# Grothendieck Topology and Sheaves on the Category of Types
In this file we define a Grothendieck topology on the category of types,
and construct the canonical functor that sends a type to a sheaf over
the category of types, and make this an equivalence of categories.
Then we prove that the topology defined is the canonical topology.
-/
universe u
namespace CategoryTheory
/-- A Grothendieck topology associated to the category of all types.
A sieve is a covering iff it is jointly surjective. -/
def typesGrothendieckTopology : GrothendieckTopology (Type u) where
sieves α S := ∀ x : α, S fun _ : PUnit => x
top_mem' _ _ := trivial
pullback_stable' _ _ _ f hs x := hs (f x)
transitive' _ _ hs _ hr x := hr (hs x) PUnit.unit
/-- The discrete sieve on a type, which only includes arrows whose image is a subsingleton. -/
@[simps]
def discreteSieve (α : Type u) : Sieve α where
arrows _ f := ∃ x, ∀ y, f y = x
downward_closed := fun ⟨x, hx⟩ g => ⟨x, fun y => hx <| g y⟩
theorem discreteSieve_mem (α : Type u) : discreteSieve α ∈ typesGrothendieckTopology α :=
fun x => ⟨x, fun _ => rfl⟩
/-- The discrete presieve on a type, which only includes arrows whose domain is a singleton. -/
def discretePresieve (α : Type u) : Presieve α :=
fun β _ => ∃ x : β, ∀ y : β, y = x
theorem generate_discretePresieve_mem (α : Type u) :
Sieve.generate (discretePresieve α) ∈ typesGrothendieckTopology α :=
fun x => ⟨PUnit, id, fun _ => x, ⟨PUnit.unit, fun _ => Subsingleton.elim _ _⟩, rfl⟩
/-- The sheaf condition for `yoneda'`. -/
theorem Presieve.isSheaf_yoneda' {α : Type u} :
Presieve.IsSheaf typesGrothendieckTopology (yoneda.obj α) :=
fun β _ hs x hx =>
⟨fun y => x _ (hs y) PUnit.unit, fun γ f h =>
funext fun z => by
convert congr_fun (hx (𝟙 _) (fun _ => z) (hs <| f z) h rfl) PUnit.unit using 1,
fun f hf => funext fun y => by convert congr_fun (hf _ (hs y)) PUnit.unit⟩
/-- The sheaf condition for `yoneda'`. -/
theorem Presheaf.isSheaf_yoneda' {α : Type u} :
Presheaf.IsSheaf typesGrothendieckTopology (yoneda.obj α) := by
rw [isSheaf_iff_isSheaf_of_type]
exact Presieve.isSheaf_yoneda'
/-- The yoneda functor that sends a type to a sheaf over the category of types. -/
@[simps]
def yoneda' : Type u ⥤ Sheaf typesGrothendieckTopology (Type u) where
obj α := ⟨yoneda.obj α, Presheaf.isSheaf_yoneda'⟩
map f := ⟨yoneda.map f⟩
@[simp]
theorem yoneda'_comp : yoneda'.{u} ⋙ sheafToPresheaf _ _ = yoneda :=
rfl
open Opposite
/-- Given a presheaf `P` on the category of types, construct
a map `P(α) → (α → P(*))` for all type `α`. -/
def eval (P : Type uᵒᵖ ⥤ Type u) (α : Type u) (s : P.obj (op α)) (x : α) : P.obj (op PUnit) :=
P.map (↾fun _ => x).op s
open Presieve
/-- Given a sheaf `S` on the category of types, construct a map
`(α → S(*)) → S(α)` that is inverse to `eval`. -/
noncomputable def typesGlue (S : Type uᵒᵖ ⥤ Type u) (hs : IsSheaf typesGrothendieckTopology S)
(α : Type u) (f : α → S.obj (op PUnit)) : S.obj (op α) :=
(hs.isSheafFor _ _ (generate_discretePresieve_mem α)).amalgamate
(fun _ g hg => S.map (↾fun _ => PUnit.unit).op <| f <| g <| Classical.choose hg)
fun β γ δ g₁ g₂ f₁ f₂ hf₁ hf₂ h =>
(hs.isSheafFor _ _ (generate_discretePresieve_mem δ)).isSeparatedFor.ext fun ε g ⟨x, _⟩ => by
have : f₁ (Classical.choose hf₁) = f₂ (Classical.choose hf₂) :=
Classical.choose_spec hf₁ (g₁ <| g x) ▸
Classical.choose_spec hf₂ (g₂ <| g x) ▸ congr_fun h _
simp_rw [← FunctorToTypes.map_comp_apply, this, ← op_comp]
rfl
theorem eval_typesGlue {S hs α} (f) : eval.{u} S α (typesGlue S hs α f) = f := by
funext x
apply (IsSheafFor.valid_glue _ _ _ <| ⟨PUnit.unit, fun _ => Subsingleton.elim _ _⟩).trans
convert FunctorToTypes.map_id_apply S _
theorem typesGlue_eval {S hs α} (s) : typesGlue.{u} S hs α (eval S α s) = s := by
apply (hs.isSheafFor _ _ (generate_discretePresieve_mem α)).isSeparatedFor.ext
intro β f hf
apply (IsSheafFor.valid_glue _ _ _ hf).trans
apply (FunctorToTypes.map_comp_apply _ _ _ _).symm.trans
rw [← op_comp]
--congr 2 -- Porting note: This tactic didn't work. Find an alternative.
suffices ((↾fun _ ↦ PUnit.unit) ≫ ↾fun _ ↦ f (Classical.choose hf)) = f by rw [this]
funext x
exact congr_arg f (Classical.choose_spec hf x).symm
/-- Given a sheaf `S`, construct an equivalence `S(α) ≃ (α → S(*))`. -/
@[simps]
noncomputable def evalEquiv (S : Type uᵒᵖ ⥤ Type u)
(hs : Presheaf.IsSheaf typesGrothendieckTopology S)
(α : Type u) : S.obj (op α) ≃ (α → S.obj (op PUnit)) where
toFun := eval S α
invFun := typesGlue S ((isSheaf_iff_isSheaf_of_type _ _ ).1 hs) α
left_inv := typesGlue_eval
right_inv := eval_typesGlue
theorem eval_map (S : Type uᵒᵖ ⥤ Type u) (α β) (f : β ⟶ α) (s x) :
eval S β (S.map f.op s) x = eval S α s (f x) := by
simp_rw [eval, ← FunctorToTypes.map_comp_apply, ← op_comp]; rfl
/-- Given a sheaf `S`, construct an isomorphism `S ≅ [-, S(*)]`. -/
@[simps!]
noncomputable def equivYoneda (S : Type uᵒᵖ ⥤ Type u)
(hs : Presheaf.IsSheaf typesGrothendieckTopology S) :
S ≅ yoneda.obj (S.obj (op PUnit)) :=
NatIso.ofComponents (fun α => Equiv.toIso <| evalEquiv S hs <| unop α) fun {α β} f =>
funext fun _ => funext fun _ => eval_map S (unop α) (unop β) f.unop _ _
/-- Given a sheaf `S`, construct an isomorphism `S ≅ [-, S(*)]`. -/
@[simps]
noncomputable def equivYoneda' (S : Sheaf typesGrothendieckTopology (Type u)) :
S ≅ yoneda'.obj (S.1.obj (op PUnit)) where
hom := ⟨(equivYoneda S.1 S.2).hom⟩
inv := ⟨(equivYoneda S.1 S.2).inv⟩
hom_inv_id := by ext1; apply (equivYoneda S.1 S.2).hom_inv_id
inv_hom_id := by ext1; apply (equivYoneda S.1 S.2).inv_hom_id
theorem eval_app (S₁ S₂ : Sheaf typesGrothendieckTopology (Type u)) (f : S₁ ⟶ S₂) (α : Type u)
(s : S₁.1.obj (op α)) (x : α) :
eval S₂.1 α (f.val.app (op α) s) x = f.val.app (op PUnit) (eval S₁.1 α s x) :=
(congr_fun (f.val.naturality (↾fun _ : PUnit => x).op) s).symm
/-- `yoneda'` induces an equivalence of category between `Type u` and
`Sheaf typesGrothendieckTopology (Type u)`. -/
@[simps!]
noncomputable def typeEquiv : Type u ≌ Sheaf typesGrothendieckTopology (Type u) where
functor := yoneda'
inverse := sheafToPresheaf _ _ ⋙ (evaluation _ _).obj (op PUnit)
unitIso := NatIso.ofComponents
(fun _α => -- α ≅ PUnit ⟶ α
{ hom := fun x _ => x
inv := fun f => f PUnit.unit
hom_inv_id := funext fun _ => rfl
inv_hom_id := funext fun _ => funext fun y => PUnit.casesOn y rfl })
fun _ => rfl
counitIso := Iso.symm <|
NatIso.ofComponents (fun S => equivYoneda' S) (fun {S₁ S₂} f => by
ext ⟨α⟩ s
dsimp at s ⊢
ext x
exact eval_app S₁ S₂ f α s x)
functor_unitIso_comp X := by
ext1
apply yonedaEquiv.injective
dsimp [yoneda', yonedaEquiv, evalEquiv]
erw [typesGlue_eval]
instance subcanonical_typesGrothendieckTopology : typesGrothendieckTopology.{u}.Subcanonical :=
GrothendieckTopology.Subcanonical.of_isSheaf_yoneda_obj _ fun _ => Presieve.isSheaf_yoneda'
theorem typesGrothendieckTopology_eq_canonical :
typesGrothendieckTopology.{u} = Sheaf.canonicalTopology (Type u) := by
refine le_antisymm typesGrothendieckTopology.le_canonical (sInf_le ?_)
refine ⟨yoneda.obj (ULift Bool), ⟨_, rfl⟩, GrothendieckTopology.ext ?_⟩
funext α
ext S
refine ⟨fun hs x => ?_, fun hs β f => Presieve.isSheaf_yoneda' _ fun y => hs _⟩
by_contra hsx
have : (fun _ => ULift.up true) = fun _ => ULift.up false :=
(hs PUnit fun _ => x).isSeparatedFor.ext
fun β f hf => funext fun y => hsx.elim <| S.2 hf fun _ => y
simp [funext_iff] at this
end CategoryTheory
|
LHopital.lean
|
/-
Copyright (c) 2020 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Analysis.Calculus.Deriv.Inv
import Mathlib.Analysis.Calculus.Deriv.MeanValue
/-!
# L'Hôpital's rule for 0/0 indeterminate forms
In this file, we prove several forms of "L'Hôpital's rule" for computing 0/0
indeterminate forms. The proof of `HasDerivAt.lhopital_zero_right_on_Ioo`
is based on the one given in the corresponding
[Wikibooks](https://en.wikibooks.org/wiki/Calculus/L%27H%C3%B4pital%27s_Rule)
chapter, and all other statements are derived from this one by composing by
carefully chosen functions.
Note that the filter `f'/g'` tends to isn't required to be one of `𝓝 a`,
`atTop` or `atBot`. In fact, we give a slightly stronger statement by
allowing it to be any filter on `ℝ`.
Each statement is available in a `HasDerivAt` form and a `deriv` form, which
is denoted by each statement being in either the `HasDerivAt` or the `deriv`
namespace.
## Tags
L'Hôpital's rule, L'Hopital's rule
-/
open Filter Set
open scoped Filter Topology Pointwise
variable {a b : ℝ} {l : Filter ℝ} {f f' g g' : ℝ → ℝ}
/-!
## Interval-based versions
We start by proving statements where all conditions (derivability, `g' ≠ 0`) have
to be satisfied on an explicitly-provided interval.
-/
namespace HasDerivAt
theorem lhopital_zero_right_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0)
(hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
have sub : ∀ x ∈ Ioo a b, Ioo a x ⊆ Ioo a b := fun x hx =>
Ioo_subset_Ioo (le_refl a) (le_of_lt hx.2)
have hg : ∀ x ∈ Ioo a b, g x ≠ 0 := by
intro x hx h
have : Tendsto g (𝓝[<] x) (𝓝 0) := by
rw [← h, ← nhdsWithin_Ioo_eq_nhdsLT hx.1]
exact ((hgg' x hx).continuousAt.continuousWithinAt.mono <| sub x hx).tendsto
obtain ⟨y, hyx, hy⟩ : ∃ c ∈ Ioo a x, g' c = 0 :=
exists_hasDerivAt_eq_zero' hx.1 hga this fun y hy => hgg' y <| sub x hx hy
exact hg' y (sub x hx hyx) hy
have : ∀ x ∈ Ioo a b, ∃ c ∈ Ioo a x, f x * g' c = g x * f' c := by
intro x hx
rw [← sub_zero (f x), ← sub_zero (g x)]
exact exists_ratio_hasDerivAt_eq_ratio_slope' g g' hx.1 f f' (fun y hy => hgg' y <| sub x hx hy)
(fun y hy => hff' y <| sub x hx hy) hga hfa
(tendsto_nhdsWithin_of_tendsto_nhds (hgg' x hx).continuousAt.tendsto)
(tendsto_nhdsWithin_of_tendsto_nhds (hff' x hx).continuousAt.tendsto)
choose! c hc using this
have : ∀ x ∈ Ioo a b, ((fun x' => f' x' / g' x') ∘ c) x = f x / g x := by grind
have cmp : ∀ x ∈ Ioo a b, a < c x ∧ c x < x := fun x hx => (hc x hx).1
rw [← nhdsWithin_Ioo_eq_nhdsGT hab]
apply tendsto_nhdsWithin_congr this
apply hdiv.comp
refine tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _
(tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
(tendsto_nhdsWithin_of_tendsto_nhds tendsto_id) ?_ ?_) ?_
all_goals
apply eventually_nhdsWithin_of_forall
intro x hx
have := cmp x hx
try simp
linarith [this]
theorem lhopital_zero_right_on_Ico (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ico a b))
(hcg : ContinuousOn g (Ico a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfa : f a = 0) (hga : g a = 0)
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
refine lhopital_zero_right_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv
· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
theorem lhopital_zero_left_on_Ioo (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0)
(hfb : Tendsto f (𝓝[<] b) (𝓝 0)) (hgb : Tendsto g (𝓝[<] b) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) :
Tendsto (fun x => f x / g x) (𝓝[<] b) l := by
-- Here, we essentially compose by `Neg.neg`. The following is mostly technical details.
have hdnf : ∀ x ∈ -Ioo a b, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx =>
comp x (hff' (-x) hx) (hasDerivAt_neg x)
have hdng : ∀ x ∈ -Ioo a b, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx =>
comp x (hgg' (-x) hx) (hasDerivAt_neg x)
rw [neg_Ioo] at hdnf
rw [neg_Ioo] at hdng
have := lhopital_zero_right_on_Ioo (neg_lt_neg hab) hdnf hdng (by
intro x hx h
apply hg' _ (by rw [← neg_Ioo] at hx; exact hx)
rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h)
(hfb.comp tendsto_neg_nhdsGT_neg) (hgb.comp tendsto_neg_nhdsGT_neg)
(by
simp only [neg_div_neg_eq, mul_one, mul_neg]
exact hdiv.comp tendsto_neg_nhdsGT_neg)
have := this.comp tendsto_neg_nhdsLT
unfold Function.comp at this
simpa only [neg_neg]
theorem lhopital_zero_left_on_Ioc (hab : a < b) (hff' : ∀ x ∈ Ioo a b, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Ioo a b, HasDerivAt g (g' x) x) (hcf : ContinuousOn f (Ioc a b))
(hcg : ContinuousOn g (Ioc a b)) (hg' : ∀ x ∈ Ioo a b, g' x ≠ 0) (hfb : f b = 0) (hgb : g b = 0)
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] b) l) :
Tendsto (fun x => f x / g x) (𝓝[<] b) l := by
refine lhopital_zero_left_on_Ioo hab hff' hgg' hg' ?_ ?_ hdiv
· rw [← hfb, ← nhdsWithin_Ioo_eq_nhdsLT hab]
exact ((hcf b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto
· rw [← hgb, ← nhdsWithin_Ioo_eq_nhdsLT hab]
exact ((hcg b <| right_mem_Ioc.mpr hab).mono Ioo_subset_Ioc_self).tendsto
theorem lhopital_zero_atTop_on_Ioi (hff' : ∀ x ∈ Ioi a, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Ioi a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Ioi a, g' x ≠ 0)
(hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by
obtain ⟨a', haa', ha'⟩ : ∃ a', a < a' ∧ 0 < a' := ⟨1 + max a 0,
⟨lt_of_le_of_lt (le_max_left a 0) (lt_one_add _),
lt_of_le_of_lt (le_max_right a 0) (lt_one_add _)⟩⟩
have fact1 : ∀ x : ℝ, x ∈ Ioo 0 a'⁻¹ → x ≠ 0 := fun _ hx => (ne_of_lt hx.1).symm
have fact2 (x) (hx : x ∈ Ioo 0 a'⁻¹) : a < x⁻¹ := lt_trans haa' ((lt_inv_comm₀ ha' hx.1).mpr hx.2)
have hdnf : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (f ∘ Inv.inv) (f' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx =>
comp x (hff' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx)
have hdng : ∀ x ∈ Ioo 0 a'⁻¹, HasDerivAt (g ∘ Inv.inv) (g' x⁻¹ * -(x ^ 2)⁻¹) x := fun x hx =>
comp x (hgg' x⁻¹ <| fact2 x hx) (hasDerivAt_inv <| fact1 x hx)
have := lhopital_zero_right_on_Ioo (inv_pos.mpr ha') hdnf hdng
(by
intro x hx
refine mul_ne_zero ?_ (neg_ne_zero.mpr <| inv_ne_zero <| pow_ne_zero _ <| fact1 x hx)
exact hg' _ (fact2 x hx))
(hftop.comp tendsto_inv_nhdsGT_zero) (hgtop.comp tendsto_inv_nhdsGT_zero)
(by
refine (tendsto_congr' ?_).mp (hdiv.comp tendsto_inv_nhdsGT_zero)
filter_upwards [self_mem_nhdsWithin] with x (hx : 0 < x)
simp only [Function.comp_def]
rw [mul_div_mul_right]
exact neg_ne_zero.mpr (by positivity))
have := this.comp tendsto_inv_atTop_nhdsGT_zero
unfold Function.comp at this
simpa only [inv_inv]
theorem lhopital_zero_atBot_on_Iio (hff' : ∀ x ∈ Iio a, HasDerivAt f (f' x) x)
(hgg' : ∀ x ∈ Iio a, HasDerivAt g (g' x) x) (hg' : ∀ x ∈ Iio a, g' x ≠ 0)
(hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by
-- Here, we essentially compose by `Neg.neg`. The following is mostly technical details.
have hdnf : ∀ x ∈ -Iio a, HasDerivAt (f ∘ Neg.neg) (f' (-x) * -1) x := fun x hx =>
comp x (hff' (-x) hx) (hasDerivAt_neg x)
have hdng : ∀ x ∈ -Iio a, HasDerivAt (g ∘ Neg.neg) (g' (-x) * -1) x := fun x hx =>
comp x (hgg' (-x) hx) (hasDerivAt_neg x)
rw [neg_Iio] at hdnf
rw [neg_Iio] at hdng
have := lhopital_zero_atTop_on_Ioi hdnf hdng
(by
intro x hx h
apply hg' _ (by rw [← neg_Iio] at hx; exact hx)
rwa [mul_comm, ← neg_eq_neg_one_mul, neg_eq_zero] at h)
(hfbot.comp tendsto_neg_atTop_atBot) (hgbot.comp tendsto_neg_atTop_atBot)
(by
simp only [mul_one, mul_neg, neg_div_neg_eq]
exact (hdiv.comp tendsto_neg_atTop_atBot))
have := this.comp tendsto_neg_atBot_atTop
unfold Function.comp at this
simpa only [neg_neg]
end HasDerivAt
namespace deriv
theorem lhopital_zero_right_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b))
(hg' : ∀ x ∈ Ioo a b, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0))
(hga : Tendsto g (𝓝[>] a) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
have hdf : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx =>
(hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2)
have hdg : ∀ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_right_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfa hga hdiv
theorem lhopital_zero_right_on_Ico (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b))
(hcf : ContinuousOn f (Ico a b)) (hcg : ContinuousOn g (Ico a b))
(hg' : ∀ x ∈ Ioo a b, (deriv g) x ≠ 0) (hfa : f a = 0) (hga : g a = 0)
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
refine lhopital_zero_right_on_Ioo hab hdf hg' ?_ ?_ hdiv
· rw [← hfa, ← nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcf a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
· rw [← hga, ← nhdsWithin_Ioo_eq_nhdsGT hab]
exact ((hcg a <| left_mem_Ico.mpr hab).mono Ioo_subset_Ico_self).tendsto
theorem lhopital_zero_left_on_Ioo (hab : a < b) (hdf : DifferentiableOn ℝ f (Ioo a b))
(hg' : ∀ x ∈ Ioo a b, (deriv g) x ≠ 0) (hfb : Tendsto f (𝓝[<] b) (𝓝 0))
(hgb : Tendsto g (𝓝[<] b) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] b) l) :
Tendsto (fun x => f x / g x) (𝓝[<] b) l := by
have hdf : ∀ x ∈ Ioo a b, DifferentiableAt ℝ f x := fun x hx =>
(hdf x hx).differentiableAt (Ioo_mem_nhds hx.1 hx.2)
have hdg : ∀ x ∈ Ioo a b, DifferentiableAt ℝ g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_left_on_Ioo hab (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfb hgb hdiv
theorem lhopital_zero_atTop_on_Ioi (hdf : DifferentiableOn ℝ f (Ioi a))
(hg' : ∀ x ∈ Ioi a, (deriv g) x ≠ 0) (hftop : Tendsto f atTop (𝓝 0))
(hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) :
Tendsto (fun x => f x / g x) atTop l := by
have hdf : ∀ x ∈ Ioi a, DifferentiableAt ℝ f x := fun x hx =>
(hdf x hx).differentiableAt (Ioi_mem_nhds hx)
have hdg : ∀ x ∈ Ioi a, DifferentiableAt ℝ g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_atTop_on_Ioi (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hftop hgtop hdiv
theorem lhopital_zero_atBot_on_Iio (hdf : DifferentiableOn ℝ f (Iio a))
(hg' : ∀ x ∈ Iio a, (deriv g) x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0))
(hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) :
Tendsto (fun x => f x / g x) atBot l := by
have hdf : ∀ x ∈ Iio a, DifferentiableAt ℝ f x := fun x hx =>
(hdf x hx).differentiableAt (Iio_mem_nhds hx)
have hdg : ∀ x ∈ Iio a, DifferentiableAt ℝ g x := fun x hx =>
by_contradiction fun h => hg' x hx (deriv_zero_of_not_differentiableAt h)
exact HasDerivAt.lhopital_zero_atBot_on_Iio (fun x hx => (hdf x hx).hasDerivAt)
(fun x hx => (hdg x hx).hasDerivAt) hg' hfbot hgbot hdiv
end deriv
/-!
## Generic versions
The following statements no longer any explicit interval, as they only require
conditions holding eventually.
-/
namespace HasDerivAt
/-- L'Hôpital's rule for approaching a real from the right, `HasDerivAt` version -/
theorem lhopital_zero_nhdsGT (hff' : ∀ᶠ x in 𝓝[>] a, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in 𝓝[>] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[>] a, g' x ≠ 0)
(hfa : Tendsto f (𝓝[>] a) (𝓝 0)) (hga : Tendsto g (𝓝[>] a) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with ⟨s₁, hs₁, hff'⟩
rcases hgg' with ⟨s₂, hs₂, hgg'⟩
rcases hg' with ⟨s₃, hs₃, hg'⟩
let s := s₁ ∩ s₂ ∩ s₃
have hs : s ∈ 𝓝[>] a := inter_mem (inter_mem hs₁ hs₂) hs₃
rw [mem_nhdsGT_iff_exists_Ioo_subset] at hs
rcases hs with ⟨u, hau, hu⟩
refine lhopital_zero_right_on_Ioo hau ?_ ?_ ?_ hfa hga hdiv <;>
intro x hx <;> apply_assumption <;>
first | exact (hu hx).1.1 | exact (hu hx).1.2 | exact (hu hx).2
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_right := lhopital_zero_nhdsGT
/-- L'Hôpital's rule for approaching a real from the left, `HasDerivAt` version -/
theorem lhopital_zero_nhdsLT (hff' : ∀ᶠ x in 𝓝[<] a, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in 𝓝[<] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[<] a, g' x ≠ 0)
(hfa : Tendsto f (𝓝[<] a) (𝓝 0)) (hga : Tendsto g (𝓝[<] a) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[<] a) l) :
Tendsto (fun x => f x / g x) (𝓝[<] a) l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with ⟨s₁, hs₁, hff'⟩
rcases hgg' with ⟨s₂, hs₂, hgg'⟩
rcases hg' with ⟨s₃, hs₃, hg'⟩
let s := s₁ ∩ s₂ ∩ s₃
have hs : s ∈ 𝓝[<] a := inter_mem (inter_mem hs₁ hs₂) hs₃
rw [mem_nhdsLT_iff_exists_Ioo_subset] at hs
rcases hs with ⟨l, hal, hl⟩
refine lhopital_zero_left_on_Ioo hal ?_ ?_ ?_ hfa hga hdiv <;> intro x hx <;> apply_assumption <;>
first | exact (hl hx).1.1| exact (hl hx).1.2| exact (hl hx).2
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_left := lhopital_zero_nhdsLT
/-- L'Hôpital's rule for approaching a real, `HasDerivAt` version. This
does not require anything about the situation at `a` -/
theorem lhopital_zero_nhdsNE (hff' : ∀ᶠ x in 𝓝[≠] a, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in 𝓝[≠] a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝[≠] a, g' x ≠ 0)
(hfa : Tendsto f (𝓝[≠] a) (𝓝 0)) (hga : Tendsto g (𝓝[≠] a) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝[≠] a) l) :
Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by
simp only [← Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at *
exact ⟨lhopital_zero_nhdsLT hff'.1 hgg'.1 hg'.1 hfa.1 hga.1 hdiv.1,
lhopital_zero_nhdsGT hff'.2 hgg'.2 hg'.2 hfa.2 hga.2 hdiv.2⟩
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds' := lhopital_zero_nhdsNE
/-- **L'Hôpital's rule** for approaching a real, `HasDerivAt` version -/
theorem lhopital_zero_nhds (hff' : ∀ᶠ x in 𝓝 a, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in 𝓝 a, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in 𝓝 a, g' x ≠ 0)
(hfa : Tendsto f (𝓝 a) (𝓝 0)) (hga : Tendsto g (𝓝 a) (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) (𝓝 a) l) : Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by
apply @lhopital_zero_nhdsNE _ _ _ f' _ g' <;>
(first | apply eventually_nhdsWithin_of_eventually_nhds |
apply tendsto_nhdsWithin_of_tendsto_nhds) <;> assumption
/-- L'Hôpital's rule for approaching +∞, `HasDerivAt` version -/
theorem lhopital_zero_atTop (hff' : ∀ᶠ x in atTop, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in atTop, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in atTop, g' x ≠ 0)
(hftop : Tendsto f atTop (𝓝 0)) (hgtop : Tendsto g atTop (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) atTop l) : Tendsto (fun x => f x / g x) atTop l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with ⟨s₁, hs₁, hff'⟩
rcases hgg' with ⟨s₂, hs₂, hgg'⟩
rcases hg' with ⟨s₃, hs₃, hg'⟩
let s := s₁ ∩ s₂ ∩ s₃
have hs : s ∈ atTop := inter_mem (inter_mem hs₁ hs₂) hs₃
rw [mem_atTop_sets] at hs
rcases hs with ⟨l, hl⟩
have hl' : Ioi l ⊆ s := fun x hx => hl x (le_of_lt hx)
refine lhopital_zero_atTop_on_Ioi ?_ ?_ (fun x hx => hg' x <| (hl' hx).2) hftop hgtop hdiv <;>
intro x hx <;> apply_assumption <;> first | exact (hl' hx).1.1| exact (hl' hx).1.2
/-- L'Hôpital's rule for approaching -∞, `HasDerivAt` version -/
theorem lhopital_zero_atBot (hff' : ∀ᶠ x in atBot, HasDerivAt f (f' x) x)
(hgg' : ∀ᶠ x in atBot, HasDerivAt g (g' x) x) (hg' : ∀ᶠ x in atBot, g' x ≠ 0)
(hfbot : Tendsto f atBot (𝓝 0)) (hgbot : Tendsto g atBot (𝓝 0))
(hdiv : Tendsto (fun x => f' x / g' x) atBot l) : Tendsto (fun x => f x / g x) atBot l := by
rw [eventually_iff_exists_mem] at *
rcases hff' with ⟨s₁, hs₁, hff'⟩
rcases hgg' with ⟨s₂, hs₂, hgg'⟩
rcases hg' with ⟨s₃, hs₃, hg'⟩
let s := s₁ ∩ s₂ ∩ s₃
have hs : s ∈ atBot := inter_mem (inter_mem hs₁ hs₂) hs₃
rw [mem_atBot_sets] at hs
rcases hs with ⟨l, hl⟩
have hl' : Iio l ⊆ s := fun x hx => hl x (le_of_lt hx)
refine lhopital_zero_atBot_on_Iio ?_ ?_ (fun x hx => hg' x <| (hl' hx).2) hfbot hgbot hdiv <;>
intro x hx <;> apply_assumption <;> first | exact (hl' hx).1.1| exact (hl' hx).1.2
end HasDerivAt
namespace deriv
/-- **L'Hôpital's rule** for approaching a real from the right, `deriv` version -/
theorem lhopital_zero_nhdsGT (hdf : ∀ᶠ x in 𝓝[>] a, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x in 𝓝[>] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[>] a) (𝓝 0))
(hga : Tendsto g (𝓝[>] a) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[>] a) l) :
Tendsto (fun x => f x / g x) (𝓝[>] a) l := by
have hdg : ∀ᶠ x in 𝓝[>] a, DifferentiableAt ℝ g x :=
hg'.mono fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)
have hdf' : ∀ᶠ x in 𝓝[>] a, HasDerivAt f (deriv f x) x :=
hdf.mono fun _ => DifferentiableAt.hasDerivAt
have hdg' : ∀ᶠ x in 𝓝[>] a, HasDerivAt g (deriv g x) x :=
hdg.mono fun _ => DifferentiableAt.hasDerivAt
exact HasDerivAt.lhopital_zero_nhdsGT hdf' hdg' hg' hfa hga hdiv
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_right := lhopital_zero_nhdsGT
/-- **L'Hôpital's rule** for approaching a real from the left, `deriv` version -/
theorem lhopital_zero_nhdsLT (hdf : ∀ᶠ x in 𝓝[<] a, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x in 𝓝[<] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[<] a) (𝓝 0))
(hga : Tendsto g (𝓝[<] a) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[<] a) l) :
Tendsto (fun x => f x / g x) (𝓝[<] a) l := by
have hdg : ∀ᶠ x in 𝓝[<] a, DifferentiableAt ℝ g x :=
hg'.mono fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)
have hdf' : ∀ᶠ x in 𝓝[<] a, HasDerivAt f (deriv f x) x :=
hdf.mono fun _ => DifferentiableAt.hasDerivAt
have hdg' : ∀ᶠ x in 𝓝[<] a, HasDerivAt g (deriv g x) x :=
hdg.mono fun _ => DifferentiableAt.hasDerivAt
exact HasDerivAt.lhopital_zero_nhdsLT hdf' hdg' hg' hfa hga hdiv
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds_left := lhopital_zero_nhdsLT
/-- **L'Hôpital's rule** for approaching a real, `deriv` version. This
does not require anything about the situation at `a` -/
theorem lhopital_zero_nhdsNE (hdf : ∀ᶠ x in 𝓝[≠] a, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x in 𝓝[≠] a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝[≠] a) (𝓝 0))
(hga : Tendsto g (𝓝[≠] a) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝[≠] a) l) :
Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by
simp only [← Iio_union_Ioi, nhdsWithin_union, tendsto_sup, eventually_sup] at *
exact ⟨lhopital_zero_nhdsLT hdf.1 hg'.1 hfa.1 hga.1 hdiv.1,
lhopital_zero_nhdsGT hdf.2 hg'.2 hfa.2 hga.2 hdiv.2⟩
@[deprecated (since := "2025-03-02")]
alias lhopital_zero_nhds' := lhopital_zero_nhdsNE
/-- **L'Hôpital's rule** for approaching a real, `deriv` version -/
theorem lhopital_zero_nhds (hdf : ∀ᶠ x in 𝓝 a, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x in 𝓝 a, deriv g x ≠ 0) (hfa : Tendsto f (𝓝 a) (𝓝 0)) (hga : Tendsto g (𝓝 a) (𝓝 0))
(hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) (𝓝 a) l) :
Tendsto (fun x => f x / g x) (𝓝[≠] a) l := by
apply lhopital_zero_nhdsNE <;>
(first | apply eventually_nhdsWithin_of_eventually_nhds |
apply tendsto_nhdsWithin_of_tendsto_nhds) <;> assumption
/-- **L'Hôpital's rule** for approaching +∞, `deriv` version -/
theorem lhopital_zero_atTop (hdf : ∀ᶠ x : ℝ in atTop, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x : ℝ in atTop, deriv g x ≠ 0) (hftop : Tendsto f atTop (𝓝 0))
(hgtop : Tendsto g atTop (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atTop l) :
Tendsto (fun x => f x / g x) atTop l := by
have hdg : ∀ᶠ x in atTop, DifferentiableAt ℝ g x := hg'.mp
(Eventually.of_forall fun _ hg' =>
by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h))
have hdf' : ∀ᶠ x in atTop, HasDerivAt f (deriv f x) x :=
hdf.mono fun _ => DifferentiableAt.hasDerivAt
have hdg' : ∀ᶠ x in atTop, HasDerivAt g (deriv g x) x :=
hdg.mono fun _ => DifferentiableAt.hasDerivAt
exact HasDerivAt.lhopital_zero_atTop hdf' hdg' hg' hftop hgtop hdiv
/-- **L'Hôpital's rule** for approaching -∞, `deriv` version -/
theorem lhopital_zero_atBot (hdf : ∀ᶠ x : ℝ in atBot, DifferentiableAt ℝ f x)
(hg' : ∀ᶠ x : ℝ in atBot, deriv g x ≠ 0) (hfbot : Tendsto f atBot (𝓝 0))
(hgbot : Tendsto g atBot (𝓝 0)) (hdiv : Tendsto (fun x => (deriv f) x / (deriv g) x) atBot l) :
Tendsto (fun x => f x / g x) atBot l := by
have hdg : ∀ᶠ x in atBot, DifferentiableAt ℝ g x :=
hg'.mono fun _ hg' => by_contradiction fun h => hg' (deriv_zero_of_not_differentiableAt h)
have hdf' : ∀ᶠ x in atBot, HasDerivAt f (deriv f x) x :=
hdf.mono fun _ => DifferentiableAt.hasDerivAt
have hdg' : ∀ᶠ x in atBot, HasDerivAt g (deriv g x) x :=
hdg.mono fun _ => DifferentiableAt.hasDerivAt
exact HasDerivAt.lhopital_zero_atBot hdf' hdg' hg' hfbot hgbot hdiv
end deriv
|
PSeriesComplex.lean
|
/-
Copyright (c) 2024 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.PSeries
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.Data.Complex.FiniteDimensional
/-!
# Convergence of `p`-series (complex case)
Here we show convergence of `∑ n : ℕ, 1 / n ^ p` for complex `p`. This is done in a separate file
rather than in `Analysis.PSeries` in order to keep the prerequisites of the former relatively light.
## Tags
p-series, Cauchy condensation test
-/
lemma Complex.summable_one_div_nat_cpow {p : ℂ} :
Summable (fun n : ℕ ↦ 1 / (n : ℂ) ^ p) ↔ 1 < re p := by
rw [← Real.summable_one_div_nat_rpow, ← summable_nat_add_iff 1 (G := ℝ),
← summable_nat_add_iff 1 (G := ℂ), ← summable_norm_iff]
simp only [norm_div, norm_one, ← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos
(Nat.cast_pos.mpr <| Nat.succ_pos _)]
|
PartialTraj.lean
|
/-
Copyright (c) 2025 Etienne Marion. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Etienne Marion
-/
import Mathlib.MeasureTheory.MeasurableSpace.PreorderRestrict
import Mathlib.Probability.Kernel.Composition.Prod
import Mathlib.Probability.Kernel.IonescuTulcea.Maps
/-!
# Consecutive composition of kernels
This file is the first step towards Ionescu-Tulcea theorem, which allows for instance to construct
the product of an infinite family of probability measures. The idea of the statement is as follows:
consider a family of kernels `κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))`.
One can interpret `κ n` as a kernel which takes as an input the trajectory of a point started in
`X 0` and moving `X 0 → X 1 → X 2 → ... → X n` and which outputs the distribution of the next
position of the point in `X (n + 1)`. If `a b : ℕ` and `a < b`, we can compose the kernels,
and `κ a ⊗ₖ κ (a + 1) ⊗ₖ ... ⊗ₖ κ b` takes the trajectory up to time `a` as input and outputs
the distribution of the trajectory in `X (a + 1) × ... × X (b + 1)`.
The Ionescu-Tulcea theorem then tells us that these compositions can be extended into a kernel
`η : Kernel (Π i : Iic a, X i) → Π n > a, X n` which given the trajectory up to time `a` outputs
the distribution of the infinite trajectory started in `X (a + 1)`. In other words this theorem
makes sense of composing infinitely many kernels together.
To be able to even state the theorem we want to take the composition-product
(see `ProbabilityTheory.Kernel.compProd`) of consecutive kernels.
This however is not straightforward.
Consider `n : ℕ`. We cannot write `(κ n) ⊗ₖ (κ (n + 1))` directly, we need to first
introduce an equivalence to see `κ (n + 1)` as a kernel with codomain
`(Π i : Iic n, X i) × X (n + 1)`, and we get a `Kernel (Π i : Iic n, X i) (X (n + 1) × (X (n + 2))`.
However we want to do multiple composition at ones, i.e. write
`(κ n) ⊗ₖ ... ⊗ₖ (κ m)` for `n < m`. This requires even more equivalences to make sense of, and at
the end of the day we get kernels which still cannot be composed together.
To tackle this issue, we decide here to only consider kernels of the form
`Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)`. In other words these kernels take as input
a trajectory up to time `a` and output the distribution of the full trajectory up to time `b`.
This is captured in the definition `partialTraj κ a b`
(`partialTraj` stands for "partial trajectory").
The advantage of this approach is that it allows us to write for instance
`partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c` (see `partialTraj_comp_partialTraj`.)
In this file we therefore define this family of kernels and prove some properties of it.
In particular we provide at the end of the file some results to compute the integral of a function
against `partialTraj κ a b`, taking inspiration from `MeasureTheory.lmarginal`.
## Main definitions
* `partialTraj κ a b`: Given the trajectory of a point up to time `a`, returns the distribution
of the trajectory up to time `b`.
* `lmarginalPartialTraj κ a b f`: The integral of `f` against `partialTraj κ a b`.
This is essentially the integral of `f` against `κ (a + 1) ⊗ₖ ... ⊗ₖ κ b` but seen as depending
on all the variables, mimicking `MeasureTheory.lmarginal`. This allows to write
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f)`.
## Main statements
* `partialTraj_comp_partialTraj`: if `a ≤ b` and `b ≤ c` then
`partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c`.
* `lmarginalPartialTraj_self` : if `a ≤ b` and `b ≤ c` then
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f) = lmarginalPartialTraj κ a c`.
## Tags
Ionescu-Tulcea theorem, composition of kernels
-/
open Finset Function MeasureTheory Preorder ProbabilityTheory
open scoped ENNReal
variable {X : ℕ → Type*} {mX : ∀ n, MeasurableSpace (X n)} {a b c : ℕ}
{κ : (n : ℕ) → Kernel (Π i : Iic n, X i) (X (n + 1))}
section partialTraj
/-! ### Definition of `partialTraj` -/
namespace ProbabilityTheory.Kernel
open MeasurableEquiv
variable (κ) in
/-- Given a family of kernels `κ n` from `X 0 × ... × X n` to `X (n + 1)` for all `n`,
construct a kernel from `X 0 × ... × X a` to `X 0 × ... × X b` by iterating `κ`.
The idea is that the input is some trajectory up to time `a`, and the output is the distribution
of the trajectory up to time `b`. In particular if `b ≤ a`, this is just a deterministic kernel
(see `partialTraj_le`). The name `partialTraj` stands for "partial trajectory".
This kernel can be extended into a kernel with codomain `Π n, X n` via the Ionescu-Tulcea theorem.
-/
noncomputable def partialTraj (a b : ℕ) : Kernel (Π i : Iic a, X i) (Π i : Iic b, X i) :=
if h : b ≤ a then deterministic (frestrictLe₂ h) (measurable_frestrictLe₂ h)
else @Nat.leRec a (fun b _ ↦ Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)) Kernel.id
(fun k _ κ_k ↦ ((Kernel.id ×ₖ ((κ k).map (piSingleton k))) ∘ₖ κ_k).map (IicProdIoc k (k + 1)))
b (Nat.le_of_not_ge h)
section Basic
/-- If `b ≤ a`, given the trajectory up to time `a`, the trajectory up to time `b` is
deterministic and is equal to the restriction of the trajectory up to time `a`. -/
lemma partialTraj_le (hba : b ≤ a) :
partialTraj κ a b = deterministic (frestrictLe₂ hba) (measurable_frestrictLe₂ _) := by
rw [partialTraj, dif_pos hba]
@[simp]
lemma partialTraj_self (a : ℕ) : partialTraj κ a a = Kernel.id := by rw [partialTraj_le le_rfl]; rfl
@[simp]
lemma partialTraj_zero :
partialTraj κ a 0 = deterministic (frestrictLe₂ (zero_le a)) (measurable_frestrictLe₂ _) := by
rw [partialTraj_le (zero_le a)]
lemma partialTraj_le_def (hab : a ≤ b) : partialTraj κ a b =
@Nat.leRec a (fun b _ ↦ Kernel (Π i : Iic a, X i) (Π i : Iic b, X i)) Kernel.id
(fun k _ κ_k ↦ ((Kernel.id ×ₖ ((κ k).map (piSingleton k))) ∘ₖ κ_k).map (IicProdIoc k (k + 1)))
b hab := by
obtain rfl | hab := eq_or_lt_of_le hab
· simp
· rw [partialTraj, dif_neg (not_le.2 hab)]
lemma partialTraj_succ_of_le (hab : a ≤ b) : partialTraj κ a (b + 1) =
((Kernel.id ×ₖ ((κ b).map (piSingleton b))) ∘ₖ partialTraj κ a b).map
(IicProdIoc b (b + 1)) := by
rw [partialTraj, dif_neg (by omega)]
induction b, hab using Nat.le_induction with
| base => simp
| succ k hak hk => rw [Nat.leRec_succ, ← partialTraj_le_def]; omega
instance (a b : ℕ) : IsSFiniteKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsFiniteKernel (κ n)] (a b : ℕ) : IsFiniteKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsZeroOrMarkovKernel (κ n)] (a b : ℕ) :
IsZeroOrMarkovKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak => rw [partialTraj_succ_of_le hak]; infer_instance
· rw [partialTraj_le hba]; infer_instance
instance [∀ n, IsMarkovKernel (κ n)] (a b : ℕ) :
IsMarkovKernel (partialTraj κ a b) := by
obtain hab | hba := le_total a b
· induction b, hab using Nat.le_induction with
| base => rw [partialTraj_self]; infer_instance
| succ k hak =>
rw [partialTraj_succ_of_le hak]
have := IsMarkovKernel.map (κ k) (piSingleton k).measurable
exact IsMarkovKernel.map _ measurable_IicProdIoc
· rw [partialTraj_le hba]; infer_instance
lemma partialTraj_succ_self (a : ℕ) :
partialTraj κ a (a + 1) =
(Kernel.id ×ₖ ((κ a).map (piSingleton a))).map (IicProdIoc a (a + 1)) := by
rw [partialTraj_succ_of_le le_rfl, partialTraj_self, comp_id]
lemma partialTraj_succ_eq_comp (hab : a ≤ b) :
partialTraj κ a (b + 1) = partialTraj κ b (b + 1) ∘ₖ partialTraj κ a b := by
rw [partialTraj_succ_self, ← map_comp, partialTraj_succ_of_le hab]
/-- Given the trajectory up to time `a`, `partialTraj κ a b` gives the distribution of
the trajectory up to time `b`. Then plugging this into `partialTraj κ b c` gives
the distribution of the trajectory up to time `c`. -/
theorem partialTraj_comp_partialTraj (hab : a ≤ b) (hbc : b ≤ c) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
induction c, hbc using Nat.le_induction with
| base => simp
| succ k h hk => rw [partialTraj_succ_eq_comp h, comp_assoc, hk,
← partialTraj_succ_eq_comp (hab.trans h)]
/-- This is a specific lemma used in the proof of `partialTraj_eq_prod`. It is the main rewrite step
and stating it as a separate lemma avoids using extensionality of kernels, which would generate
a lot of measurability subgoals. -/
private lemma fst_prod_comp_id_prod {X Y Z : Type*} {mX : MeasurableSpace X}
{mY : MeasurableSpace Y} {mZ : MeasurableSpace Z} (κ : Kernel X Y) [IsSFiniteKernel κ]
(η : Kernel (X × Y) Z) [IsSFiniteKernel η] :
((deterministic Prod.fst measurable_fst) ×ₖ η) ∘ₖ (Kernel.id ×ₖ κ) =
Kernel.id ×ₖ (η ∘ₖ (Kernel.id ×ₖ κ)) := by
ext x s ms
simp_rw [comp_apply' _ _ _ ms, lintegral_id_prod (Kernel.measurable_coe _ ms),
deterministic_prod_apply' _ _ _ ms, id_prod_apply' _ _ ms,
comp_apply' _ _ _ (measurable_prodMk_left ms),
lintegral_id_prod (η.measurable_coe (measurable_prodMk_left ms))]
/-- This is a technical lemma saying that `partialTraj κ a b` consists of two independent parts, the
first one being the identity. It allows to compute integrals. -/
lemma partialTraj_eq_prod [∀ n, IsSFiniteKernel (κ n)] (a b : ℕ) :
partialTraj κ a b =
(Kernel.id ×ₖ (partialTraj κ a b).map (restrict₂ Ioc_subset_Iic_self)).map
(IicProdIoc a b) := by
obtain hba | hab := le_total b a
· rw [partialTraj_le hba, IicProdIoc_le hba, map_comp_right, ← fst_eq, deterministic_map,
fst_prod, id_map]
all_goals fun_prop
induction b, hab using Nat.le_induction with
| base =>
ext1 x
rw [partialTraj_self, id_map, map_apply, prod_apply, IicProdIoc_self, ← Measure.fst,
Measure.fst_prod]
all_goals fun_prop
| succ k h hk =>
have : (IicProdIoc (X := X) k (k + 1)) ∘ (Prod.map (IicProdIoc a k) id) =
(IicProdIoc (h.trans k.le_succ) ∘ (Prod.map id (IocProdIoc a k (k + 1)))) ∘
prodAssoc := by
ext x i
simp only [IicProdIoc_def, MeasurableEquiv.IicProdIoc, MeasurableEquiv.coe_mk,
Equiv.coe_fn_mk, Function.comp_apply, Prod.map_fst, Prod.map_snd, id_eq,
Nat.succ_eq_add_one, IocProdIoc]
split_ifs <;> try rfl
omega
nth_rw 1 [← partialTraj_comp_partialTraj h k.le_succ, hk, partialTraj_succ_self, comp_map,
comap_map_comm, comap_prod, id_comap, ← id_map, map_prod_eq, ← map_comp_right, this,
map_comp_right, id_prod_eq, prodAssoc_prod, map_comp_right, ← map_prod_map, map_id,
← map_comp, map_apply_eq_iff_map_symm_apply_eq, fst_prod_comp_id_prod, ← map_comp_right,
← coe_IicProdIoc (h.trans k.le_succ), symm_comp_self, map_id,
deterministic_congr IicProdIoc_comp_restrict₂.symm, ← deterministic_comp_deterministic,
comp_deterministic_eq_comap, ← comap_prod, ← map_comp, ← comp_map, ← hk,
← partialTraj_comp_partialTraj h k.le_succ, partialTraj_succ_self, map_comp, map_comp,
← map_comp_right, ← id_map, map_prod_eq, ← map_comp_right]
· rfl
all_goals fun_prop
variable [∀ n, IsMarkovKernel (κ n)]
lemma partialTraj_succ_map_frestrictLe₂ (a b : ℕ) :
(partialTraj κ a (b + 1)).map (frestrictLe₂ b.le_succ) = partialTraj κ a b := by
obtain hab | hba := le_or_gt a b
· have := IsMarkovKernel.map (κ b) (piSingleton b).measurable
rw [partialTraj_succ_eq_comp hab, map_comp, partialTraj_succ_self, ← map_comp_right,
frestrictLe₂_comp_IicProdIoc, ← fst_eq, fst_prod, id_comp]
all_goals fun_prop
· rw [partialTraj_le (Nat.succ_le.2 hba), partialTraj_le hba.le, deterministic_map]
· rfl
· fun_prop
/-- If we restrict the distribution of the trajectory up to time `c` to times `≤ b` we get
the trajectory up to time `b`. -/
theorem partialTraj_map_frestrictLe₂ (a : ℕ) (hbc : b ≤ c) :
(partialTraj κ a c).map (frestrictLe₂ hbc) = partialTraj κ a b := by
induction c, hbc using Nat.le_induction with
| base => exact map_id ..
| succ k h hk =>
rw [← hk, ← frestrictLe₂_comp_frestrictLe₂ h k.le_succ, map_comp_right,
partialTraj_succ_map_frestrictLe₂]
all_goals fun_prop
lemma partialTraj_map_frestrictLe₂_apply (x₀ : Π i : Iic a, X i) (hbc : b ≤ c) :
(partialTraj κ a c x₀).map (frestrictLe₂ hbc) = partialTraj κ a b x₀ := by
rw [← map_apply _ (by fun_prop), partialTraj_map_frestrictLe₂]
/-- Same as `partialTraj_comp_partialTraj` but only assuming `a ≤ b`. It requires Markov kernels. -/
lemma partialTraj_comp_partialTraj' (c : ℕ) (hab : a ≤ b) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
obtain hbc | hcb := le_total b c
· rw [partialTraj_comp_partialTraj hab hbc]
· rw [partialTraj_le hcb, deterministic_comp_eq_map, partialTraj_map_frestrictLe₂]
/-- Same as `partialTraj_comp_partialTraj` but only assuming `b ≤ c`. It requires Markov kernels. -/
lemma partialTraj_comp_partialTraj'' {b c : ℕ} (hcb : c ≤ b) :
partialTraj κ b c ∘ₖ partialTraj κ a b = partialTraj κ a c := by
rw [partialTraj_le hcb, deterministic_comp_eq_map, partialTraj_map_frestrictLe₂]
end Basic
section lmarginalPartialTraj
/-! ### Integrating against `partialTraj` -/
variable (κ)
/-- This function computes the integral of a function `f` against `partialTraj`,
and allows to view it as a function depending on all the variables.
This is inspired by `MeasureTheory.lmarginal`, to be able to write
`lmarginalPartialTraj κ b c (lmarginalPartialTraj κ a b f) = lmarginalPartialTraj κ a c`. -/
noncomputable def lmarginalPartialTraj (a b : ℕ) (f : (Π n, X n) → ℝ≥0∞) (x₀ : Π n, X n) : ℝ≥0∞ :=
∫⁻ z : (i : Iic b) → X i, f (updateFinset x₀ _ z) ∂(partialTraj κ a b (frestrictLe a x₀))
/-- If `b ≤ a`, then integrating `f` against `partialTraj κ a b` does nothing. -/
lemma lmarginalPartialTraj_le (hba : b ≤ a) {f : (Π n, X n) → ℝ≥0∞} (mf : Measurable f) :
lmarginalPartialTraj κ a b f = f := by
ext x₀
rw [lmarginalPartialTraj, partialTraj_le hba, Kernel.lintegral_deterministic']
· congr with i
simp [updateFinset]
· exact mf.comp measurable_updateFinset
variable {κ}
lemma lmarginalPartialTraj_mono (a b : ℕ) {f g : (Π n, X n) → ℝ≥0∞} (hfg : f ≤ g) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a b f x₀ ≤ lmarginalPartialTraj κ a b g x₀ :=
lintegral_mono fun _ ↦ hfg _
/-- Integrating `f` against `partialTraj κ a b x` is the same as integrating only over the variables
from `x_{a+1}` to `x_b`. -/
lemma lmarginalPartialTraj_eq_lintegral_map [∀ n, IsSFiniteKernel (κ n)] {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a b f x₀ =
∫⁻ x : (Π i : Ioc a b, X i), f (updateFinset x₀ _ x)
∂(partialTraj κ a b).map (restrict₂ Ioc_subset_Iic_self) (frestrictLe a x₀) := by
nth_rw 1 [lmarginalPartialTraj, partialTraj_eq_prod, lintegral_map, lintegral_id_prod]
· congrm ∫⁻ _, f (fun i ↦ ?_) ∂_
simp only [updateFinset, mem_Iic, IicProdIoc_def,
frestrictLe_apply, mem_Ioc]
split_ifs <;> try rfl
all_goals omega
all_goals fun_prop
/-- Integrating `f` against `partialTraj κ a (a + 1)` is the same as integrating against `κ a`. -/
lemma lmarginalPartialTraj_succ [∀ n, IsSFiniteKernel (κ n)] (a : ℕ)
{f : (Π n, X n) → ℝ≥0∞} (mf : Measurable f) (x₀ : Π n, X n) :
lmarginalPartialTraj κ a (a + 1) f x₀ =
∫⁻ x : X (a + 1), f (update x₀ _ x) ∂κ a (frestrictLe a x₀) := by
rw [lmarginalPartialTraj, partialTraj_succ_self, lintegral_map, lintegral_id_prod, lintegral_map]
· congrm ∫⁻ x, f (fun i ↦ ?_) ∂_
simp only [updateFinset, mem_Iic, IicProdIoc_def, frestrictLe_apply, piSingleton,
MeasurableEquiv.coe_mk, Equiv.coe_fn_mk, update]
split_ifs with h1 h2 h3 <;> try rfl
all_goals omega
all_goals fun_prop
@[measurability, fun_prop]
lemma measurable_lmarginalPartialTraj (a b : ℕ) {f : (Π n, X n) → ℝ≥0∞} (hf : Measurable f) :
Measurable (lmarginalPartialTraj κ a b f) := by
unfold lmarginalPartialTraj
let g : ((i : Iic b) → X i) × (Π n, X n) → ℝ≥0∞ := fun c ↦ f (updateFinset c.2 _ c.1)
let η : Kernel (Π n, X n) (Π i : Iic b, X i) :=
(partialTraj κ a b).comap (frestrictLe a) (measurable_frestrictLe _)
change Measurable fun x₀ ↦ ∫⁻ z : (i : Iic b) → X i, g (z, x₀) ∂η x₀
refine Measurable.lintegral_kernel_prod_left' <| hf.comp ?_
simp only [updateFinset, measurable_pi_iff]
intro i
by_cases h : i ∈ Iic b <;> simp [h] <;> fun_prop
/-- Integrating `f` against `partialTraj κ a b` and then against `partialTraj κ b c` is the same
as integrating `f` against `partialTraj κ a c`. -/
theorem lmarginalPartialTraj_self (hab : a ≤ b) (hbc : b ≤ c)
{f : (Π n, X n) → ℝ≥0∞} (hf : Measurable f) :
lmarginalPartialTraj κ a b (lmarginalPartialTraj κ b c f) = lmarginalPartialTraj κ a c f := by
ext x₀
obtain rfl | hab := eq_or_lt_of_le hab <;> obtain rfl | hbc := eq_or_lt_of_le hbc
· rw [lmarginalPartialTraj_le κ le_rfl (measurable_lmarginalPartialTraj _ _ hf)]
· rw [lmarginalPartialTraj_le κ le_rfl (measurable_lmarginalPartialTraj _ _ hf)]
· rw [lmarginalPartialTraj_le κ le_rfl hf]
simp_rw [lmarginalPartialTraj, frestrictLe, restrict_updateFinset,
updateFinset_updateFinset_of_subset (Iic_subset_Iic.2 hbc.le)]
rw [← lintegral_comp, partialTraj_comp_partialTraj hab.le hbc.le]
fun_prop
end lmarginalPartialTraj
end ProbabilityTheory.Kernel
open ProbabilityTheory Kernel
namespace DependsOn
/-! ### Lemmas about `lmarginalPartialTraj` and `DependsOn` -/
/-- If `f` only depends on the variables up to rank `a` and `a ≤ b`, integrating `f` against
`partialTraj κ b c` does nothing. -/
theorem lmarginalPartialTraj_of_le [∀ n, IsMarkovKernel (κ n)] (c : ℕ) {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (hf : DependsOn f (Iic a)) (hab : a ≤ b) :
lmarginalPartialTraj κ b c f = f := by
ext x
rw [lmarginalPartialTraj_eq_lintegral_map mf]
refine @lintegral_eq_const _ _ _ ?_ _ _ (ae_of_all _ fun y ↦ hf fun i hi ↦ ?_)
· refine @IsMarkovKernel.isProbabilityMeasure _ _ _ _ _ ?_ _
exact IsMarkovKernel.map _ (by fun_prop)
· simp_all only [coe_Iic, Set.mem_Iic, Function.updateFinset, mem_Ioc, dite_eq_right_iff]
omega
/-- If `f` only depends on the variables uo to rank `a`, integrating beyond rank `a` is the same
as integrating up to rank `a`. -/
theorem lmarginalPartialTraj_const_right [∀ n, IsMarkovKernel (κ n)] {d : ℕ} {f : (Π n, X n) → ℝ≥0∞}
(mf : Measurable f) (hf : DependsOn f (Iic a)) (hac : a ≤ c) (had : a ≤ d) :
lmarginalPartialTraj κ b c f = lmarginalPartialTraj κ b d f := by
wlog hcd : c ≤ d generalizing c d
· rw [this had hac (le_of_not_ge hcd)]
obtain hbc | hcb := le_total b c
· rw [← lmarginalPartialTraj_self hbc hcd mf, hf.lmarginalPartialTraj_of_le d mf hac]
· rw [hf.lmarginalPartialTraj_of_le c mf (hac.trans hcb),
hf.lmarginalPartialTraj_of_le d mf (hac.trans hcb)]
/-- If `f` only depends on variables up to rank `b`, its integral from `a` to `b` only depends on
variables up to rank `a`. -/
theorem dependsOn_lmarginalPartialTraj [∀ n, IsSFiniteKernel (κ n)] (a : ℕ) {f : (Π n, X n) → ℝ≥0∞}
(hf : DependsOn f (Iic b)) (mf : Measurable f) :
DependsOn (lmarginalPartialTraj κ a b f) (Iic a) := by
intro x y hxy
obtain hba | hab := le_total b a
· rw [Kernel.lmarginalPartialTraj_le κ hba mf]
exact hf fun i hi ↦ hxy i (Iic_subset_Iic.2 hba hi)
rw [lmarginalPartialTraj_eq_lintegral_map mf, lmarginalPartialTraj_eq_lintegral_map mf]
congrm ∫⁻ z : _, ?_ ∂(partialTraj κ a b).map _ (fun i ↦ ?_)
· exact hxy i.1 i.2
· refine hf.updateFinset _ ?_
rwa [← coe_sdiff, Iic_diff_Ioc_self_of_le hab]
end DependsOn
end partialTraj
|
Trails.lean
|
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Algebra.Ring.Parity
import Mathlib.Combinatorics.SimpleGraph.Paths
/-!
# Trails and Eulerian trails
This module contains additional theory about trails, including Eulerian trails (also known
as Eulerian circuits).
## Main definitions
* `SimpleGraph.Walk.IsEulerian` is the predicate that a trail is an Eulerian trail.
* `SimpleGraph.Walk.IsTrail.even_countP_edges_iff` gives a condition on the number of edges
in a trail that can be incident to a given vertex.
* `SimpleGraph.Walk.IsEulerian.even_degree_iff` gives a condition on the degrees of vertices
when there exists an Eulerian trail.
* `SimpleGraph.Walk.IsEulerian.card_odd_degree` gives the possible numbers of odd-degree
vertices when there exists an Eulerian trail.
## TODO
* Prove that there exists an Eulerian trail when the conclusion to
`SimpleGraph.Walk.IsEulerian.card_odd_degree` holds.
## Tags
Eulerian trails
-/
namespace SimpleGraph
variable {V : Type*} {G : SimpleGraph V}
namespace Walk
/-- The edges of a trail as a finset, since each edge in a trail appears exactly once. -/
abbrev IsTrail.edgesFinset {u v : V} {p : G.Walk u v} (h : p.IsTrail) : Finset (Sym2 V) :=
⟨p.edges, h.edges_nodup⟩
variable [DecidableEq V]
theorem IsTrail.even_countP_edges_iff {u v : V} {p : G.Walk u v} (ht : p.IsTrail) (x : V) :
Even (p.edges.countP fun e => x ∈ e) ↔ u ≠ v → x ≠ u ∧ x ≠ v := by
induction p with
| nil => simp
| cons huv p ih =>
rw [cons_isTrail_iff] at ht
specialize ih ht.1
simp only [List.countP_cons, Ne, edges_cons, Sym2.mem_iff]
split_ifs with h
· rw [decide_eq_true_eq] at h
obtain (rfl | rfl) := h
· rw [Nat.even_add_one, ih]
simp only [huv.ne, imp_false, Ne, not_false_iff, true_and, not_forall,
Classical.not_not, exists_prop, not_true, false_and,
and_iff_right_iff_imp]
rintro rfl rfl
exact G.loopless _ huv
· rw [Nat.even_add_one, ih, ← not_iff_not]
simp only [huv.ne.symm, Ne, not_true, false_and, not_forall,
not_false_iff, exists_prop, and_true, Classical.not_not, true_and, iff_and_self]
rintro rfl
exact huv.ne
· grind
/-- An *Eulerian trail* (also known as an "Eulerian path") is a walk
`p` that visits every edge exactly once. The lemma `SimpleGraph.Walk.IsEulerian.IsTrail` shows
that these are trails.
Combine with `p.IsCircuit` to get an Eulerian circuit (also known as an "Eulerian cycle"). -/
def IsEulerian {u v : V} (p : G.Walk u v) : Prop :=
∀ e, e ∈ G.edgeSet → p.edges.count e = 1
theorem IsEulerian.isTrail {u v : V} {p : G.Walk u v} (h : p.IsEulerian) : p.IsTrail := by
rw [isTrail_def, List.nodup_iff_count_le_one]
intro e
by_cases he : e ∈ p.edges
· exact (h e (edges_subset_edgeSet _ he)).le
· simp [List.count_eq_zero_of_not_mem he]
theorem IsEulerian.mem_edges_iff {u v : V} {p : G.Walk u v} (h : p.IsEulerian) {e : Sym2 V} :
e ∈ p.edges ↔ e ∈ G.edgeSet :=
⟨ fun h => p.edges_subset_edgeSet h
, fun he => by simpa [Nat.succ_le] using (h e he).ge ⟩
/-- The edge set of an Eulerian graph is finite. -/
def IsEulerian.fintypeEdgeSet {u v : V} {p : G.Walk u v} (h : p.IsEulerian) :
Fintype G.edgeSet :=
Fintype.ofFinset h.isTrail.edgesFinset fun e => by
simp only [Finset.mem_mk, Multiset.mem_coe, h.mem_edges_iff]
theorem IsTrail.isEulerian_of_forall_mem {u v : V} {p : G.Walk u v} (h : p.IsTrail)
(hc : ∀ e, e ∈ G.edgeSet → e ∈ p.edges) : p.IsEulerian := fun e he =>
List.count_eq_one_of_mem h.edges_nodup (hc e he)
theorem isEulerian_iff {u v : V} (p : G.Walk u v) :
p.IsEulerian ↔ p.IsTrail ∧ ∀ e, e ∈ G.edgeSet → e ∈ p.edges := by
constructor
· intro h
exact ⟨h.isTrail, fun _ => h.mem_edges_iff.mpr⟩
· rintro ⟨h, hl⟩
exact h.isEulerian_of_forall_mem hl
theorem IsTrail.isEulerian_iff {u v : V} {p : G.Walk u v} (hp : p.IsTrail) :
p.IsEulerian ↔ p.edgeSet = G.edgeSet :=
⟨fun h ↦ Set.Subset.antisymm p.edges_subset_edgeSet (p.isEulerian_iff.mp h).2,
fun h ↦ p.isEulerian_iff.mpr ⟨hp, by simp [← h]⟩⟩
theorem IsEulerian.edgeSet_eq {u v : V} {p : G.Walk u v} (h : p.IsEulerian) :
p.edgeSet = G.edgeSet := by
rwa [← h.isTrail.isEulerian_iff]
theorem IsEulerian.edgesFinset_eq [Fintype G.edgeSet] {u v : V} {p : G.Walk u v}
(h : p.IsEulerian) : h.isTrail.edgesFinset = G.edgeFinset := by
ext e
simp [h.mem_edges_iff]
theorem IsEulerian.even_degree_iff {x u v : V} {p : G.Walk u v} (ht : p.IsEulerian) [Fintype V]
[DecidableRel G.Adj] : Even (G.degree x) ↔ u ≠ v → x ≠ u ∧ x ≠ v := by
convert ht.isTrail.even_countP_edges_iff x
rw [← Multiset.coe_countP, Multiset.countP_eq_card_filter, ← card_incidenceFinset_eq_degree]
change Multiset.card _ = _
congr 1
convert_to _ = (ht.isTrail.edgesFinset.filter (x ∈ ·)).val
have : Fintype G.edgeSet := fintypeEdgeSet ht
rw [ht.edgesFinset_eq, G.incidenceFinset_eq_filter x]
theorem IsEulerian.card_filter_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V}
{p : G.Walk u v} (ht : p.IsEulerian) {s}
(h : s = (Finset.univ : Finset V).filter fun v => Odd (G.degree v)) :
s.card = 0 ∨ s.card = 2 := by
subst s
simp only [← Nat.not_even_iff_odd, Finset.card_eq_zero]
simp only [ht.even_degree_iff, Ne, not_forall, not_and, Classical.not_not, exists_prop]
obtain rfl | hn := eq_or_ne u v
· left
simp
· right
convert_to _ = ({u, v} : Finset V).card
· simp [hn]
· congr
ext x
simp [hn, imp_iff_not_or]
theorem IsEulerian.card_odd_degree [Fintype V] [DecidableRel G.Adj] {u v : V} {p : G.Walk u v}
(ht : p.IsEulerian) : Fintype.card { v : V | Odd (G.degree v) } = 0 ∨
Fintype.card { v : V | Odd (G.degree v) } = 2 := by
rw [← Set.toFinset_card]
apply IsEulerian.card_filter_odd_degree ht
ext v
simp
end Walk
end SimpleGraph
|
CatEnriched.lean
|
/-
Copyright (c) 2025 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Emily Riehl
-/
import Mathlib.CategoryTheory.Monoidal.Cartesian.Cat
import Mathlib.CategoryTheory.Enriched.Basic
import Mathlib.CategoryTheory.Enriched.Ordinary.Basic
/-!
# The strict bicategory associated to a Cat-enriched category
If `C` is a type with a `EnrichedCategory Cat C` structure, then it has hom-categories, whose
objects define 1-dimensional arrows on `C` and whose morphisms define 2-dimensional arrows between
these. The enriched category axioms equip this data with the structure of a strict bicategory.
We define a type alias `CatEnriched C` for a type `C` with a `EnrichedCategory Cat C` structure. We
provide this with an instance of a strict bicategory structure constructing
`Bicategory.Strict (CatEnriched C)`.
If `C` is a type with a `EnrichedOrdinaryCategory Cat C` structure, then it has an `Enrichred Cat C`
structure, so the previous construction would again produce a strict bicategory. However, in this
setting `C` is also given a `Category C` structure, together with an equivalence between this
category and the underlying category of the `Enriched Cat C`, and in examples the given category
structure is the preferred one.
Thus, we define a type alias `CatEnrichedOrdinary C` for a type `C` with an
`EnrichedOrdinaryCategory Cat C` structure. We provide this with an instance of a strict bicategory
structure extending the category structure provided by the given instance `Category C` constructing
`Bicategory.Strict (CatEnrichedOrdinary C)`.
-/
universe u v u' v'
namespace CategoryTheory
open Category
section
variable {C : Type*} [EnrichedCategory Cat C]
/-- A type synonym for `C`, which should come equipped with a `Cat`-enriched category structure.
This converts it to a strict bicategory where `Category (X ⟶ Y)` is `(X ⟶[Cat] Y)`. -/
def CatEnriched (C : Type*) := C
namespace CatEnriched
instance : EnrichedCategory Cat (CatEnriched C) := inferInstanceAs (EnrichedCategory Cat C)
/-- Any enriched category has an underlying category structure defined by `ForgetEnrichment`.
This is equivalent but not definitionally equal the category structure constructed here, which is
more canonically associated to the data of an `EnrichedCategory Cat` structure. -/
instance : CategoryStruct (CatEnriched C) where
Hom X Y := X ⟶[Cat] Y
id X := (eId Cat X).obj ⟨⟨()⟩⟩
comp {X Y Z} f g := (eComp Cat X Y Z).obj (f, g)
theorem id_eq (X : CatEnriched C) : 𝟙 X = (eId Cat X).obj ⟨⟨()⟩⟩ := rfl
theorem comp_eq {X Y Z : CatEnriched C} (f : X ⟶ Y) (g : Y ⟶ Z) :
f ≫ g = (eComp Cat X Y Z).obj (f, g) := rfl
instance {X Y : CatEnriched C} : Category (X ⟶ Y) := inferInstanceAs (Category (X ⟶[Cat] Y).α)
/-- The horizontal composition on 2-morphisms is defined using the action on arrows of the
composition bifunctor from the enriched category structure. -/
def hComp {a b c : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c}
(η : f ⟶ f') (θ : g ⟶ g') : f ≫ g ⟶ f' ≫ g' := (eComp Cat a b c).map (η, θ)
@[simp]
theorem id_hComp_id {a b c : CatEnriched C} (f : a ⟶ b) (g : b ⟶ c) :
hComp (𝟙 f) (𝟙 g) = 𝟙 (f ≫ g) := Functor.map_id ..
@[simp]
theorem eqToHom_hComp_eqToHom {a b c : CatEnriched C}
{f f' : a ⟶ b} (α : f = f') {g g' : b ⟶ c} (β : g = g') :
hComp (eqToHom α) (eqToHom β) = eqToHom (α ▸ β ▸ rfl) := by cases α; cases β; simp
/-- The interchange law for horizontal and vertical composition of 2-cells in a bicategory. -/
@[simp]
theorem hComp_comp {a b c : CatEnriched C} {f₁ f₂ f₃ : a ⟶ b} {g₁ g₂ g₃ : b ⟶ c}
(η : f₁ ⟶ f₂) (η' : f₂ ⟶ f₃) (θ : g₁ ⟶ g₂) (θ' : g₂ ⟶ g₃) :
hComp η θ ≫ hComp η' θ' = hComp (η ≫ η') (θ ≫ θ') :=
((eComp Cat a b c).map_comp (Y := (_, _)) (_, _) (_, _)).symm
/-- The action on objects of the `EnrichedCategory Cat` coherences proves the category axioms. -/
instance : Category (CatEnriched C) where
id_comp {X Y} f := congrArg (·.obj f) (e_id_comp (V := Cat) X Y)
comp_id {X Y} f := congrArg (·.obj f) (e_comp_id (V := Cat) X Y)
assoc {X Y Z W} f g h := congrArg (·.obj (f, g, h)) (e_assoc (V := Cat) X Y Z W)
/-- The category instance on `CatEnriched C` promotes it to a `Cat` enriched ordinary
category. -/
instance : EnrichedOrdinaryCategory Cat (CatEnriched C) where
homEquiv := Cat.fromChosenTerminalEquiv.symm
homEquiv_comp _ _ := (Equiv.symm_apply_eq Cat.fromChosenTerminalEquiv).mpr rfl
homEquiv_id _ := (Equiv.symm_apply_eq Cat.fromChosenTerminalEquiv).mpr rfl
theorem id_hComp_heq {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') :
HEq (hComp (𝟙 (𝟙 a)) η) η := by
rw [id_eq, ← Functor.map_id]
exact congr_arg_heq (·.map η) (e_id_comp (V := Cat) a b)
theorem id_hComp {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') :
hComp (𝟙 (𝟙 a)) η = eqToHom (id_comp f) ≫ η ≫ eqToHom (id_comp f').symm := by
simp [← heq_eq_eq, id_hComp_heq]
theorem hComp_id_heq {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') :
HEq (hComp η (𝟙 (𝟙 b))) η := by
rw [id_eq, ← Functor.map_id]
exact congr_arg_heq (·.map η) (e_comp_id (V := Cat) a b)
theorem hComp_id {a b : CatEnriched C} {f f' : a ⟶ b} (η : f ⟶ f') :
hComp η (𝟙 (𝟙 b)) = eqToHom (comp_id f) ≫ η ≫ eqToHom (comp_id f').symm := by
simp [← heq_eq_eq, hComp_id_heq]
theorem hComp_assoc_heq {a b c d : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d}
(η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') :
HEq (hComp (hComp η θ) κ) (hComp η (hComp θ κ)) :=
congr_arg_heq (·.map (X := (_, _, _)) (Y := (_, _, _)) (η, θ, κ)) (e_assoc (V := Cat) a b c d)
theorem hComp_assoc {a b c d : CatEnriched C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d}
(η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') :
hComp (hComp η θ) κ =
eqToHom (assoc f g h) ≫ hComp η (hComp θ κ) ≫ eqToHom (assoc f' g' h').symm := by
simp [← heq_eq_eq, hComp_assoc_heq]
instance : Bicategory (CatEnriched C) where
homCategory := inferInstance
whiskerLeft {_ _ _} f {_ _} η := hComp (𝟙 f) η
whiskerRight η h := hComp η (𝟙 h)
associator f g h := eqToIso (assoc f g h)
leftUnitor f := eqToIso (id_comp f)
rightUnitor f := eqToIso (comp_id f)
id_whiskerLeft := id_hComp
comp_whiskerLeft := by simp [← id_hComp_id, hComp_assoc]
whiskerRight_id := hComp_id
whiskerRight_comp := by simp [hComp_assoc]
whisker_assoc := by simp [hComp_assoc]
pentagon f g h i := by
generalize_proofs h1 h2 h3 h4; revert h1 h2 h3 h4
generalize (f ≫ g) ≫ h = x, (g ≫ h) ≫ i = w
rintro rfl _ rfl _; simp
triangle f g := by
generalize_proofs h1 h2 h3; revert h1 h2 h3
generalize 𝟙 _ ≫ g = g, f ≫ 𝟙 _ = f
rintro _ rfl rfl; simp
/-- As the associator and left and right unitors are defined as eqToIso of category axioms, the
bicategory structure on `CatEnriched C` is strict. -/
instance : Bicategory.Strict (CatEnriched C) where
end CatEnriched
end
section
variable {C : Type u} [Category.{v} C] [EnrichedOrdinaryCategory Cat.{v', u'} C]
/-- A type synonym for `C`, which should come equipped with a `Cat`-enriched category structure.
This converts it to a strict bicategory where `Category (X ⟶ Y)` is `(X ⟶[Cat] Y)`. -/
def CatEnrichedOrdinary (C : Type*) := C
namespace CatEnrichedOrdinary
instance : Category (CatEnrichedOrdinary C) := inferInstanceAs (Category C)
instance : EnrichedCategory Cat (CatEnrichedOrdinary C) := inferInstanceAs (EnrichedCategory Cat C)
instance : EnrichedOrdinaryCategory Cat (CatEnrichedOrdinary C) :=
inferInstanceAs (EnrichedOrdinaryCategory Cat C)
/-- The forgetful map from the type alias associated to `EnrichedOrdinaryCategory Cat C` and the
type alias associated to `EnrichedCategory Cat C` is the identity on underlying types. -/
def toBase (a : CatEnrichedOrdinary C) : CatEnriched C := a
/-- The hom-types in a `Cat`-enriched ordinary category are equivalent to the types underlying the
hom-categories. -/
def homEquiv {a b : CatEnrichedOrdinary C} : (a ⟶ b) ≃ (a.toBase ⟶ b.toBase) :=
(eHomEquiv (V := Cat)).trans Cat.fromChosenTerminalEquiv
theorem homEquiv_id {a : CatEnrichedOrdinary C} : homEquiv (𝟙 a) = 𝟙 a.toBase := by
unfold homEquiv
simp only [Equiv.trans_apply]
rw [eHomEquiv_id]
rfl
theorem homEquiv_comp {a b c : CatEnrichedOrdinary C} (f : a ⟶ b) (g : b ⟶ c) :
homEquiv (f ≫ g) = homEquiv f ≫ homEquiv g := by
unfold homEquiv
simp only [Equiv.trans_apply]
rw [eHomEquiv_comp]
rfl
/-- The 2-cells between a parallel pair of 1-cells `f g` in `CatEnrichedOrdinary C` are defined to
be the morphisms in the hom-categories provided by the `EnrichedCategory Cat C` structure between
the corresponding objects. -/
structure Hom {X Y : CatEnrichedOrdinary C} (f g : X ⟶ Y) where mk' ::
/-- A 2-cell from `f` to `g` is a 2-cell from `homEquiv f` to `homEquiv g`. -/
base' : homEquiv f ⟶ homEquiv g
instance {X Y : CatEnrichedOrdinary C} : Quiver (X ⟶ Y) where
Hom f g := Hom f g
/-- A 2-cell in `CatEnrichedOrdinary C` has a corresponding "base" 2-cell in `CatEnriched C`. -/
def Hom.base {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f ⟶ g) :
homEquiv f ⟶ homEquiv g := α.base'
/-- A 2-cell in `CatEnriched C` can be "made" into a 2-cell in `CatEnrichedOrdinary C`. -/
def Hom.mk {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : homEquiv f ⟶ homEquiv g) :
f ⟶ g := .mk' α
@[simp] theorem mk_base {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f ⟶ g) :
Hom.mk (Hom.base α) = α := rfl
@[simp] theorem base_mk {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : homEquiv f ⟶ homEquiv g) :
Hom.base (Hom.mk α) = α := rfl
instance {X Y : CatEnrichedOrdinary C} : CategoryStruct (X ⟶ Y) where
id f := Hom.mk (𝟙 (homEquiv f))
comp α β := Hom.mk (Hom.base α ≫ Hom.base β)
theorem Hom.id_eq {X Y : CatEnrichedOrdinary C} (f : X ⟶ Y) :
𝟙 f = Hom.mk (𝟙 (homEquiv f)) := rfl
@[simp] theorem Hom.base_id {X Y : CatEnrichedOrdinary C} (f : X ⟶ Y) :
Hom.base (𝟙 f) = 𝟙 (homEquiv f) := rfl
theorem Hom.comp_eq {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y}
(α : f ⟶ g) (β : g ⟶ h) : (α ≫ β) = Hom.mk (Hom.base α ≫ Hom.base β) := rfl
@[simp] theorem Hom.base_comp {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y}
(α : f ⟶ g) (β : g ⟶ h) : Hom.base (α ≫ β) = Hom.base α ≫ Hom.base β := rfl
theorem Hom.mk_comp {X Y : CatEnrichedOrdinary C} {f g h : X ⟶ Y}
(α : homEquiv f ⟶ homEquiv g) (β : homEquiv g ⟶ homEquiv h) :
Hom.mk (α ≫ β) = Hom.mk α ≫ Hom.mk β := rfl
@[ext] theorem Hom.ext {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α β : f ⟶ g)
(H : Hom.base α = Hom.base β) : α = β := by cases α; cases β; cases H; rfl
/-- A `Cat`-enriched ordinary category comes with hom-categories `X ⟶[Cat] Y` whose underlying type
of objects is equivalent to the type `X ⟶ Y` defined by the category structure on `C`. The following
definition transfers the category structure to the latter type of objects. -/
instance {X Y : CatEnrichedOrdinary C} : Category (X ⟶ Y) where
@[simp] theorem Hom.base_eqToHom {X Y : CatEnrichedOrdinary C} {f g : X ⟶ Y} (α : f = g) :
Hom.base (eqToHom α) = eqToHom (congrArg _ α) := by cases α; rfl
/-- The horizontal composition on 2-morphisms is defined using the action on arrows of the
composition bifunctor from the enriched category structure. -/
def hComp {a b c : CatEnrichedOrdinary C} {f f' : a ⟶ b} {g g' : b ⟶ c}
(η : f ⟶ f') (θ : g ⟶ g') : f ≫ g ⟶ f' ≫ g' :=
.mk <|
eqToHom (homEquiv_comp f g) ≫ CatEnriched.hComp (Hom.base η) (Hom.base θ) ≫
eqToHom (homEquiv_comp f' g').symm
@[simp]
theorem id_hComp_id {a b c : CatEnrichedOrdinary C} (f : a ⟶ b) (g : b ⟶ c) :
hComp (𝟙 f) (𝟙 g) = 𝟙 (f ≫ g) := by simp [hComp, Hom.id_eq]
@[simp]
theorem eqToHom_hComp_eqToHom {a b c : CatEnrichedOrdinary C}
{f f' : a ⟶ b} (α : f = f') {g g' : b ⟶ c} (β : g = g') :
hComp (eqToHom α) (eqToHom β) = eqToHom (α ▸ β ▸ rfl) := by cases α; cases β; simp
/-- The interchange law for horizontal and vertical composition of 2-cells in a bicategory. -/
@[simp]
theorem hComp_comp {a b c : CatEnrichedOrdinary C} {f₁ f₂ f₃ : a ⟶ b} {g₁ g₂ g₃ : b ⟶ c}
(η : f₁ ⟶ f₂) (η' : f₂ ⟶ f₃) (θ : g₁ ⟶ g₂) (θ' : g₂ ⟶ g₃) :
hComp η θ ≫ hComp η' θ' = hComp (η ≫ η') (θ ≫ θ') := by
simp [hComp, ← CatEnriched.hComp_comp, Hom.comp_eq]
theorem id_hComp {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') :
hComp (𝟙 (𝟙 a)) η = eqToHom (id_comp f) ≫ η ≫ eqToHom (id_comp f').symm := by
ext
simp only [hComp, Hom.base_id, base_mk, ← heq_eq_eq, eqToHom_comp_heq_iff, comp_eqToHom_heq_iff]
rw [homEquiv_id]; simp [CatEnriched.id_hComp_heq]
theorem id_hComp_heq {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') :
HEq (hComp (𝟙 (𝟙 a)) η) η := by simp [id_hComp]
theorem hComp_id {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') :
hComp η (𝟙 (𝟙 b)) = eqToHom (comp_id f) ≫ η ≫ eqToHom (comp_id f').symm := by
ext
simp only [hComp, Hom.base_id, base_mk, ← heq_eq_eq, eqToHom_comp_heq_iff, comp_eqToHom_heq_iff]
rw [homEquiv_id]
simp [CatEnriched.hComp_id_heq]
theorem hComp_id_heq {a b : CatEnrichedOrdinary C} {f f' : a ⟶ b} (η : f ⟶ f') :
HEq (hComp η (𝟙 (𝟙 b))) η := by simp [hComp_id]
theorem id_eq_eqToHom {C} [Category C] (X : C) : 𝟙 X = eqToHom rfl := rfl
theorem hComp_assoc {a b c d : CatEnrichedOrdinary C} {f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d}
(η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') :
hComp (hComp η θ) κ =
eqToHom (assoc f g h) ≫ hComp η (hComp θ κ) ≫ eqToHom (assoc f' g' h').symm := by
ext
simp only [hComp, base_mk, Hom.base_comp, Hom.base_eqToHom,
← heq_eq_eq, heq_eqToHom_comp_iff, heq_comp_eqToHom_iff,
eqToHom_comp_heq_iff, comp_eqToHom_heq_iff]
conv => enter [1,2]; exact ((id_comp _).trans (comp_id _)).symm
conv => enter [2,1]; exact ((id_comp _).trans (comp_id _)).symm
iterate 4 rw [← CatEnriched.hComp_comp, id_eq_eqToHom, CatEnriched.eqToHom_hComp_eqToHom]
simp [CatEnriched.hComp_assoc_heq]
theorem hComp_assoc_heq {a b c d : CatEnrichedOrdinary C}
{f f' : a ⟶ b} {g g' : b ⟶ c} {h h' : c ⟶ d} (η : f ⟶ f') (θ : g ⟶ g') (κ : h ⟶ h') :
HEq (hComp (hComp η θ) κ) (hComp η (hComp θ κ)) := by simp [hComp_assoc]
instance : Bicategory (CatEnrichedOrdinary C) where
homCategory := inferInstance
whiskerLeft {_ _ _} f {_ _} η := hComp (𝟙 f) η
whiskerRight η h := hComp η (𝟙 h)
associator f g h := eqToIso (assoc f g h)
leftUnitor f := eqToIso (id_comp f)
rightUnitor f := eqToIso (comp_id f)
id_whiskerLeft := by simp [id_hComp]
comp_whiskerLeft := by simp [← hComp_assoc]
whiskerRight_id := by simp [hComp_id]
whiskerRight_comp := by simp [hComp_assoc]
whisker_assoc := by simp [hComp_assoc]
pentagon := by simp [id_eq_eqToHom, -eqToHom_refl]
triangle := by simp [id_eq_eqToHom, -eqToHom_refl]
/-- As the associator and left and right unitors are defined as eqToIso of category axioms, the
bicategory structure on `CatEnrichedOrdinary C` is strict. -/
instance : Bicategory.Strict (CatEnrichedOrdinary C) where
end CatEnrichedOrdinary
end
end CategoryTheory
|
Comma.lean
|
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.CategoryTheory.Comma.Over.Basic
import Mathlib.CategoryTheory.MorphismProperty.Composition
/-!
# Subcategories of comma categories defined by morphism properties
Given functors `L : A ⥤ T` and `R : B ⥤ T` and morphism properties `P`, `Q` and `W`
on `T`, A` and `B` respectively, we define the subcategory `P.Comma L R Q W` of
`Comma L R` where
- objects are objects of `Comma L R` with the structural morphism satisfying `P`, and
- morphisms are morphisms of `Comma L R` where the left morphism satisfies `Q` and the
right morphism satisfies `W`.
For an object `X : T`, this specializes to `P.Over Q X` which is the subcategory of `Over X`
where the structural morphism satisfies `P` and where the horizontal morphisms satisfy `Q`.
Common examples of the latter are e.g. the category of schemes étale (finite, affine, etc.)
over a base `X`. Here `Q = ⊤`.
## Implementation details
- We provide the general constructor `P.Comma L R Q W` to obtain `Over X` and `Under X` as
special cases of the more general setup.
- Most results are developed only in the case where `Q = ⊤` and `W = ⊤`, but the definition
is setup in the general case to allow for a later generalization if needed.
-/
namespace CategoryTheory.MorphismProperty
open Limits
section Comma
variable {A : Type*} [Category A] {B : Type*} [Category B] {T : Type*} [Category T]
(L : A ⥤ T) (R : B ⥤ T)
lemma costructuredArrow_iso_iff (P : MorphismProperty T) [P.RespectsIso]
{L : A ⥤ T} {X : T} {f g : CostructuredArrow L X} (e : f ≅ g) :
P f.hom ↔ P g.hom :=
P.comma_iso_iff e
lemma over_iso_iff (P : MorphismProperty T) [P.RespectsIso] {X : T} {f g : Over X} (e : f ≅ g) :
P f.hom ↔ P g.hom :=
P.comma_iso_iff e
variable (P : MorphismProperty T) (Q : MorphismProperty A) (W : MorphismProperty B)
/-- `P.Comma L R Q W` is the subcategory of `Comma L R` consisting of
objects `X : Comma L R` where `X.hom` satisfies `P`. The morphisms are given by
morphisms in `Comma L R` where the left one satisfies `Q` and the right one satisfies `W`. -/
@[ext]
protected structure Comma (Q : MorphismProperty A) (W : MorphismProperty B) extends Comma L R where
prop : P toComma.hom
namespace Comma
variable {L R P Q W}
/-- A morphism in `P.Comma L R Q W` is a morphism in `Comma L R` where the left
hom satisfies `Q` and the right one satisfies `W`. -/
@[ext]
structure Hom (X Y : P.Comma L R Q W) extends CommaMorphism X.toComma Y.toComma where
prop_hom_left : Q toCommaMorphism.left
prop_hom_right : W toCommaMorphism.right
/-- The underlying morphism of objects in `Comma L R`. -/
abbrev Hom.hom {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : X.toComma ⟶ Y.toComma :=
f.toCommaMorphism
@[simp, nolint simpVarHead]
lemma Hom.hom_mk {X Y : P.Comma L R Q W} (f : CommaMorphism X.toComma Y.toComma) (hf) (hg) :
Comma.Hom.hom ⟨f, hf, hg⟩ = f := rfl
lemma Hom.hom_left {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : f.hom.left = f.left := rfl
lemma Hom.hom_right {X Y : P.Comma L R Q W} (f : Comma.Hom X Y) : f.hom.right = f.right := rfl
/-- See Note [custom simps projection] -/
def Hom.Simps.hom {X Y : P.Comma L R Q W} (f : X.Hom Y) :
X.toComma ⟶ Y.toComma :=
f.hom
initialize_simps_projections Comma.Hom (toCommaMorphism → hom)
/-- The identity morphism of an object in `P.Comma L R Q W`. -/
@[simps]
def id [Q.ContainsIdentities] [W.ContainsIdentities] (X : P.Comma L R Q W) : Comma.Hom X X where
left := 𝟙 X.left
right := 𝟙 X.right
prop_hom_left := Q.id_mem X.toComma.left
prop_hom_right := W.id_mem X.toComma.right
/-- Composition of morphisms in `P.Comma L R Q W`. -/
@[simps]
def Hom.comp [Q.IsStableUnderComposition] [W.IsStableUnderComposition] {X Y Z : P.Comma L R Q W}
(f : Comma.Hom X Y) (g : Comma.Hom Y Z) :
Comma.Hom X Z where
left := f.left ≫ g.left
right := f.right ≫ g.right
prop_hom_left := Q.comp_mem _ _ f.prop_hom_left g.prop_hom_left
prop_hom_right := W.comp_mem _ _ f.prop_hom_right g.prop_hom_right
variable [Q.IsMultiplicative] [W.IsMultiplicative]
variable (L R P Q W) in
instance : Category (P.Comma L R Q W) where
Hom X Y := X.Hom Y
id X := X.id
comp f g := f.comp g
lemma toCommaMorphism_eq_hom {X Y : P.Comma L R Q W} (f : X ⟶ Y) : f.toCommaMorphism = f.hom := rfl
/-- Alternative `ext` lemma for `Comma.Hom`. -/
@[ext]
lemma Hom.ext' {X Y : P.Comma L R Q W} {f g : X ⟶ Y} (h : f.hom = g.hom) :
f = g := Comma.Hom.ext
(congrArg CommaMorphism.left h)
(congrArg CommaMorphism.right h)
@[simp]
lemma id_hom (X : P.Comma L R Q W) : (𝟙 X : X ⟶ X).hom = 𝟙 X.toComma := rfl
@[simp]
lemma comp_hom {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).hom = f.hom ≫ g.hom := rfl
@[reassoc]
lemma comp_left {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).left = f.left ≫ g.left := rfl
@[reassoc]
lemma comp_right {X Y Z : P.Comma L R Q W} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).right = f.right ≫ g.right := rfl
/-- If `i` is an isomorphism in `Comma L R`, it is also a morphism in `P.Comma L R Q W`. -/
@[simps hom]
def homFromCommaOfIsIso [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W}
(i : X.toComma ⟶ Y.toComma) [IsIso i] :
X ⟶ Y where
__ := i
prop_hom_left := Q.of_isIso i.left
prop_hom_right := W.of_isIso i.right
instance [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (i : X.toComma ⟶ Y.toComma)
[IsIso i] : IsIso (homFromCommaOfIsIso i) := by
constructor
use homFromCommaOfIsIso (inv i)
constructor <;> ext : 1 <;> simp
/-- Any isomorphism between objects of `P.Comma L R Q W` in `Comma L R` is also an isomorphism
in `P.Comma L R Q W`. -/
@[simps]
def isoFromComma [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W}
(i : X.toComma ≅ Y.toComma) : X ≅ Y where
hom := homFromCommaOfIsIso i.hom
inv := homFromCommaOfIsIso i.inv
/-- Constructor for isomorphisms in `P.Comma L R Q W` from isomorphisms of the left and right
components and naturality in the forward direction. -/
@[simps!]
def isoMk [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W} (l : X.left ≅ Y.left)
(r : X.right ≅ Y.right) (h : L.map l.hom ≫ Y.hom = X.hom ≫ R.map r.hom := by cat_disch) :
X ≅ Y :=
isoFromComma (CategoryTheory.Comma.isoMk l r h)
variable (L R P Q W)
/-- The forgetful functor. -/
@[simps]
def forget : P.Comma L R Q W ⥤ Comma L R where
obj X := X.toComma
map f := f.hom
instance : (forget L R P Q W).Faithful where
map_injective := Comma.Hom.ext'
variable {L R P Q W}
instance {X Y : P.Comma L R Q W} (f : X ⟶ Y) [IsIso f] : IsIso f.hom :=
(forget L R P Q W).map_isIso f
lemma hom_homFromCommaOfIsIso [Q.RespectsIso] [W.RespectsIso] {X Y : P.Comma L R Q W}
(i : X ⟶ Y) [IsIso i.hom] :
homFromCommaOfIsIso i.hom = i :=
rfl
lemma inv_hom {X Y : P.Comma L R Q W} (f : X ⟶ Y) [IsIso f] : (inv f).hom = inv f.hom := by
apply IsIso.eq_inv_of_hom_inv_id
rw [← comp_hom, IsIso.hom_inv_id, id_hom]
variable (L R P Q W)
instance [Q.RespectsIso] [W.RespectsIso] : (forget L R P Q W).ReflectsIsomorphisms where
reflects f hf := by
simp only [forget_obj, forget_map] at hf
rw [← hom_homFromCommaOfIsIso f]
infer_instance
/-- The forgetful functor from the full subcategory of `Comma L R` defined by `P` is
fully faithful. -/
def forgetFullyFaithful : (forget L R P ⊤ ⊤).FullyFaithful where
preimage {X Y} f := ⟨f, trivial, trivial⟩
instance : (forget L R P ⊤ ⊤).Full :=
Functor.FullyFaithful.full (forgetFullyFaithful L R P)
section
variable {L R}
@[simp]
lemma eqToHom_left {X Y : P.Comma L R Q W} (h : X = Y) :
(eqToHom h).left = eqToHom (by rw [h]) := by
subst h
rfl
@[simp]
lemma eqToHom_right {X Y : P.Comma L R Q W} (h : X = Y) :
(eqToHom h).right = eqToHom (by rw [h]) := by
subst h
rfl
end
section
variable {P P' : MorphismProperty T} {Q Q' : MorphismProperty A} {W W' : MorphismProperty B}
(hP : P ≤ P') (hQ : Q ≤ Q') (hW : W ≤ W')
variable [Q.IsMultiplicative] [Q'.IsMultiplicative] [W.IsMultiplicative] [W'.IsMultiplicative]
/-- Weaken the conditions on all components. -/
def changeProp : P.Comma L R Q W ⥤ P'.Comma L R Q' W' where
obj X := ⟨X.toComma, hP _ X.2⟩
map f := ⟨f.toCommaMorphism, hQ _ f.2, hW _ f.3⟩
/-- Weakening the condition on the structure morphisms is fully faithful. -/
def fullyFaithfulChangeProp :
(changeProp (Q := Q) (W := W) L R hP le_rfl le_rfl).FullyFaithful where
preimage f := ⟨f.toCommaMorphism, f.2, f.3⟩
instance : (changeProp L R hP hQ hW).Faithful where
map_injective {X Y} f g h := by ext : 1; exact congr($(h).hom)
instance : (changeProp (Q := Q) (W := W) L R hP le_rfl le_rfl).Full :=
(fullyFaithfulChangeProp ..).full
end
section Functoriality
variable {L R P Q W}
variable {L₁ L₂ L₃ : A ⥤ T} {R₁ R₂ R₃ : B ⥤ T}
/-- Lift a functor `F : C ⥤ Comma L R` to the subcategory `P.Comma L R Q W` under
suitable assumptions on `F`. -/
@[simps obj_toComma map_hom]
def lift {C : Type*} [Category C] (F : C ⥤ Comma L R)
(hP : ∀ X, P (F.obj X).hom)
(hQ : ∀ {X Y} (f : X ⟶ Y), Q (F.map f).left)
(hW : ∀ {X Y} (f : X ⟶ Y), W (F.map f).right) :
C ⥤ P.Comma L R Q W where
obj X :=
{ __ := F.obj X
prop := hP X }
map {X Y} f :=
{ __ := F.map f
prop_hom_left := hQ f
prop_hom_right := hW f }
variable (R) in
/-- A natural transformation `L₁ ⟶ L₂` induces a functor `P.Comma L₂ R Q W ⥤ P.Comma L₁ R Q W`. -/
@[simps!]
def mapLeft (l : L₁ ⟶ L₂) (hl : ∀ X : P.Comma L₂ R Q W, P (l.app X.left ≫ X.hom)) :
P.Comma L₂ R Q W ⥤ P.Comma L₁ R Q W :=
lift (forget _ _ _ _ _ ⋙ CategoryTheory.Comma.mapLeft R l) hl
(fun f ↦ f.prop_hom_left) (fun f ↦ f.prop_hom_right)
variable (L) in
/-- A natural transformation `R₁ ⟶ R₂` induces a functor `P.Comma L R₁ Q W ⥤ P.Comma L R₂ Q W`. -/
@[simps!]
def mapRight (r : R₁ ⟶ R₂) (hr : ∀ X : P.Comma L R₁ Q W, P (X.hom ≫ r.app X.right)) :
P.Comma L R₁ Q W ⥤ P.Comma L R₂ Q W :=
lift (forget _ _ _ _ _ ⋙ CategoryTheory.Comma.mapRight L r) hr
(fun f ↦ f.prop_hom_left) (fun f ↦ f.prop_hom_right)
end Functoriality
end Comma
end Comma
section Over
variable {T : Type*} [Category T] (P Q : MorphismProperty T) (X : T) [Q.IsMultiplicative]
/-- Given a morphism property `P` on a category `C` and an object `X : C`, this is the
subcategory of `Over X` defined by `P` where morphisms satisfy `Q`. -/
protected abbrev Over : Type _ :=
P.Comma (Functor.id T) (Functor.fromPUnit.{0} X) Q ⊤
/-- The forgetful functor from the full subcategory of `Over X` defined by `P` to `Over X`. -/
protected abbrev Over.forget : P.Over Q X ⥤ Over X :=
Comma.forget (Functor.id T) (Functor.fromPUnit.{0} X) P Q ⊤
instance : (Over.forget P ⊤ X).Faithful := inferInstanceAs <| (Comma.forget _ _ _ _ _).Faithful
instance : (Over.forget P ⊤ X).Full := inferInstanceAs <| (Comma.forget _ _ _ _ _).Full
variable {P Q X}
/-- Construct a morphism in `P.Over Q X` from a morphism in `Over.X`. -/
@[simps hom]
def Over.Hom.mk {A B : P.Over Q X} (f : A.toComma ⟶ B.toComma) (hf : Q f.left) : A ⟶ B where
__ := f
prop_hom_left := hf
prop_hom_right := trivial
variable (Q) in
/-- Make an object of `P.Over Q X` from a morphism `f : A ⟶ X` and a proof of `P f`. -/
@[simps hom left]
protected def Over.mk {A : T} (f : A ⟶ X) (hf : P f) : P.Over Q X where
left := A
right := ⟨⟨⟩⟩
hom := f
prop := hf
/-- Make a morphism in `P.Over Q X` from a morphism in `T` with compatibilities. -/
@[simps hom]
protected def Over.homMk {A B : P.Over Q X} (f : A.left ⟶ B.left)
(w : f ≫ B.hom = A.hom := by cat_disch) (hf : Q f := by trivial) : A ⟶ B where
__ := CategoryTheory.Over.homMk f w
prop_hom_left := hf
prop_hom_right := trivial
/-- Make an isomorphism in `P.Over Q X` from an isomorphism in `T` with compatibilities. -/
@[simps! hom_left inv_left]
protected def Over.isoMk [Q.RespectsIso] {A B : P.Over Q X} (f : A.left ≅ B.left)
(w : f.hom ≫ B.hom = A.hom := by cat_disch) : A ≅ B :=
Comma.isoMk f (Discrete.eqToIso' rfl)
@[ext]
lemma Over.Hom.ext {A B : P.Over Q X} {f g : A ⟶ B} (h : f.left = g.left) : f = g := by
ext
· exact h
· simp
@[reassoc]
lemma Over.w {A B : P.Over Q X} (f : A ⟶ B) :
f.left ≫ B.hom = A.hom := by
simp
end Over
section Under
variable {T : Type*} [Category T] (P Q : MorphismProperty T) (X : T) [Q.IsMultiplicative]
/-- Given a morphism property `P` on a category `C` and an object `X : C`, this is the
subcategory of `Under X` defined by `P` where morphisms satisfy `Q`. -/
protected abbrev Under : Type _ :=
P.Comma (Functor.fromPUnit.{0} X) (Functor.id T) ⊤ Q
/-- The forgetful functor from the full subcategory of `Under X` defined by `P` to `Under X`. -/
protected abbrev Under.forget : P.Under Q X ⥤ Under X :=
Comma.forget (Functor.fromPUnit.{0} X) (Functor.id T) P ⊤ Q
instance : (Under.forget P ⊤ X).Faithful := inferInstanceAs <| (Comma.forget _ _ _ _ _).Faithful
instance : (Under.forget P ⊤ X).Full := inferInstanceAs <| (Comma.forget _ _ _ _ _).Full
variable {P Q X}
/-- Construct a morphism in `P.Under Q X` from a morphism in `Under.X`. -/
@[simps hom]
def Under.Hom.mk {A B : P.Under Q X} (f : A.toComma ⟶ B.toComma) (hf : Q f.right) : A ⟶ B where
__ := f
prop_hom_left := trivial
prop_hom_right := hf
variable (Q) in
/-- Make an object of `P.Under Q X` from a morphism `f : A ⟶ X` and a proof of `P f`. -/
@[simps hom left]
protected def Under.mk {A : T} (f : X ⟶ A) (hf : P f) : P.Under Q X where
left := ⟨⟨⟩⟩
right := A
hom := f
prop := hf
/-- Make a morphism in `P.Under Q X` from a morphism in `T` with compatibilities. -/
@[simps hom]
protected def Under.homMk {A B : P.Under Q X} (f : A.right ⟶ B.right)
(w : A.hom ≫ f = B.hom := by cat_disch) (hf : Q f := by trivial) : A ⟶ B where
__ := CategoryTheory.Under.homMk f w
prop_hom_left := trivial
prop_hom_right := hf
/-- Make an isomorphism in `P.Under Q X` from an isomorphism in `T` with compatibilities. -/
@[simps! hom_right inv_right]
protected def Under.isoMk [Q.RespectsIso] {A B : P.Under Q X} (f : A.right ≅ B.right)
(w : A.hom ≫ f.hom = B.hom := by cat_disch) : A ≅ B :=
Comma.isoMk (Discrete.eqToIso' rfl) f
@[ext]
lemma Under.Hom.ext {A B : P.Under Q X} {f g : A ⟶ B} (h : f.right = g.right) : f = g := by
ext
· simp
· exact h
@[reassoc]
lemma Under.w {A B : P.Under Q X} (f : A ⟶ B) :
A.hom ≫ f.right = B.hom := by
simp
end Under
end CategoryTheory.MorphismProperty
|
HashCommandLinter.lean
|
/-
Copyright (c) 2024 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Lean.Elab.Command
-- Import this linter explicitly to ensure that
-- this file has a valid copyright header and module docstring.
import Mathlib.Tactic.Linter.Header
/-!
# `#`-command linter
The `#`-command linter produces a warning when a command starting with `#` is used *and*
* either the command emits no message;
* or `warningAsError` is set to `true`.
The rationale behind this is that `#`-commands are intended to be transient:
they provide useful information in development, but are not intended to be present in final code.
Most of them are noisy and get picked up anyway by CI, but even the quiet ones are not expected to
outlive their in-development status.
-/
namespace Mathlib.Linter
/--
The linter emits a warning on any command beginning with `#` that itself emits no message.
For example, `#guard true` and `#check_tactic True ~> True by skip` trigger a message.
There is a list of silent `#`-command that are allowed.
-/
register_option linter.hashCommand : Bool := {
defValue := false
descr := "enable the `#`-command linter"
}
namespace HashCommandLinter
open Lean Elab Linter
open Command in
/-- Exactly like `withSetOptionIn`, but recursively discards nested uses of `in`.
Intended to be used in the `hashCommand` linter, where we want to enter `set_option` `in` commands.
-/
private partial def withSetOptionIn' (cmd : CommandElab) : CommandElab := fun stx => do
if stx.getKind == ``Lean.Parser.Command.in then
if stx[0].getKind == ``Lean.Parser.Command.set_option then
let opts ← Elab.elabSetOption stx[0][1] stx[0][3]
withScope (fun scope => { scope with opts }) do
withSetOptionIn' cmd stx[2]
else
withSetOptionIn' cmd stx[2]
else
cmd stx
/-- `allowed_commands` is the `HashSet` of `#`-commands that are allowed in 'Mathlib'. -/
private abbrev allowed_commands : Std.HashSet String := { "#adaptation_note" }
/-- Checks that no command beginning with `#` is present in 'Mathlib',
except for the ones in `allowed_commands`.
If `warningAsError` is `true`, then the linter logs an info (rather than a warning).
This means that CI will eventually fail on `#`-commands, but does not stop it from continuing.
However, in order to avoid local clutter, when `warningAsError` is `false`, the linter
logs a warning only for the `#`-commands that do not already emit a message. -/
def hashCommandLinter : Linter where run := withSetOptionIn' fun stx => do
if getLinterValue linter.hashCommand (← getLinterOptions) &&
((← get).messages.reportedPlusUnreported.isEmpty || warningAsError.get (← getOptions))
then
if let some sa := stx.getHead? then
let a := sa.getAtomVal
if (a.get ⟨0⟩ == '#' && ! allowed_commands.contains a) then
let msg := m!"`#`-commands, such as '{a}', are not allowed in 'Mathlib'"
if warningAsError.get (← getOptions) then
logInfoAt sa (msg ++ " [linter.hashCommand]")
else Linter.logLint linter.hashCommand sa msg
initialize addLinter hashCommandLinter
end HashCommandLinter
|
Integrability.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.BoxIntegral.Basic
import Mathlib.MeasureTheory.Integral.Bochner.Set
import Mathlib.Tactic.Generalize
/-!
# McShane integrability vs Bochner integrability
In this file we prove that any Bochner integrable function is McShane integrable (hence, it is
Henstock and `GP` integrable) with the same integral. The proof is based on
[Russel A. Gordon, *The integrals of Lebesgue, Denjoy, Perron, and Henstock*][Gordon55].
We deduce that the same is true for the Riemann integral for continuous functions.
## Tags
integral, McShane integral, Bochner integral
-/
open scoped NNReal ENNReal Topology
universe u v
variable {ι : Type u} {E : Type v} [Fintype ι] [NormedAddCommGroup E] [NormedSpace ℝ E]
open MeasureTheory Metric Set Finset Filter BoxIntegral
namespace BoxIntegral
/-- The indicator function of a measurable set is McShane integrable with respect to any
locally-finite measure. -/
theorem hasIntegralIndicatorConst (l : IntegrationParams) (hl : l.bRiemann = false)
{s : Set (ι → ℝ)} (hs : MeasurableSet s) (I : Box ι) (y : E) (μ : Measure (ι → ℝ))
[IsLocallyFiniteMeasure μ] :
HasIntegral.{u, v, v} I l (s.indicator fun _ => y) μ.toBoxAdditive.toSMul
(μ.real (s ∩ I) • y) := by
refine HasIntegral.of_mul ‖y‖ fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.le; rw [NNReal.coe_pos] at ε0
/- First we choose a closed set `F ⊆ s ∩ I.Icc` and an open set `U ⊇ s` such that
both `(s ∩ I.Icc) \ F` and `U \ s` have measure less than `ε`. -/
have A : μ (s ∩ Box.Icc I) ≠ ∞ :=
((measure_mono Set.inter_subset_right).trans_lt (I.measure_Icc_lt_top μ)).ne
have B : μ (s ∩ I) ≠ ∞ :=
((measure_mono Set.inter_subset_right).trans_lt (I.measure_coe_lt_top μ)).ne
obtain ⟨F, hFs, hFc, hμF⟩ : ∃ F, F ⊆ s ∩ Box.Icc I ∧ IsClosed F ∧ μ ((s ∩ Box.Icc I) \ F) < ε :=
(hs.inter I.measurableSet_Icc).exists_isClosed_diff_lt A (ENNReal.coe_pos.2 ε0).ne'
obtain ⟨U, hsU, hUo, hUt, hμU⟩ :
∃ U, s ∩ Box.Icc I ⊆ U ∧ IsOpen U ∧ μ U < ∞ ∧ μ (U \ (s ∩ Box.Icc I)) < ε :=
(hs.inter I.measurableSet_Icc).exists_isOpen_diff_lt A (ENNReal.coe_pos.2 ε0).ne'
/- Then we choose `r` so that `closed_ball x (r x) ⊆ U` whenever `x ∈ s ∩ I.Icc` and
`closed_ball x (r x)` is disjoint with `F` otherwise. -/
have : ∀ x ∈ s ∩ Box.Icc I, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ U := fun x hx => by
rcases nhds_basis_closedBall.mem_iff.1 (hUo.mem_nhds <| hsU hx) with ⟨r, hr₀, hr⟩
exact ⟨⟨r, hr₀⟩, hr⟩
choose! rs hrsU using this
have : ∀ x ∈ Box.Icc I \ s, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ Fᶜ := fun x hx => by
obtain ⟨r, hr₀, hr⟩ :=
nhds_basis_closedBall.mem_iff.1 (hFc.isOpen_compl.mem_nhds fun hx' => hx.2 (hFs hx').1)
exact ⟨⟨r, hr₀⟩, hr⟩
choose! rs' hrs'F using this
classical
set r : (ι → ℝ) → Ioi (0 : ℝ) := s.piecewise rs rs'
refine ⟨fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ hπp => ?_⟩; rw [mul_comm]
/- Then the union of boxes `J ∈ π` such that `π.tag ∈ s` includes `F` and is included by `U`,
hence its measure is `ε`-close to the measure of `s`. -/
dsimp [integralSum]
simp only [dist_eq_norm, ← indicator_const_smul_apply, sum_indicator_eq_sum_filter, ← sum_smul,
← sub_smul, norm_smul, Real.norm_eq_abs, ← Prepartition.filter_boxes,
← Prepartition.measure_iUnion_toReal]
gcongr
set t := (π.filter (π.tag · ∈ s)).iUnion
change abs (μ.real t - μ.real (s ∩ I)) ≤ ε
have htU : t ⊆ U ∩ I := by
simp only [t, TaggedPrepartition.iUnion_def, iUnion_subset_iff, TaggedPrepartition.mem_filter,
and_imp]
refine fun J hJ hJs x hx => ⟨hrsU _ ⟨hJs, π.tag_mem_Icc J⟩ ?_, π.le_of_mem' J hJ hx⟩
simpa only [r, s.piecewise_eq_of_mem _ _ hJs] using hπ.1 J hJ (Box.coe_subset_Icc hx)
refine abs_sub_le_iff.2 ⟨?_, ?_⟩
· refine (ENNReal.le_toReal_sub B).trans (ENNReal.toReal_le_coe_of_le_coe ?_)
refine (tsub_le_tsub (measure_mono htU) le_rfl).trans (le_measure_diff.trans ?_)
refine (measure_mono fun x hx => ?_).trans hμU.le
exact ⟨hx.1.1, fun hx' => hx.2 ⟨hx'.1, hx.1.2⟩⟩
· have hμt : μ t ≠ ∞ := ((measure_mono (htU.trans inter_subset_left)).trans_lt hUt).ne
refine (ENNReal.le_toReal_sub hμt).trans (ENNReal.toReal_le_coe_of_le_coe ?_)
refine le_measure_diff.trans ((measure_mono ?_).trans hμF.le)
rintro x ⟨⟨hxs, hxI⟩, hxt⟩
refine ⟨⟨hxs, Box.coe_subset_Icc hxI⟩, fun hxF => hxt ?_⟩
simp only [t, TaggedPrepartition.iUnion_def, TaggedPrepartition.mem_filter, Set.mem_iUnion]
rcases hπp x hxI with ⟨J, hJπ, hxJ⟩
refine ⟨J, ⟨hJπ, ?_⟩, hxJ⟩
contrapose hxF
refine hrs'F _ ⟨π.tag_mem_Icc J, hxF⟩ ?_
simpa only [r, s.piecewise_eq_of_notMem _ _ hxF] using hπ.1 J hJπ (Box.coe_subset_Icc hxJ)
/-- If `f` is a.e. equal to zero on a rectangular box, then it has McShane integral zero on this
box. -/
theorem HasIntegral.of_aeEq_zero {l : IntegrationParams} {I : Box ι} {f : (ι → ℝ) → E}
{μ : Measure (ι → ℝ)} [IsLocallyFiniteMeasure μ] (hf : f =ᵐ[μ.restrict I] 0)
(hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul 0 := by
/- Each set `{x | n < ‖f x‖ ≤ n + 1}`, `n : ℕ`, has measure zero. We cover it by an open set of
measure less than `ε / 2 ^ n / (n + 1)`. Then the norm of the integral sum is less than `ε`. -/
refine hasIntegral_iff.2 fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.lt.le; rw [gt_iff_lt, NNReal.coe_pos] at ε0
rcases NNReal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩
haveI := Fact.mk (I.measure_coe_lt_top μ)
change μ.restrict I {x | f x ≠ 0} = 0 at hf
set N : (ι → ℝ) → ℕ := fun x => ⌈‖f x‖⌉₊
have N0 : ∀ {x}, N x = 0 ↔ f x = 0 := by simp [N]
have : ∀ n, ∃ U, N ⁻¹' {n} ⊆ U ∧ IsOpen U ∧ μ.restrict I U < δ n / n := fun n ↦ by
refine (N ⁻¹' {n}).exists_isOpen_lt_of_lt _ ?_
rcases n with - | n
· simp [ENNReal.div_zero (ENNReal.coe_pos.2 (δ0 _)).ne']
· refine (measure_mono_null ?_ hf).le.trans_lt ?_
· exact fun x hxN hxf => n.succ_ne_zero ((Eq.symm hxN).trans <| N0.2 hxf)
· simp [(δ0 _).ne']
choose U hNU hUo hμU using this
have : ∀ x, ∃ r : Ioi (0 : ℝ), closedBall x r ⊆ U (N x) := fun x => by
obtain ⟨r, hr₀, hr⟩ := nhds_basis_closedBall.mem_iff.1 ((hUo _).mem_nhds (hNU _ rfl))
exact ⟨⟨r, hr₀⟩, hr⟩
choose r hrU using this
refine ⟨fun _ => r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ _ => ?_⟩
rw [dist_eq_norm, sub_zero, ← integralSum_fiberwise fun J => N (π.tag J)]
refine le_trans ?_ (NNReal.coe_lt_coe.2 hcε).le
refine (norm_sum_le_of_le _ ?_).trans
(sum_le_hasSum _ (fun n _ => (δ n).2) (NNReal.hasSum_coe.2 hδc))
rintro n -
dsimp [integralSum]
have : ∀ J ∈ π.filter fun J => N (π.tag J) = n,
‖μ.real ↑J • f (π.tag J)‖ ≤ μ.real J * n := fun J hJ ↦ by
rw [TaggedPrepartition.mem_filter] at hJ
rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg]
gcongr
exact hJ.2 ▸ Nat.le_ceil _
refine (norm_sum_le_of_le _ this).trans ?_; clear this
rw [← sum_mul, ← Prepartition.measure_iUnion_toReal]
let m := μ (π.filter fun J => N (π.tag J) = n).iUnion
change m.toReal * ↑n ≤ ↑(δ n)
have : m < δ n / n := by
simp only [Measure.restrict_apply (hUo _).measurableSet] at hμU
refine (measure_mono ?_).trans_lt (hμU _)
simp only [Set.subset_def, TaggedPrepartition.mem_iUnion, TaggedPrepartition.mem_filter]
rintro x ⟨J, ⟨hJ, rfl⟩, hx⟩
exact ⟨hrU _ (hπ.1 _ hJ (Box.coe_subset_Icc hx)), π.le_of_mem' J hJ hx⟩
clear_value m
lift m to ℝ≥0 using ne_top_of_lt this
rw [ENNReal.coe_toReal, ← NNReal.coe_natCast, ← NNReal.coe_mul, NNReal.coe_le_coe, ←
ENNReal.coe_le_coe, ENNReal.coe_mul, ENNReal.coe_natCast, mul_comm]
exact (mul_le_mul_left' this.le _).trans ENNReal.mul_div_le
/-- If `f` has integral `y` on a box `I` with respect to a locally finite measure `μ` and `g` is
a.e. equal to `f` on `I`, then `g` has the same integral on `I`. -/
theorem HasIntegral.congr_ae {l : IntegrationParams} {I : Box ι} {y : E} {f g : (ι → ℝ) → E}
{μ : Measure (ι → ℝ)} [IsLocallyFiniteMeasure μ]
(hf : HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul y) (hfg : f =ᵐ[μ.restrict I] g)
(hl : l.bRiemann = false) : HasIntegral.{u, v, v} I l g μ.toBoxAdditive.toSMul y := by
have : g - f =ᵐ[μ.restrict I] 0 := hfg.mono fun x hx => sub_eq_zero.2 hx.symm
simpa using hf.add (HasIntegral.of_aeEq_zero this hl)
end BoxIntegral
namespace MeasureTheory
namespace SimpleFunc
/-- A simple function is McShane integrable w.r.t. any locally finite measure. -/
theorem hasBoxIntegral (f : SimpleFunc (ι → ℝ) E) (μ : Measure (ι → ℝ)) [IsLocallyFiniteMeasure μ]
(I : Box ι) (l : IntegrationParams) (hl : l.bRiemann = false) :
HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul (f.integral (μ.restrict I)) := by
induction f using MeasureTheory.SimpleFunc.induction with
| @const y s hs =>
simpa [hs] using BoxIntegral.hasIntegralIndicatorConst l hl hs I y μ
| @add f g _ hfi hgi =>
borelize E; haveI := Fact.mk (I.measure_coe_lt_top μ)
rw [integral_add]
exacts [hfi.add hgi, integrable_iff.2 fun _ _ => measure_lt_top _ _,
integrable_iff.2 fun _ _ => measure_lt_top _ _]
/-- For a simple function, its McShane (or Henstock, or `⊥`) box integral is equal to its
integral in the sense of `MeasureTheory.SimpleFunc.integral`. -/
theorem box_integral_eq_integral (f : SimpleFunc (ι → ℝ) E) (μ : Measure (ι → ℝ))
[IsLocallyFiniteMeasure μ] (I : Box ι) (l : IntegrationParams) (hl : l.bRiemann = false) :
BoxIntegral.integral.{u, v, v} I l f μ.toBoxAdditive.toSMul = f.integral (μ.restrict I) :=
(f.hasBoxIntegral μ I l hl).integral_eq
end SimpleFunc
open TopologicalSpace
/-- If `f : ℝⁿ → E` is Bochner integrable w.r.t. a locally finite measure `μ` on a rectangular box
`I`, then it is McShane integrable on `I` with the same integral. -/
theorem IntegrableOn.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} {μ : Measure (ι → ℝ)}
[IsLocallyFiniteMeasure μ] {I : Box ι} (hf : IntegrableOn f I μ) (l : IntegrationParams)
(hl : l.bRiemann = false) :
HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul (∫ x in I, f x ∂μ) := by
borelize E
-- First we replace an `ae_strongly_measurable` function by a measurable one.
rcases hf.aestronglyMeasurable with ⟨g, hg, hfg⟩
haveI : SeparableSpace (range g ∪ {0} : Set E) := hg.separableSpace_range_union_singleton
rw [integral_congr_ae hfg]; have hgi : IntegrableOn g I μ := (integrable_congr hfg).1 hf
refine BoxIntegral.HasIntegral.congr_ae ?_ hfg.symm hl
clear! f
/- Now consider the sequence of simple functions
`SimpleFunc.approxOn g hg.measurable (range g ∪ {0}) 0 (by simp)`
approximating `g`. Recall some properties of this sequence. -/
set f : ℕ → SimpleFunc (ι → ℝ) E :=
SimpleFunc.approxOn g hg.measurable (range g ∪ {0}) 0 (by simp)
have hfi : ∀ n, IntegrableOn (f n) I μ :=
SimpleFunc.integrable_approxOn_range hg.measurable hgi
have hfi' := fun n => ((f n).hasBoxIntegral μ I l hl).integrable
have hfg_mono : ∀ (x) {m n}, m ≤ n → ‖f n x - g x‖ ≤ ‖f m x - g x‖ := by
intro x m n hmn
rw [← dist_eq_norm, ← dist_eq_norm, dist_nndist, dist_nndist, NNReal.coe_le_coe, ←
ENNReal.coe_le_coe, ← edist_nndist, ← edist_nndist]
exact SimpleFunc.edist_approxOn_mono hg.measurable _ x hmn
/- Now consider `ε > 0`. We need to find `r` such that for any tagged partition subordinate
to `r`, the integral sum is `(μ I + 1 + 1) * ε`-close to the Bochner integral. -/
refine HasIntegral.of_mul (μ.real I + 1 + 1) fun ε ε0 => ?_
lift ε to ℝ≥0 using ε0.le; rw [NNReal.coe_pos] at ε0; have ε0' := ENNReal.coe_pos.2 ε0
-- Choose `N` such that the integral of `‖f N x - g x‖` is less than or equal to `ε`.
obtain ⟨N₀, hN₀⟩ : ∃ N : ℕ, ∫ x in I, ‖f N x - g x‖ ∂μ ≤ ε := by
have : Tendsto (fun n => ∫⁻ x in I, ‖f n x - g x‖₊ ∂μ) atTop (𝓝 0) :=
SimpleFunc.tendsto_approxOn_range_L1_enorm hg.measurable hgi
refine (this.eventually (ge_mem_nhds ε0')).exists.imp fun N hN => ?_
exact integral_coe_le_of_lintegral_coe_le hN
-- For each `x`, we choose `Nx x ≥ N₀` such that `dist (f Nx x) (g x) ≤ ε`.
have : ∀ x, ∃ N₁, N₀ ≤ N₁ ∧ dist (f N₁ x) (g x) ≤ ε := fun x ↦ by
have : Tendsto (f · x) atTop (𝓝 <| g x) :=
SimpleFunc.tendsto_approxOn hg.measurable _ (subset_closure (by simp))
exact ((eventually_ge_atTop N₀).and <| this <| closedBall_mem_nhds _ ε0).exists
choose Nx hNx hNxε using this
-- We also choose a convergent series with `∑' i : ℕ, δ i < ε`.
rcases NNReal.exists_pos_sum_of_countable ε0.ne' ℕ with ⟨δ, δ0, c, hδc, hcε⟩
/- Since each simple function `fᵢ` is integrable, there exists `rᵢ : ℝⁿ → (0, ∞)` such that
the integral sum of `f` over any tagged prepartition is `δᵢ`-close to the sum of integrals
of `fᵢ` over the boxes of this prepartition. For each `x`, we choose `r (Nx x)` as the radius
at `x`. -/
set r : ℝ≥0 → (ι → ℝ) → Ioi (0 : ℝ) := fun c x => (hfi' <| Nx x).convergenceR (δ <| Nx x) c x
refine ⟨r, fun c => l.rCond_of_bRiemann_eq_false hl, fun c π hπ hπp => ?_⟩
/- Now we prove the estimate in 3 "jumps": first we replace `g x` in the formula for the
integral sum by `f (Nx x)`; then we replace each `μ J • f (Nx (π.tag J)) (π.tag J)`
by the Bochner integral of `f (Nx (π.tag J)) x` over `J`, then we jump to the Bochner
integral of `g`. -/
refine (dist_triangle4 _ (∑ J ∈ π.boxes, μ.real J • f (Nx <| π.tag J) (π.tag J))
(∑ J ∈ π.boxes, ∫ x in J, f (Nx <| π.tag J) x ∂μ) _).trans ?_
rw [add_mul, add_mul, one_mul]
refine add_le_add_three ?_ ?_ ?_
· /- Since each `f (Nx <| π.tag J)` is `ε`-close to `g (π.tag J)`, replacing the latter with
the former in the formula for the integral sum changes the sum at most by `μ I * ε`. -/
rw [← hπp.iUnion_eq, π.measure_iUnion_toReal, sum_mul, integralSum]
refine dist_sum_sum_le_of_le _ fun J _ => ?_; dsimp
rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg measureReal_nonneg]
gcongr
rw [← dist_eq_norm']; exact hNxε _
· /- We group the terms of both sums by the values of `Nx (π.tag J)`.
For each `N`, the sum of Bochner integrals over the boxes is equal
to the sum of box integrals, and the sum of box integrals is `δᵢ`-close
to the corresponding integral sum due to the Henstock-Sacks inequality. -/
rw [← π.sum_fiberwise fun J => Nx (π.tag J), ← π.sum_fiberwise fun J => Nx (π.tag J)]
refine le_trans ?_ (NNReal.coe_lt_coe.2 hcε).le
refine
(dist_sum_sum_le_of_le _ fun n hn => ?_).trans
(sum_le_hasSum _ (fun n _ => (δ n).2) (NNReal.hasSum_coe.2 hδc))
have hNxn : ∀ J ∈ π.filter fun J => Nx (π.tag J) = n, Nx (π.tag J) = n := fun J hJ =>
(π.mem_filter.1 hJ).2
have hrn : ∀ J ∈ π.filter fun J => Nx (π.tag J) = n,
r c (π.tag J) = (hfi' n).convergenceR (δ n) c (π.tag J) := fun J hJ ↦ by
obtain rfl := hNxn J hJ
rfl
have :
l.MemBaseSet I c ((hfi' n).convergenceR (δ n) c) (π.filter fun J => Nx (π.tag J) = n) :=
(hπ.filter _).mono' _ le_rfl le_rfl fun J hJ => (hrn J hJ).le
convert (hfi' n).dist_integralSum_sum_integral_le_of_memBaseSet (δ0 _) this using 2
· refine sum_congr rfl fun J hJ => ?_
simp [hNxn J hJ]
· refine sum_congr rfl fun J hJ => ?_
rw [← SimpleFunc.integral_eq_integral, SimpleFunc.box_integral_eq_integral _ _ _ _ hl,
hNxn J hJ]
exact (hfi _).mono_set (Prepartition.le_of_mem _ hJ)
· /- For the last jump, we use the fact that the distance between `f (Nx x) x` and `g x` is less
than or equal to the distance between `f N₀ x` and `g x` and the integral of
`‖f N₀ x - g x‖` is less than or equal to `ε`. -/
refine le_trans ?_ hN₀
have hfi : ∀ (n), ∀ J ∈ π, IntegrableOn (f n) (↑J) μ := fun n J hJ =>
(hfi n).mono_set (π.le_of_mem' J hJ)
have hgi : ∀ J ∈ π, IntegrableOn g (↑J) μ := fun J hJ => hgi.mono_set (π.le_of_mem' J hJ)
have hfgi : ∀ (n), ∀ J ∈ π, IntegrableOn (fun x => ‖f n x - g x‖) J μ := fun n J hJ =>
((hfi n J hJ).sub (hgi J hJ)).norm
rw [← hπp.iUnion_eq, Prepartition.iUnion_def',
integral_finset_biUnion π.boxes (fun J _ => J.measurableSet_coe) π.pairwiseDisjoint hgi,
integral_finset_biUnion π.boxes (fun J _ => J.measurableSet_coe) π.pairwiseDisjoint (hfgi _)]
refine dist_sum_sum_le_of_le _ fun J hJ => ?_
rw [dist_eq_norm, ← integral_sub (hfi _ J hJ) (hgi J hJ)]
refine norm_integral_le_of_norm_le (hfgi _ J hJ) (Eventually.of_forall fun x => ?_)
exact hfg_mono x (hNx (π.tag J))
/-- If `f : ℝⁿ → E` is continuous on a rectangular box `I`, then it is Box integrable on `I`
w.r.t. a locally finite measure `μ` with the same integral. -/
theorem ContinuousOn.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} (μ : Measure (ι → ℝ))
[IsLocallyFiniteMeasure μ] {I : Box ι} (hc : ContinuousOn f (Box.Icc I))
(l : IntegrationParams) :
HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul (∫ x in I, f x ∂μ) := by
obtain ⟨y, hy⟩ := BoxIntegral.integrable_of_continuousOn l hc μ
convert hy
have : IntegrableOn f I μ :=
IntegrableOn.mono_set (hc.integrableOn_compact I.isCompact_Icc) Box.coe_subset_Icc
exact HasIntegral.unique (IntegrableOn.hasBoxIntegral this ⊥ rfl) (HasIntegral.mono hy bot_le)
/-- If `f : ℝⁿ → E` is a.e. continuous and bounded on a rectangular box `I`, then it is Box
integrable on `I` w.r.t. a locally finite measure `μ` with the same integral. -/
theorem AEContinuous.hasBoxIntegral [CompleteSpace E] {f : (ι → ℝ) → E} (μ : Measure (ι → ℝ))
[IsLocallyFiniteMeasure μ] {I : Box ι} (hb : ∃ C : ℝ, ∀ x ∈ Box.Icc I, ‖f x‖ ≤ C)
(hc : ∀ᵐ x ∂μ, ContinuousAt f x) (l : IntegrationParams) :
HasIntegral.{u, v, v} I l f μ.toBoxAdditive.toSMul (∫ x in I, f x ∂μ) := by
obtain ⟨y, hy⟩ := integrable_of_bounded_and_ae_continuous l hb μ hc
convert hy
refine HasIntegral.unique (IntegrableOn.hasBoxIntegral ?_ ⊥ rfl) (HasIntegral.mono hy bot_le)
constructor
· let v := {x : (ι → ℝ) | ContinuousAt f x}
have : AEStronglyMeasurable f (μ.restrict v) :=
(continuousOn_of_forall_continuousAt fun _ h ↦ h).aestronglyMeasurable
(measurableSet_of_continuousAt f)
refine this.mono_measure (Measure.le_iff.2 fun s hs ↦ ?_)
repeat rw [μ.restrict_apply hs]
apply le_of_le_of_eq <| μ.mono s.inter_subset_left
refine measure_eq_measure_of_null_diff s.inter_subset_left ?_ |>.symm
rw [diff_self_inter, Set.diff_eq]
refine (le_antisymm (zero_le (μ (s ∩ vᶜ))) ?_).symm
exact le_trans (μ.mono s.inter_subset_right) (nonpos_iff_eq_zero.2 hc)
· have : IsFiniteMeasure (μ.restrict (Box.Icc I)) :=
{ measure_univ_lt_top := by simp [I.isCompact_Icc.measure_lt_top (μ := μ)] }
have : IsFiniteMeasure (μ.restrict I) :=
isFiniteMeasure_of_le (μ.restrict (Box.Icc I))
(μ.restrict_mono Box.coe_subset_Icc (le_refl μ))
obtain ⟨C, hC⟩ := hb
refine .of_bounded (C := C) (Filter.eventually_iff_exists_mem.2 ?_)
use I, self_mem_ae_restrict I.measurableSet_coe, fun y hy ↦ hC y (I.coe_subset_Icc hy)
end MeasureTheory
|
CoversTop.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.CategoryTheory.Sites.Sheaf
/-! Objects which cover the terminal object
In this file, given a site `(C, J)`, we introduce the notion of a family
of objects `Y : I → C` which "cover the final object": this means
that for all `X : C`, the sieve `Sieve.ofObjects Y X` is covering for `J`.
When there is a terminal object `X : C`, then `J.CoversTop Y`
holds iff `Sieve.ofObjects Y X` is covering for `J`.
We introduce a notion of compatible family of elements on objects `Y`
and obtain `Presheaf.FamilyOfElementsOnObjects.IsCompatible.existsUnique_section`
which asserts that if a presheaf of types is a sheaf, then any compatible
family of elements on objects `Y` which cover the final object extends as
a section of this presheaf.
-/
universe w v' v u' u
namespace CategoryTheory
open Limits
variable {C : Type u} [Category.{v} C] (J : GrothendieckTopology C)
{A : Type u'} [Category.{v'} A]
namespace GrothendieckTopology
/-- A family of objects `Y : I → C` "covers the final object"
if for all `X : C`, the sieve `ofObjects Y X` is a covering sieve. -/
def CoversTop {I : Type*} (Y : I → C) : Prop :=
∀ (X : C), Sieve.ofObjects Y X ∈ J X
lemma coversTop_iff_of_isTerminal (X : C) (hX : IsTerminal X)
{I : Type*} (Y : I → C) :
J.CoversTop Y ↔ Sieve.ofObjects Y X ∈ J X := by
constructor
· tauto
· intro h W
apply J.superset_covering _ (J.pullback_stable (hX.from W) h)
rintro T a ⟨i, ⟨b⟩⟩
exact ⟨i, ⟨b⟩⟩
namespace CoversTop
variable {J}
variable {I : Type*} {Y : I → C} (hY : J.CoversTop Y)
include hY
/-- The cover of any object `W : C` attached to a family of objects `Y` that satisfy
`J.CoversTop Y` -/
abbrev cover (W : C) : Cover J W := ⟨Sieve.ofObjects Y W, hY W⟩
lemma ext (F : Sheaf J A) {c : Cone F.1} (hc : IsLimit c) {X : A} {f g : X ⟶ c.pt}
(h : ∀ (i : I), f ≫ c.π.app (Opposite.op (Y i)) =
g ≫ c.π.app (Opposite.op (Y i))) :
f = g := by
refine hc.hom_ext (fun Z => F.2.hom_ext (hY.cover Z.unop) _ _ ?_)
rintro ⟨W, a, ⟨i, ⟨b⟩⟩⟩
simpa using h i =≫ F.1.map b.op
lemma sections_ext (F : Sheaf J (Type _)) {x y : F.1.sections}
(h : ∀ (i : I), x.1 (Opposite.op (Y i)) = y.1 (Opposite.op (Y i))) :
x = y := by
ext W
apply (Presieve.isSeparated_of_isSheaf J F.1
((isSheaf_iff_isSheaf_of_type _ _).1 F.2) _ (hY W.unop)).ext
rintro T a ⟨i, ⟨b⟩⟩
simpa using congr_arg (F.1.map b.op) (h i)
end CoversTop
end GrothendieckTopology
namespace Presheaf
variable (F : Cᵒᵖ ⥤ Type w) {I : Type*} (Y : I → C)
/-- A family of elements of a presheaf of types `F` indexed by a family of objects
`Y : I → C` consists of the data of an element in `F.obj (Opposite.op (Y i))` for all `i`. -/
def FamilyOfElementsOnObjects := ∀ (i : I), F.obj (Opposite.op (Y i))
namespace FamilyOfElementsOnObjects
variable {F Y}
variable (x : FamilyOfElementsOnObjects F Y)
/-- `x : FamilyOfElementsOnObjects F Y` is compatible if for any object `Z` such that
there exists a morphism `f : Z → Y i`, then the pullback of `x i` by `f` is independent
of `f` and `i`. -/
def IsCompatible (x : FamilyOfElementsOnObjects F Y) : Prop :=
∀ (Z : C) (i j : I) (f : Z ⟶ Y i) (g : Z ⟶ Y j),
F.map f.op (x i) = F.map g.op (x j)
/-- A family of elements indexed by `Sieve.ofObjects Y X` that is induced by
`x : FamilyOfElementsOnObjects F Y`. See the equational lemma
`IsCompatible.familyOfElements_apply` which holds under the assumption `x.IsCompatible`. -/
noncomputable def familyOfElements (X : C) :
Presieve.FamilyOfElements F (Sieve.ofObjects Y X).arrows :=
fun _ _ hf => F.map hf.choose_spec.some.op (x _)
namespace IsCompatible
variable {x}
lemma familyOfElements_apply (hx : x.IsCompatible) {X Z : C} (f : Z ⟶ X) (i : I) (φ : Z ⟶ Y i) :
familyOfElements x X f ⟨i, ⟨φ⟩⟩ = F.map φ.op (x i) := by
apply hx
lemma familyOfElements_isCompatible (hx : x.IsCompatible) (X : C) :
(familyOfElements x X).Compatible := by
intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ ⟨i₁, ⟨φ₁⟩⟩ ⟨i₂, ⟨φ₂⟩⟩ _
simpa [hx.familyOfElements_apply f₁ i₁ φ₁,
hx.familyOfElements_apply f₂ i₂ φ₂] using hx Z i₁ i₂ (g₁ ≫ φ₁) (g₂ ≫ φ₂)
variable {J}
lemma existsUnique_section (hx : x.IsCompatible) (hY : J.CoversTop Y) (hF : IsSheaf J F) :
∃! (s : F.sections), ∀ (i : I), s.1 (Opposite.op (Y i)) = x i := by
have H := (isSheaf_iff_isSheaf_of_type _ _).1 hF
apply existsUnique_of_exists_of_unique
· let s := fun (X : C) => (H _ (hY X)).amalgamate _
(hx.familyOfElements_isCompatible X)
have hs : ∀ {X : C} (i : I) (f : X ⟶ Y i), s X = F.map f.op (x i) := fun {X} i f => by
have h := Presieve.IsSheafFor.valid_glue (H _ (hY X))
(hx.familyOfElements_isCompatible _) (𝟙 _) ⟨i, ⟨f⟩⟩
simp only [op_id, F.map_id, types_id_apply] at h
exact h.trans (hx.familyOfElements_apply _ _ _)
have hs' : ∀ {W X : C} (a : W ⟶ X) (i : I) (_ : W ⟶ Y i), F.map a.op (s X) = s W := by
intro W X a i b
rw [hs i b]
exact (Presieve.IsSheafFor.valid_glue (H _ (hY X))
(hx.familyOfElements_isCompatible _) a ⟨i, ⟨b⟩⟩).trans (familyOfElements_apply hx _ _ _)
refine ⟨⟨fun X => s X.unop, ?_⟩, fun i => (hs i (𝟙 (Y i))).trans (by simp)⟩
rintro ⟨Y₁⟩ ⟨Y₂⟩ ⟨f : Y₂ ⟶ Y₁⟩
change F.map f.op (s Y₁) = s Y₂
apply (Presieve.isSeparated_of_isSheaf J F H _ (hY Y₂)).ext
rintro Z φ ⟨i, ⟨g⟩⟩
rw [hs' φ i g, ← hs' (φ ≫ f) i g, op_comp, F.map_comp]
rfl
· intro y₁ y₂ hy₁ hy₂
exact hY.sections_ext ⟨F, hF⟩ (fun i => by rw [hy₁, hy₂])
variable (hx : x.IsCompatible) (hY : J.CoversTop Y) (hF : IsSheaf J F)
/-- The section of a sheaf of types which lifts a compatible family of elements indexed
by objects which cover the terminal object. -/
noncomputable def section_ : F.sections := (hx.existsUnique_section hY hF).choose
@[simp]
lemma section_apply (i : I) : (hx.section_ hY hF).1 (Opposite.op (Y i)) = x i :=
(hx.existsUnique_section hY hF).choose_spec.1 i
end IsCompatible
end FamilyOfElementsOnObjects
end Presheaf
end CategoryTheory
|
sesquilinear.v
|
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq div.
From mathcomp Require Import choice fintype tuple bigop ssralg finset fingroup.
From mathcomp Require Import zmodp poly order ssrnum matrix mxalgebra vector.
(******************************************************************************)
(* Sesquilinear forms *)
(* *)
(* e_ j := the row matrix with a 1 in column j *)
(* M ^ phi := map_mx phi M *)
(* Notation in scope sesquilinear_scope. *)
(* M ^t phi := (M ^T) ^ phi *)
(* Notation in scope sesquilinear_scope. *)
(* involutive_rmorphism R == the type of involutive functions *)
(* R has type nzRingType. *)
(* The HB class is InvolutiveRMorphism. *)
(* *)
(* {bilinear U -> U' -> V | s & s'} == the type of bilinear forms which are *)
(* essentially functions of type U -> U' -> V *)
(* U and U' are lmodType's, V is a zmodType, s and *)
(* s' are scaling operations of type R -> V -> V. *)
(* The HB class is Bilinear. *)
(* The factory bilinear_isBilinear provides a way *)
(* to instantiate a bilinear form from two *)
(* GRing.linear_for proofs. *)
(* {bilinear U -> V -> W | s } := {bilinear U -> V -> W | s.1 & s.2} *)
(* {bilinear U -> V -> W} := {bilinear U -> V -> W | *:%R & *:%R } *)
(* {biscalar U} := {bilinear U -> U -> _ | *%R & *%R } *)
(* *)
(* applyr f x := f ^~ x with f : U -> U' -> V *)
(* form theta M u v == form defined from a matrix M *)
(* := (u *m M *m (v ^t theta)) 0 0 *)
(* u and v are row vectors, M is a square matrix, *)
(* coefficients have type R : fieldType, *)
(* theta is a morphism *)
(* *)
(* {hermitian U for eps & theta} == hermitian/skew-hermitian form *)
(* eps is a boolean flag, *)
(* (false -> hermitian, true -> skew-hermitian), *)
(* theta is a function R -> R (R : nzRingType). *)
(* The HB class is Hermitian. *)
(* *%R is used as a the first scaling operator. *)
(* theta \; *R is used as the second scaling *)
(* operation of the bilinear form. *)
(* The archetypal case is theta being the complex *)
(* conjugate. *)
(* *)
(* M \is (eps, theta).-sesqui == M is a sesquilinear form *)
(* *)
(* orthomx theta M B == M-orthogonal complement of B *)
(* := kermx (M *m B ^t theta) *)
(* M is a square matrix representing a sesquilinear *)
(* form, B is a rectangle matrix representing a *)
(* subspace *)
(* (local notation: B ^_|_) *)
(* ortho theta M B == orthomx theta M B with theta a morphism *)
(* A '_|_ B := (A%MS <= B^_|_)%MS *)
(* This is a local notation. *)
(* rad theta M := ortho theta M 1%:M *)
(* (local notation: 1%:M^_|_) *)
(* *)
(* {symmetric U} == symmetric form *)
(* := {hermitian U for false & idfun} *)
(* {skew_symmetric U} == skew-symmetric form *)
(* := {hermitian U for true & idfun} *)
(* {hermitian_sym U for theta} := hermitian form using theta (eps = false) *)
(* {dot U for theta} == type of positive definite forms *)
(* The HB class is Dot. *)
(* *)
(* is_skew eps theta form := eps = true /\ theta = idfun *)
(* is_sym eps theta form := eps = false /\ theta = idfun *)
(* is_hermsym eps theta form := eps = false *)
(* *)
(* ortho_rec s1 s2 := elements of s1 and s2 are pairwise orthogonal *)
(* pairwise_orthogonal s == elements of s are pairwise orthogonal and *)
(* s does not contain 0 *)
(* orthogonal s1 s2 == the inner product of an element of S1 and *)
(* an element of S2 is 0 *)
(* := ortho_rec s1 s2 *)
(* orthonormal s == s is an orthonormal set of unit vectors *)
(* *)
(* isometry form1 form2 tau == tau is an isometry from form1 to form2 *)
(* form1 and form2 are hermitian forms. *)
(* {in D, isometry tau, to R} == local notation for now *)
(* *)
(* orthov (V : {vspace vT}) == the space orthogonal to V *)
(* *)
(* In the following definitions, we have f : {hermitian vT for eps & theta} *)
(* with vT : vectType F (F : fieldType): *)
(* nondegenerate f == f is non-degenerated *)
(* is_symplectic f == f is a symplectic bilinear form *)
(* is_orthogonal f == f is an orthogonal form *)
(* is_unitary f == f is a unitary form *)
(* *)
(* form_of_matrix theta M U V := \tr (U *m M *m (V ^t theta)) *)
(* matrix_of_form f := \matrix_(i, j) form 'e_i 'e_j *)
(* M \is hermitianmx eps theta == same as M \is (eps, theta).-sesqui *)
(* without the constraint that theta is a morphism *)
(* *)
(* symmetricmx := hermitianmx _ false idfun *)
(* skewmx := hermitianmx _ true idfun *)
(* hermsymmx := hermitianmx _ false conjC *)
(* *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "M ^t phi"
(at level 39, left associativity, format "M ^t phi").
Reserved Notation "A ^!" (format "A ^!").
Reserved Notation "A ^_|_" (format "A ^_|_").
Reserved Notation "A ''_|_' B" (at level 69, format "A ''_|_' B").
Reserved Notation "eps_theta .-sesqui" (format "eps_theta .-sesqui").
Local Open Scope ring_scope.
Import GRing.Theory Order.Theory Num.Theory.
Notation "''e_' j" := (delta_mx 0 j)
(format "''e_' j", at level 8, j at level 2) : ring_scope.
Declare Scope sesquilinear_scope.
Delimit Scope sesquilinear_scope with sesqui.
Local Open Scope sesquilinear_scope.
Notation "M ^ phi" := (map_mx phi M) : sesquilinear_scope.
Notation "M ^t phi" := ((M ^T) ^ phi) : sesquilinear_scope.
(* TODO: move? *)
Lemma eq_map_mx_id (R : nzRingType) m n (M : 'M[R]_(m, n)) (f : R -> R) :
f =1 id -> M ^ f = M.
Proof. by move=> /eq_map_mx->; rewrite map_mx_id. Qed.
HB.mixin Record isInvolutive (R : nzRingType) (f : R -> R) :=
{ involutive_subproof : involutive f }.
(* TODO: move? *)
#[short(type="involutive_rmorphism")]
HB.structure Definition InvolutiveRMorphism (R : nzRingType) :=
{ f of @GRing.RMorphism R R f & @isInvolutive R f }.
Section InvolutiveTheory.
Variable R : nzRingType.
Let idfunK : involutive (@idfun R). Proof. by []. Qed.
HB.instance Definition _ := isInvolutive.Build _ _ idfunK.
Lemma rmorphK (f : involutive_rmorphism R) : involutive f.
Proof. by move: f => [? [? ? []]]. Qed.
End InvolutiveTheory.
Definition conjC {C : numClosedFieldType} (c : C) : C := c^*.
HB.instance Definition _ (C : numClosedFieldType) :=
GRing.RMorphism.on (@conjC C).
Section conjC_involutive.
Variable C : numClosedFieldType.
Let conjCfun_involutive : involutive (@conjC C). Proof. exact: conjCK. Qed.
HB.instance Definition _ :=
isInvolutive.Build _ (@conjC C) conjCfun_involutive.
End conjC_involutive.
Lemma map_mxCK {C : numClosedFieldType} m n (A : 'M[C]_(m, n)) :
(A ^ conjC) ^ conjC = A.
Proof. by apply/matrixP=> i j; rewrite !mxE conjCK. Qed.
(*Structure revop X Y Z (f : Y -> X -> Z) := RevOp {
fun_of_revop :> X -> Y -> Z;
_ : forall x, f x =1 fun_of_revop^~ x
}.
Notation "[ 'revop' revop 'of' op ]" :=
(@RevOp _ _ _ revop op (fun _ _ => erefl))
(format "[ 'revop' revop 'of' op ]") : form_scope.*)
HB.mixin Record isBilinear (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : U -> U' -> V) := {
zmod_morphisml_subproof : forall u', zmod_morphism (f ^~ u') ;
zmod_morphismr_subproof : forall u, zmod_morphism (f u) ;
linearl_subproof : forall u', scalable_for s (f ^~ u') ;
linearr_subproof : forall u, scalable_for s' (f u)
}.
#[short(type="bilinear")]
HB.structure Definition Bilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : R -> V -> V) (s' : R -> V -> V) :=
{f of isBilinear R U U' V s s' f}.
Definition bilinear_for (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : GRing.Scale.law R V) (s' : GRing.Scale.law R V) (f : U -> U' -> V) :=
((forall u', GRing.linear_for (s : R -> V -> V) (f ^~ u'))
* (forall u, GRing.linear_for s' (f u)))%type.
HB.factory Record bilinear_isBilinear (R : nzRingType) (U U' : lmodType R)
(V : zmodType) (s : GRing.Scale.law R V) (s' : GRing.Scale.law R V)
(f : U -> U' -> V) := {
bilinear_subproof : bilinear_for s s' f
}.
HB.builders Context R U U' V s s' f of bilinear_isBilinear R U U' V s s' f.
HB.instance Definition _ := isBilinear.Build R U U' V s s' f
(fun u' => zmod_morphism_linear (bilinear_subproof.1 u'))
(fun u => zmod_morphism_linear (bilinear_subproof.2 u))
(fun u' => scalable_linear (bilinear_subproof.1 u'))
(fun u => scalable_linear (bilinear_subproof.2 u)).
HB.end.
Module BilinearExports.
Module Bilinear.
Section bilinear.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Local Notation bilinear f := (bilinear_for *:%R *:%R f).
Local Notation biscalar f := (bilinear_for *%R *%R f).
(* Support for right-to-left rewriting with the generic linearZ rule. *)
Notation mapUUV := (@Bilinear.type R U U' V s s').
Definition map_class := mapUUV.
Definition map_at_left (a : R) := mapUUV.
Definition map_at_right (b : R) := mapUUV.
Definition map_at_both (a b : R) := mapUUV.
Structure map_for_left a s_a :=
MapForLeft {map_for_left_map : mapUUV; _ : s a = s_a }.
Structure map_for_right b s'_b :=
MapForRight {map_for_right_map : mapUUV; _ : s' b = s'_b }.
Structure map_for_both a b s_a s'_b :=
MapForBoth {map_for_both_map : mapUUV; _ : s a = s_a ; _ : s' b = s'_b }.
Definition unify_map_at_left a (f : map_at_left a) :=
MapForLeft f (erefl (s a)).
Definition unify_map_at_right b (f : map_at_right b) :=
MapForRight f (erefl (s' b)).
Definition unify_map_at_both a b (f : map_at_both a b) :=
MapForBoth f (erefl (s a)) (erefl (s' b)).
Structure wrapped := Wrap {unwrap : mapUUV}.
Definition wrap (f : map_class) := Wrap f.
End bilinear.
End Bilinear.
Notation "{ 'bilinear' U -> V -> W | s & t }" :=
(@Bilinear.type _ U%type V%type W%type s t)
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s & t }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W | s }" :=
({bilinear U -> V -> W | s.1 & s.2})
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W | s }") : ring_scope.
Notation "{ 'bilinear' U -> V -> W }" := {bilinear U -> V -> W | *:%R & *:%R}
(U at level 98, V at level 98, W at level 99,
format "{ 'bilinear' U -> V -> W }") : ring_scope.
Notation "{ 'biscalar' U }" := {bilinear U%type -> U%type -> _ | *%R & *%R}
(format "{ 'biscalar' U }") : ring_scope.
End BilinearExports.
Export BilinearExports.
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V)
(f : {bilinear U -> U' -> V | s & s'}) (u : U)
:= @GRing.isZmodMorphism.Build U' V (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s : R -> V -> V) (s' : R -> V -> V) (f : @bilinear R U U' V s s') (u : U)
:= @GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
Section applyr.
Variables (R : nzRingType) (U U' : lmodType R) (V : zmodType)
(s s' : R -> V -> V).
Definition applyr_head t (f : U -> U' -> V) u v := let: tt := t in f v u.
End applyr.
Notation applyr := (applyr_head tt).
Coercion Bilinear.map_for_left_map : Bilinear.map_for_left >-> Bilinear.type.
Coercion Bilinear.map_for_right_map : Bilinear.map_for_right >-> Bilinear.type.
Coercion Bilinear.map_for_both_map : Bilinear.map_for_both >-> Bilinear.type.
Coercion Bilinear.unify_map_at_left : Bilinear.map_at_left >-> Bilinear.map_for_left.
Coercion Bilinear.unify_map_at_right : Bilinear.map_at_right >-> Bilinear.map_for_right.
Coercion Bilinear.unify_map_at_both : Bilinear.map_at_both >-> Bilinear.map_for_both.
Canonical Bilinear.unify_map_at_left.
Canonical Bilinear.unify_map_at_right.
Canonical Bilinear.unify_map_at_both.
Coercion Bilinear.unwrap : Bilinear.wrapped >-> Bilinear.type.
Coercion Bilinear.wrap : Bilinear.map_class >-> Bilinear.wrapped.
Canonical Bilinear.wrap.
Section BilinearTheory.
Variable R : nzRingType.
Section GenericProperties.
Variables (U U' : lmodType R) (V : zmodType) (s : R -> V -> V) (s' : R -> V -> V).
Variable f : {bilinear U -> U' -> V | s & s'}.
Section GenericPropertiesr.
Variable z : U.
Lemma linear0r : f z 0 = 0. Proof. by rewrite raddf0. Qed.
Lemma linearNr : {morph f z : x / - x}. Proof. exact: raddfN. Qed.
Lemma linearDr : {morph f z : x y / x + y}. Proof. exact: raddfD. Qed.
Lemma linearBr : {morph f z : x y / x - y}. Proof. exact: raddfB. Qed.
Lemma linearMnr n : {morph f z : x / x *+ n}. Proof. exact: raddfMn. Qed.
Lemma linearMNnr n : {morph f z : x / x *- n}. Proof. exact: raddfMNn. Qed.
Lemma linear_sumr I r (P : pred I) E :
f z (\sum_(i <- r | P i) E i) = \sum_(i <- r | P i) f z (E i).
Proof. exact: raddf_sum. Qed.
Lemma linearZr_LR : scalable_for s' (f z). Proof. exact: linearZ_LR. Qed.
Lemma linearPr a : {morph f z : u v / a *: u + v >-> s' a u + v}.
Proof. exact: linearP. Qed.
End GenericPropertiesr.
Lemma applyrE x : applyr f x =1 f^~ x. Proof. by []. Qed.
Section GenericPropertiesl.
Variable z : U'.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build _ _ (applyr f z) (@zmod_morphisml_subproof _ _ _ _ _ _ f z).
HB.instance Definition _ :=
GRing.isScalable.Build _ _ _ _ (applyr f z) (@linearl_subproof _ _ _ _ _ _ f z).
Lemma linear0l : f 0 z = 0. Proof. by rewrite -applyrE raddf0. Qed.
Lemma linearNl : {morph f^~ z : x / - x}.
Proof. by move=> ?; rewrite -applyrE raddfN. Qed.
Lemma linearDl : {morph f^~ z : x y / x + y}.
Proof. by move=> ? ?; rewrite -applyrE raddfD. Qed.
Lemma linearBl : {morph f^~ z : x y / x - y}.
Proof. by move=> ? ?; rewrite -applyrE raddfB. Qed.
Lemma linearMnl n : {morph f^~ z : x / x *+ n}.
Proof. by move=> ?; rewrite -applyrE raddfMn. Qed.
Lemma linearMNnl n : {morph f^~ z : x / x *- n}.
Proof. by move=> ?; rewrite -applyrE raddfMNn. Qed.
Lemma linear_sumlz I r (P : pred I) E :
f (\sum_(i <- r | P i) E i) z = \sum_(i <- r | P i) f (E i) z.
Proof. by rewrite -applyrE raddf_sum. Qed.
Lemma linearZl_LR : scalable_for s (f ^~ z).
Proof. by move=> ? ?; rewrite -applyrE linearZ_LR. Qed.
Lemma linearPl a : {morph f^~ z : u v / a *: u + v >-> s a u + v}.
Proof. by move=> ? ?; rewrite -applyrE linearP. Qed.
End GenericPropertiesl.
End GenericProperties.
Section BidirectionalLinearZ.
Variables (U U' : lmodType R) (V : zmodType) (s s' : R -> V -> V).
Variables (S : nzRingType) (h : GRing.Scale.law S V) (h' : GRing.Scale.law S V).
Lemma linearZl z (c : S) (a : R) (h_c := h c)
(f : Bilinear.map_for_left U U' s s' a h_c) u :
f (a *: u) z = h_c (Bilinear.wrap f u z).
Proof. by rewrite linearZl_LR; case: f => f /= ->. Qed.
Lemma linearZr z c' b (h'_c' := h' c')
(f : Bilinear.map_for_right U U' s s' b h'_c') u :
f z (b *: u) = h'_c' (Bilinear.wrap f z u).
Proof. by rewrite linearZr_LR; case: f => f /= ->. Qed.
Lemma linearZlr c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h_c (h'_c' (Bilinear.wrap f u v)).
Proof. by rewrite linearZl_LR linearZ_LR; case: f => f /= -> ->. Qed.
Lemma linearZrl c c' a b (h_c := h c) (h'_c' := h' c')
(f : Bilinear.map_for_both U U' s s' a b h_c h'_c') u v :
f (a *: u) (b *: v) = h'_c' (h_c (Bilinear.wrap f u v)).
Proof. by rewrite linearZ_LR/= linearZl_LR; case: f => f /= -> ->. Qed.
End BidirectionalLinearZ.
End BilinearTheory.
(* TODO
Canonical rev_mulmx (R : nzRingType) m n p := [revop mulmxr of @mulmx R m n p].
*)
(*Canonical mulmx_bilinear (R : comNzRingType) m n p := [bilinear of @mulmx R m n p].*)
Lemma mulmx_is_bilinear (R : comNzRingType) m n p : bilinear_for
(GRing.Scale.Law.clone _ _ *:%R _) (GRing.Scale.Law.clone _ _ *:%R _)
(@mulmx R m n p).
Proof.
split=> [u'|u] a x y /=.
- by rewrite mulmxDl scalemxAl.
- by rewrite mulmxDr scalemxAr.
Qed.
HB.instance Definition _ (R : comNzRingType) m n p := bilinear_isBilinear.Build R
[the lmodType R of 'M[R]_(m, n)] [the lmodType R of 'M[R]_(n, p)]
[the zmodType of 'M[R]_(m, p)] _ _ (@mulmx R m n p)
(mulmx_is_bilinear R m n p).
Section BilinearForms.
Variables (R : fieldType) (theta : {rmorphism R -> R}).
Variables (n : nat) (M : 'M[R]_n).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Definition form u v := (u *m M *m (v ^t theta)) 0 0.
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma form0l u : '[0, u] = 0. Proof. by rewrite /form !mul0mx mxE. Qed.
Lemma form0r u : '[u, 0] = 0.
Proof. by rewrite /form trmx0 map_mx0 mulmx0 mxE. Qed.
Lemma formDl u v w : '[u + v, w] = '[u, w] + '[v, w].
Proof. by rewrite /form !mulmxDl mxE. Qed.
Lemma formDr u v w : '[u, v + w] = '[u, v] + '[u, w].
Proof. by rewrite /form linearD !map_mxD !mulmxDr mxE. Qed.
Lemma formZr a u v : '[u, a *: v] = theta a * '[u, v].
Proof. by rewrite /form !(linearZ, map_mxZ) /= mxE. Qed.
Lemma formZl a u v : '[a *: u, v] = a * '[u, v].
Proof.
by do !rewrite /form -[_ *: _ *m _]/(mulmxr _ _) linearZ /=; rewrite mxE.
Qed.
Lemma formNl u v : '[- u, v] = - '[u, v].
Proof. by rewrite -scaleN1r formZl mulN1r. Qed.
Lemma formNr u v : '[u, - v] = - '[u, v].
Proof. by rewrite -scaleN1r formZr rmorphN1 mulN1r. Qed.
Lemma formee i j : '['e_i, 'e_j] = M i j.
Proof.
rewrite /form -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE !mxE.
Qed.
Lemma form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof. by rewrite/form=> -> u v; rewrite mulmx0 mul0mx mxE. Qed.
End BilinearForms.
HB.mixin Record isHermitianSesquilinear (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : U -> U -> R) := {
hermitian_subproof : forall x y : U, f x y = (-1) ^+ eps * theta (f y x)
}.
HB.structure Definition Hermitian (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) :=
{f of @Bilinear R U U _ ( *%R ) (theta \; *%R) f &
@isHermitianSesquilinear R U eps theta f}.
Notation "{ 'hermitian' U 'for' eps & theta }" := (@Hermitian.type _ U eps theta)
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : nzRingType) (U : lmodType R)
(eps : bool) (theta : R -> R) (f : {hermitian U for eps & theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Variables (R : nzRingType) (U : lmodType R) (eps : bool) (theta : R -> R).
Implicit Types phU : phant U.
Local Coercion GRing.Scale.op : GRing.Scale.law >-> Funclass.
Definition axiom (f : U -> U -> R) :=
forall x y : U, f x y = (-1) ^+ eps * theta (f y x).
Record class_of (f : U -> U -> R) : Prop := Class {
base : Bilinear.class_of ( *%R) (theta \; *%R) f;
mixin : axiom f
}.*)
(*Canonical additiver (u : U) := Additive (base class u).
Canonical linearr (u : U) := Linear (base class u).
Canonical additivel (u' : U) := @GRing.Additive.Pack _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical linearl (u' : U) := @GRing.Linear.Pack _ _ _ _ (Phant (U -> R))
(applyr cF u') (Bilinear.basel (base class) u').
Canonical bilinear := @Bilinear.Pack _ _ _ _ _ _ (Phant (U -> U -> R)) cF (base class).*)
(*Module Exports.
Notation "{ 'hermitian' U 'for' eps & theta }" := (map eps theta (Phant U))
(format "{ 'hermitian' U 'for' eps & theta }") : ring_scope.
Coercion base : class_of >-> bilmorphism_for.
Coercion apply : map >-> Funclass.
Notation "[ 'hermitian' 'of' f 'as' g ]" := (@clone _ _ _ _ _ _ f g _ idfun idfun)
(format "[ 'hermitian' 'of' f 'as' g ]") : form_scope.
Notation "[ 'hermitian' 'of' f ]" := (@clone _ _ _ _ _ _ f f _ idfun idfun)
(format "[ 'hermitian' 'of' f ]") : form_scope.
Notation hermitian_for := Hermitian.axiom.
Notation Hermitian fM := (pack (Phant _) fM idfun).
Canonical additiver.
Canonical linearr.
Canonical additivel.
Canonical linearl.
Canonical bilinear.
Notation hermapplyr := (@applyr_head _ _ _ _ tt).
End Exports.
End Hermitian.
Include Hermitian.Exports.*)
Definition orthomx {R : fieldType} (theta : R -> R) n m M (B : 'M_(m, n)) : 'M_n :=
kermx (M *m (B ^t theta)).
Section Sesquilinear.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (N P Q : 'M[R]_n).
Section Def.
Variable eps_theta : bool * {rmorphism R -> R}.
Definition sesqui :=
[qualify M : 'M_n | M == ((-1) ^+ eps_theta.1) *: M ^t eps_theta.2].
Fact sesqui_key : pred_key sesqui. Proof. by []. Qed.
Canonical sesqui_keyed := KeyedQualifier sesqui_key.
End Def.
Local Notation "eps_theta .-sesqui" := (sesqui eps_theta).
Variables (eps : bool) (theta : {rmorphism R -> R}) (M : 'M[R]_n).
Local Notation "''[' u , v ]" := (form theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u] : ring_scope.
Lemma sesquiE : (M \is (eps, theta).-sesqui) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma sesquiP : reflect (M = (-1) ^+ eps *: M ^t theta)
(M \is (eps, theta).-sesqui).
Proof. by rewrite sesquiE; exact/eqP. Qed.
Hypotheses (thetaK : involutive theta) (M_sesqui : M \is (eps, theta).-sesqui).
Lemma trmx_sesqui : M^T = (-1) ^+ eps *: M ^ theta.
Proof.
rewrite [in LHS](sesquiP _) // -mul_scalar_mx trmx_mul.
by rewrite tr_scalar_mx mul_mx_scalar map_trmx trmxK.
Qed.
Lemma maptrmx_sesqui : M^t theta = (-1) ^+ eps *: M.
Proof.
by rewrite trmx_sesqui map_mxZ rmorph_sign -map_mx_comp eq_map_mx_id.
Qed.
Lemma formC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof.
rewrite /form [M in LHS](sesquiP _) // -mulmxA !mxE rmorph_sum mulr_sumr.
apply: eq_bigr => /= i _; rewrite !(mxE, mulr_sumr, mulr_suml, rmorph_sum).
apply: eq_bigr => /= j _; rewrite !mxE !rmorphM mulrCA -!mulrA.
by congr (_ * _); rewrite mulrA mulrC /= thetaK.
Qed.
Lemma form_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite formC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
Definition ortho m (B : 'M_(m, n)) := orthomx theta M B.
Local Notation "B ^_|_" := (ortho B) : ring_scope.
Local Notation "A '_|_ B" := (A%MS <= B^_|_)%MS : ring_scope.
Lemma normalE u v : (u '_|_ v) = ('[u, v] == 0).
Proof.
by rewrite (sameP sub_kermxP eqP) mulmxA [_ *m _^t _]mx11_scalar fmorph_eq0.
Qed.
Lemma form_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v).
Proof. by rewrite normalE; apply/eqP. Qed.
Lemma normalP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), (u <= A)%MS -> (v <= B)%MS -> u '_|_ v)
(A '_|_ B).
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma normalC p q (A : 'M_(p, n)) (B : 'M_(q, n)) : (A '_|_ B) = (B '_|_ A).
Proof.
gen have nC : p q A B / A '_|_ B -> B '_|_ A; last by apply/idP/idP; apply/nC.
move=> AnB; apply/normalP => u v ? ?; rewrite normalE.
rewrite formC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -normalE (normalP _ _ AnB).
Qed.
Lemma normal_ortho_mx p (A : 'M_(p, n)) : ((A^_|_) '_|_ A).
Proof. by []. Qed.
Lemma normal_mx_ortho p (A : 'M_(p, n)) : (A '_|_ (A^_|_)).
Proof. by rewrite normalC. Qed.
Lemma rank_normal u : (\rank (u ^_|_) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Definition rad := 1%:M^_|_.
Lemma rad_ker : rad = kermx M.
Proof. by rewrite /rad /ortho /orthomx trmx1 map_mx1 mulmx1. Qed.
(* Pythagoras *)
Theorem formDd u v : u '_|_ v -> '[u + v] = '[u] + '[v].
Proof.
move=> uNv; rewrite formDl !formDr ['[v, u]]formC.
by rewrite ['[u, v]](form_eq0P _) // rmorph0 mulr0 addr0 add0r.
Qed.
Lemma formZ a u : '[a *: u]= (a * theta a) * '[u].
Proof. by rewrite formZl formZr mulrA. Qed.
Lemma formN u : '[- u] = '[u].
Proof. by rewrite formNr formNl opprK. Qed.
Lemma form_sign m u : '[(-1) ^+ m *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: odd; rewrite ?formN. Qed.
Lemma formD u v : let d := '[u, v] in
'[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite formDl !formDr ['[v, _]]formC [_ + '[v]]addrC addrACA. Qed.
Lemma formB u v : let d := '[u, v] in
'[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof. by rewrite formD formN !formNr rmorphN mulrN -opprD. Qed.
Lemma formBd u v : u '_|_ v -> '[u - v] = '[u] + '[v].
Proof.
by move=> uTv; rewrite formDd ?formN // normalE formNr oppr_eq0 -normalE.
Qed.
(* Lemma formJ u v : '[u ^ theta, v ^ theta] = (-1) ^+ eps * theta '[u, v]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* Lemma formJ u : '[u ^ theta] = (-1) ^+ eps * '[u]. *)
(* Proof. *)
(* rewrite {1}/form -map_trmx -map_mx_comp (@eq_map_mx _ _ _ _ _ id) ?map_mx_id //. *)
(* set x := (_ *m _); have -> : x 0 0 = theta ((x^t theta) 0 0) by rewrite !mxE. *)
(* rewrite !trmx_mul trmxK map_trmx mulmxA !map_mxM. *)
(* rewrite maptrmx_sesqui -!scalemxAr -scalemxAl mxE rmorphM rmorph_sign. *)
(* rewrite !map_mxM. *)
(* rewrite -map_mx_comp eq_map_mx_id //. *)
(* !linearZr_LR /=. linearZ. *)
(* linearZl. *)
(* rewrite trmx_sesqui. *)
(* rewrite mapmx. *)
(* rewrite map *)
(* apply/matrixP. *)
(* rewrite formC. *)
(* Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed. *)
(* Lemma cfCauchySchwarz u v : *)
(* `|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free (u :: v). *)
(* Proof. *)
(* rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC. *)
(* have [-> | nz_v] /= := altP (v =P 0). *)
(* by apply/lerifP; rewrite !cfdot0r normCK mul0r mulr0. *)
(* without loss ou: u / '[u, v] = 0. *)
(* move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v. *)
(* have ou: '[u1, v] = 0. *)
(* by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr. *)
(* rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //. *)
(* rewrite cfdotDl ou add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)). *)
(* rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ou mulr0. *)
(* by have:= IHo _ ou; rewrite mulrDl -lerif_subLR subrr ou normCK mul0r. *)
(* rewrite ou normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0. *)
(* rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_v) /=. *)
(* apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ou mulr0. *)
(* by rewrite cfnorm_eq0 => /eqP->; apply: rpred0. *)
(* Qed. *)
End Sesquilinear.
Notation "eps_theta .-sesqui" := (sesqui _ eps_theta) : ring_scope.
Notation symmetric_form := (false, idfun).-sesqui.
Notation skew := (true, idfun).-sesqui.
Notation hermitian := (false, @Num.conj_op _).-sesqui.
HB.mixin Record isDotProduct (R : numDomainType) (U : lmodType R)
(op : U -> U -> R) := { neq0_dnorm_gt0 : forall u, u != 0 -> 0 < op u u }.
HB.structure Definition Dot (R : numDomainType) (U : lmodType R)
(theta : R -> R) :=
{op of isDotProduct R U op & @Hermitian R U false theta op}.
Notation "{ 'dot' U 'for' theta }" := (@Dot.type _ U theta)
(format "{ 'dot' U 'for' theta }") : ring_scope.
(* duplicate to trick HB *)
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isZmodMorphism.Build _ _ (f u) (@zmod_morphismr_subproof _ _ _ _ _ _ f u).
#[non_forgetful_inheritance]
HB.instance Definition _ (R : numDomainType) (U : lmodType R)
(theta : R -> R) (f : {dot U for theta}) (u : U) :=
@GRing.isScalable.Build _ _ _ _ (f u) (@linearr_subproof _ _ _ _ _ _ f u).
(*Notation "{ 'dot' U 'for' theta }" := (map theta (Phant U))
(format "{ 'dot' U 'for' theta }") : ring_scope.
Coercion base : class_of >-> Hermitian.class_of.
Coercion apply : map >-> Funclass.
Notation "[ 'dot' 'of' f 'as' g ]" := (@clone _ _ _ _ _ f g _ idfun idfun)
(format "[ 'dot' 'of' f 'as' g ]") : form_scope.
Notation "[ 'dot' 'of' f ]" := (@clone _ _ _ _ _ f f _ idfun idfun)
(format "[ 'dot' 'of' f ]") : form_scope.
Notation Dot fM := (pack fM idfun).
Notation is_dot := Dot.axiom.*)
Notation "{ 'symmetric' U }" := ({hermitian U for false & idfun})
(format "{ 'symmetric' U }") : ring_scope.
Notation "{ 'skew_symmetric' U }" := ({hermitian U for true & idfun})
(format "{ 'skew_symmetric' U }") : ring_scope.
Notation "{ 'hermitian_sym' U 'for' theta }" := ({hermitian U for false & theta})
(format "{ 'hermitian_sym' U 'for' theta }") : ring_scope.
Definition is_skew (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = true) /\ (theta =1 id).
Definition is_sym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false) /\ (theta =1 id).
Definition is_hermsym (R : nzRingType) (eps : bool) (theta : R -> R)
(U : lmodType R) (form : {hermitian U for eps & theta}) :=
(eps = false).
Section HermitianModuleTheory.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma hermC u v : '[u, v] = (-1) ^+ eps * theta '[v, u].
Proof. by move: form => [? [[? ? ? ?] []]] /=. Qed.
Lemma hnormN u : '[- u] = '[u].
Proof. by rewrite linearNl linearNr opprK. Qed.
Lemma hnorm_sign n u : '[(-1) ^+ n *: u] = '[u].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?hnormN. Qed.
Lemma hnormD u v :
let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + (-1) ^+ eps * theta d).
Proof. by rewrite /= addrAC -hermC linearDl 2!linearDr !addrA. Qed.
Lemma hnormB u v :
let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + (-1) ^+ eps * theta d).
Proof.
by rewrite /= hnormD hnormN linearNr addrA rmorphN mulrN opprD addrA.
Qed.
Lemma hnormDd u v : '[u, v] = 0 -> '[u + v] = '[u] + '[v].
Proof. by move=> ouv; rewrite hnormD ouv rmorph0 mulr0 !addr0. Qed.
Lemma hnormBd u v : '[u, v] = 0 -> '[u - v] = '[u] + '[v].
Proof.
by move=> ouv; rewrite hnormDd ?hnormN// linearNr [X in - X]ouv oppr0.
Qed.
Local Notation "u '_|_ v" := ('[u, v] == 0) : ring_scope.
Definition ortho_rec (s1 s2 : seq U) :=
all [pred u | all [pred v | u '_|_ v] s2] s1.
Fixpoint pair_ortho_rec (s : seq U) :=
if s is v :: s' then ortho_rec [:: v] s' && pair_ortho_rec s' else true.
(* We exclude 0 from pairwise orthogonal sets. *)
Definition pairwise_orthogonal s := (0 \notin s) && pair_ortho_rec s.
Definition orthogonal s1 s2 := (@ortho_rec s1 s2).
Arguments orthogonal : simpl never.
Lemma orthogonal_cons u us vs :
orthogonal (u :: us) vs = orthogonal [:: u] vs && orthogonal us vs.
Proof. by rewrite /orthogonal /= andbT. Qed.
Definition orthonormal s := all [pred v | '[v] == 1] s && pair_ortho_rec s.
Lemma orthonormal_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= linear0r eq_sym oner_eq0.
Qed.
Lemma orthonormalE S :
orthonormal S = all [pred phi | '[phi] == 1] S && pairwise_orthogonal S.
Proof. by rewrite -(andb_idl (@orthonormal_not0 S)) andbCA. Qed.
Lemma orthonormal_orthogonal S : orthonormal S -> pairwise_orthogonal S.
Proof. by rewrite orthonormalE => /andP[_]. Qed.
End HermitianModuleTheory.
Arguments orthogonal {R eps theta U} form s1 s2.
Arguments pairwise_orthogonal {R eps theta U} form s.
Arguments orthonormal {R eps theta U} form s.
Section HermitianIsometry.
Variables (R : nzRingType) (eps : bool) (theta : {rmorphism R -> R}).
Variables (U1 U2 : lmodType R) (form1 : {hermitian U1 for eps & theta})
(form2 : {hermitian U2 for eps & theta}).
Local Notation "''[' u , v ]_1" := (form1 u%R v%R) : ring_scope.
Local Notation "''[' u , v ]_2" := (form2 u%R v%R) : ring_scope.
Local Notation "''[' u ]_1" := (form1 u%R u%R) : ring_scope.
Local Notation "''[' u ]_2" := (form2 u%R u%R): ring_scope.
Definition isometry tau := forall u v, form1 (tau u) (tau v) = form2 u%R v%R.
Definition isometry_from_to mD tau mR :=
prop_in2 mD (inPhantom (isometry tau)) /\
prop_in1 mD (inPhantom (forall u, in_mem (tau u) mR)).
Local Notation "{ 'in' D , 'isometry' tau , 'to' R }" :=
(isometry_from_to (mem D) tau (mem R))
(format "{ 'in' D , 'isometry' tau , 'to' R }")
: type_scope.
End HermitianIsometry.
Section HermitianVectTheory.
Variables (R : fieldType) (eps : bool) (theta : {rmorphism R -> R}).
Variable (U : lmodType R) (form : {hermitian U for eps & theta}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma herm_eq0C u v : ('[u, v] == 0) = ('[v, u] == 0).
Proof. by rewrite hermC mulf_eq0 signr_eq0 /= fmorph_eq0. Qed.
End HermitianVectTheory.
Section HermitianFinVectTheory.
Variables (F : fieldType) (eps : bool) (theta : {rmorphism F -> F}).
Variables (vT : vectType F) (form : {hermitian vT for eps & theta}).
Let n := \dim {:vT}.
Implicit Types (u v : vT) (U V : {vspace vT}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Let alpha v := (linfun (applyr form v : vT -> F^o)).
Definition orthov V := (\bigcap_(i < \dim V) lker (alpha (vbasis V)`_i))%VS.
Local Notation "U '_|_ V" := (U <= orthov V)%VS : vspace_scope.
Lemma mem_orthovPn V u : reflect (exists2 v, v \in V & '[u, v] != 0) (u \notin orthov V).
Proof.
apply: (iffP idP) => [u_orthovV|[v /coord_vbasis-> uvNorthov]]; last first.
apply/subv_bigcapP => uP.
rewrite linear_sumr big1 ?eqxx//= in uvNorthov.
move=> i _; have := uP i isT.
by rewrite -memvE memv_ker lfunE/= linearZr/= => /eqP/= ->; rewrite mulr0.
suff /existsP [i ui_neq0] : [exists i : 'I_(\dim V), '[u, (vbasis V)`_i] != 0].
by exists (vbasis V)`_i => //; rewrite vbasis_mem ?mem_nth ?size_tuple.
apply: contraNT u_orthovV; rewrite negb_exists => /forallP ui_eq0.
apply/subv_bigcapP => i _.
by rewrite -memvE memv_ker lfunE /= -[_ == _]negbK.
Qed.
Lemma mem_orthovP V u : reflect {in V, forall v, '[u, v] = 0} (u \in orthov V).
Proof.
apply: (iffP idP) => [/mem_orthovPn orthovNu v vV|/(_ _ _)/eqP orthov_u].
by apply/eqP/negP=> /negP Northov_uv; apply: orthovNu; exists v.
by apply/mem_orthovPn => -[v /orthov_u->].
Qed.
Lemma orthov1E u : orthov <[u]> = lker (alpha u).
Proof.
apply/eqP; rewrite eqEsubv; apply/andP.
split; apply/subvP=> v; rewrite memv_ker lfunE /=.
by move=> /mem_orthovP-> //; rewrite ?memv_line.
move=> vu_eq0; apply/mem_orthovP => w /vlineP[k->].
by apply/eqP; rewrite linearZ mulf_eq0 vu_eq0 orbT.
Qed.
Lemma orthovP U V : reflect {in U & V, forall u v, '[u, v] = 0} (U '_|_ V)%VS.
Proof.
apply: (iffP subvP); last by move=> H ??; apply/mem_orthovP=> ??; apply: H.
by move=> /(_ _ _)/mem_orthovP; move=> H ????; apply: H.
Qed.
Lemma orthov_sym U V : (U '_|_ V)%VS = (V '_|_ U)%VS.
Proof. by apply/orthovP/orthovP => eq0 ????; apply/eqP; rewrite herm_eq0C eq0. Qed.
Lemma mem_orthov1 v u : (u \in orthov <[v]>) = ('[u, v] == 0).
Proof. by rewrite orthov1E memv_ker lfunE. Qed.
Lemma orthov11 u v : (<[u]> '_|_ <[v]>)%VS = ('[u, v] == 0).
Proof. exact: mem_orthov1. Qed.
Lemma mem_orthov1_sym v u : (u \in orthov <[v]>) = (v \in orthov <[u]>).
Proof. exact: orthov_sym. Qed.
Lemma orthov0 : orthov 0 = fullv.
Proof.
apply/eqP; rewrite eqEsubv subvf.
apply/subvP => x _; rewrite mem_orthov1.
by rewrite linear0r.
Qed.
Lemma mem_orthov_sym V u : (u \in orthov V) = (V <= orthov <[u]>)%VS.
Proof. exact: orthov_sym. Qed.
Lemma leq_dim_orthov1 u V : ((\dim V).-1 <= \dim (V :&: orthov <[u]>))%N.
Proof.
rewrite -(limg_ker_dim (alpha u) V) -orthov1E.
have := dimvS (subvf (alpha u @: V)); rewrite dimvf addnC.
by case: (\dim _) => [|[]] // _; rewrite leq_pred.
Qed.
Lemma dim_img_form_eq1 u V : u \notin orthov V -> \dim (alpha u @: V)%VS = 1%N.
Proof.
move=> /mem_orthovPn [v vV Northov_uv]; apply/eqP; rewrite eqn_leq /=.
rewrite -[1%N as X in (_ <= X)%N](dimvf [the vectType F of F^o]) dimvS ?subvf//=.
have := @dimvS _ _ <['[v, u] : F^o]> (alpha u @: V).
rewrite -memvE dim_vline herm_eq0C Northov_uv; apply.
by apply/memv_imgP; exists v; rewrite ?memvf// !lfunE /=.
Qed.
Lemma eq_dim_orthov1 u V : u \notin orthov V -> (\dim V).-1 = \dim (V :&: orthov <[u]>).
Proof.
rewrite -(limg_ker_dim (alpha u) V) => /dim_img_form_eq1->.
by rewrite -orthov1E addn1.
Qed.
Lemma dim_img_form_eq0 u V : u \in orthov V -> \dim (alpha u @: V)%VS = 0%N.
Proof. by move=> uV; apply/eqP; rewrite dimv_eq0 -lkerE -orthov1E orthov_sym. Qed.
Lemma neq_dim_orthov1 u V : (\dim V > 0)%N ->
u \in orthov V -> ((\dim V).-1 < \dim (V :&: orthov <[u]>))%N.
Proof.
move=> V_gt0; rewrite -(limg_ker_dim (alpha u) V) -orthov1E => u_in.
rewrite dim_img_form_eq0 // addn0 (capv_idPl _) 1?orthov_sym //.
by case: (\dim _) V_gt0.
Qed.
Lemma leqif_dim_orthov1 u V : (\dim V > 0)%N ->
((\dim V).-1 <= \dim (V :&: orthov <[u]>) ?= iff (u \notin orthov V))%N.
Proof.
move=> Vr_gt0; apply/leqifP.
by case: (boolP (u \in _)) => /= [/neq_dim_orthov1->|/eq_dim_orthov1->].
Qed.
Lemma leqif_dim_orthov1_full u : (n > 0)%N ->
((\dim {:vT}).-1 <= \dim (orthov <[u]>) ?= iff (u \notin orthov fullv))%N.
Proof.
by move=> n_gt0; have := @leqif_dim_orthov1 u fullv; rewrite capfv; apply.
Qed.
(* Link between orthov and orthovgonality of sequences *)
Lemma orthogonal1P u v : reflect ('[u, v] = 0) (orthogonal form [:: u] [:: v]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP us vs :
reflect {in us & vs, forall u v, '[u, v] = 0} (orthogonal form us vs).
Proof.
apply: (iffP allP) => ousvs u => [v /ousvs/allP opus /opus/eqP // | /ousvs opus].
by apply/allP=> v /= /opus->.
Qed.
Lemma orthogonal_oppr S R : orthogonal form S (map -%R R) = orthogonal form S R.
Proof.
wlog suffices IH: S R / orthogonal form S R -> orthogonal form S (map -%R R).
by apply/idP/idP=> /IH; rewrite ?mapK //; apply: opprK.
move/orthogonalP=> oSR; apply/orthogonalP=> xi1 _ Sxi1 /mapP[xi2 Rxi2 ->].
by rewrite linearNr /= oSR ?oppr0.
Qed.
Lemma orthogonalE us vs : (orthogonal form us vs) = (<<us>> '_|_ <<vs>>)%VS.
Proof.
apply/orthogonalP/orthovP => uvsP u v; last first.
by move=> uus vvs; rewrite uvsP // memv_span.
rewrite -[us]in_tupleE -[vs]in_tupleE => /coord_span-> /coord_span->.
rewrite linear_sumr big1 //= => i _.
rewrite linear_sumlz big1 //= => j _.
by rewrite linearZlr/= uvsP ?mulr0// mem_nth.
Qed.
Lemma orthovE U V : (U '_|_ V)%VS = orthogonal form (vbasis U) (vbasis V).
Proof. by rewrite orthogonalE !(span_basis (vbasisP _)). Qed.
Notation radv := (orthov fullv).
Lemma orthoDv U V W : (U + V '_|_ W)%VS = (U '_|_ W)%VS && (V '_|_ W)%VS.
Proof. by rewrite subv_add. Qed.
Lemma orthovD U V W : (U '_|_ V + W)%VS = (U '_|_ V)%VS && (U '_|_ W)%VS.
Proof. by rewrite ![(U '_|_ _)%VS]orthov_sym orthoDv. Qed.
Definition nondegenerate := radv == 0%VS.
Definition is_psymplectic := [/\ nondegenerate, is_skew form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_porthogonal := [/\ nondegenerate, is_sym form &
2 \in [pchar F] -> forall u, '[u, u] = 0].
Definition is_unitary := nondegenerate /\ (is_hermsym form).
End HermitianFinVectTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use is_psymplectic instead.")]
Notation is_symplectic := is_psymplectic (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use is_porthogonal instead.")]
Notation is_orthogonal := is_porthogonal (only parsing).
Arguments orthogonalP {F eps theta vT form us vs}.
Arguments orthovP {F eps theta vT form U V}.
Arguments mem_orthovPn {F eps theta vT form V u}.
Arguments mem_orthovP {F eps theta vT form V u}.
Section DotVectTheory.
Variables (C : numClosedFieldType).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma dnorm_geiff0 u : 0 <= '[u] ?= iff (u == 0).
Proof.
by apply/leifP; have [->|uN0] := altP eqP; rewrite ?linear0r ?neq0_dnorm_gt0.
Qed.
Lemma dnorm_ge0 u : 0 <= '[u]. Proof. by rewrite dnorm_geiff0. Qed.
Lemma dnorm_eq0 u : ('[u] == 0) = (u == 0).
Proof. by rewrite -dnorm_geiff0 eq_sym. Qed.
Lemma dnorm_gt0 u : (0 < '[u]) = (u != 0).
Proof. by rewrite lt_def dnorm_eq0 dnorm_ge0 andbT. Qed.
Lemma sqrt_dnorm_ge0 u : 0 <= sqrtC '[u].
Proof. by rewrite sqrtC_ge0 dnorm_ge0. Qed.
Lemma sqrt_dnorm_eq0 u : (sqrtC '[u] == 0) = (u == 0).
Proof. by rewrite sqrtC_eq0 dnorm_eq0. Qed.
Lemma sqrt_dnorm_gt0 u : (sqrtC '[u] > 0) = (u != 0).
Proof. by rewrite sqrtC_gt0 dnorm_gt0. Qed.
Lemma dnormZ a u : '[a *: u]= `|a| ^+ 2 * '[u].
Proof. by rewrite linearZl_LR linearZr_LR/= mulrA normCK. Qed.
Lemma dnormD u v : let d := '[u, v] in '[u + v] = '[u] + '[v] + (d + d^*).
Proof. by rewrite hnormD mul1r. Qed.
Lemma dnormB u v : let d := '[u, v] in '[u - v] = '[u] + '[v] - (d + d^*).
Proof. by rewrite hnormB mul1r. Qed.
End DotVectTheory.
#[global]
Hint Extern 0 (is_true (0 <= Dot.sort _ _ _
(* NB: This Hint is assuming ^*, a more precise pattern would be welcome *)))
=> apply: dnorm_ge0 : core.
Section HermitianTheory.
Variables (C : numClosedFieldType) (eps : bool) (theta : {rmorphism C -> C}).
Variable (U : lmodType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal form S).
Proof.
rewrite /pairwise_orthogonal /=; case notS0: (~~ _); last by right; case.
elim: S notS0 => [|phi S IH] /=; first by left.
rewrite inE eq_sym andbT => /norP[nz_phi {}/IH IH].
have [opS | not_opS] := allP; last first.
right=> [[/andP[notSp _] opS]]; case: not_opS => psi Spsi /=.
by rewrite opS ?mem_head 1?mem_behead // (memPnC notSp).
rewrite (contra (opS _)) /= ?dnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi; rewrite !inE => /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
apply/eqP; rewrite hermC.
by move: (opS psi Spsi) => /= /eqP ->; rewrite rmorph0 mulr0.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal form (R ++ S) =
[&& pairwise_orthogonal form R, pairwise_orthogonal form S & orthogonal form R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT// all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma orthonormal_cat R S :
orthonormal form (R ++ S) =
[&& orthonormal form R, orthonormal form S & orthogonal form R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi] = (phi == psi)%:R})
(orthonormal form S).
Proof.
rewrite orthonormalE; have [/= normS | not_normS] := allP; last first.
by right=> [[_ o1S]]; case: not_normS => phi Sphi; rewrite /= o1S ?eqxx.
apply: (iffP (pairwise_orthogonalP S)) => [] [uniqS oSS].
split=> // [|phi psi]; first by case/andP: uniqS.
by have [-> _ /normS/eqP | /oSS] := altP eqP.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // linear0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal form S2 -> orthonormal form S1.
Proof.
move=> sS12 uniqS1 /orthonormalP[_ oS1].
by apply/orthonormalP; split; last apply: sub_in2 sS12 _ _.
Qed.
Lemma orthonormal2P phi psi :
reflect [/\ '[phi, psi] = 0, '[phi] = 1 & '[psi] = 1]
(orthonormal form [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
End HermitianTheory.
Section DotFinVectTheory.
Variable C : numClosedFieldType.
Variables (U : vectType C) (form : {dot U for conjC}).
Local Notation "''[' u , v ]" := (form u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal form S2 -> pairwise_orthogonal form S1.
Proof.
move=> sS12 uniqS1 /pairwise_orthogonalP[/andP[notS2_0 _] oS2].
apply/pairwise_orthogonalP; rewrite /= (contra (sS12 0)) //.
by split=> //; apply: sub_in2 oS2.
Qed.
Lemma orthogonal_free S : pairwise_orthogonal form S -> free S.
Proof.
case/pairwise_orthogonalP=> [/=/andP[notS0 uniqS] oSS].
rewrite -(in_tupleE S); apply/freeP => a aS0 i.
have S_i: S`_i \in S by apply: mem_nth.
have /eqP: '[S`_i, 0] = 0 := linear0r _ _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite linearZ /= oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 linearZ mulf_eq0 conjC_eq0 dnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal form S -> pairwise_orthogonal form (filter p S).
Proof.
move=> orthoS; apply: sub_pairwise_orthogonal (orthoS).
exact: mem_subseq (filter_subseq p S).
exact/filter_uniq/free_uniq/orthogonal_free.
Qed.
Lemma orthonormal_free S : orthonormal form S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Theorem CauchySchwarz (u v : U) :
`|'[u, v]| ^+ 2 <= '[u] * '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] /= := altP (v =P 0).
by apply/leifP; rewrite /= !linear0r normCK mul0r mulr0.
without loss ou: u / '[u, v] = 0.
move=> IHo; pose a := '[u, v] / '[v]; pose u1 := u - a *: v.
have ou: '[u1, v] = 0.
rewrite linearBl/=.
rewrite linearZl_LR.
by rewrite divfK ?dnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl u1)) rpredDr ?rpredZ ?memv_line //.
rewrite linearDl /= ou add0r.
rewrite linearZl_LR/= normrM (ger0_norm (dnorm_ge0 _ _)).
rewrite exprMn mulrA -dnormZ hnormDd/=; last by rewrite linearZr_LR/= ou mulr0.
have:= IHo _ ou.
by rewrite mulrDl -leifBLR subrr ou normCK mul0r.
rewrite ou normCK mul0r; split; first by rewrite mulr_ge0.
rewrite eq_sym mulf_eq0 orbC dnorm_eq0 (negPf nz_v) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite linearZr_LR/= ou mulr0.
by rewrite dnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma CauchySchwarz_sqrt u v :
`|'[u, v]| <= sqrtC '[u] * sqrtC '[v] ?= iff ~~ free [:: u; v].
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?nnegrE//.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM//= ?nnegrE//=.
exact: CauchySchwarz.
Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal form [:: phi] [:: psi]).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal form [:: phi] S).
Proof.
by rewrite [orthogonal form _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (orthogonal form).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite hermC /= oRS ?rmorph0 ?mulr0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal form S [:: psi]).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite hermC /= oSpsi //= conjC0 mulr0.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal form (R1 ++ R2) S = orthogonal form R1 S && orthogonal form R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal form R (S1 ++ S2) = orthogonal form R S1 && orthogonal form R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal form R = pairwise_orthogonal form S.
Proof.
apply: catCA_perm_subst R S => R S S'.
rewrite !pairwise_orthogonal_cat !orthogonal_catr (orthogonal_sym R S) -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal S0 S : perm_eq S0 S -> orthonormal form S0 = orthonormal form S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthogonal_oppl S R : orthogonal form (map -%R S) R = orthogonal form S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma triangle_lerif u v :
sqrtC '[u + v] <= sqrtC '[u] + sqrtC '[v]
?= iff ~~ free [:: u; v] && (0 <= coord [tuple v] 0 u).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?nnegrE ?sqrtC_ge0//.
rewrite andbC sqrrD !sqrtCK addrAC dnormD (mono_leif (lerD2l _))/=.
rewrite -mulr_natr -[_ + _](divfK (negbT (pnatr_eq0 C 2))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n//.
have := leif_trans (leif_Re_Creal '[u, v]) (CauchySchwarz_sqrt u v).
rewrite ReE; congr (_ <= _ ?= iff _); apply: andb_id2r.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_v] := altP (v =P 0); first by rewrite linear0 coord0.
case/vlineP=> [x ->]; rewrite linearZl linearZ/= pmulr_lge0 ?dnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal form S1 S2 -> phi1 \in <<S1>>%VS -> phi2 \in <<S2>>%VS ->
'[phi1, phi2] = 0.
Proof.
move/orthogonalP=> oS12; do 2!move/(@coord_span _ _ _ (in_tuple _))->.
rewrite linear_sumlz big1 // => i _; rewrite linear_sumr big1 // => j _.
by rewrite linearZlr/= oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : U & X \in <<S>>%VS &
{Y :U | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal form [:: Y] S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal form [:: Y] S}}.
- exists X => //; exists Y.
by rewrite hermC /= (span_orthogonal oYS) ?memv_span1 ?conjC0 // mulr0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[UU S_U [V -> oVS]] [X S_X [Y -> oYS]]] := (IHS phi, IHS beta).
pose Z := '[Y, V] / '[V] *: V; exists (X + Z).
rewrite /Z -{4}(addKr UU V) scalerDr scalerN addrA addrC span_cons.
by rewrite memv_add ?memvB ?memvZ ?memv_line.
exists (Y - Z); first by rewrite addrCA !addrA addrK addrC.
apply/orthoPl=> psi; rewrite !inE => /predU1P[-> | Spsi]; last first.
by rewrite linearBl linearZl_LR /= (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite linearBl !linearDr /= (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !linearZl_LR /= (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite linear0r !mul0r subrr.
by rewrite divfK ?dnorm_eq0 ?subrr.
Qed.
End DotFinVectTheory.
Arguments orthoP {C U form phi psi}.
Arguments pairwise_orthogonalP {C U form S}.
Arguments orthonormalP {C U form S}.
Arguments orthoPl {C U form phi S}.
Arguments orthoPr {C U form S psi}.
Section BuildIsometries.
Variables (C : numClosedFieldType) (U U1 U2 : vectType C).
Variables (form : {dot U for conjC}) (form1 : {dot U1 for conjC})
(form2 : {dot U2 for conjC}).
Definition normf1 := fun u => form1 u u.
Definition normf2 := fun u => form2 u u.
Lemma isometry_of_dnorm S tauS :
pairwise_orthogonal form1 S -> pairwise_orthogonal form2 tauS ->
map normf2 tauS = map normf1 S ->
{tau : {linear U1 -> U2} | map tau S = tauS
& {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> oS oT eq_nST; have freeS := orthogonal_free oS.
have eq_sz: size tauS = size S by have:= congr1 size eq_nST; rewrite !size_map.
have [tau defT] := linear_of_free S tauS; rewrite -[S]/(tval (in_tuple S)).
exists tau => [|u v /coord_span-> /coord_span->]; rewrite ?raddf_sum ?defT //=.
apply: eq_bigr => i _ /=; rewrite !linearZ/= !linear_sumlz; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !linearZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite /= -[RHS](nth_map 0 0 normf1) -?[LHS](nth_map 0 0 normf2) ?eq_sz // eq_nST.
have{oS} [/=/andP[_ uS] oS] := pairwise_orthogonalP oS.
have{oT} [/=/andP[_ uT] oT] := pairwise_orthogonalP oT.
by rewrite oS ?oT ?mem_nth ?nth_uniq ?eq_sz.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry form2 form1 f} ->
{tau : {linear U1 -> U2} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry form2 form1 tau}}.
Proof.
move=> freeS If; have defS := free_span freeS.
have [tau /(_ freeS (size_map f S))Dtau] := linear_of_free S (map f S).
have {}Dtau: {in S, tau =1 f}.
by move=> _ /(nthP 0)[i ltiS <-]; rewrite -!(nth_map 0 0) ?Dtau.
exists tau => // _ _ /defS[a -> _] /defS[b -> _] /=.
rewrite 2!{1}linear_sum /= !{1}linear_sumlz /=; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}linear_sumr; apply/eq_big_seq=> xi2 Sxi2 /=.
by rewrite !linearZ /= !linearZl !Dtau //= If.
Qed.
Lemma isometry_raddf_inj (tau : {additive U1 -> U2}) :
{in U1 &, isometry form2 form1 tau} ->
{in U1 &, forall u v, u - v \in U1} ->
{in U1 &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -(dnorm_eq0 form2) Itau ?linU // dnorm_eq0 subr_eq0 => /eqP.
Qed.
End BuildIsometries.
Section MatrixForms.
Variables (R : fieldType) (n : nat).
Implicit Types (a b : R) (u v : 'rV[R]_n) (M N P Q : 'M[R]_n).
Section Def.
Variable theta : R -> R.
Definition form_of_matrix m M (U V : 'M_(m, n)) := \tr (U *m M *m (V ^t theta)).
Definition matrix_of_form (form : 'rV[R]_n -> 'rV[R]_n -> R) : 'M[R]_n :=
\matrix_(i, j) form 'e_i 'e_j.
Implicit Type form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formE form i j : matrix_of_form form i j = form 'e_i 'e_j.
Proof. by rewrite mxE. Qed.
End Def.
Section FormOfMatrix.
Variables (m : nat) (M : 'M[R]_n).
Implicit Types (U V : 'M[R]_(m, n)).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' U , V ]" := (form_of_matrix theta M U%R V%R) : ring_scope.
Local Notation "''[' U ]" := '[U, U]%R : ring_scope.
Let form_of_matrix_is_linear U :
linear_for (theta \; *%R) (form_of_matrix theta M U).
Proof.
rewrite /form_of_matrix => k v w; rewrite -linearP/=.
by rewrite linearP map_mxD map_mxZ !mulmxDr !scalemxAr.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrix theta M U) (form_of_matrix_is_linear U).
Definition form_of_matrixr U := (form_of_matrix theta M)^~U.
Let form_of_matrixr_is_linear U : linear_for *%R (form_of_matrixr U).
Proof.
rewrite /form_of_matrixr /form_of_matrix => k v w.
by rewrite -linearP /= !mulmxDl -!scalemxAl.
Qed.
HB.instance Definition _ U := @GRing.isLinear.Build _ _ _ _
(form_of_matrixr U) (form_of_matrixr_is_linear U).
(* TODO
Canonical form_of_matrixr_rev :=
[revop form_of_matrixr of form_of_matrix theta M].
*)
Lemma form_of_matrix_is_bilinear :
bilinear_for
(GRing.Scale.Law.clone _ _ ( *%R ) _) (GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M).
Proof.
split=> [u'|u] a x y /=.
- by rewrite /form_of_matrix !mulmxDl linearD/= -!scalemxAl linearZ.
- rewrite /form_of_matrix -linearZ/= -linearD/= [in LHS]linearD/= map_mxD.
rewrite mulmxDr; congr (\tr (_ + _)).
rewrite scalemxAr; congr (_ *m _).
by rewrite linearZ/= map_mxZ.
Qed.
HB.instance Definition _ :=
bilinear_isBilinear.Build R _ _ _
(GRing.Scale.Law.clone _ _ ( *%R ) _)
(GRing.Scale.Law.clone _ _ (theta \; *%R ) _)
(@form_of_matrix theta m M)
form_of_matrix_is_bilinear.
(*Canonical form_of_matrix_is_bilinear := [the @bilinear _ _ _ _ of form_of_matrix theta M].*)
End FormOfMatrix.
Section FormOfMatrix1.
Variables (M : 'M[R]_n).
Variables (theta : {rmorphism R -> R}).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Lemma rV_formee i j : '['e_i :'rV__, 'e_j] = M i j.
Proof.
rewrite /form_of_matrix -rowE -map_trmx map_delta_mx -[M in LHS]trmxK.
by rewrite -tr_col -trmx_mul -rowE trace_mx11 !mxE.
Qed.
Lemma form_of_matrixK : matrix_of_form (form_of_matrix theta M) = M.
Proof. by apply/matrixP => i j; rewrite !mxE rV_formee. Qed.
Lemma rV_form0_eq0 : M = 0 -> forall u v, '[u, v] = 0.
Proof.
by rewrite /form_of_matrix => -> u v; rewrite mulmx0 mul0mx trace_mx11 mxE.
Qed.
End FormOfMatrix1.
Section MatrixOfForm.
Variable (theta : {rmorphism R -> R}).
Variable form : {bilinear 'rV[R]_n -> 'rV[R]_n -> R | *%R & theta \; *%R}.
Lemma matrix_of_formK : form_of_matrix theta (matrix_of_form form) =2 form.
Proof.
set f := (X in X =2 _); have f_eq i j : f 'e_i 'e_j = form 'e_i 'e_j.
by rewrite /f rV_formee mxE.
move=> u v; rewrite [u]row_sum_delta [v]row_sum_delta /f.
rewrite !linear_sum/=; apply: eq_bigr => j _.
rewrite !linear_sumlz/=; apply: eq_bigr => i _.
by rewrite !linearZlr/= -f_eq.
Qed.
End MatrixOfForm.
Section HermitianMx.
Variable eps : bool.
Section HermitianMxDef.
Variable theta : R -> R.
Definition hermitianmx :=
[qualify M : 'M_n | M == ((-1) ^+ eps) *: M ^t theta].
Fact hermitianmx_key : pred_key hermitianmx. Proof. by []. Qed.
Canonical hermitianmx_keyed := KeyedQualifier hermitianmx_key.
Structure hermitian_matrix := HermitianMx {
mx_of_hermitian :> 'M[R]_n;
_ : mx_of_hermitian \is hermitianmx }.
Lemma is_hermitianmxE M :
(M \is hermitianmx) = (M == (-1) ^+ eps *: M ^t theta).
Proof. by rewrite qualifE. Qed.
Lemma is_hermitianmxP M :
reflect (M = (-1) ^+ eps *: M ^t theta) (M \is hermitianmx).
Proof. by rewrite is_hermitianmxE; apply/eqP. Qed.
Lemma hermitianmxE (M : hermitian_matrix) :
M = ((-1) ^+ eps) *: M ^t theta :> 'M__.
Proof. by apply/eqP; case: M. Qed.
Lemma trmx_hermitian (M : hermitian_matrix) :
M^T = ((-1) ^+ eps) *: M ^ theta :> 'M__.
Proof. by rewrite {1}hermitianmxE linearZ /= map_trmx trmxK. Qed.
End HermitianMxDef.
Section HermitianMxTheory.
Variables (theta : involutive_rmorphism R) (M : hermitian_matrix theta).
Lemma maptrmx_hermitian : M^t theta = (-1) ^+ eps *: (M : 'M__).
Proof.
rewrite trmx_hermitian map_mxZ rmorph_sign -map_mx_comp.
by rewrite (map_mx_id (rmorphK _)).
Qed.
Lemma form_of_matrix_is_hermitian m x y :
(@form_of_matrix theta m M) x y =
(-1) ^+ eps * theta ((@form_of_matrix theta m M) y x).
Proof.
rewrite {1}hermitianmxE /form_of_matrix.
rewrite -!(scalemxAr, scalemxAl) linearZ/=; congr (_ * _).
rewrite -mxtrace_tr -trace_map_mx !(trmx_mul, map_mxM, map_trmx, trmxK).
by rewrite -mulmxA -!map_mx_comp !(map_mx_id (rmorphK _)).
Qed.
HB.instance Definition _ m := @isHermitianSesquilinear.Build _ _ _ _ _
(@form_of_matrix_is_hermitian m).
Local Notation "''[' u , v ]" := (form_of_matrix theta M u%R v%R) : ring_scope.
Local Notation "''[' u ]" := '[u, u]%R : ring_scope.
Local Notation "B ^!" := (orthomx theta M B) : matrix_set_scope.
Local Notation "A '_|_ B" := (A%MS <= B%MS^!)%MS : matrix_set_scope.
Lemma orthomxE u v : (u '_|_ v)%MS = ('[u, v] == 0).
Proof.
rewrite (sameP sub_kermxP eqP) mulmxA.
by rewrite [_ *m _^t _]mx11_scalar -trace_mx11 fmorph_eq0.
Qed.
Lemma hermmx_eq0P {u v} : reflect ('[u, v] = 0) (u '_|_ v)%MS.
Proof. by rewrite orthomxE; apply/eqP. Qed.
Lemma orthomxP p q (A : 'M_(p, n)) (B :'M_(q, n)) :
reflect (forall (u v : 'rV_n), u <= A -> v <= B -> u '_|_ v)%MS
(A '_|_ B)%MS.
Proof.
apply: (iffP idP) => AnB.
move=> u v uA vB; rewrite (submx_trans uA) // (submx_trans AnB) //.
apply/sub_kermxP; have /submxP [w ->] := vB.
rewrite trmx_mul map_mxM !mulmxA -[kermx _ *m _ *m _]mulmxA.
by rewrite [kermx _ *m _](sub_kermxP _) // mul0mx.
apply/rV_subP => u /AnB /(_ _) /sub_kermxP uMv; apply/sub_kermxP.
suff: forall m (v : 'rV[R]_m),
(forall i, v *m 'e_i ^t theta = 0 :> 'M_1) -> v = 0.
apply => i; rewrite !mulmxA -!mulmxA -map_mxM -trmx_mul uMv //.
by apply/submxP; exists 'e_i.
move=> /= m v Hv; apply: (can_inj (@trmxK _ _ _)).
rewrite trmx0; apply/row_matrixP=> i; rewrite row0 rowE.
apply: (can_inj (@trmxK _ _ _)); rewrite trmx0 trmx_mul trmxK.
by rewrite -(map_delta_mx theta) map_trmx Hv.
Qed.
Lemma orthomx_sym p q (A : 'M_(p, n)) (B :'M_(q, n)) :
(A '_|_ B)%MS = (B '_|_ A)%MS.
Proof.
gen have nC : p q A B / (A '_|_ B -> B '_|_ A)%MS; last by apply/idP/idP; apply/nC.
move=> AnB; apply/orthomxP => u v ? ?; rewrite orthomxE.
rewrite hermC mulf_eq0 ?fmorph_eq0 ?signr_eq0 /=.
by rewrite -orthomxE (orthomxP _ _ AnB).
Qed.
Lemma ortho_ortho_mx p (A : 'M_(p, n)) : (A^! '_|_ A)%MS. Proof. by []. Qed.
Lemma ortho_mx_ortho p (A : 'M_(p, n)) : (A '_|_ A^!)%MS.
Proof. by rewrite orthomx_sym. Qed.
Lemma rank_orthomx u : (\rank (u ^!) >= n.-1)%N.
Proof.
rewrite mxrank_ker -subn1 leq_sub2l //.
by rewrite (leq_trans (mxrankM_maxr _ _)) // rank_leq_col.
Qed.
Local Notation radmx := (1%:M^!)%MS.
Lemma radmxE : radmx = kermx M.
Proof. by rewrite /orthomx /orthomx trmx1 map_mx1 mulmx1. Qed.
Lemma orthoNmx k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
((- A) '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by rewrite eqmx_opp. Qed.
Lemma orthomxN k m (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) :
(A '_|_ (- B))%MS = (A '_|_ B)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoNmx. Qed.
Lemma orthoDmx k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A + B '_|_ C)%MS = (A '_|_ C)%MS && (B '_|_ C)%MS.
Proof. by rewrite addsmxE !(sameP sub_kermxP eqP) mul_col_mx col_mx_eq0. Qed.
Lemma orthomxD k m p (A : 'M[R]_(k, n)) (B : 'M[R]_(m, n)) (C : 'M[R]_(p, n)) :
(A '_|_ B + C)%MS = (A '_|_ B)%MS && (A '_|_ C)%MS.
Proof. by rewrite ![(A '_|_ _)%MS]orthomx_sym orthoDmx. Qed.
Lemma orthoZmx p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(a *: A '_|_ B)%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite eqmx_scale. Qed.
Lemma orthomxZ p m a (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) : a != 0 ->
(A '_|_ (a *: B))%MS = (A '_|_ B)%MS.
Proof. by move=> a_neq0; rewrite ![(A '_|_ _)%MS]orthomx_sym orthoZmx. Qed.
Lemma eqmx_ortho p m (A : 'M[R]_(p, n)) (B : 'M[R]_(m, n)) :
(A :=: B)%MS -> (A^! :=: B^!)%MS.
Proof.
move=> eqAB; apply/eqmxP.
by rewrite orthomx_sym -eqAB ortho_mx_ortho orthomx_sym eqAB ortho_mx_ortho.
Qed.
Lemma genmx_ortho p (A : 'M[R]_(p, n)) : (<<A>>^! :=: A^!)%MS.
Proof. exact: (eqmx_ortho (genmxE _)). Qed.
End HermitianMxTheory.
End HermitianMx.
End MatrixForms.
Notation symmetricmx := (hermitianmx _ false idfun).
Notation skewmx := (hermitianmx _ true idfun).
Notation hermsymmx := (hermitianmx _ false conjC).
Lemma hermitian1mx_subproof {C : numClosedFieldType} n : (1%:M : 'M[C]_n) \is hermsymmx.
Proof.
by rewrite qualifE /= expr0 scale1r tr_scalar_mx map_scalar_mx conjC1.
Qed.
Canonical hermitian1mx {C : numClosedFieldType} n :=
HermitianMx (@hermitian1mx_subproof C n).
|
test_rat.v
|
From mathcomp Require Import all_boot all_order all_algebra.
Local Open Scope ring_scope.
Goal 2%:Q + 2%:Q = 4%:Q.
Proof. reflexivity. Qed.
Goal - 2%:Q = -1 * 2%:Q.
Proof. reflexivity. Qed.
Goal 2%:Q ^+ 2 = 4%:Q.
Proof. reflexivity. Qed.
Goal (-1)^-1 = -1 :> rat.
Proof. reflexivity. Qed.
Local Open Scope rat_scope.
Check 12.
Check 3.14.
Check -3.14.
Check 0.5.
Check 0.2.
|
burnside_app.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 fingroup.
From mathcomp Require Import action perm primitive_action ssrAC.
(* Application of the Burside formula to count the number of distinct *)
(* colorings of the vertices of a square and a cube. *)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Lemma burnside_formula : forall (gT : finGroupType) s (G : {group gT}),
uniq s -> s =i G ->
forall (sT : finType) (to : {action gT &-> sT}),
(#|orbit to G @: setT| * size s)%N = \sum_(p <- s) #|'Fix_to[p]|.
Proof.
move=> gT s G Us sG sT to.
rewrite big_uniq // -(card_uniqP Us) (eq_card sG) -Frobenius_Cauchy.
by apply: eq_big => // p _; rewrite setTI.
by apply/actsP=> ? _ ?; rewrite !inE.
Qed.
Arguments burnside_formula {gT}.
Section colouring.
Variable n : nat.
Definition colors := 'I_n.
HB.instance Definition _ := Finite.on colors.
Section square_colouring.
Definition square := 'I_4.
HB.instance Definition _ := SubType.on square.
HB.instance Definition _ := Finite.on square.
Definition mksquare i : square := Sub (i %% _) (ltn_mod i 4).
Definition c0 := mksquare 0.
Definition c1 := mksquare 1.
Definition c2 := mksquare 2.
Definition c3 := mksquare 3.
(*rotations*)
Definition R1 (sc : square) : square := tnth [tuple c1; c2; c3; c0] sc.
Definition R2 (sc : square) : square := tnth [tuple c2; c3; c0; c1] sc.
Definition R3 (sc : square) : square := tnth [tuple c3; c0; c1; c2] sc.
Ltac get_inv elt l :=
match l with
| (_, (elt, ?x)) => x
| (elt, ?x) => x
| (?x, _) => get_inv elt x
end.
Definition rot_inv := ((R1, R3), (R2, R2), (R3, R1)).
Ltac inj_tac :=
move: (erefl rot_inv); unfold rot_inv;
match goal with |- ?X = _ -> injective ?Y =>
move=> _; let x := get_inv Y X in
apply: (can_inj (g:=x)); move=> [val H1]
end.
Lemma R1_inj : injective R1.
Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed.
Lemma R2_inj : injective R2.
Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed.
Lemma R3_inj : injective R3.
Proof. by inj_tac; repeat (destruct val => //=; first by apply/eqP). Qed.
Definition r1 := (perm R1_inj).
Definition r2 := (perm R2_inj).
Definition r3 := (perm R3_inj).
Definition id1 := (1 : {perm square}).
Definition is_rot (r : {perm _}) := (r * r1 == r1 * r).
Definition rot := [set r | is_rot r].
Lemma group_set_rot : group_set rot.
Proof.
apply/group_setP; split; first by rewrite /rot inE /is_rot mulg1 mul1g.
move=> x1 y; rewrite /rot !inE /= /is_rot; move/eqP => hx1; move/eqP => hy.
by rewrite -mulgA hy !mulgA hx1.
Qed.
Canonical rot_group := Group group_set_rot.
Definition rotations := [set id1; r1; r2; r3].
Lemma rot_eq_c0 : forall r s : {perm square},
is_rot r -> is_rot s -> r c0 = s c0 -> r = s.
Proof.
rewrite /is_rot => r s; move/eqP => hr; move/eqP=> hs hrs; apply/permP => a.
have ->: a = (r1 ^+ a) c0
by apply/eqP; case: a; do 4?case=> //=; rewrite ?permM !permE.
by rewrite -!permM -!commuteX // !permM hrs.
Qed.
Lemma rot_r1 : forall r, is_rot r -> r = r1 ^+ (r c0).
Proof.
move=> r hr; apply: rot_eq_c0 => //; apply/eqP.
by symmetry; apply: commuteX.
by case: (r c0); do 4?case=> //=; rewrite ?permM !permE /=.
Qed.
Lemma rotations_is_rot : forall r, r \in rotations -> is_rot r.
Proof.
move=> r Dr; apply/eqP; apply/permP => a; rewrite !inE -!orbA !permM in Dr *.
by case/or4P: Dr; move/eqP->; rewrite !permE //; case: a; do 4?case.
Qed.
Lemma rot_is_rot : rot = rotations.
Proof.
apply/setP=> r; apply/idP/idP => [|/rotations_is_rot] /[!inE]// h.
have -> : r = r1 ^+ (r c0) by apply: rot_eq_c0; rewrite // -rot_r1.
have e2: 2 = r2 c0 by rewrite permE /=.
have e3: 3 = r3 c0 by rewrite permE /=.
case (r c0); do 4?[case] => // ?; rewrite ?(expg1, eqxx, orbT) //.
by rewrite [nat_of_ord _]/= e2 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE).
by rewrite [nat_of_ord _]/= e3 -rot_r1 ?(eqxx, orbT, rotations_is_rot, inE).
Qed.
(*symmetries*)
Definition Sh (sc : square) : square := tnth [tuple c1; c0; c3; c2] sc.
Lemma Sh_inj : injective Sh.
Proof.
by apply: (can_inj (g:= Sh)); case; do 4?case=> //=; move=> H; apply/eqP.
Qed.
Definition sh := (perm Sh_inj).
Lemma sh_inv : sh^-1 = sh.
Proof.
apply: (mulIg sh); rewrite mulVg; apply/permP.
by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP.
Qed.
Definition Sv (sc : square) : square := tnth [tuple c3; c2; c1; c0] sc.
Lemma Sv_inj : injective Sv.
Proof.
by apply: (can_inj (g:= Sv)); case; do 4?case=> //=; move=> H; apply/eqP.
Qed.
Definition sv := (perm Sv_inj).
Lemma sv_inv : sv^-1 = sv.
Proof.
apply: (mulIg sv); rewrite mulVg; apply/permP.
by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP.
Qed.
Definition Sd1 (sc : square) : square := tnth [tuple c0; c3; c2; c1] sc.
Lemma Sd1_inj : injective Sd1.
Proof.
by apply: can_inj Sd1 _; case; do 4?case=> //=; move=> H; apply/eqP.
Qed.
Definition sd1 := (perm Sd1_inj).
Lemma sd1_inv : sd1^-1 = sd1.
Proof.
apply: (mulIg sd1); rewrite mulVg; apply/permP.
by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP.
Qed.
Definition Sd2 (sc : square) : square := tnth [tuple c2; c1; c0; c3] sc.
Lemma Sd2_inj : injective Sd2.
Proof.
by apply: can_inj Sd2 _; case; do 4?case=> //=; move=> H; apply/eqP.
Qed.
Definition sd2 := (perm Sd2_inj).
Lemma sd2_inv : sd2^-1 = sd2.
Proof.
apply: (mulIg sd2); rewrite mulVg; apply/permP.
by case; do 4?case=> //=; move=> H; rewrite !permE /= !permE; apply/eqP.
Qed.
Lemma ord_enum4 : enum 'I_4 = [:: c0; c1; c2; c3].
Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed.
Lemma diff_id_sh : 1 != sh.
Proof.
by apply/eqP; move/(congr1 (fun p : {perm square} => p c0)); rewrite !permE.
Qed.
Definition isometries2 := [set 1; sh].
Lemma card_iso2 : #|isometries2| = 2.
Proof. by rewrite cards2 diff_id_sh. Qed.
Lemma group_set_iso2 : group_set isometries2.
Proof.
apply/group_setP; split => [|x y]; rewrite !inE ?eqxx //.
do 2![case/orP; move/eqP->]; rewrite ?(mul1g, mulg1) ?eqxx ?orbT//.
by rewrite -/sh -{1}sh_inv mulVg eqxx.
Qed.
Canonical iso2_group := Group group_set_iso2.
Definition isometries :=
[set p | [|| p == 1, p == r1, p == r2, p == r3,
p == sh, p == sv, p == sd1 | p == sd2 ]].
Definition opp (sc : square) := tnth [tuple c2; c3; c0; c1] sc.
Definition is_iso (p : {perm square}) := forall ci, p (opp ci) = opp (p ci).
Lemma isometries_iso : forall p, p \in isometries -> is_iso p.
Proof.
move=> p; rewrite inE.
by do ?case/orP; move/eqP=> -> a; rewrite !permE; case: a; do 4?case.
Qed.
Ltac non_inj p a1 a2 heq1 heq2 :=
let h1:= fresh "h1" in
(absurd (p a1 = p a2); first (by red => - h1; move: (perm_inj h1));
by rewrite heq1 heq2; apply/eqP).
Ltac is_isoPtac p f e0 e1 e2 e3 :=
suff ->: p = f by [rewrite inE eqxx ?orbT];
let e := fresh "e" in apply/permP;
(do 5?[case] => // ?; [move: e0 | move: e1 | move: e2 | move: e3]) => e;
apply: etrans (congr1 p _) (etrans e _); apply/eqP; rewrite // permE.
Lemma is_isoP : forall p, reflect (is_iso p) (p \in isometries).
Proof.
move=> p; apply: (iffP idP) => [|iso_p]; first exact: isometries_iso.
move e1: (p c1) (iso_p c1) => k1; move e0: (p c0) (iso_p c0) k1 e1 => k0.
case: k0 e0; do 4?[case] => //= ? e0 e2; do 5?[case] => //= ? e1 e3;
try by [non_inj p c0 c1 e0 e1 | non_inj p c0 c3 e0 e3].
by is_isoPtac p id1 e0 e1 e2 e3.
by is_isoPtac p sd1 e0 e1 e2 e3.
by is_isoPtac p sh e0 e1 e2 e3.
by is_isoPtac p r1 e0 e1 e2 e3.
by is_isoPtac p sd2 e0 e1 e2 e3.
by is_isoPtac p r2 e0 e1 e2 e3.
by is_isoPtac p r3 e0 e1 e2 e3.
by is_isoPtac p sv e0 e1 e2 e3.
Qed.
Lemma group_set_iso : group_set isometries.
Proof.
apply/group_setP; split; first by rewrite inE eqxx /=.
by move=> x y hx hy; apply/is_isoP => ci; rewrite !permM !isometries_iso.
Qed.
Canonical iso_group := Group group_set_iso.
Lemma card_rot : #|rot| = 4.
Proof.
rewrite -[4]/(size [:: id1; r1; r2; r3]) -(card_uniqP _).
by apply: eq_card => x; rewrite rot_is_rot !inE -!orbA.
by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE.
Qed.
Lemma group_set_rotations : group_set rotations.
Proof. by rewrite -rot_is_rot group_set_rot. Qed.
Canonical rotations_group := Group group_set_rotations.
Notation col_squares := {ffun square -> colors}.
Definition act_f (sc : col_squares) (p : {perm square}) : col_squares :=
[ffun z => sc (p^-1 z)].
Lemma act_f_1 : forall k, act_f k 1 = k.
Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed.
Lemma act_f_morph : forall k x y, act_f k (x * y) = act_f (act_f k x) y.
Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed.
Definition to := TotalAction act_f_1 act_f_morph.
Definition square_coloring_number2 := #|orbit to isometries2 @: setT|.
Definition square_coloring_number4 := #|orbit to rotations @: setT|.
Definition square_coloring_number8 := #|orbit to isometries @: setT|.
Lemma Fid : 'Fix_to(1) = setT.
Proof. by apply/setP=> x /=; rewrite in_setT; apply/afix1P; apply: act1. Qed.
Lemma card_Fid : #|'Fix_to(1)| = (n ^ 4)%N.
Proof.
rewrite -[4]card_ord -[n]card_ord -card_ffun_on Fid cardsE.
by symmetry; apply: eq_card => f; apply/ffun_onP.
Qed.
Definition coin0 (sc : col_squares) : colors := sc c0.
Definition coin1 (sc : col_squares) : colors := sc c1.
Definition coin2 (sc : col_squares) : colors := sc c2.
Definition coin3 (sc : col_squares) : colors := sc c3.
Lemma eqperm_map : forall p1 p2 : col_squares,
(p1 == p2) = all (fun s => p1 s == p2 s) [:: c0; c1; c2; c3].
Proof.
move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x.
by apply/eqP; apply Ep12; case: x; do 4!case=> //.
Qed.
Lemma F_Sh :
'Fix_to[sh] = [set x | (coin0 x == coin1 x) && (coin2 x == coin3 x)].
Proof.
apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f sh_inv !ffunE !permE /=.
by rewrite eq_sym (eq_sym (x c3)) andbT andbA !andbb.
Qed.
Lemma F_Sv :
'Fix_to[sv] = [set x | (coin0 x == coin3 x) && (coin2 x == coin1 x)].
Proof.
apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f sv_inv !ffunE !permE /=.
by rewrite eq_sym andbT andbC (eq_sym (x c1)) andbA -andbA !andbb andbC.
Qed.
Ltac inv_tac :=
apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _;
let a := fresh "a" in apply/permP => a;
apply/eqP; rewrite permM !permE; case: a; do 4?case.
Lemma r1_inv : r1^-1 = r3.
Proof. by inv_tac. Qed.
Lemma r2_inv : r2^-1 = r2.
Proof. by inv_tac. Qed.
Lemma r3_inv : r3^-1 = r1.
Proof. by inv_tac. Qed.
Lemma F_r2 :
'Fix_to[r2] = [set x | (coin0 x == coin2 x) && (coin1 x == coin3 x)].
Proof.
apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f r2_inv !ffunE !permE /=.
by rewrite eq_sym andbT andbCA andbC (eq_sym (x c3)) andbA -andbA !andbb andbC.
Qed.
Lemma F_r1 : 'Fix_to[r1] =
[set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)].
Proof.
apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f r1_inv !ffunE !permE andbC.
by do 3![case E: {+}(_ == _); rewrite // {E}(eqP E)]; rewrite eqxx.
Qed.
Lemma F_r3 : 'Fix_to[r3] =
[set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&&(coin2 x == coin3 x)].
Proof.
apply/setP=> x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f r3_inv !ffunE !permE /=.
by do 3![case: eqVneq=> // <-].
Qed.
Lemma card_n2 : forall x y z t : square, uniq [:: x; y; z; t] ->
#|[set p : col_squares | (p x == p y) && (p z == p t)]| = (n ^ 2)%N.
Proof.
move=> x y z t Uxt; rewrite -[n]card_ord.
pose f (p : col_squares) := (p x, p z); rewrite -(@card_in_image _ _ f).
rewrite -mulnn -card_prod; apply: eq_card => [] [c d] /=; apply/imageP.
rewrite (cat_uniq [::x; y]) in Uxt; case/and3P: Uxt => _.
rewrite /= !orbF !andbT => /norP[] /[!inE] nxzt nyzt _.
exists [ffun i => if pred2 x y i then c else d].
by rewrite inE !ffunE /= !eqxx orbT (negbTE nxzt) (negbTE nyzt) !eqxx.
by rewrite {}/f !ffunE /= eqxx (negbTE nxzt).
move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz].
have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t].
by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz !eqxx.
apply/ffunP=> i; apply/eqP; apply: (allP eqp12).
by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxt) card_ord.
Qed.
Lemma card_n :
#|[set x | (coin0 x == coin1 x)&&(coin1 x == coin2 x)&& (coin2 x == coin3 x)]|
= n.
Proof.
rewrite -[n]card_ord /coin0 /coin1 /coin2 /coin3.
pose f (p : col_squares) := p c3; rewrite -(@card_in_image _ _ f).
apply: eq_card => c /=; apply/imageP.
exists ([ffun => c] : col_squares); last by rewrite /f ffunE.
by rewrite /= inE !ffunE !eqxx.
move=> p1 p2; rewrite /= !inE /f -!andbA => eqp1 eqp2 eqp12.
apply/eqP; rewrite eqperm_map /= andbT.
case/and3P: eqp1; do 3!move/eqP->; case/and3P: eqp2; do 3!move/eqP->.
by rewrite !andbb eqp12.
Qed.
Lemma burnside_app2 : (square_coloring_number2 * 2 = n ^ 4 + n ^ 2)%N.
Proof.
rewrite (burnside_formula [:: id1; sh]) => [||p]; last first.
- by rewrite !inE.
- by rewrite /= inE diff_id_sh.
by rewrite 2!big_cons big_nil addn0 {1}card_Fid F_Sh card_n2.
Qed.
Lemma burnside_app_rot :
(square_coloring_number4 * 4 = n ^ 4 + n ^ 2 + 2 * n)%N.
Proof.
rewrite (burnside_formula [:: id1; r1; r2; r3]) => [||p]; last first.
- by rewrite !inE !orbA.
- by apply: map_uniq (fun p : {perm square} => p c0) _ _; rewrite /= !permE.
rewrite !big_cons big_nil /= addn0 {1}card_Fid F_r1 F_r2 F_r3.
by rewrite card_n card_n2 //= [n + _]addnC !addnA addn0.
Qed.
Lemma F_Sd1 : 'Fix_to[sd1] = [set x | coin1 x == coin3 x].
Proof.
apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
rewrite /act_f sd1_inv !ffunE !permE /=.
by rewrite !eqxx !andbT eq_sym /= andbb.
Qed.
Lemma card_n3 : forall x y : square, x != y ->
#|[set k : col_squares | k x == k y]| = (n ^ 3)%N.
Proof.
move=> x y nxy; apply/eqP; case: (posnP n) => [n0|].
by rewrite n0; apply/existsP=> [] [p _]; case: (p c0) => i; rewrite n0.
move/eqn_pmul2l <-; rewrite -expnS -card_Fid Fid cardsT.
rewrite -{1}[n]card_ord -cardX.
pose pk k := [ffun i => k (if i == y then x else i) : colors].
rewrite -(@card_image _ _ (fun k : col_squares => (k y, pk k))).
apply/eqP; apply: eq_card => ck /=; rewrite inE /= [_ \in _]inE.
apply/eqP/imageP; last first.
by case=> k _ -> /=; rewrite !ffunE if_same eqxx.
case: ck => c k /= kxy.
exists [ffun i => if i == y then c else k i]; first by rewrite inE.
rewrite !ffunE eqxx; congr (_, _); apply/ffunP=> i; rewrite !ffunE.
case Eiy: (i == y); last by rewrite Eiy.
by rewrite (negbTE nxy) (eqP Eiy).
move=> k1 k2 [Eky Epk]; apply/ffunP=> i.
have{Epk}: pk k1 i = pk k2 i by rewrite Epk.
by rewrite !ffunE; case: eqP => // ->.
Qed.
Lemma F_Sd2 : 'Fix_to[sd2] = [set x | coin0 x == coin2 x].
Proof.
apply/setP => x; rewrite (sameP afix1P eqP) !inE eqperm_map /=.
by rewrite /act_f sd2_inv !ffunE !permE /= !eqxx !andbT eq_sym /= andbb.
Qed.
Lemma burnside_app_iso :
(square_coloring_number8 * 8 = n ^ 4 + 2 * n ^ 3 + 3 * n ^ 2 + 2 * n)%N.
Proof.
pose iso_list := [:: id1; r1; r2; r3; sh; sv; sd1; sd2].
rewrite (burnside_formula iso_list) => [||p]; last first.
- by rewrite /= !inE.
- apply: map_uniq (fun p : {perm square} => (p c0, p c1)) _ _.
by rewrite /= !permE.
rewrite !big_cons big_nil {1}card_Fid F_r1 F_r2 F_r3 F_Sh F_Sv F_Sd1 F_Sd2.
rewrite card_n !card_n3 // !card_n2 //= !addnA !addn0.
by rewrite [LHS]addn.[ACl 1 * 7 * 8 * 3 * 5 * 6 * 2 * 4].
Qed.
End square_colouring.
Section cube_colouring.
Definition cube := 'I_6.
HB.instance Definition _ := SubType.on cube.
HB.instance Definition _ := Finite.on cube.
Definition mkFcube i : cube := Sub (i %% 6) (ltn_mod i 6).
Definition F0 := mkFcube 0.
Definition F1 := mkFcube 1.
Definition F2 := mkFcube 2.
Definition F3 := mkFcube 3.
Definition F4 := mkFcube 4.
Definition F5 := mkFcube 5.
(* axial symetries*)
Definition S05 := [:: F0; F4; F3; F2; F1; F5].
Definition S05f (sc : cube) : cube := tnth [tuple of S05] sc.
Definition S14 := [:: F5; F1; F3; F2; F4; F0].
Definition S14f (sc : cube) : cube := tnth [tuple of S14] sc.
Definition S23 := [:: F5; F4; F2; F3; F1; F0].
Definition S23f (sc : cube) : cube := tnth [tuple of S23] sc.
(* rotations 90 *)
Definition R05 := [:: F0; F2; F4; F1; F3; F5].
Definition R05f (sc : cube) : cube := tnth [tuple of R05] sc.
Definition R50 := [:: F0; F3; F1; F4; F2; F5].
Definition R50f (sc : cube) : cube := tnth [tuple of R50] sc.
Definition R14 := [:: F3; F1; F0; F5; F4; F2].
Definition R14f (sc : cube) : cube := tnth [tuple of R14] sc.
Definition R41 := [:: F2; F1; F5; F0; F4; F3].
Definition R41f (sc : cube) : cube := tnth [tuple of R41] sc.
Definition R23 := [:: F1; F5; F2; F3; F0; F4].
Definition R23f (sc : cube) : cube := tnth [tuple of R23] sc.
Definition R32 := [:: F4; F0; F2; F3; F5; F1].
Definition R32f (sc : cube) : cube := tnth [tuple of R32] sc.
(* rotations 120 *)
Definition R024 := [:: F2; F5; F4; F1; F0; F3].
Definition R024f (sc : cube) : cube := tnth [tuple of R024] sc.
Definition R042 := [:: F4; F3; F0; F5; F2; F1].
Definition R042f (sc : cube) : cube := tnth [tuple of R042] sc.
Definition R012 := [:: F1; F2; F0; F5; F3; F4].
Definition R012f (sc : cube) : cube := tnth [tuple of R012] sc.
Definition R021 := [:: F2; F0; F1; F4; F5; F3].
Definition R021f (sc : cube) : cube := tnth [tuple of R021] sc.
Definition R031 := [:: F3; F0; F4; F1; F5; F2].
Definition R031f (sc : cube) : cube := tnth [tuple of R031] sc.
Definition R013 := [:: F1; F3; F5; F0; F2; F4].
Definition R013f (sc : cube) : cube := tnth [tuple of R013] sc.
Definition R043 := [:: F4; F2; F5; F0; F3; F1].
Definition R043f (sc : cube) : cube := tnth [tuple of R043] sc.
Definition R034 := [:: F3; F5; F1; F4; F0; F2].
Definition R034f (sc : cube) : cube := tnth [tuple of R034] sc.
(* last symmetries*)
Definition S1 := [:: F5; F2; F1; F4; F3; F0].
Definition S1f (sc : cube) : cube := tnth [tuple of S1] sc.
Definition S2 := [:: F5; F3; F4; F1; F2; F0].
Definition S2f (sc : cube) : cube := tnth [tuple of S2] sc.
Definition S3 := [:: F1; F0; F3; F2; F5; F4].
Definition S3f (sc : cube) : cube := tnth [tuple of S3] sc.
Definition S4 := [:: F4; F5; F3; F2; F0; F1].
Definition S4f (sc : cube) : cube := tnth [tuple of S4] sc.
Definition S5 := [:: F2; F4; F0; F5; F1; F3].
Definition S5f (sc : cube) : cube := tnth [tuple of S5] sc.
Definition S6 := [::F3; F4; F5; F0; F1; F2].
Definition S6f (sc : cube) : cube := tnth [tuple of S6] sc.
Lemma S1_inv : involutive S1f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S2_inv : involutive S2f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S3_inv : involutive S3f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S4_inv : involutive S4f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S5_inv : involutive S5f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S6_inv : involutive S6f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma S05_inj : injective S05f.
Proof. by apply: can_inj S05f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma S14_inj : injective S14f.
Proof. by apply: can_inj S14f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma S23_inv : involutive S23f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Lemma R05_inj : injective R05f.
Proof. by apply: can_inj R50f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R14_inj : injective R14f.
Proof. by apply: can_inj R41f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R23_inj : injective R23f.
Proof. by apply: can_inj R32f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R50_inj : injective R50f.
Proof. by apply: can_inj R05f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R41_inj : injective R41f.
Proof. by apply: can_inj R14f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R32_inj : injective R32f.
Proof. by apply: can_inj R23f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R024_inj : injective R024f.
Proof. by apply: can_inj R042f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R042_inj : injective R042f.
Proof. by apply: can_inj R024f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R012_inj : injective R012f.
Proof. by apply: can_inj R021f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R021_inj : injective R021f.
Proof. by apply: can_inj R012f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R031_inj : injective R031f.
Proof. by apply: can_inj R013f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R013_inj : injective R013f.
Proof. by apply: can_inj R031f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R043_inj : injective R043f.
Proof. by apply: can_inj R034f _ => z; apply/eqP; case: z; do 6?case. Qed.
Lemma R034_inj : injective R034f.
Proof. by apply: can_inj R043f _ => z; apply/eqP; case: z; do 6?case. Qed.
Definition id3 := 1 : {perm cube}.
Definition s05 := (perm S05_inj).
Definition s14 : {perm cube}.
Proof.
apply: (@perm _ S14f); apply: can_inj S14f _ => z.
by apply/eqP; case: z; do 6?case.
Defined.
Definition s23 := (perm (inv_inj S23_inv)).
Definition r05 := (perm R05_inj).
Definition r14 := (perm R14_inj).
Definition r23 := (perm R23_inj).
Definition r50 := (perm R50_inj).
Definition r41 := (perm R41_inj).
Definition r32 := (perm R32_inj).
Definition r024 := (perm R024_inj).
Definition r042 := (perm R042_inj).
Definition r012 := (perm R012_inj).
Definition r021 := (perm R021_inj).
Definition r031 := (perm R031_inj).
Definition r013 := (perm R013_inj).
Definition r043 := (perm R043_inj).
Definition r034 := (perm R034_inj).
Definition s1 := (perm (inv_inj S1_inv)).
Definition s2 := (perm (inv_inj S2_inv)).
Definition s3 := (perm (inv_inj S3_inv)).
Definition s4 := (perm (inv_inj S4_inv)).
Definition s5 := (perm (inv_inj S5_inv)).
Definition s6 := (perm (inv_inj S6_inv)).
Definition dir_iso3 := [set p |
[|| id3 == p, s05 == p, s14 == p, s23 == p, r05 == p, r14 == p, r23 == p,
r50 == p, r41 == p, r32 == p, r024 == p, r042 == p, r012 == p, r021 == p,
r031 == p, r013 == p, r043 == p, r034 == p,
s1 == p, s2 == p, s3 == p, s4 == p, s5 == p | s6 == p]].
Definition dir_iso3l := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41;
r32; r024; r042; r012; r021; r031; r013; r043; r034;
s1; s2; s3; s4; s5; s6].
Definition S0 := [:: F5; F4; F3; F2; F1; F0].
Definition S0f (sc : cube) : cube := tnth [tuple of S0] sc.
Lemma S0_inv : involutive S0f.
Proof. by move=> z; apply/eqP; case: z; do 6?case. Qed.
Definition s0 := (perm (inv_inj S0_inv)).
Definition is_iso3 (p : {perm cube}) := forall fi, p (s0 fi) = s0 (p fi).
Lemma dir_iso_iso3 : forall p, p \in dir_iso3 -> is_iso3 p.
Proof.
move=> p; rewrite inE.
by do ?case/orP; move/eqP=> <- a; rewrite !permE; case: a; do 6?case.
Qed.
Lemma iso3_ndir : forall p, p \in dir_iso3 -> is_iso3 (s0 * p).
Proof.
move=> p; rewrite inE.
by do ?case/orP; move/eqP=> <- a; rewrite !(permM, permE); case: a; do 6?case.
Qed.
Definition sop (p : {perm cube}) : seq cube := fgraph (val p).
Lemma sop_inj : injective sop.
Proof. by move=> p1 p2 /val_inj/(can_inj fgraphK)/val_inj. Qed.
Definition prod_tuple (t1 t2 : seq cube) :=
map (fun n : 'I_6 => nth F0 t2 n) t1.
Lemma sop_spec x (n0 : 'I_6): nth F0 (sop x) n0 = x n0.
Proof. by rewrite nth_fgraph_ord pvalE. Qed.
Lemma prod_t_correct : forall (x y : {perm cube}) (i : cube),
(x * y) i = nth F0 (prod_tuple (sop x) (sop y)) i.
Proof.
move=> x y i; rewrite permM -!sop_spec [RHS](nth_map F0) // size_tuple /=.
by rewrite card_ord ltn_ord.
Qed.
Lemma sop_morph : {morph sop : x y / x * y >-> prod_tuple x y}.
Proof.
move=> x y; apply: (@eq_from_nth _ F0) => [|/= i].
by rewrite size_map !size_tuple.
rewrite size_tuple card_ord => lti6.
by rewrite -[i]/(val (Ordinal lti6)) sop_spec -prod_t_correct.
Qed.
Definition ecubes : seq cube := [:: F0; F1; F2; F3; F4; F5].
Lemma ecubes_def : ecubes = enum (@predT cube).
Proof. by apply: (inj_map val_inj); rewrite val_enum_ord. Qed.
Definition seq_iso_L := [::
[:: F0; F1; F2; F3; F4; F5];
S05; S14; S23; R05; R14; R23; R50; R41; R32;
R024; R042; R012; R021; R031; R013; R043; R034;
S1; S2; S3; S4; S5; S6].
Lemma seqs1 : forall f injf, sop (@perm _ f injf) = map f ecubes.
Proof.
move=> f ?; rewrite ecubes_def /sop /= -codom_ffun pvalE.
by apply: eq_codom; apply: permE.
Qed.
Lemma Lcorrect : seq_iso_L == map sop [:: id3; s05; s14; s23; r05; r14; r23;
r50; r41; r32; r024; r042; r012; r021; r031; r013; r043; r034;
s1; s2; s3; s4; s5; s6].
Proof. by rewrite /= !seqs1. Qed.
Lemma iso0_1 : dir_iso3 =i dir_iso3l.
Proof. by move=> p; rewrite /= !inE /= -!(eq_sym p). Qed.
Lemma L_iso : forall p, (p \in dir_iso3) = (sop p \in seq_iso_L).
Proof.
by move=> p; rewrite (eqP Lcorrect) mem_map ?iso0_1 //; apply: sop_inj.
Qed.
Lemma stable : forall x y,
x \in dir_iso3 -> y \in dir_iso3 -> x * y \in dir_iso3.
Proof.
move=> x y; rewrite !L_iso sop_morph => Hx Hy.
by move/sop: y Hy; apply/allP; move/sop: x Hx; apply/allP; vm_compute.
Qed.
Lemma iso_eq_F0_F1 : forall r s : {perm cube}, r \in dir_iso3 ->
s \in dir_iso3 -> r F0 = s F0 -> r F1 = s F1 -> r = s.
Proof.
move=> r s; rewrite !L_iso => hr hs hrs0 hrs1; apply: sop_inj; apply/eqP.
move/eqP: hrs0; apply/implyP; move/eqP: hrs1; apply/implyP; rewrite -!sop_spec.
by move/sop: r hr; apply/allP; move/sop: s hs; apply/allP; vm_compute.
Qed.
Lemma ndir_s0p : forall p, p \in dir_iso3 -> s0 * p \notin dir_iso3.
Proof.
move=> p; rewrite !L_iso sop_morph seqs1.
by move/sop: p; apply/allP; vm_compute.
Qed.
Definition indir_iso3l := map (mulg s0) dir_iso3l.
Definition iso3l := dir_iso3l ++ indir_iso3l.
Definition seq_iso3_L := map sop iso3l.
Lemma eqperm : forall p1 p2 : {perm cube},
(p1 == p2) = all (fun s => p1 s == p2 s) ecubes.
Proof.
move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/permP=> x.
by apply/eqP; rewrite Ep12 // ecubes_def mem_enum.
Qed.
Lemma iso_eq_F0_F1_F2 : forall r s : {perm cube}, is_iso3 r ->
is_iso3 s -> r F0 = s F0 -> r F1 = s F1 -> r F2 = s F2 -> r = s.
Proof.
move=> r s hr hs hrs0 hrs1 hrs2.
have:= hrs0; have:= hrs1; have:= hrs2.
have e23: F2 = s0 F3 by apply/eqP; rewrite permE /S0f (tnth_nth F0).
have e14: F1 = s0 F4 by apply/eqP; rewrite permE /S0f (tnth_nth F0).
have e05: F0 = s0 F5 by apply/eqP; rewrite permE /S0f (tnth_nth F0).
rewrite e23 e14 e05; rewrite !hr !hs.
move/perm_inj=> hrs3; move/perm_inj=> hrs4; move/perm_inj=> hrs5.
by apply/eqP; rewrite eqperm /= hrs0 hrs1 hrs2 hrs3 hrs4 hrs5 !eqxx.
Qed.
Ltac iso_tac :=
let a := fresh "a" in apply/permP => a;
apply/eqP; rewrite !permM !permE; case: a; do 6?case.
Ltac inv_tac :=
apply: esym (etrans _ (mul1g _)); apply: canRL (mulgK _) _; iso_tac.
Lemma dir_s0p : forall p, (s0 * p) \in dir_iso3 -> p \notin dir_iso3.
Proof.
move=> p Hs0p; move: (ndir_s0p Hs0p); rewrite mulgA.
have e: (s0^-1=s0) by inv_tac.
by rewrite -{1}e mulVg mul1g.
Qed.
Definition is_iso3b p := (p * s0 == s0 * p).
Definition iso3 := [set p | is_iso3b p].
Lemma is_iso3P : forall p, reflect (is_iso3 p) (p \in iso3).
Proof.
move=> p; apply: (iffP idP); rewrite inE /iso3 /is_iso3b /is_iso3 => e.
by move=> fi; rewrite -!permM (eqP e).
by apply/eqP; apply/permP=> z; rewrite !permM (e z).
Qed.
Lemma group_set_iso3 : group_set iso3.
Proof.
apply/group_setP; split.
by apply/is_iso3P => fi; rewrite -!permM mulg1 mul1g.
move=> x1 y; rewrite /iso3 !inE /= /is_iso3.
rewrite /is_iso3b.
rewrite -mulgA.
move/eqP => hx1; move/eqP => hy.
rewrite hy !mulgA. by rewrite -hx1.
Qed.
Canonical iso_group3 := Group group_set_iso3.
Lemma group_set_diso3 : group_set dir_iso3.
Proof.
apply/group_setP; split; first by rewrite inE eqxx /=.
by apply: stable.
Qed.
Canonical diso_group3 := Group group_set_diso3.
Lemma gen_diso3 : dir_iso3 = <<[set r05; r14]>>.
Proof.
apply/setP/subset_eqP/andP; split; first last.
rewrite gen_subG; apply/subsetP.
by move=> x /[!inE] /orP[] /eqP->; rewrite !eqxx !orbT.
apply/subsetP => x /[!inE].
have -> : s05 = r05 * r05 by iso_tac.
have -> : s14 = r14 * r14 by iso_tac.
have -> : s23 = r14 * r14 * r05 * r05 by iso_tac.
have -> : r23 = r05 * r14 * r05 * r14 * r14 by iso_tac.
have -> : r50 = r05 * r05 * r05 by iso_tac.
have -> : r41 = r14 * r14 * r14 by iso_tac.
have -> : r32 = r14 * r14 * r14 * r05* r14 by iso_tac.
have -> : r024 = r05 * r14 * r14 * r14 by iso_tac.
have -> : r042 = r14 * r05 * r05 * r05 by iso_tac.
have -> : r012 = r14 * r05 by iso_tac.
have -> : r021 = r05 * r14 * r05 * r05 by iso_tac.
have -> : r031 = r05 * r14 by iso_tac.
have -> : r013 = r05 * r05 * r14 * r05 by iso_tac.
have -> : r043 = r14 * r14 * r14 * r05 by iso_tac.
have -> : r034 = r05 * r05 * r05 * r14 by iso_tac.
have -> : s1 = r14 * r14 * r05 by iso_tac.
have -> : s2 = r05 * r14 * r14 by iso_tac.
have -> : s3 = r05 * r14 * r05 by iso_tac.
have -> : s4 = r05 * r14 * r14 * r14 * r05 by iso_tac.
have -> : s5 = r14 * r05 * r05 by iso_tac.
have -> : s6 = r05 * r05 * r14 by iso_tac.
by do ?case/predU1P=> [<-|]; first exact: group1; last (move/eqP<-);
rewrite ?groupMl ?mem_gen // !inE eqxx ?orbT.
Qed.
Notation col_cubes := {ffun cube -> colors}.
Definition act_g (sc : col_cubes) (p : {perm cube}) : col_cubes :=
[ffun z => sc (p^-1 z)].
Lemma act_g_1 : forall k, act_g k 1 = k.
Proof. by move=> k; apply/ffunP=> a; rewrite ffunE invg1 permE. Qed.
Lemma act_g_morph : forall k x y, act_g k (x * y) = act_g (act_g k x) y.
Proof. by move=> k x y; apply/ffunP=> a; rewrite !ffunE invMg permE. Qed.
Definition to_g := TotalAction act_g_1 act_g_morph.
Definition cube_coloring_number24 := #|orbit to_g diso_group3 @: setT|.
Lemma Fid3 : 'Fix_to_g[1] = setT.
Proof. by apply/setP=> x /=; rewrite (sameP afix1P eqP) !inE act1 eqxx. Qed.
Lemma card_Fid3 : #|'Fix_to_g[1]| = (n ^ 6)%N.
Proof.
rewrite -[6]card_ord -[n]card_ord -card_ffun_on Fid3 cardsT.
by symmetry; apply: eq_card => ff; apply/ffun_onP.
Qed.
Definition col0 (sc : col_cubes) : colors := sc F0.
Definition col1 (sc : col_cubes) : colors := sc F1.
Definition col2 (sc : col_cubes) : colors := sc F2.
Definition col3 (sc : col_cubes) : colors := sc F3.
Definition col4 (sc : col_cubes) : colors := sc F4.
Definition col5 (sc : col_cubes) : colors := sc F5.
Lemma eqperm_map2 : forall p1 p2 : col_cubes,
(p1 == p2) = all (fun s => p1 s == p2 s) [:: F0; F1; F2; F3; F4; F5].
Proof.
move=> p1 p2; apply/eqP/allP=> [-> // | Ep12]; apply/ffunP=> x.
by apply/eqP; apply Ep12; case: x; do 6?case.
Qed.
Notation infE := (sameP afix1P eqP).
Lemma F_s05 :
'Fix_to_g[s05] = [set x | (col1 x == col4 x) && (col2 x == col3 x)].
Proof.
have s05_inv: s05^-1=s05 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s05_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0.
by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ].
Qed.
Lemma F_s14 :
'Fix_to_g[s14]= [set x | (col0 x == col5 x) && (col2 x == col3 x)].
Proof.
have s14_inv: s14^-1=s14 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s14_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0.
by do 2![rewrite eq_sym; case: {+}(_ == _)=> //= ].
Qed.
Lemma r05_inv : r05^-1 = r50.
Proof. by inv_tac. Qed.
Lemma r50_inv : r50^-1 = r05.
Proof. by inv_tac. Qed.
Lemma r14_inv : r14^-1 = r41.
Proof. by inv_tac. Qed.
Lemma r41_inv : r41^-1 = r14.
Proof. by inv_tac. Qed.
Lemma s23_inv : s23^-1 = s23.
Proof. by inv_tac. Qed.
Lemma F_s23 :
'Fix_to_g[s23] = [set x | (col0 x == col5 x) && (col1 x == col4 x)].
Proof.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s23_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= andbT/col1/col2/col3/col4/col5/col0.
by do 2![rewrite eq_sym; case: {+}(_ == _)=> //=].
Qed.
Lemma F_r05 : 'Fix_to_g[r05]=
[set x | (col1 x == col2 x) && (col2 x == col3 x)
&& (col3 x == col4 x)].
Proof.
apply sym_equal.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r05_inv !ffunE !permE /=.
rewrite !eqxx /= !andbT /col1/col2/col3/col4/col5/col0.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r50 : 'Fix_to_g[r50]=
[set x | (col1 x == col2 x) && (col2 x == col3 x)
&& (col3 x == col4 x)].
Proof.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r50_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= !andbT /col1/col2/col3/col4.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r23 : 'Fix_to_g[r23] =
[set x | (col0 x == col1 x) && (col1 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r23_inv: r23^-1 = r32 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r23_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r32 : 'Fix_to_g[r32] =
[set x | (col0 x == col1 x) && (col1 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r32_inv: r32^-1 = r23 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r32_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= !andbT /col1/col0/col5/col4.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r14 : 'Fix_to_g[r14] =
[set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)].
Proof.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r14_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r41 : 'Fix_to_g[r41] =
[set x | (col0 x == col2 x) && (col2 x == col3 x) && (col3 x == col5 x)].
Proof.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r41_inv !ffunE !permE /=.
apply sym_equal; rewrite !eqxx /= !andbT /col2/col0/col5/col3.
by do 3![case: eqVneq; rewrite ?andbF // => <-].
Qed.
Lemma F_r024 : 'Fix_to_g[r024] =
[set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x)
&& (col3 x == col5 x) ].
Proof.
have r024_inv: r024^-1 = r042 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r024_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r042 : 'Fix_to_g[r042] =
[set x | (col0 x == col4 x) && (col4 x == col2 x) && (col1 x == col3 x)
&& (col3 x == col5 x)].
Proof.
have r042_inv: r042^-1 = r024 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r042_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r012 : 'Fix_to_g[r012] =
[set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r012_inv: r012^-1 = r021 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r012_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r021 : 'Fix_to_g[r021] =
[set x | (col0 x == col2 x) && (col2 x == col1 x) && (col3 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r021_inv: r021^-1 = r012 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r021_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r031 : 'Fix_to_g[r031] =
[set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r031_inv: r031^-1 = r013 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r031_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r013 : 'Fix_to_g[r013] =
[set x | (col0 x == col3 x) && (col3 x == col1 x) && (col2 x == col4 x)
&& (col4 x == col5 x)].
Proof.
have r013_inv: r013^-1 = r031 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r013_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r043 : 'Fix_to_g[r043] =
[set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x)
&& (col2 x == col5 x)].
Proof.
have r043_inv: r043^-1 = r034 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r043_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_r034 : 'Fix_to_g[r034] =
[set x | (col0 x == col4 x) && (col4 x == col3 x) && (col1 x == col2 x)
&& (col2 x == col5 x)].
Proof.
have r034_inv: r034^-1 = r043 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g r034_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 4![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s1 : 'Fix_to_g[s1] =
[set x | (col0 x == col5 x) && (col1 x == col2 x) && (col3 x == col4 x)].
Proof.
have s1_inv: s1^-1 = s1 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s1_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s2 : 'Fix_to_g[s2] =
[set x | (col0 x == col5 x) && (col1 x == col3 x) && (col2 x == col4 x)].
Proof.
have s2_inv: s2^-1 = s2 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s2_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s3 : 'Fix_to_g[s3] =
[set x | (col0 x == col1 x) && (col2 x == col3 x) && (col4 x == col5 x)].
Proof.
have s3_inv: s3^-1 = s3 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s3_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s4 : 'Fix_to_g[s4] =
[set x | (col0 x == col4 x) && (col1 x == col5 x) && (col2 x == col3 x)].
Proof.
have s4_inv: s4^-1 = s4 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s4_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s5 : 'Fix_to_g[s5] =
[set x | (col0 x == col2 x) && (col1 x == col4 x) && (col3 x == col5 x)].
Proof.
have s5_inv: s5^-1 = s5 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s5_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma F_s6 : 'Fix_to_g[s6] =
[set x | (col0 x == col3 x) && (col1 x == col4 x) && (col2 x == col5 x)].
Proof.
have s6_inv: s6^-1 = s6 by inv_tac.
apply/setP => x; rewrite infE !inE eqperm_map2 /= /act_g s6_inv !ffunE !permE /=.
apply sym_equal; rewrite ?eqxx /= !andbT /col0/col1/col2/col3/col4/col5.
by do 3![case: eqVneq=> E; rewrite ?andbF // ?{}E].
Qed.
Lemma uniq4_uniq6 : forall x y z t : cube,
uniq [:: x; y; z; t] -> exists u, exists v, uniq [:: x; y; z; t; u; v].
Proof.
move=> x y z t Uxt; move: (cardC [in [:: x; y; z; t]]).
rewrite card_ord (card_uniq_tuple Uxt) => hcard.
have hcard2: #|[predC [:: x; y; z; t]]| = 2.
by apply: (@addnI 4); rewrite /injective hcard.
have: #|[predC [:: x; y; z; t]]| != 0 by rewrite hcard2.
case/existsP=> u Hu; exists u.
move: (cardC [in [:: x; y; z; t; u]]); rewrite card_ord => hcard5.
have: #|[predC [:: x; y; z; t; u]]| !=0.
rewrite -lt0n -(ltn_add2l #|[:: x; y; z; t; u]|) hcard5 addn0.
by apply: (leq_ltn_trans (card_size [:: x; y; z; t; u])).
case/existsP => v; rewrite (mem_cat _ [:: _; _; _; _]) => /norP[Hv Huv].
exists v; rewrite (cat_uniq [:: x; y; z; t]) Uxt andTb -rev_uniq /= orbF.
by rewrite negb_or Hu Hv Huv.
Qed.
Lemma card_n4 : forall x y z t : cube, uniq [:: x; y; z; t] ->
#|[set p : col_cubes | (p x == p y) && (p z == p t)]| = (n ^ 4)%N.
Proof.
move=> x y z t Uxt; rewrite -[n]card_ord.
case: (uniq4_uniq6 Uxt) => u [v Uxv].
pose ff (p : col_cubes) := (p x, p z, p u, p v).
rewrite -(@card_in_image _ _ ff); first last.
move=> p1 p2 /[!inE] /andP[p1y p1t] /andP[p2y p2t] [px pz] pu pv.
have eqp12 : all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v].
by rewrite /= -(eqP p1y) -(eqP p1t) -(eqP p2y) -(eqP p2t) px pz pu pv !eqxx.
apply/ffunP=> i; apply/eqP; apply: (allP eqp12).
by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord.
have -> : forall n, (n ^ 4 = n * n * n * n)%N by move=> ?; rewrite -!mulnA.
rewrite -!card_prod; apply: eq_card => [] [[[c d] e] g] /=; apply/imageP => /=.
move: Uxv; rewrite (cat_uniq [:: x; y; z; t]) => /and3P[_]/=; rewrite orbF.
move=> /norP[] /[!inE] + + /andP[/negPf nuv _].
rewrite orbA => /norP[/negPf nxyu /negPf nztu].
rewrite orbA => /norP[/negPf nxyv /negPf nztv].
move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_]/= /[!(andbT, orbF)].
move=> /norP[] /[!inE] /negPf nxyz /negPf nxyt _.
exists [ffun i => if pred2 x y i then c else if pred2 z t i then d
else if u == i then e else g].
by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt.
by rewrite {}/ff !ffunE /= !eqxx /= nxyz nxyu nztu nxyv nztv nuv.
Qed.
Lemma card_n3_3 : forall x y z t: cube, uniq [:: x; y; z; t] ->
#|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p z == p t)]|
= (n ^ 3)%N.
Proof.
move=> x y z t Uxt; rewrite -[n]card_ord.
case: (uniq4_uniq6 Uxt) => u [v Uxv].
pose ff (p : col_cubes) := (p x, p u, p v);
rewrite -(@card_in_image _ _ ff); first last.
move=> p1 p2 /[!inE]; rewrite -!andbA.
move=> /and3P[/eqP p1xy /eqP p1yz /eqP p1zt].
move=> /and3P[/eqP p2xy /eqP p2yz /eqP p2zt] [px pu] pv.
have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v].
by rewrite /= -p1zt -p2zt -p1yz -p2yz -p1xy -p2xy px pu pv !eqxx.
apply/ffunP=> i; apply/eqP; apply: (allP eqp12).
by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord.
have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA.
rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP.
move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[_ hasxt].
rewrite /uniq !inE !andbT => /negPf nuv.
exists [ffun i => if i \in [:: x; y; z; t] then c else if u == i then d else e].
by rewrite /= !(inE, ffunE, eqxx, orbT).
rewrite {}/ff !(ffunE, inE, eqxx) /=; move: hasxt; rewrite nuv.
by do 8![case E: ( _ == _ ); rewrite ?(eqP E)/= ?inE ?eqxx //= ?E {E}].
Qed.
Lemma card_n2_3 : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] ->
#|[set p : col_cubes | (p x == p y) && (p y == p z)&& (p t == p u )
&& (p u== p v)]| = (n ^ 2)%N.
Proof.
move=> x y z t u v Uxv; rewrite -[n]card_ord .
pose ff (p : col_cubes) := (p x, p t).
rewrite -(@card_in_image _ _ ff); first last.
move=> p1 p2 /[!inE]; rewrite -!andbA.
move=> /and4P[/eqP p1xy /eqP p1yz /eqP p1tu /eqP p1uv].
move=> /and4P[/eqP p2xy/eqP p2yz /eqP p2tu /eqP p2uv] [px pu].
have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v].
by rewrite /= -p1yz -p2yz -p1xy -p2xy -p1uv -p2uv -p1tu -p2tu px pu !eqxx.
apply/ffunP=> i; apply/eqP; apply: (allP eqp12).
by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord.
rewrite -mulnn -!card_prod; apply: eq_card => [] [c d]/=; apply/imageP.
move: Uxv; rewrite (cat_uniq [::x; y; z]) => /= /and3P[Uxt + nuv].
move=> /[!orbF] /norP[] /[!inE] /negPf nxyzt /norP[/negPf nxyzu /negPf nxyzv].
exists [ffun i => if (i \in [:: x; y; z] ) then c else d].
by rewrite /= !(inE, ffunE, eqxx, orbT, nxyzt, nxyzu, nxyzv).
by rewrite {}/ff !ffunE !inE /= !eqxx /= nxyzt.
Qed.
Lemma card_n3s : forall x y z t u v: cube, uniq [:: x; y; z; t; u; v] ->
#|[set p : col_cubes | (p x == p y) && (p z == p t)&& (p u == p v )]|
= (n ^ 3)%N.
Proof.
move=> x y z t u v Uxv; rewrite -[n]card_ord .
pose ff (p : col_cubes) := (p x, p z, p u).
rewrite -(@card_in_image _ _ ff); first last.
move=> p1 p2 /[!inE]; rewrite -!andbA.
move=> /and3P[/eqP p1xy /eqP p1zt /eqP p1uv].
move=> /and3P[/eqP p2xy /eqP p2zt /eqP p2uv] [px pz] pu.
have eqp12: all (fun i => p1 i == p2 i) [:: x; y; z; t; u; v].
by rewrite /= -p1xy -p2xy -p1zt -p2zt -p1uv -p2uv px pz pu !eqxx.
apply/ffunP=> i; apply/eqP; apply: (allP eqp12).
by rewrite (subset_cardP _ (subset_predT _)) // (card_uniqP Uxv) card_ord.
have -> : forall n, (n ^ 3 = n * n * n)%N by move=> ?; rewrite -!mulnA.
rewrite -!card_prod; apply: eq_card => [] [[c d] e] /=; apply/imageP.
move: Uxv; rewrite (cat_uniq [::x; y; z; t]) => /and3P[Uxt + nuv].
move=> /= /[!orbF] /norP[] /[!inE].
rewrite orbA => /norP[/negPf nxyu /negPf nztu].
rewrite orbA => /norP[/negPf nxyv /negPf nztv].
move: Uxt; rewrite (cat_uniq [::x; y]) => /and3P[_].
rewrite /= !orbF !andbT => /norP[] /[!inE] /negPf nxyz /negPf nxyt _.
exists [ffun i => if i \in [:: x; y] then c
else if i \in [:: z; t] then d else e].
by rewrite !(inE, ffunE, eqxx,orbT)//= nxyz nxyt nxyu nztu nxyv nztv !eqxx.
by rewrite {}/ff !ffunE !inE /= !eqxx nxyz nxyu nztu.
Qed.
Lemma burnside_app_iso3 :
(cube_coloring_number24 * 24 =
n ^ 6 + 6 * n ^ 3 + 3 * n ^ 4 + 8 * (n ^ 2) + 6 * n ^ 3)%N.
Proof.
pose iso_list := [:: id3; s05; s14; s23; r05; r14; r23; r50; r41; r32;
r024; r042; r012; r021; r031; r013; r043; r034;
s1; s2; s3; s4; s5; s6].
rewrite (burnside_formula iso_list); last first.
- by move=> p; rewrite !inE /= !(eq_sym _ p).
- apply: map_uniq (fun p : {perm cube} => (p F0, p F1)) _ _.
have bsr : (fun p : {perm cube} => (p F0, p F1)) =1
(fun p => (nth F0 p F0, nth F0 p F1)) \o sop.
by move=> x; rewrite /= -2!sop_spec.
by rewrite (eq_map bsr) map_comp -(eqP Lcorrect); vm_compute.
rewrite !big_cons big_nil {1}card_Fid3 /= F_s05 F_s14 F_s23 F_r05 F_r14 F_r23
F_r50 F_r41 F_r32 F_r024 F_r042 F_r012 F_r021 F_r031 F_r013 F_r043 F_r034
F_s1 F_s2 F_s3 F_s4 F_s5 F_s6.
rewrite !card_n4 // !card_n3_3 // !card_n2_3 // !card_n3s //.
by rewrite [RHS]addn.[ACl 1 * 3 * 2 * 4 * 5] !addnA !addn0.
Qed.
End cube_colouring.
End colouring.
Corollary burnside_app_iso_3_3col: cube_coloring_number24 3 = 57.
Proof. by apply/eqP; rewrite -(@eqn_pmul2r 24) // burnside_app_iso3. Qed.
Corollary burnside_app_iso_2_4col: square_coloring_number8 4 = 55.
Proof. by apply/eqP; rewrite -(@eqn_pmul2r 8) // burnside_app_iso. Qed.
|
Pochhammer.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Algebra.Basic
import Mathlib.Algebra.CharP.Defs
import Mathlib.Algebra.Polynomial.Degree.Lemmas
import Mathlib.Algebra.Polynomial.Eval.Algebra
import Mathlib.Tactic.Abel
/-!
# The Pochhammer polynomials
We define and prove some basic relations about
`ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)`
which is also known as the rising factorial and about
`descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)`
which is also known as the falling factorial. Versions of this definition
that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and
`Nat.descFactorial`.
## Implementation
As with many other families of polynomials, even though the coefficients are always in `ℕ` or `ℤ` ,
we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`.
In an integral domain `S`, we show that `ascPochhammer S n` is zero iff
`n` is a sufficiently large non-positive integer.
## TODO
There is lots more in this direction:
* q-factorials, q-binomials, q-Pochhammer.
-/
universe u v
open Polynomial
section Semiring
variable (S : Type u) [Semiring S]
/-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`,
with coefficients in the semiring `S`.
-/
noncomputable def ascPochhammer : ℕ → S[X]
| 0 => 1
| n + 1 => X * (ascPochhammer n).comp (X + 1)
@[simp]
theorem ascPochhammer_zero : ascPochhammer S 0 = 1 :=
rfl
@[simp]
theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer]
theorem ascPochhammer_succ_left (n : ℕ) :
ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by
rw [ascPochhammer]
theorem monic_ascPochhammer (n : ℕ) [Nontrivial S] [NoZeroDivisors S] :
Monic <| ascPochhammer S n := by
induction' n with n hn
· simp
· have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1
rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul,
leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) ≠ 0), hn,
monic_X, one_mul, one_mul, this, one_pow]
section
variable {S} {T : Type v} [Semiring T]
@[simp]
theorem ascPochhammer_map (f : S →+* T) (n : ℕ) :
(ascPochhammer S n).map f = ascPochhammer T n := by
induction n with
| zero => simp
| succ n ih => simp [ih, ascPochhammer_succ_left, map_comp]
theorem ascPochhammer_eval₂ (f : S →+* T) (n : ℕ) (t : T) :
(ascPochhammer T n).eval t = (ascPochhammer S n).eval₂ f t := by
rw [← ascPochhammer_map f]
exact eval_map f t
theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : ℕ) (p : R[X]) [Algebra R S]
(x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x =
(ascPochhammer S n).eval (p.eval₂ (algebraMap R S) x) := by
rw [ascPochhammer_eval₂ (algebraMap R S), ← eval₂_comp', ← ascPochhammer_map (algebraMap R S),
← map_comp, eval_map]
end
@[simp, norm_cast]
theorem ascPochhammer_eval_cast (n k : ℕ) :
(((ascPochhammer ℕ n).eval k : ℕ) : S) = ((ascPochhammer S n).eval k : S) := by
rw [← ascPochhammer_map (algebraMap ℕ S), eval_map, ← eq_natCast (algebraMap ℕ S),
eval₂_at_natCast,Nat.cast_id]
theorem ascPochhammer_eval_zero {n : ℕ} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by
cases n
· simp
· simp [X_mul, ascPochhammer_succ_left]
theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp
@[simp]
theorem ascPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (ascPochhammer S n).eval 0 = 0 := by
simp [ascPochhammer_eval_zero, h]
theorem ascPochhammer_succ_right (n : ℕ) :
ascPochhammer S (n + 1) = ascPochhammer S n * (X + (n : S[X])) := by
suffices h : ascPochhammer ℕ (n + 1) = ascPochhammer ℕ n * (X + (n : ℕ[X])) by
apply_fun Polynomial.map (algebraMap ℕ S) at h
simpa only [ascPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X,
Polynomial.map_natCast] using h
induction n with
| zero => simp
| succ n ih =>
conv_lhs =>
rw [ascPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← ascPochhammer_succ_left, add_comp,
X_comp, natCast_comp, add_assoc, add_comm (1 : ℕ[X]), ← Nat.cast_succ]
theorem ascPochhammer_succ_eval {S : Type*} [Semiring S] (n : ℕ) (k : S) :
(ascPochhammer S (n + 1)).eval k = (ascPochhammer S n).eval k * (k + n) := by
rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast,
eval_C_mul, Nat.cast_comm, ← mul_add]
theorem ascPochhammer_succ_comp_X_add_one (n : ℕ) :
(ascPochhammer S (n + 1)).comp (X + 1) =
ascPochhammer S (n + 1) + (n + 1) • (ascPochhammer S n).comp (X + 1) := by
suffices (ascPochhammer ℕ (n + 1)).comp (X + 1) =
ascPochhammer ℕ (n + 1) + (n + 1) * (ascPochhammer ℕ n).comp (X + 1)
by simpa [map_comp] using congr_arg (Polynomial.map (Nat.castRingHom S)) this
nth_rw 2 [ascPochhammer_succ_left]
rw [← add_mul, ascPochhammer_succ_right ℕ n, mul_comp, mul_comm, add_comp, X_comp, natCast_comp,
add_comm, ← add_assoc]
ring
theorem ascPochhammer_mul (n m : ℕ) :
ascPochhammer S n * (ascPochhammer S m).comp (X + (n : S[X])) = ascPochhammer S (n + m) := by
induction' m with m ih
· simp
· rw [ascPochhammer_succ_right, Polynomial.mul_X_add_natCast_comp, ← mul_assoc, ih,
← add_assoc, ascPochhammer_succ_right, Nat.cast_add, add_assoc]
theorem ascPochhammer_nat_eq_ascFactorial (n : ℕ) :
∀ k, (ascPochhammer ℕ k).eval n = n.ascFactorial k
| 0 => by rw [ascPochhammer_zero, eval_one, Nat.ascFactorial_zero]
| t + 1 => by
rw [ascPochhammer_succ_right, eval_mul, ascPochhammer_nat_eq_ascFactorial n t, eval_add, eval_X,
eval_natCast, Nat.cast_id, Nat.ascFactorial_succ, mul_comm]
theorem ascPochhammer_nat_eq_natCast_ascFactorial (S : Type*) [Semiring S] (n k : ℕ) :
(ascPochhammer S k).eval (n : S) = n.ascFactorial k := by
norm_cast
rw [ascPochhammer_nat_eq_ascFactorial]
theorem ascPochhammer_nat_eq_descFactorial (a b : ℕ) :
(ascPochhammer ℕ b).eval a = (a + b - 1).descFactorial b := by
rw [ascPochhammer_nat_eq_ascFactorial, Nat.add_descFactorial_eq_ascFactorial']
theorem ascPochhammer_nat_eq_natCast_descFactorial (S : Type*) [Semiring S] (a b : ℕ) :
(ascPochhammer S b).eval (a : S) = (a + b - 1).descFactorial b := by
norm_cast
rw [ascPochhammer_nat_eq_descFactorial]
@[simp]
theorem ascPochhammer_natDegree (n : ℕ) [NoZeroDivisors S] [Nontrivial S] :
(ascPochhammer S n).natDegree = n := by
induction' n with n hn
· simp
· have : natDegree (X + (n : S[X])) = 1 := natDegree_X_add_C (n : S)
rw [ascPochhammer_succ_right,
natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this]
cases n
· simp
· refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _
end Semiring
section StrictOrderedSemiring
variable {S : Type*} [Semiring S] [PartialOrder S] [IsStrictOrderedRing S]
theorem ascPochhammer_pos (n : ℕ) (s : S) (h : 0 < s) : 0 < (ascPochhammer S n).eval s := by
induction n with
| zero =>
simp only [ascPochhammer_zero, eval_one]
exact zero_lt_one
| succ n ih =>
rw [ascPochhammer_succ_right, mul_add, eval_add, ← Nat.cast_comm, eval_natCast_mul, eval_mul_X,
Nat.cast_comm, ← mul_add]
exact mul_pos ih (lt_of_lt_of_le h (le_add_of_nonneg_right (Nat.cast_nonneg n)))
end StrictOrderedSemiring
section Factorial
open Nat
variable (S : Type*) [Semiring S] (r n : ℕ)
@[simp]
theorem ascPochhammer_eval_one (S : Type*) [Semiring S] (n : ℕ) :
(ascPochhammer S n).eval (1 : S) = (n ! : S) := by
rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.one_ascFactorial]
theorem factorial_mul_ascPochhammer (S : Type*) [Semiring S] (r n : ℕ) :
(r ! : S) * (ascPochhammer S n).eval (r + 1 : S) = (r + n)! := by
rw_mod_cast [ascPochhammer_nat_eq_ascFactorial, Nat.factorial_mul_ascFactorial]
theorem ascPochhammer_nat_eval_succ (r : ℕ) :
∀ n : ℕ, n * (ascPochhammer ℕ r).eval (n + 1) = (n + r) * (ascPochhammer ℕ r).eval n
| 0 => by
by_cases h : r = 0
· simp only [h, zero_mul, zero_add]
· simp only [ascPochhammer_eval_zero, zero_mul, if_neg h, mul_zero]
| k + 1 => by simp only [ascPochhammer_nat_eq_ascFactorial, Nat.succ_ascFactorial, add_right_comm]
theorem ascPochhammer_eval_succ (r n : ℕ) :
(n : S) * (ascPochhammer S r).eval (n + 1 : S) =
(n + r) * (ascPochhammer S r).eval (n : S) :=
mod_cast congr_arg Nat.cast (ascPochhammer_nat_eval_succ r n)
end Factorial
section Ring
variable (R : Type u) [Ring R]
/-- `descPochhammer R n` is the polynomial `X * (X - 1) * ... * (X - n + 1)`,
with coefficients in the ring `R`.
-/
noncomputable def descPochhammer : ℕ → R[X]
| 0 => 1
| n + 1 => X * (descPochhammer n).comp (X - 1)
@[simp]
theorem descPochhammer_zero : descPochhammer R 0 = 1 :=
rfl
@[simp]
theorem descPochhammer_one : descPochhammer R 1 = X := by simp [descPochhammer]
theorem descPochhammer_succ_left (n : ℕ) :
descPochhammer R (n + 1) = X * (descPochhammer R n).comp (X - 1) := by
rw [descPochhammer]
theorem monic_descPochhammer (n : ℕ) [Nontrivial R] [NoZeroDivisors R] :
Monic <| descPochhammer R n := by
induction' n with n hn
· simp
· have h : leadingCoeff (X - 1 : R[X]) = 1 := leadingCoeff_X_sub_C 1
have : natDegree (X - (1 : R[X])) ≠ 0 := ne_zero_of_eq_one <| natDegree_X_sub_C (1 : R)
rw [descPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp this, hn, monic_X,
one_mul, one_mul, h, one_pow]
section
variable {R} {T : Type v} [Ring T]
@[simp]
theorem descPochhammer_map (f : R →+* T) (n : ℕ) :
(descPochhammer R n).map f = descPochhammer T n := by
induction n with
| zero => simp
| succ n ih => simp [ih, descPochhammer_succ_left, map_comp]
end
@[simp, norm_cast]
theorem descPochhammer_eval_cast (n : ℕ) (k : ℤ) :
(((descPochhammer ℤ n).eval k : ℤ) : R) = ((descPochhammer R n).eval k : R) := by
rw [← descPochhammer_map (algebraMap ℤ R), eval_map, ← eq_intCast (algebraMap ℤ R)]
simp only [algebraMap_int_eq, eq_intCast, eval₂_at_intCast, Int.cast_id]
theorem descPochhammer_eval_zero {n : ℕ} :
(descPochhammer R n).eval 0 = if n = 0 then 1 else 0 := by
cases n
· simp
· simp [X_mul, descPochhammer_succ_left]
theorem descPochhammer_zero_eval_zero : (descPochhammer R 0).eval 0 = 1 := by simp
@[simp]
theorem descPochhammer_ne_zero_eval_zero {n : ℕ} (h : n ≠ 0) : (descPochhammer R n).eval 0 = 0 := by
simp [descPochhammer_eval_zero, h]
theorem descPochhammer_succ_right (n : ℕ) :
descPochhammer R (n + 1) = descPochhammer R n * (X - (n : R[X])) := by
suffices h : descPochhammer ℤ (n + 1) = descPochhammer ℤ n * (X - (n : ℤ[X])) by
apply_fun Polynomial.map (algebraMap ℤ R) at h
simpa [descPochhammer_map, Polynomial.map_mul, Polynomial.map_add, map_X,
Polynomial.map_intCast] using h
induction n with
| zero => simp [descPochhammer]
| succ n ih =>
conv_lhs =>
rw [descPochhammer_succ_left, ih, mul_comp, ← mul_assoc, ← descPochhammer_succ_left, sub_comp,
X_comp, natCast_comp]
rw [Nat.cast_add, Nat.cast_one, sub_add_eq_sub_sub_swap]
@[simp]
theorem descPochhammer_natDegree (n : ℕ) [NoZeroDivisors R] [Nontrivial R] :
(descPochhammer R n).natDegree = n := by
induction' n with n hn
· simp
· have : natDegree (X - (n : R[X])) = 1 := natDegree_X_sub_C (n : R)
rw [descPochhammer_succ_right,
natDegree_mul _ (ne_zero_of_natDegree_gt <| this.symm ▸ Nat.zero_lt_one), hn, this]
cases n
· simp
· refine ne_zero_of_natDegree_gt <| hn.symm ▸ Nat.add_one_pos _
theorem descPochhammer_succ_eval {S : Type*} [Ring S] (n : ℕ) (k : S) :
(descPochhammer S (n + 1)).eval k = (descPochhammer S n).eval k * (k - n) := by
rw [descPochhammer_succ_right, mul_sub, eval_sub, eval_mul_X, ← Nat.cast_comm, ← C_eq_natCast,
eval_C_mul, Nat.cast_comm, ← mul_sub]
theorem descPochhammer_succ_comp_X_sub_one (n : ℕ) :
(descPochhammer R (n + 1)).comp (X - 1) =
descPochhammer R (n + 1) - (n + (1 : R[X])) • (descPochhammer R n).comp (X - 1) := by
suffices (descPochhammer ℤ (n + 1)).comp (X - 1) =
descPochhammer ℤ (n + 1) - (n + 1) * (descPochhammer ℤ n).comp (X - 1)
by simpa [map_comp] using congr_arg (Polynomial.map (Int.castRingHom R)) this
nth_rw 2 [descPochhammer_succ_left]
rw [← sub_mul, descPochhammer_succ_right ℤ n, mul_comp, mul_comm, sub_comp, X_comp, natCast_comp]
ring
theorem descPochhammer_eq_ascPochhammer (n : ℕ) :
descPochhammer ℤ n = (ascPochhammer ℤ n).comp ((X : ℤ[X]) - n + 1) := by
induction n with
| zero => rw [descPochhammer_zero, ascPochhammer_zero, one_comp]
| succ n ih =>
rw [Nat.cast_succ, sub_add, add_sub_cancel_right, descPochhammer_succ_right,
ascPochhammer_succ_left, ih, X_mul, mul_X_comp, comp_assoc, add_comp, X_comp, one_comp]
theorem descPochhammer_eval_eq_ascPochhammer (r : R) (n : ℕ) :
(descPochhammer R n).eval r = (ascPochhammer R n).eval (r - n + 1) := by
induction n with
| zero => rw [descPochhammer_zero, eval_one, ascPochhammer_zero, eval_one]
| succ n ih =>
rw [Nat.cast_succ, sub_add, add_sub_cancel_right, descPochhammer_succ_eval, ih,
ascPochhammer_succ_left, X_mul, eval_mul_X, show (X + 1 : R[X]) =
(X + 1 : ℕ[X]).map (algebraMap ℕ R) by simp only [Polynomial.map_add, map_X,
Polynomial.map_one], ascPochhammer_eval_comp, eval₂_add, eval₂_X, eval₂_one]
theorem descPochhammer_mul (n m : ℕ) :
descPochhammer R n * (descPochhammer R m).comp (X - (n : R[X])) = descPochhammer R (n + m) := by
induction' m with m ih
· simp
· rw [descPochhammer_succ_right, Polynomial.mul_X_sub_intCast_comp, ← mul_assoc, ih,
← add_assoc, descPochhammer_succ_right, Nat.cast_add, sub_add_eq_sub_sub]
theorem ascPochhammer_eval_neg_eq_descPochhammer (r : R) : ∀ (k : ℕ),
(ascPochhammer R k).eval (-r) = (-1)^k * (descPochhammer R k).eval r
| 0 => by
rw [ascPochhammer_zero, descPochhammer_zero]
simp only [eval_one, pow_zero, mul_one]
| (k+1) => by
rw [ascPochhammer_succ_right, mul_add, eval_add, eval_mul_X, ← Nat.cast_comm, eval_natCast_mul,
Nat.cast_comm, ← mul_add, ascPochhammer_eval_neg_eq_descPochhammer r k, mul_assoc,
descPochhammer_succ_right, mul_sub, eval_sub, eval_mul_X, ← Nat.cast_comm, eval_natCast_mul,
pow_add, pow_one, mul_assoc ((-1)^k) (-1), mul_sub, neg_one_mul, neg_mul_eq_mul_neg,
Nat.cast_comm, sub_eq_add_neg, neg_one_mul, neg_neg, ← mul_add]
theorem descPochhammer_eval_eq_descFactorial (n k : ℕ) :
(descPochhammer R k).eval (n : R) = n.descFactorial k := by
induction k with
| zero => rw [descPochhammer_zero, eval_one, Nat.descFactorial_zero, Nat.cast_one]
| succ k ih =>
rw [descPochhammer_succ_right, Nat.descFactorial_succ, mul_sub, eval_sub, eval_mul_X,
← Nat.cast_comm k, eval_natCast_mul, ← Nat.cast_comm n, ← sub_mul, ih]
by_cases h : n < k
· rw [Nat.descFactorial_eq_zero_iff_lt.mpr h, Nat.cast_zero, mul_zero, mul_zero, Nat.cast_zero]
· rw [Nat.cast_mul, Nat.cast_sub <| not_lt.mp h]
theorem descPochhammer_int_eq_ascFactorial (a b : ℕ) :
(descPochhammer ℤ b).eval (a + b : ℤ) = (a + 1).ascFactorial b := by
rw [← Nat.cast_add, descPochhammer_eval_eq_descFactorial ℤ (a + b) b,
Nat.add_descFactorial_eq_ascFactorial]
variable {R}
/-- The Pochhammer polynomial of degree `n` has roots at `0`, `-1`, ..., `-(n - 1)`. -/
theorem ascPochhammer_eval_neg_coe_nat_of_lt {n k : ℕ} (h : k < n) :
(ascPochhammer R n).eval (-(k : R)) = 0 := by
induction n with
| zero => contradiction
| succ n ih =>
rw [ascPochhammer_succ_eval]
rcases lt_trichotomy k n with hkn | rfl | hkn
· simp [ih hkn]
· simp
· omega
/-- Over an integral domain, the Pochhammer polynomial of degree `n` has roots *only* at
`0`, `-1`, ..., `-(n - 1)`. -/
@[simp]
theorem ascPochhammer_eval_eq_zero_iff [IsDomain R]
(n : ℕ) (r : R) : (ascPochhammer R n).eval r = 0 ↔ ∃ k < n, k = -r := by
refine ⟨fun zero' ↦ ?_, fun hrn ↦ ?_⟩
· induction n with
| zero => simp only [ascPochhammer_zero, Polynomial.eval_one, one_ne_zero] at zero'
| succ n ih =>
rw [ascPochhammer_succ_eval, mul_eq_zero] at zero'
cases zero' with
| inl h =>
obtain ⟨rn, hrn, rrn⟩ := ih h
exact ⟨rn, by omega, rrn⟩
| inr h =>
exact ⟨n, lt_add_one n, eq_neg_of_add_eq_zero_right h⟩
· obtain ⟨rn, hrn, rnn⟩ := hrn
convert ascPochhammer_eval_neg_coe_nat_of_lt hrn
simp [rnn]
/-- `descPochhammer R n` is `0` for `0, 1, …, n-1`. -/
theorem descPochhammer_eval_coe_nat_of_lt {k n : ℕ} (h : k < n) :
(descPochhammer R n).eval (k : R) = 0 := by
rw [descPochhammer_eval_eq_ascPochhammer, sub_add_eq_add_sub,
← Nat.cast_add_one, ← neg_sub, ← Nat.cast_sub h]
exact ascPochhammer_eval_neg_coe_nat_of_lt (Nat.sub_lt_of_pos_le k.succ_pos h)
lemma descPochhammer_eval_eq_prod_range {R : Type*} [CommRing R] (n : ℕ) (r : R) :
(descPochhammer R n).eval r = ∏ j ∈ Finset.range n, (r - j) := by
induction n with
| zero => simp
| succ n ih => simp [descPochhammer_succ_right, ih, ← Finset.prod_range_succ]
end Ring
section StrictOrderedRing
variable {S : Type*} [Ring S] [PartialOrder S] [IsStrictOrderedRing S]
/-- `descPochhammer S n` is positive on `(n-1, ∞)`. -/
theorem descPochhammer_pos {n : ℕ} {s : S} (h : n - 1 < s) :
0 < (descPochhammer S n).eval s := by
rw [← sub_pos, ← sub_add] at h
rw [descPochhammer_eval_eq_ascPochhammer]
exact ascPochhammer_pos n (s - n + 1) h
/-- `descPochhammer S n` is nonnegative on `[n-1, ∞)`. -/
theorem descPochhammer_nonneg {n : ℕ} {s : S} (h : n - 1 ≤ s) :
0 ≤ (descPochhammer S n).eval s := by
rcases eq_or_lt_of_le h with heq | h
· rw [← heq, descPochhammer_eval_eq_ascPochhammer,
sub_sub_cancel_left, neg_add_cancel, ascPochhammer_eval_zero]
positivity
· exact (descPochhammer_pos h).le
/-- `descPochhammer S n` is at least `(s-n+1)^n` on `[n-1, ∞)`. -/
theorem pow_le_descPochhammer_eval {n : ℕ} {s : S} (h : n - 1 ≤ s) :
(s - n + 1)^n ≤ (descPochhammer S n).eval s := by
induction n with
| zero => simp
| succ n ih =>
rw [Nat.cast_add_one, add_sub_cancel_right, ← sub_nonneg] at h
have hsub1 : n - 1 ≤ s := (sub_le_self (n : S) zero_le_one).trans (le_of_sub_nonneg h)
rw [pow_succ, descPochhammer_succ_eval, Nat.cast_add_one, sub_add, add_sub_cancel_right]
apply mul_le_mul _ le_rfl h (descPochhammer_nonneg hsub1)
exact (ih hsub1).trans' <| pow_le_pow_left₀ h (le_add_of_nonneg_right zero_le_one) n
/-- `descPochhammer S n` is monotone on `[n-1, ∞)`. -/
theorem monotoneOn_descPochhammer_eval (n : ℕ) :
MonotoneOn (descPochhammer S n).eval (Set.Ici (n - 1 : S)) := by
induction n with
| zero => simp [monotoneOn_const]
| succ n ih =>
intro a ha b hb hab
rw [Set.mem_Ici, Nat.cast_add_one, add_sub_cancel_right] at ha hb
have ha_sub1 : n - 1 ≤ a := (sub_le_self (n : S) zero_le_one).trans ha
have hb_sub1 : n - 1 ≤ b := (sub_le_self (n : S) zero_le_one).trans hb
simp_rw [descPochhammer_succ_eval]
exact mul_le_mul (ih ha_sub1 hb_sub1 hab) (sub_le_sub_right hab (n : S))
(sub_nonneg_of_le ha) (descPochhammer_nonneg hb_sub1)
end StrictOrderedRing
|
Locally.lean
|
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.RingTheory.LocalProperties.Basic
import Mathlib.RingTheory.Localization.BaseChange
import Mathlib.RingTheory.Localization.Away.Lemmas
/-!
# Target local closure of ring homomorphism properties
If `P` is a property of ring homomorphisms, we call `Locally P` the closure of `P` with
respect to standard open coverings on the (algebraic) target (i.e. geometric source). Hence
for `f : R →+* S`, the property `Locally P` holds if it holds locally on `S`, i.e. if there exists
a subset `{ t }` of `S` generating the unit ideal, such that `P` holds for all compositions
`R →+* Sₜ`.
Assuming without further mention that `P` is stable under composition with isomorphisms,
`Locally P` is local on the target by construction, i.e. it satisfies
`RingHom.OfLocalizationSpanTarget`. If `P` itself is local on the target,
`Locally P` coincides with `P`.
The `Locally` construction preserves various properties of `P`, e.g. if `P` is stable under
composition, base change, etc., so is `Locally P`.
## Main results
- `RingHom.locally_ofLocalizationSpanTarget`: `Locally P` is local on the target.
- `RingHom.locally_holdsForLocalizationAway`: `Locally P` holds for localization away maps
if `P` does.
- `RingHom.locally_isStableUnderBaseChange`: `Locally P` is stable under base change if `P` is.
- `RingHom.locally_stableUnderComposition`: `Locally P` is stable under composition
if `P` is and `P` is preserved under localizations.
- `RingHom.locally_StableUnderCompositionWithLocalizationAwayTarget` and
`RingHom.locally_StableUnderCompositionWithLocalizationAwaySource`: `Locally P` is stable under
composition with localization away maps if `P` is.
- `RingHom.locally_localizationPreserves`: If `P` is preserved by localizations, then so is
`Locally P`.
-/
universe u v
open TensorProduct
namespace RingHom
variable (P : ∀ {R S : Type u} [CommRing R] [CommRing S] (_ : R →+* S), Prop)
/--
For a property of ring homomorphisms `P`, `Locally P` holds for `f : R →+* S` if
it holds locally on `S`, i.e. if there exists a subset `{ t }` of `S` generating
the unit ideal, such that `P` holds for all compositions `R →+* Sₜ`.
We may require `s` to be finite here, for the equivalence, see `locally_iff_finite`.
-/
def Locally {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) : Prop :=
∃ (s : Set S) (_ : Ideal.span s = ⊤),
∀ t ∈ s, P ((algebraMap S (Localization.Away t)).comp f)
variable {R S : Type u} [CommRing R] [CommRing S]
lemma locally_iff_finite (f : R →+* S) :
Locally P f ↔ ∃ (s : Finset S) (_ : Ideal.span (s : Set S) = ⊤),
∀ t ∈ s, P ((algebraMap S (Localization.Away t)).comp f) := by
constructor
· intro ⟨s, hsone, hs⟩
obtain ⟨s', h₁, h₂⟩ := (Ideal.span_eq_top_iff_finite s).mp hsone
exact ⟨s', h₂, fun t ht ↦ hs t (h₁ ht)⟩
· intro ⟨s, hsone, hs⟩
use s, hsone, hs
variable {P}
/-- If `P` respects isomorphisms, to check `P` holds locally for `f : R →+* S`, it suffices
to check `P` holds on a standard open cover. -/
lemma locally_of_exists (hP : RespectsIso P) (f : R →+* S) {ι : Type*} (s : ι → S)
(hsone : Ideal.span (Set.range s) = ⊤)
(Sₜ : ι → Type u) [∀ i, CommRing (Sₜ i)] [∀ i, Algebra S (Sₜ i)]
[∀ i, IsLocalization.Away (s i) (Sₜ i)] (hf : ∀ i, P ((algebraMap S (Sₜ i)).comp f)) :
Locally P f := by
use Set.range s, hsone
rintro - ⟨i, rfl⟩
let e : Localization.Away (s i) ≃+* Sₜ i :=
(IsLocalization.algEquiv (Submonoid.powers (s i)) _ _).toRingEquiv
have : algebraMap S (Localization.Away (s i)) = e.symm.toRingHom.comp (algebraMap S (Sₜ i)) :=
RingHom.ext (fun x ↦ (AlgEquiv.commutes (IsLocalization.algEquiv _ _ _).symm _).symm)
rw [this, RingHom.comp_assoc]
exact hP.left _ _ (hf i)
/-- Equivalence variant of `locally_of_exists`. This is sometimes easier to use, if the
`IsLocalization.Away` instance can't be automatically inferred. -/
lemma locally_iff_exists (hP : RespectsIso P) (f : R →+* S) :
Locally P f ↔ ∃ (ι : Type u) (s : ι → S) (_ : Ideal.span (Set.range s) = ⊤) (Sₜ : ι → Type u)
(_ : (i : ι) → CommRing (Sₜ i)) (_ : (i : ι) → Algebra S (Sₜ i))
(_ : (i : ι) → IsLocalization.Away (s i : S) (Sₜ i)),
∀ i, P ((algebraMap S (Sₜ i)).comp f) :=
⟨fun ⟨s, hsone, hs⟩ ↦ ⟨s, fun t : s ↦ (t : S), by simpa, fun t ↦ Localization.Away (t : S),
inferInstance, inferInstance, inferInstance, fun t ↦ hs t.val t.property⟩,
fun ⟨ι, s, hsone, Sₜ, _, _, hislocal, hs⟩ ↦ locally_of_exists hP f s hsone Sₜ hs⟩
/-- In the definition of `Locally` we may replace `Localization.Away` with an arbitrary
algebra satisfying `IsLocalization.Away`. -/
lemma locally_iff_isLocalization (hP : RespectsIso P) (f : R →+* S) :
Locally P f ↔ ∃ (s : Finset S) (_ : Ideal.span (s : Set S) = ⊤),
∀ t ∈ s, ∀ (Sₜ : Type u) [CommRing Sₜ] [Algebra S Sₜ] [IsLocalization.Away t Sₜ],
P ((algebraMap S Sₜ).comp f) := by
rw [locally_iff_finite P f]
refine ⟨fun ⟨s, hsone, hs⟩ ↦ ⟨s, hsone, fun t ht Sₜ _ _ _ ↦ ?_⟩, fun ⟨s, hsone, hs⟩ ↦ ?_⟩
· let e : Localization.Away t ≃+* Sₜ :=
(IsLocalization.algEquiv (Submonoid.powers t) _ _).toRingEquiv
have : algebraMap S Sₜ = e.toRingHom.comp (algebraMap S (Localization.Away t)) :=
RingHom.ext (fun x ↦ (AlgEquiv.commutes (IsLocalization.algEquiv _ _ _) _).symm)
rw [this, RingHom.comp_assoc]
exact hP.left _ _ (hs t ht)
· exact ⟨s, hsone, fun t ht ↦ hs t ht _⟩
/-- If `f` satisfies `P`, then in particular it satisfies `Locally P`. -/
lemma locally_of (hP : RespectsIso P) (f : R →+* S) (hf : P f) : Locally P f := by
use {1}
let e : S ≃+* Localization.Away (1 : S) :=
(IsLocalization.atUnits S (Submonoid.powers 1) (by simp)).toRingEquiv
simp only [Set.mem_singleton_iff, forall_eq, Ideal.span_singleton_one, exists_const]
exact hP.left f e hf
lemma locally_of_locally {Q : ∀ {R S : Type u} [CommRing R] [CommRing S], (R →+* S) → Prop}
(hPQ : ∀ {R S : Type u} [CommRing R] [CommRing S] {f : R →+* S}, P f → Q f)
{R S : Type u} [CommRing R] [CommRing S] {f : R →+* S} (hf : Locally P f) : Locally Q f := by
obtain ⟨s, hsone, hs⟩ := hf
exact ⟨s, hsone, fun t ht ↦ hPQ (hs t ht)⟩
/-- If `P` is local on the target, then `Locally P` coincides with `P`. -/
lemma locally_iff_of_localizationSpanTarget (hPi : RespectsIso P)
(hPs : OfLocalizationSpanTarget P) {R S : Type u} [CommRing R] [CommRing S] (f : R →+* S) :
Locally P f ↔ P f :=
⟨fun ⟨s, hsone, hs⟩ ↦ hPs f s hsone (fun a ↦ hs a.val a.property), locally_of hPi f⟩
section OfLocalizationSpanTarget
/-- `Locally P` is local on the target. -/
lemma locally_ofLocalizationSpanTarget (hP : RespectsIso P) :
OfLocalizationSpanTarget (Locally P) := by
intro R S _ _ f s hsone hs
choose t htone ht using hs
rw [locally_iff_exists hP]
refine ⟨(a : s) × t a, IsLocalization.Away.mulNumerator s t,
IsLocalization.Away.span_range_mulNumerator_eq_top hsone htone,
fun ⟨a, b⟩ ↦ Localization.Away b.val, inferInstance, inferInstance, fun ⟨a, b⟩ ↦ ?_, ?_⟩
· haveI : IsLocalization.Away ((algebraMap S (Localization.Away a.val))
(IsLocalization.Away.sec a.val b.val).1) (Localization.Away b.val) := by
apply IsLocalization.Away.of_associated (r := b.val)
rw [← IsLocalization.Away.sec_spec]
apply associated_mul_unit_right
rw [map_pow _ _]
exact IsUnit.pow _ (IsLocalization.Away.algebraMap_isUnit _)
apply IsLocalization.Away.mul' (Localization.Away a.val) (Localization.Away b.val)
· intro ⟨a, b⟩
rw [IsScalarTower.algebraMap_eq S (Localization.Away a.val) (Localization.Away b.val)]
apply ht _ _ b.property
end OfLocalizationSpanTarget
section Stability
/-- If `P` respects isomorphism, so does `Locally P`. -/
lemma locally_respectsIso (hPi : RespectsIso P) : RespectsIso (Locally P) where
left {R S T} _ _ _ f e := fun ⟨s, hsone, hs⟩ ↦ by
refine ⟨e '' s, ?_, ?_⟩
· rw [← Ideal.map_span, hsone, Ideal.map_top]
· rintro - ⟨a, ha, rfl⟩
let e' : Localization.Away a ≃+* Localization.Away (e a) :=
IsLocalization.ringEquivOfRingEquiv _ _ e (Submonoid.map_powers e a)
have : (algebraMap T (Localization.Away (e a))).comp e.toRingHom =
e'.toRingHom.comp (algebraMap S (Localization.Away a)) := by
ext x
simp [e']
rw [← RingHom.comp_assoc, this, RingHom.comp_assoc]
apply hPi.left
exact hs a ha
right {R S T} _ _ _ f e := fun ⟨s, hsone, hs⟩ ↦
⟨s, hsone, fun a ha ↦ (RingHom.comp_assoc _ _ _).symm ▸ hPi.right _ _ (hs a ha)⟩
/-- If `P` holds for localization away maps, then so does `Locally P`. -/
lemma locally_holdsForLocalizationAway (hPa : HoldsForLocalizationAway P) :
HoldsForLocalizationAway (Locally P) := by
introv R _
use {1}
simp only [Set.mem_singleton_iff, forall_eq, Ideal.span_singleton_one, exists_const]
let e : S ≃ₐ[R] (Localization.Away (1 : S)) :=
(IsLocalization.atUnits S (Submonoid.powers 1) (by simp)).restrictScalars R
haveI : IsLocalization.Away r (Localization.Away (1 : S)) :=
IsLocalization.isLocalization_of_algEquiv (Submonoid.powers r) e
rw [← IsScalarTower.algebraMap_eq]
apply hPa _ r
/-- If `P` preserves localizations, then `Locally P` is stable under composition if `P` is. -/
lemma locally_stableUnderComposition (hPi : RespectsIso P) (hPl : LocalizationPreserves P)
(hPc : StableUnderComposition P) :
StableUnderComposition (Locally P) := by
classical
intro R S T _ _ _ f g hf hg
rw [locally_iff_finite] at hf hg
obtain ⟨sf, hsfone, hsf⟩ := hf
obtain ⟨sg, hsgone, hsg⟩ := hg
rw [locally_iff_exists hPi]
refine ⟨sf × sg, fun (a, b) ↦ g a * b, ?_,
fun (a, b) ↦ Localization.Away ((algebraMap T (Localization.Away b.val)) (g a.val)),
inferInstance, inferInstance, inferInstance, ?_⟩
· rw [eq_top_iff, ← hsgone, Ideal.span_le]
intro t ht
have : 1 ∈ Ideal.span (Set.range <| fun a : sf ↦ a.val) := by simp [hsfone]
simp only [Ideal.mem_span_range_iff_exists_fun, SetLike.mem_coe] at this ⊢
obtain ⟨cf, hcf⟩ := this
let cg : sg → T := Pi.single ⟨t, ht⟩ 1
use fun (a, b) ↦ g (cf a) * cg b
simp [cg, Pi.single_apply, Fintype.sum_prod_type, ← mul_assoc, ← Finset.sum_mul, ← map_mul,
← map_sum, hcf] at hcf ⊢
· intro ⟨a, b⟩
let g' := (algebraMap T (Localization.Away b.val)).comp g
let a' := (algebraMap T (Localization.Away b.val)) (g a.val)
have : (algebraMap T <| Localization.Away a').comp (g.comp f) =
(Localization.awayMap g' a.val).comp ((algebraMap S (Localization.Away a.val)).comp f) := by
ext x
simp only [coe_comp, Function.comp_apply, a']
change _ = Localization.awayMap g' a.val (algebraMap S _ (f x))
simp only [Localization.awayMap, IsLocalization.Away.map, IsLocalization.map_eq]
rfl
simp only [this, a']
apply hPc _ _ (hsf a.val a.property)
apply @hPl _ _ _ _ g' _ _ _ _ _ _ _ _ ?_ (hsg b.val b.property)
exact IsLocalization.Away.instMapRingHomPowersOfCoe (Localization.Away (g' a.val)) a.val
/-- If `P` is stable under composition with localization away maps on the right,
then so is `Locally P`. -/
lemma locally_StableUnderCompositionWithLocalizationAwayTarget
(hP0 : RespectsIso P)
(hPa : StableUnderCompositionWithLocalizationAwayTarget P) :
StableUnderCompositionWithLocalizationAwayTarget (Locally P) := by
intro R S T _ _ _ _ t _ f hf
simp only [locally_iff_isLocalization hP0 f] at hf
obtain ⟨s, hsone, hs⟩ := hf
refine ⟨algebraMap S T '' s, ?_, ?_⟩
· rw [← Ideal.map_span, hsone, Ideal.map_top]
· rintro - ⟨a, ha, rfl⟩
letI : Algebra (Localization.Away a) (Localization.Away (algebraMap S T a)) :=
(IsLocalization.Away.map _ _ (algebraMap S T) a).toAlgebra
have : (algebraMap (Localization.Away a) (Localization.Away (algebraMap S T a))).comp
(algebraMap S (Localization.Away a)) =
(algebraMap T (Localization.Away (algebraMap S T a))).comp (algebraMap S T) := by
simp [algebraMap_toAlgebra, IsLocalization.Away.map]
rw [← comp_assoc, ← this, comp_assoc]
haveI : IsScalarTower S (Localization.Away a) (Localization.Away ((algebraMap S T) a)) := by
apply IsScalarTower.of_algebraMap_eq
intro x
simp [algebraMap_toAlgebra, IsLocalization.Away.map, ← IsScalarTower.algebraMap_apply]
haveI : IsLocalization.Away (algebraMap S (Localization.Away a) t)
(Localization.Away (algebraMap S T a)) :=
IsLocalization.Away.commutes _ T ((Localization.Away (algebraMap S T a))) a t
apply hPa _ (algebraMap S (Localization.Away a) t)
apply hs a ha
/-- If `P` is stable under composition with localization away maps on the left,
then so is `Locally P`. -/
lemma locally_StableUnderCompositionWithLocalizationAwaySource
(hPa : StableUnderCompositionWithLocalizationAwaySource P) :
StableUnderCompositionWithLocalizationAwaySource (Locally P) := by
intro R S T _ _ _ _ r _ f ⟨s, hsone, hs⟩
refine ⟨s, hsone, fun t ht ↦ ?_⟩
rw [← comp_assoc]
exact hPa _ r _ (hs t ht)
attribute [local instance] Algebra.TensorProduct.rightAlgebra in
/-- If `P` is stable under base change, then so is `Locally P`. -/
lemma locally_isStableUnderBaseChange (hPi : RespectsIso P) (hPb : IsStableUnderBaseChange P) :
IsStableUnderBaseChange (Locally P) := by
apply IsStableUnderBaseChange.mk (locally_respectsIso hPi)
introv hf
obtain ⟨s, hsone, hs⟩ := hf
rw [locally_iff_exists hPi]
letI (a : s) : Algebra (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) :=
(Algebra.TensorProduct.map (AlgHom.id R S) (IsScalarTower.toAlgHom R _ _)).toRingHom.toAlgebra
letI (a : s) : Algebra T (S ⊗[R] Localization.Away a.val) :=
((algebraMap _ (S ⊗[R] Localization.Away a.val)).comp (algebraMap T (S ⊗[R] T))).toAlgebra
haveI (a : s) : IsScalarTower T (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) :=
IsScalarTower.of_algebraMap_eq' rfl
haveI (a : s) : IsScalarTower T (Localization.Away a.val) (S ⊗[R] Localization.Away a.val) :=
IsScalarTower.of_algebraMap_eq' rfl
haveI (a : s) : IsScalarTower S (S ⊗[R] T) (S ⊗[R] Localization.Away a.val) :=
IsScalarTower.of_algebraMap_eq <| by
intro x
simp [RingHom.algebraMap_toAlgebra]
haveI (a : s) : Algebra.IsPushout T (Localization.Away a.val) (S ⊗[R] T)
(S ⊗[R] Localization.Away a.val) := by
rw [← Algebra.IsPushout.comp_iff R _ S]
infer_instance
refine ⟨s, fun a ↦ Algebra.TensorProduct.includeRight a.val, ?_,
fun a ↦ (S ⊗[R] Localization.Away a.val), inferInstance, inferInstance, ?_, ?_⟩
· rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top]
· intro a
convert_to IsLocalization (Algebra.algebraMapSubmonoid (S ⊗[R] T) (Submonoid.powers a.val))
(S ⊗[R] Localization.Away a.val)
· simp only [Algebra.TensorProduct.includeRight_apply, Algebra.algebraMapSubmonoid,
Submonoid.map_powers]
rfl
· rw [← isLocalizedModule_iff_isLocalization, isLocalizedModule_iff_isBaseChange
(S := Submonoid.powers a.val) (A := Localization.Away a.val)]
exact Algebra.IsPushout.out
· intro a
have : (algebraMap (S ⊗[R] T) (S ⊗[R] Localization.Away a.val)).comp
Algebra.TensorProduct.includeLeftRingHom =
Algebra.TensorProduct.includeLeftRingHom := by
ext x
simp [RingHom.algebraMap_toAlgebra]
rw [this]
apply hPb R (Localization.Away a.val)
rw [IsScalarTower.algebraMap_eq R T (Localization.Away a.val)]
apply hs a a.property
/-- If `P` is preserved by localization away, then so is `Locally P`. -/
lemma locally_localizationAwayPreserves (hPl : LocalizationAwayPreserves P) :
LocalizationAwayPreserves (Locally P) := by
introv R hf
obtain ⟨s, hsone, hs⟩ := hf
rw [locally_iff_exists hPl.respectsIso]
let rₐ (a : s) : Localization.Away a.val := algebraMap _ _ (f r)
let Sₐ (a : s) := Localization.Away (rₐ a)
haveI (a : s) :
IsLocalization.Away (((algebraMap S (Localization.Away a.val)).comp f) r) (Sₐ a) :=
inferInstanceAs (IsLocalization.Away (rₐ a) (Sₐ a))
haveI (a : s) : IsLocalization (Algebra.algebraMapSubmonoid (Localization.Away a.val)
(Submonoid.map f (Submonoid.powers r))) (Sₐ a) := by
convert inferInstanceAs (IsLocalization.Away (rₐ a) (Sₐ a))
simp [rₐ, Algebra.algebraMapSubmonoid]
have H (a : s) : Submonoid.powers (f r) ≤
(Submonoid.powers (rₐ a)).comap (algebraMap S (Localization.Away a.val)) := by
simp [rₐ, Submonoid.powers_le]
letI (a : s) : Algebra S' (Sₐ a) :=
(IsLocalization.map (Sₐ a) (algebraMap S (Localization.Away a.val)) (H a)).toAlgebra
haveI (a : s) : IsScalarTower S S' (Sₐ a) :=
IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (H a)).symm
refine ⟨s, fun a ↦ algebraMap S S' a.val, ?_, Sₐ,
inferInstance, inferInstance, fun a ↦ ?_, fun a ↦ ?_⟩
· rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top]
· convert IsLocalization.commutes (T := Sₐ a) (M₁ := (Submonoid.powers r).map f) (S₁ := S')
(S₂ := Localization.Away a.val) (M₂ := Submonoid.powers a.val)
simp [Algebra.algebraMapSubmonoid]
· rw [algebraMap_toAlgebra, IsLocalization.Away.map, IsLocalization.map_comp_map]
exact hPl ((algebraMap _ (Localization.Away a.val)).comp f) r R' (Sₐ a) (hs _ a.2)
/-- If `P` is preserved by localizations, then so is `Locally P`. -/
lemma locally_localizationPreserves (hPl : LocalizationPreserves P) :
LocalizationPreserves (Locally P) := by
introv R hf
obtain ⟨s, hsone, hs⟩ := hf
rw [locally_iff_exists hPl.away.respectsIso]
let Mₐ (a : s) : Submonoid (Localization.Away a.val) :=
(M.map f).map (algebraMap S (Localization.Away a.val))
let Sₐ (a : s) := Localization (Mₐ a)
have hM (a : s) : M.map ((algebraMap S (Localization.Away a.val)).comp f) = Mₐ a :=
(M.map_map _ _).symm
haveI (a : s) :
IsLocalization (M.map ((algebraMap S (Localization.Away a.val)).comp f)) (Sₐ a) := by
rw [hM]
infer_instance
haveI (a : s) :
IsLocalization (Algebra.algebraMapSubmonoid (Localization.Away a.val) (M.map f)) (Sₐ a) :=
inferInstanceAs <| IsLocalization (Mₐ a) (Sₐ a)
letI (a : s) : Algebra S' (Sₐ a) :=
(IsLocalization.map (Sₐ a) (algebraMap S (Localization.Away a.val))
(M.map f).le_comap_map).toAlgebra
haveI (a : s) : IsScalarTower S S' (Sₐ a) :=
IsScalarTower.of_algebraMap_eq' (IsLocalization.map_comp (M.map f).le_comap_map).symm
refine ⟨s, fun a ↦ algebraMap S S' a.val, ?_, Sₐ,
inferInstance, inferInstance, fun a ↦ ?_, fun a ↦ ?_⟩
· rw [← Set.image_eq_range, ← Ideal.map_span, hsone, Ideal.map_top]
· convert IsLocalization.commutes (T := Sₐ a) (M₁ := M.map f) (S₁ := S')
(S₂ := Localization.Away a.val) (M₂ := Submonoid.powers a.val)
simp [Algebra.algebraMapSubmonoid]
· rw [algebraMap_toAlgebra, IsLocalization.map_comp_map]
apply hPl
exact hs a.val a.property
/-- If `P` is preserved by localizations and stable under composition with localization
away maps, then `Locally P` is a local property of ring homomorphisms. -/
lemma locally_propertyIsLocal (hPl : LocalizationAwayPreserves P)
(hPa : StableUnderCompositionWithLocalizationAway P) : PropertyIsLocal (Locally P) where
localizationAwayPreserves := locally_localizationAwayPreserves hPl
StableUnderCompositionWithLocalizationAwayTarget :=
locally_StableUnderCompositionWithLocalizationAwayTarget hPl.respectsIso hPa.right
ofLocalizationSpan := (locally_ofLocalizationSpanTarget hPl.respectsIso).ofLocalizationSpan
(locally_StableUnderCompositionWithLocalizationAwaySource hPa.left)
ofLocalizationSpanTarget := locally_ofLocalizationSpanTarget hPl.respectsIso
end Stability
end RingHom
|
Defs.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp
-/
import Mathlib.Data.Fintype.BigOperators
import Mathlib.LinearAlgebra.Finsupp.LinearCombination
/-!
# Bases
This file defines bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## Main definitions
All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or
vector space and `ι : Type*` is an arbitrary indexing type.
* `Basis ι R M` is the type of `ι`-indexed `R`-bases for a module `M`,
represented by a linear equiv `M ≃ₗ[R] ι →₀ R`.
* the basis vectors of a basis `b : Basis ι R M` are available as `b i`, where `i : ι`
* `Basis.repr` is the isomorphism sending `x : M` to its coordinates `Basis.repr x : ι →₀ R`.
The converse, turning this isomorphism into a basis, is called `Basis.ofRepr`.
* If `ι` is finite, there is a variant of `repr` called `Basis.equivFun b : M ≃ₗ[R] ι → R`
(saving you from having to work with `Finsupp`). The converse, turning this isomorphism into
a basis, is called `Basis.ofEquivFun`.
* `Basis.reindex` uses an equiv to map a basis to a different indexing set.
* `Basis.map` uses a linear equiv to map a basis to a different module.
* `Basis.constr`: given `b : Basis ι R M` and `f : ι → M`, construct a linear map `g` so that
`g (b i) = f i`.
* `Basis.coord`: `b.coord i x` is the `i`-th coordinate of a vector `x` with respect to the basis
`b`.
## Main results
* `Basis.ext` states that two linear maps are equal if they coincide on a basis.
Similar results are available for linear equivs (if they coincide on the basis vectors),
elements (if their coordinates coincide) and the functions `b.repr` and `⇑b`.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ι`.
## Tags
basis, bases
-/
assert_not_exists LinearMap.pi LinearIndependent Cardinal
-- TODO: assert_not_exists Submodule
-- (should be possible after splitting `Mathlib/LinearAlgebra/Finsupp/LinearCombination.lean`)
noncomputable section
universe u
open Function Set Submodule Finsupp
variable {ι : Type*} {ι' : Type*} {R : Type*} {R₂ : Type*} {K : Type*}
variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
namespace Module
variable [Semiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
variable (ι R M) in
/-- A `Basis ι R M` for a module `M` is the type of `ι`-indexed `R`-bases of `M`.
The basis vectors are available as `DFunLike.coe (b : Basis ι R M) : ι → M`.
To turn a linear independent family of vectors spanning `M` into a basis, use `Basis.mk`.
They are internally represented as linear equivs `M ≃ₗ[R] (ι →₀ R)`,
available as `Basis.repr`.
-/
structure Basis where
/-- `Basis.ofRepr` constructs a basis given an assignment of coordinates to each vector. -/
ofRepr ::
/-- `repr` is the linear equivalence sending a vector `x` to its coordinates:
the `c`s such that `x = ∑ i, c i`. -/
repr : M ≃ₗ[R] ι →₀ R
namespace Basis
instance : Inhabited (Basis ι R (ι →₀ R)) :=
⟨.ofRepr (LinearEquiv.refl _ _)⟩
variable (b b₁ : Basis ι R M) (i : ι) (c : R) (x : M)
section repr
theorem repr_injective : Injective (repr : Basis ι R M → M ≃ₗ[R] ι →₀ R) := fun f g h => by
cases f; cases g; congr
/-- `b i` is the `i`th basis vector. -/
instance instFunLike : FunLike (Basis ι R M) ι M where
coe b i := b.repr.symm (Finsupp.single i 1)
coe_injective' f g h := repr_injective <| LinearEquiv.symm_bijective.injective <|
LinearEquiv.toLinearMap_injective <| by ext; exact congr_fun h _
@[simp]
theorem coe_ofRepr (e : M ≃ₗ[R] ι →₀ R) : ⇑(ofRepr e) = fun i => e.symm (Finsupp.single i 1) :=
rfl
protected theorem injective [Nontrivial R] : Injective b :=
b.repr.symm.injective.comp fun _ _ => (Finsupp.single_left_inj (one_ne_zero : (1 : R) ≠ 0)).mp
theorem repr_symm_single_one : b.repr.symm (Finsupp.single i 1) = b i :=
rfl
theorem repr_symm_single : b.repr.symm (Finsupp.single i c) = c • b i :=
calc
b.repr.symm (Finsupp.single i c) = b.repr.symm (c • Finsupp.single i (1 : R)) := by
{ rw [Finsupp.smul_single', mul_one] }
_ = c • b i := by rw [LinearEquiv.map_smul, repr_symm_single_one]
@[simp]
theorem repr_self : b.repr (b i) = Finsupp.single i 1 :=
LinearEquiv.apply_symm_apply _ _
theorem repr_self_apply (j) [Decidable (i = j)] : b.repr (b i) j = if i = j then 1 else 0 := by
rw [repr_self, Finsupp.single_apply]
@[simp]
theorem repr_symm_apply (v) : b.repr.symm v = Finsupp.linearCombination R b v :=
calc
b.repr.symm v = b.repr.symm (v.sum Finsupp.single) := by simp
_ = v.sum fun i vi => b.repr.symm (Finsupp.single i vi) := map_finsuppSum ..
_ = Finsupp.linearCombination R b v := by simp only [repr_symm_single,
Finsupp.linearCombination_apply]
@[simp]
theorem coe_repr_symm : ↑b.repr.symm = Finsupp.linearCombination R b :=
LinearMap.ext fun v => b.repr_symm_apply v
@[simp]
theorem repr_linearCombination (v) : b.repr (Finsupp.linearCombination _ b v) = v := by
rw [← b.coe_repr_symm]
exact b.repr.apply_symm_apply v
@[simp]
theorem linearCombination_repr : Finsupp.linearCombination _ b (b.repr x) = x := by
rw [← b.coe_repr_symm]
exact b.repr.symm_apply_apply x
end repr
section Map
variable (f : M ≃ₗ[R] M')
/-- Apply the linear equivalence `f` to the basis vectors. -/
@[simps]
protected def map : Basis ι R M' :=
ofRepr (f.symm.trans b.repr)
@[simp]
theorem map_apply (i) : b.map f i = f (b i) :=
rfl
theorem coe_map : (b.map f : ι → M') = f ∘ b :=
rfl
end Map
section Reindex
variable (b' : Basis ι' R M')
variable (e : ι ≃ ι')
/-- `b.reindex (e : ι ≃ ι')` is a basis indexed by `ι'` -/
def reindex : Basis ι' R M :=
.ofRepr (b.repr.trans (Finsupp.domLCongr e))
theorem reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') :=
show (b.repr.trans (Finsupp.domLCongr e)).symm (Finsupp.single i' 1) =
b.repr.symm (Finsupp.single (e.symm i') 1)
by rw [LinearEquiv.symm_trans_apply, Finsupp.domLCongr_symm, Finsupp.domLCongr_single]
@[simp]
theorem coe_reindex : (b.reindex e : ι' → M) = b ∘ e.symm :=
funext (b.reindex_apply e)
theorem repr_reindex_apply (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') :=
show (Finsupp.domLCongr e : _ ≃ₗ[R] _) (b.repr x) i' = _ by simp
@[simp]
theorem repr_reindex : (b.reindex e).repr x = (b.repr x).mapDomain e :=
DFunLike.ext _ _ <| by simp [repr_reindex_apply]
@[simp]
theorem reindex_refl : b.reindex (Equiv.refl ι) = b := by
simp [reindex]
/-- `simp` can prove this as `Basis.coe_reindex` + `EquivLike.range_comp` -/
theorem range_reindex : Set.range (b.reindex e) = Set.range b := by
simp [coe_reindex, range_comp]
end Reindex
end Basis
section Fintype
open Basis
open Fintype
/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.
-/
def Basis.equivFun [Finite ι] (b : Basis ι R M) : M ≃ₗ[R] ι → R :=
LinearEquiv.trans b.repr
({ Finsupp.equivFunOnFinite with
toFun := (↑)
map_add' := Finsupp.coe_add
map_smul' := Finsupp.coe_smul } :
(ι →₀ R) ≃ₗ[R] ι → R)
/-- A module over a finite ring that admits a finite basis is finite. -/
def fintypeOfFintype [Fintype ι] (b : Basis ι R M) [Fintype R] : Fintype M :=
haveI := Classical.decEq ι
Fintype.ofEquiv _ b.equivFun.toEquiv.symm
theorem card_fintype [Fintype ι] (b : Basis ι R M) [Fintype R] [Fintype M] :
card M = card R ^ card ι := by
classical
calc
card M = card (ι → R) := card_congr b.equivFun.toEquiv
_ = card R ^ card ι := card_fun
/-- Given a basis `v` indexed by `ι`, the canonical linear equivalence between `ι → R` and `M` maps
a function `x : ι → R` to the linear combination `∑_i x i • v i`. -/
@[simp]
theorem Basis.equivFun_symm_apply [Fintype ι] (b : Basis ι R M) (x : ι → R) :
b.equivFun.symm x = ∑ i, x i • b i := by
simp [Basis.equivFun, Finsupp.linearCombination_apply, sum_fintype, equivFunOnFinite]
@[simp]
theorem Basis.equivFun_apply [Finite ι] (b : Basis ι R M) (u : M) : b.equivFun u = b.repr u :=
rfl
@[simp]
theorem Basis.map_equivFun [Finite ι] (b : Basis ι R M) (f : M ≃ₗ[R] M') :
(b.map f).equivFun = f.symm.trans b.equivFun :=
rfl
theorem Basis.sum_equivFun [Fintype ι] (b : Basis ι R M) (u : M) :
∑ i, b.equivFun u i • b i = u := by
rw [← b.equivFun_symm_apply, b.equivFun.symm_apply_apply]
@[simp]
theorem Basis.sum_repr [Fintype ι] (b : Basis ι R M) (u : M) : ∑ i, b.repr u i • b i = u :=
b.sum_equivFun u
@[simp]
theorem Basis.equivFun_self [Finite ι] [DecidableEq ι] (b : Basis ι R M) (i j : ι) :
b.equivFun (b i) j = if i = j then 1 else 0 := by rw [b.equivFun_apply, b.repr_self_apply]
theorem Basis.repr_sum_self [Fintype ι] (b : Basis ι R M) (c : ι → R) :
b.repr (∑ i, c i • b i) = c := by
simp_rw [← b.equivFun_symm_apply, ← b.equivFun_apply, b.equivFun.apply_symm_apply]
/-- Define a basis by mapping each vector `x : M` to its coordinates `e x : ι → R`,
as long as `ι` is finite. -/
def Basis.ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) : Basis ι R M :=
.ofRepr <| e.trans <| LinearEquiv.symm <| Finsupp.linearEquivFunOnFinite R R ι
@[simp]
theorem Basis.ofEquivFun_repr_apply [Finite ι] (e : M ≃ₗ[R] ι → R) (x : M) (i : ι) :
(Basis.ofEquivFun e).repr x i = e x i :=
rfl
@[simp]
theorem Basis.coe_ofEquivFun [Finite ι] [DecidableEq ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e : ι → M) = fun i => e.symm (Pi.single i 1) :=
funext fun i =>
e.injective <|
funext fun j => by
simp [Basis.ofEquivFun, ← Finsupp.single_eq_pi_single]
@[simp]
theorem Basis.ofEquivFun_equivFun [Finite ι] (v : Basis ι R M) :
Basis.ofEquivFun v.equivFun = v :=
Basis.repr_injective <| by ext; rfl
@[simp]
theorem Basis.equivFun_ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e).equivFun = e := by
ext j
simp_rw [Basis.equivFun_apply, Basis.ofEquivFun_repr_apply]
end Fintype
variable {ι R M : Type*}
variable [Semiring R] [AddCommMonoid M] [Module R M]
namespace Basis
variable (b : Basis ι R M)
section Ext
variable {R₁ : Type*} [Semiring R₁] {σ : R →+* R₁} {σ' : R₁ →+* R}
variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
variable {M₁ : Type*} [AddCommMonoid M₁] [Module R₁ M₁]
/-- Two linear maps are equal if they are equal on basis vectors. -/
theorem ext {f₁ f₂ : M →ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.linearCombination_repr x, Finsupp.linearCombination_apply, Finsupp.sum]
simp only [map_sum, LinearMap.map_smulₛₗ, h]
/-- Two linear equivs are equal if they are equal on basis vectors. -/
theorem ext' {f₁ f₂ : M ≃ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.linearCombination_repr x, Finsupp.linearCombination_apply, Finsupp.sum]
simp only [map_sum, LinearEquiv.map_smulₛₗ, h]
/-- Two elements are equal iff their coordinates are equal. -/
theorem ext_elem_iff {x y : M} : x = y ↔ ∀ i, b.repr x i = b.repr y i := by
simp only [← DFunLike.ext_iff, EmbeddingLike.apply_eq_iff_eq]
alias ⟨_, ext_elem⟩ := ext_elem_iff
theorem repr_eq_iff {b : Basis ι R M} {f : M →ₗ[R] ι →₀ R} :
↑b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext fun i => (b.repr_self i).trans (h i).symm⟩
theorem repr_eq_iff' {b : Basis ι R M} {f : M ≃ₗ[R] ι →₀ R} :
b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext' fun i => (b.repr_self i).trans (h i).symm⟩
theorem apply_eq_iff {b : Basis ι R M} {x : M} {i : ι} : b i = x ↔ b.repr x = Finsupp.single i 1 :=
⟨fun h => h ▸ b.repr_self i, fun h => b.repr.injective ((b.repr_self i).trans h.symm)⟩
/-- An unbundled version of `repr_eq_iff` -/
theorem repr_apply_eq (f : M → ι → R) (hadd : ∀ x y, f (x + y) = f x + f y)
(hsmul : ∀ (c : R) (x : M), f (c • x) = c • f x) (f_eq : ∀ i, f (b i) = Finsupp.single i 1)
(x : M) (i : ι) : b.repr x i = f x i := by
let f_i : M →ₗ[R] R :=
{ toFun x := f x i
map_add' _ _ := by rw [hadd, Pi.add_apply]
map_smul' _ _ := by simp [hsmul, Pi.smul_apply] }
have : Finsupp.lapply i ∘ₗ ↑b.repr = f_i := by
refine b.ext fun j => ?_
change b.repr (b j) i = f (b j) i
rw [b.repr_self, f_eq]
calc
b.repr x i = f_i x := by
{ rw [← this]
rfl }
_ = f x i := rfl
/-- Two bases are equal if they assign the same coordinates. -/
theorem eq_ofRepr_eq_repr {b₁ b₂ : Basis ι R M} (h : ∀ x i, b₁.repr x i = b₂.repr x i) : b₁ = b₂ :=
repr_injective <| by ext; apply h
/-- Two bases are equal if their basis vectors are the same. -/
@[ext]
theorem eq_of_apply_eq {b₁ b₂ : Basis ι R M} : (∀ i, b₁ i = b₂ i) → b₁ = b₂ :=
DFunLike.ext _ _
end Ext
section MapCoeffs
variable {R' : Type*} [Semiring R'] [Module R' M] (f : R ≃+* R')
attribute [local instance] SMul.comp.isScalarTower
/-- If `R` and `R'` are isomorphic rings that act identically on a module `M`,
then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module.
See also `Basis.algebraMapCoeffs` for the case where `f` is equal to `algebraMap`.
-/
@[simps +simpRhs]
def mapCoeffs (h : ∀ (c) (x : M), f c • x = c • x) : Basis ι R' M := by
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
exact ofRepr <| (b.repr.restrictScalars R').trans <|
Finsupp.mapRange.linearEquiv (Module.compHom.toLinearEquiv f.symm).symm
variable (h : ∀ (c) (x : M), f c • x = c • x)
theorem mapCoeffs_apply (i : ι) : b.mapCoeffs f h i = b i :=
apply_eq_iff.mpr <| by simp
@[simp]
theorem coe_mapCoeffs : (b.mapCoeffs f h : ι → M) = b :=
funext <| b.mapCoeffs_apply f h
end MapCoeffs
section ReindexRange
/-- `b.reindexRange` is a basis indexed by `range b`, the basis vectors themselves. -/
def reindexRange : Basis (range b) R M :=
haveI := Classical.dec (Nontrivial R)
if h : Nontrivial R then
letI := h
b.reindex (Equiv.ofInjective b (Basis.injective b))
else
letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp h
.ofRepr (Module.subsingletonEquiv R M (range b))
theorem reindexRange_self (i : ι) (h := Set.mem_range_self i) : b.reindexRange ⟨b i, h⟩ = b i := by
by_cases htr : Nontrivial R
· letI := htr
simp [htr, reindexRange, reindex_apply]
· letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp htr
letI := Module.subsingleton R M
simp [reindexRange, eq_iff_true_of_subsingleton]
theorem reindexRange_repr_self (i : ι) :
b.reindexRange.repr (b i) = Finsupp.single ⟨b i, mem_range_self i⟩ 1 :=
calc
b.reindexRange.repr (b i) = b.reindexRange.repr (b.reindexRange ⟨b i, mem_range_self i⟩) :=
congr_arg _ (b.reindexRange_self _ _).symm
_ = Finsupp.single ⟨b i, mem_range_self i⟩ 1 := b.reindexRange.repr_self _
@[simp]
theorem reindexRange_apply (x : range b) : b.reindexRange x = x := by
rcases x with ⟨bi, ⟨i, rfl⟩⟩
exact b.reindexRange_self i
theorem reindexRange_repr' (x : M) {bi : M} {i : ι} (h : b i = bi) :
b.reindexRange.repr x ⟨bi, ⟨i, h⟩⟩ = b.repr x i := by
nontriviality
subst h
apply (b.repr_apply_eq (fun x i => b.reindexRange.repr x ⟨b i, _⟩) _ _ _ x i).symm
· intro x y
ext i
simp only [Pi.add_apply, LinearEquiv.map_add, Finsupp.coe_add]
· intro c x
ext i
simp only [Pi.smul_apply, LinearEquiv.map_smul, Finsupp.coe_smul]
· intro i
ext j
simp only [reindexRange_repr_self]
apply Finsupp.single_apply_left (f := fun i => (⟨b i, _⟩ : Set.range b))
exact fun i j h => b.injective (Subtype.mk.inj h)
@[simp]
theorem reindexRange_repr (x : M) (i : ι) (h := Set.mem_range_self i) :
b.reindexRange.repr x ⟨b i, h⟩ = b.repr x i :=
b.reindexRange_repr' _ rfl
section Fintype
variable [Fintype ι] [DecidableEq M]
/-- `b.reindexFinsetRange` is a basis indexed by `Finset.univ.image b`,
the finite set of basis vectors themselves. -/
def reindexFinsetRange : Basis (Finset.univ.image b) R M :=
b.reindexRange.reindex ((Equiv.refl M).subtypeEquiv (by simp))
theorem reindexFinsetRange_self (i : ι) (h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange ⟨b i, h⟩ = b i := by
rw [reindexFinsetRange, reindex_apply, reindexRange_apply]
rfl
@[simp]
theorem reindexFinsetRange_apply (x : Finset.univ.image b) : b.reindexFinsetRange x = x := by
rcases x with ⟨bi, hbi⟩
rcases Finset.mem_image.mp hbi with ⟨i, -, rfl⟩
exact b.reindexFinsetRange_self i
theorem reindexFinsetRange_repr_self (i : ι) :
b.reindexFinsetRange.repr (b i) =
Finsupp.single ⟨b i, Finset.mem_image_of_mem b (Finset.mem_univ i)⟩ 1 := by
ext ⟨bi, hbi⟩
rw [reindexFinsetRange, repr_reindex, Finsupp.mapDomain_equiv_apply, reindexRange_repr_self]
simp [Finsupp.single_apply]
@[simp]
theorem reindexFinsetRange_repr (x : M) (i : ι)
(h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange.repr x ⟨b i, h⟩ = b.repr x i := by simp [reindexFinsetRange]
end Fintype
end ReindexRange
variable [Module R M']
section Constr
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
/-- Construct a linear map given the value at the basis, called `Basis.constr b S f` where `b` is
a basis, `f` is the value of the linear map over the elements of the basis, and `S` is an
extra semiring (typically `S = R` or `S = ℕ`).
This definition is parameterized over an extra `Semiring S`,
such that `SMulCommClass R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `AddEquiv` by setting `S := ℕ`.
See library note [bundled maps over different rings].
-/
def constr : (ι → M') ≃ₗ[S] M →ₗ[R] M' where
toFun f := (Finsupp.linearCombination R id).comp <| Finsupp.lmapDomain R R f ∘ₗ ↑b.repr
invFun f i := f (b i)
left_inv f := by
ext
simp
right_inv f := by
refine b.ext fun i => ?_
simp
map_add' f g := by
refine b.ext fun i => ?_
simp
map_smul' c f := by
refine b.ext fun i => ?_
simp
theorem constr_def (f : ι → M') :
constr (M' := M') b S f = linearCombination R id ∘ₗ Finsupp.lmapDomain R R f ∘ₗ ↑b.repr :=
rfl
theorem constr_apply (f : ι → M') (x : M) :
constr (M' := M') b S f x = (b.repr x).sum fun b a => a • f b := by
simp only [constr_def, LinearMap.comp_apply, lmapDomain_apply, linearCombination_apply]
rw [Finsupp.sum_mapDomain_index] <;> simp [add_smul]
@[simp]
theorem constr_basis (f : ι → M') (i : ι) : (constr (M' := M') b S f : M → M') (b i) = f i := by
simp [Basis.constr_apply, b.repr_self]
theorem constr_eq {g : ι → M'} {f : M →ₗ[R] M'} (h : ∀ i, g i = f (b i)) :
constr (M' := M') b S g = f :=
b.ext fun i => (b.constr_basis S g i).trans (h i)
theorem constr_self (f : M →ₗ[R] M') : (constr (M' := M') b S fun i => f (b i)) = f :=
b.constr_eq S fun _ => rfl
theorem constr_range {f : ι → M'} :
LinearMap.range (constr (M' := M') b S f) = span R (range f) := by
rw [b.constr_def S f, LinearMap.range_comp, LinearMap.range_comp, LinearEquiv.range, ←
Finsupp.supported_univ, Finsupp.lmapDomain_supported, ← Set.image_univ, ←
Finsupp.span_image_eq_map_linearCombination, Set.image_id]
@[simp]
theorem constr_comp (f : M' →ₗ[R] M') (v : ι → M') :
constr (M' := M') b S (f ∘ v) = f.comp (constr (M' := M') b S v) :=
b.ext fun i => by simp only [Basis.constr_basis, LinearMap.comp_apply, Function.comp]
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
@[simp]
theorem constr_apply_fintype [Fintype ι] (b : Basis ι R M) (f : ι → M') (x : M) :
(constr (M' := M') b S f : M → M') x = ∑ i, b.equivFun x i • f i := by
simp [b.constr_apply, b.equivFun_apply, Finsupp.sum_fintype]
end Constr
section Equiv
variable (i : ι)
variable {M'' : Type*} (b' : Basis ι' R M') (e : ι ≃ ι')
variable [AddCommMonoid M''] [Module R M'']
/-- If `b` is a basis for `M` and `b'` a basis for `M'`, and the index types are equivalent,
`b.equiv b' e` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `b' (e i)`. -/
protected def equiv : M ≃ₗ[R] M' :=
b.repr.trans (b'.reindex e.symm).repr.symm
@[simp]
theorem equiv_apply : b.equiv b' e (b i) = b' (e i) := by simp [Basis.equiv]
@[simp]
theorem equiv_refl : b.equiv b (Equiv.refl ι) = LinearEquiv.refl R M :=
b.ext' fun i => by simp
@[simp]
theorem equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm :=
b'.ext' fun i => (b.equiv b' e).injective (by simp)
@[simp]
theorem equiv_trans {ι'' : Type*} (b'' : Basis ι'' R M'') (e : ι ≃ ι') (e' : ι' ≃ ι'') :
(b.equiv b' e).trans (b'.equiv b'' e') = b.equiv b'' (e.trans e') :=
b.ext' fun i => by simp
@[simp]
theorem map_equiv (b : Basis ι R M) (b' : Basis ι' R M') (e : ι ≃ ι') :
b.map (b.equiv b' e) = b'.reindex e.symm := by
ext i
simp
section CommSemiring
variable {R M M' : Type*} [CommSemiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
variable (b : Basis ι R M) (b' : Basis ι' R M')
variable [SMulCommClass R R M']
/-- If `b` is a basis for `M` and `b'` a basis for `M'`,
and `f`, `g` form a bijection between the basis vectors,
`b.equiv' b' f g hf hg hgf hfg` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `f (b i)`.
-/
def equiv' (f : M → M') (g : M' → M) (hf : ∀ i, f (b i) ∈ range b') (hg : ∀ i, g (b' i) ∈ range b)
(hgf : ∀ i, g (f (b i)) = b i) (hfg : ∀ i, f (g (b' i)) = b' i) : M ≃ₗ[R] M' :=
{ constr (M' := M') b R (f ∘ b) with
invFun := constr (M' := M) b' R (g ∘ b')
left_inv :=
have : (constr (M' := M) b' R (g ∘ b')).comp (constr (M' := M') b R (f ∘ b)) = LinearMap.id :=
b.ext fun i =>
Exists.elim (hf i) fun i' hi' => by
rw [LinearMap.comp_apply, b.constr_basis, Function.comp_apply, ← hi', b'.constr_basis,
Function.comp_apply, hi', hgf, LinearMap.id_apply]
fun x => congr_arg (fun h : M →ₗ[R] M => h x) this
right_inv :=
have : (constr (M' := M') b R (f ∘ b)).comp (constr (M' := M) b' R (g ∘ b')) = LinearMap.id :=
b'.ext fun i =>
Exists.elim (hg i) fun i' hi' => by
rw [LinearMap.comp_apply, b'.constr_basis, Function.comp_apply, ← hi', b.constr_basis,
Function.comp_apply, hi', hfg, LinearMap.id_apply]
fun x => congr_arg (fun h : M' →ₗ[R] M' => h x) this }
@[simp]
theorem equiv'_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι) :
b.equiv' b' f g hf hg hgf hfg (b i) = f (b i) :=
b.constr_basis R _ _
@[simp]
theorem equiv'_symm_apply (f : M → M') (g : M' → M) (hf hg hgf hfg) (i : ι') :
(b.equiv' b' f g hf hg hgf hfg).symm (b' i) = g (b' i) :=
b'.constr_basis R _ _
theorem sum_repr_mul_repr {ι'} [Fintype ι'] (b' : Basis ι' R M) (x : M) (i : ι) :
(∑ j : ι', b.repr (b' j) i * b'.repr x j) = b.repr x i := by
conv_rhs => rw [← b'.sum_repr x]
simp_rw [map_sum, map_smul, Finset.sum_apply']
refine Finset.sum_congr rfl fun j _ => ?_
rw [Finsupp.smul_apply, smul_eq_mul, mul_comm]
end CommSemiring
end Equiv
section Coord
variable (i : ι)
/-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector
with respect to the basis `b`.
`b.coord i` is an element of the dual space. In particular, for
finite-dimensional spaces it is the `ι`th basis vector of the dual space.
-/
@[simps!]
def coord : M →ₗ[R] R :=
Finsupp.lapply i ∘ₗ ↑b.repr
theorem forall_coord_eq_zero_iff {x : M} : (∀ i, b.coord i x = 0) ↔ x = 0 :=
Iff.trans (by simp only [b.coord_apply, DFunLike.ext_iff, Finsupp.zero_apply])
b.repr.map_eq_zero_iff
/-- The sum of the coordinates of an element `m : M` with respect to a basis. -/
noncomputable def sumCoords : M →ₗ[R] R :=
(Finsupp.lsum ℕ fun _ => LinearMap.id) ∘ₗ (b.repr : M →ₗ[R] ι →₀ R)
@[simp]
theorem coe_sumCoords : (b.sumCoords : M → R) = fun m => (b.repr m).sum fun _ => id :=
rfl
@[simp high]
theorem coe_sumCoords_of_fintype [Fintype ι] : (b.sumCoords : M → R) = ∑ i, b.coord i := by
ext m
simp only [sumCoords, Finsupp.sum_fintype, LinearMap.id_coe, LinearEquiv.coe_coe, coord_apply,
id, Fintype.sum_apply, imp_true_iff, Finsupp.coe_lsum, LinearMap.coe_comp, comp_apply,
LinearMap.coeFn_sum]
@[simp]
theorem sumCoords_self_apply : b.sumCoords (b i) = 1 := by
simp only [Basis.sumCoords, LinearMap.id_coe, LinearEquiv.coe_coe, id, Basis.repr_self,
Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp, Finsupp.sum_single_index]
theorem dvd_coord_smul (i : ι) (m : M) (r : R) : r ∣ b.coord i (r • m) :=
⟨b.coord i m, by simp⟩
theorem coord_repr_symm (b : Basis ι R M) (i : ι) (f : ι →₀ R) :
b.coord i (b.repr.symm f) = f i := by
simp only [repr_symm_apply, coord_apply, repr_linearCombination]
theorem coe_sumCoords_eq_finsum : (b.sumCoords : M → R) = fun m => ∑ᶠ i, b.coord i m := by
ext m
simp only [Basis.sumCoords, Basis.coord, Finsupp.lapply_apply, LinearMap.id_coe,
LinearEquiv.coe_coe, Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp,
finsum_eq_sum _ (b.repr m).finite_support, Finsupp.sum, Finset.finite_toSet_toFinset, id,
Finsupp.fun_support_eq]
variable (e : ι ≃ ι')
@[simp]
theorem sumCoords_reindex : (b.reindex e).sumCoords = b.sumCoords := by
ext x
simp only [coe_sumCoords, repr_reindex]
exact Finsupp.sum_mapDomain_index (fun _ => rfl) fun _ _ _ => rfl
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
theorem coord_equivFun_symm [Finite ι] (b : Basis ι R M) (i : ι) (f : ι → R) :
b.coord i (b.equivFun.symm f) = f i :=
b.coord_repr_symm i (Finsupp.equivFunOnFinite.symm f)
end Coord
end Basis
end Module
|
Matrix.lean
|
/-
Copyright (c) 2024 Jon Bannon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jon Bannon, Jireh Loreaux
-/
import Mathlib.LinearAlgebra.Eigenspace.Basic
/-!
# Eigenvalues, Eigenvectors and Spectrum for Matrices
This file collects results about eigenvectors, eigenvalues and spectrum specific to matrices
over a nontrivial commutative ring, nontrivial commutative ring without zero divisors, or field.
## Tags
eigenspace, eigenvector, eigenvalue, spectrum, matrix
-/
section SpectrumDiagonal
variable {R n M : Type*} [DecidableEq n] [Fintype n]
open Matrix Module End
section NontrivialCommRing
variable [CommRing R] [Nontrivial R] [AddCommGroup M] [Module R M]
/-- Basis vectors are eigenvectors of associated diagonal linear operator. -/
lemma hasEigenvector_toLin_diagonal (d : n → R) (i : n) (b : Basis n R M) :
HasEigenvector (toLin b b (diagonal d)) (d i) (b i) :=
⟨mem_eigenspace_iff.mpr <| by simp [diagonal], Basis.ne_zero b i⟩
/-- Standard basis vectors are eigenvectors of any associated diagonal linear operator. -/
lemma hasEigenvector_toLin'_diagonal (d : n → R) (i : n) :
HasEigenvector (toLin' (diagonal d)) (d i) (Pi.basisFun R n i) :=
hasEigenvector_toLin_diagonal _ _ (Pi.basisFun R n)
/-- Eigenvalues of a diagonal linear operator are the diagonal entries. -/
lemma hasEigenvalue_toLin_diagonal_iff (d : n → R) {μ : R} [NoZeroSMulDivisors R M]
(b : Basis n R M) : HasEigenvalue (toLin b b (diagonal d)) μ ↔ ∃ i, d i = μ := by
have (i : n) : HasEigenvalue (toLin b b (diagonal d)) (d i) :=
hasEigenvalue_of_hasEigenvector <| hasEigenvector_toLin_diagonal d i b
constructor
· contrapose!
intro hμ h_eig
have h_iSup : ⨆ μ ∈ Set.range d, eigenspace (toLin b b (diagonal d)) μ = ⊤ := by
rw [eq_top_iff, ← b.span_eq, Submodule.span_le]
rintro - ⟨i, rfl⟩
simp only [SetLike.mem_coe]
apply Submodule.mem_iSup_of_mem (d i)
apply Submodule.mem_iSup_of_mem ⟨i, rfl⟩
rw [mem_eigenspace_iff]
exact (hasEigenvector_toLin_diagonal d i b).apply_eq_smul
have hμ_notMem : μ ∉ Set.range d := by simpa using fun i ↦ (hμ i)
have := eigenspaces_iSupIndep (toLin b b (diagonal d)) |>.disjoint_biSup hμ_notMem
rw [h_iSup, disjoint_top] at this
exact h_eig this
· rintro ⟨i, rfl⟩
exact this i
/-- Eigenvalues of a diagonal linear operator with respect to standard basis
are the diagonal entries. -/
lemma hasEigenvalue_toLin'_diagonal_iff [NoZeroDivisors R] (d : n → R) {μ : R} :
HasEigenvalue (toLin' (diagonal d)) μ ↔ (∃ i, d i = μ) :=
hasEigenvalue_toLin_diagonal_iff _ <| Pi.basisFun R n
end NontrivialCommRing
namespace Matrix
variable [CommRing R] [AddCommGroup M] [Module R M] (d : n → R) {μ : R} (b : Basis n R M)
@[simp]
lemma iSup_eigenspace_toLin_diagonal_eq_top :
⨆ μ, eigenspace ((diagonal d).toLin b b) μ = ⊤ := by
refine (Submodule.eq_top_iff_forall_basis_mem b).mpr fun j ↦ ?_
exact Submodule.mem_iSup_of_mem (d j) <| by simp [diagonal_apply]
@[simp]
lemma iSup_eigenspace_toLin'_diagonal_eq_top :
⨆ μ, eigenspace (diagonal d).toLin' μ = ⊤ :=
iSup_eigenspace_toLin_diagonal_eq_top d <| Pi.basisFun R n
variable [IsDomain R]
@[simp]
lemma maxGenEigenspace_toLin_diagonal_eq_eigenspace :
maxGenEigenspace ((diagonal d).toLin b b) μ = eigenspace ((diagonal d).toLin b b) μ := by
refine le_antisymm (fun x hx ↦ ?_) eigenspace_le_maxGenEigenspace
obtain ⟨k, hk⟩ := (mem_maxGenEigenspace _ _ _).mp hx
replace hk (j : n) : b.repr x j = 0 ∨ d j = μ ∧ k ≠ 0 := by
have aux : (diagonal d).toLin b b - μ • 1 = (diagonal (d - μ • 1)).toLin b b := by
change _ = (diagonal fun i ↦ d i - _).toLin b b; rw [← diagonal_sub]; simp [one_eq_id]
rw [aux, ← toLin_pow, diagonal_pow, toLin_apply_eq_zero_iff] at hk
simpa [mulVec_eq_sum, diagonal_apply, sub_eq_zero] using hk j
have aux (j : n) : (b.repr x j * d j) • b j = μ • (b.repr x j • b j) := by
rcases hk j with hj | hj
· simp [hj]
· rw [← hj.1, mul_comm, MulAction.mul_smul]
simp [toLin_apply, mulVec_eq_sum, diagonal_apply, aux, ← Finset.smul_sum]
@[simp]
lemma maxGenEigenspace_toLin'_diagonal_eq_eigenspace :
maxGenEigenspace (diagonal d).toLin' μ = eigenspace (diagonal d).toLin' μ :=
maxGenEigenspace_toLin_diagonal_eq_eigenspace d <| Pi.basisFun R n
end Matrix
/-- The spectrum of the diagonal operator is the range of the diagonal viewed as a function. -/
@[simp] lemma spectrum_diagonal [Field R] (d : n → R) :
spectrum R (diagonal d) = Set.range d := by
ext μ
rw [← AlgEquiv.spectrum_eq (toLinAlgEquiv <| Pi.basisFun R n), ← hasEigenvalue_iff_mem_spectrum]
exact hasEigenvalue_toLin'_diagonal_iff d
end SpectrumDiagonal
|
fraction.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 div seq.
From mathcomp Require Import ssrAC choice tuple bigop ssralg poly polydiv.
From mathcomp Require Import generic_quotient.
(******************************************************************************)
(* Field of fraction of an integral domain *)
(* *)
(* This file builds the field of fraction of any integral domain. The main *)
(* result of this file is the existence of the field and of the tofrac *)
(* function which is a injective ring morphism from R to its fraction field *)
(* {fraction R}. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GRing.Theory.
Local Open Scope ring_scope.
Local Open Scope quotient_scope.
Reserved Notation "{ 'ratio' T }" (format "{ 'ratio' T }").
Reserved Notation "{ 'fraction' T }" (format "{ 'fraction' T }").
Reserved Notation "x %:F" (format "x %:F").
Section FracDomain.
Variable R : nzRingType.
(* ratios are pairs of R, such that the second member is nonzero *)
Inductive ratio := mkRatio { frac :> R * R; _ : frac.2 != 0 }.
HB.instance Definition _ := [isSub for frac].
HB.instance Definition _ := [Choice of ratio by <:].
Lemma denom_ratioP : forall f : ratio, f.2 != 0. Proof. by case. Qed.
Definition ratio0 := (@mkRatio (0, 1) (oner_neq0 _)).
Definition Ratio x y : ratio := insubd ratio0 (x, y).
Lemma numer_Ratio x y : y != 0 -> (Ratio x y).1 = x.
Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed.
Lemma denom_Ratio x y : y != 0 -> (Ratio x y).2 = y.
Proof. by move=> ny0; rewrite /Ratio /insubd insubT. Qed.
Definition numden_Ratio := (numer_Ratio, denom_Ratio).
Variant Ratio_spec (n d : R) : ratio -> R -> R -> Type :=
| RatioNull of d = 0 : Ratio_spec n d ratio0 n 0
| RatioNonNull (d_neq0 : d != 0) :
Ratio_spec n d (@mkRatio (n, d) d_neq0) n d.
Lemma RatioP n d : Ratio_spec n d (Ratio n d) n d.
Proof.
rewrite /Ratio /insubd; case: insubP=> /= [x /= d_neq0 hx|].
have ->: x = @mkRatio (n, d) d_neq0 by apply: val_inj.
by constructor.
by rewrite negbK=> /eqP hx; rewrite {2}hx; constructor.
Qed.
Lemma Ratio0 x : Ratio x 0 = ratio0.
Proof. by rewrite /Ratio /insubd; case: insubP; rewrite //= eqxx. Qed.
End FracDomain.
Arguments ratio R%_type.
Notation "{ 'ratio' T }" := (ratio T) : type_scope.
Notation "'\n_' x" := (frac x).1
(at level 8, x at level 2, format "'\n_' x").
Notation "'\d_' x" := (frac x).2
(at level 8, x at level 2, format "'\d_' x").
Module FracField.
Section FracField.
Variable R : idomainType.
Local Notation frac := (R * R).
Local Notation dom := (ratio R).
Local Notation domP := denom_ratioP.
Implicit Types x y z : dom.
(* We define a relation in ratios *)
Local Notation equivf_notation x y := (\n_x * \d_y == \d_x * \n_y).
Definition equivf x y := equivf_notation x y.
Lemma equivfE x y : equivf x y = equivf_notation x y.
Proof. by []. Qed.
Lemma equivf_refl : reflexive equivf.
Proof. by move=> x; rewrite /equivf mulrC. Qed.
Lemma equivf_sym : symmetric equivf.
Proof. by move=> x y; rewrite /equivf eq_sym; congr (_==_); rewrite mulrC. Qed.
Lemma equivf_trans : transitive equivf.
Proof.
move=> [x Px] [y Py] [z Pz]; rewrite /equivf /= mulrC => /eqP xy /eqP yz.
by rewrite -(inj_eq (mulfI Px)) mulrA xy -mulrA yz mulrCA.
Qed.
(* we show that equivf is an equivalence *)
Canonical equivf_equiv := EquivRel equivf equivf_refl equivf_sym equivf_trans.
Definition type := {eq_quot equivf}.
(* we recover some structure for the quotient *)
HB.instance Definition _ : EqQuotient _ equivf type := EqQuotient.on type.
HB.instance Definition _ := Choice.on type.
(* we explain what was the equivalence on the quotient *)
Lemma equivf_def (x y : ratio R) : x == y %[mod type]
= (\n_x * \d_y == \d_x * \n_y).
Proof. by rewrite eqmodE. Qed.
Lemma equivf_r x : \n_x * \d_(repr (\pi_type x)) = \d_x * \n_(repr (\pi_type x)).
Proof. by apply/eqP; rewrite -equivf_def reprK. Qed.
Lemma equivf_l x : \n_(repr (\pi_type x)) * \d_x = \d_(repr (\pi_type x)) * \n_x.
Proof. by apply/eqP; rewrite -equivf_def reprK. Qed.
Lemma numer0 x : (\n_x == 0) = (x == (ratio0 R) %[mod_eq equivf]).
Proof. by rewrite eqmodE /= !equivfE // mulr1 mulr0. Qed.
Lemma Ratio_numden : forall x, Ratio \n_x \d_x = x.
Proof.
case=> [[n d] /= nd]; rewrite /Ratio /insubd; apply: val_inj=> /=.
by case: insubP=> //=; rewrite nd.
Qed.
Definition tofrac := lift_embed type (fun x : R => Ratio x 1).
Canonical tofrac_pi_morph := PiEmbed tofrac.
Notation "x %:F" := (@tofrac x).
Implicit Types a b c : type.
Definition addf x y : dom := Ratio (\n_x * \d_y + \n_y * \d_x) (\d_x * \d_y).
Definition add := lift_op2 type addf.
Lemma pi_add : {morph \pi : x y / addf x y >-> add x y}.
Proof.
move=> x y; unlock add; apply/eqmodP; rewrite /= equivfE /addf /=.
rewrite !numden_Ratio ?mulf_neq0 ?domP // mulrDr mulrDl; apply/eqP.
symmetry; rewrite (AC (2*2) (3*1*2*4)) (AC (2*2) (3*2*1*4))/=.
by rewrite !equivf_l (ACl ((2*3)*(1*4))) (ACl ((2*3)*(4*1)))/=.
Qed.
Canonical pi_add_morph := PiMorph2 pi_add.
Definition oppf x : dom := Ratio (- \n_x) \d_x.
Definition opp := lift_op1 type oppf.
Lemma pi_opp : {morph \pi : x / oppf x >-> opp x}.
Proof.
move=> x; unlock opp; apply/eqmodP; rewrite /= /equivf /oppf /=.
by rewrite !numden_Ratio ?(domP,mulf_neq0) // mulNr mulrN -equivf_r.
Qed.
Canonical pi_opp_morph := PiMorph1 pi_opp.
Definition mulf x y : dom := Ratio (\n_x * \n_y) (\d_x * \d_y).
Definition mul := lift_op2 type mulf.
Lemma pi_mul : {morph \pi : x y / mulf x y >-> mul x y}.
Proof.
move=> x y; unlock mul; apply/eqmodP=> /=.
rewrite equivfE /= /addf /= !numden_Ratio ?mulf_neq0 ?domP //.
by rewrite mulrACA !equivf_r mulrACA.
Qed.
Canonical pi_mul_morph := PiMorph2 pi_mul.
Definition invf x : dom := Ratio \d_x \n_x.
Definition inv := lift_op1 type invf.
Lemma pi_inv : {morph \pi : x / invf x >-> inv x}.
Proof.
move=> x; unlock inv; apply/eqmodP=> /=; rewrite equivfE /invf eq_sym.
do 2?case: RatioP=> /= [/eqP|];
rewrite ?mul0r ?mul1r -?equivf_def ?numer0 ?reprK //.
by move=> hx /eqP hx'; rewrite hx' eqxx in hx.
by move=> /eqP ->; rewrite eqxx.
Qed.
Canonical pi_inv_morph := PiMorph1 pi_inv.
Lemma addA : associative add.
Proof.
elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE.
rewrite /addf /= !numden_Ratio ?mulf_neq0 ?domP // !mulrDl.
by rewrite !mulrA !addrA ![_ * _ * \d_x]mulrAC.
Qed.
Lemma addC : commutative add.
Proof.
by elim/quotW=> x; elim/quotW=> y; rewrite !piE /addf addrC [\d__ * _]mulrC.
Qed.
Lemma add0_l : left_id 0%:F add.
Proof.
elim/quotW=> x; rewrite !piE /addf !numden_Ratio ?oner_eq0 //.
by rewrite mul0r mul1r mulr1 add0r Ratio_numden.
Qed.
Lemma addN_l : left_inverse 0%:F opp add.
Proof.
elim/quotW=> x; apply/eqP; rewrite piE /equivf.
rewrite /addf /oppf !numden_Ratio ?(oner_eq0, mulf_neq0, domP) //.
by rewrite mulr1 mulr0 mulNr addNr.
Qed.
(* fracions form an abelian group *)
HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0_l addN_l.
Lemma mulA : associative mul.
Proof.
elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; rewrite !piE.
by rewrite /mulf !numden_Ratio ?mulf_neq0 ?domP // !mulrA.
Qed.
Lemma mulC : commutative mul.
Proof.
elim/quotW=> x; elim/quotW=> y; rewrite !piE /mulf.
by rewrite [_ * (\d_x)]mulrC [_ * (\n_x)]mulrC.
Qed.
Lemma mul1_l : left_id 1%:F mul.
Proof.
elim/quotW=> x; rewrite !piE /mulf.
by rewrite !numden_Ratio ?oner_eq0 // !mul1r Ratio_numden.
Qed.
Lemma mul_addl : left_distributive mul add.
Proof.
elim/quotW=> x; elim/quotW=> y; elim/quotW=> z; apply/eqP.
rewrite !piE /equivf /mulf /addf !numden_Ratio ?mulf_neq0 ?domP //; apply/eqP.
rewrite !(mulrDr, mulrDl) (AC (3*(2*2)) (4*2*7*((1*3)*(6*5))))/=.
by rewrite [X in _ + X](AC (3*(2*2)) (4*6*7*((1*3)*(2*5))))/=.
Qed.
Lemma nonzero1 : 1%:F != 0%:F :> type.
Proof. by rewrite piE equivfE !numden_Ratio ?mul1r ?oner_eq0. Qed.
(* fractions form a commutative ring *)
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build type mulA mulC mul1_l mul_addl nonzero1.
Lemma mulV_l : forall a, a != 0%:F -> mul (inv a) a = 1%:F.
Proof.
elim/quotW=> x /=; rewrite !piE.
rewrite /equivf !numden_Ratio ?oner_eq0 // mulr1 mulr0=> nx0.
apply/eqmodP; rewrite /= equivfE.
by rewrite !numden_Ratio ?(oner_eq0, mulf_neq0, domP) // !mulr1 mulrC.
Qed.
Lemma inv0 : inv 0%:F = 0%:F.
Proof.
rewrite !piE /invf !numden_Ratio ?oner_eq0 // /Ratio /insubd.
do 2?case: insubP; rewrite //= ?eqxx ?oner_eq0 // => u _ hu _.
by congr \pi; apply: val_inj; rewrite /= hu.
Qed.
(* fractions form a ring with explicit unit *)
(* fractions form a field *)
HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulV_l inv0.
End FracField.
End FracField.
HB.export FracField.
Arguments FracField.type R%_type.
Notation "{ 'fraction' T }" := (FracField.type T).
Notation equivf := (@FracField.equivf _).
#[global] Hint Resolve denom_ratioP : core.
Section FracFieldTheory.
Import FracField.
Variable R : idomainType.
Lemma Ratio_numden (x : {ratio R}) : Ratio \n_x \d_x = x.
Proof. exact: FracField.Ratio_numden. Qed.
(* exporting the embedding from R to {fraction R} *)
Local Notation tofrac := (@FracField.tofrac R).
Local Notation "x %:F" := (tofrac x).
Lemma tofrac_is_zmod_morphism: zmod_morphism tofrac.
Proof.
move=> p q /=; unlock tofrac.
rewrite -[X in _ = _ + X]pi_opp -[RHS]pi_add.
by rewrite /addf /oppf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1).
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `tofrac_is_zmod_morphism` instead")]
Definition tofrac_is_additive := tofrac_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build R {fraction R} tofrac
tofrac_is_zmod_morphism.
Lemma tofrac_is_monoid_morphism: monoid_morphism tofrac.
Proof.
split=> [//|p q]; unlock tofrac; rewrite -[RHS]pi_mul.
by rewrite /mulf /= !numden_Ratio ?(oner_neq0, mul1r, mulr1).
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `tofrac_is_monoid_morphism` instead")]
Definition tofrac_is_multiplicative := tofrac_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R {fraction R} tofrac
tofrac_is_monoid_morphism.
(* tests *)
Lemma tofrac0 : 0%:F = 0. Proof. exact: rmorph0. Qed.
Lemma tofracN : {morph tofrac: x / - x}. Proof. exact: rmorphN. Qed.
Lemma tofracD : {morph tofrac: x y / x + y}. Proof. exact: rmorphD. Qed.
Lemma tofracB : {morph tofrac: x y / x - y}. Proof. exact: rmorphB. Qed.
Lemma tofracMn n : {morph tofrac: x / x *+ n}. Proof. exact: rmorphMn. Qed.
Lemma tofracMNn n : {morph tofrac: x / x *- n}. Proof. exact: rmorphMNn. Qed.
Lemma tofrac1 : 1%:F = 1. Proof. exact: rmorph1. Qed.
Lemma tofracM : {morph tofrac: x y / x * y}. Proof. exact: rmorphM. Qed.
Lemma tofracXn n : {morph tofrac: x / x ^+ n}. Proof. exact: rmorphXn. Qed.
Lemma tofrac_eq (p q : R): (p%:F == q%:F) = (p == q).
Proof.
apply/eqP/eqP=> [|->//]; unlock tofrac=> /eqmodP /eqP /=.
by rewrite !numden_Ratio ?(oner_eq0, mul1r, mulr1).
Qed.
Lemma tofrac_eq0 (p : R): (p%:F == 0) = (p == 0).
Proof. by rewrite tofrac_eq. Qed.
End FracFieldTheory.
|
Pow.lean
|
/-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Data.Nat.Cast.Commute
import Mathlib.Data.Nat.Cast.Order.Ring
/-! # Bernoulli's inequality -/
variable {R : Type*}
section OrderedSemiring
variable [Semiring R] [PartialOrder R] [IsOrderedRing R] {a : R}
/-- **Bernoulli's inequality**. This version works for semirings but requires
additional hypotheses `0 ≤ a * a` and `0 ≤ (1 + a) * (1 + a)`. -/
lemma one_add_mul_le_pow' (Hsq : 0 ≤ a * a) (Hsq' : 0 ≤ (1 + a) * (1 + a)) (H : 0 ≤ 2 + a) :
∀ n : ℕ, 1 + n * a ≤ (1 + a) ^ n
| 0 => by simp
| 1 => by simp
| n + 2 =>
have : 0 ≤ n * (a * a * (2 + a)) + a * a :=
add_nonneg (mul_nonneg n.cast_nonneg (mul_nonneg Hsq H)) Hsq
calc
_ ≤ 1 + ↑(n + 2) * a + (n * (a * a * (2 + a)) + a * a) := le_add_of_nonneg_right this
_ = (1 + a) * (1 + a) * (1 + n * a) := by
simp only [Nat.cast_add, add_mul, mul_add, one_mul, mul_one, ← one_add_one_eq_two,
Nat.cast_one, add_assoc]
simp only [← add_assoc, add_comm _ (↑n * a)]
simp only [add_assoc, (n.cast_commute (_ : R)).left_comm]
simp only [add_comm, add_left_comm]
_ ≤ (1 + a) * (1 + a) * (1 + a) ^ n :=
mul_le_mul_of_nonneg_left (one_add_mul_le_pow' Hsq Hsq' H _) Hsq'
_ = (1 + a) ^ (n + 2) := by simp only [pow_succ', mul_assoc]
end OrderedSemiring
section LinearOrderedRing
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a : R} {n : ℕ}
/-- **Bernoulli's inequality** for `n : ℕ`, `-2 ≤ a`. -/
lemma one_add_mul_le_pow (H : -2 ≤ a) (n : ℕ) : 1 + n * a ≤ (1 + a) ^ n :=
one_add_mul_le_pow' (mul_self_nonneg _) (mul_self_nonneg _) (neg_le_iff_add_nonneg'.1 H) _
/-- **Bernoulli's inequality** reformulated to estimate `a^n`. -/
lemma one_add_mul_sub_le_pow (H : -1 ≤ a) (n : ℕ) : 1 + n * (a - 1) ≤ a ^ n := by
have : -2 ≤ a - 1 := by
rwa [← one_add_one_eq_two, neg_add, ← sub_eq_add_neg, sub_le_sub_iff_right]
simpa only [add_sub_cancel] using one_add_mul_le_pow this n
end LinearOrderedRing
|
Sum.lean
|
/-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import Mathlib.Data.Fintype.Sum
/-!
# Finiteness of sum types
-/
variable {α β : Type*}
namespace Finite
instance [Finite α] [Finite β] : Finite (α ⊕ β) := by
haveI := Fintype.ofFinite α
haveI := Fintype.ofFinite β
infer_instance
theorem sum_left (β) [Finite (α ⊕ β)] : Finite α :=
of_injective (Sum.inl : α → α ⊕ β) Sum.inl_injective
theorem sum_right (α) [Finite (α ⊕ β)] : Finite β :=
of_injective (Sum.inr : β → α ⊕ β) Sum.inr_injective
instance {α β : Sort*} [Finite α] [Finite β] : Finite (α ⊕' β) :=
of_equiv _ ((Equiv.psumEquivSum _ _).symm.trans (Equiv.plift.psumCongr Equiv.plift))
theorem psum_left {α β : Sort*} [Finite (α ⊕' β)] : Finite α :=
of_injective (PSum.inl : α → α ⊕' β) PSum.inl_injective
theorem psum_right {α β : Sort*} [Finite (α ⊕' β)] : Finite β :=
of_injective (PSum.inr : β → α ⊕' β) PSum.inr_injective
end Finite
|
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_}.
|
finmodule.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq path.
From mathcomp Require Import div choice fintype bigop ssralg finset fingroup.
From mathcomp Require Import morphism perm finalg action gproduct commutator .
From mathcomp Require Import cyclic.
(******************************************************************************)
(* This file regroups constructions and results that are based on the most *)
(* primitive version of representation theory -- viewing an abelian group as *)
(* the additive group of a (finite) Z-module. This includes the Gaschutz *)
(* splitting and transitivity theorem, from which we will later derive the *)
(* Schur-Zassenhaus theorem and the elementary abelian special case of *)
(* Maschke's theorem, the coprime abelian centraliser/commutator trivial *)
(* intersection theorem, which is used to show that p-groups under coprime *)
(* action factor into special groups, and the construction of the transfer *)
(* homomorphism and its expansion relative to a cycle, from which we derive *)
(* the Higman Focal Subgroup and the Burnside Normal Complement theorems. *)
(* The definitions and lemmas for the finite Z-module induced by an abelian *)
(* are packaged in an auxiliary FiniteModule submodule: they should not be *)
(* needed much outside this file, which contains all the results that exploit *)
(* this construction. *)
(* FiniteModule defines the Z[N(A)]-module associated with a finite abelian *)
(* abelian group A, given a proof (abelA : abelian A) : *)
(* fmod_of abelA == the type of elements of the module (similar to but *)
(* distinct from [subg A]). *)
(* fmod abelA x == the injection of x into fmod_of abelA if x \in A, else 0 *)
(* fmval u == the projection of u : fmod_of abelA onto A *)
(* u ^@ x == the action of x \in 'N(A) on u : fmod_of abelA *)
(* The transfer morphism is be constructed from a morphism f : H >-> rT, and *)
(* a group G, along with the two assumptions sHG : H \subset G and *)
(* abfH : abelian (f @* H): *)
(* transfer sGH abfH == the function gT -> FiniteModule.fmod_of abfH that *)
(* implements the transfer morphism induced by f on G. *)
(* The Lemma transfer_indep states that the transfer morphism can be expanded *)
(* using any transversal of the partition HG := rcosets H G of G. *)
(* Further, for any g \in G, HG :* <[g]> is also a partition of G (Lemma *)
(* rcosets_cycle_partition), and for any transversal X of HG :* <[g]> the *)
(* function r mapping x : gT to rcosets (H :* x) <[g]> is (constructively) a *)
(* bijection from X to the <[g]>-orbit partition of HG, and Lemma *)
(* transfer_cycle_expansion gives a simplified expansion of the transfer *)
(* morphism. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope GRing.Theory FinRing.Theory.
Local Open Scope ring_scope.
Module FiniteModule.
Reserved Notation "u ^@ x" (at level 31, left associativity).
Inductive fmod_of (gT : finGroupType) (A : {group gT}) (abelA : abelian A) :=
Fmod x & x \in A.
Bind Scope ring_scope with fmod_of.
Section OneFinMod.
(* TODO: understand why FinGroup has to be changed to BaseFinGroup here. *)
Let f2sub (gT : finGroupType) (A : {group gT}) (abA : abelian A) :=
fun u : fmod_of abA => let : Fmod x Ax := u in Subg Ax : BaseFinGroup.arg_sort _.
Local Coercion f2sub : fmod_of >-> BaseFinGroup.arg_sort.
Variables (gT : finGroupType) (A : {group gT}) (abelA : abelian A).
Local Notation fmodA := (fmod_of abelA).
Implicit Types (x y z : gT) (u v w : fmodA).
Let sub2f (s : [subg A]) := Fmod abelA (valP s).
Definition fmval u := val (f2sub u).
#[export]
HB.instance Definition _ := [isSub for fmval].
Local Notation valA := (val: fmodA -> gT) (only parsing).
#[export]
HB.instance Definition _ := [Finite of fmodA by <:].
Definition fmod x := sub2f (subg A x).
Definition actr u x := if x \in 'N(A) then fmod (fmval u ^ x) else u.
Definition fmod_opp u := sub2f u^-1.
Definition fmod_add u v := sub2f (u * v).
Fact fmod_add0r : left_id (sub2f 1) fmod_add.
Proof. by move=> u; apply: val_inj; apply: mul1g. Qed.
Fact fmod_addrA : associative fmod_add.
Proof. by move=> u v w; apply: val_inj; apply: mulgA. Qed.
Fact fmod_addNr : left_inverse (sub2f 1) fmod_opp fmod_add.
Proof. by move=> u; apply: val_inj; apply: mulVg. Qed.
Fact fmod_addrC : commutative fmod_add.
Proof. by case=> x Ax [y Ay]; apply: val_inj; apply: (centsP abelA). Qed.
#[export]
HB.instance Definition _ :=
GRing.isZmodule.Build fmodA fmod_addrA fmod_addrC fmod_add0r fmod_addNr.
(* TODO: Should isZmodule and the like be exported from ssralg *)
#[export]
HB.instance Definition _ := [finGroupMixin of fmodA for +%R].
Lemma fmodP u : val u \in A. Proof. exact: valP. Qed.
Lemma fmod_inj : injective fmval. Proof. exact: val_inj. Qed.
Lemma congr_fmod u v : u = v -> fmval u = fmval v.
Proof. exact: congr1. Qed.
Lemma fmvalA : {morph valA : x y / x + y >-> (x * y)%g}. Proof. by []. Qed.
Lemma fmvalN : {morph valA : x / - x >-> x^-1%g}. Proof. by []. Qed.
Lemma fmval0 : valA 0 = 1%g. Proof. by []. Qed.
Canonical fmval_morphism := @Morphism _ _ setT fmval (in2W fmvalA).
Definition fmval_sum := big_morph fmval fmvalA fmval0.
Lemma fmvalZ n : {morph valA : x / x *+ n >-> (x ^+ n)%g}.
Proof. by move=> u; rewrite /= morphX ?inE. Qed.
Lemma fmodKcond x : val (fmod x) = if x \in A then x else 1%g.
Proof. by rewrite /= /fmval /= val_insubd. Qed.
Lemma fmodK : {in A, cancel fmod val}. Proof. exact: subgK. Qed.
Lemma fmvalK : cancel val fmod.
Proof. by case=> x Ax; apply: val_inj; rewrite /fmod /= sgvalK. Qed.
Lemma fmod1 : fmod 1 = 0. Proof. by rewrite -fmval0 fmvalK. Qed.
Lemma fmodM : {in A &, {morph fmod : x y / (x * y)%g >-> x + y}}.
Proof. by move=> x y Ax Ay /=; apply: val_inj; rewrite /fmod morphM. Qed.
Canonical fmod_morphism := Morphism fmodM.
Lemma fmodX n : {in A, {morph fmod : x / (x ^+ n)%g >-> x *+ n}}.
Proof. exact: morphX. Qed.
Lemma fmodV : {morph fmod : x / x^-1%g >-> - x}.
Proof.
move=> x; apply: val_inj; rewrite fmvalN !fmodKcond groupV.
by case: (x \in A); rewrite ?invg1.
Qed.
Lemma injm_fmod : 'injm fmod.
Proof.
by apply/injmP=> x y Ax Ay []; move/val_inj; apply: (injmP (injm_subg A)).
Qed.
Notation "u ^@ x" := (actr u x) : ring_scope.
Lemma fmvalJcond u x :
val (u ^@ x) = if x \in 'N(A) then val u ^ x else val u.
Proof. by case: ifP => Nx; rewrite /actr Nx ?fmodK // memJ_norm ?fmodP. Qed.
Lemma fmvalJ u x : x \in 'N(A) -> val (u ^@ x) = val u ^ x.
Proof. by move=> Nx; rewrite fmvalJcond Nx. Qed.
Lemma fmodJ x y : y \in 'N(A) -> fmod (x ^ y) = fmod x ^@ y.
Proof.
move=> Ny; apply: val_inj; rewrite fmvalJ ?fmodKcond ?memJ_norm //.
by case: ifP => // _; rewrite conj1g.
Qed.
Fact actr_is_action : is_action 'N(A) actr.
Proof.
split=> [a u v eq_uv_a | u a b Na Nb].
case Na: (a \in 'N(A)); last by rewrite /actr Na in eq_uv_a.
by apply: val_inj; apply: (conjg_inj a); rewrite -!fmvalJ ?eq_uv_a.
by apply: val_inj; rewrite !fmvalJ ?groupM ?conjgM.
Qed.
Canonical actr_action := Action actr_is_action.
Notation "''M'" := actr_action : action_scope.
Lemma act0r x : 0 ^@ x = 0.
Proof. by rewrite /actr conj1g morph1 if_same. Qed.
Lemma actAr x : {morph actr^~ x : u v / u + v}.
Proof.
by move=> u v; apply: val_inj; rewrite !(fmvalA, fmvalJcond) conjMg; case: ifP.
Qed.
Definition actr_sum x := big_morph _ (actAr x) (act0r x).
Lemma actNr x : {morph actr^~ x : u / - u}.
Proof. by move=> u; apply: (addrI (u ^@ x)); rewrite -actAr !subrr act0r. Qed.
Lemma actZr x n : {morph actr^~ x : u / u *+ n}.
Proof.
by move=> u; elim: n => [|n IHn]; rewrite ?act0r // !mulrS actAr IHn.
Qed.
Fact actr_is_groupAction : is_groupAction setT 'M.
Proof.
move=> a Na /[1!inE]; apply/andP; split; first by apply/subsetP=> u _ /[1!inE].
by apply/morphicP=> u v _ _; rewrite !permE /= actAr.
Qed.
Canonical actr_groupAction := GroupAction actr_is_groupAction.
Notation "''M'" := actr_groupAction : groupAction_scope.
Lemma actr1 u : u ^@ 1 = u.
Proof. exact: act1. Qed.
Lemma actrM : {in 'N(A) &, forall x y u, u ^@ (x * y) = u ^@ x ^@ y}.
Proof.
by move=> x y Nx Ny /= u; apply: val_inj; rewrite !fmvalJ ?conjgM ?groupM.
Qed.
Lemma actrK x : cancel (actr^~ x) (actr^~ x^-1%g).
Proof.
move=> u; apply: val_inj; rewrite !fmvalJcond groupV.
by case: ifP => -> //; rewrite conjgK.
Qed.
Lemma actrKV x : cancel (actr^~ x^-1%g) (actr^~ x).
Proof. by move=> u; rewrite /= -{2}(invgK x) actrK. Qed.
End OneFinMod.
Bind Scope ring_scope with fmod_of.
Prenex Implicits fmval fmod actr.
Notation "u ^@ x" := (actr u x) : ring_scope.
Notation "''M'" := actr_action : action_scope.
Notation "''M'" := actr_groupAction : groupAction_scope.
Module Exports.
HB.reexport FiniteModule.
End Exports.
End FiniteModule.
HB.export FiniteModule.Exports.
Arguments FiniteModule.fmodK {gT A} abelA [x] Ax.
Arguments FiniteModule.fmvalK {gT A abelA} x.
Arguments FiniteModule.actrK {gT A abelA} x.
Arguments FiniteModule.actrKV {gT A abelA} x.
(* Still allow ring notations, but give priority to groups now. *)
Import FiniteModule GroupScope.
Section Gaschutz.
Variables (gT : finGroupType) (G H P : {group gT}).
Implicit Types K L : {group gT}.
Hypotheses (nsHG : H <| G) (sHP : H \subset P) (sPG : P \subset G).
Hypotheses (abelH : abelian H) (coHiPG : coprime #|H| #|G : P|).
Let sHG := normal_sub nsHG.
Let nHG := subsetP (normal_norm nsHG).
Let m := (expg_invn H #|G : P|).
Implicit Types a b : fmod_of abelH.
Local Notation fmod := (fmod abelH).
Theorem Gaschutz_split : [splits G, over H] = [splits P, over H].
Proof.
apply/splitsP/splitsP=> [[K /complP[tiHK eqHK]] | [Q /complP[tiHQ eqHQ]]].
exists (K :&: P)%G; rewrite inE setICA (setIidPl sHP) setIC tiHK eqxx.
by rewrite group_modl // eqHK (sameP eqP setIidPr).
have sQP: Q \subset P by rewrite -eqHQ mulG_subr.
pose rP x := repr (P :* x); pose pP x := x * (rP x)^-1.
have PpP x: pP x \in P by rewrite -mem_rcoset rcoset_repr rcoset_refl.
have rPmul x y: x \in P -> rP (x * y) = rP y.
by move=> Px; rewrite /rP rcosetM rcoset_id.
pose pQ x := remgr H Q x; pose rH x := pQ (pP x) * rP x.
have pQhq: {in H & Q, forall h q, pQ (h * q) = q} by apply: remgrMid.
have pQmul: {in P &, {morph pQ : x y / x * y}}.
by apply: remgrM; [apply/complP | apply: normalS (nsHG)].
have HrH x: rH x \in H :* x.
by rewrite rcoset_sym mem_rcoset invMg mulgA mem_divgr // eqHQ PpP.
have GrH x: x \in G -> rH x \in G.
move=> Gx; case/rcosetP: (HrH x) => y Hy ->.
by rewrite groupM // (subsetP sHG).
have rH_Pmul x y: x \in P -> rH (x * y) = pQ x * rH y.
by move=> Px; rewrite /rH mulgA -pQmul; first by rewrite /pP rPmul ?mulgA.
have rH_Hmul h y: h \in H -> rH (h * y) = rH y.
by move=> Hh; rewrite rH_Pmul ?(subsetP sHP) // -(mulg1 h) pQhq ?mul1g.
pose mu x y := fmod ((rH x * rH y)^-1 * rH (x * y)).
pose nu y := (\sum_(Px in rcosets P G) mu (repr Px) y)%R.
have rHmul: {in G &, forall x y, rH (x * y) = rH x * rH y * val (mu x y)}.
move=> x y Gx Gy; rewrite /= fmodK ?mulKVg // -mem_lcoset lcoset_sym.
rewrite -norm_rlcoset; last by rewrite nHG ?GrH ?groupM.
by rewrite (rcoset_eqP (HrH _)) -rcoset_mul ?nHG ?GrH // mem_mulg.
have actrH a x: x \in G -> (a ^@ rH x = a ^@ x)%R.
move=> Gx; apply: val_inj; rewrite /= !fmvalJ ?nHG ?GrH //.
case/rcosetP: (HrH x) => b /(fmodK abelH) <- ->; rewrite conjgM.
by congr (_ ^ _); rewrite conjgE -fmvalN -!fmvalA (addrC a) addKr.
have mu_Pmul x y z: x \in P -> mu (x * y) z = mu y z.
move=> Px; congr fmod; rewrite -mulgA !(rH_Pmul x) ?rPmul //.
by rewrite -mulgA invMg -mulgA mulKg.
have mu_Hmul x y z: x \in G -> y \in H -> mu x (y * z) = mu x z.
move=> Gx Hy; congr fmod; rewrite (mulgA x) (conjgCV x) -mulgA 2?rH_Hmul //.
by rewrite -mem_conjg (normP _) ?nHG.
have{mu_Hmul} nu_Hmul y z: y \in H -> nu (y * z) = nu z.
move=> Hy; apply: eq_bigr => _ /rcosetsP[x Gx ->]; apply: mu_Hmul y z _ Hy.
by rewrite -(groupMl _ (subsetP sPG _ (PpP x))) mulgKV.
have cocycle_mu: {in G & &, forall x y z,
mu (x * y)%g z + mu x y ^@ z = mu y z + mu x (y * z)%g}%R.
- move=> x y z Gx Gy Gz; apply: val_inj.
apply: (mulgI (rH x * rH y * rH z)).
rewrite -(actrH _ _ Gz) addrC [in LHS]fmvalA fmvalJ ?nHG ?GrH //.
rewrite mulgA -(mulgA _ (rH z)) -conjgC mulgA -!rHmul ?groupM //.
by rewrite mulgA -mulgA -2!(mulgA (rH x)) -!rHmul ?groupM.
move: mu => mu in rHmul mu_Pmul cocycle_mu nu nu_Hmul.
have{cocycle_mu} cocycle_nu: {in G &, forall y z,
nu z + nu y ^@ z = mu y z *+ #|G : P| + nu (y * z)%g}%R.
- move=> y z Gy Gz; rewrite /= (actr_sum z) /=.
have ->: (nu z = \sum_(Px in rcosets P G) mu (repr Px * y)%g z)%R.
rewrite /nu (reindex_acts _ (actsRs_rcosets P G) Gy) /=.
apply: eq_bigr => _ /rcosetsP[x Gx /= ->].
rewrite rcosetE -rcosetM.
case: repr_rcosetP=> p1 Pp1; case: repr_rcosetP=> p2 Pp2.
by rewrite -mulgA [x * y]lock !mu_Pmul.
rewrite -sumr_const -!big_split /=; apply: eq_bigr => _ /rcosetsP[x Gx ->].
rewrite -cocycle_mu //; case: repr_rcosetP => p1 Pp1.
by rewrite groupMr // (subsetP sPG).
move: nu => nu in nu_Hmul cocycle_nu.
pose f x := rH x * val (nu x *+ m)%R.
have{cocycle_nu} fM: {in G &, {morph f : x y / x * y}}.
move=> x y Gx Gy; rewrite /f ?rHmul // -3!mulgA; congr (_ * _).
rewrite (mulgA _ (rH y)) (conjgC _ (rH y)) -mulgA; congr (_ * _).
rewrite -fmvalJ ?actrH ?nHG ?GrH // -!fmvalA actZr -mulrnDl.
rewrite -(addrC (nu y)) cocycle_nu // mulrnDl !fmvalA; congr (_ * _).
by rewrite !fmvalZ expgK ?fmodP.
exists (Morphism fM @* G)%G; apply/complP; split.
apply/trivgP/subsetP=> x /setIP[Hx /morphimP[y _ Gy eq_x]].
apply/set1P; move: Hx; rewrite {x}eq_x /= groupMr ?subgP //.
rewrite -{1}(mulgKV y (rH y)) groupMl -?mem_rcoset // => Hy.
by rewrite -(mulg1 y) /f nu_Hmul // rH_Hmul //; apply: (morph1 (Morphism fM)).
apply/setP=> x; apply/mulsgP/idP=> [[h y Hh fy ->{x}] | Gx].
rewrite groupMl; last exact: (subsetP sHG).
case/morphimP: fy => z _ Gz ->{h Hh y}.
by rewrite /= /f groupMl ?GrH // (subsetP sHG) ?fmodP.
exists (x * (f x)^-1) (f x); last first; first by rewrite mulgKV.
by apply/morphimP; exists x.
rewrite -groupV invMg invgK -mulgA (conjgC (val _)) mulgA.
by rewrite groupMl -(mem_rcoset, mem_conjg) // (normP _) ?nHG ?fmodP.
Qed.
Theorem Gaschutz_transitive : {in [complements to H in G] &,
forall K L, K :&: P = L :&: P -> exists2 x, x \in H & L :=: K :^ x}.
Proof.
move=> K L /=; set Q := K :&: P => /complP[tiHK eqHK] cpHL QeqLP.
have [trHL eqHL] := complP cpHL.
pose nu x := fmod (divgr H L x^-1).
have sKG: {subset K <= G} by apply/subsetP; rewrite -eqHK mulG_subr.
have sLG: {subset L <= G} by apply/subsetP; rewrite -eqHL mulG_subr.
have val_nu x: x \in G -> val (nu x) = divgr H L x^-1.
by move=> Gx; rewrite fmodK // mem_divgr // eqHL groupV.
have nu_cocycle: {in G &, forall x y, nu (x * y)%g = nu x ^@ y + nu y}%R.
move=> x y Gx Gy; apply: val_inj; rewrite fmvalA fmvalJ ?nHG //.
rewrite !val_nu ?groupM // /divgr conjgE !mulgA mulgK.
by rewrite !(invMg, remgrM cpHL) ?groupV ?mulgA.
have nuL x: x \in L -> nu x = 0%R.
move=> Lx; apply: val_inj; rewrite val_nu ?sLG //.
by rewrite /divgr remgr_id ?groupV ?mulgV.
exists (fmval ((\sum_(X in rcosets Q K) nu (repr X)) *+ m)).
exact: fmodP.
apply/eqP; rewrite eq_sym eqEcard; apply/andP; split; last first.
by rewrite cardJg -(leq_pmul2l (cardG_gt0 H)) -!TI_cardMg // eqHL eqHK.
apply/subsetP=> _ /imsetP[x Kx ->]; rewrite conjgE mulgA (conjgC _ x).
have Gx: x \in G by rewrite sKG.
rewrite conjVg -mulgA -fmvalJ ?nHG // -fmvalN -fmvalA (_ : _ + _ = nu x)%R.
by rewrite val_nu // mulKVg groupV mem_remgr // eqHL groupV.
rewrite actZr -!mulNrn -mulrnDl actr_sum.
rewrite addrC (reindex_acts _ (actsRs_rcosets _ K) Kx) -sumrB /= -/Q.
rewrite (eq_bigr (fun _ => nu x)) => [|_ /imsetP[y Ky ->]]; last first.
rewrite !rcosetE -rcosetM QeqLP.
case: repr_rcosetP => z /setIP[Lz _]; case: repr_rcosetP => t /setIP[Lt _].
rewrite !nu_cocycle ?groupM ?(sKG y) // ?sLG //.
by rewrite (nuL z) ?(nuL t) // !act0r !add0r addrC addKr.
apply: val_inj; rewrite sumr_const !fmvalZ.
rewrite -{2}(expgK coHiPG (fmodP (nu x))); congr (_ ^+ _ ^+ _).
rewrite -[#|_|]divgS ?subsetIl // -(divnMl (cardG_gt0 H)).
rewrite -!TI_cardMg //; last by rewrite setIA setIAC (setIidPl sHP).
by rewrite group_modl // eqHK (setIidPr sPG) divgS.
Qed.
End Gaschutz.
(* This is the TI part of B & G, Proposition 1.6(d). *)
(* We go with B & G rather than Aschbacher and will derive 1.6(e) from (d), *)
(* rather than the converse, because the derivation of 24.6 from 24.3 in *)
(* Aschbacher requires a separate reduction to p-groups to yield 1.6(d), *)
(* making it altogether longer than the direct Gaschutz-style proof. *)
(* This Lemma is used in maximal.v for the proof of Aschbacher 24.7. *)
Lemma coprime_abel_cent_TI (gT : finGroupType) (A G : {group gT}) :
A \subset 'N(G) -> coprime #|G| #|A| -> abelian G -> 'C_[~: G, A](A) = 1.
Proof.
move=> nGA coGA abG; pose f x := val (\sum_(a in A) fmod abG x ^@ a)%R.
have fM: {in G &, {morph f : x y / x * y}}.
move=> x y Gx Gy /=; rewrite -fmvalA -big_split /=; congr (fmval _).
by apply: eq_bigr => a Aa; rewrite fmodM // actAr.
have nfA x a: a \in A -> f (x ^ a) = f x.
move=> Aa; rewrite {2}/f (reindex_inj (mulgI a)) /=; congr (fmval _).
apply: eq_big => [b | b Ab]; first by rewrite groupMl.
by rewrite -!fmodJ ?groupM ?(subsetP nGA) // conjgM.
have kerR: [~: G, A] \subset 'ker (Morphism fM).
rewrite gen_subG; apply/subsetP=> xa; case/imset2P=> x a Gx Aa -> {xa}.
have Gxa: x ^ a \in G by rewrite memJ_norm ?(subsetP nGA).
rewrite commgEl; apply/kerP; rewrite (groupM, morphM) ?(groupV, morphV) //=.
by rewrite nfA ?mulVg.
apply/trivgP; apply/subsetP=> x /setIP[Rx cAx]; apply/set1P.
have Gx: x \in G by apply: subsetP Rx; rewrite commg_subl.
rewrite -(expgK coGA Gx) (_ : x ^+ _ = 1) ?expg1n //.
rewrite -(fmodK abG Gx) -fmvalZ -(mker (subsetP kerR x Rx)); congr fmval.
rewrite -GRing.sumr_const; apply: eq_bigr => a Aa.
by rewrite -fmodJ ?(subsetP nGA) // /conjg (centP cAx) // mulKg.
Qed.
Section Transfer.
Variables (gT aT : finGroupType) (G H : {group gT}).
Variable alpha : {morphism H >-> aT}.
Hypotheses (sHG : H \subset G) (abelA : abelian (alpha @* H)).
Local Notation HG := (rcosets (gval H) (gval G)).
Fact transfer_morph_subproof : H \subset alpha @*^-1 (alpha @* H).
Proof. by rewrite -sub_morphim_pre. Qed.
Let fmalpha := restrm transfer_morph_subproof (fmod abelA \o alpha).
Let V (rX : {set gT} -> gT) g :=
\sum_(Hx in rcosets H G) fmalpha (rX Hx * g * (rX (Hx :* g))^-1).
Definition transfer g := V repr g.
(* This is Aschbacher (37.2). *)
Lemma transferM : {in G &, {morph transfer : x y / (x * y)%g >-> x + y}}.
Proof.
move=> s t Gs Gt /=.
rewrite [transfer t](reindex_acts 'Rs _ Gs) ?actsRs_rcosets //= -big_split /=.
apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM.
rewrite -zmodMgE -morphM -?mem_rcoset; first by rewrite !mulgA mulgKV rcosetM.
by rewrite rcoset_repr rcosetM mem_rcoset mulgK mem_repr_rcoset.
by rewrite rcoset_repr (rcosetM _ _ t) mem_rcoset mulgK mem_repr_rcoset.
Qed.
Canonical transfer_morphism := Morphism transferM.
(* This is Aschbacher (37.1). *)
Lemma transfer_indep X (rX := transversal_repr 1 X) :
is_transversal X HG G -> {in G, transfer =1 V rX}.
Proof.
move=> trX g Gg; have mem_rX := repr_mem_pblock trX 1; rewrite -/rX in mem_rX.
apply: (addrI (\sum_(Hx in HG) fmalpha (repr Hx * (rX Hx)^-1))).
rewrite {1}(reindex_acts 'Rs _ Gg) ?actsRs_rcosets // -!big_split /=.
apply: eq_bigr => _ /rcosetsP[x Gx ->]; rewrite !rcosetE -!rcosetM.
case: repr_rcosetP => h1 Hh1; case: repr_rcosetP => h2 Hh2.
have: H :* (x * g) \in rcosets H G by rewrite -rcosetE imset_f ?groupM.
have: H :* x \in rcosets H G by rewrite -rcosetE imset_f.
case/mem_rX/rcosetP=> h3 Hh3 -> /mem_rX/rcosetP[h4 Hh4 ->].
rewrite -!(mulgA h1) -!(mulgA h2) -!(mulgA h3) !(mulKVg, invMg).
by rewrite addrC -!zmodMgE -!morphM ?groupM ?groupV // -!mulgA !mulKg.
Qed.
Section FactorTransfer.
Variable g : gT.
Hypothesis Gg : g \in G.
Let sgG : <[g]> \subset G. Proof. by rewrite cycle_subG. Qed.
Let H_g_rcosets x : {set {set gT}} := rcosets (H :* x) <[g]>.
Let n_ x := #|<[g]> : H :* x|.
Lemma mulg_exp_card_rcosets x : x * (g ^+ n_ x) \in H :* x.
Proof.
rewrite /n_ /indexg -orbitRs -porbit_actperm ?inE //.
rewrite -{2}(iter_porbit (actperm 'Rs g) (H :* x)) -permX -morphX ?inE //.
by rewrite actpermE //= rcosetE -rcosetM rcoset_refl.
Qed.
Let HGg : {set {set {set gT}}} := orbit 'Rs <[g]> @: HG.
Let partHG : partition HG G := rcosets_partition sHG.
Let actsgHG : [acts <[g]>, on HG | 'Rs].
Proof. exact: subset_trans sgG (actsRs_rcosets H G). Qed.
Let partHGg : partition HGg HG := orbit_partition actsgHG.
Let injHGg : {in HGg &, injective cover}.
Proof. by have [] := partition_partition partHG partHGg. Qed.
Let defHGg : HG :* <[g]> = cover @: HGg.
Proof.
rewrite -imset_comp [_ :* _]imset2_set1r; apply: eq_imset => Hx /=.
by rewrite cover_imset -curry_imset2r.
Qed.
Lemma rcosets_cycle_partition : partition (HG :* <[g]>) G.
Proof. by rewrite defHGg; have [] := partition_partition partHG partHGg. Qed.
Variable X : {set gT}.
Hypothesis trX : is_transversal X (HG :* <[g]>) G.
Let sXG : {subset X <= G}. Proof. exact/subsetP/(transversal_sub trX). Qed.
Lemma rcosets_cycle_transversal : H_g_rcosets @: X = HGg.
Proof.
have sHXgHGg x: x \in X -> H_g_rcosets x \in HGg.
by move/sXG=> Gx; apply: imset_f; rewrite -rcosetE imset_f.
apply/setP=> Hxg; apply/imsetP/idP=> [[x /sHXgHGg HGgHxg -> //] | HGgHxg].
have [_ /rcosetsP[z Gz ->] ->] := imsetP HGgHxg.
pose Hzg := H :* z * <[g]>; pose x := transversal_repr 1 X Hzg.
have HGgHzg: Hzg \in HG :* <[g]>.
by rewrite mem_mulg ?set11 // -rcosetE imset_f.
have Hzg_x: x \in Hzg by rewrite (repr_mem_pblock trX).
exists x; first by rewrite (repr_mem_transversal trX).
case/mulsgP: Hzg_x => y u /rcoset_eqP <- /(orbit_act 'Rs) <- -> /=.
by rewrite rcosetE -rcosetM.
Qed.
Local Notation defHgX := rcosets_cycle_transversal.
Let injHg: {in X &, injective H_g_rcosets}.
Proof.
apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg.
by rewrite (card_in_imset injHGg).
Qed.
Lemma sum_index_rcosets_cycle : (\sum_(x in X) n_ x)%N = #|G : H|.
Proof. by rewrite [#|G : H|](card_partition partHGg) -defHgX big_imset. Qed.
Lemma transfer_cycle_expansion :
transfer g = \sum_(x in X) fmalpha ((g ^+ n_ x) ^ (x^-1)).
Proof.
pose Y := \bigcup_(x in X) [set x * g ^+ i | i : 'I_(n_ x)].
pose rY := transversal_repr 1 Y.
pose pcyc x := porbit (actperm 'Rs g) (H :* x).
pose traj x := traject (actperm 'Rs g) (H :* x) #|pcyc x|.
have Hgr_eq x: H_g_rcosets x = pcyc x.
by rewrite /H_g_rcosets -orbitRs -porbit_actperm ?inE.
have pcyc_eq x: pcyc x =i traj x by apply: porbit_traject.
have uniq_traj x: uniq (traj x) by apply: uniq_traject_porbit.
have n_eq x: n_ x = #|pcyc x| by rewrite -Hgr_eq.
have size_traj x: size (traj x) = n_ x by rewrite n_eq size_traject.
have nth_traj x j: j < n_ x -> nth (H :* x) (traj x) j = H :* (x * g ^+ j).
move=> lt_j_x; rewrite nth_traject -?n_eq //.
by rewrite -permX -morphX ?inE // actpermE //= rcosetE rcosetM.
have sYG: Y \subset G.
apply/bigcupsP=> x Xx; apply/subsetP=> _ /imsetP[i _ ->].
by rewrite groupM ?groupX // sXG.
have trY: is_transversal Y HG G.
apply/and3P; split=> //; apply/forall_inP=> Hy.
have /and3P[/eqP <- _ _] := partHGg; rewrite -defHgX cover_imset.
case/bigcupP=> x Xx; rewrite Hgr_eq pcyc_eq => /trajectP[i].
rewrite -n_eq -permX -morphX ?in_setT // actpermE /= rcosetE -rcosetM => lti.
set y := x * _ => ->{Hy}; pose oi := Ordinal lti.
have Yy: y \in Y by apply/bigcupP; exists x => //; apply/imsetP; exists oi.
apply/cards1P; exists y; apply/esym/eqP.
rewrite eqEsubset sub1set inE Yy rcoset_refl.
apply/subsetP=> _ /setIP[/bigcupP[x' Xx' /imsetP[j _ ->]] Hy_x'gj].
have eq_xx': x = x'.
apply: (pblock_inj trX) => //; have /andP[/and3P[_ tiX _] _] := trX.
have HGgHyg: H :* y * <[g]> \in HG :* <[g]>.
by rewrite mem_mulg ?set11 // -rcosetE imset_f ?(subsetP sYG).
rewrite !(def_pblock tiX HGgHyg) //.
by rewrite -[x'](mulgK (g ^+ j)) mem_mulg // groupV mem_cycle.
by rewrite -[x](mulgK (g ^+ i)) mem_mulg ?rcoset_refl // groupV mem_cycle.
apply/set1P; rewrite /y eq_xx'; congr (_ * _ ^+ _) => //; apply/eqP.
rewrite -(@nth_uniq _ (H :* x) (traj x)) ?size_traj // ?eq_xx' //.
by rewrite !nth_traj ?(rcoset_eqP Hy_x'gj) // -eq_xx'.
have rYE x i : x \in X -> i < n_ x -> rY (H :* x :* g ^+ i) = x * g ^+ i.
move=> Xx lt_i_x; rewrite -rcosetM; apply: (canLR_in (pblockK trY 1)).
by apply/bigcupP; exists x => //; apply/imsetP; exists (Ordinal lt_i_x).
apply/esym/def_pblock; last exact: rcoset_refl; first by case/and3P: partHG.
by rewrite -rcosetE imset_f ?groupM ?groupX // sXG.
rewrite (transfer_indep trY Gg) /V -/rY (set_partition_big _ partHGg) /=.
rewrite -defHgX big_imset /=; last first.
apply/imset_injP; rewrite defHgX (card_transversal trX) defHGg.
by rewrite (card_in_imset injHGg).
apply eq_bigr=> x Xx; rewrite Hgr_eq (eq_bigl _ _ (pcyc_eq x)) -big_uniq //=.
have n_gt0: 0 < n_ x by rewrite indexg_gt0.
rewrite /traj -n_eq; case def_n: (n_ x) (n_gt0) => // [n] _.
rewrite conjgE invgK -{1}[H :* x]rcoset1 -{1}(expg0 g).
elim: {1 3}n 0%N (addn0 n) => [|m IHm] i def_i /=.
rewrite big_seq1 {i}[i]def_i rYE // ?def_n //.
rewrite -(mulgA _ _ g) -rcosetM -expgSr -[(H :* x) :* _]rcosetE.
rewrite -actpermE morphX ?inE // permX // -{2}def_n n_eq iter_porbit mulgA.
by rewrite -[H :* x]rcoset1 (rYE _ 0) ?mulg1.
rewrite big_cons rYE //; last by rewrite def_n -def_i ltnS leq_addl.
rewrite permE /= rcosetE -rcosetM -(mulgA _ _ g) -expgSr.
rewrite addSnnS in def_i; rewrite IHm //.
rewrite rYE //; last by rewrite def_n -def_i ltnS leq_addl.
by rewrite mulgV [fmalpha 1]morph1 add0r.
Qed.
End FactorTransfer.
End Transfer.
|
morphism.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 choice.
From mathcomp Require Import fintype finfun bigop finset fingroup.
(******************************************************************************)
(* This file contains the definitions of: *)
(* *)
(* {morphism D >-> rT} == *)
(* the structure type of functions that are group morphisms mapping a *)
(* domain set D : {set aT} to a type rT; rT must have a finGroupType *)
(* structure, and D is usually a group (most of the theory expects this). *)
(* mfun == the coercion projecting {morphism D >-> rT} to aT -> rT *)
(* *)
(* Basic examples: *)
(* idm D == the identity morphism with domain D, or more precisely *)
(* the identity function, but with a canonical *)
(* {morphism G -> gT} structure. *)
(* trivm D == the trivial morphism with domain D. *)
(* If f has a {morphism D >-> rT} structure *)
(* 'dom f == D, the domain of f. *)
(* f @* A == the image of A by f, where f is defined. *)
(* := f @: (D :&: A) *)
(* f @*^-1 R == the pre-image of R by f, where f is defined. *)
(* := D :&: f @^-1: R *)
(* 'ker f == the kernel of f. *)
(* := f @*^-1 1 *)
(* 'ker_G f == the kernel of f restricted to G. *)
(* := G :&: 'ker f (this is a pure notation) *)
(* 'injm f <=> f injective on D. *)
(* <-> ker f \subset 1 (this is a pure notation) *)
(* invm injf == the inverse morphism of f, with domain f @* D, when f *)
(* is injective (injf : 'injm f). *)
(* restrm f sDom == the restriction of f to a subset A of D, given *)
(* (sDom : A \subset D); restrm f sDom is transparently *)
(* identical to f; the restrmP and domP lemmas provide *)
(* opaque restrictions. *)
(* *)
(* G \isog H <=> G and H are isomorphic as groups. *)
(* H \homg G <=> H is a homomorphic image of G. *)
(* isom G H f <=> f maps G isomorphically to H, provided D contains G. *)
(* := f @: G^# == H^# *)
(* *)
(* If, moreover, g : {morphism G >-> gT} with G : {group aT}, *)
(* factm sKer sDom == the (natural) factor morphism mapping f @* G to g @* G *)
(* with sDom : G \subset D, sKer : 'ker f \subset 'ker g. *)
(* ifactm injf g == the (natural) factor morphism mapping f @* G to g @* G *)
(* when f is injective (injf : 'injm f); here g must *)
(* denote an actual morphism structure, not its function *)
(* projection. *)
(* *)
(* If g has a {morphism G >-> aT} structure for any G : {group gT}, then *)
(* f \o g has a canonical {morphism g @*^-1 D >-> rT} structure. *)
(* *)
(* Finally, for an arbitrary function f : aT -> rT *)
(* morphic D f <=> f preserves group multiplication in D, i.e., *)
(* f (x * y) = (f x) * (f y) for all x, y in D. *)
(* morphm fM == a function identical to f, but with a canonical *)
(* {morphism D >-> rT} structure, given fM : morphic D f. *)
(* misom D C f <=> f is a morphism that maps D isomorphically to C. *)
(* := morphic D f && isom D C f *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Reserved Notation "x \isog y" (at level 70).
Section MorphismStructure.
Variables aT rT : finGroupType.
Structure morphism (D : {set aT}) : Type := Morphism {
mfun :> aT -> FinGroup.sort rT;
_ : {in D &, {morph mfun : x y / x * y}}
}.
(* We give the 'lightest' possible specification to define morphisms: local *)
(* congruence, in D, with the group law of aT. We then provide the properties *)
(* for the 'textbook' notion of morphism, when the required structures are *)
(* available (e.g. its domain is a group). *)
Definition morphism_for D of phant rT := morphism D.
Definition clone_morphism D f :=
let: Morphism _ fM := f
return {type of @Morphism D for f} -> morphism_for D (Phant rT)
in fun k => k fM.
Variables (D A : {set aT}) (R : {set rT}) (x : aT) (y : rT) (f : aT -> rT).
Variant morphim_spec : Prop := MorphimSpec z & z \in D & z \in A & y = f z.
Lemma morphimP : reflect morphim_spec (y \in f @: (D :&: A)).
Proof.
apply: (iffP imsetP) => [] [z]; first by case/setIP; exists z.
by exists z; first apply/setIP.
Qed.
Lemma morphpreP : reflect (x \in D /\ f x \in R) (x \in D :&: f @^-1: R).
Proof. by rewrite !inE; apply: andP. Qed.
End MorphismStructure.
Notation "{ 'morphism' D >-> T }" := (morphism_for D (Phant T))
(format "{ 'morphism' D >-> T }") : type_scope.
Notation "[ 'morphism' D 'of' f ]" :=
(@clone_morphism _ _ D _ (fun fM => @Morphism _ _ D f fM))
(format "[ 'morphism' D 'of' f ]") : form_scope.
Notation "[ 'morphism' 'of' f ]" := (clone_morphism (@Morphism _ _ _ f))
(format "[ 'morphism' 'of' f ]") : form_scope.
Arguments morphimP {aT rT D A y f}.
Arguments morphpreP {aT rT D R x f}.
(* Domain, image, preimage, kernel, using phantom types to infer the domain. *)
Section MorphismOps1.
Variables (aT rT : finGroupType) (D : {set aT}) (f : {morphism D >-> rT}).
Lemma morphM : {in D &, {morph f : x y / x * y}}.
Proof. by case f. Qed.
Notation morPhantom := (phantom (aT -> rT)).
Definition MorPhantom := Phantom (aT -> rT).
Definition dom of morPhantom f := D.
Definition morphim of morPhantom f := fun A => f @: (D :&: A).
Definition morphpre of morPhantom f := fun R : {set rT} => D :&: f @^-1: R.
Definition ker mph := morphpre mph 1.
End MorphismOps1.
Arguments morphim _ _ _%_g _ _ _%_g.
Arguments morphpre _ _ _%_g _ _ _%_g.
Notation "''dom' f" := (dom (MorPhantom f))
(at level 10, f at level 8, format "''dom' f") : group_scope.
Notation "''ker' f" := (ker (MorPhantom f))
(at level 10, f at level 8, format "''ker' f") : group_scope.
Notation "''ker_' H f" := (H :&: 'ker f)
(at level 10, H at level 2, f at level 8, format "''ker_' H f")
: group_scope.
Notation "f @* A" := (morphim (MorPhantom f) A)
(at level 24, format "f @* A") : group_scope.
Notation "f @*^-1 R" := (morphpre (MorPhantom f) R)
(at level 24, format "f @*^-1 R") : group_scope.
Notation "''injm' f" := (pred_of_set ('ker f) \subset pred_of_set 1)
(at level 10, f at level 8, format "''injm' f") : group_scope.
Section MorphismTheory.
Variables aT rT : finGroupType.
Implicit Types A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Types R S : {set rT}.
Implicit Types M : {group rT}.
(* Most properties of morphims hold only when the domain is a group. *)
Variables (D : {group aT}) (f : {morphism D >-> rT}).
Lemma morph1 : f 1 = 1.
Proof. by apply: (mulgI (f 1)); rewrite -morphM ?mulg1. Qed.
Lemma morph_prod I r (P : pred I) F :
(forall i, P i -> F i \in D) ->
f (\prod_(i <- r | P i) F i) = \prod_( i <- r | P i) f (F i).
Proof.
move=> D_F; elim/(big_load (fun x => x \in D)): _.
elim/big_rec2: _ => [|i _ x Pi [Dx <-]]; first by rewrite morph1.
by rewrite groupM ?morphM // D_F.
Qed.
Lemma morphV : {in D, {morph f : x / x^-1}}.
Proof.
move=> x Dx; apply: (mulgI (f x)).
by rewrite -morphM ?groupV // !mulgV morph1.
Qed.
Lemma morphJ : {in D &, {morph f : x y / x ^ y}}.
Proof. by move=> * /=; rewrite !morphM ?morphV // ?groupM ?groupV. Qed.
Lemma morphX n : {in D, {morph f : x / x ^+ n}}.
Proof.
by elim: n => [|n IHn] x Dx; rewrite ?morph1 // !expgS morphM ?(groupX, IHn).
Qed.
Lemma morphR : {in D &, {morph f : x y / [~ x, y]}}.
Proof. by move=> * /=; rewrite morphM ?(groupV, groupJ) // morphJ ?morphV. Qed.
(* Morphic image, preimage properties w.r.t. set-theoretic operations. *)
Lemma morphimE A : f @* A = f @: (D :&: A). Proof. by []. Qed.
Lemma morphpreE R : f @*^-1 R = D :&: f @^-1: R. Proof. by []. Qed.
Lemma kerE : 'ker f = f @*^-1 1. Proof. by []. Qed.
Lemma morphimEsub A : A \subset D -> f @* A = f @: A.
Proof. by move=> sAD; rewrite /morphim (setIidPr sAD). Qed.
Lemma morphimEdom : f @* D = f @: D.
Proof. exact: morphimEsub. Qed.
Lemma morphimIdom A : f @* (D :&: A) = f @* A.
Proof. by rewrite /morphim setIA setIid. Qed.
Lemma morphpreIdom R : D :&: f @*^-1 R = f @*^-1 R.
Proof. by rewrite /morphim setIA setIid. Qed.
Lemma morphpreIim R : f @*^-1 (f @* D :&: R) = f @*^-1 R.
Proof.
apply/setP=> x; rewrite morphimEdom !inE.
by case Dx: (x \in D); rewrite // imset_f.
Qed.
Lemma morphimIim A : f @* D :&: f @* A = f @* A.
Proof. by apply/setIidPr; rewrite imsetS // setIid subsetIl. Qed.
Lemma mem_morphim A x : x \in D -> x \in A -> f x \in f @* A.
Proof. by move=> Dx Ax; apply/morphimP; exists x. Qed.
Lemma mem_morphpre R x : x \in D -> f x \in R -> x \in f @*^-1 R.
Proof. by move=> Dx Rfx; apply/morphpreP. Qed.
Lemma morphimS A B : A \subset B -> f @* A \subset f @* B.
Proof. by move=> sAB; rewrite imsetS ?setIS. Qed.
Lemma morphim_sub A : f @* A \subset f @* D.
Proof. by rewrite imsetS // setIid subsetIl. Qed.
Lemma leq_morphim A : #|f @* A| <= #|A|.
Proof.
by apply: (leq_trans (leq_imset_card _ _)); rewrite subset_leq_card ?subsetIr.
Qed.
Lemma morphpreS R S : R \subset S -> f @*^-1 R \subset f @*^-1 S.
Proof. by move=> sRS; rewrite setIS ?preimsetS. Qed.
Lemma morphpre_sub R : f @*^-1 R \subset D.
Proof. exact: subsetIl. Qed.
Lemma morphim_setIpre A R : f @* (A :&: f @*^-1 R) = f @* A :&: R.
Proof.
apply/setP=> fa; apply/morphimP/setIP=> [[a Da] | [/morphimP[a Da Aa ->] Rfa]].
by rewrite !inE Da /= => /andP[Aa Rfa] ->; rewrite mem_morphim.
by exists a; rewrite // !inE Aa Da.
Qed.
Lemma morphim0 : f @* set0 = set0.
Proof. by rewrite morphimE setI0 imset0. Qed.
Lemma morphim_eq0 A : A \subset D -> (f @* A == set0) = (A == set0).
Proof. by rewrite imset_eq0 => /setIidPr->. Qed.
Lemma morphim_set1 x : x \in D -> f @* [set x] = [set f x].
Proof. by rewrite /morphim -sub1set => /setIidPr->; apply: imset_set1. Qed.
Lemma morphim1 : f @* 1 = 1.
Proof. by rewrite morphim_set1 ?morph1. Qed.
Lemma morphimV A : f @* A^-1 = (f @* A)^-1.
Proof.
wlog suffices: A / f @* A^-1 \subset (f @* A)^-1.
by move=> IH; apply/eqP; rewrite eqEsubset IH -invSg invgK -{1}(invgK A) IH.
apply/subsetP=> _ /morphimP[x Dx Ax' ->]; rewrite !inE in Ax' *.
by rewrite -morphV // imset_f // inE groupV Dx.
Qed.
Lemma morphpreV R : f @*^-1 R^-1 = (f @*^-1 R)^-1.
Proof.
apply/setP=> x; rewrite !inE groupV; case Dx: (x \in D) => //=.
by rewrite morphV.
Qed.
Lemma morphimMl A B : A \subset D -> f @* (A * B) = f @* A * f @* B.
Proof.
move=> sAD; rewrite /morphim setIC -group_modl // (setIidPr sAD).
apply/setP=> fxy; apply/idP/idP.
case/imsetP=> _ /imset2P[x y Ax /setIP[Dy By] ->] ->{fxy}.
by rewrite morphM // (subsetP sAD, imset2_f) // imset_f // inE By.
case/imset2P=> _ _ /imsetP[x Ax ->] /morphimP[y Dy By ->] ->{fxy}.
by rewrite -morphM // (subsetP sAD, imset_f) // mem_mulg // inE By.
Qed.
Lemma morphimMr A B : B \subset D -> f @* (A * B) = f @* A * f @* B.
Proof.
move=> sBD; apply: invg_inj.
by rewrite invMg -!morphimV invMg morphimMl // -invGid invSg.
Qed.
Lemma morphpreMl R S :
R \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S.
Proof.
move=> sRfD; apply/setP=> x; rewrite !inE.
apply/andP/imset2P=> [[Dx] | [y z]]; last first.
rewrite !inE => /andP[Dy Rfy] /andP[Dz Rfz] ->.
by rewrite ?(groupM, morphM, imset2_f).
case/imset2P=> fy fz Rfy Rfz def_fx.
have /morphimP[y Dy _ def_fy]: fy \in f @* D := subsetP sRfD fy Rfy.
exists y (y^-1 * x); last by rewrite mulKVg.
by rewrite !inE Dy -def_fy.
by rewrite !inE groupM ?(morphM, morphV, groupV) // def_fx -def_fy mulKg.
Qed.
Lemma morphimJ A x : x \in D -> f @* (A :^ x) = f @* A :^ f x.
Proof.
move=> Dx; rewrite !conjsgE morphimMl ?(morphimMr, sub1set, groupV) //.
by rewrite !(morphim_set1, groupV, morphV).
Qed.
Lemma morphpreJ R x : x \in D -> f @*^-1 (R :^ f x) = f @*^-1 R :^ x.
Proof.
move=> Dx; apply/setP=> y; rewrite conjIg !inE conjGid // !mem_conjg inE.
by case Dy: (y \in D); rewrite // morphJ ?(morphV, groupV).
Qed.
Lemma morphim_class x A :
x \in D -> A \subset D -> f @* (x ^: A) = f x ^: f @* A.
Proof.
move=> Dx sAD; rewrite !morphimEsub ?class_subG // /class -!imset_comp.
by apply: eq_in_imset => y Ay /=; rewrite morphJ // (subsetP sAD).
Qed.
Lemma classes_morphim A :
A \subset D -> classes (f @* A) = [set f @* xA | xA in classes A].
Proof.
move=> sAD; rewrite morphimEsub // /classes -!imset_comp.
apply: eq_in_imset => x /(subsetP sAD) Dx /=.
by rewrite morphim_class ?morphimEsub.
Qed.
Lemma morphimT : f @* setT = f @* D.
Proof. by rewrite -morphimIdom setIT. Qed.
Lemma morphimU A B : f @* (A :|: B) = f @* A :|: f @* B.
Proof. by rewrite -imsetU -setIUr. Qed.
Lemma morphimI A B : f @* (A :&: B) \subset f @* A :&: f @* B.
Proof. by rewrite subsetI // ?morphimS ?(subsetIl, subsetIr). Qed.
Lemma morphpre0 : f @*^-1 set0 = set0.
Proof. by rewrite morphpreE preimset0 setI0. Qed.
Lemma morphpreT : f @*^-1 setT = D.
Proof. by rewrite morphpreE preimsetT setIT. Qed.
Lemma morphpreU R S : f @*^-1 (R :|: S) = f @*^-1 R :|: f @*^-1 S.
Proof. by rewrite -setIUr -preimsetU. Qed.
Lemma morphpreI R S : f @*^-1 (R :&: S) = f @*^-1 R :&: f @*^-1 S.
Proof. by rewrite -setIIr -preimsetI. Qed.
Lemma morphpreD R S : f @*^-1 (R :\: S) = f @*^-1 R :\: f @*^-1 S.
Proof. by apply/setP=> x /[!inE]; case: (x \in D). Qed.
(* kernel, domain properties *)
Lemma kerP x : x \in D -> reflect (f x = 1) (x \in 'ker f).
Proof. by move=> Dx; rewrite 2!inE Dx; apply: set1P. Qed.
Lemma dom_ker : {subset 'ker f <= D}.
Proof. by move=> x /morphpreP[]. Qed.
Lemma mker x : x \in 'ker f -> f x = 1.
Proof. by move=> Kx; apply/kerP=> //; apply: dom_ker. Qed.
Lemma mkerl x y : x \in 'ker f -> y \in D -> f (x * y) = f y.
Proof. by move=> Kx Dy; rewrite morphM // ?(dom_ker, mker Kx, mul1g). Qed.
Lemma mkerr x y : x \in D -> y \in 'ker f -> f (x * y) = f x.
Proof. by move=> Dx Ky; rewrite morphM // ?(dom_ker, mker Ky, mulg1). Qed.
Lemma rcoset_kerP x y :
x \in D -> y \in D -> reflect (f x = f y) (x \in 'ker f :* y).
Proof.
move=> Dx Dy; rewrite mem_rcoset !inE groupM ?morphM ?groupV //=.
by rewrite morphV // -eq_mulgV1; apply: eqP.
Qed.
Lemma ker_rcoset x y :
x \in D -> y \in D -> f x = f y -> exists2 z, z \in 'ker f & x = z * y.
Proof. by move=> Dx Dy eqfxy; apply/rcosetP; apply/rcoset_kerP. Qed.
Lemma ker_norm : D \subset 'N('ker f).
Proof.
apply/subsetP=> x Dx /[1!inE]; apply/subsetP=> _ /imsetP[y Ky ->].
by rewrite !inE groupJ ?morphJ // ?dom_ker //= mker ?conj1g.
Qed.
Lemma ker_normal : 'ker f <| D.
Proof. by rewrite /(_ <| D) subsetIl ker_norm. Qed.
Lemma morphimGI G A : 'ker f \subset G -> f @* (G :&: A) = f @* G :&: f @* A.
Proof.
move=> sKG; apply/eqP; rewrite eqEsubset morphimI setIC.
apply/subsetP=> _ /setIP[/morphimP[x Dx Ax ->] /morphimP[z Dz Gz]].
case/ker_rcoset=> {Dz}// y Ky def_x.
have{z Gz y Ky def_x} Gx: x \in G by rewrite def_x groupMl // (subsetP sKG).
by rewrite imset_f ?inE // Dx Gx Ax.
Qed.
Lemma morphimIG A G : 'ker f \subset G -> f @* (A :&: G) = f @* A :&: f @* G.
Proof. by move=> sKG; rewrite setIC morphimGI // setIC. Qed.
Lemma morphimD A B : f @* A :\: f @* B \subset f @* (A :\: B).
Proof.
rewrite subDset -morphimU morphimS //.
by rewrite setDE setUIr setUCr setIT subsetUr.
Qed.
Lemma morphimDG A G : 'ker f \subset G -> f @* (A :\: G) = f @* A :\: f @* G.
Proof.
move=> sKG; apply/eqP; rewrite eqEsubset morphimD andbT !setDE subsetI.
rewrite morphimS ?subsetIl // -[~: f @* G]setU0 -subDset setDE setCK.
by rewrite -morphimIG //= setIAC -setIA setICr setI0 morphim0.
Qed.
Lemma morphimD1 A : (f @* A)^# \subset f @* A^#.
Proof. by rewrite -!set1gE -morphim1 morphimD. Qed.
(* group structure preservation *)
Lemma morphpre_groupset M : group_set (f @*^-1 M).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?(morph1, group1) //.
by case/andP=> Dx Mfx /andP[Dy Mfy]; rewrite morphM ?groupM.
Qed.
Lemma morphim_groupset G : group_set (f @* G).
Proof.
apply/group_setP; split=> [|_ _ /morphimP[x Dx Gx ->] /morphimP[y Dy Gy ->]].
by rewrite -morph1 imset_f ?group1.
by rewrite -morphM ?imset_f ?inE ?groupM.
Qed.
Canonical morphpre_group fPh M :=
@group _ (morphpre fPh M) (morphpre_groupset M).
Canonical morphim_group fPh G := @group _ (morphim fPh G) (morphim_groupset G).
Canonical ker_group fPh : {group aT} := Eval hnf in [group of ker fPh].
Lemma morph_dom_groupset : group_set (f @: D).
Proof. by rewrite -morphimEdom groupP. Qed.
Canonical morph_dom_group := group morph_dom_groupset.
Lemma morphpreMr R S :
S \subset f @* D -> f @*^-1 (R * S) = f @*^-1 R * f @*^-1 S.
Proof.
move=> sSfD; apply: invg_inj.
by rewrite invMg -!morphpreV invMg morphpreMl // -invSg invgK invGid.
Qed.
Lemma morphimK A : A \subset D -> f @*^-1 (f @* A) = 'ker f * A.
Proof.
move=> sAD; apply/setP=> x; rewrite !inE.
apply/idP/idP=> [/andP[Dx /morphimP[y Dy Ay eqxy]] | /imset2P[z y Kz Ay ->{x}]].
rewrite -(mulgKV y x) mem_mulg // !inE !(groupM, morphM, groupV) //.
by rewrite morphV //= eqxy mulgV.
have [Dy Dz]: y \in D /\ z \in D by rewrite (subsetP sAD) // dom_ker.
by rewrite groupM // morphM // mker // mul1g imset_f // inE Dy.
Qed.
Lemma morphimGK G : 'ker f \subset G -> G \subset D -> f @*^-1 (f @* G) = G.
Proof. by move=> sKG sGD; rewrite morphimK // mulSGid. Qed.
Lemma morphpre_set1 x : x \in D -> f @*^-1 [set f x] = 'ker f :* x.
Proof. by move=> Dx; rewrite -morphim_set1 // morphimK ?sub1set. Qed.
Lemma morphpreK R : R \subset f @* D -> f @* (f @*^-1 R) = R.
Proof.
move=> sRfD; apply/setP=> y; apply/morphimP/idP=> [[x _] | Ry].
by rewrite !inE; case/andP=> _ Rfx ->.
have /morphimP[x Dx _ defy]: y \in f @* D := subsetP sRfD y Ry.
by exists x; rewrite // !inE Dx -defy.
Qed.
Lemma morphim_ker : f @* 'ker f = 1.
Proof. by rewrite morphpreK ?sub1G. Qed.
Lemma ker_sub_pre M : 'ker f \subset f @*^-1 M.
Proof. by rewrite morphpreS ?sub1G. Qed.
Lemma ker_normal_pre M : 'ker f <| f @*^-1 M.
Proof. by rewrite /normal ker_sub_pre subIset ?ker_norm. Qed.
Lemma morphpreSK R S :
R \subset f @* D -> (f @*^-1 R \subset f @*^-1 S) = (R \subset S).
Proof.
move=> sRfD; apply/idP/idP=> [sf'RS|]; last exact: morphpreS.
suffices: R \subset f @* D :&: S by rewrite subsetI sRfD.
rewrite -(morphpreK sRfD) -[_ :&: S]morphpreK (morphimS, subsetIl) //.
by rewrite morphpreI morphimGK ?subsetIl // setIA setIid.
Qed.
Lemma sub_morphim_pre A R :
A \subset D -> (f @* A \subset R) = (A \subset f @*^-1 R).
Proof.
move=> sAD; rewrite -morphpreSK (morphimS, morphimK) //.
apply/idP/idP; first by apply: subset_trans; apply: mulG_subr.
by move/(mulgS ('ker f)); rewrite -morphpreMl ?(sub1G, mul1g).
Qed.
Lemma morphpre_proper R S :
R \subset f @* D -> S \subset f @* D ->
(f @*^-1 R \proper f @*^-1 S) = (R \proper S).
Proof. by move=> dQ dR; rewrite /proper !morphpreSK. Qed.
Lemma sub_morphpre_im R G :
'ker f \subset G -> G \subset D -> R \subset f @* D ->
(f @*^-1 R \subset G) = (R \subset f @* G).
Proof. by symmetry; rewrite -morphpreSK ?morphimGK. Qed.
Lemma ker_trivg_morphim A :
(A \subset 'ker f) = (A \subset D) && (f @* A \subset [1]).
Proof.
case sAD: (A \subset D); first by rewrite sub_morphim_pre.
by rewrite subsetI sAD.
Qed.
Lemma morphimSK A B :
A \subset D -> (f @* A \subset f @* B) = (A \subset 'ker f * B).
Proof.
move=> sAD; transitivity (A \subset 'ker f * (D :&: B)).
by rewrite -morphimK ?subsetIl // -sub_morphim_pre // /morphim setIA setIid.
by rewrite setIC group_modl (subsetIl, subsetI) // andbC sAD.
Qed.
Lemma morphimSGK A G :
A \subset D -> 'ker f \subset G -> (f @* A \subset f @* G) = (A \subset G).
Proof. by move=> sGD skfK; rewrite morphimSK // mulSGid. Qed.
Lemma ltn_morphim A : [1] \proper 'ker_A f -> #|f @* A| < #|A|.
Proof.
case/properP; rewrite sub1set => /setIP[A1 _] [x /setIP[Ax kx] x1].
rewrite (cardsD1 1 A) A1 ltnS -{1}(setD1K A1) morphimU morphim1.
rewrite (setUidPr _) ?sub1set; last first.
by rewrite -(mker kx) mem_morphim ?(dom_ker kx) // inE x1.
by rewrite (leq_trans (leq_imset_card _ _)) ?subset_leq_card ?subsetIr.
Qed.
(* injectivity of image and preimage *)
Lemma morphpre_inj :
{in [pred R : {set rT} | R \subset f @* D] &, injective (fun R => f @*^-1 R)}.
Proof. exact: can_in_inj morphpreK. Qed.
Lemma morphim_injG :
{in [pred G : {group aT} | 'ker f \subset G & G \subset D] &,
injective (fun G => f @* G)}.
Proof.
move=> G H /andP[sKG sGD] /andP[sKH sHD] eqfGH.
by apply: val_inj; rewrite /= -(morphimGK sKG sGD) eqfGH morphimGK.
Qed.
Lemma morphim_inj G H :
('ker f \subset G) && (G \subset D) ->
('ker f \subset H) && (H \subset D) ->
f @* G = f @* H -> G :=: H.
Proof. by move=> nsGf nsHf /morphim_injG->. Qed.
(* commutation with generated groups and cycles *)
Lemma morphim_gen A : A \subset D -> f @* <<A>> = <<f @* A>>.
Proof.
move=> sAD; apply/eqP.
rewrite eqEsubset andbC gen_subG morphimS; last exact: subset_gen.
by rewrite sub_morphim_pre gen_subG // -sub_morphim_pre // subset_gen.
Qed.
Lemma morphim_cycle x : x \in D -> f @* <[x]> = <[f x]>.
Proof. by move=> Dx; rewrite morphim_gen (sub1set, morphim_set1). Qed.
Lemma morphimY A B :
A \subset D -> B \subset D -> f @* (A <*> B) = f @* A <*> f @* B.
Proof. by move=> sAD sBD; rewrite morphim_gen ?morphimU // subUset sAD. Qed.
Lemma morphpre_gen R :
1 \in R -> R \subset f @* D -> f @*^-1 <<R>> = <<f @*^-1 R>>.
Proof.
move=> R1 sRfD; apply/eqP.
rewrite eqEsubset andbC gen_subG morphpreS; last exact: subset_gen.
rewrite -{1}(morphpreK sRfD) -morphim_gen ?subsetIl // morphimGK //=.
by rewrite sub_gen // setIS // preimsetS ?sub1set.
by rewrite gen_subG subsetIl.
Qed.
(* commutator, normaliser, normal, center properties*)
Lemma morphimR A B :
A \subset D -> B \subset D -> f @* [~: A, B] = [~: f @* A, f @* B].
Proof.
move/subsetP=> sAD /subsetP sBD.
rewrite morphim_gen; last first; last congr <<_>>.
by apply/subsetP=> _ /imset2P[x y Ax By ->]; rewrite groupR; auto.
apply/setP=> fz; apply/morphimP/imset2P=> [[z _] | [fx fy]].
case/imset2P=> x y Ax By -> -> {z fz}.
have Dx := sAD x Ax; have Dy := sBD y By.
by exists (f x) (f y); rewrite ?(imset_f, morphR) // ?(inE, Dx, Dy).
case/morphimP=> x Dx Ax ->{fx}; case/morphimP=> y Dy By ->{fy} -> {fz}.
by exists [~ x, y]; rewrite ?(inE, morphR, groupR, imset2_f).
Qed.
Lemma morphim_norm A : f @* 'N(A) \subset 'N(f @* A).
Proof.
apply/subsetP=> fx; case/morphimP=> x Dx Nx -> {fx}.
by rewrite inE -morphimJ ?(normP Nx).
Qed.
Lemma morphim_norms A B : A \subset 'N(B) -> f @* A \subset 'N(f @* B).
Proof.
by move=> nBA; apply: subset_trans (morphim_norm B); apply: morphimS.
Qed.
Lemma morphim_subnorm A B : f @* 'N_A(B) \subset 'N_(f @* A)(f @* B).
Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_norm B)). Qed.
Lemma morphim_normal A B : A <| B -> f @* A <| f @* B.
Proof. by case/andP=> sAB nAB; rewrite /(_ <| _) morphimS // morphim_norms. Qed.
Lemma morphim_cent1 x : x \in D -> f @* 'C[x] \subset 'C[f x].
Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_norm. Qed.
Lemma morphim_cent1s A x : x \in D -> A \subset 'C[x] -> f @* A \subset 'C[f x].
Proof.
by move=> Dx cAx; apply: subset_trans (morphim_cent1 Dx); apply: morphimS.
Qed.
Lemma morphim_subcent1 A x : x \in D -> f @* 'C_A[x] \subset 'C_(f @* A)[f x].
Proof. by move=> Dx; rewrite -(morphim_set1 Dx) morphim_subnorm. Qed.
Lemma morphim_cent A : f @* 'C(A) \subset 'C(f @* A).
Proof.
apply/bigcapsP=> fx; case/morphimP=> x Dx Ax ->{fx}.
by apply: subset_trans (morphim_cent1 Dx); apply: morphimS; apply: bigcap_inf.
Qed.
Lemma morphim_cents A B : A \subset 'C(B) -> f @* A \subset 'C(f @* B).
Proof.
by move=> cBA; apply: subset_trans (morphim_cent B); apply: morphimS.
Qed.
Lemma morphim_subcent A B : f @* 'C_A(B) \subset 'C_(f @* A)(f @* B).
Proof. exact: subset_trans (morphimI A _) (setIS _ (morphim_cent B)). Qed.
Lemma morphim_abelian A : abelian A -> abelian (f @* A).
Proof. exact: morphim_cents. Qed.
Lemma morphpre_norm R : f @*^-1 'N(R) \subset 'N(f @*^-1 R).
Proof.
by apply/subsetP=> x /[!inE] /andP[Dx Nfx]; rewrite -morphpreJ ?morphpreS.
Qed.
Lemma morphpre_norms R S : R \subset 'N(S) -> f @*^-1 R \subset 'N(f @*^-1 S).
Proof.
by move=> nSR; apply: subset_trans (morphpre_norm S); apply: morphpreS.
Qed.
Lemma morphpre_normal R S :
R \subset f @* D -> S \subset f @* D -> (f @*^-1 R <| f @*^-1 S) = (R <| S).
Proof.
move=> sRfD sSfD; apply/idP/andP=> [|[sRS nSR]].
by move/morphim_normal; rewrite !morphpreK //; case/andP.
by rewrite /(_ <| _) (subset_trans _ (morphpre_norm _)) morphpreS.
Qed.
Lemma morphpre_subnorm R S : f @*^-1 'N_R(S) \subset 'N_(f @*^-1 R)(f @*^-1 S).
Proof. by rewrite morphpreI setIS ?morphpre_norm. Qed.
Lemma morphim_normG G :
'ker f \subset G -> G \subset D -> f @* 'N(G) = 'N_(f @* D)(f @* G).
Proof.
move=> sKG sGD; apply/eqP; rewrite eqEsubset -{1}morphimIdom morphim_subnorm.
rewrite -(morphpreK (subsetIl _ _)) morphimS //= morphpreI subIset // orbC.
by rewrite -{2}(morphimGK sKG sGD) morphpre_norm.
Qed.
Lemma morphim_subnormG A G :
'ker f \subset G -> G \subset D -> f @* 'N_A(G) = 'N_(f @* A)(f @* G).
Proof.
move=> sKB sBD; rewrite morphimIG ?normsG // morphim_normG //.
by rewrite setICA setIA morphimIim.
Qed.
Lemma morphpre_cent1 x : x \in D -> 'C_D[x] \subset f @*^-1 'C[f x].
Proof.
move=> Dx; rewrite -sub_morphim_pre ?subsetIl //.
by apply: subset_trans (morphim_cent1 Dx); rewrite morphimS ?subsetIr.
Qed.
Lemma morphpre_cent1s R x :
x \in D -> R \subset f @* D -> f @*^-1 R \subset 'C[x] -> R \subset 'C[f x].
Proof. by move=> Dx sRfD; move/(morphim_cent1s Dx); rewrite morphpreK. Qed.
Lemma morphpre_subcent1 R x :
x \in D -> 'C_(f @*^-1 R)[x] \subset f @*^-1 'C_R[f x].
Proof.
move=> Dx; rewrite -morphpreIdom -setIA setICA morphpreI setIS //.
exact: morphpre_cent1.
Qed.
Lemma morphpre_cent A : 'C_D(A) \subset f @*^-1 'C(f @* A).
Proof.
rewrite -sub_morphim_pre ?subsetIl // morphimGI ?(subsetIl, subIset) // orbC.
by rewrite (subset_trans (morphim_cent _)).
Qed.
Lemma morphpre_cents A R :
R \subset f @* D -> f @*^-1 R \subset 'C(A) -> R \subset 'C(f @* A).
Proof. by move=> sRfD; move/morphim_cents; rewrite morphpreK. Qed.
Lemma morphpre_subcent R A : 'C_(f @*^-1 R)(A) \subset f @*^-1 'C_R(f @* A).
Proof.
by rewrite -morphpreIdom -setIA setICA morphpreI setIS //; apply: morphpre_cent.
Qed.
(* local injectivity properties *)
Lemma injmP : reflect {in D &, injective f} ('injm f).
Proof.
apply: (iffP subsetP) => [injf x y Dx Dy | injf x /= Kx].
by case/ker_rcoset=> // z /injf/set1P->; rewrite mul1g.
have Dx := dom_ker Kx; apply/set1P/injf => //.
by apply/rcoset_kerP; rewrite // mulg1.
Qed.
Lemma card_im_injm : (#|f @* D| == #|D|) = 'injm f.
Proof. by rewrite morphimEdom (sameP imset_injP injmP). Qed.
Section Injective.
Hypothesis injf : 'injm f.
Lemma ker_injm : 'ker f = 1.
Proof. exact/trivgP. Qed.
Lemma injmK A : A \subset D -> f @*^-1 (f @* A) = A.
Proof. by move=> sAD; rewrite morphimK // ker_injm // mul1g. Qed.
Lemma injm_morphim_inj A B :
A \subset D -> B \subset D -> f @* A = f @* B -> A = B.
Proof. by move=> sAD sBD eqAB; rewrite -(injmK sAD) eqAB injmK. Qed.
Lemma card_injm A : A \subset D -> #|f @* A| = #|A|.
Proof.
move=> sAD; rewrite morphimEsub // card_in_imset //.
exact: (sub_in2 (subsetP sAD) (injmP injf)).
Qed.
Lemma order_injm x : x \in D -> #[f x] = #[x].
Proof.
by move=> Dx; rewrite orderE -morphim_cycle // card_injm ?cycle_subG.
Qed.
Lemma injm1 x : x \in D -> f x = 1 -> x = 1.
Proof. by move=> Dx; move/(kerP Dx); rewrite ker_injm; move/set1P. Qed.
Lemma morph_injm_eq1 x : x \in D -> (f x == 1) = (x == 1).
Proof. by move=> Dx; rewrite -morph1 (inj_in_eq (injmP injf)) ?group1. Qed.
Lemma injmSK A B :
A \subset D -> (f @* A \subset f @* B) = (A \subset B).
Proof. by move=> sAD; rewrite morphimSK // ker_injm mul1g. Qed.
Lemma sub_morphpre_injm R A :
A \subset D -> R \subset f @* D ->
(f @*^-1 R \subset A) = (R \subset f @* A).
Proof. by move=> sAD sRfD; rewrite -morphpreSK ?injmK. Qed.
Lemma injm_eq A B : A \subset D -> B \subset D -> (f @* A == f @* B) = (A == B).
Proof. by move=> sAD sBD; rewrite !eqEsubset !injmSK. Qed.
Lemma morphim_injm_eq1 A : A \subset D -> (f @* A == 1) = (A == 1).
Proof. by move=> sAD; rewrite -morphim1 injm_eq ?sub1G. Qed.
Lemma injmI A B : f @* (A :&: B) = f @* A :&: f @* B.
Proof.
rewrite -morphimIdom setIIr -4!(injmK (subsetIl D _), =^~ morphimIdom).
by rewrite -morphpreI morphpreK // subIset ?morphim_sub.
Qed.
Lemma injmD1 A : f @* A^# = (f @* A)^#.
Proof. by have:= morphimDG A injf; rewrite morphim1. Qed.
Lemma nclasses_injm A : A \subset D -> #|classes (f @* A)| = #|classes A|.
Proof.
move=> sAD; rewrite classes_morphim // card_in_imset //.
move=> _ _ /imsetP[x Ax ->] /imsetP[y Ay ->].
by apply: injm_morphim_inj; rewrite // class_subG ?(subsetP sAD).
Qed.
Lemma injm_norm A : A \subset D -> f @* 'N(A) = 'N_(f @* D)(f @* A).
Proof.
move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subnorm.
rewrite -sub_morphpre_injm ?subsetIl // morphpreI injmK // setIS //.
by rewrite -{2}(injmK sAD) morphpre_norm.
Qed.
Lemma injm_norms A B :
A \subset D -> B \subset D -> (f @* A \subset 'N(f @* B)) = (A \subset 'N(B)).
Proof. by move=> sAD sBD; rewrite -injmSK // injm_norm // subsetI morphimS. Qed.
Lemma injm_normal A B :
A \subset D -> B \subset D -> (f @* A <| f @* B) = (A <| B).
Proof. by move=> sAD sBD; rewrite /normal injmSK ?injm_norms. Qed.
Lemma injm_subnorm A B : B \subset D -> f @* 'N_A(B) = 'N_(f @* A)(f @* B).
Proof. by move=> sBD; rewrite injmI injm_norm // setICA setIA morphimIim. Qed.
Lemma injm_cent1 x : x \in D -> f @* 'C[x] = 'C_(f @* D)[f x].
Proof. by move=> Dx; rewrite injm_norm ?morphim_set1 ?sub1set. Qed.
Lemma injm_subcent1 A x : x \in D -> f @* 'C_A[x] = 'C_(f @* A)[f x].
Proof. by move=> Dx; rewrite injm_subnorm ?morphim_set1 ?sub1set. Qed.
Lemma injm_cent A : A \subset D -> f @* 'C(A) = 'C_(f @* D)(f @* A).
Proof.
move=> sAD; apply/eqP; rewrite -morphimIdom eqEsubset morphim_subcent.
apply/subsetP=> fx; case/setIP; case/morphimP=> x Dx _ ->{fx} cAfx.
rewrite mem_morphim // inE Dx -sub1set centsC cent_set1 -injmSK //.
by rewrite injm_cent1 // subsetI morphimS // -cent_set1 centsC sub1set.
Qed.
Lemma injm_cents A B :
A \subset D -> B \subset D -> (f @* A \subset 'C(f @* B)) = (A \subset 'C(B)).
Proof. by move=> sAD sBD; rewrite -injmSK // injm_cent // subsetI morphimS. Qed.
Lemma injm_subcent A B : B \subset D -> f @* 'C_A(B) = 'C_(f @* A)(f @* B).
Proof. by move=> sBD; rewrite injmI injm_cent // setICA setIA morphimIim. Qed.
Lemma injm_abelian A : A \subset D -> abelian (f @* A) = abelian A.
Proof.
by move=> sAD; rewrite /abelian -subsetIidl -injm_subcent // injmSK ?subsetIidl.
Qed.
End Injective.
Lemma eq_morphim (g : {morphism D >-> rT}):
{in D, f =1 g} -> forall A, f @* A = g @* A.
Proof.
by move=> efg A; apply: eq_in_imset; apply: sub_in1 efg => x /setIP[].
Qed.
Lemma eq_in_morphim B A (g : {morphism B >-> rT}) :
D :&: A = B :&: A -> {in A, f =1 g} -> f @* A = g @* A.
Proof.
move=> eqDBA eqAfg; rewrite /morphim /= eqDBA.
by apply: eq_in_imset => x /setIP[_]/eqAfg.
Qed.
End MorphismTheory.
Notation "''ker' f" := (ker_group (MorPhantom f)) : Group_scope.
Notation "''ker_' G f" := (G :&: 'ker f)%G : Group_scope.
Notation "f @* G" := (morphim_group (MorPhantom f) G) : Group_scope.
Notation "f @*^-1 M" := (morphpre_group (MorPhantom f) M) : Group_scope.
Notation "f @: D" := (morph_dom_group f D) : Group_scope.
Arguments injmP {aT rT D f}.
Arguments morphpreK {aT rT D f} [R] sRf.
Section IdentityMorphism.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Type G : {group gT}.
Definition idm of {set gT} := fun x : gT => x : FinGroup.sort gT.
Lemma idm_morphM A : {in A & , {morph idm A : x y / x * y}}.
Proof. by []. Qed.
Canonical idm_morphism A := Morphism (@idm_morphM A).
Lemma injm_idm G : 'injm (idm G).
Proof. by apply/injmP=> x y _ _. Qed.
Lemma ker_idm G : 'ker (idm G) = 1.
Proof. by apply/trivgP; apply: injm_idm. Qed.
Lemma morphim_idm A B : B \subset A -> idm A @* B = B.
Proof.
rewrite /morphim /= /idm => /setIidPr->.
by apply/setP=> x; apply/imsetP/idP=> [[y By ->]|Bx]; last exists x.
Qed.
Lemma morphpre_idm A B : idm A @*^-1 B = A :&: B.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma im_idm A : idm A @* A = A.
Proof. exact: morphim_idm. Qed.
End IdentityMorphism.
Arguments idm {_} _%_g _%_g.
Section RestrictedMorphism.
Variables aT rT : finGroupType.
Variables A D : {set aT}.
Implicit Type B : {set aT}.
Implicit Type R : {set rT}.
Definition restrm of A \subset D := @id (aT -> FinGroup.sort rT).
Section Props.
Hypothesis sAD : A \subset D.
Variable f : {morphism D >-> rT}.
Local Notation fA := (restrm sAD (mfun f)).
Canonical restrm_morphism :=
@Morphism aT rT A fA (sub_in2 (subsetP sAD) (morphM f)).
Lemma morphim_restrm B : fA @* B = f @* (A :&: B).
Proof. by rewrite {2}/morphim setIA (setIidPr sAD). Qed.
Lemma restrmEsub B : B \subset A -> fA @* B = f @* B.
Proof. by rewrite morphim_restrm => /setIidPr->. Qed.
Lemma im_restrm : fA @* A = f @* A.
Proof. exact: restrmEsub. Qed.
Lemma morphpre_restrm R : fA @*^-1 R = A :&: f @*^-1 R.
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma ker_restrm : 'ker fA = 'ker_A f.
Proof. exact: morphpre_restrm. Qed.
Lemma injm_restrm : 'injm f -> 'injm fA.
Proof. by apply: subset_trans; rewrite ker_restrm subsetIr. Qed.
End Props.
Lemma restrmP (f : {morphism D >-> rT}) : A \subset 'dom f ->
{g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker_A f,
forall R, g @*^-1 R = A :&: f @*^-1 R
& forall B, B \subset A -> g @* B = f @* B]}.
Proof.
move=> sAD; exists (restrm_morphism sAD f).
split=> // [|R|B sBA]; first 1 [exact: ker_restrm | exact: morphpre_restrm].
by rewrite morphim_restrm (setIidPr sBA).
Qed.
Lemma domP (f : {morphism D >-> rT}) : 'dom f = A ->
{g : {morphism A >-> rT} | [/\ g = f :> (aT -> rT), 'ker g = 'ker f,
forall R, g @*^-1 R = f @*^-1 R
& forall B, g @* B = f @* B]}.
Proof. by move <-; exists f. Qed.
End RestrictedMorphism.
Arguments restrm {_ _ _%_g _%_g} _ _%_g.
Arguments restrmP {aT rT A D}.
Arguments domP {aT rT A D}.
Section TrivMorphism.
Variables aT rT : finGroupType.
Definition trivm of {set aT} & aT := 1 : FinGroup.sort rT.
Lemma trivm_morphM (A : {set aT}) : {in A &, {morph trivm A : x y / x * y}}.
Proof. by move=> x y /=; rewrite mulg1. Qed.
Canonical triv_morph A := Morphism (@trivm_morphM A).
Lemma morphim_trivm (G H : {group aT}) : trivm G @* H = 1.
Proof.
apply/setP=> /= y; rewrite inE; apply/idP/eqP=> [|->]; first by case/morphimP.
by apply/morphimP; exists (1 : aT); rewrite /= ?group1.
Qed.
Lemma ker_trivm (G : {group aT}) : 'ker (trivm G) = G.
Proof. by apply/setIidPl/subsetP=> x _; rewrite !inE /=. Qed.
End TrivMorphism.
Arguments trivm {aT rT} _%_g _%_g.
(* The composition of two morphisms is a Canonical morphism instance. *)
Section MorphismComposition.
Variables gT hT rT : finGroupType.
Variables (G : {group gT}) (H : {group hT}).
Variable f : {morphism G >-> hT}.
Variable g : {morphism H >-> rT}.
Local Notation gof := (mfun g \o mfun f).
Lemma comp_morphM : {in f @*^-1 H &, {morph gof: x y / x * y}}.
Proof.
by move=> x y; rewrite /= !inE => /andP[? ?] /andP[? ?]; rewrite !morphM.
Qed.
Canonical comp_morphism := Morphism comp_morphM.
Lemma ker_comp : 'ker gof = f @*^-1 'ker g.
Proof. by apply/setP=> x; rewrite !inE andbA. Qed.
Lemma injm_comp : 'injm f -> 'injm g -> 'injm gof.
Proof. by move=> injf; rewrite ker_comp; move/trivgP=> ->. Qed.
Lemma morphim_comp (A : {set gT}) : gof @* A = g @* (f @* A).
Proof.
apply/setP=> z; apply/morphimP/morphimP=> [[x]|[y Hy fAy ->{z}]].
rewrite !inE => /andP[Gx Hfx]; exists (f x) => //.
by apply/morphimP; exists x.
by case/morphimP: fAy Hy => x Gx Ax ->{y} Hfx; exists x; rewrite ?inE ?Gx.
Qed.
Lemma morphpre_comp (C : {set rT}) : gof @*^-1 C = f @*^-1 (g @*^-1 C).
Proof. by apply/setP=> z; rewrite !inE andbA. Qed.
End MorphismComposition.
(* The factor morphism *)
Section FactorMorphism.
Variables aT qT rT : finGroupType.
Variables G H : {group aT}.
Variable f : {morphism G >-> rT}.
Variable q : {morphism H >-> qT}.
Definition factm of 'ker q \subset 'ker f & G \subset H :=
fun x => f (repr (q @*^-1 [set x])).
Hypothesis sKqKf : 'ker q \subset 'ker f.
Hypothesis sGH : G \subset H.
Notation ff := (factm sKqKf sGH).
Lemma factmE x : x \in G -> ff (q x) = f x.
Proof.
rewrite /ff => Gx; have Hx := subsetP sGH x Gx.
have /mem_repr: x \in q @*^-1 [set q x] by rewrite !inE Hx /=.
case/morphpreP; move: (repr _) => y Hy /set1P.
by case/ker_rcoset=> // z Kz ->; rewrite mkerl ?(subsetP sKqKf).
Qed.
Lemma factm_morphM : {in q @* G &, {morph ff : x y / x * y}}.
Proof.
move=> _ _ /morphimP[x Hx Gx ->] /morphimP[y Hy Gy ->].
by rewrite -morphM ?factmE ?groupM // morphM.
Qed.
Canonical factm_morphism := Morphism factm_morphM.
Lemma morphim_factm (A : {set aT}) : ff @* (q @* A) = f @* A.
Proof.
rewrite -morphim_comp /= {1}/morphim /= morphimGK //; last first.
by rewrite (subset_trans sKqKf) ?subsetIl.
apply/setP=> y; apply/morphimP/morphimP;
by case=> x Gx Ax ->{y}; exists x; rewrite //= factmE.
Qed.
Lemma morphpre_factm (C : {set rT}) : ff @*^-1 C = q @* (f @*^-1 C).
Proof.
apply/setP=> y /[!inE]/=; apply/andP/morphimP=> [[]|[x Hx]]; last first.
by case/morphpreP=> Gx Cfx ->; rewrite factmE ?imset_f ?inE ?Hx.
case/morphimP=> x Hx Gx ->; rewrite factmE //.
by exists x; rewrite // !inE Gx.
Qed.
Lemma ker_factm : 'ker ff = q @* 'ker f.
Proof. exact: morphpre_factm. Qed.
Lemma injm_factm : 'injm f -> 'injm ff.
Proof. by rewrite ker_factm => /trivgP->; rewrite morphim1. Qed.
Lemma injm_factmP : reflect ('ker f = 'ker q) ('injm ff).
Proof.
rewrite ker_factm -morphimIdom sub_morphim_pre ?subsetIl //.
rewrite setIA (setIidPr sGH) (sameP setIidPr eqP) (setIidPl _) // eq_sym.
exact: eqP.
Qed.
Lemma ker_factm_loc (K : {group aT}) : 'ker_(q @* K) ff = q @* 'ker_K f.
Proof. by rewrite ker_factm -morphimIG. Qed.
End FactorMorphism.
Prenex Implicits factm.
Section InverseMorphism.
Variables aT rT : finGroupType.
Implicit Types A B : {set aT}.
Implicit Types C D : {set rT}.
Variables (G : {group aT}) (f : {morphism G >-> rT}).
Hypothesis injf : 'injm f.
Lemma invm_subker : 'ker f \subset 'ker (idm G).
Proof. by rewrite ker_idm. Qed.
Definition invm := factm invm_subker (subxx _).
Canonical invm_morphism := Eval hnf in [morphism of invm].
Lemma invmE : {in G, cancel f invm}.
Proof. exact: factmE. Qed.
Lemma invmK : {in f @* G, cancel invm f}.
Proof. by move=> fx; case/morphimP=> x _ Gx ->; rewrite invmE. Qed.
Lemma morphpre_invm A : invm @*^-1 A = f @* A.
Proof. by rewrite morphpre_factm morphpre_idm morphimIdom. Qed.
Lemma morphim_invm A : A \subset G -> invm @* (f @* A) = A.
Proof. by move=> sAG; rewrite morphim_factm morphim_idm. Qed.
Lemma morphim_invmE C : invm @* C = f @*^-1 C.
Proof.
rewrite -morphpreIdom -(morphim_invm (subsetIl _ _)).
by rewrite morphimIdom -morphpreIim morphpreK (subsetIl, morphimIdom).
Qed.
Lemma injm_proper A B :
A \subset G -> B \subset G -> (f @* A \proper f @* B) = (A \proper B).
Proof.
move=> dA dB; rewrite -morphpre_invm -(morphpre_invm B).
by rewrite morphpre_proper ?morphim_invm.
Qed.
Lemma injm_invm : 'injm invm.
Proof. by move/can_in_inj/injmP: invmK. Qed.
Lemma ker_invm : 'ker invm = 1.
Proof. by move/trivgP: injm_invm. Qed.
Lemma im_invm : invm @* (f @* G) = G.
Proof. exact: morphim_invm. Qed.
End InverseMorphism.
Prenex Implicits invm.
Section InjFactm.
Variables (gT aT rT : finGroupType) (D G : {group gT}).
Variables (g : {morphism G >-> rT}) (f : {morphism D >-> aT}) (injf : 'injm f).
Definition ifactm :=
tag (domP [morphism of g \o invm injf] (morphpre_invm injf G)).
Lemma ifactmE : {in D, forall x, ifactm (f x) = g x}.
Proof.
rewrite /ifactm => x Dx; case: domP => f' /= [def_f' _ _ _].
by rewrite {f'}def_f' //= invmE.
Qed.
Lemma morphim_ifactm (A : {set gT}) :
A \subset D -> ifactm @* (f @* A) = g @* A.
Proof.
rewrite /ifactm => sAD; case: domP => _ /= [_ _ _ ->].
by rewrite morphim_comp morphim_invm.
Qed.
Lemma im_ifactm : G \subset D -> ifactm @* (f @* G) = g @* G.
Proof. exact: morphim_ifactm. Qed.
Lemma morphpre_ifactm C : ifactm @*^-1 C = f @* (g @*^-1 C).
Proof.
rewrite /ifactm; case: domP => _ /= [_ _ -> _].
by rewrite morphpre_comp morphpre_invm.
Qed.
Lemma ker_ifactm : 'ker ifactm = f @* 'ker g.
Proof. exact: morphpre_ifactm. Qed.
Lemma injm_ifactm : 'injm g -> 'injm ifactm.
Proof. by rewrite ker_ifactm => /trivgP->; rewrite morphim1. Qed.
End InjFactm.
(* Reflected (boolean) form of morphism and isomorphism properties. *)
Section ReflectProp.
Variables aT rT : finGroupType.
Section Defs.
Variables (A : {set aT}) (B : {set rT}).
(* morphic is the morphM property of morphisms seen through morphicP. *)
Definition morphic (f : aT -> rT) :=
[forall u in [predX A & A], f (u.1 * u.2) == f u.1 * f u.2].
Definition isom f := f @: A^# == B^#.
Definition misom f := morphic f && isom f.
Definition isog := [exists f : {ffun aT -> rT}, misom f].
Section MorphicProps.
Variable f : aT -> rT.
Lemma morphicP : reflect {in A &, {morph f : x y / x * y}} (morphic f).
Proof.
apply: (iffP forallP) => [fM x y Ax Ay | fM [x y] /=].
by apply/eqP; have:= fM (x, y); rewrite inE /= Ax Ay.
by apply/implyP=> /andP[Ax Ay]; rewrite fM.
Qed.
Definition morphm of morphic f := f : aT -> FinGroup.sort rT.
Lemma morphmE fM : morphm fM = f. Proof. by []. Qed.
Canonical morphm_morphism fM := @Morphism _ _ A (morphm fM) (morphicP fM).
End MorphicProps.
Lemma misomP f : reflect {fM : morphic f & isom (morphm fM)} (misom f).
Proof. by apply: (iffP andP) => [] [fM fiso] //; exists fM. Qed.
Lemma misom_isog f : misom f -> isog.
Proof.
case/andP=> fM iso_f; apply/existsP; exists (finfun f).
apply/andP; split; last by rewrite /misom /isom !(eq_imset _ (ffunE f)).
by apply/forallP=> u; rewrite !ffunE; apply: forallP fM u.
Qed.
Lemma isom_isog (D : {group aT}) (f : {morphism D >-> rT}) :
A \subset D -> isom f -> isog.
Proof.
move=> sAD isof; apply: (@misom_isog f); rewrite /misom isof andbT.
by apply/morphicP; apply: (sub_in2 (subsetP sAD) (morphM f)).
Qed.
Lemma isog_isom : isog -> {f : {morphism A >-> rT} | isom f}.
Proof.
by case/existsP/sigW=> f /misomP[fM isom_f]; exists (morphm_morphism fM).
Qed.
End Defs.
Infix "\isog" := isog.
Arguments isom_isog [A B D].
(* The real reflection properties only hold for true groups and morphisms. *)
Section Main.
Variables (G : {group aT}) (H : {group rT}).
Lemma isomP (f : {morphism G >-> rT}) :
reflect ('injm f /\ f @* G = H) (isom G H f).
Proof.
apply: (iffP eqP) => [eqfGH | [injf <-]]; last first.
by rewrite -injmD1 // morphimEsub ?subsetDl.
split.
apply/subsetP=> x /morphpreP[Gx fx1]; have: f x \notin H^# by rewrite inE fx1.
by apply: contraR => ntx; rewrite -eqfGH imset_f // inE ntx.
rewrite morphimEdom -{2}(setD1K (group1 G)) imsetU eqfGH.
by rewrite imset_set1 morph1 setD1K.
Qed.
Lemma isogP :
reflect (exists2 f : {morphism G >-> rT}, 'injm f & f @* G = H) (G \isog H).
Proof.
apply: (iffP idP) => [/isog_isom[f /isomP[]] | [f injf fG]]; first by exists f.
by apply: (isom_isog f) => //; apply/isomP.
Qed.
Variable f : {morphism G >-> rT}.
Hypothesis isoGH : isom G H f.
Lemma isom_inj : 'injm f. Proof. by have /isomP[] := isoGH. Qed.
Lemma isom_im : f @* G = H. Proof. by have /isomP[] := isoGH. Qed.
Lemma isom_card : #|G| = #|H|.
Proof. by rewrite -isom_im card_injm ?isom_inj. Qed.
Lemma isom_sub_im : H \subset f @* G. Proof. by rewrite isom_im. Qed.
Definition isom_inv := restrm isom_sub_im (invm isom_inj).
End Main.
Variables (G : {group aT}) (f : {morphism G >-> rT}).
Lemma morphim_isom (H : {group aT}) (K : {group rT}) :
H \subset G -> isom H K f -> f @* H = K.
Proof. by case/(restrmP f)=> g [gf _ _ <- //]; rewrite -gf; case/isomP. Qed.
Lemma sub_isom (A : {set aT}) (C : {set rT}) :
A \subset G -> f @* A = C -> 'injm f -> isom A C f.
Proof.
move=> sAG; case: (restrmP f sAG) => g [_ _ _ img] <-{C} injf.
rewrite /isom -morphimEsub ?morphimDG ?morphim1 //.
by rewrite subDset setUC subsetU ?sAG.
Qed.
Lemma sub_isog (A : {set aT}) : A \subset G -> 'injm f -> isog A (f @* A).
Proof. by move=> sAG injf; apply: (isom_isog f sAG); apply: sub_isom. Qed.
Lemma restr_isom_to (A : {set aT}) (C R : {group rT}) (sAG : A \subset G) :
f @* A = C -> isom G R f -> isom A C (restrm sAG f).
Proof. by move=> defC /isomP[inj_f _]; apply: sub_isom. Qed.
Lemma restr_isom (A : {group aT}) (R : {group rT}) (sAG : A \subset G) :
isom G R f -> isom A (f @* A) (restrm sAG f).
Proof. exact: restr_isom_to. Qed.
End ReflectProp.
Arguments isom {_ _} _%_g _%_g _.
Arguments morphic {_ _} _%_g _.
Arguments misom _ _ _%_g _%_g _.
Arguments isog {_ _} _%_g _%_g.
Arguments morphicP {aT rT A f}.
Arguments misomP {aT rT A B f}.
Arguments isom_isog [aT rT A B D].
Arguments isomP {aT rT G H f}.
Arguments isogP {aT rT G H}.
Prenex Implicits morphm.
Notation "x \isog y":= (isog x y).
Section Isomorphisms.
Variables gT hT kT : finGroupType.
Variables (G : {group gT}) (H : {group hT}) (K : {group kT}).
Lemma idm_isom : isom G G (idm G).
Proof. exact: sub_isom (im_idm G) (injm_idm G). Qed.
Lemma isog_refl : G \isog G. Proof. exact: isom_isog idm_isom. Qed.
Lemma card_isog : G \isog H -> #|G| = #|H|.
Proof. by case/isogP=> f injf <-; apply: isom_card (f) _; apply/isomP. Qed.
Lemma isog_abelian : G \isog H -> abelian G = abelian H.
Proof. by case/isogP=> f injf <-; rewrite injm_abelian. Qed.
Lemma trivial_isog : G :=: 1 -> H :=: 1 -> G \isog H.
Proof.
move=> -> ->; apply/isogP.
exists [morphism of @trivm gT hT 1]; rewrite /= ?morphim1 //.
by rewrite ker_trivm; apply: subxx.
Qed.
Lemma isog_eq1 : G \isog H -> (G :==: 1) = (H :==: 1).
Proof. by move=> isoGH; rewrite !trivg_card1 card_isog. Qed.
Lemma isom_sym (f : {morphism G >-> hT}) (isoGH : isom G H f) :
isom H G (isom_inv isoGH).
Proof.
rewrite sub_isom 1?injm_restrm ?injm_invm // im_restrm.
by rewrite -(isom_im isoGH) im_invm.
Qed.
Lemma isog_symr : G \isog H -> H \isog G.
Proof. by case/isog_isom=> f /isom_sym/isom_isog->. Qed.
Lemma isog_trans : G \isog H -> H \isog K -> G \isog K.
Proof.
case/isogP=> f injf <-; case/isogP=> g injg <-.
have defG: f @*^-1 (f @* G) = G by rewrite morphimGK ?subsetIl.
rewrite -morphim_comp -{1 8}defG.
by apply/isogP; exists [morphism of g \o f]; rewrite ?injm_comp.
Qed.
Lemma nclasses_isog : G \isog H -> #|classes G| = #|classes H|.
Proof. by case/isogP=> f injf <-; rewrite nclasses_injm. Qed.
End Isomorphisms.
Section IsoBoolEquiv.
Variables gT hT kT : finGroupType.
Variables (G : {group gT}) (H : {group hT}) (K : {group kT}).
Lemma isog_sym : (G \isog H) = (H \isog G).
Proof. by apply/idP/idP; apply: isog_symr. Qed.
Lemma isog_transl : G \isog H -> (G \isog K) = (H \isog K).
Proof.
by move=> iso; apply/idP/idP; apply: isog_trans; rewrite // -isog_sym.
Qed.
Lemma isog_transr : G \isog H -> (K \isog G) = (K \isog H).
Proof.
by move=> iso; apply/idP/idP; move/isog_trans; apply; rewrite // -isog_sym.
Qed.
End IsoBoolEquiv.
Section Homg.
Implicit Types rT gT aT : finGroupType.
Definition homg rT aT (C : {set rT}) (D : {set aT}) :=
[exists (f : {ffun aT -> rT} | morphic D f), f @: D == C].
Lemma homgP rT aT (C : {set rT}) (D : {set aT}) :
reflect (exists f : {morphism D >-> rT}, f @* D = C) (homg C D).
Proof.
apply: (iffP exists_eq_inP) => [[f fM <-] | [f <-]].
by exists (morphm_morphism fM); rewrite /morphim /= setIid.
exists (finfun f); first by apply/morphicP=> x y Dx Dy; rewrite !ffunE morphM.
by rewrite /morphim setIid; apply: eq_imset => x; rewrite ffunE.
Qed.
Lemma morphim_homg aT rT (A D : {set aT}) (f : {morphism D >-> rT}) :
A \subset D -> homg (f @* A) A.
Proof.
move=> sAD; apply/homgP; exists (restrm_morphism sAD f).
by rewrite morphim_restrm setIid.
Qed.
Lemma leq_homg rT aT (C : {set rT}) (G : {group aT}) :
homg C G -> #|C| <= #|G|.
Proof. by case/homgP=> f <-; apply: leq_morphim. Qed.
Lemma homg_refl aT (A : {set aT}) : homg A A.
Proof. by apply/homgP; exists (idm_morphism A); rewrite im_idm. Qed.
Lemma homg_trans aT (B : {set aT}) rT (C : {set rT}) gT (G : {group gT}) :
homg C B -> homg B G -> homg C G.
Proof.
move=> homCB homBG; case/homgP: homBG homCB => fG <- /homgP[fK <-].
by rewrite -morphim_comp morphim_homg // -sub_morphim_pre.
Qed.
Lemma isogEcard rT aT (G : {group rT}) (H : {group aT}) :
(G \isog H) = (homg G H) && (#|H| <= #|G|).
Proof.
rewrite isog_sym; apply/isogP/andP=> [[f injf <-] | []].
by rewrite leq_eqVlt eq_sym card_im_injm injf morphim_homg.
case/homgP=> f <-; rewrite leq_eqVlt eq_sym card_im_injm.
by rewrite ltnNge leq_morphim orbF; exists f.
Qed.
Lemma isog_hom rT aT (G : {group rT}) (H : {group aT}) : G \isog H -> homg G H.
Proof. by rewrite isogEcard; case/andP. Qed.
Lemma isogEhom rT aT (G : {group rT}) (H : {group aT}) :
(G \isog H) = homg G H && homg H G.
Proof.
apply/idP/andP=> [isoGH | [homGH homHG]].
by rewrite !isog_hom // isog_sym.
by rewrite isogEcard homGH leq_homg.
Qed.
Lemma eq_homgl gT aT rT (G : {group gT}) (H : {group aT}) (K : {group rT}) :
G \isog H -> homg G K = homg H K.
Proof.
by rewrite isogEhom => /andP[homGH homHG]; apply/idP/idP; apply: homg_trans.
Qed.
Lemma eq_homgr gT rT aT (G : {group gT}) (H : {group rT}) (K : {group aT}) :
G \isog H -> homg K G = homg K H.
Proof.
rewrite isogEhom => /andP[homGH homHG].
by apply/idP/idP=> homK; apply: homg_trans homK _.
Qed.
End Homg.
Arguments homg _ _ _%_g _%_g.
Notation "G \homg H" := (homg G H)
(at level 70, no associativity) : group_scope.
Arguments homgP {rT aT C D}.
(* Isomorphism between a group and its subtype. *)
Section SubMorphism.
Variables (gT : finGroupType) (G : {group gT}).
Canonical sgval_morphism := Morphism (@sgvalM _ G).
Canonical subg_morphism := Morphism (@subgM _ G).
Lemma injm_sgval : 'injm sgval.
Proof. exact/injmP/(in2W subg_inj). Qed.
Lemma injm_subg : 'injm (subg G).
Proof. exact/injmP/(can_in_inj subgK). Qed.
Hint Resolve injm_sgval injm_subg : core.
Lemma ker_sgval : 'ker sgval = 1. Proof. exact/trivgP. Qed.
Lemma ker_subg : 'ker (subg G) = 1. Proof. exact/trivgP. Qed.
Lemma im_subg : subg G @* G = [subg G].
Proof.
apply/eqP; rewrite -subTset morphimEdom.
by apply/subsetP=> u _; rewrite -(sgvalK u) imset_f ?subgP.
Qed.
Lemma sgval_sub A : sgval @* A \subset G.
Proof. by apply/subsetP=> x; case/imsetP=> u _ ->; apply: subgP. Qed.
Lemma sgvalmK A : subg G @* (sgval @* A) = A.
Proof.
apply/eqP; rewrite eqEcard !card_injm ?subsetT ?sgval_sub // leqnn andbT.
rewrite -morphim_comp; apply/subsetP=> _ /morphimP[v _ Av ->] /=.
by rewrite sgvalK.
Qed.
Lemma subgmK (A : {set gT}) : A \subset G -> sgval @* (subg G @* A) = A.
Proof.
move=> sAG; apply/eqP; rewrite eqEcard !card_injm ?subsetT //.
rewrite leqnn andbT -morphim_comp morphimE /= morphpreT.
by apply/subsetP=> _ /morphimP[v Gv Av ->] /=; rewrite subgK.
Qed.
Lemma im_sgval : sgval @* [subg G] = G.
Proof. by rewrite -{2}im_subg subgmK. Qed.
Lemma isom_subg : isom G [subg G] (subg G).
Proof. by apply/isomP; rewrite im_subg. Qed.
Lemma isom_sgval : isom [subg G] G sgval.
Proof. by apply/isomP; rewrite im_sgval. Qed.
Lemma isog_subg : isog G [subg G].
Proof. exact: isom_isog isom_subg. Qed.
End SubMorphism.
Arguments sgvalmK {gT G} A.
Arguments subgmK {gT G} [A] sAG.
|
Arctan.lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan
import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic
/-!
# Measurability of arctan
-/
namespace Real
@[measurability]
theorem measurable_arctan : Measurable arctan :=
continuous_arctan.measurable
end Real
section RealComposition
open Real
variable {α : Type*} {m : MeasurableSpace α} {f : α → ℝ}
@[measurability, fun_prop]
theorem Measurable.arctan (hf : Measurable f) : Measurable fun x => arctan (f x) :=
measurable_arctan.comp hf
end RealComposition
|
MfldSetTac.lean
|
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth, Frédéric Dupuis
-/
import Mathlib.Logic.Equiv.PartialEquiv
private axiom test_sorry : ∀ {α}, α
/-!
This is a test file for the tactic `mfld_set_tac`. Because this tactic applies a simp-set which
mostly contains lemmas in advanced parts of mathlib, it is currently impossible to truly test it
in realistic conditions. Instead, we create stub definitions and lemmas on objects such as
`PartialHomeomorph`, label them with `mfld_simps` and run tests on those.
-/
open Lean Meta Elab Tactic
/-! ## Syntax of objects and lemmas needed for testing `MfldSetTac` -/
set_option autoImplicit true
section stub_lemmas
structure PartialHomeomorph (α : Type u) (β : Type u) extends PartialEquiv α β
noncomputable
instance PartialHomeomorph.has_coe_to_fun : CoeFun (PartialHomeomorph α β) (fun _ ↦ α → β) :=
test_sorry
noncomputable
def PartialHomeomorph.symm (_e : PartialHomeomorph α β) : PartialHomeomorph β α := test_sorry
@[mfld_simps] lemma PartialHomeomorph.left_inv (e : PartialHomeomorph α β) {x : α}
(_h : x ∈ e.toPartialEquiv.source) :
e.symm (e x) = x :=
test_sorry
@[mfld_simps] theorem PartialHomeomorph.symm_to_PartialEquiv (e : PartialHomeomorph α β) :
e.symm.toPartialEquiv = e.toPartialEquiv.symm :=
test_sorry
@[mfld_simps] lemma PartialHomeomorph.coe_coe (e : PartialHomeomorph α β) :
(e.toPartialEquiv : α → β) = e :=
test_sorry
@[mfld_simps] lemma PartialHomeomorph.coe_coe_symm (e : PartialHomeomorph α β) :
(e.toPartialEquiv.symm : β → α) = (e.symm : β → α) :=
test_sorry
structure ModelWithCorners (𝕜 E H : Type u) extends PartialEquiv H E where
(source_eq : source = Set.univ)
attribute [mfld_simps] ModelWithCorners.source_eq
noncomputable
def ModelWithCorners.symm (_I : ModelWithCorners 𝕜 E H) : PartialEquiv E H := test_sorry
noncomputable
instance ModelWithCorners.has_coe_to_fun : CoeFun (ModelWithCorners 𝕜 E H) (fun _ ↦ H → E) :=
test_sorry
@[mfld_simps] lemma ModelWithCorners.left_inv (I : ModelWithCorners 𝕜 E H) (x : H) :
I.symm (I x) = x :=
test_sorry
@[mfld_simps] lemma ModelWithCorners.to_local_equiv_coe (I : ModelWithCorners 𝕜 E H) :
(I.toPartialEquiv : H → E) = I :=
test_sorry
@[mfld_simps] lemma ModelWithCorners.to_local_equiv_coe_symm (I : ModelWithCorners 𝕜 E H) :
(I.toPartialEquiv.symm : E → H) = I.symm :=
test_sorry
end stub_lemmas
/-! ## Tests for `MfldSetTac` -/
section tests
example (e : PartialEquiv α β) (e' : PartialEquiv β γ) :
(e.trans e').source = e.source ∩ Set.preimage e (e.target ∩ e'.source) := by
mfld_set_tac
example (e : PartialEquiv α β) : (e.trans e.symm).source = e.source := by mfld_set_tac
example (s : Set α) (f : PartialHomeomorph α β) :
f.symm.toPartialEquiv.source ∩ (f.toPartialEquiv.target ∩ Set.preimage f.symm s)
= f.symm.toPartialEquiv.source ∩ Set.preimage f.symm s := by mfld_set_tac
example
{I : ModelWithCorners 𝕜 E H}
{I' : ModelWithCorners 𝕜 E' H'}
{I'' : ModelWithCorners 𝕜 E'' H''}
(e₁ : PartialHomeomorph M H)
(e₂ : PartialHomeomorph M' H')
(e₃ : PartialHomeomorph M'' H'')
{f : M → M'}
{g : M' → M''} :
(Set.preimage (f ∘ ((e₁.toPartialEquiv.trans I.toPartialEquiv).symm))
(e₂.toPartialEquiv.trans I'.toPartialEquiv).source) ⊆
{y : E |
((e₃.toPartialEquiv.trans I''.toPartialEquiv) ∘
(g ∘ f) ∘ ((e₁.toPartialEquiv.trans I.toPartialEquiv).symm)) y
= (((e₃.toPartialEquiv.trans I''.toPartialEquiv : M'' → E'') ∘
g ∘ ((e₂.toPartialEquiv.trans I'.toPartialEquiv).symm)) ∘
(e₂.toPartialEquiv.trans I'.toPartialEquiv : M' → E') ∘
f ∘ ((e₁.toPartialEquiv.trans I.toPartialEquiv).symm)) y} := by
mfld_set_tac
end tests
|
Count.lean
|
/-
Copyright (c) 2021 Vladimir Goryachev. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Vladimir Goryachev, Kyle Miller, Kim Morrison, Eric Rodriguez
-/
import Mathlib.Algebra.Group.Nat.Range
import Mathlib.Data.Set.Finite.Basic
/-!
# Counting on ℕ
This file defines the `count` function, which gives, for any predicate on the natural numbers,
"how many numbers under `k` satisfy this predicate?".
We then prove several expected lemmas about `count`, relating it to the cardinality of other
objects, and helping to evaluate it for specific `k`.
-/
assert_not_imported Mathlib.Dynamics.FixedPoints.Basic
assert_not_exists Ring
open Finset
namespace Nat
variable (p : ℕ → Prop)
section Count
variable [DecidablePred p]
/-- Count the number of naturals `k < n` satisfying `p k`. -/
def count (n : ℕ) : ℕ :=
(List.range n).countP p
@[simp]
theorem count_zero : count p 0 = 0 := by
rw [count, List.range_zero, List.countP, List.countP.go]
/-- A fintype instance for the set relevant to `Nat.count`. Locally an instance in locale `count` -/
def CountSet.fintype (n : ℕ) : Fintype { i // i < n ∧ p i } := by
apply Fintype.ofFinset {x ∈ range n | p x}
intro x
rw [mem_filter, mem_range]
rfl
scoped[Count] attribute [instance] Nat.CountSet.fintype
open Count
theorem count_eq_card_filter_range (n : ℕ) : count p n = #{x ∈ range n | p x} := by
rw [count, List.countP_eq_length_filter]
rfl
/-- `count p n` can be expressed as the cardinality of `{k // k < n ∧ p k}`. -/
theorem count_eq_card_fintype (n : ℕ) : count p n = Fintype.card { k : ℕ // k < n ∧ p k } := by
rw [count_eq_card_filter_range, ← Fintype.card_ofFinset, ← CountSet.fintype]
rfl
theorem count_le {n : ℕ} : count p n ≤ n := by
rw [count_eq_card_filter_range]
exact (card_filter_le _ _).trans_eq (card_range _)
theorem count_succ (n : ℕ) : count p (n + 1) = count p n + if p n then 1 else 0 := by
split_ifs with h <;> simp [count, List.range_succ, h]
@[mono]
theorem count_monotone : Monotone (count p) :=
monotone_nat_of_le_succ fun n ↦ by by_cases h : p n <;> simp [count_succ, h]
theorem count_add (a b : ℕ) : count p (a + b) = count p a + count (fun k ↦ p (a + k)) b := by
have : Disjoint {x ∈ range a | p x} {x ∈ (range b).map <| addLeftEmbedding a | p x} := by
apply disjoint_filter_filter
rw [Finset.disjoint_left]
simp_rw [mem_map, mem_range, addLeftEmbedding_apply]
rintro x hx ⟨c, _, rfl⟩
exact (Nat.le_add_right _ _).not_gt hx
simp_rw [count_eq_card_filter_range, range_add, filter_union, card_union_of_disjoint this,
filter_map, addLeftEmbedding, card_map]
rfl
theorem count_add' (a b : ℕ) : count p (a + b) = count (fun k ↦ p (k + b)) a + count p b := by
rw [add_comm, count_add, add_comm]
simp_rw [add_comm b]
theorem count_one : count p 1 = if p 0 then 1 else 0 := by simp [count_succ]
theorem count_succ' (n : ℕ) :
count p (n + 1) = count (fun k ↦ p (k + 1)) n + if p 0 then 1 else 0 := by
rw [count_add', count_one]
variable {p}
@[simp]
theorem count_lt_count_succ_iff {n : ℕ} : count p n < count p (n + 1) ↔ p n := by
by_cases h : p n <;> simp [count_succ, h]
theorem count_succ_eq_succ_count_iff {n : ℕ} : count p (n + 1) = count p n + 1 ↔ p n := by
by_cases h : p n <;> simp [h, count_succ]
theorem count_succ_eq_count_iff {n : ℕ} : count p (n + 1) = count p n ↔ ¬p n := by
by_cases h : p n <;> simp [h, count_succ]
alias ⟨_, count_succ_eq_succ_count⟩ := count_succ_eq_succ_count_iff
alias ⟨_, count_succ_eq_count⟩ := count_succ_eq_count_iff
theorem lt_of_count_lt_count {a b : ℕ} (h : count p a < count p b) : a < b :=
(count_monotone p).reflect_lt h
theorem count_strict_mono {m n : ℕ} (hm : p m) (hmn : m < n) : count p m < count p n :=
(count_lt_count_succ_iff.2 hm).trans_le <| count_monotone _ (Nat.succ_le_iff.2 hmn)
theorem count_injective {m n : ℕ} (hm : p m) (hn : p n) (heq : count p m = count p n) : m = n := by
by_contra! h : m ≠ n
wlog hmn : m < n
· exact this hn hm heq.symm h.symm (h.lt_or_gt.resolve_left hmn)
· simpa [heq] using count_strict_mono hm hmn
theorem count_le_card (hp : (setOf p).Finite) (n : ℕ) : count p n ≤ #hp.toFinset := by
rw [count_eq_card_filter_range]
exact Finset.card_mono fun x hx ↦ hp.mem_toFinset.2 (mem_filter.1 hx).2
theorem count_lt_card {n : ℕ} (hp : (setOf p).Finite) (hpn : p n) : count p n < #hp.toFinset :=
(count_lt_count_succ_iff.2 hpn).trans_le (count_le_card hp _)
theorem count_iff_forall {n : ℕ} : count p n = n ↔ ∀ n' < n, p n' := by
simpa [count_eq_card_filter_range, card_range, mem_range] using
card_filter_eq_iff (p := p) (s := range n)
alias ⟨_, count_of_forall⟩ := count_iff_forall
@[simp] theorem count_true (n : ℕ) : count (fun _ ↦ True) n = n := count_of_forall fun _ _ ↦ trivial
theorem count_iff_forall_not {n : ℕ} : count p n = 0 ↔ ∀ m < n, ¬p m := by
simpa [count_eq_card_filter_range, mem_range] using
card_filter_eq_zero_iff (p := p) (s := range n)
alias ⟨_, count_of_forall_not⟩ := count_iff_forall_not
theorem count_ne_iff_exists {n : ℕ} : n.count p ≠ 0 ↔ ∃ m < n, p m := by
simp [Nat.count_iff_forall_not]
@[simp] theorem count_false (n : ℕ) : count (fun _ ↦ False) n = 0 :=
count_of_forall_not fun _ _ ↦ id
lemma exists_of_count_lt_count {a b : ℕ} (h : a.count p < b.count p) : ∃ x ∈ Set.Ico a b, p x := by
obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_lt (lt_of_count_lt_count h)
rw [add_assoc, count_add, Nat.lt_add_right_iff_pos] at h
obtain ⟨t, ht, hp⟩ := count_ne_iff_exists.mp h.ne'
simp_rw [Set.mem_Ico]
exact ⟨a + t, ⟨le_add_right _ _, by rwa [add_assoc _ k, Nat.add_lt_add_iff_left]⟩, hp⟩
variable {q : ℕ → Prop}
variable [DecidablePred q]
theorem count_mono_left {n : ℕ} (hpq : ∀ k, p k → q k) : count p n ≤ count q n := by
simp only [count_eq_card_filter_range]
exact card_le_card ((range n).monotone_filter_right hpq)
end Count
end Nat
|
Free.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Johan Commelin
-/
import Mathlib.LinearAlgebra.DirectSum.Finsupp
import Mathlib.LinearAlgebra.Finsupp.Pi
import Mathlib.LinearAlgebra.FreeModule.Basic
import Mathlib.LinearAlgebra.Matrix.ToLin
/-!
# Results on bases of tensor products
In the file we construct a basis for the base change of a module to an algebra,
and deduce that `Module.Free` is stable under base change.
## Main declarations
- `Algebra.TensorProduct.basis`: given a basis of a module `M` over a commutative semiring `R`,
and an `R`-algebra `A`, this provides a basis for `A ⊗[R] M` over `A`.
- `Algebra.TensorProduct.instFree`: if `M` is free, then so is `A ⊗[R] M`.
-/
assert_not_exists Cardinal
open Module
open scoped TensorProduct
namespace Algebra
namespace TensorProduct
variable {R A : Type*}
section Basis
universe uM uι
variable {M : Type uM} {ι : Type uι}
variable [CommSemiring R] [Semiring A] [Algebra R A]
variable [AddCommMonoid M] [Module R M] (b : Basis ι R M)
variable (A) in
/-- Given an `R`-algebra `A` and an `R`-basis of `M`, this is an `R`-linear isomorphism
`A ⊗[R] M ≃ (ι →₀ A)` (which is in fact `A`-linear). -/
noncomputable def basisAux : A ⊗[R] M ≃ₗ[R] ι →₀ A :=
_root_.TensorProduct.congr (Finsupp.LinearEquiv.finsuppUnique R A PUnit.{uι+1}).symm b.repr ≪≫ₗ
(finsuppTensorFinsupp R R A R PUnit ι).trans
(Finsupp.lcongr (Equiv.uniqueProd ι PUnit) (_root_.TensorProduct.rid R A))
theorem basisAux_tmul (a : A) (m : M) :
basisAux A b (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) := by
ext
simp [basisAux, ← Algebra.commutes, Algebra.smul_def]
theorem basisAux_map_smul (a : A) (x : A ⊗[R] M) : basisAux A b (a • x) = a • basisAux A b x :=
TensorProduct.induction_on x (by simp)
(fun x y => by simp only [TensorProduct.smul_tmul', basisAux_tmul, smul_assoc])
fun x y hx hy => by simp [hx, hy]
variable (A) in
/-- Given a `R`-algebra `A`, this is the `A`-basis of `A ⊗[R] M` induced by a `R`-basis of `M`. -/
noncomputable def basis : Basis ι A (A ⊗[R] M) where
repr := { basisAux A b with map_smul' := basisAux_map_smul b }
@[simp]
theorem basis_repr_tmul (a : A) (m : M) :
(basis A b).repr (a ⊗ₜ m) = a • Finsupp.mapRange (algebraMap R A) (map_zero _) (b.repr m) :=
basisAux_tmul b a m -- Porting note: Lean 3 had _ _ _
theorem basis_repr_symm_apply (a : A) (i : ι) :
(basis A b).repr.symm (Finsupp.single i a) = a ⊗ₜ b.repr.symm (Finsupp.single i 1) := by
rw [basis, LinearEquiv.coe_symm_mk] -- Porting note: `coe_symm_mk` isn't firing in `simp`
simp [Equiv.uniqueProd_symm_apply, basisAux]
@[simp]
theorem basis_apply (i : ι) : basis A b i = 1 ⊗ₜ b i := basis_repr_symm_apply b 1 i
theorem basis_repr_symm_apply' (a : A) (i : ι) : a • basis A b i = a ⊗ₜ b i := by
simpa using basis_repr_symm_apply b a i
section baseChange
open LinearMap
variable [Fintype ι]
variable {ι' N : Type*} [Fintype ι'] [DecidableEq ι'] [AddCommMonoid N] [Module R N]
variable (A : Type*) [CommSemiring A] [Algebra R A]
lemma _root_.Module.Basis.baseChange_linearMap (b : Basis ι R M) (b' : Basis ι' R N) (ij : ι × ι') :
baseChange A (b'.linearMap b ij) = (basis A b').linearMap (basis A b) ij := by
apply (basis A b').ext
intro k
conv_lhs => simp only [basis_apply, baseChange_tmul]
simp_rw [Basis.linearMap_apply_apply, basis_apply]
split <;> simp only [TensorProduct.tmul_zero]
variable [DecidableEq ι]
lemma _root_.Module.Basis.baseChange_end (b : Basis ι R M) (ij : ι × ι) :
baseChange A (b.end ij) = (basis A b).end ij :=
b.baseChange_linearMap A b ij
end baseChange
end Basis
instance instFree (R A M : Type*)
[CommSemiring R] [AddCommMonoid M] [Module R M] [Module.Free R M]
[CommSemiring A] [Algebra R A] :
Module.Free A (A ⊗[R] M) :=
Module.Free.of_basis <| Algebra.TensorProduct.basis A (Module.Free.chooseBasis R M)
end TensorProduct
end Algebra
namespace LinearMap
open Algebra.TensorProduct
variable {R M₁ M₂ ι ι₂ : Type*} (A : Type*)
[Fintype ι] [Finite ι₂] [DecidableEq ι]
[CommSemiring R] [CommSemiring A] [Algebra R A]
[AddCommMonoid M₁] [Module R M₁] [AddCommMonoid M₂] [Module R M₂]
@[simp]
lemma toMatrix_baseChange (f : M₁ →ₗ[R] M₂) (b₁ : Basis ι R M₁) (b₂ : Basis ι₂ R M₂) :
toMatrix (basis A b₁) (basis A b₂) (f.baseChange A) =
(toMatrix b₁ b₂ f).map (algebraMap R A) := by
ext; simp [toMatrix_apply]
end LinearMap
|
Topology.lean
|
/-
Copyright (c) 2024 Christian Merten. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christian Merten
-/
import Mathlib.CategoryTheory.Galois.Prorepresentability
import Mathlib.Topology.Algebra.ContinuousMonoidHom
import Mathlib.Topology.Algebra.Group.Basic
/-!
# Topology of fundamental group
In this file we define a natural topology on the automorphism group of a functor
`F : C ⥤ FintypeCat`: It is defined as the subspace topology induced by the natural
embedding of `Aut F` into `∀ X, Aut (F.obj X)` where
`Aut (F.obj X)` carries the discrete topology.
## References
- [Stacks 0BMQ](https://stacks.math.columbia.edu/tag/0BMQ)
-/
open Topology
universe u₁ u₂ v₁ v₂ v w
namespace CategoryTheory
namespace PreGaloisCategory
open Functor
variable {C : Type u₁} [Category.{u₂} C] (F : C ⥤ FintypeCat.{w})
/-- For a functor `F : C ⥤ FintypeCat`, the canonical embedding of `Aut F` into
the product over `Aut (F.obj X)` for all objects `X`. -/
def autEmbedding : Aut F →* ∀ X, Aut (F.obj X) :=
MonoidHom.mk' (fun σ X ↦ σ.app X) (fun _ _ ↦ rfl)
@[simp]
lemma autEmbedding_apply (σ : Aut F) (X : C) : autEmbedding F σ X = σ.app X :=
rfl
lemma autEmbedding_injective : Function.Injective (autEmbedding F) := by
intro σ τ h
ext X x
have : σ.app X = τ.app X := congr_fun h X
rw [← Iso.app_hom, ← Iso.app_hom, this]
/-- We put the discrete topology on `F.obj X`. -/
scoped instance (X : C) : TopologicalSpace (F.obj X) := ⊥
@[scoped instance]
lemma obj_discreteTopology (X : C) : DiscreteTopology (F.obj X) := ⟨rfl⟩
/-- We put the discrete topology on `Aut (F.obj X)`. -/
scoped instance (X : C) : TopologicalSpace (Aut (F.obj X)) := ⊥
@[scoped instance]
lemma aut_discreteTopology (X : C) : DiscreteTopology (Aut (F.obj X)) := ⟨rfl⟩
/-- `Aut F` is equipped with the by the embedding into `∀ X, Aut (F.obj X)` induced embedding. -/
instance : TopologicalSpace (Aut F) :=
TopologicalSpace.induced (autEmbedding F) inferInstance
/-- The image of `Aut F` in `∀ X, Aut (F.obj X)` are precisely the compatible families of
automorphisms. -/
lemma autEmbedding_range :
Set.range (autEmbedding F) =
⋂ (f : Arrow C), { a | F.map f.hom ≫ (a f.right).hom = (a f.left).hom ≫ F.map f.hom } := by
ext a
simp only [Set.mem_range, id_obj, Set.mem_iInter, Set.mem_setOf_eq]
refine ⟨fun ⟨σ, h⟩ i ↦ h.symm ▸ σ.hom.naturality i.hom, fun h ↦ ?_⟩
· use NatIso.ofComponents a (fun {X Y} f ↦ h ⟨X, Y, f⟩)
rfl
/-- The image of `Aut F` in `∀ X, Aut (F.obj X)` is closed. -/
lemma autEmbedding_range_isClosed : IsClosed (Set.range (autEmbedding F)) := by
rw [autEmbedding_range]
refine isClosed_iInter (fun f ↦ isClosed_eq (X := F.obj f.left → F.obj f.right) ?_ ?_)
· fun_prop
· fun_prop
lemma autEmbedding_isClosedEmbedding : IsClosedEmbedding (autEmbedding F) where
eq_induced := rfl
injective := autEmbedding_injective F
isClosed_range := autEmbedding_range_isClosed F
instance : CompactSpace (Aut F) := (autEmbedding_isClosedEmbedding F).compactSpace
instance : T2Space (Aut F) :=
T2Space.of_injective_continuous (autEmbedding_injective F) continuous_induced_dom
instance : TotallyDisconnectedSpace (Aut F) :=
(autEmbedding_isClosedEmbedding F).isEmbedding.isTotallyDisconnected_range.mp
(isTotallyDisconnected_of_totallyDisconnectedSpace _)
instance : ContinuousMul (Aut F) :=
(autEmbedding_isClosedEmbedding F).isInducing.continuousMul (autEmbedding F)
instance : ContinuousInv (Aut F) :=
(autEmbedding_isClosedEmbedding F).isInducing.continuousInv fun _ ↦ rfl
instance : IsTopologicalGroup (Aut F) := ⟨⟩
instance (X : C) : SMul (Aut (F.obj X)) (F.obj X) := ⟨fun σ a => σ.hom a⟩
instance (X : C) : ContinuousSMul (Aut (F.obj X)) (F.obj X) := by
constructor
fun_prop
instance continuousSMul_aut_fiber (X : C) : ContinuousSMul (Aut F) (F.obj X) where
continuous_smul := by
let g : Aut (F.obj X) × F.obj X → F.obj X := fun ⟨σ, x⟩ ↦ σ.hom x
let h (q : Aut F × F.obj X) : Aut (F.obj X) × F.obj X :=
⟨((fun p ↦ p X) ∘ autEmbedding F) q.1, q.2⟩
change Continuous (g ∘ h)
fun_prop
/-- If `G` is a functor of categories of finite types, the induced map `Aut F → Aut (F ⋙ G)` is
continuous. -/
lemma continuous_mapAut_whiskeringRight (G : FintypeCat.{w} ⥤ FintypeCat.{v}) :
Continuous (((whiskeringRight _ _ _).obj G).mapAut F) := by
rw [Topology.IsInducing.continuous_iff (autEmbedding_isClosedEmbedding _).isInducing,
continuous_pi_iff]
intro X
change Continuous fun a ↦ G.mapAut (F.obj X) (autEmbedding F a X)
fun_prop
/-- If `G` is a fully faithful functor of categories finite types, this is the automorphism of
topological groups `Aut F ≃ Aut (F ⋙ G)`. -/
noncomputable def autEquivAutWhiskerRight {G : FintypeCat.{w} ⥤ FintypeCat.{v}}
(h : G.FullyFaithful) :
Aut F ≃ₜ* Aut (F ⋙ G) where
__ := (h.whiskeringRight C).autMulEquivOfFullyFaithful F
continuous_toFun := continuous_mapAut_whiskeringRight F G
continuous_invFun := Continuous.continuous_symm_of_equiv_compact_to_t2
(f := ((h.whiskeringRight C).autMulEquivOfFullyFaithful F).toEquiv)
(continuous_mapAut_whiskeringRight F G)
variable [GaloisCategory C] [FiberFunctor F]
/--
If `H` is an open subset of `Aut F` such that `1 ∈ H`, there exists a finite
set `I` of connected objects of `C` such that every `σ : Aut F` that induces the identity
on `F.obj X` for all `X ∈ I` is contained in `H`. In other words: The kernel
of the evaluation map `Aut F →* ∏ X : I ↦ Aut (F.obj X)` is contained in `H`.
-/
lemma exists_set_ker_evaluation_subset_of_isOpen
{H : Set (Aut F)} (h1 : 1 ∈ H) (h : IsOpen H) :
∃ (I : Set C) (_ : Fintype I), (∀ X ∈ I, IsConnected X) ∧
(∀ σ : Aut F, (∀ X : I, σ.hom.app X = 𝟙 (F.obj X)) → σ ∈ H) := by
obtain ⟨U, hUopen, rfl⟩ := isOpen_induced_iff.mp h
obtain ⟨I, u, ho, ha⟩ := isOpen_pi_iff.mp hUopen 1 h1
choose fι ff fc h4 h5 h6 using (fun X : I => has_decomp_connected_components X.val)
refine ⟨⋃ X, Set.range (ff X), Fintype.ofFinite _, ?_, ?_⟩
· rintro X ⟨A, ⟨Y, rfl⟩, hA2⟩
obtain ⟨i, rfl⟩ := hA2
exact h5 Y i
· refine fun σ h ↦ ha (fun X XinI ↦ ?_)
suffices h : autEmbedding F σ X = 1 by
rw [h]
exact (ho X XinI).right
have h : σ.hom.app X = 𝟙 (F.obj X) := by
have : Fintype (fι ⟨X, XinI⟩) := Fintype.ofFinite _
ext x
obtain ⟨⟨j⟩, a, ha : F.map _ a = x⟩ := Limits.FintypeCat.jointly_surjective
(Discrete.functor (ff ⟨X, XinI⟩) ⋙ F) _ (Limits.isColimitOfPreserves F (h4 ⟨X, XinI⟩)) x
rw [FintypeCat.id_apply, ← ha, FunctorToFintypeCat.naturality]
simp [h ⟨(ff _) j, ⟨Set.range (ff ⟨X, XinI⟩), ⟨⟨_, rfl⟩, ⟨j, rfl⟩⟩⟩⟩]
exact Iso.ext h
open Limits
/-- The stabilizers of points in the fibers of Galois objects form a neighbourhood basis
of the identity in `Aut F`. -/
lemma nhds_one_has_basis_stabilizers : (nhds (1 : Aut F)).HasBasis (fun _ ↦ True)
(fun X : PointedGaloisObject F ↦ MulAction.stabilizer (Aut F) X.pt) where
mem_iff' S := by
rw [mem_nhds_iff]
refine ⟨?_, ?_⟩
· intro ⟨U, hU, hUopen, hUone⟩
obtain ⟨I, _, hc, hmem⟩ := exists_set_ker_evaluation_subset_of_isOpen F hUone hUopen
let P : C := ∏ᶜ fun X : I ↦ X.val
obtain ⟨A, a, hgal, hbij⟩ := exists_galois_representative F P
refine ⟨⟨A, a, hgal⟩, trivial, ?_⟩
intro t (ht : t.hom.app A a = a)
apply hU
apply hmem
haveI (X : I) : IsConnected X.val := hc X.val X.property
haveI (X : I) : Nonempty (F.obj X.val) := nonempty_fiber_of_isConnected F X
intro X
ext x
simp only [FintypeCat.id_apply]
obtain ⟨z, rfl⟩ :=
surjective_of_nonempty_fiber_of_isConnected F (Pi.π (fun X : I ↦ X.val) X) x
obtain ⟨f, rfl⟩ := hbij.surjective z
rw [FunctorToFintypeCat.naturality, FunctorToFintypeCat.naturality, ht]
· intro ⟨X, _, h⟩
exact ⟨MulAction.stabilizer (Aut F) X.pt, h, stabilizer_isOpen (Aut F) X.pt,
Subgroup.one_mem _⟩
end PreGaloisCategory
end CategoryTheory
|
TransferInstance.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
-/
import Mathlib.Algebra.Group.TransferInstance
import Mathlib.Algebra.GroupWithZero.InjSurj
/-!
# Transfer algebraic structures across `Equiv`s
This continues the pattern set in `Mathlib/Algebra/Group/TransferInstance.lean`.
-/
assert_not_exists MulAction Ring
universe u v
variable {α : Type u} {β : Type v}
namespace Equiv
variable (e : α ≃ β)
/-- Transfer `SemigroupWithZero` across an `Equiv` -/
protected abbrev semigroupWithZero [SemigroupWithZero β] : SemigroupWithZero α := by
let mul := e.mul
let zero := e.zero
apply e.injective.semigroupWithZero _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `MulZeroClass` across an `Equiv` -/
protected abbrev mulZeroClass [MulZeroClass β] : MulZeroClass α := by
let zero := e.zero
let mul := e.mul
apply e.injective.mulZeroClass _ <;> intros <;> exact e.apply_symm_apply _
/-- Transfer `MulZeroOneClass` across an `Equiv` -/
protected abbrev mulZeroOneClass [MulZeroOneClass β] : MulZeroOneClass α := by
let zero := e.zero
let one := e.one
let mul := e.mul
apply e.injective.mulZeroOneClass _ <;> intros <;> exact e.apply_symm_apply _
end Equiv
|
DFA.lean
|
/-
Copyright (c) 2020 Fox Thomson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Fox Thomson, Chris Wong
-/
import Mathlib.Computability.Language
import Mathlib.Data.Countable.Small
import Mathlib.Data.Fintype.Pigeonhole
import Mathlib.Tactic.NormNum
/-!
# Deterministic Finite Automata
A Deterministic Finite Automaton (DFA) is a state machine which
decides membership in a particular `Language`, by following a path
uniquely determined by an input string.
We define regular languages to be ones for which a DFA exists, other formulations
are later proved equivalent.
Note that this definition allows for automata with infinite states,
a `Fintype` instance must be supplied for true DFAs.
## Main definitions
- `DFA α σ`: automaton over alphabet `α` and set of states `σ`
- `M.accepts`: the language accepted by the DFA `M`
- `Language.IsRegular L`: a predicate stating that `L` is a regular language, i.e. there exists
a DFA that recognizes the language
## Main theorems
- `DFA.pumping_lemma` : every sufficiently long string accepted by the DFA has a substring that can
be repeated arbitrarily many times (and have the overall string still be accepted)
## Implementation notes
Currently, there are two disjoint sets of simp lemmas: one for `DFA.eval`, and another for
`DFA.evalFrom`. You can switch from the former to the latter using `simp [eval]`.
## TODO
- Should we unify these simp sets, such that `eval` is rewritten to `evalFrom` automatically?
- Should `mem_accepts` and `mem_acceptsFrom` be marked `@[simp]`?
-/
universe u v
open Computability
/-- A DFA is a set of states (`σ`), a transition function from state to state labelled by the
alphabet (`step`), a starting state (`start`) and a set of acceptance states (`accept`). -/
structure DFA (α : Type u) (σ : Type v) where
/-- A transition function from state to state labelled by the alphabet. -/
step : σ → α → σ
/-- Starting state. -/
start : σ
/-- Set of acceptance states. -/
accept : Set σ
namespace DFA
variable {α : Type u} {σ : Type v} (M : DFA α σ)
instance [Inhabited σ] : Inhabited (DFA α σ) :=
⟨DFA.mk (fun _ _ => default) default ∅⟩
/-- `M.evalFrom s x` evaluates `M` with input `x` starting from the state `s`. -/
def evalFrom (s : σ) : List α → σ :=
List.foldl M.step s
@[simp]
theorem evalFrom_nil (s : σ) : M.evalFrom s [] = s :=
rfl
@[simp]
theorem evalFrom_singleton (s : σ) (a : α) : M.evalFrom s [a] = M.step s a :=
rfl
@[simp]
theorem evalFrom_append_singleton (s : σ) (x : List α) (a : α) :
M.evalFrom s (x ++ [a]) = M.step (M.evalFrom s x) a := by
simp only [evalFrom, List.foldl_append, List.foldl_cons, List.foldl_nil]
/-- `M.eval x` evaluates `M` with input `x` starting from the state `M.start`. -/
def eval : List α → σ :=
M.evalFrom M.start
@[simp]
theorem eval_nil : M.eval [] = M.start :=
rfl
@[simp]
theorem eval_singleton (a : α) : M.eval [a] = M.step M.start a :=
rfl
@[simp]
theorem eval_append_singleton (x : List α) (a : α) : M.eval (x ++ [a]) = M.step (M.eval x) a :=
evalFrom_append_singleton _ _ _ _
theorem evalFrom_of_append (start : σ) (x y : List α) :
M.evalFrom start (x ++ y) = M.evalFrom (M.evalFrom start x) y :=
List.foldl_append
/--
`M.acceptsFrom s` is the language of `x` such that `M.evalFrom s x` is an accept state.
-/
def acceptsFrom (s : σ) : Language α := {x | M.evalFrom s x ∈ M.accept}
theorem mem_acceptsFrom {s : σ} {x : List α} :
x ∈ M.acceptsFrom s ↔ M.evalFrom s x ∈ M.accept := by rfl
/-- `M.accepts` is the language of `x` such that `M.eval x` is an accept state. -/
def accepts : Language α := M.acceptsFrom M.start
theorem mem_accepts {x : List α} : x ∈ M.accepts ↔ M.eval x ∈ M.accept := by rfl
theorem evalFrom_split [Fintype σ] {x : List α} {s t : σ} (hlen : Fintype.card σ ≤ x.length)
(hx : M.evalFrom s x = t) :
∃ q a b c,
x = a ++ b ++ c ∧
a.length + b.length ≤ Fintype.card σ ∧
b ≠ [] ∧ M.evalFrom s a = q ∧ M.evalFrom q b = q ∧ M.evalFrom q c = t := by
obtain ⟨n, m, hneq, heq⟩ :=
Fintype.exists_ne_map_eq_of_card_lt
(fun n : Fin (Fintype.card σ + 1) => M.evalFrom s (x.take n)) (by simp)
wlog hle : (n : ℕ) ≤ m generalizing n m
· exact this m n hneq.symm heq.symm (le_of_not_ge hle)
have hm : (m : ℕ) ≤ Fintype.card σ := Fin.is_le m
refine
⟨M.evalFrom s ((x.take m).take n), (x.take m).take n, (x.take m).drop n,
x.drop m, ?_, ?_, ?_, by rfl, ?_⟩
· rw [List.take_append_drop, List.take_append_drop]
· simp only [List.length_drop, List.length_take]
omega
· intro h
have hlen' := congr_arg List.length h
simp only [List.length_drop, List.length, List.length_take] at hlen'
omega
have hq : M.evalFrom (M.evalFrom s ((x.take m).take n)) ((x.take m).drop n) =
M.evalFrom s ((x.take m).take n) := by
rw [List.take_take, min_eq_left hle, ← evalFrom_of_append, heq, ← min_eq_left hle, ←
List.take_take, min_eq_left hle, List.take_append_drop]
use hq
rwa [← hq, ← evalFrom_of_append, ← evalFrom_of_append, ← List.append_assoc,
List.take_append_drop, List.take_append_drop]
theorem evalFrom_of_pow {x y : List α} {s : σ} (hx : M.evalFrom s x = s)
(hy : y ∈ ({x} : Language α)∗) : M.evalFrom s y = s := by
rw [Language.mem_kstar] at hy
rcases hy with ⟨S, rfl, hS⟩
induction S with
| nil => rfl
| cons a S ih =>
have ha := hS a List.mem_cons_self
rw [Set.mem_singleton_iff] at ha
rw [List.flatten, evalFrom_of_append, ha, hx]
apply ih
intro z hz
exact hS z (List.mem_cons_of_mem a hz)
theorem pumping_lemma [Fintype σ] {x : List α} (hx : x ∈ M.accepts)
(hlen : Fintype.card σ ≤ List.length x) :
∃ a b c,
x = a ++ b ++ c ∧
a.length + b.length ≤ Fintype.card σ ∧ b ≠ [] ∧ {a} * {b}∗ * {c} ≤ M.accepts := by
obtain ⟨_, a, b, c, hx, hlen, hnil, rfl, hb, hc⟩ := M.evalFrom_split (s := M.start) hlen rfl
use a, b, c, hx, hlen, hnil
intro y hy
rw [Language.mem_mul] at hy
rcases hy with ⟨ab, hab, c', hc', rfl⟩
rw [Language.mem_mul] at hab
rcases hab with ⟨a', ha', b', hb', rfl⟩
rw [Set.mem_singleton_iff] at ha' hc'
substs ha' hc'
have h := M.evalFrom_of_pow hb hb'
rwa [mem_accepts, eval, evalFrom_of_append, evalFrom_of_append, h, hc]
section Maps
variable {α' σ' : Type*}
/--
`M.comap f` pulls back the alphabet of `M` along `f`. In other words, it applies `f` to the input
before passing it to `M`.
-/
@[simps]
def comap (f : α' → α) (M : DFA α σ) : DFA α' σ where
step s a := M.step s (f a)
start := M.start
accept := M.accept
@[simp]
theorem comap_id : M.comap id = M := rfl
@[simp]
theorem evalFrom_comap (f : α' → α) (s : σ) (x : List α') :
(M.comap f).evalFrom s x = M.evalFrom s (x.map f) := by
induction x using List.reverseRecOn with
| nil => simp
| append_singleton x a ih => simp [ih]
@[simp]
theorem eval_comap (f : α' → α) (x : List α') : (M.comap f).eval x = M.eval (x.map f) := by
simp [eval]
@[simp]
theorem accepts_comap (f : α' → α) : (M.comap f).accepts = List.map f ⁻¹' M.accepts := by
ext x
conv =>
rhs
rw [Set.mem_preimage, mem_accepts]
simp [mem_accepts]
/-- Lifts an equivalence on states to an equivalence on DFAs. -/
@[simps apply_step apply_start apply_accept]
def reindex (g : σ ≃ σ') : DFA α σ ≃ DFA α σ' where
toFun M := {
step := fun s a => g (M.step (g.symm s) a)
start := g M.start
accept := g.symm ⁻¹' M.accept
}
invFun M := {
step := fun s a => g.symm (M.step (g s) a)
start := g.symm M.start
accept := g ⁻¹' M.accept
}
left_inv M := by simp
right_inv M := by simp
@[simp]
theorem reindex_refl : reindex (Equiv.refl σ) M = M := rfl
@[simp]
theorem symm_reindex (g : σ ≃ σ') : (reindex (α := α) g).symm = reindex g.symm := rfl
@[simp]
theorem evalFrom_reindex (g : σ ≃ σ') (s : σ') (x : List α) :
(reindex g M).evalFrom s x = g (M.evalFrom (g.symm s) x) := by
induction x using List.reverseRecOn with
| nil => simp
| append_singleton x a ih => simp [ih]
@[simp]
theorem eval_reindex (g : σ ≃ σ') (x : List α) : (reindex g M).eval x = g (M.eval x) := by
simp [eval]
@[simp]
theorem accepts_reindex (g : σ ≃ σ') : (reindex g M).accepts = M.accepts := by
ext x
simp [mem_accepts]
theorem comap_reindex (f : α' → α) (g : σ ≃ σ') :
(reindex g M).comap f = reindex g (M.comap f) := by
simp [comap, reindex]
end Maps
end DFA
/-- A regular language is a language that is defined by a DFA with finite states. -/
def Language.IsRegular {T : Type u} (L : Language T) : Prop :=
∃ σ : Type, ∃ _ : Fintype σ, ∃ M : DFA T σ, M.accepts = L
/-- Lifts the state type `σ` inside `Language.IsRegular` to a different universe. -/
private lemma Language.isRegular_iff.helper.{v'} {T : Type u} {L : Language T}
(hL : ∃ σ : Type v, ∃ _ : Fintype σ, ∃ M : DFA T σ, M.accepts = L) :
∃ σ' : Type v', ∃ _ : Fintype σ', ∃ M : DFA T σ', M.accepts = L :=
have ⟨σ, _, M, hM⟩ := hL
have ⟨σ', ⟨f⟩⟩ := Small.equiv_small.{v', v} (α := σ)
⟨σ', Fintype.ofEquiv σ f, M.reindex f, hM ▸ DFA.accepts_reindex M f⟩
/--
A language is regular if and only if it is defined by a DFA with finite states.
This is more general than using the definition of `Language.IsRegular` directly, as the state type
`σ` is universe-polymorphic.
-/
theorem Language.isRegular_iff {T : Type u} {L : Language T} :
L.IsRegular ↔ ∃ σ : Type v, ∃ _ : Fintype σ, ∃ M : DFA T σ, M.accepts = L :=
⟨Language.isRegular_iff.helper, Language.isRegular_iff.helper⟩
|
Finsupp.lean
|
/-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import Mathlib.Algebra.DirectSum.Module
import Mathlib.Data.Finsupp.ToDFinsupp
/-!
# Results on direct sums and finitely supported functions.
1. The linear equivalence between finitely supported functions `ι →₀ M` and
the direct sum of copies of `M` indexed by `ι`.
-/
universe u v w
noncomputable section
open DirectSum
open LinearMap Submodule
variable {R : Type u} {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M]
section finsuppLequivDirectSum
variable (R M) (ι : Type*) [DecidableEq ι]
/-- The finitely supported functions `ι →₀ M` are in linear equivalence with the direct sum of
copies of M indexed by ι. -/
def finsuppLEquivDirectSum : (ι →₀ M) ≃ₗ[R] ⨁ _ : ι, M :=
haveI : ∀ m : M, Decidable (m ≠ 0) := Classical.decPred _
finsuppLequivDFinsupp R
@[simp]
theorem finsuppLEquivDirectSum_single (i : ι) (m : M) :
finsuppLEquivDirectSum R M ι (Finsupp.single i m) = DirectSum.lof R ι _ i m :=
Finsupp.toDFinsupp_single i m
@[simp]
theorem finsuppLEquivDirectSum_symm_lof (i : ι) (m : M) :
(finsuppLEquivDirectSum R M ι).symm (DirectSum.lof R ι _ i m) = Finsupp.single i m :=
letI : ∀ m : M, Decidable (m ≠ 0) := Classical.decPred _
DFinsupp.toFinsupp_single i m
end finsuppLequivDirectSum
|
Functoriality.lean
|
/-
Copyright (c) 2025 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.RepresentationTheory.Homological.GroupCohomology.Functoriality
deprecated_module (since := "2025-06-14")
|
CompleteLat.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.Order.Category.BddLat
import Mathlib.Order.Hom.CompleteLattice
/-!
# The category of complete lattices
This file defines `CompleteLat`, the category of complete lattices.
-/
universe u
open CategoryTheory
/-- The category of complete lattices. -/
structure CompleteLat where
/-- The underlying lattice. -/
(carrier : Type*)
[str : CompleteLattice carrier]
attribute [instance] CompleteLat.str
initialize_simps_projections CompleteLat (carrier → coe, -str)
namespace CompleteLat
instance : CoeSort CompleteLat (Type _) :=
⟨CompleteLat.carrier⟩
attribute [coe] CompleteLat.carrier
/-- Construct a bundled `CompleteLat` from the underlying type and typeclass. -/
abbrev of (X : Type*) [CompleteLattice X] : CompleteLat := ⟨X⟩
theorem coe_of (α : Type*) [CompleteLattice α] : ↥(of α) = α :=
rfl
instance : Inhabited CompleteLat :=
⟨of PUnit⟩
instance : LargeCategory.{u} CompleteLat where
Hom X Y := CompleteLatticeHom X Y
id X := CompleteLatticeHom.id X
comp f g := g.comp f
instance : ConcreteCategory CompleteLat (CompleteLatticeHom · ·) where
hom f := f
ofHom f := f
instance hasForgetToBddLat : HasForget₂ CompleteLat BddLat where
forget₂.obj X := .of X
forget₂.map f := BddLat.ofHom (CompleteLatticeHom.toBoundedLatticeHom f)
/-- Constructs an isomorphism of complete lattices from an order isomorphism between them. -/
@[simps]
def Iso.mk {α β : CompleteLat.{u}} (e : α ≃o β) : α ≅ β where
hom := ConcreteCategory.ofHom e
inv := ConcreteCategory.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 : CompleteLat ⥤ CompleteLat where
obj X := of Xᵒᵈ
map {_ _} := CompleteLatticeHom.dual
/-- The equivalence between `CompleteLat` and itself induced by `OrderDual` both ways. -/
@[simps functor inverse]
def dualEquiv : CompleteLat ≌ CompleteLat where
functor := dual
inverse := dual
unitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
counitIso := NatIso.ofComponents fun X => Iso.mk <| OrderIso.dualDual X
end CompleteLat
theorem completeLat_dual_comp_forget_to_bddLat :
CompleteLat.dual ⋙ forget₂ CompleteLat BddLat =
forget₂ CompleteLat BddLat ⋙ BddLat.dual :=
rfl
|
Complex.lean
|
/-
Copyright (c) 2025 Miyahara Kō. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Miyahara Kō
-/
import Mathlib.Analysis.CStarAlgebra.Classes
import Mathlib.Analysis.Meromorphic.NormalForm
import Mathlib.Analysis.SpecialFunctions.Gamma.Beta
/-!
# The Gamma function is meromorphic
-/
open Set Complex
lemma MeromorphicNFOn.Gamma : MeromorphicNFOn Gamma univ :=
meromorphicNFOn_inv.mp <| AnalyticOnNhd.meromorphicNFOn <|
analyticOnNhd_univ_iff_differentiable.mpr differentiable_one_div_Gamma
lemma MeromorphicOn.Gamma : MeromorphicOn Gamma univ :=
MeromorphicNFOn.Gamma.meromorphicOn
|
Basic.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import Mathlib.Algebra.BigOperators.Group.List.Basic
import Mathlib.Algebra.Group.Pi.Basic
import Mathlib.Algebra.Group.Subgroup.Ker
import Mathlib.Data.List.Chain
/-!
# Free groups
This file defines free groups over a type. Furthermore, it is shown that the free group construction
is an instance of a monad. For the result that `FreeGroup` is the left adjoint to the forgetful
functor from groups to types, see `Mathlib/Algebra/Category/Grp/Adjunctions.lean`.
## Main definitions
* `FreeGroup`/`FreeAddGroup`: the free group (resp. free additive group) associated to a type
`α` defined as the words over `a : α × Bool` modulo the relation `a * x * x⁻¹ * b = a * b`.
* `FreeGroup.mk`/`FreeAddGroup.mk`: the canonical quotient map `List (α × Bool) → FreeGroup α`.
* `FreeGroup.of`/`FreeAddGroup.of`: the canonical injection `α → FreeGroup α`.
* `FreeGroup.lift f`/`FreeAddGroup.lift`: the canonical group homomorphism `FreeGroup α →* G`
given a group `G` and a function `f : α → G`.
## Main statements
* `FreeGroup.Red.church_rosser`/`FreeAddGroup.Red.church_rosser`: The Church-Rosser theorem for word
reduction (also known as Newman's diamond lemma).
* `FreeGroup.freeGroupUnitEquivInt`: The free group over the one-point type
is isomorphic to the integers.
* The free group construction is an instance of a monad.
## Implementation details
First we introduce the one step reduction relation `FreeGroup.Red.Step`:
`w * x * x⁻¹ * v ~> w * v`, its reflexive transitive closure `FreeGroup.Red.trans`
and prove that its join is an equivalence relation. Then we introduce `FreeGroup α` as a quotient
over `FreeGroup.Red.Step`.
For the additive version we introduce the same relation under a different name so that we can
distinguish the quotient types more easily.
## Tags
free group, Newman's diamond lemma, Church-Rosser theorem
-/
open Relation
open scoped List
universe u v w
variable {α : Type u}
attribute [local simp] List.append_eq_has_append
-- Porting note: to_additive.map_namespace is not supported yet
-- worked around it by putting a few extra manual mappings (but not too many all in all)
-- run_cmd to_additive.map_namespace `FreeGroup `FreeAddGroup
/-- Reduction step for the additive free group relation: `w + x + (-x) + v ~> w + v` -/
inductive FreeAddGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeAddGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeAddGroup.Red.Step.not
/-- Reduction step for the multiplicative free group relation: `w * x * x⁻¹ * v ~> w * v` -/
@[to_additive FreeAddGroup.Red.Step]
inductive FreeGroup.Red.Step : List (α × Bool) → List (α × Bool) → Prop
| not {L₁ L₂ x b} : FreeGroup.Red.Step (L₁ ++ (x, b) :: (x, not b) :: L₂) (L₁ ++ L₂)
attribute [simp] FreeGroup.Red.Step.not
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- Reflexive-transitive closure of `Red.Step` -/
@[to_additive FreeAddGroup.Red /-- Reflexive-transitive closure of `Red.Step` -/]
def Red : List (α × Bool) → List (α × Bool) → Prop :=
ReflTransGen Red.Step
@[to_additive (attr := refl)]
theorem Red.refl : Red L L :=
ReflTransGen.refl
@[to_additive (attr := trans)]
theorem Red.trans : Red L₁ L₂ → Red L₂ L₃ → Red L₁ L₃ :=
ReflTransGen.trans
namespace Red
/-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e. there are words
`w₃ w₄` and letter `x` such that `w₁ = w₃xx⁻¹w₄` and `w₂ = w₃w₄` -/
@[to_additive /-- Predicate asserting that the word `w₁` can be reduced to `w₂` in one step, i.e.
there are words `w₃ w₄` and letter `x` such that `w₁ = w₃ + x + (-x) + w₄` and `w₂ = w₃w₄` -/]
theorem Step.length : ∀ {L₁ L₂ : List (α × Bool)}, Step L₁ L₂ → L₂.length + 2 = L₁.length
| _, _, @Red.Step.not _ L1 L2 x b => by rw [List.length_append, List.length_append]; rfl
@[to_additive (attr := simp)]
theorem Step.not_rev {x b} : Step (L₁ ++ (x, !b) :: (x, b) :: L₂) (L₁ ++ L₂) := by
cases b <;> exact Step.not
@[to_additive (attr := simp)]
theorem Step.cons_not {x b} : Red.Step ((x, b) :: (x, !b) :: L) L :=
@Step.not _ [] _ _ _
@[to_additive (attr := simp)]
theorem Step.cons_not_rev {x b} : Red.Step ((x, !b) :: (x, b) :: L) L :=
@Red.Step.not_rev _ [] _ _ _
@[to_additive]
theorem Step.append_left : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₂ L₃ → Step (L₁ ++ L₂) (L₁ ++ L₃)
| _, _, _, Red.Step.not => by rw [← List.append_assoc, ← List.append_assoc]; constructor
@[to_additive]
theorem Step.cons {x} (H : Red.Step L₁ L₂) : Red.Step (x :: L₁) (x :: L₂) :=
@Step.append_left _ [x] _ _ H
@[to_additive]
theorem Step.append_right : ∀ {L₁ L₂ L₃ : List (α × Bool)}, Step L₁ L₂ → Step (L₁ ++ L₃) (L₂ ++ L₃)
| _, _, _, Red.Step.not => by simp
@[to_additive]
theorem not_step_nil : ¬Step [] L := by
generalize h' : [] = L'
intro h
rcases h with - | ⟨L₁, L₂⟩
simp at h'
@[to_additive]
theorem Step.cons_left_iff {a : α} {b : Bool} :
Step ((a, b) :: L₁) L₂ ↔ (∃ L, Step L₁ L ∧ L₂ = (a, b) :: L) ∨ L₁ = (a, ! b) :: L₂ := by
constructor
· generalize hL : ((a, b) :: L₁ : List _) = L
rintro @⟨_ | ⟨p, s'⟩, e, a', b'⟩ <;> simp_all
· rintro (⟨L, h, rfl⟩ | rfl)
· exact Step.cons h
· exact Step.cons_not
@[to_additive]
theorem not_step_singleton : ∀ {p : α × Bool}, ¬Step [p] L
| (a, b) => by simp [Step.cons_left_iff, not_step_nil]
@[to_additive]
theorem Step.cons_cons_iff : ∀ {p : α × Bool}, Step (p :: L₁) (p :: L₂) ↔ Step L₁ L₂ := by
simp +contextual [Step.cons_left_iff, iff_def, or_imp]
@[to_additive]
theorem Step.append_left_iff : ∀ L, Step (L ++ L₁) (L ++ L₂) ↔ Step L₁ L₂
| [] => by simp
| p :: l => by simp [Step.append_left_iff l, Step.cons_cons_iff]
@[to_additive]
theorem Step.diamond_aux :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)} {x1 b1 x2 b2},
L₁ ++ (x1, b1) :: (x1, !b1) :: L₂ = L₃ ++ (x2, b2) :: (x2, !b2) :: L₄ →
L₁ ++ L₂ = L₃ ++ L₄ ∨ ∃ L₅, Red.Step (L₁ ++ L₂) L₅ ∧ Red.Step (L₃ ++ L₄) L₅
| [], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, [(x3, b3)], _, _, _, _, _, H => by injections; subst_vars; simp
| [(x3, b3)], _, [], _, _, _, _, _, H => by injections; subst_vars; simp
| [], _, (x3, b3) :: (x4, b4) :: tl, _, _, _, _, _, H => by
injections; subst_vars; right; exact ⟨_, Red.Step.not, Red.Step.cons_not⟩
| (x3, b3) :: (x4, b4) :: tl, _, [], _, _, _, _, _, H => by
injections; subst_vars; right; simpa using ⟨_, Red.Step.cons_not, Red.Step.not⟩
| (x3, b3) :: tl, _, (x4, b4) :: tl2, _, _, _, _, _, H =>
let ⟨H1, H2⟩ := List.cons.inj H
match Step.diamond_aux H2 with
| Or.inl H3 => Or.inl <| by simp [H1, H3]
| Or.inr ⟨L₅, H3, H4⟩ => Or.inr ⟨_, Step.cons H3, by simpa [H1] using Step.cons H4⟩
@[to_additive]
theorem Step.diamond :
∀ {L₁ L₂ L₃ L₄ : List (α × Bool)},
Red.Step L₁ L₃ → Red.Step L₂ L₄ → L₁ = L₂ → L₃ = L₄ ∨ ∃ L₅, Red.Step L₃ L₅ ∧ Red.Step L₄ L₅
| _, _, _, _, Red.Step.not, Red.Step.not, H => Step.diamond_aux H
@[to_additive]
theorem Step.to_red : Step L₁ L₂ → Red L₁ L₂ :=
ReflTransGen.single
/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma. -/
@[to_additive
/-- **Church-Rosser theorem** for word reduction: If `w1 w2 w3` are words such that `w1` reduces
to `w2` and `w3` respectively, then there is a word `w4` such that `w2` and `w3` reduce to `w4`
respectively. This is also known as Newman's diamond lemma. -/]
theorem church_rosser : Red L₁ L₂ → Red L₁ L₃ → Join Red L₂ L₃ :=
Relation.church_rosser fun _ b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, hcd.to_red⟩
@[to_additive]
theorem cons_cons {p} : Red L₁ L₂ → Red (p :: L₁) (p :: L₂) :=
ReflTransGen.lift (List.cons p) fun _ _ => Step.cons
@[to_additive]
theorem cons_cons_iff (p) : Red (p :: L₁) (p :: L₂) ↔ Red L₁ L₂ :=
Iff.intro
(by
generalize eq₁ : (p :: L₁ : List _) = LL₁
generalize eq₂ : (p :: L₂ : List _) = LL₂
intro h
induction h using Relation.ReflTransGen.head_induction_on generalizing L₁ L₂ with
| refl =>
subst_vars
cases eq₂
constructor
| head h₁₂ h ih =>
subst_vars
obtain ⟨a, b⟩ := p
rw [Step.cons_left_iff] at h₁₂
rcases h₁₂ with (⟨L, h₁₂, rfl⟩ | rfl)
· exact (ih rfl rfl).head h₁₂
· exact (cons_cons h).tail Step.cons_not_rev)
cons_cons
@[to_additive]
theorem append_append_left_iff : ∀ L, Red (L ++ L₁) (L ++ L₂) ↔ Red L₁ L₂
| [] => Iff.rfl
| p :: L => by simp [append_append_left_iff L, cons_cons_iff]
@[to_additive]
theorem append_append (h₁ : Red L₁ L₃) (h₂ : Red L₂ L₄) : Red (L₁ ++ L₂) (L₃ ++ L₄) :=
(h₁.lift (fun L => L ++ L₂) fun _ _ => Step.append_right).trans ((append_append_left_iff _).2 h₂)
@[to_additive]
theorem to_append_iff : Red L (L₁ ++ L₂) ↔ ∃ L₃ L₄, L = L₃ ++ L₄ ∧ Red L₃ L₁ ∧ Red L₄ L₂ :=
Iff.intro
(by
generalize eq : L₁ ++ L₂ = L₁₂
intro h
induction h generalizing L₁ L₂ with
| refl => exact ⟨_, _, eq.symm, by rfl, by rfl⟩
| tail hLL' h ih =>
obtain @⟨s, e, a, b⟩ := h
rcases List.append_eq_append_iff.1 eq with (⟨s', rfl, rfl⟩ | ⟨e', rfl, rfl⟩)
· have : L₁ ++ (s' ++ (a, b) :: (a, not b) :: e) = L₁ ++ s' ++ (a, b) :: (a, not b) :: e :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁, h₂.tail Step.not⟩
· have : s ++ (a, b) :: (a, not b) :: e' ++ L₂ = s ++ (a, b) :: (a, not b) :: (e' ++ L₂) :=
by simp
rcases ih this with ⟨w₁, w₂, rfl, h₁, h₂⟩
exact ⟨w₁, w₂, rfl, h₁.tail Step.not, h₂⟩)
fun ⟨_, _, Eq, h₃, h₄⟩ => Eq.symm ▸ append_append h₃ h₄
/-- The empty word `[]` only reduces to itself. -/
@[to_additive /-- The empty word `[]` only reduces to itself. -/]
theorem nil_iff : Red [] L ↔ L = [] :=
reflTransGen_iff_eq fun _ => Red.not_step_nil
/-- A letter only reduces to itself. -/
@[to_additive /-- A letter only reduces to itself. -/]
theorem singleton_iff {x} : Red [x] L₁ ↔ L₁ = [x] :=
reflTransGen_iff_eq fun _ => not_step_singleton
/-- If `x` is a letter and `w` is a word such that `xw` reduces to the empty word, then `w` reduces
to `x⁻¹` -/
@[to_additive
/-- If `x` is a letter and `w` is a word such that `x + w` reduces to the empty word, then `w`
reduces to `-x`. -/]
theorem cons_nil_iff_singleton {x b} : Red ((x, b) :: L) [] ↔ Red L [(x, not b)] :=
Iff.intro
(fun h => by
have h₁ : Red ((x, not b) :: (x, b) :: L) [(x, not b)] := cons_cons h
have h₂ : Red ((x, not b) :: (x, b) :: L) L := ReflTransGen.single Step.cons_not_rev
let ⟨L', h₁, h₂⟩ := church_rosser h₁ h₂
rw [singleton_iff] at h₁
subst L'
assumption)
fun h => (cons_cons h).tail Step.cons_not
@[to_additive]
theorem red_iff_irreducible {x1 b1 x2 b2} (h : (x1, b1) ≠ (x2, b2)) :
Red [(x1, !b1), (x2, b2)] L ↔ L = [(x1, !b1), (x2, b2)] := by
apply reflTransGen_iff_eq
generalize eq : [(x1, not b1), (x2, b2)] = L'
intro L h'
cases h'
simp only [List.cons_eq_append_iff, List.cons.injEq, Prod.mk.injEq, and_false,
List.nil_eq_append_iff, exists_const, or_self, or_false, List.cons_ne_nil] at eq
rcases eq with ⟨rfl, ⟨rfl, rfl⟩, ⟨rfl, rfl⟩, rfl⟩
simp at h
/-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `xw₁` reduces to `yw₂`, then
`w₁` reduces to `x⁻¹yw₂`. -/
@[to_additive /-- If `x` and `y` are distinct letters and `w₁ w₂` are words such that `x + w₁`
reduces to `y + w₂`, then `w₁` reduces to `-x + y + w₂`. -/]
theorem inv_of_red_of_ne {x1 b1 x2 b2} (H1 : (x1, b1) ≠ (x2, b2))
(H2 : Red ((x1, b1) :: L₁) ((x2, b2) :: L₂)) : Red L₁ ((x1, not b1) :: (x2, b2) :: L₂) := by
have : Red ((x1, b1) :: L₁) ([(x2, b2)] ++ L₂) := H2
rcases to_append_iff.1 this with ⟨_ | ⟨p, L₃⟩, L₄, eq, h₁, h₂⟩
· simp [nil_iff] at h₁
· cases eq
change Red (L₃ ++ L₄) ([(x1, not b1), (x2, b2)] ++ L₂)
apply append_append _ h₂
have h₁ : Red ((x1, not b1) :: (x1, b1) :: L₃) [(x1, not b1), (x2, b2)] := cons_cons h₁
have h₂ : Red ((x1, not b1) :: (x1, b1) :: L₃) L₃ := Step.cons_not_rev.to_red
rcases church_rosser h₁ h₂ with ⟨L', h₁, h₂⟩
rw [red_iff_irreducible H1] at h₁
rwa [h₁] at h₂
open List -- for <+ notation
@[to_additive]
theorem Step.sublist (H : Red.Step L₁ L₂) : L₂ <+ L₁ := by
cases H; simp
/-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/
@[to_additive
/-- If `w₁ w₂` are words such that `w₁` reduces to `w₂`, then `w₂` is a sublist of `w₁`. -/]
protected theorem sublist : Red L₁ L₂ → L₂ <+ L₁ :=
@reflTransGen_of_transitive_reflexive
_ (fun a b => b <+ a) _ _ _
(fun l => List.Sublist.refl l)
(fun _a _b _c hab hbc => List.Sublist.trans hbc hab)
(fun _ _ => Red.Step.sublist)
@[to_additive]
theorem length_le (h : Red L₁ L₂) : L₂.length ≤ L₁.length :=
h.sublist.length_le
@[to_additive]
theorem sizeof_of_step : ∀ {L₁ L₂ : List (α × Bool)},
Step L₁ L₂ → sizeOf L₂ < sizeOf L₁
| _, _, @Step.not _ L1 L2 x b => by
induction L1 with
| nil =>
dsimp
omega
| cons hd tl ih =>
dsimp
exact Nat.add_lt_add_left ih _
@[to_additive]
theorem length (h : Red L₁ L₂) : ∃ n, L₁.length = L₂.length + 2 * n := by
induction h with
| refl => exact ⟨0, rfl⟩
| tail _h₁₂ h₂₃ ih =>
rcases ih with ⟨n, eq⟩
exists 1 + n
simp [Nat.mul_add, eq, (Step.length h₂₃).symm, add_assoc]
@[to_additive]
theorem antisymm (h₁₂ : Red L₁ L₂) (h₂₁ : Red L₂ L₁) : L₁ = L₂ :=
h₂₁.sublist.antisymm h₁₂.sublist
end Red
@[to_additive FreeAddGroup.equivalence_join_red]
theorem equivalence_join_red : Equivalence (Join (@Red α)) :=
equivalence_join_reflTransGen fun _ b c hab hac =>
match b, c, Red.Step.diamond hab hac rfl with
| b, _, Or.inl rfl => ⟨b, by rfl, by rfl⟩
| _, _, Or.inr ⟨d, hbd, hcd⟩ => ⟨d, ReflGen.single hbd, ReflTransGen.single hcd⟩
@[to_additive FreeAddGroup.join_red_of_step]
theorem join_red_of_step (h : Red.Step L₁ L₂) : Join Red L₁ L₂ :=
join_of_single reflexive_reflTransGen h.to_red
@[to_additive FreeAddGroup.eqvGen_step_iff_join_red]
theorem eqvGen_step_iff_join_red : EqvGen Red.Step L₁ L₂ ↔ Join Red L₁ L₂ :=
Iff.intro
(fun h =>
have : EqvGen (Join Red) L₁ L₂ := h.mono fun _ _ => join_red_of_step
equivalence_join_red.eqvGen_iff.1 this)
(join_of_equivalence (Relation.EqvGen.is_equivalence _) fun _ _ =>
reflTransGen_of_equivalence (Relation.EqvGen.is_equivalence _) EqvGen.rel)
/-! ### Reduced words -/
/-- Predicate asserting that the word `L` admits no reduction steps, i.e., no two neighboring
elements of the word cancel. -/
@[to_additive FreeAddGroup.IsReduced /-- Predicate asserting the word `L` admits no reduction steps,
i.e., no two neighboring elements of the word cancel. -/]
def IsReduced (L : List (α × Bool)) : Prop := L.Chain' fun a b ↦ a.1 = b.1 → a.2 = b.2
section IsReduced
open List
@[to_additive (attr := simp)]
theorem IsReduced.nil : IsReduced ([] : List (α × Bool)) := chain'_nil
@[to_additive (attr := simp)]
theorem IsReduced.singleton {a : α × Bool} : IsReduced [a] := chain'_singleton a
@[to_additive (attr := simp) FreeAddGroup.isReduced_cons_cons]
theorem isReduced_cons_cons {a b : (α × Bool)} :
IsReduced (a :: b :: L) ↔ (a.1 = b.1 → a.2 = b.2) ∧ IsReduced (b :: L) := chain'_cons_cons
@[to_additive]
theorem IsReduced.not_step (h : IsReduced L₁) : ¬ Red.Step L₁ L₂ := fun step ↦ by
induction step
simp [IsReduced] at h
@[to_additive]
lemma IsReduced.of_forall_not_step :
∀ {L₁ : List (α × Bool)}, (∀ L₂, ¬ Red.Step L₁ L₂) → IsReduced L₁
| [], _ => .nil
| [a], _ => .singleton
| (a₁, b₁) :: (a₂, b₂) :: L₁, hL₁ => by
rw [isReduced_cons_cons]
refine ⟨?_, .of_forall_not_step fun L₂ step ↦ hL₁ _ step.cons⟩
rintro rfl
symm
rw [← Bool.ne_not]
rintro rfl
exact hL₁ L₁ <| .not (L₁ := [])
@[to_additive FreeAddGroup.isReduced_iff_not_step]
theorem isReduced_iff_not_step : IsReduced L₁ ↔ ∀ L₂, ¬ Red.Step L₁ L₂ where
mp h _ := h.not_step
mpr := .of_forall_not_step
@[to_additive]
theorem IsReduced.red_iff_eq (h : IsReduced L₁) : Red L₁ L₂ ↔ L₂ = L₁ :=
Relation.reflTransGen_iff_eq fun _ => h.not_step
@[to_additive]
theorem IsReduced.append_overlap {L₁ L₂ L₃ : List (α × Bool)} (h₁ : IsReduced (L₁ ++ L₂))
(h₂ : IsReduced (L₂ ++ L₃)) (hn : L₂ ≠ []) : IsReduced (L₁ ++ L₂ ++ L₃) :=
Chain'.append_overlap h₁ h₂ hn
@[to_additive]
theorem IsReduced.infix (h : IsReduced L₂) (h' : L₁ <:+: L₂) : IsReduced L₁ := Chain'.infix h h'
end IsReduced
end FreeGroup
/--
If `α` is a type, then `FreeGroup α` is the free group generated by `α`.
This is a group equipped with a function `FreeGroup.of : α → FreeGroup α` which has
the following universal property: if `G` is any group, and `f : α → G` is any function,
then this function is the composite of `FreeGroup.of` and a unique group homomorphism
`FreeGroup.lift f : FreeGroup α →* G`.
A typical element of `FreeGroup α` is a formal product of
elements of `α` and their formal inverses, quotient by reduction.
For example if `x` and `y` are terms of type `α` then `x⁻¹ * y * y * x * y⁻¹` is a
"typical" element of `FreeGroup α`. In particular if `α` is empty
then `FreeGroup α` is isomorphic to the trivial group, and if `α` has one term
then `FreeGroup α` is isomorphic to `Multiplicative ℤ`.
If `α` has two or more terms then `FreeGroup α` is not commutative.
-/
@[to_additive
/-- If `α` is a type, then `FreeAddGroup α` is the free additive group generated by `α`.
This is a group equipped with a function `FreeAddGroup.of : α → FreeAddGroup α` which has
the following universal property: if `G` is any group, and `f : α → G` is any function,
then this function is the composite of `FreeAddGroup.of` and a unique group homomorphism
`FreeAddGroup.lift f : FreeAddGroup α →+ G`.
A typical element of `FreeAddGroup α` is a formal sum of
elements of `α` and their formal inverses, quotient by reduction.
For example if `x` and `y` are terms of type `α` then `-x + y + y + x + -y` is a
"typical" element of `FreeAddGroup α`. In particular if `α` is empty
then `FreeAddGroup α` is isomorphic to the trivial group, and if `α` has one term
then `FreeAddGroup α` is isomorphic to `ℤ`.
If `α` has two or more terms then `FreeAddGroup α` is not commutative. -/]
def FreeGroup (α : Type u) : Type u :=
Quot <| @FreeGroup.Red.Step α
namespace FreeGroup
variable {L L₁ L₂ L₃ L₄ : List (α × Bool)}
/-- The canonical map from `List (α × Bool)` to the free group on `α`. -/
@[to_additive /-- The canonical map from `List (α × Bool)` to the free additive group on `α`. -/]
def mk (L : List (α × Bool)) : FreeGroup α :=
Quot.mk Red.Step L
@[to_additive (attr := simp)]
theorem quot_mk_eq_mk : Quot.mk Red.Step L = mk L :=
rfl
@[to_additive (attr := simp)]
theorem quot_lift_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.lift f H (mk L) = f L :=
rfl
@[to_additive (attr := simp)]
theorem quot_liftOn_mk (β : Type v) (f : List (α × Bool) → β)
(H : ∀ L₁ L₂, Red.Step L₁ L₂ → f L₁ = f L₂) : Quot.liftOn (mk L) f H = f L :=
rfl
open scoped Relator in
@[to_additive (attr := simp)]
theorem quot_map_mk (β : Type v) (f : List (α × Bool) → List (β × Bool))
(H : (Red.Step ⇒ Red.Step) f f) : Quot.map f H (mk L) = mk (f L) :=
rfl
@[to_additive]
instance : One (FreeGroup α) :=
⟨mk []⟩
@[to_additive]
theorem one_eq_mk : (1 : FreeGroup α) = mk [] :=
rfl
@[to_additive]
instance : Inhabited (FreeGroup α) :=
⟨1⟩
@[to_additive]
instance [IsEmpty α] : Unique (FreeGroup α) := by unfold FreeGroup; infer_instance
@[to_additive]
instance : Mul (FreeGroup α) :=
⟨fun x y =>
Quot.liftOn x
(fun L₁ =>
Quot.liftOn y (fun L₂ => mk <| L₁ ++ L₂) fun _L₂ _L₃ H =>
Quot.sound <| Red.Step.append_left H)
fun _L₁ _L₂ H => Quot.inductionOn y fun _L₃ => Quot.sound <| Red.Step.append_right H⟩
@[to_additive (attr := simp)]
theorem mul_mk : mk L₁ * mk L₂ = mk (L₁ ++ L₂) :=
rfl
/-- Transform a word representing a free group element into a word representing its inverse. -/
@[to_additive /-- Transform a word representing a free group element into a word representing its
negative. -/]
def invRev (w : List (α × Bool)) : List (α × Bool) :=
(List.map (fun g : α × Bool => (g.1, not g.2)) w).reverse
@[to_additive (attr := simp)]
theorem invRev_length : (invRev L₁).length = L₁.length := by simp [invRev]
@[to_additive (attr := simp)]
theorem invRev_invRev : invRev (invRev L₁) = L₁ := by
simp [invRev, List.map_reverse, Function.comp_def]
@[to_additive (attr := simp)]
theorem invRev_empty : invRev ([] : List (α × Bool)) = [] :=
rfl
@[to_additive (attr := simp)]
theorem invRev_append : invRev (L₁ ++ L₂) = invRev L₂ ++ invRev L₁ := by simp [invRev]
@[to_additive]
theorem invRev_cons {a : (α × Bool)} : invRev (a :: L) = invRev L ++ invRev [a] := by
simp [invRev]
@[to_additive]
theorem invRev_involutive : Function.Involutive (@invRev α) := fun _ => invRev_invRev
@[to_additive]
theorem invRev_injective : Function.Injective (@invRev α) :=
invRev_involutive.injective
@[to_additive]
theorem invRev_surjective : Function.Surjective (@invRev α) :=
invRev_involutive.surjective
@[to_additive]
theorem invRev_bijective : Function.Bijective (@invRev α) :=
invRev_involutive.bijective
@[to_additive]
instance : Inv (FreeGroup α) :=
⟨Quot.map invRev
(by
intro a b h
cases h
simp [invRev])⟩
@[to_additive (attr := simp)]
theorem inv_mk : (mk L)⁻¹ = mk (invRev L) :=
rfl
@[to_additive]
theorem Red.Step.invRev {L₁ L₂ : List (α × Bool)} (h : Red.Step L₁ L₂) :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) := by
obtain ⟨a, b, x, y⟩ := h
simp [FreeGroup.invRev]
@[to_additive]
theorem Red.invRev {L₁ L₂ : List (α × Bool)} (h : Red L₁ L₂) : Red (invRev L₁) (invRev L₂) :=
Relation.ReflTransGen.lift _ (fun _a _b => Red.Step.invRev) h
@[to_additive (attr := simp)]
theorem Red.step_invRev_iff :
Red.Step (FreeGroup.invRev L₁) (FreeGroup.invRev L₂) ↔ Red.Step L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
@[to_additive (attr := simp)]
theorem red_invRev_iff : Red (invRev L₁) (invRev L₂) ↔ Red L₁ L₂ :=
⟨fun h => by simpa only [invRev_invRev] using h.invRev, fun h => h.invRev⟩
@[to_additive]
instance : Group (FreeGroup α) where
mul := (· * ·)
one := 1
inv := Inv.inv
mul_assoc := by rintro ⟨L₁⟩ ⟨L₂⟩ ⟨L₃⟩; simp
one_mul := by rintro ⟨L⟩; rfl
mul_one := by rintro ⟨L⟩; simp [one_eq_mk]
inv_mul_cancel := by
rintro ⟨L⟩
exact
List.recOn L rfl fun ⟨x, b⟩ tl ih =>
Eq.trans (Quot.sound <| by simp [invRev]) ih
@[to_additive (attr := simp)]
theorem pow_mk (n : ℕ) : mk L ^ n = mk (List.flatten <| List.replicate n L) :=
match n with
| 0 => rfl
| n + 1 => by rw [pow_succ', pow_mk, mul_mk, List.replicate_succ, List.flatten_cons]
/-- `of` is the canonical injection from the type to the free group over that type by sending each
element to the equivalence class of the letter that is the element. -/
@[to_additive /-- `of` is the canonical injection from the type to the free group over that type
by sending each element to the equivalence class of the letter that is the element. -/]
def of (x : α) : FreeGroup α :=
mk [(x, true)]
@[to_additive (attr := elab_as_elim, induction_eliminator)]
protected lemma induction_on {C : FreeGroup α → Prop} (z : FreeGroup α) (C1 : C 1)
(of : ∀ x, C <| of x) (inv_of : ∀ x, C (.of x) → C (.of x)⁻¹)
(mul : ∀ x y, C x → C y → C (x * y)) : C z :=
Quot.inductionOn z fun L ↦ L.recOn C1 fun ⟨x, b⟩ _tl ih ↦
b.recOn (mul _ _ (inv_of _ <| of x) ih) (mul _ _ (of x) ih)
/-- Two homomorphisms out of a free group are equal if they are equal on generators.
See note [partially-applied ext lemmas]. -/
@[to_additive (attr := ext) /-- Two homomorphisms out of a free additive group are equal if they are
equal on generators. See note [partially-applied ext lemmas]. -/]
lemma ext_hom {M : Type*} [Monoid M] (f g : FreeGroup α →* M) (h : ∀ a, f (of a) = g (of a)) :
f = g := by
ext x
have this (x) : f (of x)⁻¹ = g (of x)⁻¹ := by
trans f (of x)⁻¹ * f (of x) * g (of x)⁻¹
· simp_rw [mul_assoc, h, ← _root_.map_mul, mul_inv_cancel, _root_.map_one, mul_one]
· simp_rw [← _root_.map_mul, inv_mul_cancel, _root_.map_one, one_mul]
induction x <;> simp [*]
@[to_additive]
theorem Red.exact : mk L₁ = mk L₂ ↔ Join Red L₁ L₂ :=
calc
mk L₁ = mk L₂ ↔ EqvGen Red.Step L₁ L₂ := Iff.intro Quot.eqvGen_exact Quot.eqvGen_sound
_ ↔ Join Red L₁ L₂ := eqvGen_step_iff_join_red
/-- The canonical map from the type to the free group is an injection. -/
@[to_additive /-- The canonical map from the type to the additive free group is an injection. -/]
theorem of_injective : Function.Injective (@of α) := fun _ _ H => by
let ⟨L₁, hx, hy⟩ := Red.exact.1 H
simp [Red.singleton_iff] at hx hy; aesop
section lift
variable {β : Type v} [Group β] (f : α → β) {x y : FreeGroup α}
/-- Given `f : α → β` with `β` a group, the canonical map `List (α × Bool) → β` -/
@[to_additive /-- Given `f : α → β` with `β` an additive group, the canonical map
`List (α × Bool) → β` -/]
def Lift.aux : List (α × Bool) → β := fun L =>
List.prod <| L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹
@[to_additive]
theorem Red.Step.lift {f : α → β} (H : Red.Step L₁ L₂) : Lift.aux f L₁ = Lift.aux f L₂ := by
obtain @⟨_, _, _, b⟩ := H; cases b <;> simp [Lift.aux]
/-- If `β` is a group, then any function from `α` to `β` extends uniquely to a group homomorphism
from the free group over `α` to `β` -/
@[to_additive (attr := simps symm_apply)
/-- If `β` is an additive group, then any function from `α` to `β` extends uniquely to an
additive group homomorphism from the free additive group over `α` to `β` -/]
def lift : (α → β) ≃ (FreeGroup α →* β) where
toFun f :=
MonoidHom.mk' (Quot.lift (Lift.aux f) fun _ _ => Red.Step.lift) <| by
rintro ⟨L₁⟩ ⟨L₂⟩; simp [Lift.aux]
invFun g := g ∘ of
left_inv f := List.prod_singleton
right_inv g := by ext; simp [of, Lift.aux]
variable {f}
@[to_additive (attr := simp)]
theorem lift_mk : lift f (mk L) = List.prod (L.map fun x => cond x.2 (f x.1) (f x.1)⁻¹) :=
rfl
@[to_additive (attr := simp)]
theorem lift_apply_of {x} : lift f (of x) = f x :=
List.prod_singleton
@[to_additive]
theorem lift_unique (g : FreeGroup α →* β) (hg : ∀ x, g (FreeGroup.of x) = f x) {x} :
g x = FreeGroup.lift f x :=
DFunLike.congr_fun (lift.symm_apply_eq.mp (funext hg : g ∘ FreeGroup.of = f)) x
@[to_additive]
theorem lift_of_eq_id (α) : lift of = MonoidHom.id (FreeGroup α) :=
lift.apply_symm_apply (MonoidHom.id _)
@[to_additive]
theorem lift_of_apply (x : FreeGroup α) : lift FreeGroup.of x = x :=
DFunLike.congr_fun (lift_of_eq_id α) x
@[to_additive]
theorem range_lift_le {s : Subgroup β} (H : Set.range f ⊆ s) : (lift f).range ≤ s := by
rintro _ ⟨⟨L⟩, rfl⟩
exact List.recOn L s.one_mem fun ⟨x, b⟩ tl ih ↦
Bool.recOn b (by simpa using s.mul_mem (s.inv_mem <| H ⟨x, rfl⟩) ih)
(by simpa using s.mul_mem (H ⟨x, rfl⟩) ih)
@[to_additive]
theorem range_lift_eq_closure : (lift f).range = Subgroup.closure (Set.range f) := by
apply le_antisymm (range_lift_le Subgroup.subset_closure)
rw [Subgroup.closure_le]
rintro _ ⟨a, rfl⟩
exact ⟨FreeGroup.of a, by simp only [lift_apply_of]⟩
/-- The generators of `FreeGroup α` generate `FreeGroup α`. That is, the subgroup closure of the
set of generators equals `⊤`. -/
@[to_additive (attr := simp)]
theorem closure_range_of (α) :
Subgroup.closure (Set.range (FreeGroup.of : α → FreeGroup α)) = ⊤ := by
rw [← range_lift_eq_closure, lift_of_eq_id]
exact MonoidHom.range_eq_top.2 Function.surjective_id
end lift
section Map
variable {β : Type v} (f : α → β) {x y : FreeGroup α}
/-- Any function from `α` to `β` extends uniquely to a group homomorphism from the free group over
`α` to the free group over `β`. -/
@[to_additive /-- Any function from `α` to `β` extends uniquely to an additive group homomorphism
from the additive free group over `α` to the additive free group over `β`. -/]
def map : FreeGroup α →* FreeGroup β :=
MonoidHom.mk'
(Quot.map (List.map fun x => (f x.1, x.2)) fun L₁ L₂ H => by cases H; simp)
(by rintro ⟨L₁⟩ ⟨L₂⟩; simp)
variable {f}
@[to_additive (attr := simp)]
theorem map.mk : map f (mk L) = mk (L.map fun x => (f x.1, x.2)) :=
rfl
@[to_additive (attr := simp)]
theorem map.id (x : FreeGroup α) : map id x = x := by rcases x with ⟨L⟩; simp [List.map_id']
@[to_additive (attr := simp)]
theorem map.id' (x : FreeGroup α) : map (fun z => z) x = x :=
map.id x
@[to_additive]
theorem map.comp {γ : Type w} (f : α → β) (g : β → γ) (x) :
map g (map f x) = map (g ∘ f) x := by
rcases x with ⟨L⟩; simp [Function.comp_def]
@[to_additive (attr := simp)]
theorem map.of {x} : map f (of x) = of (f x) :=
rfl
@[to_additive]
theorem map.unique (g : FreeGroup α →* FreeGroup β)
(hg : ∀ x, g (FreeGroup.of x) = FreeGroup.of (f x)) :
∀ {x}, g x = map f x := by
rintro ⟨L⟩
exact List.recOn L g.map_one fun ⟨x, b⟩ t (ih : g (FreeGroup.mk t) = map f (FreeGroup.mk t)) =>
Bool.recOn b
(show g ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) =
FreeGroup.map f ((FreeGroup.of x)⁻¹ * FreeGroup.mk t) by
simp [g.map_mul, g.map_inv, hg, ih])
(show g (FreeGroup.of x * FreeGroup.mk t) =
FreeGroup.map f (FreeGroup.of x * FreeGroup.mk t) by simp [g.map_mul, hg, ih])
@[to_additive]
theorem map_eq_lift : map f x = lift (of ∘ f) x :=
Eq.symm <| map.unique _ fun x => by simp
/-- Equivalent types give rise to multiplicatively equivalent free groups.
The converse can be found in `Mathlib/GroupTheory/FreeGroup/GeneratorEquiv.lean`, as
`Equiv.ofFreeGroupEquiv`. -/
@[to_additive (attr := simps apply)
/-- Equivalent types give rise to additively equivalent additive free groups. -/]
def freeGroupCongr {α β} (e : α ≃ β) : FreeGroup α ≃* FreeGroup β where
toFun := map e
invFun := map e.symm
left_inv x := by simp [map.comp]
right_inv x := by simp [map.comp]
map_mul' := MonoidHom.map_mul _
@[to_additive (attr := simp)]
theorem freeGroupCongr_refl : freeGroupCongr (Equiv.refl α) = MulEquiv.refl _ :=
MulEquiv.ext map.id
@[to_additive (attr := simp)]
theorem freeGroupCongr_symm {α β} (e : α ≃ β) : (freeGroupCongr e).symm = freeGroupCongr e.symm :=
rfl
@[to_additive]
theorem freeGroupCongr_trans {α β γ} (e : α ≃ β) (f : β ≃ γ) :
(freeGroupCongr e).trans (freeGroupCongr f) = freeGroupCongr (e.trans f) :=
MulEquiv.ext <| map.comp _ _
end Map
section Prod
variable [Group α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the multiplicative version of `FreeGroup.sum`. -/
@[to_additive /-- If `α` is an additive group, then any function from `α` to `α` extends uniquely
to an additive homomorphism from the additive free group over `α` to `α`. -/]
def prod : FreeGroup α →* α :=
lift id
variable {x y}
@[to_additive (attr := simp)]
theorem prod_mk : prod (mk L) = List.prod (L.map fun x => cond x.2 x.1 x.1⁻¹) :=
rfl
@[to_additive (attr := simp)]
theorem prod.of {x : α} : prod (of x) = x :=
lift_apply_of
@[to_additive]
theorem prod.unique (g : FreeGroup α →* α) (hg : ∀ x, g (FreeGroup.of x) = x) {x} : g x = prod x :=
lift_unique g hg
end Prod
@[to_additive]
theorem lift_eq_prod_map {β : Type v} [Group β] {f : α → β} {x} : lift f x = prod (map f x) := by
rw [← lift_unique (prod.comp (map f)) (by simp), MonoidHom.coe_comp, Function.comp_apply]
section Sum
variable [AddGroup α] (x y : FreeGroup α)
/-- If `α` is a group, then any function from `α` to `α` extends uniquely to a homomorphism from the
free group over `α` to `α`. This is the additive version of `Prod`. -/
def sum : α :=
@prod (Multiplicative _) _ x
variable {x y}
@[simp]
theorem sum_mk : sum (mk L) = List.sum (L.map fun x => cond x.2 x.1 (-x.1)) :=
rfl
@[simp]
theorem sum.of {x : α} : sum (of x) = x :=
@prod.of _ (_) _
-- note: there are no bundled homs with different notation in the domain and codomain, so we copy
-- these manually
@[simp]
theorem sum.map_mul : sum (x * y) = sum x + sum y :=
(@prod (Multiplicative _) _).map_mul _ _
@[simp]
theorem sum.map_one : sum (1 : FreeGroup α) = 0 :=
(@prod (Multiplicative _) _).map_one
@[simp]
theorem sum.map_inv : sum x⁻¹ = -sum x :=
(prod : FreeGroup (Multiplicative α) →* Multiplicative α).map_inv _
end Sum
/-- The bijection between the free group on the empty type, and a type with one element. -/
@[to_additive /-- The bijection between the additive free group on the empty type, and a type with
one element. -/]
def freeGroupEmptyEquivUnit : FreeGroup Empty ≃ Unit where
toFun _ := ()
invFun _ := 1
left_inv := by rintro ⟨_ | ⟨⟨⟨⟩, _⟩, _⟩⟩; rfl
/-- The bijection between the free group on a singleton, and the integers. -/
def freeGroupUnitEquivInt : FreeGroup Unit ≃ ℤ where
toFun x := sum (by
revert x
exact ↑(map fun _ => (1 : ℤ)))
invFun x := of () ^ x
left_inv := by
rintro ⟨L⟩
simp only [quot_mk_eq_mk, map.mk, sum_mk, List.map_map]
exact List.recOn L
(by rfl)
(fun ⟨⟨⟩, b⟩ tl ih => by
cases b <;> simp [zpow_add] at ih ⊢ <;> rw [ih] <;> rfl)
right_inv x :=
Int.induction_on x (by simp)
(fun i ih => by
simp only [zpow_natCast, map_pow, map.of] at ih
simp [zpow_add, ih])
(fun i ih => by
simp only [zpow_neg, zpow_natCast, map_inv, map_pow, map.of, sum.map_inv, neg_inj] at ih
simp [zpow_add, ih, sub_eq_add_neg])
section Category
variable {β : Type u}
@[to_additive]
instance : Monad FreeGroup.{u} where
pure {_α} := of
map {_α _β f} := map f
bind {_α _β x f} := lift f x
@[to_additive]
theorem map_pure (f : α → β) (x : α) : f <$> (pure x : FreeGroup α) = pure (f x) :=
map.of
@[to_additive (attr := simp)]
theorem map_one (f : α → β) : f <$> (1 : FreeGroup α) = 1 :=
(map f).map_one
@[to_additive (attr := simp)]
theorem map_mul (f : α → β) (x y : FreeGroup α) : f <$> (x * y) = f <$> x * f <$> y :=
(map f).map_mul x y
@[to_additive (attr := simp)]
theorem map_inv (f : α → β) (x : FreeGroup α) : f <$> x⁻¹ = (f <$> x)⁻¹ :=
(map f).map_inv x
@[to_additive]
theorem pure_bind (f : α → FreeGroup β) (x) : pure x >>= f = f x :=
lift_apply_of
@[to_additive (attr := simp)]
theorem one_bind (f : α → FreeGroup β) : 1 >>= f = 1 :=
(lift f).map_one
@[to_additive (attr := simp)]
theorem mul_bind (f : α → FreeGroup β) (x y : FreeGroup α) : x * y >>= f = (x >>= f) * (y >>= f) :=
(lift f).map_mul _ _
@[to_additive (attr := simp)]
theorem inv_bind (f : α → FreeGroup β) (x : FreeGroup α) : x⁻¹ >>= f = (x >>= f)⁻¹ :=
(lift f).map_inv _
@[to_additive]
instance : LawfulMonad FreeGroup.{u} := LawfulMonad.mk'
(id_map := fun x =>
FreeGroup.induction_on x (map_one id) (fun x => map_pure id x) (fun x ih => by rw [map_inv, ih])
fun x y ihx ihy => by rw [map_mul, ihx, ihy])
(pure_bind := fun x f => pure_bind f x)
(bind_assoc := fun x => by
refine FreeGroup.induction_on x ?_ ?_ ?_ ?_ <;> simp +contextual [instMonad])
(bind_pure_comp := fun f x => by
refine FreeGroup.induction_on x ?_ ?_ ?_ ?_ <;> simp +contextual [instMonad])
end Category
end FreeGroup
|
Sigma.lean
|
/-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Sean Leather
-/
import Batteries.Data.List.Perm
import Mathlib.Data.List.Pairwise
import Mathlib.Data.List.Nodup
import Mathlib.Data.List.Lookmap
import Mathlib.Data.Sigma.Basic
/-!
# Utilities for lists of sigmas
This file includes several ways of interacting with `List (Sigma β)`, treated as a key-value store.
If `α : Type*` and `β : α → Type*`, then we regard `s : Sigma β` as having key `s.1 : α` and value
`s.2 : β s.1`. Hence, `List (Sigma β)` behaves like a key-value store.
## Main Definitions
- `List.keys` extracts the list of keys.
- `List.NodupKeys` determines if the store has duplicate keys.
- `List.lookup`/`lookup_all` accesses the value(s) of a particular key.
- `List.kreplace` replaces the first value with a given key by a given value.
- `List.kerase` removes a value.
- `List.kinsert` inserts a value.
- `List.kunion` computes the union of two stores.
- `List.kextract` returns a value with a given key and the rest of the values.
-/
universe u u' v v'
namespace List
variable {α : Type u} {α' : Type u'} {β : α → Type v} {β' : α' → Type v'} {l l₁ l₂ : List (Sigma β)}
/-! ### `keys` -/
/-- List of keys from a list of key-value pairs -/
def keys : List (Sigma β) → List α :=
map Sigma.fst
@[simp]
theorem keys_nil : @keys α β [] = [] :=
rfl
@[simp]
theorem keys_cons {s} {l : List (Sigma β)} : (s :: l).keys = s.1 :: l.keys :=
rfl
theorem mem_keys_of_mem {s : Sigma β} {l : List (Sigma β)} : s ∈ l → s.1 ∈ l.keys :=
mem_map_of_mem
theorem exists_of_mem_keys {a} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ b : β a, Sigma.mk a b ∈ l :=
let ⟨⟨_, b'⟩, m, e⟩ := exists_of_mem_map h
Eq.recOn e (Exists.intro b' m)
theorem mem_keys {a} {l : List (Sigma β)} : a ∈ l.keys ↔ ∃ b : β a, Sigma.mk a b ∈ l :=
⟨exists_of_mem_keys, fun ⟨_, h⟩ => mem_keys_of_mem h⟩
theorem notMem_keys {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ b : β a, Sigma.mk a b ∉ l :=
(not_congr mem_keys).trans not_exists
@[deprecated (since := "2025-05-23")] alias not_mem_keys := notMem_keys
theorem ne_key {a} {l : List (Sigma β)} : a ∉ l.keys ↔ ∀ s : Sigma β, s ∈ l → a ≠ s.1 :=
Iff.intro (fun h₁ s h₂ e => absurd (mem_keys_of_mem h₂) (by rwa [e] at h₁)) fun f h₁ =>
let ⟨_, h₂⟩ := exists_of_mem_keys h₁
f _ h₂ rfl
@[deprecated (since := "2025-04-27")]
alias not_eq_key := ne_key
/-! ### `NodupKeys` -/
/-- Determines whether the store uses a key several times. -/
def NodupKeys (l : List (Sigma β)) : Prop :=
l.keys.Nodup
theorem nodupKeys_iff_pairwise {l} : NodupKeys l ↔ Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
pairwise_map
theorem NodupKeys.pairwise_ne {l} (h : NodupKeys l) :
Pairwise (fun s s' : Sigma β => s.1 ≠ s'.1) l :=
nodupKeys_iff_pairwise.1 h
@[simp]
theorem nodupKeys_nil : @NodupKeys α β [] :=
Pairwise.nil
@[simp]
theorem nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} :
NodupKeys (s :: l) ↔ s.1 ∉ l.keys ∧ NodupKeys l := by simp [keys, NodupKeys]
theorem notMem_keys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
s.1 ∉ l.keys :=
(nodupKeys_cons.1 h).1
@[deprecated (since := "2025-05-23")]
alias not_mem_keys_of_nodupKeys_cons := notMem_keys_of_nodupKeys_cons
theorem nodupKeys_of_nodupKeys_cons {s : Sigma β} {l : List (Sigma β)} (h : NodupKeys (s :: l)) :
NodupKeys l :=
(nodupKeys_cons.1 h).2
theorem NodupKeys.eq_of_fst_eq {l : List (Sigma β)} (nd : NodupKeys l) {s s' : Sigma β} (h : s ∈ l)
(h' : s' ∈ l) : s.1 = s'.1 → s = s' :=
@Pairwise.forall_of_forall _ (fun s s' : Sigma β => s.1 = s'.1 → s = s') _
(fun _ _ H h => (H h.symm).symm) (fun _ _ _ => rfl)
((nodupKeys_iff_pairwise.1 nd).imp fun h h' => (h h').elim) _ h _ h'
theorem NodupKeys.eq_of_mk_mem {a : α} {b b' : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) (h' : Sigma.mk a b' ∈ l) : b = b' := by
cases nd.eq_of_fst_eq h h' rfl; rfl
theorem nodupKeys_singleton (s : Sigma β) : NodupKeys [s] :=
nodup_singleton _
theorem NodupKeys.sublist {l₁ l₂ : List (Sigma β)} (h : l₁ <+ l₂) : NodupKeys l₂ → NodupKeys l₁ :=
Nodup.sublist <| h.map _
protected theorem NodupKeys.nodup {l : List (Sigma β)} : NodupKeys l → Nodup l :=
Nodup.of_map _
theorem perm_nodupKeys {l₁ l₂ : List (Sigma β)} (h : l₁ ~ l₂) : NodupKeys l₁ ↔ NodupKeys l₂ :=
(h.map _).nodup_iff
theorem nodupKeys_flatten {L : List (List (Sigma β))} :
NodupKeys (flatten L) ↔ (∀ l ∈ L, NodupKeys l) ∧ Pairwise Disjoint (L.map keys) := by
rw [nodupKeys_iff_pairwise, pairwise_flatten, pairwise_map]
refine and_congr (forall₂_congr fun l _ => by simp [nodupKeys_iff_pairwise]) ?_
apply iff_of_eq; congr! with (l₁ l₂)
simp [keys, disjoint_iff_ne, Sigma.forall]
theorem nodup_zipIdx_map_snd (l : List α) : (l.zipIdx.map Prod.snd).Nodup := by
simp [List.nodup_range']
theorem mem_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.Nodup) (nd₁ : l₁.Nodup)
(h : ∀ x, x ∈ l₀ ↔ x ∈ l₁) : l₀ ~ l₁ :=
(perm_ext_iff_of_nodup nd₀ nd₁).2 h
variable [DecidableEq α] [DecidableEq α']
/-! ### `dlookup` -/
/-- `dlookup a l` is the first value in `l` corresponding to the key `a`,
or `none` if no such element exists. -/
def dlookup (a : α) : List (Sigma β) → Option (β a)
| [] => none
| ⟨a', b⟩ :: l => if h : a' = a then some (Eq.recOn h b) else dlookup a l
@[simp]
theorem dlookup_nil (a : α) : dlookup a [] = @none (β a) :=
rfl
@[simp]
theorem dlookup_cons_eq (l) (a : α) (b : β a) : dlookup a (⟨a, b⟩ :: l) = some b :=
dif_pos rfl
@[simp]
theorem dlookup_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → dlookup a (s :: l) = dlookup a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem dlookup_isSome {a : α} : ∀ {l : List (Sigma β)}, (dlookup a l).isSome ↔ a ∈ l.keys
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simp [h, dlookup_isSome]
theorem dlookup_eq_none {a : α} {l : List (Sigma β)} : dlookup a l = none ↔ a ∉ l.keys := by
simp [← dlookup_isSome, Option.isNone_iff_eq_none]
theorem of_mem_dlookup {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ dlookup a l → Sigma.mk a b ∈ l
| ⟨a', b'⟩ :: l, H => by
by_cases h : a = a'
· subst a'
simp? at H says simp only [dlookup_cons_eq, Option.mem_def, Option.some.injEq] at H
simp [H]
· simp only [ne_eq, h, not_false_iff, dlookup_cons_ne] at H
simp [of_mem_dlookup H]
theorem mem_dlookup {a} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) (h : Sigma.mk a b ∈ l) :
b ∈ dlookup a l := by
obtain ⟨b', h'⟩ := Option.isSome_iff_exists.mp (dlookup_isSome.mpr (mem_keys_of_mem h))
cases nd.eq_of_mk_mem h (of_mem_dlookup h')
exact h'
theorem map_dlookup_eq_find (a : α) :
∀ l : List (Sigma β), (dlookup a l).map (Sigma.mk a) = find? (fun s => a = s.1) l
| [] => rfl
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst a'
simp
· simpa [h] using map_dlookup_eq_find a l
theorem mem_dlookup_iff {a : α} {b : β a} {l : List (Sigma β)} (nd : l.NodupKeys) :
b ∈ dlookup a l ↔ Sigma.mk a b ∈ l :=
⟨of_mem_dlookup, mem_dlookup nd⟩
theorem perm_dlookup (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : dlookup a l₁ = dlookup a l₂ := by
ext b; simp only [← Option.mem_def, mem_dlookup_iff nd₁, mem_dlookup_iff nd₂, p.mem_iff]
theorem lookup_ext {l₀ l₁ : List (Sigma β)} (nd₀ : l₀.NodupKeys) (nd₁ : l₁.NodupKeys)
(h : ∀ x y, y ∈ l₀.dlookup x ↔ y ∈ l₁.dlookup x) : l₀ ~ l₁ :=
mem_ext nd₀.nodup nd₁.nodup fun ⟨a, b⟩ => by
rw [← mem_dlookup_iff, ← mem_dlookup_iff, h] <;> assumption
theorem dlookup_map (l : List (Sigma β))
{f : α → α'} (hf : Function.Injective f) (g : ∀ a, β a → β' (f a)) (a : α) :
(l.map fun x => ⟨f x.1, g _ x.2⟩).dlookup (f a) = (l.dlookup a).map (g a) := by
induction' l with b l IH
· rw [map_nil, dlookup_nil, dlookup_nil, Option.map_none]
· rw [map_cons]
obtain rfl | h := eq_or_ne a b.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.map_some]
· rw [dlookup_cons_ne _ _ h, dlookup_cons_ne _ _ (fun he => h <| hf he), IH]
theorem dlookup_map₁ {β : Type v} (l : List (Σ _ : α, β))
{f : α → α'} (hf : Function.Injective f) (a : α) :
(l.map fun x => ⟨f x.1, x.2⟩ : List (Σ _ : α', β)).dlookup (f a) = l.dlookup a := by
rw [dlookup_map (β' := fun _ => β) l hf (fun _ x => x) a, Option.map_id']
theorem dlookup_map₂ {γ δ : α → Type*} {l : List (Σ a, γ a)} {f : ∀ a, γ a → δ a} (a : α) :
(l.map fun x => ⟨x.1, f _ x.2⟩ : List (Σ a, δ a)).dlookup a = (l.dlookup a).map (f a) :=
dlookup_map l Function.injective_id _ _
/-! ### `lookupAll` -/
/-- `lookup_all a l` is the list of all values in `l` corresponding to the key `a`. -/
def lookupAll (a : α) : List (Sigma β) → List (β a)
| [] => []
| ⟨a', b⟩ :: l => if h : a' = a then Eq.recOn h b :: lookupAll a l else lookupAll a l
@[simp]
theorem lookupAll_nil (a : α) : lookupAll a [] = @nil (β a) :=
rfl
@[simp]
theorem lookupAll_cons_eq (l) (a : α) (b : β a) : lookupAll a (⟨a, b⟩ :: l) = b :: lookupAll a l :=
dif_pos rfl
@[simp]
theorem lookupAll_cons_ne (l) {a} : ∀ s : Sigma β, a ≠ s.1 → lookupAll a (s :: l) = lookupAll a l
| ⟨_, _⟩, h => dif_neg h.symm
theorem lookupAll_eq_nil {a : α} :
∀ {l : List (Sigma β)}, lookupAll a l = [] ↔ ∀ b : β a, Sigma.mk a b ∉ l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst a'
simp only [lookupAll_cons_eq, mem_cons, Sigma.mk.inj_iff, heq_eq_eq, true_and, not_or,
false_iff, not_forall, not_and, not_not, reduceCtorEq]
use b
simp
· simp [h, lookupAll_eq_nil]
theorem head?_lookupAll (a : α) : ∀ l : List (Sigma β), head? (lookupAll a l) = dlookup a l
| [] => by simp
| ⟨a', b⟩ :: l => by
by_cases h : a = a'
· subst h; simp
· rw [lookupAll_cons_ne, dlookup_cons_ne, head?_lookupAll a l] <;> assumption
theorem mem_lookupAll {a : α} {b : β a} :
∀ {l : List (Sigma β)}, b ∈ lookupAll a l ↔ Sigma.mk a b ∈ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp [*, mem_lookupAll]
· simp [*, mem_lookupAll]
theorem lookupAll_sublist (a : α) : ∀ l : List (Sigma β), (lookupAll a l).map (Sigma.mk a) <+ l
| [] => by simp
| ⟨a', b'⟩ :: l => by
by_cases h : a = a'
· subst h
simp only [lookupAll_cons_eq, List.map]
exact (lookupAll_sublist a l).cons₂ _
· simp only [ne_eq, h, not_false_iff, lookupAll_cons_ne]
exact (lookupAll_sublist a l).cons _
theorem lookupAll_length_le_one (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
length (lookupAll a l) ≤ 1 := by
have := Nodup.sublist ((lookupAll_sublist a l).map _) h
rw [map_map] at this
rwa [← nodup_replicate, ← map_const]
theorem lookupAll_eq_dlookup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) :
lookupAll a l = (dlookup a l).toList := by
rw [← head?_lookupAll]
have h1 := lookupAll_length_le_one a h; revert h1
rcases lookupAll a l with (_ | ⟨b, _ | ⟨c, l⟩⟩) <;> intro h1 <;> try rfl
exact absurd h1 (by simp)
theorem lookupAll_nodup (a : α) {l : List (Sigma β)} (h : l.NodupKeys) : (lookupAll a l).Nodup := by
(rw [lookupAll_eq_dlookup a h]; apply Option.toList_nodup)
theorem perm_lookupAll (a : α) {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys)
(p : l₁ ~ l₂) : lookupAll a l₁ = lookupAll a l₂ := by
simp [lookupAll_eq_dlookup, nd₁, nd₂, perm_dlookup a nd₁ nd₂ p]
theorem dlookup_append (l₁ l₂ : List (Sigma β)) (a : α) :
(l₁ ++ l₂).dlookup a = (l₁.dlookup a).or (l₂.dlookup a) := by
induction l₁ with
| nil => rfl
| cons x l₁ IH =>
rw [cons_append]
obtain rfl | hb := Decidable.eq_or_ne a x.1
· rw [dlookup_cons_eq, dlookup_cons_eq, Option.or]
· rw [dlookup_cons_ne _ _ hb, dlookup_cons_ne _ _ hb, IH]
/-! ### `kreplace` -/
/-- Replaces the first value with key `a` by `b`. -/
def kreplace (a : α) (b : β a) : List (Sigma β) → List (Sigma β) :=
lookmap fun s => if a = s.1 then some ⟨a, b⟩ else none
theorem kreplace_of_forall_not (a : α) (b : β a) {l : List (Sigma β)}
(H : ∀ b : β a, Sigma.mk a b ∉ l) : kreplace a b l = l :=
lookmap_of_forall_not _ <| by
rintro ⟨a', b'⟩ h; dsimp; split_ifs
· subst a'
exact H _ h
· rfl
theorem kreplace_self {a : α} {b : β a} {l : List (Sigma β)} (nd : NodupKeys l)
(h : Sigma.mk a b ∈ l) : kreplace a b l = l := by
refine (lookmap_congr ?_).trans (lookmap_id' (Option.guard fun (s : Sigma β) => a = s.1) ?_ _)
· rintro ⟨a', b'⟩ h'
dsimp [Option.guard]
split_ifs
· subst a'
simp [nd.eq_of_mk_mem h h']
· simp_all
· simp_all
· rfl
· simp
theorem keys_kreplace (a : α) (b : β a) : ∀ l : List (Sigma β), (kreplace a b l).keys = l.keys :=
lookmap_map_eq _ _ <| by
rintro ⟨a₁, b₂⟩ ⟨a₂, b₂⟩
dsimp
split_ifs with h <;> simp +contextual [h]
theorem kreplace_nodupKeys (a : α) (b : β a) {l : List (Sigma β)} :
(kreplace a b l).NodupKeys ↔ l.NodupKeys := by simp [NodupKeys, keys_kreplace]
theorem Perm.kreplace {a : α} {b : β a} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kreplace a b l₁ ~ kreplace a b l₂ :=
perm_lookmap _ <| by
refine nd.pairwise_ne.imp ?_
intro x y h z h₁ w h₂
split_ifs at h₁ h₂ with h_2 h_1 <;> cases h₁ <;> cases h₂
exact (h (h_2.symm.trans h_1)).elim
/-! ### `kerase` -/
/-- Remove the first pair with the key `a`. -/
def kerase (a : α) : List (Sigma β) → List (Sigma β) :=
eraseP fun s => a = s.1
@[simp]
theorem kerase_nil {a} : @kerase _ β _ a [] = [] :=
rfl
@[simp]
theorem kerase_cons_eq {a} {s : Sigma β} {l : List (Sigma β)} (h : a = s.1) :
kerase a (s :: l) = l := by simp [kerase, h]
@[simp]
theorem kerase_cons_ne {a} {s : Sigma β} {l : List (Sigma β)} (h : a ≠ s.1) :
kerase a (s :: l) = s :: kerase a l := by simp [kerase, h]
@[simp]
theorem kerase_of_notMem_keys {a} {l : List (Sigma β)} (h : a ∉ l.keys) : kerase a l = l := by
induction l with
| nil => rfl
| cons _ _ ih => simp [not_or] at h; simp [h.1, ih h.2]
@[deprecated (since := "2025-05-23")] alias kerase_of_not_mem_keys := kerase_of_notMem_keys
theorem kerase_sublist (a : α) (l : List (Sigma β)) : kerase a l <+ l :=
eraseP_sublist
theorem kerase_keys_subset (a) (l : List (Sigma β)) : (kerase a l).keys ⊆ l.keys :=
((kerase_sublist a l).map _).subset
theorem mem_keys_of_mem_keys_kerase {a₁ a₂} {l : List (Sigma β)} :
a₁ ∈ (kerase a₂ l).keys → a₁ ∈ l.keys :=
@kerase_keys_subset _ _ _ _ _ _
theorem exists_of_kerase {a : α} {l : List (Sigma β)} (h : a ∈ l.keys) :
∃ (b : β a) (l₁ l₂ : List (Sigma β)),
a ∉ l₁.keys ∧ l = l₁ ++ ⟨a, b⟩ :: l₂ ∧ kerase a l = l₁ ++ l₂ := by
induction l with
| nil => cases h
| cons hd tl ih =>
by_cases e : a = hd.1
· subst e
exact ⟨hd.2, [], tl, by simp, by cases hd; rfl, by simp⟩
· simp only [keys_cons, mem_cons] at h
rcases h with h | h
· exact absurd h e
rcases ih h with ⟨b, tl₁, tl₂, h₁, h₂, h₃⟩
exact ⟨b, hd :: tl₁, tl₂, not_mem_cons_of_ne_of_not_mem e h₁, by (rw [h₂]; rfl), by
simp [e, h₃]⟩
@[simp]
theorem mem_keys_kerase_of_ne {a₁ a₂} {l : List (Sigma β)} (h : a₁ ≠ a₂) :
a₁ ∈ (kerase a₂ l).keys ↔ a₁ ∈ l.keys :=
(Iff.intro mem_keys_of_mem_keys_kerase) fun p =>
if q : a₂ ∈ l.keys then
match l, kerase a₂ l, exists_of_kerase q, p with
| _, _, ⟨_, _, _, _, rfl, rfl⟩, p => by simpa [keys, h] using p
else by simp [q, p]
theorem keys_kerase {a} {l : List (Sigma β)} : (kerase a l).keys = l.keys.erase a := by
rw [keys, kerase, erase_eq_eraseP, eraseP_map, Function.comp_def]
congr
theorem kerase_kerase {a a'} {l : List (Sigma β)} :
(kerase a' l).kerase a = (kerase a l).kerase a' := by
by_cases h : a = a'
· subst a'; rfl
induction' l with x xs
· rfl
· by_cases a' = x.1
· subst a'
simp [kerase_cons_ne h, kerase_cons_eq rfl]
by_cases h' : a = x.1
· subst a
simp [kerase_cons_eq rfl, kerase_cons_ne (Ne.symm h)]
· simp [kerase_cons_ne, *]
theorem NodupKeys.kerase (a : α) : NodupKeys l → (kerase a l).NodupKeys :=
NodupKeys.sublist <| kerase_sublist _ _
theorem Perm.kerase {a : α} {l₁ l₂ : List (Sigma β)} (nd : l₁.NodupKeys) :
l₁ ~ l₂ → kerase a l₁ ~ kerase a l₂ := by
apply Perm.eraseP
apply (nodupKeys_iff_pairwise.1 nd).imp
intros; simp_all
@[simp]
theorem notMem_keys_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
a ∉ (kerase a l).keys := by
induction l with
| nil => simp
| cons hd tl ih =>
simp? at nd says simp only [nodupKeys_cons] at nd
by_cases h : a = hd.1
· subst h
simp [nd.1]
· simp [h, ih nd.2]
@[deprecated (since := "2025-05-23")] alias not_mem_keys_kerase := notMem_keys_kerase
@[simp]
theorem dlookup_kerase (a) {l : List (Sigma β)} (nd : l.NodupKeys) :
dlookup a (kerase a l) = none :=
dlookup_eq_none.mpr (notMem_keys_kerase a nd)
@[simp]
theorem dlookup_kerase_ne {a a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kerase a' l) = dlookup a l := by
induction l with
| nil => rfl
| cons hd tl ih =>
obtain ⟨ah, bh⟩ := hd
by_cases h₁ : a = ah <;> by_cases h₂ : a' = ah
· substs h₁ h₂
cases Ne.irrefl h
· subst h₁
simp [h₂]
· subst h₂
simp [h]
· simp [h₁, h₂, ih]
theorem kerase_append_left {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∈ l₁.keys → kerase a (l₁ ++ l₂) = kerase a l₁ ++ l₂
| [], _, h => by cases h
| s :: l₁, l₂, h₁ => by
if h₂ : a = s.1 then simp [h₂]
else simp_all [kerase_append_left]
theorem kerase_append_right {a} :
∀ {l₁ l₂ : List (Sigma β)}, a ∉ l₁.keys → kerase a (l₁ ++ l₂) = l₁ ++ kerase a l₂
| [], _, _ => rfl
| _ :: l₁, l₂, h => by
simp only [keys_cons, mem_cons, not_or] at h
simp [h.1, kerase_append_right h.2]
theorem kerase_comm (a₁ a₂) (l : List (Sigma β)) :
kerase a₂ (kerase a₁ l) = kerase a₁ (kerase a₂ l) :=
if h : a₁ = a₂ then by simp [h]
else
if ha₁ : a₁ ∈ l.keys then
if ha₂ : a₂ ∈ l.keys then
match l, kerase a₁ l, exists_of_kerase ha₁, ha₂ with
| _, _, ⟨b₁, l₁, l₂, a₁_nin_l₁, rfl, rfl⟩, _ =>
if h' : a₂ ∈ l₁.keys then by
simp [kerase_append_left h',
kerase_append_right (mt (mem_keys_kerase_of_ne h).mp a₁_nin_l₁)]
else by
simp [kerase_append_right h', kerase_append_right a₁_nin_l₁,
@kerase_cons_ne _ _ _ a₂ ⟨a₁, b₁⟩ _ (Ne.symm h)]
else by simp [ha₂, mt mem_keys_of_mem_keys_kerase ha₂]
else by simp [ha₁, mt mem_keys_of_mem_keys_kerase ha₁]
theorem sizeOf_kerase [SizeOf (Sigma β)] (x : α)
(xs : List (Sigma β)) : SizeOf.sizeOf (List.kerase x xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with y ys
· simp
· by_cases x = y.1 <;> simp [*]
/-! ### `kinsert` -/
/-- Insert the pair `⟨a, b⟩` and erase the first pair with the key `a`. -/
def kinsert (a : α) (b : β a) (l : List (Sigma β)) : List (Sigma β) :=
⟨a, b⟩ :: kerase a l
@[simp]
theorem kinsert_def {a} {b : β a} {l : List (Sigma β)} : kinsert a b l = ⟨a, b⟩ :: kerase a l :=
rfl
theorem mem_keys_kinsert {a a'} {b' : β a'} {l : List (Sigma β)} :
a ∈ (kinsert a' b' l).keys ↔ a = a' ∨ a ∈ l.keys := by by_cases h : a = a' <;> simp [h]
theorem kinsert_nodupKeys (a) (b : β a) {l : List (Sigma β)} (nd : l.NodupKeys) :
(kinsert a b l).NodupKeys :=
nodupKeys_cons.mpr ⟨notMem_keys_kerase a nd, nd.kerase a⟩
theorem Perm.kinsert {a} {b : β a} {l₁ l₂ : List (Sigma β)} (nd₁ : l₁.NodupKeys) (p : l₁ ~ l₂) :
kinsert a b l₁ ~ kinsert a b l₂ :=
(p.kerase nd₁).cons _
theorem dlookup_kinsert {a} {b : β a} (l : List (Sigma β)) :
dlookup a (kinsert a b l) = some b := by
simp only [kinsert, dlookup_cons_eq]
theorem dlookup_kinsert_ne {a a'} {b' : β a'} {l : List (Sigma β)} (h : a ≠ a') :
dlookup a (kinsert a' b' l) = dlookup a l := by simp [h]
/-! ### `kextract` -/
/-- Finds the first entry with a given key `a` and returns its value (as an `Option` because there
might be no entry with key `a`) alongside with the rest of the entries. -/
def kextract (a : α) : List (Sigma β) → Option (β a) × List (Sigma β)
| [] => (none, [])
| s :: l =>
if h : s.1 = a then (some (Eq.recOn h s.2), l)
else
let (b', l') := kextract a l
(b', s :: l')
@[simp]
theorem kextract_eq_dlookup_kerase (a : α) :
∀ l : List (Sigma β), kextract a l = (dlookup a l, kerase a l)
| [] => rfl
| ⟨a', b⟩ :: l => by
simp only [kextract]; split_ifs with h
· subst a'
simp [kerase]
· simp [Ne.symm h, kextract_eq_dlookup_kerase a l, kerase]
/-! ### `dedupKeys` -/
/-- Remove entries with duplicate keys from `l : List (Sigma β)`. -/
def dedupKeys : List (Sigma β) → List (Sigma β) :=
List.foldr (fun x => kinsert x.1 x.2) []
theorem dedupKeys_cons {x : Sigma β} (l : List (Sigma β)) :
dedupKeys (x :: l) = kinsert x.1 x.2 (dedupKeys l) :=
rfl
theorem nodupKeys_dedupKeys (l : List (Sigma β)) : NodupKeys (dedupKeys l) := by
dsimp [dedupKeys]
generalize hl : nil = l'
have : NodupKeys l' := by
rw [← hl]
apply nodup_nil
clear hl
induction' l with x xs l_ih
· apply this
· cases x
simp only [foldr_cons, kinsert_def, nodupKeys_cons]
constructor
· simp only [keys_kerase]
apply l_ih.not_mem_erase
· exact l_ih.kerase _
theorem dlookup_dedupKeys (a : α) (l : List (Sigma β)) : dlookup a (dedupKeys l) = dlookup a l := by
induction' l with l_hd _ l_ih
· rfl
obtain ⟨a', b⟩ := l_hd
by_cases h : a = a'
· subst a'
rw [dedupKeys_cons, dlookup_kinsert, dlookup_cons_eq]
· rw [dedupKeys_cons, dlookup_kinsert_ne h, l_ih, dlookup_cons_ne]
exact h
theorem sizeOf_dedupKeys [SizeOf (Sigma β)]
(xs : List (Sigma β)) : SizeOf.sizeOf (dedupKeys xs) ≤ SizeOf.sizeOf xs := by
simp only [SizeOf.sizeOf, _sizeOf_1]
induction' xs with x xs
· simp [dedupKeys]
· simp only [dedupKeys_cons, kinsert_def, Nat.add_le_add_iff_left, Sigma.eta]
trans
· apply sizeOf_kerase
· assumption
/-! ### `kunion` -/
/-- `kunion l₁ l₂` is the append to l₁ of l₂ after, for each key in l₁, the
first matching pair in l₂ is erased. -/
def kunion : List (Sigma β) → List (Sigma β) → List (Sigma β)
| [], l₂ => l₂
| s :: l₁, l₂ => s :: kunion l₁ (kerase s.1 l₂)
@[simp]
theorem nil_kunion {l : List (Sigma β)} : kunion [] l = l :=
rfl
@[simp]
theorem kunion_nil : ∀ {l : List (Sigma β)}, kunion l [] = l
| [] => rfl
| _ :: l => by rw [kunion, kerase_nil, kunion_nil]
@[simp]
theorem kunion_cons {s} {l₁ l₂ : List (Sigma β)} :
kunion (s :: l₁) l₂ = s :: kunion l₁ (kerase s.1 l₂) :=
rfl
@[simp]
theorem mem_keys_kunion {a} {l₁ l₂ : List (Sigma β)} :
a ∈ (kunion l₁ l₂).keys ↔ a ∈ l₁.keys ∨ a ∈ l₂.keys := by
induction l₁ generalizing l₂ with
| nil => simp
| cons s l₁ ih => by_cases h : a = s.1 <;> [simp [h]; simp [h, ih]]
@[simp]
theorem kunion_kerase {a} :
∀ {l₁ l₂ : List (Sigma β)}, kunion (kerase a l₁) (kerase a l₂) = kerase a (kunion l₁ l₂)
| [], _ => rfl
| s :: _, l => by by_cases h : a = s.1 <;> simp [h, kerase_comm a s.1 l, kunion_kerase]
theorem NodupKeys.kunion (nd₁ : l₁.NodupKeys) (nd₂ : l₂.NodupKeys) : (kunion l₁ l₂).NodupKeys := by
induction l₁ generalizing l₂ with
| nil => simp only [nil_kunion, nd₂]
| cons s l₁ ih =>
simp? at nd₁ says simp only [nodupKeys_cons] at nd₁
simp [nd₁.1, nd₂, ih nd₁.2 (nd₂.kerase s.1)]
theorem Perm.kunion_right {l₁ l₂ : List (Sigma β)} (p : l₁ ~ l₂) (l) :
kunion l₁ l ~ kunion l₂ l := by
induction p generalizing l with
| nil => rfl
| cons hd _ ih =>
simp [ih (List.kerase _ _)]
| swap s₁ s₂ l => simp [kerase_comm, Perm.swap]
| trans _ _ ih₁₂ ih₂₃ => exact Perm.trans (ih₁₂ l) (ih₂₃ l)
theorem Perm.kunion_left :
∀ (l) {l₁ l₂ : List (Sigma β)}, l₁.NodupKeys → l₁ ~ l₂ → kunion l l₁ ~ kunion l l₂
| [], _, _, _, p => p
| s :: l, _, _, nd₁, p => ((p.kerase nd₁).kunion_left l <| nd₁.kerase s.1).cons s
theorem Perm.kunion {l₁ l₂ l₃ l₄ : List (Sigma β)} (nd₃ : l₃.NodupKeys) (p₁₂ : l₁ ~ l₂)
(p₃₄ : l₃ ~ l₄) : kunion l₁ l₃ ~ kunion l₂ l₄ :=
(p₁₂.kunion_right l₃).trans (p₃₄.kunion_left l₂ nd₃)
@[simp]
theorem dlookup_kunion_left {a} {l₁ l₂ : List (Sigma β)} (h : a ∈ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₁ := by
induction' l₁ with s _ ih generalizing l₂ <;> simp at h; rcases h with h | h <;> obtain ⟨a'⟩ := s
· subst h
simp
· rw [kunion_cons]
by_cases h' : a = a'
· subst h'
simp
· simp [h', ih h]
@[simp]
theorem dlookup_kunion_right {a} {l₁ l₂ : List (Sigma β)} (h : a ∉ l₁.keys) :
dlookup a (kunion l₁ l₂) = dlookup a l₂ := by
induction l₁ generalizing l₂ with
| nil => simp
| cons _ _ ih => simp_all [not_or]
theorem mem_dlookup_kunion {a} {b : β a} {l₁ l₂ : List (Sigma β)} :
b ∈ dlookup a (kunion l₁ l₂) ↔ b ∈ dlookup a l₁ ∨ a ∉ l₁.keys ∧ b ∈ dlookup a l₂ := by
induction l₁ generalizing l₂ with
| nil => simp
| cons s _ ih =>
obtain ⟨a'⟩ := s
by_cases h₁ : a = a'
· subst h₁
simp
· let h₂ := @ih (kerase a' l₂)
simp? [h₁] at h₂ says
simp only [Option.mem_def, ne_eq, h₁, not_false_eq_true, dlookup_kerase_ne] at h₂
simp [h₁, h₂]
@[simp]
theorem dlookup_kunion_eq_some {a} {b : β a} {l₁ l₂ : List (Sigma β)} :
dlookup a (kunion l₁ l₂) = some b ↔
dlookup a l₁ = some b ∨ a ∉ l₁.keys ∧ dlookup a l₂ = some b :=
mem_dlookup_kunion
theorem mem_dlookup_kunion_middle {a} {b : β a} {l₁ l₂ l₃ : List (Sigma β)}
(h₁ : b ∈ dlookup a (kunion l₁ l₃)) (h₂ : a ∉ keys l₂) :
b ∈ dlookup a (kunion (kunion l₁ l₂) l₃) :=
match mem_dlookup_kunion.mp h₁ with
| Or.inl h => mem_dlookup_kunion.mpr (Or.inl (mem_dlookup_kunion.mpr (Or.inl h)))
| Or.inr h => mem_dlookup_kunion.mpr <| Or.inr ⟨mt mem_keys_kunion.mp (not_or.mpr ⟨h.1, h₂⟩), h.2⟩
end List
|
TriangleShift.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.CategoryTheory.Linear.LinearFunctor
import Mathlib.CategoryTheory.Triangulated.Rotate
import Mathlib.Algebra.Ring.NegOnePow
/-!
# The shift on the category of triangles
In this file, it is shown that if `C` is a preadditive category with
a shift by `ℤ`, then the category of triangles `Triangle C` is also
endowed with a shift. We also show that rotating triangles three times
identifies with the shift by `1`.
The shift on the category of triangles was also obtained by Adam Topaz,
Johan Commelin and Andrew Yang during the Liquid Tensor Experiment.
-/
assert_not_exists TwoSidedIdeal
universe v u
namespace CategoryTheory
open Category Preadditive
variable (C : Type u) [Category.{v} C] [Preadditive C] [HasShift C ℤ]
[∀ (n : ℤ), (CategoryTheory.shiftFunctor C n).Additive]
namespace Pretriangulated
attribute [local simp] Triangle.eqToHom_hom₁ Triangle.eqToHom_hom₂ Triangle.eqToHom_hom₃
shiftFunctorAdd_zero_add_hom_app shiftFunctorAdd_add_zero_hom_app
shiftFunctorAdd'_eq_shiftFunctorAdd shift_shiftFunctorCompIsoId_inv_app
/-- The shift functor `Triangle C ⥤ Triangle C` by `n : ℤ` sends a triangle
to the triangle obtained by shifting the objects by `n` in `C` and by
multiplying the three morphisms by `(-1)^n`. -/
@[simps]
noncomputable def Triangle.shiftFunctor (n : ℤ) : Triangle C ⥤ Triangle C where
obj T := Triangle.mk (n.negOnePow • T.mor₁⟦n⟧') (n.negOnePow • T.mor₂⟦n⟧')
(n.negOnePow • T.mor₃⟦n⟧' ≫ (shiftFunctorComm C 1 n).hom.app T.obj₁)
map f :=
{ hom₁ := f.hom₁⟦n⟧'
hom₂ := f.hom₂⟦n⟧'
hom₃ := f.hom₃⟦n⟧'
comm₁ := by
dsimp
simp only [Linear.units_smul_comp, Linear.comp_units_smul, ← Functor.map_comp, f.comm₁]
comm₂ := by
dsimp
simp only [Linear.units_smul_comp, Linear.comp_units_smul, ← Functor.map_comp, f.comm₂]
comm₃ := by
dsimp
rw [Linear.units_smul_comp, Linear.comp_units_smul, ← Functor.map_comp_assoc, ← f.comm₃,
Functor.map_comp, assoc, assoc]
erw [(shiftFunctorComm C 1 n).hom.naturality]
rfl }
/-- The canonical isomorphism `Triangle.shiftFunctor C 0 ≅ 𝟭 (Triangle C)`. -/
@[simps!]
noncomputable def Triangle.shiftFunctorZero : Triangle.shiftFunctor C 0 ≅ 𝟭 _ :=
NatIso.ofComponents
(fun T => Triangle.isoMk _ _ ((CategoryTheory.shiftFunctorZero C ℤ).app _)
((CategoryTheory.shiftFunctorZero C ℤ).app _) ((CategoryTheory.shiftFunctorZero C ℤ).app _)
(by simp) (by simp) (by
dsimp
simp only [one_smul, assoc, shiftFunctorComm_zero_hom_app,
← Functor.map_comp, Iso.inv_hom_id_app, Functor.id_obj, Functor.map_id,
comp_id, NatTrans.naturality, Functor.id_map]))
(by cat_disch)
/-- The canonical isomorphism
`Triangle.shiftFunctor C n ≅ Triangle.shiftFunctor C a ⋙ Triangle.shiftFunctor C b`
when `a + b = n`. -/
@[simps!]
noncomputable def Triangle.shiftFunctorAdd' (a b n : ℤ) (h : a + b = n) :
Triangle.shiftFunctor C n ≅ Triangle.shiftFunctor C a ⋙ Triangle.shiftFunctor C b :=
NatIso.ofComponents
(fun T => Triangle.isoMk _ _
((CategoryTheory.shiftFunctorAdd' C a b n h).app _)
((CategoryTheory.shiftFunctorAdd' C a b n h).app _)
((CategoryTheory.shiftFunctorAdd' C a b n h).app _)
(by
subst h
dsimp
rw [Linear.units_smul_comp, NatTrans.naturality, Linear.comp_units_smul, Functor.comp_map,
Functor.map_units_smul, Linear.comp_units_smul, smul_smul, Int.negOnePow_add, mul_comm])
(by
subst h
dsimp
rw [Linear.units_smul_comp, NatTrans.naturality, Linear.comp_units_smul, Functor.comp_map,
Functor.map_units_smul, Linear.comp_units_smul, smul_smul, Int.negOnePow_add, mul_comm])
(by
subst h
dsimp
rw [Linear.units_smul_comp, Linear.comp_units_smul, Functor.map_units_smul,
Linear.units_smul_comp, Linear.comp_units_smul, smul_smul, assoc,
Functor.map_comp, assoc]
erw [← NatTrans.naturality_assoc]
simp only [shiftFunctorAdd'_eq_shiftFunctorAdd, Int.negOnePow_add,
shiftFunctorComm_hom_app_comp_shift_shiftFunctorAdd_hom_app, add_comm a]))
(by cat_disch)
/-- Rotating triangles three times identifies with the shift by `1`. -/
noncomputable def rotateRotateRotateIso :
rotate C ⋙ rotate C ⋙ rotate C ≅ Triangle.shiftFunctor C 1 :=
NatIso.ofComponents
(fun T => Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by simp) (by simp) (by simp))
(by cat_disch)
/-- Rotating triangles three times backwards identifies with the shift by `-1`. -/
noncomputable def invRotateInvRotateInvRotateIso :
invRotate C ⋙ invRotate C ⋙ invRotate C ≅ Triangle.shiftFunctor C (-1) :=
NatIso.ofComponents
(fun T => Triangle.isoMk _ _ (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by simp)
(by simp)
(by
dsimp [shiftFunctorCompIsoId]
simp [shiftFunctorComm_eq C _ _ _ (add_neg_cancel (1 : ℤ))]))
(by cat_disch)
/-- The inverse of the rotation of triangles can be expressed using a double
rotation and the shift by `-1`. -/
noncomputable def invRotateIsoRotateRotateShiftFunctorNegOne :
invRotate C ≅ rotate C ⋙ rotate C ⋙ Triangle.shiftFunctor C (-1) :=
calc
invRotate C ≅ invRotate C ⋙ 𝟭 _ := (Functor.rightUnitor _).symm
_ ≅ invRotate C ⋙ Triangle.shiftFunctor C 0 :=
Functor.isoWhiskerLeft _ (Triangle.shiftFunctorZero C).symm
_ ≅ invRotate C ⋙ Triangle.shiftFunctor C 1 ⋙ Triangle.shiftFunctor C (-1) :=
Functor.isoWhiskerLeft _ (Triangle.shiftFunctorAdd' C 1 (-1) 0 (add_neg_cancel 1))
_ ≅ invRotate C ⋙ (rotate C ⋙ rotate C ⋙ rotate C) ⋙ Triangle.shiftFunctor C (-1) :=
Functor.isoWhiskerLeft _ (Functor.isoWhiskerRight (rotateRotateRotateIso C).symm _)
_ ≅ (invRotate C ⋙ rotate C) ⋙ rotate C ⋙ rotate C ⋙ Triangle.shiftFunctor C (-1) :=
Functor.isoWhiskerLeft _ (Functor.associator _ _ _ ≪≫
Functor.isoWhiskerLeft _ (Functor.associator _ _ _)) ≪≫ (Functor.associator _ _ _).symm
_ ≅ 𝟭 _ ⋙ rotate C ⋙ rotate C ⋙ Triangle.shiftFunctor C (-1) :=
Functor.isoWhiskerRight (triangleRotation C).counitIso _
_ ≅ _ := Functor.leftUnitor _
namespace Triangle
noncomputable instance : HasShift (Triangle C) ℤ :=
hasShiftMk (Triangle C) ℤ
{ F := Triangle.shiftFunctor C
zero := Triangle.shiftFunctorZero C
add := fun a b => Triangle.shiftFunctorAdd' C a b _ rfl
assoc_hom_app := fun a b c T => by
ext
all_goals
dsimp
rw [← shiftFunctorAdd'_assoc_hom_app a b c _ _ _ rfl rfl (add_assoc a b c)]
dsimp only [CategoryTheory.shiftFunctorAdd']
simp }
@[simp]
lemma shiftFunctor_eq (n : ℤ) :
CategoryTheory.shiftFunctor (Triangle C) n = Triangle.shiftFunctor C n := rfl
@[simp]
lemma shiftFunctorZero_eq :
CategoryTheory.shiftFunctorZero (Triangle C) ℤ = Triangle.shiftFunctorZero C :=
ShiftMkCore.shiftFunctorZero_eq _
@[simp]
lemma shiftFunctorAdd_eq (a b : ℤ) :
CategoryTheory.shiftFunctorAdd (Triangle C) a b =
Triangle.shiftFunctorAdd' C a b _ rfl :=
ShiftMkCore.shiftFunctorAdd_eq _ _ _
@[simp]
lemma shiftFunctorAdd'_eq (a b c : ℤ) (h : a + b = c) :
CategoryTheory.shiftFunctorAdd' (Triangle C) a b c h =
Triangle.shiftFunctorAdd' C a b c h := by
subst h
rw [shiftFunctorAdd'_eq_shiftFunctorAdd]
apply shiftFunctorAdd_eq
end Triangle
end Pretriangulated
end CategoryTheory
|
AddTorsor.lean
|
/-
Copyright (c) 2024 Scott Carnahan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Carnahan
-/
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Order.Monoid.Defs
/-!
# Ordered scalar multiplication and vector addition
This file defines ordered scalar multiplication and vector addition, and proves some properties.
In the additive case, a motivating example is given by the additive action of `ℤ` on subsets of
reals that are closed under integer translation. The order compatibility allows for a treatment of
the `R((z))`-module structure on `(z ^ s) V((z))` for an `R`-module `V`, using the formalism of Hahn
series. In the multiplicative case, a standard example is the action of non-negative rationals on
an ordered field.
## Implementation notes
* Because these classes mix the algebra and order hierarchies, we write them as `Prop`-valued
mixins.
* Despite the file name, Ordered AddTorsors are not defined as a separate class. To implement them,
combine `[AddTorsor G P]` with `[IsOrderedCancelVAdd G P]`
## Definitions
* IsOrderedSMul : inequalities are preserved by scalar multiplication.
* IsOrderedVAdd : inequalities are preserved by translation.
* IsCancelSMul : the scalar multiplication version of cancellative multiplication
* IsCancelVAdd : the vector addition version of cancellative addition
* IsOrderedCancelSMul : inequalities are preserved and reflected by scalar multiplication.
* IsOrderedCancelVAdd : inequalities are preserved and reflected by translation.
## Instances
* OrderedCommMonoid.toIsOrderedSMul
* OrderedAddCommMonoid.toIsOrderedVAdd
* IsOrderedSMul.toCovariantClassLeft
* IsOrderedVAdd.toCovariantClassLeft
* IsOrderedCancelSMul.toCancelSMul
* IsOrderedCancelVAdd.toCancelVAdd
* OrderedCancelCommMonoid.toIsOrderedCancelSMul
* OrderedCancelAddCommMonoid.toIsOrderedCancelVAdd
* IsOrderedCancelSMul.toContravariantClassLeft
* IsOrderedCancelVAdd.toContravariantClassLeft
## TODO
* (lex) prod instances
* Pi instances
* WithTop (in a different file?)
-/
open Function
variable {G P : Type*}
/-- An ordered vector addition is a bi-monotone vector addition. -/
class IsOrderedVAdd (G P : Type*) [LE G] [LE P] [VAdd G P] : Prop where
protected vadd_le_vadd_left : ∀ a b : P, a ≤ b → ∀ c : G, c +ᵥ a ≤ c +ᵥ b
protected vadd_le_vadd_right : ∀ c d : G, c ≤ d → ∀ a : P, c +ᵥ a ≤ d +ᵥ a
/-- An ordered scalar multiplication is a bi-monotone scalar multiplication. Note that this is
different from `OrderedSMul`, which uses strict inequality, requires `G` to be a semiring, and the
defining conditions are restricted to positive elements of `G`. -/
@[to_additive]
class IsOrderedSMul (G P : Type*) [LE G] [LE P] [SMul G P] : Prop where
protected smul_le_smul_left : ∀ a b : P, a ≤ b → ∀ c : G, c • a ≤ c • b
protected smul_le_smul_right : ∀ c d : G, c ≤ d → ∀ a : P, c • a ≤ d • a
@[to_additive]
instance [LE G] [LE P] [SMul G P] [IsOrderedSMul G P] : CovariantClass G P (· • ·) (· ≤ ·) where
elim := fun a _ _ bc ↦ IsOrderedSMul.smul_le_smul_left _ _ bc a
@[to_additive]
instance [CommMonoid G] [PartialOrder G] [IsOrderedMonoid G] : IsOrderedSMul G G where
smul_le_smul_left _ _ := mul_le_mul_left'
smul_le_smul_right _ _ := mul_le_mul_right'
@[to_additive]
theorem IsOrderedSMul.smul_le_smul [LE G] [Preorder P] [SMul G P] [IsOrderedSMul G P]
{a b : G} {c d : P} (hab : a ≤ b) (hcd : c ≤ d) : a • c ≤ b • d :=
(IsOrderedSMul.smul_le_smul_left _ _ hcd _).trans (IsOrderedSMul.smul_le_smul_right _ _ hab _)
@[to_additive]
theorem Monotone.smul {γ : Type*} [Preorder G] [Preorder P] [Preorder γ] [SMul G P]
[IsOrderedSMul G P] {f : γ → G} {g : γ → P} (hf : Monotone f) (hg : Monotone g) :
Monotone fun x => f x • g x :=
fun _ _ hab => (IsOrderedSMul.smul_le_smul_left _ _ (hg hab) _).trans
(IsOrderedSMul.smul_le_smul_right _ _ (hf hab) _)
/-- A vector addition is cancellative if it is pointwise injective on the left and right. -/
class IsCancelVAdd (G P : Type*) [VAdd G P] : Prop where
protected left_cancel : ∀ (a : G) (b c : P), a +ᵥ b = a +ᵥ c → b = c
protected right_cancel : ∀ (a b : G) (c : P), a +ᵥ c = b +ᵥ c → a = b
/-- A scalar multiplication is cancellative if it is pointwise injective on the left and right. -/
@[to_additive]
class IsCancelSMul (G P : Type*) [SMul G P] : Prop where
protected left_cancel : ∀ (a : G) (b c : P), a • b = a • c → b = c
protected right_cancel : ∀ (a b : G) (c : P), a • c = b • c → a = b
/-- An ordered cancellative vector addition is an ordered vector addition that is cancellative. -/
class IsOrderedCancelVAdd (G P : Type*) [LE G] [LE P] [VAdd G P] : Prop
extends IsOrderedVAdd G P where
protected le_of_vadd_le_vadd_left : ∀ (a : G) (b c : P), a +ᵥ b ≤ a +ᵥ c → b ≤ c
protected le_of_vadd_le_vadd_right : ∀ (a b : G) (c : P), a +ᵥ c ≤ b +ᵥ c → a ≤ b
/-- An ordered cancellative scalar multiplication is an ordered scalar multiplication that is
cancellative. -/
@[to_additive]
class IsOrderedCancelSMul (G P : Type*) [LE G] [LE P] [SMul G P] : Prop
extends IsOrderedSMul G P where
protected le_of_smul_le_smul_left : ∀ (a : G) (b c : P), a • b ≤ a • c → b ≤ c
protected le_of_smul_le_smul_right : ∀ (a b : G) (c : P), a • c ≤ b • c → a ≤ b
@[to_additive]
instance [PartialOrder G] [PartialOrder P] [SMul G P] [IsOrderedCancelSMul G P] :
IsCancelSMul G P where
left_cancel a b c h := (IsOrderedCancelSMul.le_of_smul_le_smul_left a b c h.le).antisymm
(IsOrderedCancelSMul.le_of_smul_le_smul_left a c b h.ge)
right_cancel a b c h := (IsOrderedCancelSMul.le_of_smul_le_smul_right a b c h.le).antisymm
(IsOrderedCancelSMul.le_of_smul_le_smul_right b a c h.ge)
@[to_additive]
instance [CommMonoid G] [PartialOrder G] [IsOrderedCancelMonoid G] : IsOrderedCancelSMul G G where
le_of_smul_le_smul_left _ _ _ := le_of_mul_le_mul_left'
le_of_smul_le_smul_right _ _ _ := le_of_mul_le_mul_right'
@[to_additive]
instance (priority := 200) [LE G] [LE P] [SMul G P] [IsOrderedCancelSMul G P] :
ContravariantClass G P (· • ·) (· ≤ ·) :=
⟨IsOrderedCancelSMul.le_of_smul_le_smul_left⟩
namespace SMul
@[to_additive]
theorem smul_lt_smul_of_le_of_lt [LE G] [Preorder P] [SMul G P] [IsOrderedCancelSMul G P]
{a b : G} {c d : P} (h₁ : a ≤ b) (h₂ : c < d) :
a • c < b • d := by
refine lt_of_le_of_lt (IsOrderedSMul.smul_le_smul_right a b h₁ c) ?_
refine lt_of_le_not_ge (IsOrderedSMul.smul_le_smul_left c d (le_of_lt h₂) b) ?_
by_contra hbdc
have h : d ≤ c := IsOrderedCancelSMul.le_of_smul_le_smul_left b d c hbdc
rw [@lt_iff_le_not_ge] at h₂
simp_all only [not_true_eq_false, and_false]
@[to_additive]
theorem smul_lt_smul_of_lt_of_le [Preorder G] [Preorder P] [SMul G P] [IsOrderedCancelSMul G P]
{a b : G} {c d : P} (h₁ : a < b) (h₂ : c ≤ d) : a • c < b • d := by
refine lt_of_le_of_lt (IsOrderedSMul.smul_le_smul_left c d h₂ a) ?_
refine lt_of_le_not_ge (IsOrderedSMul.smul_le_smul_right a b (le_of_lt h₁) d) ?_
by_contra hbad
have h : b ≤ a := IsOrderedCancelSMul.le_of_smul_le_smul_right b a d hbad
rw [@lt_iff_le_not_ge] at h₁
simp_all only [not_true_eq_false, and_false]
end SMul
|
FinCategory.lean
|
/-
Copyright (c) 2025 Moisés Herradón Cueto. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Moisés Herradón Cueto
-/
import Mathlib.CategoryTheory.FinCategory.Basic
import Mathlib.CategoryTheory.WithTerminal.Basic
import Mathlib.Data.Fintype.Option
/-!
# `WithTerminal C` and `WithInitial C` are finite whenever `C` is
If `C` has finitely many objects, then so do `WithTerminal C` and `WithInitial C`,
and likewise if `C` has finitely many morphisms as well.
-/
universe v u
variable (C : Type u) [CategoryTheory.Category.{v} C]
namespace CategoryTheory.WithTerminal
/-- The equivalence between `Option C` and `WithTerminal C` (they are both the
type `C` plus an extra object `none` or `star`). -/
def optionEquiv : Option C ≃ WithTerminal C where
toFun
| some a => of a
| none => star
invFun
| of a => some a
| star => none
left_inv a := by cases a <;> simp
right_inv a := by cases a <;> simp
instance instFintype [Fintype C] : Fintype (WithTerminal C) :=
.ofEquiv (Option C) <| optionEquiv C
instance instFinCategory [SmallCategory C] [FinCategory C] :
FinCategory (WithTerminal C) where
fintypeObj := inferInstance
fintypeHom
| star, star
| of _, star => (inferInstance : Fintype PUnit)
| star, of _ => (inferInstance : Fintype PEmpty)
| of a, of b => (inferInstance : Fintype (a ⟶ b))
end CategoryTheory.WithTerminal
namespace CategoryTheory.WithInitial
/-- The equivalence between `Option C` and `WithInitial C` (they are both the
type `C` plus an extra object `none` or `star`). -/
def optionEquiv : Option C ≃ WithInitial C where
toFun
| some a => of a
| none => star
invFun
| of a => some a
| star => none
left_inv a := by cases a <;> simp
right_inv a := by cases a <;> simp
instance instFintype [Fintype C] : Fintype (WithInitial C) :=
.ofEquiv (Option C) <| optionEquiv C
instance instFinCategory [SmallCategory C] [FinCategory C] :
FinCategory (WithInitial C) where
fintypeObj := inferInstance
fintypeHom
| star, star
| star, of _ => (inferInstance : Fintype PUnit)
| of _, star => (inferInstance : Fintype PEmpty)
| of a, of b => (inferInstance : Fintype (a ⟶ b))
end CategoryTheory.WithInitial
|
DomMulAct.lean
|
/-
Copyright (c) 2023 Junyan Xu, Antoine Chambert-Loir. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Junyan Xu, Antoine Chambert-Loir
-/
import Mathlib.Algebra.Group.Action.End
import Mathlib.Data.Fintype.Perm
import Mathlib.Data.Set.Card
import Mathlib.GroupTheory.GroupAction.Defs
import Mathlib.GroupTheory.GroupAction.DomAct.Basic
/-!
# Subgroup of `Equiv.Perm α` preserving a function
Let `α` and `ι` by types and let `f : α → ι`
* `DomMulAct.mem_stabilizer_iff` proves that the stabilizer of `f : α → ι`
in `(Equiv.Perm α)ᵈᵐᵃ` is the set of `g : (Equiv.Perm α)ᵈᵐᵃ` such that `f ∘ (mk.symm g) = f`.
The natural equivalence from `stabilizer (Perm α)ᵈᵐᵃ f` to `{ g : Perm α // p ∘ g = f }`
can be obtained as `subtypeEquiv mk.symm (fun _ => mem_stabilizer_iff)`
* `DomMulAct.stabilizerMulEquiv` is the `MulEquiv` from
the MulOpposite of this stabilizer to the product,
for `i : ι`, of `Equiv.Perm {a // f a = i}`.
* Under `Fintype α` and `Fintype ι`, `DomMulAct.stabilizer_card p` computes
the cardinality of the type of permutations preserving `p` :
`Fintype.card {g : Perm α // f ∘ g = f} = ∏ i, (Fintype.card {a // f a = i})!`.
* Without `Fintype ι`, `DomMulAct.stabilizer_card' p` gives an equivalent
formula, where the product is restricted to `Finset.univ.image f`.
-/
assert_not_exists Field
open Equiv MulAction
variable {α ι : Type*} {f : α → ι}
namespace DomMulAct
lemma mem_stabilizer_iff {g : (Perm α)ᵈᵐᵃ} :
g ∈ stabilizer (Perm α)ᵈᵐᵃ f ↔ f ∘ (mk.symm g :) = f := by
simp only [MulAction.mem_stabilizer_iff]; rfl
/-- The `invFun` component of `MulEquiv` from `MulAction.stabilizer (Perm α) f`
to the product of the `Equiv.Perm {a // f a = i} -/
def stabilizerEquiv_invFun (g : ∀ i, Perm {a // f a = i}) (a : α) : α := g (f a) ⟨a, rfl⟩
lemma stabilizerEquiv_invFun_eq (g : ∀ i, Perm {a // f a = i}) {a : α} {i : ι} (h : f a = i) :
stabilizerEquiv_invFun g a = g i ⟨a, h⟩ := by subst h; rfl
lemma comp_stabilizerEquiv_invFun (g : ∀ i, Perm {a // f a = i}) (a : α) :
f (stabilizerEquiv_invFun g a) = f a :=
(g (f a) ⟨a, rfl⟩).prop
/-- The `invFun` component of `MulEquiv` from `MulAction.stabilizer (Perm α) p`
to the product of the `Equiv.Perm {a | f a = i} (as an `Equiv.Perm α`) -/
def stabilizerEquiv_invFun_aux (g : ∀ i, Perm {a // f a = i}) : Perm α where
toFun := stabilizerEquiv_invFun g
invFun := stabilizerEquiv_invFun (fun i ↦ (g i).symm)
left_inv a := by
rw [stabilizerEquiv_invFun_eq _ (comp_stabilizerEquiv_invFun g a)]
exact congr_arg Subtype.val ((g <| f a).left_inv _)
right_inv a := by
rw [stabilizerEquiv_invFun_eq _ (comp_stabilizerEquiv_invFun _ a)]
exact congr_arg Subtype.val ((g <| f a).right_inv _)
variable (f) in
/-- The `MulEquiv` from the `MulOpposite` of `MulAction.stabilizer (Perm α)ᵈᵐᵃ f`
to the product of the `Equiv.Perm {a // f a = i}` -/
def stabilizerMulEquiv : (stabilizer (Perm α)ᵈᵐᵃ f)ᵐᵒᵖ ≃* (∀ i, Perm {a // f a = i}) where
toFun g i := Perm.subtypePerm (mk.symm g.unop) fun a ↦ by
rw [← Function.comp_apply (f := f), mem_stabilizer_iff.mp g.unop.prop]
invFun g := ⟨mk (stabilizerEquiv_invFun_aux g), by
ext a
rw [smul_apply, symm_apply_apply, Perm.smul_def]
apply comp_stabilizerEquiv_invFun⟩
right_inv g := by ext i a; apply stabilizerEquiv_invFun_eq
map_mul' _ _ := rfl
lemma stabilizerMulEquiv_apply (g : (stabilizer (Perm α)ᵈᵐᵃ f)ᵐᵒᵖ) {a : α} {i : ι} (h : f a = i) :
((stabilizerMulEquiv f)) g i ⟨a, h⟩ = (mk.symm g.unop : Equiv.Perm α) a := rfl
section Fintype
variable [Fintype α]
open Nat
variable (f)
/-- The cardinality of the type of permutations preserving a function -/
theorem stabilizer_card [DecidableEq α] [DecidableEq ι] [Fintype ι] :
Fintype.card {g : Perm α // f ∘ g = f} = ∏ i, (Fintype.card {a // f a = i})! := by
-- rewriting via Nat.card because Fintype instance is not found
rw [← Nat.card_eq_fintype_card,
Nat.card_congr (subtypeEquiv mk fun _ ↦ ?_),
Nat.card_congr MulOpposite.opEquiv,
Nat.card_congr (DomMulAct.stabilizerMulEquiv f).toEquiv, Nat.card_pi]
· exact Finset.prod_congr rfl fun i _ ↦ by rw [Nat.card_eq_fintype_card, Fintype.card_perm]
· rfl
omit [Fintype α] in
/-- The cardinality of the set of permutations preserving a function -/
theorem stabilizer_ncard [Finite α] [Fintype ι] :
Set.ncard {g : Perm α | f ∘ g = f} = ∏ i, (Set.ncard {a | f a = i})! := by
classical
cases nonempty_fintype α
simp only [← Nat.card_coe_set_eq, Set.coe_setOf, card_eq_fintype_card]
exact stabilizer_card f
variable [DecidableEq α] [DecidableEq ι]
/-- The cardinality of the type of permutations preserving a function
(without the finiteness assumption on target) -/
theorem stabilizer_card' :
Fintype.card {g : Perm α // f ∘ g = f} =
∏ i ∈ Finset.univ.image f, (Fintype.card ({a // f a = i}))! := by
set φ : α → Finset.univ.image f :=
Set.codRestrict f (Finset.univ.image f) (fun a => by simp)
suffices ∀ g : Perm α, f ∘ g = f ↔ φ ∘ g = φ by
simp only [this, stabilizer_card]
apply Finset.prod_bij (fun g _ => g.val)
· exact fun g _ => Finset.coe_mem g
· exact fun g _ g' _ => SetCoe.ext
· simp
· intro i _
apply congr_arg
apply Fintype.card_congr
apply Equiv.subtypeEquiv (Equiv.refl α)
intro a
rw [refl_apply, ← Subtype.coe_inj]
simp only [φ, Set.val_codRestrict_apply]
· intro g
simp only [funext_iff]
apply forall_congr'
intro a
simp only [Function.comp_apply, φ, ← Subtype.coe_inj, Set.val_codRestrict_apply]
end Fintype
end DomMulAct
|
Rep.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Category.ModuleCat.Adjunctions
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Category.ModuleCat.Limits
import Mathlib.Algebra.Category.ModuleCat.Colimits
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Symmetric
import Mathlib.Algebra.Category.ModuleCat.Projective
import Mathlib.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Action.Monoidal
import Mathlib.RepresentationTheory.Basic
/-!
# `Rep k G` is the category of `k`-linear representations of `G`.
If `V : Rep k G`, there is a coercion that allows you to treat `V` as a type,
and this type comes equipped with a `Module k V` instance.
Also `V.ρ` gives the homomorphism `G →* (V →ₗ[k] V)`.
Conversely, given a homomorphism `ρ : G →* (V →ₗ[k] V)`,
you can construct the bundled representation as `Rep.of ρ`.
We construct the categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`.
We verify that `Rep k G` is a `k`-linear abelian symmetric monoidal category with all (co)limits.
-/
suppress_compilation
universe u
open CategoryTheory
open CategoryTheory.Limits
/-- The category of `k`-linear representations of a monoid `G`. -/
abbrev Rep (k G : Type u) [Ring k] [Monoid G] :=
Action (ModuleCat.{u} k) G
instance (k G : Type u) [CommRing k] [Monoid G] : Linear k (Rep k G) := by infer_instance
namespace Rep
variable {k G : Type u} [CommRing k]
section
variable [Monoid G]
instance : CoeSort (Rep k G) (Type u) :=
⟨fun V => V.V⟩
instance (V : Rep k G) : AddCommGroup V := by
change AddCommGroup ((forget₂ (Rep k G) (ModuleCat k)).obj V); infer_instance
instance (V : Rep k G) : Module k V := by
change Module k ((forget₂ (Rep k G) (ModuleCat k)).obj V)
infer_instance
/-- Specialize the existing `Action.ρ`, changing the type to `Representation k G V`.
-/
def ρ (V : Rep k G) : Representation k G V :=
-- Porting note: was `V.ρ`
(ModuleCat.endRingEquiv V.V).toMonoidHom.comp (Action.ρ V)
/-- Lift an unbundled representation to `Rep`. -/
abbrev of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : Rep k G :=
⟨ModuleCat.of k V, (ModuleCat.endRingEquiv _).symm.toMonoidHom.comp ρ⟩
theorem coe_of {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) :
(of ρ : Type u) = V :=
rfl
@[simp]
theorem of_ρ {V : Type u} [AddCommGroup V] [Module k V] (ρ : G →* V →ₗ[k] V) : (of ρ).ρ = ρ :=
rfl
theorem Action_ρ_eq_ρ {A : Rep k G} :
Action.ρ A = (ModuleCat.endRingEquiv _).symm.toMonoidHom.comp A.ρ :=
rfl
@[simp]
lemma ρ_hom {X : Rep k G} (g : G) : (Action.ρ X g).hom = X.ρ g := rfl
@[simp]
lemma ofHom_ρ {X : Rep k G} (g : G) : ModuleCat.ofHom (X.ρ g) = Action.ρ X g := rfl
@[deprecated Representation.inv_self_apply (since := "2025-05-09")]
theorem ρ_inv_self_apply {G : Type u} [Group G] (A : Rep k G) (g : G) (x : A) :
A.ρ g⁻¹ (A.ρ g x) = x :=
show (A.ρ g⁻¹ * A.ρ g) x = x by rw [← map_mul, inv_mul_cancel, map_one, Module.End.one_apply]
@[deprecated Representation.self_inv_apply (since := "2025-05-09")]
theorem ρ_self_inv_apply {G : Type u} [Group G] {A : Rep k G} (g : G) (x : A) :
A.ρ g (A.ρ g⁻¹ x) = x :=
show (A.ρ g * A.ρ g⁻¹) x = x by rw [← map_mul, mul_inv_cancel, map_one, Module.End.one_apply]
theorem hom_comm_apply {A B : Rep k G} (f : A ⟶ B) (g : G) (x : A) :
f.hom (A.ρ g x) = B.ρ g (f.hom x) :=
LinearMap.ext_iff.1 (ModuleCat.hom_ext_iff.mp (f.comm g)) x
variable (k G)
/-- The trivial `k`-linear `G`-representation on a `k`-module `V.` -/
abbrev trivial (V : Type u) [AddCommGroup V] [Module k V] : Rep k G :=
Rep.of (Representation.trivial k G V)
variable {k G}
theorem trivial_def {V : Type u} [AddCommGroup V] [Module k V] (g : G) :
(trivial k G V).ρ g = LinearMap.id :=
rfl
variable (k G) in
/-- The functor equipping a module with the trivial representation. -/
@[simps! obj_V map_hom]
def trivialFunctor : ModuleCat k ⥤ Rep k G where
obj V := trivial k G V
map f := { hom := f, comm := fun _ => rfl }
/-- A predicate for representations that fix every element. -/
abbrev IsTrivial (A : Rep k G) := A.ρ.IsTrivial
instance (X : ModuleCat k) : ((trivialFunctor k G).obj X).IsTrivial where
instance {V : Type u} [AddCommGroup V] [Module k V] :
IsTrivial (Rep.trivial k G V) where
instance {V : Type u} [AddCommGroup V] [Module k V] (ρ : Representation k G V) [ρ.IsTrivial] :
IsTrivial (Rep.of ρ) where
instance {H V : Type u} [Group H] [AddCommGroup V] [Module k V] (ρ : Representation k H V)
(f : G →* H) [Representation.IsTrivial (ρ.comp f)] :
Representation.IsTrivial ((Rep.of ρ).ρ.comp f) := ‹_›
section Commutative
variable {k G : Type u} [CommRing k] [CommMonoid G]
variable (A : Rep k G)
/-- Given a representation `A` of a commutative monoid `G`, the map `ρ_A(g)` is a representation
morphism `A ⟶ A` for any `g : G`. -/
@[simps]
def applyAsHom (g : G) : A ⟶ A where
hom := ModuleCat.ofHom (A.ρ g)
comm _ := by ext; simp [← Module.End.mul_apply, ← map_mul, mul_comm]
@[reassoc, elementwise]
lemma applyAsHom_comm {A B : Rep k G} (f : A ⟶ B) (g : G) :
A.applyAsHom g ≫ f = f ≫ B.applyAsHom g := by
ext
simp [hom_comm_apply]
end Commutative
section
variable {G : Type u} [Group G] (A : Rep k G) (S : Subgroup G)
[S.Normal] [Representation.IsTrivial (A.ρ.comp S.subtype)]
/-- Given a normal subgroup `S ≤ G`, a `G`-representation `ρ` which is trivial on `S` factors
through `G ⧸ S`. -/
abbrev ofQuotient : Rep k (G ⧸ S) := Rep.of (A.ρ.ofQuotient S)
/-- A `G`-representation `A` on which a normal subgroup `S ≤ G` acts trivially induces a
`G ⧸ S`-representation on `A`, and composing this with the quotient map `G → G ⧸ S` gives the
original representation by definition. Useful for typechecking. -/
abbrev resOfQuotientIso [Representation.IsTrivial (A.ρ.comp S.subtype)] :
(Action.res _ (QuotientGroup.mk' S)).obj (A.ofQuotient S) ≅ A := Iso.refl _
end
variable (A : Rep k G)
/-- Given a `k`-linear `G`-representation `(V, ρ)`, this is the representation defined by
restricting `ρ` to a `G`-invariant `k`-submodule of `V`. -/
abbrev subrepresentation (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
Rep k G :=
Rep.of (A.ρ.subrepresentation W le_comap)
/-- The natural inclusion of a subrepresentation into the ambient representation. -/
@[simps]
def subtype (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
subrepresentation A W le_comap ⟶ A where
hom := ModuleCat.ofHom W.subtype
comm _ := rfl
/-- Given a `k`-linear `G`-representation `(V, ρ)` and a `G`-invariant `k`-submodule `W ≤ V`, this
is the representation induced on `V ⧸ W` by `ρ`. -/
abbrev quotient (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
Rep k G :=
Rep.of (A.ρ.quotient W le_comap)
/-- The natural projection from a representation to its quotient by a subrepresentation. -/
@[simps]
def mkQ (W : Submodule k A) (le_comap : ∀ g, W ≤ W.comap (A.ρ g)) :
A ⟶ quotient A W le_comap where
hom := ModuleCat.ofHom <| Submodule.mkQ _
comm _ := rfl
-- Porting note: the two following instances were found automatically in mathlib3
instance : PreservesLimits (forget₂ (Rep k G) (ModuleCat.{u} k)) :=
Action.preservesLimits_forget _ _
instance : PreservesColimits (forget₂ (Rep k G) (ModuleCat.{u} k)) :=
Action.preservesColimits_forget _ _
theorem epi_iff_surjective {A B : Rep k G} (f : A ⟶ B) : Epi f ↔ Function.Surjective f.hom :=
⟨fun _ => (ModuleCat.epi_iff_surjective ((forget₂ _ _).map f)).1 inferInstance,
fun h => (forget₂ _ _).epi_of_epi_map ((ModuleCat.epi_iff_surjective <|
(forget₂ _ _).map f).2 h)⟩
theorem mono_iff_injective {A B : Rep k G} (f : A ⟶ B) : Mono f ↔ Function.Injective f.hom :=
⟨fun _ => (ModuleCat.mono_iff_injective ((forget₂ _ _).map f)).1 inferInstance,
fun h => (forget₂ _ _).mono_of_mono_map ((ModuleCat.mono_iff_injective <|
(forget₂ _ _).map f).2 h)⟩
instance {A B : Rep k G} (f : A ⟶ B) [Mono f] : Mono f.hom :=
inferInstanceAs <| Mono ((forget₂ _ _).map f)
instance {A B : Rep k G} (f : A ⟶ B) [Epi f] : Epi f.hom :=
inferInstanceAs <| Epi ((forget₂ _ _).map f)
open MonoidalCategory in
@[simp]
theorem tensor_ρ {A B : Rep k G} : (A ⊗ B).ρ = A.ρ.tprod B.ρ := rfl
@[simp]
lemma res_obj_ρ {H : Type u} [Monoid H] (f : G →* H) (A : Rep k H) :
ρ ((Action.res _ f).obj A) = A.ρ.comp f := rfl
@[simp]
lemma coe_res_obj_ρ {H : Type u} [Monoid H] (f : G →* H) (A : Rep k H) (g : G) :
DFunLike.coe (F := G →* (A →ₗ[k] A)) (ρ ((Action.res _ f).obj A)) g = A.ρ (f g) := rfl
section Linearization
variable (k G)
/-- The monoidal functor sending a type `H` with a `G`-action to the induced `k`-linear
`G`-representation on `k[H].` -/
def linearization : (Action (Type u) G) ⥤ (Rep k G) :=
(ModuleCat.free k).mapAction G
instance : (linearization k G).Monoidal := by
dsimp only [linearization]
infer_instance
variable {k G}
@[simp]
theorem coe_linearization_obj (X : Action (Type u) G) :
(linearization k G).obj X = (X.V →₀ k) := rfl
theorem linearization_obj_ρ (X : Action (Type u) G) (g : G) :
((linearization k G).obj X).ρ g = Finsupp.lmapDomain k k (X.ρ g) :=
rfl
@[simp]
theorem coe_linearization_obj_ρ (X : Action (Type u) G) (g : G) :
@DFunLike.coe (no_index G →* ((X.V →₀ k) →ₗ[k] (X.V →₀ k))) _
(fun _ => (X.V →₀ k) →ₗ[k] (X.V →₀ k)) _
((linearization k G).obj X).ρ g = Finsupp.lmapDomain k k (X.ρ g) := rfl
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): helps fixing `linearizationTrivialIso` since change in behaviour of `ext`.
theorem linearization_single (X : Action (Type u) G) (g : G) (x : X.V) (r : k) :
((linearization k G).obj X).ρ g (Finsupp.single x r) = Finsupp.single (X.ρ g x) r := by
simp
@[deprecated "Use `Rep.linearization_single` instead" (since := "2025-06-02")]
theorem linearization_of (X : Action (Type u) G) (g : G) (x : X.V) :
((linearization k G).obj X).ρ g (Finsupp.single x (1 : k))
= Finsupp.single (X.ρ g x) (1 : k) := by
simp
variable {X Y : Action (Type u) G} (f : X ⟶ Y)
@[simp]
theorem linearization_map_hom : ((linearization k G).map f).hom =
ModuleCat.ofHom (Finsupp.lmapDomain k k f.hom) :=
rfl
theorem linearization_map_hom_single (x : X.V) (r : k) :
((linearization k G).map f).hom (Finsupp.single x r) = Finsupp.single (f.hom x) r :=
Finsupp.mapDomain_single
open Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal
@[simp]
theorem linearization_μ_hom (X Y : Action (Type u) G) :
(μ (linearization k G) X Y).hom =
ModuleCat.ofHom (finsuppTensorFinsupp' k X.V Y.V).toLinearMap :=
rfl
@[simp]
theorem linearization_δ_hom (X Y : Action (Type u) G) :
(δ (linearization k G) X Y).hom =
ModuleCat.ofHom (finsuppTensorFinsupp' k X.V Y.V).symm.toLinearMap :=
rfl
@[simp]
theorem linearization_ε_hom : (ε (linearization k G)).hom =
ModuleCat.ofHom (Finsupp.lsingle PUnit.unit) :=
rfl
theorem linearization_η_hom_apply (r : k) :
(η (linearization k G)).hom (Finsupp.single PUnit.unit r) = r :=
(εIso (linearization k G)).hom_inv_id_apply r
variable (k G)
/-- The linearization of a type `X` on which `G` acts trivially is the trivial `G`-representation
on `k[X]`. -/
@[simps! hom_hom inv_hom]
def linearizationTrivialIso (X : Type u) :
(linearization k G).obj (Action.mk X 1) ≅ trivial k G (X →₀ k) :=
Action.mkIso (Iso.refl _) fun _ => ModuleCat.hom_ext <| Finsupp.lhom_ext' fun _ => LinearMap.ext
fun _ => linearization_single ..
/-- Given a `G`-action on `H`, this is `k[H]` bundled with the natural representation
`G →* End(k[H])` as a term of type `Rep k G`. -/
abbrev ofMulAction (H : Type u) [MulAction G H] : Rep k G :=
of <| Representation.ofMulAction k G H
/-- The `k`-linear `G`-representation on `k[G]`, induced by left multiplication. -/
abbrev leftRegular : Rep k G :=
ofMulAction k G G
/-- The `k`-linear `G`-representation on `k[Gⁿ]`, induced by left multiplication. -/
abbrev diagonal (n : ℕ) : Rep k G :=
ofMulAction k G (Fin n → G)
/-- The natural isomorphism between the representations on `k[G¹]` and `k[G]` induced by left
multiplication in `G`. -/
@[simps! hom_hom inv_hom]
def diagonalOneIsoLeftRegular :
diagonal k G 1 ≅ leftRegular k G :=
Action.mkIso (Finsupp.domLCongr <| Equiv.funUnique (Fin 1) G).toModuleIso fun _ =>
ModuleCat.hom_ext <| Finsupp.lhom_ext fun _ _ => by simp [diagonal, ModuleCat.endRingEquiv]
/-- When `H = {1}`, the `G`-representation on `k[H]` induced by an action of `G` on `H` is
isomorphic to the trivial representation on `k`. -/
@[simps! hom_hom inv_hom]
def ofMulActionSubsingletonIsoTrivial
(H : Type u) [Subsingleton H] [MulOneClass H] [MulAction G H] :
ofMulAction k G H ≅ trivial k G k :=
letI : Unique H := uniqueOfSubsingleton 1
Action.mkIso (Finsupp.LinearEquiv.finsuppUnique _ _ _).toModuleIso fun _ =>
ModuleCat.hom_ext <| Finsupp.lhom_ext fun _ _ => by
simp [Subsingleton.elim _ (1 : H), ModuleCat.endRingEquiv]
/-- The linearization of a type `H` with a `G`-action is definitionally isomorphic to the
`k`-linear `G`-representation on `k[H]` induced by the `G`-action on `H`. -/
def linearizationOfMulActionIso (H : Type u) [MulAction G H] :
(linearization k G).obj (Action.ofMulAction G H) ≅ ofMulAction k G H :=
Iso.refl _
section
variable (k G A : Type u) [CommRing k] [Monoid G] [AddCommGroup A]
[Module k A] [DistribMulAction G A] [SMulCommClass G k A]
/-- Turns a `k`-module `A` with a compatible `DistribMulAction` of a monoid `G` into a
`k`-linear `G`-representation on `A`. -/
def ofDistribMulAction : Rep k G := Rep.of (Representation.ofDistribMulAction k G A)
@[simp] theorem ofDistribMulAction_ρ_apply_apply (g : G) (a : A) :
(ofDistribMulAction k G A).ρ g a = g • a := rfl
/-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of
`S ≃ₐ[R] S` on `S`. -/
@[simp] def ofAlgebraAut (R S : Type) [CommRing R] [CommRing S] [Algebra R S] :
Rep ℤ (S ≃ₐ[R] S) := ofDistribMulAction ℤ (S ≃ₐ[R] S) S
end
section
variable (M G : Type) [Monoid M] [CommGroup G] [MulDistribMulAction M G]
/-- Turns a `CommGroup` `G` with a `MulDistribMulAction` of a monoid `M` into a
`ℤ`-linear `M`-representation on `Additive G`. -/
def ofMulDistribMulAction : Rep ℤ M := Rep.of (Representation.ofMulDistribMulAction M G)
@[simp] theorem ofMulDistribMulAction_ρ_apply_apply (g : M) (a : Additive G) :
(ofMulDistribMulAction M G).ρ g a = Additive.ofMul (g • a.toMul) := rfl
/-- Given an `R`-algebra `S`, the `ℤ`-linear representation associated to the natural action of
`S ≃ₐ[R] S` on `Sˣ`. -/
@[simp] def ofAlgebraAutOnUnits (R S : Type) [CommRing R] [CommRing S] [Algebra R S] :
Rep ℤ (S ≃ₐ[R] S) := Rep.ofMulDistribMulAction (S ≃ₐ[R] S) Sˣ
end
variable {k G}
/-- Given an element `x : A`, there is a natural morphism of representations `k[G] ⟶ A` sending
`g ↦ A.ρ(g)(x).` -/
@[simps]
def leftRegularHom (A : Rep k G) (x : A) : leftRegular k G ⟶ A where
hom := ModuleCat.ofHom <| Finsupp.lift A k G fun g => A.ρ g x
comm _ := by ext; simp [ModuleCat.endRingEquiv]
theorem leftRegularHom_hom_single {A : Rep k G} (g : G) (x : A) (r : k) :
(leftRegularHom A x).hom (Finsupp.single g r) = r • A.ρ g x := by simp
/-- Given a `k`-linear `G`-representation `A`, there is a `k`-linear isomorphism between
representation morphisms `Hom(k[G], A)` and `A`. -/
@[simps]
def leftRegularHomEquiv (A : Rep k G) : (leftRegular k G ⟶ A) ≃ₗ[k] A where
toFun f := f.hom (Finsupp.single 1 1)
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun x := leftRegularHom A x
left_inv f := by ext; simp [← hom_comm_apply f]
right_inv x := by simp
theorem leftRegularHomEquiv_symm_single {A : Rep k G} (x : A) (g : G) :
((leftRegularHomEquiv A).symm x).hom (Finsupp.single g 1) = A.ρ g x := by
simp
end Linearization
section Finsupp
open Finsupp
variable (α : Type u) (A : Rep k G)
/-- The representation on `α →₀ A` defined pointwise by a representation on `A`. -/
abbrev finsupp : Rep k G :=
Rep.of (Representation.finsupp A.ρ α)
variable (k G) in
/-- The representation on `α →₀ k[G]` defined pointwise by the left regular representation on
`k[G]`. -/
abbrev free : Rep k G :=
Rep.of (V := (α →₀ G →₀ k)) (Representation.free k G α)
variable {α} [DecidableEq α]
/-- Given `f : α → A`, the natural representation morphism `(α →₀ k[G]) ⟶ A` sending
`single a (single g r) ↦ r • A.ρ g (f a)`. -/
@[simps]
def freeLift (f : α → A) :
free k G α ⟶ A where
hom := ModuleCat.ofHom <| linearCombination k (fun x => A.ρ x.2 (f x.1)) ∘ₗ
(finsuppProdLEquiv k).symm.toLinearMap
comm _ := by
ext; simp [ModuleCat.endRingEquiv]
variable {A} in
lemma freeLift_hom_single_single (f : α → A) (i : α) (g : G) (r : k) :
(freeLift A f).hom (single i (single g r)) = r • A.ρ g (f i) := by
simp
variable (α) in
/-- The natural linear equivalence between functions `α → A` and representation morphisms
`(α →₀ k[G]) ⟶ A`. -/
@[simps]
def freeLiftLEquiv :
(free k G α ⟶ A) ≃ₗ[k] (α → A) where
toFun f i := f.hom (single i (single 1 1))
invFun := freeLift A
left_inv x := by
ext i j
simpa [← map_smul] using (hom_comm_apply x j (single i (single 1 1))).symm
right_inv _ := by ext; simp
map_add' _ _ := rfl
map_smul' _ _ := rfl
variable {A}
@[ext]
lemma free_ext (f g : free k G α ⟶ A)
(h : ∀ i : α, f.hom (single i (single 1 1)) = g.hom (single i (single 1 1))) : f = g :=
(freeLiftLEquiv α A).injective (funext_iff.2 h)
section
open MonoidalCategory
variable (A B : Rep k G) (α : Type u) [DecidableEq α]
open ModuleCat.MonoidalCategory
-- the proof below can be simplified after #24823 is merged
/-- Given representations `A, B` and a type `α`, this is the natural representation isomorphism
`(α →₀ A) ⊗ B ≅ (A ⊗ B) →₀ α` sending `single x a ⊗ₜ b ↦ single x (a ⊗ₜ b)`. -/
@[simps! hom_hom inv_hom]
def finsuppTensorLeft :
A.finsupp α ⊗ B ≅ (A ⊗ B).finsupp α :=
Action.mkIso (TensorProduct.finsuppLeft k A B α).toModuleIso
fun _ => ModuleCat.hom_ext <| TensorProduct.ext <| lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, TensorProduct.finsuppLeft_apply_tmul, tensorObj_def,
ModuleCat.MonoidalCategory.tensorObj, ModuleCat.endRingEquiv]
/-- Given representations `A, B` and a type `α`, this is the natural representation isomorphism
`A ⊗ (α →₀ B) ≅ (A ⊗ B) →₀ α` sending `a ⊗ₜ single x b ↦ single x (a ⊗ₜ b)`. -/
@[simps! hom_hom inv_hom]
def finsuppTensorRight :
A ⊗ B.finsupp α ≅ (A ⊗ B).finsupp α :=
Action.mkIso (TensorProduct.finsuppRight k A B α).toModuleIso fun _ => ModuleCat.hom_ext <|
TensorProduct.ext <| LinearMap.ext fun _ => lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, TensorProduct.finsuppRight_apply_tmul, ModuleCat.endRingEquiv,
tensorObj_def, ModuleCat.MonoidalCategory.tensorObj]
variable (k G) in
/-- The natural isomorphism sending `single g r₁ ⊗ single a r₂ ↦ single a (single g r₁r₂)`. -/
@[simps! -isSimp hom_hom inv_hom]
def leftRegularTensorTrivialIsoFree :
leftRegular k G ⊗ trivial k G (α →₀ k) ≅ free k G α :=
Action.mkIso (finsuppTensorFinsupp' k G α ≪≫ₗ Finsupp.domLCongr (Equiv.prodComm G α) ≪≫ₗ
finsuppProdLEquiv k).toModuleIso fun _ =>
ModuleCat.hom_ext <| TensorProduct.ext <| lhom_ext fun _ _ => lhom_ext fun _ _ => by
ext
simp [Action_ρ_eq_ρ, tensorObj_def, ModuleCat.endRingEquiv, tensorObj_def,
ModuleCat.MonoidalCategory.tensorObj]
variable {α}
@[simp]
lemma leftRegularTensorTrivialIsoFree_hom_hom_single_tmul_single (i : α) (g : G) (r s : k) :
DFunLike.coe (F := ↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k (α →₀ k)) →ₗ[k] α →₀ G →₀ k)
(leftRegularTensorTrivialIsoFree k G α).hom.hom.hom (single g r ⊗ₜ[k] single i s) =
single i (single g (r * s)) := by
simp [leftRegularTensorTrivialIsoFree, tensorObj_def, ModuleCat.MonoidalCategory.tensorObj]
@[simp]
lemma leftRegularTensorTrivialIsoFree_inv_hom_single_single (i : α) (g : G) (r : k) :
DFunLike.coe (F := (α →₀ G →₀ k) →ₗ[k] ↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k (α →₀ k)))
(leftRegularTensorTrivialIsoFree k G α).inv.hom.hom (single i (single g r)) =
single g r ⊗ₜ[k] single i 1 := by
simp [leftRegularTensorTrivialIsoFree, finsuppTensorFinsupp'_symm_single_eq_tmul_single_one,
tensorObj_def, ModuleCat.MonoidalCategory.tensorObj]
end
end Finsupp
end
section Group
open Finsupp MonoidalCategory ModuleCat.MonoidalCategory
open Representation (IsTrivial)
variable [Group G] {n : ℕ}
variable (k G n) in
/-- An isomorphism of `k`-linear representations of `G` from `k[Gⁿ⁺¹]` to `k[G] ⊗ₖ k[Gⁿ]` (on
which `G` acts by `ρ(g₁)(g₂ ⊗ x) = (g₁ * g₂) ⊗ x`) sending `(g₀, ..., gₙ)` to
`g₀ ⊗ (g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ)`. The inverse sends `g₀ ⊗ (g₁, ..., gₙ)` to
`(g₀, g₀g₁, ..., g₀g₁...gₙ)`. -/
def diagonalSuccIsoTensorTrivial :
diagonal k G (n + 1) ≅ leftRegular k G ⊗ trivial k G ((Fin n → G) →₀ k) :=
(linearization k G).mapIso (Action.diagonalSuccIsoTensorTrivial G n) ≪≫
(Functor.Monoidal.μIso (linearization k G) _ _).symm ≪≫
tensorIso (Iso.refl _) (linearizationTrivialIso k G (Fin n → G))
@[simp]
theorem diagonalSuccIsoTensorTrivial_hom_hom_single (f : Fin (n + 1) → G) (a : k) :
DFunLike.coe (F := ((Fin (n + 1) → G) →₀ k) →ₗ[k]
↑(ModuleCat.of k (G →₀ k) ⊗ ModuleCat.of k ((Fin n → G) →₀ k)))
(diagonalSuccIsoTensorTrivial k G n).hom.hom.hom (single f a) =
single (f 0) 1 ⊗ₜ single (fun i => (f (Fin.castSucc i))⁻¹ * f i.succ) a := by
simp [diagonalSuccIsoTensorTrivial, whiskerLeft_def, tensorObj_def,
ModuleCat.MonoidalCategory.whiskerLeft, types_tensorObj_def,
ModuleCat.MonoidalCategory.tensorObj, finsuppTensorFinsupp'_symm_single_eq_single_one_tmul,
ModuleCat.hom_id (M := ((linearization k G).obj _).V), Action.ofMulAction_V]
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_single (g : G) (f : Fin n → G) (a b : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (single g a ⊗ₜ single f b) =
single (g • Fin.partialProd f) (a * b) := by
have := Action.diagonalSuccIsoTensorTrivial_inv_hom_apply (G := G) (n := n)
simp_all [diagonalSuccIsoTensorTrivial, ModuleCat.MonoidalCategory.tensorHom_def,
tensorObj_def, ModuleCat.MonoidalCategory.tensorObj, types_tensorObj_def,
ModuleCat.hom_id (M := ((linearization k G).obj _).V), Action.ofMulAction_V]
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_left (g : G) (f : (Fin n → G) →₀ k) (r : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (single g r ⊗ₜ f) =
Finsupp.lift ((Fin (n + 1) → G) →₀ k) k (Fin n → G)
(fun f => single (g • Fin.partialProd f) r) f := by
refine f.induction ?_ ?_
· simp only [TensorProduct.tmul_zero, map_zero]
· intro a b x _ _ hx
simpa [-Action.tensorObj_V, TensorProduct.tmul_add, map_add, mul_comm b, hx] using
diagonalSuccIsoTensorTrivial_inv_hom_single_single ..
theorem diagonalSuccIsoTensorTrivial_inv_hom_single_right (g : G →₀ k) (f : Fin n → G) (r : k) :
(diagonalSuccIsoTensorTrivial k G n).inv.hom (g ⊗ₜ single f r) =
Finsupp.lift _ k G (fun a => single (a • Fin.partialProd f) r) g := by
refine g.induction ?_ ?_
· simp only [TensorProduct.zero_tmul, map_zero]
· intro a b x _ _ hx
simpa [-Action.tensorObj_V, map_add, hx, TensorProduct.add_tmul] using
diagonalSuccIsoTensorTrivial_inv_hom_single_single ..
variable [DecidableEq (Fin n → G)]
variable (k G n) in
/-- Representation isomorphism `k[Gⁿ⁺¹] ≅ (Gⁿ →₀ k[G])`, where the righthand representation is
defined pointwise by the left regular representation on `k[G]`. The map sends
`single (g₀, ..., gₙ) a ↦ single (g₀⁻¹g₁, ..., gₙ₋₁⁻¹gₙ) (single g₀ a)`. -/
def diagonalSuccIsoFree : diagonal k G (n + 1) ≅ free k G (Fin n → G) :=
diagonalSuccIsoTensorTrivial k G n ≪≫ leftRegularTensorTrivialIsoFree k G (Fin n → G)
@[simp]
theorem diagonalSuccIsoFree_hom_hom_single (f : Fin (n + 1) → G) (a : k) :
(diagonalSuccIsoFree k G n).hom.hom (single f a) =
single (fun i => (f i.castSucc)⁻¹ * f i.succ) (single (f 0) a) := by
simp [diagonalSuccIsoFree, leftRegularTensorTrivialIsoFree_hom_hom_single_tmul_single
(k := k)]
@[simp]
theorem diagonalSuccIsoFree_inv_hom_single_single (g : G) (f : Fin n → G) (a : k) :
(diagonalSuccIsoFree k G n).inv.hom (single f (single g a)) =
single (g • Fin.partialProd f) a := by
have := diagonalSuccIsoTensorTrivial_inv_hom_single_single g f a 1
simp_all [diagonalSuccIsoFree, leftRegularTensorTrivialIsoFree_inv_hom_single_single (k := k)]
theorem diagonalSuccIsoFree_inv_hom_single (g : G →₀ k) (f : Fin n → G) :
(diagonalSuccIsoFree k G n).inv.hom (single f g) =
lift _ k G (fun a => single (a • Fin.partialProd f) 1) g :=
g.induction (by simp) fun _ _ _ _ _ _ => by
rw [single_add, map_add, diagonalSuccIsoFree_inv_hom_single_single]
simp_all [sum_add_index']
variable (n) (A : Rep k G)
/-- Given a `k`-linear `G`-representation `A`, the set of representation morphisms
`Hom(k[Gⁿ⁺¹], A)` is `k`-linearly isomorphic to the set of functions `Gⁿ → A`. -/
def diagonalHomEquiv :
(Rep.diagonal k G (n + 1) ⟶ A) ≃ₗ[k] (Fin n → G) → A :=
Linear.homCongr k (diagonalSuccIsoFree k G n) (Iso.refl _) ≪≫ₗ
freeLiftLEquiv (Fin n → G) A
variable {n A}
/-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of
the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that this
sends a morphism of representations `f : k[Gⁿ⁺¹] ⟶ A` to the function
`(g₁, ..., gₙ) ↦ f(1, g₁, g₁g₂, ..., g₁g₂...gₙ).` -/
theorem diagonalHomEquiv_apply (f : Rep.diagonal k G (n + 1) ⟶ A) (x : Fin n → G) :
diagonalHomEquiv n A f x = f.hom (Finsupp.single (Fin.partialProd x) 1) := by
simp [diagonalHomEquiv, Linear.homCongr_apply,
diagonalSuccIsoFree_inv_hom_single_single (k := k)]
/-- Given a `k`-linear `G`-representation `A`, `diagonalHomEquiv` is a `k`-linear isomorphism of
the set of representation morphisms `Hom(k[Gⁿ⁺¹], A)` with `Fun(Gⁿ, A)`. This lemma says that the
inverse map sends a function `f : Gⁿ → A` to the representation morphism sending
`(g₀, ... gₙ) ↦ ρ(g₀)(f(g₀⁻¹g₁, g₁⁻¹g₂, ..., gₙ₋₁⁻¹gₙ))`, where `ρ` is the representation attached
to `A`. -/
theorem diagonalHomEquiv_symm_apply (f : (Fin n → G) → A) (x : Fin (n + 1) → G) :
((diagonalHomEquiv n A).symm f).hom (Finsupp.single x 1) =
A.ρ (x 0) (f fun i : Fin n => (x (Fin.castSucc i))⁻¹ * x i.succ) := by
simp [diagonalHomEquiv, Linear.homCongr_symm_apply, diagonalSuccIsoFree_hom_hom_single (k := k)]
/-- Auxiliary lemma for defining group cohomology, used to show that the isomorphism
`diagonalHomEquiv` commutes with the differentials in two complexes which compute
group cohomology. -/
@[deprecated "We no longer use `diagonalHomEquiv` to define group cohomology"
(since := "2025-06-08")]
theorem diagonalHomEquiv_symm_partialProd_succ (f : (Fin n → G) → A) (g : Fin (n + 1) → G)
(a : Fin (n + 1)) :
((diagonalHomEquiv n A).symm f).hom (Finsupp.single (Fin.partialProd g ∘ a.succ.succAbove) 1)
= f (Fin.contractNth a (· * ·) g) := by
rw [diagonalHomEquiv_symm_apply]
simp only [Function.comp_apply, Fin.succ_succAbove_zero, Fin.partialProd_zero, map_one,
Fin.succ_succAbove_succ, Module.End.one_apply, Fin.partialProd_succ]
congr
ext
rw [← Fin.partialProd_succ, Fin.inv_partialProd_mul_eq_contractNth]
section
variable [Fintype G] (A : Rep k G)
/-- Given a representation `A` of a finite group `G`, `norm A` is the representation morphism
`A ⟶ A` defined by `x ↦ ∑ A.ρ g x` for `g` in `G`. -/
@[simps]
def norm : End A where
hom := ModuleCat.ofHom <| Representation.norm A.ρ
comm g := by ext; simp
@[reassoc, elementwise]
lemma norm_comm {A B : Rep k G} (f : A ⟶ B) : f ≫ norm B = norm A ≫ f := by
ext
simp [Representation.norm, hom_comm_apply]
/-- Given a representation `A` of a finite group `G`, the norm map `A ⟶ A` defined by
`x ↦ ∑ A.ρ g x` for `g` in `G` defines a natural endomorphism of the identity functor. -/
@[simps]
def normNatTrans : End (𝟭 (Rep k G)) where
app := norm
naturality _ _ := norm_comm
end
section MonoidalClosed
open MonoidalCategory Action
variable (A B C : Rep k G)
/-- Given a `k`-linear `G`-representation `(A, ρ₁)`, this is the 'internal Hom' functor sending
`(B, ρ₂)` to the representation `Homₖ(A, B)` that maps `g : G` and `f : A →ₗ[k] B` to
`(ρ₂ g) ∘ₗ f ∘ₗ (ρ₁ g⁻¹)`. -/
@[simps]
protected noncomputable def ihom (A : Rep k G) : Rep k G ⥤ Rep k G where
obj B := Rep.of (Representation.linHom A.ρ B.ρ)
map := fun {X} {Y} f =>
{ hom := ModuleCat.ofHom (LinearMap.llcomp k _ _ _ f.hom.hom)
comm g := by ext; simp [ModuleCat.endRingEquiv, hom_comm_apply] }
map_id := fun _ => by ext; rfl
map_comp := fun _ _ => by ext; rfl
@[simp] theorem ihom_obj_ρ_apply {A B : Rep k G} (g : G) (x : A →ₗ[k] B) :
-- Hint to put this lemma into `simp`-normal form.
DFunLike.coe (F := (Representation k G (↑A.V →ₗ[k] ↑B.V)))
((Rep.ihom A).obj B).ρ g x = B.ρ g ∘ₗ x ∘ₗ A.ρ g⁻¹ :=
rfl
/-- Given a `k`-linear `G`-representation `A`, this is the Hom-set bijection in the adjunction
`A ⊗ - ⊣ ihom(A, -)`. It sends `f : A ⊗ B ⟶ C` to a `Rep k G` morphism defined by currying the
`k`-linear map underlying `f`, giving a map `A →ₗ[k] B →ₗ[k] C`, then flipping the arguments. -/
def homEquiv (A B C : Rep k G) : (A ⊗ B ⟶ C) ≃ (B ⟶ (Rep.ihom A).obj C) where
toFun f :=
{ hom := ModuleCat.ofHom <| (TensorProduct.curry f.hom.hom).flip
comm g := ModuleCat.hom_ext <| LinearMap.ext fun x => LinearMap.ext fun y => by
simpa [ModuleCat.MonoidalCategory.tensorObj_def,
ModuleCat.MonoidalCategory.tensorObj, ModuleCat.endRingEquiv] using
hom_comm_apply f g (A.ρ g⁻¹ y ⊗ₜ[k] x) }
invFun f :=
{ hom := ModuleCat.ofHom <| TensorProduct.uncurry k _ _ _ f.hom.hom.flip
comm g := ModuleCat.hom_ext <| TensorProduct.ext' fun x y => by
simpa using LinearMap.ext_iff.1 (hom_comm_apply f g y) (A.ρ g x) }
left_inv _ := Action.Hom.ext (ModuleCat.hom_ext <| TensorProduct.ext' fun _ _ => rfl)
variable {A B C}
/-- Porting note: if we generate this with `@[simps]` the linter complains some types in the LHS
simplify. -/
theorem homEquiv_apply_hom (f : A ⊗ B ⟶ C) :
(homEquiv A B C f).hom = ModuleCat.ofHom (TensorProduct.curry f.hom.hom).flip := rfl
/-- Porting note: if we generate this with `@[simps]` the linter complains some types in the LHS
simplify. -/
theorem homEquiv_symm_apply_hom (f : B ⟶ (Rep.ihom A).obj C) :
((homEquiv A B C).symm f).hom =
ModuleCat.ofHom (TensorProduct.uncurry k A B C f.hom.hom.flip) := rfl
instance : MonoidalClosed (Rep k G) where
closed A :=
{ rightAdj := Rep.ihom A
adj := Adjunction.mkOfHomEquiv (
{ homEquiv := Rep.homEquiv A
homEquiv_naturality_left_symm := fun _ _ => Action.Hom.ext
(ModuleCat.hom_ext (TensorProduct.ext' fun _ _ => rfl))
homEquiv_naturality_right := fun _ _ => Action.Hom.ext (ModuleCat.hom_ext (LinearMap.ext
fun _ => LinearMap.ext fun _ => rfl)) })}
@[simp]
theorem ihom_obj_ρ_def (A B : Rep k G) : ((ihom A).obj B).ρ = ((Rep.ihom A).obj B).ρ :=
rfl
@[simp]
theorem homEquiv_def (A B C : Rep k G) : (ihom.adjunction A).homEquiv B C = Rep.homEquiv A B C :=
congrFun (congrFun (Adjunction.mkOfHomEquiv_homEquiv _) _) _
@[simp]
theorem ihom_ev_app_hom (A B : Rep k G) :
Action.Hom.hom ((ihom.ev A).app B) = ModuleCat.ofHom
(TensorProduct.uncurry k A (A →ₗ[k] B) B LinearMap.id.flip) := by
ext; rfl
@[simp] theorem ihom_coev_app_hom (A B : Rep k G) :
Action.Hom.hom ((ihom.coev A).app B) = ModuleCat.ofHom (TensorProduct.mk k _ _).flip :=
ModuleCat.hom_ext <| LinearMap.ext fun _ => LinearMap.ext fun _ => rfl
variable (A B C)
/-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)`
and `Hom(B, Homₖ(A, C))`. -/
def MonoidalClosed.linearHomEquiv : (A ⊗ B ⟶ C) ≃ₗ[k] B ⟶ A ⟶[Rep k G] C :=
{ (ihom.adjunction A).homEquiv _ _ with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl }
/-- There is a `k`-linear isomorphism between the sets of representation morphisms`Hom(A ⊗ B, C)`
and `Hom(A, Homₖ(B, C))`. -/
def MonoidalClosed.linearHomEquivComm : (A ⊗ B ⟶ C) ≃ₗ[k] A ⟶ B ⟶[Rep k G] C :=
Linear.homCongr k (β_ A B) (Iso.refl _) ≪≫ₗ MonoidalClosed.linearHomEquiv _ _ _
variable {A B C}
@[simp]
theorem MonoidalClosed.linearHomEquiv_hom (f : A ⊗ B ⟶ C) :
(MonoidalClosed.linearHomEquiv A B C f).hom =
ModuleCat.ofHom (TensorProduct.curry f.hom.hom).flip :=
rfl
@[simp]
theorem MonoidalClosed.linearHomEquivComm_hom (f : A ⊗ B ⟶ C) :
(MonoidalClosed.linearHomEquivComm A B C f).hom =
ModuleCat.ofHom (TensorProduct.curry f.hom.hom) :=
rfl
theorem MonoidalClosed.linearHomEquiv_symm_hom (f : B ⟶ A ⟶[Rep k G] C) :
((MonoidalClosed.linearHomEquiv A B C).symm f).hom =
ModuleCat.ofHom (TensorProduct.uncurry k A B C f.hom.hom.flip) := by
simp [linearHomEquiv]
rfl
theorem MonoidalClosed.linearHomEquivComm_symm_hom (f : A ⟶ B ⟶[Rep k G] C) :
((MonoidalClosed.linearHomEquivComm A B C).symm f).hom =
ModuleCat.ofHom (TensorProduct.uncurry k A B C f.hom.hom) :=
ModuleCat.hom_ext <| TensorProduct.ext' fun _ _ => rfl
end MonoidalClosed
end Group
end Rep
namespace Representation
open MonoidalCategory
variable {k G : Type u} [CommRing k] [Monoid G] {V W : Type u} [AddCommGroup V] [AddCommGroup W]
[Module k V] [Module k W] (ρ : Representation k G V) (τ : Representation k G W)
/-- Tautological isomorphism to help Lean in typechecking. -/
def repOfTprodIso : Rep.of (ρ.tprod τ) ≅ Rep.of ρ ⊗ Rep.of τ :=
Iso.refl _
theorem repOfTprodIso_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).hom.hom x = x :=
rfl
theorem repOfTprodIso_inv_apply (x : TensorProduct k V W) : (repOfTprodIso ρ τ).inv.hom x = x :=
rfl
end Representation
/-!
# The categorical equivalence `Rep k G ≌ Module.{u} (MonoidAlgebra k G)`.
-/
namespace Rep
variable {k G : Type u} [CommRing k] [Monoid G]
-- Verify that the symmetric monoidal structure is available.
example : SymmetricCategory (Rep k G) := by infer_instance
example : MonoidalPreadditive (Rep k G) := by infer_instance
example : MonoidalLinear k (Rep k G) := by infer_instance
/-- Auxiliary lemma for `toModuleMonoidAlgebra`. -/
theorem to_Module_monoidAlgebra_map_aux {k G : Type*} [CommRing k] [Monoid G] (V W : Type*)
[AddCommGroup V] [AddCommGroup W] [Module k V] [Module k W] (ρ : G →* V →ₗ[k] V)
(σ : G →* W →ₗ[k] W) (f : V →ₗ[k] W) (w : ∀ g : G, f.comp (ρ g) = (σ g).comp f)
(r : MonoidAlgebra k G) (x : V) :
f ((((MonoidAlgebra.lift k G (V →ₗ[k] V)) ρ) r) x) =
(((MonoidAlgebra.lift k G (W →ₗ[k] W)) σ) r) (f x) := by
apply MonoidAlgebra.induction_on r
· intro g
simp only [one_smul, MonoidAlgebra.lift_single, MonoidAlgebra.of_apply]
exact LinearMap.congr_fun (w g) x
· intro g h gw hw; simp only [map_add, LinearMap.add_apply, hw, gw]
· intro r g w
simp only [map_smul, w, LinearMap.smul_apply]
/-- Auxiliary definition for `toModuleMonoidAlgebra`. -/
def toModuleMonoidAlgebraMap {V W : Rep k G} (f : V ⟶ W) :
ModuleCat.of (MonoidAlgebra k G) V.ρ.asModule ⟶ ModuleCat.of (MonoidAlgebra k G) W.ρ.asModule :=
ModuleCat.ofHom
{ f.hom.hom with
map_smul' := fun r x => to_Module_monoidAlgebra_map_aux V.V W.V V.ρ W.ρ f.hom.hom
(fun g => ModuleCat.hom_ext_iff.mp (f.comm g)) r x }
/-- Functorially convert a representation of `G` into a module over `MonoidAlgebra k G`. -/
def toModuleMonoidAlgebra : Rep k G ⥤ ModuleCat.{u} (MonoidAlgebra k G) where
obj V := ModuleCat.of _ V.ρ.asModule
map f := toModuleMonoidAlgebraMap f
/-- Functorially convert a module over `MonoidAlgebra k G` into a representation of `G`. -/
def ofModuleMonoidAlgebra : ModuleCat.{u} (MonoidAlgebra k G) ⥤ Rep k G where
obj M := Rep.of (Representation.ofModule M)
map f :=
{ hom := ModuleCat.ofHom
{ f.hom with
map_smul' := fun r x => f.hom.map_smul (algebraMap k _ r) x }
comm := fun g => by ext; apply f.hom.map_smul }
theorem ofModuleMonoidAlgebra_obj_coe (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra.obj M : Type u) = RestrictScalars k (MonoidAlgebra k G) M :=
rfl
theorem ofModuleMonoidAlgebra_obj_ρ (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra.obj M).ρ = Representation.ofModule M :=
rfl
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def counitIsoAddEquiv {M : ModuleCat.{u} (MonoidAlgebra k G)} :
(ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≃+ M := by
dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
exact (Representation.ofModule M).asModuleEquiv.toAddEquiv.trans
(RestrictScalars.addEquiv k (MonoidAlgebra k G) _)
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def unitIsoAddEquiv {V : Rep k G} : V ≃+ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V := by
dsimp [ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
exact V.ρ.asModuleEquiv.symm.toAddEquiv.trans (RestrictScalars.addEquiv _ _ _).symm
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def counitIso (M : ModuleCat.{u} (MonoidAlgebra k G)) :
(ofModuleMonoidAlgebra ⋙ toModuleMonoidAlgebra).obj M ≅ M :=
LinearEquiv.toModuleIso
{ counitIsoAddEquiv with
map_smul' := fun r x => by
dsimp [counitIsoAddEquiv]
simp }
theorem unit_iso_comm (V : Rep k G) (g : G) (x : V) :
unitIsoAddEquiv ((V.ρ g).toFun x) = ((ofModuleMonoidAlgebra.obj
(toModuleMonoidAlgebra.obj V)).ρ g).toFun (unitIsoAddEquiv x) := by
simp [unitIsoAddEquiv, ofModuleMonoidAlgebra, toModuleMonoidAlgebra]
/-- Auxiliary definition for `equivalenceModuleMonoidAlgebra`. -/
def unitIso (V : Rep k G) : V ≅ (toModuleMonoidAlgebra ⋙ ofModuleMonoidAlgebra).obj V :=
Action.mkIso
(LinearEquiv.toModuleIso
{ unitIsoAddEquiv with
map_smul' := fun r x => by
change (RestrictScalars.addEquiv _ _ _).symm (V.ρ.asModuleEquiv.symm (r • x)) = _
simp only [Representation.asModuleEquiv_symm_map_smul]
rfl })
fun g => by ext; apply unit_iso_comm
/-- The categorical equivalence `Rep k G ≌ ModuleCat (MonoidAlgebra k G)`. -/
def equivalenceModuleMonoidAlgebra : Rep k G ≌ ModuleCat.{u} (MonoidAlgebra k G) where
functor := toModuleMonoidAlgebra
inverse := ofModuleMonoidAlgebra
unitIso := NatIso.ofComponents (fun V => unitIso V) (by cat_disch)
counitIso := NatIso.ofComponents (fun M => counitIso M) (by cat_disch)
-- TODO Verify that the equivalence with `ModuleCat (MonoidAlgebra k G)` is a monoidal functor.
instance : EnoughProjectives (Rep k G) :=
equivalenceModuleMonoidAlgebra.enoughProjectives_iff.2 ModuleCat.enoughProjectives.{u}
instance free_projective {G α : Type u} [Group G] :
Projective (free k G α) :=
equivalenceModuleMonoidAlgebra.toAdjunction.projective_of_map_projective _ <|
@ModuleCat.projective_of_free.{u} _ _
(ModuleCat.of (MonoidAlgebra k G) (Representation.free k G α).asModule)
_ (Representation.freeAsModuleBasis k G α)
section
variable {G : Type u} [Group G] {n : ℕ} [DecidableEq (Fin n → G)]
instance diagonal_succ_projective :
Projective (diagonal k G (n + 1)) :=
Projective.of_iso (diagonalSuccIsoFree k G n).symm inferInstance
instance leftRegular_projective :
Projective (leftRegular k G) :=
Projective.of_iso (diagonalOneIsoLeftRegular k G) inferInstance
instance trivial_projective_of_subsingleton [Subsingleton G] :
Projective (trivial k G k) :=
Projective.of_iso (ofMulActionSubsingletonIsoTrivial _ _ (Fin 1 → G)) diagonal_succ_projective
end
end Rep
|
Pointwise.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, Eric Wieser
-/
import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Module.Pointwise
import Mathlib.Data.Real.Archimedean
/-!
# Pointwise operations on sets of reals
This file relates `sInf (a • s)`/`sSup (a • s)` with `a • sInf s`/`a • sSup s` for `s : Set ℝ`.
From these, it relates `⨅ i, a • f i` / `⨆ i, a • f i` with `a • (⨅ i, f i)` / `a • (⨆ i, f i)`,
and provides lemmas about distributing `*` over `⨅` and `⨆`.
## TODO
This is true more generally for conditionally complete linear order whose default value is `0`. We
don't have those yet.
-/
assert_not_exists Finset
open Set
open Pointwise
variable {ι : Sort*} {α : Type*} [Field α] [LinearOrder α] [IsStrictOrderedRing α]
section MulActionWithZero
variable [MulActionWithZero α ℝ] [OrderedSMul α ℝ] {a : α}
theorem Real.sInf_smul_of_nonneg (ha : 0 ≤ a) (s : Set ℝ) : sInf (a • s) = a • sInf s := by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [smul_set_empty, Real.sInf_empty, smul_zero]
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul_set hs, zero_smul]
exact csInf_singleton 0
by_cases h : BddBelow s
· exact ((OrderIso.smulRight ha').map_csInf' hs h).symm
· rw [Real.sInf_of_not_bddBelow (mt (bddBelow_smul_iff_of_pos ha').1 h),
Real.sInf_of_not_bddBelow h, smul_zero]
theorem Real.smul_iInf_of_nonneg (ha : 0 ≤ a) (f : ι → ℝ) : (a • ⨅ i, f i) = ⨅ i, a • f i :=
(Real.sInf_smul_of_nonneg ha _).symm.trans <| congr_arg sInf <| (range_comp _ _).symm
theorem Real.sSup_smul_of_nonneg (ha : 0 ≤ a) (s : Set ℝ) : sSup (a • s) = a • sSup s := by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [smul_set_empty, Real.sSup_empty, smul_zero]
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul_set hs, zero_smul]
exact csSup_singleton 0
by_cases h : BddAbove s
· exact ((OrderIso.smulRight ha').map_csSup' hs h).symm
· rw [Real.sSup_of_not_bddAbove (mt (bddAbove_smul_iff_of_pos ha').1 h),
Real.sSup_of_not_bddAbove h, smul_zero]
theorem Real.smul_iSup_of_nonneg (ha : 0 ≤ a) (f : ι → ℝ) : (a • ⨆ i, f i) = ⨆ i, a • f i :=
(Real.sSup_smul_of_nonneg ha _).symm.trans <| congr_arg sSup <| (range_comp _ _).symm
end MulActionWithZero
section Module
variable [Module α ℝ] [OrderedSMul α ℝ] {a : α}
theorem Real.sInf_smul_of_nonpos (ha : a ≤ 0) (s : Set ℝ) : sInf (a • s) = a • sSup s := by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [smul_set_empty, Real.sInf_empty, Real.sSup_empty, smul_zero]
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul_set hs, zero_smul]
exact csInf_singleton 0
by_cases h : BddAbove s
· exact ((OrderIso.smulRightDual ℝ ha').map_csSup' hs h).symm
· rw [Real.sInf_of_not_bddBelow (mt (bddBelow_smul_iff_of_neg ha').1 h),
Real.sSup_of_not_bddAbove h, smul_zero]
theorem Real.smul_iSup_of_nonpos (ha : a ≤ 0) (f : ι → ℝ) : (a • ⨆ i, f i) = ⨅ i, a • f i :=
(Real.sInf_smul_of_nonpos ha _).symm.trans <| congr_arg sInf <| (range_comp _ _).symm
theorem Real.sSup_smul_of_nonpos (ha : a ≤ 0) (s : Set ℝ) : sSup (a • s) = a • sInf s := by
obtain rfl | hs := s.eq_empty_or_nonempty
· rw [smul_set_empty, Real.sSup_empty, Real.sInf_empty, smul_zero]
obtain rfl | ha' := ha.eq_or_lt
· rw [zero_smul_set hs, zero_smul]
exact csSup_singleton 0
by_cases h : BddBelow s
· exact ((OrderIso.smulRightDual ℝ ha').map_csInf' hs h).symm
· rw [Real.sSup_of_not_bddAbove (mt (bddAbove_smul_iff_of_neg ha').1 h),
Real.sInf_of_not_bddBelow h, smul_zero]
theorem Real.smul_iInf_of_nonpos (ha : a ≤ 0) (f : ι → ℝ) : (a • ⨅ i, f i) = ⨆ i, a • f i :=
(Real.sSup_smul_of_nonpos ha _).symm.trans <| congr_arg sSup <| (range_comp _ _).symm
end Module
/-! ## Special cases for real multiplication -/
section Mul
variable {r : ℝ}
theorem Real.mul_iInf_of_nonneg (ha : 0 ≤ r) (f : ι → ℝ) : (r * ⨅ i, f i) = ⨅ i, r * f i :=
Real.smul_iInf_of_nonneg ha f
theorem Real.mul_iSup_of_nonneg (ha : 0 ≤ r) (f : ι → ℝ) : (r * ⨆ i, f i) = ⨆ i, r * f i :=
Real.smul_iSup_of_nonneg ha f
theorem Real.mul_iInf_of_nonpos (ha : r ≤ 0) (f : ι → ℝ) : (r * ⨅ i, f i) = ⨆ i, r * f i :=
Real.smul_iInf_of_nonpos ha f
theorem Real.mul_iSup_of_nonpos (ha : r ≤ 0) (f : ι → ℝ) : (r * ⨆ i, f i) = ⨅ i, r * f i :=
Real.smul_iSup_of_nonpos ha f
theorem Real.iInf_mul_of_nonneg (ha : 0 ≤ r) (f : ι → ℝ) : (⨅ i, f i) * r = ⨅ i, f i * r := by
simp only [Real.mul_iInf_of_nonneg ha, mul_comm]
theorem Real.iSup_mul_of_nonneg (ha : 0 ≤ r) (f : ι → ℝ) : (⨆ i, f i) * r = ⨆ i, f i * r := by
simp only [Real.mul_iSup_of_nonneg ha, mul_comm]
theorem Real.iInf_mul_of_nonpos (ha : r ≤ 0) (f : ι → ℝ) : (⨅ i, f i) * r = ⨆ i, f i * r := by
simp only [Real.mul_iInf_of_nonpos ha, mul_comm]
theorem Real.iSup_mul_of_nonpos (ha : r ≤ 0) (f : ι → ℝ) : (⨆ i, f i) * r = ⨅ i, f i * r := by
simp only [Real.mul_iSup_of_nonpos ha, mul_comm]
end Mul
|
LogLikelihoodRatio.lean
|
/-
Copyright (c) 2023 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import Mathlib.MeasureTheory.Measure.Tilted
/-!
# Log-likelihood Ratio
The likelihood ratio between two measures `μ` and `ν` is their Radon-Nikodym derivative
`μ.rnDeriv ν`. The logarithm of that function is often used instead: this is the log-likelihood
ratio.
This file contains a definition of the log-likelihood ratio (llr) and its properties.
## Main definitions
* `llr μ ν`: Log-Likelihood Ratio between `μ` and `ν`, defined as the function
`x ↦ log (μ.rnDeriv ν x).toReal`.
-/
open Real
open scoped ENNReal NNReal Topology
namespace MeasureTheory
variable {α : Type*} {mα : MeasurableSpace α} {μ ν : Measure α} {f : α → ℝ}
/-- Log-Likelihood Ratio between two measures. -/
noncomputable def llr (μ ν : Measure α) (x : α) : ℝ := log (μ.rnDeriv ν x).toReal
lemma llr_def (μ ν : Measure α) : llr μ ν = fun x ↦ log (μ.rnDeriv ν x).toReal := rfl
lemma llr_self (μ : Measure α) [SigmaFinite μ] : llr μ μ =ᵐ[μ] 0 := by
filter_upwards [μ.rnDeriv_self] with a ha using by simp [llr, ha]
lemma exp_llr (μ ν : Measure α) [SigmaFinite μ] :
(fun x ↦ exp (llr μ ν x))
=ᵐ[ν] fun x ↦ if μ.rnDeriv ν x = 0 then 1 else (μ.rnDeriv ν x).toReal := by
filter_upwards [Measure.rnDeriv_lt_top μ ν] with x hx
by_cases h_zero : μ.rnDeriv ν x = 0
· simp only [llr, h_zero, ENNReal.toReal_zero, log_zero, exp_zero, ite_true]
· rw [llr, exp_log, if_neg h_zero]
exact ENNReal.toReal_pos h_zero hx.ne
lemma exp_llr_of_ac (μ ν : Measure α) [SigmaFinite μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) :
(fun x ↦ exp (llr μ ν x)) =ᵐ[μ] fun x ↦ (μ.rnDeriv ν x).toReal := by
filter_upwards [hμν.ae_le (exp_llr μ ν), Measure.rnDeriv_pos hμν] with x hx_eq hx_pos
rw [hx_eq, if_neg hx_pos.ne']
lemma exp_llr_of_ac' (μ ν : Measure α) [SigmaFinite μ] [SigmaFinite ν] (hμν : ν ≪ μ) :
(fun x ↦ exp (llr μ ν x)) =ᵐ[ν] fun x ↦ (μ.rnDeriv ν x).toReal := by
filter_upwards [exp_llr μ ν, Measure.rnDeriv_pos' hμν] with x hx hx_pos
rwa [if_neg hx_pos.ne'] at hx
lemma neg_llr [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν) :
- llr μ ν =ᵐ[μ] llr ν μ := by
filter_upwards [Measure.inv_rnDeriv hμν] with x hx
rw [Pi.neg_apply, llr, llr, ← log_inv, ← ENNReal.toReal_inv]
congr
lemma exp_neg_llr [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν) :
(fun x ↦ exp (- llr μ ν x)) =ᵐ[μ] fun x ↦ (ν.rnDeriv μ x).toReal := by
filter_upwards [neg_llr hμν, exp_llr_of_ac' ν μ hμν] with x hx hx_exp_log
rw [Pi.neg_apply] at hx
rw [hx, hx_exp_log]
lemma exp_neg_llr' [SigmaFinite μ] [SigmaFinite ν] (hμν : ν ≪ μ) :
(fun x ↦ exp (- llr μ ν x)) =ᵐ[ν] fun x ↦ (ν.rnDeriv μ x).toReal := by
filter_upwards [neg_llr hμν, exp_llr_of_ac ν μ hμν] with x hx hx_exp_log
rw [Pi.neg_apply, neg_eq_iff_eq_neg] at hx
rw [← hx, hx_exp_log]
@[measurability, fun_prop]
lemma measurable_llr (μ ν : Measure α) : Measurable (llr μ ν) :=
(Measure.measurable_rnDeriv μ ν).ennreal_toReal.log
@[measurability]
lemma stronglyMeasurable_llr (μ ν : Measure α) : StronglyMeasurable (llr μ ν) :=
(measurable_llr μ ν).stronglyMeasurable
lemma llr_smul_left [IsFiniteMeasure μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) (c : ℝ≥0∞) (hc : c ≠ 0) (hc_ne_top : c ≠ ∞) :
llr (c • μ) ν =ᵐ[μ] fun x ↦ llr μ ν x + log c.toReal := by
simp only [llr, llr_def]
have h := Measure.rnDeriv_smul_left_of_ne_top μ ν hc_ne_top
filter_upwards [hμν.ae_le h, Measure.rnDeriv_pos hμν, hμν.ae_le (Measure.rnDeriv_lt_top μ ν)]
with x hx_eq hx_pos hx_ne_top
rw [hx_eq]
simp only [Pi.smul_apply, smul_eq_mul, ENNReal.toReal_mul]
rw [log_mul]
rotate_left
· rw [ENNReal.toReal_ne_zero]
simp [hc, hc_ne_top]
· rw [ENNReal.toReal_ne_zero]
simp [hx_pos.ne', hx_ne_top.ne]
ring
lemma llr_smul_right [IsFiniteMeasure μ] [Measure.HaveLebesgueDecomposition μ ν]
(hμν : μ ≪ ν) (c : ℝ≥0∞) (hc : c ≠ 0) (hc_ne_top : c ≠ ∞) :
llr μ (c • ν) =ᵐ[μ] fun x ↦ llr μ ν x - log c.toReal := by
simp only [llr, llr_def]
have h := Measure.rnDeriv_smul_right_of_ne_top μ ν hc hc_ne_top
filter_upwards [hμν.ae_le h, Measure.rnDeriv_pos hμν, hμν.ae_le (Measure.rnDeriv_lt_top μ ν)]
with x hx_eq hx_pos hx_ne_top
rw [hx_eq]
simp only [Pi.smul_apply, smul_eq_mul, ENNReal.toReal_mul]
rw [log_mul]
rotate_left
· rw [ENNReal.toReal_ne_zero]
simp [hc, hc_ne_top]
· rw [ENNReal.toReal_ne_zero]
simp [hx_pos.ne', hx_ne_top.ne]
rw [ENNReal.toReal_inv, log_inv]
ring
lemma integrable_rnDeriv_mul_log_iff [SigmaFinite μ] [μ.HaveLebesgueDecomposition ν] (hμν : μ ≪ ν) :
Integrable (fun a ↦ (μ.rnDeriv ν a).toReal * log (μ.rnDeriv ν a).toReal) ν
↔ Integrable (llr μ ν) μ :=
integrable_rnDeriv_smul_iff hμν
lemma integral_rnDeriv_mul_log [SigmaFinite μ] [μ.HaveLebesgueDecomposition ν] (hμν : μ ≪ ν) :
∫ a, (μ.rnDeriv ν a).toReal * log (μ.rnDeriv ν a).toReal ∂ν = ∫ a, llr μ ν a ∂μ := by
simp_rw [← smul_eq_mul, integral_rnDeriv_smul hμν, llr]
section llr_tilted
lemma llr_tilted_left [SigmaFinite μ] [SigmaFinite ν] (hμν : μ ≪ ν)
(hf : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
(llr (μ.tilted f) ν) =ᵐ[μ] fun x ↦ f x - log (∫ z, exp (f z) ∂μ) + llr μ ν x := by
cases eq_zero_or_neZero μ with
| inl hμ =>
simp only [hμ, ae_zero, Filter.EventuallyEq, Filter.eventually_bot]
| inr h0 =>
filter_upwards [hμν.ae_le (toReal_rnDeriv_tilted_left μ hfν), Measure.rnDeriv_pos hμν,
hμν.ae_le (Measure.rnDeriv_lt_top μ ν)] with x hx hx_pos hx_lt_top
rw [llr, hx, log_mul, div_eq_mul_inv, log_mul (exp_pos _).ne', log_exp, log_inv, llr,
← sub_eq_add_neg]
· simp only [ne_eq, inv_eq_zero]
exact (integral_exp_pos hf).ne'
· simp only [ne_eq, div_eq_zero_iff]
push_neg
exact ⟨(exp_pos _).ne', (integral_exp_pos hf).ne'⟩
· simp [ENNReal.toReal_eq_zero_iff, hx_lt_top.ne, hx_pos.ne']
lemma integrable_llr_tilted_left [IsFiniteMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable f μ) (h_int : Integrable (llr μ ν) μ)
(hfμ : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
Integrable (llr (μ.tilted f) ν) μ := by
rw [integrable_congr (llr_tilted_left hμν hfμ hfν)]
exact Integrable.add (hf.sub (integrable_const _)) h_int
lemma integral_llr_tilted_left [IsProbabilityMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable f μ) (h_int : Integrable (llr μ ν) μ)
(hfμ : Integrable (fun x ↦ exp (f x)) μ) (hfν : AEMeasurable f ν) :
∫ x, llr (μ.tilted f) ν x ∂μ = ∫ x, llr μ ν x ∂μ + ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) := by
calc ∫ x, llr (μ.tilted f) ν x ∂μ
= ∫ x, f x - log (∫ x, exp (f x) ∂μ) + llr μ ν x ∂μ :=
integral_congr_ae (llr_tilted_left hμν hfμ hfν)
_ = ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) + ∫ x, llr μ ν x ∂μ := by
rw [integral_add ?_ h_int]
swap; · exact hf.sub (integrable_const _)
rw [integral_sub hf (integrable_const _)]
simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, one_mul]
_ = ∫ x, llr μ ν x ∂μ + ∫ x, f x ∂μ - log (∫ x, exp (f x) ∂μ) := by abel
lemma llr_tilted_right [SigmaFinite μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hf : Integrable (fun x ↦ exp (f x)) ν) :
(llr μ (ν.tilted f)) =ᵐ[μ] fun x ↦ - f x + log (∫ z, exp (f z) ∂ν) + llr μ ν x := by
cases eq_zero_or_neZero ν with
| inl h =>
have hμ : μ = 0 := by ext s _; exact hμν (by simp [h])
simp only [hμ, ae_zero, Filter.EventuallyEq, Filter.eventually_bot]
| inr h0 =>
filter_upwards [hμν.ae_le (toReal_rnDeriv_tilted_right μ ν hf), Measure.rnDeriv_pos hμν,
hμν.ae_le (Measure.rnDeriv_lt_top μ ν)] with x hx hx_pos hx_lt_top
rw [llr, hx, log_mul, log_mul (exp_pos _).ne', log_exp, llr]
· exact (integral_exp_pos hf).ne'
· refine (mul_pos (exp_pos _) (integral_exp_pos hf)).ne'
· simp [ENNReal.toReal_eq_zero_iff, hx_lt_top.ne, hx_pos.ne']
lemma integrable_llr_tilted_right [IsFiniteMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hfμ : Integrable f μ)
(h_int : Integrable (llr μ ν) μ) (hfν : Integrable (fun x ↦ exp (f x)) ν) :
Integrable (llr μ (ν.tilted f)) μ := by
rw [integrable_congr (llr_tilted_right hμν hfν)]
exact Integrable.add (hfμ.neg.add (integrable_const _)) h_int
lemma integral_llr_tilted_right [IsProbabilityMeasure μ] [SigmaFinite ν]
(hμν : μ ≪ ν) (hfμ : Integrable f μ) (hfν : Integrable (fun x ↦ exp (f x)) ν)
(h_int : Integrable (llr μ ν) μ) :
∫ x, llr μ (ν.tilted f) x ∂μ = ∫ x, llr μ ν x ∂μ - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) := by
calc ∫ x, llr μ (ν.tilted f) x ∂μ
= ∫ x, - f x + log (∫ x, exp (f x) ∂ν) + llr μ ν x ∂μ :=
integral_congr_ae (llr_tilted_right hμν hfν)
_ = - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) + ∫ x, llr μ ν x ∂μ := by
rw [← integral_neg, integral_add ?_ h_int]
swap; · exact hfμ.neg.add (integrable_const _)
rw [integral_add ?_ (integrable_const _)]
swap; · exact hfμ.neg
simp only [integral_const, measureReal_univ_eq_one, smul_eq_mul, one_mul]
_ = ∫ x, llr μ ν x ∂μ - ∫ x, f x ∂μ + log (∫ x, exp (f x) ∂ν) := by abel
end llr_tilted
end MeasureTheory
|
Pointwise.lean
|
/-
Copyright (c) 2022 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Hanting Zhang
-/
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic
/-! # Pointwise instances on `AffineSubspace`s
This file provides the additive action `AffineSubspace.pointwiseAddAction` in the
`Pointwise` locale.
-/
open Affine Pointwise
open Set
variable {M k V P V₁ P₁ V₂ P₂ : Type*}
namespace AffineSubspace
section Ring
variable [Ring k]
variable [AddCommGroup V] [Module k V] [AffineSpace V P]
variable [AddCommGroup V₁] [Module k V₁] [AddTorsor V₁ P₁]
variable [AddCommGroup V₂] [Module k V₂] [AddTorsor V₂ P₂]
/-- The additive action on an affine subspace corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseVAdd : VAdd V (AffineSubspace k P) where
vadd x s := s.map (AffineEquiv.constVAdd k P x)
scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseVAdd
@[simp, norm_cast] lemma coe_pointwise_vadd (v : V) (s : AffineSubspace k P) :
((v +ᵥ s : AffineSubspace k P) : Set P) = v +ᵥ (s : Set P) := rfl
/-- The additive action on an affine subspace corresponding to applying the action to every element.
This is available as an instance in the `Pointwise` locale. -/
protected def pointwiseAddAction : AddAction V (AffineSubspace k P) :=
SetLike.coe_injective.addAction _ coe_pointwise_vadd
scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseAddAction
theorem pointwise_vadd_eq_map (v : V) (s : AffineSubspace k P) :
v +ᵥ s = s.map (AffineEquiv.constVAdd k P v) :=
rfl
theorem vadd_mem_pointwise_vadd_iff {v : V} {s : AffineSubspace k P} {p : P} :
v +ᵥ p ∈ v +ᵥ s ↔ p ∈ s :=
vadd_mem_vadd_set_iff
@[simp] theorem pointwise_vadd_bot (v : V) : v +ᵥ (⊥ : AffineSubspace k P) = ⊥ := by
ext; simp [pointwise_vadd_eq_map, map_bot]
@[simp] lemma pointwise_vadd_top (v : V) : v +ᵥ (⊤ : AffineSubspace k P) = ⊤ := by
ext; simp [pointwise_vadd_eq_map, vadd_eq_iff_eq_neg_vadd]
theorem pointwise_vadd_direction (v : V) (s : AffineSubspace k P) :
(v +ᵥ s).direction = s.direction := by
rw [pointwise_vadd_eq_map, map_direction]
exact Submodule.map_id _
theorem pointwise_vadd_span (v : V) (s : Set P) : v +ᵥ affineSpan k s = affineSpan k (v +ᵥ s) :=
map_span _ s
theorem map_pointwise_vadd (f : P₁ →ᵃ[k] P₂) (v : V₁) (s : AffineSubspace k P₁) :
(v +ᵥ s).map f = f.linear v +ᵥ s.map f := by
rw [pointwise_vadd_eq_map, pointwise_vadd_eq_map, map_map, map_map]
congr 1
ext
exact f.map_vadd _ _
section SMul
variable [Monoid M] [DistribMulAction M V] [SMulCommClass M k V] {a : M} {s : AffineSubspace k V}
{p : V}
/-- The multiplicative action on an affine subspace corresponding to applying the action to every
element.
This is available as an instance in the `Pointwise` locale.
TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineSubspace k P)`, which acts on `P` with a
`VAdd` version of a `DistribMulAction`. -/
protected def pointwiseSMul : SMul M (AffineSubspace k V) where
smul a s := s.map (DistribMulAction.toLinearMap k _ a).toAffineMap
scoped[Pointwise] attribute [instance] AffineSubspace.pointwiseSMul
@[simp, norm_cast]
lemma coe_smul (a : M) (s : AffineSubspace k V) : ↑(a • s) = a • (s : Set V) := rfl
/-- The multiplicative action on an affine subspace corresponding to applying the action to every
element.
This is available as an instance in the `Pointwise` locale.
TODO: generalize to include `SMul (P ≃ᵃ[k] P) (AffineSubspace k P)`, which acts on `P` with a
`VAdd` version of a `DistribMulAction`. -/
protected def mulAction : MulAction M (AffineSubspace k V) :=
SetLike.coe_injective.mulAction _ coe_smul
scoped[Pointwise] attribute [instance] AffineSubspace.mulAction
lemma smul_eq_map (a : M) (s : AffineSubspace k V) :
a • s = s.map (DistribMulAction.toLinearMap k _ a).toAffineMap := rfl
lemma smul_mem_smul_iff {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {a : G} :
a • p ∈ a • s ↔ p ∈ s := smul_mem_smul_set_iff
lemma smul_mem_smul_iff_of_isUnit (ha : IsUnit a) : a • p ∈ a • s ↔ p ∈ s :=
smul_mem_smul_iff (a := ha.unit)
lemma smul_mem_smul_iff₀ {G₀ : Type*} [GroupWithZero G₀] [DistribMulAction G₀ V]
[SMulCommClass G₀ k V] {a : G₀} (ha : a ≠ 0) : a • p ∈ a • s ↔ p ∈ s :=
smul_mem_smul_iff_of_isUnit ha.isUnit
@[simp] lemma smul_bot (a : M) : a • (⊥ : AffineSubspace k V) = ⊥ := by
ext; simp [smul_eq_map, map_bot]
@[simp] lemma smul_top (ha : IsUnit a) : a • (⊤ : AffineSubspace k V) = ⊤ := by
ext x; simpa [smul_eq_map, map_top] using ⟨ha.unit⁻¹ • x, smul_inv_smul ha.unit _⟩
lemma smul_span (a : M) (s : Set V) : a • affineSpan k s = affineSpan k (a • s) := map_span _ s
end SMul
end Ring
section Field
variable [Field k] [AddCommGroup V] [Module k V] {a : k}
@[simp]
lemma direction_smul (ha : a ≠ 0) (s : AffineSubspace k V) : (a • s).direction = s.direction := by
have : DistribMulAction.toLinearMap k V a = a • LinearMap.id := by
ext; simp
simp [smul_eq_map, map_direction, this, Submodule.map_smul, ha]
end Field
end AffineSubspace
|
SMul.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker
-/
import Mathlib.Algebra.Polynomial.Degree.Support
import Mathlib.Algebra.Polynomial.Eval.Defs
/-!
# Evaluating polynomials and scalar multiplication
## Main results
* `eval₂_smul`, `eval_smul`, `map_smul`, `comp_smul`: the functions preserve scalar multiplication
* `Polynomial.leval`: `Polynomial.eval` as linear map
-/
noncomputable section
open Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v w y
variable {R : Type u} {S : Type v} {T : Type w} {ι : Type y} {a b : R} {m n : ℕ}
section Semiring
variable [Semiring R] {p q r : R[X]}
section
variable [Semiring S]
variable (f : R →+* S) (x : S)
@[simp]
theorem eval₂_smul (g : R →+* S) (p : R[X]) (x : S) {s : R} :
eval₂ g x (s • p) = g s * eval₂ g x p := by
have A : p.natDegree < p.natDegree.succ := Nat.lt_succ_self _
have B : (s • p).natDegree < p.natDegree.succ := (natDegree_smul_le _ _).trans_lt A
rw [eval₂_eq_sum, eval₂_eq_sum, sum_over_range' _ _ _ A, sum_over_range' _ _ _ B] <;>
simp [mul_sum, mul_assoc]
end
section Eval
variable {x : R}
@[simp]
theorem eval_smul [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p : R[X])
(x : R) : (s • p).eval x = s • p.eval x := by
rw [← smul_one_smul R s p, eval, eval₂_smul, RingHom.id_apply, smul_one_mul]
/-- `Polynomial.eval` as linear map -/
@[simps]
def leval {R : Type*} [Semiring R] (r : R) : R[X] →ₗ[R] R where
toFun f := f.eval r
map_add' _f _g := eval_add
map_smul' c f := eval_smul c f r
end Eval
section Comp
@[simp]
theorem smul_comp [SMulZeroClass S R] [IsScalarTower S R R] (s : S) (p q : R[X]) :
(s • p).comp q = s • p.comp q := by
rw [← smul_one_smul R s p, comp, comp, eval₂_smul, ← smul_eq_C_mul, smul_assoc, one_smul]
end Comp
section Map
variable [Semiring S]
variable (f : R →+* S)
@[simp]
protected theorem map_smul (r : R) : (r • p).map f = f r • p.map f := by
rw [map, eval₂_smul, RingHom.comp_apply, C_mul']
end Map
end Semiring
end Polynomial
|
Basic.lean
|
/-
Copyright (c) 2024 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.Algebra.Category.ModuleCat.Basic
import Mathlib.RingTheory.Coalgebra.Equiv
/-!
# The category of coalgebras over a commutative ring
We introduce the bundled category `CoalgCat` of coalgebras over a fixed commutative ring `R`
along with the forgetful functor to `ModuleCat`.
This file mimics `Mathlib/LinearAlgebra/QuadraticForm/QuadraticModuleCat.lean`.
-/
open CategoryTheory
universe v u
variable (R : Type u) [CommRing R]
/-- The category of `R`-coalgebras. -/
structure CoalgCat extends ModuleCat.{v} R where
instCoalgebra : Coalgebra R carrier
attribute [instance] CoalgCat.instCoalgebra
variable {R}
namespace CoalgCat
open Coalgebra
instance : CoeSort (CoalgCat.{v} R) (Type v) :=
⟨(·.carrier)⟩
@[simp] theorem moduleCat_of_toModuleCat (X : CoalgCat.{v} R) :
ModuleCat.of R X.toModuleCat = X.toModuleCat :=
rfl
variable (R) in
/-- The object in the category of `R`-coalgebras associated to an `R`-coalgebra. -/
abbrev of (X : Type v) [AddCommGroup X] [Module R X] [Coalgebra R X] :
CoalgCat R :=
{ ModuleCat.of R X with
instCoalgebra := (inferInstance : Coalgebra R X) }
@[simp]
lemma of_comul {X : Type v} [AddCommGroup X] [Module R X] [Coalgebra R X] :
Coalgebra.comul (A := of R X) = Coalgebra.comul (R := R) (A := X) := rfl
@[simp]
lemma of_counit {X : Type v} [AddCommGroup X] [Module R X] [Coalgebra R X] :
Coalgebra.counit (A := of R X) = Coalgebra.counit (R := R) (A := X) := rfl
/-- A type alias for `CoalgHom` to avoid confusion between the categorical and
algebraic spellings of composition. -/
@[ext]
structure Hom (V W : CoalgCat.{v} R) where
/-- The underlying `CoalgHom` -/
toCoalgHom' : V →ₗc[R] W
instance category : Category (CoalgCat.{v} R) where
Hom M N := Hom M N
id M := ⟨CoalgHom.id R M⟩
comp f g := ⟨CoalgHom.comp g.toCoalgHom' f.toCoalgHom'⟩
instance concreteCategory : ConcreteCategory (CoalgCat.{v} R) (· →ₗc[R] ·) where
hom f := f.toCoalgHom'
ofHom f := ⟨f⟩
/-- Turn a morphism in `CoalgCat` back into a `CoalgHom`. -/
abbrev Hom.toCoalgHom {X Y : CoalgCat.{v} R} (f : Hom X Y) : X →ₗc[R] Y :=
ConcreteCategory.hom (C := CoalgCat.{v} R) f
/-- Typecheck a `CoalgHom` as a morphism in `CoalgCat R`. -/
abbrev ofHom {X Y : Type v} [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y]
[Coalgebra R X] [Coalgebra R Y] (f : X →ₗc[R] Y) :
of R X ⟶ of R Y :=
ConcreteCategory.ofHom f
lemma Hom.toCoalgHom_injective (V W : CoalgCat.{v} R) :
Function.Injective (Hom.toCoalgHom' : Hom V W → _) :=
fun ⟨f⟩ ⟨g⟩ _ => by congr
@[ext]
lemma hom_ext {M N : CoalgCat.{v} R} (f g : M ⟶ N) (h : f.toCoalgHom = g.toCoalgHom) :
f = g :=
Hom.ext h
@[simp] theorem toCoalgHom_comp {M N U : CoalgCat.{v} R} (f : M ⟶ N) (g : N ⟶ U) :
(f ≫ g).toCoalgHom = g.toCoalgHom.comp f.toCoalgHom :=
rfl
@[simp] theorem toCoalgHom_id {M : CoalgCat.{v} R} :
Hom.toCoalgHom (𝟙 M) = CoalgHom.id _ _ :=
rfl
instance hasForgetToModule : HasForget₂ (CoalgCat R) (ModuleCat R) where
forget₂ :=
{ obj := fun M => ModuleCat.of R M
map := fun f => ModuleCat.ofHom f.toCoalgHom.toLinearMap }
@[simp]
theorem forget₂_obj (X : CoalgCat R) :
(forget₂ (CoalgCat R) (ModuleCat R)).obj X = ModuleCat.of R X :=
rfl
@[simp]
theorem forget₂_map (X Y : CoalgCat R) (f : X ⟶ Y) :
(forget₂ (CoalgCat R) (ModuleCat R)).map f = ModuleCat.ofHom (f.toCoalgHom : X →ₗ[R] Y) :=
rfl
end CoalgCat
namespace CoalgEquiv
open CoalgCat
variable {X Y Z : Type v}
variable [AddCommGroup X] [Module R X] [AddCommGroup Y] [Module R Y] [AddCommGroup Z] [Module R Z]
variable [Coalgebra R X] [Coalgebra R Y] [Coalgebra R Z]
/-- Build an isomorphism in the category `CoalgCat R` from a
`CoalgEquiv`. -/
@[simps]
def toCoalgIso (e : X ≃ₗc[R] Y) : CoalgCat.of R X ≅ CoalgCat.of R Y where
hom := CoalgCat.ofHom e
inv := CoalgCat.ofHom e.symm
hom_inv_id := Hom.ext <| DFunLike.ext _ _ e.left_inv
inv_hom_id := Hom.ext <| DFunLike.ext _ _ e.right_inv
@[simp] theorem toCoalgIso_refl :
toCoalgIso (CoalgEquiv.refl R X) = .refl _ :=
rfl
@[simp] theorem toCoalgIso_symm (e : X ≃ₗc[R] Y) :
toCoalgIso e.symm = (toCoalgIso e).symm :=
rfl
@[simp] theorem toCoalgIso_trans (e : X ≃ₗc[R] Y) (f : Y ≃ₗc[R] Z) :
toCoalgIso (e.trans f) = toCoalgIso e ≪≫ toCoalgIso f :=
rfl
end CoalgEquiv
namespace CategoryTheory.Iso
open Coalgebra
variable {X Y Z : CoalgCat.{v} R}
/-- Build a `CoalgEquiv` from an isomorphism in the category
`CoalgCat R`. -/
def toCoalgEquiv (i : X ≅ Y) : X ≃ₗc[R] Y :=
{ i.hom.toCoalgHom with
invFun := i.inv.toCoalgHom
left_inv := fun x => CoalgHom.congr_fun (congr_arg CoalgCat.Hom.toCoalgHom i.3) x
right_inv := fun x => CoalgHom.congr_fun (congr_arg CoalgCat.Hom.toCoalgHom i.4) x }
@[simp] theorem toCoalgEquiv_toCoalgHom (i : X ≅ Y) :
i.toCoalgEquiv = i.hom.toCoalgHom := rfl
@[simp] theorem toCoalgEquiv_refl : toCoalgEquiv (.refl X) = .refl _ _ :=
rfl
@[simp] theorem toCoalgEquiv_symm (e : X ≅ Y) :
toCoalgEquiv e.symm = (toCoalgEquiv e).symm :=
rfl
@[simp] theorem toCoalgEquiv_trans (e : X ≅ Y) (f : Y ≅ Z) :
toCoalgEquiv (e ≪≫ f) = e.toCoalgEquiv.trans f.toCoalgEquiv :=
rfl
end CategoryTheory.Iso
instance CoalgCat.forget_reflects_isos :
(forget (CoalgCat.{v} R)).ReflectsIsomorphisms where
reflects {X Y} f _ := by
let i := asIso ((forget (CoalgCat.{v} R)).map f)
let e : X ≃ₗc[R] Y := { f.toCoalgHom, i.toEquiv with }
exact ⟨e.toCoalgIso.isIso_hom.1⟩
|
Spectrum.lean
|
/-
Copyright (c) 2022 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Analysis.CStarAlgebra.Unitization
import Mathlib.Analysis.Complex.Convex
import Mathlib.Analysis.Normed.Algebra.Spectrum
import Mathlib.Analysis.SpecialFunctions.Exponential
import Mathlib.Algebra.Star.StarAlgHom
/-! # Spectral properties in C⋆-algebras
In this file, we establish various properties related to the spectrum of elements in C⋆-algebras.
In particular, we show that the spectrum of a unitary element is contained in the unit circle in
`ℂ`, the spectrum of a selfadjoint element is real, the spectral radius of a selfadjoint element
or normal element is its norm, among others.
An essential feature of C⋆-algebras is **spectral permanence**. This is the property that the
spectrum of an element in a closed subalgebra is the same as the spectrum of the element in the
whole algebra. For Banach algebras more generally, and even for Banach ⋆-algebras, this fails.
A consequence of spectral permanence is that one may always enlarge the C⋆-algebra (via a unital
embedding) while preserving the spectrum of any element. In addition, it allows us to make sense of
the spectrum of elements in non-unital C⋆-algebras by considering them as elements in the
`Unitization` of the C⋆-algebra, or indeed *any* unital C⋆-algebra. Of course, one may do this
(that is, consider the spectrum of an element in a non-unital by embedding it in a unital algebra)
for any Banach algebra, but the downside in that setting is that embedding in different unital
algebras results in varying spectra.
In Mathlib, we don't *define* the spectrum of an element in a non-unital C⋆-algebra, and instead
simply consider the `quasispectrum` so as to avoid depending on a choice of unital algebra. However,
we can still establish a form of spectral permanence.
## Main statements
+ `unitary.spectrum_subset_circle`: The spectrum of a unitary element is contained in the unit
sphere in `ℂ`.
+ `IsSelfAdjoint.spectralRadius_eq_nnnorm`: The spectral radius of a selfadjoint element is equal
to its norm.
+ `IsStarNormal.spectralRadius_eq_nnnorm`: The spectral radius of a normal element is equal to
its norm.
+ `IsSelfAdjoint.mem_spectrum_eq_re`: Any element of the spectrum of a selfadjoint element is real.
* `StarSubalgebra.coe_isUnit`: for `x : S` in a C⋆-Subalgebra `S` of `A`, then `↑x : A` is a Unit
if and only if `x` is a unit.
* `StarSubalgebra.spectrum_eq`: **spectral_permanence** for `x : S`, where `S` is a C⋆-Subalgebra
of `A`, `spectrum ℂ x = spectrum ℂ (x : A)`.
## TODO
+ prove a variation of spectral permanence using `StarAlgHom` instead of `StarSubalgebra`.
+ prove a variation of spectral permanence for `quasispectrum`.
-/
local notation "σ" => spectrum
local postfix:max "⋆" => star
section
open scoped Topology ENNReal
open Filter ENNReal spectrum CStarRing NormedSpace
section UnitarySpectrum
variable {𝕜 : Type*} [NormedField 𝕜] {E : Type*} [NormedRing E] [StarRing E] [CStarRing E]
[NormedAlgebra 𝕜 E] [CompleteSpace E]
theorem unitary.spectrum_subset_circle (u : unitary E) :
spectrum 𝕜 (u : E) ⊆ Metric.sphere 0 1 := by
nontriviality E
refine fun k hk => mem_sphere_zero_iff_norm.mpr (le_antisymm ?_ ?_)
· simpa only [CStarRing.norm_coe_unitary u] using norm_le_norm_of_mem hk
· rw [← unitary.val_toUnits_apply u] at hk
have hnk := ne_zero_of_mem_of_unit hk
rw [← inv_inv (unitary.toUnits u), ← spectrum.map_inv, Set.mem_inv] at hk
have : ‖k‖⁻¹ ≤ ‖(↑(unitary.toUnits u)⁻¹ : E)‖ := by
simpa only [norm_inv] using norm_le_norm_of_mem hk
simpa using inv_le_of_inv_le₀ (norm_pos_iff.mpr hnk) this
theorem spectrum.subset_circle_of_unitary {u : E} (h : u ∈ unitary E) :
spectrum 𝕜 u ⊆ Metric.sphere 0 1 :=
unitary.spectrum_subset_circle ⟨u, h⟩
end UnitarySpectrum
section Quasispectrum
open scoped NNReal in
lemma CStarAlgebra.le_nnnorm_of_mem_quasispectrum {A : Type*} [NonUnitalCStarAlgebra A]
{a : A} {x : ℝ≥0} (hx : x ∈ quasispectrum ℝ≥0 a) : x ≤ ‖a‖₊ := by
rw [Unitization.quasispectrum_eq_spectrum_inr' ℝ≥0 ℂ] at hx
simpa [Unitization.nnnorm_inr] using spectrum.le_nnnorm_of_mem hx
end Quasispectrum
section ComplexScalars
open Complex
variable {A : Type*} [CStarAlgebra A]
local notation "↑ₐ" => algebraMap ℂ A
theorem IsSelfAdjoint.spectralRadius_eq_nnnorm {a : A} (ha : IsSelfAdjoint a) :
spectralRadius ℂ a = ‖a‖₊ := by
have hconst : Tendsto (fun _n : ℕ => (‖a‖₊ : ℝ≥0∞)) atTop _ := tendsto_const_nhds
refine tendsto_nhds_unique ?_ hconst
convert
(spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a : A)).comp
(Nat.tendsto_pow_atTop_atTop_of_one_lt one_lt_two) using 1
refine funext fun n => ?_
rw [Function.comp_apply, ha.nnnorm_pow_two_pow, ENNReal.coe_pow, ← rpow_natCast, ← rpow_mul]
simp
/-- In a C⋆-algebra, the spectral radius of a self-adjoint element is equal to its norm.
See `IsSelfAdjoint.toReal_spectralRadius_eq_norm` for a version involving
`spectralRadius ℝ a`. -/
lemma IsSelfAdjoint.toReal_spectralRadius_complex_eq_norm {a : A} (ha : IsSelfAdjoint a) :
(spectralRadius ℂ a).toReal = ‖a‖ := by
simp [ha.spectralRadius_eq_nnnorm]
theorem IsStarNormal.spectralRadius_eq_nnnorm (a : A) [IsStarNormal a] :
spectralRadius ℂ a = ‖a‖₊ := by
refine (ENNReal.pow_right_strictMono two_ne_zero).injective ?_
have heq :
(fun n : ℕ => (‖(a⋆ * a) ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ)) =
(fun x => x ^ 2) ∘ fun n : ℕ => (‖a ^ n‖₊ : ℝ≥0∞) ^ (1 / n : ℝ) := by
funext n
rw [Function.comp_apply, ← rpow_natCast, ← rpow_mul, mul_comm, rpow_mul, rpow_natCast, ←
coe_pow, sq, ← nnnorm_star_mul_self, Commute.mul_pow (star_comm_self' a), star_pow]
have h₂ :=
((ENNReal.continuous_pow 2).tendsto (spectralRadius ℂ a)).comp
(spectrum.pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius a)
rw [← heq] at h₂
convert tendsto_nhds_unique h₂ (pow_nnnorm_pow_one_div_tendsto_nhds_spectralRadius (a⋆ * a))
rw [(IsSelfAdjoint.star_mul_self a).spectralRadius_eq_nnnorm, sq, nnnorm_star_mul_self, coe_mul]
variable [StarModule ℂ A]
/-- Any element of the spectrum of a selfadjoint is real. -/
theorem IsSelfAdjoint.mem_spectrum_eq_re {a : A} (ha : IsSelfAdjoint a) {z : ℂ}
(hz : z ∈ spectrum ℂ a) : z = z.re := by
have hu := exp_mem_unitary_of_mem_skewAdjoint ℂ (ha.smul_mem_skewAdjoint conj_I)
let Iu := Units.mk0 I I_ne_zero
have : NormedSpace.exp ℂ (I • z) ∈ spectrum ℂ (NormedSpace.exp ℂ (I • a)) := by
simpa only [Units.smul_def, Units.val_mk0] using
spectrum.exp_mem_exp (Iu • a) (smul_mem_smul_iff.mpr hz)
exact Complex.ext (ofReal_re _) <| by
simpa only [← Complex.exp_eq_exp_ℂ, mem_sphere_zero_iff_norm, norm_exp, Real.exp_eq_one_iff,
smul_eq_mul, I_mul, neg_eq_zero] using
spectrum.subset_circle_of_unitary hu this
/-- Any element of the spectrum of a selfadjoint is real. -/
theorem selfAdjoint.mem_spectrum_eq_re (a : selfAdjoint A) {z : ℂ}
(hz : z ∈ spectrum ℂ (a : A)) : z = z.re :=
a.prop.mem_spectrum_eq_re hz
/-- Any element of the spectrum of a selfadjoint is real. -/
theorem IsSelfAdjoint.im_eq_zero_of_mem_spectrum {a : A} (ha : IsSelfAdjoint a)
{z : ℂ} (hz : z ∈ spectrum ℂ a) : z.im = 0 := by
rw [ha.mem_spectrum_eq_re hz, ofReal_im]
/-- The spectrum of a selfadjoint is real -/
theorem IsSelfAdjoint.val_re_map_spectrum {a : A} (ha : IsSelfAdjoint a) :
spectrum ℂ a = ((↑) ∘ re '' spectrum ℂ a : Set ℂ) :=
le_antisymm (fun z hz => ⟨z, hz, (ha.mem_spectrum_eq_re hz).symm⟩) fun z => by
rintro ⟨z, hz, rfl⟩
simpa only [(ha.mem_spectrum_eq_re hz).symm, Function.comp_apply] using hz
/-- The spectrum of a selfadjoint is real -/
theorem selfAdjoint.val_re_map_spectrum (a : selfAdjoint A) :
spectrum ℂ (a : A) = ((↑) ∘ re '' spectrum ℂ (a : A) : Set ℂ) :=
a.property.val_re_map_spectrum
/-- The complement of the spectrum of a selfadjoint element in a C⋆-algebra is connected. -/
lemma IsSelfAdjoint.isConnected_spectrum_compl {a : A} (ha : IsSelfAdjoint a) :
IsConnected (σ ℂ a)ᶜ := by
suffices IsConnected (((σ ℂ a)ᶜ ∩ {z | 0 ≤ z.im}) ∪ (σ ℂ a)ᶜ ∩ {z | z.im ≤ 0}) by
rw [← Set.inter_union_distrib_left, ← Set.setOf_or] at this
rw [← Set.inter_univ (σ ℂ a)ᶜ]
convert this using 2
exact Eq.symm <| Set.eq_univ_of_forall (fun z ↦ le_total 0 z.im)
refine IsConnected.union ?nonempty ?upper ?lower
case nonempty =>
have := Filter.NeBot.nonempty_of_mem inferInstance <| Filter.mem_map.mp <|
Complex.isometry_ofReal.antilipschitz.tendsto_cobounded (spectrum.isBounded a |>.compl)
exact this.image Complex.ofReal |>.mono <| by simp
case' upper => apply Complex.isConnected_of_upperHalfPlane ?_ <| Set.inter_subset_right
case' lower => apply Complex.isConnected_of_lowerHalfPlane ?_ <| Set.inter_subset_right
all_goals
refine Set.subset_inter (fun z hz hz' ↦ ?_) (fun _ ↦ by simpa using le_of_lt)
rw [Set.mem_setOf_eq, ha.im_eq_zero_of_mem_spectrum hz'] at hz
simp_all
namespace StarSubalgebra
variable (S : StarSubalgebra ℂ A) [hS : IsClosed (S : Set A)]
/-- For a unital C⋆-subalgebra `S` of `A` and `x : S`, if `↑x : A` is invertible in `A`, then
`x` is invertible in `S`. -/
lemma coe_isUnit {a : S} : IsUnit (a : A) ↔ IsUnit a := by
refine ⟨fun ha ↦ ?_, IsUnit.map S.subtype⟩
have ha₁ := ha.star.mul ha
have ha₂ := ha.mul ha.star
have spec_eq {x : S} (hx : IsSelfAdjoint x) : spectrum ℂ x = spectrum ℂ (x : A) :=
Subalgebra.spectrum_eq_of_isPreconnected_compl S _ <|
(hx.map S.subtype).isConnected_spectrum_compl.isPreconnected
rw [← StarMemClass.coe_star, ← MulMemClass.coe_mul, ← spectrum.zero_notMem_iff ℂ, ← spec_eq,
spectrum.zero_notMem_iff] at ha₁ ha₂
· have h₁ : ha₁.unit⁻¹ * star a * a = 1 := mul_assoc _ _ a ▸ ha₁.val_inv_mul
have h₂ : a * (star a * ha₂.unit⁻¹) = 1 := (mul_assoc a _ _).symm ▸ ha₂.mul_val_inv
exact ⟨⟨a, ha₁.unit⁻¹ * star a, left_inv_eq_right_inv h₁ h₂ ▸ h₂, h₁⟩, rfl⟩
· exact IsSelfAdjoint.mul_star_self a
· exact IsSelfAdjoint.star_mul_self a
lemma mem_spectrum_iff {a : S} {z : ℂ} : z ∈ spectrum ℂ a ↔ z ∈ spectrum ℂ (a : A) :=
not_iff_not.mpr S.coe_isUnit.symm
/-- **Spectral permanence.** The spectrum of an element is invariant of the (closed)
`StarSubalgebra` in which it is contained. -/
lemma spectrum_eq {a : S} : spectrum ℂ a = spectrum ℂ (a : A) :=
Set.ext fun _ ↦ S.mem_spectrum_iff
end StarSubalgebra
end ComplexScalars
namespace NonUnitalStarAlgHom
variable {F A B : Type*} [NonUnitalCStarAlgebra A] [NonUnitalCStarAlgebra B]
variable [FunLike F A B] [NonUnitalAlgHomClass F ℂ A B] [StarHomClass F A B]
open Unitization
/-- A non-unital star algebra homomorphism of complex C⋆-algebras is norm contractive. -/
lemma nnnorm_apply_le (φ : F) (a : A) : ‖φ a‖₊ ≤ ‖a‖₊ := by
have h (ψ : Unitization ℂ A →⋆ₐ[ℂ] Unitization ℂ B) (x : Unitization ℂ A) :
‖ψ x‖₊ ≤ ‖x‖₊ := by
suffices ∀ {s}, IsSelfAdjoint s → ‖ψ s‖₊ ≤ ‖s‖₊ by
refine nonneg_le_nonneg_of_sq_le_sq zero_le' ?_
simp_rw [← nnnorm_star_mul_self, ← map_star, ← map_mul]
exact this <| .star_mul_self x
intro s hs
suffices this : spectralRadius ℂ (ψ s) ≤ spectralRadius ℂ s by
rwa [(hs.map ψ).spectralRadius_eq_nnnorm, hs.spectralRadius_eq_nnnorm, coe_le_coe]
at this
exact iSup_le_iSup_of_subset (AlgHom.spectrum_apply_subset ψ s)
simpa [nnnorm_inr] using h (starLift (inrNonUnitalStarAlgHom ℂ B |>.comp (φ : A →⋆ₙₐ[ℂ] B))) a
/-- A non-unital star algebra homomorphism of complex C⋆-algebras is norm contractive. -/
lemma norm_apply_le (φ : F) (a : A) : ‖φ a‖ ≤ ‖a‖ := by
exact_mod_cast nnnorm_apply_le φ a
/-- Non-unital star algebra homomorphisms between C⋆-algebras are continuous linear maps.
See note [lower instance priority] -/
lemma instContinuousLinearMapClassComplex : ContinuousLinearMapClass F ℂ A B :=
{ NonUnitalAlgHomClass.instLinearMapClass with
map_continuous := fun φ =>
AddMonoidHomClass.continuous_of_bound φ 1 (by simpa only [one_mul] using nnnorm_apply_le φ) }
scoped[CStarAlgebra] attribute [instance] NonUnitalStarAlgHom.instContinuousLinearMapClassComplex
end NonUnitalStarAlgHom
namespace StarAlgEquiv
variable {F A B : Type*} [NonUnitalCStarAlgebra A] [NonUnitalCStarAlgebra B] [EquivLike F A B]
variable [NonUnitalAlgEquivClass F ℂ A B] [StarHomClass F A B]
lemma nnnorm_map (φ : F) (a : A) : ‖φ a‖₊ = ‖a‖₊ :=
le_antisymm (NonUnitalStarAlgHom.nnnorm_apply_le φ a) <| by
simpa using NonUnitalStarAlgHom.nnnorm_apply_le (symm (φ : A ≃⋆ₐ[ℂ] B)) ((φ : A ≃⋆ₐ[ℂ] B) a)
lemma norm_map (φ : F) (a : A) : ‖φ a‖ = ‖a‖ :=
congr_arg NNReal.toReal (nnnorm_map φ a)
lemma isometry (φ : F) : Isometry φ :=
AddMonoidHomClass.isometry_of_norm φ (norm_map φ)
end StarAlgEquiv
end
namespace WeakDual
open ContinuousMap Complex
open scoped ComplexStarModule
variable {F A : Type*} [CStarAlgebra A] [FunLike F A ℂ] [hF : AlgHomClass F ℂ A ℂ]
/-- This instance is provided instead of `StarHomClass` to avoid type class inference loops.
See note [lower instance priority] -/
noncomputable instance (priority := 100) Complex.instStarHomClass : StarHomClass F A ℂ where
map_star φ a := by
suffices hsa : ∀ s : selfAdjoint A, (φ s)⋆ = φ s by
rw [← realPart_add_I_smul_imaginaryPart a]
simp only [map_add, map_smul, star_add, star_smul, hsa, selfAdjoint.star_val_eq]
intro s
have := AlgHom.apply_mem_spectrum φ (s : A)
rw [selfAdjoint.val_re_map_spectrum s] at this
rcases this with ⟨⟨_, _⟩, _, heq⟩
simp only [Function.comp_apply] at heq
rw [← heq, RCLike.star_def]
exact RCLike.conj_ofReal _
/-- This is not an instance to avoid type class inference loops. See
`WeakDual.Complex.instStarHomClass`. -/
lemma _root_.AlgHomClass.instStarHomClass : StarHomClass F A ℂ :=
{ WeakDual.Complex.instStarHomClass, hF with }
namespace CharacterSpace
noncomputable instance instStarHomClass : StarHomClass (characterSpace ℂ A) A ℂ :=
{ AlgHomClass.instStarHomClass with }
end CharacterSpace
end WeakDual
|
Constructions.lean
|
/-
Copyright (c) 2024 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson
-/
import Mathlib.Data.Matroid.Minor.Restrict
/-!
# Some constructions of matroids
This file defines some very elementary examples of matroids, namely those with at most one base.
## Main definitions
* `emptyOn α` is the matroid on `α` with empty ground set.
For `E : Set α`, ...
* `loopyOn E` is the matroid on `E` whose elements are all loops, or equivalently in which `∅`
is the only base.
* `freeOn E` is the 'free matroid' whose ground set `E` is the only base.
* For `I ⊆ E`, `uniqueBaseOn I E` is the matroid with ground set `E` in which `I` is the only base.
## Implementation details
To avoid the tedious process of certifying the matroid axioms for each of these easy examples,
we bootstrap the definitions starting with `emptyOn α` (which `simp` can prove is a matroid)
and then construct the other examples using duality and restriction.
-/
assert_not_exists Field
variable {α : Type*} {M : Matroid α} {E B I X R J : Set α}
namespace Matroid
open Set
section EmptyOn
/-- The `Matroid α` with empty ground set. -/
def emptyOn (α : Type*) : Matroid α where
E := ∅
IsBase := (· = ∅)
Indep := (· = ∅)
indep_iff' := by simp [subset_empty_iff]
exists_isBase := ⟨∅, rfl⟩
isBase_exchange := by rintro _ _ rfl; simp
maximality := by rintro _ _ _ rfl -; exact ⟨∅, by simp [Maximal]⟩
subset_ground := by simp
@[simp] theorem emptyOn_ground : (emptyOn α).E = ∅ := rfl
@[simp] theorem emptyOn_isBase_iff : (emptyOn α).IsBase B ↔ B = ∅ := Iff.rfl
@[simp] theorem emptyOn_indep_iff : (emptyOn α).Indep I ↔ I = ∅ := Iff.rfl
theorem ground_eq_empty_iff : (M.E = ∅) ↔ M = emptyOn α := by
simp only [emptyOn, ext_iff_indep, iff_self_and]
exact fun h ↦ by simp [h, subset_empty_iff]
@[simp] theorem emptyOn_dual_eq : (emptyOn α)✶ = emptyOn α := by
rw [← ground_eq_empty_iff]; rfl
@[simp] theorem restrict_empty (M : Matroid α) : M ↾ (∅ : Set α) = emptyOn α := by
simp [← ground_eq_empty_iff]
theorem eq_emptyOn_or_nonempty (M : Matroid α) : M = emptyOn α ∨ Matroid.Nonempty M := by
rw [← ground_eq_empty_iff]
exact M.E.eq_empty_or_nonempty.elim Or.inl (fun h ↦ Or.inr ⟨h⟩)
theorem eq_emptyOn [IsEmpty α] (M : Matroid α) : M = emptyOn α := by
rw [← ground_eq_empty_iff]
exact M.E.eq_empty_of_isEmpty
instance finite_emptyOn (α : Type*) : (emptyOn α).Finite :=
⟨finite_empty⟩
end EmptyOn
section LoopyOn
/-- The `Matroid α` with ground set `E` whose only base is `∅`.
The elements are all 'loops' - see `Matroid.IsLoop` and `Matroid.loopyOn_isLoop_iff`. -/
def loopyOn (E : Set α) : Matroid α := emptyOn α ↾ E
@[simp] theorem loopyOn_ground (E : Set α) : (loopyOn E).E = E := rfl
@[simp] theorem loopyOn_empty (α : Type*) : loopyOn (∅ : Set α) = emptyOn α := by
rw [← ground_eq_empty_iff, loopyOn_ground]
@[simp] theorem loopyOn_indep_iff : (loopyOn E).Indep I ↔ I = ∅ := by
simp only [loopyOn, restrict_indep_iff, emptyOn_indep_iff, and_iff_left_iff_imp]
rintro rfl; apply empty_subset
theorem eq_loopyOn_iff : M = loopyOn E ↔ M.E = E ∧ ∀ X ⊆ M.E, M.Indep X → X = ∅ := by
simp only [ext_iff_indep, loopyOn_ground, loopyOn_indep_iff, and_congr_right_iff]
rintro rfl
refine ⟨fun h I hI ↦ (h hI).1, fun h I hIE ↦ ⟨h I hIE, by rintro rfl; simp⟩⟩
@[simp] theorem loopyOn_isBase_iff : (loopyOn E).IsBase B ↔ B = ∅ := by
simp [Maximal, isBase_iff_maximal_indep]
@[simp] theorem loopyOn_isBasis_iff : (loopyOn E).IsBasis I X ↔ I = ∅ ∧ X ⊆ E :=
⟨fun h ↦ ⟨loopyOn_indep_iff.mp h.indep, h.subset_ground⟩,
by rintro ⟨rfl, hX⟩; rw [isBasis_iff]; simp⟩
instance loopyOn_rankFinite : RankFinite (loopyOn E) :=
⟨∅, by simp⟩
theorem Finite.loopyOn_finite (hE : E.Finite) : Matroid.Finite (loopyOn E) :=
⟨hE⟩
@[simp] theorem loopyOn_restrict (E R : Set α) : (loopyOn E) ↾ R = loopyOn R := by
refine ext_indep rfl ?_
simp only [restrict_ground_eq, restrict_indep_iff, loopyOn_indep_iff, and_iff_left_iff_imp]
exact fun _ h _ ↦ h
theorem empty_isBase_iff : M.IsBase ∅ ↔ M = loopyOn M.E := by
simp only [isBase_iff_maximal_indep, Maximal, empty_indep, le_eq_subset, empty_subset,
subset_empty_iff, true_implies, true_and, ext_iff_indep, loopyOn_ground,
loopyOn_indep_iff]
exact ⟨fun h I _ ↦ ⟨@h _, fun hI ↦ by simp [hI]⟩, fun h I hI ↦ (h hI.subset_ground).1 hI⟩
theorem eq_loopyOn_or_rankPos (M : Matroid α) : M = loopyOn M.E ∨ RankPos M := by
rw [← empty_isBase_iff, rankPos_iff]; apply em
theorem not_rankPos_iff : ¬RankPos M ↔ M = loopyOn M.E := by
rw [rankPos_iff, not_iff_comm, empty_isBase_iff]
end LoopyOn
section FreeOn
/-- The `Matroid α` with ground set `E` whose only base is `E`. -/
def freeOn (E : Set α) : Matroid α := (loopyOn E)✶
@[simp] theorem freeOn_ground : (freeOn E).E = E := rfl
@[simp] theorem freeOn_dual_eq : (freeOn E)✶ = loopyOn E := by
rw [freeOn, dual_dual]
@[simp] theorem loopyOn_dual_eq : (loopyOn E)✶ = freeOn E := rfl
@[simp] theorem freeOn_empty (α : Type*) : freeOn (∅ : Set α) = emptyOn α := by
simp [freeOn]
@[simp] theorem freeOn_isBase_iff : (freeOn E).IsBase B ↔ B = E := by
simp only [freeOn, loopyOn_ground, dual_isBase_iff', loopyOn_isBase_iff, diff_eq_empty,
← subset_antisymm_iff, eq_comm (a := E)]
@[simp] theorem freeOn_indep_iff : (freeOn E).Indep I ↔ I ⊆ E := by
simp [indep_iff]
theorem freeOn_indep (hIE : I ⊆ E) : (freeOn E).Indep I :=
freeOn_indep_iff.2 hIE
@[simp] theorem freeOn_isBasis_iff : (freeOn E).IsBasis I X ↔ I = X ∧ X ⊆ E := by
use fun h ↦ ⟨(freeOn_indep h.subset_ground).eq_of_isBasis h ,h.subset_ground⟩
rintro ⟨rfl, hIE⟩
exact (freeOn_indep hIE).isBasis_self
@[simp] theorem freeOn_isBasis'_iff : (freeOn E).IsBasis' I X ↔ I = X ∩ E := by
rw [isBasis'_iff_isBasis_inter_ground, freeOn_isBasis_iff, freeOn_ground,
and_iff_left inter_subset_right]
theorem eq_freeOn_iff : M = freeOn E ↔ M.E = E ∧ M.Indep E := by
refine ⟨?_, fun h ↦ ?_⟩
· rintro rfl; simp
simp only [ext_iff_indep, freeOn_ground, freeOn_indep_iff, h.1, true_and]
exact fun I hIX ↦ iff_of_true (h.2.subset hIX) hIX
theorem ground_indep_iff_eq_freeOn : M.Indep M.E ↔ M = freeOn M.E := by
simp [eq_freeOn_iff]
theorem freeOn_restrict (h : R ⊆ E) : (freeOn E) ↾ R = freeOn R := by
simp [h, eq_freeOn_iff]
theorem restrict_eq_freeOn_iff : M ↾ I = freeOn I ↔ M.Indep I := by
rw [eq_freeOn_iff, and_iff_right M.restrict_ground_eq, restrict_indep_iff,
and_iff_left Subset.rfl]
theorem Indep.restrict_eq_freeOn (hI : M.Indep I) : M ↾ I = freeOn I := by
rwa [restrict_eq_freeOn_iff]
instance freeOn_finitary : Finitary (freeOn E) := by
simp only [finitary_iff, freeOn_indep_iff]
exact fun I h e heI ↦ by simpa using h {e} (by simpa)
lemma freeOn_rankPos (hE : E.Nonempty) : RankPos (freeOn E) := by
simp [rankPos_iff, hE.ne_empty.symm]
end FreeOn
section uniqueBaseOn
/-- The matroid on `E` whose unique base is the subset `I` of `E`.
Intended for use when `I ⊆ E`; if this not not the case, then the base is `I ∩ E`. -/
def uniqueBaseOn (I E : Set α) : Matroid α := freeOn I ↾ E
@[simp] theorem uniqueBaseOn_ground : (uniqueBaseOn I E).E = E :=
rfl
theorem uniqueBaseOn_isBase_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).IsBase B ↔ B = I := by
rw [uniqueBaseOn, isBase_restrict_iff', freeOn_isBasis'_iff, inter_eq_self_of_subset_right hIE]
theorem uniqueBaseOn_inter_ground_eq (I E : Set α) :
uniqueBaseOn (I ∩ E) E = uniqueBaseOn I E := by
simp only [uniqueBaseOn, restrict_eq_restrict_iff, freeOn_indep_iff, subset_inter_iff]
tauto
@[simp] theorem uniqueBaseOn_indep_iff' : (uniqueBaseOn I E).Indep J ↔ J ⊆ I ∩ E := by
rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, subset_inter_iff]
theorem uniqueBaseOn_indep_iff (hIE : I ⊆ E) : (uniqueBaseOn I E).Indep J ↔ J ⊆ I := by
rw [uniqueBaseOn, restrict_indep_iff, freeOn_indep_iff, and_iff_left_iff_imp]
exact fun h ↦ h.trans hIE
theorem uniqueBaseOn_isBasis_iff (hX : X ⊆ E) : (uniqueBaseOn I E).IsBasis J X ↔ J = X ∩ I := by
rw [isBasis_iff_maximal]
exact maximal_iff_eq (by simp [inter_subset_left.trans hX])
(by simp +contextual)
theorem uniqueBaseOn_inter_isBasis (hX : X ⊆ E) : (uniqueBaseOn I E).IsBasis (X ∩ I) X := by
rw [uniqueBaseOn_isBasis_iff hX]
@[simp] theorem uniqueBaseOn_dual_eq (I E : Set α) :
(uniqueBaseOn I E)✶ = uniqueBaseOn (E \ I) E := by
rw [← uniqueBaseOn_inter_ground_eq]
refine ext_isBase rfl (fun B (hB : B ⊆ E) ↦ ?_)
rw [dual_isBase_iff, uniqueBaseOn_isBase_iff inter_subset_right,
uniqueBaseOn_isBase_iff diff_subset, uniqueBaseOn_ground]
exact ⟨fun h ↦ by rw [← diff_diff_cancel_left hB, h, diff_inter_self_eq_diff],
fun h ↦ by rw [h, inter_comm I]; simp⟩
@[simp] theorem uniqueBaseOn_self (I : Set α) : uniqueBaseOn I I = freeOn I := by
rw [uniqueBaseOn, freeOn_restrict rfl.subset]
@[simp] theorem uniqueBaseOn_empty (I : Set α) : uniqueBaseOn ∅ I = loopyOn I := by
rw [← dual_inj, uniqueBaseOn_dual_eq, diff_empty, uniqueBaseOn_self, loopyOn_dual_eq]
theorem uniqueBaseOn_restrict' (I E R : Set α) :
(uniqueBaseOn I E) ↾ R = uniqueBaseOn (I ∩ R ∩ E) R := by
simp_rw [ext_iff_indep, restrict_ground_eq, uniqueBaseOn_ground, true_and,
restrict_indep_iff, uniqueBaseOn_indep_iff', subset_inter_iff]
tauto
theorem uniqueBaseOn_restrict (h : I ⊆ E) (R : Set α) :
(uniqueBaseOn I E) ↾ R = uniqueBaseOn (I ∩ R) R := by
rw [uniqueBaseOn_restrict', inter_right_comm, inter_eq_self_of_subset_left h]
lemma uniqueBaseOn_rankFinite (hI : I.Finite) : RankFinite (uniqueBaseOn I E) := by
rw [← uniqueBaseOn_inter_ground_eq]
refine ⟨I ∩ E, ?_⟩
rw [uniqueBaseOn_isBase_iff inter_subset_right, and_iff_right rfl]
exact hI.subset inter_subset_left
instance uniqueBaseOn_finitary : Finitary (uniqueBaseOn I E) := by
refine ⟨fun K hK ↦ ?_⟩
simp only [uniqueBaseOn_indep_iff'] at hK ⊢
exact fun e heK ↦ singleton_subset_iff.1 <| hK _ (by simpa) (by simp)
lemma uniqueBaseOn_rankPos (hIE : I ⊆ E) (hI : I.Nonempty) : RankPos (uniqueBaseOn I E) where
empty_not_isBase := by simpa [uniqueBaseOn_isBase_iff hIE] using Ne.symm <| hI.ne_empty
end uniqueBaseOn
end Matroid
|
Prod.lean
|
/-
Copyright (c) 2023 Antoine Chambert-Loir and María Inés de Frutos-Fernández. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Antoine Chambert-Loir, María Inés de Frutos-Fernández, Bhavik Mehta, Eric Wieser
-/
import Mathlib.Algebra.Order.Monoid.Canonical.Defs
import Mathlib.Algebra.Order.Sub.Defs
import Mathlib.Data.Finset.Basic
import Mathlib.Order.Interval.Finset.Defs
/-! # Antidiagonal with values in general types
We define a type class `Finset.HasAntidiagonal A` which contains a function
`antidiagonal : A → Finset (A × A)` such that `antidiagonal n`
is the finset of all pairs adding to `n`, as witnessed by `mem_antidiagonal`.
When `A` is a canonically ordered add monoid with locally finite order
this typeclass can be instantiated with `Finset.antidiagonalOfLocallyFinite`.
This applies in particular when `A` is `ℕ`, more generally or `σ →₀ ℕ`,
or even `ι →₀ A` under the additional assumption `OrderedSub A`
that make it a canonically ordered add monoid.
(In fact, we would just need an `AddMonoid` with a compatible order,
finite `Iic`, such that if `a + b = n`, then `a, b ≤ n`,
and any finiteness condition would be OK.)
For computational reasons it is better to manually provide instances for `ℕ`
and `σ →₀ ℕ`, to avoid quadratic runtime performance.
These instances are provided as `Finset.Nat.instHasAntidiagonal` and `Finsupp.instHasAntidiagonal`.
This is why `Finset.antidiagonalOfLocallyFinite` is an `abbrev` and not an `instance`.
This definition does not exactly match with that of `Multiset.antidiagonal`
defined in `Mathlib/Data/Multiset/Antidiagonal.lean`, because of the multiplicities.
Indeed, by counting multiplicities, `Multiset α` is equivalent to `α →₀ ℕ`,
but `Finset.antidiagonal` and `Multiset.antidiagonal` will return different objects.
For example, for `s : Multiset ℕ := {0,0,0}`, `Multiset.antidiagonal s` has 8 elements
but `Finset.antidiagonal s` has only 4.
```lean
def s : Multiset ℕ := {0, 0, 0}
#eval (Finset.antidiagonal s).card -- 4
#eval Multiset.card (Multiset.antidiagonal s) -- 8
```
## TODO
* Define `HasMulAntidiagonal` (for monoids).
For `PNat`, we will recover the set of divisors of a strictly positive integer.
-/
open Function
namespace Finset
/-- The class of additive monoids with an antidiagonal -/
class HasAntidiagonal (A : Type*) [AddMonoid A] where
/-- The antidiagonal of an element `n` is the finset of pairs `(i, j)` such that `i + j = n`. -/
antidiagonal : A → Finset (A × A)
/-- A pair belongs to `antidiagonal n` iff the sum of its components is equal to `n`. -/
mem_antidiagonal {n} {a} : a ∈ antidiagonal n ↔ a.fst + a.snd = n
export HasAntidiagonal (antidiagonal mem_antidiagonal)
attribute [simp] mem_antidiagonal
variable {A : Type*}
/-- All `HasAntidiagonal` instances are equal -/
instance [AddMonoid A] : Subsingleton (HasAntidiagonal A) where
allEq := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
congr with n xy
rw [ha, hb]
-- The goal of this lemma is to allow to rewrite antidiagonal
-- when the decidability instances obsucate Lean
lemma hasAntidiagonal_congr (A : Type*) [AddMonoid A]
[H1 : HasAntidiagonal A] [H2 : HasAntidiagonal A] :
H1.antidiagonal = H2.antidiagonal := by congr!; subsingleton
theorem swap_mem_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} {xy : A × A} :
xy.swap ∈ antidiagonal n ↔ xy ∈ antidiagonal n := by
simp [add_comm]
@[simp] theorem map_prodComm_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} :
(antidiagonal n).map (Equiv.prodComm A A) = antidiagonal n :=
Finset.ext fun ⟨a, b⟩ => by simp [add_comm]
/-- See also `Finset.map_prodComm_antidiagonal`. -/
@[simp] theorem map_swap_antidiagonal [AddCommMonoid A] [HasAntidiagonal A] {n : A} :
(antidiagonal n).map ⟨Prod.swap, Prod.swap_injective⟩ = antidiagonal n :=
map_prodComm_antidiagonal
section AddCancelMonoid
variable [AddCancelMonoid A] [HasAntidiagonal A] {p q : A × A} {n : A}
/-- A point in the antidiagonal is determined by its first coordinate.
See also `Finset.antidiagonal_congr'`. -/
theorem antidiagonal_congr (hp : p ∈ antidiagonal n) (hq : q ∈ antidiagonal n) :
p = q ↔ p.1 = q.1 := by
refine ⟨congr_arg Prod.fst, fun h ↦ Prod.ext h ((add_right_inj q.fst).mp ?_)⟩
rw [mem_antidiagonal] at hp hq
rw [hq, ← h, hp]
/-- A point in the antidiagonal is determined by its first co-ordinate (subtype version of
`Finset.antidiagonal_congr`). This lemma is used by the `ext` tactic. -/
@[ext] theorem antidiagonal_subtype_ext {p q : antidiagonal n} (h : p.val.1 = q.val.1) : p = q :=
Subtype.ext ((antidiagonal_congr p.prop q.prop).mpr h)
end AddCancelMonoid
section AddCancelCommMonoid
variable [AddCancelCommMonoid A] [HasAntidiagonal A] {p q : A × A} {n : A}
/-- A point in the antidiagonal is determined by its second coordinate.
See also `Finset.antidiagonal_congr`. -/
lemma antidiagonal_congr' (hp : p ∈ antidiagonal n) (hq : q ∈ antidiagonal n) :
p = q ↔ p.2 = q.2 := by
rw [← Prod.swap_inj]
exact antidiagonal_congr (swap_mem_antidiagonal.2 hp) (swap_mem_antidiagonal.2 hq)
end AddCancelCommMonoid
section CanonicallyOrderedAdd
variable [AddCommMonoid A] [PartialOrder A] [CanonicallyOrderedAdd A] [HasAntidiagonal A]
@[simp]
theorem antidiagonal_zero : antidiagonal (0 : A) = {(0, 0)} := by
ext ⟨x, y⟩
simp
theorem antidiagonal.fst_le {n : A} {kl : A × A} (hlk : kl ∈ antidiagonal n) : kl.1 ≤ n := by
rw [le_iff_exists_add]
use kl.2
rwa [mem_antidiagonal, eq_comm] at hlk
theorem antidiagonal.snd_le {n : A} {kl : A × A} (hlk : kl ∈ antidiagonal n) : kl.2 ≤ n := by
rw [le_iff_exists_add]
use kl.1
rwa [mem_antidiagonal, eq_comm, add_comm] at hlk
end CanonicallyOrderedAdd
section OrderedSub
variable [AddCommMonoid A] [PartialOrder A] [CanonicallyOrderedAdd A] [Sub A] [OrderedSub A]
variable [AddLeftReflectLE A]
variable [HasAntidiagonal A]
theorem filter_fst_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable (m ≤ n)] :
{x ∈ antidiagonal n | x.fst = m} = if m ≤ n then {(m, n - m)} else ∅ := by
ext ⟨a, b⟩
suffices a = m → (a + b = n ↔ m ≤ n ∧ b = n - m) by
rw [mem_filter, mem_antidiagonal, apply_ite (fun n ↦ (a, b) ∈ n), mem_singleton,
Prod.mk_inj, ite_prop_iff_or]
simpa [← and_assoc, @and_right_comm _ (a = _), and_congr_left_iff]
rintro rfl
constructor
· rintro rfl
exact ⟨le_add_right le_rfl, (add_tsub_cancel_left _ _).symm⟩
· rintro ⟨h, rfl⟩
exact add_tsub_cancel_of_le h
theorem filter_snd_eq_antidiagonal (n m : A) [DecidablePred (· = m)] [Decidable (m ≤ n)] :
{x ∈ antidiagonal n | x.snd = m} = if m ≤ n then {(n - m, m)} else ∅ := by
have : (fun x : A × A ↦ (x.snd = m)) ∘ Prod.swap = fun x : A × A ↦ x.fst = m := by
ext; simp
rw [← map_swap_antidiagonal, filter_map]
simp [this, filter_fst_eq_antidiagonal, apply_ite (Finset.map _)]
end OrderedSub
/-- The disjoint union of antidiagonals `Σ (n : A), antidiagonal n` is equivalent to the product
`A × A`. This is such an equivalence, obtained by mapping `(n, (k, l))` to `(k, l)`. -/
@[simps]
def sigmaAntidiagonalEquivProd [AddMonoid A] [HasAntidiagonal A] :
(Σ n : A, antidiagonal n) ≃ A × A where
toFun x := x.2
invFun x := ⟨x.1 + x.2, x, mem_antidiagonal.mpr rfl⟩
left_inv := by
rintro ⟨n, ⟨k, l⟩, h⟩
rw [mem_antidiagonal] at h
exact Sigma.subtype_ext h rfl
variable {A : Type*}
[AddCommMonoid A] [PartialOrder A] [CanonicallyOrderedAdd A]
[LocallyFiniteOrderBot A] [DecidableEq A]
/-- In a canonically ordered add monoid, the antidiagonal can be construct by filtering.
Note that this is not an instance, as for some times a more efficient algorithm is available. -/
abbrev antidiagonalOfLocallyFinite : HasAntidiagonal A where
antidiagonal n := {uv ∈ Iic n ×ˢ Iic n | uv.fst + uv.snd = n}
mem_antidiagonal {n} {a} := by
simp only [mem_filter, and_iff_right_iff_imp]
intro h
simp [← h]
end Finset
|
Units.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.Algebra.Group.Nat.Defs
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Logic.Unique
/-!
# The unit of the natural numbers
-/
assert_not_exists MonoidWithZero DenselyOrdered
namespace Nat
/-! #### Units -/
lemma units_eq_one (u : ℕˣ) : u = 1 := Units.ext <| Nat.eq_one_of_dvd_one ⟨u.inv, u.val_inv.symm⟩
lemma addUnits_eq_zero (u : AddUnits ℕ) : u = 0 :=
AddUnits.ext <| (Nat.eq_zero_of_add_eq_zero u.val_neg).1
instance unique_units : Unique ℕˣ where
default := 1
uniq := Nat.units_eq_one
instance unique_addUnits : Unique (AddUnits ℕ) where
default := 0
uniq := Nat.addUnits_eq_zero
/-- Alias of `isUnit_iff_eq_one` for discoverability. -/
protected lemma isUnit_iff {n : ℕ} : IsUnit n ↔ n = 1 := isUnit_iff_eq_one
/-- Alias of `isAddUnit_iff_eq_zero` for discoverability. -/
protected lemma isAddUnit_iff {n : ℕ} : IsAddUnit n ↔ n = 0 := isAddUnit_iff_eq_zero
end Nat
|
Basic.lean
|
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots
import Mathlib.NumberTheory.NumberField.Basic
import Mathlib.FieldTheory.SeparableClosure
/-!
# Cyclotomic extensions
Let `A` and `B` be commutative rings with `Algebra A B`. For `S : Set ℕ`, we define a class
`IsCyclotomicExtension S A B` expressing the fact that `B` is obtained from `A` by adding `n`-th
primitive roots of unity, for all nonzero `n ∈ S`.
## Main definitions
* `IsCyclotomicExtension S A B` : means that `B` is obtained from `A` by adding `n`-th primitive
roots of unity, for all nonzero `n ∈ S`.
* `CyclotomicField`: given `n : ℕ` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has the instance
`IsCyclotomicExtension {n} K (CyclotomicField n K)`.
* `CyclotomicRing` : if `A` is a domain with fraction field `K` and `n : ℕ`, we define
`CyclotomicRing n A K` as the `A`-subalgebra of `CyclotomicField n K` generated by the roots of
`X ^ n - 1`. If `n` is nonzero in `A`, it has the instance
`IsCyclotomicExtension {n} A (CyclotomicRing n A K)`.
## Main results
* `IsCyclotomicExtension.trans` : if `IsCyclotomicExtension S A B` and
`IsCyclotomicExtension T B C`, then `IsCyclotomicExtension (S ∪ T) A C` if
`Function.Injective (algebraMap B C)`.
* `IsCyclotomicExtension.union_right` : given `IsCyclotomicExtension (S ∪ T) A B`, then
`IsCyclotomicExtension T (adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ (a : ℕ) = 1 }) B`.
* `IsCyclotomicExtension.union_left` : given `IsCyclotomicExtension T A B` and `S ⊆ T`, then
`IsCyclotomicExtension S A (adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ (a : ℕ) = 1 })`.
* `IsCyclotomicExtension.finite` : if `S` is finite and `IsCyclotomicExtension S A B`, then
`B` is a finite `A`-algebra.
* `IsCyclotomicExtension.numberField` : a finite cyclotomic extension of a number field is a
number field.
* `IsCyclotomicExtension.isSplittingField_X_pow_sub_one` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `X ^ n - 1`.
* `IsCyclotomicExtension.splitting_field_cyclotomic` : if `IsCyclotomicExtension {n} K L`,
then `L` is the splitting field of `cyclotomic n K`.
## Implementation details
Our definition of `IsCyclotomicExtension` is very general, to allow rings of any characteristic
and infinite extensions, but it will mainly be used in the case `S = {n}` and for integral domains.
All results are in the `IsCyclotomicExtension` namespace.
Note that some results, for example `IsCyclotomicExtension.trans`,
`IsCyclotomicExtension.finite`, `IsCyclotomicExtension.numberField`,
`IsCyclotomicExtension.finiteDimensional`, `IsCyclotomicExtension.isGalois` and
`CyclotomicField.algebraBase` are lemmas, but they can be made local instances. Some of them are
included in the `Cyclotomic` locale.
-/
open Polynomial Algebra Module Set
universe u v w z
noncomputable section
/-- Given an `A`-algebra `B` and `S : Set ℕ`, we define `IsCyclotomicExtension S A B` requiring
that there is an `n`-th primitive root of unity in `B` for all nonzero `n ∈ S` and that
`B` is generated over `A` by the roots of `X ^ n - 1`. -/
@[mk_iff]
class IsCyclotomicExtension
(S : Set ℕ) (A : Type u) (B : Type v)
[CommRing A] [CommRing B] [Algebra A B] : Prop where
/-- For all nonzero `n ∈ S`, there exists a primitive `n`-th root of unity in `B`. -/
exists_isPrimitiveRoot {S} (A B) {n : ℕ} (ha : n ∈ S) (ha' : n ≠ 0) :
∃ r : B, IsPrimitiveRoot r n
/-- The `n`-th roots of unity, for `n ∈ S` nonzero, generate `B` as an `A`-algebra. -/
adjoin_roots : ∀ x : B, x ∈ adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}
variable (n : ℕ) [NeZero n] (S T : Set ℕ) (A : Type u) (B : Type v) (K : Type w) (L : Type z)
variable [CommRing A] [CommRing B] [Algebra A B]
variable [Field K] [Field L] [Algebra K L]
namespace IsCyclotomicExtension
section Basic
variable {S B} in
@[deprecated exists_isPrimitiveRoot (since := "2025-05-21")]
theorem exists_prim_root [IsCyclotomicExtension S A B] {n : ℕ} (ha : n ∈ S) (ha' : n ≠ 0) :
∃ r : B, IsPrimitiveRoot r n :=
exists_isPrimitiveRoot A B ha ha'
/-- A reformulation of `IsCyclotomicExtension` that uses `⊤`. -/
theorem iff_adjoin_eq_top :
IsCyclotomicExtension S A B ↔
(∀ n : ℕ, n ∈ S → n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n) ∧
adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1} = ⊤ :=
⟨fun h => ⟨fun _ => h.exists_isPrimitiveRoot, Algebra.eq_top_iff.2 h.adjoin_roots⟩, fun h =>
⟨h.1 _, Algebra.eq_top_iff.1 h.2⟩⟩
/-- A reformulation of `IsCyclotomicExtension` in the case `S` is a singleton. -/
theorem iff_singleton :
IsCyclotomicExtension {n} A B ↔
(∃ r : B, IsPrimitiveRoot r n) ∧ ∀ x, x ∈ adjoin A {b : B | b ^ n = 1} := by
simp [isCyclotomicExtension_iff, NeZero.ne]
/-- If `IsCyclotomicExtension ∅ A B`, then the image of `A` in `B` equals `B`. -/
theorem empty [h : IsCyclotomicExtension ∅ A B] : (⊥ : Subalgebra A B) = ⊤ := by
simpa [Algebra.eq_top_iff, isCyclotomicExtension_iff] using h
theorem eq_self_sdiff_zero :
IsCyclotomicExtension S A B = IsCyclotomicExtension (S \ {0}) A B := by
simp [isCyclotomicExtension_iff, and_assoc]
/-- If `IsCyclotomicExtension {1} A B`, then the image of `A` in `B` equals `B`. -/
theorem singleton_one [h : IsCyclotomicExtension {1} A B] : (⊥ : Subalgebra A B) = ⊤ :=
Algebra.eq_top_iff.2 fun x => by
simpa [adjoin_singleton_one] using ((isCyclotomicExtension_iff _ _ _).1 h).2 x
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension ∅ A B`. -/
theorem singleton_zero_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension ∅ A B := by
refine (iff_adjoin_eq_top _ _ _).2
⟨fun s hs => by simp at hs, _root_.eq_top_iff.2 fun x hx => ?_⟩
rw [← h] at hx
simpa using hx
variable (A B)
/-- Transitivity of cyclotomic extensions. -/
theorem trans (C : Type w) [CommRing C] [Algebra A C] [Algebra B C] [IsScalarTower A B C]
[hS : IsCyclotomicExtension S A B] [hT : IsCyclotomicExtension T B C]
(h : Function.Injective (algebraMap B C)) : IsCyclotomicExtension (S ∪ T) A C := by
refine ⟨fun hn => ?_, fun x => ?_⟩
· intro hn'
rcases hn with hn | hn
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 hS).1 hn hn'
refine ⟨algebraMap B C b, ?_⟩
exact hb.map_of_injective h
· exact ((isCyclotomicExtension_iff _ _ _).1 hT).1 hn hn'
· refine adjoin_induction (hx := ((isCyclotomicExtension_iff T B _).1 hT).2 x)
(fun c ⟨n, hn⟩ => subset_adjoin ⟨n, Or.inr hn.1, hn.2⟩) (fun b => ?_)
(fun x y _ _ hx hy => Subalgebra.add_mem _ hx hy)
fun x y _ _ hx hy => Subalgebra.mul_mem _ hx hy
let f := IsScalarTower.toAlgHom A B C
have hb : f b ∈ (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}).map f :=
⟨b, ((isCyclotomicExtension_iff _ _ _).1 hS).2 b, rfl⟩
rw [IsScalarTower.toAlgHom_apply, ← adjoin_image] at hb
refine adjoin_mono (fun y hy => ?_) hb
obtain ⟨b₁, ⟨⟨n, hn⟩, h₁⟩⟩ := hy
exact ⟨n, ⟨mem_union_left T hn.1, hn.2.1, by rw [← h₁, ← map_pow, hn.2.2, map_one]⟩⟩
@[nontriviality]
theorem subsingleton_iff [Subsingleton B] :
IsCyclotomicExtension S A B ↔ S ⊆ {0, 1} := by
have : Subsingleton (Subalgebra A B) := inferInstance
refine ⟨fun ⟨hprim, _⟩ ↦ ?_, fun hS ↦ ?_⟩
· refine subset_pair_iff.mpr fun s hs ↦ or_iff_not_imp_left.mpr fun hs' ↦ ?_
obtain ⟨ζ, hζ⟩ := hprim hs hs'
exact mod_cast hζ.unique (IsPrimitiveRoot.of_subsingleton ζ)
· refine ⟨fun {s} hs hs' ↦ ?_, fun x ↦ by convert (mem_top (R := A) : x ∈ ⊤)⟩
· have : s = 1 := (subset_pair_iff.mp hS s hs).resolve_left hs'
exact ⟨0, this ▸ IsPrimitiveRoot.of_subsingleton 0⟩
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `S ∪ T`, then `B`
is a cyclotomic extension of `adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1 }` given by
roots of unity of order in `T`. -/
theorem union_right [h : IsCyclotomicExtension (S ∪ T) A B] :
IsCyclotomicExtension T (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}) B := by
have : {b : B | ∃ n : ℕ, n ∈ S ∪ T ∧ n ≠ 0 ∧ b ^ n = 1} =
{b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1} ∪
{b : B | ∃ n : ℕ, n ∈ T ∧ n ≠ 0 ∧ b ^ n = 1} := by
refine le_antisymm ?_ ?_
· rintro x ⟨n, hn₁ | hn₂, hnpow⟩
· left; exact ⟨n, hn₁, hnpow⟩
· right; exact ⟨n, hn₂, hnpow⟩
· rintro x (⟨n, hn⟩ | ⟨n, hn⟩)
· exact ⟨n, Or.inl hn.1, hn.2⟩
· exact ⟨n, Or.inr hn.1, hn.2⟩
refine ⟨fun hn => ((isCyclotomicExtension_iff _ A _).1 h).1 (mem_union_right S hn), fun b => ?_⟩
replace h := ((isCyclotomicExtension_iff _ _ _).1 h).2 b
rwa [this, adjoin_union_eq_adjoin_adjoin, Subalgebra.mem_restrictScalars] at h
/-- If `B` is a cyclotomic extension of `A` given by roots of unity of order in `T` and `S ⊆ T`,
then `adjoin A { b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1 }` is a cyclotomic extension of `B`
given by roots of unity of order in `S`. -/
theorem union_left [h : IsCyclotomicExtension T A B] (hS : S ⊆ T) :
IsCyclotomicExtension S A (adjoin A {b : B | ∃ a : ℕ, a ∈ S ∧ a ≠ 0 ∧ b ^ a = 1}) := by
refine ⟨fun {n} hn hn' => ?_, fun b => ?_⟩
· obtain ⟨b, hb⟩ := ((isCyclotomicExtension_iff _ _ _).1 h).1 (hS hn) hn'
refine ⟨⟨b, subset_adjoin ⟨n, hn, hn', hb.pow_eq_one⟩⟩, ?_⟩
rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk]
· convert mem_top (R := A) (x := b)
rw [← adjoin_adjoin_coe_preimage, preimage_setOf_eq]
norm_cast
variable {n S}
/-- If there exists a nonzero `s ∈ S` such that `n ∣ s`, then `IsCyclotomicExtension S A B`
implies `IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem of_union_of_dvd (h : ∃ s ∈ S, s ≠ 0 ∧ n ∣ s) [H : IsCyclotomicExtension S A B] :
IsCyclotomicExtension (S ∪ {n}) A B := by
refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs hs' ↦ ?_, ?_⟩
· rw [mem_union, mem_singleton_iff] at hs
obtain hs | rfl := hs
· exact H.exists_isPrimitiveRoot hs hs'
· obtain ⟨m, hm, hm', ⟨x, rfl⟩⟩ := h
obtain ⟨ζ, hζ⟩ := H.exists_isPrimitiveRoot hm hm'
refine ⟨ζ ^ x, ?_⟩
have h_xnz : x ≠ 0 := Nat.ne_zero_of_mul_ne_zero_right hm'
have := hζ.pow_of_dvd h_xnz (dvd_mul_left x s)
rwa [mul_div_cancel_right₀ _ h_xnz] at this
· refine _root_.eq_top_iff.2 ?_
rw [← ((iff_adjoin_eq_top S A B).1 H).2]
refine adjoin_mono fun x hx ↦ ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, hm, hm'⟩ := hx
exact ⟨m, ⟨Or.inr hm, hm'⟩⟩
/-- If there exists a nonzero `s ∈ S` such that `n ∣ s`, then `IsCyclotomicExtension S A B`
if and only if `IsCyclotomicExtension (S ∪ {n}) A B`. -/
theorem iff_union_of_dvd (h : ∃ s ∈ S, s ≠ 0 ∧ n ∣ s) :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {n}) A B := by
refine
⟨fun H ↦ of_union_of_dvd A B h, fun H => (iff_adjoin_eq_top _ A _).2
⟨fun s hs ↦ ?_, ?_⟩⟩
· exact H.exists_isPrimitiveRoot (subset_union_left hs)
· rw [_root_.eq_top_iff, ← ((iff_adjoin_eq_top _ A B).1 H).2]
refine adjoin_mono fun x hx => ?_
simp only [union_singleton, mem_insert_iff, mem_setOf_eq] at hx ⊢
obtain ⟨m, rfl | hm, hxpow⟩ := hx
· obtain ⟨y, ⟨hy, hy', ⟨z, rfl⟩⟩⟩ := h
exact ⟨_, ⟨hy, hy', by simp only [pow_mul, hxpow, one_pow]⟩⟩
· exact ⟨m, ⟨hm, hxpow⟩⟩
variable (n S)
/-- `IsCyclotomicExtension S A B` is equivalent to `IsCyclotomicExtension (S ∪ {1}) A B`. -/
theorem iff_union_singleton_one :
IsCyclotomicExtension S A B ↔ IsCyclotomicExtension (S ∪ {1}) A B := by
by_cases hS : ∃ s ∈ S, s ≠ 0
· exact iff_union_of_dvd _ _ (by simpa)
· rw [eq_self_sdiff_zero S, eq_self_sdiff_zero (S ∪ {1}), union_diff_distrib,
show S \ {0} = ∅ by aesop, empty_union, show {1} \ {0} = {1} by simp]
refine ⟨fun H ↦ ?_, fun H ↦ ?_⟩
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs _ ↦ ⟨1, by simp [mem_singleton_iff.1 hs]⟩, ?_⟩
simp [adjoin_singleton_one, empty]
· refine (iff_adjoin_eq_top _ A _).2 ⟨fun s hs ↦ (notMem_empty s hs).elim, ?_⟩
simp [singleton_one]
variable {A B}
/-- If `(⊥ : SubAlgebra A B) = ⊤`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_bot_eq_top (h : (⊥ : Subalgebra A B) = ⊤) :
IsCyclotomicExtension {1} A B := by
convert (iff_union_singleton_one _ A _).1 (singleton_zero_of_bot_eq_top h)
simp
/-- If `Function.Surjective (algebraMap A B)`, then `IsCyclotomicExtension {1} A B`. -/
theorem singleton_one_of_algebraMap_bijective (h : Function.Surjective (algebraMap A B)) :
IsCyclotomicExtension {1} A B :=
singleton_one_of_bot_eq_top (surjective_algebraMap_iff.1 h).symm
variable (A B)
/-- Given `(f : B ≃ₐ[A] C)`, if `IsCyclotomicExtension S A B` then
`IsCyclotomicExtension S A C`. -/
protected
theorem equiv {C : Type*} [CommRing C] [Algebra A C] [h : IsCyclotomicExtension S A B]
(f : B ≃ₐ[A] C) : IsCyclotomicExtension S A C := by
letI : Algebra B C := f.toAlgHom.toRingHom.toAlgebra
haveI : IsCyclotomicExtension {1} B C := singleton_one_of_algebraMap_bijective f.surjective
haveI : IsScalarTower A B C := IsScalarTower.of_algHom f.toAlgHom
exact (iff_union_singleton_one _ _ _).2 (trans S {1} A B C f.injective)
theorem neZero_of_mem [IsCyclotomicExtension S A B] [IsDomain B] (hn : n ∈ S) : NeZero (n : B) :=
(exists_isPrimitiveRoot A B hn NeZero.out).choose_spec.neZero'
theorem neZero_of_mem' [IsCyclotomicExtension S A B] [IsDomain B] (hn : n ∈ S) : NeZero (n : A) :=
(neZero_of_mem n S A B hn).nat_of_neZero (algebraMap A B)
protected
theorem neZero [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero (n : B) :=
neZero_of_mem n {n} A B (mem_singleton n)
protected
theorem neZero' [IsCyclotomicExtension {n} A B] [IsDomain B] : NeZero (n : A) :=
neZero_of_mem' n {n} A B (mem_singleton n)
/-- A cyclotomic extension is integral. -/
theorem integral [IsCyclotomicExtension S A B] : Algebra.IsIntegral A B := by
rw [← (Subalgebra.equivOfEq _ _ ((IsCyclotomicExtension.iff_adjoin_eq_top S A B).1 ‹_›).2
|>.trans Subalgebra.topEquiv).isIntegral_iff]
exact Algebra.IsIntegral.adjoin fun x ⟨n, hn, h1, h2⟩ ↦
⟨X ^ n - 1, monic_X_pow_sub_C 1 h1, by simp [h2]⟩
theorem _root_.Algebra.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot
(h : ∀ n ∈ S, n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n) :
IsCyclotomicExtension S A (adjoin A {b : B | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}) where
exists_isPrimitiveRoot {n} hn1 hn2 := by
obtain ⟨r, hr1, hr2⟩ := h n hn1 hn2
exact ⟨⟨r, subset_adjoin ⟨n, hn1, hn2, hr1⟩⟩, Subtype.val_injective hr1,
fun l hl ↦ hr2 l congr($hl.1)⟩
adjoin_roots := by
rintro ⟨x, hx⟩
induction hx using adjoin_induction with
| mem x hx =>
obtain ⟨n, hn1, hn2, hx⟩ := hx
exact subset_adjoin ⟨n, hn1, hn2, Subtype.val_injective hx⟩
| algebraMap x => exact Subalgebra.algebraMap_mem _ x
| add x y hx hy ihx ihy => exact Subalgebra.add_mem _ ihx ihy
| mul x y hx hy ihx ihy => exact Subalgebra.mul_mem _ ihx ihy
/-- Two elements in the Galois group of a cyclotomic extension are equal if
their actions on primitive roots are equal. -/
theorem algEquiv_eq_of_apply_eq [IsCyclotomicExtension S A B] [IsDomain B] {f g : B ≃ₐ[A] B}
(H : ∀ n ∈ S, n ≠ 0 → ∃ r : B, IsPrimitiveRoot r n ∧ f r = g r) : f = g := by
ext x
have hx := ‹IsCyclotomicExtension S A B›.adjoin_roots x
induction hx using Algebra.adjoin_induction with
| mem y hy =>
obtain ⟨n, hn, h1, h2⟩ := hy
obtain ⟨r, hr1, hr2⟩ := H n hn h1
have := NeZero.mk h1
obtain ⟨m, -, rfl⟩ := hr1.eq_pow_of_pow_eq_one h2
simp [hr2]
| algebraMap y => simp
| add x y hx hy ihx ihy => simp [ihx, ihy]
| mul x y hx hy ihx ihy => simp [ihx, ihy]
/-- Cyclotomic extensions are abelian. -/
theorem isMulCommutative [IsCyclotomicExtension S A B] [IsDomain B] :
IsMulCommutative (B ≃ₐ[A] B) := by
refine ⟨⟨fun f g ↦ algEquiv_eq_of_apply_eq S A B fun n hn h1 ↦ ?_⟩⟩
obtain ⟨r, hr⟩ := ‹IsCyclotomicExtension S A B›.exists_isPrimitiveRoot hn h1
use r, hr
simp only [AlgEquiv.mul_apply]
have := NeZero.mk h1
obtain ⟨mf, -, hf⟩ := hr.eq_pow_of_pow_eq_one (show f r ^ n = 1 by rw [← map_pow, hr.1, map_one])
obtain ⟨mg, -, hg⟩ := hr.eq_pow_of_pow_eq_one (show g r ^ n = 1 by rw [← map_pow, hr.1, map_one])
simp [← hf, ← hg, ← pow_mul, mul_comm mf mg]
end Basic
section Fintype
theorem finite_of_singleton [IsDomain B] [h : IsCyclotomicExtension {n} A B] :
Module.Finite A B := by
classical
rw [Module.finite_def, ← top_toSubmodule, ← ((iff_adjoin_eq_top _ _ _).1 h).2]
refine fg_adjoin_of_finite ?_ fun b ⟨n, hb⟩ => ?_
· simp only [mem_singleton_iff, exists_eq_left]
have : {b : B | n ≠ 0 ∧ b ^ n = 1} = (nthRoots n (1 : B)).toFinset :=
Set.ext fun x ↦ ⟨fun h ↦ by simpa [n.pos_of_neZero] using h.2,
fun h ↦ by simpa [n.pos_of_neZero, NeZero.ne n] using h⟩
rw [this]
exact (nthRoots n 1).toFinset.finite_toSet
· simp only [mem_singleton_iff] at hb
exact ⟨X ^ n - 1,
⟨monic_X_pow_sub_C _ (hb.1 ▸ NeZero.ne _), by simpa [sub_eq_zero] using hb.2.2⟩⟩
/-- If `S` is finite and `IsCyclotomicExtension S A B`, then `B` is a finite `A`-algebra. -/
protected theorem finite [IsDomain B] [h₁ : Finite S] [h₂ : IsCyclotomicExtension S A B] :
Module.Finite A B := by
rw [finite_coe_iff] at h₁
induction S, h₁ using Set.Finite.induction_on generalizing h₂ A B with
| empty =>
refine Module.finite_def.2 ⟨({1} : Finset B), ?_⟩
simp [← top_toSubmodule, ← empty, toSubmodule_bot, Submodule.one_eq_span]
| @insert n S _ _ H =>
by_cases hn : n = 0
· have : insert n S \ {0} = S \ {0} := by aesop
rw [eq_self_sdiff_zero, this, ← eq_self_sdiff_zero] at h₂
exact H A B
have : IsCyclotomicExtension S A (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) :=
union_left _ (insert n S) _ _ (subset_insert n S)
have := H A (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1})
have : Module.Finite (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) B := by
rw [← union_singleton] at h₂
let _ := union_right S {n} A B
have : NeZero n := ⟨hn⟩
exact finite_of_singleton n _ _
exact Module.Finite.trans (adjoin A {b : B | ∃ n : ℕ, n ∈ S ∧ n ≠ 0 ∧ b ^ n = 1}) _
/-- A cyclotomic finite extension of a number field is a number field. -/
theorem numberField [h : NumberField K] [Finite S] [IsCyclotomicExtension S K L] : NumberField L :=
{ to_charZero := charZero_of_injective_algebraMap (algebraMap K L).injective
to_finiteDimensional := by
haveI := charZero_of_injective_algebraMap (algebraMap K L).injective
haveI := IsCyclotomicExtension.finite S K L
exact Module.Finite.trans K _ }
/-- If `S` is finite and `IsCyclotomicExtension S K A`, then `finiteDimensional K A`. -/
theorem finiteDimensional (C : Type z) [Finite S] [CommRing C] [Algebra K C] [IsDomain C]
[IsCyclotomicExtension S K C] : FiniteDimensional K C :=
IsCyclotomicExtension.finite S K C
end Fintype
section
variable {A B}
theorem adjoin_roots_cyclotomic_eq_adjoin_nth_roots [IsDomain B] {ζ : B} {n : ℕ} [NeZero n]
(hζ : IsPrimitiveRoot ζ n) :
adjoin A ((cyclotomic n A).rootSet B) =
adjoin A {b : B | ∃ a : ℕ, a ∈ ({n} : Set ℕ) ∧ a ≠ 0 ∧ b ^ a = 1} := by
simp only [mem_singleton_iff, exists_eq_left]
refine le_antisymm (adjoin_mono fun x hx => ?_) (adjoin_le fun x hx => ?_)
· rw [mem_rootSet'] at hx
simp only [mem_setOf_eq]
rw [isRoot_of_unity_iff (NeZero.pos n)]
refine ⟨NeZero.ne n, n, Nat.mem_divisors_self n (NeZero.ne n), ?_⟩
rw [IsRoot.def, ← map_cyclotomic n (algebraMap A B), eval_map, ← aeval_def]
exact hx.2
· simp only [mem_setOf_eq] at hx
obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx.2
refine SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin ?_) _)
rw [mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, map_cyclotomic, ← IsRoot]
exact ⟨cyclotomic_ne_zero n B, hζ.isRoot_cyclotomic (NeZero.pos n)⟩
theorem adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic {n : ℕ} [NeZero n] [IsDomain B] {ζ : B}
(hζ : IsPrimitiveRoot ζ n) : adjoin A ((cyclotomic n A).rootSet B) = adjoin A {ζ} := by
refine le_antisymm (adjoin_le fun x hx => ?_) (adjoin_mono fun x hx => ?_)
· suffices hx : x ^ n = 1 by
obtain ⟨i, _, rfl⟩ := hζ.eq_pow_of_pow_eq_one hx
exact SetLike.mem_coe.2 (Subalgebra.pow_mem _ (subset_adjoin <| mem_singleton ζ) _)
refine (isRoot_of_unity_iff (NeZero.pos n) B).2 ?_
refine ⟨n, Nat.mem_divisors_self n (NeZero.ne n), ?_⟩
rw [mem_rootSet', aeval_def, ← eval_map, map_cyclotomic, ← IsRoot] at hx
exact hx.2
· simp only [mem_singleton_iff] at hx
simpa only [hx, mem_rootSet', map_cyclotomic, aeval_def, ← eval_map, IsRoot] using
And.intro (cyclotomic_ne_zero n B) (hζ.isRoot_cyclotomic (NeZero.pos n))
theorem adjoin_primitive_root_eq_top {n : ℕ} [NeZero n] [IsDomain B]
[h : IsCyclotomicExtension {n} A B]
{ζ : B} (hζ : IsPrimitiveRoot ζ n) : adjoin A ({ζ} : Set B) = ⊤ := by
classical
rw [← adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic hζ]
rw [adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ]
exact ((iff_adjoin_eq_top {n} A B).mp h).2
variable (A)
theorem _root_.IsPrimitiveRoot.adjoin_isCyclotomicExtension {ζ : B} {n : ℕ} [NeZero n]
(h : IsPrimitiveRoot ζ n) : IsCyclotomicExtension {n} A (adjoin A ({ζ} : Set B)) :=
{ exists_isPrimitiveRoot := fun hi hi' => by
rw [Set.mem_singleton_iff] at hi
refine ⟨⟨ζ, subset_adjoin <| Set.mem_singleton ζ⟩, ?_⟩
rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk, hi]
adjoin_roots := fun ⟨x, hx⟩ => by
refine
adjoin_induction
(hx := hx) (fun b hb => ?_) (fun a => ?_) (fun b₁ b₂ _ _ hb₁ hb₂ => ?_)
(fun b₁ b₂ _ _ hb₁ hb₂ => ?_)
· rw [Set.mem_singleton_iff] at hb
refine subset_adjoin ?_
simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq, hb]
rw [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk]
exact ⟨NeZero.ne n, ((IsPrimitiveRoot.iff_def ζ n).1 h).1⟩
· exact Subalgebra.algebraMap_mem _ _
· exact Subalgebra.add_mem _ hb₁ hb₂
· exact Subalgebra.mul_mem _ hb₁ hb₂ }
variable {L} in
theorem _root_.IsPrimitiveRoot.intermediateField_adjoin_isCyclotomicExtension
[Algebra.IsIntegral K L] {n : ℕ} [NeZero n] {ζ : L} (hζ : IsPrimitiveRoot ζ n) :
IsCyclotomicExtension {n} K (IntermediateField.adjoin K {ζ}) := by
change IsCyclotomicExtension {n} K (IntermediateField.adjoin K {ζ}).toSubalgebra
rw [IntermediateField.adjoin_simple_toSubalgebra_of_integral (IsIntegral.isIntegral ζ)]
exact hζ.adjoin_isCyclotomicExtension K
end
section Field
variable {n S}
/-- A cyclotomic extension splits `X ^ n - 1` if `n ∈ S`. -/
theorem splits_X_pow_sub_one [H : IsCyclotomicExtension S K L] (hS : n ∈ S) :
Splits (algebraMap K L) (X ^ n - 1) := by
rw [← splits_id_iff_splits, Polynomial.map_sub, Polynomial.map_one, Polynomial.map_pow,
Polynomial.map_X]
obtain ⟨z, hz⟩ := ((isCyclotomicExtension_iff _ _ _).1 H).1 hS (NeZero.ne _)
exact X_pow_sub_one_splits hz
/-- A cyclotomic extension splits `cyclotomic n K` if `n ∈ S`. -/
theorem splits_cyclotomic [IsCyclotomicExtension S K L] (hS : n ∈ S) :
Splits (algebraMap K L) (cyclotomic n K) := by
refine splits_of_splits_of_dvd _ (X_pow_sub_C_ne_zero (NeZero.pos _) _)
(splits_X_pow_sub_one K L hS) ?_
use ∏ i ∈ n.properDivisors, Polynomial.cyclotomic i K
rw [(eq_cyclotomic_iff (NeZero.pos _) _).1 rfl, RingHom.map_one]
variable (n S)
theorem _root_.IntermediateField.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot
(h : ∀ n ∈ S, n ≠ 0 → ∃ r : L, IsPrimitiveRoot r n) :
IsCyclotomicExtension S K
(IntermediateField.adjoin K {b : L | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}) := by
have key : ∀ b ∈ {b : L | ∃ n ∈ S, n ≠ 0 ∧ b ^ n = 1}, IsAlgebraic K b := by
rintro b ⟨n, hn, h1, h2⟩
exact ⟨X ^ n - 1, (monic_X_pow_sub_C (1 : K) h1).ne_zero, by simp [h2]⟩
change IsCyclotomicExtension S K (IntermediateField.toSubalgebra _)
rw [congr(IsCyclotomicExtension S K $(IntermediateField.adjoin_algebraic_toSubalgebra key))]
exact Algebra.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot S K L h
theorem isSeparable [IsCyclotomicExtension S K L] : Algebra.IsSeparable K L := by
have := integral S K L
have h := (IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_› |>.2
rw [← IntermediateField.adjoin_algebraic_toSubalgebra
fun b _ ↦ Algebra.IsAlgebraic.isAlgebraic b, ← IntermediateField.top_toSubalgebra] at h
rw [← AlgEquiv.Algebra.isSeparable_iff <|
(IntermediateField.equivOfEq (IntermediateField.toSubalgebra_injective h)).trans
IntermediateField.topEquiv, IntermediateField.isSeparable_adjoin_iff_isSeparable]
rintro b ⟨n, hn, h1, h2⟩
have := NeZero.mk h1
have := Polynomial.X_pow_sub_one_separable_iff.2 (neZero_of_mem' n S K L hn).out
exact this.of_dvd <| minpoly.dvd K b <| by simp [h2]
theorem nonempty_algEquiv_adjoin_of_isSepClosed [IsCyclotomicExtension S K L]
(M : Type*) [Field M] [Algebra K M] [IsSepClosed M] :
Nonempty (L ≃ₐ[K] IntermediateField.adjoin K {x : M | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) := by
have := isSeparable S K L
let i : L →ₐ[K] M := IsSepClosed.lift
refine ⟨(show L ≃ₐ[K] i.fieldRange from AlgEquiv.ofInjectiveField i).trans
(IntermediateField.equivOfEq (le_antisymm ?_ ?_))⟩
· rintro x (hx : x ∈ i.range)
let e := Subalgebra.equivOfEq _ _ ((IsCyclotomicExtension.iff_adjoin_eq_top S K L).1 ‹_›).2
|>.trans Subalgebra.topEquiv
have hrange : i.range = (i.comp (AlgHomClass.toAlgHom e)).range := by
ext x
simp only [AlgHom.mem_range, AlgHom.coe_comp, AlgHom.coe_coe, Function.comp_apply]
constructor
· rintro ⟨y, rfl⟩; exact ⟨e.symm y, by simp⟩
· rintro ⟨y, rfl⟩; exact ⟨e y, rfl⟩
rw [hrange, AlgHom.mem_range] at hx
obtain ⟨⟨y, hy⟩, rfl⟩ := hx
induction hy using Algebra.adjoin_induction with
| mem x hx =>
obtain ⟨n, hn, h1, h2⟩ := hx
apply IntermediateField.subset_adjoin
use n, hn, h1
rw [← map_pow, ← map_one (i.comp (AlgHomClass.toAlgHom e))]
congr 1
apply_fun _ using Subtype.val_injective
simpa
| algebraMap x =>
convert IntermediateField.algebraMap_mem _ x
exact AlgHom.commutes _ x
| add x y hx hy ihx ihy =>
convert add_mem ihx ihy
exact map_add (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
| mul x y hx hy ihx ihy =>
convert mul_mem ihx ihy
exact map_mul (i.comp (AlgHomClass.toAlgHom e)) ⟨x, hx⟩ ⟨y, hy⟩
· rw [IntermediateField.adjoin_le_iff]
rintro x ⟨n, hn, h1, h2⟩
have := NeZero.mk h1
obtain ⟨y, hy⟩ := exists_isPrimitiveRoot K L hn h1
obtain ⟨m, -, rfl⟩ := (hy.map_of_injective (f := i) i.injective).eq_pow_of_pow_eq_one h2
exact ⟨y ^ m, by simp⟩
theorem isGalois [IsCyclotomicExtension S K L] : IsGalois K L := by
rw [isGalois_iff]
use isSeparable S K L
obtain ⟨i⟩ := nonempty_algEquiv_adjoin_of_isSepClosed S K L (AlgebraicClosure K)
rw [i.transfer_normal, IntermediateField.normal_iff_forall_map_le]
intro f x hx
rw [← IntermediateField.mem_toSubalgebra, IntermediateField.toSubalgebra_map,
Subalgebra.mem_map] at hx
obtain ⟨y, hy, rfl⟩ := hx
rw [IntermediateField.mem_toSubalgebra] at hy
induction hy using IntermediateField.adjoin_induction with
| mem x hx =>
obtain ⟨n, hn, h1, h2⟩ := hx
apply IntermediateField.subset_adjoin
use n, hn, h1
rw [← map_pow, ← map_one f, h2]
| algebraMap x =>
convert IntermediateField.algebraMap_mem _ x
exact AlgHom.commutes _ x
| add x y hx hy ihx ihy =>
rw [map_add]
exact add_mem ihx ihy
| mul x y hx hy ihx ihy =>
rw [map_mul]
exact mul_mem ihx ihy
| inv x hx ihx =>
rw [map_inv₀]
exact inv_mem ihx
/-- Any two `S`-cyclotomic extensions are isomorphic. -/
noncomputable def algEquiv [IsCyclotomicExtension S K L]
(L' : Type*) [Field L'] [Algebra K L'] [IsCyclotomicExtension S K L'] : L ≃ₐ[K] L' :=
(nonempty_algEquiv_adjoin_of_isSepClosed S K L (AlgebraicClosure K)).some.trans
(nonempty_algEquiv_adjoin_of_isSepClosed S K L' (AlgebraicClosure K)).some.symm
theorem nonempty_algEquiv_adjoin_of_exists_isPrimitiveRoot [IsCyclotomicExtension S K L]
(M : Type*) [Field M] [Algebra K M] (h : ∀ n ∈ S, n ≠ 0 → ∃ r : M, IsPrimitiveRoot r n) :
Nonempty (L ≃ₐ[K] IntermediateField.adjoin K {x : M | ∃ n ∈ S, n ≠ 0 ∧ x ^ n = 1}) :=
have := IntermediateField.isCyclotomicExtension_adjoin_of_exists_isPrimitiveRoot S K M h
⟨algEquiv S K L _⟩
section Singleton
variable [IsCyclotomicExtension {n} K L]
/-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `X ^ n - 1`. -/
theorem isSplittingField_X_pow_sub_one : IsSplittingField K L (X ^ n - 1) :=
{ splits' := splits_X_pow_sub_one K L (mem_singleton n)
adjoin_rootSet' := by
rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2]
congr
refine Set.ext fun x => ?_
simp only [mem_singleton_iff, ne_eq, exists_eq_left, NeZero.ne, not_false_eq_true, true_and,
mem_setOf_eq]
simp only [mem_rootSet', map_sub, map_pow, aeval_one, aeval_X, sub_eq_zero, map_X,
and_iff_right_iff_imp, Polynomial.map_sub, Polynomial.map_pow, Polynomial.map_one]
exact fun _ => X_pow_sub_C_ne_zero (NeZero.pos n) (1 : L) }
scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.isSplittingField_X_pow_sub_one
/-- If `IsCyclotomicExtension {n} K L`, then `L` is the splitting field of `cyclotomic n K`. -/
theorem splitting_field_cyclotomic : IsSplittingField K L (cyclotomic n K) :=
{ splits' := splits_cyclotomic K L (mem_singleton n)
adjoin_rootSet' := by
rw [← ((iff_adjoin_eq_top {n} K L).1 inferInstance).2]
letI := Classical.decEq L
obtain ⟨ζ : L, hζ⟩ :=
IsCyclotomicExtension.exists_isPrimitiveRoot K L (mem_singleton n) (NeZero.ne _)
exact adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ }
scoped[Cyclotomic] attribute [instance] IsCyclotomicExtension.splitting_field_cyclotomic
end Singleton
end Field
end IsCyclotomicExtension
section CyclotomicField
/-- Given a nonzero `n : ℕ` and a field `K`, we define `CyclotomicField n K` as the
splitting field of `cyclotomic n K`. If `n` is nonzero in `K`, it has
the instance `IsCyclotomicExtension {n} K (CyclotomicField n K)`. -/
def CyclotomicField : Type w :=
(cyclotomic n K).SplittingField
namespace CyclotomicField
instance : Field (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance algebra : Algebra K (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance : Inhabited (CyclotomicField n K) := by
delta CyclotomicField; infer_instance
instance [CharZero K] : CharZero (CyclotomicField n K) :=
charZero_of_injective_algebraMap (algebraMap K _).injective
instance isCyclotomicExtension [NeZero (n : K)] :
IsCyclotomicExtension {n} K (CyclotomicField n K) := by
have : NeZero (n : CyclotomicField n K) :=
NeZero.nat_of_injective (algebraMap K _).injective
letI := Classical.decEq (CyclotomicField n K)
obtain ⟨ζ, hζ⟩ :=
exists_root_of_splits (algebraMap K (CyclotomicField n K)) (SplittingField.splits _)
(degree_cyclotomic_pos n K (NeZero.pos n)).ne'
rw [← eval_map, ← IsRoot.def, map_cyclotomic, isRoot_cyclotomic_iff] at hζ
refine ⟨?_, ?_⟩
· simp only [mem_singleton_iff, forall_eq]
exact fun _ ↦ ⟨ζ, hζ⟩
· rw [← Algebra.eq_top_iff, ← SplittingField.adjoin_rootSet, eq_comm]
exact IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots hζ
instance [NumberField K] : NumberField (CyclotomicField n K) :=
IsCyclotomicExtension.numberField {n} K _
end CyclotomicField
end CyclotomicField
section IsDomain
variable [Algebra A K]
section CyclotomicRing
/-- If `K` is an `A`-algebra, the `A`-algebra structure on `CyclotomicField n K`.
-/
instance CyclotomicField.algebraBase : Algebra A (CyclotomicField n K) :=
SplittingField.instAlgebra (cyclotomic n K)
/-- Ensure there are no diamonds when `A = ℤ` but there are `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906 -/
example : Ring.toIntAlgebra (CyclotomicField n ℚ) = CyclotomicField.algebraBase _ _ _ := rfl
instance {R : Type*} [CommRing R] [Algebra R K] : IsScalarTower R K (CyclotomicField n K) :=
SplittingField.instIsScalarTower _
instance [IsFractionRing A K] : NoZeroSMulDivisors A (CyclotomicField n K) := by
rw [NoZeroSMulDivisors.iff_faithfulSMul, faithfulSMul_iff_algebraMap_injective,
IsScalarTower.algebraMap_eq A K (CyclotomicField n K)]
exact
(Function.Injective.comp (FaithfulSMul.algebraMap_injective K (CyclotomicField n K))
(IsFractionRing.injective A K) :)
/-- If `A` is a domain with fraction field `K` and `n : ℕ`, we define `CyclotomicRing n A K` as
the `A`-subalgebra of `CyclotomicField n K` generated by the roots of `X ^ n - 1`. If `n`
is nonzero in `A`, it has the instance `IsCyclotomicExtension {n} A (CyclotomicRing n A K)`. -/
@[nolint unusedArguments]
def CyclotomicRing : Type w :=
adjoin A {b : CyclotomicField n K | b ^ n = 1}
namespace CyclotomicRing
instance : CommRing (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
instance : IsDomain (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
instance : Inhabited (CyclotomicRing n A K) := by
delta CyclotomicRing; infer_instance
/-- The `A`-algebra structure on `CyclotomicRing n A K`. -/
instance algebraBase : Algebra A (CyclotomicRing n A K) :=
(adjoin A _).algebra
-- Ensure that there is no diamonds with ℤ.
-- but there is at `reducible_and_instances` https://github.com/leanprover-community/mathlib4/issues/10906
example {n : ℕ} : CyclotomicRing.algebraBase n ℤ ℚ = Ring.toIntAlgebra _ := rfl
instance [IsFractionRing A K] :
NoZeroSMulDivisors A (CyclotomicRing n A K) :=
(adjoin A _).noZeroSMulDivisors_bot
omit [NeZero n] in
theorem algebraBase_injective [IsFractionRing A K] :
Function.Injective <| algebraMap A (CyclotomicRing n A K) :=
FaithfulSMul.algebraMap_injective _ _
instance : Algebra (CyclotomicRing n A K) (CyclotomicField n K) :=
(adjoin A _).toAlgebra
omit [NeZero n] in
theorem adjoin_algebra_injective :
Function.Injective <| algebraMap (CyclotomicRing n A K) (CyclotomicField n K) :=
Subtype.val_injective
instance : NoZeroSMulDivisors (CyclotomicRing n A K) (CyclotomicField n K) :=
NoZeroSMulDivisors.iff_algebraMap_injective.mpr (adjoin_algebra_injective n A K)
instance : IsScalarTower A (CyclotomicRing n A K) (CyclotomicField n K) :=
IsScalarTower.subalgebra' _ _ _ _
instance isCyclotomicExtension [IsFractionRing A K] [NeZero ((n : ℕ) : A)] :
IsCyclotomicExtension {n} A (CyclotomicRing n A K) where
exists_isPrimitiveRoot {a} han _ := by
rw [mem_singleton_iff] at han
subst a
have := NeZero.of_faithfulSMul A K n
have := NeZero.of_faithfulSMul A (CyclotomicField n K) n
obtain ⟨μ, hμ⟩ := (CyclotomicField.isCyclotomicExtension n K).exists_isPrimitiveRoot
(mem_singleton n) (NeZero.ne n)
refine ⟨⟨μ, subset_adjoin ?_⟩, ?_⟩
· apply (isRoot_of_unity_iff (NeZero.pos n) (CyclotomicField n K)).mpr
refine ⟨n, Nat.mem_divisors_self _ (NeZero.ne n), ?_⟩
rwa [← isRoot_cyclotomic_iff] at hμ
· rwa [← IsPrimitiveRoot.coe_submonoidClass_iff, Subtype.coe_mk]
adjoin_roots x := by
obtain ⟨x, hx⟩ := x
refine
adjoin_induction (fun y hy => ?_) (fun a => ?_) (fun y z _ _ hy hz => ?_)
(fun y z _ _ hy hz => ?_) hx
· refine subset_adjoin ?_
simp only [mem_singleton_iff, exists_eq_left, mem_setOf_eq]
exact ⟨NeZero.ne n, by rwa [← Subalgebra.coe_eq_one, Subalgebra.coe_pow, Subtype.coe_mk]⟩
· exact Subalgebra.algebraMap_mem _ a
· exact Subalgebra.add_mem _ hy hz
· exact Subalgebra.mul_mem _ hy hz
instance [IsFractionRing A K] [IsDomain A] [NeZero (n : A)] :
IsFractionRing (CyclotomicRing n A K) (CyclotomicField n K) where
map_units' := fun ⟨x, hx⟩ => by
rw [isUnit_iff_ne_zero]
apply map_ne_zero_of_mem_nonZeroDivisors
· apply adjoin_algebra_injective
· exact hx
surj' x := by
have : NeZero (n : K) := NeZero.nat_of_injective (IsFractionRing.injective A K)
refine
Algebra.adjoin_induction
(hx := ((IsCyclotomicExtension.iff_singleton n K (CyclotomicField n K)).1
(CyclotomicField.isCyclotomicExtension n K)).2 x)
(fun y hy => ?_) (fun k => ?_) ?_ ?_
· exact ⟨⟨⟨y, subset_adjoin hy⟩, 1⟩, by simp; rfl⟩
· have : IsLocalization (nonZeroDivisors A) K := inferInstance
replace := this.surj
obtain ⟨⟨z, w⟩, hw⟩ := this k
refine ⟨⟨algebraMap A (CyclotomicRing n A K) z, algebraMap A (CyclotomicRing n A K) w,
map_mem_nonZeroDivisors _ (algebraBase_injective n A K) w.2⟩, ?_⟩
letI : IsScalarTower A K (CyclotomicField n K) :=
IsScalarTower.of_algebraMap_eq (congr_fun rfl)
rw [← IsScalarTower.algebraMap_apply, ← IsScalarTower.algebraMap_apply,
@IsScalarTower.algebraMap_apply A K _ _ _ _ _ (_root_.CyclotomicField.algebra n K) _ _ w,
← RingHom.map_mul, hw, ← IsScalarTower.algebraMap_apply]
· rintro y z - - ⟨a, ha⟩ ⟨b, hb⟩
refine ⟨⟨a.1 * b.2 + b.1 * a.2, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩
rw [RingHom.map_mul, add_mul, ← mul_assoc, ha,
mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, hb]
simp only [map_add, map_mul]
· rintro y z - - ⟨a, ha⟩ ⟨b, hb⟩
refine ⟨⟨a.1 * b.1, a.2 * b.2, mul_mem_nonZeroDivisors.2 ⟨a.2.2, b.2.2⟩⟩, ?_⟩
rw [RingHom.map_mul, mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), mul_assoc, ←
mul_assoc z, hb, ← mul_comm ((algebraMap (CyclotomicRing n A K) _) ↑a.2), ← mul_assoc, ha]
simp only [map_mul]
exists_of_eq {x y} h := ⟨1, by rw [adjoin_algebra_injective n A K h]⟩
theorem eq_adjoin_primitive_root {μ : CyclotomicField n K} (h : IsPrimitiveRoot μ n) :
CyclotomicRing n A K = adjoin A ({μ} : Set (CyclotomicField n K)) := by
rw [← IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_root_cyclotomic h,
IsCyclotomicExtension.adjoin_roots_cyclotomic_eq_adjoin_nth_roots h]
simp [CyclotomicRing, NeZero.ne n]
end CyclotomicRing
end CyclotomicRing
end IsDomain
-- TODO: move to suitable place
theorem Polynomial.separable_cyclotomic (n : ℕ) (K : Type*) [Field K] [NeZero (n : K)] :
(cyclotomic n K).Separable :=
.of_dvd (separable_X_pow_sub_C 1 NeZero.out one_ne_zero) (cyclotomic.dvd_X_pow_sub_one n K)
section IsSepClosed
variable [IsSepClosed K]
/-- Separably closed fields are `S`-cyclotomic extensions over themselves if
`NeZero ((a : ℕ) : K)` for all nonzero `a ∈ S`. -/
theorem IsSepClosed.isCyclotomicExtension (h : ∀ a ∈ S, a ≠ 0 → NeZero (a : K)) :
IsCyclotomicExtension S K K := by
refine ⟨fun {a} ha ha' ↦ ?_, Algebra.eq_top_iff.mp <| Subsingleton.elim _ _⟩
have := h a ha ha'
obtain ⟨r, hr⟩ := IsSepClosed.exists_aeval_eq_zero K _
(degree_cyclotomic_pos a K (Nat.pos_of_ne_zero ha')).ne' (separable_cyclotomic a K)
exact ⟨r, by rwa [coe_aeval_eq_eval, ← IsRoot.def, isRoot_cyclotomic_iff] at hr⟩
@[deprecated (since := "2025-06-22")]
alias IsAlgClosed.isCyclotomicExtension := IsSepClosed.isCyclotomicExtension
instance IsSepClosedOfCharZero.isCyclotomicExtension [CharZero K] :
∀ S, IsCyclotomicExtension S K K := fun S => by
rw [IsCyclotomicExtension.eq_self_sdiff_zero]
exact IsSepClosed.isCyclotomicExtension _ K fun _ _ h ↦ ⟨Nat.cast_ne_zero.mpr h⟩
@[deprecated (since := "2025-06-22")]
alias IsAlgClosedOfCharZero.isCyclotomicExtension := IsSepClosedOfCharZero.isCyclotomicExtension
end IsSepClosed
|
finset.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 div seq.
From mathcomp Require Import choice fintype finfun bigop.
(******************************************************************************)
(* This file defines a type for sets over a finite Type, similar to the type *)
(* of functions over a finite Type defined in finfun.v (indeed, based in it): *)
(* {set T} where T must have a finType structure. *)
(* We equip {set T} itself with a finType structure, hence Leibnitz and *)
(* extensional equalities coincide on {set T}, and we can form {set {set T}}. *)
(* If A, B : {set T} and P : {set {set T}}, we define: *)
(* x \in A == x belongs to A (i.e., {set T} implements predType, *)
(* by coercion to pred_sort) *)
(* mem A == the predicate corresponding to A *)
(* finset p == the set corresponding to a predicate p *)
(* [set x | P] == the set containing the x such that P is true (x may *)
(* appear in P) *)
(* [set x | P & Q] := [set x | P && Q] *)
(* [set x in A] == the set containing the x in a collective predicate A *)
(* [set x in A | P] == the set containing the x in A such that P is true *)
(* [set x in A | P & Q] := [set x in A | P && Q] *)
(* All these have typed variants [set x : T | P], [set x : T in A], etc. *)
(* set0 == the empty set *)
(* [set: T] or setT == the full set (the A containing all x : T) *)
(* [set x] == the singleton {x} *)
(* [set~ x] == the complement of the singleton {x} *)
(* [set:: s] == the set spanned by the sequence s *)
(* [set a1; a2;...; an] := a1 |: [set a2] :|: ... :|: [set an] *)
(* A :|: B == the union of A and B *)
(* x |: A == A with the element x added (:= [set x] :|: A) *)
(* A :&: B == the intersection of A and B *)
(* ~: A == the complement of A *)
(* A :\: B == the difference A minus B *)
(* A :\ x == A with the element x removed (:= A :\: [set x]) *)
(* \bigcup_<range> A == the union of all A, for i in <range> (i is bound in *)
(* A, see bigop.v) *)
(* \bigcap_<range> A == the intersection of all A, for i in <range> *)
(* cover P == the union of the set of sets P *)
(* trivIset P <=> the elements of P are pairwise disjoint *)
(* partition P A <=> P is a partition of A *)
(* pblock P x == a block of P containing x, or else set0 *)
(* equivalence_partition R D == the partition induced on D by the relation R *)
(* (provided R is an equivalence relation in D) *)
(* preim_partition f D == the partition induced on D by the equivalence *)
(* [rel x y | f x == f y] *)
(* is_transversal X P D <=> X is a transversal of the partition P of D *)
(* transversal P D == a transversal of P, provided P is a partition of D *)
(* transversal_repr x0 X B == a representative of B \in P selected by the *)
(* transversal X of P, or else x0 *)
(* powerset A == the set of all subset of the set A *)
(* P ::&: A == those sets in P that are subsets of the set A *)
(* setX A1 A2 == cartesian product of A1 and A2 *)
(* := [set u | u.1 \in A1 & u.2 \in A2] *)
(* setXn I f A == indexed cartesian product of *)
(* A : forall i : I, {set f i} *)
(* f @^-1: A == the preimage of the collective predicate A under f *)
(* f @: A == the image set of the collective predicate A by f *)
(* f @2:(A, B) == the image set of A x B by the binary function f *)
(* [set E | x in A] == the set of all the values of the expression E, for x *)
(* drawn from the collective predicate A *)
(* [set E | x in A & P] == the set of values of E for x drawn from A, such *)
(* that P is true *)
(* [set E | x in A, y in B] == the set of values of E for x drawn from A and *)
(* and y drawn from B; B may depend on x *)
(* [set E | x in A, y in B & P] == the set of values of E for x drawn from A *)
(* y drawn from B, such that P is true *)
(* [set E | x : T] == the set of all values of E, with x in type T *)
(* [set E | x : T & P] == the set of values of E for x : T s.t. P is true *)
(* [set E | x : T, y : U in B], [set E | x : T, y : U in B & P], *)
(* [set E | x : T in A, y : U], [set E | x : T in A, y : U & P], *)
(* [set E | x : T, y : U], [set E | x : T, y : U & P] *)
(* == type-ranging versions of the binary comprehensions *)
(* [set E | x : T in A], [set E | x in A, y], [set E | x, y & P], etc. *)
(* == typed and untyped variants of the comprehensions above*)
(* The types may be required as type inference processes *)
(* E before considering A or B. Note that type casts in *)
(* the binary comprehension must either be both present *)
(* or absent and that there are no untyped variants for *)
(* single-type comprehension as Coq parsing confuses *)
(* [x | P] and [E | x]. *)
(* minset p A == A is a minimal set satisfying p *)
(* maxset p A == A is a maximal set satisfying p *)
(* unset1 A == [pick x in A] if #|A| == 1, else None *)
(* fprod_pick I T_ p == pick a function of type (forall i : I, T_ i) provided *)
(* a proof p of 0 < #|fprod I T_| is given *)
(* ftagged I T_ p f i == untag (fprod_pick I T_ p) i (fun x=>x) (f i), useful *)
(* to lift f : {ffun I -> {i : I & T_ i}} (akin to FProd's building blocks) *)
(* to a vanilla dependent function of type (forall i : I, T_ i). *)
(* Provided a monotonous function F : {set T} -> {set T}, we get fixpoints *)
(* fixset F := iter #|T| F set0 *)
(* == the least fixpoint of F *)
(* == the minimal set such that F X == X *)
(* fix_order F x == the minimum number of iterations so that *)
(* x is in iter (fix_order F x) F set0 *)
(* funsetC F := fun X => ~: F (~: X) *)
(* cofixset F == the greatest fixpoint of F *)
(* == the maximal set such that F X == X *)
(* := ~: fixset (funsetC F) *)
(* We also provide notations A :=: B, A :<>: B, A :==: B, A :!=: B, A :=P: B *)
(* that specialize A = B, A <> B, A == B, etc., to {set _}. This is useful *)
(* for subtypes of {set T}, such as {group T}, that coerce to {set T}. *)
(* We give many lemmas on these operations, on card, and on set inclusion. *)
(* In addition to the standard suffixes described in ssrbool.v, we associate *)
(* the following suffixes to set operations: *)
(* 0 -- the empty set, as in in_set0 : (x \in set0) = false *)
(* T -- the full set, as in in_setT : x \in [set: T] *)
(* 1 -- a singleton set, as in in_set1 : (x \in [set a]) = (x == a) *)
(* 2 -- an unordered pair, as in *)
(* in_set2 : (x \in [set a; b]) = (x == a) || (x == b) *)
(* C -- complement, as in setCK : ~: ~: A = A *)
(* I -- intersection, as in setIid : A :&: A = A *)
(* U -- union, as in setUid : A :|: A = A *)
(* D -- difference, as in setDv : A :\: A = set0 *)
(* S -- a subset argument, as in *)
(* setIS: B \subset C -> A :&: B \subset A :&: C *)
(* These suffixes are sometimes preceded with an `s' to distinguish them from *)
(* their basic ssrbool interpretation, e.g., *)
(* card1 : #|pred1 x| = 1 and cards1 : #|[set x]| = 1 *)
(* We also use a trailing `r' to distinguish a right-hand complement from *)
(* commutativity, e.g., *)
(* setIC : A :&: B = B :&: A and setICr : A :&: ~: A = set0. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope set_scope.
Section SetType.
Variable T : finType.
Inductive set_type : predArgType := FinSet of {ffun pred T}.
Definition finfun_of_set A := let: FinSet f := A in f.
Definition set_of := set_type.
Identity Coercion type_of_set_of : set_of >-> set_type.
Definition set_isSub := Eval hnf in [isNew for finfun_of_set].
HB.instance Definition _ := set_isSub.
HB.instance Definition _ := [Finite of set_type by <:].
End SetType.
Delimit Scope set_scope with SET.
Bind Scope set_scope with set_type.
Bind Scope set_scope with set_of.
Open Scope set_scope.
Arguments set_of T%_type.
Arguments finfun_of_set {T} A%_SET.
Notation "{ 'set' T }" := (set_of T) (format "{ 'set' T }") : type_scope.
(* We later define several subtypes that coerce to set; for these it is *)
(* preferable to state equalities at the {set _} level, even when comparing *)
(* subtype values, because the primitive "injection" tactic tends to diverge *)
(* on complex types (e.g., quotient groups). We provide some parse-only *)
(* notation to make this technicality less obstructive. *)
Notation "A :=: B" := (A = B :> {set _})
(at level 70, no associativity, only parsing) : set_scope.
Notation "A :<>: B" := (A <> B :> {set _})
(at level 70, no associativity, only parsing) : set_scope.
Notation "A :==: B" := (A == B :> {set _})
(at level 70, no associativity, only parsing) : set_scope.
Notation "A :!=: B" := (A != B :> {set _})
(at level 70, no associativity, only parsing) : set_scope.
Notation "A :=P: B" := (A =P B :> {set _})
(at level 70, no associativity, only parsing) : set_scope.
HB.lock
Definition finset (T : finType) (P : pred T) : {set T} := @FinSet T (finfun P).
Canonical finset_unlock := Unlockable finset.unlock.
(* The weird type of pred_of_set is imposed by the syntactic restrictions on *)
(* coercion declarations; it is unfortunately not possible to use a functor *)
(* to retype the declaration, because this triggers an ugly bug in the Coq *)
(* coercion chaining code. *)
HB.lock
Definition pred_of_set T (A : set_type T) : fin_pred_sort (predPredType T)
:= val A.
Canonical pred_of_set_unlock := Unlockable pred_of_set.unlock.
Notation "[ 'set' x : T | P ]" := (finset (fun x : T => P%B))
(x at level 99, only parsing) : set_scope.
Notation "[ 'set' x | P ]" := [set x : _ | P]
(P at level 99, format "[ 'set' x | P ]") : set_scope.
Notation "[ 'set' x 'in' A ]" := [set x | x \in A]
(format "[ 'set' x 'in' A ]") : set_scope.
Notation "[ 'set' x : T 'in' A ]" := [set x : T | x \in A]
(only parsing) : set_scope.
Notation "[ 'set' x : T | P & Q ]" := [set x : T | P && Q]
(only parsing) : set_scope.
Notation "[ 'set' x | P & Q ]" := [set x | P && Q ]
(P at level 99, format "[ 'set' x | P & Q ]") : set_scope.
Notation "[ 'set' x : T 'in' A | P ]" := [set x : T | x \in A & P]
(only parsing) : set_scope.
Notation "[ 'set' x 'in' A | P ]" := [set x | x \in A & P]
(format "[ 'set' x 'in' A | P ]") : set_scope.
Notation "[ 'set' x 'in' A | P & Q ]" := [set x in A | P && Q]
(format "[ 'set' x 'in' A | P & Q ]") : set_scope.
Notation "[ 'set' x : T 'in' A | P & Q ]" := [set x : T in A | P && Q]
(only parsing) : set_scope.
Notation "[ 'set' :: s ]" := (finset [in pred_of_seq s])
(format "[ 'set' :: s ]") : set_scope.
(* This lets us use set and subtypes of set, like group or coset_of, both as *)
(* collective predicates and as arguments of the \pi(_) notation. *)
Coercion pred_of_set: set_type >-> fin_pred_sort.
(* Declare pred_of_set as a canonical instance of topred, but use the *)
(* coercion to resolve mem A to @mem (predPredType T) (pred_of_set A). *)
Canonical set_predType T := @PredType _ (unkeyed (set_type T)) (@pred_of_set T).
Section BasicSetTheory.
Variable T : finType.
Implicit Types (x : T) (A B : {set T}) (pA : pred T).
HB.instance Definition _ := Finite.on {set T}.
Lemma in_set pA x : x \in finset pA = pA x.
Proof. by rewrite [@finset]unlock unlock [x \in _]ffunE. Qed.
Lemma setP A B : A =i B <-> A = B.
Proof.
by split=> [eqAB|-> //]; apply/val_inj/ffunP=> x; have:= eqAB x; rewrite unlock.
Qed.
Definition set0 := [set x : T | false].
Definition setTfor := [set x : T | true].
Lemma in_setT x : x \in setTfor.
Proof. by rewrite in_set. Qed.
Lemma eqsVneq A B : eq_xor_neq A B (B == A) (A == B).
Proof. exact: eqVneq. Qed.
Lemma eq_finset (pA pB : pred T) : pA =1 pB -> finset pA = finset pB.
Proof. by move=> eq_p; apply/setP => x; rewrite !(in_set, inE) eq_p. Qed.
End BasicSetTheory.
Arguments eqsVneq {T} A B, {T A B}.
Arguments set0 {T}.
Arguments setTfor T%_type.
Arguments eq_finset {T} [pA] pB eq_pAB.
#[global] Hint Resolve in_setT : core.
Notation "[ 'set' : T ]" := (setTfor T) (format "[ 'set' : T ]") : set_scope.
Notation setT := [set: _] (only parsing).
HB.lock
Definition set1 (T : finType) (a : T) := [set x | x == a].
Section setOpsDefs.
Variable T : finType.
Implicit Types (a x : T) (A B D : {set T}) (P : {set {set T}}).
Definition setU A B := [set x | (x \in A) || (x \in B)].
Definition setI A B := [set x in A | x \in B].
Definition setC A := [set x | x \notin A].
Definition setD A B := [set x | x \notin B & x \in A].
Definition ssetI P D := [set A in P | A \subset D].
Definition powerset D := [set A : {set T} | A \subset D].
End setOpsDefs.
Notation "[ 'set' a ]" := (set1 a)
(a at level 99, format "[ 'set' a ]") : set_scope.
Notation "[ 'set' a : T ]" := [set (a : T)]
(a at level 99, format "[ 'set' a : T ]") : set_scope.
Notation "A :|: B" := (setU A B) : set_scope.
Notation "a |: A" := ([set a] :|: A) : set_scope.
(* This is left-associative due to historical limitations of the .. Notation. *)
Notation "[ 'set' a1 ; a2 ; .. ; an ]" := (setU .. (a1 |: [set a2]) .. [set an])
(format "[ 'set' a1 ; a2 ; .. ; an ]") : set_scope.
Notation "A :&: B" := (setI A B) : set_scope.
Notation "~: A" := (setC A) (at level 35, right associativity) : set_scope.
Notation "[ 'set' ~ a ]" := (~: [set a])
(format "[ 'set' ~ a ]") : set_scope.
Notation "A :\: B" := (setD A B) : set_scope.
Notation "A :\ a" := (A :\: [set a]) : set_scope.
Notation "P ::&: D" := (ssetI P D) (at level 48) : set_scope.
Section setOps.
Variable T : finType.
Implicit Types (a x : T) (A B C D : {set T}) (pA pB pC : pred T).
Lemma eqEsubset A B : (A == B) = (A \subset B) && (B \subset A).
Proof. by apply/eqP/subset_eqP=> /setP. Qed.
Lemma subEproper A B : A \subset B = (A == B) || (A \proper B).
Proof. by rewrite eqEsubset -andb_orr orbN andbT. Qed.
Lemma eqVproper A B : A \subset B -> A = B \/ A \proper B.
Proof. by rewrite subEproper => /predU1P. Qed.
Lemma properEneq A B : A \proper B = (A != B) && (A \subset B).
Proof. by rewrite andbC eqEsubset negb_and andb_orr andbN. Qed.
Lemma proper_neq A B : A \proper B -> A != B.
Proof. by rewrite properEneq; case/andP. Qed.
Lemma eqEproper A B : (A == B) = (A \subset B) && ~~ (A \proper B).
Proof. by rewrite negb_and negbK andb_orr andbN eqEsubset. Qed.
Lemma eqEcard A B : (A == B) = (A \subset B) && (#|B| <= #|A|).
Proof.
rewrite eqEsubset; apply: andb_id2l => sAB.
by rewrite (geq_leqif (subset_leqif_card sAB)).
Qed.
Lemma properEcard A B : (A \proper B) = (A \subset B) && (#|A| < #|B|).
Proof. by rewrite properEneq ltnNge andbC eqEcard; case: (A \subset B). Qed.
Lemma subset_leqif_cards A B : A \subset B -> (#|A| <= #|B| ?= iff (A == B)).
Proof. by move=> sAB; rewrite eqEsubset sAB; apply: subset_leqif_card. Qed.
Lemma in_set0 x : x \in set0 = false.
Proof. by rewrite in_set. Qed.
Lemma sub0set A : set0 \subset A.
Proof. by apply/subsetP=> x; rewrite in_set. Qed.
Lemma subset0 A : (A \subset set0) = (A == set0).
Proof. by rewrite eqEsubset sub0set andbT. Qed.
Lemma proper0 A : (set0 \proper A) = (A != set0).
Proof. by rewrite properE sub0set subset0. Qed.
Lemma subset_neq0 A B : A \subset B -> A != set0 -> B != set0.
Proof. by rewrite -!proper0 => sAB /proper_sub_trans->. Qed.
Lemma set_0Vmem A : (A = set0) + {x : T | x \in A}.
Proof.
case: (pickP (mem A)) => [x Ax | A0]; [by right; exists x | left].
by apply/setP=> x; rewrite in_set; apply: A0.
Qed.
Lemma set_enum A : [set x | x \in enum A] = A.
Proof. by apply/setP => x; rewrite in_set mem_enum. Qed.
Lemma enum_set0 : enum set0 = [::] :> seq T.
Proof. by rewrite (eq_enum (in_set _)) enum0. Qed.
Lemma subsetT A : A \subset setT.
Proof. by apply/subsetP=> x; rewrite in_set. Qed.
Lemma subsetT_hint mA : subset mA (mem [set: T]).
Proof. by rewrite unlock; apply/pred0P=> x; rewrite !inE in_set. Qed.
Hint Resolve subsetT_hint : core.
Lemma subTset A : (setT \subset A) = (A == setT).
Proof. by rewrite eqEsubset subsetT. Qed.
Lemma properT A : (A \proper setT) = (A != setT).
Proof. by rewrite properEneq subsetT andbT. Qed.
Lemma set1P x a : reflect (x = a) (x \in [set a]).
Proof. by rewrite set1.unlock in_set; apply: eqP. Qed.
Lemma enum_setT : enum [set: T] = Finite.enum T.
Proof. by rewrite (eq_enum (in_set _)) enumT. Qed.
Lemma in_set1 x a : (x \in [set a]) = (x == a).
Proof. by rewrite set1.unlock in_set. Qed.
Definition inE := (in_set, in_set1, inE).
Lemma set11 x : x \in [set x].
Proof. by rewrite !inE. Qed.
Lemma set1_inj : injective (@set1 T).
Proof. by move=> a b eqsab; apply/set1P; rewrite -eqsab set11. Qed.
Lemma enum_set1 a : enum [set a] = [:: a].
Proof. by rewrite set1.unlock (eq_enum (in_set _)) enum1. Qed.
Lemma setU1P x a B : reflect (x = a \/ x \in B) (x \in a |: B).
Proof. by rewrite !inE; apply: predU1P. Qed.
Lemma in_setU1 x a B : (x \in a |: B) = (x == a) || (x \in B).
Proof. by rewrite !inE. Qed.
Lemma set_nil : [set:: nil] = @set0 T. Proof. by rewrite -enum_set0 set_enum. Qed.
Lemma set_seq1 a : [set:: [:: a]] = [set a].
Proof. by rewrite -enum_set1 set_enum. Qed.
Lemma set_cons a s : [set:: a :: s] = a |: [set:: s].
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma setU11 x B : x \in x |: B.
Proof. by rewrite !inE eqxx. Qed.
Lemma setU1r x a B : x \in B -> x \in a |: B.
Proof. by move=> Bx; rewrite !inE predU1r. Qed.
(* We need separate lemmas for the explicit enumerations since they *)
(* associate on the left. *)
Lemma set1Ul x A b : x \in A -> x \in A :|: [set b].
Proof. by move=> Ax; rewrite !inE Ax. Qed.
Lemma set1Ur A b : b \in A :|: [set b].
Proof. by rewrite !inE eqxx orbT. Qed.
Lemma in_setC1 x a : (x \in [set~ a]) = (x != a).
Proof. by rewrite !inE. Qed.
Lemma setC11 x : (x \in [set~ x]) = false.
Proof. by rewrite !inE eqxx. Qed.
Lemma setD1P x A b : reflect (x != b /\ x \in A) (x \in A :\ b).
Proof. by rewrite !inE; apply: andP. Qed.
Lemma in_setD1 x A b : (x \in A :\ b) = (x != b) && (x \in A) .
Proof. by rewrite !inE. Qed.
Lemma setD11 b A : (b \in A :\ b) = false.
Proof. by rewrite !inE eqxx. Qed.
Lemma setD1K a A : a \in A -> a |: (A :\ a) = A.
Proof. by move=> Aa; apply/setP=> x /[!inE]; case: eqP => // ->. Qed.
Lemma setU1K a B : a \notin B -> (a |: B) :\ a = B.
Proof.
by move/negPf=> nBa; apply/setP=> x /[!inE]; case: eqP => // ->.
Qed.
Lemma set2P x a b : reflect (x = a \/ x = b) (x \in [set a; b]).
Proof. by rewrite !inE; apply: pred2P. Qed.
Lemma in_set2 x a b : (x \in [set a; b]) = (x == a) || (x == b).
Proof. by rewrite !inE. Qed.
Lemma set21 a b : a \in [set a; b].
Proof. by rewrite !inE eqxx. Qed.
Lemma set22 a b : b \in [set a; b].
Proof. by rewrite !inE eqxx orbT. Qed.
Lemma setUP x A B : reflect (x \in A \/ x \in B) (x \in A :|: B).
Proof. by rewrite !inE; apply: orP. Qed.
Lemma in_setU x A B : (x \in A :|: B) = (x \in A) || (x \in B).
Proof. exact: in_set. Qed.
Lemma setUC A B : A :|: B = B :|: A.
Proof. by apply/setP => x; rewrite !inE orbC. Qed.
Lemma setUS A B C : A \subset B -> C :|: A \subset C :|: B.
Proof.
move=> sAB; apply/subsetP=> x; rewrite !inE.
by case: (x \in C) => //; apply: (subsetP sAB).
Qed.
Lemma setSU A B C : A \subset B -> A :|: C \subset B :|: C.
Proof. by move=> sAB; rewrite -!(setUC C) setUS. Qed.
Lemma setUSS A B C D : A \subset C -> B \subset D -> A :|: B \subset C :|: D.
Proof. by move=> /(setSU B) /subset_trans sAC /(setUS C)/sAC. Qed.
Lemma set0U A : set0 :|: A = A.
Proof. by apply/setP => x; rewrite !inE orFb. Qed.
Lemma setU0 A : A :|: set0 = A.
Proof. by rewrite setUC set0U. Qed.
Lemma setUA A B C : A :|: (B :|: C) = A :|: B :|: C.
Proof. by apply/setP => x; rewrite !inE orbA. Qed.
Lemma setUCA A B C : A :|: (B :|: C) = B :|: (A :|: C).
Proof. by rewrite !setUA (setUC B). Qed.
Lemma setUAC A B C : A :|: B :|: C = A :|: C :|: B.
Proof. by rewrite -!setUA (setUC B). Qed.
Lemma setUACA A B C D : (A :|: B) :|: (C :|: D) = (A :|: C) :|: (B :|: D).
Proof. by rewrite -!setUA (setUCA B). Qed.
Lemma setTU A : setT :|: A = setT.
Proof. by apply/setP => x; rewrite !inE orTb. Qed.
Lemma setUT A : A :|: setT = setT.
Proof. by rewrite setUC setTU. Qed.
Lemma setUid A : A :|: A = A.
Proof. by apply/setP=> x; rewrite inE orbb. Qed.
Lemma setUUl A B C : A :|: B :|: C = (A :|: C) :|: (B :|: C).
Proof. by rewrite setUA !(setUAC _ C) -(setUA _ C) setUid. Qed.
Lemma setUUr A B C : A :|: (B :|: C) = (A :|: B) :|: (A :|: C).
Proof. by rewrite !(setUC A) setUUl. Qed.
(* intersection *)
(* setIdP is a generalisation of setIP that applies to comprehensions. *)
Lemma setIdP x pA pB : reflect (pA x /\ pB x) (x \in [set y | pA y & pB y]).
Proof. by rewrite !inE; apply: andP. Qed.
Lemma setId2P x pA pB pC :
reflect [/\ pA x, pB x & pC x] (x \in [set y | pA y & pB y && pC y]).
Proof. by rewrite !inE; apply: and3P. Qed.
Lemma setIdE A pB : [set x in A | pB x] = A :&: [set x | pB x].
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma setIP x A B : reflect (x \in A /\ x \in B) (x \in A :&: B).
Proof. exact: (iffP (@setIdP _ _ _)). Qed.
Lemma in_setI x A B : (x \in A :&: B) = (x \in A) && (x \in B).
Proof. exact: in_set. Qed.
Lemma setIC A B : A :&: B = B :&: A.
Proof. by apply/setP => x; rewrite !inE andbC. Qed.
Lemma setIS A B C : A \subset B -> C :&: A \subset C :&: B.
Proof.
move=> sAB; apply/subsetP=> x; rewrite !inE.
by case: (x \in C) => //; apply: (subsetP sAB).
Qed.
Lemma setSI A B C : A \subset B -> A :&: C \subset B :&: C.
Proof. by move=> sAB; rewrite -!(setIC C) setIS. Qed.
Lemma setISS A B C D : A \subset C -> B \subset D -> A :&: B \subset C :&: D.
Proof. by move=> /(setSI B) /subset_trans sAC /(setIS C) /sAC. Qed.
Lemma setTI A : setT :&: A = A.
Proof. by apply/setP => x; rewrite !inE andTb. Qed.
Lemma setIT A : A :&: setT = A.
Proof. by rewrite setIC setTI. Qed.
Lemma set0I A : set0 :&: A = set0.
Proof. by apply/setP => x; rewrite !inE andFb. Qed.
Lemma setI0 A : A :&: set0 = set0.
Proof. by rewrite setIC set0I. Qed.
Lemma setIA A B C : A :&: (B :&: C) = A :&: B :&: C.
Proof. by apply/setP=> x; rewrite !inE andbA. Qed.
Lemma setICA A B C : A :&: (B :&: C) = B :&: (A :&: C).
Proof. by rewrite !setIA (setIC A). Qed.
Lemma setIAC A B C : A :&: B :&: C = A :&: C :&: B.
Proof. by rewrite -!setIA (setIC B). Qed.
Lemma setIACA A B C D : (A :&: B) :&: (C :&: D) = (A :&: C) :&: (B :&: D).
Proof. by rewrite -!setIA (setICA B). Qed.
Lemma setIid A : A :&: A = A.
Proof. by apply/setP=> x; rewrite inE andbb. Qed.
Lemma setIIl A B C : A :&: B :&: C = (A :&: C) :&: (B :&: C).
Proof. by rewrite setIA !(setIAC _ C) -(setIA _ C) setIid. Qed.
Lemma setIIr A B C : A :&: (B :&: C) = (A :&: B) :&: (A :&: C).
Proof. by rewrite !(setIC A) setIIl. Qed.
(* distribute /cancel *)
Lemma setIUr A B C : A :&: (B :|: C) = (A :&: B) :|: (A :&: C).
Proof. by apply/setP=> x; rewrite !inE andb_orr. Qed.
Lemma setIUl A B C : (A :|: B) :&: C = (A :&: C) :|: (B :&: C).
Proof. by apply/setP=> x; rewrite !inE andb_orl. Qed.
Lemma setUIr A B C : A :|: (B :&: C) = (A :|: B) :&: (A :|: C).
Proof. by apply/setP=> x; rewrite !inE orb_andr. Qed.
Lemma setUIl A B C : (A :&: B) :|: C = (A :|: C) :&: (B :|: C).
Proof. by apply/setP=> x; rewrite !inE orb_andl. Qed.
Lemma setUK A B : (A :|: B) :&: A = A.
Proof. by apply/setP=> x; rewrite !inE orbK. Qed.
Lemma setKU A B : A :&: (B :|: A) = A.
Proof. by apply/setP=> x; rewrite !inE orKb. Qed.
Lemma setIK A B : (A :&: B) :|: A = A.
Proof. by apply/setP=> x; rewrite !inE andbK. Qed.
Lemma setKI A B : A :|: (B :&: A) = A.
Proof. by apply/setP=> x; rewrite !inE andKb. Qed.
(* complement *)
Lemma setCP x A : reflect (~ x \in A) (x \in ~: A).
Proof. by rewrite !inE; apply: negP. Qed.
Lemma in_setC x A : (x \in ~: A) = (x \notin A).
Proof. exact: in_set. Qed.
Lemma setCK : involutive (@setC T).
Proof. by move=> A; apply/setP=> x; rewrite !inE negbK. Qed.
Lemma setC_inj : injective (@setC T).
Proof. exact: can_inj setCK. Qed.
Lemma subsets_disjoint A B : (A \subset B) = [disjoint A & ~: B].
Proof. by rewrite subset_disjoint; apply: eq_disjoint_r => x; rewrite !inE. Qed.
Lemma disjoints_subset A B : [disjoint A & B] = (A \subset ~: B).
Proof. by rewrite subsets_disjoint setCK. Qed.
Lemma powersetCE A B : (A \in powerset (~: B)) = [disjoint A & B].
Proof. by rewrite inE disjoints_subset. Qed.
Lemma setCS A B : (~: A \subset ~: B) = (B \subset A).
Proof. by rewrite !subsets_disjoint setCK disjoint_sym. Qed.
Lemma setCU A B : ~: (A :|: B) = ~: A :&: ~: B.
Proof. by apply/setP=> x; rewrite !inE negb_or. Qed.
Lemma setCI A B : ~: (A :&: B) = ~: A :|: ~: B.
Proof. by apply/setP=> x; rewrite !inE negb_and. Qed.
Lemma setUCr A : A :|: ~: A = setT.
Proof. by apply/setP=> x; rewrite !inE orbN. Qed.
Lemma setICr A : A :&: ~: A = set0.
Proof. by apply/setP=> x; rewrite !inE andbN. Qed.
Lemma setC0 : ~: set0 = [set: T].
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma setCT : ~: [set: T] = set0.
Proof. by rewrite -setC0 setCK. Qed.
Lemma properC A B : (~: B \proper ~: A) = (A \proper B).
Proof. by rewrite !properE !setCS. Qed.
(* difference *)
Lemma setDP A B x : reflect (x \in A /\ x \notin B) (x \in A :\: B).
Proof. by rewrite inE andbC; apply: andP. Qed.
Lemma in_setD A B x : (x \in A :\: B) = (x \notin B) && (x \in A).
Proof. exact: in_set. Qed.
Lemma setDE A B : A :\: B = A :&: ~: B.
Proof. by apply/setP => x; rewrite !inE andbC. Qed.
Lemma setSD A B C : A \subset B -> A :\: C \subset B :\: C.
Proof. by rewrite !setDE; apply: setSI. Qed.
Lemma setDS A B C : A \subset B -> C :\: B \subset C :\: A.
Proof. by rewrite !setDE -setCS; apply: setIS. Qed.
Lemma setDSS A B C D : A \subset C -> D \subset B -> A :\: B \subset C :\: D.
Proof. by move=> /(setSD B) /subset_trans sAC /(setDS C) /sAC. Qed.
Lemma setD0 A : A :\: set0 = A.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma set0D A : set0 :\: A = set0.
Proof. by apply/setP=> x; rewrite !inE andbF. Qed.
Lemma setDT A : A :\: setT = set0.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma setTD A : setT :\: A = ~: A.
Proof. by apply/setP=> x; rewrite !inE andbT. Qed.
Lemma setDv A : A :\: A = set0.
Proof. by apply/setP=> x; rewrite !inE andNb. Qed.
Lemma setCD A B : ~: (A :\: B) = ~: A :|: B.
Proof. by rewrite !setDE setCI setCK. Qed.
Lemma setID A B : A :&: B :|: A :\: B = A.
Proof. by rewrite setDE -setIUr setUCr setIT. Qed.
Lemma setDUl A B C : (A :|: B) :\: C = (A :\: C) :|: (B :\: C).
Proof. by rewrite !setDE setIUl. Qed.
Lemma setDUr A B C : A :\: (B :|: C) = (A :\: B) :&: (A :\: C).
Proof. by rewrite !setDE setCU setIIr. Qed.
Lemma setDIl A B C : (A :&: B) :\: C = (A :\: C) :&: (B :\: C).
Proof. by rewrite !setDE setIIl. Qed.
Lemma setIDA A B C : A :&: (B :\: C) = (A :&: B) :\: C.
Proof. by rewrite !setDE setIA. Qed.
Lemma setIDAC A B C : (A :\: B) :&: C = (A :&: C) :\: B.
Proof. by rewrite !setDE setIAC. Qed.
Lemma setDIr A B C : A :\: (B :&: C) = (A :\: B) :|: (A :\: C).
Proof. by rewrite !setDE setCI setIUr. Qed.
Lemma setDDl A B C : (A :\: B) :\: C = A :\: (B :|: C).
Proof. by rewrite !setDE setCU setIA. Qed.
Lemma setDDr A B C : A :\: (B :\: C) = (A :\: B) :|: (A :&: C).
Proof. by rewrite !setDE setCI setIUr setCK. Qed.
(* powerset *)
Lemma powersetE A B : (A \in powerset B) = (A \subset B).
Proof. by rewrite inE. Qed.
Lemma powersetS A B : (powerset A \subset powerset B) = (A \subset B).
Proof.
apply/subsetP/idP=> [sAB | sAB C /[!inE]/subset_trans->//].
by rewrite -powersetE sAB // inE.
Qed.
Lemma powerset0 : powerset set0 = [set set0] :> {set {set T}}.
Proof. by apply/setP=> A; rewrite set1.unlock !inE subset0. Qed.
Lemma powersetT : powerset [set: T] = [set: {set T}].
Proof. by apply/setP=> A; rewrite !inE subsetT. Qed.
Lemma setI_powerset P A : P :&: powerset A = P ::&: A.
Proof. by apply/setP=> B; rewrite !inE. Qed.
(* cardinal lemmas for sets *)
Lemma cardsE pA : #|[set x in pA]| = #|pA|.
Proof. exact/eq_card/in_set. Qed.
Lemma sum1dep_card pA : \sum_(x | pA x) 1 = #|[set x | pA x]|.
Proof. by rewrite sum1_card cardsE. Qed.
Lemma sum_nat_cond_const pA n : \sum_(x | pA x) n = #|[set x | pA x]| * n.
Proof. by rewrite sum_nat_const cardsE. Qed.
Lemma cards0 : #|@set0 T| = 0.
Proof. by rewrite cardsE card0. Qed.
Lemma cards_eq0 A : (#|A| == 0) = (A == set0).
Proof. by rewrite (eq_sym A) eqEcard sub0set cards0 leqn0. Qed.
Lemma set0Pn A : reflect (exists x, x \in A) (A != set0).
Proof. by rewrite -cards_eq0; apply: existsP. Qed.
Lemma set0_Nexists A : (A == set0) = ~~ [exists x, x \in A].
Proof. by rewrite -(sameP (set0Pn _) existsP) negbK. Qed.
Lemma card_gt0 A : (0 < #|A|) = (A != set0).
Proof. by rewrite lt0n cards_eq0. Qed.
Lemma cards0_eq A : #|A| = 0 -> A = set0.
Proof. by move=> A_0; apply/setP=> x; rewrite inE (card0_eq A_0). Qed.
Lemma cards1 x : #|[set x]| = 1.
Proof. by rewrite set1.unlock cardsE card1. Qed.
Lemma cardsUI A B : #|A :|: B| + #|A :&: B| = #|A| + #|B|.
Proof. by rewrite !cardsE cardUI. Qed.
Lemma cardsU A B : #|A :|: B| = #|A| + #|B| - #|A :&: B|.
Proof. by rewrite -cardsUI addnK. Qed.
Lemma cardsI A B : #|A :&: B| = #|A| + #|B| - #|A :|: B|.
Proof. by rewrite -cardsUI addKn. Qed.
Lemma cardsT : #|[set: T]| = #|T|.
Proof. by rewrite cardsE. Qed.
Lemma cardsID B A : #|A :&: B| + #|A :\: B| = #|A|.
Proof. by rewrite !cardsE cardID. Qed.
Lemma cardsD A B : #|A :\: B| = #|A| - #|A :&: B|.
Proof. by rewrite -(cardsID B A) addKn. Qed.
Lemma cardsC A : #|A| + #|~: A| = #|T|.
Proof. by rewrite cardsE cardC. Qed.
Lemma cardsCs A : #|A| = #|T| - #|~: A|.
Proof. by rewrite -(cardsC A) addnK. Qed.
Lemma cardsU1 a A : #|a |: A| = (a \notin A) + #|A|.
Proof. by rewrite -cardU1; apply: eq_card=> x; rewrite !inE. Qed.
Lemma cards2 a b : #|[set a; b]| = (a != b).+1.
Proof. by rewrite -card2; apply: eq_card=> x; rewrite !inE. Qed.
Lemma cardsC1 a : #|[set~ a]| = #|T|.-1.
Proof. by rewrite -(cardC1 a); apply: eq_card=> x; rewrite !inE. Qed.
Lemma cardsD1 a A : #|A| = (a \in A) + #|A :\ a|.
Proof.
by rewrite (cardD1 a); congr (_ + _); apply: eq_card => x; rewrite !inE.
Qed.
(* other inclusions *)
Lemma subsetIl A B : A :&: B \subset A.
Proof. by apply/subsetP=> x /[!inE] /andP[]. Qed.
Lemma subsetIr A B : A :&: B \subset B.
Proof. by apply/subsetP=> x /[!inE] /andP[]. Qed.
Lemma subsetUl A B : A \subset A :|: B.
Proof. by apply/subsetP=> x /[!inE] ->. Qed.
Lemma subsetUr A B : B \subset A :|: B.
Proof. by apply/subsetP=> x; rewrite inE orbC => ->. Qed.
Lemma subsetU1 x A : A \subset x |: A.
Proof. exact: subsetUr. Qed.
Lemma subsetDl A B : A :\: B \subset A.
Proof. by rewrite setDE subsetIl. Qed.
Lemma subD1set A x : A :\ x \subset A.
Proof. by rewrite subsetDl. Qed.
Lemma subsetDr A B : A :\: B \subset ~: B.
Proof. by rewrite setDE subsetIr. Qed.
Lemma sub1set A x : ([set x] \subset A) = (x \in A).
Proof. by rewrite -subset_pred1; apply: eq_subset=> y; rewrite !inE. Qed.
Variant cards_eq_spec A : seq T -> {set T} -> nat -> Type :=
| CardEq (s : seq T) & uniq s : cards_eq_spec A s [set x | x \in s] (size s).
Lemma cards_eqP A : cards_eq_spec A (enum A) A #|A|.
Proof.
by move: (enum A) (cardE A) (set_enum A) (enum_uniq A) => s -> <-; constructor.
Qed.
Lemma cards1P A : reflect (exists x, A = [set x]) (#|A| == 1).
Proof.
apply: (iffP idP) => [|[x ->]]; last by rewrite cards1.
by have [[|x []]// _] := cards_eqP; exists x; apply/setP => y; rewrite !inE.
Qed.
Lemma cards2P A : reflect (exists x y : T, x != y /\ A = [set x; y])
(#|A| == 2).
Proof.
apply: (iffP idP) => [|[x] [y] [xy ->]]; last by rewrite cards2 xy.
have [[|x [|y []]]//=] := cards_eqP; rewrite !inE andbT => neq_xy.
by exists x, y; split=> //; apply/setP => z; rewrite !inE.
Qed.
Lemma subset1 A x : (A \subset [set x]) = (A == [set x]) || (A == set0).
Proof.
rewrite eqEcard cards1 -cards_eq0 orbC andbC.
by case: posnP => // A0; rewrite (cards0_eq A0) sub0set.
Qed.
Lemma powerset1 x : powerset [set x] = [set set0; [set x]].
Proof. by apply/setP=> A; rewrite inE subset1 orbC set1.unlock !inE. Qed.
Lemma setIidPl A B : reflect (A :&: B = A) (A \subset B).
Proof.
apply: (iffP subsetP) => [sAB | <- x /setIP[] //].
by apply/setP=> x /[1!inE]; apply/andb_idr/sAB.
Qed.
Arguments setIidPl {A B}.
Lemma setIidPr A B : reflect (A :&: B = B) (B \subset A).
Proof. by rewrite setIC; apply: setIidPl. Qed.
Lemma cardsDS A B : B \subset A -> #|A :\: B| = #|A| - #|B|.
Proof. by rewrite cardsD => /setIidPr->. Qed.
Lemma setUidPl A B : reflect (A :|: B = A) (B \subset A).
Proof.
by rewrite -setCS (sameP setIidPl eqP) -setCU (inj_eq setC_inj); apply: eqP.
Qed.
Lemma setUidPr A B : reflect (A :|: B = B) (A \subset B).
Proof. by rewrite setUC; apply: setUidPl. Qed.
Lemma setDidPl A B : reflect (A :\: B = A) [disjoint A & B].
Proof. by rewrite setDE disjoints_subset; apply: setIidPl. Qed.
Lemma subIset A B C : (B \subset A) || (C \subset A) -> (B :&: C \subset A).
Proof. by case/orP; apply: subset_trans; rewrite (subsetIl, subsetIr). Qed.
Lemma subsetI A B C : (A \subset B :&: C) = (A \subset B) && (A \subset C).
Proof.
rewrite !(sameP setIidPl eqP) setIA; have [-> //|] := eqVneq (A :&: B) A.
by apply: contraNF => /eqP <-; rewrite -setIA -setIIl setIAC.
Qed.
Lemma subsetIP A B C : reflect (A \subset B /\ A \subset C) (A \subset B :&: C).
Proof. by rewrite subsetI; apply: andP. Qed.
Lemma subsetIidl A B : (A \subset A :&: B) = (A \subset B).
Proof. by rewrite subsetI subxx. Qed.
Lemma subsetIidr A B : (B \subset A :&: B) = (B \subset A).
Proof. by rewrite setIC subsetIidl. Qed.
Lemma powersetI A B : powerset (A :&: B) = powerset A :&: powerset B.
Proof. by apply/setP=> C; rewrite !inE subsetI. Qed.
Lemma subUset A B C : (B :|: C \subset A) = (B \subset A) && (C \subset A).
Proof. by rewrite -setCS setCU subsetI !setCS. Qed.
Lemma subsetU A B C : (A \subset B) || (A \subset C) -> A \subset B :|: C.
Proof. by rewrite -!(setCS _ A) setCU; apply: subIset. Qed.
Lemma subUsetP A B C : reflect (A \subset C /\ B \subset C) (A :|: B \subset C).
Proof. by rewrite subUset; apply: andP. Qed.
Lemma subsetC A B : (A \subset ~: B) = (B \subset ~: A).
Proof. by rewrite -setCS setCK. Qed.
Lemma subCset A B : (~: A \subset B) = (~: B \subset A).
Proof. by rewrite -setCS setCK. Qed.
Lemma subsetD A B C : (A \subset B :\: C) = (A \subset B) && [disjoint A & C].
Proof. by rewrite setDE subsetI -disjoints_subset. Qed.
Lemma subDset A B C : (A :\: B \subset C) = (A \subset B :|: C).
Proof.
apply/subsetP/subsetP=> sABC x; rewrite !inE.
by case Bx: (x \in B) => // Ax; rewrite sABC ?inE ?Bx.
by case Bx: (x \in B) => // /sABC; rewrite inE Bx.
Qed.
Lemma subsetDP A B C :
reflect (A \subset B /\ [disjoint A & C]) (A \subset B :\: C).
Proof. by rewrite subsetD; apply: andP. Qed.
Lemma setU_eq0 A B : (A :|: B == set0) = (A == set0) && (B == set0).
Proof. by rewrite -!subset0 subUset. Qed.
Lemma setD_eq0 A B : (A :\: B == set0) = (A \subset B).
Proof. by rewrite -subset0 subDset setU0. Qed.
Lemma setI_eq0 A B : (A :&: B == set0) = [disjoint A & B].
Proof. by rewrite disjoints_subset -setD_eq0 setDE setCK. Qed.
Lemma eq0_subset B A : (A == set0) = (A \subset B) && (A \subset ~: B).
Proof. by rewrite -subsetI setICr subset0. Qed.
Lemma disjoint_setI0 A B : [disjoint A & B] -> A :&: B = set0.
Proof. by rewrite -setI_eq0; move/eqP. Qed.
Lemma subsetC_disjoint A B : [disjoint A & B] ->
forall C, C != set0 -> C \subset A -> ~~ (C \subset B).
Proof.
move=> dAB C + CA; apply: contra_neqN => CB.
by apply/eqP; rewrite -subset0 -(disjoint_setI0 dAB) subsetI CA CB.
Qed.
Lemma disjoints1 A x : [disjoint [set x] & A] = (x \notin A).
Proof. by rewrite (@eq_disjoint1 _ x) // => y; rewrite !inE. Qed.
Lemma subsetD1 A B x : (A \subset B :\ x) = (A \subset B) && (x \notin A).
Proof. by rewrite setDE subsetI subsetC sub1set inE. Qed.
Lemma subsetD1P A B x : reflect (A \subset B /\ x \notin A) (A \subset B :\ x).
Proof. by rewrite subsetD1; apply: andP. Qed.
Lemma properD1 A x : x \in A -> A :\ x \proper A.
Proof.
move=> Ax; rewrite properE subsetDl; apply/subsetPn; exists x=> //.
by rewrite in_setD1 Ax eqxx.
Qed.
Lemma properIr A B : ~~ (B \subset A) -> A :&: B \proper B.
Proof. by move=> nsAB; rewrite properE subsetIr subsetI negb_and nsAB. Qed.
Lemma properIl A B : ~~ (A \subset B) -> A :&: B \proper A.
Proof. by move=> nsBA; rewrite properE subsetIl subsetI negb_and nsBA orbT. Qed.
Lemma properUr A B : ~~ (A \subset B) -> B \proper A :|: B.
Proof. by rewrite properE subsetUr subUset subxx /= andbT. Qed.
Lemma properUl A B : ~~ (B \subset A) -> A \proper A :|: B.
Proof. by move=> not_sBA; rewrite setUC properUr. Qed.
Lemma proper1set A x : ([set x] \proper A) -> (x \in A).
Proof. by move/proper_sub; rewrite sub1set. Qed.
Lemma properIset A B C : (B \proper A) || (C \proper A) -> (B :&: C \proper A).
Proof. by case/orP; apply: sub_proper_trans; rewrite (subsetIl, subsetIr). Qed.
Lemma properI A B C : (A \proper B :&: C) -> (A \proper B) && (A \proper C).
Proof.
move=> pAI; apply/andP.
by split; apply: (proper_sub_trans pAI); rewrite (subsetIl, subsetIr).
Qed.
Lemma properU A B C : (B :|: C \proper A) -> (B \proper A) && (C \proper A).
Proof.
move=> pUA; apply/andP.
by split; apply: sub_proper_trans pUA; rewrite (subsetUr, subsetUl).
Qed.
Lemma properD A B C : (A \proper B :\: C) -> (A \proper B) && [disjoint A & C].
Proof. by rewrite setDE disjoints_subset => /properI/andP[-> /proper_sub]. Qed.
Lemma properCr A B : (A \proper ~: B) = (B \proper ~: A).
Proof. by rewrite -properC setCK. Qed.
Lemma properCl A B : (~: A \proper B) = (~: B \proper A).
Proof. by rewrite -properC setCK. Qed.
(* relationship with seq *)
Lemma enum_setU A B : perm_eq (enum (A :|: B)) (undup (enum A ++ enum B)).
Proof.
apply: uniq_perm; rewrite ?enum_uniq ?undup_uniq//.
by move=> i; rewrite mem_undup mem_enum inE mem_cat !mem_enum.
Qed.
Lemma enum_setI A B : perm_eq (enum (A :&: B)) (filter [in B] (enum A)).
Proof.
apply: uniq_perm; rewrite ?enum_uniq// 1?filter_uniq// ?enum_uniq//.
by move=> x; rewrite /= mem_enum mem_filter inE mem_enum andbC.
Qed.
Lemma has_set1 pA A a : has pA (enum [set a]) = pA a.
Proof. by rewrite enum_set1 has_seq1. Qed.
Lemma has_setU pA A B :
has pA (enum (A :|: B)) = (has pA (enum A)) || (has pA (enum B)).
Proof. by rewrite (perm_has _ (enum_setU _ _)) has_undup has_cat. Qed.
Lemma all_set1 pA A a : all pA (enum [set a]) = pA a.
Proof. by rewrite enum_set1 all_seq1. Qed.
Lemma all_setU pA A B :
all pA (enum (A :|: B)) = (all pA (enum A)) && (all pA (enum B)).
Proof. by rewrite (perm_all _ (enum_setU _ _)) all_undup all_cat. Qed.
End setOps.
Arguments set1P {T x a}.
Arguments set1_inj {T} [x1 x2].
Arguments set2P {T x a b}.
Arguments setIdP {T x pA pB}.
Arguments setIP {T x A B}.
Arguments setU1P {T x a B}.
Arguments setD1P {T x A b}.
Arguments setUP {T x A B}.
Arguments setDP {T A B x}.
Arguments cards1P {T A}.
Arguments setCP {T x A}.
Arguments setIidPl {T A B}.
Arguments setIidPr {T A B}.
Arguments setUidPl {T A B}.
Arguments setUidPr {T A B}.
Arguments setDidPl {T A B}.
Arguments subsetIP {T A B C}.
Arguments subUsetP {T A B C}.
Arguments subsetDP {T A B C}.
Arguments subsetD1P {T A B x}.
Prenex Implicits set1.
#[global] Hint Extern 0 (is_true (subset _ (mem (pred_of_set (setTfor _))))) =>
solve [apply: subsetT_hint] : core.
Section setOpsAlgebra.
Import Monoid.
Variable T : finType.
HB.instance Definition _ := isComLaw.Build {set T} [set: T] (@setI T)
(@setIA T) (@setIC T) (@setTI T).
HB.instance Definition _ := isMulLaw.Build {set T} set0 (@setI T)
(@set0I T) (@setI0 T).
HB.instance Definition _ := isComLaw.Build {set T} set0 (@setU T)
(@setUA T) (@setUC T) (@set0U T).
HB.instance Definition _ := isMulLaw.Build {set T} [set: T] (@setU T)
(@setTU T) (@setUT T).
HB.instance Definition _ := isAddLaw.Build {set T} (@setU T) (@setI T)
(@setUIl T) (@setUIr T).
HB.instance Definition _ := isAddLaw.Build {set T} (@setI T) (@setU T)
(@setIUl T) (@setIUr T).
End setOpsAlgebra.
Section CartesianProd.
Variables fT1 fT2 : finType.
Variables (A1 : {set fT1}) (A2 : {set fT2}).
Definition setX := [set u | u.1 \in A1 & u.2 \in A2].
Lemma in_setX x1 x2 : ((x1, x2) \in setX) = (x1 \in A1) && (x2 \in A2).
Proof. by rewrite inE. Qed.
Lemma setXP x1 x2 : reflect (x1 \in A1 /\ x2 \in A2) ((x1, x2) \in setX).
Proof. by rewrite inE; apply: andP. Qed.
Lemma cardsX : #|setX| = #|A1| * #|A2|.
Proof. by rewrite cardsE cardX. Qed.
End CartesianProd.
Arguments setXP {fT1 fT2 A1 A2 x1 x2}.
Section CartesianNProd.
Variables (I : finType) (fT : I -> finType).
Variables (A : forall i, {set fT i}).
Implicit Types (x : {dffun forall i, fT i}).
Definition setXn := [set x : {dffun _} in family A].
Lemma in_setXn x : (x \in setXn) = [forall i, x i \in A i].
Proof. by rewrite inE. Qed.
Lemma setXnP x : reflect (forall i, x i \in A i) (x \in setXn).
Proof. by rewrite inE; apply: forallP. Qed.
Lemma cardsXn : #|setXn| = \prod_i #|A i|.
Proof. by rewrite cardsE card_family foldrE big_map big_enum. Qed.
End CartesianNProd.
Arguments setXnP {I fT A x}.
HB.lock
Definition imset (aT rT : finType) f mD := [set y in @image_mem aT rT f mD].
Canonical imset_unlock := Unlockable imset.unlock.
HB.lock
Definition imset2 (aT1 aT2 rT : finType) f (D1 : mem_pred aT1) (D2 : _ -> mem_pred aT2) :=
[set y in @image_mem _ rT (uncurry f) (mem [pred u | D1 u.1 & D2 u.1 u.2])].
Canonical imset2_unlock := Unlockable imset2.unlock.
Definition preimset (aT : finType) rT f (R : mem_pred rT) :=
[set x : aT | in_mem (f x) R].
Notation "f @^-1: A" := (preimset f (mem A)) (at level 24) : set_scope.
Notation "f @: A" := (imset f (mem A)) (at level 24) : set_scope.
Notation "f @2: ( A , B )" := (imset2 f (mem A) (fun _ => mem B))
(at level 24, format "f @2: ( A , B )") : set_scope.
(* Comprehensions *)
Notation "[ 'set' E | x 'in' A ]" := ((fun x => E) @: A)
(format "[ '[hv' 'set' E '/ ' | x 'in' A ] ']'") : set_scope.
Notation "[ 'set' E | x 'in' A & P ]" := [set E | x in pred_of_set [set x in A | P]]
(format "[ '[hv' 'set' E '/ ' | x 'in' A '/ ' & P ] ']'") : set_scope.
Notation "[ 'set' E | x 'in' A , y 'in' B ]" :=
(imset2 (fun x y => E) (mem A) (fun x => mem B))
(y at level 99, format
"[ '[hv' 'set' E '/ ' | x 'in' A , '/ ' y 'in' B ] ']'"
) : set_scope.
Notation "[ 'set' E | x 'in' A , y 'in' B & P ]" :=
[set E | x in A, y in pred_of_set [set y in B | P]]
(format
"[ '[hv' 'set' E '/ ' | x 'in' A , '/ ' y 'in' B '/ ' & P ] ']'"
) : set_scope.
(* Typed variants *)
Notation "[ 'set' E | x : T 'in' A ]" := ((fun x : T => E) @: A)
(only parsing) : set_scope.
Notation "[ 'set' E | x : T 'in' A & P ]" :=
[set E | x : T in [set x : T in A | P]]
(only parsing) : set_scope.
Notation "[ 'set' E | x : T 'in' A , y : U 'in' B ]" :=
(imset2 (fun (x : T) (y : U) => E) (mem A) (fun (x : T) => mem B))
(y at level 99, only parsing) : set_scope.
Notation "[ 'set' E | x : T 'in' A , y : U 'in' B & P ]" :=
[set E | x : T in A, y : U in [set y : U in B | P]]
(only parsing) : set_scope.
(* Comprehensions over a type *)
Local Notation predOfType T := (pred_of_simpl (@pred_of_argType T)).
Notation "[ 'set' E | x : T ]" := [set E | x : T in predOfType T]
(format "[ '[hv' 'set' E '/ ' | x : T ] ']'") : set_scope.
Notation "[ 'set' E | x : T & P ]" :=
[set E | x : T in pred_of_set [set x : T | P]]
(format "[ '[hv' 'set' E '/ ' | x : T '/ ' & P ] ']'") : set_scope.
Notation "[ 'set' E | x : T , y : U 'in' B ]" :=
[set E | x : T in predOfType T, y : U in B]
(y at level 99, format
"[ '[hv' 'set' E '/ ' | x : T , '/ ' y : U 'in' B ] ']'")
: set_scope.
Notation "[ 'set' E | x : T , y : U 'in' B & P ]" :=
[set E | x : T, y : U in pred_of_set [set y in B | P]]
(format
"[ '[hv ' 'set' E '/' | x : T , '/ ' y : U 'in' B '/' & P ] ']'"
) : set_scope.
Notation "[ 'set' E | x : T 'in' A , y : U ]" :=
[set E | x : T in A, y : U in predOfType U]
(format
"[ '[hv' 'set' E '/ ' | x : T 'in' A , '/ ' y : U ] ']'")
: set_scope.
Notation "[ 'set' E | x : T 'in' A , y : U & P ]" :=
[set E | x : T in A, y : U in pred_of_set [set y in P]]
(format
"[ '[hv' 'set' E '/ ' | x : T 'in' A , '/ ' y : U & P ] ']'")
: set_scope.
Notation "[ 'set' E | x : T , y : U ]" :=
[set E | x : T, y : U in predOfType U]
(format
"[ '[hv' 'set' E '/ ' | x : T , '/ ' y : U ] ']'")
: set_scope.
Notation "[ 'set' E | x : T , y : U & P ]" :=
[set E | x : T, y : U in pred_of_set [set y in P]]
(format
"[ '[hv' 'set' E '/ ' | x : T , '/ ' y : U & P ] ']'")
: set_scope.
(* Untyped variants *)
Notation "[ 'set' E | x , y 'in' B ]" := [set E | x : _, y : _ in B]
(y at level 99, only parsing) : set_scope.
Notation "[ 'set' E | x , y 'in' B & P ]" := [set E | x : _, y : _ in B & P]
(only parsing) : set_scope.
Notation "[ 'set' E | x 'in' A , y ]" := [set E | x : _ in A, y : _]
(only parsing) : set_scope.
Notation "[ 'set' E | x 'in' A , y & P ]" := [set E | x : _ in A, y : _ & P]
(only parsing) : set_scope.
Notation "[ 'set' E | x , y ]" := [set E | x : _, y : _]
(only parsing) : set_scope.
Notation "[ 'set' E | x , y & P ]" := [set E | x : _, y : _ & P ]
(only parsing) : set_scope.
Section FunImage.
Variables aT aT2 : finType.
Section ImsetTheory.
Variable rT : finType.
Section ImsetProp.
Variables (f : aT -> rT) (f2 : aT -> aT2 -> rT).
Lemma imsetP D y : reflect (exists2 x, in_mem x D & y = f x) (y \in imset f D).
Proof. by rewrite [@imset]unlock inE; apply: imageP. Qed.
Variant imset2_spec D1 D2 y : Prop :=
Imset2spec x1 x2 of in_mem x1 D1 & in_mem x2 (D2 x1) & y = f2 x1 x2.
Lemma imset2P D1 D2 y : reflect (imset2_spec D1 D2 y) (y \in imset2 f2 D1 D2).
Proof.
rewrite [@imset2]unlock inE.
apply: (iffP imageP) => [[[x1 x2] Dx12] | [x1 x2 Dx1 Dx2]] -> {y}.
by case/andP: Dx12; exists x1 x2.
by exists (x1, x2); rewrite //= !inE Dx1.
Qed.
Lemma imset_f (D : {pred aT}) x : x \in D -> f x \in f @: D.
Proof. by move=> Dx; apply/imsetP; exists x. Qed.
Lemma mem_imset (D : {pred aT}) x : injective f -> f x \in f @: D = (x \in D).
Proof.
by move=> f_inj; apply/imsetP/idP;[case=> [y] ? /f_inj -> | move=> ?; exists x].
Qed.
Lemma imset0 : f @: set0 = set0.
Proof. by apply/setP => y /[!inE]; apply/imsetP => -[x /[!inE]]. Qed.
Lemma imset_eq0 (A : {set aT}) : (f @: A == set0) = (A == set0).
Proof.
have [-> | [x Ax]] := set_0Vmem A; first by rewrite imset0 !eqxx.
by rewrite -!cards_eq0 (cardsD1 x) Ax (cardsD1 (f x)) imset_f.
Qed.
Lemma imset_set1 x : f @: [set x] = [set f x].
Proof.
apply/setP => y.
by apply/imsetP/set1P=> [[x' /set1P-> //]| ->]; exists x; rewrite ?set11.
Qed.
Lemma imset_inj : injective f -> injective (fun A : {set aT} => f @: A).
Proof.
move=> inj_f A B => /setP E; apply/setP => x.
by rewrite -(mem_imset A x inj_f) E mem_imset.
Qed.
Lemma imset_disjoint (A B : {pred aT}) :
injective f -> [disjoint f @: A & f @: B] = [disjoint A & B].
Proof.
move=> inj_f; apply/pred0Pn/pred0Pn => /= [[_ /andP[/imsetP[x xA ->]] xB]|].
by exists x; rewrite xA -(mem_imset B x inj_f).
by move=> [x /andP[xA xB]]; exists (f x); rewrite !mem_imset ?xA.
Qed.
Lemma imset2_f (D : {pred aT}) (D2 : aT -> {pred aT2}) x x2 :
x \in D -> x2 \in D2 x ->
f2 x x2 \in [set f2 y y2 | y in D, y2 in D2 y].
Proof. by move=> Dx Dx2; apply/imset2P; exists x x2. Qed.
Lemma mem_imset2 (D : {pred aT}) (D2 : aT -> {pred aT2}) x x2 :
injective2 f2 ->
(f2 x x2 \in [set f2 y y2 | y in D, y2 in D2 y])
= (x \in D) && (x2 \in D2 x).
Proof.
move=> inj2_f; apply/imset2P/andP => [|[xD xD2]]; last by exists x x2.
by move => [x' x2' xD xD2 eq_f2]; case: (inj2_f _ _ _ _ eq_f2) => -> ->.
Qed.
Lemma sub_imset_pre (A : {pred aT}) (B : {pred rT}) :
(f @: A \subset B) = (A \subset f @^-1: B).
Proof.
apply/subsetP/subsetP=> [sfAB x Ax | sAf'B fx].
by rewrite inE sfAB ?imset_f.
by move=> /imsetP[a + ->] => /sAf'B /[!inE].
Qed.
Lemma preimsetS (A B : {pred rT}) :
A \subset B -> (f @^-1: A) \subset (f @^-1: B).
Proof. by move=> sAB; apply/subsetP=> y /[!inE]; apply: subsetP. Qed.
Lemma preimset0 : f @^-1: set0 = set0.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma preimsetT : f @^-1: setT = setT.
Proof. by apply/setP=> x; rewrite !inE. Qed.
Lemma preimsetI (A B : {set rT}) :
f @^-1: (A :&: B) = (f @^-1: A) :&: (f @^-1: B).
Proof. by apply/setP=> y; rewrite !inE. Qed.
Lemma preimsetU (A B : {set rT}) :
f @^-1: (A :|: B) = (f @^-1: A) :|: (f @^-1: B).
Proof. by apply/setP=> y; rewrite !inE. Qed.
Lemma preimsetD (A B : {set rT}) :
f @^-1: (A :\: B) = (f @^-1: A) :\: (f @^-1: B).
Proof. by apply/setP=> y; rewrite !inE. Qed.
Lemma preimsetC (A : {set rT}) : f @^-1: (~: A) = ~: f @^-1: A.
Proof. by apply/setP=> y; rewrite !inE. Qed.
Lemma imsetS (A B : {pred aT}) : A \subset B -> f @: A \subset f @: B.
Proof.
move=> sAB; apply/subsetP => _ /imsetP[x Ax ->].
by apply/imsetP; exists x; rewrite ?(subsetP sAB).
Qed.
Lemma imset_proper (A B : {set aT}) :
{in B &, injective f} -> A \proper B -> f @: A \proper f @: B.
Proof.
move=> injf /properP[sAB [x Bx nAx]]; rewrite properE imsetS //=.
apply: contra nAx => sfBA.
have: f x \in f @: A by rewrite (subsetP sfBA) ?imset_f.
by case/imsetP=> y Ay /injf-> //; apply: subsetP sAB y Ay.
Qed.
Lemma preimset_proper (A B : {set rT}) :
B \subset codom f -> A \proper B -> (f @^-1: A) \proper (f @^-1: B).
Proof.
move=> sBc /properP[sAB [u Bu nAu]]; rewrite properE preimsetS //=.
by apply/subsetPn; exists (iinv (subsetP sBc _ Bu)); rewrite inE /= f_iinv.
Qed.
Lemma imsetU (A B : {set aT}) : f @: (A :|: B) = (f @: A) :|: (f @: B).
Proof.
apply/eqP; rewrite eqEsubset subUset.
rewrite 2?imsetS (andbT, subsetUl, subsetUr) // andbT.
apply/subsetP=> _ /imsetP[x ABx ->]; apply/setUP.
by case/setUP: ABx => [Ax | Bx]; [left | right]; apply/imsetP; exists x.
Qed.
Lemma imsetU1 a (A : {set aT}) : f @: (a |: A) = f a |: (f @: A).
Proof. by rewrite imsetU imset_set1. Qed.
Lemma imsetI (A B : {set aT}) :
{in A & B, injective f} -> f @: (A :&: B) = f @: A :&: f @: B.
Proof.
move=> injf; apply/eqP; rewrite eqEsubset subsetI.
rewrite 2?imsetS (andTb, subsetIl, subsetIr) //=.
apply/subsetP=> _ /setIP[/imsetP[x Ax ->] /imsetP[z Bz /injf eqxz]].
by rewrite imset_f // inE Ax eqxz.
Qed.
Lemma imset2Sl (A B : {pred aT}) (C : {pred aT2}) :
A \subset B -> f2 @2: (A, C) \subset f2 @2: (B, C).
Proof.
move=> sAB; apply/subsetP=> _ /imset2P[x y Ax Cy ->].
by apply/imset2P; exists x y; rewrite ?(subsetP sAB).
Qed.
Lemma imset2Sr (A B : {pred aT2}) (C : {pred aT}) :
A \subset B -> f2 @2: (C, A) \subset f2 @2: (C, B).
Proof.
move=> sAB; apply/subsetP=> _ /imset2P[x y Ax Cy ->].
by apply/imset2P; exists x y; rewrite ?(subsetP sAB).
Qed.
Lemma imset2S (A B : {pred aT}) (A2 B2 : {pred aT2}) :
A \subset B -> A2 \subset B2 -> f2 @2: (A, A2) \subset f2 @2: (B, B2).
Proof. by move=> /(imset2Sl B2) sBA /(imset2Sr A)/subset_trans->. Qed.
End ImsetProp.
Implicit Types (f g : aT -> rT) (D : {pred aT}) (R : {pred rT}).
Lemma eq_preimset f g R : f =1 g -> f @^-1: R = g @^-1: R.
Proof. by move=> eqfg; apply/setP => y; rewrite !inE eqfg. Qed.
Lemma eq_imset f g D : f =1 g -> f @: D = g @: D.
Proof.
move=> eqfg; apply/setP=> y.
by apply/imsetP/imsetP=> [] [x Dx ->]; exists x; rewrite ?eqfg.
Qed.
Lemma eq_in_imset f g D : {in D, f =1 g} -> f @: D = g @: D.
Proof.
move=> eqfg; apply/setP => y.
by apply/imsetP/imsetP=> [] [x Dx ->]; exists x; rewrite ?eqfg.
Qed.
Lemma eq_in_imset2 (f g : aT -> aT2 -> rT) (D : {pred aT}) (D2 : {pred aT2}) :
{in D & D2, f =2 g} -> f @2: (D, D2) = g @2: (D, D2).
Proof.
move=> eqfg; apply/setP => y.
by apply/imset2P/imset2P=> [] [x x2 Dx Dx2 ->]; exists x x2; rewrite ?eqfg.
Qed.
End ImsetTheory.
Lemma imset2_pair (A : {set aT}) (B : {set aT2}) :
[set (x, y) | x in A, y in B] = setX A B.
Proof.
apply/setP=> [[x y]]; rewrite !inE /=.
by apply/imset2P/andP=> [[_ _ _ _ [-> ->]//]| []]; exists x y.
Qed.
Lemma setXS (A1 B1 : {set aT}) (A2 B2 : {set aT2}) :
A1 \subset B1 -> A2 \subset B2 -> setX A1 A2 \subset setX B1 B2.
Proof. by move=> sAB1 sAB2; rewrite -!imset2_pair imset2S. Qed.
End FunImage.
Arguments imsetP {aT rT f D y}.
Arguments imset2P {aT aT2 rT f2 D1 D2 y}.
Arguments imset_disjoint {aT rT f A B}.
Section unset1.
Variable (I : finType).
Implicit Types (i : I) (A : {set I}).
Lemma pick_set1 i0 : [pick x in [set i0]] = Some i0.
Proof. by case: pickP => [i /[!inE]/eqP-> | /(_ i0)/[!(inE, eqxx)]]. Qed.
Definition unset1 A : option I := if #|A| == 1 then [pick x in A] else None.
Lemma set1K : pcancel set1 unset1.
Proof. by move=> i; rewrite /unset1 cards1 eqxx pick_set1. Qed.
Lemma omap_unset1K A : #|A| = 1 -> omap set1 (unset1 A) = Some A.
Proof. by move=> /eqP/cards1P[i ->]; rewrite set1K. Qed.
Lemma unset10 : unset1 set0 = None. Proof. by rewrite /unset1 cards0. Qed.
Lemma unset1N1 A : #|A| != 1 -> unset1 A = None.
Proof. by move=> AN1; rewrite /unset1 ifN. Qed.
Lemma unset1K : ocancel unset1 set1.
Proof.
move=> A; rewrite /unset1.
by case: ifPn => // /cards1P[i ->]/=; rewrite pick_set1.
Qed.
End unset1.
Arguments unset1 {I}.
Lemma setXnS (I : finType) (T : I -> finType) (A B : forall i, {set T i}) :
(forall i, A i \subset B i) -> setXn A \subset setXn B.
Proof.
move=> sAB; apply/subsetP => x /setXnP xA.
by apply/setXnP => i; apply/subsetP: (xA i).
Qed.
Lemma eq_setXn (I : finType) (T : I -> finType) (A B : forall i, {set T i}) :
(forall i, A i = B i) -> setXn A = setXn B.
Proof.
by move=> eqAB; apply/eqP; rewrite eqEsubset !setXnS// => j; rewrite eqAB.
Qed.
Section BigOpsAnyOp.
Variables (R : Type) (x : R) (op : R -> R -> R).
Variables I : finType.
Implicit Type F : I -> R.
Lemma big_set0 F : \big[op/x]_(i in set0) F i = x.
Proof. by apply: big_pred0 => i; rewrite inE. Qed.
Lemma big_set1E j F : \big[op/x]_(i in [set j]) F i = op (F j) x.
Proof. by rewrite -big_pred1_eq_id; apply: eq_bigl => i; apply: in_set1. Qed.
Lemma big_set (A : pred I) F :
\big[op/x]_(i in [set i | A i]) (F i) = \big[op/x]_(i in A) (F i).
Proof. by apply: eq_bigl => i; rewrite inE. Qed.
End BigOpsAnyOp.
Section BigOpsSemiGroup.
Variables (R : Type) (op : SemiGroup.com_law R).
Variable (le : rel R).
Hypotheses (le_refl : reflexive le) (le_incr : forall x y, le x (op x y)).
Context [x : R].
Lemma subset_le_big_cond (I : finType) (A A' P P' : {pred I}) (F : I -> R) :
[set i in A | P i] \subset [set i in A' | P' i] ->
le (\big[op/x]_(i in A | P i) F i) (\big[op/x]_(i in A' | P' i) F i).
Proof.
by move=> /subsetP AP; apply: sub_le_big => // i; have /[!inE] := AP i.
Qed.
Lemma big_imset_idem [I J : finType] (h : I -> J) (A : pred I) F :
idempotent_op op ->
\big[op/x]_(j in h @: A) F j = \big[op/x]_(i in A) F (h i).
Proof.
rewrite -!big_image => op_idem; rewrite -big_undup// -[RHS]big_undup//.
apply/perm_big/perm_undup => j; apply/imageP.
have [mem_j | /imageP mem_j] := boolP (j \in [seq h j | j in A]).
- by exists j => //; apply/imsetP; apply: imageP mem_j.
- by case=> k /imsetP [i j_in_A ->] eq_i; apply: mem_j; exists i.
Qed.
End BigOpsSemiGroup.
Section BigOps.
Variables (R : Type) (idx : R).
Variables (op : Monoid.law idx) (aop : Monoid.com_law idx).
Variables (times : Monoid.mul_law idx) (plus : Monoid.add_law idx times).
Variables I J : finType.
Implicit Type A B : {set I}.
Implicit Type h : I -> J.
Implicit Type P : pred I.
Implicit Type F : I -> R.
Lemma big_set1 a F : \big[op/idx]_(i in [set a]) F i = F a.
Proof. by apply: big_pred1 => i; rewrite !inE. Qed.
Lemma big_setID A B F :
\big[aop/idx]_(i in A) F i =
aop (\big[aop/idx]_(i in A :&: B) F i)
(\big[aop/idx]_(i in A :\: B) F i).
Proof.
rewrite (bigID [in B]) setDE.
by congr (aop _ _); apply: eq_bigl => i; rewrite !inE.
Qed.
Lemma big_setIDcond A B P F :
\big[aop/idx]_(i in A | P i) F i =
aop (\big[aop/idx]_(i in A :&: B | P i) F i)
(\big[aop/idx]_(i in A :\: B | P i) F i).
Proof. by rewrite !big_mkcondr; apply: big_setID. Qed.
Lemma big_setD1 a A F : a \in A ->
\big[aop/idx]_(i in A) F i = aop (F a) (\big[aop/idx]_(i in A :\ a) F i).
Proof.
move=> Aa; rewrite (bigD1 a Aa); congr (aop _).
by apply: eq_bigl => x; rewrite !inE andbC.
Qed.
Lemma big_setU1 a A F : a \notin A ->
\big[aop/idx]_(i in a |: A) F i = aop (F a) (\big[aop/idx]_(i in A) F i).
Proof. by move=> notAa; rewrite (@big_setD1 a) ?setU11 //= setU1K. Qed.
Lemma big_subset_idem_cond A B P F :
idempotent_op aop ->
A \subset B ->
aop (\big[aop/idx]_(i in A | P i) F i) (\big[aop/idx]_(i in B | P i) F i)
= \big[aop/idx]_(i in B | P i) F i.
Proof.
by move=> idaop /setIidPr <-; rewrite (big_setIDcond B A) Monoid.mulmA /= idaop.
Qed.
Lemma big_subset_idem A B F :
idempotent_op aop ->
A \subset B ->
aop (\big[aop/idx]_(i in A) F i) (\big[aop/idx]_(i in B) F i)
= \big[aop/idx]_(i in B) F i.
Proof. by rewrite -2!big_condT; apply: big_subset_idem_cond. Qed.
Lemma big_setU_cond A B P F :
idempotent_op aop ->
\big[aop/idx]_(i in A :|: B | P i) F i
= aop (\big[aop/idx]_(i in A | P i) F i) (\big[aop/idx]_(i in B | P i) F i).
Proof.
move=> idemaop; rewrite (big_setIDcond _ A) setUK setDUl setDv set0U.
rewrite (big_setIDcond B A) Monoid.mulmCA Monoid.mulmA /=.
by rewrite (@big_subset_idem_cond (B :&: A)) // subsetIr.
Qed.
Lemma big_setU A B F :
idempotent_op aop ->
\big[aop/idx]_(i in A :|: B) F i
= aop (\big[aop/idx]_(i in A) F i) (\big[aop/idx]_(i in B) F i).
Proof. by rewrite -3!big_condT; apply: big_setU_cond. Qed.
Lemma big_imset h (A : {pred I}) G : {in A &, injective h} ->
\big[aop/idx]_(j in h @: A) G j = \big[aop/idx]_(i in A) G (h i).
Proof.
move=> injh; pose hA := mem (image h A).
rewrite (eq_bigl hA) => [|j]; last exact/imsetP/imageP.
pose h' := omap (fun u : {j | hA j} => iinv (svalP u)) \o insub.
rewrite (reindex_omap h h') => [|j hAj]; rewrite {}/h'/= ?insubT/= ?f_iinv//.
apply: eq_bigl => i; case: insubP => [u /= -> def_u | nhAhi]; last first.
by apply/andP/idP => [[]//| Ai]; case/imageP: nhAhi; exists i.
set i' := iinv _; have Ai' : i' \in A := mem_iinv (svalP u).
by apply/eqP/idP => [[<-] // | Ai]; congr Some; apply: injh; rewrite ?f_iinv.
Qed.
Lemma big_imset_cond h (A : {pred I}) (P : pred J) G : {in A &, injective h} ->
\big[aop/idx]_(j in h @: A | P j) G j =
\big[aop/idx]_(i in A | P (h i)) G (h i).
Proof. by move=> h_inj; rewrite 2!big_mkcondr big_imset. Qed.
Lemma partition_big_imset h (A : {pred I}) F :
\big[aop/idx]_(i in A) F i =
\big[aop/idx]_(j in h @: A) \big[aop/idx]_(i in A | h i == j) F i.
Proof. by apply: partition_big => i Ai; apply/imsetP; exists i. Qed.
Lemma big_cards1 (f : {set I} -> R) :
\big[aop/idx]_(A : {set I} | #|A| == 1) f A
= \big[aop/idx]_(i : I) f [set i].
Proof.
rewrite (reindex_omap set1 unset1) => [|A /cards1P[i ->] /[!set1K]//].
by apply: eq_bigl => i; rewrite set1K cards1 !eqxx.
Qed.
End BigOps.
Lemma bigA_distr (R : Type) (zero one : R) (mul : Monoid.mul_law zero)
(add : Monoid.add_law zero mul) (I : finType) (F G : I -> R) :
\big[mul/one]_i add (F i) (G i) =
\big[add/zero]_(J in {set I}) \big[mul/one]_i (if i \in J then F i else G i).
Proof.
under eq_bigr => i _ do rewrite -(big_bool _ (fun b => if b then F i else G i)).
rewrite bigA_distr_bigA.
set f := fun J : {set I} => val J.
transitivity (\big[add/zero]_(f0 in (imset f (mem setT)))
\big[mul/one]_i (if f0 i then F i else G i)).
suff <-: setT = imset f (mem setT) by apply: congr_big=>// i; rewrite in_setT.
apply/esym/eqP; rewrite -subTset; apply/subsetP => b _.
by apply/imsetP; exists (FinSet b).
rewrite big_imset; last by case=> g; case=> h _ _; rewrite /f => /= ->.
apply: congr_big => //; case=> g; first exact: in_setT.
by move=> _; apply: eq_bigr => i _; congr (if _ then _ else _); rewrite unlock.
Qed.
Arguments big_setID [R idx aop I A].
Arguments big_setD1 [R idx aop I] a [A F].
Arguments big_setU1 [R idx aop I] a [A F].
Arguments big_imset [R idx aop I J h A].
Arguments partition_big_imset [R idx aop I J].
Section Fun2Set1.
Variables aT1 aT2 rT : finType.
Variables (f : aT1 -> aT2 -> rT).
Lemma imset2_set1l x1 (D2 : {pred aT2}) : f @2: ([set x1], D2) = f x1 @: D2.
Proof.
apply/setP=> y; apply/imset2P/imsetP=> [[x x2 /set1P->]| [x2 Dx2 ->]].
by exists x2.
by exists x1 x2; rewrite ?set11.
Qed.
Lemma imset2_set1r x2 (D1 : {pred aT1}) : f @2: (D1, [set x2]) = f^~ x2 @: D1.
Proof.
apply/setP=> y; apply/imset2P/imsetP=> [[x1 x Dx1 /set1P->]| [x1 Dx1 ->]].
by exists x1.
by exists x1 x2; rewrite ?set11.
Qed.
End Fun2Set1.
Section CardFunImage.
Variables aT aT2 rT : finType.
Variables (f : aT -> rT) (g : rT -> aT) (f2 : aT -> aT2 -> rT).
Variables (D : {pred aT}) (D2 : {pred aT}).
Lemma imset_card : #|f @: D| = #|image f D|.
Proof. by rewrite [@imset]unlock cardsE. Qed.
Lemma leq_imset_card : #|f @: D| <= #|D|.
Proof. by rewrite imset_card leq_image_card. Qed.
Lemma card_in_imset : {in D &, injective f} -> #|f @: D| = #|D|.
Proof. by move=> injf; rewrite imset_card card_in_image. Qed.
Lemma card_imset : injective f -> #|f @: D| = #|D|.
Proof. by move=> injf; rewrite imset_card card_image. Qed.
Lemma imset_injP : reflect {in D &, injective f} (#|f @: D| == #|D|).
Proof. by rewrite [@imset]unlock cardsE; apply: image_injP. Qed.
Lemma can2_in_imset_pre :
{in D, cancel f g} -> {on D, cancel g & f} -> f @: D = g @^-1: D.
Proof.
move=> fK gK; apply/setP=> y; rewrite inE.
by apply/imsetP/idP=> [[x Ax ->] | Agy]; last exists (g y); rewrite ?(fK, gK).
Qed.
Lemma can2_imset_pre : cancel f g -> cancel g f -> f @: D = g @^-1: D.
Proof. by move=> fK gK; apply: can2_in_imset_pre; apply: in1W. Qed.
End CardFunImage.
Arguments imset_injP {aT rT f D}.
Lemma on_card_preimset (aT rT : finType) (f : aT -> rT) (R : {pred rT}) :
{on R, bijective f} -> #|f @^-1: R| = #|R|.
Proof.
case=> g fK gK; rewrite -(can2_in_imset_pre gK) // card_in_imset //.
exact: can_in_inj gK.
Qed.
Lemma can_imset_pre (T : finType) f g (A : {set T}) :
cancel f g -> f @: A = g @^-1: A :> {set T}.
Proof.
move=> fK; apply: can2_imset_pre => // x.
suffices fx: x \in codom f by rewrite -(f_iinv fx) fK.
exact/(subset_cardP (card_codom (can_inj fK)))/subsetP.
Qed.
Lemma imset_id (T : finType) (A : {set T}) : [set x | x in A] = A.
Proof. by apply/setP=> x; rewrite (@can_imset_pre _ _ id) ?inE. Qed.
Lemma card_preimset (T : finType) (f : T -> T) (A : {set T}) :
injective f -> #|f @^-1: A| = #|A|.
Proof.
move=> injf; apply: on_card_preimset; apply: onW_bij.
have ontof: _ \in codom f by apply/(subset_cardP (card_codom injf))/subsetP.
by exists (fun x => iinv (ontof x)) => x; rewrite (f_iinv, iinv_f).
Qed.
Lemma card_powerset (T : finType) (A : {set T}) : #|powerset A| = 2 ^ #|A|.
Proof.
rewrite -card_bool -(card_pffun_on false) -(card_imset _ val_inj).
apply: eq_card => f; pose sf := false.-support f; pose D := finset sf.
have sDA: (D \subset A) = (sf \subset A) by apply: eq_subset; apply: in_set.
have eq_sf x : sf x = f x by rewrite /= negb_eqb addbF.
have valD: val D = f by rewrite /D unlock; apply/ffunP=> x; rewrite ffunE eq_sf.
apply/imsetP/pffun_onP=> [[B] | [sBA _]]; last by exists D; rewrite // inE ?sDA.
by rewrite inE -sDA -valD => sBA /val_inj->.
Qed.
Section FunImageComp.
Variables T T' U : finType.
Lemma imset_comp (f : T' -> U) (g : T -> T') (H : {pred T}) :
(f \o g) @: H = f @: (g @: H).
Proof.
apply/setP/subset_eqP/andP.
split; apply/subsetP=> _ /imsetP[x0 Hx0 ->]; apply/imsetP.
by exists (g x0); first apply: imset_f.
by move/imsetP: Hx0 => [x1 Hx1 ->]; exists x1.
Qed.
End FunImageComp.
Notation "\bigcup_ ( i <- r | P ) F" :=
(\big[@setU _/set0]_(i <- r | P) F%SET) : set_scope.
Notation "\bigcup_ ( i <- r ) F" :=
(\big[@setU _/set0]_(i <- r) F%SET) : set_scope.
Notation "\bigcup_ ( m <= i < n | P ) F" :=
(\big[@setU _/set0]_(m <= i < n | P%B) F%SET) : set_scope.
Notation "\bigcup_ ( m <= i < n ) F" :=
(\big[@setU _/set0]_(m <= i < n) F%SET) : set_scope.
Notation "\bigcup_ ( i | P ) F" :=
(\big[@setU _/set0]_(i | P%B) F%SET) : set_scope.
Notation "\bigcup_ i F" :=
(\big[@setU _/set0]_i F%SET) : set_scope.
Notation "\bigcup_ ( i : t | P ) F" :=
(\big[@setU _/set0]_(i : t | P%B) F%SET) (only parsing): set_scope.
Notation "\bigcup_ ( i : t ) F" :=
(\big[@setU _/set0]_(i : t) F%SET) (only parsing) : set_scope.
Notation "\bigcup_ ( i < n | P ) F" :=
(\big[@setU _/set0]_(i < n | P%B) F%SET) : set_scope.
Notation "\bigcup_ ( i < n ) F" :=
(\big[@setU _/set0]_ (i < n) F%SET) : set_scope.
Notation "\bigcup_ ( i 'in' A | P ) F" :=
(\big[@setU _/set0]_(i in A | P%B) F%SET) : set_scope.
Notation "\bigcup_ ( i 'in' A ) F" :=
(\big[@setU _/set0]_(i in A) F%SET) : set_scope.
Notation "\bigcap_ ( i <- r | P ) F" :=
(\big[@setI _/setT]_(i <- r | P%B) F%SET) : set_scope.
Notation "\bigcap_ ( i <- r ) F" :=
(\big[@setI _/setT]_(i <- r) F%SET) : set_scope.
Notation "\bigcap_ ( m <= i < n | P ) F" :=
(\big[@setI _/setT]_(m <= i < n | P%B) F%SET) : set_scope.
Notation "\bigcap_ ( m <= i < n ) F" :=
(\big[@setI _/setT]_(m <= i < n) F%SET) : set_scope.
Notation "\bigcap_ ( i | P ) F" :=
(\big[@setI _/setT]_(i | P%B) F%SET) : set_scope.
Notation "\bigcap_ i F" :=
(\big[@setI _/setT]_i F%SET) : set_scope.
Notation "\bigcap_ ( i : t | P ) F" :=
(\big[@setI _/setT]_(i : t | P%B) F%SET) (only parsing): set_scope.
Notation "\bigcap_ ( i : t ) F" :=
(\big[@setI _/setT]_(i : t) F%SET) (only parsing) : set_scope.
Notation "\bigcap_ ( i < n | P ) F" :=
(\big[@setI _/setT]_(i < n | P%B) F%SET) : set_scope.
Notation "\bigcap_ ( i < n ) F" :=
(\big[@setI _/setT]_(i < n) F%SET) : set_scope.
Notation "\bigcap_ ( i 'in' A | P ) F" :=
(\big[@setI _/setT]_(i in A | P%B) F%SET) : set_scope.
Notation "\bigcap_ ( i 'in' A ) F" :=
(\big[@setI _/setT]_(i in A) F%SET) : set_scope.
Section BigSetOps.
Variables T I : finType.
Implicit Types (U : {pred T}) (P : pred I) (A B : {set I}) (F : I -> {set T}).
(* It is very hard to use this lemma, because the unification fails to *)
(* defer the F j pattern (even though it's a Miller pattern!). *)
Lemma bigcup_sup j P F : P j -> F j \subset \bigcup_(i | P i) F i.
Proof. by move=> Pj; rewrite (bigD1 j) //= subsetUl. Qed.
Lemma bigcup_max j U P F :
P j -> U \subset F j -> U \subset \bigcup_(i | P i) F i.
Proof. by move=> Pj sUF; apply: subset_trans (bigcup_sup _ Pj). Qed.
Lemma bigcupP x P F :
reflect (exists2 i, P i & x \in F i) (x \in \bigcup_(i | P i) F i).
Proof.
apply: (iffP idP) => [|[i Pi]]; last first.
by apply: subsetP x; apply: bigcup_sup.
by elim/big_rec: _ => [|i _ Pi _ /setUP[|//]]; [rewrite inE | exists i].
Qed.
Lemma bigcupsP U P F :
reflect (forall i, P i -> F i \subset U) (\bigcup_(i | P i) F i \subset U).
Proof.
apply: (iffP idP) => [sFU i Pi| sFU].
by apply: subset_trans sFU; apply: bigcup_sup.
by apply/subsetP=> x /bigcupP[i Pi]; apply: (subsetP (sFU i Pi)).
Qed.
Lemma bigcup0P P F :
reflect (forall i, P i -> F i = set0) (\bigcup_(i | P i) F i == set0).
Proof.
rewrite -subset0; apply: (iffP (bigcupsP _ _ _)) => sub0 i /sub0; last by move->.
by rewrite subset0 => /eqP.
Qed.
Lemma bigcup_disjointP U P F :
reflect (forall i : I, P i -> [disjoint U & F i])
[disjoint U & \bigcup_(i | P i) F i].
Proof.
apply: (iffP idP) => [dUF i Pp|dUF].
by apply: disjointWr dUF; apply: bigcup_sup.
rewrite disjoint_sym disjoint_subset.
by apply/bigcupsP=> i /dUF; rewrite disjoint_sym disjoint_subset.
Qed.
Lemma bigcup_disjoint U P F :
(forall i, P i -> [disjoint U & F i]) -> [disjoint U & \bigcup_(i | P i) F i].
Proof. by move/bigcup_disjointP. Qed.
Lemma bigcup_setU A B F :
\bigcup_(i in A :|: B) F i =
(\bigcup_(i in A) F i) :|: (\bigcup_ (i in B) F i).
Proof.
apply/setP=> x; apply/bigcupP/setUP=> [[i] | ].
by case/setUP; [left | right]; apply/bigcupP; exists i.
by case=> /bigcupP[i Pi]; exists i; rewrite // inE Pi ?orbT.
Qed.
Lemma bigcup_seq r F : \bigcup_(i <- r) F i = \bigcup_(i in r) F i.
Proof.
elim: r => [|i r IHr]; first by rewrite big_nil big_pred0.
rewrite big_cons {}IHr; case r_i: (i \in r).
rewrite (setUidPr _) ?bigcup_sup //.
by apply: eq_bigl => j /[!inE]; case: eqP => // ->.
rewrite (bigD1 i (mem_head i r)) /=; congr (_ :|: _).
by apply: eq_bigl => j /=; rewrite andbC; case: eqP => // ->.
Qed.
(* Unlike its setU counterpart, this lemma is useable. *)
Lemma bigcap_inf j P F : P j -> \bigcap_(i | P i) F i \subset F j.
Proof. by move=> Pj; rewrite (bigD1 j) //= subsetIl. Qed.
Lemma bigcap_min j U P F :
P j -> F j \subset U -> \bigcap_(i | P i) F i \subset U.
Proof. by move=> Pj; apply: subset_trans (bigcap_inf _ Pj). Qed.
Lemma bigcapsP U P F :
reflect (forall i, P i -> U \subset F i) (U \subset \bigcap_(i | P i) F i).
Proof.
apply: (iffP idP) => [sUF i Pi | sUF].
by apply: subset_trans sUF _; apply: bigcap_inf.
elim/big_rec: _ => [|i V Pi sUV]; apply/subsetP=> x Ux; rewrite inE //.
by rewrite !(subsetP _ x Ux) ?sUF.
Qed.
Lemma bigcapP x P F :
reflect (forall i, P i -> x \in F i) (x \in \bigcap_(i | P i) F i).
Proof.
rewrite -sub1set.
by apply: (iffP (bigcapsP _ _ _)) => Fx i /Fx; rewrite sub1set.
Qed.
Lemma setC_bigcup J r (P : pred J) (F : J -> {set T}) :
~: (\bigcup_(j <- r | P j) F j) = \bigcap_(j <- r | P j) ~: F j.
Proof. by apply: big_morph => [A B|]; rewrite ?setC0 ?setCU. Qed.
Lemma setC_bigcap J r (P : pred J) (F : J -> {set T}) :
~: (\bigcap_(j <- r | P j) F j) = \bigcup_(j <- r | P j) ~: F j.
Proof. by apply: big_morph => [A B|]; rewrite ?setCT ?setCI. Qed.
Lemma bigcap_setU A B F :
(\bigcap_(i in A :|: B) F i) =
(\bigcap_(i in A) F i) :&: (\bigcap_(i in B) F i).
Proof. by apply: setC_inj; rewrite setCI !setC_bigcap bigcup_setU. Qed.
Lemma bigcap_seq r F : \bigcap_(i <- r) F i = \bigcap_(i in r) F i.
Proof. by apply: setC_inj; rewrite !setC_bigcap bigcup_seq. Qed.
End BigSetOps.
Arguments bigcup_sup [T I] j [P F].
Arguments bigcup_max [T I] j [U P F].
Arguments bigcupP {T I x P F}.
Arguments bigcupsP {T I U P F}.
Arguments bigcup_disjointP {T I U P F}.
Arguments bigcap_inf [T I] j [P F].
Arguments bigcap_min [T I] j [U P F].
Arguments bigcapP {T I x P F}.
Arguments bigcapsP {T I U P F}.
Section ImsetCurry.
Variables (aT1 aT2 rT : finType) (f : aT1 -> aT2 -> rT).
Section Curry.
Variables (A1 : {set aT1}) (A2 : {set aT2}).
Variables (D1 : {pred aT1}) (D2 : {pred aT2}).
Lemma curry_imset2X : f @2: (A1, A2) = uncurry f @: (setX A1 A2).
Proof.
rewrite [@imset]unlock unlock; apply/setP=> x; rewrite !in_set; congr (x \in _).
by apply: eq_image => u //=; rewrite !inE.
Qed.
Lemma curry_imset2l : f @2: (D1, D2) = \bigcup_(x1 in D1) f x1 @: D2.
Proof.
apply/setP=> y; apply/imset2P/bigcupP => [[x1 x2 Dx1 Dx2 ->{y}] | [x1 Dx1]].
by exists x1; rewrite // imset_f.
by case/imsetP=> x2 Dx2 ->{y}; exists x1 x2.
Qed.
Lemma curry_imset2r : f @2: (D1, D2) = \bigcup_(x2 in D2) f^~ x2 @: D1.
Proof.
apply/setP=> y; apply/imset2P/bigcupP => [[x1 x2 Dx1 Dx2 ->{y}] | [x2 Dx2]].
by exists x2; rewrite // (imset_f (f^~ x2)).
by case/imsetP=> x1 Dx1 ->{y}; exists x1 x2.
Qed.
End Curry.
Lemma imset2Ul (A B : {set aT1}) (C : {set aT2}) :
f @2: (A :|: B, C) = f @2: (A, C) :|: f @2: (B, C).
Proof. by rewrite !curry_imset2l bigcup_setU. Qed.
Lemma imset2Ur (A : {set aT1}) (B C : {set aT2}) :
f @2: (A, B :|: C) = f @2: (A, B) :|: f @2: (A, C).
Proof. by rewrite !curry_imset2r bigcup_setU. Qed.
End ImsetCurry.
Section Partitions.
Variables T I : finType.
Implicit Types (x y z : T) (A B D X : {set T}) (P Q : {set {set T}}).
Implicit Types (J : pred I) (F : I -> {set T}).
Definition cover P := \bigcup_(B in P) B.
Definition pblock P x := odflt set0 (pick [pred B in P | x \in B]).
Definition trivIset P := \sum_(B in P) #|B| == #|cover P|.
Definition partition P D := [&& cover P == D, trivIset P & set0 \notin P].
Definition is_transversal X P D :=
[&& partition P D, X \subset D & [forall B in P, #|X :&: B| == 1]].
Definition transversal P D := [set odflt x [pick y in pblock P x] | x in D].
Definition transversal_repr x0 X B := odflt x0 [pick x in X :&: B].
Lemma leq_card_setU A B : #|A :|: B| <= #|A| + #|B| ?= iff [disjoint A & B].
Proof.
rewrite -(addn0 #|_|) -setI_eq0 -cards_eq0 -cardsUI eq_sym.
by rewrite (mono_leqif (leq_add2l _)).
Qed.
Lemma leq_card_cover P : #|cover P| <= \sum_(A in P) #|A| ?= iff trivIset P.
Proof.
split; last exact: eq_sym.
rewrite /cover; elim/big_rec2: _ => [|A n U _ leUn]; first by rewrite cards0.
by rewrite (leq_trans (leq_card_setU A U).1) ?leq_add2l.
Qed.
Lemma imset_cover (T' : finType) P (f : T -> T') :
[set f x | x in cover P] = \bigcup_(i in P) [set f x | x in i].
Proof.
apply/setP=> y; apply/imsetP/bigcupP => [|[A AP /imsetP[x xA ->]]].
by move=> [x /bigcupP[A AP xA] ->]; exists A => //; rewrite imset_f.
by exists x => //; apply/bigcupP; exists A.
Qed.
Lemma cover1 A : cover [set A] = A.
Proof. by rewrite /cover big_set1. Qed.
Lemma trivIset1 A : trivIset [set A].
Proof. by rewrite /trivIset cover1 big_set1. Qed.
Lemma trivIsetP P :
reflect {in P &, forall A B, A != B -> [disjoint A & B]} (trivIset P).
Proof.
rewrite -[P]set_enum; elim: {P}(enum _) (enum_uniq P) => [_ | A e IHe] /=.
by rewrite /trivIset /cover !big_set0 cards0; left=> A; rewrite inE.
case/andP; rewrite set_cons -(in_set (fun B => B \in e)) => PA {}/IHe.
move: {e}[set x in e] PA => P PA IHP.
rewrite /trivIset /cover !big_setU1 //= eq_sym.
have:= leq_card_cover P; rewrite -(mono_leqif (leq_add2l #|A|)).
move/(leqif_trans (leq_card_setU _ _))->; rewrite disjoints_subset setC_bigcup.
case: bigcapsP => [disjA | meetA]; last first.
right=> [tI]; case: meetA => B PB; rewrite -disjoints_subset.
by rewrite tI ?setU11 ?setU1r //; apply: contraNneq PA => ->.
apply: (iffP IHP) => [] tI B C PB PC; last by apply: tI; apply: setU1r.
by case/setU1P: PC PB => [->|PC] /setU1P[->|PB]; try by [apply: tI | case/eqP];
first rewrite disjoint_sym; rewrite disjoints_subset disjA.
Qed.
Lemma trivIsetS P Q : P \subset Q -> trivIset Q -> trivIset P.
Proof. by move/subsetP/sub_in2=> sPQ /trivIsetP/sPQ/trivIsetP. Qed.
Lemma trivIsetD P Q : trivIset P -> trivIset (P :\: Q).
Proof.
move/trivIsetP => tP; apply/trivIsetP => A B /setDP[TA _] /setDP[TB _]; exact: tP.
Qed.
Lemma trivIsetU P Q :
trivIset Q -> trivIset P -> [disjoint cover Q & cover P] -> trivIset (Q :|: P).
Proof.
move => /trivIsetP tQ /trivIsetP tP dQP; apply/trivIsetP => A B.
move => /setUP[?|?] /setUP[?|?]; first [exact:tQ|exact:tP|move => _].
by apply: disjointW dQP; rewrite bigcup_sup.
by rewrite disjoint_sym; apply: disjointW dQP; rewrite bigcup_sup.
Qed.
Lemma coverD1 P B : trivIset P -> B \in P -> cover (P :\ B) = cover P :\: B.
Proof.
move/trivIsetP => tP SP; apply/setP => x; rewrite inE.
apply/bigcupP/idP => [[A /setD1P [ADS AP] xA]|/andP[xNS /bigcupP[A AP xA]]].
by rewrite (disjointFr (tP _ _ _ _ ADS)) //=; apply/bigcupP; exists A.
by exists A; rewrite // !inE AP andbT; apply: contraNneq xNS => <-.
Qed.
Lemma trivIsetI P D : trivIset P -> trivIset (P ::&: D).
Proof. by apply: trivIsetS; rewrite -setI_powerset subsetIl. Qed.
Lemma cover_setI P D : cover (P ::&: D) \subset cover P :&: D.
Proof.
by apply/bigcupsP=> A /setIdP[PA sAD]; rewrite subsetI sAD andbT (bigcup_max A).
Qed.
Lemma mem_pblock P x : (x \in pblock P x) = (x \in cover P).
Proof.
rewrite /pblock; apply/esym/bigcupP.
case: pickP => /= [A /andP[PA Ax]| noA]; first by rewrite Ax; exists A.
by rewrite inE => [[A PA Ax]]; case/andP: (noA A).
Qed.
Lemma pblock_mem P x : x \in cover P -> pblock P x \in P.
Proof.
by rewrite -mem_pblock /pblock; case: pickP => [A /andP[]| _] //=; rewrite inE.
Qed.
Lemma def_pblock P B x : trivIset P -> B \in P -> x \in B -> pblock P x = B.
Proof.
move/trivIsetP=> tiP PB Bx; have Px: x \in cover P by apply/bigcupP; exists B.
apply: (contraNeq (tiP _ _ _ PB)); first by rewrite pblock_mem.
by apply/pred0Pn; exists x; rewrite /= mem_pblock Px.
Qed.
Lemma same_pblock P x y :
trivIset P -> x \in pblock P y -> pblock P x = pblock P y.
Proof.
rewrite {1 3}/pblock => tI; case: pickP => [A|]; last by rewrite inE.
by case/andP=> PA _{y} /= Ax; apply: def_pblock.
Qed.
Lemma eq_pblock P x y :
trivIset P -> x \in cover P ->
(pblock P x == pblock P y) = (y \in pblock P x).
Proof.
move=> tiP Px; apply/eqP/idP=> [eq_xy | /same_pblock-> //].
move: Px; rewrite -mem_pblock eq_xy /pblock.
by case: pickP => [B /andP[] // | _] /[1!inE].
Qed.
Lemma trivIsetU1 A P :
{in P, forall B, [disjoint A & B]} -> trivIset P -> set0 \notin P ->
trivIset (A |: P) /\ A \notin P.
Proof.
move=> tiAP tiP notPset0; split; last first.
apply: contra notPset0 => P_A.
by have:= tiAP A P_A; rewrite -setI_eq0 setIid => /eqP <-.
apply/trivIsetP=> B1 B2 /setU1P[->|PB1] /setU1P[->|PB2];
by [apply: (trivIsetP _ tiP) | rewrite ?eqxx // ?(tiAP, disjoint_sym)].
Qed.
Lemma cover_imset J F : cover (F @: J) = \bigcup_(i in J) F i.
Proof.
apply/setP=> x.
apply/bigcupP/bigcupP=> [[_ /imsetP[i Ji ->]] | [i]]; first by exists i.
by exists (F i); first apply: imset_f.
Qed.
Lemma trivIimset J F (P := F @: J) :
{in J &, forall i j, j != i -> [disjoint F i & F j]} -> set0 \notin P ->
trivIset P /\ {in J &, injective F}.
Proof.
move=> tiF notPset0; split=> [|i j Ji Jj /= eqFij].
apply/trivIsetP=> _ _ /imsetP[i Ji ->] /imsetP[j Jj ->] neqFij.
by rewrite tiF // (contraNneq _ neqFij) // => ->.
apply: contraNeq notPset0 => neq_ij; apply/imsetP; exists i => //; apply/eqP.
by rewrite eq_sym -[F i]setIid setI_eq0 {1}eqFij tiF.
Qed.
Lemma cover_partition P D : partition P D -> cover P = D.
Proof. by case/and3P=> /eqP. Qed.
Lemma partition0 P D : partition P D -> set0 \in P = false.
Proof. case/and3P => _ _. by apply: contraNF. Qed.
Lemma partition_neq0 P D B : partition P D -> B \in P -> B != set0.
Proof. by move=> partP; apply: contraTneq => ->; rewrite (partition0 partP). Qed.
Lemma partition_trivIset P D : partition P D -> trivIset P.
Proof. by case/and3P. Qed.
Lemma partitionS P D B : partition P D -> B \in P -> B \subset D.
Proof.
by move=> partP BP; rewrite -(cover_partition partP); apply: bigcup_max BP _.
Qed.
Lemma partitionD1 P D B :
partition P D -> B \in P -> partition (P :\ B) (D :\: B).
Proof.
case/and3P => /eqP covP trivP set0P SP.
by rewrite /partition inE (negbTE set0P) trivIsetD ?coverD1 -?covP ?eqxx ?andbF.
Qed.
Lemma partitionU1 P D B :
partition P D -> B != set0 -> [disjoint B & D] -> partition (B |: P) (B :|: D).
Proof.
case/and3P => /eqP covP trivP set0P BD0 disSD.
rewrite /partition !inE (negbTE set0P) orbF [_ == B]eq_sym BD0 andbT.
rewrite /cover bigcup_setU /= big_set1 -covP eqxx /=.
by move: disSD; rewrite -covP=> /bigcup_disjointP/trivIsetU1 => -[].
Qed.
Lemma partition_set0 P : partition P set0 = (P == set0).
Proof.
apply/and3P/eqP => [[/bigcup0P covP _ ]|->]; last first.
by rewrite /partition inE /trivIset/cover !big_set0 cards0 !eqxx.
by apply: contraNeq => /set0Pn[B BP]; rewrite -(covP B BP).
Qed.
Lemma card_partition P D : partition P D -> #|D| = \sum_(A in P) #|A|.
Proof. by case/and3P=> /eqP <- /eqnP. Qed.
Lemma card_uniform_partition n P D :
{in P, forall A, #|A| = n} -> partition P D -> #|D| = #|P| * n.
Proof.
by move=> uniP /card_partition->; rewrite -sum_nat_const; apply: eq_bigr.
Qed.
Lemma partition_pigeonhole P D A :
partition P D -> #|P| <= #|A| -> A \subset D -> {in P, forall B, #|A :&: B| <= 1} ->
{in P, forall B, A :&: B != set0}.
Proof.
move=> partP card_A_P /subsetP subAD sub1; apply/forall_inP.
apply: contraTT card_A_P => /forall_inPn [B BP]; rewrite negbK => AB0.
rewrite -!ltnNge -(setD1K BP) cardsU1 !inE eqxx /= add1n ltnS.
have [tP covP] := (partition_trivIset partP,cover_partition partP).
have APx x : x \in A -> x \in pblock P x by rewrite mem_pblock covP; apply: subAD.
have inj_f : {in A &, injective (pblock P)}.
move=> x y xA yA /eqP; rewrite eq_pblock ?covP ?subAD // => Pxy.
apply: (@card_le1_eqP _ (A :&: pblock P x)); rewrite ?inE ?Pxy ?APx ?andbT //.
by apply: sub1; rewrite pblock_mem ?covP ?subAD.
rewrite -(card_in_imset inj_f); apply: subset_leq_card.
apply/subsetP => ? /imsetP[x xA ->].
rewrite !inE pblock_mem ?covP ?subAD ?andbT //.
by apply: contraTneq AB0 => <-; apply/set0Pn; exists x; rewrite inE APx ?andbT.
Qed.
Section BigOps.
Variables (R : Type) (idx : R) (op : Monoid.com_law idx).
Let rhs_cond P K E := \big[op/idx]_(A in P) \big[op/idx]_(x in A | K x) E x.
Let rhs P E := \big[op/idx]_(A in P) \big[op/idx]_(x in A) E x.
Lemma big_trivIset_cond P (K : pred T) (E : T -> R) :
trivIset P -> \big[op/idx]_(x in cover P | K x) E x = rhs_cond P K E.
Proof.
move=> tiP; rewrite (partition_big (pblock P) [in P]) -/op => /= [|x].
apply: eq_bigr => A PA; apply: eq_bigl => x; rewrite andbAC; congr (_ && _).
rewrite -mem_pblock; apply/andP/idP=> [[Px /eqP <- //] | Ax].
by rewrite (def_pblock tiP PA Ax).
by case/andP=> Px _; apply: pblock_mem.
Qed.
Lemma big_trivIset P (E : T -> R) :
trivIset P -> \big[op/idx]_(x in cover P) E x = rhs P E.
Proof.
have biginT := eq_bigl _ _ (fun _ => andbT _) => tiP.
by rewrite -biginT big_trivIset_cond //; apply: eq_bigr => A _; apply: biginT.
Qed.
Lemma set_partition_big_cond P D (K : pred T) (E : T -> R) :
partition P D -> \big[op/idx]_(x in D | K x) E x = rhs_cond P K E.
Proof. by case/and3P=> /eqP <- tI_P _; apply: big_trivIset_cond. Qed.
Lemma set_partition_big P D (E : T -> R) :
partition P D -> \big[op/idx]_(x in D) E x = rhs P E.
Proof. by case/and3P=> /eqP <- tI_P _; apply: big_trivIset. Qed.
Lemma partition_disjoint_bigcup (F : I -> {set T}) E :
(forall i j, i != j -> [disjoint F i & F j]) ->
\big[op/idx]_(x in \bigcup_i F i) E x =
\big[op/idx]_i \big[op/idx]_(x in F i) E x.
Proof.
move=> disjF; pose P := [set F i | i in I & F i != set0].
have trivP: trivIset P.
apply/trivIsetP=> _ _ /imsetP[i _ ->] /imsetP[j _ ->] neqFij.
by apply: disjF; apply: contraNneq neqFij => ->.
have ->: \bigcup_i F i = cover P.
apply/esym; rewrite cover_imset big_mkcond; apply: eq_bigr => i _.
by rewrite inE; case: eqP.
rewrite big_trivIset // /rhs big_imset => [|i j _ /setIdP[_ notFj0] eqFij].
rewrite big_mkcond; apply: eq_bigr => i _; rewrite inE.
by case: eqP => //= ->; rewrite big_set0.
by apply: contraNeq (disjF _ _) _; rewrite -setI_eq0 eqFij setIid.
Qed.
End BigOps.
Section Equivalence.
Variables (R : rel T) (D : {set T}).
Let Px x := [set y in D | R x y].
Definition equivalence_partition := [set Px x | x in D].
Local Notation P := equivalence_partition.
Hypothesis eqiR : {in D & &, equivalence_rel R}.
Let Pxx x : x \in D -> x \in Px x.
Proof. by move=> Dx; rewrite !inE Dx (eqiR Dx Dx). Qed.
Let PPx x : x \in D -> Px x \in P := fun Dx => imset_f _ Dx.
Lemma equivalence_partitionP : partition P D.
Proof.
have defD: cover P == D.
rewrite eqEsubset; apply/andP; split.
by apply/bigcupsP=> _ /imsetP[x Dx ->]; rewrite /Px setIdE subsetIl.
by apply/subsetP=> x Dx; apply/bigcupP; exists (Px x); rewrite (Pxx, PPx).
have tiP: trivIset P.
apply/trivIsetP=> _ _ /imsetP[x Dx ->] /imsetP[y Dy ->]; apply: contraR.
case/pred0Pn=> z /andP[] /[!inE] /andP[Dz Rxz] /andP[_ Ryz].
apply/eqP/setP=> t /[!inE]; apply: andb_id2l => Dt.
by rewrite (eqiR Dx Dz Dt) // (eqiR Dy Dz Dt).
rewrite /partition tiP defD /=.
by apply/imsetP=> [[x /Pxx Px_x Px0]]; rewrite -Px0 inE in Px_x.
Qed.
Lemma pblock_equivalence_partition :
{in D &, forall x y, (y \in pblock P x) = R x y}.
Proof.
have [_ tiP _] := and3P equivalence_partitionP.
by move=> x y Dx Dy; rewrite /= (def_pblock tiP (PPx Dx) (Pxx Dx)) inE Dy.
Qed.
End Equivalence.
Lemma pblock_equivalence P D :
partition P D -> {in D & &, equivalence_rel (fun x y => y \in pblock P x)}.
Proof.
case/and3P=> /eqP <- tiP _ x y z Px Py Pz.
by rewrite mem_pblock; split=> // /same_pblock->.
Qed.
Lemma equivalence_partition_pblock P D :
partition P D -> equivalence_partition (fun x y => y \in pblock P x) D = P.
Proof.
case/and3P=> /eqP <-{D} tiP notP0; apply/setP=> B /=; set D := cover P.
have defP x: x \in D -> [set y in D | y \in pblock P x] = pblock P x.
by move=> Dx; apply/setIidPr; rewrite (bigcup_max (pblock P x)) ?pblock_mem.
apply/imsetP/idP=> [[x Px ->{B}] | PB]; first by rewrite defP ?pblock_mem.
have /set0Pn[x Bx]: B != set0 := memPn notP0 B PB.
have Px: x \in cover P by apply/bigcupP; exists B.
by exists x; rewrite // defP // (def_pblock tiP PB Bx).
Qed.
Section Preim.
Variables (rT : eqType) (f : T -> rT).
Definition preim_partition := equivalence_partition (fun x y => f x == f y).
Lemma preim_partitionP D : partition (preim_partition D) D.
Proof. by apply/equivalence_partitionP; split=> // /eqP->. Qed.
End Preim.
Lemma preim_partition_pblock P D :
partition P D -> preim_partition (pblock P) D = P.
Proof.
move=> partP; have [/eqP defD tiP _] := and3P partP.
rewrite -{2}(equivalence_partition_pblock partP); apply: eq_in_imset => x Dx.
by apply/setP=> y; rewrite !inE eq_pblock ?defD.
Qed.
Lemma transversalP P D : partition P D -> is_transversal (transversal P D) P D.
Proof.
case/and3P=> /eqP <- tiP notP0; apply/and3P; split; first exact/and3P.
apply/subsetP=> _ /imsetP[x Px ->]; case: pickP => //= y Pxy.
by apply/bigcupP; exists (pblock P x); rewrite ?pblock_mem //.
apply/forall_inP=> B PB; have /set0Pn[x Bx]: B != set0 := memPn notP0 B PB.
apply/cards1P; exists (odflt x [pick y in pblock P x]); apply/esym/eqP.
rewrite eqEsubset sub1set !inE -andbA; apply/andP; split.
by apply/imset_f/bigcupP; exists B.
rewrite (def_pblock tiP PB Bx); case def_y: _ / pickP => [y By | /(_ x)/idP//].
rewrite By /=; apply/subsetP=> _ /setIP[/imsetP[z Pz ->]].
case: {1}_ / pickP => [t zPt Bt | /(_ z)/idP[]]; last by rewrite mem_pblock.
by rewrite -(same_pblock tiP zPt) (def_pblock tiP PB Bt) def_y inE.
Qed.
Section Transversals.
Variables (X : {set T}) (P : {set {set T}}) (D : {set T}).
Hypothesis trPX : is_transversal X P D.
Lemma transversal_sub : X \subset D. Proof. by case/and3P: trPX. Qed.
Let tiP : trivIset P. Proof. by case/andP: trPX => /and3P[]. Qed.
Let sXP : {subset X <= cover P}.
Proof. by case/and3P: trPX => /andP[/eqP-> _] /subsetP. Qed.
Let trX : {in P, forall B, #|X :&: B| == 1}.
Proof. by case/and3P: trPX => _ _ /forall_inP. Qed.
Lemma setI_transversal_pblock x0 B :
B \in P -> X :&: B = [set transversal_repr x0 X B].
Proof.
by case/trX/cards1P=> x defXB; rewrite /transversal_repr defXB /pick enum_set1.
Qed.
Lemma repr_mem_pblock x0 B : B \in P -> transversal_repr x0 X B \in B.
Proof. by move=> PB; rewrite -sub1set -setI_transversal_pblock ?subsetIr. Qed.
Lemma repr_mem_transversal x0 B : B \in P -> transversal_repr x0 X B \in X.
Proof. by move=> PB; rewrite -sub1set -setI_transversal_pblock ?subsetIl. Qed.
Lemma transversal_reprK x0 : {in P, cancel (transversal_repr x0 X) (pblock P)}.
Proof. by move=> B PB; rewrite /= (def_pblock tiP PB) ?repr_mem_pblock. Qed.
Lemma pblockK x0 : {in X, cancel (pblock P) (transversal_repr x0 X)}.
Proof.
move=> x Xx; have /bigcupP[B PB Bx] := sXP Xx; rewrite (def_pblock tiP PB Bx).
by apply/esym/set1P; rewrite -setI_transversal_pblock // inE Xx.
Qed.
Lemma pblock_inj : {in X &, injective (pblock P)}.
Proof. by move=> x0; apply: (can_in_inj (pblockK x0)). Qed.
Lemma pblock_transversal : pblock P @: X = P.
Proof.
apply/setP=> B; apply/imsetP/idP=> [[x Xx ->] | PB].
by rewrite pblock_mem ?sXP.
have /cards1P[x0 _] := trX PB; set x := transversal_repr x0 X B.
by exists x; rewrite ?transversal_reprK ?repr_mem_transversal.
Qed.
Lemma card_transversal : #|X| = #|P|.
Proof. by rewrite -pblock_transversal card_in_imset //; apply: pblock_inj. Qed.
Lemma im_transversal_repr x0 : transversal_repr x0 X @: P = X.
Proof.
rewrite -{2}[X]imset_id -pblock_transversal -imset_comp.
by apply: eq_in_imset; apply: pblockK.
Qed.
End Transversals.
End Partitions.
Arguments trivIsetP {T P}.
Arguments big_trivIset_cond [T R idx op] P [K E].
Arguments set_partition_big_cond [T R idx op] P [D K E].
Arguments big_trivIset [T R idx op] P [E].
Arguments set_partition_big [T R idx op] P [D E].
Prenex Implicits cover trivIset partition pblock.
Lemma partition_partition (T : finType) (D : {set T}) P Q :
partition P D -> partition Q P ->
partition (cover @: Q) D /\ {in Q &, injective cover}.
Proof.
move=> /and3P[/eqP defG tiP notP0] /and3P[/eqP defP tiQ notQ0].
have sQP E: E \in Q -> {subset E <= P}.
by move=> Q_E; apply/subsetP; rewrite -defP (bigcup_max E).
rewrite /partition cover_imset -(big_trivIset _ tiQ) defP -defG eqxx /= andbC.
have{} notQ0: set0 \notin cover @: Q.
apply: contra notP0 => /imsetP[E Q_E E0].
have /set0Pn[/= A E_A] := memPn notQ0 E Q_E.
congr (_ \in P): (sQP E Q_E A E_A).
by apply/eqP; rewrite -subset0 E0 (bigcup_max A).
rewrite notQ0; apply: trivIimset => // E F Q_E Q_F.
apply: contraR => /pred0Pn[x /andP[/bigcupP[A E_A Ax] /bigcupP[B F_B Bx]]].
rewrite -(def_pblock tiQ Q_E E_A) -(def_pblock tiP _ Ax) ?(sQP E) //.
by rewrite -(def_pblock tiQ Q_F F_B) -(def_pblock tiP _ Bx) ?(sQP F).
Qed.
Lemma indexed_partition (I T : finType) (J : {pred I}) (B : I -> {set T}) :
let P := [set B i | i in J] in
{in J &, forall i j : I, j != i -> [disjoint B i & B j]} ->
(forall i : I, J i -> B i != set0) -> partition P (cover P) /\ {in J &, injective B}.
Proof.
move=> P disjB inhB; have s0NP : set0 \notin P.
by apply/negP => /imsetP[x xI /eqP]; apply/negP; rewrite eq_sym inhB.
by rewrite /partition eqxx s0NP andbT /=; apply: trivIimset.
Qed.
Section PartitionImage.
Variables (T : finType) (P : {set {set T}}) (D : {set T}).
Variables (T' : finType) (f : T -> T') (inj_f : injective f).
Let fP := [set f @: (B : {set T}) | B in P].
Lemma imset_trivIset : trivIset fP = trivIset P.
Proof.
apply/trivIsetP/trivIsetP => [trivP A B AP BP|].
- rewrite -(imset_disjoint inj_f) -(inj_eq (imset_inj inj_f)).
by apply: trivP; rewrite imset_f.
- move=> trivP ? ? /imsetP[A AP ->] /imsetP[B BP ->].
by rewrite (inj_eq (imset_inj inj_f)) imset_disjoint //; apply: trivP.
Qed.
Lemma imset0mem : (set0 \in fP) = (set0 \in P).
Proof.
apply/imsetP/idP => [[A AP /esym/eqP]|P0]; last by exists set0; rewrite ?imset0.
by rewrite imset_eq0 => /eqP<-.
Qed.
Lemma imset_partition : partition fP (f @: D) = partition P D.
Proof.
suff cov: (cover fP == f @:D) = (cover P == D).
by rewrite /partition -imset_trivIset imset0mem cov.
by rewrite /fP cover_imset -imset_cover (inj_eq (imset_inj inj_f)).
Qed.
End PartitionImage.
(**********************************************************************)
(* *)
(* Maximum and minimum (sub)set with respect to a given pred *)
(* *)
(**********************************************************************)
Section MaxSetMinSet.
Variable T : finType.
Notation sT := {set T}.
Implicit Types A B C : sT.
Implicit Type P : pred sT.
Definition minset P A := [forall (B : sT | B \subset A), (B == A) == P B].
Lemma minset_eq P1 P2 A : P1 =1 P2 -> minset P1 A = minset P2 A.
Proof. by move=> eP12; apply: eq_forallb => B; rewrite eP12. Qed.
Lemma minsetP P A :
reflect ((P A) /\ (forall B, P B -> B \subset A -> B = A)) (minset P A).
Proof.
apply: (iffP forallP) => [minA | [PA minA] B].
split; first by have:= minA A; rewrite subxx eqxx /= => /eqP.
by move=> B PB sBA; have:= minA B; rewrite PB sBA /= eqb_id => /eqP.
by apply/implyP=> sBA; apply/eqP; apply/eqP/idP=> [-> // | /minA]; apply.
Qed.
Arguments minsetP {P A}.
Lemma minsetp P A : minset P A -> P A.
Proof. by case/minsetP. Qed.
Lemma minsetinf P A B : minset P A -> P B -> B \subset A -> B = A.
Proof. by case/minsetP=> _; apply. Qed.
Lemma ex_minset P : (exists A, P A) -> {A | minset P A}.
Proof.
move=> exP; pose pS n := [pred B | P B & #|B| == n].
pose p n := ~~ pred0b (pS n); have{exP}: exists n, p n.
by case: exP => A PA; exists #|A|; apply/existsP; exists A; rewrite /= PA /=.
case/ex_minnP=> n /pred0P; case: (pickP (pS n)) => // A /andP[PA] /eqP <-{n} _.
move=> minA; exists A => //; apply/minsetP; split=> // B PB sBA; apply/eqP.
by rewrite eqEcard sBA minA //; apply/pred0Pn; exists B; rewrite /= PB /=.
Qed.
Lemma minset_exists P C : P C -> {A | minset P A & A \subset C}.
Proof.
move=> PC; have{PC}: exists A, P A && (A \subset C) by exists C; rewrite PC /=.
case/ex_minset=> A /minsetP[/andP[PA sAC] minA]; exists A => //; apply/minsetP.
by split=> // B PB sBA; rewrite (minA B) // PB (subset_trans sBA).
Qed.
(* The 'locked_with' allows Coq to find the value of P by unification. *)
Fact maxset_key : unit. Proof. by []. Qed.
Definition maxset P A :=
minset (fun B => locked_with maxset_key P (~: B)) (~: A).
Lemma maxset_eq P1 P2 A : P1 =1 P2 -> maxset P1 A = maxset P2 A.
Proof. by move=> eP12; apply: minset_eq => x /=; rewrite !unlock_with eP12. Qed.
Lemma maxminset P A : maxset P A = minset [pred B | P (~: B)] (~: A).
Proof. by rewrite /maxset unlock. Qed.
Lemma minmaxset P A : minset P A = maxset [pred B | P (~: B)] (~: A).
Proof.
by rewrite /maxset unlock setCK; apply: minset_eq => B /=; rewrite setCK.
Qed.
Lemma maxsetP P A :
reflect ((P A) /\ (forall B, P B -> A \subset B -> B = A)) (maxset P A).
Proof.
apply: (iffP minsetP); rewrite ?setCK unlock_with => [] [PA minA].
by split=> // B PB sAB; rewrite -[B]setCK [~: B]minA (setCK, setCS).
by split=> // B PB' sBA'; rewrite -(minA _ PB') -1?setCS setCK.
Qed.
Lemma maxsetp P A : maxset P A -> P A.
Proof. by case/maxsetP. Qed.
Lemma maxsetsup P A B : maxset P A -> P B -> A \subset B -> B = A.
Proof. by case/maxsetP=> _; apply. Qed.
Lemma ex_maxset P : (exists A, P A) -> {A | maxset P A}.
Proof.
move=> exP; have{exP}: exists A, P (~: A).
by case: exP => A PA; exists (~: A); rewrite setCK.
by case/ex_minset=> A minA; exists (~: A); rewrite /maxset unlock setCK.
Qed.
Lemma maxset_exists P C : P C -> {A : sT | maxset P A & C \subset A}.
Proof.
move=> PC; pose P' B := P (~: B); have: P' (~: C) by rewrite /P' setCK.
case/minset_exists=> B; rewrite -[B]setCK setCS.
by exists (~: B); rewrite // /maxset unlock.
Qed.
End MaxSetMinSet.
Arguments setCK {T}.
Arguments minsetP {T P A}.
Arguments maxsetP {T P A}.
Prenex Implicits minset maxset.
Section SetFixpoint.
Section Least.
Variables (T : finType) (F : {set T} -> {set T}).
Hypothesis (F_mono : {homo F : X Y / X \subset Y}).
Let n := #|T|.
Let iterF i := iter i F set0.
Lemma subset_iterS i : iterF i \subset iterF i.+1.
Proof. by elim: i => [| i IHi]; rewrite /= ?sub0set ?F_mono. Qed.
Lemma subset_iter : {homo iterF : i j / i <= j >-> i \subset j}.
Proof.
by apply: homo_leq => //[? ? ?|]; [apply: subset_trans|apply: subset_iterS].
Qed.
Definition fixset := iterF n.
Lemma fixsetK : F fixset = fixset.
Proof.
suff /'exists_eqP[x /= e]: [exists k : 'I_n.+1, iterF k == iterF k.+1].
by rewrite /fixset -(subnK (leq_ord x)) /iterF iterD iter_fix.
apply: contraT => /existsPn /(_ (Ordinal _)) /= neq_iter.
suff iter_big k : k <= n.+1 -> k <= #|iter k F set0|.
by have := iter_big _ (leqnn _); rewrite ltnNge max_card.
elim: k => [|k IHk] k_lt //=; apply: (leq_ltn_trans (IHk (ltnW k_lt))).
by rewrite proper_card// properEneq// subset_iterS neq_iter.
Qed.
Hint Resolve fixsetK : core.
Lemma minset_fix : minset [pred X | F X == X] fixset.
Proof.
apply/minsetP; rewrite inE fixsetK eqxx; split=> // X /eqP FXeqX Xsubfix.
apply/eqP; rewrite eqEsubset Xsubfix/=.
suff: fixset \subset iter n F X by rewrite iter_fix.
by rewrite /fixset; elim: n => //= [|m IHm]; rewrite ?sub0set ?F_mono.
Qed.
Lemma fixsetKn k : iter k F fixset = fixset.
Proof. by rewrite iter_fix. Qed.
Lemma iter_sub_fix k : iterF k \subset fixset.
Proof.
have [/subset_iter //|/ltnW/subnK<-] := leqP k n;
by rewrite /iterF iterD fixsetKn.
Qed.
Lemma fix_order_proof x : x \in fixset -> exists n, x \in iterF n.
Proof. by move=> x_fix; exists n. Qed.
Definition fix_order (x : T) :=
if (x \in fixset) =P true isn't ReflectT x_fix then 0
else (ex_minn (fix_order_proof x_fix)).
Lemma fix_order_le_max (x : T) : fix_order x <= n.
Proof.
rewrite /fix_order; case: eqP => //= x_in.
by case: ex_minnP => //= ? ?; apply.
Qed.
Lemma in_iter_fix_orderE (x : T) :
(x \in iterF (fix_order x)) = (x \in fixset).
Proof.
rewrite /fix_order; case: eqP => [x_in | /negP/negPf-> /[1!inE]//].
by case: ex_minnP => m ->; rewrite x_in.
Qed.
Lemma fix_order_gt0 (x : T) : (fix_order x > 0) = (x \in fixset).
Proof.
rewrite /fix_order; case: eqP => [x_in | /negP/negPf->//].
by rewrite x_in; case: ex_minnP => -[/[!inE] | m].
Qed.
Lemma fix_order_eq0 (x : T) : (fix_order x == 0) = (x \notin fixset).
Proof. by rewrite -fix_order_gt0 -ltnNge ltnS leqn0. Qed.
Lemma in_iter_fixE (x : T) k : (x \in iterF k) = (0 < fix_order x <= k).
Proof.
rewrite /fix_order; case: eqP => //= [x_in|/negP xNin]; last first.
by apply: contraNF xNin; apply/subsetP/iter_sub_fix.
case: ex_minnP => -[/[!inE]//|m] xm mP.
by apply/idP/idP=> [/mP//|lt_mk]; apply: subsetP xm; apply: subset_iter.
Qed.
Lemma in_iter (x : T) k : x \in fixset -> fix_order x <= k -> x \in iterF k.
Proof. by move=> x_in xk; rewrite in_iter_fixE fix_order_gt0 x_in xk. Qed.
Lemma notin_iter (x : T) k : k < fix_order x -> x \notin iterF k.
Proof. by move=> k_le; rewrite in_iter_fixE negb_and orbC -ltnNge k_le. Qed.
Lemma fix_order_small x k : x \in iterF k -> fix_order x <= k.
Proof. by rewrite in_iter_fixE => /andP[]. Qed.
Lemma fix_order_big x k : x \in fixset -> x \notin iterF k -> fix_order x > k.
Proof. by move=> x_in; rewrite in_iter_fixE fix_order_gt0 x_in /= -ltnNge. Qed.
Lemma le_fix_order (x y : T) : y \in iterF (fix_order x) ->
fix_order y <= fix_order x.
Proof. exact: fix_order_small. Qed.
End Least.
Section Greatest.
Variables (T : finType) (F : {set T} -> {set T}).
Hypothesis (F_mono : {homo F : X Y / X \subset Y}).
Definition funsetC X := ~: (F (~: X)).
Lemma funsetC_mono : {homo funsetC : X Y / X \subset Y}.
Proof. by move=> *; rewrite subCset setCK F_mono// subCset setCK. Qed.
Hint Resolve funsetC_mono : core.
Definition cofixset := ~: fixset funsetC.
Lemma cofixsetK : F cofixset = cofixset.
Proof. by rewrite /cofixset -[in RHS]fixsetK ?setCK. Qed.
Lemma maxset_cofix : maxset [pred X | F X == X] cofixset.
Proof.
rewrite maxminset setCK.
rewrite (@minset_eq _ _ [pred X | funsetC X == X]) ?minset_fix//.
by move=> X /=; rewrite (can2_eq setCK setCK).
Qed.
End Greatest.
End SetFixpoint.
Section FProd.
Variables (I : finType) (T_ : I -> finType).
Lemma card_fprod : #|fprod T_| = \prod_(i : I) #|T_ i|.
Proof.
rewrite card_sub (card_family (tagged_with T_)) foldrE big_image/=.
apply: eq_bigr => i _/=; rewrite -card_sig; apply/esym.
exact: bij_eq_card (tag_with_bij T_ i).
Qed.
Definition fprod_pick : 0 < #|fprod T_| -> forall i : I, T_ i.
Proof.
by rewrite card_fprod => /[swap] i /gt0_prodn/(_ i isT) /card_gt0P/sigW[].
Qed.
Definition ftagged (T_gt0 : 0 < #|fprod T_|)
(f : {ffun I -> {i : I & T_ i}}) (i : I) :=
@untag I T_ (T_ i) (fprod_pick T_gt0 i) i id (f i).
Lemma ftaggedE t T_gt0 i : ftagged T_gt0 (fprod_fun t) i = t i.
Proof. by rewrite /ftagged untagE ?tag_fprod_fun// => e; rewrite etaggedE. Qed.
End FProd.
Section BigTag.
Variables (R : Type) (idx : R) (op : Monoid.com_law idx).
Variables (I : finType) (T_ : I -> finType).
Lemma big_tag_cond (Q_ : forall i, {pred T_ i})
(P_ : forall i : I, T_ i -> R) (i : I) :
\big[op/idx]_(j in Q_ i) P_ i j =
\big[op/idx]_(j in tagged_with T_ i | untag true (Q_ i) j)
untag idx (P_ i) j.
Proof.
rewrite (big_sub_cond (tagged_with T_ i)).
rewrite (reindex (tag_with i)); last exact/onW_bij/tag_with_bij.
by apply: eq_big => [x|x Qix]; rewrite ?untagE.
Qed.
Lemma big_tag (P_ : forall i : I, T_ i -> R) (i : I) :
\big[op/idx]_(j : T_ i) P_ i j =
\big[op/idx]_(j in tagged_with T_ i) untag idx (P_ i) j.
Proof. by rewrite big_tag_cond; under eq_bigl do rewrite untag_cst ?andbT. Qed.
End BigTag.
Arguments big_tag_cond [R idx op I T_] _ _ _.
Arguments big_tag [R idx op I T_] _ _.
Section BigFProd.
Variables (R : Type) (zero one : R) (times : R -> R -> R).
Variables (plus : Monoid.add_law zero times).
Variables (I : finType) (T_ : I -> finType).
Variables (P_ : forall i : I, {ffun T_ i -> R}).
Let T := fprod T_.
Lemma big_fprod_dep (Q : {pred {ffun I -> {i : I & (T_ i)}}}) :
\big[plus/zero]_(t : T | Q (fprod_fun t)) \big[times/one]_(i : I) P_ i (t i) =
\big[plus/zero]_(g in family (tagged_with T_) | Q g)
\big[times/one]_(i : I) (untag zero (P_ i) (g i)).
Proof.
rewrite (reindex (@of_family_tagged_with _ T_)); last first.
exact/onW_bij/of_family_tagged_with_bij.
rewrite [in RHS]big_sub_cond; apply/esym/eq_bigr => -[/= f fP] Qf.
apply: eq_bigr => i _; rewrite /fun_of_fprod/=.
by case: (f i) ('forall_eqP _ _) => //= j t; case: _ /; rewrite untagE.
Qed.
Lemma big_fprod :
\big[plus/zero]_(t : T) \big[times/one]_(i in I) P_ i (t i) =
\big[plus/zero]_(g in family (tagged_with T_))
\big[times/one]_(i : I) (untag zero (P_ i) (g i)).
Proof. by rewrite (big_fprod_dep predT) big_mkcondr. Qed.
End BigFProd.
|
Basis.lean
|
/-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.LinearAlgebra.TensorAlgebra.Basic
import Mathlib.LinearAlgebra.FreeAlgebra
/-!
# A basis for `TensorAlgebra R M`
## Main definitions
* `TensorAlgebra.equivMonoidAlgebra b : TensorAlgebra R M ≃ₐ[R] FreeAlgebra R κ`:
the isomorphism given by a basis `b : Basis κ R M`.
* `Basis.tensorAlgebra b : Basis (FreeMonoid κ) R (TensorAlgebra R M)`:
the basis on the tensor algebra given by a basis `b : Basis κ R M`.
## Main results
* `TensorAlgebra.instFreeModule`: the tensor algebra over `M` is free when `M` is
* `TensorAlgebra.rank_eq`
-/
open Module
namespace TensorAlgebra
universe uκ uR uM
variable {κ : Type uκ} {R : Type uR} {M : Type uM}
section CommSemiring
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
/-- A basis provides an algebra isomorphism with the free algebra, replacing each basis vector
with its index. -/
noncomputable def equivFreeAlgebra (b : Basis κ R M) :
TensorAlgebra R M ≃ₐ[R] FreeAlgebra R κ :=
AlgEquiv.ofAlgHom
(TensorAlgebra.lift _ (Finsupp.linearCombination _ (FreeAlgebra.ι _) ∘ₗ b.repr.toLinearMap))
(FreeAlgebra.lift _ (ι R ∘ b))
(by ext; simp)
(hom_ext <| b.ext fun i => by simp)
@[simp]
lemma equivFreeAlgebra_ι_apply (b : Basis κ R M) (i : κ) :
equivFreeAlgebra b (ι R (b i)) = FreeAlgebra.ι R i :=
(TensorAlgebra.lift_ι_apply _ _).trans <| by simp
@[simp]
lemma equivFreeAlgebra_symm_ι (b : Basis κ R M) (i : κ) :
(equivFreeAlgebra b).symm (FreeAlgebra.ι R i) = ι R (b i) :=
(equivFreeAlgebra b).toEquiv.symm_apply_eq.mpr <| equivFreeAlgebra_ι_apply b i |>.symm
/-- A basis on `M` can be lifted to a basis on `TensorAlgebra R M` -/
@[simps! repr_apply]
noncomputable def _root_.Module.Basis.tensorAlgebra (b : Basis κ R M) :
Basis (FreeMonoid κ) R (TensorAlgebra R M) :=
(FreeAlgebra.basisFreeMonoid R κ).map <| (equivFreeAlgebra b).symm.toLinearEquiv
/-- `TensorAlgebra R M` is free when `M` is. -/
instance instModuleFree [Module.Free R M] : Module.Free R (TensorAlgebra R M) :=
let ⟨⟨_κ, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
.of_basis b.tensorAlgebra
/-- The `TensorAlgebra` of a free module over a commutative semiring with no zero-divisors has
no zero-divisors. -/
instance instNoZeroDivisors [NoZeroDivisors R] [Module.Free R M] :
NoZeroDivisors (TensorAlgebra R M) :=
have ⟨⟨_, b⟩⟩ := ‹Module.Free R M›
(equivFreeAlgebra b).toMulEquiv.noZeroDivisors
end CommSemiring
section CommRing
variable [CommRing R] [AddCommGroup M] [Module R M]
/-- The `TensorAlgebra` of a free module over an integral domain is a domain. -/
instance instIsDomain [IsDomain R] [Module.Free R M] : IsDomain (TensorAlgebra R M) :=
NoZeroDivisors.to_isDomain _
attribute [pp_with_univ] Cardinal.lift
open Cardinal in
lemma rank_eq [Nontrivial R] [Module.Free R M] :
Module.rank R (TensorAlgebra R M) = Cardinal.lift.{uR} (sum fun n ↦ Module.rank R M ^ n) := by
let ⟨⟨κ, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M)
rw [(equivFreeAlgebra b).toLinearEquiv.rank_eq, FreeAlgebra.rank_eq, mk_list_eq_sum_pow,
Basis.mk_eq_rank'' b]
end CommRing
end TensorAlgebra
|
Basic.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot
-/
import Mathlib.Order.Filter.Bases.Basic
import Mathlib.Order.Filter.AtTopBot.Tendsto
import Mathlib.Order.Nat
import Mathlib.Tactic.Subsingleton
/-!
# Basic results on `Filter.atTop` and `Filter.atBot` filters
In this file we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”.
-/
assert_not_exists Finset
variable {ι ι' α β γ : Type*}
open Set
namespace Filter
section IsDirected
variable [Preorder α] [IsDirected α (· ≤ ·)] {p : α → Prop}
theorem hasAntitoneBasis_atTop [Nonempty α] : (@atTop α _).HasAntitoneBasis Ici :=
.iInf_principal fun _ _ ↦ Ici_subset_Ici.2
theorem atTop_basis [Nonempty α] : (@atTop α _).HasBasis (fun _ => True) Ici :=
hasAntitoneBasis_atTop.1
lemma atTop_basis_Ioi [Nonempty α] [NoMaxOrder α] : (@atTop α _).HasBasis (fun _ => True) Ioi :=
atTop_basis.to_hasBasis (fun a ha => ⟨a, ha, Ioi_subset_Ici_self⟩) fun a ha =>
(exists_gt a).imp fun _b hb => ⟨ha, Ici_subset_Ioi.2 hb⟩
lemma atTop_basis_Ioi' [NoMaxOrder α] (a : α) : atTop.HasBasis (a < ·) Ioi := by
have : Nonempty α := ⟨a⟩
refine atTop_basis_Ioi.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩
obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b
obtain ⟨d, hcd⟩ := exists_gt c
exact ⟨d, hac.trans_lt hcd, Ioi_subset_Ioi (hbc.trans hcd.le)⟩
theorem atTop_basis' (a : α) : atTop.HasBasis (a ≤ ·) Ici := by
have : Nonempty α := ⟨a⟩
refine atTop_basis.to_hasBasis (fun b _ ↦ ?_) fun b _ ↦ ⟨b, trivial, Subset.rfl⟩
obtain ⟨c, hac, hbc⟩ := exists_ge_ge a b
exact ⟨c, hac, Ici_subset_Ici.2 hbc⟩
variable [Nonempty α]
@[instance]
lemma atTop_neBot : NeBot (atTop : Filter α) := atTop_basis.neBot_iff.2 fun _ => nonempty_Ici
theorem atTop_neBot_iff {α : Type*} [Preorder α] :
(atTop : Filter α).NeBot ↔ Nonempty α ∧ IsDirected α (· ≤ ·) := by
refine ⟨fun h ↦ ⟨nonempty_of_neBot atTop, ⟨fun x y ↦ ?_⟩⟩, fun ⟨h₁, h₂⟩ ↦ atTop_neBot⟩
exact ((eventually_ge_atTop x).and (eventually_ge_atTop y)).exists
theorem atBot_neBot_iff {α : Type*} [Preorder α] :
(atBot : Filter α).NeBot ↔ Nonempty α ∧ IsDirected α (· ≥ ·) :=
atTop_neBot_iff (α := αᵒᵈ)
@[simp] lemma mem_atTop_sets {s : Set α} : s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s :=
atTop_basis.mem_iff.trans <| exists_congr fun _ => iff_of_eq (true_and _)
@[simp] lemma eventually_atTop : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b := mem_atTop_sets
theorem frequently_atTop : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b ≥ a, p b :=
atTop_basis.frequently_iff.trans <| by simp
alias ⟨Eventually.exists_forall_of_atTop, _⟩ := eventually_atTop
lemma exists_eventually_atTop {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atTop, r a b) ↔ ∀ᶠ a₀ in atTop, ∃ b, ∀ a ≥ a₀, r a b := by
simp_rw [eventually_atTop, ← exists_swap (α := α)]
exact exists_congr fun a ↦ .symm <| forall_ge_iff <| Monotone.exists fun _ _ _ hb H n hn ↦
H n (hb.trans hn)
theorem map_atTop_eq {f : α → β} : atTop.map f = ⨅ a, 𝓟 (f '' { a' | a ≤ a' }) :=
(atTop_basis.map f).eq_iInf
theorem frequently_atTop' [NoMaxOrder α] : (∃ᶠ x in atTop, p x) ↔ ∀ a, ∃ b > a, p b :=
atTop_basis_Ioi.frequently_iff.trans <| by simp
end IsDirected
section IsCodirected
variable [Preorder α] [IsDirected α (· ≥ ·)] {p : α → Prop}
lemma atBot_basis_Iio [Nonempty α] [NoMinOrder α] : (@atBot α _).HasBasis (fun _ => True) Iio :=
atTop_basis_Ioi (α := αᵒᵈ)
lemma atBot_basis_Iio' [NoMinOrder α] (a : α) : atBot.HasBasis (· < a) Iio :=
atTop_basis_Ioi' (α := αᵒᵈ) a
lemma atBot_basis' (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic := atTop_basis' (α := αᵒᵈ) _
variable [Nonempty α]
lemma atBot_basis : (@atBot α _).HasBasis (fun _ => True) Iic := atTop_basis (α := αᵒᵈ)
@[instance] lemma atBot_neBot : NeBot (atBot : Filter α) := atTop_neBot (α := αᵒᵈ)
@[simp] lemma mem_atBot_sets {s : Set α} : s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s :=
mem_atTop_sets (α := αᵒᵈ)
@[simp] lemma eventually_atBot : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b := mem_atBot_sets
theorem frequently_atBot : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b ≤ a, p b := frequently_atTop (α := αᵒᵈ)
alias ⟨Eventually.exists_forall_of_atBot, _⟩ := eventually_atBot
lemma exists_eventually_atBot {r : α → β → Prop} :
(∃ b, ∀ᶠ a in atBot, r a b) ↔ ∀ᶠ a₀ in atBot, ∃ b, ∀ a ≤ a₀, r a b :=
exists_eventually_atTop (α := αᵒᵈ)
theorem map_atBot_eq {f : α → β} : atBot.map f = ⨅ a, 𝓟 (f '' { a' | a' ≤ a }) :=
map_atTop_eq (α := αᵒᵈ)
theorem frequently_atBot' [NoMinOrder α] : (∃ᶠ x in atBot, p x) ↔ ∀ a, ∃ b < a, p b :=
frequently_atTop' (α := αᵒᵈ)
end IsCodirected
/-!
### Sequences
-/
@[deprecated (since := "2025-04-20")] alias extraction_of_frequently_atTop' :=
Nat.exists_strictMono_subsequence
theorem extraction_of_frequently_atTop {P : ℕ → Prop} (h : ∃ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) := by
rw [frequently_atTop'] at h
exact Nat.exists_strictMono_subsequence h
theorem extraction_of_eventually_atTop {P : ℕ → Prop} (h : ∀ᶠ n in atTop, P n) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P (φ n) :=
extraction_of_frequently_atTop h.frequently
theorem extraction_forall_of_frequently {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) := by
simp only [frequently_atTop'] at h
choose u hu hu' using h
use (fun n => Nat.recOn n (u 0 0) fun n v => u (n + 1) v : ℕ → ℕ)
constructor
· apply strictMono_nat_of_lt_succ
intro n
apply hu
· intro n
cases n <;> simp [hu']
theorem extraction_forall_of_eventually {P : ℕ → ℕ → Prop} (h : ∀ n, ∀ᶠ k in atTop, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_frequently fun n => (h n).frequently
theorem extraction_forall_of_eventually' {P : ℕ → ℕ → Prop} (h : ∀ n, ∃ N, ∀ k ≥ N, P n k) :
∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, P n (φ n) :=
extraction_forall_of_eventually (by simp [eventually_atTop, h])
section IsDirected
variable [Preorder α] [IsDirected α (· ≤ ·)] {F : Filter β} {u : α → β}
theorem inf_map_atTop_neBot_iff [Nonempty α] :
NeBot (F ⊓ map u atTop) ↔ ∀ U ∈ F, ∀ N, ∃ n ≥ N, u n ∈ U := by
simp_rw [inf_neBot_iff_frequently_left, frequently_map, frequently_atTop]; rfl
variable [Preorder β]
lemma exists_le_of_tendsto_atTop (h : Tendsto u atTop atTop) (a : α) (b : β) :
∃ a' ≥ a, b ≤ u a' := by
have : Nonempty α := ⟨a⟩
have : ∀ᶠ x in atTop, a ≤ x ∧ b ≤ u x :=
(eventually_ge_atTop a).and (h.eventually <| eventually_ge_atTop b)
exact this.exists
theorem exists_le_of_tendsto_atBot (h : Tendsto u atTop atBot) :
∀ a b, ∃ a' ≥ a, u a' ≤ b := exists_le_of_tendsto_atTop (β := βᵒᵈ) h
theorem exists_lt_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto u atTop atTop) (a : α) (b : β) :
∃ a' ≥ a, b < u a' := by
obtain ⟨b', hb'⟩ := exists_gt b
rcases exists_le_of_tendsto_atTop h a b' with ⟨a', ha', ha''⟩
exact ⟨a', ha', lt_of_lt_of_le hb' ha''⟩
theorem exists_lt_of_tendsto_atBot [NoMinOrder β] (h : Tendsto u atTop atBot) :
∀ a b, ∃ a' ≥ a, u a' < b := exists_lt_of_tendsto_atTop (β := βᵒᵈ) h
end IsDirected
section IsCodirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {F : Filter β} {u : α → β}
theorem inf_map_atBot_neBot_iff : NeBot (F ⊓ map u atBot) ↔ ∀ U ∈ F, ∀ N, ∃ n ≤ N, u n ∈ U :=
inf_map_atTop_neBot_iff (α := αᵒᵈ)
end IsCodirected
section IsDirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] {f : α → β} {l : Filter β}
theorem tendsto_atTop' : Tendsto f atTop l ↔ ∀ s ∈ l, ∃ a, ∀ b ≥ a, f b ∈ s := by
simp only [tendsto_def, mem_atTop_sets, mem_preimage]
theorem tendsto_atTop_principal {s : Set β} : Tendsto f atTop (𝓟 s) ↔ ∃ N, ∀ n ≥ N, f n ∈ s := by
simp_rw [tendsto_iff_comap, comap_principal, le_principal_iff, mem_atTop_sets, mem_preimage]
variable [Preorder β]
/-- A function `f` grows to `+∞` independent of an order-preserving embedding `e`. -/
theorem tendsto_atTop_atTop : Tendsto f atTop atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → b ≤ f a :=
tendsto_iInf.trans <| forall_congr' fun _ => tendsto_atTop_principal
theorem tendsto_atTop_atBot : Tendsto f atTop atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, i ≤ a → f a ≤ b :=
tendsto_atTop_atTop (β := βᵒᵈ)
theorem tendsto_atTop_atTop_iff_of_monotone (hf : Monotone f) :
Tendsto f atTop atTop ↔ ∀ b : β, ∃ a, b ≤ f a :=
tendsto_atTop_atTop.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans h <| hf ha'⟩
theorem tendsto_atTop_atBot_iff_of_antitone (hf : Antitone f) :
Tendsto f atTop atBot ↔ ∀ b : β, ∃ a, f a ≤ b :=
tendsto_atTop_atTop_iff_of_monotone (β := βᵒᵈ) hf
end IsDirected
section IsCodirected
variable [Nonempty α] [Preorder α] [IsDirected α (· ≥ ·)] {f : α → β} {l : Filter β}
theorem tendsto_atBot' : Tendsto f atBot l ↔ ∀ s ∈ l, ∃ a, ∀ b ≤ a, f b ∈ s :=
tendsto_atTop' (α := αᵒᵈ)
theorem tendsto_atBot_principal {s : Set β} : Tendsto f atBot (𝓟 s) ↔ ∃ N, ∀ n ≤ N, f n ∈ s :=
tendsto_atTop_principal (α := αᵒᵈ) (β := βᵒᵈ)
variable [Preorder β]
theorem tendsto_atBot_atTop : Tendsto f atBot atTop ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → b ≤ f a :=
tendsto_atTop_atTop (α := αᵒᵈ)
theorem tendsto_atBot_atBot : Tendsto f atBot atBot ↔ ∀ b : β, ∃ i : α, ∀ a : α, a ≤ i → f a ≤ b :=
tendsto_atTop_atTop (α := αᵒᵈ) (β := βᵒᵈ)
theorem tendsto_atBot_atBot_iff_of_monotone (hf : Monotone f) :
Tendsto f atBot atBot ↔ ∀ b : β, ∃ a, f a ≤ b :=
tendsto_atBot_atBot.trans <| forall_congr' fun _ => exists_congr fun a =>
⟨fun h => h a (le_refl a), fun h _a' ha' => le_trans (hf ha') h⟩
theorem tendsto_atBot_atTop_iff_of_antitone (hf : Antitone f) :
Tendsto f atBot atTop ↔ ∀ b : β, ∃ a, b ≤ f a :=
tendsto_atBot_atBot_iff_of_monotone (β := βᵒᵈ) hf
end IsCodirected
alias _root_.Monotone.tendsto_atTop_atTop_iff := tendsto_atTop_atTop_iff_of_monotone
alias _root_.Monotone.tendsto_atBot_atBot_iff := tendsto_atBot_atBot_iff_of_monotone
theorem Tendsto.subseq_mem {F : Filter α} {V : ℕ → Set α} (h : ∀ n, V n ∈ F) {u : ℕ → α}
(hu : Tendsto u atTop F) : ∃ φ : ℕ → ℕ, StrictMono φ ∧ ∀ n, u (φ n) ∈ V n :=
extraction_forall_of_eventually'
(fun n => tendsto_atTop'.mp hu _ (h n) : ∀ n, ∃ N, ∀ k ≥ N, u k ∈ V n)
/-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connection above `b`. -/
theorem map_atTop_eq_of_gc_preorder
[Preorder α] [IsDirected α (· ≤ ·)] [Preorder β] [IsDirected β (· ≤ ·)] {f : α → β}
(hf : Monotone f) (b : β)
(hgi : ∀ c ≥ b, ∃ x, f x = c ∧ ∀ a, f a ≤ c ↔ a ≤ x) : map f atTop = atTop := by
have : Nonempty α := (hgi b le_rfl).nonempty
choose! g hfg hgle using hgi
refine le_antisymm (hf.tendsto_atTop_atTop fun c ↦ ?_) ?_
· rcases exists_ge_ge c b with ⟨d, hcd, hbd⟩
exact ⟨g d, hcd.trans (hfg d hbd).ge⟩
· have : Nonempty α := ⟨g b⟩
rw [(atTop_basis.map f).ge_iff]
intro a _
filter_upwards [eventually_ge_atTop (f a), eventually_ge_atTop b] with c hac hbc
exact ⟨g c, (hgle _ hbc _).1 hac, hfg _ hbc⟩
/-- A function `f` maps upwards closed sets (atTop sets) to upwards closed sets when it is a
Galois insertion. The Galois "insertion" and "connection" is weakened to only require it to be an
insertion and a connection above `b`. -/
theorem map_atTop_eq_of_gc
[Preorder α] [IsDirected α (· ≤ ·)] [PartialOrder β] [IsDirected β (· ≤ ·)]
{f : α → β} (g : β → α) (b : β) (hf : Monotone f)
(gc : ∀ a, ∀ c ≥ b, f a ≤ c ↔ a ≤ g c) (hgi : ∀ c ≥ b, c ≤ f (g c)) :
map f atTop = atTop :=
map_atTop_eq_of_gc_preorder hf b fun c hc ↦
⟨g c, le_antisymm ((gc _ _ hc).2 le_rfl) (hgi c hc), (gc · c hc)⟩
theorem map_atBot_eq_of_gc_preorder
[Preorder α] [IsDirected α (· ≥ ·)] [Preorder β] [IsDirected β (· ≥ ·)] {f : α → β}
(hf : Monotone f) (b : β)
(hgi : ∀ c ≤ b, ∃ x, f x = c ∧ ∀ a, c ≤ f a ↔ x ≤ a) : map f atBot = atBot :=
map_atTop_eq_of_gc_preorder (α := αᵒᵈ) (β := βᵒᵈ) hf.dual _ hgi
theorem map_atBot_eq_of_gc [Preorder α] [IsDirected α (· ≥ ·)]
[PartialOrder β] [IsDirected β (· ≥ ·)] {f : α → β} (g : β → α) (b' : β)
(hf : Monotone f) (gc : ∀ a, ∀ b ≤ b', b ≤ f a ↔ g b ≤ a) (hgi : ∀ b ≤ b', f (g b) ≤ b) :
map f atBot = atBot :=
map_atTop_eq_of_gc (α := αᵒᵈ) (β := βᵒᵈ) _ _ hf.dual gc hgi
theorem map_val_atTop_of_Ici_subset [Preorder α] [IsDirected α (· ≤ ·)] {a : α} {s : Set α}
(h : Ici a ⊆ s) : map ((↑) : s → α) atTop = atTop := by
choose f hl hr using exists_ge_ge (α := α)
have : DirectedOn (· ≤ ·) s := fun x _ y _ ↦
⟨f a (f x y), h <| hl _ _, (hl x y).trans (hr _ _), (hr x y).trans (hr _ _)⟩
have : IsDirected s (· ≤ ·) := by
rw [directedOn_iff_directed] at this
rwa [← directed_id_iff]
refine map_atTop_eq_of_gc_preorder (Subtype.mono_coe _) a fun c hc ↦ ?_
exact ⟨⟨c, h hc⟩, rfl, fun _ ↦ .rfl⟩
@[simp]
theorem _root_.Nat.map_cast_int_atTop : map ((↑) : ℕ → ℤ) atTop = atTop := by
refine map_atTop_eq_of_gc_preorder (fun _ _ ↦ Int.ofNat_le.2) 0 fun n hn ↦ ?_
lift n to ℕ using hn
exact ⟨n, rfl, fun _ ↦ Int.ofNat_le⟩
/-- The image of the filter `atTop` on `Ici a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)] (a : α) :
map ((↑) : Ici a → α) atTop = atTop :=
map_val_atTop_of_Ici_subset Subset.rfl
/-- The image of the filter `atTop` on `Ioi a` under the coercion equals `atTop`. -/
@[simp]
theorem map_val_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)] [NoMaxOrder α] (a : α) :
map ((↑) : Ioi a → α) atTop = atTop :=
let ⟨_b, hb⟩ := exists_gt a
map_val_atTop_of_Ici_subset <| Ici_subset_Ioi.2 hb
/-- The `atTop` filter for an open interval `Ioi a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ioi_eq [Preorder α] [IsDirected α (· ≤ ·)] (a : α) :
atTop = comap ((↑) : Ioi a → α) atTop := by
rcases isEmpty_or_nonempty (Ioi a) with h|⟨⟨b, hb⟩⟩
· subsingleton
· rw [← map_val_atTop_of_Ici_subset (Ici_subset_Ioi.2 hb), comap_map Subtype.coe_injective]
/-- The `atTop` filter for an open interval `Ici a` comes from the `atTop` filter in the ambient
order. -/
theorem atTop_Ici_eq [Preorder α] [IsDirected α (· ≤ ·)] (a : α) :
atTop = comap ((↑) : Ici a → α) atTop := by
rw [← map_val_Ici_atTop a, comap_map Subtype.coe_injective]
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)] [NoMinOrder α] (a : α) :
map ((↑) : Iio a → α) atBot = atBot :=
map_val_Ioi_atTop (OrderDual.toDual a)
/-- The `atBot` filter for an open interval `Iio a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iio_eq [Preorder α] [IsDirected α (· ≥ ·)] (a : α) :
atBot = comap ((↑) : Iio a → α) atBot :=
atTop_Ioi_eq (OrderDual.toDual a)
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
@[simp]
theorem map_val_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)] (a : α) :
map ((↑) : Iic a → α) atBot = atBot :=
map_val_Ici_atTop (OrderDual.toDual a)
/-- The `atBot` filter for an open interval `Iic a` comes from the `atBot` filter in the ambient
order. -/
theorem atBot_Iic_eq [Preorder α] [IsDirected α (· ≥ ·)] (a : α) :
atBot = comap ((↑) : Iic a → α) atBot :=
atTop_Ici_eq (OrderDual.toDual a)
theorem tendsto_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)]
{a : α} {f : β → Ioi a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ioi_eq, tendsto_comap_iff, Function.comp_def]
theorem tendsto_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)]
{a : α} {f : β → Iio a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot :=
tendsto_Ioi_atTop (α := αᵒᵈ)
theorem tendsto_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)]
{a : α} {f : β → Ici a} {l : Filter β} :
Tendsto f l atTop ↔ Tendsto (fun x => (f x : α)) l atTop := by
rw [atTop_Ici_eq, tendsto_comap_iff, Function.comp_def]
theorem tendsto_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)]
{a : α} {f : β → Iic a} {l : Filter β} :
Tendsto f l atBot ↔ Tendsto (fun x => (f x : α)) l atBot :=
tendsto_Ici_atTop (α := αᵒᵈ)
@[simp]
theorem tendsto_comp_val_Ioi_atTop [Preorder α] [IsDirected α (· ≤ ·)] [NoMaxOrder α]
{a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Ioi a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ioi_atTop a, tendsto_map'_iff, Function.comp_def]
@[simp]
theorem tendsto_comp_val_Ici_atTop [Preorder α] [IsDirected α (· ≤ ·)]
{a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Ici a => f x) atTop l ↔ Tendsto f atTop l := by
rw [← map_val_Ici_atTop a, tendsto_map'_iff, Function.comp_def]
@[simp]
theorem tendsto_comp_val_Iio_atBot [Preorder α] [IsDirected α (· ≥ ·)] [NoMinOrder α]
{a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Iio a => f x) atBot l ↔ Tendsto f atBot l :=
tendsto_comp_val_Ioi_atTop (α := αᵒᵈ)
@[simp]
theorem tendsto_comp_val_Iic_atBot [Preorder α] [IsDirected α (· ≥ ·)]
{a : α} {f : α → β} {l : Filter β} :
Tendsto (fun x : Iic a => f x) atBot l ↔ Tendsto f atBot l :=
tendsto_comp_val_Ici_atTop (α := αᵒᵈ)
theorem map_add_atTop_eq_nat (k : ℕ) : map (fun a => a + k) atTop = atTop :=
map_atTop_eq_of_gc (· - k) k (fun _ _ h => Nat.add_le_add_right h k)
(fun _ _ h => (Nat.le_sub_iff_add_le h).symm) fun a h => by rw [Nat.sub_add_cancel h]
theorem map_sub_atTop_eq_nat (k : ℕ) : map (fun a => a - k) atTop = atTop :=
map_atTop_eq_of_gc (· + k) 0 (fun _ _ h => Nat.sub_le_sub_right h _)
(fun _ _ _ => Nat.sub_le_iff_le_add) fun b _ => by rw [Nat.add_sub_cancel_right]
theorem tendsto_add_atTop_nat (k : ℕ) : Tendsto (fun a => a + k) atTop atTop :=
le_of_eq (map_add_atTop_eq_nat k)
theorem tendsto_sub_atTop_nat (k : ℕ) : Tendsto (fun a => a - k) atTop atTop :=
le_of_eq (map_sub_atTop_eq_nat k)
theorem tendsto_add_atTop_iff_nat {f : ℕ → α} {l : Filter α} (k : ℕ) :
Tendsto (fun n => f (n + k)) atTop l ↔ Tendsto f atTop l :=
show Tendsto (f ∘ fun n => n + k) atTop l ↔ Tendsto f atTop l by
rw [← tendsto_map'_iff, map_add_atTop_eq_nat]
theorem map_div_atTop_eq_nat (k : ℕ) (hk : 0 < k) : map (fun a => a / k) atTop = atTop :=
map_atTop_eq_of_gc (fun b => k * b + (k - 1)) 1 (fun _ _ h => Nat.div_le_div_right h)
(fun a b _ => by rw [Nat.div_le_iff_le_mul_add_pred hk])
fun b _ => by rw [Nat.mul_add_div hk, Nat.div_eq_of_lt, Nat.add_zero]; omega
section NeBot
variable [Preorder β] {l : Filter α} [NeBot l] {f : α → β}
theorem not_bddAbove_of_tendsto_atTop [NoMaxOrder β] (h : Tendsto f l atTop) :
¬BddAbove (range f) := by
rintro ⟨M, hM⟩
have : ∀ x, f x ≤ M := by aesop
have : ∅ = f ⁻¹' Ioi M := by aesop (add forward safe not_le_of_gt)
apply Filter.empty_notMem l
aesop (add safe Ioi_mem_atTop)
theorem not_bddBelow_of_tendsto_atBot [NoMinOrder β] (h : Tendsto f l atBot) :
¬BddBelow (range f) := not_bddAbove_of_tendsto_atTop (β := βᵒᵈ) h
@[deprecated (since := "2025-04-28")]
alias unbounded_of_tendsto_atTop := not_bddAbove_of_tendsto_atTop
@[deprecated (since := "2025-04-28")]
alias unbounded_of_tendsto_atBot := not_bddBelow_of_tendsto_atBot
@[deprecated (since := "2025-04-28")]
alias unbounded_of_tendsto_atTop' := not_bddAbove_of_tendsto_atTop
@[deprecated (since := "2025-04-28")]
alias unbounded_of_tendsto_atBot' := not_bddBelow_of_tendsto_atBot
end NeBot
theorem HasAntitoneBasis.eventually_subset [Preorder ι] {l : Filter α} {s : ι → Set α}
(hl : l.HasAntitoneBasis s) {t : Set α} (ht : t ∈ l) : ∀ᶠ i in atTop, s i ⊆ t :=
let ⟨i, _, hi⟩ := hl.1.mem_iff.1 ht
(eventually_ge_atTop i).mono fun _j hj => (hl.antitone hj).trans hi
protected theorem HasAntitoneBasis.tendsto [Preorder ι] {l : Filter α} {s : ι → Set α}
(hl : l.HasAntitoneBasis s) {φ : ι → α} (h : ∀ i : ι, φ i ∈ s i) : Tendsto φ atTop l :=
fun _t ht => mem_map.2 <| (hl.eventually_subset ht).mono fun i hi => hi (h i)
theorem HasAntitoneBasis.comp_mono [Nonempty ι] [Preorder ι] [IsDirected ι (· ≤ ·)] [Preorder ι']
{l : Filter α}
{s : ι' → Set α} (hs : l.HasAntitoneBasis s) {φ : ι → ι'} (φ_mono : Monotone φ)
(hφ : Tendsto φ atTop atTop) : l.HasAntitoneBasis (s ∘ φ) :=
⟨hs.1.to_hasBasis
(fun n _ => (hφ.eventually_ge_atTop n).exists.imp fun _m hm => ⟨trivial, hs.antitone hm⟩)
fun n _ => ⟨φ n, trivial, Subset.rfl⟩,
hs.antitone.comp_monotone φ_mono⟩
theorem HasAntitoneBasis.comp_strictMono {l : Filter α} {s : ℕ → Set α} (hs : l.HasAntitoneBasis s)
{φ : ℕ → ℕ} (hφ : StrictMono φ) : l.HasAntitoneBasis (s ∘ φ) :=
hs.comp_mono hφ.monotone hφ.tendsto_atTop
theorem subseq_forall_of_frequently {ι : Type*} {x : ℕ → ι} {p : ι → Prop} {l : Filter ι}
(h_tendsto : Tendsto x atTop l) (h : ∃ᶠ n in atTop, p (x n)) :
∃ ns : ℕ → ℕ, Tendsto (fun n => x (ns n)) atTop l ∧ ∀ n, p (x (ns n)) := by
choose ns hge hns using frequently_atTop.1 h
exact ⟨ns, h_tendsto.comp (tendsto_atTop_mono hge tendsto_id), hns⟩
end Filter
|
Fiber.lean
|
/-
Copyright (c) 2024 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne, Paul Lezeau
-/
import Mathlib.CategoryTheory.FiberedCategory.HomLift
import Mathlib.CategoryTheory.Functor.Const
/-!
# Fibers of a functors
In this file we define, for a functor `p : 𝒳 ⥤ 𝒴`, the fiber categories `Fiber p S` for every
`S : 𝒮` as follows
- An object in `Fiber p S` is a pair `(a, ha)` where `a : 𝒳` and `ha : p.obj a = S`.
- A morphism in `Fiber p S` is a morphism `φ : a ⟶ b` in 𝒳 such that `p.map φ = 𝟙 S`.
For any category `C` equipped with a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at `S`,
we define a functor `inducedFunctor : C ⥤ Fiber p S` that `F` factors through.
-/
universe v₁ u₁ v₂ u₂ v₃ u₃
namespace CategoryTheory
open IsHomLift
namespace Functor
variable {𝒮 : Type u₁} {𝒳 : Type u₂} [Category.{v₁} 𝒮] [Category.{v₂} 𝒳]
/-- `Fiber p S` is the type of elements of `𝒳` mapping to `S` via `p`. -/
def Fiber (p : 𝒳 ⥤ 𝒮) (S : 𝒮) := { a : 𝒳 // p.obj a = S }
namespace Fiber
variable {p : 𝒳 ⥤ 𝒮} {S : 𝒮}
/-- `Fiber p S` has the structure of a category with morphisms being those lying over `𝟙 S`. -/
instance fiberCategory : Category (Fiber p S) where
Hom a b := {φ : a.1 ⟶ b.1 // IsHomLift p (𝟙 S) φ}
id a := ⟨𝟙 a.1, IsHomLift.id a.2⟩
comp φ ψ := ⟨φ.val ≫ ψ.val, by have := φ.2; have := ψ.2; infer_instance⟩
/-- The functor including `Fiber p S` into `𝒳`. -/
def fiberInclusion : Fiber p S ⥤ 𝒳 where
obj a := a.1
map φ := φ.1
instance {a b : Fiber p S} (φ : a ⟶ b) : IsHomLift p (𝟙 S) (fiberInclusion.map φ) := φ.2
@[ext]
lemma hom_ext {a b : Fiber p S} {φ ψ : a ⟶ b}
(h : fiberInclusion.map φ = fiberInclusion.map ψ) : φ = ψ :=
Subtype.ext h
instance : (fiberInclusion : Fiber p S ⥤ _).Faithful where
lemma fiberInclusion_obj_inj : (fiberInclusion : Fiber p S ⥤ _).obj.Injective :=
fun _ _ f ↦ Subtype.val_inj.1 f
/-- For fixed `S : 𝒮` this is the natural isomorphism between `fiberInclusion ⋙ p` and the constant
function valued at `S`. -/
@[simps!]
def fiberInclusionCompIsoConst : fiberInclusion ⋙ p ≅ (const (Fiber p S)).obj S :=
NatIso.ofComponents (fun X ↦ eqToIso X.2)
(fun φ ↦ by simp [IsHomLift.fac' p (𝟙 S) (fiberInclusion.map φ)])
lemma fiberInclusion_comp_eq_const : fiberInclusion ⋙ p = (const (Fiber p S)).obj S :=
Functor.ext_of_iso fiberInclusionCompIsoConst (fun x ↦ x.2)
/-- The object of the fiber over `S` corresponding to a `a : 𝒳` such that `p(a) = S`. -/
def mk {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) : Fiber p S := ⟨a, ha⟩
@[simp]
lemma fiberInclusion_mk {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {a : 𝒳} (ha : p.obj a = S) :
fiberInclusion.obj (mk ha) = a :=
rfl
/-- The morphism in the fiber over `S` corresponding to a morphism in `𝒳` lifting `𝟙 S`. -/
def homMk (p : 𝒳 ⥤ 𝒮) (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsHomLift p (𝟙 S) φ] :
mk (domain_eq p (𝟙 S) φ) ⟶ mk (codomain_eq p (𝟙 S) φ) :=
⟨φ, inferInstance⟩
@[simp]
lemma fiberInclusion_homMk (p : 𝒳 ⥤ 𝒮) (S : 𝒮) {a b : 𝒳} (φ : a ⟶ b) [IsHomLift p (𝟙 S) φ] :
fiberInclusion.map (homMk p S φ) = φ :=
rfl
@[simp]
lemma homMk_id (p : 𝒳 ⥤ 𝒮) (S : 𝒮) (a : 𝒳) [IsHomLift p (𝟙 S) (𝟙 a)] :
homMk p S (𝟙 a) = 𝟙 (mk (domain_eq p (𝟙 S) (𝟙 a))) :=
rfl
@[simp]
lemma homMk_comp {a b c : 𝒳} (φ : a ⟶ b) (ψ : b ⟶ c) [IsHomLift p (𝟙 S) φ]
[IsHomLift p (𝟙 S) ψ] : homMk p S φ ≫ homMk p S ψ = homMk p S (φ ≫ ψ) :=
rfl
section
variable {p : 𝒳 ⥤ 𝒮} {S : 𝒮} {C : Type u₃} [Category.{v₃} C] {F : C ⥤ 𝒳}
(hF : F ⋙ p = (const C).obj S)
/-- Given a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at some `S : 𝒮`, then
we get an induced functor `C ⥤ Fiber p S` that `F` factors through. -/
def inducedFunctor : C ⥤ Fiber p S where
obj x := ⟨F.obj x, by simp only [← comp_obj, hF, const_obj_obj]⟩
map φ := ⟨F.map φ, of_commsq _ _ _ (congr_obj hF _) (congr_obj hF _) <|
by simpa using (eqToIso hF).hom.naturality φ⟩
/-- Given a functor `F : C ⥤ 𝒳` such that `F ⋙ p` is constant at some `S : 𝒮`, then
we get a natural isomorphism between `inducedFunctor _ ⋙ fiberInclusion` and `F`. -/
@[simps!]
def inducedFunctorCompIsoSelf : (inducedFunctor hF) ⋙ fiberInclusion ≅ F := .refl _
lemma inducedFunctor_comp : (inducedFunctor hF) ⋙ fiberInclusion = F := rfl
@[simp]
lemma inducedFunctor_comp_obj (X : C) :
fiberInclusion.obj ((inducedFunctor hF).obj X) = F.obj X := rfl
@[simp]
lemma inducedFunctor_comp_map {X Y : C} (f : X ⟶ Y) :
fiberInclusion.map ((inducedFunctor hF).map f) = F.map f := rfl
end
end Fiber
end Functor
end CategoryTheory
|
Imo2019Q1.lean
|
/-
Copyright (c) 2020 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
/-!
# IMO 2019 Q1
Determine all functions `f : ℤ → ℤ` such that, for all integers `a` and `b`,
`f(2a) + 2f(b) = f(f(a+b))`.
The desired theorem is that either:
- `f = fun _ ↦ 0`
- `∃ c, f = fun x ↦ 2 * x + c`
Note that there is a much more compact proof of this fact in Isabelle/HOL
- http://downthetypehole.de/paste/4YbGgqb4
-/
theorem imo2019_q1 (f : ℤ → ℤ) :
(∀ a b : ℤ, f (2 * a) + 2 * f b = f (f (a + b))) ↔ f = 0 ∨ ∃ c, f = fun x => 2 * x + c := by
constructor; swap
-- easy way: f(x)=0 and f(x)=2x+c work.
· rintro (rfl | ⟨c, rfl⟩) <;> intros <;> norm_num; ring
-- hard way.
intro hf
-- functional equation
-- Using `h` for `(0, b)` and `(-1, b + 1)`, we get `f (b + 1) = f b + m`
obtain ⟨m, H⟩ : ∃ m, ∀ b, f (b + 1) = f b + m := by
refine ⟨(f 0 - f (-2)) / 2, fun b => ?_⟩
refine sub_eq_iff_eq_add'.1 (Int.eq_ediv_of_mul_eq_right two_ne_zero ?_)
have h1 : f 0 + 2 * f b = f (f b) := by simpa using hf 0 b
have h2 : f (-2) + 2 * f (b + 1) = f (f b) := by simpa using hf (-1) (b + 1)
linarith
-- Hence, `f` is an affine map, `f b = f 0 + m * b`
obtain ⟨c, H⟩ : ∃ c, ∀ b, f b = c + m * b := by
refine ⟨f 0, fun b => ?_⟩
induction b with
| zero => simp
| succ b ihb => simp [H, ihb, mul_add, add_assoc]
| pred b ihb =>
rw [← sub_eq_of_eq_add (H _)]
simp [ihb]; ring
-- Now use `hf 0 0` and `hf 0 1` to show that `m ∈ {0, 2}`
have H3 : 2 * c = m * c := by simpa [H, mul_add] using hf 0 0
obtain rfl | rfl : 2 = m ∨ m = 0 := by simpa [H, mul_add, H3] using hf 0 1
· right; use c; ext b; simp [H, add_comm]
· left; ext b; simpa [H, two_ne_zero] using H3
|
Yoneda.lean
|
/-
Copyright (c) 2025 Yaël Dillies, Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Andrew Yang
-/
import Mathlib.Algebra.Category.Grp.Basic
import Mathlib.Algebra.Group.Pi.Lemmas
import Mathlib.CategoryTheory.Yoneda
/-!
# Yoneda embeddings
This file defines a few Yoneda embeddings for the category of commutative groups.
-/
open CategoryTheory
universe u
/-- The `CommGrp`-valued coyoneda embedding. -/
@[to_additive (attr := simps) /-- The `AddCommGrp`-valued coyoneda embedding. -/]
def CommGrp.coyoneda : CommGrpᵒᵖ ⥤ CommGrp ⥤ CommGrp where
obj M := { obj N := of (M.unop →* N), map f := ofHom (.compHom f.hom) }
map f := { app N := ofHom (.compHom' f.unop.hom) }
/-- The `CommGrp`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/
@[to_additive (attr := simps!)
/-- The `AddCommGrp`-valued coyoneda embedding composed with the forgetful functor is the usual
coyoneda embedding. -/]
def CommGrp.coyonedaForget :
coyoneda ⋙ (Functor.whiskeringRight _ _ _).obj (forget _) ≅ CategoryTheory.coyoneda :=
NatIso.ofComponents fun X ↦ NatIso.ofComponents fun Y ↦ { hom f := ofHom f, inv f := f.hom }
/-- The Hom bifunctor sending a type `X` and a commutative group `G` to the commutative group
`X → G` with pointwise operations.
This is also the coyoneda embedding of `Type` into `CommGrp`-valued presheaves of commutative
groups. -/
@[to_additive (attr := simps)
/-- The Hom bifunctor sending a type `X` and a commutative group `G` to the commutative group
`X → G` with pointwise operations.
This is also the coyoneda embedding of `Type` into `AddCommGrp`-valued presheaves of commutative
groups. -/]
def CommGrp.coyonedaType : (Type u)ᵒᵖ ⥤ CommGrp.{u} ⥤ CommGrp.{u} where
obj X := { obj G := of <| X.unop → G
map f := ofHom <| Pi.monoidHom fun i ↦ f.hom.comp <| Pi.evalMonoidHom _ i }
map f := { app G := ofHom <| Pi.monoidHom fun i ↦ Pi.evalMonoidHom _ <| f.unop i }
|
Sheaf.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.Topology.Sheaves.Presheaf
import Mathlib.CategoryTheory.Sites.Sheaf
import Mathlib.CategoryTheory.Sites.Spaces
/-!
# Sheaves
We define sheaves on a topological space, with values in an arbitrary category.
A presheaf on a topological space `X` is a sheaf precisely when it is a sheaf under the
grothendieck topology on `opens X`, which expands out to say: For each open cover `{ Uᵢ }` of
`U`, and a family of compatible functions `A ⟶ F(Uᵢ)` for an `A : X`, there exists a unique
gluing `A ⟶ F(U)` compatible with the restriction.
See the docstring of `TopCat.Presheaf.IsSheaf` for an explanation on the design decisions and a list
of equivalent conditions.
We provide the instance `CategoryTheory.Category (TopCat.Sheaf C X)` as the full subcategory of
presheaves, and the fully faithful functor `Sheaf.forget : TopCat.Sheaf C X ⥤ TopCat.Presheaf C X`.
-/
universe w v u
noncomputable section
open CategoryTheory CategoryTheory.Limits TopologicalSpace Opposite TopologicalSpace.Opens
namespace TopCat
variable {C : Type u} [Category.{v} C]
variable {X : TopCat.{w}} (F : Presheaf C X) {ι : Type v} (U : ι → Opens X)
namespace Presheaf
/-- The sheaf condition has several different equivalent formulations.
The official definition chosen here is in terms of grothendieck topologies so that the results on
sites could be applied here easily, and this condition does not require additional constraints on
the value category.
The equivalent formulations of the sheaf condition on `presheaf C X` are as follows :
1. `TopCat.Presheaf.IsSheaf`: (the official definition)
It is a sheaf with respect to the grothendieck topology on `opens X`, which is to say:
For each open cover `{ Uᵢ }` of `U`, and a family of compatible functions `A ⟶ F(Uᵢ)` for an
`A : X`, there exists a unique gluing `A ⟶ F(U)` compatible with the restriction.
2. `TopCat.Presheaf.IsSheafEqualizerProducts`: (requires `C` to have all products)
For each open cover `{ Uᵢ }` of `U`, `F(U) ⟶ ∏ᶜ F(Uᵢ)` is the equalizer of the two morphisms
`∏ᶜ F(Uᵢ) ⟶ ∏ᶜ F(Uᵢ ∩ Uⱼ)`.
See `TopCat.Presheaf.isSheaf_iff_isSheafEqualizerProducts`.
3. `TopCat.Presheaf.IsSheafOpensLeCover`:
For each open cover `{ Uᵢ }` of `U`, `F(U)` is the limit of the diagram consisting of arrows
`F(V₁) ⟶ F(V₂)` for every pair of open sets `V₁ ⊇ V₂` that are contained in some `Uᵢ`.
See `TopCat.Presheaf.isSheaf_iff_isSheafOpensLeCover`.
4. `TopCat.Presheaf.IsSheafPairwiseIntersections`:
For each open cover `{ Uᵢ }` of `U`, `F(U)` is the limit of the diagram consisting of arrows
from `F(Uᵢ)` and `F(Uⱼ)` to `F(Uᵢ ∩ Uⱼ)` for each pair `(i, j)`.
See `TopCat.Presheaf.isSheaf_iff_isSheafPairwiseIntersections`.
The following requires `C` to be concrete and complete, and `forget C` to reflect isomorphisms and
preserve limits. This applies to most "algebraic" categories, e.g. groups, abelian groups and rings.
5. `TopCat.Presheaf.IsSheafUniqueGluing`:
(requires `C` to be concrete and complete; `forget C` to reflect isomorphisms and preserve limits)
For each open cover `{ Uᵢ }` of `U`, and a compatible family of elements `x : F(Uᵢ)`, there exists
a unique gluing `x : F(U)` that restricts to the given elements.
See `TopCat.Presheaf.isSheaf_iff_isSheafUniqueGluing`.
6. The underlying sheaf of types is a sheaf.
See `TopCat.Presheaf.isSheaf_iff_isSheaf_comp` and
`CategoryTheory.Presheaf.isSheaf_iff_isSheaf_forget`.
-/
nonrec def IsSheaf (F : Presheaf.{w, v, u} C X) : Prop :=
Presheaf.IsSheaf (Opens.grothendieckTopology X) F
/-- The presheaf valued in `Unit` over any topological space is a sheaf.
-/
theorem isSheaf_unit (F : Presheaf (CategoryTheory.Discrete Unit) X) : F.IsSheaf :=
fun x U S _ x _ => ⟨eqToHom (Subsingleton.elim _ _), by cat_disch, fun _ => by cat_disch⟩
theorem isSheaf_iso_iff {F G : Presheaf C X} (α : F ≅ G) : F.IsSheaf ↔ G.IsSheaf :=
Presheaf.isSheaf_of_iso_iff α
/-- Transfer the sheaf condition across an isomorphism of presheaves.
-/
theorem isSheaf_of_iso {F G : Presheaf C X} (α : F ≅ G) (h : F.IsSheaf) : G.IsSheaf :=
(isSheaf_iso_iff α).1 h
end Presheaf
variable (C X)
/-- A `TopCat.Sheaf C X` is a presheaf of objects from `C` over a (bundled) topological space `X`,
satisfying the sheaf condition.
-/
nonrec def Sheaf : Type max u v w :=
Sheaf (Opens.grothendieckTopology X) C
deriving Category
variable {C X}
/-- The underlying presheaf of a sheaf -/
abbrev Sheaf.presheaf (F : X.Sheaf C) : TopCat.Presheaf C X :=
F.1
variable (C X)
-- Let's construct a trivial example, to keep the inhabited linter happy.
instance sheafInhabited : Inhabited (Sheaf (CategoryTheory.Discrete PUnit) X) :=
⟨⟨Functor.star _, Presheaf.isSheaf_unit _⟩⟩
namespace Sheaf
/-- The forgetful functor from sheaves to presheaves.
-/
def forget : TopCat.Sheaf C X ⥤ TopCat.Presheaf C X :=
sheafToPresheaf _ _
-- The following instances should be constructed by a deriving handler.
-- https://github.com/leanprover-community/mathlib4/issues/380
instance forget_full : (forget C X).Full where
map_surjective f := ⟨Sheaf.Hom.mk f, rfl⟩
instance forgetFaithful : (forget C X).Faithful where
map_injective := Sheaf.Hom.ext
-- Note: These can be proved by simp.
theorem id_app (F : Sheaf C X) (t) : (𝟙 F : F ⟶ F).1.app t = 𝟙 _ :=
rfl
theorem comp_app {F G H : Sheaf C X} (f : F ⟶ G) (g : G ⟶ H) (t) :
(f ≫ g).1.app t = f.1.app t ≫ g.1.app t :=
rfl
end Sheaf
lemma Presheaf.IsSheaf.section_ext {X : TopCat.{u}}
{A : Type*} [Category.{u} A] {FC : A → A → Type*} {CC : A → Type u}
[∀ X Y : A, FunLike (FC X Y) (CC X) (CC Y)] [ConcreteCategory.{u} A FC]
[HasLimits A] [PreservesLimits (forget A)] [(forget A).ReflectsIsomorphisms]
{F : TopCat.Presheaf A X} (hF : TopCat.Presheaf.IsSheaf F)
{U : (Opens X)ᵒᵖ} {s t : ToType (F.obj U)}
(hst : ∀ x ∈ U.unop, ∃ V, ∃ hV : V ≤ U.unop, x ∈ V ∧
F.map (homOfLE hV).op s = F.map (homOfLE hV).op t) :
s = t := by
have := (isSheaf_iff_isSheaf_of_type _ _).mp
((Presheaf.isSheaf_iff_isSheaf_forget (C := Opens X) (A' := A) _ F (forget _)).mp hF)
choose V hV hxV H using fun x : U.unop ↦ hst x.1 x.2
refine (this.isSheafFor _ (.ofArrows V fun x ↦ homOfLE (hV x)) ?_).isSeparatedFor.ext ?_
· exact fun x hx ↦ ⟨V ⟨x, hx⟩, homOfLE (hV _), Sieve.le_generate _ _ (.mk _), hxV _⟩
· rintro _ _ ⟨x⟩; exact H x
end TopCat
|
Conjugate.lean
|
/-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Logic.Function.Basic
/-!
# Semiconjugate and commuting maps
We define the following predicates:
* `Function.Semiconj`: `f : α → β` semiconjugates `ga : α → α` to `gb : β → β` if `f ∘ ga = gb ∘ f`;
* `Function.Semiconj₂`: `f : α → β` semiconjugates a binary operation `ga : α → α → α`
to `gb : β → β → β` if `f (ga x y) = gb (f x) (f y)`;
* `Function.Commute`: `f : α → α` commutes with `g : α → α` if `f ∘ g = g ∘ f`,
or equivalently `Semiconj f g g`.
-/
namespace Function
variable {α : Type*} {β : Type*} {γ : Type*}
/--
We say that `f : α → β` semiconjugates `ga : α → α` to `gb : β → β` if `f ∘ ga = gb ∘ f`.
We use `∀ x, f (ga x) = gb (f x)` as the definition, so given `h : Function.Semiconj f ga gb` and
`a : α`, we have `h a : f (ga a) = gb (f a)` and `h.comp_eq : f ∘ ga = gb ∘ f`.
-/
def Semiconj (f : α → β) (ga : α → α) (gb : β → β) : Prop :=
∀ x, f (ga x) = gb (f x)
namespace Semiconj
variable {f fab : α → β} {fbc : β → γ} {ga ga' : α → α} {gb gb' : β → β} {gc : γ → γ}
/-- Definition of `Function.Semiconj` in terms of functional equality. -/
lemma _root_.Function.semiconj_iff_comp_eq : Semiconj f ga gb ↔ f ∘ ga = gb ∘ f := funext_iff.symm
protected alias ⟨comp_eq, _⟩ := semiconj_iff_comp_eq
protected theorem eq (h : Semiconj f ga gb) (x : α) : f (ga x) = gb (f x) :=
h x
/-- If `f` semiconjugates `ga` to `gb` and `ga'` to `gb'`,
then it semiconjugates `ga ∘ ga'` to `gb ∘ gb'`. -/
theorem comp_right (h : Semiconj f ga gb) (h' : Semiconj f ga' gb') :
Semiconj f (ga ∘ ga') (gb ∘ gb') := fun x ↦ by
simp only [comp_apply, h.eq, h'.eq]
/-- If `fab : α → β` semiconjugates `ga` to `gb` and `fbc : β → γ` semiconjugates `gb` to `gc`,
then `fbc ∘ fab` semiconjugates `ga` to `gc`.
See also `Function.Semiconj.comp_left` for a version with reversed arguments. -/
protected theorem trans (hab : Semiconj fab ga gb) (hbc : Semiconj fbc gb gc) :
Semiconj (fbc ∘ fab) ga gc := fun x ↦ by
simp only [comp_apply, hab.eq, hbc.eq]
/-- If `fbc : β → γ` semiconjugates `gb` to `gc` and `fab : α → β` semiconjugates `ga` to `gb`,
then `fbc ∘ fab` semiconjugates `ga` to `gc`.
See also `Function.Semiconj.trans` for a version with reversed arguments.
**Backward compatibility note:** before 2024-01-13,
this lemma used to have the same order of arguments that `Function.Semiconj.trans` has now. -/
theorem comp_left (hbc : Semiconj fbc gb gc) (hab : Semiconj fab ga gb) :
Semiconj (fbc ∘ fab) ga gc :=
hab.trans hbc
/-- Any function semiconjugates the identity function to the identity function. -/
theorem id_right : Semiconj f id id := fun _ ↦ rfl
/-- The identity function semiconjugates any function to itself. -/
theorem id_left : Semiconj id ga ga := fun _ ↦ rfl
/-- If `f : α → β` semiconjugates `ga : α → α` to `gb : β → β`,
`ga'` is a right inverse of `ga`, and `gb'` is a left inverse of `gb`,
then `f` semiconjugates `ga'` to `gb'` as well. -/
theorem inverses_right (h : Semiconj f ga gb) (ha : RightInverse ga' ga) (hb : LeftInverse gb' gb) :
Semiconj f ga' gb' := fun x ↦ by
rw [← hb (f (ga' x)), ← h.eq, ha x]
/-- If `f` semiconjugates `ga` to `gb` and `f'` is both a left and a right inverse of `f`,
then `f'` semiconjugates `gb` to `ga`. -/
lemma inverse_left {f' : β → α} (h : Semiconj f ga gb)
(hf₁ : LeftInverse f' f) (hf₂ : RightInverse f' f) : Semiconj f' gb ga := fun x ↦ by
rw [← hf₁.injective.eq_iff, h, hf₂, hf₂]
/-- If `f : α → β` semiconjugates `ga : α → α` to `gb : β → β`,
then `Option.map f` semiconjugates `Option.map ga` to `Option.map gb`. -/
theorem option_map {f : α → β} {ga : α → α} {gb : β → β} (h : Semiconj f ga gb) :
Semiconj (Option.map f) (Option.map ga) (Option.map gb)
| none => rfl
| some _ => congr_arg some <| h _
end Semiconj
/--
Two maps `f g : α → α` commute if `f (g x) = g (f x)` for all `x : α`.
Given `h : Function.commute f g` and `a : α`, we have `h a : f (g a) = g (f a)` and
`h.comp_eq : f ∘ g = g ∘ f`.
-/
protected def Commute (f g : α → α) : Prop :=
Semiconj f g g
open Function (Commute)
/-- Reinterpret `Function.Semiconj f g g` as `Function.Commute f g`. These two predicates are
definitionally equal but have different dot-notation lemmas. -/
theorem Semiconj.commute {f g : α → α} (h : Semiconj f g g) : Commute f g := h
namespace Commute
variable {f f' g g' : α → α}
/-- Reinterpret `Function.Commute f g` as `Function.Semiconj f g g`. These two predicates are
definitionally equal but have different dot-notation lemmas. -/
theorem semiconj (h : Commute f g) : Semiconj f g g := h
@[refl]
theorem refl (f : α → α) : Commute f f := fun _ ↦ Eq.refl _
@[symm]
theorem symm (h : Commute f g) : Commute g f := fun x ↦ (h x).symm
/-- If `f` commutes with `g` and `g'`, then it commutes with `g ∘ g'`. -/
theorem comp_right (h : Commute f g) (h' : Commute f g') : Commute f (g ∘ g') :=
Semiconj.comp_right h h'
/-- If `f` and `f'` commute with `g`, then `f ∘ f'` commutes with `g` as well. -/
nonrec theorem comp_left (h : Commute f g) (h' : Commute f' g) : Commute (f ∘ f') g :=
h.comp_left h'
/-- Any self-map commutes with the identity map. -/
theorem id_right : Commute f id := Semiconj.id_right
/-- The identity map commutes with any self-map. -/
theorem id_left : Commute id f :=
Semiconj.id_left
/-- If `f` commutes with `g`, then `Option.map f` commutes with `Option.map g`. -/
nonrec theorem option_map {f g : α → α} (h : Commute f g) : Commute (Option.map f) (Option.map g) :=
h.option_map
end Commute
/--
A map `f` semiconjugates a binary operation `ga` to a binary operation `gb` if
for all `x`, `y` we have `f (ga x y) = gb (f x) (f y)`. E.g., a `MonoidHom`
semiconjugates `(*)` to `(*)`.
-/
def Semiconj₂ (f : α → β) (ga : α → α → α) (gb : β → β → β) : Prop :=
∀ x y, f (ga x y) = gb (f x) (f y)
namespace Semiconj₂
variable {f : α → β} {ga : α → α → α} {gb : β → β → β}
protected theorem eq (h : Semiconj₂ f ga gb) (x y : α) : f (ga x y) = gb (f x) (f y) :=
h x y
protected theorem comp_eq (h : Semiconj₂ f ga gb) : bicompr f ga = bicompl gb f f :=
funext fun x ↦ funext <| h x
theorem id_left (op : α → α → α) : Semiconj₂ id op op := fun _ _ ↦ rfl
theorem comp {f' : β → γ} {gc : γ → γ → γ} (hf' : Semiconj₂ f' gb gc) (hf : Semiconj₂ f ga gb) :
Semiconj₂ (f' ∘ f) ga gc := fun x y ↦ by simp only [hf'.eq, hf.eq, comp_apply]
theorem isAssociative_right [Std.Associative ga] (h : Semiconj₂ f ga gb) (h_surj : Surjective f) :
Std.Associative gb :=
⟨h_surj.forall₃.2 fun x₁ x₂ x₃ ↦ by simp only [← h.eq, Std.Associative.assoc (op := ga)]⟩
theorem isAssociative_left [Std.Associative gb] (h : Semiconj₂ f ga gb) (h_inj : Injective f) :
Std.Associative ga :=
⟨fun x₁ x₂ x₃ ↦ h_inj <| by simp only [h.eq, Std.Associative.assoc (op := gb)]⟩
theorem isIdempotent_right [Std.IdempotentOp ga] (h : Semiconj₂ f ga gb) (h_surj : Surjective f) :
Std.IdempotentOp gb :=
⟨h_surj.forall.2 fun x ↦ by simp only [← h.eq, Std.IdempotentOp.idempotent (op := ga)]⟩
theorem isIdempotent_left [Std.IdempotentOp gb] (h : Semiconj₂ f ga gb) (h_inj : Injective f) :
Std.IdempotentOp ga :=
⟨fun x ↦ h_inj <| by rw [h.eq, Std.IdempotentOp.idempotent (op := gb)]⟩
end Semiconj₂
end Function
|
Basic.lean
|
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Ideal.Quotient.Nilpotent
import Mathlib.RingTheory.Smooth.Basic
import Mathlib.RingTheory.Unramified.Basic
/-!
# Etale morphisms
An `R`-algebra `A` is formally étale if for every `R`-algebra `B`,
every square-zero ideal `I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists
exactly one lift `A →ₐ[R] B`.
It is étale if it is formally étale and of finite presentation.
We show that the property extends onto nilpotent ideals, and that these properties are stable
under `R`-algebra homomorphisms and compositions.
We show that étale is stable under algebra isomorphisms, composition and
localization at an element.
-/
-- Porting note: added to make the syntax work below.
open scoped TensorProduct
universe u
namespace Algebra
section
variable (R : Type u) [CommRing R]
variable (A : Type u) [CommRing A] [Algebra R A]
/-- An `R` algebra `A` is formally étale if for every `R`-algebra, every square-zero ideal
`I : Ideal B` and `f : A →ₐ[R] B ⧸ I`, there exists exactly one lift `A →ₐ[R] B`. -/
@[mk_iff, stacks 00UQ]
class FormallyEtale : Prop where
comp_bijective :
∀ ⦃B : Type u⦄ [CommRing B],
∀ [Algebra R B] (I : Ideal B) (_ : I ^ 2 = ⊥),
Function.Bijective ((Ideal.Quotient.mkₐ R I).comp : (A →ₐ[R] B) → A →ₐ[R] B ⧸ I)
end
namespace FormallyEtale
section
variable {R : Type u} [CommRing R]
variable {A : Type u} [CommRing A] [Algebra R A]
theorem iff_unramified_and_smooth :
FormallyEtale R A ↔ FormallyUnramified R A ∧ FormallySmooth R A := by
rw [FormallyUnramified.iff_comp_injective, formallySmooth_iff, formallyEtale_iff]
simp_rw [← forall_and, Function.Bijective]
instance (priority := 100) to_unramified [h : FormallyEtale R A] :
FormallyUnramified R A :=
(FormallyEtale.iff_unramified_and_smooth.mp h).1
instance (priority := 100) to_smooth [h : FormallyEtale R A] : FormallySmooth R A :=
(FormallyEtale.iff_unramified_and_smooth.mp h).2
theorem of_unramified_and_smooth [h₁ : FormallyUnramified R A]
[h₂ : FormallySmooth R A] : FormallyEtale R A :=
FormallyEtale.iff_unramified_and_smooth.mpr ⟨h₁, h₂⟩
end
section OfEquiv
variable {R : Type u} [CommRing R]
variable {A B : Type u} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
theorem of_equiv [FormallyEtale R A] (e : A ≃ₐ[R] B) : FormallyEtale R B :=
FormallyEtale.iff_unramified_and_smooth.mpr
⟨FormallyUnramified.of_equiv e, FormallySmooth.of_equiv e⟩
theorem iff_of_equiv (e : A ≃ₐ[R] B) : FormallyEtale R A ↔ FormallyEtale R B :=
⟨fun _ ↦ of_equiv e, fun _ ↦ of_equiv e.symm⟩
end OfEquiv
section Comp
variable (R : Type u) [CommRing R]
variable (A : Type u) [CommRing A] [Algebra R A]
variable (B : Type u) [CommRing B] [Algebra R B] [Algebra A B] [IsScalarTower R A B]
theorem comp [FormallyEtale R A] [FormallyEtale A B] : FormallyEtale R B :=
FormallyEtale.iff_unramified_and_smooth.mpr
⟨FormallyUnramified.comp R A B, FormallySmooth.comp R A B⟩
end Comp
section BaseChange
open scoped TensorProduct
variable {R : Type u} [CommRing R]
variable {A : Type u} [CommRing A] [Algebra R A]
variable (B : Type u) [CommRing B] [Algebra R B]
instance base_change [FormallyEtale R A] : FormallyEtale B (B ⊗[R] A) :=
FormallyEtale.iff_unramified_and_smooth.mpr ⟨inferInstance, inferInstance⟩
end BaseChange
section Localization
/-!
We now consider a commutative square of commutative rings
```
R -----> S
| |
| |
v v
Rₘ ----> Sₘ
```
where `Rₘ` and `Sₘ` are the localisations of `R` and `S` at a multiplicatively closed
subset `M` of `R`.
-/
/-! Let R, S, Rₘ, Sₘ be commutative rings -/
variable {R S Rₘ Sₘ : Type u} [CommRing R] [CommRing S] [CommRing Rₘ] [CommRing Sₘ]
/-! Let M be a multiplicatively closed subset of `R` -/
variable (M : Submonoid R)
/-! Assume that the rings are in a commutative diagram as above. -/
variable [Algebra R S] [Algebra R Sₘ] [Algebra S Sₘ] [Algebra R Rₘ] [Algebra Rₘ Sₘ]
variable [IsScalarTower R Rₘ Sₘ] [IsScalarTower R S Sₘ]
/-! and that Rₘ and Sₘ are localizations of R and S at M. -/
variable [IsLocalization M Rₘ] [IsLocalization (M.map (algebraMap R S)) Sₘ]
include M
-- Porting note: no longer supported
-- attribute [local elab_as_elim] Ideal.IsNilpotent.induction_on
theorem of_isLocalization : FormallyEtale R Rₘ :=
FormallyEtale.iff_unramified_and_smooth.mpr
⟨FormallyUnramified.of_isLocalization M, FormallySmooth.of_isLocalization M⟩
theorem localization_base [FormallyEtale R Sₘ] : FormallyEtale Rₘ Sₘ :=
FormallyEtale.iff_unramified_and_smooth.mpr
⟨FormallyUnramified.localization_base M, FormallySmooth.localization_base M⟩
/-- The localization of a formally étale map is formally étale. -/
theorem localization_map [FormallyEtale R S] : FormallyEtale Rₘ Sₘ := by
haveI : FormallyEtale S Sₘ := FormallyEtale.of_isLocalization (M.map (algebraMap R S))
haveI : FormallyEtale R Sₘ := FormallyEtale.comp R S Sₘ
exact FormallyEtale.localization_base M
end Localization
end FormallyEtale
section
variable (R : Type u) [CommRing R]
variable (A : Type u) [CommRing A] [Algebra R A]
/-- An `R`-algebra `A` is étale if it is formally étale and of finite presentation. -/
@[stacks 00U1 "Note that this is a different definition from this Stacks entry, but
<https://stacks.math.columbia.edu/tag/00UR> shows that it is equivalent to the definition here."]
class Etale : Prop where
formallyEtale : FormallyEtale R A := by infer_instance
finitePresentation : FinitePresentation R A := by infer_instance
end
namespace Etale
attribute [instance] formallyEtale finitePresentation
variable {R : Type u} [CommRing R]
variable {A B : Type u} [CommRing A] [Algebra R A] [CommRing B] [Algebra R B]
/-- Being étale is transported via algebra isomorphisms. -/
theorem of_equiv [Etale R A] (e : A ≃ₐ[R] B) : Etale R B where
formallyEtale := FormallyEtale.of_equiv e
finitePresentation := FinitePresentation.equiv e
section Comp
variable (R A B)
/-- Etale is stable under composition. -/
theorem comp [Algebra A B] [IsScalarTower R A B] [Etale R A] [Etale A B] : Etale R B where
formallyEtale := FormallyEtale.comp R A B
finitePresentation := FinitePresentation.trans R A B
/-- Etale is stable under base change. -/
instance baseChange [Etale R A] : Etale B (B ⊗[R] A) where
end Comp
/-- Localization at an element is étale. -/
theorem of_isLocalization_Away (r : R) [IsLocalization.Away r A] : Etale R A where
formallyEtale := Algebra.FormallyEtale.of_isLocalization (Submonoid.powers r)
finitePresentation := IsLocalization.Away.finitePresentation r
end Etale
end Algebra
namespace RingHom
variable {R S : Type u} [CommRing R] [CommRing S]
/--
A ring homomorphism `R →+* A` is formally etale if it is formally unramified and formally smooth.
See `Algebra.FormallyEtale`.
-/
@[algebraize Algebra.FormallyEtale]
def FormallyEtale (f : R →+* S) : Prop :=
letI := f.toAlgebra
Algebra.FormallyEtale R S
lemma formallyEtale_algebraMap [Algebra R S] :
(algebraMap R S).FormallyEtale ↔ Algebra.FormallyEtale R S := by
rw [FormallyEtale, toAlgebra_algebraMap]
end RingHom
|
Limits.lean
|
/-
Copyright (c) 2023 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Dagur Asgeirsson
-/
import Mathlib.Topology.Category.Profinite.Basic
import Mathlib.Topology.Category.CompHausLike.Limits
/-!
# Explicit limits and colimits
This file applies the general API for explicit limits and colimits in `CompHausLike P` (see
the file `Mathlib/Topology/Category/CompHausLike/Limits.lean`) to the special case of `Profinite`.
-/
namespace Profinite
universe u w
open CategoryTheory Limits CompHausLike
instance : HasExplicitPullbacks (fun Y ↦ TotallyDisconnectedSpace Y) where
hasProp _ _ := { hasProp :=
show TotallyDisconnectedSpace {_xy : _ | _} from inferInstance}
instance : HasExplicitFiniteCoproducts.{w, u} (fun Y ↦ TotallyDisconnectedSpace Y) where
hasProp _ := { hasProp :=
show TotallyDisconnectedSpace (Σ (_a : _), _) from inferInstance}
/-- A one-element space is terminal in `Profinite` -/
abbrev isTerminalPUnit : IsTerminal (Profinite.of PUnit.{u + 1}) := CompHausLike.isTerminalPUnit
example : FinitaryExtensive Profinite.{u} := inferInstance
noncomputable example : PreservesFiniteCoproducts profiniteToCompHaus := inferInstance
end Profinite
|
Basic.lean
|
/-
Copyright (c) 2017 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Kim Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Pi.Basic
import Mathlib.Data.ULift
/-!
# Discrete categories
We define `Discrete α` as a structure containing a term `a : α` for any type `α`,
and use this type alias to provide a `SmallCategory` instance
whose only morphisms are the identities.
There is an annoying technical difficulty that it has turned out to be inconvenient
to allow categories with morphisms living in `Prop`,
so instead of defining `X ⟶ Y` in `Discrete α` as `X = Y`,
one might define it as `PLift (X = Y)`.
In fact, to allow `Discrete α` to be a `SmallCategory`
(i.e. with morphisms in the same universe as the objects),
we actually define the hom type `X ⟶ Y` as `ULift (PLift (X = Y))`.
`Discrete.functor` promotes a function `f : I → C` (for any category `C`) to a functor
`Discrete.functor f : Discrete I ⥤ C`.
Similarly, `Discrete.natTrans` and `Discrete.natIso` promote `I`-indexed families of morphisms,
or `I`-indexed families of isomorphisms to natural transformations or natural isomorphism.
We show equivalences of types are the same as (categorical) equivalences of the corresponding
discrete categories.
-/
namespace CategoryTheory
-- morphism levels before object levels. See note [CategoryTheory universes].
universe v₁ v₂ v₃ u₁ u₁' u₂ u₃
-- This is intentionally a structure rather than a type synonym
-- to enforce using `DiscreteEquiv` (or `Discrete.mk` and `Discrete.as`) to move between
-- `Discrete α` and `α`. Otherwise there is too much API leakage.
/-- A wrapper for promoting any type to a category,
with the only morphisms being equalities.
-/
@[ext, aesop safe cases (rule_sets := [CategoryTheory])]
structure Discrete (α : Type u₁) where
/-- A wrapper for promoting any type to a category,
with the only morphisms being equalities. -/
as : α
@[simp]
theorem Discrete.mk_as {α : Type u₁} (X : Discrete α) : Discrete.mk X.as = X :=
rfl
/-- `Discrete α` is equivalent to the original type `α`. -/
@[simps]
def discreteEquiv {α : Type u₁} : Discrete α ≃ α where
toFun := Discrete.as
invFun := Discrete.mk
left_inv := by cat_disch
right_inv := by cat_disch
instance {α : Type u₁} [DecidableEq α] : DecidableEq (Discrete α) :=
discreteEquiv.decidableEq
/-- The "Discrete" category on a type, whose morphisms are equalities.
Because we do not allow morphisms in `Prop` (only in `Type`),
somewhat annoyingly we have to define `X ⟶ Y` as `ULift (PLift (X = Y))`. -/
@[stacks 001A]
instance discreteCategory (α : Type u₁) : SmallCategory (Discrete α) where
Hom X Y := ULift (PLift (X.as = Y.as))
id _ := ULift.up (PLift.up rfl)
comp {X Y Z} g f := by
cases X
cases Y
cases Z
rcases f with ⟨⟨⟨⟩⟩⟩
exact g
namespace Discrete
variable {α : Type u₁}
instance [Inhabited α] : Inhabited (Discrete α) :=
⟨⟨default⟩⟩
instance [Subsingleton α] : Subsingleton (Discrete α) :=
⟨by cat_disch⟩
instance instSubsingletonDiscreteHom (X Y : Discrete α) : Subsingleton (X ⟶ Y) :=
show Subsingleton (ULift (PLift _)) from inferInstance
/-- A simple tactic to run `cases` on any `Discrete α` hypotheses. -/
macro "discrete_cases" : tactic =>
`(tactic| fail_if_no_progress casesm* Discrete _, (_ : Discrete _) ⟶ (_ : Discrete _), PLift _)
open Lean Elab Tactic in
/--
Use:
```
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
```
to locally gives `cat_disch` the ability to call `cases` on
`Discrete` and `(_ : Discrete _) ⟶ (_ : Discrete _)` hypotheses.
-/
def discreteCases : TacticM Unit := do
evalTactic (← `(tactic| discrete_cases))
-- TODO: investigate turning on either
-- `attribute [aesop safe cases (rule_sets := [CategoryTheory])] Discrete`
-- or
-- `attribute [aesop safe tactic (rule_sets := [CategoryTheory])] discreteCases`
-- globally.
instance [Unique α] : Unique (Discrete α) :=
Unique.mk' (Discrete α)
/-- Extract the equation from a morphism in a discrete category. -/
theorem eq_of_hom {X Y : Discrete α} (i : X ⟶ Y) : X.as = Y.as :=
i.down.down
/-- Promote an equation between the wrapped terms in `X Y : Discrete α` to a morphism `X ⟶ Y`
in the discrete category. -/
protected abbrev eqToHom {X Y : Discrete α} (h : X.as = Y.as) : X ⟶ Y :=
eqToHom (by cat_disch)
/-- Promote an equation between the wrapped terms in `X Y : Discrete α` to an isomorphism `X ≅ Y`
in the discrete category. -/
protected abbrev eqToIso {X Y : Discrete α} (h : X.as = Y.as) : X ≅ Y :=
eqToIso (by cat_disch)
/-- A variant of `eqToHom` that lifts terms to the discrete category. -/
abbrev eqToHom' {a b : α} (h : a = b) : Discrete.mk a ⟶ Discrete.mk b :=
Discrete.eqToHom h
/-- A variant of `eqToIso` that lifts terms to the discrete category. -/
abbrev eqToIso' {a b : α} (h : a = b) : Discrete.mk a ≅ Discrete.mk b :=
Discrete.eqToIso h
@[simp]
theorem id_def (X : Discrete α) : ULift.up (PLift.up (Eq.refl X.as)) = 𝟙 X :=
rfl
variable {C : Type u₂} [Category.{v₂} C]
instance {I : Type u₁} {i j : Discrete I} (f : i ⟶ j) : IsIso f :=
⟨⟨Discrete.eqToHom (eq_of_hom f).symm, by cat_disch⟩⟩
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
/-- Any function `I → C` gives a functor `Discrete I ⥤ C`. -/
def functor {I : Type u₁} (F : I → C) : Discrete I ⥤ C where
obj := F ∘ Discrete.as
map {X Y} f := by
dsimp
rcases f with ⟨⟨h⟩⟩
exact eqToHom (congrArg _ h)
@[simp]
theorem functor_obj {I : Type u₁} (F : I → C) (i : I) :
(Discrete.functor F).obj (Discrete.mk i) = F i :=
rfl
theorem functor_map {I : Type u₁} (F : I → C) {i : Discrete I} (f : i ⟶ i) :
(Discrete.functor F).map f = 𝟙 (F i.as) := by cat_disch
@[simp]
theorem functor_obj_eq_as {I : Type u₁} (F : I → C) (X : Discrete I) :
(Discrete.functor F).obj X = F X.as :=
rfl
/-- The discrete functor induced by a composition of maps can be written as a
composition of two discrete functors.
-/
@[simps!]
def functorComp {I : Type u₁} {J : Type u₁'} (f : J → C) (g : I → J) :
Discrete.functor (f ∘ g) ≅ Discrete.functor (Discrete.mk ∘ g) ⋙ Discrete.functor f :=
NatIso.ofComponents fun _ => Iso.refl _
/-- For functors out of a discrete category,
a natural transformation is just a collection of maps,
as the naturality squares are trivial.
-/
@[simps]
def natTrans {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ⟶ G.obj i) :
F ⟶ G where
app := f
naturality := fun {X Y} ⟨⟨g⟩⟩ => by
discrete_cases
rcases g
change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _)
simp
/-- For functors out of a discrete category,
a natural isomorphism is just a collection of isomorphisms,
as the naturality squares are trivial.
-/
@[simps!]
def natIso {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i) :
F ≅ G :=
NatIso.ofComponents f fun ⟨⟨g⟩⟩ => by
discrete_cases
rcases g
change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _)
simp
instance {I : Type*} {F G : Discrete I ⥤ C} (f : ∀ i, F.obj i ⟶ G.obj i) [∀ i, IsIso (f i)] :
IsIso (Discrete.natTrans f) := by
change IsIso (Discrete.natIso (fun i => asIso (f i))).hom
infer_instance
@[simp]
theorem natIso_app {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i)
(i : Discrete I) : (Discrete.natIso f).app i = f i := by cat_disch
/-- Every functor `F` from a discrete category is naturally isomorphic (actually, equal) to
`Discrete.functor (F.obj)`. -/
@[simps!]
def natIsoFunctor {I : Type u₁} {F : Discrete I ⥤ C} : F ≅ Discrete.functor (F.obj ∘ Discrete.mk) :=
natIso fun _ => Iso.refl _
/-- Composing `Discrete.functor F` with another functor `G` amounts to composing `F` with `G.obj` -/
@[simps!]
def compNatIsoDiscrete {I : Type u₁} {D : Type u₃} [Category.{v₃} D] (F : I → C) (G : C ⥤ D) :
Discrete.functor F ⋙ G ≅ Discrete.functor (G.obj ∘ F) :=
natIso fun _ => Iso.refl _
/-- We can promote a type-level `Equiv` to
an equivalence between the corresponding `discrete` categories.
-/
@[simps]
def equivalence {I : Type u₁} {J : Type u₂} (e : I ≃ J) : Discrete I ≌ Discrete J where
functor := Discrete.functor (Discrete.mk ∘ (e : I → J))
inverse := Discrete.functor (Discrete.mk ∘ (e.symm : J → I))
unitIso :=
Discrete.natIso fun i => eqToIso (by simp)
counitIso :=
Discrete.natIso fun j => eqToIso (by simp)
/-- We can convert an equivalence of `discrete` categories to a type-level `Equiv`. -/
@[simps]
def equivOfEquivalence {α : Type u₁} {β : Type u₂} (h : Discrete α ≌ Discrete β) : α ≃ β where
toFun := Discrete.as ∘ h.functor.obj ∘ Discrete.mk
invFun := Discrete.as ∘ h.inverse.obj ∘ Discrete.mk
left_inv a := by simpa using eq_of_hom (h.unitIso.app (Discrete.mk a)).2
right_inv a := by simpa using eq_of_hom (h.counitIso.app (Discrete.mk a)).1
end Discrete
namespace Discrete
variable {J : Type v₁}
open Opposite
/-- A discrete category is equivalent to its opposite category. -/
@[simps! functor_obj_as inverse_obj]
protected def opposite (α : Type u₁) : (Discrete α)ᵒᵖ ≌ Discrete α :=
let F : Discrete α ⥤ (Discrete α)ᵒᵖ := Discrete.functor fun x => op (Discrete.mk x)
{ functor := F.leftOp
inverse := F
unitIso := NatIso.ofComponents fun ⟨_⟩ => Iso.refl _
counitIso := Discrete.natIso fun ⟨_⟩ => Iso.refl _ }
variable {C : Type u₂} [Category.{v₂} C]
@[simp]
theorem functor_map_id (F : Discrete J ⥤ C) {j : Discrete J} (f : j ⟶ j) :
F.map f = 𝟙 (F.obj j) := by
have h : f = 𝟙 j := by cat_disch
rw [h]
simp
end Discrete
/-- The equivalence of categories `(J → C) ≌ (Discrete J ⥤ C)`. -/
@[simps]
def piEquivalenceFunctorDiscrete (J : Type u₂) (C : Type u₁) [Category.{v₁} C] :
(J → C) ≌ (Discrete J ⥤ C) where
functor :=
{ obj := fun F => Discrete.functor F
map := fun f => Discrete.natTrans (fun j => f j.as) }
inverse :=
{ obj := fun F j => F.obj ⟨j⟩
map := fun f j => f.app ⟨j⟩ }
unitIso := Iso.refl _
counitIso := NatIso.ofComponents (fun F => (NatIso.ofComponents (fun _ => Iso.refl _)
(by
rintro ⟨x⟩ ⟨y⟩ f
obtain rfl : x = y := Discrete.eq_of_hom f
obtain rfl : f = 𝟙 _ := rfl
simp))) (by cat_disch)
/-- A category is discrete when there is at most one morphism between two objects,
in which case they are equal. -/
class IsDiscrete (C : Type*) [Category C] : Prop where
subsingleton (X Y : C) : Subsingleton (X ⟶ Y) := by infer_instance
eq_of_hom {X Y : C} (f : X ⟶ Y) : X = Y
attribute [instance] IsDiscrete.subsingleton
instance Discrete.isDiscrete (C : Type*) : IsDiscrete (Discrete C) where
eq_of_hom := by rintro ⟨_⟩ ⟨_⟩ ⟨⟨rfl⟩⟩; rfl
section
variable {C : Type*} [Category C] [IsDiscrete C]
lemma obj_ext_of_isDiscrete {X Y : C} (f : X ⟶ Y) : X = Y := IsDiscrete.eq_of_hom f
instance isIso_of_isDiscrete {X Y : C} (f : X ⟶ Y) : IsIso f :=
⟨eqToHom (IsDiscrete.eq_of_hom f).symm, by cat_disch⟩
instance : IsDiscrete Cᵒᵖ where
eq_of_hom := by
rintro ⟨_⟩ ⟨_⟩ ⟨f⟩
obtain rfl := obj_ext_of_isDiscrete f
rfl
end
end CategoryTheory
|
Pow.lean
|
/-
Copyright (c) 2021 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Thomas Murrills
-/
import Mathlib.Data.Int.Cast.Lemmas
import Mathlib.Tactic.NormNum.Basic
/-!
## `norm_num` plugin for `^`.
-/
assert_not_exists RelIso
namespace Mathlib
open Lean
open Meta
namespace Meta.NormNum
open Qq
variable {a b c : ℕ}
theorem natPow_zero : Nat.pow a (nat_lit 0) = nat_lit 1 := rfl
theorem natPow_one : Nat.pow a (nat_lit 1) = a := Nat.pow_one _
theorem zero_natPow : Nat.pow (nat_lit 0) (Nat.succ b) = nat_lit 0 := rfl
theorem one_natPow : Nat.pow (nat_lit 1) b = nat_lit 1 := Nat.one_pow _
/-- This is an opaque wrapper around `Nat.pow` to prevent lean from unfolding the definition of
`Nat.pow` on numerals. The arbitrary precondition `p` is actually a formula of the form
`Nat.pow a' b' = c'` but we usually don't care to unfold this proposition so we just carry a
reference to it. -/
structure IsNatPowT (p : Prop) (a b c : Nat) : Prop where
/-- Unfolds the assertion. -/
run' : p → Nat.pow a b = c
theorem IsNatPowT.run
(p : IsNatPowT (Nat.pow a (nat_lit 1) = a) a b c) : Nat.pow a b = c := p.run' (Nat.pow_one _)
/-- This is the key to making the proof proceed as a balanced tree of applications instead of
a linear sequence. It is just modus ponens after unwrapping the definitions. -/
theorem IsNatPowT.trans {p : Prop} {b' c' : ℕ} (h1 : IsNatPowT p a b c)
(h2 : IsNatPowT (Nat.pow a b = c) a b' c') : IsNatPowT p a b' c' :=
⟨h2.run' ∘ h1.run'⟩
theorem IsNatPowT.bit0 : IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b) (Nat.mul c c) :=
⟨fun h1 => by simp [two_mul, pow_add, ← h1]⟩
theorem IsNatPowT.bit1 :
IsNatPowT (Nat.pow a b = c) a (nat_lit 2 * b + nat_lit 1) (Nat.mul c (Nat.mul c a)) :=
⟨fun h1 => by simp [two_mul, pow_add, mul_assoc, ← h1]⟩
/--
Proves `Nat.pow a b = c` where `a` and `b` are raw nat literals. This could be done by just
`rfl` but the kernel does not have a special case implementation for `Nat.pow` so this would
proceed by unary recursion on `b`, which is too slow and also leads to deep recursion.
We instead do the proof by binary recursion, but this can still lead to deep recursion,
so we use an additional trick to do binary subdivision on `log2 b`. As a result this produces
a proof of depth `log (log b)` which will essentially never overflow before the numbers involved
themselves exceed memory limits.
-/
partial def evalNatPow (a b : Q(ℕ)) : (c : Q(ℕ)) × Q(Nat.pow $a $b = $c) :=
if b.natLit! = 0 then
haveI : $b =Q 0 := ⟨⟩
⟨q(nat_lit 1), q(natPow_zero)⟩
else if a.natLit! = 0 then
haveI : $a =Q 0 := ⟨⟩
have b' : Q(ℕ) := mkRawNatLit (b.natLit! - 1)
haveI : $b =Q Nat.succ $b' := ⟨⟩
⟨q(nat_lit 0), q(zero_natPow)⟩
else if a.natLit! = 1 then
haveI : $a =Q 1 := ⟨⟩
⟨q(nat_lit 1), q(one_natPow)⟩
else if b.natLit! = 1 then
haveI : $b =Q 1 := ⟨⟩
⟨a, q(natPow_one)⟩
else
let ⟨c, p⟩ := go b.natLit!.log2 a (mkRawNatLit 1) a b _ .rfl
⟨c, q(($p).run)⟩
where
/-- Invariants: `a ^ b₀ = c₀`, `depth > 0`, `b >>> depth = b₀`, `p := Nat.pow $a $b₀ = $c₀` -/
go (depth : Nat) (a b₀ c₀ b : Q(ℕ)) (p : Q(Prop)) (hp : $p =Q (Nat.pow $a $b₀ = $c₀)) :
(c : Q(ℕ)) × Q(IsNatPowT $p $a $b $c) :=
let b' := b.natLit!
if depth ≤ 1 then
let a' := a.natLit!
let c₀' := c₀.natLit!
if b' &&& 1 == 0 then
have c : Q(ℕ) := mkRawNatLit (c₀' * c₀')
haveI : $c =Q Nat.mul $c₀ $c₀ := ⟨⟩
haveI : $b =Q 2 * $b₀ := ⟨⟩
⟨c, q(IsNatPowT.bit0)⟩
else
have c : Q(ℕ) := mkRawNatLit (c₀' * (c₀' * a'))
haveI : $c =Q Nat.mul $c₀ (Nat.mul $c₀ $a) := ⟨⟩
haveI : $b =Q 2 * $b₀ + 1 := ⟨⟩
⟨c, q(IsNatPowT.bit1)⟩
else
let d := depth >>> 1
have hi : Q(ℕ) := mkRawNatLit (b' >>> d)
let ⟨c1, p1⟩ := go (depth - d) a b₀ c₀ hi p (by exact hp)
let ⟨c2, p2⟩ := go d a hi c1 b q(Nat.pow $a $hi = $c1) ⟨⟩
⟨c2, q(($p1).trans $p2)⟩
theorem intPow_ofNat (h1 : Nat.pow a b = c) :
Int.pow (Int.ofNat a) b = Int.ofNat c := by simp [← h1]
theorem intPow_negOfNat_bit0 {b' c' : ℕ} (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' = b) (hc : c' * c' = c) :
Int.pow (Int.negOfNat a) b = Int.ofNat c := by
rw [← hb, Int.negOfNat_eq, Int.pow_eq, pow_mul, neg_pow_two, ← pow_mul, two_mul, pow_add, ← hc,
← h1]
simp
theorem intPow_negOfNat_bit1 {b' c' : ℕ} (h1 : Nat.pow a b' = c')
(hb : nat_lit 2 * b' + nat_lit 1 = b) (hc : c' * (c' * a) = c) :
Int.pow (Int.negOfNat a) b = Int.negOfNat c := by
rw [← hb, Int.negOfNat_eq, Int.negOfNat_eq, Int.pow_eq, pow_succ, pow_mul, neg_pow_two, ← pow_mul,
two_mul, pow_add, ← hc, ← h1]
simp [mul_comm, mul_left_comm]
/-- Evaluates `Int.pow a b = c` where `a` and `b` are raw integer literals. -/
partial def evalIntPow (za : ℤ) (a : Q(ℤ)) (b : Q(ℕ)) : ℤ × (c : Q(ℤ)) × Q(Int.pow $a $b = $c) :=
have a' : Q(ℕ) := a.appArg!
if 0 ≤ za then
haveI : $a =Q .ofNat $a' := ⟨⟩
let ⟨c, p⟩ := evalNatPow a' b
⟨c.natLit!, q(.ofNat $c), q(intPow_ofNat $p)⟩
else
haveI : $a =Q .negOfNat $a' := ⟨⟩
let b' := b.natLit!
have b₀ : Q(ℕ) := mkRawNatLit (b' >>> 1)
let ⟨c₀, p⟩ := evalNatPow a' b₀
let c' := c₀.natLit!
if b' &&& 1 == 0 then
have c : Q(ℕ) := mkRawNatLit (c' * c')
have pc : Q($c₀ * $c₀ = $c) := (q(Eq.refl $c) : Expr)
have pb : Q(2 * $b₀ = $b) := (q(Eq.refl $b) : Expr)
⟨c.natLit!, q(.ofNat $c), q(intPow_negOfNat_bit0 $p $pb $pc)⟩
else
have c : Q(ℕ) := mkRawNatLit (c' * (c' * a'.natLit!))
have pc : Q($c₀ * ($c₀ * $a') = $c) := (q(Eq.refl $c) : Expr)
have pb : Q(2 * $b₀ + 1 = $b) := (q(Eq.refl $b) : Expr)
⟨-c.natLit!, q(.negOfNat $c), q(intPow_negOfNat_bit1 $p $pb $pc)⟩
-- see note [norm_num lemma function equality]
theorem isNat_pow {α} [Semiring α] : ∀ {f : α → ℕ → α} {a : α} {b a' b' c : ℕ},
f = HPow.hPow → IsNat a a' → IsNat b b' → Nat.pow a' b' = c → IsNat (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩
-- see note [norm_num lemma function equality]
theorem isInt_pow {α} [Ring α] : ∀ {f : α → ℕ → α} {a : α} {b : ℕ} {a' : ℤ} {b' : ℕ} {c : ℤ},
f = HPow.hPow → IsInt a a' → IsNat b b' → Int.pow a' b' = c → IsInt (f a b) c
| _, _, _, _, _, _, rfl, ⟨rfl⟩, ⟨rfl⟩, rfl => ⟨by simp⟩
-- see note [norm_num lemma function equality]
theorem isRat_pow {α} [Ring α] {f : α → ℕ → α} {a : α} {an cn : ℤ} {ad b b' cd : ℕ} :
f = HPow.hPow → IsRat a an ad → IsNat b b' →
Int.pow an b' = cn → Nat.pow ad b' = cd →
IsRat (f a b) cn cd := by
rintro rfl ⟨_, rfl⟩ ⟨rfl⟩ (rfl : an ^ b = _) (rfl : ad ^ b = _)
have := invertiblePow (ad:α) b
rw [← Nat.cast_pow] at this
use this; simp [invOf_pow, Commute.mul_pow]
theorem isNNRat_pow {α} [Semiring α] {f : α → ℕ → α} {a : α} {an cn : ℕ} {ad b b' cd : ℕ} :
f = HPow.hPow → IsNNRat a an ad → IsNat b b' →
Nat.pow an b' = cn → Nat.pow ad b' = cd →
IsNNRat (f a b) cn cd := by
rintro rfl ⟨_, rfl⟩ ⟨rfl⟩ (rfl : an ^ b = _) (rfl : ad ^ b = _)
have := invertiblePow (ad:α) b
rw [← Nat.cast_pow] at this
use this; simp [invOf_pow, Commute.mul_pow, Nat.cast_commute]
attribute [local instance] monadLiftOptionMetaM in
/-- The `norm_num` extension which identifies expressions of the form `a ^ b`,
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℕ`. -/
@[norm_num _ ^ (_ : ℕ)]
def evalPow : NormNumExt where eval {u α} e := do
let .app (.app (f : Q($α → ℕ → $α)) (a : Q($α))) (b : Q(ℕ)) ← whnfR e | failure
let ⟨nb, pb⟩ ← deriveNat b q(instAddMonoidWithOneNat)
let sα ← inferSemiring α
let ra ← derive a
guard <|← withDefault <| withNewMCtxDepth <| isDefEq f q(HPow.hPow (α := $α))
haveI' : $e =Q $a ^ $b := ⟨⟩
haveI' : $f =Q HPow.hPow := ⟨⟩
let rec
/-- Main part of `evalPow`. -/
core : Option (Result e) := do
match ra with
| .isBool .. => failure
| .isNat sα na pa =>
assumeInstancesCommute
have ⟨c, r⟩ := evalNatPow na nb
return .isNat sα c q(isNat_pow (f := $f) (.refl $f) $pa $pb $r)
| .isNegNat rα .. =>
assumeInstancesCommute
let ⟨za, na, pa⟩ ← ra.toInt rα
have ⟨zc, c, r⟩ := evalIntPow za na nb
return .isInt rα c zc q(isInt_pow (f := $f) (.refl $f) $pa $pb $r)
| .isNNRat dα _qa na da pa =>
assumeInstancesCommute
have ⟨nc, r1⟩ := evalNatPow na nb
have ⟨dc, r2⟩ := evalNatPow da nb
let qc := mkRat nc.natLit! dc.natLit!
return .isNNRat dα qc nc dc q(isNNRat_pow (f := $f) (.refl $f) $pa $pb $r1 $r2)
| .isNegNNRat dα qa na da pa =>
assumeInstancesCommute
have ⟨zc, nc, r1⟩ := evalIntPow qa.num q(Int.negOfNat $na) nb
have ⟨dc, r2⟩ := evalNatPow da nb
let qc := mkRat zc dc.natLit!
return .isRat dα qc nc dc q(isRat_pow (f := $f) (.refl $f) $pa $pb $r1 $r2)
core
theorem isNat_zpow_pos {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsNat b nb) (pe' : IsNat (a ^ nb) ne) :
IsNat (a ^ b) ne := by
rwa [pb.out, zpow_natCast]
theorem isNat_zpow_neg {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsNat (a ^ nb)⁻¹ ne) :
IsNat (a ^ b) ne := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast]
theorem isInt_zpow_pos {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsNat b nb) (pe' : IsInt (a ^ nb) (Int.negOfNat ne)) :
IsInt (a ^ b) (Int.negOfNat ne) := by
rwa [pb.out, zpow_natCast]
theorem isInt_zpow_neg {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb ne : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsInt (a ^ nb)⁻¹ (Int.negOfNat ne)) :
IsInt (a ^ b) (Int.negOfNat ne) := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast]
theorem isNNRat_zpow_pos {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℕ} {den : ℕ}
(pb : IsNat b nb) (pe' : IsNNRat (a ^ nb) num den) :
IsNNRat (a^b) num den := by
rwa [pb.out, zpow_natCast]
theorem isNNRat_zpow_neg {α : Type*} [DivisionSemiring α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℕ} {den : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsNNRat ((a ^ nb)⁻¹) num den) :
IsNNRat (a^b) num den := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast]
theorem isRat_zpow_pos {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℤ} {den : ℕ}
(pb : IsNat b nb) (pe' : IsRat (a ^ nb) num den) :
IsRat (a ^ b) num den := by
rwa [pb.out, zpow_natCast]
theorem isRat_zpow_neg {α : Type*} [DivisionRing α] {a : α} {b : ℤ} {nb : ℕ}
{num : ℤ} {den : ℕ}
(pb : IsInt b (Int.negOfNat nb)) (pe' : IsRat ((a ^ nb)⁻¹) num den) :
IsRat (a ^ b) num den := by
rwa [pb.out, Int.cast_negOfNat, zpow_neg, zpow_natCast]
#adaptation_note /-- https://github.com/leanprover/lean4/pull/4096
the repeated
```
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
```
blocks below were not necessary: we just did it once outside the `match rb with` block.
-/
/-- The `norm_num` extension which identifies expressions of the form `a ^ b`,
such that `norm_num` successfully recognises both `a` and `b`, with `b : ℤ`. -/
@[norm_num _ ^ (_ : ℤ)]
def evalZPow : NormNumExt where eval {u α} e := do
let .app (.app (f : Q($α → ℤ → $α)) (a : Q($α))) (b : Q(ℤ)) ← whnfR e | failure
let _c ← synthInstanceQ q(DivisionSemiring $α)
let rb ← derive (α := q(ℤ)) b
match rb with
| .isBool .. | .isNNRat _ .. | .isNegNNRat _ .. => failure
| .isNat sβ nb pb =>
match ← derive q($a ^ $nb) with
| .isBool .. => failure
| .isNat sα' ne' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
return .isNat sα' ne' q(isNat_zpow_pos $pb $pe')
| .isNegNat sα' ne' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
let _c ← synthInstanceQ q(DivisionRing $α)
assumeInstancesCommute
return .isNegNat sα' ne' q(isInt_zpow_pos $pb $pe')
| .isNNRat dsα' qe' nume' dene' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
return .isNNRat dsα' qe' nume' dene' q(isNNRat_zpow_pos $pb $pe')
| .isNegNNRat dα' qe' nume' dene' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
let proof := q(isRat_zpow_pos $pb $pe')
return .isRat dα' qe' nume' dene' proof
| .isNegNat sβ nb pb =>
match ← derive q(($a ^ $nb)⁻¹) with
| .isBool .. => failure
| .isNat sα' ne' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
return .isNat sα' ne' q(isNat_zpow_neg $pb $pe')
| .isNegNat sα' ne' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
let _c ← synthInstanceQ q(DivisionRing $α)
assumeInstancesCommute
return .isNegNat sα' ne' q(isInt_zpow_neg $pb $pe')
| .isNNRat dsα' qe' nume' dene' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
return .isNNRat dsα' qe' nume' dene' q(isNNRat_zpow_neg $pb $pe')
| .isNegNNRat dα' qe' nume' dene' pe' =>
have h : $e =Q (HPow.hPow (γ := $α) $a $b) := ⟨⟩
h.check
assumeInstancesCommute
return .isRat dα' qe' q(.negOfNat $nume') dene' q(isRat_zpow_neg $pb $pe')
end NormNum
end Meta
end Mathlib
|
Defs.lean
|
/-
Copyright (c) 2020 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Algebra.Group.Submonoid.Defs
import Mathlib.Data.Set.Inclusion
import Mathlib.Tactic.Common
import Mathlib.Tactic.FastInstance
/-!
# Subgroups
This file defines multiplicative and additive subgroups as an extension of submonoids, in a bundled
form (unbundled subgroups are in `Deprecated/Subgroups.lean`).
Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration.
## Main definitions
Notation used here:
- `G N` are `Group`s
- `A` is an `AddGroup`
- `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A`
- `x` is an element of type `G` or type `A`
- `f g : N →* G` are group homomorphisms
- `s k` are sets of elements of type `G`
Definitions in the file:
* `Subgroup G` : the type of subgroups of a group `G`
* `AddSubgroup A` : the type of subgroups of an additive group `A`
* `Subgroup.subtype` : the natural group homomorphism from a subgroup of group `G` to `G`
## Implementation notes
Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as
membership of a subgroup's underlying set.
## Tags
subgroup, subgroups
-/
assert_not_exists RelIso OrderedCommMonoid Multiset MonoidWithZero
open Function
open scoped Int
variable {G : Type*} [Group G] {A : Type*} [AddGroup A]
section SubgroupClass
/-- `InvMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under inverses. -/
class InvMemClass (S : Type*) (G : outParam Type*) [Inv G] [SetLike S G] : Prop where
/-- `s` is closed under inverses -/
inv_mem : ∀ {s : S} {x}, x ∈ s → x⁻¹ ∈ s
export InvMemClass (inv_mem)
/-- `NegMemClass S G` states `S` is a type of subsets `s ⊆ G` closed under negation. -/
class NegMemClass (S : Type*) (G : outParam Type*) [Neg G] [SetLike S G] : Prop where
/-- `s` is closed under negation -/
neg_mem : ∀ {s : S} {x}, x ∈ s → -x ∈ s
export NegMemClass (neg_mem)
/-- `SubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are subgroups of `G`. -/
class SubgroupClass (S : Type*) (G : outParam Type*) [DivInvMonoid G] [SetLike S G] : Prop
extends SubmonoidClass S G, InvMemClass S G
/-- `AddSubgroupClass S G` states `S` is a type of subsets `s ⊆ G` that are
additive subgroups of `G`. -/
class AddSubgroupClass (S : Type*) (G : outParam Type*) [SubNegMonoid G] [SetLike S G] : Prop
extends AddSubmonoidClass S G, NegMemClass S G
attribute [to_additive] InvMemClass SubgroupClass
attribute [aesop 90% (rule_sets := [SetLike])] inv_mem neg_mem
@[to_additive (attr := simp)]
theorem inv_mem_iff {S G} [InvolutiveInv G] {_ : SetLike S G} [InvMemClass S G] {H : S}
{x : G} : x⁻¹ ∈ H ↔ x ∈ H :=
⟨fun h => inv_inv x ▸ inv_mem h, inv_mem⟩
variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S}
/-- A subgroup is closed under division. -/
@[to_additive (attr := aesop 90% (rule_sets := [SetLike]))
/-- An additive subgroup is closed under subtraction. -/]
theorem div_mem {x y : M} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H := by
rw [div_eq_mul_inv]; exact mul_mem hx (inv_mem hy)
@[to_additive (attr := aesop 90% (rule_sets := [SetLike]))]
theorem zpow_mem {x : M} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K
| (n : ℕ) => by
rw [zpow_natCast]
exact pow_mem hx n
| -[n+1] => by
rw [zpow_negSucc]
exact inv_mem (pow_mem hx n.succ)
variable [SetLike S G] [SubgroupClass S G]
@[to_additive]
theorem exists_inv_mem_iff_exists_mem {P : G → Prop} :
(∃ x : G, x ∈ H ∧ P x⁻¹) ↔ ∃ x ∈ H, P x := by
constructor <;>
· rintro ⟨x, x_in, hx⟩
exact ⟨x⁻¹, inv_mem x_in, by simp [hx]⟩
@[to_additive]
theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H :=
⟨fun hba => by simpa using mul_mem hba (inv_mem h), fun hb => mul_mem hb h⟩
@[to_additive]
theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H :=
⟨fun hab => by simpa using mul_mem (inv_mem h) hab, mul_mem h⟩
namespace InvMemClass
/-- A subgroup of a group inherits an inverse. -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits an inverse. -/]
instance inv {G S : Type*} [Inv G] [SetLike S G] [InvMemClass S G] {H : S} : Inv H :=
⟨fun a => ⟨a⁻¹, inv_mem a.2⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (x : H) : (x⁻¹).1 = x.1⁻¹ :=
rfl
end InvMemClass
namespace SubgroupClass
-- Here we assume H, K, and L are subgroups, but in fact any one of them
-- could be allowed to be a subsemigroup.
-- Counterexample where K and L are submonoids: H = ℤ, K = ℕ, L = -ℕ
-- Counterexample where H and K are submonoids: H = {n | n = 0 ∨ 3 ≤ n}, K = 3ℕ + 4ℕ, L = 5ℤ
@[to_additive]
theorem subset_union {H K L : S} : (H : Set G) ⊆ K ∪ L ↔ H ≤ K ∨ H ≤ L := by
refine ⟨fun h ↦ ?_, fun h x xH ↦ h.imp (· xH) (· xH)⟩
rw [or_iff_not_imp_left, SetLike.not_le_iff_exists]
exact fun ⟨x, xH, xK⟩ y yH ↦ (h <| mul_mem xH yH).elim
((h yH).resolve_left fun yK ↦ xK <| (mul_mem_cancel_right yK).mp ·)
(mul_mem_cancel_left <| (h xH).resolve_left xK).mp
/-- A subgroup of a group inherits a division -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits a subtraction. -/]
instance div {G S : Type*} [DivInvMonoid G] [SetLike S G] [SubgroupClass S G] {H : S} : Div H :=
⟨fun a b => ⟨a / b, div_mem a.2 b.2⟩⟩
/-- An additive subgroup of an `AddGroup` inherits an integer scaling. -/
instance _root_.AddSubgroupClass.zsmul {M S} [SubNegMonoid M] [SetLike S M]
[AddSubgroupClass S M] {H : S} : SMul ℤ H :=
⟨fun n a => ⟨n • a.1, zsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits an integer power. -/
@[to_additive existing]
instance zpow {M S} [DivInvMonoid M] [SetLike S M] [SubgroupClass S M] {H : S} : Pow H ℤ :=
⟨fun a n => ⟨a.1 ^ n, zpow_mem a.2 n⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (x y : H) : (x / y).1 = x.1 / y.1 :=
rfl
variable (H)
-- Prefer subclasses of `Group` over subclasses of `SubgroupClass`.
/-- A subgroup of a group inherits a group structure. -/
@[to_additive /-- An additive subgroup of an `AddGroup` inherits an `AddGroup` structure. -/]
instance (priority := 75) toGroup : Group H := fast_instance%
Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
-- Prefer subclasses of `CommGroup` over subclasses of `SubgroupClass`.
/-- A subgroup of a `CommGroup` is a `CommGroup`. -/
@[to_additive /-- An additive subgroup of an `AddCommGroup` is an `AddCommGroup`. -/]
instance (priority := 75) toCommGroup {G : Type*} [CommGroup G] [SetLike S G] [SubgroupClass S G] :
CommGroup H := fast_instance%
Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- The natural group hom from a subgroup of group `G` to `G`. -/
@[to_additive (attr := coe)
/-- The natural group hom from an additive subgroup of `AddGroup` `G` to `G`. -/]
protected def subtype : H →* G where
toFun := ((↑) : H → G); map_one' := rfl; map_mul' := fun _ _ => rfl
variable {H} in
@[to_additive (attr := simp)]
lemma subtype_apply (x : H) :
SubgroupClass.subtype H x = x := rfl
@[to_additive]
lemma subtype_injective :
Function.Injective (SubgroupClass.subtype H) :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : (SubgroupClass.subtype H : H → G) = ((↑) : H → G) := by
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
@[deprecated (since := "2025-02-18")]
alias _root_.AddSubgroupClass.coeSubtype := _root_.AddSubgroupClass.coe_subtype
variable {H}
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/
@[to_additive
/-- The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`. -/]
def inclusion {H K : S} (h : H ≤ K) : H →* K :=
MonoidHom.mk' (fun x => ⟨x, h x.prop⟩) fun _ _ => rfl
@[to_additive (attr := simp)]
theorem inclusion_self (x : H) : inclusion le_rfl x = x := by
cases x
rfl
@[to_additive (attr := simp)]
theorem inclusion_mk {h : H ≤ K} (x : G) (hx : x ∈ H) : inclusion h ⟨x, hx⟩ = ⟨x, h hx⟩ :=
rfl
@[to_additive]
theorem inclusion_right (h : H ≤ K) (x : K) (hx : (x : G) ∈ H) : inclusion h ⟨x, hx⟩ = x := by
cases x
rfl
@[simp]
theorem inclusion_inclusion {L : S} (hHK : H ≤ K) (hKL : K ≤ L) (x : H) :
inclusion hKL (inclusion hHK x) = inclusion (hHK.trans hKL) x := by
cases x
rfl
@[to_additive (attr := simp)]
theorem coe_inclusion {H K : S} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by
cases a
simp only [inclusion, MonoidHom.mk'_apply]
@[to_additive (attr := simp)]
theorem subtype_comp_inclusion {H K : S} (hH : H ≤ K) :
(SubgroupClass.subtype K).comp (inclusion hH) = SubgroupClass.subtype H := by
ext
simp only [MonoidHom.comp_apply, coe_subtype, coe_inclusion]
end SubgroupClass
end SubgroupClass
/-- A subgroup of a group `G` is a subset containing 1, closed under multiplication
and closed under multiplicative inverse. -/
structure Subgroup (G : Type*) [Group G] extends Submonoid G where
/-- `G` is closed under inverses -/
inv_mem' {x} : x ∈ carrier → x⁻¹ ∈ carrier
/-- An additive subgroup of an additive group `G` is a subset containing 0, closed
under addition and additive inverse. -/
structure AddSubgroup (G : Type*) [AddGroup G] extends AddSubmonoid G where
/-- `G` is closed under negation -/
neg_mem' {x} : x ∈ carrier → -x ∈ carrier
attribute [to_additive] Subgroup
/-- Reinterpret a `Subgroup` as a `Submonoid`. -/
add_decl_doc Subgroup.toSubmonoid
/-- Reinterpret an `AddSubgroup` as an `AddSubmonoid`. -/
add_decl_doc AddSubgroup.toAddSubmonoid
namespace Subgroup
@[to_additive]
instance : SetLike (Subgroup G) G where
coe s := s.carrier
coe_injective' p q h := by
obtain ⟨⟨⟨hp,_⟩,_⟩,_⟩ := p
obtain ⟨⟨⟨hq,_⟩,_⟩,_⟩ := q
congr
initialize_simps_projections Subgroup (carrier → coe, as_prefix coe)
initialize_simps_projections AddSubgroup (carrier → coe, as_prefix coe)
/-- The actual `Subgroup` obtained from an element of a `SubgroupClass` -/
@[to_additive (attr := simps) /-- The actual `AddSubgroup` obtained from an element of a
`AddSubgroupClass` -/]
def ofClass {S G : Type*} [Group G] [SetLike S G] [SubgroupClass S G]
(s : S) : Subgroup G :=
⟨⟨⟨s, MulMemClass.mul_mem⟩, OneMemClass.one_mem s⟩, InvMemClass.inv_mem⟩
@[to_additive]
instance (priority := 100) : CanLift (Set G) (Subgroup G) (↑)
(fun s ↦ 1 ∈ s ∧ (∀ {x y}, x ∈ s → y ∈ s → x * y ∈ s) ∧ ∀ {x}, x ∈ s → x⁻¹ ∈ s) where
prf s h := ⟨{ carrier := s, one_mem' := h.1, mul_mem' := h.2.1, inv_mem' := h.2.2}, rfl⟩
-- TODO: Below can probably be written more uniformly
@[to_additive]
instance : SubgroupClass (Subgroup G) G where
inv_mem := Subgroup.inv_mem' _
one_mem _ := (Subgroup.toSubmonoid _).one_mem'
mul_mem := (Subgroup.toSubmonoid _).mul_mem'
-- This is not a simp lemma,
-- because the simp normal form left-hand side is given by `mem_toSubmonoid` below.
@[to_additive]
theorem mem_carrier {s : Subgroup G} {x : G} : x ∈ s.carrier ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem mem_mk {s : Submonoid G} {x : G} (h_inv) :
x ∈ mk s h_inv ↔ x ∈ s :=
Iff.rfl
@[to_additive (attr := simp)]
theorem coe_set_mk {s : Submonoid G} (h_inv) :
(mk s h_inv : Set G) = s :=
rfl
@[to_additive (attr := simp)]
theorem mk_le_mk {s t : Submonoid G} (h_inv) (h_inv') :
mk s h_inv ≤ mk t h_inv' ↔ s ≤ t :=
Iff.rfl
@[to_additive (attr := simp)]
theorem coe_toSubmonoid (K : Subgroup G) : (K.toSubmonoid : Set G) = K :=
rfl
@[to_additive (attr := simp)]
theorem mem_toSubmonoid (K : Subgroup G) (x : G) : x ∈ K.toSubmonoid ↔ x ∈ K :=
Iff.rfl
@[to_additive]
theorem toSubmonoid_injective : Function.Injective (toSubmonoid : Subgroup G → Submonoid G) :=
fun p q h => by
have := SetLike.ext'_iff.1 h
rw [coe_toSubmonoid, coe_toSubmonoid] at this
exact SetLike.ext'_iff.2 this
@[to_additive (attr := simp)]
theorem toSubmonoid_inj {p q : Subgroup G} : p.toSubmonoid = q.toSubmonoid ↔ p = q :=
toSubmonoid_injective.eq_iff
@[to_additive (attr := mono)]
theorem toSubmonoid_strictMono : StrictMono (toSubmonoid : Subgroup G → Submonoid G) := fun _ _ =>
id
@[to_additive (attr := mono)]
theorem toSubmonoid_mono : Monotone (toSubmonoid : Subgroup G → Submonoid G) :=
toSubmonoid_strictMono.monotone
@[to_additive (attr := simp)]
theorem toSubmonoid_le {p q : Subgroup G} : p.toSubmonoid ≤ q.toSubmonoid ↔ p ≤ q :=
Iff.rfl
@[to_additive (attr := simp)]
lemma coe_nonempty (s : Subgroup G) : (s : Set G).Nonempty := ⟨1, one_mem _⟩
end Subgroup
namespace Subgroup
variable (H K : Subgroup G)
/-- Copy of a subgroup with a new `carrier` equal to the old one. Useful to fix definitional
equalities. -/
@[to_additive (attr := simps)
/-- Copy of an additive subgroup with a new `carrier` equal to the old one.
Useful to fix definitional equalities -/]
protected def copy (K : Subgroup G) (s : Set G) (hs : s = K) : Subgroup G where
carrier := s
one_mem' := hs.symm ▸ K.one_mem'
mul_mem' := hs.symm ▸ K.mul_mem'
inv_mem' hx := by simpa [hs] using hx
@[to_additive]
theorem copy_eq (K : Subgroup G) (s : Set G) (hs : s = ↑K) : K.copy s hs = K :=
SetLike.coe_injective hs
/-- Two subgroups are equal if they have the same elements. -/
@[to_additive (attr := ext) /-- Two `AddSubgroup`s are equal if they have the same elements. -/]
theorem ext {H K : Subgroup G} (h : ∀ x, x ∈ H ↔ x ∈ K) : H = K :=
SetLike.ext h
/-- A subgroup contains the group's 1. -/
@[to_additive /-- An `AddSubgroup` contains the group's 0. -/]
protected theorem one_mem : (1 : G) ∈ H :=
one_mem _
/-- A subgroup is closed under multiplication. -/
@[to_additive /-- An `AddSubgroup` is closed under addition. -/]
protected theorem mul_mem {x y : G} : x ∈ H → y ∈ H → x * y ∈ H :=
mul_mem
/-- A subgroup is closed under inverse. -/
@[to_additive /-- An `AddSubgroup` is closed under inverse. -/]
protected theorem inv_mem {x : G} : x ∈ H → x⁻¹ ∈ H :=
inv_mem
/-- A subgroup is closed under division. -/
@[to_additive /-- An `AddSubgroup` is closed under subtraction. -/]
protected theorem div_mem {x y : G} (hx : x ∈ H) (hy : y ∈ H) : x / y ∈ H :=
div_mem hx hy
@[to_additive]
protected theorem inv_mem_iff {x : G} : x⁻¹ ∈ H ↔ x ∈ H :=
inv_mem_iff
@[to_additive]
protected theorem exists_inv_mem_iff_exists_mem (K : Subgroup G) {P : G → Prop} :
(∃ x : G, x ∈ K ∧ P x⁻¹) ↔ ∃ x ∈ K, P x :=
exists_inv_mem_iff_exists_mem
@[to_additive]
protected theorem mul_mem_cancel_right {x y : G} (h : x ∈ H) : y * x ∈ H ↔ y ∈ H :=
mul_mem_cancel_right h
@[to_additive]
protected theorem mul_mem_cancel_left {x y : G} (h : x ∈ H) : x * y ∈ H ↔ y ∈ H :=
mul_mem_cancel_left h
@[to_additive]
protected theorem pow_mem {x : G} (hx : x ∈ K) : ∀ n : ℕ, x ^ n ∈ K :=
pow_mem hx
@[to_additive]
protected theorem zpow_mem {x : G} (hx : x ∈ K) : ∀ n : ℤ, x ^ n ∈ K :=
zpow_mem hx
/-- Construct a subgroup from a nonempty set that is closed under division. -/
@[to_additive /-- Construct a subgroup from a nonempty set that is closed under subtraction -/]
def ofDiv (s : Set G) (hsn : s.Nonempty) (hs : ∀ᵉ (x ∈ s) (y ∈ s), x * y⁻¹ ∈ s) :
Subgroup G :=
have one_mem : (1 : G) ∈ s := by
let ⟨x, hx⟩ := hsn
simpa using hs x hx x hx
have inv_mem : ∀ x, x ∈ s → x⁻¹ ∈ s := fun x hx => by simpa using hs 1 one_mem x hx
{ carrier := s
one_mem' := one_mem
inv_mem' := inv_mem _
mul_mem' := fun hx hy => by simpa using hs _ hx _ (inv_mem _ hy) }
/-- A subgroup of a group inherits a multiplication. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an addition. -/]
instance mul : Mul H :=
H.toSubmonoid.mul
/-- A subgroup of a group inherits a 1. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits a zero. -/]
instance one : One H :=
H.toSubmonoid.one
/-- A subgroup of a group inherits an inverse. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an inverse. -/]
instance inv : Inv H :=
⟨fun a => ⟨a⁻¹, H.inv_mem a.2⟩⟩
/-- A subgroup of a group inherits a division -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits a subtraction. -/]
instance div : Div H :=
⟨fun a b => ⟨a / b, H.div_mem a.2 b.2⟩⟩
/-- An `AddSubgroup` of an `AddGroup` inherits a natural scaling. -/
instance _root_.AddSubgroup.nsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℕ H :=
⟨fun n a => ⟨n • a, H.nsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits a natural power -/
@[to_additive existing]
protected instance npow : Pow H ℕ :=
⟨fun a n => ⟨a ^ n, H.pow_mem a.2 n⟩⟩
/-- An `AddSubgroup` of an `AddGroup` inherits an integer scaling. -/
instance _root_.AddSubgroup.zsmul {G} [AddGroup G] {H : AddSubgroup G} : SMul ℤ H :=
⟨fun n a => ⟨n • a, H.zsmul_mem a.2 n⟩⟩
/-- A subgroup of a group inherits an integer power -/
@[to_additive existing]
instance zpow : Pow H ℤ :=
⟨fun a n => ⟨a ^ n, H.zpow_mem a.2 n⟩⟩
@[to_additive (attr := simp, norm_cast)]
theorem coe_mul (x y : H) : (↑(x * y) : G) = ↑x * ↑y :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_one : ((1 : H) : G) = 1 :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv (x : H) : ↑(x⁻¹ : H) = (x⁻¹ : G) :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_div (x y : H) : (↑(x / y) : G) = ↑x / ↑y :=
rfl
@[to_additive (attr := norm_cast)]
theorem coe_mk (x : G) (hx : x ∈ H) : ((⟨x, hx⟩ : H) : G) = x :=
rfl
@[to_additive (attr := simp, norm_cast)]
theorem coe_pow (x : H) (n : ℕ) : ((x ^ n : H) : G) = (x : G) ^ n :=
rfl
@[to_additive (attr := norm_cast)]
theorem coe_zpow (x : H) (n : ℤ) : ((x ^ n : H) : G) = (x : G) ^ n := by
dsimp
@[to_additive (attr := simp)]
theorem mk_eq_one {g : G} {h} : (⟨g, h⟩ : H) = 1 ↔ g = 1 := Submonoid.mk_eq_one ..
/-- A subgroup of a group inherits a group structure. -/
@[to_additive /-- An `AddSubgroup` of an `AddGroup` inherits an `AddGroup` structure. -/]
instance toGroup {G : Type*} [Group G] (H : Subgroup G) : Group H := fast_instance%
Subtype.coe_injective.group _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- A subgroup of a `CommGroup` is a `CommGroup`. -/
@[to_additive /-- An `AddSubgroup` of an `AddCommGroup` is an `AddCommGroup`. -/]
instance toCommGroup {G : Type*} [CommGroup G] (H : Subgroup G) : CommGroup H := fast_instance%
Subtype.coe_injective.commGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl)
(fun _ _ => rfl) fun _ _ => rfl
/-- The natural group hom from a subgroup of group `G` to `G`. -/
@[to_additive /-- The natural group hom from an `AddSubgroup` of `AddGroup` `G` to `G`. -/]
protected def subtype : H →* G where
toFun := ((↑) : H → G); map_one' := rfl; map_mul' _ _ := rfl
@[to_additive (attr := simp)]
lemma subtype_apply {s : Subgroup G} (x : s) :
s.subtype x = x := rfl
@[to_additive]
lemma subtype_injective (s : Subgroup G) :
Function.Injective s.subtype :=
Subtype.coe_injective
@[to_additive (attr := simp)]
theorem coe_subtype : ⇑H.subtype = ((↑) : H → G) :=
rfl
@[deprecated (since := "2025-02-18")]
alias coeSubtype := coe_subtype
@[deprecated (since := "2025-02-18")]
alias _root_.AddSubgroup.coeSubtype := AddSubgroup.coe_subtype
/-- The inclusion homomorphism from a subgroup `H` contained in `K` to `K`. -/
@[to_additive
/-- The inclusion homomorphism from an additive subgroup `H` contained in `K` to `K`. -/]
def inclusion {H K : Subgroup G} (h : H ≤ K) : H →* K :=
MonoidHom.mk' (fun x => ⟨x, h x.2⟩) fun _ _ => rfl
@[to_additive (attr := simp)]
theorem coe_inclusion {H K : Subgroup G} {h : H ≤ K} (a : H) : (inclusion h a : G) = a := by
cases a
simp only [inclusion, coe_mk, MonoidHom.mk'_apply]
@[to_additive]
theorem inclusion_injective {H K : Subgroup G} (h : H ≤ K) : Function.Injective <| inclusion h :=
Set.inclusion_injective h
@[to_additive (attr := simp)]
lemma inclusion_inj {H K : Subgroup G} (h : H ≤ K) {x y : H} :
inclusion h x = inclusion h y ↔ x = y :=
(inclusion_injective h).eq_iff
@[to_additive (attr := simp)]
theorem subtype_comp_inclusion {H K : Subgroup G} (hH : H ≤ K) :
K.subtype.comp (inclusion hH) = H.subtype :=
rfl
open Set
/-- A subgroup `H` is normal if whenever `n ∈ H`, then `g * n * g⁻¹ ∈ H` for every `g : G` -/
structure Normal : Prop where
/-- `H` is closed under conjugation -/
conj_mem : ∀ n, n ∈ H → ∀ g : G, g * n * g⁻¹ ∈ H
attribute [class] Normal
end Subgroup
namespace AddSubgroup
/-- An AddSubgroup `H` is normal if whenever `n ∈ H`, then `g + n - g ∈ H` for every `g : A` -/
structure Normal (H : AddSubgroup A) : Prop where
/-- `H` is closed under additive conjugation -/
conj_mem : ∀ n, n ∈ H → ∀ g : A, g + n + -g ∈ H
attribute [to_additive] Subgroup.Normal
attribute [class] Normal
end AddSubgroup
namespace Subgroup
variable {H : Subgroup G}
@[to_additive]
instance (priority := 100) normal_of_comm {G : Type*} [CommGroup G] (H : Subgroup G) : H.Normal :=
⟨by simp [mul_comm]⟩
namespace Normal
@[to_additive]
theorem conj_mem' (nH : H.Normal) (n : G) (hn : n ∈ H) (g : G) :
g⁻¹ * n * g ∈ H := by
convert nH.conj_mem n hn g⁻¹
rw [inv_inv]
@[to_additive]
theorem mem_comm (nH : H.Normal) {a b : G} (h : a * b ∈ H) : b * a ∈ H := by
have : a⁻¹ * (a * b) * a⁻¹⁻¹ ∈ H := nH.conj_mem (a * b) h a⁻¹
simpa
@[to_additive]
theorem mem_comm_iff (nH : H.Normal) {a b : G} : a * b ∈ H ↔ b * a ∈ H :=
⟨nH.mem_comm, nH.mem_comm⟩
end Normal
end Subgroup
namespace Subgroup
variable (H : Subgroup G)
section Normalizer
/-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/
@[to_additive
/-- The `normalizer` of `H` is the largest subgroup of `G` inside which `H` is normal. -/]
def normalizer : Subgroup G where
carrier := { g : G | ∀ n, n ∈ H ↔ g * n * g⁻¹ ∈ H }
one_mem' := by simp
mul_mem' {a b} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) (hb : ∀ n, n ∈ H ↔ b * n * b⁻¹ ∈ H) n := by
rw [hb, ha]
simp only [mul_assoc, mul_inv_rev]
inv_mem' {a} (ha : ∀ n, n ∈ H ↔ a * n * a⁻¹ ∈ H) n := by
rw [ha (a⁻¹ * n * a⁻¹⁻¹)]
simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_inv_cancel, mul_one]
-- variant for sets.
-- TODO should this replace `normalizer`?
/-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy `g*S*g⁻¹=S` -/
@[to_additive
/-- The `setNormalizer` of `S` is the subgroup of `G` whose elements satisfy
`g+S-g=S`. -/]
def setNormalizer (S : Set G) : Subgroup G where
carrier := { g : G | ∀ n, n ∈ S ↔ g * n * g⁻¹ ∈ S }
one_mem' := by simp
mul_mem' {a b} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) (hb : ∀ n, n ∈ S ↔ b * n * b⁻¹ ∈ S) n := by
rw [hb, ha]
simp only [mul_assoc, mul_inv_rev]
inv_mem' {a} (ha : ∀ n, n ∈ S ↔ a * n * a⁻¹ ∈ S) n := by
rw [ha (a⁻¹ * n * a⁻¹⁻¹)]
simp only [inv_inv, mul_assoc, mul_inv_cancel_left, mul_inv_cancel, mul_one]
variable {H}
@[to_additive]
theorem mem_normalizer_iff {g : G} : g ∈ H.normalizer ↔ ∀ h, h ∈ H ↔ g * h * g⁻¹ ∈ H :=
Iff.rfl
@[to_additive]
theorem mem_normalizer_iff'' {g : G} : g ∈ H.normalizer ↔ ∀ h : G, h ∈ H ↔ g⁻¹ * h * g ∈ H := by
rw [← inv_mem_iff (x := g), mem_normalizer_iff, inv_inv]
@[to_additive]
theorem mem_normalizer_iff' {g : G} : g ∈ H.normalizer ↔ ∀ n, n * g ∈ H ↔ g * n ∈ H :=
⟨fun h n => by rw [h, mul_assoc, mul_inv_cancel_right], fun h n => by
rw [mul_assoc, ← h, inv_mul_cancel_right]⟩
@[to_additive]
theorem le_normalizer : H ≤ normalizer H := fun x xH n => by
rw [H.mul_mem_cancel_right (H.inv_mem xH), H.mul_mem_cancel_left xH]
end Normalizer
@[deprecated (since := "2025-04-09")] alias IsCommutative := IsMulCommutative
@[deprecated (since := "2025-04-09")] alias _root_.AddSubgroup.IsCommutative := IsAddCommutative
/-- A subgroup of a commutative group is commutative. -/
@[to_additive /-- A subgroup of a commutative group is commutative. -/]
instance commGroup_isMulCommutative {G : Type*} [CommGroup G] (H : Subgroup G) :
IsMulCommutative H :=
⟨CommMagma.to_isCommutative⟩
@[deprecated (since := "2025-04-09")] alias commGroup_isCommutative := commGroup_isMulCommutative
@[deprecated (since := "2025-04-09")] alias _root_.AddSubgroup.addCommGroup_isCommutative :=
commGroup_isMulCommutative
@[to_additive]
lemma mul_comm_of_mem_isMulCommutative [IsMulCommutative H] {a b : G} (ha : a ∈ H) (hb : b ∈ H) :
a * b = b * a := by
simpa only [MulMemClass.mk_mul_mk, Subtype.mk.injEq] using mul_comm (⟨a, ha⟩ : H) (⟨b, hb⟩ : H)
@[deprecated (since := "2025-04-09")] alias mul_comm_of_mem_isCommutative :=
mul_comm_of_mem_isMulCommutative
@[deprecated (since := "2025-04-09")] alias _root_.AddSubgroup.add_comm_of_mem_isCommutative :=
_root_.AddSubgroup.add_comm_of_mem_isAddCommutative
end Subgroup
|
List.lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Kyle Miller
-/
import Mathlib.Data.Set.Finite.Basic
import Mathlib.Data.Set.Finite.Lattice
import Mathlib.Data.Set.Finite.Range
import Mathlib.Data.Set.Lattice
import Mathlib.Data.Finite.Sigma
import Mathlib.Data.Finite.Vector
/-!
# Finiteness of sets of lists
## Tags
finite sets
-/
assert_not_exists OrderedRing MonoidWithZero
namespace List
variable (α : Type*) [Finite α] (n : ℕ)
lemma finite_length_eq : {l : List α | l.length = n}.Finite := List.Vector.finite
lemma finite_length_lt : {l : List α | l.length < n}.Finite := by
convert (Finset.range n).finite_toSet.biUnion fun i _ ↦ finite_length_eq α i; ext; simp
lemma finite_length_le : {l : List α | l.length ≤ n}.Finite := by
simpa [Nat.lt_succ_iff] using finite_length_lt α (n + 1)
end List
|
Quiv.lean
|
/-
Copyright (c) 2021 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Emily Riehl, Joël Riou
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.PathCategory.MorphismProperty
/-!
# The category of quivers
The category of (bundled) quivers, and the free/forgetful adjunction between `Cat` and `Quiv`.
-/
universe v u v₁ v₂ v₃ u₁ u₂ u₃ w
namespace CategoryTheory
-- intended to be used with explicit universe parameters
/-- Category of quivers. -/
@[nolint checkUnivs]
def Quiv :=
Bundled Quiver.{v + 1, u}
namespace Quiv
instance : CoeSort Quiv (Type u) where coe := Bundled.α
instance str' (C : Quiv.{v, u}) : Quiver.{v + 1, u} C :=
C.str
/-- Construct a bundled `Quiv` from the underlying type and the typeclass. -/
def of (C : Type u) [Quiver.{v + 1} C] : Quiv.{v, u} :=
Bundled.of C
instance : Inhabited Quiv :=
⟨Quiv.of (Quiver.Empty PEmpty)⟩
/-- Category structure on `Quiv` -/
instance category : LargeCategory.{max v u} Quiv.{v, u} where
Hom C D := Prefunctor C D
id C := Prefunctor.id C
comp F G := Prefunctor.comp F G
/-- The forgetful functor from categories to quivers. -/
@[simps]
def forget : Cat.{v, u} ⥤ Quiv.{v, u} where
obj C := Quiv.of C
map F := F.toPrefunctor
/-- The identity in the category of quivers equals the identity prefunctor. -/
theorem id_eq_id (X : Quiv) : 𝟙 X = 𝟭q X := rfl
/-- Composition in the category of quivers equals prefunctor composition. -/
theorem comp_eq_comp {X Y Z : Quiv} (F : X ⟶ Y) (G : Y ⟶ Z) : F ≫ G = F ⋙q G := rfl
end Quiv
namespace Prefunctor
/-- Prefunctors between quivers define arrows in `Quiv`. -/
def toQuivHom {C D : Type u} [Quiver.{v + 1} C] [Quiver.{v + 1} D] (F : C ⥤q D) :
Quiv.of C ⟶ Quiv.of D := F
/-- Arrows in `Quiv` define prefunctors. -/
def ofQuivHom {C D : Quiv} (F : C ⟶ D) : C ⥤q D := F
@[simp] theorem to_ofQuivHom {C D : Quiv} (F : C ⟶ D) : toQuivHom (ofQuivHom F) = F := rfl
@[simp] theorem of_toQuivHom {C D : Type} [Quiver C] [Quiver D] (F : C ⥤q D) :
ofQuivHom (toQuivHom F) = F := rfl
end Prefunctor
namespace Cat
/-- A prefunctor `V ⥤q W` induces a functor between the path categories defined by `F.mapPath`. -/
@[simps]
def freeMap {V W : Type*} [Quiver V] [Quiver W] (F : V ⥤q W) : Paths V ⥤ Paths W where
obj := F.obj
map := F.mapPath
map_comp f g := F.mapPath_comp f g
/-- The functor `free : Quiv ⥤ Cat` preserves identities up to natural isomorphism and in fact up
to equality. -/
@[simps!]
def freeMapIdIso (V : Type*) [Quiver V] : freeMap (𝟭q V) ≅ 𝟭 _ :=
NatIso.ofComponents (fun _ ↦ Iso.refl _)
theorem freeMap_id (V : Type*) [Quiver V] :
freeMap (𝟭q V) = 𝟭 _ :=
Functor.ext_of_iso (freeMapIdIso V) (fun _ ↦ rfl)
/-- The functor `free : Quiv ⥤ Cat` preserves composition up to natural isomorphism and in fact up
to equality. -/
@[simps!]
def freeMapCompIso {V₁ : Type u₁} {V₂ : Type u₂} {V₃ : Type u₃}
[Quiver.{v₁ + 1} V₁] [Quiver.{v₂ + 1} V₂] [Quiver.{v₃ + 1} V₃] (F : V₁ ⥤q V₂) (G : V₂ ⥤q V₃) :
freeMap (F ⋙q G) ≅ freeMap F ⋙ freeMap G :=
NatIso.ofComponents (fun _ ↦ Iso.refl _) (fun f ↦ by
dsimp
simp only [Category.comp_id, Category.id_comp, Prefunctor.mapPath_comp_apply])
theorem freeMap_comp {V₁ : Type u₁} {V₂ : Type u₂} {V₃ : Type u₃}
[Quiver.{v₁ + 1} V₁] [Quiver.{v₂ + 1} V₂] [Quiver.{v₃ + 1} V₃]
(F : V₁ ⥤q V₂) (G : V₂ ⥤q V₃) :
freeMap (F ⋙q G) = freeMap F ⋙ freeMap G :=
Functor.ext_of_iso (freeMapCompIso F G) (fun _ ↦ rfl)
/-- The functor sending each quiver to its path category. -/
@[simps]
def free : Quiv.{v, u} ⥤ Cat.{max u v, u} where
obj V := Cat.of (Paths V)
map F := Functor.toCatHom (freeMap (Prefunctor.ofQuivHom F))
map_id _ := freeMap_id _
map_comp _ _ := freeMap_comp _ _
end Cat
namespace Quiv
section
variable {V W : Quiv} (e : V ≅ W)
/-- An isomorphism of quivers defines an equivalence on carrier types. -/
@[simps]
def equivOfIso : V ≃ W where
toFun := e.hom.obj
invFun := e.inv.obj
left_inv := Prefunctor.congr_obj e.hom_inv_id
right_inv := Prefunctor.congr_obj e.inv_hom_id
@[simp]
lemma inv_obj_hom_obj_of_iso (X : V) : e.inv.obj (e.hom.obj X) = X := (equivOfIso e).left_inv X
@[simp]
lemma hom_obj_inv_obj_of_iso (Y : W) : e.hom.obj (e.inv.obj Y) = Y := (equivOfIso e).right_inv Y
lemma hom_map_inv_map_of_iso {V W : Quiv} (e : V ≅ W) {X Y : W} (f : X ⟶ Y) :
e.hom.map (e.inv.map f) = Quiver.homOfEq f (by simp) (by simp) := by
rw [← Prefunctor.comp_map]
exact (Prefunctor.congr_hom e.inv_hom_id.symm f).symm
lemma inv_map_hom_map_of_iso {V W : Quiv} (e : V ≅ W) {X Y : V} (f : X ⟶ Y) :
e.inv.map (e.hom.map f) = Quiver.homOfEq f (by simp) (by simp) :=
hom_map_inv_map_of_iso e.symm f
/-- An isomorphism of quivers defines an equivalence on hom types. -/
@[simps]
def homEquivOfIso {V W : Quiv} (e : V ≅ W) {X Y : V} :
(X ⟶ Y) ≃ (e.hom.obj X ⟶ e.hom.obj Y) where
toFun f := e.hom.map f
invFun g := Quiver.homOfEq (e.inv.map g) (by simp) (by simp)
left_inv f := by simp [inv_map_hom_map_of_iso]
right_inv g := by simp [hom_map_inv_map_of_iso]
end
section
variable {V W : Type u} [Quiver V] [Quiver W]
(e : V ≃ W) (he : ∀ X Y : V, (X ⟶ Y) ≃ (e X ⟶ e Y))
include he in
@[simp]
lemma homOfEq_map_homOfEq {X Y : V} (f : X ⟶ Y) {X' Y' : V} (hX : X = X') (hY : Y = Y')
{X'' Y'' : W} (hX' : e X' = X'') (hY' : e Y' = Y'') :
Quiver.homOfEq (he _ _ (Quiver.homOfEq f hX hY)) hX' hY' =
Quiver.homOfEq (he _ _ f) (by rw [hX, hX']) (by rw [hY, hY']) := by
subst hX hY hX' hY'
rfl
/-- Compatible equivalences of types and hom-types induce an isomorphism of quivers. -/
def isoOfEquiv : Quiv.of V ≅ Quiv.of W where
hom := Prefunctor.mk e (he _ _)
inv :=
{ obj := e.symm
map {X Y} f := (he _ _).symm (Quiver.homOfEq f (by simp) (by simp)) }
hom_inv_id := Prefunctor.ext' e.left_inv (fun X Y f ↦ by
dsimp [Quiv.id_eq_id, Quiv.comp_eq_comp]
apply (he _ _).injective
apply Quiver.homOfEq_injective (X' := e X) (Y' := e Y) (by simp) (by simp)
simp)
inv_hom_id := Prefunctor.ext' e.right_inv (by simp [Quiv.id_eq_id, Quiv.comp_eq_comp])
end
/-- Any prefunctor into a category lifts to a functor from the path category. -/
@[simps]
def lift {V : Type u} [Quiver.{v + 1} V] {C : Type u₁} [Category.{v₁} C]
(F : Prefunctor V C) : Paths V ⥤ C where
obj X := F.obj X
map f := composePath (F.mapPath f)
/-- Naturality of `pathComposition`. -/
def pathCompositionNaturality {C : Type u} {D : Type u₁}
[Category.{v} C] [Category.{v₁} D] (F : C ⥤ D) :
Cat.freeMap (F.toPrefunctor) ⋙ pathComposition D ≅ pathComposition C ⋙ F :=
Paths.liftNatIso (fun _ ↦ Iso.refl _) (by simp)
/-- Naturality of `pathComposition`, which defines a natural transformation
`Quiv.forget ⋙ Cat.free ⟶ 𝟭 _`. -/
theorem pathComposition_naturality {C : Type u} {D : Type u₁}
[Category.{v} C] [Category.{v₁} D]
(F : C ⥤ D) : Cat.freeMap (F.toPrefunctor) ⋙ pathComposition D = pathComposition C ⋙ F :=
Paths.ext_functor rfl (by simp)
/-- Naturality of `Paths.of`, which defines a natural transformation
` 𝟭 _⟶ Cat.free ⋙ Quiv.forget`. -/
lemma pathsOf_freeMap_toPrefunctor
{V : Type u} {W : Type u₁} [Quiver.{v + 1} V] [Quiver.{v₁ + 1} W] (F : V ⥤q W) :
Paths.of V ⋙q (Cat.freeMap F).toPrefunctor = F ⋙q Paths.of W := rfl
/-- The left triangle identity of `Cat.free ⊣ Quiv.forget` as a natural isomorphism -/
def freeMapPathsOfCompPathCompositionIso (V : Type u) [Quiver.{v + 1} V] :
Cat.freeMap (Paths.of V) ⋙ pathComposition (Paths V) ≅ 𝟭 (Paths V) :=
Paths.liftNatIso (fun v ↦ Iso.refl _) (by simp)
lemma freeMap_pathsOf_pathComposition (V : Type u) [Quiver.{v + 1} V] :
Cat.freeMap (Paths.of (V := V)) ⋙ pathComposition (Paths V) = 𝟭 (Paths V) :=
Paths.ext_functor rfl (by simp)
/-- An unbundled version of the right triangle equality. -/
lemma pathsOf_pathComposition_toPrefunctor (C : Type u) [Category.{v} C] :
Paths.of C ⋙q (pathComposition C).toPrefunctor = 𝟭q C := by
dsimp only [Prefunctor.comp]
congr
funext X Y f
exact Category.id_comp _
/--
The adjunction between forming the free category on a quiver, and forgetting a category to a quiver.
-/
def adj : Cat.free ⊣ Quiv.forget :=
Adjunction.mkOfUnitCounit {
unit := { app _ := Paths.of _}
counit := {
app C := pathComposition C
naturality _ _ F := pathComposition_naturality F
}
left_triangle := by
ext V
exact freeMap_pathsOf_pathComposition V
right_triangle := by
ext C
exact pathsOf_pathComposition_toPrefunctor C
}
/-- The universal property of the path category of a quiver. -/
def pathsEquiv {V : Type u} {C : Type u₁} [Quiver.{v + 1} V] [Category.{v₁} C] :
(Paths V ⥤ C) ≃ V ⥤q C where
toFun F := (Paths.of V).comp F.toPrefunctor
invFun G := Cat.freeMap G ⋙ pathComposition C
left_inv F := by
dsimp
rw [Cat.freeMap_comp, Functor.assoc, pathComposition_naturality, ← Functor.assoc,
freeMap_pathsOf_pathComposition, Functor.id_comp]
right_inv G := by
dsimp
rw [← Functor.toPrefunctor_comp, ← Prefunctor.comp_assoc,
pathsOf_freeMap_toPrefunctor, Prefunctor.comp_assoc,
pathsOf_pathComposition_toPrefunctor, Prefunctor.comp_id]
@[simp]
lemma adj_homEquiv {V C : Type u} [Quiver.{max u v + 1} V] [Category.{max u v} C] :
adj.homEquiv (Quiv.of V) (Cat.of C) = pathsEquiv (V := V) (C := C) := rfl
end Quiv
end CategoryTheory
|
Basic.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import Mathlib.Algebra.Algebra.Defs
import Mathlib.Algebra.Module.Equiv.Basic
import Mathlib.Algebra.Module.Submodule.Ker
import Mathlib.Algebra.Module.Submodule.RestrictScalars
import Mathlib.Algebra.Module.ULift
import Mathlib.Algebra.Ring.CharZero
import Mathlib.Algebra.Ring.Subring.Basic
import Mathlib.Data.Nat.Cast.Order.Basic
import Mathlib.Data.Int.CharZero
/-!
# Further basic results about `Algebra`.
This file could usefully be split further.
-/
universe u v w u₁ v₁
open Function
namespace Algebra
variable {R : Type u} {A : Type w}
section Semiring
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
section PUnit
instance _root_.PUnit.algebra : Algebra R PUnit.{v + 1} where
algebraMap :=
{ toFun _ := PUnit.unit
map_one' := rfl
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl }
commutes' _ _ := rfl
smul_def' _ _ := rfl
@[simp]
theorem algebraMap_pUnit (r : R) : algebraMap R PUnit r = PUnit.unit :=
rfl
end PUnit
section ULift
instance _root_.ULift.algebra : Algebra R (ULift A) :=
{ ULift.module' with
algebraMap :=
{ (ULift.ringEquiv : ULift A ≃+* A).symm.toRingHom.comp (algebraMap R A) with
toFun := fun r => ULift.up (algebraMap R A r) }
commutes' := fun r x => ULift.down_injective <| Algebra.commutes r x.down
smul_def' := fun r x => ULift.down_injective <| Algebra.smul_def' r x.down }
theorem _root_.ULift.algebraMap_eq (r : R) :
algebraMap R (ULift A) r = ULift.up (algebraMap R A r) :=
rfl
@[simp]
theorem _root_.ULift.down_algebraMap (r : R) : (algebraMap R (ULift A) r).down = algebraMap R A r :=
rfl
end ULift
/-- Algebra over a subsemiring. This builds upon `Subsemiring.module`. -/
instance ofSubsemiring (S : Subsemiring R) : Algebra S A where
algebraMap := (algebraMap R A).comp S.subtype
smul := (· • ·)
commutes' r x := Algebra.commutes (r : R) x
smul_def' r x := Algebra.smul_def (r : R) x
theorem algebraMap_ofSubsemiring (S : Subsemiring R) :
(algebraMap S R : S →+* R) = Subsemiring.subtype S :=
rfl
theorem coe_algebraMap_ofSubsemiring (S : Subsemiring R) : (algebraMap S R : S → R) = Subtype.val :=
rfl
theorem algebraMap_ofSubsemiring_apply (S : Subsemiring R) (x : S) : algebraMap S R x = x :=
rfl
/-- Algebra over a subring. This builds upon `Subring.module`. -/
instance ofSubring {R A : Type*} [CommRing R] [Ring A] [Algebra R A] (S : Subring R) :
Algebra S A where
algebraMap := (algebraMap R A).comp S.subtype
smul := (· • ·)
commutes' r x := Algebra.commutes (r : R) x
smul_def' r x := Algebra.smul_def (r : R) x
theorem algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
(algebraMap S R : S →+* R) = Subring.subtype S :=
rfl
theorem coe_algebraMap_ofSubring {R : Type*} [CommRing R] (S : Subring R) :
(algebraMap S R : S → R) = Subtype.val :=
rfl
theorem algebraMap_ofSubring_apply {R : Type*} [CommRing R] (S : Subring R) (x : S) :
algebraMap S R x = x :=
rfl
/-- Explicit characterization of the submonoid map in the case of an algebra.
`S` is made explicit to help with type inference -/
def algebraMapSubmonoid (S : Type*) [Semiring S] [Algebra R S] (M : Submonoid R) : Submonoid S :=
M.map (algebraMap R S)
theorem mem_algebraMapSubmonoid_of_mem {S : Type*} [Semiring S] [Algebra R S] {M : Submonoid R}
(x : M) : algebraMap R S x ∈ algebraMapSubmonoid S M :=
Set.mem_image_of_mem (algebraMap R S) x.2
@[simp]
lemma algebraMapSubmonoid_powers {S : Type*} [Semiring S] [Algebra R S] (r : R) :
Algebra.algebraMapSubmonoid S (.powers r) = Submonoid.powers (algebraMap R S r) := by
simp [Algebra.algebraMapSubmonoid]
end Semiring
section CommSemiring
variable [CommSemiring R]
theorem mul_sub_algebraMap_commutes [Ring A] [Algebra R A] (x : A) (r : R) :
x * (x - algebraMap R A r) = (x - algebraMap R A r) * x := by rw [mul_sub, ← commutes, sub_mul]
theorem mul_sub_algebraMap_pow_commutes [Ring A] [Algebra R A] (x : A) (r : R) (n : ℕ) :
x * (x - algebraMap R A r) ^ n = (x - algebraMap R A r) ^ n * x := by
induction n with
| zero => simp
| succ n ih =>
rw [pow_succ', ← mul_assoc, mul_sub_algebraMap_commutes, mul_assoc, ih, ← mul_assoc]
end CommSemiring
section Ring
/-- A `Semiring` that is an `Algebra` over a commutative ring carries a natural `Ring` structure.
See note [reducible non-instances]. -/
abbrev semiringToRing (R : Type*) [CommRing R] [Semiring A] [Algebra R A] : Ring A :=
{ __ := (inferInstance : Semiring A)
__ := Module.addCommMonoidToAddCommGroup R
intCast := fun z => algebraMap R A z
intCast_ofNat := fun z => by simp only [Int.cast_natCast, map_natCast]
intCast_negSucc := fun z => by simp }
instance {R : Type*} [Ring R] : Algebra (Subring.center R) R where
algebraMap :=
{ toFun := Subtype.val
map_one' := rfl
map_mul' _ _ := rfl
map_zero' := rfl
map_add' _ _ := rfl }
commutes' r x := (Subring.mem_center_iff.1 r.2 x).symm
smul_def' _ _ := rfl
end Ring
end Algebra
open scoped Algebra
namespace Module
variable (R : Type u) (S : Type v) (M : Type w)
variable [CommSemiring R] [Semiring S] [AddCommMonoid M] [Module R M] [Module S M]
variable [SMulCommClass S R M] [SMul R S] [IsScalarTower R S M]
instance End.instAlgebra : Algebra R (Module.End S M) :=
Algebra.ofModule smul_mul_assoc fun r f g => (smul_comm r f g).symm
-- to prove this is a special case of the above
example : Algebra R (Module.End R M) := End.instAlgebra _ _ _
theorem algebraMap_end_eq_smul_id (a : R) : algebraMap R (End S M) a = a • LinearMap.id :=
rfl
@[simp]
theorem algebraMap_end_apply (a : R) (m : M) : algebraMap R (End S M) a m = a • m :=
rfl
@[simp]
theorem ker_algebraMap_end (K : Type u) (V : Type v) [Semifield K] [AddCommMonoid V] [Module K V]
(a : K) (ha : a ≠ 0) : LinearMap.ker ((algebraMap K (End K V)) a) = ⊥ :=
LinearMap.ker_smul _ _ ha
section
variable {R M}
theorem End.algebraMap_isUnit_inv_apply_eq_iff {x : R}
(h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :
(↑(h.unit⁻¹) : Module.End S M) m = m' ↔ m = x • m' where
mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm
mpr H :=
H.symm ▸ by
apply_fun ⇑h.unit.val using ((isUnit_iff _).mp h).injective
simpa using Module.End.isUnit_apply_inv_apply_of_isUnit h (x • m')
@[deprecated (since := "2025-04-28")]
alias End_algebraMap_isUnit_inv_apply_eq_iff := End.algebraMap_isUnit_inv_apply_eq_iff
theorem End.algebraMap_isUnit_inv_apply_eq_iff' {x : R}
(h : IsUnit (algebraMap R (Module.End S M) x)) (m m' : M) :
m' = (↑h.unit⁻¹ : Module.End S M) m ↔ m = x • m' where
mp H := H ▸ (isUnit_apply_inv_apply_of_isUnit h m).symm
mpr H :=
H.symm ▸ by
apply_fun (↑h.unit : M → M) using ((isUnit_iff _).mp h).injective
simpa using isUnit_apply_inv_apply_of_isUnit h (x • m') |>.symm
@[deprecated (since := "2025-04-28")]
alias End_algebraMap_isUnit_inv_apply_eq_iff' := End.algebraMap_isUnit_inv_apply_eq_iff'
end
end Module
namespace LinearMap
variable {R : Type*} {A : Type*} {B : Type*} [CommSemiring R] [Semiring A] [Semiring B]
[Algebra R A] [Algebra R B]
/-- An alternate statement of `LinearMap.map_smul` for when `algebraMap` is more convenient to
work with than `•`. -/
theorem map_algebraMap_mul (f : A →ₗ[R] B) (a : A) (r : R) :
f (algebraMap R A r * a) = algebraMap R B r * f a := by
rw [← Algebra.smul_def, ← Algebra.smul_def, map_smul]
theorem map_mul_algebraMap (f : A →ₗ[R] B) (a : A) (r : R) :
f (a * algebraMap R A r) = f a * algebraMap R B r := by
rw [← Algebra.commutes, ← Algebra.commutes, map_algebraMap_mul]
end LinearMap
section Nat
variable {R : Type*} [Semiring R]
-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℕ`-algebras.
-- TODO: is this still needed?
/-- Semiring ⥤ ℕ-Alg -/
instance (priority := 99) Semiring.toNatAlgebra : Algebra ℕ R where
commutes' := Nat.cast_commute
smul_def' _ _ := nsmul_eq_mul _ _
algebraMap := Nat.castRingHom R
instance nat_algebra_subsingleton : Subsingleton (Algebra ℕ R) :=
⟨fun P Q => by ext; simp⟩
@[simp]
lemma algebraMap_comp_natCast (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] :
algebraMap R A ∘ Nat.cast = Nat.cast := by
ext; simp
end Nat
section Int
variable (R : Type*) [Ring R]
-- Lower the priority so that `Algebra.id` is picked most of the time when working with
-- `ℤ`-algebras.
-- TODO: is this still needed?
/-- Ring ⥤ ℤ-Alg -/
instance (priority := 99) Ring.toIntAlgebra : Algebra ℤ R where
commutes' := Int.cast_commute
smul_def' _ _ := zsmul_eq_mul _ _
algebraMap := Int.castRingHom R
/-- A special case of `eq_intCast'` that happens to be true definitionally -/
@[simp]
theorem algebraMap_int_eq : algebraMap ℤ R = Int.castRingHom R :=
rfl
variable {R}
instance int_algebra_subsingleton : Subsingleton (Algebra ℤ R) :=
⟨fun P Q => Algebra.algebra_ext P Q <| RingHom.congr_fun <| Subsingleton.elim _ _⟩
@[simp]
lemma algebraMap_comp_intCast (R A : Type*) [CommRing R] [Ring A] [Algebra R A] :
algebraMap R A ∘ Int.cast = Int.cast := by
ext; simp
end Int
section FaithfulSMul
theorem _root_.NeZero.of_faithfulSMul (R A : Type*) [Semiring R] [Semiring A] [Module R A]
[IsScalarTower R A A] [FaithfulSMul R A] (n : ℕ) [NeZero (n : R)] :
NeZero (n : A) :=
NeZero.nat_of_injective (f := ringHomEquivModuleIsScalarTower.symm ⟨_, ‹_›⟩) <|
(faithfulSMul_iff_injective_smul_one R A).mp ‹_›
variable (R A : Type*) [CommSemiring R] [Semiring A] [Algebra R A]
lemma faithfulSMul_iff_algebraMap_injective : FaithfulSMul R A ↔ Injective (algebraMap R A) := by
rw [faithfulSMul_iff_injective_smul_one, Algebra.algebraMap_eq_smul_one']
variable [FaithfulSMul R A]
namespace FaithfulSMul
lemma algebraMap_injective : Injective (algebraMap R A) :=
(faithfulSMul_iff_algebraMap_injective R A).mp inferInstance
@[simp]
lemma algebraMap_eq_zero_iff {r : R} : algebraMap R A r = 0 ↔ r = 0 :=
map_eq_zero_iff (algebraMap R A) <| algebraMap_injective R A
@[simp]
lemma algebraMap_eq_one_iff {r : R} : algebraMap R A r = 1 ↔ r = 1 :=
map_eq_one_iff _ <| FaithfulSMul.algebraMap_injective R A
end FaithfulSMul
lemma Algebra.charZero_of_charZero [CharZero R] : CharZero A :=
have := algebraMap_comp_natCast R A
⟨this ▸ (FaithfulSMul.algebraMap_injective R A).comp CharZero.cast_injective⟩
instance [CharZero R] : FaithfulSMul ℕ R := by
simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℕ R).injective_nat
instance (R : Type*) [Ring R] [CharZero R] : FaithfulSMul ℤ R := by
simpa only [faithfulSMul_iff_algebraMap_injective] using (algebraMap ℤ R).injective_int
end FaithfulSMul
namespace NoZeroSMulDivisors
-- see Note [lower instance priority]
instance (priority := 100) instOfFaithfulSMul {R A : Type*}
[CommSemiring R] [Semiring A] [Algebra R A] [NoZeroDivisors A] [FaithfulSMul R A] :
NoZeroSMulDivisors R A :=
⟨fun hcx => (mul_eq_zero.mp ((Algebra.smul_def _ _).symm.trans hcx)).imp_left
(map_eq_zero_iff (algebraMap R A) <| FaithfulSMul.algebraMap_injective R A).mp⟩
variable {R A : Type*} [CommRing R] [Ring A] [Algebra R A]
instance [Nontrivial A] [NoZeroSMulDivisors R A] : FaithfulSMul R A where
eq_of_smul_eq_smul {r₁ r₂} h := by
specialize h 1
rw [← sub_eq_zero, ← sub_smul, smul_eq_zero, sub_eq_zero] at h
exact h.resolve_right one_ne_zero
theorem iff_faithfulSMul [IsDomain A] : NoZeroSMulDivisors R A ↔ FaithfulSMul R A :=
⟨fun _ ↦ inferInstance, fun _ ↦ inferInstance⟩
theorem iff_algebraMap_injective [IsDomain A] :
NoZeroSMulDivisors R A ↔ Injective (algebraMap R A) := by
rw [iff_faithfulSMul]
exact faithfulSMul_iff_algebraMap_injective R A
end NoZeroSMulDivisors
section IsScalarTower
variable {R : Type*} [CommSemiring R]
variable (A : Type*) [Semiring A] [Algebra R A]
variable {M : Type*} [AddCommMonoid M] [Module A M] [Module R M] [IsScalarTower R A M]
theorem algebra_compatible_smul (r : R) (m : M) : r • m = (algebraMap R A) r • m := by
rw [← one_smul A m, ← smul_assoc, Algebra.smul_def, mul_one, one_smul]
@[simp]
theorem algebraMap_smul (r : R) (m : M) : (algebraMap R A) r • m = r • m :=
(algebra_compatible_smul A r m).symm
/-- If `M` is `A`-torsion free and `algebraMap R A` is injective, `M` is also `R`-torsion free. -/
theorem NoZeroSMulDivisors.trans_faithfulSMul (R A M : Type*) [CommSemiring R] [Semiring A]
[Algebra R A] [FaithfulSMul R A] [AddCommMonoid M] [Module R M] [Module A M]
[IsScalarTower R A M] [NoZeroSMulDivisors A M] : NoZeroSMulDivisors R M where
eq_zero_or_eq_zero_of_smul_eq_zero hx := by
rw [← algebraMap_smul (A := A)] at hx
simpa only [map_eq_zero_iff _ <| FaithfulSMul.algebraMap_injective R A] using
eq_zero_or_eq_zero_of_smul_eq_zero hx
variable {A}
-- see Note [lower instance priority]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path
instance (priority := 120) IsScalarTower.to_smulCommClass : SMulCommClass R A M :=
⟨fun r a m => by
rw [algebra_compatible_smul A r (a • m), smul_smul, Algebra.commutes, mul_smul, ←
algebra_compatible_smul]⟩
-- see Note [lower instance priority]
-- priority manually adjusted in https://github.com/leanprover-community/mathlib4/pull/11980, as it is a very common path
instance (priority := 110) IsScalarTower.to_smulCommClass' : SMulCommClass A R M :=
SMulCommClass.symm _ _ _
-- see Note [lower instance priority]
instance (priority := 200) Algebra.to_smulCommClass {R A} [CommSemiring R] [Semiring A]
[Algebra R A] : SMulCommClass R A A :=
IsScalarTower.to_smulCommClass
theorem smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m :=
smul_comm _ _ _
namespace LinearMap
variable (R)
-- TODO: generalize to `CompatibleSMul`
/-- `A`-linearly coerce an `R`-linear map from `M` to `A` to a function, given an algebra `A` over
a commutative semiring `R` and `M` a module over `R`. -/
def ltoFun (R : Type u) (M : Type v) (A : Type w) [CommSemiring R] [AddCommMonoid M] [Module R M]
[CommSemiring A] [Algebra R A] : (M →ₗ[R] A) →ₗ[A] M → A where
toFun f := f.toFun
map_add' _ _ := rfl
map_smul' _ _ := rfl
end LinearMap
end IsScalarTower
/-! TODO: The following lemmas no longer involve `Algebra` at all, and could be moved closer
to `Algebra/Module/Submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥`
are all defined in `LinearAlgebra/Basic.lean`. -/
section Module
variable (R : Type*) {S M N : Type*} [Semiring R] [Semiring S] [SMul R S]
variable [AddCommMonoid M] [Module R M] [Module S M] [IsScalarTower R S M]
variable [AddCommMonoid N] [Module R N] [Module S N] [IsScalarTower R S N]
@[simp]
theorem LinearMap.ker_restrictScalars (f : M →ₗ[S] N) :
LinearMap.ker (f.restrictScalars R) = (LinearMap.ker f).restrictScalars R :=
rfl
end Module
example {R A} [CommSemiring R] [Semiring A] [Module R A] [SMulCommClass R A A]
[IsScalarTower R A A] : Algebra R A :=
Algebra.ofModule smul_mul_assoc mul_smul_comm
section invertibility
variable {R A B : Type*}
variable [CommSemiring R] [Semiring A] [Semiring B] [Algebra R A] [Algebra R B]
/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is
invertible when `algebraMap R A r` is. -/
abbrev Invertible.algebraMapOfInvertibleAlgebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}
(h : Invertible (algebraMap R A r)) : Invertible (algebraMap R B r) where
invOf := f ⅟(algebraMap R A r)
invOf_mul_self := by rw [← Algebra.commutes, ← Algebra.smul_def, ← map_smul, Algebra.smul_def,
mul_invOf_self, hf]
mul_invOf_self := by rw [← Algebra.smul_def, ← map_smul, Algebra.smul_def, mul_invOf_self, hf]
/-- If there is a linear map `f : A →ₗ[R] B` that preserves `1`, then `algebraMap R B r` is
a unit when `algebraMap R A r` is. -/
lemma IsUnit.algebraMap_of_algebraMap (f : A →ₗ[R] B) (hf : f 1 = 1) {r : R}
(h : IsUnit (algebraMap R A r)) : IsUnit (algebraMap R B r) :=
let ⟨i⟩ := nonempty_invertible h
letI := Invertible.algebraMapOfInvertibleAlgebraMap f hf i
isUnit_of_invertible _
end invertibility
section algebraMap
variable {F E : Type*} [CommSemiring F] [Semiring E] [Algebra F E] (b : F →ₗ[F] E)
/-- If `E` is an `F`-algebra, and there exists an injective `F`-linear map from `F` to `E`,
then the algebra map from `F` to `E` is also injective. -/
theorem injective_algebraMap_of_linearMap (hb : Injective b) :
Injective (algebraMap F E) := fun x y e ↦ hb <| by
rw [← mul_one x, ← mul_one y, ← smul_eq_mul, ← smul_eq_mul,
map_smul, map_smul, Algebra.smul_def, Algebra.smul_def, e]
/-- If `E` is an `F`-algebra, and there exists a surjective `F`-linear map from `F` to `E`,
then the algebra map from `F` to `E` is also surjective. -/
theorem surjective_algebraMap_of_linearMap (hb : Surjective b) :
Surjective (algebraMap F E) := fun x ↦ by
obtain ⟨x, rfl⟩ := hb x
obtain ⟨y, hy⟩ := hb (b 1 * b 1)
refine ⟨x * y, ?_⟩
obtain ⟨z, hz⟩ := hb 1
apply_fun (x • z • ·) at hy
rwa [← map_smul, smul_eq_mul, mul_comm, ← smul_mul_assoc, ← map_smul _ z, smul_eq_mul, mul_one,
← smul_eq_mul, map_smul, hz, one_mul, ← map_smul, smul_eq_mul, mul_one, smul_smul,
← Algebra.algebraMap_eq_smul_one] at hy
/-- If `E` is an `F`-algebra, and there exists a bijective `F`-linear map from `F` to `E`,
then the algebra map from `F` to `E` is also bijective.
NOTE: The same result can also be obtained if there are two `F`-linear maps from `F` to `E`,
one is injective, the other one is surjective. In this case, use
`injective_algebraMap_of_linearMap` and `surjective_algebraMap_of_linearMap` separately. -/
theorem bijective_algebraMap_of_linearMap (hb : Bijective b) :
Bijective (algebraMap F E) :=
⟨injective_algebraMap_of_linearMap b hb.1, surjective_algebraMap_of_linearMap b hb.2⟩
/-- If `E` is an `F`-algebra, there exists an `F`-linear isomorphism from `F` to `E` (namely,
`E` is a free `F`-module of rank one), then the algebra map from `F` to `E` is bijective. -/
theorem bijective_algebraMap_of_linearEquiv (b : F ≃ₗ[F] E) :
Bijective (algebraMap F E) :=
bijective_algebraMap_of_linearMap _ b.bijective
end algebraMap
section surjective
variable {R S} [CommSemiring R] [Semiring S] [Algebra R S]
variable {M N} [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module S M] [IsScalarTower R S M]
variable [Module R N] [Module S N] [IsScalarTower R S N]
/-- If `R →+* S` is surjective, then `S`-linear maps between modules are exactly `R`-linear maps. -/
def LinearMap.extendScalarsOfSurjectiveEquiv (h : Surjective (algebraMap R S)) :
(M →ₗ[R] N) ≃ₗ[R] (M →ₗ[S] N) where
toFun f := { __ := f, map_smul' := fun r x ↦ by obtain ⟨r, rfl⟩ := h r; simp }
map_add' _ _ := rfl
map_smul' _ _ := rfl
invFun f := f.restrictScalars S
/-- If `R →+* S` is surjective, then `R`-linear maps are also `S`-linear. -/
abbrev LinearMap.extendScalarsOfSurjective (h : Surjective (algebraMap R S))
(l : M →ₗ[R] N) : M →ₗ[S] N :=
extendScalarsOfSurjectiveEquiv h l
/-- If `R →+* S` is surjective, then `R`-linear isomorphisms are also `S`-linear. -/
def LinearEquiv.extendScalarsOfSurjective (h : Surjective (algebraMap R S))
(f : M ≃ₗ[R] N) : M ≃ₗ[S] N where
__ := f
map_smul' r x := by obtain ⟨r, rfl⟩ := h r; simp
variable (h : Surjective (algebraMap R S))
@[simp]
lemma LinearMap.extendScalarsOfSurjective_apply (l : M →ₗ[R] N) (x) :
l.extendScalarsOfSurjective h x = l x := rfl
@[simp]
lemma LinearEquiv.extendScalarsOfSurjective_apply (f : M ≃ₗ[R] N) (x) :
f.extendScalarsOfSurjective h x = f x := rfl
@[simp]
lemma LinearEquiv.extendScalarsOfSurjective_symm (f : M ≃ₗ[R] N) :
(f.extendScalarsOfSurjective h).symm = f.symm.extendScalarsOfSurjective h := rfl
end surjective
namespace algebraMap
section CommSemiringCommSemiring
variable {R A : Type*} [CommSemiring R] [CommSemiring A] [Algebra R A] {ι : Type*} {s : Finset ι}
@[norm_cast]
theorem coe_prod (a : ι → R) : (↑(∏ i ∈ s, a i : R) : A) = ∏ i ∈ s, (↑(a i) : A) :=
map_prod (algebraMap R A) a s
@[norm_cast]
theorem coe_sum (a : ι → R) : ↑(∑ i ∈ s, a i) = ∑ i ∈ s, (↑(a i) : A) :=
map_sum (algebraMap R A) a s
end CommSemiringCommSemiring
end algebraMap
|
Cofinite.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, Jeremy Avigad, Yury Kudryashov
-/
import Mathlib.Data.Finite.Prod
import Mathlib.Data.Fintype.Pi
import Mathlib.Data.Set.Finite.Lemmas
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Filter.CountablyGenerated
import Mathlib.Order.Filter.Ker
import Mathlib.Order.Filter.Pi
import Mathlib.Order.Filter.Prod
import Mathlib.Order.Filter.AtTopBot.Basic
/-!
# The cofinite filter
In this file we define
`Filter.cofinite`: the filter of sets with finite complement
and prove its basic properties. In particular, we prove that for `ℕ` it is equal to `Filter.atTop`.
## TODO
Define filters for other cardinalities of the complement.
-/
open Set Function
variable {ι α β : Type*} {l : Filter α}
namespace Filter
/-- The cofinite filter is the filter of subsets whose complements are finite. -/
def cofinite : Filter α :=
comk Set.Finite finite_empty (fun _t ht _s hsub ↦ ht.subset hsub) fun _ h _ ↦ h.union
@[simp]
theorem mem_cofinite {s : Set α} : s ∈ @cofinite α ↔ sᶜ.Finite :=
Iff.rfl
@[simp]
theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in cofinite, p x) ↔ { x | ¬p x }.Finite :=
Iff.rfl
theorem hasBasis_cofinite : HasBasis cofinite (fun s : Set α => s.Finite) compl :=
⟨fun s =>
⟨fun h => ⟨sᶜ, h, (compl_compl s).subset⟩, fun ⟨_t, htf, hts⟩ =>
htf.subset <| compl_subset_comm.2 hts⟩⟩
instance cofinite_neBot [Infinite α] : NeBot (@cofinite α) :=
hasBasis_cofinite.neBot_iff.2 fun hs => hs.infinite_compl.nonempty
@[simp]
theorem cofinite_eq_bot_iff : @cofinite α = ⊥ ↔ Finite α := by
simp [← empty_mem_iff_bot, finite_univ_iff]
@[simp]
theorem cofinite_eq_bot [Finite α] : @cofinite α = ⊥ := cofinite_eq_bot_iff.2 ‹_›
theorem frequently_cofinite_iff_infinite {p : α → Prop} :
(∃ᶠ x in cofinite, p x) ↔ Set.Infinite { x | p x } := by
simp only [Filter.Frequently, eventually_cofinite, not_not, Set.Infinite]
lemma frequently_cofinite_mem_iff_infinite {s : Set α} : (∃ᶠ x in cofinite, x ∈ s) ↔ s.Infinite :=
frequently_cofinite_iff_infinite
alias ⟨_, _root_.Set.Infinite.frequently_cofinite⟩ := frequently_cofinite_mem_iff_infinite
@[simp]
lemma cofinite_inf_principal_neBot_iff {s : Set α} : (cofinite ⊓ 𝓟 s).NeBot ↔ s.Infinite :=
frequently_mem_iff_neBot.symm.trans frequently_cofinite_mem_iff_infinite
alias ⟨_, _root_.Set.Infinite.cofinite_inf_principal_neBot⟩ := cofinite_inf_principal_neBot_iff
theorem _root_.Set.Finite.compl_mem_cofinite {s : Set α} (hs : s.Finite) : sᶜ ∈ @cofinite α :=
mem_cofinite.2 <| (compl_compl s).symm ▸ hs
theorem _root_.Set.Finite.eventually_cofinite_notMem {s : Set α} (hs : s.Finite) :
∀ᶠ x in cofinite, x ∉ s :=
hs.compl_mem_cofinite
@[deprecated (since := "2025-05-24")]
alias _root_.Set.Finite.eventually_cofinite_nmem := _root_.Set.Finite.eventually_cofinite_notMem
theorem _root_.Finset.eventually_cofinite_notMem (s : Finset α) : ∀ᶠ x in cofinite, x ∉ s :=
s.finite_toSet.eventually_cofinite_notMem
@[deprecated (since := "2025-05-24")]
alias _root_.Finset.eventually_cofinite_nmem := _root_.Finset.eventually_cofinite_notMem
theorem _root_.Set.infinite_iff_frequently_cofinite {s : Set α} :
Set.Infinite s ↔ ∃ᶠ x in cofinite, x ∈ s :=
frequently_cofinite_iff_infinite.symm
theorem eventually_cofinite_ne (x : α) : ∀ᶠ a in cofinite, a ≠ x :=
(Set.finite_singleton x).eventually_cofinite_notMem
theorem le_cofinite_iff_compl_singleton_mem : l ≤ cofinite ↔ ∀ x, {x}ᶜ ∈ l := by
refine ⟨fun h x => h (finite_singleton x).compl_mem_cofinite, fun h s (hs : sᶜ.Finite) => ?_⟩
rw [← compl_compl s, ← biUnion_of_singleton sᶜ, compl_iUnion₂, Filter.biInter_mem hs]
exact fun x _ => h x
theorem le_cofinite_iff_eventually_ne : l ≤ cofinite ↔ ∀ x, ∀ᶠ y in l, y ≠ x :=
le_cofinite_iff_compl_singleton_mem
/-- If `α` is a preorder with no top element, then `atTop ≤ cofinite`. -/
theorem atTop_le_cofinite [Preorder α] [NoTopOrder α] : (atTop : Filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_atTop
/-- If `α` is a preorder with no bottom element, then `atBot ≤ cofinite`. -/
theorem atBot_le_cofinite [Preorder α] [NoBotOrder α] : (atBot : Filter α) ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr eventually_ne_atBot
theorem comap_cofinite_le (f : α → β) : comap f cofinite ≤ cofinite :=
le_cofinite_iff_eventually_ne.mpr fun x =>
mem_comap.2 ⟨{f x}ᶜ, (finite_singleton _).compl_mem_cofinite, fun _ => ne_of_apply_ne f⟩
/-- The coproduct of the cofinite filters on two types is the cofinite filter on their product. -/
theorem coprod_cofinite : (cofinite : Filter α).coprod (cofinite : Filter β) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprod, mem_cofinite, compl_compl, finite_image_fst_and_snd_iff]
theorem coprodᵢ_cofinite {α : ι → Type*} [Finite ι] :
(Filter.coprodᵢ fun i => (cofinite : Filter (α i))) = cofinite :=
Filter.coext fun s => by
simp only [compl_mem_coprodᵢ, mem_cofinite, compl_compl, forall_finite_image_eval_iff]
theorem disjoint_cofinite_left : Disjoint cofinite l ↔ ∃ s ∈ l, Set.Finite s := by
simp [l.basis_sets.disjoint_iff_right]
theorem disjoint_cofinite_right : Disjoint l cofinite ↔ ∃ s ∈ l, Set.Finite s :=
disjoint_comm.trans disjoint_cofinite_left
/-- If `l ≥ Filter.cofinite` is a countably generated filter, then `l.ker` is cocountable. -/
theorem countable_compl_ker [l.IsCountablyGenerated] (h : cofinite ≤ l) : Set.Countable l.kerᶜ := by
rcases exists_antitone_basis l with ⟨s, hs⟩
simp only [hs.ker, iInter_true, compl_iInter]
exact countable_iUnion fun n ↦ Set.Finite.countable <| h <| hs.mem _
/-- If `f` tends to a countably generated filter `l` along `Filter.cofinite`,
then for all but countably many elements, `f x ∈ l.ker`. -/
theorem Tendsto.countable_compl_preimage_ker {f : α → β}
{l : Filter β} [l.IsCountablyGenerated] (h : Tendsto f cofinite l) :
Set.Countable (f ⁻¹' l.ker)ᶜ := by rw [← ker_comap]; exact countable_compl_ker h.le_comap
/-- Given a collection of filters `l i : Filter (α i)` and sets `s i ∈ l i`,
if all but finitely many of `s i` are the whole space,
then their indexed product `Set.pi Set.univ s` belongs to the filter `Filter.pi l`. -/
theorem univ_pi_mem_pi {α : ι → Type*} {s : ∀ i, Set (α i)} {l : ∀ i, Filter (α i)}
(h : ∀ i, s i ∈ l i) (hfin : ∀ᶠ i in cofinite, s i = univ) : univ.pi s ∈ pi l := by
filter_upwards [pi_mem_pi hfin fun i _ ↦ h i] with a ha i _
if hi : s i = univ then
simp [hi]
else
exact ha i hi
/-- Given a family of maps `f i : α i → β i` and a family of filters `l i : Filter (α i)`,
if all but finitely many of `f i` are surjective,
then the indexed product of `f i`s maps the indexed product of the filters `l i`
to the indexed products of their pushforwards under individual `f i`s.
See also `map_piMap_pi_finite` for the case of a finite index type.
-/
theorem map_piMap_pi {α β : ι → Type*} {f : ∀ i, α i → β i}
(hf : ∀ᶠ i in cofinite, Surjective (f i)) (l : ∀ i, Filter (α i)) :
map (Pi.map f) (pi l) = pi fun i ↦ map (f i) (l i) := by
refine le_antisymm (tendsto_piMap_pi fun _ ↦ tendsto_map) ?_
refine ((hasBasis_pi fun i ↦ (l i).basis_sets).map _).ge_iff.2 ?_
rintro ⟨I, s⟩ ⟨hI : I.Finite, hs : ∀ i ∈ I, s i ∈ l i⟩
classical
rw [← univ_pi_piecewise_univ, piMap_image_univ_pi]
refine univ_pi_mem_pi (fun i ↦ ?_) ?_
· by_cases hi : i ∈ I
· simpa [hi] using image_mem_map (hs i hi)
· simp [hi]
· filter_upwards [hf, hI.compl_mem_cofinite] with i hsurj (hiI : i ∉ I)
simp [hiI, hsurj.range_eq]
/-- Given finite families of maps `f i : α i → β i` and of filters `l i : Filter (α i)`,
the indexed product of `f i`s maps the indexed product of the filters `l i`
to the indexed products of their pushforwards under individual `f i`s.
See also `map_piMap_pi` for a more general case.
-/
theorem map_piMap_pi_finite {α β : ι → Type*} [Finite ι]
(f : ∀ i, α i → β i) (l : ∀ i, Filter (α i)) :
map (Pi.map f) (pi l) = pi fun i ↦ map (f i) (l i) :=
map_piMap_pi (by simp) l
end Filter
open Filter
lemma Set.Finite.cofinite_inf_principal_compl {s : Set α} (hs : s.Finite) :
cofinite ⊓ 𝓟 sᶜ = cofinite := by
simpa using hs.compl_mem_cofinite
lemma Set.Finite.cofinite_inf_principal_diff {s t : Set α} (ht : t.Finite) :
cofinite ⊓ 𝓟 (s \ t) = cofinite ⊓ 𝓟 s := by
rw [diff_eq, ← inf_principal, ← inf_assoc, inf_right_comm, ht.cofinite_inf_principal_compl]
/-- For natural numbers the filters `Filter.cofinite` and `Filter.atTop` coincide. -/
theorem Nat.cofinite_eq_atTop : @cofinite ℕ = atTop := by
refine le_antisymm ?_ atTop_le_cofinite
refine atTop_basis.ge_iff.2 fun N _ => ?_
simpa only [mem_cofinite, compl_Ici] using finite_lt_nat N
theorem Nat.frequently_atTop_iff_infinite {p : ℕ → Prop} :
(∃ᶠ n in atTop, p n) ↔ Set.Infinite { n | p n } := by
rw [← Nat.cofinite_eq_atTop, frequently_cofinite_iff_infinite]
lemma Nat.eventually_pos : ∀ᶠ (k : ℕ) in Filter.atTop, 0 < k :=
Filter.eventually_of_mem (Filter.mem_atTop_sets.mpr ⟨1, fun _ hx ↦ hx⟩) (fun _ hx ↦ hx)
theorem Filter.Tendsto.exists_within_forall_le {α β : Type*} [LinearOrder β] {s : Set α}
(hs : s.Nonempty) {f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atTop) :
∃ a₀ ∈ s, ∀ a ∈ s, f a₀ ≤ f a := by
rcases em (∃ y ∈ s, ∃ x, f y < x) with (⟨y, hys, x, hx⟩ | not_all_top)
· -- the set of points `{y | f y < x}` is nonempty and finite, so we take `min` over this set
have : { y | ¬x ≤ f y }.Finite := Filter.eventually_cofinite.mp (tendsto_atTop.1 hf x)
simp only [not_le] at this
obtain ⟨a₀, ⟨ha₀ : f a₀ < x, ha₀s⟩, others_bigger⟩ :=
exists_min_image _ f (this.inter_of_left s) ⟨y, hx, hys⟩
refine ⟨a₀, ha₀s, fun a has => (lt_or_ge (f a) x).elim ?_ (le_trans ha₀.le)⟩
exact fun h => others_bigger a ⟨h, has⟩
· -- in this case, f is constant because all values are at top
push_neg at not_all_top
obtain ⟨a₀, ha₀s⟩ := hs
exact ⟨a₀, ha₀s, fun a ha => not_all_top a ha (f a₀)⟩
theorem Filter.Tendsto.exists_forall_le [Nonempty α] [LinearOrder β] {f : α → β}
(hf : Tendsto f cofinite atTop) : ∃ a₀, ∀ a, f a₀ ≤ f a :=
let ⟨a₀, _, ha₀⟩ := hf.exists_within_forall_le univ_nonempty
⟨a₀, fun a => ha₀ a (mem_univ _)⟩
theorem Filter.Tendsto.exists_within_forall_ge [LinearOrder β] {s : Set α} (hs : s.Nonempty)
{f : α → β} (hf : Filter.Tendsto f Filter.cofinite Filter.atBot) :
∃ a₀ ∈ s, ∀ a ∈ s, f a ≤ f a₀ :=
@Filter.Tendsto.exists_within_forall_le _ βᵒᵈ _ _ hs _ hf
theorem Filter.Tendsto.exists_forall_ge [Nonempty α] [LinearOrder β] {f : α → β}
(hf : Tendsto f cofinite atBot) : ∃ a₀, ∀ a, f a ≤ f a₀ :=
@Filter.Tendsto.exists_forall_le _ βᵒᵈ _ _ _ hf
theorem Function.Surjective.le_map_cofinite {f : α → β} (hf : Surjective f) :
cofinite ≤ map f cofinite := fun _ h => .of_preimage h hf
/-- For an injective function `f`, inverse images of finite sets are finite. See also
`Filter.comap_cofinite_le` and `Function.Injective.comap_cofinite_eq`. -/
theorem Function.Injective.tendsto_cofinite {f : α → β} (hf : Injective f) :
Tendsto f cofinite cofinite := fun _ h => h.preimage hf.injOn
/-- For a function with finite fibres, inverse images of finite sets are finite. -/
theorem Filter.Tendsto.cofinite_of_finite_preimage_singleton {f : α → β}
(hf : ∀ b, Finite (f ⁻¹' {b})) : Tendsto f cofinite cofinite :=
fun _ h => h.preimage' fun b _ ↦ hf b
/-- The pullback of the `Filter.cofinite` under an injective function is equal to `Filter.cofinite`.
See also `Filter.comap_cofinite_le` and `Function.Injective.tendsto_cofinite`. -/
theorem Function.Injective.comap_cofinite_eq {f : α → β} (hf : Injective f) :
comap f cofinite = cofinite :=
(comap_cofinite_le f).antisymm hf.tendsto_cofinite.le_comap
/-- An injective sequence `f : ℕ → ℕ` tends to infinity at infinity. -/
theorem Function.Injective.nat_tendsto_atTop {f : ℕ → ℕ} (hf : Injective f) :
Tendsto f atTop atTop :=
Nat.cofinite_eq_atTop ▸ hf.tendsto_cofinite
|
ULift.lean
|
/-
Copyright (c) 2021 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Control.ULift
import Mathlib.Logic.Equiv.Basic
/-!
# Extra lemmas about `ULift` and `PLift`
In this file we provide `Subsingleton`, `Unique`, `DecidableEq`, and `isEmpty` instances for
`ULift α` and `PLift α`. We also prove `ULift.forall`, `ULift.exists`, `PLift.forall`, and
`PLift.exists`.
-/
universe u v u' v'
open Function
namespace PLift
variable {α : Sort u} {β : Sort v} {f : α → β}
instance [Subsingleton α] : Subsingleton (PLift α) :=
Equiv.plift.subsingleton
instance [Nonempty α] : Nonempty (PLift α) :=
Equiv.plift.nonempty
instance [Unique α] : Unique (PLift α) :=
Equiv.plift.unique
instance [DecidableEq α] : DecidableEq (PLift α) :=
Equiv.plift.decidableEq
instance [IsEmpty α] : IsEmpty (PLift α) :=
Equiv.plift.isEmpty
theorem up_injective : Injective (@up α) :=
Equiv.plift.symm.injective
theorem up_surjective : Surjective (@up α) :=
Equiv.plift.symm.surjective
theorem up_bijective : Bijective (@up α) :=
Equiv.plift.symm.bijective
theorem up_inj {x y : α} : up x = up y ↔ x = y := by simp
theorem down_surjective : Surjective (@down α) :=
Equiv.plift.surjective
theorem down_bijective : Bijective (@down α) :=
Equiv.plift.bijective
-- This is not a good simp lemma, as its discrimination tree key is just an arrow.
theorem «forall» {p : PLift α → Prop} : (∀ x, p x) ↔ ∀ x : α, p (PLift.up x) :=
up_surjective.forall
@[simp]
theorem «exists» {p : PLift α → Prop} : (∃ x, p x) ↔ ∃ x : α, p (PLift.up x) :=
up_surjective.exists
@[simp] lemma map_injective : Injective (PLift.map f) ↔ Injective f :=
(Injective.of_comp_iff' _ down_bijective).trans <| up_injective.of_comp_iff _
@[simp] lemma map_surjective : Surjective (PLift.map f) ↔ Surjective f :=
(down_surjective.of_comp_iff _).trans <| Surjective.of_comp_iff' up_bijective _
@[simp] lemma map_bijective : Bijective (PLift.map f) ↔ Bijective f :=
(down_bijective.of_comp_iff _).trans <| Bijective.of_comp_iff' up_bijective _
end PLift
namespace ULift
variable {α : Type u} {β : Type v} {f : α → β}
instance [Subsingleton α] : Subsingleton (ULift α) :=
Equiv.ulift.subsingleton
instance [Nonempty α] : Nonempty (ULift α) :=
Equiv.ulift.nonempty
instance [Unique α] : Unique (ULift α) :=
Equiv.ulift.unique
instance [DecidableEq α] : DecidableEq (ULift α) :=
Equiv.ulift.decidableEq
instance [IsEmpty α] : IsEmpty (ULift α) :=
Equiv.ulift.isEmpty
theorem up_injective : Injective (@up α) :=
Equiv.ulift.symm.injective
theorem up_surjective : Surjective (@up α) :=
Equiv.ulift.symm.surjective
theorem up_bijective : Bijective (@up α) :=
Equiv.ulift.symm.bijective
theorem up_inj {x y : α} : up x = up y ↔ x = y := by simp
theorem down_surjective : Surjective (@down α) :=
Equiv.ulift.surjective
theorem down_bijective : Bijective (@down α) :=
Equiv.ulift.bijective
@[simp]
theorem «forall» {p : ULift α → Prop} : (∀ x, p x) ↔ ∀ x : α, p (ULift.up x) :=
up_surjective.forall
@[simp]
theorem «exists» {p : ULift α → Prop} : (∃ x, p x) ↔ ∃ x : α, p (ULift.up x) :=
up_surjective.exists
@[simp] lemma map_injective : Injective (ULift.map f : ULift.{u'} α → ULift.{v'} β) ↔ Injective f :=
(Injective.of_comp_iff' _ down_bijective).trans <| up_injective.of_comp_iff _
@[simp] lemma map_surjective :
Surjective (ULift.map f : ULift.{u'} α → ULift.{v'} β) ↔ Surjective f :=
(down_surjective.of_comp_iff _).trans <| Surjective.of_comp_iff' up_bijective _
@[simp] lemma map_bijective : Bijective (ULift.map f : ULift.{u'} α → ULift.{v'} β) ↔ Bijective f :=
(down_bijective.of_comp_iff _).trans <| Bijective.of_comp_iff' up_bijective _
@[ext]
theorem ext (x y : ULift α) (h : x.down = y.down) : x = y :=
congrArg up h
@[simp]
lemma rec_update {β : ULift α → Type*} [DecidableEq α]
(f : ∀ a, β (.up a)) (a : α) (x : β (.up a)) :
ULift.rec (update f a x) = update (ULift.rec f) (.up a) x :=
Function.rec_update up_injective (ULift.rec ·) (fun _ _ => rfl) (fun
| _, _, .up _, h => (h _ rfl).elim) _ _ _
end ULift
|
FiniteField.lean
|
/-
Copyright (c) 2020 Aaron Anderson, Jalex Stark. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark
-/
import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff
import Mathlib.FieldTheory.Finite.Basic
import Mathlib.Data.Matrix.CharP
/-!
# Results on characteristic polynomials and traces over finite fields.
-/
noncomputable section
open Polynomial Matrix
open scoped Polynomial
variable {n : Type*} [DecidableEq n] [Fintype n]
@[simp]
theorem FiniteField.Matrix.charpoly_pow_card {K : Type*} [Field K] [Fintype K] (M : Matrix n n K) :
(M ^ Fintype.card K).charpoly = M.charpoly := by
cases (isEmpty_or_nonempty n).symm
· obtain ⟨p, hp⟩ := CharP.exists K; letI := hp
rcases FiniteField.card K p with ⟨⟨k, kpos⟩, ⟨hp, hk⟩⟩
haveI : Fact p.Prime := ⟨hp⟩
dsimp at hk; rw [hk]
apply (frobenius_inj K[X] p).iterate k
repeat' rw [iterate_frobenius (R := K[X])]; rw [← hk]
rw [← FiniteField.expand_card]
unfold charpoly
rw [AlgHom.map_det, ← coe_detMonoidHom, ← (detMonoidHom : Matrix n n K[X] →* K[X]).map_pow]
apply congr_arg det
refine matPolyEquiv.injective ?_
rw [map_pow, matPolyEquiv_charmatrix, hk, sub_pow_char_pow_of_commute, ← C_pow]
· exact (id (matPolyEquiv_eq_X_pow_sub_C (p ^ k) M) :)
· exact (C M).commute_X
· exact congr_arg _ (Subsingleton.elim _ _)
@[simp]
theorem ZMod.charpoly_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) :
(M ^ p).charpoly = M.charpoly := by
have h := FiniteField.Matrix.charpoly_pow_card M
rwa [ZMod.card] at h
theorem FiniteField.trace_pow_card {K : Type*} [Field K] [Fintype K] (M : Matrix n n K) :
trace (M ^ Fintype.card K) = trace M ^ Fintype.card K := by
cases isEmpty_or_nonempty n
· simp [Matrix.trace]
rw [Matrix.trace_eq_neg_charpoly_coeff, Matrix.trace_eq_neg_charpoly_coeff,
FiniteField.Matrix.charpoly_pow_card, FiniteField.pow_card]
theorem ZMod.trace_pow_card {p : ℕ} [Fact p.Prime] (M : Matrix n n (ZMod p)) :
trace (M ^ p) = trace M ^ p := by have h := FiniteField.trace_pow_card M; rwa [ZMod.card] at h
|
pgroup.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 bigop finset prime fingroup morphism.
From mathcomp Require Import gfunctor automorphism quotient action gproduct.
From mathcomp Require Import cyclic.
(******************************************************************************)
(* Standard group notions and constructions based on the prime decomposition *)
(* of the order of the group or its elements: *)
(* pi.-group G <=> G is a pi-group, i.e., pi.-nat #|G|. *)
(* -> Recall that here and in the sequel pi can be a single prime p. *)
(* pi.-subgroup(H) G <=> H is a pi-subgroup of G. *)
(* := (H \subset G) && pi.-group H. *)
(* -> This is provided mostly as a shorhand, with few associated lemmas. *)
(* However, we do establish some results on maximal pi-subgroups. *)
(* pi.-elt x <=> x is a pi-element. *)
(* := pi.-nat #[x] or pi.-group <[x]>. *)
(* x.`_pi == the pi-constituent of x: the (unique) pi-element *)
(* y \in <[x]> such that x * y^-1 is a pi'-element. *)
(* pi.-Hall(G) H <=> H is a Hall pi-subgroup of G. *)
(* := [&& H \subset G, pi.-group H & pi^'.-nat #|G : H|]. *)
(* -> This is also equivalent to H \subset G /\ #|H| = #|G|`_pi. *)
(* p.-Sylow(G) P <=> P is a Sylow p-subgroup of G. *)
(* -> This is the display and preferred input notation for p.-Hall(G) P. *)
(* 'Syl_p(G) == the set of the p-Sylow subgroups of G. *)
(* := [set P : {group _} | p.-Sylow(G) P]. *)
(* p_group P <=> P is a p-group for some prime p. *)
(* Hall G H <=> H is a Hall pi-subgroup of G for some pi. *)
(* := coprime #|H| #|G : H| && (H \subset G). *)
(* Sylow G P <=> P is a Sylow p-subgroup of G for some p. *)
(* := p_group P && Hall G P. *)
(* 'O_pi(G) == the pi-core (largest normal pi-subgroup) of G. *)
(* pcore_mod pi G H == the pi-core of G mod H. *)
(* := G :&: (coset H @*^-1 'O_pi(G / H)). *)
(* 'O_{pi2, pi1}(G) == the pi1,pi2-core of G. *)
(* := the pi1-core of G mod 'O_pi2(G). *)
(* -> We have 'O_{pi2, pi1}(G) / 'O_pi2(G) = 'O_pi1(G / 'O_pi2(G)) *)
(* with 'O_pi2(G) <| 'O_{pi2, pi1}(G) <| G. *)
(* 'O_{pn, ..., p1}(G) == the p1, ..., pn-core of G. *)
(* := the p1-core of G mod 'O_{pn, ..., p2}(G). *)
(* Note that notions are always defined on sets even though their name *)
(* indicates "group" properties; the actual definition of the notion never *)
(* tests for the group property, since this property will always be provided *)
(* by a (canonical) group structure. Similarly, p-group properties assume *)
(* without test that p is a prime. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section PgroupDefs.
(* We defer the definition of the functors ('0_p(G), etc) because they need *)
(* to quantify over the finGroupType explicitly. *)
Variable gT : finGroupType.
Implicit Type (x : gT) (A B : {set gT}) (pi : nat_pred) (p n : nat).
Definition pgroup pi A := pi.-nat #|A|.
Definition psubgroup pi A B := (B \subset A) && pgroup pi B.
Definition p_group A := pgroup (pdiv #|A|) A.
Definition p_elt pi x := pi.-nat #[x].
Definition constt x pi := x ^+ (chinese #[x]`_pi #[x]`_pi^' 1 0).
Definition Hall A B := (B \subset A) && coprime #|B| #|A : B|.
Definition pHall pi A B := [&& B \subset A, pgroup pi B & pi^'.-nat #|A : B|].
Definition Syl p A := [set P : {group gT} | pHall p A P].
Definition Sylow A B := p_group B && Hall A B.
End PgroupDefs.
Arguments pgroup {gT} pi%_N A%_g.
Arguments psubgroup {gT} pi%_N A%_g B%_g.
Arguments p_group {gT} A%_g.
Arguments p_elt {gT} pi%_N x.
Arguments constt {gT} x%_g pi%_N.
Arguments Hall {gT} A%_g B%_g.
Arguments pHall {gT} pi%_N A%_g B%_g.
Arguments Syl {gT} p%_N A%_g.
Arguments Sylow {gT} A%_g B%_g.
Notation "pi .-group" := (pgroup pi) (format "pi .-group") : group_scope.
Notation "pi .-subgroup ( A )" := (psubgroup pi A)
(format "pi .-subgroup ( A )") : group_scope.
Notation "pi .-elt" := (p_elt pi) (format "pi .-elt") : group_scope.
Notation "x .`_ pi" := (constt x pi)
(at level 3, left associativity, format "x .`_ pi") : group_scope.
Notation "pi .-Hall ( G )" := (pHall pi G)
(format "pi .-Hall ( G )") : group_scope.
Notation "p .-Sylow ( G )" := (nat_pred_of_nat p).-Hall(G)
(format "p .-Sylow ( G )") : group_scope.
Notation "''Syl_' p ( G )" := (Syl p G)
(p at level 2, format "''Syl_' p ( G )") : group_scope.
Section PgroupProps.
Variable gT : finGroupType.
Implicit Types (pi rho : nat_pred) (p : nat).
Implicit Types (x y z : gT) (A B C D : {set gT}) (G H K P Q R : {group gT}).
Lemma trivgVpdiv G : G :=: 1 \/ (exists2 p, prime p & p %| #|G|).
Proof.
have [leG1|lt1G] := leqP #|G| 1; first by left; apply: card_le1_trivg.
by right; exists (pdiv #|G|); rewrite ?pdiv_dvd ?pdiv_prime.
Qed.
Lemma prime_subgroupVti G H : prime #|G| -> G \subset H \/ H :&: G = 1.
Proof.
move=> prG; have [|[p p_pr pG]] := trivgVpdiv (H :&: G); first by right.
left; rewrite (sameP setIidPr eqP) eqEcard subsetIr.
suffices <-: p = #|G| by rewrite dvdn_leq ?cardG_gt0.
by apply/eqP; rewrite -dvdn_prime2 // -(LagrangeI G H) setIC dvdn_mulr.
Qed.
Lemma pgroupE pi A : pi.-group A = pi.-nat #|A|. Proof. by []. Qed.
Lemma sub_pgroup pi rho A : {subset pi <= rho} -> pi.-group A -> rho.-group A.
Proof. by move=> pi_sub_rho; apply: sub_in_pnat (in1W pi_sub_rho). Qed.
Lemma eq_pgroup pi rho A : pi =i rho -> pi.-group A = rho.-group A.
Proof. exact: eq_pnat. Qed.
Lemma eq_p'group pi rho A : pi =i rho -> pi^'.-group A = rho^'.-group A.
Proof. by move/eq_negn; apply: eq_pnat. Qed.
Lemma pgroupNK pi A : pi^'^'.-group A = pi.-group A.
Proof. exact: pnatNK. Qed.
Lemma pi_pgroup p pi A : p.-group A -> p \in pi -> pi.-group A.
Proof. exact: pi_pnat. Qed.
Lemma pi_p'group p pi A : pi.-group A -> p \in pi^' -> p^'.-group A.
Proof. exact: pi_p'nat. Qed.
Lemma pi'_p'group p pi A : pi^'.-group A -> p \in pi -> p^'.-group A.
Proof. exact: pi'_p'nat. Qed.
Lemma p'groupEpi p G : p^'.-group G = (p \notin \pi(G)).
Proof. exact: p'natEpi (cardG_gt0 G). Qed.
Lemma pgroup_pi G : \pi(G).-group G.
Proof. by rewrite /=; apply: pnat_pi. Qed.
Lemma partG_eq1 pi G : (#|G|`_pi == 1%N) = pi^'.-group G.
Proof. exact: partn_eq1 (cardG_gt0 G). Qed.
Lemma pgroupP pi G :
reflect (forall p, prime p -> p %| #|G| -> p \in pi) (pi.-group G).
Proof. exact: pnatP. Qed.
Arguments pgroupP {pi G}.
Lemma pgroup1 pi : pi.-group [1 gT].
Proof. by rewrite /pgroup cards1. Qed.
Lemma pgroupS pi G H : H \subset G -> pi.-group G -> pi.-group H.
Proof. by move=> sHG; apply: pnat_dvd (cardSg sHG). Qed.
Lemma oddSg G H : H \subset G -> odd #|G| -> odd #|H|.
Proof. by rewrite !odd_2'nat; apply: pgroupS. Qed.
Lemma odd_pgroup_odd p G : odd p -> p.-group G -> odd #|G|.
Proof.
move=> p_odd pG; rewrite odd_2'nat (pi_pnat pG) // !inE.
by case: eqP p_odd => // ->.
Qed.
Lemma card_pgroup p G : p.-group G -> #|G| = (p ^ logn p #|G|)%N.
Proof. by move=> pG; rewrite -p_part part_pnat_id. Qed.
Lemma properG_ltn_log p G H :
p.-group G -> H \proper G -> logn p #|H| < logn p #|G|.
Proof.
move=> pG; rewrite properEneq eqEcard andbC ltnNge => /andP[sHG].
rewrite sHG /= {1}(card_pgroup pG) {1}(card_pgroup (pgroupS sHG pG)).
by apply: contra; case: p {pG} => [|p] leHG; rewrite ?logn0 // leq_pexp2l.
Qed.
Lemma pgroupM pi G H : pi.-group (G * H) = pi.-group G && pi.-group H.
Proof.
have GH_gt0: 0 < #|G :&: H| := cardG_gt0 _.
rewrite /pgroup -(mulnK #|_| GH_gt0) -mul_cardG -(LagrangeI G H) -mulnA.
by rewrite mulKn // -(LagrangeI H G) setIC !pnatM andbCA; case: (pnat _).
Qed.
Lemma pgroupJ pi G x : pi.-group (G :^ x) = pi.-group G.
Proof. by rewrite /pgroup cardJg. Qed.
Lemma pgroup_p p P : p.-group P -> p_group P.
Proof.
case: (leqP #|P| 1); first by move=> /card_le1_trivg-> _; apply: pgroup1.
move/pdiv_prime=> pr_q pgP; have:= pgroupP pgP _ pr_q (pdiv_dvd _).
by rewrite /p_group => /eqnP->.
Qed.
Lemma p_groupP P : p_group P -> exists2 p, prime p & p.-group P.
Proof.
case: (ltnP 1 #|P|); first by move/pdiv_prime; exists (pdiv #|P|).
by move/card_le1_trivg=> -> _; exists 2 => //; apply: pgroup1.
Qed.
Lemma pgroup_pdiv p G :
p.-group G -> G :!=: 1 ->
[/\ prime p, p %| #|G| & exists m, #|G| = p ^ m.+1]%N.
Proof.
move=> pG; rewrite trivg_card1; case/p_groupP: (pgroup_p pG) => q q_pr qG.
move/implyP: (pgroupP pG q q_pr); case/p_natP: qG => // [[|m] ->] //.
by rewrite dvdn_exp // => /eqnP <- _; split; rewrite ?dvdn_exp //; exists m.
Qed.
Lemma coprime_p'group p K R :
coprime #|K| #|R| -> p.-group R -> R :!=: 1 -> p^'.-group K.
Proof.
move=> coKR pR ntR; have [p_pr _ [e oK]] := pgroup_pdiv pR ntR.
by rewrite oK coprime_sym coprime_pexpl // prime_coprime // -p'natE in coKR.
Qed.
Lemma card_Hall pi G H : pi.-Hall(G) H -> #|H| = #|G|`_pi.
Proof.
case/and3P=> sHG piH pi'H; rewrite -(Lagrange sHG).
by rewrite partnM ?Lagrange // part_pnat_id ?part_p'nat ?muln1.
Qed.
Lemma pHall_sub pi A B : pi.-Hall(A) B -> B \subset A.
Proof. by case/andP. Qed.
Lemma pHall_pgroup pi A B : pi.-Hall(A) B -> pi.-group B.
Proof. by case/and3P. Qed.
Lemma pHallP pi G H : reflect (H \subset G /\ #|H| = #|G|`_pi) (pi.-Hall(G) H).
Proof.
apply: (iffP idP) => [piH | [sHG oH]].
by split; [apply: pHall_sub piH | apply: card_Hall].
rewrite /pHall sHG -divgS // /pgroup oH.
by rewrite -{2}(@partnC pi #|G|) ?mulKn ?part_pnat.
Qed.
Lemma pHallE pi G H : pi.-Hall(G) H = (H \subset G) && (#|H| == #|G|`_pi).
Proof. by apply/pHallP/andP=> [] [->] /eqP. Qed.
Lemma coprime_mulpG_Hall pi G K R :
K * R = G -> pi.-group K -> pi^'.-group R ->
pi.-Hall(G) K /\ pi^'.-Hall(G) R.
Proof.
move=> defG piK pi'R; apply/andP.
rewrite /pHall piK -!divgS /= -defG ?mulG_subl ?mulg_subr //= pnatNK.
by rewrite coprime_cardMg ?(pnat_coprime piK) // mulKn ?mulnK //; apply/and3P.
Qed.
Lemma coprime_mulGp_Hall pi G K R :
K * R = G -> pi^'.-group K -> pi.-group R ->
pi^'.-Hall(G) K /\ pi.-Hall(G) R.
Proof.
move=> defG pi'K piR; apply/andP; rewrite andbC; apply/andP.
by apply: coprime_mulpG_Hall => //; rewrite -(comm_group_setP _) defG ?groupP.
Qed.
Lemma eq_in_pHall pi rho G H :
{in \pi(G), pi =i rho} -> pi.-Hall(G) H = rho.-Hall(G) H.
Proof.
move=> eq_pi_rho; apply: andb_id2l => sHG.
congr (_ && _); apply: eq_in_pnat => p piHp.
by apply: eq_pi_rho; apply: (piSg sHG).
by congr (~~ _); apply: eq_pi_rho; apply: (pi_of_dvd (dvdn_indexg G H)).
Qed.
Lemma eq_pHall pi rho G H : pi =i rho -> pi.-Hall(G) H = rho.-Hall(G) H.
Proof. by move=> eq_pi_rho; apply: eq_in_pHall (in1W eq_pi_rho). Qed.
Lemma eq_p'Hall pi rho G H : pi =i rho -> pi^'.-Hall(G) H = rho^'.-Hall(G) H.
Proof. by move=> eq_pi_rho; apply: eq_pHall (eq_negn _). Qed.
Lemma pHallNK pi G H : pi^'^'.-Hall(G) H = pi.-Hall(G) H.
Proof. exact: eq_pHall (negnK _). Qed.
Lemma subHall_Hall pi rho G H K :
rho.-Hall(G) H -> {subset pi <= rho} -> pi.-Hall(H) K -> pi.-Hall(G) K.
Proof.
move=> hallH pi_sub_rho hallK.
rewrite pHallE (subset_trans (pHall_sub hallK) (pHall_sub hallH)) /=.
by rewrite (card_Hall hallK) (card_Hall hallH) partn_part.
Qed.
Lemma subHall_Sylow pi p G H P :
pi.-Hall(G) H -> p \in pi -> p.-Sylow(H) P -> p.-Sylow(G) P.
Proof.
move=> hallH pi_p sylP; have [sHG piH _] := and3P hallH.
rewrite pHallE (subset_trans (pHall_sub sylP) sHG) /=.
by rewrite (card_Hall sylP) (card_Hall hallH) partn_part // => q; move/eqnP->.
Qed.
Lemma pHall_Hall pi A B : pi.-Hall(A) B -> Hall A B.
Proof. by case/and3P=> sBA piB pi'B; rewrite /Hall sBA (pnat_coprime piB). Qed.
Lemma Hall_pi G H : Hall G H -> \pi(H).-Hall(G) H.
Proof.
by case/andP=> sHG coHG /=; rewrite /pHall sHG /pgroup pnat_pi -?coprime_pi'.
Qed.
Lemma HallP G H : Hall G H -> exists pi, pi.-Hall(G) H.
Proof. by exists \pi(H); apply: Hall_pi. Qed.
Lemma sdprod_Hall G K H : K ><| H = G -> Hall G K = Hall G H.
Proof.
case/sdprod_context=> /andP[sKG _] sHG defG _ tiKH.
by rewrite /Hall sKG sHG -!divgS // -defG TI_cardMg // coprime_sym mulKn ?mulnK.
Qed.
Lemma coprime_sdprod_Hall_l G K H : K ><| H = G -> coprime #|K| #|H| = Hall G K.
Proof.
case/sdprod_context=> /andP[sKG _] _ defG _ tiKH.
by rewrite /Hall sKG -divgS // -defG TI_cardMg ?mulKn.
Qed.
Lemma coprime_sdprod_Hall_r G K H : K ><| H = G -> coprime #|K| #|H| = Hall G H.
Proof.
by move=> defG; rewrite (coprime_sdprod_Hall_l defG) (sdprod_Hall defG).
Qed.
Lemma compl_pHall pi K H G :
pi.-Hall(G) K -> (H \in [complements to K in G]) = pi^'.-Hall(G) H.
Proof.
move=> hallK; apply/complP/idP=> [[tiKH mulKH] | hallH].
have [_] := andP hallK; rewrite /pHall pnatNK -{3}(invGid G) -mulKH mulG_subr.
rewrite invMG !indexMg -indexgI andbC.
by rewrite -[#|K : H|]indexgI setIC tiKH !indexg1.
have [[sKG piK _] [sHG pi'H _]] := (and3P hallK, and3P hallH).
have tiKH: K :&: H = 1 := coprime_TIg (pnat_coprime piK pi'H).
split=> //; apply/eqP; rewrite eqEcard mul_subG //= TI_cardMg //.
by rewrite (card_Hall hallK) (card_Hall hallH) partnC.
Qed.
Lemma compl_p'Hall pi K H G :
pi^'.-Hall(G) K -> (H \in [complements to K in G]) = pi.-Hall(G) H.
Proof. by move/compl_pHall->; apply: eq_pHall (negnK pi). Qed.
Lemma sdprod_normal_p'HallP pi K H G :
K <| G -> pi^'.-Hall(G) H -> reflect (K ><| H = G) (pi.-Hall(G) K).
Proof.
move=> nsKG hallH; rewrite -(compl_p'Hall K hallH).
exact: sdprod_normal_complP.
Qed.
Lemma sdprod_normal_pHallP pi K H G :
K <| G -> pi.-Hall(G) H -> reflect (K ><| H = G) (pi^'.-Hall(G) K).
Proof.
by move=> nsKG hallH; apply: sdprod_normal_p'HallP; rewrite ?pHallNK.
Qed.
Lemma pHallJ2 pi G H x : pi.-Hall(G :^ x) (H :^ x) = pi.-Hall(G) H.
Proof. by rewrite !pHallE conjSg !cardJg. Qed.
Lemma pHallJnorm pi G H x : x \in 'N(G) -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H.
Proof. by move=> Nx; rewrite -{1}(normP Nx) pHallJ2. Qed.
Lemma pHallJ pi G H x : x \in G -> pi.-Hall(G) (H :^ x) = pi.-Hall(G) H.
Proof. by move=> Gx; rewrite -{1}(conjGid Gx) pHallJ2. Qed.
Lemma HallJ G H x : x \in G -> Hall G (H :^ x) = Hall G H.
Proof.
by move=> Gx; rewrite /Hall -!divgI -{1 3}(conjGid Gx) conjSg -conjIg !cardJg.
Qed.
Lemma psubgroupJ pi G H x :
x \in G -> pi.-subgroup(G) (H :^ x) = pi.-subgroup(G) H.
Proof. by move=> Gx; rewrite /psubgroup pgroupJ -{1}(conjGid Gx) conjSg. Qed.
Lemma p_groupJ P x : p_group (P :^ x) = p_group P.
Proof. by rewrite /p_group cardJg pgroupJ. Qed.
Lemma SylowJ G P x : x \in G -> Sylow G (P :^ x) = Sylow G P.
Proof. by move=> Gx; rewrite /Sylow p_groupJ HallJ. Qed.
Lemma p_Sylow p G P : p.-Sylow(G) P -> Sylow G P.
Proof.
by move=> pP; rewrite /Sylow (pgroup_p (pHall_pgroup pP)) (pHall_Hall pP).
Qed.
Lemma pHall_subl pi G K H :
H \subset K -> K \subset G -> pi.-Hall(G) H -> pi.-Hall(K) H.
Proof.
by move=> sHK sKG; rewrite /pHall sHK => /and3P[_ ->]; apply/pnat_dvd/indexSg.
Qed.
Lemma Hall1 G : Hall G 1.
Proof. by rewrite /Hall sub1G cards1 coprime1n. Qed.
Lemma p_group1 : @p_group gT 1.
Proof. by rewrite (@pgroup_p 2) ?pgroup1. Qed.
Lemma Sylow1 G : Sylow G 1.
Proof. by rewrite /Sylow p_group1 Hall1. Qed.
Lemma SylowP G P : reflect (exists2 p, prime p & p.-Sylow(G) P) (Sylow G P).
Proof.
apply: (iffP idP) => [| [p _]]; last exact: p_Sylow.
case/andP=> /p_groupP[p p_pr] /p_natP[[P1 _ | n oP /Hall_pi]]; last first.
by rewrite /= oP pi_of_exp // (eq_pHall _ _ (pi_of_prime _)) //; exists p.
have{p p_pr P1} ->: P :=: 1 by apply: card1_trivg; rewrite P1.
pose p := pdiv #|G|.+1; have p_pr: prime p by rewrite pdiv_prime ?ltnS.
exists p; rewrite // pHallE sub1G cards1 part_p'nat //.
apply/pgroupP=> q pr_q qG; apply/eqnP=> def_q.
have: p %| #|G| + 1 by rewrite addn1 pdiv_dvd.
by rewrite dvdn_addr -def_q // Euclid_dvd1.
Qed.
Lemma p_elt_exp pi x m : pi.-elt (x ^+ m) = (#[x]`_pi^' %| m).
Proof.
apply/idP/idP=> [pi_xm | /dvdnP[q ->{m}]]; last first.
rewrite mulnC; apply: pnat_dvd (part_pnat pi #[x]).
by rewrite order_dvdn -expgM mulnC mulnA partnC // -order_dvdn dvdn_mulr.
rewrite -(@Gauss_dvdr _ #[x ^+ m]); last first.
by rewrite coprime_sym (pnat_coprime pi_xm) ?part_pnat.
apply: (@dvdn_trans #[x]); first by rewrite -{2}[#[x]](partnC pi) ?dvdn_mull.
by rewrite order_dvdn mulnC expgM expg_order.
Qed.
Lemma mem_p_elt pi x G : pi.-group G -> x \in G -> pi.-elt x.
Proof. by move=> piG Gx; apply: pgroupS piG; rewrite cycle_subG. Qed.
Lemma p_eltM_norm pi x y :
x \in 'N(<[y]>) -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y).
Proof.
move=> nyx pi_x pi_y; apply: (@mem_p_elt pi _ (<[x]> <*> <[y]>)%G).
by rewrite /= norm_joinEl ?cycle_subG // pgroupM; apply/andP.
by rewrite groupM // mem_gen // inE cycle_id ?orbT.
Qed.
Lemma p_eltM pi x y : commute x y -> pi.-elt x -> pi.-elt y -> pi.-elt (x * y).
Proof.
move=> cxy; apply: p_eltM_norm; apply: (subsetP (cent_sub _)).
by rewrite cent_gen cent_set1; apply/cent1P.
Qed.
Lemma p_elt1 pi : pi.-elt (1 : gT).
Proof. by rewrite /p_elt order1. Qed.
Lemma p_eltV pi x : pi.-elt x^-1 = pi.-elt x.
Proof. by rewrite /p_elt orderV. Qed.
Lemma p_eltX pi x n : pi.-elt x -> pi.-elt (x ^+ n).
Proof. by rewrite -{1}[x]expg1 !p_elt_exp dvdn1 => /eqnP->. Qed.
Lemma p_eltJ pi x y : pi.-elt (x ^ y) = pi.-elt x.
Proof. by congr pnat; rewrite orderJ. Qed.
Lemma sub_p_elt pi1 pi2 x : {subset pi1 <= pi2} -> pi1.-elt x -> pi2.-elt x.
Proof. by move=> pi12; apply: sub_in_pnat => q _; apply: pi12. Qed.
Lemma eq_p_elt pi1 pi2 x : pi1 =i pi2 -> pi1.-elt x = pi2.-elt x.
Proof. by move=> pi12; apply: eq_pnat. Qed.
Lemma p_eltNK pi x : pi^'^'.-elt x = pi.-elt x.
Proof. exact: pnatNK. Qed.
Lemma eq_constt pi1 pi2 x : pi1 =i pi2 -> x.`_pi1 = x.`_pi2.
Proof.
move=> pi12; congr (x ^+ (chinese _ _ 1 0)); apply: eq_partn => // a.
by congr (~~ _); apply: pi12.
Qed.
Lemma consttNK pi x : x.`_pi^'^' = x.`_pi.
Proof. by rewrite /constt !partnNK. Qed.
Lemma cycle_constt pi x : x.`_pi \in <[x]>.
Proof. exact: mem_cycle. Qed.
Lemma consttV pi x : (x^-1).`_pi = (x.`_pi)^-1.
Proof. by rewrite /constt expgVn orderV. Qed.
Lemma constt1 pi : 1.`_pi = 1 :> gT.
Proof. exact: expg1n. Qed.
Lemma consttJ pi x y : (x ^ y).`_pi = x.`_pi ^ y.
Proof. by rewrite /constt orderJ conjXg. Qed.
Lemma p_elt_constt pi x : pi.-elt x.`_pi.
Proof. by rewrite p_elt_exp /chinese addn0 mul1n dvdn_mulr. Qed.
Lemma consttC pi x : x.`_pi * x.`_pi^' = x.
Proof.
apply/eqP; rewrite -{3}[x]expg1 -expgD eq_expg_mod_order.
rewrite partnNK -{5 6}(@partnC pi #[x]) // /chinese !addn0.
by rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC ?eqxx.
Qed.
Lemma p'_elt_constt pi x : pi^'.-elt (x * (x.`_pi)^-1).
Proof. by rewrite -{1}(consttC pi^' x) consttNK mulgK p_elt_constt. Qed.
Lemma order_constt pi (x : gT) : #[x.`_pi] = #[x]`_pi.
Proof.
rewrite -{2}(consttC pi x) orderM; [|exact: commuteX2|]; last first.
by apply: (@pnat_coprime pi); apply: p_elt_constt.
by rewrite partnM // part_pnat_id ?part_p'nat ?muln1 //; apply: p_elt_constt.
Qed.
Lemma consttM pi x y : commute x y -> (x * y).`_pi = x.`_pi * y.`_pi.
Proof.
move=> cxy; pose m := #|<<[set x; y]>>|; have m_gt0: 0 < m := cardG_gt0 _.
pose k := chinese m`_pi m`_pi^' 1 0.
suffices kXpi z: z \in <<[set x; y]>> -> z.`_pi = z ^+ k.
by rewrite !kXpi ?expgMn // ?groupM ?mem_gen // !inE eqxx ?orbT.
move=> xyz; have{xyz} zm: #[z] %| m by rewrite cardSg ?cycle_subG.
apply/eqP; rewrite eq_expg_mod_order -{3 4}[#[z]](partnC pi) //.
rewrite chinese_remainder ?chinese_modl ?chinese_modr ?coprime_partC //.
rewrite -!(modn_dvdm k (partn_dvd _ m_gt0 zm)).
rewrite chinese_modl ?chinese_modr ?coprime_partC //.
by rewrite !modn_dvdm ?partn_dvd ?eqxx.
Qed.
Lemma consttX pi x n : (x ^+ n).`_pi = x.`_pi ^+ n.
Proof.
elim: n => [|n IHn]; first exact: constt1.
by rewrite !expgS consttM ?IHn //; apply: commuteX.
Qed.
Lemma constt1P pi x : reflect (x.`_pi = 1) (pi^'.-elt x).
Proof.
rewrite -{2}[x]expg1 p_elt_exp -order_constt consttNK order_dvdn expg1.
exact: eqP.
Qed.
Lemma constt_p_elt pi x : pi.-elt x -> x.`_pi = x.
Proof.
by rewrite -p_eltNK -{3}(consttC pi x) => /constt1P->; rewrite mulg1.
Qed.
Lemma sub_in_constt pi1 pi2 x :
{in \pi(#[x]), {subset pi1 <= pi2}} -> x.`_pi2.`_pi1 = x.`_pi1.
Proof.
move=> pi12; rewrite -{2}(consttC pi2 x) consttM; last exact: commuteX2.
rewrite (constt1P _ x.`_pi2^' _) ?mulg1 //.
apply: sub_in_pnat (p_elt_constt _ x) => p; rewrite order_constt => pi_p.
by apply/contra/pi12; rewrite -[#[x]](partnC pi2^') // primesM // pi_p.
Qed.
Lemma prod_constt x : \prod_(0 <= p < #[x].+1) x.`_p = x.
Proof.
pose lp n := [pred p | p < n].
have: (lp #[x].+1).-elt x by apply/pnatP=> // p _; apply: dvdn_leq.
move/constt_p_elt=> def_x; symmetry; rewrite -{1}def_x {def_x}.
elim: _.+1 => [|p IHp].
by rewrite big_nil; apply/constt1P; apply/pgroupP.
rewrite big_nat_recr //= -{}IHp -(consttC (lp p) x.`__); congr (_ * _).
by rewrite sub_in_constt // => q _; apply: leqW.
set y := _.`__; rewrite -(consttC p y) (constt1P p^' _ _) ?mulg1.
by rewrite 2?sub_in_constt // => q _; move/eqnP->; rewrite !inE ?ltnn.
rewrite /p_elt pnatNK !order_constt -partnI.
apply: sub_in_pnat (part_pnat _ _) => q _.
by rewrite !inE ltnS -leqNgt -eqn_leq.
Qed.
Lemma max_pgroupJ pi M G x :
x \in G -> [max M | pi.-subgroup(G) M] ->
[max M :^ x of M | pi.-subgroup(G) M].
Proof.
move=> Gx /maxgroupP[piM maxM]; apply/maxgroupP.
split=> [|H piH]; first by rewrite psubgroupJ.
by rewrite -(conjsgKV x H) conjSg => /maxM/=-> //; rewrite psubgroupJ ?groupV.
Qed.
Lemma comm_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G ->
commute H M -> H \subset M.
Proof.
case/maxgroupP=> /andP[sMG piM] maxM piH sHG cHM.
rewrite -(maxM (H <*> M)%G) /= comm_joingE ?(mulG_subl, mulG_subr) //.
by rewrite /psubgroup pgroupM piM piH mul_subG.
Qed.
Lemma normal_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H <| G -> H \subset M.
Proof.
move=> maxM piH /andP[sHG nHG].
apply: comm_sub_max_pgroup piH sHG _ => //; apply: commute_sym; apply: normC.
by apply: subset_trans nHG; case/andP: (maxgroupp maxM).
Qed.
Lemma norm_sub_max_pgroup pi H M G :
[max M | pi.-subgroup(G) M] -> pi.-group H -> H \subset G ->
H \subset 'N(M) -> H \subset M.
Proof. by move=> maxM piH sHG /normC; apply: comm_sub_max_pgroup piH sHG. Qed.
Lemma sub_pHall pi H G K :
pi.-Hall(G) H -> pi.-group K -> H \subset K -> K \subset G -> K :=: H.
Proof.
move=> hallH piK sHK sKG; apply/eqP; rewrite eq_sym eqEcard sHK.
by rewrite (card_Hall hallH) -(part_pnat_id piK) dvdn_leq ?partn_dvd ?cardSg.
Qed.
Lemma Hall_max pi H G : pi.-Hall(G) H -> [max H | pi.-subgroup(G) H].
Proof.
move=> hallH; apply/maxgroupP; split=> [|K /andP[sKG piK] sHK].
by rewrite /psubgroup; case/and3P: hallH => ->.
exact: (sub_pHall hallH).
Qed.
Lemma pHall_id pi H G : pi.-Hall(G) H -> pi.-group G -> H :=: G.
Proof.
by move=> hallH piG; rewrite (sub_pHall hallH piG) ?(pHall_sub hallH).
Qed.
Lemma psubgroup1 pi G : pi.-subgroup(G) 1.
Proof. by rewrite /psubgroup sub1G pgroup1. Qed.
Lemma Cauchy p G : prime p -> p %| #|G| -> {x | x \in G & #[x] = p}.
Proof.
move=> p_pr; have [n] := ubnP #|G|; elim: n G => // n IHn G /ltnSE-leGn pG.
pose xpG := [pred x in G | #[x] == p].
have [x /andP[Gx /eqP] | no_x] := pickP xpG; first by exists x.
have{pG n leGn IHn} pZ: p %| #|'C_G(G)|.
suffices /dvdn_addl <-: p %| #|G :\: 'C(G)| by rewrite cardsID.
have /acts_sum_card_orbit <-: [acts G, on G :\: 'C(G) | 'J].
by apply/actsP=> x Gx y; rewrite !inE -!mem_conjgV -centJ conjGid ?groupV.
elim/big_rec: _ => // _ _ /imsetP[x /setDP[Gx nCx] ->] /dvdn_addl->.
have ltCx: 'C_G[x] \proper G by rewrite properE subsetIl subsetIidl sub_cent1.
have /negP: ~ p %| #|'C_G[x]|.
case/(IHn _ (leq_trans (proper_card ltCx) leGn))=> y /setIP[Gy _] /eqP-oy.
by have /andP[] := no_x y.
by apply/implyP; rewrite -index_cent1 indexgI implyNb -Euclid_dvdM ?LagrangeI.
have [Q maxQ _]: {Q | [max Q | p^'.-subgroup('C_G(G)) Q] & 1%G \subset Q}.
by apply: maxgroup_exists; apply: psubgroup1.
case/andP: (maxgroupp maxQ) => sQC; rewrite /pgroup p'natE // => /negP[].
apply: dvdn_trans pZ (cardSg _); apply/subsetP=> x /setIP[Gx Cx].
rewrite -sub1set -gen_subG (normal_sub_max_pgroup maxQ) //; last first.
rewrite /normal subsetI !cycle_subG ?Gx ?cents_norm ?subIset ?andbT //=.
by rewrite centsC cycle_subG Cx.
rewrite /pgroup p'natE //= -[#|_|]/#[x]; apply/dvdnP=> [[m oxm]].
have m_gt0: 0 < m by apply: dvdn_gt0 (order_gt0 x) _; rewrite oxm dvdn_mulr.
case/idP: (no_x (x ^+ m)); rewrite /= groupX //= orderXgcd //= oxm.
by rewrite gcdnC gcdnMr mulKn.
Qed.
(* These lemmas actually hold for maximal pi-groups, but below we'll *)
(* derive from the Cauchy lemma that a normal max pi-group is Hall. *)
Lemma sub_normal_Hall pi G H K :
pi.-Hall(G) H -> H <| G -> K \subset G -> (K \subset H) = pi.-group K.
Proof.
move=> hallH nsHG sKG; apply/idP/idP=> [sKH | piK].
by rewrite (pgroupS sKH) ?(pHall_pgroup hallH).
apply: norm_sub_max_pgroup (Hall_max hallH) piK _ _ => //.
exact: subset_trans sKG (normal_norm nsHG).
Qed.
Lemma mem_normal_Hall pi H G x :
pi.-Hall(G) H -> H <| G -> x \in G -> (x \in H) = pi.-elt x.
Proof. by rewrite -!cycle_subG; apply: sub_normal_Hall. Qed.
Lemma uniq_normal_Hall pi H G K :
pi.-Hall(G) H -> H <| G -> [max K | pi.-subgroup(G) K] -> K :=: H.
Proof.
move=> hallH nHG /maxgroupP[/andP[sKG piK] /(_ H) -> //].
exact: (maxgroupp (Hall_max hallH)).
by rewrite (sub_normal_Hall hallH).
Qed.
End PgroupProps.
Arguments pgroupP {gT pi G}.
Arguments constt1P {gT pi x}.
Section NormalHall.
Variables (gT : finGroupType) (pi : nat_pred).
Implicit Types G H K : {group gT}.
Lemma normal_max_pgroup_Hall G H :
[max H | pi.-subgroup(G) H] -> H <| G -> pi.-Hall(G) H.
Proof.
case/maxgroupP=> /andP[sHG piH] maxH nsHG; have [_ nHG] := andP nsHG.
rewrite /pHall sHG piH; apply/pnatP=> // p p_pr.
rewrite inE /= -pnatE // -card_quotient //.
case/Cauchy=> //= Hx; rewrite -sub1set -gen_subG -/<[Hx]> /order.
case/inv_quotientS=> //= K -> sHK sKG {Hx}.
rewrite card_quotient ?(subset_trans sKG) // => iKH; apply/negP=> pi_p.
rewrite -iKH -divgS // (maxH K) ?divnn ?cardG_gt0 // in p_pr.
by rewrite /psubgroup sKG /pgroup -(Lagrange sHK) mulnC pnatM iKH pi_p.
Qed.
Lemma setI_normal_Hall G H K :
H <| G -> pi.-Hall(G) H -> K \subset G -> pi.-Hall(K) (H :&: K).
Proof.
move=> nsHG hallH sKG; apply: normal_max_pgroup_Hall; last first.
by rewrite /= setIC (normalGI sKG nsHG).
apply/maxgroupP; split=> [|M /andP[sMK piM] sHK_M].
by rewrite /psubgroup subsetIr (pgroupS (subsetIl _ _) (pHall_pgroup hallH)).
apply/eqP; rewrite eqEsubset sHK_M subsetI sMK !andbT.
by rewrite (sub_normal_Hall hallH) // (subset_trans sMK).
Qed.
End NormalHall.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Types (pi : nat_pred) (G H P : {group aT}).
Lemma morphim_pgroup pi G : pi.-group G -> pi.-group (f @* G).
Proof. by apply: pnat_dvd; apply: dvdn_morphim. Qed.
Lemma morphim_odd G : odd #|G| -> odd #|f @* G|.
Proof. by rewrite !odd_2'nat; apply: morphim_pgroup. Qed.
Lemma pmorphim_pgroup pi G :
pi.-group ('ker f) -> G \subset D -> pi.-group (f @* G) = pi.-group G.
Proof.
move=> piker sGD; apply/idP/idP=> [pifG|]; last exact: morphim_pgroup.
apply: (@pgroupS _ _ (f @*^-1 (f @* G))); first by rewrite -sub_morphim_pre.
by rewrite /pgroup card_morphpre ?morphimS // pnatM; apply/andP.
Qed.
Lemma morphim_p_index pi G H :
H \subset D -> pi.-nat #|G : H| -> pi.-nat #|f @* G : f @* H|.
Proof.
by move=> sHD; apply: pnat_dvd; rewrite index_morphim ?subIset // sHD orbT.
Qed.
Lemma morphim_pHall pi G H :
H \subset D -> pi.-Hall(G) H -> pi.-Hall(f @* G) (f @* H).
Proof.
move=> sHD /and3P[sHG piH pi'GH].
by rewrite /pHall morphimS // morphim_pgroup // morphim_p_index.
Qed.
Lemma pmorphim_pHall pi G H :
G \subset D -> H \subset D -> pi.-subgroup(H :&: G) ('ker f) ->
pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H.
Proof.
move=> sGD sHD /andP[/subsetIP[sKH sKG] piK]; rewrite !pHallE morphimSGK //.
apply: andb_id2l => sHG; rewrite -(Lagrange sKH) -(Lagrange sKG) partnM //.
by rewrite (part_pnat_id piK) !card_morphim !(setIidPr _) // eqn_pmul2l.
Qed.
Lemma morphim_Hall G H : H \subset D -> Hall G H -> Hall (f @* G) (f @* H).
Proof.
by move=> sHD /HallP[pi piH]; apply: (@pHall_Hall _ pi); apply: morphim_pHall.
Qed.
Lemma morphim_pSylow p G P :
P \subset D -> p.-Sylow(G) P -> p.-Sylow(f @* G) (f @* P).
Proof. exact: morphim_pHall. Qed.
Lemma morphim_p_group P : p_group P -> p_group (f @* P).
Proof. by move/morphim_pgroup; apply: pgroup_p. Qed.
Lemma morphim_Sylow G P : P \subset D -> Sylow G P -> Sylow (f @* G) (f @* P).
Proof.
by move=> sPD /andP[pP hallP]; rewrite /Sylow morphim_p_group // morphim_Hall.
Qed.
Lemma morph_p_elt pi x : x \in D -> pi.-elt x -> pi.-elt (f x).
Proof. by move=> Dx; apply: pnat_dvd; apply: morph_order. Qed.
Lemma morph_constt pi x : x \in D -> f x.`_pi = (f x).`_pi.
Proof.
move=> Dx; rewrite -{2}(consttC pi x) morphM ?groupX //.
rewrite consttM; last by rewrite !morphX //; apply: commuteX2.
have: pi.-elt (f x.`_pi) by rewrite morph_p_elt ?groupX ?p_elt_constt //.
have: pi^'.-elt (f x.`_pi^') by rewrite morph_p_elt ?groupX ?p_elt_constt //.
by move/constt1P->; move/constt_p_elt->; rewrite mulg1.
Qed.
End Morphim.
Section Pquotient.
Variables (pi : nat_pred) (gT : finGroupType) (p : nat) (G H K : {group gT}).
Hypothesis piK : pi.-group K.
Lemma quotient_pgroup : pi.-group (K / H). Proof. exact: morphim_pgroup. Qed.
Lemma quotient_pHall :
K \subset 'N(H) -> pi.-Hall(G) K -> pi.-Hall(G / H) (K / H).
Proof. exact: morphim_pHall. Qed.
Lemma quotient_odd : odd #|K| -> odd #|K / H|. Proof. exact: morphim_odd. Qed.
Lemma pquotient_pgroup : G \subset 'N(K) -> pi.-group (G / K) = pi.-group G.
Proof. by move=> nKG; rewrite pmorphim_pgroup ?ker_coset. Qed.
Lemma pquotient_pHall :
K <| G -> K <| H -> pi.-Hall(G / K) (H / K) = pi.-Hall(G) H.
Proof.
case/andP=> sKG nKG; case/andP=> sKH nKH.
by rewrite pmorphim_pHall // ker_coset /psubgroup subsetI sKH sKG.
Qed.
Lemma ltn_log_quotient :
p.-group G -> H :!=: 1 -> H \subset G -> logn p #|G / H| < logn p #|G|.
Proof.
move=> pG ntH sHG; apply: contraLR (ltn_quotient ntH sHG); rewrite -!leqNgt.
rewrite {2}(card_pgroup pG) {2}(card_pgroup (morphim_pgroup _ pG)).
by case: (posnP p) => [-> //|]; apply: leq_pexp2l.
Qed.
End Pquotient.
(* Application of card_Aut_cyclic to internal faithful action on cyclic *)
(* p-subgroups. *)
Section InnerAutCyclicPgroup.
Variables (gT : finGroupType) (p : nat) (G C : {group gT}).
Hypothesis nCG : G \subset 'N(C).
Lemma logn_quotient_cent_cyclic_pgroup :
p.-group C -> cyclic C -> logn p #|G / 'C_G(C)| <= (logn p #|C|).-1.
Proof.
move=> pC cycC; have [-> | ntC] := eqsVneq C 1.
by rewrite cent1T setIT trivg_quotient cards1 logn1.
have [p_pr _ [e oC]] := pgroup_pdiv pC ntC.
rewrite -ker_conj_aut (card_isog (first_isog_loc _ _)) //.
apply: leq_trans (dvdn_leq_log _ _ (cardSg (Aut_conj_aut _ _))) _ => //.
rewrite card_Aut_cyclic // oC totient_pfactor //= logn_Gauss ?pfactorK //.
by rewrite prime_coprime // gtnNdvd // -(subnKC (prime_gt1 p_pr)).
Qed.
Lemma p'group_quotient_cent_prime :
prime p -> #|C| %| p -> p^'.-group (G / 'C_G(C)).
Proof.
move=> p_pr pC; have pgC: p.-group C := pnat_dvd pC (pnat_id p_pr).
have [_ dv_p] := primeP p_pr; case/pred2P: {dv_p pC}(dv_p _ pC) => [|pC].
by move/card1_trivg->; rewrite cent1T setIT trivg_quotient pgroup1.
have le_oGC := logn_quotient_cent_cyclic_pgroup pgC.
rewrite /pgroup -partn_eq1 ?cardG_gt0 // -dvdn1 p_part pfactor_dvdn // logn1.
by rewrite (leq_trans (le_oGC _)) ?prime_cyclic // pC ?(pfactorK 1).
Qed.
End InnerAutCyclicPgroup.
Section PcoreDef.
(* A functor needs to quantify over the finGroupType just beore the set. *)
Variables (pi : nat_pred) (gT : finGroupType) (A : {set gT}).
Definition pcore := \bigcap_(G | [max G | pi.-subgroup(A) G]) G.
Canonical pcore_group : {group gT} := Eval hnf in [group of pcore].
End PcoreDef.
Arguments pcore pi%_N {gT} A%_g.
Arguments pcore_group pi%_N {gT} A%_G.
Notation "''O_' pi ( G )" := (pcore pi G)
(pi at level 2, format "''O_' pi ( G )") : group_scope.
Notation "''O_' pi ( G )" := (pcore_group pi G) : Group_scope.
Section PseriesDefs.
Variables (pis : seq nat_pred) (gT : finGroupType) (A : {set gT}).
Definition pcore_mod pi B := coset B @*^-1 'O_pi(A / B).
Canonical pcore_mod_group pi B : {group gT} :=
Eval hnf in [group of pcore_mod pi B].
Definition pseries := foldr pcore_mod 1 (rev pis).
Lemma pseries_group_set : group_set pseries.
Proof. by rewrite /pseries; case: rev => [|pi1 pi1']; apply: groupP. Qed.
Canonical pseries_group : {group gT} := group pseries_group_set.
End PseriesDefs.
Arguments pseries pis%_SEQ {gT} _%_g.
Local Notation ConsPred p := (@Cons nat_pred p%N) (only parsing).
Notation "''O_{' p1 , .. , pn } ( A )" :=
(pseries (ConsPred p1 .. (ConsPred pn [::]) ..) A)
(format "''O_{' p1 , .. , pn } ( A )") : group_scope.
Notation "''O_{' p1 , .. , pn } ( A )" :=
(pseries_group (ConsPred p1 .. (ConsPred pn [::]) ..) A) : Group_scope.
Section PCoreProps.
Variables (pi : nat_pred) (gT : finGroupType).
Implicit Types (A : {set gT}) (G H M K : {group gT}).
Lemma pcore_psubgroup G : pi.-subgroup(G) 'O_pi(G).
Proof.
have [M maxM _]: {M | [max M | pi.-subgroup(G) M] & 1%G \subset M}.
by apply: maxgroup_exists; rewrite /psubgroup sub1G pgroup1.
have sOM: 'O_pi(G) \subset M by apply: bigcap_inf.
have /andP[piM sMG] := maxgroupp maxM.
by rewrite /psubgroup (pgroupS sOM) // (subset_trans sOM).
Qed.
Lemma pcore_pgroup G : pi.-group 'O_pi(G).
Proof. by case/andP: (pcore_psubgroup G). Qed.
Lemma pcore_sub G : 'O_pi(G) \subset G.
Proof. by case/andP: (pcore_psubgroup G). Qed.
Lemma pcore_sub_Hall G H : pi.-Hall(G) H -> 'O_pi(G) \subset H.
Proof. by move/Hall_max=> maxH; apply: bigcap_inf. Qed.
Lemma pcore_max G H : pi.-group H -> H <| G -> H \subset 'O_pi(G).
Proof.
move=> piH nHG; apply/bigcapsP=> M maxM.
exact: normal_sub_max_pgroup piH nHG.
Qed.
Lemma pcore_pgroup_id G : pi.-group G -> 'O_pi(G) = G.
Proof. by move=> piG; apply/eqP; rewrite eqEsubset pcore_sub pcore_max. Qed.
Lemma pcore_normal G : 'O_pi(G) <| G.
Proof.
rewrite /(_ <| G) pcore_sub; apply/subsetP=> x Gx.
rewrite inE; apply/bigcapsP=> M maxM; rewrite sub_conjg.
by apply: bigcap_inf; apply: max_pgroupJ; rewrite ?groupV.
Qed.
Lemma normal_Hall_pcore H G : pi.-Hall(G) H -> H <| G -> 'O_pi(G) = H.
Proof.
move=> hallH nHG; apply/eqP.
rewrite eqEsubset (sub_normal_Hall hallH) ?pcore_sub ?pcore_pgroup //=.
by rewrite pcore_max //= (pHall_pgroup hallH).
Qed.
Lemma eq_Hall_pcore G H :
pi.-Hall(G) 'O_pi(G) -> pi.-Hall(G) H -> H :=: 'O_pi(G).
Proof.
move=> hallGpi hallH.
exact: uniq_normal_Hall (pcore_normal G) (Hall_max hallH).
Qed.
Lemma sub_Hall_pcore G K :
pi.-Hall(G) 'O_pi(G) -> K \subset G -> (K \subset 'O_pi(G)) = pi.-group K.
Proof. by move=> hallGpi; apply: sub_normal_Hall (pcore_normal G). Qed.
Lemma mem_Hall_pcore G x :
pi.-Hall(G) 'O_pi(G) -> x \in G -> (x \in 'O_pi(G)) = pi.-elt x.
Proof. by move=> hallGpi; apply: mem_normal_Hall (pcore_normal G). Qed.
Lemma sdprod_Hall_pcoreP H G :
pi.-Hall(G) 'O_pi(G) -> reflect ('O_pi(G) ><| H = G) (pi^'.-Hall(G) H).
Proof.
move=> hallGpi; rewrite -(compl_pHall H hallGpi) complgC.
exact: sdprod_normal_complP (pcore_normal G).
Qed.
Lemma sdprod_pcore_HallP H G :
pi^'.-Hall(G) H -> reflect ('O_pi(G) ><| H = G) (pi.-Hall(G) 'O_pi(G)).
Proof. exact: sdprod_normal_p'HallP (pcore_normal G). Qed.
Lemma pcoreJ G x : 'O_pi(G :^ x) = 'O_pi(G) :^ x.
Proof.
apply/eqP; rewrite eqEsubset -sub_conjgV.
rewrite !pcore_max ?pgroupJ ?pcore_pgroup ?normalJ ?pcore_normal //.
by rewrite -(normalJ _ _ x) conjsgKV pcore_normal.
Qed.
End PCoreProps.
Section MorphPcore.
Implicit Types (pi : nat_pred) (gT rT : finGroupType).
Lemma morphim_pcore pi : GFunctor.pcontinuous (@pcore pi).
Proof.
move=> gT rT D G f; apply/bigcapsP=> M /normal_sub_max_pgroup; apply.
by rewrite morphim_pgroup ?pcore_pgroup.
by apply: morphim_normal; apply: pcore_normal.
Qed.
Lemma pcoreS pi gT (G H : {group gT}) :
H \subset G -> H :&: 'O_pi(G) \subset 'O_pi(H).
Proof.
move=> sHG; rewrite -{2}(setIidPl sHG).
by do 2!rewrite -(morphim_idm (subsetIl H _)) morphimIdom; apply: morphim_pcore.
Qed.
Canonical pcore_igFun pi := [igFun by pcore_sub pi & morphim_pcore pi].
Canonical pcore_gFun pi := [gFun by morphim_pcore pi].
Canonical pcore_pgFun pi := [pgFun by morphim_pcore pi].
Lemma pcore_char pi gT (G : {group gT}) : 'O_pi(G) \char G.
Proof. exact: gFchar. Qed.
Section PcoreMod.
Variable F : GFunctor.pmap.
Lemma pcore_mod_sub pi gT (G : {group gT}) : pcore_mod G pi (F _ G) \subset G.
Proof.
by rewrite sub_morphpre_im ?gFsub_trans ?morphimS ?gFnorm //= ker_coset gFsub.
Qed.
Lemma quotient_pcore_mod pi gT (G : {group gT}) (B : {set gT}) :
pcore_mod G pi B / B = 'O_pi(G / B).
Proof. exact/morphpreK/gFsub_trans/morphim_sub. Qed.
Lemma morphim_pcore_mod pi gT rT (D G : {group gT}) (f : {morphism D >-> rT}) :
f @* pcore_mod G pi (F _ G) \subset pcore_mod (f @* G) pi (F _ (f @* G)).
Proof.
have sDF: D :&: G \subset 'dom (coset (F _ G)).
by rewrite setIC subIset ?gFnorm.
have sDFf: D :&: G \subset 'dom (coset (F _ (f @* G)) \o f).
by rewrite -sub_morphim_pre ?subsetIl // morphimIdom gFnorm.
pose K := 'ker (restrm sDFf (coset (F _ (f @* G)) \o f)).
have sFK: 'ker (restrm sDF (coset (F _ G))) \subset K.
rewrite /K !ker_restrm ker_comp /= subsetI subsetIl /= -setIA.
rewrite -sub_morphim_pre ?subsetIl //.
by rewrite morphimIdom !ker_coset (setIidPr _) ?pmorphimF ?gFsub.
have sOF := pcore_sub pi (G / F _ G); have sDD: D :&: G \subset D :&: G by [].
rewrite -sub_morphim_pre -?quotientE; last first.
by apply: subset_trans (gFnorm F _); rewrite morphimS ?pcore_mod_sub.
suffices im_fact (H : {group gT}) : F _ G \subset H -> H \subset G ->
factm sFK sDD @* (H / F _ G) = f @* H / F _ (f @* G).
- rewrite -2?im_fact ?pcore_mod_sub ?gFsub //;
try by rewrite -{1}[F _ G]ker_coset morphpreS ?sub1G.
by rewrite quotient_pcore_mod morphim_pcore.
move=> sFH sHG; rewrite -(morphimIdom _ (H / _)) /= {2}morphim_restrm setIid.
rewrite -morphimIG ?ker_coset //.
rewrite -(morphim_restrm sDF) morphim_factm morphim_restrm.
by rewrite morphim_comp -quotientE -setIA morphimIdom (setIidPr _).
Qed.
Lemma pcore_mod_res pi gT rT (D : {group gT}) (f : {morphism D >-> rT}) :
f @* pcore_mod D pi (F _ D) \subset pcore_mod (f @* D) pi (F _ (f @* D)).
Proof. exact: morphim_pcore_mod. Qed.
Lemma pcore_mod1 pi gT (G : {group gT}) : pcore_mod G pi 1 = 'O_pi(G).
Proof.
rewrite /pcore_mod; have inj1 := coset1_injm gT; rewrite -injmF ?norms1 //.
by rewrite -(morphim_invmE inj1) morphim_invm ?norms1.
Qed.
End PcoreMod.
Lemma pseries_rcons pi pis gT (A : {set gT}) :
pseries (rcons pis pi) A = pcore_mod A pi (pseries pis A).
Proof. by rewrite /pseries rev_rcons. Qed.
Lemma pseries_subfun pis :
GFunctor.closed (@pseries pis) /\ GFunctor.pcontinuous (@pseries pis).
Proof.
elim/last_ind: pis => [|pis pi [sFpi fFpi]].
by split=> [gT G | gT rT D G f]; rewrite (sub1G, morphim1).
pose fF := [gFun by fFpi : GFunctor.continuous [igFun by sFpi & fFpi]].
pose F := [pgFun by fFpi : GFunctor.hereditary fF].
split=> [gT G | gT rT D G f]; rewrite !pseries_rcons ?(pcore_mod_sub F) //.
exact: (morphim_pcore_mod F).
Qed.
Lemma pseries_sub pis : GFunctor.closed (@pseries pis).
Proof. by case: (pseries_subfun pis). Qed.
Lemma morphim_pseries pis : GFunctor.pcontinuous (@pseries pis).
Proof. by case: (pseries_subfun pis). Qed.
Lemma pseriesS pis : GFunctor.hereditary (@pseries pis).
Proof. exact: (morphim_pseries pis). Qed.
Canonical pseries_igFun pis := [igFun by pseries_sub pis & morphim_pseries pis].
Canonical pseries_gFun pis := [gFun by morphim_pseries pis].
Canonical pseries_pgFun pis := [pgFun by morphim_pseries pis].
Lemma pseries_char pis gT (G : {group gT}) : pseries pis G \char G.
Proof. exact: gFchar. Qed.
Lemma pseries_normal pis gT (G : {group gT}) : pseries pis G <| G.
Proof. exact: gFnormal. Qed.
Lemma pseriesJ pis gT (G : {group gT}) x :
pseries pis (G :^ x) = pseries pis G :^ x.
Proof.
rewrite -{1}(setIid G) -morphim_conj -(injmF _ (injm_conj G x)) //=.
by rewrite morphim_conj (setIidPr (pseries_sub _ _)).
Qed.
Lemma pseries1 pi gT (G : {group gT}) : 'O_{pi}(G) = 'O_pi(G).
Proof. exact: pcore_mod1. Qed.
Lemma pseries_pop pi pis gT (G : {group gT}) :
'O_pi(G) = 1 -> pseries (pi :: pis) G = pseries pis G.
Proof.
by move=> OG1; rewrite /pseries rev_cons -cats1 foldr_cat /= pcore_mod1 OG1.
Qed.
Lemma pseries_pop2 pi1 pi2 gT (G : {group gT}) :
'O_pi1(G) = 1 -> 'O_{pi1, pi2}(G) = 'O_pi2(G).
Proof. by move/pseries_pop->; apply: pseries1. Qed.
Lemma pseries_sub_catl pi1s pi2s gT (G : {group gT}) :
pseries pi1s G \subset pseries (pi1s ++ pi2s) G.
Proof.
elim/last_ind: pi2s => [|pi pis IHpi]; rewrite ?cats0 // -rcons_cat.
by rewrite pseries_rcons; apply: subset_trans IHpi _; rewrite sub_cosetpre.
Qed.
Lemma quotient_pseries pis pi gT (G : {group gT}) :
pseries (rcons pis pi) G / pseries pis G = 'O_pi(G / pseries pis G).
Proof. by rewrite pseries_rcons quotient_pcore_mod. Qed.
Lemma pseries_norm2 pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \subset 'N(pseries pi1s G).
Proof. by rewrite gFsub_trans ?gFnorm. Qed.
Lemma pseries_sub_catr pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \subset pseries (pi1s ++ pi2s) G.
Proof.
elim: pi1s => //= pi1 pi1s /subset_trans; apply.
elim/last_ind: {pi1s pi2s}(_ ++ _) => [|pis pi IHpi]; first exact: sub1G.
rewrite -rcons_cons (pseries_rcons _ (pi1 :: pis)).
rewrite -sub_morphim_pre ?pseries_norm2 //.
apply: pcore_max; last by rewrite morphim_normal ?pseries_normal.
have: pi.-group (pseries (rcons pis pi) G / pseries pis G).
by rewrite quotient_pseries pcore_pgroup.
by apply: pnat_dvd; rewrite !card_quotient ?pseries_norm2 // indexgS.
Qed.
Lemma quotient_pseries2 pi1 pi2 gT (G : {group gT}) :
'O_{pi1, pi2}(G) / 'O_pi1(G) = 'O_pi2(G / 'O_pi1(G)).
Proof. by rewrite -pseries1 -quotient_pseries. Qed.
Lemma quotient_pseries_cat pi1s pi2s gT (G : {group gT}) :
pseries (pi1s ++ pi2s) G / pseries pi1s G
= pseries pi2s (G / pseries pi1s G).
Proof.
elim/last_ind: pi2s => [|pi2s pi IHpi]; first by rewrite cats0 trivg_quotient.
have psN := pseries_normal _ G; set K := pseries _ G.
case: (third_isom (pseries_sub_catl pi1s pi2s G) (psN _)) => //= f inj_f im_f.
have nH2H: pseries pi2s (G / K) <| pseries (pi1s ++ rcons pi2s pi) G / K.
rewrite -IHpi morphim_normal // -cats1 catA.
by apply/andP; rewrite pseries_sub_catl pseries_norm2.
apply: (quotient_inj nH2H).
by apply/andP; rewrite /= -cats1 pseries_sub_catl pseries_norm2.
rewrite /= quotient_pseries /= -IHpi -rcons_cat.
rewrite -[G / _ / _](morphim_invm inj_f) //= {2}im_f //.
rewrite -(@injmF [igFun of @pcore pi]) /= ?injm_invm ?im_f // -quotient_pseries.
by rewrite -im_f ?morphim_invm ?morphimS ?normal_sub.
Qed.
Lemma pseries_catl_id pi1s pi2s gT (G : {group gT}) :
pseries pi1s (pseries (pi1s ++ pi2s) G) = pseries pi1s G.
Proof.
elim/last_ind: pi1s => [//|pi1s pi IHpi] in pi2s *.
apply: (@quotient_inj _ (pseries_group pi1s G)).
- rewrite /= -(IHpi (pi :: pi2s)) cat_rcons /(_ <| _) pseries_norm2.
by rewrite -cats1 pseries_sub_catl.
- by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
rewrite /= cat_rcons -(IHpi (pi :: pi2s)) {1}quotient_pseries IHpi.
apply/eqP; rewrite quotient_pseries eqEsubset !pcore_max ?pcore_pgroup //=.
rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2.
by rewrite -cat_rcons pseries_sub_catl.
by rewrite gFnormal_trans ?quotient_normal ?gFnormal.
Qed.
Lemma pseries_char_catl pi1s pi2s gT (G : {group gT}) :
pseries pi1s G \char pseries (pi1s ++ pi2s) G.
Proof. by rewrite -(pseries_catl_id pi1s pi2s G) pseries_char. Qed.
Lemma pseries_catr_id pi1s pi2s gT (G : {group gT}) :
pseries pi2s (pseries (pi1s ++ pi2s) G) = pseries pi2s G.
Proof.
elim/last_ind: pi2s => [//|pi2s pi IHpi] in G *.
have Epis: pseries pi2s (pseries (pi1s ++ rcons pi2s pi) G) = pseries pi2s G.
by rewrite -cats1 catA -[RHS]IHpi -[LHS]IHpi /= [pseries (_ ++ _) _]pseries_catl_id.
apply: (@quotient_inj _ (pseries_group pi2s G)).
- by rewrite /= -Epis /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
- by rewrite /= /(_ <| _) pseries_norm2 -cats1 pseries_sub_catl.
rewrite /= -Epis {1}quotient_pseries Epis quotient_pseries.
apply/eqP; rewrite eqEsubset !pcore_max ?pcore_pgroup //=.
rewrite -quotient_pseries morphim_normal // /(_ <| _) pseries_norm2.
by rewrite pseries_sub_catr.
by rewrite gFnormal_trans ?morphim_normal ?gFnormal.
Qed.
Lemma pseries_char_catr pi1s pi2s gT (G : {group gT}) :
pseries pi2s G \char pseries (pi1s ++ pi2s) G.
Proof. by rewrite -(pseries_catr_id pi1s pi2s G) pseries_char. Qed.
Lemma pcore_modp pi gT (G H : {group gT}) :
H <| G -> pi.-group H -> pcore_mod G pi H = 'O_pi(G).
Proof.
move=> nsHG piH; have nHG := normal_norm nsHG; apply/eqP.
rewrite eqEsubset andbC -sub_morphim_pre ?(gFsub_trans, morphim_pcore) //=.
rewrite -[G in 'O_pi(G)](quotientGK nsHG) pcore_max //.
by rewrite -(pquotient_pgroup piH) ?subsetIl // cosetpreK pcore_pgroup.
by rewrite morphpre_normal ?gFnormal ?gFsub_trans ?morphim_sub.
Qed.
Lemma pquotient_pcore pi gT (G H : {group gT}) :
H <| G -> pi.-group H -> 'O_pi(G / H) = 'O_pi(G) / H.
Proof. by move=> nsHG piH; rewrite -quotient_pcore_mod pcore_modp. Qed.
Lemma trivg_pcore_quotient pi gT (G : {group gT}) : 'O_pi(G / 'O_pi(G)) = 1.
Proof. by rewrite pquotient_pcore ?gFnormal ?pcore_pgroup ?trivg_quotient. Qed.
Lemma pseries_rcons_id pis pi gT (G : {group gT}) :
pseries (rcons (rcons pis pi) pi) G = pseries (rcons pis pi) G.
Proof.
apply/eqP; rewrite -!cats1 eqEsubset pseries_sub_catl andbT -catA.
rewrite -(quotientSGK _ (pseries_sub_catl _ _ _)) ?pseries_norm2 //.
rewrite !quotient_pseries_cat -quotient_sub1 ?pseries_norm2 //.
by rewrite quotient_pseries_cat /= !pseries1 trivg_pcore_quotient.
Qed.
End MorphPcore.
Section EqPcore.
Variables gT : finGroupType.
Implicit Types (pi rho : nat_pred) (G H : {group gT}).
Lemma sub_in_pcore pi rho G :
{in \pi(G), {subset pi <= rho}} -> 'O_pi(G) \subset 'O_rho(G).
Proof.
move=> pi_sub_rho; rewrite pcore_max ?pcore_normal //.
apply: sub_in_pnat (pcore_pgroup _ _) => p.
by move/(piSg (pcore_sub _ _)); apply: pi_sub_rho.
Qed.
Lemma sub_pcore pi rho G : {subset pi <= rho} -> 'O_pi(G) \subset 'O_rho(G).
Proof. by move=> pi_sub_rho; apply: sub_in_pcore (in1W pi_sub_rho). Qed.
Lemma eq_in_pcore pi rho G : {in \pi(G), pi =i rho} -> 'O_pi(G) = 'O_rho(G).
Proof.
move=> eq_pi_rho; apply/eqP; rewrite eqEsubset.
by rewrite !sub_in_pcore // => p /eq_pi_rho->.
Qed.
Lemma eq_pcore pi rho G : pi =i rho -> 'O_pi(G) = 'O_rho(G).
Proof. by move=> eq_pi_rho; apply: eq_in_pcore (in1W eq_pi_rho). Qed.
Lemma pcoreNK pi G : 'O_pi^'^'(G) = 'O_pi(G).
Proof. by apply: eq_pcore; apply: negnK. Qed.
Lemma eq_p'core pi rho G : pi =i rho -> 'O_pi^'(G) = 'O_rho^'(G).
Proof. by move/eq_negn; apply: eq_pcore. Qed.
Lemma sdprod_Hall_p'coreP pi H G :
pi^'.-Hall(G) 'O_pi^'(G) -> reflect ('O_pi^'(G) ><| H = G) (pi.-Hall(G) H).
Proof. by rewrite -(pHallNK pi G H); apply: sdprod_Hall_pcoreP. Qed.
Lemma sdprod_p'core_HallP pi H G :
pi.-Hall(G) H -> reflect ('O_pi^'(G) ><| H = G) (pi^'.-Hall(G) 'O_pi^'(G)).
Proof. by rewrite -(pHallNK pi G H); apply: sdprod_pcore_HallP. Qed.
Lemma pcoreI pi rho G : 'O_[predI pi & rho](G) = 'O_pi('O_rho(G)).
Proof.
apply/eqP; rewrite eqEsubset !pcore_max //.
- rewrite /pgroup pnatI -!pgroupE.
by rewrite pcore_pgroup (pgroupS (pcore_sub pi _))// pcore_pgroup.
- by rewrite !gFnormal_trans.
- by apply: sub_pgroup (pcore_pgroup _ _) => p /andP[].
apply/andP; split; first by apply: sub_pcore => p /andP[].
by rewrite gFnorm_trans ?normsG ?gFsub.
Qed.
Lemma bigcap_p'core pi G :
G :&: \bigcap_(p < #|G|.+1 | (p : nat) \in pi) 'O_p^'(G) = 'O_pi^'(G).
Proof.
apply/eqP; rewrite eqEsubset subsetI pcore_sub pcore_max /=.
- by apply/bigcapsP=> p pi_p; apply: sub_pcore => r; apply: contraNneq => ->.
- apply/pgroupP=> q q_pr qGpi'; apply: contraL (eqxx q) => /= pi_q.
apply: (pgroupP (pcore_pgroup q^' G)) => //.
have qG: q %| #|G| by rewrite (dvdn_trans qGpi') // cardSg ?subsetIl.
have ltqG: q < #|G|.+1 by rewrite ltnS dvdn_leq.
rewrite (dvdn_trans qGpi') ?cardSg ?subIset //= orbC.
by rewrite (bigcap_inf (Ordinal ltqG)).
rewrite /normal subsetIl normsI ?normG // norms_bigcap //.
by apply/bigcapsP => p _; apply: gFnorm.
Qed.
Lemma coprime_pcoreC (rT : finGroupType) pi G (R : {group rT}) :
coprime #|'O_pi(G)| #|'O_pi^'(R)|.
Proof. exact: pnat_coprime (pcore_pgroup _ _) (pcore_pgroup _ _). Qed.
Lemma TI_pcoreC pi G H : 'O_pi(G) :&: 'O_pi^'(H) = 1.
Proof. by rewrite coprime_TIg ?coprime_pcoreC. Qed.
Lemma pcore_setI_normal pi G H : H <| G -> 'O_pi(G) :&: H = 'O_pi(H).
Proof.
move=> nsHG; apply/eqP; rewrite eqEsubset subsetI pcore_sub setIC.
rewrite !pcore_max ?(pgroupS (subsetIr H _)) ?pcore_pgroup ?gFnormal_trans //=.
by rewrite norm_normalI ?gFnorm_trans ?normsG ?normal_sub.
Qed.
End EqPcore.
Arguments sdprod_Hall_pcoreP {pi gT H G}.
Arguments sdprod_Hall_p'coreP {gT pi H G}.
Section Injm.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Hypothesis injf : 'injm f.
Implicit Types (A : {set aT}) (G H : {group aT}).
Lemma injm_pgroup pi A : A \subset D -> pi.-group (f @* A) = pi.-group A.
Proof. by move=> sAD; rewrite /pgroup card_injm. Qed.
Lemma injm_pelt pi x : x \in D -> pi.-elt (f x) = pi.-elt x.
Proof. by move=> Dx; rewrite /p_elt order_injm. Qed.
Lemma injm_pHall pi G H :
G \subset D -> H \subset D -> pi.-Hall(f @* G) (f @* H) = pi.-Hall(G) H.
Proof. by move=> sGD sGH; rewrite !pHallE injmSK ?card_injm. Qed.
Lemma injm_pcore pi G : G \subset D -> f @* 'O_pi(G) = 'O_pi(f @* G).
Proof. exact: injmF. Qed.
Lemma injm_pseries pis G :
G \subset D -> f @* pseries pis G = pseries pis (f @* G).
Proof. exact: injmF. Qed.
End Injm.
Section Isog.
Variables (aT rT : finGroupType) (G : {group aT}) (H : {group rT}).
Lemma isog_pgroup pi : G \isog H -> pi.-group G = pi.-group H.
Proof. by move=> isoGH; rewrite /pgroup (card_isog isoGH). Qed.
Lemma isog_pcore pi : G \isog H -> 'O_pi(G) \isog 'O_pi(H).
Proof. exact: gFisog. Qed.
Lemma isog_pseries pis : G \isog H -> pseries pis G \isog pseries pis H.
Proof. exact: gFisog. Qed.
End Isog.
|
InclusionExclusion.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.Algebra.BigOperators.Pi
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Module.BigOperators
/-!
# Inclusion-exclusion principle
This file proves several variants of the inclusion-exclusion principle.
The inclusion-exclusion principle says that the sum/integral of a function over a finite union of
sets can be calculated as the alternating sum over `n > 0` of the sum/integral of the function over
the intersection of `n` of the sets.
By taking complements, it also says that the sum/integral of a function over a finite intersection
of complements of sets can be calculated as the alternating sum over `n ≥ 0` of the sum/integral of
the function over the intersection of `n` of the sets.
By taking the function to be constant `1`, we instead get a result about the cardinality/measure of
the sets.
## Main declarations
Per the above explanation, this file contains the following variants of inclusion-exclusion:
* `Finset.inclusion_exclusion_sum_biUnion`: Sum of a function over a finite union of sets
* `Finset.inclusion_exclusion_card_biUnion`: Cardinality of a finite union of sets
* `Finset.inclusion_exclusion_sum_inf_compl`: Sum of a function over a finite intersection of
complements of sets
* `Finset.inclusion_exclusion_card_inf_compl`: Cardinality of a finite intersection of
complements of sets
See also `MeasureTheory.integral_biUnion_eq_sum_powerset` for the version with integrals, and
`MeasureTheory.measureReal_biUnion_eq_sum_powerset` for the version with measures.
## TODO
* Prove that truncating the series alternatively gives an upper/lower bound to the true value.
-/
assert_not_exists Field
namespace Finset
variable {ι α G : Type*} [AddCommGroup G] {s : Finset ι}
lemma prod_indicator_biUnion_sub_indicator (hs : s.Nonempty) (S : ι → Set α) (a : α) :
∏ i ∈ s, (Set.indicator (⋃ i ∈ s, S i) 1 a - Set.indicator (S i) 1 a) = (0 : ℤ) := by
by_cases ha : a ∈ ⋃ i ∈ s, S i
· have ha' := ha
simp only [Set.mem_iUnion, exists_prop] at ha
obtain ⟨i, hi, ha⟩ := ha
apply prod_eq_zero hi (by simp [ha, ha'])
· obtain ⟨i, hi⟩ := hs
have ha : a ∉ S i := by aesop
exact prod_eq_zero hi <| by simp [*, -coe_biUnion]
/-- **Inclusion-exclusion principle**, indicator version over a finite union of sets. -/
lemma indicator_biUnion_eq_sum_powerset (s : Finset ι) (S : ι → Set α) (f : α → G) (a : α) :
Set.indicator (⋃ i ∈ s, S i) f a = ∑ t ∈ s.powerset with t.Nonempty,
(-1) ^ (#t + 1) • Set.indicator (⋂ i ∈ t, S i) f a := by
classical
by_cases ha : a ∈ ⋃ i ∈ s, S i; swap
· simp only [ha, not_false_eq_true, Set.indicator_of_notMem, Int.reduceNeg, pow_succ, mul_neg,
mul_one, neg_smul]
symm
apply sum_eq_zero
simp only [Int.reduceNeg, neg_eq_zero, mem_filter, mem_powerset, and_imp]
intro t hts ht
rw [Set.indicator_of_notMem]
· simp
· contrapose! ha
simp only [Set.mem_iInter] at ha
rcases ht with ⟨i, hi⟩
simp only [Set.mem_iUnion, exists_prop]
exact ⟨i, hts hi, ha _ hi⟩
rw [← sub_eq_zero]
calc
Set.indicator (⋃ i ∈ s, S i) f a - ∑ t ∈ s.powerset with t.Nonempty,
(-1) ^ (#t + 1) • Set.indicator (⋂ i ∈ t.1, S i) f a
_ = ∑ t ∈ s.powerset with t.Nonempty, (-1) ^ #t • Set.indicator (⋂ i ∈ t, S i) f a +
∑ t ∈ s.powerset with ¬ t.Nonempty, (-1) ^ #t • Set.indicator (⋂ i ∈ t, S i) f a := by
simp [sub_eq_neg_add, ← sum_neg_distrib, filter_eq', pow_succ, ha]
_ = ∑ t ∈ s.powerset, (-1) ^ #t • Set.indicator (⋂ i ∈ t, S i) f a := by
rw [sum_filter_add_sum_filter_not]
_ = (∏ i ∈ s, (1 - Set.indicator (S i) 1 a : ℤ)) • f a := by
simp only [Int.reduceNeg, prod_sub, prod_const_one, mul_one, sum_smul]
congr! 1 with t
simp only [prod_const_one, prod_indicator_apply]
simp [Set.indicator]
_ = 0 := by
have : Set.indicator (⋃ i ∈ s, S i) 1 a = (1 : ℤ) := Set.indicator_of_mem ha 1
rw [← this, prod_indicator_biUnion_sub_indicator, zero_smul]
simp only [Set.mem_iUnion, exists_prop] at ha
rcases ha with ⟨i, hi, -⟩
exact ⟨i, hi⟩
variable [DecidableEq α]
lemma prod_indicator_biUnion_finset_sub_indicator (hs : s.Nonempty) (S : ι → Finset α) (a : α) :
∏ i ∈ s, (Set.indicator (s.biUnion S) 1 a - Set.indicator (S i) 1 a) = (0 : ℤ) := by
convert prod_indicator_biUnion_sub_indicator hs (fun i ↦ S i) a
simp
/-- **Inclusion-exclusion principle** for the sum of a function over a union.
The sum of a function `f` over the union of the `S i` over `i ∈ s` is the alternating sum of the
sums of `f` over the intersections of the `S i`. -/
theorem inclusion_exclusion_sum_biUnion (s : Finset ι) (S : ι → Finset α) (f : α → G) :
∑ a ∈ s.biUnion S, f a = ∑ t : s.powerset.filter (·.Nonempty),
(-1) ^ (#t.1 + 1) • ∑ a ∈ t.1.inf' (mem_filter.1 t.2).2 S, f a := by
classical
rw [← sub_eq_zero]
calc
∑ a ∈ s.biUnion S, f a - ∑ t : s.powerset.filter (·.Nonempty),
(-1) ^ (#t.1 + 1) • ∑ a ∈ t.1.inf' (mem_filter.1 t.2).2 S, f a
= ∑ t : s.powerset.filter (·.Nonempty),
(-1) ^ #t.1 • ∑ a ∈ t.1.inf' (mem_filter.1 t.2).2 S, f a +
∑ t ∈ s.powerset.filter (¬ ·.Nonempty), (-1) ^ #t • ∑ a ∈ s.biUnion S, f a := by
simp [sub_eq_neg_add, ← sum_neg_distrib, filter_eq', pow_succ]
_ = ∑ t ∈ s.powerset, (-1) ^ #t •
if ht : t.Nonempty then ∑ a ∈ t.inf' ht S, f a else ∑ a ∈ s.biUnion S, f a := by
rw [← sum_attach (filter ..)]; simp [sum_dite]
_ = ∑ a ∈ s.biUnion S, (∏ i ∈ s, (1 - Set.indicator (S i) 1 a : ℤ)) • f a := by
simp only [Int.reduceNeg, prod_sub, sum_comm (s := s.biUnion S), sum_smul, mul_assoc]
congr! with t
split_ifs with ht
· obtain ⟨i, hi⟩ := ht
simp only [prod_const_one, prod_indicator_apply]
simp only [smul_sum, Set.indicator, Set.mem_iInter, mem_coe, Pi.one_apply, mul_ite, mul_one,
mul_zero, ite_smul, zero_smul, sum_ite, not_forall, sum_const_zero, add_zero]
congr
aesop
· obtain rfl := not_nonempty_iff_eq_empty.1 ht
simp
_ = ∑ a ∈ s.biUnion S, (∏ i ∈ s,
(Set.indicator (s.biUnion S) 1 a - Set.indicator (S i) 1 a) : ℤ) • f a := by
congr! with t; rw [Set.indicator_of_mem ‹_›, Pi.one_apply]
_ = 0 := by
obtain rfl | hs := s.eq_empty_or_nonempty <;>
simp [-coe_biUnion, prod_indicator_biUnion_finset_sub_indicator, *]
/-- **Inclusion-exclusion principle** for the cardinality of a union.
The cardinality of the union of the `S i` over `i ∈ s` is the alternating sum of the cardinalities
of the intersections of the `S i`. -/
theorem inclusion_exclusion_card_biUnion (s : Finset ι) (S : ι → Finset α) :
#(s.biUnion S) = ∑ t : s.powerset.filter (·.Nonempty),
(-1 : ℤ) ^ (#t.1 + 1) * #(t.1.inf' (mem_filter.1 t.2).2 S) := by
simpa using inclusion_exclusion_sum_biUnion (G := ℤ) s S (f := 1)
variable [Fintype α]
/-- **Inclusion-exclusion principle** for the sum of a function over an intersection of complements.
The sum of a function `f` over the intersection of the complements of the `S i` over `i ∈ s` is the
alternating sum of the sums of `f` over the intersections of the `S i`. -/
theorem inclusion_exclusion_sum_inf_compl (s : Finset ι) (S : ι → Finset α) (f : α → G) :
∑ a ∈ s.inf fun i ↦ (S i)ᶜ, f a = ∑ t ∈ s.powerset, (-1) ^ #t • ∑ a ∈ t.inf S, f a := by
classical
calc
∑ a ∈ s.inf fun i ↦ (S i)ᶜ, f a
= ∑ a, f a - ∑ a ∈ s.biUnion S, f a := by
rw [← Finset.compl_sup, sup_eq_biUnion, eq_sub_iff_add_eq, sum_compl_add_sum]
_ = ∑ t ∈ s.powerset.filter (¬ ·.Nonempty), (-1) ^ #t • ∑ a ∈ t.inf S, f a
+ ∑ t ∈ s.powerset.filter (·.Nonempty), (-1) ^ #t • ∑ a ∈ t.inf S, f a := by
simp [← sum_attach (filter ..), inclusion_exclusion_sum_biUnion, inf'_eq_inf, filter_eq',
sub_eq_add_neg, pow_succ]
_ = ∑ t ∈ s.powerset, (-1) ^ #t • ∑ a ∈ t.inf S, f a := sum_filter_not_add_sum_filter ..
/-- **Inclusion-exclusion principle** for the cardinality of an intersection of complements.
The cardinality of the intersection of the complements of the `S i` over `i ∈ s` is the
alternating sum of the cardinalities of the intersections of the `S i`. -/
theorem inclusion_exclusion_card_inf_compl (s : Finset ι) (S : ι → Finset α) :
#(s.inf fun i ↦ (S i)ᶜ) = ∑ t ∈ s.powerset, (-1 : ℤ) ^ #t * #(t.inf S) := by
simpa using inclusion_exclusion_sum_inf_compl (G := ℤ) s S (f := 1)
end Finset
|
ChainOfDivisors.lean
|
/-
Copyright (c) 2021 Paul Lezeau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Paul Lezeau
-/
import Mathlib.Algebra.GCDMonoid.Basic
import Mathlib.Algebra.IsPrimePow
import Mathlib.RingTheory.UniqueFactorizationDomain.Multiplicity
import Mathlib.Order.Atoms
import Mathlib.Order.Hom.Bounded
/-!
# Chains of divisors
The results in this file show that in the monoid `Associates M` of a `UniqueFactorizationMonoid`
`M`, an element `a` is an n-th prime power iff its set of divisors is a strictly increasing chain
of length `n + 1`, meaning that we can find a strictly increasing bijection between `Fin (n + 1)`
and the set of factors of `a`.
## Main results
- `DivisorChain.exists_chain_of_prime_pow` : existence of a chain for prime powers.
- `DivisorChain.is_prime_pow_of_has_chain` : elements that have a chain are prime powers.
- `multiplicity_prime_eq_multiplicity_image_by_factor_orderIso` : if there is a
monotone bijection `d` between the set of factors of `a : Associates M` and the set of factors of
`b : Associates N` then for any prime `p ∣ a`, `multiplicity p a = multiplicity (d p) b`.
- `multiplicity_eq_multiplicity_factor_dvd_iso_of_mem_normalizedFactors` : if there is a bijection
between the set of factors of `a : M` and `b : N` then for any prime `p ∣ a`,
`multiplicity p a = multiplicity (d p) b`
## TODO
- Create a structure for chains of divisors.
- Simplify proof of `mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors` using
`mem_normalizedFactors_factor_order_iso_of_mem_normalizedFactors` or vice versa.
-/
assert_not_exists Field
variable {M : Type*} [CancelCommMonoidWithZero M]
theorem Associates.isAtom_iff {p : Associates M} (h₁ : p ≠ 0) : IsAtom p ↔ Irreducible p :=
⟨fun hp =>
⟨by simpa only [Associates.isUnit_iff_eq_one] using hp.1, fun a b h =>
(hp.le_iff.mp ⟨_, h⟩).casesOn (fun ha => Or.inl (a.isUnit_iff_eq_one.mpr ha)) fun ha =>
Or.inr
(show IsUnit b by
rw [ha] at h
apply isUnit_of_associated_mul (show Associated (p * b) p by conv_rhs => rw [h]) h₁)⟩,
fun hp =>
⟨by simpa only [Associates.isUnit_iff_eq_one, Associates.bot_eq_one] using hp.1,
fun b ⟨⟨a, hab⟩, hb⟩ =>
(hp.isUnit_or_isUnit hab).casesOn
(fun hb => show b = ⊥ by rwa [Associates.isUnit_iff_eq_one, ← Associates.bot_eq_one] at hb)
fun ha =>
absurd
(show p ∣ b from
⟨(ha.unit⁻¹ : Units _), by rw [hab, mul_assoc, IsUnit.mul_val_inv ha, mul_one]⟩)
hb⟩⟩
open UniqueFactorizationMonoid Irreducible Associates
namespace DivisorChain
theorem exists_chain_of_prime_pow {p : Associates M} {n : ℕ} (hn : n ≠ 0) (hp : Prime p) :
∃ c : Fin (n + 1) → Associates M,
c 1 = p ∧ StrictMono c ∧ ∀ {r : Associates M}, r ≤ p ^ n ↔ ∃ i, r = c i := by
refine ⟨fun i => p ^ (i : ℕ), ?_, fun n m h => ?_, @fun y => ⟨fun h => ?_, ?_⟩⟩
· dsimp only
rw [Fin.coe_ofNat_eq_mod, Nat.mod_eq_of_lt, pow_one]
exact Nat.lt_succ_of_le (Nat.one_le_iff_ne_zero.mpr hn)
· exact Associates.dvdNotUnit_iff_lt.mp
⟨pow_ne_zero n hp.ne_zero, p ^ (m - n : ℕ),
not_isUnit_of_not_isUnit_dvd hp.not_unit (dvd_pow dvd_rfl (Nat.sub_pos_of_lt h).ne'),
(pow_mul_pow_sub p h.le).symm⟩
· obtain ⟨i, i_le, hi⟩ := (dvd_prime_pow hp n).1 h
rw [associated_iff_eq] at hi
exact ⟨⟨i, Nat.lt_succ_of_le i_le⟩, hi⟩
· rintro ⟨i, rfl⟩
exact ⟨p ^ (n - i : ℕ), (pow_mul_pow_sub p (Nat.succ_le_succ_iff.mp i.2)).symm⟩
theorem element_of_chain_not_isUnit_of_index_ne_zero {n : ℕ} {i : Fin (n + 1)} (i_pos : i ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) : ¬IsUnit (c i) :=
DvdNotUnit.not_unit
(Associates.dvdNotUnit_iff_lt.2
(h₁ <| show (0 : Fin (n + 1)) < i from Fin.pos_iff_ne_zero.mpr i_pos))
theorem first_of_chain_isUnit {q : Associates M} {n : ℕ} {c : Fin (n + 1) → Associates M}
(h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) : IsUnit (c 0) := by
obtain ⟨i, hr⟩ := h₂.mp Associates.one_le
rw [Associates.isUnit_iff_eq_one, ← Associates.le_one_iff, hr]
exact h₁.monotone (Fin.zero_le i)
/-- The second element of a chain is irreducible. -/
theorem second_of_chain_is_irreducible {q : Associates M} {n : ℕ} (hn : n ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i)
(hq : q ≠ 0) : Irreducible (c 1) := by
rcases n with - | n; · contradiction
refine (Associates.isAtom_iff (ne_zero_of_dvd_ne_zero hq (h₂.2 ⟨1, rfl⟩))).mp ⟨?_, fun b hb => ?_⟩
· exact ne_bot_of_gt (h₁ (show (0 : Fin (n + 2)) < 1 from Fin.one_pos))
obtain ⟨⟨i, hi⟩, rfl⟩ := h₂.1 (hb.le.trans (h₂.2 ⟨1, rfl⟩))
cases i
· exact (Associates.isUnit_iff_eq_one _).mp (first_of_chain_isUnit h₁ @h₂)
· simpa [Fin.lt_iff_val_lt_val] using h₁.lt_iff_lt.mp hb
theorem eq_second_of_chain_of_prime_dvd {p q r : Associates M} {n : ℕ} (hn : n ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c)
(h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hp : Prime p) (hr : r ∣ q) (hp' : p ∣ r) :
p = c 1 := by
rcases n with - | n
· contradiction
obtain ⟨i, rfl⟩ := h₂.1 (dvd_trans hp' hr)
refine congr_arg c (eq_of_le_of_not_lt' ?_ fun hi => ?_)
· rw [Fin.le_iff_val_le_val, Fin.val_one, Nat.succ_le_iff, ← Fin.val_zero (n.succ + 1), ←
Fin.lt_iff_val_lt_val, Fin.pos_iff_ne_zero]
rintro rfl
exact hp.not_unit (first_of_chain_isUnit h₁ @h₂)
obtain rfl | ⟨j, rfl⟩ := i.eq_zero_or_eq_succ
· cases hi
refine
not_irreducible_of_not_unit_dvdNotUnit
(DvdNotUnit.not_unit
(Associates.dvdNotUnit_iff_lt.2 (h₁ (show (0 : Fin (n + 2)) < j.castSucc from ?_))))
?_ hp.irreducible
· simpa using Fin.lt_def.mp hi
· refine Associates.dvdNotUnit_iff_lt.2 (h₁ ?_)
simpa only [Fin.coe_eq_castSucc] using Fin.lt_succ
theorem card_subset_divisors_le_length_of_chain {q : Associates M} {n : ℕ}
{c : Fin (n + 1) → Associates M} (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i) {m : Finset (Associates M)}
(hm : ∀ r, r ∈ m → r ≤ q) : m.card ≤ n + 1 := by
classical
have mem_image : ∀ r : Associates M, r ≤ q → r ∈ Finset.univ.image c := by
intro r hr
obtain ⟨i, hi⟩ := h₂.1 hr
exact Finset.mem_image.2 ⟨i, Finset.mem_univ _, hi.symm⟩
rw [← Finset.card_fin (n + 1)]
exact (Finset.card_le_card fun x hx => mem_image x <| hm x hx).trans Finset.card_image_le
variable [UniqueFactorizationMonoid M]
theorem element_of_chain_eq_pow_second_of_chain {q r : Associates M} {n : ℕ} (hn : n ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c) (h₂ : ∀ {r}, r ≤ q ↔ ∃ i, r = c i)
(hr : r ∣ q) (hq : q ≠ 0) : ∃ i : Fin (n + 1), r = c 1 ^ (i : ℕ) := by
classical
let i := Multiset.card (normalizedFactors r)
have hi : normalizedFactors r = Multiset.replicate i (c 1) := by
apply Multiset.eq_replicate_of_mem
intro b hb
refine
eq_second_of_chain_of_prime_dvd hn h₁ (@fun r' => h₂) (prime_of_normalized_factor b hb) hr
(dvd_of_mem_normalizedFactors hb)
have H : r = c 1 ^ i := by
have := UniqueFactorizationMonoid.prod_normalizedFactors (ne_zero_of_dvd_ne_zero hq hr)
rw [associated_iff_eq, hi, Multiset.prod_replicate] at this
rw [this]
refine ⟨⟨i, ?_⟩, H⟩
have : (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card = i + 1 := by
conv_rhs => rw [← Finset.card_fin (i + 1)]
cases n
· contradiction
rw [Finset.card_image_iff]
refine Set.injOn_of_injective (fun m m' h => Fin.ext ?_)
refine
pow_injective_of_not_isUnit (element_of_chain_not_isUnit_of_index_ne_zero (by simp) h₁) ?_ h
exact Irreducible.ne_zero (second_of_chain_is_irreducible hn h₁ (@h₂) hq)
suffices H' : ∀ r ∈ Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ), r ≤ q by
simp only [← Nat.succ_le_iff, Nat.succ_eq_add_one, ← this]
apply card_subset_divisors_le_length_of_chain (@h₂) H'
simp only [Finset.mem_image]
rintro r ⟨a, _, rfl⟩
refine dvd_trans ?_ hr
use c 1 ^ (i - (a : ℕ))
rw [pow_mul_pow_sub (c 1)]
· exact H
· exact Nat.succ_le_succ_iff.mp a.2
open Fin.NatCast in -- TODO: should this be refactored to avoid needing the coercion?
theorem eq_pow_second_of_chain_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c)
(h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : q = c 1 ^ n := by
classical
obtain ⟨i, hi'⟩ := element_of_chain_eq_pow_second_of_chain hn h₁ (@fun r => h₂) (dvd_refl q) hq
convert hi'
refine (Nat.lt_succ_iff.1 i.prop).antisymm' (Nat.le_of_succ_le_succ ?_)
calc
n + 1 = (Finset.univ : Finset (Fin (n + 1))).card := (Finset.card_fin _).symm
_ = (Finset.univ.image c).card := (Finset.card_image_iff.mpr h₁.injective.injOn).symm
_ ≤ (Finset.univ.image fun m : Fin (i + 1) => c 1 ^ (m : ℕ)).card :=
(Finset.card_le_card ?_)
_ ≤ (Finset.univ : Finset (Fin (i + 1))).card := Finset.card_image_le
_ = i + 1 := Finset.card_fin _
intro r hr
obtain ⟨j, -, rfl⟩ := Finset.mem_image.1 hr
have := h₂.2 ⟨j, rfl⟩
rw [hi'] at this
have h := (dvd_prime_pow (show Prime (c 1) from ?_) i).1 this
· rcases h with ⟨u, hu, hu'⟩
refine Finset.mem_image.mpr ⟨u, Finset.mem_univ _, ?_⟩
rw [associated_iff_eq] at hu'
rw [Fin.val_cast_of_lt (Nat.lt_succ_of_le hu), hu']
· rw [← irreducible_iff_prime]
exact second_of_chain_is_irreducible hn h₁ (@h₂) hq
theorem isPrimePow_of_has_chain {q : Associates M} {n : ℕ} (hn : n ≠ 0)
{c : Fin (n + 1) → Associates M} (h₁ : StrictMono c)
(h₂ : ∀ {r : Associates M}, r ≤ q ↔ ∃ i, r = c i) (hq : q ≠ 0) : IsPrimePow q :=
⟨c 1, n, irreducible_iff_prime.mp (second_of_chain_is_irreducible hn h₁ (@h₂) hq),
zero_lt_iff.mpr hn, (eq_pow_second_of_chain_of_has_chain hn h₁ (@h₂) hq).symm⟩
end DivisorChain
variable {N : Type*} [CancelCommMonoidWithZero N]
theorem factor_orderIso_map_one_eq_bot {m : Associates M} {n : Associates N}
(d : { l : Associates M // l ≤ m } ≃o { l : Associates N // l ≤ n }) :
(d ⟨1, one_dvd m⟩ : Associates N) = 1 := by
letI : OrderBot { l : Associates M // l ≤ m } := Subtype.orderBot bot_le
letI : OrderBot { l : Associates N // l ≤ n } := Subtype.orderBot bot_le
simp only [← Associates.bot_eq_one, Subtype.mk_bot, bot_le, Subtype.coe_eq_bot_iff]
letI : BotHomClass ({ l // l ≤ m } ≃o { l // l ≤ n }) _ _ := OrderIsoClass.toBotHomClass
exact map_bot d
theorem coe_factor_orderIso_map_eq_one_iff {m u : Associates M} {n : Associates N} (hu' : u ≤ m)
(d : Set.Iic m ≃o Set.Iic n) : (d ⟨u, hu'⟩ : Associates N) = 1 ↔ u = 1 :=
⟨fun hu => by
rw [show u = (d.symm ⟨d ⟨u, hu'⟩, (d ⟨u, hu'⟩).prop⟩) by
simp only [Subtype.coe_eta, OrderIso.symm_apply_apply, Subtype.coe_mk]]
conv_rhs => rw [← factor_orderIso_map_one_eq_bot d.symm]
congr, fun hu => by
simp_rw [hu]
conv_rhs => rw [← factor_orderIso_map_one_eq_bot d]
rfl⟩
section
variable [UniqueFactorizationMonoid N] [UniqueFactorizationMonoid M]
open DivisorChain
theorem pow_image_of_prime_by_factor_orderIso_dvd
{m p : Associates M} {n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m)
(d : Set.Iic m ≃o Set.Iic n) {s : ℕ} (hs' : p ^ s ≤ m) :
(d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ^ s ≤ n := by
by_cases hs : s = 0
· simp [← Associates.bot_eq_one, hs]
suffices (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ^ s =
(d ⟨p ^ s, hs'⟩) by
rw [this]
apply Subtype.prop (d ⟨p ^ s, hs'⟩)
obtain ⟨c₁, rfl, hc₁', hc₁''⟩ := exists_chain_of_prime_pow hs (prime_of_normalized_factor p hp)
let c₂ : Fin (s + 1) → Associates N := fun t => d ⟨c₁ t, le_trans (hc₁''.2 ⟨t, by simp⟩) hs'⟩
have c₂_def : ∀ t, c₂ t = d ⟨c₁ t, _⟩ := fun t => rfl
rw [← c₂_def]
refine (eq_pow_second_of_chain_of_has_chain hs (fun t u h => ?_)
(@fun r => ⟨@fun hr => ?_, ?_⟩) ?_).symm
· rw [c₂_def, c₂_def, Subtype.coe_lt_coe, d.lt_iff_lt, Subtype.mk_lt_mk, hc₁'.lt_iff_lt]
exact h
· have : r ≤ n := hr.trans (d ⟨c₁ 1 ^ s, _⟩).2
suffices d.symm ⟨r, this⟩ ≤ ⟨c₁ 1 ^ s, hs'⟩ by
obtain ⟨i, hi⟩ := hc₁''.1 this
use i
simp only [c₂_def, ← hi, d.apply_symm_apply, Subtype.coe_eta, Subtype.coe_mk]
conv_rhs => rw [← d.symm_apply_apply ⟨c₁ 1 ^ s, hs'⟩]
rw [d.symm.le_iff_le]
simpa only [← Subtype.coe_le_coe, Subtype.coe_mk] using hr
· rintro ⟨i, hr⟩
rw [hr, c₂_def, Subtype.coe_le_coe, d.le_iff_le]
simpa [Subtype.mk_le_mk] using hc₁''.2 ⟨i, rfl⟩
exact ne_zero_of_dvd_ne_zero hn (Subtype.prop (d ⟨c₁ 1 ^ s, _⟩))
theorem map_prime_of_factor_orderIso {m p : Associates M} {n : Associates N} (hn : n ≠ 0)
(hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) :
Prime (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) := by
rw [← irreducible_iff_prime]
refine (Associates.isAtom_iff <|
ne_zero_of_dvd_ne_zero hn (d ⟨p, _⟩).prop).mp ⟨?_, fun b hb => ?_⟩
· rw [Ne, ← Associates.isUnit_iff_eq_bot, Associates.isUnit_iff_eq_one,
coe_factor_orderIso_map_eq_one_iff _ d]
rintro rfl
exact (prime_of_normalized_factor 1 hp).not_unit isUnit_one
· obtain ⟨x, hx⟩ :=
d.surjective ⟨b, le_trans (le_of_lt hb) (d ⟨p, dvd_of_mem_normalizedFactors hp⟩).prop⟩
rw [← Subtype.coe_mk b _, ← hx] at hb
letI : OrderBot { l : Associates M // l ≤ m } := Subtype.orderBot bot_le
letI : OrderBot { l : Associates N // l ≤ n } := Subtype.orderBot bot_le
suffices x = ⊥ by
rw [this, OrderIso.map_bot d] at hx
refine (Subtype.mk_eq_bot_iff ?_ _).mp hx.symm
simp
obtain ⟨a, ha⟩ := x
rw [Subtype.mk_eq_bot_iff]
· exact
((Associates.isAtom_iff <| Prime.ne_zero <| prime_of_normalized_factor p hp).mpr <|
irreducible_of_normalized_factor p hp).right
a (Subtype.mk_lt_mk.mp <| d.lt_iff_lt.mp hb)
simp
theorem mem_normalizedFactors_factor_orderIso_of_mem_normalizedFactors {m p : Associates M}
{n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) :
(d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : Associates N) ∈ normalizedFactors n := by
obtain ⟨q, hq, hq'⟩ :=
exists_mem_normalizedFactors_of_dvd hn (map_prime_of_factor_orderIso hn hp d).irreducible
(d ⟨p, dvd_of_mem_normalizedFactors hp⟩).prop
rw [associated_iff_eq] at hq'
rwa [hq']
theorem emultiplicity_prime_le_emultiplicity_image_by_factor_orderIso {m p : Associates M}
{n : Associates N} (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) :
emultiplicity p m ≤ emultiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n := by
by_cases hn : n = 0
· simp [hn]
by_cases hm : m = 0
· simp [hm] at hp
rw [FiniteMultiplicity.of_prime_left (prime_of_normalized_factor p hp) hm
|>.emultiplicity_eq_multiplicity, ← pow_dvd_iff_le_emultiplicity]
apply pow_image_of_prime_by_factor_orderIso_dvd hn hp d (pow_multiplicity_dvd ..)
theorem emultiplicity_prime_eq_emultiplicity_image_by_factor_orderIso {m p : Associates M}
{n : Associates N} (hn : n ≠ 0) (hp : p ∈ normalizedFactors m) (d : Set.Iic m ≃o Set.Iic n) :
emultiplicity p m = emultiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n := by
refine le_antisymm (emultiplicity_prime_le_emultiplicity_image_by_factor_orderIso hp d) ?_
suffices emultiplicity (↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩)) n ≤
emultiplicity (↑(d.symm (d ⟨p, dvd_of_mem_normalizedFactors hp⟩))) m by
rw [d.symm_apply_apply ⟨p, dvd_of_mem_normalizedFactors hp⟩, Subtype.coe_mk] at this
exact this
letI := Classical.decEq (Associates N)
simpa only [Subtype.coe_eta] using
emultiplicity_prime_le_emultiplicity_image_by_factor_orderIso
(mem_normalizedFactors_factor_orderIso_of_mem_normalizedFactors hn hp d) d.symm
end
variable [Subsingleton Mˣ] [Subsingleton Nˣ]
/-- The order isomorphism between the factors of `mk m` and the factors of `mk n` induced by a
bijection between the factors of `m` and the factors of `n` that preserves `∣`. -/
@[simps]
def mkFactorOrderIsoOfFactorDvdEquiv {m : M} {n : N} {d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }}
(hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ (l' : M)) :
Set.Iic (Associates.mk m) ≃o Set.Iic (Associates.mk n) where
toFun l :=
⟨Associates.mk
(d
⟨associatesEquivOfUniqueUnits ↑l, by
obtain ⟨x, hx⟩ := l
rw [Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_dvd_iff]
exact hx⟩),
mk_le_mk_iff_dvd.mpr (Subtype.prop (d ⟨associatesEquivOfUniqueUnits ↑l, _⟩))⟩
invFun l :=
⟨Associates.mk
(d.symm
⟨associatesEquivOfUniqueUnits ↑l, by
obtain ⟨x, hx⟩ := l
rw [Subtype.coe_mk, associatesEquivOfUniqueUnits_apply, out_dvd_iff]
exact hx⟩),
mk_le_mk_iff_dvd.mpr (Subtype.prop (d.symm ⟨associatesEquivOfUniqueUnits ↑l, _⟩))⟩
left_inv := fun ⟨l, hl⟩ => by
simp only [Subtype.coe_eta, Equiv.symm_apply_apply, Subtype.coe_mk,
associatesEquivOfUniqueUnits_apply, mk_out, out_mk, normalize_eq]
right_inv := fun ⟨l, hl⟩ => by
simp only [Subtype.coe_eta, Equiv.apply_symm_apply, Subtype.coe_mk,
associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq, mk_out]
map_rel_iff' := by
rintro ⟨a, ha⟩ ⟨b, hb⟩
simp only [Equiv.coe_fn_mk, Subtype.mk_le_mk, Associates.mk_le_mk_iff_dvd, hd,
associatesEquivOfUniqueUnits_apply, out_dvd_iff, mk_out]
variable [UniqueFactorizationMonoid M] [UniqueFactorizationMonoid N]
theorem mem_normalizedFactors_factor_dvd_iso_of_mem_normalizedFactors {m p : M} {n : N} (hm : m ≠ 0)
(hn : n ≠ 0) (hp : p ∈ normalizedFactors m) {d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }}
(hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ (l' : M)) :
↑(d ⟨p, dvd_of_mem_normalizedFactors hp⟩) ∈ normalizedFactors n := by
suffices
Prime (d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by
simp [dvd_of_mem_normalizedFactors hp]⟩ : N) by
simp only [associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq,
associatesEquivOfUniqueUnits_symm_apply] at this
obtain ⟨q, hq, hq'⟩ :=
exists_mem_normalizedFactors_of_dvd hn this.irreducible
(d ⟨p, by apply dvd_of_mem_normalizedFactors; convert hp⟩).prop
rwa [associated_iff_eq.mp hq']
have :
Associates.mk
(d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by
simp only [dvd_of_mem_normalizedFactors hp, associatesEquivOfUniqueUnits_apply,
out_mk, normalize_eq, associatesEquivOfUniqueUnits_symm_apply]⟩ : N) =
↑(mkFactorOrderIsoOfFactorDvdEquiv hd
⟨associatesEquivOfUniqueUnits.symm p, by
simp only [associatesEquivOfUniqueUnits_symm_apply]
exact mk_dvd_mk.mpr (dvd_of_mem_normalizedFactors hp)⟩) := by
rw [mkFactorOrderIsoOfFactorDvdEquiv_apply_coe]
rw [← Associates.prime_mk, this]
letI := Classical.decEq (Associates M)
refine map_prime_of_factor_orderIso (mk_ne_zero.mpr hn) ?_ _
obtain ⟨q, hq, hq'⟩ :=
exists_mem_normalizedFactors_of_dvd (mk_ne_zero.mpr hm)
(prime_mk.mpr (prime_of_normalized_factor p (by convert hp))).irreducible
(mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp))
simpa only [associated_iff_eq.mp hq', associatesEquivOfUniqueUnits_symm_apply] using hq
theorem emultiplicity_factor_dvd_iso_eq_emultiplicity_of_mem_normalizedFactors {m p : M} {n : N}
(hm : m ≠ 0) (hn : n ≠ 0) (hp : p ∈ normalizedFactors m)
{d : { l : M // l ∣ m } ≃ { l : N // l ∣ n }} (hd : ∀ l l', (d l : N) ∣ d l' ↔ (l : M) ∣ l') :
emultiplicity (d ⟨p, dvd_of_mem_normalizedFactors hp⟩ : N) n = emultiplicity p m := by
apply Eq.symm
suffices emultiplicity (Associates.mk p) (Associates.mk m) = emultiplicity (Associates.mk
↑(d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by
simp [dvd_of_mem_normalizedFactors hp]⟩)) (Associates.mk n) by
simpa only [emultiplicity_mk_eq_emultiplicity, associatesEquivOfUniqueUnits_symm_apply,
associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq] using this
have : Associates.mk (d ⟨associatesEquivOfUniqueUnits (associatesEquivOfUniqueUnits.symm p), by
simp only [dvd_of_mem_normalizedFactors hp, associatesEquivOfUniqueUnits_symm_apply,
associatesEquivOfUniqueUnits_apply, out_mk, normalize_eq]⟩ : N) =
↑(mkFactorOrderIsoOfFactorDvdEquiv hd ⟨associatesEquivOfUniqueUnits.symm p, by
rw [associatesEquivOfUniqueUnits_symm_apply]
exact mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp)⟩) := by
rw [mkFactorOrderIsoOfFactorDvdEquiv_apply_coe]
rw [this]
refine
emultiplicity_prime_eq_emultiplicity_image_by_factor_orderIso (mk_ne_zero.mpr hn) ?_
(mkFactorOrderIsoOfFactorDvdEquiv hd)
obtain ⟨q, hq, hq'⟩ :=
exists_mem_normalizedFactors_of_dvd (mk_ne_zero.mpr hm)
(prime_mk.mpr (prime_of_normalized_factor p hp)).irreducible
(mk_le_mk_of_dvd (dvd_of_mem_normalizedFactors hp))
rwa [associated_iff_eq.mp hq']
|
test_rat.v
|
From mathcomp Require Import all_boot all_order all_algebra.
Local Open Scope ring_scope.
Goal 2%:Q + 2%:Q = 4%:Q.
Proof. reflexivity. Qed.
Goal - 2%:Q = -1 * 2%:Q.
Proof. reflexivity. Qed.
Goal 2%:Q ^+ 2 = 4%:Q.
Proof. reflexivity. Qed.
Goal (-1)^-1 = -1 :> rat.
Proof. reflexivity. Qed.
Local Open Scope rat_scope.
Check 12.
Check 3.14.
Check -3.14.
Check 0.5.
Check 0.2.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.